diff --git a/lean/OAI/Probability/ThorpRouting/Dense/Main.lean b/lean/OAI/Probability/ThorpRouting/Dense/Main.lean index 1a27bc3d393b7e49b97570094305f4b11c58c167..a550c07fd29d7504f14661961b5a664333afb20f 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/Main.lean @@ -1,1125 +1,1125 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.SingleSlotsEquiv - -namespace OAI - -namespace ThorpNine.Dense - -open scoped BigOperators -namespace Thorp - -lemma sharedPartnerMean_nonneg (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - 0 ≤ sharedPartnerMean r s A := by - unfold sharedPartnerMean - positivity - -lemma sum_suffix_pair_counts (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - (∑ y : Card s, ((suffixMarks r (s+1) A (Fin.cons false y)).card + - (suffixMarks r (s+1) A (Fin.cons true y)).card)) = A.card := by - classical - have hh := sum_card_blockMarks ((cardSplit r (s+1)).trans (Equiv.prodComm _ _)) A - rw [←Equiv.sum_comp (headTailEquiv s).symm,Fintype.sum_prod_type,Fintype.sum_bool] at hh - simpa [suffixMarks,headTailEquiv,Fin.consEquiv,Finset.sum_add_distrib,add_comm] using hh - -lemma sharedPartnerMean_twice_le (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - 2*sharedPartnerMean r s A ≤ A.card := by - have hcap (y : Card (s+1)) : (suffixMarks r (s+1) A y).card ≤ 2^r := by - simpa only [card_positions] using Finset.card_le_univ (suffixMarks r (s+1) A y) - have hp : (0:ℝ) < (2:ℝ)^r := by positivity - rw [sharedPartnerMean,←mul_div_assoc,div_le_iff₀ hp,Finset.mul_sum] - have hs : (A.card:ℝ) = ∑ y : Card s, - ((suffixMarks r (s+1) A (Fin.cons false y)).card + - (suffixMarks r (s+1) A (Fin.cons true y)).card : ℝ) := by - exact_mod_cast (sum_suffix_pair_counts r s A).symm - rw [hs,Finset.sum_mul] - apply Finset.sum_le_sum - intro y _ - have h₀ : (suffixMarks r (s+1) A (Fin.cons false y)).card ≤ (2:ℝ)^r := by - exact_mod_cast hcap (Fin.cons false y) - have h₁ : (suffixMarks r (s+1) A (Fin.cons true y)).card ≤ (2:ℝ)^r := by - exact_mod_cast hcap (Fin.cons true y) - nlinarith [mul_nonneg (sub_nonneg.mpr h₀) - (Nat.cast_nonneg (suffixMarks r (s+1) A (Fin.cons true y)).card), - mul_nonneg (sub_nonneg.mpr h₁) - (Nat.cast_nonneg (suffixMarks r (s+1) A (Fin.cons false y)).card)] - - -lemma palindrome_level_dense_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card ((s+1)+r)) (t : ℝ) (ht : 0 ≤ t) : - finiteMean (fun ω : BenesCoins ((s+1)+r) => - Real.exp (t * palindromeLevelCost (s+1) ((s+1)+r) e ω)) ≤ - Real.exp ((Real.exp (denseLevelCoefficient s t)-1) * - sharedPartnerMean r s (Finset.univ.image e)) := by - classical - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun X : SwitchIndex ((s+1)+r) → Bool => - Real.exp (denseLevelCoefficient s t * sharedLevel (s+1) ((s+1)+r) e X)) := by - apply finiteMean_mono - intro X - exact palindrome_level_dense_conditional s ((s+1)+r) e X t ht - _ = finiteMean (fun hi : Card (s+1) × SwitchIndex r → Bool => - Real.exp (denseLevelCoefficient s t * - gridShared r s (inverseButterflyMarks ((s+1)+r) (Finset.univ.image e) - (assembleBits r (s+1) (fun _ => false) hi)))) := by - rw [finiteMean_split] - simp_rw [sharedLevel_partial_marks] - rw [finiteMean_const] - _ ≤ _ := partial_grid_mgf r s (Finset.univ.image e) _ - (denseLevelCoefficient_nonneg s ht) - - -lemma cardSplit_snd_apply (r s : ℕ) (x : Card (s+r)) (i : Fin s) : - (cardSplit r s x).2 i = x ⟨r+i,by omega⟩ := by - induction r with - | zero => simp [cardSplit] - | succ r ih => - change (cardSplit r s (Fin.tail x)).2 i = _ - rw [ih] - simp only [Fin.tail] - congr 1 - apply Fin.ext - simp only [Fin.val_succ] - omega - -def PairSeparated {d : ℕ} (i : Fin d) (x y : Card d) : Prop := - x i = false ∧ y i = true ∧ ∀ j : Fin d, i < j → x j = y j - -lemma PairSeparated.unique {d : ℕ} {i j : Fin d} {x y : Card d} - (hi : PairSeparated i x y) (hj : PairSeparated j x y) : i = j := by - by_contra h - rcases lt_or_gt_of_ne h with h | h - · have hh := hi.2.2 j h - rw [hj.1,hj.2.1] at hh - exact Bool.false_ne_true hh - · have hh := hj.2.2 i h - rw [hi.1,hi.2.1] at hh - exact Bool.false_ne_true hh - -lemma PairSeparated.not_reverse {d : ℕ} {i j : Fin d} {x y : Card d} - (hi : PairSeparated i x y) : ¬ PairSeparated j y x := by - intro hj - rcases lt_trichotomy i j with h | h | h - · have hh := hi.2.2 j h - rw [hj.2.1,hj.1] at hh - exact Bool.noConfusion hh - · subst j - exact Bool.false_ne_true (hi.1.symm.trans hj.2.1) - · have hh := hj.2.2 i h - rw [hi.1,hi.2.1] at hh - exact Bool.noConfusion hh - -lemma pairSeparated_split_iff (r s : ℕ) (x y : Card ((s+1)+r)) : - PairSeparated ⟨r,by omega⟩ x y ↔ - ∃ z : Card s, (cardSplit r (s+1) x).2 = Fin.cons false z ∧ - (cardSplit r (s+1) y).2 = Fin.cons true z := by - constructor - · intro h - refine ⟨Fin.tail (cardSplit r (s+1) x).2, ?_, ?_⟩ - · have h₀ : (cardSplit r (s+1) x).2 0 = false := by - simpa only [cardSplit_snd_apply,Fin.val_zero,Nat.add_zero] using h.1 - rw [←h₀,Fin.cons_self_tail] - · funext k - refine Fin.cases ?_ (fun k => ?_) k - · simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using h.2.1 - · simp only [Fin.cons_succ,Fin.tail,cardSplit_snd_apply] - exact (h.2.2 _ (by change r < r + (k.val+1); omega)).symm - · rintro ⟨z,hx,hy⟩ - refine ⟨?_,?_,?_⟩ - · have hh := congrFun hx 0 - simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using hh - · have hh := congrFun hy 0 - simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using hh - · intro j hj - change r < j.val at hj - have hbound : j.val-r-1 < s := by omega - let k : Fin s := ⟨j.val-r-1,hbound⟩ - have hjk : j = ⟨r+(k.val+1),by omega⟩ := Fin.ext (by dsimp [k]; omega) - rw [hjk] - have hx' := congrFun hx k.succ - have hy' := congrFun hy k.succ - simp only [cardSplit_snd_apply,Fin.cons_succ] at hx' hy' - exact hx'.trans hy'.symm - - -abbrev SeparatedPair {d : ℕ} (A : Finset (Card d)) (i : Fin d) := - {p : A × A // PairSeparated i p.1.val p.2.val} - -noncomputable def separatedCount {d : ℕ} (A : Finset (Card d)) (i : Fin d) : ℕ := by - classical - exact Fintype.card (SeparatedPair A i) - -lemma separated_budget_strong {d : ℕ} (A : Finset (Card d)) : - 2 * ∑ i : Fin d, separatedCount A i ≤ A.card * (A.card-1) := by - classical - let F : Bool × (Σ i : Fin d, SeparatedPair A i) → A × A := - fun ⟨b,i,p⟩ => if b then (p.val.2,p.val.1) else p.val - have hF : Function.Injective F := by - rintro ⟨b,i,p⟩ ⟨c,j,q⟩ h - cases b <;> cases c - · change p.val = q.val at h - have hij : i = j := p.property.unique (by rw [h]; exact q.property) - subst j - have hpq : p = q := Subtype.ext h - subst q - rfl - · change p.val = (q.val.2,q.val.1) at h - have hp := p.property - rw [h] at hp - exact False.elim (hp.not_reverse q.property) - · change (p.val.2,p.val.1) = q.val at h - have hq := q.property - rw [←h] at hq - exact False.elim (hq.not_reverse p.property) - · change (p.val.2,p.val.1) = (q.val.2,q.val.1) at h - have hpq : p.val = q.val := Prod.ext (congrArg Prod.snd h) (congrArg Prod.fst h) - have hij : i = j := p.property.unique (by rw [hpq]; exact q.property) - subst j - have hpqq : p = q := Subtype.ext hpq - subst q - rfl - have hneq (v : Bool × (Σ i : Fin d, SeparatedPair A i)) : (F v).1 ≠ (F v).2 := by - obtain ⟨b,i,p⟩ := v - have hp : p.val.1 ≠ p.val.2 := by - intro he - have hx := p.property.1 - have hy := p.property.2.1 - rw [he] at hx - exact Bool.false_ne_true (hx.symm.trans hy) - cases b <;> simp [F,hp,Ne.symm hp] - let G : Bool × (Σ i : Fin d, SeparatedPair A i) → ↥((Finset.univ : Finset A).offDiag) := - fun v => ⟨F v,Finset.mem_offDiag.mpr ⟨Finset.mem_univ _,Finset.mem_univ _,hneq v⟩⟩ - have hG : Function.Injective G := fun _ _ he => hF (congrArg Subtype.val he) - have hh := Fintype.card_le_of_injective G hG - simpa only [Fintype.card_prod,Fintype.card_bool,Fintype.card_sigma, - Fintype.card_coe,separatedCount,Finset.offDiag_card,Finset.card_univ, - Nat.mul_sub_left_distrib,mul_one] using hh - -lemma separated_budget {d : ℕ} (A : Finset (Card d)) : - 2 * ∑ i : Fin d, separatedCount A i ≤ A.card * A.card := - (separated_budget_strong A).trans (Nat.mul_le_mul_left _ (Nat.sub_le _ _)) - -lemma mem_suffixMarks (r s : ℕ) (A : Finset (Card (s+r))) (y : Card s) (x : Card r) : - x ∈ suffixMarks r s A y ↔ (cardSplit r s).symm (x,y) ∈ A := by - exact mem_blockMarks _ _ _ _ - -lemma separatedCount_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - separatedCount A ⟨r,by omega⟩ = - ∑ y : Card s, (suffixMarks r (s+1) A (Fin.cons false y)).card * - (suffixMarks r (s+1) A (Fin.cons true y)).card := by - classical - let D := Σ y : Card s, ↥(suffixMarks r (s+1) A (Fin.cons false y)) × - ↥(suffixMarks r (s+1) A (Fin.cons true y)) - let F : D → SeparatedPair A ⟨r,by omega⟩ := fun ⟨y,u,v⟩ => - ⟨(⟨(cardSplit r (s+1)).symm (u.val,Fin.cons false y), - (mem_suffixMarks _ _ _ _ _).mp u.property⟩, - ⟨(cardSplit r (s+1)).symm (v.val,Fin.cons true y), - (mem_suffixMarks _ _ _ _ _).mp v.property⟩), - (pairSeparated_split_iff r s _ _).mpr - ⟨y,by simp only [Equiv.apply_symm_apply],by simp only [Equiv.apply_symm_apply]⟩⟩ - have hF : Function.Bijective F := by - constructor - · rintro ⟨y,u,v⟩ ⟨z,u',v'⟩ he - have h₀ := congrArg (fun p => cardSplit r (s+1) p.val.1.val) he - have h₁ := congrArg (fun p => cardSplit r (s+1) p.val.2.val) he - change cardSplit r (s+1) ((cardSplit r (s+1)).symm (u.val,Fin.cons false y)) = - cardSplit r (s+1) ((cardSplit r (s+1)).symm (u'.val,Fin.cons false z)) at h₀ - change cardSplit r (s+1) ((cardSplit r (s+1)).symm (v.val,Fin.cons true y)) = - cardSplit r (s+1) ((cardSplit r (s+1)).symm (v'.val,Fin.cons true z)) at h₁ - simp only [Equiv.apply_symm_apply] at h₀ h₁ - have hyz : y = z := by - have hh := congrArg (fun p => Fin.tail p.2) h₀ - simpa only [Fin.tail_cons] using hh - subst z - have hu : u = u' := Subtype.ext (congrArg Prod.fst h₀) - have hv : v = v' := Subtype.ext (congrArg Prod.fst h₁) - subst u'; subst v'; rfl - · intro p - obtain ⟨y,hx,hy⟩ := (pairSeparated_split_iff r s p.val.1.val p.val.2.val).mp p.property - have hx' : (cardSplit r (s+1)).symm ((cardSplit r (s+1) p.val.1.val).1,Fin.cons false y) = - p.val.1.val := by rw [←hx,Prod.mk.eta,Equiv.symm_apply_apply] - have hy' : (cardSplit r (s+1)).symm ((cardSplit r (s+1) p.val.2.val).1,Fin.cons true y) = - p.val.2.val := by rw [←hy,Prod.mk.eta,Equiv.symm_apply_apply] - refine ⟨⟨y,⟨(cardSplit r (s+1) p.val.1.val).1,?_⟩, - ⟨(cardSplit r (s+1) p.val.2.val).1,?_⟩⟩,?_⟩ - · rw [mem_suffixMarks,hx']; exact p.val.1.property - · rw [mem_suffixMarks,hy']; exact p.val.2.property - · apply Subtype.ext - exact Prod.ext (Subtype.ext hx') (Subtype.ext hy') - have hh := Fintype.card_congr (Equiv.ofBijective F hF) - simpa only [D,Fintype.card_sigma,Fintype.card_prod,Fintype.card_coe,separatedCount] using hh.symm - - -noncomputable def partnerMean (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := - if hj : j < d then (separatedCount A ⟨d-j-1,by omega⟩ : ℝ) / (2:ℝ)^(d-j-1) else 0 - -lemma partnerMean_nonneg (d : ℕ) (A : Finset (Card d)) (j : ℕ) : - 0 ≤ partnerMean d A j := by - unfold partnerMean - split <;> positivity - -lemma partnerMean_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - partnerMean ((s+1)+r) A s = sharedPartnerMean r s A := by - classical - have hs : s < (s+1)+r := by omega - have hr : (s+1+r)-s-1 = r := by omega - simp only [partnerMean,dite_eq_left hs,hr,separatedCount_eq,sharedPartnerMean, - Nat.cast_sum,Nat.cast_mul] - -lemma partnerMean_twice_le (d : ℕ) (A : Finset (Card d)) (j : ℕ) : - 2*partnerMean d A j ≤ A.card := by - by_cases hj : j < d - · obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le (Nat.succ_le_of_lt hj) - rw [partnerMean_eq] - exact sharedPartnerMean_twice_le r j A - · simp only [partnerMean,dite_eq_right hj,mul_zero,Nat.cast_nonneg] - -lemma partnerMean_rate (d : ℕ) (A : Finset (Card d)) (j : Fin d) : - partnerMean d A j / (2:ℝ)^(j.val+1) = - (separatedCount A j.rev : ℝ) / (2:ℝ)^d := by - have hj : j.val < d := j.isLt - have hd : (d-j.val-1)+(j.val+1) = d := by omega - simp only [partnerMean,dite_eq_left hj,div_div,←pow_add,hd] - rfl - -lemma partnerMean_budget (d : ℕ) (A : Finset (Card d)) : - 2 * (∑ j ∈ Finset.range d, partnerMean d A j / (2:ℝ)^(j+1)) ≤ - (A.card:ℝ)^2/(2:ℝ)^d := by - classical - rw [←Fin.sum_univ_eq_sum_range] - simp_rw [partnerMean_rate] - rw [←Finset.sum_div] - have he : (∑ j : Fin d, (separatedCount A j.rev:ℝ)) = ∑ j : Fin d, (separatedCount A j:ℝ) := by - exact Equiv.sum_comp (Fin.revPerm : Equiv.Perm (Fin d)) (fun j : Fin d => (separatedCount A j : ℝ)) - rw [he,←mul_div_assoc] - apply div_le_div_of_nonneg_right _ (by positivity) - exact_mod_cast (by simpa only [pow_two] using separated_budget A) - -noncomputable def partnerAllocation (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := - 2*partnerMean d A j/A.card - -lemma partnerAllocation_admissible (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - DenseTruncation.AdmissibleAllocation ((A.card:ℝ)/(2:ℝ)^d) (partnerAllocation d A) := by - classical - have hA' : (0:ℝ) < A.card := by exact_mod_cast hA - constructor - · intro j - constructor - · exact div_nonneg (mul_nonneg (by norm_num) (partnerMean_nonneg d A j)) hA'.le - · rw [partnerAllocation,div_le_one hA'] - exact partnerMean_twice_le d A j - · have hz (j : ℕ) (hj : j ∉ Finset.range d) : - partnerAllocation d A j/(2:ℝ)^(j+1) = 0 := by - have h : ¬ j < d := by simpa only [Finset.mem_range] using hj - simp only [partnerAllocation,partnerMean,dite_eq_right h,mul_zero,zero_div] - rw [tsum_eq_sum (s := Finset.range d) hz] - have he (j : ℕ) : partnerAllocation d A j/(2:ℝ)^(j+1) = - 2/A.card * (partnerMean d A j/(2:ℝ)^(j+1)) := by - unfold partnerAllocation - ring - simp_rw [he] - rw [←Finset.mul_sum] - have hh := partnerMean_budget d A - apply (show 2/(A.card:ℝ) * ∑ j ∈ Finset.range d, partnerMean d A j/(2:ℝ)^(j+1) = - (2*(∑ j ∈ Finset.range d,partnerMean d A j/(2:ℝ)^(j+1)))/A.card by ring).le.trans - apply (div_le_div_of_nonneg_right hh hA'.le).trans - have hne : (A.card:ℝ) ≠ 0 := ne_of_gt hA' - exact le_of_eq (by field_simp) - - -lemma partner_weighted_sum_le (d H : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ - A.card * DenseTruncation.H ((A.card:ℝ)/(2:ℝ)^d) := by - have ha := partnerAllocation_admissible d A hA - have hh := DenseTruncation.allocation_le_H ha - have hA' : (0:ℝ) < A.card := by exact_mod_cast hA - have he (j : ℕ) : DenseTruncation.h (j+1)*partnerMean d A j = - (A.card:ℝ)/2*(DenseTruncation.h (j+1)*partnerAllocation d A j) := by - unfold partnerAllocation - field_simp - simp_rw [he] - rw [←Finset.mul_sum] - calc - _ ≤ (A.card:ℝ)/2 * ∑' j, DenseTruncation.h (j+1)*partnerAllocation d A j := by - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact (DenseTruncation.allocation_value_summable ha).sum_le_tsum _ - (fun j _ => mul_nonneg (DenseTruncation.h_nonneg _) (ha.1 j).1) - _ = (A.card:ℝ)*((1/2:ℝ)*∑' j, DenseTruncation.h (j+1)*partnerAllocation d A j) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg _) - -lemma finiteMean_rpow_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (f : Ω → ℝ) (hf : ∀ ω, 0 ≤ f ω) {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) : - finiteMean (fun ω => (f ω)^p) ≤ (finiteMean f)^p := by - have hN : (0:ℝ) < Fintype.card Ω := Nat.cast_pos.mpr Fintype.card_pos - have hh := (Real.concaveOn_rpow hp hp1).le_map_sum - (t := Finset.univ) (w := fun _ : Ω => 1/(Fintype.card Ω:ℝ)) - (p := f) (fun _ _ => by positivity) - (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) - (fun ω _ => hf ω) - simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : Ω,_), - ←div_eq_mul_inv,finiteMean] using hh - -lemma finiteMean_exp_scale {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (f : Ω → ℝ) (a b t : ℝ) (hb : 0 < b) (ht : 0 ≤ t) (htb : t ≤ b) - (h : finiteMean (fun ω => Real.exp (b*f ω)) ≤ Real.exp (b*a)) : - finiteMean (fun ω => Real.exp (t*f ω)) ≤ Real.exp (t*a) := by - have hp : 0 ≤ t/b := div_nonneg ht hb.le - have hp1 : t/b ≤ 1 := (div_le_one hb).mpr htb - have hh := (finiteMean_rpow_le (fun ω => Real.exp (b*f ω)) - (fun _ => (Real.exp_pos _).le) hp hp1).trans - (Real.rpow_le_rpow (finiteMean_nonneg (fun _ => (Real.exp_pos _).le)) h hp) - have he (x : ℝ) : (Real.exp (b*x))^(t/b) = Real.exp (t*x) := by - rw [←Real.exp_mul] - congr 1 - field_simp - simpa only [he] using hh - -lemma finiteMean_exp_sum_le {Ω I : Type*} [Fintype Ω] [Nonempty Ω] - [Fintype I] [Nonempty I] (f : I → Ω → ℝ) (a : I → ℝ) (t : ℝ) - (h : ∀ i, finiteMean (fun ω => Real.exp ((Fintype.card I:ℝ)*t*f i ω)) ≤ - Real.exp ((Fintype.card I:ℝ)*t*a i)) : - finiteMean (fun ω => Real.exp (t*∑ i, f i ω)) ≤ Real.exp (t*∑ i, a i) := by - have hN : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos - let N : ℝ := Fintype.card I - have hc (i : I) : finiteMean (fun ω => Real.exp (N*t*(f i ω-a i))) ≤ 1 := by - have he (ω : Ω) : Real.exp (N*t*(f i ω-a i)) = - Real.exp (N*t*f i ω) * Real.exp (-(N*t*a i)) := by - rw [←Real.exp_add]; congr 1; ring - simp_rw [he] - rw [finiteMean_mul_const] - calc - _ ≤ Real.exp (N*t*a i)*Real.exp (-(N*t*a i)) := - mul_le_mul_of_nonneg_right (h i) (Real.exp_pos _).le - _ = 1 := by rw [←Real.exp_add,add_neg_cancel,Real.exp_zero] - have hj (ω : Ω) : Real.exp (t*(∑ i, (f i ω-a i))) ≤ - ∑ i, (1/N)*Real.exp (N*t*(f i ω-a i)) := by - have hh := convexOn_exp.map_sum_le - (t := Finset.univ) (w := fun _ : I => 1/N) - (p := fun i => N*t*(f i ω-a i)) - (fun _ _ => by dsimp [N]; positivity) - (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; dsimp [N]; field_simp) - (fun _ _ => Set.mem_univ _) - have he (i : I) : (1/N)*(N*t*(f i ω-a i)) = t*(f i ω-a i) := by - dsimp [N]; field_simp - simpa only [smul_eq_mul,he,←Finset.mul_sum] using hh - have hm : finiteMean (fun ω => Real.exp (t*(∑ i, (f i ω-a i)))) ≤ 1 := by - apply (finiteMean_mono hj).trans - rw [finiteMean_sum] - calc - _ ≤ ∑ _ : I, 1/N := by - apply Finset.sum_le_sum - intro i _ - have he (ω : Ω) : 1/N*Real.exp (N*t*(f i ω-a i)) = - Real.exp (N*t*(f i ω-a i))*(1/N) := mul_comm _ _ - simp_rw [he] - rw [finiteMean_mul_const] - simpa only [one_mul] using mul_le_mul_of_nonneg_right (hc i) - (by dsimp [N]; positivity : 0 ≤ 1/N) - _ = 1 := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; dsimp [N]; field_simp - have he (ω : Ω) : Real.exp (t*∑ i,f i ω) = - Real.exp (t*(∑ i, (f i ω-a i)))*Real.exp (t*∑ i,a i) := by - rw [←Real.exp_add,Finset.sum_sub_distrib] - congr 1; ring - simp_rw [he] - rw [finiteMean_mul_const] - simpa only [one_mul] using mul_le_mul_of_nonneg_right hm (Real.exp_pos _).le - - -open Filter Topology - -lemma dense_coefficient_hasDerivAt (j : ℕ) : - HasDerivAt (fun t : ℝ => Real.exp (denseLevelCoefficient j t)-1) - (DenseTruncation.h (j+1)) 0 := by - have hp : (2:ℝ)^j ≠ 0 := by positivity - have h₀ := (hasDerivAt_id (0:ℝ)).mul_const ((2:ℝ)^j) - have h₁ := h₀.exp.sub_const 1 - have h₂ := h₁.div_const ((2:ℝ)^j) - have hh := h₂.const_mul (DenseTruncation.h (j+1)) - simpa [denseLevelCoefficient, hp] using hh.exp.sub_const 1 - -lemma dense_coefficient_small (H : ℕ) (δ : ℝ) (hδ : 0 < δ) : - ∃ τ : ℝ, 0 < τ ∧ τ ≤ 1/500 ∧ ∀ j < H, - Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ) := by - have hj (j : Fin H) : ∀ᶠ t : ℝ in 𝓝[>] 0, - (Real.exp (denseLevelCoefficient j t)-1)/t < DenseTruncation.h (j+1)+δ := by - have hh := (dense_coefficient_hasDerivAt j).tendsto_slope_zero_right - simp only [zero_add,denseLevelCoefficient,zero_mul,Real.exp_zero,sub_self,zero_div, - mul_zero,smul_eq_mul,sub_zero] at hh - have hh' : Tendsto (fun t : ℝ => (Real.exp (denseLevelCoefficient j t)-1)/t) - (𝓝[>] 0) (𝓝 (DenseTruncation.h (j+1))) := by - simpa only [denseLevelCoefficient,div_eq_mul_inv,mul_comm] using hh - exact (tendsto_order.mp hh').2 _ (by linarith) - have ha : ∀ᶠ t : ℝ in 𝓝[>] 0, ∀ j : Fin H, - (Real.exp (denseLevelCoefficient j t)-1)/t < DenseTruncation.h (j+1)+δ := - Filter.eventually_all.mpr hj - have hb : ∀ᶠ t : ℝ in 𝓝[>] 0, t < 1/500 := - (eventually_lt_nhds (by norm_num : (0:ℝ) < 1/500)).filter_mono nhdsWithin_le_nhds - have hc : ∀ᶠ t : ℝ in 𝓝[>] 0, 0 < t := self_mem_nhdsWithin - obtain ⟨τ,ht,hb,ha⟩ := (hc.and (hb.and ha)).exists - refine ⟨τ,ht,hb.le,fun j hj => ?_⟩ - exact ((div_lt_iff₀ ht).mp (ha ⟨j,hj⟩)).le.trans_eq (mul_comm _ _) - -lemma palindrome_level_dense_mgf_all (d j : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (t : ℝ) (ht : 0 ≤ t) : - finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeLevelCost (j+1) d e ω)) ≤ - Real.exp ((Real.exp (denseLevelCoefficient j t)-1)*partnerMean d (Finset.univ.image e) j) := by - classical - by_cases hj : j < d - · obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le (Nat.succ_le_of_lt hj) - rw [partnerMean_eq] - exact palindrome_level_dense_mgf r j e t ht - · simp only [palindromeLevelCost_gt (j+1) d (by omega) e, Nat.cast_zero,mul_zero, - Real.exp_zero,finiteMean_const,partnerMean,dite_eq_right hj,le_refl] - -lemma palindrome_low_dense_mgf (H : ℕ) (hH : 0 < H) (δ τ : ℝ) (hδ : 0 ≤ δ) (ht : 0 ≤ τ) - (hτ : ∀ j < H, Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ)) - (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (hι : 0 < Fintype.card ι) : - finiteMean (fun ω : BenesCoins d => Real.exp ((τ/H)*palindromeLowCost H d e ω)) ≤ - Real.exp ((τ/H)*Fintype.card ι* - (DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)+H*δ/2)) := by - classical - let A := Finset.univ.image e - have hA : A.card = Fintype.card ι := by simp [A, Finset.card_image_of_injective _ e.injective] - have hn : (H:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hH) - have he : (H:ℝ)*(τ/H) = τ := by field_simp - let : Nonempty (Fin H) := Fin.pos_iff_nonempty.mp hH - have hh := finiteMean_exp_sum_le - (fun j : Fin H => fun ω : BenesCoins d => (palindromeLevelCost (j+1) d e ω:ℝ)) - (fun j : Fin H => (DenseTruncation.h (j+1)+δ)*partnerMean d A j) (τ/H) (by - intro j - simp only [Fintype.card_fin,he] - apply (palindrome_level_dense_mgf_all d j e τ ht).trans - apply Real.exp_le_exp.mpr - simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hτ j j.isLt) - (partnerMean_nonneg d A j)) - have hsum : (∑ j : Fin H, (DenseTruncation.h (j+1)+δ)*partnerMean d A j) ≤ - Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)+H*δ/2) := by - rw [Fin.sum_univ_eq_sum_range (fun j => (DenseTruncation.h (j+1)+δ)*partnerMean d A j)] - simp_rw [add_mul] - rw [Finset.sum_add_distrib] - have hm := partner_weighted_sum_le d H A (by omega) - rw [hA] at hm - have hs : (∑ j ∈ Finset.range H, δ*partnerMean d A j) ≤ (H:ℝ)*δ*(Fintype.card ι)/2 := by - calc - _ ≤ ∑ _j ∈ Finset.range H, δ*((Fintype.card ι:ℝ)/2) := by - apply Finset.sum_le_sum - intro j _ - apply mul_le_mul_of_nonneg_left _ hδ - have hg := partnerMean_twice_le d A j - rw [hA] at hg - linarith - _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring - nlinarith - have hh' := hh.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by positivity))) - have hl (ω : BenesCoins d) : - (∑ j : Fin H, (palindromeLevelCost (j+1) d e ω : ℝ)) = - ∑ j ∈ Finset.range H, (palindromeLevelCost (j+1) d e ω : ℝ) := - Fin.sum_univ_eq_sum_range (fun j => (palindromeLevelCost (j+1) d e ω : ℝ)) H - simpa only [palindromeLowCost_sum,Nat.cast_sum,hl,mul_assoc] using hh' - - -lemma heightDecay_tendsto : Tendsto heightDecay atTop (𝓝 0) := by - have hr : 0 ≤ Real.exp (-(1:ℝ)/64) := (Real.exp_pos _).le - have hr1 : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hh := ((tendsto_pow_atTop_nhds_zero_of_lt_one hr hr1).const_mul 68).div_const - (1-Real.exp (-(1:ℝ)/64)) - have he (H : ℕ) : (Real.exp (-(1:ℝ)/64))^H = Real.exp (-(H:ℝ)/64) := by - rw [←Real.exp_nat_mul] - congr 1; ring - change Tendsto (fun H : ℕ => 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64))) _ _ - simpa only [he,mul_zero,zero_div] using hh - -lemma heightDecay_exists {ε : ℝ} (hε : 0 < ε) : - ∃ H : ℕ, 0 < H ∧ 500*heightDecay H < ε := by - have hh := heightDecay_tendsto.const_mul 500 - simp only [mul_zero] at hh - have he := (tendsto_order.mp hh).2 ε hε - exact ((eventually_gt_atTop 0).and he).exists - -lemma palindrome_high_exp_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (t : ℝ) (ht : 0 ≤ t) (htb : t ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => Real.exp (t* - (palindromeFamilyCost H n d e ω+palindromeFamilyCost (2*H) n d e ω))) ≤ - Real.exp (t*Fintype.card ι*(500*heightDecay H)) := by - have hh := palindrome_high_full_mgf H n d hH e (Real.exp (1/500)) - (Real.one_le_exp_iff.mpr (by norm_num)) (by rw [Real.log_exp]) - have hp : finiteMean (fun ω : BenesCoins d => Real.exp ((1/500:ℝ)* - (palindromeFamilyCost H n d e ω+palindromeFamilyCost (2*H) n d e ω))) ≤ - Real.exp ((1/500:ℝ)*(Fintype.card ι*(500*heightDecay H))) := by - have he (k : ℕ) : (Real.exp (1/500:ℝ))^k = Real.exp ((1/500:ℝ)*k) := by - rw [←Real.exp_nat_mul]; congr 1; ring - simpa only [he,Nat.cast_add,show (1/500:ℝ)*(Fintype.card ι*(500*heightDecay H)) = - Fintype.card ι*heightDecay H by ring] using hh - have hs := finiteMean_exp_scale - (fun ω : BenesCoins d => ((palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω):ℝ)) - (Fintype.card ι*(500*heightDecay H)) (1/500) t (by norm_num) ht htb - (by simpa only [Nat.cast_add] using hp) - simpa only [Nat.cast_add,mul_assoc] using hs - -end Thorp - -namespace Thorp.DenseTruncation - -lemma harmonic_le_h (j : ℕ) : - (harmonic (2^j):ℝ)/(2:ℝ)^j ≤ h (j+1) := by - classical - let M := 2^j - have hM : 0 < M := by dsimp [M]; positivity - have hM' : (0:ℝ) < M := Nat.cast_pos.mpr hM - have hMc : (M:ℝ) = (2:ℝ)^j := by simp [M] - let p : ℕ → ℝ := fun l => if l < M then 1/M else 0 - have hp : AdmissibleCycleLaw (j+1) p := by - refine ⟨fun l => by dsimp [p]; split_ifs <;> positivity, ?_, ?_⟩ - · have hs : HasSum p (∑ l ∈ Finset.range M,p l) := - hasSum_sum_of_ne_finset_zero (s := Finset.range M) (f := p) - (fun l hl => by simp only [Finset.mem_range] at hl; simp [p,hl]) - have he : (∑ l ∈ Finset.range M,p l) = 1 := by - simp only [p] - rw [Finset.sum_congr rfl (fun l hl => ite_eq_left (Finset.mem_range.mp hl))] - simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] - field_simp - exact he ▸ hs - · intro l - simp only [Nat.add_sub_cancel] - by_cases hl : l < M - · simp only [p,ite_eq_left hl,←hMc] - apply div_le_div_of_nonneg_right _ hM'.le - exact_mod_cast Nat.succ_pos l - · simp only [p,ite_eq_right hl] - positivity - have he : (∑' l, p l / ((l+1:ℕ):ℝ)) = (harmonic M:ℝ)/(M:ℝ) := by - rw [tsum_eq_sum (s := Finset.range M) (fun l hl => by - simp only [Finset.mem_range] at hl; simp [p,hl])] - simp only [harmonic,Rat.cast_sum,Rat.cast_inv,Rat.cast_natCast,Finset.sum_div] - apply Finset.sum_congr rfl - intro l hl - simp only [p,ite_eq_left (Finset.mem_range.mp hl)] - ring - have hh := reciprocal_le_h hp - rw [he,hMc] at hh - exact hh - -lemma harmonic_lower (m : ℕ) (hm : 0 < m) : - Real.log m+1/2 ≤ (harmonic m:ℝ) := by - have hh := Real.one_half_lt_eulerMascheroniConstant.trans - (Real.eulerMascheroniConstant_lt_eulerMascheroniSeq' m) - simp only [Real.eulerMascheroniSeq',ite_eq_right (ne_of_gt hm)] at hh - linarith - -lemma h_log_lower (j : ℕ) : - ((j:ℝ)*Real.log 2+1/2)/(2:ℝ)^j ≤ h (j+1) := by - have hh := harmonic_lower (2^j) (by positivity) - rw [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh - exact (div_le_div_of_nonneg_right hh (by positivity)).trans (harmonic_le_h j) - -noncomputable def unusedTail (d : ℕ) : ℝ := - (1/2:ℝ)*∑' j : ℕ, h (d+j+1) - -lemma unusedTail_nonneg (d : ℕ) : 0 ≤ unusedTail d := by - apply mul_nonneg (by norm_num) - exact tsum_nonneg (fun j => h_nonneg _) - -lemma unusedTail_lower (d : ℕ) : - ((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d ≤ unusedTail d := by - have hg := hasSum_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) - have hj := hasSum_coe_mul_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) - norm_num at hg hj - have hs : HasSum (fun j : ℕ => (((d+j:ℕ):ℝ)*Real.log 2+1/2)/(2:ℝ)^(d+j)) - (2*((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d) := by - convert! ((hg.mul_left ((d:ℝ)*Real.log 2+1/2)).add - (hj.mul_left (Real.log 2))).div_const ((2:ℝ)^d) using 1 - · funext j - simp only [Nat.cast_add,pow_add,div_pow,one_pow] - ring - · ring - have hsum : Summable (fun j : ℕ => h (d+j+1)) := by - simpa only [Nat.add_comm d] using (summable_nat_add_iff d).mpr h_summable - have hh := hs.summable.tsum_le_tsum (fun j => h_log_lower (d+j)) hsum - rw [hs.tsum_eq] at hh - unfold unusedTail - calc - _ = (1/2:ℝ)*(2*((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by norm_num) - -end Thorp.DenseTruncation - -namespace Thorp - -lemma partnerMean_budget_strong (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - 2 * (∑ j ∈ Finset.range d, partnerMean d A j / (2:ℝ)^(j+1)) ≤ - (A.card:ℝ)*(A.card-1)/(2:ℝ)^d := by - classical - rw [←Fin.sum_univ_eq_sum_range] - simp_rw [partnerMean_rate] - rw [←Finset.sum_div] - have he : (∑ j : Fin d, (separatedCount A j.rev:ℝ)) = ∑ j : Fin d, (separatedCount A j:ℝ) := by - exact Equiv.sum_comp (Fin.revPerm : Equiv.Perm (Fin d)) (fun j : Fin d => (separatedCount A j : ℝ)) - rw [he,←mul_div_assoc] - apply div_le_div_of_nonneg_right _ (by positivity) - have hh : (2:ℝ)*(∑ i : Fin d,(separatedCount A i:ℝ)) ≤ - (A.card:ℝ)*((A.card-1:ℕ):ℝ) := by exact_mod_cast separated_budget_strong A - simpa only [Nat.cast_sub (show 1 ≤ A.card by omega),Nat.cast_one] using hh - -lemma partnerAllocation_range_budget (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - (∑ j ∈ Finset.range d, partnerAllocation d A j/(2:ℝ)^(j+1)) ≤ - ((A.card:ℝ)-1)/(2:ℝ)^d := by - have hp : (0:ℝ) < A.card := Nat.cast_pos.mpr hA - have he (j : ℕ) : partnerAllocation d A j/(2:ℝ)^(j+1) = - (2*partnerMean d A j/(2:ℝ)^(j+1))/A.card := by unfold partnerAllocation; ring - simp_rw [he] - rw [←Finset.sum_div] - simp_rw [mul_div_assoc] - rw [←Finset.mul_sum] - apply (div_le_div_of_nonneg_right (partnerMean_budget_strong d A hA) hp.le).trans - exact le_of_eq (by field_simp) - -lemma dyadic_weights_hasSum (d : ℕ) : - HasSum (fun j : ℕ => 1/(2:ℝ)^(d+j+1)) (1/(2:ℝ)^d) := by - have hg := hasSum_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) - norm_num at hg - convert! hg.div_const ((2:ℝ)^(d+1)) using 1 - · funext j - simp only [pow_add,div_pow,one_pow,pow_one] - ring - · simp only [pow_succ] - field_simp - -noncomputable def augmentedAllocation (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := - if j < d then partnerAllocation d A j else 1 - -lemma augmentedAllocation_bounds (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) (j : ℕ) : - 0 ≤ augmentedAllocation d A j ∧ augmentedAllocation d A j ≤ 1 := by - unfold augmentedAllocation - split_ifs - · exact (partnerAllocation_admissible d A hA).1 j - · norm_num - -lemma augmentedAllocation_admissible (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - DenseTruncation.AdmissibleAllocation ((A.card:ℝ)/(2:ℝ)^d) (augmentedAllocation d A) := by - classical - refine ⟨augmentedAllocation_bounds d A hA,?_⟩ - have hs : Summable (fun j => augmentedAllocation d A j/(2:ℝ)^(j+1)) := by - apply Summable.of_nonneg_of_le (fun j => div_nonneg (augmentedAllocation_bounds d A hA j).1 - (by positivity)) (fun j => div_le_div_of_nonneg_right (augmentedAllocation_bounds d A hA j).2 - (by positivity)) - simpa only [Nat.zero_add] using (dyadic_weights_hasSum 0).summable - have hh := hs.sum_add_tsum_nat_add d - have ht : (∑' j, augmentedAllocation d A (j+d)/(2:ℝ)^(j+d+1)) = 1/(2:ℝ)^d := by - have he (j : ℕ) : augmentedAllocation d A (j+d)/(2:ℝ)^(j+d+1) = 1/(2:ℝ)^(d+j+1) := by - rw [augmentedAllocation,ite_eq_right (show ¬j+d by rw [augmentedAllocation,ite_eq_left (Finset.mem_range.mp hj)]) - rw [←hh,ht,hf] - apply (add_le_add (partnerAllocation_range_budget d A hA) (le_refl ((1:ℝ)/2^d))).trans - exact le_of_eq (by ring) - -lemma partner_weighted_sum_gap (d H : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : - (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ - A.card * (DenseTruncation.H ((A.card:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d) := by - classical - have ha := augmentedAllocation_admissible d A hA - have hs := DenseTruncation.allocation_value_summable ha - have HH := DenseTruncation.allocation_le_H ha - have he := hs.sum_add_tsum_nat_add d - have ht : (∑' j, DenseTruncation.h (j+d+1)*augmentedAllocation d A (j+d)) = - ∑' j, DenseTruncation.h (d+j+1) := by - congr 1 - funext j - rw [augmentedAllocation,ite_eq_right (show ¬j+d DenseTruncation.h (j+1)*partnerMean d A j) := - (hasSum_sum_of_ne_finset_zero hz : HasSum _ - (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)).summable - have hlow : (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ - ∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j := by - calc - _ ≤ ∑' j, DenseTruncation.h (j+1)*partnerMean d A j := - hsum.sum_le_tsum _ (fun j _ => mul_nonneg (DenseTruncation.h_nonneg _) - (partnerMean_nonneg _ _ _)) - _ = _ := tsum_eq_sum hz - have hp : (0:ℝ) < A.card := Nat.cast_pos.mpr hA - have HH' := mul_le_mul_of_nonneg_left HH hp.le - have HE : (A.card:ℝ)*((1/2:ℝ)*((2/(A.card:ℝ))* - (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)+ - ∑' j, DenseTruncation.h (d+j+1))) = - (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)+ - (A.card:ℝ)*((1/2:ℝ)*∑' j, DenseTruncation.h (d+j+1)) := by - field_simp - rw [HE] at HH' - unfold DenseTruncation.unusedTail - exact hlow.trans (by nlinarith [HH']) - - -lemma palindrome_low_dense_mgf_gap (H : ℕ) (hH : 0 < H) (δ τ : ℝ) (hδ : 0 ≤ δ) (ht : 0 ≤ τ) - (hτ : ∀ j < H, Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ)) - (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (hι : 0 < Fintype.card ι) : - finiteMean (fun ω : BenesCoins d => Real.exp ((τ/H)*palindromeLowCost H d e ω)) ≤ - Real.exp ((τ/H)*Fintype.card ι* - (DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d+H*δ/2)) := by - classical - let A := Finset.univ.image e - have hA : A.card = Fintype.card ι := by simp [A, Finset.card_image_of_injective _ e.injective] - have hn : (H:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hH) - have he : (H:ℝ)*(τ/H) = τ := by field_simp - let : Nonempty (Fin H) := Fin.pos_iff_nonempty.mp hH - have hh := finiteMean_exp_sum_le - (fun j : Fin H => fun ω : BenesCoins d => (palindromeLevelCost (j+1) d e ω:ℝ)) - (fun j : Fin H => (DenseTruncation.h (j+1)+δ)*partnerMean d A j) (τ/H) (by - intro j - simp only [Fintype.card_fin,he] - apply (palindrome_level_dense_mgf_all d j e τ ht).trans - apply Real.exp_le_exp.mpr - simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hτ j j.isLt) - (partnerMean_nonneg d A j)) - have hsum : (∑ j : Fin H, (DenseTruncation.h (j+1)+δ)*partnerMean d A j) ≤ - Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d+H*δ/2) := by - rw [Fin.sum_univ_eq_sum_range (fun j => (DenseTruncation.h (j+1)+δ)*partnerMean d A j)] - simp_rw [add_mul] - rw [Finset.sum_add_distrib] - have hm := partner_weighted_sum_gap d H A (by omega) - rw [hA] at hm - have hs : (∑ j ∈ Finset.range H, δ*partnerMean d A j) ≤ (H:ℝ)*δ*(Fintype.card ι)/2 := by - calc - _ ≤ ∑ _j ∈ Finset.range H, δ*((Fintype.card ι:ℝ)/2) := by - apply Finset.sum_le_sum - intro j _ - apply mul_le_mul_of_nonneg_left _ hδ - have hg := partnerMean_twice_le d A j - rw [hA] at hg - linarith - _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring - nlinarith - have hh' := hh.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by positivity))) - have hl (ω : BenesCoins d) : - (∑ j : Fin H, (palindromeLevelCost (j+1) d e ω : ℝ)) = - ∑ j ∈ Finset.range H, (palindromeLevelCost (j+1) d e ω : ℝ) := - Fin.sum_univ_eq_sum_range (fun j => (palindromeLevelCost (j+1) d e ω : ℝ)) H - simpa only [palindromeLowCost_sum,Nat.cast_sum,hl,mul_assoc] using hh' - - -lemma palindrome_dense_mgf (ε : ℝ) (hε : 0 < ε) : - ∃ t : ℝ, 0 < t ∧ ∀ d : ℕ, ∀ {ι : Type} [Fintype ι], - ∀ e : ι ↪ Card d, 0 < Fintype.card ι → - finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeCost d e ω)) ≤ - Real.exp (t*Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)- - DenseTruncation.unusedTail d+ε)) := by - obtain ⟨H,hH,hdecay⟩ := heightDecay_exists (show 0 < ε/2 by positivity) - have hHr : (0:ℝ) < H := Nat.cast_pos.mpr hH - let δ := ε/H - have hδ : 0 < δ := div_pos hε hHr - obtain ⟨τ,ht,hτb,hτ⟩ := dense_coefficient_small H δ hδ - let t := (τ/H)/2 - have htp : 0 < t := by dsimp [t]; positivity - have hσb : τ/H ≤ 1/500 := by - apply (div_le_self ht.le (by exact_mod_cast hH)).trans hτb - refine ⟨t,htp,?_⟩ - intro d ι _ e he - have hlow := palindrome_low_dense_mgf_gap H hH δ τ hδ.le ht.le hτ d e he - have hhigh := palindrome_high_exp_mgf H d d hH e (τ/H) (by positivity) hσb - have hex (k : ℝ) : (Real.exp (t*k))^2 = Real.exp ((τ/H)*k) := by - rw [←Real.exp_nat_mul] - congr 1 - dsimp [t] - ring - have hh := finiteMean_mul_exp_le - (fun ω : BenesCoins d => Real.exp (t*palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => Real.exp (t*(palindromeFamilyCost H d d e ω+ - palindromeFamilyCost (2*H) d d e ω))) - ((τ/H)*Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)- - DenseTruncation.unusedTail d+H*δ/2)) - ((τ/H)*Fintype.card ι*(500*heightDecay H)) - (by simpa only [hex] using hlow) - (by simpa only [hex,Nat.cast_add] using hhigh) - have hd : d ≤ H*4^d := by - have hg := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hc := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hc - simpa only [Nat.add_assoc] using hc.symm - have hf (ω : BenesCoins d) : Real.exp (t*palindromeCost d e ω) = - Real.exp (t*palindromeLowCost H d e ω)* - Real.exp (t*(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) := by - rw [hcost,Nat.cast_add,Nat.cast_add,mul_add,Real.exp_add] - simp_rw [←hf] at hh - apply hh.trans - apply Real.exp_le_exp.mpr - have heδ : (H:ℝ)*δ/2=ε/2 := by dsimp [δ]; field_simp - rw [heδ] - have hc : (ε/2+500*heightDecay H) ≤ ε := by linarith - have hm := mul_le_mul_of_nonneg_left hc (show 0 ≤ t*(Fintype.card ι) by positivity) - dsimp [t] at hm ⊢ - nlinarith [hm] - -end Thorp - -open scoped BigOperators -namespace Thorp.DenseTruncation - -noncomputable def stirlingRemainder (n : ℕ) : ℝ := - Real.log (n.factorial:ℝ) - n*Real.log n+n - -lemma stirlingRemainder_zero : stirlingRemainder 0 = 0 := by - simp [stirlingRemainder] - -lemma stirlingRemainder_step (n : ℕ) : - stirlingRemainder (n+1)-stirlingRemainder n = - 1-(n:ℝ)*(Real.log (n+1)-Real.log n) := by - have hn : (0:ℝ) < n+1 := by positivity - have hf : (0:ℝ) < n.factorial := Nat.cast_pos.mpr (Nat.factorial_pos n) - rw [stirlingRemainder,stirlingRemainder,Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one, - Real.log_mul (ne_of_gt hn) (ne_of_gt hf)] - ring - -lemma log_increment_mul_monotone : - Monotone (fun n : ℕ => (n:ℝ)*(Real.log (n+1)-Real.log n)) := by - intro m n hmn - have hm : (0:ℝ) ≤ m := Nat.cast_nonneg _ - have hn : (0:ℝ) ≤ n := Nat.cast_nonneg _ - have hmn' : (m:ℝ) ≤ n := by exact_mod_cast hmn - by_cases hm0 : m = 0 - · subst m - simp only [Nat.cast_zero,zero_mul] - by_cases hn0 : n = 0 - · simp [hn0] - · have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn0) - exact mul_nonneg hn (sub_nonneg.mpr (Real.log_le_log hnpos (by linarith))) - have hmpos : (0:ℝ) < m := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hm0) - have hnpos : (0:ℝ) < n := lt_of_lt_of_le hmpos hmn' - have ha : 0 ≤ (m:ℝ)/n := div_nonneg hm hn - have hb : 0 ≤ 1-(m:ℝ)/n := by rw [sub_nonneg,div_le_one hnpos]; exact hmn' - have hc := strictConcaveOn_log_Ioi.concaveOn.2 - (show (m+1:ℝ)/m ∈ Set.Ioi 0 by exact div_pos (by positivity) hmpos) - (show (1:ℝ) ∈ Set.Ioi 0 by norm_num) ha hb - (show (m:ℝ)/n+(1-(m:ℝ)/n) = 1 by ring) - have he : (m:ℝ)/n*((m+1)/m)+(1-(m:ℝ)/n)*1 = (n+1)/n := by - field_simp - ring - simp only [smul_eq_mul,Real.log_one,mul_zero,add_zero,he] at hc - rw [Real.log_div (by positivity : (m+1:ℝ) ≠ 0) (ne_of_gt hmpos), - Real.log_div (by positivity : (n+1:ℝ) ≠ 0) (ne_of_gt hnpos)] at hc - have hc' := mul_le_mul_of_nonneg_left hc hn - have he' : (n:ℝ)*((m:ℝ)/n*(Real.log (m+1)-Real.log m)) = - m*(Real.log (m+1)-Real.log m) := by field_simp - simpa only [he'] using hc' - -lemma stirlingRemainder_increment_antitone : - Antitone (fun n : ℕ => stirlingRemainder (n+1)-stirlingRemainder n) := by - intro m n hmn - simp only [stirlingRemainder_step] - linarith [log_increment_mul_monotone hmn] - -lemma stirlingRemainder_upper {n : ℕ} (hn : 0 < n) : - stirlingRemainder n ≤ 1+Real.log n/2 := by - obtain ⟨m,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (ne_of_gt hn) - have hm : (0:ℝ) < m+1 := by positivity - have he : Real.log (2*((m+1):ℝ)) = Real.log 2+Real.log (m+1) := - Real.log_mul (by norm_num) (ne_of_gt hm) - have hh := Stirling.log_stirlingSeq'_antitone (show 0 ≤ m by omega) - change Real.log (Stirling.stirlingSeq (m+1)) ≤ Real.log (Stirling.stirlingSeq 1) at hh - rw [Stirling.log_stirlingSeq_formula,Stirling.log_stirlingSeq_formula] at hh - simp only [Nat.cast_add,Nat.cast_one,he,Nat.factorial_one,Real.log_one,mul_one, - Real.log_div (ne_of_gt hm) (ne_of_gt (Real.exp_pos 1)),Real.log_exp, - Real.log_div (by norm_num : (1:ℝ) ≠ 0) (ne_of_gt (Real.exp_pos 1))] at hh - dsimp [stirlingRemainder] - push_cast - linarith - -lemma stirlingRemainder_sum (n : ℕ) : - (∑ i ∈ Finset.range n, (stirlingRemainder (i+1)-stirlingRemainder i)) = - stirlingRemainder n := by - induction n with - | zero => simp [stirlingRemainder_zero] - | succ n ih => rw [Finset.sum_range_succ,ih]; ring - -lemma stirlingRemainder_step_bound (n : ℕ) : - (n:ℝ)*(stirlingRemainder (n+1)-stirlingRemainder n) ≤ stirlingRemainder n := by - calc - _ = ∑ _i ∈ Finset.range n, (stirlingRemainder (n+1)-stirlingRemainder n) := by - simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] - _ ≤ ∑ i ∈ Finset.range n, (stirlingRemainder (i+1)-stirlingRemainder i) := by - exact Finset.sum_le_sum fun i hi => stirlingRemainder_increment_antitone - (Nat.le_of_lt (Finset.mem_range.mp hi)) - _ = _ := stirlingRemainder_sum n - -lemma stirlingRemainder_average_antitone : - Antitone (fun n : ℕ => stirlingRemainder (n+1)/(n+1)) := by - apply antitone_nat_of_succ_le - intro n - have h₁ : (0:ℝ) < n+1 := by positivity - have h₂ : (0:ℝ) < n+1+1 := by positivity - push_cast - rw [div_le_div_iff₀ h₂ h₁] - have hh := stirlingRemainder_step_bound (n+1) - push_cast at hh ⊢ - nlinarith - -lemma stirlingRemainder_difference_bound {n r : ℕ} (hn : 0 < n) (hr : r ≤ n) : - stirlingRemainder n-stirlingRemainder (n-r) ≤ (r:ℝ)/n*stirlingRemainder n := by - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have he : (n-r:ℕ)+r=n := Nat.sub_add_cancel hr - by_cases hm : n-r=0 - · have hn_eq : n=r := by omega - subst n - simp [stirlingRemainder_zero,div_self (ne_of_gt hn')] - · obtain ⟨m,hm'⟩ := Nat.exists_eq_succ_of_ne_zero hm - obtain ⟨q,hq⟩ := Nat.exists_eq_succ_of_ne_zero (ne_of_gt hn) - have hmq : m ≤ q := by omega - have hh := stirlingRemainder_average_antitone hmq - have hposm : (0:ℝ) < m+1 := by positivity - have hposq : (0:ℝ) < q+1 := by positivity - rw [div_le_div_iff₀ hposq hposm] at hh - have he' : (m:ℝ)+1+r=q+1 := by exact_mod_cast (show m+1+r=q+1 by omega) - rw [hm',hq] - push_cast - rw [div_mul_eq_mul_div,le_div_iff₀ hposq] - simp only [Nat.succ_eq_add_one] at * - have heq : (m:ℝ)+1 = (q+1:ℝ)-r := by linarith - rw [heq] at hh - nlinarith - -lemma stirlingRemainder_dyadic (d : ℕ) (hd : 1 ≤ d) : - stirlingRemainder (2^d)/Real.log 2 ≤ (d+1:ℝ)*Real.log 2+1/2 := by - have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlog : (6931/10000:ℝ) < Real.log 2 := lt_trans (by norm_num) Real.log_two_gt_d9 - rw [div_le_iff₀ hl] - by_cases hd1 : d=1 - · subst d - norm_num [stirlingRemainder] - nlinarith [sq_nonneg (Real.log 2-6931/10000)] - · have hd2 : (2:ℝ) ≤ d := by exact_mod_cast (show 2 ≤ d by omega) - have hh := stirlingRemainder_upper (n := 2^d) (by positivity) - rw [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh - have hq : 0 ≤ Real.log 2*Real.log 2-Real.log 2/2 := by - nlinarith [sq_nonneg (Real.log 2-6931/10000)] - have hprod := mul_nonneg (sub_nonneg.mpr hd2) hq - nlinarith [sq_nonneg (Real.log 2-6931/10000)] - -lemma factorial_error_identity {n r : ℕ} (hn : 0 < n) (hr : r ≤ n) : - Real.log ((n.descFactorial r:ℝ)/(n:ℝ)^r) = - stirlingRemainder n-stirlingRemainder (n-r)-(r:ℝ)- - (n-r:ℕ)*Real.log (1-(r:ℝ)/n) := by - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have hm : (0:ℝ) < (n-r).factorial := Nat.cast_pos.mpr (Nat.factorial_pos _) - have hd : (0:ℝ) < n.descFactorial r := Nat.cast_pos.mpr (Nat.descFactorial_pos.mpr hr) - have hf : ((n-r).factorial:ℝ)*(n.descFactorial r:ℝ) = n.factorial := - by exact_mod_cast Nat.factorial_mul_descFactorial hr - have hh := congrArg Real.log hf - rw [Real.log_mul (ne_of_gt hm) (ne_of_gt hd)] at hh - rw [Real.log_div (ne_of_gt hd) (ne_of_gt (pow_pos hn' r)),Real.log_pow] - unfold stirlingRemainder - by_cases hz : n-r=0 - · have hrn : r=n := by omega - subst r - simp only [Nat.sub_self,Nat.factorial_zero,Nat.cast_one,Real.log_one,Nat.cast_zero, - zero_mul,add_zero,sub_zero,Nat.descFactorial_self] - ring - · have hm' : (0:ℝ) < (n-r:ℕ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) - have he : ((n-r:ℕ):ℝ) = (n:ℝ)*(1-(r:ℝ)/n) := by - rw [Nat.cast_sub hr] - field_simp - have hρ : 0 < 1-(r:ℝ)/n := by - rw [←mul_pos_iff_of_pos_left hn',←he] - exact hm' - have hl : Real.log ((n-r:ℕ):ℝ) = Real.log n+Real.log (1-(r:ℝ)/n) := by - rw [he, Real.log_mul (ne_of_gt hn') (ne_of_gt hρ)] - rw [hl,Nat.cast_sub hr] - nlinarith [hh] - - -lemma normalization_le (d r : ℕ) (hd : 1 ≤ d) (hr : 1 ≤ r) (hrn : r ≤ 2^d) : - Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 ≤ - (r:ℝ)*(entropyCorrection ((r:ℝ)/(2:ℝ)^d)+unusedTail d) := by - have hnp : 0 < (2:ℕ)^d := by positivity - have hnr : (0:ℝ) < (2:ℝ)^d := by positivity - have hr' : (0:ℝ) < r := by exact_mod_cast hr - have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hh := stirlingRemainder_difference_bound hnp hrn - simp only [Nat.cast_pow,Nat.cast_ofNat] at hh - have hg := (stirlingRemainder_dyadic d hd).trans - ((div_le_iff₀ hnr).mp (unusedTail_lower d)) - have he : (stirlingRemainder (2^d)-stirlingRemainder (2^d-r))/Real.log 2 ≤ - (r:ℝ)*unusedTail d := by - calc - _ ≤ ((r:ℝ)/(2:ℝ)^d*stirlingRemainder (2^d))/Real.log 2 := - div_le_div_of_nonneg_right hh hl.le - _ = ((r:ℝ)/(2:ℝ)^d)*(stirlingRemainder (2^d)/Real.log 2) := by ring - _ ≤ ((r:ℝ)/(2:ℝ)^d)*(unusedTail d*(2:ℝ)^d) := - mul_le_mul_of_nonneg_left hg (by positivity) - _ = _ := by field_simp - have hid := factorial_error_identity hnp hrn - simp only [Nat.cast_pow,Nat.cast_ofNat] at hid - have heq : Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 = - (r:ℝ)*entropyCorrection ((r:ℝ)/(2:ℝ)^d)+ - (stirlingRemainder (2^d)-stirlingRemainder (2^d-r))/Real.log 2 := by - rw [hid,entropyCorrection,Nat.cast_sub hrn] - simp only [Nat.cast_pow,Nat.cast_ofNat] - field_simp - ring - rw [heq] - nlinarith - - -theorem dense_truncation : MainStatement := by - classical - intro ρ hρ ε hε - obtain ⟨t,ht,hm⟩ := palindrome_dense_mgf (ε/2) (by positivity) - refine ⟨t*ε/2, by positivity, ?_⟩ - intro d r hd hr hρr x - have hrn : r ≤ 2^d := by - have hh := Fintype.card_le_of_injective x x.injective - simpa only [Fintype.card_fin,card_positions] using hh - have hm' := hm d x (by simpa only [Fintype.card_fin] using (show 0 < r by omega)) - simp only [Fintype.card_fin,hρr] at hm' - have hn := normalization_le d r hd hr hrn - rw [hρr] at hn - let a : ℝ := r*(H ρ+entropyCorrection ρ+ε) - let b : ℝ := Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 - have hp (ω : BenesCoins d) : - (if a < densityExponent d r x ω then (1:ℝ) else 0) ≤ - Real.exp (t*palindromeCost d x ω)*Real.exp (t*(b-a)) := by - split_ifs with h - · rw [←Real.exp_add] - apply Real.one_le_exp_iff.mpr - have hh : 0 ≤ t*((palindromeCost d x ω:ℝ)+b-a) := by - apply mul_nonneg ht.le - exact sub_nonneg.mpr (le_of_lt h) - nlinarith - · positivity - have he : t*(r:ℝ)*(H ρ-unusedTail d+ε/2)+t*(b-a) ≤ -(t*ε/2)*r := by - have hh := mul_le_mul_of_nonneg_left hn ht.le - dsimp [b,a] - nlinarith [hh] - calc - _ ≤ finiteMean (fun ω : BenesCoins d => - Real.exp (t*palindromeCost d x ω)*Real.exp (t*(b-a))) := finiteMean_mono hp - _ = finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeCost d x ω))* - Real.exp (t*(b-a)) := finiteMean_mul_const _ _ - _ ≤ Real.exp (t*(r:ℝ)*(H ρ-unusedTail d+ε/2))*Real.exp (t*(b-a)) := - mul_le_mul_of_nonneg_right hm' (Real.exp_nonneg _) - _ ≤ Real.exp (-(t*ε/2)*r) := by rw [←Real.exp_add]; exact Real.exp_le_exp.mpr he - -end Thorp.DenseTruncation - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.SingleSlotsEquiv + +namespace OAI + +namespace ThorpNine.Dense + +open scoped BigOperators +namespace Thorp + +lemma sharedPartnerMean_nonneg (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + 0 ≤ sharedPartnerMean r s A := by + unfold sharedPartnerMean + positivity + +lemma sum_suffix_pair_counts (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + (∑ y : Card s, ((suffixMarks r (s+1) A (Fin.cons false y)).card + + (suffixMarks r (s+1) A (Fin.cons true y)).card)) = A.card := by + classical + have hh := sum_card_blockMarks ((cardSplit r (s+1)).trans (Equiv.prodComm _ _)) A + rw [←Equiv.sum_comp (headTailEquiv s).symm,Fintype.sum_prod_type,Fintype.sum_bool] at hh + simpa [suffixMarks,headTailEquiv,Fin.consEquiv,Finset.sum_add_distrib,add_comm] using hh + +lemma sharedPartnerMean_twice_le (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + 2*sharedPartnerMean r s A ≤ A.card := by + have hcap (y : Card (s+1)) : (suffixMarks r (s+1) A y).card ≤ 2^r := by + simpa only [card_positions] using Finset.card_le_univ (suffixMarks r (s+1) A y) + have hp : (0:ℝ) < (2:ℝ)^r := by positivity + rw [sharedPartnerMean,←mul_div_assoc,div_le_iff₀ hp,Finset.mul_sum] + have hs : (A.card:ℝ) = ∑ y : Card s, + ((suffixMarks r (s+1) A (Fin.cons false y)).card + + (suffixMarks r (s+1) A (Fin.cons true y)).card : ℝ) := by + exact_mod_cast (sum_suffix_pair_counts r s A).symm + rw [hs,Finset.sum_mul] + apply Finset.sum_le_sum + intro y _ + have h₀ : (suffixMarks r (s+1) A (Fin.cons false y)).card ≤ (2:ℝ)^r := by + exact_mod_cast hcap (Fin.cons false y) + have h₁ : (suffixMarks r (s+1) A (Fin.cons true y)).card ≤ (2:ℝ)^r := by + exact_mod_cast hcap (Fin.cons true y) + nlinarith [mul_nonneg (sub_nonneg.mpr h₀) + (Nat.cast_nonneg (suffixMarks r (s+1) A (Fin.cons true y)).card), + mul_nonneg (sub_nonneg.mpr h₁) + (Nat.cast_nonneg (suffixMarks r (s+1) A (Fin.cons false y)).card)] + + +lemma palindrome_level_dense_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card ((s+1)+r)) (t : ℝ) (ht : 0 ≤ t) : + finiteMean (fun ω : BenesCoins ((s+1)+r) => + Real.exp (t * palindromeLevelCost (s+1) ((s+1)+r) e ω)) ≤ + Real.exp ((Real.exp (denseLevelCoefficient s t)-1) * + sharedPartnerMean r s (Finset.univ.image e)) := by + classical + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun X : SwitchIndex ((s+1)+r) → Bool => + Real.exp (denseLevelCoefficient s t * sharedLevel (s+1) ((s+1)+r) e X)) := by + apply finiteMean_mono + intro X + exact palindrome_level_dense_conditional s ((s+1)+r) e X t ht + _ = finiteMean (fun hi : Card (s+1) × SwitchIndex r → Bool => + Real.exp (denseLevelCoefficient s t * + gridShared r s (inverseButterflyMarks ((s+1)+r) (Finset.univ.image e) + (assembleBits r (s+1) (fun _ => false) hi)))) := by + rw [finiteMean_split] + simp_rw [sharedLevel_partial_marks] + rw [finiteMean_const] + _ ≤ _ := partial_grid_mgf r s (Finset.univ.image e) _ + (denseLevelCoefficient_nonneg s ht) + + +lemma cardSplit_snd_apply (r s : ℕ) (x : Card (s+r)) (i : Fin s) : + (cardSplit r s x).2 i = x ⟨r+i,by omega⟩ := by + induction r with + | zero => simp [cardSplit] + | succ r ih => + change (cardSplit r s (Fin.tail x)).2 i = _ + rw [ih] + simp only [Fin.tail] + congr 1 + apply Fin.ext + simp only [Fin.val_succ] + omega + +def PairSeparated {d : ℕ} (i : Fin d) (x y : Card d) : Prop := + x i = false ∧ y i = true ∧ ∀ j : Fin d, i < j → x j = y j + +lemma PairSeparated.unique {d : ℕ} {i j : Fin d} {x y : Card d} + (hi : PairSeparated i x y) (hj : PairSeparated j x y) : i = j := by + by_contra h + rcases lt_or_gt_of_ne h with h | h + · have hh := hi.2.2 j h + rw [hj.1,hj.2.1] at hh + exact Bool.false_ne_true hh + · have hh := hj.2.2 i h + rw [hi.1,hi.2.1] at hh + exact Bool.false_ne_true hh + +lemma PairSeparated.not_reverse {d : ℕ} {i j : Fin d} {x y : Card d} + (hi : PairSeparated i x y) : ¬ PairSeparated j y x := by + intro hj + rcases lt_trichotomy i j with h | h | h + · have hh := hi.2.2 j h + rw [hj.2.1,hj.1] at hh + exact Bool.noConfusion hh + · subst j + exact Bool.false_ne_true (hi.1.symm.trans hj.2.1) + · have hh := hj.2.2 i h + rw [hi.1,hi.2.1] at hh + exact Bool.noConfusion hh + +lemma pairSeparated_split_iff (r s : ℕ) (x y : Card ((s+1)+r)) : + PairSeparated ⟨r,by omega⟩ x y ↔ + ∃ z : Card s, (cardSplit r (s+1) x).2 = Fin.cons false z ∧ + (cardSplit r (s+1) y).2 = Fin.cons true z := by + constructor + · intro h + refine ⟨Fin.tail (cardSplit r (s+1) x).2, ?_, ?_⟩ + · have h₀ : (cardSplit r (s+1) x).2 0 = false := by + simpa only [cardSplit_snd_apply,Fin.val_zero,Nat.add_zero] using h.1 + rw [←h₀,Fin.cons_self_tail] + · funext k + refine Fin.cases ?_ (fun k => ?_) k + · simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using h.2.1 + · simp only [Fin.cons_succ,Fin.tail,cardSplit_snd_apply] + exact (h.2.2 _ (by change r < r + (k.val+1); omega)).symm + · rintro ⟨z,hx,hy⟩ + refine ⟨?_,?_,?_⟩ + · have hh := congrFun hx 0 + simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using hh + · have hh := congrFun hy 0 + simpa only [cardSplit_snd_apply,Fin.cons_zero,Fin.val_zero,Nat.add_zero] using hh + · intro j hj + change r < j.val at hj + have hbound : j.val-r-1 < s := by omega + let k : Fin s := ⟨j.val-r-1,hbound⟩ + have hjk : j = ⟨r+(k.val+1),by omega⟩ := Fin.ext (by dsimp [k]; omega) + rw [hjk] + have hx' := congrFun hx k.succ + have hy' := congrFun hy k.succ + simp only [cardSplit_snd_apply,Fin.cons_succ] at hx' hy' + exact hx'.trans hy'.symm + + +abbrev SeparatedPair {d : ℕ} (A : Finset (Card d)) (i : Fin d) := + {p : A × A // PairSeparated i p.1.val p.2.val} + +noncomputable def separatedCount {d : ℕ} (A : Finset (Card d)) (i : Fin d) : ℕ := by + classical + exact Fintype.card (SeparatedPair A i) + +lemma separated_budget_strong {d : ℕ} (A : Finset (Card d)) : + 2 * ∑ i : Fin d, separatedCount A i ≤ A.card * (A.card-1) := by + classical + let F : Bool × (Σ i : Fin d, SeparatedPair A i) → A × A := + fun ⟨b,i,p⟩ => if b then (p.val.2,p.val.1) else p.val + have hF : Function.Injective F := by + rintro ⟨b,i,p⟩ ⟨c,j,q⟩ h + cases b <;> cases c + · change p.val = q.val at h + have hij : i = j := p.property.unique (by rw [h]; exact q.property) + subst j + have hpq : p = q := Subtype.ext h + subst q + rfl + · change p.val = (q.val.2,q.val.1) at h + have hp := p.property + rw [h] at hp + exact False.elim (hp.not_reverse q.property) + · change (p.val.2,p.val.1) = q.val at h + have hq := q.property + rw [←h] at hq + exact False.elim (hq.not_reverse p.property) + · change (p.val.2,p.val.1) = (q.val.2,q.val.1) at h + have hpq : p.val = q.val := Prod.ext (congrArg Prod.snd h) (congrArg Prod.fst h) + have hij : i = j := p.property.unique (by rw [hpq]; exact q.property) + subst j + have hpqq : p = q := Subtype.ext hpq + subst q + rfl + have hneq (v : Bool × (Σ i : Fin d, SeparatedPair A i)) : (F v).1 ≠ (F v).2 := by + obtain ⟨b,i,p⟩ := v + have hp : p.val.1 ≠ p.val.2 := by + intro he + have hx := p.property.1 + have hy := p.property.2.1 + rw [he] at hx + exact Bool.false_ne_true (hx.symm.trans hy) + cases b <;> simp [F,hp,Ne.symm hp] + let G : Bool × (Σ i : Fin d, SeparatedPair A i) → ↥((Finset.univ : Finset A).offDiag) := + fun v => ⟨F v,Finset.mem_offDiag.mpr ⟨Finset.mem_univ _,Finset.mem_univ _,hneq v⟩⟩ + have hG : Function.Injective G := fun _ _ he => hF (congrArg Subtype.val he) + have hh := Fintype.card_le_of_injective G hG + simpa only [Fintype.card_prod,Fintype.card_bool,Fintype.card_sigma, + Fintype.card_coe,separatedCount,Finset.offDiag_card,Finset.card_univ, + Nat.mul_sub_left_distrib,mul_one] using hh + +lemma separated_budget {d : ℕ} (A : Finset (Card d)) : + 2 * ∑ i : Fin d, separatedCount A i ≤ A.card * A.card := + (separated_budget_strong A).trans (Nat.mul_le_mul_left _ (Nat.sub_le _ _)) + +lemma mem_suffixMarks (r s : ℕ) (A : Finset (Card (s+r))) (y : Card s) (x : Card r) : + x ∈ suffixMarks r s A y ↔ (cardSplit r s).symm (x,y) ∈ A := by + exact mem_blockMarks _ _ _ _ + +lemma separatedCount_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + separatedCount A ⟨r,by omega⟩ = + ∑ y : Card s, (suffixMarks r (s+1) A (Fin.cons false y)).card * + (suffixMarks r (s+1) A (Fin.cons true y)).card := by + classical + let D := Σ y : Card s, ↥(suffixMarks r (s+1) A (Fin.cons false y)) × + ↥(suffixMarks r (s+1) A (Fin.cons true y)) + let F : D → SeparatedPair A ⟨r,by omega⟩ := fun ⟨y,u,v⟩ => + ⟨(⟨(cardSplit r (s+1)).symm (u.val,Fin.cons false y), + (mem_suffixMarks _ _ _ _ _).mp u.property⟩, + ⟨(cardSplit r (s+1)).symm (v.val,Fin.cons true y), + (mem_suffixMarks _ _ _ _ _).mp v.property⟩), + (pairSeparated_split_iff r s _ _).mpr + ⟨y,by simp only [Equiv.apply_symm_apply],by simp only [Equiv.apply_symm_apply]⟩⟩ + have hF : Function.Bijective F := by + constructor + · rintro ⟨y,u,v⟩ ⟨z,u',v'⟩ he + have h₀ := congrArg (fun p => cardSplit r (s+1) p.val.1.val) he + have h₁ := congrArg (fun p => cardSplit r (s+1) p.val.2.val) he + change cardSplit r (s+1) ((cardSplit r (s+1)).symm (u.val,Fin.cons false y)) = + cardSplit r (s+1) ((cardSplit r (s+1)).symm (u'.val,Fin.cons false z)) at h₀ + change cardSplit r (s+1) ((cardSplit r (s+1)).symm (v.val,Fin.cons true y)) = + cardSplit r (s+1) ((cardSplit r (s+1)).symm (v'.val,Fin.cons true z)) at h₁ + simp only [Equiv.apply_symm_apply] at h₀ h₁ + have hyz : y = z := by + have hh := congrArg (fun p => Fin.tail p.2) h₀ + simpa only [Fin.tail_cons] using hh + subst z + have hu : u = u' := Subtype.ext (congrArg Prod.fst h₀) + have hv : v = v' := Subtype.ext (congrArg Prod.fst h₁) + subst u'; subst v'; rfl + · intro p + obtain ⟨y,hx,hy⟩ := (pairSeparated_split_iff r s p.val.1.val p.val.2.val).mp p.property + have hx' : (cardSplit r (s+1)).symm ((cardSplit r (s+1) p.val.1.val).1,Fin.cons false y) = + p.val.1.val := by rw [←hx,Prod.mk.eta,Equiv.symm_apply_apply] + have hy' : (cardSplit r (s+1)).symm ((cardSplit r (s+1) p.val.2.val).1,Fin.cons true y) = + p.val.2.val := by rw [←hy,Prod.mk.eta,Equiv.symm_apply_apply] + refine ⟨⟨y,⟨(cardSplit r (s+1) p.val.1.val).1,?_⟩, + ⟨(cardSplit r (s+1) p.val.2.val).1,?_⟩⟩,?_⟩ + · rw [mem_suffixMarks,hx']; exact p.val.1.property + · rw [mem_suffixMarks,hy']; exact p.val.2.property + · apply Subtype.ext + exact Prod.ext (Subtype.ext hx') (Subtype.ext hy') + have hh := Fintype.card_congr (Equiv.ofBijective F hF) + simpa only [D,Fintype.card_sigma,Fintype.card_prod,Fintype.card_coe,separatedCount] using hh.symm + + +noncomputable def partnerMean (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := + if hj : j < d then (separatedCount A ⟨d-j-1,by omega⟩ : ℝ) / (2:ℝ)^(d-j-1) else 0 + +lemma partnerMean_nonneg (d : ℕ) (A : Finset (Card d)) (j : ℕ) : + 0 ≤ partnerMean d A j := by + unfold partnerMean + split <;> positivity + +lemma partnerMean_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + partnerMean ((s+1)+r) A s = sharedPartnerMean r s A := by + classical + have hs : s < (s+1)+r := by omega + have hr : (s+1+r)-s-1 = r := by omega + simp only [partnerMean,dite_eq_left hs,hr,separatedCount_eq,sharedPartnerMean, + Nat.cast_sum,Nat.cast_mul] + +lemma partnerMean_twice_le (d : ℕ) (A : Finset (Card d)) (j : ℕ) : + 2*partnerMean d A j ≤ A.card := by + by_cases hj : j < d + · obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le (Nat.succ_le_of_lt hj) + rw [partnerMean_eq] + exact sharedPartnerMean_twice_le r j A + · simp only [partnerMean,dite_eq_right hj,mul_zero,Nat.cast_nonneg] + +lemma partnerMean_rate (d : ℕ) (A : Finset (Card d)) (j : Fin d) : + partnerMean d A j / (2:ℝ)^(j.val+1) = + (separatedCount A j.rev : ℝ) / (2:ℝ)^d := by + have hj : j.val < d := j.isLt + have hd : (d-j.val-1)+(j.val+1) = d := by omega + simp only [partnerMean,dite_eq_left hj,div_div,←pow_add,hd] + rfl + +lemma partnerMean_budget (d : ℕ) (A : Finset (Card d)) : + 2 * (∑ j ∈ Finset.range d, partnerMean d A j / (2:ℝ)^(j+1)) ≤ + (A.card:ℝ)^2/(2:ℝ)^d := by + classical + rw [←Fin.sum_univ_eq_sum_range] + simp_rw [partnerMean_rate] + rw [←Finset.sum_div] + have he : (∑ j : Fin d, (separatedCount A j.rev:ℝ)) = ∑ j : Fin d, (separatedCount A j:ℝ) := by + exact Equiv.sum_comp (Fin.revPerm : Equiv.Perm (Fin d)) (fun j : Fin d => (separatedCount A j : ℝ)) + rw [he,←mul_div_assoc] + apply div_le_div_of_nonneg_right _ (by positivity) + exact_mod_cast (by simpa only [pow_two] using separated_budget A) + +noncomputable def partnerAllocation (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := + 2*partnerMean d A j/A.card + +lemma partnerAllocation_admissible (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + DenseTruncation.AdmissibleAllocation ((A.card:ℝ)/(2:ℝ)^d) (partnerAllocation d A) := by + classical + have hA' : (0:ℝ) < A.card := by exact_mod_cast hA + constructor + · intro j + constructor + · exact div_nonneg (mul_nonneg (by norm_num) (partnerMean_nonneg d A j)) hA'.le + · rw [partnerAllocation,div_le_one hA'] + exact partnerMean_twice_le d A j + · have hz (j : ℕ) (hj : j ∉ Finset.range d) : + partnerAllocation d A j/(2:ℝ)^(j+1) = 0 := by + have h : ¬ j < d := by simpa only [Finset.mem_range] using hj + simp only [partnerAllocation,partnerMean,dite_eq_right h,mul_zero,zero_div] + rw [tsum_eq_sum (s := Finset.range d) hz] + have he (j : ℕ) : partnerAllocation d A j/(2:ℝ)^(j+1) = + 2/A.card * (partnerMean d A j/(2:ℝ)^(j+1)) := by + unfold partnerAllocation + ring + simp_rw [he] + rw [←Finset.mul_sum] + have hh := partnerMean_budget d A + apply (show 2/(A.card:ℝ) * ∑ j ∈ Finset.range d, partnerMean d A j/(2:ℝ)^(j+1) = + (2*(∑ j ∈ Finset.range d,partnerMean d A j/(2:ℝ)^(j+1)))/A.card by ring).le.trans + apply (div_le_div_of_nonneg_right hh hA'.le).trans + have hne : (A.card:ℝ) ≠ 0 := ne_of_gt hA' + exact le_of_eq (by field_simp) + + +lemma partner_weighted_sum_le (d H : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ + A.card * DenseTruncation.H ((A.card:ℝ)/(2:ℝ)^d) := by + have ha := partnerAllocation_admissible d A hA + have hh := DenseTruncation.allocation_le_H ha + have hA' : (0:ℝ) < A.card := by exact_mod_cast hA + have he (j : ℕ) : DenseTruncation.h (j+1)*partnerMean d A j = + (A.card:ℝ)/2*(DenseTruncation.h (j+1)*partnerAllocation d A j) := by + unfold partnerAllocation + field_simp + simp_rw [he] + rw [←Finset.mul_sum] + calc + _ ≤ (A.card:ℝ)/2 * ∑' j, DenseTruncation.h (j+1)*partnerAllocation d A j := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact (DenseTruncation.allocation_value_summable ha).sum_le_tsum _ + (fun j _ => mul_nonneg (DenseTruncation.h_nonneg _) (ha.1 j).1) + _ = (A.card:ℝ)*((1/2:ℝ)*∑' j, DenseTruncation.h (j+1)*partnerAllocation d A j) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg _) + +lemma finiteMean_rpow_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (f : Ω → ℝ) (hf : ∀ ω, 0 ≤ f ω) {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) : + finiteMean (fun ω => (f ω)^p) ≤ (finiteMean f)^p := by + have hN : (0:ℝ) < Fintype.card Ω := Nat.cast_pos.mpr Fintype.card_pos + have hh := (Real.concaveOn_rpow hp hp1).le_map_sum + (t := Finset.univ) (w := fun _ : Ω => 1/(Fintype.card Ω:ℝ)) + (p := f) (fun _ _ => by positivity) + (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) + (fun ω _ => hf ω) + simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : Ω,_), + ←div_eq_mul_inv,finiteMean] using hh + +lemma finiteMean_exp_scale {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (f : Ω → ℝ) (a b t : ℝ) (hb : 0 < b) (ht : 0 ≤ t) (htb : t ≤ b) + (h : finiteMean (fun ω => Real.exp (b*f ω)) ≤ Real.exp (b*a)) : + finiteMean (fun ω => Real.exp (t*f ω)) ≤ Real.exp (t*a) := by + have hp : 0 ≤ t/b := div_nonneg ht hb.le + have hp1 : t/b ≤ 1 := (div_le_one hb).mpr htb + have hh := (finiteMean_rpow_le (fun ω => Real.exp (b*f ω)) + (fun _ => (Real.exp_pos _).le) hp hp1).trans + (Real.rpow_le_rpow (finiteMean_nonneg (fun _ => (Real.exp_pos _).le)) h hp) + have he (x : ℝ) : (Real.exp (b*x))^(t/b) = Real.exp (t*x) := by + rw [←Real.exp_mul] + congr 1 + field_simp + simpa only [he] using hh + +lemma finiteMean_exp_sum_le {Ω I : Type*} [Fintype Ω] [Nonempty Ω] + [Fintype I] [Nonempty I] (f : I → Ω → ℝ) (a : I → ℝ) (t : ℝ) + (h : ∀ i, finiteMean (fun ω => Real.exp ((Fintype.card I:ℝ)*t*f i ω)) ≤ + Real.exp ((Fintype.card I:ℝ)*t*a i)) : + finiteMean (fun ω => Real.exp (t*∑ i, f i ω)) ≤ Real.exp (t*∑ i, a i) := by + have hN : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos + let N : ℝ := Fintype.card I + have hc (i : I) : finiteMean (fun ω => Real.exp (N*t*(f i ω-a i))) ≤ 1 := by + have he (ω : Ω) : Real.exp (N*t*(f i ω-a i)) = + Real.exp (N*t*f i ω) * Real.exp (-(N*t*a i)) := by + rw [←Real.exp_add]; congr 1; ring + simp_rw [he] + rw [finiteMean_mul_const] + calc + _ ≤ Real.exp (N*t*a i)*Real.exp (-(N*t*a i)) := + mul_le_mul_of_nonneg_right (h i) (Real.exp_pos _).le + _ = 1 := by rw [←Real.exp_add,add_neg_cancel,Real.exp_zero] + have hj (ω : Ω) : Real.exp (t*(∑ i, (f i ω-a i))) ≤ + ∑ i, (1/N)*Real.exp (N*t*(f i ω-a i)) := by + have hh := convexOn_exp.map_sum_le + (t := Finset.univ) (w := fun _ : I => 1/N) + (p := fun i => N*t*(f i ω-a i)) + (fun _ _ => by dsimp [N]; positivity) + (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; dsimp [N]; field_simp) + (fun _ _ => Set.mem_univ _) + have he (i : I) : (1/N)*(N*t*(f i ω-a i)) = t*(f i ω-a i) := by + dsimp [N]; field_simp + simpa only [smul_eq_mul,he,←Finset.mul_sum] using hh + have hm : finiteMean (fun ω => Real.exp (t*(∑ i, (f i ω-a i)))) ≤ 1 := by + apply (finiteMean_mono hj).trans + rw [finiteMean_sum] + calc + _ ≤ ∑ _ : I, 1/N := by + apply Finset.sum_le_sum + intro i _ + have he (ω : Ω) : 1/N*Real.exp (N*t*(f i ω-a i)) = + Real.exp (N*t*(f i ω-a i))*(1/N) := mul_comm _ _ + simp_rw [he] + rw [finiteMean_mul_const] + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hc i) + (by dsimp [N]; positivity : 0 ≤ 1/N) + _ = 1 := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; dsimp [N]; field_simp + have he (ω : Ω) : Real.exp (t*∑ i,f i ω) = + Real.exp (t*(∑ i, (f i ω-a i)))*Real.exp (t*∑ i,a i) := by + rw [←Real.exp_add,Finset.sum_sub_distrib] + congr 1; ring + simp_rw [he] + rw [finiteMean_mul_const] + simpa only [one_mul] using mul_le_mul_of_nonneg_right hm (Real.exp_pos _).le + + +open Filter Topology + +lemma dense_coefficient_hasDerivAt (j : ℕ) : + HasDerivAt (fun t : ℝ => Real.exp (denseLevelCoefficient j t)-1) + (DenseTruncation.h (j+1)) 0 := by + have hp : (2:ℝ)^j ≠ 0 := by positivity + have h₀ := (hasDerivAt_id (0:ℝ)).mul_const ((2:ℝ)^j) + have h₁ := h₀.exp.sub_const 1 + have h₂ := h₁.div_const ((2:ℝ)^j) + have hh := h₂.const_mul (DenseTruncation.h (j+1)) + simpa [denseLevelCoefficient, hp] using hh.exp.sub_const 1 + +lemma dense_coefficient_small (H : ℕ) (δ : ℝ) (hδ : 0 < δ) : + ∃ τ : ℝ, 0 < τ ∧ τ ≤ 1/500 ∧ ∀ j < H, + Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ) := by + have hj (j : Fin H) : ∀ᶠ t : ℝ in 𝓝[>] 0, + (Real.exp (denseLevelCoefficient j t)-1)/t < DenseTruncation.h (j+1)+δ := by + have hh := (dense_coefficient_hasDerivAt j).tendsto_slope_zero_right + simp only [zero_add,denseLevelCoefficient,zero_mul,Real.exp_zero,sub_self,zero_div, + mul_zero,smul_eq_mul,sub_zero] at hh + have hh' : Tendsto (fun t : ℝ => (Real.exp (denseLevelCoefficient j t)-1)/t) + (𝓝[>] 0) (𝓝 (DenseTruncation.h (j+1))) := by + simpa only [denseLevelCoefficient,div_eq_mul_inv,mul_comm] using hh + exact (tendsto_order.mp hh').2 _ (by linarith) + have ha : ∀ᶠ t : ℝ in 𝓝[>] 0, ∀ j : Fin H, + (Real.exp (denseLevelCoefficient j t)-1)/t < DenseTruncation.h (j+1)+δ := + Filter.eventually_all.mpr hj + have hb : ∀ᶠ t : ℝ in 𝓝[>] 0, t < 1/500 := + (eventually_lt_nhds (by norm_num : (0:ℝ) < 1/500)).filter_mono nhdsWithin_le_nhds + have hc : ∀ᶠ t : ℝ in 𝓝[>] 0, 0 < t := self_mem_nhdsWithin + obtain ⟨τ,ht,hb,ha⟩ := (hc.and (hb.and ha)).exists + refine ⟨τ,ht,hb.le,fun j hj => ?_⟩ + exact ((div_lt_iff₀ ht).mp (ha ⟨j,hj⟩)).le.trans_eq (mul_comm _ _) + +lemma palindrome_level_dense_mgf_all (d j : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (t : ℝ) (ht : 0 ≤ t) : + finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeLevelCost (j+1) d e ω)) ≤ + Real.exp ((Real.exp (denseLevelCoefficient j t)-1)*partnerMean d (Finset.univ.image e) j) := by + classical + by_cases hj : j < d + · obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le (Nat.succ_le_of_lt hj) + rw [partnerMean_eq] + exact palindrome_level_dense_mgf r j e t ht + · simp only [palindromeLevelCost_gt (j+1) d (by omega) e, Nat.cast_zero,mul_zero, + Real.exp_zero,finiteMean_const,partnerMean,dite_eq_right hj,le_refl] + +lemma palindrome_low_dense_mgf (H : ℕ) (hH : 0 < H) (δ τ : ℝ) (hδ : 0 ≤ δ) (ht : 0 ≤ τ) + (hτ : ∀ j < H, Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ)) + (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (hι : 0 < Fintype.card ι) : + finiteMean (fun ω : BenesCoins d => Real.exp ((τ/H)*palindromeLowCost H d e ω)) ≤ + Real.exp ((τ/H)*Fintype.card ι* + (DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)+H*δ/2)) := by + classical + let A := Finset.univ.image e + have hA : A.card = Fintype.card ι := by simp [A, Finset.card_image_of_injective _ e.injective] + have hn : (H:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hH) + have he : (H:ℝ)*(τ/H) = τ := by field_simp + let : Nonempty (Fin H) := Fin.pos_iff_nonempty.mp hH + have hh := finiteMean_exp_sum_le + (fun j : Fin H => fun ω : BenesCoins d => (palindromeLevelCost (j+1) d e ω:ℝ)) + (fun j : Fin H => (DenseTruncation.h (j+1)+δ)*partnerMean d A j) (τ/H) (by + intro j + simp only [Fintype.card_fin,he] + apply (palindrome_level_dense_mgf_all d j e τ ht).trans + apply Real.exp_le_exp.mpr + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hτ j j.isLt) + (partnerMean_nonneg d A j)) + have hsum : (∑ j : Fin H, (DenseTruncation.h (j+1)+δ)*partnerMean d A j) ≤ + Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)+H*δ/2) := by + rw [Fin.sum_univ_eq_sum_range (fun j => (DenseTruncation.h (j+1)+δ)*partnerMean d A j)] + simp_rw [add_mul] + rw [Finset.sum_add_distrib] + have hm := partner_weighted_sum_le d H A (by omega) + rw [hA] at hm + have hs : (∑ j ∈ Finset.range H, δ*partnerMean d A j) ≤ (H:ℝ)*δ*(Fintype.card ι)/2 := by + calc + _ ≤ ∑ _j ∈ Finset.range H, δ*((Fintype.card ι:ℝ)/2) := by + apply Finset.sum_le_sum + intro j _ + apply mul_le_mul_of_nonneg_left _ hδ + have hg := partnerMean_twice_le d A j + rw [hA] at hg + linarith + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring + nlinarith + have hh' := hh.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by positivity))) + have hl (ω : BenesCoins d) : + (∑ j : Fin H, (palindromeLevelCost (j+1) d e ω : ℝ)) = + ∑ j ∈ Finset.range H, (palindromeLevelCost (j+1) d e ω : ℝ) := + Fin.sum_univ_eq_sum_range (fun j => (palindromeLevelCost (j+1) d e ω : ℝ)) H + simpa only [palindromeLowCost_sum,Nat.cast_sum,hl,mul_assoc] using hh' + + +lemma heightDecay_tendsto : Tendsto heightDecay atTop (𝓝 0) := by + have hr : 0 ≤ Real.exp (-(1:ℝ)/64) := (Real.exp_pos _).le + have hr1 : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hh := ((tendsto_pow_atTop_nhds_zero_of_lt_one hr hr1).const_mul 68).div_const + (1-Real.exp (-(1:ℝ)/64)) + have he (H : ℕ) : (Real.exp (-(1:ℝ)/64))^H = Real.exp (-(H:ℝ)/64) := by + rw [←Real.exp_nat_mul] + congr 1; ring + change Tendsto (fun H : ℕ => 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64))) _ _ + simpa only [he,mul_zero,zero_div] using hh + +lemma heightDecay_exists {ε : ℝ} (hε : 0 < ε) : + ∃ H : ℕ, 0 < H ∧ 500*heightDecay H < ε := by + have hh := heightDecay_tendsto.const_mul 500 + simp only [mul_zero] at hh + have he := (tendsto_order.mp hh).2 ε hε + exact ((eventually_gt_atTop 0).and he).exists + +lemma palindrome_high_exp_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (t : ℝ) (ht : 0 ≤ t) (htb : t ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => Real.exp (t* + (palindromeFamilyCost H n d e ω+palindromeFamilyCost (2*H) n d e ω))) ≤ + Real.exp (t*Fintype.card ι*(500*heightDecay H)) := by + have hh := palindrome_high_full_mgf H n d hH e (Real.exp (1/500)) + (Real.one_le_exp_iff.mpr (by norm_num)) (by rw [Real.log_exp]) + have hp : finiteMean (fun ω : BenesCoins d => Real.exp ((1/500:ℝ)* + (palindromeFamilyCost H n d e ω+palindromeFamilyCost (2*H) n d e ω))) ≤ + Real.exp ((1/500:ℝ)*(Fintype.card ι*(500*heightDecay H))) := by + have he (k : ℕ) : (Real.exp (1/500:ℝ))^k = Real.exp ((1/500:ℝ)*k) := by + rw [←Real.exp_nat_mul]; congr 1; ring + simpa only [he,Nat.cast_add,show (1/500:ℝ)*(Fintype.card ι*(500*heightDecay H)) = + Fintype.card ι*heightDecay H by ring] using hh + have hs := finiteMean_exp_scale + (fun ω : BenesCoins d => ((palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω):ℝ)) + (Fintype.card ι*(500*heightDecay H)) (1/500) t (by norm_num) ht htb + (by simpa only [Nat.cast_add] using hp) + simpa only [Nat.cast_add,mul_assoc] using hs + +end Thorp + +namespace Thorp.DenseTruncation + +lemma harmonic_le_h (j : ℕ) : + (harmonic (2^j):ℝ)/(2:ℝ)^j ≤ h (j+1) := by + classical + let M := 2^j + have hM : 0 < M := by dsimp [M]; positivity + have hM' : (0:ℝ) < M := Nat.cast_pos.mpr hM + have hMc : (M:ℝ) = (2:ℝ)^j := by simp [M] + let p : ℕ → ℝ := fun l => if l < M then 1/M else 0 + have hp : AdmissibleCycleLaw (j+1) p := by + refine ⟨fun l => by dsimp [p]; split_ifs <;> positivity, ?_, ?_⟩ + · have hs : HasSum p (∑ l ∈ Finset.range M,p l) := + hasSum_sum_of_ne_finset_zero (s := Finset.range M) (f := p) + (fun l hl => by simp only [Finset.mem_range] at hl; simp [p,hl]) + have he : (∑ l ∈ Finset.range M,p l) = 1 := by + simp only [p] + rw [Finset.sum_congr rfl (fun l hl => ite_eq_left (Finset.mem_range.mp hl))] + simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + field_simp + exact he ▸ hs + · intro l + simp only [Nat.add_sub_cancel] + by_cases hl : l < M + · simp only [p,ite_eq_left hl,←hMc] + apply div_le_div_of_nonneg_right _ hM'.le + exact_mod_cast Nat.succ_pos l + · simp only [p,ite_eq_right hl] + positivity + have he : (∑' l, p l / ((l+1:ℕ):ℝ)) = (harmonic M:ℝ)/(M:ℝ) := by + rw [tsum_eq_sum (s := Finset.range M) (fun l hl => by + simp only [Finset.mem_range] at hl; simp [p,hl])] + simp only [harmonic,Rat.cast_sum,Rat.cast_inv,Rat.cast_natCast,Finset.sum_div] + apply Finset.sum_congr rfl + intro l hl + simp only [p,ite_eq_left (Finset.mem_range.mp hl)] + ring + have hh := reciprocal_le_h hp + rw [he,hMc] at hh + exact hh + +lemma harmonic_lower (m : ℕ) (hm : 0 < m) : + Real.log m+1/2 ≤ (harmonic m:ℝ) := by + have hh := Real.one_half_lt_eulerMascheroniConstant.trans + (Real.eulerMascheroniConstant_lt_eulerMascheroniSeq' m) + simp only [Real.eulerMascheroniSeq',ite_eq_right (ne_of_gt hm)] at hh + linarith + +lemma h_log_lower (j : ℕ) : + ((j:ℝ)*Real.log 2+1/2)/(2:ℝ)^j ≤ h (j+1) := by + have hh := harmonic_lower (2^j) (by positivity) + rw [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh + exact (div_le_div_of_nonneg_right hh (by positivity)).trans (harmonic_le_h j) + +noncomputable def unusedTail (d : ℕ) : ℝ := + (1/2:ℝ)*∑' j : ℕ, h (d+j+1) + +lemma unusedTail_nonneg (d : ℕ) : 0 ≤ unusedTail d := by + apply mul_nonneg (by norm_num) + exact tsum_nonneg (fun j => h_nonneg _) + +lemma unusedTail_lower (d : ℕ) : + ((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d ≤ unusedTail d := by + have hg := hasSum_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) + have hj := hasSum_coe_mul_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) + norm_num at hg hj + have hs : HasSum (fun j : ℕ => (((d+j:ℕ):ℝ)*Real.log 2+1/2)/(2:ℝ)^(d+j)) + (2*((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d) := by + convert! ((hg.mul_left ((d:ℝ)*Real.log 2+1/2)).add + (hj.mul_left (Real.log 2))).div_const ((2:ℝ)^d) using 1 + · funext j + simp only [Nat.cast_add,pow_add,div_pow,one_pow] + ring + · ring + have hsum : Summable (fun j : ℕ => h (d+j+1)) := by + simpa only [Nat.add_comm d] using (summable_nat_add_iff d).mpr h_summable + have hh := hs.summable.tsum_le_tsum (fun j => h_log_lower (d+j)) hsum + rw [hs.tsum_eq] at hh + unfold unusedTail + calc + _ = (1/2:ℝ)*(2*((d+1:ℝ)*Real.log 2+1/2)/(2:ℝ)^d) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by norm_num) + +end Thorp.DenseTruncation + +namespace Thorp + +lemma partnerMean_budget_strong (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + 2 * (∑ j ∈ Finset.range d, partnerMean d A j / (2:ℝ)^(j+1)) ≤ + (A.card:ℝ)*(A.card-1)/(2:ℝ)^d := by + classical + rw [←Fin.sum_univ_eq_sum_range] + simp_rw [partnerMean_rate] + rw [←Finset.sum_div] + have he : (∑ j : Fin d, (separatedCount A j.rev:ℝ)) = ∑ j : Fin d, (separatedCount A j:ℝ) := by + exact Equiv.sum_comp (Fin.revPerm : Equiv.Perm (Fin d)) (fun j : Fin d => (separatedCount A j : ℝ)) + rw [he,←mul_div_assoc] + apply div_le_div_of_nonneg_right _ (by positivity) + have hh : (2:ℝ)*(∑ i : Fin d,(separatedCount A i:ℝ)) ≤ + (A.card:ℝ)*((A.card-1:ℕ):ℝ) := by exact_mod_cast separated_budget_strong A + simpa only [Nat.cast_sub (show 1 ≤ A.card by omega),Nat.cast_one] using hh + +lemma partnerAllocation_range_budget (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + (∑ j ∈ Finset.range d, partnerAllocation d A j/(2:ℝ)^(j+1)) ≤ + ((A.card:ℝ)-1)/(2:ℝ)^d := by + have hp : (0:ℝ) < A.card := Nat.cast_pos.mpr hA + have he (j : ℕ) : partnerAllocation d A j/(2:ℝ)^(j+1) = + (2*partnerMean d A j/(2:ℝ)^(j+1))/A.card := by unfold partnerAllocation; ring + simp_rw [he] + rw [←Finset.sum_div] + simp_rw [mul_div_assoc] + rw [←Finset.mul_sum] + apply (div_le_div_of_nonneg_right (partnerMean_budget_strong d A hA) hp.le).trans + exact le_of_eq (by field_simp) + +lemma dyadic_weights_hasSum (d : ℕ) : + HasSum (fun j : ℕ => 1/(2:ℝ)^(d+j+1)) (1/(2:ℝ)^d) := by + have hg := hasSum_geometric_of_norm_lt_one (show ‖(1/2:ℝ)‖ < 1 by norm_num) + norm_num at hg + convert! hg.div_const ((2:ℝ)^(d+1)) using 1 + · funext j + simp only [pow_add,div_pow,one_pow,pow_one] + ring + · simp only [pow_succ] + field_simp + +noncomputable def augmentedAllocation (d : ℕ) (A : Finset (Card d)) (j : ℕ) : ℝ := + if j < d then partnerAllocation d A j else 1 + +lemma augmentedAllocation_bounds (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) (j : ℕ) : + 0 ≤ augmentedAllocation d A j ∧ augmentedAllocation d A j ≤ 1 := by + unfold augmentedAllocation + split_ifs + · exact (partnerAllocation_admissible d A hA).1 j + · norm_num + +lemma augmentedAllocation_admissible (d : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + DenseTruncation.AdmissibleAllocation ((A.card:ℝ)/(2:ℝ)^d) (augmentedAllocation d A) := by + classical + refine ⟨augmentedAllocation_bounds d A hA,?_⟩ + have hs : Summable (fun j => augmentedAllocation d A j/(2:ℝ)^(j+1)) := by + apply Summable.of_nonneg_of_le (fun j => div_nonneg (augmentedAllocation_bounds d A hA j).1 + (by positivity)) (fun j => div_le_div_of_nonneg_right (augmentedAllocation_bounds d A hA j).2 + (by positivity)) + simpa only [Nat.zero_add] using (dyadic_weights_hasSum 0).summable + have hh := hs.sum_add_tsum_nat_add d + have ht : (∑' j, augmentedAllocation d A (j+d)/(2:ℝ)^(j+d+1)) = 1/(2:ℝ)^d := by + have he (j : ℕ) : augmentedAllocation d A (j+d)/(2:ℝ)^(j+d+1) = 1/(2:ℝ)^(d+j+1) := by + rw [augmentedAllocation,ite_eq_right (show ¬j+d by rw [augmentedAllocation,ite_eq_left (Finset.mem_range.mp hj)]) + rw [←hh,ht,hf] + apply (add_le_add (partnerAllocation_range_budget d A hA) (le_refl ((1:ℝ)/2^d))).trans + exact le_of_eq (by ring) + +lemma partner_weighted_sum_gap (d H : ℕ) (A : Finset (Card d)) (hA : 0 < A.card) : + (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ + A.card * (DenseTruncation.H ((A.card:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d) := by + classical + have ha := augmentedAllocation_admissible d A hA + have hs := DenseTruncation.allocation_value_summable ha + have HH := DenseTruncation.allocation_le_H ha + have he := hs.sum_add_tsum_nat_add d + have ht : (∑' j, DenseTruncation.h (j+d+1)*augmentedAllocation d A (j+d)) = + ∑' j, DenseTruncation.h (d+j+1) := by + congr 1 + funext j + rw [augmentedAllocation,ite_eq_right (show ¬j+d DenseTruncation.h (j+1)*partnerMean d A j) := + (hasSum_sum_of_ne_finset_zero hz : HasSum _ + (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)).summable + have hlow : (∑ j ∈ Finset.range H, DenseTruncation.h (j+1)*partnerMean d A j) ≤ + ∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j := by + calc + _ ≤ ∑' j, DenseTruncation.h (j+1)*partnerMean d A j := + hsum.sum_le_tsum _ (fun j _ => mul_nonneg (DenseTruncation.h_nonneg _) + (partnerMean_nonneg _ _ _)) + _ = _ := tsum_eq_sum hz + have hp : (0:ℝ) < A.card := Nat.cast_pos.mpr hA + have HH' := mul_le_mul_of_nonneg_left HH hp.le + have HE : (A.card:ℝ)*((1/2:ℝ)*((2/(A.card:ℝ))* + (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)+ + ∑' j, DenseTruncation.h (d+j+1))) = + (∑ j ∈ Finset.range d, DenseTruncation.h (j+1)*partnerMean d A j)+ + (A.card:ℝ)*((1/2:ℝ)*∑' j, DenseTruncation.h (d+j+1)) := by + field_simp + rw [HE] at HH' + unfold DenseTruncation.unusedTail + exact hlow.trans (by nlinarith [HH']) + + +lemma palindrome_low_dense_mgf_gap (H : ℕ) (hH : 0 < H) (δ τ : ℝ) (hδ : 0 ≤ δ) (ht : 0 ≤ τ) + (hτ : ∀ j < H, Real.exp (denseLevelCoefficient j τ)-1 ≤ τ*(DenseTruncation.h (j+1)+δ)) + (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (hι : 0 < Fintype.card ι) : + finiteMean (fun ω : BenesCoins d => Real.exp ((τ/H)*palindromeLowCost H d e ω)) ≤ + Real.exp ((τ/H)*Fintype.card ι* + (DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d+H*δ/2)) := by + classical + let A := Finset.univ.image e + have hA : A.card = Fintype.card ι := by simp [A, Finset.card_image_of_injective _ e.injective] + have hn : (H:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hH) + have he : (H:ℝ)*(τ/H) = τ := by field_simp + let : Nonempty (Fin H) := Fin.pos_iff_nonempty.mp hH + have hh := finiteMean_exp_sum_le + (fun j : Fin H => fun ω : BenesCoins d => (palindromeLevelCost (j+1) d e ω:ℝ)) + (fun j : Fin H => (DenseTruncation.h (j+1)+δ)*partnerMean d A j) (τ/H) (by + intro j + simp only [Fintype.card_fin,he] + apply (palindrome_level_dense_mgf_all d j e τ ht).trans + apply Real.exp_le_exp.mpr + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hτ j j.isLt) + (partnerMean_nonneg d A j)) + have hsum : (∑ j : Fin H, (DenseTruncation.h (j+1)+δ)*partnerMean d A j) ≤ + Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)-DenseTruncation.unusedTail d+H*δ/2) := by + rw [Fin.sum_univ_eq_sum_range (fun j => (DenseTruncation.h (j+1)+δ)*partnerMean d A j)] + simp_rw [add_mul] + rw [Finset.sum_add_distrib] + have hm := partner_weighted_sum_gap d H A (by omega) + rw [hA] at hm + have hs : (∑ j ∈ Finset.range H, δ*partnerMean d A j) ≤ (H:ℝ)*δ*(Fintype.card ι)/2 := by + calc + _ ≤ ∑ _j ∈ Finset.range H, δ*((Fintype.card ι:ℝ)/2) := by + apply Finset.sum_le_sum + intro j _ + apply mul_le_mul_of_nonneg_left _ hδ + have hg := partnerMean_twice_le d A j + rw [hA] at hg + linarith + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring + nlinarith + have hh' := hh.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by positivity))) + have hl (ω : BenesCoins d) : + (∑ j : Fin H, (palindromeLevelCost (j+1) d e ω : ℝ)) = + ∑ j ∈ Finset.range H, (palindromeLevelCost (j+1) d e ω : ℝ) := + Fin.sum_univ_eq_sum_range (fun j => (palindromeLevelCost (j+1) d e ω : ℝ)) H + simpa only [palindromeLowCost_sum,Nat.cast_sum,hl,mul_assoc] using hh' + + +lemma palindrome_dense_mgf (ε : ℝ) (hε : 0 < ε) : + ∃ t : ℝ, 0 < t ∧ ∀ d : ℕ, ∀ {ι : Type} [Fintype ι], + ∀ e : ι ↪ Card d, 0 < Fintype.card ι → + finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeCost d e ω)) ≤ + Real.exp (t*Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)- + DenseTruncation.unusedTail d+ε)) := by + obtain ⟨H,hH,hdecay⟩ := heightDecay_exists (show 0 < ε/2 by positivity) + have hHr : (0:ℝ) < H := Nat.cast_pos.mpr hH + let δ := ε/H + have hδ : 0 < δ := div_pos hε hHr + obtain ⟨τ,ht,hτb,hτ⟩ := dense_coefficient_small H δ hδ + let t := (τ/H)/2 + have htp : 0 < t := by dsimp [t]; positivity + have hσb : τ/H ≤ 1/500 := by + apply (div_le_self ht.le (by exact_mod_cast hH)).trans hτb + refine ⟨t,htp,?_⟩ + intro d ι _ e he + have hlow := palindrome_low_dense_mgf_gap H hH δ τ hδ.le ht.le hτ d e he + have hhigh := palindrome_high_exp_mgf H d d hH e (τ/H) (by positivity) hσb + have hex (k : ℝ) : (Real.exp (t*k))^2 = Real.exp ((τ/H)*k) := by + rw [←Real.exp_nat_mul] + congr 1 + dsimp [t] + ring + have hh := finiteMean_mul_exp_le + (fun ω : BenesCoins d => Real.exp (t*palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => Real.exp (t*(palindromeFamilyCost H d d e ω+ + palindromeFamilyCost (2*H) d d e ω))) + ((τ/H)*Fintype.card ι*(DenseTruncation.H ((Fintype.card ι:ℝ)/(2:ℝ)^d)- + DenseTruncation.unusedTail d+H*δ/2)) + ((τ/H)*Fintype.card ι*(500*heightDecay H)) + (by simpa only [hex] using hlow) + (by simpa only [hex,Nat.cast_add] using hhigh) + have hd : d ≤ H*4^d := by + have hg := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hc := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hc + simpa only [Nat.add_assoc] using hc.symm + have hf (ω : BenesCoins d) : Real.exp (t*palindromeCost d e ω) = + Real.exp (t*palindromeLowCost H d e ω)* + Real.exp (t*(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) := by + rw [hcost,Nat.cast_add,Nat.cast_add,mul_add,Real.exp_add] + simp_rw [←hf] at hh + apply hh.trans + apply Real.exp_le_exp.mpr + have heδ : (H:ℝ)*δ/2=ε/2 := by dsimp [δ]; field_simp + rw [heδ] + have hc : (ε/2+500*heightDecay H) ≤ ε := by linarith + have hm := mul_le_mul_of_nonneg_left hc (show 0 ≤ t*(Fintype.card ι) by positivity) + dsimp [t] at hm ⊢ + nlinarith [hm] + +end Thorp + +open scoped BigOperators +namespace Thorp.DenseTruncation + +noncomputable def stirlingRemainder (n : ℕ) : ℝ := + Real.log (n.factorial:ℝ) - n*Real.log n+n + +lemma stirlingRemainder_zero : stirlingRemainder 0 = 0 := by + simp [stirlingRemainder] + +lemma stirlingRemainder_step (n : ℕ) : + stirlingRemainder (n+1)-stirlingRemainder n = + 1-(n:ℝ)*(Real.log (n+1)-Real.log n) := by + have hn : (0:ℝ) < n+1 := by positivity + have hf : (0:ℝ) < n.factorial := Nat.cast_pos.mpr (Nat.factorial_pos n) + rw [stirlingRemainder,stirlingRemainder,Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one, + Real.log_mul (ne_of_gt hn) (ne_of_gt hf)] + ring + +lemma log_increment_mul_monotone : + Monotone (fun n : ℕ => (n:ℝ)*(Real.log (n+1)-Real.log n)) := by + intro m n hmn + have hm : (0:ℝ) ≤ m := Nat.cast_nonneg _ + have hn : (0:ℝ) ≤ n := Nat.cast_nonneg _ + have hmn' : (m:ℝ) ≤ n := by exact_mod_cast hmn + by_cases hm0 : m = 0 + · subst m + simp only [Nat.cast_zero,zero_mul] + by_cases hn0 : n = 0 + · simp [hn0] + · have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn0) + exact mul_nonneg hn (sub_nonneg.mpr (Real.log_le_log hnpos (by linarith))) + have hmpos : (0:ℝ) < m := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hm0) + have hnpos : (0:ℝ) < n := lt_of_lt_of_le hmpos hmn' + have ha : 0 ≤ (m:ℝ)/n := div_nonneg hm hn + have hb : 0 ≤ 1-(m:ℝ)/n := by rw [sub_nonneg,div_le_one hnpos]; exact hmn' + have hc := strictConcaveOn_log_Ioi.concaveOn.2 + (show (m+1:ℝ)/m ∈ Set.Ioi 0 by exact div_pos (by positivity) hmpos) + (show (1:ℝ) ∈ Set.Ioi 0 by norm_num) ha hb + (show (m:ℝ)/n+(1-(m:ℝ)/n) = 1 by ring) + have he : (m:ℝ)/n*((m+1)/m)+(1-(m:ℝ)/n)*1 = (n+1)/n := by + field_simp + ring + simp only [smul_eq_mul,Real.log_one,mul_zero,add_zero,he] at hc + rw [Real.log_div (by positivity : (m+1:ℝ) ≠ 0) (ne_of_gt hmpos), + Real.log_div (by positivity : (n+1:ℝ) ≠ 0) (ne_of_gt hnpos)] at hc + have hc' := mul_le_mul_of_nonneg_left hc hn + have he' : (n:ℝ)*((m:ℝ)/n*(Real.log (m+1)-Real.log m)) = + m*(Real.log (m+1)-Real.log m) := by field_simp + simpa only [he'] using hc' + +lemma stirlingRemainder_increment_antitone : + Antitone (fun n : ℕ => stirlingRemainder (n+1)-stirlingRemainder n) := by + intro m n hmn + simp only [stirlingRemainder_step] + linarith [log_increment_mul_monotone hmn] + +lemma stirlingRemainder_upper {n : ℕ} (hn : 0 < n) : + stirlingRemainder n ≤ 1+Real.log n/2 := by + obtain ⟨m,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (ne_of_gt hn) + have hm : (0:ℝ) < m+1 := by positivity + have he : Real.log (2*((m+1):ℝ)) = Real.log 2+Real.log (m+1) := + Real.log_mul (by norm_num) (ne_of_gt hm) + have hh := Stirling.log_stirlingSeq'_antitone (show 0 ≤ m by omega) + change Real.log (Stirling.stirlingSeq (m+1)) ≤ Real.log (Stirling.stirlingSeq 1) at hh + rw [Stirling.log_stirlingSeq_formula,Stirling.log_stirlingSeq_formula] at hh + simp only [Nat.cast_add,Nat.cast_one,he,Nat.factorial_one,Real.log_one,mul_one, + Real.log_div (ne_of_gt hm) (ne_of_gt (Real.exp_pos 1)),Real.log_exp, + Real.log_div (by norm_num : (1:ℝ) ≠ 0) (ne_of_gt (Real.exp_pos 1))] at hh + dsimp [stirlingRemainder] + push_cast + linarith + +lemma stirlingRemainder_sum (n : ℕ) : + (∑ i ∈ Finset.range n, (stirlingRemainder (i+1)-stirlingRemainder i)) = + stirlingRemainder n := by + induction n with + | zero => simp [stirlingRemainder_zero] + | succ n ih => rw [Finset.sum_range_succ,ih]; ring + +lemma stirlingRemainder_step_bound (n : ℕ) : + (n:ℝ)*(stirlingRemainder (n+1)-stirlingRemainder n) ≤ stirlingRemainder n := by + calc + _ = ∑ _i ∈ Finset.range n, (stirlingRemainder (n+1)-stirlingRemainder n) := by + simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + _ ≤ ∑ i ∈ Finset.range n, (stirlingRemainder (i+1)-stirlingRemainder i) := by + exact Finset.sum_le_sum fun i hi => stirlingRemainder_increment_antitone + (Nat.le_of_lt (Finset.mem_range.mp hi)) + _ = _ := stirlingRemainder_sum n + +lemma stirlingRemainder_average_antitone : + Antitone (fun n : ℕ => stirlingRemainder (n+1)/(n+1)) := by + apply antitone_nat_of_succ_le + intro n + have h₁ : (0:ℝ) < n+1 := by positivity + have h₂ : (0:ℝ) < n+1+1 := by positivity + push_cast + rw [div_le_div_iff₀ h₂ h₁] + have hh := stirlingRemainder_step_bound (n+1) + push_cast at hh ⊢ + nlinarith + +lemma stirlingRemainder_difference_bound {n r : ℕ} (hn : 0 < n) (hr : r ≤ n) : + stirlingRemainder n-stirlingRemainder (n-r) ≤ (r:ℝ)/n*stirlingRemainder n := by + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have he : (n-r:ℕ)+r=n := Nat.sub_add_cancel hr + by_cases hm : n-r=0 + · have hn_eq : n=r := by omega + subst n + simp [stirlingRemainder_zero,div_self (ne_of_gt hn')] + · obtain ⟨m,hm'⟩ := Nat.exists_eq_succ_of_ne_zero hm + obtain ⟨q,hq⟩ := Nat.exists_eq_succ_of_ne_zero (ne_of_gt hn) + have hmq : m ≤ q := by omega + have hh := stirlingRemainder_average_antitone hmq + have hposm : (0:ℝ) < m+1 := by positivity + have hposq : (0:ℝ) < q+1 := by positivity + rw [div_le_div_iff₀ hposq hposm] at hh + have he' : (m:ℝ)+1+r=q+1 := by exact_mod_cast (show m+1+r=q+1 by omega) + rw [hm',hq] + push_cast + rw [div_mul_eq_mul_div,le_div_iff₀ hposq] + simp only [Nat.succ_eq_add_one] at * + have heq : (m:ℝ)+1 = (q+1:ℝ)-r := by linarith + rw [heq] at hh + nlinarith + +lemma stirlingRemainder_dyadic (d : ℕ) (hd : 1 ≤ d) : + stirlingRemainder (2^d)/Real.log 2 ≤ (d+1:ℝ)*Real.log 2+1/2 := by + have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlog : (6931/10000:ℝ) < Real.log 2 := lt_trans (by norm_num) Real.log_two_gt_d9 + rw [div_le_iff₀ hl] + by_cases hd1 : d=1 + · subst d + norm_num [stirlingRemainder] + nlinarith [sq_nonneg (Real.log 2-6931/10000)] + · have hd2 : (2:ℝ) ≤ d := by exact_mod_cast (show 2 ≤ d by omega) + have hh := stirlingRemainder_upper (n := 2^d) (by positivity) + rw [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh + have hq : 0 ≤ Real.log 2*Real.log 2-Real.log 2/2 := by + nlinarith [sq_nonneg (Real.log 2-6931/10000)] + have hprod := mul_nonneg (sub_nonneg.mpr hd2) hq + nlinarith [sq_nonneg (Real.log 2-6931/10000)] + +lemma factorial_error_identity {n r : ℕ} (hn : 0 < n) (hr : r ≤ n) : + Real.log ((n.descFactorial r:ℝ)/(n:ℝ)^r) = + stirlingRemainder n-stirlingRemainder (n-r)-(r:ℝ)- + (n-r:ℕ)*Real.log (1-(r:ℝ)/n) := by + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hm : (0:ℝ) < (n-r).factorial := Nat.cast_pos.mpr (Nat.factorial_pos _) + have hd : (0:ℝ) < n.descFactorial r := Nat.cast_pos.mpr (Nat.descFactorial_pos.mpr hr) + have hf : ((n-r).factorial:ℝ)*(n.descFactorial r:ℝ) = n.factorial := + by exact_mod_cast Nat.factorial_mul_descFactorial hr + have hh := congrArg Real.log hf + rw [Real.log_mul (ne_of_gt hm) (ne_of_gt hd)] at hh + rw [Real.log_div (ne_of_gt hd) (ne_of_gt (pow_pos hn' r)),Real.log_pow] + unfold stirlingRemainder + by_cases hz : n-r=0 + · have hrn : r=n := by omega + subst r + simp only [Nat.sub_self,Nat.factorial_zero,Nat.cast_one,Real.log_one,Nat.cast_zero, + zero_mul,add_zero,sub_zero,Nat.descFactorial_self] + ring + · have hm' : (0:ℝ) < (n-r:ℕ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) + have he : ((n-r:ℕ):ℝ) = (n:ℝ)*(1-(r:ℝ)/n) := by + rw [Nat.cast_sub hr] + field_simp + have hρ : 0 < 1-(r:ℝ)/n := by + rw [←mul_pos_iff_of_pos_left hn',←he] + exact hm' + have hl : Real.log ((n-r:ℕ):ℝ) = Real.log n+Real.log (1-(r:ℝ)/n) := by + rw [he, Real.log_mul (ne_of_gt hn') (ne_of_gt hρ)] + rw [hl,Nat.cast_sub hr] + nlinarith [hh] + + +lemma normalization_le (d r : ℕ) (hd : 1 ≤ d) (hr : 1 ≤ r) (hrn : r ≤ 2^d) : + Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 ≤ + (r:ℝ)*(entropyCorrection ((r:ℝ)/(2:ℝ)^d)+unusedTail d) := by + have hnp : 0 < (2:ℕ)^d := by positivity + have hnr : (0:ℝ) < (2:ℝ)^d := by positivity + have hr' : (0:ℝ) < r := by exact_mod_cast hr + have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hh := stirlingRemainder_difference_bound hnp hrn + simp only [Nat.cast_pow,Nat.cast_ofNat] at hh + have hg := (stirlingRemainder_dyadic d hd).trans + ((div_le_iff₀ hnr).mp (unusedTail_lower d)) + have he : (stirlingRemainder (2^d)-stirlingRemainder (2^d-r))/Real.log 2 ≤ + (r:ℝ)*unusedTail d := by + calc + _ ≤ ((r:ℝ)/(2:ℝ)^d*stirlingRemainder (2^d))/Real.log 2 := + div_le_div_of_nonneg_right hh hl.le + _ = ((r:ℝ)/(2:ℝ)^d)*(stirlingRemainder (2^d)/Real.log 2) := by ring + _ ≤ ((r:ℝ)/(2:ℝ)^d)*(unusedTail d*(2:ℝ)^d) := + mul_le_mul_of_nonneg_left hg (by positivity) + _ = _ := by field_simp + have hid := factorial_error_identity hnp hrn + simp only [Nat.cast_pow,Nat.cast_ofNat] at hid + have heq : Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 = + (r:ℝ)*entropyCorrection ((r:ℝ)/(2:ℝ)^d)+ + (stirlingRemainder (2^d)-stirlingRemainder (2^d-r))/Real.log 2 := by + rw [hid,entropyCorrection,Nat.cast_sub hrn] + simp only [Nat.cast_pow,Nat.cast_ofNat] + field_simp + ring + rw [heq] + nlinarith + + +theorem dense_truncation : MainStatement := by + classical + intro ρ hρ ε hε + obtain ⟨t,ht,hm⟩ := palindrome_dense_mgf (ε/2) (by positivity) + refine ⟨t*ε/2, by positivity, ?_⟩ + intro d r hd hr hρr x + have hrn : r ≤ 2^d := by + have hh := Fintype.card_le_of_injective x x.injective + simpa only [Fintype.card_fin,card_positions] using hh + have hm' := hm d x (by simpa only [Fintype.card_fin] using (show 0 < r by omega)) + simp only [Fintype.card_fin,hρr] at hm' + have hn := normalization_le d r hd hr hrn + rw [hρr] at hn + let a : ℝ := r*(H ρ+entropyCorrection ρ+ε) + let b : ℝ := Real.log (((2^d).descFactorial r:ℝ)/((2:ℝ)^d)^r)/Real.log 2 + have hp (ω : BenesCoins d) : + (if a < densityExponent d r x ω then (1:ℝ) else 0) ≤ + Real.exp (t*palindromeCost d x ω)*Real.exp (t*(b-a)) := by + split_ifs with h + · rw [←Real.exp_add] + apply Real.one_le_exp_iff.mpr + have hh : 0 ≤ t*((palindromeCost d x ω:ℝ)+b-a) := by + apply mul_nonneg ht.le + exact sub_nonneg.mpr (le_of_lt h) + nlinarith + · positivity + have he : t*(r:ℝ)*(H ρ-unusedTail d+ε/2)+t*(b-a) ≤ -(t*ε/2)*r := by + have hh := mul_le_mul_of_nonneg_left hn ht.le + dsimp [b,a] + nlinarith [hh] + calc + _ ≤ finiteMean (fun ω : BenesCoins d => + Real.exp (t*palindromeCost d x ω)*Real.exp (t*(b-a))) := finiteMean_mono hp + _ = finiteMean (fun ω : BenesCoins d => Real.exp (t*palindromeCost d x ω))* + Real.exp (t*(b-a)) := finiteMean_mul_const _ _ + _ ≤ Real.exp (t*(r:ℝ)*(H ρ-unusedTail d+ε/2))*Real.exp (t*(b-a)) := + mul_le_mul_of_nonneg_right hm' (Real.exp_nonneg _) + _ ≤ Real.exp (-(t*ε/2)*r) := by rw [←Real.exp_add]; exact Real.exp_le_exp.mpr he + +end Thorp.DenseTruncation + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/Model.lean b/lean/OAI/Probability/ThorpRouting/Dense/Model.lean index 9b350e85dab8886f84a942b405f1b8aeaa3b3ef8..9c6a6c189c8eb6d70cbb8b3f0db609f7a06e7f13 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/Model.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/Model.lean @@ -1,267 +1,267 @@ -import Mathlib - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev Card (d : ℕ) := Fin d → Bool - -def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := - Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) - -theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : - Function.Involutive (switchFun ξ) := by - intro x - funext i - refine Fin.cases ?_ (fun j => ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -end Thorp - -namespace Thorp.RoutingNetwork -open scoped BigOperators -open Filter -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -end Thorp.RoutingNetwork - -namespace Thorp -open scoped BigOperators -open Filter - -section -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -end - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -end Thorp - -namespace Thorp.CycleColoring -open scoped BigOperators -open Filter -variable {α : Type*} [Fintype α] [DecidableEq α] - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -end Thorp.CycleColoring - -namespace Thorp.PairRouting -open scoped BigOperators -open Filter -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -end Thorp.PairRouting - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -end Thorp - -namespace Thorp.DenseTruncation -open scoped BigOperators - -def AdmissibleCycleLaw (j : ℕ) (p : ℕ → ℝ) : Prop := - (∀ l, 0 ≤ p l) ∧ HasSum p 1 ∧ - ∀ l, p l ≤ ((l + 1 : ℕ) : ℝ) / (2 : ℝ) ^ (j - 1) - -noncomputable def h (j : ℕ) : ℝ := - sSup {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ - z = ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)} - -def AdmissibleAllocation (ρ : ℝ) (x : ℕ → ℝ) : Prop := - (∀ j, 0 ≤ x j ∧ x j ≤ 1) ∧ - (∑' j : ℕ, x j / (2 : ℝ) ^ (j + 1)) ≤ ρ - -noncomputable def H (ρ : ℝ) : ℝ := - sSup {z : ℝ | ∃ x : ℕ → ℝ, AdmissibleAllocation ρ x ∧ - z = (1 / 2 : ℝ) * ∑' j : ℕ, h (j + 1) * x j} - -noncomputable def entropyCorrection (ρ : ℝ) : ℝ := - (-ρ - (1 - ρ) * Real.log (1 - ρ)) / (ρ * Real.log 2) - -noncomputable def densityExponent (d r : ℕ) (x : Fin r ↪ Card d) - (ω : BenesCoins d) : ℝ := - palindromeCost d x ω + - Real.log (((2 ^ d).descFactorial r : ℝ) / ((2 : ℝ) ^ d) ^ r) / Real.log 2 - -def MainStatement : Prop := - ∀ ρ : ℝ, 0 < ρ → ∀ ε : ℝ, 0 < ε → - ∃ c : ℝ, 0 < c ∧ ∀ d r : ℕ, 1 ≤ d → 1 ≤ r → - (r : ℝ) / (2 : ℝ) ^ d = ρ → ∀ x : Fin r ↪ Card d, - finiteMean (fun ω : BenesCoins d => - if (r : ℝ) * (H ρ + entropyCorrection ρ + ε) < densityExponent d r x ω - then (1 : ℝ) else 0) ≤ Real.exp (-c * r) - -end Thorp.DenseTruncation - -end ThorpNine.Dense - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +end Thorp + +namespace Thorp.RoutingNetwork +open scoped BigOperators +open Filter +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +end Thorp.RoutingNetwork + +namespace Thorp +open scoped BigOperators +open Filter + +section +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +end + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +end Thorp + +namespace Thorp.CycleColoring +open scoped BigOperators +open Filter +variable {α : Type*} [Fintype α] [DecidableEq α] + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +end Thorp.CycleColoring + +namespace Thorp.PairRouting +open scoped BigOperators +open Filter +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +end Thorp.PairRouting + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +end Thorp + +namespace Thorp.DenseTruncation +open scoped BigOperators + +def AdmissibleCycleLaw (j : ℕ) (p : ℕ → ℝ) : Prop := + (∀ l, 0 ≤ p l) ∧ HasSum p 1 ∧ + ∀ l, p l ≤ ((l + 1 : ℕ) : ℝ) / (2 : ℝ) ^ (j - 1) + +noncomputable def h (j : ℕ) : ℝ := + sSup {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ + z = ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)} + +def AdmissibleAllocation (ρ : ℝ) (x : ℕ → ℝ) : Prop := + (∀ j, 0 ≤ x j ∧ x j ≤ 1) ∧ + (∑' j : ℕ, x j / (2 : ℝ) ^ (j + 1)) ≤ ρ + +noncomputable def H (ρ : ℝ) : ℝ := + sSup {z : ℝ | ∃ x : ℕ → ℝ, AdmissibleAllocation ρ x ∧ + z = (1 / 2 : ℝ) * ∑' j : ℕ, h (j + 1) * x j} + +noncomputable def entropyCorrection (ρ : ℝ) : ℝ := + (-ρ - (1 - ρ) * Real.log (1 - ρ)) / (ρ * Real.log 2) + +noncomputable def densityExponent (d r : ℕ) (x : Fin r ↪ Card d) + (ω : BenesCoins d) : ℝ := + palindromeCost d x ω + + Real.log (((2 ^ d).descFactorial r : ℝ) / ((2 : ℝ) ^ d) ^ r) / Real.log 2 + +def MainStatement : Prop := + ∀ ρ : ℝ, 0 < ρ → ∀ ε : ℝ, 0 < ε → + ∃ c : ℝ, 0 < c ∧ ∀ d r : ℕ, 1 ≤ d → 1 ≤ r → + (r : ℝ) / (2 : ℝ) ^ d = ρ → ∀ x : Fin r ↪ Card d, + finiteMean (fun ω : BenesCoins d => + if (r : ℝ) * (H ρ + entropyCorrection ρ + ε) < densityExponent d r x ω + then (1 : ℝ) else 0) ≤ Real.exp (-c * r) + +end Thorp.DenseTruncation + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.lean b/lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.lean index e69f682dff43d8b5c6a667ce93dcb114f28920f1..0c6a7816b51c092ee2ba7a27a6db998fcdc89052 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/PalindromeFamilyCost.lean @@ -1,834 +1,834 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.CutoffMass - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -end Thorp - -open scoped BigOperators -namespace Thorp.RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -omit [DecidableEq α] in -lemma single_min_eq_within (o : α → Option (Fin 1)) (u v : α) : - min (pathWeight o u) (pathWeight o v) = withinWeight o u v := by - cases hu : o u with - | none => - cases hv : o v with - | none => simp [pathWeight, withinWeight, hu, hv] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [pathWeight, withinWeight, hu, hv, min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [pathWeight, withinWeight, hu, hv, min_eq_right hi] - | some j => - have hij : i = j := Subsingleton.elim _ _ - simp [pathWeight, withinWeight, hu, hv, hij] - -lemma single_rotationCharge_mean_bound {o : α → Option (Fin 1)} - [∀ i : Fin 1, Nonempty {x : α // o x = some i}] - (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ - Real.log (cycleFiber o 0).card / Real.log 2 := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x, (mem_cycleFiber _ _ _).mpr hx⟩ - have hm : Monotone (fun i => (cycleFiber o i).card) := by - intro i j _ - have : i = j := Subsingleton.elim _ _ - simp [this] - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm, single_min_eq_within, ← two_mul] - rw [← Finset.mul_sum] - have h := withinWeight_sum_bound R o hn b - simp only [Fin.sum_univ_one] at h - rw [mul_comm 2 (Real.log 2), div_mul_eq_div_div] at h - linarith - -lemma single_rotation_exp_bound {o : α → Option (Fin 1)} - [∀ i : Fin 1, Nonempty {x : α // o x = some i}] - (b : ι → Bool) : - 1 / (cycleFiber o 0).card ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have h := single_rotationCharge_mean_bound R (o := o) b - have hlog : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hcard : (0 : ℝ) < (cycleFiber o 0).card := by - apply Nat.cast_pos.mpr - apply Finset.card_pos.mpr - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some 0}) - exact ⟨x, (mem_cycleFiber _ _ _).mpr hx⟩ - have hm : -Real.log (cycleFiber o 0).card ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - have hh := mul_le_mul_of_nonpos_left h (neg_nonpos.mpr hlog.le) - calc - _ = -Real.log 2 * (Real.log (cycleFiber o 0).card / Real.log 2) := by - field_simp - _ ≤ _ := hh - have he := (Real.exp_le_exp.mpr hm).trans (exp_finiteMean_le _) - simpa only [Real.exp_neg, Real.exp_log hcard, one_div] using he - -lemma single_collection_rotation_lower (S : Finset α) (r : ℕ) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S (fun _ : Fin 1 => r)) : - (2:ℝ)^d ≤ ∑ z : Terminal c.val, - (2:ℝ)^d * Real.exp (-Real.log 2 * rotationCharge R c.val ω z) := by - classical - let (i : Fin 1) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hb := single_rotation_exp_bound R ω (o := c.val) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = (cycleFiber c.val 0).card := by - rw [Fintype.card_pi] - simp only [Fin.prod_univ_one, card_cycleFiber] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hh := (le_div_iff₀ hp).mp hb - rw [hcard, one_div_mul_cancel (ne_of_gt (by simpa only [hcard] using hp))] at hh - rw [← Finset.mul_sum] - simpa only [mul_one] using mul_le_mul_of_nonneg_left hh (show 0 ≤ (2:ℝ)^d by positivity) - -lemma single_cycleSlots_weighted_moment (S : Finset α) (r : ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S (fun _ : Fin 1 => r)) : ℝ)) * - (2:ℝ)^d ≤ S.card := by - classical - let rs : Fin 1 → ℕ := fun _ => r - let g (a : Fin 1 → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,rs i))) ∅).succeeds ω then - ((2:ℝ)^d)^1 / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,rs i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S rs) : ℝ) * (2:ℝ)^d ≤ - ∑ a : Fin 1 → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S rs, (2:ℝ)^d := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S rs, - ∑ z : Terminal c.val, ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.val ω z) := by - apply Finset.sum_le_sum - intro c _ - simpa only [pow_one] using single_collection_rotation_lower R S r ω c - _ = ∑ c : RootedSlots (R.perm ω) S rs, - ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.1.val ω c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S rs => - ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.1.val ω c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S rs ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const, finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin 1 → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin 1 → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin 1 => ((a i).val,rs i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -noncomputable def singleRootedEquiv (p : Equiv.Perm α) (r : ℕ) : - RootedSlots p Finset.univ (fun _ : Fin 1 => r) ≃ - {x : α // (orbitSet p x).card = r + 1} := by - classical - let f : RootedSlots p Finset.univ (fun _ : Fin 1 => r) → - {x : α // (orbitSet p x).card = r + 1} := fun c => - ⟨(c.2 0).val, by rw [c.1.property.2.2 0 _ (c.2 0).property, c.1.property.1]⟩ - apply Equiv.ofBijective f - constructor - · intro c c' h - apply rootedStart_injective - funext i - have hi : i = 0 := Subsingleton.elim _ _ - subst i - apply Subtype.ext - exact congrArg p (congrArg Subtype.val h) - · intro x - let C : SelectedCycle p Finset.univ := ⟨orbitSet p x, ⟨⟨x,rfl⟩, Finset.subset_univ _⟩⟩ - let a : SlotAssignment p Finset.univ (fun _ : Fin 1 => r) := - ⟨fun _ => C, Function.injective_of_subsingleton _, fun _ => x.property⟩ - let c := assignmentToSlots a - have hx : ∀ i : Fin 1, c.val x = some i := by - intro i - change assignmentOwner a x = some i - rw [assignmentOwner_eq_some] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl p x) - exact ⟨⟨c, fun i => ⟨x, hx i⟩⟩, Subtype.ext rfl⟩ - -lemma single_root_count (p : Equiv.Perm α) (r : ℕ) : - (Fintype.card {x : α // (orbitSet p x).card = r+1} : ℝ) = - (Fintype.card (CycleSlots p Finset.univ (fun _ : Fin 1 => r)) : ℝ) * (r+1) := by - classical - rw [← Fintype.card_congr (singleRootedEquiv p r), Fintype.card_sigma] - simp only [Fintype.card_pi, Fin.prod_univ_one, card_cycleFiber] - simp only [Nat.cast_sum] - have he (c : CycleSlots p Finset.univ (fun _ : Fin 1 => r)) : - ((cycleFiber c.val 0).card : ℝ) = (r : ℝ) + 1 := by - rw [c.property.1]; norm_cast - simp only [he, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - -lemma uniform_cycle_length_cap [Nonempty α] (r : ℕ) : - finiteMean (fun ω : ι → Bool => finiteMean (fun x : α => - if (orbitSet (R.perm ω) x).card = r+1 then (1:ℝ) else 0)) ≤ - ((r : ℝ)+1) / (2:ℝ)^d := by - classical - have hn : 0 < (Fintype.card α : ℝ) := Nat.cast_pos.mpr Fintype.card_pos - have hinner (ω : ι → Bool) : - finiteMean (fun x : α => if (orbitSet (R.perm ω) x).card = r+1 then (1:ℝ) else 0) = - (Fintype.card (CycleSlots (R.perm ω) Finset.univ (fun _ : Fin 1 => r)) : ℝ) * - (((r:ℝ)+1) / Fintype.card α) := by - rw [← mul_div_assoc, ← single_root_count (R.perm ω) r] - simp [finiteMean, Fintype.card_subtype] - simp only [hinner, finiteMean_mul_const] - have h := single_cycleSlots_weighted_moment R Finset.univ r - simp only [Finset.card_univ] at h - have h' := (le_div_iff₀ (show 0 < (2:ℝ)^d by positivity)).mpr h - calc - _ ≤ ((Fintype.card α : ℝ) / (2:ℝ)^d) * (((r:ℝ)+1) / Fintype.card α) := - mul_le_mul_of_nonneg_right h' (by positivity) - _ = _ := by field_simp - -end Thorp.RoutingNetwork - - -namespace Thorp.DenseTruncation -open scoped BigOperators - -lemma law_reciprocal_summable {j : ℕ} {p : ℕ → ℝ} - (hp : AdmissibleCycleLaw j p) : - Summable (fun l => p l / ((l + 1 : ℕ) : ℝ)) := by - apply Summable.of_nonneg_of_le (fun l => div_nonneg (hp.1 l) (by positivity)) - (fun l => ?_) hp.2.1.summable - exact div_le_self (hp.1 l) (by exact_mod_cast Nat.succ_pos l) - -lemma law_reciprocal_nonneg {j : ℕ} {p : ℕ → ℝ} - (hp : AdmissibleCycleLaw j p) : - 0 ≤ ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ) := - tsum_nonneg (fun l => div_nonneg (hp.1 l) (by positivity)) - -lemma law_reciprocal_le_one {j : ℕ} {p : ℕ → ℝ} - (hp : AdmissibleCycleLaw j p) : - (∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)) ≤ 1 := by - rw [← hp.2.1.tsum_eq] - exact Summable.tsum_le_tsum (fun l => div_le_self (hp.1 l) - (by exact_mod_cast Nat.succ_pos l)) (law_reciprocal_summable hp) hp.2.1.summable - -lemma reciprocal_values_bdd (j : ℕ) : BddAbove - {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ - z = ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)} := - ⟨1, fun _ ⟨_,hp,hz⟩ => hz ▸ law_reciprocal_le_one hp⟩ - -lemma reciprocal_le_h {j : ℕ} {p : ℕ → ℝ} - (hp : AdmissibleCycleLaw j p) : - (∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)) ≤ h j := - le_csSup (reciprocal_values_bdd j) ⟨p,hp,rfl⟩ - -lemma subprob_reciprocal_le_h {j : ℕ} {q : ℕ → ℝ} - (hq : ∀ l, 0 ≤ q l) (hs : Summable q) (ht : (∑' l, q l) ≤ 1) - (hc : ∀ l, q l ≤ ((l+1 : ℕ) : ℝ) / (2:ℝ)^(j-1)) : - (∑' l, q l / ((l+1 : ℕ) : ℝ)) ≤ h j := by - let t := 2^(j-1)-1 - have hpow : 1 ≤ 2^(j-1) := Nat.one_le_pow _ _ (by norm_num) - have htlen : (t+1 : ℕ) = 2^(j-1) := Nat.sub_add_cancel hpow - have hreal : ((t+1 : ℕ) : ℝ) = (2:ℝ)^(j-1) := by rw [htlen]; norm_cast - let m := 1 - ∑' l, q l - have hm : 0 ≤ m := sub_nonneg.mpr ht - let a : ℕ → ℝ := fun l => if l=t then m else 0 - have ha : HasSum a m := by - simpa only [a,ite_eq_left rfl] using (hasSum_single t (f := a) (fun l hl => by simp [a,hl])) - let p : ℕ → ℝ := fun l => q l+a l - have hp : AdmissibleCycleLaw j p := by - refine ⟨fun l => add_nonneg (hq l) (by dsimp [a]; split_ifs <;> positivity), ?_, ?_⟩ - · convert hs.hasSum.add ha using 1; dsimp [p,m]; ring - · intro l - by_cases hl : l=t - · subst l - have hqt := hs.le_tsum t (fun l _ => hq l) - have hp2 : (2:ℝ)^(j-1) ≠ 0 := by positivity - simp only [p,a,hreal,div_self hp2] - dsimp [m] - linarith - · simpa only [p,a,ite_eq_right hl,add_zero] using hc l - have hqs : Summable (fun l => q l / ((l+1 : ℕ) : ℝ)) := by - apply Summable.of_nonneg_of_le (fun l => div_nonneg (hq l) (by positivity)) - (fun l => div_le_self (hq l) (by exact_mod_cast Nat.succ_pos l)) hs - calc - _ ≤ ∑' l, p l / ((l+1 : ℕ) : ℝ) := by - apply Summable.tsum_le_tsum _ hqs (law_reciprocal_summable hp) - intro l - apply div_le_div_of_nonneg_right _ (by positivity) - dsimp [p,a] - split_ifs <;> linarith - _ ≤ _ := reciprocal_le_h hp - -end Thorp.DenseTruncation - - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.CutoffMass + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +end Thorp + +open scoped BigOperators +namespace Thorp.RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +omit [DecidableEq α] in +lemma single_min_eq_within (o : α → Option (Fin 1)) (u v : α) : + min (pathWeight o u) (pathWeight o v) = withinWeight o u v := by + cases hu : o u with + | none => + cases hv : o v with + | none => simp [pathWeight, withinWeight, hu, hv] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [pathWeight, withinWeight, hu, hv, min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [pathWeight, withinWeight, hu, hv, min_eq_right hi] + | some j => + have hij : i = j := Subsingleton.elim _ _ + simp [pathWeight, withinWeight, hu, hv, hij] + +lemma single_rotationCharge_mean_bound {o : α → Option (Fin 1)} + [∀ i : Fin 1, Nonempty {x : α // o x = some i}] + (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ + Real.log (cycleFiber o 0).card / Real.log 2 := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x, (mem_cycleFiber _ _ _).mpr hx⟩ + have hm : Monotone (fun i => (cycleFiber o i).card) := by + intro i j _ + have : i = j := Subsingleton.elim _ _ + simp [this] + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm, single_min_eq_within, ← two_mul] + rw [← Finset.mul_sum] + have h := withinWeight_sum_bound R o hn b + simp only [Fin.sum_univ_one] at h + rw [mul_comm 2 (Real.log 2), div_mul_eq_div_div] at h + linarith + +lemma single_rotation_exp_bound {o : α → Option (Fin 1)} + [∀ i : Fin 1, Nonempty {x : α // o x = some i}] + (b : ι → Bool) : + 1 / (cycleFiber o 0).card ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have h := single_rotationCharge_mean_bound R (o := o) b + have hlog : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hcard : (0 : ℝ) < (cycleFiber o 0).card := by + apply Nat.cast_pos.mpr + apply Finset.card_pos.mpr + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some 0}) + exact ⟨x, (mem_cycleFiber _ _ _).mpr hx⟩ + have hm : -Real.log (cycleFiber o 0).card ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + have hh := mul_le_mul_of_nonpos_left h (neg_nonpos.mpr hlog.le) + calc + _ = -Real.log 2 * (Real.log (cycleFiber o 0).card / Real.log 2) := by + field_simp + _ ≤ _ := hh + have he := (Real.exp_le_exp.mpr hm).trans (exp_finiteMean_le _) + simpa only [Real.exp_neg, Real.exp_log hcard, one_div] using he + +lemma single_collection_rotation_lower (S : Finset α) (r : ℕ) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S (fun _ : Fin 1 => r)) : + (2:ℝ)^d ≤ ∑ z : Terminal c.val, + (2:ℝ)^d * Real.exp (-Real.log 2 * rotationCharge R c.val ω z) := by + classical + let (i : Fin 1) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hb := single_rotation_exp_bound R ω (o := c.val) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = (cycleFiber c.val 0).card := by + rw [Fintype.card_pi] + simp only [Fin.prod_univ_one, card_cycleFiber] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hh := (le_div_iff₀ hp).mp hb + rw [hcard, one_div_mul_cancel (ne_of_gt (by simpa only [hcard] using hp))] at hh + rw [← Finset.mul_sum] + simpa only [mul_one] using mul_le_mul_of_nonneg_left hh (show 0 ≤ (2:ℝ)^d by positivity) + +lemma single_cycleSlots_weighted_moment (S : Finset α) (r : ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S (fun _ : Fin 1 => r)) : ℝ)) * + (2:ℝ)^d ≤ S.card := by + classical + let rs : Fin 1 → ℕ := fun _ => r + let g (a : Fin 1 → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,rs i))) ∅).succeeds ω then + ((2:ℝ)^d)^1 / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,rs i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S rs) : ℝ) * (2:ℝ)^d ≤ + ∑ a : Fin 1 → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S rs, (2:ℝ)^d := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S rs, + ∑ z : Terminal c.val, ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.val ω z) := by + apply Finset.sum_le_sum + intro c _ + simpa only [pow_one] using single_collection_rotation_lower R S r ω c + _ = ∑ c : RootedSlots (R.perm ω) S rs, + ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.1.val ω c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S rs => + ((2:ℝ)^d)^1 * Real.exp (-Real.log 2 * rotationCharge R c.1.val ω c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S rs ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const, finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin 1 → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin 1 → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin 1 => ((a i).val,rs i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +noncomputable def singleRootedEquiv (p : Equiv.Perm α) (r : ℕ) : + RootedSlots p Finset.univ (fun _ : Fin 1 => r) ≃ + {x : α // (orbitSet p x).card = r + 1} := by + classical + let f : RootedSlots p Finset.univ (fun _ : Fin 1 => r) → + {x : α // (orbitSet p x).card = r + 1} := fun c => + ⟨(c.2 0).val, by rw [c.1.property.2.2 0 _ (c.2 0).property, c.1.property.1]⟩ + apply Equiv.ofBijective f + constructor + · intro c c' h + apply rootedStart_injective + funext i + have hi : i = 0 := Subsingleton.elim _ _ + subst i + apply Subtype.ext + exact congrArg p (congrArg Subtype.val h) + · intro x + let C : SelectedCycle p Finset.univ := ⟨orbitSet p x, ⟨⟨x,rfl⟩, Finset.subset_univ _⟩⟩ + let a : SlotAssignment p Finset.univ (fun _ : Fin 1 => r) := + ⟨fun _ => C, Function.injective_of_subsingleton _, fun _ => x.property⟩ + let c := assignmentToSlots a + have hx : ∀ i : Fin 1, c.val x = some i := by + intro i + change assignmentOwner a x = some i + rw [assignmentOwner_eq_some] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl p x) + exact ⟨⟨c, fun i => ⟨x, hx i⟩⟩, Subtype.ext rfl⟩ + +lemma single_root_count (p : Equiv.Perm α) (r : ℕ) : + (Fintype.card {x : α // (orbitSet p x).card = r+1} : ℝ) = + (Fintype.card (CycleSlots p Finset.univ (fun _ : Fin 1 => r)) : ℝ) * (r+1) := by + classical + rw [← Fintype.card_congr (singleRootedEquiv p r), Fintype.card_sigma] + simp only [Fintype.card_pi, Fin.prod_univ_one, card_cycleFiber] + simp only [Nat.cast_sum] + have he (c : CycleSlots p Finset.univ (fun _ : Fin 1 => r)) : + ((cycleFiber c.val 0).card : ℝ) = (r : ℝ) + 1 := by + rw [c.property.1]; norm_cast + simp only [he, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + +lemma uniform_cycle_length_cap [Nonempty α] (r : ℕ) : + finiteMean (fun ω : ι → Bool => finiteMean (fun x : α => + if (orbitSet (R.perm ω) x).card = r+1 then (1:ℝ) else 0)) ≤ + ((r : ℝ)+1) / (2:ℝ)^d := by + classical + have hn : 0 < (Fintype.card α : ℝ) := Nat.cast_pos.mpr Fintype.card_pos + have hinner (ω : ι → Bool) : + finiteMean (fun x : α => if (orbitSet (R.perm ω) x).card = r+1 then (1:ℝ) else 0) = + (Fintype.card (CycleSlots (R.perm ω) Finset.univ (fun _ : Fin 1 => r)) : ℝ) * + (((r:ℝ)+1) / Fintype.card α) := by + rw [← mul_div_assoc, ← single_root_count (R.perm ω) r] + simp [finiteMean, Fintype.card_subtype] + simp only [hinner, finiteMean_mul_const] + have h := single_cycleSlots_weighted_moment R Finset.univ r + simp only [Finset.card_univ] at h + have h' := (le_div_iff₀ (show 0 < (2:ℝ)^d by positivity)).mpr h + calc + _ ≤ ((Fintype.card α : ℝ) / (2:ℝ)^d) * (((r:ℝ)+1) / Fintype.card α) := + mul_le_mul_of_nonneg_right h' (by positivity) + _ = _ := by field_simp + +end Thorp.RoutingNetwork + + +namespace Thorp.DenseTruncation +open scoped BigOperators + +lemma law_reciprocal_summable {j : ℕ} {p : ℕ → ℝ} + (hp : AdmissibleCycleLaw j p) : + Summable (fun l => p l / ((l + 1 : ℕ) : ℝ)) := by + apply Summable.of_nonneg_of_le (fun l => div_nonneg (hp.1 l) (by positivity)) + (fun l => ?_) hp.2.1.summable + exact div_le_self (hp.1 l) (by exact_mod_cast Nat.succ_pos l) + +lemma law_reciprocal_nonneg {j : ℕ} {p : ℕ → ℝ} + (hp : AdmissibleCycleLaw j p) : + 0 ≤ ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ) := + tsum_nonneg (fun l => div_nonneg (hp.1 l) (by positivity)) + +lemma law_reciprocal_le_one {j : ℕ} {p : ℕ → ℝ} + (hp : AdmissibleCycleLaw j p) : + (∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)) ≤ 1 := by + rw [← hp.2.1.tsum_eq] + exact Summable.tsum_le_tsum (fun l => div_le_self (hp.1 l) + (by exact_mod_cast Nat.succ_pos l)) (law_reciprocal_summable hp) hp.2.1.summable + +lemma reciprocal_values_bdd (j : ℕ) : BddAbove + {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ + z = ∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)} := + ⟨1, fun _ ⟨_,hp,hz⟩ => hz ▸ law_reciprocal_le_one hp⟩ + +lemma reciprocal_le_h {j : ℕ} {p : ℕ → ℝ} + (hp : AdmissibleCycleLaw j p) : + (∑' l : ℕ, p l / ((l + 1 : ℕ) : ℝ)) ≤ h j := + le_csSup (reciprocal_values_bdd j) ⟨p,hp,rfl⟩ + +lemma subprob_reciprocal_le_h {j : ℕ} {q : ℕ → ℝ} + (hq : ∀ l, 0 ≤ q l) (hs : Summable q) (ht : (∑' l, q l) ≤ 1) + (hc : ∀ l, q l ≤ ((l+1 : ℕ) : ℝ) / (2:ℝ)^(j-1)) : + (∑' l, q l / ((l+1 : ℕ) : ℝ)) ≤ h j := by + let t := 2^(j-1)-1 + have hpow : 1 ≤ 2^(j-1) := Nat.one_le_pow _ _ (by norm_num) + have htlen : (t+1 : ℕ) = 2^(j-1) := Nat.sub_add_cancel hpow + have hreal : ((t+1 : ℕ) : ℝ) = (2:ℝ)^(j-1) := by rw [htlen]; norm_cast + let m := 1 - ∑' l, q l + have hm : 0 ≤ m := sub_nonneg.mpr ht + let a : ℕ → ℝ := fun l => if l=t then m else 0 + have ha : HasSum a m := by + simpa only [a,ite_eq_left rfl] using (hasSum_single t (f := a) (fun l hl => by simp [a,hl])) + let p : ℕ → ℝ := fun l => q l+a l + have hp : AdmissibleCycleLaw j p := by + refine ⟨fun l => add_nonneg (hq l) (by dsimp [a]; split_ifs <;> positivity), ?_, ?_⟩ + · convert hs.hasSum.add ha using 1; dsimp [p,m]; ring + · intro l + by_cases hl : l=t + · subst l + have hqt := hs.le_tsum t (fun l _ => hq l) + have hp2 : (2:ℝ)^(j-1) ≠ 0 := by positivity + simp only [p,a,hreal,div_self hp2] + dsimp [m] + linarith + · simpa only [p,a,ite_eq_right hl,add_zero] using hc l + have hqs : Summable (fun l => q l / ((l+1 : ℕ) : ℝ)) := by + apply Summable.of_nonneg_of_le (fun l => div_nonneg (hq l) (by positivity)) + (fun l => div_le_self (hq l) (by exact_mod_cast Nat.succ_pos l)) hs + calc + _ ≤ ∑' l, p l / ((l+1 : ℕ) : ℝ) := by + apply Summable.tsum_le_tsum _ hqs (law_reciprocal_summable hp) + intro l + apply div_le_div_of_nonneg_right _ (by positivity) + dsimp [p,a] + split_ifs <;> linarith + _ ≤ _ := reciprocal_le_h hp + +end Thorp.DenseTruncation + + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.lean index 5ec706ee83cb3f54d6a6b1fadd20224eb28932d9..c5252c972ab1f94aae9b6f90f7acc6436e30f599 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/ParallelFollow.lean @@ -1,854 +1,854 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.PriorPaths - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.PriorPaths + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.lean index 169541c18d1f6a74692834c6ac9bec7e814a87ee..f9e6c587760ace0bf47c17ef737dc4d710b5e316 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/PriorPaths.lean @@ -1,876 +1,876 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.AssignmentSlots - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.AssignmentSlots + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.lean b/lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.lean index 65249176e1f4d21d1ffa2f481a5a2ea7ba8e0f5c..fbcb11b37419d61386fbc48e870c9207807c5167 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/ProjectCycle.lean @@ -1,811 +1,811 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.ParallelFollow - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -end PairRouting -end Thorp - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.ParallelFollow + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +end PairRouting +end Thorp + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.lean b/lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.lean index d78c92cd83675d66a3f811b2046eae8ea65aecbd..f34b15488e9077e3738ddeca269fa2b90cec4ecc 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/RotationCharge.lean @@ -1,888 +1,888 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.ExposedCoins - -namespace OAI - -namespace ThorpNine.Dense - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -end Thorp - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.ExposedCoins + +namespace OAI + +namespace ThorpNine.Dense + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +end Thorp + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.lean b/lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.lean index f5e6a932a2f432871716e2fbac7a569778343188..a2d60665bebd05e50d1e57154abfe8c0f1eead49 100644 --- a/lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/Dense/SingleSlotsEquiv.lean @@ -1,916 +1,916 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Dense.PalindromeFamilyCost - -namespace OAI - -namespace ThorpNine.Dense - -open scoped BigOperators -namespace Thorp.RoutingNetwork -open scoped BigOperators -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def singleSlotsEquiv (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : - CycleSlots p S (fun _ : Fin 1 => r) ≃ - {C : SelectedCycle p S // C.val.card = r+1} := - (cycleSlotsEquivAssignments p S (fun _ : Fin 1 => r)).trans - { toFun := fun a => ⟨a.val 0, a.property.2 0⟩ - invFun := fun C => ⟨fun _ => C.val, Function.injective_of_subsingleton _, fun _ => C.property⟩ - left_inv := fun a => by - apply Subtype.ext - funext i - have hi : i=0 := Subsingleton.elim _ _ - subst i - rfl - right_inv := fun C => rfl } - -noncomputable def cycleCount (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : ℝ := - Fintype.card {C : SelectedCycle p S // C.val.card = r+1} - -lemma cycleCount_eq_sum (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : - cycleCount p S r = ∑ C : SelectedCycle p S, if C.val.card=r+1 then (1:ℝ) else 0 := by - classical - simp only [cycleCount, Fintype.card_subtype, Finset.sum_boole] - -lemma hasSum_cycleCount_weight (p : Equiv.Perm α) (S : Finset α) (f : ℕ → ℝ) : - HasSum (fun l => cycleCount p S l * f (l+1)) - (∑ C : SelectedCycle p S, f C.val.card) := by - classical - have h (C : SelectedCycle p S) : - HasSum (fun l : ℕ => if C.val.card=l+1 then f C.val.card else 0) (f C.val.card) := by - have hc : 1 ≤ C.val.card := C.nonempty.card_pos - have hs := hasSum_single (C.val.card-1) - (f := fun l : ℕ => if C.val.card=l+1 then f C.val.card else 0) - (fun l hl => ite_eq_right (by omega)) - simpa only [Nat.sub_add_cancel hc, ↓reduceIte] using hs - convert hasSum_sum (s := Finset.univ) (fun C _ => h C) using 1 - funext l - rw [cycleCount_eq_sum, Finset.sum_mul] - apply Finset.sum_congr rfl - intro C _ - split_ifs with hc - · simp only [one_mul, hc] - · simp - -end Thorp.RoutingNetwork - -namespace Thorp -open scoped BigOperators -lemma hasSum_finiteMean {Ω : Type*} [Fintype Ω] {f : Ω → ℕ → ℝ} {a : Ω → ℝ} - (hf : ∀ ω, HasSum (f ω) (a ω)) : - HasSum (fun l => finiteMean (fun ω => f ω l)) (finiteMean a) := - (hasSum_sum (s := Finset.univ) (fun ω _ => hf ω)).div_const (Fintype.card Ω : ℝ) -end Thorp - -namespace Thorp.RoutingNetwork -open scoped BigOperators -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma selected_cycle_mean_le_h (S : Finset α) : - finiteMean (fun ω : ι → Bool => (Fintype.card (SelectedCycle (R.perm ω) S) : ℝ)) ≤ - (S.card : ℝ) * DenseTruncation.h (d+1) := by - classical - by_cases hS : S.Nonempty - · have hpos : (0:ℝ) < S.card := Nat.cast_pos.mpr hS.card_pos - let w : ℕ → ℝ := fun l => finiteMean (fun ω : ι → Bool => cycleCount (R.perm ω) S l) - have hw : ∀ l, 0 ≤ w l := fun _ => finiteMean_nonneg (fun _ => Nat.cast_nonneg _) - have hc (l : ℕ) : w l ≤ (S.card : ℝ) / (2:ℝ)^d := by - apply (le_div_iff₀ (by positivity : 0 < (2:ℝ)^d)).mpr - have he (ω : ι → Bool) : cycleCount (R.perm ω) S l = - (Fintype.card (CycleSlots (R.perm ω) S (fun _ : Fin 1 => l)) : ℝ) := by - rw [cycleCount, Fintype.card_congr (singleSlotsEquiv (R.perm ω) S l)] - simpa only [w,he] using single_cycleSlots_weighted_moment R S l - have hmass := hasSum_finiteMean (fun ω : ι → Bool => - hasSum_cycleCount_weight (R.perm ω) S (fun n => (n:ℝ))) - have hm : HasSum (fun l => ((l+1 : ℕ) : ℝ) * w l) - (finiteMean (fun ω : ι → Bool => (cycleMass (R.perm ω) S : ℝ))) := by - simp only [finiteMean_mul_const] at hmass - simpa only [w, mul_comm, cycleMass,Nat.cast_sum] using hmass - have hmt : finiteMean (fun ω : ι → Bool => (cycleMass (R.perm ω) S : ℝ)) ≤ S.card := by - calc - _ ≤ finiteMean (fun _ : ι → Bool => (S.card : ℝ)) := - finiteMean_mono (fun ω => by exact_mod_cast cycleMass_le (R.perm ω) S) - _ = _ := finiteMean_const _ - let q : ℕ → ℝ := fun l => ((l+1 : ℕ) : ℝ) * w l / S.card - have hq : ∀ l, 0 ≤ q l := fun l => div_nonneg (mul_nonneg (by positivity) (hw l)) hpos.le - have hqs : Summable q := (hm.div_const (S.card : ℝ)).summable - have hqt : (∑' l, q l) ≤ 1 := by - rw [(hm.div_const (S.card : ℝ)).tsum_eq] - exact (div_le_one hpos).mpr hmt - have hqc (l : ℕ) : q l ≤ ((l+1 : ℕ) : ℝ) / (2:ℝ)^((d+1)-1) := by - simp only [Nat.add_sub_cancel] - dsimp [q] - calc - _ ≤ (((l+1 : ℕ) : ℝ) * ((S.card : ℝ) / (2:ℝ)^d)) / S.card := by - gcongr - exact hc l - _ = _ := by field_simp - have hh := DenseTruncation.subprob_reciprocal_le_h hq hqs hqt hqc - have hcount := hasSum_finiteMean (fun ω : ι → Bool => - hasSum_cycleCount_weight (R.perm ω) S (fun _ => (1:ℝ))) - have hwc : HasSum w (finiteMean (fun ω : ι → Bool => - (Fintype.card (SelectedCycle (R.perm ω) S) : ℝ))) := by - simpa only [mul_one,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] using hcount - have he (l : ℕ) : q l / ((l+1 : ℕ) : ℝ) = w l / S.card := by - have hl : ((l+1 : ℕ) : ℝ) ≠ 0 := by positivity - dsimp [q] - field_simp - simp only [he, (hwc.div_const (S.card : ℝ)).tsum_eq] at hh - simpa only [mul_comm] using (div_le_iff₀ hpos).mp hh - · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS - subst S - have hz (ω : ι → Bool) : Fintype.card (SelectedCycle (R.perm ω) ∅) = 0 := by - let : IsEmpty (SelectedCycle (R.perm ω) ∅) := - ⟨fun C => C.nonempty.ne_empty (Finset.subset_empty.mp C.property.2)⟩ - exact Fintype.card_eq_zero - simp only [hz,Nat.cast_zero,finiteMean_const,Finset.card_empty,zero_mul,le_refl] - -end Thorp.RoutingNetwork - -namespace Thorp.DenseTruncation -open scoped BigOperators - -lemma reciprocal_values_nonempty (j : ℕ) : - {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ - z = ∑' l : ℕ, p l / ((l+1 : ℕ) : ℝ)}.Nonempty := by - let t := 2^(j-1)-1 - have ht : t+1 = 2^(j-1) := Nat.sub_add_cancel (Nat.one_le_pow _ _ (by norm_num)) - let p : ℕ → ℝ := fun l => if l=t then 1 else 0 - have hp : AdmissibleCycleLaw j p := by - refine ⟨fun l => by dsimp [p]; split_ifs <;> norm_num, hasSum_ite_eq t 1, ?_⟩ - intro l - by_cases hl : l=t - · subst l - have he : ((t+1 : ℕ) : ℝ) = (2:ℝ)^(j-1) := by rw [ht]; norm_cast - simp only [p,↓reduceIte,he,div_self (by positivity : (2:ℝ)^(j-1) ≠ 0),le_refl] - · simp only [p,ite_eq_right hl] - positivity - exact ⟨_,p,hp,rfl⟩ - -lemma h_nonneg (j : ℕ) : 0 ≤ h j := by - obtain ⟨z,p,hp,rfl⟩ := reciprocal_values_nonempty j - exact (law_reciprocal_nonneg hp).trans (reciprocal_le_h hp) - -lemma h_le_one (j : ℕ) : h j ≤ 1 := - csSup_le (reciprocal_values_nonempty j) (fun _ ⟨_,hp,hz⟩ => hz ▸ law_reciprocal_le_one hp) - -lemma law_reciprocal_cutoff {j : ℕ} {p : ℕ → ℝ} (hp : AdmissibleCycleLaw j p) - (L : ℕ) (hL : 0 < L) : - (∑' l, p l / ((l+1 : ℕ) : ℝ)) ≤ (L : ℝ)/(2:ℝ)^(j-1) + 1/L := by - let a : ℕ → ℝ := fun l => if l by simpa only [a,Finset.mem_range] using ite_eq_right (show ¬l hl (Finset.mem_range.mpr hh))) - simpa only [a,Finset.sum_ite_of_true (fun l hl => Finset.mem_range.mp hl), - Finset.sum_const,Finset.card_range,nsmul_eq_mul,mul_one_div] using hs - have hb := hp.2.1.div_const (L:ℝ) - have he (l : ℕ) : p l / ((l+1 : ℕ) : ℝ) ≤ a l + p l/L := by - by_cases hl : l hz ▸ law_reciprocal_cutoff hp L hL) - -lemma h_dyadic_bound (j : ℕ) : h (j+1) ≤ 2/(2:ℝ)^(j/2) := by - have h := h_cutoff (j+1) (2^(j/2)) (by positivity) - simp only [Nat.add_sub_cancel,Nat.cast_pow,Nat.cast_ofNat] at h - have hpow : ((2:ℝ)^(j/2))^2 ≤ (2:ℝ)^j := by - rw [←pow_mul] - exact pow_le_pow_right₀ (by norm_num) (by omega) - have hp : (0:ℝ) < (2:ℝ)^(j/2) := by positivity - have hq : (0:ℝ) < (2:ℝ)^j := by positivity - have hr : (2:ℝ)^(j/2)/(2:ℝ)^j ≤ 1/(2:ℝ)^(j/2) := by - apply (div_le_div_iff₀ hq hp).mpr - nlinarith - calc - _ ≤ 1/(2:ℝ)^(j/2) + 1/(2:ℝ)^(j/2) := h.trans (by linarith) - _ = _ := by ring - -lemma summable_half_dyadic : Summable (fun j : ℕ => 2/(2:ℝ)^(j/2)) := by - apply ((Nat.divModEquiv 2).symm.summable_iff).mp - have he (p : ℕ × Fin 2) : 2/(2:ℝ)^(((Nat.divModEquiv 2).symm p)/2) = - 2*(1/2:ℝ)^p.1 := by - rw [Nat.divModEquiv_symm_apply] - have hi : (p.1*2+p.2.val)/2 = p.1 := by omega - rw [hi,div_pow,one_pow] - ring - simp only [Function.comp_def,he] - apply (summable_prod_of_nonneg (fun p => by positivity)).mpr - constructor - · intro n - exact (hasSum_fintype _).summable - · simpa only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_ofNat,←mul_assoc,show (2:ℝ)*2=4 from by norm_num] using summable_geometric_two.mul_left 4 - -lemma h_summable : Summable (fun j => h (j+1)) := - Summable.of_nonneg_of_le (fun j => h_nonneg (j+1)) h_dyadic_bound summable_half_dyadic - -lemma allocation_value_summable {ρ : ℝ} {x : ℕ → ℝ} (hx : AdmissibleAllocation ρ x) : - Summable (fun j => h (j+1)*x j) := - Summable.of_nonneg_of_le (fun j => mul_nonneg (h_nonneg _) (hx.1 j).1) - (fun j => mul_le_of_le_one_right (h_nonneg _) (hx.1 j).2) h_summable - -lemma H_values_bdd (ρ : ℝ) : BddAbove {z : ℝ | ∃ x : ℕ → ℝ, - AdmissibleAllocation ρ x ∧ z = (1/2:ℝ)*∑' j, h (j+1)*x j} := by - refine ⟨(1/2:ℝ)*∑' j, h (j+1), ?_⟩ - rintro z ⟨x,hx,rfl⟩ - apply mul_le_mul_of_nonneg_left _ (by norm_num) - exact Summable.tsum_le_tsum (fun j => mul_le_of_le_one_right (h_nonneg _) (hx.1 j).2) - (allocation_value_summable hx) h_summable - -lemma allocation_le_H {ρ : ℝ} {x : ℕ → ℝ} (hx : AdmissibleAllocation ρ x) : - (1/2:ℝ)*∑' j, h (j+1)*x j ≤ H ρ := - le_csSup (H_values_bdd ρ) ⟨x,hx,rfl⟩ - -end Thorp.DenseTruncation - -namespace Thorp -open scoped BigOperators - -def unitCardEquiv (d : ℕ) : Card d ≃ Unit × Card d where - toFun x := ((),x) - invFun x := x.2 - left_inv _ := rfl - right_inv x := by cases x with | mk u x => cases u; rfl - -def unitBitsEquiv (d : ℕ) : (Unit × SwitchIndex d → Bool) ≃ (SwitchIndex d → Bool) where - toFun ω i := ω ((),i) - invFun ω i := ω i.2 - left_inv ω := by funext i; rcases i with ⟨u,i⟩; cases u; rfl - right_inv _ := rfl - -lemma relabeled_single_cycle_mean (d : ℕ) (pre post : Equiv.Perm (Card d)) - (S : Finset (Card d)) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (RoutingNetwork.SelectedCycle - (post * butterflyPerm d (decodeButterfly d ω) * pre) S) : ℝ)) ≤ - (S.card : ℝ)*DenseTruncation.h (d+1) := by - have hh := RoutingNetwork.selected_cycle_mean_le_h - (parallelNetwork (pre.trans (unitCardEquiv d)) ((unitCardEquiv d).symm.trans post)) S - rw [finiteMean_equiv (unitBitsEquiv d)] at hh - exact hh - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def projectSharedCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p (A ∩ B) := by - refine ⟨(projectCycle p A B C).val, (projectCycle p A B C).property.1, ?_⟩ - intro x hx - apply Finset.mem_inter.mpr - refine ⟨(projectCycle p A B C).property.2 hx, ?_⟩ - have he := selected_alternating_eq p A B C - have hc : (true,x) ∈ C.val := by - rw [he] - exact (mem_childJoin _ _ true x).mpr hx - exact (mem_childJoin A B true x).mp (C.property.2 hc) - -lemma projectSharedCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectSharedCycle p A B) := by - intro C D h - apply projectCycle_injective p A B - apply Subtype.ext - change (projectSharedCycle p A B C).val = (projectSharedCycle p A B D).val - exact congrArg Subtype.val h - -lemma card_alternating_cycles_le_shared (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p (A ∩ B)) := - Fintype.card_le_of_injective _ (projectSharedCycle_injective p A B) - -end CycleColoring - -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def sharedPairs (e : ι ↪ Bool × α) : Finset α := - boolFiber (labelSet e) false ∩ boolFiber (labelSet e) true - -lemma alternatingCycles_le_sharedSelected (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (sharedPairs e)) := by - unfold alternatingCycles sharedPairs - conv_lhs => rw [←childJoin_boolFiber (labelSet e)] - exact CycleColoring.card_alternating_cycles_le_shared _ _ _ - -omit [Fintype α] in -lemma sharedPairs_card_twice_le (e : ι ↪ Bool × α) : - 2*(sharedPairs e).card ≤ Fintype.card ι := by - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - have h₀ := Finset.card_le_card (Finset.inter_subset_left : sharedPairs e ⊆ boolFiber (labelSet e) false) - have h₁ := Finset.card_le_card (Finset.inter_subset_right : sharedPairs e ⊆ boolFiber (labelSet e) true) - simp only [sharedPairs] at * - omega - -omit [Fintype α] in -lemma labelSet_switched (e : ι ↪ Bool × α) (ξ : α → Bool) : - labelSet (switchedEmbedding e ξ) = (labelSet e).image (pairLayer ξ) := by - classical - simp only [labelSet,Finset.image_image,switchedEmbedding] - rfl - -omit [Fintype α] in -lemma sharedPairs_switched (e : ι ↪ Bool × α) (ξ : α → Bool) : - sharedPairs (switchedEmbedding e ξ) = sharedPairs e := by - classical - ext x - simp only [sharedPairs,Finset.mem_inter,mem_boolFiber,labelSet_switched,mem_image_perm_iff] - change (Bool.xor false (ξ x),x) ∈ labelSet e ∧ - (Bool.xor true (ξ x),x) ∈ labelSet e ↔ - (false,x) ∈ labelSet e ∧ (true,x) ∈ labelSet e - cases ξ x <;> simp only [Bool.xor_false,Bool.xor_true,Bool.not_false,Bool.not_true,and_comm] - -lemma node_cycle_mean (d : ℕ) (e : ι ↪ Bool × Card d) : - finiteMean (fun c : BenesCoins d × BenesCoins d => - (alternatingCycles e (fun b => palindromePerm d (if b then c.2 else c.1)) : ℝ)) ≤ - (sharedPairs e).card * DenseTruncation.h (d+1) := by - classical - rw [finiteMean_prod] - have hone (c₀ : BenesCoins d) : - finiteMean (fun c₁ : BenesCoins d => - (alternatingCycles e (fun b => palindromePerm d (if b then c₁ else c₀)) : ℝ)) ≤ - (sharedPairs e).card * DenseTruncation.h (d+1) := by - rw [finiteMean_prod,finiteMean_comm] - have hf (X : SwitchIndex d → Bool) : - finiteMean (fun Y : SwitchIndex d → Bool => - (alternatingCycles e (fun b => palindromePerm d (if b then (Y,X) else c₀)) : ℝ)) ≤ - (sharedPairs e).card * DenseTruncation.h (d+1) := by - calc - _ ≤ finiteMean (fun Y : SwitchIndex d → Bool => - (Fintype.card (RoutingNetwork.SelectedCycle - ((palindromePerm d c₀).symm * butterflyPerm d (decodeButterfly d Y) * - (butterflyPerm d (decodeButterfly d X)).symm) (sharedPairs e)) : ℝ)) := by - apply finiteMean_mono - intro Y - have hh := alternatingCycles_le_sharedSelected e - (fun b => palindromePerm d (if b then (Y,X) else c₀)) - simpa only [alternatingProjection,Bool.false_eq_true,↓reduceIte,palindromePerm,mul_assoc] using - (Nat.cast_le.mpr hh : (alternatingCycles e _ : ℝ) ≤ _) - _ ≤ _ := relabeled_single_cycle_mean d _ _ _ - calc - _ ≤ finiteMean (fun _ : SwitchIndex d → Bool => - (sharedPairs e).card * DenseTruncation.h (d+1)) := finiteMean_mono hf - _ = _ := finiteMean_const _ - calc - _ ≤ finiteMean (fun _ : BenesCoins d => (sharedPairs e).card * DenseTruncation.h (d+1)) := - finiteMean_mono hone - _ = _ := finiteMean_const _ - -end PairRouting -end Thorp - -namespace Thorp - -lemma exp_secant {M x t : ℝ} (hM : 0 < M) (hx : 0 ≤ x) (hxM : x ≤ M) : - Real.exp (t*x) ≤ 1 + x*((Real.exp (t*M)-1)/M) := by - have hb : 0 ≤ x/M := div_nonneg hx hM.le - have ha : 0 ≤ 1-x/M := sub_nonneg.mpr ((div_le_one hM).mpr hxM) - have hh := convexOn_exp.2 (Set.mem_univ (0:ℝ)) (Set.mem_univ (t*M)) ha hb - (show (1-x/M)+(x/M)=1 by ring) - simp only [smul_eq_mul, mul_zero, zero_add, Real.exp_zero, mul_one] at hh - have he : x/M*(t*M) = t*x := by field_simp - rw [he] at hh - calc - _ ≤ 1-x/M+(x/M)*Real.exp (t*M) := hh - _ = _ := by ring - -lemma finiteMean_exp_bounded {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (Z : Ω → ℝ) (M t μ : ℝ) (hM : 0 < M) (ht : 0 ≤ t) - (hZ : ∀ ω, 0 ≤ Z ω ∧ Z ω ≤ M) (hmean : finiteMean Z ≤ μ) : - finiteMean (fun ω => Real.exp (t*Z ω)) ≤ - Real.exp (μ*((Real.exp (t*M)-1)/M)) := by - have hz : 0 ≤ (Real.exp (t*M)-1)/M := - div_nonneg (sub_nonneg.mpr (Real.one_le_exp_iff.mpr (mul_nonneg ht hM.le))) hM.le - calc - _ ≤ finiteMean (fun ω => 1 + Z ω*((Real.exp (t*M)-1)/M)) := - finiteMean_mono (fun ω => exp_secant hM (hZ ω).1 (hZ ω).2) - _ = 1 + finiteMean Z*((Real.exp (t*M)-1)/M) := by - rw [finiteMean_add,finiteMean_const,finiteMean_mul_const] - _ ≤ 1 + μ*((Real.exp (t*M)-1)/M) := by gcongr - _ ≤ _ := by simpa only [add_comm] using Real.add_one_le_exp (μ*((Real.exp (t*M)-1)/M)) - -namespace PairRouting -variable {ι : Type*} [Fintype ι] - -lemma node_cycle_mgf (d : ℕ) (e : ι ↪ Bool × Card d) (t : ℝ) (ht : 0 ≤ t) : - finiteMean (fun c : BenesCoins d × BenesCoins d => - Real.exp (t * alternatingCycles e - (fun b => palindromePerm d (if b then c.2 else c.1)))) ≤ - Real.exp ((sharedPairs e).card * DenseTruncation.h (d+1) * - ((Real.exp (t*(2:ℝ)^d)-1)/(2:ℝ)^d)) := by - apply finiteMean_exp_bounded _ _ _ _ (by positivity) ht _ (node_cycle_mean d e) - intro c - constructor - · exact Nat.cast_nonneg _ - · have h₀ := alternatingCycles_double e - (fun b => palindromePerm d (if b then c.2 else c.1)) - have h₁ := Fintype.card_le_of_injective e e.injective - simp only [Fintype.card_prod,Fintype.card_bool,card_positions] at h₁ - have h₂ : alternatingCycles e (fun b => palindromePerm d (if b then c.2 else c.1)) ≤ 2^d := by omega - exact_mod_cast h₂ - -end PairRouting - -open scoped BigOperators - -lemma shared_pair_mgf {β Ω : Type*} [Fintype β] [DecidableEq β] - [Fintype Ω] (F : Ω → Finset (Bool × β)) (p : Bool × β → ℝ) - (hp : ∀ x, 0 ≤ p x) (hc : CylinderBound (inclusionMoment F) p) - (z : ℝ) (hz : 0 ≤ z) : - finiteMean (fun ω => Real.exp (z * (boolFiber (F ω) false ∩ boolFiber (F ω) true).card)) ≤ - Real.exp ((Real.exp z - 1) * ∑ b, p (false,b)*p (true,b)) := by - classical - let T : β → Bool → Finset (Bool × β) := fun b q => - if q then {(false,b),(true,b)} else ∅ - let c : β → Bool → ℝ := fun _ q => if q then Real.exp z - 1 else 1 - have hcz : 0 ≤ Real.exp z - 1 := sub_nonneg.mpr (Real.one_le_exp_iff.mpr hz) - have hdis : ∀ b b', b ≠ b' → ∀ q q', Disjoint (T b q) (T b' q') := by - intro b b' h q q' - cases q <;> cases q' <;> simp [T,Finset.disjoint_left,h] - have hh := cylinder_block_polynomial (fun _ : β => Bool) F p hc T c - (fun b q => by cases q <;> simp only [c,↓reduceIte] <;> positivity) hdis - have hsum (A : Finset (Bool × β)) (b : β) : - (∑ q, c b q * if T b q ⊆ A then 1 else 0) = - Real.exp (z * if (false,b) ∈ A ∧ (true,b) ∈ A then 1 else 0) := by - simp only [Fintype.sum_bool,c,T,Bool.false_eq_true,↓reduceIte,Finset.empty_subset, - mul_one,Finset.insert_subset_iff,Finset.singleton_subset_iff] - split_ifs <;> simp - have hcard (A : Finset (Bool × β)) : - (∑ b : β, if (false,b) ∈ A ∧ (true,b) ∈ A then (1:ℝ) else 0) = - (boolFiber A false ∩ boolFiber A true).card := by - rw [Finset.sum_boole] - congr 2 - ext b - simp [mem_boolFiber] - have hleft (ω : Ω) : - (∏ b, ∑ q, c b q * if T b q ⊆ F ω then 1 else 0) = - Real.exp (z*(boolFiber (F ω) false ∩ boolFiber (F ω) true).card) := by - simp_rw [hsum] - rw [←Real.exp_sum,←Finset.mul_sum,hcard] - have hright (b : β) : - (∑ q, c b q * ∏ x ∈ T b q, p x) = - 1+(Real.exp z-1)*(p (false,b)*p (true,b)) := by - simp [c,T,add_comm] - simp_rw [hleft,hright] at hh - refine hh.trans ?_ - rw [Finset.mul_sum,Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact add_nonneg (by norm_num) (mul_nonneg hcz (mul_nonneg (hp _) (hp _))) - · intro b _ - simpa only [add_comm] using Real.add_one_le_exp ((Real.exp z-1)*(p (false,b)*p (true,b))) - -end Thorp - -namespace Thorp -variable {B : Type*} [Fintype B] [DecidableEq B] - -lemma prod_blockMarks (d : ℕ) (S : Finset (B × Card d)) (f : B × Card d → ℝ) : - (∏ x ∈ S, f x) = ∏ b, ∏ x ∈ blockMarks (Equiv.refl _) S b, f (b,x) := by - classical - have hb (b : B) : (∏ x ∈ blockMarks (Equiv.refl _) S b, f (b,x)) = - ∏ x, if (b,x) ∈ S then f (b,x) else 1 := by - exact Finset.prod_filter (fun x => (b,x) ∈ S) (fun x => f (b,x)) - simp_rw [hb] - rw [←Fintype.prod_prod_type (fun x : B × Card d => if x ∈ S then f x else 1)] - symm - calc - _ = ∏ x ∈ Finset.univ.filter (fun x : B × Card d => x ∈ S), f x := - (Finset.prod_filter _ _).symm - _ = _ := by simp - -omit [Fintype B] in -lemma subset_parallel_inverse (d : ℕ) (A S : Finset (B × Card d)) - (ω : B × SwitchIndex d → Bool) : - S ⊆ A.image (parallelPerm ω).symm ↔ - ∀ b, blockMarks (Equiv.refl _) S b ⊆ - inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) (fun i => ω (b,i)) := by - classical - constructor - · intro h b x hx - have hh := h ((mem_blockMarks (Equiv.refl _) S b x).mp hx) - rw [mem_image_perm_iff] at hh - rw [inverseButterflyMarks,mem_image_perm_iff] - exact (mem_blockMarks (Equiv.refl _) A b _).mpr hh - · intro h ⟨b,x⟩ hx - have hh := h b ((mem_blockMarks (Equiv.refl _) S b x).mpr hx) - rw [inverseButterflyMarks,mem_image_perm_iff] at hh - rw [mem_image_perm_iff] - exact (mem_blockMarks (Equiv.refl _) A b _).mp hh - -lemma parallel_inverse_cylinder (d : ℕ) (A : Finset (B × Card d)) : - CylinderBound (inclusionMoment (fun ω : B × SwitchIndex d → Bool => - A.image (parallelPerm ω).symm)) - (fun x => (blockMarks (Equiv.refl _) A x.1).card / (2:ℝ)^d) := by - classical - intro S - rw [inclusionMoment_eq,finiteMean_equiv (Equiv.curry B (SwitchIndex d) Bool)] - have hi (ω : B → SwitchIndex d → Bool) : - (if S ⊆ A.image (parallelPerm ((Equiv.curry B (SwitchIndex d) Bool).symm ω)).symm - then (1:ℝ) else 0) = - ∏ b, if blockMarks (Equiv.refl _) S b ⊆ inverseButterflyMarks d - (blockMarks (Equiv.refl _) A b) (ω b) then 1 else 0 := by - simp only [subset_parallel_inverse] - change (if ∀ b, blockMarks (Equiv.refl _) S b ⊆ inverseButterflyMarks d - (blockMarks (Equiv.refl _) A b) (ω b) then (1:ℝ) else 0) = _ - by_cases h : ∀ b, blockMarks (Equiv.refl _) S b ⊆ - inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) (ω b) - · simp [h] - · rw [ite_eq_right h] - obtain ⟨b,hb⟩ := not_forall.mp h - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - exact ite_eq_right hb - simp_rw [hi] - rw [finiteMean_pi_prod (fun b ω => if blockMarks (Equiv.refl _) S b ⊆ - inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) ω then 1 else 0),prod_blockMarks] - apply Finset.prod_le_prod₀ - · intro b _ - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - · intro b _ - simpa only [←inclusionMoment_eq,Finset.prod_const] using - inverseButterflyMarks_inclusion d (blockMarks (Equiv.refl _) A b) - (blockMarks (Equiv.refl _) S b) - -end Thorp - -namespace Thorp -namespace PairRouting -variable {ι : Type*} [Fintype ι] - -lemma node_cycle_mean_one_fresh (d : ℕ) (e : ι ↪ Bool × Card d) - (c₀ : BenesCoins d) (X : SwitchIndex d → Bool) : - finiteMean (fun Y : SwitchIndex d → Bool => - (alternatingCycles e (fun b => palindromePerm d (if b then (Y,X) else c₀)) : ℝ)) ≤ - (sharedPairs e).card * DenseTruncation.h (d+1) := by - classical - calc - _ ≤ finiteMean (fun Y : SwitchIndex d → Bool => - (Fintype.card (RoutingNetwork.SelectedCycle - ((palindromePerm d c₀).symm * butterflyPerm d (decodeButterfly d Y) * - (butterflyPerm d (decodeButterfly d X)).symm) (sharedPairs e)) : ℝ)) := by - apply finiteMean_mono - intro Y - have hh := alternatingCycles_le_sharedSelected e - (fun b => palindromePerm d (if b then (Y,X) else c₀)) - simpa only [alternatingProjection,Bool.false_eq_true,↓reduceIte,palindromePerm,mul_assoc] using - (Nat.cast_le.mpr hh : (alternatingCycles e _ : ℝ) ≤ _) - _ ≤ _ := relabeled_single_cycle_mean d _ _ _ - -lemma node_cycle_mgf_fixed_input (d : ℕ) (e : ι ↪ Bool × Card d) - (X : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (t : ℝ) (ht : 0 ≤ t) : - finiteMean (fun Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - Real.exp (t * alternatingCycles e - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))))) ≤ - Real.exp ((sharedPairs e).card * DenseTruncation.h (d+1) * - ((Real.exp (t*(2:ℝ)^d)-1)/(2:ℝ)^d)) := by - apply finiteMean_exp_bounded _ _ _ _ (by positivity) ht - · intro Y - constructor - · exact Nat.cast_nonneg _ - · have h₀ := alternatingCycles_double e - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) - have h₁ := Fintype.card_le_of_injective e e.injective - simp only [Fintype.card_prod,Fintype.card_bool,card_positions] at h₁ - exact_mod_cast (show alternatingCycles e _ ≤ 2^d by omega) - · rw [finiteMean_prod] - calc - _ ≤ finiteMean (fun _ : SwitchIndex d → Bool => - (sharedPairs e).card * DenseTruncation.h (d+1)) := - finiteMean_mono (fun Y => node_cycle_mean_one_fresh d e (Y,X.1) X.2) - _ = _ := finiteMean_const _ - -end PairRouting - -noncomputable def sharedLevel (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, X => - let χ := coinStepEquiv d X - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - if t = d+1 then (PairRouting.sharedPairs x).card else - sharedLevel t d (PairRouting.childEmbedding x c hc false) χ.1.1 + - sharedLevel t d (PairRouting.childEmbedding x c hc true) χ.1.2 - -noncomputable def denseLevelCoefficient (j : ℕ) (t : ℝ) : ℝ := - DenseTruncation.h (j+1) * ((Real.exp (t*(2:ℝ)^j)-1)/(2:ℝ)^j) - -lemma denseLevelCoefficient_nonneg (j : ℕ) {t : ℝ} (ht : 0 ≤ t) : - 0 ≤ denseLevelCoefficient j t := by - apply mul_nonneg (DenseTruncation.h_nonneg _) - apply div_nonneg _ (by positivity) - exact sub_nonneg.mpr (Real.one_le_exp_iff.mpr (mul_nonneg ht (by positivity))) - -lemma palindrome_level_dense_conditional (j d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (t : ℝ) (ht : 0 ≤ t) : - finiteMean (fun Y : SwitchIndex d → Bool => - Real.exp (t * palindromeLevelCost (j+1) d e (Y,X))) ≤ - Real.exp (denseLevelCoefficient j t * sharedLevel (j+1) d e X) := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLevelCost,sharedLevel,Nat.cast_zero,mul_zero, - Real.exp_zero,finiteMean_const,le_refl] - | succ d ih => - let χ := coinStepEquiv d X - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - have hs (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : - palindromeLevelCost (j+1) (d+1) e ((coinStepEquiv d).symm (Y,η),X) = - if j+1 = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x χ.2) - (fun b => palindromePerm d (if b then (Y.2,χ.1.2) else (Y.1,χ.1.1))) else - palindromeLevelCost (j+1) d e₀ (Y.1,χ.1.1) + - palindromeLevelCost (j+1) d e₁ (Y.2,χ.1.2) := by - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step] - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - simp_rw [hs,finiteMean_const] - change _ ≤ Real.exp (denseLevelCoefficient j t * - (if j+1 = d+1 then (PairRouting.sharedPairs x).card else - sharedLevel (j+1) d e₀ χ.1.1 + sharedLevel (j+1) d e₁ χ.1.2)) - by_cases hj : j = d - · subst j - simp only [ite_true] - have hh := PairRouting.node_cycle_mgf_fixed_input d - (PairRouting.switchedEmbedding x χ.2) χ.1 t ht - rw [PairRouting.sharedPairs_switched] at hh - simpa only [denseLevelCoefficient,mul_left_comm,mul_assoc,mul_comm] using hh - · have hne : j+1 ≠ d+1 := by omega - simp only [ite_eq_right hne,Nat.cast_add,mul_add,Real.exp_add] - rw [finiteMean_prod_mul - (fun Y : SwitchIndex d → Bool => Real.exp (t * palindromeLevelCost (j+1) d e₀ (Y,χ.1.1))) - (fun Y : SwitchIndex d → Bool => Real.exp (t * palindromeLevelCost (j+1) d e₁ (Y,χ.1.2)))] - exact mul_le_mul (ih e₀ χ.1.1) (ih e₁ χ.1.2) - (finiteMean_nonneg (fun _ => (Real.exp_pos _).le)) (Real.exp_pos _).le - - -def pairCoords (r s : ℕ) : Card ((s+1)+r) ≃ Bool × (Card r × Card s) := - (cardSplit r (s+1)).trans - { toFun := fun x => ((x.2) 0,(x.1,Fin.tail x.2)) - invFun := fun x => (x.2.1,Fin.cons x.1 x.2.2) - left_inv := by intro x; simp only [Fin.cons_self_tail] - right_inv := by intro x; simp only [Fin.cons_zero,Fin.tail_cons] } - -noncomputable def gridPairs (r s : ℕ) (A : Finset (Card ((s+1)+r))) : Finset (Card r × Card s) := - Finset.univ.filter (fun x => (pairCoords r s).symm (false,x) ∈ A ∧ - (pairCoords r s).symm (true,x) ∈ A) - -noncomputable def gridShared (r s : ℕ) (A : Finset (Card ((s+1)+r))) : ℕ := - (gridPairs r s A).card - -lemma gridPairs_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : - gridPairs r s A = boolFiber (A.image (pairCoords r s)) false ∩ - boolFiber (A.image (pairCoords r s)) true := by - classical - ext x - have hm (b : Bool) : (b,x) ∈ A.image (pairCoords r s) ↔ - (pairCoords r s).symm (b,x) ∈ A := by - constructor - · rintro h - obtain ⟨a,ha,he⟩ := Finset.mem_image.mp h - rw [←he,Equiv.symm_apply_apply] - exact ha - · intro h - exact Finset.mem_image.mpr ⟨_,h,(pairCoords r s).apply_symm_apply _⟩ - simp only [gridPairs,Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_inter, - mem_boolFiber,hm] - -lemma gridShared_zero (s : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+1)) : - gridShared 0 s (Finset.univ.image e) = - (PairRouting.sharedPairs (e.trans (headTailEquiv s).toEmbedding)).card := by - classical - let z : Card 0 := fun i => Fin.elim0 i - have he : gridPairs 0 s (Finset.univ.image e) = - (PairRouting.sharedPairs (e.trans (headTailEquiv s).toEmbedding)).image (fun y => (z,y)) := by - ext ⟨b,y⟩ - have hb : b = z := Subsingleton.elim _ _ - subst b - simp only [gridPairs,Finset.mem_filter,Finset.mem_univ,true_and, - PairRouting.sharedPairs,Finset.mem_inter,mem_boolFiber,PairRouting.labelSet, - Finset.mem_image,Prod.mk.injEq,true_and] - change ((∃ i, e i = Fin.cons false y) ∧ ∃ i, e i = Fin.cons true y) ↔ _ - simp only [Function.Embedding.trans_apply,Equiv.toEmbedding_apply, - headTailEquiv] - constructor - · rintro ⟨⟨i,hi⟩,⟨i',hi'⟩⟩ - refine ⟨y,⟨?_,?_⟩,rfl⟩ - · exact ⟨i,by change (e i 0,Fin.tail (e i)) = (false,y); rw [hi]; rfl⟩ - · exact ⟨i',by change (e i' 0,Fin.tail (e i')) = (true,y); rw [hi']; rfl⟩ - · rintro ⟨y',⟨⟨i,hi⟩,⟨i',hi'⟩⟩,rfl⟩ - constructor - · exact ⟨i,(headTailEquiv s).injective hi⟩ - · exact ⟨i',(headTailEquiv s).injective hi'⟩ - rw [gridShared,he,Finset.card_image_of_injective] - intro y y' h - exact congrArg Prod.snd h - -lemma gridShared_step (r s : ℕ) (A : Finset (Card ((s+1)+(r+1)))) : - gridShared (r+1) s A = gridShared r s (childMarks A false) + - gridShared r s (childMarks A true) := by - classical - have hsum (r : ℕ) (A : Finset (Card ((s+1)+r))) : gridShared r s A = - ∑ b : Card r, ∑ y : Card s, - if (pairCoords r s).symm (false,(b,y)) ∈ A ∧ - (pairCoords r s).symm (true,(b,y)) ∈ A then (1:ℕ) else 0 := by - rw [gridShared,gridPairs,Finset.card_filter,Fintype.sum_prod_type] - rw [hsum,hsum,hsum,←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - have hc (b : Bool) (x : Card r) (y : Card s) (ε : Bool) : - (pairCoords (r+1) s).symm (ε,((headTailEquiv r).symm (b,x),y)) = - Fin.cons b ((pairCoords r s).symm (ε,(x,y))) := rfl - simp only [hc,mem_childMarks] - exact add_comm _ _ - -lemma butterfly_false (d : ℕ) : - butterflyPerm d (decodeButterfly d (fun _ => false)) = 1 := by - induction d with - | zero => exact Subsingleton.elim _ _ - | succ d ih => - have he : (fun _ : SwitchIndex (d+1) => false) = (coinStepEquiv d).symm - (((fun _ => false),(fun _ => false)),fun _ => false) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - rw [he,butterflyPerm_step] - ext x i - simp [ih,Equiv.Perm.mul_apply,childLift] - change Fin.cons (Bool.xor (x 0) false) (Fin.tail x) i = x i - simp - -lemma inverseButterflyMarks_false (d : ℕ) (A : Finset (Card d)) : - inverseButterflyMarks d A (fun _ => false) = A := by - rw [inverseButterflyMarks,butterfly_false] - change Finset.image id A = A - exact Finset.image_id - - -lemma sharedLevel_partial_marks (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card ((s+1)+r)) - (lo : Card r × SwitchIndex (s+1) → Bool) - (hi : Card (s+1) × SwitchIndex r → Bool) : - sharedLevel (s+1) ((s+1)+r) e (assembleBits r (s+1) lo hi) = - gridShared r s (inverseButterflyMarks ((s+1)+r) (Finset.univ.image e) - (assembleBits r (s+1) (fun _ => false) hi)) := by - classical - induction r generalizing ι with - | zero => - rw [show assembleBits 0 (s+1) (fun _ => false) hi = (fun _ => false) from rfl, - inverseButterflyMarks_false,gridShared_zero] - simp only [sharedLevel,ite_true] - | succ r ih => - obtain ⟨c,rfl⟩ := (highStepEquiv r (s+1)).symm.surjective hi - simp only [Nat.add_succ] at * - rw [assembleBits_step,sharedLevel] - simp only [Equiv.apply_symm_apply] - rw [ite_eq_right (by omega : s+1 ≠ s+1+r+1)] - rw [ih,ih,assembleBits_step,gridShared_step, - inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - -lemma partial_input_parallel (r s : ℕ) (hi : Card s × SwitchIndex r → Bool) - (x : Card (s+r)) : - ((cardSplit r s).trans (Equiv.prodComm _ _)) - ((butterflyPerm (s+r) (decodeButterfly (s+r) - (assembleBits r s (fun _ => false) hi))).symm x) = - (parallelPerm hi).symm (((cardSplit r s).trans (Equiv.prodComm _ _)) x) := by - let y := (butterflyPerm (s+r) (decodeButterfly (s+r) - (assembleBits r s (fun _ => false) hi))).symm x - have hh := butterfly_split r s (fun _ => false) hi y - dsimp only [y] at hh - simp only [butterfly_false,Equiv.Perm.one_apply,Equiv.apply_symm_apply] at hh - change cardSplit r s x = - (butterflyPerm r (decodeButterfly r (fun i => hi ((cardSplit r s y).2,i))) - (cardSplit r s y).1,(cardSplit r s y).2) at hh - have hs := congrArg Prod.snd hh - have hf := congrArg Prod.fst hh - dsimp only at hs hf - change ((cardSplit r s y).2,(cardSplit r s y).1) = - ((cardSplit r s x).2,(butterflyPerm r - (decodeButterfly r (fun i => hi ((cardSplit r s x).2,i)))).symm (cardSplit r s x).1) - rw [hs,hf,Equiv.symm_apply_apply] - -lemma partial_marks_parallel (r s : ℕ) (A : Finset (Card (s+r))) - (hi : Card s × SwitchIndex r → Bool) : - (inverseButterflyMarks (s+r) A (assembleBits r s (fun _ => false) hi)).image - ((cardSplit r s).trans (Equiv.prodComm _ _)) = - (A.image ((cardSplit r s).trans (Equiv.prodComm _ _))).image (parallelPerm hi).symm := by - classical - simp only [inverseButterflyMarks,Finset.image_image] - congr 1 - funext x - exact partial_input_parallel r s hi x - -lemma cylinder_image_equiv_bound {α β Ω : Type*} [DecidableEq α] [DecidableEq β] - [Fintype Ω] (e : α ≃ β) (F : Ω → Finset α) (p : α → ℝ) - (h : CylinderBound (inclusionMoment F) p) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) (fun x => p (e.symm x)) := by - intro S - rw [inclusionMoment_image_equiv] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - - -noncomputable def suffixMarks (r s : ℕ) (A : Finset (Card (s+r))) (y : Card s) : Finset (Card r) := - blockMarks ((cardSplit r s).trans (Equiv.prodComm _ _)) A y - -noncomputable def sharedPartnerMean (r s : ℕ) (A : Finset (Card ((s+1)+r))) : ℝ := - (∑ y : Card s, ((suffixMarks r (s+1) A (Fin.cons false y)).card : ℝ) * - (suffixMarks r (s+1) A (Fin.cons true y)).card) / (2:ℝ)^r - -lemma blockMarks_image_equiv {α B : Type*} [Fintype α] [DecidableEq α] - [Fintype B] [DecidableEq B] (r : ℕ) (E : α ≃ B × Card r) - (A : Finset α) (b : B) : - blockMarks (Equiv.refl _) (A.image E) b = blockMarks E A b := by - classical - ext y - simp only [mem_blockMarks,Equiv.refl_symm,Equiv.refl_apply,Finset.mem_image] - constructor - · rintro ⟨x,hx,he⟩ - rw [←he,Equiv.symm_apply_apply] - exact hx - · intro h - exact ⟨_,h,E.apply_symm_apply _⟩ - -def pairReorder (r s : ℕ) : Card (s+1) × Card r ≃ Bool × (Card r × Card s) where - toFun x := (x.1 0,(x.2,Fin.tail x.1)) - invFun x := (Fin.cons x.1 x.2.2,x.2.1) - left_inv x := by simp only [Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero,Fin.tail_cons] - -lemma pairCoords_reorder (r s : ℕ) : - pairCoords r s = ((cardSplit r (s+1)).trans (Equiv.prodComm _ _)).trans (pairReorder r s) := rfl - -lemma partial_grid_mgf (r s : ℕ) (A : Finset (Card ((s+1)+r))) - (z : ℝ) (hz : 0 ≤ z) : - finiteMean (fun hi : Card (s+1) × SwitchIndex r → Bool => - Real.exp (z * gridShared r s (inverseButterflyMarks ((s+1)+r) A - (assembleBits r (s+1) (fun _ => false) hi)))) ≤ - Real.exp ((Real.exp z-1)*sharedPartnerMean r s A) := by - classical - let E := (cardSplit r (s+1)).trans (Equiv.prodComm _ _) - let F (hi : Card (s+1) × SwitchIndex r → Bool) := (A.image E).image (parallelPerm hi).symm - let p (x : Card (s+1) × Card r) : ℝ := - (suffixMarks r (s+1) A x.1).card / (2:ℝ)^r - have hc : CylinderBound (inclusionMoment F) p := by - have hh := parallel_inverse_cylinder r (A.image E) - simp only [blockMarks_image_equiv] at hh - exact hh - have hp : ∀ x, 0 ≤ p x := by intro x; exact div_nonneg (Nat.cast_nonneg _) (by positivity) - have hh := shared_pair_mgf (fun hi => (F hi).image (pairReorder r s)) - (fun x => p ((pairReorder r s).symm x)) (fun x => hp _) - (cylinder_image_equiv_bound (pairReorder r s) F p hc) z hz - have he (hi : Card (s+1) × SwitchIndex r → Bool) : - (F hi).image (pairReorder r s) = - (inverseButterflyMarks ((s+1)+r) A - (assembleBits r (s+1) (fun _ => false) hi)).image (pairCoords r s) := by - rw [pairCoords_reorder] - change (F hi).image (pairReorder r s) = - (inverseButterflyMarks ((s+1)+r) A - (assembleBits r (s+1) (fun _ => false) hi)).image ((pairReorder r s) ∘ E) - rw [←Finset.image_image,partial_marks_parallel] - have hm : (∑ b : Card r × Card s, - p ((pairReorder r s).symm (false,b))*p ((pairReorder r s).symm (true,b))) = - sharedPartnerMean r s A := by - simp only [p,pairReorder,Equiv.coe_fn_symm_mk,Fintype.sum_prod_type] - rw [Finset.sum_const,Finset.card_univ,card_positions,nsmul_eq_mul] - simp only [sharedPartnerMean, div_mul_div_comm, ←Finset.sum_div] - rw [show (↑(2^r) : ℝ) = (2:ℝ)^r by rfl] - have hpow : (2:ℝ)^r ≠ 0 := by positivity - generalize (∑ y : Card s, (suffixMarks r (s+1) A (Fin.cons false y)).card * - (suffixMarks r (s+1) A (Fin.cons true y)).card : ℝ) = v - field_simp - ; push_cast - ; ring - simp_rw [he,←gridPairs_eq] at hh - rw [hm] at hh - exact hh - -end Thorp - -end ThorpNine.Dense - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Dense.PalindromeFamilyCost + +namespace OAI + +namespace ThorpNine.Dense + +open scoped BigOperators +namespace Thorp.RoutingNetwork +open scoped BigOperators +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def singleSlotsEquiv (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : + CycleSlots p S (fun _ : Fin 1 => r) ≃ + {C : SelectedCycle p S // C.val.card = r+1} := + (cycleSlotsEquivAssignments p S (fun _ : Fin 1 => r)).trans + { toFun := fun a => ⟨a.val 0, a.property.2 0⟩ + invFun := fun C => ⟨fun _ => C.val, Function.injective_of_subsingleton _, fun _ => C.property⟩ + left_inv := fun a => by + apply Subtype.ext + funext i + have hi : i=0 := Subsingleton.elim _ _ + subst i + rfl + right_inv := fun C => rfl } + +noncomputable def cycleCount (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : ℝ := + Fintype.card {C : SelectedCycle p S // C.val.card = r+1} + +lemma cycleCount_eq_sum (p : Equiv.Perm α) (S : Finset α) (r : ℕ) : + cycleCount p S r = ∑ C : SelectedCycle p S, if C.val.card=r+1 then (1:ℝ) else 0 := by + classical + simp only [cycleCount, Fintype.card_subtype, Finset.sum_boole] + +lemma hasSum_cycleCount_weight (p : Equiv.Perm α) (S : Finset α) (f : ℕ → ℝ) : + HasSum (fun l => cycleCount p S l * f (l+1)) + (∑ C : SelectedCycle p S, f C.val.card) := by + classical + have h (C : SelectedCycle p S) : + HasSum (fun l : ℕ => if C.val.card=l+1 then f C.val.card else 0) (f C.val.card) := by + have hc : 1 ≤ C.val.card := C.nonempty.card_pos + have hs := hasSum_single (C.val.card-1) + (f := fun l : ℕ => if C.val.card=l+1 then f C.val.card else 0) + (fun l hl => ite_eq_right (by omega)) + simpa only [Nat.sub_add_cancel hc, ↓reduceIte] using hs + convert hasSum_sum (s := Finset.univ) (fun C _ => h C) using 1 + funext l + rw [cycleCount_eq_sum, Finset.sum_mul] + apply Finset.sum_congr rfl + intro C _ + split_ifs with hc + · simp only [one_mul, hc] + · simp + +end Thorp.RoutingNetwork + +namespace Thorp +open scoped BigOperators +lemma hasSum_finiteMean {Ω : Type*} [Fintype Ω] {f : Ω → ℕ → ℝ} {a : Ω → ℝ} + (hf : ∀ ω, HasSum (f ω) (a ω)) : + HasSum (fun l => finiteMean (fun ω => f ω l)) (finiteMean a) := + (hasSum_sum (s := Finset.univ) (fun ω _ => hf ω)).div_const (Fintype.card Ω : ℝ) +end Thorp + +namespace Thorp.RoutingNetwork +open scoped BigOperators +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma selected_cycle_mean_le_h (S : Finset α) : + finiteMean (fun ω : ι → Bool => (Fintype.card (SelectedCycle (R.perm ω) S) : ℝ)) ≤ + (S.card : ℝ) * DenseTruncation.h (d+1) := by + classical + by_cases hS : S.Nonempty + · have hpos : (0:ℝ) < S.card := Nat.cast_pos.mpr hS.card_pos + let w : ℕ → ℝ := fun l => finiteMean (fun ω : ι → Bool => cycleCount (R.perm ω) S l) + have hw : ∀ l, 0 ≤ w l := fun _ => finiteMean_nonneg (fun _ => Nat.cast_nonneg _) + have hc (l : ℕ) : w l ≤ (S.card : ℝ) / (2:ℝ)^d := by + apply (le_div_iff₀ (by positivity : 0 < (2:ℝ)^d)).mpr + have he (ω : ι → Bool) : cycleCount (R.perm ω) S l = + (Fintype.card (CycleSlots (R.perm ω) S (fun _ : Fin 1 => l)) : ℝ) := by + rw [cycleCount, Fintype.card_congr (singleSlotsEquiv (R.perm ω) S l)] + simpa only [w,he] using single_cycleSlots_weighted_moment R S l + have hmass := hasSum_finiteMean (fun ω : ι → Bool => + hasSum_cycleCount_weight (R.perm ω) S (fun n => (n:ℝ))) + have hm : HasSum (fun l => ((l+1 : ℕ) : ℝ) * w l) + (finiteMean (fun ω : ι → Bool => (cycleMass (R.perm ω) S : ℝ))) := by + simp only [finiteMean_mul_const] at hmass + simpa only [w, mul_comm, cycleMass,Nat.cast_sum] using hmass + have hmt : finiteMean (fun ω : ι → Bool => (cycleMass (R.perm ω) S : ℝ)) ≤ S.card := by + calc + _ ≤ finiteMean (fun _ : ι → Bool => (S.card : ℝ)) := + finiteMean_mono (fun ω => by exact_mod_cast cycleMass_le (R.perm ω) S) + _ = _ := finiteMean_const _ + let q : ℕ → ℝ := fun l => ((l+1 : ℕ) : ℝ) * w l / S.card + have hq : ∀ l, 0 ≤ q l := fun l => div_nonneg (mul_nonneg (by positivity) (hw l)) hpos.le + have hqs : Summable q := (hm.div_const (S.card : ℝ)).summable + have hqt : (∑' l, q l) ≤ 1 := by + rw [(hm.div_const (S.card : ℝ)).tsum_eq] + exact (div_le_one hpos).mpr hmt + have hqc (l : ℕ) : q l ≤ ((l+1 : ℕ) : ℝ) / (2:ℝ)^((d+1)-1) := by + simp only [Nat.add_sub_cancel] + dsimp [q] + calc + _ ≤ (((l+1 : ℕ) : ℝ) * ((S.card : ℝ) / (2:ℝ)^d)) / S.card := by + gcongr + exact hc l + _ = _ := by field_simp + have hh := DenseTruncation.subprob_reciprocal_le_h hq hqs hqt hqc + have hcount := hasSum_finiteMean (fun ω : ι → Bool => + hasSum_cycleCount_weight (R.perm ω) S (fun _ => (1:ℝ))) + have hwc : HasSum w (finiteMean (fun ω : ι → Bool => + (Fintype.card (SelectedCycle (R.perm ω) S) : ℝ))) := by + simpa only [mul_one,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] using hcount + have he (l : ℕ) : q l / ((l+1 : ℕ) : ℝ) = w l / S.card := by + have hl : ((l+1 : ℕ) : ℝ) ≠ 0 := by positivity + dsimp [q] + field_simp + simp only [he, (hwc.div_const (S.card : ℝ)).tsum_eq] at hh + simpa only [mul_comm] using (div_le_iff₀ hpos).mp hh + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + have hz (ω : ι → Bool) : Fintype.card (SelectedCycle (R.perm ω) ∅) = 0 := by + let : IsEmpty (SelectedCycle (R.perm ω) ∅) := + ⟨fun C => C.nonempty.ne_empty (Finset.subset_empty.mp C.property.2)⟩ + exact Fintype.card_eq_zero + simp only [hz,Nat.cast_zero,finiteMean_const,Finset.card_empty,zero_mul,le_refl] + +end Thorp.RoutingNetwork + +namespace Thorp.DenseTruncation +open scoped BigOperators + +lemma reciprocal_values_nonempty (j : ℕ) : + {z : ℝ | ∃ p : ℕ → ℝ, AdmissibleCycleLaw j p ∧ + z = ∑' l : ℕ, p l / ((l+1 : ℕ) : ℝ)}.Nonempty := by + let t := 2^(j-1)-1 + have ht : t+1 = 2^(j-1) := Nat.sub_add_cancel (Nat.one_le_pow _ _ (by norm_num)) + let p : ℕ → ℝ := fun l => if l=t then 1 else 0 + have hp : AdmissibleCycleLaw j p := by + refine ⟨fun l => by dsimp [p]; split_ifs <;> norm_num, hasSum_ite_eq t 1, ?_⟩ + intro l + by_cases hl : l=t + · subst l + have he : ((t+1 : ℕ) : ℝ) = (2:ℝ)^(j-1) := by rw [ht]; norm_cast + simp only [p,↓reduceIte,he,div_self (by positivity : (2:ℝ)^(j-1) ≠ 0),le_refl] + · simp only [p,ite_eq_right hl] + positivity + exact ⟨_,p,hp,rfl⟩ + +lemma h_nonneg (j : ℕ) : 0 ≤ h j := by + obtain ⟨z,p,hp,rfl⟩ := reciprocal_values_nonempty j + exact (law_reciprocal_nonneg hp).trans (reciprocal_le_h hp) + +lemma h_le_one (j : ℕ) : h j ≤ 1 := + csSup_le (reciprocal_values_nonempty j) (fun _ ⟨_,hp,hz⟩ => hz ▸ law_reciprocal_le_one hp) + +lemma law_reciprocal_cutoff {j : ℕ} {p : ℕ → ℝ} (hp : AdmissibleCycleLaw j p) + (L : ℕ) (hL : 0 < L) : + (∑' l, p l / ((l+1 : ℕ) : ℝ)) ≤ (L : ℝ)/(2:ℝ)^(j-1) + 1/L := by + let a : ℕ → ℝ := fun l => if l by simpa only [a,Finset.mem_range] using ite_eq_right (show ¬l hl (Finset.mem_range.mpr hh))) + simpa only [a,Finset.sum_ite_of_true (fun l hl => Finset.mem_range.mp hl), + Finset.sum_const,Finset.card_range,nsmul_eq_mul,mul_one_div] using hs + have hb := hp.2.1.div_const (L:ℝ) + have he (l : ℕ) : p l / ((l+1 : ℕ) : ℝ) ≤ a l + p l/L := by + by_cases hl : l hz ▸ law_reciprocal_cutoff hp L hL) + +lemma h_dyadic_bound (j : ℕ) : h (j+1) ≤ 2/(2:ℝ)^(j/2) := by + have h := h_cutoff (j+1) (2^(j/2)) (by positivity) + simp only [Nat.add_sub_cancel,Nat.cast_pow,Nat.cast_ofNat] at h + have hpow : ((2:ℝ)^(j/2))^2 ≤ (2:ℝ)^j := by + rw [←pow_mul] + exact pow_le_pow_right₀ (by norm_num) (by omega) + have hp : (0:ℝ) < (2:ℝ)^(j/2) := by positivity + have hq : (0:ℝ) < (2:ℝ)^j := by positivity + have hr : (2:ℝ)^(j/2)/(2:ℝ)^j ≤ 1/(2:ℝ)^(j/2) := by + apply (div_le_div_iff₀ hq hp).mpr + nlinarith + calc + _ ≤ 1/(2:ℝ)^(j/2) + 1/(2:ℝ)^(j/2) := h.trans (by linarith) + _ = _ := by ring + +lemma summable_half_dyadic : Summable (fun j : ℕ => 2/(2:ℝ)^(j/2)) := by + apply ((Nat.divModEquiv 2).symm.summable_iff).mp + have he (p : ℕ × Fin 2) : 2/(2:ℝ)^(((Nat.divModEquiv 2).symm p)/2) = + 2*(1/2:ℝ)^p.1 := by + rw [Nat.divModEquiv_symm_apply] + have hi : (p.1*2+p.2.val)/2 = p.1 := by omega + rw [hi,div_pow,one_pow] + ring + simp only [Function.comp_def,he] + apply (summable_prod_of_nonneg (fun p => by positivity)).mpr + constructor + · intro n + exact (hasSum_fintype _).summable + · simpa only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_ofNat,←mul_assoc,show (2:ℝ)*2=4 from by norm_num] using summable_geometric_two.mul_left 4 + +lemma h_summable : Summable (fun j => h (j+1)) := + Summable.of_nonneg_of_le (fun j => h_nonneg (j+1)) h_dyadic_bound summable_half_dyadic + +lemma allocation_value_summable {ρ : ℝ} {x : ℕ → ℝ} (hx : AdmissibleAllocation ρ x) : + Summable (fun j => h (j+1)*x j) := + Summable.of_nonneg_of_le (fun j => mul_nonneg (h_nonneg _) (hx.1 j).1) + (fun j => mul_le_of_le_one_right (h_nonneg _) (hx.1 j).2) h_summable + +lemma H_values_bdd (ρ : ℝ) : BddAbove {z : ℝ | ∃ x : ℕ → ℝ, + AdmissibleAllocation ρ x ∧ z = (1/2:ℝ)*∑' j, h (j+1)*x j} := by + refine ⟨(1/2:ℝ)*∑' j, h (j+1), ?_⟩ + rintro z ⟨x,hx,rfl⟩ + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact Summable.tsum_le_tsum (fun j => mul_le_of_le_one_right (h_nonneg _) (hx.1 j).2) + (allocation_value_summable hx) h_summable + +lemma allocation_le_H {ρ : ℝ} {x : ℕ → ℝ} (hx : AdmissibleAllocation ρ x) : + (1/2:ℝ)*∑' j, h (j+1)*x j ≤ H ρ := + le_csSup (H_values_bdd ρ) ⟨x,hx,rfl⟩ + +end Thorp.DenseTruncation + +namespace Thorp +open scoped BigOperators + +def unitCardEquiv (d : ℕ) : Card d ≃ Unit × Card d where + toFun x := ((),x) + invFun x := x.2 + left_inv _ := rfl + right_inv x := by cases x with | mk u x => cases u; rfl + +def unitBitsEquiv (d : ℕ) : (Unit × SwitchIndex d → Bool) ≃ (SwitchIndex d → Bool) where + toFun ω i := ω ((),i) + invFun ω i := ω i.2 + left_inv ω := by funext i; rcases i with ⟨u,i⟩; cases u; rfl + right_inv _ := rfl + +lemma relabeled_single_cycle_mean (d : ℕ) (pre post : Equiv.Perm (Card d)) + (S : Finset (Card d)) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (RoutingNetwork.SelectedCycle + (post * butterflyPerm d (decodeButterfly d ω) * pre) S) : ℝ)) ≤ + (S.card : ℝ)*DenseTruncation.h (d+1) := by + have hh := RoutingNetwork.selected_cycle_mean_le_h + (parallelNetwork (pre.trans (unitCardEquiv d)) ((unitCardEquiv d).symm.trans post)) S + rw [finiteMean_equiv (unitBitsEquiv d)] at hh + exact hh + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def projectSharedCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p (A ∩ B) := by + refine ⟨(projectCycle p A B C).val, (projectCycle p A B C).property.1, ?_⟩ + intro x hx + apply Finset.mem_inter.mpr + refine ⟨(projectCycle p A B C).property.2 hx, ?_⟩ + have he := selected_alternating_eq p A B C + have hc : (true,x) ∈ C.val := by + rw [he] + exact (mem_childJoin _ _ true x).mpr hx + exact (mem_childJoin A B true x).mp (C.property.2 hc) + +lemma projectSharedCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectSharedCycle p A B) := by + intro C D h + apply projectCycle_injective p A B + apply Subtype.ext + change (projectSharedCycle p A B C).val = (projectSharedCycle p A B D).val + exact congrArg Subtype.val h + +lemma card_alternating_cycles_le_shared (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p (A ∩ B)) := + Fintype.card_le_of_injective _ (projectSharedCycle_injective p A B) + +end CycleColoring + +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def sharedPairs (e : ι ↪ Bool × α) : Finset α := + boolFiber (labelSet e) false ∩ boolFiber (labelSet e) true + +lemma alternatingCycles_le_sharedSelected (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (sharedPairs e)) := by + unfold alternatingCycles sharedPairs + conv_lhs => rw [←childJoin_boolFiber (labelSet e)] + exact CycleColoring.card_alternating_cycles_le_shared _ _ _ + +omit [Fintype α] in +lemma sharedPairs_card_twice_le (e : ι ↪ Bool × α) : + 2*(sharedPairs e).card ≤ Fintype.card ι := by + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + have h₀ := Finset.card_le_card (Finset.inter_subset_left : sharedPairs e ⊆ boolFiber (labelSet e) false) + have h₁ := Finset.card_le_card (Finset.inter_subset_right : sharedPairs e ⊆ boolFiber (labelSet e) true) + simp only [sharedPairs] at * + omega + +omit [Fintype α] in +lemma labelSet_switched (e : ι ↪ Bool × α) (ξ : α → Bool) : + labelSet (switchedEmbedding e ξ) = (labelSet e).image (pairLayer ξ) := by + classical + simp only [labelSet,Finset.image_image,switchedEmbedding] + rfl + +omit [Fintype α] in +lemma sharedPairs_switched (e : ι ↪ Bool × α) (ξ : α → Bool) : + sharedPairs (switchedEmbedding e ξ) = sharedPairs e := by + classical + ext x + simp only [sharedPairs,Finset.mem_inter,mem_boolFiber,labelSet_switched,mem_image_perm_iff] + change (Bool.xor false (ξ x),x) ∈ labelSet e ∧ + (Bool.xor true (ξ x),x) ∈ labelSet e ↔ + (false,x) ∈ labelSet e ∧ (true,x) ∈ labelSet e + cases ξ x <;> simp only [Bool.xor_false,Bool.xor_true,Bool.not_false,Bool.not_true,and_comm] + +lemma node_cycle_mean (d : ℕ) (e : ι ↪ Bool × Card d) : + finiteMean (fun c : BenesCoins d × BenesCoins d => + (alternatingCycles e (fun b => palindromePerm d (if b then c.2 else c.1)) : ℝ)) ≤ + (sharedPairs e).card * DenseTruncation.h (d+1) := by + classical + rw [finiteMean_prod] + have hone (c₀ : BenesCoins d) : + finiteMean (fun c₁ : BenesCoins d => + (alternatingCycles e (fun b => palindromePerm d (if b then c₁ else c₀)) : ℝ)) ≤ + (sharedPairs e).card * DenseTruncation.h (d+1) := by + rw [finiteMean_prod,finiteMean_comm] + have hf (X : SwitchIndex d → Bool) : + finiteMean (fun Y : SwitchIndex d → Bool => + (alternatingCycles e (fun b => palindromePerm d (if b then (Y,X) else c₀)) : ℝ)) ≤ + (sharedPairs e).card * DenseTruncation.h (d+1) := by + calc + _ ≤ finiteMean (fun Y : SwitchIndex d → Bool => + (Fintype.card (RoutingNetwork.SelectedCycle + ((palindromePerm d c₀).symm * butterflyPerm d (decodeButterfly d Y) * + (butterflyPerm d (decodeButterfly d X)).symm) (sharedPairs e)) : ℝ)) := by + apply finiteMean_mono + intro Y + have hh := alternatingCycles_le_sharedSelected e + (fun b => palindromePerm d (if b then (Y,X) else c₀)) + simpa only [alternatingProjection,Bool.false_eq_true,↓reduceIte,palindromePerm,mul_assoc] using + (Nat.cast_le.mpr hh : (alternatingCycles e _ : ℝ) ≤ _) + _ ≤ _ := relabeled_single_cycle_mean d _ _ _ + calc + _ ≤ finiteMean (fun _ : SwitchIndex d → Bool => + (sharedPairs e).card * DenseTruncation.h (d+1)) := finiteMean_mono hf + _ = _ := finiteMean_const _ + calc + _ ≤ finiteMean (fun _ : BenesCoins d => (sharedPairs e).card * DenseTruncation.h (d+1)) := + finiteMean_mono hone + _ = _ := finiteMean_const _ + +end PairRouting +end Thorp + +namespace Thorp + +lemma exp_secant {M x t : ℝ} (hM : 0 < M) (hx : 0 ≤ x) (hxM : x ≤ M) : + Real.exp (t*x) ≤ 1 + x*((Real.exp (t*M)-1)/M) := by + have hb : 0 ≤ x/M := div_nonneg hx hM.le + have ha : 0 ≤ 1-x/M := sub_nonneg.mpr ((div_le_one hM).mpr hxM) + have hh := convexOn_exp.2 (Set.mem_univ (0:ℝ)) (Set.mem_univ (t*M)) ha hb + (show (1-x/M)+(x/M)=1 by ring) + simp only [smul_eq_mul, mul_zero, zero_add, Real.exp_zero, mul_one] at hh + have he : x/M*(t*M) = t*x := by field_simp + rw [he] at hh + calc + _ ≤ 1-x/M+(x/M)*Real.exp (t*M) := hh + _ = _ := by ring + +lemma finiteMean_exp_bounded {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (Z : Ω → ℝ) (M t μ : ℝ) (hM : 0 < M) (ht : 0 ≤ t) + (hZ : ∀ ω, 0 ≤ Z ω ∧ Z ω ≤ M) (hmean : finiteMean Z ≤ μ) : + finiteMean (fun ω => Real.exp (t*Z ω)) ≤ + Real.exp (μ*((Real.exp (t*M)-1)/M)) := by + have hz : 0 ≤ (Real.exp (t*M)-1)/M := + div_nonneg (sub_nonneg.mpr (Real.one_le_exp_iff.mpr (mul_nonneg ht hM.le))) hM.le + calc + _ ≤ finiteMean (fun ω => 1 + Z ω*((Real.exp (t*M)-1)/M)) := + finiteMean_mono (fun ω => exp_secant hM (hZ ω).1 (hZ ω).2) + _ = 1 + finiteMean Z*((Real.exp (t*M)-1)/M) := by + rw [finiteMean_add,finiteMean_const,finiteMean_mul_const] + _ ≤ 1 + μ*((Real.exp (t*M)-1)/M) := by gcongr + _ ≤ _ := by simpa only [add_comm] using Real.add_one_le_exp (μ*((Real.exp (t*M)-1)/M)) + +namespace PairRouting +variable {ι : Type*} [Fintype ι] + +lemma node_cycle_mgf (d : ℕ) (e : ι ↪ Bool × Card d) (t : ℝ) (ht : 0 ≤ t) : + finiteMean (fun c : BenesCoins d × BenesCoins d => + Real.exp (t * alternatingCycles e + (fun b => palindromePerm d (if b then c.2 else c.1)))) ≤ + Real.exp ((sharedPairs e).card * DenseTruncation.h (d+1) * + ((Real.exp (t*(2:ℝ)^d)-1)/(2:ℝ)^d)) := by + apply finiteMean_exp_bounded _ _ _ _ (by positivity) ht _ (node_cycle_mean d e) + intro c + constructor + · exact Nat.cast_nonneg _ + · have h₀ := alternatingCycles_double e + (fun b => palindromePerm d (if b then c.2 else c.1)) + have h₁ := Fintype.card_le_of_injective e e.injective + simp only [Fintype.card_prod,Fintype.card_bool,card_positions] at h₁ + have h₂ : alternatingCycles e (fun b => palindromePerm d (if b then c.2 else c.1)) ≤ 2^d := by omega + exact_mod_cast h₂ + +end PairRouting + +open scoped BigOperators + +lemma shared_pair_mgf {β Ω : Type*} [Fintype β] [DecidableEq β] + [Fintype Ω] (F : Ω → Finset (Bool × β)) (p : Bool × β → ℝ) + (hp : ∀ x, 0 ≤ p x) (hc : CylinderBound (inclusionMoment F) p) + (z : ℝ) (hz : 0 ≤ z) : + finiteMean (fun ω => Real.exp (z * (boolFiber (F ω) false ∩ boolFiber (F ω) true).card)) ≤ + Real.exp ((Real.exp z - 1) * ∑ b, p (false,b)*p (true,b)) := by + classical + let T : β → Bool → Finset (Bool × β) := fun b q => + if q then {(false,b),(true,b)} else ∅ + let c : β → Bool → ℝ := fun _ q => if q then Real.exp z - 1 else 1 + have hcz : 0 ≤ Real.exp z - 1 := sub_nonneg.mpr (Real.one_le_exp_iff.mpr hz) + have hdis : ∀ b b', b ≠ b' → ∀ q q', Disjoint (T b q) (T b' q') := by + intro b b' h q q' + cases q <;> cases q' <;> simp [T,Finset.disjoint_left,h] + have hh := cylinder_block_polynomial (fun _ : β => Bool) F p hc T c + (fun b q => by cases q <;> simp only [c,↓reduceIte] <;> positivity) hdis + have hsum (A : Finset (Bool × β)) (b : β) : + (∑ q, c b q * if T b q ⊆ A then 1 else 0) = + Real.exp (z * if (false,b) ∈ A ∧ (true,b) ∈ A then 1 else 0) := by + simp only [Fintype.sum_bool,c,T,Bool.false_eq_true,↓reduceIte,Finset.empty_subset, + mul_one,Finset.insert_subset_iff,Finset.singleton_subset_iff] + split_ifs <;> simp + have hcard (A : Finset (Bool × β)) : + (∑ b : β, if (false,b) ∈ A ∧ (true,b) ∈ A then (1:ℝ) else 0) = + (boolFiber A false ∩ boolFiber A true).card := by + rw [Finset.sum_boole] + congr 2 + ext b + simp [mem_boolFiber] + have hleft (ω : Ω) : + (∏ b, ∑ q, c b q * if T b q ⊆ F ω then 1 else 0) = + Real.exp (z*(boolFiber (F ω) false ∩ boolFiber (F ω) true).card) := by + simp_rw [hsum] + rw [←Real.exp_sum,←Finset.mul_sum,hcard] + have hright (b : β) : + (∑ q, c b q * ∏ x ∈ T b q, p x) = + 1+(Real.exp z-1)*(p (false,b)*p (true,b)) := by + simp [c,T,add_comm] + simp_rw [hleft,hright] at hh + refine hh.trans ?_ + rw [Finset.mul_sum,Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact add_nonneg (by norm_num) (mul_nonneg hcz (mul_nonneg (hp _) (hp _))) + · intro b _ + simpa only [add_comm] using Real.add_one_le_exp ((Real.exp z-1)*(p (false,b)*p (true,b))) + +end Thorp + +namespace Thorp +variable {B : Type*} [Fintype B] [DecidableEq B] + +lemma prod_blockMarks (d : ℕ) (S : Finset (B × Card d)) (f : B × Card d → ℝ) : + (∏ x ∈ S, f x) = ∏ b, ∏ x ∈ blockMarks (Equiv.refl _) S b, f (b,x) := by + classical + have hb (b : B) : (∏ x ∈ blockMarks (Equiv.refl _) S b, f (b,x)) = + ∏ x, if (b,x) ∈ S then f (b,x) else 1 := by + exact Finset.prod_filter (fun x => (b,x) ∈ S) (fun x => f (b,x)) + simp_rw [hb] + rw [←Fintype.prod_prod_type (fun x : B × Card d => if x ∈ S then f x else 1)] + symm + calc + _ = ∏ x ∈ Finset.univ.filter (fun x : B × Card d => x ∈ S), f x := + (Finset.prod_filter _ _).symm + _ = _ := by simp + +omit [Fintype B] in +lemma subset_parallel_inverse (d : ℕ) (A S : Finset (B × Card d)) + (ω : B × SwitchIndex d → Bool) : + S ⊆ A.image (parallelPerm ω).symm ↔ + ∀ b, blockMarks (Equiv.refl _) S b ⊆ + inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) (fun i => ω (b,i)) := by + classical + constructor + · intro h b x hx + have hh := h ((mem_blockMarks (Equiv.refl _) S b x).mp hx) + rw [mem_image_perm_iff] at hh + rw [inverseButterflyMarks,mem_image_perm_iff] + exact (mem_blockMarks (Equiv.refl _) A b _).mpr hh + · intro h ⟨b,x⟩ hx + have hh := h b ((mem_blockMarks (Equiv.refl _) S b x).mpr hx) + rw [inverseButterflyMarks,mem_image_perm_iff] at hh + rw [mem_image_perm_iff] + exact (mem_blockMarks (Equiv.refl _) A b _).mp hh + +lemma parallel_inverse_cylinder (d : ℕ) (A : Finset (B × Card d)) : + CylinderBound (inclusionMoment (fun ω : B × SwitchIndex d → Bool => + A.image (parallelPerm ω).symm)) + (fun x => (blockMarks (Equiv.refl _) A x.1).card / (2:ℝ)^d) := by + classical + intro S + rw [inclusionMoment_eq,finiteMean_equiv (Equiv.curry B (SwitchIndex d) Bool)] + have hi (ω : B → SwitchIndex d → Bool) : + (if S ⊆ A.image (parallelPerm ((Equiv.curry B (SwitchIndex d) Bool).symm ω)).symm + then (1:ℝ) else 0) = + ∏ b, if blockMarks (Equiv.refl _) S b ⊆ inverseButterflyMarks d + (blockMarks (Equiv.refl _) A b) (ω b) then 1 else 0 := by + simp only [subset_parallel_inverse] + change (if ∀ b, blockMarks (Equiv.refl _) S b ⊆ inverseButterflyMarks d + (blockMarks (Equiv.refl _) A b) (ω b) then (1:ℝ) else 0) = _ + by_cases h : ∀ b, blockMarks (Equiv.refl _) S b ⊆ + inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) (ω b) + · simp [h] + · rw [ite_eq_right h] + obtain ⟨b,hb⟩ := not_forall.mp h + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + exact ite_eq_right hb + simp_rw [hi] + rw [finiteMean_pi_prod (fun b ω => if blockMarks (Equiv.refl _) S b ⊆ + inverseButterflyMarks d (blockMarks (Equiv.refl _) A b) ω then 1 else 0),prod_blockMarks] + apply Finset.prod_le_prod₀ + · intro b _ + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + · intro b _ + simpa only [←inclusionMoment_eq,Finset.prod_const] using + inverseButterflyMarks_inclusion d (blockMarks (Equiv.refl _) A b) + (blockMarks (Equiv.refl _) S b) + +end Thorp + +namespace Thorp +namespace PairRouting +variable {ι : Type*} [Fintype ι] + +lemma node_cycle_mean_one_fresh (d : ℕ) (e : ι ↪ Bool × Card d) + (c₀ : BenesCoins d) (X : SwitchIndex d → Bool) : + finiteMean (fun Y : SwitchIndex d → Bool => + (alternatingCycles e (fun b => palindromePerm d (if b then (Y,X) else c₀)) : ℝ)) ≤ + (sharedPairs e).card * DenseTruncation.h (d+1) := by + classical + calc + _ ≤ finiteMean (fun Y : SwitchIndex d → Bool => + (Fintype.card (RoutingNetwork.SelectedCycle + ((palindromePerm d c₀).symm * butterflyPerm d (decodeButterfly d Y) * + (butterflyPerm d (decodeButterfly d X)).symm) (sharedPairs e)) : ℝ)) := by + apply finiteMean_mono + intro Y + have hh := alternatingCycles_le_sharedSelected e + (fun b => palindromePerm d (if b then (Y,X) else c₀)) + simpa only [alternatingProjection,Bool.false_eq_true,↓reduceIte,palindromePerm,mul_assoc] using + (Nat.cast_le.mpr hh : (alternatingCycles e _ : ℝ) ≤ _) + _ ≤ _ := relabeled_single_cycle_mean d _ _ _ + +lemma node_cycle_mgf_fixed_input (d : ℕ) (e : ι ↪ Bool × Card d) + (X : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (t : ℝ) (ht : 0 ≤ t) : + finiteMean (fun Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + Real.exp (t * alternatingCycles e + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))))) ≤ + Real.exp ((sharedPairs e).card * DenseTruncation.h (d+1) * + ((Real.exp (t*(2:ℝ)^d)-1)/(2:ℝ)^d)) := by + apply finiteMean_exp_bounded _ _ _ _ (by positivity) ht + · intro Y + constructor + · exact Nat.cast_nonneg _ + · have h₀ := alternatingCycles_double e + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) + have h₁ := Fintype.card_le_of_injective e e.injective + simp only [Fintype.card_prod,Fintype.card_bool,card_positions] at h₁ + exact_mod_cast (show alternatingCycles e _ ≤ 2^d by omega) + · rw [finiteMean_prod] + calc + _ ≤ finiteMean (fun _ : SwitchIndex d → Bool => + (sharedPairs e).card * DenseTruncation.h (d+1)) := + finiteMean_mono (fun Y => node_cycle_mean_one_fresh d e (Y,X.1) X.2) + _ = _ := finiteMean_const _ + +end PairRouting + +noncomputable def sharedLevel (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, X => + let χ := coinStepEquiv d X + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + if t = d+1 then (PairRouting.sharedPairs x).card else + sharedLevel t d (PairRouting.childEmbedding x c hc false) χ.1.1 + + sharedLevel t d (PairRouting.childEmbedding x c hc true) χ.1.2 + +noncomputable def denseLevelCoefficient (j : ℕ) (t : ℝ) : ℝ := + DenseTruncation.h (j+1) * ((Real.exp (t*(2:ℝ)^j)-1)/(2:ℝ)^j) + +lemma denseLevelCoefficient_nonneg (j : ℕ) {t : ℝ} (ht : 0 ≤ t) : + 0 ≤ denseLevelCoefficient j t := by + apply mul_nonneg (DenseTruncation.h_nonneg _) + apply div_nonneg _ (by positivity) + exact sub_nonneg.mpr (Real.one_le_exp_iff.mpr (mul_nonneg ht (by positivity))) + +lemma palindrome_level_dense_conditional (j d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (t : ℝ) (ht : 0 ≤ t) : + finiteMean (fun Y : SwitchIndex d → Bool => + Real.exp (t * palindromeLevelCost (j+1) d e (Y,X))) ≤ + Real.exp (denseLevelCoefficient j t * sharedLevel (j+1) d e X) := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLevelCost,sharedLevel,Nat.cast_zero,mul_zero, + Real.exp_zero,finiteMean_const,le_refl] + | succ d ih => + let χ := coinStepEquiv d X + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + have hs (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : + palindromeLevelCost (j+1) (d+1) e ((coinStepEquiv d).symm (Y,η),X) = + if j+1 = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x χ.2) + (fun b => palindromePerm d (if b then (Y.2,χ.1.2) else (Y.1,χ.1.1))) else + palindromeLevelCost (j+1) d e₀ (Y.1,χ.1.1) + + palindromeLevelCost (j+1) d e₁ (Y.2,χ.1.2) := by + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step] + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + simp_rw [hs,finiteMean_const] + change _ ≤ Real.exp (denseLevelCoefficient j t * + (if j+1 = d+1 then (PairRouting.sharedPairs x).card else + sharedLevel (j+1) d e₀ χ.1.1 + sharedLevel (j+1) d e₁ χ.1.2)) + by_cases hj : j = d + · subst j + simp only [ite_true] + have hh := PairRouting.node_cycle_mgf_fixed_input d + (PairRouting.switchedEmbedding x χ.2) χ.1 t ht + rw [PairRouting.sharedPairs_switched] at hh + simpa only [denseLevelCoefficient,mul_left_comm,mul_assoc,mul_comm] using hh + · have hne : j+1 ≠ d+1 := by omega + simp only [ite_eq_right hne,Nat.cast_add,mul_add,Real.exp_add] + rw [finiteMean_prod_mul + (fun Y : SwitchIndex d → Bool => Real.exp (t * palindromeLevelCost (j+1) d e₀ (Y,χ.1.1))) + (fun Y : SwitchIndex d → Bool => Real.exp (t * palindromeLevelCost (j+1) d e₁ (Y,χ.1.2)))] + exact mul_le_mul (ih e₀ χ.1.1) (ih e₁ χ.1.2) + (finiteMean_nonneg (fun _ => (Real.exp_pos _).le)) (Real.exp_pos _).le + + +def pairCoords (r s : ℕ) : Card ((s+1)+r) ≃ Bool × (Card r × Card s) := + (cardSplit r (s+1)).trans + { toFun := fun x => ((x.2) 0,(x.1,Fin.tail x.2)) + invFun := fun x => (x.2.1,Fin.cons x.1 x.2.2) + left_inv := by intro x; simp only [Fin.cons_self_tail] + right_inv := by intro x; simp only [Fin.cons_zero,Fin.tail_cons] } + +noncomputable def gridPairs (r s : ℕ) (A : Finset (Card ((s+1)+r))) : Finset (Card r × Card s) := + Finset.univ.filter (fun x => (pairCoords r s).symm (false,x) ∈ A ∧ + (pairCoords r s).symm (true,x) ∈ A) + +noncomputable def gridShared (r s : ℕ) (A : Finset (Card ((s+1)+r))) : ℕ := + (gridPairs r s A).card + +lemma gridPairs_eq (r s : ℕ) (A : Finset (Card ((s+1)+r))) : + gridPairs r s A = boolFiber (A.image (pairCoords r s)) false ∩ + boolFiber (A.image (pairCoords r s)) true := by + classical + ext x + have hm (b : Bool) : (b,x) ∈ A.image (pairCoords r s) ↔ + (pairCoords r s).symm (b,x) ∈ A := by + constructor + · rintro h + obtain ⟨a,ha,he⟩ := Finset.mem_image.mp h + rw [←he,Equiv.symm_apply_apply] + exact ha + · intro h + exact Finset.mem_image.mpr ⟨_,h,(pairCoords r s).apply_symm_apply _⟩ + simp only [gridPairs,Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_inter, + mem_boolFiber,hm] + +lemma gridShared_zero (s : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+1)) : + gridShared 0 s (Finset.univ.image e) = + (PairRouting.sharedPairs (e.trans (headTailEquiv s).toEmbedding)).card := by + classical + let z : Card 0 := fun i => Fin.elim0 i + have he : gridPairs 0 s (Finset.univ.image e) = + (PairRouting.sharedPairs (e.trans (headTailEquiv s).toEmbedding)).image (fun y => (z,y)) := by + ext ⟨b,y⟩ + have hb : b = z := Subsingleton.elim _ _ + subst b + simp only [gridPairs,Finset.mem_filter,Finset.mem_univ,true_and, + PairRouting.sharedPairs,Finset.mem_inter,mem_boolFiber,PairRouting.labelSet, + Finset.mem_image,Prod.mk.injEq,true_and] + change ((∃ i, e i = Fin.cons false y) ∧ ∃ i, e i = Fin.cons true y) ↔ _ + simp only [Function.Embedding.trans_apply,Equiv.toEmbedding_apply, + headTailEquiv] + constructor + · rintro ⟨⟨i,hi⟩,⟨i',hi'⟩⟩ + refine ⟨y,⟨?_,?_⟩,rfl⟩ + · exact ⟨i,by change (e i 0,Fin.tail (e i)) = (false,y); rw [hi]; rfl⟩ + · exact ⟨i',by change (e i' 0,Fin.tail (e i')) = (true,y); rw [hi']; rfl⟩ + · rintro ⟨y',⟨⟨i,hi⟩,⟨i',hi'⟩⟩,rfl⟩ + constructor + · exact ⟨i,(headTailEquiv s).injective hi⟩ + · exact ⟨i',(headTailEquiv s).injective hi'⟩ + rw [gridShared,he,Finset.card_image_of_injective] + intro y y' h + exact congrArg Prod.snd h + +lemma gridShared_step (r s : ℕ) (A : Finset (Card ((s+1)+(r+1)))) : + gridShared (r+1) s A = gridShared r s (childMarks A false) + + gridShared r s (childMarks A true) := by + classical + have hsum (r : ℕ) (A : Finset (Card ((s+1)+r))) : gridShared r s A = + ∑ b : Card r, ∑ y : Card s, + if (pairCoords r s).symm (false,(b,y)) ∈ A ∧ + (pairCoords r s).symm (true,(b,y)) ∈ A then (1:ℕ) else 0 := by + rw [gridShared,gridPairs,Finset.card_filter,Fintype.sum_prod_type] + rw [hsum,hsum,hsum,←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + have hc (b : Bool) (x : Card r) (y : Card s) (ε : Bool) : + (pairCoords (r+1) s).symm (ε,((headTailEquiv r).symm (b,x),y)) = + Fin.cons b ((pairCoords r s).symm (ε,(x,y))) := rfl + simp only [hc,mem_childMarks] + exact add_comm _ _ + +lemma butterfly_false (d : ℕ) : + butterflyPerm d (decodeButterfly d (fun _ => false)) = 1 := by + induction d with + | zero => exact Subsingleton.elim _ _ + | succ d ih => + have he : (fun _ : SwitchIndex (d+1) => false) = (coinStepEquiv d).symm + (((fun _ => false),(fun _ => false)),fun _ => false) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + rw [he,butterflyPerm_step] + ext x i + simp [ih,Equiv.Perm.mul_apply,childLift] + change Fin.cons (Bool.xor (x 0) false) (Fin.tail x) i = x i + simp + +lemma inverseButterflyMarks_false (d : ℕ) (A : Finset (Card d)) : + inverseButterflyMarks d A (fun _ => false) = A := by + rw [inverseButterflyMarks,butterfly_false] + change Finset.image id A = A + exact Finset.image_id + + +lemma sharedLevel_partial_marks (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card ((s+1)+r)) + (lo : Card r × SwitchIndex (s+1) → Bool) + (hi : Card (s+1) × SwitchIndex r → Bool) : + sharedLevel (s+1) ((s+1)+r) e (assembleBits r (s+1) lo hi) = + gridShared r s (inverseButterflyMarks ((s+1)+r) (Finset.univ.image e) + (assembleBits r (s+1) (fun _ => false) hi)) := by + classical + induction r generalizing ι with + | zero => + rw [show assembleBits 0 (s+1) (fun _ => false) hi = (fun _ => false) from rfl, + inverseButterflyMarks_false,gridShared_zero] + simp only [sharedLevel,ite_true] + | succ r ih => + obtain ⟨c,rfl⟩ := (highStepEquiv r (s+1)).symm.surjective hi + simp only [Nat.add_succ] at * + rw [assembleBits_step,sharedLevel] + simp only [Equiv.apply_symm_apply] + rw [ite_eq_right (by omega : s+1 ≠ s+1+r+1)] + rw [ih,ih,assembleBits_step,gridShared_step, + inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + +lemma partial_input_parallel (r s : ℕ) (hi : Card s × SwitchIndex r → Bool) + (x : Card (s+r)) : + ((cardSplit r s).trans (Equiv.prodComm _ _)) + ((butterflyPerm (s+r) (decodeButterfly (s+r) + (assembleBits r s (fun _ => false) hi))).symm x) = + (parallelPerm hi).symm (((cardSplit r s).trans (Equiv.prodComm _ _)) x) := by + let y := (butterflyPerm (s+r) (decodeButterfly (s+r) + (assembleBits r s (fun _ => false) hi))).symm x + have hh := butterfly_split r s (fun _ => false) hi y + dsimp only [y] at hh + simp only [butterfly_false,Equiv.Perm.one_apply,Equiv.apply_symm_apply] at hh + change cardSplit r s x = + (butterflyPerm r (decodeButterfly r (fun i => hi ((cardSplit r s y).2,i))) + (cardSplit r s y).1,(cardSplit r s y).2) at hh + have hs := congrArg Prod.snd hh + have hf := congrArg Prod.fst hh + dsimp only at hs hf + change ((cardSplit r s y).2,(cardSplit r s y).1) = + ((cardSplit r s x).2,(butterflyPerm r + (decodeButterfly r (fun i => hi ((cardSplit r s x).2,i)))).symm (cardSplit r s x).1) + rw [hs,hf,Equiv.symm_apply_apply] + +lemma partial_marks_parallel (r s : ℕ) (A : Finset (Card (s+r))) + (hi : Card s × SwitchIndex r → Bool) : + (inverseButterflyMarks (s+r) A (assembleBits r s (fun _ => false) hi)).image + ((cardSplit r s).trans (Equiv.prodComm _ _)) = + (A.image ((cardSplit r s).trans (Equiv.prodComm _ _))).image (parallelPerm hi).symm := by + classical + simp only [inverseButterflyMarks,Finset.image_image] + congr 1 + funext x + exact partial_input_parallel r s hi x + +lemma cylinder_image_equiv_bound {α β Ω : Type*} [DecidableEq α] [DecidableEq β] + [Fintype Ω] (e : α ≃ β) (F : Ω → Finset α) (p : α → ℝ) + (h : CylinderBound (inclusionMoment F) p) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) (fun x => p (e.symm x)) := by + intro S + rw [inclusionMoment_image_equiv] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + + +noncomputable def suffixMarks (r s : ℕ) (A : Finset (Card (s+r))) (y : Card s) : Finset (Card r) := + blockMarks ((cardSplit r s).trans (Equiv.prodComm _ _)) A y + +noncomputable def sharedPartnerMean (r s : ℕ) (A : Finset (Card ((s+1)+r))) : ℝ := + (∑ y : Card s, ((suffixMarks r (s+1) A (Fin.cons false y)).card : ℝ) * + (suffixMarks r (s+1) A (Fin.cons true y)).card) / (2:ℝ)^r + +lemma blockMarks_image_equiv {α B : Type*} [Fintype α] [DecidableEq α] + [Fintype B] [DecidableEq B] (r : ℕ) (E : α ≃ B × Card r) + (A : Finset α) (b : B) : + blockMarks (Equiv.refl _) (A.image E) b = blockMarks E A b := by + classical + ext y + simp only [mem_blockMarks,Equiv.refl_symm,Equiv.refl_apply,Finset.mem_image] + constructor + · rintro ⟨x,hx,he⟩ + rw [←he,Equiv.symm_apply_apply] + exact hx + · intro h + exact ⟨_,h,E.apply_symm_apply _⟩ + +def pairReorder (r s : ℕ) : Card (s+1) × Card r ≃ Bool × (Card r × Card s) where + toFun x := (x.1 0,(x.2,Fin.tail x.1)) + invFun x := (Fin.cons x.1 x.2.2,x.2.1) + left_inv x := by simp only [Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero,Fin.tail_cons] + +lemma pairCoords_reorder (r s : ℕ) : + pairCoords r s = ((cardSplit r (s+1)).trans (Equiv.prodComm _ _)).trans (pairReorder r s) := rfl + +lemma partial_grid_mgf (r s : ℕ) (A : Finset (Card ((s+1)+r))) + (z : ℝ) (hz : 0 ≤ z) : + finiteMean (fun hi : Card (s+1) × SwitchIndex r → Bool => + Real.exp (z * gridShared r s (inverseButterflyMarks ((s+1)+r) A + (assembleBits r (s+1) (fun _ => false) hi)))) ≤ + Real.exp ((Real.exp z-1)*sharedPartnerMean r s A) := by + classical + let E := (cardSplit r (s+1)).trans (Equiv.prodComm _ _) + let F (hi : Card (s+1) × SwitchIndex r → Bool) := (A.image E).image (parallelPerm hi).symm + let p (x : Card (s+1) × Card r) : ℝ := + (suffixMarks r (s+1) A x.1).card / (2:ℝ)^r + have hc : CylinderBound (inclusionMoment F) p := by + have hh := parallel_inverse_cylinder r (A.image E) + simp only [blockMarks_image_equiv] at hh + exact hh + have hp : ∀ x, 0 ≤ p x := by intro x; exact div_nonneg (Nat.cast_nonneg _) (by positivity) + have hh := shared_pair_mgf (fun hi => (F hi).image (pairReorder r s)) + (fun x => p ((pairReorder r s).symm x)) (fun x => hp _) + (cylinder_image_equiv_bound (pairReorder r s) F p hc) z hz + have he (hi : Card (s+1) × SwitchIndex r → Bool) : + (F hi).image (pairReorder r s) = + (inverseButterflyMarks ((s+1)+r) A + (assembleBits r (s+1) (fun _ => false) hi)).image (pairCoords r s) := by + rw [pairCoords_reorder] + change (F hi).image (pairReorder r s) = + (inverseButterflyMarks ((s+1)+r) A + (assembleBits r (s+1) (fun _ => false) hi)).image ((pairReorder r s) ∘ E) + rw [←Finset.image_image,partial_marks_parallel] + have hm : (∑ b : Card r × Card s, + p ((pairReorder r s).symm (false,b))*p ((pairReorder r s).symm (true,b))) = + sharedPartnerMean r s A := by + simp only [p,pairReorder,Equiv.coe_fn_symm_mk,Fintype.sum_prod_type] + rw [Finset.sum_const,Finset.card_univ,card_positions,nsmul_eq_mul] + simp only [sharedPartnerMean, div_mul_div_comm, ←Finset.sum_div] + rw [show (↑(2^r) : ℝ) = (2:ℝ)^r by rfl] + have hpow : (2:ℝ)^r ≠ 0 := by positivity + generalize (∑ y : Card s, (suffixMarks r (s+1) A (Fin.cons false y)).card * + (suffixMarks r (s+1) A (Fin.cons true y)).card : ℝ) = v + field_simp + ; push_cast + ; ring + simp_rw [he,←gridPairs_eq] at hh + rw [hm] at hh + exact hh + +end Thorp + +end ThorpNine.Dense + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.lean index cd62ec1fe9f9e2de549d51a8fed06e163d16f06f..d1f0fbd30cae82bb5c1c7d73b07cd66771cc281a 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/AlternatingPerm.lean @@ -1,857 +1,857 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.ParallelFollow - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -end PairRouting -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.ParallelFollow + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +end PairRouting +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/AssignmentSlots.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/AssignmentSlots.lean index b4027d64e362965fb2ca104c077ac0c3d26009e0..4ef7ae5c8b22e70018fcdc018c3267c985d7cba7 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/AssignmentSlots.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/AssignmentSlots.lean @@ -1,834 +1,834 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.RotationMeeting - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -section CycleCounting -variable {d A : ℕ} - -lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {d A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr - -end GroupedCounting - -section AllLengths -variable {d A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) - (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) - (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : - finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by - have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by - rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] - exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm - have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), - ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by - calc - _ = ((q-1)+1)^(F ω) := by congr 1; ring - _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by - rw [add_pow] - simp only [one_pow,mul_one] - _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by - apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) - intro a _ ha - have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega - rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] - _ = _ := by - apply Finset.sum_congr rfl - intro a _ - rw [hc] - ring - simp_rw [hex,finiteMean_sum,finiteMean_mul_const] - calc - _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_right (hm a) (by positivity) - _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by - apply Finset.sum_congr rfl - intro a _ - rw [mul_pow] - ring - _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ - -lemma inv_sqrt_step (j : ℕ) : - 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by - have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) - apply (div_le_iff₀ hp).mpr - have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) - have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) - nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] - -lemma sum_inv_sqrt (J : ℕ) : - (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by - have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ] - have hs := inv_sqrt_step n - push_cast - linarith - rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] - exact h J -section CycleMGF -variable {d : ℕ} - -lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment S J - -end CycleMGF - -section FullCycleMGF -variable {d : ℕ} - -abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by - apply div_pos - · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty - · exact Nat.cast_pos.mpr Fintype.card_pos - -lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - -end FullCycleMGF - -structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] - [Fintype ι] [DecidableEq ι] (d : ℕ) where - perm : (ι → Bool) → Equiv.Perm α - path : (ι → Bool) → α → Finset ι - users : (ι → Bool) → ι → α × α - users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 - mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x - card_path : ∀ ω x, (path ω x).card = d - entropy : ∀ ω (S : Finset α), - (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) - follow : α → (α → QueryTree ι) → QueryTree ι - close : α → α → QueryTree ι → QueryTree ι - follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω - follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω - follow_stale_charge : ∀ x k R ω, - (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω - close_succeeds : ∀ x y k ω, - (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false - close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d - close_stale_charge : ∀ x y k R ω, perm ω x = y → - (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card - -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma card_switches_using (ω : ι → Bool) (x : α) : - (Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by - ext i - simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] - rw [he,R.card_path] -lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = - (d : ℝ) * ∑ x : α, w x := by - classical - calc - _ = ∑ i : ι, ∑ x : α, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : α => - (R.users b i).1 = x ∨ (R.users b i).2 = x) = - {(R.users b i).1, (R.users b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (R.users_ne b i)] - _ = ∑ x : α, ∑ i : ι, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : α, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ - (d : ℝ) / 2 * ∑ x : α, w x := by - have h : 2 * (∑ i : ι, - min (w (R.users b i).1) (w (R.users b i).2)) ≤ - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), - min_le_right (w (R.users b i).1) (w (R.users b i).2)] - rw [switch_incidence_sum] at h - linarith -section Rotation -variable {A : ℕ} - -def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -omit [DecidableEq α] in -@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} - -noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) - (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -omit [DecidableEq α] in -lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : - Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (i : Fin A) (x : α) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -omit [DecidableEq α] in -lemma slotWeight_antitone (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -omit [DecidableEq α] in -lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : α, pathWeight o x = (A : ℝ) := by - classical - have he (x : α) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : - (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : α) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := R.entropy b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) - (z : Terminal o) : ℝ := - ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 - -lemma rotationCharge_mean_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound R b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound R o hn b - linarith - -lemma rotation_exp_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have hb := rotationCharge_mean_bound R hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -namespace QueryTree -open Thorp.QueryTree - -noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : - ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → - QueryTree (ι) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x - (fun y => seekCycle R S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) - (ω : ι → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle R S a r x V k).succeeds ω = true) : - (seekCycle R S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs - rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - -noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : - List (α × ℕ) → Finset (α) → QueryTree (ι) - | [], _ => accept - | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) - -lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) - (V : Finset (α)) (ω : ι → Bool) - (hs : (seekCycles R S L V).succeeds ω = true) : - (seekCycles R S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : - finiteMean (fun ω : ι → Bool => - if (seekCycles R S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles R S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge R S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree -noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : - Finset (ι) := - V.biUnion (fun x => R.path b x) - -@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : - exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := - (R.path b z ∩ exposedPaths R b V).card - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V W : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : - (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (S V : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (hS : orbitSet (R.perm ω) z ⊆ S) - (hV : Disjoint V (orbitSet (R.perm ω) z)) : - let p := R.perm ω - let W := V ∪ orbitSet p z - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -end RoutingNetwork -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.RotationMeeting + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +section CycleCounting +variable {d A : ℕ} + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {d A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr + +end GroupedCounting + +section AllLengths +variable {d A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) + (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) + (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : + finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by + have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by + rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] + exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm + have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), + ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by + calc + _ = ((q-1)+1)^(F ω) := by congr 1; ring + _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by + rw [add_pow] + simp only [one_pow,mul_one] + _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by + apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) + intro a _ ha + have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega + rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [hc] + ring + simp_rw [hex,finiteMean_sum,finiteMean_mul_const] + calc + _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_right (hm a) (by positivity) + _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by + apply Finset.sum_congr rfl + intro a _ + rw [mul_pow] + ring + _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ + +lemma inv_sqrt_step (j : ℕ) : + 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by + have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) + apply (div_le_iff₀ hp).mpr + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) + have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) + nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] + +lemma sum_inv_sqrt (J : ℕ) : + (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by + have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ] + have hs := inv_sqrt_step n + push_cast + linarith + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] + exact h J +section CycleMGF +variable {d : ℕ} + +lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment S J + +end CycleMGF + +section FullCycleMGF +variable {d : ℕ} + +abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by + apply div_pos + · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty + · exact Nat.cast_pos.mpr Fintype.card_pos + +lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + +end FullCycleMGF + +structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] + [Fintype ι] [DecidableEq ι] (d : ℕ) where + perm : (ι → Bool) → Equiv.Perm α + path : (ι → Bool) → α → Finset ι + users : (ι → Bool) → ι → α × α + users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 + mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x + card_path : ∀ ω x, (path ω x).card = d + entropy : ∀ ω (S : Finset α), + (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) + follow : α → (α → QueryTree ι) → QueryTree ι + close : α → α → QueryTree ι → QueryTree ι + follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω + follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω + follow_stale_charge : ∀ x k R ω, + (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω + close_succeeds : ∀ x y k ω, + (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false + close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d + close_stale_charge : ∀ x y k R ω, perm ω x = y → + (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card + +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma card_switches_using (ω : ι → Bool) (x : α) : + (Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by + ext i + simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] + rw [he,R.card_path] +lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = + (d : ℝ) * ∑ x : α, w x := by + classical + calc + _ = ∑ i : ι, ∑ x : α, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : α => + (R.users b i).1 = x ∨ (R.users b i).2 = x) = + {(R.users b i).1, (R.users b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (R.users_ne b i)] + _ = ∑ x : α, ∑ i : ι, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : α, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ + (d : ℝ) / 2 * ∑ x : α, w x := by + have h : 2 * (∑ i : ι, + min (w (R.users b i).1) (w (R.users b i).2)) ≤ + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), + min_le_right (w (R.users b i).1) (w (R.users b i).2)] + rw [switch_incidence_sum] at h + linarith +section Rotation +variable {A : ℕ} + +def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +omit [DecidableEq α] in +@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} + +noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) + (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +omit [DecidableEq α] in +lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : + Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (i : Fin A) (x : α) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +omit [DecidableEq α] in +lemma slotWeight_antitone (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +omit [DecidableEq α] in +lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : α, pathWeight o x = (A : ℝ) := by + classical + have he (x : α) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : + (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : α) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := R.entropy b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) + (z : Terminal o) : ℝ := + ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 + +lemma rotationCharge_mean_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound R b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound R o hn b + linarith + +lemma rotation_exp_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have hb := rotationCharge_mean_bound R hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +namespace QueryTree +open Thorp.QueryTree + +noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : + ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → + QueryTree (ι) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x + (fun y => seekCycle R S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) + (ω : ι → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle R S a r x V k).succeeds ω = true) : + (seekCycle R S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs + rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + +noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : + List (α × ℕ) → Finset (α) → QueryTree (ι) + | [], _ => accept + | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) + +lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) + (V : Finset (α)) (ω : ι → Bool) + (hs : (seekCycles R S L V).succeeds ω = true) : + (seekCycles R S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : + finiteMean (fun ω : ι → Bool => + if (seekCycles R S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles R S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge R S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree +noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : + Finset (ι) := + V.biUnion (fun x => R.path b x) + +@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : + exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := + (R.path b z ∩ exposedPaths R b V).card + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V W : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : + (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (S V : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (hS : orbitSet (R.perm ω) z ⊆ S) + (hV : Disjoint V (orbitSet (R.perm ω) z)) : + let p := R.perm ω + let W := V ∪ orbitSet p z + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +end RoutingNetwork +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/AverageMap.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/AverageMap.lean index 438753c4b4c3509f361cd2ea981781acef426f4b..2ec82cbd4239a7bbb61c1e4476a2ae95f52bc927 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/AverageMap.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/AverageMap.lean @@ -1,883 +1,883 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.Shapes - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where - toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) - isIntertwining' h := by - ext v - simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] - have hh (w : W) : σ h (σ h⁻¹ w)=w := by - change (σ h*σ h⁻¹) w=w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [hh] - -omit [FiniteDimensional ℂ V] in -lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : - LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = - (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by - change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ - rw [map_sum] - have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by - rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] - simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - -lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (A : Module.End ℂ V) : - ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ - c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by - obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) - have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by - rw [←hc] - rfl - refine ⟨c,he,?_⟩ - rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] - -theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (u v w z : V) : - (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = - (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by - obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap - rw [InnerProductSpace.trace_rankOne] at htrace - have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc - change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ - simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ - have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by - simpa only [mul_comm] using happ - rw [hsum] - calc - _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring - _ = _ := by rw [htrace] - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X : Type*} [Group G] [Fintype G] [Fintype X] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) - -noncomputable def representative (x : X) : G := Classical.choose (ha x) - -omit [Fintype G] [Fintype X] in -lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := - Classical.choose_spec (ha x) - -include ha in -lemma orbit_sum (F : X → ℂ) : - (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by - have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by - obtain ⟨t,rfl⟩ := ha x - symm - apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) - intro g - simp - calc - _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm - _ = ∑ g : G, ∑ x : X, F x := by - apply Finset.sum_congr rfl - intro g _ - exact Equiv.sum_comp (a g) F - _ = _ := by simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) - -def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w - -noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : - coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by - let r := representative a x₀ ha (a g x₀) - have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ - have hs : a (g⁻¹*r) x₀=x₀ := by - simp only [map_mul,Equiv.Perm.mul_apply] - rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] - rfl - have he := congrArg (ρ g) (hw (g⁻¹*r) hs) - have hh : ρ r w=ρ g w := by - simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, - mul_inv_cancel_left] using he - change inner ℂ (ρ r w) v= _ - rw [hh] - -lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = - (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by - have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) - simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs - simp only [←starRingEnd_apply,inner_conj_symm] at hs - simp only [starRingEnd_apply] at hs - have ho := coefficient_orthogonality ρ hρ v w z t - have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - apply mul_left_cancel₀ hcard - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,starRingEnd_apply] - have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = - ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by - apply Finset.sum_congr rfl - intro x _ - ring - rw [hsum] - calc - _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, - star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring - _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, - inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring - _ = _ := by rw [ho]; ring - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) - (v : V) (g : G) (x : X) : - coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by - obtain ⟨r,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, - coefficient_at a x₀ ha ρ w hw] - simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] - -noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := - (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v - -lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = - inner ℂ z w*inner ℂ v t := by - let : Nonempty X := ⟨x₀⟩ - have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = - (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by - rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] - simp - simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] - simp only [Complex.conj_ofReal] - rw [←mul_assoc,←pow_two,hs] - have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t - field_simp - simpa only [mul_assoc] using hi - -lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) - (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : - Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by - rw [orthonormal_iff_ite] at hw ⊢ - intro i j - rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, - inner_self_eq_norm_sq_to_K,hv] - simp [eq_comm] - -lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : - ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by - have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v - rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he - simp only [inner_self_eq_norm_sq_to_K] at he - norm_num at he - have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he - nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteConvolution -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) -noncomputable def power (p : G → ℝ) : ℕ → G → ℝ - | 0 => fun g => if g=1 then 1 else 0 - | n+1 => conv p (power p n) - -lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : - ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) - -lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) - {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by - apply lt_of_lt_of_le (mul_pos ha hb) - have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) - (Finset.mem_univ a) - simpa [conv] using h - -lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by - unfold conv - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [←Finset.mul_sum] - congr 1 - exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) - -lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by - intro n - induction n with - | zero => intro g; simp only [power]; split_ifs <;> norm_num - | succ n ih => exact conv_nonneg hp ih - -lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by - intro n - induction n with - | zero => simp [power] - | succ n ih => rw [power,sum_conv,hp,ih,one_mul] - -lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) - (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by - induction l with - | nil => simp [power] - | cons a l ih => - simpa only [List.length_cons,List.prod_cons,power] using - conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) - (ih (fun g hg => hl g (by simp [hg]))) - -lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by - induction m, hnm using Nat.le_induction with - | base => exact hg - | succ m _ ih => - simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih - -theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - (hgen : Subgroup.closure {g | 0 < p g}=⊤) : - ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by - have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by - rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] - trivial - choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) - let n := Finset.univ.sup (fun g => (l g).length) - refine ⟨n,fun g => ?_⟩ - have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) - have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) - have hpos := power_list_pos hp (l g) (hl g) - rw [hprod g] at hpos - exact power_pos_mono hp h1 (hlen.trans hpow) hpos - -structure Minorant (p : G → ℝ) where - exponent : ℕ - mass : ℝ - mass_pos : 0 < mass - mass_le_one : mass ≤ 1 - lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g - -noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) - (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by - let n := Classical.choose (exists_positive_power hp h1 hgen) - have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) - let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) - have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) - have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) - have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos - have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' - refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ - have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp - rw [he] - exact hag g - -end Thorp.FiniteConvolution -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : - continuousRepresentation ρ g v=ρ g v := rfl - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : - ‖ρ g v‖=‖v‖ := by - rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] - -omit [Fintype G] in -lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - ‖continuousRepresentation ρ g‖≤1 := by - apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one - intro v - simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] - -omit [Fintype G] in -lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by - ext w - apply ext_inner_left ℂ - intro v - rw [ContinuousLinearMap.adjoint_inner_right] - exact (unitary_inner_inv ρ hρ g v w).symm - -noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := - ∑ g, (p g : ℂ) • continuousRepresentation ρ g - -lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro g _ - rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] - exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) - -lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by - change (weightedOperator ρ p).adjoint=weightedOperator ρ p - unfold weightedOperator - rw [map_sum] - simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] - apply Fintype.sum_equiv (Equiv.inv G) - intro g - simp [hp] - -noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := - weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) - -lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) - -lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : - continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,←map_mul] - exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) - -lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : - uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,←map_mul] - exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) - -lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : - IsIdempotentElem (uniformOperator ρ) := by - change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ - nth_rw 1 [uniformOperator,weightedOperator] - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, - ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] - rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsStarProjection (uniformOperator ρ) := - ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ - -lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : - weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : - uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) - (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : - ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by - let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) - have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) - have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hsum : ∑ g,q g=1-ε := by - simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by - simp only [uniformOperator,weightedOperator] - rw [Finset.smul_sum,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro g _ - simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, - Complex.ofReal_inv,Complex.ofReal_natCast] - congr 1 - field_simp - ring - have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by - rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] - rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] - calc - _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ - _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) - ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) - (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) - _ = _ := mul_one _ - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : - weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by - unfold weightedOperator FiniteConvolution.conv - simp only [Complex.ofReal_sum,Finset.sum_smul] - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [Finset.mul_sum] - simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp [Complex.ofReal_mul,mul_comm] - -lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : - weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by - induction n with - | zero => simp [FiniteConvolution.power,weightedOperator] - | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] - -lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) - (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : - (weightedOperator ρ p-uniformOperator ρ)^n= - (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by - have hAP := weighted_uniform_left ρ p - have hPA := weighted_uniform_right ρ p - rw [hp,one_smul] at hAP hPA - have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by - show _*_= _*_ - rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] - have he : weightedOperator ρ p-uniformOperator ρ= - weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] - rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] - -noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := - 1-c.mass/(2*(2:ℝ)^c.exponent) - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - unfold minorantGap - linarith - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by - unfold minorantGap - exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) - -theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) - (c : FiniteConvolution.Minorant p) : - ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by - have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) - have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) - (FiniteConvolution.sum_power hp _) c.mass c.lower - rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), - hself.norm_pow_two_pow] at hbound - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - have hbern := one_add_mul_le_pow - (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) - (2^c.exponent) - have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by - push_cast - field_simp - ring - rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern - by_contra h - have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h - have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) - linarith [c.mass_pos] - -end Thorp.UnitaryFinite -namespace Thorp -open scoped BigOperators Classical - -def butterflyIdentity : (d : ℕ) → Butterfly d - | 0 => () - | d+1 => (fun _ => false,fun _ => butterflyIdentity d) - -lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by - apply Equiv.ext - intro x - change switchFun (fun _ => false) x=x - simp [switchFun] - -lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by - ext x i - simp [childLift] - -lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by - induction d with - | zero => rfl - | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] - -noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where - toFun p := childLift (fun c => if c=b then p else 1) - map_one' := by simpa only [ite_self] using childLift_one d - map_mul' p q := by - rw [childLift_mul] - congr 1 - funext c - split_ifs <;> simp - -lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : - childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ - by_cases hc : c=b - · subst c - simp only [↓reduceIte] - rw [Equiv.swap_apply_def] - split_ifs with h₁ h₂ - · subst w; simp - · subst w; simp - · rw [Equiv.swap_apply_of_ne_of_ne] - · exact fun h => h₁ (by simpa using congrArg Fin.tail h) - · exact fun h => h₂ (by simpa using congrArg Fin.tail h) - · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - -lemma pairSwitch_single (d : ℕ) (u : Card d) : - pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ - by_cases h : w=u - · subst w - cases c <;> simp [switchFun] - · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) - have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) - simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] - -theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) - (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by - induction d with - | zero => - apply top_unique - intro p _ - have hp : p=1 := Subsingleton.elim _ _ - rw [hp] - exact H.one_mem - | succ d ih => - have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by - have hc : H.comap (childInjection d b)=⊤ := by - apply ih - intro ω - change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H - have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) - simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h - have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial - exact hp - have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by - rw [←pairSwitch_single] - have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) - simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h - have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by - have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by - cases a <;> cases b - · rw [Equiv.swap_self]; exact H.one_mem - · exact hpair _ - · rw [Equiv.swap_comm]; exact hpair _ - · rw [Equiv.swap_self]; exact H.one_mem - have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by - convert ht (x 0) (y 0) (Fin.tail x) using 1 - rw [Fin.cons_self_tail] - have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) - rw [childInjection_swap,Fin.cons_self_tail] at h₂ - exact SubmonoidClass.swap_mem_trans H h₁ h₂ - rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] - rintro _ ⟨x,y,_,rfl⟩ - exact hswap x y - -lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := - butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) - -variable {Ω G : Type*} [Fintype Ω] [Fintype G] - -noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := - finiteMean (fun ω => if P ω=g then 1 else 0) - -omit [Fintype G] in -lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := - finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) - -lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by - unfold sampleLaw - rw [←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype G] in -lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : - 0 by split_ifs <;> norm_num)] - simp only [Finset.mem_univ,true_and] - apply exists_congr - intro ω - split_ifs <;> simp_all - -omit [Fintype G] in -lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : - sampleLaw (P ∘ e)=sampleLaw P := by - funext g - simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) - -variable [Group G] -omit [Fintype G] in -lemma sampleLaw_inverse (P : Ω → G) (g : G) : - sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by - apply finiteMean_congr - intro ω - rw [inv_eq_iff_eq_inv] - -omit [Fintype G] in -lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) - (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by - rw [←sampleLaw_inverse] - have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) - rw [hh,sampleLaw_equiv] - -end Thorp - -namespace Thorp -open scoped BigOperators Classical - -lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by - refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), - (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - exact mul_inv_cancel _ - -lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : - ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by - refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - unfold palindromePerm - have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := - (butterflyCoinEquiv d).apply_symm_apply β - rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] - -lemma palindrome_support_generates (d : ℕ) : - Subgroup.closure {g | 0 P i v) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) - rw [hsplit] at hp - have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) - rw [hsplit] at ha - have he (i : ι) : P i (A v)=(A*P i) (P i v) := by - change (P i*A) v=(A*P i*P i) v - rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] - have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by - rw [he] - exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) - have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) - simp_rw [mul_pow] at hsq - rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq - exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq - -theorem sector_sandwich_le (T P A B : V →L[ℂ] V) - (hT : IsStarProjection T) (hP : IsStarProjection P) - (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : - ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by - have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by - change _=star (T*B)*A*(T*B) - rw [star_mul,hT.isSelfAdjoint.star_eq] - change _=B.adjoint*T*A*(T*B) - rw [mul_assoc B.adjoint T A,←hcomm.eq] - simp only [mul_assoc] - rw [←mul_assoc T T B,hT.isIdempotentElem.eq] - have hTB : ‖T*B‖≤‖P*B‖ := by - have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] - rw [he] - exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) - rw [he,projection_sandwich_norm P B hP] - calc - _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] - _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 - -omit [CompleteSpace V] [Fintype ι] in -lemma resolution_commute (P : ι → V →L[ℂ] V) - (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by - by_cases hij : i=j - · subst j; exact Commute.refl _ - · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm - -omit [Fintype ι] in -lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : - (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by - rw [Finset.sum_mul] - have he (i : ι) : P i*P j=if i=j then P j else 0 := by - split_ifs with h - · subst i; exact (hP j).isIdempotentElem.eq - · exact horth i j h - simp only [he,Finset.sum_ite_eq'] - -lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) - (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) - (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : - ‖A*(∑ i∈S,P i)‖≤c := by - apply resolution_norm_bound P hP horth hsum _ _ c hc - · intro i - rw [mul_assoc,resolution_sum_mul P hP horth] - split_ifs with hi - · exact hbound i hi - · simp [hc] - · intro i - exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) - -theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) - (hT : ∀ i, IsStarProjection (T i)) - (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) - (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) - (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) - (hA : ‖A‖≤1) (hB : ‖B‖≤1) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : - ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by - have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm - Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) - have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by - rw [Finset.sum_compl_add_sum,hsum] - have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ - ∑ i∈S,B.adjoint*A*T i*B := by - rw [←Finset.sum_mul,←Finset.mul_sum] - rw [←add_mul] - simp only [mul_assoc] - rw [←mul_add,←mul_add,hsplit] - simp only [mul_one,mul_assoc] - rw [he] - apply (norm_add_le _ _).trans - apply add_le_add - · calc - _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := - (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) - hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) - _ = c := by ring - · apply (norm_sum_le _ _).trans - exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA - -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) - -noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1-P i else P i - -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma choice_commute (E F : Finset ι) (i j : ι) : - Commute (choice P E i) (choice P F j) := by - unfold choice - split_ifs - · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) - · exact (Commute.one_left _).sub_left (hcomm i j) - · exact (Commute.one_right _).sub_right (hcomm i j) - · exact hcomm i j - -noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := - s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : - sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by - exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha - -end Thorp.CommutingBlocks - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.Shapes + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where + toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) + isIntertwining' h := by + ext v + simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] + have hh (w : W) : σ h (σ h⁻¹ w)=w := by + change (σ h*σ h⁻¹) w=w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [hh] + +omit [FiniteDimensional ℂ V] in +lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : + LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = + (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by + change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ + rw [map_sum] + have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by + rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] + simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + +lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (A : Module.End ℂ V) : + ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ + c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by + obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) + have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by + rw [←hc] + rfl + refine ⟨c,he,?_⟩ + rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] + +theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (u v w z : V) : + (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = + (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by + obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap + rw [InnerProductSpace.trace_rankOne] at htrace + have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc + change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ + simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ + have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by + simpa only [mul_comm] using happ + rw [hsum] + calc + _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring + _ = _ := by rw [htrace] + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X : Type*} [Group G] [Fintype G] [Fintype X] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) + +noncomputable def representative (x : X) : G := Classical.choose (ha x) + +omit [Fintype G] [Fintype X] in +lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := + Classical.choose_spec (ha x) + +include ha in +lemma orbit_sum (F : X → ℂ) : + (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by + have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by + obtain ⟨t,rfl⟩ := ha x + symm + apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) + intro g + simp + calc + _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm + _ = ∑ g : G, ∑ x : X, F x := by + apply Finset.sum_congr rfl + intro g _ + exact Equiv.sum_comp (a g) F + _ = _ := by simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) + +def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w + +noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : + coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by + let r := representative a x₀ ha (a g x₀) + have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ + have hs : a (g⁻¹*r) x₀=x₀ := by + simp only [map_mul,Equiv.Perm.mul_apply] + rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] + rfl + have he := congrArg (ρ g) (hw (g⁻¹*r) hs) + have hh : ρ r w=ρ g w := by + simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, + mul_inv_cancel_left] using he + change inner ℂ (ρ r w) v= _ + rw [hh] + +lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = + (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by + have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) + simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs + simp only [←starRingEnd_apply,inner_conj_symm] at hs + simp only [starRingEnd_apply] at hs + have ho := coefficient_orthogonality ρ hρ v w z t + have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + apply mul_left_cancel₀ hcard + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,starRingEnd_apply] + have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = + ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by + apply Finset.sum_congr rfl + intro x _ + ring + rw [hsum] + calc + _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, + star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring + _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, + inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring + _ = _ := by rw [ho]; ring + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) + (v : V) (g : G) (x : X) : + coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by + obtain ⟨r,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, + coefficient_at a x₀ ha ρ w hw] + simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] + +noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := + (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v + +lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = + inner ℂ z w*inner ℂ v t := by + let : Nonempty X := ⟨x₀⟩ + have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = + (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by + rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] + simp + simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] + simp only [Complex.conj_ofReal] + rw [←mul_assoc,←pow_two,hs] + have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t + field_simp + simpa only [mul_assoc] using hi + +lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) + (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : + Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by + rw [orthonormal_iff_ite] at hw ⊢ + intro i j + rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, + inner_self_eq_norm_sq_to_K,hv] + simp [eq_comm] + +lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : + ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by + have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v + rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he + simp only [inner_self_eq_norm_sq_to_K] at he + norm_num at he + have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he + nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteConvolution +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) +noncomputable def power (p : G → ℝ) : ℕ → G → ℝ + | 0 => fun g => if g=1 then 1 else 0 + | n+1 => conv p (power p n) + +lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : + ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) + +lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) + {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by + apply lt_of_lt_of_le (mul_pos ha hb) + have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) + (Finset.mem_univ a) + simpa [conv] using h + +lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by + unfold conv + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [←Finset.mul_sum] + congr 1 + exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) + +lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by + intro n + induction n with + | zero => intro g; simp only [power]; split_ifs <;> norm_num + | succ n ih => exact conv_nonneg hp ih + +lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by + intro n + induction n with + | zero => simp [power] + | succ n ih => rw [power,sum_conv,hp,ih,one_mul] + +lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) + (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by + induction l with + | nil => simp [power] + | cons a l ih => + simpa only [List.length_cons,List.prod_cons,power] using + conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) + (ih (fun g hg => hl g (by simp [hg]))) + +lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by + induction m, hnm using Nat.le_induction with + | base => exact hg + | succ m _ ih => + simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih + +theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + (hgen : Subgroup.closure {g | 0 < p g}=⊤) : + ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by + have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by + rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] + trivial + choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) + let n := Finset.univ.sup (fun g => (l g).length) + refine ⟨n,fun g => ?_⟩ + have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) + have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) + have hpos := power_list_pos hp (l g) (hl g) + rw [hprod g] at hpos + exact power_pos_mono hp h1 (hlen.trans hpow) hpos + +structure Minorant (p : G → ℝ) where + exponent : ℕ + mass : ℝ + mass_pos : 0 < mass + mass_le_one : mass ≤ 1 + lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g + +noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) + (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by + let n := Classical.choose (exists_positive_power hp h1 hgen) + have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) + let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) + have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) + have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) + have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos + have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' + refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ + have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp + rw [he] + exact hag g + +end Thorp.FiniteConvolution +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : + continuousRepresentation ρ g v=ρ g v := rfl + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : + ‖ρ g v‖=‖v‖ := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] + +omit [Fintype G] in +lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + ‖continuousRepresentation ρ g‖≤1 := by + apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one + intro v + simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] + +omit [Fintype G] in +lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by + ext w + apply ext_inner_left ℂ + intro v + rw [ContinuousLinearMap.adjoint_inner_right] + exact (unitary_inner_inv ρ hρ g v w).symm + +noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := + ∑ g, (p g : ℂ) • continuousRepresentation ρ g + +lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro g _ + rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] + exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) + +lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by + change (weightedOperator ρ p).adjoint=weightedOperator ρ p + unfold weightedOperator + rw [map_sum] + simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] + apply Fintype.sum_equiv (Equiv.inv G) + intro g + simp [hp] + +noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := + weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) + +lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) + +lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : + continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,←map_mul] + exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) + +lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : + uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,←map_mul] + exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) + +lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : + IsIdempotentElem (uniformOperator ρ) := by + change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ + nth_rw 1 [uniformOperator,weightedOperator] + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, + ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] + rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsStarProjection (uniformOperator ρ) := + ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ + +lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : + weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : + uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) + (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : + ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by + let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) + have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) + have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hsum : ∑ g,q g=1-ε := by + simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by + simp only [uniformOperator,weightedOperator] + rw [Finset.smul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro g _ + simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, + Complex.ofReal_inv,Complex.ofReal_natCast] + congr 1 + field_simp + ring + have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by + rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] + rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] + calc + _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ + _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) + ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) + (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) + _ = _ := mul_one _ + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : + weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by + unfold weightedOperator FiniteConvolution.conv + simp only [Complex.ofReal_sum,Finset.sum_smul] + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [Finset.mul_sum] + simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp [Complex.ofReal_mul,mul_comm] + +lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : + weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by + induction n with + | zero => simp [FiniteConvolution.power,weightedOperator] + | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] + +lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) + (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : + (weightedOperator ρ p-uniformOperator ρ)^n= + (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by + have hAP := weighted_uniform_left ρ p + have hPA := weighted_uniform_right ρ p + rw [hp,one_smul] at hAP hPA + have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by + show _*_= _*_ + rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] + have he : weightedOperator ρ p-uniformOperator ρ= + weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] + rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] + +noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := + 1-c.mass/(2*(2:ℝ)^c.exponent) + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + unfold minorantGap + linarith + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by + unfold minorantGap + exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) + +theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) + (c : FiniteConvolution.Minorant p) : + ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by + have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) + have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) + (FiniteConvolution.sum_power hp _) c.mass c.lower + rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), + hself.norm_pow_two_pow] at hbound + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + have hbern := one_add_mul_le_pow + (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) + (2^c.exponent) + have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by + push_cast + field_simp + ring + rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern + by_contra h + have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h + have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) + linarith [c.mass_pos] + +end Thorp.UnitaryFinite +namespace Thorp +open scoped BigOperators Classical + +def butterflyIdentity : (d : ℕ) → Butterfly d + | 0 => () + | d+1 => (fun _ => false,fun _ => butterflyIdentity d) + +lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by + apply Equiv.ext + intro x + change switchFun (fun _ => false) x=x + simp [switchFun] + +lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by + ext x i + simp [childLift] + +lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by + induction d with + | zero => rfl + | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] + +noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where + toFun p := childLift (fun c => if c=b then p else 1) + map_one' := by simpa only [ite_self] using childLift_one d + map_mul' p q := by + rw [childLift_mul] + congr 1 + funext c + split_ifs <;> simp + +lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : + childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ + by_cases hc : c=b + · subst c + simp only [↓reduceIte] + rw [Equiv.swap_apply_def] + split_ifs with h₁ h₂ + · subst w; simp + · subst w; simp + · rw [Equiv.swap_apply_of_ne_of_ne] + · exact fun h => h₁ (by simpa using congrArg Fin.tail h) + · exact fun h => h₂ (by simpa using congrArg Fin.tail h) + · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + +lemma pairSwitch_single (d : ℕ) (u : Card d) : + pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ + by_cases h : w=u + · subst w + cases c <;> simp [switchFun] + · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) + have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) + simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] + +theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) + (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by + induction d with + | zero => + apply top_unique + intro p _ + have hp : p=1 := Subsingleton.elim _ _ + rw [hp] + exact H.one_mem + | succ d ih => + have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by + have hc : H.comap (childInjection d b)=⊤ := by + apply ih + intro ω + change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H + have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) + simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h + have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial + exact hp + have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by + rw [←pairSwitch_single] + have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) + simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h + have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by + have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by + cases a <;> cases b + · rw [Equiv.swap_self]; exact H.one_mem + · exact hpair _ + · rw [Equiv.swap_comm]; exact hpair _ + · rw [Equiv.swap_self]; exact H.one_mem + have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by + convert ht (x 0) (y 0) (Fin.tail x) using 1 + rw [Fin.cons_self_tail] + have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) + rw [childInjection_swap,Fin.cons_self_tail] at h₂ + exact SubmonoidClass.swap_mem_trans H h₁ h₂ + rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] + rintro _ ⟨x,y,_,rfl⟩ + exact hswap x y + +lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := + butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) + +variable {Ω G : Type*} [Fintype Ω] [Fintype G] + +noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := + finiteMean (fun ω => if P ω=g then 1 else 0) + +omit [Fintype G] in +lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := + finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) + +lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by + unfold sampleLaw + rw [←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype G] in +lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : + 0 by split_ifs <;> norm_num)] + simp only [Finset.mem_univ,true_and] + apply exists_congr + intro ω + split_ifs <;> simp_all + +omit [Fintype G] in +lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : + sampleLaw (P ∘ e)=sampleLaw P := by + funext g + simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) + +variable [Group G] +omit [Fintype G] in +lemma sampleLaw_inverse (P : Ω → G) (g : G) : + sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by + apply finiteMean_congr + intro ω + rw [inv_eq_iff_eq_inv] + +omit [Fintype G] in +lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) + (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by + rw [←sampleLaw_inverse] + have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) + rw [hh,sampleLaw_equiv] + +end Thorp + +namespace Thorp +open scoped BigOperators Classical + +lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by + refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), + (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + exact mul_inv_cancel _ + +lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : + ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by + refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + unfold palindromePerm + have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := + (butterflyCoinEquiv d).apply_symm_apply β + rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] + +lemma palindrome_support_generates (d : ℕ) : + Subgroup.closure {g | 0 P i v) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) + rw [hsplit] at hp + have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) + rw [hsplit] at ha + have he (i : ι) : P i (A v)=(A*P i) (P i v) := by + change (P i*A) v=(A*P i*P i) v + rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] + have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by + rw [he] + exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) + have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) + simp_rw [mul_pow] at hsq + rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq + exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq + +theorem sector_sandwich_le (T P A B : V →L[ℂ] V) + (hT : IsStarProjection T) (hP : IsStarProjection P) + (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : + ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by + have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by + change _=star (T*B)*A*(T*B) + rw [star_mul,hT.isSelfAdjoint.star_eq] + change _=B.adjoint*T*A*(T*B) + rw [mul_assoc B.adjoint T A,←hcomm.eq] + simp only [mul_assoc] + rw [←mul_assoc T T B,hT.isIdempotentElem.eq] + have hTB : ‖T*B‖≤‖P*B‖ := by + have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] + rw [he] + exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) + rw [he,projection_sandwich_norm P B hP] + calc + _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] + _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 + +omit [CompleteSpace V] [Fintype ι] in +lemma resolution_commute (P : ι → V →L[ℂ] V) + (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by + by_cases hij : i=j + · subst j; exact Commute.refl _ + · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm + +omit [Fintype ι] in +lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : + (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by + rw [Finset.sum_mul] + have he (i : ι) : P i*P j=if i=j then P j else 0 := by + split_ifs with h + · subst i; exact (hP j).isIdempotentElem.eq + · exact horth i j h + simp only [he,Finset.sum_ite_eq'] + +lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) + (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) + (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : + ‖A*(∑ i∈S,P i)‖≤c := by + apply resolution_norm_bound P hP horth hsum _ _ c hc + · intro i + rw [mul_assoc,resolution_sum_mul P hP horth] + split_ifs with hi + · exact hbound i hi + · simp [hc] + · intro i + exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) + +theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) + (hT : ∀ i, IsStarProjection (T i)) + (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) + (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) + (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) + (hA : ‖A‖≤1) (hB : ‖B‖≤1) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : + ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by + have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm + Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) + have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by + rw [Finset.sum_compl_add_sum,hsum] + have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ + ∑ i∈S,B.adjoint*A*T i*B := by + rw [←Finset.sum_mul,←Finset.mul_sum] + rw [←add_mul] + simp only [mul_assoc] + rw [←mul_add,←mul_add,hsplit] + simp only [mul_one,mul_assoc] + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add + · calc + _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) + hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) + _ = c := by ring + · apply (norm_sum_le _ _).trans + exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA + +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) + +noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1-P i else P i + +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma choice_commute (E F : Finset ι) (i j : ι) : + Commute (choice P E i) (choice P F j) := by + unfold choice + split_ifs + · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) + · exact (Commute.one_left _).sub_left (hcomm i j) + · exact (Commute.one_right _).sub_right (hcomm i j) + · exact hcomm i j + +noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := + s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : + sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by + exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha + +end Thorp.CommutingBlocks + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/BlockProduct.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/BlockProduct.lean index 80161aeba7bfdc24dc3df6c8119377f886d7ba27..c812ca4936a8a9cb09c373cb912f3b1f03da59b1 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/BlockProduct.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/BlockProduct.lean @@ -1,892 +1,892 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.AverageMap - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : - sector P hcomm s E=sector P hcomm s F := by - apply Finset.noncommProd_congr rfl - intro i hi - simp only [choice,h i hi] - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_factor_commute (s E F : Finset ι) (i : ι) : - Commute (choice P E i) (sector P hcomm s F) := - Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) - -omit [Fintype ι] in -lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : - IsStarProjection (sector P hcomm s E) := by - induction s using Finset.induction_on with - | empty => exact IsStarProjection.one _ - | @insert a s ha ih => - rw [sector_insert P hcomm s E a ha] - have hc : IsStarProjection (choice P E a) := by - unfold choice - split_ifs - · exact (hP a).one_sub - · exact hP a - exact hc.mul ih (sector_factor_commute P hcomm s E E a) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by - induction s using Finset.induction_on with - | empty => - simp only [Finset.powerset_empty,Finset.sum_singleton] - exact Finset.noncommProd_empty _ _ - | @insert a s ha ih => - rw [Finset.sum_powerset_insert ha] - have h₁ (E : Finset ι) (hE : E∈s.powerset) : - sector P hcomm (insert a s) E=P a*sector P hcomm s E := by - rw [sector_insert P hcomm s E a ha] - congr 1 - exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) - have h₂ (E : Finset ι) (_hE : E∈s.powerset) : - sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by - rw [sector_insert P hcomm s (insert a E) a ha] - simp only [choice,Finset.mem_insert_self,↓reduceIte] - congr 1 - apply sector_congr - intro i hi - simp [ne_of_mem_of_not_mem hi ha] - rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, - ←Finset.mul_sum,←Finset.mul_sum,ih] - simp - -omit [Fintype ι] in -lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) - (hP : ∀ i, IsStarProjection (P i)) : - choice P E i*sector P hcomm s E=sector P hcomm s E := by - have hc : IsIdempotentElem (choice P E i) := by - unfold choice - split_ifs - · exact (hP i).one_sub.isIdempotentElem - · exact (hP i).isIdempotentElem - have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) - (fun i _ j _ _ => choice_commute P hcomm E E i j) - change choice P E i*sector P hcomm s E=sector P hcomm s E - change _=sector P hcomm s E at hsplit - nth_rw 1 [←hsplit] - rw [←mul_assoc,hc.eq,hsplit] - -omit [Fintype ι] in -lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) - (hP : ∀ i, IsStarProjection (P i)) : - sector P hcomm s E*sector P hcomm s F=0 := by - have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by - by_contra h - push Not at h - exact hEF (Finset.ext fun i => by - by_cases hi : i∈s - · exact h i hi - · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) - obtain ⟨i,hi,hdiff⟩ := hdiff - have hz : choice P E i*choice P F i=0 := by - by_cases he : i∈E <;> by_cases hf : i∈F - · exact (hdiff (iff_of_true he hf)).elim - · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self - · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self - · exact (hdiff (iff_of_false he hf)).elim - have hEi := sector_absorb_factor P hcomm s E i hi hP - have hFi := sector_absorb_factor P hcomm s F i hi hP - calc - _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by - simp only [mul_assoc] - rw [hFi] - rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] - _ = 0 := by rw [hz,mul_zero,zero_mul] - -noncomputable def blockProduct (A : ι → V →L[ℂ] V) - (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := - s.noncommProd A (fun i _ j _ _ => hA i j) - -omit hcomm [Fintype ι] in -lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by - induction s using Finset.induction_on with - | empty => exact ContinuousLinearMap.norm_id_le - | @insert a s ha ih => - have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,Finset.prod_insert ha] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) - -noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := - blockProduct A hA Finset.univ - -omit hcomm in -lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := - (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) - -omit [CompleteSpace V] in -lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : - Commute (blocks A hA) (sector P hcomm Finset.univ E) := by - unfold blocks blockProduct - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm - intro i _ - unfold sector - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm - intro j _ - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - -lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : - ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by - have hAC (i j : ι) : Commute (A i) (choice P E j) := by - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) - (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) - (fun i _ j _ _ => (hAC j i).symm) - change _=blocks A hA*sector P hcomm Finset.univ E at hprod - rw [←hprod] - have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := - ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) - apply (norm_noncommProd_le _ hc Finset.univ).trans - calc - _ ≤ ∏ i : ι, if i∈E then θ else 1 := by - apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) - intro i _ - dsimp only [Pi.mul_apply] - unfold choice - split_ifs with hi - · exact hgap i - · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) - _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] - -noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := - Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) - -lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - IsStarProjection (coarse P hcomm E) := by - have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by - apply Finset.noncommProd_congr rfl - intro i _ - simp [choice] - rw [he] - exact sector_projection P hcomm hP _ _ - -lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by - have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by - have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP - rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h - simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h - have hp (s : Finset ι) (hs : ∀ i∈s, - sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : - sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by - induction s using Finset.induction_on with - | empty => exact mul_one _ - | @insert a s ha ih => - have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] - exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) - exact hp Eᶜ hpi - -theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) - (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : - ‖B.adjoint*blocks A hA*B‖≤θ^n+ - ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) - (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) - hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) - (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) - (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all - -lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - ‖sampleOperator ρ P‖≤1 := by - rw [sampleOperator_weighted] - exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) - -omit [Fintype G] in -lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : - sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by - simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] - rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] - -omit [Fintype G] in -lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by - simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, - Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - apply Finset.sum_congr rfl - intro ξ _ - rw [mul_comm] - -omit [Fintype G] in -lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by - simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, - continuousRepresentation_adjoint ρ hρ] - -lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : - sampleOperator ρ (palindromePerm d)= - sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* - (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by - rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] - rfl - -omit [Fintype G] in -lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : - sampleOperator ρ (fun _ : Ω => 1)=1 := by - simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, - smul_smul] - rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by - simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, - Finset.smul_sum,id_eq] - -lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by - rw [sampleOperator_prod] - have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by - rw [←sampleOperator_uniform] - exact sampleOperator_equiv ρ id (Equiv.inv G) - rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteAverage -open scoped BigOperators Classical -variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] - [Ring A] [Algebra ℂ A] - -noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := - MultilinearMap.domDomCongr (Fintype.equivFin I).symm - (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) - -lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : - orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by - unfold orderedProduct - rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] - let l := List.ofFn (Fintype.equivFin I).symm - have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective - have hu : l.toFinset=Finset.univ := by - ext i - simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] - exact (Fintype.equivFin I).symm.surjective i - have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl - rw [hu] at he - rw [he] - congr 1 - exact List.map_ofFn.symm - -lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : - F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by - rw [F.map_smul_univ,F.map_sum] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] - -lemma ordered_average (x : I → Ω → A) - (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) - (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : - (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - (fun _ _ _ _ hij => havg hij))= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, - Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by - rw [←orderedProduct_eq _ havg,multilinear_average] - simp only [orderedProduct_eq _ (hc _)] - -end Thorp.FiniteAverage -namespace Thorp.FiniteCharacters -open Module -open scoped BigOperators Classical - -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) -include hneq hcard - -lemma character_expansion (f : ConjClasses G → ℂ) : - f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases h : i=j - · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] - · rw [ite_eq_right h,ite_eq_right (hneq i j h)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij; exact (horth i j).trans (ite_eq_right hij) - · intro i; simpa using horth i i - have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) - have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ - have hd (i : ι) : b.coord i=characterDual (ρ i) := by - apply b.ext - intro j - rw [hb,horth] - simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] - split_ifs <;> simp_all - have h := b.sum_repr f - simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm - -theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by - let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 - have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by - simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] - have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by - change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ - simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, - Representation.char_one,Nat.card_eq_fintype_card] - have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) - rw [hf,ite_eq_left rfl] at he - simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he - have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by - calc - _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * - (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - field_simp - _ = _ := by rw [←he,mul_one] - exact_mod_cast hs - -end Thorp.FiniteCharacters - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] - [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] - [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : - averageMap ρ σ A=0 := by - rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h - · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim - · exact h - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) - (u z : W) (v w : V) : - ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by - have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap - have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he - change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv - simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] - -def regularAction : G →* Equiv.Perm G where - toFun := Equiv.mulLeft - map_one' := by ext; simp - map_mul' _ _ := by ext; simp - -omit [Fintype G] in -lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by - intro g hg - have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg - subst g - simp - -noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := - normalizedCoefficient regularAction 1 regular_transitive ρ w v - -omit [FiniteDimensional ℂ V] in -lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : - regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by - unfold regularCoefficient normalizedCoefficient - simp only [PiLp.smul_apply,smul_eq_mul] - congr 1 - have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g - simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he - -lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (w z v t : V) : - inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := - normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z - (regular_fixed ρ w) (regular_fixed ρ z) v t - -variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) - (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, - inner_conj_symm] - have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z - calc - _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* - (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * - ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - _ = 0 := by rw [he,mul_zero] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteFourier -open scoped BigOperators ComplexConjugate Classical -open UnitaryFinite -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hρ : ∀ i, IsUnitary (ρ i)) -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) - - -abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) - -noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := - regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) - -omit [Fintype ι] in -include hρ hneq in -lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by - rw [orthonormal_iff_ite] - rintro ⟨i,a,b⟩ ⟨j,c,d⟩ - dsimp only [coefficientFamily] - by_cases hij : i=j - · subst j - rw [regularCoefficient_inner _ (hρ i)] - simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] - by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] - · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] - rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] - -include ρ hneq hcard in -lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by - simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] - exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard - -noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := - OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) - (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' - (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) - -lemma coefficientBasis_apply (a : CoefficientIndex V) : - coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a - -include hρ hneq hcard in - -theorem parseval (f : EuclideanSpace ℂ G) : - ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by - simpa only [coefficientBasis_apply] using - (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f - - -noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : - inner ℂ (coefficientFamily V ρ a) (realVector p)= - (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* - inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by - simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, - RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, - weightedOperator,sum_apply,smul_apply, - continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : - ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= - ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* - ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by - rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, - abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] - -include hρ hneq hcard in -lemma parseval_operator (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2= - ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←parseval V ρ hρ hneq hcard (realVector p)] - simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] - have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - have he (a : Fin (Module.finrank ℂ (V i))) : - (∑ b : Fin (Module.finrank ℂ (V i)), - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) - (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] - simp_rw [he] - rw [←Finset.mul_sum] - field_simp - -include hρ hneq hcard in -lemma realVector_bound (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2≤ - ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - rw [parseval_operator V ρ hρ hneq hcard] - apply Finset.sum_le_sum - intro i _ - calc - _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - apply Finset.sum_le_sum - intro a _ - apply pow_le_pow_left₀ (norm_nonneg _) - simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using - (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring - -include hρ hneq hcard in - -theorem l1_fourier_bound (p : G → ℝ) : - (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) - have he : ‖realVector p‖^2=∑ g,|p g|^2 := by - rw [EuclideanSpace.norm_sq_eq] - simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] - rw [he] - simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) - -end Thorp.FiniteFourier - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -variable {B X : Type*} - -def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where - toFun p := - { toFun := fun x => (x.1,p x.1 x.2) - invFun := fun x => (x.1,(p x.1).symm x.2) - left_inv := fun x => by simp - right_inv := fun x => by simp } - map_one' := rfl - map_mul' _ _ := rfl - -@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl - -noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := - lift.comp - { toFun := fun p c => if c=b then p else 1 - map_one' := by funext c; simp - map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } - -@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : - injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by - simp only [injection,MonoidHom.comp_apply,lift_apply] - by_cases h : x.1=b <;> simp [h] - -lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : - Commute (injection b p) (injection c q) := by - apply Equiv.ext - intro x - simp only [Equiv.Perm.mul_apply,injection_apply] - by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all - -variable [Fintype B] - -lemma lift_product (p : B → Equiv.Perm X) : - lift p=Finset.univ.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := by - have he (s : Finset B) (x : B × X) : - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) x= - (x.1,if x.1∈s then p x.1 x.2 else x.2) := by - induction s using Finset.induction_on with - | empty => - have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ - rw [hz]; simp - | @insert a s ha ih => - have hz : (insert a s).noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] - by_cases h : x.1=a - · subst a; simp [ha] - · simp [h] - apply Equiv.ext - intro x - rw [he] - simp - -end Thorp.ParallelBlocks -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H : Type*} [Group G] [Group H] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : - continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl - -lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : - sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl - -omit [FiniteDimensional ℂ V] in -lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : - IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w - -lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) - (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : - Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by - unfold sampleOperator - apply Commute.smul_left - apply Commute.smul_right - apply Commute.sum_left - intro ω _ - apply Commute.sum_right - intro ξ _ - exact (h ω ξ).map (continuousRepresentation ρ) - -lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] - (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by - rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype B] [DecidableEq B] in -lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) - (sampleOperator (ρ.comp (injection c)) (P c)) := by - by_cases h : b=c - · subst c; exact Commute.refl _ - · rw [sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) : - sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= - CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) - (local_average_commute ρ P) := by - let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) - have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by - intro ω b c h - exact (injection_commute h _ _).map (continuousRepresentation ρ) - have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by - intro b c _ - exact local_average_commute ρ P b c - have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= - Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by - rw [lift_product] - exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) - unfold sampleOperator - simp_rw [he] - exact (FiniteAverage.ordered_average A hc havg).symm - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical - -noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := - (cardSplit r L).permCongrHom - -noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : - Equiv.Perm (Card r × Card L) := - (Equiv.prodComm (Card L) (Card r)).permCongrHom - (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) - -lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : - outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl - -lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= - outerPerm r L hi*ParallelBlocks.lift - (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by - apply Equiv.ext - intro x - change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) - ((cardSplit r L).symm x))=_ - rw [butterfly_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r+1) → Bool) : - boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) - (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by - conv_lhs => unfold boundaryTree - congr 1 - funext b - cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : - boundaryOutput L (r+1) Y b= - boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by - conv_lhs => unfold boundaryOutput - cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : - cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= - let y := cardSplit r L x - let z := U y.1 y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) - have hh := ih U' lo' hi' (Fin.tail x) - let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) - let y := cardSplit r L (Fin.tail x) - let z := U' y.1 y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r L u=(w,z) at hh - rw [boundaryTree_node_raw] - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) - ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= - outerPerm r L hi*ParallelBlocks.lift U := by - apply Equiv.ext - intro x - change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm - ((cardSplit r L).symm x))=_ - rw [boundaryTree_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) (b : Card r) : - boundaryOutput L r (assembleBits r L lo hi) b= - butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by - induction r with - | zero => - rw [Subsingleton.elim b (fun j => Fin.elim0 j)] - rfl - | succ r ih => - rw [boundaryOutput_node_raw] - change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ - rw [ih] - simp only [Fin.cons_self_tail] - - -abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool -abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool - -def parallelSplitCoinEquiv (r L : ℕ) : - ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := - (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans - (splitCoinEquiv r L) - -lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : - parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by - exact splitCoinEquiv_apply _ _ _ _ - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.AverageMap + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : + sector P hcomm s E=sector P hcomm s F := by + apply Finset.noncommProd_congr rfl + intro i hi + simp only [choice,h i hi] + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_factor_commute (s E F : Finset ι) (i : ι) : + Commute (choice P E i) (sector P hcomm s F) := + Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) + +omit [Fintype ι] in +lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : + IsStarProjection (sector P hcomm s E) := by + induction s using Finset.induction_on with + | empty => exact IsStarProjection.one _ + | @insert a s ha ih => + rw [sector_insert P hcomm s E a ha] + have hc : IsStarProjection (choice P E a) := by + unfold choice + split_ifs + · exact (hP a).one_sub + · exact hP a + exact hc.mul ih (sector_factor_commute P hcomm s E E a) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by + induction s using Finset.induction_on with + | empty => + simp only [Finset.powerset_empty,Finset.sum_singleton] + exact Finset.noncommProd_empty _ _ + | @insert a s ha ih => + rw [Finset.sum_powerset_insert ha] + have h₁ (E : Finset ι) (hE : E∈s.powerset) : + sector P hcomm (insert a s) E=P a*sector P hcomm s E := by + rw [sector_insert P hcomm s E a ha] + congr 1 + exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) + have h₂ (E : Finset ι) (_hE : E∈s.powerset) : + sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by + rw [sector_insert P hcomm s (insert a E) a ha] + simp only [choice,Finset.mem_insert_self,↓reduceIte] + congr 1 + apply sector_congr + intro i hi + simp [ne_of_mem_of_not_mem hi ha] + rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, + ←Finset.mul_sum,←Finset.mul_sum,ih] + simp + +omit [Fintype ι] in +lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) + (hP : ∀ i, IsStarProjection (P i)) : + choice P E i*sector P hcomm s E=sector P hcomm s E := by + have hc : IsIdempotentElem (choice P E i) := by + unfold choice + split_ifs + · exact (hP i).one_sub.isIdempotentElem + · exact (hP i).isIdempotentElem + have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) + (fun i _ j _ _ => choice_commute P hcomm E E i j) + change choice P E i*sector P hcomm s E=sector P hcomm s E + change _=sector P hcomm s E at hsplit + nth_rw 1 [←hsplit] + rw [←mul_assoc,hc.eq,hsplit] + +omit [Fintype ι] in +lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) + (hP : ∀ i, IsStarProjection (P i)) : + sector P hcomm s E*sector P hcomm s F=0 := by + have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by + by_contra h + push Not at h + exact hEF (Finset.ext fun i => by + by_cases hi : i∈s + · exact h i hi + · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) + obtain ⟨i,hi,hdiff⟩ := hdiff + have hz : choice P E i*choice P F i=0 := by + by_cases he : i∈E <;> by_cases hf : i∈F + · exact (hdiff (iff_of_true he hf)).elim + · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self + · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self + · exact (hdiff (iff_of_false he hf)).elim + have hEi := sector_absorb_factor P hcomm s E i hi hP + have hFi := sector_absorb_factor P hcomm s F i hi hP + calc + _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by + simp only [mul_assoc] + rw [hFi] + rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] + _ = 0 := by rw [hz,mul_zero,zero_mul] + +noncomputable def blockProduct (A : ι → V →L[ℂ] V) + (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := + s.noncommProd A (fun i _ j _ _ => hA i j) + +omit hcomm [Fintype ι] in +lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by + induction s using Finset.induction_on with + | empty => exact ContinuousLinearMap.norm_id_le + | @insert a s ha ih => + have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,Finset.prod_insert ha] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) + +noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := + blockProduct A hA Finset.univ + +omit hcomm in +lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := + (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) + +omit [CompleteSpace V] in +lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : + Commute (blocks A hA) (sector P hcomm Finset.univ E) := by + unfold blocks blockProduct + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm + intro i _ + unfold sector + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm + intro j _ + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + +lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : + ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by + have hAC (i j : ι) : Commute (A i) (choice P E j) := by + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) + (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) + (fun i _ j _ _ => (hAC j i).symm) + change _=blocks A hA*sector P hcomm Finset.univ E at hprod + rw [←hprod] + have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := + ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) + apply (norm_noncommProd_le _ hc Finset.univ).trans + calc + _ ≤ ∏ i : ι, if i∈E then θ else 1 := by + apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) + intro i _ + dsimp only [Pi.mul_apply] + unfold choice + split_ifs with hi + · exact hgap i + · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) + _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] + +noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := + Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) + +lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + IsStarProjection (coarse P hcomm E) := by + have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by + apply Finset.noncommProd_congr rfl + intro i _ + simp [choice] + rw [he] + exact sector_projection P hcomm hP _ _ + +lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by + have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by + have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP + rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h + simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h + have hp (s : Finset ι) (hs : ∀ i∈s, + sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : + sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by + induction s using Finset.induction_on with + | empty => exact mul_one _ + | @insert a s ha ih => + have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] + exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) + exact hp Eᶜ hpi + +theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) + (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : + ‖B.adjoint*blocks A hA*B‖≤θ^n+ + ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) + (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) + hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) + (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) + (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all + +lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + ‖sampleOperator ρ P‖≤1 := by + rw [sampleOperator_weighted] + exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) + +omit [Fintype G] in +lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : + sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by + simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] + rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] + +omit [Fintype G] in +lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by + simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, + Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro ξ _ + rw [mul_comm] + +omit [Fintype G] in +lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by + simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, + continuousRepresentation_adjoint ρ hρ] + +lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : + sampleOperator ρ (palindromePerm d)= + sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* + (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by + rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] + rfl + +omit [Fintype G] in +lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : + sampleOperator ρ (fun _ : Ω => 1)=1 := by + simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, + smul_smul] + rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by + simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, + Finset.smul_sum,id_eq] + +lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by + rw [sampleOperator_prod] + have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by + rw [←sampleOperator_uniform] + exact sampleOperator_equiv ρ id (Equiv.inv G) + rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteAverage +open scoped BigOperators Classical +variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] + [Ring A] [Algebra ℂ A] + +noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := + MultilinearMap.domDomCongr (Fintype.equivFin I).symm + (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) + +lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : + orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by + unfold orderedProduct + rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] + let l := List.ofFn (Fintype.equivFin I).symm + have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective + have hu : l.toFinset=Finset.univ := by + ext i + simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] + exact (Fintype.equivFin I).symm.surjective i + have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl + rw [hu] at he + rw [he] + congr 1 + exact List.map_ofFn.symm + +lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : + F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by + rw [F.map_smul_univ,F.map_sum] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] + +lemma ordered_average (x : I → Ω → A) + (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) + (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : + (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + (fun _ _ _ _ hij => havg hij))= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, + Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by + rw [←orderedProduct_eq _ havg,multilinear_average] + simp only [orderedProduct_eq _ (hc _)] + +end Thorp.FiniteAverage +namespace Thorp.FiniteCharacters +open Module +open scoped BigOperators Classical + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) +include hneq hcard + +lemma character_expansion (f : ConjClasses G → ℂ) : + f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases h : i=j + · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] + · rw [ite_eq_right h,ite_eq_right (hneq i j h)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij; exact (horth i j).trans (ite_eq_right hij) + · intro i; simpa using horth i i + have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) + have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ + have hd (i : ι) : b.coord i=characterDual (ρ i) := by + apply b.ext + intro j + rw [hb,horth] + simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] + split_ifs <;> simp_all + have h := b.sum_repr f + simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm + +theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by + let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 + have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by + simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] + have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by + change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ + simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, + Representation.char_one,Nat.card_eq_fintype_card] + have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) + rw [hf,ite_eq_left rfl] at he + simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he + have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by + calc + _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * + (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + field_simp + _ = _ := by rw [←he,mul_one] + exact_mod_cast hs + +end Thorp.FiniteCharacters + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] + [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] + [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : + averageMap ρ σ A=0 := by + rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h + · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim + · exact h + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) + (u z : W) (v w : V) : + ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by + have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap + have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he + change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv + simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] + +def regularAction : G →* Equiv.Perm G where + toFun := Equiv.mulLeft + map_one' := by ext; simp + map_mul' _ _ := by ext; simp + +omit [Fintype G] in +lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by + intro g hg + have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg + subst g + simp + +noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := + normalizedCoefficient regularAction 1 regular_transitive ρ w v + +omit [FiniteDimensional ℂ V] in +lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : + regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by + unfold regularCoefficient normalizedCoefficient + simp only [PiLp.smul_apply,smul_eq_mul] + congr 1 + have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g + simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he + +lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (w z v t : V) : + inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := + normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z + (regular_fixed ρ w) (regular_fixed ρ z) v t + +variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) + (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, + inner_conj_symm] + have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z + calc + _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* + (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * + ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + _ = 0 := by rw [he,mul_zero] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteFourier +open scoped BigOperators ComplexConjugate Classical +open UnitaryFinite +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hρ : ∀ i, IsUnitary (ρ i)) +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) + + +abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) + +noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := + regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) + +omit [Fintype ι] in +include hρ hneq in +lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by + rw [orthonormal_iff_ite] + rintro ⟨i,a,b⟩ ⟨j,c,d⟩ + dsimp only [coefficientFamily] + by_cases hij : i=j + · subst j + rw [regularCoefficient_inner _ (hρ i)] + simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] + by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] + · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] + rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] + +include ρ hneq hcard in +lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by + simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] + exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard + +noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := + OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) + (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' + (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) + +lemma coefficientBasis_apply (a : CoefficientIndex V) : + coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a + +include hρ hneq hcard in + +theorem parseval (f : EuclideanSpace ℂ G) : + ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by + simpa only [coefficientBasis_apply] using + (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f + + +noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : + inner ℂ (coefficientFamily V ρ a) (realVector p)= + (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* + inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by + simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, + RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, + weightedOperator,sum_apply,smul_apply, + continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : + ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= + ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* + ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by + rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] + +include hρ hneq hcard in +lemma parseval_operator (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2= + ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←parseval V ρ hρ hneq hcard (realVector p)] + simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] + have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + have he (a : Fin (Module.finrank ℂ (V i))) : + (∑ b : Fin (Module.finrank ℂ (V i)), + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) + (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] + simp_rw [he] + rw [←Finset.mul_sum] + field_simp + +include hρ hneq hcard in +lemma realVector_bound (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2≤ + ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + rw [parseval_operator V ρ hρ hneq hcard] + apply Finset.sum_le_sum + intro i _ + calc + _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro a _ + apply pow_le_pow_left₀ (norm_nonneg _) + simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using + (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring + +include hρ hneq hcard in + +theorem l1_fourier_bound (p : G → ℝ) : + (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) + have he : ‖realVector p‖^2=∑ g,|p g|^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] + rw [he] + simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) + +end Thorp.FiniteFourier + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +variable {B X : Type*} + +def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where + toFun p := + { toFun := fun x => (x.1,p x.1 x.2) + invFun := fun x => (x.1,(p x.1).symm x.2) + left_inv := fun x => by simp + right_inv := fun x => by simp } + map_one' := rfl + map_mul' _ _ := rfl + +@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl + +noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := + lift.comp + { toFun := fun p c => if c=b then p else 1 + map_one' := by funext c; simp + map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } + +@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : + injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by + simp only [injection,MonoidHom.comp_apply,lift_apply] + by_cases h : x.1=b <;> simp [h] + +lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : + Commute (injection b p) (injection c q) := by + apply Equiv.ext + intro x + simp only [Equiv.Perm.mul_apply,injection_apply] + by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all + +variable [Fintype B] + +lemma lift_product (p : B → Equiv.Perm X) : + lift p=Finset.univ.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := by + have he (s : Finset B) (x : B × X) : + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) x= + (x.1,if x.1∈s then p x.1 x.2 else x.2) := by + induction s using Finset.induction_on with + | empty => + have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ + rw [hz]; simp + | @insert a s ha ih => + have hz : (insert a s).noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] + by_cases h : x.1=a + · subst a; simp [ha] + · simp [h] + apply Equiv.ext + intro x + rw [he] + simp + +end Thorp.ParallelBlocks +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H : Type*} [Group G] [Group H] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : + continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl + +lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : + sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl + +omit [FiniteDimensional ℂ V] in +lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : + IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w + +lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) + (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : + Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by + unfold sampleOperator + apply Commute.smul_left + apply Commute.smul_right + apply Commute.sum_left + intro ω _ + apply Commute.sum_right + intro ξ _ + exact (h ω ξ).map (continuousRepresentation ρ) + +lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] + (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by + rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype B] [DecidableEq B] in +lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) + (sampleOperator (ρ.comp (injection c)) (P c)) := by + by_cases h : b=c + · subst c; exact Commute.refl _ + · rw [sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) : + sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= + CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) + (local_average_commute ρ P) := by + let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) + have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by + intro ω b c h + exact (injection_commute h _ _).map (continuousRepresentation ρ) + have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by + intro b c _ + exact local_average_commute ρ P b c + have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= + Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by + rw [lift_product] + exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) + unfold sampleOperator + simp_rw [he] + exact (FiniteAverage.ordered_average A hc havg).symm + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical + +noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := + (cardSplit r L).permCongrHom + +noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : + Equiv.Perm (Card r × Card L) := + (Equiv.prodComm (Card L) (Card r)).permCongrHom + (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) + +lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : + outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl + +lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= + outerPerm r L hi*ParallelBlocks.lift + (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by + apply Equiv.ext + intro x + change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) + ((cardSplit r L).symm x))=_ + rw [butterfly_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r+1) → Bool) : + boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) + (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by + conv_lhs => unfold boundaryTree + congr 1 + funext b + cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : + boundaryOutput L (r+1) Y b= + boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by + conv_lhs => unfold boundaryOutput + cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : + cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= + let y := cardSplit r L x + let z := U y.1 y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) + have hh := ih U' lo' hi' (Fin.tail x) + let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) + let y := cardSplit r L (Fin.tail x) + let z := U' y.1 y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r L u=(w,z) at hh + rw [boundaryTree_node_raw] + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) + ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= + outerPerm r L hi*ParallelBlocks.lift U := by + apply Equiv.ext + intro x + change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm + ((cardSplit r L).symm x))=_ + rw [boundaryTree_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) (b : Card r) : + boundaryOutput L r (assembleBits r L lo hi) b= + butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by + induction r with + | zero => + rw [Subsingleton.elim b (fun j => Fin.elim0 j)] + rfl + | succ r ih => + rw [boundaryOutput_node_raw] + change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ + rw [ih] + simp only [Fin.cons_self_tail] + + +abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool +abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool + +def parallelSplitCoinEquiv (r L : ℕ) : + ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := + (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans + (splitCoinEquiv r L) + +lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : + parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by + exact splitCoinEquiv_apply _ _ _ _ + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/Coins.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/Coins.lean index ac37b363f1ff06ecf2f078915f725275e466a3a4..8f54a3cb1b4dcce22deb0132d78c458673bc0e4d 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/Coins.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/Coins.lean @@ -1,764 +1,764 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.Model - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -open scoped BigOperators -open Filter - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Card d → Bool - -instance (d : ℕ) : Fintype (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -instance (d : ℕ) : Nonempty (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -def rotate (d : ℕ) : Equiv.Perm (Card d) where - toFun x i := x (finRotate d i) - invFun x i := x ((finRotate d).symm i) - left_inv x := by funext i; simp only [Equiv.apply_symm_apply] - right_inv x := by funext i; simp only [Equiv.symm_apply_apply] - -def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, ξ => rotate (d + 1) * pairSwitch ξ - -def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) - | 0, _ => 1 - | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) - -noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := - (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / - (Fintype.card (Fin t → Coins d) : ℝ) - -noncomputable def distance (d t : ℕ) : ℝ := - (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| - -noncomputable def mixingTime (d : ℕ) : ℕ := - sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} - -noncomputable def supportTimeBound (d : ℕ) : ℤ := - ⌈(2 / (2 : ℝ) ^ d) * - (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ - -def OptimalOrder : Prop := - ∃ C : ℕ, 0 < C ∧ - Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ - (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ - (∀ᶠ d : ℕ in atTop, - supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ - (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) - -noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by - classical - exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) - -lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : - ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by - classical - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : - 0 ≤ finiteLaw f b := by - exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - -lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : - ∑ b, finiteLaw f b = 1 := by - classical - simp only [finiteLaw, ← Finset.sum_div] - have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by - exact_mod_cast sum_card_fibers f - rw [hc] - exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by - classical - have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr - ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ - simp [finiteLaw] - -lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] - (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : - (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by - have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := - Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) - have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) - have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) - have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) - rw [hpq] at hz - rw [← Finset.sum_sub_distrib] - linarith - -lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] - [Fintype β] [Nonempty β] (f : α → β) : - 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ - (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by - classical - let s := Finset.univ.image f - have hs : ∑ b ∈ s, finiteLaw f b = 1 := by - have h := Finset.sum_subset (Finset.subset_univ s) - (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) - simpa only [finiteLaw_sum] using h - have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] - have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by - rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] - have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s - rw [hs] at he - have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by - simp [div_eq_mul_inv] - rw [hsq] at he - have hcard : (s.card : ℝ) ≤ Fintype.card α := by - exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) - have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) - linarith - -lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by - simp [Card] - -lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by - rw [Fintype.card_perm, card_positions] - -lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by - rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] - -lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : - law d t g = finiteLaw (run d t) g := by - unfold law finiteLaw - apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) - exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) - -lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by - rw [law_eq_finiteLaw] - exact finiteLaw_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by - simp only [law_eq_finiteLaw] - exact finiteLaw_sum (run d t) - -lemma physical_support_bound_succ (d t : ℕ) : - 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by - have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ - have h := finiteLaw_support_bound (run (d + 1) t) - rw [card_tapes_succ, card_permutations] at h - simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h - -lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : - step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by - change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ - rw [Fin.snoc_eq_cons_rotate] - rfl - -lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by - unfold distance - exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - -lemma physical_support_bound (d t : ℕ) : - 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by - cases d with - | zero => - have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) - simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using - le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) - | succ d => - have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by - push_cast - rw [pow_succ] - ring - rw [he, Real.rpow_natCast] - exact physical_support_bound_succ d t - -lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : - supportTimeBound d ≤ (t : ℤ) := by - have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity - have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity - have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) - have hb := physical_support_bound d t - have hp : (3 / 4 : ℝ) ≤ - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by - linarith - have hr := (le_div_iff₀ hF).mp hp - have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr - rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog - unfold supportTimeBound - apply Int.ceil_le.mpr - simp only [Int.cast_natCast] - calc - 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = - Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by - field_simp - _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by - nlinarith [hlog]) - -lemma supportTimeBound_le_mixingTime {d : ℕ} - (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : - supportTimeBound d ≤ (mixingTime d : ℤ) := by - exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) - -lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : - (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by - have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) - have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) - have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by - have := Real.pi_gt_three - linarith) - linarith - -lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) - have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by - rw [← Real.log_inv] - congr 1 - norm_num - rw [he] at h - linarith - -lemma linear_le_supportTimeBound (d : ℕ) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by - have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) - have hNp : 0 < (2 : ℝ) ^ d := by positivity - have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) - have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - rw [Real.log_mul (by norm_num) (by positivity)] - push_cast at hf - rw [Real.log_pow] at hf - linarith [log_three_quarters_lower] - apply le_trans _ (Int.le_ceil _) - have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) = - (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by - field_simp - ring - rw [hcancel] - linarith - convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 - field_simp - -lemma linear_le_time_of_distance_le (d t : ℕ) - (ht : distance d t ≤ (1 / 4 : ℝ)) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by - have h := supportTimeBound_le_of_distance_le d t ht - have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h - exact (linear_le_supportTimeBound d).trans hr - -lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : - 2 * p * Real.log 2 ≤ Real.binEntropy p := by - have hc := Real.strictConcave_binEntropy.concaveOn.2 - (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show 0 ≤ 1 - 2 * p by linarith) - (show 0 ≤ 2 * p by positivity) - (show (1 - 2 * p) + 2 * p = 1 by ring) - simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, - smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc - -lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : - 2 * min a b * Real.log 2 ≤ - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - wlog hab : a ≤ b generalizing a b - · have hba := this b a hb ha (le_of_not_ge hab) - simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) - rw [min_eq_left hab] - by_cases hz : a = 0 - · subst a - simp - have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) - have hbp : 0 < b := hap.trans_le hab - have hs : 0 < a + b := add_pos hap hbp - have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le - have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) - have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le - have he : (a + b) * Real.binEntropy (a / (a + b)) = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - unfold Real.binEntropy - rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] - simp only [Real.log_inv] - rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), - Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] - field_simp - ring - rw [he] at hc - calc - 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by - field_simp - _ ≤ _ := hc - -noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail - -lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by - classical - unfold childMarks - apply Finset.card_image_iff.mpr - intro x hx y hy hxy - have hx0 := (Finset.mem_filter.mp hx).2 - have hy0 := (Finset.mem_filter.mp hy).2 - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] - -lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : - (childMarks s false).card + (childMarks s true).card = s.card := by - classical - rw [card_childMarks, card_childMarks] - simpa only [Bool.not_eq_false] using - (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) - -noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) : Finset (Card d) := - ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ - ((childMarks s true).image (butterflyPerm d (b.2 true))) - -lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : - (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by - classical - apply le_min - · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) - · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) - -noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ - | 0, _, _ => 0 - | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card - -lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - induction d with - | zero => - simp only [encounters, Nat.cast_zero] - have hs : s.card ≤ 1 := by - simpa [Card] using Finset.card_le_univ s - interval_cases s.card <;> simp - | succ d ih => - have h₀ := ih (b.2 false) (childMarks s false) - have h₁ := ih (b.2 true) (childMarks s true) - have ht : ((topMeetings b s).card : ℝ) ≤ - min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by - exact_mod_cast card_topMeetings_le b s - have he := split_entropy_lower ((childMarks s false).card : ℝ) - ((childMarks s true).card : ℝ) (by positivity) (by positivity) - have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by - exact_mod_cast card_childMarks_add s - rw [hs] at he - have hL : 0 < 2 * Real.log 2 := by positivity - rw [le_div_iff₀ hL] at h₀ h₁ ⊢ - simp only [encounters, Nat.cast_add] - nlinarith [mul_le_mul_of_nonneg_right ht hL.le] - -lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by - by_cases ha : a ∈ s - · rw [ite_eq_left ha] - exact (Finset.mul_prod_erase s f ha).symm - · simp [ha] - -lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) - (a b : α) (hab : a ≠ b) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * - ∏ i ∈ (s.erase a).erase b, f i := by - calc - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := - prod_split_at s f a - _ = _ := by - rw [prod_split_at (s.erase a) f b] - have hm : (b ∈ s.erase a) ↔ b ∈ s := - ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ - simp only [hm, mul_assoc] - -lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ - ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by - by_cases hab : a = b - · subst b - simp only [Equiv.swap_self, Equiv.refl_apply] - have h : (fun i => (p i + p i) / 2) = p := by funext i; ring - rw [h] - linarith - let t := (s.erase a).erase b - have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by - intro i hi - exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) - have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) - rw [prod_split_two s p a b hab, - prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, - prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] - change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + - (if a ∈ s then p (Equiv.swap a b a) else 1) * - (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ - rw [hprod] - change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * - (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * - (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) - rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] - have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) - by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] - · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht - nlinarith - all_goals ring_nf; rfl - -def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := - ∀ s, m s ≤ ∏ i ∈ s, p i - -lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] - {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) - (fun i => (p i + p (Equiv.swap a b i)) / 2) := by - intro s - have h₀ := h s - have h₁ := h (s.image (Equiv.swap a b)) - rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ - exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans - (swap_average_product s p hp a b) - -noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : ℝ := by - classical - exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) - -lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by - classical - unfold inclusionMoment finiteMean - positivity - -lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : - (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by - by_cases h : s ⊆ A - · rw [ite_eq_left h] - exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm - · rw [ite_eq_right h] - obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h - exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm - -lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] - (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = - if s ⊆ A then 1 else 0 := by - classical - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] - -lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : - CylinderBound (inclusionMoment (fun _ : Ω => A)) - (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by - classical - intro s - simp only [inclusionMoment_const, Finset.singleton_subset_iff] - exact (indicator_subset_prod A s).le - -noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] - (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := - fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 - -lemma subset_swap_image_iff {α : Type*} [DecidableEq α] - (A s : Finset α) (a b : α) : - s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by - constructor - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - -lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) (s : Finset α) : - inclusionMoment (fairSetSwap F a b) s = - (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by - classical - simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, - fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, - Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] - rw [div_mul_eq_div_div, add_div] - ring_nf - -lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) - (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : - CylinderBound (inclusionMoment (fairSetSwap F a b)) - (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by - classical - have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b - intro s - simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s - -def SwitchSamples : ℕ → Type - | 0 => Unit - | n + 1 => SwitchSamples n × Bool - -instance (n : ℕ) : Fintype (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Fintype Unit) - | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) - -instance (n : ℕ) : Nonempty (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Nonempty Unit) - | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) - -noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : - (L : List (α × α)) → SwitchSamples L.length → Finset α - | [], _ => A - | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω - -lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) - (L : List (α × α)) : - CylinderBound (inclusionMoment (switchedSet A L)) - (fun i => inclusionMoment (switchedSet A L) {i}) := by - induction L with - | nil => exact cylinder_const A - | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih - -inductive QueryTree (ι : Type*) - | reject : QueryTree ι - | accept : QueryTree ι - | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι - | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι - -namespace QueryTree - -variable {ι : Type*} [DecidableEq ι] - -def queries : QueryTree ι → Finset ι - | reject => ∅ - | accept => ∅ - | branch i zero one => insert i (queries zero ∪ queries one) - | force i _ next => insert i (queries next) - -def Fresh : QueryTree ι → Prop - | reject => True - | accept => True - | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one - | force i _ next => i ∉ queries next ∧ Fresh next - -def weighted : QueryTree ι → (ι → Bool) → ℝ - | reject, _ => 0 - | accept, _ => 1 - | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω - | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 - -omit [DecidableEq ι] in -lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by - induction T with - | reject => exact le_rfl - | accept => exact zero_le_one - | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ - | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl - -lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} - (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by - induction T with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), - ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] - | force i b next ih => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] - -def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := - (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by - intro ω - funext j - by_cases h : j = i - · subst j; simp - · simp [Function.update_of_ne h]).toPerm - -lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by - change Function.update ω i (!(ω i)) i = _ - exact Function.update_self _ _ _ - -lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : - flipCoin i ω j = ω j := by - change Function.update ω i (!(ω i)) j = _ - exact Function.update_of_ne h _ _ - -lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) - (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by - apply weighted_congr - intro j hj - exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω - -lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) - (hf : ∀ ω, f (flipCoin i ω) = f ω) : - finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by - let g := fun ω : ι → Bool => if ω i = b then f ω else 0 - have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by - dsimp [g] - rw [flipCoin_apply_eq, hf] - cases hω : ω i <;> cases b <;> simp - have hs := Equiv.sum_comp (flipCoin i) g - have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun ω _ => hp ω) - unfold finiteMean - change (∑ ω, g ω) / _ = _ - rw [hs] at hadd - have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith - rw [hh] - ring - -lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : - finiteMean T.weighted ≤ 1 := by - induction T with - | reject => simp [weighted, finiteMean] - | accept => simp [weighted, finiteMean] - | branch i zero one ih₀ ih₁ => - obtain ⟨hz, ho, hfz, hfo⟩ := hT - have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) - have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) - have he : finiteMean (branch i zero one).weighted = - finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + - finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by - unfold finiteMean - rw [← add_div, ← Finset.sum_add_distrib] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - cases hω : ω i <;> simp [weighted, hω] - rw [he, h₀, h₁] - linarith [ih₀ hfz, ih₁ hfo] - | force i b next ih => - obtain ⟨hi, hn⟩ := hT - have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) - have he : finiteMean (force i b next).weighted = - 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by - unfold finiteMean - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : ω i = b <;> simp [weighted, h] - rw [he, hm] - linarith [ih hn] - -def succeeds : QueryTree ι → (ι → Bool) → Bool - | reject, _ => false - | accept, _ => true - | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω - | force i b next, ω => if ω i = b then succeeds next ω else false - -def charge : QueryTree ι → (ι → Bool) → ℕ - | reject, _ => 0 - | accept, _ => 0 - | branch i zero one, ω => if ω i then charge one ω else charge zero ω - | force i b next, ω => if ω i = b then charge next ω + 1 else 0 - -omit [DecidableEq ι] in -lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : - T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by - induction T with - | reject => rfl - | accept => norm_num [weighted, succeeds, charge] - | branch i zero one ih₀ ih₁ => - cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] - | force i b next ih => - by_cases h : ω i = b - · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] - cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] - · simp [weighted, succeeds, h] - -lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) - (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : - finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by - have hw (ω : ι → Bool) : - (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by - rw [weighted_eq] - cases hs : T.succeeds ω - · simp - · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) - have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ - have hm := div_le_div_of_nonneg_right - (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn - rw [← Finset.mul_sum, mul_div_assoc] at hm - change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ - finiteMean T.weighted at hm - exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by - rw [mul_comm] - exact hm.trans (mean_weighted_le_one T hT)) - -end QueryTree - -def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool - | 0, _, i => nomatch i - | _d + 1, b, Sum.inl y => b.1 y - | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i - -lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : - decodeButterfly d (encodeButterfly d b) = b := by - induction d with - | zero => exact Unit.ext _ _ - | succ d ih => - apply Prod.ext - · rfl - · funext ε - exact ih (b.2 ε) - -lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : - encodeButterfly d (decodeButterfly d ω) = ω := by - induction d with - | zero => funext i; exact Empty.elim i - | succ d ih => - funext i - cases i with - | inl y => rfl - | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 - -def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where - toFun := decodeButterfly d - invFun := encodeButterfly d - left_inv := encode_decodeButterfly d - right_inv := decode_encodeButterfly d - -noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) - | 0, _, _ => ∅ - | d + 1, x, y => by - classical - exact insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) - -def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool - | 0, _, _, i => nomatch i - | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) - | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.Model + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +open scoped BigOperators +open Filter + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Card d → Bool + +instance (d : ℕ) : Fintype (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +instance (d : ℕ) : Nonempty (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +def rotate (d : ℕ) : Equiv.Perm (Card d) where + toFun x i := x (finRotate d i) + invFun x i := x ((finRotate d).symm i) + left_inv x := by funext i; simp only [Equiv.apply_symm_apply] + right_inv x := by funext i; simp only [Equiv.symm_apply_apply] + +def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, ξ => rotate (d + 1) * pairSwitch ξ + +def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) + | 0, _ => 1 + | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) + +noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := + (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / + (Fintype.card (Fin t → Coins d) : ℝ) + +noncomputable def distance (d t : ℕ) : ℝ := + (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| + +noncomputable def mixingTime (d : ℕ) : ℕ := + sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} + +noncomputable def supportTimeBound (d : ℕ) : ℤ := + ⌈(2 / (2 : ℝ) ^ d) * + (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ + +def OptimalOrder : Prop := + ∃ C : ℕ, 0 < C ∧ + Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ + (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ + (∀ᶠ d : ℕ in atTop, + supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ + (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) + +noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by + classical + exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) + +lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : + ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by + classical + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : + 0 ≤ finiteLaw f b := by + exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : + ∑ b, finiteLaw f b = 1 := by + classical + simp only [finiteLaw, ← Finset.sum_div] + have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by + exact_mod_cast sum_card_fibers f + rw [hc] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by + classical + have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr + ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ + simp [finiteLaw] + +lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] + (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : + (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by + have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := + Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) + have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) + have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) + have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) + rw [hpq] at hz + rw [← Finset.sum_sub_distrib] + linarith + +lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] + [Fintype β] [Nonempty β] (f : α → β) : + 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ + (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by + classical + let s := Finset.univ.image f + have hs : ∑ b ∈ s, finiteLaw f b = 1 := by + have h := Finset.sum_subset (Finset.subset_univ s) + (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) + simpa only [finiteLaw_sum] using h + have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] + have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by + rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] + have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s + rw [hs] at he + have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by + simp [div_eq_mul_inv] + rw [hsq] at he + have hcard : (s.card : ℝ) ≤ Fintype.card α := by + exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) + have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) + linarith + +lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by + simp [Card] + +lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by + rw [Fintype.card_perm, card_positions] + +lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by + rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] + +lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : + law d t g = finiteLaw (run d t) g := by + unfold law finiteLaw + apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) + exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) + +lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by + rw [law_eq_finiteLaw] + exact finiteLaw_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by + simp only [law_eq_finiteLaw] + exact finiteLaw_sum (run d t) + +lemma physical_support_bound_succ (d t : ℕ) : + 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by + have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ + have h := finiteLaw_support_bound (run (d + 1) t) + rw [card_tapes_succ, card_permutations] at h + simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h + +lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : + step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by + change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ + rw [Fin.snoc_eq_cons_rotate] + rfl + +lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by + unfold distance + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + +lemma physical_support_bound (d t : ℕ) : + 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by + cases d with + | zero => + have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) + simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using + le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) + | succ d => + have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by + push_cast + rw [pow_succ] + ring + rw [he, Real.rpow_natCast] + exact physical_support_bound_succ d t + +lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : + supportTimeBound d ≤ (t : ℤ) := by + have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity + have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hb := physical_support_bound d t + have hp : (3 / 4 : ℝ) ≤ + (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by + linarith + have hr := (le_div_iff₀ hF).mp hp + have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr + rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog + unfold supportTimeBound + apply Int.ceil_le.mpr + simp only [Int.cast_natCast] + calc + 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = + Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by + field_simp + _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by + nlinarith [hlog]) + +lemma supportTimeBound_le_mixingTime {d : ℕ} + (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : + supportTimeBound d ≤ (mixingTime d : ℤ) := by + exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) + +lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : + (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by + have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) + have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) + have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by + have := Real.pi_gt_three + linarith) + linarith + +lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) + have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by + rw [← Real.log_inv] + congr 1 + norm_num + rw [he] at h + linarith + +lemma linear_le_supportTimeBound (d : ℕ) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by + have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) + have hNp : 0 < (2 : ℝ) ^ d := by positivity + have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) + have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + rw [Real.log_mul (by norm_num) (by positivity)] + push_cast at hf + rw [Real.log_pow] at hf + linarith [log_three_quarters_lower] + apply le_trans _ (Int.le_ceil _) + have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) = + (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by + field_simp + ring + rw [hcancel] + linarith + convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 + field_simp + +lemma linear_le_time_of_distance_le (d t : ℕ) + (ht : distance d t ≤ (1 / 4 : ℝ)) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by + have h := supportTimeBound_le_of_distance_le d t ht + have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h + exact (linear_le_supportTimeBound d).trans hr + +lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc := Real.strictConcave_binEntropy.concaveOn.2 + (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show 0 ≤ 1 - 2 * p by linarith) + (show 0 ≤ 2 * p by positivity) + (show (1 - 2 * p) + 2 * p = 1 by ring) + simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, + smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc + +lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + wlog hab : a ≤ b generalizing a b + · have hba := this b a hb ha (le_of_not_ge hab) + simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) + rw [min_eq_left hab] + by_cases hz : a = 0 + · subst a + simp + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) + have hbp : 0 < b := hap.trans_le hab + have hs : 0 < a + b := add_pos hap hbp + have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le + have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) + have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le + have he : (a + b) * Real.binEntropy (a / (a + b)) = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + unfold Real.binEntropy + rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] + simp only [Real.log_inv] + rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), + Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] + field_simp + ring + rw [he] at hc + calc + 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by + field_simp + _ ≤ _ := hc + +noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail + +lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by + classical + unfold childMarks + apply Finset.card_image_iff.mpr + intro x hx y hy hxy + have hx0 := (Finset.mem_filter.mp hx).2 + have hy0 := (Finset.mem_filter.mp hy).2 + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] + +lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : + (childMarks s false).card + (childMarks s true).card = s.card := by + classical + rw [card_childMarks, card_childMarks] + simpa only [Bool.not_eq_false] using + (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) + +noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) : Finset (Card d) := + ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ + ((childMarks s true).image (butterflyPerm d (b.2 true))) + +lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : + (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by + classical + apply le_min + · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) + · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) + +noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ + | 0, _, _ => 0 + | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card + +lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + induction d with + | zero => + simp only [encounters, Nat.cast_zero] + have hs : s.card ≤ 1 := by + simpa [Card] using Finset.card_le_univ s + interval_cases s.card <;> simp + | succ d ih => + have h₀ := ih (b.2 false) (childMarks s false) + have h₁ := ih (b.2 true) (childMarks s true) + have ht : ((topMeetings b s).card : ℝ) ≤ + min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by + exact_mod_cast card_topMeetings_le b s + have he := split_entropy_lower ((childMarks s false).card : ℝ) + ((childMarks s true).card : ℝ) (by positivity) (by positivity) + have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by + exact_mod_cast card_childMarks_add s + rw [hs] at he + have hL : 0 < 2 * Real.log 2 := by positivity + rw [le_div_iff₀ hL] at h₀ h₁ ⊢ + simp only [encounters, Nat.cast_add] + nlinarith [mul_le_mul_of_nonneg_right ht hL.le] + +lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by + by_cases ha : a ∈ s + · rw [ite_eq_left ha] + exact (Finset.mul_prod_erase s f ha).symm + · simp [ha] + +lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) + (a b : α) (hab : a ≠ b) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * + ∏ i ∈ (s.erase a).erase b, f i := by + calc + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := + prod_split_at s f a + _ = _ := by + rw [prod_split_at (s.erase a) f b] + have hm : (b ∈ s.erase a) ↔ b ∈ s := + ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ + simp only [hm, mul_assoc] + +lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ + ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by + by_cases hab : a = b + · subst b + simp only [Equiv.swap_self, Equiv.refl_apply] + have h : (fun i => (p i + p i) / 2) = p := by funext i; ring + rw [h] + linarith + let t := (s.erase a).erase b + have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by + intro i hi + exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) + have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) + rw [prod_split_two s p a b hab, + prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, + prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] + change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + + (if a ∈ s then p (Equiv.swap a b a) else 1) * + (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ + rw [hprod] + change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * + (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * + (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) + rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] + have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) + by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] + · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht + nlinarith + all_goals ring_nf; rfl + +def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := + ∀ s, m s ≤ ∏ i ∈ s, p i + +lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] + {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) + (fun i => (p i + p (Equiv.swap a b i)) / 2) := by + intro s + have h₀ := h s + have h₁ := h (s.image (Equiv.swap a b)) + rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ + exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans + (swap_average_product s p hp a b) + +noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : ℝ := by + classical + exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) + +lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by + classical + unfold inclusionMoment finiteMean + positivity + +lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : + (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by + by_cases h : s ⊆ A + · rw [ite_eq_left h] + exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm + · rw [ite_eq_right h] + obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h + exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm + +lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] + (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = + if s ⊆ A then 1 else 0 := by + classical + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] + +lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : + CylinderBound (inclusionMoment (fun _ : Ω => A)) + (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by + classical + intro s + simp only [inclusionMoment_const, Finset.singleton_subset_iff] + exact (indicator_subset_prod A s).le + +noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] + (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := + fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 + +lemma subset_swap_image_iff {α : Type*} [DecidableEq α] + (A s : Finset α) (a b : α) : + s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by + constructor + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + +lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) (s : Finset α) : + inclusionMoment (fairSetSwap F a b) s = + (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by + classical + simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, + fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, + Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] + rw [div_mul_eq_div_div, add_div] + ring_nf + +lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) + (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : + CylinderBound (inclusionMoment (fairSetSwap F a b)) + (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by + classical + have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b + intro s + simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s + +def SwitchSamples : ℕ → Type + | 0 => Unit + | n + 1 => SwitchSamples n × Bool + +instance (n : ℕ) : Fintype (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Fintype Unit) + | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) + +instance (n : ℕ) : Nonempty (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) + +noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : + (L : List (α × α)) → SwitchSamples L.length → Finset α + | [], _ => A + | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω + +lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) + (L : List (α × α)) : + CylinderBound (inclusionMoment (switchedSet A L)) + (fun i => inclusionMoment (switchedSet A L) {i}) := by + induction L with + | nil => exact cylinder_const A + | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih + +inductive QueryTree (ι : Type*) + | reject : QueryTree ι + | accept : QueryTree ι + | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι + | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι + +namespace QueryTree + +variable {ι : Type*} [DecidableEq ι] + +def queries : QueryTree ι → Finset ι + | reject => ∅ + | accept => ∅ + | branch i zero one => insert i (queries zero ∪ queries one) + | force i _ next => insert i (queries next) + +def Fresh : QueryTree ι → Prop + | reject => True + | accept => True + | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one + | force i _ next => i ∉ queries next ∧ Fresh next + +def weighted : QueryTree ι → (ι → Bool) → ℝ + | reject, _ => 0 + | accept, _ => 1 + | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω + | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 + +omit [DecidableEq ι] in +lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by + induction T with + | reject => exact le_rfl + | accept => exact zero_le_one + | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ + | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl + +lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} + (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by + induction T with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), + ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] + | force i b next ih => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] + +def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := + (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by + intro ω + funext j + by_cases h : j = i + · subst j; simp + · simp [Function.update_of_ne h]).toPerm + +lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by + change Function.update ω i (!(ω i)) i = _ + exact Function.update_self _ _ _ + +lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : + flipCoin i ω j = ω j := by + change Function.update ω i (!(ω i)) j = _ + exact Function.update_of_ne h _ _ + +lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) + (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by + apply weighted_congr + intro j hj + exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω + +lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) + (hf : ∀ ω, f (flipCoin i ω) = f ω) : + finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by + let g := fun ω : ι → Bool => if ω i = b then f ω else 0 + have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by + dsimp [g] + rw [flipCoin_apply_eq, hf] + cases hω : ω i <;> cases b <;> simp + have hs := Equiv.sum_comp (flipCoin i) g + have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun ω _ => hp ω) + unfold finiteMean + change (∑ ω, g ω) / _ = _ + rw [hs] at hadd + have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith + rw [hh] + ring + +lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : + finiteMean T.weighted ≤ 1 := by + induction T with + | reject => simp [weighted, finiteMean] + | accept => simp [weighted, finiteMean] + | branch i zero one ih₀ ih₁ => + obtain ⟨hz, ho, hfz, hfo⟩ := hT + have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) + have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) + have he : finiteMean (branch i zero one).weighted = + finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + + finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by + unfold finiteMean + rw [← add_div, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + cases hω : ω i <;> simp [weighted, hω] + rw [he, h₀, h₁] + linarith [ih₀ hfz, ih₁ hfo] + | force i b next ih => + obtain ⟨hi, hn⟩ := hT + have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) + have he : finiteMean (force i b next).weighted = + 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by + unfold finiteMean + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : ω i = b <;> simp [weighted, h] + rw [he, hm] + linarith [ih hn] + +def succeeds : QueryTree ι → (ι → Bool) → Bool + | reject, _ => false + | accept, _ => true + | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω + | force i b next, ω => if ω i = b then succeeds next ω else false + +def charge : QueryTree ι → (ι → Bool) → ℕ + | reject, _ => 0 + | accept, _ => 0 + | branch i zero one, ω => if ω i then charge one ω else charge zero ω + | force i b next, ω => if ω i = b then charge next ω + 1 else 0 + +omit [DecidableEq ι] in +lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : + T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by + induction T with + | reject => rfl + | accept => norm_num [weighted, succeeds, charge] + | branch i zero one ih₀ ih₁ => + cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] + | force i b next ih => + by_cases h : ω i = b + · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] + cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] + · simp [weighted, succeeds, h] + +lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) + (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : + finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by + have hw (ω : ι → Bool) : + (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by + rw [weighted_eq] + cases hs : T.succeeds ω + · simp + · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) + have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ + have hm := div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn + rw [← Finset.mul_sum, mul_div_assoc] at hm + change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ + finiteMean T.weighted at hm + exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by + rw [mul_comm] + exact hm.trans (mean_weighted_le_one T hT)) + +end QueryTree + +def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool + | 0, _, i => nomatch i + | _d + 1, b, Sum.inl y => b.1 y + | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i + +lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : + decodeButterfly d (encodeButterfly d b) = b := by + induction d with + | zero => exact Unit.ext _ _ + | succ d ih => + apply Prod.ext + · rfl + · funext ε + exact ih (b.2 ε) + +lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : + encodeButterfly d (decodeButterfly d ω) = ω := by + induction d with + | zero => funext i; exact Empty.elim i + | succ d ih => + funext i + cases i with + | inl y => rfl + | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 + +def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where + toFun := decodeButterfly d + invFun := encodeButterfly d + left_inv := encode_decodeButterfly d + right_inv := decode_encodeButterfly d + +noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) + | 0, _, _ => ∅ + | d + 1, x, y => by + classical + exact insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) + +def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool + | 0, _, _, i => nomatch i + | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) + | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/CutoffMass.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/CutoffMass.lean index 04ac1081b7e7b5e598082f585652a117c7a5cdaf..3aa2b96f09bcdf8898f2cc4cf82716c7fc872c00 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/CutoffMass.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/CutoffMass.lean @@ -1,862 +1,862 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.SandwichShuffle - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, ι, _, e, ω => - if d+1 ≤ H then crowdedMass (Fintype.card ι) else - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = palindromeCost d e ω := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLowCost,palindromeCost,ite_eq_left h] - congr 2 <;> exact ih (by omega) _ _ - -lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by - classical - induction d generalizing ι with - | zero => simp [palindromeLowCost,cutoffMass] - | succ d ih => - by_cases h : d+1 ≤ H - · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] - exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) - · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] - exact Nat.add_le_add (ih _ _) (ih _ _) - - -noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := - Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) - -lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : - x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by - classical - constructor - · intro h - obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h - simp only [Equiv.apply_symm_apply] - · intro h - apply Finset.mem_image.mpr - refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ - rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] - -lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by - classical - rw [centralBlock,Finset.card_image_of_injective] - · exact card_positions H - · intro x y h - exact congrArg Prod.snd ((cardSplit r H).symm.injective h) - -lemma centralBlock_disjoint (r H : ℕ) : - Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by - classical - intro b b' h - apply Finset.disjoint_left.mpr - intro x hx hy - exact h (((mem_centralBlock r H b x).mp hx).symm.trans - ((mem_centralBlock r H b' x).mp hy)) - -lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by - classical - ext x - simp only [mem_centralBlock,Finset.mem_univ,iff_true] - exact Subsingleton.elim _ _ - -lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : - centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by - classical - simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, - Fin.cons_zero,Fin.tail_cons,Function.comp_def] - -lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : - centralBlock (r+1) H (Fin.cons b c) ∩ A = - (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by - classical - rw [centralBlock_step] - ext x - constructor - · intro hx - obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB - exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, - (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ - -lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : - sparseMass (centralBlock 0 H) A = crowdedMass A.card := by - classical - simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, - Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] - -lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : - sparseMass (centralBlock (r+1) H) A = - sparseMass (centralBlock r H) (childMarks A false) + - sparseMass (centralBlock r H) (childMarks A true) := by - classical - unfold sparseMass - rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl - simp only [Fintype.sum_bool,ht] - have hc (b : Bool) (c : Card r) : - (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = - (centralBlock r H c ∩ childMarks A b).card := by - rw [block_inter_step] - apply Finset.card_image_of_injective - intro x y h - simpa only [Fin.tail_cons] using congrArg Fin.tail h - simp only [hc] - exact add_comm _ _ - - -lemma inverseButterfly_coordinates_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) - (x : Card (d+1)) : - headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = - (Bool.xor (x 0) (ξ (Fin.tail x)), - (butterflyPerm d (decodeButterfly d - (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by - rw [butterflyPerm_step] - rfl - -lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : - childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) - ((coinStepEquiv d).symm (c,ξ))) b = - inverseButterflyMarks d - (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) - (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by - classical - let x := e.trans (headTailEquiv d).toEmbedding - let col := PairRouting.colors x ξ - let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b - have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = - (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := - inverseButterfly_coordinates_step d c ξ (e i) - ext y - simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, - Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] - constructor - · rintro ⟨i,hi⟩ - have he := congrArg (headTailEquiv d) hi - rw [hp i] at he - change (col i,_) = (b,y) at he - have hb := congrArg Prod.fst he - have hy := congrArg Prod.snd he - dsimp only at hb hy - refine ⟨⟨i,hb⟩,?_⟩ - change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y - simpa only [hb] using hy - · rintro ⟨i,hi⟩ - refine ⟨i.val,?_⟩ - apply (headTailEquiv d).injective - rw [hp] - change (col i.val,_) = (b,y) - have hb : col i.val = b := i.property - rw [hb] - exact Prod.ext rfl hi - -lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : - (inverseButterflyMarks d A ω).card = A.card := by - classical - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective - -lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : - ω.2 = (coinStepEquiv d).symm - (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by - change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) - exact ((coinStepEquiv d).symm_apply_apply ω.2).symm - -lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : - cutoffMass H (H+r) e ω = - sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by - classical - induction r generalizing ι with - | zero => - rw [sparseMass_central_zero,inverseButterflyMarks_card, - Finset.card_image_of_injective _ e.injective,Finset.card_univ] - cases H with - | zero => - have hcard : Fintype.card ι ≤ 1 := by - have hh := Fintype.card_le_of_injective e e.injective - simpa only [Nat.add_zero,card_positions,pow_zero] using hh - simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] - | succ H => simp only [cutoffMass,le_refl,ite_true] - | succ r ih => - simp only [Nat.add_succ] at * - rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] - let σ := benesStepEquiv (H+r) ω - let x := e.trans (headTailEquiv (H+r)).toEmbedding - let col := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + - cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ - rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] - rw [inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - - -theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ - Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by - classical - have hec : (Finset.univ.image e).card = Fintype.card ι := by - rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] - have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) - (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) - (pow_nonneg (by linarith) _) (fun b => by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) - calc - _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by - apply finiteMean_mono - intro ω - rw [←pow_mul] - exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) - _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => - (q^H)^(sparseMass (centralBlock r H) - (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by - simp_rw [cutoffMass_central] - simp only [finiteMean_prod,finiteMean_const] - _ ≤ _ := by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, - Finset.card_univ,card_positions,nsmul_eq_mul] using hm - -variable {α B : Type*} {r s : ℕ} - -def parallelFreshPre (pre : α ≃ B × Card (s+r)) - (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := - ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans - (Equiv.prodCongrRight (fun b => - (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans - (Equiv.prodAssoc _ _ _).symm - -def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := - (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) - (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post - -def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := - fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 - -lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : - relabeledPerm pre post (parallelAssembled lo hi) = - relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by - ext x - have h := butterfly_split r s (lo (pre x).1) - (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 - have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h - simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, - Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, - Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, - Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh - -theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] - (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ - (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by - simp_rw [parallel_exposed_perm] - exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq - -end Thorp -namespace Thorp -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] - -lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Fintype.card_congr - refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ - invFun := fun C => ⟨C.val,?_,C.property.2⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ - -lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : - orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by - ext y - simp only [mem_orbitSet,Finset.mem_image] - rw [Equiv.Perm.sameCycle_conj] - change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y - rw [Equiv.symm_apply_apply] - constructor - · intro h - exact ⟨g.symm y,h,g.apply_symm_apply y⟩ - · rintro ⟨z,hz,rfl⟩ - simpa only [Equiv.symm_apply_apply] using hz - -noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) - (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by - refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ - -lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : - Function.Injective (conjugateCycle p g S) := by - intro C D he - apply Subtype.ext - exact (Finset.image_injective g.injective) (congrArg Subtype.val he) - -lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Nat.le_antisymm - · have h := Fintype.card_le_of_injective _ - (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) - have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group - rw [inv_inv,hp] at h - have hs : (S.image g).image g.symm = S := by - ext x - simp only [Finset.mem_image] - constructor - · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ - have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he - exact hz' ▸ hz - · intro hx - exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ - change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h - rw [hs] at h - exact h - · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) - -lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false)) := by - have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) - simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h - -lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle - ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = - Fintype.card (RoutingNetwork.SelectedCycle - (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by - let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) - calc - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) - (S.image X₀.symm)) := by - change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ - have h := (selectedCycle_conjugate p X₀⁻¹ S).symm - rw [inv_inv] at h - exact h - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ - (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm - _ = _ := by - have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group - rw [he] - -end Thorp -namespace Thorp - -noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := - Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) - -lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - 0 ≤ cycleCoefficient r J q := by - unfold cycleCoefficient - exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) - (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) - -lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] - (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by - have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) - (boolFiber (PairRouting.labelSet e) true) - rw [childJoin_boolFiber,PairRouting.card_labelSet] at h - omega - -theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient r J q) := by - classical - let S := boolFiber (PairRouting.labelSet e) false - let S' := S.image X₀.symm - let post := X₀⁻¹*X₁*Y₁⁻¹ - let count := fun hi : Card s × SwitchIndex r → Bool => - Fintype.card (RoutingNetwork.SelectedCycle - ((Equiv.refl _).trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') - have hpoint (hi : Card s × SwitchIndex r → Bool) : - PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by - refine (alternatingCycles_le_projection e _).trans_eq ?_ - simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] - change Fintype.card (RoutingNetwork.SelectedCycle - ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi - exact projectionCycles_forward X₀ X₁ _ Y₁ S - have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq - have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_pos (fun _ => pow_pos (by linarith) _) - have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ - Real.exp (S'.card * cycleCoefficient r J q) := by - rw [←Real.exp_log hp] - apply Real.exp_le_exp.mpr - calc - _ ≤ _ := hm - _ = _ := by unfold cycleCoefficient; ring - have hcard : S'.card ≤ Fintype.card ι := by - rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] - exact projectionSide_card_le e - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) - _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right - (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) - - -def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ - (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) where - toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), - fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) - invFun c := fun j => match j.2 with - | Sum.inl y => c.2 (j.1,y) - | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) - left_inv hi := by - funext j - rcases j with ⟨z,y|⟨b,i⟩⟩ - · rfl - · cases b <;> rfl - right_inv c := by - rcases c with ⟨⟨h₀,h₁⟩,η⟩ - rfl - -lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) - (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) : - assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = - (coinStepEquiv (s+r)).symm - ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, - assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), - fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - -noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (ξ η : Card d → Bool) : - palindromeLevelCost t (d+1) e - ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by - rw [palindromeLevelCost] - rfl - -lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] - - -theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - let χ := coinStepEquiv (s+r) X - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x χ.2 - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) - else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - palindromeLevelCost (s+u+1) (s+r+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] - rw [palindromeLevelCost_step] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] - congr 2 - funext b - cases b <;> rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' e₀ χ.1.1 lo₀ - have h₁ := ih u hu' e₁ χ.1.2 lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -def switchHeight : (d : ℕ) → SwitchIndex d → ℕ - | 0, i => nomatch i - | d+1, Sum.inl _ => d+1 - | d+1, Sum.inr (_,i) => switchHeight d i - -lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - rcases i with y | ⟨b,i⟩ - · exact le_refl _ - · exact (ih i).trans (Nat.le_succ d) - -def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := - ∀ i, switchHeight d i ≤ s → Y i = Y' i - -def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := - ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' - -lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} - (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := - fun i hi => hh i (hi.trans h) - -lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} - (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := - fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) - -lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} - (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := - fun Y Y' h => congrArg g (hf Y Y' h) - -lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) - (f : ι → (SwitchIndex d → Bool) → ℕ) - (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : - LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by - intro Y Y' h - exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) - -lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi hi' : Card s × SwitchIndex r → Bool) : - AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by - induction r with - | zero => intro i _; rfl - | succ r ih => - intro i h - rcases i with y | ⟨b,i⟩ - · have : s+r+1 ≤ s := h - omega - · exact ih (fun j => lo (Fin.cons b j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h - -lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by - classical - induction d generalizing ι with - | zero => intro Y Y' _; rfl - | succ d ih => - intro Y Y' h - change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step,palindromeLevelCost_step] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih - intro i hi - exact h (Sum.inr (true,i)) hi - -lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) - (hG : ∀ lo : Card r × SwitchIndex s → Bool, - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : - finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by - rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] - apply finiteMean_mono - intro lo - let H : Card s × SwitchIndex r → Bool := fun _ => false - have hh (hi : Card s × SwitchIndex r → Bool) : - F (assembleBits r s lo hi) = F (assembleBits r s lo H) := - hA _ _ (assembleBits_agree r s lo hi H) - simp_rw [hh,finiteMean_const] - rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = - (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by - funext hi; exact mul_comm _ _,finiteMean_mul_const] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) - - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/250) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by - have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) - have he := Real.exp_pos ((l:ℝ)/32) - have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h - exact_mod_cast this - - -lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] - (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : - q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by - have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = - (∑ i, z i:ℕ)*Real.log q := by - simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] - field_simp - have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) - rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he - simpa only [Real.exp_nat_mul,Real.exp_log hq] using he - -noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω - -lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact palindromeLevelCost_gt _ _ (by omega) _ _ - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.SandwichShuffle + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, ι, _, e, ω => + if d+1 ≤ H then crowdedMass (Fintype.card ι) else + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = palindromeCost d e ω := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLowCost,palindromeCost,ite_eq_left h] + congr 2 <;> exact ih (by omega) _ _ + +lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by + classical + induction d generalizing ι with + | zero => simp [palindromeLowCost,cutoffMass] + | succ d ih => + by_cases h : d+1 ≤ H + · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] + exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) + · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] + exact Nat.add_le_add (ih _ _) (ih _ _) + + +noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := + Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) + +lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : + x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by + classical + constructor + · intro h + obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h + simp only [Equiv.apply_symm_apply] + · intro h + apply Finset.mem_image.mpr + refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ + rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] + +lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by + classical + rw [centralBlock,Finset.card_image_of_injective] + · exact card_positions H + · intro x y h + exact congrArg Prod.snd ((cardSplit r H).symm.injective h) + +lemma centralBlock_disjoint (r H : ℕ) : + Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by + classical + intro b b' h + apply Finset.disjoint_left.mpr + intro x hx hy + exact h (((mem_centralBlock r H b x).mp hx).symm.trans + ((mem_centralBlock r H b' x).mp hy)) + +lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by + classical + ext x + simp only [mem_centralBlock,Finset.mem_univ,iff_true] + exact Subsingleton.elim _ _ + +lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : + centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by + classical + simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, + Fin.cons_zero,Fin.tail_cons,Function.comp_def] + +lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : + centralBlock (r+1) H (Fin.cons b c) ∩ A = + (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by + classical + rw [centralBlock_step] + ext x + constructor + · intro hx + obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB + exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, + (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ + +lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : + sparseMass (centralBlock 0 H) A = crowdedMass A.card := by + classical + simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, + Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] + +lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : + sparseMass (centralBlock (r+1) H) A = + sparseMass (centralBlock r H) (childMarks A false) + + sparseMass (centralBlock r H) (childMarks A true) := by + classical + unfold sparseMass + rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl + simp only [Fintype.sum_bool,ht] + have hc (b : Bool) (c : Card r) : + (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = + (centralBlock r H c ∩ childMarks A b).card := by + rw [block_inter_step] + apply Finset.card_image_of_injective + intro x y h + simpa only [Fin.tail_cons] using congrArg Fin.tail h + simp only [hc] + exact add_comm _ _ + + +lemma inverseButterfly_coordinates_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) + (x : Card (d+1)) : + headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = + (Bool.xor (x 0) (ξ (Fin.tail x)), + (butterflyPerm d (decodeButterfly d + (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by + rw [butterflyPerm_step] + rfl + +lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : + childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) + ((coinStepEquiv d).symm (c,ξ))) b = + inverseButterflyMarks d + (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) + (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by + classical + let x := e.trans (headTailEquiv d).toEmbedding + let col := PairRouting.colors x ξ + let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b + have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = + (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := + inverseButterfly_coordinates_step d c ξ (e i) + ext y + simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, + Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] + constructor + · rintro ⟨i,hi⟩ + have he := congrArg (headTailEquiv d) hi + rw [hp i] at he + change (col i,_) = (b,y) at he + have hb := congrArg Prod.fst he + have hy := congrArg Prod.snd he + dsimp only at hb hy + refine ⟨⟨i,hb⟩,?_⟩ + change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y + simpa only [hb] using hy + · rintro ⟨i,hi⟩ + refine ⟨i.val,?_⟩ + apply (headTailEquiv d).injective + rw [hp] + change (col i.val,_) = (b,y) + have hb : col i.val = b := i.property + rw [hb] + exact Prod.ext rfl hi + +lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : + (inverseButterflyMarks d A ω).card = A.card := by + classical + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective + +lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : + ω.2 = (coinStepEquiv d).symm + (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by + change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) + exact ((coinStepEquiv d).symm_apply_apply ω.2).symm + +lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : + cutoffMass H (H+r) e ω = + sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by + classical + induction r generalizing ι with + | zero => + rw [sparseMass_central_zero,inverseButterflyMarks_card, + Finset.card_image_of_injective _ e.injective,Finset.card_univ] + cases H with + | zero => + have hcard : Fintype.card ι ≤ 1 := by + have hh := Fintype.card_le_of_injective e e.injective + simpa only [Nat.add_zero,card_positions,pow_zero] using hh + simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] + | succ H => simp only [cutoffMass,le_refl,ite_true] + | succ r ih => + simp only [Nat.add_succ] at * + rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] + let σ := benesStepEquiv (H+r) ω + let x := e.trans (headTailEquiv (H+r)).toEmbedding + let col := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + + cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ + rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] + rw [inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + + +theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ + Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by + classical + have hec : (Finset.univ.image e).card = Fintype.card ι := by + rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] + have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) + (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) + (pow_nonneg (by linarith) _) (fun b => by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) + calc + _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by + apply finiteMean_mono + intro ω + rw [←pow_mul] + exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) + _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => + (q^H)^(sparseMass (centralBlock r H) + (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by + simp_rw [cutoffMass_central] + simp only [finiteMean_prod,finiteMean_const] + _ ≤ _ := by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, + Finset.card_univ,card_positions,nsmul_eq_mul] using hm + +variable {α B : Type*} {r s : ℕ} + +def parallelFreshPre (pre : α ≃ B × Card (s+r)) + (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := + ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans + (Equiv.prodCongrRight (fun b => + (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans + (Equiv.prodAssoc _ _ _).symm + +def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := + (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) + (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post + +def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := + fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 + +lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : + relabeledPerm pre post (parallelAssembled lo hi) = + relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by + ext x + have h := butterfly_split r s (lo (pre x).1) + (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 + have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h + simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, + Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, + Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, + Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh + +theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] + (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ + (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by + simp_rw [parallel_exposed_perm] + exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq + +end Thorp +namespace Thorp +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] + +lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Fintype.card_congr + refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ + invFun := fun C => ⟨C.val,?_,C.property.2⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ + +lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : + orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by + ext y + simp only [mem_orbitSet,Finset.mem_image] + rw [Equiv.Perm.sameCycle_conj] + change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y + rw [Equiv.symm_apply_apply] + constructor + · intro h + exact ⟨g.symm y,h,g.apply_symm_apply y⟩ + · rintro ⟨z,hz,rfl⟩ + simpa only [Equiv.symm_apply_apply] using hz + +noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) + (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by + refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ + +lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : + Function.Injective (conjugateCycle p g S) := by + intro C D he + apply Subtype.ext + exact (Finset.image_injective g.injective) (congrArg Subtype.val he) + +lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Nat.le_antisymm + · have h := Fintype.card_le_of_injective _ + (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) + have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group + rw [inv_inv,hp] at h + have hs : (S.image g).image g.symm = S := by + ext x + simp only [Finset.mem_image] + constructor + · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ + have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he + exact hz' ▸ hz + · intro hx + exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ + change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h + rw [hs] at h + exact h + · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) + +lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false)) := by + have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) + simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h + +lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle + ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = + Fintype.card (RoutingNetwork.SelectedCycle + (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by + let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) + calc + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) + (S.image X₀.symm)) := by + change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ + have h := (selectedCycle_conjugate p X₀⁻¹ S).symm + rw [inv_inv] at h + exact h + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ + (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm + _ = _ := by + have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group + rw [he] + +end Thorp +namespace Thorp + +noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := + Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) + +lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + 0 ≤ cycleCoefficient r J q := by + unfold cycleCoefficient + exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) + (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) + +lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by + have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) + (boolFiber (PairRouting.labelSet e) true) + rw [childJoin_boolFiber,PairRouting.card_labelSet] at h + omega + +theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient r J q) := by + classical + let S := boolFiber (PairRouting.labelSet e) false + let S' := S.image X₀.symm + let post := X₀⁻¹*X₁*Y₁⁻¹ + let count := fun hi : Card s × SwitchIndex r → Bool => + Fintype.card (RoutingNetwork.SelectedCycle + ((Equiv.refl _).trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') + have hpoint (hi : Card s × SwitchIndex r → Bool) : + PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by + refine (alternatingCycles_le_projection e _).trans_eq ?_ + simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] + change Fintype.card (RoutingNetwork.SelectedCycle + ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi + exact projectionCycles_forward X₀ X₁ _ Y₁ S + have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq + have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_pos (fun _ => pow_pos (by linarith) _) + have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ + Real.exp (S'.card * cycleCoefficient r J q) := by + rw [←Real.exp_log hp] + apply Real.exp_le_exp.mpr + calc + _ ≤ _ := hm + _ = _ := by unfold cycleCoefficient; ring + have hcard : S'.card ≤ Fintype.card ι := by + rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] + exact projectionSide_card_le e + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) + _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) + + +def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ + (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) where + toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), + fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) + invFun c := fun j => match j.2 with + | Sum.inl y => c.2 (j.1,y) + | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) + left_inv hi := by + funext j + rcases j with ⟨z,y|⟨b,i⟩⟩ + · rfl + · cases b <;> rfl + right_inv c := by + rcases c with ⟨⟨h₀,h₁⟩,η⟩ + rfl + +lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) + (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) : + assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = + (coinStepEquiv (s+r)).symm + ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, + assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), + fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + +noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (ξ η : Card d → Bool) : + palindromeLevelCost t (d+1) e + ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by + rw [palindromeLevelCost] + rfl + +lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] + + +theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + let χ := coinStepEquiv (s+r) X + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x χ.2 + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) + else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + palindromeLevelCost (s+u+1) (s+r+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] + rw [palindromeLevelCost_step] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] + congr 2 + funext b + cases b <;> rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' e₀ χ.1.1 lo₀ + have h₁ := ih u hu' e₁ χ.1.2 lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +def switchHeight : (d : ℕ) → SwitchIndex d → ℕ + | 0, i => nomatch i + | d+1, Sum.inl _ => d+1 + | d+1, Sum.inr (_,i) => switchHeight d i + +lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + rcases i with y | ⟨b,i⟩ + · exact le_refl _ + · exact (ih i).trans (Nat.le_succ d) + +def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := + ∀ i, switchHeight d i ≤ s → Y i = Y' i + +def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := + ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' + +lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} + (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := + fun i hi => hh i (hi.trans h) + +lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} + (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := + fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) + +lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} + (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := + fun Y Y' h => congrArg g (hf Y Y' h) + +lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) + (f : ι → (SwitchIndex d → Bool) → ℕ) + (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : + LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by + intro Y Y' h + exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) + +lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi hi' : Card s × SwitchIndex r → Bool) : + AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by + induction r with + | zero => intro i _; rfl + | succ r ih => + intro i h + rcases i with y | ⟨b,i⟩ + · have : s+r+1 ≤ s := h + omega + · exact ih (fun j => lo (Fin.cons b j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h + +lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by + classical + induction d generalizing ι with + | zero => intro Y Y' _; rfl + | succ d ih => + intro Y Y' h + change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step,palindromeLevelCost_step] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih + intro i hi + exact h (Sum.inr (true,i)) hi + +lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) + (hG : ∀ lo : Card r × SwitchIndex s → Bool, + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : + finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by + rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] + apply finiteMean_mono + intro lo + let H : Card s × SwitchIndex r → Bool := fun _ => false + have hh (hi : Card s × SwitchIndex r → Bool) : + F (assembleBits r s lo hi) = F (assembleBits r s lo H) := + hA _ _ (assembleBits_agree r s lo hi H) + simp_rw [hh,finiteMean_const] + rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = + (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by + funext hi; exact mul_comm _ _,finiteMean_mul_const] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) + + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/250) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by + have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) + have he := Real.exp_pos ((l:ℝ)/32) + have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h + exact_mod_cast this + + +lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] + (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : + q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = + (∑ i, z i:ℕ)*Real.log q := by + simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] + field_simp + have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) + rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he + simpa only [Real.exp_nat_mul,Real.exp_log hq] using he + +noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω + +lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact palindromeLevelCost_gt _ _ (by omega) _ _ + +lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/ExposedCoins.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/ExposedCoins.lean index 0e6119cbee9094f78bf87034309919e42e58ccc2..5e828b5a5ec55777a656ccb21d325be4aa71ddc0 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/ExposedCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/ExposedCoins.lean @@ -1,860 +1,860 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.Coins - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter - -lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by - classical - induction d with - | zero => rfl - | succ d ih => - change (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 - rw [Finset.card_insert_of_notMem (by simp)] - rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] - -lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by - cases a <;> cases b <;> cases c <;> decide - -lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : - butterflyPerm d (decodeButterfly d ω) x = y ↔ - ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by - classical - induction d with - | zero => - have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ - simp [he, routeDomain] - | succ d ih => - let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) - change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ - have hv : v = Fin.tail y ↔ - ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), - ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := - ih _ _ _ - constructor - · intro h i hi - have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h - have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by - have he := congrFun h 0 - simp only [Fin.cons_zero, ht] at he - exact (xor_eq_iff _ _ _).mp he - rcases Finset.mem_insert.mp hi with htop | hchild - · subst i - exact hh - · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild - exact hv.mp ht j hj - · intro h - have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) - have ht : v = Fin.tail y := hv.mpr (fun i hi => - h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) - have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := - (xor_eq_iff _ _ _).mpr hh - rw [ht, hh', Fin.cons_self_tail] - -lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by - unfold finiteMean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) : - finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = - 1 / (2 : ℝ) ^ s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 - have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - dsimp [f] - simp only [he] - have hm := QueryTree.mean_indicator_bit f i (v i) hf - have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = - (fun ω => if ω i = v i then f ω else 0) := by - funext ω - by_cases h : ω i = v i <;> simp [f, h] - rw [he, hm] - change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ - rw [ih, Finset.card_insert_of_notMem hi, pow_succ] - ring - -def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := - fun i => if i ∈ R then η i else ω i - -lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] - (s R : Finset ι) (v η : ι → Bool) : - finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by - have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ - (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by - constructor - · intro h - constructor - · intro i hi - simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 - · intro i hi - simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 - · rintro ⟨ho, hf⟩ i hi - by_cases hR : i ∈ R - · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) - · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) - have hm : finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - finiteMean (fun ω : ι → Bool => - if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [he ω]) - rw [hm] - by_cases h : ∀ i ∈ s ∩ R, η i = v i - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h - simp only [hp, true_and, ↓reduceIte] - exact mean_coinCylinder (s \ R) v - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h - simp only [hp, false_and, ↓reduceIte] - simp [finiteMean] - -lemma butterfly_closure_probability (d : ℕ) (x y : Card d) - (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then - (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder_exposed] - congr 1 - have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter, card_routeDomain] - have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * - (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by - rw [← pow_add] - exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm - rw [hp] - have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) - field_simp - -lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder, card_routeDomain] - -def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d - | 0, _, i => nomatch i - | d + 1, b, Sum.inl y => - (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), - Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) - | d + 1, b, Sum.inr (ε,i) => - (Fin.cons ε (switchUsers d (b.2 ε) i).1, - Fin.cons ε (switchUsers d (b.2 ε) i).2) - -lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : - (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - intro h - have := congrFun h 0 - simp only [switchUsers, Fin.cons_zero] at this - exact Bool.false_ne_true this - | inr z => - intro h - exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) - -lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : - Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by - constructor - · intro h - exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, - by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ - · rintro ⟨rfl,rfl⟩ - exact Fin.cons_self_tail x - -lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : - i ∈ routeDomain d x (butterflyPerm d b x) ↔ - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by - classical - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, - Sum.inr_ne_inl, and_false, exists_false, or_false] - change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ - simp only [switchUsers, cons_eq_iff] - cases x 0 <;> simp [Equiv.symm_apply_eq] - | inr z => - obtain ⟨ε,i⟩ := z - change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, - Sum.inr.injEq, Prod.mk.injEq] - change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ - x 0 = ε ∧ j = i) ↔ _ - simp only [switchUsers, cons_eq_iff] - constructor - · rintro ⟨j,hj,hε,rfl⟩ - subst ε - rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h - · exact Or.inl ⟨rfl,h⟩ - · exact Or.inr ⟨rfl,h⟩ - · rintro (⟨hε,h⟩ | ⟨hε,h⟩) - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ - -lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : - (Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - routeDomain d x (butterflyPerm d b x) := by - ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] - rw [he,card_routeDomain] - -lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = - (d : ℝ) * ∑ x : Card d, w x := by - classical - calc - _ = ∑ i : SwitchIndex d, ∑ x : Card d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : Card d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - {(switchUsers d b i).1, (switchUsers d b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (switchUsers_ne d b i)] - _ = ∑ x : Card d, ∑ i : SwitchIndex d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : Card d, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ - (d : ℝ) / 2 * ∑ x : Card d, w x := by - have h : 2 * (∑ i : SwitchIndex d, - min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), - min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] - rw [switch_incidence_sum] at h - linarith - -lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : - x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by - classical - constructor - · intro h - obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy - rw [← hxy, ← hyε, Fin.cons_self_tail] - exact hys - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons ε x, - Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ - -lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) (y : Card d) : - y ∈ topMeetings b s ↔ - (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by - classical - have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ - (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by - constructor - · intro h - obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h - simpa only [Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ - simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] - -lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - encounters d b s = ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by - classical - induction d with - | zero => - simp only [encounters] - symm - apply Finset.sum_eq_zero - intro i _ - exact Empty.elim i - | succ d ih => - change encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = - ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ - rw [Fintype.sum_sum_type, Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [ih,ih] - have ht : (∑ y : Card d, - if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = - (topMeetings b s).card := by - simp only [← mem_topMeetings] - simp - rw [ht] - simp only [mem_childMarks, switchUsers] - ac_rfl - -lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ - (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - classical - have he : (encounters d b s : ℝ) = - ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by - rw [encounters_eq_switch_sum, Nat.cast_sum] - apply Finset.sum_congr rfl - intro i _ - split_ifs <;> simp - rw [← he] - exact butterfly_encounters d b s - -namespace QueryTree -variable {ι : Type*} [DecidableEq ι] - -def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι - | reject, _, _ => reject - | accept, _, _ => accept - | branch i zero one, R, η => - if i ∈ R then (if η i then memo one R η else memo zero R η) else - branch i (memo zero (insert i R) (Function.update η i false)) - (memo one (insert i R) (Function.update η i true)) - | force i b next, R, η => - if i ∈ R then (if η i = b then memo next R η else reject) else - force i b (memo next (insert i R) (Function.update η i b)) - -lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - Disjoint (memo T R η).queries R := by - induction T generalizing R η with - | reject => simp [memo,queries] - | accept => simp [memo,queries] - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] - exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), - (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,queries] - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] - exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - -lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - (memo T R η).Fresh := by - induction T generalizing R η with - | reject => trivial - | accept => trivial - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm - (Finset.mem_insert_self _ _), - fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm - (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,Fresh] - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm - (Finset.mem_insert_self _ _),ih _ _⟩ - -lemma update_agrees {R : Finset ι} {η ω : ι → Bool} - (h : ∀ i ∈ R, η i = ω i) (i : ι) : - ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by - intro j hj - rcases Finset.mem_insert.mp hj with rfl | hj - · simp - · by_cases hji : j = i - · subst j; simp - · rw [Function.update_of_ne hji] - exact h j hj - -lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,succeeds,h i hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,succeeds] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte,succeeds] - exact ih R η h - · simp [hb,succeeds] - · simp only [memo,hi,↓reduceIte,succeeds] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih _ _ (by simpa only [hb] using update_agrees h i) - · simp [hb] - -def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 - -lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih R η h - · simp [hb,charge] - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - rw [ih _ _ (by simpa only [hb] using update_agrees h i)] - · simp [hb] - -lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by - let η : ι → Bool := fun _ => false - have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) - have he : finiteMean (memo T ∅ η).weighted = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] - rw [he] at hm - exact hm - - -def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → - (Card d → QueryTree ι) → QueryTree ι - | 0, _, x, k => k x - | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) - (fun y => branch (e (Sum.inl y)) - (k (Fin.cons (Bool.xor (x 0) false) y)) - (k (Fin.cons (Bool.xor (x 0) true) y))) - -omit [DecidableEq ι] in -lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).succeeds ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω - cases ω (e (Sum.inl y)) <;> rfl - -lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - freshCharge (followPath d e x k) R ω = - freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - classical - induction d generalizing R with - | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) - change (if ω (e (Sum.inl y)) then - freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else - freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = - freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) - (R ∪ (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω - have hs : (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = - insert (e (Sum.inl y)) S := by - let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e - change (insert (Sum.inl y) - ((routeDomain d (Fin.tail x) y).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ - rw [Finset.image_insert, Finset.image_image] - rfl - rw [hs,Finset.union_insert] - cases ω (e (Sum.inl y)) <;> rfl - -def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι - | [], _, k => k - | i :: L, v, k => force i (v i) (forceList L v k) - -omit [DecidableEq ι] in -lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : - (forceList L v k).succeeds ω = - if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by - induction L with - | nil => simp [forceList] - | cons i L ih => - simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] - by_cases h : ω i = v i <;> simp [h] - -lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) - (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : - freshCharge (forceList L v k) R ω = - freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by - induction L generalizing R with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), - ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.toFinset_cons] - have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp - rw [hs] - by_cases hi : i ∈ R - · rw [ite_eq_left hi] - have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he,Nat.add_zero] - · rw [ite_eq_right hi] - have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he, Finset.card_insert_of_notMem (by simp)] - omega - - -def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω - else staleCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 - -lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by - induction T generalizing R with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] - | force i b next ih => - by_cases hb : ω i = b - · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] - have he := ih (insert i R) - by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega - · simp [freshCharge,staleCharge,charge,hb] - -omit [DecidableEq ι] in -lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).charge ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω - cases ω (e (Sum.inl y)) <;> rfl - -omit [DecidableEq ι] in -lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) - (h : ∀ i ∈ L, ω i = v i) : - (forceList L v k).charge ω = k.charge ω + L.length := by - induction L with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), - ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.length_cons,Nat.add_assoc] - -noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : - QueryTree (SwitchIndex d) := - forceList (routeDomain d x y).toList (routeValue d x y) k - -lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) : - (closePath d x y k).succeeds ω = - if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by - unfold closePath - rw [forceList_succeeds] - simp only [Finset.mem_toList, ← butterfly_endpoint_iff] - -lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).charge ω = k.charge ω + d := by - unfold closePath - rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] - -lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).freshCharge R ω = - k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by - unfold closePath - rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] - -lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).staleCharge R ω = - k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by - have h₀ := fresh_add_stale (closePath d x y k) R ω - have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω - rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ - have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_routeDomain] - omega - -noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : - ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → - QueryTree (SwitchIndex d) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x - (fun y => seekCycle d S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle d S a r x V k).succeeds ω = true) : - (seekCycle d S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs - rw [seekCycle,ite_eq_left hv,followPath_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,succeeds] at hs - -noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : - List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) - | [], _ => accept - | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) - -lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) - (V : Finset (Card d)) (ω : SwitchIndex d → Bool) - (hs : (seekCycles d S L V).succeeds ω = true) : - (seekCycles d S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : - finiteMean (fun ω : SwitchIndex d → Bool => - if (seekCycles d S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles d S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge d S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree - -lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by - simp only [finiteMean,Finset.sum_add_distrib,add_div] - -lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : - finiteMean (fun ω => f ω * c) = finiteMean f * c := by - unfold finiteMean - rw [← Finset.sum_mul] - ring - -lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : - finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by - simp only [finiteMean,Finset.sum_div] - exact Finset.sum_comm - -lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω → ℝ) : - finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by - unfold finiteMean - rw [Fintype.card_congr e] - congr 1 - exact Fintype.sum_equiv e _ _ (fun ω => by simp) - -lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] - (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by - simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, - ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] - have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - field_simp - -lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] - {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] - (c : C) (g : A c → ℝ) : - finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by - rw [finiteMean_equiv (Equiv.piSplitAt c A)] - have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => - g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by - funext z - simp [Equiv.piSplitAt] - rw [he,finiteMean_prod_left] - -lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : - finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by - simp [finiteMean] - -lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] - have hj := convexOn_exp.map_sum_le (t := Finset.univ) - (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) - (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) - simp only [smul_eq_mul, ← Finset.mul_sum] at hj - simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj - -variable {d A : ℕ} - -def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} - -noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.Coins + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter + +lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by + classical + induction d with + | zero => rfl + | succ d ih => + change (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 + rw [Finset.card_insert_of_notMem (by simp)] + rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] + +lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by + cases a <;> cases b <;> cases c <;> decide + +lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : + butterflyPerm d (decodeButterfly d ω) x = y ↔ + ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by + classical + induction d with + | zero => + have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ + simp [he, routeDomain] + | succ d ih => + let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) + change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ + have hv : v = Fin.tail y ↔ + ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), + ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := + ih _ _ _ + constructor + · intro h i hi + have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h + have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by + have he := congrFun h 0 + simp only [Fin.cons_zero, ht] at he + exact (xor_eq_iff _ _ _).mp he + rcases Finset.mem_insert.mp hi with htop | hchild + · subst i + exact hh + · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild + exact hv.mp ht j hj + · intro h + have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) + have ht : v = Fin.tail y := hv.mpr (fun i hi => + h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) + have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := + (xor_eq_iff _ _ _).mpr hh + rw [ht, hh', Fin.cons_self_tail] + +lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by + unfold finiteMean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) : + finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = + 1 / (2 : ℝ) ^ s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 + have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + dsimp [f] + simp only [he] + have hm := QueryTree.mean_indicator_bit f i (v i) hf + have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = + (fun ω => if ω i = v i then f ω else 0) := by + funext ω + by_cases h : ω i = v i <;> simp [f, h] + rw [he, hm] + change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ + rw [ih, Finset.card_insert_of_notMem hi, pow_succ] + ring + +def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := + fun i => if i ∈ R then η i else ω i + +lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] + (s R : Finset ι) (v η : ι → Bool) : + finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by + have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ + (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by + constructor + · intro h + constructor + · intro i hi + simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 + · intro i hi + simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 + · rintro ⟨ho, hf⟩ i hi + by_cases hR : i ∈ R + · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) + · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) + have hm : finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + finiteMean (fun ω : ι → Bool => + if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [he ω]) + rw [hm] + by_cases h : ∀ i ∈ s ∩ R, η i = v i + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h + simp only [hp, true_and, ↓reduceIte] + exact mean_coinCylinder (s \ R) v + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h + simp only [hp, false_and, ↓reduceIte] + simp [finiteMean] + +lemma butterfly_closure_probability (d : ℕ) (x y : Card d) + (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then + (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder_exposed] + congr 1 + have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter, card_routeDomain] + have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * + (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by + rw [← pow_add] + exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm + rw [hp] + have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) + field_simp + +lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder, card_routeDomain] + +def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d + | 0, _, i => nomatch i + | d + 1, b, Sum.inl y => + (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), + Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) + | d + 1, b, Sum.inr (ε,i) => + (Fin.cons ε (switchUsers d (b.2 ε) i).1, + Fin.cons ε (switchUsers d (b.2 ε) i).2) + +lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : + (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + intro h + have := congrFun h 0 + simp only [switchUsers, Fin.cons_zero] at this + exact Bool.false_ne_true this + | inr z => + intro h + exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) + +lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : + Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by + constructor + · intro h + exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, + by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ + · rintro ⟨rfl,rfl⟩ + exact Fin.cons_self_tail x + +lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : + i ∈ routeDomain d x (butterflyPerm d b x) ↔ + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by + classical + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, + Sum.inr_ne_inl, and_false, exists_false, or_false] + change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ + simp only [switchUsers, cons_eq_iff] + cases x 0 <;> simp [Equiv.symm_apply_eq] + | inr z => + obtain ⟨ε,i⟩ := z + change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, + Sum.inr.injEq, Prod.mk.injEq] + change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ + x 0 = ε ∧ j = i) ↔ _ + simp only [switchUsers, cons_eq_iff] + constructor + · rintro ⟨j,hj,hε,rfl⟩ + subst ε + rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h + · exact Or.inl ⟨rfl,h⟩ + · exact Or.inr ⟨rfl,h⟩ + · rintro (⟨hε,h⟩ | ⟨hε,h⟩) + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ + +lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : + (Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + routeDomain d x (butterflyPerm d b x) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] + rw [he,card_routeDomain] + +lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = + (d : ℝ) * ∑ x : Card d, w x := by + classical + calc + _ = ∑ i : SwitchIndex d, ∑ x : Card d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : Card d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + {(switchUsers d b i).1, (switchUsers d b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (switchUsers_ne d b i)] + _ = ∑ x : Card d, ∑ i : SwitchIndex d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : Card d, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ + (d : ℝ) / 2 * ∑ x : Card d, w x := by + have h : 2 * (∑ i : SwitchIndex d, + min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), + min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] + rw [switch_incidence_sum] at h + linarith + +lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : + x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by + classical + constructor + · intro h + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy + rw [← hxy, ← hyε, Fin.cons_self_tail] + exact hys + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons ε x, + Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ + +lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) (y : Card d) : + y ∈ topMeetings b s ↔ + (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by + classical + have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ + (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by + constructor + · intro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + simpa only [Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ + simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] + +lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + encounters d b s = ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by + classical + induction d with + | zero => + simp only [encounters] + symm + apply Finset.sum_eq_zero + intro i _ + exact Empty.elim i + | succ d ih => + change encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = + ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ + rw [Fintype.sum_sum_type, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [ih,ih] + have ht : (∑ y : Card d, + if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = + (topMeetings b s).card := by + simp only [← mem_topMeetings] + simp + rw [ht] + simp only [mem_childMarks, switchUsers] + ac_rfl + +lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ + (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + classical + have he : (encounters d b s : ℝ) = + ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by + rw [encounters_eq_switch_sum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + rw [← he] + exact butterfly_encounters d b s + +namespace QueryTree +variable {ι : Type*} [DecidableEq ι] + +def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι + | reject, _, _ => reject + | accept, _, _ => accept + | branch i zero one, R, η => + if i ∈ R then (if η i then memo one R η else memo zero R η) else + branch i (memo zero (insert i R) (Function.update η i false)) + (memo one (insert i R) (Function.update η i true)) + | force i b next, R, η => + if i ∈ R then (if η i = b then memo next R η else reject) else + force i b (memo next (insert i R) (Function.update η i b)) + +lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + Disjoint (memo T R η).queries R := by + induction T generalizing R η with + | reject => simp [memo,queries] + | accept => simp [memo,queries] + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] + exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), + (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,queries] + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] + exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + +lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + (memo T R η).Fresh := by + induction T generalizing R η with + | reject => trivial + | accept => trivial + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm + (Finset.mem_insert_self _ _), + fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm + (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,Fresh] + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm + (Finset.mem_insert_self _ _),ih _ _⟩ + +lemma update_agrees {R : Finset ι} {η ω : ι → Bool} + (h : ∀ i ∈ R, η i = ω i) (i : ι) : + ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by + intro j hj + rcases Finset.mem_insert.mp hj with rfl | hj + · simp + · by_cases hji : j = i + · subst j; simp + · rw [Function.update_of_ne hji] + exact h j hj + +lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,succeeds,h i hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,succeeds] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte,succeeds] + exact ih R η h + · simp [hb,succeeds] + · simp only [memo,hi,↓reduceIte,succeeds] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih _ _ (by simpa only [hb] using update_agrees h i) + · simp [hb] + +def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 + +lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih R η h + · simp [hb,charge] + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + rw [ih _ _ (by simpa only [hb] using update_agrees h i)] + · simp [hb] + +lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by + let η : ι → Bool := fun _ => false + have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) + have he : finiteMean (memo T ∅ η).weighted = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] + rw [he] at hm + exact hm + + +def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → + (Card d → QueryTree ι) → QueryTree ι + | 0, _, x, k => k x + | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) + (fun y => branch (e (Sum.inl y)) + (k (Fin.cons (Bool.xor (x 0) false) y)) + (k (Fin.cons (Bool.xor (x 0) true) y))) + +omit [DecidableEq ι] in +lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).succeeds ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω + cases ω (e (Sum.inl y)) <;> rfl + +lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + freshCharge (followPath d e x k) R ω = + freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + classical + induction d generalizing R with + | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) + change (if ω (e (Sum.inl y)) then + freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else + freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = + freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) + (R ∪ (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω + have hs : (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = + insert (e (Sum.inl y)) S := by + let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e + change (insert (Sum.inl y) + ((routeDomain d (Fin.tail x) y).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ + rw [Finset.image_insert, Finset.image_image] + rfl + rw [hs,Finset.union_insert] + cases ω (e (Sum.inl y)) <;> rfl + +def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι + | [], _, k => k + | i :: L, v, k => force i (v i) (forceList L v k) + +omit [DecidableEq ι] in +lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : + (forceList L v k).succeeds ω = + if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by + induction L with + | nil => simp [forceList] + | cons i L ih => + simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] + by_cases h : ω i = v i <;> simp [h] + +lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) + (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : + freshCharge (forceList L v k) R ω = + freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by + induction L generalizing R with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), + ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.toFinset_cons] + have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp + rw [hs] + by_cases hi : i ∈ R + · rw [ite_eq_left hi] + have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he,Nat.add_zero] + · rw [ite_eq_right hi] + have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he, Finset.card_insert_of_notMem (by simp)] + omega + + +def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω + else staleCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 + +lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by + induction T generalizing R with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] + | force i b next ih => + by_cases hb : ω i = b + · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] + have he := ih (insert i R) + by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega + · simp [freshCharge,staleCharge,charge,hb] + +omit [DecidableEq ι] in +lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).charge ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω + cases ω (e (Sum.inl y)) <;> rfl + +omit [DecidableEq ι] in +lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) + (h : ∀ i ∈ L, ω i = v i) : + (forceList L v k).charge ω = k.charge ω + L.length := by + induction L with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), + ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.length_cons,Nat.add_assoc] + +noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : + QueryTree (SwitchIndex d) := + forceList (routeDomain d x y).toList (routeValue d x y) k + +lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) : + (closePath d x y k).succeeds ω = + if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by + unfold closePath + rw [forceList_succeeds] + simp only [Finset.mem_toList, ← butterfly_endpoint_iff] + +lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).charge ω = k.charge ω + d := by + unfold closePath + rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] + +lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).freshCharge R ω = + k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by + unfold closePath + rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] + +lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).staleCharge R ω = + k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by + have h₀ := fresh_add_stale (closePath d x y k) R ω + have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω + rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ + have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_routeDomain] + omega + +noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : + ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → + QueryTree (SwitchIndex d) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x + (fun y => seekCycle d S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle d S a r x V k).succeeds ω = true) : + (seekCycle d S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs + rw [seekCycle,ite_eq_left hv,followPath_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,succeeds] at hs + +noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : + List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) + | [], _ => accept + | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) + +lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) + (V : Finset (Card d)) (ω : SwitchIndex d → Bool) + (hs : (seekCycles d S L V).succeeds ω = true) : + (seekCycles d S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : + finiteMean (fun ω : SwitchIndex d → Bool => + if (seekCycles d S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles d S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge d S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree + +lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by + simp only [finiteMean,Finset.sum_add_distrib,add_div] + +lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : + finiteMean (fun ω => f ω * c) = finiteMean f * c := by + unfold finiteMean + rw [← Finset.sum_mul] + ring + +lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : + finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by + simp only [finiteMean,Finset.sum_div] + exact Finset.sum_comm + +lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω → ℝ) : + finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by + unfold finiteMean + rw [Fintype.card_congr e] + congr 1 + exact Fintype.sum_equiv e _ _ (fun ω => by simp) + +lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] + (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by + simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, + ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] + have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + field_simp + +lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] + {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] + (c : C) (g : A c → ℝ) : + finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by + rw [finiteMean_equiv (Equiv.piSplitAt c A)] + have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => + g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by + funext z + simp [Equiv.piSplitAt] + rw [he,finiteMean_prod_left] + +lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : + finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by + simp [finiteMean] + +lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] + have hj := convexOn_exp.map_sum_le (t := Finset.univ) + (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) + (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul, ← Finset.mul_sum] at hj + simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj + +variable {d A : ℕ} + +def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} + +noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/InputTree.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/InputTree.lean index 376ba4ed80bacfa7377fe34235f4d989b18f7e8f..9d0536b69a9b583a2542e2c10c2fb39df021b1cd 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/InputTree.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/InputTree.lean @@ -1,869 +1,869 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.PalindromeFamilyCost - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - centralLevelCost_perturb (l+i.val+1) L r C D e ω) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh - -lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : - centralDistance L r C D ≤ E.card*2^L := by - classical - calc - _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by - apply Finset.sum_le_sum - intro u _ - split_ifs with hu - · simpa only [card_positions] using permDistance_le (C u) (D u) - · rw [h u hu,permDistance_refl] - _ = _ := by simp - - -inductive InputTree : ℕ → Type - | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d - | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) - -def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) - | _, .tip p => p - | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) - -noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → - {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ - | _, .tip _, _, _, _, _ => 0 - | d+1, .node ξ T, _, _, e, Y => - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let σ := coinStepEquiv d Y - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) - (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : - (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by - rw [InputTree.levelCost] - rfl - -lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - T.levelCost t e Y = 0 := by - induction T generalizing ι with - | tip p => rfl - | @node d ξ T ih => - rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] - -lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by - induction T generalizing ι with - | tip p => intro Y Y' _; rfl - | @node d ξ T ih => - intro Y Y' h - dsimp only - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] - rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), - InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih false - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih true - intro i hi - exact h (Sum.inr (true,i)) hi - -theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) - (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - cases T with - | tip p => - simp only [InputTree.levelCost,pow_zero,finiteMean_const] - exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) - | node ξ T => - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x ξ - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => - if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ - else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - (T false).levelCost (s+u+1) e₀ (Y₀ hi) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - (T true).levelCost (s+u+1) e₁ (Y₁ hi) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - (InputTree.node ξ T).levelCost (s+u+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' (T false).perm (T true).perm - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' (T false) e₀ lo₀ - have h₁ := ih u hu' (T true) e₁ lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i : Fin l, T.levelCost (l+i.1+1) e Y - -lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) - -theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)))) := by - apply finiteMean_mono - intro hi - simpa only [InputTree.slabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - (SwitchIndex (L+r) → Bool) → InputTree (L+r) - | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) - | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => - boundaryTree L r (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) - -def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → - Card r → Equiv.Perm (Card L) - | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) - | r+1, Y, u => boundaryOutput L r - (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) - -lemma boundaryOutput_adapted (L r : ℕ) : - LayerAdapted (L+r) L (boundaryOutput L r) := by - induction r with - | zero => - intro Y Y' h - have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) - rw [he] - | succ r ih => - intro Y Y' h - funext u - dsimp only [boundaryOutput] - cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) - -noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u - -lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) : - LayerAdapted (L+r) L (modifiedBoundary L r E U) := by - intro Y Y' h - unfold modifiedBoundary - rw [boundaryOutput_adapted L r Y Y' h] - -lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) : - permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = - centralDistance L r U V := by - induction r with - | zero => - simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - simp only [boundaryTree,InputTree.perm,permDistance_mul_left] - rw [permDistance_childLift,centralDistance_step,ih,ih] - -lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y ≤ - (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by - induction r generalizing ι with - | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] - by_cases ht : t = L+r+1 - · simp only [ite_eq_left ht] - have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (coinStepEquiv (L+r) X).2) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, - permDistance_boundaryTree,←centralDistance_step] using hh - · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] - rw [centralDistance_step] - have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) - (coinStepEquiv (L+r) X).1.1 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 - have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) - (coinStepEquiv (L+r) X).1.2 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 - omega - -lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh - -lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by - apply centralDistance_exceptional - intro u hu - exact ite_eq_right hu - - -lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.slabCost l d T e Y = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact InputTree.levelCost_gt _ _ T (by omega) _ _ - -lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - apply adapted_mul_mean_le r s F _ hF hA - intro lo - let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false - have he (hi : Card s × SwitchIndex r → Bool) : - T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := - hT _ _ (assembleBits_agree r s lo hi hi₀) - simp_rw [he] - exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog - -lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) - (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) - (fun _ _ _ => rfl) q hq hlog - simpa only [one_mul,finiteMean_const] using hh - -noncomputable def InputTree.familyCost (L n d : ℕ) - (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y - -lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by - intro Y Y' h - dsimp only - rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] - exact InputTree.slabCost_adapted l d (T Y') e Y Y' - (agreeThrough_mono (le_max_right _ _) h) - -lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) - (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) - -theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => - simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,add_zero] - exact Real.one_le_exp hp - | succ n ih => - by_cases hn : n = 0 - · subst n - simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst - · let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n - have hs' : s ≤ familyEnd L n := by - have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) - simp only [pow_zero,mul_one] at hh - omega - have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = - InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T - (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) - · apply layerAdapted_comp - exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) - · exact hq - · exact hlog - · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp only [l] - ring - -lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*heightDecay L) := by - apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans - apply Real.exp_le_exp.mpr - apply add_le_add_right - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using hh - - -noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := - boundaryTree L r (modifiedBoundary L r E U Y) X - -lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : - LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by - intro Y Y' h - unfold modifiedInputTree - rw [modifiedBoundary_adapted L r E U Y Y' h] - -lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ - Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - have hqp : 0 < q := by linarith - have hpoint (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by - apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans - apply Nat.add_le_add_left - simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) - calc - _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := - finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) - _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * - q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ - _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := - mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) - _ = _ := by - have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by - rw [Real.exp_nat_mul,Real.exp_log hqp] - rw [Real.exp_add,he,mul_comm] - -lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by - exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ - (modifiedInputTree_adapted L r E U X) e q hq hlog _ - (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) - (modified_slab_mgf l L r hl E U X e q hq hlog) - -theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ - InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 - have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 - have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) - (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by - apply h₁.trans - apply Real.exp_le_exp.mpr - exact add_le_add_right (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ - have hh := finiteMean_mul_exp_le - (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) - (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) - _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simp only [←pow_add] at hh - refine hh.trans_eq ?_ - congr 1 - simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] - ring - -noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y - -lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by - rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L - -lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + - InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by - induction n with - | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] - omega - -lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by - symm - apply Finset.sum_subset (Finset.range_mono hd) - intro i _ hi - have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi - exact InputTree.levelCost_gt (i+1) d T (by omega) e Y - -lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y = 0 := by - induction r generalizing ι with - | zero => rfl - | succ r ih => - rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] - -lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by - apply Finset.sum_eq_zero - intro i hi - exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y - -theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hbound : L+r ≤ L*4^(L+r) := by - have h₀ := pow_four_ge (L+r) - have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL - nlinarith - have he (Y : SwitchIndex (L+r) → Bool) := - InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y - have hz (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := - boundaryTree_lowCost_zero L r _ X e Y - simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he - simp_rw [←he] - exact modified_high_mgf L (L+r) r hL E U X e q hq hlog - - -noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := - Finset.univ.filter (fun u => Fin.cons b u ∈ E) - -lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : - u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by - classical - simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] - -lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : - (exceptionChild E false).card+(exceptionChild E true).card = E.card := by - classical - have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) - (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he - simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he - simpa only [exceptionChild,Finset.card_filter,add_comm] using he - -def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where - toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) - invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) - left_inv U := by - funext u - dsimp only - split_ifs with h - · rw [←h,Fin.cons_self_tail] - · have h' : u 0 = false := by cases hh : u 0 <;> simp_all - rw [←h',Fin.cons_self_tail] - right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] - -def seedSandwichShuffle {A B C D E : Type*} : - (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where - toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) - invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) - left_inv _ := rfl - right_inv _ := rfl - -abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) - -def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ - (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := - (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans - seedSandwichShuffle - -noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * - (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ - -noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := - InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 - -lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) - (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : - (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = - modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by - funext u - simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] - -lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - let z := (modifiedStepEquiv L r).symm (ω,coins) - modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = - InputTree.node coins.1 (fun b => - let w := if b then ω.2 else ω.1 - modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by - dsimp only - unfold modifiedInputTree - rw [boundaryTree] - change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ - congr 1 - funext b - rw [modifiedBoundary_cons] - cases b <;> rfl - -lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = - pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by - rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] - change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ - rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) - (x : Card (L+r+1)) : - headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by - rw [modifiedPerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (η : Card d → Bool) : - InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + - InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + - InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by - dsimp only - rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] - have he : (∑ i ∈ Finset.range d, - (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = - InputTree.lowCost d d (T false) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + - InputTree.lowCost d d (T true) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by - rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro i hi - rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] - rw [he] - omega - -noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + - modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 - -lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = - modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [modifiedCost,modifiedInputTree_node] - change InputTree.lowCost (L+r+1) (L+r+1) _ e - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ - rw [InputTree.lowCost_node] - unfold modifiedAssignmentCost - dsimp only - simp only [Bool.false_eq_true,↓reduceIte] - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - congr 2 - - -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) - (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - Function.Surjective (childEmbedding x c hc b) := by - intro y - have hs : Function.Surjective (coloredEmbedding x c hc) := - (pairLayer (chosenCoin x c)).surjective.comp hx - obtain ⟨i,hi⟩ := hs (b,y) - rw [coloredEmbedding_apply] at hi - exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ - -omit [DecidableEq ι] in -lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : - finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ - 1/(Fintype.card (Equiv.Perm α):ℝ) := by - classical - let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i - have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by - have hh : p*u⁻¹ = p*v⁻¹ := by - ext x - obtain ⟨i,rfl⟩ := he x - exact (hu i).trans (hv i).symm - exact inv_injective (mul_left_cancel hh) - unfold finiteMean - apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 - by_cases h : ∃ u, M u - · obtain ⟨u,hu⟩ := h - rw [Finset.sum_eq_single u] - · simp only [hu,↓reduceIte,le_refl] - · intro v _ hv - exact ite_eq_right (fun hh => hv (huniq v u hh hu)) - · simp - · push Not at h - simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] - -end PairRouting - -noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := - (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) - -lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ - -lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : - centralFactor L (r+1) E a = - centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by - unfold centralFactor - rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] - congr 1 - have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by - exact_mod_cast exceptionChild_card_add E - rw [pow_succ,←he] - ring - -lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : - modifiedPerm L 0 E ω = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 - else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by - unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput - split_ifs - · exact mul_inv_cancel _ - · rfl - -lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by - simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, - InputTree.levelCost,Finset.sum_const_zero] - -lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : - centralFactor L 0 E a = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by - classical - let z : Card 0 := fun j => Fin.elim0 j - have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by - by_cases hz : z ∈ E - · have he : E = {z} := by - ext u - rw [Subsingleton.elim u z] - simp only [hz,Finset.mem_singleton] - rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] - · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) - rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] - unfold centralFactor - rw [pow_zero,he] - split_ifs <;> simp - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.PalindromeFamilyCost + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + centralLevelCost_perturb (l+i.val+1) L r C D e ω) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh + +lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : + centralDistance L r C D ≤ E.card*2^L := by + classical + calc + _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by + apply Finset.sum_le_sum + intro u _ + split_ifs with hu + · simpa only [card_positions] using permDistance_le (C u) (D u) + · rw [h u hu,permDistance_refl] + _ = _ := by simp + + +inductive InputTree : ℕ → Type + | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d + | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) + +def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) + | _, .tip p => p + | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) + +noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → + {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ + | _, .tip _, _, _, _, _ => 0 + | d+1, .node ξ T, _, _, e, Y => + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let σ := coinStepEquiv d Y + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) + (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : + (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by + rw [InputTree.levelCost] + rfl + +lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + T.levelCost t e Y = 0 := by + induction T generalizing ι with + | tip p => rfl + | @node d ξ T ih => + rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] + +lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by + induction T generalizing ι with + | tip p => intro Y Y' _; rfl + | @node d ξ T ih => + intro Y Y' h + dsimp only + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] + rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), + InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih false + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih true + intro i hi + exact h (Sum.inr (true,i)) hi + +theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) + (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + cases T with + | tip p => + simp only [InputTree.levelCost,pow_zero,finiteMean_const] + exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) + | node ξ T => + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x ξ + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => + if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ + else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + (T false).levelCost (s+u+1) e₀ (Y₀ hi) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + (T true).levelCost (s+u+1) e₁ (Y₁ hi) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + (InputTree.node ξ T).levelCost (s+u+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' (T false).perm (T true).perm + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' (T false) e₀ lo₀ + have h₁ := ih u hu' (T true) e₁ lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i : Fin l, T.levelCost (l+i.1+1) e Y + +lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) + +theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)))) := by + apply finiteMean_mono + intro hi + simpa only [InputTree.slabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + (SwitchIndex (L+r) → Bool) → InputTree (L+r) + | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) + | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => + boundaryTree L r (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) + +def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → + Card r → Equiv.Perm (Card L) + | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) + | r+1, Y, u => boundaryOutput L r + (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) + +lemma boundaryOutput_adapted (L r : ℕ) : + LayerAdapted (L+r) L (boundaryOutput L r) := by + induction r with + | zero => + intro Y Y' h + have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) + rw [he] + | succ r ih => + intro Y Y' h + funext u + dsimp only [boundaryOutput] + cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) + +noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u + +lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) : + LayerAdapted (L+r) L (modifiedBoundary L r E U) := by + intro Y Y' h + unfold modifiedBoundary + rw [boundaryOutput_adapted L r Y Y' h] + +lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) : + permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = + centralDistance L r U V := by + induction r with + | zero => + simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + simp only [boundaryTree,InputTree.perm,permDistance_mul_left] + rw [permDistance_childLift,centralDistance_step,ih,ih] + +lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y ≤ + (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by + induction r generalizing ι with + | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] + by_cases ht : t = L+r+1 + · simp only [ite_eq_left ht] + have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (coinStepEquiv (L+r) X).2) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, + permDistance_boundaryTree,←centralDistance_step] using hh + · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] + rw [centralDistance_step] + have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) + (coinStepEquiv (L+r) X).1.1 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 + have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) + (coinStepEquiv (L+r) X).1.2 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 + omega + +lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh + +lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by + apply centralDistance_exceptional + intro u hu + exact ite_eq_right hu + + +lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.slabCost l d T e Y = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact InputTree.levelCost_gt _ _ T (by omega) _ _ + +lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + apply adapted_mul_mean_le r s F _ hF hA + intro lo + let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false + have he (hi : Card s × SwitchIndex r → Bool) : + T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := + hT _ _ (assembleBits_agree r s lo hi hi₀) + simp_rw [he] + exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog + +lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) + (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) + (fun _ _ _ => rfl) q hq hlog + simpa only [one_mul,finiteMean_const] using hh + +noncomputable def InputTree.familyCost (L n d : ℕ) + (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y + +lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by + intro Y Y' h + dsimp only + rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] + exact InputTree.slabCost_adapted l d (T Y') e Y Y' + (agreeThrough_mono (le_max_right _ _) h) + +lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) + (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) + +theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => + simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,add_zero] + exact Real.one_le_exp hp + | succ n ih => + by_cases hn : n = 0 + · subst n + simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst + · let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n + have hs' : s ≤ familyEnd L n := by + have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) + simp only [pow_zero,mul_one] at hh + omega + have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = + InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T + (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) + · apply layerAdapted_comp + exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) + · exact hq + · exact hlog + · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp only [l] + ring + +lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*heightDecay L) := by + apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans + apply Real.exp_le_exp.mpr + apply add_le_add_right + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using hh + + +noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := + boundaryTree L r (modifiedBoundary L r E U Y) X + +lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : + LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by + intro Y Y' h + unfold modifiedInputTree + rw [modifiedBoundary_adapted L r E U Y Y' h] + +lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ + Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + have hqp : 0 < q := by linarith + have hpoint (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by + apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans + apply Nat.add_le_add_left + simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) + calc + _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := + finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) + _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * + q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ + _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := + mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) + _ = _ := by + have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by + rw [Real.exp_nat_mul,Real.exp_log hqp] + rw [Real.exp_add,he,mul_comm] + +lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by + exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ + (modifiedInputTree_adapted L r E U X) e q hq hlog _ + (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) + (modified_slab_mgf l L r hl E U X e q hq hlog) + +theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ + InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 + have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 + have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) + (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by + apply h₁.trans + apply Real.exp_le_exp.mpr + exact add_le_add_right (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ + have hh := finiteMean_mul_exp_le + (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) + (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) + _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simp only [←pow_add] at hh + refine hh.trans_eq ?_ + congr 1 + simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] + ring + +noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y + +lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by + rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L + +lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + + InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by + induction n with + | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] + omega + +lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by + symm + apply Finset.sum_subset (Finset.range_mono hd) + intro i _ hi + have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi + exact InputTree.levelCost_gt (i+1) d T (by omega) e Y + +lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y = 0 := by + induction r generalizing ι with + | zero => rfl + | succ r ih => + rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] + +lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by + apply Finset.sum_eq_zero + intro i hi + exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y + +theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hbound : L+r ≤ L*4^(L+r) := by + have h₀ := pow_four_ge (L+r) + have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL + nlinarith + have he (Y : SwitchIndex (L+r) → Bool) := + InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y + have hz (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := + boundaryTree_lowCost_zero L r _ X e Y + simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he + simp_rw [←he] + exact modified_high_mgf L (L+r) r hL E U X e q hq hlog + + +noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := + Finset.univ.filter (fun u => Fin.cons b u ∈ E) + +lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : + u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by + classical + simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : + (exceptionChild E false).card+(exceptionChild E true).card = E.card := by + classical + have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) + (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he + simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he + simpa only [exceptionChild,Finset.card_filter,add_comm] using he + +def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where + toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) + invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) + left_inv U := by + funext u + dsimp only + split_ifs with h + · rw [←h,Fin.cons_self_tail] + · have h' : u 0 = false := by cases hh : u 0 <;> simp_all + rw [←h',Fin.cons_self_tail] + right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] + +def seedSandwichShuffle {A B C D E : Type*} : + (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where + toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) + invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) + left_inv _ := rfl + right_inv _ := rfl + +abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) + +def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ + (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := + (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans + seedSandwichShuffle + +noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * + (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ + +noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := + InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 + +lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) + (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : + (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = + modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by + funext u + simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] + +lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + let z := (modifiedStepEquiv L r).symm (ω,coins) + modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = + InputTree.node coins.1 (fun b => + let w := if b then ω.2 else ω.1 + modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by + dsimp only + unfold modifiedInputTree + rw [boundaryTree] + change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ + congr 1 + funext b + rw [modifiedBoundary_cons] + cases b <;> rfl + +lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = + pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by + rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] + change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ + rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) + (x : Card (L+r+1)) : + headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by + rw [modifiedPerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (η : Card d → Bool) : + InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + + InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + + InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by + dsimp only + rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] + have he : (∑ i ∈ Finset.range d, + (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = + InputTree.lowCost d d (T false) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + + InputTree.lowCost d d (T true) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by + rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] + rw [he] + omega + +noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + + modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 + +lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = + modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [modifiedCost,modifiedInputTree_node] + change InputTree.lowCost (L+r+1) (L+r+1) _ e + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ + rw [InputTree.lowCost_node] + unfold modifiedAssignmentCost + dsimp only + simp only [Bool.false_eq_true,↓reduceIte] + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + congr 2 + + +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) + (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + Function.Surjective (childEmbedding x c hc b) := by + intro y + have hs : Function.Surjective (coloredEmbedding x c hc) := + (pairLayer (chosenCoin x c)).surjective.comp hx + obtain ⟨i,hi⟩ := hs (b,y) + rw [coloredEmbedding_apply] at hi + exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ + +omit [DecidableEq ι] in +lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : + finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ + 1/(Fintype.card (Equiv.Perm α):ℝ) := by + classical + let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i + have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by + have hh : p*u⁻¹ = p*v⁻¹ := by + ext x + obtain ⟨i,rfl⟩ := he x + exact (hu i).trans (hv i).symm + exact inv_injective (mul_left_cancel hh) + unfold finiteMean + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 + by_cases h : ∃ u, M u + · obtain ⟨u,hu⟩ := h + rw [Finset.sum_eq_single u] + · simp only [hu,↓reduceIte,le_refl] + · intro v _ hv + exact ite_eq_right (fun hh => hv (huniq v u hh hu)) + · simp + · push Not at h + simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] + +end PairRouting + +noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := + (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) + +lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ + +lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : + centralFactor L (r+1) E a = + centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by + unfold centralFactor + rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] + congr 1 + have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by + exact_mod_cast exceptionChild_card_add E + rw [pow_succ,←he] + ring + +lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : + modifiedPerm L 0 E ω = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 + else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by + unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput + split_ifs + · exact mul_inv_cancel _ + · rfl + +lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by + simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, + InputTree.levelCost,Finset.sum_const_zero] + +lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : + centralFactor L 0 E a = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by + classical + let z : Card 0 := fun j => Fin.elim0 j + have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by + by_cases hz : z ∈ E + · have he : E = {z} := by + ext u + rw [Subsingleton.elim u z] + simp only [hz,Finset.mem_singleton] + rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] + · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) + rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] + unfold centralFactor + rw [pow_zero,he] + split_ifs <;> simp + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/InsertionPerm.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/InsertionPerm.lean index f2cb5e0d78bcdd3c4e8df3138ac1212d5d690ff9..76ca2a98518d138f5b603af2da82ccfea47227d9 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/InsertionPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/InsertionPerm.lean @@ -1,891 +1,891 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.ZeroExtend - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.DimensionEstimates -open scoped BigOperators Classical - -section -open Filter - -lemma chosenTuple_density_bound (N j : ℕ) (hj : 0.1 - have he : (j:ℝ)*x=N := by dsimp [x]; field_simp - have hk := (chosenTuple_bounds N j hj hx hhalf).2.2 - change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower at hk - have hratio : (chosenTuple N j:ℝ)/N≤2*x^(nearPower-1) := by - rw [Real.rpow_sub hxp,Real.rpow_one] - apply (div_le_iff₀ hNp).mpr - rw [←he] - have : 2*(x^nearPower/x)*((j:ℝ)*x)=2*(j:ℝ)*x^nearPower := by field_simp - rw [this] - exact hk - have hpow := Real.rpow_le_rpow (by positivity : (0:ℝ)≤(chosenTuple N j:ℝ)/N) hratio - (by norm_num : (0:ℝ)≤1/512) - have hmain := mul_le_mul hk hpow (by positivity) (by positivity) - have hrpow : (2*x^(nearPower-1))^(1/512:ℝ)= - (2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)) := by - rw [Real.mul_rpow (by norm_num) (by positivity),←Real.rpow_mul hxp.le] - rw [hrpow] at hmain - have heq : 2*(j:ℝ)*x^nearPower*((2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)))= - (2:ℝ)^(1+(1/512:ℝ))*(j:ℝ)*x^(-tailPower) := by - rw [Real.rpow_add (by norm_num : (0:ℝ)<2),Real.rpow_one] - have hp : nearPower+(nearPower-1)*(1/512) = -tailPower := by norm_num [nearPower,tailPower] - rw [←hp,Real.rpow_add hxp] - ring - rw [heq] at hmain - have h := mul_le_mul_of_nonneg_left hmain hC - simpa only [mul_assoc] using h - -lemma near_conditions_eventually (C : ℝ) : - ∀ᶠ x : ℝ in atTop, 2≤x ∧ 2≤x^nearPower ∧ x^(nearPower-1)≤1/2 ∧ - 8*Real.log 2/nearPower≤Real.log x ∧ 4*Real.log 2+2≤Real.log x ∧ - C*2^(1+(1/512:ℝ))*x^(-tailPower) ≤ nearFraction/4000 := by - have hpow := (tendsto_rpow_atTop (by norm_num [nearPower] : 0 C*2^(1+(1/512:ℝ))*x^(-tailPower)) atTop (nhds 0) := by - simpa only [mul_zero] using - (tendsto_const_nhds.mul (tendsto_rpow_neg_atTop (by norm_num [tailPower] : 0 f x) hg - rw [he,map_one] - rfl - -omit [FiniteDimensional ℂ V] in -lemma full_tuple_finrank (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - Module.finrank ℂ (fixedSpace tupleAction (Function.Embedding.refl (Card d)) ρ)=Module.finrank ℂ V := by - rw [full_tuple_fixed,finrank_top] - -theorem palindrome_irrep_amplification (d : ℕ) {ι : Type*} [Fintype ι] - (f : ι ↪ Card d) (hk : 0 by simpa only [tupleAction_kernel] using modified_kernel_symmetric L r E e f) - (fun e => by simpa only [tupleAction_kernel] using PairRouting.tupleProbability_row_sum (modifiedPerm L r E) e) - (1/1000) z (Real.exp u) (by norm_num) hz (by positivity) - (fun e => by simpa only [tupleAction_kernel,modifiedRowMoment] using hM e) - (by simpa only [f,full_tuple_finrank] using hm) - simpa only [f,full_tuple_finrank] using h - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -theorem choose_tail_le_of_factorial (μ : YoungDiagram) (D : ℕ) - (hd : μ.card.factorial ≤ D * Fintype.card (rowGroup μ) * Fintype.card (colGroup μ)) : - μ.card.choose (μ.card-μ.rowLen 0) ≤ D * 2^(μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - have htail := card_fiberGroups_mul_le - (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) - (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) - rw [tail_card] at htail - have hc := column_group_le_tail μ - have hr := tail_row_group μ - simp only [←Nat.card_eq_fintype_card] at htail hc hr hd - have hh : μ.card.factorial ≤ D * 2^j * - ((μ.rowLen 0).factorial * j.factorial) := by - calc - _ ≤ _ := hd - _ ≤ D * Nat.card (rowGroup μ) * - (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc - _ = D * 2^j * (μ.rowLen 0).factorial * - (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * - Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring - _ ≤ _ := by - calc - _ ≤ D * 2^j * (μ.rowLen 0).factorial * j.factorial := - Nat.mul_le_mul_left _ htail - _ = _ := by ring - have hj : j ≤ μ.card := Nat.sub_le _ _ - have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega - have hf := Nat.choose_mul_factorial_mul_factorial hj - rw [hs] at hf - rw [←hf] at hh - have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) - nlinarith - -lemma card_rowGroup_transpose (μ : YoungDiagram) : - Fintype.card (rowGroup μ.transpose) = Fintype.card (colGroup μ) := by - rw [card_rowGroup,card_colGroup] - apply Fintype.prod_equiv (finCongr (μ.colLen_transpose 0)) - intro i - change (μ.transpose.rowLen i).factorial = (μ.colLen i).factorial - rw [YoungDiagram.rowLen_transpose] - -lemma card_colGroup_transpose (μ : YoungDiagram) : - Fintype.card (colGroup μ.transpose) = Fintype.card (rowGroup μ) := by - rw [card_colGroup,card_rowGroup] - apply Fintype.prod_equiv (finCongr (μ.rowLen_transpose 0)) - intro i - change (μ.transpose.colLen i).factorial = (μ.rowLen i).factorial - rw [YoungDiagram.colLen_transpose] - -lemma card_transpose (μ : YoungDiagram) : μ.transpose.card=μ.card := by - unfold YoungDiagram.card YoungDiagram.transpose - exact Finset.card_map _ - -theorem choose_column_tail_le_dimension (μ : YoungDiagram) : - μ.card.choose (μ.card-μ.colLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.colLen 0) := by - have hd := factorial_le_dimension_row_column μ - have ht := choose_tail_le_of_factorial μ.transpose (Module.finrank ℂ (space μ)) - simp only [card_transpose,card_rowGroup_transpose,card_colGroup_transpose,YoungDiagram.rowLen_transpose] at ht - apply ht - nlinarith - -open DimensionEstimates Filter - -lemma dimension_log_incidence (μ : YoungDiagram) (hμ : 0<μ.card) : - (2*Real.log 2-1)*(μ.card:ℝ)-Real.log 2*((μ.rowLen 0:ℝ)+μ.colLen 0)+1≤ - Real.log (Module.finrank ℂ (space μ)) := by - let : Nonempty (Cell μ) := Fintype.card_pos_iff.mp (by simpa only [card_cell] using hμ) - have hd := factorial_le_dimension_row_column μ - rw [card_rowGroup,card_colGroup] at hd - have hr (i : Fin (μ.colLen 0)) : Nat.card {x : Cell μ // rowIndex x=i}=μ.rowLen i := by - let e : {x : Cell μ // rowIndex x=i} ≃ {x : Cell μ // row x=i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Nat.card_congr e,Nat.card_congr (rowEquiv μ i),Nat.card_fin] - have hc (i : Fin (μ.rowLen 0)) : Nat.card {x : Cell μ // colIndex x=i}=μ.colLen i := by - let e : {x : Cell μ // colIndex x=i} ≃ {x : Cell μ // col x=i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Nat.card_congr e,Nat.card_congr (columnEquiv μ i),Nat.card_fin] - have hcell : Nat.card (Cell μ)=μ.card := by rw [Nat.card_eq_fintype_card,card_cell] - have h := dimension_log_from_incidence (rowIndex (μ := μ)) (colIndex (μ := μ)) - (fun x y h => Subtype.ext (Prod.ext (congrArg (fun z => (z.1:ℕ)) h) - (congrArg (fun z => (z.2:ℕ)) h))) (Module.finrank ℂ (space μ)) - (by simpa only [←Nat.card_eq_fintype_card,hr,hc,hcell] using hd) - simpa only [card_cell,Fintype.card_fin,add_comm (μ.colLen 0:ℝ)] using h - -lemma medium_dimension_raw (μ : YoungDiagram) (hμ : 0<μ.card) (δ : ℝ) (hδ : 0<δ) - (hδ2 : δ≤1/2) (hrow : δ*(μ.card:ℝ)≤μ.card-μ.rowLen 0) - (hcol : (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2) : - min ((3/2:ℝ)*Real.log 2-1) (entropyGap*δ)*(μ.card:ℝ)-2*Real.log μ.card-1≤ - Real.log (Module.finrank ℂ (space μ)) := by - let c := (3/2:ℝ)*Real.log 2-1 - have hN : (0:ℝ)<μ.card := by exact_mod_cast hμ - have hlog : 0≤Real.log μ.card := Real.log_nonneg (by exact_mod_cast hμ) - have hc : 0≤Real.log 2 := Real.log_nonneg (by norm_num) - have hr := rowLen_zero_le_card μ - have hcl : μ.colLen 0≤μ.card := by - simpa only [YoungDiagram.rowLen_transpose,card_transpose] using rowLen_zero_le_card μ.transpose - by_cases hsum : (μ.rowLen 0:ℝ)+μ.colLen 0≤(μ.card:ℝ)/2 - · have hi := dimension_log_incidence μ hμ - have hm := mul_le_mul_of_nonneg_right (min_le_left c (entropyGap*δ)) hN.le - dsimp [c] at hm - nlinarith - · have hbig : (μ.card:ℝ)/4≤μ.rowLen 0 ∨ (μ.card:ℝ)/4≤μ.colLen 0 := by - by_contra h - push Not at h - linarith - rcases hbig with hrb | hcb - · have hj : 0<μ.card-μ.rowLen 0 := by - rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hr] - exact lt_of_lt_of_le (mul_pos hδ hN) hrow - have hjN : μ.card-μ.rowLen 0<μ.card := by - have : 0<μ.rowLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.rowLen 0) - omega - have hi := log_dimension_from_binomial μ.card (μ.card-μ.rowLen 0) - (Module.finrank ℂ (space μ)) hj hjN - (by rw [Nat.cast_sub hr]; linarith) (choose_tail_le_dimension μ) - rw [Nat.cast_sub hr] at hi - have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le - nlinarith [entropyGap_pos] - · have hj : 0<μ.card-μ.colLen 0 := by - rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hcl] - linarith - have hjN : μ.card-μ.colLen 0<μ.card := by - have : 0<μ.colLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.colLen 0) - omega - have hi := log_dimension_from_binomial μ.card (μ.card-μ.colLen 0) - (Module.finrank ℂ (space μ)) hj hjN - (by rw [Nat.cast_sub hcl]; linarith) (choose_column_tail_le_dimension μ) - rw [Nat.cast_sub hcl] at hi - have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le - have ht := mul_le_mul_of_nonneg_left (show δ*(μ.card:ℝ)≤(μ.card:ℝ)-μ.colLen 0 by nlinarith) entropyGap_pos.le - linarith - -end Thorp.Specht - -namespace Thorp.DimensionEstimates - -section -open scoped BigOperators Classical -open Filter - -lemma finset_power_sum {ι : Type*} [Fintype ι] (x : ℝ) : - ∑ E : Finset ι, x^E.card=(1+x)^Fintype.card ι := by - have h := Finset.prod_one_add (f := fun _ : ι => x) Finset.univ - simpa only [Finset.prod_const,Finset.card_univ,Finset.powerset_univ] using h.symm - -lemma small_sets_count {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : - (∑ E : Finset ι, if (E.card:ℝ)<ε*Fintype.card ι then (1:ℝ) else 0) ≤ - Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by - have hpow (E : Finset ι) : (Real.exp (-t))^E.card=Real.exp (-t*(E.card:ℝ)) := by - rw [←Real.exp_nat_mul] - congr 1 - ring - calc - _ ≤ ∑ E : Finset ι, Real.exp (t*ε*Fintype.card ι)*(Real.exp (-t))^E.card := by - apply Finset.sum_le_sum - intro E _ - split_ifs with hE - · rw [hpow,←Real.exp_add,←Real.exp_zero] - apply Real.exp_le_exp.mpr - nlinarith [mul_le_mul_of_nonneg_left hE.le ht] - · positivity - _ = Real.exp (t*ε*Fintype.card ι)*(1+Real.exp (-t))^Fintype.card ι := by - rw [←Finset.mul_sum,finset_power_sum] - _ = _ := by - have he : (1+Real.exp (-t))^Fintype.card ι= - Real.exp (Real.log (1+Real.exp (-t))*(Fintype.card ι:ℝ)) := by - rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)] - rw [he,←Real.exp_add] - congr 1 - ring - -lemma small_sets_ceil_bound {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : - (∑ E : Finset ι, if E.card<⌈ε*Fintype.card ι⌉₊ then (1:ℝ) else 0) ≤ - Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by - have he (E : Finset ι) : E.card<⌈ε*Fintype.card ι⌉₊ ↔ (E.card:ℝ)<ε*Fintype.card ι := Nat.lt_ceil - simp only [he] - exact small_sets_count ε t ht - -lemma exists_small_set_rate (κ ε₀ : ℝ) (hκ : 0<κ) (hε₀ : 0<ε₀) : - ∃ ε : ℝ, 0<ε ∧ ε≤ε₀ ∧ ε<1/2 ∧ ∃ t : ℝ, 0≤t ∧ - t*ε+Real.log (1+Real.exp (-t))≤κ := by - have ht : Tendsto (fun t : ℝ => Real.log (1+Real.exp (-t))) atTop (nhds 0) := by - have he : Tendsto (fun t : ℝ => Real.exp (-t)) atTop (nhds 0) := - Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot - have hl := (tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0) - simpa only [add_zero,Real.log_one] using hl - obtain ⟨t,ht,hlog⟩ := ((eventually_ge_atTop (1:ℝ)).and - (ht.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists - let ε := min ε₀ (min (1/4) (κ/(2*t))) - have htp : 0 α) y a)=Fin.snoc (α := fun _ => α) (Fin.insertNth i b y) a := by - apply Fin.lastCases ?_ (fun j => ?_) |> fun h => funext h - · rw [←show i.castSucc.succAbove (Fin.last d)=Fin.last (d+1) from - Fin.succAbove_castSucc_of_le i (Fin.last d) (Fin.le_last i),Fin.insertNth_apply_succAbove] - simp - · cases j using Fin.succAboveCases i with - | x => simp - | p j => - have he : i.castSucc.succAbove j.castSucc=(i.succAbove j).castSucc := by - simp only [Fin.succAbove,Fin.castSucc_lt_castSucc_iff] - split_ifs <;> rfl - rw [←he,Fin.insertNth_apply_succAbove] - simp - -lemma rotate_cons (d : ℕ) (b : Bool) (y : Card d) : - rotate (d+1) (Fin.cons b y)=Fin.snoc y b := (Fin.snoc_eq_cons_rotate y b).symm - -lemma rotate_insert (d : ℕ) (i : Fin (d+1)) (b : Bool) (y : Card (d+1)) : - rotate (d+2) (Fin.insertNth i.succ b y)=Fin.insertNth i.castSucc b (rotate (d+1) y) := by - rw [←Fin.cons_self_tail y,Fin.insertNth_succ_cons,rotate_cons,rotate_cons,insertNth_castSucc_snoc] - -def insertionPerm (d : ℕ) (i : Fin (d+1)) : Equiv.Perm (Card (d+1)) := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm.trans - (Fin.insertNthEquiv (fun _ : Fin (d+1) => Bool) i) - -lemma insertionPerm_apply (d : ℕ) (i : Fin (d+1)) (x : Card (d+1)) : - insertionPerm d i x=Fin.insertNth i (x 0) (Fin.tail x) := rfl - -lemma insertionPerm_zero (d : ℕ) : insertionPerm d 0=1 := by - ext x j - simp [insertionPerm_apply] - -lemma insertionPerm_last (d : ℕ) : insertionPerm d (Fin.last d)=rotate (d+1) := by - apply Equiv.ext - intro x - rw [insertionPerm_apply,Fin.insertNth_last',←rotate_cons,Fin.cons_self_tail] - -lemma physical_carry_step (d : ℕ) (i : Fin (d+1)) (ξ : Bool → Coins (d+1)) : - step (d+2) (fun y => ξ (y i) (Fin.removeNth i y))*insertionPerm (d+1) i.succ= - insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b)) := by - apply Equiv.ext - intro x - have he : Fin.cons (Bool.xor ((Fin.tail x) 0) (ξ (x 0) (Fin.tail (Fin.tail x)))) - (Fin.insertNth i (x 0) (Fin.tail (Fin.tail x))) = - (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by - simp only [switchFun,Fin.insertNth_succ_cons] - have hs : switchFun (fun y => ξ (y i) (Fin.removeNth i y)) - (Fin.insertNth i.succ (x 0) (Fin.tail x)) = - (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by - conv_lhs => rw [←Fin.cons_self_tail (Fin.tail x),Fin.insertNth_succ_cons] - simp only [switchFun,Fin.cons_zero,Fin.tail_cons,Fin.insertNth_apply_same,Fin.removeNth_insertNth] - exact he - change rotate (d+2) (switchFun (fun y => ξ (y i) (Fin.removeNth i y)) - (Fin.insertNth i.succ (x 0) (Fin.tail x))) = _ - rw [hs,rotate_insert] - rfl - -end Thorp -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω : Type*} [Fintype Ω] - -lemma sampleOperator_mul_const (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : - sampleOperator ρ (fun ω => P ω*g)=sampleOperator ρ P*continuousRepresentation ρ g := by - simp only [sampleOperator,map_mul,Finset.sum_mul,smul_mul_assoc] - -lemma sampleOperator_const_mul (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : - sampleOperator ρ (fun ω => g*P ω)=continuousRepresentation ρ g*sampleOperator ρ P := by - simp only [sampleOperator,map_mul,Finset.mul_sum,mul_smul_comm] - -lemma sampleOperator_run (d t : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - sampleOperator ρ (run d t)=(sampleOperator ρ (step d))^t := by - induction t with - | zero => exact sampleOperator_one ρ - | succ t ih => - let e : Coins d × (Fin t → Coins d) ≃ (Fin (t+1) → Coins d) := - Fin.snocEquiv (fun _ => Coins d) - have he : run d (t+1) ∘ e=fun w => step d w.1*run d t w.2 := by - funext w - simp only [Function.comp_apply,e,Fin.snocEquiv_apply, - run,Fin.snoc_last,Fin.snoc_castSucc] - rw [←sampleOperator_equiv ρ (run d (t+1)) e,he,sampleOperator_prod,ih,pow_succ'] - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite - -def carryCoins (d : ℕ) (i : Fin (d+1)) : (Bool → Coins (d+1)) ≃ Coins (d+2) where - toFun ξ y := ξ (y i) (Fin.removeNth i y) - invFun ξ b y := ξ (Fin.insertNth i b y) - left_inv ξ := by funext b y; simp - right_inv ξ := by funext y; simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma physical_carry_average (d : ℕ) (i : Fin d) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - sampleOperator ρ (step (d+1))*continuousRepresentation ρ (insertionPerm d i.succ)= - continuousRepresentation ρ (insertionPerm d i.castSucc)* - sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) := by - cases d with - | zero => exact Fin.elim0 i - | succ d => - have he : (fun ξ : Bool → Coins (d+1) => - step (d+2) (carryCoins d i ξ)*insertionPerm (d+1) i.succ)= - (fun ξ => insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b))) := by - funext ξ - exact physical_carry_step d i ξ - have h := congrArg (sampleOperator ρ) he - rw [sampleOperator_mul_const,sampleOperator_const_mul] at h - change sampleOperator ρ (step (d+2) ∘ carryCoins d i)*_=_ at h - rw [sampleOperator_equiv] at h - exact h - -theorem physical_sweep_recursion (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - (sampleOperator ρ (step (d+1)))^(d+1)= - (sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))))^d* - sampleOperator ρ (pairSwitch (d := d)) := by - let A := sampleOperator ρ (step (d+1)) - let K := sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) - have h (t : ℕ) (ht : t≤d) : A^t*continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)=K^t := by - induction t with - | zero => - change 1*continuousRepresentation ρ (insertionPerm d 0)=1 - rw [insertionPerm_zero,map_one,one_mul] - | succ t ih => - have hc := physical_carry_average d (⟨t,by omega⟩ : Fin d) ρ - change A*continuousRepresentation ρ (insertionPerm d ⟨t+1,by omega⟩)= - continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)*K at hc - rw [pow_succ,mul_assoc,hc,←mul_assoc,ih (by omega),←pow_succ] - have he : sampleOperator ρ (step (d+1))= - continuousRepresentation ρ (rotate (d+1))*sampleOperator ρ (pairSwitch (d := d)) := - sampleOperator_const_mul ρ (pairSwitch (d := d)) (rotate (d+1)) - calc - _ = A^d*A := pow_succ A d - _ = A^d*(continuousRepresentation ρ (insertionPerm d (Fin.last d))* - sampleOperator ρ (pairSwitch (d := d))) := by rw [insertionPerm_last]; rw [←he] - _ = _ := by - rw [←mul_assoc] - exact congrArg (fun z => z*sampleOperator ρ (pairSwitch (d := d))) (h d le_rfl) - -end Thorp -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite - -lemma childInjection_product (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - childInjection d false (p false)*childInjection d true (p true)=childLift p := by - change childLift _*childLift _=_ - rw [childLift_mul] - congr 1 - funext b - cases b <;> simp - -lemma childInjection_commute (d : ℕ) (p q : Equiv.Perm (Card d)) : - Commute (childInjection d false p) (childInjection d true q) := by - change childLift _*childLift _=childLift _*childLift _ - rw [childLift_mul,childLift_mul] - congr 1 - funext b - cases b <;> simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω : Type*} [Fintype Ω] - -lemma sampleOperator_child (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) - (P : Ω → Equiv.Perm (Card d)) : - sampleOperator ρ (fun ω : Bool → Ω => childLift (fun b => P (ω b)))= - sampleOperator (ρ.comp (childInjection d false)) P* - sampleOperator (ρ.comp (childInjection d true)) P := by - let e := (Equiv.boolArrowEquivProd Ω).symm - have he : (fun ω : Bool → Ω => childLift (fun b => P (ω b))) ∘ e= - fun w : Ω × Ω => childInjection d false (P w.1)*childInjection d true (P w.2) := by - funext w - change childLift (fun b => P (e w b))=_ - rw [←childInjection_product] - rfl - rw [←sampleOperator_equiv ρ _ e,he] - exact sampleOperator_prod ρ (fun w => childInjection d false (P w)) - (fun w => childInjection d true (P w)) - -lemma sampleOperator_child_commute (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) - (P : Ω → Equiv.Perm (Card d)) : - Commute (sampleOperator (ρ.comp (childInjection d false)) P) - (sampleOperator (ρ.comp (childInjection d true)) P) := by - rw [sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => childInjection_commute d _ _) - -lemma inverse_butterfly_average_step (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)= - sampleOperator ρ (fun ω : Bool → (SwitchIndex d → Bool) => - childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹))* - sampleOperator ρ (pairSwitch (d := d)) := by - let e := ((Equiv.prodCongr (Equiv.boolArrowEquivProd (SwitchIndex d → Bool)) (Equiv.refl (Card d → Bool))).trans - (coinStepEquiv d).symm) - have he : (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹) ∘ e= - fun w : (Bool → (SwitchIndex d → Bool)) × (Card d → Bool) => - childLift (fun b => (butterflyPerm d (decodeButterfly d (w.1 b)))⁻¹)*pairSwitch w.2 := by - funext w - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((w.1 false,w.1 true),w.2))))⁻¹=_ - rw [butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - congr 2 - funext b - cases b <;> rfl - rw [←sampleOperator_equiv ρ _ e,he] - exact sampleOperator_prod ρ - (fun ω : Bool → (SwitchIndex d → Bool) => childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹)) - (pairSwitch (d := d)) - -theorem physical_sweep_inverse_butterfly (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - (sampleOperator ρ (step d))^d= - sampleOperator ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹) := by - induction d with - | zero => - symm - exact sampleOperator_one ρ - | succ d ih => - rw [physical_sweep_recursion,sampleOperator_child, - (sampleOperator_child_commute d ρ (step d)).mul_pow,ih,ih, - inverse_butterfly_average_step] - rw [sampleOperator_child d ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹)] - -lemma physical_sweep_adjoint (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card d)) V) (hρ : IsUnitary ρ) : - sampleOperator ρ (run d d)= - (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by - rw [sampleOperator_run,physical_sweep_inverse_butterfly,sampleOperator_inv ρ hρ] - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical -open UnitaryFinite DimensionEstimates Filter - -lemma dimension_pos (μ : YoungDiagram) : 0 < Module.finrank ℂ (space μ) := by - have h := factorial_le_dimension_row_column μ - by_contra hn - have hz : Module.finrank ℂ (space μ)=0 := by omega - rw [hz,zero_mul,zero_mul] at h - exact (Nat.factorial_pos μ.card).not_ge h - -lemma near_numerical_cutoff : - ∃ X : ℝ, 2 ≤ X ∧ ∀ (N j D : ℕ), 0 < j → X ≤ (N:ℝ)/j → N.choose j ≤ D * 2^j → - ∃ k : ℕ, j ≤ k ∧ k ≤ N ∧ ∀ m : ℕ, D * k.choose j ≤ m * N.choose j → - nearFraction * Real.log D ≤ Real.log m ∧ - densityConstant * (k:ℝ) * ((k:ℝ)/N)^(1/512:ℝ) ≤ Real.log m/4000 ∧ - (1/2:ℝ) * Real.log N ≤ Real.log D ∧ (j:ℝ) ≤ Real.log D := by - obtain ⟨X,hX,h⟩ := exists_near_cutoff densityConstant densityConstant_pos.le - refine ⟨X,hX,?_⟩ - intro N j D hj hx hd - have hjN : j ≤ N := by - have hjp : (0:ℝ) < j := by exact_mod_cast hj - have hh : (j:ℝ) ≤ N := by - have := (le_div_iff₀ hjp).mp (hX.trans hx) - linarith - exact_mod_cast hh - have hc : 1 ≤ N.choose j := Nat.choose_pos hjN - have hfoot : D * (chosenTuple N j).choose j ≤ (D * (chosenTuple N j).choose j) * N.choose j := - Nat.le_mul_of_pos_right _ hc - have hh := h N j D _ hj hx hd hfoot - refine ⟨chosenTuple N j,hh.1,hh.2.1,?_⟩ - intro m hm - exact (h N j D m hj hx hd hm).2.2 - -lemma near_row_amplification (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) - {k : ℕ} (f : Fin k ↪ Card d) (hk : 0 rw [←Real.exp_log hθ,←Real.exp_nat_mul] - apply Real.exp_le_exp.mpr - have hg := mul_le_mul_of_nonpos_left (Nat.le_ceil (ε*M)) (Real.log_nonpos hθ.le hθ1.le) - nlinarith - -end Thorp.DimensionEstimates - -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -open DimensionEstimates -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -theorem medium_exception_decay (L r : ℕ) (h ε t : ℝ) (ht : 0≤t) - (hcount : t*ε+Real.log (1+Real.exp (-t))≤h*(2:ℝ)^L/16000) - (ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (hm : 0.1 + have he : (j:ℝ)*x=N := by dsimp [x]; field_simp + have hk := (chosenTuple_bounds N j hj hx hhalf).2.2 + change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower at hk + have hratio : (chosenTuple N j:ℝ)/N≤2*x^(nearPower-1) := by + rw [Real.rpow_sub hxp,Real.rpow_one] + apply (div_le_iff₀ hNp).mpr + rw [←he] + have : 2*(x^nearPower/x)*((j:ℝ)*x)=2*(j:ℝ)*x^nearPower := by field_simp + rw [this] + exact hk + have hpow := Real.rpow_le_rpow (by positivity : (0:ℝ)≤(chosenTuple N j:ℝ)/N) hratio + (by norm_num : (0:ℝ)≤1/512) + have hmain := mul_le_mul hk hpow (by positivity) (by positivity) + have hrpow : (2*x^(nearPower-1))^(1/512:ℝ)= + (2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)) := by + rw [Real.mul_rpow (by norm_num) (by positivity),←Real.rpow_mul hxp.le] + rw [hrpow] at hmain + have heq : 2*(j:ℝ)*x^nearPower*((2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)))= + (2:ℝ)^(1+(1/512:ℝ))*(j:ℝ)*x^(-tailPower) := by + rw [Real.rpow_add (by norm_num : (0:ℝ)<2),Real.rpow_one] + have hp : nearPower+(nearPower-1)*(1/512) = -tailPower := by norm_num [nearPower,tailPower] + rw [←hp,Real.rpow_add hxp] + ring + rw [heq] at hmain + have h := mul_le_mul_of_nonneg_left hmain hC + simpa only [mul_assoc] using h + +lemma near_conditions_eventually (C : ℝ) : + ∀ᶠ x : ℝ in atTop, 2≤x ∧ 2≤x^nearPower ∧ x^(nearPower-1)≤1/2 ∧ + 8*Real.log 2/nearPower≤Real.log x ∧ 4*Real.log 2+2≤Real.log x ∧ + C*2^(1+(1/512:ℝ))*x^(-tailPower) ≤ nearFraction/4000 := by + have hpow := (tendsto_rpow_atTop (by norm_num [nearPower] : 0 C*2^(1+(1/512:ℝ))*x^(-tailPower)) atTop (nhds 0) := by + simpa only [mul_zero] using + (tendsto_const_nhds.mul (tendsto_rpow_neg_atTop (by norm_num [tailPower] : 0 f x) hg + rw [he,map_one] + rfl + +omit [FiniteDimensional ℂ V] in +lemma full_tuple_finrank (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + Module.finrank ℂ (fixedSpace tupleAction (Function.Embedding.refl (Card d)) ρ)=Module.finrank ℂ V := by + rw [full_tuple_fixed,finrank_top] + +theorem palindrome_irrep_amplification (d : ℕ) {ι : Type*} [Fintype ι] + (f : ι ↪ Card d) (hk : 0 by simpa only [tupleAction_kernel] using modified_kernel_symmetric L r E e f) + (fun e => by simpa only [tupleAction_kernel] using PairRouting.tupleProbability_row_sum (modifiedPerm L r E) e) + (1/1000) z (Real.exp u) (by norm_num) hz (by positivity) + (fun e => by simpa only [tupleAction_kernel,modifiedRowMoment] using hM e) + (by simpa only [f,full_tuple_finrank] using hm) + simpa only [f,full_tuple_finrank] using h + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +theorem choose_tail_le_of_factorial (μ : YoungDiagram) (D : ℕ) + (hd : μ.card.factorial ≤ D * Fintype.card (rowGroup μ) * Fintype.card (colGroup μ)) : + μ.card.choose (μ.card-μ.rowLen 0) ≤ D * 2^(μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + have htail := card_fiberGroups_mul_le + (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) + (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) + rw [tail_card] at htail + have hc := column_group_le_tail μ + have hr := tail_row_group μ + simp only [←Nat.card_eq_fintype_card] at htail hc hr hd + have hh : μ.card.factorial ≤ D * 2^j * + ((μ.rowLen 0).factorial * j.factorial) := by + calc + _ ≤ _ := hd + _ ≤ D * Nat.card (rowGroup μ) * + (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc + _ = D * 2^j * (μ.rowLen 0).factorial * + (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * + Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring + _ ≤ _ := by + calc + _ ≤ D * 2^j * (μ.rowLen 0).factorial * j.factorial := + Nat.mul_le_mul_left _ htail + _ = _ := by ring + have hj : j ≤ μ.card := Nat.sub_le _ _ + have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega + have hf := Nat.choose_mul_factorial_mul_factorial hj + rw [hs] at hf + rw [←hf] at hh + have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) + nlinarith + +lemma card_rowGroup_transpose (μ : YoungDiagram) : + Fintype.card (rowGroup μ.transpose) = Fintype.card (colGroup μ) := by + rw [card_rowGroup,card_colGroup] + apply Fintype.prod_equiv (finCongr (μ.colLen_transpose 0)) + intro i + change (μ.transpose.rowLen i).factorial = (μ.colLen i).factorial + rw [YoungDiagram.rowLen_transpose] + +lemma card_colGroup_transpose (μ : YoungDiagram) : + Fintype.card (colGroup μ.transpose) = Fintype.card (rowGroup μ) := by + rw [card_colGroup,card_rowGroup] + apply Fintype.prod_equiv (finCongr (μ.rowLen_transpose 0)) + intro i + change (μ.transpose.colLen i).factorial = (μ.rowLen i).factorial + rw [YoungDiagram.colLen_transpose] + +lemma card_transpose (μ : YoungDiagram) : μ.transpose.card=μ.card := by + unfold YoungDiagram.card YoungDiagram.transpose + exact Finset.card_map _ + +theorem choose_column_tail_le_dimension (μ : YoungDiagram) : + μ.card.choose (μ.card-μ.colLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.colLen 0) := by + have hd := factorial_le_dimension_row_column μ + have ht := choose_tail_le_of_factorial μ.transpose (Module.finrank ℂ (space μ)) + simp only [card_transpose,card_rowGroup_transpose,card_colGroup_transpose,YoungDiagram.rowLen_transpose] at ht + apply ht + nlinarith + +open DimensionEstimates Filter + +lemma dimension_log_incidence (μ : YoungDiagram) (hμ : 0<μ.card) : + (2*Real.log 2-1)*(μ.card:ℝ)-Real.log 2*((μ.rowLen 0:ℝ)+μ.colLen 0)+1≤ + Real.log (Module.finrank ℂ (space μ)) := by + let : Nonempty (Cell μ) := Fintype.card_pos_iff.mp (by simpa only [card_cell] using hμ) + have hd := factorial_le_dimension_row_column μ + rw [card_rowGroup,card_colGroup] at hd + have hr (i : Fin (μ.colLen 0)) : Nat.card {x : Cell μ // rowIndex x=i}=μ.rowLen i := by + let e : {x : Cell μ // rowIndex x=i} ≃ {x : Cell μ // row x=i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Nat.card_congr e,Nat.card_congr (rowEquiv μ i),Nat.card_fin] + have hc (i : Fin (μ.rowLen 0)) : Nat.card {x : Cell μ // colIndex x=i}=μ.colLen i := by + let e : {x : Cell μ // colIndex x=i} ≃ {x : Cell μ // col x=i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Nat.card_congr e,Nat.card_congr (columnEquiv μ i),Nat.card_fin] + have hcell : Nat.card (Cell μ)=μ.card := by rw [Nat.card_eq_fintype_card,card_cell] + have h := dimension_log_from_incidence (rowIndex (μ := μ)) (colIndex (μ := μ)) + (fun x y h => Subtype.ext (Prod.ext (congrArg (fun z => (z.1:ℕ)) h) + (congrArg (fun z => (z.2:ℕ)) h))) (Module.finrank ℂ (space μ)) + (by simpa only [←Nat.card_eq_fintype_card,hr,hc,hcell] using hd) + simpa only [card_cell,Fintype.card_fin,add_comm (μ.colLen 0:ℝ)] using h + +lemma medium_dimension_raw (μ : YoungDiagram) (hμ : 0<μ.card) (δ : ℝ) (hδ : 0<δ) + (hδ2 : δ≤1/2) (hrow : δ*(μ.card:ℝ)≤μ.card-μ.rowLen 0) + (hcol : (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2) : + min ((3/2:ℝ)*Real.log 2-1) (entropyGap*δ)*(μ.card:ℝ)-2*Real.log μ.card-1≤ + Real.log (Module.finrank ℂ (space μ)) := by + let c := (3/2:ℝ)*Real.log 2-1 + have hN : (0:ℝ)<μ.card := by exact_mod_cast hμ + have hlog : 0≤Real.log μ.card := Real.log_nonneg (by exact_mod_cast hμ) + have hc : 0≤Real.log 2 := Real.log_nonneg (by norm_num) + have hr := rowLen_zero_le_card μ + have hcl : μ.colLen 0≤μ.card := by + simpa only [YoungDiagram.rowLen_transpose,card_transpose] using rowLen_zero_le_card μ.transpose + by_cases hsum : (μ.rowLen 0:ℝ)+μ.colLen 0≤(μ.card:ℝ)/2 + · have hi := dimension_log_incidence μ hμ + have hm := mul_le_mul_of_nonneg_right (min_le_left c (entropyGap*δ)) hN.le + dsimp [c] at hm + nlinarith + · have hbig : (μ.card:ℝ)/4≤μ.rowLen 0 ∨ (μ.card:ℝ)/4≤μ.colLen 0 := by + by_contra h + push Not at h + linarith + rcases hbig with hrb | hcb + · have hj : 0<μ.card-μ.rowLen 0 := by + rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hr] + exact lt_of_lt_of_le (mul_pos hδ hN) hrow + have hjN : μ.card-μ.rowLen 0<μ.card := by + have : 0<μ.rowLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.rowLen 0) + omega + have hi := log_dimension_from_binomial μ.card (μ.card-μ.rowLen 0) + (Module.finrank ℂ (space μ)) hj hjN + (by rw [Nat.cast_sub hr]; linarith) (choose_tail_le_dimension μ) + rw [Nat.cast_sub hr] at hi + have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le + nlinarith [entropyGap_pos] + · have hj : 0<μ.card-μ.colLen 0 := by + rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hcl] + linarith + have hjN : μ.card-μ.colLen 0<μ.card := by + have : 0<μ.colLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.colLen 0) + omega + have hi := log_dimension_from_binomial μ.card (μ.card-μ.colLen 0) + (Module.finrank ℂ (space μ)) hj hjN + (by rw [Nat.cast_sub hcl]; linarith) (choose_column_tail_le_dimension μ) + rw [Nat.cast_sub hcl] at hi + have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le + have ht := mul_le_mul_of_nonneg_left (show δ*(μ.card:ℝ)≤(μ.card:ℝ)-μ.colLen 0 by nlinarith) entropyGap_pos.le + linarith + +end Thorp.Specht + +namespace Thorp.DimensionEstimates + +section +open scoped BigOperators Classical +open Filter + +lemma finset_power_sum {ι : Type*} [Fintype ι] (x : ℝ) : + ∑ E : Finset ι, x^E.card=(1+x)^Fintype.card ι := by + have h := Finset.prod_one_add (f := fun _ : ι => x) Finset.univ + simpa only [Finset.prod_const,Finset.card_univ,Finset.powerset_univ] using h.symm + +lemma small_sets_count {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : + (∑ E : Finset ι, if (E.card:ℝ)<ε*Fintype.card ι then (1:ℝ) else 0) ≤ + Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by + have hpow (E : Finset ι) : (Real.exp (-t))^E.card=Real.exp (-t*(E.card:ℝ)) := by + rw [←Real.exp_nat_mul] + congr 1 + ring + calc + _ ≤ ∑ E : Finset ι, Real.exp (t*ε*Fintype.card ι)*(Real.exp (-t))^E.card := by + apply Finset.sum_le_sum + intro E _ + split_ifs with hE + · rw [hpow,←Real.exp_add,←Real.exp_zero] + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hE.le ht] + · positivity + _ = Real.exp (t*ε*Fintype.card ι)*(1+Real.exp (-t))^Fintype.card ι := by + rw [←Finset.mul_sum,finset_power_sum] + _ = _ := by + have he : (1+Real.exp (-t))^Fintype.card ι= + Real.exp (Real.log (1+Real.exp (-t))*(Fintype.card ι:ℝ)) := by + rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)] + rw [he,←Real.exp_add] + congr 1 + ring + +lemma small_sets_ceil_bound {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : + (∑ E : Finset ι, if E.card<⌈ε*Fintype.card ι⌉₊ then (1:ℝ) else 0) ≤ + Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by + have he (E : Finset ι) : E.card<⌈ε*Fintype.card ι⌉₊ ↔ (E.card:ℝ)<ε*Fintype.card ι := Nat.lt_ceil + simp only [he] + exact small_sets_count ε t ht + +lemma exists_small_set_rate (κ ε₀ : ℝ) (hκ : 0<κ) (hε₀ : 0<ε₀) : + ∃ ε : ℝ, 0<ε ∧ ε≤ε₀ ∧ ε<1/2 ∧ ∃ t : ℝ, 0≤t ∧ + t*ε+Real.log (1+Real.exp (-t))≤κ := by + have ht : Tendsto (fun t : ℝ => Real.log (1+Real.exp (-t))) atTop (nhds 0) := by + have he : Tendsto (fun t : ℝ => Real.exp (-t)) atTop (nhds 0) := + Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot + have hl := (tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0) + simpa only [add_zero,Real.log_one] using hl + obtain ⟨t,ht,hlog⟩ := ((eventually_ge_atTop (1:ℝ)).and + (ht.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists + let ε := min ε₀ (min (1/4) (κ/(2*t))) + have htp : 0 α) y a)=Fin.snoc (α := fun _ => α) (Fin.insertNth i b y) a := by + apply Fin.lastCases ?_ (fun j => ?_) |> fun h => funext h + · rw [←show i.castSucc.succAbove (Fin.last d)=Fin.last (d+1) from + Fin.succAbove_castSucc_of_le i (Fin.last d) (Fin.le_last i),Fin.insertNth_apply_succAbove] + simp + · cases j using Fin.succAboveCases i with + | x => simp + | p j => + have he : i.castSucc.succAbove j.castSucc=(i.succAbove j).castSucc := by + simp only [Fin.succAbove,Fin.castSucc_lt_castSucc_iff] + split_ifs <;> rfl + rw [←he,Fin.insertNth_apply_succAbove] + simp + +lemma rotate_cons (d : ℕ) (b : Bool) (y : Card d) : + rotate (d+1) (Fin.cons b y)=Fin.snoc y b := (Fin.snoc_eq_cons_rotate y b).symm + +lemma rotate_insert (d : ℕ) (i : Fin (d+1)) (b : Bool) (y : Card (d+1)) : + rotate (d+2) (Fin.insertNth i.succ b y)=Fin.insertNth i.castSucc b (rotate (d+1) y) := by + rw [←Fin.cons_self_tail y,Fin.insertNth_succ_cons,rotate_cons,rotate_cons,insertNth_castSucc_snoc] + +def insertionPerm (d : ℕ) (i : Fin (d+1)) : Equiv.Perm (Card (d+1)) := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm.trans + (Fin.insertNthEquiv (fun _ : Fin (d+1) => Bool) i) + +lemma insertionPerm_apply (d : ℕ) (i : Fin (d+1)) (x : Card (d+1)) : + insertionPerm d i x=Fin.insertNth i (x 0) (Fin.tail x) := rfl + +lemma insertionPerm_zero (d : ℕ) : insertionPerm d 0=1 := by + ext x j + simp [insertionPerm_apply] + +lemma insertionPerm_last (d : ℕ) : insertionPerm d (Fin.last d)=rotate (d+1) := by + apply Equiv.ext + intro x + rw [insertionPerm_apply,Fin.insertNth_last',←rotate_cons,Fin.cons_self_tail] + +lemma physical_carry_step (d : ℕ) (i : Fin (d+1)) (ξ : Bool → Coins (d+1)) : + step (d+2) (fun y => ξ (y i) (Fin.removeNth i y))*insertionPerm (d+1) i.succ= + insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b)) := by + apply Equiv.ext + intro x + have he : Fin.cons (Bool.xor ((Fin.tail x) 0) (ξ (x 0) (Fin.tail (Fin.tail x)))) + (Fin.insertNth i (x 0) (Fin.tail (Fin.tail x))) = + (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by + simp only [switchFun,Fin.insertNth_succ_cons] + have hs : switchFun (fun y => ξ (y i) (Fin.removeNth i y)) + (Fin.insertNth i.succ (x 0) (Fin.tail x)) = + (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by + conv_lhs => rw [←Fin.cons_self_tail (Fin.tail x),Fin.insertNth_succ_cons] + simp only [switchFun,Fin.cons_zero,Fin.tail_cons,Fin.insertNth_apply_same,Fin.removeNth_insertNth] + exact he + change rotate (d+2) (switchFun (fun y => ξ (y i) (Fin.removeNth i y)) + (Fin.insertNth i.succ (x 0) (Fin.tail x))) = _ + rw [hs,rotate_insert] + rfl + +end Thorp +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω : Type*} [Fintype Ω] + +lemma sampleOperator_mul_const (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : + sampleOperator ρ (fun ω => P ω*g)=sampleOperator ρ P*continuousRepresentation ρ g := by + simp only [sampleOperator,map_mul,Finset.sum_mul,smul_mul_assoc] + +lemma sampleOperator_const_mul (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : + sampleOperator ρ (fun ω => g*P ω)=continuousRepresentation ρ g*sampleOperator ρ P := by + simp only [sampleOperator,map_mul,Finset.mul_sum,mul_smul_comm] + +lemma sampleOperator_run (d t : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + sampleOperator ρ (run d t)=(sampleOperator ρ (step d))^t := by + induction t with + | zero => exact sampleOperator_one ρ + | succ t ih => + let e : Coins d × (Fin t → Coins d) ≃ (Fin (t+1) → Coins d) := + Fin.snocEquiv (fun _ => Coins d) + have he : run d (t+1) ∘ e=fun w => step d w.1*run d t w.2 := by + funext w + simp only [Function.comp_apply,e,Fin.snocEquiv_apply, + run,Fin.snoc_last,Fin.snoc_castSucc] + rw [←sampleOperator_equiv ρ (run d (t+1)) e,he,sampleOperator_prod,ih,pow_succ'] + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite + +def carryCoins (d : ℕ) (i : Fin (d+1)) : (Bool → Coins (d+1)) ≃ Coins (d+2) where + toFun ξ y := ξ (y i) (Fin.removeNth i y) + invFun ξ b y := ξ (Fin.insertNth i b y) + left_inv ξ := by funext b y; simp + right_inv ξ := by funext y; simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma physical_carry_average (d : ℕ) (i : Fin d) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + sampleOperator ρ (step (d+1))*continuousRepresentation ρ (insertionPerm d i.succ)= + continuousRepresentation ρ (insertionPerm d i.castSucc)* + sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) := by + cases d with + | zero => exact Fin.elim0 i + | succ d => + have he : (fun ξ : Bool → Coins (d+1) => + step (d+2) (carryCoins d i ξ)*insertionPerm (d+1) i.succ)= + (fun ξ => insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b))) := by + funext ξ + exact physical_carry_step d i ξ + have h := congrArg (sampleOperator ρ) he + rw [sampleOperator_mul_const,sampleOperator_const_mul] at h + change sampleOperator ρ (step (d+2) ∘ carryCoins d i)*_=_ at h + rw [sampleOperator_equiv] at h + exact h + +theorem physical_sweep_recursion (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + (sampleOperator ρ (step (d+1)))^(d+1)= + (sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))))^d* + sampleOperator ρ (pairSwitch (d := d)) := by + let A := sampleOperator ρ (step (d+1)) + let K := sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) + have h (t : ℕ) (ht : t≤d) : A^t*continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)=K^t := by + induction t with + | zero => + change 1*continuousRepresentation ρ (insertionPerm d 0)=1 + rw [insertionPerm_zero,map_one,one_mul] + | succ t ih => + have hc := physical_carry_average d (⟨t,by omega⟩ : Fin d) ρ + change A*continuousRepresentation ρ (insertionPerm d ⟨t+1,by omega⟩)= + continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)*K at hc + rw [pow_succ,mul_assoc,hc,←mul_assoc,ih (by omega),←pow_succ] + have he : sampleOperator ρ (step (d+1))= + continuousRepresentation ρ (rotate (d+1))*sampleOperator ρ (pairSwitch (d := d)) := + sampleOperator_const_mul ρ (pairSwitch (d := d)) (rotate (d+1)) + calc + _ = A^d*A := pow_succ A d + _ = A^d*(continuousRepresentation ρ (insertionPerm d (Fin.last d))* + sampleOperator ρ (pairSwitch (d := d))) := by rw [insertionPerm_last]; rw [←he] + _ = _ := by + rw [←mul_assoc] + exact congrArg (fun z => z*sampleOperator ρ (pairSwitch (d := d))) (h d le_rfl) + +end Thorp +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite + +lemma childInjection_product (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + childInjection d false (p false)*childInjection d true (p true)=childLift p := by + change childLift _*childLift _=_ + rw [childLift_mul] + congr 1 + funext b + cases b <;> simp + +lemma childInjection_commute (d : ℕ) (p q : Equiv.Perm (Card d)) : + Commute (childInjection d false p) (childInjection d true q) := by + change childLift _*childLift _=childLift _*childLift _ + rw [childLift_mul,childLift_mul] + congr 1 + funext b + cases b <;> simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω : Type*} [Fintype Ω] + +lemma sampleOperator_child (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) + (P : Ω → Equiv.Perm (Card d)) : + sampleOperator ρ (fun ω : Bool → Ω => childLift (fun b => P (ω b)))= + sampleOperator (ρ.comp (childInjection d false)) P* + sampleOperator (ρ.comp (childInjection d true)) P := by + let e := (Equiv.boolArrowEquivProd Ω).symm + have he : (fun ω : Bool → Ω => childLift (fun b => P (ω b))) ∘ e= + fun w : Ω × Ω => childInjection d false (P w.1)*childInjection d true (P w.2) := by + funext w + change childLift (fun b => P (e w b))=_ + rw [←childInjection_product] + rfl + rw [←sampleOperator_equiv ρ _ e,he] + exact sampleOperator_prod ρ (fun w => childInjection d false (P w)) + (fun w => childInjection d true (P w)) + +lemma sampleOperator_child_commute (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) + (P : Ω → Equiv.Perm (Card d)) : + Commute (sampleOperator (ρ.comp (childInjection d false)) P) + (sampleOperator (ρ.comp (childInjection d true)) P) := by + rw [sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => childInjection_commute d _ _) + +lemma inverse_butterfly_average_step (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)= + sampleOperator ρ (fun ω : Bool → (SwitchIndex d → Bool) => + childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹))* + sampleOperator ρ (pairSwitch (d := d)) := by + let e := ((Equiv.prodCongr (Equiv.boolArrowEquivProd (SwitchIndex d → Bool)) (Equiv.refl (Card d → Bool))).trans + (coinStepEquiv d).symm) + have he : (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹) ∘ e= + fun w : (Bool → (SwitchIndex d → Bool)) × (Card d → Bool) => + childLift (fun b => (butterflyPerm d (decodeButterfly d (w.1 b)))⁻¹)*pairSwitch w.2 := by + funext w + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((w.1 false,w.1 true),w.2))))⁻¹=_ + rw [butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + congr 2 + funext b + cases b <;> rfl + rw [←sampleOperator_equiv ρ _ e,he] + exact sampleOperator_prod ρ + (fun ω : Bool → (SwitchIndex d → Bool) => childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹)) + (pairSwitch (d := d)) + +theorem physical_sweep_inverse_butterfly (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + (sampleOperator ρ (step d))^d= + sampleOperator ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹) := by + induction d with + | zero => + symm + exact sampleOperator_one ρ + | succ d ih => + rw [physical_sweep_recursion,sampleOperator_child, + (sampleOperator_child_commute d ρ (step d)).mul_pow,ih,ih, + inverse_butterfly_average_step] + rw [sampleOperator_child d ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹)] + +lemma physical_sweep_adjoint (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card d)) V) (hρ : IsUnitary ρ) : + sampleOperator ρ (run d d)= + (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by + rw [sampleOperator_run,physical_sweep_inverse_butterfly,sampleOperator_inv ρ hρ] + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical +open UnitaryFinite DimensionEstimates Filter + +lemma dimension_pos (μ : YoungDiagram) : 0 < Module.finrank ℂ (space μ) := by + have h := factorial_le_dimension_row_column μ + by_contra hn + have hz : Module.finrank ℂ (space μ)=0 := by omega + rw [hz,zero_mul,zero_mul] at h + exact (Nat.factorial_pos μ.card).not_ge h + +lemma near_numerical_cutoff : + ∃ X : ℝ, 2 ≤ X ∧ ∀ (N j D : ℕ), 0 < j → X ≤ (N:ℝ)/j → N.choose j ≤ D * 2^j → + ∃ k : ℕ, j ≤ k ∧ k ≤ N ∧ ∀ m : ℕ, D * k.choose j ≤ m * N.choose j → + nearFraction * Real.log D ≤ Real.log m ∧ + densityConstant * (k:ℝ) * ((k:ℝ)/N)^(1/512:ℝ) ≤ Real.log m/4000 ∧ + (1/2:ℝ) * Real.log N ≤ Real.log D ∧ (j:ℝ) ≤ Real.log D := by + obtain ⟨X,hX,h⟩ := exists_near_cutoff densityConstant densityConstant_pos.le + refine ⟨X,hX,?_⟩ + intro N j D hj hx hd + have hjN : j ≤ N := by + have hjp : (0:ℝ) < j := by exact_mod_cast hj + have hh : (j:ℝ) ≤ N := by + have := (le_div_iff₀ hjp).mp (hX.trans hx) + linarith + exact_mod_cast hh + have hc : 1 ≤ N.choose j := Nat.choose_pos hjN + have hfoot : D * (chosenTuple N j).choose j ≤ (D * (chosenTuple N j).choose j) * N.choose j := + Nat.le_mul_of_pos_right _ hc + have hh := h N j D _ hj hx hd hfoot + refine ⟨chosenTuple N j,hh.1,hh.2.1,?_⟩ + intro m hm + exact (h N j D m hj hx hd hm).2.2 + +lemma near_row_amplification (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) + {k : ℕ} (f : Fin k ↪ Card d) (hk : 0 rw [←Real.exp_log hθ,←Real.exp_nat_mul] + apply Real.exp_le_exp.mpr + have hg := mul_le_mul_of_nonpos_left (Nat.le_ceil (ε*M)) (Real.log_nonpos hθ.le hθ1.le) + nlinarith + +end Thorp.DimensionEstimates + +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +open DimensionEstimates +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +theorem medium_exception_decay (L r : ℕ) (h ε t : ℝ) (ht : 0≤t) + (hcount : t*ε+Real.log (1+Real.exp (-t))≤h*(2:ℝ)^L/16000) + (ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (hm : 0 q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hlow (ω : BenesCoins d) : q^(palindromeLowCost 1 d e ω) ≤ Real.exp (Fintype.card ι) := by - calc - _ ≤ q^(Fintype.card ι) := pow_le_pow_right₀ hq (by simpa using palindromeLowCost_le 1 d e ω) - _ = Real.exp (Fintype.card ι*Real.log q) := by rw [Real.exp_nat_mul,Real.exp_log hqp] - _ ≤ _ := Real.exp_le_exp.mpr (by nlinarith [Nat.cast_nonneg (α:=ℝ) (Fintype.card ι)]) - calc - _ ≤ finiteMean (fun ω : BenesCoins d => Real.exp (Fintype.card ι)* - q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) := by - apply finiteMean_mono - intro ω - rw [hcost,pow_add] - exact mul_le_mul_of_nonneg_right (hlow ω) (pow_nonneg hqp.le _) - _ = Real.exp (Fintype.card ι)*finiteMean (fun ω : BenesCoins d => - q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) := by simpa only [mul_comm] using finiteMean_mul_const (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) (Real.exp (Fintype.card ι)) - _ ≤ Real.exp (Fintype.card ι)*Real.exp (Fintype.card ι*heightDecay 1) := by - exact mul_le_mul_of_nonneg_left - (palindrome_high_full_mgf 1 d d (by decide) e q hq hlog) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add]; congr 1; ring - -lemma row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (a : ℝ) (ha : 0 < a) (ha32 : a ≤ 1/32) : - palindromeRowMoment d e a ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - let q : ℝ := (2:ℝ)^a - have hq : 1 ≤ q := Real.one_le_rpow (by norm_num) ha.le - have hlog : Real.log q ≤ 1/32 := by - dsimp [q] - rw [Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh - nlinarith - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 ha.le - have hm := palindrome_row_density_moment d e a ha.le - have he (c : ℕ) : q^c = (2:ℝ)^((c:ℝ)*a) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - simp_rw [←he] at hm - exact (hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) hq) _)) hpow)).trans - (palindrome_cost_mgf_coarse d e q hq hlog) - - -lemma applyKernel_mul {X : Type*} [Fintype X] (P Q : Matrix X X ℝ) - (v : EuclideanSpace ℂ X) : - DensityTransfer.applyKernel (fun x y => (P*Q) x y) v = - DensityTransfer.applyKernel (fun x y => P x y) (DensityTransfer.applyKernel (fun x y => Q x y) v) := by - apply PiLp.ext - intro x - change DensityTransfer.applyKernel (fun x y => (P*Q) x y) v x = DensityTransfer.applyKernel (fun x y => P x y) (DensityTransfer.applyKernel (fun x y => Q x y) v) x - simp only [DensityTransfer.applyKernel_apply,Matrix.mul_apply,Complex.ofReal_sum, - Complex.ofReal_mul,Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro y _ - apply Finset.sum_congr rfl - intro z _ - ring - -lemma applyKernel_one {X : Type*} [Fintype X] [DecidableEq X] - (v : EuclideanSpace ℂ X) : DensityTransfer.applyKernel (fun x y => (1 : Matrix X X ℝ) x y) v = v := by - apply PiLp.ext - intro x - change DensityTransfer.applyKernel (fun x y => (1 : Matrix X X ℝ) x y) v x = v x - simp [DensityTransfer.applyKernel_apply,Matrix.one_apply,apply_ite,ite_mul] - -lemma symmetric_hs_power {X : Type*} [Fintype X] [DecidableEq X] - (P : Matrix X X ℝ) (hs : P.IsSymm) (r : ℕ) : - (∑ x, ∑ y, ((P^r) x y)^2) = ∑ x, (P^(2*r)) x x := by - rw [two_mul,pow_add] - apply Finset.sum_congr rfl - intro x _ - simp only [Matrix.mul_apply] - apply Finset.sum_congr rfl - intro y _ - rw [(hs.pow r).apply x y,pow_two] - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] - -lemma trace_power_le_hs (A : V →L[ℂ] V) (hs : IsSelfAdjoint A) (hn : ‖A‖ ≤ 1) - (r : ℕ) : - (LinearMap.trace ℂ V ((A^(2*r+1)).toLinearMap)).re ≤ - ∑ j, ‖(A^r) (stdOrthonormalBasis ℂ V j)‖^2 := by - let B := stdOrthonormalBasis ℂ V - rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] - simp only [Matrix.trace,Matrix.diag,Complex.re_sum,LinearMap.toMatrix_apply, - OrthonormalBasis.coe_toBasis_repr_apply,OrthonormalBasis.repr_apply_apply] - apply Finset.sum_le_sum - intro j _ - have he : (A^(2*r+1)) (B j) = (A^r) (A ((A^r) (B j))) := by - have hnat : 2*r+1=r+(1+r) := by omega - rw [hnat,pow_add,pow_add,pow_one] - rfl - change (inner ℂ (B j) ((A^(2*r+1)) (B j))).re ≤ ‖(A^r) (B j)‖^2 - rw [he] - conv_lhs => rw [←(hs.pow r).adjoint_eq,ContinuousLinearMap.adjoint_inner_right] - rw [(hs.pow r).adjoint_eq] - apply (Complex.re_le_norm _).trans - apply (norm_inner_le_norm _ _).trans - have hh := A.le_opNorm ((A^r) (B j)) - have ha : ‖A ((A^r) (B j))‖ ≤ ‖(A^r) (B j)‖ := by - exact hh.trans (by simpa using mul_le_mul_of_nonneg_right hn (norm_nonneg _)) - nlinarith [norm_nonneg ((A^r) (B j))] - -open UnitaryFinite -lemma palindrome_selfadjoint (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : IsSelfAdjoint (sampleOperator ρ (palindromePerm d)) := by - rw [sampleOperator_palindrome _ _ hρ] - change IsSelfAdjoint (_ * star _) - simp only [isSelfAdjoint_iff,star_mul,star_star] - -variable {G X : Type*} [Group G] [Fintype G] [Fintype X] [DecidableEq X] - -lemma coefficient_trace_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) - [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (P : Matrix X X ℝ) (A : V →L[ℂ] V) - (hmap : ∀ w, IsFixed a x₀ ρ w → ∀ v, - DensityTransfer.applyKernel (fun x y => P x y) (normalizedCoefficient a x₀ ha ρ w v) = - normalizedCoefficient a x₀ ha ρ w (A v)) - (hs : IsSelfAdjoint A) (hn : ‖A‖ ≤ 1) (r : ℕ) : - (Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ) * - (LinearMap.trace ℂ V ((A^(2*r+1)).toLinearMap)).re ≤ - ∑ x, ∑ y, ((P^r) x y)^2 := by - let W := fixedSpace a x₀ ρ - let B := stdOrthonormalBasis ℂ V - let C := stdOrthonormalBasis ℂ W - let w : Fin (Module.finrank ℂ W) → V := fun i => (C i : V) - have hfix (i) : IsFixed a x₀ ρ (w i) := (C i).2 - have hw : Orthonormal ℂ w := C.orthonormal.comp_linearIsometry W.subtypeₗᵢ - let v : Fin (Module.finrank ℂ W) × Fin (Module.finrank ℂ V) → EuclideanSpace ℂ X := - fun ij => normalizedCoefficient a x₀ ha ρ (w ij.1) (B ij.2) - have hv : Orthonormal ℂ v := by - rw [orthonormal_iff_ite] - intro i j - dsimp [v] - rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix _) (hfix _)] - rw [(orthonormal_iff_ite.mp hw), (orthonormal_iff_ite.mp B.orthonormal)] - by_cases h1 : i.1=j.1 <;> by_cases h2 : i.2=j.2 <;> - simp [h1,h2,Prod.ext_iff,eq_comm] - have hp (s : ℕ) (i) (t : V) : - DensityTransfer.applyKernel (fun x y => (P^s) x y) (normalizedCoefficient a x₀ ha ρ (w i) t) = - normalizedCoefficient a x₀ ha ρ (w i) ((A^s) t) := by - induction s with - | zero => simp [applyKernel_one] - | succ s ih => - rw [pow_succ',applyKernel_mul,ih,hmap _ (hfix _),pow_succ'] - rfl - have hhs := DensityTransfer.hilbert_schmidt_family (fun x y => (P^r) x y) v hv - have he : (∑ ij, ‖DensityTransfer.applyKernel (fun x y => (P^r) x y) (v ij)‖^2) = - (Module.finrank ℂ W:ℝ) * ∑ j, ‖(A^r) (B j)‖^2 := by - simp only [v,hp,normalizedCoefficient_norm a x₀ ha ρ hρ _ (hfix _) - (hw.norm_eq_one _),Fintype.sum_prod_type] - simp - rw [he] at hhs - exact (mul_le_mul_of_nonneg_left (trace_power_le_hs A hs hn r) (by positivity)).trans hhs - -end Thorp.Casimir - -namespace Thorp.Casimir -open scoped BigOperators Classical -open UnitaryFinite - -section -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def tupleKernel (d k : ℕ) : Matrix (Fin k ↪ Card d) (Fin k ↪ Card d) ℝ := - fun x y => PairRouting.tupleProbability (palindromePerm d) x y - -lemma palindrome_trace_amplification (d k : ℕ) (x₀ : Fin k ↪ Card d) - (ρ : Representation ℂ (Equiv.Perm (Card d)) V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (r : ℕ) : - (Module.finrank ℂ (fixedSpace tupleAction x₀ ρ):ℝ) * - (LinearMap.trace ℂ V (((sampleOperator ρ (palindromePerm d))^(2*r+1)).toLinearMap)).re ≤ - ∑ x, ∑ y, ((tupleKernel d k)^r) x y ^ 2 := by - let ha := tupleAction_transitive x₀ - have hmap (w : V) (hw : IsFixed tupleAction x₀ ρ w) (v : V) : - DensityTransfer.applyKernel (fun x y : Fin k ↪ Card d => - PairRouting.tupleProbability (palindromePerm d) x y) - (normalizedCoefficient tupleAction x₀ ha ρ w v) = - normalizedCoefficient tupleAction x₀ ha ρ w (sampleOperator ρ (palindromePerm d) v) := by - have hh := coefficient_random tupleAction x₀ ha ρ hρ (palindromePerm d) w hw v - have he : actionKernel tupleAction (palindromePerm d) = - fun x y : Fin k ↪ Card d => PairRouting.tupleProbability (palindromePerm d) x y := by - funext x y - exact tupleAction_kernel _ x y - rw [he,←sampleOperator_inv_apply,sampleOperator_inv _ hρ, - (palindrome_selfadjoint d ρ hρ).adjoint_eq] at hh - exact hh - exact coefficient_trace_amplification tupleAction x₀ ha ρ hρ _ _ hmap - (palindrome_selfadjoint d ρ hρ) (sampleOperator_norm_le ρ hρ _) r - -end - -lemma tupleKernel_symm (d k : ℕ) : (tupleKernel d k).IsSymm := by - ext x y - exact palindrome_kernel_symmetric d y x - -lemma tupleKernel_power64 (d k : ℕ) (x y : Fin k ↪ Card d) : - ((tupleKernel d k)^64) x y ≤ - Real.exp ((64*(1+heightDecay 1))*k)/(Fintype.card (Fin k ↪ Card d):ℝ) := by - let : Nonempty (Fin k ↪ Card d) := ⟨x⟩ - have hr (x : Fin k ↪ Card d) : ∑ y, tupleKernel d k x y = 1 := - PairRouting.tupleProbability_row_sum _ x - have hc (y : Fin k ↪ Card d) : ∑ x, tupleKernel d k x y = 1 := by - simp_rw [(tupleKernel_symm d k).apply y] - exact hr y - have hm (x : Fin k ↪ Card d) : - finiteMean (fun y => ((Fintype.card (Fin k ↪ Card d):ℝ)*tupleKernel d k x y)^ - (1+(1/32:ℝ))) ≤ Real.exp ((k:ℝ)*(1+heightDecay 1)) := by - simpa only [palindromeRowMoment,Fintype.card_fin,tupleKernel] using - row_moment_coarse d x (1/32) (by norm_num) (by norm_num) - have hnum : 2 ≤ (1+(1/32:ℝ))^(32:ℕ) := by - have hh := one_add_mul_le_pow (a := (1/32:ℝ)) (by norm_num) 32 - norm_num at hh ⊢ - have hh := StrongSmoothing.symmetric_kernel_smoothing (tupleKernel d k) - (fun x y => PairRouting.tupleProbability_nonneg _ x y) hr hc (tupleKernel_symm d k) - (p := 1+(1/32:ℝ)) (A := k*(1+heightDecay 1)) (by norm_num) - (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) hm 32 hnum x y - have he : 2*((k:ℝ)*(1+heightDecay 1))*(32:ℝ) = (64*(1+heightDecay 1))*k := by ring - simpa only [show 2*32=64 by norm_num,Nat.cast_ofNat,he] using hh - -lemma K_selfadjoint (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : - @IsSelfAdjoint _ (ContinuousLinearMap.instStarId (𝕜:=ℂ) (E:=Specht.hilbertSpace μ)) (K d μ e) := by - exact palindrome_selfadjoint (V:=Specht.hilbertSpace μ) d _ (Specht.relabelledUnitary_unitary μ e) - -lemma K_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : - ‖K d μ e‖ ≤ 1 := - sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ - -lemma fixed_trace_bound (d k : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (x₀ : Fin k ↪ Card d) : - (Module.finrank ℂ (fixedSpace (V := Specht.hilbertSpace μ) tupleAction x₀ - (Specht.relabelledUnitary μ e)):ℝ) * traceMoment d μ e 65 ≤ - Real.exp ((64*(1+heightDecay 1))*k) := by - let ρ := Specht.relabelledUnitary μ e - let := Specht.relabelledUnitary_irreducible μ e - have hh := palindrome_trace_amplification (V:=Specht.hilbertSpace μ) d k x₀ ρ - (Specht.relabelledUnitary_unitary μ e) 32 - change _ * traceMoment d μ e 65 ≤ _ at hh - rw [symmetric_hs_power _ (tupleKernel_symm d k)] at hh - apply hh.trans - have hX : (0:ℝ) < Fintype.card (Fin k ↪ Card d) := by - let : Nonempty (Fin k ↪ Card d) := ⟨x₀⟩ - exact Nat.cast_pos.mpr Fintype.card_pos - calc - _ ≤ ∑ x : Fin k ↪ Card d, - Real.exp ((64*(1+heightDecay 1))*k)/(Fintype.card (Fin k ↪ Card d):ℝ) := - Finset.sum_le_sum (fun x _ => tupleKernel_power64 d k x x) - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel₀ _ (ne_of_gt hX) - -lemma levelScale_ge (n k : ℕ) (hk : k ≤ n) : (k:ℝ) ≤ levelScale n k := by - by_cases h : k=0 - · simp [h,levelScale] - have hkp : (0:ℝ) A v) - (uniformOperator_left (V:=Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) g) - exact he - -lemma gap_of_uniform_zero {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) (hz : uniformOperator ρ=0) : - ‖sampleOperator ρ (palindromePerm d)‖ ≤ blockGap d := by - have hh := palindrome_off_invariants_gap d ρ hρ - rw [hz,sub_zero,←sampleOperator_weighted] at hh - exact hh - -lemma nontrivial_gap (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : 0<μ.card-μ.rowLen 0) : ‖K d μ e‖ ≤ blockGap d := by - exact gap_of_uniform_zero (V:=Specht.hilbertSpace μ) d _ - (Specht.relabelledUnitary_unitary μ e) (nontrivial_uniform_zero d μ e hk) - -lemma eventual_level_dimension : - ∃ η : ℝ, 0<η ∧ ∀ᶠ d : ℕ in atTop, - ∀ μ : YoungDiagram, μ.card=2^d → 0<μ.card-μ.rowLen 0 → - (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2 → - η*levelScale (2^d) (μ.card-μ.rowLen 0) ≤ - Real.log (Module.finrank ℂ (Specht.space μ)) := by - obtain ⟨h,hh,hm⟩ := Specht.medium_dimension (1/16) (by norm_num) (by norm_num) - refine ⟨min (1/3) h,lt_min (by norm_num) hh,?_⟩ - filter_upwards [twopow_nat_tendsto.eventually hm] with d hd - intro μ hμ hk hc - let k := μ.card-μ.rowLen 0 - have hkn : k≤2^d := by dsimp [k]; omega - have hΛ : 0≤levelScale (2^d) k := (Nat.cast_nonneg k).trans (levelScale_ge _ _ hkn) - have hr : ((μ.card-μ.rowLen 0:ℕ):ℝ)=(μ.card:ℝ)-μ.rowLen 0 := - Nat.cast_sub (Specht.rowLen_zero_le_card μ) - by_cases hs : (k:ℝ)≤(2^d:ℕ)/16 - · have hk2 : 2*k≤2^d := by exact_mod_cast (show (2:ℝ)*k≤(2^d:ℕ) by linarith) - have hdim := DimensionEstimates.near_row_log_dimension (2^d) k _ hk hk2 - (by simpa only [←hμ] using Specht.choose_tail_le_dimension μ) - have hkp : (0:ℝ) exact ⟨1,by norm_num,by omega⟩ - | succ D ih => - obtain ⟨b,hb,hh⟩ := ih (fun d hd => hf d (by omega)) - refine ⟨min b (f D),lt_min hb (hf D (by omega)),?_⟩ - intro d hd - by_cases he : d=D - · subst d; exact min_le_right _ _ - · exact (min_le_left _ _).trans (hh d (by omega)) - -theorem level_contraction : - ∃ a : ℝ, 0 hf d) - refine ⟨min a b,lt_min ha hb,?_⟩ - intro d μ e hk - have hμ : μ.card=2^d := by rw [←Specht.card_cell,←Fintype.card_congr e,card_positions] - have hkn : μ.card-μ.rowLen 0≤2^d := by omega - have hΛ : 0≤levelScale (2^d) (μ.card-μ.rowLen 0) := - (Nat.cast_nonneg _).trans (levelScale_ge _ _ hkn) - by_cases hd : D≤d - · apply (hD d hd μ e hk).trans (Real.exp_le_exp.mpr _) - have hh := mul_le_mul_of_nonneg_right (min_le_left a b) hΛ - linarith - · have hab : min a b≤f d := (min_le_right _ _).trans (hbD d (by omega)) - have hscale : levelScale (2^d) (μ.card-μ.rowLen 0) ≤ (2:ℝ)^d := by - simpa only [Nat.cast_pow,Nat.cast_ofNat] using levelScale_le (2^d) _ (by positivity) hkn - have hprod := mul_le_mul_of_nonneg_right hab (by positivity : (0:ℝ)≤(2:ℝ)^d) - have hfprod : f d*(2:ℝ)^d = -Real.log (blockGap d) := by dsimp [f]; field_simp - rw [hfprod] at hprod - have hs := mul_le_mul_of_nonneg_left hscale (le_of_lt (lt_min ha hb)) - calc - _ ≤ blockGap d := nontrivial_gap d μ e hk - _ = Real.exp (Real.log (blockGap d)) := (Real.exp_log (blockGap_pos d)).symm - _ ≤ _ := Real.exp_le_exp.mpr (by linarith) - -end Thorp.Casimir - -namespace Thorp.Specht -open scoped BigOperators Classical -open UnitaryFinite - -noncomputable def cardLabels (d : ℕ) (μ : Shapes (2^d)) : Card d ≃ Cell μ.1 := - ((Fintype.equivFin (Card d)).trans (finCongr (card_positions d))).trans (labels μ).symm - -noncomputable def cardRepresentation (d : ℕ) (μ : Shapes (2^d)) : - Representation ℂ (Equiv.Perm (Card d)) (hilbertSpace μ.1) := - relabelledUnitary μ.1 (cardLabels d μ) - -lemma cardRepresentation_unitary (d : ℕ) (μ : Shapes (2^d)) : - IsUnitary (V := hilbertSpace μ.1) (cardRepresentation d μ) := - relabelledUnitary_unitary _ _ - -noncomputable instance cardRepresentation_irreducible (d : ℕ) (μ : Shapes (2^d)) : - Representation.IsIrreducible (cardRepresentation d μ) := - relabelledUnitary_irreducible _ _ - -lemma relabelledUnitary_neq {α : Type*} (μ ν : YoungDiagram) - (e : α ≃ Cell μ) (f : α ≃ Cell ν) - (T : Representation.Equiv (relabelledUnitary μ e) (relabelledUnitary ν f)) : μ=ν := by - let S := (spaceHilbertEquiv μ).trans (T.toLinearEquiv.trans (spaceHilbertEquiv ν).symm) - apply shapes_eq_of_equivariant_equiv μ ν (e.symm.trans f) S - intro p v - have hT := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap - (e.symm.permCongr p) (spaceHilbertEquiv μ v) - change T.toLinearEquiv (spaceHilbertEquiv μ - (representation μ (e.permCongr (e.symm.permCongr p)) - ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))))= - spaceHilbertEquiv ν (representation ν (f.permCongr (e.symm.permCongr p)) - ((spaceHilbertEquiv ν).symm (T.toLinearEquiv (spaceHilbertEquiv μ v)))) at hT - have he : e.permCongr (e.symm.permCongr p)=p := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] - have hf : f.permCongr (e.symm.permCongr p)=(e.symm.trans f).permCongr p := by - apply Equiv.ext - intro x - rfl - rw [he,hf,LinearEquiv.symm_apply_apply] at hT - have ht := congrArg (spaceHilbertEquiv ν).symm hT - simpa only [LinearEquiv.symm_apply_apply,S,LinearEquiv.trans_apply] using ht - -lemma cardRepresentation_distinct (d : ℕ) (μ ν : Shapes (2^d)) (hne : μ≠ν) : - ¬Nonempty (Representation.Equiv (cardRepresentation d μ) (cardRepresentation d ν)) := by - rintro ⟨T⟩ - exact hne (Subtype.ext (relabelledUnitary_neq μ.1 ν.1 (cardLabels d μ) (cardLabels d ν) T)) - -lemma card_conjugacy_shapes (d : ℕ) : - Nat.card (ConjClasses (Equiv.Perm (Card d)))≤Fintype.card (Shapes (2^d)) := by - have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Card d)) - simpa only [card_positions,Nat.card_eq_fintype_card,Fintype.card_congr (shapePartitionEquiv (2^d))] using h - -lemma row_zero_of_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) (x : Cell μ) : row x=0 := by - have hr : μ.row 0=μ.cells := Finset.eq_of_subset_of_card_le - (Finset.filter_subset _ _) (by rw [←μ.rowLen_eq_card]; exact hμ.ge) - have hx : x.1∈μ.row 0 := by rw [hr]; exact x.2 - exact (YoungDiagram.mem_row_iff.mp hx).2 - -lemma tabloid_subsingleton_of_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) : - Subsingleton (Tabloid μ) := by - refine ⟨fun f g => ?_⟩ - apply Subtype.ext - funext x - obtain ⟨p,hp⟩ := f.2 - obtain ⟨q,hq⟩ := g.2 - simp only [hp,hq,Function.comp_apply] - apply Fin.ext - exact (row_zero_of_full_row μ hμ (p x)).trans (row_zero_of_full_row μ hμ (q x)).symm - -lemma representation_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) - (p : Equiv.Perm (Cell μ)) : representation μ p=1 := by - let := tabloid_subsingleton_of_full_row μ hμ - apply LinearMap.ext - intro v - apply Subtype.ext - funext f - change v.1 (tabloidAct p⁻¹ f)=v.1 f - rw [show tabloidAct p⁻¹ f=f from Subsingleton.elim _ _] - -lemma relabelled_full_row {α : Type*} (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) - (e : α ≃ Cell μ) (p : Equiv.Perm α) : relabelledUnitary μ e p=1 := by - change ((spaceHilbertEquiv μ).conjAlgEquiv ℂ) (representation μ (e.permCongr p))=1 - rw [representation_full_row μ hμ,map_one] - -end Thorp.Specht -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G Ω V : Type*} [Group G] [Fintype G] [Fintype Ω] [Nonempty Ω] - [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma sample_uniform_left (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by - rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -lemma uniform_zero_of_sample_norm_lt_one (ρ : Representation ℂ G V) (P : Ω → G) - (h : ‖sampleOperator ρ P‖<1) : uniformOperator ρ=0 := by - have hn := norm_mul_le (sampleOperator ρ P) (uniformOperator ρ) - rw [sample_uniform_left] at hn - apply norm_eq_zero.mp - nlinarith [norm_nonneg (uniformOperator ρ)] - -omit [Fintype G] in -lemma sampleOperator_trivial (ρ : Representation ℂ G V) (hρ : ∀ g,ρ g=1) (P : Ω → G) : - sampleOperator ρ P=1 := by - convert sampleOperator_one (Ω := Ω) ρ using 1 - unfold sampleOperator - congr 1 - apply Finset.sum_congr rfl - intro ω _ - apply ContinuousLinearMap.ext - intro v - change ρ (P ω) v=ρ 1 v - rw [hρ,hρ] - -lemma uniformOperator_trivial (ρ : Representation ℂ G V) (hρ : ∀ g,ρ g=1) : - uniformOperator ρ=1 := by - rw [←sampleOperator_uniform] - exact sampleOperator_trivial ρ hρ id - -lemma weighted_sub (ρ : Representation ℂ G V) (p q : G → ℝ) : - weightedOperator ρ (fun g => p g-q g)=weightedOperator ρ p-weightedOperator ρ q := by - simp only [weightedOperator,Complex.ofReal_sub,sub_smul,Finset.sum_sub_distrib] - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma physical_palindrome_norm (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : - ‖sampleOperator ρ (run d d)‖^2=‖sampleOperator ρ (palindromePerm d)‖ := by - rw [physical_sweep_adjoint d ρ hρ,sampleOperator_palindrome d ρ hρ] - have h := ContinuousLinearMap.norm_adjoint_comp_self - ((sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint) - rw [ContinuousLinearMap.adjoint_adjoint] at h - simpa only [ContinuousLinearMap.mul_def,←sq] using h.symm - -lemma physical_power_bound (d C : ℕ) (hC : 0 < C) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : - ‖sampleOperator ρ (run d (C*d))‖^2≤‖sampleOperator ρ (palindromePerm d)‖^C := by - have he : sampleOperator ρ (run d (C*d))=(sampleOperator ρ (run d d))^C := by - simp only [sampleOperator_run,←pow_mul,Nat.mul_comm C d] - rw [he,←physical_palindrome_norm d ρ hρ] - calc - _ ≤ (‖sampleOperator ρ (run d d)‖^C)^2 := - pow_le_pow_left₀ (norm_nonneg _) (norm_pow_le' _ hC) _ - _ = _ := by rw [←pow_mul,←pow_mul,Nat.mul_comm C 2] - -end Thorp -namespace Thorp.Specht -open scoped BigOperators Classical - -section -open UnitaryFinite - -lemma card_fourier_decay (d C : ℕ) (μ : Shapes (2^d)) (a s : ℝ) - (ha : 0 < a) (hs : 0 ≤ s) (hC : s+2 ≤ a*C) - (hD : 1≤Real.log (Module.finrank ℂ (space μ.1))) - (hK : ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (palindromePerm d)‖≤ - Real.exp (-a*Real.log (Module.finrank ℂ (space μ.1)))) : - (Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2* - ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d))-uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2≤ - Real.exp (-s*Real.log (Module.finrank ℂ (space μ.1))) := by - let : NormedAddCommGroup (hilbertSpace μ.1) := inferInstance - let : InnerProductSpace ℂ (hilbertSpace μ.1) := inferInstance - let : FiniteDimensional ℂ (hilbertSpace μ.1) := inferInstance - have hu : uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)=0 := - uniform_zero_of_sample_norm_lt_one _ (palindromePerm d) (hK.trans_lt (by - rw [Real.exp_lt_one_iff]; nlinarith)) - rw [hu,sub_zero,finrank_hilbertSpace] - have hCp : 0 < C := by - by_contra hn - have hz : C=0 := by omega - rw [hz,Nat.cast_zero,mul_zero] at hC - linarith - have hp := physical_power_bound d C hCp (cardRepresentation d μ) (cardRepresentation_unitary d μ) - have hkpow := pow_le_pow_left₀ (norm_nonneg _) hK C - have hDp : (0:ℝ) simp - | succ n ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring - rw [he] - nlinarith [pow_nonneg (by norm_num : (0:ℝ)≤1/2) n] - -lemma shape_weight_sum (N : ℕ) : - (∑ μ : Shapes N,(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0))≤2 := by - have he := Finset.sum_fiberwise_of_maps_to' - (s := (Finset.univ : Finset (Shapes N))) (t := Finset.range (N+1)) - (g := fun μ : Shapes N => μ.1.card-μ.1.rowLen 0) - (by intro μ _; simp only [Finset.mem_range]; have := μ.2; omega) - (fun j => (1/4:ℝ)^j) - rw [←he] - apply le_trans _ (half_geom_sum (N+1)) - apply Finset.sum_le_sum - intro j _ - have hc : ((Finset.univ.filter (fun μ : Shapes N => μ.1.card-μ.1.rowLen 0=j)).card:ℝ)≤(2:ℝ)^j := by - have hh := tail_shapes_count N j - rw [Fintype.card_subtype] at hh - exact_mod_cast hh - simp only [Finset.sum_const,nsmul_eq_mul] - calc - _ ≤ (2:ℝ)^j*(1/4:ℝ)^j := mul_le_mul_of_nonneg_right hc (by positivity) - _ = (1/2:ℝ)^j := by rw [←mul_pow]; norm_num - -lemma near_shape_term (N j : ℕ) (L s : ℝ) (hN : 0 z/(Fintype.card (Fin t → Coins d):ℝ)) - convert Finset.sum_boole (R := ℝ) (fun x => run d t x = g) Finset.univ using 1 - apply Finset.sum_congr rfl - intro ω _ - split_ifs with h <;> simp only [h, ite_true, ite_false] - -lemma physical_fourier_bound (d t : ℕ) : - distance d t^2≤∑ μ : Shapes (2^d),(Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2* - ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t)- - uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2 := by - let V : Shapes (2^d) → Type := fun μ => hilbertSpace μ.1 - let : ∀ μ,NormedAddCommGroup (V μ) := fun _ => inferInstance - let : ∀ μ,InnerProductSpace ℂ (V μ) := fun _ => inferInstance - let : ∀ μ,FiniteDimensional ℂ (V μ) := fun _ => inferInstance - let p := fun g : Equiv.Perm (Card d) => law d t g-1/(Nat.factorial (2^d):ℝ) - have hb := FiniteFourier.l1_fourier_bound V (cardRepresentation d) - (cardRepresentation_unitary d) (cardRepresentation_distinct d) (card_conjugacy_shapes d) p - have he (μ : Shapes (2^d)) : weightedOperator (V := V μ) (cardRepresentation d μ) p= - sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t)- - uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) := by - rw [sampleOperator_weighted,sampleLaw_run] - dsimp only [p] - rw [weighted_sub] - congr 1 - unfold uniformOperator - rw [card_permutations] - simp only [one_div] - simp_rw [he] at hb - apply le_trans _ hb - change ((1/2:ℝ)*(∑ g,|p g|))^2≤(∑ g,|p g|)^2 - nlinarith [sq_nonneg (∑ g,|p g|)] - -theorem eventual_physical_bound : - ∃ C : ℕ, 0 hbound μ) - _ = (1/(2:ℝ)^d)*(∑ μ : Shapes (2^d),(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0))+ - (Fintype.card (Shapes (2^d)):ℝ)*Real.exp (-s*h*(2:ℝ)^d) := by - rw [Finset.sum_add_distrib,←Finset.mul_sum,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ ≤ (1/(2:ℝ)^d)*2+Real.exp (-(2:ℝ)^d) := by - apply add_le_add - · exact mul_le_mul_of_nonneg_left (shape_weight_sum (2^d)) (by positivity) - · simpa only [Nat.cast_pow,Nat.cast_ofNat] using shapes_medium_sum (2^d) h s hsh - _ = _ := by ring - -end -open Filter DimensionEstimates - -lemma physical_convergence : ∃ C : ℕ, 0 distance d (C*d)) atTop (nhds 0) := by - obtain ⟨C,hC,hbound⟩ := eventual_physical_bound - refine ⟨C,hC,?_⟩ - have hrec : Tendsto (fun d : ℕ => 2/(2:ℝ)^d) atTop (nhds 0) := - tendsto_const_nhds.div_atTop twopow_tendsto - have hexp : Tendsto (fun d : ℕ => Real.exp (-(2:ℝ)^d)) atTop (nhds 0) := - Real.tendsto_exp_neg_atTop_nhds_zero.comp twopow_tendsto - have hr : Tendsto (fun d : ℕ => 2/(2:ℝ)^d+Real.exp (-(2:ℝ)^d)) atTop (nhds 0) := by - simpa only [zero_add] using hrec.add hexp - have hsq : Tendsto (fun d : ℕ => distance d (C*d)^2) atTop (nhds 0) := - squeeze_zero' (Eventually.of_forall (fun d => sq_nonneg (distance d (C*d)))) hbound hr - have hs := (Real.continuous_sqrt.tendsto (0:ℝ)).comp hsq - have he : (Real.sqrt ∘ fun d : ℕ => distance d (C*d)^2)=(fun d => distance d (C*d)) := by - funext d - exact Real.sqrt_sq (distance_nonneg _ _) - rw [he,Real.sqrt_zero] at hs - exact hs - -end Thorp - -namespace Thorp.Casimir -open scoped BigOperators Classical -open Filter UnitaryFinite - -lemma K_source_square (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : - K d μ e = (ContinuousLinearMap.adjoint (𝕜:=ℂ) (E:=Specht.hilbertSpace μ) (F:=Specht.hilbertSpace μ) - (SparseContact.sweepOperator d μ e true)) * - SparseContact.sweepOperator d μ e true := by - simp only [SparseContact.sweepOperator,ite_true] - rw [sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), - ContinuousLinearMap.adjoint_adjoint] - exact sampleOperator_palindrome _ _ (Specht.relabelledUnitary_unitary μ e) - -lemma density_bound (d k : ℕ) (hk : k≤2^d) (x : Fin k ↪ Card d) : - (palindromeRowMoment d x (1/64))^(64/65:ℝ) ≤ - Real.exp ((1+64*(1+heightDecay 1))*levelScale (2^d) k) := by - have hm := row_moment_coarse d x (1/64) (by norm_num) (by norm_num) - have hh := Real.rpow_le_rpow (palindromeRowMoment_nonneg d x (1/64)) hm - (by norm_num : (0:ℝ)≤64/65) - simp only [Fintype.card_fin] at hh - apply hh.trans - rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hL := levelScale_ge (2^d) k hk - have hA := heightDecay_nonneg 1 - have hk0 : (0:ℝ)≤k := by positivity - nlinarith - -lemma fromDistance_eq (d t : ℕ) (σ : Equiv.Perm (Card d)) : fromDistance d t σ=distance d t := by - unfold fromDistance distance - congr 1 - exact Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ (fun _ => rfl) - -lemma trace_real {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (A : V →L[ℂ] V) (hA : IsSelfAdjoint A) : - (((LinearMap.trace ℂ V A.toLinearMap).re : ℝ):ℂ) = LinearMap.trace ℂ V A.toLinearMap := by - let B := stdOrthonormalBasis ℂ V - rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] - simp only [Matrix.trace,Matrix.diag,Complex.re_sum,Complex.ofReal_sum, - LinearMap.toMatrix_apply,OrthonormalBasis.coe_toBasis_repr_apply, - OrthonormalBasis.repr_apply_apply] - apply Finset.sum_congr rfl - intro j _ - exact hA.isSymmetric.coe_re_inner_self_apply (B j) - -lemma trace_power_real {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (A : V →L[ℂ] V) (hA : IsSelfAdjoint A) (r : ℕ) : - (((LinearMap.trace ℂ V (A^r).toLinearMap).re : ℝ):ℂ) = - LinearMap.trace ℂ V (A^r).toLinearMap := trace_real _ (hA.pow r) - -lemma traceMoment_real (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (r : ℕ) : - (traceMoment d μ e r:ℂ) = - LinearMap.trace ℂ (Specht.hilbertSpace μ) ((K d μ e)^r).toLinearMap := by - exact trace_power_real (V:=Specht.hilbertSpace μ) _ (K_selfadjoint d μ e) r - -theorem casimir_main : MainStatement := by - obtain ⟨a,ha,hnorm⟩ := level_contraction - refine ⟨a,1+64*(1+heightDecay 1),ha,by linarith [heightDecay_nonneg 1],?_,?_,?_⟩ - · intro d k _ hk x - exact density_bound d k hk x - · intro d μ e hk - exact ⟨hnorm d μ e hk,trace_bound d μ e⟩ - · obtain ⟨l,hl,hm⟩ := physical_convergence - refine ⟨l,hl,fun starts => ?_⟩ - simpa only [fromDistance_eq] using hm - -end Thorp.Casimir - -namespace Thorp.StrongTail -open scoped BigOperators Classical -open Specht UnitaryFinite - -def MainStatement : Prop := - ∃ p Cdensity C : ℝ, 1 < p ∧ p ≤ 2 ∧ DensityAt p Cdensity ∧ - ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool), - ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ - Real.exp (C*(μ.card-μ.rowLen 0 : ℕ)) * - (Module.finrank ℂ (Specht.space (tailDiagram μ)):ℝ)^(-((p-1)/p)) - -lemma dimension_le_factorial (μ : YoungDiagram) : - Module.finrank ℂ (space μ) ≤ μ.card.factorial := by - have hdim : Module.finrank ℂ (space μ) ≤ Fintype.card (Tabloid μ) := by - simpa using Submodule.finrank_le (space μ) - have hrow : 1 ≤ Fintype.card (rowGroup μ) := Fintype.card_pos - have hc := card_tabloid_mul_row μ - nlinarith - -lemma tail_card_exact (μ : YoungDiagram) : - (tailDiagram μ).card = μ.card - μ.rowLen 0 := by - rw [←card_cell,Fintype.card_congr (tailCellEquiv μ),tail_card] - -lemma tail_dimension_le_factorial (μ : YoungDiagram) : - Module.finrank ℂ (space (tailDiagram μ)) ≤ (μ.card - μ.rowLen 0).factorial := by - simpa only [tail_card_exact] using dimension_le_factorial (tailDiagram μ) - -lemma sweep_sq_palindrome (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : - ‖SparseContact.sweepOperator d μ e rev‖^2 = - ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ := by - rw [SparseContact.sweep_forward_norm, sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e)] - change ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))‖^2 = _ - rw [show (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint = - star (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))) from rfl] - simpa only [pow_two] using (CStarRing.norm_self_mul_star (x := sampleOperator (V := hilbertSpace μ) - (relabelledUnitary μ e) (fun ω => butterflyPerm d (decodeButterfly d ω)))).symm - -lemma sweep_sq_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : - ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ 1 := by - have h := SparseContact.sweep_norm_le_one d μ e rev - nlinarith [norm_nonneg (SparseContact.sweepOperator d μ e rev)] - -theorem strong_tail : MainStatement := by - obtain ⟨a,h,ha,hh,dE⟩ := Specht.spectral_regimes - obtain ⟨D0,hD0⟩ := Filter.eventually_atTop.mp dE - let d0 := max D0 1 - let t : ℝ := min a (1/1000) - have ht : 0 < t := lt_min ha (by norm_num) - have hta : t ≤ a := min_le_left _ _ - have htq : t ≤ 1/1000 := min_le_right _ _ - let b := t/(1+t) - have hden : 0 < 1+t := by linarith - have hb : 0 < b := div_pos ht hden - have hbt : b ≤ t := (div_le_iff₀ hden).mpr (by nlinarith [sq_nonneg t]) - have hba : b ≤ a := hbt.trans hta - have hb1 : b ≤ 1 := (div_le_one hden).mpr (by linarith) - let C := Real.log (((2^d0).factorial:ℕ):ℝ) - have hC : 0 ≤ C := Real.log_nonneg (by exact_mod_cast Nat.factorial_pos (2^d0)) - refine ⟨1+t,3+heightDecay 1,C,by linarith,by linarith, - density_at_small_exponent (by linarith) (by linarith),?_⟩ - intro d μ e rev - let k := μ.card - μ.rowLen 0 - let D : ℝ := Module.finrank ℂ (space (tailDiagram μ)) - have hD : 1 ≤ D := by dsimp [D]; exact_mod_cast dimension_pos (tailDiagram μ) - have hDp : 0 < D := by linarith - have hlog : 0 ≤ Real.log D := Real.log_nonneg hD - have hμ : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions] - have hform : -(((1+t)-1)/(1+t)) = -b := by dsimp [b]; congr 1; ring - rw [hform] - change ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ Real.exp (C*k)*D^(-b) - rw [Real.rpow_def_of_pos hDp,←Real.exp_add] - by_cases hk : k=0 - · have hDone : D=1 := by - have hn := tail_dimension_le_factorial μ - change Module.finrank ℂ (space (tailDiagram μ)) ≤ k.factorial at hn - rw [hk,Nat.factorial_zero] at hn - have hu : D ≤ 1 := by dsimp [D]; exact_mod_cast hn - linarith - rw [hk,Nat.cast_zero,mul_zero,hDone,Real.log_one,zero_mul,add_zero,Real.exp_zero] - exact sweep_sq_le_one d μ e rev - · have hkpos : 0 hf d) - refine ⟨min a b,lt_min ha hb,?_⟩ - intro d μ e hk - have hμ : μ.card=2^d := by rw [←Specht.card_cell,←Fintype.card_congr e,card_positions] - have hDpos : (0:ℝ) q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hlow (ω : BenesCoins d) : q^(palindromeLowCost 1 d e ω) ≤ Real.exp (Fintype.card ι) := by + calc + _ ≤ q^(Fintype.card ι) := pow_le_pow_right₀ hq (by simpa using palindromeLowCost_le 1 d e ω) + _ = Real.exp (Fintype.card ι*Real.log q) := by rw [Real.exp_nat_mul,Real.exp_log hqp] + _ ≤ _ := Real.exp_le_exp.mpr (by nlinarith [Nat.cast_nonneg (α:=ℝ) (Fintype.card ι)]) + calc + _ ≤ finiteMean (fun ω : BenesCoins d => Real.exp (Fintype.card ι)* + q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) := by + apply finiteMean_mono + intro ω + rw [hcost,pow_add] + exact mul_le_mul_of_nonneg_right (hlow ω) (pow_nonneg hqp.le _) + _ = Real.exp (Fintype.card ι)*finiteMean (fun ω : BenesCoins d => + q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) := by simpa only [mul_comm] using finiteMean_mul_const (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) (Real.exp (Fintype.card ι)) + _ ≤ Real.exp (Fintype.card ι)*Real.exp (Fintype.card ι*heightDecay 1) := by + exact mul_le_mul_of_nonneg_left + (palindrome_high_full_mgf 1 d d (by decide) e q hq hlog) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add]; congr 1; ring + +lemma row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (a : ℝ) (ha : 0 < a) (ha32 : a ≤ 1/32) : + palindromeRowMoment d e a ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + let q : ℝ := (2:ℝ)^a + have hq : 1 ≤ q := Real.one_le_rpow (by norm_num) ha.le + have hlog : Real.log q ≤ 1/32 := by + dsimp [q] + rw [Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh + nlinarith + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 ha.le + have hm := palindrome_row_density_moment d e a ha.le + have he (c : ℕ) : q^c = (2:ℝ)^((c:ℝ)*a) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + simp_rw [←he] at hm + exact (hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) hq) _)) hpow)).trans + (palindrome_cost_mgf_coarse d e q hq hlog) + + +lemma applyKernel_mul {X : Type*} [Fintype X] (P Q : Matrix X X ℝ) + (v : EuclideanSpace ℂ X) : + DensityTransfer.applyKernel (fun x y => (P*Q) x y) v = + DensityTransfer.applyKernel (fun x y => P x y) (DensityTransfer.applyKernel (fun x y => Q x y) v) := by + apply PiLp.ext + intro x + change DensityTransfer.applyKernel (fun x y => (P*Q) x y) v x = DensityTransfer.applyKernel (fun x y => P x y) (DensityTransfer.applyKernel (fun x y => Q x y) v) x + simp only [DensityTransfer.applyKernel_apply,Matrix.mul_apply,Complex.ofReal_sum, + Complex.ofReal_mul,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + apply Finset.sum_congr rfl + intro z _ + ring + +lemma applyKernel_one {X : Type*} [Fintype X] [DecidableEq X] + (v : EuclideanSpace ℂ X) : DensityTransfer.applyKernel (fun x y => (1 : Matrix X X ℝ) x y) v = v := by + apply PiLp.ext + intro x + change DensityTransfer.applyKernel (fun x y => (1 : Matrix X X ℝ) x y) v x = v x + simp [DensityTransfer.applyKernel_apply,Matrix.one_apply,apply_ite,ite_mul] + +lemma symmetric_hs_power {X : Type*} [Fintype X] [DecidableEq X] + (P : Matrix X X ℝ) (hs : P.IsSymm) (r : ℕ) : + (∑ x, ∑ y, ((P^r) x y)^2) = ∑ x, (P^(2*r)) x x := by + rw [two_mul,pow_add] + apply Finset.sum_congr rfl + intro x _ + simp only [Matrix.mul_apply] + apply Finset.sum_congr rfl + intro y _ + rw [(hs.pow r).apply x y,pow_two] + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] + +lemma trace_power_le_hs (A : V →L[ℂ] V) (hs : IsSelfAdjoint A) (hn : ‖A‖ ≤ 1) + (r : ℕ) : + (LinearMap.trace ℂ V ((A^(2*r+1)).toLinearMap)).re ≤ + ∑ j, ‖(A^r) (stdOrthonormalBasis ℂ V j)‖^2 := by + let B := stdOrthonormalBasis ℂ V + rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] + simp only [Matrix.trace,Matrix.diag,Complex.re_sum,LinearMap.toMatrix_apply, + OrthonormalBasis.coe_toBasis_repr_apply,OrthonormalBasis.repr_apply_apply] + apply Finset.sum_le_sum + intro j _ + have he : (A^(2*r+1)) (B j) = (A^r) (A ((A^r) (B j))) := by + have hnat : 2*r+1=r+(1+r) := by omega + rw [hnat,pow_add,pow_add,pow_one] + rfl + change (inner ℂ (B j) ((A^(2*r+1)) (B j))).re ≤ ‖(A^r) (B j)‖^2 + rw [he] + conv_lhs => rw [←(hs.pow r).adjoint_eq,ContinuousLinearMap.adjoint_inner_right] + rw [(hs.pow r).adjoint_eq] + apply (Complex.re_le_norm _).trans + apply (norm_inner_le_norm _ _).trans + have hh := A.le_opNorm ((A^r) (B j)) + have ha : ‖A ((A^r) (B j))‖ ≤ ‖(A^r) (B j)‖ := by + exact hh.trans (by simpa using mul_le_mul_of_nonneg_right hn (norm_nonneg _)) + nlinarith [norm_nonneg ((A^r) (B j))] + +open UnitaryFinite +lemma palindrome_selfadjoint (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : IsSelfAdjoint (sampleOperator ρ (palindromePerm d)) := by + rw [sampleOperator_palindrome _ _ hρ] + change IsSelfAdjoint (_ * star _) + simp only [isSelfAdjoint_iff,star_mul,star_star] + +variable {G X : Type*} [Group G] [Fintype G] [Fintype X] [DecidableEq X] + +lemma coefficient_trace_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) + [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (P : Matrix X X ℝ) (A : V →L[ℂ] V) + (hmap : ∀ w, IsFixed a x₀ ρ w → ∀ v, + DensityTransfer.applyKernel (fun x y => P x y) (normalizedCoefficient a x₀ ha ρ w v) = + normalizedCoefficient a x₀ ha ρ w (A v)) + (hs : IsSelfAdjoint A) (hn : ‖A‖ ≤ 1) (r : ℕ) : + (Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ) * + (LinearMap.trace ℂ V ((A^(2*r+1)).toLinearMap)).re ≤ + ∑ x, ∑ y, ((P^r) x y)^2 := by + let W := fixedSpace a x₀ ρ + let B := stdOrthonormalBasis ℂ V + let C := stdOrthonormalBasis ℂ W + let w : Fin (Module.finrank ℂ W) → V := fun i => (C i : V) + have hfix (i) : IsFixed a x₀ ρ (w i) := (C i).2 + have hw : Orthonormal ℂ w := C.orthonormal.comp_linearIsometry W.subtypeₗᵢ + let v : Fin (Module.finrank ℂ W) × Fin (Module.finrank ℂ V) → EuclideanSpace ℂ X := + fun ij => normalizedCoefficient a x₀ ha ρ (w ij.1) (B ij.2) + have hv : Orthonormal ℂ v := by + rw [orthonormal_iff_ite] + intro i j + dsimp [v] + rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix _) (hfix _)] + rw [(orthonormal_iff_ite.mp hw), (orthonormal_iff_ite.mp B.orthonormal)] + by_cases h1 : i.1=j.1 <;> by_cases h2 : i.2=j.2 <;> + simp [h1,h2,Prod.ext_iff,eq_comm] + have hp (s : ℕ) (i) (t : V) : + DensityTransfer.applyKernel (fun x y => (P^s) x y) (normalizedCoefficient a x₀ ha ρ (w i) t) = + normalizedCoefficient a x₀ ha ρ (w i) ((A^s) t) := by + induction s with + | zero => simp [applyKernel_one] + | succ s ih => + rw [pow_succ',applyKernel_mul,ih,hmap _ (hfix _),pow_succ'] + rfl + have hhs := DensityTransfer.hilbert_schmidt_family (fun x y => (P^r) x y) v hv + have he : (∑ ij, ‖DensityTransfer.applyKernel (fun x y => (P^r) x y) (v ij)‖^2) = + (Module.finrank ℂ W:ℝ) * ∑ j, ‖(A^r) (B j)‖^2 := by + simp only [v,hp,normalizedCoefficient_norm a x₀ ha ρ hρ _ (hfix _) + (hw.norm_eq_one _),Fintype.sum_prod_type] + simp + rw [he] at hhs + exact (mul_le_mul_of_nonneg_left (trace_power_le_hs A hs hn r) (by positivity)).trans hhs + +end Thorp.Casimir + +namespace Thorp.Casimir +open scoped BigOperators Classical +open UnitaryFinite + +section +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def tupleKernel (d k : ℕ) : Matrix (Fin k ↪ Card d) (Fin k ↪ Card d) ℝ := + fun x y => PairRouting.tupleProbability (palindromePerm d) x y + +lemma palindrome_trace_amplification (d k : ℕ) (x₀ : Fin k ↪ Card d) + (ρ : Representation ℂ (Equiv.Perm (Card d)) V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (r : ℕ) : + (Module.finrank ℂ (fixedSpace tupleAction x₀ ρ):ℝ) * + (LinearMap.trace ℂ V (((sampleOperator ρ (palindromePerm d))^(2*r+1)).toLinearMap)).re ≤ + ∑ x, ∑ y, ((tupleKernel d k)^r) x y ^ 2 := by + let ha := tupleAction_transitive x₀ + have hmap (w : V) (hw : IsFixed tupleAction x₀ ρ w) (v : V) : + DensityTransfer.applyKernel (fun x y : Fin k ↪ Card d => + PairRouting.tupleProbability (palindromePerm d) x y) + (normalizedCoefficient tupleAction x₀ ha ρ w v) = + normalizedCoefficient tupleAction x₀ ha ρ w (sampleOperator ρ (palindromePerm d) v) := by + have hh := coefficient_random tupleAction x₀ ha ρ hρ (palindromePerm d) w hw v + have he : actionKernel tupleAction (palindromePerm d) = + fun x y : Fin k ↪ Card d => PairRouting.tupleProbability (palindromePerm d) x y := by + funext x y + exact tupleAction_kernel _ x y + rw [he,←sampleOperator_inv_apply,sampleOperator_inv _ hρ, + (palindrome_selfadjoint d ρ hρ).adjoint_eq] at hh + exact hh + exact coefficient_trace_amplification tupleAction x₀ ha ρ hρ _ _ hmap + (palindrome_selfadjoint d ρ hρ) (sampleOperator_norm_le ρ hρ _) r + +end + +lemma tupleKernel_symm (d k : ℕ) : (tupleKernel d k).IsSymm := by + ext x y + exact palindrome_kernel_symmetric d y x + +lemma tupleKernel_power64 (d k : ℕ) (x y : Fin k ↪ Card d) : + ((tupleKernel d k)^64) x y ≤ + Real.exp ((64*(1+heightDecay 1))*k)/(Fintype.card (Fin k ↪ Card d):ℝ) := by + let : Nonempty (Fin k ↪ Card d) := ⟨x⟩ + have hr (x : Fin k ↪ Card d) : ∑ y, tupleKernel d k x y = 1 := + PairRouting.tupleProbability_row_sum _ x + have hc (y : Fin k ↪ Card d) : ∑ x, tupleKernel d k x y = 1 := by + simp_rw [(tupleKernel_symm d k).apply y] + exact hr y + have hm (x : Fin k ↪ Card d) : + finiteMean (fun y => ((Fintype.card (Fin k ↪ Card d):ℝ)*tupleKernel d k x y)^ + (1+(1/32:ℝ))) ≤ Real.exp ((k:ℝ)*(1+heightDecay 1)) := by + simpa only [palindromeRowMoment,Fintype.card_fin,tupleKernel] using + row_moment_coarse d x (1/32) (by norm_num) (by norm_num) + have hnum : 2 ≤ (1+(1/32:ℝ))^(32:ℕ) := by + have hh := one_add_mul_le_pow (a := (1/32:ℝ)) (by norm_num) 32 + norm_num at hh ⊢ + have hh := StrongSmoothing.symmetric_kernel_smoothing (tupleKernel d k) + (fun x y => PairRouting.tupleProbability_nonneg _ x y) hr hc (tupleKernel_symm d k) + (p := 1+(1/32:ℝ)) (A := k*(1+heightDecay 1)) (by norm_num) + (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) hm 32 hnum x y + have he : 2*((k:ℝ)*(1+heightDecay 1))*(32:ℝ) = (64*(1+heightDecay 1))*k := by ring + simpa only [show 2*32=64 by norm_num,Nat.cast_ofNat,he] using hh + +lemma K_selfadjoint (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : + @IsSelfAdjoint _ (ContinuousLinearMap.instStarId (𝕜:=ℂ) (E:=Specht.hilbertSpace μ)) (K d μ e) := by + exact palindrome_selfadjoint (V:=Specht.hilbertSpace μ) d _ (Specht.relabelledUnitary_unitary μ e) + +lemma K_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : + ‖K d μ e‖ ≤ 1 := + sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ + +lemma fixed_trace_bound (d k : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (x₀ : Fin k ↪ Card d) : + (Module.finrank ℂ (fixedSpace (V := Specht.hilbertSpace μ) tupleAction x₀ + (Specht.relabelledUnitary μ e)):ℝ) * traceMoment d μ e 65 ≤ + Real.exp ((64*(1+heightDecay 1))*k) := by + let ρ := Specht.relabelledUnitary μ e + let := Specht.relabelledUnitary_irreducible μ e + have hh := palindrome_trace_amplification (V:=Specht.hilbertSpace μ) d k x₀ ρ + (Specht.relabelledUnitary_unitary μ e) 32 + change _ * traceMoment d μ e 65 ≤ _ at hh + rw [symmetric_hs_power _ (tupleKernel_symm d k)] at hh + apply hh.trans + have hX : (0:ℝ) < Fintype.card (Fin k ↪ Card d) := by + let : Nonempty (Fin k ↪ Card d) := ⟨x₀⟩ + exact Nat.cast_pos.mpr Fintype.card_pos + calc + _ ≤ ∑ x : Fin k ↪ Card d, + Real.exp ((64*(1+heightDecay 1))*k)/(Fintype.card (Fin k ↪ Card d):ℝ) := + Finset.sum_le_sum (fun x _ => tupleKernel_power64 d k x x) + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel₀ _ (ne_of_gt hX) + +lemma levelScale_ge (n k : ℕ) (hk : k ≤ n) : (k:ℝ) ≤ levelScale n k := by + by_cases h : k=0 + · simp [h,levelScale] + have hkp : (0:ℝ) A v) + (uniformOperator_left (V:=Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) g) + exact he + +lemma gap_of_uniform_zero {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) (hz : uniformOperator ρ=0) : + ‖sampleOperator ρ (palindromePerm d)‖ ≤ blockGap d := by + have hh := palindrome_off_invariants_gap d ρ hρ + rw [hz,sub_zero,←sampleOperator_weighted] at hh + exact hh + +lemma nontrivial_gap (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : 0<μ.card-μ.rowLen 0) : ‖K d μ e‖ ≤ blockGap d := by + exact gap_of_uniform_zero (V:=Specht.hilbertSpace μ) d _ + (Specht.relabelledUnitary_unitary μ e) (nontrivial_uniform_zero d μ e hk) + +lemma eventual_level_dimension : + ∃ η : ℝ, 0<η ∧ ∀ᶠ d : ℕ in atTop, + ∀ μ : YoungDiagram, μ.card=2^d → 0<μ.card-μ.rowLen 0 → + (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2 → + η*levelScale (2^d) (μ.card-μ.rowLen 0) ≤ + Real.log (Module.finrank ℂ (Specht.space μ)) := by + obtain ⟨h,hh,hm⟩ := Specht.medium_dimension (1/16) (by norm_num) (by norm_num) + refine ⟨min (1/3) h,lt_min (by norm_num) hh,?_⟩ + filter_upwards [twopow_nat_tendsto.eventually hm] with d hd + intro μ hμ hk hc + let k := μ.card-μ.rowLen 0 + have hkn : k≤2^d := by dsimp [k]; omega + have hΛ : 0≤levelScale (2^d) k := (Nat.cast_nonneg k).trans (levelScale_ge _ _ hkn) + have hr : ((μ.card-μ.rowLen 0:ℕ):ℝ)=(μ.card:ℝ)-μ.rowLen 0 := + Nat.cast_sub (Specht.rowLen_zero_le_card μ) + by_cases hs : (k:ℝ)≤(2^d:ℕ)/16 + · have hk2 : 2*k≤2^d := by exact_mod_cast (show (2:ℝ)*k≤(2^d:ℕ) by linarith) + have hdim := DimensionEstimates.near_row_log_dimension (2^d) k _ hk hk2 + (by simpa only [←hμ] using Specht.choose_tail_le_dimension μ) + have hkp : (0:ℝ) exact ⟨1,by norm_num,by omega⟩ + | succ D ih => + obtain ⟨b,hb,hh⟩ := ih (fun d hd => hf d (by omega)) + refine ⟨min b (f D),lt_min hb (hf D (by omega)),?_⟩ + intro d hd + by_cases he : d=D + · subst d; exact min_le_right _ _ + · exact (min_le_left _ _).trans (hh d (by omega)) + +theorem level_contraction : + ∃ a : ℝ, 0 hf d) + refine ⟨min a b,lt_min ha hb,?_⟩ + intro d μ e hk + have hμ : μ.card=2^d := by rw [←Specht.card_cell,←Fintype.card_congr e,card_positions] + have hkn : μ.card-μ.rowLen 0≤2^d := by omega + have hΛ : 0≤levelScale (2^d) (μ.card-μ.rowLen 0) := + (Nat.cast_nonneg _).trans (levelScale_ge _ _ hkn) + by_cases hd : D≤d + · apply (hD d hd μ e hk).trans (Real.exp_le_exp.mpr _) + have hh := mul_le_mul_of_nonneg_right (min_le_left a b) hΛ + linarith + · have hab : min a b≤f d := (min_le_right _ _).trans (hbD d (by omega)) + have hscale : levelScale (2^d) (μ.card-μ.rowLen 0) ≤ (2:ℝ)^d := by + simpa only [Nat.cast_pow,Nat.cast_ofNat] using levelScale_le (2^d) _ (by positivity) hkn + have hprod := mul_le_mul_of_nonneg_right hab (by positivity : (0:ℝ)≤(2:ℝ)^d) + have hfprod : f d*(2:ℝ)^d = -Real.log (blockGap d) := by dsimp [f]; field_simp + rw [hfprod] at hprod + have hs := mul_le_mul_of_nonneg_left hscale (le_of_lt (lt_min ha hb)) + calc + _ ≤ blockGap d := nontrivial_gap d μ e hk + _ = Real.exp (Real.log (blockGap d)) := (Real.exp_log (blockGap_pos d)).symm + _ ≤ _ := Real.exp_le_exp.mpr (by linarith) + +end Thorp.Casimir + +namespace Thorp.Specht +open scoped BigOperators Classical +open UnitaryFinite + +noncomputable def cardLabels (d : ℕ) (μ : Shapes (2^d)) : Card d ≃ Cell μ.1 := + ((Fintype.equivFin (Card d)).trans (finCongr (card_positions d))).trans (labels μ).symm + +noncomputable def cardRepresentation (d : ℕ) (μ : Shapes (2^d)) : + Representation ℂ (Equiv.Perm (Card d)) (hilbertSpace μ.1) := + relabelledUnitary μ.1 (cardLabels d μ) + +lemma cardRepresentation_unitary (d : ℕ) (μ : Shapes (2^d)) : + IsUnitary (V := hilbertSpace μ.1) (cardRepresentation d μ) := + relabelledUnitary_unitary _ _ + +noncomputable instance cardRepresentation_irreducible (d : ℕ) (μ : Shapes (2^d)) : + Representation.IsIrreducible (cardRepresentation d μ) := + relabelledUnitary_irreducible _ _ + +lemma relabelledUnitary_neq {α : Type*} (μ ν : YoungDiagram) + (e : α ≃ Cell μ) (f : α ≃ Cell ν) + (T : Representation.Equiv (relabelledUnitary μ e) (relabelledUnitary ν f)) : μ=ν := by + let S := (spaceHilbertEquiv μ).trans (T.toLinearEquiv.trans (spaceHilbertEquiv ν).symm) + apply shapes_eq_of_equivariant_equiv μ ν (e.symm.trans f) S + intro p v + have hT := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap + (e.symm.permCongr p) (spaceHilbertEquiv μ v) + change T.toLinearEquiv (spaceHilbertEquiv μ + (representation μ (e.permCongr (e.symm.permCongr p)) + ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))))= + spaceHilbertEquiv ν (representation ν (f.permCongr (e.symm.permCongr p)) + ((spaceHilbertEquiv ν).symm (T.toLinearEquiv (spaceHilbertEquiv μ v)))) at hT + have he : e.permCongr (e.symm.permCongr p)=p := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] + have hf : f.permCongr (e.symm.permCongr p)=(e.symm.trans f).permCongr p := by + apply Equiv.ext + intro x + rfl + rw [he,hf,LinearEquiv.symm_apply_apply] at hT + have ht := congrArg (spaceHilbertEquiv ν).symm hT + simpa only [LinearEquiv.symm_apply_apply,S,LinearEquiv.trans_apply] using ht + +lemma cardRepresentation_distinct (d : ℕ) (μ ν : Shapes (2^d)) (hne : μ≠ν) : + ¬Nonempty (Representation.Equiv (cardRepresentation d μ) (cardRepresentation d ν)) := by + rintro ⟨T⟩ + exact hne (Subtype.ext (relabelledUnitary_neq μ.1 ν.1 (cardLabels d μ) (cardLabels d ν) T)) + +lemma card_conjugacy_shapes (d : ℕ) : + Nat.card (ConjClasses (Equiv.Perm (Card d)))≤Fintype.card (Shapes (2^d)) := by + have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Card d)) + simpa only [card_positions,Nat.card_eq_fintype_card,Fintype.card_congr (shapePartitionEquiv (2^d))] using h + +lemma row_zero_of_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) (x : Cell μ) : row x=0 := by + have hr : μ.row 0=μ.cells := Finset.eq_of_subset_of_card_le + (Finset.filter_subset _ _) (by rw [←μ.rowLen_eq_card]; exact hμ.ge) + have hx : x.1∈μ.row 0 := by rw [hr]; exact x.2 + exact (YoungDiagram.mem_row_iff.mp hx).2 + +lemma tabloid_subsingleton_of_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) : + Subsingleton (Tabloid μ) := by + refine ⟨fun f g => ?_⟩ + apply Subtype.ext + funext x + obtain ⟨p,hp⟩ := f.2 + obtain ⟨q,hq⟩ := g.2 + simp only [hp,hq,Function.comp_apply] + apply Fin.ext + exact (row_zero_of_full_row μ hμ (p x)).trans (row_zero_of_full_row μ hμ (q x)).symm + +lemma representation_full_row (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) + (p : Equiv.Perm (Cell μ)) : representation μ p=1 := by + let := tabloid_subsingleton_of_full_row μ hμ + apply LinearMap.ext + intro v + apply Subtype.ext + funext f + change v.1 (tabloidAct p⁻¹ f)=v.1 f + rw [show tabloidAct p⁻¹ f=f from Subsingleton.elim _ _] + +lemma relabelled_full_row {α : Type*} (μ : YoungDiagram) (hμ : μ.rowLen 0=μ.card) + (e : α ≃ Cell μ) (p : Equiv.Perm α) : relabelledUnitary μ e p=1 := by + change ((spaceHilbertEquiv μ).conjAlgEquiv ℂ) (representation μ (e.permCongr p))=1 + rw [representation_full_row μ hμ,map_one] + +end Thorp.Specht +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G Ω V : Type*} [Group G] [Fintype G] [Fintype Ω] [Nonempty Ω] + [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma sample_uniform_left (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by + rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +lemma uniform_zero_of_sample_norm_lt_one (ρ : Representation ℂ G V) (P : Ω → G) + (h : ‖sampleOperator ρ P‖<1) : uniformOperator ρ=0 := by + have hn := norm_mul_le (sampleOperator ρ P) (uniformOperator ρ) + rw [sample_uniform_left] at hn + apply norm_eq_zero.mp + nlinarith [norm_nonneg (uniformOperator ρ)] + +omit [Fintype G] in +lemma sampleOperator_trivial (ρ : Representation ℂ G V) (hρ : ∀ g,ρ g=1) (P : Ω → G) : + sampleOperator ρ P=1 := by + convert sampleOperator_one (Ω := Ω) ρ using 1 + unfold sampleOperator + congr 1 + apply Finset.sum_congr rfl + intro ω _ + apply ContinuousLinearMap.ext + intro v + change ρ (P ω) v=ρ 1 v + rw [hρ,hρ] + +lemma uniformOperator_trivial (ρ : Representation ℂ G V) (hρ : ∀ g,ρ g=1) : + uniformOperator ρ=1 := by + rw [←sampleOperator_uniform] + exact sampleOperator_trivial ρ hρ id + +lemma weighted_sub (ρ : Representation ℂ G V) (p q : G → ℝ) : + weightedOperator ρ (fun g => p g-q g)=weightedOperator ρ p-weightedOperator ρ q := by + simp only [weightedOperator,Complex.ofReal_sub,sub_smul,Finset.sum_sub_distrib] + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma physical_palindrome_norm (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : + ‖sampleOperator ρ (run d d)‖^2=‖sampleOperator ρ (palindromePerm d)‖ := by + rw [physical_sweep_adjoint d ρ hρ,sampleOperator_palindrome d ρ hρ] + have h := ContinuousLinearMap.norm_adjoint_comp_self + ((sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint) + rw [ContinuousLinearMap.adjoint_adjoint] at h + simpa only [ContinuousLinearMap.mul_def,←sq] using h.symm + +lemma physical_power_bound (d C : ℕ) (hC : 0 < C) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : + ‖sampleOperator ρ (run d (C*d))‖^2≤‖sampleOperator ρ (palindromePerm d)‖^C := by + have he : sampleOperator ρ (run d (C*d))=(sampleOperator ρ (run d d))^C := by + simp only [sampleOperator_run,←pow_mul,Nat.mul_comm C d] + rw [he,←physical_palindrome_norm d ρ hρ] + calc + _ ≤ (‖sampleOperator ρ (run d d)‖^C)^2 := + pow_le_pow_left₀ (norm_nonneg _) (norm_pow_le' _ hC) _ + _ = _ := by rw [←pow_mul,←pow_mul,Nat.mul_comm C 2] + +end Thorp +namespace Thorp.Specht +open scoped BigOperators Classical + +section +open UnitaryFinite + +lemma card_fourier_decay (d C : ℕ) (μ : Shapes (2^d)) (a s : ℝ) + (ha : 0 < a) (hs : 0 ≤ s) (hC : s+2 ≤ a*C) + (hD : 1≤Real.log (Module.finrank ℂ (space μ.1))) + (hK : ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (palindromePerm d)‖≤ + Real.exp (-a*Real.log (Module.finrank ℂ (space μ.1)))) : + (Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2* + ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d (C*d))-uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2≤ + Real.exp (-s*Real.log (Module.finrank ℂ (space μ.1))) := by + let : NormedAddCommGroup (hilbertSpace μ.1) := inferInstance + let : InnerProductSpace ℂ (hilbertSpace μ.1) := inferInstance + let : FiniteDimensional ℂ (hilbertSpace μ.1) := inferInstance + have hu : uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)=0 := + uniform_zero_of_sample_norm_lt_one _ (palindromePerm d) (hK.trans_lt (by + rw [Real.exp_lt_one_iff]; nlinarith)) + rw [hu,sub_zero,finrank_hilbertSpace] + have hCp : 0 < C := by + by_contra hn + have hz : C=0 := by omega + rw [hz,Nat.cast_zero,mul_zero] at hC + linarith + have hp := physical_power_bound d C hCp (cardRepresentation d μ) (cardRepresentation_unitary d μ) + have hkpow := pow_le_pow_left₀ (norm_nonneg _) hK C + have hDp : (0:ℝ) simp + | succ n ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring + rw [he] + nlinarith [pow_nonneg (by norm_num : (0:ℝ)≤1/2) n] + +lemma shape_weight_sum (N : ℕ) : + (∑ μ : Shapes N,(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0))≤2 := by + have he := Finset.sum_fiberwise_of_maps_to' + (s := (Finset.univ : Finset (Shapes N))) (t := Finset.range (N+1)) + (g := fun μ : Shapes N => μ.1.card-μ.1.rowLen 0) + (by intro μ _; simp only [Finset.mem_range]; have := μ.2; omega) + (fun j => (1/4:ℝ)^j) + rw [←he] + apply le_trans _ (half_geom_sum (N+1)) + apply Finset.sum_le_sum + intro j _ + have hc : ((Finset.univ.filter (fun μ : Shapes N => μ.1.card-μ.1.rowLen 0=j)).card:ℝ)≤(2:ℝ)^j := by + have hh := tail_shapes_count N j + rw [Fintype.card_subtype] at hh + exact_mod_cast hh + simp only [Finset.sum_const,nsmul_eq_mul] + calc + _ ≤ (2:ℝ)^j*(1/4:ℝ)^j := mul_le_mul_of_nonneg_right hc (by positivity) + _ = (1/2:ℝ)^j := by rw [←mul_pow]; norm_num + +lemma near_shape_term (N j : ℕ) (L s : ℝ) (hN : 0 z/(Fintype.card (Fin t → Coins d):ℝ)) + convert Finset.sum_boole (R := ℝ) (fun x => run d t x = g) Finset.univ using 1 + apply Finset.sum_congr rfl + intro ω _ + split_ifs with h <;> simp only [h, ite_true, ite_false] + +lemma physical_fourier_bound (d t : ℕ) : + distance d t^2≤∑ μ : Shapes (2^d),(Module.finrank ℂ (hilbertSpace μ.1):ℝ)^2* + ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t)- + uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2 := by + let V : Shapes (2^d) → Type := fun μ => hilbertSpace μ.1 + let : ∀ μ,NormedAddCommGroup (V μ) := fun _ => inferInstance + let : ∀ μ,InnerProductSpace ℂ (V μ) := fun _ => inferInstance + let : ∀ μ,FiniteDimensional ℂ (V μ) := fun _ => inferInstance + let p := fun g : Equiv.Perm (Card d) => law d t g-1/(Nat.factorial (2^d):ℝ) + have hb := FiniteFourier.l1_fourier_bound V (cardRepresentation d) + (cardRepresentation_unitary d) (cardRepresentation_distinct d) (card_conjugacy_shapes d) p + have he (μ : Shapes (2^d)) : weightedOperator (V := V μ) (cardRepresentation d μ) p= + sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t)- + uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) := by + rw [sampleOperator_weighted,sampleLaw_run] + dsimp only [p] + rw [weighted_sub] + congr 1 + unfold uniformOperator + rw [card_permutations] + simp only [one_div] + simp_rw [he] at hb + apply le_trans _ hb + change ((1/2:ℝ)*(∑ g,|p g|))^2≤(∑ g,|p g|)^2 + nlinarith [sq_nonneg (∑ g,|p g|)] + +theorem eventual_physical_bound : + ∃ C : ℕ, 0 hbound μ) + _ = (1/(2:ℝ)^d)*(∑ μ : Shapes (2^d),(1/4:ℝ)^(μ.1.card-μ.1.rowLen 0))+ + (Fintype.card (Shapes (2^d)):ℝ)*Real.exp (-s*h*(2:ℝ)^d) := by + rw [Finset.sum_add_distrib,←Finset.mul_sum,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ ≤ (1/(2:ℝ)^d)*2+Real.exp (-(2:ℝ)^d) := by + apply add_le_add + · exact mul_le_mul_of_nonneg_left (shape_weight_sum (2^d)) (by positivity) + · simpa only [Nat.cast_pow,Nat.cast_ofNat] using shapes_medium_sum (2^d) h s hsh + _ = _ := by ring + +end +open Filter DimensionEstimates + +lemma physical_convergence : ∃ C : ℕ, 0 distance d (C*d)) atTop (nhds 0) := by + obtain ⟨C,hC,hbound⟩ := eventual_physical_bound + refine ⟨C,hC,?_⟩ + have hrec : Tendsto (fun d : ℕ => 2/(2:ℝ)^d) atTop (nhds 0) := + tendsto_const_nhds.div_atTop twopow_tendsto + have hexp : Tendsto (fun d : ℕ => Real.exp (-(2:ℝ)^d)) atTop (nhds 0) := + Real.tendsto_exp_neg_atTop_nhds_zero.comp twopow_tendsto + have hr : Tendsto (fun d : ℕ => 2/(2:ℝ)^d+Real.exp (-(2:ℝ)^d)) atTop (nhds 0) := by + simpa only [zero_add] using hrec.add hexp + have hsq : Tendsto (fun d : ℕ => distance d (C*d)^2) atTop (nhds 0) := + squeeze_zero' (Eventually.of_forall (fun d => sq_nonneg (distance d (C*d)))) hbound hr + have hs := (Real.continuous_sqrt.tendsto (0:ℝ)).comp hsq + have he : (Real.sqrt ∘ fun d : ℕ => distance d (C*d)^2)=(fun d => distance d (C*d)) := by + funext d + exact Real.sqrt_sq (distance_nonneg _ _) + rw [he,Real.sqrt_zero] at hs + exact hs + +end Thorp + +namespace Thorp.Casimir +open scoped BigOperators Classical +open Filter UnitaryFinite + +lemma K_source_square (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : + K d μ e = (ContinuousLinearMap.adjoint (𝕜:=ℂ) (E:=Specht.hilbertSpace μ) (F:=Specht.hilbertSpace μ) + (SparseContact.sweepOperator d μ e true)) * + SparseContact.sweepOperator d μ e true := by + simp only [SparseContact.sweepOperator,ite_true] + rw [sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), + ContinuousLinearMap.adjoint_adjoint] + exact sampleOperator_palindrome _ _ (Specht.relabelledUnitary_unitary μ e) + +lemma density_bound (d k : ℕ) (hk : k≤2^d) (x : Fin k ↪ Card d) : + (palindromeRowMoment d x (1/64))^(64/65:ℝ) ≤ + Real.exp ((1+64*(1+heightDecay 1))*levelScale (2^d) k) := by + have hm := row_moment_coarse d x (1/64) (by norm_num) (by norm_num) + have hh := Real.rpow_le_rpow (palindromeRowMoment_nonneg d x (1/64)) hm + (by norm_num : (0:ℝ)≤64/65) + simp only [Fintype.card_fin] at hh + apply hh.trans + rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hL := levelScale_ge (2^d) k hk + have hA := heightDecay_nonneg 1 + have hk0 : (0:ℝ)≤k := by positivity + nlinarith + +lemma fromDistance_eq (d t : ℕ) (σ : Equiv.Perm (Card d)) : fromDistance d t σ=distance d t := by + unfold fromDistance distance + congr 1 + exact Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ (fun _ => rfl) + +lemma trace_real {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (A : V →L[ℂ] V) (hA : IsSelfAdjoint A) : + (((LinearMap.trace ℂ V A.toLinearMap).re : ℝ):ℂ) = LinearMap.trace ℂ V A.toLinearMap := by + let B := stdOrthonormalBasis ℂ V + rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] + simp only [Matrix.trace,Matrix.diag,Complex.re_sum,Complex.ofReal_sum, + LinearMap.toMatrix_apply,OrthonormalBasis.coe_toBasis_repr_apply, + OrthonormalBasis.repr_apply_apply] + apply Finset.sum_congr rfl + intro j _ + exact hA.isSymmetric.coe_re_inner_self_apply (B j) + +lemma trace_power_real {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (A : V →L[ℂ] V) (hA : IsSelfAdjoint A) (r : ℕ) : + (((LinearMap.trace ℂ V (A^r).toLinearMap).re : ℝ):ℂ) = + LinearMap.trace ℂ V (A^r).toLinearMap := trace_real _ (hA.pow r) + +lemma traceMoment_real (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (r : ℕ) : + (traceMoment d μ e r:ℂ) = + LinearMap.trace ℂ (Specht.hilbertSpace μ) ((K d μ e)^r).toLinearMap := by + exact trace_power_real (V:=Specht.hilbertSpace μ) _ (K_selfadjoint d μ e) r + +theorem casimir_main : MainStatement := by + obtain ⟨a,ha,hnorm⟩ := level_contraction + refine ⟨a,1+64*(1+heightDecay 1),ha,by linarith [heightDecay_nonneg 1],?_,?_,?_⟩ + · intro d k _ hk x + exact density_bound d k hk x + · intro d μ e hk + exact ⟨hnorm d μ e hk,trace_bound d μ e⟩ + · obtain ⟨l,hl,hm⟩ := physical_convergence + refine ⟨l,hl,fun starts => ?_⟩ + simpa only [fromDistance_eq] using hm + +end Thorp.Casimir + +namespace Thorp.StrongTail +open scoped BigOperators Classical +open Specht UnitaryFinite + +def MainStatement : Prop := + ∃ p Cdensity C : ℝ, 1 < p ∧ p ≤ 2 ∧ DensityAt p Cdensity ∧ + ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool), + ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ + Real.exp (C*(μ.card-μ.rowLen 0 : ℕ)) * + (Module.finrank ℂ (Specht.space (tailDiagram μ)):ℝ)^(-((p-1)/p)) + +lemma dimension_le_factorial (μ : YoungDiagram) : + Module.finrank ℂ (space μ) ≤ μ.card.factorial := by + have hdim : Module.finrank ℂ (space μ) ≤ Fintype.card (Tabloid μ) := by + simpa using Submodule.finrank_le (space μ) + have hrow : 1 ≤ Fintype.card (rowGroup μ) := Fintype.card_pos + have hc := card_tabloid_mul_row μ + nlinarith + +lemma tail_card_exact (μ : YoungDiagram) : + (tailDiagram μ).card = μ.card - μ.rowLen 0 := by + rw [←card_cell,Fintype.card_congr (tailCellEquiv μ),tail_card] + +lemma tail_dimension_le_factorial (μ : YoungDiagram) : + Module.finrank ℂ (space (tailDiagram μ)) ≤ (μ.card - μ.rowLen 0).factorial := by + simpa only [tail_card_exact] using dimension_le_factorial (tailDiagram μ) + +lemma sweep_sq_palindrome (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : + ‖SparseContact.sweepOperator d μ e rev‖^2 = + ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ := by + rw [SparseContact.sweep_forward_norm, sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e)] + change ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))‖^2 = _ + rw [show (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint = + star (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))) from rfl] + simpa only [pow_two] using (CStarRing.norm_self_mul_star (x := sampleOperator (V := hilbertSpace μ) + (relabelledUnitary μ e) (fun ω => butterflyPerm d (decodeButterfly d ω)))).symm + +lemma sweep_sq_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : + ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ 1 := by + have h := SparseContact.sweep_norm_le_one d μ e rev + nlinarith [norm_nonneg (SparseContact.sweepOperator d μ e rev)] + +theorem strong_tail : MainStatement := by + obtain ⟨a,h,ha,hh,dE⟩ := Specht.spectral_regimes + obtain ⟨D0,hD0⟩ := Filter.eventually_atTop.mp dE + let d0 := max D0 1 + let t : ℝ := min a (1/1000) + have ht : 0 < t := lt_min ha (by norm_num) + have hta : t ≤ a := min_le_left _ _ + have htq : t ≤ 1/1000 := min_le_right _ _ + let b := t/(1+t) + have hden : 0 < 1+t := by linarith + have hb : 0 < b := div_pos ht hden + have hbt : b ≤ t := (div_le_iff₀ hden).mpr (by nlinarith [sq_nonneg t]) + have hba : b ≤ a := hbt.trans hta + have hb1 : b ≤ 1 := (div_le_one hden).mpr (by linarith) + let C := Real.log (((2^d0).factorial:ℕ):ℝ) + have hC : 0 ≤ C := Real.log_nonneg (by exact_mod_cast Nat.factorial_pos (2^d0)) + refine ⟨1+t,3+heightDecay 1,C,by linarith,by linarith, + density_at_small_exponent (by linarith) (by linarith),?_⟩ + intro d μ e rev + let k := μ.card - μ.rowLen 0 + let D : ℝ := Module.finrank ℂ (space (tailDiagram μ)) + have hD : 1 ≤ D := by dsimp [D]; exact_mod_cast dimension_pos (tailDiagram μ) + have hDp : 0 < D := by linarith + have hlog : 0 ≤ Real.log D := Real.log_nonneg hD + have hμ : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions] + have hform : -(((1+t)-1)/(1+t)) = -b := by dsimp [b]; congr 1; ring + rw [hform] + change ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ Real.exp (C*k)*D^(-b) + rw [Real.rpow_def_of_pos hDp,←Real.exp_add] + by_cases hk : k=0 + · have hDone : D=1 := by + have hn := tail_dimension_le_factorial μ + change Module.finrank ℂ (space (tailDiagram μ)) ≤ k.factorial at hn + rw [hk,Nat.factorial_zero] at hn + have hu : D ≤ 1 := by dsimp [D]; exact_mod_cast hn + linarith + rw [hk,Nat.cast_zero,mul_zero,hDone,Real.log_one,zero_mul,add_zero,Real.exp_zero] + exact sweep_sq_le_one d μ e rev + · have hkpos : 0 hf d) + refine ⟨min a b,lt_min ha hb,?_⟩ + intro d μ e hk + have hμ : μ.card=2^d := by rw [←Specht.card_cell,←Fintype.card_congr e,card_positions] + have hDpos : (0:ℝ) ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -end Thorp - -namespace Thorp.PairRouting -open scoped BigOperators -open Filter -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -end Thorp.PairRouting - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical - -abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} - -def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 - -def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 - -lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := - YoungDiagram.mem_iff_lt_colLen.mp x.2 - -noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := - ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ - -abbrev Tabloid (μ : YoungDiagram) := - {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} - -noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ - -noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ - -noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - Equiv.Perm (Tabloid μ) where - toFun f := ⟨fun x => f.1 (p⁻¹ x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p⁻¹, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - invFun f := ⟨fun x => f.1 (p x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - left_inv f := by apply Subtype.ext; funext x; simp - right_inv f := by apply Subtype.ext; funext x; simp - -@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl - -@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by - ext f x - rfl - -@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : - tabloidAct (p*q) = tabloidAct p * tabloidAct q := by - ext f x - simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] - -noncomputable def tabloidRep (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where - toFun p := - { toFun := fun v f => v (tabloidAct p⁻¹ f) - map_add' := by intros; rfl - map_smul' := by intros; rfl } - map_one' := by ext v f; simp - map_mul' p q := by - ext v f - simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] - rfl - -noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := - fun g => if g=f then 1 else 0 - -noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where - carrier := {p | ∀ x, col (p x) = col x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := - ((Equiv.Perm.sign p : ℤ) : ℂ) - - -section -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by - classical - exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c - -end - -noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := - alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) - -noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := - Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) - -lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ - -lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨q,rfl⟩ := hv - change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ - rw [←map_mul] - exact orbit_mem_space μ (p*q) - | zero => simp - | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw - | smul a v hv ih => simpa using (space μ).smul_mem a ih - -noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := - ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ - -noncomputable def representation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := - (subrepresentation μ).toRepresentation - -end Thorp.Specht - -namespace Thorp.PermutationHilbert -open scoped BigOperators ComplexConjugate Classical -open Complex -variable {X : Type*} [Fintype X] - -abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X - -end Thorp.PermutationHilbert - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def hilbertEquiv (μ : YoungDiagram) : - (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := - (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm - -noncomputable def hilbertSpace (μ : YoungDiagram) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap - -end Thorp.Specht - -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where - toFun g := (ρ g).toContinuousLinearMap - map_one' := by ext v; simp - map_mul' g h := by ext v; simp - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := - (hilbertEquiv μ).submoduleMap (space μ) - -noncomputable def unitaryRepresentation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := - ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := - (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators - -noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) - (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : - Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := - UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) - (fun ω : SwitchIndex d → Bool => if reverse then - (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) - -end Thorp.SparseContact - -namespace Thorp.StrongSmoothing - -def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where - toFun x := fun i => x (order.symm i) - invFun x := fun i => x (order i) - left_inv x := by funext i; simp - right_inv x := by funext i; simp - -def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : - Equiv.Perm (Card d) := - coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * - (coordinateRelabel d order)⁻¹ - -abbrev Tuples (d l : ℕ) := Fin l ↪ Card d - -noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : - Matrix (Tuples d l) (Tuples d l) ℝ := - fun x y => PairRouting.tupleProbability (sweep d order) x y - -noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : - Matrix (Tuples d l) (Tuples d l) ℝ := - let A := sweepKernel d l order - if orientation then A * A.transpose else A.transpose * A - -end Thorp.StrongSmoothing - -namespace Thorp.StrongTail -open scoped BigOperators Classical -open Specht - -def tailDiagram (μ : YoungDiagram) : YoungDiagram := - YoungDiagram.ofRowLens μ.rowLens.tail μ.rowLens_sorted.pairwise.tail.sortedGE - -end Thorp.StrongTail - -namespace Thorp.Casimir -open scoped BigOperators Classical -open Filter - -noncomputable def levelScale (n k : ℕ) : ℝ := - (k:ℝ) * (1 + Real.log ((n:ℝ)/(k:ℝ))) - -noncomputable def K (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : - Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := - UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) - (Specht.relabelledUnitary μ e) (palindromePerm d) - -end Thorp.Casimir - -namespace Thorp.HarmonicBounds -open scoped BigOperators Classical -open Casimir StrongSmoothing - -abbrev tail (μ : YoungDiagram) := StrongTail.tailDiagram μ - -noncomputable def W (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : ℝ := ‖K d μ e‖ - -noncomputable def tupleTrace (d k : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) (p : ℕ) : ℝ := - Matrix.trace ((reflectedKernel d k order rev)^p) - -def MainStatement : Prop := - ∃ c C ζ δ cTail c₁ c₂ : ℝ, ∃ p₀ : ℕ, - 0 ((Fintype.card (Tuples d k):ℝ)* - reflectedKernel d k order rev x y)^(1+δ)) ≤ - Real.exp (C*levelScale (2^d) k)) ∧ - tupleTrace d k order rev p₀ ≤ Real.exp (C*levelScale (2^d) k)) - -end Thorp.HarmonicBounds - -end ThorpNine.Harmonic - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +end Thorp + +namespace Thorp.PairRouting +open scoped BigOperators +open Filter +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +end Thorp.PairRouting + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical + +abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} + +def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 + +def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 + +lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := + YoungDiagram.mem_iff_lt_colLen.mp x.2 + +noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := + ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ + +abbrev Tabloid (μ : YoungDiagram) := + {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} + +noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ + +noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ + +noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + Equiv.Perm (Tabloid μ) where + toFun f := ⟨fun x => f.1 (p⁻¹ x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p⁻¹, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + invFun f := ⟨fun x => f.1 (p x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + left_inv f := by apply Subtype.ext; funext x; simp + right_inv f := by apply Subtype.ext; funext x; simp + +@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl + +@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by + ext f x + rfl + +@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : + tabloidAct (p*q) = tabloidAct p * tabloidAct q := by + ext f x + simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] + +noncomputable def tabloidRep (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where + toFun p := + { toFun := fun v f => v (tabloidAct p⁻¹ f) + map_add' := by intros; rfl + map_smul' := by intros; rfl } + map_one' := by ext v f; simp + map_mul' p q := by + ext v f + simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] + rfl + +noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := + fun g => if g=f then 1 else 0 + +noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where + carrier := {p | ∀ x, col (p x) = col x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := + ((Equiv.Perm.sign p : ℤ) : ℂ) + + +section +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by + classical + exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c + +end + +noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := + alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) + +noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := + Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) + +lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ + +lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨q,rfl⟩ := hv + change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ + rw [←map_mul] + exact orbit_mem_space μ (p*q) + | zero => simp + | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw + | smul a v hv ih => simpa using (space μ).smul_mem a ih + +noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := + ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ + +noncomputable def representation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := + (subrepresentation μ).toRepresentation + +end Thorp.Specht + +namespace Thorp.PermutationHilbert +open scoped BigOperators ComplexConjugate Classical +open Complex +variable {X : Type*} [Fintype X] + +abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X + +end Thorp.PermutationHilbert + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def hilbertEquiv (μ : YoungDiagram) : + (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := + (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm + +noncomputable def hilbertSpace (μ : YoungDiagram) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap + +end Thorp.Specht + +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where + toFun g := (ρ g).toContinuousLinearMap + map_one' := by ext v; simp + map_mul' g h := by ext v; simp + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := + (hilbertEquiv μ).submoduleMap (space μ) + +noncomputable def unitaryRepresentation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := + ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := + (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators + +noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) + (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : + Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := + UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) + (fun ω : SwitchIndex d → Bool => if reverse then + (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) + +end Thorp.SparseContact + +namespace Thorp.StrongSmoothing + +def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where + toFun x := fun i => x (order.symm i) + invFun x := fun i => x (order i) + left_inv x := by funext i; simp + right_inv x := by funext i; simp + +def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : + Equiv.Perm (Card d) := + coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * + (coordinateRelabel d order)⁻¹ + +abbrev Tuples (d l : ℕ) := Fin l ↪ Card d + +noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : + Matrix (Tuples d l) (Tuples d l) ℝ := + fun x y => PairRouting.tupleProbability (sweep d order) x y + +noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : + Matrix (Tuples d l) (Tuples d l) ℝ := + let A := sweepKernel d l order + if orientation then A * A.transpose else A.transpose * A + +end Thorp.StrongSmoothing + +namespace Thorp.StrongTail +open scoped BigOperators Classical +open Specht + +def tailDiagram (μ : YoungDiagram) : YoungDiagram := + YoungDiagram.ofRowLens μ.rowLens.tail μ.rowLens_sorted.pairwise.tail.sortedGE + +end Thorp.StrongTail + +namespace Thorp.Casimir +open scoped BigOperators Classical +open Filter + +noncomputable def levelScale (n k : ℕ) : ℝ := + (k:ℝ) * (1 + Real.log ((n:ℝ)/(k:ℝ))) + +noncomputable def K (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : + Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := + UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) + (Specht.relabelledUnitary μ e) (palindromePerm d) + +end Thorp.Casimir + +namespace Thorp.HarmonicBounds +open scoped BigOperators Classical +open Casimir StrongSmoothing + +abbrev tail (μ : YoungDiagram) := StrongTail.tailDiagram μ + +noncomputable def W (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) : ℝ := ‖K d μ e‖ + +noncomputable def tupleTrace (d k : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) (p : ℕ) : ℝ := + Matrix.trace ((reflectedKernel d k order rev)^p) + +def MainStatement : Prop := + ∃ c C ζ δ cTail c₁ c₂ : ℝ, ∃ p₀ : ℕ, + 0 ((Fintype.card (Tuples d k):ℝ)* + reflectedKernel d k order rev x y)^(1+δ)) ≤ + Real.exp (C*levelScale (2^d) k)) ∧ + tupleTrace d k order rev p₀ ≤ Real.exp (C*levelScale (2^d) k)) + +end Thorp.HarmonicBounds + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedReverseCoins.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedReverseCoins.lean index 9108027a38e464cd7ca276e9407fddd5c25d4c8d..505dbfe909a6f97fe110fe481791b291125dc6db 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedReverseCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedReverseCoins.lean @@ -1,761 +1,761 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.ModifiedRoutingMoment - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r - | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * - butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) - | r+1, ω => - let z := modifiedStepEquiv L r ω - (modifiedStepEquiv L r).symm - ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) - -lemma modifiedReverseCoins_involutive (L r : ℕ) : - Function.Involutive (modifiedReverseCoins L r) := by - induction r with - | zero => - intro ω - apply Prod.ext - · funext u - simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp [mul_assoc] - · rfl - | succ r ih => - change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih - intro ω - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] - exact (modifiedStepEquiv L r).symm_apply_apply ω - -noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where - toFun := modifiedReverseCoins L r - invFun := modifiedReverseCoins L r - left_inv := modifiedReverseCoins_involutive L r - right_inv := modifiedReverseCoins_involutive L r - -lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by - induction r with - | zero => - rw [modifiedPerm_zero,modifiedPerm_zero] - split_ifs - · simp only [inv_one] - · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp - | succ r ih => - obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω - rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, - mul_inv_rev,pairSwitch_inv,childLift_inv] - rw [mul_assoc] - congr 1 - congr 1 - apply congrArg childLift - funext b - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] - -lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : - PairRouting.tupleProbability (modifiedPerm L r E) e f = - PairRouting.tupleProbability (modifiedPerm L r E) f e := - PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) - (modifiedPerm_reverse L r E) e f - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical - -@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by - simp [Cell, YoungDiagram.card] - -noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : - {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where - toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ - invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm - right_inv i := by rfl - -noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := - (Finset.univ.filter (fun x => col x = j)).image f - -lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : - f x ∈ columnValues f (col x) := by - classical - exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ - -lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : - (columnValues f j).card = μ.colLen j := by - classical - rw [columnValues, Finset.card_image_iff.mpr] - · rw [← Fintype.card_subtype] - exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) - intro x hx y hy he - exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he - -lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : - ∀ i, i.val ≤ f i := by - intro i - induction h : i.val using Nat.strong_induction_on generalizing i with - | h n ih => - by_cases hn : n = 0 - · omega - · have hn' : n-1 < i.val := by omega - let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ - have hj := ih (n-1) (by omega) j rfl - have hij := hf (show j < i from hn') - dsimp [j] at hj hij - omega - -noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := - let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩ - ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ - -@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - col (rankCell f hf x) = col x := rfl - -lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by - change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) - (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩)).val = f x - simp - -lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : - Function.Injective (rankCell f hf) := by - intro x y h - have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h - apply hf x y hc - have hx := rankCell_orderEmb f hf x - have hy := rankCell_orderEmb f hf y - change (columnValues f (col (rankCell f hf x))).orderEmbOfFin - (card_columnValues f hf (col (rankCell f hf x))) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx - rw [h] at hx - exact hx.symm.trans hy - -noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := - Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) - -lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - row (rankCell f hf x) ≤ f x := by - rw [←rankCell_orderEmb f hf x] - exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ - -theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : - ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ - ∀ x, row (c x) = row (p x) := by - classical - let c := rankPerm (fun x => row (p x)) hp - refine ⟨c, fun x => rfl, ?_⟩ - have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x - have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by - rw [Equiv.sum_comp, Equiv.sum_comp] - exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) - - -@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by - ext f x - simp [tabloidAct,Equiv.Perm.inv_def] - -@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl - -lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tabloidRep μ p (delta f) = delta (tabloidAct p f) := by - classical - ext g - simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] - congr 1 - exact propext (Equiv.symm_apply_eq (tabloidAct p)) - -@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl - -lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) - (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by - apply Equiv.ext - intro x - have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc - simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr - apply Subtype.ext - exact Prod.ext hr.symm (c.2 x) - -lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) - (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : - ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by - obtain ⟨p,hp⟩ := f.2 - have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by - intro x y hcol hrow - apply hf x y hcol - rw [hp] - exact Fin.ext hrow - obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' - refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ - apply Subtype.ext - funext x - apply Fin.ext - simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] - exact (hrow x).symm - - -@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : - permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] -@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : - permSign (p*q) = permSign p * permSign q := by simp [permSign] -@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] -lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p * permSign p = 1 := by - calc - permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] - _ = 1 := by simp -@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : - permSign (Equiv.swap x y) = -1 := by simp [permSign, h] -@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] - -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -lemma alternator_mul (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.sum_mul,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulRight c) - intro a - simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring - _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] - _ = _ := by ring - -lemma mul_alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.mul_sum,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulLeft c) - intro a - simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring - _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] - _ = _ := by ring - -lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) - -lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) - -lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) - (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : - alternator C ρ v = 0 := by - have h := alternator_apply_action C ρ c v - rw [hv,hc,neg_one_smul] at h - have h2 : (2:ℂ) • alternator C ρ v = 0 := by - rw [two_smul] - nth_rw 1 [h] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -end Thorp.Specht -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : - Equiv.swap x y ∈ colGroup μ := by - classical - intro z - by_cases hx : z=x - · subst z; simpa using hc.symm - by_cases hy : z=y - · subst z; simpa using hc - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) - (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by - classical - apply Subtype.ext - funext z - simp only [tabloidAct_apply, Equiv.swap_inv] - by_cases hx : z=x - · subst z; simpa using hxy.symm - by_cases hy : z=y - · subst z; simpa using hxy - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by - classical - by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y - · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf - refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ - rw [←tabloidRep_delta] - exact alternator_apply_action _ _ c _ - · push Not at hf - obtain ⟨x,y,hcol,hrow,hne⟩ := hf - refine ⟨0, ?_⟩ - rw [zero_smul] - apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ - · exact permSign_swap hne - · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] - -lemma polytabloid_formula (μ : YoungDiagram) : - polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • - delta (tabloidAct c (baseTabloid μ)) := by - classical - simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] - -lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by - classical - rw [polytabloid_formula,Finset.sum_apply] - rw [Finset.sum_eq_single (1 : colGroup μ)] - · simp [delta] - · intro c hc hne - have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by - intro h - apply hne - exact Subtype.ext (colGroup_row_stabilizer c h.symm) - simp [Pi.smul_apply,delta,hn] - · simp - -lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by - intro h - have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp [polytabloid_base] at hv - -lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - v = ∑ f : Tabloid μ, v f • delta f := by - classical - funext g - simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] - simp - -theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by - classical - choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f - refine ⟨∑ f, v f * z f, ?_⟩ - conv_lhs => rw [delta_decomposition v] - simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] - -lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = - (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by - obtain ⟨z,hz⟩ := alternator_rank_one μ v - rw [hz] - simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] - - -noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := - ∑ f, w f * starRingEnd ℂ (v f) - -lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : - pairing (delta f) v = v f := by - classical - simp [pairing,delta] - -lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] - (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : - pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by - simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] - exact Finset.sum_comm - -lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : - pairing (a • v) w = starRingEnd ℂ a * pairing v w := by - simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] - apply Finset.sum_congr rfl - intro f hf - ring - -lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by - simp [pairing] - -lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : - pairing (u+v) w = pairing u w + pairing v w := by - simp [pairing,mul_add,Finset.sum_add_distrib] - -lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - pairing v v = 0 ↔ v = 0 := by - change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 - rw [inner_self_eq_zero] - constructor - · intro h; exact congrArg WithLp.ofLp h - · intro h; subst v; rfl - -lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : - pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by - classical - simp only [pairing,tabloidRep_apply,inv_inv] - apply Fintype.sum_equiv (tabloidAct p⁻¹) - intro f - have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by - rw [tabloidAct_inv] - exact (tabloidAct p).apply_symm_apply f - rw [hcancel] - -lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by - classical - simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, - smul_eq_mul,tabloidRep_apply] - apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) - intro c - simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] - -theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by - rw [alternator_rank_one_exact,alternator_base_pairing] - - -lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by - simpa using orbit_mem_space μ 1 - -lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : - alternator (colGroup μ) (tabloidRep μ) v ∈ W := by - classical - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] - exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) - -theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : - space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by - classical - by_cases hSW : space μ ≤ W - · exact Or.inl hSW - right - have he : polytabloid μ ∉ W := by - intro he - apply hSW - apply Submodule.span_le.mpr - rintro _ ⟨p,rfl⟩ - exact hW p _ he - have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by - intro v hv - by_contra hne - apply he - have hal := alternator_mem_invariant μ W hW v hv - rw [alternator_pairing] at hal - have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal - simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh - intro v hv w hw - induction hw using Submodule.span_induction with - | mem w hw => - obtain ⟨p,rfl⟩ := hw - rw [pairing_action] - exact hpair _ (hW p⁻¹ v hv) - | zero => exact pairing_zero_left v - | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] - | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] - -theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : - W = ⊥ ∨ W = space μ := by - obtain hSW | horth := submodule_theorem μ W hW - · exact Or.inr (le_antisymm hWS hSW) - · left - apply le_antisymm _ bot_le - intro v hv - exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) - - -lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by - intro h - have he := polytabloid_mem_space μ - rw [h,Submodule.mem_bot] at he - exact polytabloid_ne_zero μ he - -theorem representation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (representation μ) := by - have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ - (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial - have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he - exact polytabloid_ne_zero μ (congrArg Subtype.val he') - refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } - intro U - let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype - have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by - intro p v hv - obtain ⟨u,hu,rfl⟩ := hv - exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ - have hWS : W ≤ space μ := by - intro v hv - obtain ⟨u,hu,rfl⟩ := hv - exact u.2 - obtain hbot | htop := space_simple μ W hW hWS - · left - apply le_antisymm _ bot_le - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ - rw [hbot,Submodule.mem_bot] at hmem - change u = 0 - exact Subtype.ext hmem - · right - apply le_antisymm le_top - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 - obtain ⟨v,hv,hvu⟩ := hmem - have heq : v = u := Subtype.ext hvu - exact heq ▸ hv - - -section Symmetrizer -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := - ∑ h : H, ρ h - -lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : - symmetrizer H ρ * ρ h = symmetrizer H ρ := by - rw [symmetrizer,Finset.sum_mul] - exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) - -lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : - symmetrizer H ρ v = 0 := by - have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) - change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh - rw [hv,map_neg] at hh - have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by - rw [two_smul] - nth_rw 1 [←hh] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x, f (p x) = f x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -omit [Fintype α] in -lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : - Equiv.swap x y ∈ fiberGroup f := by - intro z - by_cases hx : z=x - · subst z; simpa using hf.symm - by_cases hy : z=y - · subst z; simpa using hf - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -end Symmetrizer - -lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) - (hcol : col x = col y) : - tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by - have h := action_alternator_apply (colGroup μ) (tabloidRep μ) - ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) - simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h - -theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] - (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : - symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by - rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - exact hj - obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ - apply symmetrizer_eq_zero_of_neg _ _ h - change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) - rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] - rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - - -noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : - {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where - toFun x := ⟨col x.1, by - have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 - change col x.1 < μ.rowLen (row x.1) at h - simpa only [x.2] using h⟩ - invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl - right_inv j := rfl - -def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x - -lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (he : ∀ x, row (e x) = row x) : μ = ν := by - have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by - let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := - { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ - invFun := fun x => ⟨e.symm x.1,by - have h := he (e.symm x.1) - simp only [Equiv.apply_symm_apply] at h - exact h.symm.trans x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } - simpa only [Fintype.card_fin] using Fintype.card_congr - ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) - apply YoungDiagram.ext - ext ⟨i,j⟩ - simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] - -lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - let c := rankPerm (fun x => row (e x)) h - have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x - have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ - have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ - constructor - · rw [←hsumc,←hsume] - exact Finset.sum_le_sum (fun x _ => hle x) - · intro heq - have he : ∀ x, row (c x) = row (e x) := by - apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp - (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) - apply eq_of_row_preserving μ ν (c.symm.trans e) - intro x - simpa using (he (c.symm x)).symm - -lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] - (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by - ext z - simp only [Equiv.permCongr_apply] - exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) - -lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (v : Tabloid ν → ℂ) (hv : v ≠ 0) - (hs : ∀ c : colGroup μ, - tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by - by_contra h - push Not at h - exact hv (funext h) - obtain ⟨p,hp⟩ := f.2 - apply column_injective_rowCost μ ν (e.trans p) - intro x y hcol hrow - by_contra hne - have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by - apply swap_fixes_tabloid - rw [hp] - exact Fin.ext hrow - have heq := congrArg (fun w : Tabloid ν → ℂ => w f) - (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) - rw [swap_relabel,permSign_swap hne] at heq - simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq - apply hf - have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq - exact (mul_eq_zero.mp h2).resolve_left (by norm_num) - -lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : - tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply _ _ c _ - -theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (T : space μ ≃ₗ[ℂ] space ν) - (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : - μ = ν := by - let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ - have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) - have hTcol (c : colGroup μ) : - tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by - change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ - rw [←hT] - have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := - Subtype.ext (polytabloid_col_action μ c) - rw [hh,map_smul] - rfl - have hfwd := sign_vector_rowCost μ ν e (T u) - (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol - let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ - have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) - have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : - T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by - apply T.injective - rw [T.apply_symm_apply,hT,T.apply_symm_apply] - have hp : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] - have hTicol (c : colGroup ν) : - tabloidRep μ (e.symm.permCongr c) (T.symm w) = - permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by - change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ - rw [←hTi] - have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := - Subtype.ext (polytabloid_col_action ν c) - rw [hh,map_smul] - rfl - have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) - (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol - exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) - - -noncomputable def cellRowsEquiv (μ : YoungDiagram) : - Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where - toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ - invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ - left_inv x := by apply Subtype.ext; rfl - right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl - -lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by - rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] - simp only [Fintype.card_fin] - -lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by - rw [card_eq_sum_rowLen,YoungDiagram.rowLens] - rw [Fin.sum_univ_eq_sum_range] - have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by - induction n with - | zero => simp - | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] - exact hh _ - -noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where - parts := μ.rowLens - parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simp - -noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := - YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE - -end Thorp.Specht - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.ModifiedRoutingMoment + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r + | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * + butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) + | r+1, ω => + let z := modifiedStepEquiv L r ω + (modifiedStepEquiv L r).symm + ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) + +lemma modifiedReverseCoins_involutive (L r : ℕ) : + Function.Involutive (modifiedReverseCoins L r) := by + induction r with + | zero => + intro ω + apply Prod.ext + · funext u + simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp [mul_assoc] + · rfl + | succ r ih => + change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih + intro ω + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] + exact (modifiedStepEquiv L r).symm_apply_apply ω + +noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where + toFun := modifiedReverseCoins L r + invFun := modifiedReverseCoins L r + left_inv := modifiedReverseCoins_involutive L r + right_inv := modifiedReverseCoins_involutive L r + +lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by + induction r with + | zero => + rw [modifiedPerm_zero,modifiedPerm_zero] + split_ifs + · simp only [inv_one] + · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp + | succ r ih => + obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω + rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, + mul_inv_rev,pairSwitch_inv,childLift_inv] + rw [mul_assoc] + congr 1 + congr 1 + apply congrArg childLift + funext b + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] + +lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : + PairRouting.tupleProbability (modifiedPerm L r E) e f = + PairRouting.tupleProbability (modifiedPerm L r E) f e := + PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) + (modifiedPerm_reverse L r E) e f + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical + +@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by + simp [Cell, YoungDiagram.card] + +noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : + {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where + toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ + invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm + right_inv i := by rfl + +noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := + (Finset.univ.filter (fun x => col x = j)).image f + +lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : + f x ∈ columnValues f (col x) := by + classical + exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ + +lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : + (columnValues f j).card = μ.colLen j := by + classical + rw [columnValues, Finset.card_image_iff.mpr] + · rw [← Fintype.card_subtype] + exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) + intro x hx y hy he + exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he + +lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : + ∀ i, i.val ≤ f i := by + intro i + induction h : i.val using Nat.strong_induction_on generalizing i with + | h n ih => + by_cases hn : n = 0 + · omega + · have hn' : n-1 < i.val := by omega + let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ + have hj := ih (n-1) (by omega) j rfl + have hij := hf (show j < i from hn') + dsimp [j] at hj hij + omega + +noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := + let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩ + ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ + +@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + col (rankCell f hf x) = col x := rfl + +lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by + change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) + (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩)).val = f x + simp + +lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : + Function.Injective (rankCell f hf) := by + intro x y h + have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h + apply hf x y hc + have hx := rankCell_orderEmb f hf x + have hy := rankCell_orderEmb f hf y + change (columnValues f (col (rankCell f hf x))).orderEmbOfFin + (card_columnValues f hf (col (rankCell f hf x))) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx + rw [h] at hx + exact hx.symm.trans hy + +noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := + Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) + +lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + row (rankCell f hf x) ≤ f x := by + rw [←rankCell_orderEmb f hf x] + exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ + +theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : + ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ + ∀ x, row (c x) = row (p x) := by + classical + let c := rankPerm (fun x => row (p x)) hp + refine ⟨c, fun x => rfl, ?_⟩ + have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x + have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by + rw [Equiv.sum_comp, Equiv.sum_comp] + exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) + + +@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by + ext f x + simp [tabloidAct,Equiv.Perm.inv_def] + +@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl + +lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tabloidRep μ p (delta f) = delta (tabloidAct p f) := by + classical + ext g + simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] + congr 1 + exact propext (Equiv.symm_apply_eq (tabloidAct p)) + +@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl + +lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) + (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by + apply Equiv.ext + intro x + have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc + simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr + apply Subtype.ext + exact Prod.ext hr.symm (c.2 x) + +lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) + (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : + ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by + obtain ⟨p,hp⟩ := f.2 + have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by + intro x y hcol hrow + apply hf x y hcol + rw [hp] + exact Fin.ext hrow + obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' + refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ + apply Subtype.ext + funext x + apply Fin.ext + simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] + exact (hrow x).symm + + +@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : + permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] +@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : + permSign (p*q) = permSign p * permSign q := by simp [permSign] +@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] +lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p * permSign p = 1 := by + calc + permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] + _ = 1 := by simp +@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : + permSign (Equiv.swap x y) = -1 := by simp [permSign, h] +@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] + +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +lemma alternator_mul (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.sum_mul,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulRight c) + intro a + simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring + _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] + _ = _ := by ring + +lemma mul_alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.mul_sum,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulLeft c) + intro a + simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring + _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] + _ = _ := by ring + +lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) + +lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) + +lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) + (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : + alternator C ρ v = 0 := by + have h := alternator_apply_action C ρ c v + rw [hv,hc,neg_one_smul] at h + have h2 : (2:ℂ) • alternator C ρ v = 0 := by + rw [two_smul] + nth_rw 1 [h] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +end Thorp.Specht +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : + Equiv.swap x y ∈ colGroup μ := by + classical + intro z + by_cases hx : z=x + · subst z; simpa using hc.symm + by_cases hy : z=y + · subst z; simpa using hc + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) + (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by + classical + apply Subtype.ext + funext z + simp only [tabloidAct_apply, Equiv.swap_inv] + by_cases hx : z=x + · subst z; simpa using hxy.symm + by_cases hy : z=y + · subst z; simpa using hxy + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by + classical + by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y + · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf + refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ + rw [←tabloidRep_delta] + exact alternator_apply_action _ _ c _ + · push Not at hf + obtain ⟨x,y,hcol,hrow,hne⟩ := hf + refine ⟨0, ?_⟩ + rw [zero_smul] + apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ + · exact permSign_swap hne + · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] + +lemma polytabloid_formula (μ : YoungDiagram) : + polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • + delta (tabloidAct c (baseTabloid μ)) := by + classical + simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] + +lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by + classical + rw [polytabloid_formula,Finset.sum_apply] + rw [Finset.sum_eq_single (1 : colGroup μ)] + · simp [delta] + · intro c hc hne + have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by + intro h + apply hne + exact Subtype.ext (colGroup_row_stabilizer c h.symm) + simp [Pi.smul_apply,delta,hn] + · simp + +lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by + intro h + have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp [polytabloid_base] at hv + +lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + v = ∑ f : Tabloid μ, v f • delta f := by + classical + funext g + simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] + simp + +theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by + classical + choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f + refine ⟨∑ f, v f * z f, ?_⟩ + conv_lhs => rw [delta_decomposition v] + simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] + +lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = + (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by + obtain ⟨z,hz⟩ := alternator_rank_one μ v + rw [hz] + simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] + + +noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := + ∑ f, w f * starRingEnd ℂ (v f) + +lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : + pairing (delta f) v = v f := by + classical + simp [pairing,delta] + +lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] + (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : + pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by + simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] + exact Finset.sum_comm + +lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : + pairing (a • v) w = starRingEnd ℂ a * pairing v w := by + simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro f hf + ring + +lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by + simp [pairing] + +lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : + pairing (u+v) w = pairing u w + pairing v w := by + simp [pairing,mul_add,Finset.sum_add_distrib] + +lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + pairing v v = 0 ↔ v = 0 := by + change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 + rw [inner_self_eq_zero] + constructor + · intro h; exact congrArg WithLp.ofLp h + · intro h; subst v; rfl + +lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : + pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by + classical + simp only [pairing,tabloidRep_apply,inv_inv] + apply Fintype.sum_equiv (tabloidAct p⁻¹) + intro f + have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by + rw [tabloidAct_inv] + exact (tabloidAct p).apply_symm_apply f + rw [hcancel] + +lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by + classical + simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, + smul_eq_mul,tabloidRep_apply] + apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) + intro c + simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] + +theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by + rw [alternator_rank_one_exact,alternator_base_pairing] + + +lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by + simpa using orbit_mem_space μ 1 + +lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : + alternator (colGroup μ) (tabloidRep μ) v ∈ W := by + classical + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] + exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) + +theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : + space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by + classical + by_cases hSW : space μ ≤ W + · exact Or.inl hSW + right + have he : polytabloid μ ∉ W := by + intro he + apply hSW + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + exact hW p _ he + have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by + intro v hv + by_contra hne + apply he + have hal := alternator_mem_invariant μ W hW v hv + rw [alternator_pairing] at hal + have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal + simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh + intro v hv w hw + induction hw using Submodule.span_induction with + | mem w hw => + obtain ⟨p,rfl⟩ := hw + rw [pairing_action] + exact hpair _ (hW p⁻¹ v hv) + | zero => exact pairing_zero_left v + | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] + | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] + +theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : + W = ⊥ ∨ W = space μ := by + obtain hSW | horth := submodule_theorem μ W hW + · exact Or.inr (le_antisymm hWS hSW) + · left + apply le_antisymm _ bot_le + intro v hv + exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) + + +lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by + intro h + have he := polytabloid_mem_space μ + rw [h,Submodule.mem_bot] at he + exact polytabloid_ne_zero μ he + +theorem representation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (representation μ) := by + have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ + (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial + have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he + exact polytabloid_ne_zero μ (congrArg Subtype.val he') + refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } + intro U + let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype + have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by + intro p v hv + obtain ⟨u,hu,rfl⟩ := hv + exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ + have hWS : W ≤ space μ := by + intro v hv + obtain ⟨u,hu,rfl⟩ := hv + exact u.2 + obtain hbot | htop := space_simple μ W hW hWS + · left + apply le_antisymm _ bot_le + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ + rw [hbot,Submodule.mem_bot] at hmem + change u = 0 + exact Subtype.ext hmem + · right + apply le_antisymm le_top + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 + obtain ⟨v,hv,hvu⟩ := hmem + have heq : v = u := Subtype.ext hvu + exact heq ▸ hv + + +section Symmetrizer +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := + ∑ h : H, ρ h + +lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : + symmetrizer H ρ * ρ h = symmetrizer H ρ := by + rw [symmetrizer,Finset.sum_mul] + exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) + +lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : + symmetrizer H ρ v = 0 := by + have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) + change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh + rw [hv,map_neg] at hh + have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by + rw [two_smul] + nth_rw 1 [←hh] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x, f (p x) = f x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +omit [Fintype α] in +lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : + Equiv.swap x y ∈ fiberGroup f := by + intro z + by_cases hx : z=x + · subst z; simpa using hf.symm + by_cases hy : z=y + · subst z; simpa using hf + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +end Symmetrizer + +lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) + (hcol : col x = col y) : + tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by + have h := action_alternator_apply (colGroup μ) (tabloidRep μ) + ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) + simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h + +theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] + (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : + symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by + rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + exact hj + obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ + apply symmetrizer_eq_zero_of_neg _ _ h + change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) + rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] + rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + + +noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : + {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where + toFun x := ⟨col x.1, by + have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 + change col x.1 < μ.rowLen (row x.1) at h + simpa only [x.2] using h⟩ + invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl + right_inv j := rfl + +def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x + +lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (he : ∀ x, row (e x) = row x) : μ = ν := by + have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by + let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := + { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ + invFun := fun x => ⟨e.symm x.1,by + have h := he (e.symm x.1) + simp only [Equiv.apply_symm_apply] at h + exact h.symm.trans x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } + simpa only [Fintype.card_fin] using Fintype.card_congr + ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) + apply YoungDiagram.ext + ext ⟨i,j⟩ + simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] + +lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + let c := rankPerm (fun x => row (e x)) h + have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x + have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ + have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ + constructor + · rw [←hsumc,←hsume] + exact Finset.sum_le_sum (fun x _ => hle x) + · intro heq + have he : ∀ x, row (c x) = row (e x) := by + apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp + (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) + apply eq_of_row_preserving μ ν (c.symm.trans e) + intro x + simpa using (he (c.symm x)).symm + +lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] + (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by + ext z + simp only [Equiv.permCongr_apply] + exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) + +lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (v : Tabloid ν → ℂ) (hv : v ≠ 0) + (hs : ∀ c : colGroup μ, + tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by + by_contra h + push Not at h + exact hv (funext h) + obtain ⟨p,hp⟩ := f.2 + apply column_injective_rowCost μ ν (e.trans p) + intro x y hcol hrow + by_contra hne + have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by + apply swap_fixes_tabloid + rw [hp] + exact Fin.ext hrow + have heq := congrArg (fun w : Tabloid ν → ℂ => w f) + (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) + rw [swap_relabel,permSign_swap hne] at heq + simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq + apply hf + have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq + exact (mul_eq_zero.mp h2).resolve_left (by norm_num) + +lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : + tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply _ _ c _ + +theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (T : space μ ≃ₗ[ℂ] space ν) + (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : + μ = ν := by + let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ + have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) + have hTcol (c : colGroup μ) : + tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by + change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ + rw [←hT] + have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := + Subtype.ext (polytabloid_col_action μ c) + rw [hh,map_smul] + rfl + have hfwd := sign_vector_rowCost μ ν e (T u) + (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol + let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ + have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) + have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : + T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by + apply T.injective + rw [T.apply_symm_apply,hT,T.apply_symm_apply] + have hp : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] + have hTicol (c : colGroup ν) : + tabloidRep μ (e.symm.permCongr c) (T.symm w) = + permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by + change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ + rw [←hTi] + have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := + Subtype.ext (polytabloid_col_action ν c) + rw [hh,map_smul] + rfl + have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) + (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol + exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) + + +noncomputable def cellRowsEquiv (μ : YoungDiagram) : + Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where + toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ + invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ + left_inv x := by apply Subtype.ext; rfl + right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl + +lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by + rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] + simp only [Fintype.card_fin] + +lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by + rw [card_eq_sum_rowLen,YoungDiagram.rowLens] + rw [Fin.sum_univ_eq_sum_range] + have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by + induction n with + | zero => simp + | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] + exact hh _ + +noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where + parts := μ.rowLens + parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simp + +noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := + YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE + +end Thorp.Specht + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedRoutingMoment.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedRoutingMoment.lean index b1f2c299ee7f571ccaebfd2f1c934fa3c727c239..d0cd688cb82eff840479a59cd12abf0fa1754696 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedRoutingMoment.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/ModifiedRoutingMoment.lean @@ -1,856 +1,856 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.InputTree - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : - PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by - classical - rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] - let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) - change _ ≤ B - calc - _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by - apply finiteMean_mono - intro ω - simp only [modifiedPerm_zero] - by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E - · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] - split_ifs <;> norm_num - · simp only [h,↓reduceIte,B] - rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => - if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] - convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 - rw [Fintype.card_perm,card_positions] - _ = _ := finiteMean_const B - -noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : ModifiedCoins L r => - if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) - -lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : - 0 ≤ modifiedRoutingMoment L r E e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : - modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by - simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, - PairRouting.tupleProbability] - -lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ - centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by - have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f - rw [modifiedRoutingMoment_zero] - have hbound := modified_probability_zero_le L E e f he - have hpow := Real.rpow_le_rpow hp hbound ha - have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) - have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = - centralFactor L 0 E a := by - rw [centralFactor_zero] - split_ifs - · exact Real.one_rpow _ - · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] - rw [heq] at hpow - rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] - exact mul_le_mul_of_nonneg_right hpow hp - - -lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} - (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] - rfl - -lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (L+r+1)) (a : ℝ) : - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - let : Fintype (ModifiedCoins L r) := inferInstance - rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have he (ω : ModifiedCoins L r × ModifiedCoins L r) : - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [modified_matches_step,modifiedCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = - (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r+1)) : - PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - let : Fintype (ModifiedCoins L r) := inferInstance - rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have hp (b : Bool) (p q : ModifiedCoins L r) : - modifiedPerm L r (exceptionChild E b) (if b then p else q) = - (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by - cases b <;> rfl - simp only [modified_matches_step,hp] - - -lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - - -lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * - modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) - (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) - have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = - -(r:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - calc - _ ≤ _ := hh - _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* - (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * - (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * - (modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring - _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] - - -theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by - classical - induction r generalizing ι with - | zero => - simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using - modified_pointwise_zero L E e f he a ha - | succ r ih => - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) - have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) - have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - apply hh'.trans - have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha - convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring - have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha - rw [←modified_probability_step L r E e f] at hnode - change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) - ring - - -lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : - (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card (L+r) => - ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) - -lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (he : Function.Surjective e) : Fintype.card ι = 2^d := by - rw [←card_positions d] - exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) - -lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by - simpa only [card_positions] using E.card_le_univ - -noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := - (Nat.factorial (2^(L+r)):ℝ) / - (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) - -lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : - 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity - -lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - (Nat.factorial (2^(L+r)):ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = - modifiedNormalization L r E ^ a := by - rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, - Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), - Real.mul_rpow (by positivity) (by positivity)] - have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by - rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, - show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, - Real.rpow_neg (by positivity)] - ring - -theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ - rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * - ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * - modifiedRoutingMoment L r E e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, - card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] - -lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : - finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - let B := Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) - rw [finiteMean_prod] - apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le - rw [finiteMean_prod,finiteMean_comm] - apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le - exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) - -lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - modifiedNormalization L r E ^ (1/1000:ℝ) * - Real.exp ((2^(L+r):ℕ)*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - apply hm.trans - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) - simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e - - -lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : - Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by - induction n with - | zero => omega - | succ n ih => - by_cases hz : n = 0 - · subst n; norm_num - have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) - have hn1 : (0:ℝ) < n+1 := by positivity - have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) - rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h - have hh := mul_le_mul_of_nonneg_left h hn1.le - have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring - rw [hcancel] at hh - have hi := ih (by omega) - rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] - nlinarith - -lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) = - Real.log (Nat.factorial (2^(L+r))) - - ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by - unfold modifiedNormalization - rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), - Real.log_pow,Real.log_pow,Real.log_pow, - Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - simp only [Nat.cast_pow,Nat.cast_ofNat] - -lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) ≤ - ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by - have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) - have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) - have hu := log_factorial_upper hN - have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) - simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ - rw [log_modifiedNormalization] - simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ - nlinarith - -lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + - (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - apply (modifiedRowMoment_bound L r hL E e he).trans - rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] - apply Real.exp_le_exp.mpr - have h := log_modifiedNormalization_le L r E - linarith - -lemma log_power_factorial_le (L : ℕ) : - Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by - have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by - exact_mod_cast Nat.factorial_le_pow (2^L) - have hh := Real.log_le_log (by positivity) hf - rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh - apply hh.trans - have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity - nlinarith - -lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) - (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + - (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by - apply (modified_moment_exponential L r hL E e he).trans - apply Real.exp_le_exp.mpr - have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) - have hb := mul_le_mul_of_nonneg_left momentBase_log - (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) - have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) - simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ - nlinarith - - -lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by - have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := - (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr - tendsto_natCast_atTop_atTop - have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) - convert ht using 1 - · funext L - unfold heightDecay - dsimp only [Function.comp_apply] - rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] - · simp - -noncomputable def modifiedOverhead (L r : ℕ) : ℝ := - (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) - -lemma modifiedOverhead_tendsto (L : ℕ) : - Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by - have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) - have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) - simp only [pow_one] at h₁ - simp only [pow_zero] at h₀ - have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const - ((2:ℝ)^L*1000) - convert ht using 1 - · funext r - simp only [modifiedOverhead,Nat.cast_add,pow_add] - field_simp - ring - · simp - -theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : - ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ - ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → - ∀ (e : Card (L+r) ↪ Card (L+r)), - modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by - have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := - heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists - have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL - let ε : ℝ := min (1/4) (η*250/(3*L)) - have hε : 0 < ε := lt_min (by norm_num) (by positivity) - have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) - have hεL : ε*L/250 ≤ η/3 := by - have h := min_le_right (1/4:ℝ) (η*250/(3*L)) - change ε ≤ η*250/(3*L) at h - have hh := mul_le_mul_of_nonneg_right h hL0.le - have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp - exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le - refine ⟨L,hL,ε,hε,hε1,?_⟩ - have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := - (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - filter_upwards [hr] with r hr - intro E hE e - have he := Finite.surjective_of_injective e.injective - apply (modified_moment_exception_bound L r hL E e he ε hE).trans - apply Real.exp_le_exp.mpr - have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity - have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = - (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by - unfold modifiedOverhead - field_simp - have hh := mul_le_mul_of_nonneg_right hr.le hn.le - rw [hd] at hh - have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le - linarith - - -namespace DensityTransfer -open scoped BigOperators - -noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - -lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) (x : X) : - applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl - -lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) - (v : EuclideanSpace ℂ X) : - applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by - ext x - simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] - rfl - -lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : - ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by - have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by - rw [applyKernel_apply] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] - apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans - exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) - (fun y _ => by ring_nf; exact le_rfl) - -lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) - (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) - (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by - have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by - rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] - calc - _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by - apply Finset.sum_le_sum - intro x _ - apply (kernel_component_sq P hP v x).trans - exact mul_le_mul_of_nonneg_right (hrow x) - (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) - _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by - rw [←Finset.mul_sum,Finset.sum_comm] - congr 1 - apply Finset.sum_congr rfl - intro y _ - exact (Finset.sum_mul Finset.univ _ _).symm - _ ≤ δ * ∑ y, δ*‖v y‖^2 := by - apply mul_le_mul_of_nonneg_left _ hδ - exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) - _ = _ := by rw [←Finset.mul_sum]; ring - have hn := norm_nonneg (applyKernel P v) - have hr := mul_nonneg hδ (norm_nonneg v) - nlinarith - -lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] - (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : - (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by - simp_rw [EuclideanSpace.norm_sq_eq] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro x _ - let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) - have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by - rw [norm_inner_symm] - congr 1 - simp only [applyKernel_apply,PiLp.inner_apply] - apply Finset.sum_congr rfl - intro y _ - simp [w,RCLike.inner_apply,mul_comm] - simp_rw [he] - have h := hv.sum_inner_products_le (s := Finset.univ) w - apply h.trans_eq - rw [EuclideanSpace.norm_sq_eq] - apply Finset.sum_congr rfl - intro y _ - simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] - - -lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : - (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by - split_ifs with h - · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] - apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr - rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] - exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht - · positivity - -lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : - finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by - rw [←finiteMean_mul_const] - exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) - -noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 - -noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y - -lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : - (fun x y => tailKernel P z x y+headKernel P z x y) = P := by - funext x y - unfold tailKernel headKernel - split_ifs <;> simp - -lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) - (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by - unfold tailKernel - split_ifs <;> simp only [hP,le_refl] - -lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : - ∑ y, tailKernel P z x y ≤ M*z^(-a) := by - have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then - (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by - unfold finiteMean - calc - _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by - congr 1 - apply Finset.sum_congr rfl - intro y _ - by_cases hy : z < (Fintype.card X:ℝ)*P x y - · simp only [tailKernel,hy,↓reduceIte] - · simp only [tailKernel,hy,↓reduceIte,mul_zero] - _ = _ := by rw [←Finset.mul_sum]; field_simp - rw [←he] - exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans - (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) - -lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : EuclideanSpace ℂ X) : - ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by - apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) - (tailKernel_row P hP a z M ha hz hM) - intro y - have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by - funext x - simp only [tailKernel,hsym x y] - rw [hs] - exact tailKernel_row P hP a z M ha hz hM y - -lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : - (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by - unfold headKernel - split_ifs with h - · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] - exact mul_nonneg (div_nonneg hz hn.le) (hP x y) - · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h - have hh := mul_le_mul_of_nonneg_right h' (hP x y) - rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] - apply (le_div_iff₀ hn).mpr - nlinarith - calc - _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := - Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) - _ = z := by - simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - - -theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] - [Fintype I] [Nonempty I] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : - μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by - let δ : ℝ := M*z^(-a) - have hδ : 0 ≤ δ := by dsimp [δ]; positivity - have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos - change μ ≤ δ+_ - by_cases hμ : μ ≤ δ - · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) - have hmd : 0 ≤ μ-δ := by linarith - have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by - have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) - rw [hv.norm_eq_one i,mul_one] at hr - have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) - rw [tail_add_head] at he - have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) - rw [←he] at hn - have hh := hvμ i - change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr - linarith - have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by - calc - _ = ∑ i : I, (μ-δ)^2 := by simp - _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := - Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) - _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv - _ ≤ z := headKernel_hs P hP hrow z hz.le - have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) - have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq - linarith - -end DensityTransfer -namespace PairRouting -open scoped BigOperators - -lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] - [DecidableEq β] [Fintype Ω] [Nonempty Ω] - (P : Ω → Equiv.Perm β) (e : ι ↪ β) : - (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by - classical - simp only [tupleProbability] - rw [←finiteMean_sum] - have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun g : ι ↪ β => g i) h - simp_rw [h] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : - tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by - classical - apply finiteMean_congr - intro ω - congr 1 - apply propext - constructor - · intro h i - have hh := congrArg (P ω) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm - · intro h i - have hh := congrArg (fun x => (P ω).symm x) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - -lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : - tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := - finiteMean_equiv τ _ - -lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) - (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : - tupleProbability P e f = tupleProbability P f e := by - rw [tupleProbability_equiv P τ.symm] - simp only [Equiv.symm_symm,hτ] - exact tupleProbability_inverse P e f - -end PairRouting - -lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : - palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by - simp only [palindromePerm,mul_inv_rev] - rfl - -lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) : - PairRouting.tupleProbability (palindromePerm d) e f = - PairRouting.tupleProbability (palindromePerm d) f e := - PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f - -theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] - [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) - (z : ℝ) (hz : 0 < z) : - μ ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ - Real.sqrt (z/(Fintype.card I:ℝ)) := by - let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ - apply DensityTransfer.multiplicity_amplification - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) - (fun e f => PairRouting.tupleProbability_nonneg _ e f) - (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) - (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ - intro e - exact palindrome_row_moment_bound d e hk - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.InputTree + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : + PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by + classical + rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] + let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) + change _ ≤ B + calc + _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by + apply finiteMean_mono + intro ω + simp only [modifiedPerm_zero] + by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E + · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] + split_ifs <;> norm_num + · simp only [h,↓reduceIte,B] + rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => + if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] + convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 + rw [Fintype.card_perm,card_positions] + _ = _ := finiteMean_const B + +noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : ModifiedCoins L r => + if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) + +lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : + 0 ≤ modifiedRoutingMoment L r E e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : + modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by + simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, + PairRouting.tupleProbability] + +lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ + centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by + have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f + rw [modifiedRoutingMoment_zero] + have hbound := modified_probability_zero_le L E e f he + have hpow := Real.rpow_le_rpow hp hbound ha + have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) + have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = + centralFactor L 0 E a := by + rw [centralFactor_zero] + split_ifs + · exact Real.one_rpow _ + · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] + rw [heq] at hpow + rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] + exact mul_le_mul_of_nonneg_right hpow hp + + +lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} + (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] + rfl + +lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (L+r+1)) (a : ℝ) : + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + let : Fintype (ModifiedCoins L r) := inferInstance + rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have he (ω : ModifiedCoins L r × ModifiedCoins L r) : + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [modified_matches_step,modifiedCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = + (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r+1)) : + PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + let : Fintype (ModifiedCoins L r) := inferInstance + rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have hp (b : Bool) (p q : ModifiedCoins L r) : + modifiedPerm L r (exceptionChild E b) (if b then p else q) = + (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by + cases b <;> rfl + simp only [modified_matches_step,hp] + + +lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + + +lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * + modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) + (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) + have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = + -(r:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + calc + _ ≤ _ := hh + _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* + (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * + (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * + (modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring + _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] + + +theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by + classical + induction r generalizing ι with + | zero => + simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using + modified_pointwise_zero L E e f he a ha + | succ r ih => + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) + have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) + have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + apply hh'.trans + have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha + convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring + have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha + rw [←modified_probability_step L r E e f] at hnode + change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) + ring + + +lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : + (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card (L+r) => + ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) + +lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (he : Function.Surjective e) : Fintype.card ι = 2^d := by + rw [←card_positions d] + exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) + +lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by + simpa only [card_positions] using E.card_le_univ + +noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := + (Nat.factorial (2^(L+r)):ℝ) / + (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) + +lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : + 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity + +lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + (Nat.factorial (2^(L+r)):ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = + modifiedNormalization L r E ^ a := by + rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, + Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), + Real.mul_rpow (by positivity) (by positivity)] + have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by + rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, + show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, + Real.rpow_neg (by positivity)] + ring + +theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ + rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * + ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * + modifiedRoutingMoment L r E e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, + card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] + +lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : + finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + let B := Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) + rw [finiteMean_prod] + apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le + rw [finiteMean_prod,finiteMean_comm] + apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le + exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) + +lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + modifiedNormalization L r E ^ (1/1000:ℝ) * + Real.exp ((2^(L+r):ℕ)*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + apply hm.trans + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) + simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e + + +lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : + Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by + induction n with + | zero => omega + | succ n ih => + by_cases hz : n = 0 + · subst n; norm_num + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) + have hn1 : (0:ℝ) < n+1 := by positivity + have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) + rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h + have hh := mul_le_mul_of_nonneg_left h hn1.le + have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring + rw [hcancel] at hh + have hi := ih (by omega) + rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] + nlinarith + +lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) = + Real.log (Nat.factorial (2^(L+r))) - + ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by + unfold modifiedNormalization + rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), + Real.log_pow,Real.log_pow,Real.log_pow, + Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + simp only [Nat.cast_pow,Nat.cast_ofNat] + +lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) ≤ + ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by + have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) + have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) + have hu := log_factorial_upper hN + have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) + simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ + rw [log_modifiedNormalization] + simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ + nlinarith + +lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + + (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + apply (modifiedRowMoment_bound L r hL E e he).trans + rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] + apply Real.exp_le_exp.mpr + have h := log_modifiedNormalization_le L r E + linarith + +lemma log_power_factorial_le (L : ℕ) : + Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by + have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by + exact_mod_cast Nat.factorial_le_pow (2^L) + have hh := Real.log_le_log (by positivity) hf + rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh + apply hh.trans + have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity + nlinarith + +lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) + (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + + (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by + apply (modified_moment_exponential L r hL E e he).trans + apply Real.exp_le_exp.mpr + have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) + have hb := mul_le_mul_of_nonneg_left momentBase_log + (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) + have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) + simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ + nlinarith + + +lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by + have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := + (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr + tendsto_natCast_atTop_atTop + have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) + convert ht using 1 + · funext L + unfold heightDecay + dsimp only [Function.comp_apply] + rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] + · simp + +noncomputable def modifiedOverhead (L r : ℕ) : ℝ := + (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) + +lemma modifiedOverhead_tendsto (L : ℕ) : + Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by + have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) + have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) + simp only [pow_one] at h₁ + simp only [pow_zero] at h₀ + have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const + ((2:ℝ)^L*1000) + convert ht using 1 + · funext r + simp only [modifiedOverhead,Nat.cast_add,pow_add] + field_simp + ring + · simp + +theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : + ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ + ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → + ∀ (e : Card (L+r) ↪ Card (L+r)), + modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by + have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := + heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists + have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL + let ε : ℝ := min (1/4) (η*250/(3*L)) + have hε : 0 < ε := lt_min (by norm_num) (by positivity) + have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) + have hεL : ε*L/250 ≤ η/3 := by + have h := min_le_right (1/4:ℝ) (η*250/(3*L)) + change ε ≤ η*250/(3*L) at h + have hh := mul_le_mul_of_nonneg_right h hL0.le + have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp + exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le + refine ⟨L,hL,ε,hε,hε1,?_⟩ + have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := + (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + filter_upwards [hr] with r hr + intro E hE e + have he := Finite.surjective_of_injective e.injective + apply (modified_moment_exception_bound L r hL E e he ε hE).trans + apply Real.exp_le_exp.mpr + have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity + have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = + (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by + unfold modifiedOverhead + field_simp + have hh := mul_le_mul_of_nonneg_right hr.le hn.le + rw [hd] at hh + have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le + linarith + + +namespace DensityTransfer +open scoped BigOperators + +noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + +lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) (x : X) : + applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl + +lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) + (v : EuclideanSpace ℂ X) : + applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by + ext x + simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] + rfl + +lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : + ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by + have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by + rw [applyKernel_apply] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] + apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans + exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) + (fun y _ => by ring_nf; exact le_rfl) + +lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) + (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) + (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by + have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by + rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] + calc + _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by + apply Finset.sum_le_sum + intro x _ + apply (kernel_component_sq P hP v x).trans + exact mul_le_mul_of_nonneg_right (hrow x) + (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) + _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by + rw [←Finset.mul_sum,Finset.sum_comm] + congr 1 + apply Finset.sum_congr rfl + intro y _ + exact (Finset.sum_mul Finset.univ _ _).symm + _ ≤ δ * ∑ y, δ*‖v y‖^2 := by + apply mul_le_mul_of_nonneg_left _ hδ + exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) + _ = _ := by rw [←Finset.mul_sum]; ring + have hn := norm_nonneg (applyKernel P v) + have hr := mul_nonneg hδ (norm_nonneg v) + nlinarith + +lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] + (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : + (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by + simp_rw [EuclideanSpace.norm_sq_eq] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro x _ + let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) + have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by + rw [norm_inner_symm] + congr 1 + simp only [applyKernel_apply,PiLp.inner_apply] + apply Finset.sum_congr rfl + intro y _ + simp [w,RCLike.inner_apply,mul_comm] + simp_rw [he] + have h := hv.sum_inner_products_le (s := Finset.univ) w + apply h.trans_eq + rw [EuclideanSpace.norm_sq_eq] + apply Finset.sum_congr rfl + intro y _ + simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] + + +lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : + (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by + split_ifs with h + · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] + apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr + rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] + exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht + · positivity + +lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : + finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by + rw [←finiteMean_mul_const] + exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) + +noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 + +noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y + +lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : + (fun x y => tailKernel P z x y+headKernel P z x y) = P := by + funext x y + unfold tailKernel headKernel + split_ifs <;> simp + +lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) + (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by + unfold tailKernel + split_ifs <;> simp only [hP,le_refl] + +lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : + ∑ y, tailKernel P z x y ≤ M*z^(-a) := by + have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then + (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by + unfold finiteMean + calc + _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by + congr 1 + apply Finset.sum_congr rfl + intro y _ + by_cases hy : z < (Fintype.card X:ℝ)*P x y + · simp only [tailKernel,hy,↓reduceIte] + · simp only [tailKernel,hy,↓reduceIte,mul_zero] + _ = _ := by rw [←Finset.mul_sum]; field_simp + rw [←he] + exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans + (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) + +lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : EuclideanSpace ℂ X) : + ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by + apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) + (tailKernel_row P hP a z M ha hz hM) + intro y + have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by + funext x + simp only [tailKernel,hsym x y] + rw [hs] + exact tailKernel_row P hP a z M ha hz hM y + +lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : + (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by + unfold headKernel + split_ifs with h + · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] + exact mul_nonneg (div_nonneg hz hn.le) (hP x y) + · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h + have hh := mul_le_mul_of_nonneg_right h' (hP x y) + rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] + apply (le_div_iff₀ hn).mpr + nlinarith + calc + _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := + Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) + _ = z := by + simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + + +theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] + [Fintype I] [Nonempty I] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : + μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by + let δ : ℝ := M*z^(-a) + have hδ : 0 ≤ δ := by dsimp [δ]; positivity + have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos + change μ ≤ δ+_ + by_cases hμ : μ ≤ δ + · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) + have hmd : 0 ≤ μ-δ := by linarith + have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by + have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) + rw [hv.norm_eq_one i,mul_one] at hr + have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) + rw [tail_add_head] at he + have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) + rw [←he] at hn + have hh := hvμ i + change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr + linarith + have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by + calc + _ = ∑ i : I, (μ-δ)^2 := by simp + _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := + Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) + _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv + _ ≤ z := headKernel_hs P hP hrow z hz.le + have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) + have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq + linarith + +end DensityTransfer +namespace PairRouting +open scoped BigOperators + +lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] + [DecidableEq β] [Fintype Ω] [Nonempty Ω] + (P : Ω → Equiv.Perm β) (e : ι ↪ β) : + (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by + classical + simp only [tupleProbability] + rw [←finiteMean_sum] + have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun g : ι ↪ β => g i) h + simp_rw [h] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : + tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by + classical + apply finiteMean_congr + intro ω + congr 1 + apply propext + constructor + · intro h i + have hh := congrArg (P ω) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm + · intro h i + have hh := congrArg (fun x => (P ω).symm x) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + +lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : + tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := + finiteMean_equiv τ _ + +lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) + (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : + tupleProbability P e f = tupleProbability P f e := by + rw [tupleProbability_equiv P τ.symm] + simp only [Equiv.symm_symm,hτ] + exact tupleProbability_inverse P e f + +end PairRouting + +lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : + palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by + simp only [palindromePerm,mul_inv_rev] + rfl + +lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) : + PairRouting.tupleProbability (palindromePerm d) e f = + PairRouting.tupleProbability (palindromePerm d) f e := + PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f + +theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] + [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) + (z : ℝ) (hz : 0 < z) : + μ ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ + Real.sqrt (z/(Fintype.card I:ℝ)) := by + let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ + apply DensityTransfer.multiplicity_amplification + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) + (fun e f => PairRouting.tupleProbability_nonneg _ e f) + (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) + (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ + intro e + exact palindrome_row_moment_bound d e hk + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/PairAssembleEquiv.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/PairAssembleEquiv.lean index 9e7104213e9ec904b85fa1e09e170cd1d52cea43..fa34095949efdefaff728903add8ffbdb6f2d130 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/PairAssembleEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/PairAssembleEquiv.lean @@ -1,835 +1,835 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.BlockProduct - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators Classical - -def pairAssembleEquiv (B C H : Type*) : - ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where - toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) - invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) - left_inv _w := rfl - right_inv _w := rfl - -def palindromeStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := - (pairAssembleEquiv _ _ _).trans - (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) - -lemma palindromeStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - palindromeStageEquiv r L w= - (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by - simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] - -def modifiedAssembleEquiv (B C H U : Type*) : - ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where - toFun w := ((fun b => (w.1.2 b).1), - (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) - invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) - left_inv _w := rfl - right_inv _w := rfl - -def modifiedStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ - ModifiedCoins L r := - (modifiedAssembleEquiv _ _ _ _).trans - (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) - -lemma modifiedStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - modifiedStageEquiv r L w= - ((fun b => (w.1.2 b).1), - (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by - simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] - -lemma palindrome_stage (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [palindromeStageEquiv_apply] - change splitPerm r L (_*_⁻¹)=_ - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - rfl - -noncomputable def localModifiedPerm (L : ℕ) (e : Bool) - (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := - if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ - -lemma modified_stage (r L : ℕ) (E : Finset (Card r)) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [modifiedStageEquiv_apply] - unfold modifiedPerm modifiedInputTree - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - congr 2 - apply congrArg ParallelBlocks.lift - funext b - simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] - by_cases h : b∈E <;> simp [h] - -end Thorp -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= - sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by - rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), - sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] - -lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : - sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by - cases e - · simp only [Bool.false_eq_true,ite_false] - rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] - exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) - · simp only [ite_true] - exact sampleOperator_one ρ - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma sampleOperator_palindrome_stage (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) - -lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift - (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := - funext (modified_stage r L E) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) - -end Thorp -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] [DecidableEq ι] - -noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1 else P i - -omit [CompleteSpace V] [Fintype ι] in -lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) - (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by - unfold retain - split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ - -omit [CompleteSpace V] in -lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : - blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by - have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E - have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right - (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) - simp only [hs] at hh - change blocks (retain P E) (retain_commute P hP E)=_ at hh - rw [hh] - have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by - exact (Finset.noncommProd_eq_pow_card E (retain P E) - (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) - rw [he,one_mul] - apply Finset.noncommProd_congr rfl - intro i hi - exact ite_eq_right (Finset.mem_compl.mp hi) - -end Thorp.CommutingBlocks - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := - uniformOperator (ρ.comp (injection b)) - -omit [Fintype B] in -lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : - Commute (centralProjection ρ b) (centralProjection ρ c) := by - simpa only [centralProjection,sampleOperator_uniform] using - local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c - -omit [Fintype B] in -lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by - by_cases h : b=c - · subst c - change _*uniformOperator _=uniformOperator _*_ - rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] - · unfold centralProjection - rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite ParallelBlocks CommutingBlocks -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= - coarse (centralProjection ρ) (centralProjection_commute ρ) E := by - rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] - apply Finset.noncommProd_congr rfl - · intro b _ - rw [localModified_average] - simp only [retain,centralProjection,decide_eq_true_eq] - · intro b _ c _ _ - exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c - -lemma central_local_gap (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : - ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by - change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ - rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] - exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) - -lemma central_blocks_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) - (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : - ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) - (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L)) - (local_central_commute ρ (fun _ => palindromePerm L)) - (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) - (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) - B.adjoint hB n - simpa only [ContinuousLinearMap.adjoint_adjoint] using h - -theorem palindrome_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : - ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] - apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) - (sampleOperator_norm_le ρ hρ _) n).trans_eq - congr 1 - apply Finset.sum_congr rfl - intro E _ - split_ifs - · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] - · rfl - -end Thorp - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] - -noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := - finiteMean (fun ω => if a (P ω) x=y then 1 else 0) - -omit [Fintype G] in -lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) - (v : EuclideanSpace ℂ X) (x : X) : - DensityTransfer.applyKernel (actionKernel a P) v x = - (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by - simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, - Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] - rw [Finset.sum_comm] - calc - _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by - apply Finset.sum_congr rfl - intro ω _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all - _ = _ := by simp [Finset.mul_sum] - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : - DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = - normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by - ext x - rw [actionKernel_apply] - simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, - coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, - inner_smul_right,inner_sum] - apply Finset.sum_congr rfl - intro ω _ - have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x - change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = - inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h - rw [h] - ring - -noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : - Submodule ℂ V where - carrier := {w | IsFixed a x₀ ρ w} - zero_mem' := fun g hg => map_zero _ - add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] - smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] - -theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : - ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - let K := fixedSpace a x₀ ρ - let m := Module.finrank ℂ K - let : Nonempty X := ⟨x₀⟩ - let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ - let B := stdOrthonormalBasis ℂ K - let w : Fin m → V := fun i => (B i : V) - have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 - have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ - have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv - have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) - (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by - rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), - normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] - have h := DensityTransfer.multiplicity_amplification (actionKernel a P) - (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow - b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) - simpa only [Fintype.card_fin] using h - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where - toFun p := - { toFun := fun e => e.trans p.toEmbedding - invFun := fun e => e.trans p.symm.toEmbedding - left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) - right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } - map_one' := by ext e i; rfl - map_mul' p q := by ext e i; rfl - -omit [Fintype α] [Fintype ι] in -@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : - tupleAction p e i=p (e i) := rfl - -omit [Fintype α] in -lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by - obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective - exact ⟨p,Function.Embedding.ext hp⟩ - -omit [Fintype α] in -lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : - tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by - constructor - · intro h x hx - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx - exact congrArg (fun f : ι ↪ α => f i) h - · intro h - ext i - exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - -omit [Fintype α] in -lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) - (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by - unfold actionKernel PairRouting.tupleProbability - congr 1 - funext ω - congr 1 - exact propext Function.Embedding.ext_iff - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -lemma irreducible_of_equiv {G V W : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : - Representation.IsIrreducible σ := by - rw [Representation.irreducible_iff_isSimpleModule_asModule] - have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance - let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := - Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap - have hf : Function.Bijective f := e.toLinearEquiv.bijective - exact (f.isSimpleModule_iff_of_bijective hf).mp hi - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : hilbertSpace μ) : - (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = - PermutationHilbert.act (tabloidAct p) v := by - obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v - change hilbertEquiv μ (tabloidRep μ p w) = _ - exact hilbert_action μ p w - -noncomputable def unitaryEquiv (μ : YoungDiagram) : - Representation.Equiv (representation μ) (unitaryRepresentation μ) := - Representation.Equiv.mk (spaceHilbertEquiv μ) (by - intro p - apply LinearMap.ext - intro v - change spaceHilbertEquiv μ (representation μ p v) = - spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) - rw [LinearEquiv.symm_apply_apply]) - -lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (unitaryRepresentation μ) := by - let := representation_irreducible μ - exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) - -lemma unitaryRepresentation_unitary (μ : YoungDiagram) : - UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by - intro p v w - change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) - (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ - rw [unitaryRepresentation_coe,unitaryRepresentation_coe] - exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w - - -noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] - fixedHilbert μ (Finset.univ.image e) where - toFun v := ⟨v.1.1,v.1.2,by - intro p hp - have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) - exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ - invFun v := ⟨⟨v.1,v.2.1⟩,by - intro p hp - apply Subtype.ext - exact (unitaryRepresentation_coe μ p _).trans - (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] - have h := fixedHilbert_dimension μ (Finset.univ.image e) - simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h - -end Thorp.Specht -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : - sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by - simp only [sampleOperator,randomOperator,smul_apply, - sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] - -theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : - ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) - intro v hv - rw [sampleOperator_inv_apply] - exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : - Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where - toFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun g v hv => by - have h := U.apply_mem_toSubmodule (e.symm g) hv - change ρ (e (e.symm g)) v∈U.toSubmodule at h - simpa only [e.apply_symm_apply] using h } - invFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } - left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - map_rel_iff' := Iff.rfl - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by - exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -omit [Fintype α] in -lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by - intro g v w - exact unitaryRepresentation_unitary μ (e.permCongr g) v w - -omit [Fintype α] in -lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation.IsIrreducible (relabelledUnitary μ e) := by - let := unitaryRepresentation_irreducible μ - exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom - -noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where - toFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg - change g (e (f i))=e (f i) at hh - simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] - have hh := v.2 (e.symm.permCongr g) hp - change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh - have he : e.permCongr (e.symm.permCongr g)=g := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] - simpa only [he] using hh⟩ - invFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ α => f i) hg - change g (f i)=f i at hh - simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, - Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] - exact v.2 (e.permCongr g) hp⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -omit [Fintype α] in -lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(relabelledTupleFixed μ e f).finrank_eq] - exact tupleFixed_dimension μ (f.trans e.toEmbedding) - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x ∈ A, p x = x} - one_mem' := by intro x _; rfl - mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] - inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm - -lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) - (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by - intro z hz - exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) - -lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : - Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by - classical - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := - { toFun := fun x => ⟨p x.1,x.2⟩ - invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } - have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by - rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] - have hr := Specht.rowLen_zero_le_card μ - omega - obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) - (by simpa only [Fintype.card_fin] using hc) - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), - swap_mem_pointStabilizer A _ _ x.2 y.2⟩ - apply Specht.symmetrizer_eq_zero_of_neg _ _ h - change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) - rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] - rw [map_mul, Module.End.mul_apply, - Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - -lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by - classical - have hz := point_symmetrizer_zero μ A hA v hv - have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = - (Fintype.card (pointStabilizer A) : ℂ) • v := by - simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), - Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] - rw [he] at hz - exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) - -lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by - let w := (Specht.spaceHilbertEquiv μ).symm v - have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by - intro p hp - have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) - change Specht.representation μ p w = w at he - exact congrArg Subtype.val he - have hz := point_fixed_zero μ A hA w.val w.prop hw - have hw0 : w = 0 := Subtype.ext hz - have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 - simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he - -lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) - (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) - (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by - classical - apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v - intro p hp - have hf : e.symm.permCongr p ∈ pointStabilizer A := by - intro x hx - have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) - simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] - have hh := hfix _ hf - change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh - have he : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] - simpa only [he] using hh - - -lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) - (hG : ∀ v, ∃ w, G.Adj v w) : - ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ - ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by - classical - obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le - let c := hF.coloringTwo - have hneigh (v : V) : ∃ w, F.Adj v w := by - obtain ⟨w, hvw⟩ := hG v - have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable - exact hr.nonempty_neighborSet_left hvw.ne - let A : Finset V := Finset.univ.filter (fun v => c v = 0) - let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) - have hab : A.card + B.card = Fintype.card V := by - exact Finset.card_filter_add_card_filter_not _ - have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw - by_cases h : A.card ≤ B.card - · refine ⟨A, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v ≠ 0 := by simpa [A] using hv - have hw0 : c w = 0 := by - have hv1 : c v = 1 := by omega - have hn := hcolor hvw - omega - exact ⟨w, by simp [A, hw0], hFG hvw⟩ - · refine ⟨B, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v = 0 := by simpa [B] using hv - have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm - exact ⟨w, by simp [B, hw0], hFG hvw⟩ - -lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : - (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by - rw [← Finset.prod_one_add, Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro v _; exact add_nonneg (by norm_num) (hp v) - · intro v _ - have h := Real.add_one_le_exp (p v) - linarith - -lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : - (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ - δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by - have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : - (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by - rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] - field_simp - calc - _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by - rw [Finset.mul_sum] - exact Finset.sum_congr rfl hsplit - _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by - apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro L hL - exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 - · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) - _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := - mul_le_mul_of_nonneg_left - (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) - (pow_nonneg hδ.le _) - _ = _ := by rw [Finset.sum_div] - -noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) - (R : Finset V) : Finset V := by - classical - exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) - -lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : - (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by - classical - calc - _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum - intro w hw - obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 - have h : (if G.Adj v w then p w else 0) ≤ - ∑ u ∈ R, if G.Adj u w then p w else 0 := - Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv - simpa only [ite_eq_left hvw] using h - _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro w _ _ - exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) - _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm - _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) - _ = _ := by simp - -lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) - (R : Finset V) (hR : 2 * R.card ≤ k) : - (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ - δ^((k:ℝ)/2) * Real.exp R.card := by - classical - have hmass := neighborhood_weight_le G p hp δ hdeg R - have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by - rw [← Real.rpow_natCast] - apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 - have hr : R.card ≤ k := by omega - rw [Nat.cast_sub hr] - have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR - linarith - apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans - apply mul_le_mul hpow - · apply Real.exp_le_exp.mpr - exact (div_le_iff₀ hδ).mpr hmass - · positivity - · positivity - -def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := - ∀ v ∈ S, ∃ w ∈ S, G.Adj v w - -lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) - (S : Finset V) (hS : NoIsolated G S) : - ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by - classical - let H := G.induce (S : Set V) - have hH : ∀ v : S, ∃ w : S, H.Adj v w := by - intro v - obtain ⟨w, hw, hvw⟩ := hS v v.2 - exact ⟨⟨w, hw⟩, hvw⟩ - obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH - let T := R.image (fun v : S => (v : V)) - have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective - refine ⟨T, ?_, ?_, ?_⟩ - · intro v hv - obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv - exact w.2 - · simpa [hc, H] using hR - · intro v hv - have hvS := (Finset.mem_sdiff.mp hv).1 - have hvR : (⟨v, hvS⟩ : S) ∉ R := by - intro hh - exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) - obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR - exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, - ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ - -end Thorp.SparseContact - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.BlockProduct + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators Classical + +def pairAssembleEquiv (B C H : Type*) : + ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where + toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) + invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) + left_inv _w := rfl + right_inv _w := rfl + +def palindromeStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := + (pairAssembleEquiv _ _ _).trans + (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) + +lemma palindromeStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + palindromeStageEquiv r L w= + (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by + simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] + +def modifiedAssembleEquiv (B C H U : Type*) : + ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where + toFun w := ((fun b => (w.1.2 b).1), + (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) + invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) + left_inv _w := rfl + right_inv _w := rfl + +def modifiedStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ + ModifiedCoins L r := + (modifiedAssembleEquiv _ _ _ _).trans + (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) + +lemma modifiedStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + modifiedStageEquiv r L w= + ((fun b => (w.1.2 b).1), + (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by + simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] + +lemma palindrome_stage (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [palindromeStageEquiv_apply] + change splitPerm r L (_*_⁻¹)=_ + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + rfl + +noncomputable def localModifiedPerm (L : ℕ) (e : Bool) + (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := + if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ + +lemma modified_stage (r L : ℕ) (E : Finset (Card r)) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [modifiedStageEquiv_apply] + unfold modifiedPerm modifiedInputTree + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + congr 2 + apply congrArg ParallelBlocks.lift + funext b + simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] + by_cases h : b∈E <;> simp [h] + +end Thorp +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= + sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by + rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), + sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] + +lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : + sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by + cases e + · simp only [Bool.false_eq_true,ite_false] + rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] + exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) + · simp only [ite_true] + exact sampleOperator_one ρ + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma sampleOperator_palindrome_stage (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) + +lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift + (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := + funext (modified_stage r L E) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) + +end Thorp +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1 else P i + +omit [CompleteSpace V] [Fintype ι] in +lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) + (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by + unfold retain + split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ + +omit [CompleteSpace V] in +lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : + blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by + have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E + have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right + (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) + simp only [hs] at hh + change blocks (retain P E) (retain_commute P hP E)=_ at hh + rw [hh] + have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by + exact (Finset.noncommProd_eq_pow_card E (retain P E) + (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) + rw [he,one_mul] + apply Finset.noncommProd_congr rfl + intro i hi + exact ite_eq_right (Finset.mem_compl.mp hi) + +end Thorp.CommutingBlocks + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := + uniformOperator (ρ.comp (injection b)) + +omit [Fintype B] in +lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : + Commute (centralProjection ρ b) (centralProjection ρ c) := by + simpa only [centralProjection,sampleOperator_uniform] using + local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c + +omit [Fintype B] in +lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by + by_cases h : b=c + · subst c + change _*uniformOperator _=uniformOperator _*_ + rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] + · unfold centralProjection + rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite ParallelBlocks CommutingBlocks +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= + coarse (centralProjection ρ) (centralProjection_commute ρ) E := by + rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] + apply Finset.noncommProd_congr rfl + · intro b _ + rw [localModified_average] + simp only [retain,centralProjection,decide_eq_true_eq] + · intro b _ c _ _ + exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c + +lemma central_local_gap (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : + ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by + change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ + rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] + exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) + +lemma central_blocks_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) + (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : + ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) + (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L)) + (local_central_commute ρ (fun _ => palindromePerm L)) + (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) + (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) + B.adjoint hB n + simpa only [ContinuousLinearMap.adjoint_adjoint] using h + +theorem palindrome_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : + ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] + apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) + (sampleOperator_norm_le ρ hρ _) n).trans_eq + congr 1 + apply Finset.sum_congr rfl + intro E _ + split_ifs + · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] + · rfl + +end Thorp + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] + +noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := + finiteMean (fun ω => if a (P ω) x=y then 1 else 0) + +omit [Fintype G] in +lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) + (v : EuclideanSpace ℂ X) (x : X) : + DensityTransfer.applyKernel (actionKernel a P) v x = + (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by + simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, + Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] + rw [Finset.sum_comm] + calc + _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by + apply Finset.sum_congr rfl + intro ω _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all + _ = _ := by simp [Finset.mul_sum] + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : + DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = + normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by + ext x + rw [actionKernel_apply] + simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, + coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, + inner_smul_right,inner_sum] + apply Finset.sum_congr rfl + intro ω _ + have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x + change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = + inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h + rw [h] + ring + +noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : + Submodule ℂ V where + carrier := {w | IsFixed a x₀ ρ w} + zero_mem' := fun g hg => map_zero _ + add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] + smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] + +theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : + ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + let K := fixedSpace a x₀ ρ + let m := Module.finrank ℂ K + let : Nonempty X := ⟨x₀⟩ + let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ + let B := stdOrthonormalBasis ℂ K + let w : Fin m → V := fun i => (B i : V) + have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 + have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ + have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv + have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) + (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by + rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), + normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] + have h := DensityTransfer.multiplicity_amplification (actionKernel a P) + (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow + b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) + simpa only [Fintype.card_fin] using h + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where + toFun p := + { toFun := fun e => e.trans p.toEmbedding + invFun := fun e => e.trans p.symm.toEmbedding + left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) + right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } + map_one' := by ext e i; rfl + map_mul' p q := by ext e i; rfl + +omit [Fintype α] [Fintype ι] in +@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : + tupleAction p e i=p (e i) := rfl + +omit [Fintype α] in +lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by + obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective + exact ⟨p,Function.Embedding.ext hp⟩ + +omit [Fintype α] in +lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : + tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by + constructor + · intro h x hx + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + exact congrArg (fun f : ι ↪ α => f i) h + · intro h + ext i + exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + +omit [Fintype α] in +lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) + (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by + unfold actionKernel PairRouting.tupleProbability + congr 1 + funext ω + congr 1 + exact propext Function.Embedding.ext_iff + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +lemma irreducible_of_equiv {G V W : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : + Representation.IsIrreducible σ := by + rw [Representation.irreducible_iff_isSimpleModule_asModule] + have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance + let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := + Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap + have hf : Function.Bijective f := e.toLinearEquiv.bijective + exact (f.isSimpleModule_iff_of_bijective hf).mp hi + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : hilbertSpace μ) : + (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = + PermutationHilbert.act (tabloidAct p) v := by + obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v + change hilbertEquiv μ (tabloidRep μ p w) = _ + exact hilbert_action μ p w + +noncomputable def unitaryEquiv (μ : YoungDiagram) : + Representation.Equiv (representation μ) (unitaryRepresentation μ) := + Representation.Equiv.mk (spaceHilbertEquiv μ) (by + intro p + apply LinearMap.ext + intro v + change spaceHilbertEquiv μ (representation μ p v) = + spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) + rw [LinearEquiv.symm_apply_apply]) + +lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (unitaryRepresentation μ) := by + let := representation_irreducible μ + exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) + +lemma unitaryRepresentation_unitary (μ : YoungDiagram) : + UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by + intro p v w + change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) + (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ + rw [unitaryRepresentation_coe,unitaryRepresentation_coe] + exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w + + +noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] + fixedHilbert μ (Finset.univ.image e) where + toFun v := ⟨v.1.1,v.1.2,by + intro p hp + have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) + exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ + invFun v := ⟨⟨v.1,v.2.1⟩,by + intro p hp + apply Subtype.ext + exact (unitaryRepresentation_coe μ p _).trans + (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] + have h := fixedHilbert_dimension μ (Finset.univ.image e) + simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h + +end Thorp.Specht +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : + sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by + simp only [sampleOperator,randomOperator,smul_apply, + sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] + +theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : + ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) + intro v hv + rw [sampleOperator_inv_apply] + exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : + Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where + toFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun g v hv => by + have h := U.apply_mem_toSubmodule (e.symm g) hv + change ρ (e (e.symm g)) v∈U.toSubmodule at h + simpa only [e.apply_symm_apply] using h } + invFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } + left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + map_rel_iff' := Iff.rfl + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by + exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +omit [Fintype α] in +lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by + intro g v w + exact unitaryRepresentation_unitary μ (e.permCongr g) v w + +omit [Fintype α] in +lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation.IsIrreducible (relabelledUnitary μ e) := by + let := unitaryRepresentation_irreducible μ + exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom + +noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where + toFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg + change g (e (f i))=e (f i) at hh + simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] + have hh := v.2 (e.symm.permCongr g) hp + change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh + have he : e.permCongr (e.symm.permCongr g)=g := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] + simpa only [he] using hh⟩ + invFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ α => f i) hg + change g (f i)=f i at hh + simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, + Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] + exact v.2 (e.permCongr g) hp⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +omit [Fintype α] in +lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(relabelledTupleFixed μ e f).finrank_eq] + exact tupleFixed_dimension μ (f.trans e.toEmbedding) + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x ∈ A, p x = x} + one_mem' := by intro x _; rfl + mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] + inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm + +lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) + (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by + intro z hz + exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) + +lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : + Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by + classical + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := + { toFun := fun x => ⟨p x.1,x.2⟩ + invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } + have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by + rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] + have hr := Specht.rowLen_zero_le_card μ + omega + obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) + (by simpa only [Fintype.card_fin] using hc) + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), + swap_mem_pointStabilizer A _ _ x.2 y.2⟩ + apply Specht.symmetrizer_eq_zero_of_neg _ _ h + change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) + rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] + rw [map_mul, Module.End.mul_apply, + Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + +lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by + classical + have hz := point_symmetrizer_zero μ A hA v hv + have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = + (Fintype.card (pointStabilizer A) : ℂ) • v := by + simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), + Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] + rw [he] at hz + exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) + +lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by + let w := (Specht.spaceHilbertEquiv μ).symm v + have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by + intro p hp + have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) + change Specht.representation μ p w = w at he + exact congrArg Subtype.val he + have hz := point_fixed_zero μ A hA w.val w.prop hw + have hw0 : w = 0 := Subtype.ext hz + have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 + simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he + +lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) + (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) + (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by + classical + apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v + intro p hp + have hf : e.symm.permCongr p ∈ pointStabilizer A := by + intro x hx + have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) + simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] + have hh := hfix _ hf + change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh + have he : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] + simpa only [he] using hh + + +lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) + (hG : ∀ v, ∃ w, G.Adj v w) : + ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ + ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by + classical + obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le + let c := hF.coloringTwo + have hneigh (v : V) : ∃ w, F.Adj v w := by + obtain ⟨w, hvw⟩ := hG v + have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable + exact hr.nonempty_neighborSet_left hvw.ne + let A : Finset V := Finset.univ.filter (fun v => c v = 0) + let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) + have hab : A.card + B.card = Fintype.card V := by + exact Finset.card_filter_add_card_filter_not _ + have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw + by_cases h : A.card ≤ B.card + · refine ⟨A, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v ≠ 0 := by simpa [A] using hv + have hw0 : c w = 0 := by + have hv1 : c v = 1 := by omega + have hn := hcolor hvw + omega + exact ⟨w, by simp [A, hw0], hFG hvw⟩ + · refine ⟨B, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v = 0 := by simpa [B] using hv + have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm + exact ⟨w, by simp [B, hw0], hFG hvw⟩ + +lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : + (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by + rw [← Finset.prod_one_add, Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro v _; exact add_nonneg (by norm_num) (hp v) + · intro v _ + have h := Real.add_one_le_exp (p v) + linarith + +lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : + (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ + δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by + have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : + (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by + rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] + field_simp + calc + _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl hsplit + _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by + apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro L hL + exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 + · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) + _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := + mul_le_mul_of_nonneg_left + (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) + (pow_nonneg hδ.le _) + _ = _ := by rw [Finset.sum_div] + +noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) + (R : Finset V) : Finset V := by + classical + exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) + +lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : + (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by + classical + calc + _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum + intro w hw + obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 + have h : (if G.Adj v w then p w else 0) ≤ + ∑ u ∈ R, if G.Adj u w then p w else 0 := + Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv + simpa only [ite_eq_left hvw] using h + _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro w _ _ + exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) + _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm + _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) + _ = _ := by simp + +lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) + (R : Finset V) (hR : 2 * R.card ≤ k) : + (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ + δ^((k:ℝ)/2) * Real.exp R.card := by + classical + have hmass := neighborhood_weight_le G p hp δ hdeg R + have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 + have hr : R.card ≤ k := by omega + rw [Nat.cast_sub hr] + have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR + linarith + apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans + apply mul_le_mul hpow + · apply Real.exp_le_exp.mpr + exact (div_le_iff₀ hδ).mpr hmass + · positivity + · positivity + +def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := + ∀ v ∈ S, ∃ w ∈ S, G.Adj v w + +lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) + (S : Finset V) (hS : NoIsolated G S) : + ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by + classical + let H := G.induce (S : Set V) + have hH : ∀ v : S, ∃ w : S, H.Adj v w := by + intro v + obtain ⟨w, hw, hvw⟩ := hS v v.2 + exact ⟨⟨w, hw⟩, hvw⟩ + obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH + let T := R.image (fun v : S => (v : V)) + have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective + refine ⟨T, ?_, ?_, ?_⟩ + · intro v hv + obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv + exact w.2 + · simpa [hc, H] using hR + · intro v hv + have hvS := (Finset.mem_sdiff.mp hv).1 + have hvR : (⟨v, hvS⟩ : S) ∉ R := by + intro hh + exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) + obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ + +end Thorp.SparseContact + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/PalindromeFamilyCost.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/PalindromeFamilyCost.lean index b2cf9a579ef63cc544292658384ad7ec5d31bcd8..3756d494f6a3312442c1862d8cefdfc52aed306e 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/PalindromeFamilyCost.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/PalindromeFamilyCost.lean @@ -1,880 +1,880 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.CutoffMass - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) - (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by - have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by - apply (mem_orbitSet _ _ _).mpr - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - have he (n : ℕ) : (p^n) x = (q^n) x := by - induction n with - | zero => rfl - | succ n ih => - rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] - exact h _ (hp n) - ext y - simp only [mem_orbitSet] - constructor - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,←he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - -noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) - (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by - refine ⟨C.val,?_,C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ - intro z hz - exact h z (hC z (hx ▸ hz)) - -noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by - classical - by_cases hb : ∃ x ∈ C.val, x ∈ B - · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ - · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) - -lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by - classical - intro C D he - by_cases hC : ∃ x ∈ C.val, x ∈ B <;> - by_cases hD : ∃ x ∈ D.val, x ∈ B - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he - have hx : hC.choose = hD.choose := congrArg Subtype.val he - exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 - (hx.symm ▸ hD.choose_spec.1) - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he - have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he - exact Subtype.ext hval - -theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by - have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) - simpa only [Fintype.card_sum,Fintype.card_coe] using hh - - -noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := - (Finset.univ.filter (fun x => p x ≠ q x)).card - -lemma permDistance_sum (p q : Equiv.Perm α) : - permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by - classical - simp [permDistance,Finset.card_filter] - -lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by - simp [permDistance] - -lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := - (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) - -lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by - simp only [permDistance,ne_comm] - -lemma permDistance_triangle (p q r : Equiv.Perm α) : - permDistance p r ≤ permDistance p q+permDistance q r := by - classical - simp only [permDistance_sum,←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro x _ - by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> - by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> - omega - -lemma permDistance_mul_left (p q g : Equiv.Perm α) : - permDistance (g*p) (g*q) = permDistance p q := by - classical - unfold permDistance - congr 1 - ext x - simp only [Finset.mem_filter,Finset.mem_univ,true_and] - exact not_congr g.injective.eq_iff - -lemma permDistance_mul_right (p q g : Equiv.Perm α) : - permDistance (p*g) (q*g) = permDistance p q := by - classical - simp only [permDistance_sum,Equiv.Perm.mul_apply] - exact Fintype.sum_equiv g _ _ (fun _ => rfl) - -lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by - have hh := permDistance_mul_left p⁻¹ q⁻¹ q - have hhh := permDistance_mul_right (q*p⁻¹) 1 p - simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh - rw [←hhh] at hh - rw [←hh,permDistance_symm] - -lemma permDistance_mul_le (p q g h : Equiv.Perm α) : - permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by - have hh := permDistance_triangle (p*g) (q*g) (q*h) - simpa only [permDistance_mul_left,permDistance_mul_right] using hh - -lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by - apply selectedCycle_perturb_le - intro x hx - simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx - -lemma permDistance_alternating (p q : Equiv.Perm α) : - permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by - classical - simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] - simp [CycleColoring.alternatingPerm] - -lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ - (permDistance (p false) (q false)+permDistance (p true) (q true)) := by - have hh := selectedCycle_distance_le - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) - rw [permDistance_alternating] at hh - apply hh.trans - apply Nat.add_le_add_left - dsimp only [PairRouting.alternatingProjection] - exact (permDistance_mul_le _ _ _ _).trans_eq (by - change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ - rw [permDistance_inv]) - -end Thorp -namespace Thorp - -def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - Equiv.Perm (Card (L+r)) - | 0, C => C (fun j => Fin.elim0 j) - | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) - -def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * - (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ - -lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - (c : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r - (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by - change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * - childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * - (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - simp only [mul_assoc] - rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → - (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ - | 0, _, _, _, _, _ => 0 - | r+1, C, _, _, e, ω => - let σ := benesStepEquiv (L+r) ω - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) σ.1.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := - ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω - -lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - permDistance (childLift p) (childLift q) = - permDistance (p false) (q false)+permDistance (p true) (q true) := by - classical - rw [permDistance_sum] - have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = - ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by - apply Fintype.sum_equiv (headTailEquiv d) - intro x - have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl - rw [hx] - congr 1 - apply propext - constructor - · intro h - have ht := congrArg Fin.tail h - simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht - · intro h - dsimp only [childLift,Equiv.coe_fn_mk] - exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h - rw [hh] - simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] - omega - -noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := - ∑ u : Card r, permDistance (C u) (D u) - -lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : - centralDistance L (r+1) C D = - centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ - centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by - classical - unfold centralDistance - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) - (fun x => by - change permDistance (C x) (D x) = - permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) - rw [Fin.cons_self_tail])] - simp only [Fintype.sum_prod_type,Fintype.sum_bool] - omega - -lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : - permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by - induction r with - | zero => - simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] - -lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : - permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = - centralDistance L r C D := by - rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, - permDistance_mul_left,permDistance_centralBlock] - -lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x coins.1 - let hc := PairRouting.colors_compatible x coins.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) ω.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) ω.2 := by - rw [centralLevelCost] - rfl - -lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by - induction r generalizing ι with - | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] - dsimp only - split_ifs with ht - · have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (benesStepEquiv (L+r) ω).2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh - · rw [centralDistance_step] - have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) false) - (benesStepEquiv (L+r) ω).1.1 - have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) true) - (benesStepEquiv (L+r) ω).1.2 - omega - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.CutoffMass + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) + (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by + have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by + apply (mem_orbitSet _ _ _).mpr + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + have he (n : ℕ) : (p^n) x = (q^n) x := by + induction n with + | zero => rfl + | succ n ih => + rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] + exact h _ (hp n) + ext y + simp only [mem_orbitSet] + constructor + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,←he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + +noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) + (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by + refine ⟨C.val,?_,C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ + intro z hz + exact h z (hC z (hx ▸ hz)) + +noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by + classical + by_cases hb : ∃ x ∈ C.val, x ∈ B + · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ + · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) + +lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by + classical + intro C D he + by_cases hC : ∃ x ∈ C.val, x ∈ B <;> + by_cases hD : ∃ x ∈ D.val, x ∈ B + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he + have hx : hC.choose = hD.choose := congrArg Subtype.val he + exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 + (hx.symm ▸ hD.choose_spec.1) + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he + have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he + exact Subtype.ext hval + +theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by + have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) + simpa only [Fintype.card_sum,Fintype.card_coe] using hh + + +noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := + (Finset.univ.filter (fun x => p x ≠ q x)).card + +lemma permDistance_sum (p q : Equiv.Perm α) : + permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by + classical + simp [permDistance,Finset.card_filter] + +lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by + simp [permDistance] + +lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := + (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) + +lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by + simp only [permDistance,ne_comm] + +lemma permDistance_triangle (p q r : Equiv.Perm α) : + permDistance p r ≤ permDistance p q+permDistance q r := by + classical + simp only [permDistance_sum,←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro x _ + by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> + by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> + omega + +lemma permDistance_mul_left (p q g : Equiv.Perm α) : + permDistance (g*p) (g*q) = permDistance p q := by + classical + unfold permDistance + congr 1 + ext x + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact not_congr g.injective.eq_iff + +lemma permDistance_mul_right (p q g : Equiv.Perm α) : + permDistance (p*g) (q*g) = permDistance p q := by + classical + simp only [permDistance_sum,Equiv.Perm.mul_apply] + exact Fintype.sum_equiv g _ _ (fun _ => rfl) + +lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by + have hh := permDistance_mul_left p⁻¹ q⁻¹ q + have hhh := permDistance_mul_right (q*p⁻¹) 1 p + simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh + rw [←hhh] at hh + rw [←hh,permDistance_symm] + +lemma permDistance_mul_le (p q g h : Equiv.Perm α) : + permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by + have hh := permDistance_triangle (p*g) (q*g) (q*h) + simpa only [permDistance_mul_left,permDistance_mul_right] using hh + +lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by + apply selectedCycle_perturb_le + intro x hx + simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx + +lemma permDistance_alternating (p q : Equiv.Perm α) : + permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by + classical + simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] + simp [CycleColoring.alternatingPerm] + +lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ + (permDistance (p false) (q false)+permDistance (p true) (q true)) := by + have hh := selectedCycle_distance_le + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) + rw [permDistance_alternating] at hh + apply hh.trans + apply Nat.add_le_add_left + dsimp only [PairRouting.alternatingProjection] + exact (permDistance_mul_le _ _ _ _).trans_eq (by + change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ + rw [permDistance_inv]) + +end Thorp +namespace Thorp + +def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + Equiv.Perm (Card (L+r)) + | 0, C => C (fun j => Fin.elim0 j) + | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) + +def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * + (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ + +lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + (c : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r + (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by + change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * + childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * + (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + simp only [mul_assoc] + rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → + (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ + | 0, _, _, _, _, _ => 0 + | r+1, C, _, _, e, ω => + let σ := benesStepEquiv (L+r) ω + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) σ.1.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := + ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω + +lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + permDistance (childLift p) (childLift q) = + permDistance (p false) (q false)+permDistance (p true) (q true) := by + classical + rw [permDistance_sum] + have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = + ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by + apply Fintype.sum_equiv (headTailEquiv d) + intro x + have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl + rw [hx] + congr 1 + apply propext + constructor + · intro h + have ht := congrArg Fin.tail h + simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht + · intro h + dsimp only [childLift,Equiv.coe_fn_mk] + exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h + rw [hh] + simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] + omega + +noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := + ∑ u : Card r, permDistance (C u) (D u) + +lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : + centralDistance L (r+1) C D = + centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ + centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by + classical + unfold centralDistance + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) + (fun x => by + change permDistance (C x) (D x) = + permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) + rw [Fin.cons_self_tail])] + simp only [Fintype.sum_prod_type,Fintype.sum_bool] + omega + +lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : + permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by + induction r with + | zero => + simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] + +lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : + permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = + centralDistance L r C D := by + rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, + permDistance_mul_left,permDistance_centralBlock] + +lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x coins.1 + let hc := PairRouting.colors_compatible x coins.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) ω.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) ω.2 := by + rw [centralLevelCost] + rfl + +lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by + induction r generalizing ι with + | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] + dsimp only + split_ifs with ht + · have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (benesStepEquiv (L+r) ω).2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh + · rw [centralDistance_step] + have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) false) + (benesStepEquiv (L+r) ω).1.1 + have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) true) + (benesStepEquiv (L+r) ω).1.2 + omega + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/ParallelFollow.lean index 6cdd396a0d457832461494fb8761a25eba765077..8ff10d317e6106a290320bc2c426b3aae27ae52d 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/ParallelFollow.lean @@ -1,883 +1,883 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.PriorPaths - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.PriorPaths + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/PriorPaths.lean index c5ec921fff698cb8568f7a9f765d68b4d78f186b..e683839901f5f6dcc138faa3aee7cc1015061675 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/PriorPaths.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.AssignmentSlots - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.AssignmentSlots + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/RotationMeeting.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/RotationMeeting.lean index abbae9a3da050019c607c0c3aa3d5fd2f1435fcd..d2b484610273d17dda5d260f05fbbb4862669ad8 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/RotationMeeting.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/RotationMeeting.lean @@ -1,881 +1,881 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.ExposedCoins - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) - (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.ExposedCoins + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) + (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/SandwichShuffle.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/SandwichShuffle.lean index f8a86b4ce2efdcb9e4f36e39e6c8883dc9fa09ca..e7f52ea033face800c2748cd4f140c8ca440a826 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/SandwichShuffle.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/SandwichShuffle.lean @@ -1,879 +1,879 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.AlternatingPerm - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp -open scoped BigOperators -open Filter -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) - (a : ℝ) (ha : 0 ≤ a) : - (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)))^(1+a) ≤ - (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * - ∑ c ∈ compatibleSet x y, - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by - classical - rw [sandwich_mean,sum_colors_factor] - let f (c : ι → Bool) : ℝ := - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) - have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) - (tupleProbability_nonneg _ _ _) - rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] - have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) - (show 1 ≤ 1+a by linarith) (fun c _ => hf c) - have he : 1+a-1=a := by ring - rw [he] at hh - calc - _ ≤ (outerWeight x y)^(1+a) * - (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := - mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) - _ = _ := by - rw [←mul_assoc] - congr 1 - apply Finset.sum_congr rfl - intro c _ - exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) - -end PairRouting - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - childLift p * childLift q = childLift (fun b => p b * q b) := by - ext x i - simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] - -lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl - -lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl - -lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * - pairSwitch coins.1 := by - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * - (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : - headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl - -lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : - headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl - -lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : - headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) - (headTailEquiv d x) := by - rw [palindromePerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by - obtain ⟨x,hx⟩ := C.nonempty - have hpx : alternatingPerm p x ∈ C.val := by - rw [←C.orbit_eq hx,mem_orbitSet] - exact (Equiv.Perm.SameCycle.refl _ _).apply_right - have hne : x ≠ alternatingPerm p x := by - intro he - have hh := congrArg Prod.fst he - rw [alternatingPerm_flip] at hh - cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh - have hs : {x,alternatingPerm p x} ⊆ C.val := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl <;> assumption - have hh := Finset.card_le_card hs - simpa only [Finset.card_pair hne] using hh - -lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : - 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by - classical - calc - _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] - _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := - Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) - _ ≤ _ := RoutingNetwork.cycleMass_le _ _ - -lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) - (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by - have h := alternating_cycle_count_double p S - omega - -end CycleColoring - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - 2 * alternatingCycles e p ≤ Fintype.card ι := by - have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) - simpa only [alternatingCycles, card_labelSet] using hh - -lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by - have hh := alternatingCycles_double e p - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : - colors x (chosenCoin x c) = c := by - funext i - simp only [colors,chosenCoin_apply x c hc i,required] - cases (x i).1 <;> cases c i <;> rfl - -noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : - ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) - -omit [Fintype α] [DecidableEq ι] in -lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - coloredEmbedding x c hc i = (c i,(x i).2) := by - apply Prod.ext - · exact congrFun (colors_chosenCoin x c hc) i - · rfl - -omit [Fintype α] [DecidableEq ι] in -lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) - (ξ : α → Bool) (he : colors x ξ = c) : - switchedEmbedding x ξ = coloredEmbedding x c hc := by - ext i : 1 - rw [coloredEmbedding_apply] - apply Prod.ext - · exact congrFun he i - · rfl - -lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - (compatibleSet x y).card ≤ - 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + - alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by - obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc - let ξ := chosenCoin x c - let η := chosenCoin y c - have he : routedEmbedding x ξ η p = y := by - ext i : 1 - have h := (sandwich_matches_iff ξ η p x y).mpr - ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by - simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ - exact h i - have hh := assignments_actual_bound x ξ η p - rw [he] at hh - rw [card_compatibleSet] - exact hh - -omit [Fintype α] [DecidableEq ι] in -lemma occupied_sum_ge (x y : ι ↪ Bool × α) : - Fintype.card ι ≤ (occupied x).card + (occupied y).card := by - have h₀ := occupied_card_double x - have h₁ := occupied_card_double y - omega - -lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ - (2:ℝ)^((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by - let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p - let b := (occupied x).card+(occupied y).card - let h := Fintype.card ι - have hb : h ≤ b := occupied_sum_ge x y - have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by - exact_mod_cast assignments_match_bound x y c hc p hm - change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) - rw [mul_one_div] - calc - _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) - _ = _ := by - rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] - congr 1 - rw [Nat.cast_add,Nat.cast_sub hb] - ring - -lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) - (a : ℝ) (ha : 0 ≤ a) : - (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ - (2:ℝ)^(((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by - have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) - (assignment_weight_bound x y c hc p hm) ha - rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), - ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h - simpa only [mul_comm] using h - - -lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, - if ChildMatches p x y c.val then W c.val else 0 := by - rw [sandwich_weighted_probability] - congr 1 - rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] - -omit [Fintype α] [DecidableEq α] [DecidableEq ι] in -lemma color_card_add (c : ι → Bool) : - Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by - have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by - cases c i <;> simp - rw [Fintype.card_congr he] - rw [Fintype.card_subtype_compl] - exact Nat.add_sub_of_le (Fintype.card_subtype_le _) - -end PairRouting - -noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) - (ω : BenesCoins d × BenesCoins d) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => palindromePerm d (if b then ω.2 else ω.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 - -lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : - palindromeCost (d+1) e σ = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) - (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by - unfold palindromeCost assignmentCost - dsimp only - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - -lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [palindromeCost_eq] - simp only [Equiv.apply_symm_apply] - -noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : BenesCoins d => - if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) - -lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma palindrome_matches_step (d : ℕ) {ι : Type*} - (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] - rfl - -lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (d+1)) (a : ℝ) : - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - routingMoment (d+1) e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have he (ω : BenesCoins d × BenesCoins d) : - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [palindrome_matches_step,palindromeCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold routingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = - (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (d+1)) : - PairRouting.tupleProbability (palindromePerm (d+1)) e f = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have hp (b : Bool) (p q : BenesCoins d) : - palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by - cases b <;> rfl - simp only [palindrome_matches_step,hp] - -lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) - rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh - have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = - -(d:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - rwa [he] at hh - -lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - -theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by - classical - induction d generalizing ι with - | zero => - have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := - fun _ _ => Subsingleton.elim _ _ - simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] - | succ d ih => - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) - have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha - rw [←palindrome_probability_step d e f] at hnode - change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) - ring - -lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : - (∑ f : ι ↪ Card d, routingMoment d e f a) = - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - unfold routingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] - (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : - finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = - (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] - rw [Real.rpow_add hn,Real.rpow_one] - field_simp - -noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card d => - ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) - -lemma density_normalization (d h n : ℕ) (a : ℝ) : - (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by - rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] - rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, - Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] - -theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - palindromeRowMoment d e a ≤ - (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card d) := ⟨e⟩ - rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * - ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, - Fintype.card_embedding_eq,card_positions] - norm_cast - -end Thorp -namespace Thorp - -lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] - (A : Finset α) (T : β → Finset α) : - (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = - ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by - classical - by_cases h : Finset.univ.biUnion T ⊆ A - · rw [ite_eq_left h] - symm - apply Finset.prod_eq_one - intro b _ - rw [ite_eq_left] - exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h - · rw [ite_eq_right h] - obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h - obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - rw [ite_eq_right] - exact fun hb => hxA (hb hxb) - -lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] - [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] - (F : Ω → Finset α) (p : α → ℝ) - (hF : CylinderBound (inclusionMoment F) p) - (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) - (hc : ∀ b s, 0 ≤ c b s) - (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : - finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ - ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by - classical - simp_rw [Fintype.prod_sum] - rw [finiteMean_sum] - apply Finset.sum_le_sum - intro s _ - let U := Finset.univ.biUnion (fun b => T b (s b)) - have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = - fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by - funext ω - rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] - exact mul_comm _ _ - rw [he,finiteMean_mul_const] - have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by - intro b _ b' _ hbb - exact hd b b' hbb (s b) (s b') - have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - by_cases hh : U ⊆ F ω <;> simp [hh] - calc - _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := - mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) - _ = _ := by - dsimp only [U] - rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro b _ - exact mul_comm _ _ - - -noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := - if T.card = 1 then 0 else w^T.card - -lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : - 0 ≤ sparseCoefficient w T := by - unfold sparseCoefficient - split_ifs <;> positivity - -lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) - (w : ℝ) (hw : 0 ≤ w) : - w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ - ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by - classical - let V := D ∩ A - let T : ↑D.powerset := if 2 ≤ V.card then - ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else - ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ - calc - _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by - by_cases h : 2 ≤ V.card - · have hn : V.card ≠ 1 := by omega - simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] - · simp [T,ite_eq_right h,sparseCoefficient,V] at * - _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => - sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) - (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) - (by split_ifs <;> norm_num)) (Finset.mem_univ T) - -lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : - ∑ i ∈ Finset.range n, x^i ≤ 2 := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ',pow_zero] - simp only [pow_succ',←Finset.mul_sum] - nlinarith - -lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : - ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ - 1 + 2*((R:ℝ)*z)^2 := by - classical - let x := (R:ℝ)*z - have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz - have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ - if i=1 then 0 else x^i := by - by_cases h : i=1 - · simp [h] - · simp only [ite_eq_right h] - dsimp [x] - rw [mul_pow] - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) - exact_mod_cast Nat.choose_le_pow R i - calc - _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := - Finset.sum_le_sum (fun i _ => hbound i) - _ ≤ 1+2*x^2 := by - rcases R with _ | R - · simp [x] - rcases R with _ | R - · norm_num [Finset.sum_range_succ] - positivity - have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = - 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by - rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] - have hn (i : ℕ) : 2+i ≠ 1 := by omega - simp only [hn,ite_false,pow_add,←Finset.mul_sum] - norm_num [Finset.sum_range_succ] - rw [he] - have hg := geometric_sum_half (R+1) hx hr - nlinarith [sq_nonneg x] - -lemma sparse_block_product_bound {α : Type*} [DecidableEq α] - (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : - ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ - Real.exp (2*((D.card:ℝ)*(p*w))^2) := by - classical - have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = - ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by - rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] - have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = - fun T => if T.card=1 then 0 else (p*w)^T.card := by - funext T - unfold sparseCoefficient - split_ifs <;> simp [mul_pow,mul_comm] - change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ - rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] - simp only [nsmul_eq_mul] - rw [he] - exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans - (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) - - -noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] - (D : β → Finset α) (A : Finset α) : ℕ := - ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 - -theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] - (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hF : ∀ T, inclusionMoment F T ≤ p^T.card) - (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : - finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by - classical - have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by - intro T - simpa only [Finset.prod_const] using hF T - have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc - (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) - (fun _ S => sparseCoefficient_nonneg w hw S.val) - (fun b b' h S S' => (hd h).mono - (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) - calc - _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, - sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by - apply finiteMean_mono - intro ω - rw [sparseMass,←Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) - intro b _ - exact sparse_block_pointwise (F ω) (D b) w hw - _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by - simpa only [Finset.prod_const] using hb - _ ≤ _ := by - rw [Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact Finset.sum_nonneg (fun S _ => mul_nonneg - (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) - · intro b _ - exact sparse_block_product_bound (D b) p w hp hw (hr b) - -theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] - (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) - (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : - finiteMean (fun ω : SwitchIndex d → Bool => - w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by - apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w - (by positivity) hw - · exact inverseButterflyMarks_inclusion d A - · exact hr - - -def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 - -lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by - unfold crowdedMass - split_ifs <;> omega - -lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by - unfold crowdedMass - split_ifs <;> omega - -lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by - unfold crowdedMass - split_ifs with h - · have hh := PairRouting.alternatingCycles_double e p - omega - · rw [PairRouting.alternatingCycles_zero e p (by omega)] - -lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by - classical - induction d generalizing ι with - | zero => simp [palindromeCost] - | succ d ih => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 - have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 - have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) - have hs := crowdedMass_add (Fintype.card {i // c i = false}) - (Fintype.card {i // c i = true}) - rw [PairRouting.color_card_add] at hs - change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ - nlinarith - -noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -end Thorp - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.AlternatingPerm + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp +open scoped BigOperators +open Filter +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) + (a : ℝ) (ha : 0 ≤ a) : + (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)))^(1+a) ≤ + (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * + ∑ c ∈ compatibleSet x y, + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by + classical + rw [sandwich_mean,sum_colors_factor] + let f (c : ι → Bool) : ℝ := + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) + have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) + (tupleProbability_nonneg _ _ _) + rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] + have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) + (show 1 ≤ 1+a by linarith) (fun c _ => hf c) + have he : 1+a-1=a := by ring + rw [he] at hh + calc + _ ≤ (outerWeight x y)^(1+a) * + (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := + mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) + _ = _ := by + rw [←mul_assoc] + congr 1 + apply Finset.sum_congr rfl + intro c _ + exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) + +end PairRouting + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + childLift p * childLift q = childLift (fun b => p b * q b) := by + ext x i + simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] + +lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl + +lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl + +lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * + pairSwitch coins.1 := by + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * + (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : + headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl + +lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : + headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl + +lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : + headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) + (headTailEquiv d x) := by + rw [palindromePerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by + obtain ⟨x,hx⟩ := C.nonempty + have hpx : alternatingPerm p x ∈ C.val := by + rw [←C.orbit_eq hx,mem_orbitSet] + exact (Equiv.Perm.SameCycle.refl _ _).apply_right + have hne : x ≠ alternatingPerm p x := by + intro he + have hh := congrArg Prod.fst he + rw [alternatingPerm_flip] at hh + cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh + have hs : {x,alternatingPerm p x} ⊆ C.val := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl <;> assumption + have hh := Finset.card_le_card hs + simpa only [Finset.card_pair hne] using hh + +lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : + 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by + classical + calc + _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] + _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := + Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) + _ ≤ _ := RoutingNetwork.cycleMass_le _ _ + +lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) + (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by + have h := alternating_cycle_count_double p S + omega + +end CycleColoring + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + 2 * alternatingCycles e p ≤ Fintype.card ι := by + have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) + simpa only [alternatingCycles, card_labelSet] using hh + +lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by + have hh := alternatingCycles_double e p + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : + colors x (chosenCoin x c) = c := by + funext i + simp only [colors,chosenCoin_apply x c hc i,required] + cases (x i).1 <;> cases c i <;> rfl + +noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : + ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) + +omit [Fintype α] [DecidableEq ι] in +lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + coloredEmbedding x c hc i = (c i,(x i).2) := by + apply Prod.ext + · exact congrFun (colors_chosenCoin x c hc) i + · rfl + +omit [Fintype α] [DecidableEq ι] in +lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) + (ξ : α → Bool) (he : colors x ξ = c) : + switchedEmbedding x ξ = coloredEmbedding x c hc := by + ext i : 1 + rw [coloredEmbedding_apply] + apply Prod.ext + · exact congrFun he i + · rfl + +lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + (compatibleSet x y).card ≤ + 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + + alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by + obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc + let ξ := chosenCoin x c + let η := chosenCoin y c + have he : routedEmbedding x ξ η p = y := by + ext i : 1 + have h := (sandwich_matches_iff ξ η p x y).mpr + ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by + simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ + exact h i + have hh := assignments_actual_bound x ξ η p + rw [he] at hh + rw [card_compatibleSet] + exact hh + +omit [Fintype α] [DecidableEq ι] in +lemma occupied_sum_ge (x y : ι ↪ Bool × α) : + Fintype.card ι ≤ (occupied x).card + (occupied y).card := by + have h₀ := occupied_card_double x + have h₁ := occupied_card_double y + omega + +lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ + (2:ℝ)^((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by + let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p + let b := (occupied x).card+(occupied y).card + let h := Fintype.card ι + have hb : h ≤ b := occupied_sum_ge x y + have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by + exact_mod_cast assignments_match_bound x y c hc p hm + change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) + rw [mul_one_div] + calc + _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by + rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] + congr 1 + rw [Nat.cast_add,Nat.cast_sub hb] + ring + +lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) + (a : ℝ) (ha : 0 ≤ a) : + (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ + (2:ℝ)^(((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by + have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) + (assignment_weight_bound x y c hc p hm) ha + rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), + ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h + simpa only [mul_comm] using h + + +lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, + if ChildMatches p x y c.val then W c.val else 0 := by + rw [sandwich_weighted_probability] + congr 1 + rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] + +omit [Fintype α] [DecidableEq α] [DecidableEq ι] in +lemma color_card_add (c : ι → Bool) : + Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by + have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by + cases c i <;> simp + rw [Fintype.card_congr he] + rw [Fintype.card_subtype_compl] + exact Nat.add_sub_of_le (Fintype.card_subtype_le _) + +end PairRouting + +noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) + (ω : BenesCoins d × BenesCoins d) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => palindromePerm d (if b then ω.2 else ω.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 + +lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : + palindromeCost (d+1) e σ = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) + (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by + unfold palindromeCost assignmentCost + dsimp only + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + +lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [palindromeCost_eq] + simp only [Equiv.apply_symm_apply] + +noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : BenesCoins d => + if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) + +lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma palindrome_matches_step (d : ℕ) {ι : Type*} + (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] + rfl + +lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (d+1)) (a : ℝ) : + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + routingMoment (d+1) e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have he (ω : BenesCoins d × BenesCoins d) : + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [palindrome_matches_step,palindromeCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold routingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = + (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (d+1)) : + PairRouting.tupleProbability (palindromePerm (d+1)) e f = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have hp (b : Bool) (p q : BenesCoins d) : + palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by + cases b <;> rfl + simp only [palindrome_matches_step,hp] + +lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) + rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh + have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = + -(d:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + rwa [he] at hh + +lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + +theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by + classical + induction d generalizing ι with + | zero => + have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := + fun _ _ => Subsingleton.elim _ _ + simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] + | succ d ih => + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) + have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha + rw [←palindrome_probability_step d e f] at hnode + change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) + ring + +lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : + (∑ f : ι ↪ Card d, routingMoment d e f a) = + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + unfold routingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] + (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : + finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = + (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] + rw [Real.rpow_add hn,Real.rpow_one] + field_simp + +noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card d => + ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) + +lemma density_normalization (d h n : ℕ) (a : ℝ) : + (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by + rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] + rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, + Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] + +theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + palindromeRowMoment d e a ≤ + (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card d) := ⟨e⟩ + rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * + ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, + Fintype.card_embedding_eq,card_positions] + norm_cast + +end Thorp +namespace Thorp + +lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] + (A : Finset α) (T : β → Finset α) : + (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = + ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by + classical + by_cases h : Finset.univ.biUnion T ⊆ A + · rw [ite_eq_left h] + symm + apply Finset.prod_eq_one + intro b _ + rw [ite_eq_left] + exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h + · rw [ite_eq_right h] + obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h + obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + rw [ite_eq_right] + exact fun hb => hxA (hb hxb) + +lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] + [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] + (F : Ω → Finset α) (p : α → ℝ) + (hF : CylinderBound (inclusionMoment F) p) + (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) + (hc : ∀ b s, 0 ≤ c b s) + (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : + finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ + ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by + classical + simp_rw [Fintype.prod_sum] + rw [finiteMean_sum] + apply Finset.sum_le_sum + intro s _ + let U := Finset.univ.biUnion (fun b => T b (s b)) + have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = + fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by + funext ω + rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] + exact mul_comm _ _ + rw [he,finiteMean_mul_const] + have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by + intro b _ b' _ hbb + exact hd b b' hbb (s b) (s b') + have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + by_cases hh : U ⊆ F ω <;> simp [hh] + calc + _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := + mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) + _ = _ := by + dsimp only [U] + rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro b _ + exact mul_comm _ _ + + +noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := + if T.card = 1 then 0 else w^T.card + +lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : + 0 ≤ sparseCoefficient w T := by + unfold sparseCoefficient + split_ifs <;> positivity + +lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) + (w : ℝ) (hw : 0 ≤ w) : + w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ + ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by + classical + let V := D ∩ A + let T : ↑D.powerset := if 2 ≤ V.card then + ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else + ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ + calc + _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by + by_cases h : 2 ≤ V.card + · have hn : V.card ≠ 1 := by omega + simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] + · simp [T,ite_eq_right h,sparseCoefficient,V] at * + _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => + sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) + (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) + (by split_ifs <;> norm_num)) (Finset.mem_univ T) + +lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : + ∑ i ∈ Finset.range n, x^i ≤ 2 := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ',pow_zero] + simp only [pow_succ',←Finset.mul_sum] + nlinarith + +lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : + ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ + 1 + 2*((R:ℝ)*z)^2 := by + classical + let x := (R:ℝ)*z + have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz + have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ + if i=1 then 0 else x^i := by + by_cases h : i=1 + · simp [h] + · simp only [ite_eq_right h] + dsimp [x] + rw [mul_pow] + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) + exact_mod_cast Nat.choose_le_pow R i + calc + _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := + Finset.sum_le_sum (fun i _ => hbound i) + _ ≤ 1+2*x^2 := by + rcases R with _ | R + · simp [x] + rcases R with _ | R + · norm_num [Finset.sum_range_succ] + positivity + have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = + 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by + rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] + have hn (i : ℕ) : 2+i ≠ 1 := by omega + simp only [hn,ite_false,pow_add,←Finset.mul_sum] + norm_num [Finset.sum_range_succ] + rw [he] + have hg := geometric_sum_half (R+1) hx hr + nlinarith [sq_nonneg x] + +lemma sparse_block_product_bound {α : Type*} [DecidableEq α] + (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : + ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ + Real.exp (2*((D.card:ℝ)*(p*w))^2) := by + classical + have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = + ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by + rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] + have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = + fun T => if T.card=1 then 0 else (p*w)^T.card := by + funext T + unfold sparseCoefficient + split_ifs <;> simp [mul_pow,mul_comm] + change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ + rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] + simp only [nsmul_eq_mul] + rw [he] + exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans + (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) + + +noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] + (D : β → Finset α) (A : Finset α) : ℕ := + ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 + +theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] + (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hF : ∀ T, inclusionMoment F T ≤ p^T.card) + (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : + finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by + classical + have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by + intro T + simpa only [Finset.prod_const] using hF T + have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc + (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) + (fun _ S => sparseCoefficient_nonneg w hw S.val) + (fun b b' h S S' => (hd h).mono + (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) + calc + _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, + sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by + apply finiteMean_mono + intro ω + rw [sparseMass,←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) + intro b _ + exact sparse_block_pointwise (F ω) (D b) w hw + _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by + simpa only [Finset.prod_const] using hb + _ ≤ _ := by + rw [Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact Finset.sum_nonneg (fun S _ => mul_nonneg + (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) + · intro b _ + exact sparse_block_product_bound (D b) p w hp hw (hr b) + +theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] + (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) + (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : + finiteMean (fun ω : SwitchIndex d → Bool => + w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by + apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w + (by positivity) hw + · exact inverseButterflyMarks_inclusion d A + · exact hr + + +def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 + +lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by + unfold crowdedMass + split_ifs <;> omega + +lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by + unfold crowdedMass + split_ifs <;> omega + +lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by + unfold crowdedMass + split_ifs with h + · have hh := PairRouting.alternatingCycles_double e p + omega + · rw [PairRouting.alternatingCycles_zero e p (by omega)] + +lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by + classical + induction d generalizing ι with + | zero => simp [palindromeCost] + | succ d ih => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 + have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 + have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + have hs := crowdedMass_add (Fintype.card {i // c i = false}) + (Fintype.card {i // c i = true}) + rw [PairRouting.color_card_add] at hs + change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ + nlinarith + +noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +end Thorp + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/Shapes.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/Shapes.lean index e68d8dd984b908d5b968bdedcb78580be2f011e9..9c3f91689ae4343735d3cc2c2e15c735502171f1 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/Shapes.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/Shapes.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.ModifiedReverseCoins - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : - (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by - apply YoungDiagram.rowLens_ofRowLens_eq_self - intro x hx - exact p.parts_pos ((Multiset.mem_sort _).mp hx) - -lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by - rw [←sum_rowLens,partitionDiagram_rowLens] - change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N - rw [Multiset.sort_eq,p.parts_sum] - -lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : - partitionDiagram (diagramPartition μ) = μ := by - apply YoungDiagram.equivListRowLens.injective - apply Subtype.ext - change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens - rw [partitionDiagram_rowLens] - change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens - rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] - -abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} - -noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where - toFun μ := { parts := μ.1.rowLens - parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } - invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ - left_inv μ := by - apply Subtype.ext - obtain ⟨μ,rfl⟩ := μ - exact partitionDiagram_diagramPartition μ - right_inv p := by - apply Nat.Partition.ext - change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts - rw [partitionDiagram_rowLens,Multiset.sort_eq] - -noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm - -noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : - ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := - Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) - -lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : - Function.Injective (conjugacyPartition (α := α)) := by - intro p q - induction p using Quotient.inductionOn with | _ p => - induction q using Quotient.inductionOn with | _ q => - intro h - exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) - -lemma card_conjugacy_le_shapes (N : ℕ) : - Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by - have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) - simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h - -noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := - (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) - -noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : - Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := - (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom - -lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : - Representation.IsIrreducible (labelledRepresentation μ) := by - let e := (labels μ).symm.permCongrHom - let ρ := representation μ.1 - have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ - (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial - exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) - refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } - intro U - let U' : Subrepresentation ρ := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun p v hv => by - have hh := U.apply_mem_toSubmodule (e.symm p) hv - change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh - simpa using hh } - have := representation_irreducible μ.1 - obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' - · left - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - · right - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - -lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) - (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by - apply Subtype.ext - apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv - intro p v - have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v - change T.toLinearEquiv - (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = - representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh - have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] at hh - convert hh using 2 - congr 1 - -end Thorp.Specht - -namespace Thorp.FiniteCharacters -open scoped BigOperators Classical - -section Group -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose -omit [Fintype G] in -lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := - (ConjClasses.exists_rep c).choose_spec - -variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := - fun c => ρ.character (classRep c) - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : - characterClass ρ (ConjClasses.mk g) = ρ.character g := by - have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) - obtain ⟨p,hp⟩ := isConj_iff.mp h - change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g - exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) - -noncomputable def characterDual (ρ : Representation ℂ G V) : - (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where - toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ - map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] - map_smul' a f := by - simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] - simp_rw [mul_assoc] - rw [←Finset.mul_sum] - ring - -lemma characterDual_characterClass (ρ : Representation ℂ G V) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : - characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by - exact_mod_cast (Nat.card_pos (α := G)).ne') - change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ - simp only [characterClass_mk] - exact Representation.char_orthonormal σ ρ - -end Group - -theorem complete_of_card_conjugacy_le - {G ι : Type*} [Group G] [Fintype G] [Fintype ι] - (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] - (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] - (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : - ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases hij : i=j - · subst j - simp only [ite_true] - exact ite_eq_left ⟨Representation.Equiv.refl _⟩ - · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij - exact (horth i j).trans (ite_eq_right hij) - · intro i - simpa using horth i i - have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - have hspan := hLI.span_eq_top_of_card_eq_finrank' heq - by_contra h - push Not at h - have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ - (characterDual σ).ker := by - apply Submodule.span_le.mpr - rintro f ⟨i,rfl⟩ - change characterDual σ (characterClass (ρ i)) = 0 - rw [characterDual_characterClass,ite_eq_right] - rintro ⟨T⟩ - exact (h i).false T.symm - rw [hspan] at hker - have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) - rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz - exact one_ne_zero hz - -end Thorp.FiniteCharacters - -namespace Thorp.Specht -open scoped Classical - -theorem labelled_complete {N : ℕ} - {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : - ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by - let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := - labelledRepresentation_irreducible μ - apply FiniteCharacters.complete_of_card_conjugacy_le - (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ - intro μ ν h ⟨T⟩ - exact h (labelledRepresentation_equiv_shapes μ ν T) - -end Thorp.Specht - -namespace Thorp.PermutationHilbert - -section -open scoped BigOperators ComplexConjugate Classical -open Complex - -variable {X : Type*} [Fintype X] - -noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := - LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p - -@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : - act p v x = v (p⁻¹ x) := rfl - -lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : - act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by - exact EuclideanSpace.piLpCongrLeft_single p x 1 - -lemma trace_projection (W : Submodule ℂ (H X)) : - ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by - classical - have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by - constructor - · intro x; exact (W.orthogonalProjectionOnto x).2 - · intro x hx; exact W.starProjection_eq_self_iff.mpr hx - have ht := hp.trace - rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht - simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, - EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, - OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht - -lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : - (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - classical - have hh := W.inner_starProjection_left_eq_right - (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) - have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := - W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 - rw [hf] at hh - rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh - simpa using hh.symm - -lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) - (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : - act p (W.starProjection v) = W.starProjection (act p v) := by - have hh := (act p).toLinearIsometry.map_starProjection W v - change act p (W.starProjection v) = - (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh - simpa only [hW] using hh - -lemma uniform_diagonal (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : - (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = - Module.finrank ℂ W := by - classical - have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - obtain ⟨p,hp,hW⟩ := htrans x y - subst y - rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] - have ht := trace_projection W - simp_rw [hh] at ht - have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = - (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht - simpa using hhreal - -theorem uncertainty (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (v : H X) (hv : v ∈ W) (x : X) : - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by - classical - have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by - rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, - EuclideanSpace.inner_single_left] - simp - have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v - rw [hh] at hc - have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by - nlinarith [norm_nonneg (v x),norm_nonneg v, - norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] - calc - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ - (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := - mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) - _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] - -end -open scoped BigOperators Classical - -variable {X : Type*} [Fintype X] - -lemma trace_projection_real (W : Submodule ℂ (H X)) : - ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by - have hh := trace_projection W - simp_rw [projection_diagonal] at hh - exact_mod_cast hh - -theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : - (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ - (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by - have he (x : X) (hx : x ∈ S) : - K.starProjection (EuclideanSpace.single x (1:ℂ)) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := by - apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) - intro v hv - exact W.starProjection_inner_eq_zero _ v (hKW hv) - have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ - (Module.finrank ℂ K:ℝ) := by - rw [←trace_projection_real K] - calc - _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by - apply Finset.sum_congr rfl - intro x hx - rw [he x hx] - _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) - have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) - rw [Finset.mul_sum] at hmul - simp_rw [uniform_diagonal W htrans] at hmul - simpa using hmul - -end Thorp.PermutationHilbert -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma finrank_hilbertSpace (μ : YoungDiagram) : - Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := - (hilbertEquiv μ).finrank_map_eq (space μ) - -lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : - hilbertEquiv μ (tabloidRep μ p v) = - PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by - ext f - simp [hilbertEquiv,PermutationHilbert.act_apply] - -lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = - hilbertSpace μ := by - apply le_antisymm - · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ - exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ - · rintro _ ⟨w,hw,rfl⟩ - refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), - ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ - change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w - rw [←hilbert_action] - change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ - rw [←map_mul,mul_inv_cancel,map_one] - rfl - -lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : - ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by - obtain ⟨q,hq⟩ := f.2 - obtain ⟨r,hr⟩ := g.2 - refine ⟨r⁻¹*q, ?_⟩ - apply Subtype.ext - funext x - simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, - Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] - -lemma polytabloid_pairing (μ : YoungDiagram) : - pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by - have h := alternator_pairing μ (polytabloid μ) - have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = - permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply (colGroup μ) (tabloidRep μ) c _ - have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, - Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb - simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb - exact hb.symm - -lemma polytabloid_norm_sq (μ : YoungDiagram) : - ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by - have hp := polytabloid_pairing μ - change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp - rw [inner_self_eq_norm_sq_to_K] at hp - have hre := congrArg Complex.re hp - simpa [pow_two] using hre - -theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : - Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht - (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) - have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ - rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu - exact_mod_cast hu - - -section FiberGroup -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -noncomputable def fiberGroupEquiv (f : α → β) : - fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where - toFun p b := - { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ - invFun x := ⟨p.1⁻¹ x.1, by - have hh := p.2 (p.1⁻¹ x.1) - simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh - exact hh.symm.trans x.2⟩ - left_inv x := by apply Subtype.ext; simp - right_inv x := by apply Subtype.ext; simp } - invFun q := - ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), - fun x => (q (f x) ⟨x,rfl⟩).2⟩ - left_inv p := by - apply Subtype.ext - apply Equiv.ext - intro x - rfl - right_inv q := by - funext b - apply Equiv.ext - intro x - apply Subtype.ext - change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 - cases x with - | mk x hx => dsimp only at *; subst b; rfl - -lemma nat_card_fiberGroup (f : α → β) : - Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by - rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] - simp only [Nat.card_eq_fintype_card,Fintype.card_perm] - -omit [Fintype β] [Fintype γ] in - -lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) - (hinj : ∀ x y, f x = f y → g x = g y → x=y) : - Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by - have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by - intro p q hpq - dsimp only at hpq - have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by - apply inv_mul_eq_iff_eq_mul.mpr - rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] - have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 - have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) - have h1 : p.1.1⁻¹*q.1.1 = 1 := by - apply Equiv.ext - intro x - exact hinj _ x (hf x) (hg x) - have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) - have hpg : p.2=q.2 := by - apply Subtype.ext - have hh := hpq - rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh - exact mul_left_cancel hh - exact Prod.ext hpf hpg - have hc := Fintype.card_le_of_injective _ hi - simpa only [Fintype.card_prod,Fintype.card_perm] using hc - -end FiberGroup - -noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := - fiberGroup (rowIndex (μ := μ)) - -noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := - ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ - -lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by - ext p - constructor - · intro hp x; exact Fin.ext (hp x) - · intro hp x; exact congrArg Fin.val (hp x) - -noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where - smul p f := tabloidAct p f - one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl - mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl - -lemma tabloid_orbit_all (μ : YoungDiagram) : - MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by - ext f - simp only [Set.mem_univ,iff_true] - obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f - exact ⟨p,hp⟩ - -lemma tabloid_stabilizer (μ : YoungDiagram) : - MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by - ext p - change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x - constructor - · intro h x - have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h - simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - · intro h - apply Subtype.ext - funext x - exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) - -lemma card_tabloid_mul_row (μ : YoungDiagram) : - Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by - have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group - (Equiv.Perm (Cell μ)) (baseTabloid μ) - have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = - Fintype.card (Tabloid μ) := by - rw [tabloid_orbit_all,Fintype.card_setUniv] - simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh - -theorem factorial_le_dimension_row_column (μ : YoungDiagram) : - μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by - rw [←card_tabloid_mul_row] - nlinarith [dimension_times_column_ge_tabloids μ] - - -lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by - let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] - -lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by - let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - -lemma card_rowGroup (μ : YoungDiagram) : - Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by - rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_row_fiber] - -lemma card_colGroup (μ : YoungDiagram) : - Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by - rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card,card_col_fiber] - -abbrev Tail (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} - -lemma tail_card (μ : YoungDiagram) : Fintype.card (Tail μ) = μ.card - μ.rowLen 0 := by - have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) - rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh - exact hh - -lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by - have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) - rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h - -noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - {x : Tail μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where - toFun x := ⟨row x.1.1-1, by - have hx := row_lt_colLen x.1.1 - have hc : col x.1.1 = j := congrArg Fin.val x.2 - rw [hc] at hx - have hz := x.1.2 - omega⟩ - invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ - left_inv x := by - apply Subtype.ext - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · change row x.1.1 - 1 + 1 = row x.1.1 - have := x.1.2 - omega - · exact (congrArg Fin.val x.2).symm - right_inv i := by apply Fin.ext; simp [row] - -lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : Tail μ // colIndex x.1 = j} = μ.colLen j-1 := by - rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] - -lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : Tail μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by - by_cases hi : i.val=0 - · rw [ite_eq_left hi] - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun x => x.1.2 ?_⟩ - exact (congrArg Fin.val x.2).trans hi - · rw [ite_eq_right hi] - let e : {x : Tail μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := - { toFun := fun x => ⟨x.1.1,x.2⟩ - invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ - left_inv := fun x => rfl - right_inv := fun x => rfl } - rw [Fintype.card_congr e,card_row_fiber] - -lemma tail_row_group (μ : YoungDiagram) : - (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) = - Fintype.card (rowGroup μ) := by - rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_row] - by_cases hn : μ.colLen 0=0 - · have hr : μ.rowLen 0=0 := by - by_contra h - have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) - have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem - omega - let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ - simp [hr] - · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ - have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] - simp only [hz] - have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = - ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by - rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] - simp only [ite_true,Nat.factorial_zero,mul_one] - apply Finset.prod_congr rfl - intro x hx - rw [ite_eq_right (Finset.mem_erase.mp hx).1] - rw [hprod] - exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) - -lemma sum_tail_columns (μ : YoungDiagram) : - ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by - simp_rw [←card_tail_col] - rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : Tail μ => colIndex x.1)),tail_card] - -lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := - YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) - -lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num - | succ n ih => rw [pow_succ]; omega - -lemma column_group_le_tail (μ : YoungDiagram) : - Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * - Fintype.card (fiberGroup (fun x : Tail μ => colIndex x.1)) := by - rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => colIndex x.1)),nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_col] - calc - _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by - apply Finset.prod_congr rfl - intro j hj - exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm - _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by - apply Finset.prod_le_prod - intro j hj - exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) - _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] - -theorem choose_tail_le_dimension (μ : YoungDiagram) : - μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - have htail := card_fiberGroups_mul_le - (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) - (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) - rw [tail_card] at htail - have hc := column_group_le_tail μ - have hr := tail_row_group μ - have hd := factorial_le_dimension_row_column μ - simp only [←Nat.card_eq_fintype_card] at htail hc hr hd - have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * - ((μ.rowLen 0).factorial * j.factorial) := by - calc - _ ≤ _ := hd - _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * - (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc - _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * - (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * - Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring - _ ≤ _ := by - calc - _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := - Nat.mul_le_mul_left _ htail - _ = _ := by ring - have hj : j ≤ μ.card := Nat.sub_le _ _ - have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega - have hf := Nat.choose_mul_factorial_mul_factorial hj - rw [hs] at hf - rw [←hf] at hh - have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) - nlinarith - - -lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : - ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by - let e : s ≃ t := Finset.equivOfCardEq hc - let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by - simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) - let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) - refine ⟨p,fun x => ?_⟩ - by_cases hx : x ∈ s - · have hp : p x ∈ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t - rw [Equiv.sumCompl_symm_apply_of_pos hx] - exact (e ⟨x,hx⟩).2 - exact iff_of_true hp hx - · have hp : p x ∉ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t - rw [Equiv.sumCompl_symm_apply_of_neg hx] - exact (ec ⟨x,hx⟩).2 - exact iff_of_false hp hx - -noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := - Finset.univ.filter (fun x => (f.1 x).val ≠ 0) - -@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : - x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] - -lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tailSet (tabloidAct p f) = (tailSet f).image p := by - ext x - simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] - constructor - · intro h; exact ⟨p⁻¹ x,h,by simp⟩ - · rintro ⟨y,hy,rfl⟩; simpa using hy - -lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : - (tailSet f).card = μ.card-μ.rowLen 0 := by - obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f - rw [tailSet_act,Finset.card_image_of_injective _ p.injective] - change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ - rw [←Fintype.card_subtype] - exact tail_card μ - -noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := - Finset.univ.filter (fun f => tailSet f ⊆ A) - -lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by - obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst - have he : s.image p=t := by - ext x - constructor - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (hp y).mpr hy - · intro hx - exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ - apply Finset.card_equiv (tabloidAct p) - intro f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] - exact (Finset.image_inj p.injective).symm - -lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : - (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = - Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - let s := tailSet (baseTabloid μ) - let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card - have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := - tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) - have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by - have h := Finset.sum_card_fiberwise_eq_card_filter - (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet - have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by - ext f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, - card_tailSet,footprint] - simp [j] - rw [he] at h - rw [←h] - calc - _ = ∑ _t ∈ A.powersetCard j, c := by - apply Finset.sum_congr rfl - intro t ht - exact hconstant t (Finset.mem_powersetCard.mp ht).2 - _ = _ := by simp [Finset.card_powersetCard] - have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by - simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] - have hN := hcount Finset.univ - rw [hfull,Finset.card_univ,card_cell] at hN - rw [hcount,hN] - ring - -lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) - (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by - have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 - apply Subtype.ext - funext x - change f.1 (p⁻¹ x) = f.1 x - by_cases hx : x ∈ A - · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] - · have hy : p⁻¹ x ∉ A := by - intro h - have hh := hp (p⁻¹ x) h - have he : x=p⁻¹ x := by simpa using hh - exact hx (he ▸ h) - apply Fin.ext - have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) - have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) - exact hy0.trans hx0.symm - -noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where - carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), - (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} - zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ - add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by - rw [map_add,hv.2 p hp,hw.2 p hp]⟩ - smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by - rw [map_smul,hv.2 p hp]⟩ - -lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := - fun _ hv => hv.1 - -theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : - Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by - let : DecidableEq (Tabloid μ) := Classical.decEq _ - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : - (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by - refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ - rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), - PermutationHilbert.act_single,footprint_fixed A f hf p hp] - have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) - (fixedHilbert_le μ A) ht (footprint μ A) hproj - rw [finrank_hilbertSpace] at h - have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ - Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h - have hc := footprint_card_product μ A - have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ - have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn - nlinarith - -end Thorp.Specht - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -def IsUnitary (ρ : Representation ℂ G V) : Prop := - ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : - inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by - have h := hρ g v (ρ g⁻¹ w) - have he : ρ g (ρ g⁻¹ w) = w := by - change (ρ g * ρ g⁻¹) w = w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [he] at h - exact h.symm - -end Thorp.UnitaryFinite - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.ModifiedReverseCoins + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : + (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by + apply YoungDiagram.rowLens_ofRowLens_eq_self + intro x hx + exact p.parts_pos ((Multiset.mem_sort _).mp hx) + +lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by + rw [←sum_rowLens,partitionDiagram_rowLens] + change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N + rw [Multiset.sort_eq,p.parts_sum] + +lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : + partitionDiagram (diagramPartition μ) = μ := by + apply YoungDiagram.equivListRowLens.injective + apply Subtype.ext + change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens + rw [partitionDiagram_rowLens] + change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens + rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] + +abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} + +noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where + toFun μ := { parts := μ.1.rowLens + parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } + invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ + left_inv μ := by + apply Subtype.ext + obtain ⟨μ,rfl⟩ := μ + exact partitionDiagram_diagramPartition μ + right_inv p := by + apply Nat.Partition.ext + change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts + rw [partitionDiagram_rowLens,Multiset.sort_eq] + +noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm + +noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : + ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := + Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) + +lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : + Function.Injective (conjugacyPartition (α := α)) := by + intro p q + induction p using Quotient.inductionOn with | _ p => + induction q using Quotient.inductionOn with | _ q => + intro h + exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) + +lemma card_conjugacy_le_shapes (N : ℕ) : + Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by + have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) + simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h + +noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := + (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) + +noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : + Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := + (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom + +lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : + Representation.IsIrreducible (labelledRepresentation μ) := by + let e := (labels μ).symm.permCongrHom + let ρ := representation μ.1 + have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ + (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial + exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) + refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } + intro U + let U' : Subrepresentation ρ := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun p v hv => by + have hh := U.apply_mem_toSubmodule (e.symm p) hv + change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh + simpa using hh } + have := representation_irreducible μ.1 + obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' + · left + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + · right + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + +lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) + (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by + apply Subtype.ext + apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv + intro p v + have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v + change T.toLinearEquiv + (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = + representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh + have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] at hh + convert hh using 2 + congr 1 + +end Thorp.Specht + +namespace Thorp.FiniteCharacters +open scoped BigOperators Classical + +section Group +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose +omit [Fintype G] in +lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := + (ConjClasses.exists_rep c).choose_spec + +variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := + fun c => ρ.character (classRep c) + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : + characterClass ρ (ConjClasses.mk g) = ρ.character g := by + have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) + obtain ⟨p,hp⟩ := isConj_iff.mp h + change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g + exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) + +noncomputable def characterDual (ρ : Representation ℂ G V) : + (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where + toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ + map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] + map_smul' a f := by + simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] + simp_rw [mul_assoc] + rw [←Finset.mul_sum] + ring + +lemma characterDual_characterClass (ρ : Representation ℂ G V) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : + characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by + exact_mod_cast (Nat.card_pos (α := G)).ne') + change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ + simp only [characterClass_mk] + exact Representation.char_orthonormal σ ρ + +end Group + +theorem complete_of_card_conjugacy_le + {G ι : Type*} [Group G] [Fintype G] [Fintype ι] + (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] + (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] + (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : + ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases hij : i=j + · subst j + simp only [ite_true] + exact ite_eq_left ⟨Representation.Equiv.refl _⟩ + · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij + exact (horth i j).trans (ite_eq_right hij) + · intro i + simpa using horth i i + have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + have hspan := hLI.span_eq_top_of_card_eq_finrank' heq + by_contra h + push Not at h + have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ + (characterDual σ).ker := by + apply Submodule.span_le.mpr + rintro f ⟨i,rfl⟩ + change characterDual σ (characterClass (ρ i)) = 0 + rw [characterDual_characterClass,ite_eq_right] + rintro ⟨T⟩ + exact (h i).false T.symm + rw [hspan] at hker + have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) + rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz + exact one_ne_zero hz + +end Thorp.FiniteCharacters + +namespace Thorp.Specht +open scoped Classical + +theorem labelled_complete {N : ℕ} + {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : + ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by + let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := + labelledRepresentation_irreducible μ + apply FiniteCharacters.complete_of_card_conjugacy_le + (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ + intro μ ν h ⟨T⟩ + exact h (labelledRepresentation_equiv_shapes μ ν T) + +end Thorp.Specht + +namespace Thorp.PermutationHilbert + +section +open scoped BigOperators ComplexConjugate Classical +open Complex + +variable {X : Type*} [Fintype X] + +noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p + +@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : + act p v x = v (p⁻¹ x) := rfl + +lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : + act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by + exact EuclideanSpace.piLpCongrLeft_single p x 1 + +lemma trace_projection (W : Submodule ℂ (H X)) : + ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by + classical + have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by + constructor + · intro x; exact (W.orthogonalProjectionOnto x).2 + · intro x hx; exact W.starProjection_eq_self_iff.mpr hx + have ht := hp.trace + rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht + simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, + EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, + OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht + +lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : + (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + classical + have hh := W.inner_starProjection_left_eq_right + (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) + have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := + W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 + rw [hf] at hh + rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh + simpa using hh.symm + +lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) + (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : + act p (W.starProjection v) = W.starProjection (act p v) := by + have hh := (act p).toLinearIsometry.map_starProjection W v + change act p (W.starProjection v) = + (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh + simpa only [hW] using hh + +lemma uniform_diagonal (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : + (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = + Module.finrank ℂ W := by + classical + have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + obtain ⟨p,hp,hW⟩ := htrans x y + subst y + rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] + have ht := trace_projection W + simp_rw [hh] at ht + have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = + (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht + simpa using hhreal + +theorem uncertainty (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (v : H X) (hv : v ∈ W) (x : X) : + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by + classical + have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by + rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, + EuclideanSpace.inner_single_left] + simp + have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v + rw [hh] at hc + have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by + nlinarith [norm_nonneg (v x),norm_nonneg v, + norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] + calc + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ + (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := + mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) + _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] + +end +open scoped BigOperators Classical + +variable {X : Type*} [Fintype X] + +lemma trace_projection_real (W : Submodule ℂ (H X)) : + ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by + have hh := trace_projection W + simp_rw [projection_diagonal] at hh + exact_mod_cast hh + +theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : + (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ + (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by + have he (x : X) (hx : x ∈ S) : + K.starProjection (EuclideanSpace.single x (1:ℂ)) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := by + apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) + intro v hv + exact W.starProjection_inner_eq_zero _ v (hKW hv) + have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ + (Module.finrank ℂ K:ℝ) := by + rw [←trace_projection_real K] + calc + _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by + apply Finset.sum_congr rfl + intro x hx + rw [he x hx] + _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) + have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) + rw [Finset.mul_sum] at hmul + simp_rw [uniform_diagonal W htrans] at hmul + simpa using hmul + +end Thorp.PermutationHilbert +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma finrank_hilbertSpace (μ : YoungDiagram) : + Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := + (hilbertEquiv μ).finrank_map_eq (space μ) + +lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : + hilbertEquiv μ (tabloidRep μ p v) = + PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by + ext f + simp [hilbertEquiv,PermutationHilbert.act_apply] + +lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = + hilbertSpace μ := by + apply le_antisymm + · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ + exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ + · rintro _ ⟨w,hw,rfl⟩ + refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), + ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ + change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w + rw [←hilbert_action] + change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ + rw [←map_mul,mul_inv_cancel,map_one] + rfl + +lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : + ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by + obtain ⟨q,hq⟩ := f.2 + obtain ⟨r,hr⟩ := g.2 + refine ⟨r⁻¹*q, ?_⟩ + apply Subtype.ext + funext x + simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, + Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] + +lemma polytabloid_pairing (μ : YoungDiagram) : + pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by + have h := alternator_pairing μ (polytabloid μ) + have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = + permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply (colGroup μ) (tabloidRep μ) c _ + have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, + Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb + simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb + exact hb.symm + +lemma polytabloid_norm_sq (μ : YoungDiagram) : + ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by + have hp := polytabloid_pairing μ + change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp + rw [inner_self_eq_norm_sq_to_K] at hp + have hre := congrArg Complex.re hp + simpa [pow_two] using hre + +theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : + Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht + (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) + have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ + rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu + exact_mod_cast hu + + +section FiberGroup +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +noncomputable def fiberGroupEquiv (f : α → β) : + fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where + toFun p b := + { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ + invFun x := ⟨p.1⁻¹ x.1, by + have hh := p.2 (p.1⁻¹ x.1) + simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh + exact hh.symm.trans x.2⟩ + left_inv x := by apply Subtype.ext; simp + right_inv x := by apply Subtype.ext; simp } + invFun q := + ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), + fun x => (q (f x) ⟨x,rfl⟩).2⟩ + left_inv p := by + apply Subtype.ext + apply Equiv.ext + intro x + rfl + right_inv q := by + funext b + apply Equiv.ext + intro x + apply Subtype.ext + change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 + cases x with + | mk x hx => dsimp only at *; subst b; rfl + +lemma nat_card_fiberGroup (f : α → β) : + Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by + rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] + simp only [Nat.card_eq_fintype_card,Fintype.card_perm] + +omit [Fintype β] [Fintype γ] in + +lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) + (hinj : ∀ x y, f x = f y → g x = g y → x=y) : + Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by + have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by + intro p q hpq + dsimp only at hpq + have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by + apply inv_mul_eq_iff_eq_mul.mpr + rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] + have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 + have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) + have h1 : p.1.1⁻¹*q.1.1 = 1 := by + apply Equiv.ext + intro x + exact hinj _ x (hf x) (hg x) + have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) + have hpg : p.2=q.2 := by + apply Subtype.ext + have hh := hpq + rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh + exact mul_left_cancel hh + exact Prod.ext hpf hpg + have hc := Fintype.card_le_of_injective _ hi + simpa only [Fintype.card_prod,Fintype.card_perm] using hc + +end FiberGroup + +noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := + fiberGroup (rowIndex (μ := μ)) + +noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := + ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ + +lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by + ext p + constructor + · intro hp x; exact Fin.ext (hp x) + · intro hp x; exact congrArg Fin.val (hp x) + +noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where + smul p f := tabloidAct p f + one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl + mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl + +lemma tabloid_orbit_all (μ : YoungDiagram) : + MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by + ext f + simp only [Set.mem_univ,iff_true] + obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f + exact ⟨p,hp⟩ + +lemma tabloid_stabilizer (μ : YoungDiagram) : + MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by + ext p + change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x + constructor + · intro h x + have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h + simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + · intro h + apply Subtype.ext + funext x + exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) + +lemma card_tabloid_mul_row (μ : YoungDiagram) : + Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by + have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group + (Equiv.Perm (Cell μ)) (baseTabloid μ) + have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = + Fintype.card (Tabloid μ) := by + rw [tabloid_orbit_all,Fintype.card_setUniv] + simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh + +theorem factorial_le_dimension_row_column (μ : YoungDiagram) : + μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by + rw [←card_tabloid_mul_row] + nlinarith [dimension_times_column_ge_tabloids μ] + + +lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by + let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] + +lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by + let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + +lemma card_rowGroup (μ : YoungDiagram) : + Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by + rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_row_fiber] + +lemma card_colGroup (μ : YoungDiagram) : + Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by + rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card,card_col_fiber] + +abbrev Tail (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} + +lemma tail_card (μ : YoungDiagram) : Fintype.card (Tail μ) = μ.card - μ.rowLen 0 := by + have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) + rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh + exact hh + +lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by + have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) + rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h + +noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + {x : Tail μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where + toFun x := ⟨row x.1.1-1, by + have hx := row_lt_colLen x.1.1 + have hc : col x.1.1 = j := congrArg Fin.val x.2 + rw [hc] at hx + have hz := x.1.2 + omega⟩ + invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ + left_inv x := by + apply Subtype.ext + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · change row x.1.1 - 1 + 1 = row x.1.1 + have := x.1.2 + omega + · exact (congrArg Fin.val x.2).symm + right_inv i := by apply Fin.ext; simp [row] + +lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : Tail μ // colIndex x.1 = j} = μ.colLen j-1 := by + rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] + +lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : Tail μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by + by_cases hi : i.val=0 + · rw [ite_eq_left hi] + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun x => x.1.2 ?_⟩ + exact (congrArg Fin.val x.2).trans hi + · rw [ite_eq_right hi] + let e : {x : Tail μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := + { toFun := fun x => ⟨x.1.1,x.2⟩ + invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ + left_inv := fun x => rfl + right_inv := fun x => rfl } + rw [Fintype.card_congr e,card_row_fiber] + +lemma tail_row_group (μ : YoungDiagram) : + (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) = + Fintype.card (rowGroup μ) := by + rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_row] + by_cases hn : μ.colLen 0=0 + · have hr : μ.rowLen 0=0 := by + by_contra h + have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) + have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem + omega + let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ + simp [hr] + · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ + have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] + simp only [hz] + have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = + ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by + rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] + simp only [ite_true,Nat.factorial_zero,mul_one] + apply Finset.prod_congr rfl + intro x hx + rw [ite_eq_right (Finset.mem_erase.mp hx).1] + rw [hprod] + exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) + +lemma sum_tail_columns (μ : YoungDiagram) : + ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by + simp_rw [←card_tail_col] + rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : Tail μ => colIndex x.1)),tail_card] + +lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := + YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) + +lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num + | succ n ih => rw [pow_succ]; omega + +lemma column_group_le_tail (μ : YoungDiagram) : + Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * + Fintype.card (fiberGroup (fun x : Tail μ => colIndex x.1)) := by + rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => colIndex x.1)),nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_col] + calc + _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by + apply Finset.prod_congr rfl + intro j hj + exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm + _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by + apply Finset.prod_le_prod + intro j hj + exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) + _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] + +theorem choose_tail_le_dimension (μ : YoungDiagram) : + μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + have htail := card_fiberGroups_mul_le + (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) + (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) + rw [tail_card] at htail + have hc := column_group_le_tail μ + have hr := tail_row_group μ + have hd := factorial_le_dimension_row_column μ + simp only [←Nat.card_eq_fintype_card] at htail hc hr hd + have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * + ((μ.rowLen 0).factorial * j.factorial) := by + calc + _ ≤ _ := hd + _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * + (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc + _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * + (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * + Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring + _ ≤ _ := by + calc + _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := + Nat.mul_le_mul_left _ htail + _ = _ := by ring + have hj : j ≤ μ.card := Nat.sub_le _ _ + have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega + have hf := Nat.choose_mul_factorial_mul_factorial hj + rw [hs] at hf + rw [←hf] at hh + have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) + nlinarith + + +lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : + ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by + let e : s ≃ t := Finset.equivOfCardEq hc + let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by + simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) + let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) + refine ⟨p,fun x => ?_⟩ + by_cases hx : x ∈ s + · have hp : p x ∈ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t + rw [Equiv.sumCompl_symm_apply_of_pos hx] + exact (e ⟨x,hx⟩).2 + exact iff_of_true hp hx + · have hp : p x ∉ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t + rw [Equiv.sumCompl_symm_apply_of_neg hx] + exact (ec ⟨x,hx⟩).2 + exact iff_of_false hp hx + +noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := + Finset.univ.filter (fun x => (f.1 x).val ≠ 0) + +@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : + x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] + +lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tailSet (tabloidAct p f) = (tailSet f).image p := by + ext x + simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] + constructor + · intro h; exact ⟨p⁻¹ x,h,by simp⟩ + · rintro ⟨y,hy,rfl⟩; simpa using hy + +lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : + (tailSet f).card = μ.card-μ.rowLen 0 := by + obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f + rw [tailSet_act,Finset.card_image_of_injective _ p.injective] + change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ + rw [←Fintype.card_subtype] + exact tail_card μ + +noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := + Finset.univ.filter (fun f => tailSet f ⊆ A) + +lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by + obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst + have he : s.image p=t := by + ext x + constructor + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (hp y).mpr hy + · intro hx + exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ + apply Finset.card_equiv (tabloidAct p) + intro f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] + exact (Finset.image_inj p.injective).symm + +lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : + (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = + Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + let s := tailSet (baseTabloid μ) + let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card + have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := + tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) + have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by + have h := Finset.sum_card_fiberwise_eq_card_filter + (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet + have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by + ext f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, + card_tailSet,footprint] + simp [j] + rw [he] at h + rw [←h] + calc + _ = ∑ _t ∈ A.powersetCard j, c := by + apply Finset.sum_congr rfl + intro t ht + exact hconstant t (Finset.mem_powersetCard.mp ht).2 + _ = _ := by simp [Finset.card_powersetCard] + have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by + simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] + have hN := hcount Finset.univ + rw [hfull,Finset.card_univ,card_cell] at hN + rw [hcount,hN] + ring + +lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) + (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by + have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 + apply Subtype.ext + funext x + change f.1 (p⁻¹ x) = f.1 x + by_cases hx : x ∈ A + · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] + · have hy : p⁻¹ x ∉ A := by + intro h + have hh := hp (p⁻¹ x) h + have he : x=p⁻¹ x := by simpa using hh + exact hx (he ▸ h) + apply Fin.ext + have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) + have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) + exact hy0.trans hx0.symm + +noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where + carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), + (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} + zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ + add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by + rw [map_add,hv.2 p hp,hw.2 p hp]⟩ + smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by + rw [map_smul,hv.2 p hp]⟩ + +lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := + fun _ hv => hv.1 + +theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : + Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by + let : DecidableEq (Tabloid μ) := Classical.decEq _ + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : + (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by + refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ + rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), + PermutationHilbert.act_single,footprint_fixed A f hf p hp] + have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) + (fixedHilbert_le μ A) ht (footprint μ A) hproj + rw [finrank_hilbertSpace] at h + have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ + Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h + have hc := footprint_card_product μ A + have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ + have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn + nlinarith + +end Thorp.Specht + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +def IsUnitary (ρ : Representation ℂ G V) : Prop := + ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : + inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by + have h := hρ g v (ρ g⁻¹ w) + have he : ρ g (ρ g⁻¹ w) = w := by + change (ρ g * ρ g⁻¹) w = w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [he] at h + exact h.symm + +end Thorp.UnitaryFinite + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/Site.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/Site.lean index 40807f32b8f0f86b3d89e8a2c608315fb8c30d0b..4c9c1d0fe1edf4af52ef3f768f9b0477de06d426 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/Site.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/Site.lean @@ -1,873 +1,873 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.TailShapes - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.StrongSmoothing -open scoped BigOperators - -lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : - regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by - have hn : 0 < Fintype.card (Tuples d (2^d)) := by - rw [tuples_card,Nat.descFactorial_self] - exact Nat.factorial_pos _ - have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) - calc - _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / - ((2^d).descFactorial (2^d):ℝ) := by - apply Finset.sum_le_sum - intro x _ - exact both_pointwise d (2^d) order false x x - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] - push_cast - field_simp - -theorem strong_smoothing : MainStatement := by - refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ - intro d l _ order orientation x y - exact both_pointwise d l order orientation x y - -end Thorp.StrongSmoothing - -namespace Thorp.ButterflyReverse -open scoped BigOperators - -abbrev Site (d : ℕ) := {t : Fin d × Card d // t.2 t.1 = false} - -def site : (d : ℕ) → SwitchIndex d → Site d - | 0, t => nomatch t - | _+1, Sum.inl y => ⟨(0, Fin.cons false y), rfl⟩ - | d+1, Sum.inr (b,t) => - ⟨((site d t).1.1.succ, Fin.cons b (site d t).1.2), (site d t).2⟩ - -lemma site_injective (d : ℕ) : Function.Injective (site d) := by - induction d with - | zero => intro t; exact Empty.elim t - | succ d ih => - intro s t h - cases s with - | inl y => - cases t with - | inl z => - have he := congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h - exact congrArg Sum.inl he - | inr t => - have he := congrArg (fun a : Site (d+1) => a.1.1.val) h - simp [site] at he - | inr s => - cases t with - | inl y => - have he := congrArg (fun a : Site (d+1) => a.1.1.val) h - simp [site] at he - | inr t => - obtain ⟨b,s⟩ := s - obtain ⟨c,t⟩ := t - have hbc := congrArg (fun a : Site (d+1) => a.1.2 0) h - simp only [site, Fin.cons_zero] at hbc - have hst : site d s = site d t := by - apply Subtype.ext - apply Prod.ext - · exact Fin.succ_inj.mp (congrArg (fun a : Site (d+1) => a.1.1) h) - · exact congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h - cases hbc - cases ih hst - rfl - -lemma site_surjective (d : ℕ) : Function.Surjective (site d) := by - induction d with - | zero => intro t; exact Fin.elim0 t.1.1 - | succ d ih => - rintro ⟨⟨i,x⟩,hx⟩ - refine Fin.cases ?_ (fun j => ?_) i hx - · intro hx0 - refine ⟨Sum.inl (Fin.tail x), ?_⟩ - apply Subtype.ext - simp only [site, Prod.mk.injEq, true_and] - rw [←hx0,Fin.cons_self_tail] - · intro hxj - obtain ⟨t,ht⟩ := ih ⟨(j,Fin.tail x),hxj⟩ - refine ⟨Sum.inr (x 0,t), ?_⟩ - apply Subtype.ext - simp only [site,ht,Fin.cons_self_tail] - -noncomputable def siteEquiv (d : ℕ) : SwitchIndex d ≃ Site d := - Equiv.ofBijective (site d) ⟨site_injective d,site_surjective d⟩ - -def reverseCard (d : ℕ) : Equiv.Perm (Card d) where - toFun x := fun i => x i.rev - invFun x := fun i => x i.rev - left_inv x := by funext i; simp - right_inv x := by funext i; simp - -@[simp] lemma reverseCard_apply (d : ℕ) (x : Card d) (i : Fin d) : - reverseCard d x i = x i.rev := rfl - -@[simp] lemma reverseCard_involutive (d : ℕ) (x : Card d) : - reverseCard d (reverseCard d x) = x := by funext i; simp - -def mirrorSite (d : ℕ) : Equiv.Perm (Site d) where - toFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ - invFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ - left_inv s := by apply Subtype.ext; simp - right_inv s := by apply Subtype.ext; simp - -noncomputable def mirrorSwitch (d : ℕ) : Equiv.Perm (SwitchIndex d) := - (siteEquiv d).trans ((mirrorSite d).trans (siteEquiv d).symm) - -lemma site_mirrorSwitch (d : ℕ) (t : SwitchIndex d) : - site d (mirrorSwitch d t) = mirrorSite d (site d t) := by - exact (siteEquiv d).apply_symm_apply _ - -lemma routeDomain_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - t ∈ routeDomain d x y ↔ - ∀ j : Fin d, j ≠ (site d t).1.1 → - (site d t).1.2 j = if j < (site d t).1.1 then x j else y j := by - classical - induction d with - | zero => exact Empty.elim t - | succ d ih => - cases t with - | inl z => - change Sum.inl z ∈ (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq,Finset.mem_image, - reduceCtorEq,and_false,exists_false,or_false] - constructor - · intro hz j hj - subst z - have hj0 : j ≠ 0 := hj - obtain ⟨i,rfl⟩ := Fin.eq_succ_of_ne_zero hj0 - simp [site,Fin.tail] - · intro h - funext j - have he := h j.succ (by simp [site]) - simpa [site,Fin.tail] using he - | inr z => - obtain ⟨b,t⟩ := z - change Sum.inr (b,t) ∈ (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ - simp only [Finset.mem_insert,reduceCtorEq,false_or,Finset.mem_image,Sum.inr.injEq,Prod.mk.injEq] - constructor - · rintro ⟨s,hs,hb,ht⟩ - subst s - have hst := (ih (Fin.tail x) (Fin.tail y) t).mp hs - intro j hj - refine Fin.cases ?_ (fun i => ?_) j hj - · intro _ - simp [site,hb] - · intro hi - have hi' : i ≠ (site d t).1.1 := by simpa [site] using hi - simpa [site,Fin.tail] using hst i hi' - · intro h - have hb := h 0 (by simpa only [site] using (Fin.succ_ne_zero (site d t).1.1).symm) - have hb' : x 0 = b := by simpa [site] using hb.symm - refine ⟨t,?_,hb',rfl⟩ - apply (ih (Fin.tail x) (Fin.tail y) t).mpr - intro j hj - have he := h j.succ (by simpa [site] using hj) - simpa [site,Fin.tail] using he - -lemma routeValue_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - routeValue d x y t = Bool.xor (x (site d t).1.1) (y (site d t).1.1) := by - induction d with - | zero => exact Empty.elim t - | succ d ih => - cases t with - | inl z => rfl - | inr z => exact ih (Fin.tail x) (Fin.tail y) z.2 - -lemma mirrorSwitch_involutive (d : ℕ) (t : SwitchIndex d) : - mirrorSwitch d (mirrorSwitch d t) = t := by - apply site_injective d - rw [site_mirrorSwitch,site_mirrorSwitch] - apply Subtype.ext - simp [mirrorSite] - -lemma mirror_routeDomain (d : ℕ) (x y : Card d) (t : SwitchIndex d) - (ht : t ∈ routeDomain d x y) : - mirrorSwitch d t ∈ routeDomain d (reverseCard d y) (reverseCard d x) := by - rw [routeDomain_site,site_mirrorSwitch] - intro j hj - have hj' : j.rev ≠ (site d t).1.1 := by - intro h - apply hj - change j = (site d t).1.1.rev - rw [←h,Fin.rev_rev] - have he := (routeDomain_site d x y t).mp ht j.rev hj' - change (site d t).1.2 j.rev = - if j < (site d t).1.1.rev then y j.rev else x j.rev - rw [he] - have hord : j < (site d t).1.1.rev ↔ ¬j.rev < (site d t).1.1 := by - rw [Fin.lt_rev_iff] - constructor - · intro h - exact not_lt_of_ge h.le - · intro h - exact lt_of_le_of_ne (le_of_not_gt h) (Ne.symm hj') - by_cases h : j.rev < (site d t).1.1 <;> simp [h,hord] - -lemma mirror_routeValue (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - routeValue d (reverseCard d y) (reverseCard d x) (mirrorSwitch d t) = - routeValue d x y t := by - rw [routeValue_site,routeValue_site,site_mirrorSwitch] - simp only [mirrorSite,Equiv.coe_fn_mk,reverseCard_apply,Fin.rev_rev] - exact Bool.xor_comm _ _ - -noncomputable def mirrorCoins (d : ℕ) : Equiv.Perm (SwitchIndex d → Bool) where - toFun ω := fun t => ω (mirrorSwitch d t) - invFun ω := fun t => ω (mirrorSwitch d t) - left_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] - right_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] - -lemma mirror_endpoint (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) - (hxy : butterflyPerm d (decodeButterfly d ω) x = y) : - butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) (reverseCard d y) = - reverseCard d x := by - apply (butterfly_endpoint_iff d _ _ _).mpr - intro t ht - have ht' := mirror_routeDomain d (reverseCard d y) (reverseCard d x) t ht - simp only [reverseCard_involutive] at ht' - have he := (butterfly_endpoint_iff d ω x y).mp hxy (mirrorSwitch d t) ht' - change ω (mirrorSwitch d t) = _ - rw [he] - have hv := mirror_routeValue d x y (mirrorSwitch d t) - rw [mirrorSwitch_involutive] at hv - exact hv.symm - -lemma butterfly_mirror (d : ℕ) (ω : SwitchIndex d → Bool) : - butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) = - reverseCard d * (butterflyPerm d (decodeButterfly d ω))⁻¹ * reverseCard d := by - apply Equiv.ext - intro x - have he := mirror_endpoint d ω - ((butterflyPerm d (decodeButterfly d ω))⁻¹ (reverseCard d x)) (reverseCard d x) - (Equiv.apply_symm_apply _ _) - simpa only [reverseCard_involutive,Equiv.Perm.mul_apply] using he - -def reverseOrder (d : ℕ) : Equiv.Perm (Fin d) where - toFun := Fin.rev - invFun := Fin.rev - left_inv := Fin.rev_rev - right_inv := Fin.rev_rev - -lemma relabel_mul (d : ℕ) (a b : Equiv.Perm (Fin d)) : - StrongSmoothing.coordinateRelabel d (a*b) = - StrongSmoothing.coordinateRelabel d a * StrongSmoothing.coordinateRelabel d b := rfl - -lemma relabel_reverse (d : ℕ) : - StrongSmoothing.coordinateRelabel d (reverseOrder d) = reverseCard d := rfl - -lemma reverseCard_sq (d : ℕ) : reverseCard d * reverseCard d = 1 := by - ext x i - simp - -lemma sweep_mirror (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : - StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω) = - (StrongSmoothing.sweep d order ω)⁻¹ := by - simp only [StrongSmoothing.sweep,relabel_mul,relabel_reverse,butterfly_mirror,mul_inv_rev] - have hR : (reverseCard d)⁻¹ = reverseCard d := by - exact inv_eq_of_mul_eq_one_right (reverseCard_sq d) - rw [hR] - calc - _ = StrongSmoothing.coordinateRelabel d order * - (reverseCard d*reverseCard d) * - (butterflyPerm d (decodeButterfly d ω))⁻¹ * - (reverseCard d*reverseCard d) * (StrongSmoothing.coordinateRelabel d order)⁻¹ := by group - _ = _ := by rw [reverseCard_sq]; group - -lemma sweepKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : - StrongSmoothing.sweepKernel d l (order*reverseOrder d) = - (StrongSmoothing.sweepKernel d l order).transpose := by - classical - rw [StrongSmoothing.sweepKernel_law,StrongSmoothing.sweepKernel_law, - ←StrongSmoothing.PermLaw.inverse] - ext x y - unfold StrongSmoothing.PermLaw.kernel - rw [finiteMean_equiv (mirrorCoins d)] - apply finiteMean_congr - intro ω - change (if StrongSmoothing.tuplePerm - (StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω)) x = y then (1:ℝ) else 0) = _ - rw [sweep_mirror,StrongSmoothing.tuplePerm_inverse] - -lemma reflectedKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : - StrongSmoothing.reflectedKernel d l order true = - StrongSmoothing.reflectedKernel d l (order*reverseOrder d) false := by - simp only [StrongSmoothing.reflectedKernel,Bool.false_eq_true, - ↓reduceIte,sweepKernel_reverse,Matrix.transpose_transpose] - -end Thorp.ButterflyReverse - -namespace Thorp.StrongTail -open scoped BigOperators Classical - -section -open Specht - -lemma mem_tailDiagram (μ : YoungDiagram) (i j : ℕ) : - (i,j) ∈ tailDiagram μ ↔ (i+1,j) ∈ μ := by - rw [tailDiagram, YoungDiagram.mem_ofRowLens] - constructor - · rintro ⟨hi,hj⟩ - rw [List.getElem_tail,YoungDiagram.get_rowLens] at hj - exact YoungDiagram.mem_iff_lt_rowLen.mpr hj - · intro h - have hi : i+1 < μ.colLen 0 := - (YoungDiagram.mem_iff_lt_colLen.mp h).trans_le (μ.colLen_anti 0 j (Nat.zero_le _)) - have hi' : i < μ.rowLens.tail.length := by simp only [List.length_tail,YoungDiagram.length_rowLens]; omega - refine ⟨hi', ?_⟩ - simpa only [List.getElem_tail,YoungDiagram.get_rowLens] using YoungDiagram.mem_iff_lt_rowLen.mp h - -lemma tail_height (μ : YoungDiagram) : (tailDiagram μ).colLen 0 = μ.colLen 0 - 1 := by - rw [←YoungDiagram.length_rowLens] - exact (YoungDiagram.rowLens_length_ofRowLens (fun x hx => μ.pos_of_mem_rowLens x (List.mem_of_mem_tail hx))).trans - (by simp only [List.length_tail,YoungDiagram.length_rowLens]) - -noncomputable def tailCellEquiv (μ : YoungDiagram) : Cell (tailDiagram μ) ≃ Tail μ where - toFun x := ⟨⟨(x.1.1+1,x.1.2),(mem_tailDiagram μ _ _).mp x.2⟩,by simp [row]⟩ - invFun x := ⟨(row x.1-1,col x.1),(mem_tailDiagram μ _ _).mpr (by - have he : row x.1-1+1 = row x.1 := by have := x.2; omega - change (row x.1-1+1,col x.1) ∈ μ - rw [he] - exact x.1.2)⟩ - left_inv x := by apply Subtype.ext; simp [row,col] - right_inv x := by - apply Subtype.ext; apply Subtype.ext; apply Prod.ext - · change row x.1-1+1 = row x.1 - have := x.2; omega - · rfl - -noncomputable abbrev upCell (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : Cell μ := (tailCellEquiv μ x).1 - -@[simp] lemma upCell_row (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : row (upCell μ x) = row x+1 := rfl -@[simp] lemma upCell_col (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : col (upCell μ x) = col x := rfl - -lemma tail_card_eq (μ : YoungDiagram) : (tailDiagram μ).card = μ.card-μ.rowLen 0 := by - rw [←card_cell, Fintype.card_congr (tailCellEquiv μ), tail_card] - -noncomputable def extendPerm (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - Equiv.Perm (Cell μ) := p.extendDomain (tailCellEquiv μ) - -@[simp] lemma extendPerm_up (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (x : Cell (tailDiagram μ)) : extendPerm μ p (upCell μ x) = upCell μ (p x) := - Equiv.Perm.extendDomain_apply_image p (tailCellEquiv μ) x - -lemma extendPerm_top (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (x : Cell μ) (hx : row x=0) : extendPerm μ p x = x := - Equiv.Perm.extendDomain_apply_not_subtype p (tailCellEquiv μ) (not_not.mpr hx) - -@[simp] lemma extendPerm_inv (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - (extendPerm μ p)⁻¹ = extendPerm μ p⁻¹ := Equiv.Perm.extendDomain_symm _ _ - -@[simp] lemma extendPerm_sign (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - permSign (extendPerm μ p) = permSign p := by - simp [extendPerm,permSign,Equiv.Perm.sign_extendDomain] - -noncomputable def liftRows (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) : Fin (μ.colLen 0) := - if hx : row x ≠ 0 then - ⟨(f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).val+1,by - have h := (f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).isLt - have hh := tail_height μ - omega⟩ - else rowIndex x - -@[simp] lemma liftRows_up (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) - (x : Cell (tailDiagram μ)) : (liftRows μ f (upCell μ x)).val = (f.1 x).val+1 := by - simp [liftRows,upCell] - -lemma liftRows_top (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) (hx : row x=0) : - liftRows μ f x = rowIndex x := by simp [liftRows,hx] - -lemma liftRows_perm (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) - (p : Equiv.Perm (Cell (tailDiagram μ))) (hf : f.1 = rowIndex ∘ p) : - liftRows μ f = rowIndex ∘ extendPerm μ p := by - funext x - by_cases hx : row x = 0 - · simp [liftRows_top μ f x hx,extendPerm_top μ p x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he] - apply Fin.ext - simp [hf,Function.comp_apply,rowIndex] - -noncomputable def liftTabloid (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) : Tabloid μ := - ⟨liftRows μ f, by obtain ⟨p,hp⟩ := f.2; exact ⟨extendPerm μ p,liftRows_perm μ f p hp⟩⟩ - -@[simp] lemma liftTabloid_base (μ : YoungDiagram) : - liftTabloid μ (baseTabloid (tailDiagram μ)) = baseTabloid μ := by - apply Subtype.ext - funext x - by_cases hx : row x=0 - · exact liftRows_top μ _ x hx - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he] - apply Fin.ext - exact liftRows_up μ _ y - -lemma liftTabloid_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (f : Tabloid (tailDiagram μ)) : - liftTabloid μ (tabloidAct p f) = tabloidAct (extendPerm μ p) (liftTabloid μ f) := by - apply Subtype.ext - funext x - change liftRows μ (tabloidAct p f) x = liftRows μ f ((extendPerm μ p)⁻¹ x) - rw [extendPerm_inv] - by_cases hx : row x=0 - · rw [extendPerm_top μ p⁻¹ x hx,liftRows_top μ _ x hx,liftRows_top μ _ x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he,extendPerm_up] - apply Fin.ext - simp only [liftRows_up,tabloidAct_apply] - -noncomputable def restrictTabloids (μ : YoungDiagram) : - (Tabloid μ → ℂ) →ₗ[ℂ] (Tabloid (tailDiagram μ) → ℂ) where - toFun v := fun f => v (liftTabloid μ f) - map_add' := by intros; rfl - map_smul' := by intros; rfl - -lemma restrict_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (v : Tabloid μ → ℂ) : - restrictTabloids μ (tabloidRep μ (extendPerm μ p) v) = - tabloidRep (tailDiagram μ) p (restrictTabloids μ v) := by - ext f - change v (tabloidAct (extendPerm μ p)⁻¹ (liftTabloid μ f)) = v (liftTabloid μ (tabloidAct p⁻¹ f)) - rw [extendPerm_inv,liftTabloid_action] - -lemma extend_colGroup (μ : YoungDiagram) (c : colGroup (tailDiagram μ)) : - extendPerm μ c ∈ colGroup μ := by - intro x - by_cases hx : row x=0 - · rw [extendPerm_top μ c x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he,extendPerm_up,upCell_col,upCell_col] - exact c.2 y - -lemma restrict_polytabloid (μ : YoungDiagram) : - restrictTabloids μ (polytabloid μ) = polytabloid (tailDiagram μ) := by - let v := restrictTabloids μ (polytabloid μ) - have hv (c : colGroup (tailDiagram μ)) : - tabloidRep (tailDiagram μ) c v = permSign (c:Equiv.Perm (Cell (tailDiagram μ))) • v := by - rw [←restrict_action] - rw [polytabloid_col_action μ ⟨extendPerm μ c,extend_colGroup μ c⟩] - simp only [map_smul,extendPerm_sign] - rfl - have ha : alternator (colGroup (tailDiagram μ)) (tabloidRep (tailDiagram μ)) v = - (Fintype.card (colGroup (tailDiagram μ)):ℂ) • v := by - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,hv,smul_smul,permSign_sq,one_smul] - ext f - simp - have hb : v (baseTabloid (tailDiagram μ)) = 1 := by - change polytabloid μ (liftTabloid μ (baseTabloid (tailDiagram μ))) = 1 - rw [liftTabloid_base, polytabloid_base] - have he := alternator_rank_one_exact (tailDiagram μ) v - rw [ha] at he - simp only [Pi.smul_apply,hb,smul_eq_mul,mul_one] at he - have hc : (Fintype.card (colGroup (tailDiagram μ)):ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - exact (smul_right_injective _ hc) he - -lemma tail_space_le_image (μ : YoungDiagram) : - space (tailDiagram μ) ≤ (space μ).map (restrictTabloids μ) := by - apply Submodule.span_le.mpr - rintro _ ⟨p,rfl⟩ - refine ⟨tabloidRep μ (extendPerm μ p) (polytabloid μ), orbit_mem_space μ _, ?_⟩ - rw [restrict_action,restrict_polytabloid] - -theorem tail_dimension_le (μ : YoungDiagram) : - Module.finrank ℂ (space (tailDiagram μ)) ≤ Module.finrank ℂ (space μ) := - (Submodule.finrank_mono (tail_space_le_image μ)).trans (Submodule.finrank_map_le _ _) - -end -open StrongSmoothing - -def DensityAt (p C : ℝ) : Prop := - ∀ (d l : ℕ), l ≤ 2^d → ∀ (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : StrongSmoothing.Tuples d l), - let H := StrongSmoothing.reflectedKernel d l order rev - (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H x y)^p) - ≤ Real.exp (C*l)) ∧ - (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H y x)^p) - ≤ Real.exp (C*l)) ∧ - (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H x y)^p) ≤ Real.exp (C*l) ∧ - (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H y x)^p) ≤ Real.exp (C*l) - -lemma reflected_nonneg_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x y : Tuples d l) : 0 ≤ reflectedKernel d l order rev x y := by - cases rev - · exact reflected_nonneg _ _ _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_nonneg _ _ _ _ _ - -lemma reflected_symm_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) : - (reflectedKernel d l order rev).IsSymm := by - cases rev - · exact reflected_symmetric _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_symmetric _ _ _ - -lemma reflected_moment_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : Tuples d l) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^(1+(1/1000:ℝ))) ≤ - Real.exp (l*(1+heightDecay 1)) := by - cases rev - · exact reflected_moment _ _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_moment _ _ _ _ - -lemma reflected_moment_small (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : Tuples d l) {p : ℝ} (hp : 0 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) ≤ - Real.exp (l*(1+heightDecay 1)) := by - let : Nonempty (Tuples d l) := ⟨x⟩ - let q : ℝ := 1+1/1000 - let f := fun y : Tuples d l => (Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y - have hf : ∀ y, 0 ≤ f y := fun y => mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both _ _ _ _ _ _) - have hq : 0 < q := by norm_num [q] - have hr : 0 ≤ p/q := (div_pos hp hq).le - have hr1 : p/q ≤ 1 := (div_le_one hq).mpr hpq - have he (y) : (f y)^p = ((f y)^q)^(p/q) := by - rw [←Real.rpow_mul (hf y)] - congr 1 - field_simp - simp_rw [show (fun y : Tuples d l => ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) - = fun y => ((f y)^q)^(p/q) from funext he] - apply (mean_rpow_concave _ (fun y => Real.rpow_nonneg (hf y) _) hr hr1).trans - apply (Real.rpow_le_rpow (finiteMean_nonneg (fun y => Real.rpow_nonneg (hf y) _)) - (reflected_moment_both d l order rev x) hr).trans - rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hA : 0 ≤ (l:ℝ)*(1+heightDecay 1) := by - have hh := heightDecay_nonneg 1 - positivity - nlinarith - -lemma log_factorial_le_power (n N : ℕ) (hn : n ≤ N) (_ : 0 < N) : - Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log N := by - have hb : (n.factorial:ℝ) ≤ (N:ℝ)^n := by - exact_mod_cast (Nat.factorial_le_pow n).trans (Nat.pow_le_pow_left hn n) - simpa only [Real.log_pow] using Real.log_le_log (by positivity : (0:ℝ) ((Fintype.card X:ℝ)*f x)^p) := by - let M : ℝ := Fintype.card X - have hM : 0 < M := Nat.cast_pos.mpr Fintype.card_pos - have he (x) : (N*f x)^p = (N/M)^p*(M*f x)^p := by - rw [←Real.mul_rpow (div_nonneg hN.le hM.le) (mul_nonneg hM.le (hf x))] - congr 1 - field_simp - simp_rw [he] - rw [←Finset.mul_sum,Real.rpow_sub (div_pos hN hM),Real.rpow_one] - unfold finiteMean - dsimp [M] at hM ⊢ - field_simp - -lemma density_at_small_exponent {p : ℝ} (hp : 1 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : - DensityAt p (3+heightDecay 1) := by - intro d l hl order rev x - dsimp only - let : Nonempty (Tuples d l) := ⟨x⟩ - let H := reflectedKernel d l order rev - have hm := reflected_moment_small d l order rev x (by linarith : 0 H x y) (reflected_nonneg_both d l order rev x) - (by positivity) p] - have hrat : ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) ≤ Real.exp (2*l) := by - apply (Real.log_le_iff_le_exp (by positivity)).mp - rw [tuples_card] - exact_mod_cast log_normalization_le (2^d) l (by positivity) hl - have hr : 0 ≤ ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) := by positivity - have hrp : (((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ))^(p-1) ≤ Real.exp (2*l) := by - apply (Real.rpow_le_rpow hr hrat (by linarith)).trans - rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hpl : p-1 ≤ 1 := by linarith - nlinarith [(show (0:ℝ) ≤ l by positivity)] - apply (mul_le_mul hrp hm (finiteMean_nonneg (fun y => Real.rpow_nonneg - (mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both d l order rev x y)) _)) (Real.exp_pos _).le).trans - rw [←Real.exp_add] - apply Real.exp_le_exp.mpr - ring_nf - rfl - dsimp [H] at hpow - refine ⟨hm.trans hb,?_,hpow,?_⟩ - · simpa only [hs] using hm.trans hb - · simpa only [hs] using hpow - -end Thorp.StrongTail - -namespace Thorp.Casimir -open scoped BigOperators Classical - -section -open Filter - -noncomputable def traceMoment (d : ℕ) (μ : YoungDiagram) - (e : Card d ≃ Specht.Cell μ) (r : ℕ) : ℝ := - (LinearMap.trace ℂ (Specht.hilbertSpace μ) ((K d μ e)^r).toLinearMap).re - -noncomputable def fromDistance (d t : ℕ) (σ : Equiv.Perm (Card d)) : ℝ := - (1/2:ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t (g*σ⁻¹) - 1/(Nat.factorial (2^d):ℝ)| - -def MainStatement : Prop := - ∃ a C : ℝ, 0 < a ∧ 0 < C ∧ - (∀ d k : ℕ, 1 ≤ k → k ≤ 2^d → ∀ x : Fin k ↪ Card d, - (palindromeRowMoment d x (1/64))^(64/65:ℝ) ≤ - Real.exp (C*levelScale (2^d) k)) ∧ - (∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), - 0 < μ.card-μ.rowLen 0 → - ‖K d μ e‖ ≤ Real.exp (-a*levelScale (2^d) (μ.card-μ.rowLen 0)) ∧ - (Module.finrank ℂ (Specht.space μ):ℝ) * traceMoment d μ e 65 ≤ - Real.exp (C*levelScale (2^d) (μ.card-μ.rowLen 0))) ∧ - (∃ l : ℕ, 0 < l ∧ ∀ starts : (d : ℕ) → Equiv.Perm (Card d), - Tendsto (fun d => fromDistance d (l*d) (starts d)) atTop (nhds 0)) - -end - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/16) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/16) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/16)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/16+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/16) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/16) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/16) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/16) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/32) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/16 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/32) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -end Thorp.Casimir - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.TailShapes + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.StrongSmoothing +open scoped BigOperators + +lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : + regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by + have hn : 0 < Fintype.card (Tuples d (2^d)) := by + rw [tuples_card,Nat.descFactorial_self] + exact Nat.factorial_pos _ + have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) + calc + _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / + ((2^d).descFactorial (2^d):ℝ) := by + apply Finset.sum_le_sum + intro x _ + exact both_pointwise d (2^d) order false x x + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] + push_cast + field_simp + +theorem strong_smoothing : MainStatement := by + refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ + intro d l _ order orientation x y + exact both_pointwise d l order orientation x y + +end Thorp.StrongSmoothing + +namespace Thorp.ButterflyReverse +open scoped BigOperators + +abbrev Site (d : ℕ) := {t : Fin d × Card d // t.2 t.1 = false} + +def site : (d : ℕ) → SwitchIndex d → Site d + | 0, t => nomatch t + | _+1, Sum.inl y => ⟨(0, Fin.cons false y), rfl⟩ + | d+1, Sum.inr (b,t) => + ⟨((site d t).1.1.succ, Fin.cons b (site d t).1.2), (site d t).2⟩ + +lemma site_injective (d : ℕ) : Function.Injective (site d) := by + induction d with + | zero => intro t; exact Empty.elim t + | succ d ih => + intro s t h + cases s with + | inl y => + cases t with + | inl z => + have he := congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h + exact congrArg Sum.inl he + | inr t => + have he := congrArg (fun a : Site (d+1) => a.1.1.val) h + simp [site] at he + | inr s => + cases t with + | inl y => + have he := congrArg (fun a : Site (d+1) => a.1.1.val) h + simp [site] at he + | inr t => + obtain ⟨b,s⟩ := s + obtain ⟨c,t⟩ := t + have hbc := congrArg (fun a : Site (d+1) => a.1.2 0) h + simp only [site, Fin.cons_zero] at hbc + have hst : site d s = site d t := by + apply Subtype.ext + apply Prod.ext + · exact Fin.succ_inj.mp (congrArg (fun a : Site (d+1) => a.1.1) h) + · exact congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h + cases hbc + cases ih hst + rfl + +lemma site_surjective (d : ℕ) : Function.Surjective (site d) := by + induction d with + | zero => intro t; exact Fin.elim0 t.1.1 + | succ d ih => + rintro ⟨⟨i,x⟩,hx⟩ + refine Fin.cases ?_ (fun j => ?_) i hx + · intro hx0 + refine ⟨Sum.inl (Fin.tail x), ?_⟩ + apply Subtype.ext + simp only [site, Prod.mk.injEq, true_and] + rw [←hx0,Fin.cons_self_tail] + · intro hxj + obtain ⟨t,ht⟩ := ih ⟨(j,Fin.tail x),hxj⟩ + refine ⟨Sum.inr (x 0,t), ?_⟩ + apply Subtype.ext + simp only [site,ht,Fin.cons_self_tail] + +noncomputable def siteEquiv (d : ℕ) : SwitchIndex d ≃ Site d := + Equiv.ofBijective (site d) ⟨site_injective d,site_surjective d⟩ + +def reverseCard (d : ℕ) : Equiv.Perm (Card d) where + toFun x := fun i => x i.rev + invFun x := fun i => x i.rev + left_inv x := by funext i; simp + right_inv x := by funext i; simp + +@[simp] lemma reverseCard_apply (d : ℕ) (x : Card d) (i : Fin d) : + reverseCard d x i = x i.rev := rfl + +@[simp] lemma reverseCard_involutive (d : ℕ) (x : Card d) : + reverseCard d (reverseCard d x) = x := by funext i; simp + +def mirrorSite (d : ℕ) : Equiv.Perm (Site d) where + toFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ + invFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ + left_inv s := by apply Subtype.ext; simp + right_inv s := by apply Subtype.ext; simp + +noncomputable def mirrorSwitch (d : ℕ) : Equiv.Perm (SwitchIndex d) := + (siteEquiv d).trans ((mirrorSite d).trans (siteEquiv d).symm) + +lemma site_mirrorSwitch (d : ℕ) (t : SwitchIndex d) : + site d (mirrorSwitch d t) = mirrorSite d (site d t) := by + exact (siteEquiv d).apply_symm_apply _ + +lemma routeDomain_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + t ∈ routeDomain d x y ↔ + ∀ j : Fin d, j ≠ (site d t).1.1 → + (site d t).1.2 j = if j < (site d t).1.1 then x j else y j := by + classical + induction d with + | zero => exact Empty.elim t + | succ d ih => + cases t with + | inl z => + change Sum.inl z ∈ (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq,Finset.mem_image, + reduceCtorEq,and_false,exists_false,or_false] + constructor + · intro hz j hj + subst z + have hj0 : j ≠ 0 := hj + obtain ⟨i,rfl⟩ := Fin.eq_succ_of_ne_zero hj0 + simp [site,Fin.tail] + · intro h + funext j + have he := h j.succ (by simp [site]) + simpa [site,Fin.tail] using he + | inr z => + obtain ⟨b,t⟩ := z + change Sum.inr (b,t) ∈ (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ + simp only [Finset.mem_insert,reduceCtorEq,false_or,Finset.mem_image,Sum.inr.injEq,Prod.mk.injEq] + constructor + · rintro ⟨s,hs,hb,ht⟩ + subst s + have hst := (ih (Fin.tail x) (Fin.tail y) t).mp hs + intro j hj + refine Fin.cases ?_ (fun i => ?_) j hj + · intro _ + simp [site,hb] + · intro hi + have hi' : i ≠ (site d t).1.1 := by simpa [site] using hi + simpa [site,Fin.tail] using hst i hi' + · intro h + have hb := h 0 (by simpa only [site] using (Fin.succ_ne_zero (site d t).1.1).symm) + have hb' : x 0 = b := by simpa [site] using hb.symm + refine ⟨t,?_,hb',rfl⟩ + apply (ih (Fin.tail x) (Fin.tail y) t).mpr + intro j hj + have he := h j.succ (by simpa [site] using hj) + simpa [site,Fin.tail] using he + +lemma routeValue_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + routeValue d x y t = Bool.xor (x (site d t).1.1) (y (site d t).1.1) := by + induction d with + | zero => exact Empty.elim t + | succ d ih => + cases t with + | inl z => rfl + | inr z => exact ih (Fin.tail x) (Fin.tail y) z.2 + +lemma mirrorSwitch_involutive (d : ℕ) (t : SwitchIndex d) : + mirrorSwitch d (mirrorSwitch d t) = t := by + apply site_injective d + rw [site_mirrorSwitch,site_mirrorSwitch] + apply Subtype.ext + simp [mirrorSite] + +lemma mirror_routeDomain (d : ℕ) (x y : Card d) (t : SwitchIndex d) + (ht : t ∈ routeDomain d x y) : + mirrorSwitch d t ∈ routeDomain d (reverseCard d y) (reverseCard d x) := by + rw [routeDomain_site,site_mirrorSwitch] + intro j hj + have hj' : j.rev ≠ (site d t).1.1 := by + intro h + apply hj + change j = (site d t).1.1.rev + rw [←h,Fin.rev_rev] + have he := (routeDomain_site d x y t).mp ht j.rev hj' + change (site d t).1.2 j.rev = + if j < (site d t).1.1.rev then y j.rev else x j.rev + rw [he] + have hord : j < (site d t).1.1.rev ↔ ¬j.rev < (site d t).1.1 := by + rw [Fin.lt_rev_iff] + constructor + · intro h + exact not_lt_of_ge h.le + · intro h + exact lt_of_le_of_ne (le_of_not_gt h) (Ne.symm hj') + by_cases h : j.rev < (site d t).1.1 <;> simp [h,hord] + +lemma mirror_routeValue (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + routeValue d (reverseCard d y) (reverseCard d x) (mirrorSwitch d t) = + routeValue d x y t := by + rw [routeValue_site,routeValue_site,site_mirrorSwitch] + simp only [mirrorSite,Equiv.coe_fn_mk,reverseCard_apply,Fin.rev_rev] + exact Bool.xor_comm _ _ + +noncomputable def mirrorCoins (d : ℕ) : Equiv.Perm (SwitchIndex d → Bool) where + toFun ω := fun t => ω (mirrorSwitch d t) + invFun ω := fun t => ω (mirrorSwitch d t) + left_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] + right_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] + +lemma mirror_endpoint (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) + (hxy : butterflyPerm d (decodeButterfly d ω) x = y) : + butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) (reverseCard d y) = + reverseCard d x := by + apply (butterfly_endpoint_iff d _ _ _).mpr + intro t ht + have ht' := mirror_routeDomain d (reverseCard d y) (reverseCard d x) t ht + simp only [reverseCard_involutive] at ht' + have he := (butterfly_endpoint_iff d ω x y).mp hxy (mirrorSwitch d t) ht' + change ω (mirrorSwitch d t) = _ + rw [he] + have hv := mirror_routeValue d x y (mirrorSwitch d t) + rw [mirrorSwitch_involutive] at hv + exact hv.symm + +lemma butterfly_mirror (d : ℕ) (ω : SwitchIndex d → Bool) : + butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) = + reverseCard d * (butterflyPerm d (decodeButterfly d ω))⁻¹ * reverseCard d := by + apply Equiv.ext + intro x + have he := mirror_endpoint d ω + ((butterflyPerm d (decodeButterfly d ω))⁻¹ (reverseCard d x)) (reverseCard d x) + (Equiv.apply_symm_apply _ _) + simpa only [reverseCard_involutive,Equiv.Perm.mul_apply] using he + +def reverseOrder (d : ℕ) : Equiv.Perm (Fin d) where + toFun := Fin.rev + invFun := Fin.rev + left_inv := Fin.rev_rev + right_inv := Fin.rev_rev + +lemma relabel_mul (d : ℕ) (a b : Equiv.Perm (Fin d)) : + StrongSmoothing.coordinateRelabel d (a*b) = + StrongSmoothing.coordinateRelabel d a * StrongSmoothing.coordinateRelabel d b := rfl + +lemma relabel_reverse (d : ℕ) : + StrongSmoothing.coordinateRelabel d (reverseOrder d) = reverseCard d := rfl + +lemma reverseCard_sq (d : ℕ) : reverseCard d * reverseCard d = 1 := by + ext x i + simp + +lemma sweep_mirror (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : + StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω) = + (StrongSmoothing.sweep d order ω)⁻¹ := by + simp only [StrongSmoothing.sweep,relabel_mul,relabel_reverse,butterfly_mirror,mul_inv_rev] + have hR : (reverseCard d)⁻¹ = reverseCard d := by + exact inv_eq_of_mul_eq_one_right (reverseCard_sq d) + rw [hR] + calc + _ = StrongSmoothing.coordinateRelabel d order * + (reverseCard d*reverseCard d) * + (butterflyPerm d (decodeButterfly d ω))⁻¹ * + (reverseCard d*reverseCard d) * (StrongSmoothing.coordinateRelabel d order)⁻¹ := by group + _ = _ := by rw [reverseCard_sq]; group + +lemma sweepKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : + StrongSmoothing.sweepKernel d l (order*reverseOrder d) = + (StrongSmoothing.sweepKernel d l order).transpose := by + classical + rw [StrongSmoothing.sweepKernel_law,StrongSmoothing.sweepKernel_law, + ←StrongSmoothing.PermLaw.inverse] + ext x y + unfold StrongSmoothing.PermLaw.kernel + rw [finiteMean_equiv (mirrorCoins d)] + apply finiteMean_congr + intro ω + change (if StrongSmoothing.tuplePerm + (StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω)) x = y then (1:ℝ) else 0) = _ + rw [sweep_mirror,StrongSmoothing.tuplePerm_inverse] + +lemma reflectedKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : + StrongSmoothing.reflectedKernel d l order true = + StrongSmoothing.reflectedKernel d l (order*reverseOrder d) false := by + simp only [StrongSmoothing.reflectedKernel,Bool.false_eq_true, + ↓reduceIte,sweepKernel_reverse,Matrix.transpose_transpose] + +end Thorp.ButterflyReverse + +namespace Thorp.StrongTail +open scoped BigOperators Classical + +section +open Specht + +lemma mem_tailDiagram (μ : YoungDiagram) (i j : ℕ) : + (i,j) ∈ tailDiagram μ ↔ (i+1,j) ∈ μ := by + rw [tailDiagram, YoungDiagram.mem_ofRowLens] + constructor + · rintro ⟨hi,hj⟩ + rw [List.getElem_tail,YoungDiagram.get_rowLens] at hj + exact YoungDiagram.mem_iff_lt_rowLen.mpr hj + · intro h + have hi : i+1 < μ.colLen 0 := + (YoungDiagram.mem_iff_lt_colLen.mp h).trans_le (μ.colLen_anti 0 j (Nat.zero_le _)) + have hi' : i < μ.rowLens.tail.length := by simp only [List.length_tail,YoungDiagram.length_rowLens]; omega + refine ⟨hi', ?_⟩ + simpa only [List.getElem_tail,YoungDiagram.get_rowLens] using YoungDiagram.mem_iff_lt_rowLen.mp h + +lemma tail_height (μ : YoungDiagram) : (tailDiagram μ).colLen 0 = μ.colLen 0 - 1 := by + rw [←YoungDiagram.length_rowLens] + exact (YoungDiagram.rowLens_length_ofRowLens (fun x hx => μ.pos_of_mem_rowLens x (List.mem_of_mem_tail hx))).trans + (by simp only [List.length_tail,YoungDiagram.length_rowLens]) + +noncomputable def tailCellEquiv (μ : YoungDiagram) : Cell (tailDiagram μ) ≃ Tail μ where + toFun x := ⟨⟨(x.1.1+1,x.1.2),(mem_tailDiagram μ _ _).mp x.2⟩,by simp [row]⟩ + invFun x := ⟨(row x.1-1,col x.1),(mem_tailDiagram μ _ _).mpr (by + have he : row x.1-1+1 = row x.1 := by have := x.2; omega + change (row x.1-1+1,col x.1) ∈ μ + rw [he] + exact x.1.2)⟩ + left_inv x := by apply Subtype.ext; simp [row,col] + right_inv x := by + apply Subtype.ext; apply Subtype.ext; apply Prod.ext + · change row x.1-1+1 = row x.1 + have := x.2; omega + · rfl + +noncomputable abbrev upCell (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : Cell μ := (tailCellEquiv μ x).1 + +@[simp] lemma upCell_row (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : row (upCell μ x) = row x+1 := rfl +@[simp] lemma upCell_col (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : col (upCell μ x) = col x := rfl + +lemma tail_card_eq (μ : YoungDiagram) : (tailDiagram μ).card = μ.card-μ.rowLen 0 := by + rw [←card_cell, Fintype.card_congr (tailCellEquiv μ), tail_card] + +noncomputable def extendPerm (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : + Equiv.Perm (Cell μ) := p.extendDomain (tailCellEquiv μ) + +@[simp] lemma extendPerm_up (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) + (x : Cell (tailDiagram μ)) : extendPerm μ p (upCell μ x) = upCell μ (p x) := + Equiv.Perm.extendDomain_apply_image p (tailCellEquiv μ) x + +lemma extendPerm_top (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) + (x : Cell μ) (hx : row x=0) : extendPerm μ p x = x := + Equiv.Perm.extendDomain_apply_not_subtype p (tailCellEquiv μ) (not_not.mpr hx) + +@[simp] lemma extendPerm_inv (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : + (extendPerm μ p)⁻¹ = extendPerm μ p⁻¹ := Equiv.Perm.extendDomain_symm _ _ + +@[simp] lemma extendPerm_sign (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : + permSign (extendPerm μ p) = permSign p := by + simp [extendPerm,permSign,Equiv.Perm.sign_extendDomain] + +noncomputable def liftRows (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) : Fin (μ.colLen 0) := + if hx : row x ≠ 0 then + ⟨(f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).val+1,by + have h := (f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).isLt + have hh := tail_height μ + omega⟩ + else rowIndex x + +@[simp] lemma liftRows_up (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) + (x : Cell (tailDiagram μ)) : (liftRows μ f (upCell μ x)).val = (f.1 x).val+1 := by + simp [liftRows,upCell] + +lemma liftRows_top (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) (hx : row x=0) : + liftRows μ f x = rowIndex x := by simp [liftRows,hx] + +lemma liftRows_perm (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) + (p : Equiv.Perm (Cell (tailDiagram μ))) (hf : f.1 = rowIndex ∘ p) : + liftRows μ f = rowIndex ∘ extendPerm μ p := by + funext x + by_cases hx : row x = 0 + · simp [liftRows_top μ f x hx,extendPerm_top μ p x hx] + · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ + have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) + rw [←he] + apply Fin.ext + simp [hf,Function.comp_apply,rowIndex] + +noncomputable def liftTabloid (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) : Tabloid μ := + ⟨liftRows μ f, by obtain ⟨p,hp⟩ := f.2; exact ⟨extendPerm μ p,liftRows_perm μ f p hp⟩⟩ + +@[simp] lemma liftTabloid_base (μ : YoungDiagram) : + liftTabloid μ (baseTabloid (tailDiagram μ)) = baseTabloid μ := by + apply Subtype.ext + funext x + by_cases hx : row x=0 + · exact liftRows_top μ _ x hx + · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ + have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) + rw [←he] + apply Fin.ext + exact liftRows_up μ _ y + +lemma liftTabloid_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) + (f : Tabloid (tailDiagram μ)) : + liftTabloid μ (tabloidAct p f) = tabloidAct (extendPerm μ p) (liftTabloid μ f) := by + apply Subtype.ext + funext x + change liftRows μ (tabloidAct p f) x = liftRows μ f ((extendPerm μ p)⁻¹ x) + rw [extendPerm_inv] + by_cases hx : row x=0 + · rw [extendPerm_top μ p⁻¹ x hx,liftRows_top μ _ x hx,liftRows_top μ _ x hx] + · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ + have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) + rw [←he,extendPerm_up] + apply Fin.ext + simp only [liftRows_up,tabloidAct_apply] + +noncomputable def restrictTabloids (μ : YoungDiagram) : + (Tabloid μ → ℂ) →ₗ[ℂ] (Tabloid (tailDiagram μ) → ℂ) where + toFun v := fun f => v (liftTabloid μ f) + map_add' := by intros; rfl + map_smul' := by intros; rfl + +lemma restrict_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) + (v : Tabloid μ → ℂ) : + restrictTabloids μ (tabloidRep μ (extendPerm μ p) v) = + tabloidRep (tailDiagram μ) p (restrictTabloids μ v) := by + ext f + change v (tabloidAct (extendPerm μ p)⁻¹ (liftTabloid μ f)) = v (liftTabloid μ (tabloidAct p⁻¹ f)) + rw [extendPerm_inv,liftTabloid_action] + +lemma extend_colGroup (μ : YoungDiagram) (c : colGroup (tailDiagram μ)) : + extendPerm μ c ∈ colGroup μ := by + intro x + by_cases hx : row x=0 + · rw [extendPerm_top μ c x hx] + · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ + have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) + rw [←he,extendPerm_up,upCell_col,upCell_col] + exact c.2 y + +lemma restrict_polytabloid (μ : YoungDiagram) : + restrictTabloids μ (polytabloid μ) = polytabloid (tailDiagram μ) := by + let v := restrictTabloids μ (polytabloid μ) + have hv (c : colGroup (tailDiagram μ)) : + tabloidRep (tailDiagram μ) c v = permSign (c:Equiv.Perm (Cell (tailDiagram μ))) • v := by + rw [←restrict_action] + rw [polytabloid_col_action μ ⟨extendPerm μ c,extend_colGroup μ c⟩] + simp only [map_smul,extendPerm_sign] + rfl + have ha : alternator (colGroup (tailDiagram μ)) (tabloidRep (tailDiagram μ)) v = + (Fintype.card (colGroup (tailDiagram μ)):ℂ) • v := by + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,hv,smul_smul,permSign_sq,one_smul] + ext f + simp + have hb : v (baseTabloid (tailDiagram μ)) = 1 := by + change polytabloid μ (liftTabloid μ (baseTabloid (tailDiagram μ))) = 1 + rw [liftTabloid_base, polytabloid_base] + have he := alternator_rank_one_exact (tailDiagram μ) v + rw [ha] at he + simp only [Pi.smul_apply,hb,smul_eq_mul,mul_one] at he + have hc : (Fintype.card (colGroup (tailDiagram μ)):ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + exact (smul_right_injective _ hc) he + +lemma tail_space_le_image (μ : YoungDiagram) : + space (tailDiagram μ) ≤ (space μ).map (restrictTabloids μ) := by + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + refine ⟨tabloidRep μ (extendPerm μ p) (polytabloid μ), orbit_mem_space μ _, ?_⟩ + rw [restrict_action,restrict_polytabloid] + +theorem tail_dimension_le (μ : YoungDiagram) : + Module.finrank ℂ (space (tailDiagram μ)) ≤ Module.finrank ℂ (space μ) := + (Submodule.finrank_mono (tail_space_le_image μ)).trans (Submodule.finrank_map_le _ _) + +end +open StrongSmoothing + +def DensityAt (p C : ℝ) : Prop := + ∀ (d l : ℕ), l ≤ 2^d → ∀ (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : StrongSmoothing.Tuples d l), + let H := StrongSmoothing.reflectedKernel d l order rev + (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H x y)^p) + ≤ Real.exp (C*l)) ∧ + (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H y x)^p) + ≤ Real.exp (C*l)) ∧ + (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H x y)^p) ≤ Real.exp (C*l) ∧ + (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H y x)^p) ≤ Real.exp (C*l) + +lemma reflected_nonneg_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x y : Tuples d l) : 0 ≤ reflectedKernel d l order rev x y := by + cases rev + · exact reflected_nonneg _ _ _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_nonneg _ _ _ _ _ + +lemma reflected_symm_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) : + (reflectedKernel d l order rev).IsSymm := by + cases rev + · exact reflected_symmetric _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_symmetric _ _ _ + +lemma reflected_moment_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : Tuples d l) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^(1+(1/1000:ℝ))) ≤ + Real.exp (l*(1+heightDecay 1)) := by + cases rev + · exact reflected_moment _ _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_moment _ _ _ _ + +lemma reflected_moment_small (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : Tuples d l) {p : ℝ} (hp : 0 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) ≤ + Real.exp (l*(1+heightDecay 1)) := by + let : Nonempty (Tuples d l) := ⟨x⟩ + let q : ℝ := 1+1/1000 + let f := fun y : Tuples d l => (Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y + have hf : ∀ y, 0 ≤ f y := fun y => mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both _ _ _ _ _ _) + have hq : 0 < q := by norm_num [q] + have hr : 0 ≤ p/q := (div_pos hp hq).le + have hr1 : p/q ≤ 1 := (div_le_one hq).mpr hpq + have he (y) : (f y)^p = ((f y)^q)^(p/q) := by + rw [←Real.rpow_mul (hf y)] + congr 1 + field_simp + simp_rw [show (fun y : Tuples d l => ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) + = fun y => ((f y)^q)^(p/q) from funext he] + apply (mean_rpow_concave _ (fun y => Real.rpow_nonneg (hf y) _) hr hr1).trans + apply (Real.rpow_le_rpow (finiteMean_nonneg (fun y => Real.rpow_nonneg (hf y) _)) + (reflected_moment_both d l order rev x) hr).trans + rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hA : 0 ≤ (l:ℝ)*(1+heightDecay 1) := by + have hh := heightDecay_nonneg 1 + positivity + nlinarith + +lemma log_factorial_le_power (n N : ℕ) (hn : n ≤ N) (_ : 0 < N) : + Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log N := by + have hb : (n.factorial:ℝ) ≤ (N:ℝ)^n := by + exact_mod_cast (Nat.factorial_le_pow n).trans (Nat.pow_le_pow_left hn n) + simpa only [Real.log_pow] using Real.log_le_log (by positivity : (0:ℝ) ((Fintype.card X:ℝ)*f x)^p) := by + let M : ℝ := Fintype.card X + have hM : 0 < M := Nat.cast_pos.mpr Fintype.card_pos + have he (x) : (N*f x)^p = (N/M)^p*(M*f x)^p := by + rw [←Real.mul_rpow (div_nonneg hN.le hM.le) (mul_nonneg hM.le (hf x))] + congr 1 + field_simp + simp_rw [he] + rw [←Finset.mul_sum,Real.rpow_sub (div_pos hN hM),Real.rpow_one] + unfold finiteMean + dsimp [M] at hM ⊢ + field_simp + +lemma density_at_small_exponent {p : ℝ} (hp : 1 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : + DensityAt p (3+heightDecay 1) := by + intro d l hl order rev x + dsimp only + let : Nonempty (Tuples d l) := ⟨x⟩ + let H := reflectedKernel d l order rev + have hm := reflected_moment_small d l order rev x (by linarith : 0 H x y) (reflected_nonneg_both d l order rev x) + (by positivity) p] + have hrat : ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) ≤ Real.exp (2*l) := by + apply (Real.log_le_iff_le_exp (by positivity)).mp + rw [tuples_card] + exact_mod_cast log_normalization_le (2^d) l (by positivity) hl + have hr : 0 ≤ ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) := by positivity + have hrp : (((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ))^(p-1) ≤ Real.exp (2*l) := by + apply (Real.rpow_le_rpow hr hrat (by linarith)).trans + rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hpl : p-1 ≤ 1 := by linarith + nlinarith [(show (0:ℝ) ≤ l by positivity)] + apply (mul_le_mul hrp hm (finiteMean_nonneg (fun y => Real.rpow_nonneg + (mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both d l order rev x y)) _)) (Real.exp_pos _).le).trans + rw [←Real.exp_add] + apply Real.exp_le_exp.mpr + ring_nf + rfl + dsimp [H] at hpow + refine ⟨hm.trans hb,?_,hpow,?_⟩ + · simpa only [hs] using hm.trans hb + · simpa only [hs] using hpow + +end Thorp.StrongTail + +namespace Thorp.Casimir +open scoped BigOperators Classical + +section +open Filter + +noncomputable def traceMoment (d : ℕ) (μ : YoungDiagram) + (e : Card d ≃ Specht.Cell μ) (r : ℕ) : ℝ := + (LinearMap.trace ℂ (Specht.hilbertSpace μ) ((K d μ e)^r).toLinearMap).re + +noncomputable def fromDistance (d t : ℕ) (σ : Equiv.Perm (Card d)) : ℝ := + (1/2:ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t (g*σ⁻¹) - 1/(Nat.factorial (2^d):ℝ)| + +def MainStatement : Prop := + ∃ a C : ℝ, 0 < a ∧ 0 < C ∧ + (∀ d k : ℕ, 1 ≤ k → k ≤ 2^d → ∀ x : Fin k ↪ Card d, + (palindromeRowMoment d x (1/64))^(64/65:ℝ) ≤ + Real.exp (C*levelScale (2^d) k)) ∧ + (∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), + 0 < μ.card-μ.rowLen 0 → + ‖K d μ e‖ ≤ Real.exp (-a*levelScale (2^d) (μ.card-μ.rowLen 0)) ∧ + (Module.finrank ℂ (Specht.space μ):ℝ) * traceMoment d μ e 65 ≤ + Real.exp (C*levelScale (2^d) (μ.card-μ.rowLen 0))) ∧ + (∃ l : ℕ, 0 < l ∧ ∀ starts : (d : ℕ) → Equiv.Perm (Card d), + Tendsto (fun d => fromDistance d (l*d) (starts d)) atTop (nhds 0)) + +end + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/16) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/16) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/16)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/16+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/16) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + +lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/16) : + finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/16) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/16) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/32) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/16 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/32) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +end Thorp.Casimir + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/TailShapes.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/TailShapes.lean index 3188ed1556e7de8e65ed20dac157f8f875e6ab36..8fd8c83b725d6eb2a3dc2ce6cc668d51366d3fec 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/TailShapes.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/TailShapes.lean @@ -1,870 +1,870 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.InsertionPerm - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma partition_count (N : ℕ) : Fintype.card (Nat.Partition N)≤2^N := by - have h := Fintype.card_le_of_surjective (Nat.Partition.ofComposition N) Nat.Partition.ofComposition_surj - rw [composition_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) (Nat.sub_le N 1)) - -lemma shapes_count (N : ℕ) : Fintype.card (Shapes N)≤2^N := by - rw [Fintype.card_congr (shapePartitionEquiv N)] - exact partition_count N - -lemma rowLens_headD (μ : YoungDiagram) : μ.rowLens.headD 0=μ.rowLen 0 := by - cases he : μ.rowLens with - | nil => - have hc := sum_rowLens μ - rw [he,List.sum_nil] at hc - have hr := rowLen_zero_le_card μ - simp only [List.headD_nil] - omega - | cons a l => - have hh := YoungDiagram.get_rowLens (μ := μ) (i := 0) (h := by simp [he]) - simpa only [he,List.getElem_cons_zero,List.headD_cons] using hh - -lemma rowLens_tail_sum (μ : YoungDiagram) : μ.rowLens.tail.sum=μ.card-μ.rowLen 0 := by - have hh := rowLens_headD μ - have hc := sum_rowLens μ - cases he : μ.rowLens with - | nil => simp only [he,List.headD_nil] at hh; simp only [he,List.sum_nil] at hc; simp [←hc] - | cons a l => - simp only [he,List.headD_cons] at hh - simp only [he,List.sum_cons] at hc - simp only [List.tail_cons] - omega - -lemma positive_list_eq_of_tail_sum {a b : List ℕ} - (ha : ∀ x∈a, 0 - cases b with - | nil => rfl - | cons x l => - simp only [List.tail_nil,List.tail_cons] at ht - subst l - have hx := hb x (by simp) - simp only [List.sum_nil,List.sum_cons,add_zero] at hs - omega - | cons x l => - cases b with - | nil => - simp only [List.tail_nil,List.tail_cons] at ht - subst l - have hx := ha x (by simp) - simp only [List.sum_nil,List.sum_cons,add_zero] at hs - omega - | cons y m => - simp only [List.tail_cons] at ht - subst m - simp only [List.sum_cons] at hs - congr 1 - omega - -abbrev TailShapes (N j : ℕ) := {μ : Shapes N // μ.1.card-μ.1.rowLen 0=j} - -noncomputable def tailShapePartition (N j : ℕ) (μ : TailShapes N j) : Nat.Partition j where - parts := μ.1.1.rowLens.tail - parts_pos := fun {x} hx => μ.1.1.pos_of_mem_rowLens x (List.mem_of_mem_tail (by simpa using hx)) - parts_sum := by simpa using (rowLens_tail_sum μ.1.1).trans μ.2 - -lemma tailShapePartition_injective (N j : ℕ) : Function.Injective (tailShapePartition N j) := by - intro μ ν he - have hh : (μ.1.1.rowLens.tail : Multiset ℕ)=(ν.1.1.rowLens.tail : Multiset ℕ) := - congrArg Nat.Partition.parts he - have ht : μ.1.1.rowLens.tail=ν.1.1.rowLens.tail := by - have hm := congrArg (fun s : Multiset ℕ => s.sort (· ≥ ·)) hh - simpa only [Multiset.coe_sort, - List.mergeSort_eq_self _ μ.1.1.rowLens_sorted.pairwise.tail, - List.mergeSort_eq_self _ ν.1.1.rowLens_sorted.pairwise.tail] using hm - have hl := positive_list_eq_of_tail_sum (μ.1.1.pos_of_mem_rowLens) (ν.1.1.pos_of_mem_rowLens) - ht (by rw [sum_rowLens,sum_rowLens,μ.1.2,ν.1.2]) - apply Subtype.ext - apply Subtype.ext - apply YoungDiagram.equivListRowLens.injective - exact Subtype.ext hl - -lemma tail_shapes_count (N j : ℕ) : Fintype.card (TailShapes N j)≤2^j := by - exact (Fintype.card_le_of_injective _ (tailShapePartition_injective N j)).trans (partition_count j) - -end Thorp.Specht - -namespace Thorp -open scoped BigOperators Classical - -lemma tail_preserving_pairSwitch (d : ℕ) (p : Equiv.Perm (Card (d+1))) - (hp : ∀ x, Fin.tail (p x)=Fin.tail x) : - pairSwitch (fun u => p (Fin.cons false u) 0)=p := by - apply Equiv.ext - intro x - rw [←Fin.cons_self_tail x] - generalize x 0=b - generalize Fin.tail x=u - apply funext - intro i - refine Fin.cases ?_ (fun j => ?_) i - · change Bool.xor b (p (Fin.cons false u) 0)=p (Fin.cons b u) 0 - cases b with - | false => simp - | true => - have hn : p (Fin.cons false u) 0 ≠ p (Fin.cons true u) 0 := by - intro he - have hh : p (Fin.cons false u)=p (Fin.cons true u) := by - rw [←Fin.cons_self_tail (p (Fin.cons false u)),←Fin.cons_self_tail (p (Fin.cons true u)), - hp,hp,Fin.tail_cons,Fin.tail_cons,he] - have hh := congrFun (p.injective hh) 0 - simp only [Fin.cons_zero] at hh - contradiction - cases h0 : p (Fin.cons false u) 0 <;> cases h1 : p (Fin.cons true u) 0 <;> simp_all - · change u j=p (Fin.cons b u) j.succ - have h := congrFun (hp (Fin.cons b u)) j - simpa only [Fin.tail_cons,Fin.tail,Fin.cons_succ] using h.symm - -lemma pairSwitch_injective (d : ℕ) : Function.Injective (pairSwitch (d := d)) := by - intro ξ η h - funext u - have hh := congrArg (fun p : Equiv.Perm (Card (d+1)) => p (Fin.cons false u) 0) h - change Bool.xor false (ξ u)=Bool.xor false (η u) at hh - simpa only [Bool.false_xor] using hh - -end Thorp -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def pairFiberEquiv (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) : - (Card d → Bool) ≃ fiberGroup (fun x => Fin.tail (e.symm x)) := - Equiv.ofBijective (fun ξ => ⟨e.permCongr (pairSwitch ξ),by - intro x - simp only [Equiv.permCongr_apply,e.symm_apply_apply] - exact Fin.tail_cons _ _⟩) - ⟨fun ξ η h => pairSwitch_injective d (e.permCongr.injective (congrArg Subtype.val h)),by - intro p - let q := e.symm.permCongr p.1 - have hq : ∀ x, Fin.tail (q x)=Fin.tail x := by - intro x - have h := p.2 (e x) - simpa only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply] using h - refine ⟨fun u => q (Fin.cons false u) 0,?_⟩ - apply Subtype.ext - change e.permCongr (pairSwitch (fun u => q (Fin.cons false u) 0))=p.1 - rw [tail_preserving_pairSwitch d q hq] - apply Equiv.ext - intro x - simp only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply]⟩ - -lemma pair_sum_taboid_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d < μ.colLen 0) (v : space μ) : - (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ))) v.1=0 := by - have he : (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)))= - symmetrizer (fiberGroup (fun x => Fin.tail (e.symm x))) (tabloidRep μ) := - Fintype.sum_equiv (pairFiberEquiv d μ e) _ _ (fun _ => rfl) - rw [he] - exact tall_column_average_zero μ _ 0 (by simpa only [card_positions] using hj) v.1 v.2 - -lemma pair_operator_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d < μ.colLen 0) : - UnitaryFinite.sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) pairSwitch=0 := by - apply ContinuousLinearMap.ext - intro v - obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v - have hh : (∑ ξ : Card d → Bool, representation μ (e.permCongr (pairSwitch ξ))) w=0 := by - apply Subtype.ext - simp only [LinearMap.sum_apply,Submodule.coe_sum,Submodule.coe_zero] - change (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)) w.1)=0 - simpa only [LinearMap.sum_apply] using pair_sum_taboid_zero d μ e hj w - have hh' := congrArg (spaceHilbertEquiv μ) hh - simp only [LinearMap.sum_apply,map_sum,map_zero] at hh' - change ((Fintype.card (Card d → Bool):ℂ)⁻¹ • - ∑ ξ : Card d → Bool, UnitaryFinite.continuousRepresentation (relabelledUnitary μ e) (pairSwitch ξ)) - (spaceHilbertEquiv μ w)=0 - rw [smul_apply,sum_apply] - change (Fintype.card (Card d → Bool):ℂ)⁻¹ • - (∑ ξ : Card d → Bool, spaceHilbertEquiv μ (representation μ (e.permCongr (pairSwitch ξ)) - ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ w))))=0 - simp only [LinearEquiv.symm_apply_apply,hh',smul_zero] - -open UnitaryFinite - -lemma palindrome_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d<μ.colLen 0) : - sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm (d+1))=0 := by - let ρ := relabelledUnitary μ e - let : NormedAddCommGroup (hilbertSpace μ) := inferInstance - let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance - let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance - have hpair : sampleOperator (V := hilbertSpace μ) ρ (pairSwitch (d := d))=0 := pair_operator_tall_zero d μ e hj - have hi : sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)=0 := by - rw [inverse_butterfly_average_step,hpair,mul_zero] - rw [sampleOperator_inv ρ (relabelledUnitary_unitary μ e)] at hi - rw [sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e),hi,mul_zero] - -lemma palindrome_tall_zero_general (d : ℕ) (hd : 0 (2:ℝ)^d) atTop atTop := - tendsto_pow_atTop_atTop_of_one_lt (by norm_num) - -lemma twopow_nat_tendsto : Tendsto (fun d : ℕ => (2:ℕ)^d) atTop atTop := - tendsto_pow_atTop_atTop_of_one_lt (by norm_num) - -lemma twopow_mul_eventually (c : ℝ) (hc : 0.trans_eq (mul_comm _ _) - -lemma exp_two_absorb (β n : ℝ) (hx : Real.log 2≤β*n/2) : - Real.exp (-β*n)+Real.exp (-β*n)≤Real.exp (-β*n/2) := by - calc - _ = Real.exp (Real.log 2-β*n) := by rw [Real.exp_sub,Real.exp_log (by norm_num)]; rw [neg_mul,Real.exp_neg]; ring - _ ≤ _ := Real.exp_le_exp.mpr (by linarith) - -end Thorp.DimensionEstimates -namespace Thorp.Specht -open scoped BigOperators Classical -open Filter UnitaryFinite DimensionEstimates - -theorem exponential_dimension_spectral (h : ℝ) (hh : 0 (f x)^a) ≤ (finiteMean f)^a := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hh := (Real.concaveOn_rpow ha ha1).le_map_sum - (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) - (p := f) (fun _ _ => by positivity) - (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) - (fun x _ => hf x) - simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), - ←div_eq_mul_inv,finiteMean] using hh - -noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x - -omit [Nonempty X] in -lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := - Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) - -omit [Nonempty X] in -lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - {b : ℝ} (hb : 1 ≤ b) (y : X) : - (act K f y)^b ≤ act K (fun x => (f x)^b) y := by - simpa only [smul_eq_mul,act] using - (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) - (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) - -lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - {p A : ℝ} (hp : 1 ≤ p) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by - classical - let s : ℝ := ∑ x, f x - have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - by_cases hz : s=0 - · have hfz : ∀ x, f x=0 := by - intro x - exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) - simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, - Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] - · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) - let w : X → ℝ := fun x => f x/s - have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs - have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz - have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by - simp only [act,w,finiteMean,Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - have hz' : (∑ x, f x) ≠ 0 := hz - dsimp [s] - field_simp [hz',ne_of_gt hN] - have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by - rw [hact,Real.mul_rpow (mean_nonneg f hf) - (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) - exact (convexOn_rpow hp).map_sum_le - (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) - have hh := finiteMean_mono hj - have he : finiteMean (fun y => (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = - (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by - simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, - finiteMean_sum, mul_comm (w _), finiteMean_mul_const] - rw [he] at hh - apply hh.trans - have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by - calc - _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum - (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) - _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] - simpa only [mul_comm (Real.exp A)] using - mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) - -lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^(b*p)) ≤ - Real.exp A*(finiteMean (fun x => (f x)^b))^p := by - calc - _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by - apply finiteMean_mono - intro y - rw [Real.rpow_mul (act_nonneg K hK f hf y)] - exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) - _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) - -variable [DecidableEq X] - -omit [Nonempty X] in -lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : - ∀ x y, 0 ≤ (K^r) x y := by - classical - induction r with - | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num - | succ r ih => - intro x y - rw [pow_succ,Matrix.mul_apply] - exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) - -omit [Nonempty X] in -lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : - ∀ x, ∑ y, (K^r) x y = 1 := by - classical - induction r with - | zero => intro x; simp [Matrix.one_apply] - | succ r ih => - intro x - simp only [pow_succ,Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hrow,mul_one,ih] - -noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := - (Fintype.card X:ℝ)*(K^r) x y - -omit [Nonempty X] in -lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : - 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) - -omit [Nonempty X] in -lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : - rowDensity K (r+1) x y = act K (rowDensity K r x) y := by - simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] - apply Finset.sum_congr rfl - intro z _ - ring - -lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : - finiteMean (rowDensity K r x) = 1 := by - have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) - simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] - -lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by - induction r with - | zero => simp [rowDensity_mean K hrow] - | succ r ih => - have hpr : 1 ≤ p^r := one_le_pow₀ hp - have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp - simp_rw [rowDensity_succ] - calc - _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by - rw [pow_succ] - exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) - _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by - apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le - exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) - _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring - _ ≤ _ := by - apply Real.exp_le_exp.mpr - have hh := mul_le_mul_of_nonneg_left hps hA - push_cast - nlinarith - -lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by - have hpos : 0 < p^r := by linarith - have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) - (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) - (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) - have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by - rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] - rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] - simp_rw [he] at hj - apply hj.trans - calc - _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := - Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) - (by positivity) - _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] - -lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : - (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z - have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = - finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by - simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] - rw [Finset.sum_div] - apply Finset.sum_congr rfl - intro z _ - field_simp - have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ - Real.exp (2*A*r) := by - calc - _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by - apply finiteMean_mono - intro z - nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] - _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ - finiteMean (fun z => (rowDensity K r y z)^2))/2 := by - simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] - _ ≤ _ := by - have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x - have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y - linarith - apply (le_div_iff₀ hN).mpr - simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh - -lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by - calc - (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num - _ ≤ _ := by simpa only [Nat.cast_ofNat] using - (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) - -end Thorp.StrongSmoothing - -namespace Thorp.StrongSmoothing.PermLaw -open scoped BigOperators -variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] - -noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := - fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) - -omit [Fintype X] in -lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by - simp only [kernel,←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype X] in -lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by - ext x y - apply finiteMean_congr - intro ω - have he : (P ω)⁻¹ x=y ↔ P ω y=x := by - change (P ω).symm x=y ↔ P ω y=x - exact (Equiv.symm_apply_eq (P ω)).trans eq_comm - simp only [he] - -lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by - have hh := row (fun ω => (P ω)⁻¹) y - rw [inverse] at hh - exact hh - -lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : - kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by - ext x y - simp only [Matrix.mul_apply,kernel] - have he (ω : Ω × Ω') : - (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = - ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by - simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] - rfl - change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro z _ - exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) - (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) - -omit [Fintype X] in -lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : - kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by - apply finiteMean_congr - intro ω - have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by - change e (P ω (e.symm x))=y ↔ _ - exact (Equiv.eq_symm_apply e).symm - simp only [he] - -end Thorp.StrongSmoothing.PermLaw - -namespace Thorp.StrongSmoothing -open scoped BigOperators - -section MatrixHelpers -variable {X : Type*} [Fintype X] - -lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := - Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) - -lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) - (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hB,mul_one,hA] - -lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) - (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.sum_mul,hA,one_mul,hB] - -lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) - _ = D := by rw [←Finset.sum_mul,hrow,one_mul] - -lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) - (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) - _ = D := by rw [←Finset.mul_sum,hcol,mul_one] - -variable [DecidableEq X] - -lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by - induction r with - | zero => simp - | succ r ih => - calc - _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring - _ = (A*B)^(r+1)*(A*B) := by rw [ih] - _ = _ := (pow_succ (A*B) (r+1)).symm - -end MatrixHelpers - -section TupleAction -variable {ι β Ω : Type*} [Fintype Ω] - -def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where - toFun x := x.trans P.toEmbedding - invFun x := x.trans P.symm.toEmbedding - left_inv x := by ext i; simp - right_inv x := by ext i; simp - -@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : - tuplePerm P x i = P (x i) := rfl - -lemma tuplePerm_mul (P Q : Equiv.Perm β) : - tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by - ext x i - rfl - -lemma tuplePerm_inverse (P : Equiv.Perm β) : - tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by - ext x i - rfl - -variable [Fintype ι] [DecidableEq β] - -lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : - PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by - classical - apply finiteMean_congr - intro ω - have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun z : ι ↪ β => z i) h - simp only [he] -end TupleAction - -lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : - sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by - ext x y - exact tupleProbability_kernel _ x y - -lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - reflectedKernel d l order false x y = - PairRouting.tupleProbability (palindromePerm d) - ((tuplePerm (coordinateRelabel d order)).symm x) - ((tuplePerm (coordinateRelabel d order)).symm y) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) - have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by - rw [sweepKernel_law] - simp only [sweep,tuplePerm_mul,tuplePerm_inverse] - rfl - rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] - rw [←PermLaw.inverse,←PermLaw.mul] - have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = - fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by - funext ω - simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] - change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ - group - rw [hprod,PermLaw.conjugate,tupleProbability_kernel] - - -lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ - -lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.row _ _ - -lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.col _ _ - -lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ reflectedKernel d l order false x y := by - exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_nonneg d l order) x y - -lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, reflectedKernel d l order false x y = 1 := - mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x - -lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, reflectedKernel d l order false x y = 1 := - mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y - -lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : - (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ - -lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ - Real.exp (l*(1+heightDecay 1)) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - simp_rw [reflectedKernel_conjugate] - have he := finiteMean_equiv e (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ - (1+(1/1000:ℝ))) - change finiteMean (fun y => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ - (1+(1/1000:ℝ))) ≤ _ - rw [←he] - simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) - -lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by - simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] - -lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - ((reflectedKernel d l order false)^2000) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - let : Nonempty (Tuples d l) := ⟨x⟩ - have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) - (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) - (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) - (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) - (reflected_moment d l order) 1000 density_exponent_numeric x y - have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring - norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh - simpa only [he,tuples_card] using hh - -lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) - (x y : Tuples d l) : - ((reflectedKernel d l order orientation)^2001) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - cases orientation - · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ - rw [pow_succ] - exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) - (canonical_pointwise d l order) x y - · let A := sweepKernel d l order - change ((A*A.transpose)^(2000+1)) x y ≤ _ - rw [←sandwich_power] - apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_row d l order) - exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) - (canonical_pointwise d l order) - -end Thorp.StrongSmoothing - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.InsertionPerm + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma partition_count (N : ℕ) : Fintype.card (Nat.Partition N)≤2^N := by + have h := Fintype.card_le_of_surjective (Nat.Partition.ofComposition N) Nat.Partition.ofComposition_surj + rw [composition_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) (Nat.sub_le N 1)) + +lemma shapes_count (N : ℕ) : Fintype.card (Shapes N)≤2^N := by + rw [Fintype.card_congr (shapePartitionEquiv N)] + exact partition_count N + +lemma rowLens_headD (μ : YoungDiagram) : μ.rowLens.headD 0=μ.rowLen 0 := by + cases he : μ.rowLens with + | nil => + have hc := sum_rowLens μ + rw [he,List.sum_nil] at hc + have hr := rowLen_zero_le_card μ + simp only [List.headD_nil] + omega + | cons a l => + have hh := YoungDiagram.get_rowLens (μ := μ) (i := 0) (h := by simp [he]) + simpa only [he,List.getElem_cons_zero,List.headD_cons] using hh + +lemma rowLens_tail_sum (μ : YoungDiagram) : μ.rowLens.tail.sum=μ.card-μ.rowLen 0 := by + have hh := rowLens_headD μ + have hc := sum_rowLens μ + cases he : μ.rowLens with + | nil => simp only [he,List.headD_nil] at hh; simp only [he,List.sum_nil] at hc; simp [←hc] + | cons a l => + simp only [he,List.headD_cons] at hh + simp only [he,List.sum_cons] at hc + simp only [List.tail_cons] + omega + +lemma positive_list_eq_of_tail_sum {a b : List ℕ} + (ha : ∀ x∈a, 0 + cases b with + | nil => rfl + | cons x l => + simp only [List.tail_nil,List.tail_cons] at ht + subst l + have hx := hb x (by simp) + simp only [List.sum_nil,List.sum_cons,add_zero] at hs + omega + | cons x l => + cases b with + | nil => + simp only [List.tail_nil,List.tail_cons] at ht + subst l + have hx := ha x (by simp) + simp only [List.sum_nil,List.sum_cons,add_zero] at hs + omega + | cons y m => + simp only [List.tail_cons] at ht + subst m + simp only [List.sum_cons] at hs + congr 1 + omega + +abbrev TailShapes (N j : ℕ) := {μ : Shapes N // μ.1.card-μ.1.rowLen 0=j} + +noncomputable def tailShapePartition (N j : ℕ) (μ : TailShapes N j) : Nat.Partition j where + parts := μ.1.1.rowLens.tail + parts_pos := fun {x} hx => μ.1.1.pos_of_mem_rowLens x (List.mem_of_mem_tail (by simpa using hx)) + parts_sum := by simpa using (rowLens_tail_sum μ.1.1).trans μ.2 + +lemma tailShapePartition_injective (N j : ℕ) : Function.Injective (tailShapePartition N j) := by + intro μ ν he + have hh : (μ.1.1.rowLens.tail : Multiset ℕ)=(ν.1.1.rowLens.tail : Multiset ℕ) := + congrArg Nat.Partition.parts he + have ht : μ.1.1.rowLens.tail=ν.1.1.rowLens.tail := by + have hm := congrArg (fun s : Multiset ℕ => s.sort (· ≥ ·)) hh + simpa only [Multiset.coe_sort, + List.mergeSort_eq_self _ μ.1.1.rowLens_sorted.pairwise.tail, + List.mergeSort_eq_self _ ν.1.1.rowLens_sorted.pairwise.tail] using hm + have hl := positive_list_eq_of_tail_sum (μ.1.1.pos_of_mem_rowLens) (ν.1.1.pos_of_mem_rowLens) + ht (by rw [sum_rowLens,sum_rowLens,μ.1.2,ν.1.2]) + apply Subtype.ext + apply Subtype.ext + apply YoungDiagram.equivListRowLens.injective + exact Subtype.ext hl + +lemma tail_shapes_count (N j : ℕ) : Fintype.card (TailShapes N j)≤2^j := by + exact (Fintype.card_le_of_injective _ (tailShapePartition_injective N j)).trans (partition_count j) + +end Thorp.Specht + +namespace Thorp +open scoped BigOperators Classical + +lemma tail_preserving_pairSwitch (d : ℕ) (p : Equiv.Perm (Card (d+1))) + (hp : ∀ x, Fin.tail (p x)=Fin.tail x) : + pairSwitch (fun u => p (Fin.cons false u) 0)=p := by + apply Equiv.ext + intro x + rw [←Fin.cons_self_tail x] + generalize x 0=b + generalize Fin.tail x=u + apply funext + intro i + refine Fin.cases ?_ (fun j => ?_) i + · change Bool.xor b (p (Fin.cons false u) 0)=p (Fin.cons b u) 0 + cases b with + | false => simp + | true => + have hn : p (Fin.cons false u) 0 ≠ p (Fin.cons true u) 0 := by + intro he + have hh : p (Fin.cons false u)=p (Fin.cons true u) := by + rw [←Fin.cons_self_tail (p (Fin.cons false u)),←Fin.cons_self_tail (p (Fin.cons true u)), + hp,hp,Fin.tail_cons,Fin.tail_cons,he] + have hh := congrFun (p.injective hh) 0 + simp only [Fin.cons_zero] at hh + contradiction + cases h0 : p (Fin.cons false u) 0 <;> cases h1 : p (Fin.cons true u) 0 <;> simp_all + · change u j=p (Fin.cons b u) j.succ + have h := congrFun (hp (Fin.cons b u)) j + simpa only [Fin.tail_cons,Fin.tail,Fin.cons_succ] using h.symm + +lemma pairSwitch_injective (d : ℕ) : Function.Injective (pairSwitch (d := d)) := by + intro ξ η h + funext u + have hh := congrArg (fun p : Equiv.Perm (Card (d+1)) => p (Fin.cons false u) 0) h + change Bool.xor false (ξ u)=Bool.xor false (η u) at hh + simpa only [Bool.false_xor] using hh + +end Thorp +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def pairFiberEquiv (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) : + (Card d → Bool) ≃ fiberGroup (fun x => Fin.tail (e.symm x)) := + Equiv.ofBijective (fun ξ => ⟨e.permCongr (pairSwitch ξ),by + intro x + simp only [Equiv.permCongr_apply,e.symm_apply_apply] + exact Fin.tail_cons _ _⟩) + ⟨fun ξ η h => pairSwitch_injective d (e.permCongr.injective (congrArg Subtype.val h)),by + intro p + let q := e.symm.permCongr p.1 + have hq : ∀ x, Fin.tail (q x)=Fin.tail x := by + intro x + have h := p.2 (e x) + simpa only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply] using h + refine ⟨fun u => q (Fin.cons false u) 0,?_⟩ + apply Subtype.ext + change e.permCongr (pairSwitch (fun u => q (Fin.cons false u) 0))=p.1 + rw [tail_preserving_pairSwitch d q hq] + apply Equiv.ext + intro x + simp only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply]⟩ + +lemma pair_sum_taboid_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d < μ.colLen 0) (v : space μ) : + (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ))) v.1=0 := by + have he : (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)))= + symmetrizer (fiberGroup (fun x => Fin.tail (e.symm x))) (tabloidRep μ) := + Fintype.sum_equiv (pairFiberEquiv d μ e) _ _ (fun _ => rfl) + rw [he] + exact tall_column_average_zero μ _ 0 (by simpa only [card_positions] using hj) v.1 v.2 + +lemma pair_operator_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d < μ.colLen 0) : + UnitaryFinite.sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) pairSwitch=0 := by + apply ContinuousLinearMap.ext + intro v + obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v + have hh : (∑ ξ : Card d → Bool, representation μ (e.permCongr (pairSwitch ξ))) w=0 := by + apply Subtype.ext + simp only [LinearMap.sum_apply,Submodule.coe_sum,Submodule.coe_zero] + change (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)) w.1)=0 + simpa only [LinearMap.sum_apply] using pair_sum_taboid_zero d μ e hj w + have hh' := congrArg (spaceHilbertEquiv μ) hh + simp only [LinearMap.sum_apply,map_sum,map_zero] at hh' + change ((Fintype.card (Card d → Bool):ℂ)⁻¹ • + ∑ ξ : Card d → Bool, UnitaryFinite.continuousRepresentation (relabelledUnitary μ e) (pairSwitch ξ)) + (spaceHilbertEquiv μ w)=0 + rw [smul_apply,sum_apply] + change (Fintype.card (Card d → Bool):ℂ)⁻¹ • + (∑ ξ : Card d → Bool, spaceHilbertEquiv μ (representation μ (e.permCongr (pairSwitch ξ)) + ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ w))))=0 + simp only [LinearEquiv.symm_apply_apply,hh',smul_zero] + +open UnitaryFinite + +lemma palindrome_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d<μ.colLen 0) : + sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm (d+1))=0 := by + let ρ := relabelledUnitary μ e + let : NormedAddCommGroup (hilbertSpace μ) := inferInstance + let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance + let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance + have hpair : sampleOperator (V := hilbertSpace μ) ρ (pairSwitch (d := d))=0 := pair_operator_tall_zero d μ e hj + have hi : sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)=0 := by + rw [inverse_butterfly_average_step,hpair,mul_zero] + rw [sampleOperator_inv ρ (relabelledUnitary_unitary μ e)] at hi + rw [sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e),hi,mul_zero] + +lemma palindrome_tall_zero_general (d : ℕ) (hd : 0 (2:ℝ)^d) atTop atTop := + tendsto_pow_atTop_atTop_of_one_lt (by norm_num) + +lemma twopow_nat_tendsto : Tendsto (fun d : ℕ => (2:ℕ)^d) atTop atTop := + tendsto_pow_atTop_atTop_of_one_lt (by norm_num) + +lemma twopow_mul_eventually (c : ℝ) (hc : 0.trans_eq (mul_comm _ _) + +lemma exp_two_absorb (β n : ℝ) (hx : Real.log 2≤β*n/2) : + Real.exp (-β*n)+Real.exp (-β*n)≤Real.exp (-β*n/2) := by + calc + _ = Real.exp (Real.log 2-β*n) := by rw [Real.exp_sub,Real.exp_log (by norm_num)]; rw [neg_mul,Real.exp_neg]; ring + _ ≤ _ := Real.exp_le_exp.mpr (by linarith) + +end Thorp.DimensionEstimates +namespace Thorp.Specht +open scoped BigOperators Classical +open Filter UnitaryFinite DimensionEstimates + +theorem exponential_dimension_spectral (h : ℝ) (hh : 0 (f x)^a) ≤ (finiteMean f)^a := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hh := (Real.concaveOn_rpow ha ha1).le_map_sum + (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) + (p := f) (fun _ _ => by positivity) + (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) + (fun x _ => hf x) + simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), + ←div_eq_mul_inv,finiteMean] using hh + +noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x + +omit [Nonempty X] in +lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := + Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) + +omit [Nonempty X] in +lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + {b : ℝ} (hb : 1 ≤ b) (y : X) : + (act K f y)^b ≤ act K (fun x => (f x)^b) y := by + simpa only [smul_eq_mul,act] using + (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) + (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) + +lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + {p A : ℝ} (hp : 1 ≤ p) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by + classical + let s : ℝ := ∑ x, f x + have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + by_cases hz : s=0 + · have hfz : ∀ x, f x=0 := by + intro x + exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) + simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, + Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] + · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) + let w : X → ℝ := fun x => f x/s + have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs + have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz + have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by + simp only [act,w,finiteMean,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + have hz' : (∑ x, f x) ≠ 0 := hz + dsimp [s] + field_simp [hz',ne_of_gt hN] + have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by + rw [hact,Real.mul_rpow (mean_nonneg f hf) + (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) + exact (convexOn_rpow hp).map_sum_le + (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) + have hh := finiteMean_mono hj + have he : finiteMean (fun y => (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = + (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by + simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, + finiteMean_sum, mul_comm (w _), finiteMean_mul_const] + rw [he] at hh + apply hh.trans + have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by + calc + _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum + (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) + _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] + simpa only [mul_comm (Real.exp A)] using + mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) + +lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^(b*p)) ≤ + Real.exp A*(finiteMean (fun x => (f x)^b))^p := by + calc + _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by + apply finiteMean_mono + intro y + rw [Real.rpow_mul (act_nonneg K hK f hf y)] + exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) + _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) + +variable [DecidableEq X] + +omit [Nonempty X] in +lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : + ∀ x y, 0 ≤ (K^r) x y := by + classical + induction r with + | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num + | succ r ih => + intro x y + rw [pow_succ,Matrix.mul_apply] + exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) + +omit [Nonempty X] in +lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : + ∀ x, ∑ y, (K^r) x y = 1 := by + classical + induction r with + | zero => intro x; simp [Matrix.one_apply] + | succ r ih => + intro x + simp only [pow_succ,Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hrow,mul_one,ih] + +noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := + (Fintype.card X:ℝ)*(K^r) x y + +omit [Nonempty X] in +lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : + 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) + +omit [Nonempty X] in +lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : + rowDensity K (r+1) x y = act K (rowDensity K r x) y := by + simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] + apply Finset.sum_congr rfl + intro z _ + ring + +lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : + finiteMean (rowDensity K r x) = 1 := by + have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) + simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] + +lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by + induction r with + | zero => simp [rowDensity_mean K hrow] + | succ r ih => + have hpr : 1 ≤ p^r := one_le_pow₀ hp + have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp + simp_rw [rowDensity_succ] + calc + _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by + rw [pow_succ] + exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) + _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) + _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left hps hA + push_cast + nlinarith + +lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by + have hpos : 0 < p^r := by linarith + have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) + (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) + (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) + have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by + rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] + rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] + simp_rw [he] at hj + apply hj.trans + calc + _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := + Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) + (by positivity) + _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] + +lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : + (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z + have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = + finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by + simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro z _ + field_simp + have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ + Real.exp (2*A*r) := by + calc + _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by + apply finiteMean_mono + intro z + nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] + _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ + finiteMean (fun z => (rowDensity K r y z)^2))/2 := by + simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] + _ ≤ _ := by + have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x + have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y + linarith + apply (le_div_iff₀ hN).mpr + simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh + +lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by + calc + (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num + _ ≤ _ := by simpa only [Nat.cast_ofNat] using + (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) + +end Thorp.StrongSmoothing + +namespace Thorp.StrongSmoothing.PermLaw +open scoped BigOperators +variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] + +noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := + fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) + +omit [Fintype X] in +lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by + simp only [kernel,←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype X] in +lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by + ext x y + apply finiteMean_congr + intro ω + have he : (P ω)⁻¹ x=y ↔ P ω y=x := by + change (P ω).symm x=y ↔ P ω y=x + exact (Equiv.symm_apply_eq (P ω)).trans eq_comm + simp only [he] + +lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by + have hh := row (fun ω => (P ω)⁻¹) y + rw [inverse] at hh + exact hh + +lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : + kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by + ext x y + simp only [Matrix.mul_apply,kernel] + have he (ω : Ω × Ω') : + (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = + ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by + simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] + rfl + change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro z _ + exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) + (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) + +omit [Fintype X] in +lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : + kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by + apply finiteMean_congr + intro ω + have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by + change e (P ω (e.symm x))=y ↔ _ + exact (Equiv.eq_symm_apply e).symm + simp only [he] + +end Thorp.StrongSmoothing.PermLaw + +namespace Thorp.StrongSmoothing +open scoped BigOperators + +section MatrixHelpers +variable {X : Type*} [Fintype X] + +lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := + Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) + +lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) + (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hB,mul_one,hA] + +lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) + (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.sum_mul,hA,one_mul,hB] + +lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) + _ = D := by rw [←Finset.sum_mul,hrow,one_mul] + +lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) + (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) + _ = D := by rw [←Finset.mul_sum,hcol,mul_one] + +variable [DecidableEq X] + +lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by + induction r with + | zero => simp + | succ r ih => + calc + _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring + _ = (A*B)^(r+1)*(A*B) := by rw [ih] + _ = _ := (pow_succ (A*B) (r+1)).symm + +end MatrixHelpers + +section TupleAction +variable {ι β Ω : Type*} [Fintype Ω] + +def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where + toFun x := x.trans P.toEmbedding + invFun x := x.trans P.symm.toEmbedding + left_inv x := by ext i; simp + right_inv x := by ext i; simp + +@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : + tuplePerm P x i = P (x i) := rfl + +lemma tuplePerm_mul (P Q : Equiv.Perm β) : + tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by + ext x i + rfl + +lemma tuplePerm_inverse (P : Equiv.Perm β) : + tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by + ext x i + rfl + +variable [Fintype ι] [DecidableEq β] + +lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : + PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by + classical + apply finiteMean_congr + intro ω + have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun z : ι ↪ β => z i) h + simp only [he] +end TupleAction + +lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : + sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by + ext x y + exact tupleProbability_kernel _ x y + +lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + reflectedKernel d l order false x y = + PairRouting.tupleProbability (palindromePerm d) + ((tuplePerm (coordinateRelabel d order)).symm x) + ((tuplePerm (coordinateRelabel d order)).symm y) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) + have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by + rw [sweepKernel_law] + simp only [sweep,tuplePerm_mul,tuplePerm_inverse] + rfl + rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] + rw [←PermLaw.inverse,←PermLaw.mul] + have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = + fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by + funext ω + simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] + change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ + group + rw [hprod,PermLaw.conjugate,tupleProbability_kernel] + + +lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ + +lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.row _ _ + +lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.col _ _ + +lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ reflectedKernel d l order false x y := by + exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_nonneg d l order) x y + +lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, reflectedKernel d l order false x y = 1 := + mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x + +lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, reflectedKernel d l order false x y = 1 := + mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y + +lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : + (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ + +lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ + Real.exp (l*(1+heightDecay 1)) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + simp_rw [reflectedKernel_conjugate] + have he := finiteMean_equiv e (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ + (1+(1/1000:ℝ))) + change finiteMean (fun y => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ + (1+(1/1000:ℝ))) ≤ _ + rw [←he] + simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) + +lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by + simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] + +lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + ((reflectedKernel d l order false)^2000) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + let : Nonempty (Tuples d l) := ⟨x⟩ + have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) + (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) + (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) + (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) + (reflected_moment d l order) 1000 density_exponent_numeric x y + have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring + norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh + simpa only [he,tuples_card] using hh + +lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) + (x y : Tuples d l) : + ((reflectedKernel d l order orientation)^2001) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + cases orientation + · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ + rw [pow_succ] + exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) + (canonical_pointwise d l order) x y + · let A := sweepKernel d l order + change ((A*A.transpose)^(2000+1)) x y ≤ _ + rw [←sandwich_power] + apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_row d l order) + exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) + (canonical_pointwise d l order) + +end Thorp.StrongSmoothing + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/TypedSet.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/TypedSet.lean index 2ba0f83aa32473dec93615b4eb94fc1e50034e31..a91fc6bfb6353e095747d39edd1bb72feaad7b7f 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/TypedSet.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/TypedSet.lean @@ -1,871 +1,871 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.PairAssembleEquiv - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - let root (S : I) := (small_dominating_subset G S.val S.property.2).choose - have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ - S.val \ root S ⊆ neighborhood G (root S) := by - simpa only [root, S.property.1] using - (small_dominating_subset G S.val S.property.2).choose_spec - let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) - have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := - Finset.union_sdiff_of_subset (hroot S).1 - have hinj : Function.Injective enc := by - intro S T h - apply Subtype.ext - rw [← hrec S, ← hrec T, h] - let W (z : Finset V × Finset V) : ℝ := - if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) - then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 - have hW (z : Finset V × Finset V) : 0 ≤ W z := by - dsimp [W] - split_ifs - · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) - (Finset.prod_nonneg (fun v _ => hp v)) - · exact le_rfl - have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by - have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by - refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ - change (S.val \ root S).card = k-(root S).card - rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] - dsimp only [W] - rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] - exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) - have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by - calc - _ = ∑ z ∈ Finset.univ.image enc, W z := by - rw [Finset.sum_image (fun S _ T _ h => hinj h)] - exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun z _ _ => hW z) - apply hsum.trans - rw [Fintype.sum_prod_type] - calc - (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ - ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by - apply Finset.sum_le_sum - intro R _ - by_cases hR : 2*R.card ≤ k - · have he : (∑ L : Finset V, W (R,L)) = - (∏ v ∈ R, p v) * - ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by - simp only [W, hR, true_and] - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] - rw [he] - have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) - (Finset.prod_nonneg (s := R) (fun v _ => hp v)) - simpa only [mul_comm, mul_left_comm, mul_assoc] using h - · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] - exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) - (Finset.prod_nonneg (fun v _ => hp v)) - _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro R _ - rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] - simp only [mul_one, mul_assoc] - _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) - simpa only [Finset.powerset_univ] using - powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) - (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) - _ = _ := by rw [← Finset.mul_sum] - - -lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] - (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) - (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) - (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) - (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - calc - _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by - apply finiteMean_mono - intro ω - split_ifs with h - · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) - (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) - · positivity - _ = ∑ S : I, inclusionMoment O S.val := by - rw [finiteMean_sum] - rfl - _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) - _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg - -noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : Finset (N × X) := by - classical - exact Finset.univ.filter (fun v => v.2 ∈ A v.1) - -@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by - classical - simp [typedSet] - -noncomputable def fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) : Finset X := by - classical - exact Finset.univ.filter (fun x => (t,x) ∈ S) - -@[simp] lemma mem_fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by - classical - simp [fiber] - -lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] - (S : Finset (N × X)) : typedSet (fiber S) = S := by - classical - ext v - simp - -lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (p : N × X → ℝ) : - (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by - classical - simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] - apply Finset.prod_congr rfl - intro t _ - rw [← Finset.prod_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by - classical - simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (D : Finset (N × X)) : - D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by - constructor - · intro h t x hx - exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) - · intro h v hv - exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) - -noncomputable def typedMarks {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : Finset (N × Card d) := - typedSet (fun t => butterflyMarks d (A t) (ω t)) - -lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : - (typedMarks d A ω).card = ∑ t, (A t).card := by - classical - rw [typedMarks, typedSet_card] - apply Finset.sum_congr rfl - intro t _ - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective - -lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (D : Finset (N × Card d)) : - inclusionMoment (typedMarks d A) D ≤ - ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by - classical - have he : inclusionMoment (typedMarks d A) D = - ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by - rw [inclusionMoment_eq] - have hh (ω : N → (SwitchIndex d → Bool)) : - (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = - ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by - rw [Fintype.prod_boole] - simp only [typedMarks, subset_typedSet] - rw [finiteMean_congr hh] - simp only [inclusionMoment_eq] - exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) - (fun t (ω : SwitchIndex d → Bool) => - if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) - have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = - ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by - conv_lhs => rw [← typedSet_fiber D] - exact typedSet_prod _ _ - rw [he, hprod] - apply Finset.prod_le_prod₀ - · intro t _; exact inclusionMoment_nonneg _ _ - · intro t _ - simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) - -noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (v : N × Card d) : Finset (SwitchIndex d) := - routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 - -noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : - SimpleGraph (N × Card d) where - Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) - symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ - loopless := ⟨fun _ h => h.1 rfl⟩ - -lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : - (returnRoute d b v).card = d := card_routeDomain _ _ _ - -lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (t : N) (y : Card d) (i : SwitchIndex d) : - i ∈ returnRoute d b (t,y) ↔ - y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by - have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i - simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h - -lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (i : SwitchIndex d) : - (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = - 2 * ∑ t, p t := by - classical - rw [Fintype.sum_prod_type, Finset.mul_sum] - apply Finset.sum_congr rfl - intro t _ - have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ - butterflyPerm d (b t) (switchUsers d (b t) i).2 := - (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) - simp only [mem_returnRoute] - have he (y : Card d) : - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by - split_ifs <;> simp_all - simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] - ring - -lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : - (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ - 2*d*∑ t, p t := by - classical - calc - _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by - apply Finset.sum_le_sum - intro w _ - split_ifs with h - · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 - have hh := Finset.single_le_sum - (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) - (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi - simpa only [ite_eq_left hw] using hh - · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) - _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := - Finset.sum_comm - _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, - nsmul_eq_mul]; ring - -lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) : - (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, - Nat.cast_ofNat, nsmul_eq_mul] - field_simp - -lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) - (hk : ∑ t, (A t).card = k) - (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : N → (SwitchIndex d → Bool) => - if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by - have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk - have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k - (fun ω => (typedMarks_card d A ω).trans hk) - (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) - (typedMarks_inclusion d A) _ hδ hδ1 - (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) - (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) - simpa only [typed_weight_sum, hs] using hm - - -lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) - (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : - finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = - finiteMean f / (2:ℝ)^s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 - have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] - have he (ω : ι → Bool) : - (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = - (if ω i = v i then g ω else 0) := by - by_cases h : ω i = v i <;> simp [h,g] - rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] - have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) - change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ - rw [hs, Finset.card_insert_of_notMem hi, pow_succ] - ring - -noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := by - classical - exact finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) - -lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ endpointProb d A x y := by - classical - exact finiteMean_nonneg (fun _ => by positivity) - -lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by - classical - let f := fun ω : SwitchIndex d → Bool => - if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 - have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by - intro t ht ω - have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ - ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by - apply forall₂_congr - intro j hj - rw [butterfly_endpoint_iff, butterfly_endpoint_iff] - apply forall₂_congr - intro s hs - rw [QueryTree.flipCoin_apply_ne t s (fun h => - Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] - simp only [f, he] - have he (ω : SwitchIndex d → Bool) : - (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = - (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by - by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i - · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h - rw [ite_eq_left hh] - simp only [Finset.forall_mem_insert, h, true_and, f] - · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h - simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] - change finiteMean _ = _ - rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] - rfl - -noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := - ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y - -lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) (hi : i ∉ A) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - partialKernel d (insert i A) x y = partialKernel d A x y := by - classical - rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, - Finset.card_insert_of_notMem hi, pow_succ, partialKernel] - field_simp - -def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := - ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) - -lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) - (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : - (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by - classical - have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ - rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] - · rw [← Finset.sum_add_distrib] - apply Finset.sum_eq_zero - intro A hA - have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ - ((Finset.mem_powerset.mp hA) hh) - rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] - ring - · exact Finset.notMem_erase _ _ - -lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) - (x y : L → Card d) (h : ¬ContactEvent d x y) : - (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by - classical - unfold ContactEvent at h - push Not at h - obtain ⟨i, hi⟩ := h - apply alternating_cube_cancel _ i - intro A hiA - apply partialKernel_insert_isolated d A x y i hiA - intro j hj - exact hi j (fun hij => hiA (hij ▸ hj)) - - -noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by - classical - exact if i ∈ A then none else some i - -noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := - fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) - -noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := - fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) - -noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by - classical - exact fun t => match t with - | none => A - | some i => if i ∈ A then ∅ else {i} - -lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : - i ∈ labelsOf A t ↔ networkOf A i = t := by - classical - cases t with - | none => simp [labelsOf, networkOf] - | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction - -lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : - mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, - butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by - constructor - · intro h t i hi - have he := congrFun h i - simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he - · intro h - funext i - exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) - -lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : - mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by - constructor - · intro h - funext i - exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm - · intro h - funext i - exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm - -lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : - endpointProb d {i} x y = 1/(2:ℝ)^d := by - classical - simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) - -lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by - classical - have he (ω : Option L → (SwitchIndex d → Bool)) : - (if mixedTuple d A ω x = y then (1:ℝ) else 0) = - ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i - then (1:ℝ) else 0 := by - simp only [Fintype.prod_boole, mixedTuple_eq_iff] - rw [finiteMean_congr he] - rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] - have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = - endpointProb d (labelsOf A t) x y := by - unfold endpointProb - apply finiteMean_congr - intro w - split_ifs <;> rfl - simp only [hfac] - rw [Fintype.prod_option] - have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = - if i ∈ A then 1 else 1/(2:ℝ)^d := by - by_cases h : i ∈ A - · simp [labelsOf, h, endpointProb, finiteMean_const] - · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] - rw [show labelsOf A none = A from rfl] - simp only [hi] - have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = - (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by - rw [Finset.prod_ite] - simp only [Finset.prod_const_one, one_mul] - simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, - Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] - rw [hp, partialKernel, one_div, inv_pow] - have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ - have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = - ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] - have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity - have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity - field_simp - rw [← hn] - ring - -lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y z : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by - simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y - -noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (t : Option L) : Finset (Card d) := by - classical - exact (labelsOf A t).image x - -lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : - typedMarks d (mixedInitial d A x) ω = Finset.univ.image - (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - classical - ext v - simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, - Finset.mem_image, Finset.mem_univ, true_and] - constructor - · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ - have ht := mem_labelsOf A i v.1 |>.mp hi - exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ - · rintro ⟨i, hi⟩ - have ht := congrArg Prod.fst hi - have hv := congrArg Prod.snd hi - change networkOf A i = v.1 at ht - change mixedTuple d A ω x i = v.2 at hv - exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, - by simpa only [mixedTuple, ht] using hv⟩ - -lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω : Option L → (SwitchIndex d → Bool)) : - Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - intro i j h - have ht := congrArg Prod.fst h - have hv := congrArg Prod.snd h - change networkOf A i = networkOf A j at ht - dsimp only [mixedTuple] at hv - rw [ht] at hv - exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) - -lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) : - (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by - classical - let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false - rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, - Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] - -lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω b : Option L → (SwitchIndex d → Bool)) : - ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ - NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) - (typedMarks d (mixedInitial d A x) ω) := by - classical - rw [typedMarks_mixedInitial] - let f := fun i => (networkOf A i, mixedTuple d A ω x i) - have hf : Function.Injective f := typedTuple_injective d A x hx ω - constructor - · intro h v hv - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv - obtain ⟨j,hij,hc⟩ := h i - exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, - hf.ne hij, hc⟩ - · intro h i - obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv - exact ⟨j, fun he => hij (congrArg f he), hc⟩ - -lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (b : Option L → (SwitchIndex d → Bool)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) - then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - simp only [contactEvent_mixedReturn_iff d A x hx] - convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) - (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 - congr 1 - exact Subsingleton.elim _ _ - - -lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] - (g : Ω → X) (f : X → ℝ) : - finiteMean (fun ω => f (g ω)) = - ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by - classical - simp_rw [← finiteMean_mul_const, ← finiteMean_sum] - apply finiteMean_congr - intro ω - simp - -lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = - ∑ y, partialKernel d A x y * f y := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] - apply Finset.sum_congr rfl - intro y _ - congr 1 - convert mixedTuple_mass d A x y using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = - ∑ z, partialKernel d A z y * f z := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] - apply Finset.sum_congr rfl - intro z _ - congr 1 - convert mixedReturn_mass d A y z using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ partialKernel d A x y := - mul_nonneg (by positivity) (endpointProb_nonneg d A x y) - -noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : ℝ := by - classical - exact if ContactEvent d x y then partialKernel d A x y else 0 - -lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact partialKernel_nonneg d A x y - · exact le_rfl - -lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact le_rfl - · exact partialKernel_nonneg d A x y - -lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 - have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ - ∑ z : L → Card d, partialKernel d A z y * f y z := by - have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by - unfold retainedKernel f - split_ifs <;> ring - simp_rw [he] - rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) - (Function.Embedding.coe_injective.injOn)] - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro z _ _ - exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) - calc - _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by - rw [Finset.sum_comm] - simp only [Finset.mul_sum] - _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by - apply Finset.sum_le_sum - intro y _ - exact mul_le_mul (retainedKernel_le d A x y) (hsub y) - (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) - _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by - rw [mixedTuple_expectation d A x (fun y => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] - simp only [mixedReturn_expectation] - _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ - _ ≤ _ := by - apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq - exact finiteMean_const _ - -noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := - LinearMap.toContinuousLinearMap - { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - map_add' := by - intro v w - ext x - simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] - map_smul' := by - intro c v - ext x - simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] - change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - ring } - -@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : - rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl - -lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = - rectOperator (fun y x => P x y) := by - apply Eq.symm - rw [ContinuousLinearMap.eq_adjoint_iff] - intro v w - simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, - map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = - rectOperator (fun x x' => ∑ y, P x y * P x' y) := by - ext v x - simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, - Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x' _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) - (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : - ‖rectOperator P‖^2 ≤ B := by - let S := fun x x' => ∑ y, P x y * P x' y - have hs : ∀ x x', S x x' = S x' x := by - intro x x' - unfold S - apply Finset.sum_congr rfl - intro y _ - ring - have hbound : ‖rectOperator S‖ ≤ B := by - apply ContinuousLinearMap.opNorm_le_bound _ hB - intro v - exact DensityTransfer.schur_bound S - (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB - hrow (fun x' => by - calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') - _ ≤ B := hrow x') v - have hn := ContinuousLinearMap.norm_adjoint_comp_self - (ContinuousLinearMap.adjoint (rectOperator P)) - rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), - rectOperator_adjoint, rectOperator_comp_transpose] at hn - rw [pow_two, ← hn] - exact hbound - -lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖rectOperator (retainedKernel d A)‖^2 ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := - rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) - (fun x => retained_square_row d A x hδ hδ1) - - -section Orbit -variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] - [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) - (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) - -noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w - -include hw in -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by - apply ext_inner_right ℂ - intro v - exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g - -include hw in -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma orbitVector_action (g : G) (x : X) : - orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by - obtain ⟨h,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, - orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] -end Orbit - -def IsHarmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := - ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, - (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 - -lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) - (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) - (w : Specht.hilbertSpace μ) - (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) - (v : Specht.hilbertSpace μ) : - IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by - classical - intro A hA z - let ρ := Specht.relabelledUnitary μ e - let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w - let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 - have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by - apply (Finset.card_image_le).trans_lt - rw [← hk] - exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) - have hz : S = 0 := by - apply point_relabelled_fixed_zero μ e (A.image z) hcard - intro p hp - change ρ p S = S - simp only [S, map_sum, apply_ite, map_zero] - apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) - intro y - have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by - apply forall₂_congr - intro i hi - have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) - change p (y i) = z i ↔ y i = z i - exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff - simp only [he] - split_ifs - · exact (orbitVector_action UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm - · rfl - let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) - calc - _ = c * inner ℂ S v := by - dsimp only [S] - rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, - smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] - _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] - -end Thorp.SparseContact - - -end ThorpNine.Harmonic - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Harmonic.PairAssembleEquiv + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + let root (S : I) := (small_dominating_subset G S.val S.property.2).choose + have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ + S.val \ root S ⊆ neighborhood G (root S) := by + simpa only [root, S.property.1] using + (small_dominating_subset G S.val S.property.2).choose_spec + let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) + have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := + Finset.union_sdiff_of_subset (hroot S).1 + have hinj : Function.Injective enc := by + intro S T h + apply Subtype.ext + rw [← hrec S, ← hrec T, h] + let W (z : Finset V × Finset V) : ℝ := + if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) + then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 + have hW (z : Finset V × Finset V) : 0 ≤ W z := by + dsimp [W] + split_ifs + · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) + (Finset.prod_nonneg (fun v _ => hp v)) + · exact le_rfl + have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by + have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by + refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ + change (S.val \ root S).card = k-(root S).card + rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] + dsimp only [W] + rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] + exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) + have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by + calc + _ = ∑ z ∈ Finset.univ.image enc, W z := by + rw [Finset.sum_image (fun S _ T _ h => hinj h)] + exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun z _ _ => hW z) + apply hsum.trans + rw [Fintype.sum_prod_type] + calc + (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ + ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by + apply Finset.sum_le_sum + intro R _ + by_cases hR : 2*R.card ≤ k + · have he : (∑ L : Finset V, W (R,L)) = + (∏ v ∈ R, p v) * + ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by + simp only [W, hR, true_and] + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] + rw [he] + have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) + (Finset.prod_nonneg (s := R) (fun v _ => hp v)) + simpa only [mul_comm, mul_left_comm, mul_assoc] using h + · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] + exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) + (Finset.prod_nonneg (fun v _ => hp v)) + _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro R _ + rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] + simp only [mul_one, mul_assoc] + _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) + simpa only [Finset.powerset_univ] using + powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) + (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) + _ = _ := by rw [← Finset.mul_sum] + + +lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] + (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) + (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) + (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) + (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + calc + _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by + apply finiteMean_mono + intro ω + split_ifs with h + · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) + (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) + · positivity + _ = ∑ S : I, inclusionMoment O S.val := by + rw [finiteMean_sum] + rfl + _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) + _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg + +noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : Finset (N × X) := by + classical + exact Finset.univ.filter (fun v => v.2 ∈ A v.1) + +@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by + classical + simp [typedSet] + +noncomputable def fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) : Finset X := by + classical + exact Finset.univ.filter (fun x => (t,x) ∈ S) + +@[simp] lemma mem_fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by + classical + simp [fiber] + +lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] + (S : Finset (N × X)) : typedSet (fiber S) = S := by + classical + ext v + simp + +lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (p : N × X → ℝ) : + (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by + classical + simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] + apply Finset.prod_congr rfl + intro t _ + rw [← Finset.prod_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by + classical + simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (D : Finset (N × X)) : + D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by + constructor + · intro h t x hx + exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) + · intro h v hv + exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) + +noncomputable def typedMarks {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : Finset (N × Card d) := + typedSet (fun t => butterflyMarks d (A t) (ω t)) + +lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : + (typedMarks d A ω).card = ∑ t, (A t).card := by + classical + rw [typedMarks, typedSet_card] + apply Finset.sum_congr rfl + intro t _ + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective + +lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (D : Finset (N × Card d)) : + inclusionMoment (typedMarks d A) D ≤ + ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by + classical + have he : inclusionMoment (typedMarks d A) D = + ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by + rw [inclusionMoment_eq] + have hh (ω : N → (SwitchIndex d → Bool)) : + (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = + ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by + rw [Fintype.prod_boole] + simp only [typedMarks, subset_typedSet] + rw [finiteMean_congr hh] + simp only [inclusionMoment_eq] + exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) + (fun t (ω : SwitchIndex d → Bool) => + if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) + have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = + ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by + conv_lhs => rw [← typedSet_fiber D] + exact typedSet_prod _ _ + rw [he, hprod] + apply Finset.prod_le_prod₀ + · intro t _; exact inclusionMoment_nonneg _ _ + · intro t _ + simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) + +noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (v : N × Card d) : Finset (SwitchIndex d) := + routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 + +noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : + SimpleGraph (N × Card d) where + Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) + symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ + loopless := ⟨fun _ h => h.1 rfl⟩ + +lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : + (returnRoute d b v).card = d := card_routeDomain _ _ _ + +lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (t : N) (y : Card d) (i : SwitchIndex d) : + i ∈ returnRoute d b (t,y) ↔ + y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by + have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i + simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h + +lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (i : SwitchIndex d) : + (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = + 2 * ∑ t, p t := by + classical + rw [Fintype.sum_prod_type, Finset.mul_sum] + apply Finset.sum_congr rfl + intro t _ + have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ + butterflyPerm d (b t) (switchUsers d (b t) i).2 := + (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) + simp only [mem_returnRoute] + have he (y : Card d) : + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by + split_ifs <;> simp_all + simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + ring + +lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : + (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ + 2*d*∑ t, p t := by + classical + calc + _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by + apply Finset.sum_le_sum + intro w _ + split_ifs with h + · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 + have hh := Finset.single_le_sum + (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) + (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi + simpa only [ite_eq_left hw] using hh + · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) + _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := + Finset.sum_comm + _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, + nsmul_eq_mul]; ring + +lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) : + (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, + Nat.cast_ofNat, nsmul_eq_mul] + field_simp + +lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) + (hk : ∑ t, (A t).card = k) + (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : N → (SwitchIndex d → Bool) => + if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by + have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk + have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k + (fun ω => (typedMarks_card d A ω).trans hk) + (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) + (typedMarks_inclusion d A) _ hδ hδ1 + (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) + (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) + simpa only [typed_weight_sum, hs] using hm + + +lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) + (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : + finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = + finiteMean f / (2:ℝ)^s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 + have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] + have he (ω : ι → Bool) : + (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = + (if ω i = v i then g ω else 0) := by + by_cases h : ω i = v i <;> simp [h,g] + rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] + have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) + change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ + rw [hs, Finset.card_insert_of_notMem hi, pow_succ] + ring + +noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := by + classical + exact finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) + +lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ endpointProb d A x y := by + classical + exact finiteMean_nonneg (fun _ => by positivity) + +lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by + classical + let f := fun ω : SwitchIndex d → Bool => + if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 + have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by + intro t ht ω + have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ + ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by + apply forall₂_congr + intro j hj + rw [butterfly_endpoint_iff, butterfly_endpoint_iff] + apply forall₂_congr + intro s hs + rw [QueryTree.flipCoin_apply_ne t s (fun h => + Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] + simp only [f, he] + have he (ω : SwitchIndex d → Bool) : + (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = + (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by + by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i + · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h + rw [ite_eq_left hh] + simp only [Finset.forall_mem_insert, h, true_and, f] + · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h + simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] + change finiteMean _ = _ + rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] + rfl + +noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := + ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y + +lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) (hi : i ∉ A) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + partialKernel d (insert i A) x y = partialKernel d A x y := by + classical + rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, + Finset.card_insert_of_notMem hi, pow_succ, partialKernel] + field_simp + +def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := + ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) + +lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) + (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : + (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by + classical + have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ + rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] + · rw [← Finset.sum_add_distrib] + apply Finset.sum_eq_zero + intro A hA + have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ + ((Finset.mem_powerset.mp hA) hh) + rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] + ring + · exact Finset.notMem_erase _ _ + +lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) + (x y : L → Card d) (h : ¬ContactEvent d x y) : + (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by + classical + unfold ContactEvent at h + push Not at h + obtain ⟨i, hi⟩ := h + apply alternating_cube_cancel _ i + intro A hiA + apply partialKernel_insert_isolated d A x y i hiA + intro j hj + exact hi j (fun hij => hiA (hij ▸ hj)) + + +noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by + classical + exact if i ∈ A then none else some i + +noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := + fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) + +noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := + fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) + +noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by + classical + exact fun t => match t with + | none => A + | some i => if i ∈ A then ∅ else {i} + +lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : + i ∈ labelsOf A t ↔ networkOf A i = t := by + classical + cases t with + | none => simp [labelsOf, networkOf] + | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction + +lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : + mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, + butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by + constructor + · intro h t i hi + have he := congrFun h i + simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he + · intro h + funext i + exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) + +lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : + mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by + constructor + · intro h + funext i + exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm + · intro h + funext i + exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm + +lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : + endpointProb d {i} x y = 1/(2:ℝ)^d := by + classical + simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) + +lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by + classical + have he (ω : Option L → (SwitchIndex d → Bool)) : + (if mixedTuple d A ω x = y then (1:ℝ) else 0) = + ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i + then (1:ℝ) else 0 := by + simp only [Fintype.prod_boole, mixedTuple_eq_iff] + rw [finiteMean_congr he] + rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] + have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = + endpointProb d (labelsOf A t) x y := by + unfold endpointProb + apply finiteMean_congr + intro w + split_ifs <;> rfl + simp only [hfac] + rw [Fintype.prod_option] + have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = + if i ∈ A then 1 else 1/(2:ℝ)^d := by + by_cases h : i ∈ A + · simp [labelsOf, h, endpointProb, finiteMean_const] + · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] + rw [show labelsOf A none = A from rfl] + simp only [hi] + have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = + (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by + rw [Finset.prod_ite] + simp only [Finset.prod_const_one, one_mul] + simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, + Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] + rw [hp, partialKernel, one_div, inv_pow] + have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ + have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = + ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] + have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity + have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity + field_simp + rw [← hn] + ring + +lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y z : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by + simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y + +noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (t : Option L) : Finset (Card d) := by + classical + exact (labelsOf A t).image x + +lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : + typedMarks d (mixedInitial d A x) ω = Finset.univ.image + (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + classical + ext v + simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, + Finset.mem_image, Finset.mem_univ, true_and] + constructor + · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ + have ht := mem_labelsOf A i v.1 |>.mp hi + exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ + · rintro ⟨i, hi⟩ + have ht := congrArg Prod.fst hi + have hv := congrArg Prod.snd hi + change networkOf A i = v.1 at ht + change mixedTuple d A ω x i = v.2 at hv + exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, + by simpa only [mixedTuple, ht] using hv⟩ + +lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω : Option L → (SwitchIndex d → Bool)) : + Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + intro i j h + have ht := congrArg Prod.fst h + have hv := congrArg Prod.snd h + change networkOf A i = networkOf A j at ht + dsimp only [mixedTuple] at hv + rw [ht] at hv + exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) + +lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) : + (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by + classical + let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false + rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, + Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] + +lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω b : Option L → (SwitchIndex d → Bool)) : + ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ + NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) + (typedMarks d (mixedInitial d A x) ω) := by + classical + rw [typedMarks_mixedInitial] + let f := fun i => (networkOf A i, mixedTuple d A ω x i) + have hf : Function.Injective f := typedTuple_injective d A x hx ω + constructor + · intro h v hv + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv + obtain ⟨j,hij,hc⟩ := h i + exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, + hf.ne hij, hc⟩ + · intro h i + obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv + exact ⟨j, fun he => hij (congrArg f he), hc⟩ + +lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (b : Option L → (SwitchIndex d → Bool)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) + then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + simp only [contactEvent_mixedReturn_iff d A x hx] + convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) + (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 + congr 1 + exact Subsingleton.elim _ _ + + +lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] + (g : Ω → X) (f : X → ℝ) : + finiteMean (fun ω => f (g ω)) = + ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by + classical + simp_rw [← finiteMean_mul_const, ← finiteMean_sum] + apply finiteMean_congr + intro ω + simp + +lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = + ∑ y, partialKernel d A x y * f y := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] + apply Finset.sum_congr rfl + intro y _ + congr 1 + convert mixedTuple_mass d A x y using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = + ∑ z, partialKernel d A z y * f z := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] + apply Finset.sum_congr rfl + intro z _ + congr 1 + convert mixedReturn_mass d A y z using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ partialKernel d A x y := + mul_nonneg (by positivity) (endpointProb_nonneg d A x y) + +noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : ℝ := by + classical + exact if ContactEvent d x y then partialKernel d A x y else 0 + +lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact partialKernel_nonneg d A x y + · exact le_rfl + +lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact le_rfl + · exact partialKernel_nonneg d A x y + +lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 + have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ + ∑ z : L → Card d, partialKernel d A z y * f y z := by + have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by + unfold retainedKernel f + split_ifs <;> ring + simp_rw [he] + rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) + (Function.Embedding.coe_injective.injOn)] + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro z _ _ + exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) + calc + _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul (retainedKernel_le d A x y) (hsub y) + (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) + _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by + rw [mixedTuple_expectation d A x (fun y => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] + simp only [mixedReturn_expectation] + _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ + _ ≤ _ := by + apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq + exact finiteMean_const _ + +noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := + LinearMap.toContinuousLinearMap + { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + map_add' := by + intro v w + ext x + simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] + map_smul' := by + intro c v + ext x + simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] + change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + ring } + +@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : + rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl + +lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = + rectOperator (fun y x => P x y) := by + apply Eq.symm + rw [ContinuousLinearMap.eq_adjoint_iff] + intro v w + simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, + map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = + rectOperator (fun x x' => ∑ y, P x y * P x' y) := by + ext v x + simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, + Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x' _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) + (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : + ‖rectOperator P‖^2 ≤ B := by + let S := fun x x' => ∑ y, P x y * P x' y + have hs : ∀ x x', S x x' = S x' x := by + intro x x' + unfold S + apply Finset.sum_congr rfl + intro y _ + ring + have hbound : ‖rectOperator S‖ ≤ B := by + apply ContinuousLinearMap.opNorm_le_bound _ hB + intro v + exact DensityTransfer.schur_bound S + (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB + hrow (fun x' => by + calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') + _ ≤ B := hrow x') v + have hn := ContinuousLinearMap.norm_adjoint_comp_self + (ContinuousLinearMap.adjoint (rectOperator P)) + rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), + rectOperator_adjoint, rectOperator_comp_transpose] at hn + rw [pow_two, ← hn] + exact hbound + +lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖rectOperator (retainedKernel d A)‖^2 ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := + rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) + (fun x => retained_square_row d A x hδ hδ1) + + +section Orbit +variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] + [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) + (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) + +noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w + +include hw in +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by + apply ext_inner_right ℂ + intro v + exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g + +include hw in +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma orbitVector_action (g : G) (x : X) : + orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by + obtain ⟨h,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, + orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] +end Orbit + +def IsHarmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := + ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, + (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 + +lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) + (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) + (w : Specht.hilbertSpace μ) + (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) + (v : Specht.hilbertSpace μ) : + IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by + classical + intro A hA z + let ρ := Specht.relabelledUnitary μ e + let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w + let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 + have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by + apply (Finset.card_image_le).trans_lt + rw [← hk] + exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) + have hz : S = 0 := by + apply point_relabelled_fixed_zero μ e (A.image z) hcard + intro p hp + change ρ p S = S + simp only [S, map_sum, apply_ite, map_zero] + apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) + intro y + have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by + apply forall₂_congr + intro i hi + have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) + change p (y i) = z i ↔ y i = z i + exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff + simp only [he] + split_ifs + · exact (orbitVector_action UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm + · rfl + let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) + calc + _ = c * inner ℂ S v := by + dsimp only [S] + rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, + smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] + _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] + +end Thorp.SparseContact + + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Harmonic/ZeroExtend.lean b/lean/OAI/Probability/ThorpRouting/Harmonic/ZeroExtend.lean index 38b783ec87521a596f0de716906a9cfc6d9b3cef..b169d3050cb89541b97ce5a30198e61e8c91f15c 100644 --- a/lean/OAI/Probability/ThorpRouting/Harmonic/ZeroExtend.lean +++ b/lean/OAI/Probability/ThorpRouting/Harmonic/ZeroExtend.lean @@ -1,871 +1,871 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Harmonic.TypedSet - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.SparseContact - -section -open scoped BigOperators Classical - -lemma sum_injections {L α M : Type*} [Fintype L] [Fintype α] [AddCommMonoid M] - (F : (L → α) → M) (hF : ∀ y, ¬Function.Injective y → F y = 0) : - (∑ y : L → α, F y) = ∑ y : L ↪ α, F y := by - classical - rw [← Finset.sum_image Function.Embedding.coe_injective.injOn] - apply Eq.symm - apply Finset.sum_subset (Finset.subset_univ _) - intro y _ hy - apply hF y - intro h - exact hy (Finset.mem_image.mpr ⟨⟨y,h⟩, Finset.mem_univ _, rfl⟩) - -noncomputable def zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : EuclideanSpace ℂ (L → α) := by - classical - exact WithLp.toLp 2 (fun y => if h : Function.Injective y then f ⟨y,h⟩ else 0) - -@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] - congr 1 - -lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] - -lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : - (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by - rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] - simp only [zeroExtend_inj] - -lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by - have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by - rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, - sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] - simp only [zeroExtend_inj] - nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] - -lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : - rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 - simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, - Complex.ofReal_sum, Complex.ofReal_natCast] - simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] - rw [mul_eq_zero] - right - simp only [Finset.sum_mul] - rw [Finset.sum_comm] - apply mul_eq_zero_of_right - apply Finset.sum_eq_zero - intro ω _ - calc - _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * - (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := - by - apply Finset.sum_congr rfl - intro y _ - have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ - (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := - forall₂_congr fun _ _ => eq_comm - by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i - · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] - · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] - _ = 0 := by - rw [← Finset.mul_sum] - apply mul_eq_zero_of_right - convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> rfl - -lemma partial_full_action {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) : - rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d Finset.univ x y) (zeroExtend f) = - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - apply Finset.sum_congr rfl - intro y _ - congr 2 - simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), - one_mul, endpointProb, UnitaryFinite.actionKernel] - apply finiteMean_congr - intro ω - congr 1 - simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] - rfl - -lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) - (x : L ↪ Card d) (y : L → Card d) : - (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = - ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by - classical - by_cases h : ContactEvent d x y - · simp only [retainedKernel, ite_eq_left h] - · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] - exact (alternating_kernel_cancel d x y h).symm - -lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : - (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = - ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - calc - _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by - ext x - simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] - rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] - apply Finset.sum_congr rfl - intro y _ - simp_rw [← mul_assoc, ← Finset.sum_mul] - congr 1 - have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) - simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, - Complex.ofReal_one] using he - _ = ((-1:ℂ)^(Fintype.card L)) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by - rw [Finset.sum_eq_single (Finset.univ : Finset L)] - · simp only [Finset.card_univ] - · intro A _ hA - rw [partial_proper_zero d A hA f hf, smul_zero] - · simp - _ = _ := by rw [partial_full_action] - -lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by - classical - let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) - have hB : 0 ≤ B := by dsimp [B]; positivity - have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by - have hh := retained_norm_sq d A hδ hδ1 - have hs := Real.sq_sqrt hB - have hn := Real.sqrt_nonneg B - nlinarith - calc - _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by - rw [alternating_harmonic_action d f hf] - _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := - norm_sum_le _ _ - _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by - apply Finset.sum_le_sum - intro A _ - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := - ContinuousLinearMap.le_opNorm _ _ - _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) - _ = _ := by rw [norm_zeroExtend] - _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, - Nat.cast_pow, Nat.cast_ofNat]; ring - -lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) - (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by - classical - obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL - have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by - ext v x - have hh (y : L → Card d) : ¬ContactEvent d x y := by - intro h - obtain ⟨j,hj,_⟩ := h i - exact hj (hi j).symm - simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, - zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] - have he := alternating_harmonic_action d f hf - simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, - neg_smul, one_smul] at he - exact neg_eq_zero.mp he.symm - -end -open scoped BigOperators - -def MainStatement : Prop := - ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ - ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), - let k := μ.card - μ.rowLen 0 - 1 ≤ k → k < 2^d → ∀ reverse : Bool, - ‖sweepOperator d μ e reverse‖^2 ≤ - min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ - (k = 1 → sweepOperator d μ e reverse = 0) ∧ - ‖sweepOperator d μ e reverse‖^2 ≤ - C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - -end Thorp.SparseContact - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) - (hL : Fintype.card L = μ.card - μ.rowLen 0) : - ∃ w : Specht.hilbertSpace μ, - UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by - let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) - have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by - rw [Specht.finrank_hilbertSpace] - exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) - have hdim := Specht.relabelled_tuple_dimension μ e x₀ - rw [hL, Nat.choose_self, mul_one] at hdim - have hm : 0 < Module.finrank ℂ K := by - by_contra h - have hz : Module.finrank ℂ K = 0 := by omega - change _ ≤ Module.finrank ℂ K * _ at hdim - rw [hz, zero_mul] at hdim - omega - let B := stdOrthonormalBasis ℂ K - let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ - exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ - -lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by - cases rev - · rfl - · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] - rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), - ContinuousLinearMap.adjoint.norm_map] - -lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ 1 := - UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ - -section Generic -variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] - -lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) := by - rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), - ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_bound d _ (hh v) hδ hδ1 - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha - exact ha - -lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hL : Fintype.card L = 1) : - UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by - apply ContinuousLinearMap.adjoint.injective - rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.ext - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_zero_one d hL _ (hh v) - have he := congrArg norm ha - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he - exact norm_eq_zero.mp he -end Generic - -lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * - Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * - Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by - classical - let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - rw [sweep_forward_norm μ e rev] - have hh (v : Specht.hilbertSpace μ) : IsHarmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) - simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he - -lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by - classical - let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - have hh (v : Specht.hilbertSpace μ) : IsHarmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he ((Specht.tail_card μ).trans hk) - have hz : sweepOperator d μ e false = 0 := by - simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he - apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp - rw [sweep_forward_norm μ e rev, hz] - exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ - -end Thorp.SparseContact - -namespace Thorp.SparseContact - -noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) - -lemma contactConstant_gt_one : 1 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma contactConstant_gt_two : 2 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : - ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = - ((contactConstant/2)*δ)^((k:ℝ)/2) := by - have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity - rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] - have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by - unfold contactConstant - rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, - Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] - norm_num - ring - rw [hc, ←Real.exp_mul] - have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by - rw [← pow_mul, mul_comm k 2, pow_mul] - norm_num only [pow_two] - rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] - rw [hpow] - calc - _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring - _ = _ := by rw [←Real.exp_add]; congr 2; ring - -lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : - (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by - rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] - apply mul_le_mul_of_nonneg_right _ (by positivity) - apply mul_le_mul - · rw [← Real.rpow_natCast] - exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) - · calc - d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) - _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) - · positivity - · positivity - - -lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : - ‖sweepOperator d μ e rev‖^2 ≤ min 1 - ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by - let k := μ.card - μ.rowLen 0 - have hk' : (0:ℝ) < k := by exact_mod_cast hk - have hd' : (0:ℝ) < d := by exact_mod_cast hd - have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity - have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by - have h := sweep_norm_le_one d μ e rev - have h0 := norm_nonneg (sweepOperator d μ e rev) - nlinarith - refine le_min hOne ?_ - have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = - (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring - change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - rw [he] - by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 - · have h := sweep_norm_bound d μ e hδ hs rev - have hb : 0 ≤ (2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity - calc - _ ≤ ((2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := - (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h - _ = _ := inflated_contact_bound hδ.le k - · apply hOne.trans - apply Real.one_le_rpow - · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith - exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) - · positivity - -theorem uniform_sparse_contact : MainStatement := by - refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), - (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ - intro d hd μ e k hk _ rev - have hs := sweep_sharp_bound d hd μ e hk rev - refine ⟨hs, ?_, ?_⟩ - · intro hk1 - exact sweep_zero_one d μ e hk1 rev - · apply (hs.trans (min_le_right _ _)).trans - change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ - rw [mul_div_assoc] - exact contact_crude_arithmetic contactConstant_gt_one.le - (by exact_mod_cast hd) (by positivity) k - -end Thorp.SparseContact - -namespace Thorp.DimensionEstimates -open scoped BigOperators - -lemma log_factorial_upper_binary (n : ℕ) (hn : 0 norm_num - | succ n hn ih => - have hn0 : (0:ℝ) norm_num - | succ n hn ih => - have hn0 : (0:ℝ) norm_num - | succ n hn ih => - have hn0 : (0:ℝ) congrArg u x.property) - _ = _ := by simp [fiberWeight] - -lemma sum_fiberWeight (f : X → I) : ∑ i, fiberWeight f i=Fintype.card X := by - have h := fiber_sum f (fun _ => 1) - simpa using h.symm - -theorem incidence_entropy (f : X → I) (g : X → J) - (hinj : Function.Injective (fun x => (f x,g x))) : - (∑ i, fiberWeight f i*Real.log (fiberWeight f i))+ - (∑ j, fiberWeight g j*Real.log (fiberWeight g j)) ≤ - (Fintype.card X:ℝ)*Real.log (Fintype.card X) := by - by_cases hX : Nonempty X - · let : Nonempty X := hX - have hN : (0:ℝ) (f x,g x)), fiberWeight f p.1*fiberWeight g p.2 := by - rw [Finset.sum_image (fun x _ y _ h => hinj h)] - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun p _ _ => mul_nonneg (fiberWeight_nonneg f p.1) (fiberWeight_nonneg g p.2)) - _ = _ := by - rw [Fintype.sum_prod_type] - simp_rw [←Finset.mul_sum] - rw [←Finset.sum_mul,sum_fiberWeight,sum_fiberWeight,pow_two] - have hdiv : (∑ x, fiberWeight f (f x)*fiberWeight g (g x))/(Fintype.card X:ℝ) ≤ Fintype.card X := by - apply (div_le_iff₀ hN).mpr - simpa only [pow_two] using hprod - have hl (x : X) := Real.log_le_sub_one_of_pos - (show 0 hl x) - simp_rw [Real.log_div (mul_pos (fiberWeight_pos f _) (fiberWeight_pos g _)).ne' hN.ne', - Real.log_mul (fiberWeight_pos f _).ne' (fiberWeight_pos g _).ne'] at hs - rw [Finset.sum_sub_distrib,Finset.sum_add_distrib, - fiber_sum f (fun i => Real.log (fiberWeight f i)), - fiber_sum g (fun j => Real.log (fiberWeight g j)), - Finset.sum_sub_distrib,←Finset.sum_div] at hs - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hs - linarith - · let : IsEmpty X := not_nonempty_iff.mp hX - have hf (i : I) : fiberWeight f i=0 := by simp [fiberWeight] - have hg (j : J) : fiberWeight g j=0 := by simp [fiberWeight] - simp [hf,hg] - -end Thorp.DimensionEstimates - -namespace Thorp.DimensionEstimates -open scoped BigOperators Classical - -lemma log_factorial_upper_binary_all (n : ℕ) : - Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by - by_cases hn : n=0 - · subst n - simpa using (Real.log_nonneg (by norm_num : (1:ℝ)≤2)) - · exact log_factorial_upper_binary n (Nat.pos_of_ne_zero hn) - -lemma log_fiber_factorials {X I : Type*} [Fintype X] [Fintype I] (f : X → I) : - Real.log ((∏ i, (Fintype.card {x // f x=i}).factorial : ℕ):ℝ) ≤ - ∑ i, fiberWeight f i*Real.log (fiberWeight f i) - - Real.log 2*((Fintype.card X:ℝ)-Fintype.card I) := by - rw [Nat.cast_prod,Real.log_prod (fun _ _ => by positivity)] - have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - log_factorial_upper_binary_all (Fintype.card {x // f x=i})) - change ∑ i, Real.log ((Fintype.card {x // f x=i}).factorial:ℝ) ≤ - ∑ i, (fiberWeight f i*Real.log (fiberWeight f i)-Real.log 2*(fiberWeight f i-1)) at h - rw [Finset.sum_sub_distrib,←Finset.mul_sum,Finset.sum_sub_distrib,sum_fiberWeight] at h - simpa using h - -theorem dimension_log_from_incidence {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] - [Nonempty X] (f : X → I) (g : X → J) - (hinj : Function.Injective (fun x => (f x,g x))) (D : ℕ) - (hD : (Fintype.card X).factorial ≤ D * - (∏ i, (Fintype.card {x // f x=i}).factorial) * - (∏ j, (Fintype.card {x // g x=j}).factorial)) : - ((2*Real.log 2-1)*(Fintype.card X:ℝ)- - Real.log 2*((Fintype.card I:ℝ)+Fintype.card J)+1) ≤ Real.log D := by - have hd : 0 Real.log (n:ℝ)) (Nat.choose_mul_factorial_mul_factorial hjN.le) - simp only [Nat.cast_mul] at hfac - rw [Real.log_mul (mul_pos hchoose (by positivity)).ne' (by positivity), - Real.log_mul hchoose.ne' (by positivity)] at hfac - have hlo := log_factorial_lower N hN - have hji := log_factorial_upper j hj - have hti := log_factorial_upper (N-j) ht - have hjlog := Real.log_le_log hj0 hjN0.le - have htlog := Real.log_le_log (by exact_mod_cast ht : (0:ℝ)<(N-j:ℕ)) - (by exact_mod_cast Nat.sub_le N j : ((N-j:ℕ):ℝ)≤N) - rw [Nat.cast_sub hjN.le] at hti htlog - rw [scaled_binEntropy N j hN0 hj0 hjN0] - linarith - -lemma binEntropy_three_quarters : - Real.binEntropy (3/4:ℝ)=2*Real.log 2-(3/4:ℝ)*Real.log 3 := by - have h4 : Real.log (4:ℝ)=2*Real.log 2 := by - rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num - unfold Real.binEntropy - norm_num only [show (1-(3/4:ℝ))=1/4 by norm_num] - rw [Real.log_div (by norm_num) (by norm_num),h4] - ring - -noncomputable def entropyGap : ℝ := Real.log (32/27:ℝ)/3 - -lemma entropyGap_pos : 0 norm_num) - (show (3/4:ℝ)∈Set.Icc 0 1 by constructor <;> norm_num) - (show 0≤1-4*q/3 by linarith) (show 0≤4*q/3 by positivity) - (show (1-4*q/3)+(4*q/3)=1 by ring) - simp only [Real.binEntropy_zero,binEntropy_three_quarters,smul_eq_mul,mul_zero,zero_add] at hc - have he : 4*q/3*(3/4:ℝ)=q := by ring - rw [he] at hc - rw [entropyGap_eq] - linarith - -lemma log_dimension_from_binomial (N j D : ℕ) (hj : 0 if h : Function.Injective y then f ⟨y,h⟩ else 0) + +@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] + congr 1 + +lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] + +lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : + (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by + rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] + simp only [zeroExtend_inj] + +lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by + have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by + rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, + sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] + simp only [zeroExtend_inj] + nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] + +lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : + rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 + simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, + Complex.ofReal_sum, Complex.ofReal_natCast] + simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] + rw [mul_eq_zero] + right + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply mul_eq_zero_of_right + apply Finset.sum_eq_zero + intro ω _ + calc + _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * + (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := + by + apply Finset.sum_congr rfl + intro y _ + have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ + (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := + forall₂_congr fun _ _ => eq_comm + by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i + · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] + · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] + _ = 0 := by + rw [← Finset.mul_sum] + apply mul_eq_zero_of_right + convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> rfl + +lemma partial_full_action {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) : + rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d Finset.univ x y) (zeroExtend f) = + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + apply Finset.sum_congr rfl + intro y _ + congr 2 + simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), + one_mul, endpointProb, UnitaryFinite.actionKernel] + apply finiteMean_congr + intro ω + congr 1 + simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] + rfl + +lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) + (x : L ↪ Card d) (y : L → Card d) : + (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = + ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by + classical + by_cases h : ContactEvent d x y + · simp only [retainedKernel, ite_eq_left h] + · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] + exact (alternating_kernel_cancel d x y h).symm + +lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : + (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = + ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + calc + _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by + ext x + simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] + rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] + apply Finset.sum_congr rfl + intro y _ + simp_rw [← mul_assoc, ← Finset.sum_mul] + congr 1 + have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) + simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, + Complex.ofReal_one] using he + _ = ((-1:ℂ)^(Fintype.card L)) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by + rw [Finset.sum_eq_single (Finset.univ : Finset L)] + · simp only [Finset.card_univ] + · intro A _ hA + rw [partial_proper_zero d A hA f hf, smul_zero] + · simp + _ = _ := by rw [partial_full_action] + +lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by + classical + let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) + have hB : 0 ≤ B := by dsimp [B]; positivity + have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by + have hh := retained_norm_sq d A hδ hδ1 + have hs := Real.sq_sqrt hB + have hn := Real.sqrt_nonneg B + nlinarith + calc + _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by + rw [alternating_harmonic_action d f hf] + _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := + norm_sum_le _ _ + _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by + apply Finset.sum_le_sum + intro A _ + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := + ContinuousLinearMap.le_opNorm _ _ + _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) + _ = _ := by rw [norm_zeroExtend] + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat]; ring + +lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) + (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : IsHarmonic f) : + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by + classical + obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL + have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by + ext v x + have hh (y : L → Card d) : ¬ContactEvent d x y := by + intro h + obtain ⟨j,hj,_⟩ := h i + exact hj (hi j).symm + simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, + zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] + have he := alternating_harmonic_action d f hf + simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, + neg_smul, one_smul] at he + exact neg_eq_zero.mp he.symm + +end +open scoped BigOperators + +def MainStatement : Prop := + ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ + ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), + let k := μ.card - μ.rowLen 0 + 1 ≤ k → k < 2^d → ∀ reverse : Bool, + ‖sweepOperator d μ e reverse‖^2 ≤ + min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ + (k = 1 → sweepOperator d μ e reverse = 0) ∧ + ‖sweepOperator d μ e reverse‖^2 ≤ + C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + +end Thorp.SparseContact + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) + (hL : Fintype.card L = μ.card - μ.rowLen 0) : + ∃ w : Specht.hilbertSpace μ, + UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by + let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) + have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by + rw [Specht.finrank_hilbertSpace] + exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) + have hdim := Specht.relabelled_tuple_dimension μ e x₀ + rw [hL, Nat.choose_self, mul_one] at hdim + have hm : 0 < Module.finrank ℂ K := by + by_contra h + have hz : Module.finrank ℂ K = 0 := by omega + change _ ≤ Module.finrank ℂ K * _ at hdim + rw [hz, zero_mul] at hdim + omega + let B := stdOrthonormalBasis ℂ K + let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ + exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ + +lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by + cases rev + · rfl + · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] + rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), + ContinuousLinearMap.adjoint.norm_map] + +lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ 1 := + UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ + +section Generic +variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] + +lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) := by + rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), + ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_bound d _ (hh v) hδ hδ1 + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha + exact ha + +lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, IsHarmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hL : Fintype.card L = 1) : + UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by + apply ContinuousLinearMap.adjoint.injective + rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.ext + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_zero_one d hL _ (hh v) + have he := congrArg norm ha + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he + exact norm_eq_zero.mp he +end Generic + +lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * + Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * + Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by + classical + let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + rw [sweep_forward_norm μ e rev] + have hh (v : Specht.hilbertSpace μ) : IsHarmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) + simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he + +lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by + classical + let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + have hh (v : Specht.hilbertSpace μ) : IsHarmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he ((Specht.tail_card μ).trans hk) + have hz : sweepOperator d μ e false = 0 := by + simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he + apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp + rw [sweep_forward_norm μ e rev, hz] + exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ + +end Thorp.SparseContact + +namespace Thorp.SparseContact + +noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) + +lemma contactConstant_gt_one : 1 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma contactConstant_gt_two : 2 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : + ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = + ((contactConstant/2)*δ)^((k:ℝ)/2) := by + have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity + rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] + have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by + unfold contactConstant + rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, + Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] + norm_num + ring + rw [hc, ←Real.exp_mul] + have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by + rw [← pow_mul, mul_comm k 2, pow_mul] + norm_num only [pow_two] + rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] + rw [hpow] + calc + _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring + _ = _ := by rw [←Real.exp_add]; congr 2; ring + +lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : + (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by + rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply mul_le_mul + · rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) + · calc + d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) + _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) + · positivity + · positivity + + +lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : + ‖sweepOperator d μ e rev‖^2 ≤ min 1 + ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by + let k := μ.card - μ.rowLen 0 + have hk' : (0:ℝ) < k := by exact_mod_cast hk + have hd' : (0:ℝ) < d := by exact_mod_cast hd + have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity + have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by + have h := sweep_norm_le_one d μ e rev + have h0 := norm_nonneg (sweepOperator d μ e rev) + nlinarith + refine le_min hOne ?_ + have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = + (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring + change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + rw [he] + by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 + · have h := sweep_norm_bound d μ e hδ hs rev + have hb : 0 ≤ (2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity + calc + _ ≤ ((2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := + (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h + _ = _ := inflated_contact_bound hδ.le k + · apply hOne.trans + apply Real.one_le_rpow + · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith + exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) + · positivity + +theorem uniform_sparse_contact : MainStatement := by + refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), + (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ + intro d hd μ e k hk _ rev + have hs := sweep_sharp_bound d hd μ e hk rev + refine ⟨hs, ?_, ?_⟩ + · intro hk1 + exact sweep_zero_one d μ e hk1 rev + · apply (hs.trans (min_le_right _ _)).trans + change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ + rw [mul_div_assoc] + exact contact_crude_arithmetic contactConstant_gt_one.le + (by exact_mod_cast hd) (by positivity) k + +end Thorp.SparseContact + +namespace Thorp.DimensionEstimates +open scoped BigOperators + +lemma log_factorial_upper_binary (n : ℕ) (hn : 0 norm_num + | succ n hn ih => + have hn0 : (0:ℝ) norm_num + | succ n hn ih => + have hn0 : (0:ℝ) norm_num + | succ n hn ih => + have hn0 : (0:ℝ) congrArg u x.property) + _ = _ := by simp [fiberWeight] + +lemma sum_fiberWeight (f : X → I) : ∑ i, fiberWeight f i=Fintype.card X := by + have h := fiber_sum f (fun _ => 1) + simpa using h.symm + +theorem incidence_entropy (f : X → I) (g : X → J) + (hinj : Function.Injective (fun x => (f x,g x))) : + (∑ i, fiberWeight f i*Real.log (fiberWeight f i))+ + (∑ j, fiberWeight g j*Real.log (fiberWeight g j)) ≤ + (Fintype.card X:ℝ)*Real.log (Fintype.card X) := by + by_cases hX : Nonempty X + · let : Nonempty X := hX + have hN : (0:ℝ) (f x,g x)), fiberWeight f p.1*fiberWeight g p.2 := by + rw [Finset.sum_image (fun x _ y _ h => hinj h)] + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun p _ _ => mul_nonneg (fiberWeight_nonneg f p.1) (fiberWeight_nonneg g p.2)) + _ = _ := by + rw [Fintype.sum_prod_type] + simp_rw [←Finset.mul_sum] + rw [←Finset.sum_mul,sum_fiberWeight,sum_fiberWeight,pow_two] + have hdiv : (∑ x, fiberWeight f (f x)*fiberWeight g (g x))/(Fintype.card X:ℝ) ≤ Fintype.card X := by + apply (div_le_iff₀ hN).mpr + simpa only [pow_two] using hprod + have hl (x : X) := Real.log_le_sub_one_of_pos + (show 0 hl x) + simp_rw [Real.log_div (mul_pos (fiberWeight_pos f _) (fiberWeight_pos g _)).ne' hN.ne', + Real.log_mul (fiberWeight_pos f _).ne' (fiberWeight_pos g _).ne'] at hs + rw [Finset.sum_sub_distrib,Finset.sum_add_distrib, + fiber_sum f (fun i => Real.log (fiberWeight f i)), + fiber_sum g (fun j => Real.log (fiberWeight g j)), + Finset.sum_sub_distrib,←Finset.sum_div] at hs + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hs + linarith + · let : IsEmpty X := not_nonempty_iff.mp hX + have hf (i : I) : fiberWeight f i=0 := by simp [fiberWeight] + have hg (j : J) : fiberWeight g j=0 := by simp [fiberWeight] + simp [hf,hg] + +end Thorp.DimensionEstimates + +namespace Thorp.DimensionEstimates +open scoped BigOperators Classical + +lemma log_factorial_upper_binary_all (n : ℕ) : + Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by + by_cases hn : n=0 + · subst n + simpa using (Real.log_nonneg (by norm_num : (1:ℝ)≤2)) + · exact log_factorial_upper_binary n (Nat.pos_of_ne_zero hn) + +lemma log_fiber_factorials {X I : Type*} [Fintype X] [Fintype I] (f : X → I) : + Real.log ((∏ i, (Fintype.card {x // f x=i}).factorial : ℕ):ℝ) ≤ + ∑ i, fiberWeight f i*Real.log (fiberWeight f i) - + Real.log 2*((Fintype.card X:ℝ)-Fintype.card I) := by + rw [Nat.cast_prod,Real.log_prod (fun _ _ => by positivity)] + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + log_factorial_upper_binary_all (Fintype.card {x // f x=i})) + change ∑ i, Real.log ((Fintype.card {x // f x=i}).factorial:ℝ) ≤ + ∑ i, (fiberWeight f i*Real.log (fiberWeight f i)-Real.log 2*(fiberWeight f i-1)) at h + rw [Finset.sum_sub_distrib,←Finset.mul_sum,Finset.sum_sub_distrib,sum_fiberWeight] at h + simpa using h + +theorem dimension_log_from_incidence {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] + [Nonempty X] (f : X → I) (g : X → J) + (hinj : Function.Injective (fun x => (f x,g x))) (D : ℕ) + (hD : (Fintype.card X).factorial ≤ D * + (∏ i, (Fintype.card {x // f x=i}).factorial) * + (∏ j, (Fintype.card {x // g x=j}).factorial)) : + ((2*Real.log 2-1)*(Fintype.card X:ℝ)- + Real.log 2*((Fintype.card I:ℝ)+Fintype.card J)+1) ≤ Real.log D := by + have hd : 0 Real.log (n:ℝ)) (Nat.choose_mul_factorial_mul_factorial hjN.le) + simp only [Nat.cast_mul] at hfac + rw [Real.log_mul (mul_pos hchoose (by positivity)).ne' (by positivity), + Real.log_mul hchoose.ne' (by positivity)] at hfac + have hlo := log_factorial_lower N hN + have hji := log_factorial_upper j hj + have hti := log_factorial_upper (N-j) ht + have hjlog := Real.log_le_log hj0 hjN0.le + have htlog := Real.log_le_log (by exact_mod_cast ht : (0:ℝ)<(N-j:ℕ)) + (by exact_mod_cast Nat.sub_le N j : ((N-j:ℕ):ℝ)≤N) + rw [Nat.cast_sub hjN.le] at hti htlog + rw [scaled_binEntropy N j hN0 hj0 hjN0] + linarith + +lemma binEntropy_three_quarters : + Real.binEntropy (3/4:ℝ)=2*Real.log 2-(3/4:ℝ)*Real.log 3 := by + have h4 : Real.log (4:ℝ)=2*Real.log 2 := by + rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num + unfold Real.binEntropy + norm_num only [show (1-(3/4:ℝ))=1/4 by norm_num] + rw [Real.log_div (by norm_num) (by norm_num),h4] + ring + +noncomputable def entropyGap : ℝ := Real.log (32/27:ℝ)/3 + +lemma entropyGap_pos : 0 norm_num) + (show (3/4:ℝ)∈Set.Icc 0 1 by constructor <;> norm_num) + (show 0≤1-4*q/3 by linarith) (show 0≤4*q/3 by positivity) + (show (1-4*q/3)+(4*q/3)=1 by ring) + simp only [Real.binEntropy_zero,binEntropy_three_quarters,smul_eq_mul,mul_zero,zero_add] at hc + have he : 4*q/3*(3/4:ℝ)=q := by ring + rw [he] at hc + rw [entropyGap_eq] + linarith + +lemma log_dimension_from_binomial (N j D : ℕ) (hj : 0 r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr - -end GroupedCounting - -section AllLengths -variable {d A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) - (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) - (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : - finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by - have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by - rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] - exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm - have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), - ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by - calc - _ = ((q-1)+1)^(F ω) := by congr 1; ring - _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by - rw [add_pow] - simp only [one_pow,mul_one] - _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by - apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) - intro a _ ha - have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega - rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] - _ = _ := by - apply Finset.sum_congr rfl - intro a _ - rw [hc] - ring - simp_rw [hex,finiteMean_sum,finiteMean_mul_const] - calc - _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_right (hm a) (by positivity) - _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by - apply Finset.sum_congr rfl - intro a _ - rw [mul_pow] - ring - _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ - -lemma inv_sqrt_step (j : ℕ) : - 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by - have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) - apply (div_le_iff₀ hp).mpr - have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) - have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) - nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] - -lemma sum_inv_sqrt (J : ℕ) : - (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by - have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ] - have hs := inv_sqrt_step n - push_cast - linarith - rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] - exact h J -section CycleMGF -variable {d : ℕ} - -lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment S J - -end CycleMGF - -section FullCycleMGF -variable {d : ℕ} - -abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by - apply div_pos - · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty - · exact Nat.cast_pos.mpr Fintype.card_pos - -lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - -end FullCycleMGF - -structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] - [Fintype ι] [DecidableEq ι] (d : ℕ) where - perm : (ι → Bool) → Equiv.Perm α - path : (ι → Bool) → α → Finset ι - users : (ι → Bool) → ι → α × α - users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 - mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x - card_path : ∀ ω x, (path ω x).card = d - entropy : ∀ ω (S : Finset α), - (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) - follow : α → (α → QueryTree ι) → QueryTree ι - close : α → α → QueryTree ι → QueryTree ι - follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω - follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω - follow_stale_charge : ∀ x k R ω, - (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω - close_succeeds : ∀ x y k ω, - (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false - close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d - close_stale_charge : ∀ x y k R ω, perm ω x = y → - (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card - -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma card_switches_using (ω : ι → Bool) (x : α) : - (Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by - ext i - simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] - rw [he,R.card_path] -lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = - (d : ℝ) * ∑ x : α, w x := by - classical - calc - _ = ∑ i : ι, ∑ x : α, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : α => - (R.users b i).1 = x ∨ (R.users b i).2 = x) = - {(R.users b i).1, (R.users b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (R.users_ne b i)] - _ = ∑ x : α, ∑ i : ι, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : α, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ - (d : ℝ) / 2 * ∑ x : α, w x := by - have h : 2 * (∑ i : ι, - min (w (R.users b i).1) (w (R.users b i).2)) ≤ - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), - min_le_right (w (R.users b i).1) (w (R.users b i).2)] - rw [switch_incidence_sum] at h - linarith -section Rotation -variable {A : ℕ} - -def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -omit [DecidableEq α] in -@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} - -noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) - (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -omit [DecidableEq α] in -lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : - Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (i : Fin A) (x : α) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -omit [DecidableEq α] in -lemma slotWeight_antitone (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -omit [DecidableEq α] in -lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : α, pathWeight o x = (A : ℝ) := by - classical - have he (x : α) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : - (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : α) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := R.entropy b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) - (z : Terminal o) : ℝ := - ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 - -lemma rotationCharge_mean_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound R b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound R o hn b - linarith - -lemma rotation_exp_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have hb := rotationCharge_mean_bound R hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -namespace QueryTree -open Thorp.QueryTree - -noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : - ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → - QueryTree (ι) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x - (fun y => seekCycle R S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) - (ω : ι → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle R S a r x V k).succeeds ω = true) : - (seekCycle R S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs - rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - -noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : - List (α × ℕ) → Finset (α) → QueryTree (ι) - | [], _ => accept - | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) - -lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) - (V : Finset (α)) (ω : ι → Bool) - (hs : (seekCycles R S L V).succeeds ω = true) : - (seekCycles R S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : - finiteMean (fun ω : ι → Bool => - if (seekCycles R S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles R S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge R S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree -noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : - Finset (ι) := - V.biUnion (fun x => R.path b x) - -@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : - exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := - (R.path b z ∩ exposedPaths R b V).card - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V W : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : - (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (S V : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (hS : orbitSet (R.perm ω) z ⊆ S) - (hV : Disjoint V (orbitSet (R.perm ω) z)) : - let p := R.perm ω - let W := V ∪ orbitSet p z - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -end RoutingNetwork -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.RotationMeeting + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +section CycleCounting +variable {d A : ℕ} + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {d A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr + +end GroupedCounting + +section AllLengths +variable {d A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) + (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) + (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : + finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by + have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by + rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] + exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm + have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), + ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by + calc + _ = ((q-1)+1)^(F ω) := by congr 1; ring + _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by + rw [add_pow] + simp only [one_pow,mul_one] + _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by + apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) + intro a _ ha + have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega + rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [hc] + ring + simp_rw [hex,finiteMean_sum,finiteMean_mul_const] + calc + _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_right (hm a) (by positivity) + _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by + apply Finset.sum_congr rfl + intro a _ + rw [mul_pow] + ring + _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ + +lemma inv_sqrt_step (j : ℕ) : + 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by + have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) + apply (div_le_iff₀ hp).mpr + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) + have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) + nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] + +lemma sum_inv_sqrt (J : ℕ) : + (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by + have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ] + have hs := inv_sqrt_step n + push_cast + linarith + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] + exact h J +section CycleMGF +variable {d : ℕ} + +lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment S J + +end CycleMGF + +section FullCycleMGF +variable {d : ℕ} + +abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by + apply div_pos + · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty + · exact Nat.cast_pos.mpr Fintype.card_pos + +lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + +end FullCycleMGF + +structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] + [Fintype ι] [DecidableEq ι] (d : ℕ) where + perm : (ι → Bool) → Equiv.Perm α + path : (ι → Bool) → α → Finset ι + users : (ι → Bool) → ι → α × α + users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 + mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x + card_path : ∀ ω x, (path ω x).card = d + entropy : ∀ ω (S : Finset α), + (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) + follow : α → (α → QueryTree ι) → QueryTree ι + close : α → α → QueryTree ι → QueryTree ι + follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω + follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω + follow_stale_charge : ∀ x k R ω, + (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω + close_succeeds : ∀ x y k ω, + (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false + close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d + close_stale_charge : ∀ x y k R ω, perm ω x = y → + (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card + +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma card_switches_using (ω : ι → Bool) (x : α) : + (Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by + ext i + simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] + rw [he,R.card_path] +lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = + (d : ℝ) * ∑ x : α, w x := by + classical + calc + _ = ∑ i : ι, ∑ x : α, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : α => + (R.users b i).1 = x ∨ (R.users b i).2 = x) = + {(R.users b i).1, (R.users b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (R.users_ne b i)] + _ = ∑ x : α, ∑ i : ι, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : α, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ + (d : ℝ) / 2 * ∑ x : α, w x := by + have h : 2 * (∑ i : ι, + min (w (R.users b i).1) (w (R.users b i).2)) ≤ + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), + min_le_right (w (R.users b i).1) (w (R.users b i).2)] + rw [switch_incidence_sum] at h + linarith +section Rotation +variable {A : ℕ} + +def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +omit [DecidableEq α] in +@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} + +noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) + (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +omit [DecidableEq α] in +lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : + Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (i : Fin A) (x : α) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +omit [DecidableEq α] in +lemma slotWeight_antitone (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +omit [DecidableEq α] in +lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : α, pathWeight o x = (A : ℝ) := by + classical + have he (x : α) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : + (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : α) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := R.entropy b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) + (z : Terminal o) : ℝ := + ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 + +lemma rotationCharge_mean_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound R b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound R o hn b + linarith + +lemma rotation_exp_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have hb := rotationCharge_mean_bound R hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +namespace QueryTree +open Thorp.QueryTree + +noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : + ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → + QueryTree (ι) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x + (fun y => seekCycle R S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) + (ω : ι → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle R S a r x V k).succeeds ω = true) : + (seekCycle R S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs + rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + +noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : + List (α × ℕ) → Finset (α) → QueryTree (ι) + | [], _ => accept + | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) + +lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) + (V : Finset (α)) (ω : ι → Bool) + (hs : (seekCycles R S L V).succeeds ω = true) : + (seekCycles R S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : + finiteMean (fun ω : ι → Bool => + if (seekCycles R S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles R S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge R S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree +noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : + Finset (ι) := + V.biUnion (fun x => R.path b x) + +@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : + exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := + (R.path b z ∩ exposedPaths R b V).card + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V W : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : + (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (S V : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (hS : orbitSet (R.perm ω) z ⊆ S) + (hV : Disjoint V (orbitSet (R.perm ω) z)) : + let p := R.perm ω + let W := V ∪ orbitSet p z + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +end RoutingNetwork +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/Coins.lean b/lean/OAI/Probability/ThorpRouting/HighTail/Coins.lean index f9ec989cec535346137960e0c21d2d0f931e72d9..9e727a42abda78acc5ce748276ee453b5cd12945 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/Coins.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/Coins.lean @@ -1,764 +1,764 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.Model - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp - -open scoped BigOperators -open Filter - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Card d → Bool - -instance (d : ℕ) : Fintype (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -instance (d : ℕ) : Nonempty (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -def rotate (d : ℕ) : Equiv.Perm (Card d) where - toFun x i := x (finRotate d i) - invFun x i := x ((finRotate d).symm i) - left_inv x := by funext i; simp only [Equiv.apply_symm_apply] - right_inv x := by funext i; simp only [Equiv.symm_apply_apply] - -def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, ξ => rotate (d + 1) * pairSwitch ξ - -def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) - | 0, _ => 1 - | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) - -noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := - (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / - (Fintype.card (Fin t → Coins d) : ℝ) - -noncomputable def distance (d t : ℕ) : ℝ := - (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| - -noncomputable def mixingTime (d : ℕ) : ℕ := - sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} - -noncomputable def supportTimeBound (d : ℕ) : ℤ := - ⌈(2 / (2 : ℝ) ^ d) * - (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ - -def OptimalOrder : Prop := - ∃ C : ℕ, 0 < C ∧ - Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ - (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ - (∀ᶠ d : ℕ in atTop, - supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ - (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) - -noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by - classical - exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) - -lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : - ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by - classical - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : - 0 ≤ finiteLaw f b := by - exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - -lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : - ∑ b, finiteLaw f b = 1 := by - classical - simp only [finiteLaw, ← Finset.sum_div] - have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by - exact_mod_cast sum_card_fibers f - rw [hc] - exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by - classical - have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr - ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ - simp [finiteLaw] - -lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] - (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : - (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by - have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := - Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) - have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) - have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) - have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) - rw [hpq] at hz - rw [← Finset.sum_sub_distrib] - linarith - -lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] - [Fintype β] [Nonempty β] (f : α → β) : - 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ - (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by - classical - let s := Finset.univ.image f - have hs : ∑ b ∈ s, finiteLaw f b = 1 := by - have h := Finset.sum_subset (Finset.subset_univ s) - (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) - simpa only [finiteLaw_sum] using h - have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] - have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by - rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] - have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s - rw [hs] at he - have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by - simp [div_eq_mul_inv] - rw [hsq] at he - have hcard : (s.card : ℝ) ≤ Fintype.card α := by - exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) - have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) - linarith - -lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by - simp [Card] - -lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by - rw [Fintype.card_perm, card_positions] - -lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by - rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] - -lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : - law d t g = finiteLaw (run d t) g := by - unfold law finiteLaw - apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) - exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) - -lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by - rw [law_eq_finiteLaw] - exact finiteLaw_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by - simp only [law_eq_finiteLaw] - exact finiteLaw_sum (run d t) - -lemma physical_support_bound_succ (d t : ℕ) : - 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by - have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ - have h := finiteLaw_support_bound (run (d + 1) t) - rw [card_tapes_succ, card_permutations] at h - simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h - -lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : - step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by - change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ - rw [Fin.snoc_eq_cons_rotate] - rfl - -lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by - unfold distance - exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - -lemma physical_support_bound (d t : ℕ) : - 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by - cases d with - | zero => - have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) - simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using - le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) - | succ d => - have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by - push_cast - rw [pow_succ] - ring - rw [he, Real.rpow_natCast] - exact physical_support_bound_succ d t - -lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : - supportTimeBound d ≤ (t : ℤ) := by - have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity - have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity - have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) - have hb := physical_support_bound d t - have hp : (3 / 4 : ℝ) ≤ - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by - linarith - have hr := (le_div_iff₀ hF).mp hp - have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr - rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog - unfold supportTimeBound - apply Int.ceil_le.mpr - simp only [Int.cast_natCast] - calc - 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = - Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by - field_simp - _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by - nlinarith [hlog]) - -lemma supportTimeBound_le_mixingTime {d : ℕ} - (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : - supportTimeBound d ≤ (mixingTime d : ℤ) := by - exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) - -lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : - (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by - have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) - have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) - have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by - have := Real.pi_gt_three - linarith) - linarith - -lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) - have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by - rw [← Real.log_inv] - congr 1 - norm_num - rw [he] at h - linarith - -lemma linear_le_supportTimeBound (d : ℕ) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by - have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) - have hNp : 0 < (2 : ℝ) ^ d := by positivity - have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) - have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - rw [Real.log_mul (by norm_num) (by positivity)] - push_cast at hf - rw [Real.log_pow] at hf - linarith [log_three_quarters_lower] - apply le_trans _ (Int.le_ceil _) - have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) = - (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by - field_simp - ring - rw [hcancel] - linarith - convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 - field_simp - -lemma linear_le_time_of_distance_le (d t : ℕ) - (ht : distance d t ≤ (1 / 4 : ℝ)) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by - have h := supportTimeBound_le_of_distance_le d t ht - have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h - exact (linear_le_supportTimeBound d).trans hr - -lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : - 2 * p * Real.log 2 ≤ Real.binEntropy p := by - have hc := Real.strictConcave_binEntropy.concaveOn.2 - (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show 0 ≤ 1 - 2 * p by linarith) - (show 0 ≤ 2 * p by positivity) - (show (1 - 2 * p) + 2 * p = 1 by ring) - simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, - smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc - -lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : - 2 * min a b * Real.log 2 ≤ - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - wlog hab : a ≤ b generalizing a b - · have hba := this b a hb ha (le_of_not_ge hab) - simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) - rw [min_eq_left hab] - by_cases hz : a = 0 - · subst a - simp - have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) - have hbp : 0 < b := hap.trans_le hab - have hs : 0 < a + b := add_pos hap hbp - have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le - have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) - have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le - have he : (a + b) * Real.binEntropy (a / (a + b)) = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - unfold Real.binEntropy - rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] - simp only [Real.log_inv] - rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), - Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] - field_simp - ring - rw [he] at hc - calc - 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by - field_simp - _ ≤ _ := hc - -noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail - -lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by - classical - unfold childMarks - apply Finset.card_image_iff.mpr - intro x hx y hy hxy - have hx0 := (Finset.mem_filter.mp hx).2 - have hy0 := (Finset.mem_filter.mp hy).2 - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] - -lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : - (childMarks s false).card + (childMarks s true).card = s.card := by - classical - rw [card_childMarks, card_childMarks] - simpa only [Bool.not_eq_false] using - (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) - -noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) : Finset (Card d) := - ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ - ((childMarks s true).image (butterflyPerm d (b.2 true))) - -lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : - (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by - classical - apply le_min - · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) - · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) - -noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ - | 0, _, _ => 0 - | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card - -lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - induction d with - | zero => - simp only [encounters, Nat.cast_zero] - have hs : s.card ≤ 1 := by - simpa [Card] using Finset.card_le_univ s - interval_cases s.card <;> simp - | succ d ih => - have h₀ := ih (b.2 false) (childMarks s false) - have h₁ := ih (b.2 true) (childMarks s true) - have ht : ((topMeetings b s).card : ℝ) ≤ - min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by - exact_mod_cast card_topMeetings_le b s - have he := split_entropy_lower ((childMarks s false).card : ℝ) - ((childMarks s true).card : ℝ) (by positivity) (by positivity) - have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by - exact_mod_cast card_childMarks_add s - rw [hs] at he - have hL : 0 < 2 * Real.log 2 := by positivity - rw [le_div_iff₀ hL] at h₀ h₁ ⊢ - simp only [encounters, Nat.cast_add] - nlinarith [mul_le_mul_of_nonneg_right ht hL.le] - -lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by - by_cases ha : a ∈ s - · rw [ite_eq_left ha] - exact (Finset.mul_prod_erase s f ha).symm - · simp [ha] - -lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) - (a b : α) (hab : a ≠ b) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * - ∏ i ∈ (s.erase a).erase b, f i := by - calc - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := - prod_split_at s f a - _ = _ := by - rw [prod_split_at (s.erase a) f b] - have hm : (b ∈ s.erase a) ↔ b ∈ s := - ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ - simp only [hm, mul_assoc] - -lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ - ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by - by_cases hab : a = b - · subst b - simp only [Equiv.swap_self, Equiv.refl_apply] - have h : (fun i => (p i + p i) / 2) = p := by funext i; ring - rw [h] - linarith - let t := (s.erase a).erase b - have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by - intro i hi - exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) - have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) - rw [prod_split_two s p a b hab, - prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, - prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] - change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + - (if a ∈ s then p (Equiv.swap a b a) else 1) * - (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ - rw [hprod] - change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * - (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * - (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) - rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] - have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) - by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] - · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht - nlinarith - all_goals ring_nf; rfl - -def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := - ∀ s, m s ≤ ∏ i ∈ s, p i - -lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] - {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) - (fun i => (p i + p (Equiv.swap a b i)) / 2) := by - intro s - have h₀ := h s - have h₁ := h (s.image (Equiv.swap a b)) - rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ - exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans - (swap_average_product s p hp a b) - -noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : ℝ := by - classical - exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) - -lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by - classical - unfold inclusionMoment finiteMean - positivity - -lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : - (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by - by_cases h : s ⊆ A - · rw [ite_eq_left h] - exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm - · rw [ite_eq_right h] - obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h - exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm - -lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] - (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = - if s ⊆ A then 1 else 0 := by - classical - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] - -lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : - CylinderBound (inclusionMoment (fun _ : Ω => A)) - (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by - classical - intro s - simp only [inclusionMoment_const, Finset.singleton_subset_iff] - exact (indicator_subset_prod A s).le - -noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] - (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := - fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 - -lemma subset_swap_image_iff {α : Type*} [DecidableEq α] - (A s : Finset α) (a b : α) : - s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by - constructor - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - -lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) (s : Finset α) : - inclusionMoment (fairSetSwap F a b) s = - (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by - classical - simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, - fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, - Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] - rw [div_mul_eq_div_div, add_div] - ring_nf - -lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) - (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : - CylinderBound (inclusionMoment (fairSetSwap F a b)) - (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by - classical - have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b - intro s - simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s - -def SwitchSamples : ℕ → Type - | 0 => Unit - | n + 1 => SwitchSamples n × Bool - -instance (n : ℕ) : Fintype (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Fintype Unit) - | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) - -instance (n : ℕ) : Nonempty (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Nonempty Unit) - | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) - -noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : - (L : List (α × α)) → SwitchSamples L.length → Finset α - | [], _ => A - | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω - -lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) - (L : List (α × α)) : - CylinderBound (inclusionMoment (switchedSet A L)) - (fun i => inclusionMoment (switchedSet A L) {i}) := by - induction L with - | nil => exact cylinder_const A - | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih - -inductive QueryTree (ι : Type*) - | reject : QueryTree ι - | accept : QueryTree ι - | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι - | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι - -namespace QueryTree - -variable {ι : Type*} [DecidableEq ι] - -def queries : QueryTree ι → Finset ι - | reject => ∅ - | accept => ∅ - | branch i zero one => insert i (queries zero ∪ queries one) - | force i _ next => insert i (queries next) - -def Fresh : QueryTree ι → Prop - | reject => True - | accept => True - | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one - | force i _ next => i ∉ queries next ∧ Fresh next - -def weighted : QueryTree ι → (ι → Bool) → ℝ - | reject, _ => 0 - | accept, _ => 1 - | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω - | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 - -omit [DecidableEq ι] in -lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by - induction T with - | reject => exact le_rfl - | accept => exact zero_le_one - | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ - | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl - -lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} - (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by - induction T with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), - ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] - | force i b next ih => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] - -def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := - (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by - intro ω - funext j - by_cases h : j = i - · subst j; simp - · simp [Function.update_of_ne h]).toPerm - -lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by - change Function.update ω i (!(ω i)) i = _ - exact Function.update_self _ _ _ - -lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : - flipCoin i ω j = ω j := by - change Function.update ω i (!(ω i)) j = _ - exact Function.update_of_ne h _ _ - -lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) - (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by - apply weighted_congr - intro j hj - exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω - -lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) - (hf : ∀ ω, f (flipCoin i ω) = f ω) : - finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by - let g := fun ω : ι → Bool => if ω i = b then f ω else 0 - have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by - dsimp [g] - rw [flipCoin_apply_eq, hf] - cases hω : ω i <;> cases b <;> simp - have hs := Equiv.sum_comp (flipCoin i) g - have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun ω _ => hp ω) - unfold finiteMean - change (∑ ω, g ω) / _ = _ - rw [hs] at hadd - have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith - rw [hh] - ring - -lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : - finiteMean T.weighted ≤ 1 := by - induction T with - | reject => simp [weighted, finiteMean] - | accept => simp [weighted, finiteMean] - | branch i zero one ih₀ ih₁ => - obtain ⟨hz, ho, hfz, hfo⟩ := hT - have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) - have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) - have he : finiteMean (branch i zero one).weighted = - finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + - finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by - unfold finiteMean - rw [← add_div, ← Finset.sum_add_distrib] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - cases hω : ω i <;> simp [weighted, hω] - rw [he, h₀, h₁] - linarith [ih₀ hfz, ih₁ hfo] - | force i b next ih => - obtain ⟨hi, hn⟩ := hT - have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) - have he : finiteMean (force i b next).weighted = - 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by - unfold finiteMean - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : ω i = b <;> simp [weighted, h] - rw [he, hm] - linarith [ih hn] - -def succeeds : QueryTree ι → (ι → Bool) → Bool - | reject, _ => false - | accept, _ => true - | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω - | force i b next, ω => if ω i = b then succeeds next ω else false - -def charge : QueryTree ι → (ι → Bool) → ℕ - | reject, _ => 0 - | accept, _ => 0 - | branch i zero one, ω => if ω i then charge one ω else charge zero ω - | force i b next, ω => if ω i = b then charge next ω + 1 else 0 - -omit [DecidableEq ι] in -lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : - T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by - induction T with - | reject => rfl - | accept => norm_num [weighted, succeeds, charge] - | branch i zero one ih₀ ih₁ => - cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] - | force i b next ih => - by_cases h : ω i = b - · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] - cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] - · simp [weighted, succeeds, h] - -lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) - (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : - finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by - have hw (ω : ι → Bool) : - (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by - rw [weighted_eq] - cases hs : T.succeeds ω - · simp - · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) - have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ - have hm := div_le_div_of_nonneg_right - (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn - rw [← Finset.mul_sum, mul_div_assoc] at hm - change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ - finiteMean T.weighted at hm - exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by - rw [mul_comm] - exact hm.trans (mean_weighted_le_one T hT)) - -end QueryTree - -def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool - | 0, _, i => nomatch i - | _d + 1, b, Sum.inl y => b.1 y - | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i - -lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : - decodeButterfly d (encodeButterfly d b) = b := by - induction d with - | zero => exact Unit.ext _ _ - | succ d ih => - apply Prod.ext - · rfl - · funext ε - exact ih (b.2 ε) - -lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : - encodeButterfly d (decodeButterfly d ω) = ω := by - induction d with - | zero => funext i; exact Empty.elim i - | succ d ih => - funext i - cases i with - | inl y => rfl - | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 - -def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where - toFun := decodeButterfly d - invFun := encodeButterfly d - left_inv := encode_decodeButterfly d - right_inv := decode_encodeButterfly d - -noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) - | 0, _, _ => ∅ - | d + 1, x, y => by - classical - exact insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) - -def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool - | 0, _, _, i => nomatch i - | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) - | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.Model + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp + +open scoped BigOperators +open Filter + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Card d → Bool + +instance (d : ℕ) : Fintype (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +instance (d : ℕ) : Nonempty (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +def rotate (d : ℕ) : Equiv.Perm (Card d) where + toFun x i := x (finRotate d i) + invFun x i := x ((finRotate d).symm i) + left_inv x := by funext i; simp only [Equiv.apply_symm_apply] + right_inv x := by funext i; simp only [Equiv.symm_apply_apply] + +def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, ξ => rotate (d + 1) * pairSwitch ξ + +def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) + | 0, _ => 1 + | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) + +noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := + (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / + (Fintype.card (Fin t → Coins d) : ℝ) + +noncomputable def distance (d t : ℕ) : ℝ := + (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| + +noncomputable def mixingTime (d : ℕ) : ℕ := + sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} + +noncomputable def supportTimeBound (d : ℕ) : ℤ := + ⌈(2 / (2 : ℝ) ^ d) * + (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ + +def OptimalOrder : Prop := + ∃ C : ℕ, 0 < C ∧ + Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ + (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ + (∀ᶠ d : ℕ in atTop, + supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ + (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) + +noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by + classical + exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) + +lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : + ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by + classical + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : + 0 ≤ finiteLaw f b := by + exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : + ∑ b, finiteLaw f b = 1 := by + classical + simp only [finiteLaw, ← Finset.sum_div] + have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by + exact_mod_cast sum_card_fibers f + rw [hc] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by + classical + have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr + ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ + simp [finiteLaw] + +lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] + (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : + (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by + have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := + Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) + have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) + have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) + have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) + rw [hpq] at hz + rw [← Finset.sum_sub_distrib] + linarith + +lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] + [Fintype β] [Nonempty β] (f : α → β) : + 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ + (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by + classical + let s := Finset.univ.image f + have hs : ∑ b ∈ s, finiteLaw f b = 1 := by + have h := Finset.sum_subset (Finset.subset_univ s) + (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) + simpa only [finiteLaw_sum] using h + have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] + have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by + rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] + have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s + rw [hs] at he + have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by + simp [div_eq_mul_inv] + rw [hsq] at he + have hcard : (s.card : ℝ) ≤ Fintype.card α := by + exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) + have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) + linarith + +lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by + simp [Card] + +lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by + rw [Fintype.card_perm, card_positions] + +lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by + rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] + +lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : + law d t g = finiteLaw (run d t) g := by + unfold law finiteLaw + apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) + exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) + +lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by + rw [law_eq_finiteLaw] + exact finiteLaw_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by + simp only [law_eq_finiteLaw] + exact finiteLaw_sum (run d t) + +lemma physical_support_bound_succ (d t : ℕ) : + 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by + have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ + have h := finiteLaw_support_bound (run (d + 1) t) + rw [card_tapes_succ, card_permutations] at h + simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h + +lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : + step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by + change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ + rw [Fin.snoc_eq_cons_rotate] + rfl + +lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by + unfold distance + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + +lemma physical_support_bound (d t : ℕ) : + 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by + cases d with + | zero => + have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) + simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using + le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) + | succ d => + have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by + push_cast + rw [pow_succ] + ring + rw [he, Real.rpow_natCast] + exact physical_support_bound_succ d t + +lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : + supportTimeBound d ≤ (t : ℤ) := by + have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity + have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hb := physical_support_bound d t + have hp : (3 / 4 : ℝ) ≤ + (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by + linarith + have hr := (le_div_iff₀ hF).mp hp + have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr + rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog + unfold supportTimeBound + apply Int.ceil_le.mpr + simp only [Int.cast_natCast] + calc + 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = + Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by + field_simp + _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by + nlinarith [hlog]) + +lemma supportTimeBound_le_mixingTime {d : ℕ} + (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : + supportTimeBound d ≤ (mixingTime d : ℤ) := by + exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) + +lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : + (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by + have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) + have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) + have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by + have := Real.pi_gt_three + linarith) + linarith + +lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) + have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by + rw [← Real.log_inv] + congr 1 + norm_num + rw [he] at h + linarith + +lemma linear_le_supportTimeBound (d : ℕ) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by + have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) + have hNp : 0 < (2 : ℝ) ^ d := by positivity + have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) + have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + rw [Real.log_mul (by norm_num) (by positivity)] + push_cast at hf + rw [Real.log_pow] at hf + linarith [log_three_quarters_lower] + apply le_trans _ (Int.le_ceil _) + have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) = + (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by + field_simp + ring + rw [hcancel] + linarith + convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 + field_simp + +lemma linear_le_time_of_distance_le (d t : ℕ) + (ht : distance d t ≤ (1 / 4 : ℝ)) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by + have h := supportTimeBound_le_of_distance_le d t ht + have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h + exact (linear_le_supportTimeBound d).trans hr + +lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc := Real.strictConcave_binEntropy.concaveOn.2 + (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show 0 ≤ 1 - 2 * p by linarith) + (show 0 ≤ 2 * p by positivity) + (show (1 - 2 * p) + 2 * p = 1 by ring) + simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, + smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc + +lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + wlog hab : a ≤ b generalizing a b + · have hba := this b a hb ha (le_of_not_ge hab) + simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) + rw [min_eq_left hab] + by_cases hz : a = 0 + · subst a + simp + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) + have hbp : 0 < b := hap.trans_le hab + have hs : 0 < a + b := add_pos hap hbp + have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le + have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) + have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le + have he : (a + b) * Real.binEntropy (a / (a + b)) = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + unfold Real.binEntropy + rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] + simp only [Real.log_inv] + rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), + Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] + field_simp + ring + rw [he] at hc + calc + 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by + field_simp + _ ≤ _ := hc + +noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail + +lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by + classical + unfold childMarks + apply Finset.card_image_iff.mpr + intro x hx y hy hxy + have hx0 := (Finset.mem_filter.mp hx).2 + have hy0 := (Finset.mem_filter.mp hy).2 + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] + +lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : + (childMarks s false).card + (childMarks s true).card = s.card := by + classical + rw [card_childMarks, card_childMarks] + simpa only [Bool.not_eq_false] using + (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) + +noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) : Finset (Card d) := + ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ + ((childMarks s true).image (butterflyPerm d (b.2 true))) + +lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : + (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by + classical + apply le_min + · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) + · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) + +noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ + | 0, _, _ => 0 + | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card + +lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + induction d with + | zero => + simp only [encounters, Nat.cast_zero] + have hs : s.card ≤ 1 := by + simpa [Card] using Finset.card_le_univ s + interval_cases s.card <;> simp + | succ d ih => + have h₀ := ih (b.2 false) (childMarks s false) + have h₁ := ih (b.2 true) (childMarks s true) + have ht : ((topMeetings b s).card : ℝ) ≤ + min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by + exact_mod_cast card_topMeetings_le b s + have he := split_entropy_lower ((childMarks s false).card : ℝ) + ((childMarks s true).card : ℝ) (by positivity) (by positivity) + have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by + exact_mod_cast card_childMarks_add s + rw [hs] at he + have hL : 0 < 2 * Real.log 2 := by positivity + rw [le_div_iff₀ hL] at h₀ h₁ ⊢ + simp only [encounters, Nat.cast_add] + nlinarith [mul_le_mul_of_nonneg_right ht hL.le] + +lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by + by_cases ha : a ∈ s + · rw [ite_eq_left ha] + exact (Finset.mul_prod_erase s f ha).symm + · simp [ha] + +lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) + (a b : α) (hab : a ≠ b) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * + ∏ i ∈ (s.erase a).erase b, f i := by + calc + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := + prod_split_at s f a + _ = _ := by + rw [prod_split_at (s.erase a) f b] + have hm : (b ∈ s.erase a) ↔ b ∈ s := + ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ + simp only [hm, mul_assoc] + +lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ + ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by + by_cases hab : a = b + · subst b + simp only [Equiv.swap_self, Equiv.refl_apply] + have h : (fun i => (p i + p i) / 2) = p := by funext i; ring + rw [h] + linarith + let t := (s.erase a).erase b + have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by + intro i hi + exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) + have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) + rw [prod_split_two s p a b hab, + prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, + prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] + change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + + (if a ∈ s then p (Equiv.swap a b a) else 1) * + (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ + rw [hprod] + change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * + (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * + (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) + rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] + have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) + by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] + · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht + nlinarith + all_goals ring_nf; rfl + +def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := + ∀ s, m s ≤ ∏ i ∈ s, p i + +lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] + {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) + (fun i => (p i + p (Equiv.swap a b i)) / 2) := by + intro s + have h₀ := h s + have h₁ := h (s.image (Equiv.swap a b)) + rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ + exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans + (swap_average_product s p hp a b) + +noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : ℝ := by + classical + exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) + +lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by + classical + unfold inclusionMoment finiteMean + positivity + +lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : + (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by + by_cases h : s ⊆ A + · rw [ite_eq_left h] + exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm + · rw [ite_eq_right h] + obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h + exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm + +lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] + (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = + if s ⊆ A then 1 else 0 := by + classical + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] + +lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : + CylinderBound (inclusionMoment (fun _ : Ω => A)) + (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by + classical + intro s + simp only [inclusionMoment_const, Finset.singleton_subset_iff] + exact (indicator_subset_prod A s).le + +noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] + (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := + fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 + +lemma subset_swap_image_iff {α : Type*} [DecidableEq α] + (A s : Finset α) (a b : α) : + s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by + constructor + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + +lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) (s : Finset α) : + inclusionMoment (fairSetSwap F a b) s = + (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by + classical + simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, + fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, + Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] + rw [div_mul_eq_div_div, add_div] + ring_nf + +lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) + (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : + CylinderBound (inclusionMoment (fairSetSwap F a b)) + (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by + classical + have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b + intro s + simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s + +def SwitchSamples : ℕ → Type + | 0 => Unit + | n + 1 => SwitchSamples n × Bool + +instance (n : ℕ) : Fintype (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Fintype Unit) + | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) + +instance (n : ℕ) : Nonempty (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) + +noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : + (L : List (α × α)) → SwitchSamples L.length → Finset α + | [], _ => A + | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω + +lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) + (L : List (α × α)) : + CylinderBound (inclusionMoment (switchedSet A L)) + (fun i => inclusionMoment (switchedSet A L) {i}) := by + induction L with + | nil => exact cylinder_const A + | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih + +inductive QueryTree (ι : Type*) + | reject : QueryTree ι + | accept : QueryTree ι + | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι + | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι + +namespace QueryTree + +variable {ι : Type*} [DecidableEq ι] + +def queries : QueryTree ι → Finset ι + | reject => ∅ + | accept => ∅ + | branch i zero one => insert i (queries zero ∪ queries one) + | force i _ next => insert i (queries next) + +def Fresh : QueryTree ι → Prop + | reject => True + | accept => True + | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one + | force i _ next => i ∉ queries next ∧ Fresh next + +def weighted : QueryTree ι → (ι → Bool) → ℝ + | reject, _ => 0 + | accept, _ => 1 + | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω + | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 + +omit [DecidableEq ι] in +lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by + induction T with + | reject => exact le_rfl + | accept => exact zero_le_one + | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ + | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl + +lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} + (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by + induction T with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), + ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] + | force i b next ih => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] + +def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := + (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by + intro ω + funext j + by_cases h : j = i + · subst j; simp + · simp [Function.update_of_ne h]).toPerm + +lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by + change Function.update ω i (!(ω i)) i = _ + exact Function.update_self _ _ _ + +lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : + flipCoin i ω j = ω j := by + change Function.update ω i (!(ω i)) j = _ + exact Function.update_of_ne h _ _ + +lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) + (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by + apply weighted_congr + intro j hj + exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω + +lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) + (hf : ∀ ω, f (flipCoin i ω) = f ω) : + finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by + let g := fun ω : ι → Bool => if ω i = b then f ω else 0 + have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by + dsimp [g] + rw [flipCoin_apply_eq, hf] + cases hω : ω i <;> cases b <;> simp + have hs := Equiv.sum_comp (flipCoin i) g + have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun ω _ => hp ω) + unfold finiteMean + change (∑ ω, g ω) / _ = _ + rw [hs] at hadd + have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith + rw [hh] + ring + +lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : + finiteMean T.weighted ≤ 1 := by + induction T with + | reject => simp [weighted, finiteMean] + | accept => simp [weighted, finiteMean] + | branch i zero one ih₀ ih₁ => + obtain ⟨hz, ho, hfz, hfo⟩ := hT + have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) + have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) + have he : finiteMean (branch i zero one).weighted = + finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + + finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by + unfold finiteMean + rw [← add_div, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + cases hω : ω i <;> simp [weighted, hω] + rw [he, h₀, h₁] + linarith [ih₀ hfz, ih₁ hfo] + | force i b next ih => + obtain ⟨hi, hn⟩ := hT + have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) + have he : finiteMean (force i b next).weighted = + 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by + unfold finiteMean + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : ω i = b <;> simp [weighted, h] + rw [he, hm] + linarith [ih hn] + +def succeeds : QueryTree ι → (ι → Bool) → Bool + | reject, _ => false + | accept, _ => true + | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω + | force i b next, ω => if ω i = b then succeeds next ω else false + +def charge : QueryTree ι → (ι → Bool) → ℕ + | reject, _ => 0 + | accept, _ => 0 + | branch i zero one, ω => if ω i then charge one ω else charge zero ω + | force i b next, ω => if ω i = b then charge next ω + 1 else 0 + +omit [DecidableEq ι] in +lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : + T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by + induction T with + | reject => rfl + | accept => norm_num [weighted, succeeds, charge] + | branch i zero one ih₀ ih₁ => + cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] + | force i b next ih => + by_cases h : ω i = b + · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] + cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] + · simp [weighted, succeeds, h] + +lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) + (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : + finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by + have hw (ω : ι → Bool) : + (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by + rw [weighted_eq] + cases hs : T.succeeds ω + · simp + · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) + have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ + have hm := div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn + rw [← Finset.mul_sum, mul_div_assoc] at hm + change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ + finiteMean T.weighted at hm + exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by + rw [mul_comm] + exact hm.trans (mean_weighted_le_one T hT)) + +end QueryTree + +def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool + | 0, _, i => nomatch i + | _d + 1, b, Sum.inl y => b.1 y + | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i + +lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : + decodeButterfly d (encodeButterfly d b) = b := by + induction d with + | zero => exact Unit.ext _ _ + | succ d ih => + apply Prod.ext + · rfl + · funext ε + exact ih (b.2 ε) + +lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : + encodeButterfly d (decodeButterfly d ω) = ω := by + induction d with + | zero => funext i; exact Empty.elim i + | succ d ih => + funext i + cases i with + | inl y => rfl + | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 + +def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where + toFun := decodeButterfly d + invFun := encodeButterfly d + left_inv := encode_decodeButterfly d + right_inv := decode_encodeButterfly d + +noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) + | 0, _, _ => ∅ + | d + 1, x, y => by + classical + exact insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) + +def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool + | 0, _, _, i => nomatch i + | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) + | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/ColoredEmbedding.lean b/lean/OAI/Probability/ThorpRouting/HighTail/ColoredEmbedding.lean index 64a9d939795da92fe762ea82ff0bdd776fdd3660..ec0e2aa35469e95de6bc1b27158e972082ec92a1 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/ColoredEmbedding.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/ColoredEmbedding.lean @@ -1,842 +1,842 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.ProjectCycle - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) - (a : ℝ) (ha : 0 ≤ a) : - (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)))^(1+a) ≤ - (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * - ∑ c ∈ compatibleSet x y, - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by - classical - rw [sandwich_mean,sum_colors_factor] - let f (c : ι → Bool) : ℝ := - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) - have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) - (tupleProbability_nonneg _ _ _) - rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] - have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) - (show 1 ≤ 1+a by linarith) (fun c _ => hf c) - have he : 1+a-1=a := by ring - rw [he] at hh - calc - _ ≤ (outerWeight x y)^(1+a) * - (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := - mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) - _ = _ := by - rw [←mul_assoc] - congr 1 - apply Finset.sum_congr rfl - intro c _ - exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) - -end PairRouting - -lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - childLift p * childLift q = childLift (fun b => p b * q b) := by - ext x i - simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] - -lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl - -lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl - -lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * - pairSwitch coins.1 := by - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * - (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : - headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl - -lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : - headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl - -lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : - headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) - (headTailEquiv d x) := by - rw [palindromePerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by - obtain ⟨x,hx⟩ := C.nonempty - have hpx : alternatingPerm p x ∈ C.val := by - rw [←C.orbit_eq hx,mem_orbitSet] - exact (Equiv.Perm.SameCycle.refl _ _).apply_right - have hne : x ≠ alternatingPerm p x := by - intro he - have hh := congrArg Prod.fst he - rw [alternatingPerm_flip] at hh - cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh - have hs : {x,alternatingPerm p x} ⊆ C.val := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl <;> assumption - have hh := Finset.card_le_card hs - simpa only [Finset.card_pair hne] using hh - -lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : - 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by - classical - calc - _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] - _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := - Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) - _ ≤ _ := RoutingNetwork.cycleMass_le _ _ - -lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) - (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by - have h := alternating_cycle_count_double p S - omega - -end CycleColoring - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - 2 * alternatingCycles e p ≤ Fintype.card ι := by - have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) - simpa only [alternatingCycles, card_labelSet] using hh - -lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by - have hh := alternatingCycles_double e p - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : - colors x (chosenCoin x c) = c := by - funext i - simp only [colors,chosenCoin_apply x c hc i,required] - cases (x i).1 <;> cases c i <;> rfl - -noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : - ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) - -omit [Fintype α] [DecidableEq ι] in -lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - coloredEmbedding x c hc i = (c i,(x i).2) := by - apply Prod.ext - · exact congrFun (colors_chosenCoin x c hc) i - · rfl - -omit [Fintype α] [DecidableEq ι] in -lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) - (ξ : α → Bool) (he : colors x ξ = c) : - switchedEmbedding x ξ = coloredEmbedding x c hc := by - ext i : 1 - rw [coloredEmbedding_apply] - apply Prod.ext - · exact congrFun he i - · rfl - -lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - (compatibleSet x y).card ≤ - 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + - alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by - obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc - let ξ := chosenCoin x c - let η := chosenCoin y c - have he : routedEmbedding x ξ η p = y := by - ext i : 1 - have h := (sandwich_matches_iff ξ η p x y).mpr - ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by - simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ - exact h i - have hh := assignments_actual_bound x ξ η p - rw [he] at hh - rw [card_compatibleSet] - exact hh - -omit [Fintype α] [DecidableEq ι] in -lemma occupied_sum_ge (x y : ι ↪ Bool × α) : - Fintype.card ι ≤ (occupied x).card + (occupied y).card := by - have h₀ := occupied_card_double x - have h₁ := occupied_card_double y - omega - -lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ - (2:ℝ)^((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by - let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p - let b := (occupied x).card+(occupied y).card - let h := Fintype.card ι - have hb : h ≤ b := occupied_sum_ge x y - have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by - exact_mod_cast assignments_match_bound x y c hc p hm - change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) - rw [mul_one_div] - calc - _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) - _ = _ := by - rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] - congr 1 - rw [Nat.cast_add,Nat.cast_sub hb] - ring - -lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) - (a : ℝ) (ha : 0 ≤ a) : - (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ - (2:ℝ)^(((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by - have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) - (assignment_weight_bound x y c hc p hm) ha - rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), - ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h - simpa only [mul_comm] using h - - -lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, - if ChildMatches p x y c.val then W c.val else 0 := by - rw [sandwich_weighted_probability] - congr 1 - rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] - -omit [Fintype α] [DecidableEq α] [DecidableEq ι] in -lemma color_card_add (c : ι → Bool) : - Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by - have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by - cases c i <;> simp - rw [Fintype.card_congr he] - rw [Fintype.card_subtype_compl] - exact Nat.add_sub_of_le (Fintype.card_subtype_le _) - -end PairRouting - -noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) - (ω : BenesCoins d × BenesCoins d) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => palindromePerm d (if b then ω.2 else ω.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 - -lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : - palindromeCost (d+1) e σ = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) - (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by - unfold palindromeCost assignmentCost - dsimp only - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - -lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [palindromeCost_eq] - simp only [Equiv.apply_symm_apply] - -noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : BenesCoins d => - if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) - -lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma palindrome_matches_step (d : ℕ) {ι : Type*} - (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] - rfl - -lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (d+1)) (a : ℝ) : - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - routingMoment (d+1) e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have he (ω : BenesCoins d × BenesCoins d) : - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [palindrome_matches_step,palindromeCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold routingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = - (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (d+1)) : - PairRouting.tupleProbability (palindromePerm (d+1)) e f = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have hp (b : Bool) (p q : BenesCoins d) : - palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by - cases b <;> rfl - simp only [palindrome_matches_step,hp] - -lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) - rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh - have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = - -(d:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - rwa [he] at hh - -lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - -theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by - classical - induction d generalizing ι with - | zero => - have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := - fun _ _ => Subsingleton.elim _ _ - simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] - | succ d ih => - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) - have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha - rw [←palindrome_probability_step d e f] at hnode - change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) - ring - -lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : - (∑ f : ι ↪ Card d, routingMoment d e f a) = - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - unfold routingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] - (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : - finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = - (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] - rw [Real.rpow_add hn,Real.rpow_one] - field_simp - -noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card d => - ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) - -lemma density_normalization (d h n : ℕ) (a : ℝ) : - (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by - rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] - rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, - Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] - -theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - palindromeRowMoment d e a ≤ - (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card d) := ⟨e⟩ - rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * - ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, - Fintype.card_embedding_eq,card_positions] - norm_cast - -end Thorp -namespace Thorp - -lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] - (A : Finset α) (T : β → Finset α) : - (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = - ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by - classical - by_cases h : Finset.univ.biUnion T ⊆ A - · rw [ite_eq_left h] - symm - apply Finset.prod_eq_one - intro b _ - rw [ite_eq_left] - exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h - · rw [ite_eq_right h] - obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h - obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - rw [ite_eq_right] - exact fun hb => hxA (hb hxb) - -lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] - [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] - (F : Ω → Finset α) (p : α → ℝ) - (hF : CylinderBound (inclusionMoment F) p) - (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) - (hc : ∀ b s, 0 ≤ c b s) - (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : - finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ - ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by - classical - simp_rw [Fintype.prod_sum] - rw [finiteMean_sum] - apply Finset.sum_le_sum - intro s _ - let U := Finset.univ.biUnion (fun b => T b (s b)) - have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = - fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by - funext ω - rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] - exact mul_comm _ _ - rw [he,finiteMean_mul_const] - have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by - intro b _ b' _ hbb - exact hd b b' hbb (s b) (s b') - have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - by_cases hh : U ⊆ F ω <;> simp [hh] - calc - _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := - mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) - _ = _ := by - dsimp only [U] - rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro b _ - exact mul_comm _ _ - - -noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := - if T.card = 1 then 0 else w^T.card - -lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : - 0 ≤ sparseCoefficient w T := by - unfold sparseCoefficient - split_ifs <;> positivity - -lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) - (w : ℝ) (hw : 0 ≤ w) : - w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ - ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by - classical - let V := D ∩ A - let T : ↑D.powerset := if 2 ≤ V.card then - ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else - ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ - calc - _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by - by_cases h : 2 ≤ V.card - · have hn : V.card ≠ 1 := by omega - simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] - · simp [T,ite_eq_right h,sparseCoefficient,V] at * - _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => - sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) - (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) - (by split_ifs <;> norm_num)) (Finset.mem_univ T) - -lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : - ∑ i ∈ Finset.range n, x^i ≤ 2 := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ',pow_zero] - simp only [pow_succ',←Finset.mul_sum] - nlinarith - -lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : - ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ - 1 + 2*((R:ℝ)*z)^2 := by - classical - let x := (R:ℝ)*z - have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz - have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ - if i=1 then 0 else x^i := by - by_cases h : i=1 - · simp [h] - · simp only [ite_eq_right h] - dsimp [x] - rw [mul_pow] - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) - exact_mod_cast Nat.choose_le_pow R i - calc - _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := - Finset.sum_le_sum (fun i _ => hbound i) - _ ≤ 1+2*x^2 := by - rcases R with _ | R - · simp [x] - rcases R with _ | R - · norm_num [Finset.sum_range_succ] - positivity - have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = - 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by - rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] - have hn (i : ℕ) : 2+i ≠ 1 := by omega - simp only [hn,ite_false,pow_add,←Finset.mul_sum] - norm_num [Finset.sum_range_succ] - rw [he] - have hg := geometric_sum_half (R+1) hx hr - nlinarith [sq_nonneg x] - -lemma sparse_block_product_bound {α : Type*} [DecidableEq α] - (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : - ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ - Real.exp (2*((D.card:ℝ)*(p*w))^2) := by - classical - have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = - ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by - rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] - have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = - fun T => if T.card=1 then 0 else (p*w)^T.card := by - funext T - unfold sparseCoefficient - split_ifs <;> simp [mul_pow,mul_comm] - change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ - rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] - simp only [nsmul_eq_mul] - rw [he] - exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans - (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) - - -noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] - (D : β → Finset α) (A : Finset α) : ℕ := - ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 - -theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] - (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hF : ∀ T, inclusionMoment F T ≤ p^T.card) - (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : - finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by - classical - have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by - intro T - simpa only [Finset.prod_const] using hF T - have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc - (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) - (fun _ S => sparseCoefficient_nonneg w hw S.val) - (fun b b' h S S' => (hd h).mono - (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) - calc - _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, - sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by - apply finiteMean_mono - intro ω - rw [sparseMass,←Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) - intro b _ - exact sparse_block_pointwise (F ω) (D b) w hw - _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by - simpa only [Finset.prod_const] using hb - _ ≤ _ := by - rw [Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact Finset.sum_nonneg (fun S _ => mul_nonneg - (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) - · intro b _ - exact sparse_block_product_bound (D b) p w hp hw (hr b) - -theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] - (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) - (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : - finiteMean (fun ω : SwitchIndex d → Bool => - w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by - apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w - (by positivity) hw - · exact inverseButterflyMarks_inclusion d A - · exact hr - - -def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 - -lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by - unfold crowdedMass - split_ifs <;> omega - -lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by - unfold crowdedMass - split_ifs <;> omega - -lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by - unfold crowdedMass - split_ifs with h - · have hh := PairRouting.alternatingCycles_double e p - omega - · rw [PairRouting.alternatingCycles_zero e p (by omega)] - -lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by - classical - induction d generalizing ι with - | zero => simp [palindromeCost] - | succ d ih => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 - have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 - have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) - have hs := crowdedMass_add (Fintype.card {i // c i = false}) - (Fintype.card {i // c i = true}) - rw [PairRouting.color_card_add] at hs - change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ - nlinarith - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.ProjectCycle + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) + (a : ℝ) (ha : 0 ≤ a) : + (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)))^(1+a) ≤ + (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * + ∑ c ∈ compatibleSet x y, + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by + classical + rw [sandwich_mean,sum_colors_factor] + let f (c : ι → Bool) : ℝ := + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) + have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) + (tupleProbability_nonneg _ _ _) + rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] + have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) + (show 1 ≤ 1+a by linarith) (fun c _ => hf c) + have he : 1+a-1=a := by ring + rw [he] at hh + calc + _ ≤ (outerWeight x y)^(1+a) * + (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := + mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) + _ = _ := by + rw [←mul_assoc] + congr 1 + apply Finset.sum_congr rfl + intro c _ + exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) + +end PairRouting + +lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + childLift p * childLift q = childLift (fun b => p b * q b) := by + ext x i + simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] + +lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl + +lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl + +lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * + pairSwitch coins.1 := by + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * + (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : + headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl + +lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : + headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl + +lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : + headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) + (headTailEquiv d x) := by + rw [palindromePerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by + obtain ⟨x,hx⟩ := C.nonempty + have hpx : alternatingPerm p x ∈ C.val := by + rw [←C.orbit_eq hx,mem_orbitSet] + exact (Equiv.Perm.SameCycle.refl _ _).apply_right + have hne : x ≠ alternatingPerm p x := by + intro he + have hh := congrArg Prod.fst he + rw [alternatingPerm_flip] at hh + cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh + have hs : {x,alternatingPerm p x} ⊆ C.val := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl <;> assumption + have hh := Finset.card_le_card hs + simpa only [Finset.card_pair hne] using hh + +lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : + 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by + classical + calc + _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] + _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := + Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) + _ ≤ _ := RoutingNetwork.cycleMass_le _ _ + +lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) + (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by + have h := alternating_cycle_count_double p S + omega + +end CycleColoring + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + 2 * alternatingCycles e p ≤ Fintype.card ι := by + have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) + simpa only [alternatingCycles, card_labelSet] using hh + +lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by + have hh := alternatingCycles_double e p + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : + colors x (chosenCoin x c) = c := by + funext i + simp only [colors,chosenCoin_apply x c hc i,required] + cases (x i).1 <;> cases c i <;> rfl + +noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : + ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) + +omit [Fintype α] [DecidableEq ι] in +lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + coloredEmbedding x c hc i = (c i,(x i).2) := by + apply Prod.ext + · exact congrFun (colors_chosenCoin x c hc) i + · rfl + +omit [Fintype α] [DecidableEq ι] in +lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) + (ξ : α → Bool) (he : colors x ξ = c) : + switchedEmbedding x ξ = coloredEmbedding x c hc := by + ext i : 1 + rw [coloredEmbedding_apply] + apply Prod.ext + · exact congrFun he i + · rfl + +lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + (compatibleSet x y).card ≤ + 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + + alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by + obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc + let ξ := chosenCoin x c + let η := chosenCoin y c + have he : routedEmbedding x ξ η p = y := by + ext i : 1 + have h := (sandwich_matches_iff ξ η p x y).mpr + ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by + simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ + exact h i + have hh := assignments_actual_bound x ξ η p + rw [he] at hh + rw [card_compatibleSet] + exact hh + +omit [Fintype α] [DecidableEq ι] in +lemma occupied_sum_ge (x y : ι ↪ Bool × α) : + Fintype.card ι ≤ (occupied x).card + (occupied y).card := by + have h₀ := occupied_card_double x + have h₁ := occupied_card_double y + omega + +lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ + (2:ℝ)^((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by + let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p + let b := (occupied x).card+(occupied y).card + let h := Fintype.card ι + have hb : h ≤ b := occupied_sum_ge x y + have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by + exact_mod_cast assignments_match_bound x y c hc p hm + change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) + rw [mul_one_div] + calc + _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by + rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] + congr 1 + rw [Nat.cast_add,Nat.cast_sub hb] + ring + +lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) + (a : ℝ) (ha : 0 ≤ a) : + (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ + (2:ℝ)^(((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by + have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) + (assignment_weight_bound x y c hc p hm) ha + rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), + ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h + simpa only [mul_comm] using h + + +lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, + if ChildMatches p x y c.val then W c.val else 0 := by + rw [sandwich_weighted_probability] + congr 1 + rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] + +omit [Fintype α] [DecidableEq α] [DecidableEq ι] in +lemma color_card_add (c : ι → Bool) : + Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by + have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by + cases c i <;> simp + rw [Fintype.card_congr he] + rw [Fintype.card_subtype_compl] + exact Nat.add_sub_of_le (Fintype.card_subtype_le _) + +end PairRouting + +noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) + (ω : BenesCoins d × BenesCoins d) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => palindromePerm d (if b then ω.2 else ω.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 + +lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : + palindromeCost (d+1) e σ = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) + (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by + unfold palindromeCost assignmentCost + dsimp only + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + +lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [palindromeCost_eq] + simp only [Equiv.apply_symm_apply] + +noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : BenesCoins d => + if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) + +lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma palindrome_matches_step (d : ℕ) {ι : Type*} + (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] + rfl + +lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (d+1)) (a : ℝ) : + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + routingMoment (d+1) e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have he (ω : BenesCoins d × BenesCoins d) : + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [palindrome_matches_step,palindromeCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold routingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = + (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (d+1)) : + PairRouting.tupleProbability (palindromePerm (d+1)) e f = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have hp (b : Bool) (p q : BenesCoins d) : + palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by + cases b <;> rfl + simp only [palindrome_matches_step,hp] + +lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) + rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh + have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = + -(d:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + rwa [he] at hh + +lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + +theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by + classical + induction d generalizing ι with + | zero => + have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := + fun _ _ => Subsingleton.elim _ _ + simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] + | succ d ih => + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) + have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha + rw [←palindrome_probability_step d e f] at hnode + change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) + ring + +lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : + (∑ f : ι ↪ Card d, routingMoment d e f a) = + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + unfold routingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] + (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : + finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = + (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] + rw [Real.rpow_add hn,Real.rpow_one] + field_simp + +noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card d => + ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) + +lemma density_normalization (d h n : ℕ) (a : ℝ) : + (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by + rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] + rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, + Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] + +theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + palindromeRowMoment d e a ≤ + (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card d) := ⟨e⟩ + rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * + ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, + Fintype.card_embedding_eq,card_positions] + norm_cast + +end Thorp +namespace Thorp + +lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] + (A : Finset α) (T : β → Finset α) : + (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = + ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by + classical + by_cases h : Finset.univ.biUnion T ⊆ A + · rw [ite_eq_left h] + symm + apply Finset.prod_eq_one + intro b _ + rw [ite_eq_left] + exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h + · rw [ite_eq_right h] + obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h + obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + rw [ite_eq_right] + exact fun hb => hxA (hb hxb) + +lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] + [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] + (F : Ω → Finset α) (p : α → ℝ) + (hF : CylinderBound (inclusionMoment F) p) + (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) + (hc : ∀ b s, 0 ≤ c b s) + (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : + finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ + ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by + classical + simp_rw [Fintype.prod_sum] + rw [finiteMean_sum] + apply Finset.sum_le_sum + intro s _ + let U := Finset.univ.biUnion (fun b => T b (s b)) + have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = + fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by + funext ω + rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] + exact mul_comm _ _ + rw [he,finiteMean_mul_const] + have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by + intro b _ b' _ hbb + exact hd b b' hbb (s b) (s b') + have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + by_cases hh : U ⊆ F ω <;> simp [hh] + calc + _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := + mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) + _ = _ := by + dsimp only [U] + rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro b _ + exact mul_comm _ _ + + +noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := + if T.card = 1 then 0 else w^T.card + +lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : + 0 ≤ sparseCoefficient w T := by + unfold sparseCoefficient + split_ifs <;> positivity + +lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) + (w : ℝ) (hw : 0 ≤ w) : + w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ + ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by + classical + let V := D ∩ A + let T : ↑D.powerset := if 2 ≤ V.card then + ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else + ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ + calc + _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by + by_cases h : 2 ≤ V.card + · have hn : V.card ≠ 1 := by omega + simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] + · simp [T,ite_eq_right h,sparseCoefficient,V] at * + _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => + sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) + (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) + (by split_ifs <;> norm_num)) (Finset.mem_univ T) + +lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : + ∑ i ∈ Finset.range n, x^i ≤ 2 := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ',pow_zero] + simp only [pow_succ',←Finset.mul_sum] + nlinarith + +lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : + ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ + 1 + 2*((R:ℝ)*z)^2 := by + classical + let x := (R:ℝ)*z + have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz + have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ + if i=1 then 0 else x^i := by + by_cases h : i=1 + · simp [h] + · simp only [ite_eq_right h] + dsimp [x] + rw [mul_pow] + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) + exact_mod_cast Nat.choose_le_pow R i + calc + _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := + Finset.sum_le_sum (fun i _ => hbound i) + _ ≤ 1+2*x^2 := by + rcases R with _ | R + · simp [x] + rcases R with _ | R + · norm_num [Finset.sum_range_succ] + positivity + have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = + 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by + rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] + have hn (i : ℕ) : 2+i ≠ 1 := by omega + simp only [hn,ite_false,pow_add,←Finset.mul_sum] + norm_num [Finset.sum_range_succ] + rw [he] + have hg := geometric_sum_half (R+1) hx hr + nlinarith [sq_nonneg x] + +lemma sparse_block_product_bound {α : Type*} [DecidableEq α] + (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : + ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ + Real.exp (2*((D.card:ℝ)*(p*w))^2) := by + classical + have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = + ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by + rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] + have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = + fun T => if T.card=1 then 0 else (p*w)^T.card := by + funext T + unfold sparseCoefficient + split_ifs <;> simp [mul_pow,mul_comm] + change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ + rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] + simp only [nsmul_eq_mul] + rw [he] + exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans + (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) + + +noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] + (D : β → Finset α) (A : Finset α) : ℕ := + ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 + +theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] + (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hF : ∀ T, inclusionMoment F T ≤ p^T.card) + (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : + finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by + classical + have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by + intro T + simpa only [Finset.prod_const] using hF T + have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc + (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) + (fun _ S => sparseCoefficient_nonneg w hw S.val) + (fun b b' h S S' => (hd h).mono + (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) + calc + _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, + sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by + apply finiteMean_mono + intro ω + rw [sparseMass,←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) + intro b _ + exact sparse_block_pointwise (F ω) (D b) w hw + _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by + simpa only [Finset.prod_const] using hb + _ ≤ _ := by + rw [Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact Finset.sum_nonneg (fun S _ => mul_nonneg + (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) + · intro b _ + exact sparse_block_product_bound (D b) p w hp hw (hr b) + +theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] + (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) + (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : + finiteMean (fun ω : SwitchIndex d → Bool => + w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by + apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w + (by positivity) hw + · exact inverseButterflyMarks_inclusion d A + · exact hr + + +def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 + +lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by + unfold crowdedMass + split_ifs <;> omega + +lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by + unfold crowdedMass + split_ifs <;> omega + +lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by + unfold crowdedMass + split_ifs with h + · have hh := PairRouting.alternatingCycles_double e p + omega + · rw [PairRouting.alternatingCycles_zero e p (by omega)] + +lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by + classical + induction d generalizing ι with + | zero => simp [palindromeCost] + | succ d ih => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 + have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 + have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + have hs := crowdedMass_add (Fintype.card {i // c i = false}) + (Fintype.card {i // c i = true}) + rw [PairRouting.color_card_add] at hs + change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ + nlinarith + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/CutoffMass.lean b/lean/OAI/Probability/ThorpRouting/HighTail/CutoffMass.lean index 78b5a4185cfab1add9a6adbc1d7a017ee6947065..645cc1f1c3d3ce879c2b53d94fbb6f9aad56125d 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/CutoffMass.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/CutoffMass.lean @@ -1,849 +1,849 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.ColoredEmbedding - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp - -noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, ι, _, e, ω => - if d+1 ≤ H then crowdedMass (Fintype.card ι) else - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = palindromeCost d e ω := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLowCost,palindromeCost,ite_eq_left h] - congr 2 <;> exact ih (by omega) _ _ - -lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by - classical - induction d generalizing ι with - | zero => simp [palindromeLowCost,cutoffMass] - | succ d ih => - by_cases h : d+1 ≤ H - · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] - exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) - · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] - exact Nat.add_le_add (ih _ _) (ih _ _) - - -noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := - Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) - -lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : - x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by - classical - constructor - · intro h - obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h - simp only [Equiv.apply_symm_apply] - · intro h - apply Finset.mem_image.mpr - refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ - rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] - -lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by - classical - rw [centralBlock,Finset.card_image_of_injective] - · exact card_positions H - · intro x y h - exact congrArg Prod.snd ((cardSplit r H).symm.injective h) - -lemma centralBlock_disjoint (r H : ℕ) : - Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by - classical - intro b b' h - apply Finset.disjoint_left.mpr - intro x hx hy - exact h (((mem_centralBlock r H b x).mp hx).symm.trans - ((mem_centralBlock r H b' x).mp hy)) - -lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by - classical - ext x - simp only [mem_centralBlock,Finset.mem_univ,iff_true] - exact Subsingleton.elim _ _ - -lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : - centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by - classical - simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, - Fin.cons_zero,Fin.tail_cons,Function.comp_def] - -lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : - centralBlock (r+1) H (Fin.cons b c) ∩ A = - (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by - classical - rw [centralBlock_step] - ext x - constructor - · intro hx - obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB - exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, - (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ - -lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : - sparseMass (centralBlock 0 H) A = crowdedMass A.card := by - classical - simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, - Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] - -lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : - sparseMass (centralBlock (r+1) H) A = - sparseMass (centralBlock r H) (childMarks A false) + - sparseMass (centralBlock r H) (childMarks A true) := by - classical - unfold sparseMass - rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl - simp only [Fintype.sum_bool,ht] - have hc (b : Bool) (c : Card r) : - (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = - (centralBlock r H c ∩ childMarks A b).card := by - rw [block_inter_step] - apply Finset.card_image_of_injective - intro x y h - simpa only [Fin.tail_cons] using congrArg Fin.tail h - simp only [hc] - exact add_comm _ _ - - -lemma inverseButterfly_coordinates_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) - (x : Card (d+1)) : - headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = - (Bool.xor (x 0) (ξ (Fin.tail x)), - (butterflyPerm d (decodeButterfly d - (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by - rw [butterflyPerm_step] - rfl - -lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : - childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) - ((coinStepEquiv d).symm (c,ξ))) b = - inverseButterflyMarks d - (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) - (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by - classical - let x := e.trans (headTailEquiv d).toEmbedding - let col := PairRouting.colors x ξ - let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b - have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = - (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := - inverseButterfly_coordinates_step d c ξ (e i) - ext y - simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, - Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] - constructor - · rintro ⟨i,hi⟩ - have he := congrArg (headTailEquiv d) hi - rw [hp i] at he - change (col i,_) = (b,y) at he - have hb := congrArg Prod.fst he - have hy := congrArg Prod.snd he - dsimp only at hb hy - refine ⟨⟨i,hb⟩,?_⟩ - change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y - simpa only [hb] using hy - · rintro ⟨i,hi⟩ - refine ⟨i.val,?_⟩ - apply (headTailEquiv d).injective - rw [hp] - change (col i.val,_) = (b,y) - have hb : col i.val = b := i.property - rw [hb] - exact Prod.ext rfl hi - -lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : - (inverseButterflyMarks d A ω).card = A.card := by - classical - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective - -lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : - ω.2 = (coinStepEquiv d).symm - (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by - change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) - exact ((coinStepEquiv d).symm_apply_apply ω.2).symm - -lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : - cutoffMass H (H+r) e ω = - sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by - classical - induction r generalizing ι with - | zero => - rw [sparseMass_central_zero,inverseButterflyMarks_card, - Finset.card_image_of_injective _ e.injective,Finset.card_univ] - cases H with - | zero => - have hcard : Fintype.card ι ≤ 1 := by - have hh := Fintype.card_le_of_injective e e.injective - simpa only [Nat.add_zero,card_positions,pow_zero] using hh - simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] - | succ H => simp only [cutoffMass,le_refl,ite_true] - | succ r ih => - simp only [Nat.add_succ] at * - rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] - let σ := benesStepEquiv (H+r) ω - let x := e.trans (headTailEquiv (H+r)).toEmbedding - let col := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + - cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ - rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] - rw [inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - - -theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ - Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by - classical - have hec : (Finset.univ.image e).card = Fintype.card ι := by - rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] - have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) - (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) - (pow_nonneg (by linarith) _) (fun b => by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) - calc - _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by - apply finiteMean_mono - intro ω - rw [←pow_mul] - exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) - _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => - (q^H)^(sparseMass (centralBlock r H) - (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by - simp_rw [cutoffMass_central] - simp only [finiteMean_prod,finiteMean_const] - _ ≤ _ := by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, - Finset.card_univ,card_positions,nsmul_eq_mul] using hm - -variable {α B : Type*} {r s : ℕ} - -def parallelFreshPre (pre : α ≃ B × Card (s+r)) - (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := - ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans - (Equiv.prodCongrRight (fun b => - (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans - (Equiv.prodAssoc _ _ _).symm - -def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := - (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) - (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post - -def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := - fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 - -lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : - relabeledPerm pre post (parallelAssembled lo hi) = - relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by - ext x - have h := butterfly_split r s (lo (pre x).1) - (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 - have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h - simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, - Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, - Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, - Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh - -theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] - (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ - (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by - simp_rw [parallel_exposed_perm] - exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq - -end Thorp -namespace Thorp -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] - -lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Fintype.card_congr - refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ - invFun := fun C => ⟨C.val,?_,C.property.2⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ - -lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : - orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by - ext y - simp only [mem_orbitSet,Finset.mem_image] - rw [Equiv.Perm.sameCycle_conj] - change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y - rw [Equiv.symm_apply_apply] - constructor - · intro h - exact ⟨g.symm y,h,g.apply_symm_apply y⟩ - · rintro ⟨z,hz,rfl⟩ - simpa only [Equiv.symm_apply_apply] using hz - -noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) - (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by - refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ - -lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : - Function.Injective (conjugateCycle p g S) := by - intro C D he - apply Subtype.ext - exact (Finset.image_injective g.injective) (congrArg Subtype.val he) - -lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Nat.le_antisymm - · have h := Fintype.card_le_of_injective _ - (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) - have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group - rw [inv_inv,hp] at h - have hs : (S.image g).image g.symm = S := by - ext x - simp only [Finset.mem_image] - constructor - · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ - have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he - exact hz' ▸ hz - · intro hx - exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ - change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h - rw [hs] at h - exact h - · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) - -lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false)) := by - have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) - simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h - -lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle - ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = - Fintype.card (RoutingNetwork.SelectedCycle - (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by - let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) - calc - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) - (S.image X₀.symm)) := by - change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ - have h := (selectedCycle_conjugate p X₀⁻¹ S).symm - rw [inv_inv] at h - exact h - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ - (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm - _ = _ := by - have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group - rw [he] - -end Thorp -namespace Thorp - -noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := - Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) - -lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - 0 ≤ cycleCoefficient r J q := by - unfold cycleCoefficient - exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) - (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) - -lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] - (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by - have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) - (boolFiber (PairRouting.labelSet e) true) - rw [childJoin_boolFiber,PairRouting.card_labelSet] at h - omega - -theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient r J q) := by - classical - let S := boolFiber (PairRouting.labelSet e) false - let S' := S.image X₀.symm - let post := X₀⁻¹*X₁*Y₁⁻¹ - let count := fun hi : Card s × SwitchIndex r → Bool => - Fintype.card (RoutingNetwork.SelectedCycle - ((Equiv.refl _).trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') - have hpoint (hi : Card s × SwitchIndex r → Bool) : - PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by - refine (alternatingCycles_le_projection e _).trans_eq ?_ - simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] - change Fintype.card (RoutingNetwork.SelectedCycle - ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi - exact projectionCycles_forward X₀ X₁ _ Y₁ S - have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq - have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_pos (fun _ => pow_pos (by linarith) _) - have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ - Real.exp (S'.card * cycleCoefficient r J q) := by - rw [←Real.exp_log hp] - apply Real.exp_le_exp.mpr - calc - _ ≤ _ := hm - _ = _ := by unfold cycleCoefficient; ring - have hcard : S'.card ≤ Fintype.card ι := by - rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] - exact projectionSide_card_le e - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) - _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right - (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) - - -def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ - (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) where - toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), - fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) - invFun c := fun j => match j.2 with - | Sum.inl y => c.2 (j.1,y) - | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) - left_inv hi := by - funext j - rcases j with ⟨z,y|⟨b,i⟩⟩ - · rfl - · cases b <;> rfl - right_inv c := by - rcases c with ⟨⟨h₀,h₁⟩,η⟩ - rfl - -lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) - (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) : - assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = - (coinStepEquiv (s+r)).symm - ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, - assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), - fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - -noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (ξ η : Card d → Bool) : - palindromeLevelCost t (d+1) e - ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by - rw [palindromeLevelCost] - rfl - -lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] - - -theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - let χ := coinStepEquiv (s+r) X - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x χ.2 - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) - else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - palindromeLevelCost (s+u+1) (s+r+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] - rw [palindromeLevelCost_step] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] - congr 2 - funext b - cases b <;> rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' e₀ χ.1.1 lo₀ - have h₁ := ih u hu' e₁ χ.1.2 lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -def switchHeight : (d : ℕ) → SwitchIndex d → ℕ - | 0, i => nomatch i - | d+1, Sum.inl _ => d+1 - | d+1, Sum.inr (_,i) => switchHeight d i - -lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - rcases i with y | ⟨b,i⟩ - · exact le_refl _ - · exact (ih i).trans (Nat.le_succ d) - -def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := - ∀ i, switchHeight d i ≤ s → Y i = Y' i - -def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := - ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' - -lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} - (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := - fun i hi => hh i (hi.trans h) - -lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} - (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := - fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) - -lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} - (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := - fun Y Y' h => congrArg g (hf Y Y' h) - -lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) - (f : ι → (SwitchIndex d → Bool) → ℕ) - (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : - LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by - intro Y Y' h - exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) - -lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi hi' : Card s × SwitchIndex r → Bool) : - AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by - induction r with - | zero => intro i _; rfl - | succ r ih => - intro i h - rcases i with y | ⟨b,i⟩ - · have : s+r+1 ≤ s := h - omega - · exact ih (fun j => lo (Fin.cons b j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h - -lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by - classical - induction d generalizing ι with - | zero => intro Y Y' _; rfl - | succ d ih => - intro Y Y' h - change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step,palindromeLevelCost_step] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih - intro i hi - exact h (Sum.inr (true,i)) hi - -lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) - (hG : ∀ lo : Card r × SwitchIndex s → Bool, - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : - finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by - rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] - apply finiteMean_mono - intro lo - let H : Card s × SwitchIndex r → Bool := fun _ => false - have hh (hi : Card s × SwitchIndex r → Bool) : - F (assembleBits r s lo hi) = F (assembleBits r s lo H) := - hA _ _ (assembleBits_agree r s lo hi H) - simp_rw [hh,finiteMean_const] - rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = - (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by - funext hi; exact mul_comm _ _,finiteMean_mul_const] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) - - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/250) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by - have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) - have he := Real.exp_pos ((l:ℝ)/32) - have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h - exact_mod_cast this - - -lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] - (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : - q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by - have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = - (∑ i, z i:ℕ)*Real.log q := by - simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] - field_simp - have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) - rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he - simpa only [Real.exp_nat_mul,Real.exp_log hq] using he - -noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω - -lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact palindromeLevelCost_gt _ _ (by omega) _ _ - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.ColoredEmbedding + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp + +noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, ι, _, e, ω => + if d+1 ≤ H then crowdedMass (Fintype.card ι) else + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = palindromeCost d e ω := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLowCost,palindromeCost,ite_eq_left h] + congr 2 <;> exact ih (by omega) _ _ + +lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by + classical + induction d generalizing ι with + | zero => simp [palindromeLowCost,cutoffMass] + | succ d ih => + by_cases h : d+1 ≤ H + · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] + exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) + · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] + exact Nat.add_le_add (ih _ _) (ih _ _) + + +noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := + Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) + +lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : + x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by + classical + constructor + · intro h + obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h + simp only [Equiv.apply_symm_apply] + · intro h + apply Finset.mem_image.mpr + refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ + rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] + +lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by + classical + rw [centralBlock,Finset.card_image_of_injective] + · exact card_positions H + · intro x y h + exact congrArg Prod.snd ((cardSplit r H).symm.injective h) + +lemma centralBlock_disjoint (r H : ℕ) : + Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by + classical + intro b b' h + apply Finset.disjoint_left.mpr + intro x hx hy + exact h (((mem_centralBlock r H b x).mp hx).symm.trans + ((mem_centralBlock r H b' x).mp hy)) + +lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by + classical + ext x + simp only [mem_centralBlock,Finset.mem_univ,iff_true] + exact Subsingleton.elim _ _ + +lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : + centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by + classical + simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, + Fin.cons_zero,Fin.tail_cons,Function.comp_def] + +lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : + centralBlock (r+1) H (Fin.cons b c) ∩ A = + (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by + classical + rw [centralBlock_step] + ext x + constructor + · intro hx + obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB + exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, + (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ + +lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : + sparseMass (centralBlock 0 H) A = crowdedMass A.card := by + classical + simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, + Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] + +lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : + sparseMass (centralBlock (r+1) H) A = + sparseMass (centralBlock r H) (childMarks A false) + + sparseMass (centralBlock r H) (childMarks A true) := by + classical + unfold sparseMass + rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl + simp only [Fintype.sum_bool,ht] + have hc (b : Bool) (c : Card r) : + (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = + (centralBlock r H c ∩ childMarks A b).card := by + rw [block_inter_step] + apply Finset.card_image_of_injective + intro x y h + simpa only [Fin.tail_cons] using congrArg Fin.tail h + simp only [hc] + exact add_comm _ _ + + +lemma inverseButterfly_coordinates_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) + (x : Card (d+1)) : + headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = + (Bool.xor (x 0) (ξ (Fin.tail x)), + (butterflyPerm d (decodeButterfly d + (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by + rw [butterflyPerm_step] + rfl + +lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : + childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) + ((coinStepEquiv d).symm (c,ξ))) b = + inverseButterflyMarks d + (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) + (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by + classical + let x := e.trans (headTailEquiv d).toEmbedding + let col := PairRouting.colors x ξ + let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b + have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = + (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := + inverseButterfly_coordinates_step d c ξ (e i) + ext y + simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, + Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] + constructor + · rintro ⟨i,hi⟩ + have he := congrArg (headTailEquiv d) hi + rw [hp i] at he + change (col i,_) = (b,y) at he + have hb := congrArg Prod.fst he + have hy := congrArg Prod.snd he + dsimp only at hb hy + refine ⟨⟨i,hb⟩,?_⟩ + change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y + simpa only [hb] using hy + · rintro ⟨i,hi⟩ + refine ⟨i.val,?_⟩ + apply (headTailEquiv d).injective + rw [hp] + change (col i.val,_) = (b,y) + have hb : col i.val = b := i.property + rw [hb] + exact Prod.ext rfl hi + +lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : + (inverseButterflyMarks d A ω).card = A.card := by + classical + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective + +lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : + ω.2 = (coinStepEquiv d).symm + (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by + change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) + exact ((coinStepEquiv d).symm_apply_apply ω.2).symm + +lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : + cutoffMass H (H+r) e ω = + sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by + classical + induction r generalizing ι with + | zero => + rw [sparseMass_central_zero,inverseButterflyMarks_card, + Finset.card_image_of_injective _ e.injective,Finset.card_univ] + cases H with + | zero => + have hcard : Fintype.card ι ≤ 1 := by + have hh := Fintype.card_le_of_injective e e.injective + simpa only [Nat.add_zero,card_positions,pow_zero] using hh + simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] + | succ H => simp only [cutoffMass,le_refl,ite_true] + | succ r ih => + simp only [Nat.add_succ] at * + rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] + let σ := benesStepEquiv (H+r) ω + let x := e.trans (headTailEquiv (H+r)).toEmbedding + let col := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + + cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ + rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] + rw [inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + + +theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ + Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by + classical + have hec : (Finset.univ.image e).card = Fintype.card ι := by + rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] + have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) + (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) + (pow_nonneg (by linarith) _) (fun b => by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) + calc + _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by + apply finiteMean_mono + intro ω + rw [←pow_mul] + exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) + _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => + (q^H)^(sparseMass (centralBlock r H) + (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by + simp_rw [cutoffMass_central] + simp only [finiteMean_prod,finiteMean_const] + _ ≤ _ := by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, + Finset.card_univ,card_positions,nsmul_eq_mul] using hm + +variable {α B : Type*} {r s : ℕ} + +def parallelFreshPre (pre : α ≃ B × Card (s+r)) + (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := + ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans + (Equiv.prodCongrRight (fun b => + (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans + (Equiv.prodAssoc _ _ _).symm + +def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := + (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) + (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post + +def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := + fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 + +lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : + relabeledPerm pre post (parallelAssembled lo hi) = + relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by + ext x + have h := butterfly_split r s (lo (pre x).1) + (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 + have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h + simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, + Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, + Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, + Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh + +theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] + (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ + (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by + simp_rw [parallel_exposed_perm] + exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq + +end Thorp +namespace Thorp +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] + +lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Fintype.card_congr + refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ + invFun := fun C => ⟨C.val,?_,C.property.2⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ + +lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : + orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by + ext y + simp only [mem_orbitSet,Finset.mem_image] + rw [Equiv.Perm.sameCycle_conj] + change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y + rw [Equiv.symm_apply_apply] + constructor + · intro h + exact ⟨g.symm y,h,g.apply_symm_apply y⟩ + · rintro ⟨z,hz,rfl⟩ + simpa only [Equiv.symm_apply_apply] using hz + +noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) + (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by + refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ + +lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : + Function.Injective (conjugateCycle p g S) := by + intro C D he + apply Subtype.ext + exact (Finset.image_injective g.injective) (congrArg Subtype.val he) + +lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Nat.le_antisymm + · have h := Fintype.card_le_of_injective _ + (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) + have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group + rw [inv_inv,hp] at h + have hs : (S.image g).image g.symm = S := by + ext x + simp only [Finset.mem_image] + constructor + · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ + have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he + exact hz' ▸ hz + · intro hx + exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ + change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h + rw [hs] at h + exact h + · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) + +lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false)) := by + have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) + simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h + +lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle + ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = + Fintype.card (RoutingNetwork.SelectedCycle + (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by + let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) + calc + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) + (S.image X₀.symm)) := by + change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ + have h := (selectedCycle_conjugate p X₀⁻¹ S).symm + rw [inv_inv] at h + exact h + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ + (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm + _ = _ := by + have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group + rw [he] + +end Thorp +namespace Thorp + +noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := + Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) + +lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + 0 ≤ cycleCoefficient r J q := by + unfold cycleCoefficient + exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) + (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) + +lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by + have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) + (boolFiber (PairRouting.labelSet e) true) + rw [childJoin_boolFiber,PairRouting.card_labelSet] at h + omega + +theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient r J q) := by + classical + let S := boolFiber (PairRouting.labelSet e) false + let S' := S.image X₀.symm + let post := X₀⁻¹*X₁*Y₁⁻¹ + let count := fun hi : Card s × SwitchIndex r → Bool => + Fintype.card (RoutingNetwork.SelectedCycle + ((Equiv.refl _).trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') + have hpoint (hi : Card s × SwitchIndex r → Bool) : + PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by + refine (alternatingCycles_le_projection e _).trans_eq ?_ + simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] + change Fintype.card (RoutingNetwork.SelectedCycle + ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi + exact projectionCycles_forward X₀ X₁ _ Y₁ S + have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq + have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_pos (fun _ => pow_pos (by linarith) _) + have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ + Real.exp (S'.card * cycleCoefficient r J q) := by + rw [←Real.exp_log hp] + apply Real.exp_le_exp.mpr + calc + _ ≤ _ := hm + _ = _ := by unfold cycleCoefficient; ring + have hcard : S'.card ≤ Fintype.card ι := by + rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] + exact projectionSide_card_le e + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) + _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) + + +def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ + (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) where + toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), + fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) + invFun c := fun j => match j.2 with + | Sum.inl y => c.2 (j.1,y) + | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) + left_inv hi := by + funext j + rcases j with ⟨z,y|⟨b,i⟩⟩ + · rfl + · cases b <;> rfl + right_inv c := by + rcases c with ⟨⟨h₀,h₁⟩,η⟩ + rfl + +lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) + (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) : + assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = + (coinStepEquiv (s+r)).symm + ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, + assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), + fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + +noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (ξ η : Card d → Bool) : + palindromeLevelCost t (d+1) e + ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by + rw [palindromeLevelCost] + rfl + +lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] + + +theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + let χ := coinStepEquiv (s+r) X + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x χ.2 + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) + else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + palindromeLevelCost (s+u+1) (s+r+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] + rw [palindromeLevelCost_step] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] + congr 2 + funext b + cases b <;> rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' e₀ χ.1.1 lo₀ + have h₁ := ih u hu' e₁ χ.1.2 lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +def switchHeight : (d : ℕ) → SwitchIndex d → ℕ + | 0, i => nomatch i + | d+1, Sum.inl _ => d+1 + | d+1, Sum.inr (_,i) => switchHeight d i + +lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + rcases i with y | ⟨b,i⟩ + · exact le_refl _ + · exact (ih i).trans (Nat.le_succ d) + +def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := + ∀ i, switchHeight d i ≤ s → Y i = Y' i + +def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := + ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' + +lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} + (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := + fun i hi => hh i (hi.trans h) + +lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} + (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := + fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) + +lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} + (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := + fun Y Y' h => congrArg g (hf Y Y' h) + +lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) + (f : ι → (SwitchIndex d → Bool) → ℕ) + (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : + LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by + intro Y Y' h + exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) + +lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi hi' : Card s × SwitchIndex r → Bool) : + AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by + induction r with + | zero => intro i _; rfl + | succ r ih => + intro i h + rcases i with y | ⟨b,i⟩ + · have : s+r+1 ≤ s := h + omega + · exact ih (fun j => lo (Fin.cons b j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h + +lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by + classical + induction d generalizing ι with + | zero => intro Y Y' _; rfl + | succ d ih => + intro Y Y' h + change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step,palindromeLevelCost_step] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih + intro i hi + exact h (Sum.inr (true,i)) hi + +lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) + (hG : ∀ lo : Card r × SwitchIndex s → Bool, + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : + finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by + rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] + apply finiteMean_mono + intro lo + let H : Card s × SwitchIndex r → Bool := fun _ => false + have hh (hi : Card s × SwitchIndex r → Bool) : + F (assembleBits r s lo hi) = F (assembleBits r s lo H) := + hA _ _ (assembleBits_agree r s lo hi H) + simp_rw [hh,finiteMean_const] + rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = + (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by + funext hi; exact mul_comm _ _,finiteMean_mul_const] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) + + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/250) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by + have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) + have he := Real.exp_pos ((l:ℝ)/32) + have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h + exact_mod_cast this + + +lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] + (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : + q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = + (∑ i, z i:ℕ)*Real.log q := by + simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] + field_simp + have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) + rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he + simpa only [Real.exp_nat_mul,Real.exp_log hq] using he + +noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω + +lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact palindromeLevelCost_gt _ _ (by omega) _ _ + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/ExposedCoins.lean b/lean/OAI/Probability/ThorpRouting/HighTail/ExposedCoins.lean index 8e1fcc04e14215b6da6b1c655793738b466ea0e2..339440b233bf5a40bd8792c75064a6e53498baf0 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/ExposedCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/ExposedCoins.lean @@ -1,860 +1,860 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.Coins - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter - -lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by - classical - induction d with - | zero => rfl - | succ d ih => - change (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 - rw [Finset.card_insert_of_notMem (by simp)] - rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] - -lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by - cases a <;> cases b <;> cases c <;> decide - -lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : - butterflyPerm d (decodeButterfly d ω) x = y ↔ - ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by - classical - induction d with - | zero => - have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ - simp [he, routeDomain] - | succ d ih => - let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) - change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ - have hv : v = Fin.tail y ↔ - ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), - ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := - ih _ _ _ - constructor - · intro h i hi - have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h - have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by - have he := congrFun h 0 - simp only [Fin.cons_zero, ht] at he - exact (xor_eq_iff _ _ _).mp he - rcases Finset.mem_insert.mp hi with htop | hchild - · subst i - exact hh - · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild - exact hv.mp ht j hj - · intro h - have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) - have ht : v = Fin.tail y := hv.mpr (fun i hi => - h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) - have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := - (xor_eq_iff _ _ _).mpr hh - rw [ht, hh', Fin.cons_self_tail] - -lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by - unfold finiteMean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) : - finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = - 1 / (2 : ℝ) ^ s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 - have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - dsimp [f] - simp only [he] - have hm := QueryTree.mean_indicator_bit f i (v i) hf - have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = - (fun ω => if ω i = v i then f ω else 0) := by - funext ω - by_cases h : ω i = v i <;> simp [f, h] - rw [he, hm] - change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ - rw [ih, Finset.card_insert_of_notMem hi, pow_succ] - ring - -def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := - fun i => if i ∈ R then η i else ω i - -lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] - (s R : Finset ι) (v η : ι → Bool) : - finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by - have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ - (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by - constructor - · intro h - constructor - · intro i hi - simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 - · intro i hi - simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 - · rintro ⟨ho, hf⟩ i hi - by_cases hR : i ∈ R - · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) - · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) - have hm : finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - finiteMean (fun ω : ι → Bool => - if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [he ω]) - rw [hm] - by_cases h : ∀ i ∈ s ∩ R, η i = v i - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h - simp only [hp, true_and, ↓reduceIte] - exact mean_coinCylinder (s \ R) v - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h - simp only [hp, false_and, ↓reduceIte] - simp [finiteMean] - -lemma butterfly_closure_probability (d : ℕ) (x y : Card d) - (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then - (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder_exposed] - congr 1 - have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter, card_routeDomain] - have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * - (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by - rw [← pow_add] - exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm - rw [hp] - have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) - field_simp - -lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder, card_routeDomain] - -def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d - | 0, _, i => nomatch i - | d + 1, b, Sum.inl y => - (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), - Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) - | d + 1, b, Sum.inr (ε,i) => - (Fin.cons ε (switchUsers d (b.2 ε) i).1, - Fin.cons ε (switchUsers d (b.2 ε) i).2) - -lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : - (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - intro h - have := congrFun h 0 - simp only [switchUsers, Fin.cons_zero] at this - exact Bool.false_ne_true this - | inr z => - intro h - exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) - -lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : - Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by - constructor - · intro h - exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, - by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ - · rintro ⟨rfl,rfl⟩ - exact Fin.cons_self_tail x - -lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : - i ∈ routeDomain d x (butterflyPerm d b x) ↔ - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by - classical - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, - Sum.inr_ne_inl, and_false, exists_false, or_false] - change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ - simp only [switchUsers, cons_eq_iff] - cases x 0 <;> simp [Equiv.symm_apply_eq] - | inr z => - obtain ⟨ε,i⟩ := z - change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, - Sum.inr.injEq, Prod.mk.injEq] - change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ - x 0 = ε ∧ j = i) ↔ _ - simp only [switchUsers, cons_eq_iff] - constructor - · rintro ⟨j,hj,hε,rfl⟩ - subst ε - rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h - · exact Or.inl ⟨rfl,h⟩ - · exact Or.inr ⟨rfl,h⟩ - · rintro (⟨hε,h⟩ | ⟨hε,h⟩) - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ - -lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : - (Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - routeDomain d x (butterflyPerm d b x) := by - ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] - rw [he,card_routeDomain] - -lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = - (d : ℝ) * ∑ x : Card d, w x := by - classical - calc - _ = ∑ i : SwitchIndex d, ∑ x : Card d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : Card d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - {(switchUsers d b i).1, (switchUsers d b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (switchUsers_ne d b i)] - _ = ∑ x : Card d, ∑ i : SwitchIndex d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : Card d, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ - (d : ℝ) / 2 * ∑ x : Card d, w x := by - have h : 2 * (∑ i : SwitchIndex d, - min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), - min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] - rw [switch_incidence_sum] at h - linarith - -lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : - x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by - classical - constructor - · intro h - obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy - rw [← hxy, ← hyε, Fin.cons_self_tail] - exact hys - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons ε x, - Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ - -lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) (y : Card d) : - y ∈ topMeetings b s ↔ - (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by - classical - have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ - (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by - constructor - · intro h - obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h - simpa only [Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ - simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] - -lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - encounters d b s = ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by - classical - induction d with - | zero => - simp only [encounters] - symm - apply Finset.sum_eq_zero - intro i _ - exact Empty.elim i - | succ d ih => - change encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = - ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ - rw [Fintype.sum_sum_type, Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [ih,ih] - have ht : (∑ y : Card d, - if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = - (topMeetings b s).card := by - simp only [← mem_topMeetings] - simp - rw [ht] - simp only [mem_childMarks, switchUsers] - ac_rfl - -lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ - (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - classical - have he : (encounters d b s : ℝ) = - ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by - rw [encounters_eq_switch_sum, Nat.cast_sum] - apply Finset.sum_congr rfl - intro i _ - split_ifs <;> simp - rw [← he] - exact butterfly_encounters d b s - -namespace QueryTree -variable {ι : Type*} [DecidableEq ι] - -def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι - | reject, _, _ => reject - | accept, _, _ => accept - | branch i zero one, R, η => - if i ∈ R then (if η i then memo one R η else memo zero R η) else - branch i (memo zero (insert i R) (Function.update η i false)) - (memo one (insert i R) (Function.update η i true)) - | force i b next, R, η => - if i ∈ R then (if η i = b then memo next R η else reject) else - force i b (memo next (insert i R) (Function.update η i b)) - -lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - Disjoint (memo T R η).queries R := by - induction T generalizing R η with - | reject => simp [memo,queries] - | accept => simp [memo,queries] - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] - exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), - (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,queries] - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] - exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - -lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - (memo T R η).Fresh := by - induction T generalizing R η with - | reject => trivial - | accept => trivial - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm - (Finset.mem_insert_self _ _), - fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm - (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,Fresh] - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm - (Finset.mem_insert_self _ _),ih _ _⟩ - -lemma update_agrees {R : Finset ι} {η ω : ι → Bool} - (h : ∀ i ∈ R, η i = ω i) (i : ι) : - ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by - intro j hj - rcases Finset.mem_insert.mp hj with rfl | hj - · simp - · by_cases hji : j = i - · subst j; simp - · rw [Function.update_of_ne hji] - exact h j hj - -lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,succeeds,h i hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,succeeds] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte,succeeds] - exact ih R η h - · simp [hb,succeeds] - · simp only [memo,hi,↓reduceIte,succeeds] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih _ _ (by simpa only [hb] using update_agrees h i) - · simp [hb] - -def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 - -lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih R η h - · simp [hb,charge] - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - rw [ih _ _ (by simpa only [hb] using update_agrees h i)] - · simp [hb] - -lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by - let η : ι → Bool := fun _ => false - have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) - have he : finiteMean (memo T ∅ η).weighted = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] - rw [he] at hm - exact hm - - -def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → - (Card d → QueryTree ι) → QueryTree ι - | 0, _, x, k => k x - | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) - (fun y => branch (e (Sum.inl y)) - (k (Fin.cons (Bool.xor (x 0) false) y)) - (k (Fin.cons (Bool.xor (x 0) true) y))) - -omit [DecidableEq ι] in -lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).succeeds ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω - cases ω (e (Sum.inl y)) <;> rfl - -lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - freshCharge (followPath d e x k) R ω = - freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - classical - induction d generalizing R with - | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) - change (if ω (e (Sum.inl y)) then - freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else - freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = - freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) - (R ∪ (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω - have hs : (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = - insert (e (Sum.inl y)) S := by - let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e - change (insert (Sum.inl y) - ((routeDomain d (Fin.tail x) y).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ - rw [Finset.image_insert, Finset.image_image] - rfl - rw [hs,Finset.union_insert] - cases ω (e (Sum.inl y)) <;> rfl - -def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι - | [], _, k => k - | i :: L, v, k => force i (v i) (forceList L v k) - -omit [DecidableEq ι] in -lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : - (forceList L v k).succeeds ω = - if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by - induction L with - | nil => simp [forceList] - | cons i L ih => - simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] - by_cases h : ω i = v i <;> simp [h] - -lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) - (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : - freshCharge (forceList L v k) R ω = - freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by - induction L generalizing R with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), - ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.toFinset_cons] - have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp - rw [hs] - by_cases hi : i ∈ R - · rw [ite_eq_left hi] - have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he,Nat.add_zero] - · rw [ite_eq_right hi] - have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he, Finset.card_insert_of_notMem (by simp)] - omega - - -def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω - else staleCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 - -lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by - induction T generalizing R with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] - | force i b next ih => - by_cases hb : ω i = b - · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] - have he := ih (insert i R) - by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega - · simp [freshCharge,staleCharge,charge,hb] - -omit [DecidableEq ι] in -lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).charge ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω - cases ω (e (Sum.inl y)) <;> rfl - -omit [DecidableEq ι] in -lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) - (h : ∀ i ∈ L, ω i = v i) : - (forceList L v k).charge ω = k.charge ω + L.length := by - induction L with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), - ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.length_cons,Nat.add_assoc] - -noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : - QueryTree (SwitchIndex d) := - forceList (routeDomain d x y).toList (routeValue d x y) k - -lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) : - (closePath d x y k).succeeds ω = - if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by - unfold closePath - rw [forceList_succeeds] - simp only [Finset.mem_toList, ← butterfly_endpoint_iff] - -lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).charge ω = k.charge ω + d := by - unfold closePath - rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] - -lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).freshCharge R ω = - k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by - unfold closePath - rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] - -lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).staleCharge R ω = - k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by - have h₀ := fresh_add_stale (closePath d x y k) R ω - have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω - rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ - have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_routeDomain] - omega - -noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : - ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → - QueryTree (SwitchIndex d) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x - (fun y => seekCycle d S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle d S a r x V k).succeeds ω = true) : - (seekCycle d S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs - rw [seekCycle,ite_eq_left hv,followPath_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,succeeds] at hs - -noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : - List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) - | [], _ => accept - | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) - -lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) - (V : Finset (Card d)) (ω : SwitchIndex d → Bool) - (hs : (seekCycles d S L V).succeeds ω = true) : - (seekCycles d S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : - finiteMean (fun ω : SwitchIndex d → Bool => - if (seekCycles d S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles d S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge d S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree - -lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by - simp only [finiteMean,Finset.sum_add_distrib,add_div] - -lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : - finiteMean (fun ω => f ω * c) = finiteMean f * c := by - unfold finiteMean - rw [← Finset.sum_mul] - ring - -lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : - finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by - simp only [finiteMean,Finset.sum_div] - exact Finset.sum_comm - -lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω → ℝ) : - finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by - unfold finiteMean - rw [Fintype.card_congr e] - congr 1 - exact Fintype.sum_equiv e _ _ (fun ω => by simp) - -lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] - (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by - simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, - ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] - have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - field_simp - -lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] - {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] - (c : C) (g : A c → ℝ) : - finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by - rw [finiteMean_equiv (Equiv.piSplitAt c A)] - have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => - g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by - funext z - simp [Equiv.piSplitAt] - rw [he,finiteMean_prod_left] - -lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : - finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by - simp [finiteMean] - -lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] - have hj := convexOn_exp.map_sum_le (t := Finset.univ) - (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) - (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) - simp only [smul_eq_mul, ← Finset.mul_sum] at hj - simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj - -variable {d A : ℕ} - -def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} - -noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.Coins + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter + +lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by + classical + induction d with + | zero => rfl + | succ d ih => + change (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 + rw [Finset.card_insert_of_notMem (by simp)] + rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] + +lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by + cases a <;> cases b <;> cases c <;> decide + +lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : + butterflyPerm d (decodeButterfly d ω) x = y ↔ + ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by + classical + induction d with + | zero => + have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ + simp [he, routeDomain] + | succ d ih => + let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) + change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ + have hv : v = Fin.tail y ↔ + ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), + ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := + ih _ _ _ + constructor + · intro h i hi + have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h + have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by + have he := congrFun h 0 + simp only [Fin.cons_zero, ht] at he + exact (xor_eq_iff _ _ _).mp he + rcases Finset.mem_insert.mp hi with htop | hchild + · subst i + exact hh + · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild + exact hv.mp ht j hj + · intro h + have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) + have ht : v = Fin.tail y := hv.mpr (fun i hi => + h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) + have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := + (xor_eq_iff _ _ _).mpr hh + rw [ht, hh', Fin.cons_self_tail] + +lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by + unfold finiteMean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) : + finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = + 1 / (2 : ℝ) ^ s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 + have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + dsimp [f] + simp only [he] + have hm := QueryTree.mean_indicator_bit f i (v i) hf + have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = + (fun ω => if ω i = v i then f ω else 0) := by + funext ω + by_cases h : ω i = v i <;> simp [f, h] + rw [he, hm] + change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ + rw [ih, Finset.card_insert_of_notMem hi, pow_succ] + ring + +def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := + fun i => if i ∈ R then η i else ω i + +lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] + (s R : Finset ι) (v η : ι → Bool) : + finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by + have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ + (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by + constructor + · intro h + constructor + · intro i hi + simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 + · intro i hi + simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 + · rintro ⟨ho, hf⟩ i hi + by_cases hR : i ∈ R + · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) + · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) + have hm : finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + finiteMean (fun ω : ι → Bool => + if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [he ω]) + rw [hm] + by_cases h : ∀ i ∈ s ∩ R, η i = v i + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h + simp only [hp, true_and, ↓reduceIte] + exact mean_coinCylinder (s \ R) v + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h + simp only [hp, false_and, ↓reduceIte] + simp [finiteMean] + +lemma butterfly_closure_probability (d : ℕ) (x y : Card d) + (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then + (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder_exposed] + congr 1 + have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter, card_routeDomain] + have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * + (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by + rw [← pow_add] + exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm + rw [hp] + have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) + field_simp + +lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder, card_routeDomain] + +def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d + | 0, _, i => nomatch i + | d + 1, b, Sum.inl y => + (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), + Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) + | d + 1, b, Sum.inr (ε,i) => + (Fin.cons ε (switchUsers d (b.2 ε) i).1, + Fin.cons ε (switchUsers d (b.2 ε) i).2) + +lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : + (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + intro h + have := congrFun h 0 + simp only [switchUsers, Fin.cons_zero] at this + exact Bool.false_ne_true this + | inr z => + intro h + exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) + +lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : + Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by + constructor + · intro h + exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, + by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ + · rintro ⟨rfl,rfl⟩ + exact Fin.cons_self_tail x + +lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : + i ∈ routeDomain d x (butterflyPerm d b x) ↔ + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by + classical + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, + Sum.inr_ne_inl, and_false, exists_false, or_false] + change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ + simp only [switchUsers, cons_eq_iff] + cases x 0 <;> simp [Equiv.symm_apply_eq] + | inr z => + obtain ⟨ε,i⟩ := z + change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, + Sum.inr.injEq, Prod.mk.injEq] + change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ + x 0 = ε ∧ j = i) ↔ _ + simp only [switchUsers, cons_eq_iff] + constructor + · rintro ⟨j,hj,hε,rfl⟩ + subst ε + rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h + · exact Or.inl ⟨rfl,h⟩ + · exact Or.inr ⟨rfl,h⟩ + · rintro (⟨hε,h⟩ | ⟨hε,h⟩) + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ + +lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : + (Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + routeDomain d x (butterflyPerm d b x) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] + rw [he,card_routeDomain] + +lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = + (d : ℝ) * ∑ x : Card d, w x := by + classical + calc + _ = ∑ i : SwitchIndex d, ∑ x : Card d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : Card d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + {(switchUsers d b i).1, (switchUsers d b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (switchUsers_ne d b i)] + _ = ∑ x : Card d, ∑ i : SwitchIndex d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : Card d, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ + (d : ℝ) / 2 * ∑ x : Card d, w x := by + have h : 2 * (∑ i : SwitchIndex d, + min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), + min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] + rw [switch_incidence_sum] at h + linarith + +lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : + x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by + classical + constructor + · intro h + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy + rw [← hxy, ← hyε, Fin.cons_self_tail] + exact hys + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons ε x, + Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ + +lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) (y : Card d) : + y ∈ topMeetings b s ↔ + (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by + classical + have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ + (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by + constructor + · intro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + simpa only [Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ + simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] + +lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + encounters d b s = ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by + classical + induction d with + | zero => + simp only [encounters] + symm + apply Finset.sum_eq_zero + intro i _ + exact Empty.elim i + | succ d ih => + change encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = + ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ + rw [Fintype.sum_sum_type, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [ih,ih] + have ht : (∑ y : Card d, + if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = + (topMeetings b s).card := by + simp only [← mem_topMeetings] + simp + rw [ht] + simp only [mem_childMarks, switchUsers] + ac_rfl + +lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ + (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + classical + have he : (encounters d b s : ℝ) = + ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by + rw [encounters_eq_switch_sum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + rw [← he] + exact butterfly_encounters d b s + +namespace QueryTree +variable {ι : Type*} [DecidableEq ι] + +def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι + | reject, _, _ => reject + | accept, _, _ => accept + | branch i zero one, R, η => + if i ∈ R then (if η i then memo one R η else memo zero R η) else + branch i (memo zero (insert i R) (Function.update η i false)) + (memo one (insert i R) (Function.update η i true)) + | force i b next, R, η => + if i ∈ R then (if η i = b then memo next R η else reject) else + force i b (memo next (insert i R) (Function.update η i b)) + +lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + Disjoint (memo T R η).queries R := by + induction T generalizing R η with + | reject => simp [memo,queries] + | accept => simp [memo,queries] + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] + exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), + (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,queries] + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] + exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + +lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + (memo T R η).Fresh := by + induction T generalizing R η with + | reject => trivial + | accept => trivial + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm + (Finset.mem_insert_self _ _), + fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm + (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,Fresh] + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm + (Finset.mem_insert_self _ _),ih _ _⟩ + +lemma update_agrees {R : Finset ι} {η ω : ι → Bool} + (h : ∀ i ∈ R, η i = ω i) (i : ι) : + ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by + intro j hj + rcases Finset.mem_insert.mp hj with rfl | hj + · simp + · by_cases hji : j = i + · subst j; simp + · rw [Function.update_of_ne hji] + exact h j hj + +lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,succeeds,h i hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,succeeds] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte,succeeds] + exact ih R η h + · simp [hb,succeeds] + · simp only [memo,hi,↓reduceIte,succeeds] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih _ _ (by simpa only [hb] using update_agrees h i) + · simp [hb] + +def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 + +lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih R η h + · simp [hb,charge] + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + rw [ih _ _ (by simpa only [hb] using update_agrees h i)] + · simp [hb] + +lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by + let η : ι → Bool := fun _ => false + have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) + have he : finiteMean (memo T ∅ η).weighted = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] + rw [he] at hm + exact hm + + +def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → + (Card d → QueryTree ι) → QueryTree ι + | 0, _, x, k => k x + | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) + (fun y => branch (e (Sum.inl y)) + (k (Fin.cons (Bool.xor (x 0) false) y)) + (k (Fin.cons (Bool.xor (x 0) true) y))) + +omit [DecidableEq ι] in +lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).succeeds ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω + cases ω (e (Sum.inl y)) <;> rfl + +lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + freshCharge (followPath d e x k) R ω = + freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + classical + induction d generalizing R with + | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) + change (if ω (e (Sum.inl y)) then + freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else + freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = + freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) + (R ∪ (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω + have hs : (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = + insert (e (Sum.inl y)) S := by + let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e + change (insert (Sum.inl y) + ((routeDomain d (Fin.tail x) y).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ + rw [Finset.image_insert, Finset.image_image] + rfl + rw [hs,Finset.union_insert] + cases ω (e (Sum.inl y)) <;> rfl + +def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι + | [], _, k => k + | i :: L, v, k => force i (v i) (forceList L v k) + +omit [DecidableEq ι] in +lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : + (forceList L v k).succeeds ω = + if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by + induction L with + | nil => simp [forceList] + | cons i L ih => + simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] + by_cases h : ω i = v i <;> simp [h] + +lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) + (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : + freshCharge (forceList L v k) R ω = + freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by + induction L generalizing R with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), + ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.toFinset_cons] + have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp + rw [hs] + by_cases hi : i ∈ R + · rw [ite_eq_left hi] + have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he,Nat.add_zero] + · rw [ite_eq_right hi] + have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he, Finset.card_insert_of_notMem (by simp)] + omega + + +def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω + else staleCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 + +lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by + induction T generalizing R with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] + | force i b next ih => + by_cases hb : ω i = b + · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] + have he := ih (insert i R) + by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega + · simp [freshCharge,staleCharge,charge,hb] + +omit [DecidableEq ι] in +lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).charge ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω + cases ω (e (Sum.inl y)) <;> rfl + +omit [DecidableEq ι] in +lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) + (h : ∀ i ∈ L, ω i = v i) : + (forceList L v k).charge ω = k.charge ω + L.length := by + induction L with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), + ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.length_cons,Nat.add_assoc] + +noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : + QueryTree (SwitchIndex d) := + forceList (routeDomain d x y).toList (routeValue d x y) k + +lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) : + (closePath d x y k).succeeds ω = + if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by + unfold closePath + rw [forceList_succeeds] + simp only [Finset.mem_toList, ← butterfly_endpoint_iff] + +lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).charge ω = k.charge ω + d := by + unfold closePath + rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] + +lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).freshCharge R ω = + k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by + unfold closePath + rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] + +lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).staleCharge R ω = + k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by + have h₀ := fresh_add_stale (closePath d x y k) R ω + have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω + rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ + have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_routeDomain] + omega + +noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : + ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → + QueryTree (SwitchIndex d) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x + (fun y => seekCycle d S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle d S a r x V k).succeeds ω = true) : + (seekCycle d S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs + rw [seekCycle,ite_eq_left hv,followPath_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,succeeds] at hs + +noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : + List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) + | [], _ => accept + | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) + +lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) + (V : Finset (Card d)) (ω : SwitchIndex d → Bool) + (hs : (seekCycles d S L V).succeeds ω = true) : + (seekCycles d S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : + finiteMean (fun ω : SwitchIndex d → Bool => + if (seekCycles d S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles d S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge d S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree + +lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by + simp only [finiteMean,Finset.sum_add_distrib,add_div] + +lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : + finiteMean (fun ω => f ω * c) = finiteMean f * c := by + unfold finiteMean + rw [← Finset.sum_mul] + ring + +lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : + finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by + simp only [finiteMean,Finset.sum_div] + exact Finset.sum_comm + +lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω → ℝ) : + finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by + unfold finiteMean + rw [Fintype.card_congr e] + congr 1 + exact Fintype.sum_equiv e _ _ (fun ω => by simp) + +lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] + (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by + simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, + ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] + have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + field_simp + +lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] + {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] + (c : C) (g : A c → ℝ) : + finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by + rw [finiteMean_equiv (Equiv.piSplitAt c A)] + have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => + g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by + funext z + simp [Equiv.piSplitAt] + rw [he,finiteMean_prod_left] + +lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : + finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by + simp [finiteMean] + +lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] + have hj := convexOn_exp.map_sum_le (t := Finset.univ) + (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) + (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul, ← Finset.mul_sum] at hj + simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj + +variable {d A : ℕ} + +def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} + +noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/Main.lean b/lean/OAI/Probability/ThorpRouting/HighTail/Main.lean index bce9727fd188c083d50d9e23c61a17b23587c422..a29ed4798fef0dc6fb6bdf0d73ea617ae0320d04 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/Main.lean @@ -1,927 +1,927 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.CutoffMass - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -end Thorp - - -namespace Thorp.HighHeight -open scoped BigOperators Classical - -lemma family_weighted (L n d s : ℕ) (hL : 0 F Y*q^(palindromeFamilyCost L n d x (Y,X))) ≤ - finiteMean F*Real.exp (Fintype.card ι*(68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => - simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - mul_one,mul_zero,Real.exp_zero] - exact le_rfl - | succ n ih => - let l := L*4^n - have hl : 0 F Y*q^(palindromeFamilyCost L n d x (Y,X))) := by - intro Y Y' hh - dsimp only - rw [hA Y Y' (agreeThrough_mono (le_max_left _ _) hh)] - congr 2 - exact palindromeFamilyCost_adapted L n d x X Y Y' (agreeThrough_mono (le_max_right _ _) hh) - have hm : finiteMean (fun Y => F Y*q^(palindromeFamilyCost L (n+1) d x (Y,X))) ≤ - finiteMean (fun Y => F Y*q^(palindromeFamilyCost L n d x (Y,X)))* - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l≤d - · simp_rw [hc,pow_add,←mul_assoc] - simpa only [mul_assoc] using palindrome_slab_adapted_mul_le d (max s (familyEnd L n)) l (by omega) - hl hs' x X _ hwt had q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) x,Nat.add_zero] - exact le_mul_of_one_le_right (finiteMean_nonneg hwt) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [mul_assoc,←Real.exp_add,Finset.sum_range_succ] - congr 2 - dsimp [l] - ring - -lemma low_switch_height (r s : ℕ) (j : Card r × SwitchIndex s) : - switchHeight (s+r) ((splitSwitch r s).symm (Sum.inl j)) ≤ s := by - induction r with - | zero => exact switchHeight_le s j.2 - | succ r ih => - exact ih (Fin.tail j.1,j.2) - -def lowCoins (r s : ℕ) (Y : SwitchIndex (s+r) → Bool) : - Card r × SwitchIndex s → Bool := - fun j => Y ((splitSwitch r s).symm (Sum.inl j)) - -lemma lowCoins_adapted (r s : ℕ) : LayerAdapted (s+r) s (lowCoins r s) := by - intro Y Y' hh - funext j - exact hh _ (low_switch_height r s j) - -lemma lowCoins_assemble (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : lowCoins r s (assembleBits r s lo hi)=lo := by - funext j - simp only [lowCoins,assembleBits_eq,Equiv.apply_symm_apply,Sum.elim_inl] - -noncomputable def lowEvent (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (Y : SwitchIndex (s+r) → Bool) : ℝ := if lowCoins r s Y=lo then 1 else 0 - -lemma lowEvent_nonneg (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (Y : SwitchIndex (s+r) → Bool) : 0≤lowEvent r s lo Y := by - unfold lowEvent; split_ifs <;> norm_num - -lemma lowEvent_adapted (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) : - LayerAdapted (s+r) s (lowEvent r s lo) := - layerAdapted_comp (lowCoins_adapted r s) (fun v => if v=lo then (1:ℝ) else 0) - -lemma lowEvent_mean_mul (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (G : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean (fun Y => lowEvent r s lo Y*G Y)= - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi))/ - (Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by - rw [finiteMean_split] - simp only [lowEvent,lowCoins_assemble,ite_mul,one_mul,zero_mul,finiteMean] - simp_rw [Finset.sum_ite_irrel,Finset.sum_const_zero,ite_div,zero_div] - simp - -lemma lowEvent_mean (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) : - finiteMean (lowEvent r s lo)=1/(Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by - simpa only [mul_one,finiteMean_const] using lowEvent_mean_mul r s lo (fun _ => 1) - -lemma family_partial (L n r s : ℕ) (hL : 0 - q^(palindromeFamilyCost L n (s+r) x (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - have hh:=family_weighted L n (s+r) s hL hs x X (lowEvent r s lo) - (lowEvent_nonneg r s lo) (lowEvent_adapted r s lo) q hq hlog - rw [lowEvent_mean_mul,lowEvent_mean,one_div,mul_comm] at hh - have hp : (0:ℝ) - q^(highCost J (s+r) x (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι*heightDecay (J-1)) := by - have hq2:=one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2)≤1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀:=family_partial (J-1) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2 - have h₁:=family_partial (2*(J-1)) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2 - have h₁':=h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show J-1≤2*(J-1) by omega)) (Nat.cast_nonneg _))) - have hh:=finiteMean_mul_exp_le - (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeFamilyCost (J-1) (s+r) (s+r) x (assembleBits r s lo hi,X))) - (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeFamilyCost (2*(J-1)) (s+r) (s+r) x (assembleBits r s lo hi,X))) - (Fintype.card ι*heightDecay (J-1)) (Fintype.card ι*heightDecay (J-1)) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [highCost_family J _ hJ,←pow_add,add_self_div_two] using hh - -lemma high_unconditional (d J : ℕ) (hJ : 2≤J) {ι : Type*} [Fintype ι] - (x : ι ↪ Card d) (q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/500) : - finiteMean (fun ω : BenesCoins d => q^(highCost J d x ω)) ≤ - Real.exp (Fintype.card ι*heightDecay (J-1)) := by - simpa only [highCost_family J _ hJ] using - palindrome_high_full_mgf (J-1) d d (by omega) x q hq hlog - - -lemma cost_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply hh.trans (Real.exp_le_exp.mpr _) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -theorem cost_bound_pos (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (cost_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma cost_bound (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ - Real.exp (densityConstant*Fintype.card ι*((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - by_cases hk : 0 momentBase^(f ω))≤Real.exp A) : - Real.log (finiteMean (fun ω => momentBase^(f ω)))≤A := by - apply (Real.log_le_iff_le_exp (finiteMean_pos (fun ω => pow_pos - (lt_of_lt_of_le zero_lt_one momentBase_one_le) _))).mpr h - -lemma high_log {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℕ) (k J : ℕ) - (hJ : 1≤J) (h : finiteMean (fun ω => momentBase^(f ω))≤Real.exp (k*heightDecay (J-1))) : - Real.log (finiteMean (fun ω => momentBase^(f ω)))/Real.log 2 ≤ - constant*k*(2:ℝ)^(-(1/1000:ℝ)*J) := by - have hl:=log_mgf_le f _ h - have hp : 0 momentBase^(palindromeCost d x ω)))/Real.log 2 ≤ - constant*k*((k:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have h:=log_mgf_le (fun ω : BenesCoins d => palindromeCost d x ω) _ (cost_bound d x) - simp only [Fintype.card_fin] at h - have hp : 0 F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +end Thorp + + +namespace Thorp.HighHeight +open scoped BigOperators Classical + +lemma family_weighted (L n d s : ℕ) (hL : 0 F Y*q^(palindromeFamilyCost L n d x (Y,X))) ≤ + finiteMean F*Real.exp (Fintype.card ι*(68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => + simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + mul_one,mul_zero,Real.exp_zero] + exact le_rfl + | succ n ih => + let l := L*4^n + have hl : 0 F Y*q^(palindromeFamilyCost L n d x (Y,X))) := by + intro Y Y' hh + dsimp only + rw [hA Y Y' (agreeThrough_mono (le_max_left _ _) hh)] + congr 2 + exact palindromeFamilyCost_adapted L n d x X Y Y' (agreeThrough_mono (le_max_right _ _) hh) + have hm : finiteMean (fun Y => F Y*q^(palindromeFamilyCost L (n+1) d x (Y,X))) ≤ + finiteMean (fun Y => F Y*q^(palindromeFamilyCost L n d x (Y,X)))* + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l≤d + · simp_rw [hc,pow_add,←mul_assoc] + simpa only [mul_assoc] using palindrome_slab_adapted_mul_le d (max s (familyEnd L n)) l (by omega) + hl hs' x X _ hwt had q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) x,Nat.add_zero] + exact le_mul_of_one_le_right (finiteMean_nonneg hwt) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [mul_assoc,←Real.exp_add,Finset.sum_range_succ] + congr 2 + dsimp [l] + ring + +lemma low_switch_height (r s : ℕ) (j : Card r × SwitchIndex s) : + switchHeight (s+r) ((splitSwitch r s).symm (Sum.inl j)) ≤ s := by + induction r with + | zero => exact switchHeight_le s j.2 + | succ r ih => + exact ih (Fin.tail j.1,j.2) + +def lowCoins (r s : ℕ) (Y : SwitchIndex (s+r) → Bool) : + Card r × SwitchIndex s → Bool := + fun j => Y ((splitSwitch r s).symm (Sum.inl j)) + +lemma lowCoins_adapted (r s : ℕ) : LayerAdapted (s+r) s (lowCoins r s) := by + intro Y Y' hh + funext j + exact hh _ (low_switch_height r s j) + +lemma lowCoins_assemble (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : lowCoins r s (assembleBits r s lo hi)=lo := by + funext j + simp only [lowCoins,assembleBits_eq,Equiv.apply_symm_apply,Sum.elim_inl] + +noncomputable def lowEvent (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (Y : SwitchIndex (s+r) → Bool) : ℝ := if lowCoins r s Y=lo then 1 else 0 + +lemma lowEvent_nonneg (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (Y : SwitchIndex (s+r) → Bool) : 0≤lowEvent r s lo Y := by + unfold lowEvent; split_ifs <;> norm_num + +lemma lowEvent_adapted (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) : + LayerAdapted (s+r) s (lowEvent r s lo) := + layerAdapted_comp (lowCoins_adapted r s) (fun v => if v=lo then (1:ℝ) else 0) + +lemma lowEvent_mean_mul (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (G : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean (fun Y => lowEvent r s lo Y*G Y)= + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi))/ + (Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by + rw [finiteMean_split] + simp only [lowEvent,lowCoins_assemble,ite_mul,one_mul,zero_mul,finiteMean] + simp_rw [Finset.sum_ite_irrel,Finset.sum_const_zero,ite_div,zero_div] + simp + +lemma lowEvent_mean (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) : + finiteMean (lowEvent r s lo)=1/(Fintype.card (Card r × SwitchIndex s → Bool):ℝ) := by + simpa only [mul_one,finiteMean_const] using lowEvent_mean_mul r s lo (fun _ => 1) + +lemma family_partial (L n r s : ℕ) (hL : 0 + q^(palindromeFamilyCost L n (s+r) x (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + have hh:=family_weighted L n (s+r) s hL hs x X (lowEvent r s lo) + (lowEvent_nonneg r s lo) (lowEvent_adapted r s lo) q hq hlog + rw [lowEvent_mean_mul,lowEvent_mean,one_div,mul_comm] at hh + have hp : (0:ℝ) + q^(highCost J (s+r) x (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι*heightDecay (J-1)) := by + have hq2:=one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2)≤1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀:=family_partial (J-1) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2 + have h₁:=family_partial (2*(J-1)) (s+r) r s (by omega) (by omega) x X lo (q^2) hq2 hlog2 + have h₁':=h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show J-1≤2*(J-1) by omega)) (Nat.cast_nonneg _))) + have hh:=finiteMean_mul_exp_le + (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeFamilyCost (J-1) (s+r) (s+r) x (assembleBits r s lo hi,X))) + (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeFamilyCost (2*(J-1)) (s+r) (s+r) x (assembleBits r s lo hi,X))) + (Fintype.card ι*heightDecay (J-1)) (Fintype.card ι*heightDecay (J-1)) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [highCost_family J _ hJ,←pow_add,add_self_div_two] using hh + +lemma high_unconditional (d J : ℕ) (hJ : 2≤J) {ι : Type*} [Fintype ι] + (x : ι ↪ Card d) (q : ℝ) (hq : 1≤q) (hlog : Real.log q≤1/500) : + finiteMean (fun ω : BenesCoins d => q^(highCost J d x ω)) ≤ + Real.exp (Fintype.card ι*heightDecay (J-1)) := by + simpa only [highCost_family J _ hJ] using + palindrome_high_full_mgf (J-1) d d (by omega) x q hq hlog + + +lemma cost_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply hh.trans (Real.exp_le_exp.mpr _) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +theorem cost_bound_pos (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (cost_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma cost_bound (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) ≤ + Real.exp (densityConstant*Fintype.card ι*((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + by_cases hk : 0 momentBase^(f ω))≤Real.exp A) : + Real.log (finiteMean (fun ω => momentBase^(f ω)))≤A := by + apply (Real.log_le_iff_le_exp (finiteMean_pos (fun ω => pow_pos + (lt_of_lt_of_le zero_lt_one momentBase_one_le) _))).mpr h + +lemma high_log {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℕ) (k J : ℕ) + (hJ : 1≤J) (h : finiteMean (fun ω => momentBase^(f ω))≤Real.exp (k*heightDecay (J-1))) : + Real.log (finiteMean (fun ω => momentBase^(f ω)))/Real.log 2 ≤ + constant*k*(2:ℝ)^(-(1/1000:ℝ)*J) := by + have hl:=log_mgf_le f _ h + have hp : 0 momentBase^(palindromeCost d x ω)))/Real.log 2 ≤ + constant*k*((k:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have h:=log_mgf_le (fun ω : BenesCoins d => palindromeCost d x ω) _ (cost_bound d x) + simp only [Fintype.card_fin] at h + have hp : 0 ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -end Thorp - -namespace Thorp.RoutingNetwork -open scoped BigOperators -open Filter -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -end Thorp.RoutingNetwork - -namespace Thorp -open scoped BigOperators -open Filter - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - - -section -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -end - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -end Thorp - -namespace Thorp.CycleColoring -open scoped BigOperators -open Filter -variable {α : Type*} [Fintype α] [DecidableEq α] - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -end Thorp.CycleColoring - -namespace Thorp.PairRouting -open scoped BigOperators -open Filter -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -end Thorp.PairRouting - -namespace Thorp - -section -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -end - -noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -end Thorp - -namespace Thorp.HighHeight -open scoped BigOperators Classical - -noncomputable def highCost (J d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - palindromeCost d x ω-palindromeLowCost (J-1) d x ω - -def MainStatement : Prop := - ∃ b δ C : ℝ, 0 ((2:ℝ)^b)^(highCost J d x ω)))/Real.log 2 ≤ - C*k*(2:ℝ)^(-b*J)) ∧ - (∀ d k : ℕ, ∀ x : Fin k ↪ Card d, - Real.log (finiteMean (fun ω : BenesCoins d => ((2:ℝ)^b)^(palindromeCost d x ω)))/Real.log 2 ≤ - C*k*((k:ℝ)/(2:ℝ)^d)^δ) ∧ - (∀ r s k : ℕ, ∀ x : Fin k ↪ Card (s+r), ∀ J : ℕ, J₀≤J → 2*s - ((2:ℝ)^b)^(highCost J (s+r) x (assembleBits r s lo hi,X))))/Real.log 2 ≤ - C*k*(2:ℝ)^(-b*J)) - -end Thorp.HighHeight - -end ThorpNine.HighTail - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +end Thorp + +namespace Thorp.RoutingNetwork +open scoped BigOperators +open Filter +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +end Thorp.RoutingNetwork + +namespace Thorp +open scoped BigOperators +open Filter + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + + +section +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +end + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +end Thorp + +namespace Thorp.CycleColoring +open scoped BigOperators +open Filter +variable {α : Type*} [Fintype α] [DecidableEq α] + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +end Thorp.CycleColoring + +namespace Thorp.PairRouting +open scoped BigOperators +open Filter +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +end Thorp.PairRouting + +namespace Thorp + +section +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +end + +noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +end Thorp + +namespace Thorp.HighHeight +open scoped BigOperators Classical + +noncomputable def highCost (J d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + palindromeCost d x ω-palindromeLowCost (J-1) d x ω + +def MainStatement : Prop := + ∃ b δ C : ℝ, 0 ((2:ℝ)^b)^(highCost J d x ω)))/Real.log 2 ≤ + C*k*(2:ℝ)^(-b*J)) ∧ + (∀ d k : ℕ, ∀ x : Fin k ↪ Card d, + Real.log (finiteMean (fun ω : BenesCoins d => ((2:ℝ)^b)^(palindromeCost d x ω)))/Real.log 2 ≤ + C*k*((k:ℝ)/(2:ℝ)^d)^δ) ∧ + (∀ r s k : ℕ, ∀ x : Fin k ↪ Card (s+r), ∀ J : ℕ, J₀≤J → 2*s + ((2:ℝ)^b)^(highCost J (s+r) x (assembleBits r s lo hi,X))))/Real.log 2 ≤ + C*k*(2:ℝ)^(-b*J)) + +end Thorp.HighHeight + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/HighTail/ParallelFollow.lean index 978862fb02d85789e651e412399b357207788179..7ce00a822a82fc1472658f110633541e77528646 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/ParallelFollow.lean @@ -1,827 +1,827 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.PriorPaths - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.PriorPaths + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/HighTail/PriorPaths.lean index 98e5d6503b2717dc348fda467aee6295b6a9bf19..fb78ac4a63d7894f5416aa39ffbf4060b8d1dca8 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/PriorPaths.lean @@ -1,876 +1,876 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.AssignmentSlots - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.AssignmentSlots + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/ProjectCycle.lean b/lean/OAI/Probability/ThorpRouting/HighTail/ProjectCycle.lean index a7d80640eafe98f06a1be038592f005c8aea4f32..9aa268aa0b1ddebcaf5d2d0356abee6db1b63379 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/ProjectCycle.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/ProjectCycle.lean @@ -1,811 +1,811 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.ParallelFollow - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -end PairRouting -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.ParallelFollow + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +end PairRouting +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/HighTail/RotationMeeting.lean b/lean/OAI/Probability/ThorpRouting/HighTail/RotationMeeting.lean index 9872557b8cbec7ce3299c57ff88835aa68fe5873..3a64b6d886ce3749dc195ddb8a9d5e67243d0aec 100644 --- a/lean/OAI/Probability/ThorpRouting/HighTail/RotationMeeting.lean +++ b/lean/OAI/Probability/ThorpRouting/HighTail/RotationMeeting.lean @@ -1,878 +1,878 @@ -import Mathlib -import OAI.Probability.ThorpRouting.HighTail.ExposedCoins - -namespace OAI - -namespace ThorpNine.HighTail - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) - (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -end Thorp - -end ThorpNine.HighTail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.HighTail.ExposedCoins + +namespace OAI + +namespace ThorpNine.HighTail + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) + (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +end Thorp + +end ThorpNine.HighTail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Main.lean b/lean/OAI/Probability/ThorpRouting/Main.lean index 706a757ddee8c42360e0209ba1bd268a707340b3..94d3657952538ab7f7f080b0d86d7bd7623f3205 100644 --- a/lean/OAI/Probability/ThorpRouting/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/Main.lean @@ -1,33 +1,33 @@ -import OAI.Probability.ThorpRouting.Adaptive.Main -import OAI.Probability.ThorpRouting.Casimir.Main -import OAI.Probability.ThorpRouting.Contact.Main -import OAI.Probability.ThorpRouting.Dense.Main -import OAI.Probability.ThorpRouting.Harmonic.Main -import OAI.Probability.ThorpRouting.HighTail.Main -import OAI.Probability.ThorpRouting.Smoothing.Main -import OAI.Probability.ThorpRouting.SparseSaving.Main -import OAI.Probability.ThorpRouting.Tail.Main - -namespace OAI - -theorem ThorpNine.main : - ThorpNine.Adaptive.Thorp.AdaptiveBounds.MainStatement ∧ - ThorpNine.Casimir.Thorp.CasimirBounds.MainStatement ∧ - ThorpNine.Dense.Thorp.DenseTruncation.MainStatement ∧ - ThorpNine.Contact.Thorp.SparseContact.MainStatement ∧ - ThorpNine.Harmonic.Thorp.HarmonicBounds.MainStatement ∧ - ThorpNine.Smoothing.Thorp.StrongSmoothing.MainStatement ∧ - ThorpNine.Tail.Thorp.StrongTail.MainStatement ∧ - ThorpNine.HighTail.Thorp.HighHeight.MainStatement ∧ - ThorpNine.SparseSaving.Thorp.SparseRegime.MainStatement := by - exact ⟨ThorpNine.Adaptive.Thorp.AdaptiveBounds.adaptive_main, - ThorpNine.Casimir.Thorp.CasimirBounds.casimir_main, - ThorpNine.Dense.Thorp.DenseTruncation.dense_truncation, - ThorpNine.Contact.Thorp.SparseContact.uniform_sparse_contact, - ThorpNine.Harmonic.Thorp.HarmonicBounds.harmonic_cycle_main, - ThorpNine.Smoothing.Thorp.StrongSmoothing.strong_smoothing, - ThorpNine.Tail.Thorp.StrongTail.strong_tail, - ThorpNine.HighTail.Thorp.HighHeight.high_tail, - ThorpNine.SparseSaving.Thorp.SparseRegime.exponential_sparse_saving⟩ - -end OAI +import OAI.Probability.ThorpRouting.Adaptive.Main +import OAI.Probability.ThorpRouting.Casimir.Main +import OAI.Probability.ThorpRouting.Contact.Main +import OAI.Probability.ThorpRouting.Dense.Main +import OAI.Probability.ThorpRouting.Harmonic.Main +import OAI.Probability.ThorpRouting.HighTail.Main +import OAI.Probability.ThorpRouting.Smoothing.Main +import OAI.Probability.ThorpRouting.SparseSaving.Main +import OAI.Probability.ThorpRouting.Tail.Main + +namespace OAI + +theorem ThorpNine.main : + ThorpNine.Adaptive.Thorp.AdaptiveBounds.MainStatement ∧ + ThorpNine.Casimir.Thorp.CasimirBounds.MainStatement ∧ + ThorpNine.Dense.Thorp.DenseTruncation.MainStatement ∧ + ThorpNine.Contact.Thorp.SparseContact.MainStatement ∧ + ThorpNine.Harmonic.Thorp.HarmonicBounds.MainStatement ∧ + ThorpNine.Smoothing.Thorp.StrongSmoothing.MainStatement ∧ + ThorpNine.Tail.Thorp.StrongTail.MainStatement ∧ + ThorpNine.HighTail.Thorp.HighHeight.MainStatement ∧ + ThorpNine.SparseSaving.Thorp.SparseRegime.MainStatement := by + exact ⟨ThorpNine.Adaptive.Thorp.AdaptiveBounds.adaptive_main, + ThorpNine.Casimir.Thorp.CasimirBounds.casimir_main, + ThorpNine.Dense.Thorp.DenseTruncation.dense_truncation, + ThorpNine.Contact.Thorp.SparseContact.uniform_sparse_contact, + ThorpNine.Harmonic.Thorp.HarmonicBounds.harmonic_cycle_main, + ThorpNine.Smoothing.Thorp.StrongSmoothing.strong_smoothing, + ThorpNine.Tail.Thorp.StrongTail.strong_tail, + ThorpNine.HighTail.Thorp.HighHeight.high_tail, + ThorpNine.SparseSaving.Thorp.SparseRegime.exponential_sparse_saving⟩ + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/RegularTrace.lean b/lean/OAI/Probability/ThorpRouting/RegularTrace.lean index 20b7287cab08ac366e8da5a8cc94cd4e352b4811..eb45fab55711a5ecd8f849e15ee190937dbeedfb 100644 --- a/lean/OAI/Probability/ThorpRouting/RegularTrace.lean +++ b/lean/OAI/Probability/ThorpRouting/RegularTrace.lean @@ -1,93 +1,93 @@ -import OAI.Probability.ThorpRouting.TraceBound - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.LowPlanes -open scoped BigOperators Classical -open Casimir Specht UnitaryFinite - -attribute [local instance] hsNorm hsInner hsFinite - -lemma sharp_physical_fourier (d t : ℕ) : - (2 * distance d t)^2 ≤ ∑ μ : Shapes (2^d), - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * - ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t) - - uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2 := by - let V : Shapes (2^d) → Type := fun μ => hilbertSpace μ.1 - let : ∀ μ, NormedAddCommGroup (V μ) := fun _ => inferInstance - let : ∀ μ, InnerProductSpace ℂ (V μ) := fun _ => inferInstance - let : ∀ μ, FiniteDimensional ℂ (V μ) := fun _ => inferInstance - let p := fun g : Equiv.Perm (Card d) => law d t g - 1/(Nat.factorial (2^d) : ℝ) - have hb := FiniteFourier.l1_fourier_bound V (cardRepresentation d) - (cardRepresentation_unitary d) (cardRepresentation_distinct d) (card_conjugacy_shapes d) p - have he (μ : Shapes (2^d)) : weightedOperator (V := V μ) (cardRepresentation d μ) p = - sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t) - - uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) := by - rw [sampleOperator_weighted, sampleLaw_run] - dsimp only [p] - rw [weighted_sub] - congr 1 - unfold uniformOperator - rw [card_permutations] - simp only [one_div] - simp_rw [he] at hb - convert hb using 1 - change (2 * ((1/2 : ℝ) * ∑ g, |p g|))^2 = (∑ g, |p g|)^2 - ring - -lemma forward_bound (d v : ℕ) (hv : 0 < v) : - (2 * distance d (v*d))^2 ≤ tailBound d v := by - apply (sharp_physical_fourier d (v*d)).trans - apply Finset.sum_le_sum - intro μ _ - by_cases hz : μ.1.card - μ.1.rowLen 0 = 0 - · simp [hz, card_fourier_full_row d (v*d) μ hz] - · simp only [hz, ite_false] - have hu : uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) = 0 := - nontrivial_uniform_zero d μ.1 (cardLabels d μ) (by omega) - rw [hu, sub_zero] - exact mul_le_mul_of_nonneg_left - (physical_power_bound d v hv (cardRepresentation d μ) (cardRepresentation_unitary d μ)) - (sq_nonneg _) - -lemma distance_of_tail_bound (d v : ℕ) (hv : 0 < v) - (ht : tailBound d v ≤ ((2 : ℝ)^d)^(-10 : ℤ)) : - distance d (v*d) ≤ (1/2 : ℝ) * ((2 : ℝ)^d)^(-5 : ℤ) := by - have hb := (forward_bound d v hv).trans ht - have hn : 0 < (2 : ℝ)^d := by positivity - have he : (((2 : ℝ)^d)^(-5 : ℤ))^2 = ((2 : ℝ)^d)^(-10 : ℤ) := by - rw [pow_two, ←zpow_add₀ hn.ne'] - norm_num - have hp : 0 < ((2 : ℝ)^d)^(-5 : ℤ) := zpow_pos hn _ - rw [←he] at hb - have hh : 2 * distance d (v*d) ≤ ((2 : ℝ)^d)^(-5 : ℤ) := by - nlinarith [distance_nonneg d (v*d)] - linarith - -theorem regular_trace_smoothing : MainStatement := by - obtain ⟨u, hu, htail⟩ := uniform_tail_bound - refine ⟨2 * (u : ℝ), ?_, ?_⟩ - · have h : (1 : ℝ) ≤ u := by exact_mod_cast hu - linarith - · intro d hd - refine ⟨?_, ?_⟩ - · exact (regularTrace_le d u (by omega)).trans - (add_le_add le_rfl (htail d hd u le_rfl)) - · intro v hv σ - have hvR : (u : ℝ) ≤ v := by linarith - have hvZ : (u : ℤ) ≤ v := by exact_mod_cast hvR - have hv0 : 0 ≤ v := (Int.natCast_nonneg u).trans hvZ - have hvn : u ≤ v.toNat := by - rw [←Int.toNat_of_nonneg hv0] at hvZ - exact_mod_cast hvZ - change fromDistance d (v.toNat*d) σ ≤ _ - rw [fromDistance_eq] - exact distance_of_tail_bound d v.toNat (by omega) (htail d hd v.toNat hvn) - -end Thorp.LowPlanes - -end ThorpNine.Harmonic - -end OAI +import OAI.Probability.ThorpRouting.TraceBound + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.LowPlanes +open scoped BigOperators Classical +open Casimir Specht UnitaryFinite + +attribute [local instance] hsNorm hsInner hsFinite + +lemma sharp_physical_fourier (d t : ℕ) : + (2 * distance d t)^2 ≤ ∑ μ : Shapes (2^d), + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * + ‖sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t) - + uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ)‖^2 := by + let V : Shapes (2^d) → Type := fun μ => hilbertSpace μ.1 + let : ∀ μ, NormedAddCommGroup (V μ) := fun _ => inferInstance + let : ∀ μ, InnerProductSpace ℂ (V μ) := fun _ => inferInstance + let : ∀ μ, FiniteDimensional ℂ (V μ) := fun _ => inferInstance + let p := fun g : Equiv.Perm (Card d) => law d t g - 1/(Nat.factorial (2^d) : ℝ) + have hb := FiniteFourier.l1_fourier_bound V (cardRepresentation d) + (cardRepresentation_unitary d) (cardRepresentation_distinct d) (card_conjugacy_shapes d) p + have he (μ : Shapes (2^d)) : weightedOperator (V := V μ) (cardRepresentation d μ) p = + sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d t) - + uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) := by + rw [sampleOperator_weighted, sampleLaw_run] + dsimp only [p] + rw [weighted_sub] + congr 1 + unfold uniformOperator + rw [card_permutations] + simp only [one_div] + simp_rw [he] at hb + convert hb using 1 + change (2 * ((1/2 : ℝ) * ∑ g, |p g|))^2 = (∑ g, |p g|)^2 + ring + +lemma forward_bound (d v : ℕ) (hv : 0 < v) : + (2 * distance d (v*d))^2 ≤ tailBound d v := by + apply (sharp_physical_fourier d (v*d)).trans + apply Finset.sum_le_sum + intro μ _ + by_cases hz : μ.1.card - μ.1.rowLen 0 = 0 + · simp [hz, card_fourier_full_row d (v*d) μ hz] + · simp only [hz, ite_false] + have hu : uniformOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) = 0 := + nontrivial_uniform_zero d μ.1 (cardLabels d μ) (by omega) + rw [hu, sub_zero] + exact mul_le_mul_of_nonneg_left + (physical_power_bound d v hv (cardRepresentation d μ) (cardRepresentation_unitary d μ)) + (sq_nonneg _) + +lemma distance_of_tail_bound (d v : ℕ) (hv : 0 < v) + (ht : tailBound d v ≤ ((2 : ℝ)^d)^(-10 : ℤ)) : + distance d (v*d) ≤ (1/2 : ℝ) * ((2 : ℝ)^d)^(-5 : ℤ) := by + have hb := (forward_bound d v hv).trans ht + have hn : 0 < (2 : ℝ)^d := by positivity + have he : (((2 : ℝ)^d)^(-5 : ℤ))^2 = ((2 : ℝ)^d)^(-10 : ℤ) := by + rw [pow_two, ←zpow_add₀ hn.ne'] + norm_num + have hp : 0 < ((2 : ℝ)^d)^(-5 : ℤ) := zpow_pos hn _ + rw [←he] at hb + have hh : 2 * distance d (v*d) ≤ ((2 : ℝ)^d)^(-5 : ℤ) := by + nlinarith [distance_nonneg d (v*d)] + linarith + +theorem regular_trace_smoothing : MainStatement := by + obtain ⟨u, hu, htail⟩ := uniform_tail_bound + refine ⟨2 * (u : ℝ), ?_, ?_⟩ + · have h : (1 : ℝ) ≤ u := by exact_mod_cast hu + linarith + · intro d hd + refine ⟨?_, ?_⟩ + · exact (regularTrace_le d u (by omega)).trans + (add_le_add le_rfl (htail d hd u le_rfl)) + · intro v hv σ + have hvR : (u : ℝ) ≤ v := by linarith + have hvZ : (u : ℤ) ≤ v := by exact_mod_cast hvR + have hv0 : 0 ≤ v := (Int.natCast_nonneg u).trans hvZ + have hvn : u ≤ v.toNat := by + rw [←Int.toNat_of_nonneg hv0] at hvZ + exact_mod_cast hvZ + change fromDistance d (v.toNat*d) σ ≤ _ + rw [fromDistance_eq] + exact distance_of_tail_bound d v.toNat (by omega) (htail d hd v.toNat hvn) + +end Thorp.LowPlanes + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/AlternatingPerm.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/AlternatingPerm.lean index fffe85ba9a21a6ab29659941ed33b0b29bd2cab3..ef568ce2835c2778ace6279dd90027c5f57f7f1b 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/AlternatingPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/AlternatingPerm.lean @@ -1,895 +1,895 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.ParallelFollow - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) - (a : ℝ) (ha : 0 ≤ a) : - (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)))^(1+a) ≤ - (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * - ∑ c ∈ compatibleSet x y, - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by - classical - rw [sandwich_mean,sum_colors_factor] - let f (c : ι → Bool) : ℝ := - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) - have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) - (tupleProbability_nonneg _ _ _) - rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] - have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) - (show 1 ≤ 1+a by linarith) (fun c _ => hf c) - have he : 1+a-1=a := by ring - rw [he] at hh - calc - _ ≤ (outerWeight x y)^(1+a) * - (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := - mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) - _ = _ := by - rw [←mul_assoc] - congr 1 - apply Finset.sum_congr rfl - intro c _ - exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) - -end PairRouting - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.ParallelFollow + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) + (a : ℝ) (ha : 0 ≤ a) : + (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)))^(1+a) ≤ + (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * + ∑ c ∈ compatibleSet x y, + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by + classical + rw [sandwich_mean,sum_colors_factor] + let f (c : ι → Bool) : ℝ := + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) + have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) + (tupleProbability_nonneg _ _ _) + rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] + have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) + (show 1 ≤ 1+a by linarith) (fun c _ => hf c) + have he : 1+a-1=a := by ring + rw [he] at hh + calc + _ ≤ (outerWeight x y)^(1+a) * + (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := + mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) + _ = _ := by + rw [←mul_assoc] + congr 1 + apply Finset.sum_congr rfl + intro c _ + exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) + +end PairRouting + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/AssignmentSlots.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/AssignmentSlots.lean index da2eee18e266ec26aa55bd43acc53e2b4b01ed1a..4801d88454d98fb554db331deb0d5f64d033bdab 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/AssignmentSlots.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/AssignmentSlots.lean @@ -1,816 +1,816 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.RotationCharge - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter -section CycleCounting -variable {d A : ℕ} - -lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {d A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr - -end GroupedCounting - -section AllLengths -variable {d A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) - (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) - (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : - finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by - have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by - rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] - exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm - have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), - ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by - calc - _ = ((q-1)+1)^(F ω) := by congr 1; ring - _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by - rw [add_pow] - simp only [one_pow,mul_one] - _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by - apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) - intro a _ ha - have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega - rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] - _ = _ := by - apply Finset.sum_congr rfl - intro a _ - rw [hc] - ring - simp_rw [hex,finiteMean_sum,finiteMean_mul_const] - calc - _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_right (hm a) (by positivity) - _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by - apply Finset.sum_congr rfl - intro a _ - rw [mul_pow] - ring - _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ - -lemma inv_sqrt_step (j : ℕ) : - 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by - have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) - apply (div_le_iff₀ hp).mpr - have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) - have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) - nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] - -lemma sum_inv_sqrt (J : ℕ) : - (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by - have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ] - have hs := inv_sqrt_step n - push_cast - linarith - rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] - exact h J -section CycleMGF -variable {d : ℕ} - -lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment S J - -end CycleMGF - -section FullCycleMGF -variable {d : ℕ} - -abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by - apply div_pos - · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty - · exact Nat.cast_pos.mpr Fintype.card_pos - -lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - -end FullCycleMGF - -structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] - [Fintype ι] [DecidableEq ι] (d : ℕ) where - perm : (ι → Bool) → Equiv.Perm α - path : (ι → Bool) → α → Finset ι - users : (ι → Bool) → ι → α × α - users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 - mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x - card_path : ∀ ω x, (path ω x).card = d - entropy : ∀ ω (S : Finset α), - (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) - follow : α → (α → QueryTree ι) → QueryTree ι - close : α → α → QueryTree ι → QueryTree ι - follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω - follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω - follow_stale_charge : ∀ x k R ω, - (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω - close_succeeds : ∀ x y k ω, - (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false - close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d - close_stale_charge : ∀ x y k R ω, perm ω x = y → - (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card - -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma card_switches_using (ω : ι → Bool) (x : α) : - (Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by - ext i - simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] - rw [he,R.card_path] -lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = - (d : ℝ) * ∑ x : α, w x := by - classical - calc - _ = ∑ i : ι, ∑ x : α, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : α => - (R.users b i).1 = x ∨ (R.users b i).2 = x) = - {(R.users b i).1, (R.users b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (R.users_ne b i)] - _ = ∑ x : α, ∑ i : ι, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : α, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ - (d : ℝ) / 2 * ∑ x : α, w x := by - have h : 2 * (∑ i : ι, - min (w (R.users b i).1) (w (R.users b i).2)) ≤ - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), - min_le_right (w (R.users b i).1) (w (R.users b i).2)] - rw [switch_incidence_sum] at h - linarith -section Rotation -variable {A : ℕ} - -def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -omit [DecidableEq α] in -@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} - -noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) - (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -omit [DecidableEq α] in -lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : - Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (i : Fin A) (x : α) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -omit [DecidableEq α] in -lemma slotWeight_antitone (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -omit [DecidableEq α] in -lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : α, pathWeight o x = (A : ℝ) := by - classical - have he (x : α) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : - (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : α) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := R.entropy b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) - (z : Terminal o) : ℝ := - ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 - -lemma rotationCharge_mean_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound R b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound R o hn b - linarith - -lemma rotation_exp_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have hb := rotationCharge_mean_bound R hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -namespace QueryTree -open Thorp.QueryTree - -noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : - ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → - QueryTree (ι) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x - (fun y => seekCycle R S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) - (ω : ι → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle R S a r x V k).succeeds ω = true) : - (seekCycle R S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs - rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - -noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : - List (α × ℕ) → Finset (α) → QueryTree (ι) - | [], _ => accept - | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) - -lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) - (V : Finset (α)) (ω : ι → Bool) - (hs : (seekCycles R S L V).succeeds ω = true) : - (seekCycles R S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : - finiteMean (fun ω : ι → Bool => - if (seekCycles R S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles R S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge R S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree -noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : - Finset (ι) := - V.biUnion (fun x => R.path b x) - -@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : - exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := - (R.path b z ∩ exposedPaths R b V).card - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V W : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : - (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (S V : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (hS : orbitSet (R.perm ω) z ⊆ S) - (hV : Disjoint V (orbitSet (R.perm ω) z)) : - let p := R.perm ω - let W := V ∪ orbitSet p z - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -end RoutingNetwork -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.RotationCharge + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter +section CycleCounting +variable {d A : ℕ} + +lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {d A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr + +end GroupedCounting + +section AllLengths +variable {d A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) + (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) + (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : + finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by + have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by + rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] + exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm + have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), + ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by + calc + _ = ((q-1)+1)^(F ω) := by congr 1; ring + _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by + rw [add_pow] + simp only [one_pow,mul_one] + _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by + apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) + intro a _ ha + have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega + rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [hc] + ring + simp_rw [hex,finiteMean_sum,finiteMean_mul_const] + calc + _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_right (hm a) (by positivity) + _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by + apply Finset.sum_congr rfl + intro a _ + rw [mul_pow] + ring + _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ + +lemma inv_sqrt_step (j : ℕ) : + 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by + have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) + apply (div_le_iff₀ hp).mpr + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) + have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) + nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] + +lemma sum_inv_sqrt (J : ℕ) : + (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by + have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ] + have hs := inv_sqrt_step n + push_cast + linarith + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] + exact h J +section CycleMGF +variable {d : ℕ} + +lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment S J + +end CycleMGF + +section FullCycleMGF +variable {d : ℕ} + +abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by + apply div_pos + · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty + · exact Nat.cast_pos.mpr Fintype.card_pos + +lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + +end FullCycleMGF + +structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] + [Fintype ι] [DecidableEq ι] (d : ℕ) where + perm : (ι → Bool) → Equiv.Perm α + path : (ι → Bool) → α → Finset ι + users : (ι → Bool) → ι → α × α + users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 + mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x + card_path : ∀ ω x, (path ω x).card = d + entropy : ∀ ω (S : Finset α), + (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) + follow : α → (α → QueryTree ι) → QueryTree ι + close : α → α → QueryTree ι → QueryTree ι + follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω + follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω + follow_stale_charge : ∀ x k R ω, + (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω + close_succeeds : ∀ x y k ω, + (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false + close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d + close_stale_charge : ∀ x y k R ω, perm ω x = y → + (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card + +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma card_switches_using (ω : ι → Bool) (x : α) : + (Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by + ext i + simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] + rw [he,R.card_path] +lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = + (d : ℝ) * ∑ x : α, w x := by + classical + calc + _ = ∑ i : ι, ∑ x : α, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : α => + (R.users b i).1 = x ∨ (R.users b i).2 = x) = + {(R.users b i).1, (R.users b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (R.users_ne b i)] + _ = ∑ x : α, ∑ i : ι, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : α, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ + (d : ℝ) / 2 * ∑ x : α, w x := by + have h : 2 * (∑ i : ι, + min (w (R.users b i).1) (w (R.users b i).2)) ≤ + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), + min_le_right (w (R.users b i).1) (w (R.users b i).2)] + rw [switch_incidence_sum] at h + linarith +section Rotation +variable {A : ℕ} + +def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +omit [DecidableEq α] in +@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} + +noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) + (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +omit [DecidableEq α] in +lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : + Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (i : Fin A) (x : α) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +omit [DecidableEq α] in +lemma slotWeight_antitone (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +omit [DecidableEq α] in +lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : α, pathWeight o x = (A : ℝ) := by + classical + have he (x : α) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : + (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : α) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := R.entropy b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) + (z : Terminal o) : ℝ := + ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 + +lemma rotationCharge_mean_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound R b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound R o hn b + linarith + +lemma rotation_exp_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have hb := rotationCharge_mean_bound R hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +namespace QueryTree +open Thorp.QueryTree + +noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : + ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → + QueryTree (ι) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x + (fun y => seekCycle R S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) + (ω : ι → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle R S a r x V k).succeeds ω = true) : + (seekCycle R S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs + rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + +noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : + List (α × ℕ) → Finset (α) → QueryTree (ι) + | [], _ => accept + | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) + +lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) + (V : Finset (α)) (ω : ι → Bool) + (hs : (seekCycles R S L V).succeeds ω = true) : + (seekCycles R S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : + finiteMean (fun ω : ι → Bool => + if (seekCycles R S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles R S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge R S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree +noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : + Finset (ι) := + V.biUnion (fun x => R.path b x) + +@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : + exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := + (R.path b z ∩ exposedPaths R b V).card + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V W : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : + (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (S V : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (hS : orbitSet (R.perm ω) z ⊆ S) + (hV : Disjoint V (orbitSet (R.perm ω) z)) : + let p := R.perm ω + let W := V ∪ orbitSet p z + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +end RoutingNetwork +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/BenesCoins.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/BenesCoins.lean index e9c32deb1fdd76f667bac296719bfa20b3be4a7a..27dcf9de9975f75d0833c6491dadb82d223336bd 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/BenesCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/BenesCoins.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.AlternatingPerm - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - childLift p * childLift q = childLift (fun b => p b * q b) := by - ext x i - simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] - -lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl - -lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl - -lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * - pairSwitch coins.1 := by - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * - (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : - headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl - -lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : - headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl - -lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : - headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) - (headTailEquiv d x) := by - rw [palindromePerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by - obtain ⟨x,hx⟩ := C.nonempty - have hpx : alternatingPerm p x ∈ C.val := by - rw [←C.orbit_eq hx,mem_orbitSet] - exact (Equiv.Perm.SameCycle.refl _ _).apply_right - have hne : x ≠ alternatingPerm p x := by - intro he - have hh := congrArg Prod.fst he - rw [alternatingPerm_flip] at hh - cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh - have hs : {x,alternatingPerm p x} ⊆ C.val := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl <;> assumption - have hh := Finset.card_le_card hs - simpa only [Finset.card_pair hne] using hh - -lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : - 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by - classical - calc - _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] - _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := - Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) - _ ≤ _ := RoutingNetwork.cycleMass_le _ _ - -lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) - (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by - have h := alternating_cycle_count_double p S - omega - -end CycleColoring - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - 2 * alternatingCycles e p ≤ Fintype.card ι := by - have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) - simpa only [alternatingCycles, card_labelSet] using hh - -lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by - have hh := alternatingCycles_double e p - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : - colors x (chosenCoin x c) = c := by - funext i - simp only [colors,chosenCoin_apply x c hc i,required] - cases (x i).1 <;> cases c i <;> rfl - -noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : - ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) - -omit [Fintype α] [DecidableEq ι] in -lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - coloredEmbedding x c hc i = (c i,(x i).2) := by - apply Prod.ext - · exact congrFun (colors_chosenCoin x c hc) i - · rfl - -omit [Fintype α] [DecidableEq ι] in -lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) - (ξ : α → Bool) (he : colors x ξ = c) : - switchedEmbedding x ξ = coloredEmbedding x c hc := by - ext i : 1 - rw [coloredEmbedding_apply] - apply Prod.ext - · exact congrFun he i - · rfl - -lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - (compatibleSet x y).card ≤ - 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + - alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by - obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc - let ξ := chosenCoin x c - let η := chosenCoin y c - have he : routedEmbedding x ξ η p = y := by - ext i : 1 - have h := (sandwich_matches_iff ξ η p x y).mpr - ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by - simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ - exact h i - have hh := assignments_actual_bound x ξ η p - rw [he] at hh - rw [card_compatibleSet] - exact hh - -omit [Fintype α] [DecidableEq ι] in -lemma occupied_sum_ge (x y : ι ↪ Bool × α) : - Fintype.card ι ≤ (occupied x).card + (occupied y).card := by - have h₀ := occupied_card_double x - have h₁ := occupied_card_double y - omega - -lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ - (2:ℝ)^((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by - let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p - let b := (occupied x).card+(occupied y).card - let h := Fintype.card ι - have hb : h ≤ b := occupied_sum_ge x y - have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by - exact_mod_cast assignments_match_bound x y c hc p hm - change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) - rw [mul_one_div] - calc - _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) - _ = _ := by - rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] - congr 1 - rw [Nat.cast_add,Nat.cast_sub hb] - ring - -lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) - (a : ℝ) (ha : 0 ≤ a) : - (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ - (2:ℝ)^(((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by - have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) - (assignment_weight_bound x y c hc p hm) ha - rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), - ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h - simpa only [mul_comm] using h - - -lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, - if ChildMatches p x y c.val then W c.val else 0 := by - rw [sandwich_weighted_probability] - congr 1 - rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] - -omit [Fintype α] [DecidableEq α] [DecidableEq ι] in -lemma color_card_add (c : ι → Bool) : - Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by - have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by - cases c i <;> simp - rw [Fintype.card_congr he] - rw [Fintype.card_subtype_compl] - exact Nat.add_sub_of_le (Fintype.card_subtype_le _) - -end PairRouting - -noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) - (ω : BenesCoins d × BenesCoins d) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => palindromePerm d (if b then ω.2 else ω.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 - -lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : - palindromeCost (d+1) e σ = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) - (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by - unfold palindromeCost assignmentCost - dsimp only - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - -lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [palindromeCost_eq] - simp only [Equiv.apply_symm_apply] - -noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : BenesCoins d => - if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) - -lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma palindrome_matches_step (d : ℕ) {ι : Type*} - (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] - rfl - -lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (d+1)) (a : ℝ) : - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - routingMoment (d+1) e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have he (ω : BenesCoins d × BenesCoins d) : - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [palindrome_matches_step,palindromeCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold routingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = - (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (d+1)) : - PairRouting.tupleProbability (palindromePerm (d+1)) e f = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have hp (b : Bool) (p q : BenesCoins d) : - palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by - cases b <;> rfl - simp only [palindrome_matches_step,hp] - -lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) - rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh - have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = - -(d:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - rwa [he] at hh - -lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - -theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by - classical - induction d generalizing ι with - | zero => - have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := - fun _ _ => Subsingleton.elim _ _ - simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] - | succ d ih => - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) - have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha - rw [←palindrome_probability_step d e f] at hnode - change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) - ring - -lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : - (∑ f : ι ↪ Card d, routingMoment d e f a) = - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - unfold routingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] - (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : - finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = - (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] - rw [Real.rpow_add hn,Real.rpow_one] - field_simp - -noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card d => - ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) - -lemma density_normalization (d h n : ℕ) (a : ℝ) : - (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by - rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] - rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, - Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] - -theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - palindromeRowMoment d e a ≤ - (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card d) := ⟨e⟩ - rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * - ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, - Fintype.card_embedding_eq,card_positions] - norm_cast - -end Thorp -namespace Thorp - -lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] - (A : Finset α) (T : β → Finset α) : - (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = - ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by - classical - by_cases h : Finset.univ.biUnion T ⊆ A - · rw [ite_eq_left h] - symm - apply Finset.prod_eq_one - intro b _ - rw [ite_eq_left] - exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h - · rw [ite_eq_right h] - obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h - obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - rw [ite_eq_right] - exact fun hb => hxA (hb hxb) - -lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] - [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] - (F : Ω → Finset α) (p : α → ℝ) - (hF : CylinderBound (inclusionMoment F) p) - (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) - (hc : ∀ b s, 0 ≤ c b s) - (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : - finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ - ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by - classical - simp_rw [Fintype.prod_sum] - rw [finiteMean_sum] - apply Finset.sum_le_sum - intro s _ - let U := Finset.univ.biUnion (fun b => T b (s b)) - have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = - fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by - funext ω - rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] - exact mul_comm _ _ - rw [he,finiteMean_mul_const] - have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by - intro b _ b' _ hbb - exact hd b b' hbb (s b) (s b') - have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - by_cases hh : U ⊆ F ω <;> simp [hh] - calc - _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := - mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) - _ = _ := by - dsimp only [U] - rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro b _ - exact mul_comm _ _ - - -noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := - if T.card = 1 then 0 else w^T.card - -lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : - 0 ≤ sparseCoefficient w T := by - unfold sparseCoefficient - split_ifs <;> positivity - -lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) - (w : ℝ) (hw : 0 ≤ w) : - w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ - ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by - classical - let V := D ∩ A - let T : ↑D.powerset := if 2 ≤ V.card then - ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else - ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ - calc - _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by - by_cases h : 2 ≤ V.card - · have hn : V.card ≠ 1 := by omega - simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] - · simp [T,ite_eq_right h,sparseCoefficient,V] at * - _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => - sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) - (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) - (by split_ifs <;> norm_num)) (Finset.mem_univ T) - -lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : - ∑ i ∈ Finset.range n, x^i ≤ 2 := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ',pow_zero] - simp only [pow_succ',←Finset.mul_sum] - nlinarith - -lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : - ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ - 1 + 2*((R:ℝ)*z)^2 := by - classical - let x := (R:ℝ)*z - have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz - have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ - if i=1 then 0 else x^i := by - by_cases h : i=1 - · simp [h] - · simp only [ite_eq_right h] - dsimp [x] - rw [mul_pow] - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) - exact_mod_cast Nat.choose_le_pow R i - calc - _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := - Finset.sum_le_sum (fun i _ => hbound i) - _ ≤ 1+2*x^2 := by - rcases R with _ | R - · simp [x] - rcases R with _ | R - · norm_num [Finset.sum_range_succ] - positivity - have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = - 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by - rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] - have hn (i : ℕ) : 2+i ≠ 1 := by omega - simp only [hn,ite_false,pow_add,←Finset.mul_sum] - norm_num [Finset.sum_range_succ] - rw [he] - have hg := geometric_sum_half (R+1) hx hr - nlinarith [sq_nonneg x] - -lemma sparse_block_product_bound {α : Type*} [DecidableEq α] - (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : - ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ - Real.exp (2*((D.card:ℝ)*(p*w))^2) := by - classical - have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = - ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by - rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] - have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = - fun T => if T.card=1 then 0 else (p*w)^T.card := by - funext T - unfold sparseCoefficient - split_ifs <;> simp [mul_pow,mul_comm] - change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ - rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] - simp only [nsmul_eq_mul] - rw [he] - exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans - (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) - - -noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] - (D : β → Finset α) (A : Finset α) : ℕ := - ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 - -theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] - (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hF : ∀ T, inclusionMoment F T ≤ p^T.card) - (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : - finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by - classical - have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by - intro T - simpa only [Finset.prod_const] using hF T - have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc - (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) - (fun _ S => sparseCoefficient_nonneg w hw S.val) - (fun b b' h S S' => (hd h).mono - (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) - calc - _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, - sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by - apply finiteMean_mono - intro ω - rw [sparseMass,←Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) - intro b _ - exact sparse_block_pointwise (F ω) (D b) w hw - _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by - simpa only [Finset.prod_const] using hb - _ ≤ _ := by - rw [Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact Finset.sum_nonneg (fun S _ => mul_nonneg - (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) - · intro b _ - exact sparse_block_product_bound (D b) p w hp hw (hr b) - -theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] - (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) - (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : - finiteMean (fun ω : SwitchIndex d → Bool => - w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by - apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w - (by positivity) hw - · exact inverseButterflyMarks_inclusion d A - · exact hr - - -def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 - -lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by - unfold crowdedMass - split_ifs <;> omega - -lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by - unfold crowdedMass - split_ifs <;> omega - -lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by - unfold crowdedMass - split_ifs with h - · have hh := PairRouting.alternatingCycles_double e p - omega - · rw [PairRouting.alternatingCycles_zero e p (by omega)] - -lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by - classical - induction d generalizing ι with - | zero => simp [palindromeCost] - | succ d ih => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 - have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 - have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) - have hs := crowdedMass_add (Fintype.card {i // c i = false}) - (Fintype.card {i // c i = true}) - rw [PairRouting.color_card_add] at hs - change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ - nlinarith - -noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, ι, _, e, ω => - if d+1 ≤ H then crowdedMass (Fintype.card ι) else - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = palindromeCost d e ω := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLowCost,palindromeCost,ite_eq_left h] - congr 2 <;> exact ih (by omega) _ _ - -lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by - classical - induction d generalizing ι with - | zero => simp [palindromeLowCost,cutoffMass] - | succ d ih => - by_cases h : d+1 ≤ H - · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] - exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) - · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] - exact Nat.add_le_add (ih _ _) (ih _ _) - - -noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := - Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.AlternatingPerm + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + childLift p * childLift q = childLift (fun b => p b * q b) := by + ext x i + simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] + +lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl + +lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl + +lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * + pairSwitch coins.1 := by + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * + (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : + headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl + +lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : + headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl + +lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : + headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) + (headTailEquiv d x) := by + rw [palindromePerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by + obtain ⟨x,hx⟩ := C.nonempty + have hpx : alternatingPerm p x ∈ C.val := by + rw [←C.orbit_eq hx,mem_orbitSet] + exact (Equiv.Perm.SameCycle.refl _ _).apply_right + have hne : x ≠ alternatingPerm p x := by + intro he + have hh := congrArg Prod.fst he + rw [alternatingPerm_flip] at hh + cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh + have hs : {x,alternatingPerm p x} ⊆ C.val := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl <;> assumption + have hh := Finset.card_le_card hs + simpa only [Finset.card_pair hne] using hh + +lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : + 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by + classical + calc + _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] + _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := + Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) + _ ≤ _ := RoutingNetwork.cycleMass_le _ _ + +lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) + (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by + have h := alternating_cycle_count_double p S + omega + +end CycleColoring + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + 2 * alternatingCycles e p ≤ Fintype.card ι := by + have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) + simpa only [alternatingCycles, card_labelSet] using hh + +lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by + have hh := alternatingCycles_double e p + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : + colors x (chosenCoin x c) = c := by + funext i + simp only [colors,chosenCoin_apply x c hc i,required] + cases (x i).1 <;> cases c i <;> rfl + +noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : + ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) + +omit [Fintype α] [DecidableEq ι] in +lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + coloredEmbedding x c hc i = (c i,(x i).2) := by + apply Prod.ext + · exact congrFun (colors_chosenCoin x c hc) i + · rfl + +omit [Fintype α] [DecidableEq ι] in +lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) + (ξ : α → Bool) (he : colors x ξ = c) : + switchedEmbedding x ξ = coloredEmbedding x c hc := by + ext i : 1 + rw [coloredEmbedding_apply] + apply Prod.ext + · exact congrFun he i + · rfl + +lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + (compatibleSet x y).card ≤ + 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + + alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by + obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc + let ξ := chosenCoin x c + let η := chosenCoin y c + have he : routedEmbedding x ξ η p = y := by + ext i : 1 + have h := (sandwich_matches_iff ξ η p x y).mpr + ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by + simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ + exact h i + have hh := assignments_actual_bound x ξ η p + rw [he] at hh + rw [card_compatibleSet] + exact hh + +omit [Fintype α] [DecidableEq ι] in +lemma occupied_sum_ge (x y : ι ↪ Bool × α) : + Fintype.card ι ≤ (occupied x).card + (occupied y).card := by + have h₀ := occupied_card_double x + have h₁ := occupied_card_double y + omega + +lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ + (2:ℝ)^((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by + let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p + let b := (occupied x).card+(occupied y).card + let h := Fintype.card ι + have hb : h ≤ b := occupied_sum_ge x y + have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by + exact_mod_cast assignments_match_bound x y c hc p hm + change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) + rw [mul_one_div] + calc + _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by + rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] + congr 1 + rw [Nat.cast_add,Nat.cast_sub hb] + ring + +lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) + (a : ℝ) (ha : 0 ≤ a) : + (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ + (2:ℝ)^(((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by + have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) + (assignment_weight_bound x y c hc p hm) ha + rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), + ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h + simpa only [mul_comm] using h + + +lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, + if ChildMatches p x y c.val then W c.val else 0 := by + rw [sandwich_weighted_probability] + congr 1 + rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] + +omit [Fintype α] [DecidableEq α] [DecidableEq ι] in +lemma color_card_add (c : ι → Bool) : + Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by + have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by + cases c i <;> simp + rw [Fintype.card_congr he] + rw [Fintype.card_subtype_compl] + exact Nat.add_sub_of_le (Fintype.card_subtype_le _) + +end PairRouting + +noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) + (ω : BenesCoins d × BenesCoins d) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => palindromePerm d (if b then ω.2 else ω.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 + +lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : + palindromeCost (d+1) e σ = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) + (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by + unfold palindromeCost assignmentCost + dsimp only + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + +lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [palindromeCost_eq] + simp only [Equiv.apply_symm_apply] + +noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : BenesCoins d => + if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) + +lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma palindrome_matches_step (d : ℕ) {ι : Type*} + (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] + rfl + +lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (d+1)) (a : ℝ) : + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + routingMoment (d+1) e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have he (ω : BenesCoins d × BenesCoins d) : + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [palindrome_matches_step,palindromeCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold routingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = + (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (d+1)) : + PairRouting.tupleProbability (palindromePerm (d+1)) e f = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have hp (b : Bool) (p q : BenesCoins d) : + palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by + cases b <;> rfl + simp only [palindrome_matches_step,hp] + +lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) + rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh + have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = + -(d:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + rwa [he] at hh + +lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + +theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by + classical + induction d generalizing ι with + | zero => + have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := + fun _ _ => Subsingleton.elim _ _ + simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] + | succ d ih => + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) + have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha + rw [←palindrome_probability_step d e f] at hnode + change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) + ring + +lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : + (∑ f : ι ↪ Card d, routingMoment d e f a) = + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + unfold routingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] + (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : + finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = + (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] + rw [Real.rpow_add hn,Real.rpow_one] + field_simp + +noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card d => + ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) + +lemma density_normalization (d h n : ℕ) (a : ℝ) : + (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by + rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] + rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, + Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] + +theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + palindromeRowMoment d e a ≤ + (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card d) := ⟨e⟩ + rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * + ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, + Fintype.card_embedding_eq,card_positions] + norm_cast + +end Thorp +namespace Thorp + +lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] + (A : Finset α) (T : β → Finset α) : + (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = + ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by + classical + by_cases h : Finset.univ.biUnion T ⊆ A + · rw [ite_eq_left h] + symm + apply Finset.prod_eq_one + intro b _ + rw [ite_eq_left] + exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h + · rw [ite_eq_right h] + obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h + obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + rw [ite_eq_right] + exact fun hb => hxA (hb hxb) + +lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] + [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] + (F : Ω → Finset α) (p : α → ℝ) + (hF : CylinderBound (inclusionMoment F) p) + (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) + (hc : ∀ b s, 0 ≤ c b s) + (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : + finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ + ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by + classical + simp_rw [Fintype.prod_sum] + rw [finiteMean_sum] + apply Finset.sum_le_sum + intro s _ + let U := Finset.univ.biUnion (fun b => T b (s b)) + have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = + fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by + funext ω + rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] + exact mul_comm _ _ + rw [he,finiteMean_mul_const] + have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by + intro b _ b' _ hbb + exact hd b b' hbb (s b) (s b') + have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + by_cases hh : U ⊆ F ω <;> simp [hh] + calc + _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := + mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) + _ = _ := by + dsimp only [U] + rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro b _ + exact mul_comm _ _ + + +noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := + if T.card = 1 then 0 else w^T.card + +lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : + 0 ≤ sparseCoefficient w T := by + unfold sparseCoefficient + split_ifs <;> positivity + +lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) + (w : ℝ) (hw : 0 ≤ w) : + w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ + ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by + classical + let V := D ∩ A + let T : ↑D.powerset := if 2 ≤ V.card then + ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else + ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ + calc + _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by + by_cases h : 2 ≤ V.card + · have hn : V.card ≠ 1 := by omega + simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] + · simp [T,ite_eq_right h,sparseCoefficient,V] at * + _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => + sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) + (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) + (by split_ifs <;> norm_num)) (Finset.mem_univ T) + +lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : + ∑ i ∈ Finset.range n, x^i ≤ 2 := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ',pow_zero] + simp only [pow_succ',←Finset.mul_sum] + nlinarith + +lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : + ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ + 1 + 2*((R:ℝ)*z)^2 := by + classical + let x := (R:ℝ)*z + have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz + have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ + if i=1 then 0 else x^i := by + by_cases h : i=1 + · simp [h] + · simp only [ite_eq_right h] + dsimp [x] + rw [mul_pow] + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) + exact_mod_cast Nat.choose_le_pow R i + calc + _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := + Finset.sum_le_sum (fun i _ => hbound i) + _ ≤ 1+2*x^2 := by + rcases R with _ | R + · simp [x] + rcases R with _ | R + · norm_num [Finset.sum_range_succ] + positivity + have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = + 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by + rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] + have hn (i : ℕ) : 2+i ≠ 1 := by omega + simp only [hn,ite_false,pow_add,←Finset.mul_sum] + norm_num [Finset.sum_range_succ] + rw [he] + have hg := geometric_sum_half (R+1) hx hr + nlinarith [sq_nonneg x] + +lemma sparse_block_product_bound {α : Type*} [DecidableEq α] + (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : + ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ + Real.exp (2*((D.card:ℝ)*(p*w))^2) := by + classical + have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = + ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by + rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] + have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = + fun T => if T.card=1 then 0 else (p*w)^T.card := by + funext T + unfold sparseCoefficient + split_ifs <;> simp [mul_pow,mul_comm] + change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ + rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] + simp only [nsmul_eq_mul] + rw [he] + exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans + (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) + + +noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] + (D : β → Finset α) (A : Finset α) : ℕ := + ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 + +theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] + (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hF : ∀ T, inclusionMoment F T ≤ p^T.card) + (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : + finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by + classical + have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by + intro T + simpa only [Finset.prod_const] using hF T + have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc + (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) + (fun _ S => sparseCoefficient_nonneg w hw S.val) + (fun b b' h S S' => (hd h).mono + (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) + calc + _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, + sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by + apply finiteMean_mono + intro ω + rw [sparseMass,←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) + intro b _ + exact sparse_block_pointwise (F ω) (D b) w hw + _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by + simpa only [Finset.prod_const] using hb + _ ≤ _ := by + rw [Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact Finset.sum_nonneg (fun S _ => mul_nonneg + (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) + · intro b _ + exact sparse_block_product_bound (D b) p w hp hw (hr b) + +theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] + (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) + (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : + finiteMean (fun ω : SwitchIndex d → Bool => + w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by + apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w + (by positivity) hw + · exact inverseButterflyMarks_inclusion d A + · exact hr + + +def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 + +lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by + unfold crowdedMass + split_ifs <;> omega + +lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by + unfold crowdedMass + split_ifs <;> omega + +lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by + unfold crowdedMass + split_ifs with h + · have hh := PairRouting.alternatingCycles_double e p + omega + · rw [PairRouting.alternatingCycles_zero e p (by omega)] + +lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by + classical + induction d generalizing ι with + | zero => simp [palindromeCost] + | succ d ih => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 + have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 + have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + have hs := crowdedMass_add (Fintype.card {i // c i = false}) + (Fintype.card {i // c i = true}) + rw [PairRouting.color_card_add] at hs + change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ + nlinarith + +noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, ι, _, e, ω => + if d+1 ≤ H then crowdedMass (Fintype.card ι) else + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = palindromeCost d e ω := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLowCost,palindromeCost,ite_eq_left h] + congr 2 <;> exact ih (by omega) _ _ + +lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by + classical + induction d generalizing ι with + | zero => simp [palindromeLowCost,cutoffMass] + | succ d ih => + by_cases h : d+1 ≤ H + · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] + exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) + · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] + exact Nat.add_le_add (ih _ _) (ih _ _) + + +noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := + Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/Coins.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/Coins.lean index b6d239e6e5e5e68f2c275333babc1a1f148f300c..64c1936bbcbc7cfa2f85039e5c1018a41fb5c731 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/Coins.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/Coins.lean @@ -1,776 +1,776 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.Model - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp - -open scoped BigOperators -open Filter - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Card d → Bool - -instance (d : ℕ) : Fintype (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -instance (d : ℕ) : Nonempty (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -def rotate (d : ℕ) : Equiv.Perm (Card d) where - toFun x i := x (finRotate d i) - invFun x i := x ((finRotate d).symm i) - left_inv x := by funext i; simp only [Equiv.apply_symm_apply] - right_inv x := by funext i; simp only [Equiv.symm_apply_apply] - -def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, ξ => rotate (d + 1) * pairSwitch ξ - -def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) - | 0, _ => 1 - | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) - -noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := - (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / - (Fintype.card (Fin t → Coins d) : ℝ) - -noncomputable def distance (d t : ℕ) : ℝ := - (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| - -noncomputable def mixingTime (d : ℕ) : ℕ := - sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} - -noncomputable def supportTimeBound (d : ℕ) : ℤ := - ⌈(2 / (2 : ℝ) ^ d) * - (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ - -def OptimalOrder : Prop := - ∃ C : ℕ, 0 < C ∧ - Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ - (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ - (∀ᶠ d : ℕ in atTop, - supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ - (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) - -noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by - classical - exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) - -lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : - ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by - classical - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : - 0 ≤ finiteLaw f b := by - exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - -lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : - ∑ b, finiteLaw f b = 1 := by - classical - simp only [finiteLaw, ← Finset.sum_div] - have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by - exact_mod_cast sum_card_fibers f - rw [hc] - exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by - classical - have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr - ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ - simp [finiteLaw] - -lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] - (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : - (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by - have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := - Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) - have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) - have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) - have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) - rw [hpq] at hz - rw [← Finset.sum_sub_distrib] - linarith - -lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] - [Fintype β] [Nonempty β] (f : α → β) : - 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ - (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by - classical - let s := Finset.univ.image f - have hs : ∑ b ∈ s, finiteLaw f b = 1 := by - have h := Finset.sum_subset (Finset.subset_univ s) - (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) - simpa only [finiteLaw_sum] using h - have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] - have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by - rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] - have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s - rw [hs] at he - have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by - simp [div_eq_mul_inv] - rw [hsq] at he - have hcard : (s.card : ℝ) ≤ Fintype.card α := by - exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) - have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) - linarith - -lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by - simp [Card] - -lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by - rw [Fintype.card_perm, card_positions] - -lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by - rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] - -lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : - law d t g = finiteLaw (run d t) g := by - unfold law finiteLaw - apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) - exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) - -lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by - rw [law_eq_finiteLaw] - exact finiteLaw_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by - simp only [law_eq_finiteLaw] - exact finiteLaw_sum (run d t) - -lemma physical_support_bound_succ (d t : ℕ) : - 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by - have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ - have h := finiteLaw_support_bound (run (d + 1) t) - rw [card_tapes_succ, card_permutations] at h - simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h - -lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : - step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by - change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ - rw [Fin.snoc_eq_cons_rotate] - rfl - -lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by - unfold distance - exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - -lemma physical_support_bound (d t : ℕ) : - 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by - cases d with - | zero => - have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) - simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using - le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) - | succ d => - have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by - push_cast - rw [pow_succ] - ring - rw [he, Real.rpow_natCast] - exact physical_support_bound_succ d t - -lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : - supportTimeBound d ≤ (t : ℤ) := by - have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity - have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity - have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) - have hb := physical_support_bound d t - have hp : (3 / 4 : ℝ) ≤ - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by - linarith - have hr := (le_div_iff₀ hF).mp hp - have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr - rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog - unfold supportTimeBound - apply Int.ceil_le.mpr - simp only [Int.cast_natCast] - calc - 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = - Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by - field_simp - _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by - nlinarith [hlog]) - -lemma supportTimeBound_le_mixingTime {d : ℕ} - (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : - supportTimeBound d ≤ (mixingTime d : ℤ) := by - exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) - -lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : - (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by - have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) - have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) - have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by - have := Real.pi_gt_three - linarith) - linarith - -lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) - have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by - rw [← Real.log_inv] - congr 1 - norm_num - rw [he] at h - linarith - -lemma linear_le_supportTimeBound (d : ℕ) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by - have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) - have hNp : 0 < (2 : ℝ) ^ d := by positivity - have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) - have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - rw [Real.log_mul (by norm_num) (by positivity)] - push_cast at hf - rw [Real.log_pow] at hf - linarith [log_three_quarters_lower] - apply le_trans _ (Int.le_ceil _) - have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) = - (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by - field_simp - ring - rw [hcancel] - linarith - convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 - field_simp - -lemma linear_le_time_of_distance_le (d t : ℕ) - (ht : distance d t ≤ (1 / 4 : ℝ)) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by - have h := supportTimeBound_le_of_distance_le d t ht - have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h - exact (linear_le_supportTimeBound d).trans hr - -lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : - 2 * p * Real.log 2 ≤ Real.binEntropy p := by - have hc := Real.strictConcave_binEntropy.concaveOn.2 - (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show 0 ≤ 1 - 2 * p by linarith) - (show 0 ≤ 2 * p by positivity) - (show (1 - 2 * p) + 2 * p = 1 by ring) - simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, - smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc - -lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : - 2 * min a b * Real.log 2 ≤ - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - wlog hab : a ≤ b generalizing a b - · have hba := this b a hb ha (le_of_not_ge hab) - simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) - rw [min_eq_left hab] - by_cases hz : a = 0 - · subst a - simp - have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) - have hbp : 0 < b := hap.trans_le hab - have hs : 0 < a + b := add_pos hap hbp - have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le - have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) - have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le - have he : (a + b) * Real.binEntropy (a / (a + b)) = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - unfold Real.binEntropy - rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] - simp only [Real.log_inv] - rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), - Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] - field_simp - ring - rw [he] at hc - calc - 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by - field_simp - _ ≤ _ := hc - -noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail - -lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by - classical - unfold childMarks - apply Finset.card_image_iff.mpr - intro x hx y hy hxy - have hx0 := (Finset.mem_filter.mp hx).2 - have hy0 := (Finset.mem_filter.mp hy).2 - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] - -lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : - (childMarks s false).card + (childMarks s true).card = s.card := by - classical - rw [card_childMarks, card_childMarks] - simpa only [Bool.not_eq_false] using - (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) - -noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) : Finset (Card d) := - ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ - ((childMarks s true).image (butterflyPerm d (b.2 true))) - -lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : - (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by - classical - apply le_min - · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) - · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) - -noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ - | 0, _, _ => 0 - | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card - -lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - induction d with - | zero => - simp only [encounters, Nat.cast_zero] - have hs : s.card ≤ 1 := by - simpa [Card] using Finset.card_le_univ s - interval_cases s.card <;> simp - | succ d ih => - have h₀ := ih (b.2 false) (childMarks s false) - have h₁ := ih (b.2 true) (childMarks s true) - have ht : ((topMeetings b s).card : ℝ) ≤ - min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by - exact_mod_cast card_topMeetings_le b s - have he := split_entropy_lower ((childMarks s false).card : ℝ) - ((childMarks s true).card : ℝ) (by positivity) (by positivity) - have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by - exact_mod_cast card_childMarks_add s - rw [hs] at he - have hL : 0 < 2 * Real.log 2 := by positivity - rw [le_div_iff₀ hL] at h₀ h₁ ⊢ - simp only [encounters, Nat.cast_add] - nlinarith [mul_le_mul_of_nonneg_right ht hL.le] - -lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by - by_cases ha : a ∈ s - · rw [ite_eq_left ha] - exact (Finset.mul_prod_erase s f ha).symm - · simp [ha] - -lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) - (a b : α) (hab : a ≠ b) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * - ∏ i ∈ (s.erase a).erase b, f i := by - calc - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := - prod_split_at s f a - _ = _ := by - rw [prod_split_at (s.erase a) f b] - have hm : (b ∈ s.erase a) ↔ b ∈ s := - ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ - simp only [hm, mul_assoc] - -lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ - ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by - by_cases hab : a = b - · subst b - simp only [Equiv.swap_self, Equiv.refl_apply] - have h : (fun i => (p i + p i) / 2) = p := by funext i; ring - rw [h] - linarith - let t := (s.erase a).erase b - have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by - intro i hi - exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) - have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) - rw [prod_split_two s p a b hab, - prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, - prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] - change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + - (if a ∈ s then p (Equiv.swap a b a) else 1) * - (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ - rw [hprod] - change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * - (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * - (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) - rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] - have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) - by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] - · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht - nlinarith - all_goals ring_nf; rfl - -def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := - ∀ s, m s ≤ ∏ i ∈ s, p i - -lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] - {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) - (fun i => (p i + p (Equiv.swap a b i)) / 2) := by - intro s - have h₀ := h s - have h₁ := h (s.image (Equiv.swap a b)) - rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ - exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans - (swap_average_product s p hp a b) - -noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : ℝ := by - classical - exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) - -lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by - classical - unfold inclusionMoment finiteMean - positivity - -lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : - (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by - by_cases h : s ⊆ A - · rw [ite_eq_left h] - exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm - · rw [ite_eq_right h] - obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h - exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm - -lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] - (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = - if s ⊆ A then 1 else 0 := by - classical - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] - -lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : - CylinderBound (inclusionMoment (fun _ : Ω => A)) - (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by - classical - intro s - simp only [inclusionMoment_const, Finset.singleton_subset_iff] - exact (indicator_subset_prod A s).le - -noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] - (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := - fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 - -lemma subset_swap_image_iff {α : Type*} [DecidableEq α] - (A s : Finset α) (a b : α) : - s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by - constructor - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - -lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) (s : Finset α) : - inclusionMoment (fairSetSwap F a b) s = - (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by - classical - simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, - fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, - Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] - rw [div_mul_eq_div_div, add_div] - ring_nf - -lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) - (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : - CylinderBound (inclusionMoment (fairSetSwap F a b)) - (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by - classical - have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b - intro s - simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s - -def SwitchSamples : ℕ → Type - | 0 => Unit - | n + 1 => SwitchSamples n × Bool - -instance (n : ℕ) : Fintype (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Fintype Unit) - | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) - -instance (n : ℕ) : Nonempty (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Nonempty Unit) - | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) - -noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : - (L : List (α × α)) → SwitchSamples L.length → Finset α - | [], _ => A - | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω - -lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) - (L : List (α × α)) : - CylinderBound (inclusionMoment (switchedSet A L)) - (fun i => inclusionMoment (switchedSet A L) {i}) := by - induction L with - | nil => exact cylinder_const A - | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih - -inductive QueryTree (ι : Type*) - | reject : QueryTree ι - | accept : QueryTree ι - | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι - | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι - -namespace QueryTree - -variable {ι : Type*} [DecidableEq ι] - -def queries : QueryTree ι → Finset ι - | reject => ∅ - | accept => ∅ - | branch i zero one => insert i (queries zero ∪ queries one) - | force i _ next => insert i (queries next) - -def Fresh : QueryTree ι → Prop - | reject => True - | accept => True - | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one - | force i _ next => i ∉ queries next ∧ Fresh next - -def weighted : QueryTree ι → (ι → Bool) → ℝ - | reject, _ => 0 - | accept, _ => 1 - | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω - | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 - -omit [DecidableEq ι] in -lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by - induction T with - | reject => exact le_rfl - | accept => exact zero_le_one - | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ - | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl - -lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} - (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by - induction T with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), - ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] - | force i b next ih => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] - -def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := - (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by - intro ω - funext j - by_cases h : j = i - · subst j; simp - · simp [Function.update_of_ne h]).toPerm - -lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by - change Function.update ω i (!(ω i)) i = _ - exact Function.update_self _ _ _ - -lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : - flipCoin i ω j = ω j := by - change Function.update ω i (!(ω i)) j = _ - exact Function.update_of_ne h _ _ - -lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) - (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by - apply weighted_congr - intro j hj - exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω - -lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) - (hf : ∀ ω, f (flipCoin i ω) = f ω) : - finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by - let g := fun ω : ι → Bool => if ω i = b then f ω else 0 - have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by - dsimp [g] - rw [flipCoin_apply_eq, hf] - cases hω : ω i <;> cases b <;> simp - have hs := Equiv.sum_comp (flipCoin i) g - have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun ω _ => hp ω) - unfold finiteMean - change (∑ ω, g ω) / _ = _ - rw [hs] at hadd - have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith - rw [hh] - ring - -lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : - finiteMean T.weighted ≤ 1 := by - induction T with - | reject => simp [weighted, finiteMean] - | accept => simp [weighted, finiteMean] - | branch i zero one ih₀ ih₁ => - obtain ⟨hz, ho, hfz, hfo⟩ := hT - have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) - have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) - have he : finiteMean (branch i zero one).weighted = - finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + - finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by - unfold finiteMean - rw [← add_div, ← Finset.sum_add_distrib] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - cases hω : ω i <;> simp [weighted, hω] - rw [he, h₀, h₁] - linarith [ih₀ hfz, ih₁ hfo] - | force i b next ih => - obtain ⟨hi, hn⟩ := hT - have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) - have he : finiteMean (force i b next).weighted = - 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by - unfold finiteMean - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : ω i = b <;> simp [weighted, h] - rw [he, hm] - linarith [ih hn] - -def succeeds : QueryTree ι → (ι → Bool) → Bool - | reject, _ => false - | accept, _ => true - | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω - | force i b next, ω => if ω i = b then succeeds next ω else false - -def charge : QueryTree ι → (ι → Bool) → ℕ - | reject, _ => 0 - | accept, _ => 0 - | branch i zero one, ω => if ω i then charge one ω else charge zero ω - | force i b next, ω => if ω i = b then charge next ω + 1 else 0 - -omit [DecidableEq ι] in -lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : - T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by - induction T with - | reject => rfl - | accept => norm_num [weighted, succeeds, charge] - | branch i zero one ih₀ ih₁ => - cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] - | force i b next ih => - by_cases h : ω i = b - · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] - cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] - · simp [weighted, succeeds, h] - -lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) - (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : - finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by - have hw (ω : ι → Bool) : - (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by - rw [weighted_eq] - cases hs : T.succeeds ω - · simp - · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) - have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ - have hm := div_le_div_of_nonneg_right - (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn - rw [← Finset.mul_sum, mul_div_assoc] at hm - change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ - finiteMean T.weighted at hm - exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by - rw [mul_comm] - exact hm.trans (mean_weighted_le_one T hT)) - -end QueryTree - -def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool - | 0, _, i => nomatch i - | _d + 1, b, Sum.inl y => b.1 y - | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i - -lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : - decodeButterfly d (encodeButterfly d b) = b := by - induction d with - | zero => exact Unit.ext _ _ - | succ d ih => - apply Prod.ext - · rfl - · funext ε - exact ih (b.2 ε) - -lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : - encodeButterfly d (decodeButterfly d ω) = ω := by - induction d with - | zero => funext i; exact Empty.elim i - | succ d ih => - funext i - cases i with - | inl y => rfl - | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 - -def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where - toFun := decodeButterfly d - invFun := encodeButterfly d - left_inv := encode_decodeButterfly d - right_inv := decode_encodeButterfly d - -noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) - | 0, _, _ => ∅ - | d + 1, x, y => by - classical - exact insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) - -def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool - | 0, _, _, i => nomatch i - | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) - | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i - -lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by - classical - induction d with - | zero => rfl - | succ d ih => - change (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 - rw [Finset.card_insert_of_notMem (by simp)] - rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.Model + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp + +open scoped BigOperators +open Filter + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Card d → Bool + +instance (d : ℕ) : Fintype (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +instance (d : ℕ) : Nonempty (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +def rotate (d : ℕ) : Equiv.Perm (Card d) where + toFun x i := x (finRotate d i) + invFun x i := x ((finRotate d).symm i) + left_inv x := by funext i; simp only [Equiv.apply_symm_apply] + right_inv x := by funext i; simp only [Equiv.symm_apply_apply] + +def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, ξ => rotate (d + 1) * pairSwitch ξ + +def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) + | 0, _ => 1 + | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) + +noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := + (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / + (Fintype.card (Fin t → Coins d) : ℝ) + +noncomputable def distance (d t : ℕ) : ℝ := + (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| + +noncomputable def mixingTime (d : ℕ) : ℕ := + sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} + +noncomputable def supportTimeBound (d : ℕ) : ℤ := + ⌈(2 / (2 : ℝ) ^ d) * + (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ + +def OptimalOrder : Prop := + ∃ C : ℕ, 0 < C ∧ + Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ + (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ + (∀ᶠ d : ℕ in atTop, + supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ + (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) + +noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by + classical + exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) + +lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : + ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by + classical + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : + 0 ≤ finiteLaw f b := by + exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : + ∑ b, finiteLaw f b = 1 := by + classical + simp only [finiteLaw, ← Finset.sum_div] + have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by + exact_mod_cast sum_card_fibers f + rw [hc] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by + classical + have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr + ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ + simp [finiteLaw] + +lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] + (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : + (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by + have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := + Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) + have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) + have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) + have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) + rw [hpq] at hz + rw [← Finset.sum_sub_distrib] + linarith + +lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] + [Fintype β] [Nonempty β] (f : α → β) : + 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ + (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by + classical + let s := Finset.univ.image f + have hs : ∑ b ∈ s, finiteLaw f b = 1 := by + have h := Finset.sum_subset (Finset.subset_univ s) + (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) + simpa only [finiteLaw_sum] using h + have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] + have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by + rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] + have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s + rw [hs] at he + have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by + simp [div_eq_mul_inv] + rw [hsq] at he + have hcard : (s.card : ℝ) ≤ Fintype.card α := by + exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) + have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) + linarith + +lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by + simp [Card] + +lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by + rw [Fintype.card_perm, card_positions] + +lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by + rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] + +lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : + law d t g = finiteLaw (run d t) g := by + unfold law finiteLaw + apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) + exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) + +lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by + rw [law_eq_finiteLaw] + exact finiteLaw_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by + simp only [law_eq_finiteLaw] + exact finiteLaw_sum (run d t) + +lemma physical_support_bound_succ (d t : ℕ) : + 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by + have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ + have h := finiteLaw_support_bound (run (d + 1) t) + rw [card_tapes_succ, card_permutations] at h + simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h + +lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : + step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by + change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ + rw [Fin.snoc_eq_cons_rotate] + rfl + +lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by + unfold distance + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + +lemma physical_support_bound (d t : ℕ) : + 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by + cases d with + | zero => + have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) + simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using + le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) + | succ d => + have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by + push_cast + rw [pow_succ] + ring + rw [he, Real.rpow_natCast] + exact physical_support_bound_succ d t + +lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : + supportTimeBound d ≤ (t : ℤ) := by + have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity + have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hb := physical_support_bound d t + have hp : (3 / 4 : ℝ) ≤ + (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by + linarith + have hr := (le_div_iff₀ hF).mp hp + have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr + rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog + unfold supportTimeBound + apply Int.ceil_le.mpr + simp only [Int.cast_natCast] + calc + 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = + Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by + field_simp + _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by + nlinarith [hlog]) + +lemma supportTimeBound_le_mixingTime {d : ℕ} + (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : + supportTimeBound d ≤ (mixingTime d : ℤ) := by + exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) + +lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : + (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by + have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) + have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) + have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by + have := Real.pi_gt_three + linarith) + linarith + +lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) + have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by + rw [← Real.log_inv] + congr 1 + norm_num + rw [he] at h + linarith + +lemma linear_le_supportTimeBound (d : ℕ) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by + have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) + have hNp : 0 < (2 : ℝ) ^ d := by positivity + have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) + have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + rw [Real.log_mul (by norm_num) (by positivity)] + push_cast at hf + rw [Real.log_pow] at hf + linarith [log_three_quarters_lower] + apply le_trans _ (Int.le_ceil _) + have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) = + (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by + field_simp + ring + rw [hcancel] + linarith + convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 + field_simp + +lemma linear_le_time_of_distance_le (d t : ℕ) + (ht : distance d t ≤ (1 / 4 : ℝ)) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by + have h := supportTimeBound_le_of_distance_le d t ht + have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h + exact (linear_le_supportTimeBound d).trans hr + +lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc := Real.strictConcave_binEntropy.concaveOn.2 + (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show 0 ≤ 1 - 2 * p by linarith) + (show 0 ≤ 2 * p by positivity) + (show (1 - 2 * p) + 2 * p = 1 by ring) + simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, + smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc + +lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + wlog hab : a ≤ b generalizing a b + · have hba := this b a hb ha (le_of_not_ge hab) + simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) + rw [min_eq_left hab] + by_cases hz : a = 0 + · subst a + simp + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) + have hbp : 0 < b := hap.trans_le hab + have hs : 0 < a + b := add_pos hap hbp + have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le + have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) + have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le + have he : (a + b) * Real.binEntropy (a / (a + b)) = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + unfold Real.binEntropy + rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] + simp only [Real.log_inv] + rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), + Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] + field_simp + ring + rw [he] at hc + calc + 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by + field_simp + _ ≤ _ := hc + +noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail + +lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by + classical + unfold childMarks + apply Finset.card_image_iff.mpr + intro x hx y hy hxy + have hx0 := (Finset.mem_filter.mp hx).2 + have hy0 := (Finset.mem_filter.mp hy).2 + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] + +lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : + (childMarks s false).card + (childMarks s true).card = s.card := by + classical + rw [card_childMarks, card_childMarks] + simpa only [Bool.not_eq_false] using + (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) + +noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) : Finset (Card d) := + ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ + ((childMarks s true).image (butterflyPerm d (b.2 true))) + +lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : + (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by + classical + apply le_min + · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) + · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) + +noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ + | 0, _, _ => 0 + | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card + +lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + induction d with + | zero => + simp only [encounters, Nat.cast_zero] + have hs : s.card ≤ 1 := by + simpa [Card] using Finset.card_le_univ s + interval_cases s.card <;> simp + | succ d ih => + have h₀ := ih (b.2 false) (childMarks s false) + have h₁ := ih (b.2 true) (childMarks s true) + have ht : ((topMeetings b s).card : ℝ) ≤ + min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by + exact_mod_cast card_topMeetings_le b s + have he := split_entropy_lower ((childMarks s false).card : ℝ) + ((childMarks s true).card : ℝ) (by positivity) (by positivity) + have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by + exact_mod_cast card_childMarks_add s + rw [hs] at he + have hL : 0 < 2 * Real.log 2 := by positivity + rw [le_div_iff₀ hL] at h₀ h₁ ⊢ + simp only [encounters, Nat.cast_add] + nlinarith [mul_le_mul_of_nonneg_right ht hL.le] + +lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by + by_cases ha : a ∈ s + · rw [ite_eq_left ha] + exact (Finset.mul_prod_erase s f ha).symm + · simp [ha] + +lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) + (a b : α) (hab : a ≠ b) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * + ∏ i ∈ (s.erase a).erase b, f i := by + calc + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := + prod_split_at s f a + _ = _ := by + rw [prod_split_at (s.erase a) f b] + have hm : (b ∈ s.erase a) ↔ b ∈ s := + ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ + simp only [hm, mul_assoc] + +lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ + ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by + by_cases hab : a = b + · subst b + simp only [Equiv.swap_self, Equiv.refl_apply] + have h : (fun i => (p i + p i) / 2) = p := by funext i; ring + rw [h] + linarith + let t := (s.erase a).erase b + have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by + intro i hi + exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) + have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) + rw [prod_split_two s p a b hab, + prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, + prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] + change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + + (if a ∈ s then p (Equiv.swap a b a) else 1) * + (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ + rw [hprod] + change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * + (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * + (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) + rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] + have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) + by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] + · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht + nlinarith + all_goals ring_nf; rfl + +def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := + ∀ s, m s ≤ ∏ i ∈ s, p i + +lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] + {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) + (fun i => (p i + p (Equiv.swap a b i)) / 2) := by + intro s + have h₀ := h s + have h₁ := h (s.image (Equiv.swap a b)) + rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ + exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans + (swap_average_product s p hp a b) + +noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : ℝ := by + classical + exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) + +lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by + classical + unfold inclusionMoment finiteMean + positivity + +lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : + (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by + by_cases h : s ⊆ A + · rw [ite_eq_left h] + exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm + · rw [ite_eq_right h] + obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h + exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm + +lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] + (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = + if s ⊆ A then 1 else 0 := by + classical + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] + +lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : + CylinderBound (inclusionMoment (fun _ : Ω => A)) + (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by + classical + intro s + simp only [inclusionMoment_const, Finset.singleton_subset_iff] + exact (indicator_subset_prod A s).le + +noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] + (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := + fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 + +lemma subset_swap_image_iff {α : Type*} [DecidableEq α] + (A s : Finset α) (a b : α) : + s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by + constructor + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + +lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) (s : Finset α) : + inclusionMoment (fairSetSwap F a b) s = + (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by + classical + simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, + fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, + Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] + rw [div_mul_eq_div_div, add_div] + ring_nf + +lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) + (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : + CylinderBound (inclusionMoment (fairSetSwap F a b)) + (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by + classical + have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b + intro s + simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s + +def SwitchSamples : ℕ → Type + | 0 => Unit + | n + 1 => SwitchSamples n × Bool + +instance (n : ℕ) : Fintype (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Fintype Unit) + | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) + +instance (n : ℕ) : Nonempty (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) + +noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : + (L : List (α × α)) → SwitchSamples L.length → Finset α + | [], _ => A + | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω + +lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) + (L : List (α × α)) : + CylinderBound (inclusionMoment (switchedSet A L)) + (fun i => inclusionMoment (switchedSet A L) {i}) := by + induction L with + | nil => exact cylinder_const A + | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih + +inductive QueryTree (ι : Type*) + | reject : QueryTree ι + | accept : QueryTree ι + | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι + | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι + +namespace QueryTree + +variable {ι : Type*} [DecidableEq ι] + +def queries : QueryTree ι → Finset ι + | reject => ∅ + | accept => ∅ + | branch i zero one => insert i (queries zero ∪ queries one) + | force i _ next => insert i (queries next) + +def Fresh : QueryTree ι → Prop + | reject => True + | accept => True + | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one + | force i _ next => i ∉ queries next ∧ Fresh next + +def weighted : QueryTree ι → (ι → Bool) → ℝ + | reject, _ => 0 + | accept, _ => 1 + | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω + | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 + +omit [DecidableEq ι] in +lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by + induction T with + | reject => exact le_rfl + | accept => exact zero_le_one + | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ + | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl + +lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} + (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by + induction T with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), + ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] + | force i b next ih => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] + +def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := + (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by + intro ω + funext j + by_cases h : j = i + · subst j; simp + · simp [Function.update_of_ne h]).toPerm + +lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by + change Function.update ω i (!(ω i)) i = _ + exact Function.update_self _ _ _ + +lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : + flipCoin i ω j = ω j := by + change Function.update ω i (!(ω i)) j = _ + exact Function.update_of_ne h _ _ + +lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) + (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by + apply weighted_congr + intro j hj + exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω + +lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) + (hf : ∀ ω, f (flipCoin i ω) = f ω) : + finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by + let g := fun ω : ι → Bool => if ω i = b then f ω else 0 + have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by + dsimp [g] + rw [flipCoin_apply_eq, hf] + cases hω : ω i <;> cases b <;> simp + have hs := Equiv.sum_comp (flipCoin i) g + have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun ω _ => hp ω) + unfold finiteMean + change (∑ ω, g ω) / _ = _ + rw [hs] at hadd + have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith + rw [hh] + ring + +lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : + finiteMean T.weighted ≤ 1 := by + induction T with + | reject => simp [weighted, finiteMean] + | accept => simp [weighted, finiteMean] + | branch i zero one ih₀ ih₁ => + obtain ⟨hz, ho, hfz, hfo⟩ := hT + have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) + have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) + have he : finiteMean (branch i zero one).weighted = + finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + + finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by + unfold finiteMean + rw [← add_div, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + cases hω : ω i <;> simp [weighted, hω] + rw [he, h₀, h₁] + linarith [ih₀ hfz, ih₁ hfo] + | force i b next ih => + obtain ⟨hi, hn⟩ := hT + have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) + have he : finiteMean (force i b next).weighted = + 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by + unfold finiteMean + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : ω i = b <;> simp [weighted, h] + rw [he, hm] + linarith [ih hn] + +def succeeds : QueryTree ι → (ι → Bool) → Bool + | reject, _ => false + | accept, _ => true + | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω + | force i b next, ω => if ω i = b then succeeds next ω else false + +def charge : QueryTree ι → (ι → Bool) → ℕ + | reject, _ => 0 + | accept, _ => 0 + | branch i zero one, ω => if ω i then charge one ω else charge zero ω + | force i b next, ω => if ω i = b then charge next ω + 1 else 0 + +omit [DecidableEq ι] in +lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : + T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by + induction T with + | reject => rfl + | accept => norm_num [weighted, succeeds, charge] + | branch i zero one ih₀ ih₁ => + cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] + | force i b next ih => + by_cases h : ω i = b + · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] + cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] + · simp [weighted, succeeds, h] + +lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) + (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : + finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by + have hw (ω : ι → Bool) : + (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by + rw [weighted_eq] + cases hs : T.succeeds ω + · simp + · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) + have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ + have hm := div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn + rw [← Finset.mul_sum, mul_div_assoc] at hm + change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ + finiteMean T.weighted at hm + exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by + rw [mul_comm] + exact hm.trans (mean_weighted_le_one T hT)) + +end QueryTree + +def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool + | 0, _, i => nomatch i + | _d + 1, b, Sum.inl y => b.1 y + | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i + +lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : + decodeButterfly d (encodeButterfly d b) = b := by + induction d with + | zero => exact Unit.ext _ _ + | succ d ih => + apply Prod.ext + · rfl + · funext ε + exact ih (b.2 ε) + +lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : + encodeButterfly d (decodeButterfly d ω) = ω := by + induction d with + | zero => funext i; exact Empty.elim i + | succ d ih => + funext i + cases i with + | inl y => rfl + | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 + +def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where + toFun := decodeButterfly d + invFun := encodeButterfly d + left_inv := encode_decodeButterfly d + right_inv := decode_encodeButterfly d + +noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) + | 0, _, _ => ∅ + | d + 1, x, y => by + classical + exact insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) + +def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool + | 0, _, _, i => nomatch i + | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) + | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i + +lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by + classical + induction d with + | zero => rfl + | succ d ih => + change (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 + rw [Finset.card_insert_of_notMem (by simp)] + rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/ExposedCoins.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/ExposedCoins.lean index 18af04399089ab4737630dd6cfd9095b66700f0f..3571af9b45fee74cc18105a5f7ece56649a8c70a 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/ExposedCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/ExposedCoins.lean @@ -1,856 +1,856 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.Coins - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter - -lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by - cases a <;> cases b <;> cases c <;> decide - -lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : - butterflyPerm d (decodeButterfly d ω) x = y ↔ - ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by - classical - induction d with - | zero => - have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ - simp [he, routeDomain] - | succ d ih => - let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) - change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ - have hv : v = Fin.tail y ↔ - ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), - ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := - ih _ _ _ - constructor - · intro h i hi - have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h - have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by - have he := congrFun h 0 - simp only [Fin.cons_zero, ht] at he - exact (xor_eq_iff _ _ _).mp he - rcases Finset.mem_insert.mp hi with htop | hchild - · subst i - exact hh - · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild - exact hv.mp ht j hj - · intro h - have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) - have ht : v = Fin.tail y := hv.mpr (fun i hi => - h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) - have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := - (xor_eq_iff _ _ _).mpr hh - rw [ht, hh', Fin.cons_self_tail] - -lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by - unfold finiteMean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) : - finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = - 1 / (2 : ℝ) ^ s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 - have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - dsimp [f] - simp only [he] - have hm := QueryTree.mean_indicator_bit f i (v i) hf - have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = - (fun ω => if ω i = v i then f ω else 0) := by - funext ω - by_cases h : ω i = v i <;> simp [f, h] - rw [he, hm] - change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ - rw [ih, Finset.card_insert_of_notMem hi, pow_succ] - ring - -def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := - fun i => if i ∈ R then η i else ω i - -lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] - (s R : Finset ι) (v η : ι → Bool) : - finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by - have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ - (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by - constructor - · intro h - constructor - · intro i hi - simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 - · intro i hi - simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 - · rintro ⟨ho, hf⟩ i hi - by_cases hR : i ∈ R - · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) - · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) - have hm : finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - finiteMean (fun ω : ι → Bool => - if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [he ω]) - rw [hm] - by_cases h : ∀ i ∈ s ∩ R, η i = v i - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h - simp only [hp, true_and, ↓reduceIte] - exact mean_coinCylinder (s \ R) v - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h - simp only [hp, false_and, ↓reduceIte] - simp [finiteMean] - -lemma butterfly_closure_probability (d : ℕ) (x y : Card d) - (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then - (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder_exposed] - congr 1 - have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter, card_routeDomain] - have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * - (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by - rw [← pow_add] - exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm - rw [hp] - have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) - field_simp - -lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder, card_routeDomain] - -def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d - | 0, _, i => nomatch i - | d + 1, b, Sum.inl y => - (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), - Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) - | d + 1, b, Sum.inr (ε,i) => - (Fin.cons ε (switchUsers d (b.2 ε) i).1, - Fin.cons ε (switchUsers d (b.2 ε) i).2) - -lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : - (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - intro h - have := congrFun h 0 - simp only [switchUsers, Fin.cons_zero] at this - exact Bool.false_ne_true this - | inr z => - intro h - exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) - -lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : - Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by - constructor - · intro h - exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, - by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ - · rintro ⟨rfl,rfl⟩ - exact Fin.cons_self_tail x - -lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : - i ∈ routeDomain d x (butterflyPerm d b x) ↔ - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by - classical - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, - Sum.inr_ne_inl, and_false, exists_false, or_false] - change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ - simp only [switchUsers, cons_eq_iff] - cases x 0 <;> simp [Equiv.symm_apply_eq] - | inr z => - obtain ⟨ε,i⟩ := z - change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, - Sum.inr.injEq, Prod.mk.injEq] - change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ - x 0 = ε ∧ j = i) ↔ _ - simp only [switchUsers, cons_eq_iff] - constructor - · rintro ⟨j,hj,hε,rfl⟩ - subst ε - rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h - · exact Or.inl ⟨rfl,h⟩ - · exact Or.inr ⟨rfl,h⟩ - · rintro (⟨hε,h⟩ | ⟨hε,h⟩) - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ - -lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : - (Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - routeDomain d x (butterflyPerm d b x) := by - ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] - rw [he,card_routeDomain] - -lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = - (d : ℝ) * ∑ x : Card d, w x := by - classical - calc - _ = ∑ i : SwitchIndex d, ∑ x : Card d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : Card d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - {(switchUsers d b i).1, (switchUsers d b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (switchUsers_ne d b i)] - _ = ∑ x : Card d, ∑ i : SwitchIndex d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : Card d, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ - (d : ℝ) / 2 * ∑ x : Card d, w x := by - have h : 2 * (∑ i : SwitchIndex d, - min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), - min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] - rw [switch_incidence_sum] at h - linarith - -lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : - x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by - classical - constructor - · intro h - obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy - rw [← hxy, ← hyε, Fin.cons_self_tail] - exact hys - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons ε x, - Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ - -lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) (y : Card d) : - y ∈ topMeetings b s ↔ - (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by - classical - have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ - (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by - constructor - · intro h - obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h - simpa only [Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ - simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] - -lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - encounters d b s = ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by - classical - induction d with - | zero => - simp only [encounters] - symm - apply Finset.sum_eq_zero - intro i _ - exact Empty.elim i - | succ d ih => - change encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = - ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ - rw [Fintype.sum_sum_type, Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [ih,ih] - have ht : (∑ y : Card d, - if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = - (topMeetings b s).card := by - simp only [← mem_topMeetings] - simp - rw [ht] - simp only [mem_childMarks, switchUsers] - ac_rfl - -lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ - (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - classical - have he : (encounters d b s : ℝ) = - ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by - rw [encounters_eq_switch_sum, Nat.cast_sum] - apply Finset.sum_congr rfl - intro i _ - split_ifs <;> simp - rw [← he] - exact butterfly_encounters d b s - -namespace QueryTree -variable {ι : Type*} [DecidableEq ι] - -def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι - | reject, _, _ => reject - | accept, _, _ => accept - | branch i zero one, R, η => - if i ∈ R then (if η i then memo one R η else memo zero R η) else - branch i (memo zero (insert i R) (Function.update η i false)) - (memo one (insert i R) (Function.update η i true)) - | force i b next, R, η => - if i ∈ R then (if η i = b then memo next R η else reject) else - force i b (memo next (insert i R) (Function.update η i b)) - -lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - Disjoint (memo T R η).queries R := by - induction T generalizing R η with - | reject => simp [memo,queries] - | accept => simp [memo,queries] - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] - exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), - (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,queries] - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] - exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - -lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - (memo T R η).Fresh := by - induction T generalizing R η with - | reject => trivial - | accept => trivial - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm - (Finset.mem_insert_self _ _), - fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm - (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,Fresh] - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm - (Finset.mem_insert_self _ _),ih _ _⟩ - -lemma update_agrees {R : Finset ι} {η ω : ι → Bool} - (h : ∀ i ∈ R, η i = ω i) (i : ι) : - ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by - intro j hj - rcases Finset.mem_insert.mp hj with rfl | hj - · simp - · by_cases hji : j = i - · subst j; simp - · rw [Function.update_of_ne hji] - exact h j hj - -lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,succeeds,h i hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,succeeds] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte,succeeds] - exact ih R η h - · simp [hb,succeeds] - · simp only [memo,hi,↓reduceIte,succeeds] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih _ _ (by simpa only [hb] using update_agrees h i) - · simp [hb] - -def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 - -lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih R η h - · simp [hb,charge] - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - rw [ih _ _ (by simpa only [hb] using update_agrees h i)] - · simp [hb] - -lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by - let η : ι → Bool := fun _ => false - have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) - have he : finiteMean (memo T ∅ η).weighted = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] - rw [he] at hm - exact hm - - -def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → - (Card d → QueryTree ι) → QueryTree ι - | 0, _, x, k => k x - | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) - (fun y => branch (e (Sum.inl y)) - (k (Fin.cons (Bool.xor (x 0) false) y)) - (k (Fin.cons (Bool.xor (x 0) true) y))) - -omit [DecidableEq ι] in -lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).succeeds ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω - cases ω (e (Sum.inl y)) <;> rfl - -lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - freshCharge (followPath d e x k) R ω = - freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - classical - induction d generalizing R with - | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) - change (if ω (e (Sum.inl y)) then - freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else - freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = - freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) - (R ∪ (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω - have hs : (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = - insert (e (Sum.inl y)) S := by - let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e - change (insert (Sum.inl y) - ((routeDomain d (Fin.tail x) y).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ - rw [Finset.image_insert, Finset.image_image] - rfl - rw [hs,Finset.union_insert] - cases ω (e (Sum.inl y)) <;> rfl - -def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι - | [], _, k => k - | i :: L, v, k => force i (v i) (forceList L v k) - -omit [DecidableEq ι] in -lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : - (forceList L v k).succeeds ω = - if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by - induction L with - | nil => simp [forceList] - | cons i L ih => - simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] - by_cases h : ω i = v i <;> simp [h] - -lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) - (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : - freshCharge (forceList L v k) R ω = - freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by - induction L generalizing R with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), - ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.toFinset_cons] - have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp - rw [hs] - by_cases hi : i ∈ R - · rw [ite_eq_left hi] - have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he,Nat.add_zero] - · rw [ite_eq_right hi] - have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he, Finset.card_insert_of_notMem (by simp)] - omega - - -def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω - else staleCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 - -lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by - induction T generalizing R with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] - | force i b next ih => - by_cases hb : ω i = b - · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] - have he := ih (insert i R) - by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega - · simp [freshCharge,staleCharge,charge,hb] - -omit [DecidableEq ι] in -lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).charge ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω - cases ω (e (Sum.inl y)) <;> rfl - -omit [DecidableEq ι] in -lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) - (h : ∀ i ∈ L, ω i = v i) : - (forceList L v k).charge ω = k.charge ω + L.length := by - induction L with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), - ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.length_cons,Nat.add_assoc] - -noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : - QueryTree (SwitchIndex d) := - forceList (routeDomain d x y).toList (routeValue d x y) k - -lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) : - (closePath d x y k).succeeds ω = - if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by - unfold closePath - rw [forceList_succeeds] - simp only [Finset.mem_toList, ← butterfly_endpoint_iff] - -lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).charge ω = k.charge ω + d := by - unfold closePath - rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] - -lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).freshCharge R ω = - k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by - unfold closePath - rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] - -lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).staleCharge R ω = - k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by - have h₀ := fresh_add_stale (closePath d x y k) R ω - have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω - rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ - have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_routeDomain] - omega - -noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : - ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → - QueryTree (SwitchIndex d) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x - (fun y => seekCycle d S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle d S a r x V k).succeeds ω = true) : - (seekCycle d S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs - rw [seekCycle,ite_eq_left hv,followPath_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,succeeds] at hs - -noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : - List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) - | [], _ => accept - | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) - -lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) - (V : Finset (Card d)) (ω : SwitchIndex d → Bool) - (hs : (seekCycles d S L V).succeeds ω = true) : - (seekCycles d S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : - finiteMean (fun ω : SwitchIndex d → Bool => - if (seekCycles d S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles d S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge d S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree - -lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by - simp only [finiteMean,Finset.sum_add_distrib,add_div] - -lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : - finiteMean (fun ω => f ω * c) = finiteMean f * c := by - unfold finiteMean - rw [← Finset.sum_mul] - ring - -lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : - finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by - simp only [finiteMean,Finset.sum_div] - exact Finset.sum_comm - -lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω → ℝ) : - finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by - unfold finiteMean - rw [Fintype.card_congr e] - congr 1 - exact Fintype.sum_equiv e _ _ (fun ω => by simp) - -lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] - (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by - simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, - ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] - have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - field_simp - -lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] - {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] - (c : C) (g : A c → ℝ) : - finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by - rw [finiteMean_equiv (Equiv.piSplitAt c A)] - have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => - g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by - funext z - simp [Equiv.piSplitAt] - rw [he,finiteMean_prod_left] - -lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : - finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by - simp [finiteMean] - -lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] - have hj := convexOn_exp.map_sum_le (t := Finset.univ) - (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) - (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) - simp only [smul_eq_mul, ← Finset.mul_sum] at hj - simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj - -variable {d A : ℕ} - -def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} - -noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) - (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.Coins + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter + +lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by + cases a <;> cases b <;> cases c <;> decide + +lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : + butterflyPerm d (decodeButterfly d ω) x = y ↔ + ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by + classical + induction d with + | zero => + have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ + simp [he, routeDomain] + | succ d ih => + let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) + change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ + have hv : v = Fin.tail y ↔ + ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), + ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := + ih _ _ _ + constructor + · intro h i hi + have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h + have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by + have he := congrFun h 0 + simp only [Fin.cons_zero, ht] at he + exact (xor_eq_iff _ _ _).mp he + rcases Finset.mem_insert.mp hi with htop | hchild + · subst i + exact hh + · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild + exact hv.mp ht j hj + · intro h + have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) + have ht : v = Fin.tail y := hv.mpr (fun i hi => + h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) + have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := + (xor_eq_iff _ _ _).mpr hh + rw [ht, hh', Fin.cons_self_tail] + +lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by + unfold finiteMean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) : + finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = + 1 / (2 : ℝ) ^ s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 + have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + dsimp [f] + simp only [he] + have hm := QueryTree.mean_indicator_bit f i (v i) hf + have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = + (fun ω => if ω i = v i then f ω else 0) := by + funext ω + by_cases h : ω i = v i <;> simp [f, h] + rw [he, hm] + change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ + rw [ih, Finset.card_insert_of_notMem hi, pow_succ] + ring + +def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := + fun i => if i ∈ R then η i else ω i + +lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] + (s R : Finset ι) (v η : ι → Bool) : + finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by + have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ + (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by + constructor + · intro h + constructor + · intro i hi + simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 + · intro i hi + simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 + · rintro ⟨ho, hf⟩ i hi + by_cases hR : i ∈ R + · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) + · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) + have hm : finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + finiteMean (fun ω : ι → Bool => + if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [he ω]) + rw [hm] + by_cases h : ∀ i ∈ s ∩ R, η i = v i + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h + simp only [hp, true_and, ↓reduceIte] + exact mean_coinCylinder (s \ R) v + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h + simp only [hp, false_and, ↓reduceIte] + simp [finiteMean] + +lemma butterfly_closure_probability (d : ℕ) (x y : Card d) + (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then + (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder_exposed] + congr 1 + have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter, card_routeDomain] + have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * + (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by + rw [← pow_add] + exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm + rw [hp] + have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) + field_simp + +lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder, card_routeDomain] + +def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d + | 0, _, i => nomatch i + | d + 1, b, Sum.inl y => + (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), + Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) + | d + 1, b, Sum.inr (ε,i) => + (Fin.cons ε (switchUsers d (b.2 ε) i).1, + Fin.cons ε (switchUsers d (b.2 ε) i).2) + +lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : + (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + intro h + have := congrFun h 0 + simp only [switchUsers, Fin.cons_zero] at this + exact Bool.false_ne_true this + | inr z => + intro h + exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) + +lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : + Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by + constructor + · intro h + exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, + by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ + · rintro ⟨rfl,rfl⟩ + exact Fin.cons_self_tail x + +lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : + i ∈ routeDomain d x (butterflyPerm d b x) ↔ + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by + classical + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, + Sum.inr_ne_inl, and_false, exists_false, or_false] + change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ + simp only [switchUsers, cons_eq_iff] + cases x 0 <;> simp [Equiv.symm_apply_eq] + | inr z => + obtain ⟨ε,i⟩ := z + change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, + Sum.inr.injEq, Prod.mk.injEq] + change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ + x 0 = ε ∧ j = i) ↔ _ + simp only [switchUsers, cons_eq_iff] + constructor + · rintro ⟨j,hj,hε,rfl⟩ + subst ε + rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h + · exact Or.inl ⟨rfl,h⟩ + · exact Or.inr ⟨rfl,h⟩ + · rintro (⟨hε,h⟩ | ⟨hε,h⟩) + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ + +lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : + (Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + routeDomain d x (butterflyPerm d b x) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] + rw [he,card_routeDomain] + +lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = + (d : ℝ) * ∑ x : Card d, w x := by + classical + calc + _ = ∑ i : SwitchIndex d, ∑ x : Card d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : Card d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + {(switchUsers d b i).1, (switchUsers d b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (switchUsers_ne d b i)] + _ = ∑ x : Card d, ∑ i : SwitchIndex d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : Card d, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ + (d : ℝ) / 2 * ∑ x : Card d, w x := by + have h : 2 * (∑ i : SwitchIndex d, + min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), + min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] + rw [switch_incidence_sum] at h + linarith + +lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : + x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by + classical + constructor + · intro h + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy + rw [← hxy, ← hyε, Fin.cons_self_tail] + exact hys + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons ε x, + Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ + +lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) (y : Card d) : + y ∈ topMeetings b s ↔ + (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by + classical + have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ + (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by + constructor + · intro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + simpa only [Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ + simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] + +lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + encounters d b s = ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by + classical + induction d with + | zero => + simp only [encounters] + symm + apply Finset.sum_eq_zero + intro i _ + exact Empty.elim i + | succ d ih => + change encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = + ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ + rw [Fintype.sum_sum_type, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [ih,ih] + have ht : (∑ y : Card d, + if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = + (topMeetings b s).card := by + simp only [← mem_topMeetings] + simp + rw [ht] + simp only [mem_childMarks, switchUsers] + ac_rfl + +lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ + (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + classical + have he : (encounters d b s : ℝ) = + ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by + rw [encounters_eq_switch_sum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + rw [← he] + exact butterfly_encounters d b s + +namespace QueryTree +variable {ι : Type*} [DecidableEq ι] + +def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι + | reject, _, _ => reject + | accept, _, _ => accept + | branch i zero one, R, η => + if i ∈ R then (if η i then memo one R η else memo zero R η) else + branch i (memo zero (insert i R) (Function.update η i false)) + (memo one (insert i R) (Function.update η i true)) + | force i b next, R, η => + if i ∈ R then (if η i = b then memo next R η else reject) else + force i b (memo next (insert i R) (Function.update η i b)) + +lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + Disjoint (memo T R η).queries R := by + induction T generalizing R η with + | reject => simp [memo,queries] + | accept => simp [memo,queries] + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] + exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), + (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,queries] + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] + exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + +lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + (memo T R η).Fresh := by + induction T generalizing R η with + | reject => trivial + | accept => trivial + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm + (Finset.mem_insert_self _ _), + fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm + (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,Fresh] + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm + (Finset.mem_insert_self _ _),ih _ _⟩ + +lemma update_agrees {R : Finset ι} {η ω : ι → Bool} + (h : ∀ i ∈ R, η i = ω i) (i : ι) : + ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by + intro j hj + rcases Finset.mem_insert.mp hj with rfl | hj + · simp + · by_cases hji : j = i + · subst j; simp + · rw [Function.update_of_ne hji] + exact h j hj + +lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,succeeds,h i hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,succeeds] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte,succeeds] + exact ih R η h + · simp [hb,succeeds] + · simp only [memo,hi,↓reduceIte,succeeds] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih _ _ (by simpa only [hb] using update_agrees h i) + · simp [hb] + +def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 + +lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih R η h + · simp [hb,charge] + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + rw [ih _ _ (by simpa only [hb] using update_agrees h i)] + · simp [hb] + +lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by + let η : ι → Bool := fun _ => false + have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) + have he : finiteMean (memo T ∅ η).weighted = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] + rw [he] at hm + exact hm + + +def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → + (Card d → QueryTree ι) → QueryTree ι + | 0, _, x, k => k x + | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) + (fun y => branch (e (Sum.inl y)) + (k (Fin.cons (Bool.xor (x 0) false) y)) + (k (Fin.cons (Bool.xor (x 0) true) y))) + +omit [DecidableEq ι] in +lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).succeeds ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω + cases ω (e (Sum.inl y)) <;> rfl + +lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + freshCharge (followPath d e x k) R ω = + freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + classical + induction d generalizing R with + | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) + change (if ω (e (Sum.inl y)) then + freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else + freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = + freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) + (R ∪ (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω + have hs : (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = + insert (e (Sum.inl y)) S := by + let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e + change (insert (Sum.inl y) + ((routeDomain d (Fin.tail x) y).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ + rw [Finset.image_insert, Finset.image_image] + rfl + rw [hs,Finset.union_insert] + cases ω (e (Sum.inl y)) <;> rfl + +def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι + | [], _, k => k + | i :: L, v, k => force i (v i) (forceList L v k) + +omit [DecidableEq ι] in +lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : + (forceList L v k).succeeds ω = + if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by + induction L with + | nil => simp [forceList] + | cons i L ih => + simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] + by_cases h : ω i = v i <;> simp [h] + +lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) + (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : + freshCharge (forceList L v k) R ω = + freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by + induction L generalizing R with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), + ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.toFinset_cons] + have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp + rw [hs] + by_cases hi : i ∈ R + · rw [ite_eq_left hi] + have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he,Nat.add_zero] + · rw [ite_eq_right hi] + have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he, Finset.card_insert_of_notMem (by simp)] + omega + + +def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω + else staleCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 + +lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by + induction T generalizing R with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] + | force i b next ih => + by_cases hb : ω i = b + · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] + have he := ih (insert i R) + by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega + · simp [freshCharge,staleCharge,charge,hb] + +omit [DecidableEq ι] in +lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).charge ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω + cases ω (e (Sum.inl y)) <;> rfl + +omit [DecidableEq ι] in +lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) + (h : ∀ i ∈ L, ω i = v i) : + (forceList L v k).charge ω = k.charge ω + L.length := by + induction L with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), + ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.length_cons,Nat.add_assoc] + +noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : + QueryTree (SwitchIndex d) := + forceList (routeDomain d x y).toList (routeValue d x y) k + +lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) : + (closePath d x y k).succeeds ω = + if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by + unfold closePath + rw [forceList_succeeds] + simp only [Finset.mem_toList, ← butterfly_endpoint_iff] + +lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).charge ω = k.charge ω + d := by + unfold closePath + rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] + +lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).freshCharge R ω = + k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by + unfold closePath + rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] + +lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).staleCharge R ω = + k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by + have h₀ := fresh_add_stale (closePath d x y k) R ω + have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω + rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ + have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_routeDomain] + omega + +noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : + ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → + QueryTree (SwitchIndex d) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x + (fun y => seekCycle d S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle d S a r x V k).succeeds ω = true) : + (seekCycle d S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs + rw [seekCycle,ite_eq_left hv,followPath_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,succeeds] at hs + +noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : + List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) + | [], _ => accept + | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) + +lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) + (V : Finset (Card d)) (ω : SwitchIndex d → Bool) + (hs : (seekCycles d S L V).succeeds ω = true) : + (seekCycles d S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : + finiteMean (fun ω : SwitchIndex d → Bool => + if (seekCycles d S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles d S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge d S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree + +lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by + simp only [finiteMean,Finset.sum_add_distrib,add_div] + +lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : + finiteMean (fun ω => f ω * c) = finiteMean f * c := by + unfold finiteMean + rw [← Finset.sum_mul] + ring + +lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : + finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by + simp only [finiteMean,Finset.sum_div] + exact Finset.sum_comm + +lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω → ℝ) : + finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by + unfold finiteMean + rw [Fintype.card_congr e] + congr 1 + exact Fintype.sum_equiv e _ _ (fun ω => by simp) + +lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] + (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by + simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, + ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] + have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + field_simp + +lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] + {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] + (c : C) (g : A c → ℝ) : + finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by + rw [finiteMean_equiv (Equiv.piSplitAt c A)] + have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => + g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by + funext z + simp [Equiv.piSplitAt] + rw [he,finiteMean_prod_left] + +lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : + finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by + simp [finiteMean] + +lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] + have hj := convexOn_exp.map_sum_le (t := Finset.univ) + (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) + (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul, ← Finset.mul_sum] at hj + simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj + +variable {d A : ℕ} + +def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} + +noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) + (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/Main.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/Main.lean index ff1722b085337de6043209b6bf987960b3ffb836..514ebb302310d161394410426ce554bf2f2b1b17 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/Main.lean @@ -1,1064 +1,1064 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.ParallelFreshPre - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -end Thorp - - -namespace Thorp.StrongSmoothing -open scoped BigOperators - -variable {X : Type*} [Fintype X] [Nonempty X] - -omit [Nonempty X] in -lemma mean_nonneg (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : 0 ≤ finiteMean f := - finiteMean_nonneg hf - -lemma mean_rpow_concave (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - {a : ℝ} (ha : 0 ≤ a) (ha1 : a ≤ 1) : - finiteMean (fun x => (f x)^a) ≤ (finiteMean f)^a := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hh := (Real.concaveOn_rpow ha ha1).le_map_sum - (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) - (p := f) (fun _ _ => by positivity) - (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) - (fun x _ => hf x) - simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), - ←div_eq_mul_inv,finiteMean] using hh - -noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x - -omit [Nonempty X] in -lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := - Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) - -omit [Nonempty X] in -lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - {b : ℝ} (hb : 1 ≤ b) (y : X) : - (act K f y)^b ≤ act K (fun x => (f x)^b) y := by - simpa only [smul_eq_mul,act] using - (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) - (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) - -lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - {p A : ℝ} (hp : 1 ≤ p) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by - classical - let s : ℝ := ∑ x, f x - have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - by_cases hz : s=0 - · have hfz : ∀ x, f x=0 := by - intro x - exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) - simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, - Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] - · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) - let w : X → ℝ := fun x => f x/s - have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs - have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz - have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by - simp only [act,w,finiteMean,Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - have hz' : (∑ x, f x) ≠ 0 := hz - dsimp [s] - field_simp [hz',ne_of_gt hN] - have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by - rw [hact,Real.mul_rpow (mean_nonneg f hf) - (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) - exact (convexOn_rpow hp).map_sum_le - (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) - have hh := finiteMean_mono hj - have he : finiteMean (fun y => (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = - (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by - simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, - finiteMean_sum, mul_comm (w _), finiteMean_mul_const] - rw [he] at hh - apply hh.trans - have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by - calc - _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum - (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) - _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] - simpa only [mul_comm (Real.exp A)] using - mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) - -lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^(b*p)) ≤ - Real.exp A*(finiteMean (fun x => (f x)^b))^p := by - calc - _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by - apply finiteMean_mono - intro y - rw [Real.rpow_mul (act_nonneg K hK f hf y)] - exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) - _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) - -variable [DecidableEq X] - -omit [Nonempty X] in -lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : - ∀ x y, 0 ≤ (K^r) x y := by - classical - induction r with - | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num - | succ r ih => - intro x y - rw [pow_succ,Matrix.mul_apply] - exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) - -omit [Nonempty X] in -lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : - ∀ x, ∑ y, (K^r) x y = 1 := by - classical - induction r with - | zero => intro x; simp [Matrix.one_apply] - | succ r ih => - intro x - simp only [pow_succ,Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hrow,mul_one,ih] - -noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := - (Fintype.card X:ℝ)*(K^r) x y - -omit [Nonempty X] in -lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : - 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) - -omit [Nonempty X] in -lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : - rowDensity K (r+1) x y = act K (rowDensity K r x) y := by - simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] - apply Finset.sum_congr rfl - intro z _ - ring - -lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : - finiteMean (rowDensity K r x) = 1 := by - have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) - simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] - -lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by - induction r with - | zero => simp [rowDensity_mean K hrow] - | succ r ih => - have hpr : 1 ≤ p^r := one_le_pow₀ hp - have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp - simp_rw [rowDensity_succ] - calc - _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by - rw [pow_succ] - exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) - _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by - apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le - exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) - _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring - _ ≤ _ := by - apply Real.exp_le_exp.mpr - have hh := mul_le_mul_of_nonneg_left hps hA - push_cast - nlinarith - -lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by - have hpos : 0 < p^r := by linarith - have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) - (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) - (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) - have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by - rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] - rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] - simp_rw [he] at hj - apply hj.trans - calc - _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := - Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) - (by positivity) - _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] - -lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : - (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z - have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = - finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by - simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] - rw [Finset.sum_div] - apply Finset.sum_congr rfl - intro z _ - field_simp - have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ - Real.exp (2*A*r) := by - calc - _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by - apply finiteMean_mono - intro z - nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] - _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ - finiteMean (fun z => (rowDensity K r y z)^2))/2 := by - simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] - _ ≤ _ := by - have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x - have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y - linarith - apply (le_div_iff₀ hN).mpr - simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh - -lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by - calc - (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num - _ ≤ _ := by simpa only [Nat.cast_ofNat] using - (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) - -end Thorp.StrongSmoothing - -namespace Thorp.StrongSmoothing.PermLaw -open scoped BigOperators -variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] - -noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := - fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) - -omit [Fintype X] in -lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by - simp only [kernel,←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype X] in -lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by - ext x y - apply finiteMean_congr - intro ω - have he : (P ω)⁻¹ x=y ↔ P ω y=x := by - change (P ω).symm x=y ↔ P ω y=x - exact (Equiv.symm_apply_eq (P ω)).trans eq_comm - simp only [he] - -lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by - have hh := row (fun ω => (P ω)⁻¹) y - rw [inverse] at hh - exact hh - -lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : - kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by - ext x y - simp only [Matrix.mul_apply,kernel] - have he (ω : Ω × Ω') : - (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = - ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by - simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] - rfl - change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro z _ - exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) - (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) - -omit [Fintype X] in -lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : - kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by - apply finiteMean_congr - intro ω - have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by - change e (P ω (e.symm x))=y ↔ _ - exact (Equiv.eq_symm_apply e).symm - simp only [he] - -end Thorp.StrongSmoothing.PermLaw - -namespace Thorp.StrongSmoothing -open scoped BigOperators - -section MatrixHelpers -variable {X : Type*} [Fintype X] [DecidableEq X] - -omit [DecidableEq X] in -lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := - Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) - -omit [DecidableEq X] in -lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) - (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hB,mul_one,hA] - -omit [DecidableEq X] in -lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) - (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.sum_mul,hA,one_mul,hB] - -omit [DecidableEq X] in -lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) - _ = D := by rw [←Finset.sum_mul,hrow,one_mul] - -omit [DecidableEq X] in -lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) - (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) - _ = D := by rw [←Finset.mul_sum,hcol,mul_one] - -lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by - induction r with - | zero => simp - | succ r ih => - calc - _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring - _ = (A*B)^(r+1)*(A*B) := by rw [ih] - _ = _ := (pow_succ (A*B) (r+1)).symm - -end MatrixHelpers - -section TupleAction -variable {ι β Ω : Type*} [Fintype ι] [Fintype β] [DecidableEq β] [Fintype Ω] - -def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where - toFun x := x.trans P.toEmbedding - invFun x := x.trans P.symm.toEmbedding - left_inv x := by ext i; simp - right_inv x := by ext i; simp - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : - tuplePerm P x i = P (x i) := rfl - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -lemma tuplePerm_mul (P Q : Equiv.Perm β) : - tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by - ext x i - rfl - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -lemma tuplePerm_inverse (P : Equiv.Perm β) : - tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by - ext x i - rfl - -omit [Fintype β] in -lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : - PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by - classical - apply finiteMean_congr - intro ω - have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun z : ι ↪ β => z i) h - simp only [he] -end TupleAction - -lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : - sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by - ext x y - exact tupleProbability_kernel _ x y - -lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - reflectedKernel d l order false x y = - PairRouting.tupleProbability (palindromePerm d) - ((tuplePerm (coordinateRelabel d order)).symm x) - ((tuplePerm (coordinateRelabel d order)).symm y) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) - have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by - rw [sweepKernel_law] - simp only [sweep,tuplePerm_mul,tuplePerm_inverse] - rfl - rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] - rw [←PermLaw.inverse,←PermLaw.mul] - have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = - fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by - funext ω - simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] - change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ - group - rw [hprod,PermLaw.conjugate,tupleProbability_kernel] - - -lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ - -lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.row _ _ - -lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.col _ _ - -lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ reflectedKernel d l order false x y := by - exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_nonneg d l order) x y - -lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, reflectedKernel d l order false x y = 1 := - mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x - -lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, reflectedKernel d l order false x y = 1 := - mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y - -lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : - (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ - -lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ - Real.exp (l*(1+heightDecay 1)) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - simp_rw [reflectedKernel_conjugate] - have he := finiteMean_equiv e (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ - (1+(1/1000:ℝ))) - change finiteMean (fun y => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ - (1+(1/1000:ℝ))) ≤ _ - rw [←he] - simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) - -lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by - simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] - -lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - ((reflectedKernel d l order false)^2000) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - let : Nonempty (Tuples d l) := ⟨x⟩ - have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) - (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) - (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) - (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) - (reflected_moment d l order) 1000 density_exponent_numeric x y - have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring - norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh - simpa only [he,tuples_card] using hh - -lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) - (x y : Tuples d l) : - ((reflectedKernel d l order orientation)^2001) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - cases orientation - · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ - rw [pow_succ] - exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) - (canonical_pointwise d l order) x y - · let A := sweepKernel d l order - change ((A*A.transpose)^(2000+1)) x y ≤ _ - rw [←sandwich_power] - apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_row d l order) - exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) - (canonical_pointwise d l order) - -lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : - regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by - have hn : 0 < Fintype.card (Tuples d (2^d)) := by - rw [tuples_card,Nat.descFactorial_self] - exact Nat.factorial_pos _ - have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) - calc - _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / - ((2^d).descFactorial (2^d):ℝ) := by - apply Finset.sum_le_sum - intro x _ - exact both_pointwise d (2^d) order false x x - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] - push_cast - field_simp - -theorem strong_smoothing : MainStatement := by - refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ - intro d l _ order orientation x y - exact both_pointwise d l order orientation x y - -end Thorp.StrongSmoothing - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.ParallelFreshPre + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +end Thorp + + +namespace Thorp.StrongSmoothing +open scoped BigOperators + +variable {X : Type*} [Fintype X] [Nonempty X] + +omit [Nonempty X] in +lemma mean_nonneg (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : 0 ≤ finiteMean f := + finiteMean_nonneg hf + +lemma mean_rpow_concave (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + {a : ℝ} (ha : 0 ≤ a) (ha1 : a ≤ 1) : + finiteMean (fun x => (f x)^a) ≤ (finiteMean f)^a := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hh := (Real.concaveOn_rpow ha ha1).le_map_sum + (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) + (p := f) (fun _ _ => by positivity) + (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) + (fun x _ => hf x) + simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), + ←div_eq_mul_inv,finiteMean] using hh + +noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x + +omit [Nonempty X] in +lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := + Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) + +omit [Nonempty X] in +lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + {b : ℝ} (hb : 1 ≤ b) (y : X) : + (act K f y)^b ≤ act K (fun x => (f x)^b) y := by + simpa only [smul_eq_mul,act] using + (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) + (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) + +lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + {p A : ℝ} (hp : 1 ≤ p) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by + classical + let s : ℝ := ∑ x, f x + have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + by_cases hz : s=0 + · have hfz : ∀ x, f x=0 := by + intro x + exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) + simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, + Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] + · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) + let w : X → ℝ := fun x => f x/s + have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs + have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz + have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by + simp only [act,w,finiteMean,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + have hz' : (∑ x, f x) ≠ 0 := hz + dsimp [s] + field_simp [hz',ne_of_gt hN] + have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by + rw [hact,Real.mul_rpow (mean_nonneg f hf) + (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) + exact (convexOn_rpow hp).map_sum_le + (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) + have hh := finiteMean_mono hj + have he : finiteMean (fun y => (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = + (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by + simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, + finiteMean_sum, mul_comm (w _), finiteMean_mul_const] + rw [he] at hh + apply hh.trans + have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by + calc + _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum + (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) + _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] + simpa only [mul_comm (Real.exp A)] using + mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) + +lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^(b*p)) ≤ + Real.exp A*(finiteMean (fun x => (f x)^b))^p := by + calc + _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by + apply finiteMean_mono + intro y + rw [Real.rpow_mul (act_nonneg K hK f hf y)] + exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) + _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) + +variable [DecidableEq X] + +omit [Nonempty X] in +lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : + ∀ x y, 0 ≤ (K^r) x y := by + classical + induction r with + | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num + | succ r ih => + intro x y + rw [pow_succ,Matrix.mul_apply] + exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) + +omit [Nonempty X] in +lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : + ∀ x, ∑ y, (K^r) x y = 1 := by + classical + induction r with + | zero => intro x; simp [Matrix.one_apply] + | succ r ih => + intro x + simp only [pow_succ,Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hrow,mul_one,ih] + +noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := + (Fintype.card X:ℝ)*(K^r) x y + +omit [Nonempty X] in +lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : + 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) + +omit [Nonempty X] in +lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : + rowDensity K (r+1) x y = act K (rowDensity K r x) y := by + simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] + apply Finset.sum_congr rfl + intro z _ + ring + +lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : + finiteMean (rowDensity K r x) = 1 := by + have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) + simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] + +lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by + induction r with + | zero => simp [rowDensity_mean K hrow] + | succ r ih => + have hpr : 1 ≤ p^r := one_le_pow₀ hp + have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp + simp_rw [rowDensity_succ] + calc + _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by + rw [pow_succ] + exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) + _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) + _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left hps hA + push_cast + nlinarith + +lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by + have hpos : 0 < p^r := by linarith + have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) + (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) + (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) + have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by + rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] + rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] + simp_rw [he] at hj + apply hj.trans + calc + _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := + Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) + (by positivity) + _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] + +lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : + (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z + have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = + finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by + simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro z _ + field_simp + have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ + Real.exp (2*A*r) := by + calc + _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by + apply finiteMean_mono + intro z + nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] + _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ + finiteMean (fun z => (rowDensity K r y z)^2))/2 := by + simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] + _ ≤ _ := by + have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x + have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y + linarith + apply (le_div_iff₀ hN).mpr + simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh + +lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by + calc + (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num + _ ≤ _ := by simpa only [Nat.cast_ofNat] using + (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) + +end Thorp.StrongSmoothing + +namespace Thorp.StrongSmoothing.PermLaw +open scoped BigOperators +variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] + +noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := + fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) + +omit [Fintype X] in +lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by + simp only [kernel,←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype X] in +lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by + ext x y + apply finiteMean_congr + intro ω + have he : (P ω)⁻¹ x=y ↔ P ω y=x := by + change (P ω).symm x=y ↔ P ω y=x + exact (Equiv.symm_apply_eq (P ω)).trans eq_comm + simp only [he] + +lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by + have hh := row (fun ω => (P ω)⁻¹) y + rw [inverse] at hh + exact hh + +lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : + kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by + ext x y + simp only [Matrix.mul_apply,kernel] + have he (ω : Ω × Ω') : + (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = + ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by + simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] + rfl + change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro z _ + exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) + (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) + +omit [Fintype X] in +lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : + kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by + apply finiteMean_congr + intro ω + have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by + change e (P ω (e.symm x))=y ↔ _ + exact (Equiv.eq_symm_apply e).symm + simp only [he] + +end Thorp.StrongSmoothing.PermLaw + +namespace Thorp.StrongSmoothing +open scoped BigOperators + +section MatrixHelpers +variable {X : Type*} [Fintype X] [DecidableEq X] + +omit [DecidableEq X] in +lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := + Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) + +omit [DecidableEq X] in +lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) + (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hB,mul_one,hA] + +omit [DecidableEq X] in +lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) + (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.sum_mul,hA,one_mul,hB] + +omit [DecidableEq X] in +lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) + _ = D := by rw [←Finset.sum_mul,hrow,one_mul] + +omit [DecidableEq X] in +lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) + (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) + _ = D := by rw [←Finset.mul_sum,hcol,mul_one] + +lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by + induction r with + | zero => simp + | succ r ih => + calc + _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring + _ = (A*B)^(r+1)*(A*B) := by rw [ih] + _ = _ := (pow_succ (A*B) (r+1)).symm + +end MatrixHelpers + +section TupleAction +variable {ι β Ω : Type*} [Fintype ι] [Fintype β] [DecidableEq β] [Fintype Ω] + +def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where + toFun x := x.trans P.toEmbedding + invFun x := x.trans P.symm.toEmbedding + left_inv x := by ext i; simp + right_inv x := by ext i; simp + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : + tuplePerm P x i = P (x i) := rfl + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +lemma tuplePerm_mul (P Q : Equiv.Perm β) : + tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by + ext x i + rfl + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +lemma tuplePerm_inverse (P : Equiv.Perm β) : + tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by + ext x i + rfl + +omit [Fintype β] in +lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : + PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by + classical + apply finiteMean_congr + intro ω + have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun z : ι ↪ β => z i) h + simp only [he] +end TupleAction + +lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : + sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by + ext x y + exact tupleProbability_kernel _ x y + +lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + reflectedKernel d l order false x y = + PairRouting.tupleProbability (palindromePerm d) + ((tuplePerm (coordinateRelabel d order)).symm x) + ((tuplePerm (coordinateRelabel d order)).symm y) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) + have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by + rw [sweepKernel_law] + simp only [sweep,tuplePerm_mul,tuplePerm_inverse] + rfl + rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] + rw [←PermLaw.inverse,←PermLaw.mul] + have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = + fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by + funext ω + simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] + change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ + group + rw [hprod,PermLaw.conjugate,tupleProbability_kernel] + + +lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ + +lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.row _ _ + +lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.col _ _ + +lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ reflectedKernel d l order false x y := by + exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_nonneg d l order) x y + +lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, reflectedKernel d l order false x y = 1 := + mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x + +lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, reflectedKernel d l order false x y = 1 := + mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y + +lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : + (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ + +lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ + Real.exp (l*(1+heightDecay 1)) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + simp_rw [reflectedKernel_conjugate] + have he := finiteMean_equiv e (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ + (1+(1/1000:ℝ))) + change finiteMean (fun y => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ + (1+(1/1000:ℝ))) ≤ _ + rw [←he] + simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) + +lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by + simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] + +lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + ((reflectedKernel d l order false)^2000) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + let : Nonempty (Tuples d l) := ⟨x⟩ + have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) + (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) + (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) + (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) + (reflected_moment d l order) 1000 density_exponent_numeric x y + have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring + norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh + simpa only [he,tuples_card] using hh + +lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) + (x y : Tuples d l) : + ((reflectedKernel d l order orientation)^2001) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + cases orientation + · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ + rw [pow_succ] + exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) + (canonical_pointwise d l order) x y + · let A := sweepKernel d l order + change ((A*A.transpose)^(2000+1)) x y ≤ _ + rw [←sandwich_power] + apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_row d l order) + exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) + (canonical_pointwise d l order) + +lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : + regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by + have hn : 0 < Fintype.card (Tuples d (2^d)) := by + rw [tuples_card,Nat.descFactorial_self] + exact Nat.factorial_pos _ + have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) + calc + _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / + ((2^d).descFactorial (2^d):ℝ) := by + apply Finset.sum_le_sum + intro x _ + exact both_pointwise d (2^d) order false x x + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] + push_cast + field_simp + +theorem strong_smoothing : MainStatement := by + refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ + intro d l _ order orientation x y + exact both_pointwise d l order orientation x y + +end Thorp.StrongSmoothing + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/Model.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/Model.lean index 40f2a245f6a803005ace3fbdc2472bdef8eead74..032fe596f5154b195c8e1f4b870644ef32c8f717 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/Model.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/Model.lean @@ -1,121 +1,121 @@ -import Mathlib - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev Card (d : ℕ) := Fin d → Bool - -def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := - Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) - -theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : - Function.Involutive (switchFun ξ) := by - intro x - funext i - refine Fin.cases ?_ (fun j => ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -end Thorp - -namespace Thorp.PairRouting -open scoped BigOperators -open Filter -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -end Thorp.PairRouting - -namespace Thorp.StrongSmoothing - -def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where - toFun x := fun i => x (order.symm i) - invFun x := fun i => x (order i) - left_inv x := by funext i; simp - right_inv x := by funext i; simp - -def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : - Equiv.Perm (Card d) := - coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * - (coordinateRelabel d order)⁻¹ - -abbrev Tuples (d l : ℕ) := Fin l ↪ Card d - -noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : - Matrix (Tuples d l) (Tuples d l) ℝ := - fun x y => PairRouting.tupleProbability (sweep d order) x y - -noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : - Matrix (Tuples d l) (Tuples d l) ℝ := - let A := sweepKernel d l order - if orientation then A * A.transpose else A.transpose * A - -noncomputable def regularAbsoluteEvenTrace (d : ℕ) (order : Equiv.Perm (Fin d)) (u : ℕ) : ℝ := - Matrix.trace ((reflectedKernel d (2^d) order false)^u) - -def MainStatement : Prop := - ∃ u : ℕ, 1 ≤ u ∧ ∃ C : ℝ, - (∀ d l : ℕ, l ≤ 2^d → ∀ order : Equiv.Perm (Fin d), ∀ orientation : Bool, - ∀ x y : Tuples d l, - ((reflectedKernel d l order orientation)^u) x y ≤ - Real.exp (C*l)/((2^d).descFactorial l:ℝ)) ∧ - (∀ d : ℕ, ∀ order : Equiv.Perm (Fin d), - regularAbsoluteEvenTrace d order u ≤ Real.exp (C*(2:ℝ)^d)) - -end Thorp.StrongSmoothing - -end ThorpNine.Smoothing - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +end Thorp + +namespace Thorp.PairRouting +open scoped BigOperators +open Filter +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +end Thorp.PairRouting + +namespace Thorp.StrongSmoothing + +def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where + toFun x := fun i => x (order.symm i) + invFun x := fun i => x (order i) + left_inv x := by funext i; simp + right_inv x := by funext i; simp + +def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : + Equiv.Perm (Card d) := + coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * + (coordinateRelabel d order)⁻¹ + +abbrev Tuples (d l : ℕ) := Fin l ↪ Card d + +noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : + Matrix (Tuples d l) (Tuples d l) ℝ := + fun x y => PairRouting.tupleProbability (sweep d order) x y + +noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : + Matrix (Tuples d l) (Tuples d l) ℝ := + let A := sweepKernel d l order + if orientation then A * A.transpose else A.transpose * A + +noncomputable def regularAbsoluteEvenTrace (d : ℕ) (order : Equiv.Perm (Fin d)) (u : ℕ) : ℝ := + Matrix.trace ((reflectedKernel d (2^d) order false)^u) + +def MainStatement : Prop := + ∃ u : ℕ, 1 ≤ u ∧ ∃ C : ℝ, + (∀ d l : ℕ, l ≤ 2^d → ∀ order : Equiv.Perm (Fin d), ∀ orientation : Bool, + ∀ x y : Tuples d l, + ((reflectedKernel d l order orientation)^u) x y ≤ + Real.exp (C*l)/((2^d).descFactorial l:ℝ)) ∧ + (∀ d : ℕ, ∀ order : Equiv.Perm (Fin d), + regularAbsoluteEvenTrace d order u ≤ Real.exp (C*(2:ℝ)^d)) + +end Thorp.StrongSmoothing + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFollow.lean index 38b17d7bb9de543ae51d3f54d785c6201b3fa64f..59cca4fb8b3461a70a07b0247cefffadc9755de1 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFollow.lean @@ -1,883 +1,883 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.PriorPaths - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.PriorPaths + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFreshPre.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFreshPre.lean index f9c2cda61f1f0d5b8936e4d210297d7b731b4f7b..0e87038e88285a03b7e6437d850492c71b359bfc 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFreshPre.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/ParallelFreshPre.lean @@ -1,848 +1,848 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.BenesCoins - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp - -lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : - x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by - classical - constructor - · intro h - obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h - simp only [Equiv.apply_symm_apply] - · intro h - apply Finset.mem_image.mpr - refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ - rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] - -lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by - classical - rw [centralBlock,Finset.card_image_of_injective] - · exact card_positions H - · intro x y h - exact congrArg Prod.snd ((cardSplit r H).symm.injective h) - -lemma centralBlock_disjoint (r H : ℕ) : - Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by - classical - intro b b' h - apply Finset.disjoint_left.mpr - intro x hx hy - exact h (((mem_centralBlock r H b x).mp hx).symm.trans - ((mem_centralBlock r H b' x).mp hy)) - -lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by - classical - ext x - simp only [mem_centralBlock,Finset.mem_univ,iff_true] - exact Subsingleton.elim _ _ - -lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : - centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by - classical - simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, - Fin.cons_zero,Fin.tail_cons,Function.comp_def] - -lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : - centralBlock (r+1) H (Fin.cons b c) ∩ A = - (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by - classical - rw [centralBlock_step] - ext x - constructor - · intro hx - obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB - exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, - (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ - -lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : - sparseMass (centralBlock 0 H) A = crowdedMass A.card := by - classical - simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, - Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] - -lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : - sparseMass (centralBlock (r+1) H) A = - sparseMass (centralBlock r H) (childMarks A false) + - sparseMass (centralBlock r H) (childMarks A true) := by - classical - unfold sparseMass - rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl - simp only [Fintype.sum_bool,ht] - have hc (b : Bool) (c : Card r) : - (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = - (centralBlock r H c ∩ childMarks A b).card := by - rw [block_inter_step] - apply Finset.card_image_of_injective - intro x y h - simpa only [Fin.tail_cons] using congrArg Fin.tail h - simp only [hc] - exact add_comm _ _ - - -lemma inverseButterfly_coordinates_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) - (x : Card (d+1)) : - headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = - (Bool.xor (x 0) (ξ (Fin.tail x)), - (butterflyPerm d (decodeButterfly d - (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by - rw [butterflyPerm_step] - rfl - -lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : - childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) - ((coinStepEquiv d).symm (c,ξ))) b = - inverseButterflyMarks d - (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) - (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by - classical - let x := e.trans (headTailEquiv d).toEmbedding - let col := PairRouting.colors x ξ - let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b - have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = - (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := - inverseButterfly_coordinates_step d c ξ (e i) - ext y - simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, - Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] - constructor - · rintro ⟨i,hi⟩ - have he := congrArg (headTailEquiv d) hi - rw [hp i] at he - change (col i,_) = (b,y) at he - have hb := congrArg Prod.fst he - have hy := congrArg Prod.snd he - dsimp only at hb hy - refine ⟨⟨i,hb⟩,?_⟩ - change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y - simpa only [hb] using hy - · rintro ⟨i,hi⟩ - refine ⟨i.val,?_⟩ - apply (headTailEquiv d).injective - rw [hp] - change (col i.val,_) = (b,y) - have hb : col i.val = b := i.property - rw [hb] - exact Prod.ext rfl hi - -lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : - (inverseButterflyMarks d A ω).card = A.card := by - classical - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective - -lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : - ω.2 = (coinStepEquiv d).symm - (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by - change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) - exact ((coinStepEquiv d).symm_apply_apply ω.2).symm - -lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : - cutoffMass H (H+r) e ω = - sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by - classical - induction r generalizing ι with - | zero => - rw [sparseMass_central_zero,inverseButterflyMarks_card, - Finset.card_image_of_injective _ e.injective,Finset.card_univ] - cases H with - | zero => - have hcard : Fintype.card ι ≤ 1 := by - have hh := Fintype.card_le_of_injective e e.injective - simpa only [Nat.add_zero,card_positions,pow_zero] using hh - simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] - | succ H => simp only [cutoffMass,le_refl,ite_true] - | succ r ih => - simp only [Nat.add_succ] at * - rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] - let σ := benesStepEquiv (H+r) ω - let x := e.trans (headTailEquiv (H+r)).toEmbedding - let col := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + - cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ - rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] - rw [inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - - -theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ - Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by - classical - have hec : (Finset.univ.image e).card = Fintype.card ι := by - rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] - have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) - (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) - (pow_nonneg (by linarith) _) (fun b => by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) - calc - _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by - apply finiteMean_mono - intro ω - rw [←pow_mul] - exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) - _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => - (q^H)^(sparseMass (centralBlock r H) - (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by - simp_rw [cutoffMass_central] - simp only [finiteMean_prod,finiteMean_const] - _ ≤ _ := by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, - Finset.card_univ,card_positions,nsmul_eq_mul] using hm - -variable {α B : Type*} {r s : ℕ} - -def parallelFreshPre (pre : α ≃ B × Card (s+r)) - (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := - ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans - (Equiv.prodCongrRight (fun b => - (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans - (Equiv.prodAssoc _ _ _).symm - -def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := - (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) - (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post - -def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := - fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 - -lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : - relabeledPerm pre post (parallelAssembled lo hi) = - relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by - ext x - have h := butterfly_split r s (lo (pre x).1) - (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 - have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h - simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, - Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, - Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, - Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh - -theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] - (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ - (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by - simp_rw [parallel_exposed_perm] - exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq - -end Thorp -namespace Thorp -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] - -lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Fintype.card_congr - refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ - invFun := fun C => ⟨C.val,?_,C.property.2⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ - -lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : - orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by - ext y - simp only [mem_orbitSet,Finset.mem_image] - rw [Equiv.Perm.sameCycle_conj] - change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y - rw [Equiv.symm_apply_apply] - constructor - · intro h - exact ⟨g.symm y,h,g.apply_symm_apply y⟩ - · rintro ⟨z,hz,rfl⟩ - simpa only [Equiv.symm_apply_apply] using hz - -noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) - (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by - refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ - -lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : - Function.Injective (conjugateCycle p g S) := by - intro C D he - apply Subtype.ext - exact (Finset.image_injective g.injective) (congrArg Subtype.val he) - -lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Nat.le_antisymm - · have h := Fintype.card_le_of_injective _ - (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) - have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group - rw [inv_inv,hp] at h - have hs : (S.image g).image g.symm = S := by - ext x - simp only [Finset.mem_image] - constructor - · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ - have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he - exact hz' ▸ hz - · intro hx - exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ - change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h - rw [hs] at h - exact h - · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) - -lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false)) := by - have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) - simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h - -lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle - ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = - Fintype.card (RoutingNetwork.SelectedCycle - (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by - let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) - calc - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) - (S.image X₀.symm)) := by - change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ - have h := (selectedCycle_conjugate p X₀⁻¹ S).symm - rw [inv_inv] at h - exact h - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ - (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm - _ = _ := by - have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group - rw [he] - -end Thorp -namespace Thorp - -noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := - Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) - -lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - 0 ≤ cycleCoefficient r J q := by - unfold cycleCoefficient - exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) - (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) - -lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] - (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by - have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) - (boolFiber (PairRouting.labelSet e) true) - rw [childJoin_boolFiber,PairRouting.card_labelSet] at h - omega - -theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient r J q) := by - classical - let S := boolFiber (PairRouting.labelSet e) false - let S' := S.image X₀.symm - let post := X₀⁻¹*X₁*Y₁⁻¹ - let count := fun hi : Card s × SwitchIndex r → Bool => - Fintype.card (RoutingNetwork.SelectedCycle - ((Equiv.refl _).trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') - have hpoint (hi : Card s × SwitchIndex r → Bool) : - PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by - refine (alternatingCycles_le_projection e _).trans_eq ?_ - simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] - change Fintype.card (RoutingNetwork.SelectedCycle - ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi - exact projectionCycles_forward X₀ X₁ _ Y₁ S - have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq - have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_pos (fun _ => pow_pos (by linarith) _) - have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ - Real.exp (S'.card * cycleCoefficient r J q) := by - rw [←Real.exp_log hp] - apply Real.exp_le_exp.mpr - calc - _ ≤ _ := hm - _ = _ := by unfold cycleCoefficient; ring - have hcard : S'.card ≤ Fintype.card ι := by - rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] - exact projectionSide_card_le e - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) - _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right - (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) - - -def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ - (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) where - toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), - fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) - invFun c := fun j => match j.2 with - | Sum.inl y => c.2 (j.1,y) - | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) - left_inv hi := by - funext j - rcases j with ⟨z,y|⟨b,i⟩⟩ - · rfl - · cases b <;> rfl - right_inv c := by - rcases c with ⟨⟨h₀,h₁⟩,η⟩ - rfl - -lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) - (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) : - assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = - (coinStepEquiv (s+r)).symm - ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, - assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), - fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - -noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (ξ η : Card d → Bool) : - palindromeLevelCost t (d+1) e - ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by - rw [palindromeLevelCost] - rfl - -lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] - - -theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - let χ := coinStepEquiv (s+r) X - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x χ.2 - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) - else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - palindromeLevelCost (s+u+1) (s+r+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] - rw [palindromeLevelCost_step] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] - congr 2 - funext b - cases b <;> rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' e₀ χ.1.1 lo₀ - have h₁ := ih u hu' e₁ χ.1.2 lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -def switchHeight : (d : ℕ) → SwitchIndex d → ℕ - | 0, i => nomatch i - | d+1, Sum.inl _ => d+1 - | d+1, Sum.inr (_,i) => switchHeight d i - -lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - rcases i with y | ⟨b,i⟩ - · exact le_refl _ - · exact (ih i).trans (Nat.le_succ d) - -def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := - ∀ i, switchHeight d i ≤ s → Y i = Y' i - -def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := - ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' - -lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} - (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := - fun i hi => hh i (hi.trans h) - -lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} - (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := - fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) - -lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} - (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := - fun Y Y' h => congrArg g (hf Y Y' h) - -lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) - (f : ι → (SwitchIndex d → Bool) → ℕ) - (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : - LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by - intro Y Y' h - exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) - -lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi hi' : Card s × SwitchIndex r → Bool) : - AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by - induction r with - | zero => intro i _; rfl - | succ r ih => - intro i h - rcases i with y | ⟨b,i⟩ - · have : s+r+1 ≤ s := h - omega - · exact ih (fun j => lo (Fin.cons b j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h - -lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by - classical - induction d generalizing ι with - | zero => intro Y Y' _; rfl - | succ d ih => - intro Y Y' h - change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step,palindromeLevelCost_step] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih - intro i hi - exact h (Sum.inr (true,i)) hi - -lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) - (hG : ∀ lo : Card r × SwitchIndex s → Bool, - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : - finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by - rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] - apply finiteMean_mono - intro lo - let H : Card s × SwitchIndex r → Bool := fun _ => false - have hh (hi : Card s × SwitchIndex r → Bool) : - F (assembleBits r s lo hi) = F (assembleBits r s lo H) := - hA _ _ (assembleBits_agree r s lo hi H) - simp_rw [hh,finiteMean_const] - rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = - (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by - funext hi; exact mul_comm _ _,finiteMean_mul_const] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) - - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/250) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by - have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) - have he := Real.exp_pos ((l:ℝ)/32) - have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h - exact_mod_cast this - - -lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] - (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : - q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by - have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = - (∑ i, z i:ℕ)*Real.log q := by - simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] - field_simp - have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) - rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he - simpa only [Real.exp_nat_mul,Real.exp_log hq] using he - -noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω - -lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact palindromeLevelCost_gt _ _ (by omega) _ _ - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.BenesCoins + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp + +lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : + x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by + classical + constructor + · intro h + obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h + simp only [Equiv.apply_symm_apply] + · intro h + apply Finset.mem_image.mpr + refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ + rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] + +lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by + classical + rw [centralBlock,Finset.card_image_of_injective] + · exact card_positions H + · intro x y h + exact congrArg Prod.snd ((cardSplit r H).symm.injective h) + +lemma centralBlock_disjoint (r H : ℕ) : + Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by + classical + intro b b' h + apply Finset.disjoint_left.mpr + intro x hx hy + exact h (((mem_centralBlock r H b x).mp hx).symm.trans + ((mem_centralBlock r H b' x).mp hy)) + +lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by + classical + ext x + simp only [mem_centralBlock,Finset.mem_univ,iff_true] + exact Subsingleton.elim _ _ + +lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : + centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by + classical + simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, + Fin.cons_zero,Fin.tail_cons,Function.comp_def] + +lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : + centralBlock (r+1) H (Fin.cons b c) ∩ A = + (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by + classical + rw [centralBlock_step] + ext x + constructor + · intro hx + obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB + exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, + (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ + +lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : + sparseMass (centralBlock 0 H) A = crowdedMass A.card := by + classical + simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, + Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] + +lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : + sparseMass (centralBlock (r+1) H) A = + sparseMass (centralBlock r H) (childMarks A false) + + sparseMass (centralBlock r H) (childMarks A true) := by + classical + unfold sparseMass + rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl + simp only [Fintype.sum_bool,ht] + have hc (b : Bool) (c : Card r) : + (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = + (centralBlock r H c ∩ childMarks A b).card := by + rw [block_inter_step] + apply Finset.card_image_of_injective + intro x y h + simpa only [Fin.tail_cons] using congrArg Fin.tail h + simp only [hc] + exact add_comm _ _ + + +lemma inverseButterfly_coordinates_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) + (x : Card (d+1)) : + headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = + (Bool.xor (x 0) (ξ (Fin.tail x)), + (butterflyPerm d (decodeButterfly d + (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by + rw [butterflyPerm_step] + rfl + +lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : + childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) + ((coinStepEquiv d).symm (c,ξ))) b = + inverseButterflyMarks d + (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) + (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by + classical + let x := e.trans (headTailEquiv d).toEmbedding + let col := PairRouting.colors x ξ + let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b + have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = + (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := + inverseButterfly_coordinates_step d c ξ (e i) + ext y + simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, + Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] + constructor + · rintro ⟨i,hi⟩ + have he := congrArg (headTailEquiv d) hi + rw [hp i] at he + change (col i,_) = (b,y) at he + have hb := congrArg Prod.fst he + have hy := congrArg Prod.snd he + dsimp only at hb hy + refine ⟨⟨i,hb⟩,?_⟩ + change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y + simpa only [hb] using hy + · rintro ⟨i,hi⟩ + refine ⟨i.val,?_⟩ + apply (headTailEquiv d).injective + rw [hp] + change (col i.val,_) = (b,y) + have hb : col i.val = b := i.property + rw [hb] + exact Prod.ext rfl hi + +lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : + (inverseButterflyMarks d A ω).card = A.card := by + classical + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective + +lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : + ω.2 = (coinStepEquiv d).symm + (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by + change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) + exact ((coinStepEquiv d).symm_apply_apply ω.2).symm + +lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : + cutoffMass H (H+r) e ω = + sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by + classical + induction r generalizing ι with + | zero => + rw [sparseMass_central_zero,inverseButterflyMarks_card, + Finset.card_image_of_injective _ e.injective,Finset.card_univ] + cases H with + | zero => + have hcard : Fintype.card ι ≤ 1 := by + have hh := Fintype.card_le_of_injective e e.injective + simpa only [Nat.add_zero,card_positions,pow_zero] using hh + simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] + | succ H => simp only [cutoffMass,le_refl,ite_true] + | succ r ih => + simp only [Nat.add_succ] at * + rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] + let σ := benesStepEquiv (H+r) ω + let x := e.trans (headTailEquiv (H+r)).toEmbedding + let col := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + + cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ + rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] + rw [inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + + +theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ + Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by + classical + have hec : (Finset.univ.image e).card = Fintype.card ι := by + rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] + have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) + (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) + (pow_nonneg (by linarith) _) (fun b => by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) + calc + _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by + apply finiteMean_mono + intro ω + rw [←pow_mul] + exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) + _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => + (q^H)^(sparseMass (centralBlock r H) + (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by + simp_rw [cutoffMass_central] + simp only [finiteMean_prod,finiteMean_const] + _ ≤ _ := by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, + Finset.card_univ,card_positions,nsmul_eq_mul] using hm + +variable {α B : Type*} {r s : ℕ} + +def parallelFreshPre (pre : α ≃ B × Card (s+r)) + (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := + ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans + (Equiv.prodCongrRight (fun b => + (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans + (Equiv.prodAssoc _ _ _).symm + +def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := + (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) + (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post + +def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := + fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 + +lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : + relabeledPerm pre post (parallelAssembled lo hi) = + relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by + ext x + have h := butterfly_split r s (lo (pre x).1) + (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 + have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h + simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, + Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, + Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, + Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh + +theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] + (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ + (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by + simp_rw [parallel_exposed_perm] + exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq + +end Thorp +namespace Thorp +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] + +lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Fintype.card_congr + refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ + invFun := fun C => ⟨C.val,?_,C.property.2⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ + +lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : + orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by + ext y + simp only [mem_orbitSet,Finset.mem_image] + rw [Equiv.Perm.sameCycle_conj] + change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y + rw [Equiv.symm_apply_apply] + constructor + · intro h + exact ⟨g.symm y,h,g.apply_symm_apply y⟩ + · rintro ⟨z,hz,rfl⟩ + simpa only [Equiv.symm_apply_apply] using hz + +noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) + (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by + refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ + +lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : + Function.Injective (conjugateCycle p g S) := by + intro C D he + apply Subtype.ext + exact (Finset.image_injective g.injective) (congrArg Subtype.val he) + +lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Nat.le_antisymm + · have h := Fintype.card_le_of_injective _ + (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) + have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group + rw [inv_inv,hp] at h + have hs : (S.image g).image g.symm = S := by + ext x + simp only [Finset.mem_image] + constructor + · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ + have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he + exact hz' ▸ hz + · intro hx + exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ + change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h + rw [hs] at h + exact h + · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) + +lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false)) := by + have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) + simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h + +lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle + ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = + Fintype.card (RoutingNetwork.SelectedCycle + (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by + let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) + calc + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) + (S.image X₀.symm)) := by + change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ + have h := (selectedCycle_conjugate p X₀⁻¹ S).symm + rw [inv_inv] at h + exact h + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ + (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm + _ = _ := by + have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group + rw [he] + +end Thorp +namespace Thorp + +noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := + Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) + +lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + 0 ≤ cycleCoefficient r J q := by + unfold cycleCoefficient + exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) + (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) + +lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by + have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) + (boolFiber (PairRouting.labelSet e) true) + rw [childJoin_boolFiber,PairRouting.card_labelSet] at h + omega + +theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient r J q) := by + classical + let S := boolFiber (PairRouting.labelSet e) false + let S' := S.image X₀.symm + let post := X₀⁻¹*X₁*Y₁⁻¹ + let count := fun hi : Card s × SwitchIndex r → Bool => + Fintype.card (RoutingNetwork.SelectedCycle + ((Equiv.refl _).trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') + have hpoint (hi : Card s × SwitchIndex r → Bool) : + PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by + refine (alternatingCycles_le_projection e _).trans_eq ?_ + simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] + change Fintype.card (RoutingNetwork.SelectedCycle + ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi + exact projectionCycles_forward X₀ X₁ _ Y₁ S + have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq + have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_pos (fun _ => pow_pos (by linarith) _) + have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ + Real.exp (S'.card * cycleCoefficient r J q) := by + rw [←Real.exp_log hp] + apply Real.exp_le_exp.mpr + calc + _ ≤ _ := hm + _ = _ := by unfold cycleCoefficient; ring + have hcard : S'.card ≤ Fintype.card ι := by + rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] + exact projectionSide_card_le e + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) + _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) + + +def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ + (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) where + toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), + fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) + invFun c := fun j => match j.2 with + | Sum.inl y => c.2 (j.1,y) + | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) + left_inv hi := by + funext j + rcases j with ⟨z,y|⟨b,i⟩⟩ + · rfl + · cases b <;> rfl + right_inv c := by + rcases c with ⟨⟨h₀,h₁⟩,η⟩ + rfl + +lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) + (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) : + assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = + (coinStepEquiv (s+r)).symm + ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, + assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), + fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + +noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (ξ η : Card d → Bool) : + palindromeLevelCost t (d+1) e + ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by + rw [palindromeLevelCost] + rfl + +lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] + + +theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + let χ := coinStepEquiv (s+r) X + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x χ.2 + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) + else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + palindromeLevelCost (s+u+1) (s+r+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] + rw [palindromeLevelCost_step] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] + congr 2 + funext b + cases b <;> rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' e₀ χ.1.1 lo₀ + have h₁ := ih u hu' e₁ χ.1.2 lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +def switchHeight : (d : ℕ) → SwitchIndex d → ℕ + | 0, i => nomatch i + | d+1, Sum.inl _ => d+1 + | d+1, Sum.inr (_,i) => switchHeight d i + +lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + rcases i with y | ⟨b,i⟩ + · exact le_refl _ + · exact (ih i).trans (Nat.le_succ d) + +def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := + ∀ i, switchHeight d i ≤ s → Y i = Y' i + +def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := + ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' + +lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} + (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := + fun i hi => hh i (hi.trans h) + +lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} + (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := + fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) + +lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} + (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := + fun Y Y' h => congrArg g (hf Y Y' h) + +lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) + (f : ι → (SwitchIndex d → Bool) → ℕ) + (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : + LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by + intro Y Y' h + exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) + +lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi hi' : Card s × SwitchIndex r → Bool) : + AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by + induction r with + | zero => intro i _; rfl + | succ r ih => + intro i h + rcases i with y | ⟨b,i⟩ + · have : s+r+1 ≤ s := h + omega + · exact ih (fun j => lo (Fin.cons b j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h + +lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by + classical + induction d generalizing ι with + | zero => intro Y Y' _; rfl + | succ d ih => + intro Y Y' h + change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step,palindromeLevelCost_step] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih + intro i hi + exact h (Sum.inr (true,i)) hi + +lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) + (hG : ∀ lo : Card r × SwitchIndex s → Bool, + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : + finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by + rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] + apply finiteMean_mono + intro lo + let H : Card s × SwitchIndex r → Bool := fun _ => false + have hh (hi : Card s × SwitchIndex r → Bool) : + F (assembleBits r s lo hi) = F (assembleBits r s lo H) := + hA _ _ (assembleBits_agree r s lo hi H) + simp_rw [hh,finiteMean_const] + rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = + (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by + funext hi; exact mul_comm _ _,finiteMean_mul_const] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) + + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/250) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by + have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) + have he := Real.exp_pos ((l:ℝ)/32) + have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h + exact_mod_cast this + + +lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] + (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : + q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = + (∑ i, z i:ℕ)*Real.log q := by + simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] + field_simp + have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) + rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he + simpa only [Real.exp_nat_mul,Real.exp_log hq] using he + +noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω + +lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact palindromeLevelCost_gt _ _ (by omega) _ _ + +lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/PriorPaths.lean index 1dcb9a7d8fe48c51b79e98360af426bcb5e14afe..dbbfaf88e7e2f24fa0c2152c16c97979ee0dc14f 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/PriorPaths.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.AssignmentSlots - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.AssignmentSlots + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Smoothing/RotationCharge.lean b/lean/OAI/Probability/ThorpRouting/Smoothing/RotationCharge.lean index 96377350588dfe520c71106be9424dc66fc356c6..bb1bc4d9028fa5952e6650d9883235b490d4ad0f 100644 --- a/lean/OAI/Probability/ThorpRouting/Smoothing/RotationCharge.lean +++ b/lean/OAI/Probability/ThorpRouting/Smoothing/RotationCharge.lean @@ -1,891 +1,891 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Smoothing.ExposedCoins - -namespace OAI - -namespace ThorpNine.Smoothing - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -end Thorp - -end ThorpNine.Smoothing - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Smoothing.ExposedCoins + +namespace OAI + +namespace ThorpNine.Smoothing + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +end Thorp + +end ThorpNine.Smoothing + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/AlternatingPerm.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/AlternatingPerm.lean index 9bffc02be908ba4454443eeae83b19ff3c551ca4..fab51c46b39f32f5be343e86e4203a016cf59d06 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/AlternatingPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/AlternatingPerm.lean @@ -1,900 +1,900 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ParallelFollow - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) - (a : ℝ) (ha : 0 ≤ a) : - (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)))^(1+a) ≤ - (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * - ∑ c ∈ compatibleSet x y, - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by - classical - rw [sandwich_mean,sum_colors_factor] - let f (c : ι → Bool) : ℝ := - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) - have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) - (tupleProbability_nonneg _ _ _) - rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] - have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) - (show 1 ≤ 1+a by linarith) (fun c _ => hf c) - have he : 1+a-1=a := by ring - rw [he] at hh - calc - _ ≤ (outerWeight x y)^(1+a) * - (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := - mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) - _ = _ := by - rw [←mul_assoc] - congr 1 - apply Finset.sum_congr rfl - intro c _ - exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) - -end PairRouting - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ParallelFollow + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) + (a : ℝ) (ha : 0 ≤ a) : + (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)))^(1+a) ≤ + (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * + ∑ c ∈ compatibleSet x y, + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by + classical + rw [sandwich_mean,sum_colors_factor] + let f (c : ι → Bool) : ℝ := + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) + have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) + (tupleProbability_nonneg _ _ _) + rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] + have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) + (show 1 ≤ 1+a by linarith) (fun c _ => hf c) + have he : 1+a-1=a := by ring + rw [he] at hh + calc + _ ≤ (outerWeight x y)^(1+a) * + (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := + mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) + _ = _ := by + rw [←mul_assoc] + congr 1 + apply Finset.sum_congr rfl + intro c _ + exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) + +end PairRouting + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/AssignmentSlots.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/AssignmentSlots.lean index f3fb711c3367c6963ceb86eda0b9d7a61bd07a3e..91001448c15e8603ebe8997c68ff98ee8e6e0e7e 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/AssignmentSlots.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/AssignmentSlots.lean @@ -1,834 +1,834 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.RotationMeeting - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter -section CycleCounting -variable {d A : ℕ} - -lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {d A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr - -end GroupedCounting - -section AllLengths -variable {d A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) - (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) - (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : - finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by - have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by - rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] - exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm - have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), - ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by - calc - _ = ((q-1)+1)^(F ω) := by congr 1; ring - _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by - rw [add_pow] - simp only [one_pow,mul_one] - _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by - apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) - intro a _ ha - have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega - rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] - _ = _ := by - apply Finset.sum_congr rfl - intro a _ - rw [hc] - ring - simp_rw [hex,finiteMean_sum,finiteMean_mul_const] - calc - _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_right (hm a) (by positivity) - _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by - apply Finset.sum_congr rfl - intro a _ - rw [mul_pow] - ring - _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ - -lemma inv_sqrt_step (j : ℕ) : - 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by - have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) - apply (div_le_iff₀ hp).mpr - have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) - have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) - nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] - -lemma sum_inv_sqrt (J : ℕ) : - (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by - have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ] - have hs := inv_sqrt_step n - push_cast - linarith - rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] - exact h J -section CycleMGF -variable {d : ℕ} - -lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment S J - -end CycleMGF - -section FullCycleMGF -variable {d : ℕ} - -abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by - apply div_pos - · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty - · exact Nat.cast_pos.mpr Fintype.card_pos - -lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - -end FullCycleMGF - -structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] - [Fintype ι] [DecidableEq ι] (d : ℕ) where - perm : (ι → Bool) → Equiv.Perm α - path : (ι → Bool) → α → Finset ι - users : (ι → Bool) → ι → α × α - users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 - mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x - card_path : ∀ ω x, (path ω x).card = d - entropy : ∀ ω (S : Finset α), - (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) - follow : α → (α → QueryTree ι) → QueryTree ι - close : α → α → QueryTree ι → QueryTree ι - follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω - follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω - follow_stale_charge : ∀ x k R ω, - (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω - close_succeeds : ∀ x y k ω, - (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false - close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d - close_stale_charge : ∀ x y k R ω, perm ω x = y → - (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card - -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma card_switches_using (ω : ι → Bool) (x : α) : - (Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by - ext i - simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] - rw [he,R.card_path] -lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = - (d : ℝ) * ∑ x : α, w x := by - classical - calc - _ = ∑ i : ι, ∑ x : α, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : α => - (R.users b i).1 = x ∨ (R.users b i).2 = x) = - {(R.users b i).1, (R.users b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (R.users_ne b i)] - _ = ∑ x : α, ∑ i : ι, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : α, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ - (d : ℝ) / 2 * ∑ x : α, w x := by - have h : 2 * (∑ i : ι, - min (w (R.users b i).1) (w (R.users b i).2)) ≤ - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), - min_le_right (w (R.users b i).1) (w (R.users b i).2)] - rw [switch_incidence_sum] at h - linarith -section Rotation -variable {A : ℕ} - -def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -omit [DecidableEq α] in -@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} - -noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) - (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -omit [DecidableEq α] in -lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : - Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (i : Fin A) (x : α) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -omit [DecidableEq α] in -lemma slotWeight_antitone (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -omit [DecidableEq α] in -lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : α, pathWeight o x = (A : ℝ) := by - classical - have he (x : α) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : - (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : α) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := R.entropy b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) - (z : Terminal o) : ℝ := - ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 - -lemma rotationCharge_mean_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound R b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound R o hn b - linarith - -lemma rotation_exp_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have hb := rotationCharge_mean_bound R hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -namespace QueryTree -open Thorp.QueryTree - -noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : - ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → - QueryTree (ι) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x - (fun y => seekCycle R S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) - (ω : ι → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle R S a r x V k).succeeds ω = true) : - (seekCycle R S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs - rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - -noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : - List (α × ℕ) → Finset (α) → QueryTree (ι) - | [], _ => accept - | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) - -lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) - (V : Finset (α)) (ω : ι → Bool) - (hs : (seekCycles R S L V).succeeds ω = true) : - (seekCycles R S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : - finiteMean (fun ω : ι → Bool => - if (seekCycles R S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles R S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge R S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree -noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : - Finset (ι) := - V.biUnion (fun x => R.path b x) - -@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : - exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := - (R.path b z ∩ exposedPaths R b V).card - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V W : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : - (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (S V : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (hS : orbitSet (R.perm ω) z ⊆ S) - (hV : Disjoint V (orbitSet (R.perm ω) z)) : - let p := R.perm ω - let W := V ∪ orbitSet p z - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -end RoutingNetwork -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.RotationMeeting + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter +section CycleCounting +variable {d A : ℕ} + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {d A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr + +end GroupedCounting + +section AllLengths +variable {d A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) + (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) + (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : + finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by + have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by + rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] + exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm + have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), + ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by + calc + _ = ((q-1)+1)^(F ω) := by congr 1; ring + _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by + rw [add_pow] + simp only [one_pow,mul_one] + _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by + apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) + intro a _ ha + have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega + rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [hc] + ring + simp_rw [hex,finiteMean_sum,finiteMean_mul_const] + calc + _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_right (hm a) (by positivity) + _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by + apply Finset.sum_congr rfl + intro a _ + rw [mul_pow] + ring + _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ + +lemma inv_sqrt_step (j : ℕ) : + 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by + have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) + apply (div_le_iff₀ hp).mpr + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) + have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) + nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] + +lemma sum_inv_sqrt (J : ℕ) : + (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by + have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ] + have hs := inv_sqrt_step n + push_cast + linarith + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] + exact h J +section CycleMGF +variable {d : ℕ} + +lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment S J + +end CycleMGF + +section FullCycleMGF +variable {d : ℕ} + +abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by + apply div_pos + · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty + · exact Nat.cast_pos.mpr Fintype.card_pos + +lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + +end FullCycleMGF + +structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] + [Fintype ι] [DecidableEq ι] (d : ℕ) where + perm : (ι → Bool) → Equiv.Perm α + path : (ι → Bool) → α → Finset ι + users : (ι → Bool) → ι → α × α + users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 + mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x + card_path : ∀ ω x, (path ω x).card = d + entropy : ∀ ω (S : Finset α), + (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) + follow : α → (α → QueryTree ι) → QueryTree ι + close : α → α → QueryTree ι → QueryTree ι + follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω + follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω + follow_stale_charge : ∀ x k R ω, + (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω + close_succeeds : ∀ x y k ω, + (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false + close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d + close_stale_charge : ∀ x y k R ω, perm ω x = y → + (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card + +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma card_switches_using (ω : ι → Bool) (x : α) : + (Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by + ext i + simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] + rw [he,R.card_path] +lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = + (d : ℝ) * ∑ x : α, w x := by + classical + calc + _ = ∑ i : ι, ∑ x : α, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : α => + (R.users b i).1 = x ∨ (R.users b i).2 = x) = + {(R.users b i).1, (R.users b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (R.users_ne b i)] + _ = ∑ x : α, ∑ i : ι, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : α, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ + (d : ℝ) / 2 * ∑ x : α, w x := by + have h : 2 * (∑ i : ι, + min (w (R.users b i).1) (w (R.users b i).2)) ≤ + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), + min_le_right (w (R.users b i).1) (w (R.users b i).2)] + rw [switch_incidence_sum] at h + linarith +section Rotation +variable {A : ℕ} + +def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +omit [DecidableEq α] in +@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} + +noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) + (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +omit [DecidableEq α] in +lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : + Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (i : Fin A) (x : α) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +omit [DecidableEq α] in +lemma slotWeight_antitone (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +omit [DecidableEq α] in +lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : α, pathWeight o x = (A : ℝ) := by + classical + have he (x : α) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : + (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : α) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := R.entropy b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) + (z : Terminal o) : ℝ := + ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 + +lemma rotationCharge_mean_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound R b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound R o hn b + linarith + +lemma rotation_exp_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have hb := rotationCharge_mean_bound R hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +namespace QueryTree +open Thorp.QueryTree + +noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : + ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → + QueryTree (ι) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x + (fun y => seekCycle R S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) + (ω : ι → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle R S a r x V k).succeeds ω = true) : + (seekCycle R S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs + rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + +noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : + List (α × ℕ) → Finset (α) → QueryTree (ι) + | [], _ => accept + | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) + +lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) + (V : Finset (α)) (ω : ι → Bool) + (hs : (seekCycles R S L V).succeeds ω = true) : + (seekCycles R S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : + finiteMean (fun ω : ι → Bool => + if (seekCycles R S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles R S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge R S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree +noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : + Finset (ι) := + V.biUnion (fun x => R.path b x) + +@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : + exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := + (R.path b z ∩ exposedPaths R b V).card + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V W : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : + (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (S V : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (hS : orbitSet (R.perm ω) z ⊆ S) + (hV : Disjoint V (orbitSet (R.perm ω) z)) : + let p := R.perm ω + let W := V ∪ orbitSet p z + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +end RoutingNetwork +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/BenesCoins.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/BenesCoins.lean index 8464dd8548ca2fed1284e2b1e402a55590491714..6f2905ba4afa5afd25bd3c063ccb6a1b6b4fa5a3 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/BenesCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/BenesCoins.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.AlternatingPerm - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - childLift p * childLift q = childLift (fun b => p b * q b) := by - ext x i - simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] - -lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl - -lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl - -lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * - pairSwitch coins.1 := by - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * - (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : - headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl - -lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : - headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl - -lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : - headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) - (headTailEquiv d x) := by - rw [palindromePerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by - obtain ⟨x,hx⟩ := C.nonempty - have hpx : alternatingPerm p x ∈ C.val := by - rw [←C.orbit_eq hx,mem_orbitSet] - exact (Equiv.Perm.SameCycle.refl _ _).apply_right - have hne : x ≠ alternatingPerm p x := by - intro he - have hh := congrArg Prod.fst he - rw [alternatingPerm_flip] at hh - cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh - have hs : {x,alternatingPerm p x} ⊆ C.val := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl <;> assumption - have hh := Finset.card_le_card hs - simpa only [Finset.card_pair hne] using hh - -lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : - 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by - classical - calc - _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] - _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := - Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) - _ ≤ _ := RoutingNetwork.cycleMass_le _ _ - -lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) - (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by - have h := alternating_cycle_count_double p S - omega - -end CycleColoring - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - 2 * alternatingCycles e p ≤ Fintype.card ι := by - have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) - simpa only [alternatingCycles, card_labelSet] using hh - -lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by - have hh := alternatingCycles_double e p - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : - colors x (chosenCoin x c) = c := by - funext i - simp only [colors,chosenCoin_apply x c hc i,required] - cases (x i).1 <;> cases c i <;> rfl - -noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : - ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) - -omit [Fintype α] [DecidableEq ι] in -lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - coloredEmbedding x c hc i = (c i,(x i).2) := by - apply Prod.ext - · exact congrFun (colors_chosenCoin x c hc) i - · rfl - -omit [Fintype α] [DecidableEq ι] in -lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) - (ξ : α → Bool) (he : colors x ξ = c) : - switchedEmbedding x ξ = coloredEmbedding x c hc := by - ext i : 1 - rw [coloredEmbedding_apply] - apply Prod.ext - · exact congrFun he i - · rfl - -lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - (compatibleSet x y).card ≤ - 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + - alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by - obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc - let ξ := chosenCoin x c - let η := chosenCoin y c - have he : routedEmbedding x ξ η p = y := by - ext i : 1 - have h := (sandwich_matches_iff ξ η p x y).mpr - ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by - simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ - exact h i - have hh := assignments_actual_bound x ξ η p - rw [he] at hh - rw [card_compatibleSet] - exact hh - -omit [Fintype α] [DecidableEq ι] in -lemma occupied_sum_ge (x y : ι ↪ Bool × α) : - Fintype.card ι ≤ (occupied x).card + (occupied y).card := by - have h₀ := occupied_card_double x - have h₁ := occupied_card_double y - omega - -lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ - (2:ℝ)^((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by - let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p - let b := (occupied x).card+(occupied y).card - let h := Fintype.card ι - have hb : h ≤ b := occupied_sum_ge x y - have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by - exact_mod_cast assignments_match_bound x y c hc p hm - change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) - rw [mul_one_div] - calc - _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) - _ = _ := by - rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] - congr 1 - rw [Nat.cast_add,Nat.cast_sub hb] - ring - -lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) - (a : ℝ) (ha : 0 ≤ a) : - (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ - (2:ℝ)^(((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by - have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) - (assignment_weight_bound x y c hc p hm) ha - rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), - ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h - simpa only [mul_comm] using h - - -lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, - if ChildMatches p x y c.val then W c.val else 0 := by - rw [sandwich_weighted_probability] - congr 1 - rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] - -omit [Fintype α] [DecidableEq α] [DecidableEq ι] in -lemma color_card_add (c : ι → Bool) : - Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by - have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by - cases c i <;> simp - rw [Fintype.card_congr he] - rw [Fintype.card_subtype_compl] - exact Nat.add_sub_of_le (Fintype.card_subtype_le _) - -end PairRouting - -noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) - (ω : BenesCoins d × BenesCoins d) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => palindromePerm d (if b then ω.2 else ω.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 - -lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : - palindromeCost (d+1) e σ = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) - (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by - unfold palindromeCost assignmentCost - dsimp only - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - -lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [palindromeCost_eq] - simp only [Equiv.apply_symm_apply] - -noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : BenesCoins d => - if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) - -lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma palindrome_matches_step (d : ℕ) {ι : Type*} - (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] - rfl - -lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (d+1)) (a : ℝ) : - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - routingMoment (d+1) e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have he (ω : BenesCoins d × BenesCoins d) : - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [palindrome_matches_step,palindromeCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold routingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = - (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (d+1)) : - PairRouting.tupleProbability (palindromePerm (d+1)) e f = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have hp (b : Bool) (p q : BenesCoins d) : - palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by - cases b <;> rfl - simp only [palindrome_matches_step,hp] - -lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) - rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh - have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = - -(d:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - rwa [he] at hh - -lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - -theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by - classical - induction d generalizing ι with - | zero => - have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := - fun _ _ => Subsingleton.elim _ _ - simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] - | succ d ih => - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) - have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha - rw [←palindrome_probability_step d e f] at hnode - change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) - ring - -lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : - (∑ f : ι ↪ Card d, routingMoment d e f a) = - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - unfold routingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] - (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : - finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = - (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] - rw [Real.rpow_add hn,Real.rpow_one] - field_simp - -noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card d => - ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) - -lemma density_normalization (d h n : ℕ) (a : ℝ) : - (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by - rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] - rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, - Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] - -theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - palindromeRowMoment d e a ≤ - (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card d) := ⟨e⟩ - rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * - ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, - Fintype.card_embedding_eq,card_positions] - norm_cast - -end Thorp -namespace Thorp - -lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] - (A : Finset α) (T : β → Finset α) : - (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = - ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by - classical - by_cases h : Finset.univ.biUnion T ⊆ A - · rw [ite_eq_left h] - symm - apply Finset.prod_eq_one - intro b _ - rw [ite_eq_left] - exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h - · rw [ite_eq_right h] - obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h - obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - rw [ite_eq_right] - exact fun hb => hxA (hb hxb) - -lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] - [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] - (F : Ω → Finset α) (p : α → ℝ) - (hF : CylinderBound (inclusionMoment F) p) - (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) - (hc : ∀ b s, 0 ≤ c b s) - (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : - finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ - ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by - classical - simp_rw [Fintype.prod_sum] - rw [finiteMean_sum] - apply Finset.sum_le_sum - intro s _ - let U := Finset.univ.biUnion (fun b => T b (s b)) - have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = - fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by - funext ω - rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] - exact mul_comm _ _ - rw [he,finiteMean_mul_const] - have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by - intro b _ b' _ hbb - exact hd b b' hbb (s b) (s b') - have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - by_cases hh : U ⊆ F ω <;> simp [hh] - calc - _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := - mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) - _ = _ := by - dsimp only [U] - rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro b _ - exact mul_comm _ _ - - -noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := - if T.card = 1 then 0 else w^T.card - -lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : - 0 ≤ sparseCoefficient w T := by - unfold sparseCoefficient - split_ifs <;> positivity - -lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) - (w : ℝ) (hw : 0 ≤ w) : - w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ - ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by - classical - let V := D ∩ A - let T : ↑D.powerset := if 2 ≤ V.card then - ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else - ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ - calc - _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by - by_cases h : 2 ≤ V.card - · have hn : V.card ≠ 1 := by omega - simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] - · simp [T,ite_eq_right h,sparseCoefficient,V] at * - _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => - sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) - (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) - (by split_ifs <;> norm_num)) (Finset.mem_univ T) - -lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : - ∑ i ∈ Finset.range n, x^i ≤ 2 := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ',pow_zero] - simp only [pow_succ',←Finset.mul_sum] - nlinarith - -lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : - ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ - 1 + 2*((R:ℝ)*z)^2 := by - classical - let x := (R:ℝ)*z - have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz - have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ - if i=1 then 0 else x^i := by - by_cases h : i=1 - · simp [h] - · simp only [ite_eq_right h] - dsimp [x] - rw [mul_pow] - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) - exact_mod_cast Nat.choose_le_pow R i - calc - _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := - Finset.sum_le_sum (fun i _ => hbound i) - _ ≤ 1+2*x^2 := by - rcases R with _ | R - · simp [x] - rcases R with _ | R - · norm_num [Finset.sum_range_succ] - positivity - have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = - 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by - rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] - have hn (i : ℕ) : 2+i ≠ 1 := by omega - simp only [hn,ite_false,pow_add,←Finset.mul_sum] - norm_num [Finset.sum_range_succ] - rw [he] - have hg := geometric_sum_half (R+1) hx hr - nlinarith [sq_nonneg x] - -lemma sparse_block_product_bound {α : Type*} [DecidableEq α] - (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : - ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ - Real.exp (2*((D.card:ℝ)*(p*w))^2) := by - classical - have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = - ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by - rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] - have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = - fun T => if T.card=1 then 0 else (p*w)^T.card := by - funext T - unfold sparseCoefficient - split_ifs <;> simp [mul_pow,mul_comm] - change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ - rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] - simp only [nsmul_eq_mul] - rw [he] - exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans - (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) - - -noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] - (D : β → Finset α) (A : Finset α) : ℕ := - ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 - -theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] - (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hF : ∀ T, inclusionMoment F T ≤ p^T.card) - (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : - finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by - classical - have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by - intro T - simpa only [Finset.prod_const] using hF T - have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc - (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) - (fun _ S => sparseCoefficient_nonneg w hw S.val) - (fun b b' h S S' => (hd h).mono - (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) - calc - _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, - sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by - apply finiteMean_mono - intro ω - rw [sparseMass,←Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) - intro b _ - exact sparse_block_pointwise (F ω) (D b) w hw - _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by - simpa only [Finset.prod_const] using hb - _ ≤ _ := by - rw [Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact Finset.sum_nonneg (fun S _ => mul_nonneg - (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) - · intro b _ - exact sparse_block_product_bound (D b) p w hp hw (hr b) - -theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] - (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) - (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : - finiteMean (fun ω : SwitchIndex d → Bool => - w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by - apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w - (by positivity) hw - · exact inverseButterflyMarks_inclusion d A - · exact hr - - -def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 - -lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by - unfold crowdedMass - split_ifs <;> omega - -lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by - unfold crowdedMass - split_ifs <;> omega - -lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by - unfold crowdedMass - split_ifs with h - · have hh := PairRouting.alternatingCycles_double e p - omega - · rw [PairRouting.alternatingCycles_zero e p (by omega)] - -lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by - classical - induction d generalizing ι with - | zero => simp [palindromeCost] - | succ d ih => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 - have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 - have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) - have hs := crowdedMass_add (Fintype.card {i // c i = false}) - (Fintype.card {i // c i = true}) - rw [PairRouting.color_card_add] at hs - change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ - nlinarith - -noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, ι, _, e, ω => - if d+1 ≤ H then crowdedMass (Fintype.card ι) else - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = palindromeCost d e ω := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLowCost,palindromeCost,ite_eq_left h] - congr 2 <;> exact ih (by omega) _ _ - -lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by - classical - induction d generalizing ι with - | zero => simp [palindromeLowCost,cutoffMass] - | succ d ih => - by_cases h : d+1 ≤ H - · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] - exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) - · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] - exact Nat.add_le_add (ih _ _) (ih _ _) - - -noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := - Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.AlternatingPerm + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + childLift p * childLift q = childLift (fun b => p b * q b) := by + ext x i + simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] + +lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl + +lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl + +lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * + pairSwitch coins.1 := by + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * + (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : + headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl + +lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : + headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl + +lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : + headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) + (headTailEquiv d x) := by + rw [palindromePerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by + obtain ⟨x,hx⟩ := C.nonempty + have hpx : alternatingPerm p x ∈ C.val := by + rw [←C.orbit_eq hx,mem_orbitSet] + exact (Equiv.Perm.SameCycle.refl _ _).apply_right + have hne : x ≠ alternatingPerm p x := by + intro he + have hh := congrArg Prod.fst he + rw [alternatingPerm_flip] at hh + cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh + have hs : {x,alternatingPerm p x} ⊆ C.val := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl <;> assumption + have hh := Finset.card_le_card hs + simpa only [Finset.card_pair hne] using hh + +lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : + 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by + classical + calc + _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] + _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := + Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) + _ ≤ _ := RoutingNetwork.cycleMass_le _ _ + +lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) + (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by + have h := alternating_cycle_count_double p S + omega + +end CycleColoring + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + 2 * alternatingCycles e p ≤ Fintype.card ι := by + have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) + simpa only [alternatingCycles, card_labelSet] using hh + +lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by + have hh := alternatingCycles_double e p + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : + colors x (chosenCoin x c) = c := by + funext i + simp only [colors,chosenCoin_apply x c hc i,required] + cases (x i).1 <;> cases c i <;> rfl + +noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : + ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) + +omit [Fintype α] [DecidableEq ι] in +lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + coloredEmbedding x c hc i = (c i,(x i).2) := by + apply Prod.ext + · exact congrFun (colors_chosenCoin x c hc) i + · rfl + +omit [Fintype α] [DecidableEq ι] in +lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) + (ξ : α → Bool) (he : colors x ξ = c) : + switchedEmbedding x ξ = coloredEmbedding x c hc := by + ext i : 1 + rw [coloredEmbedding_apply] + apply Prod.ext + · exact congrFun he i + · rfl + +lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + (compatibleSet x y).card ≤ + 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + + alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by + obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc + let ξ := chosenCoin x c + let η := chosenCoin y c + have he : routedEmbedding x ξ η p = y := by + ext i : 1 + have h := (sandwich_matches_iff ξ η p x y).mpr + ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by + simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ + exact h i + have hh := assignments_actual_bound x ξ η p + rw [he] at hh + rw [card_compatibleSet] + exact hh + +omit [Fintype α] [DecidableEq ι] in +lemma occupied_sum_ge (x y : ι ↪ Bool × α) : + Fintype.card ι ≤ (occupied x).card + (occupied y).card := by + have h₀ := occupied_card_double x + have h₁ := occupied_card_double y + omega + +lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ + (2:ℝ)^((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by + let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p + let b := (occupied x).card+(occupied y).card + let h := Fintype.card ι + have hb : h ≤ b := occupied_sum_ge x y + have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by + exact_mod_cast assignments_match_bound x y c hc p hm + change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) + rw [mul_one_div] + calc + _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by + rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] + congr 1 + rw [Nat.cast_add,Nat.cast_sub hb] + ring + +lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) + (a : ℝ) (ha : 0 ≤ a) : + (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ + (2:ℝ)^(((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by + have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) + (assignment_weight_bound x y c hc p hm) ha + rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), + ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h + simpa only [mul_comm] using h + + +lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, + if ChildMatches p x y c.val then W c.val else 0 := by + rw [sandwich_weighted_probability] + congr 1 + rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] + +omit [Fintype α] [DecidableEq α] [DecidableEq ι] in +lemma color_card_add (c : ι → Bool) : + Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by + have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by + cases c i <;> simp + rw [Fintype.card_congr he] + rw [Fintype.card_subtype_compl] + exact Nat.add_sub_of_le (Fintype.card_subtype_le _) + +end PairRouting + +noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) + (ω : BenesCoins d × BenesCoins d) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => palindromePerm d (if b then ω.2 else ω.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 + +lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : + palindromeCost (d+1) e σ = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) + (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by + unfold palindromeCost assignmentCost + dsimp only + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + +lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [palindromeCost_eq] + simp only [Equiv.apply_symm_apply] + +noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : BenesCoins d => + if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) + +lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma palindrome_matches_step (d : ℕ) {ι : Type*} + (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] + rfl + +lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (d+1)) (a : ℝ) : + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + routingMoment (d+1) e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have he (ω : BenesCoins d × BenesCoins d) : + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [palindrome_matches_step,palindromeCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold routingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = + (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (d+1)) : + PairRouting.tupleProbability (palindromePerm (d+1)) e f = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have hp (b : Bool) (p q : BenesCoins d) : + palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by + cases b <;> rfl + simp only [palindrome_matches_step,hp] + +lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) + rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh + have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = + -(d:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + rwa [he] at hh + +lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + +theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by + classical + induction d generalizing ι with + | zero => + have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := + fun _ _ => Subsingleton.elim _ _ + simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] + | succ d ih => + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) + have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha + rw [←palindrome_probability_step d e f] at hnode + change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) + ring + +lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : + (∑ f : ι ↪ Card d, routingMoment d e f a) = + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + unfold routingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] + (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : + finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = + (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] + rw [Real.rpow_add hn,Real.rpow_one] + field_simp + +noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card d => + ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) + +lemma density_normalization (d h n : ℕ) (a : ℝ) : + (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by + rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] + rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, + Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] + +theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + palindromeRowMoment d e a ≤ + (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card d) := ⟨e⟩ + rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * + ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, + Fintype.card_embedding_eq,card_positions] + norm_cast + +end Thorp +namespace Thorp + +lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] + (A : Finset α) (T : β → Finset α) : + (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = + ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by + classical + by_cases h : Finset.univ.biUnion T ⊆ A + · rw [ite_eq_left h] + symm + apply Finset.prod_eq_one + intro b _ + rw [ite_eq_left] + exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h + · rw [ite_eq_right h] + obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h + obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + rw [ite_eq_right] + exact fun hb => hxA (hb hxb) + +lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] + [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] + (F : Ω → Finset α) (p : α → ℝ) + (hF : CylinderBound (inclusionMoment F) p) + (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) + (hc : ∀ b s, 0 ≤ c b s) + (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : + finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ + ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by + classical + simp_rw [Fintype.prod_sum] + rw [finiteMean_sum] + apply Finset.sum_le_sum + intro s _ + let U := Finset.univ.biUnion (fun b => T b (s b)) + have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = + fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by + funext ω + rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] + exact mul_comm _ _ + rw [he,finiteMean_mul_const] + have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by + intro b _ b' _ hbb + exact hd b b' hbb (s b) (s b') + have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + by_cases hh : U ⊆ F ω <;> simp [hh] + calc + _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := + mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) + _ = _ := by + dsimp only [U] + rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro b _ + exact mul_comm _ _ + + +noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := + if T.card = 1 then 0 else w^T.card + +lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : + 0 ≤ sparseCoefficient w T := by + unfold sparseCoefficient + split_ifs <;> positivity + +lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) + (w : ℝ) (hw : 0 ≤ w) : + w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ + ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by + classical + let V := D ∩ A + let T : ↑D.powerset := if 2 ≤ V.card then + ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else + ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ + calc + _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by + by_cases h : 2 ≤ V.card + · have hn : V.card ≠ 1 := by omega + simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] + · simp [T,ite_eq_right h,sparseCoefficient,V] at * + _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => + sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) + (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) + (by split_ifs <;> norm_num)) (Finset.mem_univ T) + +lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : + ∑ i ∈ Finset.range n, x^i ≤ 2 := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ',pow_zero] + simp only [pow_succ',←Finset.mul_sum] + nlinarith + +lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : + ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ + 1 + 2*((R:ℝ)*z)^2 := by + classical + let x := (R:ℝ)*z + have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz + have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ + if i=1 then 0 else x^i := by + by_cases h : i=1 + · simp [h] + · simp only [ite_eq_right h] + dsimp [x] + rw [mul_pow] + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) + exact_mod_cast Nat.choose_le_pow R i + calc + _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := + Finset.sum_le_sum (fun i _ => hbound i) + _ ≤ 1+2*x^2 := by + rcases R with _ | R + · simp [x] + rcases R with _ | R + · norm_num [Finset.sum_range_succ] + positivity + have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = + 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by + rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] + have hn (i : ℕ) : 2+i ≠ 1 := by omega + simp only [hn,ite_false,pow_add,←Finset.mul_sum] + norm_num [Finset.sum_range_succ] + rw [he] + have hg := geometric_sum_half (R+1) hx hr + nlinarith [sq_nonneg x] + +lemma sparse_block_product_bound {α : Type*} [DecidableEq α] + (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : + ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ + Real.exp (2*((D.card:ℝ)*(p*w))^2) := by + classical + have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = + ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by + rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] + have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = + fun T => if T.card=1 then 0 else (p*w)^T.card := by + funext T + unfold sparseCoefficient + split_ifs <;> simp [mul_pow,mul_comm] + change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ + rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] + simp only [nsmul_eq_mul] + rw [he] + exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans + (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) + + +noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] + (D : β → Finset α) (A : Finset α) : ℕ := + ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 + +theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] + (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hF : ∀ T, inclusionMoment F T ≤ p^T.card) + (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : + finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by + classical + have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by + intro T + simpa only [Finset.prod_const] using hF T + have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc + (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) + (fun _ S => sparseCoefficient_nonneg w hw S.val) + (fun b b' h S S' => (hd h).mono + (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) + calc + _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, + sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by + apply finiteMean_mono + intro ω + rw [sparseMass,←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) + intro b _ + exact sparse_block_pointwise (F ω) (D b) w hw + _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by + simpa only [Finset.prod_const] using hb + _ ≤ _ := by + rw [Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact Finset.sum_nonneg (fun S _ => mul_nonneg + (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) + · intro b _ + exact sparse_block_product_bound (D b) p w hp hw (hr b) + +theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] + (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) + (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : + finiteMean (fun ω : SwitchIndex d → Bool => + w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by + apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w + (by positivity) hw + · exact inverseButterflyMarks_inclusion d A + · exact hr + + +def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 + +lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by + unfold crowdedMass + split_ifs <;> omega + +lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by + unfold crowdedMass + split_ifs <;> omega + +lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by + unfold crowdedMass + split_ifs with h + · have hh := PairRouting.alternatingCycles_double e p + omega + · rw [PairRouting.alternatingCycles_zero e p (by omega)] + +lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by + classical + induction d generalizing ι with + | zero => simp [palindromeCost] + | succ d ih => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 + have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 + have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + have hs := crowdedMass_add (Fintype.card {i // c i = false}) + (Fintype.card {i // c i = true}) + rw [PairRouting.color_card_add] at hs + change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ + nlinarith + +noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, ι, _, e, ω => + if d+1 ≤ H then crowdedMass (Fintype.card ι) else + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = palindromeCost d e ω := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLowCost,palindromeCost,ite_eq_left h] + congr 2 <;> exact ih (by omega) _ _ + +lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by + classical + induction d generalizing ι with + | zero => simp [palindromeLowCost,cutoffMass] + | succ d ih => + by_cases h : d+1 ≤ H + · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] + exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) + · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] + exact Nat.add_le_add (ih _ _) (ih _ _) + + +noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := + Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/BlockProduct.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/BlockProduct.lean index ec4091a6cc0fcddbcff9d4084e12056a4b18e56e..b8ad19552c2a1b8c7d04686ddbdc265042d3e7f8 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/BlockProduct.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/BlockProduct.lean @@ -1,894 +1,894 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.Representative - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by - induction s using Finset.induction_on with - | empty => - simp only [Finset.powerset_empty,Finset.sum_singleton] - exact Finset.noncommProd_empty _ _ - | @insert a s ha ih => - rw [Finset.sum_powerset_insert ha] - have h₁ (E : Finset ι) (hE : E∈s.powerset) : - sector P hcomm (insert a s) E=P a*sector P hcomm s E := by - rw [sector_insert P hcomm s E a ha] - congr 1 - exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) - have h₂ (E : Finset ι) (_hE : E∈s.powerset) : - sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by - rw [sector_insert P hcomm s (insert a E) a ha] - simp only [choice,Finset.mem_insert_self,↓reduceIte] - congr 1 - apply sector_congr - intro i hi - simp [ne_of_mem_of_not_mem hi ha] - rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, - ←Finset.mul_sum,←Finset.mul_sum,ih] - simp - -omit [Fintype ι] in -lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) - (hP : ∀ i, IsStarProjection (P i)) : - choice P E i*sector P hcomm s E=sector P hcomm s E := by - have hc : IsIdempotentElem (choice P E i) := by - unfold choice - split_ifs - · exact (hP i).one_sub.isIdempotentElem - · exact (hP i).isIdempotentElem - have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) - (fun i _ j _ _ => choice_commute P hcomm E E i j) - change choice P E i*sector P hcomm s E=sector P hcomm s E - change _=sector P hcomm s E at hsplit - nth_rw 1 [←hsplit] - rw [←mul_assoc,hc.eq,hsplit] - -omit [Fintype ι] in -lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) - (hP : ∀ i, IsStarProjection (P i)) : - sector P hcomm s E*sector P hcomm s F=0 := by - have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by - by_contra h - push Not at h - exact hEF (Finset.ext fun i => by - by_cases hi : i∈s - · exact h i hi - · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) - obtain ⟨i,hi,hdiff⟩ := hdiff - have hz : choice P E i*choice P F i=0 := by - by_cases he : i∈E <;> by_cases hf : i∈F - · exact (hdiff (iff_of_true he hf)).elim - · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self - · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self - · exact (hdiff (iff_of_false he hf)).elim - have hEi := sector_absorb_factor P hcomm s E i hi hP - have hFi := sector_absorb_factor P hcomm s F i hi hP - calc - _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by - simp only [mul_assoc] - rw [hFi] - rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] - _ = 0 := by rw [hz,mul_zero,zero_mul] - -noncomputable def blockProduct (A : ι → V →L[ℂ] V) - (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := - s.noncommProd A (fun i _ j _ _ => hA i j) - -omit hcomm [Fintype ι] in -lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by - induction s using Finset.induction_on with - | empty => exact ContinuousLinearMap.norm_id_le - | @insert a s ha ih => - have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,Finset.prod_insert ha] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) - -noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := - blockProduct A hA Finset.univ - -omit hcomm in -lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := - (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) - -omit [CompleteSpace V] in -lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : - Commute (blocks A hA) (sector P hcomm Finset.univ E) := by - unfold blocks blockProduct - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm - intro i _ - unfold sector - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm - intro j _ - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - -lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : - ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by - have hAC (i j : ι) : Commute (A i) (choice P E j) := by - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) - (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) - (fun i _ j _ _ => (hAC j i).symm) - change _=blocks A hA*sector P hcomm Finset.univ E at hprod - rw [←hprod] - have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := - ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) - apply (norm_noncommProd_le _ hc Finset.univ).trans - calc - _ ≤ ∏ i : ι, if i∈E then θ else 1 := by - apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) - intro i _ - dsimp only [Pi.mul_apply] - unfold choice - split_ifs with hi - · exact hgap i - · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) - _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] - -noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := - Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) - -lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - IsStarProjection (coarse P hcomm E) := by - have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by - apply Finset.noncommProd_congr rfl - intro i _ - simp [choice] - rw [he] - exact sector_projection P hcomm hP _ _ - -lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by - have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by - have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP - rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h - simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h - have hp (s : Finset ι) (hs : ∀ i∈s, - sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : - sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by - induction s using Finset.induction_on with - | empty => exact mul_one _ - | @insert a s ha ih => - have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] - exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) - exact hp Eᶜ hpi - -theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) - (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : - ‖B.adjoint*blocks A hA*B‖≤θ^n+ - ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) - (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) - hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) - (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) - (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all - -lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - ‖sampleOperator ρ P‖≤1 := by - rw [sampleOperator_weighted] - exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) - -omit [Fintype G] in -lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : - sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by - simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] - rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] - -omit [Fintype G] in -lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by - simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, - Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - apply Finset.sum_congr rfl - intro ξ _ - rw [mul_comm] - -omit [Fintype G] in -lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by - simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, - continuousRepresentation_adjoint ρ hρ] - -lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : - sampleOperator ρ (palindromePerm d)= - sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* - (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by - rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] - rfl - -omit [Fintype G] in -lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : - sampleOperator ρ (fun _ : Ω => 1)=1 := by - simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, - smul_smul] - rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by - simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, - Finset.smul_sum,id_eq] - -lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by - rw [sampleOperator_prod] - have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by - rw [←sampleOperator_uniform] - exact sampleOperator_equiv ρ id (Equiv.inv G) - rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteAverage -open scoped BigOperators Classical -variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] - [Ring A] [Algebra ℂ A] - -noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := - MultilinearMap.domDomCongr (Fintype.equivFin I).symm - (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) - -lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : - orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by - unfold orderedProduct - rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] - let l := List.ofFn (Fintype.equivFin I).symm - have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective - have hu : l.toFinset=Finset.univ := by - ext i - simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] - exact (Fintype.equivFin I).symm.surjective i - have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl - rw [hu] at he - rw [he] - congr 1 - exact List.map_ofFn.symm - -lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : - F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by - rw [F.map_smul_univ,F.map_sum] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] - -lemma ordered_average (x : I → Ω → A) - (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) - (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : - (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - (fun _ _ _ _ hij => havg hij))= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, - Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by - rw [←orderedProduct_eq _ havg,multilinear_average] - simp only [orderedProduct_eq _ (hc _)] - -end Thorp.FiniteAverage -namespace Thorp.FiniteCharacters -open Module -open scoped BigOperators Classical - -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) -include hneq hcard - -lemma character_expansion (f : ConjClasses G → ℂ) : - f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases h : i=j - · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] - · rw [ite_eq_right h,ite_eq_right (hneq i j h)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij; exact (horth i j).trans (ite_eq_right hij) - · intro i; simpa using horth i i - have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) - have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ - have hd (i : ι) : b.coord i=characterDual (ρ i) := by - apply b.ext - intro j - rw [hb,horth] - simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] - split_ifs <;> simp_all - have h := b.sum_repr f - simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm - -theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by - let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 - have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by - simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] - have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by - change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ - simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, - Representation.char_one,Nat.card_eq_fintype_card] - have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) - rw [hf,ite_eq_left rfl] at he - simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he - have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by - calc - _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * - (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - field_simp - _ = _ := by rw [←he,mul_one] - exact_mod_cast hs - -end Thorp.FiniteCharacters - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] - [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] - [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : - averageMap ρ σ A=0 := by - rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h - · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim - · exact h - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) - (u z : W) (v w : V) : - ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by - have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap - have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he - change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv - simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] - -def regularAction : G →* Equiv.Perm G where - toFun := Equiv.mulLeft - map_one' := by ext; simp - map_mul' _ _ := by ext; simp - -omit [Fintype G] in -lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by - intro g hg - have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg - subst g - simp - -noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := - normalizedCoefficient regularAction 1 regular_transitive ρ w v - -omit [FiniteDimensional ℂ V] in -lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : - regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by - unfold regularCoefficient normalizedCoefficient - simp only [PiLp.smul_apply,smul_eq_mul] - congr 1 - have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g - simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he - -lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (w z v t : V) : - inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := - normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z - (regular_fixed ρ w) (regular_fixed ρ z) v t - -variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) - (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, - inner_conj_symm] - have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z - calc - _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* - (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * - ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - _ = 0 := by rw [he,mul_zero] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteFourier -open scoped BigOperators ComplexConjugate Classical -open UnitaryFinite -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hρ : ∀ i, IsUnitary (ρ i)) -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) - - -abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) - -noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := - regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) - -omit [Fintype ι] in -include hρ hneq in -lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by - rw [orthonormal_iff_ite] - rintro ⟨i,a,b⟩ ⟨j,c,d⟩ - dsimp only [coefficientFamily] - by_cases hij : i=j - · subst j - rw [regularCoefficient_inner _ (hρ i)] - simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] - by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] - · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] - rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] - -include ρ hneq hcard in -lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by - simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] - exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard - -noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := - OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) - (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' - (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) - -lemma coefficientBasis_apply (a : CoefficientIndex V) : - coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a - -include hρ hneq hcard in - -theorem parseval (f : EuclideanSpace ℂ G) : - ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by - simpa only [coefficientBasis_apply] using - (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f - - -noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : - inner ℂ (coefficientFamily V ρ a) (realVector p)= - (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* - inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by - simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, - RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, - weightedOperator,sum_apply,smul_apply, - continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : - ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= - ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* - ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by - rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, - abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] - -include hρ hneq hcard in -lemma parseval_operator (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2= - ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←parseval V ρ hρ hneq hcard (realVector p)] - simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] - have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - have he (a : Fin (Module.finrank ℂ (V i))) : - (∑ b : Fin (Module.finrank ℂ (V i)), - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) - (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] - simp_rw [he] - rw [←Finset.mul_sum] - field_simp - -include hρ hneq hcard in -lemma realVector_bound (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2≤ - ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - rw [parseval_operator V ρ hρ hneq hcard] - apply Finset.sum_le_sum - intro i _ - calc - _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - apply Finset.sum_le_sum - intro a _ - apply pow_le_pow_left₀ (norm_nonneg _) - simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using - (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring - -include hρ hneq hcard in - -theorem l1_fourier_bound (p : G → ℝ) : - (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) - have he : ‖realVector p‖^2=∑ g,|p g|^2 := by - rw [EuclideanSpace.norm_sq_eq] - simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] - rw [he] - simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) - -end Thorp.FiniteFourier - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -variable {B X : Type*} - -def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where - toFun p := - { toFun := fun x => (x.1,p x.1 x.2) - invFun := fun x => (x.1,(p x.1).symm x.2) - left_inv := fun x => by simp - right_inv := fun x => by simp } - map_one' := rfl - map_mul' _ _ := rfl - -@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl - -noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := - lift.comp - { toFun := fun p c => if c=b then p else 1 - map_one' := by funext c; simp - map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } - -@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : - injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by - simp only [injection,MonoidHom.comp_apply,lift_apply] - by_cases h : x.1=b <;> simp [h] - -lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : - Commute (injection b p) (injection c q) := by - apply Equiv.ext - intro x - simp only [Equiv.Perm.mul_apply,injection_apply] - by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all - -variable [Fintype B] - -lemma lift_product (p : B → Equiv.Perm X) : - lift p=Finset.univ.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := by - have he (s : Finset B) (x : B × X) : - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) x= - (x.1,if x.1∈s then p x.1 x.2 else x.2) := by - induction s using Finset.induction_on with - | empty => - have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ - rw [hz]; simp - | @insert a s ha ih => - have hz : (insert a s).noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] - by_cases h : x.1=a - · subst a; simp [ha] - · simp [h] - apply Equiv.ext - intro x - rw [he] - simp - -end Thorp.ParallelBlocks -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H : Type*} [Group G] [Group H] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : - continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl - -lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : - sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl - -omit [FiniteDimensional ℂ V] in -lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : - IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w - -lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) - (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : - Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by - unfold sampleOperator - apply Commute.smul_left - apply Commute.smul_right - apply Commute.sum_left - intro ω _ - apply Commute.sum_right - intro ξ _ - exact (h ω ξ).map (continuousRepresentation ρ) - -lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] - (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by - rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype B] [DecidableEq B] in -lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) - (sampleOperator (ρ.comp (injection c)) (P c)) := by - by_cases h : b=c - · subst c; exact Commute.refl _ - · rw [sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) : - sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= - CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) - (local_average_commute ρ P) := by - let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) - have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by - intro ω b c h - exact (injection_commute h _ _).map (continuousRepresentation ρ) - have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by - intro b c _ - exact local_average_commute ρ P b c - have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= - Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by - rw [lift_product] - exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) - unfold sampleOperator - simp_rw [he] - exact (FiniteAverage.ordered_average A hc havg).symm - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical - -noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := - (cardSplit r L).permCongrHom - -noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : - Equiv.Perm (Card r × Card L) := - (Equiv.prodComm (Card L) (Card r)).permCongrHom - (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) - -lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : - outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl - -lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= - outerPerm r L hi*ParallelBlocks.lift - (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by - apply Equiv.ext - intro x - change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) - ((cardSplit r L).symm x))=_ - rw [butterfly_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r+1) → Bool) : - boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) - (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by - conv_lhs => unfold boundaryTree - congr 1 - funext b - cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : - boundaryOutput L (r+1) Y b= - boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by - conv_lhs => unfold boundaryOutput - cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : - cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= - let y := cardSplit r L x - let z := U y.1 y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) - have hh := ih U' lo' hi' (Fin.tail x) - let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) - let y := cardSplit r L (Fin.tail x) - let z := U' y.1 y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r L u=(w,z) at hh - rw [boundaryTree_node_raw] - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) - ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= - outerPerm r L hi*ParallelBlocks.lift U := by - apply Equiv.ext - intro x - change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm - ((cardSplit r L).symm x))=_ - rw [boundaryTree_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) (b : Card r) : - boundaryOutput L r (assembleBits r L lo hi) b= - butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by - induction r with - | zero => - rw [Subsingleton.elim b (fun j => Fin.elim0 j)] - rfl - | succ r ih => - rw [boundaryOutput_node_raw] - change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ - rw [ih] - simp only [Fin.cons_self_tail] - - -abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool -abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool - -def parallelSplitCoinEquiv (r L : ℕ) : - ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := - (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans - (splitCoinEquiv r L) - -lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : - parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by - exact splitCoinEquiv_apply _ _ _ _ - -def pairAssembleEquiv (B C H : Type*) : - ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where - toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) - invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) - left_inv _w := rfl - right_inv _w := rfl - -def palindromeStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := - (pairAssembleEquiv _ _ _).trans - (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) - -lemma palindromeStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - palindromeStageEquiv r L w= - (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by - simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] - -def modifiedAssembleEquiv (B C H U : Type*) : - ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where - toFun w := ((fun b => (w.1.2 b).1), - (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) - invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) - left_inv _w := rfl - right_inv _w := rfl - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.Representative + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by + induction s using Finset.induction_on with + | empty => + simp only [Finset.powerset_empty,Finset.sum_singleton] + exact Finset.noncommProd_empty _ _ + | @insert a s ha ih => + rw [Finset.sum_powerset_insert ha] + have h₁ (E : Finset ι) (hE : E∈s.powerset) : + sector P hcomm (insert a s) E=P a*sector P hcomm s E := by + rw [sector_insert P hcomm s E a ha] + congr 1 + exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) + have h₂ (E : Finset ι) (_hE : E∈s.powerset) : + sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by + rw [sector_insert P hcomm s (insert a E) a ha] + simp only [choice,Finset.mem_insert_self,↓reduceIte] + congr 1 + apply sector_congr + intro i hi + simp [ne_of_mem_of_not_mem hi ha] + rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, + ←Finset.mul_sum,←Finset.mul_sum,ih] + simp + +omit [Fintype ι] in +lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) + (hP : ∀ i, IsStarProjection (P i)) : + choice P E i*sector P hcomm s E=sector P hcomm s E := by + have hc : IsIdempotentElem (choice P E i) := by + unfold choice + split_ifs + · exact (hP i).one_sub.isIdempotentElem + · exact (hP i).isIdempotentElem + have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) + (fun i _ j _ _ => choice_commute P hcomm E E i j) + change choice P E i*sector P hcomm s E=sector P hcomm s E + change _=sector P hcomm s E at hsplit + nth_rw 1 [←hsplit] + rw [←mul_assoc,hc.eq,hsplit] + +omit [Fintype ι] in +lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) + (hP : ∀ i, IsStarProjection (P i)) : + sector P hcomm s E*sector P hcomm s F=0 := by + have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by + by_contra h + push Not at h + exact hEF (Finset.ext fun i => by + by_cases hi : i∈s + · exact h i hi + · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) + obtain ⟨i,hi,hdiff⟩ := hdiff + have hz : choice P E i*choice P F i=0 := by + by_cases he : i∈E <;> by_cases hf : i∈F + · exact (hdiff (iff_of_true he hf)).elim + · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self + · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self + · exact (hdiff (iff_of_false he hf)).elim + have hEi := sector_absorb_factor P hcomm s E i hi hP + have hFi := sector_absorb_factor P hcomm s F i hi hP + calc + _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by + simp only [mul_assoc] + rw [hFi] + rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] + _ = 0 := by rw [hz,mul_zero,zero_mul] + +noncomputable def blockProduct (A : ι → V →L[ℂ] V) + (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := + s.noncommProd A (fun i _ j _ _ => hA i j) + +omit hcomm [Fintype ι] in +lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by + induction s using Finset.induction_on with + | empty => exact ContinuousLinearMap.norm_id_le + | @insert a s ha ih => + have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,Finset.prod_insert ha] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) + +noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := + blockProduct A hA Finset.univ + +omit hcomm in +lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := + (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) + +omit [CompleteSpace V] in +lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : + Commute (blocks A hA) (sector P hcomm Finset.univ E) := by + unfold blocks blockProduct + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm + intro i _ + unfold sector + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm + intro j _ + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + +lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : + ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by + have hAC (i j : ι) : Commute (A i) (choice P E j) := by + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) + (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) + (fun i _ j _ _ => (hAC j i).symm) + change _=blocks A hA*sector P hcomm Finset.univ E at hprod + rw [←hprod] + have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := + ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) + apply (norm_noncommProd_le _ hc Finset.univ).trans + calc + _ ≤ ∏ i : ι, if i∈E then θ else 1 := by + apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) + intro i _ + dsimp only [Pi.mul_apply] + unfold choice + split_ifs with hi + · exact hgap i + · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) + _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] + +noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := + Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) + +lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + IsStarProjection (coarse P hcomm E) := by + have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by + apply Finset.noncommProd_congr rfl + intro i _ + simp [choice] + rw [he] + exact sector_projection P hcomm hP _ _ + +lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by + have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by + have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP + rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h + simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h + have hp (s : Finset ι) (hs : ∀ i∈s, + sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : + sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by + induction s using Finset.induction_on with + | empty => exact mul_one _ + | @insert a s ha ih => + have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] + exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) + exact hp Eᶜ hpi + +theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) + (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : + ‖B.adjoint*blocks A hA*B‖≤θ^n+ + ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) + (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) + hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) + (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) + (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all + +lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + ‖sampleOperator ρ P‖≤1 := by + rw [sampleOperator_weighted] + exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) + +omit [Fintype G] in +lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : + sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by + simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] + rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] + +omit [Fintype G] in +lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by + simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, + Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro ξ _ + rw [mul_comm] + +omit [Fintype G] in +lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by + simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, + continuousRepresentation_adjoint ρ hρ] + +lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : + sampleOperator ρ (palindromePerm d)= + sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* + (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by + rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] + rfl + +omit [Fintype G] in +lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : + sampleOperator ρ (fun _ : Ω => 1)=1 := by + simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, + smul_smul] + rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by + simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, + Finset.smul_sum,id_eq] + +lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by + rw [sampleOperator_prod] + have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by + rw [←sampleOperator_uniform] + exact sampleOperator_equiv ρ id (Equiv.inv G) + rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteAverage +open scoped BigOperators Classical +variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] + [Ring A] [Algebra ℂ A] + +noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := + MultilinearMap.domDomCongr (Fintype.equivFin I).symm + (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) + +lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : + orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by + unfold orderedProduct + rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] + let l := List.ofFn (Fintype.equivFin I).symm + have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective + have hu : l.toFinset=Finset.univ := by + ext i + simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] + exact (Fintype.equivFin I).symm.surjective i + have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl + rw [hu] at he + rw [he] + congr 1 + exact List.map_ofFn.symm + +lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : + F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by + rw [F.map_smul_univ,F.map_sum] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] + +lemma ordered_average (x : I → Ω → A) + (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) + (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : + (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + (fun _ _ _ _ hij => havg hij))= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, + Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by + rw [←orderedProduct_eq _ havg,multilinear_average] + simp only [orderedProduct_eq _ (hc _)] + +end Thorp.FiniteAverage +namespace Thorp.FiniteCharacters +open Module +open scoped BigOperators Classical + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) +include hneq hcard + +lemma character_expansion (f : ConjClasses G → ℂ) : + f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases h : i=j + · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] + · rw [ite_eq_right h,ite_eq_right (hneq i j h)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij; exact (horth i j).trans (ite_eq_right hij) + · intro i; simpa using horth i i + have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) + have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ + have hd (i : ι) : b.coord i=characterDual (ρ i) := by + apply b.ext + intro j + rw [hb,horth] + simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] + split_ifs <;> simp_all + have h := b.sum_repr f + simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm + +theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by + let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 + have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by + simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] + have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by + change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ + simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, + Representation.char_one,Nat.card_eq_fintype_card] + have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) + rw [hf,ite_eq_left rfl] at he + simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he + have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by + calc + _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * + (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + field_simp + _ = _ := by rw [←he,mul_one] + exact_mod_cast hs + +end Thorp.FiniteCharacters + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] + [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] + [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : + averageMap ρ σ A=0 := by + rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h + · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim + · exact h + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) + (u z : W) (v w : V) : + ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by + have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap + have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he + change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv + simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] + +def regularAction : G →* Equiv.Perm G where + toFun := Equiv.mulLeft + map_one' := by ext; simp + map_mul' _ _ := by ext; simp + +omit [Fintype G] in +lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by + intro g hg + have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg + subst g + simp + +noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := + normalizedCoefficient regularAction 1 regular_transitive ρ w v + +omit [FiniteDimensional ℂ V] in +lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : + regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by + unfold regularCoefficient normalizedCoefficient + simp only [PiLp.smul_apply,smul_eq_mul] + congr 1 + have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g + simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he + +lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (w z v t : V) : + inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := + normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z + (regular_fixed ρ w) (regular_fixed ρ z) v t + +variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) + (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, + inner_conj_symm] + have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z + calc + _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* + (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * + ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + _ = 0 := by rw [he,mul_zero] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteFourier +open scoped BigOperators ComplexConjugate Classical +open UnitaryFinite +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hρ : ∀ i, IsUnitary (ρ i)) +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) + + +abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) + +noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := + regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) + +omit [Fintype ι] in +include hρ hneq in +lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by + rw [orthonormal_iff_ite] + rintro ⟨i,a,b⟩ ⟨j,c,d⟩ + dsimp only [coefficientFamily] + by_cases hij : i=j + · subst j + rw [regularCoefficient_inner _ (hρ i)] + simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] + by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] + · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] + rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] + +include ρ hneq hcard in +lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by + simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] + exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard + +noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := + OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) + (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' + (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) + +lemma coefficientBasis_apply (a : CoefficientIndex V) : + coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a + +include hρ hneq hcard in + +theorem parseval (f : EuclideanSpace ℂ G) : + ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by + simpa only [coefficientBasis_apply] using + (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f + + +noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : + inner ℂ (coefficientFamily V ρ a) (realVector p)= + (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* + inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by + simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, + RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, + weightedOperator,sum_apply,smul_apply, + continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : + ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= + ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* + ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by + rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] + +include hρ hneq hcard in +lemma parseval_operator (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2= + ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←parseval V ρ hρ hneq hcard (realVector p)] + simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] + have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + have he (a : Fin (Module.finrank ℂ (V i))) : + (∑ b : Fin (Module.finrank ℂ (V i)), + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) + (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] + simp_rw [he] + rw [←Finset.mul_sum] + field_simp + +include hρ hneq hcard in +lemma realVector_bound (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2≤ + ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + rw [parseval_operator V ρ hρ hneq hcard] + apply Finset.sum_le_sum + intro i _ + calc + _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro a _ + apply pow_le_pow_left₀ (norm_nonneg _) + simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using + (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring + +include hρ hneq hcard in + +theorem l1_fourier_bound (p : G → ℝ) : + (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) + have he : ‖realVector p‖^2=∑ g,|p g|^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] + rw [he] + simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) + +end Thorp.FiniteFourier + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +variable {B X : Type*} + +def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where + toFun p := + { toFun := fun x => (x.1,p x.1 x.2) + invFun := fun x => (x.1,(p x.1).symm x.2) + left_inv := fun x => by simp + right_inv := fun x => by simp } + map_one' := rfl + map_mul' _ _ := rfl + +@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl + +noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := + lift.comp + { toFun := fun p c => if c=b then p else 1 + map_one' := by funext c; simp + map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } + +@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : + injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by + simp only [injection,MonoidHom.comp_apply,lift_apply] + by_cases h : x.1=b <;> simp [h] + +lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : + Commute (injection b p) (injection c q) := by + apply Equiv.ext + intro x + simp only [Equiv.Perm.mul_apply,injection_apply] + by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all + +variable [Fintype B] + +lemma lift_product (p : B → Equiv.Perm X) : + lift p=Finset.univ.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := by + have he (s : Finset B) (x : B × X) : + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) x= + (x.1,if x.1∈s then p x.1 x.2 else x.2) := by + induction s using Finset.induction_on with + | empty => + have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ + rw [hz]; simp + | @insert a s ha ih => + have hz : (insert a s).noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] + by_cases h : x.1=a + · subst a; simp [ha] + · simp [h] + apply Equiv.ext + intro x + rw [he] + simp + +end Thorp.ParallelBlocks +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H : Type*} [Group G] [Group H] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : + continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl + +lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : + sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl + +omit [FiniteDimensional ℂ V] in +lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : + IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w + +lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) + (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : + Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by + unfold sampleOperator + apply Commute.smul_left + apply Commute.smul_right + apply Commute.sum_left + intro ω _ + apply Commute.sum_right + intro ξ _ + exact (h ω ξ).map (continuousRepresentation ρ) + +lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] + (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by + rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype B] [DecidableEq B] in +lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) + (sampleOperator (ρ.comp (injection c)) (P c)) := by + by_cases h : b=c + · subst c; exact Commute.refl _ + · rw [sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) : + sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= + CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) + (local_average_commute ρ P) := by + let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) + have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by + intro ω b c h + exact (injection_commute h _ _).map (continuousRepresentation ρ) + have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by + intro b c _ + exact local_average_commute ρ P b c + have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= + Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by + rw [lift_product] + exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) + unfold sampleOperator + simp_rw [he] + exact (FiniteAverage.ordered_average A hc havg).symm + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical + +noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := + (cardSplit r L).permCongrHom + +noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : + Equiv.Perm (Card r × Card L) := + (Equiv.prodComm (Card L) (Card r)).permCongrHom + (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) + +lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : + outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl + +lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= + outerPerm r L hi*ParallelBlocks.lift + (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by + apply Equiv.ext + intro x + change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) + ((cardSplit r L).symm x))=_ + rw [butterfly_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r+1) → Bool) : + boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) + (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by + conv_lhs => unfold boundaryTree + congr 1 + funext b + cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : + boundaryOutput L (r+1) Y b= + boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by + conv_lhs => unfold boundaryOutput + cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : + cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= + let y := cardSplit r L x + let z := U y.1 y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) + have hh := ih U' lo' hi' (Fin.tail x) + let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) + let y := cardSplit r L (Fin.tail x) + let z := U' y.1 y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r L u=(w,z) at hh + rw [boundaryTree_node_raw] + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) + ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= + outerPerm r L hi*ParallelBlocks.lift U := by + apply Equiv.ext + intro x + change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm + ((cardSplit r L).symm x))=_ + rw [boundaryTree_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) (b : Card r) : + boundaryOutput L r (assembleBits r L lo hi) b= + butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by + induction r with + | zero => + rw [Subsingleton.elim b (fun j => Fin.elim0 j)] + rfl + | succ r ih => + rw [boundaryOutput_node_raw] + change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ + rw [ih] + simp only [Fin.cons_self_tail] + + +abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool +abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool + +def parallelSplitCoinEquiv (r L : ℕ) : + ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := + (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans + (splitCoinEquiv r L) + +lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : + parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by + exact splitCoinEquiv_apply _ _ _ _ + +def pairAssembleEquiv (B C H : Type*) : + ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where + toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) + invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) + left_inv _w := rfl + right_inv _w := rfl + +def palindromeStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := + (pairAssembleEquiv _ _ _).trans + (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) + +lemma palindromeStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + palindromeStageEquiv r L w= + (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by + simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] + +def modifiedAssembleEquiv (B C H U : Type*) : + ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where + toFun w := ((fun b => (w.1.2 b).1), + (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) + invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) + left_inv _w := rfl + right_inv _w := rfl + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/Coins.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/Coins.lean index cbf202901ae6254a459188acb806a1e557372a2d..34618abd78f0363c3f030d1b4e2d037c108fb29c 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/Coins.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/Coins.lean @@ -1,767 +1,767 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.Model - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -open scoped BigOperators -open Filter - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Card d → Bool - -instance (d : ℕ) : Fintype (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -instance (d : ℕ) : Nonempty (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -def rotate (d : ℕ) : Equiv.Perm (Card d) where - toFun x i := x (finRotate d i) - invFun x i := x ((finRotate d).symm i) - left_inv x := by funext i; simp only [Equiv.apply_symm_apply] - right_inv x := by funext i; simp only [Equiv.symm_apply_apply] - -def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, ξ => rotate (d + 1) * pairSwitch ξ - -def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) - | 0, _ => 1 - | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) - -noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := - (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / - (Fintype.card (Fin t → Coins d) : ℝ) - -noncomputable def distance (d t : ℕ) : ℝ := - (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| - -noncomputable def mixingTime (d : ℕ) : ℕ := - sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} - -noncomputable def supportTimeBound (d : ℕ) : ℤ := - ⌈(2 / (2 : ℝ) ^ d) * - (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ - -def OptimalOrder : Prop := - ∃ C : ℕ, 0 < C ∧ - Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ - (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ - (∀ᶠ d : ℕ in atTop, - supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ - (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) - -noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by - classical - exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) - -lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : - ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by - classical - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : - 0 ≤ finiteLaw f b := by - exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - -lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : - ∑ b, finiteLaw f b = 1 := by - classical - simp only [finiteLaw, ← Finset.sum_div] - have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by - exact_mod_cast sum_card_fibers f - rw [hc] - exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by - classical - have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr - ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ - simp [finiteLaw] - -lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] - (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : - (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by - have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := - Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) - have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) - have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) - have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) - rw [hpq] at hz - rw [← Finset.sum_sub_distrib] - linarith - -lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] - [Fintype β] [Nonempty β] (f : α → β) : - 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ - (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by - classical - let s := Finset.univ.image f - have hs : ∑ b ∈ s, finiteLaw f b = 1 := by - have h := Finset.sum_subset (Finset.subset_univ s) - (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) - simpa only [finiteLaw_sum] using h - have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] - have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by - rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] - have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s - rw [hs] at he - have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by - simp [div_eq_mul_inv] - rw [hsq] at he - have hcard : (s.card : ℝ) ≤ Fintype.card α := by - exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) - have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) - linarith - -lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by - simp [Card] - -lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by - rw [Fintype.card_perm, card_positions] - -lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by - rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] - -lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : - law d t g = finiteLaw (run d t) g := by - unfold law finiteLaw - apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) - exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) - -lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by - rw [law_eq_finiteLaw] - exact finiteLaw_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by - simp only [law_eq_finiteLaw] - exact finiteLaw_sum (run d t) - -lemma physical_support_bound_succ (d t : ℕ) : - 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by - have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ - have h := finiteLaw_support_bound (run (d + 1) t) - rw [card_tapes_succ, card_permutations] at h - simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h - -lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : - step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by - change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ - rw [Fin.snoc_eq_cons_rotate] - rfl - -lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by - unfold distance - exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - -lemma physical_support_bound (d t : ℕ) : - 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by - cases d with - | zero => - have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) - simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using - le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) - | succ d => - have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by - push_cast - rw [pow_succ] - ring - rw [he, Real.rpow_natCast] - exact physical_support_bound_succ d t - -lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : - supportTimeBound d ≤ (t : ℤ) := by - have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity - have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity - have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) - have hb := physical_support_bound d t - have hp : (3 / 4 : ℝ) ≤ - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by - linarith - have hr := (le_div_iff₀ hF).mp hp - have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr - rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog - unfold supportTimeBound - apply Int.ceil_le.mpr - simp only [Int.cast_natCast] - calc - 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = - Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by - field_simp - _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by - nlinarith [hlog]) - -lemma supportTimeBound_le_mixingTime {d : ℕ} - (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : - supportTimeBound d ≤ (mixingTime d : ℤ) := by - exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) - -lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : - (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by - have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) - have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) - have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by - have := Real.pi_gt_three - linarith) - linarith - -lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) - have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by - rw [← Real.log_inv] - congr 1 - norm_num - rw [he] at h - linarith - -lemma linear_le_supportTimeBound (d : ℕ) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by - have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) - have hNp : 0 < (2 : ℝ) ^ d := by positivity - have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) - have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - rw [Real.log_mul (by norm_num) (by positivity)] - push_cast at hf - rw [Real.log_pow] at hf - linarith [log_three_quarters_lower] - apply le_trans _ (Int.le_ceil _) - have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) = - (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by - field_simp - ring - rw [hcancel] - linarith - convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 - field_simp - -lemma linear_le_time_of_distance_le (d t : ℕ) - (ht : distance d t ≤ (1 / 4 : ℝ)) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by - have h := supportTimeBound_le_of_distance_le d t ht - have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h - exact (linear_le_supportTimeBound d).trans hr - -lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : - 2 * p * Real.log 2 ≤ Real.binEntropy p := by - have hc := Real.strictConcave_binEntropy.concaveOn.2 - (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show 0 ≤ 1 - 2 * p by linarith) - (show 0 ≤ 2 * p by positivity) - (show (1 - 2 * p) + 2 * p = 1 by ring) - simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, - smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc - -lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : - 2 * min a b * Real.log 2 ≤ - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - wlog hab : a ≤ b generalizing a b - · have hba := this b a hb ha (le_of_not_ge hab) - simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) - rw [min_eq_left hab] - by_cases hz : a = 0 - · subst a - simp - have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) - have hbp : 0 < b := hap.trans_le hab - have hs : 0 < a + b := add_pos hap hbp - have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le - have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) - have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le - have he : (a + b) * Real.binEntropy (a / (a + b)) = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - unfold Real.binEntropy - rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] - simp only [Real.log_inv] - rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), - Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] - field_simp - ring - rw [he] at hc - calc - 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by - field_simp - _ ≤ _ := hc - -noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail - -lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by - classical - unfold childMarks - apply Finset.card_image_iff.mpr - intro x hx y hy hxy - have hx0 := (Finset.mem_filter.mp hx).2 - have hy0 := (Finset.mem_filter.mp hy).2 - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] - -lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : - (childMarks s false).card + (childMarks s true).card = s.card := by - classical - rw [card_childMarks, card_childMarks] - simpa only [Bool.not_eq_false] using - (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) - -noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) : Finset (Card d) := - ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ - ((childMarks s true).image (butterflyPerm d (b.2 true))) - -lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : - (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by - classical - apply le_min - · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) - · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) - -noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ - | 0, _, _ => 0 - | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card - -lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - induction d with - | zero => - simp only [encounters, Nat.cast_zero] - have hs : s.card ≤ 1 := by - simpa [Card] using Finset.card_le_univ s - interval_cases s.card <;> simp - | succ d ih => - have h₀ := ih (b.2 false) (childMarks s false) - have h₁ := ih (b.2 true) (childMarks s true) - have ht : ((topMeetings b s).card : ℝ) ≤ - min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by - exact_mod_cast card_topMeetings_le b s - have he := split_entropy_lower ((childMarks s false).card : ℝ) - ((childMarks s true).card : ℝ) (by positivity) (by positivity) - have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by - exact_mod_cast card_childMarks_add s - rw [hs] at he - have hL : 0 < 2 * Real.log 2 := by positivity - rw [le_div_iff₀ hL] at h₀ h₁ ⊢ - simp only [encounters, Nat.cast_add] - nlinarith [mul_le_mul_of_nonneg_right ht hL.le] - -lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by - by_cases ha : a ∈ s - · rw [ite_eq_left ha] - exact (Finset.mul_prod_erase s f ha).symm - · simp [ha] - -lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) - (a b : α) (hab : a ≠ b) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * - ∏ i ∈ (s.erase a).erase b, f i := by - calc - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := - prod_split_at s f a - _ = _ := by - rw [prod_split_at (s.erase a) f b] - have hm : (b ∈ s.erase a) ↔ b ∈ s := - ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ - simp only [hm, mul_assoc] - -lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ - ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by - by_cases hab : a = b - · subst b - simp only [Equiv.swap_self, Equiv.refl_apply] - have h : (fun i => (p i + p i) / 2) = p := by funext i; ring - rw [h] - linarith - let t := (s.erase a).erase b - have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by - intro i hi - exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) - have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) - rw [prod_split_two s p a b hab, - prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, - prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] - change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + - (if a ∈ s then p (Equiv.swap a b a) else 1) * - (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ - rw [hprod] - change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * - (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * - (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) - rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] - have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) - by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] - · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht - nlinarith - all_goals ring_nf; rfl - -def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := - ∀ s, m s ≤ ∏ i ∈ s, p i - -lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] - {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) - (fun i => (p i + p (Equiv.swap a b i)) / 2) := by - intro s - have h₀ := h s - have h₁ := h (s.image (Equiv.swap a b)) - rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ - exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans - (swap_average_product s p hp a b) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : ℝ := by - classical - exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) - -lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by - classical - unfold inclusionMoment finiteMean - positivity - -lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : - (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by - by_cases h : s ⊆ A - · rw [ite_eq_left h] - exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm - · rw [ite_eq_right h] - obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h - exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm - -lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] - (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = - if s ⊆ A then 1 else 0 := by - classical - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] - -lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : - CylinderBound (inclusionMoment (fun _ : Ω => A)) - (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by - classical - intro s - simp only [inclusionMoment_const, Finset.singleton_subset_iff] - exact (indicator_subset_prod A s).le - -noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] - (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := - fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 - -lemma subset_swap_image_iff {α : Type*} [DecidableEq α] - (A s : Finset α) (a b : α) : - s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by - constructor - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - -lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) (s : Finset α) : - inclusionMoment (fairSetSwap F a b) s = - (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by - classical - simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, - fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, - Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] - rw [div_mul_eq_div_div, add_div] - ring_nf - -lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) - (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : - CylinderBound (inclusionMoment (fairSetSwap F a b)) - (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by - classical - have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b - intro s - simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s - -def SwitchSamples : ℕ → Type - | 0 => Unit - | n + 1 => SwitchSamples n × Bool - -instance (n : ℕ) : Fintype (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Fintype Unit) - | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) - -instance (n : ℕ) : Nonempty (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Nonempty Unit) - | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) - -noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : - (L : List (α × α)) → SwitchSamples L.length → Finset α - | [], _ => A - | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω - -lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) - (L : List (α × α)) : - CylinderBound (inclusionMoment (switchedSet A L)) - (fun i => inclusionMoment (switchedSet A L) {i}) := by - induction L with - | nil => exact cylinder_const A - | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih - -inductive QueryTree (ι : Type*) - | reject : QueryTree ι - | accept : QueryTree ι - | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι - | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι - -namespace QueryTree - -variable {ι : Type*} [DecidableEq ι] - -def queries : QueryTree ι → Finset ι - | reject => ∅ - | accept => ∅ - | branch i zero one => insert i (queries zero ∪ queries one) - | force i _ next => insert i (queries next) - -def Fresh : QueryTree ι → Prop - | reject => True - | accept => True - | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one - | force i _ next => i ∉ queries next ∧ Fresh next - -def weighted : QueryTree ι → (ι → Bool) → ℝ - | reject, _ => 0 - | accept, _ => 1 - | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω - | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 - -omit [DecidableEq ι] in -lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by - induction T with - | reject => exact le_rfl - | accept => exact zero_le_one - | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ - | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl - -lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} - (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by - induction T with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), - ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] - | force i b next ih => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] - -def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := - (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by - intro ω - funext j - by_cases h : j = i - · subst j; simp - · simp [Function.update_of_ne h]).toPerm - -lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by - change Function.update ω i (!(ω i)) i = _ - exact Function.update_self _ _ _ - -lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : - flipCoin i ω j = ω j := by - change Function.update ω i (!(ω i)) j = _ - exact Function.update_of_ne h _ _ - -lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) - (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by - apply weighted_congr - intro j hj - exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω - -lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) - (hf : ∀ ω, f (flipCoin i ω) = f ω) : - finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by - let g := fun ω : ι → Bool => if ω i = b then f ω else 0 - have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by - dsimp [g] - rw [flipCoin_apply_eq, hf] - cases hω : ω i <;> cases b <;> simp - have hs := Equiv.sum_comp (flipCoin i) g - have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun ω _ => hp ω) - unfold finiteMean - change (∑ ω, g ω) / _ = _ - rw [hs] at hadd - have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith - rw [hh] - ring - -lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : - finiteMean T.weighted ≤ 1 := by - induction T with - | reject => simp [weighted, finiteMean] - | accept => simp [weighted, finiteMean] - | branch i zero one ih₀ ih₁ => - obtain ⟨hz, ho, hfz, hfo⟩ := hT - have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) - have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) - have he : finiteMean (branch i zero one).weighted = - finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + - finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by - unfold finiteMean - rw [← add_div, ← Finset.sum_add_distrib] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - cases hω : ω i <;> simp [weighted, hω] - rw [he, h₀, h₁] - linarith [ih₀ hfz, ih₁ hfo] - | force i b next ih => - obtain ⟨hi, hn⟩ := hT - have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) - have he : finiteMean (force i b next).weighted = - 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by - unfold finiteMean - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : ω i = b <;> simp [weighted, h] - rw [he, hm] - linarith [ih hn] - -def succeeds : QueryTree ι → (ι → Bool) → Bool - | reject, _ => false - | accept, _ => true - | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω - | force i b next, ω => if ω i = b then succeeds next ω else false - -def charge : QueryTree ι → (ι → Bool) → ℕ - | reject, _ => 0 - | accept, _ => 0 - | branch i zero one, ω => if ω i then charge one ω else charge zero ω - | force i b next, ω => if ω i = b then charge next ω + 1 else 0 - -omit [DecidableEq ι] in -lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : - T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by - induction T with - | reject => rfl - | accept => norm_num [weighted, succeeds, charge] - | branch i zero one ih₀ ih₁ => - cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] - | force i b next ih => - by_cases h : ω i = b - · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] - cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] - · simp [weighted, succeeds, h] - -lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) - (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : - finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by - have hw (ω : ι → Bool) : - (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by - rw [weighted_eq] - cases hs : T.succeeds ω - · simp - · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) - have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ - have hm := div_le_div_of_nonneg_right - (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn - rw [← Finset.mul_sum, mul_div_assoc] at hm - change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ - finiteMean T.weighted at hm - exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by - rw [mul_comm] - exact hm.trans (mean_weighted_le_one T hT)) - -end QueryTree - -def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool - | 0, _, i => nomatch i - | _d + 1, b, Sum.inl y => b.1 y - | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i - -lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : - decodeButterfly d (encodeButterfly d b) = b := by - induction d with - | zero => exact Unit.ext _ _ - | succ d ih => - apply Prod.ext - · rfl - · funext ε - exact ih (b.2 ε) - -lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : - encodeButterfly d (decodeButterfly d ω) = ω := by - induction d with - | zero => funext i; exact Empty.elim i - | succ d ih => - funext i - cases i with - | inl y => rfl - | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 - -def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where - toFun := decodeButterfly d - invFun := encodeButterfly d - left_inv := encode_decodeButterfly d - right_inv := decode_encodeButterfly d - -noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) - | 0, _, _ => ∅ - | d + 1, x, y => by - classical - exact insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) - -def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool - | 0, _, _, i => nomatch i - | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) - | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.Model + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +open scoped BigOperators +open Filter + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Card d → Bool + +instance (d : ℕ) : Fintype (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +instance (d : ℕ) : Nonempty (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +def rotate (d : ℕ) : Equiv.Perm (Card d) where + toFun x i := x (finRotate d i) + invFun x i := x ((finRotate d).symm i) + left_inv x := by funext i; simp only [Equiv.apply_symm_apply] + right_inv x := by funext i; simp only [Equiv.symm_apply_apply] + +def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, ξ => rotate (d + 1) * pairSwitch ξ + +def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) + | 0, _ => 1 + | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) + +noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := + (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / + (Fintype.card (Fin t → Coins d) : ℝ) + +noncomputable def distance (d t : ℕ) : ℝ := + (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| + +noncomputable def mixingTime (d : ℕ) : ℕ := + sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} + +noncomputable def supportTimeBound (d : ℕ) : ℤ := + ⌈(2 / (2 : ℝ) ^ d) * + (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ + +def OptimalOrder : Prop := + ∃ C : ℕ, 0 < C ∧ + Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ + (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ + (∀ᶠ d : ℕ in atTop, + supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ + (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) + +noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by + classical + exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) + +lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : + ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by + classical + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : + 0 ≤ finiteLaw f b := by + exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : + ∑ b, finiteLaw f b = 1 := by + classical + simp only [finiteLaw, ← Finset.sum_div] + have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by + exact_mod_cast sum_card_fibers f + rw [hc] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by + classical + have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr + ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ + simp [finiteLaw] + +lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] + (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : + (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by + have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := + Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) + have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) + have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) + have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) + rw [hpq] at hz + rw [← Finset.sum_sub_distrib] + linarith + +lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] + [Fintype β] [Nonempty β] (f : α → β) : + 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ + (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by + classical + let s := Finset.univ.image f + have hs : ∑ b ∈ s, finiteLaw f b = 1 := by + have h := Finset.sum_subset (Finset.subset_univ s) + (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) + simpa only [finiteLaw_sum] using h + have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] + have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by + rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] + have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s + rw [hs] at he + have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by + simp [div_eq_mul_inv] + rw [hsq] at he + have hcard : (s.card : ℝ) ≤ Fintype.card α := by + exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) + have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) + linarith + +lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by + simp [Card] + +lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by + rw [Fintype.card_perm, card_positions] + +lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by + rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] + +lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : + law d t g = finiteLaw (run d t) g := by + unfold law finiteLaw + apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) + exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) + +lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by + rw [law_eq_finiteLaw] + exact finiteLaw_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by + simp only [law_eq_finiteLaw] + exact finiteLaw_sum (run d t) + +lemma physical_support_bound_succ (d t : ℕ) : + 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by + have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ + have h := finiteLaw_support_bound (run (d + 1) t) + rw [card_tapes_succ, card_permutations] at h + simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h + +lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : + step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by + change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ + rw [Fin.snoc_eq_cons_rotate] + rfl + +lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by + unfold distance + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + +lemma physical_support_bound (d t : ℕ) : + 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by + cases d with + | zero => + have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) + simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using + le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) + | succ d => + have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by + push_cast + rw [pow_succ] + ring + rw [he, Real.rpow_natCast] + exact physical_support_bound_succ d t + +lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : + supportTimeBound d ≤ (t : ℤ) := by + have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity + have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hb := physical_support_bound d t + have hp : (3 / 4 : ℝ) ≤ + (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by + linarith + have hr := (le_div_iff₀ hF).mp hp + have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr + rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog + unfold supportTimeBound + apply Int.ceil_le.mpr + simp only [Int.cast_natCast] + calc + 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = + Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by + field_simp + _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by + nlinarith [hlog]) + +lemma supportTimeBound_le_mixingTime {d : ℕ} + (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : + supportTimeBound d ≤ (mixingTime d : ℤ) := by + exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) + +lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : + (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by + have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) + have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) + have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by + have := Real.pi_gt_three + linarith) + linarith + +lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) + have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by + rw [← Real.log_inv] + congr 1 + norm_num + rw [he] at h + linarith + +lemma linear_le_supportTimeBound (d : ℕ) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by + have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) + have hNp : 0 < (2 : ℝ) ^ d := by positivity + have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) + have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + rw [Real.log_mul (by norm_num) (by positivity)] + push_cast at hf + rw [Real.log_pow] at hf + linarith [log_three_quarters_lower] + apply le_trans _ (Int.le_ceil _) + have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) = + (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by + field_simp + ring + rw [hcancel] + linarith + convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 + field_simp + +lemma linear_le_time_of_distance_le (d t : ℕ) + (ht : distance d t ≤ (1 / 4 : ℝ)) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by + have h := supportTimeBound_le_of_distance_le d t ht + have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h + exact (linear_le_supportTimeBound d).trans hr + +lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc := Real.strictConcave_binEntropy.concaveOn.2 + (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show 0 ≤ 1 - 2 * p by linarith) + (show 0 ≤ 2 * p by positivity) + (show (1 - 2 * p) + 2 * p = 1 by ring) + simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, + smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc + +lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + wlog hab : a ≤ b generalizing a b + · have hba := this b a hb ha (le_of_not_ge hab) + simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) + rw [min_eq_left hab] + by_cases hz : a = 0 + · subst a + simp + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) + have hbp : 0 < b := hap.trans_le hab + have hs : 0 < a + b := add_pos hap hbp + have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le + have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) + have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le + have he : (a + b) * Real.binEntropy (a / (a + b)) = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + unfold Real.binEntropy + rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] + simp only [Real.log_inv] + rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), + Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] + field_simp + ring + rw [he] at hc + calc + 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by + field_simp + _ ≤ _ := hc + +noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail + +lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by + classical + unfold childMarks + apply Finset.card_image_iff.mpr + intro x hx y hy hxy + have hx0 := (Finset.mem_filter.mp hx).2 + have hy0 := (Finset.mem_filter.mp hy).2 + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] + +lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : + (childMarks s false).card + (childMarks s true).card = s.card := by + classical + rw [card_childMarks, card_childMarks] + simpa only [Bool.not_eq_false] using + (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) + +noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) : Finset (Card d) := + ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ + ((childMarks s true).image (butterflyPerm d (b.2 true))) + +lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : + (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by + classical + apply le_min + · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) + · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) + +noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ + | 0, _, _ => 0 + | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card + +lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + induction d with + | zero => + simp only [encounters, Nat.cast_zero] + have hs : s.card ≤ 1 := by + simpa [Card] using Finset.card_le_univ s + interval_cases s.card <;> simp + | succ d ih => + have h₀ := ih (b.2 false) (childMarks s false) + have h₁ := ih (b.2 true) (childMarks s true) + have ht : ((topMeetings b s).card : ℝ) ≤ + min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by + exact_mod_cast card_topMeetings_le b s + have he := split_entropy_lower ((childMarks s false).card : ℝ) + ((childMarks s true).card : ℝ) (by positivity) (by positivity) + have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by + exact_mod_cast card_childMarks_add s + rw [hs] at he + have hL : 0 < 2 * Real.log 2 := by positivity + rw [le_div_iff₀ hL] at h₀ h₁ ⊢ + simp only [encounters, Nat.cast_add] + nlinarith [mul_le_mul_of_nonneg_right ht hL.le] + +lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by + by_cases ha : a ∈ s + · rw [ite_eq_left ha] + exact (Finset.mul_prod_erase s f ha).symm + · simp [ha] + +lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) + (a b : α) (hab : a ≠ b) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * + ∏ i ∈ (s.erase a).erase b, f i := by + calc + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := + prod_split_at s f a + _ = _ := by + rw [prod_split_at (s.erase a) f b] + have hm : (b ∈ s.erase a) ↔ b ∈ s := + ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ + simp only [hm, mul_assoc] + +lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ + ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by + by_cases hab : a = b + · subst b + simp only [Equiv.swap_self, Equiv.refl_apply] + have h : (fun i => (p i + p i) / 2) = p := by funext i; ring + rw [h] + linarith + let t := (s.erase a).erase b + have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by + intro i hi + exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) + have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) + rw [prod_split_two s p a b hab, + prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, + prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] + change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + + (if a ∈ s then p (Equiv.swap a b a) else 1) * + (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ + rw [hprod] + change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * + (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * + (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) + rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] + have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) + by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] + · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht + nlinarith + all_goals ring_nf; rfl + +def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := + ∀ s, m s ≤ ∏ i ∈ s, p i + +lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] + {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) + (fun i => (p i + p (Equiv.swap a b i)) / 2) := by + intro s + have h₀ := h s + have h₁ := h (s.image (Equiv.swap a b)) + rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ + exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans + (swap_average_product s p hp a b) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : ℝ := by + classical + exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) + +lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by + classical + unfold inclusionMoment finiteMean + positivity + +lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : + (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by + by_cases h : s ⊆ A + · rw [ite_eq_left h] + exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm + · rw [ite_eq_right h] + obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h + exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm + +lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] + (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = + if s ⊆ A then 1 else 0 := by + classical + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] + +lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : + CylinderBound (inclusionMoment (fun _ : Ω => A)) + (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by + classical + intro s + simp only [inclusionMoment_const, Finset.singleton_subset_iff] + exact (indicator_subset_prod A s).le + +noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] + (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := + fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 + +lemma subset_swap_image_iff {α : Type*} [DecidableEq α] + (A s : Finset α) (a b : α) : + s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by + constructor + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + +lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) (s : Finset α) : + inclusionMoment (fairSetSwap F a b) s = + (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by + classical + simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, + fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, + Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] + rw [div_mul_eq_div_div, add_div] + ring_nf + +lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) + (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : + CylinderBound (inclusionMoment (fairSetSwap F a b)) + (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by + classical + have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b + intro s + simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s + +def SwitchSamples : ℕ → Type + | 0 => Unit + | n + 1 => SwitchSamples n × Bool + +instance (n : ℕ) : Fintype (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Fintype Unit) + | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) + +instance (n : ℕ) : Nonempty (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) + +noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : + (L : List (α × α)) → SwitchSamples L.length → Finset α + | [], _ => A + | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω + +lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) + (L : List (α × α)) : + CylinderBound (inclusionMoment (switchedSet A L)) + (fun i => inclusionMoment (switchedSet A L) {i}) := by + induction L with + | nil => exact cylinder_const A + | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih + +inductive QueryTree (ι : Type*) + | reject : QueryTree ι + | accept : QueryTree ι + | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι + | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι + +namespace QueryTree + +variable {ι : Type*} [DecidableEq ι] + +def queries : QueryTree ι → Finset ι + | reject => ∅ + | accept => ∅ + | branch i zero one => insert i (queries zero ∪ queries one) + | force i _ next => insert i (queries next) + +def Fresh : QueryTree ι → Prop + | reject => True + | accept => True + | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one + | force i _ next => i ∉ queries next ∧ Fresh next + +def weighted : QueryTree ι → (ι → Bool) → ℝ + | reject, _ => 0 + | accept, _ => 1 + | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω + | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 + +omit [DecidableEq ι] in +lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by + induction T with + | reject => exact le_rfl + | accept => exact zero_le_one + | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ + | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl + +lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} + (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by + induction T with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), + ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] + | force i b next ih => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] + +def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := + (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by + intro ω + funext j + by_cases h : j = i + · subst j; simp + · simp [Function.update_of_ne h]).toPerm + +lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by + change Function.update ω i (!(ω i)) i = _ + exact Function.update_self _ _ _ + +lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : + flipCoin i ω j = ω j := by + change Function.update ω i (!(ω i)) j = _ + exact Function.update_of_ne h _ _ + +lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) + (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by + apply weighted_congr + intro j hj + exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω + +lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) + (hf : ∀ ω, f (flipCoin i ω) = f ω) : + finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by + let g := fun ω : ι → Bool => if ω i = b then f ω else 0 + have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by + dsimp [g] + rw [flipCoin_apply_eq, hf] + cases hω : ω i <;> cases b <;> simp + have hs := Equiv.sum_comp (flipCoin i) g + have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun ω _ => hp ω) + unfold finiteMean + change (∑ ω, g ω) / _ = _ + rw [hs] at hadd + have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith + rw [hh] + ring + +lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : + finiteMean T.weighted ≤ 1 := by + induction T with + | reject => simp [weighted, finiteMean] + | accept => simp [weighted, finiteMean] + | branch i zero one ih₀ ih₁ => + obtain ⟨hz, ho, hfz, hfo⟩ := hT + have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) + have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) + have he : finiteMean (branch i zero one).weighted = + finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + + finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by + unfold finiteMean + rw [← add_div, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + cases hω : ω i <;> simp [weighted, hω] + rw [he, h₀, h₁] + linarith [ih₀ hfz, ih₁ hfo] + | force i b next ih => + obtain ⟨hi, hn⟩ := hT + have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) + have he : finiteMean (force i b next).weighted = + 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by + unfold finiteMean + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : ω i = b <;> simp [weighted, h] + rw [he, hm] + linarith [ih hn] + +def succeeds : QueryTree ι → (ι → Bool) → Bool + | reject, _ => false + | accept, _ => true + | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω + | force i b next, ω => if ω i = b then succeeds next ω else false + +def charge : QueryTree ι → (ι → Bool) → ℕ + | reject, _ => 0 + | accept, _ => 0 + | branch i zero one, ω => if ω i then charge one ω else charge zero ω + | force i b next, ω => if ω i = b then charge next ω + 1 else 0 + +omit [DecidableEq ι] in +lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : + T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by + induction T with + | reject => rfl + | accept => norm_num [weighted, succeeds, charge] + | branch i zero one ih₀ ih₁ => + cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] + | force i b next ih => + by_cases h : ω i = b + · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] + cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] + · simp [weighted, succeeds, h] + +lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) + (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : + finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by + have hw (ω : ι → Bool) : + (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by + rw [weighted_eq] + cases hs : T.succeeds ω + · simp + · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) + have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ + have hm := div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn + rw [← Finset.mul_sum, mul_div_assoc] at hm + change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ + finiteMean T.weighted at hm + exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by + rw [mul_comm] + exact hm.trans (mean_weighted_le_one T hT)) + +end QueryTree + +def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool + | 0, _, i => nomatch i + | _d + 1, b, Sum.inl y => b.1 y + | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i + +lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : + decodeButterfly d (encodeButterfly d b) = b := by + induction d with + | zero => exact Unit.ext _ _ + | succ d ih => + apply Prod.ext + · rfl + · funext ε + exact ih (b.2 ε) + +lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : + encodeButterfly d (decodeButterfly d ω) = ω := by + induction d with + | zero => funext i; exact Empty.elim i + | succ d ih => + funext i + cases i with + | inl y => rfl + | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 + +def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where + toFun := decodeButterfly d + invFun := encodeButterfly d + left_inv := encode_decodeButterfly d + right_inv := decode_encodeButterfly d + +noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) + | 0, _, _ => ∅ + | d + 1, x, y => by + classical + exact insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) + +def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool + | 0, _, _, i => nomatch i + | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) + | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ExposedCoins.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ExposedCoins.lean index 563496f360f623dd12c81ead97e3e7101a11cd91..b55fe6ae9178a0a86c35a7746ae866215c2ae66c 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ExposedCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ExposedCoins.lean @@ -1,860 +1,860 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.Coins - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter - -lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by - classical - induction d with - | zero => rfl - | succ d ih => - change (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 - rw [Finset.card_insert_of_notMem (by simp)] - rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] - -lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by - cases a <;> cases b <;> cases c <;> decide - -lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : - butterflyPerm d (decodeButterfly d ω) x = y ↔ - ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by - classical - induction d with - | zero => - have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ - simp [he, routeDomain] - | succ d ih => - let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) - change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ - have hv : v = Fin.tail y ↔ - ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), - ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := - ih _ _ _ - constructor - · intro h i hi - have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h - have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by - have he := congrFun h 0 - simp only [Fin.cons_zero, ht] at he - exact (xor_eq_iff _ _ _).mp he - rcases Finset.mem_insert.mp hi with htop | hchild - · subst i - exact hh - · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild - exact hv.mp ht j hj - · intro h - have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) - have ht : v = Fin.tail y := hv.mpr (fun i hi => - h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) - have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := - (xor_eq_iff _ _ _).mpr hh - rw [ht, hh', Fin.cons_self_tail] - -lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by - unfold finiteMean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) : - finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = - 1 / (2 : ℝ) ^ s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 - have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - dsimp [f] - simp only [he] - have hm := QueryTree.mean_indicator_bit f i (v i) hf - have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = - (fun ω => if ω i = v i then f ω else 0) := by - funext ω - by_cases h : ω i = v i <;> simp [f, h] - rw [he, hm] - change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ - rw [ih, Finset.card_insert_of_notMem hi, pow_succ] - ring - -def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := - fun i => if i ∈ R then η i else ω i - -lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] - (s R : Finset ι) (v η : ι → Bool) : - finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by - have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ - (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by - constructor - · intro h - constructor - · intro i hi - simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 - · intro i hi - simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 - · rintro ⟨ho, hf⟩ i hi - by_cases hR : i ∈ R - · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) - · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) - have hm : finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - finiteMean (fun ω : ι → Bool => - if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [he ω]) - rw [hm] - by_cases h : ∀ i ∈ s ∩ R, η i = v i - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h - simp only [hp, true_and, ↓reduceIte] - exact mean_coinCylinder (s \ R) v - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h - simp only [hp, false_and, ↓reduceIte] - simp [finiteMean] - -lemma butterfly_closure_probability (d : ℕ) (x y : Card d) - (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then - (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder_exposed] - congr 1 - have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter, card_routeDomain] - have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * - (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by - rw [← pow_add] - exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm - rw [hp] - have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) - field_simp - -lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder, card_routeDomain] - -def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d - | 0, _, i => nomatch i - | d + 1, b, Sum.inl y => - (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), - Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) - | d + 1, b, Sum.inr (ε,i) => - (Fin.cons ε (switchUsers d (b.2 ε) i).1, - Fin.cons ε (switchUsers d (b.2 ε) i).2) - -lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : - (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - intro h - have := congrFun h 0 - simp only [switchUsers, Fin.cons_zero] at this - exact Bool.false_ne_true this - | inr z => - intro h - exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) - -lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : - Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by - constructor - · intro h - exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, - by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ - · rintro ⟨rfl,rfl⟩ - exact Fin.cons_self_tail x - -lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : - i ∈ routeDomain d x (butterflyPerm d b x) ↔ - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by - classical - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, - Sum.inr_ne_inl, and_false, exists_false, or_false] - change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ - simp only [switchUsers, cons_eq_iff] - cases x 0 <;> simp [Equiv.symm_apply_eq] - | inr z => - obtain ⟨ε,i⟩ := z - change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, - Sum.inr.injEq, Prod.mk.injEq] - change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ - x 0 = ε ∧ j = i) ↔ _ - simp only [switchUsers, cons_eq_iff] - constructor - · rintro ⟨j,hj,hε,rfl⟩ - subst ε - rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h - · exact Or.inl ⟨rfl,h⟩ - · exact Or.inr ⟨rfl,h⟩ - · rintro (⟨hε,h⟩ | ⟨hε,h⟩) - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ - -lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : - (Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - routeDomain d x (butterflyPerm d b x) := by - ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] - rw [he,card_routeDomain] - -lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = - (d : ℝ) * ∑ x : Card d, w x := by - classical - calc - _ = ∑ i : SwitchIndex d, ∑ x : Card d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : Card d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - {(switchUsers d b i).1, (switchUsers d b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (switchUsers_ne d b i)] - _ = ∑ x : Card d, ∑ i : SwitchIndex d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : Card d, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ - (d : ℝ) / 2 * ∑ x : Card d, w x := by - have h : 2 * (∑ i : SwitchIndex d, - min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), - min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] - rw [switch_incidence_sum] at h - linarith - -lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : - x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by - classical - constructor - · intro h - obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy - rw [← hxy, ← hyε, Fin.cons_self_tail] - exact hys - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons ε x, - Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ - -lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) (y : Card d) : - y ∈ topMeetings b s ↔ - (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by - classical - have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ - (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by - constructor - · intro h - obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h - simpa only [Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ - simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] - -lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - encounters d b s = ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by - classical - induction d with - | zero => - simp only [encounters] - symm - apply Finset.sum_eq_zero - intro i _ - exact Empty.elim i - | succ d ih => - change encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = - ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ - rw [Fintype.sum_sum_type, Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [ih,ih] - have ht : (∑ y : Card d, - if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = - (topMeetings b s).card := by - simp only [← mem_topMeetings] - simp - rw [ht] - simp only [mem_childMarks, switchUsers] - ac_rfl - -lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ - (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - classical - have he : (encounters d b s : ℝ) = - ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by - rw [encounters_eq_switch_sum, Nat.cast_sum] - apply Finset.sum_congr rfl - intro i _ - split_ifs <;> simp - rw [← he] - exact butterfly_encounters d b s - -namespace QueryTree -variable {ι : Type*} [DecidableEq ι] - -def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι - | reject, _, _ => reject - | accept, _, _ => accept - | branch i zero one, R, η => - if i ∈ R then (if η i then memo one R η else memo zero R η) else - branch i (memo zero (insert i R) (Function.update η i false)) - (memo one (insert i R) (Function.update η i true)) - | force i b next, R, η => - if i ∈ R then (if η i = b then memo next R η else reject) else - force i b (memo next (insert i R) (Function.update η i b)) - -lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - Disjoint (memo T R η).queries R := by - induction T generalizing R η with - | reject => simp [memo,queries] - | accept => simp [memo,queries] - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] - exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), - (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,queries] - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] - exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - -lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - (memo T R η).Fresh := by - induction T generalizing R η with - | reject => trivial - | accept => trivial - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm - (Finset.mem_insert_self _ _), - fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm - (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,Fresh] - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm - (Finset.mem_insert_self _ _),ih _ _⟩ - -lemma update_agrees {R : Finset ι} {η ω : ι → Bool} - (h : ∀ i ∈ R, η i = ω i) (i : ι) : - ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by - intro j hj - rcases Finset.mem_insert.mp hj with rfl | hj - · simp - · by_cases hji : j = i - · subst j; simp - · rw [Function.update_of_ne hji] - exact h j hj - -lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,succeeds,h i hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,succeeds] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte,succeeds] - exact ih R η h - · simp [hb,succeeds] - · simp only [memo,hi,↓reduceIte,succeeds] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih _ _ (by simpa only [hb] using update_agrees h i) - · simp [hb] - -def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 - -lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih R η h - · simp [hb,charge] - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - rw [ih _ _ (by simpa only [hb] using update_agrees h i)] - · simp [hb] - -lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by - let η : ι → Bool := fun _ => false - have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) - have he : finiteMean (memo T ∅ η).weighted = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] - rw [he] at hm - exact hm - - -def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → - (Card d → QueryTree ι) → QueryTree ι - | 0, _, x, k => k x - | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) - (fun y => branch (e (Sum.inl y)) - (k (Fin.cons (Bool.xor (x 0) false) y)) - (k (Fin.cons (Bool.xor (x 0) true) y))) - -omit [DecidableEq ι] in -lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).succeeds ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω - cases ω (e (Sum.inl y)) <;> rfl - -lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - freshCharge (followPath d e x k) R ω = - freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - classical - induction d generalizing R with - | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) - change (if ω (e (Sum.inl y)) then - freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else - freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = - freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) - (R ∪ (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω - have hs : (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = - insert (e (Sum.inl y)) S := by - let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e - change (insert (Sum.inl y) - ((routeDomain d (Fin.tail x) y).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ - rw [Finset.image_insert, Finset.image_image] - rfl - rw [hs,Finset.union_insert] - cases ω (e (Sum.inl y)) <;> rfl - -def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι - | [], _, k => k - | i :: L, v, k => force i (v i) (forceList L v k) - -omit [DecidableEq ι] in -lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : - (forceList L v k).succeeds ω = - if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by - induction L with - | nil => simp [forceList] - | cons i L ih => - simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] - by_cases h : ω i = v i <;> simp [h] - -lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) - (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : - freshCharge (forceList L v k) R ω = - freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by - induction L generalizing R with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), - ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.toFinset_cons] - have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp - rw [hs] - by_cases hi : i ∈ R - · rw [ite_eq_left hi] - have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he,Nat.add_zero] - · rw [ite_eq_right hi] - have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he, Finset.card_insert_of_notMem (by simp)] - omega - - -def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω - else staleCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 - -lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by - induction T generalizing R with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] - | force i b next ih => - by_cases hb : ω i = b - · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] - have he := ih (insert i R) - by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega - · simp [freshCharge,staleCharge,charge,hb] - -omit [DecidableEq ι] in -lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).charge ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω - cases ω (e (Sum.inl y)) <;> rfl - -omit [DecidableEq ι] in -lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) - (h : ∀ i ∈ L, ω i = v i) : - (forceList L v k).charge ω = k.charge ω + L.length := by - induction L with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), - ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.length_cons,Nat.add_assoc] - -noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : - QueryTree (SwitchIndex d) := - forceList (routeDomain d x y).toList (routeValue d x y) k - -lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) : - (closePath d x y k).succeeds ω = - if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by - unfold closePath - rw [forceList_succeeds] - simp only [Finset.mem_toList, ← butterfly_endpoint_iff] - -lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).charge ω = k.charge ω + d := by - unfold closePath - rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] - -lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).freshCharge R ω = - k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by - unfold closePath - rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] - -lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).staleCharge R ω = - k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by - have h₀ := fresh_add_stale (closePath d x y k) R ω - have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω - rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ - have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_routeDomain] - omega - -noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : - ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → - QueryTree (SwitchIndex d) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x - (fun y => seekCycle d S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle d S a r x V k).succeeds ω = true) : - (seekCycle d S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs - rw [seekCycle,ite_eq_left hv,followPath_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,succeeds] at hs - -noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : - List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) - | [], _ => accept - | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) - -lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) - (V : Finset (Card d)) (ω : SwitchIndex d → Bool) - (hs : (seekCycles d S L V).succeeds ω = true) : - (seekCycles d S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : - finiteMean (fun ω : SwitchIndex d → Bool => - if (seekCycles d S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles d S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge d S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree - -lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by - simp only [finiteMean,Finset.sum_add_distrib,add_div] - -lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : - finiteMean (fun ω => f ω * c) = finiteMean f * c := by - unfold finiteMean - rw [← Finset.sum_mul] - ring - -lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : - finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by - simp only [finiteMean,Finset.sum_div] - exact Finset.sum_comm - -lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω → ℝ) : - finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by - unfold finiteMean - rw [Fintype.card_congr e] - congr 1 - exact Fintype.sum_equiv e _ _ (fun ω => by simp) - -lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] - (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by - simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, - ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] - have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - field_simp - -lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] - {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] - (c : C) (g : A c → ℝ) : - finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by - rw [finiteMean_equiv (Equiv.piSplitAt c A)] - have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => - g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by - funext z - simp [Equiv.piSplitAt] - rw [he,finiteMean_prod_left] - -lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : - finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by - simp [finiteMean] - -lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] - have hj := convexOn_exp.map_sum_le (t := Finset.univ) - (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) - (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) - simp only [smul_eq_mul, ← Finset.mul_sum] at hj - simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj - -variable {d A : ℕ} - -def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} - -noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.Coins + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter + +lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by + classical + induction d with + | zero => rfl + | succ d ih => + change (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 + rw [Finset.card_insert_of_notMem (by simp)] + rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] + +lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by + cases a <;> cases b <;> cases c <;> decide + +lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : + butterflyPerm d (decodeButterfly d ω) x = y ↔ + ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by + classical + induction d with + | zero => + have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ + simp [he, routeDomain] + | succ d ih => + let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) + change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ + have hv : v = Fin.tail y ↔ + ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), + ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := + ih _ _ _ + constructor + · intro h i hi + have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h + have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by + have he := congrFun h 0 + simp only [Fin.cons_zero, ht] at he + exact (xor_eq_iff _ _ _).mp he + rcases Finset.mem_insert.mp hi with htop | hchild + · subst i + exact hh + · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild + exact hv.mp ht j hj + · intro h + have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) + have ht : v = Fin.tail y := hv.mpr (fun i hi => + h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) + have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := + (xor_eq_iff _ _ _).mpr hh + rw [ht, hh', Fin.cons_self_tail] + +lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by + unfold finiteMean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) : + finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = + 1 / (2 : ℝ) ^ s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 + have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + dsimp [f] + simp only [he] + have hm := QueryTree.mean_indicator_bit f i (v i) hf + have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = + (fun ω => if ω i = v i then f ω else 0) := by + funext ω + by_cases h : ω i = v i <;> simp [f, h] + rw [he, hm] + change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ + rw [ih, Finset.card_insert_of_notMem hi, pow_succ] + ring + +def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := + fun i => if i ∈ R then η i else ω i + +lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] + (s R : Finset ι) (v η : ι → Bool) : + finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by + have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ + (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by + constructor + · intro h + constructor + · intro i hi + simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 + · intro i hi + simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 + · rintro ⟨ho, hf⟩ i hi + by_cases hR : i ∈ R + · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) + · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) + have hm : finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + finiteMean (fun ω : ι → Bool => + if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [he ω]) + rw [hm] + by_cases h : ∀ i ∈ s ∩ R, η i = v i + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h + simp only [hp, true_and, ↓reduceIte] + exact mean_coinCylinder (s \ R) v + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h + simp only [hp, false_and, ↓reduceIte] + simp [finiteMean] + +lemma butterfly_closure_probability (d : ℕ) (x y : Card d) + (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then + (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder_exposed] + congr 1 + have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter, card_routeDomain] + have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * + (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by + rw [← pow_add] + exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm + rw [hp] + have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) + field_simp + +lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder, card_routeDomain] + +def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d + | 0, _, i => nomatch i + | d + 1, b, Sum.inl y => + (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), + Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) + | d + 1, b, Sum.inr (ε,i) => + (Fin.cons ε (switchUsers d (b.2 ε) i).1, + Fin.cons ε (switchUsers d (b.2 ε) i).2) + +lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : + (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + intro h + have := congrFun h 0 + simp only [switchUsers, Fin.cons_zero] at this + exact Bool.false_ne_true this + | inr z => + intro h + exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) + +lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : + Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by + constructor + · intro h + exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, + by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ + · rintro ⟨rfl,rfl⟩ + exact Fin.cons_self_tail x + +lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : + i ∈ routeDomain d x (butterflyPerm d b x) ↔ + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by + classical + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, + Sum.inr_ne_inl, and_false, exists_false, or_false] + change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ + simp only [switchUsers, cons_eq_iff] + cases x 0 <;> simp [Equiv.symm_apply_eq] + | inr z => + obtain ⟨ε,i⟩ := z + change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, + Sum.inr.injEq, Prod.mk.injEq] + change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ + x 0 = ε ∧ j = i) ↔ _ + simp only [switchUsers, cons_eq_iff] + constructor + · rintro ⟨j,hj,hε,rfl⟩ + subst ε + rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h + · exact Or.inl ⟨rfl,h⟩ + · exact Or.inr ⟨rfl,h⟩ + · rintro (⟨hε,h⟩ | ⟨hε,h⟩) + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ + +lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : + (Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + routeDomain d x (butterflyPerm d b x) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] + rw [he,card_routeDomain] + +lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = + (d : ℝ) * ∑ x : Card d, w x := by + classical + calc + _ = ∑ i : SwitchIndex d, ∑ x : Card d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : Card d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + {(switchUsers d b i).1, (switchUsers d b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (switchUsers_ne d b i)] + _ = ∑ x : Card d, ∑ i : SwitchIndex d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : Card d, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ + (d : ℝ) / 2 * ∑ x : Card d, w x := by + have h : 2 * (∑ i : SwitchIndex d, + min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), + min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] + rw [switch_incidence_sum] at h + linarith + +lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : + x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by + classical + constructor + · intro h + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy + rw [← hxy, ← hyε, Fin.cons_self_tail] + exact hys + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons ε x, + Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ + +lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) (y : Card d) : + y ∈ topMeetings b s ↔ + (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by + classical + have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ + (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by + constructor + · intro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + simpa only [Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ + simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] + +lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + encounters d b s = ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by + classical + induction d with + | zero => + simp only [encounters] + symm + apply Finset.sum_eq_zero + intro i _ + exact Empty.elim i + | succ d ih => + change encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = + ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ + rw [Fintype.sum_sum_type, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [ih,ih] + have ht : (∑ y : Card d, + if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = + (topMeetings b s).card := by + simp only [← mem_topMeetings] + simp + rw [ht] + simp only [mem_childMarks, switchUsers] + ac_rfl + +lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ + (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + classical + have he : (encounters d b s : ℝ) = + ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by + rw [encounters_eq_switch_sum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + rw [← he] + exact butterfly_encounters d b s + +namespace QueryTree +variable {ι : Type*} [DecidableEq ι] + +def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι + | reject, _, _ => reject + | accept, _, _ => accept + | branch i zero one, R, η => + if i ∈ R then (if η i then memo one R η else memo zero R η) else + branch i (memo zero (insert i R) (Function.update η i false)) + (memo one (insert i R) (Function.update η i true)) + | force i b next, R, η => + if i ∈ R then (if η i = b then memo next R η else reject) else + force i b (memo next (insert i R) (Function.update η i b)) + +lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + Disjoint (memo T R η).queries R := by + induction T generalizing R η with + | reject => simp [memo,queries] + | accept => simp [memo,queries] + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] + exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), + (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,queries] + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] + exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + +lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + (memo T R η).Fresh := by + induction T generalizing R η with + | reject => trivial + | accept => trivial + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm + (Finset.mem_insert_self _ _), + fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm + (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,Fresh] + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm + (Finset.mem_insert_self _ _),ih _ _⟩ + +lemma update_agrees {R : Finset ι} {η ω : ι → Bool} + (h : ∀ i ∈ R, η i = ω i) (i : ι) : + ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by + intro j hj + rcases Finset.mem_insert.mp hj with rfl | hj + · simp + · by_cases hji : j = i + · subst j; simp + · rw [Function.update_of_ne hji] + exact h j hj + +lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,succeeds,h i hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,succeeds] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte,succeeds] + exact ih R η h + · simp [hb,succeeds] + · simp only [memo,hi,↓reduceIte,succeeds] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih _ _ (by simpa only [hb] using update_agrees h i) + · simp [hb] + +def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 + +lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih R η h + · simp [hb,charge] + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + rw [ih _ _ (by simpa only [hb] using update_agrees h i)] + · simp [hb] + +lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by + let η : ι → Bool := fun _ => false + have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) + have he : finiteMean (memo T ∅ η).weighted = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] + rw [he] at hm + exact hm + + +def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → + (Card d → QueryTree ι) → QueryTree ι + | 0, _, x, k => k x + | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) + (fun y => branch (e (Sum.inl y)) + (k (Fin.cons (Bool.xor (x 0) false) y)) + (k (Fin.cons (Bool.xor (x 0) true) y))) + +omit [DecidableEq ι] in +lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).succeeds ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω + cases ω (e (Sum.inl y)) <;> rfl + +lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + freshCharge (followPath d e x k) R ω = + freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + classical + induction d generalizing R with + | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) + change (if ω (e (Sum.inl y)) then + freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else + freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = + freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) + (R ∪ (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω + have hs : (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = + insert (e (Sum.inl y)) S := by + let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e + change (insert (Sum.inl y) + ((routeDomain d (Fin.tail x) y).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ + rw [Finset.image_insert, Finset.image_image] + rfl + rw [hs,Finset.union_insert] + cases ω (e (Sum.inl y)) <;> rfl + +def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι + | [], _, k => k + | i :: L, v, k => force i (v i) (forceList L v k) + +omit [DecidableEq ι] in +lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : + (forceList L v k).succeeds ω = + if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by + induction L with + | nil => simp [forceList] + | cons i L ih => + simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] + by_cases h : ω i = v i <;> simp [h] + +lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) + (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : + freshCharge (forceList L v k) R ω = + freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by + induction L generalizing R with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), + ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.toFinset_cons] + have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp + rw [hs] + by_cases hi : i ∈ R + · rw [ite_eq_left hi] + have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he,Nat.add_zero] + · rw [ite_eq_right hi] + have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he, Finset.card_insert_of_notMem (by simp)] + omega + + +def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω + else staleCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 + +lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by + induction T generalizing R with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] + | force i b next ih => + by_cases hb : ω i = b + · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] + have he := ih (insert i R) + by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega + · simp [freshCharge,staleCharge,charge,hb] + +omit [DecidableEq ι] in +lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).charge ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω + cases ω (e (Sum.inl y)) <;> rfl + +omit [DecidableEq ι] in +lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) + (h : ∀ i ∈ L, ω i = v i) : + (forceList L v k).charge ω = k.charge ω + L.length := by + induction L with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), + ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.length_cons,Nat.add_assoc] + +noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : + QueryTree (SwitchIndex d) := + forceList (routeDomain d x y).toList (routeValue d x y) k + +lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) : + (closePath d x y k).succeeds ω = + if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by + unfold closePath + rw [forceList_succeeds] + simp only [Finset.mem_toList, ← butterfly_endpoint_iff] + +lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).charge ω = k.charge ω + d := by + unfold closePath + rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] + +lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).freshCharge R ω = + k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by + unfold closePath + rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] + +lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).staleCharge R ω = + k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by + have h₀ := fresh_add_stale (closePath d x y k) R ω + have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω + rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ + have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_routeDomain] + omega + +noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : + ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → + QueryTree (SwitchIndex d) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x + (fun y => seekCycle d S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle d S a r x V k).succeeds ω = true) : + (seekCycle d S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs + rw [seekCycle,ite_eq_left hv,followPath_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,succeeds] at hs + +noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : + List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) + | [], _ => accept + | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) + +lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) + (V : Finset (Card d)) (ω : SwitchIndex d → Bool) + (hs : (seekCycles d S L V).succeeds ω = true) : + (seekCycles d S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : + finiteMean (fun ω : SwitchIndex d → Bool => + if (seekCycles d S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles d S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge d S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree + +lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by + simp only [finiteMean,Finset.sum_add_distrib,add_div] + +lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : + finiteMean (fun ω => f ω * c) = finiteMean f * c := by + unfold finiteMean + rw [← Finset.sum_mul] + ring + +lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : + finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by + simp only [finiteMean,Finset.sum_div] + exact Finset.sum_comm + +lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω → ℝ) : + finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by + unfold finiteMean + rw [Fintype.card_congr e] + congr 1 + exact Fintype.sum_equiv e _ _ (fun ω => by simp) + +lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] + (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by + simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, + ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] + have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + field_simp + +lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] + {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] + (c : C) (g : A c → ℝ) : + finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by + rw [finiteMean_equiv (Equiv.piSplitAt c A)] + have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => + g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by + funext z + simp [Equiv.piSplitAt] + rw [he,finiteMean_prod_left] + +lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : + finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by + simp [finiteMean] + +lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] + have hj := convexOn_exp.map_sum_le (t := Finset.univ) + (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) + (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul, ← Finset.mul_sum] at hj + simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj + +variable {d A : ℕ} + +def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} + +noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/HeightDecay.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/HeightDecay.lean index 3d9b5207f0f5b3e0face7aa37dce5d354016901d..bc9b1acc4a3eb464b61a34e69c85214b83a57b80 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/HeightDecay.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/HeightDecay.lean @@ -1,863 +1,863 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ParallelFreshPre - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) - (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by - have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by - apply (mem_orbitSet _ _ _).mpr - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - have he (n : ℕ) : (p^n) x = (q^n) x := by - induction n with - | zero => rfl - | succ n ih => - rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] - exact h _ (hp n) - ext y - simp only [mem_orbitSet] - constructor - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,←he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - -noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) - (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by - refine ⟨C.val,?_,C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ - intro z hz - exact h z (hC z (hx ▸ hz)) - -noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by - classical - by_cases hb : ∃ x ∈ C.val, x ∈ B - · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ - · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) - -lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by - classical - intro C D he - by_cases hC : ∃ x ∈ C.val, x ∈ B <;> - by_cases hD : ∃ x ∈ D.val, x ∈ B - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he - have hx : hC.choose = hD.choose := congrArg Subtype.val he - exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 - (hx.symm ▸ hD.choose_spec.1) - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he - have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he - exact Subtype.ext hval - -theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by - have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) - simpa only [Fintype.card_sum,Fintype.card_coe] using hh - - -noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := - (Finset.univ.filter (fun x => p x ≠ q x)).card - -lemma permDistance_sum (p q : Equiv.Perm α) : - permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by - classical - simp [permDistance,Finset.card_filter] - -lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by - simp [permDistance] - -lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := - (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) - -lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by - simp only [permDistance,ne_comm] - -lemma permDistance_triangle (p q r : Equiv.Perm α) : - permDistance p r ≤ permDistance p q+permDistance q r := by - classical - simp only [permDistance_sum,←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro x _ - by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> - by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> - omega - -lemma permDistance_mul_left (p q g : Equiv.Perm α) : - permDistance (g*p) (g*q) = permDistance p q := by - classical - unfold permDistance - congr 1 - ext x - simp only [Finset.mem_filter,Finset.mem_univ,true_and] - exact not_congr g.injective.eq_iff - -lemma permDistance_mul_right (p q g : Equiv.Perm α) : - permDistance (p*g) (q*g) = permDistance p q := by - classical - simp only [permDistance_sum,Equiv.Perm.mul_apply] - exact Fintype.sum_equiv g _ _ (fun _ => rfl) - -lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by - have hh := permDistance_mul_left p⁻¹ q⁻¹ q - have hhh := permDistance_mul_right (q*p⁻¹) 1 p - simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh - rw [←hhh] at hh - rw [←hh,permDistance_symm] - -lemma permDistance_mul_le (p q g h : Equiv.Perm α) : - permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by - have hh := permDistance_triangle (p*g) (q*g) (q*h) - simpa only [permDistance_mul_left,permDistance_mul_right] using hh - -lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by - apply selectedCycle_perturb_le - intro x hx - simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx - -lemma permDistance_alternating (p q : Equiv.Perm α) : - permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by - classical - simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] - simp [CycleColoring.alternatingPerm] - -lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ - (permDistance (p false) (q false)+permDistance (p true) (q true)) := by - have hh := selectedCycle_distance_le - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) - rw [permDistance_alternating] at hh - apply hh.trans - apply Nat.add_le_add_left - dsimp only [PairRouting.alternatingProjection] - exact (permDistance_mul_le _ _ _ _).trans_eq (by - change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ - rw [permDistance_inv]) - -end Thorp -namespace Thorp - -def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - Equiv.Perm (Card (L+r)) - | 0, C => C (fun j => Fin.elim0 j) - | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) - -def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * - (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ - -lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - (c : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r - (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by - change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * - childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * - (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - simp only [mul_assoc] - rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → - (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ - | 0, _, _, _, _, _ => 0 - | r+1, C, _, _, e, ω => - let σ := benesStepEquiv (L+r) ω - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) σ.1.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := - ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω - -lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - permDistance (childLift p) (childLift q) = - permDistance (p false) (q false)+permDistance (p true) (q true) := by - classical - rw [permDistance_sum] - have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = - ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by - apply Fintype.sum_equiv (headTailEquiv d) - intro x - have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl - rw [hx] - congr 1 - apply propext - constructor - · intro h - have ht := congrArg Fin.tail h - simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht - · intro h - dsimp only [childLift,Equiv.coe_fn_mk] - exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h - rw [hh] - simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] - omega - -noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := - ∑ u : Card r, permDistance (C u) (D u) - -lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : - centralDistance L (r+1) C D = - centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ - centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by - classical - unfold centralDistance - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) - (fun x => by - change permDistance (C x) (D x) = - permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) - rw [Fin.cons_self_tail])] - simp only [Fintype.sum_prod_type,Fintype.sum_bool] - omega - -lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : - permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by - induction r with - | zero => - simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] - -lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : - permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = - centralDistance L r C D := by - rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, - permDistance_mul_left,permDistance_centralBlock] - -lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x coins.1 - let hc := PairRouting.colors_compatible x coins.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) ω.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) ω.2 := by - rw [centralLevelCost] - rfl - -lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by - induction r generalizing ι with - | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] - dsimp only - split_ifs with ht - · have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (benesStepEquiv (L+r) ω).2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh - · rw [centralDistance_step] - have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) false) - (benesStepEquiv (L+r) ω).1.1 - have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) true) - (benesStepEquiv (L+r) ω).1.2 - omega - -lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - centralLevelCost_perturb (l+i.val+1) L r C D e ω) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ParallelFreshPre + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) + (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by + have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by + apply (mem_orbitSet _ _ _).mpr + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + have he (n : ℕ) : (p^n) x = (q^n) x := by + induction n with + | zero => rfl + | succ n ih => + rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] + exact h _ (hp n) + ext y + simp only [mem_orbitSet] + constructor + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,←he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + +noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) + (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by + refine ⟨C.val,?_,C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ + intro z hz + exact h z (hC z (hx ▸ hz)) + +noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by + classical + by_cases hb : ∃ x ∈ C.val, x ∈ B + · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ + · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) + +lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by + classical + intro C D he + by_cases hC : ∃ x ∈ C.val, x ∈ B <;> + by_cases hD : ∃ x ∈ D.val, x ∈ B + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he + have hx : hC.choose = hD.choose := congrArg Subtype.val he + exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 + (hx.symm ▸ hD.choose_spec.1) + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he + have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he + exact Subtype.ext hval + +theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by + have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) + simpa only [Fintype.card_sum,Fintype.card_coe] using hh + + +noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := + (Finset.univ.filter (fun x => p x ≠ q x)).card + +lemma permDistance_sum (p q : Equiv.Perm α) : + permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by + classical + simp [permDistance,Finset.card_filter] + +lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by + simp [permDistance] + +lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := + (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) + +lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by + simp only [permDistance,ne_comm] + +lemma permDistance_triangle (p q r : Equiv.Perm α) : + permDistance p r ≤ permDistance p q+permDistance q r := by + classical + simp only [permDistance_sum,←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro x _ + by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> + by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> + omega + +lemma permDistance_mul_left (p q g : Equiv.Perm α) : + permDistance (g*p) (g*q) = permDistance p q := by + classical + unfold permDistance + congr 1 + ext x + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact not_congr g.injective.eq_iff + +lemma permDistance_mul_right (p q g : Equiv.Perm α) : + permDistance (p*g) (q*g) = permDistance p q := by + classical + simp only [permDistance_sum,Equiv.Perm.mul_apply] + exact Fintype.sum_equiv g _ _ (fun _ => rfl) + +lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by + have hh := permDistance_mul_left p⁻¹ q⁻¹ q + have hhh := permDistance_mul_right (q*p⁻¹) 1 p + simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh + rw [←hhh] at hh + rw [←hh,permDistance_symm] + +lemma permDistance_mul_le (p q g h : Equiv.Perm α) : + permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by + have hh := permDistance_triangle (p*g) (q*g) (q*h) + simpa only [permDistance_mul_left,permDistance_mul_right] using hh + +lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by + apply selectedCycle_perturb_le + intro x hx + simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx + +lemma permDistance_alternating (p q : Equiv.Perm α) : + permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by + classical + simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] + simp [CycleColoring.alternatingPerm] + +lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ + (permDistance (p false) (q false)+permDistance (p true) (q true)) := by + have hh := selectedCycle_distance_le + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) + rw [permDistance_alternating] at hh + apply hh.trans + apply Nat.add_le_add_left + dsimp only [PairRouting.alternatingProjection] + exact (permDistance_mul_le _ _ _ _).trans_eq (by + change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ + rw [permDistance_inv]) + +end Thorp +namespace Thorp + +def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + Equiv.Perm (Card (L+r)) + | 0, C => C (fun j => Fin.elim0 j) + | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) + +def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * + (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ + +lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + (c : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r + (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by + change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * + childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * + (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + simp only [mul_assoc] + rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → + (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ + | 0, _, _, _, _, _ => 0 + | r+1, C, _, _, e, ω => + let σ := benesStepEquiv (L+r) ω + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) σ.1.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := + ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω + +lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + permDistance (childLift p) (childLift q) = + permDistance (p false) (q false)+permDistance (p true) (q true) := by + classical + rw [permDistance_sum] + have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = + ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by + apply Fintype.sum_equiv (headTailEquiv d) + intro x + have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl + rw [hx] + congr 1 + apply propext + constructor + · intro h + have ht := congrArg Fin.tail h + simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht + · intro h + dsimp only [childLift,Equiv.coe_fn_mk] + exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h + rw [hh] + simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] + omega + +noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := + ∑ u : Card r, permDistance (C u) (D u) + +lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : + centralDistance L (r+1) C D = + centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ + centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by + classical + unfold centralDistance + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) + (fun x => by + change permDistance (C x) (D x) = + permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) + rw [Fin.cons_self_tail])] + simp only [Fintype.sum_prod_type,Fintype.sum_bool] + omega + +lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : + permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by + induction r with + | zero => + simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] + +lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : + permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = + centralDistance L r C D := by + rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, + permDistance_mul_left,permDistance_centralBlock] + +lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x coins.1 + let hc := PairRouting.colors_compatible x coins.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) ω.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) ω.2 := by + rw [centralLevelCost] + rfl + +lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by + induction r generalizing ι with + | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] + dsimp only + split_ifs with ht + · have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (benesStepEquiv (L+r) ω).2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh + · rw [centralDistance_step] + have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) false) + (benesStepEquiv (L+r) ω).1.1 + have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) true) + (benesStepEquiv (L+r) ω).1.2 + omega + +lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + centralLevelCost_perturb (l+i.val+1) L r C D e ω) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/InputTree.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/InputTree.lean index f79677262b89ef0bf36dd7bf709f12c352edd8db..2f9db3c5f9b45ac69c5921b5c99972392a96075e 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/InputTree.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/InputTree.lean @@ -1,884 +1,884 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.HeightDecay - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : - centralDistance L r C D ≤ E.card*2^L := by - classical - calc - _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by - apply Finset.sum_le_sum - intro u _ - split_ifs with hu - · simpa only [card_positions] using permDistance_le (C u) (D u) - · rw [h u hu,permDistance_refl] - _ = _ := by simp - - -inductive InputTree : ℕ → Type - | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d - | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) - -def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) - | _, .tip p => p - | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) - -noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → - {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ - | _, .tip _, _, _, _, _ => 0 - | d+1, .node ξ T, _, _, e, Y => - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let σ := coinStepEquiv d Y - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) - (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : - (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by - rw [InputTree.levelCost] - rfl - -lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - T.levelCost t e Y = 0 := by - induction T generalizing ι with - | tip p => rfl - | @node d ξ T ih => - rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] - -lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by - induction T generalizing ι with - | tip p => intro Y Y' _; rfl - | @node d ξ T ih => - intro Y Y' h - dsimp only - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] - rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), - InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih false - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih true - intro i hi - exact h (Sum.inr (true,i)) hi - -theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) - (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - cases T with - | tip p => - simp only [InputTree.levelCost,pow_zero,finiteMean_const] - exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) - | node ξ T => - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x ξ - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => - if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ - else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - (T false).levelCost (s+u+1) e₀ (Y₀ hi) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - (T true).levelCost (s+u+1) e₁ (Y₁ hi) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - (InputTree.node ξ T).levelCost (s+u+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' (T false).perm (T true).perm - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' (T false) e₀ lo₀ - have h₁ := ih u hu' (T true) e₁ lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i : Fin l, T.levelCost (l+i.1+1) e Y - -lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) - -theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)))) := by - apply finiteMean_mono - intro hi - simpa only [InputTree.slabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - (SwitchIndex (L+r) → Bool) → InputTree (L+r) - | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) - | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => - boundaryTree L r (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) - -def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → - Card r → Equiv.Perm (Card L) - | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) - | r+1, Y, u => boundaryOutput L r - (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) - -lemma boundaryOutput_adapted (L r : ℕ) : - LayerAdapted (L+r) L (boundaryOutput L r) := by - induction r with - | zero => - intro Y Y' h - have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) - rw [he] - | succ r ih => - intro Y Y' h - funext u - dsimp only [boundaryOutput] - cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) - -noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u - -lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) : - LayerAdapted (L+r) L (modifiedBoundary L r E U) := by - intro Y Y' h - unfold modifiedBoundary - rw [boundaryOutput_adapted L r Y Y' h] - -lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) : - permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = - centralDistance L r U V := by - induction r with - | zero => - simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - simp only [boundaryTree,InputTree.perm,permDistance_mul_left] - rw [permDistance_childLift,centralDistance_step,ih,ih] - -lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y ≤ - (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by - induction r generalizing ι with - | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] - by_cases ht : t = L+r+1 - · simp only [ite_eq_left ht] - have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (coinStepEquiv (L+r) X).2) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, - permDistance_boundaryTree,←centralDistance_step] using hh - · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] - rw [centralDistance_step] - have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) - (coinStepEquiv (L+r) X).1.1 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 - have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) - (coinStepEquiv (L+r) X).1.2 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 - omega - -lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh - -lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by - apply centralDistance_exceptional - intro u hu - exact ite_eq_right hu - - -lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.slabCost l d T e Y = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact InputTree.levelCost_gt _ _ T (by omega) _ _ - -lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - apply adapted_mul_mean_le r s F _ hF hA - intro lo - let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false - have he (hi : Card s × SwitchIndex r → Bool) : - T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := - hT _ _ (assembleBits_agree r s lo hi hi₀) - simp_rw [he] - exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog - -lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) - (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) - (fun _ _ _ => rfl) q hq hlog - simpa only [one_mul,finiteMean_const] using hh - -noncomputable def InputTree.familyCost (L n d : ℕ) - (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y - -lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by - intro Y Y' h - dsimp only - rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] - exact InputTree.slabCost_adapted l d (T Y') e Y Y' - (agreeThrough_mono (le_max_right _ _) h) - -lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) - (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) - -theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => - simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,add_zero] - exact Real.one_le_exp hp - | succ n ih => - by_cases hn : n = 0 - · subst n - simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst - · let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n - have hs' : s ≤ familyEnd L n := by - have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) - simp only [pow_zero,mul_one] at hh - omega - have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = - InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T - (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) - · apply layerAdapted_comp - exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) - · exact hq - · exact hlog - · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp only [l] - ring - -lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*heightDecay L) := by - apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans - apply Real.exp_le_exp.mpr - apply add_le_add_right - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using hh - - -noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := - boundaryTree L r (modifiedBoundary L r E U Y) X - -lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : - LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by - intro Y Y' h - unfold modifiedInputTree - rw [modifiedBoundary_adapted L r E U Y Y' h] - -lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ - Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - have hqp : 0 < q := by linarith - have hpoint (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by - apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans - apply Nat.add_le_add_left - simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) - calc - _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := - finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) - _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * - q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ - _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := - mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) - _ = _ := by - have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by - rw [Real.exp_nat_mul,Real.exp_log hqp] - rw [Real.exp_add,he,mul_comm] - -lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by - exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ - (modifiedInputTree_adapted L r E U X) e q hq hlog _ - (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) - (modified_slab_mgf l L r hl E U X e q hq hlog) - -theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ - InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 - have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 - have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) - (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by - apply h₁.trans - apply Real.exp_le_exp.mpr - exact add_le_add_right (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ - have hh := finiteMean_mul_exp_le - (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) - (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) - _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simp only [←pow_add] at hh - refine hh.trans_eq ?_ - congr 1 - simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] - ring - -noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y - -lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by - rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L - -lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + - InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by - induction n with - | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] - omega - -lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by - symm - apply Finset.sum_subset (Finset.range_mono hd) - intro i _ hi - have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi - exact InputTree.levelCost_gt (i+1) d T (by omega) e Y - -lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y = 0 := by - induction r generalizing ι with - | zero => rfl - | succ r ih => - rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] - -lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by - apply Finset.sum_eq_zero - intro i hi - exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y - -theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hbound : L+r ≤ L*4^(L+r) := by - have h₀ := pow_four_ge (L+r) - have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL - nlinarith - have he (Y : SwitchIndex (L+r) → Bool) := - InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y - have hz (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := - boundaryTree_lowCost_zero L r _ X e Y - simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he - simp_rw [←he] - exact modified_high_mgf L (L+r) r hL E U X e q hq hlog - - -noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := - Finset.univ.filter (fun u => Fin.cons b u ∈ E) - -lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : - u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by - classical - simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] - -lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : - (exceptionChild E false).card+(exceptionChild E true).card = E.card := by - classical - have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) - (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he - simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he - simpa only [exceptionChild,Finset.card_filter,add_comm] using he - -def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where - toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) - invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) - left_inv U := by - funext u - dsimp only - split_ifs with h - · rw [←h,Fin.cons_self_tail] - · have h' : u 0 = false := by cases hh : u 0 <;> simp_all - rw [←h',Fin.cons_self_tail] - right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] - -def seedSandwichShuffle {A B C D E : Type*} : - (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where - toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) - invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) - left_inv _ := rfl - right_inv _ := rfl - -abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) - -def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ - (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := - (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans - seedSandwichShuffle - -noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * - (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ - -noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := - InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 - -lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) - (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : - (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = - modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by - funext u - simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] - -lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - let z := (modifiedStepEquiv L r).symm (ω,coins) - modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = - InputTree.node coins.1 (fun b => - let w := if b then ω.2 else ω.1 - modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by - dsimp only - unfold modifiedInputTree - rw [boundaryTree] - change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ - congr 1 - funext b - rw [modifiedBoundary_cons] - cases b <;> rfl - -lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = - pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by - rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] - change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ - rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) - (x : Card (L+r+1)) : - headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by - rw [modifiedPerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (η : Card d → Bool) : - InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + - InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + - InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by - dsimp only - rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] - have he : (∑ i ∈ Finset.range d, - (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = - InputTree.lowCost d d (T false) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + - InputTree.lowCost d d (T true) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by - rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro i hi - rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] - rw [he] - omega - -noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + - modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 - -lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = - modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [modifiedCost,modifiedInputTree_node] - change InputTree.lowCost (L+r+1) (L+r+1) _ e - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ - rw [InputTree.lowCost_node] - unfold modifiedAssignmentCost - dsimp only - simp only [Bool.false_eq_true,↓reduceIte] - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - congr 2 - - -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) - (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - Function.Surjective (childEmbedding x c hc b) := by - intro y - have hs : Function.Surjective (coloredEmbedding x c hc) := - (pairLayer (chosenCoin x c)).surjective.comp hx - obtain ⟨i,hi⟩ := hs (b,y) - rw [coloredEmbedding_apply] at hi - exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ - -omit [DecidableEq ι] in -lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : - finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ - 1/(Fintype.card (Equiv.Perm α):ℝ) := by - classical - let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i - have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by - have hh : p*u⁻¹ = p*v⁻¹ := by - ext x - obtain ⟨i,rfl⟩ := he x - exact (hu i).trans (hv i).symm - exact inv_injective (mul_left_cancel hh) - unfold finiteMean - apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 - by_cases h : ∃ u, M u - · obtain ⟨u,hu⟩ := h - rw [Finset.sum_eq_single u] - · simp only [hu,↓reduceIte,le_refl] - · intro v _ hv - exact ite_eq_right (fun hh => hv (huniq v u hh hu)) - · simp - · push Not at h - simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] - -end PairRouting - -noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := - (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) - -lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ - -lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : - centralFactor L (r+1) E a = - centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by - unfold centralFactor - rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] - congr 1 - have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by - exact_mod_cast exceptionChild_card_add E - rw [pow_succ,←he] - ring - -lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : - modifiedPerm L 0 E ω = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 - else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by - unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput - split_ifs - · exact mul_inv_cancel _ - · rfl - -lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by - simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, - InputTree.levelCost,Finset.sum_const_zero] - -lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : - centralFactor L 0 E a = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by - classical - let z : Card 0 := fun j => Fin.elim0 j - have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by - by_cases hz : z ∈ E - · have he : E = {z} := by - ext u - rw [Subsingleton.elim u z] - simp only [hz,Finset.mem_singleton] - rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] - · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) - rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] - unfold centralFactor - rw [pow_zero,he] - split_ifs <;> simp - -lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : - PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by - classical - rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] - let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) - change _ ≤ B - calc - _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by - apply finiteMean_mono - intro ω - simp only [modifiedPerm_zero] - by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E - · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] - split_ifs <;> norm_num - · simp only [h,↓reduceIte,B] - rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => - if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] - convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 - rw [Fintype.card_perm,card_positions] - _ = _ := finiteMean_const B - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.HeightDecay + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : + centralDistance L r C D ≤ E.card*2^L := by + classical + calc + _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by + apply Finset.sum_le_sum + intro u _ + split_ifs with hu + · simpa only [card_positions] using permDistance_le (C u) (D u) + · rw [h u hu,permDistance_refl] + _ = _ := by simp + + +inductive InputTree : ℕ → Type + | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d + | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) + +def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) + | _, .tip p => p + | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) + +noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → + {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ + | _, .tip _, _, _, _, _ => 0 + | d+1, .node ξ T, _, _, e, Y => + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let σ := coinStepEquiv d Y + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) + (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : + (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by + rw [InputTree.levelCost] + rfl + +lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + T.levelCost t e Y = 0 := by + induction T generalizing ι with + | tip p => rfl + | @node d ξ T ih => + rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] + +lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by + induction T generalizing ι with + | tip p => intro Y Y' _; rfl + | @node d ξ T ih => + intro Y Y' h + dsimp only + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] + rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), + InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih false + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih true + intro i hi + exact h (Sum.inr (true,i)) hi + +theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) + (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + cases T with + | tip p => + simp only [InputTree.levelCost,pow_zero,finiteMean_const] + exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) + | node ξ T => + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x ξ + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => + if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ + else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + (T false).levelCost (s+u+1) e₀ (Y₀ hi) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + (T true).levelCost (s+u+1) e₁ (Y₁ hi) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + (InputTree.node ξ T).levelCost (s+u+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' (T false).perm (T true).perm + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' (T false) e₀ lo₀ + have h₁ := ih u hu' (T true) e₁ lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i : Fin l, T.levelCost (l+i.1+1) e Y + +lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) + +theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)))) := by + apply finiteMean_mono + intro hi + simpa only [InputTree.slabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + (SwitchIndex (L+r) → Bool) → InputTree (L+r) + | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) + | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => + boundaryTree L r (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) + +def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → + Card r → Equiv.Perm (Card L) + | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) + | r+1, Y, u => boundaryOutput L r + (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) + +lemma boundaryOutput_adapted (L r : ℕ) : + LayerAdapted (L+r) L (boundaryOutput L r) := by + induction r with + | zero => + intro Y Y' h + have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) + rw [he] + | succ r ih => + intro Y Y' h + funext u + dsimp only [boundaryOutput] + cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) + +noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u + +lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) : + LayerAdapted (L+r) L (modifiedBoundary L r E U) := by + intro Y Y' h + unfold modifiedBoundary + rw [boundaryOutput_adapted L r Y Y' h] + +lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) : + permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = + centralDistance L r U V := by + induction r with + | zero => + simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + simp only [boundaryTree,InputTree.perm,permDistance_mul_left] + rw [permDistance_childLift,centralDistance_step,ih,ih] + +lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y ≤ + (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by + induction r generalizing ι with + | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] + by_cases ht : t = L+r+1 + · simp only [ite_eq_left ht] + have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (coinStepEquiv (L+r) X).2) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, + permDistance_boundaryTree,←centralDistance_step] using hh + · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] + rw [centralDistance_step] + have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) + (coinStepEquiv (L+r) X).1.1 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 + have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) + (coinStepEquiv (L+r) X).1.2 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 + omega + +lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh + +lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by + apply centralDistance_exceptional + intro u hu + exact ite_eq_right hu + + +lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.slabCost l d T e Y = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact InputTree.levelCost_gt _ _ T (by omega) _ _ + +lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + apply adapted_mul_mean_le r s F _ hF hA + intro lo + let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false + have he (hi : Card s × SwitchIndex r → Bool) : + T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := + hT _ _ (assembleBits_agree r s lo hi hi₀) + simp_rw [he] + exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog + +lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) + (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) + (fun _ _ _ => rfl) q hq hlog + simpa only [one_mul,finiteMean_const] using hh + +noncomputable def InputTree.familyCost (L n d : ℕ) + (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y + +lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by + intro Y Y' h + dsimp only + rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] + exact InputTree.slabCost_adapted l d (T Y') e Y Y' + (agreeThrough_mono (le_max_right _ _) h) + +lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) + (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) + +theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => + simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,add_zero] + exact Real.one_le_exp hp + | succ n ih => + by_cases hn : n = 0 + · subst n + simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst + · let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n + have hs' : s ≤ familyEnd L n := by + have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) + simp only [pow_zero,mul_one] at hh + omega + have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = + InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T + (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) + · apply layerAdapted_comp + exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) + · exact hq + · exact hlog + · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp only [l] + ring + +lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*heightDecay L) := by + apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans + apply Real.exp_le_exp.mpr + apply add_le_add_right + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using hh + + +noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := + boundaryTree L r (modifiedBoundary L r E U Y) X + +lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : + LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by + intro Y Y' h + unfold modifiedInputTree + rw [modifiedBoundary_adapted L r E U Y Y' h] + +lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ + Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + have hqp : 0 < q := by linarith + have hpoint (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by + apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans + apply Nat.add_le_add_left + simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) + calc + _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := + finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) + _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * + q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ + _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := + mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) + _ = _ := by + have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by + rw [Real.exp_nat_mul,Real.exp_log hqp] + rw [Real.exp_add,he,mul_comm] + +lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by + exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ + (modifiedInputTree_adapted L r E U X) e q hq hlog _ + (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) + (modified_slab_mgf l L r hl E U X e q hq hlog) + +theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ + InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 + have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 + have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) + (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by + apply h₁.trans + apply Real.exp_le_exp.mpr + exact add_le_add_right (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ + have hh := finiteMean_mul_exp_le + (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) + (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) + _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simp only [←pow_add] at hh + refine hh.trans_eq ?_ + congr 1 + simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] + ring + +noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y + +lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by + rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L + +lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + + InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by + induction n with + | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] + omega + +lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by + symm + apply Finset.sum_subset (Finset.range_mono hd) + intro i _ hi + have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi + exact InputTree.levelCost_gt (i+1) d T (by omega) e Y + +lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y = 0 := by + induction r generalizing ι with + | zero => rfl + | succ r ih => + rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] + +lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by + apply Finset.sum_eq_zero + intro i hi + exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y + +theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hbound : L+r ≤ L*4^(L+r) := by + have h₀ := pow_four_ge (L+r) + have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL + nlinarith + have he (Y : SwitchIndex (L+r) → Bool) := + InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y + have hz (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := + boundaryTree_lowCost_zero L r _ X e Y + simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he + simp_rw [←he] + exact modified_high_mgf L (L+r) r hL E U X e q hq hlog + + +noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := + Finset.univ.filter (fun u => Fin.cons b u ∈ E) + +lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : + u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by + classical + simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : + (exceptionChild E false).card+(exceptionChild E true).card = E.card := by + classical + have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) + (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he + simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he + simpa only [exceptionChild,Finset.card_filter,add_comm] using he + +def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where + toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) + invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) + left_inv U := by + funext u + dsimp only + split_ifs with h + · rw [←h,Fin.cons_self_tail] + · have h' : u 0 = false := by cases hh : u 0 <;> simp_all + rw [←h',Fin.cons_self_tail] + right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] + +def seedSandwichShuffle {A B C D E : Type*} : + (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where + toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) + invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) + left_inv _ := rfl + right_inv _ := rfl + +abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) + +def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ + (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := + (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans + seedSandwichShuffle + +noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * + (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ + +noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := + InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 + +lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) + (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : + (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = + modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by + funext u + simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] + +lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + let z := (modifiedStepEquiv L r).symm (ω,coins) + modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = + InputTree.node coins.1 (fun b => + let w := if b then ω.2 else ω.1 + modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by + dsimp only + unfold modifiedInputTree + rw [boundaryTree] + change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ + congr 1 + funext b + rw [modifiedBoundary_cons] + cases b <;> rfl + +lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = + pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by + rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] + change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ + rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) + (x : Card (L+r+1)) : + headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by + rw [modifiedPerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (η : Card d → Bool) : + InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + + InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + + InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by + dsimp only + rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] + have he : (∑ i ∈ Finset.range d, + (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = + InputTree.lowCost d d (T false) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + + InputTree.lowCost d d (T true) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by + rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] + rw [he] + omega + +noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + + modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 + +lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = + modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [modifiedCost,modifiedInputTree_node] + change InputTree.lowCost (L+r+1) (L+r+1) _ e + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ + rw [InputTree.lowCost_node] + unfold modifiedAssignmentCost + dsimp only + simp only [Bool.false_eq_true,↓reduceIte] + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + congr 2 + + +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) + (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + Function.Surjective (childEmbedding x c hc b) := by + intro y + have hs : Function.Surjective (coloredEmbedding x c hc) := + (pairLayer (chosenCoin x c)).surjective.comp hx + obtain ⟨i,hi⟩ := hs (b,y) + rw [coloredEmbedding_apply] at hi + exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ + +omit [DecidableEq ι] in +lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : + finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ + 1/(Fintype.card (Equiv.Perm α):ℝ) := by + classical + let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i + have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by + have hh : p*u⁻¹ = p*v⁻¹ := by + ext x + obtain ⟨i,rfl⟩ := he x + exact (hu i).trans (hv i).symm + exact inv_injective (mul_left_cancel hh) + unfold finiteMean + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 + by_cases h : ∃ u, M u + · obtain ⟨u,hu⟩ := h + rw [Finset.sum_eq_single u] + · simp only [hu,↓reduceIte,le_refl] + · intro v _ hv + exact ite_eq_right (fun hh => hv (huniq v u hh hu)) + · simp + · push Not at h + simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] + +end PairRouting + +noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := + (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) + +lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ + +lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : + centralFactor L (r+1) E a = + centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by + unfold centralFactor + rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] + congr 1 + have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by + exact_mod_cast exceptionChild_card_add E + rw [pow_succ,←he] + ring + +lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : + modifiedPerm L 0 E ω = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 + else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by + unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput + split_ifs + · exact mul_inv_cancel _ + · rfl + +lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by + simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, + InputTree.levelCost,Finset.sum_const_zero] + +lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : + centralFactor L 0 E a = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by + classical + let z : Card 0 := fun j => Fin.elim0 j + have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by + by_cases hz : z ∈ E + · have he : E = {z} := by + ext u + rw [Subsingleton.elim u z] + simp only [hz,Finset.mem_singleton] + rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] + · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) + rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] + unfold centralFactor + rw [pow_zero,he] + split_ifs <;> simp + +lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : + PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by + classical + rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] + let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) + change _ ≤ B + calc + _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by + apply finiteMean_mono + intro ω + simp only [modifiedPerm_zero] + by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E + · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] + split_ifs <;> norm_num + · simp only [h,↓reduceIte,B] + rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => + if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] + convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 + rw [Fintype.card_perm,card_positions] + _ = _ := finiteMean_const B + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/Main.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/Main.lean index c8e869a704176f71d6ecb53e9bb8a18fe4bb79f8..06a1e04c79ab3277b505143b8d6d5af348584d2d 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/Main.lean @@ -1,1333 +1,1333 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ModifiedStageEquiv - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -noncomputable def typedMarks {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : Finset (N × Card d) := - typedSet (fun t => butterflyMarks d (A t) (ω t)) - -lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : - (typedMarks d A ω).card = ∑ t, (A t).card := by - classical - rw [typedMarks, typedSet_card] - apply Finset.sum_congr rfl - intro t _ - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective - -lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (D : Finset (N × Card d)) : - inclusionMoment (typedMarks d A) D ≤ - ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by - classical - have he : inclusionMoment (typedMarks d A) D = - ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by - rw [inclusionMoment_eq] - have hh (ω : N → (SwitchIndex d → Bool)) : - (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = - ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by - rw [Fintype.prod_boole] - simp only [typedMarks, subset_typedSet] - rw [finiteMean_congr hh] - simp only [inclusionMoment_eq] - exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) - (fun t (ω : SwitchIndex d → Bool) => - if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) - have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = - ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by - conv_lhs => rw [← typedSet_fiber D] - exact typedSet_prod _ _ - rw [he, hprod] - apply Finset.prod_le_prod₀ - · intro t _; exact inclusionMoment_nonneg _ _ - · intro t _ - simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) - -noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (v : N × Card d) : Finset (SwitchIndex d) := - routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 - -noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : - SimpleGraph (N × Card d) where - Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) - symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ - loopless := ⟨fun _ h => h.1 rfl⟩ - -lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : - (returnRoute d b v).card = d := card_routeDomain _ _ _ - -lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (t : N) (y : Card d) (i : SwitchIndex d) : - i ∈ returnRoute d b (t,y) ↔ - y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by - have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i - simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h - -lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (i : SwitchIndex d) : - (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = - 2 * ∑ t, p t := by - classical - rw [Fintype.sum_prod_type, Finset.mul_sum] - apply Finset.sum_congr rfl - intro t _ - have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ - butterflyPerm d (b t) (switchUsers d (b t) i).2 := - (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) - simp only [mem_returnRoute] - have he (y : Card d) : - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by - split_ifs <;> simp_all - simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] - ring - -lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : - (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ - 2*d*∑ t, p t := by - classical - calc - _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by - apply Finset.sum_le_sum - intro w _ - split_ifs with h - · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 - have hh := Finset.single_le_sum - (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) - (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi - simpa only [ite_eq_left hw] using hh - · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) - _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := - Finset.sum_comm - _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, - nsmul_eq_mul]; ring - -lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) : - (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, - Nat.cast_ofNat, nsmul_eq_mul] - field_simp - -lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) - (hk : ∑ t, (A t).card = k) - (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : N → (SwitchIndex d → Bool) => - if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by - have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk - have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k - (fun ω => (typedMarks_card d A ω).trans hk) - (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) - (typedMarks_inclusion d A) _ hδ hδ1 - (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) - (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) - simpa only [typed_weight_sum, hs] using hm - - -lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) - (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : - finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = - finiteMean f / (2:ℝ)^s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 - have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] - have he (ω : ι → Bool) : - (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = - (if ω i = v i then g ω else 0) := by - by_cases h : ω i = v i <;> simp [h,g] - rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] - have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) - change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ - rw [hs, Finset.card_insert_of_notMem hi, pow_succ] - ring - -noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := by - classical - exact finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) - -lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ endpointProb d A x y := by - classical - exact finiteMean_nonneg (fun _ => by positivity) - -lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by - classical - let f := fun ω : SwitchIndex d → Bool => - if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 - have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by - intro t ht ω - have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ - ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by - apply forall₂_congr - intro j hj - rw [butterfly_endpoint_iff, butterfly_endpoint_iff] - apply forall₂_congr - intro s hs - rw [QueryTree.flipCoin_apply_ne t s (fun h => - Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] - simp only [f, he] - have he (ω : SwitchIndex d → Bool) : - (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = - (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by - by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i - · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h - rw [ite_eq_left hh] - simp only [Finset.forall_mem_insert, h, true_and, f] - · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h - simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] - change finiteMean _ = _ - rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] - rfl - -noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := - ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y - -lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) (hi : i ∉ A) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - partialKernel d (insert i A) x y = partialKernel d A x y := by - classical - rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, - Finset.card_insert_of_notMem hi, pow_succ, partialKernel] - field_simp - -def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := - ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) - -lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) - (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : - (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by - classical - have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ - rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] - · rw [← Finset.sum_add_distrib] - apply Finset.sum_eq_zero - intro A hA - have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ - ((Finset.mem_powerset.mp hA) hh) - rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] - ring - · exact Finset.notMem_erase _ _ - -lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) - (x y : L → Card d) (h : ¬ContactEvent d x y) : - (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by - classical - unfold ContactEvent at h - push Not at h - obtain ⟨i, hi⟩ := h - apply alternating_cube_cancel _ i - intro A hiA - apply partialKernel_insert_isolated d A x y i hiA - intro j hj - exact hi j (fun hij => hiA (hij ▸ hj)) - - -noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by - classical - exact if i ∈ A then none else some i - -noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := - fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) - -noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := - fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) - -noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by - classical - exact fun t => match t with - | none => A - | some i => if i ∈ A then ∅ else {i} - -lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : - i ∈ labelsOf A t ↔ networkOf A i = t := by - classical - cases t with - | none => simp [labelsOf, networkOf] - | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction - -lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : - mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, - butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by - constructor - · intro h t i hi - have he := congrFun h i - simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he - · intro h - funext i - exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) - -lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : - mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by - constructor - · intro h - funext i - exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm - · intro h - funext i - exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm - -lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : - endpointProb d {i} x y = 1/(2:ℝ)^d := by - classical - simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) - -lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by - classical - have he (ω : Option L → (SwitchIndex d → Bool)) : - (if mixedTuple d A ω x = y then (1:ℝ) else 0) = - ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i - then (1:ℝ) else 0 := by - simp only [Fintype.prod_boole, mixedTuple_eq_iff] - rw [finiteMean_congr he] - rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] - have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = - endpointProb d (labelsOf A t) x y := by - unfold endpointProb - apply finiteMean_congr - intro w - split_ifs <;> rfl - simp only [hfac] - rw [Fintype.prod_option] - have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = - if i ∈ A then 1 else 1/(2:ℝ)^d := by - by_cases h : i ∈ A - · simp [labelsOf, h, endpointProb, finiteMean_const] - · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] - rw [show labelsOf A none = A from rfl] - simp only [hi] - have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = - (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by - rw [Finset.prod_ite] - simp only [Finset.prod_const_one, one_mul] - simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, - Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] - rw [hp, partialKernel, one_div, inv_pow] - have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ - have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = - ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] - have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity - have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity - field_simp - rw [← hn] - ring - -lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y z : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by - simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y - -noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (t : Option L) : Finset (Card d) := by - classical - exact (labelsOf A t).image x - -lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : - typedMarks d (mixedInitial d A x) ω = Finset.univ.image - (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - classical - ext v - simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, - Finset.mem_image, Finset.mem_univ, true_and] - constructor - · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ - have ht := mem_labelsOf A i v.1 |>.mp hi - exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ - · rintro ⟨i, hi⟩ - have ht := congrArg Prod.fst hi - have hv := congrArg Prod.snd hi - change networkOf A i = v.1 at ht - change mixedTuple d A ω x i = v.2 at hv - exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, - by simpa only [mixedTuple, ht] using hv⟩ - -lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω : Option L → (SwitchIndex d → Bool)) : - Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - intro i j h - have ht := congrArg Prod.fst h - have hv := congrArg Prod.snd h - change networkOf A i = networkOf A j at ht - dsimp only [mixedTuple] at hv - rw [ht] at hv - exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) - -lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) : - (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by - classical - let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false - rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, - Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] - -lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω b : Option L → (SwitchIndex d → Bool)) : - ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ - NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) - (typedMarks d (mixedInitial d A x) ω) := by - classical - rw [typedMarks_mixedInitial] - let f := fun i => (networkOf A i, mixedTuple d A ω x i) - have hf : Function.Injective f := typedTuple_injective d A x hx ω - constructor - · intro h v hv - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv - obtain ⟨j,hij,hc⟩ := h i - exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, - hf.ne hij, hc⟩ - · intro h i - obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv - exact ⟨j, fun he => hij (congrArg f he), hc⟩ - -lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (b : Option L → (SwitchIndex d → Bool)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) - then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - simp only [contactEvent_mixedReturn_iff d A x hx] - convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) - (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 - congr 1 - exact Subsingleton.elim _ _ - - -lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] - (g : Ω → X) (f : X → ℝ) : - finiteMean (fun ω => f (g ω)) = - ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by - classical - simp_rw [← finiteMean_mul_const, ← finiteMean_sum] - apply finiteMean_congr - intro ω - simp - -lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = - ∑ y, partialKernel d A x y * f y := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] - apply Finset.sum_congr rfl - intro y _ - congr 1 - convert mixedTuple_mass d A x y using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = - ∑ z, partialKernel d A z y * f z := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] - apply Finset.sum_congr rfl - intro z _ - congr 1 - convert mixedReturn_mass d A y z using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ partialKernel d A x y := - mul_nonneg (by positivity) (endpointProb_nonneg d A x y) - -noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : ℝ := by - classical - exact if ContactEvent d x y then partialKernel d A x y else 0 - -lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact partialKernel_nonneg d A x y - · exact le_rfl - -lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact le_rfl - · exact partialKernel_nonneg d A x y - -lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 - have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ - ∑ z : L → Card d, partialKernel d A z y * f y z := by - have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by - unfold retainedKernel f - split_ifs <;> ring - simp_rw [he] - rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) - (Function.Embedding.coe_injective.injOn)] - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro z _ _ - exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) - calc - _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by - rw [Finset.sum_comm] - simp only [Finset.mul_sum] - _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by - apply Finset.sum_le_sum - intro y _ - exact mul_le_mul (retainedKernel_le d A x y) (hsub y) - (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) - _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by - rw [mixedTuple_expectation d A x (fun y => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] - simp only [mixedReturn_expectation] - _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ - _ ≤ _ := by - apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq - exact finiteMean_const _ - -noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := - LinearMap.toContinuousLinearMap - { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - map_add' := by - intro v w - ext x - simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] - map_smul' := by - intro c v - ext x - simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] - change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - ring } - -@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : - rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl - -lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = - rectOperator (fun y x => P x y) := by - apply Eq.symm - rw [ContinuousLinearMap.eq_adjoint_iff] - intro v w - simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, - map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = - rectOperator (fun x x' => ∑ y, P x y * P x' y) := by - ext v x - simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, - Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x' _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) - (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : - ‖rectOperator P‖^2 ≤ B := by - let S := fun x x' => ∑ y, P x y * P x' y - have hs : ∀ x x', S x x' = S x' x := by - intro x x' - unfold S - apply Finset.sum_congr rfl - intro y _ - ring - have hbound : ‖rectOperator S‖ ≤ B := by - apply ContinuousLinearMap.opNorm_le_bound _ hB - intro v - exact DensityTransfer.schur_bound S - (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB - hrow (fun x' => by - calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') - _ ≤ B := hrow x') v - have hn := ContinuousLinearMap.norm_adjoint_comp_self - (ContinuousLinearMap.adjoint (rectOperator P)) - rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), - rectOperator_adjoint, rectOperator_comp_transpose] at hn - rw [pow_two, ← hn] - exact hbound - -lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖rectOperator (retainedKernel d A)‖^2 ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := - rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) - (fun x => retained_square_row d A x hδ hδ1) - - -noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x ∈ A, p x = x} - one_mem' := by intro x _; rfl - mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] - inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm - -lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) - (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by - intro z hz - exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) - -lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : - Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by - classical - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := - { toFun := fun x => ⟨p x.1,x.2⟩ - invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } - have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by - rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] - have hr := Specht.rowLen_zero_le_card μ - omega - obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) - (by simpa only [Fintype.card_fin] using hc) - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), - swap_mem_pointStabilizer A _ _ x.2 y.2⟩ - apply Specht.symmetrizer_eq_zero_of_neg _ _ h - change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) - rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] - rw [map_mul, Module.End.mul_apply, - Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - -lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by - classical - have hz := point_symmetrizer_zero μ A hA v hv - have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = - (Fintype.card (pointStabilizer A) : ℂ) • v := by - simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), - Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] - rw [he] at hz - exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) - -lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by - let w := (Specht.spaceHilbertEquiv μ).symm v - have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by - intro p hp - have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) - change Specht.representation μ p w = w at he - exact congrArg Subtype.val he - have hz := point_fixed_zero μ A hA w.val w.prop hw - have hw0 : w = 0 := Subtype.ext hz - have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 - simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he - -lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) - (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) - (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by - classical - apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v - intro p hp - have hf : e.symm.permCongr p ∈ pointStabilizer A := by - intro x hx - have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) - simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] - have hh := hfix _ hf - change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh - have he : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] - simpa only [he] using hh - - -section Orbit -variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] - [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) - (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) - -noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w - -include hw in -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by - apply ext_inner_right ℂ - intro v - exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g - -include hw in -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma orbitVector_action (g : G) (x : X) : - orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by - obtain ⟨h,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, - orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] -end Orbit - -def Harmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := - ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, - (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 - -lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) - (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) - (w : Specht.hilbertSpace μ) - (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) - (v : Specht.hilbertSpace μ) : - Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by - classical - intro A hA z - let ρ := Specht.relabelledUnitary μ e - let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w - let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 - have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by - apply (Finset.card_image_le).trans_lt - rw [← hk] - exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) - have hz : S = 0 := by - apply point_relabelled_fixed_zero μ e (A.image z) hcard - intro p hp - change ρ p S = S - simp only [S, map_sum, apply_ite, map_zero] - apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) - intro y - have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by - apply forall₂_congr - intro i hi - have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) - change p (y i) = z i ↔ y i = z i - exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff - simp only [he] - split_ifs - · exact (orbitVector_action UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm - · rfl - let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) - calc - _ = c * inner ℂ S v := by - dsimp only [S] - rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, - smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] - _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] - -end Thorp.SparseContact - -namespace Thorp.SparseContact - -section -open scoped BigOperators Classical - -lemma sum_injections {L α M : Type*} [Fintype L] [Fintype α] [AddCommMonoid M] - (F : (L → α) → M) (hF : ∀ y, ¬Function.Injective y → F y = 0) : - (∑ y : L → α, F y) = ∑ y : L ↪ α, F y := by - classical - rw [← Finset.sum_image Function.Embedding.coe_injective.injOn] - apply Eq.symm - apply Finset.sum_subset (Finset.subset_univ _) - intro y _ hy - apply hF y - intro h - exact hy (Finset.mem_image.mpr ⟨⟨y,h⟩, Finset.mem_univ _, rfl⟩) - -noncomputable def zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : EuclideanSpace ℂ (L → α) := by - classical - exact WithLp.toLp 2 (fun y => if h : Function.Injective y then f ⟨y,h⟩ else 0) - -@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] - congr 1 - -lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] - -lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : - (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by - rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] - simp only [zeroExtend_inj] - -lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by - have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by - rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, - sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] - simp only [zeroExtend_inj] - nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] - -lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 - simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, - Complex.ofReal_sum, Complex.ofReal_natCast] - simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] - rw [mul_eq_zero] - right - simp only [Finset.sum_mul] - rw [Finset.sum_comm] - apply mul_eq_zero_of_right - apply Finset.sum_eq_zero - intro ω _ - calc - _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * - (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := - by - apply Finset.sum_congr rfl - intro y _ - have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ - (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := - forall₂_congr fun _ _ => eq_comm - by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i - · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] - · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] - _ = 0 := by - rw [← Finset.mul_sum] - apply mul_eq_zero_of_right - convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> rfl - -lemma partial_full_action {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) : - rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d Finset.univ x y) (zeroExtend f) = - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - apply Finset.sum_congr rfl - intro y _ - congr 2 - simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), - one_mul, endpointProb, UnitaryFinite.actionKernel] - apply finiteMean_congr - intro ω - congr 1 - simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] - rfl - -lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) - (x : L ↪ Card d) (y : L → Card d) : - (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = - ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by - classical - by_cases h : ContactEvent d x y - · simp only [retainedKernel, ite_eq_left h] - · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] - exact (alternating_kernel_cancel d x y h).symm - -lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = - ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - calc - _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by - ext x - simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] - rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] - apply Finset.sum_congr rfl - intro y _ - simp_rw [← mul_assoc, ← Finset.sum_mul] - congr 1 - have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) - simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, - Complex.ofReal_one] using he - _ = ((-1:ℂ)^(Fintype.card L)) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by - rw [Finset.sum_eq_single (Finset.univ : Finset L)] - · simp only [Finset.card_univ] - · intro A _ hA - rw [partial_proper_zero d A hA f hf, smul_zero] - · simp - _ = _ := by rw [partial_full_action] - -lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by - classical - let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) - have hB : 0 ≤ B := by dsimp [B]; positivity - have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by - have hh := retained_norm_sq d A hδ hδ1 - have hs := Real.sq_sqrt hB - have hn := Real.sqrt_nonneg B - nlinarith - calc - _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by - rw [alternating_harmonic_action d f hf] - _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := - norm_sum_le _ _ - _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by - apply Finset.sum_le_sum - intro A _ - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := - ContinuousLinearMap.le_opNorm _ _ - _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) - _ = _ := by rw [norm_zeroExtend] - _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, - Nat.cast_pow, Nat.cast_ofNat]; ring - -lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) - (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by - classical - obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL - have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by - ext v x - have hh (y : L → Card d) : ¬ContactEvent d x y := by - intro h - obtain ⟨j,hj,_⟩ := h i - exact hj (hi j).symm - simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, - zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] - have he := alternating_harmonic_action d f hf - simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, - neg_smul, one_smul] at he - exact neg_eq_zero.mp he.symm - -end -open scoped BigOperators - -def MainStatement : Prop := - ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ - ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), - let k := μ.card - μ.rowLen 0 - 1 ≤ k → k < 2^d → ∀ reverse : Bool, - ‖sweepOperator d μ e reverse‖^2 ≤ - min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ - (k = 1 → sweepOperator d μ e reverse = 0) ∧ - ‖sweepOperator d μ e reverse‖^2 ≤ - C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - -end Thorp.SparseContact - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) - (hL : Fintype.card L = μ.card - μ.rowLen 0) : - ∃ w : Specht.hilbertSpace μ, - UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by - let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) - have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by - rw [Specht.finrank_hilbertSpace] - exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) - have hdim := Specht.relabelled_tuple_dimension μ e x₀ - rw [hL, Nat.choose_self, mul_one] at hdim - have hm : 0 < Module.finrank ℂ K := by - by_contra h - have hz : Module.finrank ℂ K = 0 := by omega - change _ ≤ Module.finrank ℂ K * _ at hdim - rw [hz, zero_mul] at hdim - omega - let B := stdOrthonormalBasis ℂ K - let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ - exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ - -lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by - cases rev - · rfl - · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] - rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), - ContinuousLinearMap.adjoint.norm_map] - -lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ 1 := - UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ - -section Generic -variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] - -lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) := by - rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), - ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_bound d _ (hh v) hδ hδ1 - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha - exact ha - -lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hL : Fintype.card L = 1) : - UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by - apply ContinuousLinearMap.adjoint.injective - rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.ext - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_zero_one d hL _ (hh v) - have he := congrArg norm ha - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he - exact norm_eq_zero.mp he -end Generic - -lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * - Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * - Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by - classical - let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - rw [sweep_forward_norm μ e rev] - have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) - simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he - -lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by - classical - let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he ((Specht.tail_card μ).trans hk) - have hz : sweepOperator d μ e false = 0 := by - simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he - apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp - rw [sweep_forward_norm μ e rev, hz] - exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ - -end Thorp.SparseContact - -namespace Thorp.SparseContact - -noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) - -lemma contactConstant_gt_one : 1 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma contactConstant_gt_two : 2 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : - ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = - ((contactConstant/2)*δ)^((k:ℝ)/2) := by - have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity - rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] - have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by - unfold contactConstant - rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, - Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] - norm_num - ring - rw [hc, ←Real.exp_mul] - have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by - rw [← pow_mul, mul_comm k 2, pow_mul] - norm_num only [pow_two] - rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] - rw [hpow] - calc - _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring - _ = _ := by rw [←Real.exp_add]; congr 2; ring - -lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : - (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by - rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] - apply mul_le_mul_of_nonneg_right _ (by positivity) - apply mul_le_mul - · rw [← Real.rpow_natCast] - exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) - · calc - d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) - _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) - · positivity - · positivity - - -lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : - ‖sweepOperator d μ e rev‖^2 ≤ min 1 - ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by - let k := μ.card - μ.rowLen 0 - have hk' : (0:ℝ) < k := by exact_mod_cast hk - have hd' : (0:ℝ) < d := by exact_mod_cast hd - have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity - have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by - have h := sweep_norm_le_one d μ e rev - have h0 := norm_nonneg (sweepOperator d μ e rev) - nlinarith - refine le_min hOne ?_ - have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = - (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring - change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - rw [he] - by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 - · have h := sweep_norm_bound d μ e hδ hs rev - have hb : 0 ≤ (2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity - calc - _ ≤ ((2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := - (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h - _ = _ := inflated_contact_bound hδ.le k - · apply hOne.trans - apply Real.one_le_rpow - · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith - exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) - · positivity - -theorem uniform_sparse_contact : MainStatement := by - refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), - (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ - intro d hd μ e k hk _ rev - have hs := sweep_sharp_bound d hd μ e hk rev - refine ⟨hs, ?_, ?_⟩ - · intro hk1 - exact sweep_zero_one d μ e hk1 rev - · apply (hs.trans (min_le_right _ _)).trans - change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ - rw [mul_div_assoc] - exact contact_crude_arithmetic contactConstant_gt_one.le - (by exact_mod_cast hd) (by positivity) k - -end Thorp.SparseContact - - -namespace Thorp.SparseRegime -open Filter -open Thorp.SparseContact - -lemma log_contact_eventually : ∀ᶠ d : ℕ in atTop, - Real.log (contactConstant*d) ≤ (d:ℝ)^((3:ℝ)/4)/2 := by - have hn : Tendsto (fun d : ℕ => (d:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop - have hl := ((isLittleO_log_rpow_atTop (by norm_num : (0:ℝ)<3/4)).comp_tendsto hn).def - (by norm_num : (0:ℝ)<1/4) - have hr := ((tendsto_rpow_atTop (by norm_num : (0:ℝ)<3/4)).comp hn).eventually - (eventually_ge_atTop (4*Real.log contactConstant)) - filter_upwards [hl, hr, eventually_ge_atTop 1] with d hl hr hd - have hd' : (0:ℝ) butterflyMarks d (A t) (ω t)) + +lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : + (typedMarks d A ω).card = ∑ t, (A t).card := by + classical + rw [typedMarks, typedSet_card] + apply Finset.sum_congr rfl + intro t _ + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective + +lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (D : Finset (N × Card d)) : + inclusionMoment (typedMarks d A) D ≤ + ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by + classical + have he : inclusionMoment (typedMarks d A) D = + ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by + rw [inclusionMoment_eq] + have hh (ω : N → (SwitchIndex d → Bool)) : + (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = + ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by + rw [Fintype.prod_boole] + simp only [typedMarks, subset_typedSet] + rw [finiteMean_congr hh] + simp only [inclusionMoment_eq] + exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) + (fun t (ω : SwitchIndex d → Bool) => + if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) + have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = + ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by + conv_lhs => rw [← typedSet_fiber D] + exact typedSet_prod _ _ + rw [he, hprod] + apply Finset.prod_le_prod₀ + · intro t _; exact inclusionMoment_nonneg _ _ + · intro t _ + simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) + +noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (v : N × Card d) : Finset (SwitchIndex d) := + routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 + +noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : + SimpleGraph (N × Card d) where + Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) + symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ + loopless := ⟨fun _ h => h.1 rfl⟩ + +lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : + (returnRoute d b v).card = d := card_routeDomain _ _ _ + +lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (t : N) (y : Card d) (i : SwitchIndex d) : + i ∈ returnRoute d b (t,y) ↔ + y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by + have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i + simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h + +lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (i : SwitchIndex d) : + (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = + 2 * ∑ t, p t := by + classical + rw [Fintype.sum_prod_type, Finset.mul_sum] + apply Finset.sum_congr rfl + intro t _ + have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ + butterflyPerm d (b t) (switchUsers d (b t) i).2 := + (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) + simp only [mem_returnRoute] + have he (y : Card d) : + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by + split_ifs <;> simp_all + simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + ring + +lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : + (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ + 2*d*∑ t, p t := by + classical + calc + _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by + apply Finset.sum_le_sum + intro w _ + split_ifs with h + · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 + have hh := Finset.single_le_sum + (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) + (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi + simpa only [ite_eq_left hw] using hh + · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) + _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := + Finset.sum_comm + _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, + nsmul_eq_mul]; ring + +lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) : + (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, + Nat.cast_ofNat, nsmul_eq_mul] + field_simp + +lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) + (hk : ∑ t, (A t).card = k) + (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : N → (SwitchIndex d → Bool) => + if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by + have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk + have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k + (fun ω => (typedMarks_card d A ω).trans hk) + (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) + (typedMarks_inclusion d A) _ hδ hδ1 + (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) + (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) + simpa only [typed_weight_sum, hs] using hm + + +lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) + (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : + finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = + finiteMean f / (2:ℝ)^s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 + have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] + have he (ω : ι → Bool) : + (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = + (if ω i = v i then g ω else 0) := by + by_cases h : ω i = v i <;> simp [h,g] + rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] + have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) + change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ + rw [hs, Finset.card_insert_of_notMem hi, pow_succ] + ring + +noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := by + classical + exact finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) + +lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ endpointProb d A x y := by + classical + exact finiteMean_nonneg (fun _ => by positivity) + +lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by + classical + let f := fun ω : SwitchIndex d → Bool => + if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 + have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by + intro t ht ω + have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ + ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by + apply forall₂_congr + intro j hj + rw [butterfly_endpoint_iff, butterfly_endpoint_iff] + apply forall₂_congr + intro s hs + rw [QueryTree.flipCoin_apply_ne t s (fun h => + Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] + simp only [f, he] + have he (ω : SwitchIndex d → Bool) : + (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = + (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by + by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i + · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h + rw [ite_eq_left hh] + simp only [Finset.forall_mem_insert, h, true_and, f] + · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h + simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] + change finiteMean _ = _ + rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] + rfl + +noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := + ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y + +lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) (hi : i ∉ A) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + partialKernel d (insert i A) x y = partialKernel d A x y := by + classical + rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, + Finset.card_insert_of_notMem hi, pow_succ, partialKernel] + field_simp + +def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := + ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) + +lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) + (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : + (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by + classical + have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ + rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] + · rw [← Finset.sum_add_distrib] + apply Finset.sum_eq_zero + intro A hA + have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ + ((Finset.mem_powerset.mp hA) hh) + rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] + ring + · exact Finset.notMem_erase _ _ + +lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) + (x y : L → Card d) (h : ¬ContactEvent d x y) : + (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by + classical + unfold ContactEvent at h + push Not at h + obtain ⟨i, hi⟩ := h + apply alternating_cube_cancel _ i + intro A hiA + apply partialKernel_insert_isolated d A x y i hiA + intro j hj + exact hi j (fun hij => hiA (hij ▸ hj)) + + +noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by + classical + exact if i ∈ A then none else some i + +noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := + fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) + +noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := + fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) + +noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by + classical + exact fun t => match t with + | none => A + | some i => if i ∈ A then ∅ else {i} + +lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : + i ∈ labelsOf A t ↔ networkOf A i = t := by + classical + cases t with + | none => simp [labelsOf, networkOf] + | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction + +lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : + mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, + butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by + constructor + · intro h t i hi + have he := congrFun h i + simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he + · intro h + funext i + exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) + +lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : + mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by + constructor + · intro h + funext i + exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm + · intro h + funext i + exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm + +lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : + endpointProb d {i} x y = 1/(2:ℝ)^d := by + classical + simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) + +lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by + classical + have he (ω : Option L → (SwitchIndex d → Bool)) : + (if mixedTuple d A ω x = y then (1:ℝ) else 0) = + ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i + then (1:ℝ) else 0 := by + simp only [Fintype.prod_boole, mixedTuple_eq_iff] + rw [finiteMean_congr he] + rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] + have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = + endpointProb d (labelsOf A t) x y := by + unfold endpointProb + apply finiteMean_congr + intro w + split_ifs <;> rfl + simp only [hfac] + rw [Fintype.prod_option] + have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = + if i ∈ A then 1 else 1/(2:ℝ)^d := by + by_cases h : i ∈ A + · simp [labelsOf, h, endpointProb, finiteMean_const] + · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] + rw [show labelsOf A none = A from rfl] + simp only [hi] + have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = + (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by + rw [Finset.prod_ite] + simp only [Finset.prod_const_one, one_mul] + simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, + Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] + rw [hp, partialKernel, one_div, inv_pow] + have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ + have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = + ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] + have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity + have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity + field_simp + rw [← hn] + ring + +lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y z : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by + simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y + +noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (t : Option L) : Finset (Card d) := by + classical + exact (labelsOf A t).image x + +lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : + typedMarks d (mixedInitial d A x) ω = Finset.univ.image + (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + classical + ext v + simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, + Finset.mem_image, Finset.mem_univ, true_and] + constructor + · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ + have ht := mem_labelsOf A i v.1 |>.mp hi + exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ + · rintro ⟨i, hi⟩ + have ht := congrArg Prod.fst hi + have hv := congrArg Prod.snd hi + change networkOf A i = v.1 at ht + change mixedTuple d A ω x i = v.2 at hv + exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, + by simpa only [mixedTuple, ht] using hv⟩ + +lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω : Option L → (SwitchIndex d → Bool)) : + Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + intro i j h + have ht := congrArg Prod.fst h + have hv := congrArg Prod.snd h + change networkOf A i = networkOf A j at ht + dsimp only [mixedTuple] at hv + rw [ht] at hv + exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) + +lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) : + (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by + classical + let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false + rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, + Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] + +lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω b : Option L → (SwitchIndex d → Bool)) : + ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ + NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) + (typedMarks d (mixedInitial d A x) ω) := by + classical + rw [typedMarks_mixedInitial] + let f := fun i => (networkOf A i, mixedTuple d A ω x i) + have hf : Function.Injective f := typedTuple_injective d A x hx ω + constructor + · intro h v hv + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv + obtain ⟨j,hij,hc⟩ := h i + exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, + hf.ne hij, hc⟩ + · intro h i + obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv + exact ⟨j, fun he => hij (congrArg f he), hc⟩ + +lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (b : Option L → (SwitchIndex d → Bool)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) + then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + simp only [contactEvent_mixedReturn_iff d A x hx] + convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) + (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 + congr 1 + exact Subsingleton.elim _ _ + + +lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] + (g : Ω → X) (f : X → ℝ) : + finiteMean (fun ω => f (g ω)) = + ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by + classical + simp_rw [← finiteMean_mul_const, ← finiteMean_sum] + apply finiteMean_congr + intro ω + simp + +lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = + ∑ y, partialKernel d A x y * f y := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] + apply Finset.sum_congr rfl + intro y _ + congr 1 + convert mixedTuple_mass d A x y using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = + ∑ z, partialKernel d A z y * f z := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] + apply Finset.sum_congr rfl + intro z _ + congr 1 + convert mixedReturn_mass d A y z using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ partialKernel d A x y := + mul_nonneg (by positivity) (endpointProb_nonneg d A x y) + +noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : ℝ := by + classical + exact if ContactEvent d x y then partialKernel d A x y else 0 + +lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact partialKernel_nonneg d A x y + · exact le_rfl + +lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact le_rfl + · exact partialKernel_nonneg d A x y + +lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 + have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ + ∑ z : L → Card d, partialKernel d A z y * f y z := by + have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by + unfold retainedKernel f + split_ifs <;> ring + simp_rw [he] + rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) + (Function.Embedding.coe_injective.injOn)] + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro z _ _ + exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) + calc + _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul (retainedKernel_le d A x y) (hsub y) + (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) + _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by + rw [mixedTuple_expectation d A x (fun y => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] + simp only [mixedReturn_expectation] + _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ + _ ≤ _ := by + apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq + exact finiteMean_const _ + +noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := + LinearMap.toContinuousLinearMap + { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + map_add' := by + intro v w + ext x + simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] + map_smul' := by + intro c v + ext x + simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] + change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + ring } + +@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : + rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl + +lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = + rectOperator (fun y x => P x y) := by + apply Eq.symm + rw [ContinuousLinearMap.eq_adjoint_iff] + intro v w + simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, + map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = + rectOperator (fun x x' => ∑ y, P x y * P x' y) := by + ext v x + simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, + Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x' _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) + (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : + ‖rectOperator P‖^2 ≤ B := by + let S := fun x x' => ∑ y, P x y * P x' y + have hs : ∀ x x', S x x' = S x' x := by + intro x x' + unfold S + apply Finset.sum_congr rfl + intro y _ + ring + have hbound : ‖rectOperator S‖ ≤ B := by + apply ContinuousLinearMap.opNorm_le_bound _ hB + intro v + exact DensityTransfer.schur_bound S + (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB + hrow (fun x' => by + calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') + _ ≤ B := hrow x') v + have hn := ContinuousLinearMap.norm_adjoint_comp_self + (ContinuousLinearMap.adjoint (rectOperator P)) + rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), + rectOperator_adjoint, rectOperator_comp_transpose] at hn + rw [pow_two, ← hn] + exact hbound + +lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖rectOperator (retainedKernel d A)‖^2 ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := + rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) + (fun x => retained_square_row d A x hδ hδ1) + + +noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x ∈ A, p x = x} + one_mem' := by intro x _; rfl + mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] + inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm + +lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) + (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by + intro z hz + exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) + +lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : + Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by + classical + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := + { toFun := fun x => ⟨p x.1,x.2⟩ + invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } + have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by + rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] + have hr := Specht.rowLen_zero_le_card μ + omega + obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) + (by simpa only [Fintype.card_fin] using hc) + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), + swap_mem_pointStabilizer A _ _ x.2 y.2⟩ + apply Specht.symmetrizer_eq_zero_of_neg _ _ h + change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) + rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] + rw [map_mul, Module.End.mul_apply, + Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + +lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by + classical + have hz := point_symmetrizer_zero μ A hA v hv + have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = + (Fintype.card (pointStabilizer A) : ℂ) • v := by + simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), + Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] + rw [he] at hz + exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) + +lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by + let w := (Specht.spaceHilbertEquiv μ).symm v + have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by + intro p hp + have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) + change Specht.representation μ p w = w at he + exact congrArg Subtype.val he + have hz := point_fixed_zero μ A hA w.val w.prop hw + have hw0 : w = 0 := Subtype.ext hz + have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 + simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he + +lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) + (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) + (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by + classical + apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v + intro p hp + have hf : e.symm.permCongr p ∈ pointStabilizer A := by + intro x hx + have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) + simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] + have hh := hfix _ hf + change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh + have he : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] + simpa only [he] using hh + + +section Orbit +variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] + [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) + (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) + +noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w + +include hw in +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by + apply ext_inner_right ℂ + intro v + exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g + +include hw in +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma orbitVector_action (g : G) (x : X) : + orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by + obtain ⟨h,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, + orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] +end Orbit + +def Harmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := + ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, + (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 + +lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) + (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) + (w : Specht.hilbertSpace μ) + (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) + (v : Specht.hilbertSpace μ) : + Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by + classical + intro A hA z + let ρ := Specht.relabelledUnitary μ e + let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w + let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 + have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by + apply (Finset.card_image_le).trans_lt + rw [← hk] + exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) + have hz : S = 0 := by + apply point_relabelled_fixed_zero μ e (A.image z) hcard + intro p hp + change ρ p S = S + simp only [S, map_sum, apply_ite, map_zero] + apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) + intro y + have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by + apply forall₂_congr + intro i hi + have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) + change p (y i) = z i ↔ y i = z i + exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff + simp only [he] + split_ifs + · exact (orbitVector_action UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm + · rfl + let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) + calc + _ = c * inner ℂ S v := by + dsimp only [S] + rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, + smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] + _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] + +end Thorp.SparseContact + +namespace Thorp.SparseContact + +section +open scoped BigOperators Classical + +lemma sum_injections {L α M : Type*} [Fintype L] [Fintype α] [AddCommMonoid M] + (F : (L → α) → M) (hF : ∀ y, ¬Function.Injective y → F y = 0) : + (∑ y : L → α, F y) = ∑ y : L ↪ α, F y := by + classical + rw [← Finset.sum_image Function.Embedding.coe_injective.injOn] + apply Eq.symm + apply Finset.sum_subset (Finset.subset_univ _) + intro y _ hy + apply hF y + intro h + exact hy (Finset.mem_image.mpr ⟨⟨y,h⟩, Finset.mem_univ _, rfl⟩) + +noncomputable def zeroExtend {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) : EuclideanSpace ℂ (L → α) := by + classical + exact WithLp.toLp 2 (fun y => if h : Function.Injective y then f ⟨y,h⟩ else 0) + +@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] + congr 1 + +lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] + +lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : + (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by + rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] + simp only [zeroExtend_inj] + +lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by + have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by + rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, + sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] + simp only [zeroExtend_inj] + nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] + +lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 + simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, + Complex.ofReal_sum, Complex.ofReal_natCast] + simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] + rw [mul_eq_zero] + right + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply mul_eq_zero_of_right + apply Finset.sum_eq_zero + intro ω _ + calc + _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * + (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := + by + apply Finset.sum_congr rfl + intro y _ + have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ + (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := + forall₂_congr fun _ _ => eq_comm + by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i + · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] + · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] + _ = 0 := by + rw [← Finset.mul_sum] + apply mul_eq_zero_of_right + convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> rfl + +lemma partial_full_action {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) : + rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d Finset.univ x y) (zeroExtend f) = + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + apply Finset.sum_congr rfl + intro y _ + congr 2 + simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), + one_mul, endpointProb, UnitaryFinite.actionKernel] + apply finiteMean_congr + intro ω + congr 1 + simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] + rfl + +lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) + (x : L ↪ Card d) (y : L → Card d) : + (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = + ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by + classical + by_cases h : ContactEvent d x y + · simp only [retainedKernel, ite_eq_left h] + · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] + exact (alternating_kernel_cancel d x y h).symm + +lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = + ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + calc + _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by + ext x + simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] + rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] + apply Finset.sum_congr rfl + intro y _ + simp_rw [← mul_assoc, ← Finset.sum_mul] + congr 1 + have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) + simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, + Complex.ofReal_one] using he + _ = ((-1:ℂ)^(Fintype.card L)) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by + rw [Finset.sum_eq_single (Finset.univ : Finset L)] + · simp only [Finset.card_univ] + · intro A _ hA + rw [partial_proper_zero d A hA f hf, smul_zero] + · simp + _ = _ := by rw [partial_full_action] + +lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by + classical + let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) + have hB : 0 ≤ B := by dsimp [B]; positivity + have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by + have hh := retained_norm_sq d A hδ hδ1 + have hs := Real.sq_sqrt hB + have hn := Real.sqrt_nonneg B + nlinarith + calc + _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by + rw [alternating_harmonic_action d f hf] + _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := + norm_sum_le _ _ + _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by + apply Finset.sum_le_sum + intro A _ + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := + ContinuousLinearMap.le_opNorm _ _ + _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) + _ = _ := by rw [norm_zeroExtend] + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat]; ring + +lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) + (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by + classical + obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL + have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by + ext v x + have hh (y : L → Card d) : ¬ContactEvent d x y := by + intro h + obtain ⟨j,hj,_⟩ := h i + exact hj (hi j).symm + simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, + zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] + have he := alternating_harmonic_action d f hf + simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, + neg_smul, one_smul] at he + exact neg_eq_zero.mp he.symm + +end +open scoped BigOperators + +def MainStatement : Prop := + ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ + ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), + let k := μ.card - μ.rowLen 0 + 1 ≤ k → k < 2^d → ∀ reverse : Bool, + ‖sweepOperator d μ e reverse‖^2 ≤ + min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ + (k = 1 → sweepOperator d μ e reverse = 0) ∧ + ‖sweepOperator d μ e reverse‖^2 ≤ + C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + +end Thorp.SparseContact + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) + (hL : Fintype.card L = μ.card - μ.rowLen 0) : + ∃ w : Specht.hilbertSpace μ, + UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by + let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) + have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by + rw [Specht.finrank_hilbertSpace] + exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) + have hdim := Specht.relabelled_tuple_dimension μ e x₀ + rw [hL, Nat.choose_self, mul_one] at hdim + have hm : 0 < Module.finrank ℂ K := by + by_contra h + have hz : Module.finrank ℂ K = 0 := by omega + change _ ≤ Module.finrank ℂ K * _ at hdim + rw [hz, zero_mul] at hdim + omega + let B := stdOrthonormalBasis ℂ K + let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ + exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ + +lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by + cases rev + · rfl + · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] + rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), + ContinuousLinearMap.adjoint.norm_map] + +lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ 1 := + UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ + +section Generic +variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] + +lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) := by + rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), + ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_bound d _ (hh v) hδ hδ1 + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha + exact ha + +lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hL : Fintype.card L = 1) : + UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by + apply ContinuousLinearMap.adjoint.injective + rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.ext + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_zero_one d hL _ (hh v) + have he := congrArg norm ha + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he + exact norm_eq_zero.mp he +end Generic + +lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * + Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * + Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by + classical + let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + rw [sweep_forward_norm μ e rev] + have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) + simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he + +lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by + classical + let x₀ : Specht.Tail μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.Tail μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he ((Specht.tail_card μ).trans hk) + have hz : sweepOperator d μ e false = 0 := by + simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he + apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp + rw [sweep_forward_norm μ e rev, hz] + exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ + +end Thorp.SparseContact + +namespace Thorp.SparseContact + +noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) + +lemma contactConstant_gt_one : 1 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma contactConstant_gt_two : 2 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : + ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = + ((contactConstant/2)*δ)^((k:ℝ)/2) := by + have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity + rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] + have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by + unfold contactConstant + rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, + Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] + norm_num + ring + rw [hc, ←Real.exp_mul] + have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by + rw [← pow_mul, mul_comm k 2, pow_mul] + norm_num only [pow_two] + rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] + rw [hpow] + calc + _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring + _ = _ := by rw [←Real.exp_add]; congr 2; ring + +lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : + (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by + rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply mul_le_mul + · rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) + · calc + d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) + _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) + · positivity + · positivity + + +lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : + ‖sweepOperator d μ e rev‖^2 ≤ min 1 + ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by + let k := μ.card - μ.rowLen 0 + have hk' : (0:ℝ) < k := by exact_mod_cast hk + have hd' : (0:ℝ) < d := by exact_mod_cast hd + have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity + have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by + have h := sweep_norm_le_one d μ e rev + have h0 := norm_nonneg (sweepOperator d μ e rev) + nlinarith + refine le_min hOne ?_ + have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = + (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring + change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + rw [he] + by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 + · have h := sweep_norm_bound d μ e hδ hs rev + have hb : 0 ≤ (2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity + calc + _ ≤ ((2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := + (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h + _ = _ := inflated_contact_bound hδ.le k + · apply hOne.trans + apply Real.one_le_rpow + · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith + exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) + · positivity + +theorem uniform_sparse_contact : MainStatement := by + refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), + (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ + intro d hd μ e k hk _ rev + have hs := sweep_sharp_bound d hd μ e hk rev + refine ⟨hs, ?_, ?_⟩ + · intro hk1 + exact sweep_zero_one d μ e hk1 rev + · apply (hs.trans (min_le_right _ _)).trans + change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ + rw [mul_div_assoc] + exact contact_crude_arithmetic contactConstant_gt_one.le + (by exact_mod_cast hd) (by positivity) k + +end Thorp.SparseContact + + +namespace Thorp.SparseRegime +open Filter +open Thorp.SparseContact + +lemma log_contact_eventually : ∀ᶠ d : ℕ in atTop, + Real.log (contactConstant*d) ≤ (d:ℝ)^((3:ℝ)/4)/2 := by + have hn : Tendsto (fun d : ℕ => (d:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hl := ((isLittleO_log_rpow_atTop (by norm_num : (0:ℝ)<3/4)).comp_tendsto hn).def + (by norm_num : (0:ℝ)<1/4) + have hr := ((tendsto_rpow_atTop (by norm_num : (0:ℝ)<3/4)).comp hn).eventually + (eventually_ge_atTop (4*Real.log contactConstant)) + filter_upwards [hl, hr, eventually_ge_atTop 1] with d hl hr hd + have hd' : (0:ℝ) ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical - -abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} - -def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 - -def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 - -lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := - YoungDiagram.mem_iff_lt_colLen.mp x.2 - -noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := - ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ - -abbrev Tabloid (μ : YoungDiagram) := - {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} - -noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ - -noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ - -noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - Equiv.Perm (Tabloid μ) where - toFun f := ⟨fun x => f.1 (p⁻¹ x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p⁻¹, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - invFun f := ⟨fun x => f.1 (p x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - left_inv f := by apply Subtype.ext; funext x; simp - right_inv f := by apply Subtype.ext; funext x; simp - -@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl - -@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by - ext f x - rfl - -@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : - tabloidAct (p*q) = tabloidAct p * tabloidAct q := by - ext f x - simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] - -noncomputable def tabloidRep (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where - toFun p := - { toFun := fun v f => v (tabloidAct p⁻¹ f) - map_add' := by intros; rfl - map_smul' := by intros; rfl } - map_one' := by ext v f; simp - map_mul' p q := by - ext v f - simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] - rfl - -noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := - fun g => if g=f then 1 else 0 - -noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where - carrier := {p | ∀ x, col (p x) = col x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := - ((Equiv.Perm.sign p : ℤ) : ℂ) - - -section -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by - classical - exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c - -end - -noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := - alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) - -noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := - Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) - -lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ - -lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨q,rfl⟩ := hv - change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ - rw [←map_mul] - exact orbit_mem_space μ (p*q) - | zero => simp - | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw - | smul a v hv ih => simpa using (space μ).smul_mem a ih - -noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := - ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ - -noncomputable def representation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := - (subrepresentation μ).toRepresentation - -end Thorp.Specht - -namespace Thorp.PermutationHilbert -open scoped BigOperators ComplexConjugate Classical -open Complex -variable {X : Type*} [Fintype X] - -abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X - -end Thorp.PermutationHilbert - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def hilbertEquiv (μ : YoungDiagram) : - (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := - (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm - -noncomputable def hilbertSpace (μ : YoungDiagram) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap - -end Thorp.Specht - -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where - toFun g := (ρ g).toContinuousLinearMap - map_one' := by ext v; simp - map_mul' g h := by ext v; simp - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := - (hilbertEquiv μ).submoduleMap (space μ) - -noncomputable def unitaryRepresentation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := - ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := - (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators - -noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) - (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : - Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := - UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) - (fun ω : SwitchIndex d → Bool => if reverse then - (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) - -end Thorp.SparseContact - -namespace Thorp.SparseRegime - -def MainStatement : Prop := - ∃ (C : ℝ) (d₀ : ℕ), 0 < C ∧ 0 < d₀ ∧ - ∀ (d : ℕ) (μ : YoungDiagram) (e : Thorp.Card d ≃ Thorp.Specht.Cell μ), - let k := μ.card - μ.rowLen 0 - 1 ≤ k → k < 2^d → (d:ℝ)^((3:ℝ)/4) ≤ Real.log ((2:ℝ)^d/k) → - ∀ rev : Bool, - ‖Thorp.SparseContact.sweepOperator d μ e rev‖^2 ≤ - Real.exp (C*k)*((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/4) ∧ - (d₀ ≤ d → ‖Thorp.SparseContact.sweepOperator d μ e rev‖^2 ≤ - ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/4)) - -end Thorp.SparseRegime - -end ThorpNine.SparseSaving - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical + +abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} + +def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 + +def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 + +lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := + YoungDiagram.mem_iff_lt_colLen.mp x.2 + +noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := + ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ + +abbrev Tabloid (μ : YoungDiagram) := + {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} + +noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ + +noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ + +noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + Equiv.Perm (Tabloid μ) where + toFun f := ⟨fun x => f.1 (p⁻¹ x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p⁻¹, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + invFun f := ⟨fun x => f.1 (p x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + left_inv f := by apply Subtype.ext; funext x; simp + right_inv f := by apply Subtype.ext; funext x; simp + +@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl + +@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by + ext f x + rfl + +@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : + tabloidAct (p*q) = tabloidAct p * tabloidAct q := by + ext f x + simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] + +noncomputable def tabloidRep (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where + toFun p := + { toFun := fun v f => v (tabloidAct p⁻¹ f) + map_add' := by intros; rfl + map_smul' := by intros; rfl } + map_one' := by ext v f; simp + map_mul' p q := by + ext v f + simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] + rfl + +noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := + fun g => if g=f then 1 else 0 + +noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where + carrier := {p | ∀ x, col (p x) = col x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := + ((Equiv.Perm.sign p : ℤ) : ℂ) + + +section +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by + classical + exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c + +end + +noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := + alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) + +noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := + Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) + +lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ + +lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨q,rfl⟩ := hv + change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ + rw [←map_mul] + exact orbit_mem_space μ (p*q) + | zero => simp + | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw + | smul a v hv ih => simpa using (space μ).smul_mem a ih + +noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := + ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ + +noncomputable def representation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := + (subrepresentation μ).toRepresentation + +end Thorp.Specht + +namespace Thorp.PermutationHilbert +open scoped BigOperators ComplexConjugate Classical +open Complex +variable {X : Type*} [Fintype X] + +abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X + +end Thorp.PermutationHilbert + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def hilbertEquiv (μ : YoungDiagram) : + (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := + (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm + +noncomputable def hilbertSpace (μ : YoungDiagram) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap + +end Thorp.Specht + +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where + toFun g := (ρ g).toContinuousLinearMap + map_one' := by ext v; simp + map_mul' g h := by ext v; simp + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := + (hilbertEquiv μ).submoduleMap (space μ) + +noncomputable def unitaryRepresentation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := + ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := + (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators + +noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) + (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : + Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := + UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) + (fun ω : SwitchIndex d → Bool => if reverse then + (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) + +end Thorp.SparseContact + +namespace Thorp.SparseRegime + +def MainStatement : Prop := + ∃ (C : ℝ) (d₀ : ℕ), 0 < C ∧ 0 < d₀ ∧ + ∀ (d : ℕ) (μ : YoungDiagram) (e : Thorp.Card d ≃ Thorp.Specht.Cell μ), + let k := μ.card - μ.rowLen 0 + 1 ≤ k → k < 2^d → (d:ℝ)^((3:ℝ)/4) ≤ Real.log ((2:ℝ)^d/k) → + ∀ rev : Bool, + ‖Thorp.SparseContact.sweepOperator d μ e rev‖^2 ≤ + Real.exp (C*k)*((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/4) ∧ + (d₀ ≤ d → ‖Thorp.SparseContact.sweepOperator d μ e rev‖^2 ≤ + ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/4)) + +end Thorp.SparseRegime + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedReverseEquiv.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedReverseEquiv.lean index 18c26e5d4266b7575f610ae0a65a8408042ae35a..f46f6845b5d1e0f83b1e9f114ad66a26b3a9227d 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedReverseEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedReverseEquiv.lean @@ -1,759 +1,759 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ModifiedRoutingMoment - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where - toFun := modifiedReverseCoins L r - invFun := modifiedReverseCoins L r - left_inv := modifiedReverseCoins_involutive L r - right_inv := modifiedReverseCoins_involutive L r - -lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by - induction r with - | zero => - rw [modifiedPerm_zero,modifiedPerm_zero] - split_ifs - · simp only [inv_one] - · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp - | succ r ih => - obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω - rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, - mul_inv_rev,pairSwitch_inv,childLift_inv] - rw [mul_assoc] - congr 1 - congr 1 - apply congrArg childLift - funext b - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] - -lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : - PairRouting.tupleProbability (modifiedPerm L r E) e f = - PairRouting.tupleProbability (modifiedPerm L r E) f e := - PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) - (modifiedPerm_reverse L r E) e f - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical - -@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by - simp [Cell, YoungDiagram.card] - -noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : - {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where - toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ - invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm - right_inv i := by rfl - -noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := - (Finset.univ.filter (fun x => col x = j)).image f - -lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : - f x ∈ columnValues f (col x) := by - classical - exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ - -lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : - (columnValues f j).card = μ.colLen j := by - classical - rw [columnValues, Finset.card_image_iff.mpr] - · rw [← Fintype.card_subtype] - exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) - intro x hx y hy he - exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he - -lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : - ∀ i, i.val ≤ f i := by - intro i - induction h : i.val using Nat.strong_induction_on generalizing i with - | h n ih => - by_cases hn : n = 0 - · omega - · have hn' : n-1 < i.val := by omega - let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ - have hj := ih (n-1) (by omega) j rfl - have hij := hf (show j < i from hn') - dsimp [j] at hj hij - omega - -noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := - let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩ - ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ - -@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - col (rankCell f hf x) = col x := rfl - -lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by - change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) - (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩)).val = f x - simp - -lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : - Function.Injective (rankCell f hf) := by - intro x y h - have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h - apply hf x y hc - have hx := rankCell_orderEmb f hf x - have hy := rankCell_orderEmb f hf y - change (columnValues f (col (rankCell f hf x))).orderEmbOfFin - (card_columnValues f hf (col (rankCell f hf x))) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx - rw [h] at hx - exact hx.symm.trans hy - -noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := - Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) - -lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - row (rankCell f hf x) ≤ f x := by - rw [←rankCell_orderEmb f hf x] - exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ - -theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : - ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ - ∀ x, row (c x) = row (p x) := by - classical - let c := rankPerm (fun x => row (p x)) hp - refine ⟨c, fun x => rfl, ?_⟩ - have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x - have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by - rw [Equiv.sum_comp, Equiv.sum_comp] - exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) - - -@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by - ext f x - simp [tabloidAct,Equiv.Perm.inv_def] - -@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl - -lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tabloidRep μ p (delta f) = delta (tabloidAct p f) := by - classical - ext g - simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] - congr 1 - exact propext (Equiv.symm_apply_eq (tabloidAct p)) - -@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl - -lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) - (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by - apply Equiv.ext - intro x - have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc - simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr - apply Subtype.ext - exact Prod.ext hr.symm (c.2 x) - -lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) - (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : - ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by - obtain ⟨p,hp⟩ := f.2 - have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by - intro x y hcol hrow - apply hf x y hcol - rw [hp] - exact Fin.ext hrow - obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' - refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ - apply Subtype.ext - funext x - apply Fin.ext - simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] - exact (hrow x).symm - - -@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : - permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] -@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : - permSign (p*q) = permSign p * permSign q := by simp [permSign] -@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] -lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p * permSign p = 1 := by - calc - permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] - _ = 1 := by simp -@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : - permSign (Equiv.swap x y) = -1 := by simp [permSign, h] -@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] - -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -lemma alternator_mul (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.sum_mul,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulRight c) - intro a - simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring - _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] - _ = _ := by ring - -lemma mul_alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.mul_sum,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulLeft c) - intro a - simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring - _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] - _ = _ := by ring - -lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) - -lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) - -lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) - (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : - alternator C ρ v = 0 := by - have h := alternator_apply_action C ρ c v - rw [hv,hc,neg_one_smul] at h - have h2 : (2:ℂ) • alternator C ρ v = 0 := by - rw [two_smul] - nth_rw 1 [h] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -end Thorp.Specht -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : - Equiv.swap x y ∈ colGroup μ := by - classical - intro z - by_cases hx : z=x - · subst z; simpa using hc.symm - by_cases hy : z=y - · subst z; simpa using hc - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) - (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by - classical - apply Subtype.ext - funext z - simp only [tabloidAct_apply, Equiv.swap_inv] - by_cases hx : z=x - · subst z; simpa using hxy.symm - by_cases hy : z=y - · subst z; simpa using hxy - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by - classical - by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y - · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf - refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ - rw [←tabloidRep_delta] - exact alternator_apply_action _ _ c _ - · push Not at hf - obtain ⟨x,y,hcol,hrow,hne⟩ := hf - refine ⟨0, ?_⟩ - rw [zero_smul] - apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ - · exact permSign_swap hne - · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] - -lemma polytabloid_formula (μ : YoungDiagram) : - polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • - delta (tabloidAct c (baseTabloid μ)) := by - classical - simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] - -lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by - classical - rw [polytabloid_formula,Finset.sum_apply] - rw [Finset.sum_eq_single (1 : colGroup μ)] - · simp [delta] - · intro c hc hne - have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by - intro h - apply hne - exact Subtype.ext (colGroup_row_stabilizer c h.symm) - simp [Pi.smul_apply,delta,hn] - · simp - -lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by - intro h - have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp [polytabloid_base] at hv - -lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - v = ∑ f : Tabloid μ, v f • delta f := by - classical - funext g - simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] - simp - -theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by - classical - choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f - refine ⟨∑ f, v f * z f, ?_⟩ - conv_lhs => rw [delta_decomposition v] - simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] - -lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = - (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by - obtain ⟨z,hz⟩ := alternator_rank_one μ v - rw [hz] - simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] - - -noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := - ∑ f, w f * starRingEnd ℂ (v f) - -lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : - pairing (delta f) v = v f := by - classical - simp [pairing,delta] - -lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] - (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : - pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by - simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] - exact Finset.sum_comm - -lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : - pairing (a • v) w = starRingEnd ℂ a * pairing v w := by - simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] - apply Finset.sum_congr rfl - intro f hf - ring - -lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by - simp [pairing] - -lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : - pairing (u+v) w = pairing u w + pairing v w := by - simp [pairing,mul_add,Finset.sum_add_distrib] - -lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - pairing v v = 0 ↔ v = 0 := by - change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 - rw [inner_self_eq_zero] - constructor - · intro h; exact congrArg WithLp.ofLp h - · intro h; subst v; rfl - -lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : - pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by - classical - simp only [pairing,tabloidRep_apply,inv_inv] - apply Fintype.sum_equiv (tabloidAct p⁻¹) - intro f - have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by - rw [tabloidAct_inv] - exact (tabloidAct p).apply_symm_apply f - rw [hcancel] - -lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by - classical - simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, - smul_eq_mul,tabloidRep_apply] - apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) - intro c - simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] - -theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by - rw [alternator_rank_one_exact,alternator_base_pairing] - - -lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by - simpa using orbit_mem_space μ 1 - -lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : - alternator (colGroup μ) (tabloidRep μ) v ∈ W := by - classical - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] - exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) - -theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : - space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by - classical - by_cases hSW : space μ ≤ W - · exact Or.inl hSW - right - have he : polytabloid μ ∉ W := by - intro he - apply hSW - apply Submodule.span_le.mpr - rintro _ ⟨p,rfl⟩ - exact hW p _ he - have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by - intro v hv - by_contra hne - apply he - have hal := alternator_mem_invariant μ W hW v hv - rw [alternator_pairing] at hal - have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal - simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh - intro v hv w hw - induction hw using Submodule.span_induction with - | mem w hw => - obtain ⟨p,rfl⟩ := hw - rw [pairing_action] - exact hpair _ (hW p⁻¹ v hv) - | zero => exact pairing_zero_left v - | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] - | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] - -theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : - W = ⊥ ∨ W = space μ := by - obtain hSW | horth := submodule_theorem μ W hW - · exact Or.inr (le_antisymm hWS hSW) - · left - apply le_antisymm _ bot_le - intro v hv - exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) - - -lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by - intro h - have he := polytabloid_mem_space μ - rw [h,Submodule.mem_bot] at he - exact polytabloid_ne_zero μ he - -theorem representation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (representation μ) := by - have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ - (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial - have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he - exact polytabloid_ne_zero μ (congrArg Subtype.val he') - refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } - intro U - let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype - have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by - intro p v hv - obtain ⟨u,hu,rfl⟩ := hv - exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ - have hWS : W ≤ space μ := by - intro v hv - obtain ⟨u,hu,rfl⟩ := hv - exact u.2 - obtain hbot | htop := space_simple μ W hW hWS - · left - apply le_antisymm _ bot_le - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ - rw [hbot,Submodule.mem_bot] at hmem - change u = 0 - exact Subtype.ext hmem - · right - apply le_antisymm le_top - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 - obtain ⟨v,hv,hvu⟩ := hmem - have heq : v = u := Subtype.ext hvu - exact heq ▸ hv - - -section Symmetrizer -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := - ∑ h : H, ρ h - -lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : - symmetrizer H ρ * ρ h = symmetrizer H ρ := by - rw [symmetrizer,Finset.sum_mul] - exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) - -lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : - symmetrizer H ρ v = 0 := by - have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) - change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh - rw [hv,map_neg] at hh - have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by - rw [two_smul] - nth_rw 1 [←hh] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x, f (p x) = f x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -omit [Fintype α] in -lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : - Equiv.swap x y ∈ fiberGroup f := by - intro z - by_cases hx : z=x - · subst z; simpa using hf.symm - by_cases hy : z=y - · subst z; simpa using hf - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -end Symmetrizer - -lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) - (hcol : col x = col y) : - tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by - have h := action_alternator_apply (colGroup μ) (tabloidRep μ) - ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) - simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h - -theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] - (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : - symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by - rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - exact hj - obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ - apply symmetrizer_eq_zero_of_neg _ _ h - change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) - rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] - rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - - -noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : - {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where - toFun x := ⟨col x.1, by - have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 - change col x.1 < μ.rowLen (row x.1) at h - simpa only [x.2] using h⟩ - invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl - right_inv j := rfl - -def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x - -lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (he : ∀ x, row (e x) = row x) : μ = ν := by - have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by - let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := - { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ - invFun := fun x => ⟨e.symm x.1,by - have h := he (e.symm x.1) - simp only [Equiv.apply_symm_apply] at h - exact h.symm.trans x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } - simpa only [Fintype.card_fin] using Fintype.card_congr - ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) - apply YoungDiagram.ext - ext ⟨i,j⟩ - simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] - -lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - let c := rankPerm (fun x => row (e x)) h - have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x - have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ - have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ - constructor - · rw [←hsumc,←hsume] - exact Finset.sum_le_sum (fun x _ => hle x) - · intro heq - have he : ∀ x, row (c x) = row (e x) := by - apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp - (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) - apply eq_of_row_preserving μ ν (c.symm.trans e) - intro x - simpa using (he (c.symm x)).symm - -lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] - (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by - ext z - simp only [Equiv.permCongr_apply] - exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) - -lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (v : Tabloid ν → ℂ) (hv : v ≠ 0) - (hs : ∀ c : colGroup μ, - tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by - by_contra h - push Not at h - exact hv (funext h) - obtain ⟨p,hp⟩ := f.2 - apply column_injective_rowCost μ ν (e.trans p) - intro x y hcol hrow - by_contra hne - have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by - apply swap_fixes_tabloid - rw [hp] - exact Fin.ext hrow - have heq := congrArg (fun w : Tabloid ν → ℂ => w f) - (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) - rw [swap_relabel,permSign_swap hne] at heq - simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq - apply hf - have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq - exact (mul_eq_zero.mp h2).resolve_left (by norm_num) - -lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : - tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply _ _ c _ - -theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (T : space μ ≃ₗ[ℂ] space ν) - (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : - μ = ν := by - let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ - have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) - have hTcol (c : colGroup μ) : - tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by - change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ - rw [←hT] - have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := - Subtype.ext (polytabloid_col_action μ c) - rw [hh,map_smul] - rfl - have hfwd := sign_vector_rowCost μ ν e (T u) - (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol - let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ - have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) - have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : - T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by - apply T.injective - rw [T.apply_symm_apply,hT,T.apply_symm_apply] - have hp : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] - have hTicol (c : colGroup ν) : - tabloidRep μ (e.symm.permCongr c) (T.symm w) = - permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by - change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ - rw [←hTi] - have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := - Subtype.ext (polytabloid_col_action ν c) - rw [hh,map_smul] - rfl - have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) - (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol - exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) - - -noncomputable def cellRowsEquiv (μ : YoungDiagram) : - Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where - toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ - invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ - left_inv x := by apply Subtype.ext; rfl - right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl - -lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by - rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] - simp only [Fintype.card_fin] - -lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by - rw [card_eq_sum_rowLen,YoungDiagram.rowLens] - rw [Fin.sum_univ_eq_sum_range] - have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by - induction n with - | zero => simp - | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] - exact hh _ - -noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where - parts := μ.rowLens - parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simp - -noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := - YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE - -lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : - (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by - apply YoungDiagram.rowLens_ofRowLens_eq_self - intro x hx - exact p.parts_pos ((Multiset.mem_sort _).mp hx) - -lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by - rw [←sum_rowLens,partitionDiagram_rowLens] - change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N - rw [Multiset.sort_eq,p.parts_sum] - -lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : - partitionDiagram (diagramPartition μ) = μ := by - apply YoungDiagram.equivListRowLens.injective - apply Subtype.ext - change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens - rw [partitionDiagram_rowLens] - change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens - rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] - -abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} - -end Thorp.Specht - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ModifiedRoutingMoment + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where + toFun := modifiedReverseCoins L r + invFun := modifiedReverseCoins L r + left_inv := modifiedReverseCoins_involutive L r + right_inv := modifiedReverseCoins_involutive L r + +lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by + induction r with + | zero => + rw [modifiedPerm_zero,modifiedPerm_zero] + split_ifs + · simp only [inv_one] + · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp + | succ r ih => + obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω + rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, + mul_inv_rev,pairSwitch_inv,childLift_inv] + rw [mul_assoc] + congr 1 + congr 1 + apply congrArg childLift + funext b + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] + +lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : + PairRouting.tupleProbability (modifiedPerm L r E) e f = + PairRouting.tupleProbability (modifiedPerm L r E) f e := + PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) + (modifiedPerm_reverse L r E) e f + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical + +@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by + simp [Cell, YoungDiagram.card] + +noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : + {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where + toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ + invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm + right_inv i := by rfl + +noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := + (Finset.univ.filter (fun x => col x = j)).image f + +lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : + f x ∈ columnValues f (col x) := by + classical + exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ + +lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : + (columnValues f j).card = μ.colLen j := by + classical + rw [columnValues, Finset.card_image_iff.mpr] + · rw [← Fintype.card_subtype] + exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) + intro x hx y hy he + exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he + +lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : + ∀ i, i.val ≤ f i := by + intro i + induction h : i.val using Nat.strong_induction_on generalizing i with + | h n ih => + by_cases hn : n = 0 + · omega + · have hn' : n-1 < i.val := by omega + let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ + have hj := ih (n-1) (by omega) j rfl + have hij := hf (show j < i from hn') + dsimp [j] at hj hij + omega + +noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := + let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩ + ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ + +@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + col (rankCell f hf x) = col x := rfl + +lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by + change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) + (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩)).val = f x + simp + +lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : + Function.Injective (rankCell f hf) := by + intro x y h + have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h + apply hf x y hc + have hx := rankCell_orderEmb f hf x + have hy := rankCell_orderEmb f hf y + change (columnValues f (col (rankCell f hf x))).orderEmbOfFin + (card_columnValues f hf (col (rankCell f hf x))) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx + rw [h] at hx + exact hx.symm.trans hy + +noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := + Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) + +lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + row (rankCell f hf x) ≤ f x := by + rw [←rankCell_orderEmb f hf x] + exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ + +theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : + ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ + ∀ x, row (c x) = row (p x) := by + classical + let c := rankPerm (fun x => row (p x)) hp + refine ⟨c, fun x => rfl, ?_⟩ + have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x + have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by + rw [Equiv.sum_comp, Equiv.sum_comp] + exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) + + +@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by + ext f x + simp [tabloidAct,Equiv.Perm.inv_def] + +@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl + +lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tabloidRep μ p (delta f) = delta (tabloidAct p f) := by + classical + ext g + simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] + congr 1 + exact propext (Equiv.symm_apply_eq (tabloidAct p)) + +@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl + +lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) + (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by + apply Equiv.ext + intro x + have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc + simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr + apply Subtype.ext + exact Prod.ext hr.symm (c.2 x) + +lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) + (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : + ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by + obtain ⟨p,hp⟩ := f.2 + have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by + intro x y hcol hrow + apply hf x y hcol + rw [hp] + exact Fin.ext hrow + obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' + refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ + apply Subtype.ext + funext x + apply Fin.ext + simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] + exact (hrow x).symm + + +@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : + permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] +@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : + permSign (p*q) = permSign p * permSign q := by simp [permSign] +@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] +lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p * permSign p = 1 := by + calc + permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] + _ = 1 := by simp +@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : + permSign (Equiv.swap x y) = -1 := by simp [permSign, h] +@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] + +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +lemma alternator_mul (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.sum_mul,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulRight c) + intro a + simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring + _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] + _ = _ := by ring + +lemma mul_alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.mul_sum,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulLeft c) + intro a + simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring + _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] + _ = _ := by ring + +lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) + +lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) + +lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) + (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : + alternator C ρ v = 0 := by + have h := alternator_apply_action C ρ c v + rw [hv,hc,neg_one_smul] at h + have h2 : (2:ℂ) • alternator C ρ v = 0 := by + rw [two_smul] + nth_rw 1 [h] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +end Thorp.Specht +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : + Equiv.swap x y ∈ colGroup μ := by + classical + intro z + by_cases hx : z=x + · subst z; simpa using hc.symm + by_cases hy : z=y + · subst z; simpa using hc + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) + (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by + classical + apply Subtype.ext + funext z + simp only [tabloidAct_apply, Equiv.swap_inv] + by_cases hx : z=x + · subst z; simpa using hxy.symm + by_cases hy : z=y + · subst z; simpa using hxy + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by + classical + by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y + · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf + refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ + rw [←tabloidRep_delta] + exact alternator_apply_action _ _ c _ + · push Not at hf + obtain ⟨x,y,hcol,hrow,hne⟩ := hf + refine ⟨0, ?_⟩ + rw [zero_smul] + apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ + · exact permSign_swap hne + · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] + +lemma polytabloid_formula (μ : YoungDiagram) : + polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • + delta (tabloidAct c (baseTabloid μ)) := by + classical + simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] + +lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by + classical + rw [polytabloid_formula,Finset.sum_apply] + rw [Finset.sum_eq_single (1 : colGroup μ)] + · simp [delta] + · intro c hc hne + have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by + intro h + apply hne + exact Subtype.ext (colGroup_row_stabilizer c h.symm) + simp [Pi.smul_apply,delta,hn] + · simp + +lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by + intro h + have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp [polytabloid_base] at hv + +lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + v = ∑ f : Tabloid μ, v f • delta f := by + classical + funext g + simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] + simp + +theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by + classical + choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f + refine ⟨∑ f, v f * z f, ?_⟩ + conv_lhs => rw [delta_decomposition v] + simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] + +lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = + (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by + obtain ⟨z,hz⟩ := alternator_rank_one μ v + rw [hz] + simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] + + +noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := + ∑ f, w f * starRingEnd ℂ (v f) + +lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : + pairing (delta f) v = v f := by + classical + simp [pairing,delta] + +lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] + (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : + pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by + simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] + exact Finset.sum_comm + +lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : + pairing (a • v) w = starRingEnd ℂ a * pairing v w := by + simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro f hf + ring + +lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by + simp [pairing] + +lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : + pairing (u+v) w = pairing u w + pairing v w := by + simp [pairing,mul_add,Finset.sum_add_distrib] + +lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + pairing v v = 0 ↔ v = 0 := by + change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 + rw [inner_self_eq_zero] + constructor + · intro h; exact congrArg WithLp.ofLp h + · intro h; subst v; rfl + +lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : + pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by + classical + simp only [pairing,tabloidRep_apply,inv_inv] + apply Fintype.sum_equiv (tabloidAct p⁻¹) + intro f + have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by + rw [tabloidAct_inv] + exact (tabloidAct p).apply_symm_apply f + rw [hcancel] + +lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by + classical + simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, + smul_eq_mul,tabloidRep_apply] + apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) + intro c + simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] + +theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by + rw [alternator_rank_one_exact,alternator_base_pairing] + + +lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by + simpa using orbit_mem_space μ 1 + +lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : + alternator (colGroup μ) (tabloidRep μ) v ∈ W := by + classical + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] + exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) + +theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : + space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by + classical + by_cases hSW : space μ ≤ W + · exact Or.inl hSW + right + have he : polytabloid μ ∉ W := by + intro he + apply hSW + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + exact hW p _ he + have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by + intro v hv + by_contra hne + apply he + have hal := alternator_mem_invariant μ W hW v hv + rw [alternator_pairing] at hal + have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal + simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh + intro v hv w hw + induction hw using Submodule.span_induction with + | mem w hw => + obtain ⟨p,rfl⟩ := hw + rw [pairing_action] + exact hpair _ (hW p⁻¹ v hv) + | zero => exact pairing_zero_left v + | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] + | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] + +theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : + W = ⊥ ∨ W = space μ := by + obtain hSW | horth := submodule_theorem μ W hW + · exact Or.inr (le_antisymm hWS hSW) + · left + apply le_antisymm _ bot_le + intro v hv + exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) + + +lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by + intro h + have he := polytabloid_mem_space μ + rw [h,Submodule.mem_bot] at he + exact polytabloid_ne_zero μ he + +theorem representation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (representation μ) := by + have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ + (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial + have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he + exact polytabloid_ne_zero μ (congrArg Subtype.val he') + refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } + intro U + let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype + have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by + intro p v hv + obtain ⟨u,hu,rfl⟩ := hv + exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ + have hWS : W ≤ space μ := by + intro v hv + obtain ⟨u,hu,rfl⟩ := hv + exact u.2 + obtain hbot | htop := space_simple μ W hW hWS + · left + apply le_antisymm _ bot_le + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ + rw [hbot,Submodule.mem_bot] at hmem + change u = 0 + exact Subtype.ext hmem + · right + apply le_antisymm le_top + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 + obtain ⟨v,hv,hvu⟩ := hmem + have heq : v = u := Subtype.ext hvu + exact heq ▸ hv + + +section Symmetrizer +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := + ∑ h : H, ρ h + +lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : + symmetrizer H ρ * ρ h = symmetrizer H ρ := by + rw [symmetrizer,Finset.sum_mul] + exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) + +lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : + symmetrizer H ρ v = 0 := by + have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) + change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh + rw [hv,map_neg] at hh + have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by + rw [two_smul] + nth_rw 1 [←hh] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x, f (p x) = f x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +omit [Fintype α] in +lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : + Equiv.swap x y ∈ fiberGroup f := by + intro z + by_cases hx : z=x + · subst z; simpa using hf.symm + by_cases hy : z=y + · subst z; simpa using hf + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +end Symmetrizer + +lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) + (hcol : col x = col y) : + tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by + have h := action_alternator_apply (colGroup μ) (tabloidRep μ) + ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) + simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h + +theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] + (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : + symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by + rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + exact hj + obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ + apply symmetrizer_eq_zero_of_neg _ _ h + change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) + rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] + rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + + +noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : + {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where + toFun x := ⟨col x.1, by + have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 + change col x.1 < μ.rowLen (row x.1) at h + simpa only [x.2] using h⟩ + invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl + right_inv j := rfl + +def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x + +lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (he : ∀ x, row (e x) = row x) : μ = ν := by + have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by + let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := + { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ + invFun := fun x => ⟨e.symm x.1,by + have h := he (e.symm x.1) + simp only [Equiv.apply_symm_apply] at h + exact h.symm.trans x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } + simpa only [Fintype.card_fin] using Fintype.card_congr + ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) + apply YoungDiagram.ext + ext ⟨i,j⟩ + simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] + +lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + let c := rankPerm (fun x => row (e x)) h + have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x + have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ + have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ + constructor + · rw [←hsumc,←hsume] + exact Finset.sum_le_sum (fun x _ => hle x) + · intro heq + have he : ∀ x, row (c x) = row (e x) := by + apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp + (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) + apply eq_of_row_preserving μ ν (c.symm.trans e) + intro x + simpa using (he (c.symm x)).symm + +lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] + (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by + ext z + simp only [Equiv.permCongr_apply] + exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) + +lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (v : Tabloid ν → ℂ) (hv : v ≠ 0) + (hs : ∀ c : colGroup μ, + tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by + by_contra h + push Not at h + exact hv (funext h) + obtain ⟨p,hp⟩ := f.2 + apply column_injective_rowCost μ ν (e.trans p) + intro x y hcol hrow + by_contra hne + have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by + apply swap_fixes_tabloid + rw [hp] + exact Fin.ext hrow + have heq := congrArg (fun w : Tabloid ν → ℂ => w f) + (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) + rw [swap_relabel,permSign_swap hne] at heq + simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq + apply hf + have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq + exact (mul_eq_zero.mp h2).resolve_left (by norm_num) + +lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : + tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply _ _ c _ + +theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (T : space μ ≃ₗ[ℂ] space ν) + (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : + μ = ν := by + let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ + have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) + have hTcol (c : colGroup μ) : + tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by + change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ + rw [←hT] + have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := + Subtype.ext (polytabloid_col_action μ c) + rw [hh,map_smul] + rfl + have hfwd := sign_vector_rowCost μ ν e (T u) + (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol + let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ + have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) + have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : + T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by + apply T.injective + rw [T.apply_symm_apply,hT,T.apply_symm_apply] + have hp : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] + have hTicol (c : colGroup ν) : + tabloidRep μ (e.symm.permCongr c) (T.symm w) = + permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by + change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ + rw [←hTi] + have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := + Subtype.ext (polytabloid_col_action ν c) + rw [hh,map_smul] + rfl + have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) + (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol + exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) + + +noncomputable def cellRowsEquiv (μ : YoungDiagram) : + Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where + toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ + invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ + left_inv x := by apply Subtype.ext; rfl + right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl + +lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by + rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] + simp only [Fintype.card_fin] + +lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by + rw [card_eq_sum_rowLen,YoungDiagram.rowLens] + rw [Fin.sum_univ_eq_sum_range] + have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by + induction n with + | zero => simp + | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] + exact hh _ + +noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where + parts := μ.rowLens + parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simp + +noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := + YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE + +lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : + (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by + apply YoungDiagram.rowLens_ofRowLens_eq_self + intro x hx + exact p.parts_pos ((Multiset.mem_sort _).mp hx) + +lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by + rw [←sum_rowLens,partitionDiagram_rowLens] + change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N + rw [Multiset.sort_eq,p.parts_sum] + +lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : + partitionDiagram (diagramPartition μ) = μ := by + apply YoungDiagram.equivListRowLens.injective + apply Subtype.ext + change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens + rw [partitionDiagram_rowLens] + change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens + rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] + +abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} + +end Thorp.Specht + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedRoutingMoment.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedRoutingMoment.lean index 74bea64cc7820a2009ac790ee66641f360ef1054..20afd8bd0576a52fe286009b1ad8cfc75b1e2eb0 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedRoutingMoment.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedRoutingMoment.lean @@ -1,858 +1,858 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.InputTree - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : ModifiedCoins L r => - if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) - -lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : - 0 ≤ modifiedRoutingMoment L r E e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : - modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by - simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, - PairRouting.tupleProbability] - -lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ - centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by - have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f - rw [modifiedRoutingMoment_zero] - have hbound := modified_probability_zero_le L E e f he - have hpow := Real.rpow_le_rpow hp hbound ha - have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) - have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = - centralFactor L 0 E a := by - rw [centralFactor_zero] - split_ifs - · exact Real.one_rpow _ - · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] - rw [heq] at hpow - rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] - exact mul_le_mul_of_nonneg_right hpow hp - - -lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} - (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] - rfl - -lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (L+r+1)) (a : ℝ) : - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - let : Fintype (ModifiedCoins L r) := inferInstance - rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have he (ω : ModifiedCoins L r × ModifiedCoins L r) : - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [modified_matches_step,modifiedCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = - (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r+1)) : - PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - let : Fintype (ModifiedCoins L r) := inferInstance - rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have hp (b : Bool) (p q : ModifiedCoins L r) : - modifiedPerm L r (exceptionChild E b) (if b then p else q) = - (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by - cases b <;> rfl - simp only [modified_matches_step,hp] - - -lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - - -lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * - modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) - (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) - have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = - -(r:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - calc - _ ≤ _ := hh - _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* - (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * - (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * - (modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring - _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] - - -theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by - classical - induction r generalizing ι with - | zero => - simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using - modified_pointwise_zero L E e f he a ha - | succ r ih => - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) - have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) - have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - apply hh'.trans - have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha - convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring - have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha - rw [←modified_probability_step L r E e f] at hnode - change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) - ring - - -lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : - (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card (L+r) => - ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) - -lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (he : Function.Surjective e) : Fintype.card ι = 2^d := by - rw [←card_positions d] - exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) - -lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by - simpa only [card_positions] using E.card_le_univ - -noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := - (Nat.factorial (2^(L+r)):ℝ) / - (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) - -lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : - 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity - -lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - (Nat.factorial (2^(L+r)):ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = - modifiedNormalization L r E ^ a := by - rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, - Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), - Real.mul_rpow (by positivity) (by positivity)] - have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by - rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, - show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, - Real.rpow_neg (by positivity)] - ring - -theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ - rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * - ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * - modifiedRoutingMoment L r E e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, - card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] - -lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : - finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - let B := Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) - rw [finiteMean_prod] - apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le - rw [finiteMean_prod,finiteMean_comm] - apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le - exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) - -lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - modifiedNormalization L r E ^ (1/1000:ℝ) * - Real.exp ((2^(L+r):ℕ)*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - apply hm.trans - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) - simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e - - -lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : - Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by - induction n with - | zero => omega - | succ n ih => - by_cases hz : n = 0 - · subst n; norm_num - have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) - have hn1 : (0:ℝ) < n+1 := by positivity - have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) - rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h - have hh := mul_le_mul_of_nonneg_left h hn1.le - have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring - rw [hcancel] at hh - have hi := ih (by omega) - rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] - nlinarith - -lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) = - Real.log (Nat.factorial (2^(L+r))) - - ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by - unfold modifiedNormalization - rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), - Real.log_pow,Real.log_pow,Real.log_pow, - Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - simp only [Nat.cast_pow,Nat.cast_ofNat] - -lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) ≤ - ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by - have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) - have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) - have hu := log_factorial_upper hN - have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) - simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ - rw [log_modifiedNormalization] - simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ - nlinarith - -lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + - (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - apply (modifiedRowMoment_bound L r hL E e he).trans - rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] - apply Real.exp_le_exp.mpr - have h := log_modifiedNormalization_le L r E - linarith - -lemma log_power_factorial_le (L : ℕ) : - Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by - have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by - exact_mod_cast Nat.factorial_le_pow (2^L) - have hh := Real.log_le_log (by positivity) hf - rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh - apply hh.trans - have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity - nlinarith - -lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) - (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + - (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by - apply (modified_moment_exponential L r hL E e he).trans - apply Real.exp_le_exp.mpr - have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) - have hb := mul_le_mul_of_nonneg_left momentBase_log - (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) - have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) - simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ - nlinarith - - -lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by - have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := - (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr - tendsto_natCast_atTop_atTop - have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) - convert ht using 1 - · funext L - unfold heightDecay - dsimp only [Function.comp_apply] - rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] - · simp - -noncomputable def modifiedOverhead (L r : ℕ) : ℝ := - (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) - -lemma modifiedOverhead_tendsto (L : ℕ) : - Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by - have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) - have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) - simp only [pow_one] at h₁ - simp only [pow_zero] at h₀ - have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const - ((2:ℝ)^L*1000) - convert ht using 1 - · funext r - simp only [modifiedOverhead,Nat.cast_add,pow_add] - field_simp - ring - · simp - -theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : - ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ - ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → - ∀ (e : Card (L+r) ↪ Card (L+r)), - modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by - have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := - heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists - have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL - let ε : ℝ := min (1/4) (η*250/(3*L)) - have hε : 0 < ε := lt_min (by norm_num) (by positivity) - have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) - have hεL : ε*L/250 ≤ η/3 := by - have h := min_le_right (1/4:ℝ) (η*250/(3*L)) - change ε ≤ η*250/(3*L) at h - have hh := mul_le_mul_of_nonneg_right h hL0.le - have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp - exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le - refine ⟨L,hL,ε,hε,hε1,?_⟩ - have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := - (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - filter_upwards [hr] with r hr - intro E hE e - have he := Finite.surjective_of_injective e.injective - apply (modified_moment_exception_bound L r hL E e he ε hE).trans - apply Real.exp_le_exp.mpr - have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity - have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = - (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by - unfold modifiedOverhead - field_simp - have hh := mul_le_mul_of_nonneg_right hr.le hn.le - rw [hd] at hh - have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le - linarith - - -namespace DensityTransfer -open scoped BigOperators - -noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - -lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) (x : X) : - applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl - -lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) - (v : EuclideanSpace ℂ X) : - applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by - ext x - simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] - rfl - -lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : - ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by - have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by - rw [applyKernel_apply] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] - apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans - exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) - (fun y _ => by ring_nf; exact le_rfl) - -lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) - (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) - (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by - have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by - rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] - calc - _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by - apply Finset.sum_le_sum - intro x _ - apply (kernel_component_sq P hP v x).trans - exact mul_le_mul_of_nonneg_right (hrow x) - (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) - _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by - rw [←Finset.mul_sum,Finset.sum_comm] - congr 1 - apply Finset.sum_congr rfl - intro y _ - exact (Finset.sum_mul Finset.univ _ _).symm - _ ≤ δ * ∑ y, δ*‖v y‖^2 := by - apply mul_le_mul_of_nonneg_left _ hδ - exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) - _ = _ := by rw [←Finset.mul_sum]; ring - have hn := norm_nonneg (applyKernel P v) - have hr := mul_nonneg hδ (norm_nonneg v) - nlinarith - -lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] - (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : - (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by - simp_rw [EuclideanSpace.norm_sq_eq] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro x _ - let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) - have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by - rw [norm_inner_symm] - congr 1 - simp only [applyKernel_apply,PiLp.inner_apply] - apply Finset.sum_congr rfl - intro y _ - simp [w,RCLike.inner_apply,mul_comm] - simp_rw [he] - have h := hv.sum_inner_products_le (s := Finset.univ) w - apply h.trans_eq - rw [EuclideanSpace.norm_sq_eq] - apply Finset.sum_congr rfl - intro y _ - simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] - - -lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : - (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by - split_ifs with h - · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] - apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr - rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] - exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht - · positivity - -lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : - finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by - rw [←finiteMean_mul_const] - exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) - -noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 - -noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y - -lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : - (fun x y => tailKernel P z x y+headKernel P z x y) = P := by - funext x y - unfold tailKernel headKernel - split_ifs <;> simp - -lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) - (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by - unfold tailKernel - split_ifs <;> simp only [hP,le_refl] - -lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : - ∑ y, tailKernel P z x y ≤ M*z^(-a) := by - have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then - (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by - unfold finiteMean - calc - _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by - congr 1 - apply Finset.sum_congr rfl - intro y _ - by_cases hy : z < (Fintype.card X:ℝ)*P x y - · simp only [tailKernel,hy,↓reduceIte] - · simp only [tailKernel,hy,↓reduceIte,mul_zero] - _ = _ := by rw [←Finset.mul_sum]; field_simp - rw [←he] - exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans - (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) - -lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : EuclideanSpace ℂ X) : - ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by - apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) - (tailKernel_row P hP a z M ha hz hM) - intro y - have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by - funext x - simp only [tailKernel,hsym x y] - rw [hs] - exact tailKernel_row P hP a z M ha hz hM y - -lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : - (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by - unfold headKernel - split_ifs with h - · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] - exact mul_nonneg (div_nonneg hz hn.le) (hP x y) - · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h - have hh := mul_le_mul_of_nonneg_right h' (hP x y) - rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] - apply (le_div_iff₀ hn).mpr - nlinarith - calc - _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := - Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) - _ = z := by - simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - - -theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] - [Fintype I] [Nonempty I] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : - μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by - let δ : ℝ := M*z^(-a) - have hδ : 0 ≤ δ := by dsimp [δ]; positivity - have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos - change μ ≤ δ+_ - by_cases hμ : μ ≤ δ - · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) - have hmd : 0 ≤ μ-δ := by linarith - have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by - have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) - rw [hv.norm_eq_one i,mul_one] at hr - have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) - rw [tail_add_head] at he - have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) - rw [←he] at hn - have hh := hvμ i - change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr - linarith - have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by - calc - _ = ∑ i : I, (μ-δ)^2 := by simp - _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := - Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) - _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv - _ ≤ z := headKernel_hs P hP hrow z hz.le - have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) - have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq - linarith - -end DensityTransfer -namespace PairRouting -open scoped BigOperators - -lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] - [DecidableEq β] [Fintype Ω] [Nonempty Ω] - (P : Ω → Equiv.Perm β) (e : ι ↪ β) : - (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by - classical - simp only [tupleProbability] - rw [←finiteMean_sum] - have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun g : ι ↪ β => g i) h - simp_rw [h] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : - tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by - classical - apply finiteMean_congr - intro ω - congr 1 - apply propext - constructor - · intro h i - have hh := congrArg (P ω) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm - · intro h i - have hh := congrArg (fun x => (P ω).symm x) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - -lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : - tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := - finiteMean_equiv τ _ - -lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) - (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : - tupleProbability P e f = tupleProbability P f e := by - rw [tupleProbability_equiv P τ.symm] - simp only [Equiv.symm_symm,hτ] - exact tupleProbability_inverse P e f - -end PairRouting - -lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : - palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by - simp only [palindromePerm,mul_inv_rev] - rfl - -lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) : - PairRouting.tupleProbability (palindromePerm d) e f = - PairRouting.tupleProbability (palindromePerm d) f e := - PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f - -theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] - [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) - (z : ℝ) (hz : 0 < z) : - μ ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ - Real.sqrt (z/(Fintype.card I:ℝ)) := by - let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ - apply DensityTransfer.multiplicity_amplification - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) - (fun e f => PairRouting.tupleProbability_nonneg _ e f) - (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) - (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ - intro e - exact palindrome_row_moment_bound d e hk - - -noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r - | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * - butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) - | r+1, ω => - let z := modifiedStepEquiv L r ω - (modifiedStepEquiv L r).symm - ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) - -lemma modifiedReverseCoins_involutive (L r : ℕ) : - Function.Involutive (modifiedReverseCoins L r) := by - induction r with - | zero => - intro ω - apply Prod.ext - · funext u - simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp [mul_assoc] - · rfl - | succ r ih => - change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih - intro ω - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] - exact (modifiedStepEquiv L r).symm_apply_apply ω - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.InputTree + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : ModifiedCoins L r => + if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) + +lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : + 0 ≤ modifiedRoutingMoment L r E e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : + modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by + simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, + PairRouting.tupleProbability] + +lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ + centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by + have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f + rw [modifiedRoutingMoment_zero] + have hbound := modified_probability_zero_le L E e f he + have hpow := Real.rpow_le_rpow hp hbound ha + have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) + have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = + centralFactor L 0 E a := by + rw [centralFactor_zero] + split_ifs + · exact Real.one_rpow _ + · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] + rw [heq] at hpow + rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] + exact mul_le_mul_of_nonneg_right hpow hp + + +lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} + (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] + rfl + +lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (L+r+1)) (a : ℝ) : + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + let : Fintype (ModifiedCoins L r) := inferInstance + rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have he (ω : ModifiedCoins L r × ModifiedCoins L r) : + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [modified_matches_step,modifiedCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = + (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r+1)) : + PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + let : Fintype (ModifiedCoins L r) := inferInstance + rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have hp (b : Bool) (p q : ModifiedCoins L r) : + modifiedPerm L r (exceptionChild E b) (if b then p else q) = + (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by + cases b <;> rfl + simp only [modified_matches_step,hp] + + +lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + + +lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * + modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) + (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) + have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = + -(r:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + calc + _ ≤ _ := hh + _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* + (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * + (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * + (modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring + _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] + + +theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by + classical + induction r generalizing ι with + | zero => + simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using + modified_pointwise_zero L E e f he a ha + | succ r ih => + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) + have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) + have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + apply hh'.trans + have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha + convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring + have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha + rw [←modified_probability_step L r E e f] at hnode + change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) + ring + + +lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : + (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card (L+r) => + ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) + +lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (he : Function.Surjective e) : Fintype.card ι = 2^d := by + rw [←card_positions d] + exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) + +lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by + simpa only [card_positions] using E.card_le_univ + +noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := + (Nat.factorial (2^(L+r)):ℝ) / + (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) + +lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : + 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity + +lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + (Nat.factorial (2^(L+r)):ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = + modifiedNormalization L r E ^ a := by + rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, + Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), + Real.mul_rpow (by positivity) (by positivity)] + have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by + rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, + show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, + Real.rpow_neg (by positivity)] + ring + +theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ + rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * + ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * + modifiedRoutingMoment L r E e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, + card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] + +lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : + finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + let B := Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) + rw [finiteMean_prod] + apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le + rw [finiteMean_prod,finiteMean_comm] + apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le + exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) + +lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + modifiedNormalization L r E ^ (1/1000:ℝ) * + Real.exp ((2^(L+r):ℕ)*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + apply hm.trans + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) + simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e + + +lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : + Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by + induction n with + | zero => omega + | succ n ih => + by_cases hz : n = 0 + · subst n; norm_num + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) + have hn1 : (0:ℝ) < n+1 := by positivity + have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) + rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h + have hh := mul_le_mul_of_nonneg_left h hn1.le + have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring + rw [hcancel] at hh + have hi := ih (by omega) + rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] + nlinarith + +lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) = + Real.log (Nat.factorial (2^(L+r))) - + ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by + unfold modifiedNormalization + rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), + Real.log_pow,Real.log_pow,Real.log_pow, + Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + simp only [Nat.cast_pow,Nat.cast_ofNat] + +lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) ≤ + ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by + have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) + have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) + have hu := log_factorial_upper hN + have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) + simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ + rw [log_modifiedNormalization] + simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ + nlinarith + +lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + + (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + apply (modifiedRowMoment_bound L r hL E e he).trans + rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] + apply Real.exp_le_exp.mpr + have h := log_modifiedNormalization_le L r E + linarith + +lemma log_power_factorial_le (L : ℕ) : + Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by + have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by + exact_mod_cast Nat.factorial_le_pow (2^L) + have hh := Real.log_le_log (by positivity) hf + rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh + apply hh.trans + have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity + nlinarith + +lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) + (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + + (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by + apply (modified_moment_exponential L r hL E e he).trans + apply Real.exp_le_exp.mpr + have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) + have hb := mul_le_mul_of_nonneg_left momentBase_log + (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) + have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) + simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ + nlinarith + + +lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by + have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := + (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr + tendsto_natCast_atTop_atTop + have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) + convert ht using 1 + · funext L + unfold heightDecay + dsimp only [Function.comp_apply] + rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] + · simp + +noncomputable def modifiedOverhead (L r : ℕ) : ℝ := + (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) + +lemma modifiedOverhead_tendsto (L : ℕ) : + Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by + have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) + have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) + simp only [pow_one] at h₁ + simp only [pow_zero] at h₀ + have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const + ((2:ℝ)^L*1000) + convert ht using 1 + · funext r + simp only [modifiedOverhead,Nat.cast_add,pow_add] + field_simp + ring + · simp + +theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : + ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ + ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → + ∀ (e : Card (L+r) ↪ Card (L+r)), + modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by + have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := + heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists + have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL + let ε : ℝ := min (1/4) (η*250/(3*L)) + have hε : 0 < ε := lt_min (by norm_num) (by positivity) + have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) + have hεL : ε*L/250 ≤ η/3 := by + have h := min_le_right (1/4:ℝ) (η*250/(3*L)) + change ε ≤ η*250/(3*L) at h + have hh := mul_le_mul_of_nonneg_right h hL0.le + have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp + exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le + refine ⟨L,hL,ε,hε,hε1,?_⟩ + have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := + (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + filter_upwards [hr] with r hr + intro E hE e + have he := Finite.surjective_of_injective e.injective + apply (modified_moment_exception_bound L r hL E e he ε hE).trans + apply Real.exp_le_exp.mpr + have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity + have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = + (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by + unfold modifiedOverhead + field_simp + have hh := mul_le_mul_of_nonneg_right hr.le hn.le + rw [hd] at hh + have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le + linarith + + +namespace DensityTransfer +open scoped BigOperators + +noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + +lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) (x : X) : + applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl + +lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) + (v : EuclideanSpace ℂ X) : + applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by + ext x + simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] + rfl + +lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : + ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by + have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by + rw [applyKernel_apply] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] + apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans + exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) + (fun y _ => by ring_nf; exact le_rfl) + +lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) + (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) + (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by + have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by + rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] + calc + _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by + apply Finset.sum_le_sum + intro x _ + apply (kernel_component_sq P hP v x).trans + exact mul_le_mul_of_nonneg_right (hrow x) + (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) + _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by + rw [←Finset.mul_sum,Finset.sum_comm] + congr 1 + apply Finset.sum_congr rfl + intro y _ + exact (Finset.sum_mul Finset.univ _ _).symm + _ ≤ δ * ∑ y, δ*‖v y‖^2 := by + apply mul_le_mul_of_nonneg_left _ hδ + exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) + _ = _ := by rw [←Finset.mul_sum]; ring + have hn := norm_nonneg (applyKernel P v) + have hr := mul_nonneg hδ (norm_nonneg v) + nlinarith + +lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] + (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : + (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by + simp_rw [EuclideanSpace.norm_sq_eq] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro x _ + let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) + have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by + rw [norm_inner_symm] + congr 1 + simp only [applyKernel_apply,PiLp.inner_apply] + apply Finset.sum_congr rfl + intro y _ + simp [w,RCLike.inner_apply,mul_comm] + simp_rw [he] + have h := hv.sum_inner_products_le (s := Finset.univ) w + apply h.trans_eq + rw [EuclideanSpace.norm_sq_eq] + apply Finset.sum_congr rfl + intro y _ + simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] + + +lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : + (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by + split_ifs with h + · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] + apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr + rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] + exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht + · positivity + +lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : + finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by + rw [←finiteMean_mul_const] + exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) + +noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 + +noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y + +lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : + (fun x y => tailKernel P z x y+headKernel P z x y) = P := by + funext x y + unfold tailKernel headKernel + split_ifs <;> simp + +lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) + (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by + unfold tailKernel + split_ifs <;> simp only [hP,le_refl] + +lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : + ∑ y, tailKernel P z x y ≤ M*z^(-a) := by + have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then + (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by + unfold finiteMean + calc + _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by + congr 1 + apply Finset.sum_congr rfl + intro y _ + by_cases hy : z < (Fintype.card X:ℝ)*P x y + · simp only [tailKernel,hy,↓reduceIte] + · simp only [tailKernel,hy,↓reduceIte,mul_zero] + _ = _ := by rw [←Finset.mul_sum]; field_simp + rw [←he] + exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans + (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) + +lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : EuclideanSpace ℂ X) : + ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by + apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) + (tailKernel_row P hP a z M ha hz hM) + intro y + have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by + funext x + simp only [tailKernel,hsym x y] + rw [hs] + exact tailKernel_row P hP a z M ha hz hM y + +lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : + (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by + unfold headKernel + split_ifs with h + · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] + exact mul_nonneg (div_nonneg hz hn.le) (hP x y) + · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h + have hh := mul_le_mul_of_nonneg_right h' (hP x y) + rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] + apply (le_div_iff₀ hn).mpr + nlinarith + calc + _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := + Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) + _ = z := by + simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + + +theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] + [Fintype I] [Nonempty I] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : + μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by + let δ : ℝ := M*z^(-a) + have hδ : 0 ≤ δ := by dsimp [δ]; positivity + have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos + change μ ≤ δ+_ + by_cases hμ : μ ≤ δ + · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) + have hmd : 0 ≤ μ-δ := by linarith + have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by + have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) + rw [hv.norm_eq_one i,mul_one] at hr + have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) + rw [tail_add_head] at he + have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) + rw [←he] at hn + have hh := hvμ i + change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr + linarith + have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by + calc + _ = ∑ i : I, (μ-δ)^2 := by simp + _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := + Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) + _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv + _ ≤ z := headKernel_hs P hP hrow z hz.le + have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) + have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq + linarith + +end DensityTransfer +namespace PairRouting +open scoped BigOperators + +lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] + [DecidableEq β] [Fintype Ω] [Nonempty Ω] + (P : Ω → Equiv.Perm β) (e : ι ↪ β) : + (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by + classical + simp only [tupleProbability] + rw [←finiteMean_sum] + have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun g : ι ↪ β => g i) h + simp_rw [h] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : + tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by + classical + apply finiteMean_congr + intro ω + congr 1 + apply propext + constructor + · intro h i + have hh := congrArg (P ω) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm + · intro h i + have hh := congrArg (fun x => (P ω).symm x) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + +lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : + tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := + finiteMean_equiv τ _ + +lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) + (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : + tupleProbability P e f = tupleProbability P f e := by + rw [tupleProbability_equiv P τ.symm] + simp only [Equiv.symm_symm,hτ] + exact tupleProbability_inverse P e f + +end PairRouting + +lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : + palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by + simp only [palindromePerm,mul_inv_rev] + rfl + +lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) : + PairRouting.tupleProbability (palindromePerm d) e f = + PairRouting.tupleProbability (palindromePerm d) f e := + PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f + +theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] + [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) + (z : ℝ) (hz : 0 < z) : + μ ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ + Real.sqrt (z/(Fintype.card I:ℝ)) := by + let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ + apply DensityTransfer.multiplicity_amplification + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) + (fun e f => PairRouting.tupleProbability_nonneg _ e f) + (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) + (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ + intro e + exact palindrome_row_moment_bound d e hk + + +noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r + | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * + butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) + | r+1, ω => + let z := modifiedStepEquiv L r ω + (modifiedStepEquiv L r).symm + ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) + +lemma modifiedReverseCoins_involutive (L r : ℕ) : + Function.Involutive (modifiedReverseCoins L r) := by + induction r with + | zero => + intro ω + apply Prod.ext + · funext u + simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp [mul_assoc] + · rfl + | succ r ih => + change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih + intro ω + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] + exact (modifiedStepEquiv L r).symm_apply_apply ω + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedStageEquiv.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedStageEquiv.lean index 10927a55e5b75a75f7c2bce23f743eca1b1301d0..40a61a294f435e3e0f79786df3f3bd9c910c79f1 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedStageEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ModifiedStageEquiv.lean @@ -1,875 +1,875 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.BlockProduct - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators Classical - -def modifiedStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ - ModifiedCoins L r := - (modifiedAssembleEquiv _ _ _ _).trans - (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) - -lemma modifiedStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - modifiedStageEquiv r L w= - ((fun b => (w.1.2 b).1), - (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by - simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] - -lemma palindrome_stage (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [palindromeStageEquiv_apply] - change splitPerm r L (_*_⁻¹)=_ - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - rfl - -noncomputable def localModifiedPerm (L : ℕ) (e : Bool) - (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := - if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ - -lemma modified_stage (r L : ℕ) (E : Finset (Card r)) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [modifiedStageEquiv_apply] - unfold modifiedPerm modifiedInputTree - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - congr 2 - apply congrArg ParallelBlocks.lift - funext b - simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] - by_cases h : b∈E <;> simp [h] - -end Thorp -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= - sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by - rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), - sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] - -lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : - sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by - cases e - · simp only [Bool.false_eq_true,ite_false] - rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] - exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) - · simp only [ite_true] - exact sampleOperator_one ρ - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma sampleOperator_palindrome_stage (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) - -lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift - (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := - funext (modified_stage r L E) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) - -end Thorp -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] [DecidableEq ι] - -noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1 else P i - -omit [CompleteSpace V] [Fintype ι] in -lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) - (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by - unfold retain - split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ - -omit [CompleteSpace V] in -lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : - blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by - have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E - have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right - (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) - simp only [hs] at hh - change blocks (retain P E) (retain_commute P hP E)=_ at hh - rw [hh] - have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by - exact (Finset.noncommProd_eq_pow_card E (retain P E) - (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) - rw [he,one_mul] - apply Finset.noncommProd_congr rfl - intro i hi - exact ite_eq_right (Finset.mem_compl.mp hi) - -end Thorp.CommutingBlocks - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := - uniformOperator (ρ.comp (injection b)) - -omit [Fintype B] in -lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : - Commute (centralProjection ρ b) (centralProjection ρ c) := by - simpa only [centralProjection,sampleOperator_uniform] using - local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c - -omit [Fintype B] in -lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by - by_cases h : b=c - · subst c - change _*uniformOperator _=uniformOperator _*_ - rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] - · unfold centralProjection - rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite ParallelBlocks CommutingBlocks -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= - coarse (centralProjection ρ) (centralProjection_commute ρ) E := by - rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] - apply Finset.noncommProd_congr rfl - · intro b _ - rw [localModified_average] - simp only [retain,centralProjection,decide_eq_true_eq] - · intro b _ c _ _ - exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c - -lemma central_local_gap (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : - ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by - change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ - rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] - exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) - -lemma central_blocks_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) - (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : - ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) - (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L)) - (local_central_commute ρ (fun _ => palindromePerm L)) - (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) - (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) - B.adjoint hB n - simpa only [ContinuousLinearMap.adjoint_adjoint] using h - -theorem palindrome_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : - ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] - apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) - (sampleOperator_norm_le ρ hρ _) n).trans_eq - congr 1 - apply Finset.sum_congr rfl - intro E _ - split_ifs - · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] - · rfl - -end Thorp - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] - -noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := - finiteMean (fun ω => if a (P ω) x=y then 1 else 0) - -omit [Fintype G] in -lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) - (v : EuclideanSpace ℂ X) (x : X) : - DensityTransfer.applyKernel (actionKernel a P) v x = - (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by - simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, - Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] - rw [Finset.sum_comm] - calc - _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by - apply Finset.sum_congr rfl - intro ω _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all - _ = _ := by simp [Finset.mul_sum] - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : - DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = - normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by - ext x - rw [actionKernel_apply] - simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, - coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, - inner_smul_right,inner_sum] - apply Finset.sum_congr rfl - intro ω _ - have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x - change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = - inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h - rw [h] - ring - -noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : - Submodule ℂ V where - carrier := {w | IsFixed a x₀ ρ w} - zero_mem' := fun g hg => map_zero _ - add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] - smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] - -theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : - ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - let K := fixedSpace a x₀ ρ - let m := Module.finrank ℂ K - let : Nonempty X := ⟨x₀⟩ - let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ - let B := stdOrthonormalBasis ℂ K - let w : Fin m → V := fun i => (B i : V) - have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 - have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ - have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv - have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) - (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by - rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), - normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] - have h := DensityTransfer.multiplicity_amplification (actionKernel a P) - (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow - b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) - simpa only [Fintype.card_fin] using h - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where - toFun p := - { toFun := fun e => e.trans p.toEmbedding - invFun := fun e => e.trans p.symm.toEmbedding - left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) - right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } - map_one' := by ext e i; rfl - map_mul' p q := by ext e i; rfl - -omit [Fintype α] [Fintype ι] in -@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : - tupleAction p e i=p (e i) := rfl - -omit [Fintype α] in -lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by - obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective - exact ⟨p,Function.Embedding.ext hp⟩ - -omit [Fintype α] in -lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : - tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by - constructor - · intro h x hx - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx - exact congrArg (fun f : ι ↪ α => f i) h - · intro h - ext i - exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - -omit [Fintype α] in -lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) - (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by - unfold actionKernel PairRouting.tupleProbability - congr 1 - funext ω - congr 1 - exact propext Function.Embedding.ext_iff - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -lemma irreducible_of_equiv {G V W : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : - Representation.IsIrreducible σ := by - rw [Representation.irreducible_iff_isSimpleModule_asModule] - have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance - let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := - Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap - have hf : Function.Bijective f := e.toLinearEquiv.bijective - exact (f.isSimpleModule_iff_of_bijective hf).mp hi - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : hilbertSpace μ) : - (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = - PermutationHilbert.act (tabloidAct p) v := by - obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v - change hilbertEquiv μ (tabloidRep μ p w) = _ - exact hilbert_action μ p w - -noncomputable def unitaryEquiv (μ : YoungDiagram) : - Representation.Equiv (representation μ) (unitaryRepresentation μ) := - Representation.Equiv.mk (spaceHilbertEquiv μ) (by - intro p - apply LinearMap.ext - intro v - change spaceHilbertEquiv μ (representation μ p v) = - spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) - rw [LinearEquiv.symm_apply_apply]) - -lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (unitaryRepresentation μ) := by - let := representation_irreducible μ - exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) - -lemma unitaryRepresentation_unitary (μ : YoungDiagram) : - UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by - intro p v w - change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) - (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ - rw [unitaryRepresentation_coe,unitaryRepresentation_coe] - exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w - - -noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] - fixedHilbert μ (Finset.univ.image e) where - toFun v := ⟨v.1.1,v.1.2,by - intro p hp - have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) - exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ - invFun v := ⟨⟨v.1,v.2.1⟩,by - intro p hp - apply Subtype.ext - exact (unitaryRepresentation_coe μ p _).trans - (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] - have h := fixedHilbert_dimension μ (Finset.univ.image e) - simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h - -end Thorp.Specht -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : - sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by - simp only [sampleOperator,randomOperator,smul_apply, - sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] - -theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : - ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) - intro v hv - rw [sampleOperator_inv_apply] - exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : - Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where - toFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun g v hv => by - have h := U.apply_mem_toSubmodule (e.symm g) hv - change ρ (e (e.symm g)) v∈U.toSubmodule at h - simpa only [e.apply_symm_apply] using h } - invFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } - left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - map_rel_iff' := Iff.rfl - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by - exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -omit [Fintype α] in -lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by - intro g v w - exact unitaryRepresentation_unitary μ (e.permCongr g) v w - -omit [Fintype α] in -lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation.IsIrreducible (relabelledUnitary μ e) := by - let := unitaryRepresentation_irreducible μ - exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom - -noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where - toFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg - change g (e (f i))=e (f i) at hh - simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] - have hh := v.2 (e.symm.permCongr g) hp - change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh - have he : e.permCongr (e.symm.permCongr g)=g := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] - simpa only [he] using hh⟩ - invFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ α => f i) hg - change g (f i)=f i at hh - simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, - Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] - exact v.2 (e.permCongr g) hp⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -omit [Fintype α] in -lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(relabelledTupleFixed μ e f).finrank_eq] - exact tupleFixed_dimension μ (f.trans e.toEmbedding) - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) - (hG : ∀ v, ∃ w, G.Adj v w) : - ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ - ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by - classical - obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le - let c := hF.coloringTwo - have hneigh (v : V) : ∃ w, F.Adj v w := by - obtain ⟨w, hvw⟩ := hG v - have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable - exact hr.nonempty_neighborSet_left hvw.ne - let A : Finset V := Finset.univ.filter (fun v => c v = 0) - let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) - have hab : A.card + B.card = Fintype.card V := by - exact Finset.card_filter_add_card_filter_not _ - have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw - by_cases h : A.card ≤ B.card - · refine ⟨A, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v ≠ 0 := by simpa [A] using hv - have hw0 : c w = 0 := by - have hv1 : c v = 1 := by omega - have hn := hcolor hvw - omega - exact ⟨w, by simp [A, hw0], hFG hvw⟩ - · refine ⟨B, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v = 0 := by simpa [B] using hv - have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm - exact ⟨w, by simp [B, hw0], hFG hvw⟩ - -lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : - (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by - rw [← Finset.prod_one_add, Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro v _; exact add_nonneg (by norm_num) (hp v) - · intro v _ - have h := Real.add_one_le_exp (p v) - linarith - -lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : - (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ - δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by - have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : - (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by - rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] - field_simp - calc - _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by - rw [Finset.mul_sum] - exact Finset.sum_congr rfl hsplit - _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by - apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro L hL - exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 - · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) - _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := - mul_le_mul_of_nonneg_left - (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) - (pow_nonneg hδ.le _) - _ = _ := by rw [Finset.sum_div] - -noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) - (R : Finset V) : Finset V := by - classical - exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) - -lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : - (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by - classical - calc - _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum - intro w hw - obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 - have h : (if G.Adj v w then p w else 0) ≤ - ∑ u ∈ R, if G.Adj u w then p w else 0 := - Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv - simpa only [ite_eq_left hvw] using h - _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro w _ _ - exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) - _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm - _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) - _ = _ := by simp - -lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) - (R : Finset V) (hR : 2 * R.card ≤ k) : - (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ - δ^((k:ℝ)/2) * Real.exp R.card := by - classical - have hmass := neighborhood_weight_le G p hp δ hdeg R - have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by - rw [← Real.rpow_natCast] - apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 - have hr : R.card ≤ k := by omega - rw [Nat.cast_sub hr] - have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR - linarith - apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans - apply mul_le_mul hpow - · apply Real.exp_le_exp.mpr - exact (div_le_iff₀ hδ).mpr hmass - · positivity - · positivity - -def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := - ∀ v ∈ S, ∃ w ∈ S, G.Adj v w - -lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) - (S : Finset V) (hS : NoIsolated G S) : - ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by - classical - let H := G.induce (S : Set V) - have hH : ∀ v : S, ∃ w : S, H.Adj v w := by - intro v - obtain ⟨w, hw, hvw⟩ := hS v v.2 - exact ⟨⟨w, hw⟩, hvw⟩ - obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH - let T := R.image (fun v : S => (v : V)) - have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective - refine ⟨T, ?_, ?_, ?_⟩ - · intro v hv - obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv - exact w.2 - · simpa [hc, H] using hR - · intro v hv - have hvS := (Finset.mem_sdiff.mp hv).1 - have hvR : (⟨v, hvS⟩ : S) ∉ R := by - intro hh - exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) - obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR - exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, - ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ - -lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - let root (S : I) := (small_dominating_subset G S.val S.property.2).choose - have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ - S.val \ root S ⊆ neighborhood G (root S) := by - simpa only [root, S.property.1] using - (small_dominating_subset G S.val S.property.2).choose_spec - let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) - have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := - Finset.union_sdiff_of_subset (hroot S).1 - have hinj : Function.Injective enc := by - intro S T h - apply Subtype.ext - rw [← hrec S, ← hrec T, h] - let W (z : Finset V × Finset V) : ℝ := - if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) - then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 - have hW (z : Finset V × Finset V) : 0 ≤ W z := by - dsimp [W] - split_ifs - · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) - (Finset.prod_nonneg (fun v _ => hp v)) - · exact le_rfl - have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by - have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by - refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ - change (S.val \ root S).card = k-(root S).card - rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] - dsimp only [W] - rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] - exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) - have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by - calc - _ = ∑ z ∈ Finset.univ.image enc, W z := by - rw [Finset.sum_image (fun S _ T _ h => hinj h)] - exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun z _ _ => hW z) - apply hsum.trans - rw [Fintype.sum_prod_type] - calc - (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ - ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by - apply Finset.sum_le_sum - intro R _ - by_cases hR : 2*R.card ≤ k - · have he : (∑ L : Finset V, W (R,L)) = - (∏ v ∈ R, p v) * - ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by - simp only [W, hR, true_and] - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] - rw [he] - have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) - (Finset.prod_nonneg (s := R) (fun v _ => hp v)) - simpa only [mul_comm, mul_left_comm, mul_assoc] using h - · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] - exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) - (Finset.prod_nonneg (fun v _ => hp v)) - _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro R _ - rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] - simp only [mul_one, mul_assoc] - _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) - simpa only [Finset.powerset_univ] using - powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) - (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) - _ = _ := by rw [← Finset.mul_sum] - - -lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] - (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) - (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) - (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) - (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - calc - _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by - apply finiteMean_mono - intro ω - split_ifs with h - · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) - (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) - · positivity - _ = ∑ S : I, inclusionMoment O S.val := by - rw [finiteMean_sum] - rfl - _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) - _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg - -noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : Finset (N × X) := by - classical - exact Finset.univ.filter (fun v => v.2 ∈ A v.1) - -@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by - classical - simp [typedSet] - -noncomputable def fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) : Finset X := by - classical - exact Finset.univ.filter (fun x => (t,x) ∈ S) - -@[simp] lemma mem_fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by - classical - simp [fiber] - -lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] - (S : Finset (N × X)) : typedSet (fiber S) = S := by - classical - ext v - simp - -lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (p : N × X → ℝ) : - (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by - classical - simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] - apply Finset.prod_congr rfl - intro t _ - rw [← Finset.prod_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by - classical - simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (D : Finset (N × X)) : - D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by - constructor - · intro h t x hx - exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) - · intro h v hv - exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) - -end Thorp.SparseContact - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.BlockProduct + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators Classical + +def modifiedStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ + ModifiedCoins L r := + (modifiedAssembleEquiv _ _ _ _).trans + (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) + +lemma modifiedStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + modifiedStageEquiv r L w= + ((fun b => (w.1.2 b).1), + (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by + simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] + +lemma palindrome_stage (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [palindromeStageEquiv_apply] + change splitPerm r L (_*_⁻¹)=_ + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + rfl + +noncomputable def localModifiedPerm (L : ℕ) (e : Bool) + (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := + if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ + +lemma modified_stage (r L : ℕ) (E : Finset (Card r)) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [modifiedStageEquiv_apply] + unfold modifiedPerm modifiedInputTree + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + congr 2 + apply congrArg ParallelBlocks.lift + funext b + simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] + by_cases h : b∈E <;> simp [h] + +end Thorp +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= + sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by + rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), + sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] + +lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : + sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by + cases e + · simp only [Bool.false_eq_true,ite_false] + rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] + exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) + · simp only [ite_true] + exact sampleOperator_one ρ + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma sampleOperator_palindrome_stage (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) + +lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift + (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := + funext (modified_stage r L E) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) + +end Thorp +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1 else P i + +omit [CompleteSpace V] [Fintype ι] in +lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) + (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by + unfold retain + split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ + +omit [CompleteSpace V] in +lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : + blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by + have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E + have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right + (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) + simp only [hs] at hh + change blocks (retain P E) (retain_commute P hP E)=_ at hh + rw [hh] + have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by + exact (Finset.noncommProd_eq_pow_card E (retain P E) + (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) + rw [he,one_mul] + apply Finset.noncommProd_congr rfl + intro i hi + exact ite_eq_right (Finset.mem_compl.mp hi) + +end Thorp.CommutingBlocks + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := + uniformOperator (ρ.comp (injection b)) + +omit [Fintype B] in +lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : + Commute (centralProjection ρ b) (centralProjection ρ c) := by + simpa only [centralProjection,sampleOperator_uniform] using + local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c + +omit [Fintype B] in +lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by + by_cases h : b=c + · subst c + change _*uniformOperator _=uniformOperator _*_ + rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] + · unfold centralProjection + rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite ParallelBlocks CommutingBlocks +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= + coarse (centralProjection ρ) (centralProjection_commute ρ) E := by + rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] + apply Finset.noncommProd_congr rfl + · intro b _ + rw [localModified_average] + simp only [retain,centralProjection,decide_eq_true_eq] + · intro b _ c _ _ + exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c + +lemma central_local_gap (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : + ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by + change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ + rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] + exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) + +lemma central_blocks_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) + (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : + ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) + (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L)) + (local_central_commute ρ (fun _ => palindromePerm L)) + (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) + (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) + B.adjoint hB n + simpa only [ContinuousLinearMap.adjoint_adjoint] using h + +theorem palindrome_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : + ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] + apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) + (sampleOperator_norm_le ρ hρ _) n).trans_eq + congr 1 + apply Finset.sum_congr rfl + intro E _ + split_ifs + · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] + · rfl + +end Thorp + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] + +noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := + finiteMean (fun ω => if a (P ω) x=y then 1 else 0) + +omit [Fintype G] in +lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) + (v : EuclideanSpace ℂ X) (x : X) : + DensityTransfer.applyKernel (actionKernel a P) v x = + (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by + simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, + Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] + rw [Finset.sum_comm] + calc + _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by + apply Finset.sum_congr rfl + intro ω _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all + _ = _ := by simp [Finset.mul_sum] + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : + DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = + normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by + ext x + rw [actionKernel_apply] + simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, + coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, + inner_smul_right,inner_sum] + apply Finset.sum_congr rfl + intro ω _ + have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x + change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = + inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h + rw [h] + ring + +noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : + Submodule ℂ V where + carrier := {w | IsFixed a x₀ ρ w} + zero_mem' := fun g hg => map_zero _ + add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] + smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] + +theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : + ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + let K := fixedSpace a x₀ ρ + let m := Module.finrank ℂ K + let : Nonempty X := ⟨x₀⟩ + let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ + let B := stdOrthonormalBasis ℂ K + let w : Fin m → V := fun i => (B i : V) + have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 + have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ + have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv + have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) + (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by + rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), + normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] + have h := DensityTransfer.multiplicity_amplification (actionKernel a P) + (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow + b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) + simpa only [Fintype.card_fin] using h + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where + toFun p := + { toFun := fun e => e.trans p.toEmbedding + invFun := fun e => e.trans p.symm.toEmbedding + left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) + right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } + map_one' := by ext e i; rfl + map_mul' p q := by ext e i; rfl + +omit [Fintype α] [Fintype ι] in +@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : + tupleAction p e i=p (e i) := rfl + +omit [Fintype α] in +lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by + obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective + exact ⟨p,Function.Embedding.ext hp⟩ + +omit [Fintype α] in +lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : + tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by + constructor + · intro h x hx + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + exact congrArg (fun f : ι ↪ α => f i) h + · intro h + ext i + exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + +omit [Fintype α] in +lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) + (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by + unfold actionKernel PairRouting.tupleProbability + congr 1 + funext ω + congr 1 + exact propext Function.Embedding.ext_iff + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +lemma irreducible_of_equiv {G V W : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : + Representation.IsIrreducible σ := by + rw [Representation.irreducible_iff_isSimpleModule_asModule] + have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance + let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := + Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap + have hf : Function.Bijective f := e.toLinearEquiv.bijective + exact (f.isSimpleModule_iff_of_bijective hf).mp hi + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : hilbertSpace μ) : + (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = + PermutationHilbert.act (tabloidAct p) v := by + obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v + change hilbertEquiv μ (tabloidRep μ p w) = _ + exact hilbert_action μ p w + +noncomputable def unitaryEquiv (μ : YoungDiagram) : + Representation.Equiv (representation μ) (unitaryRepresentation μ) := + Representation.Equiv.mk (spaceHilbertEquiv μ) (by + intro p + apply LinearMap.ext + intro v + change spaceHilbertEquiv μ (representation μ p v) = + spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) + rw [LinearEquiv.symm_apply_apply]) + +lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (unitaryRepresentation μ) := by + let := representation_irreducible μ + exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) + +lemma unitaryRepresentation_unitary (μ : YoungDiagram) : + UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by + intro p v w + change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) + (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ + rw [unitaryRepresentation_coe,unitaryRepresentation_coe] + exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w + + +noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] + fixedHilbert μ (Finset.univ.image e) where + toFun v := ⟨v.1.1,v.1.2,by + intro p hp + have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) + exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ + invFun v := ⟨⟨v.1,v.2.1⟩,by + intro p hp + apply Subtype.ext + exact (unitaryRepresentation_coe μ p _).trans + (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] + have h := fixedHilbert_dimension μ (Finset.univ.image e) + simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h + +end Thorp.Specht +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : + sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by + simp only [sampleOperator,randomOperator,smul_apply, + sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] + +theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : + ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) + intro v hv + rw [sampleOperator_inv_apply] + exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : + Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where + toFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun g v hv => by + have h := U.apply_mem_toSubmodule (e.symm g) hv + change ρ (e (e.symm g)) v∈U.toSubmodule at h + simpa only [e.apply_symm_apply] using h } + invFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } + left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + map_rel_iff' := Iff.rfl + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by + exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +omit [Fintype α] in +lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by + intro g v w + exact unitaryRepresentation_unitary μ (e.permCongr g) v w + +omit [Fintype α] in +lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation.IsIrreducible (relabelledUnitary μ e) := by + let := unitaryRepresentation_irreducible μ + exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom + +noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where + toFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg + change g (e (f i))=e (f i) at hh + simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] + have hh := v.2 (e.symm.permCongr g) hp + change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh + have he : e.permCongr (e.symm.permCongr g)=g := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] + simpa only [he] using hh⟩ + invFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ α => f i) hg + change g (f i)=f i at hh + simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, + Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] + exact v.2 (e.permCongr g) hp⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +omit [Fintype α] in +lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(relabelledTupleFixed μ e f).finrank_eq] + exact tupleFixed_dimension μ (f.trans e.toEmbedding) + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) + (hG : ∀ v, ∃ w, G.Adj v w) : + ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ + ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by + classical + obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le + let c := hF.coloringTwo + have hneigh (v : V) : ∃ w, F.Adj v w := by + obtain ⟨w, hvw⟩ := hG v + have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable + exact hr.nonempty_neighborSet_left hvw.ne + let A : Finset V := Finset.univ.filter (fun v => c v = 0) + let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) + have hab : A.card + B.card = Fintype.card V := by + exact Finset.card_filter_add_card_filter_not _ + have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw + by_cases h : A.card ≤ B.card + · refine ⟨A, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v ≠ 0 := by simpa [A] using hv + have hw0 : c w = 0 := by + have hv1 : c v = 1 := by omega + have hn := hcolor hvw + omega + exact ⟨w, by simp [A, hw0], hFG hvw⟩ + · refine ⟨B, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v = 0 := by simpa [B] using hv + have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm + exact ⟨w, by simp [B, hw0], hFG hvw⟩ + +lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : + (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by + rw [← Finset.prod_one_add, Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro v _; exact add_nonneg (by norm_num) (hp v) + · intro v _ + have h := Real.add_one_le_exp (p v) + linarith + +lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : + (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ + δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by + have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : + (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by + rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] + field_simp + calc + _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl hsplit + _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by + apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro L hL + exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 + · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) + _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := + mul_le_mul_of_nonneg_left + (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) + (pow_nonneg hδ.le _) + _ = _ := by rw [Finset.sum_div] + +noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) + (R : Finset V) : Finset V := by + classical + exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) + +lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : + (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by + classical + calc + _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum + intro w hw + obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 + have h : (if G.Adj v w then p w else 0) ≤ + ∑ u ∈ R, if G.Adj u w then p w else 0 := + Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv + simpa only [ite_eq_left hvw] using h + _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro w _ _ + exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) + _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm + _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) + _ = _ := by simp + +lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) + (R : Finset V) (hR : 2 * R.card ≤ k) : + (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ + δ^((k:ℝ)/2) * Real.exp R.card := by + classical + have hmass := neighborhood_weight_le G p hp δ hdeg R + have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 + have hr : R.card ≤ k := by omega + rw [Nat.cast_sub hr] + have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR + linarith + apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans + apply mul_le_mul hpow + · apply Real.exp_le_exp.mpr + exact (div_le_iff₀ hδ).mpr hmass + · positivity + · positivity + +def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := + ∀ v ∈ S, ∃ w ∈ S, G.Adj v w + +lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) + (S : Finset V) (hS : NoIsolated G S) : + ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by + classical + let H := G.induce (S : Set V) + have hH : ∀ v : S, ∃ w : S, H.Adj v w := by + intro v + obtain ⟨w, hw, hvw⟩ := hS v v.2 + exact ⟨⟨w, hw⟩, hvw⟩ + obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH + let T := R.image (fun v : S => (v : V)) + have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective + refine ⟨T, ?_, ?_, ?_⟩ + · intro v hv + obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv + exact w.2 + · simpa [hc, H] using hR + · intro v hv + have hvS := (Finset.mem_sdiff.mp hv).1 + have hvR : (⟨v, hvS⟩ : S) ∉ R := by + intro hh + exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) + obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ + +lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + let root (S : I) := (small_dominating_subset G S.val S.property.2).choose + have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ + S.val \ root S ⊆ neighborhood G (root S) := by + simpa only [root, S.property.1] using + (small_dominating_subset G S.val S.property.2).choose_spec + let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) + have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := + Finset.union_sdiff_of_subset (hroot S).1 + have hinj : Function.Injective enc := by + intro S T h + apply Subtype.ext + rw [← hrec S, ← hrec T, h] + let W (z : Finset V × Finset V) : ℝ := + if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) + then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 + have hW (z : Finset V × Finset V) : 0 ≤ W z := by + dsimp [W] + split_ifs + · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) + (Finset.prod_nonneg (fun v _ => hp v)) + · exact le_rfl + have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by + have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by + refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ + change (S.val \ root S).card = k-(root S).card + rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] + dsimp only [W] + rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] + exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) + have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by + calc + _ = ∑ z ∈ Finset.univ.image enc, W z := by + rw [Finset.sum_image (fun S _ T _ h => hinj h)] + exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun z _ _ => hW z) + apply hsum.trans + rw [Fintype.sum_prod_type] + calc + (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ + ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by + apply Finset.sum_le_sum + intro R _ + by_cases hR : 2*R.card ≤ k + · have he : (∑ L : Finset V, W (R,L)) = + (∏ v ∈ R, p v) * + ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by + simp only [W, hR, true_and] + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] + rw [he] + have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) + (Finset.prod_nonneg (s := R) (fun v _ => hp v)) + simpa only [mul_comm, mul_left_comm, mul_assoc] using h + · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] + exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) + (Finset.prod_nonneg (fun v _ => hp v)) + _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro R _ + rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] + simp only [mul_one, mul_assoc] + _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) + simpa only [Finset.powerset_univ] using + powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) + (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) + _ = _ := by rw [← Finset.mul_sum] + + +lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] + (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) + (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) + (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) + (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + calc + _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by + apply finiteMean_mono + intro ω + split_ifs with h + · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) + (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) + · positivity + _ = ∑ S : I, inclusionMoment O S.val := by + rw [finiteMean_sum] + rfl + _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) + _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg + +noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : Finset (N × X) := by + classical + exact Finset.univ.filter (fun v => v.2 ∈ A v.1) + +@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by + classical + simp [typedSet] + +noncomputable def fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) : Finset X := by + classical + exact Finset.univ.filter (fun x => (t,x) ∈ S) + +@[simp] lemma mem_fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by + classical + simp [fiber] + +lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] + (S : Finset (N × X)) : typedSet (fiber S) = S := by + classical + ext v + simp + +lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (p : N × X → ℝ) : + (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by + classical + simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] + apply Finset.prod_congr rfl + intro t _ + rw [← Finset.prod_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by + classical + simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (D : Finset (N × X)) : + D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by + constructor + · intro h t x hx + exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) + · intro h v hv + exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) + +end Thorp.SparseContact + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFollow.lean index ab46d7064886c3564507e0f2840f9e93024e045a..c05465299846a021d4d3b92e1ffcea2d76b68703 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFollow.lean @@ -1,883 +1,883 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.PriorPaths - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.PriorPaths + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFreshPre.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFreshPre.lean index acfe3f3b40dd9fbf26ad0d7ef2499e16b7887936..f41e951969ce79707e4d290dea7ea94dcceafded 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFreshPre.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ParallelFreshPre.lean @@ -1,848 +1,848 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.BenesCoins - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp - -lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : - x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by - classical - constructor - · intro h - obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h - simp only [Equiv.apply_symm_apply] - · intro h - apply Finset.mem_image.mpr - refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ - rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] - -lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by - classical - rw [centralBlock,Finset.card_image_of_injective] - · exact card_positions H - · intro x y h - exact congrArg Prod.snd ((cardSplit r H).symm.injective h) - -lemma centralBlock_disjoint (r H : ℕ) : - Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by - classical - intro b b' h - apply Finset.disjoint_left.mpr - intro x hx hy - exact h (((mem_centralBlock r H b x).mp hx).symm.trans - ((mem_centralBlock r H b' x).mp hy)) - -lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by - classical - ext x - simp only [mem_centralBlock,Finset.mem_univ,iff_true] - exact Subsingleton.elim _ _ - -lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : - centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by - classical - simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, - Fin.cons_zero,Fin.tail_cons,Function.comp_def] - -lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : - centralBlock (r+1) H (Fin.cons b c) ∩ A = - (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by - classical - rw [centralBlock_step] - ext x - constructor - · intro hx - obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB - exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, - (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ - -lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : - sparseMass (centralBlock 0 H) A = crowdedMass A.card := by - classical - simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, - Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] - -lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : - sparseMass (centralBlock (r+1) H) A = - sparseMass (centralBlock r H) (childMarks A false) + - sparseMass (centralBlock r H) (childMarks A true) := by - classical - unfold sparseMass - rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl - simp only [Fintype.sum_bool,ht] - have hc (b : Bool) (c : Card r) : - (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = - (centralBlock r H c ∩ childMarks A b).card := by - rw [block_inter_step] - apply Finset.card_image_of_injective - intro x y h - simpa only [Fin.tail_cons] using congrArg Fin.tail h - simp only [hc] - exact add_comm _ _ - - -lemma inverseButterfly_coordinates_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) - (x : Card (d+1)) : - headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = - (Bool.xor (x 0) (ξ (Fin.tail x)), - (butterflyPerm d (decodeButterfly d - (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by - rw [butterflyPerm_step] - rfl - -lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : - childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) - ((coinStepEquiv d).symm (c,ξ))) b = - inverseButterflyMarks d - (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) - (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by - classical - let x := e.trans (headTailEquiv d).toEmbedding - let col := PairRouting.colors x ξ - let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b - have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = - (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := - inverseButterfly_coordinates_step d c ξ (e i) - ext y - simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, - Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] - constructor - · rintro ⟨i,hi⟩ - have he := congrArg (headTailEquiv d) hi - rw [hp i] at he - change (col i,_) = (b,y) at he - have hb := congrArg Prod.fst he - have hy := congrArg Prod.snd he - dsimp only at hb hy - refine ⟨⟨i,hb⟩,?_⟩ - change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y - simpa only [hb] using hy - · rintro ⟨i,hi⟩ - refine ⟨i.val,?_⟩ - apply (headTailEquiv d).injective - rw [hp] - change (col i.val,_) = (b,y) - have hb : col i.val = b := i.property - rw [hb] - exact Prod.ext rfl hi - -lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : - (inverseButterflyMarks d A ω).card = A.card := by - classical - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective - -lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : - ω.2 = (coinStepEquiv d).symm - (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by - change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) - exact ((coinStepEquiv d).symm_apply_apply ω.2).symm - -lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : - cutoffMass H (H+r) e ω = - sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by - classical - induction r generalizing ι with - | zero => - rw [sparseMass_central_zero,inverseButterflyMarks_card, - Finset.card_image_of_injective _ e.injective,Finset.card_univ] - cases H with - | zero => - have hcard : Fintype.card ι ≤ 1 := by - have hh := Fintype.card_le_of_injective e e.injective - simpa only [Nat.add_zero,card_positions,pow_zero] using hh - simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] - | succ H => simp only [cutoffMass,le_refl,ite_true] - | succ r ih => - simp only [Nat.add_succ] at * - rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] - let σ := benesStepEquiv (H+r) ω - let x := e.trans (headTailEquiv (H+r)).toEmbedding - let col := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + - cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ - rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] - rw [inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - - -theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ - Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by - classical - have hec : (Finset.univ.image e).card = Fintype.card ι := by - rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] - have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) - (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) - (pow_nonneg (by linarith) _) (fun b => by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) - calc - _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by - apply finiteMean_mono - intro ω - rw [←pow_mul] - exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) - _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => - (q^H)^(sparseMass (centralBlock r H) - (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by - simp_rw [cutoffMass_central] - simp only [finiteMean_prod,finiteMean_const] - _ ≤ _ := by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, - Finset.card_univ,card_positions,nsmul_eq_mul] using hm - -variable {α B : Type*} {r s : ℕ} - -def parallelFreshPre (pre : α ≃ B × Card (s+r)) - (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := - ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans - (Equiv.prodCongrRight (fun b => - (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans - (Equiv.prodAssoc _ _ _).symm - -def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := - (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) - (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post - -def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := - fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 - -lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : - relabeledPerm pre post (parallelAssembled lo hi) = - relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by - ext x - have h := butterfly_split r s (lo (pre x).1) - (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 - have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h - simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, - Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, - Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, - Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh - -theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] - (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ - (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by - simp_rw [parallel_exposed_perm] - exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq - -end Thorp -namespace Thorp -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] - -lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Fintype.card_congr - refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ - invFun := fun C => ⟨C.val,?_,C.property.2⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ - -lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : - orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by - ext y - simp only [mem_orbitSet,Finset.mem_image] - rw [Equiv.Perm.sameCycle_conj] - change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y - rw [Equiv.symm_apply_apply] - constructor - · intro h - exact ⟨g.symm y,h,g.apply_symm_apply y⟩ - · rintro ⟨z,hz,rfl⟩ - simpa only [Equiv.symm_apply_apply] using hz - -noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) - (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by - refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ - -lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : - Function.Injective (conjugateCycle p g S) := by - intro C D he - apply Subtype.ext - exact (Finset.image_injective g.injective) (congrArg Subtype.val he) - -lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Nat.le_antisymm - · have h := Fintype.card_le_of_injective _ - (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) - have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group - rw [inv_inv,hp] at h - have hs : (S.image g).image g.symm = S := by - ext x - simp only [Finset.mem_image] - constructor - · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ - have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he - exact hz' ▸ hz - · intro hx - exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ - change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h - rw [hs] at h - exact h - · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) - -lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false)) := by - have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) - simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h - -lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle - ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = - Fintype.card (RoutingNetwork.SelectedCycle - (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by - let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) - calc - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) - (S.image X₀.symm)) := by - change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ - have h := (selectedCycle_conjugate p X₀⁻¹ S).symm - rw [inv_inv] at h - exact h - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ - (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm - _ = _ := by - have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group - rw [he] - -end Thorp -namespace Thorp - -noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := - Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) - -lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - 0 ≤ cycleCoefficient r J q := by - unfold cycleCoefficient - exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) - (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) - -lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] - (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by - have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) - (boolFiber (PairRouting.labelSet e) true) - rw [childJoin_boolFiber,PairRouting.card_labelSet] at h - omega - -theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient r J q) := by - classical - let S := boolFiber (PairRouting.labelSet e) false - let S' := S.image X₀.symm - let post := X₀⁻¹*X₁*Y₁⁻¹ - let count := fun hi : Card s × SwitchIndex r → Bool => - Fintype.card (RoutingNetwork.SelectedCycle - ((Equiv.refl _).trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') - have hpoint (hi : Card s × SwitchIndex r → Bool) : - PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by - refine (alternatingCycles_le_projection e _).trans_eq ?_ - simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] - change Fintype.card (RoutingNetwork.SelectedCycle - ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi - exact projectionCycles_forward X₀ X₁ _ Y₁ S - have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq - have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_pos (fun _ => pow_pos (by linarith) _) - have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ - Real.exp (S'.card * cycleCoefficient r J q) := by - rw [←Real.exp_log hp] - apply Real.exp_le_exp.mpr - calc - _ ≤ _ := hm - _ = _ := by unfold cycleCoefficient; ring - have hcard : S'.card ≤ Fintype.card ι := by - rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] - exact projectionSide_card_le e - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) - _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right - (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) - - -def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ - (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) where - toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), - fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) - invFun c := fun j => match j.2 with - | Sum.inl y => c.2 (j.1,y) - | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) - left_inv hi := by - funext j - rcases j with ⟨z,y|⟨b,i⟩⟩ - · rfl - · cases b <;> rfl - right_inv c := by - rcases c with ⟨⟨h₀,h₁⟩,η⟩ - rfl - -lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) - (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) : - assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = - (coinStepEquiv (s+r)).symm - ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, - assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), - fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - -noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (ξ η : Card d → Bool) : - palindromeLevelCost t (d+1) e - ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by - rw [palindromeLevelCost] - rfl - -lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] - - -theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - let χ := coinStepEquiv (s+r) X - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x χ.2 - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) - else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - palindromeLevelCost (s+u+1) (s+r+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] - rw [palindromeLevelCost_step] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] - congr 2 - funext b - cases b <;> rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' e₀ χ.1.1 lo₀ - have h₁ := ih u hu' e₁ χ.1.2 lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -def switchHeight : (d : ℕ) → SwitchIndex d → ℕ - | 0, i => nomatch i - | d+1, Sum.inl _ => d+1 - | d+1, Sum.inr (_,i) => switchHeight d i - -lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - rcases i with y | ⟨b,i⟩ - · exact le_refl _ - · exact (ih i).trans (Nat.le_succ d) - -def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := - ∀ i, switchHeight d i ≤ s → Y i = Y' i - -def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := - ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' - -lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} - (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := - fun i hi => hh i (hi.trans h) - -lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} - (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := - fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) - -lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} - (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := - fun Y Y' h => congrArg g (hf Y Y' h) - -lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) - (f : ι → (SwitchIndex d → Bool) → ℕ) - (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : - LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by - intro Y Y' h - exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) - -lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi hi' : Card s × SwitchIndex r → Bool) : - AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by - induction r with - | zero => intro i _; rfl - | succ r ih => - intro i h - rcases i with y | ⟨b,i⟩ - · have : s+r+1 ≤ s := h - omega - · exact ih (fun j => lo (Fin.cons b j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h - -lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by - classical - induction d generalizing ι with - | zero => intro Y Y' _; rfl - | succ d ih => - intro Y Y' h - change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step,palindromeLevelCost_step] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih - intro i hi - exact h (Sum.inr (true,i)) hi - -lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) - (hG : ∀ lo : Card r × SwitchIndex s → Bool, - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : - finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by - rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] - apply finiteMean_mono - intro lo - let H : Card s × SwitchIndex r → Bool := fun _ => false - have hh (hi : Card s × SwitchIndex r → Bool) : - F (assembleBits r s lo hi) = F (assembleBits r s lo H) := - hA _ _ (assembleBits_agree r s lo hi H) - simp_rw [hh,finiteMean_const] - rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = - (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by - funext hi; exact mul_comm _ _,finiteMean_mul_const] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) - - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/250) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by - have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) - have he := Real.exp_pos ((l:ℝ)/32) - have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h - exact_mod_cast this - - -lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] - (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : - q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by - have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = - (∑ i, z i:ℕ)*Real.log q := by - simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] - field_simp - have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) - rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he - simpa only [Real.exp_nat_mul,Real.exp_log hq] using he - -noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω - -lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact palindromeLevelCost_gt _ _ (by omega) _ _ - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.BenesCoins + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp + +lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : + x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by + classical + constructor + · intro h + obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h + simp only [Equiv.apply_symm_apply] + · intro h + apply Finset.mem_image.mpr + refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ + rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] + +lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by + classical + rw [centralBlock,Finset.card_image_of_injective] + · exact card_positions H + · intro x y h + exact congrArg Prod.snd ((cardSplit r H).symm.injective h) + +lemma centralBlock_disjoint (r H : ℕ) : + Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by + classical + intro b b' h + apply Finset.disjoint_left.mpr + intro x hx hy + exact h (((mem_centralBlock r H b x).mp hx).symm.trans + ((mem_centralBlock r H b' x).mp hy)) + +lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by + classical + ext x + simp only [mem_centralBlock,Finset.mem_univ,iff_true] + exact Subsingleton.elim _ _ + +lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : + centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by + classical + simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, + Fin.cons_zero,Fin.tail_cons,Function.comp_def] + +lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : + centralBlock (r+1) H (Fin.cons b c) ∩ A = + (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by + classical + rw [centralBlock_step] + ext x + constructor + · intro hx + obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB + exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, + (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ + +lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : + sparseMass (centralBlock 0 H) A = crowdedMass A.card := by + classical + simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, + Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] + +lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : + sparseMass (centralBlock (r+1) H) A = + sparseMass (centralBlock r H) (childMarks A false) + + sparseMass (centralBlock r H) (childMarks A true) := by + classical + unfold sparseMass + rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl + simp only [Fintype.sum_bool,ht] + have hc (b : Bool) (c : Card r) : + (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = + (centralBlock r H c ∩ childMarks A b).card := by + rw [block_inter_step] + apply Finset.card_image_of_injective + intro x y h + simpa only [Fin.tail_cons] using congrArg Fin.tail h + simp only [hc] + exact add_comm _ _ + + +lemma inverseButterfly_coordinates_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) + (x : Card (d+1)) : + headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = + (Bool.xor (x 0) (ξ (Fin.tail x)), + (butterflyPerm d (decodeButterfly d + (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by + rw [butterflyPerm_step] + rfl + +lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : + childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) + ((coinStepEquiv d).symm (c,ξ))) b = + inverseButterflyMarks d + (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) + (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by + classical + let x := e.trans (headTailEquiv d).toEmbedding + let col := PairRouting.colors x ξ + let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b + have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = + (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := + inverseButterfly_coordinates_step d c ξ (e i) + ext y + simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, + Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] + constructor + · rintro ⟨i,hi⟩ + have he := congrArg (headTailEquiv d) hi + rw [hp i] at he + change (col i,_) = (b,y) at he + have hb := congrArg Prod.fst he + have hy := congrArg Prod.snd he + dsimp only at hb hy + refine ⟨⟨i,hb⟩,?_⟩ + change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y + simpa only [hb] using hy + · rintro ⟨i,hi⟩ + refine ⟨i.val,?_⟩ + apply (headTailEquiv d).injective + rw [hp] + change (col i.val,_) = (b,y) + have hb : col i.val = b := i.property + rw [hb] + exact Prod.ext rfl hi + +lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : + (inverseButterflyMarks d A ω).card = A.card := by + classical + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective + +lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : + ω.2 = (coinStepEquiv d).symm + (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by + change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) + exact ((coinStepEquiv d).symm_apply_apply ω.2).symm + +lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : + cutoffMass H (H+r) e ω = + sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by + classical + induction r generalizing ι with + | zero => + rw [sparseMass_central_zero,inverseButterflyMarks_card, + Finset.card_image_of_injective _ e.injective,Finset.card_univ] + cases H with + | zero => + have hcard : Fintype.card ι ≤ 1 := by + have hh := Fintype.card_le_of_injective e e.injective + simpa only [Nat.add_zero,card_positions,pow_zero] using hh + simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] + | succ H => simp only [cutoffMass,le_refl,ite_true] + | succ r ih => + simp only [Nat.add_succ] at * + rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] + let σ := benesStepEquiv (H+r) ω + let x := e.trans (headTailEquiv (H+r)).toEmbedding + let col := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + + cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ + rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] + rw [inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + + +theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ + Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by + classical + have hec : (Finset.univ.image e).card = Fintype.card ι := by + rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] + have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) + (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) + (pow_nonneg (by linarith) _) (fun b => by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) + calc + _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by + apply finiteMean_mono + intro ω + rw [←pow_mul] + exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) + _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => + (q^H)^(sparseMass (centralBlock r H) + (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by + simp_rw [cutoffMass_central] + simp only [finiteMean_prod,finiteMean_const] + _ ≤ _ := by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, + Finset.card_univ,card_positions,nsmul_eq_mul] using hm + +variable {α B : Type*} {r s : ℕ} + +def parallelFreshPre (pre : α ≃ B × Card (s+r)) + (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := + ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans + (Equiv.prodCongrRight (fun b => + (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans + (Equiv.prodAssoc _ _ _).symm + +def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := + (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) + (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post + +def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := + fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 + +lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : + relabeledPerm pre post (parallelAssembled lo hi) = + relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by + ext x + have h := butterfly_split r s (lo (pre x).1) + (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 + have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h + simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, + Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, + Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, + Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh + +theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] + (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ + (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by + simp_rw [parallel_exposed_perm] + exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq + +end Thorp +namespace Thorp +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] + +lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Fintype.card_congr + refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ + invFun := fun C => ⟨C.val,?_,C.property.2⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ + +lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : + orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by + ext y + simp only [mem_orbitSet,Finset.mem_image] + rw [Equiv.Perm.sameCycle_conj] + change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y + rw [Equiv.symm_apply_apply] + constructor + · intro h + exact ⟨g.symm y,h,g.apply_symm_apply y⟩ + · rintro ⟨z,hz,rfl⟩ + simpa only [Equiv.symm_apply_apply] using hz + +noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) + (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by + refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ + +lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : + Function.Injective (conjugateCycle p g S) := by + intro C D he + apply Subtype.ext + exact (Finset.image_injective g.injective) (congrArg Subtype.val he) + +lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Nat.le_antisymm + · have h := Fintype.card_le_of_injective _ + (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) + have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group + rw [inv_inv,hp] at h + have hs : (S.image g).image g.symm = S := by + ext x + simp only [Finset.mem_image] + constructor + · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ + have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he + exact hz' ▸ hz + · intro hx + exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ + change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h + rw [hs] at h + exact h + · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) + +lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false)) := by + have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) + simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h + +lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle + ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = + Fintype.card (RoutingNetwork.SelectedCycle + (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by + let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) + calc + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) + (S.image X₀.symm)) := by + change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ + have h := (selectedCycle_conjugate p X₀⁻¹ S).symm + rw [inv_inv] at h + exact h + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ + (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm + _ = _ := by + have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group + rw [he] + +end Thorp +namespace Thorp + +noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := + Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) + +lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + 0 ≤ cycleCoefficient r J q := by + unfold cycleCoefficient + exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) + (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) + +lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by + have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) + (boolFiber (PairRouting.labelSet e) true) + rw [childJoin_boolFiber,PairRouting.card_labelSet] at h + omega + +theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient r J q) := by + classical + let S := boolFiber (PairRouting.labelSet e) false + let S' := S.image X₀.symm + let post := X₀⁻¹*X₁*Y₁⁻¹ + let count := fun hi : Card s × SwitchIndex r → Bool => + Fintype.card (RoutingNetwork.SelectedCycle + ((Equiv.refl _).trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') + have hpoint (hi : Card s × SwitchIndex r → Bool) : + PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by + refine (alternatingCycles_le_projection e _).trans_eq ?_ + simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] + change Fintype.card (RoutingNetwork.SelectedCycle + ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi + exact projectionCycles_forward X₀ X₁ _ Y₁ S + have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq + have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_pos (fun _ => pow_pos (by linarith) _) + have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ + Real.exp (S'.card * cycleCoefficient r J q) := by + rw [←Real.exp_log hp] + apply Real.exp_le_exp.mpr + calc + _ ≤ _ := hm + _ = _ := by unfold cycleCoefficient; ring + have hcard : S'.card ≤ Fintype.card ι := by + rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] + exact projectionSide_card_le e + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) + _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) + + +def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ + (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) where + toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), + fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) + invFun c := fun j => match j.2 with + | Sum.inl y => c.2 (j.1,y) + | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) + left_inv hi := by + funext j + rcases j with ⟨z,y|⟨b,i⟩⟩ + · rfl + · cases b <;> rfl + right_inv c := by + rcases c with ⟨⟨h₀,h₁⟩,η⟩ + rfl + +lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) + (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) : + assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = + (coinStepEquiv (s+r)).symm + ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, + assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), + fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + +noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (ξ η : Card d → Bool) : + palindromeLevelCost t (d+1) e + ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by + rw [palindromeLevelCost] + rfl + +lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] + + +theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + let χ := coinStepEquiv (s+r) X + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x χ.2 + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) + else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + palindromeLevelCost (s+u+1) (s+r+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] + rw [palindromeLevelCost_step] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] + congr 2 + funext b + cases b <;> rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' e₀ χ.1.1 lo₀ + have h₁ := ih u hu' e₁ χ.1.2 lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +def switchHeight : (d : ℕ) → SwitchIndex d → ℕ + | 0, i => nomatch i + | d+1, Sum.inl _ => d+1 + | d+1, Sum.inr (_,i) => switchHeight d i + +lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + rcases i with y | ⟨b,i⟩ + · exact le_refl _ + · exact (ih i).trans (Nat.le_succ d) + +def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := + ∀ i, switchHeight d i ≤ s → Y i = Y' i + +def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := + ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' + +lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} + (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := + fun i hi => hh i (hi.trans h) + +lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} + (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := + fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) + +lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} + (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := + fun Y Y' h => congrArg g (hf Y Y' h) + +lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) + (f : ι → (SwitchIndex d → Bool) → ℕ) + (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : + LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by + intro Y Y' h + exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) + +lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi hi' : Card s × SwitchIndex r → Bool) : + AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by + induction r with + | zero => intro i _; rfl + | succ r ih => + intro i h + rcases i with y | ⟨b,i⟩ + · have : s+r+1 ≤ s := h + omega + · exact ih (fun j => lo (Fin.cons b j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h + +lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by + classical + induction d generalizing ι with + | zero => intro Y Y' _; rfl + | succ d ih => + intro Y Y' h + change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step,palindromeLevelCost_step] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih + intro i hi + exact h (Sum.inr (true,i)) hi + +lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) + (hG : ∀ lo : Card r × SwitchIndex s → Bool, + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : + finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by + rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] + apply finiteMean_mono + intro lo + let H : Card s × SwitchIndex r → Bool := fun _ => false + have hh (hi : Card s × SwitchIndex r → Bool) : + F (assembleBits r s lo hi) = F (assembleBits r s lo H) := + hA _ _ (assembleBits_agree r s lo hi H) + simp_rw [hh,finiteMean_const] + rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = + (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by + funext hi; exact mul_comm _ _,finiteMean_mul_const] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) + + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/250) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by + have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) + have he := Real.exp_pos ((l:ℝ)/32) + have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h + exact_mod_cast this + + +lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] + (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : + q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = + (∑ i, z i:ℕ)*Real.log q := by + simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] + field_simp + have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) + rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he + simpa only [Real.exp_nat_mul,Real.exp_log hq] using he + +noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω + +lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact palindromeLevelCost_gt _ _ (by omega) _ _ + +lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/PriorPaths.lean index eaa8b110a2355ffc1afa933c03e181e46d984000..6abafd0c98c6286f1ed6ca30af3156ccd2cf5ae7 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/PriorPaths.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.AssignmentSlots - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.AssignmentSlots + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/Representative.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/Representative.lean index efdb126563ceb26e4e27fc6a55d89d42882f48b2..d09582b80efffb74e632364171a4126e5a099e2b 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/Representative.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/Representative.lean @@ -1,893 +1,893 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ShapePartitionEquiv - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] -omit [FiniteDimensional ℂ V] in -lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : - LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = - (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by - change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ - rw [map_sum] - have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by - rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] - simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - -lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (A : Module.End ℂ V) : - ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ - c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by - obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) - have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by - rw [←hc] - rfl - refine ⟨c,he,?_⟩ - rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] - -theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (u v w z : V) : - (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = - (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by - obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap - rw [InnerProductSpace.trace_rankOne] at htrace - have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc - change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ - simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ - have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by - simpa only [mul_comm] using happ - rw [hsum] - calc - _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring - _ = _ := by rw [htrace] - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X : Type*} [Group G] [Fintype G] [Fintype X] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) - -noncomputable def representative (x : X) : G := Classical.choose (ha x) - -omit [Fintype G] [Fintype X] in -lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := - Classical.choose_spec (ha x) - -include ha in -lemma orbit_sum (F : X → ℂ) : - (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by - have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by - obtain ⟨t,rfl⟩ := ha x - symm - apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) - intro g - simp - calc - _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm - _ = ∑ g : G, ∑ x : X, F x := by - apply Finset.sum_congr rfl - intro g _ - exact Equiv.sum_comp (a g) F - _ = _ := by simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) - -def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w - -noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : - coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by - let r := representative a x₀ ha (a g x₀) - have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ - have hs : a (g⁻¹*r) x₀=x₀ := by - simp only [map_mul,Equiv.Perm.mul_apply] - rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] - rfl - have he := congrArg (ρ g) (hw (g⁻¹*r) hs) - have hh : ρ r w=ρ g w := by - simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, - mul_inv_cancel_left] using he - change inner ℂ (ρ r w) v= _ - rw [hh] - -lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = - (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by - have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) - simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs - simp only [←starRingEnd_apply,inner_conj_symm] at hs - simp only [starRingEnd_apply] at hs - have ho := coefficient_orthogonality ρ hρ v w z t - have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - apply mul_left_cancel₀ hcard - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,starRingEnd_apply] - have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = - ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by - apply Finset.sum_congr rfl - intro x _ - ring - rw [hsum] - calc - _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, - star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring - _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, - inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring - _ = _ := by rw [ho]; ring - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) - (v : V) (g : G) (x : X) : - coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by - obtain ⟨r,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, - coefficient_at a x₀ ha ρ w hw] - simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] - -noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := - (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v - -lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = - inner ℂ z w*inner ℂ v t := by - let : Nonempty X := ⟨x₀⟩ - have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = - (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by - rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] - simp - simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] - simp only [Complex.conj_ofReal] - rw [←mul_assoc,←pow_two,hs] - have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t - field_simp - simpa only [mul_assoc] using hi - -lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) - (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : - Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by - rw [orthonormal_iff_ite] at hw ⊢ - intro i j - rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, - inner_self_eq_norm_sq_to_K,hv] - simp [eq_comm] - -lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : - ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by - have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v - rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he - simp only [inner_self_eq_norm_sq_to_K] at he - norm_num at he - have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he - nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteConvolution -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) -noncomputable def power (p : G → ℝ) : ℕ → G → ℝ - | 0 => fun g => if g=1 then 1 else 0 - | n+1 => conv p (power p n) - -lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : - ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) - -lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) - {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by - apply lt_of_lt_of_le (mul_pos ha hb) - have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) - (Finset.mem_univ a) - simpa [conv] using h - -lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by - unfold conv - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [←Finset.mul_sum] - congr 1 - exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) - -lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by - intro n - induction n with - | zero => intro g; simp only [power]; split_ifs <;> norm_num - | succ n ih => exact conv_nonneg hp ih - -lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by - intro n - induction n with - | zero => simp [power] - | succ n ih => rw [power,sum_conv,hp,ih,one_mul] - -lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) - (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by - induction l with - | nil => simp [power] - | cons a l ih => - simpa only [List.length_cons,List.prod_cons,power] using - conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) - (ih (fun g hg => hl g (by simp [hg]))) - -lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by - induction m, hnm using Nat.le_induction with - | base => exact hg - | succ m _ ih => - simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih - -theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - (hgen : Subgroup.closure {g | 0 < p g}=⊤) : - ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by - have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by - rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] - trivial - choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) - let n := Finset.univ.sup (fun g => (l g).length) - refine ⟨n,fun g => ?_⟩ - have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) - have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) - have hpos := power_list_pos hp (l g) (hl g) - rw [hprod g] at hpos - exact power_pos_mono hp h1 (hlen.trans hpow) hpos - -structure Minorant (p : G → ℝ) where - exponent : ℕ - mass : ℝ - mass_pos : 0 < mass - mass_le_one : mass ≤ 1 - lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g - -noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) - (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by - let n := Classical.choose (exists_positive_power hp h1 hgen) - have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) - let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) - have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) - have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) - have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos - have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' - refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ - have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp - rw [he] - exact hag g - -end Thorp.FiniteConvolution -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : - continuousRepresentation ρ g v=ρ g v := rfl - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : - ‖ρ g v‖=‖v‖ := by - rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] - -omit [Fintype G] in -lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - ‖continuousRepresentation ρ g‖≤1 := by - apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one - intro v - simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] - -omit [Fintype G] in -lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by - ext w - apply ext_inner_left ℂ - intro v - rw [ContinuousLinearMap.adjoint_inner_right] - exact (unitary_inner_inv ρ hρ g v w).symm - -noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := - ∑ g, (p g : ℂ) • continuousRepresentation ρ g - -lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro g _ - rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] - exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) - -lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by - change (weightedOperator ρ p).adjoint=weightedOperator ρ p - unfold weightedOperator - rw [map_sum] - simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] - apply Fintype.sum_equiv (Equiv.inv G) - intro g - simp [hp] - -noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := - weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) - -lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) - -lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : - continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,←map_mul] - exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) - -lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : - uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,←map_mul] - exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) - -lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : - IsIdempotentElem (uniformOperator ρ) := by - change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ - nth_rw 1 [uniformOperator,weightedOperator] - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, - ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] - rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsStarProjection (uniformOperator ρ) := - ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ - -lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : - weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : - uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) - (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : - ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by - let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) - have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) - have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hsum : ∑ g,q g=1-ε := by - simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by - simp only [uniformOperator,weightedOperator] - rw [Finset.smul_sum,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro g _ - simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, - Complex.ofReal_inv,Complex.ofReal_natCast] - congr 1 - field_simp - ring - have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by - rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] - rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] - calc - _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ - _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) - ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) - (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) - _ = _ := mul_one _ - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : - weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by - unfold weightedOperator FiniteConvolution.conv - simp only [Complex.ofReal_sum,Finset.sum_smul] - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [Finset.mul_sum] - simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp [Complex.ofReal_mul,mul_comm] - -lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : - weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by - induction n with - | zero => simp [FiniteConvolution.power,weightedOperator] - | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] - -lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) - (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : - (weightedOperator ρ p-uniformOperator ρ)^n= - (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by - have hAP := weighted_uniform_left ρ p - have hPA := weighted_uniform_right ρ p - rw [hp,one_smul] at hAP hPA - have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by - show _*_= _*_ - rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] - have he : weightedOperator ρ p-uniformOperator ρ= - weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] - rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] - -noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := - 1-c.mass/(2*(2:ℝ)^c.exponent) - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - unfold minorantGap - linarith - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by - unfold minorantGap - exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) - -theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) - (c : FiniteConvolution.Minorant p) : - ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by - have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) - have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) - (FiniteConvolution.sum_power hp _) c.mass c.lower - rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), - hself.norm_pow_two_pow] at hbound - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - have hbern := one_add_mul_le_pow - (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) - (2^c.exponent) - have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by - push_cast - field_simp - ring - rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern - by_contra h - have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h - have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) - linarith [c.mass_pos] - -end Thorp.UnitaryFinite -namespace Thorp -open scoped BigOperators Classical - -def butterflyIdentity : (d : ℕ) → Butterfly d - | 0 => () - | d+1 => (fun _ => false,fun _ => butterflyIdentity d) - -lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by - apply Equiv.ext - intro x - change switchFun (fun _ => false) x=x - simp [switchFun] - -lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by - ext x i - simp [childLift] - -lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by - induction d with - | zero => rfl - | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] - -noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where - toFun p := childLift (fun c => if c=b then p else 1) - map_one' := by simpa only [ite_self] using childLift_one d - map_mul' p q := by - rw [childLift_mul] - congr 1 - funext c - split_ifs <;> simp - -lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : - childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ - by_cases hc : c=b - · subst c - simp only [↓reduceIte] - rw [Equiv.swap_apply_def] - split_ifs with h₁ h₂ - · subst w; simp - · subst w; simp - · rw [Equiv.swap_apply_of_ne_of_ne] - · exact fun h => h₁ (by simpa using congrArg Fin.tail h) - · exact fun h => h₂ (by simpa using congrArg Fin.tail h) - · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - -lemma pairSwitch_single (d : ℕ) (u : Card d) : - pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ - by_cases h : w=u - · subst w - cases c <;> simp [switchFun] - · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) - have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) - simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] - -theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) - (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by - induction d with - | zero => - apply top_unique - intro p _ - have hp : p=1 := Subsingleton.elim _ _ - rw [hp] - exact H.one_mem - | succ d ih => - have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by - have hc : H.comap (childInjection d b)=⊤ := by - apply ih - intro ω - change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H - have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) - simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h - have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial - exact hp - have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by - rw [←pairSwitch_single] - have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) - simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h - have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by - have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by - cases a <;> cases b - · rw [Equiv.swap_self]; exact H.one_mem - · exact hpair _ - · rw [Equiv.swap_comm]; exact hpair _ - · rw [Equiv.swap_self]; exact H.one_mem - have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by - convert ht (x 0) (y 0) (Fin.tail x) using 1 - rw [Fin.cons_self_tail] - have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) - rw [childInjection_swap,Fin.cons_self_tail] at h₂ - exact SubmonoidClass.swap_mem_trans H h₁ h₂ - rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] - rintro _ ⟨x,y,_,rfl⟩ - exact hswap x y - -lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := - butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) - -variable {Ω G : Type*} [Fintype Ω] [Fintype G] - -noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := - finiteMean (fun ω => if P ω=g then 1 else 0) - -omit [Fintype G] in -lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := - finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) - -lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by - unfold sampleLaw - rw [←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype G] in -lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : - 0 by split_ifs <;> norm_num)] - simp only [Finset.mem_univ,true_and] - apply exists_congr - intro ω - split_ifs <;> simp_all - -omit [Fintype G] in -lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : - sampleLaw (P ∘ e)=sampleLaw P := by - funext g - simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) - -variable [Group G] -omit [Fintype G] in -lemma sampleLaw_inverse (P : Ω → G) (g : G) : - sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by - apply finiteMean_congr - intro ω - rw [inv_eq_iff_eq_inv] - -omit [Fintype G] in -lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) - (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by - rw [←sampleLaw_inverse] - have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) - rw [hh,sampleLaw_equiv] - -end Thorp - -namespace Thorp -open scoped BigOperators Classical - -lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by - refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), - (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - exact mul_inv_cancel _ - -lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : - ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by - refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - unfold palindromePerm - have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := - (butterflyCoinEquiv d).apply_symm_apply β - rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] - -lemma palindrome_support_generates (d : ℕ) : - Subgroup.closure {g | 0 P i v) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) - rw [hsplit] at hp - have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) - rw [hsplit] at ha - have he (i : ι) : P i (A v)=(A*P i) (P i v) := by - change (P i*A) v=(A*P i*P i) v - rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] - have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by - rw [he] - exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) - have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) - simp_rw [mul_pow] at hsq - rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq - exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq - -theorem sector_sandwich_le (T P A B : V →L[ℂ] V) - (hT : IsStarProjection T) (hP : IsStarProjection P) - (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : - ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by - have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by - change _=star (T*B)*A*(T*B) - rw [star_mul,hT.isSelfAdjoint.star_eq] - change _=B.adjoint*T*A*(T*B) - rw [mul_assoc B.adjoint T A,←hcomm.eq] - simp only [mul_assoc] - rw [←mul_assoc T T B,hT.isIdempotentElem.eq] - have hTB : ‖T*B‖≤‖P*B‖ := by - have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] - rw [he] - exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) - rw [he,projection_sandwich_norm P B hP] - calc - _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] - _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 - -omit [CompleteSpace V] [Fintype ι] in -lemma resolution_commute (P : ι → V →L[ℂ] V) - (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by - by_cases hij : i=j - · subst j; exact Commute.refl _ - · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm - -omit [Fintype ι] in -lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : - (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by - rw [Finset.sum_mul] - have he (i : ι) : P i*P j=if i=j then P j else 0 := by - split_ifs with h - · subst i; exact (hP j).isIdempotentElem.eq - · exact horth i j h - simp only [he,Finset.sum_ite_eq'] - -lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) - (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) - (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : - ‖A*(∑ i∈S,P i)‖≤c := by - apply resolution_norm_bound P hP horth hsum _ _ c hc - · intro i - rw [mul_assoc,resolution_sum_mul P hP horth] - split_ifs with hi - · exact hbound i hi - · simp [hc] - · intro i - exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) - -theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) - (hT : ∀ i, IsStarProjection (T i)) - (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) - (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) - (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) - (hA : ‖A‖≤1) (hB : ‖B‖≤1) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : - ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by - have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm - Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) - have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by - rw [Finset.sum_compl_add_sum,hsum] - have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ - ∑ i∈S,B.adjoint*A*T i*B := by - rw [←Finset.sum_mul,←Finset.mul_sum] - rw [←add_mul] - simp only [mul_assoc] - rw [←mul_add,←mul_add,hsplit] - simp only [mul_one,mul_assoc] - rw [he] - apply (norm_add_le _ _).trans - apply add_le_add - · calc - _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := - (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) - hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) - _ = c := by ring - · apply (norm_sum_le _ _).trans - exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA - -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) - -noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1-P i else P i - -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma choice_commute (E F : Finset ι) (i j : ι) : - Commute (choice P E i) (choice P F j) := by - unfold choice - split_ifs - · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) - · exact (Commute.one_left _).sub_left (hcomm i j) - · exact (Commute.one_right _).sub_right (hcomm i j) - · exact hcomm i j - -noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := - s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : - sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by - exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : - sector P hcomm s E=sector P hcomm s F := by - apply Finset.noncommProd_congr rfl - intro i hi - simp only [choice,h i hi] - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_factor_commute (s E F : Finset ι) (i : ι) : - Commute (choice P E i) (sector P hcomm s F) := - Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) - -omit [Fintype ι] in -lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : - IsStarProjection (sector P hcomm s E) := by - induction s using Finset.induction_on with - | empty => exact IsStarProjection.one _ - | @insert a s ha ih => - rw [sector_insert P hcomm s E a ha] - have hc : IsStarProjection (choice P E a) := by - unfold choice - split_ifs - · exact (hP a).one_sub - · exact hP a - exact hc.mul ih (sector_factor_commute P hcomm s E E a) - -end Thorp.CommutingBlocks - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ShapePartitionEquiv + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] +omit [FiniteDimensional ℂ V] in +lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : + LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = + (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by + change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ + rw [map_sum] + have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by + rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] + simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + +lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (A : Module.End ℂ V) : + ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ + c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by + obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) + have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by + rw [←hc] + rfl + refine ⟨c,he,?_⟩ + rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] + +theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (u v w z : V) : + (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = + (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by + obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap + rw [InnerProductSpace.trace_rankOne] at htrace + have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc + change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ + simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ + have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by + simpa only [mul_comm] using happ + rw [hsum] + calc + _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring + _ = _ := by rw [htrace] + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X : Type*} [Group G] [Fintype G] [Fintype X] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) + +noncomputable def representative (x : X) : G := Classical.choose (ha x) + +omit [Fintype G] [Fintype X] in +lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := + Classical.choose_spec (ha x) + +include ha in +lemma orbit_sum (F : X → ℂ) : + (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by + have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by + obtain ⟨t,rfl⟩ := ha x + symm + apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) + intro g + simp + calc + _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm + _ = ∑ g : G, ∑ x : X, F x := by + apply Finset.sum_congr rfl + intro g _ + exact Equiv.sum_comp (a g) F + _ = _ := by simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) + +def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w + +noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : + coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by + let r := representative a x₀ ha (a g x₀) + have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ + have hs : a (g⁻¹*r) x₀=x₀ := by + simp only [map_mul,Equiv.Perm.mul_apply] + rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] + rfl + have he := congrArg (ρ g) (hw (g⁻¹*r) hs) + have hh : ρ r w=ρ g w := by + simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, + mul_inv_cancel_left] using he + change inner ℂ (ρ r w) v= _ + rw [hh] + +lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = + (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by + have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) + simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs + simp only [←starRingEnd_apply,inner_conj_symm] at hs + simp only [starRingEnd_apply] at hs + have ho := coefficient_orthogonality ρ hρ v w z t + have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + apply mul_left_cancel₀ hcard + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,starRingEnd_apply] + have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = + ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by + apply Finset.sum_congr rfl + intro x _ + ring + rw [hsum] + calc + _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, + star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring + _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, + inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring + _ = _ := by rw [ho]; ring + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) + (v : V) (g : G) (x : X) : + coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by + obtain ⟨r,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, + coefficient_at a x₀ ha ρ w hw] + simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] + +noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := + (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v + +lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = + inner ℂ z w*inner ℂ v t := by + let : Nonempty X := ⟨x₀⟩ + have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = + (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by + rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] + simp + simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] + simp only [Complex.conj_ofReal] + rw [←mul_assoc,←pow_two,hs] + have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t + field_simp + simpa only [mul_assoc] using hi + +lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) + (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : + Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by + rw [orthonormal_iff_ite] at hw ⊢ + intro i j + rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, + inner_self_eq_norm_sq_to_K,hv] + simp [eq_comm] + +lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : + ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by + have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v + rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he + simp only [inner_self_eq_norm_sq_to_K] at he + norm_num at he + have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he + nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteConvolution +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) +noncomputable def power (p : G → ℝ) : ℕ → G → ℝ + | 0 => fun g => if g=1 then 1 else 0 + | n+1 => conv p (power p n) + +lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : + ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) + +lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) + {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by + apply lt_of_lt_of_le (mul_pos ha hb) + have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) + (Finset.mem_univ a) + simpa [conv] using h + +lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by + unfold conv + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [←Finset.mul_sum] + congr 1 + exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) + +lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by + intro n + induction n with + | zero => intro g; simp only [power]; split_ifs <;> norm_num + | succ n ih => exact conv_nonneg hp ih + +lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by + intro n + induction n with + | zero => simp [power] + | succ n ih => rw [power,sum_conv,hp,ih,one_mul] + +lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) + (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by + induction l with + | nil => simp [power] + | cons a l ih => + simpa only [List.length_cons,List.prod_cons,power] using + conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) + (ih (fun g hg => hl g (by simp [hg]))) + +lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by + induction m, hnm using Nat.le_induction with + | base => exact hg + | succ m _ ih => + simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih + +theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + (hgen : Subgroup.closure {g | 0 < p g}=⊤) : + ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by + have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by + rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] + trivial + choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) + let n := Finset.univ.sup (fun g => (l g).length) + refine ⟨n,fun g => ?_⟩ + have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) + have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) + have hpos := power_list_pos hp (l g) (hl g) + rw [hprod g] at hpos + exact power_pos_mono hp h1 (hlen.trans hpow) hpos + +structure Minorant (p : G → ℝ) where + exponent : ℕ + mass : ℝ + mass_pos : 0 < mass + mass_le_one : mass ≤ 1 + lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g + +noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) + (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by + let n := Classical.choose (exists_positive_power hp h1 hgen) + have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) + let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) + have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) + have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) + have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos + have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' + refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ + have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp + rw [he] + exact hag g + +end Thorp.FiniteConvolution +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : + continuousRepresentation ρ g v=ρ g v := rfl + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : + ‖ρ g v‖=‖v‖ := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] + +omit [Fintype G] in +lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + ‖continuousRepresentation ρ g‖≤1 := by + apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one + intro v + simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] + +omit [Fintype G] in +lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by + ext w + apply ext_inner_left ℂ + intro v + rw [ContinuousLinearMap.adjoint_inner_right] + exact (unitary_inner_inv ρ hρ g v w).symm + +noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := + ∑ g, (p g : ℂ) • continuousRepresentation ρ g + +lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro g _ + rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] + exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) + +lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by + change (weightedOperator ρ p).adjoint=weightedOperator ρ p + unfold weightedOperator + rw [map_sum] + simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] + apply Fintype.sum_equiv (Equiv.inv G) + intro g + simp [hp] + +noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := + weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) + +lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) + +lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : + continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,←map_mul] + exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) + +lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : + uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,←map_mul] + exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) + +lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : + IsIdempotentElem (uniformOperator ρ) := by + change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ + nth_rw 1 [uniformOperator,weightedOperator] + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, + ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] + rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsStarProjection (uniformOperator ρ) := + ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ + +lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : + weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : + uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) + (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : + ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by + let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) + have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) + have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hsum : ∑ g,q g=1-ε := by + simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by + simp only [uniformOperator,weightedOperator] + rw [Finset.smul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro g _ + simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, + Complex.ofReal_inv,Complex.ofReal_natCast] + congr 1 + field_simp + ring + have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by + rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] + rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] + calc + _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ + _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) + ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) + (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) + _ = _ := mul_one _ + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : + weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by + unfold weightedOperator FiniteConvolution.conv + simp only [Complex.ofReal_sum,Finset.sum_smul] + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [Finset.mul_sum] + simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp [Complex.ofReal_mul,mul_comm] + +lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : + weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by + induction n with + | zero => simp [FiniteConvolution.power,weightedOperator] + | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] + +lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) + (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : + (weightedOperator ρ p-uniformOperator ρ)^n= + (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by + have hAP := weighted_uniform_left ρ p + have hPA := weighted_uniform_right ρ p + rw [hp,one_smul] at hAP hPA + have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by + show _*_= _*_ + rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] + have he : weightedOperator ρ p-uniformOperator ρ= + weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] + rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] + +noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := + 1-c.mass/(2*(2:ℝ)^c.exponent) + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + unfold minorantGap + linarith + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by + unfold minorantGap + exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) + +theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) + (c : FiniteConvolution.Minorant p) : + ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by + have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) + have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) + (FiniteConvolution.sum_power hp _) c.mass c.lower + rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), + hself.norm_pow_two_pow] at hbound + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + have hbern := one_add_mul_le_pow + (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) + (2^c.exponent) + have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by + push_cast + field_simp + ring + rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern + by_contra h + have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h + have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) + linarith [c.mass_pos] + +end Thorp.UnitaryFinite +namespace Thorp +open scoped BigOperators Classical + +def butterflyIdentity : (d : ℕ) → Butterfly d + | 0 => () + | d+1 => (fun _ => false,fun _ => butterflyIdentity d) + +lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by + apply Equiv.ext + intro x + change switchFun (fun _ => false) x=x + simp [switchFun] + +lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by + ext x i + simp [childLift] + +lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by + induction d with + | zero => rfl + | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] + +noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where + toFun p := childLift (fun c => if c=b then p else 1) + map_one' := by simpa only [ite_self] using childLift_one d + map_mul' p q := by + rw [childLift_mul] + congr 1 + funext c + split_ifs <;> simp + +lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : + childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ + by_cases hc : c=b + · subst c + simp only [↓reduceIte] + rw [Equiv.swap_apply_def] + split_ifs with h₁ h₂ + · subst w; simp + · subst w; simp + · rw [Equiv.swap_apply_of_ne_of_ne] + · exact fun h => h₁ (by simpa using congrArg Fin.tail h) + · exact fun h => h₂ (by simpa using congrArg Fin.tail h) + · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + +lemma pairSwitch_single (d : ℕ) (u : Card d) : + pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ + by_cases h : w=u + · subst w + cases c <;> simp [switchFun] + · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) + have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) + simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] + +theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) + (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by + induction d with + | zero => + apply top_unique + intro p _ + have hp : p=1 := Subsingleton.elim _ _ + rw [hp] + exact H.one_mem + | succ d ih => + have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by + have hc : H.comap (childInjection d b)=⊤ := by + apply ih + intro ω + change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H + have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) + simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h + have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial + exact hp + have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by + rw [←pairSwitch_single] + have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) + simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h + have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by + have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by + cases a <;> cases b + · rw [Equiv.swap_self]; exact H.one_mem + · exact hpair _ + · rw [Equiv.swap_comm]; exact hpair _ + · rw [Equiv.swap_self]; exact H.one_mem + have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by + convert ht (x 0) (y 0) (Fin.tail x) using 1 + rw [Fin.cons_self_tail] + have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) + rw [childInjection_swap,Fin.cons_self_tail] at h₂ + exact SubmonoidClass.swap_mem_trans H h₁ h₂ + rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] + rintro _ ⟨x,y,_,rfl⟩ + exact hswap x y + +lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := + butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) + +variable {Ω G : Type*} [Fintype Ω] [Fintype G] + +noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := + finiteMean (fun ω => if P ω=g then 1 else 0) + +omit [Fintype G] in +lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := + finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) + +lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by + unfold sampleLaw + rw [←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype G] in +lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : + 0 by split_ifs <;> norm_num)] + simp only [Finset.mem_univ,true_and] + apply exists_congr + intro ω + split_ifs <;> simp_all + +omit [Fintype G] in +lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : + sampleLaw (P ∘ e)=sampleLaw P := by + funext g + simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) + +variable [Group G] +omit [Fintype G] in +lemma sampleLaw_inverse (P : Ω → G) (g : G) : + sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by + apply finiteMean_congr + intro ω + rw [inv_eq_iff_eq_inv] + +omit [Fintype G] in +lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) + (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by + rw [←sampleLaw_inverse] + have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) + rw [hh,sampleLaw_equiv] + +end Thorp + +namespace Thorp +open scoped BigOperators Classical + +lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by + refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), + (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + exact mul_inv_cancel _ + +lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : + ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by + refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + unfold palindromePerm + have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := + (butterflyCoinEquiv d).apply_symm_apply β + rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] + +lemma palindrome_support_generates (d : ℕ) : + Subgroup.closure {g | 0 P i v) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) + rw [hsplit] at hp + have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) + rw [hsplit] at ha + have he (i : ι) : P i (A v)=(A*P i) (P i v) := by + change (P i*A) v=(A*P i*P i) v + rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] + have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by + rw [he] + exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) + have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) + simp_rw [mul_pow] at hsq + rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq + exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq + +theorem sector_sandwich_le (T P A B : V →L[ℂ] V) + (hT : IsStarProjection T) (hP : IsStarProjection P) + (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : + ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by + have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by + change _=star (T*B)*A*(T*B) + rw [star_mul,hT.isSelfAdjoint.star_eq] + change _=B.adjoint*T*A*(T*B) + rw [mul_assoc B.adjoint T A,←hcomm.eq] + simp only [mul_assoc] + rw [←mul_assoc T T B,hT.isIdempotentElem.eq] + have hTB : ‖T*B‖≤‖P*B‖ := by + have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] + rw [he] + exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) + rw [he,projection_sandwich_norm P B hP] + calc + _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] + _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 + +omit [CompleteSpace V] [Fintype ι] in +lemma resolution_commute (P : ι → V →L[ℂ] V) + (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by + by_cases hij : i=j + · subst j; exact Commute.refl _ + · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm + +omit [Fintype ι] in +lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : + (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by + rw [Finset.sum_mul] + have he (i : ι) : P i*P j=if i=j then P j else 0 := by + split_ifs with h + · subst i; exact (hP j).isIdempotentElem.eq + · exact horth i j h + simp only [he,Finset.sum_ite_eq'] + +lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) + (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) + (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : + ‖A*(∑ i∈S,P i)‖≤c := by + apply resolution_norm_bound P hP horth hsum _ _ c hc + · intro i + rw [mul_assoc,resolution_sum_mul P hP horth] + split_ifs with hi + · exact hbound i hi + · simp [hc] + · intro i + exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) + +theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) + (hT : ∀ i, IsStarProjection (T i)) + (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) + (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) + (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) + (hA : ‖A‖≤1) (hB : ‖B‖≤1) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : + ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by + have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm + Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) + have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by + rw [Finset.sum_compl_add_sum,hsum] + have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ + ∑ i∈S,B.adjoint*A*T i*B := by + rw [←Finset.sum_mul,←Finset.mul_sum] + rw [←add_mul] + simp only [mul_assoc] + rw [←mul_add,←mul_add,hsplit] + simp only [mul_one,mul_assoc] + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add + · calc + _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) + hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) + _ = c := by ring + · apply (norm_sum_le _ _).trans + exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA + +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) + +noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1-P i else P i + +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma choice_commute (E F : Finset ι) (i j : ι) : + Commute (choice P E i) (choice P F j) := by + unfold choice + split_ifs + · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) + · exact (Commute.one_left _).sub_left (hcomm i j) + · exact (Commute.one_right _).sub_right (hcomm i j) + · exact hcomm i j + +noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := + s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : + sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by + exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : + sector P hcomm s E=sector P hcomm s F := by + apply Finset.noncommProd_congr rfl + intro i hi + simp only [choice,h i hi] + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_factor_commute (s E F : Finset ι) (i : ι) : + Commute (choice P E i) (sector P hcomm s F) := + Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) + +omit [Fintype ι] in +lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : + IsStarProjection (sector P hcomm s E) := by + induction s using Finset.induction_on with + | empty => exact IsStarProjection.one _ + | @insert a s ha ih => + rw [sector_insert P hcomm s E a ha] + have hc : IsStarProjection (choice P E a) := by + unfold choice + split_ifs + · exact (hP a).one_sub + · exact hP a + exact hc.mul ih (sector_factor_commute P hcomm s E E a) + +end Thorp.CommutingBlocks + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/RotationMeeting.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/RotationMeeting.lean index 5e9006b90fa97478b2a158790d87b5ccf357b3b7..d67d3d6c82fc18d34b58b2312bb4ef3e4dc37ac8 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/RotationMeeting.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/RotationMeeting.lean @@ -1,881 +1,881 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ExposedCoins - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) - (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -end Thorp - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ExposedCoins + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) + (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +end Thorp + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/SparseSaving/ShapePartitionEquiv.lean b/lean/OAI/Probability/ThorpRouting/SparseSaving/ShapePartitionEquiv.lean index 9bb08fdadbe57b18324fa03a5b4e36135a34bbea..fe114e6bb8f940a6996b13df34afd82c295f365b 100644 --- a/lean/OAI/Probability/ThorpRouting/SparseSaving/ShapePartitionEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/SparseSaving/ShapePartitionEquiv.lean @@ -1,875 +1,875 @@ -import Mathlib -import OAI.Probability.ThorpRouting.SparseSaving.ModifiedReverseEquiv - -namespace OAI - -namespace ThorpNine.SparseSaving - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where - toFun μ := { parts := μ.1.rowLens - parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } - invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ - left_inv μ := by - apply Subtype.ext - obtain ⟨μ,rfl⟩ := μ - exact partitionDiagram_diagramPartition μ - right_inv p := by - apply Nat.Partition.ext - change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts - rw [partitionDiagram_rowLens,Multiset.sort_eq] - -noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm - -noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : - ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := - Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) - -lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : - Function.Injective (conjugacyPartition (α := α)) := by - intro p q - induction p using Quotient.inductionOn with | _ p => - induction q using Quotient.inductionOn with | _ q => - intro h - exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) - -lemma card_conjugacy_le_shapes (N : ℕ) : - Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by - have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) - simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h - -noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := - (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) - -noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : - Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := - (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom - -lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : - Representation.IsIrreducible (labelledRepresentation μ) := by - let e := (labels μ).symm.permCongrHom - let ρ := representation μ.1 - have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ - (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial - exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) - refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } - intro U - let U' : Subrepresentation ρ := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun p v hv => by - have hh := U.apply_mem_toSubmodule (e.symm p) hv - change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh - simpa using hh } - have := representation_irreducible μ.1 - obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' - · left - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - · right - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - -lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) - (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by - apply Subtype.ext - apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv - intro p v - have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v - change T.toLinearEquiv - (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = - representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh - have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] at hh - convert hh using 2 - congr 1 - -end Thorp.Specht - -namespace Thorp.FiniteCharacters -open scoped BigOperators Classical - -section Group -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose -omit [Fintype G] in -lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := - (ConjClasses.exists_rep c).choose_spec - -variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := - fun c => ρ.character (classRep c) - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : - characterClass ρ (ConjClasses.mk g) = ρ.character g := by - have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) - obtain ⟨p,hp⟩ := isConj_iff.mp h - change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g - exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) - -noncomputable def characterDual (ρ : Representation ℂ G V) : - (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where - toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ - map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] - map_smul' a f := by - simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] - simp_rw [mul_assoc] - rw [←Finset.mul_sum] - ring - -lemma characterDual_characterClass (ρ : Representation ℂ G V) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : - characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by - exact_mod_cast (Nat.card_pos (α := G)).ne') - change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ - simp only [characterClass_mk] - exact Representation.char_orthonormal σ ρ - -end Group - -theorem complete_of_card_conjugacy_le - {G ι : Type*} [Group G] [Fintype G] [Fintype ι] - (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] - (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] - (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : - ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases hij : i=j - · subst j - simp only [ite_true] - exact ite_eq_left ⟨Representation.Equiv.refl _⟩ - · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij - exact (horth i j).trans (ite_eq_right hij) - · intro i - simpa using horth i i - have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - have hspan := hLI.span_eq_top_of_card_eq_finrank' heq - by_contra h - push Not at h - have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ - (characterDual σ).ker := by - apply Submodule.span_le.mpr - rintro f ⟨i,rfl⟩ - change characterDual σ (characterClass (ρ i)) = 0 - rw [characterDual_characterClass,ite_eq_right] - rintro ⟨T⟩ - exact (h i).false T.symm - rw [hspan] at hker - have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) - rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz - exact one_ne_zero hz - -end Thorp.FiniteCharacters - -namespace Thorp.Specht -open scoped Classical - -theorem labelled_complete {N : ℕ} - {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : - ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by - let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := - labelledRepresentation_irreducible μ - apply FiniteCharacters.complete_of_card_conjugacy_le - (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ - intro μ ν h ⟨T⟩ - exact h (labelledRepresentation_equiv_shapes μ ν T) - -end Thorp.Specht - -namespace Thorp.PermutationHilbert - -section -open scoped BigOperators ComplexConjugate Classical -open Complex - -variable {X : Type*} [Fintype X] - -noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := - LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p - -@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : - act p v x = v (p⁻¹ x) := rfl - -lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : - act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by - exact EuclideanSpace.piLpCongrLeft_single p x 1 - -lemma trace_projection (W : Submodule ℂ (H X)) : - ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by - classical - have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by - constructor - · intro x; exact (W.orthogonalProjectionOnto x).2 - · intro x hx; exact W.starProjection_eq_self_iff.mpr hx - have ht := hp.trace - rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht - simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, - EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, - OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht - -lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : - (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - classical - have hh := W.inner_starProjection_left_eq_right - (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) - have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := - W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 - rw [hf] at hh - rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh - simpa using hh.symm - -lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) - (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : - act p (W.starProjection v) = W.starProjection (act p v) := by - have hh := (act p).toLinearIsometry.map_starProjection W v - change act p (W.starProjection v) = - (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh - simpa only [hW] using hh - -lemma uniform_diagonal (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : - (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = - Module.finrank ℂ W := by - classical - have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - obtain ⟨p,hp,hW⟩ := htrans x y - subst y - rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] - have ht := trace_projection W - simp_rw [hh] at ht - have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = - (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht - simpa using hhreal - -theorem uncertainty (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (v : H X) (hv : v ∈ W) (x : X) : - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by - classical - have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by - rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, - EuclideanSpace.inner_single_left] - simp - have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v - rw [hh] at hc - have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by - nlinarith [norm_nonneg (v x),norm_nonneg v, - norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] - calc - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ - (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := - mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) - _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] - -end -open scoped BigOperators Classical - -variable {X : Type*} [Fintype X] - -lemma trace_projection_real (W : Submodule ℂ (H X)) : - ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by - have hh := trace_projection W - simp_rw [projection_diagonal] at hh - exact_mod_cast hh - -theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : - (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ - (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by - have he (x : X) (hx : x ∈ S) : - K.starProjection (EuclideanSpace.single x (1:ℂ)) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := by - apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) - intro v hv - exact W.starProjection_inner_eq_zero _ v (hKW hv) - have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ - (Module.finrank ℂ K:ℝ) := by - rw [←trace_projection_real K] - calc - _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by - apply Finset.sum_congr rfl - intro x hx - rw [he x hx] - _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) - have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) - rw [Finset.mul_sum] at hmul - simp_rw [uniform_diagonal W htrans] at hmul - simpa using hmul - -end Thorp.PermutationHilbert -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma finrank_hilbertSpace (μ : YoungDiagram) : - Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := - (hilbertEquiv μ).finrank_map_eq (space μ) - -lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : - hilbertEquiv μ (tabloidRep μ p v) = - PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by - ext f - simp [hilbertEquiv,PermutationHilbert.act_apply] - -lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = - hilbertSpace μ := by - apply le_antisymm - · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ - exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ - · rintro _ ⟨w,hw,rfl⟩ - refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), - ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ - change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w - rw [←hilbert_action] - change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ - rw [←map_mul,mul_inv_cancel,map_one] - rfl - -lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : - ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by - obtain ⟨q,hq⟩ := f.2 - obtain ⟨r,hr⟩ := g.2 - refine ⟨r⁻¹*q, ?_⟩ - apply Subtype.ext - funext x - simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, - Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] - -lemma polytabloid_pairing (μ : YoungDiagram) : - pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by - have h := alternator_pairing μ (polytabloid μ) - have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = - permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply (colGroup μ) (tabloidRep μ) c _ - have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, - Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb - simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb - exact hb.symm - -lemma polytabloid_norm_sq (μ : YoungDiagram) : - ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by - have hp := polytabloid_pairing μ - change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp - rw [inner_self_eq_norm_sq_to_K] at hp - have hre := congrArg Complex.re hp - simpa [pow_two] using hre - -theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : - Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht - (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) - have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ - rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu - exact_mod_cast hu - - -section FiberGroup -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -noncomputable def fiberGroupEquiv (f : α → β) : - fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where - toFun p b := - { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ - invFun x := ⟨p.1⁻¹ x.1, by - have hh := p.2 (p.1⁻¹ x.1) - simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh - exact hh.symm.trans x.2⟩ - left_inv x := by apply Subtype.ext; simp - right_inv x := by apply Subtype.ext; simp } - invFun q := - ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), - fun x => (q (f x) ⟨x,rfl⟩).2⟩ - left_inv p := by - apply Subtype.ext - apply Equiv.ext - intro x - rfl - right_inv q := by - funext b - apply Equiv.ext - intro x - apply Subtype.ext - change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 - cases x with - | mk x hx => dsimp only at *; subst b; rfl - -lemma nat_card_fiberGroup (f : α → β) : - Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by - rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] - simp only [Nat.card_eq_fintype_card,Fintype.card_perm] - -omit [Fintype β] [Fintype γ] in - -lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) - (hinj : ∀ x y, f x = f y → g x = g y → x=y) : - Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by - have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by - intro p q hpq - dsimp only at hpq - have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by - apply inv_mul_eq_iff_eq_mul.mpr - rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] - have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 - have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) - have h1 : p.1.1⁻¹*q.1.1 = 1 := by - apply Equiv.ext - intro x - exact hinj _ x (hf x) (hg x) - have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) - have hpg : p.2=q.2 := by - apply Subtype.ext - have hh := hpq - rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh - exact mul_left_cancel hh - exact Prod.ext hpf hpg - have hc := Fintype.card_le_of_injective _ hi - simpa only [Fintype.card_prod,Fintype.card_perm] using hc - -end FiberGroup - -noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := - fiberGroup (rowIndex (μ := μ)) - -noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := - ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ - -lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by - ext p - constructor - · intro hp x; exact Fin.ext (hp x) - · intro hp x; exact congrArg Fin.val (hp x) - -noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where - smul p f := tabloidAct p f - one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl - mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl - -lemma tabloid_orbit_all (μ : YoungDiagram) : - MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by - ext f - simp only [Set.mem_univ,iff_true] - obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f - exact ⟨p,hp⟩ - -lemma tabloid_stabilizer (μ : YoungDiagram) : - MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by - ext p - change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x - constructor - · intro h x - have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h - simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - · intro h - apply Subtype.ext - funext x - exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) - -lemma card_tabloid_mul_row (μ : YoungDiagram) : - Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by - have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group - (Equiv.Perm (Cell μ)) (baseTabloid μ) - have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = - Fintype.card (Tabloid μ) := by - rw [tabloid_orbit_all,Fintype.card_setUniv] - simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh - -theorem factorial_le_dimension_row_column (μ : YoungDiagram) : - μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by - rw [←card_tabloid_mul_row] - nlinarith [dimension_times_column_ge_tabloids μ] - - -lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by - let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] - -lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by - let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - -lemma card_rowGroup (μ : YoungDiagram) : - Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by - rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_row_fiber] - -lemma card_colGroup (μ : YoungDiagram) : - Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by - rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card,card_col_fiber] - -abbrev Tail (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} - -lemma tail_card (μ : YoungDiagram) : Fintype.card (Tail μ) = μ.card - μ.rowLen 0 := by - have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) - rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh - exact hh - -lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by - have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) - rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h - -noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - {x : Tail μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where - toFun x := ⟨row x.1.1-1, by - have hx := row_lt_colLen x.1.1 - have hc : col x.1.1 = j := congrArg Fin.val x.2 - rw [hc] at hx - have hz := x.1.2 - omega⟩ - invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ - left_inv x := by - apply Subtype.ext - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · change row x.1.1 - 1 + 1 = row x.1.1 - have := x.1.2 - omega - · exact (congrArg Fin.val x.2).symm - right_inv i := by apply Fin.ext; simp [row] - -lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : Tail μ // colIndex x.1 = j} = μ.colLen j-1 := by - rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] - -lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : Tail μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by - by_cases hi : i.val=0 - · rw [ite_eq_left hi] - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun x => x.1.2 ?_⟩ - exact (congrArg Fin.val x.2).trans hi - · rw [ite_eq_right hi] - let e : {x : Tail μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := - { toFun := fun x => ⟨x.1.1,x.2⟩ - invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ - left_inv := fun x => rfl - right_inv := fun x => rfl } - rw [Fintype.card_congr e,card_row_fiber] - -lemma tail_row_group (μ : YoungDiagram) : - (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) = - Fintype.card (rowGroup μ) := by - rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_row] - by_cases hn : μ.colLen 0=0 - · have hr : μ.rowLen 0=0 := by - by_contra h - have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) - have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem - omega - let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ - simp [hr] - · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ - have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] - simp only [hz] - have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = - ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by - rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] - simp only [ite_true,Nat.factorial_zero,mul_one] - apply Finset.prod_congr rfl - intro x hx - rw [ite_eq_right (Finset.mem_erase.mp hx).1] - rw [hprod] - exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) - -lemma sum_tail_columns (μ : YoungDiagram) : - ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by - simp_rw [←card_tail_col] - rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : Tail μ => colIndex x.1)),tail_card] - -lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := - YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) - -lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num - | succ n ih => rw [pow_succ]; omega - -lemma column_group_le_tail (μ : YoungDiagram) : - Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * - Fintype.card (fiberGroup (fun x : Tail μ => colIndex x.1)) := by - rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => colIndex x.1)),nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_col] - calc - _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by - apply Finset.prod_congr rfl - intro j hj - exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm - _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by - apply Finset.prod_le_prod - intro j hj - exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) - _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] - -theorem choose_tail_le_dimension (μ : YoungDiagram) : - μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - have htail := card_fiberGroups_mul_le - (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) - (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) - rw [tail_card] at htail - have hc := column_group_le_tail μ - have hr := tail_row_group μ - have hd := factorial_le_dimension_row_column μ - simp only [←Nat.card_eq_fintype_card] at htail hc hr hd - have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * - ((μ.rowLen 0).factorial * j.factorial) := by - calc - _ ≤ _ := hd - _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * - (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc - _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * - (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * - Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring - _ ≤ _ := by - calc - _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := - Nat.mul_le_mul_left _ htail - _ = _ := by ring - have hj : j ≤ μ.card := Nat.sub_le _ _ - have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega - have hf := Nat.choose_mul_factorial_mul_factorial hj - rw [hs] at hf - rw [←hf] at hh - have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) - nlinarith - - -lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : - ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by - let e : s ≃ t := Finset.equivOfCardEq hc - let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by - simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) - let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) - refine ⟨p,fun x => ?_⟩ - by_cases hx : x ∈ s - · have hp : p x ∈ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t - rw [Equiv.sumCompl_symm_apply_of_pos hx] - exact (e ⟨x,hx⟩).2 - exact iff_of_true hp hx - · have hp : p x ∉ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t - rw [Equiv.sumCompl_symm_apply_of_neg hx] - exact (ec ⟨x,hx⟩).2 - exact iff_of_false hp hx - -noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := - Finset.univ.filter (fun x => (f.1 x).val ≠ 0) - -@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : - x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] - -lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tailSet (tabloidAct p f) = (tailSet f).image p := by - ext x - simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] - constructor - · intro h; exact ⟨p⁻¹ x,h,by simp⟩ - · rintro ⟨y,hy,rfl⟩; simpa using hy - -lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : - (tailSet f).card = μ.card-μ.rowLen 0 := by - obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f - rw [tailSet_act,Finset.card_image_of_injective _ p.injective] - change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ - rw [←Fintype.card_subtype] - exact tail_card μ - -noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := - Finset.univ.filter (fun f => tailSet f ⊆ A) - -lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by - obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst - have he : s.image p=t := by - ext x - constructor - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (hp y).mpr hy - · intro hx - exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ - apply Finset.card_equiv (tabloidAct p) - intro f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] - exact (Finset.image_inj p.injective).symm - -lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : - (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = - Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - let s := tailSet (baseTabloid μ) - let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card - have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := - tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) - have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by - have h := Finset.sum_card_fiberwise_eq_card_filter - (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet - have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by - ext f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, - card_tailSet,footprint] - simp [j] - rw [he] at h - rw [←h] - calc - _ = ∑ _t ∈ A.powersetCard j, c := by - apply Finset.sum_congr rfl - intro t ht - exact hconstant t (Finset.mem_powersetCard.mp ht).2 - _ = _ := by simp [Finset.card_powersetCard] - have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by - simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] - have hN := hcount Finset.univ - rw [hfull,Finset.card_univ,card_cell] at hN - rw [hcount,hN] - ring - -lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) - (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by - have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 - apply Subtype.ext - funext x - change f.1 (p⁻¹ x) = f.1 x - by_cases hx : x ∈ A - · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] - · have hy : p⁻¹ x ∉ A := by - intro h - have hh := hp (p⁻¹ x) h - have he : x=p⁻¹ x := by simpa using hh - exact hx (he ▸ h) - apply Fin.ext - have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) - have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) - exact hy0.trans hx0.symm - -noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where - carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), - (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} - zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ - add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by - rw [map_add,hv.2 p hp,hw.2 p hp]⟩ - smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by - rw [map_smul,hv.2 p hp]⟩ - -lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := - fun _ hv => hv.1 - -theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : - Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by - let : DecidableEq (Tabloid μ) := Classical.decEq _ - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : - (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by - refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ - rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), - PermutationHilbert.act_single,footprint_fixed A f hf p hp] - have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) - (fixedHilbert_le μ A) ht (footprint μ A) hproj - rw [finrank_hilbertSpace] at h - have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ - Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h - have hc := footprint_card_product μ A - have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ - have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn - nlinarith - -end Thorp.Specht - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -def IsUnitary (ρ : Representation ℂ G V) : Prop := - ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : - inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by - have h := hρ g v (ρ g⁻¹ w) - have he : ρ g (ρ g⁻¹ w) = w := by - change (ρ g * ρ g⁻¹) w = w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [he] at h - exact h.symm - -noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where - toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) - isIntertwining' h := by - ext v - simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] - have hh (w : W) : σ h (σ h⁻¹ w)=w := by - change (σ h*σ h⁻¹) w=w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [hh] - -end Thorp.UnitaryFinite - -end ThorpNine.SparseSaving - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.SparseSaving.ModifiedReverseEquiv + +namespace OAI + +namespace ThorpNine.SparseSaving + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where + toFun μ := { parts := μ.1.rowLens + parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } + invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ + left_inv μ := by + apply Subtype.ext + obtain ⟨μ,rfl⟩ := μ + exact partitionDiagram_diagramPartition μ + right_inv p := by + apply Nat.Partition.ext + change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts + rw [partitionDiagram_rowLens,Multiset.sort_eq] + +noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm + +noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : + ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := + Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) + +lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : + Function.Injective (conjugacyPartition (α := α)) := by + intro p q + induction p using Quotient.inductionOn with | _ p => + induction q using Quotient.inductionOn with | _ q => + intro h + exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) + +lemma card_conjugacy_le_shapes (N : ℕ) : + Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by + have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) + simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h + +noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := + (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) + +noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : + Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := + (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom + +lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : + Representation.IsIrreducible (labelledRepresentation μ) := by + let e := (labels μ).symm.permCongrHom + let ρ := representation μ.1 + have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ + (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial + exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) + refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } + intro U + let U' : Subrepresentation ρ := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun p v hv => by + have hh := U.apply_mem_toSubmodule (e.symm p) hv + change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh + simpa using hh } + have := representation_irreducible μ.1 + obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' + · left + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + · right + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + +lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) + (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by + apply Subtype.ext + apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv + intro p v + have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v + change T.toLinearEquiv + (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = + representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh + have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] at hh + convert hh using 2 + congr 1 + +end Thorp.Specht + +namespace Thorp.FiniteCharacters +open scoped BigOperators Classical + +section Group +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose +omit [Fintype G] in +lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := + (ConjClasses.exists_rep c).choose_spec + +variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := + fun c => ρ.character (classRep c) + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : + characterClass ρ (ConjClasses.mk g) = ρ.character g := by + have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) + obtain ⟨p,hp⟩ := isConj_iff.mp h + change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g + exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) + +noncomputable def characterDual (ρ : Representation ℂ G V) : + (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where + toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ + map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] + map_smul' a f := by + simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] + simp_rw [mul_assoc] + rw [←Finset.mul_sum] + ring + +lemma characterDual_characterClass (ρ : Representation ℂ G V) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : + characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by + exact_mod_cast (Nat.card_pos (α := G)).ne') + change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ + simp only [characterClass_mk] + exact Representation.char_orthonormal σ ρ + +end Group + +theorem complete_of_card_conjugacy_le + {G ι : Type*} [Group G] [Fintype G] [Fintype ι] + (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] + (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] + (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : + ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases hij : i=j + · subst j + simp only [ite_true] + exact ite_eq_left ⟨Representation.Equiv.refl _⟩ + · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij + exact (horth i j).trans (ite_eq_right hij) + · intro i + simpa using horth i i + have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + have hspan := hLI.span_eq_top_of_card_eq_finrank' heq + by_contra h + push Not at h + have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ + (characterDual σ).ker := by + apply Submodule.span_le.mpr + rintro f ⟨i,rfl⟩ + change characterDual σ (characterClass (ρ i)) = 0 + rw [characterDual_characterClass,ite_eq_right] + rintro ⟨T⟩ + exact (h i).false T.symm + rw [hspan] at hker + have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) + rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz + exact one_ne_zero hz + +end Thorp.FiniteCharacters + +namespace Thorp.Specht +open scoped Classical + +theorem labelled_complete {N : ℕ} + {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : + ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by + let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := + labelledRepresentation_irreducible μ + apply FiniteCharacters.complete_of_card_conjugacy_le + (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ + intro μ ν h ⟨T⟩ + exact h (labelledRepresentation_equiv_shapes μ ν T) + +end Thorp.Specht + +namespace Thorp.PermutationHilbert + +section +open scoped BigOperators ComplexConjugate Classical +open Complex + +variable {X : Type*} [Fintype X] + +noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p + +@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : + act p v x = v (p⁻¹ x) := rfl + +lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : + act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by + exact EuclideanSpace.piLpCongrLeft_single p x 1 + +lemma trace_projection (W : Submodule ℂ (H X)) : + ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by + classical + have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by + constructor + · intro x; exact (W.orthogonalProjectionOnto x).2 + · intro x hx; exact W.starProjection_eq_self_iff.mpr hx + have ht := hp.trace + rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht + simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, + EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, + OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht + +lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : + (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + classical + have hh := W.inner_starProjection_left_eq_right + (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) + have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := + W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 + rw [hf] at hh + rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh + simpa using hh.symm + +lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) + (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : + act p (W.starProjection v) = W.starProjection (act p v) := by + have hh := (act p).toLinearIsometry.map_starProjection W v + change act p (W.starProjection v) = + (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh + simpa only [hW] using hh + +lemma uniform_diagonal (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : + (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = + Module.finrank ℂ W := by + classical + have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + obtain ⟨p,hp,hW⟩ := htrans x y + subst y + rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] + have ht := trace_projection W + simp_rw [hh] at ht + have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = + (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht + simpa using hhreal + +theorem uncertainty (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (v : H X) (hv : v ∈ W) (x : X) : + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by + classical + have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by + rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, + EuclideanSpace.inner_single_left] + simp + have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v + rw [hh] at hc + have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by + nlinarith [norm_nonneg (v x),norm_nonneg v, + norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] + calc + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ + (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := + mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) + _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] + +end +open scoped BigOperators Classical + +variable {X : Type*} [Fintype X] + +lemma trace_projection_real (W : Submodule ℂ (H X)) : + ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by + have hh := trace_projection W + simp_rw [projection_diagonal] at hh + exact_mod_cast hh + +theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : + (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ + (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by + have he (x : X) (hx : x ∈ S) : + K.starProjection (EuclideanSpace.single x (1:ℂ)) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := by + apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) + intro v hv + exact W.starProjection_inner_eq_zero _ v (hKW hv) + have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ + (Module.finrank ℂ K:ℝ) := by + rw [←trace_projection_real K] + calc + _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by + apply Finset.sum_congr rfl + intro x hx + rw [he x hx] + _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) + have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) + rw [Finset.mul_sum] at hmul + simp_rw [uniform_diagonal W htrans] at hmul + simpa using hmul + +end Thorp.PermutationHilbert +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma finrank_hilbertSpace (μ : YoungDiagram) : + Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := + (hilbertEquiv μ).finrank_map_eq (space μ) + +lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : + hilbertEquiv μ (tabloidRep μ p v) = + PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by + ext f + simp [hilbertEquiv,PermutationHilbert.act_apply] + +lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = + hilbertSpace μ := by + apply le_antisymm + · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ + exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ + · rintro _ ⟨w,hw,rfl⟩ + refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), + ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ + change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w + rw [←hilbert_action] + change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ + rw [←map_mul,mul_inv_cancel,map_one] + rfl + +lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : + ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by + obtain ⟨q,hq⟩ := f.2 + obtain ⟨r,hr⟩ := g.2 + refine ⟨r⁻¹*q, ?_⟩ + apply Subtype.ext + funext x + simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, + Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] + +lemma polytabloid_pairing (μ : YoungDiagram) : + pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by + have h := alternator_pairing μ (polytabloid μ) + have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = + permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply (colGroup μ) (tabloidRep μ) c _ + have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, + Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb + simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb + exact hb.symm + +lemma polytabloid_norm_sq (μ : YoungDiagram) : + ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by + have hp := polytabloid_pairing μ + change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp + rw [inner_self_eq_norm_sq_to_K] at hp + have hre := congrArg Complex.re hp + simpa [pow_two] using hre + +theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : + Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht + (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) + have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ + rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu + exact_mod_cast hu + + +section FiberGroup +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +noncomputable def fiberGroupEquiv (f : α → β) : + fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where + toFun p b := + { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ + invFun x := ⟨p.1⁻¹ x.1, by + have hh := p.2 (p.1⁻¹ x.1) + simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh + exact hh.symm.trans x.2⟩ + left_inv x := by apply Subtype.ext; simp + right_inv x := by apply Subtype.ext; simp } + invFun q := + ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), + fun x => (q (f x) ⟨x,rfl⟩).2⟩ + left_inv p := by + apply Subtype.ext + apply Equiv.ext + intro x + rfl + right_inv q := by + funext b + apply Equiv.ext + intro x + apply Subtype.ext + change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 + cases x with + | mk x hx => dsimp only at *; subst b; rfl + +lemma nat_card_fiberGroup (f : α → β) : + Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by + rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] + simp only [Nat.card_eq_fintype_card,Fintype.card_perm] + +omit [Fintype β] [Fintype γ] in + +lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) + (hinj : ∀ x y, f x = f y → g x = g y → x=y) : + Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by + have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by + intro p q hpq + dsimp only at hpq + have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by + apply inv_mul_eq_iff_eq_mul.mpr + rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] + have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 + have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) + have h1 : p.1.1⁻¹*q.1.1 = 1 := by + apply Equiv.ext + intro x + exact hinj _ x (hf x) (hg x) + have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) + have hpg : p.2=q.2 := by + apply Subtype.ext + have hh := hpq + rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh + exact mul_left_cancel hh + exact Prod.ext hpf hpg + have hc := Fintype.card_le_of_injective _ hi + simpa only [Fintype.card_prod,Fintype.card_perm] using hc + +end FiberGroup + +noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := + fiberGroup (rowIndex (μ := μ)) + +noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := + ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ + +lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by + ext p + constructor + · intro hp x; exact Fin.ext (hp x) + · intro hp x; exact congrArg Fin.val (hp x) + +noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where + smul p f := tabloidAct p f + one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl + mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl + +lemma tabloid_orbit_all (μ : YoungDiagram) : + MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by + ext f + simp only [Set.mem_univ,iff_true] + obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f + exact ⟨p,hp⟩ + +lemma tabloid_stabilizer (μ : YoungDiagram) : + MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by + ext p + change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x + constructor + · intro h x + have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h + simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + · intro h + apply Subtype.ext + funext x + exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) + +lemma card_tabloid_mul_row (μ : YoungDiagram) : + Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by + have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group + (Equiv.Perm (Cell μ)) (baseTabloid μ) + have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = + Fintype.card (Tabloid μ) := by + rw [tabloid_orbit_all,Fintype.card_setUniv] + simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh + +theorem factorial_le_dimension_row_column (μ : YoungDiagram) : + μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by + rw [←card_tabloid_mul_row] + nlinarith [dimension_times_column_ge_tabloids μ] + + +lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by + let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] + +lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by + let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + +lemma card_rowGroup (μ : YoungDiagram) : + Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by + rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_row_fiber] + +lemma card_colGroup (μ : YoungDiagram) : + Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by + rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card,card_col_fiber] + +abbrev Tail (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} + +lemma tail_card (μ : YoungDiagram) : Fintype.card (Tail μ) = μ.card - μ.rowLen 0 := by + have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) + rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh + exact hh + +lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by + have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) + rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h + +noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + {x : Tail μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where + toFun x := ⟨row x.1.1-1, by + have hx := row_lt_colLen x.1.1 + have hc : col x.1.1 = j := congrArg Fin.val x.2 + rw [hc] at hx + have hz := x.1.2 + omega⟩ + invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ + left_inv x := by + apply Subtype.ext + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · change row x.1.1 - 1 + 1 = row x.1.1 + have := x.1.2 + omega + · exact (congrArg Fin.val x.2).symm + right_inv i := by apply Fin.ext; simp [row] + +lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : Tail μ // colIndex x.1 = j} = μ.colLen j-1 := by + rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] + +lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : Tail μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by + by_cases hi : i.val=0 + · rw [ite_eq_left hi] + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun x => x.1.2 ?_⟩ + exact (congrArg Fin.val x.2).trans hi + · rw [ite_eq_right hi] + let e : {x : Tail μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := + { toFun := fun x => ⟨x.1.1,x.2⟩ + invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ + left_inv := fun x => rfl + right_inv := fun x => rfl } + rw [Fintype.card_congr e,card_row_fiber] + +lemma tail_row_group (μ : YoungDiagram) : + (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) = + Fintype.card (rowGroup μ) := by + rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_row] + by_cases hn : μ.colLen 0=0 + · have hr : μ.rowLen 0=0 := by + by_contra h + have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) + have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem + omega + let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ + simp [hr] + · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ + have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] + simp only [hz] + have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = + ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by + rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] + simp only [ite_true,Nat.factorial_zero,mul_one] + apply Finset.prod_congr rfl + intro x hx + rw [ite_eq_right (Finset.mem_erase.mp hx).1] + rw [hprod] + exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) + +lemma sum_tail_columns (μ : YoungDiagram) : + ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by + simp_rw [←card_tail_col] + rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : Tail μ => colIndex x.1)),tail_card] + +lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := + YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) + +lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num + | succ n ih => rw [pow_succ]; omega + +lemma column_group_le_tail (μ : YoungDiagram) : + Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * + Fintype.card (fiberGroup (fun x : Tail μ => colIndex x.1)) := by + rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : Tail μ => colIndex x.1)),nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_col] + calc + _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by + apply Finset.prod_congr rfl + intro j hj + exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm + _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by + apply Finset.prod_le_prod + intro j hj + exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) + _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] + +theorem choose_tail_le_dimension (μ : YoungDiagram) : + μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + have htail := card_fiberGroups_mul_le + (fun x : Tail μ => rowIndex x.1) (fun x : Tail μ => colIndex x.1) + (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) + rw [tail_card] at htail + have hc := column_group_le_tail μ + have hr := tail_row_group μ + have hd := factorial_le_dimension_row_column μ + simp only [←Nat.card_eq_fintype_card] at htail hc hr hd + have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * + ((μ.rowLen 0).factorial * j.factorial) := by + calc + _ ≤ _ := hd + _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * + (2^j * Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc + _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * + (Nat.card (fiberGroup (fun x : Tail μ => rowIndex x.1)) * + Nat.card (fiberGroup (fun x : Tail μ => colIndex x.1))) := by rw [←hr]; ring + _ ≤ _ := by + calc + _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := + Nat.mul_le_mul_left _ htail + _ = _ := by ring + have hj : j ≤ μ.card := Nat.sub_le _ _ + have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega + have hf := Nat.choose_mul_factorial_mul_factorial hj + rw [hs] at hf + rw [←hf] at hh + have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) + nlinarith + + +lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : + ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by + let e : s ≃ t := Finset.equivOfCardEq hc + let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by + simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) + let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) + refine ⟨p,fun x => ?_⟩ + by_cases hx : x ∈ s + · have hp : p x ∈ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t + rw [Equiv.sumCompl_symm_apply_of_pos hx] + exact (e ⟨x,hx⟩).2 + exact iff_of_true hp hx + · have hp : p x ∉ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t + rw [Equiv.sumCompl_symm_apply_of_neg hx] + exact (ec ⟨x,hx⟩).2 + exact iff_of_false hp hx + +noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := + Finset.univ.filter (fun x => (f.1 x).val ≠ 0) + +@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : + x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] + +lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tailSet (tabloidAct p f) = (tailSet f).image p := by + ext x + simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] + constructor + · intro h; exact ⟨p⁻¹ x,h,by simp⟩ + · rintro ⟨y,hy,rfl⟩; simpa using hy + +lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : + (tailSet f).card = μ.card-μ.rowLen 0 := by + obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f + rw [tailSet_act,Finset.card_image_of_injective _ p.injective] + change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ + rw [←Fintype.card_subtype] + exact tail_card μ + +noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := + Finset.univ.filter (fun f => tailSet f ⊆ A) + +lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by + obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst + have he : s.image p=t := by + ext x + constructor + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (hp y).mpr hy + · intro hx + exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ + apply Finset.card_equiv (tabloidAct p) + intro f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] + exact (Finset.image_inj p.injective).symm + +lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : + (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = + Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + let s := tailSet (baseTabloid μ) + let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card + have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := + tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) + have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by + have h := Finset.sum_card_fiberwise_eq_card_filter + (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet + have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by + ext f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, + card_tailSet,footprint] + simp [j] + rw [he] at h + rw [←h] + calc + _ = ∑ _t ∈ A.powersetCard j, c := by + apply Finset.sum_congr rfl + intro t ht + exact hconstant t (Finset.mem_powersetCard.mp ht).2 + _ = _ := by simp [Finset.card_powersetCard] + have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by + simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] + have hN := hcount Finset.univ + rw [hfull,Finset.card_univ,card_cell] at hN + rw [hcount,hN] + ring + +lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) + (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by + have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 + apply Subtype.ext + funext x + change f.1 (p⁻¹ x) = f.1 x + by_cases hx : x ∈ A + · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] + · have hy : p⁻¹ x ∉ A := by + intro h + have hh := hp (p⁻¹ x) h + have he : x=p⁻¹ x := by simpa using hh + exact hx (he ▸ h) + apply Fin.ext + have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) + have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) + exact hy0.trans hx0.symm + +noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where + carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), + (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} + zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ + add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by + rw [map_add,hv.2 p hp,hw.2 p hp]⟩ + smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by + rw [map_smul,hv.2 p hp]⟩ + +lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := + fun _ hv => hv.1 + +theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : + Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by + let : DecidableEq (Tabloid μ) := Classical.decEq _ + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : + (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by + refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ + rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), + PermutationHilbert.act_single,footprint_fixed A f hf p hp] + have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) + (fixedHilbert_le μ A) ht (footprint μ A) hproj + rw [finrank_hilbertSpace] at h + have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ + Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h + have hc := footprint_card_product μ A + have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ + have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn + nlinarith + +end Thorp.Specht + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +def IsUnitary (ρ : Representation ℂ G V) : Prop := + ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : + inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by + have h := hρ g v (ρ g⁻¹ w) + have he : ρ g (ρ g⁻¹ w) = w := by + change (ρ g * ρ g⁻¹) w = w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [he] at h + exact h.symm + +noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where + toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) + isIntertwining' h := by + ext v + simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] + have hh (w : W) : σ h (σ h⁻¹ w)=w := by + change (σ h*σ h⁻¹) w=w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [hh] + +end Thorp.UnitaryFinite + +end ThorpNine.SparseSaving + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/AlternatingPerm.lean b/lean/OAI/Probability/ThorpRouting/Tail/AlternatingPerm.lean index bf8fa9db14025f4415850faedc05e1562f138c5f..b9baf5d656b154f43fe629b27a642feeef80f6e4 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/AlternatingPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/AlternatingPerm.lean @@ -1,895 +1,895 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ParallelFollow - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] -omit [Fintype α] in -lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Function.Injective (bipartitionFlip p S χ hχ) := by - classical - intro f g he - apply Subtype.ext - funext x - by_cases hx : x ∈ S - · have hh := congrFun (congrArg Subtype.val he) x - change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = - (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh - simp only [ite_eq_left hx] at hh - cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all - · exact (f.property.1 x hx).trans (g.property.1 x hx).symm - -lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : - Fintype.card (OppositeColoring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans - (card_coloring_le p S) - -def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := if x.1 then (false,p x.2) else (true,x.2) - invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) - left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp - -omit [Fintype α] [DecidableEq α] in -lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p x).1 = !x.1 := by - rcases x with ⟨b,x⟩ - cases b <;> rfl - -omit [Fintype α] [DecidableEq α] in -lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : - p.SameCycle x.2 (alternatingPerm p x).2 := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl p x - · exact (Equiv.Perm.SameCycle.refl p x).apply_right - -omit [DecidableEq α] in -lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} - (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl p x.2 - | succ k ih => - rw [pow_succ',Equiv.Perm.mul_apply] - exact ih.trans (alternating_step_sameCycle p _) - exact hn ▸ hp n - -omit [DecidableEq α] in -lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} - (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by - induction k with - | zero => exact Equiv.Perm.SameCycle.refl _ _ - | succ k ih => - have hs := ih.apply_right.apply_right - simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, - Bool.false_eq_true,↓reduceIte] using hs - simpa only [hn] using hp n - -omit [Fintype α] [DecidableEq α] in -lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : - (alternatingPerm p).SameCycle x (false,x.2) := by - rcases x with ⟨b,x⟩ - cases b - · exact Equiv.Perm.SameCycle.refl _ _ - · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm - -omit [DecidableEq α] in -lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : - (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by - constructor - · exact alternating_sameCycle_snd p - · intro h - exact (alternating_sameCycle_zero p x).trans - ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) - -lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : - orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by - ext ⟨b,y⟩ - simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] - -omit [Fintype α] in -lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : - boolFiber (childJoin A B) b = if b then B else A := by - ext x - cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] - -noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - RoutingNetwork.SelectedCycle p A := by - refine ⟨boolFiber C.val false,?_,?_⟩ - · obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x.2,?_⟩ - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - · intro x hx - exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) - -lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : - C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by - change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) - obtain ⟨x,hx⟩ := C.property.1 - rw [hx,orbit_alternating,boolFiber_childJoin] - rfl - -lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : - Function.Injective (projectCycle p A B) := by - intro C D he - apply Subtype.ext - rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] - -lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ - Fintype.card (RoutingNetwork.SelectedCycle p A) := - Fintype.card_le_of_injective _ (projectCycle_injective p A B) - -end CycleColoring - -section PairAssignmentCount -variable {α : Type*} [Fintype α] [DecidableEq α] - -omit [Fintype α] in -lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : - y ∈ A.image p ↔ p.symm y ∈ A := by - constructor - · intro h - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ - -omit [Fintype α] in -lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := - fun _ _ h => congrArg Prod.snd h - rw [childJoin,Finset.card_union_of_disjoint hd, - Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] - -omit [Fintype α] in -lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : - ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = - childJoin (A ∩ B.image p) (B ∩ A) := by - ext ⟨b,x⟩ - rw [Finset.mem_filter] - cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, - Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] - -omit [Fintype α] in -lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : - (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = - (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by - rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] - have h₀ := Finset.card_union_add_card_inter A B - have h₁ := Finset.card_union_add_card_inter A (B.image p) - rw [Finset.card_image_of_injective _ p.injective] at h₁ - have h₂ := Finset.inter_comm B A - rw [h₂] - omega - -lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : - Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ - 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + - Fintype.card (RoutingNetwork.SelectedCycle p A)) := by - have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) - Prod.fst (CycleColoring.alternatingPerm_flip p) - rw [alternating_boundary_card] at h - exact h.trans (Nat.pow_le_pow_right (by norm_num) - (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) - -end PairAssignmentCount - -lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : - boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by - classical - ext x - rw [mem_boolFiber,mem_childMarks] - constructor - · intro h - obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h - have hh := congrArg (headTailEquiv d).symm he - rw [Equiv.symm_apply_apply] at hh - change y = Fin.cons b x at hh - exact hh ▸ hy - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ - -lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : - (∏ x ∈ S, f x) = - (∏ x ∈ childMarks S false, f (Fin.cons false x)) * - ∏ x ∈ childMarks S true, f (Fin.cons true x) := by - classical - have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) - rw [Finset.prod_image (headTailEquiv d).injective.injOn, - boolFiber_headTail,boolFiber_headTail] at h - simp only [Equiv.symm_apply_apply] at h - exact h - -noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := - (p (Fin.cons false y)+p (Fin.cons true y))/2 - -lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : - finiteMean (headAverage p) = finiteMean p := by - rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] - apply finiteMean_congr - intro y - rw [finiteMean_bool] - rfl - -lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) - (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ - ∏ x ∈ S, headAverage p (Fin.tail x) := by - classical - have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) - (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl - have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) - simp only [Finset.prod_image (pairLayer _).injective.injOn, - Finset.prod_image (headTailEquiv d).injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rfl - · apply Finset.prod_congr rfl - intro x _ - change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = - (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 - cases x 0 - · rfl - · simp only [Bool.not_true] - ring - -lemma butterflyPerm_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : - butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = - pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by - change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * - childLift (fun b => butterflyPerm d (decodeButterfly d - (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ - apply congrArg₂ (· * ·) - · rfl - · apply congrArg childLift - funext b - apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) - funext i - cases b <;> rfl - -lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) - (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by - classical - induction d with - | zero => - have he : p = fun _ => p (fun i => Fin.elim0 i) := by - funext x - exact congrArg p (Subsingleton.elim _ _) - rw [he] - simp only [Finset.prod_const,finiteMean_const,le_refl] - | succ d ih => - let g : Card d → ℝ := headAverage p - have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) - rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] - calc - _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by - apply finiteMean_mono - intro c - let f : Equiv.Perm (Card (d+1)) := childLift (fun b => - butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) - have hh := pairSwitch_product_bound d (S.image f) p hp - simp only [Finset.prod_image f.injective.injOn] at hh - convert hh using 1 - · apply finiteMean_congr - intro ξ - apply Finset.prod_congr rfl - intro x _ - rw [butterflyPerm_step] - rfl - · rw [prod_childMarks] - simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - Bool.false_eq_true,↓reduceIte] - rfl - _ = (finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * - finiteMean (fun c : SwitchIndex d → Bool => - ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := - finiteMean_prod_mul - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, - g (butterflyPerm d (decodeButterfly d c) x)) - (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, - g (butterflyPerm d (decodeButterfly d c) x)) - _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := - mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) - (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) - (pow_nonneg (finiteMean_nonneg hg) _) - _ = (finiteMean p)^S.card := by - rw [←pow_add,card_childMarks_add,finiteMean_headAverage] - -noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)).symm - -lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (inverseButterflyMarks d A) S ≤ - ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - classical - let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 - have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by - simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - simp - have he : inclusionMoment (inverseButterflyMarks d A) S = - finiteMean (fun ω : SwitchIndex d → Bool => - ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by - rw [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, - Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] - rw [he] - simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def occupied (x : ι → Bool × α) : Finset α := - Finset.univ.image (fun i => (x i).2) - -omit [Fintype α] in -lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by - simp [occupied] - -def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) - -def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j - -def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := - Bool.xor (x i).1 (ξ (x i).2) - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : - required x (colors x ξ) i = ξ (x i).2 := by - simp only [required,colors] - cases (x i).1 <;> cases ξ (x i).2 <;> rfl - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by - intro i j he - simp only [required_colors,he] - -noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by - classical - exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false - -omit [Fintype α] in -lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - chosenCoin x c (x i).2 = required x c i := by - classical - simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] - exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) - -omit [Fintype α] in -lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : - colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by - constructor - · intro he y hy - obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy - rw [chosenCoin_apply x c hc i] - rw [←he,required_colors] - · intro he - funext i - apply (xor_eq_iff _ _ _).mpr - exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) - -noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := - Classical.propDecidable _ - -lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = - if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by - classical - by_cases hc : Compatible x c - · rw [ite_eq_left hc] - have he := fun ξ => colors_eq_iff x c hc ξ - simp only [he] - exact mean_coinCylinder (occupied x) (chosenCoin x c) - · rw [ite_eq_right hc] - have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) - simp only [he,ite_false,finiteMean_const] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : - Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by - intro i j he - apply Subtype.ext - apply x.injective - apply Prod.ext - · have hh := hc i j he - simp only [required,i.property,j.property] at hh - cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all - · exact he - -def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ - - -def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where - toFun x := (x.1,p x.1 x.2) - invFun x := (x.1,(p x.1).symm x.2) - left_inv x := by simp - right_inv x := by simp - -def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := - pairLayer η * lift p * pairLayer ξ - -def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := - ∀ i, p (c i) (x i).2 = (y i).2 - -noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - Decidable (ChildMatches p x y c) := Classical.propDecidable _ - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - (∀ i, sandwich ξ η p (x i) = y i) ↔ - colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by - have he (i : ι) : sandwich ξ η p (x i) = y i ↔ - colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by - change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ - rw [←Equiv.eq_symm_apply] - change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ - exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ - simp only [he,forall_and,←funext_iff,ChildMatches] - -lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (if ChildMatches p x y c then 1 else 0) := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const] - rw [finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ - (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ - (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by - constructor - · intro h - constructor - · intro i - simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val - · intro i - simpa only [i.property,↓reduceIte] using h i.val - · rintro ⟨h₀,h₁⟩ i - cases hi : c i - · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ - · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ - -omit [Fintype α] in -lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : - finiteMean (fun ω : Ω × Ω' => - if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) := by - classical - let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 - let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 - have he (ω : Ω × Ω') : - (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by - simp only [childMatches_split,f,g] - split_ifs <;> simp_all - simp_rw [he] - exact finiteMean_prod_mul f g - -lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : - finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)) = - ∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2)) := by - classical - simp_rw [sandwich_probability] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro c _ - simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, - childMatches_mean] - - -abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := - {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} - -noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype (BothAssignments e p) := Fintype.ofFinite _ - -noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e - -def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true - -noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (c : BothAssignments e p) : CycleColoring.OppositeColoring - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by - classical - refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ - · intro z hz - apply Function.extend_apply' - rintro ⟨i,rfl⟩ - exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - · intro z hz hnext - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext - have hfi := e.injective.extend_apply c.val (fun _ => false) i - have hfj := e.injective.extend_apply c.val (fun _ => false) j - rw [hi] at hfi - rw [hj] at hfj - rw [hfi,hfj] - rcases z with ⟨b,a⟩ - cases b - · have hj' : e j = (true,a) := hj - have ht : (e i).2 = (e j).2 := by rw [hi,hj'] - have hh := c.property.1 i j ht - simp only [required,hi,hj'] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - · have hj' : e j = (false,alternatingProjection p a) := hj - have ht : (lift p (e i)).2 = (lift p (e j)).2 := by - simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, - Function.comp_apply,Equiv.apply_symm_apply] - have hh := c.property.2 i j ht - simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh - revert hh - generalize c.val i = bi - generalize c.val j = bj - cases bi <;> cases bj <;> decide - -omit [Fintype α] in -lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Function.Injective (assignmentColoring e p) := by - intro c c' he - apply Subtype.ext - funext i - have hh := congrFun (congrArg Subtype.val he) (e i) - change Function.extend e c.val (fun _ => false) (e i) = - Function.extend e c'.val (fun _ => false) (e i) at hh - simpa only [e.injective.extend_apply] using hh - -lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image - (alternatingProjection p)).card - - ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have h := compatible_assignment_bound (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -omit [Fintype α] in -lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by - classical - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - -omit [Fintype ι] [Fintype α] in -lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] - -omit [Fintype ι] [Fintype α] in -lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : - (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by - classical - simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] - -omit [Fintype α] in -lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - (occupied (fun i => lift p (e i))).card = - (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by - classical - have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by - simp only [occupied,labelSet,Finset.image_image,Function.comp_def] - rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - let A := boolFiber (labelSet e) false - let B := boolFiber (labelSet e) true - change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card - have hh : A.image (p false) ∪ B.image (p true) = - (A ∪ B.image (alternatingProjection p)).image (p false) := by - simp only [Finset.image_union,Finset.image_image,Function.comp_def, - alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] - rw [hh,Finset.card_image_of_injective _ (p false).injective] - -lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by - have he : (occupied e).card = - (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, - Finset.card_univ] - simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p - -omit [Fintype ι] [Fintype α] [DecidableEq α] in -lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : - Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by - have he (i j : ι) (ht : (x i).2 = (x j).2) : - required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ - required x c i = required x c j := by - simp only [required,pairLayer,Equiv.coe_fn_mk,ht] - cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide - constructor - · intro h i j ht - exact (he i j ht).mp (h i j ht) - · intro h i j ht - exact (he i j ht).mpr (h i j ht) - - -noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := - Fintype.card (RoutingNetwork.SelectedCycle - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) - -omit [Fintype α] in -lemma occupied_eq_fibers (e : ι ↪ Bool × α) : - occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by - rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] - simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] - -omit [Fintype α] in -lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by - classical - exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) - -omit [Fintype α] in -lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by - have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_left - have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by - rw [occupied_eq_fibers] - exact Finset.card_le_card Finset.subset_union_right - have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by - rw [←card_childJoin,childJoin_boolFiber,card_labelSet] - omega - -lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - Fintype.card (BothAssignments e p) ≤ - 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + - alternatingCycles e p) := by - have h := CycleColoring.card_opposite_le - (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) - Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) - have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) - (labelSet e)).card = - (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by - have hh := alternating_boundary_card (alternatingProjection p) - (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber] at hh - rw [occupied_eq_fibers,occupied_lift_card] - have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) - rw [childJoin_boolFiber,card_labelSet] at he - simpa only [he] using hh - rw [hb] at h - exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h - -abbrev Assignments (x y : ι → Bool × α) := - {c : ι → Bool // Compatible x c ∧ Compatible y c} - -noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ - -def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := - e.trans (pairLayer ξ).toEmbedding - -def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding - -omit [Fintype α] in -lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : - occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl - -noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by - apply Equiv.subtypeEquivRight - intro c - change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ - rw [compatible_pairLayer_iff] - exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl - -lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : - Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ - 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + - alternatingCycles (switchedEmbedding e ξ) p) := by - rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] - exact bothAssignments_exact_bound (switchedEmbedding e ξ) p - -omit [Fintype α] in -lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) - (p : Bool → Equiv.Perm α) : - Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by - have h₀ := occupied_card_double e - have h₁ := occupied_card_double (routedEmbedding e ξ η p) - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by - classical - exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) - -omit [Fintype α] [DecidableEq α] in -lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : - c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by - classical - simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] - -omit [Fintype α] [DecidableEq α] in -lemma card_compatibleSet (x y : ι → Bool × α) : - (compatibleSet x y).card = Fintype.card (Assignments x y) := by - classical - exact (Fintype.card_subtype _).symm - -noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := - 1/(2:ℝ)^((occupied x).card+(occupied y).card) - -omit [Fintype α] [DecidableEq ι] in -lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by - unfold outerWeight - positivity - -omit [Fintype α] in -lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : - (∑ c : ι → Bool, - (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * - (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = - outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by - classical - rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro c _ - by_cases hx : Compatible x c <;> by_cases hy : Compatible y c - · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] - · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] - -lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by - classical - have he (coins : (α → Bool) × (α → Bool)) : - (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * - (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by - rw [Finset.sum_eq_single (colors x coins.1)] - · by_cases hc : colors x coins.1 = colors y coins.2 - · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] - · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] - · intro c _ hc - simp only [Ne.symm hc,ite_false,zero_mul] - · simp - simp_rw [he] - rw [finiteMean_sum,←sum_colors_factor] - apply Finset.sum_congr rfl - intro c _ - rw [finiteMean_mul_const,finiteMean_prod_mul - (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) - (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), - colors_probability,colors_probability] - -omit [Fintype α] [DecidableEq ι] in -lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by - classical - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) - (a : ℝ) (ha : 0 ≤ a) : - (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i - then (1:ℝ) else 0)))^(1+a) ≤ - (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * - ∑ c ∈ compatibleSet x y, - (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by - classical - rw [sandwich_mean,sum_colors_factor] - let f (c : ι → Bool) : ℝ := - tupleProbability P (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2) * - tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2) - have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) - (tupleProbability_nonneg _ _ _) - rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] - have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) - (show 1 ≤ 1+a by linarith) (fun c _ => hf c) - have he : 1+a-1=a := by ring - rw [he] at hh - calc - _ ≤ (outerWeight x y)^(1+a) * - (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := - mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) - _ = _ := by - rw [←mul_assoc] - congr 1 - apply Finset.sum_congr rfl - intro c _ - exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) - -end PairRouting - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ParallelFollow + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] +omit [Fintype α] in +lemma bipartitionFlip_injective (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Function.Injective (bipartitionFlip p S χ hχ) := by + classical + intro f g he + apply Subtype.ext + funext x + by_cases hx : x ∈ S + · have hh := congrFun (congrArg Subtype.val he) x + change (if x ∈ S then Bool.xor (f.val x) (χ x) else false) = + (if x ∈ S then Bool.xor (g.val x) (χ x) else false) at hh + simp only [ite_eq_left hx] at hh + cases hfx : f.val x <;> cases hgx : g.val x <;> cases hcx : χ x <;> simp_all + · exact (f.property.1 x hx).trans (g.property.1 x hx).symm + +lemma card_opposite_le (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) : + Fintype.card (OppositeColoring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + exact (Fintype.card_le_of_injective _ (bipartitionFlip_injective p S χ hχ)).trans + (card_coloring_le p S) + +def alternatingPerm (p : Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := if x.1 then (false,p x.2) else (true,x.2) + invFun x := if x.1 then (false,x.2) else (true,p.symm x.2) + left_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + right_inv x := by rcases x with ⟨b,x⟩; cases b <;> simp + +omit [Fintype α] [DecidableEq α] in +lemma alternatingPerm_flip (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p x).1 = !x.1 := by + rcases x with ⟨b,x⟩ + cases b <;> rfl + +omit [Fintype α] [DecidableEq α] in +lemma alternating_step_sameCycle (p : Equiv.Perm α) (x : Bool × α) : + p.SameCycle x.2 (alternatingPerm p x).2 := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl p x + · exact (Equiv.Perm.SameCycle.refl p x).apply_right + +omit [DecidableEq α] in +lemma alternating_sameCycle_snd (p : Equiv.Perm α) {x y : Bool × α} + (h : (alternatingPerm p).SameCycle x y) : p.SameCycle x.2 y.2 := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : p.SameCycle x.2 (((alternatingPerm p)^k) x).2 := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl p x.2 + | succ k ih => + rw [pow_succ',Equiv.Perm.mul_apply] + exact ih.trans (alternating_step_sameCycle p _) + exact hn ▸ hp n + +omit [DecidableEq α] in +lemma alternating_zero_sameCycle (p : Equiv.Perm α) {x y : α} + (h : p.SameCycle x y) : (alternatingPerm p).SameCycle (false,x) (false,y) := by + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + have hp (k : ℕ) : (alternatingPerm p).SameCycle (false,x) (false,(p^k) x) := by + induction k with + | zero => exact Equiv.Perm.SameCycle.refl _ _ + | succ k ih => + have hs := ih.apply_right.apply_right + simpa only [pow_succ',Equiv.Perm.mul_apply,alternatingPerm,Equiv.coe_fn_mk, + Bool.false_eq_true,↓reduceIte] using hs + simpa only [hn] using hp n + +omit [Fintype α] [DecidableEq α] in +lemma alternating_sameCycle_zero (p : Equiv.Perm α) (x : Bool × α) : + (alternatingPerm p).SameCycle x (false,x.2) := by + rcases x with ⟨b,x⟩ + cases b + · exact Equiv.Perm.SameCycle.refl _ _ + · exact ((Equiv.Perm.SameCycle.refl (alternatingPerm p) (false,x)).apply_right).symm + +omit [DecidableEq α] in +lemma alternating_sameCycle_iff (p : Equiv.Perm α) (x y : Bool × α) : + (alternatingPerm p).SameCycle x y ↔ p.SameCycle x.2 y.2 := by + constructor + · exact alternating_sameCycle_snd p + · intro h + exact (alternating_sameCycle_zero p x).trans + ((alternating_zero_sameCycle p h).trans (alternating_sameCycle_zero p y).symm) + +lemma orbit_alternating (p : Equiv.Perm α) (x : Bool × α) : + orbitSet (alternatingPerm p) x = childJoin (orbitSet p x.2) (orbitSet p x.2) := by + ext ⟨b,y⟩ + simp only [mem_orbitSet,alternating_sameCycle_iff,mem_childJoin,ite_self] + +omit [Fintype α] in +lemma boolFiber_childJoin (A B : Finset α) (b : Bool) : + boolFiber (childJoin A B) b = if b then B else A := by + ext x + cases b <;> simp only [mem_boolFiber,mem_childJoin,Bool.false_eq_true,↓reduceIte] + +noncomputable def projectCycle (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + RoutingNetwork.SelectedCycle p A := by + refine ⟨boolFiber C.val false,?_,?_⟩ + · obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x.2,?_⟩ + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + · intro x hx + exact (mem_childJoin A B false x).mp (C.property.2 ((mem_boolFiber _ _ _).mp hx)) + +lemma selected_alternating_eq (p : Equiv.Perm α) (A B : Finset α) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) : + C.val = childJoin (projectCycle p A B C).val (projectCycle p A B C).val := by + change C.val = childJoin (boolFiber C.val false) (boolFiber C.val false) + obtain ⟨x,hx⟩ := C.property.1 + rw [hx,orbit_alternating,boolFiber_childJoin] + rfl + +lemma projectCycle_injective (p : Equiv.Perm α) (A B : Finset α) : + Function.Injective (projectCycle p A B) := by + intro C D he + apply Subtype.ext + rw [selected_alternating_eq p A B C,selected_alternating_eq p A B D,he] + +lemma card_alternating_cycles_le (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) (childJoin A B)) ≤ + Fintype.card (RoutingNetwork.SelectedCycle p A) := + Fintype.card_le_of_injective _ (projectCycle_injective p A B) + +end CycleColoring + +section PairAssignmentCount +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [Fintype α] in +lemma mem_image_perm_iff (p : Equiv.Perm α) (A : Finset α) (y : α) : + y ∈ A.image p ↔ p.symm y ∈ A := by + constructor + · intro h + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨p.symm y,h,p.apply_symm_apply y⟩ + +omit [Fintype α] in +lemma card_childJoin (A B : Finset α) : (childJoin A B).card = A.card+B.card := by + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + have hi (b : Bool) : Function.Injective (fun x : α => (b,x)) := + fun _ _ h => congrArg Prod.snd h + rw [childJoin,Finset.card_union_of_disjoint hd, + Finset.card_image_of_injective A (hi false),Finset.card_image_of_injective B (hi true)] + +omit [Fintype α] in +lemma alternating_internal (p : Equiv.Perm α) (A B : Finset α) : + ((childJoin A B).filter (fun x => (CycleColoring.alternatingPerm p).symm x ∈ childJoin A B)) = + childJoin (A ∩ B.image p) (B ∩ A) := by + ext ⟨b,x⟩ + rw [Finset.mem_filter] + cases b <;> simp only [mem_childJoin,CycleColoring.alternatingPerm, + Equiv.symm_mk,Equiv.coe_fn_mk,Bool.false_eq_true,↓reduceIte,Finset.mem_inter,mem_image_perm_iff] + +omit [Fintype α] in +lemma alternating_boundary_card (p : Equiv.Perm α) (A B : Finset α) : + (CycleColoring.boundary (CycleColoring.alternatingPerm p) (childJoin A B)).card = + (A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) := by + rw [CycleColoring.boundary_card,alternating_internal,card_childJoin,card_childJoin] + have h₀ := Finset.card_union_add_card_inter A B + have h₁ := Finset.card_union_add_card_inter A (B.image p) + rw [Finset.card_image_of_injective _ p.injective] at h₁ + have h₂ := Finset.inter_comm B A + rw [h₂] + omega + +lemma compatible_assignment_bound (p : Equiv.Perm α) (A B : Finset α) : + Fintype.card (CycleColoring.OppositeColoring (CycleColoring.alternatingPerm p) (childJoin A B)) ≤ + 2 ^ ((A ∪ B).card + (A ∪ B.image p).card - (A.card+B.card) + + Fintype.card (RoutingNetwork.SelectedCycle p A)) := by + have h := CycleColoring.card_opposite_le (CycleColoring.alternatingPerm p) (childJoin A B) + Prod.fst (CycleColoring.alternatingPerm_flip p) + rw [alternating_boundary_card] at h + exact h.trans (Nat.pow_le_pow_right (by norm_num) + (Nat.add_le_add_left (CycleColoring.card_alternating_cycles_le p A B) _)) + +end PairAssignmentCount + +lemma finiteMean_nonneg {Ω : Type*} [Fintype Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteMean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma boolFiber_headTail (d : ℕ) (S : Finset (Card (d+1))) (b : Bool) : + boolFiber (S.image (headTailEquiv d)) b = childMarks S b := by + classical + ext x + rw [mem_boolFiber,mem_childMarks] + constructor + · intro h + obtain ⟨y,hy,he⟩ := Finset.mem_image.mp h + have hh := congrArg (headTailEquiv d).symm he + rw [Equiv.symm_apply_apply] at hh + change y = Fin.cons b x at hh + exact hh ▸ hy + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons b x,h,by rfl⟩ + +lemma prod_childMarks (d : ℕ) (S : Finset (Card (d+1))) (f : Card (d+1) → ℝ) : + (∏ x ∈ S, f x) = + (∏ x ∈ childMarks S false, f (Fin.cons false x)) * + ∏ x ∈ childMarks S true, f (Fin.cons true x) := by + classical + have h := prod_boolFibers (S.image (headTailEquiv d)) (fun x => f ((headTailEquiv d).symm x)) + rw [Finset.prod_image (headTailEquiv d).injective.injOn, + boolFiber_headTail,boolFiber_headTail] at h + simp only [Equiv.symm_apply_apply] at h + exact h + +noncomputable def headAverage {d : ℕ} (p : Card (d+1) → ℝ) (y : Card d) : ℝ := + (p (Fin.cons false y)+p (Fin.cons true y))/2 + +lemma finiteMean_headAverage (d : ℕ) (p : Card (d+1) → ℝ) : + finiteMean (headAverage p) = finiteMean p := by + rw [finiteMean_equiv (headTailEquiv d),finiteMean_prod,finiteMean_comm] + apply finiteMean_congr + intro y + rw [finiteMean_bool] + rfl + +lemma pairSwitch_product_bound (d : ℕ) (S : Finset (Card (d+1))) + (p : Card (d+1) → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ξ : Card d → Bool => ∏ x ∈ S, p (pairSwitch ξ x)) ≤ + ∏ x ∈ S, headAverage p (Fin.tail x) := by + classical + have h : CylinderBound (fun T => ∏ x ∈ T, p ((headTailEquiv d).symm x)) + (fun x => p ((headTailEquiv d).symm x)) := fun _ => le_rfl + have hh := h.fair_parallel (fun x => hp _) (S.image (headTailEquiv d)) + simp only [Finset.prod_image (pairLayer _).injective.injOn, + Finset.prod_image (headTailEquiv d).injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rfl + · apply Finset.prod_congr rfl + intro x _ + change (p (Fin.cons false (Fin.tail x))+p (Fin.cons true (Fin.tail x)))/2 = + (p (Fin.cons (x 0) (Fin.tail x))+p (Fin.cons (!(x 0)) (Fin.tail x)))/2 + cases x 0 + · rfl + · simp only [Bool.not_true] + ring + +lemma butterflyPerm_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) : + butterflyPerm (d+1) (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ))) = + pairSwitch ξ * childLift (fun b => butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) := by + change pairSwitch (fun y => (coinStepEquiv d).symm (c,ξ) (Sum.inl y)) * + childLift (fun b => butterflyPerm d (decodeButterfly d + (fun i => (coinStepEquiv d).symm (c,ξ) (Sum.inr (b,i))))) = _ + apply congrArg₂ (· * ·) + · rfl + · apply congrArg childLift + funext b + apply congrArg (fun ω => butterflyPerm d (decodeButterfly d ω)) + funext i + cases b <;> rfl + +lemma butterfly_product_bound (d : ℕ) (S : Finset (Card d)) + (p : Card d → ℝ) (hp : ∀ x, 0 ≤ p x) : + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) ≤ (finiteMean p)^S.card := by + classical + induction d with + | zero => + have he : p = fun _ => p (fun i => Fin.elim0 i) := by + funext x + exact congrArg p (Subsingleton.elim _ _) + rw [he] + simp only [Finset.prod_const,finiteMean_const,le_refl] + | succ d ih => + let g : Card d → ℝ := headAverage p + have hg : ∀ x, 0 ≤ g x := fun x => div_nonneg (add_nonneg (hp _) (hp _)) (by norm_num) + rw [finiteMean_equiv (coinStepEquiv d),finiteMean_prod] + calc + _ ≤ finiteMean (fun c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + (∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c.1) x)) * + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c.2) x)) := by + apply finiteMean_mono + intro c + let f : Equiv.Perm (Card (d+1)) := childLift (fun b => + butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))) + have hh := pairSwitch_product_bound d (S.image f) p hp + simp only [Finset.prod_image f.injective.injOn] at hh + convert hh using 1 + · apply finiteMean_congr + intro ξ + apply Finset.prod_congr rfl + intro x _ + rw [butterflyPerm_step] + rfl + · rw [prod_childMarks] + simp only [f,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + Bool.false_eq_true,↓reduceIte] + rfl + _ = (finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S false, g (butterflyPerm d (decodeButterfly d c) x))) * + finiteMean (fun c : SwitchIndex d → Bool => + ∏ x ∈ childMarks S true, g (butterflyPerm d (decodeButterfly d c) x)) := + finiteMean_prod_mul + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S false, + g (butterflyPerm d (decodeButterfly d c) x)) + (fun c : SwitchIndex d → Bool => ∏ x ∈ childMarks S true, + g (butterflyPerm d (decodeButterfly d c) x)) + _ ≤ (finiteMean g)^(childMarks S false).card * (finiteMean g)^(childMarks S true).card := + mul_le_mul (ih (childMarks S false) g hg) (ih (childMarks S true) g hg) + (finiteMean_nonneg fun c => Finset.prod_nonneg (fun x _ => hg _)) + (pow_nonneg (finiteMean_nonneg hg) _) + _ = (finiteMean p)^S.card := by + rw [←pow_add,card_childMarks_add,finiteMean_headAverage] + +noncomputable def inverseButterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)).symm + +lemma inverseButterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (inverseButterflyMarks d A) S ≤ + ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + classical + let p : Card d → ℝ := fun x => if x ∈ A then 1 else 0 + have hm : finiteMean p = (A.card : ℝ)/(2:ℝ)^d := by + simp only [finiteMean,p,card_positions,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + simp + have he : inclusionMoment (inverseButterflyMarks d A) S = + finiteMean (fun ω : SwitchIndex d → Bool => + ∏ x ∈ S, p (butterflyPerm d (decodeButterfly d ω) x)) := by + rw [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [inverseButterflyMarks,subset_image_equiv_iff,Equiv.symm_symm,indicator_subset_prod, + Finset.prod_image (butterflyPerm d (decodeButterfly d ω)).injective.injOn,p] + rw [he] + simpa only [hm] using butterfly_product_bound d S p (fun x => by dsimp [p]; split_ifs <;> norm_num) + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def occupied (x : ι → Bool × α) : Finset α := + Finset.univ.image (fun i => (x i).2) + +omit [Fintype α] in +lemma mem_occupied (x : ι → Bool × α) (y : α) : y ∈ occupied x ↔ ∃ i, (x i).2 = y := by + simp [occupied] + +def required (x : ι → Bool × α) (c : ι → Bool) (i : ι) : Bool := Bool.xor (x i).1 (c i) + +def Compatible (x : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i j, (x i).2 = (x j).2 → required x c i = required x c j + +def colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : Bool := + Bool.xor (x i).1 (ξ (x i).2) + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma required_colors (x : ι → Bool × α) (ξ : α → Bool) (i : ι) : + required x (colors x ξ) i = ξ (x i).2 := by + simp only [required,colors] + cases (x i).1 <;> cases ξ (x i).2 <;> rfl + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma colors_compatible (x : ι → Bool × α) (ξ : α → Bool) : Compatible x (colors x ξ) := by + intro i j he + simp only [required_colors,he] + +noncomputable def chosenCoin (x : ι → Bool × α) (c : ι → Bool) (y : α) : Bool := by + classical + exact if h : ∃ i, (x i).2 = y then required x c (Classical.choose h) else false + +omit [Fintype α] in +lemma chosenCoin_apply (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + chosenCoin x c (x i).2 = required x c i := by + classical + simp only [chosenCoin,dite_eq_left (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)] + exact hc _ i (Classical.choose_spec (show ∃ j, (x j).2 = (x i).2 from ⟨i,rfl⟩)) + +omit [Fintype α] in +lemma colors_eq_iff (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) (ξ : α → Bool) : + colors x ξ = c ↔ ∀ y ∈ occupied x, ξ y = chosenCoin x c y := by + constructor + · intro he y hy + obtain ⟨i,rfl⟩ := (mem_occupied x y).mp hy + rw [chosenCoin_apply x c hc i] + rw [←he,required_colors] + · intro he + funext i + apply (xor_eq_iff _ _ _).mpr + exact (he _ ((mem_occupied x _).mpr ⟨i,rfl⟩)).trans (chosenCoin_apply x c hc i) + +noncomputable instance (x : ι → Bool × α) (c : ι → Bool) : Decidable (Compatible x c) := + Classical.propDecidable _ + +lemma colors_probability (x : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ξ : α → Bool => if colors x ξ = c then (1 : ℝ) else 0) = + if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0 := by + classical + by_cases hc : Compatible x c + · rw [ite_eq_left hc] + have he := fun ξ => colors_eq_iff x c hc ξ + simp only [he] + exact mean_coinCylinder (occupied x) (chosenCoin x c) + · rw [ite_eq_right hc] + have he : ∀ ξ, colors x ξ ≠ c := fun ξ hh => hc (hh ▸ colors_compatible x ξ) + simp only [he,ite_false,finiteMean_const] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma Compatible.tail_injective {x : ι ↪ Bool × α} {c : ι → Bool} (hc : Compatible x c) (b : Bool) : + Function.Injective (fun i : {i : ι // c i = b} => (x i.val).2) := by + intro i j he + apply Subtype.ext + apply x.injective + apply Prod.ext + · have hh := hc i j he + simp only [required,i.property,j.property] at hh + cases h₀ : (x i.val).1 <;> cases h₁ : (x j.val).1 <;> cases b <;> simp_all + · exact he + +def childEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + {i : ι // c i = b} ↪ α := ⟨fun i => (x i.val).2,hc.tail_injective b⟩ + + +def lift (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) where + toFun x := (x.1,p x.1 x.2) + invFun x := (x.1,(p x.1).symm x.2) + left_inv x := by simp + right_inv x := by simp + +def sandwich (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : Equiv.Perm (Bool × α) := + pairLayer η * lift p * pairLayer ξ + +def ChildMatches (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : Prop := + ∀ i, p (c i) (x i).2 = (y i).2 + +noncomputable instance (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + Decidable (ChildMatches p x y c) := Classical.propDecidable _ + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma sandwich_matches_iff (ξ η : α → Bool) (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + (∀ i, sandwich ξ η p (x i) = y i) ↔ + colors x ξ = colors y η ∧ ChildMatches p x y (colors x ξ) := by + have he (i : ι) : sandwich ξ η p (x i) = y i ↔ + colors x ξ i = colors y η i ∧ p (colors x ξ i) (x i).2 = (y i).2 := by + change pairLayer η (lift p (pairLayer ξ (x i))) = y i ↔ _ + rw [←Equiv.eq_symm_apply] + change (colors x ξ i,p (colors x ξ i) (x i).2) = (colors y η i,(y i).2) ↔ _ + exact ⟨Prod.mk.inj,fun h => Prod.ext h.1 h.2⟩ + simp only [he,forall_and,←funext_iff,ChildMatches] + +lemma sandwich_probability [DecidableEq ι] (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (if ChildMatches p x y c then 1 else 0) := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then (1:ℝ) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then 1 else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const] + rw [finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma childMatches_split (p₀ p₁ : Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + ChildMatches (fun b => if b then p₁ else p₀) x y c ↔ + (∀ i : {i // c i = false}, p₀ (x i.val).2 = (y i.val).2) ∧ + (∀ i : {i // c i = true}, p₁ (x i.val).2 = (y i.val).2) := by + constructor + · intro h + constructor + · intro i + simpa only [i.property,Bool.false_eq_true,↓reduceIte] using h i.val + · intro i + simpa only [i.property,↓reduceIte] using h i.val + · rintro ⟨h₀,h₁⟩ i + cases hi : c i + · simpa only [hi,Bool.false_eq_true,↓reduceIte] using h₀ ⟨i,hi⟩ + · simpa only [hi,↓reduceIte] using h₁ ⟨i,hi⟩ + +omit [Fintype α] in +lemma childMatches_mean {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) (c : ι → Bool) : + finiteMean (fun ω : Ω × Ω' => + if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) := by + classical + let f : Ω → ℝ := fun ω => if ∀ i : {i // c i = false}, P ω (x i.val).2 = (y i.val).2 then 1 else 0 + let g : Ω' → ℝ := fun ω => if ∀ i : {i // c i = true}, Q ω (x i.val).2 = (y i.val).2 then 1 else 0 + have he (ω : Ω × Ω') : + (if ChildMatches (fun b => if b then Q ω.2 else P ω.1) x y c then (1:ℝ) else 0) = f ω.1*g ω.2 := by + simp only [childMatches_split,f,g] + split_ifs <;> simp_all + simp_rw [he] + exact finiteMean_prod_mul f g + +lemma sandwich_mean [DecidableEq ι] {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) : + finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)) = + ∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2)) := by + classical + simp_rw [sandwich_probability] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [mul_comm ((if Compatible x c then _ else _) * _),finiteMean_mul_const, + childMatches_mean] + + +abbrev BothAssignments (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) := + {c : ι → Bool // Compatible e c ∧ Compatible (fun i => lift p (e i)) c} + +noncomputable instance (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype (BothAssignments e p) := Fintype.ofFinite _ + +noncomputable def labelSet (e : ι ↪ Bool × α) : Finset (Bool × α) := Finset.univ.image e + +def alternatingProjection (p : Bool → Equiv.Perm α) : Equiv.Perm α := (p false).symm * p true + +noncomputable def assignmentColoring (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (c : BothAssignments e p) : CycleColoring.OppositeColoring + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) := by + classical + refine ⟨Function.extend e c.val (fun _ => false),?_,?_⟩ + · intro z hz + apply Function.extend_apply' + rintro ⟨i,rfl⟩ + exact hz (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + · intro z hz hnext + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + obtain ⟨j,_,hj⟩ := Finset.mem_image.mp hnext + have hfi := e.injective.extend_apply c.val (fun _ => false) i + have hfj := e.injective.extend_apply c.val (fun _ => false) j + rw [hi] at hfi + rw [hj] at hfj + rw [hfi,hfj] + rcases z with ⟨b,a⟩ + cases b + · have hj' : e j = (true,a) := hj + have ht : (e i).2 = (e j).2 := by rw [hi,hj'] + have hh := c.property.1 i j ht + simp only [required,hi,hj'] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + · have hj' : e j = (false,alternatingProjection p a) := hj + have ht : (lift p (e i)).2 = (lift p (e j)).2 := by + simp only [hi,hj',lift,Equiv.coe_fn_mk,alternatingProjection,Equiv.Perm.coe_mul, + Function.comp_apply,Equiv.apply_symm_apply] + have hh := c.property.2 i j ht + simp only [required,hi,hj',lift,Equiv.coe_fn_mk] at hh + revert hh + generalize c.val i = bi + generalize c.val j = bj + cases bi <;> cases bj <;> decide + +omit [Fintype α] in +lemma assignmentColoring_injective (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Function.Injective (assignmentColoring e p) := by + intro c c' he + apply Subtype.ext + funext i + have hh := congrFun (congrArg Subtype.val he) (e i) + change Function.extend e c.val (fun _ => false) (e i) = + Function.extend e c'.val (fun _ => false) (e i) at hh + simpa only [e.injective.extend_apply] using hh + +lemma bothAssignments_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card + + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image + (alternatingProjection p)).card - + ((boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card) + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have h := compatible_assignment_bound (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +omit [Fintype α] in +lemma occupied_labelSet (e : ι ↪ Bool × α) : occupied e = (labelSet e).image Prod.snd := by + classical + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + +omit [Fintype ι] [Fintype α] in +lemma image_snd_childJoin (A B : Finset α) : (childJoin A B).image Prod.snd = A ∪ B := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,Finset.image_id'] + +omit [Fintype ι] [Fintype α] in +lemma image_lift_childJoin (p : Bool → Equiv.Perm α) (A B : Finset α) : + (childJoin A B).image (fun x => (lift p x).2) = A.image (p false) ∪ B.image (p true) := by + classical + simp only [childJoin,Finset.image_union,Finset.image_image,Function.comp_def,lift,Equiv.coe_fn_mk] + +omit [Fintype α] in +lemma occupied_lift_card (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + (occupied (fun i => lift p (e i))).card = + (boolFiber (labelSet e) false ∪ (boolFiber (labelSet e) true).image (alternatingProjection p)).card := by + classical + have he : occupied (fun i => lift p (e i)) = (labelSet e).image (fun x => (lift p x).2) := by + simp only [occupied,labelSet,Finset.image_image,Function.comp_def] + rw [he,←childJoin_boolFiber (labelSet e),image_lift_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + let A := boolFiber (labelSet e) false + let B := boolFiber (labelSet e) true + change (A.image (p false) ∪ B.image (p true)).card = (A ∪ B.image (alternatingProjection p)).card + have hh : A.image (p false) ∪ B.image (p true) = + (A ∪ B.image (alternatingProjection p)).image (p false) := by + simp only [Finset.image_union,Finset.image_image,Function.comp_def, + alternatingProjection,Equiv.Perm.coe_mul,Equiv.apply_symm_apply] + rw [hh,Finset.card_image_of_injective _ (p false).injective] + +lemma bothAssignments_occupied_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + Fintype.card (RoutingNetwork.SelectedCycle (alternatingProjection p) (boolFiber (labelSet e) false))) := by + have he : (occupied e).card = + (boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true).card := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + have hc : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,labelSet,Finset.card_image_of_injective _ e.injective, + Finset.card_univ] + simpa only [he,occupied_lift_card,←hc] using bothAssignments_card e p + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma compatible_pairLayer_iff (x : ι → Bool × α) (c : ι → Bool) (ξ : α → Bool) : + Compatible (fun i => pairLayer ξ (x i)) c ↔ Compatible x c := by + have he (i j : ι) (ht : (x i).2 = (x j).2) : + required (fun i => pairLayer ξ (x i)) c i = required (fun i => pairLayer ξ (x i)) c j ↔ + required x c i = required x c j := by + simp only [required,pairLayer,Equiv.coe_fn_mk,ht] + cases (x i).1 <;> cases (x j).1 <;> cases c i <;> cases c j <;> cases ξ (x j).2 <;> decide + constructor + · intro h i j ht + exact (he i j ht).mp (h i j ht) + · intro h i j ht + exact (he i j ht).mpr (h i j ht) + + +noncomputable def alternatingCycles (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : ℕ := + Fintype.card (RoutingNetwork.SelectedCycle + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e)) + +omit [Fintype α] in +lemma occupied_eq_fibers (e : ι ↪ Bool × α) : + occupied e = boolFiber (labelSet e) false ∪ boolFiber (labelSet e) true := by + rw [occupied_labelSet,←childJoin_boolFiber (labelSet e),image_snd_childJoin] + simp only [CycleColoring.boolFiber_childJoin,Bool.false_eq_true,↓reduceIte] + +omit [Fintype α] in +lemma card_labelSet (e : ι ↪ Bool × α) : (labelSet e).card = Fintype.card ι := by + classical + exact (Finset.card_image_of_injective _ e.injective).trans (Finset.card_univ) + +omit [Fintype α] in +lemma occupied_card_double (e : ι ↪ Bool × α) : Fintype.card ι ≤ 2*(occupied e).card := by + have h₀ : (boolFiber (labelSet e) false).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_left + have h₁ : (boolFiber (labelSet e) true).card ≤ (occupied e).card := by + rw [occupied_eq_fibers] + exact Finset.card_le_card Finset.subset_union_right + have he : (boolFiber (labelSet e) false).card+(boolFiber (labelSet e) true).card = Fintype.card ι := by + rw [←card_childJoin,childJoin_boolFiber,card_labelSet] + omega + +lemma bothAssignments_exact_bound (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + Fintype.card (BothAssignments e p) ≤ + 2 ^ ((occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι + + alternatingCycles e p) := by + have h := CycleColoring.card_opposite_le + (CycleColoring.alternatingPerm (alternatingProjection p)) (labelSet e) + Prod.fst (CycleColoring.alternatingPerm_flip (alternatingProjection p)) + have hb : (CycleColoring.boundary (CycleColoring.alternatingPerm (alternatingProjection p)) + (labelSet e)).card = + (occupied e).card + (occupied (fun i => lift p (e i))).card - Fintype.card ι := by + have hh := alternating_boundary_card (alternatingProjection p) + (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber] at hh + rw [occupied_eq_fibers,occupied_lift_card] + have he := card_childJoin (boolFiber (labelSet e) false) (boolFiber (labelSet e) true) + rw [childJoin_boolFiber,card_labelSet] at he + simpa only [he] using hh + rw [hb] at h + exact (Fintype.card_le_of_injective _ (assignmentColoring_injective e p)).trans h + +abbrev Assignments (x y : ι → Bool × α) := + {c : ι → Bool // Compatible x c ∧ Compatible y c} + +noncomputable instance (x y : ι → Bool × α) : Fintype (Assignments x y) := Fintype.ofFinite _ + +def switchedEmbedding (e : ι ↪ Bool × α) (ξ : α → Bool) : ι ↪ Bool × α := + e.trans (pairLayer ξ).toEmbedding + +def routedEmbedding (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + ι ↪ Bool × α := e.trans (sandwich ξ η p).toEmbedding + +omit [Fintype α] in +lemma occupied_pairLayer (x : ι → Bool × α) (ξ : α → Bool) : + occupied (fun i => pairLayer ξ (x i)) = occupied x := rfl + +noncomputable def assignmentsEquiv (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Assignments e (routedEmbedding e ξ η p) ≃ BothAssignments (switchedEmbedding e ξ) p := by + apply Equiv.subtypeEquivRight + intro c + change Compatible e c ∧ Compatible (fun i => pairLayer η (lift p (pairLayer ξ (e i)))) c ↔ _ + rw [compatible_pairLayer_iff] + exact and_congr (compatible_pairLayer_iff e c ξ).symm Iff.rfl + +lemma assignments_actual_bound (e : ι ↪ Bool × α) (ξ η : α → Bool) (p : Bool → Equiv.Perm α) : + Fintype.card (Assignments e (routedEmbedding e ξ η p)) ≤ + 2 ^ ((occupied e).card + (occupied (routedEmbedding e ξ η p)).card - Fintype.card ι + + alternatingCycles (switchedEmbedding e ξ) p) := by + rw [Fintype.card_congr (assignmentsEquiv e ξ η p)] + exact bothAssignments_exact_bound (switchedEmbedding e ξ) p + +omit [Fintype α] in +lemma assignments_actual_exponent_nonneg (e : ι ↪ Bool × α) (ξ η : α → Bool) + (p : Bool → Equiv.Perm α) : + Fintype.card ι ≤ (occupied e).card + (occupied (routedEmbedding e ξ η p)).card := by + have h₀ := occupied_card_double e + have h₁ := occupied_card_double (routedEmbedding e ξ η p) + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +noncomputable def compatibleSet (x y : ι → Bool × α) : Finset (ι → Bool) := by + classical + exact Finset.univ.filter (fun c => Compatible x c ∧ Compatible y c) + +omit [Fintype α] [DecidableEq α] in +lemma mem_compatibleSet (x y : ι → Bool × α) (c : ι → Bool) : + c ∈ compatibleSet x y ↔ Compatible x c ∧ Compatible y c := by + classical + simp only [compatibleSet,Finset.mem_filter,Finset.mem_univ,true_and] + +omit [Fintype α] [DecidableEq α] in +lemma card_compatibleSet (x y : ι → Bool × α) : + (compatibleSet x y).card = Fintype.card (Assignments x y) := by + classical + exact (Fintype.card_subtype _).symm + +noncomputable def outerWeight (x y : ι → Bool × α) : ℝ := + 1/(2:ℝ)^((occupied x).card+(occupied y).card) + +omit [Fintype α] [DecidableEq ι] in +lemma outerWeight_pos (x y : ι → Bool × α) : 0 < outerWeight x y := by + unfold outerWeight + positivity + +omit [Fintype α] in +lemma sum_colors_factor (x y : ι → Bool × α) (f : (ι → Bool) → ℝ) : + (∑ c : ι → Bool, + (if Compatible x c then 1/(2:ℝ)^(occupied x).card else 0) * + (if Compatible y c then 1/(2:ℝ)^(occupied y).card else 0) * f c) = + outerWeight x y * ∑ c ∈ compatibleSet x y, f c := by + classical + rw [compatibleSet,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + by_cases hx : Compatible x c <;> by_cases hy : Compatible y c + · simp only [hx,hy,true_and,↓reduceIte,outerWeight,pow_add,one_div_mul_one_div] + · simp only [hx,hy,and_false,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + · simp only [hx,hy,false_and,↓reduceIte,mul_zero,zero_mul] + +lemma sandwich_weighted_probability (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c ∈ compatibleSet x y, if ChildMatches p x y c then W c else 0 := by + classical + have he (coins : (α → Bool) × (α → Bool)) : + (if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + ∑ c : ι → Bool, (if colors x coins.1 = c then (1:ℝ) else 0) * + (if colors y coins.2 = c then 1 else 0) * (if ChildMatches p x y c then W c else 0) := by + rw [Finset.sum_eq_single (colors x coins.1)] + · by_cases hc : colors x coins.1 = colors y coins.2 + · simp only [sandwich_matches_iff,hc,true_and,↓reduceIte,one_mul] + · simp only [sandwich_matches_iff,hc,false_and,↓reduceIte,one_mul,Ne.symm hc,zero_mul] + · intro c _ hc + simp only [Ne.symm hc,ite_false,zero_mul] + · simp + simp_rw [he] + rw [finiteMean_sum,←sum_colors_factor] + apply Finset.sum_congr rfl + intro c _ + rw [finiteMean_mul_const,finiteMean_prod_mul + (fun ξ : α → Bool => if colors x ξ = c then (1:ℝ) else 0) + (fun η : α → Bool => if colors y η = c then (1:ℝ) else 0), + colors_probability,colors_probability] + +omit [Fintype α] [DecidableEq ι] in +lemma tupleProbability_nonneg {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : 0 ≤ tupleProbability P x y := by + classical + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma sandwich_power_bound {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (P : Ω → Equiv.Perm α) (Q : Ω' → Equiv.Perm α) (x y : ι → Bool × α) + (a : ℝ) (ha : 0 ≤ a) : + (finiteMean (fun ω : Ω × Ω' => finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 (fun b => if b then Q ω.2 else P ω.1) (x i) = y i + then (1:ℝ) else 0)))^(1+a) ≤ + (outerWeight x y)^(1+a) * ((compatibleSet x y).card:ℝ)^a * + ∑ c ∈ compatibleSet x y, + (tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) := by + classical + rw [sandwich_mean,sum_colors_factor] + let f (c : ι → Bool) : ℝ := + tupleProbability P (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2) * + tupleProbability Q (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2) + have hf (c : ι → Bool) : 0 ≤ f c := mul_nonneg (tupleProbability_nonneg _ _ _) + (tupleProbability_nonneg _ _ _) + rw [Real.mul_rpow (le_of_lt (outerWeight_pos _ _)) (Finset.sum_nonneg (fun c _ => hf c))] + have hh := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg (compatibleSet x y) + (show 1 ≤ 1+a by linarith) (fun c _ => hf c) + have he : 1+a-1=a := by ring + rw [he] at hh + calc + _ ≤ (outerWeight x y)^(1+a) * + (((compatibleSet x y).card:ℝ)^a * ∑ c ∈ compatibleSet x y, (f c)^(1+a)) := + mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg (le_of_lt (outerWeight_pos _ _)) _) + _ = _ := by + rw [←mul_assoc] + congr 1 + apply Finset.sum_congr rfl + intro c _ + exact Real.mul_rpow (tupleProbability_nonneg _ _ _) (tupleProbability_nonneg _ _ _) + +end PairRouting + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/AssignmentSlots.lean b/lean/OAI/Probability/ThorpRouting/Tail/AssignmentSlots.lean index 46616eb1781026f7e5461c839715510bb5a3fe61..9962cc730866365c6273a9685f46bf91e9289d1e 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/AssignmentSlots.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/AssignmentSlots.lean @@ -1,834 +1,834 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.RotationMeeting - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter -section CycleCounting -variable {d A : ℕ} - -lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {d A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr - -end GroupedCounting - -section AllLengths -variable {d A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) - (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) - (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : - finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by - have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by - rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] - exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm - have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), - ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by - calc - _ = ((q-1)+1)^(F ω) := by congr 1; ring - _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by - rw [add_pow] - simp only [one_pow,mul_one] - _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by - apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) - intro a _ ha - have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega - rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] - _ = _ := by - apply Finset.sum_congr rfl - intro a _ - rw [hc] - ring - simp_rw [hex,finiteMean_sum,finiteMean_mul_const] - calc - _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_right (hm a) (by positivity) - _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by - apply Finset.sum_congr rfl - intro a _ - rw [mul_pow] - ring - _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ - -lemma inv_sqrt_step (j : ℕ) : - 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by - have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) - apply (div_le_iff₀ hp).mpr - have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) - have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) - nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] - -lemma sum_inv_sqrt (J : ℕ) : - (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by - have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ] - have hs := inv_sqrt_step n - push_cast - linarith - rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] - exact h J -section CycleMGF -variable {d : ℕ} - -lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : - finiteMean (fun ω : SwitchIndex d → Bool => - ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment S J - -end CycleMGF - -section FullCycleMGF -variable {d : ℕ} - -abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} - (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by - apply div_pos - · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty - · exact Nat.cast_pos.mpr Fintype.card_pos - -lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => - q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - -end FullCycleMGF - -structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] - [Fintype ι] [DecidableEq ι] (d : ℕ) where - perm : (ι → Bool) → Equiv.Perm α - path : (ι → Bool) → α → Finset ι - users : (ι → Bool) → ι → α × α - users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 - mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x - card_path : ∀ ω x, (path ω x).card = d - entropy : ∀ ω (S : Finset α), - (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) - follow : α → (α → QueryTree ι) → QueryTree ι - close : α → α → QueryTree ι → QueryTree ι - follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω - follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω - follow_stale_charge : ∀ x k R ω, - (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω - close_succeeds : ∀ x y k ω, - (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false - close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d - close_stale_charge : ∀ x y k R ω, perm ω x = y → - (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card - -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) - -lemma card_switches_using (ω : ι → Bool) (x : α) : - (Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : ι => - (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by - ext i - simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] - rw [he,R.card_path] -lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = - (d : ℝ) * ∑ x : α, w x := by - classical - calc - _ = ∑ i : ι, ∑ x : α, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : α => - (R.users b i).1 = x ∨ (R.users b i).2 = x) = - {(R.users b i).1, (R.users b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (R.users_ne b i)] - _ = ∑ x : α, ∑ i : ι, - if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : α, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : - ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ - (d : ℝ) / 2 * ∑ x : α, w x := by - have h : 2 * (∑ i : ι, - min (w (R.users b i).1) (w (R.users b i).2)) ≤ - ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), - min_le_right (w (R.users b i).1) (w (R.users b i).2)] - rw [switch_incidence_sum] at h - linarith -section Rotation -variable {A : ℕ} - -def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -omit [DecidableEq α] in -@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} - -noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) - (u v : α) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -omit [DecidableEq α] in -lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : - Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (i : Fin A) (x : α) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -omit [DecidableEq α] in -lemma slotWeight_antitone (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -omit [DecidableEq α] in -lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : α, pathWeight o x = (A : ℝ) := by - classical - have he (x : α) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : α → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : - (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : α) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := R.entropy b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) - (z : Terminal o) : ℝ := - ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 - -lemma rotationCharge_mean_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound R b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound R o hn b - linarith - -lemma rotation_exp_bound {o : α → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : α // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by - have hb := rotationCharge_mean_bound R hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by - have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -namespace QueryTree -open Thorp.QueryTree - -noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : - ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → - QueryTree (ι) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x - (fun y => seekCycle R S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) - (ω : ι → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle R S a r x V k).succeeds ω = true) : - (seekCycle R S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs - rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs - -noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : - List (α × ℕ) → Finset (α) → QueryTree (ι) - | [], _ => accept - | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) - -lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) - (V : Finset (α)) (ω : ι → Bool) - (hs : (seekCycles R S L V).succeeds ω = true) : - (seekCycles R S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : - finiteMean (fun ω : ι → Bool => - if (seekCycles R S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles R S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge R S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree -noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : - Finset (ι) := - V.biUnion (fun x => R.path b x) - -@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : - exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := - (R.path b z ∩ exposedPaths R b V).card - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) - (x : α) (V W : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : - (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (S V : Finset (α)) (z : α) - (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) - (hS : orbitSet (R.perm ω) z ⊆ S) - (hV : Disjoint V (orbitSet (R.perm ω) z)) : - let p := R.perm ω - let W := V ∪ orbitSet p z - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths R (ω) V) ω = - (k W).staleCharge (exposedPaths R (ω) W) ω + - terminalCharge R (ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -end RoutingNetwork -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.RotationMeeting + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter +section CycleCounting +variable {d A : ℕ} + +lemma assignmentOwner_eq_some {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {d A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (butterflyPerm d (decodeButterfly d ω)) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment S r hr + +end GroupedCounting + +section AllLengths +variable {d A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (Card d)) (r : Fin A → ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +lemma factorial_mgf {Ω : Type*} [Fintype Ω] (F : Ω → ℕ) (k : ℕ) (Λ q : ℝ) + (hF : ∀ ω, F ω ≤ k) (hΛ : 0 ≤ Λ) (hq : 1 ≤ q) + (hm : ∀ a, finiteMean (fun ω => ((F ω).descFactorial a : ℝ)) ≤ Λ^a) : + finiteMean (fun ω => q^(F ω)) ≤ Real.exp ((q-1)*Λ) := by + have hc (n a : ℕ) : (n.choose a : ℝ) = (n.descFactorial a : ℝ) / (a.factorial : ℝ) := by + rw [Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul] + exact (mul_div_cancel_left₀ _ (by exact_mod_cast Nat.factorial_ne_zero a)).symm + have hex (ω : Ω) : q^(F ω) = ∑ a ∈ Finset.range (k+1), + ((F ω).descFactorial a : ℝ) * ((q-1)^a / (a.factorial : ℝ)) := by + calc + _ = ((q-1)+1)^(F ω) := by congr 1; ring + _ = ∑ a ∈ Finset.range (F ω+1), (q-1)^a * (F ω).choose a := by + rw [add_pow] + simp only [one_pow,mul_one] + _ = ∑ a ∈ Finset.range (k+1), (q-1)^a * (F ω).choose a := by + apply Finset.sum_subset (Finset.range_mono (Nat.add_le_add_right (hF ω) _)) + intro a _ ha + have hn : F ω < a := by have := (Finset.mem_range.not.mp ha); omega + rw [Nat.choose_eq_zero_of_lt hn,Nat.cast_zero,mul_zero] + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [hc] + ring + simp_rw [hex,finiteMean_sum,finiteMean_mul_const] + calc + _ ≤ ∑ a ∈ Finset.range (k+1), Λ^a * ((q-1)^a / (a.factorial : ℝ)) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_right (hm a) (by positivity) + _ = ∑ a ∈ Finset.range (k+1), ((q-1)*Λ)^a / (a.factorial : ℝ) := by + apply Finset.sum_congr rfl + intro a _ + rw [mul_pow] + ring + _ ≤ _ := Real.sum_le_exp_of_nonneg (mul_nonneg (sub_nonneg.mpr hq) hΛ) _ + +lemma inv_sqrt_step (j : ℕ) : + 1 / Real.sqrt (j+1) ≤ 2*(Real.sqrt (j+1)-Real.sqrt j) := by + have hp : 0 < Real.sqrt (j+1) := Real.sqrt_pos.mpr (by positivity) + apply (div_le_iff₀ hp).mpr + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ j+1 by positivity) + have h0 := Real.sq_sqrt (show (0:ℝ) ≤ j by positivity) + nlinarith [sq_nonneg (Real.sqrt (j+1)-Real.sqrt j)] + +lemma sum_inv_sqrt (J : ℕ) : + (∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1)) ≤ 2*Real.sqrt J := by + have h (n : ℕ) : (∑ j ∈ Finset.range n, 1 / Real.sqrt (j+1)) ≤ 2*Real.sqrt n := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ] + have hs := inv_sqrt_step n + push_cast + linarith + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => (1 / Real.sqrt (j+1) : ℝ)) J] + exact h J +section CycleMGF +variable {d : ℕ} + +lemma butterfly_shortCycle_moment (S : Finset (Card d)) (J A : ℕ) : + finiteMean (fun ω : SwitchIndex d → Bool => + ((Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : Card d // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (Card d)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment S J + +end CycleMGF + +section FullCycleMGF +variable {d : ℕ} + +abbrev LongCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma finiteMean_pos {Ω : Type*} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} + (h : ∀ ω, 0 < f ω) : 0 < finiteMean f := by + apply div_pos + · exact Finset.sum_pos (fun ω _ => h ω) Finset.univ_nonempty + · exact Nat.cast_pos.mpr Fintype.card_pos + +lemma longCycle_pow_bound (p : Equiv.Perm (Card d)) (S : Finset (Card d)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (Card d)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (ShortCycle (butterflyPerm d (decodeButterfly d ω)) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : SwitchIndex d → Bool => + q^(Fintype.card (SelectedCycle (butterflyPerm d (decodeButterfly d ω)) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + +end FullCycleMGF + +structure RoutingNetwork (α ι : Type*) [Fintype α] [DecidableEq α] + [Fintype ι] [DecidableEq ι] (d : ℕ) where + perm : (ι → Bool) → Equiv.Perm α + path : (ι → Bool) → α → Finset ι + users : (ι → Bool) → ι → α × α + users_ne : ∀ ω i, (users ω i).1 ≠ (users ω i).2 + mem_path : ∀ ω x i, i ∈ path ω x ↔ (users ω i).1 = x ∨ (users ω i).2 = x + card_path : ∀ ω x, (path ω x).card = d + entropy : ∀ ω (S : Finset α), + (∑ i : ι, if (users ω i).1 ∈ S ∧ (users ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) + follow : α → (α → QueryTree ι) → QueryTree ι + close : α → α → QueryTree ι → QueryTree ι + follow_succeeds : ∀ x k ω, (follow x k).succeeds ω = (k (perm ω x)).succeeds ω + follow_raw_charge : ∀ x k ω, (follow x k).charge ω = (k (perm ω x)).charge ω + follow_stale_charge : ∀ x k R ω, + (follow x k).staleCharge R ω = (k (perm ω x)).staleCharge (R ∪ path ω x) ω + close_succeeds : ∀ x y k ω, + (close x y k).succeeds ω = if perm ω x = y then k.succeeds ω else false + close_raw_charge : ∀ x y k ω, perm ω x = y → (close x y k).charge ω = k.charge ω + d + close_stale_charge : ∀ x y k R ω, perm ω x = y → + (close x y k).staleCharge R ω = k.staleCharge (R ∪ path ω x) ω + (path ω x ∩ R).card + +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) + +lemma card_switches_using (ω : ι → Bool) (x : α) : + (Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : ι => + (R.users ω i).1 = x ∨ (R.users ω i).2 = x) = R.path ω x := by + ext i + simp only [Finset.mem_filter,Finset.mem_univ,true_and,R.mem_path] + rw [he,R.card_path] +lemma switch_incidence_sum (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) = + (d : ℝ) * ∑ x : α, w x := by + classical + calc + _ = ∑ i : ι, ∑ x : α, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : α => + (R.users b i).1 = x ∨ (R.users b i).2 = x) = + {(R.users b i).1, (R.users b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (R.users_ne b i)] + _ = ∑ x : α, ∑ i : ι, + if (R.users b i).1 = x ∨ (R.users b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : α, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (b : ι → Bool) (w : α → ℝ) : + ∑ i : ι, min (w (R.users b i).1) (w (R.users b i).2) ≤ + (d : ℝ) / 2 * ∑ x : α, w x := by + have h : 2 * (∑ i : ι, + min (w (R.users b i).1) (w (R.users b i).2)) ≤ + ∑ i : ι, (w (R.users b i).1 + w (R.users b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (R.users b i).1) (w (R.users b i).2), + min_le_right (w (R.users b i).1) (w (R.users b i).2)] + rw [switch_incidence_sum] at h + linarith +section Rotation +variable {A : ℕ} + +def cycleFiber (o : α → Option (Fin A)) (i : Fin A) : Finset (α) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +omit [DecidableEq α] in +@[simp] lemma mem_cycleFiber (o : α → Option (Fin A)) (i : Fin A) (x : α) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : α → Option (Fin A)) := ∀ i : Fin A, {x : α // o x = some i} + +noncomputable def slotWeight (o : α → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : α → Option (Fin A)) (x : α) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : α → Option (Fin A)) (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +noncomputable def rotationMeeting (o : α → Option (Fin A)) (z : Terminal o) + (u v : α) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +omit [DecidableEq α] in +lemma card_cycleFiber (o : α → Option (Fin A)) (i : Fin A) : + Fintype.card {x : α // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (i : Fin A) (x : α) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : α // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : α // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +omit [DecidableEq α] in +lemma slotWeight_antitone (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : α) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +omit [DecidableEq α] in +lemma pathWeight_sum (o : α → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : α, pathWeight o x = (A : ℝ) := by + classical + have he (x : α) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : α, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : α → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : ι → Bool) : + (∑ s : ι, withinWeight o (R.users b s).1 (R.users b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : α) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := R.entropy b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : α → Option (Fin A)) (b : ι → Bool) + (z : Terminal o) : ℝ := + ∑ s : ι, rotationMeeting o z (R.users b s).1 (R.users b s).2 + +lemma rotationCharge_mean_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + finiteMean (rotationCharge R o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : α // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound R b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound R o hn b + linarith + +lemma rotation_exp_bound {o : α → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : α // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : ι → Bool) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge R o b z)) := by + have hb := rotationCharge_mean_bound R hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge R o b z) := by + have he := finiteMean_mul_const (rotationCharge R o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +namespace QueryTree +open Thorp.QueryTree + +noncomputable def seekCycle (R : RoutingNetwork α ι d) (S : Finset (α)) (a : α) : + ℕ → α → Finset (α) → (Finset (α) → QueryTree (ι)) → + QueryTree (ι) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then R.close x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then R.follow x + (fun y => seekCycle R S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V : Finset (α)) (k : Finset (α) → QueryTree (ι)) + (ω : ι → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle R S a r x V k).succeeds ω = true) : + (seekCycle R S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.close_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,R.close_raw_charge _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,R.follow_succeeds] at hs + rw [seekCycle,ite_eq_left hv,R.follow_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,Thorp.QueryTree.succeeds] at hs + +noncomputable def seekCycles (R : RoutingNetwork α ι d) (S : Finset (α)) : + List (α × ℕ) → Finset (α) → QueryTree (ι) + | [], _ => accept + | (a,r) :: L, V => seekCycle R S a r a V (fun V => seekCycles R S L V) + +lemma seekCycles_raw_charge (S : Finset (α)) (L : List (α × ℕ)) + (V : Finset (α)) (ω : ι → Bool) + (hs : (seekCycles R S L V).succeeds ω = true) : + (seekCycles R S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge R S a r a V (fun V => seekCycles R S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (S : Finset (α)) (L : List (α × ℕ)) : + finiteMean (fun ω : ι → Bool => + if (seekCycles R S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles R S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles R S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge R S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree +noncomputable def exposedPaths (b : ι → Bool) (V : Finset (α)) : + Finset (ι) := + V.biUnion (fun x => R.path b x) + +@[simp] lemma exposedPaths_empty (b : ι → Bool) : exposedPaths R b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (b : ι → Bool) (V : Finset (α)) (x : α) : + exposedPaths R b (insert x V) = exposedPaths R b V ∪ R.path b x := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (b : ι → Bool) (z : α) (V : Finset (α)) : ℕ := + (R.path b z ∩ exposedPaths R b V).card + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycle_semantics (S : Finset (α)) (a : α) (r : ℕ) + (x : α) (V W : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (h : cycleTrace (R.perm ω) S a r x V = some (W,z)) : + (seekCycle R S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S a r x V k).staleCharge (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),R.close_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [R.close_stale_charge _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,R.follow_succeeds,R.follow_stale_charge] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (S V : Finset (α)) (z : α) + (k : Finset (α) → QueryTree (ι)) (ω : ι → Bool) + (hS : orbitSet (R.perm ω) z ⊆ S) + (hV : Disjoint V (orbitSet (R.perm ω) z)) : + let p := R.perm ω + let W := V ∪ orbitSet p z + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle R S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths R (ω) V) ω = + (k W).staleCharge (exposedPaths R (ω) W) ω + + terminalCharge R (ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +end RoutingNetwork +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/BenesCoins.lean b/lean/OAI/Probability/ThorpRouting/Tail/BenesCoins.lean index 558b73dc83c5ee60c6cbbccdb59f80eec7619d41..d3ae2994a5b3fda121a4f4112f1e4007d8404428 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/BenesCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/BenesCoins.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.AlternatingPerm - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter - -abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) - -def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := - butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm - -def sandwichShuffle {A B C D E F : Type*} : - ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where - toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) - invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) - left_inv _ := rfl - right_inv _ := rfl - -def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ - (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := - (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle - -lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - childLift p * childLift q = childLift (fun b => p b * q b) := by - ext x i - simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] - -lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl - -lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl - -lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * - pairSwitch coins.1 := by - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * - (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : - headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl - -lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : - headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl - -lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : - headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) - (headTailEquiv d x) := by - rw [palindromePerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) - (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by - obtain ⟨x,hx⟩ := C.nonempty - have hpx : alternatingPerm p x ∈ C.val := by - rw [←C.orbit_eq hx,mem_orbitSet] - exact (Equiv.Perm.SameCycle.refl _ _).apply_right - have hne : x ≠ alternatingPerm p x := by - intro he - have hh := congrArg Prod.fst he - rw [alternatingPerm_flip] at hh - cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh - have hs : {x,alternatingPerm p x} ⊆ C.val := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl <;> assumption - have hh := Finset.card_le_card hs - simpa only [Finset.card_pair hne] using hh - -lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : - 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by - classical - calc - _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] - _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := - Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) - _ ≤ _ := RoutingNetwork.cycleMass_le _ _ - -lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) - (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by - have h := alternating_cycle_count_double p S - omega - -end CycleColoring - -namespace PairRouting - -section -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - 2 * alternatingCycles e p ≤ Fintype.card ι := by - have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) - simpa only [alternatingCycles, card_labelSet] using hh - -lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) - (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by - have hh := alternatingCycles_double e p - omega - -end -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : - colors x (chosenCoin x c) = c := by - funext i - simp only [colors,chosenCoin_apply x c hc i,required] - cases (x i).1 <;> cases c i <;> rfl - -noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : - ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) - -omit [Fintype α] [DecidableEq ι] in -lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : - coloredEmbedding x c hc i = (c i,(x i).2) := by - apply Prod.ext - · exact congrFun (colors_chosenCoin x c hc) i - · rfl - -omit [Fintype α] [DecidableEq ι] in -lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) - (ξ : α → Bool) (he : colors x ξ = c) : - switchedEmbedding x ξ = coloredEmbedding x c hc := by - ext i : 1 - rw [coloredEmbedding_apply] - apply Prod.ext - · exact congrFun he i - · rfl - -lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - (compatibleSet x y).card ≤ - 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + - alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by - obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc - let ξ := chosenCoin x c - let η := chosenCoin y c - have he : routedEmbedding x ξ η p = y := by - ext i : 1 - have h := (sandwich_matches_iff ξ η p x y).mpr - ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by - simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ - exact h i - have hh := assignments_actual_bound x ξ η p - rw [he] at hh - rw [card_compatibleSet] - exact hh - -omit [Fintype α] [DecidableEq ι] in -lemma occupied_sum_ge (x y : ι ↪ Bool × α) : - Fintype.card ι ≤ (occupied x).card + (occupied y).card := by - have h₀ := occupied_card_double x - have h₁ := occupied_card_double y - omega - -lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : - ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ - (2:ℝ)^((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by - let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p - let b := (occupied x).card+(occupied y).card - let h := Fintype.card ι - have hb : h ≤ b := occupied_sum_ge x y - have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by - exact_mod_cast assignments_match_bound x y c hc p hm - change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) - rw [mul_one_div] - calc - _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) - _ = _ := by - rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] - congr 1 - rw [Nat.cast_add,Nat.cast_sub hb] - ring - -lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) - (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) - (a : ℝ) (ha : 0 ≤ a) : - (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ - (2:ℝ)^(((alternatingCycles - (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by - have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) - (assignment_weight_bound x y c hc p hm) ha - rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), - ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h - simpa only [mul_comm] using h - - -lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) - (W : (ι → Bool) → ℝ) : - finiteMean (fun coins : (α → Bool) × (α → Bool) => - if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = - outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, - if ChildMatches p x y c.val then W c.val else 0 := by - rw [sandwich_weighted_probability] - congr 1 - rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] - -omit [Fintype α] [DecidableEq α] [DecidableEq ι] in -lemma color_card_add (c : ι → Bool) : - Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by - have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by - cases c i <;> simp - rw [Fintype.card_congr he] - rw [Fintype.card_subtype_compl] - exact Nat.add_sub_of_le (Fintype.card_subtype_le _) - -end PairRouting - -noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] - (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) - (ω : BenesCoins d × BenesCoins d) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => palindromePerm d (if b then ω.2 else ω.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 - -lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : - palindromeCost (d+1) e σ = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) - (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by - unfold palindromeCost assignmentCost - dsimp only - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - -lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = - assignmentCost d (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [palindromeCost_eq] - simp only [Equiv.apply_symm_apply] - -noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : BenesCoins d => - if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) - -lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma palindrome_matches_step (d : ℕ) {ι : Type*} - (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) - (coins : (Card d → Bool) × (Card d → Bool)) : - (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] - rfl - -lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (d+1)) (a : ℝ) : - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - routingMoment (d+1) e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have he (ω : BenesCoins d × BenesCoins d) : - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [palindrome_matches_step,palindromeCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold routingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = - (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (d+1)) : - PairRouting.tupleProbability (palindromePerm (d+1)) e f = - finiteMean (fun ω : BenesCoins d × BenesCoins d => - finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) - ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] - have hp (b : Bool) (p q : BenesCoins d) : - palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by - cases b <;> rfl - simp only [palindrome_matches_step,hp] - -lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * - routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) - rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh - have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = - -(d:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - rwa [he] at hh - -lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - -theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ - (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by - classical - induction d generalizing ι with - | zero => - have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := - fun _ _ => Subsingleton.elim _ _ - simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] - | succ d ih => - let x := e.trans (headTailEquiv d).toEmbedding - let y := f.trans (headTailEquiv d).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (palindromePerm d) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : BenesCoins d × BenesCoins d => - if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((assignmentCost d x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) - have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha - rw [←palindrome_probability_step d e f] at hnode - change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = - (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) - ring - -lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : - (∑ f : ι ↪ Card d, routingMoment d e f a) = - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - unfold routingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] - (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : - finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = - (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] - rw [Real.rpow_add hn,Real.rpow_one] - field_simp - -noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card d => - ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) - -lemma density_normalization (d h n : ℕ) (a : ℝ) : - (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by - rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] - rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, - Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] - -theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : - palindromeRowMoment d e a ≤ - (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * - finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card d) := ⟨e⟩ - rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * - ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, - Fintype.card_embedding_eq,card_positions] - norm_cast - -end Thorp -namespace Thorp - -lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] - (A : Finset α) (T : β → Finset α) : - (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = - ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by - classical - by_cases h : Finset.univ.biUnion T ⊆ A - · rw [ite_eq_left h] - symm - apply Finset.prod_eq_one - intro b _ - rw [ite_eq_left] - exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h - · rw [ite_eq_right h] - obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h - obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx - symm - apply Finset.prod_eq_zero (Finset.mem_univ b) - rw [ite_eq_right] - exact fun hb => hxA (hb hxb) - -lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] - [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] - (F : Ω → Finset α) (p : α → ℝ) - (hF : CylinderBound (inclusionMoment F) p) - (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) - (hc : ∀ b s, 0 ≤ c b s) - (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : - finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ - ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by - classical - simp_rw [Fintype.prod_sum] - rw [finiteMean_sum] - apply Finset.sum_le_sum - intro s _ - let U := Finset.univ.biUnion (fun b => T b (s b)) - have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = - fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by - funext ω - rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] - exact mul_comm _ _ - rw [he,finiteMean_mul_const] - have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by - intro b _ b' _ hbb - exact hd b b' hbb (s b) (s b') - have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - by_cases hh : U ⊆ F ω <;> simp [hh] - calc - _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := - mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) - _ = _ := by - dsimp only [U] - rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro b _ - exact mul_comm _ _ - - -noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := - if T.card = 1 then 0 else w^T.card - -lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : - 0 ≤ sparseCoefficient w T := by - unfold sparseCoefficient - split_ifs <;> positivity - -lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) - (w : ℝ) (hw : 0 ≤ w) : - w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ - ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by - classical - let V := D ∩ A - let T : ↑D.powerset := if 2 ≤ V.card then - ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else - ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ - calc - _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by - by_cases h : 2 ≤ V.card - · have hn : V.card ≠ 1 := by omega - simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] - · simp [T,ite_eq_right h,sparseCoefficient,V] at * - _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => - sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) - (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) - (by split_ifs <;> norm_num)) (Finset.mem_univ T) - -lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : - ∑ i ∈ Finset.range n, x^i ≤ 2 := by - induction n with - | zero => simp - | succ n ih => - rw [Finset.sum_range_succ',pow_zero] - simp only [pow_succ',←Finset.mul_sum] - nlinarith - -lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : - ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ - 1 + 2*((R:ℝ)*z)^2 := by - classical - let x := (R:ℝ)*z - have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz - have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ - if i=1 then 0 else x^i := by - by_cases h : i=1 - · simp [h] - · simp only [ite_eq_right h] - dsimp [x] - rw [mul_pow] - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) - exact_mod_cast Nat.choose_le_pow R i - calc - _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := - Finset.sum_le_sum (fun i _ => hbound i) - _ ≤ 1+2*x^2 := by - rcases R with _ | R - · simp [x] - rcases R with _ | R - · norm_num [Finset.sum_range_succ] - positivity - have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = - 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by - rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] - have hn (i : ℕ) : 2+i ≠ 1 := by omega - simp only [hn,ite_false,pow_add,←Finset.mul_sum] - norm_num [Finset.sum_range_succ] - rw [he] - have hg := geometric_sum_half (R+1) hx hr - nlinarith [sq_nonneg x] - -lemma sparse_block_product_bound {α : Type*} [DecidableEq α] - (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : - ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ - Real.exp (2*((D.card:ℝ)*(p*w))^2) := by - classical - have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = - ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by - rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] - have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = - fun T => if T.card=1 then 0 else (p*w)^T.card := by - funext T - unfold sparseCoefficient - split_ifs <;> simp [mul_pow,mul_comm] - change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ - rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] - simp only [nsmul_eq_mul] - rw [he] - exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans - (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) - - -noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] - (D : β → Finset α) (A : Finset α) : ℕ := - ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 - -theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] - (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) - (hF : ∀ T, inclusionMoment F T ≤ p^T.card) - (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : - finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by - classical - have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by - intro T - simpa only [Finset.prod_const] using hF T - have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc - (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) - (fun _ S => sparseCoefficient_nonneg w hw S.val) - (fun b b' h S S' => (hd h).mono - (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) - calc - _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, - sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by - apply finiteMean_mono - intro ω - rw [sparseMass,←Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) - intro b _ - exact sparse_block_pointwise (F ω) (D b) w hw - _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by - simpa only [Finset.prod_const] using hb - _ ≤ _ := by - rw [Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro b _ - exact Finset.sum_nonneg (fun S _ => mul_nonneg - (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) - · intro b _ - exact sparse_block_product_bound (D b) p w hp hw (hr b) - -theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] - (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) - (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) - (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : - finiteMean (fun ω : SwitchIndex d → Bool => - w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ - Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by - apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w - (by positivity) hw - · exact inverseButterflyMarks_inclusion d A - · exact hr - - -def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 - -lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by - unfold crowdedMass - split_ifs <;> omega - -lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by - unfold crowdedMass - split_ifs <;> omega - -lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by - unfold crowdedMass - split_ifs with h - · have hh := PairRouting.alternatingCycles_double e p - omega - · rw [PairRouting.alternatingCycles_zero e p (by omega)] - -lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by - classical - induction d generalizing ι with - | zero => simp [palindromeCost] - | succ d ih => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 - have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 - have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) - have hs := crowdedMass_add (Fintype.card {i // c i = false}) - (Fintype.card {i // c i = true}) - rw [PairRouting.color_card_add] at hs - change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + - palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ - nlinarith - -noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, ι, _, e, ω => - if d+1 ≤ H then crowdedMass (Fintype.card ι) else - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + - cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = palindromeCost d e ω := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLowCost,palindromeCost,ite_eq_left h] - congr 2 <;> exact ih (by omega) _ _ - -lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by - classical - induction d generalizing ι with - | zero => simp [palindromeLowCost,cutoffMass] - | succ d ih => - by_cases h : d+1 ≤ H - · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] - exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) - · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] - exact Nat.add_le_add (ih _ _) (ih _ _) - - -noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := - Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.AlternatingPerm + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev BenesCoins (d : ℕ) := (SwitchIndex d → Bool) × (SwitchIndex d → Bool) + +def palindromePerm (d : ℕ) (ω : BenesCoins d) : Equiv.Perm (Card d) := + butterflyPerm d (decodeButterfly d ω.1) * (butterflyPerm d (decodeButterfly d ω.2)).symm + +def sandwichShuffle {A B C D E F : Type*} : + ((A × B) × C) × ((D × E) × F) ≃ ((A × D) × (B × E)) × (F × C) where + toFun x := (((x.1.1.1,x.2.1.1),(x.1.1.2,x.2.1.2)),(x.2.2,x.1.2)) + invFun x := (((x.1.1.1,x.1.2.1),x.2.2),((x.1.1.2,x.1.2.2),x.2.1)) + left_inv _ := rfl + right_inv _ := rfl + +def benesStepEquiv (d : ℕ) : BenesCoins (d+1) ≃ + (BenesCoins d × BenesCoins d) × ((Card d → Bool) × (Card d → Bool)) := + (Equiv.prodCongr (coinStepEquiv d) (coinStepEquiv d)).trans sandwichShuffle + +lemma childLift_mul (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + childLift p * childLift q = childLift (fun b => p b * q b) := by + ext x i + simp only [Equiv.Perm.mul_apply,childLift,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons] + +lemma childLift_inv (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + (childLift p)⁻¹ = childLift (fun b => (p b)⁻¹) := rfl + +lemma pairSwitch_inv (d : ℕ) (ξ : Card d → Bool) : (pairSwitch ξ)⁻¹ = pairSwitch ξ := rfl + +lemma palindromePerm_step (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => palindromePerm d (if b then c.2 else c.1)) * + pairSwitch coins.1 := by + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.1,c.2.1),coins.2)))) * + (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + rw [mul_assoc (pairSwitch coins.2),←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma headTail_switch (d : ℕ) (ξ : Card d → Bool) (x : Card (d+1)) : + headTailEquiv d (pairSwitch ξ x) = pairLayer ξ (headTailEquiv d x) := rfl + +lemma headTail_child (d : ℕ) (p : Bool → Equiv.Perm (Card d)) (x : Card (d+1)) : + headTailEquiv d (childLift p x) = PairRouting.lift p (headTailEquiv d x) := rfl + +lemma palindromePerm_coordinates (d : ℕ) (c : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) (x : Card (d+1)) : + headTailEquiv d (palindromePerm (d+1) ((benesStepEquiv d).symm (c,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then c.2 else c.1)) + (headTailEquiv d x) := by + rw [palindromePerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +noncomputable def palindromeCost : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma alternating_cycle_two (p : Equiv.Perm α) (S : Finset (Bool × α)) + (C : RoutingNetwork.SelectedCycle (alternatingPerm p) S) : 2 ≤ C.val.card := by + obtain ⟨x,hx⟩ := C.nonempty + have hpx : alternatingPerm p x ∈ C.val := by + rw [←C.orbit_eq hx,mem_orbitSet] + exact (Equiv.Perm.SameCycle.refl _ _).apply_right + have hne : x ≠ alternatingPerm p x := by + intro he + have hh := congrArg Prod.fst he + rw [alternatingPerm_flip] at hh + cases hb : x.1 <;> simp only [hb, Bool.not_false, Bool.not_true] at hh <;> cases hh + have hs : {x,alternatingPerm p x} ⊆ C.val := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl <;> assumption + have hh := Finset.card_le_card hs + simpa only [Finset.card_pair hne] using hh + +lemma alternating_cycle_count_double (p : Equiv.Perm α) (S : Finset (Bool × α)) : + 2 * Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) ≤ S.card := by + classical + calc + _ = ∑ _C : RoutingNetwork.SelectedCycle (alternatingPerm p) S, 2 := by simp [Nat.mul_comm] + _ ≤ RoutingNetwork.cycleMass (alternatingPerm p) S := + Finset.sum_le_sum (fun C _ => alternating_cycle_two p S C) + _ ≤ _ := RoutingNetwork.cycleMass_le _ _ + +lemma alternating_cycle_count_zero (p : Equiv.Perm α) (S : Finset (Bool × α)) + (hS : S.card ≤ 1) : Fintype.card (RoutingNetwork.SelectedCycle (alternatingPerm p) S) = 0 := by + have h := alternating_cycle_count_double p S + omega + +end CycleColoring + +namespace PairRouting + +section +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +lemma alternatingCycles_double (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + 2 * alternatingCycles e p ≤ Fintype.card ι := by + have hh := CycleColoring.alternating_cycle_count_double (alternatingProjection p) (labelSet e) + simpa only [alternatingCycles, card_labelSet] using hh + +lemma alternatingCycles_zero (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) + (hι : Fintype.card ι ≤ 1) : alternatingCycles e p = 0 := by + have hh := alternatingCycles_double e p + omega + +end +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma colors_chosenCoin (x : ι → Bool × α) (c : ι → Bool) (hc : Compatible x c) : + colors x (chosenCoin x c) = c := by + funext i + simp only [colors,chosenCoin_apply x c hc i,required] + cases (x i).1 <;> cases c i <;> rfl + +noncomputable def coloredEmbedding (x : ι ↪ Bool × α) (c : ι → Bool) (_hc : Compatible x c) : + ι ↪ Bool × α := switchedEmbedding x (chosenCoin x c) + +omit [Fintype α] [DecidableEq ι] in +lemma coloredEmbedding_apply (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) (i : ι) : + coloredEmbedding x c hc i = (c i,(x i).2) := by + apply Prod.ext + · exact congrFun (colors_chosenCoin x c hc) i + · rfl + +omit [Fintype α] [DecidableEq ι] in +lemma switchedEmbedding_eq_colored (x : ι ↪ Bool × α) (c : ι → Bool) (hc : Compatible x c) + (ξ : α → Bool) (he : colors x ξ = c) : + switchedEmbedding x ξ = coloredEmbedding x c hc := by + ext i : 1 + rw [coloredEmbedding_apply] + apply Prod.ext + · exact congrFun he i + · rfl + +lemma assignments_match_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + (compatibleSet x y).card ≤ + 2 ^ ((occupied x).card + (occupied y).card - Fintype.card ι + + alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p) := by + obtain ⟨hcx,hcy⟩ := (mem_compatibleSet x y c).mp hc + let ξ := chosenCoin x c + let η := chosenCoin y c + have he : routedEmbedding x ξ η p = y := by + ext i : 1 + have h := (sandwich_matches_iff ξ η p x y).mpr + ⟨(colors_chosenCoin x c hcx).trans (colors_chosenCoin y c hcy).symm,by + simpa only [ξ,colors_chosenCoin x c hcx] using hm⟩ + exact h i + have hh := assignments_actual_bound x ξ η p + rw [he] at hh + rw [card_compatibleSet] + exact hh + +omit [Fintype α] [DecidableEq ι] in +lemma occupied_sum_ge (x y : ι ↪ Bool × α) : + Fintype.card ι ≤ (occupied x).card + (occupied y).card := by + have h₀ := occupied_card_double x + have h₁ := occupied_card_double y + omega + +lemma assignment_weight_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) : + ((compatibleSet x y).card:ℝ) * outerWeight x y ≤ + (2:ℝ)^((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι) := by + let z := alternatingCycles (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p + let b := (occupied x).card+(occupied y).card + let h := Fintype.card ι + have hb : h ≤ b := occupied_sum_ge x y + have hn : ((compatibleSet x y).card:ℝ) ≤ (2:ℝ)^(b-h+z) := by + exact_mod_cast assignments_match_bound x y c hc p hm + change ((compatibleSet x y).card:ℝ) * (1/(2:ℝ)^b) ≤ (2:ℝ)^((z:ℝ)-h) + rw [mul_one_div] + calc + _ ≤ (2:ℝ)^(b-h+z)/(2:ℝ)^b := div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by + rw [←Real.rpow_natCast,←Real.rpow_natCast,←Real.rpow_sub (by norm_num : (0:ℝ)<2)] + congr 1 + rw [Nat.cast_add,Nat.cast_sub hb] + ring + +lemma assignment_factor_bound (x y : ι ↪ Bool × α) (c : ι → Bool) + (hc : c ∈ compatibleSet x y) (p : Bool → Equiv.Perm α) (hm : ChildMatches p x y c) + (a : ℝ) (ha : 0 ≤ a) : + (outerWeight x y)^a * ((compatibleSet x y).card:ℝ)^a ≤ + (2:ℝ)^(((alternatingCycles + (coloredEmbedding x c (mem_compatibleSet x y c |>.mp hc).1) p : ℝ) - Fintype.card ι)*a) := by + have h := Real.rpow_le_rpow (mul_nonneg (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y))) + (assignment_weight_bound x y c hc p hm) ha + rw [Real.mul_rpow (Nat.cast_nonneg _) (le_of_lt (outerWeight_pos x y)), + ←Real.rpow_mul (by norm_num : (0:ℝ)≤2)] at h + simpa only [mul_comm] using h + + +lemma sandwich_weighted_probability_subtype (p : Bool → Equiv.Perm α) (x y : ι → Bool × α) + (W : (ι → Bool) → ℝ) : + finiteMean (fun coins : (α → Bool) × (α → Bool) => + if ∀ i, sandwich coins.1 coins.2 p (x i) = y i then W (colors x coins.1) else 0) = + outerWeight x y * ∑ c : {c // c ∈ compatibleSet x y}, + if ChildMatches p x y c.val then W c.val else 0 := by + rw [sandwich_weighted_probability] + congr 1 + rw [Finset.sum_subtype (compatibleSet x y) (fun _ => Iff.rfl)] + +omit [Fintype α] [DecidableEq α] [DecidableEq ι] in +lemma color_card_add (c : ι → Bool) : + Fintype.card {i // c i = false} + Fintype.card {i // c i = true} = Fintype.card ι := by + have he : {i // c i = true} ≃ {i // ¬c i = false} := Equiv.subtypeEquivRight fun i => by + cases c i <;> simp + rw [Fintype.card_congr he] + rw [Fintype.card_subtype_compl] + exact Nat.add_sub_of_le (Fintype.card_subtype_le _) + +end PairRouting + +noncomputable def assignmentCost (d : ℕ) {ι : Type*} [Fintype ι] + (x : ι ↪ Bool × Card d) (c : ι → Bool) (hc : PairRouting.Compatible x c) + (ω : BenesCoins d × BenesCoins d) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => palindromePerm d (if b then ω.2 else ω.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) ω.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) ω.2 + +lemma palindromeCost_eq (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (σ : BenesCoins (d+1)) : + palindromeCost (d+1) e σ = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) (benesStepEquiv d σ).2.1) + (PairRouting.colors_compatible _ _) (benesStepEquiv d σ).1 := by + unfold palindromeCost assignmentCost + dsimp only + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + +lemma palindromeCost_step (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)) = + assignmentCost d (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [palindromeCost_eq] + simp only [Equiv.apply_symm_apply] + +noncomputable def routingMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : BenesCoins d => + if ∀ i, palindromePerm d ω (e i) = f i then (2:ℝ)^((palindromeCost d e ω:ℝ)*a) else 0) + +lemma routingMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) : 0 ≤ routingMoment d e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma palindrome_matches_step (d : ℕ) {ι : Type*} + (e f : ι ↪ Card (d+1)) (ω : BenesCoins d × BenesCoins d) + (coins : (Card d → Bool) × (Card d → Bool)) : + (∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv d).injective.eq_iff,palindromePerm_coordinates] + rfl + +lemma routingMoment_step (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (d+1)) (a : ℝ) : + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + routingMoment (d+1) e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + rw [routingMoment,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have he (ω : BenesCoins d × BenesCoins d) : + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, palindromePerm (d+1) ((benesStepEquiv d).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((palindromeCost (d+1) e ((benesStepEquiv d).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((assignmentCost d x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => palindromePerm d (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [palindrome_matches_step,palindromeCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma child_moment_product (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold routingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, palindromePerm d ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, palindromePerm d ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => palindromePerm d (if b then ω.2 else ω.1)) = + (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma palindrome_probability_step (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (d+1)) : + PairRouting.tupleProbability (palindromePerm (d+1)) e f = + finiteMean (fun ω : BenesCoins d × BenesCoins d => + finiteMean (fun coins : (Card d → Bool) × (Card d → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then palindromePerm d ω.2 else palindromePerm d ω.1) + ((e.trans (headTailEquiv d).toEmbedding) i) = ((f.trans (headTailEquiv d).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + rw [PairRouting.tupleProbability,finiteMean_equiv (benesStepEquiv d),finiteMean_prod] + have hp (b : Bool) (p q : BenesCoins d) : + palindromePerm d (if b then p else q) = (if b then palindromePerm d p else palindromePerm d q) := by + cases b <;> rfl + simp only [palindrome_matches_step,hp] + +lemma child_power_product_bound (d : ℕ) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = false}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card {i // c i = true}*a) * + routingMoment d (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (by positivity) (routingMoment_nonneg _ _ _ _)) + rw [mul_mul_mul_comm,child_moment_product,←Real.rpow_add (by norm_num : (0:ℝ)<2)] at hh + have he : -(d:ℝ)*Fintype.card {i // c i = false}*a + -(d:ℝ)*Fintype.card {i // c i = true}*a = + -(d:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + rwa [he] at hh + +lemma assignment_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card d) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((assignmentCost d x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : BenesCoins d × BenesCoins d → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => palindromePerm d (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => palindromePerm d (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((palindromeCost d (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + palindromeCost d (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),assignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + +theorem palindrome_pointwise_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (palindromePerm d) e f)^(1+a) ≤ + (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := by + classical + induction d generalizing ι with + | zero => + have he : ∀ (ω : BenesCoins 0) (i : ι), palindromePerm 0 ω (e i) = f i := + fun _ _ => Subsingleton.elim _ _ + simp [PairRouting.tupleProbability,routingMoment,he,palindromeCost,finiteMean_const] + | succ d ih => + let x := e.trans (headTailEquiv d).toEmbedding + let y := f.trans (headTailEquiv d).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (palindromePerm d) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : BenesCoins d × BenesCoins d => + if PairRouting.ChildMatches (fun b => palindromePerm d (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((assignmentCost d x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + have h₁ := ih (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + have hh := child_power_product_bound d x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + exact hh'.trans (assignment_moment_bound d x y c.val c.property a ha) + have hnode := PairRouting.sandwich_power_bound (palindromePerm d) (palindromePerm d) x y a ha + rw [←palindrome_probability_step d e f] at hnode + change (PairRouting.tupleProbability (palindromePerm (d+1)) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * ((2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * ∑ c, m c) = + (2:ℝ)^(-((d:ℝ)+1)*Fintype.card ι*a) * (W * ∑ c, m c) + ring + +lemma routingMoment_sum (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : + (∑ f : ι ↪ Card d, routingMoment d e f a) = + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + unfold routingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card d := e.trans (palindromePerm d ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, palindromePerm d ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, palindromePerm d ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +lemma finite_row_power {X : Type*} [Fintype X] [Nonempty X] + (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) (a : ℝ) : + finiteMean (fun x => ((Fintype.card X:ℝ)*p x)^(1+a)) = + (Fintype.card X:ℝ)^a * ∑ x, (p x)^(1+a) := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + simp only [finiteMean,Real.mul_rpow (le_of_lt hn) (hp _),←Finset.mul_sum] + rw [Real.rpow_add hn,Real.rpow_one] + field_simp + +noncomputable def palindromeRowMoment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card d => + ((Fintype.card (ι ↪ Card d):ℝ)*PairRouting.tupleProbability (palindromePerm d) e f)^(1+a)) + +lemma density_normalization (d h n : ℕ) (a : ℝ) : + (n:ℝ)^a * (2:ℝ)^(-(d:ℝ)*h*a) = ((n:ℝ)/((2:ℝ)^d)^h)^a := by + rw [Real.div_rpow (Nat.cast_nonneg _) (by positivity),←pow_mul, + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2),Nat.cast_mul] + rw [show -(d:ℝ)*h*a = -((d:ℝ)*h*a) by ring, + Real.rpow_neg (by norm_num : (0:ℝ) ≤ 2),div_eq_mul_inv] + +theorem palindrome_row_density_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) (ha : 0 ≤ a) : + palindromeRowMoment d e a ≤ + (((2^d).descFactorial (Fintype.card ι):ℝ)/((2^d:ℕ):ℝ)^(Fintype.card ι))^a * + finiteMean (fun ω : BenesCoins d => (2:ℝ)^((palindromeCost d e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card d) := ⟨e⟩ + rw [palindromeRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card d):ℝ)^a * + ∑ f : ι ↪ Card d, (2:ℝ)^(-(d:ℝ)*Fintype.card ι*a) * routingMoment d e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => palindrome_pointwise_moment d e f a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,routingMoment_sum,←mul_assoc,density_normalization, + Fintype.card_embedding_eq,card_positions] + norm_cast + +end Thorp +namespace Thorp + +lemma subset_biUnion_indicator {α β : Type*} [DecidableEq α] [Fintype β] + (A : Finset α) (T : β → Finset α) : + (if Finset.univ.biUnion T ⊆ A then (1:ℝ) else 0) = + ∏ b, if T b ⊆ A then (1:ℝ) else 0 := by + classical + by_cases h : Finset.univ.biUnion T ⊆ A + · rw [ite_eq_left h] + symm + apply Finset.prod_eq_one + intro b _ + rw [ite_eq_left] + exact (Finset.subset_biUnion_of_mem T (Finset.mem_univ b)).trans h + · rw [ite_eq_right h] + obtain ⟨x,hx,hxA⟩ := Finset.not_subset.mp h + obtain ⟨b,_,hxb⟩ := Finset.mem_biUnion.mp hx + symm + apply Finset.prod_eq_zero (Finset.mem_univ b) + rw [ite_eq_right] + exact fun hb => hxA (hb hxb) + +lemma cylinder_block_polynomial {α β Ω : Type*} [DecidableEq α] [Fintype β] + [Fintype Ω] (τ : β → Type*) [∀ b, Fintype (τ b)] + (F : Ω → Finset α) (p : α → ℝ) + (hF : CylinderBound (inclusionMoment F) p) + (T : ∀ b, τ b → Finset α) (c : ∀ b, τ b → ℝ) + (hc : ∀ b s, 0 ≤ c b s) + (hd : ∀ b b', b ≠ b' → ∀ s s', Disjoint (T b s) (T b' s')) : + finiteMean (fun ω => ∏ b, ∑ s, c b s * if T b s ⊆ F ω then 1 else 0) ≤ + ∏ b, ∑ s, c b s * ∏ x ∈ T b s, p x := by + classical + simp_rw [Fintype.prod_sum] + rw [finiteMean_sum] + apply Finset.sum_le_sum + intro s _ + let U := Finset.univ.biUnion (fun b => T b (s b)) + have he : (fun ω => ∏ b, c b (s b) * if T b (s b) ⊆ F ω then 1 else 0) = + fun ω => (if U ⊆ F ω then 1 else 0) * ∏ b, c b (s b) := by + funext ω + rw [Finset.prod_mul_distrib,←subset_biUnion_indicator] + exact mul_comm _ _ + rw [he,finiteMean_mul_const] + have hdis : ((Finset.univ : Finset β) : Set β).PairwiseDisjoint (fun b => T b (s b)) := by + intro b _ b' _ hbb + exact hd b b' hbb (s b) (s b') + have hmean : finiteMean (fun ω => if U ⊆ F ω then 1 else 0) = inclusionMoment F U := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + by_cases hh : U ⊆ F ω <;> simp [hh] + calc + _ ≤ (∏ x ∈ U, p x) * ∏ b, c b (s b) := + mul_le_mul_of_nonneg_right (hmean.le.trans (hF U)) (Finset.prod_nonneg (fun b _ => hc b (s b))) + _ = _ := by + dsimp only [U] + rw [Finset.prod_biUnion hdis,←Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro b _ + exact mul_comm _ _ + + +noncomputable def sparseCoefficient {α : Type*} (w : ℝ) (T : Finset α) : ℝ := + if T.card = 1 then 0 else w^T.card + +lemma sparseCoefficient_nonneg {α : Type*} (w : ℝ) (hw : 0 ≤ w) (T : Finset α) : + 0 ≤ sparseCoefficient w T := by + unfold sparseCoefficient + split_ifs <;> positivity + +lemma sparse_block_pointwise {α : Type*} [DecidableEq α] (A D : Finset α) + (w : ℝ) (hw : 0 ≤ w) : + w^(if 2 ≤ (D ∩ A).card then (D ∩ A).card else 0) ≤ + ∑ T : ↑D.powerset, sparseCoefficient w T.val * if T.val ⊆ A then 1 else 0 := by + classical + let V := D ∩ A + let T : ↑D.powerset := if 2 ≤ V.card then + ⟨V,Finset.mem_powerset.mpr Finset.inter_subset_left⟩ else + ⟨∅,Finset.mem_powerset.mpr (Finset.empty_subset D)⟩ + calc + _ = sparseCoefficient w T.val * (if T.val ⊆ A then 1 else 0) := by + by_cases h : 2 ≤ V.card + · have hn : V.card ≠ 1 := by omega + simp [T,ite_eq_left h,sparseCoefficient,hn,show V ⊆ A from Finset.inter_subset_right,V] + · simp [T,ite_eq_right h,sparseCoefficient,V] at * + _ ≤ _ := Finset.single_le_sum (f := fun S : ↑D.powerset => + sparseCoefficient w S.val * (if S.val ⊆ A then 1 else 0)) + (fun S _ => mul_nonneg (sparseCoefficient_nonneg w hw S.val) + (by split_ifs <;> norm_num)) (Finset.mem_univ T) + +lemma geometric_sum_half (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hhalf : x ≤ 1/2) : + ∑ i ∈ Finset.range n, x^i ≤ 2 := by + induction n with + | zero => simp + | succ n ih => + rw [Finset.sum_range_succ',pow_zero] + simp only [pow_succ',←Finset.mul_sum] + nlinarith + +lemma sparse_binomial_bound (R : ℕ) (z : ℝ) (hz : 0 ≤ z) (hr : (R:ℝ)*z ≤ 1/2) : + ∑ i ∈ Finset.range (R+1), (R.choose i:ℝ) * (if i = 1 then 0 else z^i) ≤ + 1 + 2*((R:ℝ)*z)^2 := by + classical + let x := (R:ℝ)*z + have hx : 0 ≤ x := mul_nonneg (Nat.cast_nonneg _) hz + have hbound (i : ℕ) : (R.choose i:ℝ)*(if i=1 then 0 else z^i) ≤ + if i=1 then 0 else x^i := by + by_cases h : i=1 + · simp [h] + · simp only [ite_eq_right h] + dsimp [x] + rw [mul_pow] + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hz i) + exact_mod_cast Nat.choose_le_pow R i + calc + _ ≤ ∑ i ∈ Finset.range (R+1), if i=1 then 0 else x^i := + Finset.sum_le_sum (fun i _ => hbound i) + _ ≤ 1+2*x^2 := by + rcases R with _ | R + · simp [x] + rcases R with _ | R + · norm_num [Finset.sum_range_succ] + positivity + have he : ∑ i ∈ Finset.range (R+2+1), (if i=1 then 0 else x^i) = + 1 + x^2*∑ i ∈ Finset.range (R+1), x^i := by + rw [show R+2+1=2+(R+1) by omega,Finset.sum_range_add] + have hn (i : ℕ) : 2+i ≠ 1 := by omega + simp only [hn,ite_false,pow_add,←Finset.mul_sum] + norm_num [Finset.sum_range_succ] + rw [he] + have hg := geometric_sum_half (R+1) hx hr + nlinarith [sq_nonneg x] + +lemma sparse_block_product_bound {α : Type*} [DecidableEq α] + (D : Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hr : (D.card:ℝ)*(p*w) ≤ 1/2) : + ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card ≤ + Real.exp (2*((D.card:ℝ)*(p*w))^2) := by + classical + have he : ∑ T : ↑D.powerset, sparseCoefficient w T.val * p^T.val.card = + ∑ i ∈ Finset.range (D.card+1), (D.card.choose i:ℝ)*(if i=1 then 0 else (p*w)^i) := by + rw [Finset.sum_coe_sort D.powerset (fun T => sparseCoefficient w T*p^T.card)] + have hh : (fun T : Finset α => sparseCoefficient w T*p^T.card) = + fun T => if T.card=1 then 0 else (p*w)^T.card := by + funext T + unfold sparseCoefficient + split_ifs <;> simp [mul_pow,mul_comm] + change (∑ T ∈ D.powerset, (fun T : Finset α => sparseCoefficient w T*p^T.card) T) = _ + rw [hh,Finset.sum_powerset_apply_card (fun i => if i=1 then (0:ℝ) else (p*w)^i)] + simp only [nsmul_eq_mul] + rw [he] + exact (sparse_binomial_bound D.card (p*w) (mul_nonneg hp hw) hr).trans + (by simpa only [add_comm] using Real.add_one_le_exp (2*((D.card:ℝ)*(p*w))^2)) + + +noncomputable def sparseMass {α β : Type*} [DecidableEq α] [Fintype β] + (D : β → Finset α) (A : Finset α) : ℕ := + ∑ b, if 2 ≤ (D b ∩ A).card then (D b ∩ A).card else 0 + +theorem sparse_block_mgf {α β Ω : Type*} [DecidableEq α] [Fintype β] [Fintype Ω] + (D : β → Finset α) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (F : Ω → Finset α) (p w : ℝ) (hp : 0 ≤ p) (hw : 0 ≤ w) + (hF : ∀ T, inclusionMoment F T ≤ p^T.card) + (hr : ∀ b, ((D b).card:ℝ)*(p*w) ≤ 1/2) : + finiteMean (fun ω => w^(sparseMass D (F ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*(p*w))^2) := by + classical + have hc : CylinderBound (inclusionMoment F) (fun _ => p) := by + intro T + simpa only [Finset.prod_const] using hF T + have hb := cylinder_block_polynomial (fun b => ↑(D b).powerset) F (fun _ => p) hc + (fun _ S => S.val) (fun _ S => sparseCoefficient w S.val) + (fun _ S => sparseCoefficient_nonneg w hw S.val) + (fun b b' h S S' => (hd h).mono + (Finset.mem_powerset.mp S.property) (Finset.mem_powerset.mp S'.property)) + calc + _ ≤ finiteMean (fun ω => ∏ b, ∑ S : ↑(D b).powerset, + sparseCoefficient w S.val * if S.val ⊆ F ω then 1 else 0) := by + apply finiteMean_mono + intro ω + rw [sparseMass,←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hw _) + intro b _ + exact sparse_block_pointwise (F ω) (D b) w hw + _ ≤ ∏ b, ∑ S : ↑(D b).powerset, sparseCoefficient w S.val * p^S.val.card := by + simpa only [Finset.prod_const] using hb + _ ≤ _ := by + rw [Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro b _ + exact Finset.sum_nonneg (fun S _ => mul_nonneg + (sparseCoefficient_nonneg w hw S.val) (pow_nonneg hp _)) + · intro b _ + exact sparse_block_product_bound (D b) p w hp hw (hr b) + +theorem inverseButterfly_sparse_mgf (d : ℕ) {β : Type*} [Fintype β] + (D : β → Finset (Card d)) (hd : Pairwise (fun b b' => Disjoint (D b) (D b'))) + (A : Finset (Card d)) (w : ℝ) (hw : 0 ≤ w) + (hr : ∀ b, ((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w) ≤ 1/2) : + finiteMean (fun ω : SwitchIndex d → Bool => + w^(sparseMass D (inverseButterflyMarks d A ω))) ≤ + Real.exp (∑ b, 2*(((D b).card:ℝ)*((A.card/(2:ℝ)^d)*w))^2) := by + apply sparse_block_mgf D hd (inverseButterflyMarks d A) (A.card/(2:ℝ)^d) w + (by positivity) hw + · exact inverseButterflyMarks_inclusion d A + · exact hr + + +def crowdedMass (h : ℕ) : ℕ := if 2 ≤ h then h else 0 + +lemma crowdedMass_le (h : ℕ) : crowdedMass h ≤ h := by + unfold crowdedMass + split_ifs <;> omega + +lemma crowdedMass_add (u v : ℕ) : crowdedMass u + crowdedMass v ≤ crowdedMass (u+v) := by + unfold crowdedMass + split_ifs <;> omega + +lemma alternatingCycles_le_crowded {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ crowdedMass (Fintype.card ι) := by + unfold crowdedMass + split_ifs with h + · have hh := PairRouting.alternatingCycles_double e p + omega + · rw [PairRouting.alternatingCycles_zero e p (by omega)] + +lemma palindromeCost_le_crowded (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeCost d e ω ≤ d*crowdedMass (Fintype.card ι) := by + classical + induction d generalizing ι with + | zero => simp [palindromeCost] + | succ d ih => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + have h₀ := ih (PairRouting.childEmbedding x c hc false) σ.1.1 + have h₁ := ih (PairRouting.childEmbedding x c hc true) σ.1.2 + have hz := alternatingCycles_le_crowded (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + have hs := crowdedMass_add (Fintype.card {i // c i = false}) + (Fintype.card {i // c i = true}) + rw [PairRouting.color_card_add] at hs + change PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) + + palindromeCost d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeCost d (PairRouting.childEmbedding x c hc true) σ.1.2 ≤ _ + nlinarith + +noncomputable def palindromeLowCost (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if d+1 ≤ H then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLowCost H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLowCost H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def cutoffMass (H : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, ι, _, e, ω => + if d+1 ≤ H then crowdedMass (Fintype.card ι) else + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + cutoffMass H d (PairRouting.childEmbedding x c hc false) σ.1.1 + + cutoffMass H d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLowCost_eq (H d : ℕ) (h : d ≤ H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = palindromeCost d e ω := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLowCost,palindromeCost,ite_eq_left h] + congr 2 <;> exact ih (by omega) _ _ + +lemma palindromeLowCost_le_cutoff (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω ≤ H*cutoffMass H d e ω := by + classical + induction d generalizing ι with + | zero => simp [palindromeLowCost,cutoffMass] + | succ d ih => + by_cases h : d+1 ≤ H + · rw [palindromeLowCost_eq H (d+1) h,cutoffMass,ite_eq_left h] + exact (palindromeCost_le_crowded (d+1) e ω).trans (Nat.mul_le_mul_right _ h) + · rw [palindromeLowCost,cutoffMass,ite_eq_right h,ite_eq_right h,zero_add,Nat.mul_add] + exact Nat.add_le_add (ih _ _) (ih _ _) + + +noncomputable def centralBlock (r H : ℕ) (b : Card r) : Finset (Card (H+r)) := + Finset.univ.image (fun z : Card H => (cardSplit r H).symm (b,z)) + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/BlockProduct.lean b/lean/OAI/Probability/ThorpRouting/Tail/BlockProduct.lean index d1e0e59e196042fb39ebf75aaf74823ef9bb9a8c..8ec586b2d81b7193ef52579686688dae2aa35f43 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/BlockProduct.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/BlockProduct.lean @@ -1,894 +1,894 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.Representative - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by - induction s using Finset.induction_on with - | empty => - simp only [Finset.powerset_empty,Finset.sum_singleton] - exact Finset.noncommProd_empty _ _ - | @insert a s ha ih => - rw [Finset.sum_powerset_insert ha] - have h₁ (E : Finset ι) (hE : E∈s.powerset) : - sector P hcomm (insert a s) E=P a*sector P hcomm s E := by - rw [sector_insert P hcomm s E a ha] - congr 1 - exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) - have h₂ (E : Finset ι) (_hE : E∈s.powerset) : - sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by - rw [sector_insert P hcomm s (insert a E) a ha] - simp only [choice,Finset.mem_insert_self,↓reduceIte] - congr 1 - apply sector_congr - intro i hi - simp [ne_of_mem_of_not_mem hi ha] - rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, - ←Finset.mul_sum,←Finset.mul_sum,ih] - simp - -omit [Fintype ι] in -lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) - (hP : ∀ i, IsStarProjection (P i)) : - choice P E i*sector P hcomm s E=sector P hcomm s E := by - have hc : IsIdempotentElem (choice P E i) := by - unfold choice - split_ifs - · exact (hP i).one_sub.isIdempotentElem - · exact (hP i).isIdempotentElem - have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) - (fun i _ j _ _ => choice_commute P hcomm E E i j) - change choice P E i*sector P hcomm s E=sector P hcomm s E - change _=sector P hcomm s E at hsplit - nth_rw 1 [←hsplit] - rw [←mul_assoc,hc.eq,hsplit] - -omit [Fintype ι] in -lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) - (hP : ∀ i, IsStarProjection (P i)) : - sector P hcomm s E*sector P hcomm s F=0 := by - have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by - by_contra h - push Not at h - exact hEF (Finset.ext fun i => by - by_cases hi : i∈s - · exact h i hi - · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) - obtain ⟨i,hi,hdiff⟩ := hdiff - have hz : choice P E i*choice P F i=0 := by - by_cases he : i∈E <;> by_cases hf : i∈F - · exact (hdiff (iff_of_true he hf)).elim - · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self - · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self - · exact (hdiff (iff_of_false he hf)).elim - have hEi := sector_absorb_factor P hcomm s E i hi hP - have hFi := sector_absorb_factor P hcomm s F i hi hP - calc - _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by - simp only [mul_assoc] - rw [hFi] - rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] - _ = 0 := by rw [hz,mul_zero,zero_mul] - -noncomputable def blockProduct (A : ι → V →L[ℂ] V) - (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := - s.noncommProd A (fun i _ j _ _ => hA i j) - -omit hcomm [Fintype ι] in -lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by - induction s using Finset.induction_on with - | empty => exact ContinuousLinearMap.norm_id_le - | @insert a s ha ih => - have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,Finset.prod_insert ha] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) - -noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := - blockProduct A hA Finset.univ - -omit hcomm in -lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := - (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) - -omit [CompleteSpace V] in -lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : - Commute (blocks A hA) (sector P hcomm Finset.univ E) := by - unfold blocks blockProduct - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm - intro i _ - unfold sector - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm - intro j _ - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - -lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : - ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by - have hAC (i j : ι) : Commute (A i) (choice P E j) := by - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) - (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) - (fun i _ j _ _ => (hAC j i).symm) - change _=blocks A hA*sector P hcomm Finset.univ E at hprod - rw [←hprod] - have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := - ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) - apply (norm_noncommProd_le _ hc Finset.univ).trans - calc - _ ≤ ∏ i : ι, if i∈E then θ else 1 := by - apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) - intro i _ - dsimp only [Pi.mul_apply] - unfold choice - split_ifs with hi - · exact hgap i - · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) - _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] - -noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := - Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) - -lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - IsStarProjection (coarse P hcomm E) := by - have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by - apply Finset.noncommProd_congr rfl - intro i _ - simp [choice] - rw [he] - exact sector_projection P hcomm hP _ _ - -lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by - have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by - have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP - rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h - simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h - have hp (s : Finset ι) (hs : ∀ i∈s, - sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : - sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by - induction s using Finset.induction_on with - | empty => exact mul_one _ - | @insert a s ha ih => - have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] - exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) - exact hp Eᶜ hpi - -theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) - (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : - ‖B.adjoint*blocks A hA*B‖≤θ^n+ - ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) - (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) - hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) - (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) - (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all - -lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - ‖sampleOperator ρ P‖≤1 := by - rw [sampleOperator_weighted] - exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) - -omit [Fintype G] in -lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : - sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by - simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] - rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] - -omit [Fintype G] in -lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by - simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, - Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - apply Finset.sum_congr rfl - intro ξ _ - rw [mul_comm] - -omit [Fintype G] in -lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by - simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, - continuousRepresentation_adjoint ρ hρ] - -lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - (hρ : IsUnitary ρ) : - sampleOperator ρ (palindromePerm d)= - sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* - (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by - rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] - rfl - -omit [Fintype G] in -lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : - sampleOperator ρ (fun _ : Ω => 1)=1 := by - simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, - smul_smul] - rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by - simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, - Finset.smul_sum,id_eq] - -lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by - rw [sampleOperator_prod] - have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by - rw [←sampleOperator_uniform] - exact sampleOperator_equiv ρ id (Equiv.inv G) - rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteAverage -open scoped BigOperators Classical -variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] - [Ring A] [Algebra ℂ A] - -noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := - MultilinearMap.domDomCongr (Fintype.equivFin I).symm - (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) - -lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : - orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by - unfold orderedProduct - rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] - let l := List.ofFn (Fintype.equivFin I).symm - have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective - have hu : l.toFinset=Finset.univ := by - ext i - simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] - exact (Fintype.equivFin I).symm.surjective i - have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl - rw [hu] at he - rw [he] - congr 1 - exact List.map_ofFn.symm - -lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : - F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by - rw [F.map_smul_univ,F.map_sum] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] - -lemma ordered_average (x : I → Ω → A) - (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) - (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : - (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - (fun _ _ _ _ hij => havg hij))= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, - Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by - rw [←orderedProduct_eq _ havg,multilinear_average] - simp only [orderedProduct_eq _ (hc _)] - -end Thorp.FiniteAverage -namespace Thorp.FiniteCharacters -open Module -open scoped BigOperators Classical - -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) -include hneq hcard - -lemma character_expansion (f : ConjClasses G → ℂ) : - f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases h : i=j - · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] - · rw [ite_eq_right h,ite_eq_right (hneq i j h)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij; exact (horth i j).trans (ite_eq_right hij) - · intro i; simpa using horth i i - have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) - have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ - have hd (i : ι) : b.coord i=characterDual (ρ i) := by - apply b.ext - intro j - rw [hb,horth] - simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] - split_ifs <;> simp_all - have h := b.sum_repr f - simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm - -theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by - let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 - have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by - simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] - have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by - change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ - simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, - Representation.char_one,Nat.card_eq_fintype_card] - have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) - rw [hf,ite_eq_left rfl] at he - simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he - have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by - calc - _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * - (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - field_simp - _ = _ := by rw [←he,mul_one] - exact_mod_cast hs - -end Thorp.FiniteCharacters - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] - [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] - [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : - averageMap ρ σ A=0 := by - rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h - · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim - · exact h - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) - (u z : W) (v w : V) : - ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by - have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap - have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he - change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv - simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] - -def regularAction : G →* Equiv.Perm G where - toFun := Equiv.mulLeft - map_one' := by ext; simp - map_mul' _ _ := by ext; simp - -omit [Fintype G] in -lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by - intro g hg - have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg - subst g - simp - -noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := - normalizedCoefficient regularAction 1 regular_transitive ρ w v - -omit [FiniteDimensional ℂ V] in -lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : - regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by - unfold regularCoefficient normalizedCoefficient - simp only [PiLp.smul_apply,smul_eq_mul] - congr 1 - have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g - simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he - -lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (w z v t : V) : - inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := - normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z - (regular_fixed ρ w) (regular_fixed ρ z) v t - -variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) - (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, - inner_conj_symm] - have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z - calc - _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* - (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * - ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - _ = 0 := by rw [he,mul_zero] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteFourier -open scoped BigOperators ComplexConjugate Classical -open UnitaryFinite -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hρ : ∀ i, IsUnitary (ρ i)) -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) - - -abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) - -noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := - regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) - -omit [Fintype ι] in -include hρ hneq in -lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by - rw [orthonormal_iff_ite] - rintro ⟨i,a,b⟩ ⟨j,c,d⟩ - dsimp only [coefficientFamily] - by_cases hij : i=j - · subst j - rw [regularCoefficient_inner _ (hρ i)] - simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] - by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] - · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] - rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] - -include ρ hneq hcard in -lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by - simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] - exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard - -noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := - OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) - (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' - (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) - -lemma coefficientBasis_apply (a : CoefficientIndex V) : - coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a - -include hρ hneq hcard in - -theorem parseval (f : EuclideanSpace ℂ G) : - ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by - simpa only [coefficientBasis_apply] using - (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f - - -noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : - inner ℂ (coefficientFamily V ρ a) (realVector p)= - (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* - inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by - simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, - RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, - weightedOperator,sum_apply,smul_apply, - continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : - ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= - ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* - ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by - rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, - abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] - -include hρ hneq hcard in -lemma parseval_operator (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2= - ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←parseval V ρ hρ hneq hcard (realVector p)] - simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] - have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - have he (a : Fin (Module.finrank ℂ (V i))) : - (∑ b : Fin (Module.finrank ℂ (V i)), - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) - (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] - simp_rw [he] - rw [←Finset.mul_sum] - field_simp - -include hρ hneq hcard in -lemma realVector_bound (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2≤ - ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - rw [parseval_operator V ρ hρ hneq hcard] - apply Finset.sum_le_sum - intro i _ - calc - _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - apply Finset.sum_le_sum - intro a _ - apply pow_le_pow_left₀ (norm_nonneg _) - simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using - (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring - -include hρ hneq hcard in - -theorem l1_fourier_bound (p : G → ℝ) : - (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) - have he : ‖realVector p‖^2=∑ g,|p g|^2 := by - rw [EuclideanSpace.norm_sq_eq] - simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] - rw [he] - simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) - -end Thorp.FiniteFourier - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -variable {B X : Type*} - -def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where - toFun p := - { toFun := fun x => (x.1,p x.1 x.2) - invFun := fun x => (x.1,(p x.1).symm x.2) - left_inv := fun x => by simp - right_inv := fun x => by simp } - map_one' := rfl - map_mul' _ _ := rfl - -@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl - -noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := - lift.comp - { toFun := fun p c => if c=b then p else 1 - map_one' := by funext c; simp - map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } - -@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : - injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by - simp only [injection,MonoidHom.comp_apply,lift_apply] - by_cases h : x.1=b <;> simp [h] - -lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : - Commute (injection b p) (injection c q) := by - apply Equiv.ext - intro x - simp only [Equiv.Perm.mul_apply,injection_apply] - by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all - -variable [Fintype B] - -lemma lift_product (p : B → Equiv.Perm X) : - lift p=Finset.univ.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := by - have he (s : Finset B) (x : B × X) : - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) x= - (x.1,if x.1∈s then p x.1 x.2 else x.2) := by - induction s using Finset.induction_on with - | empty => - have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ - rw [hz]; simp - | @insert a s ha ih => - have hz : (insert a s).noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* - s.noncommProd (fun b => injection b (p b)) - (fun _ _ _ _ h => injection_commute h _ _) := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] - by_cases h : x.1=a - · subst a; simp [ha] - · simp [h] - apply Equiv.ext - intro x - rw [he] - simp - -end Thorp.ParallelBlocks -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H : Type*} [Group G] [Group H] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : - continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl - -lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : - sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl - -omit [FiniteDimensional ℂ V] in -lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : - IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w - -lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) - (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : - Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by - unfold sampleOperator - apply Commute.smul_left - apply Commute.smul_right - apply Commute.sum_left - intro ω _ - apply Commute.sum_right - intro ξ _ - exact (h ω ξ).map (continuousRepresentation ρ) - -lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] - (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by - rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end Thorp.UnitaryFinite -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype B] [DecidableEq B] in -lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) - (sampleOperator (ρ.comp (injection c)) (P c)) := by - by_cases h : b=c - · subst c; exact Commute.refl _ - · rw [sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) - (P : B → Ω → Equiv.Perm X) : - sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= - CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) - (local_average_commute ρ P) := by - let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) - have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by - intro ω b c h - exact (injection_commute h _ _).map (continuousRepresentation ρ) - have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by - intro b c _ - exact local_average_commute ρ P b c - have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= - Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by - rw [lift_product] - exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) - unfold sampleOperator - simp_rw [he] - exact (FiniteAverage.ordered_average A hc havg).symm - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical - -noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := - (cardSplit r L).permCongrHom - -noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : - Equiv.Perm (Card r × Card L) := - (Equiv.prodComm (Card L) (Card r)).permCongrHom - (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) - -lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : - outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl - -lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= - outerPerm r L hi*ParallelBlocks.lift - (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by - apply Equiv.ext - intro x - change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) - ((cardSplit r L).symm x))=_ - rw [butterfly_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r+1) → Bool) : - boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) - (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by - conv_lhs => unfold boundaryTree - congr 1 - funext b - cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : - boundaryOutput L (r+1) Y b= - boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by - conv_lhs => unfold boundaryOutput - cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl - -lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : - cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= - let y := cardSplit r L x - let z := U y.1 y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) - have hh := ih U' lo' hi' (Fin.tail x) - let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) - let y := cardSplit r L (Fin.tail x) - let z := U' y.1 y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r L u=(w,z) at hh - rw [boundaryTree_node_raw] - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) - ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : - splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= - outerPerm r L hi*ParallelBlocks.lift U := by - apply Equiv.ext - intro x - change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm - ((cardSplit r L).symm x))=_ - rw [boundaryTree_split,Equiv.apply_symm_apply] - rfl - -lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) - (hi : Card L × SwitchIndex r → Bool) (b : Card r) : - boundaryOutput L r (assembleBits r L lo hi) b= - butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by - induction r with - | zero => - rw [Subsingleton.elim b (fun j => Fin.elim0 j)] - rfl - | succ r ih => - rw [boundaryOutput_node_raw] - change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ - rw [ih] - simp only [Fin.cons_self_tail] - - -abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool -abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool - -def parallelSplitCoinEquiv (r L : ℕ) : - ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := - (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans - (splitCoinEquiv r L) - -lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : - parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by - exact splitCoinEquiv_apply _ _ _ _ - -def pairAssembleEquiv (B C H : Type*) : - ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where - toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) - invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) - left_inv _w := rfl - right_inv _w := rfl - -def palindromeStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := - (pairAssembleEquiv _ _ _).trans - (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) - -lemma palindromeStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - palindromeStageEquiv r L w= - (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by - simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] - -def modifiedAssembleEquiv (B C H U : Type*) : - ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where - toFun w := ((fun b => (w.1.2 b).1), - (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) - invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) - left_inv _w := rfl - right_inv _w := rfl - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.Representative + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by + induction s using Finset.induction_on with + | empty => + simp only [Finset.powerset_empty,Finset.sum_singleton] + exact Finset.noncommProd_empty _ _ + | @insert a s ha ih => + rw [Finset.sum_powerset_insert ha] + have h₁ (E : Finset ι) (hE : E∈s.powerset) : + sector P hcomm (insert a s) E=P a*sector P hcomm s E := by + rw [sector_insert P hcomm s E a ha] + congr 1 + exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) + have h₂ (E : Finset ι) (_hE : E∈s.powerset) : + sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by + rw [sector_insert P hcomm s (insert a E) a ha] + simp only [choice,Finset.mem_insert_self,↓reduceIte] + congr 1 + apply sector_congr + intro i hi + simp [ne_of_mem_of_not_mem hi ha] + rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, + ←Finset.mul_sum,←Finset.mul_sum,ih] + simp + +omit [Fintype ι] in +lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) + (hP : ∀ i, IsStarProjection (P i)) : + choice P E i*sector P hcomm s E=sector P hcomm s E := by + have hc : IsIdempotentElem (choice P E i) := by + unfold choice + split_ifs + · exact (hP i).one_sub.isIdempotentElem + · exact (hP i).isIdempotentElem + have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) + (fun i _ j _ _ => choice_commute P hcomm E E i j) + change choice P E i*sector P hcomm s E=sector P hcomm s E + change _=sector P hcomm s E at hsplit + nth_rw 1 [←hsplit] + rw [←mul_assoc,hc.eq,hsplit] + +omit [Fintype ι] in +lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) + (hP : ∀ i, IsStarProjection (P i)) : + sector P hcomm s E*sector P hcomm s F=0 := by + have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by + by_contra h + push Not at h + exact hEF (Finset.ext fun i => by + by_cases hi : i∈s + · exact h i hi + · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) + obtain ⟨i,hi,hdiff⟩ := hdiff + have hz : choice P E i*choice P F i=0 := by + by_cases he : i∈E <;> by_cases hf : i∈F + · exact (hdiff (iff_of_true he hf)).elim + · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self + · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self + · exact (hdiff (iff_of_false he hf)).elim + have hEi := sector_absorb_factor P hcomm s E i hi hP + have hFi := sector_absorb_factor P hcomm s F i hi hP + calc + _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by + simp only [mul_assoc] + rw [hFi] + rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] + _ = 0 := by rw [hz,mul_zero,zero_mul] + +noncomputable def blockProduct (A : ι → V →L[ℂ] V) + (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := + s.noncommProd A (fun i _ j _ _ => hA i j) + +omit hcomm [Fintype ι] in +lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by + induction s using Finset.induction_on with + | empty => exact ContinuousLinearMap.norm_id_le + | @insert a s ha ih => + have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,Finset.prod_insert ha] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) + +noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := + blockProduct A hA Finset.univ + +omit hcomm in +lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := + (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) + +omit [CompleteSpace V] in +lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : + Commute (blocks A hA) (sector P hcomm Finset.univ E) := by + unfold blocks blockProduct + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm + intro i _ + unfold sector + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm + intro j _ + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + +lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : + ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by + have hAC (i j : ι) : Commute (A i) (choice P E j) := by + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) + (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) + (fun i _ j _ _ => (hAC j i).symm) + change _=blocks A hA*sector P hcomm Finset.univ E at hprod + rw [←hprod] + have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := + ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) + apply (norm_noncommProd_le _ hc Finset.univ).trans + calc + _ ≤ ∏ i : ι, if i∈E then θ else 1 := by + apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) + intro i _ + dsimp only [Pi.mul_apply] + unfold choice + split_ifs with hi + · exact hgap i + · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) + _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] + +noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := + Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) + +lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + IsStarProjection (coarse P hcomm E) := by + have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by + apply Finset.noncommProd_congr rfl + intro i _ + simp [choice] + rw [he] + exact sector_projection P hcomm hP _ _ + +lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by + have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by + have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP + rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h + simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h + have hp (s : Finset ι) (hs : ∀ i∈s, + sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : + sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by + induction s using Finset.induction_on with + | empty => exact mul_one _ + | @insert a s ha ih => + have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] + exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) + exact hp Eᶜ hpi + +theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) + (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : + ‖B.adjoint*blocks A hA*B‖≤θ^n+ + ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) + (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) + hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) + (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) + (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card simp_all + +lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + ‖sampleOperator ρ P‖≤1 := by + rw [sampleOperator_weighted] + exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) + +omit [Fintype G] in +lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : + sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by + simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] + rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] + +omit [Fintype G] in +lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by + simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, + Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro ξ _ + rw [mul_comm] + +omit [Fintype G] in +lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by + simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, + continuousRepresentation_adjoint ρ hρ] + +lemma sampleOperator_palindrome (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + (hρ : IsUnitary ρ) : + sampleOperator ρ (palindromePerm d)= + sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))* + (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by + rw [←sampleOperator_inv ρ hρ,←sampleOperator_prod] + rfl + +omit [Fintype G] in +lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : + sampleOperator ρ (fun _ : Ω => 1)=1 := by + simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, + smul_smul] + rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by + simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, + Finset.smul_sum,id_eq] + +lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by + rw [sampleOperator_prod] + have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by + rw [←sampleOperator_uniform] + exact sampleOperator_equiv ρ id (Equiv.inv G) + rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteAverage +open scoped BigOperators Classical +variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] + [Ring A] [Algebra ℂ A] + +noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := + MultilinearMap.domDomCongr (Fintype.equivFin I).symm + (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) + +lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : + orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by + unfold orderedProduct + rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] + let l := List.ofFn (Fintype.equivFin I).symm + have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective + have hu : l.toFinset=Finset.univ := by + ext i + simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] + exact (Fintype.equivFin I).symm.surjective i + have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl + rw [hu] at he + rw [he] + congr 1 + exact List.map_ofFn.symm + +lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : + F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by + rw [F.map_smul_univ,F.map_sum] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] + +lemma ordered_average (x : I → Ω → A) + (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) + (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : + (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + (fun _ _ _ _ hij => havg hij))= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, + Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by + rw [←orderedProduct_eq _ havg,multilinear_average] + simp only [orderedProduct_eq _ (hc _)] + +end Thorp.FiniteAverage +namespace Thorp.FiniteCharacters +open Module +open scoped BigOperators Classical + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) +include hneq hcard + +lemma character_expansion (f : ConjClasses G → ℂ) : + f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases h : i=j + · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] + · rw [ite_eq_right h,ite_eq_right (hneq i j h)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij; exact (horth i j).trans (ite_eq_right hij) + · intro i; simpa using horth i i + have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) + have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ + have hd (i : ι) : b.coord i=characterDual (ρ i) := by + apply b.ext + intro j + rw [hb,horth] + simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] + split_ifs <;> simp_all + have h := b.sum_repr f + simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm + +theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by + let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 + have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by + simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] + have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by + change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ + simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, + Representation.char_one,Nat.card_eq_fintype_card] + have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) + rw [hf,ite_eq_left rfl] at he + simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he + have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by + calc + _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * + (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + field_simp + _ = _ := by rw [←he,mul_one] + exact_mod_cast hs + +end Thorp.FiniteCharacters + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] + [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] + [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : + averageMap ρ σ A=0 := by + rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h + · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim + · exact h + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) + (u z : W) (v w : V) : + ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by + have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap + have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he + change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv + simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] + +def regularAction : G →* Equiv.Perm G where + toFun := Equiv.mulLeft + map_one' := by ext; simp + map_mul' _ _ := by ext; simp + +omit [Fintype G] in +lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by + intro g hg + have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg + subst g + simp + +noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := + normalizedCoefficient regularAction 1 regular_transitive ρ w v + +omit [FiniteDimensional ℂ V] in +lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : + regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by + unfold regularCoefficient normalizedCoefficient + simp only [PiLp.smul_apply,smul_eq_mul] + congr 1 + have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g + simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he + +lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (w z v t : V) : + inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := + normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z + (regular_fixed ρ w) (regular_fixed ρ z) v t + +variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) + (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, + inner_conj_symm] + have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z + calc + _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* + (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * + ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + _ = 0 := by rw [he,mul_zero] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteFourier +open scoped BigOperators ComplexConjugate Classical +open UnitaryFinite +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hρ : ∀ i, IsUnitary (ρ i)) +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) + + +abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) + +noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := + regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) + +omit [Fintype ι] in +include hρ hneq in +lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by + rw [orthonormal_iff_ite] + rintro ⟨i,a,b⟩ ⟨j,c,d⟩ + dsimp only [coefficientFamily] + by_cases hij : i=j + · subst j + rw [regularCoefficient_inner _ (hρ i)] + simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] + by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] + · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] + rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] + +include ρ hneq hcard in +lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by + simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] + exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard + +noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := + OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) + (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' + (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) + +lemma coefficientBasis_apply (a : CoefficientIndex V) : + coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a + +include hρ hneq hcard in + +theorem parseval (f : EuclideanSpace ℂ G) : + ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by + simpa only [coefficientBasis_apply] using + (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f + + +noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : + inner ℂ (coefficientFamily V ρ a) (realVector p)= + (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* + inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by + simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, + RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, + weightedOperator,sum_apply,smul_apply, + continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : + ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= + ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* + ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by + rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] + +include hρ hneq hcard in +lemma parseval_operator (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2= + ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←parseval V ρ hρ hneq hcard (realVector p)] + simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] + have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + have he (a : Fin (Module.finrank ℂ (V i))) : + (∑ b : Fin (Module.finrank ℂ (V i)), + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) + (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] + simp_rw [he] + rw [←Finset.mul_sum] + field_simp + +include hρ hneq hcard in +lemma realVector_bound (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2≤ + ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + rw [parseval_operator V ρ hρ hneq hcard] + apply Finset.sum_le_sum + intro i _ + calc + _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro a _ + apply pow_le_pow_left₀ (norm_nonneg _) + simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using + (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring + +include hρ hneq hcard in + +theorem l1_fourier_bound (p : G → ℝ) : + (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) + have he : ‖realVector p‖^2=∑ g,|p g|^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] + rw [he] + simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) + +end Thorp.FiniteFourier + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +variable {B X : Type*} + +def lift : (B → Equiv.Perm X) →* Equiv.Perm (B × X) where + toFun p := + { toFun := fun x => (x.1,p x.1 x.2) + invFun := fun x => (x.1,(p x.1).symm x.2) + left_inv := fun x => by simp + right_inv := fun x => by simp } + map_one' := rfl + map_mul' _ _ := rfl + +@[simp] lemma lift_apply (p : B → Equiv.Perm X) (x : B × X) : lift p x=(x.1,p x.1 x.2) := rfl + +noncomputable def injection (b : B) : Equiv.Perm X →* Equiv.Perm (B × X) := + lift.comp + { toFun := fun p c => if c=b then p else 1 + map_one' := by funext c; simp + map_mul' := by intro p q; funext c; by_cases h : c=b <;> simp [h] } + +@[simp] lemma injection_apply (b : B) (p : Equiv.Perm X) (x : B × X) : + injection b p x=(x.1,if x.1=b then p x.2 else x.2) := by + simp only [injection,MonoidHom.comp_apply,lift_apply] + by_cases h : x.1=b <;> simp [h] + +lemma injection_commute {b c : B} (h : b≠c) (p q : Equiv.Perm X) : + Commute (injection b p) (injection c q) := by + apply Equiv.ext + intro x + simp only [Equiv.Perm.mul_apply,injection_apply] + by_cases hb : x.1=b <;> by_cases hc : x.1=c <;> simp_all + +variable [Fintype B] + +lemma lift_product (p : B → Equiv.Perm X) : + lift p=Finset.univ.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := by + have he (s : Finset B) (x : B × X) : + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) x= + (x.1,if x.1∈s then p x.1 x.2 else x.2) := by + induction s using Finset.induction_on with + | empty => + have hz : Finset.noncommProd (∅ : Finset B) (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=1 := Finset.noncommProd_empty _ _ + rw [hz]; simp + | @insert a s ha ih => + have hz : (insert a s).noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _)=injection a (p a)* + s.noncommProd (fun b => injection b (p b)) + (fun _ _ _ _ h => injection_commute h _ _) := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [hz,Equiv.Perm.mul_apply,ih,injection_apply] + by_cases h : x.1=a + · subst a; simp [ha] + · simp [h] + apply Equiv.ext + intro x + rw [he] + simp + +end Thorp.ParallelBlocks +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H : Type*} [Group G] [Group H] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma continuousRepresentation_comp (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : + continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl + +lemma sampleOperator_comp (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : + sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl + +omit [FiniteDimensional ℂ V] in +lemma unitary_comp (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : + IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w + +lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) + (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : + Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by + unfold sampleOperator + apply Commute.smul_left + apply Commute.smul_right + apply Commute.sum_left + intro ω _ + apply Commute.sum_right + intro ξ _ + exact (h ω ξ).map (continuousRepresentation ρ) + +lemma sampleOperator_uniform_absorb [Fintype G] [Nonempty Ω] + (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ P*uniformOperator ρ=uniformOperator ρ := by + rw [sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end Thorp.UnitaryFinite +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X Ω : Type*} [Fintype B] [DecidableEq B] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype B] [DecidableEq B] in +lemma local_average_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) + (sampleOperator (ρ.comp (injection c)) (P c)) := by + by_cases h : b=c + · subst c; exact Commute.refl _ + · rw [sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +lemma sampleOperator_parallel (ρ : Representation ℂ (Equiv.Perm (B × X)) V) + (P : B → Ω → Equiv.Perm X) : + sampleOperator ρ (fun ω : B → Ω => lift (fun b => P b (ω b)))= + CommutingBlocks.blocks (fun b => sampleOperator (ρ.comp (injection b)) (P b)) + (local_average_commute ρ P) := by + let A (b : B) (w : Ω) := continuousRepresentation ρ (injection b (P b w)) + have hc : ∀ ω : B → Ω, Pairwise fun b c => Commute (A b (ω b)) (A c (ω c)) := by + intro ω b c h + exact (injection_commute h _ _).map (continuousRepresentation ρ) + have havg : Pairwise fun b c => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A b w) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ w,A c w) := by + intro b c _ + exact local_average_commute ρ P b c + have he (ω : B → Ω) : continuousRepresentation ρ (lift (fun b => P b (ω b)))= + Finset.univ.noncommProd (fun b => A b (ω b)) (fun _ _ _ _ h => hc ω h) := by + rw [lift_product] + exact Finset.map_noncommProd _ _ _ (continuousRepresentation ρ) + unfold sampleOperator + simp_rw [he] + exact (FiniteAverage.ordered_average A hc havg).symm + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical + +noncomputable def splitPerm (r L : ℕ) : Equiv.Perm (Card (L+r)) ≃* Equiv.Perm (Card r × Card L) := + (cardSplit r L).permCongrHom + +noncomputable def outerPerm (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) : + Equiv.Perm (Card r × Card L) := + (Equiv.prodComm (Card L) (Card r)).permCongrHom + (ParallelBlocks.lift (fun x => butterflyPerm r (decodeButterfly r (fun i => hi (x,i))))) + +lemma outerPerm_apply (r L : ℕ) (hi : Card L × SwitchIndex r → Bool) (x : Card r × Card L) : + outerPerm r L hi x=(butterflyPerm r (decodeButterfly r (fun i => hi (x.2,i))) x.1,x.2) := rfl + +lemma splitPerm_butterfly (r L : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)))= + outerPerm r L hi*ParallelBlocks.lift + (fun b => butterflyPerm L (decodeButterfly L (fun i => lo (b,i)))) := by + apply Equiv.ext + intro x + change cardSplit r L (butterflyPerm (L+r) (decodeButterfly (L+r) (assembleBits r L lo hi)) + ((cardSplit r L).symm x))=_ + rw [butterfly_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryTree_node_raw (L r : ℕ) (U : Card (r+1) → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r+1) → Bool) : + boundaryTree L (r+1) U X=InputTree.node (fun y => X (Sum.inl y)) + (fun b => boundaryTree L r (fun u => U (Fin.cons b u)) (fun i => X (Sum.inr (b,i)))) := by + conv_lhs => unfold boundaryTree + congr 1 + funext b + cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryOutput_node_raw (L r : ℕ) (Y : SwitchIndex (L+r+1) → Bool) (b : Card (r+1)) : + boundaryOutput L (r+1) Y b= + boundaryOutput L r (fun i => Y (Sum.inr (b 0,i))) (Fin.tail b) := by + conv_lhs => unfold boundaryOutput + cases b 0 <;> simp only [Bool.false_eq_true,ite_false,ite_true] <;> rfl + +lemma boundaryTree_split (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) (x : Card (L+r)) : + cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm x)= + let y := cardSplit r L x + let z := U y.1 y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex L → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card L × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + let U' : Card r → Equiv.Perm (Card L) := fun b => U (Fin.cons (x 0) b) + have hh := ih U' lo' hi' (Fin.tail x) + let u := (boundaryTree L r U' (assembleBits r L lo' hi')).perm (Fin.tail x) + let y := cardSplit r L (Fin.tail x) + let z := U' y.1 y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r L u=(w,z) at hh + rw [boundaryTree_node_raw] + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r L u).2,Sum.inl (cardSplit r L u).1))) + ((cardSplit r L u).1) : Card (r+1)),(cardSplit r L u).2)= + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +lemma splitPerm_boundaryTree (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (lo : Card r × SwitchIndex L → Bool) (hi : Card L × SwitchIndex r → Bool) : + splitPerm r L (boundaryTree L r U (assembleBits r L lo hi)).perm= + outerPerm r L hi*ParallelBlocks.lift U := by + apply Equiv.ext + intro x + change cardSplit r L ((boundaryTree L r U (assembleBits r L lo hi)).perm + ((cardSplit r L).symm x))=_ + rw [boundaryTree_split,Equiv.apply_symm_apply] + rfl + +lemma boundaryOutput_split (L r : ℕ) (lo : Card r × SwitchIndex L → Bool) + (hi : Card L × SwitchIndex r → Bool) (b : Card r) : + boundaryOutput L r (assembleBits r L lo hi) b= + butterflyPerm L (decodeButterfly L (fun i => lo (b,i))) := by + induction r with + | zero => + rw [Subsingleton.elim b (fun j => Fin.elim0 j)] + rfl + | succ r ih => + rw [boundaryOutput_node_raw] + change boundaryOutput L r (assembleBits r L (fun j => lo (Fin.cons (b 0) j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b 0,j.2)))) (Fin.tail b)=_ + rw [ih] + simp only [Fin.cons_self_tail] + + +abbrev OuterCoins (r L : ℕ) := Card L × SwitchIndex r → Bool +abbrev LocalCoins (L : ℕ) := SwitchIndex L → Bool + +def parallelSplitCoinEquiv (r L : ℕ) : + ((Card r → LocalCoins L) × OuterCoins r L) ≃ LocalCoins (L+r) := + (Equiv.prodCongr (Equiv.curry (Card r) (SwitchIndex L) Bool).symm (Equiv.refl _)).trans + (splitCoinEquiv r L) + +lemma parallelSplitCoinEquiv_apply (r L : ℕ) (c : Card r → LocalCoins L) (h : OuterCoins r L) : + parallelSplitCoinEquiv r L (c,h)=assembleBits r L (fun x => c x.1 x.2) h := by + exact splitCoinEquiv_apply _ _ _ _ + +def pairAssembleEquiv (B C H : Type*) : + ((H × (B → C × C)) × H) ≃ (((B → C) × H) × ((B → C) × H)) where + toFun w := (((fun b => (w.1.2 b).1),w.1.1),((fun b => (w.1.2 b).2),w.2)) + invFun w := ((w.1.2,fun b => (w.1.1 b,w.2.1 b)),w.2.2) + left_inv _w := rfl + right_inv _w := rfl + +def palindromeStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) ≃ BenesCoins (L+r) := + (pairAssembleEquiv _ _ _).trans + (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L)) + +lemma palindromeStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + palindromeStageEquiv r L w= + (assembleBits r L (fun x => (w.1.2 x.1).1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2 x.2) w.2) := by + simp only [palindromeStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,pairAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,parallelSplitCoinEquiv_apply] + +def modifiedAssembleEquiv (B C H U : Type*) : + ((H × (B → U × (C × C))) × H) ≃ (B → U) × (((B → C) × H) × ((B → C) × H)) where + toFun w := ((fun b => (w.1.2 b).1), + (((fun b => (w.1.2 b).2.1),w.1.1),((fun b => (w.1.2 b).2.2),w.2))) + invFun w := ((w.2.1.2,fun b => (w.1 b,(w.2.1.1 b,w.2.2.1 b))),w.2.2.2) + left_inv _w := rfl + right_inv _w := rfl + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/Coins.lean b/lean/OAI/Probability/ThorpRouting/Tail/Coins.lean index 41235ab3ac26e9e0e0e023da7a0b9ffb678cf7a6..1bd8eb4dfa14a8f08441e8f93081675ff49f34d0 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/Coins.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/Coins.lean @@ -1,764 +1,764 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.Model - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -open scoped BigOperators -open Filter - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Card d → Bool - -instance (d : ℕ) : Fintype (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -instance (d : ℕ) : Nonempty (Coins d) := by - cases d <;> dsimp [Coins] <;> infer_instance - -def rotate (d : ℕ) : Equiv.Perm (Card d) where - toFun x i := x (finRotate d i) - invFun x i := x ((finRotate d).symm i) - left_inv x := by funext i; simp only [Equiv.apply_symm_apply] - right_inv x := by funext i; simp only [Equiv.symm_apply_apply] - -def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, ξ => rotate (d + 1) * pairSwitch ξ - -def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) - | 0, _ => 1 - | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) - -noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := - (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / - (Fintype.card (Fin t → Coins d) : ℝ) - -noncomputable def distance (d t : ℕ) : ℝ := - (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), - |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| - -noncomputable def mixingTime (d : ℕ) : ℕ := - sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} - -noncomputable def supportTimeBound (d : ℕ) : ℤ := - ⌈(2 / (2 : ℝ) ^ d) * - (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ - -def OptimalOrder : Prop := - ∃ C : ℕ, 0 < C ∧ - Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ - (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ - (∀ᶠ d : ℕ in atTop, - supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ - (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) - -noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by - classical - exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) - -lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : - ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by - classical - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : - 0 ≤ finiteLaw f b := by - exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - -lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : - ∑ b, finiteLaw f b = 1 := by - classical - simp only [finiteLaw, ← Finset.sum_div] - have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by - exact_mod_cast sum_card_fibers f - rw [hc] - exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by - classical - have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr - ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ - simp [finiteLaw] - -lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] - (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : - (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by - have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := - Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) - have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) - have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) - have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) - rw [hpq] at hz - rw [← Finset.sum_sub_distrib] - linarith - -lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] - [Fintype β] [Nonempty β] (f : α → β) : - 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ - (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by - classical - let s := Finset.univ.image f - have hs : ∑ b ∈ s, finiteLaw f b = 1 := by - have h := Finset.sum_subset (Finset.subset_univ s) - (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) - simpa only [finiteLaw_sum] using h - have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] - have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by - rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] - have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s - rw [hs] at he - have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by - simp [div_eq_mul_inv] - rw [hsq] at he - have hcard : (s.card : ℝ) ≤ Fintype.card α := by - exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) - have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) - linarith - -lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by - simp [Card] - -lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by - rw [Fintype.card_perm, card_positions] - -lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by - rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] - -lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : - law d t g = finiteLaw (run d t) g := by - unfold law finiteLaw - apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) - exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) - -lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by - rw [law_eq_finiteLaw] - exact finiteLaw_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by - simp only [law_eq_finiteLaw] - exact finiteLaw_sum (run d t) - -lemma physical_support_bound_succ (d t : ℕ) : - 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by - have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ - have h := finiteLaw_support_bound (run (d + 1) t) - rw [card_tapes_succ, card_permutations] at h - simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h - -lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : - step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by - change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ - rw [Fin.snoc_eq_cons_rotate] - rfl - -lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by - unfold distance - exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - -lemma physical_support_bound (d t : ℕ) : - 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / - (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by - cases d with - | zero => - have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) - simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using - le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) - | succ d => - have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by - push_cast - rw [pow_succ] - ring - rw [he, Real.rpow_natCast] - exact physical_support_bound_succ d t - -lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : - supportTimeBound d ≤ (t : ℤ) := by - have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity - have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity - have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) - have hb := physical_support_bound d t - have hp : (3 / 4 : ℝ) ≤ - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by - linarith - have hr := (le_div_iff₀ hF).mp hp - have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr - rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog - unfold supportTimeBound - apply Int.ceil_le.mpr - simp only [Int.cast_natCast] - calc - 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = - Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by - field_simp - _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by - nlinarith [hlog]) - -lemma supportTimeBound_le_mixingTime {d : ℕ} - (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : - supportTimeBound d ≤ (mixingTime d : ℤ) := by - exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) - -lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : - (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by - have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) - have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) - have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by - have := Real.pi_gt_three - linarith) - linarith - -lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) - have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by - rw [← Real.log_inv] - congr 1 - norm_num - rw [he] at h - linarith - -lemma linear_le_supportTimeBound (d : ℕ) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by - have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) - have hNp : 0 < (2 : ℝ) ^ d := by positivity - have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) - have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - rw [Real.log_mul (by norm_num) (by positivity)] - push_cast at hf - rw [Real.log_pow] at hf - linarith [log_three_quarters_lower] - apply le_trans _ (Int.le_ceil _) - have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ - Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by - have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * - ((2 : ℝ) ^ d / 2 * Real.log 2) = - (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by - field_simp - ring - rw [hcancel] - linarith - convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 - field_simp - -lemma linear_le_time_of_distance_le (d t : ℕ) - (ht : distance d t ≤ (1 / 4 : ℝ)) : - 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by - have h := supportTimeBound_le_of_distance_le d t ht - have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h - exact (linear_le_supportTimeBound d).trans hr - -lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : - 2 * p * Real.log 2 ≤ Real.binEntropy p := by - have hc := Real.strictConcave_binEntropy.concaveOn.2 - (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) - (show 0 ≤ 1 - 2 * p by linarith) - (show 0 ≤ 2 * p by positivity) - (show (1 - 2 * p) + 2 * p = 1 by ring) - simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, - smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc - -lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : - 2 * min a b * Real.log 2 ≤ - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - wlog hab : a ≤ b generalizing a b - · have hba := this b a hb ha (le_of_not_ge hab) - simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) - rw [min_eq_left hab] - by_cases hz : a = 0 - · subst a - simp - have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) - have hbp : 0 < b := hap.trans_le hab - have hs : 0 < a + b := add_pos hap hbp - have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le - have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) - have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le - have he : (a + b) * Real.binEntropy (a / (a + b)) = - (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by - unfold Real.binEntropy - rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] - simp only [Real.log_inv] - rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), - Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] - field_simp - ring - rw [he] at hc - calc - 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by - field_simp - _ ≤ _ := hc - -noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail - -lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : - (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by - classical - unfold childMarks - apply Finset.card_image_iff.mpr - intro x hx y hy hxy - have hx0 := (Finset.mem_filter.mp hx).2 - have hy0 := (Finset.mem_filter.mp hy).2 - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] - -lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : - (childMarks s false).card + (childMarks s true).card = s.card := by - classical - rw [card_childMarks, card_childMarks] - simpa only [Bool.not_eq_false] using - (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) - -noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) : Finset (Card d) := - ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ - ((childMarks s true).image (butterflyPerm d (b.2 true))) - -lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : - (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by - classical - apply le_min - · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) - · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq - (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) - -noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ - | 0, _, _ => 0 - | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card - -lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - induction d with - | zero => - simp only [encounters, Nat.cast_zero] - have hs : s.card ≤ 1 := by - simpa [Card] using Finset.card_le_univ s - interval_cases s.card <;> simp - | succ d ih => - have h₀ := ih (b.2 false) (childMarks s false) - have h₁ := ih (b.2 true) (childMarks s true) - have ht : ((topMeetings b s).card : ℝ) ≤ - min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by - exact_mod_cast card_topMeetings_le b s - have he := split_entropy_lower ((childMarks s false).card : ℝ) - ((childMarks s true).card : ℝ) (by positivity) (by positivity) - have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by - exact_mod_cast card_childMarks_add s - rw [hs] at he - have hL : 0 < 2 * Real.log 2 := by positivity - rw [le_div_iff₀ hL] at h₀ h₁ ⊢ - simp only [encounters, Nat.cast_add] - nlinarith [mul_le_mul_of_nonneg_right ht hL.le] - -lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by - by_cases ha : a ∈ s - · rw [ite_eq_left ha] - exact (Finset.mul_prod_erase s f ha).symm - · simp [ha] - -lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) - (a b : α) (hab : a ≠ b) : - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * - ∏ i ∈ (s.erase a).erase b, f i := by - calc - ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := - prod_split_at s f a - _ = _ := by - rw [prod_split_at (s.erase a) f b] - have hm : (b ∈ s.erase a) ↔ b ∈ s := - ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ - simp only [hm, mul_assoc] - -lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ - ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by - by_cases hab : a = b - · subst b - simp only [Equiv.swap_self, Equiv.refl_apply] - have h : (fun i => (p i + p i) / 2) = p := by funext i; ring - rw [h] - linarith - let t := (s.erase a).erase b - have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by - intro i hi - exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) - have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := - Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) - rw [prod_split_two s p a b hab, - prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, - prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] - change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + - (if a ∈ s then p (Equiv.swap a b a) else 1) * - (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ - rw [hprod] - change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * - (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * - (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) - rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] - have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) - by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] - · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht - nlinarith - all_goals ring_nf; rfl - -def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := - ∀ s, m s ≤ ∏ i ∈ s, p i - -lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] - {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) - (hp : ∀ i, 0 ≤ p i) (a b : α) : - CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) - (fun i => (p i + p (Equiv.swap a b i)) / 2) := by - intro s - have h₀ := h s - have h₁ := h (s.image (Equiv.swap a b)) - rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ - exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ - ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans - (swap_average_product s p hp a b) - -noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : ℝ := by - classical - exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) - -lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] - (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by - classical - unfold inclusionMoment finiteMean - positivity - -lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : - (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by - by_cases h : s ⊆ A - · rw [ite_eq_left h] - exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm - · rw [ite_eq_right h] - obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h - exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm - -lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] - (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = - if s ⊆ A then 1 else 0 := by - classical - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] - -lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : - CylinderBound (inclusionMoment (fun _ : Ω => A)) - (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by - classical - intro s - simp only [inclusionMoment_const, Finset.singleton_subset_iff] - exact (indicator_subset_prod A s).le - -noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] - (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := - fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 - -lemma subset_swap_image_iff {α : Type*} [DecidableEq α] - (A s : Finset α) (a b : α) : - s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by - constructor - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := Equiv.swap a b) - simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' - -lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) (s : Finset α) : - inclusionMoment (fairSetSwap F a b) s = - (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by - classical - simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, - fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, - Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] - rw [div_mul_eq_div_div, add_div] - ring_nf - -lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (a b : α) - (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : - CylinderBound (inclusionMoment (fairSetSwap F a b)) - (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by - classical - have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b - intro s - simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s - -def SwitchSamples : ℕ → Type - | 0 => Unit - | n + 1 => SwitchSamples n × Bool - -instance (n : ℕ) : Fintype (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Fintype Unit) - | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) - -instance (n : ℕ) : Nonempty (SwitchSamples n) := by - induction n with - | zero => exact inferInstanceAs (Nonempty Unit) - | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) - -noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : - (L : List (α × α)) → SwitchSamples L.length → Finset α - | [], _ => A - | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω - -lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) - (L : List (α × α)) : - CylinderBound (inclusionMoment (switchedSet A L)) - (fun i => inclusionMoment (switchedSet A L) {i}) := by - induction L with - | nil => exact cylinder_const A - | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih - -inductive QueryTree (ι : Type*) - | reject : QueryTree ι - | accept : QueryTree ι - | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι - | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι - -namespace QueryTree - -variable {ι : Type*} [DecidableEq ι] - -def queries : QueryTree ι → Finset ι - | reject => ∅ - | accept => ∅ - | branch i zero one => insert i (queries zero ∪ queries one) - | force i _ next => insert i (queries next) - -def Fresh : QueryTree ι → Prop - | reject => True - | accept => True - | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one - | force i _ next => i ∉ queries next ∧ Fresh next - -def weighted : QueryTree ι → (ι → Bool) → ℝ - | reject, _ => 0 - | accept, _ => 1 - | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω - | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 - -omit [DecidableEq ι] in -lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by - induction T with - | reject => exact le_rfl - | accept => exact zero_le_one - | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ - | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl - -lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} - (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by - induction T with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), - ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] - | force i b next ih => - have hi := h i (Finset.mem_insert_self _ _) - simp only [weighted, hi] - rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] - -def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := - (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by - intro ω - funext j - by_cases h : j = i - · subst j; simp - · simp [Function.update_of_ne h]).toPerm - -lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by - change Function.update ω i (!(ω i)) i = _ - exact Function.update_self _ _ _ - -lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : - flipCoin i ω j = ω j := by - change Function.update ω i (!(ω i)) j = _ - exact Function.update_of_ne h _ _ - -lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) - (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by - apply weighted_congr - intro j hj - exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω - -lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) - (hf : ∀ ω, f (flipCoin i ω) = f ω) : - finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by - let g := fun ω : ι → Bool => if ω i = b then f ω else 0 - have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by - dsimp [g] - rw [flipCoin_apply_eq, hf] - cases hω : ω i <;> cases b <;> simp - have hs := Equiv.sum_comp (flipCoin i) g - have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun ω _ => hp ω) - unfold finiteMean - change (∑ ω, g ω) / _ = _ - rw [hs] at hadd - have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith - rw [hh] - ring - -lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : - finiteMean T.weighted ≤ 1 := by - induction T with - | reject => simp [weighted, finiteMean] - | accept => simp [weighted, finiteMean] - | branch i zero one ih₀ ih₁ => - obtain ⟨hz, ho, hfz, hfo⟩ := hT - have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) - have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) - have he : finiteMean (branch i zero one).weighted = - finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + - finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by - unfold finiteMean - rw [← add_div, ← Finset.sum_add_distrib] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - cases hω : ω i <;> simp [weighted, hω] - rw [he, h₀, h₁] - linarith [ih₀ hfz, ih₁ hfo] - | force i b next ih => - obtain ⟨hi, hn⟩ := hT - have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) - have he : finiteMean (force i b next).weighted = - 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by - unfold finiteMean - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : ω i = b <;> simp [weighted, h] - rw [he, hm] - linarith [ih hn] - -def succeeds : QueryTree ι → (ι → Bool) → Bool - | reject, _ => false - | accept, _ => true - | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω - | force i b next, ω => if ω i = b then succeeds next ω else false - -def charge : QueryTree ι → (ι → Bool) → ℕ - | reject, _ => 0 - | accept, _ => 0 - | branch i zero one, ω => if ω i then charge one ω else charge zero ω - | force i b next, ω => if ω i = b then charge next ω + 1 else 0 - -omit [DecidableEq ι] in -lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : - T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by - induction T with - | reject => rfl - | accept => norm_num [weighted, succeeds, charge] - | branch i zero one ih₀ ih₁ => - cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] - | force i b next ih => - by_cases h : ω i = b - · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] - cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] - · simp [weighted, succeeds, h] - -lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) - (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : - finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by - have hw (ω : ι → Bool) : - (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by - rw [weighted_eq] - cases hs : T.succeeds ω - · simp - · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) - have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ - have hm := div_le_div_of_nonneg_right - (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn - rw [← Finset.mul_sum, mul_div_assoc] at hm - change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ - finiteMean T.weighted at hm - exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by - rw [mul_comm] - exact hm.trans (mean_weighted_le_one T hT)) - -end QueryTree - -def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool - | 0, _, i => nomatch i - | _d + 1, b, Sum.inl y => b.1 y - | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i - -lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : - decodeButterfly d (encodeButterfly d b) = b := by - induction d with - | zero => exact Unit.ext _ _ - | succ d ih => - apply Prod.ext - · rfl - · funext ε - exact ih (b.2 ε) - -lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : - encodeButterfly d (decodeButterfly d ω) = ω := by - induction d with - | zero => funext i; exact Empty.elim i - | succ d ih => - funext i - cases i with - | inl y => rfl - | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 - -def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where - toFun := decodeButterfly d - invFun := encodeButterfly d - left_inv := encode_decodeButterfly d - right_inv := decode_encodeButterfly d - -noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) - | 0, _, _ => ∅ - | d + 1, x, y => by - classical - exact insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) - -def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool - | 0, _, _, i => nomatch i - | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) - | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.Model + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +open scoped BigOperators +open Filter + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Card d → Bool + +instance (d : ℕ) : Fintype (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +instance (d : ℕ) : Nonempty (Coins d) := by + cases d <;> dsimp [Coins] <;> infer_instance + +def rotate (d : ℕ) : Equiv.Perm (Card d) where + toFun x i := x (finRotate d i) + invFun x i := x ((finRotate d).symm i) + left_inv x := by funext i; simp only [Equiv.apply_symm_apply] + right_inv x := by funext i; simp only [Equiv.symm_apply_apply] + +def step : (d : ℕ) → Coins d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, ξ => rotate (d + 1) * pairSwitch ξ + +def run (d : ℕ) : (t : ℕ) → (Fin t → Coins d) → Equiv.Perm (Card d) + | 0, _ => 1 + | t + 1, ω => step d (ω (Fin.last t)) * run d t (fun i => ω i.castSucc) + +noncomputable def law (d t : ℕ) (g : Equiv.Perm (Card d)) : ℝ := + (Fintype.card {ω : Fin t → Coins d // run d t ω = g} : ℝ) / + (Fintype.card (Fin t → Coins d) : ℝ) + +noncomputable def distance (d t : ℕ) : ℝ := + (1 / 2 : ℝ) * ∑ g : Equiv.Perm (Card d), + |law d t g - 1 / (Nat.factorial (2 ^ d) : ℝ)| + +noncomputable def mixingTime (d : ℕ) : ℕ := + sInf {t : ℕ | distance d t ≤ (1 / 4 : ℝ)} + +noncomputable def supportTimeBound (d : ℕ) : ℤ := + ⌈(2 / (2 : ℝ) ^ d) * + (Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) / Real.log 2)⌉ + +def OptimalOrder : Prop := + ∃ C : ℕ, 0 < C ∧ + Tendsto (fun d : ℕ => distance d (C * d)) atTop (nhds 0) ∧ + (∀ d t : ℕ, 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t) ∧ + (∀ᶠ d : ℕ in atTop, + supportTimeBound d ≤ (mixingTime d : ℤ) ∧ mixingTime d ≤ C * d) ∧ + (∃ K : ℝ, ∀ᶠ d : ℕ in atTop, 2 * (d : ℝ) - K ≤ (mixingTime d : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) (fun d : ℕ => (d : ℝ)) + +noncomputable def finiteLaw {α β : Type*} [Fintype α] (f : α → β) (b : β) : ℝ := by + classical + exact (Fintype.card {a : α // f a = b} : ℝ) / (Fintype.card α : ℝ) + +lemma sum_card_fibers {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] (f : α → β) : + ∑ b, Fintype.card {a : α // f a = b} = Fintype.card α := by + classical + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +lemma finiteLaw_nonneg {α β : Type*} [Fintype α] (f : α → β) (b : β) : + 0 ≤ finiteLaw f b := by + exact div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +lemma finiteLaw_sum {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] (f : α → β) : + ∑ b, finiteLaw f b = 1 := by + classical + simp only [finiteLaw, ← Finset.sum_div] + have hc : (∑ b, (Fintype.card {a : α // f a = b} : ℝ)) = (Fintype.card α : ℝ) := by + exact_mod_cast sum_card_fibers f + rw [hc] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteLaw_eq_zero_of_not_mem {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) {b : β} (hb : b ∉ Finset.univ.image f) : finiteLaw f b = 0 := by + classical + have : IsEmpty {a : α // f a = b} := ⟨fun a => hb (Finset.mem_image.mpr + ⟨a.val, Finset.mem_univ _, a.property⟩)⟩ + simp [finiteLaw] + +lemma event_le_totalVariation {β : Type*} [Fintype β] [DecidableEq β] + (p q : β → ℝ) (hpq : ∑ b, (p b - q b) = 0) (s : Finset β) : + (∑ b ∈ s, p b) - (∑ b ∈ s, q b) ≤ (1 / 2 : ℝ) * ∑ b, |p b - q b| := by + have h₁ : (∑ b ∈ s, (p b - q b)) ≤ ∑ b ∈ s, |p b - q b| := + Finset.sum_le_sum (fun b _ => le_abs_self (p b - q b)) + have h₂ : -(∑ b ∈ sᶜ, (p b - q b)) ≤ ∑ b ∈ sᶜ, |p b - q b| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun b _ => neg_le_abs (p b - q b)) + have hz := Finset.sum_add_sum_compl s (fun b => p b - q b) + have ha := Finset.sum_add_sum_compl s (fun b => |p b - q b|) + rw [hpq] at hz + rw [← Finset.sum_sub_distrib] + linarith + +lemma finiteLaw_support_bound {α β : Type*} [Fintype α] [Nonempty α] + [Fintype β] [Nonempty β] (f : α → β) : + 1 - (Fintype.card α : ℝ) / (Fintype.card β : ℝ) ≤ + (1 / 2 : ℝ) * ∑ b, |finiteLaw f b - 1 / (Fintype.card β : ℝ)| := by + classical + let s := Finset.univ.image f + have hs : ∑ b ∈ s, finiteLaw f b = 1 := by + have h := Finset.sum_subset (Finset.subset_univ s) + (fun b _ hb => finiteLaw_eq_zero_of_not_mem f hb) + simpa only [finiteLaw_sum] using h + have hβ : (Fintype.card β : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hq : (∑ _b : β, 1 / (Fintype.card β : ℝ)) = 1 := by simp [hβ] + have hd : (∑ b, (finiteLaw f b - 1 / (Fintype.card β : ℝ))) = 0 := by + rw [Finset.sum_sub_distrib, finiteLaw_sum, hq, sub_self] + have he := event_le_totalVariation (finiteLaw f) (fun _ => 1 / (Fintype.card β : ℝ)) hd s + rw [hs] at he + have hsq : (∑ _b ∈ s, 1 / (Fintype.card β : ℝ)) = (s.card : ℝ) / Fintype.card β := by + simp [div_eq_mul_inv] + rw [hsq] at he + have hcard : (s.card : ℝ) ≤ Fintype.card α := by + exact_mod_cast (Finset.card_image_le (s := (Finset.univ : Finset α)) (f := f)) + have hdiv := div_le_div_of_nonneg_right hcard (Nat.cast_nonneg (Fintype.card β) : (0 : ℝ) ≤ _) + linarith + +lemma card_positions (d : ℕ) : Fintype.card (Card d) = 2 ^ d := by + simp [Card] + +lemma card_permutations (d : ℕ) : Fintype.card (Equiv.Perm (Card d)) = Nat.factorial (2 ^ d) := by + rw [Fintype.card_perm, card_positions] + +lemma card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +lemma card_tapes_succ (d t : ℕ) : Fintype.card (Fin t → Coins (d + 1)) = 2 ^ (t * 2 ^ d) := by + rw [Fintype.card_fun, card_coins_succ, Fintype.card_fin, ← pow_mul, Nat.mul_comm] + +lemma law_eq_finiteLaw (d t : ℕ) (g : Equiv.Perm (Card d)) : + law d t g = finiteLaw (run d t) g := by + unfold law finiteLaw + apply congrArg (fun n : ℕ => (n : ℝ) / (Fintype.card (Fin t → Coins d) : ℝ)) + exact congrArg (@Fintype.card _) (Subsingleton.elim _ _) + +lemma law_nonneg (d t : ℕ) (g : Equiv.Perm (Card d)) : 0 ≤ law d t g := by + rw [law_eq_finiteLaw] + exact finiteLaw_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := by + simp only [law_eq_finiteLaw] + exact finiteLaw_sum (run d t) + +lemma physical_support_bound_succ (d t : ℕ) : + 1 - (2 : ℝ) ^ (t * 2 ^ d) / (Nat.factorial (2 ^ (d + 1)) : ℝ) ≤ distance (d + 1) t := by + have : Nonempty (Equiv.Perm (Card (d + 1))) := ⟨1⟩ + have h := finiteLaw_support_bound (run (d + 1) t) + rw [card_tapes_succ, card_permutations] at h + simpa only [Nat.cast_pow, Nat.cast_ofNat, distance, law_eq_finiteLaw] using h + +lemma step_succ_formula (d : ℕ) (ξ : Coins (d + 1)) (x : Card (d + 1)) : + step (d + 1) ξ x = Fin.snoc (Fin.tail x) (Bool.xor (x 0) (ξ (Fin.tail x))) := by + change (fun i => switchFun ξ x (finRotate (d + 1) i)) = _ + rw [Fin.snoc_eq_cons_rotate] + rfl + +lemma distance_nonneg (d t : ℕ) : 0 ≤ distance d t := by + unfold distance + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + +lemma physical_support_bound (d t : ℕ) : + 1 - (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / + (Nat.factorial (2 ^ d) : ℝ) ≤ distance d t := by + cases d with + | zero => + have h : 1 ≤ (2 : ℝ) ^ ((t : ℝ) / 2) := Real.one_le_rpow (by norm_num) (by positivity) + simpa only [pow_zero, Nat.factorial_one, Nat.cast_one, div_one, mul_one] using + le_trans (sub_nonpos.mpr h) (distance_nonneg 0 t) + | succ d => + have he : (t : ℝ) * (2 : ℝ) ^ (d + 1) / 2 = (t * 2 ^ d : ℕ) := by + push_cast + rw [pow_succ] + ring + rw [he, Real.rpow_natCast] + exact physical_support_bound_succ d t + +lemma supportTimeBound_le_of_distance_le (d t : ℕ) (ht : distance d t ≤ (1 / 4 : ℝ)) : + supportTimeBound d ≤ (t : ℤ) := by + have hF : (0 : ℝ) < Nat.factorial (2 ^ d) := by positivity + have hN : (0 : ℝ) < (2 : ℝ) ^ d := by positivity + have hL : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num) + have hb := physical_support_bound d t + have hp : (3 / 4 : ℝ) ≤ + (2 : ℝ) ^ ((t : ℝ) * (2 : ℝ) ^ d / 2) / (Nat.factorial (2 ^ d) : ℝ) := by + linarith + have hr := (le_div_iff₀ hF).mp hp + have hlog := Real.log_le_log (show (0 : ℝ) < (3 / 4 : ℝ) * Nat.factorial (2 ^ d) by positivity) hr + rw [Real.log_rpow (by norm_num : (0 : ℝ) < 2)] at hlog + unfold supportTimeBound + apply Int.ceil_le.mpr + simp only [Int.cast_natCast] + calc + 2 / (2 : ℝ) ^ d * (Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / Real.log 2) = + Real.log ((3 / 4 : ℝ) * Nat.factorial (2 ^ d)) / ((2 : ℝ) ^ d / 2 * Real.log 2) := by + field_simp + _ ≤ (t : ℝ) := (div_le_iff₀ (mul_pos (div_pos hN (by norm_num)) hL)).mpr (by + nlinarith [hlog]) + +lemma supportTimeBound_le_mixingTime {d : ℕ} + (h : ({t : ℕ | distance d t ≤ (1 / 4 : ℝ)} : Set ℕ).Nonempty) : + supportTimeBound d ≤ (mixingTime d : ℤ) := by + exact supportTimeBound_le_of_distance_le d (mixingTime d) (Nat.sInf_mem h) + +lemma log_factorial_lower {n : ℕ} (hn : 1 ≤ n) : + (n : ℝ) * Real.log n - n ≤ Real.log (Nat.factorial n) := by + have h := Stirling.le_log_factorial_stirling (show n ≠ 0 by omega) + have hln : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by exact_mod_cast hn) + have hlp : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by + have := Real.pi_gt_three + linarith) + linarith + +lemma log_three_quarters_lower : -(1 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 4 / 3 by norm_num) + have he : Real.log (4 / 3 : ℝ) = - Real.log (3 / 4 : ℝ) := by + rw [← Real.log_inv] + congr 1 + norm_num + rw [he] at h + linarith + +lemma linear_le_supportTimeBound (d : ℕ) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (supportTimeBound d : ℝ) := by + have hN : 1 ≤ (2 : ℝ) ^ d := one_le_pow₀ (by norm_num) + have hNp : 0 < (2 : ℝ) ^ d := by positivity + have hL : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hf := log_factorial_lower (show 1 ≤ 2 ^ d by exact one_le_pow₀ (by norm_num)) + have hlog : (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - (2 : ℝ) ^ d - 1 ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + rw [Real.log_mul (by norm_num) (by positivity)] + push_cast at hf + rw [Real.log_pow] at hf + linarith [log_three_quarters_lower] + apply le_trans _ (Int.le_ceil _) + have hmul : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) ≤ + Real.log ((3 / 4 : ℝ) * (Nat.factorial (2 ^ d) : ℝ)) := by + have hcancel : (2 * (d : ℝ) - 4 / Real.log 2) * + ((2 : ℝ) ^ d / 2 * Real.log 2) = + (2 : ℝ) ^ d * ((d : ℝ) * Real.log 2) - 2 * (2 : ℝ) ^ d := by + field_simp + ring + rw [hcancel] + linarith + convert (le_div_iff₀ (mul_pos (div_pos hNp (by norm_num)) hL)).mpr hmul using 1 + field_simp + +lemma linear_le_time_of_distance_le (d t : ℕ) + (ht : distance d t ≤ (1 / 4 : ℝ)) : + 2 * (d : ℝ) - 4 / Real.log 2 ≤ (t : ℝ) := by + have h := supportTimeBound_le_of_distance_le d t ht + have hr : (supportTimeBound d : ℝ) ≤ (t : ℝ) := by exact_mod_cast h + exact (linear_le_supportTimeBound d).trans hr + +lemma entropy_chord (p : ℝ) (hp : 0 ≤ p) (hq : p ≤ 1 / 2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc := Real.strictConcave_binEntropy.concaveOn.2 + (show (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc (0 : ℝ) 1 by norm_num) + (show 0 ≤ 1 - 2 * p by linarith) + (show 0 ≤ 2 * p by positivity) + (show (1 - 2 * p) + 2 * p = 1 by ring) + simpa only [Real.binEntropy_zero, Real.binEntropy_two_inv, + smul_eq_mul, mul_zero, zero_add, show 2 * p * (2 : ℝ)⁻¹ = p by ring] using hc + +lemma split_entropy_lower (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + wlog hab : a ≤ b generalizing a b + · have hba := this b a hb ha (le_of_not_ge hab) + simpa only [min_comm, add_comm b a] using hba.trans_eq (show (b + a) * Real.log (b + a) - b * Real.log b - a * Real.log a = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b by rw [add_comm b a]; ring) + rw [min_eq_left hab] + by_cases hz : a = 0 + · subst a + simp + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm hz) + have hbp : 0 < b := hap.trans_le hab + have hs : 0 < a + b := add_pos hap hbp + have hp : 0 ≤ a / (a + b) := div_nonneg ha hs.le + have hq : a / (a + b) ≤ 1 / 2 := (div_le_iff₀ hs).mpr (by linarith) + have hc := mul_le_mul_of_nonneg_left (entropy_chord (a / (a + b)) hp hq) hs.le + have he : (a + b) * Real.binEntropy (a / (a + b)) = + (a + b) * Real.log (a + b) - a * Real.log a - b * Real.log b := by + unfold Real.binEntropy + rw [show 1 - a / (a + b) = b / (a + b) by field_simp; ring] + simp only [Real.log_inv] + rw [Real.log_div (ne_of_gt hap) (ne_of_gt hs), + Real.log_div (ne_of_gt hbp) (ne_of_gt hs)] + field_simp + ring + rw [he] at hc + calc + 2 * a * Real.log 2 = (a + b) * (2 * (a / (a + b)) * Real.log 2) := by + field_simp + _ ≤ _ := hc + +noncomputable def childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + Finset (Card d) := (s.filter (fun x => x 0 = ε)).image Fin.tail + +lemma card_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) : + (childMarks s ε).card = (s.filter (fun x => x 0 = ε)).card := by + classical + unfold childMarks + apply Finset.card_image_iff.mpr + intro x hx y hy hxy + have hx0 := (Finset.mem_filter.mp hx).2 + have hy0 := (Finset.mem_filter.mp hy).2 + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y, hx0, hy0, hxy] + +lemma card_childMarks_add {d : ℕ} (s : Finset (Card (d + 1))) : + (childMarks s false).card + (childMarks s true).card = s.card := by + classical + rw [card_childMarks, card_childMarks] + simpa only [Bool.not_eq_false] using + (Finset.card_filter_add_card_filter_not (s := s) (fun x => x 0 = false)) + +noncomputable def topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) : Finset (Card d) := + ((childMarks s false).image (butterflyPerm d (b.2 false))) ∩ + ((childMarks s true).image (butterflyPerm d (b.2 true))) + +lemma card_topMeetings_le {d : ℕ} (b : Butterfly (d + 1)) (s : Finset (Card (d + 1))) : + (topMeetings b s).card ≤ min (childMarks s false).card (childMarks s true).card := by + classical + apply le_min + · exact (Finset.card_le_card Finset.inter_subset_left).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 false)).injective) + · exact (Finset.card_le_card Finset.inter_subset_right).trans_eq + (Finset.card_image_of_injective _ (butterflyPerm d (b.2 true)).injective) + +noncomputable def encounters : (d : ℕ) → Butterfly d → Finset (Card d) → ℕ + | 0, _, _ => 0 + | d + 1, b, s => encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card + +lemma butterfly_encounters (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (encounters d b s : ℝ) ≤ (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + induction d with + | zero => + simp only [encounters, Nat.cast_zero] + have hs : s.card ≤ 1 := by + simpa [Card] using Finset.card_le_univ s + interval_cases s.card <;> simp + | succ d ih => + have h₀ := ih (b.2 false) (childMarks s false) + have h₁ := ih (b.2 true) (childMarks s true) + have ht : ((topMeetings b s).card : ℝ) ≤ + min ((childMarks s false).card : ℝ) ((childMarks s true).card : ℝ) := by + exact_mod_cast card_topMeetings_le b s + have he := split_entropy_lower ((childMarks s false).card : ℝ) + ((childMarks s true).card : ℝ) (by positivity) (by positivity) + have hs : ((childMarks s false).card : ℝ) + (childMarks s true).card = s.card := by + exact_mod_cast card_childMarks_add s + rw [hs] at he + have hL : 0 < 2 * Real.log 2 := by positivity + rw [le_div_iff₀ hL] at h₀ h₁ ⊢ + simp only [encounters, Nat.cast_add] + nlinarith [mul_le_mul_of_nonneg_right ht hL.le] + +lemma prod_split_at {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) (a : α) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := by + by_cases ha : a ∈ s + · rw [ite_eq_left ha] + exact (Finset.mul_prod_erase s f ha).symm + · simp [ha] + +lemma prod_split_two {α : Type*} [DecidableEq α] (s : Finset α) (f : α → ℝ) + (a b : α) (hab : a ≠ b) : + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * (if b ∈ s then f b else 1) * + ∏ i ∈ (s.erase a).erase b, f i := by + calc + ∏ i ∈ s, f i = (if a ∈ s then f a else 1) * ∏ i ∈ s.erase a, f i := + prod_split_at s f a + _ = _ := by + rw [prod_split_at (s.erase a) f b] + have hm : (b ∈ s.erase a) ↔ b ∈ s := + ⟨fun h => (Finset.mem_erase.mp h).2, fun h => Finset.mem_erase.mpr ⟨Ne.symm hab, h⟩⟩ + simp only [hm, mul_assoc] + +lemma swap_average_product {α : Type*} [DecidableEq α] (s : Finset α) (p : α → ℝ) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 ≤ + ∏ i ∈ s, (p i + p (Equiv.swap a b i)) / 2 := by + by_cases hab : a = b + · subst b + simp only [Equiv.swap_self, Equiv.refl_apply] + have h : (fun i => (p i + p i) / 2) = p := by funext i; ring + rw [h] + linarith + let t := (s.erase a).erase b + have hfix : ∀ i ∈ t, Equiv.swap a b i = i := by + intro i hi + exact Equiv.swap_apply_of_ne_of_ne (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + have hprod : (∏ i ∈ t, p (Equiv.swap a b i)) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]) + have havg : (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) = ∏ i ∈ t, p i := + Finset.prod_congr rfl (fun i hi => by rw [hfix i hi]; ring) + rw [prod_split_two s p a b hab, + prod_split_two s (fun i => p (Equiv.swap a b i)) a b hab, + prod_split_two s (fun i => (p i + p (Equiv.swap a b i)) / 2) a b hab] + change ((if a ∈ s then p a else 1) * (if b ∈ s then p b else 1) * (∏ i ∈ t, p i) + + (if a ∈ s then p (Equiv.swap a b a) else 1) * + (if b ∈ s then p (Equiv.swap a b b) else 1) * (∏ i ∈ t, p (Equiv.swap a b i))) / 2 ≤ _ + rw [hprod] + change _ ≤ (if a ∈ s then (p a + p (Equiv.swap a b a)) / 2 else 1) * + (if b ∈ s then (p b + p (Equiv.swap a b b)) / 2 else 1) * + (∏ i ∈ t, (p i + p (Equiv.swap a b i)) / 2) + rw [havg, Equiv.swap_apply_left, Equiv.swap_apply_right] + have ht : 0 ≤ ∏ i ∈ t, p i := Finset.prod_nonneg (fun i _ => hp i) + by_cases ha : a ∈ s <;> by_cases hb : b ∈ s <;> simp only [ha, hb, ↓reduceIte] + · have hsq := mul_nonneg (sq_nonneg (p a - p b)) ht + nlinarith + all_goals ring_nf; rfl + +def CylinderBound {α : Type*} (m : Finset α → ℝ) (p : α → ℝ) : Prop := + ∀ s, m s ≤ ∏ i ∈ s, p i + +lemma CylinderBound.fair_swap {α : Type*} [DecidableEq α] + {m : Finset α → ℝ} {p : α → ℝ} (h : CylinderBound m p) + (hp : ∀ i, 0 ≤ p i) (a b : α) : + CylinderBound (fun s => (m s + m (s.image (Equiv.swap a b))) / 2) + (fun i => (p i + p (Equiv.swap a b i)) / 2) := by + intro s + have h₀ := h s + have h₁ := h (s.image (Equiv.swap a b)) + rw [Finset.prod_image (Equiv.swap a b).injective.injOn] at h₁ + exact (show (m s + m (s.image (Equiv.swap a b))) / 2 ≤ + ((∏ i ∈ s, p i) + ∏ i ∈ s, p (Equiv.swap a b i)) / 2 by linarith).trans + (swap_average_product s p hp a b) + +noncomputable def inclusionMoment {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : ℝ := by + classical + exact finiteMean (fun ω => if s ⊆ F ω then 1 else 0) + +lemma inclusionMoment_nonneg {α Ω : Type*} [Fintype Ω] + (F : Ω → Finset α) (s : Finset α) : 0 ≤ inclusionMoment F s := by + classical + unfold inclusionMoment finiteMean + positivity + +lemma indicator_subset_prod {α : Type*} [DecidableEq α] (A s : Finset α) : + (if s ⊆ A then (1 : ℝ) else 0) = ∏ i ∈ s, (if i ∈ A then 1 else 0) := by + by_cases h : s ⊆ A + · rw [ite_eq_left h] + exact (Finset.prod_eq_one (fun i hi => ite_eq_left (h hi))).symm + · rw [ite_eq_right h] + obtain ⟨i, hi, hiA⟩ := Finset.not_subset.mp h + exact (Finset.prod_eq_zero hi (ite_eq_right hiA)).symm + +lemma inclusionMoment_const {α Ω : Type*} [DecidableEq α] [Fintype Ω] [Nonempty Ω] + (A s : Finset α) : inclusionMoment (fun _ : Ω => A) s = + if s ⊆ A then 1 else 0 := by + classical + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + by_cases h : s ⊆ A <;> simp [inclusionMoment, finiteMean, h, hn] + +lemma cylinder_const {α Ω : Type*} [Fintype Ω] [Nonempty Ω] (A : Finset α) : + CylinderBound (inclusionMoment (fun _ : Ω => A)) + (fun i => inclusionMoment (fun _ : Ω => A) {i}) := by + classical + intro s + simp only [inclusionMoment_const, Finset.singleton_subset_iff] + exact (indicator_subset_prod A s).le + +noncomputable def fairSetSwap {α Ω : Type*} [DecidableEq α] + (F : Ω → Finset α) (a b : α) : Ω × Bool → Finset α := + fun ω => if ω.2 then (F ω.1).image (Equiv.swap a b) else F ω.1 + +lemma subset_swap_image_iff {α : Type*} [DecidableEq α] + (A s : Finset α) (a b : α) : + s ⊆ A.image (Equiv.swap a b) ↔ s.image (Equiv.swap a b) ⊆ A := by + constructor + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := Equiv.swap a b) + simpa only [Finset.image_image, Function.comp_def, Equiv.swap_apply_self, Finset.image_id'] using h' + +lemma inclusionMoment_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) (s : Finset α) : + inclusionMoment (fairSetSwap F a b) s = + (inclusionMoment F s + inclusionMoment F (s.image (Equiv.swap a b))) / 2 := by + classical + simp only [inclusionMoment, finiteMean, Fintype.sum_prod_type, Fintype.sum_bool, + fairSetSwap, Bool.false_eq_true, ↓reduceIte, Fintype.card_prod, Fintype.card_bool, + Nat.cast_mul, Nat.cast_ofNat, subset_swap_image_iff, Finset.sum_add_distrib] + rw [div_mul_eq_div_div, add_div] + ring_nf + +lemma cylinder_fairSetSwap {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (a b : α) + (h : CylinderBound (inclusionMoment F) (fun i => inclusionMoment F {i})) : + CylinderBound (inclusionMoment (fairSetSwap F a b)) + (fun i => inclusionMoment (fairSetSwap F a b) {i}) := by + classical + have h' := h.fair_swap (fun i => inclusionMoment_nonneg F {i}) a b + intro s + simpa only [inclusionMoment_fairSetSwap, Finset.image_singleton] using h' s + +def SwitchSamples : ℕ → Type + | 0 => Unit + | n + 1 => SwitchSamples n × Bool + +instance (n : ℕ) : Fintype (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Fintype Unit) + | succ n ih => exact inferInstanceAs (Fintype (SwitchSamples n × Bool)) + +instance (n : ℕ) : Nonempty (SwitchSamples n) := by + induction n with + | zero => exact inferInstanceAs (Nonempty Unit) + | succ n ih => exact inferInstanceAs (Nonempty (SwitchSamples n × Bool)) + +noncomputable def switchedSet {α : Type*} [DecidableEq α] (A : Finset α) : + (L : List (α × α)) → SwitchSamples L.length → Finset α + | [], _ => A + | (a,b) :: L, ω => fairSetSwap (switchedSet A L) a b ω + +lemma switchedSet_cylinder {α : Type*} [DecidableEq α] (A : Finset α) + (L : List (α × α)) : + CylinderBound (inclusionMoment (switchedSet A L)) + (fun i => inclusionMoment (switchedSet A L) {i}) := by + induction L with + | nil => exact cylinder_const A + | cons e L ih => exact cylinder_fairSetSwap (switchedSet A L) e.1 e.2 ih + +inductive QueryTree (ι : Type*) + | reject : QueryTree ι + | accept : QueryTree ι + | branch (i : ι) (zero one : QueryTree ι) : QueryTree ι + | force (i : ι) (b : Bool) (next : QueryTree ι) : QueryTree ι + +namespace QueryTree + +variable {ι : Type*} [DecidableEq ι] + +def queries : QueryTree ι → Finset ι + | reject => ∅ + | accept => ∅ + | branch i zero one => insert i (queries zero ∪ queries one) + | force i _ next => insert i (queries next) + +def Fresh : QueryTree ι → Prop + | reject => True + | accept => True + | branch i zero one => i ∉ queries zero ∧ i ∉ queries one ∧ Fresh zero ∧ Fresh one + | force i _ next => i ∉ queries next ∧ Fresh next + +def weighted : QueryTree ι → (ι → Bool) → ℝ + | reject, _ => 0 + | accept, _ => 1 + | branch i zero one, ω => if ω i then weighted one ω else weighted zero ω + | force i b next, ω => if ω i = b then 2 * weighted next ω else 0 + +omit [DecidableEq ι] in +lemma weighted_nonneg (T : QueryTree ι) (ω : ι → Bool) : 0 ≤ T.weighted ω := by + induction T with + | reject => exact le_rfl + | accept => exact zero_le_one + | branch i zero one ih₀ ih₁ => simpa only [weighted] using ite_nonneg ih₁ ih₀ + | force i b next ih => simpa only [weighted] using ite_nonneg (mul_nonneg (by norm_num) ih) le_rfl + +lemma weighted_congr (T : QueryTree ι) {ω η : ι → Bool} + (h : ∀ i ∈ T.queries, ω i = η i) : T.weighted ω = T.weighted η := by + induction T with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih₀ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_left _ hj))), + ih₁ (fun j hj => h j (Finset.mem_insert_of_mem (Finset.mem_union_right _ hj)))] + | force i b next ih => + have hi := h i (Finset.mem_insert_self _ _) + simp only [weighted, hi] + rw [ih (fun j hj => h j (Finset.mem_insert_of_mem hj))] + +def flipCoin (i : ι) : Equiv.Perm (ι → Bool) := + (show Function.Involutive (fun ω : ι → Bool => Function.update ω i (!(ω i))) from by + intro ω + funext j + by_cases h : j = i + · subst j; simp + · simp [Function.update_of_ne h]).toPerm + +lemma flipCoin_apply_eq (i : ι) (ω : ι → Bool) : flipCoin i ω i = !(ω i) := by + change Function.update ω i (!(ω i)) i = _ + exact Function.update_self _ _ _ + +lemma flipCoin_apply_ne (i j : ι) (h : j ≠ i) (ω : ι → Bool) : + flipCoin i ω j = ω j := by + change Function.update ω i (!(ω i)) j = _ + exact Function.update_of_ne h _ _ + +lemma weighted_flip_of_not_mem (T : QueryTree ι) (i : ι) (hi : i ∉ T.queries) + (ω : ι → Bool) : T.weighted (flipCoin i ω) = T.weighted ω := by + apply weighted_congr + intro j hj + exact flipCoin_apply_ne i j (fun h => hi (h ▸ hj)) ω + +lemma mean_indicator_bit [Fintype ι] (f : (ι → Bool) → ℝ) (i : ι) (b : Bool) + (hf : ∀ ω, f (flipCoin i ω) = f ω) : + finiteMean (fun ω => if ω i = b then f ω else 0) = finiteMean f / 2 := by + let g := fun ω : ι → Bool => if ω i = b then f ω else 0 + have hp (ω : ι → Bool) : g ω + g (flipCoin i ω) = f ω := by + dsimp [g] + rw [flipCoin_apply_eq, hf] + cases hω : ω i <;> cases b <;> simp + have hs := Equiv.sum_comp (flipCoin i) g + have hadd : (∑ ω, g ω) + (∑ ω, g (flipCoin i ω)) = ∑ ω, f ω := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun ω _ => hp ω) + unfold finiteMean + change (∑ ω, g ω) / _ = _ + rw [hs] at hadd + have hh : (∑ ω, g ω) = (∑ ω, f ω) / 2 := by linarith + rw [hh] + ring + +lemma mean_weighted_le_one [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) : + finiteMean T.weighted ≤ 1 := by + induction T with + | reject => simp [weighted, finiteMean] + | accept => simp [weighted, finiteMean] + | branch i zero one ih₀ ih₁ => + obtain ⟨hz, ho, hfz, hfo⟩ := hT + have h₀ := mean_indicator_bit zero.weighted i false (zero.weighted_flip_of_not_mem i hz) + have h₁ := mean_indicator_bit one.weighted i true (one.weighted_flip_of_not_mem i ho) + have he : finiteMean (branch i zero one).weighted = + finiteMean (fun ω => if ω i = false then zero.weighted ω else 0) + + finiteMean (fun ω => if ω i = true then one.weighted ω else 0) := by + unfold finiteMean + rw [← add_div, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + cases hω : ω i <;> simp [weighted, hω] + rw [he, h₀, h₁] + linarith [ih₀ hfz, ih₁ hfo] + | force i b next ih => + obtain ⟨hi, hn⟩ := hT + have hm := mean_indicator_bit next.weighted i b (next.weighted_flip_of_not_mem i hi) + have he : finiteMean (force i b next).weighted = + 2 * finiteMean (fun ω => if ω i = b then next.weighted ω else 0) := by + unfold finiteMean + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : ω i = b <;> simp [weighted, h] + rw [he, hm] + linarith [ih hn] + +def succeeds : QueryTree ι → (ι → Bool) → Bool + | reject, _ => false + | accept, _ => true + | branch i zero one, ω => if ω i then succeeds one ω else succeeds zero ω + | force i b next, ω => if ω i = b then succeeds next ω else false + +def charge : QueryTree ι → (ι → Bool) → ℕ + | reject, _ => 0 + | accept, _ => 0 + | branch i zero one, ω => if ω i then charge one ω else charge zero ω + | force i b next, ω => if ω i = b then charge next ω + 1 else 0 + +omit [DecidableEq ι] in +lemma weighted_eq (T : QueryTree ι) (ω : ι → Bool) : + T.weighted ω = if T.succeeds ω then (2 : ℝ) ^ T.charge ω else 0 := by + induction T with + | reject => rfl + | accept => norm_num [weighted, succeeds, charge] + | branch i zero one ih₀ ih₁ => + cases h : ω i <;> simp [weighted, succeeds, charge, h, ih₀, ih₁] + | force i b next ih => + by_cases h : ω i = b + · simp only [weighted, succeeds, charge, h, ↓reduceIte, ih] + cases hs : next.succeeds ω <;> simp [pow_succ, mul_comm] + · simp [weighted, succeeds, h] + +lemma success_probability_le [Fintype ι] (T : QueryTree ι) (hT : T.Fresh) + (K : ℕ) (hK : ∀ ω, T.succeeds ω = true → K ≤ T.charge ω) : + finiteMean (fun ω => if T.succeeds ω then (1 : ℝ) else 0) ≤ 1 / (2 : ℝ) ^ K := by + have hw (ω : ι → Bool) : + (2 : ℝ) ^ K * (if T.succeeds ω then (1 : ℝ) else 0) ≤ T.weighted ω := by + rw [weighted_eq] + cases hs : T.succeeds ω + · simp + · simpa using pow_le_pow_right₀ (show (1 : ℝ) ≤ 2 by norm_num) (hK ω hs) + have hn : 0 ≤ (Fintype.card (ι → Bool) : ℝ) := Nat.cast_nonneg _ + have hm := div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun ω (_ : ω ∈ Finset.univ) => hw ω)) hn + rw [← Finset.mul_sum, mul_div_assoc] at hm + change (2 : ℝ) ^ K * finiteMean (fun ω => if T.succeeds ω then 1 else 0) ≤ + finiteMean T.weighted at hm + exact (le_div_iff₀ (pow_pos (by norm_num) K)).mpr (by + rw [mul_comm] + exact hm.trans (mean_weighted_le_one T hT)) + +end QueryTree + +def encodeButterfly : (d : ℕ) → Butterfly d → SwitchIndex d → Bool + | 0, _, i => nomatch i + | _d + 1, b, Sum.inl y => b.1 y + | d + 1, b, Sum.inr (ε,i) => encodeButterfly d (b.2 ε) i + +lemma decode_encodeButterfly (d : ℕ) (b : Butterfly d) : + decodeButterfly d (encodeButterfly d b) = b := by + induction d with + | zero => exact Unit.ext _ _ + | succ d ih => + apply Prod.ext + · rfl + · funext ε + exact ih (b.2 ε) + +lemma encode_decodeButterfly (d : ℕ) (ω : SwitchIndex d → Bool) : + encodeButterfly d (decodeButterfly d ω) = ω := by + induction d with + | zero => funext i; exact Empty.elim i + | succ d ih => + funext i + cases i with + | inl y => rfl + | inr z => exact congrFun (ih (fun i => ω (Sum.inr (z.1,i)))) z.2 + +def butterflyCoinEquiv (d : ℕ) : (SwitchIndex d → Bool) ≃ Butterfly d where + toFun := decodeButterfly d + invFun := encodeButterfly d + left_inv := encode_decodeButterfly d + right_inv := decode_encodeButterfly d + +noncomputable def routeDomain : (d : ℕ) → Card d → Card d → Finset (SwitchIndex d) + | 0, _, _ => ∅ + | d + 1, x, y => by + classical + exact insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image (fun i => Sum.inr (x 0,i))) + +def routeValue : (d : ℕ) → Card d → Card d → SwitchIndex d → Bool + | 0, _, _, i => nomatch i + | _d + 1, x, y, Sum.inl _ => Bool.xor (x 0) (y 0) + | d + 1, x, y, Sum.inr (_,i) => routeValue d (Fin.tail x) (Fin.tail y) i + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ExposedCoins.lean b/lean/OAI/Probability/ThorpRouting/Tail/ExposedCoins.lean index 6ff3cfeeac4f5cecd3517a414799559106006a0c..3503b48e92c3773f3cdaac85342621cb1ab8364e 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ExposedCoins.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ExposedCoins.lean @@ -1,860 +1,860 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.Coins - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter - -lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by - classical - induction d with - | zero => rfl - | succ d ih => - change (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 - rw [Finset.card_insert_of_notMem (by simp)] - rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] - -lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by - cases a <;> cases b <;> cases c <;> decide - -lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : - butterflyPerm d (decodeButterfly d ω) x = y ↔ - ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by - classical - induction d with - | zero => - have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ - simp [he, routeDomain] - | succ d ih => - let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) - change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ - have hv : v = Fin.tail y ↔ - ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), - ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := - ih _ _ _ - constructor - · intro h i hi - have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h - have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by - have he := congrFun h 0 - simp only [Fin.cons_zero, ht] at he - exact (xor_eq_iff _ _ _).mp he - rcases Finset.mem_insert.mp hi with htop | hchild - · subst i - exact hh - · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild - exact hv.mp ht j hj - · intro h - have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) - have ht : v = Fin.tail y := hv.mpr (fun i hi => - h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) - have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := - (xor_eq_iff _ _ _).mpr hh - rw [ht, hh', Fin.cons_self_tail] - -lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by - unfold finiteMean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) : - finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = - 1 / (2 : ℝ) ^ s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 - have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - dsimp [f] - simp only [he] - have hm := QueryTree.mean_indicator_bit f i (v i) hf - have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = - (fun ω => if ω i = v i then f ω else 0) := by - funext ω - by_cases h : ω i = v i <;> simp [f, h] - rw [he, hm] - change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ - rw [ih, Finset.card_insert_of_notMem hi, pow_succ] - ring - -def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := - fun i => if i ∈ R then η i else ω i - -lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] - (s R : Finset ι) (v η : ι → Bool) : - finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by - have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ - (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by - constructor - · intro h - constructor - · intro i hi - simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 - · intro i hi - simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 - · rintro ⟨ho, hf⟩ i hi - by_cases hR : i ∈ R - · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) - · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) - have hm : finiteMean (fun ω : ι → Bool => - if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = - finiteMean (fun ω : ι → Bool => - if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [he ω]) - rw [hm] - by_cases h : ∀ i ∈ s ∩ R, η i = v i - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h - simp only [hp, true_and, ↓reduceIte] - exact mean_coinCylinder (s \ R) v - · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h - simp only [hp, false_and, ↓reduceIte] - simp [finiteMean] - -lemma butterfly_closure_probability (d : ℕ) (x y : Card d) - (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then - (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder_exposed] - congr 1 - have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter, card_routeDomain] - have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * - (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by - rw [← pow_add] - exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm - rw [hp] - have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) - field_simp - -lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : - finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := - finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) - rw [he, mean_coinCylinder, card_routeDomain] - -def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d - | 0, _, i => nomatch i - | d + 1, b, Sum.inl y => - (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), - Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) - | d + 1, b, Sum.inr (ε,i) => - (Fin.cons ε (switchUsers d (b.2 ε) i).1, - Fin.cons ε (switchUsers d (b.2 ε) i).2) - -lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : - (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - intro h - have := congrFun h 0 - simp only [switchUsers, Fin.cons_zero] at this - exact Bool.false_ne_true this - | inr z => - intro h - exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) - -lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : - Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by - constructor - · intro h - exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, - by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ - · rintro ⟨rfl,rfl⟩ - exact Fin.cons_self_tail x - -lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : - i ∈ routeDomain d x (butterflyPerm d b x) ↔ - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by - classical - induction d with - | zero => exact Empty.elim i - | succ d ih => - cases i with - | inl y => - change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, - Sum.inr_ne_inl, and_false, exists_false, or_false] - change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ - simp only [switchUsers, cons_eq_iff] - cases x 0 <;> simp [Equiv.symm_apply_eq] - | inr z => - obtain ⟨ε,i⟩ := z - change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) - ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ - simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, - Sum.inr.injEq, Prod.mk.injEq] - change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ - x 0 = ε ∧ j = i) ↔ _ - simp only [switchUsers, cons_eq_iff] - constructor - · rintro ⟨j,hj,hε,rfl⟩ - subst ε - rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h - · exact Or.inl ⟨rfl,h⟩ - · exact Or.inr ⟨rfl,h⟩ - · rintro (⟨hε,h⟩ | ⟨hε,h⟩) - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ - · subst ε - exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ - -lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : - (Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by - classical - have he : Finset.univ.filter (fun i : SwitchIndex d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - routeDomain d x (butterflyPerm d b x) := by - ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] - rw [he,card_routeDomain] - -lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = - (d : ℝ) * ∑ x : Card d, w x := by - classical - calc - _ = ∑ i : SwitchIndex d, ∑ x : Card d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero] - have he : Finset.univ.filter (fun x : Card d => - (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = - {(switchUsers d b i).1, (switchUsers d b i).2} := by - ext x; simp [eq_comm] - rw [he, Finset.sum_pair (switchUsers_ne d b i)] - _ = ∑ x : Card d, ∑ i : SwitchIndex d, - if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := - Finset.sum_comm - _ = ∑ x : Card d, (d : ℝ) * w x := by - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_ite] - simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, - card_switches_using] - _ = _ := by rw [Finset.mul_sum] - -lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : - ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ - (d : ℝ) / 2 * ∑ x : Card d, w x := by - have h : 2 * (∑ i : SwitchIndex d, - min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ - ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), - min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] - rw [switch_incidence_sum] at h - linarith - -lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : - x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by - classical - constructor - · intro h - obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy - rw [← hxy, ← hyε, Fin.cons_self_tail] - exact hys - · intro h - exact Finset.mem_image.mpr ⟨Fin.cons ε x, - Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ - -lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) - (s : Finset (Card (d + 1))) (y : Card d) : - y ∈ topMeetings b s ↔ - (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by - classical - have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ - (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by - constructor - · intro h - obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h - simpa only [Equiv.symm_apply_apply] using hx - · intro h - exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ - simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] - -lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - encounters d b s = ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by - classical - induction d with - | zero => - simp only [encounters] - symm - apply Finset.sum_eq_zero - intro i _ - exact Empty.elim i - | succ d ih => - change encounters d (b.2 false) (childMarks s false) + - encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = - ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ - rw [Fintype.sum_sum_type, Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [ih,ih] - have ht : (∑ y : Card d, - if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ - (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = - (topMeetings b s).card := by - simp only [← mem_topMeetings] - simp - rw [ht] - simp only [mem_childMarks, switchUsers] - ac_rfl - -lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : - (∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ - (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by - classical - have he : (encounters d b s : ℝ) = - ∑ i : SwitchIndex d, - if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by - rw [encounters_eq_switch_sum, Nat.cast_sum] - apply Finset.sum_congr rfl - intro i _ - split_ifs <;> simp - rw [← he] - exact butterfly_encounters d b s - -namespace QueryTree -variable {ι : Type*} [DecidableEq ι] - -def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι - | reject, _, _ => reject - | accept, _, _ => accept - | branch i zero one, R, η => - if i ∈ R then (if η i then memo one R η else memo zero R η) else - branch i (memo zero (insert i R) (Function.update η i false)) - (memo one (insert i R) (Function.update η i true)) - | force i b next, R, η => - if i ∈ R then (if η i = b then memo next R η else reject) else - force i b (memo next (insert i R) (Function.update η i b)) - -lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - Disjoint (memo T R η).queries R := by - induction T generalizing R η with - | reject => simp [memo,queries] - | accept => simp [memo,queries] - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] - exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), - (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,queries] - · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] - exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ - -lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : - (memo T R η).Fresh := by - induction T generalizing R η with - | reject => trivial - | accept => trivial - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η - · exact ih₁ R η - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm - (Finset.mem_insert_self _ _), - fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm - (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte] - by_cases hb : η i = b - · simpa only [hb,↓reduceIte] using ih R η - · simp [hb,Fresh] - · simp only [memo,hi,↓reduceIte,Fresh] - exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm - (Finset.mem_insert_self _ _),ih _ _⟩ - -lemma update_agrees {R : Finset ι} {η ω : ι → Bool} - (h : ∀ i ∈ R, η i = ω i) (i : ι) : - ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by - intro j hj - rcases Finset.mem_insert.mp hj with rfl | hj - · simp - · by_cases hji : j = i - · subst j; simp - · rw [Function.update_of_ne hji] - exact h j hj - -lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,succeeds,h i hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,succeeds] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte,succeeds] - exact ih R η h - · simp [hb,succeeds] - · simp only [memo,hi,↓reduceIte,succeeds] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih _ _ (by simpa only [hb] using update_agrees h i) - · simp [hb] - -def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 - -lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) - (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by - induction T generalizing R η with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] - cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ R η h - · exact ih₁ R η h - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) - · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) - | force i b next ih => - by_cases hi : i ∈ R - · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - exact ih R η h - · simp [hb,charge] - · simp only [memo,hi,↓reduceIte,charge,freshCharge] - by_cases hb : ω i = b - · simp only [hb,↓reduceIte] - rw [ih _ _ (by simpa only [hb] using update_agrees h i)] - · simp [hb] - -lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by - let η : ι → Bool := fun _ => false - have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) - have he : finiteMean (memo T ∅ η).weighted = - finiteMean (fun ω : ι → Bool => - if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] - rw [he] at hm - exact hm - - -def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → - (Card d → QueryTree ι) → QueryTree ι - | 0, _, x, k => k x - | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) - (fun y => branch (e (Sum.inl y)) - (k (Fin.cons (Bool.xor (x 0) false) y)) - (k (Fin.cons (Bool.xor (x 0) true) y))) - -omit [DecidableEq ι] in -lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).succeeds ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω - cases ω (e (Sum.inl y)) <;> rfl - -lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - freshCharge (followPath d e x k) R ω = - freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - classical - induction d generalizing R with - | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) - change (if ω (e (Sum.inl y)) then - freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else - freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = - freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) - (R ∪ (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω - have hs : (routeDomain (d+1) x - (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = - insert (e (Sum.inl y)) S := by - let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e - change (insert (Sum.inl y) - ((routeDomain d (Fin.tail x) y).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ - rw [Finset.image_insert, Finset.image_image] - rfl - rw [hs,Finset.union_insert] - cases ω (e (Sum.inl y)) <;> rfl - -def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι - | [], _, k => k - | i :: L, v, k => force i (v i) (forceList L v k) - -omit [DecidableEq ι] in -lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : - (forceList L v k).succeeds ω = - if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by - induction L with - | nil => simp [forceList] - | cons i L ih => - simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] - by_cases h : ω i = v i <;> simp [h] - -lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) - (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : - freshCharge (forceList L v k) R ω = - freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by - induction L generalizing R with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), - ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.toFinset_cons] - have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp - rw [hs] - by_cases hi : i ∈ R - · rw [ite_eq_left hi] - have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he,Nat.add_zero] - · rw [ite_eq_right hi] - have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by - ext j - by_cases hji : j = i - · subst j; simp [hi] - · simp [hji] - rw [he, Finset.card_insert_of_notMem (by simp)] - omega - - -def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ - | reject, _, _ => 0 - | accept, _, _ => 0 - | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω - else staleCharge zero (insert i R) ω - | force i b next, R, ω => if ω i = b then - staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 - -lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by - induction T generalizing R with - | reject => rfl - | accept => rfl - | branch i zero one ih₀ ih₁ => - cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] - | force i b next ih => - by_cases hb : ω i = b - · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] - have he := ih (insert i R) - by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega - · simp [freshCharge,staleCharge,charge,hb] - -omit [DecidableEq ι] in -lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (ω : ι → Bool) : - (followPath d e x k).charge ω = - (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by - induction d with - | zero => rfl - | succ d ih => - rw [followPath, ih] - let y := butterflyPerm d - (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) - change (if ω (e (Sum.inl y)) then - (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else - (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = - (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω - cases ω (e (Sum.inl y)) <;> rfl - -omit [DecidableEq ι] in -lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) - (h : ∀ i ∈ L, ω i = v i) : - (forceList L v k).charge ω = k.charge ω + L.length := by - induction L with - | nil => simp [forceList] - | cons i L ih => - rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), - ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] - simp only [List.length_cons,Nat.add_assoc] - -noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : - QueryTree (SwitchIndex d) := - forceList (routeDomain d x y).toList (routeValue d x y) k - -lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) : - (closePath d x y k).succeeds ω = - if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by - unfold closePath - rw [forceList_succeeds] - simp only [Finset.mem_toList, ← butterfly_endpoint_iff] - -lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).charge ω = k.charge ω + d := by - unfold closePath - rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] - -lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).freshCharge R ω = - k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by - unfold closePath - rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using - (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] - -lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) - (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : butterflyPerm d (decodeButterfly d ω) x = y) : - (closePath d x y k).staleCharge R ω = - k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by - have h₀ := fresh_add_stale (closePath d x y k) R ω - have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω - rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ - have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_routeDomain] - omega - -noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : - ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → - QueryTree (SwitchIndex d) - | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject - | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x - (fun y => seekCycle d S a r y (insert x V) k) else reject - -lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) - (ω : SwitchIndex d → Bool) (K : ℕ) - (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) - (hs : (seekCycle d S a r x V k).succeeds ω = true) : - (seekCycle d S a r x V k).charge ω = K + d := by - induction r generalizing x V with - | zero => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs - split_ifs at hs with he - · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] - · simp [seekCycle,hv,succeeds] at hs - | succ r ih => - by_cases hv : x ∈ S ∧ x ∉ V - · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs - rw [seekCycle,ite_eq_left hv,followPath_raw_charge] - exact ih _ _ hs - · simp [seekCycle,hv,succeeds] at hs - -noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : - List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) - | [], _ => accept - | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) - -lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) - (V : Finset (Card d)) (ω : SwitchIndex d → Bool) - (hs : (seekCycles d S L V).succeeds ω = true) : - (seekCycles d S L V).charge ω = L.length * d := by - induction L generalizing V with - | nil => simp [seekCycles,charge] - | cons ar L ih => - obtain ⟨a,r⟩ := ar - rw [seekCycles] - rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) - (fun V hs => ih V hs) hs] - simp [Nat.add_mul] - -lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : - finiteMean (fun ω : SwitchIndex d → Bool => - if (seekCycles d S L ∅).succeeds ω then - ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by - let T := seekCycles d S L ∅ - have hh := mean_freshCharge_le_one T - have he : finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = - finiteMean (fun ω : SwitchIndex d → Bool => - if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by - apply finiteMean_congr - intro ω - cases hs : T.succeeds ω - · simp - · simp only [↓reduceIte] - have hc := fresh_add_stale T ∅ ω - rw [seekCycles_raw_charge d S L ∅ ω hs] at hc - have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by - rw [←pow_add,hc,←pow_mul,Nat.mul_comm] - rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] - rw [← he] - exact hh - -end QueryTree - -lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by - simp only [finiteMean,Finset.sum_add_distrib,add_div] - -lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : - finiteMean (fun ω => f ω * c) = finiteMean f * c := by - unfold finiteMean - rw [← Finset.sum_mul] - ring - -lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : - finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by - simp only [finiteMean,Finset.sum_div] - exact Finset.sum_comm - -lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} - (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω → ℝ) : - finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by - unfold finiteMean - rw [Fintype.card_congr e] - congr 1 - exact Fintype.sum_equiv e _ _ (fun ω => by simp) - -lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] - (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by - simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, - ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] - have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - field_simp - -lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] - {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] - (c : C) (g : A c → ℝ) : - finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by - rw [finiteMean_equiv (Equiv.piSplitAt c A)] - have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => - g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by - funext z - simp [Equiv.piSplitAt] - rw [he,finiteMean_prod_left] - -lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : - finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by - simp [finiteMean] - -lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by - have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] - have hj := convexOn_exp.map_sum_le (t := Finset.univ) - (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) - (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) - simp only [smul_eq_mul, ← Finset.mul_sum] at hj - simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj - -variable {d A : ℕ} - -def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by - classical - exact Finset.univ.filter (fun x => o x = some i) - -@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : - x ∈ cycleFiber o i ↔ o x = some i := by - classical - simp [cycleFiber] - -abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} - -noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := - 1 / (cycleFiber o i).card - -noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := - match o x with - | none => 0 - | some i => slotWeight o i - -noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i = j then slotWeight o i else 0 - | _, _ => 0 - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.Coins + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter + +lemma card_routeDomain (d : ℕ) (x y : Card d) : (routeDomain d x y).card = d := by + classical + induction d with + | zero => rfl + | succ d ih => + change (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).card = d + 1 + rw [Finset.card_insert_of_notMem (by simp)] + rw [Finset.card_image_of_injective _ (by intro i j h; cases h; rfl), ih] + +lemma xor_eq_iff (a b c : Bool) : Bool.xor a b = c ↔ b = Bool.xor a c := by + cases a <;> cases b <;> cases c <;> decide + +lemma butterfly_endpoint_iff (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) : + butterflyPerm d (decodeButterfly d ω) x = y ↔ + ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i := by + classical + induction d with + | zero => + have he : butterflyPerm 0 (decodeButterfly 0 ω) x = y := Subsingleton.elim _ _ + simp [he, routeDomain] + | succ d ih => + let v := butterflyPerm d (decodeButterfly d (fun i => ω (Sum.inr (x 0,i)))) (Fin.tail x) + change Fin.cons (Bool.xor (x 0) (ω (Sum.inl v))) v = y ↔ _ + have hv : v = Fin.tail y ↔ + ∀ i ∈ routeDomain d (Fin.tail x) (Fin.tail y), + ω (Sum.inr (x 0,i)) = routeValue d (Fin.tail x) (Fin.tail y) i := + ih _ _ _ + constructor + · intro h i hi + have ht : v = Fin.tail y := by simpa using congrArg Fin.tail h + have hh : ω (Sum.inl (Fin.tail y)) = Bool.xor (x 0) (y 0) := by + have he := congrFun h 0 + simp only [Fin.cons_zero, ht] at he + exact (xor_eq_iff _ _ _).mp he + rcases Finset.mem_insert.mp hi with htop | hchild + · subst i + exact hh + · obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hchild + exact hv.mp ht j hj + · intro h + have hh := h (Sum.inl (Fin.tail y)) (Finset.mem_insert_self _ _) + have ht : v = Fin.tail y := hv.mpr (fun i hi => + h (Sum.inr (x 0,i)) (Finset.mem_insert_of_mem (Finset.mem_image_of_mem _ hi))) + have hh' : Bool.xor (x 0) (ω (Sum.inl (Fin.tail y))) = y 0 := + (xor_eq_iff _ _ _).mpr hh + rw [ht, hh', Fin.cons_self_tail] + +lemma finiteMean_congr {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω = g ω) : finiteMean f = finiteMean g := by + unfold finiteMean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +lemma mean_coinCylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) : + finiteMean (fun ω : ι → Bool => if ∀ i ∈ s, ω i = v i then (1 : ℝ) else 0) = + 1 / (2 : ℝ) ^ s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let f := fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0 + have hf : ∀ ω, f (QueryTree.flipCoin i ω) = f ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + dsimp [f] + simp only [he] + have hm := QueryTree.mean_indicator_bit f i (v i) hf + have he : (fun ω : ι → Bool => if ∀ j ∈ insert i s, ω j = v j then (1 : ℝ) else 0) = + (fun ω => if ω i = v i then f ω else 0) := by + funext ω + by_cases h : ω i = v i <;> simp [f, h] + rw [he, hm] + change finiteMean (fun ω : ι → Bool => if ∀ j ∈ s, ω j = v j then (1 : ℝ) else 0) / 2 = _ + rw [ih, Finset.card_insert_of_notMem hi, pow_succ] + ring + +def exposedCoins {ι : Type*} [DecidableEq ι] (R : Finset ι) (η ω : ι → Bool) : ι → Bool := + fun i => if i ∈ R then η i else ω i + +lemma mean_coinCylinder_exposed {ι : Type*} [Fintype ι] [DecidableEq ι] + (s R : Finset ι) (v η : ι → Bool) : + finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + if (∀ i ∈ s ∩ R, η i = v i) then 1 / (2 : ℝ) ^ (s \ R).card else 0 := by + have he (ω : ι → Bool) : (∀ i ∈ s, exposedCoins R η ω i = v i) ↔ + (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) := by + constructor + · intro h + constructor + · intro i hi + simpa [exposedCoins, (Finset.mem_inter.mp hi).2] using h i (Finset.mem_inter.mp hi).1 + · intro i hi + simpa [exposedCoins, (Finset.mem_sdiff.mp hi).2] using h i (Finset.mem_sdiff.mp hi).1 + · rintro ⟨ho, hf⟩ i hi + by_cases hR : i ∈ R + · simpa [exposedCoins, hR] using ho i (Finset.mem_inter.mpr ⟨hi,hR⟩) + · simpa [exposedCoins, hR] using hf i (Finset.mem_sdiff.mpr ⟨hi,hR⟩) + have hm : finiteMean (fun ω : ι → Bool => + if ∀ i ∈ s, exposedCoins R η ω i = v i then (1 : ℝ) else 0) = + finiteMean (fun ω : ι → Bool => + if (∀ i ∈ s ∩ R, η i = v i) ∧ (∀ i ∈ s \ R, ω i = v i) then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [he ω]) + rw [hm] + by_cases h : ∀ i ∈ s ∩ R, η i = v i + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ True := iff_true_intro h + simp only [hp, true_and, ↓reduceIte] + exact mean_coinCylinder (s \ R) v + · have hp : (∀ i ∈ s ∩ R, η i = v i) ↔ False := iff_false_intro h + simp only [hp, false_and, ↓reduceIte] + simp [finiteMean] + +lemma butterfly_closure_probability (d : ℕ) (x y : Card d) + (R : Finset (SwitchIndex d)) (η : SwitchIndex d → Bool) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + if (∀ i ∈ routeDomain d x y ∩ R, η i = routeValue d x y i) then + (2 : ℝ) ^ (routeDomain d x y ∩ R).card / (2 : ℝ) ^ d else 0 := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d (exposedCoins R η ω)) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, exposedCoins R η ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder_exposed] + congr 1 + have hc : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter, card_routeDomain] + have hp : (2 : ℝ) ^ d = (2 : ℝ) ^ (routeDomain d x y \ R).card * + (2 : ℝ) ^ (routeDomain d x y ∩ R).card := by + rw [← pow_add] + exact congrArg (fun n => (2 : ℝ) ^ n) hc.symm + rw [hp] + have hn : (2 : ℝ) ^ (routeDomain d x y ∩ R).card ≠ 0 := pow_ne_zero _ (by norm_num) + field_simp + +lemma butterfly_single_card_uniform (d : ℕ) (x y : Card d) : + finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = 1 / (2 : ℝ) ^ d := by + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if butterflyPerm d (decodeButterfly d ω) x = y then (1 : ℝ) else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ routeDomain d x y, ω i = routeValue d x y i then (1 : ℝ) else 0) := + finiteMean_congr (fun ω => by simp only [butterfly_endpoint_iff]) + rw [he, mean_coinCylinder, card_routeDomain] + +def switchUsers : (d : ℕ) → Butterfly d → SwitchIndex d → Card d × Card d + | 0, _, i => nomatch i + | d + 1, b, Sum.inl y => + (Fin.cons false ((butterflyPerm d (b.2 false)).symm y), + Fin.cons true ((butterflyPerm d (b.2 true)).symm y)) + | d + 1, b, Sum.inr (ε,i) => + (Fin.cons ε (switchUsers d (b.2 ε) i).1, + Fin.cons ε (switchUsers d (b.2 ε) i).2) + +lemma switchUsers_ne (d : ℕ) (b : Butterfly d) (i : SwitchIndex d) : + (switchUsers d b i).1 ≠ (switchUsers d b i).2 := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + intro h + have := congrFun h 0 + simp only [switchUsers, Fin.cons_zero] at this + exact Bool.false_ne_true this + | inr z => + intro h + exact ih (b.2 z.1) z.2 (by simpa only [switchUsers, Fin.tail_cons] using congrArg Fin.tail h) + +lemma cons_eq_iff {d : ℕ} (ε : Bool) (a : Card d) (x : Card (d + 1)) : + Fin.cons ε a = x ↔ ε = x 0 ∧ a = Fin.tail x := by + constructor + · intro h + exact ⟨by simpa only [Fin.cons_zero] using congrFun h 0, + by simpa only [Fin.tail_cons] using congrArg Fin.tail h⟩ + · rintro ⟨rfl,rfl⟩ + exact Fin.cons_self_tail x + +lemma mem_routeDomain_iff_user (d : ℕ) (b : Butterfly d) (x : Card d) (i : SwitchIndex d) : + i ∈ routeDomain d x (butterflyPerm d b x) ↔ + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x := by + classical + induction d with + | zero => exact Empty.elim i + | succ d ih => + cases i with + | inl y => + change Sum.inl y ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq, Finset.mem_image, + Sum.inr_ne_inl, and_false, exists_false, or_false] + change y = butterflyPerm d (b.2 (x 0)) (Fin.tail x) ↔ _ + simp only [switchUsers, cons_eq_iff] + cases x 0 <;> simp [Equiv.symm_apply_eq] + | inr z => + obtain ⟨ε,i⟩ := z + change Sum.inr (ε,i) ∈ insert (Sum.inl (Fin.tail (butterflyPerm (d+1) b x))) + ((routeDomain d (Fin.tail x) (Fin.tail (butterflyPerm (d+1) b x))).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) ↔ _ + simp only [Finset.mem_insert, Sum.inr_ne_inl, false_or, Finset.mem_image, + Sum.inr.injEq, Prod.mk.injEq] + change (∃ j, j ∈ routeDomain d (Fin.tail x) (butterflyPerm d (b.2 (x 0)) (Fin.tail x)) ∧ + x 0 = ε ∧ j = i) ↔ _ + simp only [switchUsers, cons_eq_iff] + constructor + · rintro ⟨j,hj,hε,rfl⟩ + subst ε + rcases (ih (b.2 (x 0)) (Fin.tail x) j).mp hj with h | h + · exact Or.inl ⟨rfl,h⟩ + · exact Or.inr ⟨rfl,h⟩ + · rintro (⟨hε,h⟩ | ⟨hε,h⟩) + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inl h),rfl,rfl⟩ + · subst ε + exact ⟨i,(ih (b.2 (x 0)) (Fin.tail x) i).mpr (Or.inr h),rfl,rfl⟩ + +lemma card_switches_using (d : ℕ) (b : Butterfly d) (x : Card d) : + (Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x)).card = d := by + classical + have he : Finset.univ.filter (fun i : SwitchIndex d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + routeDomain d x (butterflyPerm d b x) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_routeDomain_iff_user] + rw [he,card_routeDomain] + +lemma switch_incidence_sum (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) = + (d : ℝ) * ∑ x : Card d, w x := by + classical + calc + _ = ∑ i : SwitchIndex d, ∑ x : Card d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero] + have he : Finset.univ.filter (fun x : Card d => + (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x) = + {(switchUsers d b i).1, (switchUsers d b i).2} := by + ext x; simp [eq_comm] + rw [he, Finset.sum_pair (switchUsers_ne d b i)] + _ = ∑ x : Card d, ∑ i : SwitchIndex d, + if (switchUsers d b i).1 = x ∨ (switchUsers d b i).2 = x then w x else 0 := + Finset.sum_comm + _ = ∑ x : Card d, (d : ℝ) * w x := by + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_ite] + simp only [Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, + card_switches_using] + _ = _ := by rw [Finset.mul_sum] + +lemma weighted_switch_min_bound (d : ℕ) (b : Butterfly d) (w : Card d → ℝ) : + ∑ i : SwitchIndex d, min (w (switchUsers d b i).1) (w (switchUsers d b i).2) ≤ + (d : ℝ) / 2 * ∑ x : Card d, w x := by + have h : 2 * (∑ i : SwitchIndex d, + min (w (switchUsers d b i).1) (w (switchUsers d b i).2)) ≤ + ∑ i : SwitchIndex d, (w (switchUsers d b i).1 + w (switchUsers d b i).2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + linarith [min_le_left (w (switchUsers d b i).1) (w (switchUsers d b i).2), + min_le_right (w (switchUsers d b i).1) (w (switchUsers d b i).2)] + rw [switch_incidence_sum] at h + linarith + +lemma mem_childMarks {d : ℕ} (s : Finset (Card (d + 1))) (ε : Bool) (x : Card d) : + x ∈ childMarks s ε ↔ Fin.cons ε x ∈ s := by + classical + constructor + · intro h + obtain ⟨y,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hys,hyε⟩ := Finset.mem_filter.mp hy + rw [← hxy, ← hyε, Fin.cons_self_tail] + exact hys + · intro h + exact Finset.mem_image.mpr ⟨Fin.cons ε x, + Finset.mem_filter.mpr ⟨h,by simp⟩,by simp⟩ + +lemma mem_topMeetings {d : ℕ} (b : Butterfly (d + 1)) + (s : Finset (Card (d + 1))) (y : Card d) : + y ∈ topMeetings b s ↔ + (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s := by + classical + have he (ε : Bool) : y ∈ (childMarks s ε).image (butterflyPerm d (b.2 ε)) ↔ + (butterflyPerm d (b.2 ε)).symm y ∈ childMarks s ε := by + constructor + · intro h + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp h + simpa only [Equiv.symm_apply_apply] using hx + · intro h + exact Finset.mem_image.mpr ⟨_,h,Equiv.apply_symm_apply _ _⟩ + simp only [topMeetings, Finset.mem_inter, he, mem_childMarks, switchUsers] + +lemma encounters_eq_switch_sum (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + encounters d b s = ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then 1 else 0 := by + classical + induction d with + | zero => + simp only [encounters] + symm + apply Finset.sum_eq_zero + intro i _ + exact Empty.elim i + | succ d ih => + change encounters d (b.2 false) (childMarks s false) + + encounters d (b.2 true) (childMarks s true) + (topMeetings b s).card = + ∑ i : Sum (Card d) (Bool × SwitchIndex d), _ + rw [Fintype.sum_sum_type, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [ih,ih] + have ht : (∑ y : Card d, + if (switchUsers (d+1) b (Sum.inl y)).1 ∈ s ∧ + (switchUsers (d+1) b (Sum.inl y)).2 ∈ s then 1 else 0) = + (topMeetings b s).card := by + simp only [← mem_topMeetings] + simp + rw [ht] + simp only [mem_childMarks, switchUsers] + ac_rfl + +lemma marked_switch_entropy_bound (d : ℕ) (b : Butterfly d) (s : Finset (Card d)) : + (∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0) ≤ + (s.card : ℝ) * Real.log s.card / (2 * Real.log 2) := by + classical + have he : (encounters d b s : ℝ) = + ∑ i : SwitchIndex d, + if (switchUsers d b i).1 ∈ s ∧ (switchUsers d b i).2 ∈ s then (1:ℝ) else 0 := by + rw [encounters_eq_switch_sum, Nat.cast_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + rw [← he] + exact butterfly_encounters d b s + +namespace QueryTree +variable {ι : Type*} [DecidableEq ι] + +def memo : QueryTree ι → Finset ι → (ι → Bool) → QueryTree ι + | reject, _, _ => reject + | accept, _, _ => accept + | branch i zero one, R, η => + if i ∈ R then (if η i then memo one R η else memo zero R η) else + branch i (memo zero (insert i R) (Function.update η i false)) + (memo one (insert i R) (Function.update η i true)) + | force i b next, R, η => + if i ∈ R then (if η i = b then memo next R η else reject) else + force i b (memo next (insert i R) (Function.update η i b)) + +lemma memo_queries_disjoint (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + Disjoint (memo T R η).queries R := by + induction T generalizing R η with + | reject => simp [memo,queries] + | accept => simp [memo,queries] + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left,Finset.disjoint_union_left] + exact ⟨by simp, (ih₀ (insert i R) _).mono_right (Finset.subset_insert _ _), + (ih₁ (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,queries] + · simp only [memo,hi,↓reduceIte,queries,Finset.disjoint_insert_left] + exact ⟨by simp,(ih (insert i R) _).mono_right (Finset.subset_insert _ _)⟩ + +lemma memo_fresh (T : QueryTree ι) (R : Finset ι) (η : ι → Bool) : + (memo T R η).Fresh := by + induction T generalizing R η with + | reject => trivial + | accept => trivial + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + cases η i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η + · exact ih₁ R η + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint zero (insert i R) _) hm + (Finset.mem_insert_self _ _), + fun hm => Finset.disjoint_left.mp (memo_queries_disjoint one (insert i R) _) hm + (Finset.mem_insert_self _ _), ih₀ _ _,ih₁ _ _⟩ + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte] + by_cases hb : η i = b + · simpa only [hb,↓reduceIte] using ih R η + · simp [hb,Fresh] + · simp only [memo,hi,↓reduceIte,Fresh] + exact ⟨fun hm => Finset.disjoint_left.mp (memo_queries_disjoint next (insert i R) _) hm + (Finset.mem_insert_self _ _),ih _ _⟩ + +lemma update_agrees {R : Finset ι} {η ω : ι → Bool} + (h : ∀ i ∈ R, η i = ω i) (i : ι) : + ∀ j ∈ insert i R, Function.update η i (ω i) j = ω j := by + intro j hj + rcases Finset.mem_insert.mp hj with rfl | hj + · simp + · by_cases hji : j = i + · subst j; simp + · rw [Function.update_of_ne hji] + exact h j hj + +lemma memo_succeeds (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).succeeds ω = T.succeeds ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,succeeds,h i hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,succeeds] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte,succeeds] + exact ih R η h + · simp [hb,succeeds] + · simp only [memo,hi,↓reduceIte,succeeds] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih _ _ (by simpa only [hb] using update_agrees h i) + · simp [hb] + +def freshCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then freshCharge one (insert i R) ω else freshCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + freshCharge next (insert i R) ω + (if i ∈ R then 0 else 1) else 0 + +lemma memo_charge (T : QueryTree ι) (R : Finset ι) (η ω : ι → Bool) + (h : ∀ i ∈ R, η i = ω i) : (memo T R η).charge ω = freshCharge T R ω := by + induction T generalizing R η with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,freshCharge,h i hi,Finset.insert_eq_of_mem hi] + cases ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ R η h + · exact ih₁ R η h + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + cases hb : ω i <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact ih₀ _ _ (by simpa only [hb] using update_agrees h i) + · exact ih₁ _ _ (by simpa only [hb] using update_agrees h i) + | force i b next ih => + by_cases hi : i ∈ R + · simp only [memo,hi,↓reduceIte,h i hi,freshCharge,Finset.insert_eq_of_mem hi,Nat.add_zero] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + exact ih R η h + · simp [hb,charge] + · simp only [memo,hi,↓reduceIte,charge,freshCharge] + by_cases hb : ω i = b + · simp only [hb,↓reduceIte] + rw [ih _ _ (by simpa only [hb] using update_agrees h i)] + · simp [hb] + +lemma mean_freshCharge_le_one [Fintype ι] (T : QueryTree ι) : + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) ≤ 1 := by + let η : ι → Bool := fun _ => false + have hm := mean_weighted_le_one (memo T ∅ η) (memo_fresh T ∅ η) + have he : finiteMean (memo T ∅ η).weighted = + finiteMean (fun ω : ι → Bool => + if T.succeeds ω then (2:ℝ) ^ T.freshCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + rw [weighted_eq, memo_succeeds _ _ _ _ (by simp), memo_charge _ _ _ _ (by simp)] + rw [he] at hm + exact hm + + +def followPath : (d : ℕ) → (SwitchIndex d → ι) → Card d → + (Card d → QueryTree ι) → QueryTree ι + | 0, _, x, k => k x + | d + 1, e, x, k => followPath d (fun i => e (Sum.inr (x 0,i))) (Fin.tail x) + (fun y => branch (e (Sum.inl y)) + (k (Fin.cons (Bool.xor (x 0) false) y)) + (k (Fin.cons (Bool.xor (x 0) true) y))) + +omit [DecidableEq ι] in +lemma followPath_succeeds (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).succeeds ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).succeeds ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).succeeds ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).succeeds ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).succeeds ω + cases ω (e (Sum.inl y)) <;> rfl + +lemma followPath_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + freshCharge (followPath d e x k) R ω = + freshCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + classical + induction d generalizing R with + | zero => simp only [followPath, routeDomain, Finset.image_empty, Finset.union_empty]; rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + let S := (routeDomain d (Fin.tail x) y).image (fun i => e (Sum.inr (x 0,i))) + change (if ω (e (Sum.inl y)) then + freshCharge (k (Fin.cons (Bool.xor (x 0) true) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω else + freshCharge (k (Fin.cons (Bool.xor (x 0) false) y)) (insert (e (Sum.inl y)) (R ∪ S)) ω) = + freshCharge (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)) + (R ∪ (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e) ω + have hs : (routeDomain (d+1) x + (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).image e = + insert (e (Sum.inl y)) S := by + let e' : Sum (Card d) (Bool × SwitchIndex d) → ι := e + change (insert (Sum.inl y) + ((routeDomain d (Fin.tail x) y).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))).image e' = _ + rw [Finset.image_insert, Finset.image_image] + rfl + rw [hs,Finset.union_insert] + cases ω (e (Sum.inl y)) <;> rfl + +def forceList : List ι → (ι → Bool) → QueryTree ι → QueryTree ι + | [], _, k => k + | i :: L, v, k => force i (v i) (forceList L v k) + +omit [DecidableEq ι] in +lemma forceList_succeeds (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) : + (forceList L v k).succeeds ω = + if ∀ i ∈ L, ω i = v i then k.succeeds ω else false := by + induction L with + | nil => simp [forceList] + | cons i L ih => + simp only [forceList,succeeds,ih,List.mem_cons,forall_eq_or_imp] + by_cases h : ω i = v i <;> simp [h] + +lemma forceList_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) + (R : Finset ι) (ω : ι → Bool) (h : ∀ i ∈ L, ω i = v i) : + freshCharge (forceList L v k) R ω = + freshCharge k (R ∪ L.toFinset) ω + (L.toFinset \ R).card := by + induction L generalizing R with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,freshCharge,ite_eq_left (h i List.mem_cons_self), + ih (insert i R) (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.toFinset_cons] + have hs : insert i R ∪ L.toFinset = R ∪ insert i L.toFinset := by ext j; simp + rw [hs] + by_cases hi : i ∈ R + · rw [ite_eq_left hi] + have he : L.toFinset \ insert i R = insert i L.toFinset \ R := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he,Nat.add_zero] + · rw [ite_eq_right hi] + have he : insert i L.toFinset \ R = insert i (L.toFinset \ insert i R) := by + ext j + by_cases hji : j = i + · subst j; simp [hi] + · simp [hji] + rw [he, Finset.card_insert_of_notMem (by simp)] + omega + + +def staleCharge : QueryTree ι → Finset ι → (ι → Bool) → ℕ + | reject, _, _ => 0 + | accept, _, _ => 0 + | branch i zero one, R, ω => if ω i then staleCharge one (insert i R) ω + else staleCharge zero (insert i R) ω + | force i b next, R, ω => if ω i = b then + staleCharge next (insert i R) ω + (if i ∈ R then 1 else 0) else 0 + +lemma fresh_add_stale (T : QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + T.freshCharge R ω + T.staleCharge R ω = T.charge ω := by + induction T generalizing R with + | reject => rfl + | accept => rfl + | branch i zero one ih₀ ih₁ => + cases hb : ω i <;> simp [freshCharge,staleCharge,charge,hb,ih₀,ih₁] + | force i b next ih => + by_cases hb : ω i = b + · simp only [freshCharge,staleCharge,charge,hb,↓reduceIte] + have he := ih (insert i R) + by_cases hi : i ∈ R <;> simp only [hi,↓reduceIte] <;> omega + · simp [freshCharge,staleCharge,charge,hb] + +omit [DecidableEq ι] in +lemma followPath_raw_charge (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (ω : ι → Bool) : + (followPath d e x k).charge ω = + (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).charge ω := by + induction d with + | zero => rfl + | succ d ih => + rw [followPath, ih] + let y := butterflyPerm d + (decodeButterfly d (fun i => ω (e (Sum.inr (x 0,i))))) (Fin.tail x) + change (if ω (e (Sum.inl y)) then + (k (Fin.cons (Bool.xor (x 0) true) y)).charge ω else + (k (Fin.cons (Bool.xor (x 0) false) y)).charge ω) = + (k (Fin.cons (Bool.xor (x 0) (ω (e (Sum.inl y)))) y)).charge ω + cases ω (e (Sum.inl y)) <;> rfl + +omit [DecidableEq ι] in +lemma forceList_raw_charge (L : List ι) (v : ι → Bool) (k : QueryTree ι) (ω : ι → Bool) + (h : ∀ i ∈ L, ω i = v i) : + (forceList L v k).charge ω = k.charge ω + L.length := by + induction L with + | nil => simp [forceList] + | cons i L ih => + rw [forceList,charge,ite_eq_left (h i List.mem_cons_self), + ih (fun j hj => h j (List.mem_cons_of_mem _ hj))] + simp only [List.length_cons,Nat.add_assoc] + +noncomputable def closePath (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) : + QueryTree (SwitchIndex d) := + forceList (routeDomain d x y).toList (routeValue d x y) k + +lemma closePath_succeeds (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) : + (closePath d x y k).succeeds ω = + if butterflyPerm d (decodeButterfly d ω) x = y then k.succeeds ω else false := by + unfold closePath + rw [forceList_succeeds] + simp only [Finset.mem_toList, ← butterfly_endpoint_iff] + +lemma closePath_raw_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).charge ω = k.charge ω + d := by + unfold closePath + rw [forceList_raw_charge _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.length_toList, card_routeDomain] + +lemma closePath_fresh_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).freshCharge R ω = + k.freshCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y \ R).card := by + unfold closePath + rw [forceList_charge _ _ _ _ _ (by simpa only [Finset.mem_toList] using + (butterfly_endpoint_iff d ω x y).mp h), Finset.toList_toFinset] + +lemma closePath_stale_charge (d : ℕ) (x y : Card d) (k : QueryTree (SwitchIndex d)) + (R : Finset (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : butterflyPerm d (decodeButterfly d ω) x = y) : + (closePath d x y k).staleCharge R ω = + k.staleCharge (R ∪ routeDomain d x y) ω + (routeDomain d x y ∩ R).card := by + have h₀ := fresh_add_stale (closePath d x y k) R ω + have h₁ := fresh_add_stale k (R ∪ routeDomain d x y) ω + rw [closePath_raw_charge _ _ _ _ _ h,closePath_fresh_charge _ _ _ _ _ _ h] at h₀ + have h₂ : (routeDomain d x y \ R).card + (routeDomain d x y ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_routeDomain] + omega + +noncomputable def seekCycle (d : ℕ) (S : Finset (Card d)) (a : Card d) : + ℕ → Card d → Finset (Card d) → (Finset (Card d) → QueryTree (SwitchIndex d)) → + QueryTree (SwitchIndex d) + | 0, x, V, k => if x ∈ S ∧ x ∉ V then closePath d x a (k (insert x V)) else reject + | r + 1, x, V, k => if x ∈ S ∧ x ∉ V then followPath d id x + (fun y => seekCycle d S a r y (insert x V) k) else reject + +lemma seekCycle_raw_charge (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V : Finset (Card d)) (k : Finset (Card d) → QueryTree (SwitchIndex d)) + (ω : SwitchIndex d → Bool) (K : ℕ) + (hK : ∀ V, (k V).succeeds ω = true → (k V).charge ω = K) + (hs : (seekCycle d S a r x V k).succeeds ω = true) : + (seekCycle d S a r x V k).charge ω = K + d := by + induction r generalizing x V with + | zero => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,closePath_succeeds] at hs + split_ifs at hs with he + · rw [seekCycle,ite_eq_left hv,closePath_raw_charge _ _ _ _ _ he,hK _ hs] + · simp [seekCycle,hv,succeeds] at hs + | succ r ih => + by_cases hv : x ∈ S ∧ x ∉ V + · rw [seekCycle,ite_eq_left hv,followPath_succeeds] at hs + rw [seekCycle,ite_eq_left hv,followPath_raw_charge] + exact ih _ _ hs + · simp [seekCycle,hv,succeeds] at hs + +noncomputable def seekCycles (d : ℕ) (S : Finset (Card d)) : + List (Card d × ℕ) → Finset (Card d) → QueryTree (SwitchIndex d) + | [], _ => accept + | (a,r) :: L, V => seekCycle d S a r a V (fun V => seekCycles d S L V) + +lemma seekCycles_raw_charge (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) + (V : Finset (Card d)) (ω : SwitchIndex d → Bool) + (hs : (seekCycles d S L V).succeeds ω = true) : + (seekCycles d S L V).charge ω = L.length * d := by + induction L generalizing V with + | nil => simp [seekCycles,charge] + | cons ar L ih => + obtain ⟨a,r⟩ := ar + rw [seekCycles] + rw [seekCycle_raw_charge d S a r a V (fun V => seekCycles d S L V) ω (L.length*d) + (fun V hs => ih V hs) hs] + simp [Nat.add_mul] + +lemma cycles_weighted_success (d : ℕ) (S : Finset (Card d)) (L : List (Card d × ℕ)) : + finiteMean (fun ω : SwitchIndex d → Bool => + if (seekCycles d S L ∅).succeeds ω then + ((2:ℝ)^d)^L.length / (2:ℝ)^(seekCycles d S L ∅).staleCharge ∅ ω else 0) ≤ 1 := by + let T := seekCycles d S L ∅ + have hh := mean_freshCharge_le_one T + have he : finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then (2:ℝ)^T.freshCharge ∅ ω else 0) = + finiteMean (fun ω : SwitchIndex d → Bool => + if T.succeeds ω then ((2:ℝ)^d)^L.length / (2:ℝ)^T.staleCharge ∅ ω else 0) := by + apply finiteMean_congr + intro ω + cases hs : T.succeeds ω + · simp + · simp only [↓reduceIte] + have hc := fresh_add_stale T ∅ ω + rw [seekCycles_raw_charge d S L ∅ ω hs] at hc + have hp : ((2:ℝ)^d)^L.length = (2:ℝ)^T.freshCharge ∅ ω * (2:ℝ)^T.staleCharge ∅ ω := by + rw [←pow_add,hc,←pow_mul,Nat.mul_comm] + rw [hp,mul_div_cancel_right₀ _ (pow_ne_zero _ (by norm_num))] + rw [← he] + exact hh + +end QueryTree + +lemma finiteMean_add {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + finiteMean (fun ω => f ω + g ω) = finiteMean f + finiteMean g := by + simp only [finiteMean,Finset.sum_add_distrib,add_div] + +lemma finiteMean_mul_const {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) (c : ℝ) : + finiteMean (fun ω => f ω * c) = finiteMean f * c := by + unfold finiteMean + rw [← Finset.sum_mul] + ring + +lemma finiteMean_sum {Ω α : Type*} [Fintype Ω] (s : Finset α) (f : α → Ω → ℝ) : + finiteMean (fun ω => ∑ i ∈ s, f i ω) = ∑ i ∈ s, finiteMean (f i) := by + simp only [finiteMean,Finset.sum_div] + exact Finset.sum_comm + +lemma finiteMean_mono {Ω : Type*} [Fintype Ω] {f g : Ω → ℝ} + (h : ∀ ω, f ω ≤ g ω) : finiteMean f ≤ finiteMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +lemma finiteMean_equiv {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω → ℝ) : + finiteMean f = finiteMean (fun ω => f (e.symm ω)) := by + unfold finiteMean + rw [Fintype.card_congr e] + congr 1 + exact Fintype.sum_equiv e _ _ (fun ω => by simp) + +lemma finiteMean_prod_left {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω'] + (f : Ω → ℝ) : finiteMean (fun ω : Ω × Ω' => f ω.1) = finiteMean f := by + simp only [finiteMean,Fintype.sum_prod_type,Finset.sum_const,nsmul_eq_mul, + ← Finset.mul_sum,Fintype.card_prod,Nat.cast_mul,Finset.card_univ] + have hn : (Fintype.card Ω' : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + field_simp + +lemma finiteMean_pi_eval {C : Type*} [Fintype C] [DecidableEq C] + {A : C → Type*} [∀ c, Fintype (A c)] [∀ c, Nonempty (A c)] + (c : C) (g : A c → ℝ) : + finiteMean (fun z : ∀ c, A c => g (z c)) = finiteMean g := by + rw [finiteMean_equiv (Equiv.piSplitAt c A)] + have he : (fun z : A c × ((j : {j // j ≠ c}) → A j) => + g ((Equiv.piSplitAt c A).symm z c)) = (fun z => g z.1) := by + funext z + simp [Equiv.piSplitAt] + rw [he,finiteMean_prod_left] + +lemma finiteMean_eq_indicator {Ω : Type*} [Fintype Ω] [DecidableEq Ω] (a : Ω) : + finiteMean (fun ω : Ω => if ω = a then (1:ℝ) else 0) = 1 / Fintype.card Ω := by + simp [finiteMean] + +lemma exp_finiteMean_le {Ω : Type*} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + Real.exp (finiteMean f) ≤ finiteMean (fun ω => Real.exp (f ω)) := by + have hn : (Fintype.card Ω : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hw : ∑ ω : Ω, (1 / (Fintype.card Ω : ℝ)) = 1 := by simp [hn] + have hj := convexOn_exp.map_sum_le (t := Finset.univ) + (w := fun _ : Ω => 1 / (Fintype.card Ω : ℝ)) (p := f) + (fun _ _ => by positivity) hw (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul, ← Finset.mul_sum] at hj + simpa only [finiteMean, div_eq_mul_inv, one_div, mul_comm, mul_one, one_mul] using hj + +variable {d A : ℕ} + +def cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : Finset (Card d) := by + classical + exact Finset.univ.filter (fun x => o x = some i) + +@[simp] lemma mem_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) (x : Card d) : + x ∈ cycleFiber o i ↔ o x = some i := by + classical + simp [cycleFiber] + +abbrev Terminal (o : Card d → Option (Fin A)) := ∀ i : Fin A, {x : Card d // o x = some i} + +noncomputable def slotWeight (o : Card d → Option (Fin A)) (i : Fin A) : ℝ := + 1 / (cycleFiber o i).card + +noncomputable def pathWeight (o : Card d → Option (Fin A)) (x : Card d) : ℝ := + match o x with + | none => 0 + | some i => slotWeight o i + +noncomputable def withinWeight (o : Card d → Option (Fin A)) (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i = j then slotWeight o i else 0 + | _, _ => 0 + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/HeightDecay.lean b/lean/OAI/Probability/ThorpRouting/Tail/HeightDecay.lean index a92bc3ae098080a8ff1f1a970e04b17c1ad099f0..246c76f1ca260e4a5493bfec3978efb922a1c8da 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/HeightDecay.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/HeightDecay.lean @@ -1,863 +1,863 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ParallelFreshPre - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,Real.exp_zero,le_refl] - | succ n ih => - let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hs : 2*familyEnd L n ≤ l := familyEnd_two L n - have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = - palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ - (fun _ => pow_nonneg (by linarith) _) - (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) - q hq hlog - · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp [l] - ring - -lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by - induction j with - | zero => norm_num - | succ j ih => rw [pow_succ]; omega - -lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : - (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ - Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by - let r := Real.exp (-(1:ℝ)/64) - have hr : 0 < r := Real.exp_pos _ - have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by - apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr - have hh := geom_sum_mul r n - nlinarith [pow_nonneg (le_of_lt hr) n] - calc - _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by - apply Finset.sum_le_sum - intro j _ - have hj := pow_four_ge j - have hlj : L+j ≤ L*4^j := by nlinarith - have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj - rw [←Real.exp_nat_mul,←Real.exp_add] - exact Real.exp_le_exp.mpr (by linarith) - _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] - _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := - mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) - _ = _ := by ring - - -lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : - palindromeLevelCost t (d+1) e ω = - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by - classical - rw [palindromeLevelCost] - dsimp only - split_ifs with h - · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] - · simp only [Nat.zero_add] - -lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by - classical - induction d generalizing ι with - | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] - | succ d ih => - rw [palindromeLowCost] - simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] - rw [←ih,←ih] - congr 2 - simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] - -lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by - rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L - -lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : - palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + - palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by - induction n with - | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] - omega - - -lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : - (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g - simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] - exact div_le_div_of_nonneg_right h (sq_nonneg _) - -lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) - (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) - (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : - finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by - have hc := finiteMean_mul_sq_le f g - have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) - have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) - have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by - rw [←Real.exp_add,←Real.exp_nat_mul] - congr 1 - push_cast - ring - rw [he] at hu - have hh := hc.trans hu - have hep := Real.exp_pos ((A+B)/2) - nlinarith - - -noncomputable def heightDecay (H : ℕ) : ℝ := - 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by - have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_antitone : Antitone heightDecay := by - intro L H h - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - apply div_le_div_of_nonneg_right _ hden - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have h' : (L:ℝ) ≤ H := by exact_mod_cast h - linarith - -lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ - Real.exp (Fintype.card ι*heightDecay L) := by - apply (palindrome_family_mgf L n d hL e X q hq hlog).trans - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using h - -theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ - palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 - have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 - have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) - have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) - (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) - (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) - (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simpa only [←pow_add,add_self_div_two] using hh - -lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : - finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ - palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by - apply finiteMean_mono - intro X - exact palindrome_high_mgf H n d hH e X q hq hlog - _ = _ := finiteMean_const _ - -theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ - Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ - Fintype.card ι*heightDecay H)/2) := by - let d := H+r - have hd : d ≤ H*4^d := by - have hh := pow_four_ge d - nlinarith - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ - (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by - have hh := palindromeCost_family H d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow := palindrome_low_mgf r H e (q^2) hq2 hr - have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 - have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) - _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ - simpa only [hcost,pow_add,pow_right_comm] using hh - - -lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : - cutoffMass H d e ω ≤ Fintype.card ι := by - classical - induction d generalizing ι with - | zero => exact Nat.zero_le _ - | succ d ih => - rw [cutoffMass] - split_ifs - · exact crowdedMass_le _ - · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) - -lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := - (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) - -theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : - finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ - Real.exp (Fintype.card ι*(1+heightDecay 1)) := by - have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega - have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ - (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by - have hh := palindromeCost_family 1 d d e ω - rw [palindromeLowCost_eq _ _ hd] at hh - simpa only [Nat.add_assoc] using hh.symm - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith - have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ - Real.exp (Fintype.card ι) := by - calc - _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by - apply finiteMean_mono - intro ω - apply pow_le_pow_right₀ hq2 - simpa only [one_mul] using palindromeLowCost_le 1 d e ω - _ = (q^2)^(Fintype.card ι) := finiteMean_const _ - _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by - rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) - (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) - (Fintype.card ι) (Fintype.card ι*heightDecay 1) - (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) - simp only [←pow_add,←hcost] at hh - apply hh.trans (Real.exp_le_exp.mpr _) - have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hD := heightDecay_nonneg 1 - nlinarith - -noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) - -lemma momentBase_one_le : 1 ≤ momentBase := by - exact Real.one_le_rpow (by norm_num) (by norm_num) - -lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - linarith - -lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by - rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] - rfl - -lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ - finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by - have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity - have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / - ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by - apply (div_le_one hn).mpr - exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) - have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) - have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => - pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) - -theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := - (palindromeRowMoment_le_cost d e).trans - (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) - - -noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ - -lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.log p ≤ -8*Real.log 2 := by - have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by - rw [show (1/256:ℝ) = 1/2^8 by norm_num, - Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] - ring - exact (Real.log_le_log hp hs).trans_eq he - -lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - 0 < densityCutoff p ∧ - (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ - -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hd : 0 < 4*Real.log 2 := by positivity - have hh := log_small_density hp hs - have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by - apply (le_div_iff₀ hd).mpr - nlinarith - refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ - · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) - · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) - -lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by - have hh := (densityCutoff_bounds hp hs).2.2 - have hb : Real.log 2 ≤ 2 := by - have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - linarith - have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity - have hu := mul_le_mul_of_nonneg_left hb hH - rw [Real.rpow_def_of_pos hp,←Real.exp_add] - apply Real.exp_le_exp.mpr - nlinarith - -lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) - (hq1 : 1 ≤ q) : - p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by - have hcut := (densityCutoff_bounds hp hs).2.1 - have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ - have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn - have hln := Real.log_nonneg hq1 - have hl := mul_le_mul_of_nonneg_right hn' hln - have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith - have hm := mul_le_mul_of_nonneg_left hnl hH - have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = - Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ - (n*densityCutoff p:ℕ)*Real.log q) := by - rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, - Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] - rw [heq,Real.rpow_def_of_pos hp] - apply Real.exp_le_exp.mpr - push_cast - nlinarith - -lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) - (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : - (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by - have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 - rw [←pow_mul] at ⊢ - have hle : p^(1/2:ℝ) ≤ 1/2 := by - have hlogp := log_small_density hp hs - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - rw [Real.rpow_def_of_pos hp] - calc - _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith - _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num - nlinarith [hh.trans hle] - - -lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by - rw [momentBase,Real.log_rpow (by norm_num)] - ring - -lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : - densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by - have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk - have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hlogk := Real.log_nonneg hk' - by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) - · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) - have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ - have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ - change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh - rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh - have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith - exact_mod_cast hle - · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) - simp only [densityCutoff,hz,Nat.zero_le] - -noncomputable def densityTailConstant : ℝ := - 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) - -lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - apply div_nonneg (by positivity) (by linarith) - -lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : - heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by - have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by - have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) - linarith - have hh := div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden - simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh - -lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : - (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = - 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by - rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] - have hH : (2:ℝ)^H ≠ 0 := by positivity - have hr : (2:ℝ)^r ≠ 0 := by positivity - field_simp - ring - -lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : - palindromeRowMoment d e (1/1000) ≤ - Real.exp (Fintype.card ι*(1+densityTailConstant)* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ - have hp : 0 < p := by rw [←hpdef]; positivity - have hle := densityCutoff_le_height d (Fintype.card ι) hk - rw [hpdef] at hle - obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle - subst d - have hH := (densityCutoff_bounds hp hs).1 - have hq := momentBase_one_le - have hqp : 0 < momentBase := by linarith - have hlog : Real.log momentBase ≤ Real.log 2/4 := by - rw [momentBase_log_exact] - have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) - linarith - have hsp := densityCutoff_sparse hp hs hqp hlog hq - rw [←hpdef] at hsp - have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log - (by simpa only [hpdef] using hsp) - apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) - rw [sparse_low_algebra,hpdef] - have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq - have hp1 : p ≤ 1 := by linarith - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) - have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) - (by positivity : (0:ℝ)≤2*Fintype.card ι) - have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) - (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) - have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := - mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) - (Real.rpow_nonneg (le_of_lt hp) _) - nlinarith - -noncomputable def densityConstant : ℝ := - 256*(1+heightDecay 1)+1+densityTailConstant - -lemma densityConstant_pos : 0 < densityConstant := by - dsimp [densityConstant] - have hh := heightDecay_nonneg 1 - have ht := densityTailConstant_nonneg - linarith - -theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by - have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity - have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by - apply (div_le_one (by positivity)).mpr - have h := Fintype.card_le_of_injective e e.injective - rw [card_positions] at h - exact_mod_cast h - have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ - have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) - by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 - · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) - have hD : 1+densityTailConstant ≤ densityConstant := by - dsimp [densityConstant] - have := heightDecay_nonneg 1 - linarith - have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow - nlinarith - · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) - rw [Real.rpow_one] at he - exact (le_of_not_ge hs).trans he - have hD : 256*(1+heightDecay 1) ≤ densityConstant := by - dsimp [densityConstant] - have := densityTailConstant_nonneg - linarith - apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) - have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith - have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) - have hb := mul_le_mul_of_nonneg_right hD hpow - have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 - nlinarith - -lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by - apply finiteMean_nonneg - intro f - exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) - (PairRouting.tupleProbability_nonneg _ _ _)) _ - -theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : - Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by - by_cases hz : palindromeRowMoment d e (1/1000) = 0 - · rw [hz,Real.log_zero] - exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) - (Real.rpow_nonneg (by positivity) _) - · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr - (palindrome_row_moment_bound d e hk) - -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) - (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by - have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by - apply (mem_orbitSet _ _ _).mpr - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - have he (n : ℕ) : (p^n) x = (q^n) x := by - induction n with - | zero => rfl - | succ n ih => - rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] - exact h _ (hp n) - ext y - simp only [mem_orbitSet] - constructor - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - · intro hy - obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq - rw [←hn,←he] - exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) - -noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) - (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by - refine ⟨C.val,?_,C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ - intro z hz - exact h z (hC z (hx ▸ hz)) - -noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by - classical - by_cases hb : ∃ x ∈ C.val, x ∈ B - · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ - · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) - -lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by - classical - intro C D he - by_cases hC : ∃ x ∈ C.val, x ∈ B <;> - by_cases hD : ∃ x ∈ D.val, x ∈ B - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he - have hx : hC.choose = hD.choose := congrArg Subtype.val he - exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 - (hx.symm ▸ hD.choose_spec.1) - · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he - cases he - · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he - have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he - exact Subtype.ext hval - -theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) - (h : ∀ x ∉ B, p x = q x) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by - have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) - simpa only [Fintype.card_sum,Fintype.card_coe] using hh - - -noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := - (Finset.univ.filter (fun x => p x ≠ q x)).card - -lemma permDistance_sum (p q : Equiv.Perm α) : - permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by - classical - simp [permDistance,Finset.card_filter] - -lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by - simp [permDistance] - -lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := - (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) - -lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by - simp only [permDistance,ne_comm] - -lemma permDistance_triangle (p q r : Equiv.Perm α) : - permDistance p r ≤ permDistance p q+permDistance q r := by - classical - simp only [permDistance_sum,←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro x _ - by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> - by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> - omega - -lemma permDistance_mul_left (p q g : Equiv.Perm α) : - permDistance (g*p) (g*q) = permDistance p q := by - classical - unfold permDistance - congr 1 - ext x - simp only [Finset.mem_filter,Finset.mem_univ,true_and] - exact not_congr g.injective.eq_iff - -lemma permDistance_mul_right (p q g : Equiv.Perm α) : - permDistance (p*g) (q*g) = permDistance p q := by - classical - simp only [permDistance_sum,Equiv.Perm.mul_apply] - exact Fintype.sum_equiv g _ _ (fun _ => rfl) - -lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by - have hh := permDistance_mul_left p⁻¹ q⁻¹ q - have hhh := permDistance_mul_right (q*p⁻¹) 1 p - simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh - rw [←hhh] at hh - rw [←hh,permDistance_symm] - -lemma permDistance_mul_le (p q g h : Equiv.Perm α) : - permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by - have hh := permDistance_triangle (p*g) (q*g) (q*h) - simpa only [permDistance_mul_left,permDistance_mul_right] using hh - -lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ - Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by - apply selectedCycle_perturb_le - intro x hx - simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx - -lemma permDistance_alternating (p q : Equiv.Perm α) : - permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by - classical - simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] - simp [CycleColoring.alternatingPerm] - -lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ - (permDistance (p false) (q false)+permDistance (p true) (q true)) := by - have hh := selectedCycle_distance_le - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) - (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) - rw [permDistance_alternating] at hh - apply hh.trans - apply Nat.add_le_add_left - dsimp only [PairRouting.alternatingProjection] - exact (permDistance_mul_le _ _ _ _).trans_eq (by - change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ - rw [permDistance_inv]) - -end Thorp -namespace Thorp - -def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - Equiv.Perm (Card (L+r)) - | 0, C => C (fun j => Fin.elim0 j) - | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) - -def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * - (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ - -lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - (c : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = - pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r - (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by - change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * - childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * - (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ - rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - simp only [mul_assoc] - rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → - (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ - | 0, _, _, _, _, _ => 0 - | r+1, C, _, _, e, ω => - let σ := benesStepEquiv (L+r) ω - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) σ.1.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) σ.1.2 - -noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := - ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω - -lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : - permDistance (childLift p) (childLift q) = - permDistance (p false) (q false)+permDistance (p true) (q true) := by - classical - rw [permDistance_sum] - have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = - ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by - apply Fintype.sum_equiv (headTailEquiv d) - intro x - have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl - rw [hx] - congr 1 - apply propext - constructor - · intro h - have ht := congrArg Fin.tail h - simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht - · intro h - dsimp only [childLift,Equiv.coe_fn_mk] - exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h - rw [hh] - simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] - omega - -noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := - ∑ u : Card r, permDistance (C u) (D u) - -lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : - centralDistance L (r+1) C D = - centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ - centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by - classical - unfold centralDistance - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) - (fun x => by - change permDistance (C x) (D x) = - permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) - rw [Fin.cons_self_tail])] - simp only [Fintype.sum_prod_type,Fintype.sum_bool] - omega - -lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : - permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by - induction r with - | zero => - simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] - -lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (ω : BenesCoins (L+r)) : - permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = - centralDistance L r C D := by - rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, - permDistance_mul_left,permDistance_centralBlock] - -lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : BenesCoins (L+r) × BenesCoins (L+r)) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let c := PairRouting.colors x coins.1 - let hc := PairRouting.colors_compatible x coins.1 - if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) - else centralLevelCost t L r (fun u => C (Fin.cons false u)) - (PairRouting.childEmbedding x c hc false) ω.1 + - centralLevelCost t L r (fun u => C (Fin.cons true u)) - (PairRouting.childEmbedding x c hc true) ω.2 := by - rw [centralLevelCost] - rfl - -lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by - induction r generalizing ι with - | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] - dsimp only - split_ifs with ht - · have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (benesStepEquiv (L+r) ω).2.1) - (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) - (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh - · rw [centralDistance_step] - have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) false) - (benesStepEquiv (L+r) ω).1.1 - have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) - (PairRouting.colors_compatible _ _) true) - (benesStepEquiv (L+r) ω).1.2 - omega - -lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : - centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - centralLevelCost_perturb (l+i.val+1) L r C D e ω) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ParallelFreshPre + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +theorem palindrome_family_mgf (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι * (68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,Real.exp_zero,le_refl] + | succ n ih => + let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hs : 2*familyEnd L n ≤ l := familyEnd_two L n + have hc : ∀ Y, palindromeFamilyCost L (n+1) d e (Y,X) = + palindromeFamilyCost L n d e (Y,X)+palindromeSlabCost l d e (Y,X) := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(palindromeFamilyCost L (n+1) d e (Y,X))) ≤ + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + exact palindrome_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hs e X _ + (fun _ => pow_nonneg (by linarith) _) + (layerAdapted_comp (palindromeFamilyCost_adapted L n d e X) (fun c => q^c)) + q hq hlog + · simp_rw [hc,palindromeSlabCost_gt l d (by omega) e,Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp [l] + ring + +lemma pow_four_ge (j : ℕ) : j+1 ≤ 4^j := by + induction j with + | zero => norm_num + | succ j ih => rw [pow_succ]; omega + +lemma sum_family_decay (L n : ℕ) (hL : 0 < L) : + (∑ j ∈ Finset.range n, Real.exp (-((L*4^j:ℕ):ℝ)/64)) ≤ + Real.exp (-(L:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) := by + let r := Real.exp (-(1:ℝ)/64) + have hr : 0 < r := Real.exp_pos _ + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + have hg : (∑ j ∈ Finset.range n, r^j) ≤ 1/(1-r) := by + apply (le_div_iff₀ (by linarith : (0:ℝ)<1-r)).mpr + have hh := geom_sum_mul r n + nlinarith [pow_nonneg (le_of_lt hr) n] + calc + _ ≤ ∑ j ∈ Finset.range n, Real.exp (-(L:ℝ)/64)*r^j := by + apply Finset.sum_le_sum + intro j _ + have hj := pow_four_ge j + have hlj : L+j ≤ L*4^j := by nlinarith + have hlj' : (L:ℝ)+j ≤ (L*4^j:ℕ) := by exact_mod_cast hlj + rw [←Real.exp_nat_mul,←Real.exp_add] + exact Real.exp_le_exp.mpr (by linarith) + _ = Real.exp (-(L:ℝ)/64)*(∑ j ∈ Finset.range n, r^j) := by rw [Finset.mul_sum] + _ ≤ Real.exp (-(L:ℝ)/64)*(1/(1-r)) := + mul_le_mul_of_nonneg_left hg (Real.exp_nonneg _) + _ = _ := by ring + + +lemma palindromeLevelCost_step_add (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (ω : BenesCoins (d+1)) : + palindromeLevelCost t (d+1) e ω = + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + (if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else 0) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 := by + classical + rw [palindromeLevelCost] + dsimp only + split_ifs with h + · simp only [palindromeLevelCost_gt t d (by omega),Nat.add_zero] + · simp only [Nat.zero_add] + +lemma palindromeLowCost_sum (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost H d e ω = ∑ i ∈ Finset.range H, palindromeLevelCost (i+1) d e ω := by + classical + induction d generalizing ι with + | zero => simp only [palindromeLowCost,palindromeLevelCost,Finset.sum_const_zero] + | succ d ih => + rw [palindromeLowCost] + simp only [palindromeLevelCost_step_add,Finset.sum_add_distrib] + rw [←ih,←ih] + congr 2 + simp only [Nat.add_right_cancel_iff,Finset.sum_ite_eq',Finset.mem_range,Nat.succ_le_iff] + +lemma palindromeLowCost_slab (L d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeSlabCost L d e ω = palindromeLowCost (2*L) d e ω := by + rw [palindromeLowCost_sum,palindromeLowCost_sum,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => palindromeLevelCost (L+i+1) d e ω) L + +lemma palindromeCost_family (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : + palindromeLowCost L d e ω + palindromeFamilyCost L n d e ω + + palindromeFamilyCost (2*L) n d e ω = palindromeLowCost (L*4^n) d e ω := by + induction n with + | zero => simp only [palindromeFamilyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [palindromeFamilyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←palindromeLowCost_slab,←palindromeLowCost_slab,←ih] + omega + + +lemma finiteMean_mul_sq_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : + (finiteMean (fun ω => f ω*g ω))^2 ≤ finiteMean (fun ω => (f ω)^2)*finiteMean (fun ω => (g ω)^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + simp only [finiteMean,div_pow,div_mul_div_comm,←pow_two] + exact div_le_div_of_nonneg_right h (sq_nonneg _) + +lemma finiteMean_mul_exp_le {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) (A B : ℝ) + (hf : finiteMean (fun ω => (f ω)^2) ≤ Real.exp A) + (hg : finiteMean (fun ω => (g ω)^2) ≤ Real.exp B) : + finiteMean (fun ω => f ω*g ω) ≤ Real.exp ((A+B)/2) := by + have hc := finiteMean_mul_sq_le f g + have hn : 0 ≤ finiteMean (fun ω => (g ω)^2) := finiteMean_nonneg (fun _ => sq_nonneg _) + have hu := mul_le_mul hf hg hn (Real.exp_nonneg _) + have he : Real.exp A*Real.exp B = (Real.exp ((A+B)/2))^2 := by + rw [←Real.exp_add,←Real.exp_nat_mul] + congr 1 + push_cast + ring + rw [he] at hu + have hh := hc.trans hu + have hep := Real.exp_pos ((A+B)/2) + nlinarith + + +noncomputable def heightDecay (H : ℕ) : ℝ := + 68*Real.exp (-(H:ℝ)/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma heightDecay_nonneg (H : ℕ) : 0 ≤ heightDecay H := by + have h : Real.exp (-(1:ℝ)/64) < 1 := Real.exp_lt_one_iff.mpr (by norm_num) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_antitone : Antitone heightDecay := by + intro L H h + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + apply div_le_div_of_nonneg_right _ hden + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have h' : (L:ℝ) ≤ H := by exact_mod_cast h + linarith + +lemma palindrome_family_mgf_decay (L n d : ℕ) (hL : 0 < L) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(palindromeFamilyCost L n d e (Y,X))) ≤ + Real.exp (Fintype.card ι*heightDecay L) := by + apply (palindrome_family_mgf L n d hL e X q hq hlog).trans + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have h := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using h + +theorem palindrome_high_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(palindromeFamilyCost H n d e (Y,X)+ + palindromeFamilyCost (2*H) n d e (Y,X))) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := palindrome_family_mgf_decay H n d hH e X (q^2) hq2 hlog2 + have h₁ := palindrome_family_mgf_decay (2*H) n d (by omega) e X (q^2) hq2 hlog2 + have h₁' := h₁.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show H ≤ 2*H by omega)) (Nat.cast_nonneg _))) + have hh := finiteMean_mul_exp_le (fun Y => q^(palindromeFamilyCost H n d e (Y,X))) + (fun Y => q^(palindromeFamilyCost (2*H) n d e (Y,X))) + (Fintype.card ι*heightDecay H) (Fintype.card ι*heightDecay H) + (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simpa only [←pow_add,add_self_div_two] using hh + +lemma palindrome_high_full_mgf (H n d : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/500) : + finiteMean (fun ω : BenesCoins d => q^(palindromeFamilyCost H n d e ω+ + palindromeFamilyCost (2*H) n d e ω)) ≤ Real.exp (Fintype.card ι*heightDecay H) := by + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _X : SwitchIndex d → Bool => Real.exp (Fintype.card ι*heightDecay H)) := by + apply finiteMean_mono + intro X + exact palindrome_high_mgf H n d hH e X q hq hlog + _ = _ := finiteMean_const _ + +theorem palindrome_cost_mgf_cutoff (r H : ℕ) (hH : 0 < H) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeCost (H+r) e ω)) ≤ + Real.exp (((2:ℝ)^r*(2*((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*(q^2)^H))^2)+ + Fintype.card ι*heightDecay H)/2) := by + let d := H+r + have hd : d ≤ H*4^d := by + have hh := pow_four_ge d + nlinarith + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost H d e ω+ + (palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω) := by + have hh := palindromeCost_family H d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow := palindrome_low_mgf r H e (q^2) hq2 hr + have hhigh := palindrome_high_full_mgf H d d hH e (q^2) hq2 hlog2 + have hh := finiteMean_mul_exp_le (fun ω : BenesCoins d => q^(palindromeLowCost H d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost H d d e ω+palindromeFamilyCost (2*H) d d e ω)) + _ _ (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + change finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ _ + simpa only [hcost,pow_add,pow_right_comm] using hh + + +lemma cutoffMass_le (H d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (ω : BenesCoins d) : + cutoffMass H d e ω ≤ Fintype.card ι := by + classical + induction d generalizing ι with + | zero => exact Nat.zero_le _ + | succ d ih => + rw [cutoffMass] + split_ifs + · exact crowdedMass_le _ + · exact (Nat.add_le_add (ih _ _) (ih _ _)).trans_eq (PairRouting.color_card_add _) + +lemma palindromeLowCost_le (H d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLowCost H d e ω ≤ H*Fintype.card ι := + (palindromeLowCost_le_cutoff H d e ω).trans (Nat.mul_le_mul_left H (cutoffMass_le H d e ω)) + +theorem palindrome_cost_mgf_coarse (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/1000) : + finiteMean (fun ω : BenesCoins d => q^(palindromeCost d e ω)) ≤ + Real.exp (Fintype.card ι*(1+heightDecay 1)) := by + have hd : d ≤ 1*4^d := by have hh := pow_four_ge d; omega + have hcost (ω : BenesCoins d) : palindromeCost d e ω = palindromeLowCost 1 d e ω+ + (palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω) := by + have hh := palindromeCost_family 1 d d e ω + rw [palindromeLowCost_eq _ _ hd] at hh + simpa only [Nat.add_assoc] using hh.symm + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/500 := by rw [Real.log_pow]; norm_num; linarith + have hlow : finiteMean (fun ω : BenesCoins d => (q^2)^(palindromeLowCost 1 d e ω)) ≤ + Real.exp (Fintype.card ι) := by + calc + _ ≤ finiteMean (fun _ω : BenesCoins d => (q^2)^(Fintype.card ι)) := by + apply finiteMean_mono + intro ω + apply pow_le_pow_right₀ hq2 + simpa only [one_mul] using palindromeLowCost_le 1 d e ω + _ = (q^2)^(Fintype.card ι) := finiteMean_const _ + _ = Real.exp (Fintype.card ι * Real.log (q^2)) := by + rw [Real.exp_nat_mul,Real.exp_log (by positivity : 0 q^(palindromeLowCost 1 d e ω)) + (fun ω : BenesCoins d => q^(palindromeFamilyCost 1 d d e ω+palindromeFamilyCost 2 d d e ω)) + (Fintype.card ι) (Fintype.card ι*heightDecay 1) + (by simpa only [pow_right_comm] using hlow) (by simpa only [pow_right_comm] using hhigh) + simp only [←pow_add,←hcost] at hh + apply hh.trans (Real.exp_le_exp.mpr _) + have hk : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hD := heightDecay_nonneg 1 + nlinarith + +noncomputable def momentBase : ℝ := (2:ℝ)^(1/1000:ℝ) + +lemma momentBase_one_le : 1 ≤ momentBase := by + exact Real.one_le_rpow (by norm_num) (by norm_num) + +lemma momentBase_log : Real.log momentBase ≤ 1/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + linarith + +lemma momentBase_pow (c : ℕ) : momentBase^c = (2:ℝ)^((c:ℝ)*(1/1000:ℝ)) := by + rw [mul_comm,Real.rpow_mul_natCast (by norm_num)] + rfl + +lemma palindromeRowMoment_le_cost (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ + finiteMean (fun ω : BenesCoins d => momentBase^(palindromeCost d e ω)) := by + have hn : (0:ℝ) < ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn0 : (0:ℝ) ≤ ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) := by positivity + have hn1 : ((2^d).descFactorial (Fintype.card ι):ℝ) / + ((2^d:ℕ):ℝ)^(Fintype.card ι) ≤ 1 := by + apply (div_le_one hn).mpr + exact_mod_cast Nat.descFactorial_le_pow (2^d) (Fintype.card ι) + have hpow := Real.rpow_le_one hn0 hn1 (by norm_num : (0:ℝ)≤1/1000) + have hm := palindrome_row_density_moment d e (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + exact hm.trans (mul_le_of_le_one_left (finiteMean_nonneg (fun _ => + pow_nonneg (le_trans (by norm_num) momentBase_one_le) _)) hpow) + +theorem palindrome_row_moment_coarse (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (Fintype.card ι*(1+heightDecay 1)) := + (palindromeRowMoment_le_cost d e).trans + (palindrome_cost_mgf_coarse d e momentBase momentBase_one_le momentBase_log) + + +noncomputable def densityCutoff (p : ℝ) : ℕ := ⌊-Real.log p/(4*Real.log 2)⌋₊ + +lemma log_small_density {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.log p ≤ -8*Real.log 2 := by + have he : Real.log (1/256:ℝ) = -8*Real.log 2 := by + rw [show (1/256:ℝ) = 1/2^8 by norm_num, + Real.log_div (by norm_num) (by positivity),Real.log_one,Real.log_pow] + ring + exact (Real.log_le_log hp hs).trans_eq he + +lemma densityCutoff_bounds {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + 0 < densityCutoff p ∧ + (densityCutoff p:ℝ)*(4*Real.log 2) ≤ -Real.log p ∧ + -Real.log p < ((densityCutoff p:ℝ)+1)*(4*Real.log 2) := by + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hd : 0 < 4*Real.log 2 := by positivity + have hh := log_small_density hp hs + have hx : 1 ≤ -Real.log p/(4*Real.log 2) := by + apply (le_div_iff₀ hd).mpr + nlinarith + refine ⟨Nat.floor_pos.mpr hx,?_,?_⟩ + · exact (le_div_iff₀ hd).mp (Nat.floor_le (by linarith : 0 ≤ -Real.log p/(4*Real.log 2))) + · exact (div_lt_iff₀ hd).mp (Nat.lt_floor_add_one (-Real.log p/(4*Real.log 2))) + +lemma densityCutoff_decay {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + Real.exp (-(densityCutoff p:ℝ)/64) ≤ Real.exp (1/64) * p^(1/512:ℝ) := by + have hh := (densityCutoff_bounds hp hs).2.2 + have hb : Real.log 2 ≤ 2 := by + have := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hH : 0 ≤ (densityCutoff p:ℝ)+1 := by positivity + have hu := mul_le_mul_of_nonneg_left hb hH + rw [Real.rpow_def_of_pos hp,←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +lemma densityCutoff_power {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (n : ℕ) (hn : n ≤ 4) + (hq1 : 1 ≤ q) : + p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) ≤ p^(1/2:ℝ) := by + have hcut := (densityCutoff_bounds hp hs).2.1 + have hH : 0 ≤ (densityCutoff p:ℝ) := Nat.cast_nonneg _ + have hn' : (n:ℝ) ≤ 4 := by exact_mod_cast hn + have hln := Real.log_nonneg hq1 + have hl := mul_le_mul_of_nonneg_right hn' hln + have hnl : (n:ℝ)*Real.log q ≤ Real.log 2 := by linarith + have hm := mul_le_mul_of_nonneg_left hnl hH + have heq : p*(2:ℝ)^(densityCutoff p)*q^(n*densityCutoff p) = + Real.exp (Real.log p+(densityCutoff p:ℝ)*Real.log 2+ + (n*densityCutoff p:ℕ)*Real.log q) := by + rw [Real.exp_add,Real.exp_add,Real.exp_nat_mul,Real.exp_nat_mul, + Real.exp_log hp,Real.exp_log hq,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [heq,Real.rpow_def_of_pos hp] + apply Real.exp_le_exp.mpr + push_cast + nlinarith + +lemma densityCutoff_sparse {p q : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) + (hq : 0 < q) (hlog : Real.log q ≤ Real.log 2/4) (hq1 : 1 ≤ q) : + (2:ℝ)^(densityCutoff p)*(p*(q^2)^(densityCutoff p)) ≤ 1/2 := by + have hh := densityCutoff_power hp hs hq hlog 2 (by decide) hq1 + rw [←pow_mul] at ⊢ + have hle : p^(1/2:ℝ) ≤ 1/2 := by + have hlogp := log_small_density hp hs + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + rw [Real.rpow_def_of_pos hp] + calc + _ ≤ Real.exp (-Real.log 2) := by apply Real.exp_le_exp.mpr; nlinarith + _ = 1/2 := by rw [Real.exp_neg,Real.exp_log (by norm_num : (0:ℝ)<2)]; norm_num + nlinarith [hh.trans hle] + + +lemma momentBase_log_exact : Real.log momentBase = Real.log 2/1000 := by + rw [momentBase,Real.log_rpow (by norm_num)] + ring + +lemma densityCutoff_le_height (d k : ℕ) (hk : 0 < k) : + densityCutoff ((k:ℝ)/(2:ℝ)^d) ≤ d := by + have hk' : (1:ℝ) ≤ k := by exact_mod_cast hk + have hp : 0 < (k:ℝ)/(2:ℝ)^d := by positivity + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlogk := Real.log_nonneg hk' + by_cases hx : 0 ≤ -Real.log ((k:ℝ)/(2:ℝ)^d)/(4*Real.log 2) + · have hh := (le_div_iff₀ (by positivity : 0 < 4*Real.log 2)).mp (Nat.floor_le hx) + have hd : (0:ℝ) ≤ d := Nat.cast_nonneg _ + have hH : (0:ℝ) ≤ densityCutoff ((k:ℝ)/(2:ℝ)^d) := Nat.cast_nonneg _ + change (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ)*(4*Real.log 2) ≤ -Real.log ((k:ℝ)/(2:ℝ)^d) at hh + rw [Real.log_div (by positivity) (by positivity),Real.log_pow] at hh + have hle : (densityCutoff ((k:ℝ)/(2:ℝ)^d):ℝ) ≤ d := by nlinarith + exact_mod_cast hle + · have hz := Nat.floor_of_nonpos (le_of_not_ge hx) + simp only [densityCutoff,hz,Nat.zero_le] + +noncomputable def densityTailConstant : ℝ := + 68*Real.exp (1/64)/(1-Real.exp (-(1:ℝ)/64)) + +lemma densityTailConstant_nonneg : 0 ≤ densityTailConstant := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + apply div_nonneg (by positivity) (by linarith) + +lemma heightDecay_cutoff {p : ℝ} (hp : 0 < p) (hs : p ≤ 1/256) : + heightDecay (densityCutoff p) ≤ densityTailConstant*p^(1/512:ℝ) := by + have hden : 0 ≤ 1-Real.exp (-(1:ℝ)/64) := by + have h := Real.exp_lt_one_iff.mpr (by norm_num : -(1:ℝ)/64 < 0) + linarith + have hh := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (densityCutoff_decay hp hs) (by norm_num : (0:ℝ)≤68)) hden + simpa only [heightDecay,densityTailConstant,mul_assoc,div_mul_eq_mul_div] using hh + +lemma sparse_low_algebra (r H k : ℕ) (q : ℝ) : + (2:ℝ)^r*(2*((2:ℝ)^H*(((k:ℝ)/(2:ℝ)^(H+r))*(q^2)^H))^2) = + 2*k*(((k:ℝ)/(2:ℝ)^(H+r))*(2:ℝ)^H*q^(4*H)) := by + rw [pow_add,←pow_mul,show 4*H = (2*H)*2 by omega,pow_mul] + have hH : (2:ℝ)^H ≠ 0 := by positivity + have hr : (2:ℝ)^r ≠ 0 := by positivity + field_simp + ring + +lemma palindrome_row_moment_small (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256) : + palindromeRowMoment d e (1/1000) ≤ + Real.exp (Fintype.card ι*(1+densityTailConstant)* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + generalize hpdef : ((Fintype.card ι:ℝ)/(2:ℝ)^d) = p at hs ⊢ + have hp : 0 < p := by rw [←hpdef]; positivity + have hle := densityCutoff_le_height d (Fintype.card ι) hk + rw [hpdef] at hle + obtain ⟨r,hr⟩ := Nat.exists_eq_add_of_le hle + subst d + have hH := (densityCutoff_bounds hp hs).1 + have hq := momentBase_one_le + have hqp : 0 < momentBase := by linarith + have hlog : Real.log momentBase ≤ Real.log 2/4 := by + rw [momentBase_log_exact] + have h2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + linarith + have hsp := densityCutoff_sparse hp hs hqp hlog hq + rw [←hpdef] at hsp + have hh := palindrome_cost_mgf_cutoff r (densityCutoff p) hH e momentBase hq momentBase_log + (by simpa only [hpdef] using hsp) + apply (palindromeRowMoment_le_cost _ e).trans (hh.trans (Real.exp_le_exp.mpr _)) + rw [sparse_low_algebra,hpdef] + have hlow := densityCutoff_power hp hs hqp hlog 4 (by decide) hq + have hp1 : p ≤ 1 := by linarith + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1/2) + have hlow' := mul_le_mul_of_nonneg_left (hlow.trans he) + (by positivity : (0:ℝ)≤2*Fintype.card ι) + have hhigh := mul_le_mul_of_nonneg_left (heightDecay_cutoff hp hs) + (Nat.cast_nonneg (Fintype.card ι): (0:ℝ)≤_) + have hnon : 0 ≤ Fintype.card ι*densityTailConstant*p^(1/512:ℝ) := + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) densityTailConstant_nonneg) + (Real.rpow_nonneg (le_of_lt hp) _) + nlinarith + +noncomputable def densityConstant : ℝ := + 256*(1+heightDecay 1)+1+densityTailConstant + +lemma densityConstant_pos : 0 < densityConstant := by + dsimp [densityConstant] + have hh := heightDecay_nonneg 1 + have ht := densityTailConstant_nonneg + linarith + +theorem palindrome_row_moment_bound (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + palindromeRowMoment d e (1/1000) ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ)) := by + have hp : 0 < (Fintype.card ι:ℝ)/(2:ℝ)^d := by positivity + have hp1 : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1 := by + apply (div_le_one (by positivity)).mpr + have h := Fintype.card_le_of_injective e e.injective + rw [card_positions] at h + exact_mod_cast h + have hk0 : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hpow := Real.rpow_nonneg (le_of_lt hp) (1/512:ℝ) + by_cases hs : (Fintype.card ι:ℝ)/(2:ℝ)^d ≤ 1/256 + · apply (palindrome_row_moment_small d e hk hs).trans (Real.exp_le_exp.mpr _) + have hD : 1+densityTailConstant ≤ densityConstant := by + dsimp [densityConstant] + have := heightDecay_nonneg 1 + linarith + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hD hk0) hpow + nlinarith + · have hlow : (1:ℝ)/256 ≤ ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + have he := Real.rpow_le_rpow_of_exponent_ge hp hp1 (by norm_num : (1:ℝ)/512 ≤ 1) + rw [Real.rpow_one] at he + exact (le_of_not_ge hs).trans he + have hD : 256*(1+heightDecay 1) ≤ densityConstant := by + dsimp [densityConstant] + have := densityTailConstant_nonneg + linarith + apply (palindrome_row_moment_coarse d e).trans (Real.exp_le_exp.mpr _) + have hD0 : 0 ≤ 1+heightDecay 1 := by have := heightDecay_nonneg 1; linarith + have ha := mul_le_mul_of_nonneg_left hlow (mul_nonneg (by norm_num : (0:ℝ)≤256) hD0) + have hb := mul_le_mul_of_nonneg_right hD hpow + have hc := mul_le_mul_of_nonneg_right (ha.trans hb) hk0 + nlinarith + +lemma palindromeRowMoment_nonneg (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (a : ℝ) : 0 ≤ palindromeRowMoment d e a := by + apply finiteMean_nonneg + intro f + exact Real.rpow_nonneg (mul_nonneg (Nat.cast_nonneg _) + (PairRouting.tupleProbability_nonneg _ _ _)) _ + +theorem palindrome_log_row_moment (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (hk : 0 < Fintype.card ι) : + Real.log (palindromeRowMoment d e (1/1000)) ≤ densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ) := by + by_cases hz : palindromeRowMoment d e (1/1000) = 0 + · rw [hz,Real.log_zero] + exact mul_nonneg (mul_nonneg (le_of_lt densityConstant_pos) (Nat.cast_nonneg _)) + (Real.rpow_nonneg (by positivity) _) + · exact (Real.log_le_iff_le_exp (lt_of_le_of_ne (palindromeRowMoment_nonneg _ _ _) (Ne.symm hz))).mpr + (palindrome_row_moment_bound d e hk) + +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_eq_of_agree (p q : Equiv.Perm α) (x : α) + (h : ∀ z ∈ orbitSet p x, p z = q z) : orbitSet p x = orbitSet q x := by + have hp (n : ℕ) : (p^n) x ∈ orbitSet p x := by + apply (mem_orbitSet _ _ _).mpr + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + have he (n : ℕ) : (p^n) x = (q^n) x := by + induction n with + | zero => rfl + | succ n ih => + rw [pow_succ',pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.mul_apply,←ih] + exact h _ (hp n) + ext y + simp only [mem_orbitSet] + constructor + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + · intro hy + obtain ⟨n,hn⟩ := hy.exists_nat_pow_eq + rw [←hn,←he] + exact Equiv.Perm.sameCycle_pow_right.mpr (Equiv.Perm.SameCycle.refl _ _) + +noncomputable def survivingCycle (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) + (hC : ∀ x ∈ C.val, x ∉ B) : RoutingNetwork.SelectedCycle q S := by + refine ⟨C.val,?_,C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + refine ⟨x,hx.trans (orbitSet_eq_of_agree p q x ?_)⟩ + intro z hz + exact h z (hC z (hx ▸ hz)) + +noncomputable def perturbCycleMap (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle q S ⊕ {x // x ∈ B} := by + classical + by_cases hb : ∃ x ∈ C.val, x ∈ B + · exact Sum.inr ⟨hb.choose,hb.choose_spec.2⟩ + · exact Sum.inl (survivingCycle p q S B h C (by simpa only [not_exists,not_and] using hb)) + +lemma perturbCycleMap_injective (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : Function.Injective (perturbCycleMap p q S B h) := by + classical + intro C D he + by_cases hC : ∃ x ∈ C.val, x ∈ B <;> + by_cases hD : ∃ x ∈ D.val, x ∈ B + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_left hD,Sum.inr.injEq] at he + have hx : hC.choose = hD.choose := congrArg Subtype.val he + exact RoutingNetwork.SelectedCycle.eq_of_mem C D hC.choose_spec.1 + (hx.symm ▸ hD.choose_spec.1) + · simp only [perturbCycleMap,dite_eq_left hC,dite_eq_right hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_left hD] at he + cases he + · simp only [perturbCycleMap,dite_eq_right hC,dite_eq_right hD,Sum.inl.injEq] at he + have hval : C.val = D.val := congrArg (fun Z : RoutingNetwork.SelectedCycle q S => Z.val) he + exact Subtype.ext hval + +theorem selectedCycle_perturb_le (p q : Equiv.Perm α) (S B : Finset α) + (h : ∀ x ∉ B, p x = q x) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+B.card := by + have hh := Fintype.card_le_of_injective _ (perturbCycleMap_injective p q S B h) + simpa only [Fintype.card_sum,Fintype.card_coe] using hh + + +noncomputable def permDistance (p q : Equiv.Perm α) : ℕ := + (Finset.univ.filter (fun x => p x ≠ q x)).card + +lemma permDistance_sum (p q : Equiv.Perm α) : + permDistance p q = ∑ x : α, if p x = q x then 0 else 1 := by + classical + simp [permDistance,Finset.card_filter] + +lemma permDistance_refl (p : Equiv.Perm α) : permDistance p p = 0 := by + simp [permDistance] + +lemma permDistance_le (p q : Equiv.Perm α) : permDistance p q ≤ Fintype.card α := + (Finset.card_filter_le _ _).trans_eq (Finset.card_univ) + +lemma permDistance_symm (p q : Equiv.Perm α) : permDistance p q = permDistance q p := by + simp only [permDistance,ne_comm] + +lemma permDistance_triangle (p q r : Equiv.Perm α) : + permDistance p r ≤ permDistance p q+permDistance q r := by + classical + simp only [permDistance_sum,←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro x _ + by_cases hpq : p x = q x <;> by_cases hqr : q x = r x <;> + by_cases hpr : p x = r x <;> simp only [hpq,hqr,hpr,↓reduceIte] <;> + omega + +lemma permDistance_mul_left (p q g : Equiv.Perm α) : + permDistance (g*p) (g*q) = permDistance p q := by + classical + unfold permDistance + congr 1 + ext x + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact not_congr g.injective.eq_iff + +lemma permDistance_mul_right (p q g : Equiv.Perm α) : + permDistance (p*g) (q*g) = permDistance p q := by + classical + simp only [permDistance_sum,Equiv.Perm.mul_apply] + exact Fintype.sum_equiv g _ _ (fun _ => rfl) + +lemma permDistance_inv (p q : Equiv.Perm α) : permDistance p⁻¹ q⁻¹ = permDistance p q := by + have hh := permDistance_mul_left p⁻¹ q⁻¹ q + have hhh := permDistance_mul_right (q*p⁻¹) 1 p + simp only [mul_inv_cancel,one_mul,inv_mul_cancel_right] at hh hhh + rw [←hhh] at hh + rw [←hh,permDistance_symm] + +lemma permDistance_mul_le (p q g h : Equiv.Perm α) : + permDistance (p*g) (q*h) ≤ permDistance p q+permDistance g h := by + have hh := permDistance_triangle (p*g) (q*g) (q*h) + simpa only [permDistance_mul_left,permDistance_mul_right] using hh + +lemma selectedCycle_distance_le (p q : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p S) ≤ + Fintype.card (RoutingNetwork.SelectedCycle q S)+permDistance p q := by + apply selectedCycle_perturb_le + intro x hx + simpa only [Finset.mem_filter,Finset.mem_univ,true_and,not_not] using hx + +lemma permDistance_alternating (p q : Equiv.Perm α) : + permDistance (CycleColoring.alternatingPerm p) (CycleColoring.alternatingPerm q) = permDistance p q := by + classical + simp only [permDistance_sum,Fintype.sum_prod_type,Fintype.sum_bool] + simp [CycleColoring.alternatingPerm] + +lemma alternatingCycles_distance_le {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p q : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ PairRouting.alternatingCycles e q+ + (permDistance (p false) (q false)+permDistance (p true) (q true)) := by + have hh := selectedCycle_distance_le + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection p)) + (CycleColoring.alternatingPerm (PairRouting.alternatingProjection q)) (PairRouting.labelSet e) + rw [permDistance_alternating] at hh + apply hh.trans + apply Nat.add_le_add_left + dsimp only [PairRouting.alternatingProjection] + exact (permDistance_mul_le _ _ _ _).trans_eq (by + change permDistance (p false)⁻¹ (q false)⁻¹ + _ = _ + rw [permDistance_inv]) + +end Thorp +namespace Thorp + +def centralBlockPerm (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + Equiv.Perm (Card (L+r)) + | 0, C => C (fun j => Fin.elim0 j) + | r+1, C => childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) + +def centralPalindromePerm (L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.1) * centralBlockPerm L r C * + (butterflyPerm (L+r) (decodeButterfly (L+r) ω.2))⁻¹ + +lemma centralPalindromePerm_step (L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + (c : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralPalindromePerm L (r+1) C ((benesStepEquiv (L+r)).symm (c,coins)) = + pairSwitch coins.2 * childLift (fun b => centralPalindromePerm L r + (fun u => C (Fin.cons b u)) (if b then c.2 else c.1)) * pairSwitch coins.1 := by + change ((butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.1,c.2.1),coins.2))))) * + childLift (fun b => centralBlockPerm L r (fun u => C (Fin.cons b u))) * + (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((c.1.2,c.2.2),coins.1))))⁻¹ = _ + rw [butterflyPerm_step,butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + simp only [mul_assoc] + rw [←mul_assoc (childLift _),childLift_mul,←mul_assoc (childLift _),childLift_mul] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +noncomputable def centralLevelCost (t L : ℕ) : (r : ℕ) → + (Card r → Equiv.Perm (Card L)) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card (L+r)) → BenesCoins (L+r) → ℕ + | 0, _, _, _, _, _ => 0 + | r+1, C, _, _, e, ω => + let σ := benesStepEquiv (L+r) ω + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then σ.1.2 else σ.1.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) σ.1.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) σ.1.2 + +noncomputable def centralSlabCost (l L r : ℕ) (C : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : ℕ := + ∑ i : Fin l, centralLevelCost (l+i.val+1) L r C e ω + +lemma permDistance_childLift (d : ℕ) (p q : Bool → Equiv.Perm (Card d)) : + permDistance (childLift p) (childLift q) = + permDistance (p false) (q false)+permDistance (p true) (q true) := by + classical + rw [permDistance_sum] + have hh : (∑ x : Card (d+1), if childLift p x = childLift q x then 0 else 1) = + ∑ x : Bool × Card d, if p x.1 x.2 = q x.1 x.2 then 0 else 1 := by + apply Fintype.sum_equiv (headTailEquiv d) + intro x + have hx : (headTailEquiv d) x = (x 0,Fin.tail x) := rfl + rw [hx] + congr 1 + apply propext + constructor + · intro h + have ht := congrArg Fin.tail h + simpa only [childLift,Equiv.coe_fn_mk,Fin.tail_cons] using ht + · intro h + dsimp only [childLift,Equiv.coe_fn_mk] + exact congrArg (fun z : Card d => (Fin.cons (x 0) z : Card (d+1))) h + rw [hh] + simp only [Fintype.sum_prod_type,Fintype.sum_bool,permDistance_sum] + omega + +noncomputable def centralDistance (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : ℕ := + ∑ u : Card r, permDistance (C u) (D u) + +lemma centralDistance_step (L r : ℕ) (C D : Card (r+1) → Equiv.Perm (Card L)) : + centralDistance L (r+1) C D = + centralDistance L r (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u))+ + centralDistance L r (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) := by + classical + unfold centralDistance + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => permDistance (C (Fin.cons x.1 x.2)) (D (Fin.cons x.1 x.2))) + (fun x => by + change permDistance (C x) (D x) = + permDistance (C (Fin.cons (x 0) (Fin.tail x))) (D (Fin.cons (x 0) (Fin.tail x))) + rw [Fin.cons_self_tail])] + simp only [Fintype.sum_prod_type,Fintype.sum_bool] + omega + +lemma permDistance_centralBlock (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) : + permDistance (centralBlockPerm L r C) (centralBlockPerm L r D) = centralDistance L r C D := by + induction r with + | zero => + simp only [centralBlockPerm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + rw [centralBlockPerm,centralBlockPerm,permDistance_childLift,centralDistance_step,ih,ih] + +lemma permDistance_centralPalindrome (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (ω : BenesCoins (L+r)) : + permDistance (centralPalindromePerm L r C ω) (centralPalindromePerm L r D ω) = + centralDistance L r C D := by + rw [centralPalindromePerm,centralPalindromePerm,permDistance_mul_right, + permDistance_mul_left,permDistance_centralBlock] + +lemma centralLevelCost_step (t L r : ℕ) (C : Card (r+1) → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : BenesCoins (L+r) × BenesCoins (L+r)) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + centralLevelCost t L (r+1) C e ((benesStepEquiv (L+r)).symm (ω,coins)) = + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let c := PairRouting.colors x coins.1 + let hc := PairRouting.colors_compatible x coins.1 + if t = L+r+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x coins.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) (if b then ω.2 else ω.1)) + else centralLevelCost t L r (fun u => C (Fin.cons false u)) + (PairRouting.childEmbedding x c hc false) ω.1 + + centralLevelCost t L r (fun u => C (Fin.cons true u)) + (PairRouting.childEmbedding x c hc true) ω.2 := by + rw [centralLevelCost] + rfl + +lemma centralLevelCost_perturb (t L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralLevelCost t L r C e ω ≤ centralLevelCost t L r D e ω+centralDistance L r C D := by + induction r generalizing ι with + | zero => simp only [centralLevelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [←(benesStepEquiv (L+r)).symm_apply_apply ω,centralLevelCost_step,centralLevelCost_step] + dsimp only + split_ifs with ht + · have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (benesStepEquiv (L+r) ω).2.1) + (fun b => centralPalindromePerm L r (fun u => C (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + (fun b => centralPalindromePerm L r (fun u => D (Fin.cons b u)) + (if b then (benesStepEquiv (L+r) ω).1.2 else (benesStepEquiv (L+r) ω).1.1)) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_centralPalindrome,←centralDistance_step] using hh + · rw [centralDistance_step] + have h₀ := ih (fun u => C (Fin.cons false u)) (fun u => D (Fin.cons false u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) false) + (benesStepEquiv (L+r) ω).1.1 + have h₁ := ih (fun u => C (Fin.cons true u)) (fun u => D (Fin.cons true u)) + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (benesStepEquiv (L+r) ω).2.1) + (PairRouting.colors_compatible _ _) true) + (benesStepEquiv (L+r) ω).1.2 + omega + +lemma centralSlabCost_perturb (l L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : BenesCoins (L+r)) : + centralSlabCost l L r C e ω ≤ centralSlabCost l L r D e ω+l*centralDistance L r C D := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + centralLevelCost_perturb (l+i.val+1) L r C D e ω) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,centralSlabCost] using hh + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/InputTree.lean b/lean/OAI/Probability/ThorpRouting/Tail/InputTree.lean index 07b425a7131ce490660d31c903ad590aab9bf91e..0ef5fe2863f0ae3e568f0b018087afaf3ce84690 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/InputTree.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/InputTree.lean @@ -1,884 +1,884 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.HeightDecay - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) - (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : - centralDistance L r C D ≤ E.card*2^L := by - classical - calc - _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by - apply Finset.sum_le_sum - intro u _ - split_ifs with hu - · simpa only [card_positions] using permDistance_le (C u) (D u) - · rw [h u hu,permDistance_refl] - _ = _ := by simp - - -inductive InputTree : ℕ → Type - | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d - | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) - -def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) - | _, .tip p => p - | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) - -noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → - {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ - | _, .tip _, _, _, _, _ => 0 - | d+1, .node ξ T, _, _, e, Y => - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let σ := coinStepEquiv d Y - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) - (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : - (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) - else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + - (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by - rw [InputTree.levelCost] - rfl - -lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - T.levelCost t e Y = 0 := by - induction T generalizing ι with - | tip p => rfl - | @node d ξ T ih => - rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] - -lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by - induction T generalizing ι with - | tip p => intro Y Y' _; rfl - | @node d ξ T ih => - intro Y Y' h - dsimp only - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] - rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), - InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih false - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih true - intro i hi - exact h (Sum.inr (true,i)) hi - -theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) - (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - cases T with - | tip p => - simp only [InputTree.levelCost,pow_zero,finiteMean_const] - exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) - | node ξ T => - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x ξ - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => - if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ - else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - (T false).levelCost (s+u+1) e₀ (Y₀ hi) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - (T true).levelCost (s+u+1) e₁ (Y₁ hi) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - (InputTree.node ξ T).levelCost (s+u+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' (T false).perm (T true).perm - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' (T false) e₀ lo₀ - have h₁ := ih u hu' (T true) e₁ lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i : Fin l, T.levelCost (l+i.1+1) e Y - -lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) : - LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) - -theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)))) := by - apply finiteMean_mono - intro hi - simpa only [InputTree.slabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e - (assembleBits r s lo hi)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → - (SwitchIndex (L+r) → Bool) → InputTree (L+r) - | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) - | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => - boundaryTree L r (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) - -def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → - Card r → Equiv.Perm (Card L) - | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) - | r+1, Y, u => boundaryOutput L r - (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) - -lemma boundaryOutput_adapted (L r : ℕ) : - LayerAdapted (L+r) L (boundaryOutput L r) := by - induction r with - | zero => - intro Y Y' h - have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) - rw [he] - | succ r ih => - intro Y Y' h - funext u - dsimp only [boundaryOutput] - cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) - · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) - -noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u - -lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) : - LayerAdapted (L+r) L (modifiedBoundary L r E U) := by - intro Y Y' h - unfold modifiedBoundary - rw [boundaryOutput_adapted L r Y Y' h] - -lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) : - permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = - centralDistance L r U V := by - induction r with - | zero => - simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] - congr 1 - | succ r ih => - simp only [boundaryTree,InputTree.perm,permDistance_mul_left] - rw [permDistance_childLift,centralDistance_step,ih,ih] - -lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y ≤ - (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by - induction r generalizing ι with - | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] - | succ r ih => - rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] - by_cases ht : t = L+r+1 - · simp only [ite_eq_left ht] - have hh := alternatingCycles_distance_le - (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (coinStepEquiv (L+r) X).2) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * - (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ - else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * - (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) - simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, - permDistance_boundaryTree,←centralDistance_step] using hh - · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] - rw [centralDistance_step] - have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) - (coinStepEquiv (L+r) X).1.1 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 - have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) - (coinStepEquiv (L+r) X).1.2 - (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) - (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 - omega - -lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by - have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => - boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) - simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh - -lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : - centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by - apply centralDistance_exceptional - intro u hu - exact ite_eq_right hu - - -lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.slabCost l d T e Y = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact InputTree.levelCost_gt _ _ T (by omega) _ _ - -lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - apply adapted_mul_mean_le r s F _ hF hA - intro lo - let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false - have he (hi : Card s × SwitchIndex r → Bool) : - T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := - hT _ _ (assembleBits_agree r s lo hi hi₀) - simp_rw [he] - exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog - -lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) - (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) - (fun _ _ _ => rfl) q hq hlog - simpa only [one_mul,finiteMean_const] using hh - -noncomputable def InputTree.familyCost (L n d : ℕ) - (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y - -lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by - intro Y Y' h - dsimp only - rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] - exact InputTree.slabCost_adapted l d (T Y') e Y Y' - (agreeThrough_mono (le_max_right _ _) h) - -lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : - LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) - (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) - -theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, - Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by - induction n with - | zero => - simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, - finiteMean_const,mul_zero,add_zero] - exact Real.one_le_exp hp - | succ n ih => - by_cases hn : n = 0 - · subst n - simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst - · let l := L*4^n - have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) - have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n - have hs' : s ≤ familyEnd L n := by - have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) - simp only [pow_zero,mul_one] at hh - omega - have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = - InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by - intro Y - exact Finset.sum_range_succ _ _ - have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * - Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - by_cases hld : l ≤ d - · simp_rw [hc,pow_add] - apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T - (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) - · apply layerAdapted_comp - exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) - · exact hq - · exact hlog - · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] - exact le_mul_of_one_le_right - (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.one_le_exp_iff.mpr (by positivity)) - refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ - rw [←Real.exp_add,Finset.sum_range_succ] - congr 1 - dsimp only [l] - ring - -lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) - (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) - (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ - Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : - finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ - Real.exp (p+Fintype.card ι*heightDecay L) := by - apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans - apply Real.exp_le_exp.mpr - apply add_le_add_right - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) - simpa only [heightDecay,mul_div_assoc] using hh - - -noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := - boundaryTree L r (modifiedBoundary L r E U Y) X - -lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : - LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by - intro Y Y' h - unfold modifiedInputTree - rw [modifiedBoundary_adapted L r E U Y Y' h] - -lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ - Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by - have hqp : 0 < q := by linarith - have hpoint (Y : SwitchIndex (L+r) → Bool) : - InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ - InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by - apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans - apply Nat.add_le_add_left - simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) - calc - _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := - finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) - _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * - q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ - _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := - mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) - _ = _ := by - have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by - rw [Real.exp_nat_mul,Real.exp_log hqp] - rw [Real.exp_add,he,mul_comm] - -lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by - exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ - (modifiedInputTree_adapted L r E U X) e q hq hlog _ - (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) - (modified_slab_mgf l L r hl E U X e q hq hlog) - -theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ - InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hq2 := one_le_pow₀ (n:=2) hq - have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith - have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 - have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 - have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) - (modifiedInputTree L r E U X) e Y)) ≤ - Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by - apply h₁.trans - apply Real.exp_le_exp.mpr - exact add_le_add_right (mul_le_mul_of_nonneg_left - (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ - have hh := finiteMean_mul_exp_le - (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) - (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) - _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') - simp only [←pow_add] at hh - refine hh.trans_eq ?_ - congr 1 - simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] - ring - -noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := - ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y - -lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by - rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] - congr 1 - exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L - -lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + - InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by - induction n with - | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, - pow_zero,mul_one] - | succ n ih => - have he : (2*L)*4^n = 2*(L*4^n) := by ring - have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring - simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ - rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] - omega - -lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : - InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by - symm - apply Finset.sum_subset (Finset.range_mono hd) - intro i _ hi - have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi - exact InputTree.levelCost_gt (i+1) d T (by omega) e Y - -lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - (boundaryTree L r U X).levelCost t e Y = 0 := by - induction r generalizing ι with - | zero => rfl - | succ r ih => - rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] - -lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) - (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by - apply Finset.sum_eq_zero - intro i hi - exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y - -theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/500) : - finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by - have hbound : L+r ≤ L*4^(L+r) := by - have h₀ := pow_four_ge (L+r) - have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL - nlinarith - have he (Y : SwitchIndex (L+r) → Bool) := - InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y - have hz (Y : SwitchIndex (L+r) → Bool) : - InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := - boundaryTree_lowCost_zero L r _ X e Y - simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he - simp_rw [←he] - exact modified_high_mgf L (L+r) r hL E U X e q hq hlog - - -noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := - Finset.univ.filter (fun u => Fin.cons b u ∈ E) - -lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : - u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by - classical - simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] - -lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : - (exceptionChild E false).card+(exceptionChild E true).card = E.card := by - classical - have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp - rw [Fintype.sum_equiv (headTailEquiv r) _ - (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) - (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he - simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he - simpa only [exceptionChild,Finset.card_filter,add_comm] using he - -def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where - toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) - invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) - left_inv U := by - funext u - dsimp only - split_ifs with h - · rw [←h,Fin.cons_self_tail] - · have h' : u 0 = false := by cases hh : u 0 <;> simp_all - rw [←h',Fin.cons_self_tail] - right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] - -def seedSandwichShuffle {A B C D E : Type*} : - (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where - toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) - invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) - left_inv _ := rfl - right_inv _ := rfl - -abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) - -def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ - (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := - (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans - seedSandwichShuffle - -noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - Equiv.Perm (Card (L+r)) := - butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * - (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ - -noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := - InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 - -lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) - (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : - (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = - modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) - (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by - funext u - simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] - -lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - let z := (modifiedStepEquiv L r).symm (ω,coins) - modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = - InputTree.node coins.1 (fun b => - let w := if b then ω.2 else ω.1 - modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by - dsimp only - unfold modifiedInputTree - rw [boundaryTree] - change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ - congr 1 - funext b - rw [modifiedBoundary_cons] - cases b <;> rfl - -lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = - pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by - rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] - change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ - rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] - congr 2 - apply congrArg childLift - funext b - cases b <;> rfl - -lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) - (x : Card (L+r+1)) : - headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = - PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) - (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by - rw [modifiedPerm_step] - simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] - rfl - -lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (η : Card d → Bool) : - InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ - else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + - InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + - InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by - dsimp only - rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] - have he : (∑ i ∈ Finset.range d, - (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = - InputTree.lowCost d d (T false) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + - InputTree.lowCost d d (T true) - (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by - rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro i hi - rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] - rw [he] - omega - -noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := - PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + - modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 - -lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) - (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = - modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) - (PairRouting.colors_compatible _ _) ω := by - rw [modifiedCost,modifiedInputTree_node] - change InputTree.lowCost (L+r+1) (L+r+1) _ e - ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ - rw [InputTree.lowCost_node] - unfold modifiedAssignmentCost - dsimp only - simp only [Bool.false_eq_true,↓reduceIte] - rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] - congr 2 - - -namespace PairRouting -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] - -omit [Fintype α] [DecidableEq ι] in -lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) - (c : ι → Bool) (hc : Compatible x c) (b : Bool) : - Function.Surjective (childEmbedding x c hc b) := by - intro y - have hs : Function.Surjective (coloredEmbedding x c hc) := - (pairLayer (chosenCoin x c)).surjective.comp hx - obtain ⟨i,hi⟩ := hs (b,y) - rw [coloredEmbedding_apply] at hi - exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ - -omit [DecidableEq ι] in -lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : - finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ - 1/(Fintype.card (Equiv.Perm α):ℝ) := by - classical - let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i - have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by - have hh : p*u⁻¹ = p*v⁻¹ := by - ext x - obtain ⟨i,rfl⟩ := he x - exact (hu i).trans (hv i).symm - exact inv_injective (mul_left_cancel hh) - unfold finiteMean - apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 - by_cases h : ∃ u, M u - · obtain ⟨u,hu⟩ := h - rw [Finset.sum_eq_single u] - · simp only [hu,↓reduceIte,le_refl] - · intro v _ hv - exact ite_eq_right (fun hh => hv (huniq v u hh hu)) - · simp - · push Not at h - simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] - -end PairRouting - -noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := - (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) - -lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ - -lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : - centralFactor L (r+1) E a = - centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by - unfold centralFactor - rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] - congr 1 - have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by - exact_mod_cast exceptionChild_card_add E - rw [pow_succ,←he] - ring - -lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : - modifiedPerm L 0 E ω = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 - else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by - unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput - split_ifs - · exact mul_inv_cancel _ - · rfl - -lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by - simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, - InputTree.levelCost,Finset.sum_const_zero] - -lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : - centralFactor L 0 E a = - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by - classical - let z : Card 0 := fun j => Fin.elim0 j - have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by - by_cases hz : z ∈ E - · have he : E = {z} := by - ext u - rw [Subsingleton.elim u z] - simp only [hz,Finset.mem_singleton] - rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] - · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) - rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] - unfold centralFactor - rw [pow_zero,he] - split_ifs <;> simp - -lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : - PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ - if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by - classical - rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] - let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) - change _ ≤ B - calc - _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by - apply finiteMean_mono - intro ω - simp only [modifiedPerm_zero] - by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E - · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] - split_ifs <;> norm_num - · simp only [h,↓reduceIte,B] - rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => - if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] - convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 - rw [Fintype.card_perm,card_positions] - _ = _ := finiteMean_const B - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.HeightDecay + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +lemma centralDistance_exceptional (L r : ℕ) (C D : Card r → Equiv.Perm (Card L)) + (E : Finset (Card r)) (h : ∀ u ∉ E, C u = D u) : + centralDistance L r C D ≤ E.card*2^L := by + classical + calc + _ ≤ ∑ u : Card r, if u ∈ E then 2^L else 0 := by + apply Finset.sum_le_sum + intro u _ + split_ifs with hu + · simpa only [card_positions] using permDistance_le (C u) (D u) + · rw [h u hu,permDistance_refl] + _ = _ := by simp + + +inductive InputTree : ℕ → Type + | tip {d : ℕ} (p : Equiv.Perm (Card d)) : InputTree d + | node {d : ℕ} (ξ : Card d → Bool) (T : Bool → InputTree d) : InputTree (d+1) + +def InputTree.perm : {d : ℕ} → InputTree d → Equiv.Perm (Card d) + | _, .tip p => p + | _, .node ξ T => pairSwitch ξ * childLift (fun b => (T b).perm) + +noncomputable def InputTree.levelCost (t : ℕ) : {d : ℕ} → InputTree d → + {ι : Type*} → [Fintype ι] → (ι ↪ Card d) → (SwitchIndex d → Bool) → ℕ + | _, .tip _, _, _, _, _ => 0 + | d+1, .node ξ T, _, _, e, Y => + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let σ := coinStepEquiv d Y + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d σ.1.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d σ.1.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) σ.1.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma InputTree.levelCost_node (t d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) + (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (η : Card d → Bool) : + (InputTree.node ξ T).levelCost t e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + else (T false).levelCost t (PairRouting.childEmbedding x c hc false) Y.1 + + (T true).levelCost t (PairRouting.childEmbedding x c hc true) Y.2 := by + rw [InputTree.levelCost] + rfl + +lemma InputTree.levelCost_gt (t d : ℕ) (T : InputTree d) (ht : d < t) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + T.levelCost t e Y = 0 := by + induction T generalizing ι with + | tip p => rfl + | @node d ξ T ih => + rw [InputTree.levelCost,ite_eq_right (by omega : t ≠ d+1),ih false (by omega),ih true (by omega)] + +lemma InputTree.levelCost_adapted (t d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (t-1) (fun Y => T.levelCost t e Y) := by + induction T generalizing ι with + | tip p => intro Y Y' _; rfl + | @node d ξ T ih => + intro Y Y' h + dsimp only + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y'] + rw [InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y).1) ((coinStepEquiv d Y).2), + InputTree.levelCost_node t d ξ T e ((coinStepEquiv d Y').1) ((coinStepEquiv d Y').2)] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih false + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih true + intro i hi + exact h (Sum.inr (true,i)) hi + +theorem InputTree.level_partial_mgf (r s u : ℕ) (hu : u < r) + (T : InputTree (s+r)) {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(T.levelCost (s+u+1) e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + cases T with + | tip p => + simp only [InputTree.levelCost,pow_zero,finiteMean_const] + exact Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) (cycleCoefficient_nonneg u J q hq)) + | node ξ T => + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x ξ + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => + if b then butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi.2)) * (T true).perm⁻¹ + else butterflyPerm (s+r) (decodeButterfly (s+r) (Y₀ hi.1)) * (T false).perm⁻¹) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + (T false).levelCost (s+u+1) e₀ (Y₀ hi) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + (T true).levelCost (s+u+1) e₁ (Y₁ hi) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + (InputTree.node ξ T).levelCost (s+u+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η))) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + rw [InputTree.levelCost_node (s+u+1) (s+r) ξ T e (Y₀ hi.1,Y₁ hi.2) (fun y => η (((cardSplit r s) y).2,((cardSplit r s) y).1))] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' (T false).perm (T true).perm + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' (T false) e₀ lo₀ + have h₁ := ih u hu' (T true) e₁ lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +noncomputable def InputTree.slabCost (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i : Fin l, T.levelCost (l+i.1+1) e Y + +lemma InputTree.slabCost_adapted (l d : ℕ) (T : InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) : + LayerAdapted d (2*l) (fun Y => InputTree.slabCost l d T e Y) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (InputTree.levelCost_adapted (l+i.1+1) d T e) (by omega) + +theorem InputTree.slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) (T : InputTree (s+r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(InputTree.slabCost l (s+r) T e (assembleBits r s lo hi))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)))) := by + apply finiteMean_mono + intro hi + simpa only [InputTree.slabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => T.levelCost (l+i.1+1) e + (assembleBits r s lo hi)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*T.levelCost (l+i.1+1) e (assembleBits r s lo hi)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := InputTree.level_partial_mgf r s (l+i.1-s) hu T e lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := InputTree.levelCost_gt (l+i.1+1) (s+r) T (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +def boundaryTree (L : ℕ) : (r : ℕ) → (Card r → Equiv.Perm (Card L)) → + (SwitchIndex (L+r) → Bool) → InputTree (L+r) + | 0, U, _ => .tip (U (fun j => Fin.elim0 j)) + | r+1, U, X => .node (coinStepEquiv (L+r) X).2 (fun b => + boundaryTree L r (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) X).1.2 else (coinStepEquiv (L+r) X).1.1)) + +def boundaryOutput (L : ℕ) : (r : ℕ) → (SwitchIndex (L+r) → Bool) → + Card r → Equiv.Perm (Card L) + | 0, Y, _ => butterflyPerm L (decodeButterfly L Y) + | r+1, Y, u => boundaryOutput L r + (if u 0 then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) (Fin.tail u) + +lemma boundaryOutput_adapted (L r : ℕ) : + LayerAdapted (L+r) L (boundaryOutput L r) := by + induction r with + | zero => + intro Y Y' h + have he : Y = Y' := funext (fun i => h i (by simpa only [Nat.add_zero] using switchHeight_le L i)) + rw [he] + | succ r ih => + intro Y Y' h + funext u + dsimp only [boundaryOutput] + cases hb : u 0 <;> simp only [Bool.false_eq_true,↓reduceIte] + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (false,i)) hi)) (Fin.tail u) + · exact congrFun (ih _ _ (fun i hi => h (Sum.inr (true,i)) hi)) (Fin.tail u) + +noncomputable def modifiedBoundary (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + Card r → Equiv.Perm (Card L) := fun u => if u ∈ E then boundaryOutput L r Y u else U u + +lemma modifiedBoundary_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) : + LayerAdapted (L+r) L (modifiedBoundary L r E U) := by + intro Y Y' h + unfold modifiedBoundary + rw [boundaryOutput_adapted L r Y Y' h] + +lemma permDistance_boundaryTree (L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) : + permDistance (boundaryTree L r U X).perm (boundaryTree L r V X).perm = + centralDistance L r U V := by + induction r with + | zero => + simp only [boundaryTree,InputTree.perm,centralDistance,Fintype.sum_unique] + congr 1 + | succ r ih => + simp only [boundaryTree,InputTree.perm,permDistance_mul_left] + rw [permDistance_childLift,centralDistance_step,ih,ih] + +lemma boundaryTree_levelCost_perturb (t L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y ≤ + (boundaryTree L r V X).levelCost t e Y + centralDistance L r U V := by + induction r generalizing ι with + | zero => simp only [boundaryTree,InputTree.levelCost,Nat.zero_add,Nat.zero_le] + | succ r ih => + rw [boundaryTree,boundaryTree,InputTree.levelCost,InputTree.levelCost] + by_cases ht : t = L+r+1 + · simp only [ite_eq_left ht] + have hh := alternatingCycles_distance_le + (PairRouting.switchedEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (coinStepEquiv (L+r) X).2) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => U (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => U (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + (fun b => if b then butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.2) * + (boundaryTree L r (fun u => V (Fin.cons true u)) (coinStepEquiv (L+r) X).1.2).perm⁻¹ + else butterflyPerm (L+r) (decodeButterfly (L+r) (coinStepEquiv (L+r) Y).1.1) * + (boundaryTree L r (fun u => V (Fin.cons false u)) (coinStepEquiv (L+r) X).1.1).perm⁻¹) + simpa only [Bool.false_eq_true,↓reduceIte,permDistance_mul_left,permDistance_inv, + permDistance_boundaryTree,←centralDistance_step] using hh + · simp only [ite_eq_right ht,Bool.false_eq_true,↓reduceIte] + rw [centralDistance_step] + have h₀ := ih (fun u => U (Fin.cons false u)) (fun u => V (Fin.cons false u)) + (coinStepEquiv (L+r) X).1.1 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) false) (coinStepEquiv (L+r) Y).1.1 + have h₁ := ih (fun u => U (Fin.cons true u)) (fun u => V (Fin.cons true u)) + (coinStepEquiv (L+r) X).1.2 + (PairRouting.childEmbedding (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) (coinStepEquiv (L+r) X).2) + (PairRouting.colors_compatible _ _) true) (coinStepEquiv (L+r) Y).1.2 + omega + +lemma boundaryTree_slabCost_perturb (l L r : ℕ) (U V : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r V X) e Y + l*centralDistance L r U V := by + have hh := Finset.sum_le_sum (fun (i : Fin l) (_ : i ∈ Finset.univ) => + boundaryTree_levelCost_perturb (l+i.val+1) L r U V X e Y) + simpa only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_id,InputTree.slabCost] using hh + +lemma modifiedBoundary_distance_le (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r) → Bool) : + centralDistance L r (modifiedBoundary L r E U Y) U ≤ E.card*2^L := by + apply centralDistance_exceptional + intro u hu + exact ite_eq_right hu + + +lemma InputTree.slabCost_gt (l d : ℕ) (T : InputTree d) (hd : d ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.slabCost l d T e Y = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact InputTree.levelCost_gt _ _ T (by omega) _ _ + +lemma InputTree.random_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (F : (SwitchIndex d → Bool) → ℝ) (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(InputTree.slabCost l d (T Y) e Y)) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + apply adapted_mul_mean_le r s F _ hF hA + intro lo + let hi₀ : Card s × SwitchIndex r → Bool := fun _ => false + have he (hi : Card s × SwitchIndex r → Bool) : + T (assembleBits r s lo hi) = T (assembleBits r s lo hi₀) := + hT _ _ (assembleBits_agree r s lo hi hi₀) + simp_rw [he] + exact InputTree.slab_partial_mgf r s l hl hs _ e lo q hq hlog + +lemma InputTree.slab_mgf (l d : ℕ) (hl : 0 < l) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l d T e Y)) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + have hh := InputTree.random_slab_adapted_mul_le d 0 l (Nat.zero_le _) hl (Nat.zero_le _) + (fun _ => T) (fun _ _ _ => rfl) e (fun _ => 1) (fun _ => by norm_num) + (fun _ _ _ => rfl) q hq hlog + simpa only [one_mul,finiteMean_const] using hh + +noncomputable def InputTree.familyCost (L n d : ℕ) + (T : (SwitchIndex d → Bool) → InputTree d) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ j ∈ Finset.range n, InputTree.slabCost (L*4^j) d (T Y) e Y + +lemma InputTree.random_slabCost_adapted (l d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (2*l)) (fun Y => InputTree.slabCost l d (T Y) e Y) := by + intro Y Y' h + dsimp only + rw [hT _ _ (agreeThrough_mono (le_max_left _ _) h)] + exact InputTree.slabCost_adapted l d (T Y') e Y Y' + (agreeThrough_mono (le_max_right _ _) h) + +lemma InputTree.familyCost_adapted (L n d s : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + (hT : LayerAdapted d s T) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) : + LayerAdapted d (max s (familyEnd L n)) (fun Y => InputTree.familyCost L n d T e Y) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (InputTree.random_slabCost_adapted (L*4^j) d s T hT e) + (max_le_max_left s (familyEnd_ge L n j (Finset.mem_range.mp hj))) + +theorem InputTree.family_mgf_first (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*∑ j ∈ Finset.range n, + Real.exp (-((L*4^j:ℕ):ℝ)/64))) := by + induction n with + | zero => + simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,pow_zero, + finiteMean_const,mul_zero,add_zero] + exact Real.one_le_exp hp + | succ n ih => + by_cases hn : n = 0 + · subst n + simpa only [InputTree.familyCost,Nat.zero_add,Finset.sum_range_one,pow_zero,mul_one] using hfirst + · let l := L*4^n + have hl : 0 < l := Nat.mul_pos hL (pow_pos (by decide) _) + have hsl : 2*familyEnd L n ≤ l := familyEnd_two L n + have hs' : s ≤ familyEnd L n := by + have hh := familyEnd_ge L n 0 (Nat.pos_of_ne_zero hn) + simp only [pow_zero,mul_one] at hh + omega + have hc : ∀ Y, InputTree.familyCost L (n+1) d T e Y = + InputTree.familyCost L n d T e Y+InputTree.slabCost l d (T Y) e Y := by + intro Y + exact Finset.sum_range_succ _ _ + have hm : finiteMean (fun Y => q^(InputTree.familyCost L (n+1) d T e Y)) ≤ + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) * + Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + by_cases hld : l ≤ d + · simp_rw [hc,pow_add] + apply InputTree.random_slab_adapted_mul_le d (familyEnd L n) l (by omega) hl hsl T + (layerAdapted_mono hT hs') e _ (fun _ => pow_nonneg (by linarith) _) + · apply layerAdapted_comp + exact layerAdapted_mono (InputTree.familyCost_adapted L n d s T hT e) (max_le hs' le_rfl) + · exact hq + · exact hlog + · simp_rw [hc,InputTree.slabCost_gt l d _ (by omega),Nat.add_zero] + exact le_mul_of_one_le_right + (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.one_le_exp_iff.mpr (by positivity)) + refine (hm.trans (mul_le_mul_of_nonneg_right ih (Real.exp_nonneg _))).trans_eq ?_ + rw [←Real.exp_add,Finset.sum_range_succ] + congr 1 + dsimp only [l] + ring + +lemma InputTree.family_mgf_first_decay (L n d s : ℕ) (hL : 0 < L) (hs : s ≤ L) + (T : (SwitchIndex d → Bool) → InputTree d) (hT : LayerAdapted d s T) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) (p : ℝ) (hp : 0 ≤ p) + (hfirst : finiteMean (fun Y => q^(InputTree.slabCost L d (T Y) e Y)) ≤ + Real.exp (p+Fintype.card ι*(68*Real.exp (-(L:ℝ)/64)))) : + finiteMean (fun Y => q^(InputTree.familyCost L n d T e Y)) ≤ + Real.exp (p+Fintype.card ι*heightDecay L) := by + apply (InputTree.family_mgf_first L n d s hL hs T hT e q hq hlog p hp hfirst).trans + apply Real.exp_le_exp.mpr + apply add_le_add_right + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have hh := mul_le_mul_of_nonneg_left (sum_family_decay L n hL) (by norm_num : (0:ℝ)≤68) + simpa only [heightDecay,mul_div_assoc] using hh + + +noncomputable def modifiedInputTree (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X Y : SwitchIndex (L+r) → Bool) : InputTree (L+r) := + boundaryTree L r (modifiedBoundary L r E U Y) X + +lemma modifiedInputTree_adapted (L r : ℕ) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) : + LayerAdapted (L+r) L (modifiedInputTree L r E U X) := by + intro Y Y' h + unfold modifiedInputTree + rw [modifiedBoundary_adapted L r E U Y Y' h] + +lemma modified_slab_mgf (l L r : ℕ) (hl : 0 < l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+ + Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) := by + have hqp : 0 < q := by linarith + have hpoint (Y : SwitchIndex (L+r) → Bool) : + InputTree.slabCost l (L+r) (modifiedInputTree L r E U X Y) e Y ≤ + InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L := by + apply (boundaryTree_slabCost_perturb l L r (modifiedBoundary L r E U Y) U X e Y).trans + apply Nat.add_le_add_left + simpa only [Nat.mul_assoc] using Nat.mul_le_mul_left l (modifiedBoundary_distance_le L r E U Y) + calc + _ ≤ finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y+l*E.card*2^L)) := + finiteMean_mono (fun Y => pow_le_pow_right₀ hq (hpoint Y)) + _ = finiteMean (fun Y => q^(InputTree.slabCost l (L+r) (boundaryTree L r U X) e Y)) * + q^(l*E.card*2^L) := by simp_rw [pow_add]; exact finiteMean_mul_const _ _ + _ ≤ Real.exp (Fintype.card ι*(68*Real.exp (-(l:ℝ)/64))) * q^(l*E.card*2^L) := + mul_le_mul_of_nonneg_right (InputTree.slab_mgf l (L+r) hl _ e q hq hlog) (pow_nonneg (by linarith) _) + _ = _ := by + have he : Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q) = q^(l*E.card*2^L) := by + rw [Real.exp_nat_mul,Real.exp_log hqp] + rw [Real.exp_add,he,mul_comm] + +lemma modified_family_mgf (l n L r : ℕ) (hl : 0 < l) (hLl : L ≤ l) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => q^(InputTree.familyCost l n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (((l*E.card*2^L:ℕ):ℝ)*Real.log q+Fintype.card ι*heightDecay l) := by + exact InputTree.family_mgf_first_decay l n (L+r) L hl hLl _ + (modifiedInputTree_adapted L r E U X) e q hq hlog _ + (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg hq)) + (modified_slab_mgf l L r hl E U X e q hq hlog) + +theorem modified_high_mgf (L n r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y+ + InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hq2 := one_le_pow₀ (n:=2) hq + have hlog2 : Real.log (q^2) ≤ 1/250 := by rw [Real.log_pow]; norm_num; linarith + have h₀ := modified_family_mgf L n L r hL le_rfl E U X e (q^2) hq2 hlog2 + have h₁ := modified_family_mgf (2*L) n L r (by omega) (by omega) E U X e (q^2) hq2 hlog2 + have h₁' : finiteMean (fun Y => (q^2)^(InputTree.familyCost (2*L) n (L+r) + (modifiedInputTree L r E U X) e Y)) ≤ + Real.exp ((((2*L)*E.card*2^L:ℕ):ℝ)*Real.log (q^2)+Fintype.card ι*heightDecay L) := by + apply h₁.trans + apply Real.exp_le_exp.mpr + exact add_le_add_right (mul_le_mul_of_nonneg_left + (heightDecay_antitone (show L ≤ 2*L by omega)) (Nat.cast_nonneg _)) _ + have hh := finiteMean_mul_exp_le + (fun Y => q^(InputTree.familyCost L n (L+r) (modifiedInputTree L r E U X) e Y)) + (fun Y => q^(InputTree.familyCost (2*L) n (L+r) (modifiedInputTree L r E U X) e Y)) + _ _ (by simpa only [pow_right_comm] using h₀) (by simpa only [pow_right_comm] using h₁') + simp only [←pow_add] at hh + refine hh.trans_eq ?_ + congr 1 + simp only [Real.log_pow,Nat.cast_mul,Nat.cast_ofNat] + ring + +noncomputable def InputTree.lowCost (H d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : ℕ := + ∑ i ∈ Finset.range H, T.levelCost (i+1) e Y + +lemma InputTree.lowCost_slab (L d : ℕ) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d T e Y+InputTree.slabCost L d T e Y = InputTree.lowCost (2*L) d T e Y := by + rw [InputTree.lowCost,InputTree.lowCost,show 2*L=L+L by omega,Finset.sum_range_add] + congr 1 + exact Fin.sum_univ_eq_sum_range (fun i => T.levelCost (L+i+1) e Y) L + +lemma InputTree.cost_family (L n d : ℕ) (T : (SwitchIndex d → Bool) → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost L d (T Y) e Y + InputTree.familyCost L n d T e Y + + InputTree.familyCost (2*L) n d T e Y = InputTree.lowCost (L*4^n) d (T Y) e Y := by + induction n with + | zero => simp only [InputTree.familyCost,Finset.range_zero,Finset.sum_empty,Nat.add_zero, + pow_zero,mul_one] + | succ n ih => + have he : (2*L)*4^n = 2*(L*4^n) := by ring + have he' : L*4^(n+1) = 2*(2*(L*4^n)) := by rw [pow_succ]; ring + simp only [InputTree.familyCost,Finset.sum_range_succ] at ih ⊢ + rw [he,he',←InputTree.lowCost_slab,←InputTree.lowCost_slab,←ih] + omega + +lemma InputTree.lowCost_ge (H d : ℕ) (hd : d ≤ H) (T : InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card d) (Y : SwitchIndex d → Bool) : + InputTree.lowCost H d T e Y = InputTree.lowCost d d T e Y := by + symm + apply Finset.sum_subset (Finset.range_mono hd) + intro i _ hi + have hi' : d ≤ i := by simpa only [Finset.mem_range,not_lt] using hi + exact InputTree.levelCost_gt (i+1) d T (by omega) e Y + +lemma boundaryTree_levelCost_low (t L r : ℕ) (ht : t ≤ L) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + (boundaryTree L r U X).levelCost t e Y = 0 := by + induction r generalizing ι with + | zero => rfl + | succ r ih => + rw [boundaryTree,InputTree.levelCost,ite_eq_right (by omega : t ≠ L+r+1),ih,ih] + +lemma boundaryTree_lowCost_zero (L r : ℕ) (U : Card r → Equiv.Perm (Card L)) + (X : SwitchIndex (L+r) → Bool) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (boundaryTree L r U X) e Y = 0 := by + apply Finset.sum_eq_zero + intro i hi + exact boundaryTree_levelCost_low (i+1) L r (by simpa only [Finset.mem_range,Nat.lt_iff_add_one_le] using hi) U X e Y + +theorem modified_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + (U : Card r → Equiv.Perm (Card L)) (X : SwitchIndex (L+r) → Bool) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/500) : + finiteMean (fun Y => q^(InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E U X Y) e Y)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log q) := by + have hbound : L+r ≤ L*4^(L+r) := by + have h₀ := pow_four_ge (L+r) + have h₁ := Nat.mul_le_mul_right (4^(L+r)) hL + nlinarith + have he (Y : SwitchIndex (L+r) → Bool) := + InputTree.cost_family L (L+r) (L+r) (modifiedInputTree L r E U X) e Y + have hz (Y : SwitchIndex (L+r) → Bool) : + InputTree.lowCost L (L+r) (modifiedInputTree L r E U X Y) e Y = 0 := + boundaryTree_lowCost_zero L r _ X e Y + simp only [hz,Nat.zero_add,InputTree.lowCost_ge _ _ hbound] at he + simp_rw [←he] + exact modified_high_mgf L (L+r) r hL E U X e q hq hlog + + +noncomputable def exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) : Finset (Card r) := + Finset.univ.filter (fun u => Fin.cons b u ∈ E) + +lemma mem_exceptionChild {r : ℕ} (E : Finset (Card (r+1))) (b : Bool) (u : Card r) : + u ∈ exceptionChild E b ↔ Fin.cons b u ∈ E := by + classical + simp only [exceptionChild,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma exceptionChild_card_add {r : ℕ} (E : Finset (Card (r+1))) : + (exceptionChild E false).card+(exceptionChild E true).card = E.card := by + classical + have he : (∑ u : Card (r+1), if u ∈ E then 1 else 0) = E.card := by simp + rw [Fintype.sum_equiv (headTailEquiv r) _ + (fun x : Bool × Card r => if Fin.cons x.1 x.2 ∈ E then 1 else 0) + (fun x => by change (if x ∈ E then 1 else 0) = (if Fin.cons (x 0) (Fin.tail x) ∈ E then 1 else 0); rw [Fin.cons_self_tail])] at he + simp only [Fintype.sum_prod_type,Fintype.sum_bool] at he + simpa only [exceptionChild,Finset.card_filter,add_comm] using he + +def seedSplitEquiv (r : ℕ) (A : Type*) : (Card (r+1) → A) ≃ (Card r → A) × (Card r → A) where + toFun U := (fun u => U (Fin.cons false u),fun u => U (Fin.cons true u)) + invFun U := fun u => if u 0 then U.2 (Fin.tail u) else U.1 (Fin.tail u) + left_inv U := by + funext u + dsimp only + split_ifs with h + · rw [←h,Fin.cons_self_tail] + · have h' : u 0 = false := by cases hh : u 0 <;> simp_all + rw [←h',Fin.cons_self_tail] + right_inv U := by simp only [Fin.cons_zero,Fin.tail_cons,Bool.false_eq_true,↓reduceIte] + +def seedSandwichShuffle {A B C D E : Type*} : + (A × B) × ((C × D) × E) ≃ ((A × C) × (B × D)) × E where + toFun x := (((x.1.1,x.2.1.1),(x.1.2,x.2.1.2)),x.2.2) + invFun x := ((x.1.1.1,x.1.2.1),((x.1.1.2,x.1.2.2),x.2)) + left_inv _ := rfl + right_inv _ := rfl + +abbrev ModifiedCoins (L r : ℕ) := (Card r → Equiv.Perm (Card L)) × BenesCoins (L+r) + +def modifiedStepEquiv (L r : ℕ) : ModifiedCoins L (r+1) ≃ + (ModifiedCoins L r × ModifiedCoins L r) × ((Card (L+r) → Bool) × (Card (L+r) → Bool)) := + (Equiv.prodCongr (seedSplitEquiv r (Equiv.Perm (Card L))) (benesStepEquiv (L+r))).trans + seedSandwichShuffle + +noncomputable def modifiedPerm (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + Equiv.Perm (Card (L+r)) := + butterflyPerm (L+r) (decodeButterfly (L+r) ω.2.1) * + (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1).perm⁻¹ + +noncomputable def modifiedCost (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (ω : ModifiedCoins L r) : ℕ := + InputTree.lowCost (L+r) (L+r) (modifiedInputTree L r E ω.1 ω.2.2 ω.2.1) e ω.2.1 + +lemma modifiedBoundary_cons (L r : ℕ) (E : Finset (Card (r+1))) + (U : Card (r+1) → Equiv.Perm (Card L)) (Y : SwitchIndex (L+r+1) → Bool) (b : Bool) : + (fun u => modifiedBoundary L (r+1) E U Y (Fin.cons b u)) = + modifiedBoundary L r (exceptionChild E b) (fun u => U (Fin.cons b u)) + (if b then (coinStepEquiv (L+r) Y).1.2 else (coinStepEquiv (L+r) Y).1.1) := by + funext u + simp only [modifiedBoundary,mem_exceptionChild,boundaryOutput,Fin.cons_zero,Fin.tail_cons] + +lemma modifiedInputTree_node (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + let z := (modifiedStepEquiv L r).symm (ω,coins) + modifiedInputTree L (r+1) E z.1 z.2.2 z.2.1 = + InputTree.node coins.1 (fun b => + let w := if b then ω.2 else ω.1 + modifiedInputTree L r (exceptionChild E b) w.1 w.2.2 w.2.1) := by + dsimp only + unfold modifiedInputTree + rw [boundaryTree] + change InputTree.node coins.1 (fun b => boundaryTree L r _ _) = _ + congr 1 + funext b + rw [modifiedBoundary_cons] + cases b <;> rfl + +lemma modifiedPerm_step (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) = + pairSwitch coins.2 * childLift (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) * pairSwitch coins.1 := by + rw [modifiedPerm,modifiedInputTree_node,InputTree.perm,mul_inv_rev,pairSwitch_inv,childLift_inv] + change (butterflyPerm (L+r+1) (decodeButterfly (L+r+1) + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)))) * _ = _ + rw [butterflyPerm_step,mul_assoc,←mul_assoc (childLift _),childLift_mul,←mul_assoc] + congr 2 + apply congrArg childLift + funext b + cases b <;> rfl + +lemma modifiedPerm_coordinates (L r : ℕ) (E : Finset (Card (r+1))) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) + (x : Card (L+r+1)) : + headTailEquiv (L+r) (modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) x) = + PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) + (if b then ω.2 else ω.1)) (headTailEquiv (L+r) x) := by + rw [modifiedPerm_step] + simp only [Equiv.Perm.mul_apply,headTail_switch,headTail_child] + rfl + +lemma InputTree.lowCost_node (d : ℕ) (ξ : Card d → Bool) (T : Bool → InputTree d) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (d+1)) (Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (η : Card d → Bool) : + InputTree.lowCost (d+1) (d+1) (.node ξ T) e ((coinStepEquiv d).symm (Y,η)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => if b then butterflyPerm d (decodeButterfly d Y.2) * (T true).perm⁻¹ + else butterflyPerm d (decodeButterfly d Y.1) * (T false).perm⁻¹) + + InputTree.lowCost d d (T false) (PairRouting.childEmbedding x c hc false) Y.1 + + InputTree.lowCost d d (T true) (PairRouting.childEmbedding x c hc true) Y.2 := by + dsimp only + rw [InputTree.lowCost,Finset.sum_range_succ,InputTree.levelCost_node,ite_eq_left rfl] + have he : (∑ i ∈ Finset.range d, + (.node ξ T : InputTree (d+1)).levelCost (i+1) e ((coinStepEquiv d).symm (Y,η))) = + InputTree.lowCost d d (T false) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) false) Y.1 + + InputTree.lowCost d d (T true) + (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) (PairRouting.colors_compatible _ _) true) Y.2 := by + rw [InputTree.lowCost,InputTree.lowCost,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + rw [InputTree.levelCost_node,ite_eq_right (by simp only [Finset.mem_range] at hi; omega : i+1 ≠ d+1)] + rw [he] + omega + +noncomputable def modifiedAssignmentCost (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hc : PairRouting.Compatible x c) (ω : ModifiedCoins L r × ModifiedCoins L r) : ℕ := + PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hc) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + + modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hc false) ω.1 + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hc true) ω.2 + +lemma modifiedCost_step (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r+1)) + (ω : ModifiedCoins L r × ModifiedCoins L r) (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)) = + modifiedAssignmentCost L r E (e.trans (headTailEquiv (L+r)).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv (L+r)).toEmbedding) coins.1) + (PairRouting.colors_compatible _ _) ω := by + rw [modifiedCost,modifiedInputTree_node] + change InputTree.lowCost (L+r+1) (L+r+1) _ e + ((coinStepEquiv (L+r)).symm ((ω.1.2.1,ω.2.2.1),coins.2)) = _ + rw [InputTree.lowCost_node] + unfold modifiedAssignmentCost + dsimp only + simp only [Bool.false_eq_true,↓reduceIte] + rw [PairRouting.switchedEmbedding_eq_colored _ _ (PairRouting.colors_compatible _ _) _ rfl] + congr 2 + + +namespace PairRouting +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] [DecidableEq ι] + +omit [Fintype α] [DecidableEq ι] in +lemma childEmbedding_surjective (x : ι ↪ Bool × α) (hx : Function.Surjective x) + (c : ι → Bool) (hc : Compatible x c) (b : Bool) : + Function.Surjective (childEmbedding x c hc b) := by + intro y + have hs : Function.Surjective (coloredEmbedding x c hc) := + (pairLayer (chosenCoin x c)).surjective.comp hx + obtain ⟨i,hi⟩ := hs (b,y) + rw [coloredEmbedding_apply] at hi + exact ⟨⟨i,congrArg Prod.fst hi⟩,congrArg Prod.snd hi⟩ + +omit [DecidableEq ι] in +lemma uniformPerm_tuple_upper (e f : ι ↪ α) (he : Function.Surjective e) (p : Equiv.Perm α) : + finiteMean (fun u : Equiv.Perm α => if ∀ i, (p*u⁻¹) (e i) = f i then (1:ℝ) else 0) ≤ + 1/(Fintype.card (Equiv.Perm α):ℝ) := by + classical + let M : Equiv.Perm α → Prop := fun u => ∀ i, (p*u⁻¹) (e i) = f i + have huniq (u v : Equiv.Perm α) (hu : M u) (hv : M v) : u = v := by + have hh : p*u⁻¹ = p*v⁻¹ := by + ext x + obtain ⟨i,rfl⟩ := he x + exact (hu i).trans (hv i).symm + exact inv_injective (mul_left_cancel hh) + unfold finiteMean + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + change (∑ u, if M u then (1:ℝ) else 0) ≤ 1 + by_cases h : ∃ u, M u + · obtain ⟨u,hu⟩ := h + rw [Finset.sum_eq_single u] + · simp only [hu,↓reduceIte,le_refl] + · intro v _ hv + exact ite_eq_right (fun hh => hv (huniq v u hh hu)) + · simp + · push Not at h + simp only [h,ite_false,Finset.sum_const_zero,zero_le_one] + +end PairRouting + +noncomputable def centralFactor (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : ℝ := + (Nat.factorial (2^L):ℝ)^(-((2:ℝ)^r-E.card)*a) + +lemma centralFactor_nonneg (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + 0 ≤ centralFactor L r E a := Real.rpow_nonneg (Nat.cast_nonneg _) _ + +lemma centralFactor_step (L r : ℕ) (E : Finset (Card (r+1))) (a : ℝ) : + centralFactor L (r+1) E a = + centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a := by + unfold centralFactor + rw [←Real.rpow_add (Nat.cast_pos.mpr (Nat.factorial_pos _))] + congr 1 + have he : ((exceptionChild E false).card:ℝ)+(exceptionChild E true).card = E.card := by + exact_mod_cast exceptionChild_card_add E + rw [pow_succ,←he] + ring + +lemma modifiedPerm_zero (L : ℕ) (E : Finset (Card 0)) (ω : ModifiedCoins L 0) : + modifiedPerm L 0 E ω = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 + else butterflyPerm L (decodeButterfly L ω.2.1)*(ω.1 (fun j => Fin.elim0 j))⁻¹ := by + unfold modifiedPerm modifiedInputTree boundaryTree InputTree.perm modifiedBoundary boundaryOutput + split_ifs + · exact mul_inv_cancel _ + · rfl + +lemma modifiedCost_zero (L : ℕ) (E : Finset (Card 0)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card L) (ω : ModifiedCoins L 0) : modifiedCost L 0 E e ω = 0 := by + simp only [modifiedCost,modifiedInputTree,boundaryTree,InputTree.lowCost, + InputTree.levelCost,Finset.sum_const_zero] + +lemma centralFactor_zero (L : ℕ) (E : Finset (Card 0)) (a : ℝ) : + centralFactor L 0 E a = + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else (Nat.factorial (2^L):ℝ)^(-a) := by + classical + let z : Card 0 := fun j => Fin.elim0 j + have he : (E.card:ℝ) = if z ∈ E then 1 else 0 := by + by_cases hz : z ∈ E + · have he : E = {z} := by + ext u + rw [Subsingleton.elim u z] + simp only [hz,Finset.mem_singleton] + rw [he,ite_eq_left (by simpa only [he] using hz),Finset.card_singleton,Nat.cast_one] + · have he : E = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun u hu => hz (Subsingleton.elim u z ▸ hu)) + rw [he,Finset.card_empty,Nat.cast_zero,ite_eq_right (by simp)] + unfold centralFactor + rw [pow_zero,he] + split_ifs <;> simp + +lemma modified_probability_zero_le (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) : + PairRouting.tupleProbability (modifiedPerm L 0 E) e f ≤ + if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) := by + classical + rw [PairRouting.tupleProbability,finiteMean_prod,finiteMean_comm] + let B : ℝ := if (fun j => Fin.elim0 j : Card 0) ∈ E then 1 else 1/(Nat.factorial (2^L):ℝ) + change _ ≤ B + calc + _ ≤ finiteMean (fun _ω : BenesCoins L => B) := by + apply finiteMean_mono + intro ω + simp only [modifiedPerm_zero] + by_cases h : (fun j => Fin.elim0 j : Card 0) ∈ E + · simp only [h,↓reduceIte,Equiv.Perm.one_apply,finiteMean_const,B] + split_ifs <;> norm_num + · simp only [h,↓reduceIte,B] + rw [finiteMean_pi_eval (A := fun _ : Card 0 => Equiv.Perm (Card L)) (fun j => Fin.elim0 j) (fun u : Equiv.Perm (Card L) => + if ∀ i, (butterflyPerm L (decodeButterfly L ω.1)*u⁻¹) (e i) = f i then (1:ℝ) else 0)] + convert PairRouting.uniformPerm_tuple_upper e f he (butterflyPerm L (decodeButterfly L ω.1)) using 1 + rw [Fintype.card_perm,card_positions] + _ = _ := finiteMean_const B + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/InsertionPerm.lean b/lean/OAI/Probability/ThorpRouting/Tail/InsertionPerm.lean index b2c8df089170b57838cf6f80ad9f0ccbe9a9ada6..ba165f51950572e1326be362c1415780596feadf 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/InsertionPerm.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/InsertionPerm.lean @@ -1,897 +1,897 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.MainStatement - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.DimensionEstimates -open scoped BigOperators Classical - -section -open Filter - -theorem exists_near_cutoff (C : ℝ) (hC : 0≤C) : - ∃ X : ℝ, 2≤X ∧ ∀ (N j D m : ℕ), 0 f x) hg - rw [he,map_one] - rfl - -omit [FiniteDimensional ℂ V] in -lemma full_tuple_finrank (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - Module.finrank ℂ (fixedSpace tupleAction (Function.Embedding.refl (Card d)) ρ)=Module.finrank ℂ V := by - rw [full_tuple_fixed,finrank_top] - -theorem palindrome_irrep_amplification (d : ℕ) {ι : Type*} [Fintype ι] - (f : ι ↪ Card d) (hk : 0 by simpa only [tupleAction_kernel] using modified_kernel_symmetric L r E e f) - (fun e => by simpa only [tupleAction_kernel] using PairRouting.tupleProbability_row_sum (modifiedPerm L r E) e) - (1/1000) z (Real.exp u) (by norm_num) hz (by positivity) - (fun e => by simpa only [tupleAction_kernel,modifiedRowMoment] using hM e) - (by simpa only [f,full_tuple_finrank] using hm) - simpa only [f,full_tuple_finrank] using h - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -theorem choose_tail_le_of_factorial (μ : YoungDiagram) (D : ℕ) - (hd : μ.card.factorial ≤ D * Fintype.card (rowGroup μ) * Fintype.card (colGroup μ)) : - μ.card.choose (μ.card-μ.rowLen 0) ≤ D * 2^(μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - have htail := card_fiberGroups_mul_le - (fun x : TailCell μ => rowIndex x.1) (fun x : TailCell μ => colIndex x.1) - (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) - rw [tail_card] at htail - have hc := column_group_le_tail μ - have hr := tail_row_group μ - simp only [←Nat.card_eq_fintype_card] at htail hc hr hd - have hh : μ.card.factorial ≤ D * 2^j * - ((μ.rowLen 0).factorial * j.factorial) := by - calc - _ ≤ _ := hd - _ ≤ D * Nat.card (rowGroup μ) * - (2^j * Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc - _ = D * 2^j * (μ.rowLen 0).factorial * - (Nat.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) * - Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := by rw [←hr]; ring - _ ≤ _ := by - calc - _ ≤ D * 2^j * (μ.rowLen 0).factorial * j.factorial := - Nat.mul_le_mul_left _ htail - _ = _ := by ring - have hj : j ≤ μ.card := Nat.sub_le _ _ - have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega - have hf := Nat.choose_mul_factorial_mul_factorial hj - rw [hs] at hf - rw [←hf] at hh - have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) - nlinarith - -lemma card_rowGroup_transpose (μ : YoungDiagram) : - Fintype.card (rowGroup μ.transpose) = Fintype.card (colGroup μ) := by - rw [card_rowGroup,card_colGroup] - apply Fintype.prod_equiv (finCongr (μ.colLen_transpose 0)) - intro i - change (μ.transpose.rowLen i).factorial = (μ.colLen i).factorial - rw [YoungDiagram.rowLen_transpose] - -lemma card_colGroup_transpose (μ : YoungDiagram) : - Fintype.card (colGroup μ.transpose) = Fintype.card (rowGroup μ) := by - rw [card_colGroup,card_rowGroup] - apply Fintype.prod_equiv (finCongr (μ.rowLen_transpose 0)) - intro i - change (μ.transpose.colLen i).factorial = (μ.rowLen i).factorial - rw [YoungDiagram.colLen_transpose] - -lemma card_transpose (μ : YoungDiagram) : μ.transpose.card=μ.card := by - unfold YoungDiagram.card YoungDiagram.transpose - exact Finset.card_map _ - -theorem choose_column_tail_le_dimension (μ : YoungDiagram) : - μ.card.choose (μ.card-μ.colLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.colLen 0) := by - have hd := factorial_le_dimension_row_column μ - have ht := choose_tail_le_of_factorial μ.transpose (Module.finrank ℂ (space μ)) - simp only [card_transpose,card_rowGroup_transpose,card_colGroup_transpose,YoungDiagram.rowLen_transpose] at ht - apply ht - nlinarith - -open DimensionEstimates Filter - -lemma dimension_log_incidence (μ : YoungDiagram) (hμ : 0<μ.card) : - (2*Real.log 2-1)*(μ.card:ℝ)-Real.log 2*((μ.rowLen 0:ℝ)+μ.colLen 0)+1≤ - Real.log (Module.finrank ℂ (space μ)) := by - let : Nonempty (Cell μ) := Fintype.card_pos_iff.mp (by simpa only [card_cell] using hμ) - have hd := factorial_le_dimension_row_column μ - rw [card_rowGroup,card_colGroup] at hd - have hr (i : Fin (μ.colLen 0)) : Nat.card {x : Cell μ // rowIndex x=i}=μ.rowLen i := by - let e : {x : Cell μ // rowIndex x=i} ≃ {x : Cell μ // row x=i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Nat.card_congr e,Nat.card_congr (rowEquiv μ i),Nat.card_fin] - have hc (i : Fin (μ.rowLen 0)) : Nat.card {x : Cell μ // colIndex x=i}=μ.colLen i := by - let e : {x : Cell μ // colIndex x=i} ≃ {x : Cell μ // col x=i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Nat.card_congr e,Nat.card_congr (columnEquiv μ i),Nat.card_fin] - have hcell : Nat.card (Cell μ)=μ.card := by rw [Nat.card_eq_fintype_card,card_cell] - have h := dimension_log_from_incidence (rowIndex (μ := μ)) (colIndex (μ := μ)) - (fun x y h => Subtype.ext (Prod.ext (congrArg (fun z => (z.1:ℕ)) h) - (congrArg (fun z => (z.2:ℕ)) h))) (Module.finrank ℂ (space μ)) - (by simpa only [←Nat.card_eq_fintype_card,hr,hc,hcell] using hd) - simpa only [card_cell,Fintype.card_fin,add_comm (μ.colLen 0:ℝ)] using h - -lemma medium_dimension_raw (μ : YoungDiagram) (hμ : 0<μ.card) (δ : ℝ) (hδ : 0<δ) - (hδ2 : δ≤1/2) (hrow : δ*(μ.card:ℝ)≤μ.card-μ.rowLen 0) - (hcol : (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2) : - min ((3/2:ℝ)*Real.log 2-1) (entropyGap*δ)*(μ.card:ℝ)-2*Real.log μ.card-1≤ - Real.log (Module.finrank ℂ (space μ)) := by - let c := (3/2:ℝ)*Real.log 2-1 - have hN : (0:ℝ)<μ.card := by exact_mod_cast hμ - have hlog : 0≤Real.log μ.card := Real.log_nonneg (by exact_mod_cast hμ) - have hc : 0≤Real.log 2 := Real.log_nonneg (by norm_num) - have hr := rowLen_zero_le_card μ - have hcl : μ.colLen 0≤μ.card := by - simpa only [YoungDiagram.rowLen_transpose,card_transpose] using rowLen_zero_le_card μ.transpose - by_cases hsum : (μ.rowLen 0:ℝ)+μ.colLen 0≤(μ.card:ℝ)/2 - · have hi := dimension_log_incidence μ hμ - have hm := mul_le_mul_of_nonneg_right (min_le_left c (entropyGap*δ)) hN.le - dsimp [c] at hm - nlinarith - · have hbig : (μ.card:ℝ)/4≤μ.rowLen 0 ∨ (μ.card:ℝ)/4≤μ.colLen 0 := by - by_contra h - push Not at h - linarith - rcases hbig with hrb | hcb - · have hj : 0<μ.card-μ.rowLen 0 := by - rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hr] - exact lt_of_lt_of_le (mul_pos hδ hN) hrow - have hjN : μ.card-μ.rowLen 0<μ.card := by - have : 0<μ.rowLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.rowLen 0) - omega - have hi := log_dimension_from_binomial μ.card (μ.card-μ.rowLen 0) - (Module.finrank ℂ (space μ)) hj hjN - (by rw [Nat.cast_sub hr]; linarith) (choose_tail_le_dimension μ) - rw [Nat.cast_sub hr] at hi - have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le - nlinarith [entropyGap_pos] - · have hj : 0<μ.card-μ.colLen 0 := by - rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hcl] - linarith - have hjN : μ.card-μ.colLen 0<μ.card := by - have : 0<μ.colLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.colLen 0) - omega - have hi := log_dimension_from_binomial μ.card (μ.card-μ.colLen 0) - (Module.finrank ℂ (space μ)) hj hjN - (by rw [Nat.cast_sub hcl]; linarith) (choose_column_tail_le_dimension μ) - rw [Nat.cast_sub hcl] at hi - have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le - have ht := mul_le_mul_of_nonneg_left (show δ*(μ.card:ℝ)≤(μ.card:ℝ)-μ.colLen 0 by nlinarith) entropyGap_pos.le - linarith - -end Thorp.Specht - -namespace Thorp.DimensionEstimates - -section -open scoped BigOperators Classical -open Filter - -lemma finset_power_sum {ι : Type*} [Fintype ι] (x : ℝ) : - ∑ E : Finset ι, x^E.card=(1+x)^Fintype.card ι := by - have h := Finset.prod_one_add (f := fun _ : ι => x) Finset.univ - simpa only [Finset.prod_const,Finset.card_univ,Finset.powerset_univ] using h.symm - -lemma small_sets_count {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : - (∑ E : Finset ι, if (E.card:ℝ)<ε*Fintype.card ι then (1:ℝ) else 0) ≤ - Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by - have hpow (E : Finset ι) : (Real.exp (-t))^E.card=Real.exp (-t*(E.card:ℝ)) := by - rw [←Real.exp_nat_mul] - congr 1 - ring - calc - _ ≤ ∑ E : Finset ι, Real.exp (t*ε*Fintype.card ι)*(Real.exp (-t))^E.card := by - apply Finset.sum_le_sum - intro E _ - split_ifs with hE - · rw [hpow,←Real.exp_add,←Real.exp_zero] - apply Real.exp_le_exp.mpr - nlinarith [mul_le_mul_of_nonneg_left hE.le ht] - · positivity - _ = Real.exp (t*ε*Fintype.card ι)*(1+Real.exp (-t))^Fintype.card ι := by - rw [←Finset.mul_sum,finset_power_sum] - _ = _ := by - have he : (1+Real.exp (-t))^Fintype.card ι= - Real.exp (Real.log (1+Real.exp (-t))*(Fintype.card ι:ℝ)) := by - rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)] - rw [he,←Real.exp_add] - congr 1 - ring - -lemma small_sets_ceil_bound {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : - (∑ E : Finset ι, if E.card<⌈ε*Fintype.card ι⌉₊ then (1:ℝ) else 0) ≤ - Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by - have he (E : Finset ι) : E.card<⌈ε*Fintype.card ι⌉₊ ↔ (E.card:ℝ)<ε*Fintype.card ι := Nat.lt_ceil - simp only [he] - exact small_sets_count ε t ht - -lemma exists_small_set_rate (κ ε₀ : ℝ) (hκ : 0<κ) (hε₀ : 0<ε₀) : - ∃ ε : ℝ, 0<ε ∧ ε≤ε₀ ∧ ε<1/2 ∧ ∃ t : ℝ, 0≤t ∧ - t*ε+Real.log (1+Real.exp (-t))≤κ := by - have ht : Tendsto (fun t : ℝ => Real.log (1+Real.exp (-t))) atTop (nhds 0) := by - have he : Tendsto (fun t : ℝ => Real.exp (-t)) atTop (nhds 0) := - Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot - have hl := (tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0) - simpa only [add_zero,Real.log_one] using hl - obtain ⟨t,ht,hlog⟩ := ((eventually_ge_atTop (1:ℝ)).and - (ht.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists - let ε := min ε₀ (min (1/4) (κ/(2*t))) - have htp : 0 α) y a)=Fin.snoc (α := fun _ => α) (Fin.insertNth i b y) a := by - apply Fin.lastCases ?_ (fun j => ?_) |> fun h => funext h - · rw [←show i.castSucc.succAbove (Fin.last d)=Fin.last (d+1) from - Fin.succAbove_castSucc_of_le i (Fin.last d) (Fin.le_last i),Fin.insertNth_apply_succAbove] - simp - · cases j using Fin.succAboveCases i with - | x => simp - | p j => - have he : i.castSucc.succAbove j.castSucc=(i.succAbove j).castSucc := by - simp only [Fin.succAbove,Fin.castSucc_lt_castSucc_iff] - split_ifs <;> rfl - rw [←he,Fin.insertNth_apply_succAbove] - simp - -lemma rotate_cons (d : ℕ) (b : Bool) (y : Card d) : - rotate (d+1) (Fin.cons b y)=Fin.snoc y b := (Fin.snoc_eq_cons_rotate y b).symm - -lemma rotate_insert (d : ℕ) (i : Fin (d+1)) (b : Bool) (y : Card (d+1)) : - rotate (d+2) (Fin.insertNth i.succ b y)=Fin.insertNth i.castSucc b (rotate (d+1) y) := by - rw [←Fin.cons_self_tail y,Fin.insertNth_succ_cons,rotate_cons,rotate_cons,insertNth_castSucc_snoc] - -def insertionPerm (d : ℕ) (i : Fin (d+1)) : Equiv.Perm (Card (d+1)) := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm.trans - (Fin.insertNthEquiv (fun _ : Fin (d+1) => Bool) i) - -lemma insertionPerm_apply (d : ℕ) (i : Fin (d+1)) (x : Card (d+1)) : - insertionPerm d i x=Fin.insertNth i (x 0) (Fin.tail x) := rfl - -lemma insertionPerm_zero (d : ℕ) : insertionPerm d 0=1 := by - ext x j - simp [insertionPerm_apply] - -lemma insertionPerm_last (d : ℕ) : insertionPerm d (Fin.last d)=rotate (d+1) := by - apply Equiv.ext - intro x - rw [insertionPerm_apply,Fin.insertNth_last',←rotate_cons,Fin.cons_self_tail] - -lemma physical_carry_step (d : ℕ) (i : Fin (d+1)) (ξ : Bool → Coins (d+1)) : - step (d+2) (fun y => ξ (y i) (Fin.removeNth i y))*insertionPerm (d+1) i.succ= - insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b)) := by - apply Equiv.ext - intro x - have he : Fin.cons (Bool.xor ((Fin.tail x) 0) (ξ (x 0) (Fin.tail (Fin.tail x)))) - (Fin.insertNth i (x 0) (Fin.tail (Fin.tail x))) = - (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by - simp only [switchFun,Fin.insertNth_succ_cons] - have hs : switchFun (fun y => ξ (y i) (Fin.removeNth i y)) - (Fin.insertNth i.succ (x 0) (Fin.tail x)) = - (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by - conv_lhs => rw [←Fin.cons_self_tail (Fin.tail x),Fin.insertNth_succ_cons] - simp only [switchFun,Fin.cons_zero,Fin.tail_cons,Fin.insertNth_apply_same,Fin.removeNth_insertNth] - exact he - change rotate (d+2) (switchFun (fun y => ξ (y i) (Fin.removeNth i y)) - (Fin.insertNth i.succ (x 0) (Fin.tail x))) = _ - rw [hs,rotate_insert] - rfl - -end Thorp -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω : Type*} [Fintype Ω] - -lemma sampleOperator_mul_const (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : - sampleOperator ρ (fun ω => P ω*g)=sampleOperator ρ P*continuousRepresentation ρ g := by - simp only [sampleOperator,map_mul,Finset.sum_mul,smul_mul_assoc] - -lemma sampleOperator_const_mul (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : - sampleOperator ρ (fun ω => g*P ω)=continuousRepresentation ρ g*sampleOperator ρ P := by - simp only [sampleOperator,map_mul,Finset.mul_sum,mul_smul_comm] - -lemma sampleOperator_run (d t : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - sampleOperator ρ (run d t)=(sampleOperator ρ (step d))^t := by - induction t with - | zero => exact sampleOperator_one ρ - | succ t ih => - let e : Coins d × (Fin t → Coins d) ≃ (Fin (t+1) → Coins d) := - Fin.snocEquiv (fun _ => Coins d) - have he : run d (t+1) ∘ e=fun w => step d w.1*run d t w.2 := by - funext w - simp only [Function.comp_apply,e,Fin.snocEquiv_apply, - run,Fin.snoc_last,Fin.snoc_castSucc] - rw [←sampleOperator_equiv ρ (run d (t+1)) e,he,sampleOperator_prod,ih,pow_succ'] - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite - -def carryCoins (d : ℕ) (i : Fin (d+1)) : (Bool → Coins (d+1)) ≃ Coins (d+2) where - toFun ξ y := ξ (y i) (Fin.removeNth i y) - invFun ξ b y := ξ (Fin.insertNth i b y) - left_inv ξ := by funext b y; simp - right_inv ξ := by funext y; simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma physical_carry_average (d : ℕ) (i : Fin d) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - sampleOperator ρ (step (d+1))*continuousRepresentation ρ (insertionPerm d i.succ)= - continuousRepresentation ρ (insertionPerm d i.castSucc)* - sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) := by - cases d with - | zero => exact Fin.elim0 i - | succ d => - have he : (fun ξ : Bool → Coins (d+1) => - step (d+2) (carryCoins d i ξ)*insertionPerm (d+1) i.succ)= - (fun ξ => insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b))) := by - funext ξ - exact physical_carry_step d i ξ - have h := congrArg (sampleOperator ρ) he - rw [sampleOperator_mul_const,sampleOperator_const_mul] at h - change sampleOperator ρ (step (d+2) ∘ carryCoins d i)*_=_ at h - rw [sampleOperator_equiv] at h - exact h - -theorem physical_sweep_recursion (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - (sampleOperator ρ (step (d+1)))^(d+1)= - (sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))))^d* - sampleOperator ρ (pairSwitch (d := d)) := by - let A := sampleOperator ρ (step (d+1)) - let K := sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) - have h (t : ℕ) (ht : t≤d) : A^t*continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)=K^t := by - induction t with - | zero => - change 1*continuousRepresentation ρ (insertionPerm d 0)=1 - rw [insertionPerm_zero,map_one,one_mul] - | succ t ih => - have hc := physical_carry_average d (⟨t,by omega⟩ : Fin d) ρ - change A*continuousRepresentation ρ (insertionPerm d ⟨t+1,by omega⟩)= - continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)*K at hc - rw [pow_succ,mul_assoc,hc,←mul_assoc,ih (by omega),←pow_succ] - have he : sampleOperator ρ (step (d+1))= - continuousRepresentation ρ (rotate (d+1))*sampleOperator ρ (pairSwitch (d := d)) := - sampleOperator_const_mul ρ (pairSwitch (d := d)) (rotate (d+1)) - calc - _ = A^d*A := pow_succ A d - _ = A^d*(continuousRepresentation ρ (insertionPerm d (Fin.last d))* - sampleOperator ρ (pairSwitch (d := d))) := by rw [insertionPerm_last]; rw [←he] - _ = _ := by - rw [←mul_assoc] - exact congrArg (fun z => z*sampleOperator ρ (pairSwitch (d := d))) (h d le_rfl) - -end Thorp -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite - -lemma childInjection_product (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : - childInjection d false (p false)*childInjection d true (p true)=childLift p := by - change childLift _*childLift _=_ - rw [childLift_mul] - congr 1 - funext b - cases b <;> simp - -lemma childInjection_commute (d : ℕ) (p q : Equiv.Perm (Card d)) : - Commute (childInjection d false p) (childInjection d true q) := by - change childLift _*childLift _=childLift _*childLift _ - rw [childLift_mul,childLift_mul] - congr 1 - funext b - cases b <;> simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω : Type*} [Fintype Ω] - -lemma sampleOperator_child (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) - (P : Ω → Equiv.Perm (Card d)) : - sampleOperator ρ (fun ω : Bool → Ω => childLift (fun b => P (ω b)))= - sampleOperator (ρ.comp (childInjection d false)) P* - sampleOperator (ρ.comp (childInjection d true)) P := by - let e := (Equiv.boolArrowEquivProd Ω).symm - have he : (fun ω : Bool → Ω => childLift (fun b => P (ω b))) ∘ e= - fun w : Ω × Ω => childInjection d false (P w.1)*childInjection d true (P w.2) := by - funext w - change childLift (fun b => P (e w b))=_ - rw [←childInjection_product] - rfl - rw [←sampleOperator_equiv ρ _ e,he] - exact sampleOperator_prod ρ (fun w => childInjection d false (P w)) - (fun w => childInjection d true (P w)) - -lemma sampleOperator_child_commute (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) - (P : Ω → Equiv.Perm (Card d)) : - Commute (sampleOperator (ρ.comp (childInjection d false)) P) - (sampleOperator (ρ.comp (childInjection d true)) P) := by - rw [sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => childInjection_commute d _ _) - -lemma inverse_butterfly_average_step (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : - sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)= - sampleOperator ρ (fun ω : Bool → (SwitchIndex d → Bool) => - childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹))* - sampleOperator ρ (pairSwitch (d := d)) := by - let e := ((Equiv.prodCongr (Equiv.boolArrowEquivProd (SwitchIndex d → Bool)) (Equiv.refl (Card d → Bool))).trans - (coinStepEquiv d).symm) - have he : (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹) ∘ e= - fun w : (Bool → (SwitchIndex d → Bool)) × (Card d → Bool) => - childLift (fun b => (butterflyPerm d (decodeButterfly d (w.1 b)))⁻¹)*pairSwitch w.2 := by - funext w - change (butterflyPerm (d+1) (decodeButterfly (d+1) - ((coinStepEquiv d).symm ((w.1 false,w.1 true),w.2))))⁻¹=_ - rw [butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] - congr 2 - funext b - cases b <;> rfl - rw [←sampleOperator_equiv ρ _ e,he] - exact sampleOperator_prod ρ - (fun ω : Bool → (SwitchIndex d → Bool) => childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹)) - (pairSwitch (d := d)) - -theorem physical_sweep_inverse_butterfly (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : - (sampleOperator ρ (step d))^d= - sampleOperator ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹) := by - induction d with - | zero => - symm - exact sampleOperator_one ρ - | succ d ih => - rw [physical_sweep_recursion,sampleOperator_child, - (sampleOperator_child_commute d ρ (step d)).mul_pow,ih,ih, - inverse_butterfly_average_step] - rw [sampleOperator_child d ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹)] - -lemma physical_sweep_adjoint (d : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card d)) V) (hρ : IsUnitary ρ) : - sampleOperator ρ (run d d)= - (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by - rw [sampleOperator_run,physical_sweep_inverse_butterfly,sampleOperator_inv ρ hρ] - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical -open UnitaryFinite DimensionEstimates Filter - -lemma dimension_pos (μ : YoungDiagram) : 0 < Module.finrank ℂ (space μ) := by - have h := factorial_le_dimension_row_column μ - by_contra hn - have hz : Module.finrank ℂ (space μ)=0 := by omega - rw [hz,zero_mul,zero_mul] at h - exact (Nat.factorial_pos μ.card).not_ge h - -lemma near_numerical_cutoff : - ∃ X : ℝ, 2 ≤ X ∧ ∀ (N j D : ℕ), 0 < j → X ≤ (N:ℝ)/j → N.choose j ≤ D * 2^j → - ∃ k : ℕ, j ≤ k ∧ k ≤ N ∧ ∀ m : ℕ, D * k.choose j ≤ m * N.choose j → - nearFraction * Real.log D ≤ Real.log m ∧ - densityConstant * (k:ℝ) * ((k:ℝ)/N)^(1/512:ℝ) ≤ Real.log m/4000 ∧ - (1/2:ℝ) * Real.log N ≤ Real.log D ∧ (j:ℝ) ≤ Real.log D := by - obtain ⟨X,hX,h⟩ := exists_near_cutoff densityConstant densityConstant_pos.le - refine ⟨X,hX,?_⟩ - intro N j D hj hx hd - have hjN : j ≤ N := by - have hjp : (0:ℝ) < j := by exact_mod_cast hj - have hh : (j:ℝ) ≤ N := by - have := (le_div_iff₀ hjp).mp (hX.trans hx) - linarith - exact_mod_cast hh - have hc : 1 ≤ N.choose j := Nat.choose_pos hjN - have hfoot : D * (chosenTuple N j).choose j ≤ (D * (chosenTuple N j).choose j) * N.choose j := - Nat.le_mul_of_pos_right _ hc - have hh := h N j D _ hj hx hd hfoot - refine ⟨chosenTuple N j,hh.1,hh.2.1,?_⟩ - intro m hm - exact (h N j D m hj hx hd hm).2.2 - -lemma near_row_amplification (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) - {k : ℕ} (f : Fin k ↪ Card d) (hk : 0 rw [←Real.exp_log hθ,←Real.exp_nat_mul] - apply Real.exp_le_exp.mpr - have hg := mul_le_mul_of_nonpos_left (Nat.le_ceil (ε*M)) (Real.log_nonpos hθ.le hθ1.le) - nlinarith - -end Thorp.DimensionEstimates - -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -open DimensionEstimates -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -theorem medium_exception_decay (L r : ℕ) (h ε t : ℝ) (ht : 0≤t) - (hcount : t*ε+Real.log (1+Real.exp (-t))≤h*(2:ℝ)^L/16000) - (ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (hm : 0 - have hc := sum_rowLens μ - rw [he,List.sum_nil] at hc - have hr := rowLen_zero_le_card μ - simp only [List.headD_nil] - omega - | cons a l => - have hh := YoungDiagram.get_rowLens (μ := μ) (i := 0) (h := by simp [he]) - simpa only [he,List.getElem_cons_zero,List.headD_cons] using hh - -lemma rowLens_tail_sum (μ : YoungDiagram) : μ.rowLens.tail.sum=μ.card-μ.rowLen 0 := by - have hh := rowLens_headD μ - have hc := sum_rowLens μ - cases he : μ.rowLens with - | nil => simp only [he,List.headD_nil] at hh; simp only [he,List.sum_nil] at hc; simp [←hc] - | cons a l => - simp only [he,List.headD_cons] at hh - simp only [he,List.sum_cons] at hc - simp only [List.tail_cons] - omega - -lemma positive_list_eq_of_tail_sum {a b : List ℕ} - (ha : ∀ x∈a, 0 - cases b with - | nil => rfl - | cons x l => - simp only [List.tail_nil,List.tail_cons] at ht - subst l - have hx := hb x (by simp) - simp only [List.sum_nil,List.sum_cons,add_zero] at hs - omega - | cons x l => - cases b with - | nil => - simp only [List.tail_nil,List.tail_cons] at ht - subst l - have hx := ha x (by simp) - simp only [List.sum_nil,List.sum_cons,add_zero] at hs - omega - | cons y m => - simp only [List.tail_cons] at ht - subst m - simp only [List.sum_cons] at hs - congr 1 - omega - -end Thorp.Specht - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.MainStatement + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.DimensionEstimates +open scoped BigOperators Classical + +section +open Filter + +theorem exists_near_cutoff (C : ℝ) (hC : 0≤C) : + ∃ X : ℝ, 2≤X ∧ ∀ (N j D m : ℕ), 0 f x) hg + rw [he,map_one] + rfl + +omit [FiniteDimensional ℂ V] in +lemma full_tuple_finrank (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + Module.finrank ℂ (fixedSpace tupleAction (Function.Embedding.refl (Card d)) ρ)=Module.finrank ℂ V := by + rw [full_tuple_fixed,finrank_top] + +theorem palindrome_irrep_amplification (d : ℕ) {ι : Type*} [Fintype ι] + (f : ι ↪ Card d) (hk : 0 by simpa only [tupleAction_kernel] using modified_kernel_symmetric L r E e f) + (fun e => by simpa only [tupleAction_kernel] using PairRouting.tupleProbability_row_sum (modifiedPerm L r E) e) + (1/1000) z (Real.exp u) (by norm_num) hz (by positivity) + (fun e => by simpa only [tupleAction_kernel,modifiedRowMoment] using hM e) + (by simpa only [f,full_tuple_finrank] using hm) + simpa only [f,full_tuple_finrank] using h + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +theorem choose_tail_le_of_factorial (μ : YoungDiagram) (D : ℕ) + (hd : μ.card.factorial ≤ D * Fintype.card (rowGroup μ) * Fintype.card (colGroup μ)) : + μ.card.choose (μ.card-μ.rowLen 0) ≤ D * 2^(μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + have htail := card_fiberGroups_mul_le + (fun x : TailCell μ => rowIndex x.1) (fun x : TailCell μ => colIndex x.1) + (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) + rw [tail_card] at htail + have hc := column_group_le_tail μ + have hr := tail_row_group μ + simp only [←Nat.card_eq_fintype_card] at htail hc hr hd + have hh : μ.card.factorial ≤ D * 2^j * + ((μ.rowLen 0).factorial * j.factorial) := by + calc + _ ≤ _ := hd + _ ≤ D * Nat.card (rowGroup μ) * + (2^j * Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc + _ = D * 2^j * (μ.rowLen 0).factorial * + (Nat.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) * + Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := by rw [←hr]; ring + _ ≤ _ := by + calc + _ ≤ D * 2^j * (μ.rowLen 0).factorial * j.factorial := + Nat.mul_le_mul_left _ htail + _ = _ := by ring + have hj : j ≤ μ.card := Nat.sub_le _ _ + have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega + have hf := Nat.choose_mul_factorial_mul_factorial hj + rw [hs] at hf + rw [←hf] at hh + have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) + nlinarith + +lemma card_rowGroup_transpose (μ : YoungDiagram) : + Fintype.card (rowGroup μ.transpose) = Fintype.card (colGroup μ) := by + rw [card_rowGroup,card_colGroup] + apply Fintype.prod_equiv (finCongr (μ.colLen_transpose 0)) + intro i + change (μ.transpose.rowLen i).factorial = (μ.colLen i).factorial + rw [YoungDiagram.rowLen_transpose] + +lemma card_colGroup_transpose (μ : YoungDiagram) : + Fintype.card (colGroup μ.transpose) = Fintype.card (rowGroup μ) := by + rw [card_colGroup,card_rowGroup] + apply Fintype.prod_equiv (finCongr (μ.rowLen_transpose 0)) + intro i + change (μ.transpose.colLen i).factorial = (μ.rowLen i).factorial + rw [YoungDiagram.colLen_transpose] + +lemma card_transpose (μ : YoungDiagram) : μ.transpose.card=μ.card := by + unfold YoungDiagram.card YoungDiagram.transpose + exact Finset.card_map _ + +theorem choose_column_tail_le_dimension (μ : YoungDiagram) : + μ.card.choose (μ.card-μ.colLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.colLen 0) := by + have hd := factorial_le_dimension_row_column μ + have ht := choose_tail_le_of_factorial μ.transpose (Module.finrank ℂ (space μ)) + simp only [card_transpose,card_rowGroup_transpose,card_colGroup_transpose,YoungDiagram.rowLen_transpose] at ht + apply ht + nlinarith + +open DimensionEstimates Filter + +lemma dimension_log_incidence (μ : YoungDiagram) (hμ : 0<μ.card) : + (2*Real.log 2-1)*(μ.card:ℝ)-Real.log 2*((μ.rowLen 0:ℝ)+μ.colLen 0)+1≤ + Real.log (Module.finrank ℂ (space μ)) := by + let : Nonempty (Cell μ) := Fintype.card_pos_iff.mp (by simpa only [card_cell] using hμ) + have hd := factorial_le_dimension_row_column μ + rw [card_rowGroup,card_colGroup] at hd + have hr (i : Fin (μ.colLen 0)) : Nat.card {x : Cell μ // rowIndex x=i}=μ.rowLen i := by + let e : {x : Cell μ // rowIndex x=i} ≃ {x : Cell μ // row x=i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Nat.card_congr e,Nat.card_congr (rowEquiv μ i),Nat.card_fin] + have hc (i : Fin (μ.rowLen 0)) : Nat.card {x : Cell μ // colIndex x=i}=μ.colLen i := by + let e : {x : Cell μ // colIndex x=i} ≃ {x : Cell μ // col x=i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Nat.card_congr e,Nat.card_congr (columnEquiv μ i),Nat.card_fin] + have hcell : Nat.card (Cell μ)=μ.card := by rw [Nat.card_eq_fintype_card,card_cell] + have h := dimension_log_from_incidence (rowIndex (μ := μ)) (colIndex (μ := μ)) + (fun x y h => Subtype.ext (Prod.ext (congrArg (fun z => (z.1:ℕ)) h) + (congrArg (fun z => (z.2:ℕ)) h))) (Module.finrank ℂ (space μ)) + (by simpa only [←Nat.card_eq_fintype_card,hr,hc,hcell] using hd) + simpa only [card_cell,Fintype.card_fin,add_comm (μ.colLen 0:ℝ)] using h + +lemma medium_dimension_raw (μ : YoungDiagram) (hμ : 0<μ.card) (δ : ℝ) (hδ : 0<δ) + (hδ2 : δ≤1/2) (hrow : δ*(μ.card:ℝ)≤μ.card-μ.rowLen 0) + (hcol : (μ.colLen 0:ℝ)≤(μ.card:ℝ)/2) : + min ((3/2:ℝ)*Real.log 2-1) (entropyGap*δ)*(μ.card:ℝ)-2*Real.log μ.card-1≤ + Real.log (Module.finrank ℂ (space μ)) := by + let c := (3/2:ℝ)*Real.log 2-1 + have hN : (0:ℝ)<μ.card := by exact_mod_cast hμ + have hlog : 0≤Real.log μ.card := Real.log_nonneg (by exact_mod_cast hμ) + have hc : 0≤Real.log 2 := Real.log_nonneg (by norm_num) + have hr := rowLen_zero_le_card μ + have hcl : μ.colLen 0≤μ.card := by + simpa only [YoungDiagram.rowLen_transpose,card_transpose] using rowLen_zero_le_card μ.transpose + by_cases hsum : (μ.rowLen 0:ℝ)+μ.colLen 0≤(μ.card:ℝ)/2 + · have hi := dimension_log_incidence μ hμ + have hm := mul_le_mul_of_nonneg_right (min_le_left c (entropyGap*δ)) hN.le + dsimp [c] at hm + nlinarith + · have hbig : (μ.card:ℝ)/4≤μ.rowLen 0 ∨ (μ.card:ℝ)/4≤μ.colLen 0 := by + by_contra h + push Not at h + linarith + rcases hbig with hrb | hcb + · have hj : 0<μ.card-μ.rowLen 0 := by + rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hr] + exact lt_of_lt_of_le (mul_pos hδ hN) hrow + have hjN : μ.card-μ.rowLen 0<μ.card := by + have : 0<μ.rowLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.rowLen 0) + omega + have hi := log_dimension_from_binomial μ.card (μ.card-μ.rowLen 0) + (Module.finrank ℂ (space μ)) hj hjN + (by rw [Nat.cast_sub hr]; linarith) (choose_tail_le_dimension μ) + rw [Nat.cast_sub hr] at hi + have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le + nlinarith [entropyGap_pos] + · have hj : 0<μ.card-μ.colLen 0 := by + rw [←Nat.cast_pos (α := ℝ),Nat.cast_sub hcl] + linarith + have hjN : μ.card-μ.colLen 0<μ.card := by + have : 0<μ.colLen 0 := by exact_mod_cast (by linarith : (0:ℝ)<μ.colLen 0) + omega + have hi := log_dimension_from_binomial μ.card (μ.card-μ.colLen 0) + (Module.finrank ℂ (space μ)) hj hjN + (by rw [Nat.cast_sub hcl]; linarith) (choose_column_tail_le_dimension μ) + rw [Nat.cast_sub hcl] at hi + have hm := mul_le_mul_of_nonneg_right (min_le_right c (entropyGap*δ)) hN.le + have ht := mul_le_mul_of_nonneg_left (show δ*(μ.card:ℝ)≤(μ.card:ℝ)-μ.colLen 0 by nlinarith) entropyGap_pos.le + linarith + +end Thorp.Specht + +namespace Thorp.DimensionEstimates + +section +open scoped BigOperators Classical +open Filter + +lemma finset_power_sum {ι : Type*} [Fintype ι] (x : ℝ) : + ∑ E : Finset ι, x^E.card=(1+x)^Fintype.card ι := by + have h := Finset.prod_one_add (f := fun _ : ι => x) Finset.univ + simpa only [Finset.prod_const,Finset.card_univ,Finset.powerset_univ] using h.symm + +lemma small_sets_count {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : + (∑ E : Finset ι, if (E.card:ℝ)<ε*Fintype.card ι then (1:ℝ) else 0) ≤ + Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by + have hpow (E : Finset ι) : (Real.exp (-t))^E.card=Real.exp (-t*(E.card:ℝ)) := by + rw [←Real.exp_nat_mul] + congr 1 + ring + calc + _ ≤ ∑ E : Finset ι, Real.exp (t*ε*Fintype.card ι)*(Real.exp (-t))^E.card := by + apply Finset.sum_le_sum + intro E _ + split_ifs with hE + · rw [hpow,←Real.exp_add,←Real.exp_zero] + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hE.le ht] + · positivity + _ = Real.exp (t*ε*Fintype.card ι)*(1+Real.exp (-t))^Fintype.card ι := by + rw [←Finset.mul_sum,finset_power_sum] + _ = _ := by + have he : (1+Real.exp (-t))^Fintype.card ι= + Real.exp (Real.log (1+Real.exp (-t))*(Fintype.card ι:ℝ)) := by + rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)] + rw [he,←Real.exp_add] + congr 1 + ring + +lemma small_sets_ceil_bound {ι : Type*} [Fintype ι] (ε t : ℝ) (ht : 0≤t) : + (∑ E : Finset ι, if E.card<⌈ε*Fintype.card ι⌉₊ then (1:ℝ) else 0) ≤ + Real.exp ((t*ε+Real.log (1+Real.exp (-t)))*Fintype.card ι) := by + have he (E : Finset ι) : E.card<⌈ε*Fintype.card ι⌉₊ ↔ (E.card:ℝ)<ε*Fintype.card ι := Nat.lt_ceil + simp only [he] + exact small_sets_count ε t ht + +lemma exists_small_set_rate (κ ε₀ : ℝ) (hκ : 0<κ) (hε₀ : 0<ε₀) : + ∃ ε : ℝ, 0<ε ∧ ε≤ε₀ ∧ ε<1/2 ∧ ∃ t : ℝ, 0≤t ∧ + t*ε+Real.log (1+Real.exp (-t))≤κ := by + have ht : Tendsto (fun t : ℝ => Real.log (1+Real.exp (-t))) atTop (nhds 0) := by + have he : Tendsto (fun t : ℝ => Real.exp (-t)) atTop (nhds 0) := + Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot + have hl := (tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0) + simpa only [add_zero,Real.log_one] using hl + obtain ⟨t,ht,hlog⟩ := ((eventually_ge_atTop (1:ℝ)).and + (ht.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists + let ε := min ε₀ (min (1/4) (κ/(2*t))) + have htp : 0 α) y a)=Fin.snoc (α := fun _ => α) (Fin.insertNth i b y) a := by + apply Fin.lastCases ?_ (fun j => ?_) |> fun h => funext h + · rw [←show i.castSucc.succAbove (Fin.last d)=Fin.last (d+1) from + Fin.succAbove_castSucc_of_le i (Fin.last d) (Fin.le_last i),Fin.insertNth_apply_succAbove] + simp + · cases j using Fin.succAboveCases i with + | x => simp + | p j => + have he : i.castSucc.succAbove j.castSucc=(i.succAbove j).castSucc := by + simp only [Fin.succAbove,Fin.castSucc_lt_castSucc_iff] + split_ifs <;> rfl + rw [←he,Fin.insertNth_apply_succAbove] + simp + +lemma rotate_cons (d : ℕ) (b : Bool) (y : Card d) : + rotate (d+1) (Fin.cons b y)=Fin.snoc y b := (Fin.snoc_eq_cons_rotate y b).symm + +lemma rotate_insert (d : ℕ) (i : Fin (d+1)) (b : Bool) (y : Card (d+1)) : + rotate (d+2) (Fin.insertNth i.succ b y)=Fin.insertNth i.castSucc b (rotate (d+1) y) := by + rw [←Fin.cons_self_tail y,Fin.insertNth_succ_cons,rotate_cons,rotate_cons,insertNth_castSucc_snoc] + +def insertionPerm (d : ℕ) (i : Fin (d+1)) : Equiv.Perm (Card (d+1)) := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm.trans + (Fin.insertNthEquiv (fun _ : Fin (d+1) => Bool) i) + +lemma insertionPerm_apply (d : ℕ) (i : Fin (d+1)) (x : Card (d+1)) : + insertionPerm d i x=Fin.insertNth i (x 0) (Fin.tail x) := rfl + +lemma insertionPerm_zero (d : ℕ) : insertionPerm d 0=1 := by + ext x j + simp [insertionPerm_apply] + +lemma insertionPerm_last (d : ℕ) : insertionPerm d (Fin.last d)=rotate (d+1) := by + apply Equiv.ext + intro x + rw [insertionPerm_apply,Fin.insertNth_last',←rotate_cons,Fin.cons_self_tail] + +lemma physical_carry_step (d : ℕ) (i : Fin (d+1)) (ξ : Bool → Coins (d+1)) : + step (d+2) (fun y => ξ (y i) (Fin.removeNth i y))*insertionPerm (d+1) i.succ= + insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b)) := by + apply Equiv.ext + intro x + have he : Fin.cons (Bool.xor ((Fin.tail x) 0) (ξ (x 0) (Fin.tail (Fin.tail x)))) + (Fin.insertNth i (x 0) (Fin.tail (Fin.tail x))) = + (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by + simp only [switchFun,Fin.insertNth_succ_cons] + have hs : switchFun (fun y => ξ (y i) (Fin.removeNth i y)) + (Fin.insertNth i.succ (x 0) (Fin.tail x)) = + (Fin.insertNth i.succ (x 0) (switchFun (ξ (x 0)) (Fin.tail x)) : Card (d+2)) := by + conv_lhs => rw [←Fin.cons_self_tail (Fin.tail x),Fin.insertNth_succ_cons] + simp only [switchFun,Fin.cons_zero,Fin.tail_cons,Fin.insertNth_apply_same,Fin.removeNth_insertNth] + exact he + change rotate (d+2) (switchFun (fun y => ξ (y i) (Fin.removeNth i y)) + (Fin.insertNth i.succ (x 0) (Fin.tail x))) = _ + rw [hs,rotate_insert] + rfl + +end Thorp +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω : Type*} [Fintype Ω] + +lemma sampleOperator_mul_const (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : + sampleOperator ρ (fun ω => P ω*g)=sampleOperator ρ P*continuousRepresentation ρ g := by + simp only [sampleOperator,map_mul,Finset.sum_mul,smul_mul_assoc] + +lemma sampleOperator_const_mul (ρ : Representation ℂ G V) (P : Ω → G) (g : G) : + sampleOperator ρ (fun ω => g*P ω)=continuousRepresentation ρ g*sampleOperator ρ P := by + simp only [sampleOperator,map_mul,Finset.mul_sum,mul_smul_comm] + +lemma sampleOperator_run (d t : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + sampleOperator ρ (run d t)=(sampleOperator ρ (step d))^t := by + induction t with + | zero => exact sampleOperator_one ρ + | succ t ih => + let e : Coins d × (Fin t → Coins d) ≃ (Fin (t+1) → Coins d) := + Fin.snocEquiv (fun _ => Coins d) + have he : run d (t+1) ∘ e=fun w => step d w.1*run d t w.2 := by + funext w + simp only [Function.comp_apply,e,Fin.snocEquiv_apply, + run,Fin.snoc_last,Fin.snoc_castSucc] + rw [←sampleOperator_equiv ρ (run d (t+1)) e,he,sampleOperator_prod,ih,pow_succ'] + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite + +def carryCoins (d : ℕ) (i : Fin (d+1)) : (Bool → Coins (d+1)) ≃ Coins (d+2) where + toFun ξ y := ξ (y i) (Fin.removeNth i y) + invFun ξ b y := ξ (Fin.insertNth i b y) + left_inv ξ := by funext b y; simp + right_inv ξ := by funext y; simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma physical_carry_average (d : ℕ) (i : Fin d) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + sampleOperator ρ (step (d+1))*continuousRepresentation ρ (insertionPerm d i.succ)= + continuousRepresentation ρ (insertionPerm d i.castSucc)* + sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) := by + cases d with + | zero => exact Fin.elim0 i + | succ d => + have he : (fun ξ : Bool → Coins (d+1) => + step (d+2) (carryCoins d i ξ)*insertionPerm (d+1) i.succ)= + (fun ξ => insertionPerm (d+1) i.castSucc*childLift (fun b => step (d+1) (ξ b))) := by + funext ξ + exact physical_carry_step d i ξ + have h := congrArg (sampleOperator ρ) he + rw [sampleOperator_mul_const,sampleOperator_const_mul] at h + change sampleOperator ρ (step (d+2) ∘ carryCoins d i)*_=_ at h + rw [sampleOperator_equiv] at h + exact h + +theorem physical_sweep_recursion (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + (sampleOperator ρ (step (d+1)))^(d+1)= + (sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))))^d* + sampleOperator ρ (pairSwitch (d := d)) := by + let A := sampleOperator ρ (step (d+1)) + let K := sampleOperator ρ (fun ξ : Bool → Coins d => childLift (fun b => step d (ξ b))) + have h (t : ℕ) (ht : t≤d) : A^t*continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)=K^t := by + induction t with + | zero => + change 1*continuousRepresentation ρ (insertionPerm d 0)=1 + rw [insertionPerm_zero,map_one,one_mul] + | succ t ih => + have hc := physical_carry_average d (⟨t,by omega⟩ : Fin d) ρ + change A*continuousRepresentation ρ (insertionPerm d ⟨t+1,by omega⟩)= + continuousRepresentation ρ (insertionPerm d ⟨t,by omega⟩)*K at hc + rw [pow_succ,mul_assoc,hc,←mul_assoc,ih (by omega),←pow_succ] + have he : sampleOperator ρ (step (d+1))= + continuousRepresentation ρ (rotate (d+1))*sampleOperator ρ (pairSwitch (d := d)) := + sampleOperator_const_mul ρ (pairSwitch (d := d)) (rotate (d+1)) + calc + _ = A^d*A := pow_succ A d + _ = A^d*(continuousRepresentation ρ (insertionPerm d (Fin.last d))* + sampleOperator ρ (pairSwitch (d := d))) := by rw [insertionPerm_last]; rw [←he] + _ = _ := by + rw [←mul_assoc] + exact congrArg (fun z => z*sampleOperator ρ (pairSwitch (d := d))) (h d le_rfl) + +end Thorp +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite + +lemma childInjection_product (d : ℕ) (p : Bool → Equiv.Perm (Card d)) : + childInjection d false (p false)*childInjection d true (p true)=childLift p := by + change childLift _*childLift _=_ + rw [childLift_mul] + congr 1 + funext b + cases b <;> simp + +lemma childInjection_commute (d : ℕ) (p q : Equiv.Perm (Card d)) : + Commute (childInjection d false p) (childInjection d true q) := by + change childLift _*childLift _=childLift _*childLift _ + rw [childLift_mul,childLift_mul] + congr 1 + funext b + cases b <;> simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω : Type*} [Fintype Ω] + +lemma sampleOperator_child (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) + (P : Ω → Equiv.Perm (Card d)) : + sampleOperator ρ (fun ω : Bool → Ω => childLift (fun b => P (ω b)))= + sampleOperator (ρ.comp (childInjection d false)) P* + sampleOperator (ρ.comp (childInjection d true)) P := by + let e := (Equiv.boolArrowEquivProd Ω).symm + have he : (fun ω : Bool → Ω => childLift (fun b => P (ω b))) ∘ e= + fun w : Ω × Ω => childInjection d false (P w.1)*childInjection d true (P w.2) := by + funext w + change childLift (fun b => P (e w b))=_ + rw [←childInjection_product] + rfl + rw [←sampleOperator_equiv ρ _ e,he] + exact sampleOperator_prod ρ (fun w => childInjection d false (P w)) + (fun w => childInjection d true (P w)) + +lemma sampleOperator_child_commute (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) + (P : Ω → Equiv.Perm (Card d)) : + Commute (sampleOperator (ρ.comp (childInjection d false)) P) + (sampleOperator (ρ.comp (childInjection d true)) P) := by + rw [sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => childInjection_commute d _ _) + +lemma inverse_butterfly_average_step (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card (d+1))) V) : + sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)= + sampleOperator ρ (fun ω : Bool → (SwitchIndex d → Bool) => + childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹))* + sampleOperator ρ (pairSwitch (d := d)) := by + let e := ((Equiv.prodCongr (Equiv.boolArrowEquivProd (SwitchIndex d → Bool)) (Equiv.refl (Card d → Bool))).trans + (coinStepEquiv d).symm) + have he : (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹) ∘ e= + fun w : (Bool → (SwitchIndex d → Bool)) × (Card d → Bool) => + childLift (fun b => (butterflyPerm d (decodeButterfly d (w.1 b)))⁻¹)*pairSwitch w.2 := by + funext w + change (butterflyPerm (d+1) (decodeButterfly (d+1) + ((coinStepEquiv d).symm ((w.1 false,w.1 true),w.2))))⁻¹=_ + rw [butterflyPerm_step,mul_inv_rev,childLift_inv,pairSwitch_inv] + congr 2 + funext b + cases b <;> rfl + rw [←sampleOperator_equiv ρ _ e,he] + exact sampleOperator_prod ρ + (fun ω : Bool → (SwitchIndex d → Bool) => childLift (fun b => (butterflyPerm d (decodeButterfly d (ω b)))⁻¹)) + (pairSwitch (d := d)) + +theorem physical_sweep_inverse_butterfly (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card d)) V) : + (sampleOperator ρ (step d))^d= + sampleOperator ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹) := by + induction d with + | zero => + symm + exact sampleOperator_one ρ + | succ d ih => + rw [physical_sweep_recursion,sampleOperator_child, + (sampleOperator_child_commute d ρ (step d)).mul_pow,ih,ih, + inverse_butterfly_average_step] + rw [sampleOperator_child d ρ (fun ω => (butterflyPerm d (decodeButterfly d ω))⁻¹)] + +lemma physical_sweep_adjoint (d : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card d)) V) (hρ : IsUnitary ρ) : + sampleOperator ρ (run d d)= + (sampleOperator ρ (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint := by + rw [sampleOperator_run,physical_sweep_inverse_butterfly,sampleOperator_inv ρ hρ] + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical +open UnitaryFinite DimensionEstimates Filter + +lemma dimension_pos (μ : YoungDiagram) : 0 < Module.finrank ℂ (space μ) := by + have h := factorial_le_dimension_row_column μ + by_contra hn + have hz : Module.finrank ℂ (space μ)=0 := by omega + rw [hz,zero_mul,zero_mul] at h + exact (Nat.factorial_pos μ.card).not_ge h + +lemma near_numerical_cutoff : + ∃ X : ℝ, 2 ≤ X ∧ ∀ (N j D : ℕ), 0 < j → X ≤ (N:ℝ)/j → N.choose j ≤ D * 2^j → + ∃ k : ℕ, j ≤ k ∧ k ≤ N ∧ ∀ m : ℕ, D * k.choose j ≤ m * N.choose j → + nearFraction * Real.log D ≤ Real.log m ∧ + densityConstant * (k:ℝ) * ((k:ℝ)/N)^(1/512:ℝ) ≤ Real.log m/4000 ∧ + (1/2:ℝ) * Real.log N ≤ Real.log D ∧ (j:ℝ) ≤ Real.log D := by + obtain ⟨X,hX,h⟩ := exists_near_cutoff densityConstant densityConstant_pos.le + refine ⟨X,hX,?_⟩ + intro N j D hj hx hd + have hjN : j ≤ N := by + have hjp : (0:ℝ) < j := by exact_mod_cast hj + have hh : (j:ℝ) ≤ N := by + have := (le_div_iff₀ hjp).mp (hX.trans hx) + linarith + exact_mod_cast hh + have hc : 1 ≤ N.choose j := Nat.choose_pos hjN + have hfoot : D * (chosenTuple N j).choose j ≤ (D * (chosenTuple N j).choose j) * N.choose j := + Nat.le_mul_of_pos_right _ hc + have hh := h N j D _ hj hx hd hfoot + refine ⟨chosenTuple N j,hh.1,hh.2.1,?_⟩ + intro m hm + exact (h N j D m hj hx hd hm).2.2 + +lemma near_row_amplification (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) + {k : ℕ} (f : Fin k ↪ Card d) (hk : 0 rw [←Real.exp_log hθ,←Real.exp_nat_mul] + apply Real.exp_le_exp.mpr + have hg := mul_le_mul_of_nonpos_left (Nat.le_ceil (ε*M)) (Real.log_nonpos hθ.le hθ1.le) + nlinarith + +end Thorp.DimensionEstimates + +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +open DimensionEstimates +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +theorem medium_exception_decay (L r : ℕ) (h ε t : ℝ) (ht : 0≤t) + (hcount : t*ε+Real.log (1+Real.exp (-t))≤h*(2:ℝ)^L/16000) + (ρ : Representation ℂ (Equiv.Perm (Card (L+r))) V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (hm : 0 + have hc := sum_rowLens μ + rw [he,List.sum_nil] at hc + have hr := rowLen_zero_le_card μ + simp only [List.headD_nil] + omega + | cons a l => + have hh := YoungDiagram.get_rowLens (μ := μ) (i := 0) (h := by simp [he]) + simpa only [he,List.getElem_cons_zero,List.headD_cons] using hh + +lemma rowLens_tail_sum (μ : YoungDiagram) : μ.rowLens.tail.sum=μ.card-μ.rowLen 0 := by + have hh := rowLens_headD μ + have hc := sum_rowLens μ + cases he : μ.rowLens with + | nil => simp only [he,List.headD_nil] at hh; simp only [he,List.sum_nil] at hc; simp [←hc] + | cons a l => + simp only [he,List.headD_cons] at hh + simp only [he,List.sum_cons] at hc + simp only [List.tail_cons] + omega + +lemma positive_list_eq_of_tail_sum {a b : List ℕ} + (ha : ∀ x∈a, 0 + cases b with + | nil => rfl + | cons x l => + simp only [List.tail_nil,List.tail_cons] at ht + subst l + have hx := hb x (by simp) + simp only [List.sum_nil,List.sum_cons,add_zero] at hs + omega + | cons x l => + cases b with + | nil => + simp only [List.tail_nil,List.tail_cons] at ht + subst l + have hx := ha x (by simp) + simp only [List.sum_nil,List.sum_cons,add_zero] at hs + omega + | cons y m => + simp only [List.tail_cons] at ht + subst m + simp only [List.sum_cons] at hs + congr 1 + omega + +end Thorp.Specht + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/Main.lean b/lean/OAI/Probability/ThorpRouting/Tail/Main.lean index fed929d1dc2c75860ecf29f5eae2f6f00f7268aa..ee13edc8b1a0ae16e775f9442886af9157bed854 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/Main.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/Main.lean @@ -1,693 +1,693 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.TailShapes - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.StrongTail -open scoped BigOperators Classical -open Specht - -noncomputable def tailCellEquiv (μ : YoungDiagram) : Cell (tailDiagram μ) ≃ TailCell μ where - toFun x := ⟨⟨(x.1.1+1,x.1.2),(mem_tailDiagram μ _ _).mp x.2⟩,by simp [row]⟩ - invFun x := ⟨(row x.1-1,col x.1),(mem_tailDiagram μ _ _).mpr (by - have he : row x.1-1+1 = row x.1 := by have := x.2; omega - change (row x.1-1+1,col x.1) ∈ μ - rw [he] - exact x.1.2)⟩ - left_inv x := by apply Subtype.ext; simp [row,col] - right_inv x := by - apply Subtype.ext; apply Subtype.ext; apply Prod.ext - · change row x.1-1+1 = row x.1 - have := x.2; omega - · rfl - -noncomputable abbrev upCell (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : Cell μ := (tailCellEquiv μ x).1 - -@[simp] lemma upCell_row (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : row (upCell μ x) = row x+1 := rfl -@[simp] lemma upCell_col (μ : YoungDiagram) (x : Cell (tailDiagram μ)) : col (upCell μ x) = col x := rfl - -lemma tail_card_eq (μ : YoungDiagram) : (tailDiagram μ).card = μ.card-μ.rowLen 0 := by - rw [←card_cell, Fintype.card_congr (tailCellEquiv μ), tail_card] - -noncomputable def extendPerm (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - Equiv.Perm (Cell μ) := p.extendDomain (tailCellEquiv μ) - -@[simp] lemma extendPerm_up (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (x : Cell (tailDiagram μ)) : extendPerm μ p (upCell μ x) = upCell μ (p x) := - Equiv.Perm.extendDomain_apply_image p (tailCellEquiv μ) x - -lemma extendPerm_top (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (x : Cell μ) (hx : row x=0) : extendPerm μ p x = x := - Equiv.Perm.extendDomain_apply_not_subtype p (tailCellEquiv μ) (not_not.mpr hx) - -@[simp] lemma extendPerm_inv (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - (extendPerm μ p)⁻¹ = extendPerm μ p⁻¹ := Equiv.Perm.extendDomain_symm _ _ - -@[simp] lemma extendPerm_sign (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) : - permSign (extendPerm μ p) = permSign p := by - simp [extendPerm,permSign,Equiv.Perm.sign_extendDomain] - -noncomputable def liftRows (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) : Fin (μ.colLen 0) := - if hx : row x ≠ 0 then - ⟨(f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).val+1,by - have h := (f.1 ((tailCellEquiv μ).symm ⟨x,hx⟩)).isLt - have hh := tail_height μ - omega⟩ - else rowIndex x - -@[simp] lemma liftRows_up (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) - (x : Cell (tailDiagram μ)) : (liftRows μ f (upCell μ x)).val = (f.1 x).val+1 := by - simp [liftRows,upCell] - -lemma liftRows_top (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) (x : Cell μ) (hx : row x=0) : - liftRows μ f x = rowIndex x := by simp [liftRows,hx] - -lemma liftRows_perm (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) - (p : Equiv.Perm (Cell (tailDiagram μ))) (hf : f.1 = rowIndex ∘ p) : - liftRows μ f = rowIndex ∘ extendPerm μ p := by - funext x - by_cases hx : row x = 0 - · simp [liftRows_top μ f x hx,extendPerm_top μ p x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he] - apply Fin.ext - simp [hf,Function.comp_apply,rowIndex] - -noncomputable def liftTabloid (μ : YoungDiagram) (f : Tabloid (tailDiagram μ)) : Tabloid μ := - ⟨liftRows μ f, by obtain ⟨p,hp⟩ := f.2; exact ⟨extendPerm μ p,liftRows_perm μ f p hp⟩⟩ - -@[simp] lemma liftTabloid_base (μ : YoungDiagram) : - liftTabloid μ (baseTabloid (tailDiagram μ)) = baseTabloid μ := by - apply Subtype.ext - funext x - by_cases hx : row x=0 - · exact liftRows_top μ _ x hx - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he] - apply Fin.ext - exact liftRows_up μ _ y - -lemma liftTabloid_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (f : Tabloid (tailDiagram μ)) : - liftTabloid μ (tabloidAct p f) = tabloidAct (extendPerm μ p) (liftTabloid μ f) := by - apply Subtype.ext - funext x - change liftRows μ (tabloidAct p f) x = liftRows μ f ((extendPerm μ p)⁻¹ x) - rw [extendPerm_inv] - by_cases hx : row x=0 - · rw [extendPerm_top μ p⁻¹ x hx,liftRows_top μ _ x hx,liftRows_top μ _ x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he,extendPerm_up] - apply Fin.ext - simp only [liftRows_up,tabloidAct_apply] - -noncomputable def restrictTabloids (μ : YoungDiagram) : - (Tabloid μ → ℂ) →ₗ[ℂ] (Tabloid (tailDiagram μ) → ℂ) where - toFun v := fun f => v (liftTabloid μ f) - map_add' := by intros; rfl - map_smul' := by intros; rfl - -lemma restrict_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) - (v : Tabloid μ → ℂ) : - restrictTabloids μ (tabloidRep μ (extendPerm μ p) v) = - tabloidRep (tailDiagram μ) p (restrictTabloids μ v) := by - ext f - change v (tabloidAct (extendPerm μ p)⁻¹ (liftTabloid μ f)) = v (liftTabloid μ (tabloidAct p⁻¹ f)) - rw [extendPerm_inv,liftTabloid_action] - -lemma extend_colGroup (μ : YoungDiagram) (c : colGroup (tailDiagram μ)) : - extendPerm μ c ∈ colGroup μ := by - intro x - by_cases hx : row x=0 - · rw [extendPerm_top μ c x hx] - · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ - have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) - rw [←he,extendPerm_up,upCell_col,upCell_col] - exact c.2 y - -lemma restrict_polytabloid (μ : YoungDiagram) : - restrictTabloids μ (polytabloid μ) = polytabloid (tailDiagram μ) := by - let v := restrictTabloids μ (polytabloid μ) - have hv (c : colGroup (tailDiagram μ)) : - tabloidRep (tailDiagram μ) c v = permSign (c:Equiv.Perm (Cell (tailDiagram μ))) • v := by - rw [←restrict_action] - rw [polytabloid_col_action μ ⟨extendPerm μ c,extend_colGroup μ c⟩] - simp only [map_smul,extendPerm_sign] - rfl - have ha : alternator (colGroup (tailDiagram μ)) (tabloidRep (tailDiagram μ)) v = - (Fintype.card (colGroup (tailDiagram μ)):ℂ) • v := by - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,hv,smul_smul,permSign_sq,one_smul] - ext f - simp - have hb : v (baseTabloid (tailDiagram μ)) = 1 := by - change polytabloid μ (liftTabloid μ (baseTabloid (tailDiagram μ))) = 1 - rw [liftTabloid_base, polytabloid_base] - have he := alternator_rank_one_exact (tailDiagram μ) v - rw [ha] at he - simp only [Pi.smul_apply,hb,smul_eq_mul,mul_one] at he - have hc : (Fintype.card (colGroup (tailDiagram μ)):ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - exact (smul_right_injective _ hc) he - -lemma tail_space_le_image (μ : YoungDiagram) : - space (tailDiagram μ) ≤ (space μ).map (restrictTabloids μ) := by - apply Submodule.span_le.mpr - rintro _ ⟨p,rfl⟩ - refine ⟨tabloidRep μ (extendPerm μ p) (polytabloid μ), orbit_mem_space μ _, ?_⟩ - rw [restrict_action,restrict_polytabloid] - -theorem tail_dimension_le (μ : YoungDiagram) : - Module.finrank ℂ (space (tailDiagram μ)) ≤ Module.finrank ℂ (space μ) := - (Submodule.finrank_mono (tail_space_le_image μ)).trans (Submodule.finrank_map_le _ _) - -end Thorp.StrongTail - -namespace Thorp.ButterflyReverse -open scoped BigOperators - -abbrev Site (d : ℕ) := {t : Fin d × Card d // t.2 t.1 = false} - -def site : (d : ℕ) → SwitchIndex d → Site d - | 0, t => nomatch t - | _+1, Sum.inl y => ⟨(0, Fin.cons false y), rfl⟩ - | d+1, Sum.inr (b,t) => - ⟨((site d t).1.1.succ, Fin.cons b (site d t).1.2), (site d t).2⟩ - -lemma site_injective (d : ℕ) : Function.Injective (site d) := by - induction d with - | zero => intro t; exact Empty.elim t - | succ d ih => - intro s t h - cases s with - | inl y => - cases t with - | inl z => - have he := congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h - exact congrArg Sum.inl he - | inr t => - have he := congrArg (fun a : Site (d+1) => a.1.1.val) h - simp [site] at he - | inr s => - cases t with - | inl y => - have he := congrArg (fun a : Site (d+1) => a.1.1.val) h - simp [site] at he - | inr t => - obtain ⟨b,s⟩ := s - obtain ⟨c,t⟩ := t - have hbc := congrArg (fun a : Site (d+1) => a.1.2 0) h - simp only [site, Fin.cons_zero] at hbc - have hst : site d s = site d t := by - apply Subtype.ext - apply Prod.ext - · exact Fin.succ_inj.mp (congrArg (fun a : Site (d+1) => a.1.1) h) - · exact congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h - cases hbc - cases ih hst - rfl - -lemma site_surjective (d : ℕ) : Function.Surjective (site d) := by - induction d with - | zero => intro t; exact Fin.elim0 t.1.1 - | succ d ih => - rintro ⟨⟨i,x⟩,hx⟩ - refine Fin.cases ?_ (fun j => ?_) i hx - · intro hx0 - refine ⟨Sum.inl (Fin.tail x), ?_⟩ - apply Subtype.ext - simp only [site, Prod.mk.injEq, true_and] - rw [←hx0,Fin.cons_self_tail] - · intro hxj - obtain ⟨t,ht⟩ := ih ⟨(j,Fin.tail x),hxj⟩ - refine ⟨Sum.inr (x 0,t), ?_⟩ - apply Subtype.ext - simp only [site,ht,Fin.cons_self_tail] - -noncomputable def siteEquiv (d : ℕ) : SwitchIndex d ≃ Site d := - Equiv.ofBijective (site d) ⟨site_injective d,site_surjective d⟩ - -def reverseCard (d : ℕ) : Equiv.Perm (Card d) where - toFun x := fun i => x i.rev - invFun x := fun i => x i.rev - left_inv x := by funext i; simp - right_inv x := by funext i; simp - -@[simp] lemma reverseCard_apply (d : ℕ) (x : Card d) (i : Fin d) : - reverseCard d x i = x i.rev := rfl - -@[simp] lemma reverseCard_involutive (d : ℕ) (x : Card d) : - reverseCard d (reverseCard d x) = x := by funext i; simp - -def mirrorSite (d : ℕ) : Equiv.Perm (Site d) where - toFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ - invFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ - left_inv s := by apply Subtype.ext; simp - right_inv s := by apply Subtype.ext; simp - -noncomputable def mirrorSwitch (d : ℕ) : Equiv.Perm (SwitchIndex d) := - (siteEquiv d).trans ((mirrorSite d).trans (siteEquiv d).symm) - -lemma site_mirrorSwitch (d : ℕ) (t : SwitchIndex d) : - site d (mirrorSwitch d t) = mirrorSite d (site d t) := by - exact (siteEquiv d).apply_symm_apply _ - -lemma routeDomain_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - t ∈ routeDomain d x y ↔ - ∀ j : Fin d, j ≠ (site d t).1.1 → - (site d t).1.2 j = if j < (site d t).1.1 then x j else y j := by - classical - induction d with - | zero => exact Empty.elim t - | succ d ih => - cases t with - | inl z => - change Sum.inl z ∈ (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ - simp only [Finset.mem_insert, Sum.inl.injEq,Finset.mem_image, - reduceCtorEq,and_false,exists_false,or_false] - constructor - · intro hz j hj - subst z - have hj0 : j ≠ 0 := hj - obtain ⟨i,rfl⟩ := Fin.eq_succ_of_ne_zero hj0 - simp [site,Fin.tail] - · intro h - funext j - have he := h j.succ (by simp [site]) - simpa [site,Fin.tail] using he - | inr z => - obtain ⟨b,t⟩ := z - change Sum.inr (b,t) ∈ (insert (Sum.inl (Fin.tail y)) - ((routeDomain d (Fin.tail x) (Fin.tail y)).image - (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : - Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ - simp only [Finset.mem_insert,reduceCtorEq,false_or,Finset.mem_image,Sum.inr.injEq,Prod.mk.injEq] - constructor - · rintro ⟨s,hs,hb,ht⟩ - subst s - have hst := (ih (Fin.tail x) (Fin.tail y) t).mp hs - intro j hj - refine Fin.cases ?_ (fun i => ?_) j hj - · intro _ - simp [site,hb] - · intro hi - have hi' : i ≠ (site d t).1.1 := by simpa [site] using hi - simpa [site,Fin.tail] using hst i hi' - · intro h - have hb := h 0 (by simpa only [site] using (Fin.succ_ne_zero (site d t).1.1).symm) - have hb' : x 0 = b := by simpa [site] using hb.symm - refine ⟨t,?_,hb',rfl⟩ - apply (ih (Fin.tail x) (Fin.tail y) t).mpr - intro j hj - have he := h j.succ (by simpa [site] using hj) - simpa [site,Fin.tail] using he - -lemma routeValue_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - routeValue d x y t = Bool.xor (x (site d t).1.1) (y (site d t).1.1) := by - induction d with - | zero => exact Empty.elim t - | succ d ih => - cases t with - | inl z => rfl - | inr z => exact ih (Fin.tail x) (Fin.tail y) z.2 - -lemma mirrorSwitch_involutive (d : ℕ) (t : SwitchIndex d) : - mirrorSwitch d (mirrorSwitch d t) = t := by - apply site_injective d - rw [site_mirrorSwitch,site_mirrorSwitch] - apply Subtype.ext - simp [mirrorSite] - -lemma mirror_routeDomain (d : ℕ) (x y : Card d) (t : SwitchIndex d) - (ht : t ∈ routeDomain d x y) : - mirrorSwitch d t ∈ routeDomain d (reverseCard d y) (reverseCard d x) := by - rw [routeDomain_site,site_mirrorSwitch] - intro j hj - have hj' : j.rev ≠ (site d t).1.1 := by - intro h - apply hj - change j = (site d t).1.1.rev - rw [←h,Fin.rev_rev] - have he := (routeDomain_site d x y t).mp ht j.rev hj' - change (site d t).1.2 j.rev = - if j < (site d t).1.1.rev then y j.rev else x j.rev - rw [he] - have hord : j < (site d t).1.1.rev ↔ ¬j.rev < (site d t).1.1 := by - rw [Fin.lt_rev_iff] - constructor - · intro h - exact not_lt_of_ge h.le - · intro h - exact lt_of_le_of_ne (le_of_not_gt h) (Ne.symm hj') - by_cases h : j.rev < (site d t).1.1 <;> simp [h,hord] - -lemma mirror_routeValue (d : ℕ) (x y : Card d) (t : SwitchIndex d) : - routeValue d (reverseCard d y) (reverseCard d x) (mirrorSwitch d t) = - routeValue d x y t := by - rw [routeValue_site,routeValue_site,site_mirrorSwitch] - simp only [mirrorSite,Equiv.coe_fn_mk,reverseCard_apply,Fin.rev_rev] - exact Bool.xor_comm _ _ - -noncomputable def mirrorCoins (d : ℕ) : Equiv.Perm (SwitchIndex d → Bool) where - toFun ω := fun t => ω (mirrorSwitch d t) - invFun ω := fun t => ω (mirrorSwitch d t) - left_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] - right_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] - -lemma mirror_endpoint (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) - (hxy : butterflyPerm d (decodeButterfly d ω) x = y) : - butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) (reverseCard d y) = - reverseCard d x := by - apply (butterfly_endpoint_iff d _ _ _).mpr - intro t ht - have ht' := mirror_routeDomain d (reverseCard d y) (reverseCard d x) t ht - simp only [reverseCard_involutive] at ht' - have he := (butterfly_endpoint_iff d ω x y).mp hxy (mirrorSwitch d t) ht' - change ω (mirrorSwitch d t) = _ - rw [he] - have hv := mirror_routeValue d x y (mirrorSwitch d t) - rw [mirrorSwitch_involutive] at hv - exact hv.symm - -lemma butterfly_mirror (d : ℕ) (ω : SwitchIndex d → Bool) : - butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) = - reverseCard d * (butterflyPerm d (decodeButterfly d ω))⁻¹ * reverseCard d := by - apply Equiv.ext - intro x - have he := mirror_endpoint d ω - ((butterflyPerm d (decodeButterfly d ω))⁻¹ (reverseCard d x)) (reverseCard d x) - (Equiv.apply_symm_apply _ _) - simpa only [reverseCard_involutive,Equiv.Perm.mul_apply] using he - -def reverseOrder (d : ℕ) : Equiv.Perm (Fin d) where - toFun := Fin.rev - invFun := Fin.rev - left_inv := Fin.rev_rev - right_inv := Fin.rev_rev - -lemma relabel_mul (d : ℕ) (a b : Equiv.Perm (Fin d)) : - StrongSmoothing.coordinateRelabel d (a*b) = - StrongSmoothing.coordinateRelabel d a * StrongSmoothing.coordinateRelabel d b := rfl - -lemma relabel_reverse (d : ℕ) : - StrongSmoothing.coordinateRelabel d (reverseOrder d) = reverseCard d := rfl - -lemma reverseCard_sq (d : ℕ) : reverseCard d * reverseCard d = 1 := by - ext x i - simp - -lemma sweep_mirror (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : - StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω) = - (StrongSmoothing.sweep d order ω)⁻¹ := by - simp only [StrongSmoothing.sweep,relabel_mul,relabel_reverse,butterfly_mirror,mul_inv_rev] - have hR : (reverseCard d)⁻¹ = reverseCard d := by - exact inv_eq_of_mul_eq_one_right (reverseCard_sq d) - rw [hR] - calc - _ = StrongSmoothing.coordinateRelabel d order * - (reverseCard d*reverseCard d) * - (butterflyPerm d (decodeButterfly d ω))⁻¹ * - (reverseCard d*reverseCard d) * (StrongSmoothing.coordinateRelabel d order)⁻¹ := by group - _ = _ := by rw [reverseCard_sq]; group - -lemma sweepKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : - StrongSmoothing.sweepKernel d l (order*reverseOrder d) = - (StrongSmoothing.sweepKernel d l order).transpose := by - classical - rw [StrongSmoothing.sweepKernel_law,StrongSmoothing.sweepKernel_law, - ←StrongSmoothing.PermLaw.inverse] - ext x y - unfold StrongSmoothing.PermLaw.kernel - rw [finiteMean_equiv (mirrorCoins d)] - apply finiteMean_congr - intro ω - change (if StrongSmoothing.tuplePerm - (StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω)) x = y then (1:ℝ) else 0) = _ - rw [sweep_mirror,StrongSmoothing.tuplePerm_inverse] - -lemma reflectedKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : - StrongSmoothing.reflectedKernel d l order true = - StrongSmoothing.reflectedKernel d l (order*reverseOrder d) false := by - simp only [StrongSmoothing.reflectedKernel,Bool.false_eq_true, - ↓reduceIte,sweepKernel_reverse,Matrix.transpose_transpose] - -end Thorp.ButterflyReverse - -namespace Thorp.StrongTail -open scoped BigOperators Classical - -section -open StrongSmoothing - -lemma reflected_nonneg_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x y : Tuples d l) : 0 ≤ reflectedKernel d l order rev x y := by - cases rev - · exact reflected_nonneg _ _ _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_nonneg _ _ _ _ _ - -lemma reflected_symm_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) : - (reflectedKernel d l order rev).IsSymm := by - cases rev - · exact reflected_symmetric _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_symmetric _ _ _ - -lemma reflected_moment_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : Tuples d l) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^(1+(1/1000:ℝ))) ≤ - Real.exp (l*(1+heightDecay 1)) := by - cases rev - · exact reflected_moment _ _ _ _ - · rw [ButterflyReverse.reflectedKernel_reverse] - exact reflected_moment _ _ _ _ - -lemma reflected_moment_small (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : Tuples d l) {p : ℝ} (hp : 0 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) ≤ - Real.exp (l*(1+heightDecay 1)) := by - let : Nonempty (Tuples d l) := ⟨x⟩ - let q : ℝ := 1+1/1000 - let f := fun y : Tuples d l => (Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y - have hf : ∀ y, 0 ≤ f y := fun y => mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both _ _ _ _ _ _) - have hq : 0 < q := by norm_num [q] - have hr : 0 ≤ p/q := (div_pos hp hq).le - have hr1 : p/q ≤ 1 := (div_le_one hq).mpr hpq - have he (y) : (f y)^p = ((f y)^q)^(p/q) := by - rw [←Real.rpow_mul (hf y)] - congr 1 - field_simp - simp_rw [show (fun y : Tuples d l => ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) - = fun y => ((f y)^q)^(p/q) from funext he] - apply (mean_rpow_concave _ (fun y => Real.rpow_nonneg (hf y) _) hr hr1).trans - apply (Real.rpow_le_rpow (finiteMean_nonneg (fun y => Real.rpow_nonneg (hf y) _)) - (reflected_moment_both d l order rev x) hr).trans - rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hA : 0 ≤ (l:ℝ)*(1+heightDecay 1) := by - have hh := heightDecay_nonneg 1 - positivity - nlinarith - -lemma log_factorial_le_power (n N : ℕ) (hn : n ≤ N) (_hN : 0 < N) : - Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log N := by - have hb : (n.factorial:ℝ) ≤ (N:ℝ)^n := by - exact_mod_cast (Nat.factorial_le_pow n).trans (Nat.pow_le_pow_left hn n) - simpa only [Real.log_pow] using Real.log_le_log (by positivity : (0:ℝ) ((Fintype.card X:ℝ)*f x)^p) := by - let M : ℝ := Fintype.card X - have hM : 0 < M := Nat.cast_pos.mpr Fintype.card_pos - have he (x) : (N*f x)^p = (N/M)^p*(M*f x)^p := by - rw [←Real.mul_rpow (div_nonneg hN.le hM.le) (mul_nonneg hM.le (hf x))] - congr 1 - field_simp - simp_rw [he] - rw [←Finset.mul_sum,Real.rpow_sub (div_pos hN hM),Real.rpow_one] - unfold finiteMean - dsimp [M] at hM ⊢ - field_simp - -lemma density_at_small_exponent {p : ℝ} (hp : 1 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : - DensityAt p (3+heightDecay 1) := by - intro d l hl order rev x - dsimp only - let : Nonempty (Tuples d l) := ⟨x⟩ - let H := reflectedKernel d l order rev - have hm := reflected_moment_small d l order rev x (by linarith : 0 H x y) (reflected_nonneg_both d l order rev x) - (by positivity) p] - have hrat : ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) ≤ Real.exp (2*l) := by - apply (Real.log_le_iff_le_exp (by positivity)).mp - rw [tuples_card] - exact_mod_cast log_normalization_le (2^d) l (by positivity) hl - have hr : 0 ≤ ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) := by positivity - have hrp : (((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ))^(p-1) ≤ Real.exp (2*l) := by - apply (Real.rpow_le_rpow hr hrat (by linarith)).trans - rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hpl : p-1 ≤ 1 := by linarith - nlinarith [(show (0:ℝ) ≤ l by positivity)] - apply (mul_le_mul hrp hm (finiteMean_nonneg (fun y => Real.rpow_nonneg - (mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both d l order rev x y)) _)) (Real.exp_pos _).le).trans - rw [←Real.exp_add] - apply Real.exp_le_exp.mpr - ring_nf - rfl - dsimp [H] at hpow - refine ⟨hm.trans hb,?_,hpow,?_⟩ - · simpa only [hs] using hm.trans hb - · simpa only [hs] using hpow - -end -open Specht UnitaryFinite - -lemma dimension_le_factorial (μ : YoungDiagram) : - Module.finrank ℂ (space μ) ≤ μ.card.factorial := by - have hdim : Module.finrank ℂ (space μ) ≤ Fintype.card (Tabloid μ) := by - simpa using Submodule.finrank_le (space μ) - have hrow : 1 ≤ Fintype.card (rowGroup μ) := Fintype.card_pos - have hc := card_tabloid_mul_row μ - nlinarith - -lemma tail_card_exact (μ : YoungDiagram) : - (tailDiagram μ).card = μ.card - μ.rowLen 0 := by - rw [←card_cell,Fintype.card_congr (tailCellEquiv μ),tail_card] - -lemma tail_dimension_le_factorial (μ : YoungDiagram) : - Module.finrank ℂ (space (tailDiagram μ)) ≤ (μ.card - μ.rowLen 0).factorial := by - simpa only [tail_card_exact] using dimension_le_factorial (tailDiagram μ) - -lemma sweep_sq_palindrome (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : - ‖SparseContact.sweepOperator d μ e rev‖^2 = - ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ := by - rw [SparseContact.sweep_forward_norm, sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e)] - change ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))‖^2 = _ - rw [show (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint = - star (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) - (fun ω => butterflyPerm d (decodeButterfly d ω))) from rfl] - simpa only [pow_two] using (CStarRing.norm_self_mul_star (x := sampleOperator (V := hilbertSpace μ) - (relabelledUnitary μ e) (fun ω => butterflyPerm d (decodeButterfly d ω)))).symm - -lemma sweep_sq_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : - ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ 1 := by - have h := SparseContact.sweep_norm_le_one d μ e rev - nlinarith [norm_nonneg (SparseContact.sweepOperator d μ e rev)] - -theorem strong_tail : MainStatement := by - obtain ⟨a,h,ha,hh,dE⟩ := Specht.spectral_regimes - obtain ⟨D0,hD0⟩ := Filter.eventually_atTop.mp dE - let d0 := max D0 1 - let t : ℝ := min a (1/1000) - have ht : 0 < t := lt_min ha (by norm_num) - have hta : t ≤ a := min_le_left _ _ - have htq : t ≤ 1/1000 := min_le_right _ _ - let b := t/(1+t) - have hden : 0 < 1+t := by linarith - have hb : 0 < b := div_pos ht hden - have hbt : b ≤ t := (div_le_iff₀ hden).mpr (by nlinarith [sq_nonneg t]) - have hba : b ≤ a := hbt.trans hta - have hb1 : b ≤ 1 := (div_le_one hden).mpr (by linarith) - let C := Real.log (((2^d0).factorial:ℕ):ℝ) - have hC : 0 ≤ C := Real.log_nonneg (by exact_mod_cast Nat.factorial_pos (2^d0)) - refine ⟨1+t,3+heightDecay 1,C,by linarith,by linarith, - density_at_small_exponent (by linarith) (by linarith),?_⟩ - intro d μ e rev - let k := μ.card - μ.rowLen 0 - let D : ℝ := Module.finrank ℂ (space (tailDiagram μ)) - have hD : 1 ≤ D := by dsimp [D]; exact_mod_cast dimension_pos (tailDiagram μ) - have hDp : 0 < D := by linarith - have hlog : 0 ≤ Real.log D := Real.log_nonneg hD - have hμ : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions] - have hform : -(((1+t)-1)/(1+t)) = -b := by dsimp [b]; congr 1; ring - rw [hform] - change ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ Real.exp (C*k)*D^(-b) - rw [Real.rpow_def_of_pos hDp,←Real.exp_add] - by_cases hk : k=0 - · have hDone : D=1 := by - have hn := tail_dimension_le_factorial μ - change Module.finrank ℂ (space (tailDiagram μ)) ≤ k.factorial at hn - rw [hk,Nat.factorial_zero] at hn - have hu : D ≤ 1 := by dsimp [D]; exact_mod_cast hn - linarith - rw [hk,Nat.cast_zero,mul_zero,hDone,Real.log_one,zero_mul,add_zero,Real.exp_zero] - exact sweep_sq_le_one d μ e rev - · have hkpos : 0 v (liftTabloid μ f) + map_add' := by intros; rfl + map_smul' := by intros; rfl + +lemma restrict_action (μ : YoungDiagram) (p : Equiv.Perm (Cell (tailDiagram μ))) + (v : Tabloid μ → ℂ) : + restrictTabloids μ (tabloidRep μ (extendPerm μ p) v) = + tabloidRep (tailDiagram μ) p (restrictTabloids μ v) := by + ext f + change v (tabloidAct (extendPerm μ p)⁻¹ (liftTabloid μ f)) = v (liftTabloid μ (tabloidAct p⁻¹ f)) + rw [extendPerm_inv,liftTabloid_action] + +lemma extend_colGroup (μ : YoungDiagram) (c : colGroup (tailDiagram μ)) : + extendPerm μ c ∈ colGroup μ := by + intro x + by_cases hx : row x=0 + · rw [extendPerm_top μ c x hx] + · let y := (tailCellEquiv μ).symm ⟨x,hx⟩ + have he : upCell μ y = x := congrArg Subtype.val ((tailCellEquiv μ).apply_symm_apply ⟨x,hx⟩) + rw [←he,extendPerm_up,upCell_col,upCell_col] + exact c.2 y + +lemma restrict_polytabloid (μ : YoungDiagram) : + restrictTabloids μ (polytabloid μ) = polytabloid (tailDiagram μ) := by + let v := restrictTabloids μ (polytabloid μ) + have hv (c : colGroup (tailDiagram μ)) : + tabloidRep (tailDiagram μ) c v = permSign (c:Equiv.Perm (Cell (tailDiagram μ))) • v := by + rw [←restrict_action] + rw [polytabloid_col_action μ ⟨extendPerm μ c,extend_colGroup μ c⟩] + simp only [map_smul,extendPerm_sign] + rfl + have ha : alternator (colGroup (tailDiagram μ)) (tabloidRep (tailDiagram μ)) v = + (Fintype.card (colGroup (tailDiagram μ)):ℂ) • v := by + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,hv,smul_smul,permSign_sq,one_smul] + ext f + simp + have hb : v (baseTabloid (tailDiagram μ)) = 1 := by + change polytabloid μ (liftTabloid μ (baseTabloid (tailDiagram μ))) = 1 + rw [liftTabloid_base, polytabloid_base] + have he := alternator_rank_one_exact (tailDiagram μ) v + rw [ha] at he + simp only [Pi.smul_apply,hb,smul_eq_mul,mul_one] at he + have hc : (Fintype.card (colGroup (tailDiagram μ)):ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + exact (smul_right_injective _ hc) he + +lemma tail_space_le_image (μ : YoungDiagram) : + space (tailDiagram μ) ≤ (space μ).map (restrictTabloids μ) := by + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + refine ⟨tabloidRep μ (extendPerm μ p) (polytabloid μ), orbit_mem_space μ _, ?_⟩ + rw [restrict_action,restrict_polytabloid] + +theorem tail_dimension_le (μ : YoungDiagram) : + Module.finrank ℂ (space (tailDiagram μ)) ≤ Module.finrank ℂ (space μ) := + (Submodule.finrank_mono (tail_space_le_image μ)).trans (Submodule.finrank_map_le _ _) + +end Thorp.StrongTail + +namespace Thorp.ButterflyReverse +open scoped BigOperators + +abbrev Site (d : ℕ) := {t : Fin d × Card d // t.2 t.1 = false} + +def site : (d : ℕ) → SwitchIndex d → Site d + | 0, t => nomatch t + | _+1, Sum.inl y => ⟨(0, Fin.cons false y), rfl⟩ + | d+1, Sum.inr (b,t) => + ⟨((site d t).1.1.succ, Fin.cons b (site d t).1.2), (site d t).2⟩ + +lemma site_injective (d : ℕ) : Function.Injective (site d) := by + induction d with + | zero => intro t; exact Empty.elim t + | succ d ih => + intro s t h + cases s with + | inl y => + cases t with + | inl z => + have he := congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h + exact congrArg Sum.inl he + | inr t => + have he := congrArg (fun a : Site (d+1) => a.1.1.val) h + simp [site] at he + | inr s => + cases t with + | inl y => + have he := congrArg (fun a : Site (d+1) => a.1.1.val) h + simp [site] at he + | inr t => + obtain ⟨b,s⟩ := s + obtain ⟨c,t⟩ := t + have hbc := congrArg (fun a : Site (d+1) => a.1.2 0) h + simp only [site, Fin.cons_zero] at hbc + have hst : site d s = site d t := by + apply Subtype.ext + apply Prod.ext + · exact Fin.succ_inj.mp (congrArg (fun a : Site (d+1) => a.1.1) h) + · exact congrArg (fun a : Site (d+1) => Fin.tail a.1.2) h + cases hbc + cases ih hst + rfl + +lemma site_surjective (d : ℕ) : Function.Surjective (site d) := by + induction d with + | zero => intro t; exact Fin.elim0 t.1.1 + | succ d ih => + rintro ⟨⟨i,x⟩,hx⟩ + refine Fin.cases ?_ (fun j => ?_) i hx + · intro hx0 + refine ⟨Sum.inl (Fin.tail x), ?_⟩ + apply Subtype.ext + simp only [site, Prod.mk.injEq, true_and] + rw [←hx0,Fin.cons_self_tail] + · intro hxj + obtain ⟨t,ht⟩ := ih ⟨(j,Fin.tail x),hxj⟩ + refine ⟨Sum.inr (x 0,t), ?_⟩ + apply Subtype.ext + simp only [site,ht,Fin.cons_self_tail] + +noncomputable def siteEquiv (d : ℕ) : SwitchIndex d ≃ Site d := + Equiv.ofBijective (site d) ⟨site_injective d,site_surjective d⟩ + +def reverseCard (d : ℕ) : Equiv.Perm (Card d) where + toFun x := fun i => x i.rev + invFun x := fun i => x i.rev + left_inv x := by funext i; simp + right_inv x := by funext i; simp + +@[simp] lemma reverseCard_apply (d : ℕ) (x : Card d) (i : Fin d) : + reverseCard d x i = x i.rev := rfl + +@[simp] lemma reverseCard_involutive (d : ℕ) (x : Card d) : + reverseCard d (reverseCard d x) = x := by funext i; simp + +def mirrorSite (d : ℕ) : Equiv.Perm (Site d) where + toFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ + invFun s := ⟨(s.1.1.rev,reverseCard d s.1.2),by simpa using s.2⟩ + left_inv s := by apply Subtype.ext; simp + right_inv s := by apply Subtype.ext; simp + +noncomputable def mirrorSwitch (d : ℕ) : Equiv.Perm (SwitchIndex d) := + (siteEquiv d).trans ((mirrorSite d).trans (siteEquiv d).symm) + +lemma site_mirrorSwitch (d : ℕ) (t : SwitchIndex d) : + site d (mirrorSwitch d t) = mirrorSite d (site d t) := by + exact (siteEquiv d).apply_symm_apply _ + +lemma routeDomain_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + t ∈ routeDomain d x y ↔ + ∀ j : Fin d, j ≠ (site d t).1.1 → + (site d t).1.2 j = if j < (site d t).1.1 then x j else y j := by + classical + induction d with + | zero => exact Empty.elim t + | succ d ih => + cases t with + | inl z => + change Sum.inl z ∈ (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ + simp only [Finset.mem_insert, Sum.inl.injEq,Finset.mem_image, + reduceCtorEq,and_false,exists_false,or_false] + constructor + · intro hz j hj + subst z + have hj0 : j ≠ 0 := hj + obtain ⟨i,rfl⟩ := Fin.eq_succ_of_ne_zero hj0 + simp [site,Fin.tail] + · intro h + funext j + have he := h j.succ (by simp [site]) + simpa [site,Fin.tail] using he + | inr z => + obtain ⟨b,t⟩ := z + change Sum.inr (b,t) ∈ (insert (Sum.inl (Fin.tail y)) + ((routeDomain d (Fin.tail x) (Fin.tail y)).image + (fun i => (Sum.inr (x 0,i) : Sum (Card d) (Bool × SwitchIndex d)))) : + Finset (Sum (Card d) (Bool × SwitchIndex d))) ↔ _ + simp only [Finset.mem_insert,reduceCtorEq,false_or,Finset.mem_image,Sum.inr.injEq,Prod.mk.injEq] + constructor + · rintro ⟨s,hs,hb,ht⟩ + subst s + have hst := (ih (Fin.tail x) (Fin.tail y) t).mp hs + intro j hj + refine Fin.cases ?_ (fun i => ?_) j hj + · intro _ + simp [site,hb] + · intro hi + have hi' : i ≠ (site d t).1.1 := by simpa [site] using hi + simpa [site,Fin.tail] using hst i hi' + · intro h + have hb := h 0 (by simpa only [site] using (Fin.succ_ne_zero (site d t).1.1).symm) + have hb' : x 0 = b := by simpa [site] using hb.symm + refine ⟨t,?_,hb',rfl⟩ + apply (ih (Fin.tail x) (Fin.tail y) t).mpr + intro j hj + have he := h j.succ (by simpa [site] using hj) + simpa [site,Fin.tail] using he + +lemma routeValue_site (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + routeValue d x y t = Bool.xor (x (site d t).1.1) (y (site d t).1.1) := by + induction d with + | zero => exact Empty.elim t + | succ d ih => + cases t with + | inl z => rfl + | inr z => exact ih (Fin.tail x) (Fin.tail y) z.2 + +lemma mirrorSwitch_involutive (d : ℕ) (t : SwitchIndex d) : + mirrorSwitch d (mirrorSwitch d t) = t := by + apply site_injective d + rw [site_mirrorSwitch,site_mirrorSwitch] + apply Subtype.ext + simp [mirrorSite] + +lemma mirror_routeDomain (d : ℕ) (x y : Card d) (t : SwitchIndex d) + (ht : t ∈ routeDomain d x y) : + mirrorSwitch d t ∈ routeDomain d (reverseCard d y) (reverseCard d x) := by + rw [routeDomain_site,site_mirrorSwitch] + intro j hj + have hj' : j.rev ≠ (site d t).1.1 := by + intro h + apply hj + change j = (site d t).1.1.rev + rw [←h,Fin.rev_rev] + have he := (routeDomain_site d x y t).mp ht j.rev hj' + change (site d t).1.2 j.rev = + if j < (site d t).1.1.rev then y j.rev else x j.rev + rw [he] + have hord : j < (site d t).1.1.rev ↔ ¬j.rev < (site d t).1.1 := by + rw [Fin.lt_rev_iff] + constructor + · intro h + exact not_lt_of_ge h.le + · intro h + exact lt_of_le_of_ne (le_of_not_gt h) (Ne.symm hj') + by_cases h : j.rev < (site d t).1.1 <;> simp [h,hord] + +lemma mirror_routeValue (d : ℕ) (x y : Card d) (t : SwitchIndex d) : + routeValue d (reverseCard d y) (reverseCard d x) (mirrorSwitch d t) = + routeValue d x y t := by + rw [routeValue_site,routeValue_site,site_mirrorSwitch] + simp only [mirrorSite,Equiv.coe_fn_mk,reverseCard_apply,Fin.rev_rev] + exact Bool.xor_comm _ _ + +noncomputable def mirrorCoins (d : ℕ) : Equiv.Perm (SwitchIndex d → Bool) where + toFun ω := fun t => ω (mirrorSwitch d t) + invFun ω := fun t => ω (mirrorSwitch d t) + left_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] + right_inv ω := by funext t; change ω (mirrorSwitch d (mirrorSwitch d t)) = ω t; rw [mirrorSwitch_involutive] + +lemma mirror_endpoint (d : ℕ) (ω : SwitchIndex d → Bool) (x y : Card d) + (hxy : butterflyPerm d (decodeButterfly d ω) x = y) : + butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) (reverseCard d y) = + reverseCard d x := by + apply (butterfly_endpoint_iff d _ _ _).mpr + intro t ht + have ht' := mirror_routeDomain d (reverseCard d y) (reverseCard d x) t ht + simp only [reverseCard_involutive] at ht' + have he := (butterfly_endpoint_iff d ω x y).mp hxy (mirrorSwitch d t) ht' + change ω (mirrorSwitch d t) = _ + rw [he] + have hv := mirror_routeValue d x y (mirrorSwitch d t) + rw [mirrorSwitch_involutive] at hv + exact hv.symm + +lemma butterfly_mirror (d : ℕ) (ω : SwitchIndex d → Bool) : + butterflyPerm d (decodeButterfly d (mirrorCoins d ω)) = + reverseCard d * (butterflyPerm d (decodeButterfly d ω))⁻¹ * reverseCard d := by + apply Equiv.ext + intro x + have he := mirror_endpoint d ω + ((butterflyPerm d (decodeButterfly d ω))⁻¹ (reverseCard d x)) (reverseCard d x) + (Equiv.apply_symm_apply _ _) + simpa only [reverseCard_involutive,Equiv.Perm.mul_apply] using he + +def reverseOrder (d : ℕ) : Equiv.Perm (Fin d) where + toFun := Fin.rev + invFun := Fin.rev + left_inv := Fin.rev_rev + right_inv := Fin.rev_rev + +lemma relabel_mul (d : ℕ) (a b : Equiv.Perm (Fin d)) : + StrongSmoothing.coordinateRelabel d (a*b) = + StrongSmoothing.coordinateRelabel d a * StrongSmoothing.coordinateRelabel d b := rfl + +lemma relabel_reverse (d : ℕ) : + StrongSmoothing.coordinateRelabel d (reverseOrder d) = reverseCard d := rfl + +lemma reverseCard_sq (d : ℕ) : reverseCard d * reverseCard d = 1 := by + ext x i + simp + +lemma sweep_mirror (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : + StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω) = + (StrongSmoothing.sweep d order ω)⁻¹ := by + simp only [StrongSmoothing.sweep,relabel_mul,relabel_reverse,butterfly_mirror,mul_inv_rev] + have hR : (reverseCard d)⁻¹ = reverseCard d := by + exact inv_eq_of_mul_eq_one_right (reverseCard_sq d) + rw [hR] + calc + _ = StrongSmoothing.coordinateRelabel d order * + (reverseCard d*reverseCard d) * + (butterflyPerm d (decodeButterfly d ω))⁻¹ * + (reverseCard d*reverseCard d) * (StrongSmoothing.coordinateRelabel d order)⁻¹ := by group + _ = _ := by rw [reverseCard_sq]; group + +lemma sweepKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : + StrongSmoothing.sweepKernel d l (order*reverseOrder d) = + (StrongSmoothing.sweepKernel d l order).transpose := by + classical + rw [StrongSmoothing.sweepKernel_law,StrongSmoothing.sweepKernel_law, + ←StrongSmoothing.PermLaw.inverse] + ext x y + unfold StrongSmoothing.PermLaw.kernel + rw [finiteMean_equiv (mirrorCoins d)] + apply finiteMean_congr + intro ω + change (if StrongSmoothing.tuplePerm + (StrongSmoothing.sweep d (order*reverseOrder d) (mirrorCoins d ω)) x = y then (1:ℝ) else 0) = _ + rw [sweep_mirror,StrongSmoothing.tuplePerm_inverse] + +lemma reflectedKernel_reverse (d l : ℕ) (order : Equiv.Perm (Fin d)) : + StrongSmoothing.reflectedKernel d l order true = + StrongSmoothing.reflectedKernel d l (order*reverseOrder d) false := by + simp only [StrongSmoothing.reflectedKernel,Bool.false_eq_true, + ↓reduceIte,sweepKernel_reverse,Matrix.transpose_transpose] + +end Thorp.ButterflyReverse + +namespace Thorp.StrongTail +open scoped BigOperators Classical + +section +open StrongSmoothing + +lemma reflected_nonneg_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x y : Tuples d l) : 0 ≤ reflectedKernel d l order rev x y := by + cases rev + · exact reflected_nonneg _ _ _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_nonneg _ _ _ _ _ + +lemma reflected_symm_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) : + (reflectedKernel d l order rev).IsSymm := by + cases rev + · exact reflected_symmetric _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_symmetric _ _ _ + +lemma reflected_moment_both (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : Tuples d l) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^(1+(1/1000:ℝ))) ≤ + Real.exp (l*(1+heightDecay 1)) := by + cases rev + · exact reflected_moment _ _ _ _ + · rw [ButterflyReverse.reflectedKernel_reverse] + exact reflected_moment _ _ _ _ + +lemma reflected_moment_small (d l : ℕ) (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : Tuples d l) {p : ℝ} (hp : 0 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) ≤ + Real.exp (l*(1+heightDecay 1)) := by + let : Nonempty (Tuples d l) := ⟨x⟩ + let q : ℝ := 1+1/1000 + let f := fun y : Tuples d l => (Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y + have hf : ∀ y, 0 ≤ f y := fun y => mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both _ _ _ _ _ _) + have hq : 0 < q := by norm_num [q] + have hr : 0 ≤ p/q := (div_pos hp hq).le + have hr1 : p/q ≤ 1 := (div_le_one hq).mpr hpq + have he (y) : (f y)^p = ((f y)^q)^(p/q) := by + rw [←Real.rpow_mul (hf y)] + congr 1 + field_simp + simp_rw [show (fun y : Tuples d l => ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order rev x y)^p) + = fun y => ((f y)^q)^(p/q) from funext he] + apply (mean_rpow_concave _ (fun y => Real.rpow_nonneg (hf y) _) hr hr1).trans + apply (Real.rpow_le_rpow (finiteMean_nonneg (fun y => Real.rpow_nonneg (hf y) _)) + (reflected_moment_both d l order rev x) hr).trans + rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hA : 0 ≤ (l:ℝ)*(1+heightDecay 1) := by + have hh := heightDecay_nonneg 1 + positivity + nlinarith + +lemma log_factorial_le_power (n N : ℕ) (hn : n ≤ N) (_hN : 0 < N) : + Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log N := by + have hb : (n.factorial:ℝ) ≤ (N:ℝ)^n := by + exact_mod_cast (Nat.factorial_le_pow n).trans (Nat.pow_le_pow_left hn n) + simpa only [Real.log_pow] using Real.log_le_log (by positivity : (0:ℝ) ((Fintype.card X:ℝ)*f x)^p) := by + let M : ℝ := Fintype.card X + have hM : 0 < M := Nat.cast_pos.mpr Fintype.card_pos + have he (x) : (N*f x)^p = (N/M)^p*(M*f x)^p := by + rw [←Real.mul_rpow (div_nonneg hN.le hM.le) (mul_nonneg hM.le (hf x))] + congr 1 + field_simp + simp_rw [he] + rw [←Finset.mul_sum,Real.rpow_sub (div_pos hN hM),Real.rpow_one] + unfold finiteMean + dsimp [M] at hM ⊢ + field_simp + +lemma density_at_small_exponent {p : ℝ} (hp : 1 < p) (hpq : p ≤ 1+(1/1000:ℝ)) : + DensityAt p (3+heightDecay 1) := by + intro d l hl order rev x + dsimp only + let : Nonempty (Tuples d l) := ⟨x⟩ + let H := reflectedKernel d l order rev + have hm := reflected_moment_small d l order rev x (by linarith : 0 H x y) (reflected_nonneg_both d l order rev x) + (by positivity) p] + have hrat : ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) ≤ Real.exp (2*l) := by + apply (Real.log_le_iff_le_exp (by positivity)).mp + rw [tuples_card] + exact_mod_cast log_normalization_le (2^d) l (by positivity) hl + have hr : 0 ≤ ((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ) := by positivity + have hrp : (((2:ℝ)^d)^l/(Fintype.card (Tuples d l):ℝ))^(p-1) ≤ Real.exp (2*l) := by + apply (Real.rpow_le_rpow hr hrat (by linarith)).trans + rw [Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hpl : p-1 ≤ 1 := by linarith + nlinarith [(show (0:ℝ) ≤ l by positivity)] + apply (mul_le_mul hrp hm (finiteMean_nonneg (fun y => Real.rpow_nonneg + (mul_nonneg (Nat.cast_nonneg _) (reflected_nonneg_both d l order rev x y)) _)) (Real.exp_pos _).le).trans + rw [←Real.exp_add] + apply Real.exp_le_exp.mpr + ring_nf + rfl + dsimp [H] at hpow + refine ⟨hm.trans hb,?_,hpow,?_⟩ + · simpa only [hs] using hm.trans hb + · simpa only [hs] using hpow + +end +open Specht UnitaryFinite + +lemma dimension_le_factorial (μ : YoungDiagram) : + Module.finrank ℂ (space μ) ≤ μ.card.factorial := by + have hdim : Module.finrank ℂ (space μ) ≤ Fintype.card (Tabloid μ) := by + simpa using Submodule.finrank_le (space μ) + have hrow : 1 ≤ Fintype.card (rowGroup μ) := Fintype.card_pos + have hc := card_tabloid_mul_row μ + nlinarith + +lemma tail_card_exact (μ : YoungDiagram) : + (tailDiagram μ).card = μ.card - μ.rowLen 0 := by + rw [←card_cell,Fintype.card_congr (tailCellEquiv μ),tail_card] + +lemma tail_dimension_le_factorial (μ : YoungDiagram) : + Module.finrank ℂ (space (tailDiagram μ)) ≤ (μ.card - μ.rowLen 0).factorial := by + simpa only [tail_card_exact] using dimension_le_factorial (tailDiagram μ) + +lemma sweep_sq_palindrome (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : + ‖SparseContact.sweepOperator d μ e rev‖^2 = + ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm d)‖ := by + rw [SparseContact.sweep_forward_norm, sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e)] + change ‖sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))‖^2 = _ + rw [show (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))).adjoint = + star (sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) + (fun ω => butterflyPerm d (decodeButterfly d ω))) from rfl] + simpa only [pow_two] using (CStarRing.norm_self_mul_star (x := sampleOperator (V := hilbertSpace μ) + (relabelledUnitary μ e) (fun ω => butterflyPerm d (decodeButterfly d ω)))).symm + +lemma sweep_sq_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ) (rev : Bool) : + ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ 1 := by + have h := SparseContact.sweep_norm_le_one d μ e rev + nlinarith [norm_nonneg (SparseContact.sweepOperator d μ e rev)] + +theorem strong_tail : MainStatement := by + obtain ⟨a,h,ha,hh,dE⟩ := Specht.spectral_regimes + obtain ⟨D0,hD0⟩ := Filter.eventually_atTop.mp dE + let d0 := max D0 1 + let t : ℝ := min a (1/1000) + have ht : 0 < t := lt_min ha (by norm_num) + have hta : t ≤ a := min_le_left _ _ + have htq : t ≤ 1/1000 := min_le_right _ _ + let b := t/(1+t) + have hden : 0 < 1+t := by linarith + have hb : 0 < b := div_pos ht hden + have hbt : b ≤ t := (div_le_iff₀ hden).mpr (by nlinarith [sq_nonneg t]) + have hba : b ≤ a := hbt.trans hta + have hb1 : b ≤ 1 := (div_le_one hden).mpr (by linarith) + let C := Real.log (((2^d0).factorial:ℕ):ℝ) + have hC : 0 ≤ C := Real.log_nonneg (by exact_mod_cast Nat.factorial_pos (2^d0)) + refine ⟨1+t,3+heightDecay 1,C,by linarith,by linarith, + density_at_small_exponent (by linarith) (by linarith),?_⟩ + intro d μ e rev + let k := μ.card - μ.rowLen 0 + let D : ℝ := Module.finrank ℂ (space (tailDiagram μ)) + have hD : 1 ≤ D := by dsimp [D]; exact_mod_cast dimension_pos (tailDiagram μ) + have hDp : 0 < D := by linarith + have hlog : 0 ≤ Real.log D := Real.log_nonneg hD + have hμ : μ.card=2^d := by rw [←card_cell,←Fintype.card_congr e,card_positions] + have hform : -(((1+t)-1)/(1+t)) = -b := by dsimp [b]; congr 1; ring + rw [hform] + change ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ Real.exp (C*k)*D^(-b) + rw [Real.rpow_def_of_pos hDp,←Real.exp_add] + by_cases hk : k=0 + · have hDone : D=1 := by + have hn := tail_dimension_le_factorial μ + change Module.finrank ℂ (space (tailDiagram μ)) ≤ k.factorial at hn + rw [hk,Nat.factorial_zero] at hn + have hu : D ≤ 1 := by dsimp [D]; exact_mod_cast hn + linarith + rw [hk,Nat.cast_zero,mul_zero,hDone,Real.log_one,zero_mul,add_zero,Real.exp_zero] + exact sweep_sq_le_one d μ e rev + · have hkpos : 0 partialKernel d Finset.univ x y) (zeroExtend f) = - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - apply Finset.sum_congr rfl - intro y _ - congr 2 - simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), - one_mul, endpointProb, UnitaryFinite.actionKernel] - apply finiteMean_congr - intro ω - congr 1 - simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] - rfl - -lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) - (x : L ↪ Card d) (y : L → Card d) : - (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = - ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by - classical - by_cases h : ContactEvent d x y - · simp only [retainedKernel, ite_eq_left h] - · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] - exact (alternating_kernel_cancel d x y h).symm - -lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = - ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by - classical - calc - _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by - ext x - simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] - rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] - apply Finset.sum_congr rfl - intro y _ - simp_rw [← mul_assoc, ← Finset.sum_mul] - congr 1 - have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) - simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, - Complex.ofReal_one] using he - _ = ((-1:ℂ)^(Fintype.card L)) • - rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by - rw [Finset.sum_eq_single (Finset.univ : Finset L)] - · simp only [Finset.card_univ] - · intro A _ hA - rw [partial_proper_zero d A hA f hf, smul_zero] - · simp - _ = _ := by rw [partial_full_action] - -lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) - (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by - classical - let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) - have hB : 0 ≤ B := by dsimp [B]; positivity - have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by - have hh := retained_norm_sq d A hδ hδ1 - have hs := Real.sq_sqrt hB - have hn := Real.sqrt_nonneg B - nlinarith - calc - _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel - (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by - rw [alternating_harmonic_action d f hf] - _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := - norm_sum_le _ _ - _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by - apply Finset.sum_le_sum - intro A _ - simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] - calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := - ContinuousLinearMap.le_opNorm _ _ - _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) - _ = _ := by rw [norm_zeroExtend] - _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, - Nat.cast_pow, Nat.cast_ofNat]; ring - -lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) - (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by - classical - obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL - have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by - ext v x - have hh (y : L → Card d) : ¬ContactEvent d x y := by - intro h - obtain ⟨j,hj,_⟩ := h i - exact hj (hi j).symm - simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, - zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] - have he := alternating_harmonic_action d f hf - simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, - neg_smul, one_smul] at he - exact neg_eq_zero.mp he.symm - -end -open scoped BigOperators - -def MainStatement : Prop := - ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ - ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), - let k := μ.card - μ.rowLen 0 - 1 ≤ k → k < 2^d → ∀ reverse : Bool, - ‖sweepOperator d μ e reverse‖^2 ≤ - min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ - (k = 1 → sweepOperator d μ e reverse = 0) ∧ - ‖sweepOperator d μ e reverse‖^2 ≤ - C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - -end Thorp.SparseContact - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) - (hL : Fintype.card L = μ.card - μ.rowLen 0) : - ∃ w : Specht.hilbertSpace μ, - UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by - let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) - have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by - rw [Specht.finrank_hilbertSpace] - exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) - have hdim := Specht.relabelled_tuple_dimension μ e x₀ - rw [hL, Nat.choose_self, mul_one] at hdim - have hm : 0 < Module.finrank ℂ K := by - by_contra h - have hz : Module.finrank ℂ K = 0 := by omega - change _ ≤ Module.finrank ℂ K * _ at hdim - rw [hz, zero_mul] at hdim - omega - let B := stdOrthonormalBasis ℂ K - let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ - exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ - -lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by - cases rev - · rfl - · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] - rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), - ContinuousLinearMap.adjoint.norm_map] - -lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ 1 := - UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ - -section Generic -variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] - -lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ - (2:ℝ)^(Fintype.card L) * - Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L))) := by - rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ - (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), - ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_bound d _ (hh v) hδ hδ1 - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha - exact ha - -lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) - [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) - (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) - (hn : ‖w‖ = 1) - (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) - (hL : Fintype.card L = 1) : - UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by - apply ContinuousLinearMap.adjoint.injective - rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.ext - intro v - rw [UnitaryFinite.sampleOperator_inv_apply] - have ha := harmonic_action_zero_one d hL _ (hh v) - have he := congrArg norm ha - rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, - UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he - exact norm_eq_zero.mp he -end Generic - -lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : - ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * - Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * - Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by - classical - let x₀ : Specht.TailCell μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - rw [sweep_forward_norm μ e rev] - have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.TailCell μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) - simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he - -lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by - classical - let x₀ : Specht.TailCell μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding - obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) - let := Specht.relabelledUnitary_irreducible μ e - have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient - (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := - normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v - have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.TailCell μ) d (Specht.relabelledUnitary μ e) - have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh - have he := he ((Specht.tail_card μ).trans hk) - have hz : sweepOperator d μ e false = 0 := by - simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he - apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp - rw [sweep_forward_norm μ e rev, hz] - exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ - -end Thorp.SparseContact - -namespace Thorp.SparseContact - -noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) - -lemma contactConstant_gt_one : 1 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma contactConstant_gt_two : 2 < contactConstant := by - have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) - unfold contactConstant - linarith - -lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : - ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = - ((contactConstant/2)*δ)^((k:ℝ)/2) := by - have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity - rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] - have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by - unfold contactConstant - rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, - Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] - norm_num - ring - rw [hc, ←Real.exp_mul] - have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by - rw [← pow_mul, mul_comm k 2, pow_mul] - norm_num only [pow_two] - rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] - rw [hpow] - calc - _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring - _ = _ := by rw [←Real.exp_add]; congr 2; ring - -lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : - (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by - rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] - apply mul_le_mul_of_nonneg_right _ (by positivity) - apply mul_le_mul - · rw [← Real.rpow_natCast] - exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) - · calc - d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) - _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) - · positivity - · positivity - - -lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) - (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : - ‖sweepOperator d μ e rev‖^2 ≤ min 1 - ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by - let k := μ.card - μ.rowLen 0 - have hk' : (0:ℝ) < k := by exact_mod_cast hk - have hd' : (0:ℝ) < d := by exact_mod_cast hd - have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity - have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by - have h := sweep_norm_le_one d μ e rev - have h0 := norm_nonneg (sweepOperator d μ e rev) - nlinarith - refine le_min hOne ?_ - have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = - (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring - change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) - rw [he] - by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 - · have h := sweep_norm_bound d μ e hδ hs rev - have hb : 0 ≤ (2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity - calc - _ ≤ ((2:ℝ)^k * Real.sqrt - ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := - (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h - _ = _ := inflated_contact_bound hδ.le k - · apply hOne.trans - apply Real.one_le_rpow - · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith - exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) - · positivity - -theorem uniform_sparse_contact : MainStatement := by - refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), - (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ - intro d hd μ e k hk _ rev - have hs := sweep_sharp_bound d hd μ e hk rev - refine ⟨hs, ?_, ?_⟩ - · intro hk1 - exact sweep_zero_one d μ e hk1 rev - · apply (hs.trans (min_le_right _ _)).trans - change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ - rw [mul_div_assoc] - exact contact_crude_arithmetic contactConstant_gt_one.le - (by exact_mod_cast hd) (by positivity) k - -end Thorp.SparseContact - -namespace Thorp.DimensionEstimates -open scoped BigOperators - -lemma log_factorial_upper_binary (n : ℕ) (hn : 0 norm_num - | succ n hn ih => - have hn0 : (0:ℝ) norm_num - | succ n hn ih => - have hn0 : (0:ℝ) norm_num - | succ n hn ih => - have hn0 : (0:ℝ) congrArg u x.property) - _ = _ := by simp [fiberWeight] - -lemma sum_fiberWeight (f : X → I) : ∑ i, fiberWeight f i=Fintype.card X := by - have h := fiber_sum f (fun _ => 1) - simpa using h.symm - -theorem incidence_entropy (f : X → I) (g : X → J) - (hinj : Function.Injective (fun x => (f x,g x))) : - (∑ i, fiberWeight f i*Real.log (fiberWeight f i))+ - (∑ j, fiberWeight g j*Real.log (fiberWeight g j)) ≤ - (Fintype.card X:ℝ)*Real.log (Fintype.card X) := by - by_cases hX : Nonempty X - · let : Nonempty X := hX - have hN : (0:ℝ) (f x,g x)), fiberWeight f p.1*fiberWeight g p.2 := by - rw [Finset.sum_image (fun x _ y _ h => hinj h)] - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun p _ _ => mul_nonneg (fiberWeight_nonneg f p.1) (fiberWeight_nonneg g p.2)) - _ = _ := by - rw [Fintype.sum_prod_type] - simp_rw [←Finset.mul_sum] - rw [←Finset.sum_mul,sum_fiberWeight,sum_fiberWeight,pow_two] - have hdiv : (∑ x, fiberWeight f (f x)*fiberWeight g (g x))/(Fintype.card X:ℝ) ≤ Fintype.card X := by - apply (div_le_iff₀ hN).mpr - simpa only [pow_two] using hprod - have hl (x : X) := Real.log_le_sub_one_of_pos - (show 0 hl x) - simp_rw [Real.log_div (mul_pos (fiberWeight_pos f _) (fiberWeight_pos g _)).ne' hN.ne', - Real.log_mul (fiberWeight_pos f _).ne' (fiberWeight_pos g _).ne'] at hs - rw [Finset.sum_sub_distrib,Finset.sum_add_distrib, - fiber_sum f (fun i => Real.log (fiberWeight f i)), - fiber_sum g (fun j => Real.log (fiberWeight g j)), - Finset.sum_sub_distrib,←Finset.sum_div] at hs - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hs - linarith - · let : IsEmpty X := not_nonempty_iff.mp hX - have hf (i : I) : fiberWeight f i=0 := by simp [fiberWeight] - have hg (j : J) : fiberWeight g j=0 := by simp [fiberWeight] - simp [hf,hg] - -end Thorp.DimensionEstimates - -namespace Thorp.DimensionEstimates -open scoped BigOperators Classical - -lemma log_factorial_upper_binary_all (n : ℕ) : - Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by - by_cases hn : n=0 - · subst n - simpa using (Real.log_nonneg (by norm_num : (1:ℝ)≤2)) - · exact log_factorial_upper_binary n (Nat.pos_of_ne_zero hn) - -lemma log_fiber_factorials {X I : Type*} [Fintype X] [Fintype I] (f : X → I) : - Real.log ((∏ i, (Fintype.card {x // f x=i}).factorial : ℕ):ℝ) ≤ - ∑ i, fiberWeight f i*Real.log (fiberWeight f i) - - Real.log 2*((Fintype.card X:ℝ)-Fintype.card I) := by - rw [Nat.cast_prod,Real.log_prod (fun _ _ => by positivity)] - have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - log_factorial_upper_binary_all (Fintype.card {x // f x=i})) - change ∑ i, Real.log ((Fintype.card {x // f x=i}).factorial:ℝ) ≤ - ∑ i, (fiberWeight f i*Real.log (fiberWeight f i)-Real.log 2*(fiberWeight f i-1)) at h - rw [Finset.sum_sub_distrib,←Finset.mul_sum,Finset.sum_sub_distrib,sum_fiberWeight] at h - simpa using h - -theorem dimension_log_from_incidence {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] - [Nonempty X] (f : X → I) (g : X → J) - (hinj : Function.Injective (fun x => (f x,g x))) (D : ℕ) - (hD : (Fintype.card X).factorial ≤ D * - (∏ i, (Fintype.card {x // f x=i}).factorial) * - (∏ j, (Fintype.card {x // g x=j}).factorial)) : - ((2*Real.log 2-1)*(Fintype.card X:ℝ)- - Real.log 2*((Fintype.card I:ℝ)+Fintype.card J)+1) ≤ Real.log D := by - have hd : 0 Real.log (n:ℝ)) (Nat.choose_mul_factorial_mul_factorial hjN.le) - simp only [Nat.cast_mul] at hfac - rw [Real.log_mul (mul_pos hchoose (by positivity)).ne' (by positivity), - Real.log_mul hchoose.ne' (by positivity)] at hfac - have hlo := log_factorial_lower N hN - have hji := log_factorial_upper j hj - have hti := log_factorial_upper (N-j) ht - have hjlog := Real.log_le_log hj0 hjN0.le - have htlog := Real.log_le_log (by exact_mod_cast ht : (0:ℝ)<(N-j:ℕ)) - (by exact_mod_cast Nat.sub_le N j : ((N-j:ℕ):ℝ)≤N) - rw [Nat.cast_sub hjN.le] at hti htlog - rw [scaled_binEntropy N j hN0 hj0 hjN0] - linarith - -lemma binEntropy_three_quarters : - Real.binEntropy (3/4:ℝ)=2*Real.log 2-(3/4:ℝ)*Real.log 3 := by - have h4 : Real.log (4:ℝ)=2*Real.log 2 := by - rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num - unfold Real.binEntropy - norm_num only [show (1-(3/4:ℝ))=1/4 by norm_num] - rw [Real.log_div (by norm_num) (by norm_num),h4] - ring - -noncomputable def entropyGap : ℝ := Real.log (32/27:ℝ)/3 - -lemma entropyGap_pos : 0 norm_num) - (show (3/4:ℝ)∈Set.Icc 0 1 by constructor <;> norm_num) - (show 0≤1-4*q/3 by linarith) (show 0≤4*q/3 by positivity) - (show (1-4*q/3)+(4*q/3)=1 by ring) - simp only [Real.binEntropy_zero,binEntropy_three_quarters,smul_eq_mul,mul_zero,zero_add] at hc - have he : 4*q/3*(3/4:ℝ)=q := by ring - rw [he] at hc - rw [entropyGap_eq] - linarith - -lemma log_dimension_from_binomial (N j D : ℕ) (hj : 0.1 - have he : (j:ℝ)*x=N := by dsimp [x]; field_simp - have hk := (chosenTuple_bounds N j hj hx hhalf).2.2 - change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower at hk - have hratio : (chosenTuple N j:ℝ)/N≤2*x^(nearPower-1) := by - rw [Real.rpow_sub hxp,Real.rpow_one] - apply (div_le_iff₀ hNp).mpr - rw [←he] - have : 2*(x^nearPower/x)*((j:ℝ)*x)=2*(j:ℝ)*x^nearPower := by field_simp - rw [this] - exact hk - have hpow := Real.rpow_le_rpow (by positivity : (0:ℝ)≤(chosenTuple N j:ℝ)/N) hratio - (by norm_num : (0:ℝ)≤1/512) - have hmain := mul_le_mul hk hpow (by positivity) (by positivity) - have hrpow : (2*x^(nearPower-1))^(1/512:ℝ)= - (2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)) := by - rw [Real.mul_rpow (by norm_num) (by positivity),←Real.rpow_mul hxp.le] - rw [hrpow] at hmain - have heq : 2*(j:ℝ)*x^nearPower*((2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)))= - (2:ℝ)^(1+(1/512:ℝ))*(j:ℝ)*x^(-tailPower) := by - rw [Real.rpow_add (by norm_num : (0:ℝ)<2),Real.rpow_one] - have hp : nearPower+(nearPower-1)*(1/512) = -tailPower := by norm_num [nearPower,tailPower] - rw [←hp,Real.rpow_add hxp] - ring - rw [heq] at hmain - have h := mul_le_mul_of_nonneg_left hmain hC - simpa only [mul_assoc] using h - -lemma near_conditions_eventually (C : ℝ) : - ∀ᶠ x : ℝ in atTop, 2≤x ∧ 2≤x^nearPower ∧ x^(nearPower-1)≤1/2 ∧ - 8*Real.log 2/nearPower≤Real.log x ∧ 4*Real.log 2+2≤Real.log x ∧ - C*2^(1+(1/512:ℝ))*x^(-tailPower) ≤ nearFraction/4000 := by - have hpow := (tendsto_rpow_atTop (by norm_num [nearPower] : 0 C*2^(1+(1/512:ℝ))*x^(-tailPower)) atTop (nhds 0) := by - simpa only [mul_zero] using - (tendsto_const_nhds.mul (tendsto_rpow_neg_atTop (by norm_num [tailPower] : 0 partialKernel d Finset.univ x y) (zeroExtend f) = + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + apply Finset.sum_congr rfl + intro y _ + congr 2 + simp only [partialKernel, Finset.card_univ, div_self (by positivity : ((2:ℝ)^d)^(Fintype.card L) ≠ 0), + one_mul, endpointProb, UnitaryFinite.actionKernel] + apply finiteMean_congr + intro ω + congr 1 + simp only [Finset.mem_univ, forall_const, Function.Embedding.ext_iff] + rfl + +lemma alternating_retained_eq {L : Type*} [Fintype L] (d : ℕ) + (x : L ↪ Card d) (y : L → Card d) : + (∑ A : Finset L, (-1:ℝ)^A.card * retainedKernel d A x y) = + ∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y := by + classical + by_cases h : ContactEvent d x y + · simp only [retainedKernel, ite_eq_left h] + · simp only [retainedKernel, ite_eq_right h, mul_zero, Finset.sum_const_zero] + exact (alternating_kernel_cancel d x y h).symm + +lemma alternating_harmonic_action {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + (∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)) = + ((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f := by + classical + calc + _ = ∑ A : Finset L, ((-1:ℂ)^A.card) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d A x y) (zeroExtend f) := by + ext x + simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, rectOperator_apply, smul_eq_mul, Finset.mul_sum] + rw [Finset.sum_comm, Finset.sum_comm (s := (Finset.univ : Finset (Finset L)))] + apply Finset.sum_congr rfl + intro y _ + simp_rw [← mul_assoc, ← Finset.sum_mul] + congr 1 + have he := congrArg (fun t : ℝ => (t:ℂ)) (alternating_retained_eq d x y) + simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_neg, + Complex.ofReal_one] using he + _ = ((-1:ℂ)^(Fintype.card L)) • + rectOperator (fun (x : L ↪ Card d) y => partialKernel d Finset.univ x y) (zeroExtend f) := by + rw [Finset.sum_eq_single (Finset.univ : Finset L)] + · simp only [Finset.card_univ] + · intro A _ hA + rw [partial_proper_zero d A hA f hf, smul_zero] + · simp + _ = _ := by rw [partial_full_action] + +lemma harmonic_action_bound {L : Type*} [Fintype L] (d : ℕ) + (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) * ‖f‖ := by + classical + let B := (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) + have hB : 0 ≤ B := by dsimp [B]; positivity + have hnorm (A : Finset L) : ‖rectOperator (retainedKernel d A)‖ ≤ Real.sqrt B := by + have hh := retained_norm_sq d A hδ hδ1 + have hs := Real.sq_sqrt hB + have hn := Real.sqrt_nonneg B + nlinarith + calc + _ = ‖((-1:ℂ)^(Fintype.card L)) • DensityTransfer.applyKernel + (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f‖ := by + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + _ = ‖∑ A : Finset L, ((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := by + rw [alternating_harmonic_action d f hf] + _ ≤ ∑ A : Finset L, ‖((-1:ℂ)^A.card) • rectOperator (retainedKernel d A) (zeroExtend f)‖ := + norm_sum_le _ _ + _ ≤ ∑ A : Finset L, Real.sqrt B * ‖f‖ := by + apply Finset.sum_le_sum + intro A _ + simp only [norm_smul, norm_pow, norm_neg, norm_one, one_pow, one_mul] + calc _ ≤ ‖rectOperator (retainedKernel d A)‖ * ‖zeroExtend f‖ := + ContinuousLinearMap.le_opNorm _ _ + _ ≤ Real.sqrt B * ‖zeroExtend f‖ := mul_le_mul_of_nonneg_right (hnorm A) (norm_nonneg _) + _ = _ := by rw [norm_zeroExtend] + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_finset, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat]; ring + +lemma harmonic_action_zero_one {L : Type*} [Fintype L] (d : ℕ) + (hL : Fintype.card L = 1) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + DensityTransfer.applyKernel (UnitaryFinite.actionKernel UnitaryFinite.tupleAction + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))) f = 0 := by + classical + obtain ⟨i,hi⟩ := Fintype.card_eq_one_iff.mp hL + have hz (A : Finset L) : rectOperator (retainedKernel d A) = 0 := by + ext v x + have hh (y : L → Card d) : ¬ContactEvent d x y := by + intro h + obtain ⟨j,hj,_⟩ := h i + exact hj (hi j).symm + simp only [rectOperator_apply, retainedKernel, ite_eq_right (hh _), Complex.ofReal_zero, + zero_mul, Finset.sum_const_zero, zero_apply, PiLp.zero_apply] + have he := alternating_harmonic_action d f hf + simp only [hz, zero_apply, smul_zero, Finset.sum_const_zero, hL, pow_one, + neg_smul, one_smul] at he + exact neg_eq_zero.mp he.symm + +end +open scoped BigOperators + +def MainStatement : Prop := + ∃ Cstar C : ℝ, 0 < Cstar ∧ 0 < C ∧ + ∀ (d : ℕ), 1 ≤ d → ∀ (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ), + let k := μ.card - μ.rowLen 0 + 1 ≤ k → k < 2^d → ∀ reverse : Bool, + ‖sweepOperator d μ e reverse‖^2 ≤ + min 1 ((Cstar * d * k / (2:ℝ)^d) ^ ((k:ℝ)/2)) ∧ + (k = 1 → sweepOperator d μ e reverse = 0) ∧ + ‖sweepOperator d μ e reverse‖^2 ≤ + C^k * (1+(d:ℝ))^(C*k) * ((k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + +end Thorp.SparseContact + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma exists_exact_fixed_unit {α L : Type*} [Fintype α] [Fintype L] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) (x₀ : L ↪ α) + (hL : Fintype.card L = μ.card - μ.rowLen 0) : + ∃ w : Specht.hilbertSpace μ, + UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w ∧ ‖w‖ = 1 := by + let K := UnitaryFinite.fixedSpace (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) + have hd : 0 < Module.finrank ℂ (Specht.hilbertSpace μ) := by + rw [Specht.finrank_hilbertSpace] + exact Module.finrank_pos_iff.mpr (Submodule.nontrivial_iff_ne_bot.mpr (Specht.space_ne_bot μ)) + have hdim := Specht.relabelled_tuple_dimension μ e x₀ + rw [hL, Nat.choose_self, mul_one] at hdim + have hm : 0 < Module.finrank ℂ K := by + by_contra h + have hz : Module.finrank ℂ K = 0 := by omega + change _ ≤ Module.finrank ℂ K * _ at hdim + rw [hz, zero_mul] at hdim + omega + let B := stdOrthonormalBasis ℂ K + let i : Fin (Module.finrank ℂ K) := ⟨0,hm⟩ + exact ⟨(B i).val, (B i).prop, B.orthonormal.norm_eq_one i⟩ + +lemma sweep_forward_norm {d : ℕ} (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ = ‖sweepOperator d μ e false‖ := by + cases rev + · rfl + · simp only [sweepOperator, Bool.false_eq_true, ite_false, ite_true] + rw [UnitaryFinite.sampleOperator_inv _ (Specht.relabelledUnitary_unitary μ e), + ContinuousLinearMap.adjoint.norm_map] + +lemma sweep_norm_le_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ 1 := + UnitaryFinite.sampleOperator_norm_le _ (Specht.relabelledUnitary_unitary μ e) _ + +section Generic +variable {L V : Type*} [Fintype L] [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] + +lemma sample_sweep_bound (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))‖ ≤ + (2:ℝ)^(Fintype.card L) * + Real.sqrt ((2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L))) := by + rw [← ContinuousLinearMap.adjoint.norm_map (UnitaryFinite.sampleOperator ρ + (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω))), + ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_bound d _ (hh v) hδ hδ1 + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn] at ha + exact ha + +lemma sample_sweep_zero_one (d : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card d)) V) + [Representation.IsIrreducible ρ] (hρ : UnitaryFinite.IsUnitary ρ) + (x₀ : L ↪ Card d) (w : V) (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ ρ w) + (hn : ‖w‖ = 1) + (hh : ∀ v, Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w v)) + (hL : Fintype.card L = 1) : + UnitaryFinite.sampleOperator ρ (fun ω : SwitchIndex d → Bool => butterflyPerm d (decodeButterfly d ω)) = 0 := by + apply ContinuousLinearMap.adjoint.injective + rw [map_zero, ← UnitaryFinite.sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.ext + intro v + rw [UnitaryFinite.sampleOperator_inv_apply] + have ha := harmonic_action_zero_one d hL _ (hh v) + have he := congrArg norm ha + rw [UnitaryFinite.coefficient_random UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ hρ _ w hw, + UnitaryFinite.normalizedCoefficient_norm _ _ _ ρ hρ w hw hn, norm_zero] at he + exact norm_eq_zero.mp he +end Generic + +lemma sweep_norm_bound (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hδ : 0 < 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d ≤ 1) (rev : Bool) : + ‖sweepOperator d μ e rev‖ ≤ (2:ℝ)^(μ.card - μ.rowLen 0) * + Real.sqrt ((2*(d:ℝ)*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2) * + Real.exp (Real.exp 1*(μ.card - μ.rowLen 0 : ℕ))) := by + classical + let x₀ : Specht.TailCell μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + rw [sweep_forward_norm μ e rev] + have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_bound (V := Specht.hilbertSpace μ) (L := Specht.TailCell μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he (by simpa only [Specht.tail_card] using hδ) (by simpa only [Specht.tail_card] using hδ1) + simpa only [sweepOperator, Bool.false_eq_true, ite_false, Specht.tail_card] using he + +lemma sweep_zero_one (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : μ.card - μ.rowLen 0 = 1) (rev : Bool) : sweepOperator d μ e rev = 0 := by + classical + let x₀ : Specht.TailCell μ ↪ Card d := (Function.Embedding.subtype _).trans e.symm.toEmbedding + obtain ⟨w,hw,hn⟩ := exists_exact_fixed_unit μ e x₀ (Specht.tail_card μ) + let := Specht.relabelledUnitary_irreducible μ e + have hh (v : Specht.hilbertSpace μ) : Harmonic (UnitaryFinite.normalizedCoefficient + (V := Specht.hilbertSpace μ) UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := + normalizedCoefficient_harmonic μ e (Specht.tail_card μ) x₀ w hw v + have he := sample_sweep_zero_one (V := Specht.hilbertSpace μ) (L := Specht.TailCell μ) d (Specht.relabelledUnitary μ e) + have he := he (Specht.relabelledUnitary_unitary μ e) x₀ w hw hn hh + have he := he ((Specht.tail_card μ).trans hk) + have hz : sweepOperator d μ e false = 0 := by + simpa only [sweepOperator, Bool.false_eq_true, ite_false] using he + apply (norm_eq_zero (a := sweepOperator d μ e rev)).mp + rw [sweep_forward_norm μ e rev, hz] + exact @norm_zero (Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ) _ + +end Thorp.SparseContact + +namespace Thorp.SparseContact + +noncomputable def contactConstant : ℝ := 32 * Real.exp (2 * Real.exp 1) + +lemma contactConstant_gt_one : 1 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma contactConstant_gt_two : 2 < contactConstant := by + have h : 1 ≤ Real.exp (2 * Real.exp 1) := Real.one_le_exp (by positivity) + unfold contactConstant + linarith + +lemma inflated_contact_bound {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) : + ((2:ℝ)^k * Real.sqrt (δ^((k:ℝ)/2) * Real.exp (Real.exp 1*k)))^2 = + ((contactConstant/2)*δ)^((k:ℝ)/2) := by + have hC : 0 ≤ contactConstant/2 := by have := contactConstant_gt_one; positivity + rw [mul_pow, Real.sq_sqrt (by positivity), Real.mul_rpow hC hδ] + have hc : contactConstant/2 = Real.exp (2*(Real.log 4+Real.exp 1)) := by + unfold contactConstant + rw [show 2*(Real.log 4+Real.exp 1) = Real.log 4*2+2*Real.exp 1 by ring, + Real.exp_add, Real.exp_mul (Real.log 4) 2, Real.exp_log (by norm_num : (0:ℝ)<4)] + norm_num + ring + rw [hc, ←Real.exp_mul] + have hpow : ((2:ℝ)^k)^2 = Real.exp (Real.log 4 * k) := by + rw [← pow_mul, mul_comm k 2, pow_mul] + norm_num only [pow_two] + rw [Real.exp_mul (Real.log 4) k, Real.exp_log (by norm_num : (0:ℝ)<4), Real.rpow_natCast] + rw [hpow] + calc + _ = (Real.exp (Real.log 4*k)*Real.exp (Real.exp 1*k))*δ^((k:ℝ)/2) := by ring + _ = _ := by rw [←Real.exp_add]; congr 2; ring + +lemma contact_crude_arithmetic {C d q : ℝ} (hC : 1 ≤ C) (hd : 1 ≤ d) (hq : 0 ≤ q) (k : ℕ) : + (C*d*q)^((k:ℝ)/2) ≤ C^k*(1+d)^(C*k)*q^((k:ℝ)/2) := by + rw [Real.mul_rpow (by positivity) hq, Real.mul_rpow (by positivity) (by positivity)] + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply mul_le_mul + · rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_le hC (by linarith [Nat.cast_nonneg (α := ℝ) k]) + · calc + d^((k:ℝ)/2) ≤ (1+d)^((k:ℝ)/2) := Real.rpow_le_rpow (by positivity) (by linarith) (by positivity) + _ ≤ (1+d)^(C*k) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by nlinarith [Nat.cast_nonneg (α := ℝ) k]) + · positivity + · positivity + + +lemma sweep_sharp_bound (d : ℕ) (hd : 1 ≤ d) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) + (hk : 1 ≤ μ.card - μ.rowLen 0) (rev : Bool) : + ‖sweepOperator d μ e rev‖^2 ≤ min 1 + ((contactConstant*d*(μ.card - μ.rowLen 0 : ℕ)/(2:ℝ)^d)^(((μ.card - μ.rowLen 0 : ℕ):ℝ)/2)) := by + let k := μ.card - μ.rowLen 0 + have hk' : (0:ℝ) < k := by exact_mod_cast hk + have hd' : (0:ℝ) < d := by exact_mod_cast hd + have hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d := by positivity + have hOne : ‖sweepOperator d μ e rev‖^2 ≤ 1 := by + have h := sweep_norm_le_one d μ e rev + have h0 := norm_nonneg (sweepOperator d μ e rev) + nlinarith + refine le_min hOne ?_ + have he : contactConstant * d * (k:ℝ)/(2:ℝ)^d = + (contactConstant/2)*(2*(d:ℝ)*k/(2:ℝ)^d) := by ring + change _ ≤ (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) + rw [he] + by_cases hs : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1 + · have h := sweep_norm_bound d μ e hδ hs rev + have hb : 0 ≤ (2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)) := by positivity + calc + _ ≤ ((2:ℝ)^k * Real.sqrt + ((2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2)*Real.exp (Real.exp 1*k)))^2 := + (sq_le_sq₀ (norm_nonneg (sweepOperator d μ e rev)) hb).mpr h + _ = _ := inflated_contact_bound hδ.le k + · apply hOne.trans + apply Real.one_le_rpow + · have hc : 1 ≤ contactConstant/2 := by have := contactConstant_gt_two; linarith + exact one_le_mul_of_one_le_of_one_le hc (le_of_lt (lt_of_not_ge hs)) + · positivity + +theorem uniform_sparse_contact : MainStatement := by + refine ⟨contactConstant, contactConstant, (lt_trans (by norm_num) contactConstant_gt_one), + (lt_trans (by norm_num) contactConstant_gt_one), ?_⟩ + intro d hd μ e k hk _ rev + have hs := sweep_sharp_bound d hd μ e hk rev + refine ⟨hs, ?_, ?_⟩ + · intro hk1 + exact sweep_zero_one d μ e hk1 rev + · apply (hs.trans (min_le_right _ _)).trans + change (contactConstant * d * (k:ℝ)/(2:ℝ)^d)^((k:ℝ)/2) ≤ _ + rw [mul_div_assoc] + exact contact_crude_arithmetic contactConstant_gt_one.le + (by exact_mod_cast hd) (by positivity) k + +end Thorp.SparseContact + +namespace Thorp.DimensionEstimates +open scoped BigOperators + +lemma log_factorial_upper_binary (n : ℕ) (hn : 0 norm_num + | succ n hn ih => + have hn0 : (0:ℝ) norm_num + | succ n hn ih => + have hn0 : (0:ℝ) norm_num + | succ n hn ih => + have hn0 : (0:ℝ) congrArg u x.property) + _ = _ := by simp [fiberWeight] + +lemma sum_fiberWeight (f : X → I) : ∑ i, fiberWeight f i=Fintype.card X := by + have h := fiber_sum f (fun _ => 1) + simpa using h.symm + +theorem incidence_entropy (f : X → I) (g : X → J) + (hinj : Function.Injective (fun x => (f x,g x))) : + (∑ i, fiberWeight f i*Real.log (fiberWeight f i))+ + (∑ j, fiberWeight g j*Real.log (fiberWeight g j)) ≤ + (Fintype.card X:ℝ)*Real.log (Fintype.card X) := by + by_cases hX : Nonempty X + · let : Nonempty X := hX + have hN : (0:ℝ) (f x,g x)), fiberWeight f p.1*fiberWeight g p.2 := by + rw [Finset.sum_image (fun x _ y _ h => hinj h)] + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun p _ _ => mul_nonneg (fiberWeight_nonneg f p.1) (fiberWeight_nonneg g p.2)) + _ = _ := by + rw [Fintype.sum_prod_type] + simp_rw [←Finset.mul_sum] + rw [←Finset.sum_mul,sum_fiberWeight,sum_fiberWeight,pow_two] + have hdiv : (∑ x, fiberWeight f (f x)*fiberWeight g (g x))/(Fintype.card X:ℝ) ≤ Fintype.card X := by + apply (div_le_iff₀ hN).mpr + simpa only [pow_two] using hprod + have hl (x : X) := Real.log_le_sub_one_of_pos + (show 0 hl x) + simp_rw [Real.log_div (mul_pos (fiberWeight_pos f _) (fiberWeight_pos g _)).ne' hN.ne', + Real.log_mul (fiberWeight_pos f _).ne' (fiberWeight_pos g _).ne'] at hs + rw [Finset.sum_sub_distrib,Finset.sum_add_distrib, + fiber_sum f (fun i => Real.log (fiberWeight f i)), + fiber_sum g (fun j => Real.log (fiberWeight g j)), + Finset.sum_sub_distrib,←Finset.sum_div] at hs + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hs + linarith + · let : IsEmpty X := not_nonempty_iff.mp hX + have hf (i : I) : fiberWeight f i=0 := by simp [fiberWeight] + have hg (j : J) : fiberWeight g j=0 := by simp [fiberWeight] + simp [hf,hg] + +end Thorp.DimensionEstimates + +namespace Thorp.DimensionEstimates +open scoped BigOperators Classical + +lemma log_factorial_upper_binary_all (n : ℕ) : + Real.log (n.factorial:ℝ) ≤ (n:ℝ)*Real.log n-Real.log 2*((n:ℝ)-1) := by + by_cases hn : n=0 + · subst n + simpa using (Real.log_nonneg (by norm_num : (1:ℝ)≤2)) + · exact log_factorial_upper_binary n (Nat.pos_of_ne_zero hn) + +lemma log_fiber_factorials {X I : Type*} [Fintype X] [Fintype I] (f : X → I) : + Real.log ((∏ i, (Fintype.card {x // f x=i}).factorial : ℕ):ℝ) ≤ + ∑ i, fiberWeight f i*Real.log (fiberWeight f i) - + Real.log 2*((Fintype.card X:ℝ)-Fintype.card I) := by + rw [Nat.cast_prod,Real.log_prod (fun _ _ => by positivity)] + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + log_factorial_upper_binary_all (Fintype.card {x // f x=i})) + change ∑ i, Real.log ((Fintype.card {x // f x=i}).factorial:ℝ) ≤ + ∑ i, (fiberWeight f i*Real.log (fiberWeight f i)-Real.log 2*(fiberWeight f i-1)) at h + rw [Finset.sum_sub_distrib,←Finset.mul_sum,Finset.sum_sub_distrib,sum_fiberWeight] at h + simpa using h + +theorem dimension_log_from_incidence {X I J : Type*} [Fintype X] [Fintype I] [Fintype J] + [Nonempty X] (f : X → I) (g : X → J) + (hinj : Function.Injective (fun x => (f x,g x))) (D : ℕ) + (hD : (Fintype.card X).factorial ≤ D * + (∏ i, (Fintype.card {x // f x=i}).factorial) * + (∏ j, (Fintype.card {x // g x=j}).factorial)) : + ((2*Real.log 2-1)*(Fintype.card X:ℝ)- + Real.log 2*((Fintype.card I:ℝ)+Fintype.card J)+1) ≤ Real.log D := by + have hd : 0 Real.log (n:ℝ)) (Nat.choose_mul_factorial_mul_factorial hjN.le) + simp only [Nat.cast_mul] at hfac + rw [Real.log_mul (mul_pos hchoose (by positivity)).ne' (by positivity), + Real.log_mul hchoose.ne' (by positivity)] at hfac + have hlo := log_factorial_lower N hN + have hji := log_factorial_upper j hj + have hti := log_factorial_upper (N-j) ht + have hjlog := Real.log_le_log hj0 hjN0.le + have htlog := Real.log_le_log (by exact_mod_cast ht : (0:ℝ)<(N-j:ℕ)) + (by exact_mod_cast Nat.sub_le N j : ((N-j:ℕ):ℝ)≤N) + rw [Nat.cast_sub hjN.le] at hti htlog + rw [scaled_binEntropy N j hN0 hj0 hjN0] + linarith + +lemma binEntropy_three_quarters : + Real.binEntropy (3/4:ℝ)=2*Real.log 2-(3/4:ℝ)*Real.log 3 := by + have h4 : Real.log (4:ℝ)=2*Real.log 2 := by + rw [show (4:ℝ)=2^2 by norm_num,Real.log_pow]; norm_num + unfold Real.binEntropy + norm_num only [show (1-(3/4:ℝ))=1/4 by norm_num] + rw [Real.log_div (by norm_num) (by norm_num),h4] + ring + +noncomputable def entropyGap : ℝ := Real.log (32/27:ℝ)/3 + +lemma entropyGap_pos : 0 norm_num) + (show (3/4:ℝ)∈Set.Icc 0 1 by constructor <;> norm_num) + (show 0≤1-4*q/3 by linarith) (show 0≤4*q/3 by positivity) + (show (1-4*q/3)+(4*q/3)=1 by ring) + simp only [Real.binEntropy_zero,binEntropy_three_quarters,smul_eq_mul,mul_zero,zero_add] at hc + have he : 4*q/3*(3/4:ℝ)=q := by ring + rw [he] at hc + rw [entropyGap_eq] + linarith + +lemma log_dimension_from_binomial (N j D : ℕ) (hj : 0.1 + have he : (j:ℝ)*x=N := by dsimp [x]; field_simp + have hk := (chosenTuple_bounds N j hj hx hhalf).2.2 + change (chosenTuple N j:ℝ)≤2*(j:ℝ)*x^nearPower at hk + have hratio : (chosenTuple N j:ℝ)/N≤2*x^(nearPower-1) := by + rw [Real.rpow_sub hxp,Real.rpow_one] + apply (div_le_iff₀ hNp).mpr + rw [←he] + have : 2*(x^nearPower/x)*((j:ℝ)*x)=2*(j:ℝ)*x^nearPower := by field_simp + rw [this] + exact hk + have hpow := Real.rpow_le_rpow (by positivity : (0:ℝ)≤(chosenTuple N j:ℝ)/N) hratio + (by norm_num : (0:ℝ)≤1/512) + have hmain := mul_le_mul hk hpow (by positivity) (by positivity) + have hrpow : (2*x^(nearPower-1))^(1/512:ℝ)= + (2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)) := by + rw [Real.mul_rpow (by norm_num) (by positivity),←Real.rpow_mul hxp.le] + rw [hrpow] at hmain + have heq : 2*(j:ℝ)*x^nearPower*((2:ℝ)^(1/512:ℝ)*x^((nearPower-1)*(1/512)))= + (2:ℝ)^(1+(1/512:ℝ))*(j:ℝ)*x^(-tailPower) := by + rw [Real.rpow_add (by norm_num : (0:ℝ)<2),Real.rpow_one] + have hp : nearPower+(nearPower-1)*(1/512) = -tailPower := by norm_num [nearPower,tailPower] + rw [←hp,Real.rpow_add hxp] + ring + rw [heq] at hmain + have h := mul_le_mul_of_nonneg_left hmain hC + simpa only [mul_assoc] using h + +lemma near_conditions_eventually (C : ℝ) : + ∀ᶠ x : ℝ in atTop, 2≤x ∧ 2≤x^nearPower ∧ x^(nearPower-1)≤1/2 ∧ + 8*Real.log 2/nearPower≤Real.log x ∧ 4*Real.log 2+2≤Real.log x ∧ + C*2^(1+(1/512:ℝ))*x^(-tailPower) ≤ nearFraction/4000 := by + have hpow := (tendsto_rpow_atTop (by norm_num [nearPower] : 0 C*2^(1+(1/512:ℝ))*x^(-tailPower)) atTop (nhds 0) := by + simpa only [mul_zero] using + (tendsto_const_nhds.mul (tendsto_rpow_neg_atTop (by norm_num [tailPower] : 0 ?_) i - · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] - cases x 0 <;> cases ξ (Fin.tail x) <;> rfl - · simp [switchFun, Fin.tail] - -def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := - { toFun := switchFun ξ - invFun := switchFun ξ - left_inv := switchFun_involutive ξ - right_inv := switchFun_involutive ξ } - -def Butterfly : ℕ → Type - | 0 => Unit - | d + 1 => (Card d → Bool) × (Bool → Butterfly d) - -def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where - toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) - invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) - left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] - -def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) - | 0, _ => 1 - | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) - -noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def SwitchIndex : ℕ → Type - | 0 => Empty - | d + 1 => Sum (Card d) (Bool × SwitchIndex d) - -instance (d : ℕ) : Fintype (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (Fintype Empty) - | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) - -instance (d : ℕ) : DecidableEq (SwitchIndex d) := by - induction d with - | zero => exact inferInstanceAs (DecidableEq Empty) - | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) - -def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d - | 0, _ => () - | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => - decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) - -end Thorp - -namespace Thorp.PairRouting -open scoped BigOperators -open Filter -variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] - -noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] - (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by - classical - exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) - -end Thorp.PairRouting - -namespace Thorp.Specht -open scoped BigOperators Classical - -abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} - -def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 - -def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 - -lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := - YoungDiagram.mem_iff_lt_colLen.mp x.2 - -noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := - ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ - -abbrev Tabloid (μ : YoungDiagram) := - {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} - -noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ - -noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ - -noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - Equiv.Perm (Tabloid μ) where - toFun f := ⟨fun x => f.1 (p⁻¹ x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p⁻¹, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - invFun f := ⟨fun x => f.1 (p x), by - obtain ⟨q,hq⟩ := f.2 - refine ⟨q*p, ?_⟩ - funext x - simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ - left_inv f := by apply Subtype.ext; funext x; simp - right_inv f := by apply Subtype.ext; funext x; simp - -@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl - -@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by - ext f x - rfl - -@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : - tabloidAct (p*q) = tabloidAct p * tabloidAct q := by - ext f x - simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] - -noncomputable def tabloidRep (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where - toFun p := - { toFun := fun v f => v (tabloidAct p⁻¹ f) - map_add' := by intros; rfl - map_smul' := by intros; rfl } - map_one' := by ext v f; simp - map_mul' p q := by - ext v f - simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] - rfl - -noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := - fun g => if g=f then 1 else 0 - -noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where - carrier := {p | ∀ x, col (p x) = col x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := - ((Equiv.Perm.sign p : ℤ) : ℂ) - - -section -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by - classical - exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c - -end - -noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := - alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) - -noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := - Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) - -lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ - -lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨q,rfl⟩ := hv - change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ - rw [←map_mul] - exact orbit_mem_space μ (p*q) - | zero => simp - | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw - | smul a v hv ih => simpa using (space μ).smul_mem a ih - -noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := - ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ - -noncomputable def representation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := - (subrepresentation μ).toRepresentation - -end Thorp.Specht - -namespace Thorp.PermutationHilbert -open scoped BigOperators ComplexConjugate Classical -open Complex -variable {X : Type*} [Fintype X] - -abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X - -end Thorp.PermutationHilbert - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def hilbertEquiv (μ : YoungDiagram) : - (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := - (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm - -noncomputable def hilbertSpace (μ : YoungDiagram) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap - -end Thorp.Specht - -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where - toFun g := (ρ g).toContinuousLinearMap - map_one' := by ext v; simp - map_mul' g h := by ext v; simp - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := - (hilbertEquiv μ).submoduleMap (space μ) - -noncomputable def unitaryRepresentation (μ : YoungDiagram) : - Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := - ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := - (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators - -noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) - (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : - Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := - UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) - (fun ω : SwitchIndex d → Bool => if reverse then - (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) - -end Thorp.SparseContact - -namespace Thorp.StrongSmoothing - -def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where - toFun x := fun i => x (order.symm i) - invFun x := fun i => x (order i) - left_inv x := by funext i; simp - right_inv x := by funext i; simp - -def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : - Equiv.Perm (Card d) := - coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * - (coordinateRelabel d order)⁻¹ - -abbrev Tuples (d l : ℕ) := Fin l ↪ Card d - -noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : - Matrix (Tuples d l) (Tuples d l) ℝ := - fun x y => PairRouting.tupleProbability (sweep d order) x y - -noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : - Matrix (Tuples d l) (Tuples d l) ℝ := - let A := sweepKernel d l order - if orientation then A * A.transpose else A.transpose * A - -end Thorp.StrongSmoothing - -namespace Thorp.StrongTail -open scoped BigOperators Classical - -section -open Specht - -def tailDiagram (μ : YoungDiagram) : YoungDiagram := - YoungDiagram.ofRowLens μ.rowLens.tail μ.rowLens_sorted.pairwise.tail.sortedGE - -end -open StrongSmoothing - -def DensityAt (p C : ℝ) : Prop := - ∀ (d l : ℕ), l ≤ 2^d → ∀ (order : Equiv.Perm (Fin d)) (rev : Bool) - (x : StrongSmoothing.Tuples d l), - let H := StrongSmoothing.reflectedKernel d l order rev - (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H x y)^p) - ≤ Real.exp (C*l)) ∧ - (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H y x)^p) - ≤ Real.exp (C*l)) ∧ - (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H x y)^p) ≤ Real.exp (C*l) ∧ - (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H y x)^p) ≤ Real.exp (C*l) - -end Thorp.StrongTail - -namespace Thorp.StrongTail -open scoped BigOperators Classical -open Specht UnitaryFinite - -def MainStatement : Prop := - ∃ p Cdensity C : ℝ, 1 < p ∧ p ≤ 2 ∧ DensityAt p Cdensity ∧ - ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool), - ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ - Real.exp (C*(μ.card-μ.rowLen 0 : ℕ)) * - (Module.finrank ℂ (Specht.space (tailDiagram μ)):ℝ)^(-((p-1)/p)) - -end Thorp.StrongTail - -end ThorpNine.Tail - -end OAI +import Mathlib + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter + +abbrev Card (d : ℕ) := Fin d → Bool + +def switchFun {d : ℕ} (ξ : Card d → Bool) (x : Card (d + 1)) : Card (d + 1) := + Fin.cons (Bool.xor (x 0) (ξ (Fin.tail x))) (Fin.tail x) + +theorem switchFun_involutive {d : ℕ} (ξ : Card d → Bool) : + Function.Involutive (switchFun ξ) := by + intro x + funext i + refine Fin.cases ?_ (fun j => ?_) i + · simp only [switchFun, Fin.cons_zero, Fin.tail_cons] + cases x 0 <;> cases ξ (Fin.tail x) <;> rfl + · simp [switchFun, Fin.tail] + +def pairSwitch {d : ℕ} (ξ : Card d → Bool) : Equiv.Perm (Card (d + 1)) := + { toFun := switchFun ξ + invFun := switchFun ξ + left_inv := switchFun_involutive ξ + right_inv := switchFun_involutive ξ } + +def Butterfly : ℕ → Type + | 0 => Unit + | d + 1 => (Card d → Bool) × (Bool → Butterfly d) + +def childLift {d : ℕ} (p : Bool → Equiv.Perm (Card d)) : Equiv.Perm (Card (d + 1)) where + toFun x := Fin.cons (x 0) (p (x 0) (Fin.tail x)) + invFun x := Fin.cons (x 0) ((p (x 0)).symm (Fin.tail x)) + left_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv x := by simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] + +def butterflyPerm : (d : ℕ) → Butterfly d → Equiv.Perm (Card d) + | 0, _ => 1 + | d + 1, b => pairSwitch b.1 * childLift (fun ε => butterflyPerm d (b.2 ε)) + +noncomputable def finiteMean {Ω : Type*} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def SwitchIndex : ℕ → Type + | 0 => Empty + | d + 1 => Sum (Card d) (Bool × SwitchIndex d) + +instance (d : ℕ) : Fintype (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => exact inferInstanceAs (Fintype (Sum (Card d) (Bool × SwitchIndex d))) + +instance (d : ℕ) : DecidableEq (SwitchIndex d) := by + induction d with + | zero => exact inferInstanceAs (DecidableEq Empty) + | succ d ih => exact inferInstanceAs (DecidableEq (Sum (Card d) (Bool × SwitchIndex d))) + +def decodeButterfly : (d : ℕ) → (SwitchIndex d → Bool) → Butterfly d + | 0, _ => () + | d + 1, ω => (fun y => ω (Sum.inl y), fun ε => + decodeButterfly d (fun i => ω (Sum.inr (ε,i)))) + +end Thorp + +namespace Thorp.PairRouting +open scoped BigOperators +open Filter +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +noncomputable def tupleProbability {Ω β : Type*} [Fintype Ω] [DecidableEq β] + (P : Ω → Equiv.Perm β) (x y : ι → β) : ℝ := by + classical + exact finiteMean (fun ω => if ∀ i, P ω (x i) = y i then 1 else 0) + +end Thorp.PairRouting + +namespace Thorp.Specht +open scoped BigOperators Classical + +abbrev Cell (μ : YoungDiagram) := {x : ℕ × ℕ // x ∈ μ.cells} + +def row {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.1 + +def col {μ : YoungDiagram} (x : Cell μ) : ℕ := x.1.2 + +lemma row_lt_colLen {μ : YoungDiagram} (x : Cell μ) : row x < μ.colLen (col x) := + YoungDiagram.mem_iff_lt_colLen.mp x.2 + +noncomputable def rowIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.colLen 0) := + ⟨row x, (row_lt_colLen x).trans_le (μ.colLen_anti 0 (col x) (Nat.zero_le _))⟩ + +abbrev Tabloid (μ : YoungDiagram) := + {f : Cell μ → Fin (μ.colLen 0) // ∃ p : Equiv.Perm (Cell μ), f = rowIndex ∘ p} + +noncomputable instance (μ : YoungDiagram) : Fintype (Tabloid μ) := Fintype.ofFinite _ + +noncomputable def baseTabloid (μ : YoungDiagram) : Tabloid μ := ⟨rowIndex, 1, rfl⟩ + +noncomputable def tabloidAct {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + Equiv.Perm (Tabloid μ) where + toFun f := ⟨fun x => f.1 (p⁻¹ x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p⁻¹, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + invFun f := ⟨fun x => f.1 (p x), by + obtain ⟨q,hq⟩ := f.2 + refine ⟨q*p, ?_⟩ + funext x + simp only [hq,Function.comp_apply,Equiv.Perm.mul_apply]⟩ + left_inv f := by apply Subtype.ext; funext x; simp + right_inv f := by apply Subtype.ext; funext x; simp + +@[simp] lemma tabloidAct_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (f : Tabloid μ) (x : Cell μ) : (tabloidAct p f).1 x = f.1 (p⁻¹ x) := rfl + +@[simp] lemma tabloidAct_one (μ : YoungDiagram) : tabloidAct (1 : Equiv.Perm (Cell μ)) = 1 := by + ext f x + rfl + +@[simp] lemma tabloidAct_mul {μ : YoungDiagram} (p q : Equiv.Perm (Cell μ)) : + tabloidAct (p*q) = tabloidAct p * tabloidAct q := by + ext f x + simp only [tabloidAct_apply, mul_inv_rev,Equiv.Perm.mul_apply] + +noncomputable def tabloidRep (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (Tabloid μ → ℂ) where + toFun p := + { toFun := fun v f => v (tabloidAct p⁻¹ f) + map_add' := by intros; rfl + map_smul' := by intros; rfl } + map_one' := by ext v f; simp + map_mul' p q := by + ext v f + simp only [mul_inv_rev,tabloidAct_mul,Equiv.Perm.mul_apply] + rfl + +noncomputable def delta {μ : YoungDiagram} (f : Tabloid μ) : Tabloid μ → ℂ := + fun g => if g=f then 1 else 0 + +noncomputable def colGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) where + carrier := {p | ∀ x, col (p x) = col x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +noncomputable def permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : ℂ := + ((Equiv.Perm.sign p : ℤ) : ℂ) + + +section +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := by + classical + exact ∑ c : C, permSign (c : Equiv.Perm α) • ρ c + +end + +noncomputable def polytabloid (μ : YoungDiagram) : Tabloid μ → ℂ := + alternator (colGroup μ) (tabloidRep μ) (delta (baseTabloid μ)) + +noncomputable def space (μ : YoungDiagram) : Submodule ℂ (Tabloid μ → ℂ) := + Submodule.span ℂ (Set.range (fun p : Equiv.Perm (Cell μ) => tabloidRep μ p (polytabloid μ))) + +lemma orbit_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + tabloidRep μ p (polytabloid μ) ∈ space μ := Submodule.subset_span ⟨p,rfl⟩ + +lemma action_mem_space (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : tabloidRep μ p v ∈ space μ := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨q,rfl⟩ := hv + change ((tabloidRep μ p)*(tabloidRep μ q)) (polytabloid μ) ∈ space μ + rw [←map_mul] + exact orbit_mem_space μ (p*q) + | zero => simp + | add v w hv hw ihv ihw => simpa using (space μ).add_mem ihv ihw + | smul a v hv ih => simpa using (space μ).smul_mem a ih + +noncomputable def subrepresentation (μ : YoungDiagram) : Subrepresentation (tabloidRep μ) := + ⟨space μ, fun p v hv => action_mem_space μ p v hv⟩ + +noncomputable def representation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (space μ) := + (subrepresentation μ).toRepresentation + +end Thorp.Specht + +namespace Thorp.PermutationHilbert +open scoped BigOperators ComplexConjugate Classical +open Complex +variable {X : Type*} [Fintype X] + +abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X + +end Thorp.PermutationHilbert + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def hilbertEquiv (μ : YoungDiagram) : + (Tabloid μ → ℂ) ≃ₗ[ℂ] PermutationHilbert.H (Tabloid μ) := + (WithLp.linearEquiv 2 ℂ (Tabloid μ → ℂ)).symm + +noncomputable def hilbertSpace (μ : YoungDiagram) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) := (space μ).map (hilbertEquiv μ).toLinearMap + +end Thorp.Specht + +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where + toFun g := (ρ g).toContinuousLinearMap + map_one' := by ext v; simp + map_mul' g h := by ext v; simp + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def spaceHilbertEquiv (μ : YoungDiagram) : space μ ≃ₗ[ℂ] hilbertSpace μ := + (hilbertEquiv μ).submoduleMap (space μ) + +noncomputable def unitaryRepresentation (μ : YoungDiagram) : + Representation ℂ (Equiv.Perm (Cell μ)) (hilbertSpace μ) := + ((spaceHilbertEquiv μ).conjAlgEquiv ℂ).toMonoidHom.comp (representation μ) + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +noncomputable def relabelledUnitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation ℂ (Equiv.Perm α) (hilbertSpace μ) := + (unitaryRepresentation μ).comp e.permCongrHom.toMonoidHom + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators + +noncomputable def sweepOperator (d : ℕ) (μ : YoungDiagram) + (e : Card d ≃ Specht.Cell μ) (reverse : Bool) : + Specht.hilbertSpace μ →L[ℂ] Specht.hilbertSpace μ := + UnitaryFinite.sampleOperator (V := Specht.hilbertSpace μ) (Specht.relabelledUnitary μ e) + (fun ω : SwitchIndex d → Bool => if reverse then + (butterflyPerm d (decodeButterfly d ω))⁻¹ else butterflyPerm d (decodeButterfly d ω)) + +end Thorp.SparseContact + +namespace Thorp.StrongSmoothing + +def coordinateRelabel (d : ℕ) (order : Equiv.Perm (Fin d)) : Equiv.Perm (Card d) where + toFun x := fun i => x (order.symm i) + invFun x := fun i => x (order i) + left_inv x := by funext i; simp + right_inv x := by funext i; simp + +def sweep (d : ℕ) (order : Equiv.Perm (Fin d)) (ω : SwitchIndex d → Bool) : + Equiv.Perm (Card d) := + coordinateRelabel d order * butterflyPerm d (decodeButterfly d ω) * + (coordinateRelabel d order)⁻¹ + +abbrev Tuples (d l : ℕ) := Fin l ↪ Card d + +noncomputable def sweepKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) : + Matrix (Tuples d l) (Tuples d l) ℝ := + fun x y => PairRouting.tupleProbability (sweep d order) x y + +noncomputable def reflectedKernel (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) : + Matrix (Tuples d l) (Tuples d l) ℝ := + let A := sweepKernel d l order + if orientation then A * A.transpose else A.transpose * A + +end Thorp.StrongSmoothing + +namespace Thorp.StrongTail +open scoped BigOperators Classical + +section +open Specht + +def tailDiagram (μ : YoungDiagram) : YoungDiagram := + YoungDiagram.ofRowLens μ.rowLens.tail μ.rowLens_sorted.pairwise.tail.sortedGE + +end +open StrongSmoothing + +def DensityAt (p C : ℝ) : Prop := + ∀ (d l : ℕ), l ≤ 2^d → ∀ (order : Equiv.Perm (Fin d)) (rev : Bool) + (x : StrongSmoothing.Tuples d l), + let H := StrongSmoothing.reflectedKernel d l order rev + (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H x y)^p) + ≤ Real.exp (C*l)) ∧ + (Thorp.finiteMean (fun y => ((Fintype.card (StrongSmoothing.Tuples d l):ℝ)*H y x)^p) + ≤ Real.exp (C*l)) ∧ + (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H x y)^p) ≤ Real.exp (C*l) ∧ + (((2:ℝ)^d)^l)⁻¹ * (∑ y, ((((2:ℝ)^d)^l)*H y x)^p) ≤ Real.exp (C*l) + +end Thorp.StrongTail + +namespace Thorp.StrongTail +open scoped BigOperators Classical +open Specht UnitaryFinite + +def MainStatement : Prop := + ∃ p Cdensity C : ℝ, 1 < p ∧ p ≤ 2 ∧ DensityAt p Cdensity ∧ + ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Specht.Cell μ) (rev : Bool), + ‖SparseContact.sweepOperator d μ e rev‖^2 ≤ + Real.exp (C*(μ.card-μ.rowLen 0 : ℕ)) * + (Module.finrank ℂ (Specht.space (tailDiagram μ)):ℝ)^(-((p-1)/p)) + +end Thorp.StrongTail + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedReverseEquiv.lean b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedReverseEquiv.lean index dff6e00a2aaed8360aa6c1da1d0a1a4992e4a7ae..fa1f4c5243702e29b44a40d97d98f9122a566ee5 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedReverseEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedReverseEquiv.lean @@ -1,759 +1,759 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ModifiedRoutingMoment - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where - toFun := modifiedReverseCoins L r - invFun := modifiedReverseCoins L r - left_inv := modifiedReverseCoins_involutive L r - right_inv := modifiedReverseCoins_involutive L r - -lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : - modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by - induction r with - | zero => - rw [modifiedPerm_zero,modifiedPerm_zero] - split_ifs - · simp only [inv_one] - · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp - | succ r ih => - obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω - rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, - mul_inv_rev,pairSwitch_inv,childLift_inv] - rw [mul_assoc] - congr 1 - congr 1 - apply congrArg childLift - funext b - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] - -lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : - PairRouting.tupleProbability (modifiedPerm L r E) e f = - PairRouting.tupleProbability (modifiedPerm L r E) f e := - PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) - (modifiedPerm_reverse L r E) e f - -end Thorp - -namespace Thorp.Specht -open scoped BigOperators Classical - -@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by - simp [Cell, YoungDiagram.card] - -noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : - {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where - toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ - invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm - right_inv i := by rfl - -noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := - (Finset.univ.filter (fun x => col x = j)).image f - -lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : - f x ∈ columnValues f (col x) := by - classical - exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ - -lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : - (columnValues f j).card = μ.colLen j := by - classical - rw [columnValues, Finset.card_image_iff.mpr] - · rw [← Fintype.card_subtype] - exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) - intro x hx y hy he - exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he - -lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : - ∀ i, i.val ≤ f i := by - intro i - induction h : i.val using Nat.strong_induction_on generalizing i with - | h n ih => - by_cases hn : n = 0 - · omega - · have hn' : n-1 < i.val := by omega - let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ - have hj := ih (n-1) (by omega) j rfl - have hij := hf (show j < i from hn') - dsimp [j] at hj hij - omega - -noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := - let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩ - ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ - -@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - col (rankCell f hf x) = col x := rfl - -lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by - change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) - (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm - ⟨f x, mem_columnValues f x⟩)).val = f x - simp - -lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : - Function.Injective (rankCell f hf) := by - intro x y h - have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h - apply hf x y hc - have hx := rankCell_orderEmb f hf x - have hy := rankCell_orderEmb f hf y - change (columnValues f (col (rankCell f hf x))).orderEmbOfFin - (card_columnValues f hf (col (rankCell f hf x))) - ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx - rw [h] at hx - exact hx.symm.trans hy - -noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := - Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) - -lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) - (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : - row (rankCell f hf x) ≤ f x := by - rw [←rankCell_orderEmb f hf x] - exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ - -theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : - ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ - ∀ x, row (c x) = row (p x) := by - classical - let c := rankPerm (fun x => row (p x)) hp - refine ⟨c, fun x => rfl, ?_⟩ - have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x - have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by - rw [Equiv.sum_comp, Equiv.sum_comp] - exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) - - -@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by - ext f x - simp [tabloidAct,Equiv.Perm.inv_def] - -@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) - (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl - -lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tabloidRep μ p (delta f) = delta (tabloidAct p f) := by - classical - ext g - simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] - congr 1 - exact propext (Equiv.symm_apply_eq (tabloidAct p)) - -@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : - p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl - -lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) - (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by - apply Equiv.ext - intro x - have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc - simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr - apply Subtype.ext - exact Prod.ext hr.symm (c.2 x) - -lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) - (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : - ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by - obtain ⟨p,hp⟩ := f.2 - have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by - intro x y hcol hrow - apply hf x y hcol - rw [hp] - exact Fin.ext hrow - obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' - refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ - apply Subtype.ext - funext x - apply Fin.ext - simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] - exact (hrow x).symm - - -@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : - permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] -@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : - permSign (p*q) = permSign p * permSign q := by simp [permSign] -@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] -lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - permSign p * permSign p = 1 := by - calc - permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] - _ = 1 := by simp -@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : - permSign (Equiv.swap x y) = -1 := by simp [permSign, h] -@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : - starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] - -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -lemma alternator_mul (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.sum_mul,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulRight c) - intro a - simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring - _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] - _ = _ := by ring - -lemma mul_alternator (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : - ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by - classical - rw [alternator,Finset.mul_sum,Finset.smul_sum] - apply Fintype.sum_equiv (Equiv.mulLeft c) - intro a - simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] - congr 1 - have h := permSign_sq (c : Equiv.Perm α) - calc - permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring - _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] - _ = _ := by ring - -lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) - -lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : - ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by - exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) - -lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) - (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : - alternator C ρ v = 0 := by - have h := alternator_apply_action C ρ c v - rw [hv,hc,neg_one_smul] at h - have h2 : (2:ℂ) • alternator C ρ v = 0 := by - rw [two_smul] - nth_rw 1 [h] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -end Thorp.Specht -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : - Equiv.swap x y ∈ colGroup μ := by - classical - intro z - by_cases hx : z=x - · subst z; simpa using hc.symm - by_cases hy : z=y - · subst z; simpa using hc - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) - (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by - classical - apply Subtype.ext - funext z - simp only [tabloidAct_apply, Equiv.swap_inv] - by_cases hx : z=x - · subst z; simpa using hxy.symm - by_cases hy : z=y - · subst z; simpa using hxy - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by - classical - by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y - · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf - refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ - rw [←tabloidRep_delta] - exact alternator_apply_action _ _ c _ - · push Not at hf - obtain ⟨x,y,hcol,hrow,hne⟩ := hf - refine ⟨0, ?_⟩ - rw [zero_smul] - apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ - · exact permSign_swap hne - · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] - -lemma polytabloid_formula (μ : YoungDiagram) : - polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • - delta (tabloidAct c (baseTabloid μ)) := by - classical - simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] - -lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by - classical - rw [polytabloid_formula,Finset.sum_apply] - rw [Finset.sum_eq_single (1 : colGroup μ)] - · simp [delta] - · intro c hc hne - have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by - intro h - apply hne - exact Subtype.ext (colGroup_row_stabilizer c h.symm) - simp [Pi.smul_apply,delta,hn] - · simp - -lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by - intro h - have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp [polytabloid_base] at hv - -lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - v = ∑ f : Tabloid μ, v f • delta f := by - classical - funext g - simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] - simp - -theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by - classical - choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f - refine ⟨∑ f, v f * z f, ?_⟩ - conv_lhs => rw [delta_decomposition v] - simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] - -lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = - (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by - obtain ⟨z,hz⟩ := alternator_rank_one μ v - rw [hz] - simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] - - -noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := - ∑ f, w f * starRingEnd ℂ (v f) - -lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : - pairing (delta f) v = v f := by - classical - simp [pairing,delta] - -lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] - (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : - pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by - simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] - exact Finset.sum_comm - -lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : - pairing (a • v) w = starRingEnd ℂ a * pairing v w := by - simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] - apply Finset.sum_congr rfl - intro f hf - ring - -lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by - simp [pairing] - -lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : - pairing (u+v) w = pairing u w + pairing v w := by - simp [pairing,mul_add,Finset.sum_add_distrib] - -lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : - pairing v v = 0 ↔ v = 0 := by - change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 - rw [inner_self_eq_zero] - constructor - · intro h; exact congrArg WithLp.ofLp h - · intro h; subst v; rfl - -lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : - pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by - classical - simp only [pairing,tabloidRep_apply,inv_inv] - apply Fintype.sum_equiv (tabloidAct p⁻¹) - intro f - have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by - rw [tabloidAct_inv] - exact (tabloidAct p).apply_symm_apply f - rw [hcancel] - -lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by - classical - simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, - smul_eq_mul,tabloidRep_apply] - apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) - intro c - simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] - -theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : - alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by - rw [alternator_rank_one_exact,alternator_base_pairing] - - -lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by - simpa using orbit_mem_space μ 1 - -lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : - alternator (colGroup μ) (tabloidRep μ) v ∈ W := by - classical - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] - exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) - -theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : - space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by - classical - by_cases hSW : space μ ≤ W - · exact Or.inl hSW - right - have he : polytabloid μ ∉ W := by - intro he - apply hSW - apply Submodule.span_le.mpr - rintro _ ⟨p,rfl⟩ - exact hW p _ he - have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by - intro v hv - by_contra hne - apply he - have hal := alternator_mem_invariant μ W hW v hv - rw [alternator_pairing] at hal - have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal - simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh - intro v hv w hw - induction hw using Submodule.span_induction with - | mem w hw => - obtain ⟨p,rfl⟩ := hw - rw [pairing_action] - exact hpair _ (hW p⁻¹ v hv) - | zero => exact pairing_zero_left v - | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] - | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] - -theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) - (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : - W = ⊥ ∨ W = space μ := by - obtain hSW | horth := submodule_theorem μ W hW - · exact Or.inr (le_antisymm hWS hSW) - · left - apply le_antisymm _ bot_le - intro v hv - exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) - - -lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by - intro h - have he := polytabloid_mem_space μ - rw [h,Submodule.mem_bot] at he - exact polytabloid_ne_zero μ he - -theorem representation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (representation μ) := by - have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ - (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial - have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he - exact polytabloid_ne_zero μ (congrArg Subtype.val he') - refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } - intro U - let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype - have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by - intro p v hv - obtain ⟨u,hu,rfl⟩ := hv - exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ - have hWS : W ≤ space μ := by - intro v hv - obtain ⟨u,hu,rfl⟩ := hv - exact u.2 - obtain hbot | htop := space_simple μ W hW hWS - · left - apply le_antisymm _ bot_le - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ - rw [hbot,Submodule.mem_bot] at hmem - change u = 0 - exact Subtype.ext hmem - · right - apply le_antisymm le_top - intro u hu - have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 - obtain ⟨v,hv,hvu⟩ := hmem - have heq : v = u := Subtype.ext hvu - exact heq ▸ hv - - -section Symmetrizer -variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] - -noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := - ∑ h : H, ρ h - -lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : - symmetrizer H ρ * ρ h = symmetrizer H ρ := by - rw [symmetrizer,Finset.sum_mul] - exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) - -lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) - (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : - symmetrizer H ρ v = 0 := by - have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) - change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh - rw [hv,map_neg] at hh - have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by - rw [two_smul] - nth_rw 1 [←hh] - exact neg_add_cancel _ - exact (smul_eq_zero.mp h2).resolve_left (by norm_num) - -noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x, f (p x) = f x} - one_mem' := by intro x; rfl - mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) - inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm - -omit [Fintype α] in -lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : - Equiv.swap x y ∈ fiberGroup f := by - intro z - by_cases hx : z=x - · subst z; simpa using hf.symm - by_cases hy : z=y - · subst z; simpa using hf - simp [Equiv.swap_apply_of_ne_of_ne hx hy] - -end Symmetrizer - -lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) - (hcol : col x = col y) : - tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by - have h := action_alternator_apply (colGroup μ) (tabloidRep μ) - ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) - simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h - -theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] - (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) - (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : - symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by - rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - exact hj - obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ - apply symmetrizer_eq_zero_of_neg _ _ h - change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) - rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] - rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - - -noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : - {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where - toFun x := ⟨col x.1, by - have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 - change col x.1 < μ.rowLen (row x.1) at h - simpa only [x.2] using h⟩ - invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ - left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl - right_inv j := rfl - -def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x - -lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (he : ∀ x, row (e x) = row x) : μ = ν := by - have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by - let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := - { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ - invFun := fun x => ⟨e.symm x.1,by - have h := he (e.symm x.1) - simp only [Equiv.apply_symm_apply] at h - exact h.symm.trans x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } - simpa only [Fintype.card_fin] using Fintype.card_congr - ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) - apply YoungDiagram.ext - ext ⟨i,j⟩ - simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] - -lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - let c := rankPerm (fun x => row (e x)) h - have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x - have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ - have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ - constructor - · rw [←hsumc,←hsume] - exact Finset.sum_le_sum (fun x _ => hle x) - · intro heq - have he : ∀ x, row (c x) = row (e x) := by - apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp - (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) - apply eq_of_row_preserving μ ν (c.symm.trans e) - intro x - simpa using (he (c.symm x)).symm - -lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] - (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by - ext z - simp only [Equiv.permCongr_apply] - exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) - -lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (v : Tabloid ν → ℂ) (hv : v ≠ 0) - (hs : ∀ c : colGroup μ, - tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : - rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by - obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by - by_contra h - push Not at h - exact hv (funext h) - obtain ⟨p,hp⟩ := f.2 - apply column_injective_rowCost μ ν (e.trans p) - intro x y hcol hrow - by_contra hne - have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by - apply swap_fixes_tabloid - rw [hp] - exact Fin.ext hrow - have heq := congrArg (fun w : Tabloid ν → ℂ => w f) - (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) - rw [swap_relabel,permSign_swap hne] at heq - simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq - apply hf - have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq - exact (mul_eq_zero.mp h2).resolve_left (by norm_num) - -lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : - tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply _ _ c _ - -theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) - (T : space μ ≃ₗ[ℂ] space ν) - (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : - μ = ν := by - let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ - have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) - have hTcol (c : colGroup μ) : - tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by - change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ - rw [←hT] - have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := - Subtype.ext (polytabloid_col_action μ c) - rw [hh,map_smul] - rfl - have hfwd := sign_vector_rowCost μ ν e (T u) - (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol - let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ - have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) - have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : - T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by - apply T.injective - rw [T.apply_symm_apply,hT,T.apply_symm_apply] - have hp : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] - have hTicol (c : colGroup ν) : - tabloidRep μ (e.symm.permCongr c) (T.symm w) = - permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by - change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ - rw [←hTi] - have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := - Subtype.ext (polytabloid_col_action ν c) - rw [hh,map_smul] - rfl - have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) - (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol - exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) - - -noncomputable def cellRowsEquiv (μ : YoungDiagram) : - Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where - toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ - invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ - left_inv x := by apply Subtype.ext; rfl - right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl - -lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by - rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] - simp only [Fintype.card_fin] - -lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by - rw [card_eq_sum_rowLen,YoungDiagram.rowLens] - rw [Fin.sum_univ_eq_sum_range] - have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by - induction n with - | zero => simp - | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] - exact hh _ - -noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where - parts := μ.rowLens - parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simp - -noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := - YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE - -lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : - (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by - apply YoungDiagram.rowLens_ofRowLens_eq_self - intro x hx - exact p.parts_pos ((Multiset.mem_sort _).mp hx) - -lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by - rw [←sum_rowLens,partitionDiagram_rowLens] - change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N - rw [Multiset.sort_eq,p.parts_sum] - -lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : - partitionDiagram (diagramPartition μ) = μ := by - apply YoungDiagram.equivListRowLens.injective - apply Subtype.ext - change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens - rw [partitionDiagram_rowLens] - change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens - rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] - -abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} - -end Thorp.Specht - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ModifiedRoutingMoment + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +noncomputable def modifiedReverseEquiv (L r : ℕ) : Equiv.Perm (ModifiedCoins L r) where + toFun := modifiedReverseCoins L r + invFun := modifiedReverseCoins L r + left_inv := modifiedReverseCoins_involutive L r + right_inv := modifiedReverseCoins_involutive L r + +lemma modifiedPerm_reverse (L r : ℕ) (E : Finset (Card r)) (ω : ModifiedCoins L r) : + modifiedPerm L r E (modifiedReverseCoins L r ω) = (modifiedPerm L r E ω)⁻¹ := by + induction r with + | zero => + rw [modifiedPerm_zero,modifiedPerm_zero] + split_ifs + · simp only [inv_one] + · simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp + | succ r ih => + obtain ⟨z,rfl⟩ := (modifiedStepEquiv L r).symm.surjective ω + rcases z with ⟨⟨ω₀,ω₁⟩,⟨ξ,η⟩⟩ + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,modifiedPerm_step, + mul_inv_rev,pairSwitch_inv,childLift_inv] + rw [mul_assoc] + congr 1 + congr 1 + apply congrArg childLift + funext b + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,ih] + +lemma modified_kernel_symmetric (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) : + PairRouting.tupleProbability (modifiedPerm L r E) e f = + PairRouting.tupleProbability (modifiedPerm L r E) f e := + PairRouting.tupleProbability_symmetric _ (modifiedReverseEquiv L r) + (modifiedPerm_reverse L r E) e f + +end Thorp + +namespace Thorp.Specht +open scoped BigOperators Classical + +@[simp] lemma card_cell (μ : YoungDiagram) : Fintype.card (Cell μ) = μ.card := by + simp [Cell, YoungDiagram.card] + +noncomputable def columnEquiv (μ : YoungDiagram) (j : ℕ) : + {x : Cell μ // col x = j} ≃ Fin (μ.colLen j) where + toFun x := ⟨row x.1, by simpa [x.2] using row_lt_colLen x.1⟩ + invFun i := ⟨⟨(i,j), YoungDiagram.mem_iff_lt_colLen.mpr i.2⟩, rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.2.symm + right_inv i := by rfl + +noncomputable def columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (j : ℕ) : Finset ℕ := + (Finset.univ.filter (fun x => col x = j)).image f + +lemma mem_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) (x : Cell μ) : + f x ∈ columnValues f (col x) := by + classical + exact Finset.mem_image.mpr ⟨x, by simp, rfl⟩ + +lemma card_columnValues {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (j : ℕ) : + (columnValues f j).card = μ.colLen j := by + classical + rw [columnValues, Finset.card_image_iff.mpr] + · rw [← Fintype.card_subtype] + exact Fintype.card_congr (columnEquiv μ j) |>.trans (Fintype.card_fin _) + intro x hx y hy he + exact hf x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) he + +lemma strictMono_fin_nat_ge {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) : + ∀ i, i.val ≤ f i := by + intro i + induction h : i.val using Nat.strong_induction_on generalizing i with + | h n ih => + by_cases hn : n = 0 + · omega + · have hn' : n-1 < i.val := by omega + let j : Fin _ := ⟨n-1, hn'.trans i.isLt⟩ + have hj := ih (n-1) (by omega) j rfl + have hij := hf (show j < i from hn') + dsimp [j] at hj hij + omega + +noncomputable def rankCell {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : Cell μ := + let k := ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩ + ⟨(k.val,col x), YoungDiagram.mem_iff_lt_colLen.mpr k.isLt⟩ + +@[simp] lemma rankCell_col {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + col (rankCell f hf x) = col x := rfl + +lemma rankCell_orderEmb {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + (columnValues f (col x)).orderEmbOfFin (card_columnValues f hf (col x)) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x := by + change ((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x)) + (((columnValues f (col x)).orderIsoOfFin (card_columnValues f hf (col x))).symm + ⟨f x, mem_columnValues f x⟩)).val = f x + simp + +lemma rankCell_injective {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : + Function.Injective (rankCell f hf) := by + intro x y h + have hc : col x = col y := by simpa only [rankCell_col] using congrArg (fun z : Cell μ => col z) h + apply hf x y hc + have hx := rankCell_orderEmb f hf x + have hy := rankCell_orderEmb f hf y + change (columnValues f (col (rankCell f hf x))).orderEmbOfFin + (card_columnValues f hf (col (rankCell f hf x))) + ⟨row (rankCell f hf x), row_lt_colLen (rankCell f hf x)⟩ = f x at hx + rw [h] at hx + exact hx.symm.trans hy + +noncomputable def rankPerm {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) : Equiv.Perm (Cell μ) := + Equiv.ofBijective (rankCell f hf) ((Finite.injective_iff_bijective).mp (rankCell_injective f hf)) + +lemma rankCell_row_le {μ : YoungDiagram} (f : Cell μ → ℕ) + (hf : ∀ x y, col x = col y → f x = f y → x = y) (x : Cell μ) : + row (rankCell f hf x) ≤ f x := by + rw [←rankCell_orderEmb f hf x] + exact strictMono_fin_nat_ge _ (OrderEmbedding.strictMono _) _ + +theorem column_transporter (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x y, col x = col y → row (p x) = row (p y) → x = y) : + ∃ c : Equiv.Perm (Cell μ), (∀ x, col (c x) = col x) ∧ + ∀ x, row (c x) = row (p x) := by + classical + let c := rankPerm (fun x => row (p x)) hp + refine ⟨c, fun x => rfl, ?_⟩ + have hle (x : Cell μ) : row (c x) ≤ row (p x) := rankCell_row_le _ hp x + have hsum : ∑ x, row (c x) = ∑ x, row (p x) := by + rw [Equiv.sum_comp, Equiv.sum_comp] + exact fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp hsum x (Finset.mem_univ _) + + +@[simp] lemma tabloidAct_inv {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + tabloidAct p⁻¹ = (tabloidAct p)⁻¹ := by + ext f x + simp [tabloidAct,Equiv.Perm.inv_def] + +@[simp] lemma tabloidRep_apply {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) + (v : Tabloid μ → ℂ) (f : Tabloid μ) : tabloidRep μ p v f = v (tabloidAct p⁻¹ f) := rfl + +lemma tabloidRep_delta {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tabloidRep μ p (delta f) = delta (tabloidAct p f) := by + classical + ext g + simp only [tabloidRep_apply,delta,Equiv.Perm.inv_def] + congr 1 + exact propext (Equiv.symm_apply_eq (tabloidAct p)) + +@[simp] lemma mem_colGroup {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) : + p ∈ colGroup μ ↔ ∀ x, col (p x) = col x := Iff.rfl + +lemma colGroup_row_stabilizer {μ : YoungDiagram} (c : colGroup μ) + (hc : tabloidAct c (baseTabloid μ) = baseTabloid μ) : (c : Equiv.Perm (Cell μ)) = 1 := by + apply Equiv.ext + intro x + have hr := congrArg (fun f : Tabloid μ => ((f.1 ((c : Equiv.Perm _) x)) : ℕ)) hc + simp only [tabloidAct_apply,Equiv.Perm.inv_def,Equiv.symm_apply_apply,baseTabloid,rowIndex] at hr + apply Subtype.ext + exact Prod.ext hr.symm (c.2 x) + +lemma tabloid_column_transporter {μ : YoungDiagram} (f : Tabloid μ) + (hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y) : + ∃ c : colGroup μ, f = tabloidAct c (baseTabloid μ) := by + obtain ⟨p,hp⟩ := f.2 + have hp' : ∀ x y, col x = col y → row (p x) = row (p y) → x = y := by + intro x y hcol hrow + apply hf x y hcol + rw [hp] + exact Fin.ext hrow + obtain ⟨c,hcol,hrow⟩ := column_transporter μ p hp' + refine ⟨⟨c⁻¹, (colGroup μ).inv_mem hcol⟩, ?_⟩ + apply Subtype.ext + funext x + apply Fin.ext + simp only [tabloidAct_apply,baseTabloid,rowIndex,inv_inv,hp,Function.comp_apply] + exact (hrow x).symm + + +@[simp] lemma permSign_one {α : Type*} [Fintype α] [DecidableEq α] : + permSign (1 : Equiv.Perm α) = 1 := by simp [permSign] +@[simp] lemma permSign_mul {α : Type*} [Fintype α] [DecidableEq α] (p q : Equiv.Perm α) : + permSign (p*q) = permSign p * permSign q := by simp [permSign] +@[simp] lemma permSign_inv {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p⁻¹ = permSign p := by simp [permSign,Equiv.Perm.inv_def] +lemma permSign_sq {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + permSign p * permSign p = 1 := by + calc + permSign p * permSign p = permSign (p*p⁻¹) := by rw [permSign_mul,permSign_inv] + _ = 1 := by simp +@[simp] lemma permSign_swap {α : Type*} [Fintype α] [DecidableEq α] {x y : α} (h : x ≠ y) : + permSign (Equiv.swap x y) = -1 := by simp [permSign, h] +@[simp] lemma conj_permSign {α : Type*} [Fintype α] [DecidableEq α] (p : Equiv.Perm α) : + starRingEnd ℂ (permSign p) = permSign p := by simp [permSign] + +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +lemma alternator_mul (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + alternator C ρ * ρ c = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.sum_mul,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulRight c) + intro a + simp only [smul_mul_assoc,←map_mul,Equiv.coe_mulRight,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = permSign (a : Equiv.Perm α)*1 := by ring + _ = permSign (a : Equiv.Perm α)*(permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α)) := by rw [h] + _ = _ := by ring + +lemma mul_alternator (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) : + ρ c * alternator C ρ = permSign (c : Equiv.Perm α) • alternator C ρ := by + classical + rw [alternator,Finset.mul_sum,Finset.smul_sum] + apply Fintype.sum_equiv (Equiv.mulLeft c) + intro a + simp only [mul_smul_comm,←map_mul,Equiv.coe_mulLeft,Subgroup.coe_mul,permSign_mul,smul_smul] + congr 1 + have h := permSign_sq (c : Equiv.Perm α) + calc + permSign (a : Equiv.Perm α) = 1*permSign (a : Equiv.Perm α) := by ring + _ = (permSign (c : Equiv.Perm α)*permSign (c : Equiv.Perm α))*permSign (a : Equiv.Perm α) := by rw [h] + _ = _ := by ring + +lemma alternator_apply_action (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + alternator C ρ (ρ c v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (alternator_mul C ρ c) + +lemma action_alternator_apply (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) : + ρ c (alternator C ρ v) = permSign (c : Equiv.Perm α) • alternator C ρ v := by + exact congrArg (fun T : Module.End ℂ V => T v) (mul_alternator C ρ c) + +lemma alternator_eq_zero_of_odd_stabilizer (C : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (c : C) (v : V) + (hc : permSign (c : Equiv.Perm α) = -1) (hv : ρ c v = v) : + alternator C ρ v = 0 := by + have h := alternator_apply_action C ρ c v + rw [hv,hc,neg_one_smul] at h + have h2 : (2:ℂ) • alternator C ρ v = 0 := by + rw [two_smul] + nth_rw 1 [h] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +end Thorp.Specht +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma swap_mem_colGroup {μ : YoungDiagram} (x y : Cell μ) (hc : col x = col y) : + Equiv.swap x y ∈ colGroup μ := by + classical + intro z + by_cases hx : z=x + · subst z; simpa using hc.symm + by_cases hy : z=y + · subst z; simpa using hc + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma swap_fixes_tabloid {μ : YoungDiagram} (f : Tabloid μ) (x y : Cell μ) + (hxy : f.1 x = f.1 y) : tabloidAct (Equiv.swap x y) f = f := by + classical + apply Subtype.ext + funext z + simp only [tabloidAct_apply, Equiv.swap_inv] + by_cases hx : z=x + · subst z; simpa using hxy.symm + by_cases hy : z=y + · subst z; simpa using hxy + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +lemma alternator_delta_rank_one {μ : YoungDiagram} (f : Tabloid μ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) (delta f) = z • polytabloid μ := by + classical + by_cases hf : ∀ x y, col x = col y → f.1 x = f.1 y → x = y + · obtain ⟨c,rfl⟩ := tabloid_column_transporter f hf + refine ⟨permSign (c:Equiv.Perm (Cell μ)), ?_⟩ + rw [←tabloidRep_delta] + exact alternator_apply_action _ _ c _ + · push Not at hf + obtain ⟨x,y,hcol,hrow,hne⟩ := hf + refine ⟨0, ?_⟩ + rw [zero_smul] + apply alternator_eq_zero_of_odd_stabilizer _ _ ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ + · exact permSign_swap hne + · rw [tabloidRep_delta,swap_fixes_tabloid f x y hrow] + +lemma polytabloid_formula (μ : YoungDiagram) : + polytabloid μ = ∑ c : colGroup μ, permSign (c:Equiv.Perm (Cell μ)) • + delta (tabloidAct c (baseTabloid μ)) := by + classical + simp only [polytabloid,alternator,LinearMap.sum_apply,LinearMap.smul_apply,tabloidRep_delta] + +lemma polytabloid_base (μ : YoungDiagram) : polytabloid μ (baseTabloid μ) = 1 := by + classical + rw [polytabloid_formula,Finset.sum_apply] + rw [Finset.sum_eq_single (1 : colGroup μ)] + · simp [delta] + · intro c hc hne + have hn : baseTabloid μ ≠ tabloidAct c (baseTabloid μ) := by + intro h + apply hne + exact Subtype.ext (colGroup_row_stabilizer c h.symm) + simp [Pi.smul_apply,delta,hn] + · simp + +lemma polytabloid_ne_zero (μ : YoungDiagram) : polytabloid μ ≠ 0 := by + intro h + have hv := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp [polytabloid_base] at hv + +lemma delta_decomposition {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + v = ∑ f : Tabloid μ, v f • delta f := by + classical + funext g + simp only [Finset.sum_apply,Pi.smul_apply,delta,smul_eq_mul,mul_ite,mul_one,mul_zero] + simp + +theorem alternator_rank_one (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + ∃ z : ℂ, alternator (colGroup μ) (tabloidRep μ) v = z • polytabloid μ := by + classical + choose z hz using fun f : Tabloid μ => alternator_delta_rank_one f + refine ⟨∑ f, v f * z f, ?_⟩ + conv_lhs => rw [delta_decomposition v] + simp only [map_sum,map_smul,hz,smul_smul,Finset.sum_smul] + +lemma alternator_rank_one_exact (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = + (alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ)) • polytabloid μ := by + obtain ⟨z,hz⟩ := alternator_rank_one μ v + rw [hz] + simp only [Pi.smul_apply,polytabloid_base,smul_eq_mul,mul_one] + + +noncomputable def pairing {μ : YoungDiagram} (v w : Tabloid μ → ℂ) : ℂ := + ∑ f, w f * starRingEnd ℂ (v f) + +lemma pairing_delta {μ : YoungDiagram} (f : Tabloid μ) (v : Tabloid μ → ℂ) : + pairing (delta f) v = v f := by + classical + simp [pairing,delta] + +lemma pairing_sum_left {μ : YoungDiagram} {ι : Type*} [Fintype ι] + (v : ι → Tabloid μ → ℂ) (w : Tabloid μ → ℂ) : + pairing (∑ i, v i) w = ∑ i, pairing (v i) w := by + simp only [pairing,Finset.sum_apply,map_sum,Finset.mul_sum] + exact Finset.sum_comm + +lemma pairing_smul_left {μ : YoungDiagram} (a : ℂ) (v w : Tabloid μ → ℂ) : + pairing (a • v) w = starRingEnd ℂ a * pairing v w := by + simp only [pairing,Pi.smul_apply,smul_eq_mul,map_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro f hf + ring + +lemma pairing_zero_left {μ : YoungDiagram} (v : Tabloid μ → ℂ) : pairing 0 v = 0 := by + simp [pairing] + +lemma pairing_add_left {μ : YoungDiagram} (u v w : Tabloid μ → ℂ) : + pairing (u+v) w = pairing u w + pairing v w := by + simp [pairing,mul_add,Finset.sum_add_distrib] + +lemma pairing_self_eq_zero {μ : YoungDiagram} (v : Tabloid μ → ℂ) : + pairing v v = 0 ↔ v = 0 := by + change inner ℂ (WithLp.toLp 2 v : EuclideanSpace ℂ (Tabloid μ)) (WithLp.toLp 2 v) = 0 ↔ v = 0 + rw [inner_self_eq_zero] + constructor + · intro h; exact congrArg WithLp.ofLp h + · intro h; subst v; rfl + +lemma pairing_action {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (v w : Tabloid μ → ℂ) : + pairing (tabloidRep μ p v) w = pairing v (tabloidRep μ p⁻¹ w) := by + classical + simp only [pairing,tabloidRep_apply,inv_inv] + apply Fintype.sum_equiv (tabloidAct p⁻¹) + intro f + have hcancel : tabloidAct p (tabloidAct p⁻¹ f) = f := by + rw [tabloidAct_inv] + exact (tabloidAct p).apply_symm_apply f + rw [hcancel] + +lemma alternator_base_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v (baseTabloid μ) = pairing (polytabloid μ) v := by + classical + simp only [polytabloid_formula,pairing_sum_left,pairing_smul_left,conj_permSign,pairing_delta] + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,Finset.sum_apply,Pi.smul_apply, + smul_eq_mul,tabloidRep_apply] + apply Fintype.sum_equiv (Equiv.inv (colGroup μ)) + intro c + simp only [Equiv.inv_apply,Subgroup.coe_inv,permSign_inv] + +theorem alternator_pairing (μ : YoungDiagram) (v : Tabloid μ → ℂ) : + alternator (colGroup μ) (tabloidRep μ) v = pairing (polytabloid μ) v • polytabloid μ := by + rw [alternator_rank_one_exact,alternator_base_pairing] + + +lemma polytabloid_mem_space (μ : YoungDiagram) : polytabloid μ ∈ space μ := by + simpa using orbit_mem_space μ 1 + +lemma alternator_mem_invariant (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (v : Tabloid μ → ℂ) (hv : v ∈ W) : + alternator (colGroup μ) (tabloidRep μ) v ∈ W := by + classical + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply] + exact W.sum_mem (fun c _ => W.smul_mem _ (hW c v hv)) + +theorem submodule_theorem (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) : + space μ ≤ W ∨ ∀ v ∈ W, ∀ w ∈ space μ, pairing w v = 0 := by + classical + by_cases hSW : space μ ≤ W + · exact Or.inl hSW + right + have he : polytabloid μ ∉ W := by + intro he + apply hSW + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + exact hW p _ he + have hpair : ∀ v ∈ W, pairing (polytabloid μ) v = 0 := by + intro v hv + by_contra hne + apply he + have hal := alternator_mem_invariant μ W hW v hv + rw [alternator_pairing] at hal + have hh := W.smul_mem (pairing (polytabloid μ) v)⁻¹ hal + simpa only [smul_smul,inv_mul_cancel₀ hne,one_smul] using hh + intro v hv w hw + induction hw using Submodule.span_induction with + | mem w hw => + obtain ⟨p,rfl⟩ := hw + rw [pairing_action] + exact hpair _ (hW p⁻¹ v hv) + | zero => exact pairing_zero_left v + | add u w hu hw ihu ihw => rw [pairing_add_left,ihu,ihw,add_zero] + | smul a w hw ih => rw [pairing_smul_left,ih,mul_zero] + +theorem space_simple (μ : YoungDiagram) (W : Submodule ℂ (Tabloid μ → ℂ)) + (hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W) (hWS : W ≤ space μ) : + W = ⊥ ∨ W = space μ := by + obtain hSW | horth := submodule_theorem μ W hW + · exact Or.inr (le_antisymm hWS hSW) + · left + apply le_antisymm _ bot_le + intro v hv + exact (pairing_self_eq_zero v).mp (horth v hv v (hWS hv)) + + +lemma space_ne_bot (μ : YoungDiagram) : space μ ≠ ⊥ := by + intro h + have he := polytabloid_mem_space μ + rw [h,Submodule.mem_bot] at he + exact polytabloid_ne_zero μ he + +theorem representation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (representation μ) := by + have hnt : (⊥ : Subrepresentation (representation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) ∈ + (⊥ : Subrepresentation (representation μ)) := by rw [h]; trivial + have he' : (⟨polytabloid μ,polytabloid_mem_space μ⟩ : space μ) = 0 := he + exact polytabloid_ne_zero μ (congrArg Subtype.val he') + refine { exists_pair_ne := ⟨⊥,⊤,hnt⟩, eq_bot_or_eq_top := ?_ } + intro U + let W : Submodule ℂ (Tabloid μ → ℂ) := U.toSubmodule.map (space μ).subtype + have hW : ∀ p v, v ∈ W → tabloidRep μ p v ∈ W := by + intro p v hv + obtain ⟨u,hu,rfl⟩ := hv + exact ⟨representation μ p u,U.apply_mem_toSubmodule p hu,rfl⟩ + have hWS : W ≤ space μ := by + intro v hv + obtain ⟨u,hu,rfl⟩ := hv + exact u.2 + obtain hbot | htop := space_simple μ W hW hWS + · left + apply le_antisymm _ bot_le + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := ⟨u,hu,rfl⟩ + rw [hbot,Submodule.mem_bot] at hmem + change u = 0 + exact Subtype.ext hmem + · right + apply le_antisymm le_top + intro u hu + have hmem : (u : Tabloid μ → ℂ) ∈ W := by rw [htop]; exact u.2 + obtain ⟨v,hv,hvu⟩ := hmem + have heq : v = u := Subtype.ext hvu + exact heq ▸ hv + + +section Symmetrizer +variable {α V : Type*} [Fintype α] [DecidableEq α] [AddCommGroup V] [Module ℂ V] + +noncomputable def symmetrizer (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) : Module.End ℂ V := + ∑ h : H, ρ h + +lemma symmetrizer_mul (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) : + symmetrizer H ρ * ρ h = symmetrizer H ρ := by + rw [symmetrizer,Finset.sum_mul] + exact Fintype.sum_equiv (Equiv.mulRight h) _ _ (fun g => by simp [←map_mul]) + +lemma symmetrizer_eq_zero_of_neg (H : Subgroup (Equiv.Perm α)) + (ρ : Representation ℂ (Equiv.Perm α) V) (h : H) (v : V) (hv : ρ h v = -v) : + symmetrizer H ρ v = 0 := by + have hh := congrArg (fun T : Module.End ℂ V => T v) (symmetrizer_mul H ρ h) + change symmetrizer H ρ (ρ h v) = symmetrizer H ρ v at hh + rw [hv,map_neg] at hh + have h2 : (2:ℂ) • symmetrizer H ρ v = 0 := by + rw [two_smul] + nth_rw 1 [←hh] + exact neg_add_cancel _ + exact (smul_eq_zero.mp h2).resolve_left (by norm_num) + +noncomputable def fiberGroup {β : Type*} (f : α → β) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x, f (p x) = f x} + one_mem' := by intro x; rfl + mul_mem' := by intro p q hp hq x; exact (hp (q x)).trans (hq x) + inv_mem' := by intro p hp x; simpa using (hp (p⁻¹ x)).symm + +omit [Fintype α] in +lemma swap_mem_fiberGroup {β : Type*} (f : α → β) (x y : α) (hf : f x = f y) : + Equiv.swap x y ∈ fiberGroup f := by + intro z + by_cases hx : z=x + · subst z; simpa using hf.symm + by_cases hy : z=y + · subst z; simpa using hf + simp [Equiv.swap_apply_of_ne_of_ne hx hy] + +end Symmetrizer + +lemma swap_polytabloid {μ : YoungDiagram} (x y : Cell μ) (hne : x ≠ y) + (hcol : col x = col y) : + tabloidRep μ (Equiv.swap x y) (polytabloid μ) = -polytabloid μ := by + have h := action_alternator_apply (colGroup μ) (tabloidRep μ) + ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩ (delta (baseTabloid μ)) + simpa only [polytabloid,permSign_swap hne,neg_one_smul] using h + +theorem tall_column_average_zero (μ : YoungDiagram) {β : Type*} [Fintype β] + (f : Cell μ → β) (j : ℕ) (hj : Fintype.card β < μ.colLen j) + (v : Tabloid μ → ℂ) (hv : v ∈ space μ) : + symmetrizer (fiberGroup f) (tabloidRep μ) v = 0 := by + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + have hcard : Fintype.card β < Fintype.card {x : Cell μ // col x = j} := by + rw [Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + exact hj + obtain ⟨x,y,hne,hf⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Cell μ // col x = j} => f (p x.1)) hcard + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : fiberGroup f := ⟨Equiv.swap (p x.1) (p y.1),swap_mem_fiberGroup f _ _ hf⟩ + apply symmetrizer_eq_zero_of_neg _ _ h + change tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (tabloidRep μ p (polytabloid μ)) = -tabloidRep μ p (polytabloid μ) + rw [←Module.End.mul_apply,←map_mul,←Equiv.mul_swap_eq_swap_mul] + rw [map_mul,Module.End.mul_apply,swap_polytabloid x.1 y.1 hxy (x.2.trans y.2.symm),map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + + +noncomputable def rowEquiv (μ : YoungDiagram) (i : ℕ) : + {x : Cell μ // row x = i} ≃ Fin (μ.rowLen i) where + toFun x := ⟨col x.1, by + have h := YoungDiagram.mem_iff_lt_rowLen.mp x.1.2 + change col x.1 < μ.rowLen (row x.1) at h + simpa only [x.2] using h⟩ + invFun j := ⟨⟨(i,j),YoungDiagram.mem_iff_lt_rowLen.mpr j.2⟩,rfl⟩ + left_inv x := by apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.2.symm rfl + right_inv j := rfl + +def rowCost (μ : YoungDiagram) : ℕ := ∑ x : Cell μ, row x + +lemma eq_of_row_preserving (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (he : ∀ x, row (e x) = row x) : μ = ν := by + have hlen (i : ℕ) : μ.rowLen i = ν.rowLen i := by + let ei : {x : Cell μ // row x = i} ≃ {x : Cell ν // row x = i} := + { toFun := fun x => ⟨e x.1,(he x.1).trans x.2⟩ + invFun := fun x => ⟨e.symm x.1,by + have h := he (e.symm x.1) + simp only [Equiv.apply_symm_apply] at h + exact h.symm.trans x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact e.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact e.apply_symm_apply _ } + simpa only [Fintype.card_fin] using Fintype.card_congr + ((rowEquiv μ i).symm.trans (ei.trans (rowEquiv ν i))) + apply YoungDiagram.ext + ext ⟨i,j⟩ + simp only [YoungDiagram.mem_cells,YoungDiagram.mem_iff_lt_rowLen,hlen] + +lemma column_injective_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (h : ∀ x y : Cell μ, col x = col y → row (e x) = row (e y) → x = y) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + let c := rankPerm (fun x => row (e x)) h + have hle (x : Cell μ) : row (c x) ≤ row (e x) := rankCell_row_le _ h x + have hsumc : ∑ x, row (c x) = rowCost μ := Equiv.sum_comp c _ + have hsume : ∑ x, row (e x) = rowCost ν := Equiv.sum_comp e _ + constructor + · rw [←hsumc,←hsume] + exact Finset.sum_le_sum (fun x _ => hle x) + · intro heq + have he : ∀ x, row (c x) = row (e x) := by + apply fun x => (Finset.sum_eq_sum_iff_of_le (fun x _ => hle x)).mp + (hsumc.trans (heq.trans hsume.symm)) x (Finset.mem_univ _) + apply eq_of_row_preserving μ ν (c.symm.trans e) + intro x + simpa using (he (c.symm x)).symm + +lemma swap_relabel {α β : Type*} [DecidableEq α] [DecidableEq β] + (e : α ≃ β) (x y : α) : e.permCongr (Equiv.swap x y) = Equiv.swap (e x) (e y) := by + ext z + simp only [Equiv.permCongr_apply] + exact e.injective.map_swap x y (e.symm z) |>.trans (by simp) + +lemma sign_vector_rowCost (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (v : Tabloid ν → ℂ) (hv : v ≠ 0) + (hs : ∀ c : colGroup μ, + tabloidRep ν (e.permCongr c) v = permSign (c : Equiv.Perm (Cell μ)) • v) : + rowCost μ ≤ rowCost ν ∧ (rowCost μ = rowCost ν → μ = ν) := by + obtain ⟨f,hf⟩ : ∃ f, v f ≠ 0 := by + by_contra h + push Not at h + exact hv (funext h) + obtain ⟨p,hp⟩ := f.2 + apply column_injective_rowCost μ ν (e.trans p) + intro x y hcol hrow + by_contra hne + have hfix : tabloidAct (Equiv.swap (e x) (e y)) f = f := by + apply swap_fixes_tabloid + rw [hp] + exact Fin.ext hrow + have heq := congrArg (fun w : Tabloid ν → ℂ => w f) + (hs ⟨Equiv.swap x y,swap_mem_colGroup x y hcol⟩) + rw [swap_relabel,permSign_swap hne] at heq + simp only [tabloidRep_apply,Equiv.swap_inv,hfix,Pi.smul_apply,neg_one_smul] at heq + apply hf + have h2 : (2:ℂ)*(v f) = 0 := by linear_combination heq + exact (mul_eq_zero.mp h2).resolve_left (by norm_num) + +lemma polytabloid_col_action (μ : YoungDiagram) (c : colGroup μ) : + tabloidRep μ c (polytabloid μ) = permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply _ _ c _ + +theorem shapes_eq_of_equivariant_equiv (μ ν : YoungDiagram) (e : Cell μ ≃ Cell ν) + (T : space μ ≃ₗ[ℂ] space ν) + (hT : ∀ p v, T (representation μ p v) = representation ν (e.permCongr p) (T v)) : + μ = ν := by + let u : space μ := ⟨polytabloid μ,polytabloid_mem_space μ⟩ + have hu : u ≠ 0 := fun h => polytabloid_ne_zero μ (congrArg Subtype.val h) + have hTcol (c : colGroup μ) : + tabloidRep ν (e.permCongr c) (T u) = permSign (c:Equiv.Perm (Cell μ)) • (T u : Tabloid ν → ℂ) := by + change (representation ν (e.permCongr c) (T u) : Tabloid ν → ℂ) = _ + rw [←hT] + have hh : representation μ c u = permSign (c:Equiv.Perm (Cell μ)) • u := + Subtype.ext (polytabloid_col_action μ c) + rw [hh,map_smul] + rfl + have hfwd := sign_vector_rowCost μ ν e (T u) + (fun h => hu (T.injective (by apply Subtype.ext; simpa using h))) hTcol + let w : space ν := ⟨polytabloid ν,polytabloid_mem_space ν⟩ + have hw : w ≠ 0 := fun h => polytabloid_ne_zero ν (congrArg Subtype.val h) + have hTi (p : Equiv.Perm (Cell ν)) (v : space ν) : + T.symm (representation ν p v) = representation μ (e.symm.permCongr p) (T.symm v) := by + apply T.injective + rw [T.apply_symm_apply,hT,T.apply_symm_apply] + have hp : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] + have hTicol (c : colGroup ν) : + tabloidRep μ (e.symm.permCongr c) (T.symm w) = + permSign (c:Equiv.Perm (Cell ν)) • (T.symm w : Tabloid μ → ℂ) := by + change (representation μ (e.symm.permCongr c) (T.symm w) : Tabloid μ → ℂ) = _ + rw [←hTi] + have hh : representation ν c w = permSign (c:Equiv.Perm (Cell ν)) • w := + Subtype.ext (polytabloid_col_action ν c) + rw [hh,map_smul] + rfl + have hbwd := sign_vector_rowCost ν μ e.symm (T.symm w) + (fun h => hw (T.symm.injective (by apply Subtype.ext; simpa using h))) hTicol + exact hfwd.2 (Nat.le_antisymm hfwd.1 hbwd.1) + + +noncomputable def cellRowsEquiv (μ : YoungDiagram) : + Cell μ ≃ (i : Fin (μ.colLen 0)) × Fin (μ.rowLen i) where + toFun x := ⟨rowIndex x,⟨col x,YoungDiagram.mem_iff_lt_rowLen.mp x.2⟩⟩ + invFun p := ⟨(p.1,p.2),YoungDiagram.mem_iff_lt_rowLen.mpr p.2.2⟩ + left_inv x := by apply Subtype.ext; rfl + right_inv p := by rcases p with ⟨⟨i,hi⟩,⟨j,hj⟩⟩; rfl + +lemma card_eq_sum_rowLen (μ : YoungDiagram) : μ.card = ∑ i : Fin (μ.colLen 0), μ.rowLen i := by + rw [←card_cell,Fintype.card_congr (cellRowsEquiv μ),Fintype.card_sigma] + simp only [Fintype.card_fin] + +lemma sum_rowLens (μ : YoungDiagram) : μ.rowLens.sum = μ.card := by + rw [card_eq_sum_rowLen,YoungDiagram.rowLens] + rw [Fin.sum_univ_eq_sum_range] + have hh (n : ℕ) : (List.map μ.rowLen (List.range n)).sum = ∑ i ∈ Finset.range n, μ.rowLen i := by + induction n with + | zero => simp + | succ n ih => simp [List.range_succ,List.map_append,Finset.sum_range_succ,ih] + exact hh _ + +noncomputable def diagramPartition (μ : YoungDiagram) : Nat.Partition μ.card where + parts := μ.rowLens + parts_pos := fun {i} hi => μ.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simp + +noncomputable def partitionDiagram {N : ℕ} (p : Nat.Partition N) : YoungDiagram := + YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE + +lemma partitionDiagram_rowLens {N : ℕ} (p : Nat.Partition N) : + (partitionDiagram p).rowLens = p.parts.sort (· ≥ ·) := by + apply YoungDiagram.rowLens_ofRowLens_eq_self + intro x hx + exact p.parts_pos ((Multiset.mem_sort _).mp hx) + +lemma partitionDiagram_card {N : ℕ} (p : Nat.Partition N) : (partitionDiagram p).card = N := by + rw [←sum_rowLens,partitionDiagram_rowLens] + change (↑(p.parts.sort (· ≥ ·)) : Multiset ℕ).sum = N + rw [Multiset.sort_eq,p.parts_sum] + +lemma partitionDiagram_diagramPartition (μ : YoungDiagram) : + partitionDiagram (diagramPartition μ) = μ := by + apply YoungDiagram.equivListRowLens.injective + apply Subtype.ext + change (partitionDiagram (diagramPartition μ)).rowLens = μ.rowLens + rw [partitionDiagram_rowLens] + change (↑μ.rowLens : Multiset ℕ).sort (· ≥ ·) = μ.rowLens + rw [Multiset.coe_sort,List.mergeSort_eq_self _ μ.rowLens_sorted.pairwise] + +abbrev Shapes (N : ℕ) := {μ : YoungDiagram // μ.card = N} + +end Thorp.Specht + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedRoutingMoment.lean b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedRoutingMoment.lean index 06b176f506ba1afe4751ca32cfe226ba234ceca4..01160500b6142ccad89b18a0182dcbde158349e2 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedRoutingMoment.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedRoutingMoment.lean @@ -1,858 +1,858 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.InputTree - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by - classical - exact finiteMean (fun ω : ModifiedCoins L r => - if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) - -lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : - 0 ≤ modifiedRoutingMoment L r E e f a := by - classical - exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) - -lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : - modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by - simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, - PairRouting.tupleProbability] - -lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) - {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ - centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by - have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f - rw [modifiedRoutingMoment_zero] - have hbound := modified_probability_zero_le L E e f he - have hpow := Real.rpow_le_rpow hp hbound ha - have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) - have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = - centralFactor L 0 E a := by - rw [centralFactor_zero] - split_ifs - · exact Real.one_rpow _ - · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] - rw [heq] at hpow - rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] - exact mul_le_mul_of_nonneg_right hpow hp - - -lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} - (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) - (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : - (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ - (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by - apply forall_congr' - intro i - rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] - rfl - -lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (e f : ι ↪ Card (L+r+1)) (a : ℝ) : - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by - classical - intro x y - let : Fintype (ModifiedCoins L r) := inferInstance - rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have he (ω : ModifiedCoins L r × ModifiedCoins L r) : - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i - then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = - PairRouting.outerWeight x y * - ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by - let W : (ι → Bool) → ℝ := fun c => - if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 - calc - _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) - (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by - apply finiteMean_congr - intro coins - simp only [modified_matches_step,modifiedCost_step] - simp only [W,PairRouting.colors_compatible,↓reduceDIte] - rfl - _ = _ := by - rw [PairRouting.sandwich_weighted_probability_subtype] - congr 1 - apply Finset.sum_congr rfl - intro c _ - simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] - simp_rw [he] - simp_rw [mul_comm (PairRouting.outerWeight x y)] - rw [finiteMean_mul_const,finiteMean_sum,mul_comm] - -lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : - modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 - let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 - have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = - (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by - funext b - cases b <;> rfl - have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ - M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ - change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ - by_cases h₀ : M₀ <;> by_cases h₁ : M₁ - · simp only [hs,h₀,h₁,true_and,↓reduceIte] - rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] - congr 1 - ring - · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] - · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] - -lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r+1)) : - PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => - if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) - ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) - then (1:ℝ) else 0)) := by - classical - let : Fintype (ModifiedCoins L r) := inferInstance - rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] - have hp (b : Bool) (p q : ModifiedCoins L r) : - modifiedPerm L r (exceptionChild E b) (if b then p else q) = - (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by - cases b <;> rfl - simp only [modified_matches_step,hp] - - -lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) - (a : ℝ) (ha : 0 ≤ a) : - let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 - PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ - (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by - classical - intro hcx - have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : - q * finiteMean F = finiteMean (fun ω => q * F ω) := by - simp_rw [mul_comm q,finiteMean_mul_const] - rw [←mul_assoc,hscale,hscale] - apply finiteMean_mono - intro ω - split_ifs with hm - · have hh := PairRouting.assignment_factor_bound x y c hc - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha - calc - _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) - (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * - (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * - (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) - _ = _ := by - simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] - congr 1 - ring - · simp only [mul_zero] - exact le_rfl - - -lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) - {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) - (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) - (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * - modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) - (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c - then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + - modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by - have hh := mul_le_mul hfalse htrue - (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) - (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) - (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) - have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = - -(r:ℝ)*Fintype.card ι*a := by - rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] - calc - _ ≤ _ := hh - _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* - (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * - (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * - (modifiedRoutingMoment L r (exceptionChild E false) - (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * - modifiedRoutingMoment L r (exceptionChild E true) - (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring - _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] - - -theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ - ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by - classical - induction r generalizing ι with - | zero => - simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using - modified_pointwise_zero L E e f he a ha - | succ r ih => - let x := e.trans (headTailEquiv (L+r)).toEmbedding - let y := f.trans (headTailEquiv (L+r)).toEmbedding - let W := PairRouting.outerWeight x y - let C := PairRouting.compatibleSet x y - let p : (ι → Bool) → ℝ := fun c => - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) - (fun i : {i // c i = false} => (x i.val).2) - (fun i : {i // c i = false} => (y i.val).2))^(1+a) * - (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) - (fun i : {i // c i = true} => (x i.val).2) - (fun i : {i // c i = true} => (y i.val).2))^(1+a) - let m : {c // c ∈ C} → ℝ := fun c => - finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => - if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val - then (2:ℝ)^((modifiedAssignmentCost L r E x c.val - ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) - have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by - obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property - have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) - (PairRouting.childEmbedding y c.val hcy false) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) - have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) - (PairRouting.childEmbedding y c.val hcy true) - (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) - have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ - have hh' := mul_le_mul_of_nonneg_left hh - (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) - (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) - apply hh'.trans - have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha - convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring - have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha - rw [←modified_probability_step L r E e f] at hnode - change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ - W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode - have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by - rw [Finset.sum_subtype C (fun _ => Iff.rfl)] - have hW : 0 < W := PairRouting.outerWeight_pos x y - calc - _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode - _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by - rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] - ring - _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_step] - simp only [Nat.cast_add,Nat.cast_one] - change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = - ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) - ring - - -lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : - (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - unfold modifiedRoutingMoment - rw [←finiteMean_sum] - apply finiteMean_congr - intro ω - let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding - rw [Finset.sum_eq_single f₀] - · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl - simp only [hm,implies_true,↓reduceIte] - · intro f _ hf - have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by - intro hh - apply hf - ext i : 1 - exact (hh i).symm - exact ite_eq_right hm - · simp - -noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := - finiteMean (fun f : ι ↪ Card (L+r) => - ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) - -lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (he : Function.Surjective e) : Fintype.card ι = 2^d := by - rw [←card_positions d] - exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) - -lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by - simpa only [card_positions] using E.card_le_univ - -noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := - (Nat.factorial (2^(L+r)):ℝ) / - (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) - -lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : - 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity - -lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : - (Nat.factorial (2^(L+r)):ℝ)^a * - ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = - modifiedNormalization L r E ^ a := by - rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, - Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), - Real.mul_rpow (by positivity) (by positivity)] - have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by - rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, - show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, - Real.rpow_neg (by positivity)] - ring - -theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : - modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * - finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by - classical - have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ - rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] - calc - _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * - ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * - modifiedRoutingMoment L r E e f a := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) - (Real.rpow_nonneg (Nat.cast_nonneg _) _) - _ = _ := by - rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, - card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] - -lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : - finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ - Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - let B := Real.exp (Fintype.card ι*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) - rw [finiteMean_prod] - apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le - rw [finiteMean_prod,finiteMean_comm] - apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le - exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) - -lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - modifiedNormalization L r E ^ (1/1000:ℝ) * - Real.exp ((2^(L+r):ℕ)*heightDecay L + - 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) - simp_rw [←momentBase_pow] at hm - apply hm.trans - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) - simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e - - -lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : - Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by - induction n with - | zero => omega - | succ n ih => - by_cases hz : n = 0 - · subst n; norm_num - have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) - have hn1 : (0:ℝ) < n+1 := by positivity - have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) - rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h - have hh := mul_le_mul_of_nonneg_left h hn1.le - have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring - rw [hcancel] at hh - have hi := ih (by omega) - rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] - nlinarith - -lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) = - Real.log (Nat.factorial (2^(L+r))) - - ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by - unfold modifiedNormalization - rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), - Real.log_pow,Real.log_pow,Real.log_pow, - Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] - simp only [Nat.cast_pow,Nat.cast_ofNat] - -lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : - Real.log (modifiedNormalization L r E) ≤ - ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by - have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) - have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) - have hu := log_factorial_upper hN - have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) - simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ - rw [log_modifiedNormalization] - simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ - nlinarith - -lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + - (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by - apply (modifiedRowMoment_bound L r hL E e he).trans - rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] - apply Real.exp_le_exp.mpr - have h := log_modifiedNormalization_le L r E - linarith - -lemma log_power_factorial_le (L : ℕ) : - Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by - have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by - exact_mod_cast Nat.factorial_le_pow (2^L) - have hh := Real.log_le_log (by positivity) hf - rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh - apply hh.trans - have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) - have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity - nlinarith - -lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) - (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : - modifiedRowMoment L r E e (1/1000) ≤ - Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + - (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by - apply (modified_moment_exponential L r hL E e he).trans - apply Real.exp_le_exp.mpr - have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) - have hb := mul_le_mul_of_nonneg_left momentBase_log - (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) - have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) - simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ - nlinarith - - -lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by - have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := - (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr - tendsto_natCast_atTop_atTop - have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) - convert ht using 1 - · funext L - unfold heightDecay - dsimp only [Function.comp_apply] - rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] - · simp - -noncomputable def modifiedOverhead (L r : ℕ) : ℝ := - (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) - -lemma modifiedOverhead_tendsto (L : ℕ) : - Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by - have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) - have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) - simp only [pow_one] at h₁ - simp only [pow_zero] at h₀ - have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const - ((2:ℝ)^L*1000) - convert ht using 1 - · funext r - simp only [modifiedOverhead,Nat.cast_add,pow_add] - field_simp - ring - · simp - -theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : - ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ - ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → - ∀ (e : Card (L+r) ↪ Card (L+r)), - modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by - have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := - heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists - have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL - let ε : ℝ := min (1/4) (η*250/(3*L)) - have hε : 0 < ε := lt_min (by norm_num) (by positivity) - have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) - have hεL : ε*L/250 ≤ η/3 := by - have h := min_le_right (1/4:ℝ) (η*250/(3*L)) - change ε ≤ η*250/(3*L) at h - have hh := mul_le_mul_of_nonneg_right h hL0.le - have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp - exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le - refine ⟨L,hL,ε,hε,hε1,?_⟩ - have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := - (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) - filter_upwards [hr] with r hr - intro E hE e - have he := Finite.surjective_of_injective e.injective - apply (modified_moment_exception_bound L r hL E e he ε hE).trans - apply Real.exp_le_exp.mpr - have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity - have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = - (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by - unfold modifiedOverhead - field_simp - have hh := mul_le_mul_of_nonneg_right hr.le hn.le - rw [hd] at hh - have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le - linarith - - -namespace DensityTransfer -open scoped BigOperators - -noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - -lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) - (v : EuclideanSpace ℂ X) (x : X) : - applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl - -lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) - (v : EuclideanSpace ℂ X) : - applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by - ext x - simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] - rfl - -lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : - ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by - have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by - rw [applyKernel_apply] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] - apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans - exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) - (fun y _ => by ring_nf; exact le_rfl) - -lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) - (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) - (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by - have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by - rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] - calc - _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by - apply Finset.sum_le_sum - intro x _ - apply (kernel_component_sq P hP v x).trans - exact mul_le_mul_of_nonneg_right (hrow x) - (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) - _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by - rw [←Finset.mul_sum,Finset.sum_comm] - congr 1 - apply Finset.sum_congr rfl - intro y _ - exact (Finset.sum_mul Finset.univ _ _).symm - _ ≤ δ * ∑ y, δ*‖v y‖^2 := by - apply mul_le_mul_of_nonneg_left _ hδ - exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) - _ = _ := by rw [←Finset.mul_sum]; ring - have hn := norm_nonneg (applyKernel P v) - have hr := mul_nonneg hδ (norm_nonneg v) - nlinarith - -lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] - (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : - (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by - simp_rw [EuclideanSpace.norm_sq_eq] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro x _ - let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) - have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by - rw [norm_inner_symm] - congr 1 - simp only [applyKernel_apply,PiLp.inner_apply] - apply Finset.sum_congr rfl - intro y _ - simp [w,RCLike.inner_apply,mul_comm] - simp_rw [he] - have h := hv.sum_inner_products_le (s := Finset.univ) w - apply h.trans_eq - rw [EuclideanSpace.norm_sq_eq] - apply Finset.sum_congr rfl - intro y _ - simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] - - -lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : - (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by - split_ifs with h - · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] - apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr - rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] - exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht - · positivity - -lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : - finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by - rw [←finiteMean_mul_const] - exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) - -noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 - -noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := - fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y - -lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : - (fun x y => tailKernel P z x y+headKernel P z x y) = P := by - funext x y - unfold tailKernel headKernel - split_ifs <;> simp - -lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) - (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by - unfold tailKernel - split_ifs <;> simp only [hP,le_refl] - -lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : - ∑ y, tailKernel P z x y ≤ M*z^(-a) := by - have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then - (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by - unfold finiteMean - calc - _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by - congr 1 - apply Finset.sum_congr rfl - intro y _ - by_cases hy : z < (Fintype.card X:ℝ)*P x y - · simp only [tailKernel,hy,↓reduceIte] - · simp only [tailKernel,hy,↓reduceIte,mul_zero] - _ = _ := by rw [←Finset.mul_sum]; field_simp - rw [←he] - exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans - (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) - -lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : EuclideanSpace ℂ X) : - ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by - apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) - (tailKernel_row P hP a z M ha hz hM) - intro y - have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by - funext x - simp only [tailKernel,hsym x y] - rw [hs] - exact tailKernel_row P hP a z M ha hz hM y - -lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : - (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by - have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by - unfold headKernel - split_ifs with h - · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] - exact mul_nonneg (div_nonneg hz hn.le) (hP x y) - · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h - have hh := mul_le_mul_of_nonneg_right h' (hP x y) - rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] - apply (le_div_iff₀ hn).mpr - nlinarith - calc - _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := - Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) - _ = z := by - simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - - -theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] - [Fintype I] [Nonempty I] (P : X → X → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) - (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) - (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) - (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : - μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by - let δ : ℝ := M*z^(-a) - have hδ : 0 ≤ δ := by dsimp [δ]; positivity - have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos - change μ ≤ δ+_ - by_cases hμ : μ ≤ δ - · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) - have hmd : 0 ≤ μ-δ := by linarith - have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by - have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) - rw [hv.norm_eq_one i,mul_one] at hr - have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) - rw [tail_add_head] at he - have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) - rw [←he] at hn - have hh := hvμ i - change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr - linarith - have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by - calc - _ = ∑ i : I, (μ-δ)^2 := by simp - _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := - Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) - _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv - _ ≤ z := headKernel_hs P hP hrow z hz.le - have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) - have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq - linarith - -end DensityTransfer -namespace PairRouting -open scoped BigOperators - -lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] - [DecidableEq β] [Fintype Ω] [Nonempty Ω] - (P : Ω → Equiv.Perm β) (e : ι ↪ β) : - (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by - classical - simp only [tupleProbability] - rw [←finiteMean_sum] - have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun g : ι ↪ β => g i) h - simp_rw [h] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : - tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by - classical - apply finiteMean_congr - intro ω - congr 1 - apply propext - constructor - · intro h i - have hh := congrArg (P ω) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm - · intro h i - have hh := congrArg (fun x => (P ω).symm x) (h i) - simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - -lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : - tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := - finiteMean_equiv τ _ - -lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] - [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) - (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : - tupleProbability P e f = tupleProbability P f e := by - rw [tupleProbability_equiv P τ.symm] - simp only [Equiv.symm_symm,hτ] - exact tupleProbability_inverse P e f - -end PairRouting - -lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : - palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by - simp only [palindromePerm,mul_inv_rev] - rfl - -lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] - (e f : ι ↪ Card d) : - PairRouting.tupleProbability (palindromePerm d) e f = - PairRouting.tupleProbability (palindromePerm d) f e := - PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f - -theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] - [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) - (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) - (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) - (z : ℝ) (hz : 0 < z) : - μ ≤ Real.exp (densityConstant*Fintype.card ι* - ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ - Real.sqrt (z/(Fintype.card I:ℝ)) := by - let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ - apply DensityTransfer.multiplicity_amplification - (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) - (fun e f => PairRouting.tupleProbability_nonneg _ e f) - (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) - (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ - intro e - exact palindrome_row_moment_bound d e hk - - -noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r - | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * - butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) - | r+1, ω => - let z := modifiedStepEquiv L r ω - (modifiedStepEquiv L r).symm - ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) - -lemma modifiedReverseCoins_involutive (L r : ℕ) : - Function.Involutive (modifiedReverseCoins L r) := by - induction r with - | zero => - intro ω - apply Prod.ext - · funext u - simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] - simp [mul_assoc] - · rfl - | succ r ih => - change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih - intro ω - simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] - exact (modifiedStepEquiv L r).symm_apply_apply ω - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.InputTree + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +noncomputable def modifiedRoutingMoment (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : ℝ := by + classical + exact finiteMean (fun ω : ModifiedCoins L r => + if ∀ i, modifiedPerm L r E ω (e i) = f i then (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a) else 0) + +lemma modifiedRoutingMoment_nonneg (L r : ℕ) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card (L+r)) (a : ℝ) : + 0 ≤ modifiedRoutingMoment L r E e f a := by + classical + exact finiteMean_nonneg (fun _ => by split_ifs <;> positivity) + +lemma modifiedRoutingMoment_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (a : ℝ) : + modifiedRoutingMoment L 0 E e f a = PairRouting.tupleProbability (modifiedPerm L 0 E) e f := by + simp only [modifiedRoutingMoment,modifiedCost_zero,Nat.cast_zero,zero_mul,Real.rpow_zero, + PairRouting.tupleProbability] + +lemma modified_pointwise_zero (L : ℕ) (E : Finset (Card 0)) + {ι : Type*} [Fintype ι] (e f : ι ↪ Card L) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L 0 E) e f)^(1+a) ≤ + centralFactor L 0 E a * modifiedRoutingMoment L 0 E e f a := by + have hp := PairRouting.tupleProbability_nonneg (modifiedPerm L 0 E) e f + rw [modifiedRoutingMoment_zero] + have hbound := modified_probability_zero_le L E e f he + have hpow := Real.rpow_le_rpow hp hbound ha + have hfpos : (0:ℝ) < Nat.factorial (2^L) := Nat.cast_pos.mpr (Nat.factorial_pos _) + have heq : (if (fun j => Fin.elim0 j : Card 0) ∈ E then (1:ℝ) else 1/(Nat.factorial (2^L):ℝ))^a = + centralFactor L 0 E a := by + rw [centralFactor_zero] + split_ifs + · exact Real.one_rpow _ + · rw [one_div,Real.inv_rpow (le_of_lt hfpos),Real.rpow_neg (le_of_lt hfpos)] + rw [heq] at hpow + rw [Real.rpow_add' hp (by linarith : (1+a:ℝ) ≠ 0),Real.rpow_one,mul_comm] + exact mul_le_mul_of_nonneg_right hpow hp + + +lemma modified_matches_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} + (e f : ι ↪ Card (L+r+1)) (ω : ModifiedCoins L r × ModifiedCoins L r) + (coins : (Card (L+r) → Bool) × (Card (L+r) → Bool)) : + (∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i) ↔ + (∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i)) := by + apply forall_congr' + intro i + rw [←(headTailEquiv (L+r)).injective.eq_iff,modifiedPerm_coordinates] + rfl + +lemma modifiedRoutingMoment_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (e f : ι ↪ Card (L+r+1)) (a : ℝ) : + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + modifiedRoutingMoment L (r+1) E e f a = PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) := by + classical + intro x y + let : Fintype (ModifiedCoins L r) := inferInstance + rw [modifiedRoutingMoment,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have he (ω : ModifiedCoins L r × ModifiedCoins L r) : + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, modifiedPerm L (r+1) E ((modifiedStepEquiv L r).symm (ω,coins)) (e i) = f i + then (2:ℝ)^((modifiedCost L (r+1) E e ((modifiedStepEquiv L r).symm (ω,coins)):ℝ)*a) else 0) = + PairRouting.outerWeight x y * + ∑ c : {c // c ∈ PairRouting.compatibleSet x y}, + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0 := by + let W : (ι → Bool) → ℝ := fun c => + if hc : PairRouting.Compatible x c then (2:ℝ)^((modifiedAssignmentCost L r E x c hc ω:ℝ)*a) else 0 + calc + _ = finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) + (x i) = y i then W (PairRouting.colors x coins.1) else 0) := by + apply finiteMean_congr + intro coins + simp only [modified_matches_step,modifiedCost_step] + simp only [W,PairRouting.colors_compatible,↓reduceDIte] + rfl + _ = _ := by + rw [PairRouting.sandwich_weighted_probability_subtype] + congr 1 + apply Finset.sum_congr rfl + intro c _ + simp only [W,((PairRouting.mem_compatibleSet x y c.val).mp c.property).1,↓reduceDIte] + simp_rw [he] + simp_rw [mul_comm (PairRouting.outerWeight x y)] + rw [finiteMean_mul_const,finiteMean_sum,mul_comm] + +lemma modified_child_moment_product (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) : + modifiedRoutingMoment L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + let M₀ := ∀ i : {i // c i = false}, modifiedPerm L r (exceptionChild E false) ω.1 (x i.val).2 = (y i.val).2 + let M₁ := ∀ i : {i // c i = true}, modifiedPerm L r (exceptionChild E true) ω.2 (x i.val).2 = (y i.val).2 + have hp : (fun b : Bool => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) = + (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) := by + funext b + cases b <;> rfl + have hs : PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c ↔ + M₀ ∧ M₁ := by rw [hp]; exact PairRouting.childMatches_split _ _ _ _ _ + change (if M₀ then _ else 0) * (if M₁ then _ else 0) = _ + by_cases h₀ : M₀ <;> by_cases h₁ : M₁ + · simp only [hs,h₀,h₁,true_and,↓reduceIte] + rw [←Real.rpow_add (by norm_num : (0:ℝ)<2)] + congr 1 + ring + · simp only [hs,h₀,h₁,and_false,↓reduceIte,mul_zero] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,zero_mul] + · simp only [hs,h₀,h₁,false_and,↓reduceIte,mul_zero] + +lemma modified_probability_step (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r+1)) : + PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f = + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + finiteMean (fun coins : (Card (L+r) → Bool) × (Card (L+r) → Bool) => + if ∀ i, PairRouting.sandwich coins.1 coins.2 (fun b => if b then modifiedPerm L r (exceptionChild E true) ω.2 else modifiedPerm L r (exceptionChild E false) ω.1) + ((e.trans (headTailEquiv (L+r)).toEmbedding) i) = ((f.trans (headTailEquiv (L+r)).toEmbedding) i) + then (1:ℝ) else 0)) := by + classical + let : Fintype (ModifiedCoins L r) := inferInstance + rw [PairRouting.tupleProbability,finiteMean_equiv (modifiedStepEquiv L r),finiteMean_prod] + have hp (b : Bool) (p q : ModifiedCoins L r) : + modifiedPerm L r (exceptionChild E b) (if b then p else q) = + (if b then modifiedPerm L r (exceptionChild E true) p else modifiedPerm L r (exceptionChild E false) q) := by + cases b <;> rfl + simp only [modified_matches_step,hp] + + +lemma modified_assignment_moment_bound (L r : ℕ) (E : Finset (Card (r+1))) {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) (hc : c ∈ PairRouting.compatibleSet x y) + (a : ℝ) (ha : 0 ≤ a) : + let hcx := ((PairRouting.mem_compatibleSet x y c).mp hc).1 + PairRouting.outerWeight x y ^ a * ((PairRouting.compatibleSet x y).card:ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0)) ≤ + (2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^((modifiedAssignmentCost L r E x c hcx ω:ℝ)*a) else 0) := by + classical + intro hcx + have hscale (q : ℝ) (F : ModifiedCoins L r × ModifiedCoins L r → ℝ) : + q * finiteMean F = finiteMean (fun ω => q * F ω) := by + simp_rw [mul_comm q,finiteMean_mul_const] + rw [←mul_assoc,hscale,hscale] + apply finiteMean_mono + intro ω + split_ifs with hm + · have hh := PairRouting.assignment_factor_bound x y c hc + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) hm a ha + calc + _ ≤ ((2:ℝ)^(((PairRouting.alternatingCycles (PairRouting.coloredEmbedding x c hcx) + (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)):ℝ)-Fintype.card ι)*a) * + (2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)) * + (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hh (by positivity)) (by positivity) + _ = _ := by + simp only [←Real.rpow_add (by norm_num : (0:ℝ)<2),modifiedAssignmentCost,Nat.cast_add] + congr 1 + ring + · simp only [mul_zero] + exact le_rfl + + +lemma modified_child_power_product_bound (L r : ℕ) (E : Finset (Card (r+1))) + {ι : Type*} [Fintype ι] (x y : ι ↪ Bool × Card (L+r)) (c : ι → Bool) + (hcx : PairRouting.Compatible x c) (hcy : PairRouting.Compatible y c) (a : ℝ) + (hfalse : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)*centralFactor L r (exceptionChild E false) a) * + modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a) + (htrue : (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)*centralFactor L r (exceptionChild E true) a) * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) : + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true))^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L (r+1) E a) * + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c + then (2:ℝ)^(((modifiedCost L r (exceptionChild E false) (PairRouting.childEmbedding x c hcx false) ω.1 : ℝ) + + modifiedCost L r (exceptionChild E true) (PairRouting.childEmbedding x c hcx true) ω.2)*a) else 0) := by + have hh := mul_le_mul hfalse htrue + (Real.rpow_nonneg (PairRouting.tupleProbability_nonneg _ _ _) _) + (mul_nonneg (mul_nonneg (by positivity) (centralFactor_nonneg _ _ _ _)) + (modifiedRoutingMoment_nonneg _ _ _ _ _ _)) + have he : -(r:ℝ)*Fintype.card {i // c i = false}*a + -(r:ℝ)*Fintype.card {i // c i = true}*a = + -(r:ℝ)*Fintype.card ι*a := by + rw [←add_mul,←mul_add,←Nat.cast_add,PairRouting.color_card_add] + calc + _ ≤ _ := hh + _ = ((2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = false}*a)* + (2:ℝ)^(-(r:ℝ)*Fintype.card {i // c i = true}*a)) * + (centralFactor L r (exceptionChild E false) a * centralFactor L r (exceptionChild E true) a) * + (modifiedRoutingMoment L r (exceptionChild E false) + (PairRouting.childEmbedding x c hcx false) (PairRouting.childEmbedding y c hcy false) a * + modifiedRoutingMoment L r (exceptionChild E true) + (PairRouting.childEmbedding x c hcx true) (PairRouting.childEmbedding y c hcy true) a) := by ring + _ = _ := by rw [←Real.rpow_add (by norm_num : (0:ℝ)<2),he,←centralFactor_step,modified_child_moment_product] + + +theorem modified_pointwise_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + (PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a) ≤ + ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * modifiedRoutingMoment L r E e f a := by + classical + induction r generalizing ι with + | zero => + simpa only [Nat.cast_zero,neg_zero,zero_mul,Real.rpow_zero,one_mul] using + modified_pointwise_zero L E e f he a ha + | succ r ih => + let x := e.trans (headTailEquiv (L+r)).toEmbedding + let y := f.trans (headTailEquiv (L+r)).toEmbedding + let W := PairRouting.outerWeight x y + let C := PairRouting.compatibleSet x y + let p : (ι → Bool) → ℝ := fun c => + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E false)) + (fun i : {i // c i = false} => (x i.val).2) + (fun i : {i // c i = false} => (y i.val).2))^(1+a) * + (PairRouting.tupleProbability (modifiedPerm L r (exceptionChild E true)) + (fun i : {i // c i = true} => (x i.val).2) + (fun i : {i // c i = true} => (y i.val).2))^(1+a) + let m : {c // c ∈ C} → ℝ := fun c => + finiteMean (fun ω : ModifiedCoins L r × ModifiedCoins L r => + if PairRouting.ChildMatches (fun b => modifiedPerm L r (exceptionChild E b) (if b then ω.2 else ω.1)) x y c.val + then (2:ℝ)^((modifiedAssignmentCost L r E x c.val + ((PairRouting.mem_compatibleSet x y c.val).mp c.property).1 ω:ℝ)*a) else 0) + have hp (c : {c // c ∈ C}) : W^a * (C.card:ℝ)^a * p c.val ≤ + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := by + obtain ⟨hcx,hcy⟩ := (PairRouting.mem_compatibleSet x y c.val).mp c.property + have h₀ := ih (exceptionChild E false) (PairRouting.childEmbedding x c.val hcx false) + (PairRouting.childEmbedding y c.val hcy false) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx false) + have h₁ := ih (exceptionChild E true) (PairRouting.childEmbedding x c.val hcx true) + (PairRouting.childEmbedding y c.val hcy true) + (PairRouting.childEmbedding_surjective x ((headTailEquiv (L+r)).surjective.comp he) c.val hcx true) + have hh := modified_child_power_product_bound L r E x y c.val hcx hcy a h₀ h₁ + have hh' := mul_le_mul_of_nonneg_left hh + (mul_nonneg (Real.rpow_nonneg (le_of_lt (PairRouting.outerWeight_pos x y)) a) + (Real.rpow_nonneg (Nat.cast_nonneg C.card) a)) + apply hh'.trans + have hm := modified_assignment_moment_bound L r E x y c.val c.property a ha + convert mul_le_mul_of_nonneg_left hm (centralFactor_nonneg L (r+1) E a) using 1 <;> ring + have hnode := PairRouting.sandwich_power_bound (modifiedPerm L r (exceptionChild E false)) (modifiedPerm L r (exceptionChild E true)) x y a ha + rw [←modified_probability_step L r E e f] at hnode + change (PairRouting.tupleProbability (modifiedPerm L (r+1) E) e f)^(1+a) ≤ + W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c at hnode + have hsum : ∑ c ∈ C, p c = ∑ c : {c // c ∈ C}, p c.val := by + rw [Finset.sum_subtype C (fun _ => Iff.rfl)] + have hW : 0 < W := PairRouting.outerWeight_pos x y + calc + _ ≤ W^(1+a) * (C.card:ℝ)^a * ∑ c ∈ C, p c := hnode + _ = W * ∑ c : {c // c ∈ C}, W^a * (C.card:ℝ)^a * p c.val := by + rw [Real.rpow_add hW,Real.rpow_one,hsum,←Finset.mul_sum] + ring + _ ≤ W * ∑ c : {c // c ∈ C}, ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * m c := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun c _ => hp c)) (le_of_lt hW) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_step] + simp only [Nat.cast_add,Nat.cast_one] + change W * (((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * ∑ c, m c) = + ((2:ℝ)^(-((r:ℝ)+1)*Fintype.card ι*a)*centralFactor L (r+1) E a) * (W * ∑ c, m c) + ring + + +lemma modifiedRoutingMoment_sum (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : + (∑ f : ι ↪ Card (L+r), modifiedRoutingMoment L r E e f a) = + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + unfold modifiedRoutingMoment + rw [←finiteMean_sum] + apply finiteMean_congr + intro ω + let f₀ : ι ↪ Card (L+r) := e.trans (modifiedPerm L r E ω).toEmbedding + rw [Finset.sum_eq_single f₀] + · have hm : ∀ i, modifiedPerm L r E ω (e i) = f₀ i := fun _ => rfl + simp only [hm,implies_true,↓reduceIte] + · intro f _ hf + have hm : ¬ ∀ i, modifiedPerm L r E ω (e i) = f i := by + intro hh + apply hf + ext i : 1 + exact (hh i).symm + exact ite_eq_right hm + · simp + +noncomputable def modifiedRowMoment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (a : ℝ) : ℝ := + finiteMean (fun f : ι ↪ Card (L+r) => + ((Fintype.card (ι ↪ Card (L+r)):ℝ)*PairRouting.tupleProbability (modifiedPerm L r E) e f)^(1+a)) + +lemma full_tuple_card (d : ℕ) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (he : Function.Surjective e) : Fintype.card ι = 2^d := by + rw [←card_positions d] + exact Fintype.card_congr (Equiv.ofBijective e ⟨e.injective,he⟩) + +lemma exception_card_le (r : ℕ) (E : Finset (Card r)) : E.card ≤ 2^r := by + simpa only [card_positions] using E.card_le_univ + +noncomputable def modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : ℝ := + (Nat.factorial (2^(L+r)):ℝ) / + (((2:ℝ)^r)^(2^(L+r)) * (Nat.factorial (2^L):ℝ)^(2^r-E.card)) + +lemma modifiedNormalization_pos (L r : ℕ) (E : Finset (Card r)) : + 0 < modifiedNormalization L r E := by unfold modifiedNormalization; positivity + +lemma modified_normalization_identity (L r : ℕ) (E : Finset (Card r)) (a : ℝ) : + (Nat.factorial (2^(L+r)):ℝ)^a * + ((2:ℝ)^(-(r:ℝ)*(2^(L+r):ℕ)*a)*centralFactor L r E a) = + modifiedNormalization L r E ^ a := by + rw [←mul_assoc,density_normalization,centralFactor,modifiedNormalization, + Real.div_rpow (by positivity) (by positivity),Real.div_rpow (by positivity) (by positivity), + Real.mul_rpow (by positivity) (by positivity)] + have hc : ((2^r-E.card:ℕ):ℝ) = (2:ℝ)^r-E.card := by + rw [Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + rw [←Real.rpow_natCast (Nat.factorial (2^L):ℝ),←Real.rpow_mul (by positivity),hc, + show -((2:ℝ)^r-E.card)*a = -(((2:ℝ)^r-E.card)*a) by ring, + Real.rpow_neg (by positivity)] + ring + +theorem modified_row_density_moment (L r : ℕ) (E : Finset (Card r)) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (L+r)) (he : Function.Surjective e) (a : ℝ) (ha : 0 ≤ a) : + modifiedRowMoment L r E e a ≤ modifiedNormalization L r E ^ a * + finiteMean (fun ω : ModifiedCoins L r => (2:ℝ)^((modifiedCost L r E e ω:ℝ)*a)) := by + classical + have : Nonempty (ι ↪ Card (L+r)) := ⟨e⟩ + rw [modifiedRowMoment,finite_row_power _ (fun f => PairRouting.tupleProbability_nonneg _ _ _)] + calc + _ ≤ (Fintype.card (ι ↪ Card (L+r)):ℝ)^a * + ∑ f : ι ↪ Card (L+r), ((2:ℝ)^(-(r:ℝ)*Fintype.card ι*a)*centralFactor L r E a) * + modifiedRoutingMoment L r E e f a := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun f _ => modified_pointwise_moment L r E e f he a ha)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + _ = _ := by + rw [←Finset.mul_sum,modifiedRoutingMoment_sum,←mul_assoc,Fintype.card_embedding_eq, + card_positions,full_tuple_card (L+r) e he,Nat.descFactorial_self,modified_normalization_identity] + +lemma modified_total_cost_mgf (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) : + finiteMean (fun ω : ModifiedCoins L r => momentBase^(modifiedCost L r E e ω)) ≤ + Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + let B := Real.exp (Fintype.card ι*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) + rw [finiteMean_prod] + apply le_trans (finiteMean_mono (fun U => ?_)) (finiteMean_const B).le + rw [finiteMean_prod,finiteMean_comm] + apply le_trans (finiteMean_mono (fun X => ?_)) (finiteMean_const B).le + exact modified_cost_mgf L r hL E U X e momentBase momentBase_one_le (momentBase_log.trans (by norm_num)) + +lemma modifiedRowMoment_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + modifiedNormalization L r E ^ (1/1000:ℝ) * + Real.exp ((2^(L+r):ℕ)*heightDecay L + + 3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + have hm := modified_row_density_moment L r E e he (1/1000) (by norm_num) + simp_rw [←momentBase_pow] at hm + apply hm.trans + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (modifiedNormalization_pos L r E).le _) + simpa only [full_tuple_card (L+r) e he] using modified_total_cost_mgf L r hL E e + + +lemma log_factorial_upper {n : ℕ} (hn : 1 ≤ n) : + Real.log (Nat.factorial n) ≤ (n:ℝ)*Real.log n-n+Real.log n+1 := by + induction n with + | zero => omega + | succ n ih => + by_cases hz : n = 0 + · subst n; norm_num + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hz) + have hn1 : (0:ℝ) < n+1 := by positivity + have h := Real.one_sub_inv_le_log_of_pos (div_pos hn1 hn0) + rw [Real.log_div (ne_of_gt hn1) (ne_of_gt hn0),inv_div] at h + have hh := mul_le_mul_of_nonneg_left h hn1.le + have hcancel : ((n:ℝ)+1)*(1-(n:ℝ)/(n+1)) = 1 := by field_simp; ring + rw [hcancel] at hh + have hi := ih (by omega) + rw [Nat.factorial_succ,Nat.cast_mul,Real.log_mul (by positivity) (by positivity),Nat.cast_add,Nat.cast_one] + nlinarith + +lemma log_modifiedNormalization (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) = + Real.log (Nat.factorial (2^(L+r))) - + ((2^(L+r):ℕ)*((r:ℝ)*Real.log 2)+((2:ℝ)^r-E.card)*Real.log (Nat.factorial (2^L))) := by + unfold modifiedNormalization + rw [Real.log_div (by positivity) (by positivity),Real.log_mul (by positivity) (by positivity), + Real.log_pow,Real.log_pow,Real.log_pow, + Nat.cast_sub (exception_card_le r E),Nat.cast_pow,Nat.cast_ofNat] + simp only [Nat.cast_pow,Nat.cast_ofNat] + +lemma log_modifiedNormalization_le (L r : ℕ) (E : Finset (Card r)) : + Real.log (modifiedNormalization L r E) ≤ + ((L+r:ℕ):ℝ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)) := by + have hN : 1 ≤ 2^(L+r) := one_le_pow₀ (by norm_num) + have hS : 1 ≤ 2^L := one_le_pow₀ (by norm_num) + have hu := log_factorial_upper hN + have hl := mul_le_mul_of_nonneg_left (log_factorial_lower hS) (by positivity : (0:ℝ) ≤ (2:ℝ)^r) + simp only [Nat.cast_pow,Nat.cast_ofNat,Real.log_pow,Nat.cast_add] at hu hl ⊢ + rw [log_modifiedNormalization] + simp only [pow_add,Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat] at hu hl ⊢ + nlinarith + +lemma modified_moment_exponential (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1+E.card*Real.log (Nat.factorial (2^L)))/1000 + + (2^(L+r):ℕ)*heightDecay L+3*((L*E.card*2^L:ℕ):ℝ)*Real.log momentBase) := by + apply (modifiedRowMoment_bound L r hL E e he).trans + rw [Real.rpow_def_of_pos (modifiedNormalization_pos L r E),←Real.exp_add] + apply Real.exp_le_exp.mpr + have h := log_modifiedNormalization_le L r E + linarith + +lemma log_power_factorial_le (L : ℕ) : + Real.log (Nat.factorial (2^L)) ≤ (2:ℝ)^L*L := by + have hf : (Nat.factorial (2^L):ℝ) ≤ ((2^L:ℕ):ℝ)^(2^L) := by + exact_mod_cast Nat.factorial_le_pow (2^L) + have hh := Real.log_le_log (by positivity) hf + rw [Real.log_pow,Nat.cast_pow,Nat.cast_ofNat,Real.log_pow] at hh + apply hh.trans + have hl := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + have hn : 0 ≤ (2:ℝ)^L*(L:ℝ) := by positivity + nlinarith + +lemma modified_moment_exception_bound (L r : ℕ) (hL : 0 < L) (E : Finset (Card r)) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (L+r)) (he : Function.Surjective e) + (ε : ℝ) (hE : (E.card:ℝ) ≤ ε*(2:ℝ)^r) : + modifiedRowMoment L r E e (1/1000) ≤ + Real.exp (((L+r:ℕ)*Real.log 2+1)/1000 + + (2:ℝ)^(L+r)*(heightDecay L+ε*L/250)) := by + apply (modified_moment_exponential L r hL E e he).trans + apply Real.exp_le_exp.mpr + have hs := mul_le_mul_of_nonneg_left (log_power_factorial_le L) (Nat.cast_nonneg E.card) + have hb := mul_le_mul_of_nonneg_left momentBase_log + (by positivity : (0:ℝ) ≤ 3*((L*E.card*2^L:ℕ):ℝ)) + have hexc := mul_le_mul_of_nonneg_left hE (by positivity : (0:ℝ) ≤ (2:ℝ)^L*L/250) + simp only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,pow_add] at hs hb hexc ⊢ + nlinarith + + +lemma heightDecay_tendsto : Filter.Tendsto heightDecay Filter.atTop (nhds 0) := by + have h : Filter.Tendsto (fun L : ℕ => (-(1:ℝ)/64)*(L:ℝ)) Filter.atTop Filter.atBot := + (Filter.tendsto_const_mul_atBot_of_neg (by norm_num : -(1:ℝ)/64 < 0)).mpr + tendsto_natCast_atTop_atTop + have ht := ((Real.tendsto_exp_atBot.comp h).const_mul 68).div_const (1-Real.exp (-(1:ℝ)/64)) + convert ht using 1 + · funext L + unfold heightDecay + dsimp only [Function.comp_apply] + rw [show -(L:ℝ)/64 = (-(1:ℝ)/64)*(L:ℝ) by ring] + · simp + +noncomputable def modifiedOverhead (L r : ℕ) : ℝ := + (((L+r:ℕ):ℝ)*Real.log 2+1)/((2:ℝ)^(L+r)*1000) + +lemma modifiedOverhead_tendsto (L : ℕ) : + Filter.Tendsto (modifiedOverhead L) Filter.atTop (nhds 0) := by + have h₁ := tendsto_pow_const_div_const_pow_of_one_lt 1 (by norm_num : (1:ℝ)<2) + have h₀ := tendsto_pow_const_div_const_pow_of_one_lt 0 (by norm_num : (1:ℝ)<2) + simp only [pow_one] at h₁ + simp only [pow_zero] at h₀ + have ht := ((h₁.const_mul (Real.log 2)).add (h₀.const_mul ((L:ℝ)*Real.log 2+1))).div_const + ((2:ℝ)^L*1000) + convert ht using 1 + · funext r + simp only [modifiedOverhead,Nat.cast_add,pow_add] + field_simp + ring + · simp + +theorem modified_arbitrarily_small_rate (η : ℝ) (hη : 0 < η) : + ∃ L : ℕ, 0 < L ∧ ∃ ε : ℝ, 0 < ε ∧ ε < 1/2 ∧ + ∀ᶠ r : ℕ in Filter.atTop, ∀ (E : Finset (Card r)), (E.card:ℝ) ≤ ε*(2:ℝ)^r → + ∀ (e : Card (L+r) ↪ Card (L+r)), + modifiedRowMoment L r E e (1/1000) ≤ Real.exp (η*(2:ℝ)^(L+r)) := by + have hsmall : ∀ᶠ L : ℕ in Filter.atTop, heightDecay L < η/3 := + heightDecay_tendsto.eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + obtain ⟨L,hdec,hL⟩ := (hsmall.and (Filter.eventually_ge_atTop 1)).exists + have hL0 : (0:ℝ) < L := Nat.cast_pos.mpr hL + let ε : ℝ := min (1/4) (η*250/(3*L)) + have hε : 0 < ε := lt_min (by norm_num) (by positivity) + have hε1 : ε < 1/2 := (min_le_left _ _).trans_lt (by norm_num) + have hεL : ε*L/250 ≤ η/3 := by + have h := min_le_right (1/4:ℝ) (η*250/(3*L)) + change ε ≤ η*250/(3*L) at h + have hh := mul_le_mul_of_nonneg_right h hL0.le + have he : (η*250/(3*(L:ℝ)))*(L:ℝ)/250 = η/3 := by field_simp + exact (div_le_div_of_nonneg_right hh (by norm_num)).trans he.le + refine ⟨L,hL,ε,hε,hε1,?_⟩ + have hr : ∀ᶠ r : ℕ in Filter.atTop, modifiedOverhead L r < η/3 := + (modifiedOverhead_tendsto L).eventually (gt_mem_nhds (by linarith : (0:ℝ)<η/3)) + filter_upwards [hr] with r hr + intro E hE e + have he := Finite.surjective_of_injective e.injective + apply (modified_moment_exception_bound L r hL E e he ε hE).trans + apply Real.exp_le_exp.mpr + have hn : (0:ℝ) < (2:ℝ)^(L+r) := by positivity + have hd : modifiedOverhead L r * (2:ℝ)^(L+r) = + (((L+r:ℕ):ℝ)*Real.log 2+1)/1000 := by + unfold modifiedOverhead + field_simp + have hh := mul_le_mul_of_nonneg_right hr.le hn.le + rw [hd] at hh + have ht := mul_le_mul_of_nonneg_left (show heightDecay L+ε*L/250 ≤ 2*η/3 by linarith) hn.le + linarith + + +namespace DensityTransfer +open scoped BigOperators + +noncomputable def applyKernel {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + +lemma applyKernel_apply {X : Type*} [Fintype X] (P : X → X → ℝ) + (v : EuclideanSpace ℂ X) (x : X) : + applyKernel P v x = ∑ y, (P x y : ℂ)*v y := rfl + +lemma applyKernel_add {X : Type*} [Fintype X] (P Q : X → X → ℝ) + (v : EuclideanSpace ℂ X) : + applyKernel (fun x y => P x y+Q x y) v = applyKernel P v+applyKernel Q v := by + ext x + simp only [applyKernel_apply,Complex.ofReal_add,add_mul,Finset.sum_add_distrib] + rfl + +lemma kernel_component_sq {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (v : EuclideanSpace ℂ X) (x : X) : + ‖applyKernel P v x‖^2 ≤ (∑ y, P x y) * ∑ y, P x y*‖v y‖^2 := by + have hs : ‖applyKernel P v x‖ ≤ ∑ y, P x y*‖v y‖ := by + rw [applyKernel_apply] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hP x y)] + apply (pow_le_pow_left₀ (norm_nonneg _) hs 2).trans + exact Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (fun y _ => hP x y) (fun y _ => mul_nonneg (hP x y) (sq_nonneg _)) + (fun y _ => by ring_nf; exact le_rfl) + +lemma schur_bound {X : Type*} [Fintype X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (δ : ℝ) (hδ : 0 ≤ δ) + (hrow : ∀ x, ∑ y, P x y ≤ δ) (hcol : ∀ y, ∑ x, P x y ≤ δ) + (v : EuclideanSpace ℂ X) : ‖applyKernel P v‖ ≤ δ*‖v‖ := by + have hsq : ‖applyKernel P v‖^2 ≤ δ^2*‖v‖^2 := by + rw [EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq] + calc + _ ≤ ∑ x, δ * ∑ y, P x y*‖v y‖^2 := by + apply Finset.sum_le_sum + intro x _ + apply (kernel_component_sq P hP v x).trans + exact mul_le_mul_of_nonneg_right (hrow x) + (Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (sq_nonneg _))) + _ = δ * ∑ y, (∑ x, P x y)*‖v y‖^2 := by + rw [←Finset.mul_sum,Finset.sum_comm] + congr 1 + apply Finset.sum_congr rfl + intro y _ + exact (Finset.sum_mul Finset.univ _ _).symm + _ ≤ δ * ∑ y, δ*‖v y‖^2 := by + apply mul_le_mul_of_nonneg_left _ hδ + exact Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_right (hcol y) (sq_nonneg _)) + _ = _ := by rw [←Finset.mul_sum]; ring + have hn := norm_nonneg (applyKernel P v) + have hr := mul_nonneg hδ (norm_nonneg v) + nlinarith + +lemma hilbert_schmidt_family {X I : Type*} [Fintype X] [Fintype I] + (P : X → X → ℝ) (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) : + (∑ i, ‖applyKernel P (v i)‖^2) ≤ ∑ x, ∑ y, (P x y)^2 := by + simp_rw [EuclideanSpace.norm_sq_eq] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro x _ + let w : EuclideanSpace ℂ X := WithLp.toLp 2 (fun y => (P x y : ℂ)) + have he (i : I) : ‖applyKernel P (v i) x‖ = ‖inner ℂ (v i) w‖ := by + rw [norm_inner_symm] + congr 1 + simp only [applyKernel_apply,PiLp.inner_apply] + apply Finset.sum_congr rfl + intro y _ + simp [w,RCLike.inner_apply,mul_comm] + simp_rw [he] + have h := hv.sum_inner_products_le (s := Finset.univ) w + apply h.trans_eq + rw [EuclideanSpace.norm_sq_eq] + apply Finset.sum_congr rfl + intro y _ + simp [w,Complex.norm_real,Real.norm_eq_abs,sq_abs] + + +lemma tail_density_pointwise (t a z : ℝ) (ht : 0 ≤ t) (ha : 0 ≤ a) (hz : 0 < z) : + (if z < t then t else 0) ≤ t^(1+a)*z^(-a) := by + split_ifs with h + · rw [Real.rpow_neg hz.le,←div_eq_mul_inv] + apply (le_div_iff₀ (Real.rpow_pos_of_pos hz a)).mpr + rw [Real.rpow_add (lt_trans hz h),Real.rpow_one] + exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hz.le h.le ha) ht + · positivity + +lemma tail_density_mean {X : Type*} [Fintype X] (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + (a z : ℝ) (ha : 0 ≤ a) (hz : 0 < z) : + finiteMean (fun x => if z < f x then f x else 0) ≤ finiteMean (fun x => f x^(1+a))*z^(-a) := by + rw [←finiteMean_mul_const] + exact finiteMean_mono (fun x => tail_density_pointwise (f x) a z (hf x) ha hz) + +noncomputable def tailKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then P x y else 0 + +noncomputable def headKernel {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : X → X → ℝ := + fun x y => if z < (Fintype.card X:ℝ)*P x y then 0 else P x y + +lemma tail_add_head {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) : + (fun x y => tailKernel P z x y+headKernel P z x y) = P := by + funext x y + unfold tailKernel headKernel + split_ifs <;> simp + +lemma tailKernel_nonneg {X : Type*} [Fintype X] (P : X → X → ℝ) (z : ℝ) + (hP : ∀ x y, 0 ≤ P x y) (x y : X) : 0 ≤ tailKernel P z x y := by + unfold tailKernel + split_ifs <;> simp only [hP,le_refl] + +lemma tailKernel_row {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) (x : X) : + ∑ y, tailKernel P z x y ≤ M*z^(-a) := by + have hn : (Fintype.card X:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have he : finiteMean (fun y => if z < (Fintype.card X:ℝ)*P x y then + (Fintype.card X:ℝ)*P x y else 0) = ∑ y, tailKernel P z x y := by + unfold finiteMean + calc + _ = (∑ y, (Fintype.card X:ℝ)*tailKernel P z x y)/(Fintype.card X:ℝ) := by + congr 1 + apply Finset.sum_congr rfl + intro y _ + by_cases hy : z < (Fintype.card X:ℝ)*P x y + · simp only [tailKernel,hy,↓reduceIte] + · simp only [tailKernel,hy,↓reduceIte,mul_zero] + _ = _ := by rw [←Finset.mul_sum]; field_simp + rw [←he] + exact (tail_density_mean _ (fun y => mul_nonneg (Nat.cast_nonneg _) (hP x y)) a z ha hz).trans + (mul_le_mul_of_nonneg_right (hM x) (Real.rpow_nonneg hz.le _)) + +lemma tailKernel_schur {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : EuclideanSpace ℂ X) : + ‖applyKernel (tailKernel P z) v‖ ≤ (M*z^(-a))*‖v‖ := by + apply schur_bound _ (tailKernel_nonneg P z hP) _ (by positivity) + (tailKernel_row P hP a z M ha hz hM) + intro y + have hs : (fun x => tailKernel P z x y) = (fun x => tailKernel P z y x) := by + funext x + simp only [tailKernel,hsym x y] + rw [hs] + exact tailKernel_row P hP a z M ha hz hM y + +lemma headKernel_hs {X : Type*} [Fintype X] [Nonempty X] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hrow : ∀ x, ∑ y, P x y = 1) (z : ℝ) (hz : 0 ≤ z) : + (∑ x, ∑ y, (headKernel P z x y)^2) ≤ z := by + have hn : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have he (x y : X) : (headKernel P z x y)^2 ≤ (z/(Fintype.card X:ℝ))*P x y := by + unfold headKernel + split_ifs with h + · simp only [zero_pow (by omega : (2:ℕ) ≠ 0)] + exact mul_nonneg (div_nonneg hz hn.le) (hP x y) + · have h' : (Fintype.card X:ℝ)*P x y ≤ z := le_of_not_gt h + have hh := mul_le_mul_of_nonneg_right h' (hP x y) + rw [show (z/(Fintype.card X:ℝ))*P x y = (z*P x y)/(Fintype.card X:ℝ) by ring] + apply (le_div_iff₀ hn).mpr + nlinarith + calc + _ ≤ ∑ x, ∑ y, (z/(Fintype.card X:ℝ))*P x y := + Finset.sum_le_sum (fun x _ => Finset.sum_le_sum (fun y _ => he x y)) + _ = z := by + simp only [←Finset.mul_sum,hrow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + + +theorem multiplicity_amplification {X I : Type*} [Fintype X] [Nonempty X] + [Fintype I] [Nonempty I] (P : X → X → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (hsym : ∀ x y, P x y = P y x) + (hrow : ∀ x, ∑ y, P x y = 1) (a z M : ℝ) (ha : 0 ≤ a) (hz : 0 < z) (hM0 : 0 ≤ M) + (hM : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*P x y)^(1+a)) ≤ M) + (v : I → EuclideanSpace ℂ X) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖applyKernel P (v i)‖) : + μ ≤ M*z^(-a)+Real.sqrt (z/(Fintype.card I:ℝ)) := by + let δ : ℝ := M*z^(-a) + have hδ : 0 ≤ δ := by dsimp [δ]; positivity + have hm : (0:ℝ) < Fintype.card I := Nat.cast_pos.mpr Fintype.card_pos + change μ ≤ δ+_ + by_cases hμ : μ ≤ δ + · exact hμ.trans (le_add_of_nonneg_right (Real.sqrt_nonneg _)) + have hmd : 0 ≤ μ-δ := by linarith + have hsmall (i : I) : μ-δ ≤ ‖applyKernel (headKernel P z) (v i)‖ := by + have hr := tailKernel_schur P hP hsym a z M ha hz hM0 hM (v i) + rw [hv.norm_eq_one i,mul_one] at hr + have he := applyKernel_add (tailKernel P z) (headKernel P z) (v i) + rw [tail_add_head] at he + have hn := norm_add_le (applyKernel (tailKernel P z) (v i)) (applyKernel (headKernel P z) (v i)) + rw [←he] at hn + have hh := hvμ i + change ‖applyKernel (tailKernel P z) (v i)‖ ≤ δ at hr + linarith + have hsum : (Fintype.card I:ℝ)*(μ-δ)^2 ≤ z := by + calc + _ = ∑ i : I, (μ-δ)^2 := by simp + _ ≤ ∑ i : I, ‖applyKernel (headKernel P z) (v i)‖^2 := + Finset.sum_le_sum (fun i _ => pow_le_pow_left₀ hmd (hsmall i) 2) + _ ≤ ∑ x, ∑ y, (headKernel P z x y)^2 := hilbert_schmidt_family _ v hv + _ ≤ z := headKernel_hs P hP hrow z hz.le + have hsq : (μ-δ)^2 ≤ z/(Fintype.card I:ℝ) := (le_div_iff₀ hm).mpr (by nlinarith) + have hs := (Real.le_sqrt hmd (div_nonneg hz.le hm.le)).mpr hsq + linarith + +end DensityTransfer +namespace PairRouting +open scoped BigOperators + +lemma tupleProbability_row_sum {ι β Ω : Type*} [Fintype ι] [Fintype β] + [DecidableEq β] [Fintype Ω] [Nonempty Ω] + (P : Ω → Equiv.Perm β) (e : ι ↪ β) : + (∑ f : ι ↪ β, tupleProbability P e f) = 1 := by + classical + simp only [tupleProbability] + rw [←finiteMean_sum] + have h (ω : Ω) (f : ι ↪ β) : (∀ i, P ω (e i) = f i) ↔ e.trans (P ω).toEmbedding = f := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun g : ι ↪ β => g i) h + simp_rw [h] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +lemma tupleProbability_inverse {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (e f : ι → β) : + tupleProbability (fun ω => (P ω)⁻¹) e f = tupleProbability P f e := by + classical + apply finiteMean_congr + intro ω + congr 1 + apply propext + constructor + · intro h i + have hh := congrArg (P ω) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] using hh.symm + · intro h i + have hh := congrArg (fun x => (P ω).symm x) (h i) + simpa only [Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + +lemma tupleProbability_equiv {ι β Ω Ω' : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] [Fintype Ω'] (P : Ω → Equiv.Perm β) (τ : Ω ≃ Ω') (e f : ι → β) : + tupleProbability P e f = tupleProbability (fun ω => P (τ.symm ω)) e f := + finiteMean_equiv τ _ + +lemma tupleProbability_symmetric {ι β Ω : Type*} [Fintype ι] [DecidableEq β] + [Fintype Ω] (P : Ω → Equiv.Perm β) (τ : Equiv.Perm Ω) + (hτ : ∀ ω, P (τ ω) = (P ω)⁻¹) (e f : ι → β) : + tupleProbability P e f = tupleProbability P f e := by + rw [tupleProbability_equiv P τ.symm] + simp only [Equiv.symm_symm,hτ] + exact tupleProbability_inverse P e f + +end PairRouting + +lemma palindromePerm_reverse (d : ℕ) (ω : BenesCoins d) : + palindromePerm d (ω.2,ω.1) = (palindromePerm d ω)⁻¹ := by + simp only [palindromePerm,mul_inv_rev] + rfl + +lemma palindrome_kernel_symmetric (d : ℕ) {ι : Type*} [Fintype ι] + (e f : ι ↪ Card d) : + PairRouting.tupleProbability (palindromePerm d) e f = + PairRouting.tupleProbability (palindromePerm d) f e := + PairRouting.tupleProbability_symmetric _ (Equiv.prodComm _ _) (palindromePerm_reverse d) e f + +theorem palindrome_density_transfer (d : ℕ) {ι I : Type*} [Fintype ι] [Fintype I] + [Nonempty I] (e₀ : ι ↪ Card d) (hk : 0 < Fintype.card ι) + (v : I → EuclideanSpace ℂ (ι ↪ Card d)) (hv : Orthonormal ℂ v) + (μ : ℝ) (hvμ : ∀ i, μ ≤ ‖DensityTransfer.applyKernel + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) (v i)‖) + (z : ℝ) (hz : 0 < z) : + μ ≤ Real.exp (densityConstant*Fintype.card ι* + ((Fintype.card ι:ℝ)/(2:ℝ)^d)^(1/512:ℝ))*z^(-(1/1000:ℝ))+ + Real.sqrt (z/(Fintype.card I:ℝ)) := by + let : Nonempty (ι ↪ Card d) := ⟨e₀⟩ + apply DensityTransfer.multiplicity_amplification + (fun e f : ι ↪ Card d => PairRouting.tupleProbability (palindromePerm d) e f) + (fun e f => PairRouting.tupleProbability_nonneg _ e f) + (palindrome_kernel_symmetric d) (PairRouting.tupleProbability_row_sum _) + (1/1000) z _ (by norm_num) hz (Real.exp_nonneg _) _ v hv μ hvμ + intro e + exact palindrome_row_moment_bound d e hk + + +noncomputable def modifiedReverseCoins (L : ℕ) : (r : ℕ) → ModifiedCoins L r → ModifiedCoins L r + | 0, ω => ((fun u => butterflyPerm L (decodeButterfly L ω.2.1) * (ω.1 u)⁻¹ * + butterflyPerm L (decodeButterfly L ω.2.1)),ω.2) + | r+1, ω => + let z := modifiedStepEquiv L r ω + (modifiedStepEquiv L r).symm + ((modifiedReverseCoins L r z.1.1,modifiedReverseCoins L r z.1.2),(z.2.2,z.2.1)) + +lemma modifiedReverseCoins_involutive (L r : ℕ) : + Function.Involutive (modifiedReverseCoins L r) := by + induction r with + | zero => + intro ω + apply Prod.ext + · funext u + simp only [modifiedReverseCoins,mul_inv_rev,inv_inv] + simp [mul_assoc] + · rfl + | succ r ih => + change ∀ ω, modifiedReverseCoins L r (modifiedReverseCoins L r ω) = ω at ih + intro ω + simp only [modifiedReverseCoins,Equiv.apply_symm_apply,ih] + exact (modifiedStepEquiv L r).symm_apply_apply ω + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedStageEquiv.lean b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedStageEquiv.lean index 13ad57c4526c43799816178fd6435d60f169afe4..59d7098af0723459ab6ed5ac4c2ff73d00e9e302 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ModifiedStageEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ModifiedStageEquiv.lean @@ -1,875 +1,875 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.BlockProduct - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators Classical - -def modifiedStageEquiv (r L : ℕ) : - ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ - ModifiedCoins L r := - (modifiedAssembleEquiv _ _ _ _).trans - (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) - -lemma modifiedStageEquiv_apply (r L : ℕ) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - modifiedStageEquiv r L w= - ((fun b => (w.1.2 b).1), - (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, - assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by - simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, - Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] - -lemma palindrome_stage (r L : ℕ) - (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : - splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [palindromeStageEquiv_apply] - change splitPerm r L (_*_⁻¹)=_ - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - rfl - -noncomputable def localModifiedPerm (L : ℕ) (e : Bool) - (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := - if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ - -lemma modified_stage (r L : ℕ) (E : Finset (Card r)) - (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : - splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= - outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := by - rw [modifiedStageEquiv_apply] - unfold modifiedPerm modifiedInputTree - rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] - rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] - congr 2 - apply congrArg ParallelBlocks.lift - funext b - simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] - by_cases h : b∈E <;> simp [h] - -end Thorp -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= - sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by - rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), - sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] - -lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : - sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by - cases e - · simp only [Bool.false_eq_true,ite_false] - rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] - exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) - · simp only [ite_true] - exact sampleOperator_one ρ - -end Thorp.UnitaryFinite - -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma sampleOperator_palindrome_stage (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* - (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) - -lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : - sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= - sampleOperator ρ (outerPerm r L)* - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* - (sampleOperator ρ (outerPerm r L)).adjoint := by - have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= - fun w => outerPerm r L w.1.1*ParallelBlocks.lift - (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := - funext (modified_stage r L E) - calc - _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := - (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm - _ = _ := (congrArg (sampleOperator ρ) he).trans - (sampleOperator_sandwich ρ hρ (outerPerm r L) - (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) - -end Thorp -namespace Thorp.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] [DecidableEq ι] - -noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1 else P i - -omit [CompleteSpace V] [Fintype ι] in -lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) - (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by - unfold retain - split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ - -omit [CompleteSpace V] in -lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : - blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by - have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E - have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right - (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) - simp only [hs] at hh - change blocks (retain P E) (retain_commute P hP E)=_ at hh - rw [hh] - have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by - exact (Finset.noncommProd_eq_pow_card E (retain P E) - (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) - rw [he,one_mul] - apply Finset.noncommProd_congr rfl - intro i hi - exact ite_eq_right (Finset.mem_compl.mp hi) - -end Thorp.CommutingBlocks - -namespace Thorp.ParallelBlocks -open scoped BigOperators Classical -open UnitaryFinite -variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := - uniformOperator (ρ.comp (injection b)) - -omit [Fintype B] in -lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : - Commute (centralProjection ρ b) (centralProjection ρ c) := by - simpa only [centralProjection,sampleOperator_uniform] using - local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c - -omit [Fintype B] in -lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] - (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : - Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by - by_cases h : b=c - · subst c - change _*uniformOperator _=uniformOperator _*_ - rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] - · unfold centralProjection - rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] - exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) - -end Thorp.ParallelBlocks -namespace Thorp -open scoped BigOperators Classical -open UnitaryFinite ParallelBlocks CommutingBlocks -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : - sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => - lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= - coarse (centralProjection ρ) (centralProjection_commute ρ) E := by - rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] - apply Finset.noncommProd_congr rfl - · intro b _ - rw [localModified_average] - simp only [retain,centralProjection,decide_eq_true_eq] - · intro b _ c _ _ - exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c - -lemma central_local_gap (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : - ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by - change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ - rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] - exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) - -lemma central_blocks_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) - (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : - ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) - (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) - (local_average_commute ρ (fun _ => palindromePerm L)) - (local_central_commute ρ (fun _ => palindromePerm L)) - (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) - (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) - B.adjoint hB n - simpa only [ContinuousLinearMap.adjoint_adjoint] using h - -theorem palindrome_exception_bound (r L : ℕ) - (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : - ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ - (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] - apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) - (sampleOperator_norm_le ρ hρ _) n).trans_eq - congr 1 - apply Finset.sum_congr rfl - intro E _ - split_ifs - · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] - · rfl - -end Thorp - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] - -noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := - finiteMean (fun ω => if a (P ω) x=y then 1 else 0) - -omit [Fintype G] in -lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) - (v : EuclideanSpace ℂ X) (x : X) : - DensityTransfer.applyKernel (actionKernel a P) v x = - (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by - simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, - Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] - rw [Finset.sum_comm] - calc - _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by - apply Finset.sum_congr rfl - intro ω _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all - _ = _ := by simp [Finset.mul_sum] - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : - DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = - normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by - ext x - rw [actionKernel_apply] - simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, - coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, - inner_smul_right,inner_sum] - apply Finset.sum_congr rfl - intro ω _ - have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x - change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = - inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h - rw [h] - ring - -noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : - Submodule ℂ V where - carrier := {w | IsFixed a x₀ ρ w} - zero_mem' := fun g hg => map_zero _ - add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] - smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] - -theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : - ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - let K := fixedSpace a x₀ ρ - let m := Module.finrank ℂ K - let : Nonempty X := ⟨x₀⟩ - let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ - let B := stdOrthonormalBasis ℂ K - let w : Fin m → V := fun i => (B i : V) - have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 - have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ - have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv - have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) - (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by - rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), - normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] - have h := DensityTransfer.multiplicity_amplification (actionKernel a P) - (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow - b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) - simpa only [Fintype.card_fin] using h - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where - toFun p := - { toFun := fun e => e.trans p.toEmbedding - invFun := fun e => e.trans p.symm.toEmbedding - left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) - right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } - map_one' := by ext e i; rfl - map_mul' p q := by ext e i; rfl - -omit [Fintype α] [Fintype ι] in -@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : - tupleAction p e i=p (e i) := rfl - -omit [Fintype α] in -lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by - obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective - exact ⟨p,Function.Embedding.ext hp⟩ - -omit [Fintype α] in -lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : - tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by - constructor - · intro h x hx - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx - exact congrArg (fun f : ι ↪ α => f i) h - · intro h - ext i - exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - -omit [Fintype α] in -lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) - (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by - unfold actionKernel PairRouting.tupleProbability - congr 1 - funext ω - congr 1 - exact propext Function.Embedding.ext_iff - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -lemma irreducible_of_equiv {G V W : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : - Representation.IsIrreducible σ := by - rw [Representation.irreducible_iff_isSimpleModule_asModule] - have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance - let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := - Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap - have hf : Function.Bijective f := e.toLinearEquiv.bijective - exact (f.isSimpleModule_iff_of_bijective hf).mp hi - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) - (v : hilbertSpace μ) : - (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = - PermutationHilbert.act (tabloidAct p) v := by - obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v - change hilbertEquiv μ (tabloidRep μ p w) = _ - exact hilbert_action μ p w - -noncomputable def unitaryEquiv (μ : YoungDiagram) : - Representation.Equiv (representation μ) (unitaryRepresentation μ) := - Representation.Equiv.mk (spaceHilbertEquiv μ) (by - intro p - apply LinearMap.ext - intro v - change spaceHilbertEquiv μ (representation μ p v) = - spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) - rw [LinearEquiv.symm_apply_apply]) - -lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : - Representation.IsIrreducible (unitaryRepresentation μ) := by - let := representation_irreducible μ - exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) - -lemma unitaryRepresentation_unitary (μ : YoungDiagram) : - UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by - intro p v w - change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) - (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ - rw [unitaryRepresentation_coe,unitaryRepresentation_coe] - exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w - - -noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] - fixedHilbert μ (Finset.univ.image e) where - toFun v := ⟨v.1.1,v.1.2,by - intro p hp - have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) - exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ - invFun v := ⟨⟨v.1,v.2.1⟩,by - intro p hp - apply Subtype.ext - exact (unitaryRepresentation_coe μ p _).trans - (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] - (e : ι ↪ Cell μ) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] - have h := fixedHilbert_dimension μ (Finset.univ.image e) - simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h - -end Thorp.Specht -namespace Thorp.UnitaryFinite -open scoped BigOperators Classical - -variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : - sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by - simp only [sampleOperator,randomOperator,smul_apply, - sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] - -theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : - ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) - intro v hv - rw [sampleOperator_inv_apply] - exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : - Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where - toFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun g v hv => by - have h := U.apply_mem_toSubmodule (e.symm g) hv - change ρ (e (e.symm g)) v∈U.toSubmodule at h - simpa only [e.apply_symm_apply] using h } - invFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } - left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - map_rel_iff' := Iff.rfl - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by - exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance - -end Thorp.UnitaryFinite - -namespace Thorp.Specht -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -omit [Fintype α] in -lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : - UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by - intro g v w - exact unitaryRepresentation_unitary μ (e.permCongr g) v w - -omit [Fintype α] in -lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : - Representation.IsIrreducible (relabelledUnitary μ e) := by - let := unitaryRepresentation_irreducible μ - exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom - -noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] - UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where - toFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg - change g (e (f i))=e (f i) at hh - simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] - have hh := v.2 (e.symm.permCongr g) hp - change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh - have he : e.permCongr (e.symm.permCongr g)=g := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] - simpa only [he] using hh⟩ - invFun v := ⟨v.1,by - intro g hg - have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by - apply Function.Embedding.ext - intro i - have hh := congrArg (fun f : ι ↪ α => f i) hg - change g (f i)=f i at hh - simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, - Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] - exact v.2 (e.permCongr g) hp⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -omit [Fintype α] in -lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : - Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * - μ.card.choose (μ.card-μ.rowLen 0) := by - rw [(relabelledTupleFixed μ e f).finrank_eq] - exact tupleFixed_dimension μ (f.trans e.toEmbedding) - -end Thorp.Specht - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) - (hG : ∀ v, ∃ w, G.Adj v w) : - ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ - ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by - classical - obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le - let c := hF.coloringTwo - have hneigh (v : V) : ∃ w, F.Adj v w := by - obtain ⟨w, hvw⟩ := hG v - have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable - exact hr.nonempty_neighborSet_left hvw.ne - let A : Finset V := Finset.univ.filter (fun v => c v = 0) - let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) - have hab : A.card + B.card = Fintype.card V := by - exact Finset.card_filter_add_card_filter_not _ - have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw - by_cases h : A.card ≤ B.card - · refine ⟨A, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v ≠ 0 := by simpa [A] using hv - have hw0 : c w = 0 := by - have hv1 : c v = 1 := by omega - have hn := hcolor hvw - omega - exact ⟨w, by simp [A, hw0], hFG hvw⟩ - · refine ⟨B, by omega, ?_⟩ - intro v hv - obtain ⟨w, hvw⟩ := hneigh v - have hv0 : c v = 0 := by simpa [B] using hv - have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm - exact ⟨w, by simp [B, hw0], hFG hvw⟩ - -lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : - (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by - rw [← Finset.prod_one_add, Real.exp_sum] - apply Finset.prod_le_prod₀ - · intro v _; exact add_nonneg (by norm_num) (hp v) - · intro v _ - have h := Real.add_one_le_exp (p v) - linarith - -lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : - (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ - δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by - have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : - (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by - rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] - field_simp - calc - _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by - rw [Finset.mul_sum] - exact Finset.sum_congr rfl hsplit - _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by - apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro L hL - exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 - · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) - _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := - mul_le_mul_of_nonneg_left - (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) - (pow_nonneg hδ.le _) - _ = _ := by rw [Finset.sum_div] - -noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) - (R : Finset V) : Finset V := by - classical - exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) - -lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : - (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by - classical - calc - _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum - intro w hw - obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 - have h : (if G.Adj v w then p w else 0) ≤ - ∑ u ∈ R, if G.Adj u w then p w else 0 := - Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv - simpa only [ite_eq_left hvw] using h - _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro w _ _ - exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) - _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm - _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) - _ = _ := by simp - -lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) - (R : Finset V) (hR : 2 * R.card ≤ k) : - (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ - δ^((k:ℝ)/2) * Real.exp R.card := by - classical - have hmass := neighborhood_weight_le G p hp δ hdeg R - have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by - rw [← Real.rpow_natCast] - apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 - have hr : R.card ≤ k := by omega - rw [Nat.cast_sub hr] - have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR - linarith - apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans - apply mul_le_mul hpow - · apply Real.exp_le_exp.mpr - exact (div_le_iff₀ hδ).mpr hmass - · positivity - · positivity - -def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := - ∀ v ∈ S, ∃ w ∈ S, G.Adj v w - -lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) - (S : Finset V) (hS : NoIsolated G S) : - ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by - classical - let H := G.induce (S : Set V) - have hH : ∀ v : S, ∃ w : S, H.Adj v w := by - intro v - obtain ⟨w, hw, hvw⟩ := hS v v.2 - exact ⟨⟨w, hw⟩, hvw⟩ - obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH - let T := R.image (fun v : S => (v : V)) - have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective - refine ⟨T, ?_, ?_, ?_⟩ - · intro v hv - obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv - exact w.2 - · simpa [hc, H] using hR - · intro v hv - have hvS := (Finset.mem_sdiff.mp hv).1 - have hvR : (⟨v, hvS⟩ : S) ∉ R := by - intro hh - exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) - obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR - exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, - ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ - -lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) - (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) - (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - let root (S : I) := (small_dominating_subset G S.val S.property.2).choose - have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ - S.val \ root S ⊆ neighborhood G (root S) := by - simpa only [root, S.property.1] using - (small_dominating_subset G S.val S.property.2).choose_spec - let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) - have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := - Finset.union_sdiff_of_subset (hroot S).1 - have hinj : Function.Injective enc := by - intro S T h - apply Subtype.ext - rw [← hrec S, ← hrec T, h] - let W (z : Finset V × Finset V) : ℝ := - if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) - then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 - have hW (z : Finset V × Finset V) : 0 ≤ W z := by - dsimp [W] - split_ifs - · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) - (Finset.prod_nonneg (fun v _ => hp v)) - · exact le_rfl - have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by - have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by - refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ - change (S.val \ root S).card = k-(root S).card - rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] - dsimp only [W] - rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] - exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) - have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by - calc - _ = ∑ z ∈ Finset.univ.image enc, W z := by - rw [Finset.sum_image (fun S _ T _ h => hinj h)] - exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun z _ _ => hW z) - apply hsum.trans - rw [Fintype.sum_prod_type] - calc - (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ - ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by - apply Finset.sum_le_sum - intro R _ - by_cases hR : 2*R.card ≤ k - · have he : (∑ L : Finset V, W (R,L)) = - (∏ v ∈ R, p v) * - ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by - simp only [W, hR, true_and] - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] - rw [he] - have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) - (Finset.prod_nonneg (s := R) (fun v _ => hp v)) - simpa only [mul_comm, mul_left_comm, mul_assoc] using h - · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] - exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) - (Finset.prod_nonneg (fun v _ => hp v)) - _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro R _ - rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] - simp only [mul_one, mul_assoc] - _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) - simpa only [Finset.powerset_univ] using - powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) - (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) - _ = _ := by rw [← Finset.mul_sum] - - -lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] - (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) - (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) - (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) - (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) - (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : - finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ - δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by - classical - let I := {S : Finset V // S.card = k ∧ NoIsolated G S} - calc - _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by - apply finiteMean_mono - intro ω - split_ifs with h - · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) - (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) - · positivity - _ = ∑ S : I, inclusionMoment O S.val := by - rw [finiteMean_sum] - rfl - _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) - _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg - -noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : Finset (N × X) := by - classical - exact Finset.univ.filter (fun v => v.2 ∈ A v.1) - -@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by - classical - simp [typedSet] - -noncomputable def fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) : Finset X := by - classical - exact Finset.univ.filter (fun x => (t,x) ∈ S) - -@[simp] lemma mem_fiber {N X : Type*} [Fintype X] - (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by - classical - simp [fiber] - -lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] - (S : Finset (N × X)) : typedSet (fiber S) = S := by - classical - ext v - simp - -lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (p : N × X → ℝ) : - (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by - classical - simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] - apply Finset.prod_congr rfl - intro t _ - rw [← Finset.prod_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by - classical - simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - -lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] - (A : N → Finset X) (D : Finset (N × X)) : - D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by - constructor - · intro h t x hx - exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) - · intro h v hv - exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) - -end Thorp.SparseContact - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.BlockProduct + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators Classical + +def modifiedStageEquiv (r L : ℕ) : + ((OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) ≃ + ModifiedCoins L r := + (modifiedAssembleEquiv _ _ _ _).trans + (Equiv.prodCongr (Equiv.refl _) (Equiv.prodCongr (parallelSplitCoinEquiv r L) (parallelSplitCoinEquiv r L))) + +lemma modifiedStageEquiv_apply (r L : ℕ) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + modifiedStageEquiv r L w= + ((fun b => (w.1.2 b).1), + (assembleBits r L (fun x => (w.1.2 x.1).2.1 x.2) w.1.1, + assembleBits r L (fun x => (w.1.2 x.1).2.2 x.2) w.2)) := by + simp only [modifiedStageEquiv,Equiv.trans_apply,Equiv.prodCongr_apply,modifiedAssembleEquiv, + Equiv.coe_fn_mk,Prod.map_apply,Equiv.refl_apply,parallelSplitCoinEquiv_apply] + +lemma palindrome_stage (r L : ℕ) + (w : (OuterCoins r L × (Card r → BenesCoins L)) × OuterCoins r L) : + splitPerm r L (palindromePerm (L+r) (palindromeStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [palindromeStageEquiv_apply] + change splitPerm r L (_*_⁻¹)=_ + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_butterfly,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + rfl + +noncomputable def localModifiedPerm (L : ℕ) (e : Bool) + (w : Equiv.Perm (Card L) × BenesCoins L) : Equiv.Perm (Card L) := + if e then 1 else butterflyPerm L (decodeButterfly L w.2.1)*w.1⁻¹ + +lemma modified_stage (r L : ℕ) (E : Finset (Card r)) + (w : (OuterCoins r L × (Card r → Equiv.Perm (Card L) × BenesCoins L)) × OuterCoins r L) : + splitPerm r L (modifiedPerm L r E (modifiedStageEquiv r L w))= + outerPerm r L w.1.1*ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := by + rw [modifiedStageEquiv_apply] + unfold modifiedPerm modifiedInputTree + rw [map_mul,map_inv,splitPerm_butterfly,splitPerm_boundaryTree,mul_inv_rev] + rw [mul_assoc,←mul_assoc (ParallelBlocks.lift _),←map_inv,←map_mul,←mul_assoc] + congr 2 + apply congrArg ParallelBlocks.lift + funext b + simp only [Pi.mul_apply,Pi.inv_apply,modifiedBoundary,boundaryOutput_split,localModifiedPerm] + by_cases h : b∈E <;> simp [h] + +end Thorp +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +lemma sampleOperator_sandwich (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun w : (Ω × Ξ) × Ω => P w.1.1*Q w.1.2*(P w.2)⁻¹)= + sampleOperator ρ P*sampleOperator ρ Q*(sampleOperator ρ P).adjoint := by + rw [sampleOperator_prod ρ (fun w : Ω × Ξ => P w.1*Q w.2) (fun w : Ω => (P w)⁻¹), + sampleOperator_prod ρ P Q,sampleOperator_inv ρ hρ] + +lemma localModified_average (L : ℕ) (ρ : Representation ℂ (Equiv.Perm (Card L)) V) (e : Bool) : + sampleOperator ρ (localModifiedPerm L e)=if e then 1 else uniformOperator ρ := by + cases e + · simp only [Bool.false_eq_true,ite_false] + rw [←sampleOperator_equiv ρ _ (Equiv.prodComm _ _)] + exact sampleOperator_uniform_mul ρ (fun w : BenesCoins L => butterflyPerm L (decodeButterfly L w.1)) + · simp only [ite_true] + exact sampleOperator_one ρ + +end Thorp.UnitaryFinite + +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma sampleOperator_palindrome_stage (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift (fun b => palindromePerm L (w.1.2 b))* + (outerPerm r L w.2)⁻¹ := funext (palindrome_stage r L) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) ∘ palindromeStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ palindromePerm (L+r)) (palindromeStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → BenesCoins L => ParallelBlocks.lift (fun b => palindromePerm L (w b)))) + +lemma sampleOperator_modified_stage (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) : + sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (modifiedPerm L r E)= + sampleOperator ρ (outerPerm r L)* + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))* + (sampleOperator ρ (outerPerm r L)).adjoint := by + have he : ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L= + fun w => outerPerm r L w.1.1*ParallelBlocks.lift + (fun b => localModifiedPerm L (decide (b∈E)) (w.1.2 b))*(outerPerm r L w.2)⁻¹ := + funext (modified_stage r L E) + calc + _ = sampleOperator ρ (((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) ∘ modifiedStageEquiv r L) := + (sampleOperator_equiv ρ ((splitPerm r L).toMonoidHom ∘ modifiedPerm L r E) (modifiedStageEquiv r L)).symm + _ = _ := (congrArg (sampleOperator ρ) he).trans + (sampleOperator_sandwich ρ hρ (outerPerm r L) + (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + ParallelBlocks.lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))) + +end Thorp +namespace Thorp.CommutingBlocks +open scoped BigOperators Classical +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def retain (P : ι → V →L[ℂ] V) (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1 else P i + +omit [CompleteSpace V] [Fintype ι] in +lemma retain_commute (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) + (E : Finset ι) (i j : ι) : Commute (retain P E i) (retain P E j) := by + unfold retain + split_ifs <;> first | exact Commute.one_left _ | exact Commute.one_right _ | exact hP _ _ + +omit [CompleteSpace V] in +lemma blocks_retain (P : ι → V →L[ℂ] V) (hP : ∀ i j, Commute (P i) (P j)) (E : Finset ι) : + blocks (retain P E) (retain_commute P hP E)=coarse P hP E := by + have hs : E∪Eᶜ=(Finset.univ : Finset ι) := Finset.union_compl E + have hh := Finset.noncommProd_union_of_disjoint (s := E) (t := Eᶜ) disjoint_compl_right + (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _) + simp only [hs] at hh + change blocks (retain P E) (retain_commute P hP E)=_ at hh + rw [hh] + have he : E.noncommProd (retain P E) (fun _ _ _ _ _ => retain_commute P hP E _ _)=1 := by + exact (Finset.noncommProd_eq_pow_card E (retain P E) + (fun i _ j _ _ => retain_commute P hP E i j) 1 (by intro i hi; exact ite_eq_left hi)).trans (one_pow _) + rw [he,one_mul] + apply Finset.noncommProd_congr rfl + intro i hi + exact ite_eq_right (Finset.mem_compl.mp hi) + +end Thorp.CommutingBlocks + +namespace Thorp.ParallelBlocks +open scoped BigOperators Classical +open UnitaryFinite +variable {B X : Type*} [Fintype B] [Fintype X] [DecidableEq X] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def centralProjection (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b : B) : V →L[ℂ] V := + uniformOperator (ρ.comp (injection b)) + +omit [Fintype B] in +lemma centralProjection_commute (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (b c : B) : + Commute (centralProjection ρ b) (centralProjection ρ c) := by + simpa only [centralProjection,sampleOperator_uniform] using + local_average_commute ρ (fun _ => id : B → Equiv.Perm X → Equiv.Perm X) b c + +omit [Fintype B] in +lemma local_central_commute {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (ρ : Representation ℂ (Equiv.Perm (B × X)) V) (P : B → Ω → Equiv.Perm X) (b c : B) : + Commute (sampleOperator (ρ.comp (injection b)) (P b)) (centralProjection ρ c) := by + by_cases h : b=c + · subst c + change _*uniformOperator _=uniformOperator _*_ + rw [sampleOperator_uniform_absorb,sampleOperator_weighted,weighted_uniform_right,sampleLaw_sum,one_smul] + · unfold centralProjection + rw [←sampleOperator_uniform,sampleOperator_comp,sampleOperator_comp] + exact sampleOperator_commute ρ _ _ (fun _ _ => injection_commute h _ _) + +end Thorp.ParallelBlocks +namespace Thorp +open scoped BigOperators Classical +open UnitaryFinite ParallelBlocks CommutingBlocks +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma modified_central_average (r L : ℕ) (E : Finset (Card r)) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) : + sampleOperator ρ (fun w : Card r → Equiv.Perm (Card L) × BenesCoins L => + lift (fun b => localModifiedPerm L (decide (b∈E)) (w b)))= + coarse (centralProjection ρ) (centralProjection_commute ρ) E := by + rw [sampleOperator_parallel ρ (fun b => localModifiedPerm L (decide (b∈E))),←blocks_retain] + apply Finset.noncommProd_congr rfl + · intro b _ + rw [localModified_average] + simp only [retain,centralProjection,decide_eq_true_eq] + · intro b _ c _ _ + exact local_average_commute ρ (fun b => localModifiedPerm L (decide (b∈E))) b c + +lemma central_local_gap (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (b : Card r) : + ‖sampleOperator (ρ.comp (injection b)) (palindromePerm L)*(1-centralProjection ρ b)‖≤blockGap L := by + change ‖sampleOperator _ _*(1-uniformOperator _)‖≤_ + rw [mul_sub,mul_one,sampleOperator_uniform_absorb,sampleOperator_weighted] + exact palindrome_off_invariants_gap L _ (unitary_comp ρ hρ _) + +lemma central_blocks_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) + (B : V →L[ℂ] V) (hB0 : ‖B‖≤1) (n : ℕ) : + ‖B*blocks (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L))*B.adjoint‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card uniformOperator_projection (ρ.comp (injection b)) (unitary_comp ρ hρ _)) + (fun b : Card r => sampleOperator (ρ.comp (injection b)) (palindromePerm L)) + (local_average_commute ρ (fun _ => palindromePerm L)) + (local_central_commute ρ (fun _ => palindromePerm L)) + (fun b => sampleOperator_norm_le (ρ.comp (injection b)) (unitary_comp ρ hρ _) (palindromePerm L)) + (blockGap L) (blockGap_pos L).le (blockGap_lt_one L).le (central_local_gap r L ρ hρ) + B.adjoint hB n + simpa only [ContinuousLinearMap.adjoint_adjoint] using h + +theorem palindrome_exception_bound (r L : ℕ) + (ρ : Representation ℂ (Equiv.Perm (Card r × Card L)) V) (hρ : IsUnitary ρ) (n : ℕ) : + ‖sampleOperator (ρ.comp (splitPerm r L).toMonoidHom) (palindromePerm (L+r))‖ ≤ + (blockGap L)^n + ∑ E : Finset (Card r), if E.card palindromePerm L)] + apply (central_blocks_exception_bound r L ρ hρ (sampleOperator ρ (outerPerm r L)) + (sampleOperator_norm_le ρ hρ _) n).trans_eq + congr 1 + apply Finset.sum_congr rfl + intro E _ + split_ifs + · rw [sampleOperator_modified_stage r L E ρ hρ,modified_central_average] + · rfl + +end Thorp + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] + +noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := + finiteMean (fun ω => if a (P ω) x=y then 1 else 0) + +omit [Fintype G] in +lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) + (v : EuclideanSpace ℂ X) (x : X) : + DensityTransfer.applyKernel (actionKernel a P) v x = + (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by + simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, + Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] + rw [Finset.sum_comm] + calc + _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by + apply Finset.sum_congr rfl + intro ω _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all + _ = _ := by simp [Finset.mul_sum] + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : + DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = + normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by + ext x + rw [actionKernel_apply] + simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, + coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, + inner_smul_right,inner_sum] + apply Finset.sum_congr rfl + intro ω _ + have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x + change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = + inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h + rw [h] + ring + +noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : + Submodule ℂ V where + carrier := {w | IsFixed a x₀ ρ w} + zero_mem' := fun g hg => map_zero _ + add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] + smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] + +theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : + ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + let K := fixedSpace a x₀ ρ + let m := Module.finrank ℂ K + let : Nonempty X := ⟨x₀⟩ + let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ + let B := stdOrthonormalBasis ℂ K + let w : Fin m → V := fun i => (B i : V) + have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 + have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ + have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv + have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) + (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by + rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), + normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] + have h := DensityTransfer.multiplicity_amplification (actionKernel a P) + (fun x y => finiteMean_nonneg (fun _ => by split_ifs <;> norm_num)) hsym hrow + b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) + simpa only [Fintype.card_fin] using h + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where + toFun p := + { toFun := fun e => e.trans p.toEmbedding + invFun := fun e => e.trans p.symm.toEmbedding + left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) + right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } + map_one' := by ext e i; rfl + map_mul' p q := by ext e i; rfl + +omit [Fintype α] [Fintype ι] in +@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : + tupleAction p e i=p (e i) := rfl + +omit [Fintype α] in +lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by + obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective + exact ⟨p,Function.Embedding.ext hp⟩ + +omit [Fintype α] in +lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : + tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by + constructor + · intro h x hx + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + exact congrArg (fun f : ι ↪ α => f i) h + · intro h + ext i + exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + +omit [Fintype α] in +lemma tupleAction_kernel [DecidableEq α] {Ω : Type*} [Fintype Ω] (P : Ω → Equiv.Perm α) + (e f : ι ↪ α) : actionKernel tupleAction P e f=PairRouting.tupleProbability P e f := by + unfold actionKernel PairRouting.tupleProbability + congr 1 + funext ω + congr 1 + exact propext Function.Embedding.ext_iff + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +lemma irreducible_of_equiv {G V W : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : + Representation.IsIrreducible σ := by + rw [Representation.irreducible_iff_isSimpleModule_asModule] + have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance + let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := + Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap + have hf : Function.Bijective f := e.toLinearEquiv.bijective + exact (f.isSimpleModule_iff_of_bijective hf).mp hi + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma unitaryRepresentation_coe (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) + (v : hilbertSpace μ) : + (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) = + PermutationHilbert.act (tabloidAct p) v := by + obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v + change hilbertEquiv μ (tabloidRep μ p w) = _ + exact hilbert_action μ p w + +noncomputable def unitaryEquiv (μ : YoungDiagram) : + Representation.Equiv (representation μ) (unitaryRepresentation μ) := + Representation.Equiv.mk (spaceHilbertEquiv μ) (by + intro p + apply LinearMap.ext + intro v + change spaceHilbertEquiv μ (representation μ p v) = + spaceHilbertEquiv μ (representation μ p ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ v))) + rw [LinearEquiv.symm_apply_apply]) + +lemma unitaryRepresentation_irreducible (μ : YoungDiagram) : + Representation.IsIrreducible (unitaryRepresentation μ) := by + let := representation_irreducible μ + exact UnitaryFinite.irreducible_of_equiv _ _ (unitaryEquiv μ) + +lemma unitaryRepresentation_unitary (μ : YoungDiagram) : + UnitaryFinite.IsUnitary (G := Equiv.Perm (Cell μ)) (V := hilbertSpace μ) (unitaryRepresentation μ) := by + intro p v w + change inner ℂ (unitaryRepresentation μ p v : PermutationHilbert.H (Tabloid μ)) + (unitaryRepresentation μ p w : PermutationHilbert.H (Tabloid μ)) = _ + rw [unitaryRepresentation_coe,unitaryRepresentation_coe] + exact (PermutationHilbert.act (tabloidAct p)).inner_map_map v w + + +noncomputable def tupleFixedEquiv (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ) ≃ₗ[ℂ] + fixedHilbert μ (Finset.univ.image e) where + toFun v := ⟨v.1.1,v.1.2,by + intro p hp + have h := v.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mpr hp) + exact (unitaryRepresentation_coe μ p v.1).symm.trans (congrArg Subtype.val h)⟩ + invFun v := ⟨⟨v.1,v.2.1⟩,by + intro p hp + apply Subtype.ext + exact (unitaryRepresentation_coe μ p _).trans + (v.2.2 p ((UnitaryFinite.tupleAction_fixed_iff e p).mp hp))⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +theorem tupleFixed_dimension (μ : YoungDiagram) {ι : Type*} [Fintype ι] + (e : ι ↪ Cell μ) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction e (unitaryRepresentation μ)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(tupleFixedEquiv μ e).finrank_eq,finrank_hilbertSpace] + have h := fixedHilbert_dimension μ (Finset.univ.image e) + simpa only [Finset.card_image_of_injective _ e.injective,Finset.card_univ] using h + +end Thorp.Specht +namespace Thorp.UnitaryFinite +open scoped BigOperators Classical + +variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : + sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by + simp only [sampleOperator,randomOperator,smul_apply, + sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] + +theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : + ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) + intro v hv + rw [sampleOperator_inv_apply] + exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : + Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where + toFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun g v hv => by + have h := U.apply_mem_toSubmodule (e.symm g) hv + change ρ (e (e.symm g)) v∈U.toSubmodule at h + simpa only [e.apply_symm_apply] using h } + invFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } + left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + map_rel_iff' := Iff.rfl + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by + exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance + +end Thorp.UnitaryFinite + +namespace Thorp.Specht +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +omit [Fintype α] in +lemma relabelledUnitary_unitary (μ : YoungDiagram) (e : α ≃ Cell μ) : + UnitaryFinite.IsUnitary (V := hilbertSpace μ) (relabelledUnitary μ e) := by + intro g v w + exact unitaryRepresentation_unitary μ (e.permCongr g) v w + +omit [Fintype α] in +lemma relabelledUnitary_irreducible (μ : YoungDiagram) (e : α ≃ Cell μ) : + Representation.IsIrreducible (relabelledUnitary μ e) := by + let := unitaryRepresentation_irreducible μ + exact UnitaryFinite.irreducible_comp_equiv (V := hilbertSpace μ) (unitaryRepresentation μ) e.permCongrHom + +noncomputable def relabelledTupleFixed (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e) ≃ₗ[ℂ] + UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction (f.trans e.toEmbedding) (unitaryRepresentation μ) where + toFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.symm.permCongr g) f=f := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ Cell μ => f i) hg + change g (e (f i))=e (f i) at hh + simp only [UnitaryFinite.tupleAction_apply,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply,hh] + have hh := v.2 (e.symm.permCongr g) hp + change unitaryRepresentation μ (e.permCongr (e.symm.permCongr g)) v=v at hh + have he : e.permCongr (e.symm.permCongr g)=g := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply] + simpa only [he] using hh⟩ + invFun v := ⟨v.1,by + intro g hg + have hp : UnitaryFinite.tupleAction (e.permCongr g) (f.trans e.toEmbedding)=f.trans e.toEmbedding := by + apply Function.Embedding.ext + intro i + have hh := congrArg (fun f : ι ↪ α => f i) hg + change g (f i)=f i at hh + simp only [UnitaryFinite.tupleAction_apply,Function.Embedding.trans_apply, + Equiv.toEmbedding_apply,Equiv.permCongr_apply,e.symm_apply_apply,hh] + exact v.2 (e.permCongr g) hp⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +omit [Fintype α] in +lemma relabelled_tuple_dimension (μ : YoungDiagram) (e : α ≃ Cell μ) (f : ι ↪ α) : + Module.finrank ℂ (hilbertSpace μ) * (Fintype.card ι).choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (UnitaryFinite.fixedSpace (V := hilbertSpace μ) UnitaryFinite.tupleAction f (relabelledUnitary μ e)) * + μ.card.choose (μ.card-μ.rowLen 0) := by + rw [(relabelledTupleFixed μ e f).finrank_eq] + exact tupleFixed_dimension μ (f.trans e.toEmbedding) + +end Thorp.Specht + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +lemma small_dominating_set {V : Type*} [Fintype V] (G : SimpleGraph V) + (hG : ∀ v, ∃ w, G.Adj v w) : + ∃ R : Finset V, 2 * R.card ≤ Fintype.card V ∧ + ∀ v, v ∉ R → ∃ w ∈ R, G.Adj v w := by + classical + obtain ⟨F, hFG, hF, hreach⟩ := G.exists_isAcyclic_reachable_eq_le + let c := hF.coloringTwo + have hneigh (v : V) : ∃ w, F.Adj v w := by + obtain ⟨w, hvw⟩ := hG v + have hr : F.Reachable v w := by rw [hreach]; exact hvw.reachable + exact hr.nonempty_neighborSet_left hvw.ne + let A : Finset V := Finset.univ.filter (fun v => c v = 0) + let B : Finset V := Finset.univ.filter (fun v => c v ≠ 0) + have hab : A.card + B.card = Fintype.card V := by + exact Finset.card_filter_add_card_filter_not _ + have hcolor {v w : V} (hvw : F.Adj v w) : c v ≠ c w := c.valid hvw + by_cases h : A.card ≤ B.card + · refine ⟨A, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v ≠ 0 := by simpa [A] using hv + have hw0 : c w = 0 := by + have hv1 : c v = 1 := by omega + have hn := hcolor hvw + omega + exact ⟨w, by simp [A, hw0], hFG hvw⟩ + · refine ⟨B, by omega, ?_⟩ + intro v hv + obtain ⟨w, hvw⟩ := hneigh v + have hv0 : c v = 0 := by simpa [B] using hv + have hw0 : c w ≠ 0 := by simpa [hv0] using (hcolor hvw).symm + exact ⟨w, by simp [B, hw0], hFG hvw⟩ + +lemma powerset_weight_le_exp {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) : + (∑ L ∈ S.powerset, ∏ v ∈ L, p v) ≤ Real.exp (∑ v ∈ S, p v) := by + rw [← Finset.prod_one_add, Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro v _; exact add_nonneg (by norm_num) (hp v) + · intro v _ + have h := Real.add_one_le_exp (p v) + linarith + +lemma fixed_size_weight_le {V : Type*} [DecidableEq V] (S : Finset V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (m : ℕ) (δ : ℝ) (hδ : 0 < δ) : + (∑ L ∈ S.powersetCard m, ∏ v ∈ L, p v) ≤ + δ^m * Real.exp ((∑ v ∈ S, p v)/δ) := by + have hsplit (L : Finset V) (hL : L ∈ S.powersetCard m) : + (∏ v ∈ L, p v) = δ^m * ∏ v ∈ L, (p v / δ) := by + rw [Finset.prod_div_distrib, Finset.prod_const, (Finset.mem_powersetCard.mp hL).2] + field_simp + calc + _ = δ^m * ∑ L ∈ S.powersetCard m, ∏ v ∈ L, (p v/δ) := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl hsplit + _ ≤ δ^m * ∑ L ∈ S.powerset, ∏ v ∈ L, (p v/δ) := by + apply mul_le_mul_of_nonneg_left _ (pow_nonneg hδ.le _) + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro L hL + exact Finset.mem_powerset.mpr (Finset.mem_powersetCard.mp hL).1 + · intro L _ _; exact Finset.prod_nonneg (fun v _ => div_nonneg (hp v) hδ.le) + _ ≤ δ^m * Real.exp (∑ v ∈ S, p v/δ) := + mul_le_mul_of_nonneg_left + (powerset_weight_le_exp S (fun v => p v/δ) (fun v => div_nonneg (hp v) hδ.le)) + (pow_nonneg hδ.le _) + _ = _ := by rw [Finset.sum_div] + +noncomputable def neighborhood {V : Type*} [Fintype V] (G : SimpleGraph V) + (R : Finset V) : Finset V := by + classical + exact Finset.univ.filter (fun w => ∃ v ∈ R, G.Adj v w) + +lemma neighborhood_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (δ : ℝ) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) (R : Finset V) : + (∑ w ∈ neighborhood G R, p w) ≤ R.card * δ := by + classical + calc + _ ≤ ∑ w ∈ neighborhood G R, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum + intro w hw + obtain ⟨v, hv, hvw⟩ := (Finset.mem_filter.mp hw).2 + have h : (if G.Adj v w then p w else 0) ≤ + ∑ u ∈ R, if G.Adj u w then p w else 0 := + Finset.single_le_sum (f := fun u => if G.Adj u w then p w else 0) (fun u _ => by split_ifs; exact hp w; exact le_rfl) hv + simpa only [ite_eq_left hvw] using h + _ ≤ ∑ w, ∑ v ∈ R, if G.Adj v w then p w else 0 := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro w _ _ + exact Finset.sum_nonneg (fun v _ => by split_ifs; exact hp w; exact le_rfl) + _ = ∑ v ∈ R, ∑ w, if G.Adj v w then p w else 0 := Finset.sum_comm + _ ≤ ∑ v ∈ R, δ := Finset.sum_le_sum (fun v _ => hdeg v) + _ = _ := by simp + +lemma root_leaves_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) + (R : Finset V) (hR : 2 * R.card ≤ k) : + (∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v) ≤ + δ^((k:ℝ)/2) * Real.exp R.card := by + classical + have hmass := neighborhood_weight_le G p hp δ hdeg R + have hpow : δ^(k-R.card) ≤ δ^((k:ℝ)/2) := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_ge hδ hδ1 + have hr : R.card ≤ k := by omega + rw [Nat.cast_sub hr] + have hh : (2:ℝ)*R.card ≤ k := by exact_mod_cast hR + linarith + apply (fixed_size_weight_le (neighborhood G R) p hp _ δ hδ).trans + apply mul_le_mul hpow + · apply Real.exp_le_exp.mpr + exact (div_le_iff₀ hδ).mpr hmass + · positivity + · positivity + +def NoIsolated {V : Type*} (G : SimpleGraph V) (S : Finset V) : Prop := + ∀ v ∈ S, ∃ w ∈ S, G.Adj v w + +lemma small_dominating_subset {V : Type*} [Fintype V] (G : SimpleGraph V) + (S : Finset V) (hS : NoIsolated G S) : + ∃ R : Finset V, R ⊆ S ∧ 2 * R.card ≤ S.card ∧ S \ R ⊆ neighborhood G R := by + classical + let H := G.induce (S : Set V) + have hH : ∀ v : S, ∃ w : S, H.Adj v w := by + intro v + obtain ⟨w, hw, hvw⟩ := hS v v.2 + exact ⟨⟨w, hw⟩, hvw⟩ + obtain ⟨R, hR, hdom⟩ := small_dominating_set H hH + let T := R.image (fun v : S => (v : V)) + have hc : T.card = R.card := Finset.card_image_of_injective _ Subtype.val_injective + refine ⟨T, ?_, ?_, ?_⟩ + · intro v hv + obtain ⟨w, _, rfl⟩ := Finset.mem_image.mp hv + exact w.2 + · simpa [hc, H] using hR + · intro v hv + have hvS := (Finset.mem_sdiff.mp hv).1 + have hvR : (⟨v, hvS⟩ : S) ∉ R := by + intro hh + exact (Finset.mem_sdiff.mp hv).2 (Finset.mem_image.mpr ⟨⟨v,hvS⟩, hh, rfl⟩) + obtain ⟨w, hw, hvw⟩ := hdom ⟨v,hvS⟩ hvR + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + ⟨w, Finset.mem_image.mpr ⟨w,hw,rfl⟩, hvw.symm⟩⟩ + +lemma noIsolated_weight_le {V : Type*} [Fintype V] (G : SimpleGraph V) + (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) (k : ℕ) (δ : ℝ) + (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + (∑ S : {S : Finset V // S.card = k ∧ NoIsolated G S}, ∏ v ∈ S.val, p v) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + let root (S : I) := (small_dominating_subset G S.val S.property.2).choose + have hroot (S : I) : root S ⊆ S.val ∧ 2*(root S).card ≤ k ∧ + S.val \ root S ⊆ neighborhood G (root S) := by + simpa only [root, S.property.1] using + (small_dominating_subset G S.val S.property.2).choose_spec + let enc (S : I) : Finset V × Finset V := (root S, S.val \ root S) + have hrec (S : I) : (enc S).1 ∪ (enc S).2 = S.val := + Finset.union_sdiff_of_subset (hroot S).1 + have hinj : Function.Injective enc := by + intro S T h + apply Subtype.ext + rw [← hrec S, ← hrec T, h] + let W (z : Finset V × Finset V) : ℝ := + if 2*z.1.card ≤ k ∧ z.2 ∈ (neighborhood G z.1).powersetCard (k-z.1.card) + then (∏ v ∈ z.1, p v) * ∏ v ∈ z.2, p v else 0 + have hW (z : Finset V × Finset V) : 0 ≤ W z := by + dsimp [W] + split_ifs + · exact mul_nonneg (Finset.prod_nonneg (fun v _ => hp v)) + (Finset.prod_nonneg (fun v _ => hp v)) + · exact le_rfl + have hwenc (S : I) : W (enc S) = ∏ v ∈ S.val, p v := by + have hmem : (enc S).2 ∈ (neighborhood G (enc S).1).powersetCard (k-(enc S).1.card) := by + refine Finset.mem_powersetCard.mpr ⟨(hroot S).2.2, ?_⟩ + change (S.val \ root S).card = k-(root S).card + rw [Finset.card_sdiff_of_subset (hroot S).1, S.property.1] + dsimp only [W] + rw [ite_eq_left ⟨(hroot S).2.1,hmem⟩] + exact (mul_comm _ _).trans (Finset.prod_sdiff (hroot S).1) + have hsum : (∑ S : I, ∏ v ∈ S.val, p v) ≤ ∑ z, W z := by + calc + _ = ∑ z ∈ Finset.univ.image enc, W z := by + rw [Finset.sum_image (fun S _ T _ h => hinj h)] + exact Finset.sum_congr rfl (fun S _ => (hwenc S).symm) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun z _ _ => hW z) + apply hsum.trans + rw [Fintype.sum_prod_type] + calc + (∑ R : Finset V, ∑ L : Finset V, W (R,L)) ≤ + ∑ R : Finset V, δ^((k:ℝ)/2) * Real.exp R.card * ∏ v ∈ R, p v := by + apply Finset.sum_le_sum + intro R _ + by_cases hR : 2*R.card ≤ k + · have he : (∑ L : Finset V, W (R,L)) = + (∏ v ∈ R, p v) * + ∑ L ∈ (neighborhood G R).powersetCard (k-R.card), ∏ v ∈ L, p v := by + simp only [W, hR, true_and] + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, Finset.mul_sum] + rw [he] + have h := mul_le_mul_of_nonneg_left (root_leaves_weight_le G p hp k δ hδ hδ1 hdeg R hR) + (Finset.prod_nonneg (s := R) (fun v _ => hp v)) + simpa only [mul_comm, mul_left_comm, mul_assoc] using h + · simp only [W, hR, false_and, ite_false, Finset.sum_const_zero] + exact mul_nonneg (mul_nonneg (Real.rpow_nonneg hδ.le _) (Real.exp_pos _).le) + (Finset.prod_nonneg (fun v _ => hp v)) + _ = δ^((k:ℝ)/2) * ∑ R : Finset V, ∏ v ∈ R, (Real.exp 1 * p v) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro R _ + rw [Finset.prod_mul_distrib, Finset.prod_const, ← Real.exp_nat_mul] + simp only [mul_one, mul_assoc] + _ ≤ δ^((k:ℝ)/2) * Real.exp (∑ v, Real.exp 1 * p v) := by + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hδ.le _) + simpa only [Finset.powerset_univ] using + powerset_weight_le_exp Finset.univ (fun v => Real.exp 1 * p v) + (fun v => mul_nonneg (Real.exp_pos _).le (hp v)) + _ = _ := by rw [← Finset.mul_sum] + + +lemma noIsolated_probability_le {V Ω : Type*} [Fintype V] [Fintype Ω] + (G : SimpleGraph V) (O : Ω → Finset V) (k : ℕ) + (hcard : ∀ ω, (O ω).card = k) (p : V → ℝ) (hp : ∀ v, 0 ≤ p v) + (hcyl : ∀ D, inclusionMoment O D ≤ ∏ v ∈ D, p v) + (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hdeg : ∀ v, (∑ w, if G.Adj v w then p w else 0) ≤ δ) : + finiteMean (fun ω => if NoIsolated G (O ω) then (1:ℝ) else 0) ≤ + δ^((k:ℝ)/2) * Real.exp (Real.exp 1 * ∑ v, p v) := by + classical + let I := {S : Finset V // S.card = k ∧ NoIsolated G S} + calc + _ ≤ finiteMean (fun ω => ∑ S : I, if S.val ⊆ O ω then (1:ℝ) else 0) := by + apply finiteMean_mono + intro ω + split_ifs with h + · exact (Finset.single_le_sum (f := fun S : I => if S.val ⊆ O ω then (1:ℝ) else 0) + (fun S _ => by positivity) (Finset.mem_univ (⟨O ω,hcard ω,h⟩ : I))) |>.trans' (by simp) + · positivity + _ = ∑ S : I, inclusionMoment O S.val := by + rw [finiteMean_sum] + rfl + _ ≤ ∑ S : I, ∏ v ∈ S.val, p v := Finset.sum_le_sum (fun S _ => hcyl S.val) + _ ≤ _ := noIsolated_weight_le G p hp k δ hδ hδ1 hdeg + +noncomputable def typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : Finset (N × X) := by + classical + exact Finset.univ.filter (fun v => v.2 ∈ A v.1) + +@[simp] lemma mem_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (v : N × X) : v ∈ typedSet A ↔ v.2 ∈ A v.1 := by + classical + simp [typedSet] + +noncomputable def fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) : Finset X := by + classical + exact Finset.univ.filter (fun x => (t,x) ∈ S) + +@[simp] lemma mem_fiber {N X : Type*} [Fintype X] + (S : Finset (N × X)) (t : N) (x : X) : x ∈ fiber S t ↔ (t,x) ∈ S := by + classical + simp [fiber] + +lemma typedSet_fiber {N X : Type*} [Fintype N] [Fintype X] + (S : Finset (N × X)) : typedSet (fiber S) = S := by + classical + ext v + simp + +lemma typedSet_prod {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (p : N × X → ℝ) : + (∏ v ∈ typedSet A, p v) = ∏ t, ∏ x ∈ A t, p (t,x) := by + classical + simp only [typedSet, Finset.prod_filter, Fintype.prod_prod_type] + apply Finset.prod_congr rfl + intro t _ + rw [← Finset.prod_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma typedSet_card {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) : (typedSet A).card = ∑ t, (A t).card := by + classical + simp only [Finset.card_eq_sum_ones, typedSet, Finset.sum_filter, Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + +lemma subset_typedSet {N X : Type*} [Fintype N] [Fintype X] + (A : N → Finset X) (D : Finset (N × X)) : + D ⊆ typedSet A ↔ ∀ t, fiber D t ⊆ A t := by + constructor + · intro h t x hx + exact mem_typedSet A (t,x) |>.mp (h (mem_fiber D t x |>.mp hx)) + · intro h v hv + exact mem_typedSet A v |>.mpr (h v.1 (mem_fiber D v.1 v.2 |>.mpr hv)) + +end Thorp.SparseContact + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ParallelFollow.lean b/lean/OAI/Probability/ThorpRouting/Tail/ParallelFollow.lean index 181b8568fb5dc308c24575c5ab31bd23bd3c7a96..6671f9d03082cbe2ee2b28a71e78c2665169ca79 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ParallelFollow.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ParallelFollow.lean @@ -1,883 +1,883 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.PriorPaths - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter -section ParallelButterfly -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} -omit [DecidableEq B] in -lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : - (∑ i : B × SwitchIndex d, - if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ - (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by - classical - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - simpa only [←mem_blockMarks,parallelUsers] using - marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) - _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by - apply Finset.sum_le_sum - intro b _ - by_cases hz : (blockMarks pre S b).card = 0 - · simp [hz] - · apply div_le_div_of_nonneg_right _ (by positivity) - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) - (by exact_mod_cast card_blockMarks_le pre S b) - _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] - -noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by - exact QueryTree.followPath_succeeds _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by - exact QueryTree.followPath_raw_charge _ _ _ _ _ - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) : - (parallelFollow pre post x k).staleCharge R ω = - (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by - exact QueryTree.followPath_stale_charge _ _ _ _ _ _ - -noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) - -def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by - change post ((pre x).1,_) = y ↔ _ - rw [←post.eq_symm_apply,Prod.mk.injEq] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) : - relabeledPerm pre post ω x = y ↔ - (pre x).1 = (post.symm y).1 ∧ - ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by - classical - rw [relabeled_endpoint_pair,butterfly_endpoint_iff] - simp only [closingDomain,Finset.forall_mem_image,closingValue] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : - closingDomain pre post x y = parallelPath pre ω x := by - rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] - -noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := - if (pre x).1 = (post.symm y).1 then - QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k - else QueryTree.reject - -omit [Fintype α] in -lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : - (parallelClose pre post x y k).succeeds ω = - if relabeledPerm pre post ω x = y then k.succeeds ω else false := by - classical - simp only [relabeled_endpoint_iff,parallelClose] - by_cases hb : (pre x).1 = (post.symm y).1 - · rw [ite_eq_left hb,QueryTree.forceList_succeeds] - simp only [Finset.mem_toList,hb,true_and] - · simp [hb,QueryTree.succeeds] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) - (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).charge ω = k.charge ω + d := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, - closingDomain_eq _ _ _ _ _ h,card_parallelPath] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).freshCharge R ω = - k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by - have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h - rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ - (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, - closingDomain_eq _ _ _ _ _ h] - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) - (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : - (parallelClose pre post x y k).staleCharge R ω = - k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by - have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω - have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω - rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ - have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by - rw [Finset.card_sdiff_add_card_inter,card_parallelPath] - omega - -noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : - RoutingNetwork α (B × SwitchIndex d) d where - perm := relabeledPerm pre post - path := parallelPath pre - users := parallelUsers pre - users_ne := parallelUsers_ne pre - mem_path := mem_parallelPath pre - card_path := card_parallelPath pre - entropy := parallel_entropy pre - follow := parallelFollow pre post - close := parallelClose pre post - follow_succeeds := parallelFollow_succeeds pre post - follow_raw_charge := parallelFollow_raw_charge pre post - follow_stale_charge := parallelFollow_stale_charge pre post - close_succeeds := parallelClose_succeeds pre post - close_raw_charge := parallelClose_raw_charge pre post - close_stale_charge := parallelClose_stale_charge pre post - -lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq - -end ParallelButterfly - -def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s - | 0, s => - { toFun := fun x => ((fun i => Fin.elim0 i), x) - invFun := fun x => x.2 - left_inv := fun _ => rfl - right_inv := fun x => by - apply Prod.ext - · exact Subsingleton.elim _ _ - · rfl } - | r+1, s => - { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), - (cardSplit r s (Fin.tail x)).2) - invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) - left_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] - right_inv := by - intro x - simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } - -def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → - (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool - | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) - | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s - (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i - -lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : - cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = - let y := cardSplit r s x - let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 - (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by - induction r with - | zero => - apply Prod.ext - · funext i - exact Fin.elim0 i - · rfl - | succ r ih => - let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) - let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) - have hh := ih lo' hi' (Fin.tail x) - let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) - let y := cardSplit r s (Fin.tail x) - let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 - let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 - change cardSplit r s u = (w,z) at hh - change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) - ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = - ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) - rw [hh] - -def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ - (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) - | 0, _ => - { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) - invFun := fun i => match i with - | Sum.inl (_,j) => j - | Sum.inr (_,j) => nomatch j - left_inv := fun _ => rfl - right_inv := by - intro i - rcases i with ⟨x,j⟩ | ⟨x,j⟩ - · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) - · exact Empty.elim j } - | r+1, s => - { toFun := fun i => match i with - | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) - | Sum.inr (b,j) => match splitSwitch r s j with - | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) - | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) - invFun := fun i => match i with - | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) - | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) - | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) - left_inv := by - intro i - rcases i with y | ⟨b,j⟩ - · dsimp only - rw [Prod.mk.eta, Equiv.symm_apply_apply] - · dsimp only - cases hz : splitSwitch r s j with - | inl z => - rcases z with ⟨p,k⟩ - simp only [Fin.cons_zero, Fin.tail_cons] - rw [←hz,Equiv.symm_apply_apply] - | inr z => - rcases z with ⟨q,k⟩ - dsimp only - rw [←hz,Equiv.symm_apply_apply] - right_inv := by - intro i - rcases i with ⟨p,j⟩ | ⟨q,j⟩ - · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] - · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } - -lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : - assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by - induction r with - | zero => rfl - | succ r ih => - rcases i with y | ⟨b,j⟩ - · rfl - · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] - rw [ih] - cases splitSwitch r s j <;> rfl - -def splitCoinEquiv (r s : ℕ) : - ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ - (SwitchIndex (s+r) → Bool) := - (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans - (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) - -lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi : Card s × SwitchIndex r → Bool) : - splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by - funext i - exact (assembleBits_eq r s lo hi i).symm - -lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : - finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by - simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ←Finset.sum_div, div_div, mul_comm] - -lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : - finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => - finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by - rw [finiteMean_equiv (splitCoinEquiv r s).symm] - simp only [Equiv.symm_symm] - rw [finiteMean_prod] - apply finiteMean_congr - intro lo - apply finiteMean_congr - intro hi - rw [splitCoinEquiv_apply] - -section PartiallyExposed -variable {α : Type*} {r s : ℕ} - -def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : - α ≃ Card s × Card r := - ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) - -def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := - ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post - -lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : - (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = - relabeledPerm (freshPre pre lo) (freshPost post) hi := by - ext x - simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, - Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using - congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) - -lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] - (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) - (lo : Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - ((pre.trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by - simp only [exposed_perm_eq] - exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq - -end PartiallyExposed - -lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] - (F : Ω → Finset α) (S : Finset α) : - inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by - unfold inclusionMoment - apply finiteMean_congr - intro ω - split_ifs <;> rfl - -lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by - simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] - ring - -lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : - finiteMean (fun _ : Ω => c) = c := by - simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) - -lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} - [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : - finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by - simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] - -section ParallelFairLayer -variable {β : Type*} [Fintype β] [DecidableEq β] - -def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where - toFun x := (Bool.xor x.1 (ξ x.2),x.2) - invFun x := (Bool.xor x.1 (ξ x.2),x.2) - left_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - right_inv x := by - rcases x with ⟨b,x⟩ - change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) - cases b <;> cases ξ x <;> rfl - -noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := - Finset.univ.filter (fun ε => (ε,b) ∈ S) - -lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by - classical - simp only [pairFiber,Finset.prod_filter] - rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] - rw [←Finset.prod_filter] - congr 1 - ext x - simp - -lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : - finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ - ∏ ε ∈ S, (p ε + p (!ε))/2 := by - rw [finiteMean_bool] - have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide - simp only [Bool.xor_false,hxor] - calc - _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := - swap_average_product S p hp false true - _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) - -lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} - (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : - CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) - (fun x => (p x+p (!x.1,x.2))/2) := by - intro S - calc - _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by - apply finiteMean_mono - intro ξ - simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) - _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by - calc - _ = finiteMean (fun ξ : β → Bool => ∏ b : β, - ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := - finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) - _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) - _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by - apply Finset.prod_le_prod₀ - · intro b _ - exact div_nonneg (Finset.sum_nonneg (fun c _ => - Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) - · intro b _ - exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) - _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm - -omit [Fintype β] in -lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : - S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by - have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x - constructor - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - · intro h - have h' := Finset.image_subset_image h (f := pairLayer ξ) - simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' - -noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : - Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) - -lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by - simp only [finiteMean,←Finset.sum_div,div_div] - rw [Finset.sum_comm,mul_comm] - -lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : - inclusionMoment (fairSetLayer F) S = - finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by - classical - simp only [inclusionMoment_eq] - have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = - (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by - funext ω - simp only [fairSetLayer,subset_pairLayer_image_iff] - apply (congrArg finiteMean he).trans - exact (finiteMean_prod (fun ω : Ω × (β → Bool) => - if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans - (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) - -lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) (x : Bool × β) : - inclusionMoment (fairSetLayer F) {x} = - (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by - rw [inclusionMoment_fairSetLayer] - simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] - rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] - rw [finiteMean_bool] - rcases x with ⟨b,x⟩ - cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] - -lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] - (F : Ω → Finset (Bool × β)) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fairSetLayer F)) - (fun x => inclusionMoment (fairSetLayer F) {x}) := by - have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) - intro S - rw [inclusionMoment_fairSetLayer] - simp only [inclusionMoment_fairSetLayer_singleton] - exact hh S - -end ParallelFairLayer - -section RelabelMarks -variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] - -omit [Fintype Ω] [Fintype Ω'] in -lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : - S ⊆ A.image e ↔ S.image e.symm ⊆ A := by - constructor - · intro h x hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) - simpa only [←hxy,Equiv.symm_apply_apply] using hx - · intro h y hy - exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ - -omit [Fintype Ω'] in -lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : - inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by - classical - simp only [inclusionMoment_eq] - apply finiteMean_congr - intro ω - simp only [subset_image_equiv_iff] - -omit [Fintype Ω'] in -lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => (F ω).image e)) - (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by - intro S - simp only [inclusionMoment_image_equiv,Finset.image_singleton] - have hh := h (S.image e.symm) - simpa only [Finset.prod_image e.symm.injective.injOn] using hh - -omit [DecidableEq β] in -lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : - inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by - classical - simp only [inclusionMoment_eq] - simpa only [Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) - -omit [DecidableEq β] in -lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) - (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : - CylinderBound (inclusionMoment (fun ω => F (e ω))) - (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by - intro S - simpa only [inclusionMoment_comp_equiv] using h S -end RelabelMarks - -lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (f : Ω → ℝ) (g : Ω' → ℝ) : - finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by - simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, - ←Finset.mul_sum,←Finset.sum_mul] - ring - -section JoinChildren -variable {β : Type*} [DecidableEq β] - -noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := - A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) - -lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : - (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by - cases b <;> simp [childJoin] - -noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := - (S.filter (fun x => x.1 = b)).image Prod.snd - -lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : - x ∈ boolFiber S b ↔ (b,x) ∈ S := by - constructor - · intro h - obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h - obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy - change c = b at hc - change y = x at hxy - simpa only [hc,hxy] using hy - · intro h - exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ - -lemma childJoin_boolFiber (S : Finset (Bool × β)) : - childJoin (boolFiber S false) (boolFiber S true) = S := by - ext ⟨b,x⟩ - rw [mem_childJoin] - cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] - -lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : - S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by - constructor - · intro h - constructor - · intro x hx - exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) - · intro x hx - exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) - · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx - rw [mem_childJoin] - cases b - · exact h₀ ((mem_boolFiber S false x).mpr hx) - · exact h₁ ((mem_boolFiber S true x).mpr hx) - -lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : - (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by - classical - have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by - apply Finset.disjoint_left.mpr - rintro x hx hy - obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx - obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy - exact Bool.false_ne_true (congrArg Prod.fst hba).symm - rw [childJoin,Finset.prod_union hd, - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), - Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] - -lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : - (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * - ∏ x ∈ boolFiber S true, f (true,x) := by - rw [←prod_childJoin,childJoin_boolFiber] - -lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : - inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = - inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by - classical - simp only [inclusionMoment_eq] - rw [←finiteMean_prod_mul] - apply finiteMean_congr - intro ω - simp only [subset_childJoin_iff] - split_ifs <;> simp_all - -lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] - (F : Ω → Finset β) (G : Ω' → Finset β) - (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) - (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : - CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) - (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by - intro S - rw [inclusionMoment_childJoin,prod_boolFibers] - have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by - ext y - simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] - have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by - ext y - cases b <;> simp [mem_boolFiber] - have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = - inclusionMoment F {x} * inclusionMoment G ∅ := by - rw [inclusionMoment_childJoin,hf] - have hh := hn true x - exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh - have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = - inclusionMoment F ∅ * inclusionMoment G {x} := by - rw [inclusionMoment_childJoin,hf] - have hh := hn false x - exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh - have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] - simp only [h₀,h₁,emF,emG,mul_one,one_mul] - exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) - (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) -end JoinChildren - -def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ - ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where - toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), - fun x => ω (Sum.inl x)) - invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) - left_inv ω := by - funext i - cases i with - | inl x => rfl - | inr bi => cases bi with | mk b i => cases b <;> rfl - right_inv ω := by - rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ - rfl - -def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := - (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm - -lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : - A = (childMarks A false).image (Fin.cons false) ∪ - (childMarks A true).image (Fin.cons true) := by - classical - ext x - constructor - · intro hx - cases hb : x 0 - · exact Finset.mem_union_left _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · exact Finset.mem_union_right _ (Finset.mem_image.mpr - ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), - by simp only [←hb,Fin.cons_self_tail]⟩) - · intro hx - rcases Finset.mem_union.mp hx with hx | hx - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (mem_childMarks _ _ _).mp hy - -noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) - (ω : SwitchIndex d → Bool) : Finset (Card d) := - A.image (butterflyPerm d (decodeButterfly d ω)) - -lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : - butterflyMarks (d+1) A ω = - (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => - childJoin (butterflyMarks d (childMarks A false) p.1) - (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image - (headTailEquiv d).symm := by - classical - unfold butterflyMarks fairSetLayer childJoin - rw [Finset.image_union,Finset.image_union] - simp only [Finset.image_image] - conv_lhs => rw [childMarks_join d A] - rw [Finset.image_union] - simp only [Finset.image_image] - apply congrArg₂ (· ∪ ·) - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - · apply Finset.image_congr - intro x _ - simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, - childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, - coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] - rfl - -lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : - CylinderBound (inclusionMoment (butterflyMarks d A)) - (fun x => inclusionMoment (butterflyMarks d A) {x}) := by - induction d with - | zero => - have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by - funext ω - simp [butterflyMarks,butterflyPerm] - rw [he] - exact cylinder_const A - | succ d ih => - have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) - (butterflyMarks d (childMarks A true)) (ih _) (ih _) - have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) - have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh - simpa only [←butterflyMarks_succ] using hs - -lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] - (A : Finset α) (p : Equiv.Perm α) (y : α) : - (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by - classical - by_cases h : y ∈ A.image p - · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h - rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] - symm - calc - _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by - intro z _ hzx - exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) - _ = 1 := ite_eq_left hxy - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro x hx - exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) - -lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : - inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by - classical - unfold inclusionMoment - simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] - rw [finiteMean_sum] - simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] - ring - -lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : - inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by - have h := butterflyMarks_cylinder d A S - simpa only [butterflyMarks_singleton,Finset.prod_const] using h - -namespace CycleColoring -variable {α : Type*} [Fintype α] [DecidableEq α] - -abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = f x} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := - Fintype.ofFinite _ - -noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := - S.filter (fun x => p.symm x ∉ S) - -noncomputable def root {p : Equiv.Perm α} {S : Finset α} - (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose - -lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : - root C ∈ C.val := C.nonempty.choose_spec - -abbrev Seed (p : Equiv.Perm α) (S : Finset α) := - {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S - -noncomputable def record {p : Equiv.Perm α} {S : Finset α} - (f : Coloring p S) : Seed p S → Bool := - Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) - -lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) - (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by - intro y hy - have hh := ((mem_orbitSet p x y).mp hy).inv - obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq - have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by - induction k with - | zero => simpa using hx - | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih - exact hn ▸ hp n - -lemma record_injective (p : Equiv.Perm α) (S : Finset α) : - Function.Injective (record (p := p) (S := S)) := by - classical - intro f g hfg - apply Subtype.ext - funext x - by_contra hne - have hx : x ∈ S := by - by_contra h - exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) - let D := S.filter (fun y => f.val y ≠ g.val y) - have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ - have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by - obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy - have hpS : p.symm y ∈ S := by - by_contra hn - have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ - exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) - refine Finset.mem_filter.mpr ⟨hpS,?_⟩ - have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) - simp only [Equiv.apply_symm_apply] at hf hg - intro he - exact hyne (hf.trans (he.trans hg.symm)) - have horb := orbit_subset_of_predecessor_closed p D hprev hxD - let C : RoutingNetwork.SelectedCycle p S := - ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ - have hrD : root C ∈ D := horb (root_mem C) - have hrne := (Finset.mem_filter.mp hrD).2 - exact hrne (congrFun hfg (Sum.inr C)) - -lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) - simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h - -omit [Fintype α] in -lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : - (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by - classical - have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) - unfold boundary - omega - -lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (Coloring p S) ≤ - 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + - Fintype.card (RoutingNetwork.SelectedCycle p S)) := by - simpa only [boundary_card] using card_coloring_le p S - - -abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := - {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ - ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} - -noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := - Fintype.ofFinite _ - -noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) - (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) - (f : OppositeColoring p S) : Coloring p S := by - classical - refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ - · intro x hx - exact ite_eq_right hx - · intro x hx hpx - simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] - cases f.val x <;> cases χ x <;> rfl - -end CycleColoring -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.PriorPaths + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter +section ParallelButterfly +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} +omit [DecidableEq B] in +lemma parallel_entropy (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (S : Finset α) : + (∑ i : B × SwitchIndex d, + if (parallelUsers pre ω i).1 ∈ S ∧ (parallelUsers pre ω i).2 ∈ S then (1:ℝ) else 0) ≤ + (S.card : ℝ) * Real.log S.card / (2 * Real.log 2) := by + classical + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log (blockMarks pre S b).card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + simpa only [←mem_blockMarks,parallelUsers] using + marked_switch_entropy_bound d (decodeButterfly d (fun i => ω (b,i))) (blockMarks pre S b) + _ ≤ ∑ b : B, (blockMarks pre S b).card * Real.log S.card / (2*Real.log 2) := by + apply Finset.sum_le_sum + intro b _ + by_cases hz : (blockMarks pre S b).card = 0 + · simp [hz] + · apply div_le_div_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) + (by exact_mod_cast card_blockMarks_le pre S b) + _ = _ := by rw [←Finset.sum_div,←Finset.sum_mul,←Nat.cast_sum,sum_card_blockMarks] + +noncomputable def parallelFollow (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + QueryTree.followPath d (fun i => ((pre x).1,i)) (pre x).2 (fun y => k (post ((pre x).1,y))) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).succeeds ω = (k (relabeledPerm pre post ω x)).succeeds ω := by + exact QueryTree.followPath_succeeds _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelFollow_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).charge ω = (k (relabeledPerm pre post ω x)).charge ω := by + exact QueryTree.followPath_raw_charge _ _ _ _ _ + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelFollow_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x : α) (k : α → QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) : + (parallelFollow pre post x k).staleCharge R ω = + (k (relabeledPerm pre post ω x)).staleCharge (R ∪ parallelPath pre ω x) ω := by + exact QueryTree.followPath_stale_charge _ _ _ _ _ _ + +noncomputable def closingDomain (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 (post.symm y).2).image (fun i => ((pre x).1,i)) + +def closingValue (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (i : B × SwitchIndex d) : Bool := routeValue d (pre x).2 (post.symm y).2 i.2 + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma relabeled_endpoint_pair (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2 = (post.symm y).2 := by + change post ((pre x).1,_) = y ↔ _ + rw [←post.eq_symm_apply,Prod.mk.injEq] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma relabeled_endpoint_iff (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) : + relabeledPerm pre post ω x = y ↔ + (pre x).1 = (post.symm y).1 ∧ + ∀ i ∈ closingDomain pre post x y, ω i = closingValue pre post x y i := by + classical + rw [relabeled_endpoint_pair,butterfly_endpoint_iff] + simp only [closingDomain,Finset.forall_mem_image,closingValue] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma closingDomain_eq (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) (x y : α) (h : relabeledPerm pre post ω x = y) : + closingDomain pre post x y = parallelPath pre ω x := by + rw [closingDomain,parallelPath,(relabeled_endpoint_pair _ _ _ _ _).mp h |>.2] + +noncomputable def parallelClose (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) : QueryTree (B × SwitchIndex d) := + if (pre x).1 = (post.symm y).1 then + QueryTree.forceList (closingDomain pre post x y).toList (closingValue pre post x y) k + else QueryTree.reject + +omit [Fintype α] in +lemma parallelClose_succeeds (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) : + (parallelClose pre post x y k).succeeds ω = + if relabeledPerm pre post ω x = y then k.succeeds ω else false := by + classical + simp only [relabeled_endpoint_iff,parallelClose] + by_cases hb : (pre x).1 = (post.symm y).1 + · rw [ite_eq_left hb,QueryTree.forceList_succeeds] + simp only [Finset.mem_toList,hb,true_and] + · simp [hb,QueryTree.succeeds] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_raw_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (ω : B × SwitchIndex d → Bool) + (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).charge ω = k.charge ω + d := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_raw_charge _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.length_toList, + closingDomain_eq _ _ _ _ _ h,card_parallelPath] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_fresh_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).freshCharge R ω = + k.freshCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x \ R).card := by + have hh := (relabeled_endpoint_iff _ _ _ _ _).mp h + rw [parallelClose,ite_eq_left hh.1,QueryTree.forceList_charge _ _ _ _ _ + (by simpa only [Finset.mem_toList] using hh.2),Finset.toList_toFinset, + closingDomain_eq _ _ _ _ _ h] + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma parallelClose_stale_charge (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (x y : α) (k : QueryTree (B × SwitchIndex d)) (R : Finset (B × SwitchIndex d)) + (ω : B × SwitchIndex d → Bool) (h : relabeledPerm pre post ω x = y) : + (parallelClose pre post x y k).staleCharge R ω = + k.staleCharge (R ∪ parallelPath pre ω x) ω + (parallelPath pre ω x ∩ R).card := by + have h₀ := QueryTree.fresh_add_stale (parallelClose pre post x y k) R ω + have h₁ := QueryTree.fresh_add_stale k (R ∪ parallelPath pre ω x) ω + rw [parallelClose_raw_charge _ _ _ _ _ _ h,parallelClose_fresh_charge _ _ _ _ _ _ _ h] at h₀ + have h₂ : (parallelPath pre ω x \ R).card + (parallelPath pre ω x ∩ R).card = d := by + rw [Finset.card_sdiff_add_card_inter,card_parallelPath] + omega + +noncomputable def parallelNetwork (pre : α ≃ B × Card d) (post : B × Card d ≃ α) : + RoutingNetwork α (B × SwitchIndex d) d where + perm := relabeledPerm pre post + path := parallelPath pre + users := parallelUsers pre + users_ne := parallelUsers_ne pre + mem_path := mem_parallelPath pre + card_path := card_parallelPath pre + entropy := parallel_entropy pre + follow := parallelFollow pre post + close := parallelClose pre post + follow_succeeds := parallelFollow_succeeds pre post + follow_raw_charge := parallelFollow_raw_charge pre post + follow_stale_charge := parallelFollow_stale_charge pre post + close_succeeds := parallelClose_succeeds pre post + close_raw_charge := parallelClose_raw_charge pre post + close_stale_charge := parallelClose_stale_charge pre post + +lemma parallel_cycle_log_mgf (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (S : Finset α) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : B × SwitchIndex d → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle (relabeledPerm pre post ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + exact (parallelNetwork pre post).butterfly_cycle_log_mgf S J hJ q hq + +end ParallelButterfly + +def cardSplit : (r s : ℕ) → Card (s+r) ≃ Card r × Card s + | 0, s => + { toFun := fun x => ((fun i => Fin.elim0 i), x) + invFun := fun x => x.2 + left_inv := fun _ => rfl + right_inv := fun x => by + apply Prod.ext + · exact Subsingleton.elim _ _ + · rfl } + | r+1, s => + { toFun := fun x => (Fin.cons (x 0) ((cardSplit r s (Fin.tail x)).1), + (cardSplit r s (Fin.tail x)).2) + invFun := fun x => Fin.cons (x.1 0) ((cardSplit r s).symm (Fin.tail x.1,x.2)) + left_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Prod.mk.eta, Equiv.symm_apply_apply, Fin.cons_self_tail] + right_inv := by + intro x + simp only [Fin.cons_zero, Fin.tail_cons, Equiv.apply_symm_apply, Fin.cons_self_tail] } + +def assembleBits : (r s : ℕ) → (Card r × SwitchIndex s → Bool) → + (Card s × SwitchIndex r → Bool) → SwitchIndex (s+r) → Bool + | 0, _, lo, _, i => lo ((fun j => Fin.elim0 j), i) + | r+1, s, _, hi, Sum.inl y => hi ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | r+1, s, lo, hi, Sum.inr (b,i) => assembleBits r s + (fun j => lo (Fin.cons b j.1,j.2)) (fun j => hi (j.1,Sum.inr (b,j.2))) i + +lemma butterfly_split (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (x : Card (s+r)) : + cardSplit r s (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)) x) = + let y := cardSplit r s x + let z := butterflyPerm s (decodeButterfly s (fun i => lo (y.1,i))) y.2 + (butterflyPerm r (decodeButterfly r (fun i => hi (z,i))) y.1,z) := by + induction r with + | zero => + apply Prod.ext + · funext i + exact Fin.elim0 i + · rfl + | succ r ih => + let lo' : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons (x 0) j.1,j.2) + let hi' : Card s × SwitchIndex r → Bool := fun j => hi (j.1,Sum.inr (x 0,j.2)) + have hh := ih lo' hi' (Fin.tail x) + let u := butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo' hi')) (Fin.tail x) + let y := cardSplit r s (Fin.tail x) + let z := butterflyPerm s (decodeButterfly s (fun i => lo' (y.1,i))) y.2 + let w := butterflyPerm r (decodeButterfly r (fun i => hi' (z,i))) y.1 + change cardSplit r s u = (w,z) at hh + change ((Fin.cons (Bool.xor (x 0) (hi ((cardSplit r s u).2,Sum.inl (cardSplit r s u).1))) + ((cardSplit r s u).1) : Card (r+1)), (cardSplit r s u).2) = + ((Fin.cons (Bool.xor (x 0) (hi (z,Sum.inl w))) w : Card (r+1)),z) + rw [hh] + +def splitSwitch : (r s : ℕ) → SwitchIndex (s+r) ≃ + (Card r × SwitchIndex s) ⊕ (Card s × SwitchIndex r) + | 0, _ => + { toFun := fun i => Sum.inl ((fun j => Fin.elim0 j),i) + invFun := fun i => match i with + | Sum.inl (_,j) => j + | Sum.inr (_,j) => nomatch j + left_inv := fun _ => rfl + right_inv := by + intro i + rcases i with ⟨x,j⟩ | ⟨x,j⟩ + · exact congrArg Sum.inl (Prod.ext (Subsingleton.elim _ _) rfl) + · exact Empty.elim j } + | r+1, s => + { toFun := fun i => match i with + | Sum.inl y => Sum.inr ((cardSplit r s y).2,Sum.inl (cardSplit r s y).1) + | Sum.inr (b,j) => match splitSwitch r s j with + | Sum.inl (p,j) => Sum.inl (Fin.cons b p,j) + | Sum.inr (q,j) => Sum.inr (q,Sum.inr (b,j)) + invFun := fun i => match i with + | Sum.inl (p,j) => Sum.inr (p 0,(splitSwitch r s).symm (Sum.inl (Fin.tail p,j))) + | Sum.inr (q,Sum.inl p) => Sum.inl ((cardSplit r s).symm (p,q)) + | Sum.inr (q,Sum.inr (b,j)) => Sum.inr (b,(splitSwitch r s).symm (Sum.inr (q,j))) + left_inv := by + intro i + rcases i with y | ⟨b,j⟩ + · dsimp only + rw [Prod.mk.eta, Equiv.symm_apply_apply] + · dsimp only + cases hz : splitSwitch r s j with + | inl z => + rcases z with ⟨p,k⟩ + simp only [Fin.cons_zero, Fin.tail_cons] + rw [←hz,Equiv.symm_apply_apply] + | inr z => + rcases z with ⟨q,k⟩ + dsimp only + rw [←hz,Equiv.symm_apply_apply] + right_inv := by + intro i + rcases i with ⟨p,j⟩ | ⟨q,j⟩ + · simp only [Equiv.apply_symm_apply, Fin.cons_self_tail] + · rcases j with p | ⟨b,j⟩ <;> simp only [Equiv.apply_symm_apply] } + +lemma assembleBits_eq (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) (i : SwitchIndex (s+r)) : + assembleBits r s lo hi i = Sum.elim lo hi (splitSwitch r s i) := by + induction r with + | zero => rfl + | succ r ih => + rcases i with y | ⟨b,j⟩ + · rfl + · simp only [assembleBits,splitSwitch,Equiv.coe_fn_mk] + rw [ih] + cases splitSwitch r s j <;> rfl + +def splitCoinEquiv (r s : ℕ) : + ((Card r × SwitchIndex s → Bool) × (Card s × SwitchIndex r → Bool)) ≃ + (SwitchIndex (s+r) → Bool) := + (Equiv.sumArrowEquivProdArrow _ _ Bool).symm.trans + (Equiv.arrowCongr (splitSwitch r s).symm (Equiv.refl Bool)) + +lemma splitCoinEquiv_apply (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi : Card s × SwitchIndex r → Bool) : + splitCoinEquiv r s (lo,hi) = assembleBits r s lo hi := by + funext i + exact (assembleBits_eq r s lo hi i).symm + +lemma finiteMean_prod {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω × Ω' → ℝ) : + finiteMean f = finiteMean (fun x => finiteMean (fun y => f (x,y))) := by + simp only [finiteMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ←Finset.sum_div, div_div, mul_comm] + +lemma finiteMean_split (r s : ℕ) (f : (SwitchIndex (s+r) → Bool) → ℝ) : + finiteMean f = finiteMean (fun lo : Card r × SwitchIndex s → Bool => + finiteMean (fun hi : Card s × SwitchIndex r → Bool => f (assembleBits r s lo hi))) := by + rw [finiteMean_equiv (splitCoinEquiv r s).symm] + simp only [Equiv.symm_symm] + rw [finiteMean_prod] + apply finiteMean_congr + intro lo + apply finiteMean_congr + intro hi + rw [splitCoinEquiv_apply] + +section PartiallyExposed +variable {α : Type*} {r s : ℕ} + +def freshPre (pre : α ≃ Card (s+r)) (lo : Card r × SwitchIndex s → Bool) : + α ≃ Card s × Card r := + ((pre.trans (cardSplit r s)).trans (parallelPerm lo)).trans (Equiv.prodComm _ _) + +def freshPost (post : Card (s+r) ≃ α) : Card s × Card r ≃ α := + ((Equiv.prodComm _ _).trans (cardSplit r s).symm).trans post + +lemma exposed_perm_eq (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (hi : Card s × SwitchIndex r → Bool) : + (pre.trans (butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post = + relabeledPerm (freshPre pre lo) (freshPost post) hi := by + ext x + simpa only [relabeledPerm, freshPre, freshPost, parallelPerm, Equiv.trans_apply, + Equiv.coe_fn_mk, Equiv.prodComm_apply, Prod.swap, Equiv.symm_apply_apply] using + congrArg (fun y => post ((cardSplit r s).symm y)) (butterfly_split r s lo hi (pre x)) + +lemma partially_exposed_cycle_log_mgf [Fintype α] [DecidableEq α] + (pre : α ≃ Card (s+r)) (post : Card (s+r) ≃ α) + (lo : Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + ((pre.trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi)))).trans post) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^r) := by + simp only [exposed_perm_eq] + exact parallel_cycle_log_mgf (freshPre pre lo) (freshPost post) S J hJ q hq + +end PartiallyExposed + +lemma inclusionMoment_eq {α Ω : Type*} [DecidableEq α] [Fintype Ω] + (F : Ω → Finset α) (S : Finset α) : + inclusionMoment F S = finiteMean (fun ω => if S ⊆ F ω then (1:ℝ) else 0) := by + unfold inclusionMoment + apply finiteMean_congr + intro ω + split_ifs <;> rfl + +lemma finiteMean_bool (f : Bool → ℝ) : finiteMean f = (f false+f true)/2 := by + simp only [finiteMean, Fintype.sum_bool, Fintype.card_bool, Nat.cast_ofNat] + ring + +lemma finiteMean_const {Ω : Type*} [Fintype Ω] [Nonempty Ω] (c : ℝ) : + finiteMean (fun _ : Ω => c) = c := by + simp only [finiteMean,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_div_cancel_left₀ c (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +lemma finiteMean_pi_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {Ω : ι → Type*} + [∀ i, Fintype (Ω i)] (f : (i : ι) → Ω i → ℝ) : + finiteMean (fun ω : (i : ι) → Ω i => ∏ i, f i (ω i)) = ∏ i, finiteMean (f i) := by + simp only [finiteMean,←Fintype.prod_sum,Fintype.card_pi,Nat.cast_prod,Finset.prod_div_distrib] + +section ParallelFairLayer +variable {β : Type*} [Fintype β] [DecidableEq β] + +def pairLayer (ξ : β → Bool) : Equiv.Perm (Bool × β) where + toFun x := (Bool.xor x.1 (ξ x.2),x.2) + invFun x := (Bool.xor x.1 (ξ x.2),x.2) + left_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + right_inv x := by + rcases x with ⟨b,x⟩ + change (Bool.xor (Bool.xor b (ξ x)) (ξ x),x) = (b,x) + cases b <;> cases ξ x <;> rfl + +noncomputable def pairFiber (S : Finset (Bool × β)) (b : β) : Finset Bool := + Finset.univ.filter (fun ε => (ε,b) ∈ S) + +lemma prod_pairFiber (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = ∏ b : β, ∏ ε ∈ pairFiber S b, f (ε,b) := by + classical + simp only [pairFiber,Finset.prod_filter] + rw [Finset.prod_comm,←Fintype.prod_prod_type (fun x : Bool × β => if x ∈ S then f x else 1)] + rw [←Finset.prod_filter] + congr 1 + ext x + simp + +lemma fiber_average_bound (S : Finset Bool) (p : Bool → ℝ) (hp : ∀ b, 0 ≤ p b) : + finiteMean (fun c : Bool => ∏ ε ∈ S, p (Bool.xor ε c)) ≤ + ∏ ε ∈ S, (p ε + p (!ε))/2 := by + rw [finiteMean_bool] + have hxor : ∀ ε : Bool, Bool.xor ε true = Equiv.swap false true ε := by decide + simp only [Bool.xor_false,hxor] + calc + _ ≤ ∏ ε ∈ S, (p ε+p (Equiv.swap false true ε))/2 := + swap_average_product S p hp false true + _ = _ := Finset.prod_congr rfl (fun ε _ => by cases ε <;> rfl) + +lemma CylinderBound.fair_parallel {m : Finset (Bool × β) → ℝ} {p : Bool × β → ℝ} + (h : CylinderBound m p) (hp : ∀ x, 0 ≤ p x) : + CylinderBound (fun S => finiteMean (fun ξ : β → Bool => m (S.image (pairLayer ξ)))) + (fun x => (p x+p (!x.1,x.2))/2) := by + intro S + calc + _ ≤ finiteMean (fun ξ : β → Bool => ∏ x ∈ S, p (pairLayer ξ x)) := by + apply finiteMean_mono + intro ξ + simpa only [Finset.prod_image (pairLayer ξ).injective.injOn] using h (S.image (pairLayer ξ)) + _ = ∏ b : β, finiteMean (fun c : Bool => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) := by + calc + _ = finiteMean (fun ξ : β → Bool => ∏ b : β, + ∏ ε ∈ pairFiber S b, p (Bool.xor ε (ξ b),b)) := + finiteMean_congr (fun ξ => prod_pairFiber S (fun x => p (pairLayer ξ x))) + _ = _ := finiteMean_pi_prod (fun b c => ∏ ε ∈ pairFiber S b, p (Bool.xor ε c,b)) + _ ≤ ∏ b : β, ∏ ε ∈ pairFiber S b, (p (ε,b)+p (!ε,b))/2 := by + apply Finset.prod_le_prod₀ + · intro b _ + exact div_nonneg (Finset.sum_nonneg (fun c _ => + Finset.prod_nonneg (fun ε _ => hp (Bool.xor ε c,b)))) (Nat.cast_nonneg _) + · intro b _ + exact fiber_average_bound (pairFiber S b) (fun ε => p (ε,b)) (fun ε => hp (ε,b)) + _ = _ := (prod_pairFiber S (fun x => (p x+p (!x.1,x.2))/2)).symm + +omit [Fintype β] in +lemma subset_pairLayer_image_iff (S A : Finset (Bool × β)) (ξ : β → Bool) : + S ⊆ A.image (pairLayer ξ) ↔ S.image (pairLayer ξ) ⊆ A := by + have hi (x : Bool × β) : pairLayer ξ (pairLayer ξ x) = x := (pairLayer ξ).left_inv x + constructor + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + · intro h + have h' := Finset.image_subset_image h (f := pairLayer ξ) + simpa only [Finset.image_image,Function.comp_def,hi,Finset.image_id'] using h' + +noncomputable def fairSetLayer {Ω : Type*} (F : Ω → Finset (Bool × β)) : + Ω × (β → Bool) → Finset (Bool × β) := fun ω => (F ω.1).image (pairLayer ω.2) + +lemma finiteMean_comm {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + finiteMean (fun x => finiteMean (f x)) = finiteMean (fun y => finiteMean (fun x => f x y)) := by + simp only [finiteMean,←Finset.sum_div,div_div] + rw [Finset.sum_comm,mul_comm] + +lemma inclusionMoment_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (S : Finset (Bool × β)) : + inclusionMoment (fairSetLayer F) S = + finiteMean (fun ξ : β → Bool => inclusionMoment F (S.image (pairLayer ξ))) := by + classical + simp only [inclusionMoment_eq] + have he : (fun ω : Ω × (β → Bool) => if S ⊆ fairSetLayer F ω then (1:ℝ) else 0) = + (fun ω : Ω × (β → Bool) => if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0) := by + funext ω + simp only [fairSetLayer,subset_pairLayer_image_iff] + apply (congrArg finiteMean he).trans + exact (finiteMean_prod (fun ω : Ω × (β → Bool) => + if S.image (pairLayer ω.2) ⊆ F ω.1 then (1:ℝ) else 0)).trans + (finiteMean_comm (fun ω ξ => if S.image (pairLayer ξ) ⊆ F ω then (1:ℝ) else 0)) + +lemma inclusionMoment_fairSetLayer_singleton {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) (x : Bool × β) : + inclusionMoment (fairSetLayer F) {x} = + (inclusionMoment F {x}+inclusionMoment F {(!x.1,x.2)})/2 := by + rw [inclusionMoment_fairSetLayer] + simp only [Finset.image_singleton,pairLayer,Equiv.coe_fn_mk] + rw [finiteMean_pi_eval (A := fun _ : β => Bool) x.2 (fun c : Bool => inclusionMoment F {(Bool.xor x.1 c,x.2)})] + rw [finiteMean_bool] + rcases x with ⟨b,x⟩ + cases b <;> simp only [Bool.xor_false,Bool.false_xor,Bool.true_xor, Bool.not_false,Bool.not_true] + +lemma cylinder_fairSetLayer {Ω : Type*} [Fintype Ω] + (F : Ω → Finset (Bool × β)) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fairSetLayer F)) + (fun x => inclusionMoment (fairSetLayer F) {x}) := by + have hh := h.fair_parallel (fun x => inclusionMoment_nonneg F {x}) + intro S + rw [inclusionMoment_fairSetLayer] + simp only [inclusionMoment_fairSetLayer_singleton] + exact hh S + +end ParallelFairLayer + +section RelabelMarks +variable {α β Ω Ω' : Type*} [DecidableEq α] [DecidableEq β] [Fintype Ω] [Fintype Ω'] + +omit [Fintype Ω] [Fintype Ω'] in +lemma subset_image_equiv_iff (e : α ≃ β) (A : Finset α) (S : Finset β) : + S ⊆ A.image e ↔ S.image e.symm ⊆ A := by + constructor + · intro h x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp (h hy) + simpa only [←hxy,Equiv.symm_apply_apply] using hx + · intro h y hy + exact Finset.mem_image.mpr ⟨e.symm y,h (Finset.mem_image_of_mem _ hy),e.apply_symm_apply y⟩ + +omit [Fintype Ω'] in +lemma inclusionMoment_image_equiv (e : α ≃ β) (F : Ω → Finset α) (S : Finset β) : + inclusionMoment (fun ω => (F ω).image e) S = inclusionMoment F (S.image e.symm) := by + classical + simp only [inclusionMoment_eq] + apply finiteMean_congr + intro ω + simp only [subset_image_equiv_iff] + +omit [Fintype Ω'] in +lemma cylinder_image_equiv (e : α ≃ β) (F : Ω → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => (F ω).image e)) + (fun x => inclusionMoment (fun ω => (F ω).image e) {x}) := by + intro S + simp only [inclusionMoment_image_equiv,Finset.image_singleton] + have hh := h (S.image e.symm) + simpa only [Finset.prod_image e.symm.injective.injOn] using hh + +omit [DecidableEq β] in +lemma inclusionMoment_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) (S : Finset α) : + inclusionMoment (fun ω => F (e ω)) S = inclusionMoment F S := by + classical + simp only [inclusionMoment_eq] + simpa only [Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if S ⊆ F (e ω) then (1 : ℝ) else 0) + +omit [DecidableEq β] in +lemma cylinder_comp_equiv (e : Ω ≃ Ω') (F : Ω' → Finset α) + (h : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) : + CylinderBound (inclusionMoment (fun ω => F (e ω))) + (fun x => inclusionMoment (fun ω => F (e ω)) {x}) := by + intro S + simpa only [inclusionMoment_comp_equiv] using h S +end RelabelMarks + +lemma finiteMean_prod_mul {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (f : Ω → ℝ) (g : Ω' → ℝ) : + finiteMean (fun ω : Ω × Ω' => f ω.1*g ω.2) = finiteMean f * finiteMean g := by + simp only [finiteMean,Fintype.sum_prod_type,Fintype.card_prod,Nat.cast_mul, + ←Finset.mul_sum,←Finset.sum_mul] + ring + +section JoinChildren +variable {β : Type*} [DecidableEq β] + +noncomputable def childJoin (A B : Finset β) : Finset (Bool × β) := + A.image (fun x => (false,x)) ∪ B.image (fun x => (true,x)) + +lemma mem_childJoin (A B : Finset β) (b : Bool) (x : β) : + (b,x) ∈ childJoin A B ↔ (if b then x ∈ B else x ∈ A) := by + cases b <;> simp [childJoin] + +noncomputable def boolFiber (S : Finset (Bool × β)) (b : Bool) : Finset β := + (S.filter (fun x => x.1 = b)).image Prod.snd + +lemma mem_boolFiber (S : Finset (Bool × β)) (b : Bool) (x : β) : + x ∈ boolFiber S b ↔ (b,x) ∈ S := by + constructor + · intro h + obtain ⟨⟨c,y⟩,hy,hxy⟩ := Finset.mem_image.mp h + obtain ⟨hy,hc⟩ := Finset.mem_filter.mp hy + change c = b at hc + change y = x at hxy + simpa only [hc,hxy] using hy + · intro h + exact Finset.mem_image.mpr ⟨(b,x),Finset.mem_filter.mpr ⟨h,rfl⟩,rfl⟩ + +lemma childJoin_boolFiber (S : Finset (Bool × β)) : + childJoin (boolFiber S false) (boolFiber S true) = S := by + ext ⟨b,x⟩ + rw [mem_childJoin] + cases b <;> simp only [Bool.false_eq_true,↓reduceIte,mem_boolFiber] + +lemma subset_childJoin_iff (S : Finset (Bool × β)) (A B : Finset β) : + S ⊆ childJoin A B ↔ boolFiber S false ⊆ A ∧ boolFiber S true ⊆ B := by + constructor + · intro h + constructor + · intro x hx + exact (mem_childJoin A B false x).mp (h ((mem_boolFiber S false x).mp hx)) + · intro x hx + exact (mem_childJoin A B true x).mp (h ((mem_boolFiber S true x).mp hx)) + · rintro ⟨h₀,h₁⟩ ⟨b,x⟩ hx + rw [mem_childJoin] + cases b + · exact h₀ ((mem_boolFiber S false x).mpr hx) + · exact h₁ ((mem_boolFiber S true x).mpr hx) + +lemma prod_childJoin (A B : Finset β) (f : Bool × β → ℝ) : + (∏ x ∈ childJoin A B, f x) = (∏ x ∈ A, f (false,x)) * ∏ x ∈ B, f (true,x) := by + classical + have hd : Disjoint (A.image (fun x => (false,x))) (B.image (fun x => (true,x))) := by + apply Finset.disjoint_left.mpr + rintro x hx hy + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨b,hb,hba⟩ := Finset.mem_image.mp hy + exact Bool.false_ne_true (congrArg Prod.fst hba).symm + rw [childJoin,Finset.prod_union hd, + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h), + Finset.prod_image (fun _ _ _ _ h => congrArg Prod.snd h)] + +lemma prod_boolFibers (S : Finset (Bool × β)) (f : Bool × β → ℝ) : + (∏ x ∈ S, f x) = (∏ x ∈ boolFiber S false, f (false,x)) * + ∏ x ∈ boolFiber S true, f (true,x) := by + rw [←prod_childJoin,childJoin_boolFiber] + +lemma inclusionMoment_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) (S : Finset (Bool × β)) : + inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) S = + inclusionMoment F (boolFiber S false) * inclusionMoment G (boolFiber S true) := by + classical + simp only [inclusionMoment_eq] + rw [←finiteMean_prod_mul] + apply finiteMean_congr + intro ω + simp only [subset_childJoin_iff] + split_ifs <;> simp_all + +lemma cylinder_childJoin {Ω Ω' : Type*} [Fintype Ω] [Fintype Ω'] [Nonempty Ω] [Nonempty Ω'] + (F : Ω → Finset β) (G : Ω' → Finset β) + (hF : CylinderBound (inclusionMoment F) (fun x => inclusionMoment F {x})) + (hG : CylinderBound (inclusionMoment G) (fun x => inclusionMoment G {x})) : + CylinderBound (inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2))) + (fun x => inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {x}) := by + intro S + rw [inclusionMoment_childJoin,prod_boolFibers] + have hf (b : Bool) (x : β) : boolFiber {(b,x)} b = {x} := by + ext y + simp only [mem_boolFiber,Finset.mem_singleton,Prod.mk.injEq,true_and] + have hn (b : Bool) (x : β) : boolFiber {(!b,x)} b = ∅ := by + ext y + cases b <;> simp [mem_boolFiber] + have h₀ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(false,x)} = + inclusionMoment F {x} * inclusionMoment G ∅ := by + rw [inclusionMoment_childJoin,hf] + have hh := hn true x + exact congrArg (fun T => inclusionMoment F {x} * inclusionMoment G T) hh + have h₁ (x : β) : inclusionMoment (fun ω : Ω × Ω' => childJoin (F ω.1) (G ω.2)) {(true,x)} = + inclusionMoment F ∅ * inclusionMoment G {x} := by + rw [inclusionMoment_childJoin,hf] + have hh := hn false x + exact congrArg (fun T => inclusionMoment F T * inclusionMoment G {x}) hh + have emF : inclusionMoment F ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + have emG : inclusionMoment G ∅ = 1 := by simp [inclusionMoment,finiteMean_const] + simp only [h₀,h₁,emF,emG,mul_one,one_mul] + exact mul_le_mul (hF _) (hG _) (inclusionMoment_nonneg _ _) + (Finset.prod_nonneg (fun x _ => inclusionMoment_nonneg F {x})) +end JoinChildren + +def coinStepEquiv (d : ℕ) : (SwitchIndex (d+1) → Bool) ≃ + ((SwitchIndex d → Bool) × (SwitchIndex d → Bool)) × (Card d → Bool) where + toFun ω := ((fun i => ω (Sum.inr (false,i)),fun i => ω (Sum.inr (true,i))), + fun x => ω (Sum.inl x)) + invFun ω := Sum.elim ω.2 (fun bi => if bi.1 then ω.1.2 bi.2 else ω.1.1 bi.2) + left_inv ω := by + funext i + cases i with + | inl x => rfl + | inr bi => cases bi with | mk b i => cases b <;> rfl + right_inv ω := by + rcases ω with ⟨⟨ω₀,ω₁⟩,ξ⟩ + rfl + +def headTailEquiv (d : ℕ) : Card (d+1) ≃ Bool × Card d := + (Fin.consEquiv (fun _ : Fin (d+1) => Bool)).symm + +lemma childMarks_join (d : ℕ) (A : Finset (Card (d+1))) : + A = (childMarks A false).image (Fin.cons false) ∪ + (childMarks A true).image (Fin.cons true) := by + classical + ext x + constructor + · intro hx + cases hb : x 0 + · exact Finset.mem_union_left _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · exact Finset.mem_union_right _ (Finset.mem_image.mpr + ⟨Fin.tail x,(mem_childMarks _ _ _).mpr (by simpa only [←hb,Fin.cons_self_tail] using hx), + by simp only [←hb,Fin.cons_self_tail]⟩) + · intro hx + rcases Finset.mem_union.mp hx with hx | hx + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + · obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (mem_childMarks _ _ _).mp hy + +noncomputable def butterflyMarks (d : ℕ) (A : Finset (Card d)) + (ω : SwitchIndex d → Bool) : Finset (Card d) := + A.image (butterflyPerm d (decodeButterfly d ω)) + +lemma butterflyMarks_succ (d : ℕ) (A : Finset (Card (d+1))) (ω : SwitchIndex (d+1) → Bool) : + butterflyMarks (d+1) A ω = + (fairSetLayer (fun p : (SwitchIndex d → Bool) × (SwitchIndex d → Bool) => + childJoin (butterflyMarks d (childMarks A false) p.1) + (butterflyMarks d (childMarks A true) p.2)) (coinStepEquiv d ω)).image + (headTailEquiv d).symm := by + classical + unfold butterflyMarks fairSetLayer childJoin + rw [Finset.image_union,Finset.image_union] + simp only [Finset.image_image] + conv_lhs => rw [childMarks_join d A] + rw [Finset.image_union] + simp only [Finset.image_image] + apply congrArg₂ (· ∪ ·) + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + · apply Finset.image_congr + intro x _ + simp only [Function.comp_def,butterflyPerm,decodeButterfly,Equiv.Perm.coe_mul, + childLift,pairSwitch,switchFun,Equiv.coe_fn_mk,Fin.cons_zero,Fin.tail_cons, + coinStepEquiv,headTailEquiv,Equiv.symm_symm,pairLayer] + rfl + +lemma butterflyMarks_cylinder (d : ℕ) (A : Finset (Card d)) : + CylinderBound (inclusionMoment (butterflyMarks d A)) + (fun x => inclusionMoment (butterflyMarks d A) {x}) := by + induction d with + | zero => + have he : butterflyMarks 0 A = fun _ : SwitchIndex 0 → Bool => A := by + funext ω + simp [butterflyMarks,butterflyPerm] + rw [he] + exact cylinder_const A + | succ d ih => + have h := cylinder_childJoin (butterflyMarks d (childMarks A false)) + (butterflyMarks d (childMarks A true)) (ih _) (ih _) + have hh := cylinder_image_equiv (headTailEquiv d).symm _ (cylinder_fairSetLayer _ h) + have hs := cylinder_comp_equiv (coinStepEquiv d) _ hh + simpa only [←butterflyMarks_succ] using hs + +lemma indicator_mem_image_perm {α : Type*} [DecidableEq α] + (A : Finset α) (p : Equiv.Perm α) (y : α) : + (if y ∈ A.image p then (1 : ℝ) else 0) = ∑ x ∈ A, if p x = y then 1 else 0 := by + classical + by_cases h : y ∈ A.image p + · obtain ⟨x,hx,hxy⟩ := Finset.mem_image.mp h + rw [ite_eq_left (Finset.mem_image.mpr ⟨x,hx,hxy⟩)] + symm + calc + _ = (if p x = y then (1:ℝ) else 0) := Finset.sum_eq_single_of_mem x hx (by + intro z _ hzx + exact ite_eq_right (fun hz => hzx (p.injective (hz.trans hxy.symm)))) + _ = 1 := ite_eq_left hxy + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro x hx + exact ite_eq_right (fun hxy => h (Finset.mem_image.mpr ⟨x,hx,hxy⟩)) + +lemma butterflyMarks_singleton (d : ℕ) (A : Finset (Card d)) (y : Card d) : + inclusionMoment (butterflyMarks d A) {y} = (A.card : ℝ)/(2:ℝ)^d := by + classical + unfold inclusionMoment + simp only [Finset.singleton_subset_iff,butterflyMarks,indicator_mem_image_perm] + rw [finiteMean_sum] + simp only [butterfly_single_card_uniform,Finset.sum_const,nsmul_eq_mul] + ring + +lemma butterflyMarks_inclusion (d : ℕ) (A S : Finset (Card d)) : + inclusionMoment (butterflyMarks d A) S ≤ ((A.card : ℝ)/(2:ℝ)^d)^S.card := by + have h := butterflyMarks_cylinder d A S + simpa only [butterflyMarks_singleton,Finset.prod_const] using h + +namespace CycleColoring +variable {α : Type*} [Fintype α] [DecidableEq α] + +abbrev Coloring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = f x} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (Coloring p S) := + Fintype.ofFinite _ + +noncomputable def boundary (p : Equiv.Perm α) (S : Finset α) : Finset α := + S.filter (fun x => p.symm x ∉ S) + +noncomputable def root {p : Equiv.Perm α} {S : Finset α} + (C : RoutingNetwork.SelectedCycle p S) : α := C.nonempty.choose + +lemma root_mem {p : Equiv.Perm α} {S : Finset α} (C : RoutingNetwork.SelectedCycle p S) : + root C ∈ C.val := C.nonempty.choose_spec + +abbrev Seed (p : Equiv.Perm α) (S : Finset α) := + {x // x ∈ boundary p S} ⊕ RoutingNetwork.SelectedCycle p S + +noncomputable def record {p : Equiv.Perm α} {S : Finset α} + (f : Coloring p S) : Seed p S → Bool := + Sum.elim (fun x => f.val x.val) (fun C => f.val (root C)) + +lemma orbit_subset_of_predecessor_closed (p : Equiv.Perm α) (D : Finset α) + (hD : ∀ x ∈ D, p.symm x ∈ D) {x : α} (hx : x ∈ D) : orbitSet p x ⊆ D := by + intro y hy + have hh := ((mem_orbitSet p x y).mp hy).inv + obtain ⟨n,hn⟩ := hh.exists_nat_pow_eq + have hp (k : ℕ) : (p⁻¹ ^ k) x ∈ D := by + induction k with + | zero => simpa using hx + | succ k ih => simpa only [pow_succ',Equiv.Perm.mul_apply,Equiv.Perm.coe_inv] using hD _ ih + exact hn ▸ hp n + +lemma record_injective (p : Equiv.Perm α) (S : Finset α) : + Function.Injective (record (p := p) (S := S)) := by + classical + intro f g hfg + apply Subtype.ext + funext x + by_contra hne + have hx : x ∈ S := by + by_contra h + exact hne ((f.property.1 x h).trans (g.property.1 x h).symm) + let D := S.filter (fun y => f.val y ≠ g.val y) + have hxD : x ∈ D := Finset.mem_filter.mpr ⟨hx,hne⟩ + have hprev (y : α) (hy : y ∈ D) : p.symm y ∈ D := by + obtain ⟨hyS,hyne⟩ := Finset.mem_filter.mp hy + have hpS : p.symm y ∈ S := by + by_contra hn + have hseed : y ∈ boundary p S := Finset.mem_filter.mpr ⟨hyS,hn⟩ + exact hyne (congrFun hfg (Sum.inl ⟨y,hseed⟩)) + refine Finset.mem_filter.mpr ⟨hpS,?_⟩ + have hf := f.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + have hg := g.property.2 (p.symm y) hpS (by simpa only [Equiv.apply_symm_apply] using hyS) + simp only [Equiv.apply_symm_apply] at hf hg + intro he + exact hyne (hf.trans (he.trans hg.symm)) + have horb := orbit_subset_of_predecessor_closed p D hprev hxD + let C : RoutingNetwork.SelectedCycle p S := + ⟨orbitSet p x,⟨x,rfl⟩,fun y hy => (Finset.mem_filter.mp (horb hy)).1⟩ + have hrD : root C ∈ D := horb (root_mem C) + have hrne := (Finset.mem_filter.mp hrD).2 + exact hrne (congrFun hfg (Sum.inr C)) + +lemma card_coloring_le (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ ((boundary p S).card + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + have h := Fintype.card_le_of_injective (record (p := p) (S := S)) (record_injective p S) + simpa only [Fintype.card_fun,Fintype.card_sum,Fintype.card_coe,Fintype.card_bool] using h + +omit [Fintype α] in +lemma boundary_card (p : Equiv.Perm α) (S : Finset α) : + (boundary p S).card = S.card - (S.filter (fun x => p.symm x ∈ S)).card := by + classical + have h := Finset.card_filter_add_card_filter_not (s := S) (fun x => p.symm x ∈ S) + unfold boundary + omega + +lemma card_coloring_le_edges (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (Coloring p S) ≤ + 2 ^ (S.card - (S.filter (fun x => p.symm x ∈ S)).card + + Fintype.card (RoutingNetwork.SelectedCycle p S)) := by + simpa only [boundary_card] using card_coloring_le p S + + +abbrev OppositeColoring (p : Equiv.Perm α) (S : Finset α) := + {f : α → Bool // (∀ x, x ∉ S → f x = false) ∧ + ∀ x ∈ S, p x ∈ S → f (p x) = !(f x)} + +noncomputable instance (p : Equiv.Perm α) (S : Finset α) : Fintype (OppositeColoring p S) := + Fintype.ofFinite _ + +noncomputable def bipartitionFlip (p : Equiv.Perm α) (S : Finset α) + (χ : α → Bool) (hχ : ∀ x, χ (p x) = !(χ x)) + (f : OppositeColoring p S) : Coloring p S := by + classical + refine ⟨(fun x => if x ∈ S then Bool.xor (f.val x) (χ x) else false),?_,?_⟩ + · intro x hx + exact ite_eq_right hx + · intro x hx hpx + simp only [ite_eq_left hx,ite_eq_left hpx,f.property.2 x hx hpx,hχ x] + cases f.val x <;> cases χ x <;> rfl + +end CycleColoring +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ParallelFreshPre.lean b/lean/OAI/Probability/ThorpRouting/Tail/ParallelFreshPre.lean index ba43c4a96ac00c01c8b119495bda9c7f702646e2..16d21a5d265fd87c35dbde327db432d3fd76e696 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ParallelFreshPre.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ParallelFreshPre.lean @@ -1,848 +1,848 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.BenesCoins - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp - -lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : - x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by - classical - constructor - · intro h - obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h - simp only [Equiv.apply_symm_apply] - · intro h - apply Finset.mem_image.mpr - refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ - rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] - -lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by - classical - rw [centralBlock,Finset.card_image_of_injective] - · exact card_positions H - · intro x y h - exact congrArg Prod.snd ((cardSplit r H).symm.injective h) - -lemma centralBlock_disjoint (r H : ℕ) : - Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by - classical - intro b b' h - apply Finset.disjoint_left.mpr - intro x hx hy - exact h (((mem_centralBlock r H b x).mp hx).symm.trans - ((mem_centralBlock r H b' x).mp hy)) - -lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by - classical - ext x - simp only [mem_centralBlock,Finset.mem_univ,iff_true] - exact Subsingleton.elim _ _ - -lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : - centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by - classical - simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, - Fin.cons_zero,Fin.tail_cons,Function.comp_def] - -lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : - centralBlock (r+1) H (Fin.cons b c) ∩ A = - (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by - classical - rw [centralBlock_step] - ext x - constructor - · intro hx - obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB - exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, - (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ - -lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : - sparseMass (centralBlock 0 H) A = crowdedMass A.card := by - classical - simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, - Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] - -lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : - sparseMass (centralBlock (r+1) H) A = - sparseMass (centralBlock r H) (childMarks A false) + - sparseMass (centralBlock r H) (childMarks A true) := by - classical - unfold sparseMass - rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] - have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl - simp only [Fintype.sum_bool,ht] - have hc (b : Bool) (c : Card r) : - (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = - (centralBlock r H c ∩ childMarks A b).card := by - rw [block_inter_step] - apply Finset.card_image_of_injective - intro x y h - simpa only [Fin.tail_cons] using congrArg Fin.tail h - simp only [hc] - exact add_comm _ _ - - -lemma inverseButterfly_coordinates_step (d : ℕ) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) - (x : Card (d+1)) : - headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = - (Bool.xor (x 0) (ξ (Fin.tail x)), - (butterflyPerm d (decodeButterfly d - (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by - rw [butterflyPerm_step] - rfl - -lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) - (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : - childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) - ((coinStepEquiv d).symm (c,ξ))) b = - inverseButterflyMarks d - (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) - (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) - (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by - classical - let x := e.trans (headTailEquiv d).toEmbedding - let col := PairRouting.colors x ξ - let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b - have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) - (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = - (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := - inverseButterfly_coordinates_step d c ξ (e i) - ext y - simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, - Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] - constructor - · rintro ⟨i,hi⟩ - have he := congrArg (headTailEquiv d) hi - rw [hp i] at he - change (col i,_) = (b,y) at he - have hb := congrArg Prod.fst he - have hy := congrArg Prod.snd he - dsimp only at hb hy - refine ⟨⟨i,hb⟩,?_⟩ - change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y - simpa only [hb] using hy - · rintro ⟨i,hi⟩ - refine ⟨i.val,?_⟩ - apply (headTailEquiv d).injective - rw [hp] - change (col i.val,_) = (b,y) - have hb : col i.val = b := i.property - rw [hb] - exact Prod.ext rfl hi - -lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : - (inverseButterflyMarks d A ω).card = A.card := by - classical - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective - -lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : - ω.2 = (coinStepEquiv d).symm - (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by - change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) - exact ((coinStepEquiv d).symm_apply_apply ω.2).symm - -lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : - cutoffMass H (H+r) e ω = - sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by - classical - induction r generalizing ι with - | zero => - rw [sparseMass_central_zero,inverseButterflyMarks_card, - Finset.card_image_of_injective _ e.injective,Finset.card_univ] - cases H with - | zero => - have hcard : Fintype.card ι ≤ 1 := by - have hh := Fintype.card_le_of_injective e e.injective - simpa only [Nat.add_zero,card_positions,pow_zero] using hh - simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] - | succ H => simp only [cutoffMass,le_refl,ite_true] - | succ r ih => - simp only [Nat.add_succ] at * - rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] - let σ := benesStepEquiv (H+r) ω - let x := e.trans (headTailEquiv (H+r)).toEmbedding - let col := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + - cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ - rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] - rw [inverseButterflyMarks_child,inverseButterflyMarks_child] - rfl - - -theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) - (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : - finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ - Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by - classical - have hec : (Finset.univ.image e).card = Fintype.card ι := by - rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] - have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) - (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) - (pow_nonneg (by linarith) _) (fun b => by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) - calc - _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by - apply finiteMean_mono - intro ω - rw [←pow_mul] - exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) - _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => - (q^H)^(sparseMass (centralBlock r H) - (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by - simp_rw [cutoffMass_central] - simp only [finiteMean_prod,finiteMean_const] - _ ≤ _ := by - simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, - Finset.card_univ,card_positions,nsmul_eq_mul] using hm - -variable {α B : Type*} {r s : ℕ} - -def parallelFreshPre (pre : α ≃ B × Card (s+r)) - (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := - ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans - (Equiv.prodCongrRight (fun b => - (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans - (Equiv.prodAssoc _ _ _).symm - -def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := - (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) - (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post - -def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := - fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 - -lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) - (hi : (B × Card s) × SwitchIndex r → Bool) : - relabeledPerm pre post (parallelAssembled lo hi) = - relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by - ext x - have h := butterfly_split r s (lo (pre x).1) - (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 - have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h - simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, - Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, - Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, - Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh - -theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] - (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) - (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => - q^(Fintype.card (RoutingNetwork.SelectedCycle - (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ - (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by - simp_rw [parallel_exposed_perm] - exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq - -end Thorp -namespace Thorp -variable {α : Type*} [Fintype α] [DecidableEq α] - -lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] - -lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Fintype.card_congr - refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ - invFun := fun C => ⟨C.val,?_,C.property.2⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ - · obtain ⟨x,hx⟩ := C.property.1 - exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ - -lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : - orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by - ext y - simp only [mem_orbitSet,Finset.mem_image] - rw [Equiv.Perm.sameCycle_conj] - change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y - rw [Equiv.symm_apply_apply] - constructor - · intro h - exact ⟨g.symm y,h,g.apply_symm_apply y⟩ - · rintro ⟨z,hz,rfl⟩ - simpa only [Equiv.symm_apply_apply] using hz - -noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) - (C : RoutingNetwork.SelectedCycle p S) : - RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by - refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ - obtain ⟨x,hx⟩ := C.property.1 - exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ - -lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : - Function.Injective (conjugateCycle p g S) := by - intro C D he - apply Subtype.ext - exact (Finset.image_injective g.injective) (congrArg Subtype.val he) - -lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = - Fintype.card (RoutingNetwork.SelectedCycle p S) := by - apply Nat.le_antisymm - · have h := Fintype.card_le_of_injective _ - (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) - have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group - rw [inv_inv,hp] at h - have hs : (S.image g).image g.symm = S := by - ext x - simp only [Finset.mem_image] - constructor - · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ - have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he - exact hz' ▸ hz - · intro hx - exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ - change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h - rw [hs] at h - exact h - · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) - -lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : - PairRouting.alternatingCycles e p ≤ - Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false)) := by - have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) - (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) - simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h - -lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : - Fintype.card (RoutingNetwork.SelectedCycle - ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = - Fintype.card (RoutingNetwork.SelectedCycle - (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by - let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) - calc - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) - (S.image X₀.symm)) := by - change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ - have h := (selectedCycle_conjugate p X₀⁻¹ S).symm - rw [inv_inv] at h - exact h - _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ - (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm - _ = _ := by - have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group - rw [he] - -end Thorp -namespace Thorp - -noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := - Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) - -lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - 0 ≤ cycleCoefficient r J q := by - unfold cycleCoefficient - exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) - (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) - -lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] - (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by - have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) - (boolFiber (PairRouting.labelSet e) true) - rw [childJoin_boolFiber,PairRouting.card_labelSet] at h - omega - -theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient r J q) := by - classical - let S := boolFiber (PairRouting.labelSet e) false - let S' := S.image X₀.symm - let post := X₀⁻¹*X₁*Y₁⁻¹ - let count := fun hi : Card s × SwitchIndex r → Bool => - Fintype.card (RoutingNetwork.SelectedCycle - ((Equiv.refl _).trans (butterflyPerm (s+r) - (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') - have hpoint (hi : Card s × SwitchIndex r → Bool) : - PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else - butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by - refine (alternatingCycles_le_projection e _).trans_eq ?_ - simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] - change Fintype.card (RoutingNetwork.SelectedCycle - ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi - exact projectionCycles_forward X₀ X₁ _ Y₁ S - have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq - have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_pos (fun _ => pow_pos (by linarith) _) - have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ - Real.exp (S'.card * cycleCoefficient r J q) := by - rw [←Real.exp_log hp] - apply Real.exp_le_exp.mpr - calc - _ ≤ _ := hm - _ = _ := by unfold cycleCoefficient; ring - have hcard : S'.card ≤ Fintype.card ι := by - rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] - exact projectionSide_card_le e - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := - finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) - _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right - (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) - - -def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ - (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) where - toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), - fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) - invFun c := fun j => match j.2 with - | Sum.inl y => c.2 (j.1,y) - | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) - left_inv hi := by - funext j - rcases j with ⟨z,y|⟨b,i⟩⟩ - · rfl - · cases b <;> rfl - right_inv c := by - rcases c with ⟨⟨h₀,h₁⟩,η⟩ - rfl - -lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) - (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × - (Card s × Card r → Bool)) : - assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = - (coinStepEquiv (s+r)).symm - ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, - assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), - fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by - funext i - rcases i with y | ⟨b,i⟩ - · rfl - · cases b <;> rfl - -noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → - (ι ↪ Card d) → BenesCoins d → ℕ - | 0, _, _, _, _ => 0 - | d+1, _, _, e, ω => - let σ := benesStepEquiv d ω - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x σ.2.1 - let hc := PairRouting.colors_compatible x σ.2.1 - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) - (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 - -lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) - (ξ η : Card d → Bool) : - palindromeLevelCost t (d+1) e - ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = - let x := e.trans (headTailEquiv d).toEmbedding - let c := PairRouting.colors x ξ - let hc := PairRouting.colors_compatible x ξ - if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) - (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else - palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + - palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by - rw [palindromeLevelCost] - rfl - -lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by - classical - induction d generalizing ι with - | zero => rfl - | succ d ih => - rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] - - -theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * cycleCoefficient u J q) := by - classical - induction r generalizing u ι with - | zero => omega - | succ r ih => - simp only [Nat.add_succ] at * - let χ := coinStepEquiv (s+r) X - let x := e.trans (headTailEquiv (s+r)).toEmbedding - let c := PairRouting.colors x χ.2 - let hc := PairRouting.colors_compatible x χ.2 - let e₀ := PairRouting.childEmbedding x c hc false - let e₁ := PairRouting.childEmbedding x c hc true - let e' := PairRouting.switchedEmbedding x χ.2 - let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) - let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) - let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi - let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi - let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => - PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) - else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) - let L₀ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) - let L₁ := fun hi : Card s × SwitchIndex r → Bool => - palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) - have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) - (η : Card s × Card r → Bool) : - palindromeLevelCost (s+u+1) (s+r+1) e - (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = - if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by - rw [assembleBits_step] - conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] - rw [palindromeLevelCost_step] - simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] - dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] - congr 2 - funext b - cases b <;> rfl - rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] - simp_rw [hs,finiteMean_const] - by_cases hur : u = r - · subst u - simp only [ite_true] - rw [finiteMean_prod,finiteMean_comm] - calc - _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => - Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by - apply finiteMean_mono - intro hi - have hn := node_partial_mgf r s e' - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) - (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) - (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq - exact hn - _ = _ := finiteMean_const _ - · simp only [ite_eq_right hur,pow_add] - rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] - have hu' : u < r := by omega - have h₀ := ih u hu' e₀ χ.1.1 lo₀ - have h₁ := ih u hu' e₁ χ.1.2 lo₁ - have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) - (Real.exp_nonneg _) - refine hp.trans_eq ?_ - rw [←Real.exp_add] - congr 1 - have hcount := PairRouting.color_card_add c - have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + - Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount - change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + - Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ - rw [←add_mul,hcount'] - - -def switchHeight : (d : ℕ) → SwitchIndex d → ℕ - | 0, i => nomatch i - | d+1, Sum.inl _ => d+1 - | d+1, Sum.inr (_,i) => switchHeight d i - -lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by - induction d with - | zero => exact Empty.elim i - | succ d ih => - rcases i with y | ⟨b,i⟩ - · exact le_refl _ - · exact (ih i).trans (Nat.le_succ d) - -def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := - ∀ i, switchHeight d i ≤ s → Y i = Y' i - -def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := - ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' - -lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} - (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := - fun i hi => hh i (hi.trans h) - -lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} - (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := - fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) - -lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} - (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := - fun Y Y' h => congrArg g (hf Y Y' h) - -lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) - (f : ι → (SwitchIndex d → Bool) → ℕ) - (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : - LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by - intro Y Y' h - exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) - -lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) - (hi hi' : Card s × SwitchIndex r → Bool) : - AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by - induction r with - | zero => intro i _; rfl - | succ r ih => - intro i h - rcases i with y | ⟨b,i⟩ - · have : s+r+1 ≤ s := h - omega - · exact ih (fun j => lo (Fin.cons b j.1,j.2)) - (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h - -lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by - classical - induction d generalizing ι with - | zero => intro Y Y' _; rfl - | succ d ih => - intro Y Y' h - change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) - conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] - conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] - rw [palindromeLevelCost_step,palindromeLevelCost_step] - by_cases ht : t = d+1 - · subst t - rw [ite_eq_left rfl,ite_eq_left rfl] - have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by - funext i - exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by - funext i - exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) - rw [he₀,he₁] - · rw [ite_eq_right ht,ite_eq_right ht] - congr 1 - · apply ih - intro i hi - exact h (Sum.inr (false,i)) hi - · apply ih - intro i hi - exact h (Sum.inr (true,i)) hi - -lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) - (hG : ∀ lo : Card r × SwitchIndex s → Bool, - finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : - finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by - rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] - apply finiteMean_mono - intro lo - let H : Card s × SwitchIndex r → Bool := fun _ => false - have hh (hi : Card s × SwitchIndex r → Bool) : - F (assembleBits r s lo hi) = F (assembleBits r s lo H) := - hA _ _ (assembleBits_agree r s lo hi H) - simp_rw [hh,finiteMean_const] - rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = - (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by - funext hi; exact mul_comm _ _,finiteMean_mul_const] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) - - -theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) - (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : - cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ - 68 * Real.exp (-(l:ℝ)/64) := by - let E := Real.exp ((l:ℝ)/32) - let J := ⌈E⌉₊ - have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ - have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) - have hEpos : 0 < E := Real.exp_pos _ - have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E - have hJ : (1:ℝ) ≤ J := hE.trans hEJ - have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ - have hJE : (J:ℝ) ≤ 2*E := by - have h := Nat.ceil_lt_add_one (le_of_lt hEpos) - change (J:ℝ) < E+1 at h - linarith - have hsqJ : Real.sqrt J ≤ (J:ℝ) := by - apply Real.sqrt_le_iff.mpr - constructor - · positivity - · nlinarith - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - have hqE : q ≤ Real.exp ((l:ℝ)/250) := by - rw [←Real.exp_log hqp] - exact Real.exp_le_exp.mpr hlog - have hln : (1/2:ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) - norm_num at hh ⊢ - exact hh - have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by - have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by - rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] - rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] - apply Real.exp_le_exp.mpr - have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ - nlinarith - have hlog' : Real.log q ≤ (l:ℝ) := by linarith - have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ - _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by - apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) - have hh := Real.add_one_le_exp ((l:ℝ)/64) - linarith - _ = _ := by - dsimp [E] - rw [mul_div_assoc,←Real.exp_sub] - congr 2 - ring - have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ - 4*Real.exp (-(l:ℝ)/64) := by - calc - _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by - apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden - have hs := hsqJ.trans hJE - have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) - nlinarith - _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by - dsimp [E] - rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) - linarith - change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ - linarith - -lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by - have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) - have he := Real.exp_pos ((l:ℝ)/32) - have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h - exact_mod_cast this - - -lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] - (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : - q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by - have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero - have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = - (∑ i, z i:ℕ)*Real.log q := by - simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] - field_simp - have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) - rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he - simpa only [Real.exp_nat_mul,Real.exp_log hq] using he - -noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω - -lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by - apply layerAdapted_sum - intro i _ - exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) - -theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) - {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) - (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - classical - let : NeZero l := ⟨ne_of_gt hl⟩ - have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq - calc - _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => - finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)))) := by - apply finiteMean_mono - intro hi - simpa only [palindromeSlabCost,Fintype.card_fin] using - pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e - (assembleBits r s lo hi,X)) q hqp - _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => - q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ - _ ≤ finiteMean (fun _i : Fin l => - Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by - apply finiteMean_mono - intro i - by_cases ht : l+i.1+1 ≤ s+r - · have hs' : s ≤ l+i.1 := by omega - have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega - have hu : l+i.1-s < r := by omega - have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo - ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) - have hc := cycleCoefficient_decay l (l+i.1-s) (by - rw [Nat.cast_sub hs',Nat.cast_add] - have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs - have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ - linarith) (q^l) (one_le_pow₀ hq) (by - rw [Real.log_pow] - nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) - simp_rw [he,pow_mul] - exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) - · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e - simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] - exact Real.one_le_exp_iff.mpr (by positivity) - _ = _ := finiteMean_const _ - - -lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by - apply Finset.sum_eq_zero - intro i _ - exact palindromeLevelCost_gt _ _ (by omega) _ _ - -lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) - (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) - (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) - (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) - (hlog : Real.log q ≤ 1/250) : - finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ - finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by - obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd - exact adapted_mul_mean_le r s F _ hF hA _ - (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) - -def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) - -lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by - cases n with - | zero => simp [familyEnd] - | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith - -lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by - cases n with - | zero => omega - | succ n => - simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] - apply Nat.mul_le_mul_left - exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) - -noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := - ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω - -lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] - (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : - LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by - apply layerAdapted_sum - intro j hj - exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) - (familyEnd_ge L n j (Finset.mem_range.mp hj)) - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.BenesCoins + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp + +lemma mem_centralBlock (r H : ℕ) (b : Card r) (x : Card (H+r)) : + x ∈ centralBlock r H b ↔ (cardSplit r H x).1 = b := by + classical + constructor + · intro h + obtain ⟨z,_,rfl⟩ := Finset.mem_image.mp h + simp only [Equiv.apply_symm_apply] + · intro h + apply Finset.mem_image.mpr + refine ⟨(cardSplit r H x).2,Finset.mem_univ _,?_⟩ + rw [←h,Prod.mk.eta,Equiv.symm_apply_apply] + +lemma centralBlock_card (r H : ℕ) (b : Card r) : (centralBlock r H b).card = 2^H := by + classical + rw [centralBlock,Finset.card_image_of_injective] + · exact card_positions H + · intro x y h + exact congrArg Prod.snd ((cardSplit r H).symm.injective h) + +lemma centralBlock_disjoint (r H : ℕ) : + Pairwise (fun b b' => Disjoint (centralBlock r H b) (centralBlock r H b')) := by + classical + intro b b' h + apply Finset.disjoint_left.mpr + intro x hx hy + exact h (((mem_centralBlock r H b x).mp hx).symm.trans + ((mem_centralBlock r H b' x).mp hy)) + +lemma centralBlock_zero (H : ℕ) (b : Card 0) : centralBlock 0 H b = Finset.univ := by + classical + ext x + simp only [mem_centralBlock,Finset.mem_univ,iff_true] + exact Subsingleton.elim _ _ + +lemma centralBlock_step (r H : ℕ) (b : Bool) (c : Card r) : + centralBlock (r+1) H (Fin.cons b c) = (centralBlock r H c).image (Fin.cons b) := by + classical + simp only [centralBlock,Finset.image_image,cardSplit,Equiv.coe_fn_symm_mk, + Fin.cons_zero,Fin.tail_cons,Function.comp_def] + +lemma block_inter_step (r H : ℕ) (b : Bool) (c : Card r) (A : Finset (Card (H+(r+1)))) : + centralBlock (r+1) H (Fin.cons b c) ∩ A = + (centralBlock r H c ∩ childMarks A b).image (Fin.cons b) := by + classical + rw [centralBlock_step] + ext x + constructor + · intro hx + obtain ⟨hxB,hxA⟩ := Finset.mem_inter.mp hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hxB + exact Finset.mem_image.mpr ⟨y,Finset.mem_inter.mpr ⟨hy,(mem_childMarks A b y).mpr hxA⟩,rfl⟩ + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact Finset.mem_inter.mpr ⟨Finset.mem_image.mpr ⟨y,(Finset.mem_inter.mp hy).1,rfl⟩, + (mem_childMarks A b y).mp (Finset.mem_inter.mp hy).2⟩ + +lemma sparseMass_central_zero (H : ℕ) (A : Finset (Card H)) : + sparseMass (centralBlock 0 H) A = crowdedMass A.card := by + classical + simp only [sparseMass,centralBlock_zero,Finset.univ_inter,crowdedMass, + Finset.sum_const,Finset.card_univ,card_positions,pow_zero,one_nsmul] + +lemma sparseMass_central_step (r H : ℕ) (A : Finset (Card (H+(r+1)))) : + sparseMass (centralBlock (r+1) H) A = + sparseMass (centralBlock r H) (childMarks A false) + + sparseMass (centralBlock r H) (childMarks A true) := by + classical + unfold sparseMass + rw [←Equiv.sum_comp (headTailEquiv r).symm,Fintype.sum_prod_type] + have ht (b : Bool) (c : Card r) : (headTailEquiv r).symm (b,c) = Fin.cons b c := rfl + simp only [Fintype.sum_bool,ht] + have hc (b : Bool) (c : Card r) : + (centralBlock (r+1) H (Fin.cons b c) ∩ A).card = + (centralBlock r H c ∩ childMarks A b).card := by + rw [block_inter_step] + apply Finset.card_image_of_injective + intro x y h + simpa only [Fin.tail_cons] using congrArg Fin.tail h + simp only [hc] + exact add_comm _ _ + + +lemma inverseButterfly_coordinates_step (d : ℕ) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) + (x : Card (d+1)) : + headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm x) = + (Bool.xor (x 0) (ξ (Fin.tail x)), + (butterflyPerm d (decodeButterfly d + (if Bool.xor (x 0) (ξ (Fin.tail x)) then c.2 else c.1))).symm (Fin.tail x)) := by + rw [butterflyPerm_step] + rfl + +lemma inverseButterflyMarks_child (d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) + (c : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) (ξ : Card d → Bool) (b : Bool) : + childMarks (inverseButterflyMarks (d+1) (Finset.univ.image e) + ((coinStepEquiv d).symm (c,ξ))) b = + inverseButterflyMarks d + (Finset.univ.image (PairRouting.childEmbedding (e.trans (headTailEquiv d).toEmbedding) + (PairRouting.colors (e.trans (headTailEquiv d).toEmbedding) ξ) + (PairRouting.colors_compatible _ _) b)) (if b then c.2 else c.1) := by + classical + let x := e.trans (headTailEquiv d).toEmbedding + let col := PairRouting.colors x ξ + let child := PairRouting.childEmbedding x col (PairRouting.colors_compatible x ξ) b + have hp (i : ι) : headTailEquiv d ((butterflyPerm (d+1) + (decodeButterfly (d+1) ((coinStepEquiv d).symm (c,ξ)))).symm (e i)) = + (col i,(butterflyPerm d (decodeButterfly d (if col i then c.2 else c.1))).symm (x i).2) := + inverseButterfly_coordinates_step d c ξ (e i) + ext y + simp only [mem_childMarks,inverseButterflyMarks,Finset.image_image, + Finset.mem_image,Finset.mem_univ,true_and,Function.comp_def] + constructor + · rintro ⟨i,hi⟩ + have he := congrArg (headTailEquiv d) hi + rw [hp i] at he + change (col i,_) = (b,y) at he + have hb := congrArg Prod.fst he + have hy := congrArg Prod.snd he + dsimp only at hb hy + refine ⟨⟨i,hb⟩,?_⟩ + change (butterflyPerm d (decodeButterfly d (if b then c.2 else c.1))).symm (x i).2 = y + simpa only [hb] using hy + · rintro ⟨i,hi⟩ + refine ⟨i.val,?_⟩ + apply (headTailEquiv d).injective + rw [hp] + change (col i.val,_) = (b,y) + have hb : col i.val = b := i.property + rw [hb] + exact Prod.ext rfl hi + +lemma inverseButterflyMarks_card (d : ℕ) (A : Finset (Card d)) (ω : SwitchIndex d → Bool) : + (inverseButterflyMarks d A ω).card = A.card := by + classical + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d ω)).symm.injective + +lemma benes_input_coordinates (d : ℕ) (ω : BenesCoins (d+1)) : + ω.2 = (coinStepEquiv d).symm + (((benesStepEquiv d ω).1.1.2,(benesStepEquiv d ω).1.2.2),(benesStepEquiv d ω).2.1) := by + change ω.2 = (coinStepEquiv d).symm (coinStepEquiv d ω.2) + exact ((coinStepEquiv d).symm_apply_apply ω.2).symm + +lemma cutoffMass_central (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (ω : BenesCoins (H+r)) : + cutoffMass H (H+r) e ω = + sparseMass (centralBlock r H) (inverseButterflyMarks (H+r) (Finset.univ.image e) ω.2) := by + classical + induction r generalizing ι with + | zero => + rw [sparseMass_central_zero,inverseButterflyMarks_card, + Finset.card_image_of_injective _ e.injective,Finset.card_univ] + cases H with + | zero => + have hcard : Fintype.card ι ≤ 1 := by + have hh := Fintype.card_le_of_injective e e.injective + simpa only [Nat.add_zero,card_positions,pow_zero] using hh + simp [cutoffMass,crowdedMass,show ¬2≤Fintype.card ι by omega] + | succ H => simp only [cutoffMass,le_refl,ite_true] + | succ r ih => + simp only [Nat.add_succ] at * + rw [cutoffMass,ite_eq_right (by omega : ¬H+r+1≤H)] + let σ := benesStepEquiv (H+r) ω + let x := e.trans (headTailEquiv (H+r)).toEmbedding + let col := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + change cutoffMass H (H+r) (PairRouting.childEmbedding x col hc false) σ.1.1 + + cutoffMass H (H+r) (PairRouting.childEmbedding x col hc true) σ.1.2 = _ + rw [ih,ih,sparseMass_central_step,benes_input_coordinates (H+r) ω] + rw [inverseButterflyMarks_child,inverseButterflyMarks_child] + rfl + + +theorem palindrome_low_mgf (r H : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (H+r)) (q : ℝ) (hq : 1 ≤ q) + (hr : (2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H) ≤ 1/2) : + finiteMean (fun ω : BenesCoins (H+r) => q^(palindromeLowCost H (H+r) e ω)) ≤ + Real.exp ((2:ℝ)^r * (2 * ((2:ℝ)^H*((Fintype.card ι/(2:ℝ)^(H+r))*q^H))^2)) := by + classical + have hec : (Finset.univ.image e).card = Fintype.card ι := by + rw [Finset.card_image_of_injective _ e.injective,Finset.card_univ] + have hm := inverseButterfly_sparse_mgf (H+r) (centralBlock r H) + (centralBlock_disjoint r H) (Finset.univ.image e) (q^H) + (pow_nonneg (by linarith) _) (fun b => by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat] using hr) + calc + _ ≤ finiteMean (fun ω : BenesCoins (H+r) => (q^H)^(cutoffMass H (H+r) e ω)) := by + apply finiteMean_mono + intro ω + rw [←pow_mul] + exact pow_le_pow_right₀ hq (palindromeLowCost_le_cutoff H (H+r) e ω) + _ = finiteMean (fun ω : SwitchIndex (H+r) → Bool => + (q^H)^(sparseMass (centralBlock r H) + (inverseButterflyMarks (H+r) (Finset.univ.image e) ω))) := by + simp_rw [cutoffMass_central] + simp only [finiteMean_prod,finiteMean_const] + _ ≤ _ := by + simpa only [centralBlock_card,hec,Nat.cast_pow,Nat.cast_ofNat,Finset.sum_const, + Finset.card_univ,card_positions,nsmul_eq_mul] using hm + +variable {α B : Type*} {r s : ℕ} + +def parallelFreshPre (pre : α ≃ B × Card (s+r)) + (lo : B → Card r × SwitchIndex s → Bool) : α ≃ (B × Card s) × Card r := + ((pre.trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s))).trans + (Equiv.prodCongrRight (fun b => + (parallelPerm (lo b)).trans (Equiv.prodComm _ _)))).trans + (Equiv.prodAssoc _ _ _).symm + +def parallelFreshPost (post : B × Card (s+r) ≃ α) : (B × Card s) × Card r ≃ α := + (((Equiv.prodAssoc _ _ _).trans (Equiv.prodCongr (Equiv.refl B) + (Equiv.prodComm _ _))).trans (Equiv.prodCongr (Equiv.refl B) (cardSplit r s).symm)).trans post + +def parallelAssembled (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : B × SwitchIndex (s+r) → Bool := + fun i => assembleBits r s (lo i.1) (fun j => hi ((i.1,j.1),j.2)) i.2 + +lemma parallel_exposed_perm (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) + (hi : (B × Card s) × SwitchIndex r → Bool) : + relabeledPerm pre post (parallelAssembled lo hi) = + relabeledPerm (parallelFreshPre pre lo) (parallelFreshPost post) hi := by + ext x + have h := butterfly_split r s (lo (pre x).1) + (fun j => hi (((pre x).1,j.1),j.2)) (pre x).2 + have hh := congrArg (fun y => post ((pre x).1,(cardSplit r s).symm y)) h + simpa only [relabeledPerm,parallelAssembled,parallelPerm,parallelFreshPre,parallelFreshPost, + Equiv.trans_apply,Equiv.prodCongr_apply,Equiv.prodCongrRight,Equiv.coe_fn_mk, + Equiv.refl_apply,Equiv.prodComm_apply,Prod.swap,Equiv.prodAssoc_apply, + Equiv.prodAssoc_symm_apply,Prod.map,Equiv.symm_apply_apply] using hh + +theorem parallel_partially_exposed_log_mgf [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] + (pre : α ≃ B × Card (s+r)) (post : B × Card (s+r) ≃ α) + (lo : B → Card r × SwitchIndex s → Bool) (S : Finset α) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun hi : (B × Card s) × SwitchIndex r → Bool => + q^(Fintype.card (RoutingNetwork.SelectedCycle + (relabeledPerm pre post (parallelAssembled lo hi)) S)))) ≤ + (S.card:ℝ)/J*Real.log q + 2*q*S.card*Real.sqrt J/Real.sqrt ((2:ℝ)^r) := by + simp_rw [parallel_exposed_perm] + exact parallel_cycle_log_mgf (parallelFreshPre pre lo) (parallelFreshPost post) S J hJ q hq + +end Thorp +namespace Thorp +variable {α : Type*} [Fintype α] [DecidableEq α] + +lemma orbitSet_inverse (p : Equiv.Perm α) (x : α) : orbitSet p⁻¹ x = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_inv] + +lemma selectedCycle_inverse (p : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle p⁻¹ S) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Fintype.card_congr + refine { toFun := fun C => ⟨C.val,?_,C.property.2⟩ + invFun := fun C => ⟨C.val,?_,C.property.2⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x)⟩ + · obtain ⟨x,hx⟩ := C.property.1 + exact ⟨x,hx.trans (orbitSet_inverse p x).symm⟩ + +lemma orbitSet_conjugate (p g : Equiv.Perm α) (x : α) : + orbitSet (g*p*g⁻¹) (g x) = (orbitSet p x).image g := by + ext y + simp only [mem_orbitSet,Finset.mem_image] + rw [Equiv.Perm.sameCycle_conj] + change p.SameCycle (g.symm (g x)) (g.symm y) ↔ ∃ z, p.SameCycle x z ∧ g z = y + rw [Equiv.symm_apply_apply] + constructor + · intro h + exact ⟨g.symm y,h,g.apply_symm_apply y⟩ + · rintro ⟨z,hz,rfl⟩ + simpa only [Equiv.symm_apply_apply] using hz + +noncomputable def conjugateCycle (p g : Equiv.Perm α) (S : Finset α) + (C : RoutingNetwork.SelectedCycle p S) : + RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g) := by + refine ⟨C.val.image g,?_,Finset.image_subset_image C.property.2⟩ + obtain ⟨x,hx⟩ := C.property.1 + exact ⟨g x,by rw [hx,orbitSet_conjugate]⟩ + +lemma conjugateCycle_injective (p g : Equiv.Perm α) (S : Finset α) : + Function.Injective (conjugateCycle p g S) := by + intro C D he + apply Subtype.ext + exact (Finset.image_injective g.injective) (congrArg Subtype.val he) + +lemma selectedCycle_conjugate (p g : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle (g*p*g⁻¹) (S.image g)) = + Fintype.card (RoutingNetwork.SelectedCycle p S) := by + apply Nat.le_antisymm + · have h := Fintype.card_le_of_injective _ + (conjugateCycle_injective (g*p*g⁻¹) g⁻¹ (S.image g)) + have hp : g⁻¹*(g*p*g⁻¹)*g = p := by group + rw [inv_inv,hp] at h + have hs : (S.image g).image g.symm = S := by + ext x + simp only [Finset.mem_image] + constructor + · rintro ⟨y,⟨z,hz,rfl⟩,he⟩ + have hz' : z = x := by simpa only [Equiv.symm_apply_apply] using he + exact hz' ▸ hz + · intro hx + exact ⟨g x,⟨x,hx,rfl⟩,g.symm_apply_apply x⟩ + change _ ≤ Fintype.card (RoutingNetwork.SelectedCycle p ((S.image g).image g.symm)) at h + rw [hs] at h + exact h + · exact Fintype.card_le_of_injective _ (conjugateCycle_injective p g S) + +lemma alternatingCycles_le_projection {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × α) (p : Bool → Equiv.Perm α) : + PairRouting.alternatingCycles e p ≤ + Fintype.card (RoutingNetwork.SelectedCycle (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false)) := by + have h := CycleColoring.card_alternating_cycles_le (PairRouting.alternatingProjection p) + (boolFiber (PairRouting.labelSet e) false) (boolFiber (PairRouting.labelSet e) true) + simpa only [PairRouting.alternatingCycles,childJoin_boolFiber] using h + +lemma projectionCycles_forward (X₀ X₁ Y₀ Y₁ : Equiv.Perm α) (S : Finset α) : + Fintype.card (RoutingNetwork.SelectedCycle + ((Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹)) S) = + Fintype.card (RoutingNetwork.SelectedCycle + (X₀⁻¹*X₁*Y₁⁻¹*Y₀) (S.image X₀.symm)) := by + let p := (Y₀*X₀⁻¹)⁻¹*(Y₁*X₁⁻¹) + calc + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀) + (S.image X₀.symm)) := by + change Fintype.card (RoutingNetwork.SelectedCycle p S) = _ + have h := (selectedCycle_conjugate p X₀⁻¹ S).symm + rw [inv_inv] at h + exact h + _ = Fintype.card (RoutingNetwork.SelectedCycle (X₀⁻¹*p*X₀)⁻¹ + (S.image X₀.symm)) := (selectedCycle_inverse _ _).symm + _ = _ := by + have he : (X₀⁻¹*p*X₀)⁻¹ = X₀⁻¹*X₁*Y₁⁻¹*Y₀ := by dsimp only [p]; group + rw [he] + +end Thorp +namespace Thorp + +noncomputable def cycleCoefficient (r J : ℕ) (q : ℝ) : ℝ := + Real.log q / J + 2*q*Real.sqrt J/Real.sqrt ((2:ℝ)^r) + +lemma cycleCoefficient_nonneg (r J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + 0 ≤ cycleCoefficient r J q := by + unfold cycleCoefficient + exact add_nonneg (div_nonneg (Real.log_nonneg hq) (Nat.cast_nonneg _)) + (div_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _)) + +lemma projectionSide_card_le {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] + (e : ι ↪ Bool × α) : (boolFiber (PairRouting.labelSet e) false).card ≤ Fintype.card ι := by + have h := card_childJoin (boolFiber (PairRouting.labelSet e) false) + (boolFiber (PairRouting.labelSet e) true) + rw [childJoin_boolFiber,PairRouting.card_labelSet] at h + omega + +theorem node_partial_mgf (r s : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Bool × Card (s+r)) (X₀ X₁ Y₁ : Equiv.Perm (Card (s+r))) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient r J q) := by + classical + let S := boolFiber (PairRouting.labelSet e) false + let S' := S.image X₀.symm + let post := X₀⁻¹*X₁*Y₁⁻¹ + let count := fun hi : Card s × SwitchIndex r → Bool => + Fintype.card (RoutingNetwork.SelectedCycle + ((Equiv.refl _).trans (butterflyPerm (s+r) + (decodeButterfly (s+r) (assembleBits r s lo hi))) |>.trans post) S') + have hpoint (hi : Card s × SwitchIndex r → Bool) : + PairRouting.alternatingCycles e (fun b => if b then Y₁*X₁⁻¹ else + butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹) ≤ count hi := by + refine (alternatingCycles_le_projection e _).trans_eq ?_ + simp only [PairRouting.alternatingProjection,Bool.false_eq_true,↓reduceIte] + change Fintype.card (RoutingNetwork.SelectedCycle + ((butterflyPerm (s+r) (decodeButterfly (s+r) (assembleBits r s lo hi))*X₀⁻¹)⁻¹ * (Y₁*X₁⁻¹)) S) = count hi + exact projectionCycles_forward X₀ X₁ _ Y₁ S + have hm := partially_exposed_cycle_log_mgf (Equiv.refl (Card (s+r))) post lo S' J hJ q hq + have hp : 0 < finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_pos (fun _ => pow_pos (by linarith) _) + have hb : finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) ≤ + Real.exp (S'.card * cycleCoefficient r J q) := by + rw [←Real.exp_log hp] + apply Real.exp_le_exp.mpr + calc + _ ≤ _ := hm + _ = _ := by unfold cycleCoefficient; ring + have hcard : S'.card ≤ Fintype.card ι := by + rw [show S'.card = S.card from Finset.card_image_of_injective _ X₀.symm.injective] + exact projectionSide_card_le e + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => q^(count hi)) := + finiteMean_mono (fun hi => pow_le_pow_right₀ hq (hpoint hi)) + _ ≤ Real.exp (S'.card * cycleCoefficient r J q) := hb + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + (by exact_mod_cast hcard) (cycleCoefficient_nonneg r J q hq)) + + +def highStepEquiv (r s : ℕ) : (Card s × SwitchIndex (r+1) → Bool) ≃ + (((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) where + toFun hi := ((fun j => hi (j.1,Sum.inr (false,j.2)), + fun j => hi (j.1,Sum.inr (true,j.2))),fun j => hi (j.1,Sum.inl j.2)) + invFun c := fun j => match j.2 with + | Sum.inl y => c.2 (j.1,y) + | Sum.inr (b,i) => if b then c.1.2 (j.1,i) else c.1.1 (j.1,i) + left_inv hi := by + funext j + rcases j with ⟨z,y|⟨b,i⟩⟩ + · rfl + · cases b <;> rfl + right_inv c := by + rcases c with ⟨⟨h₀,h₁⟩,η⟩ + rfl + +lemma assembleBits_step (r s : ℕ) (lo : Card (r+1) × SwitchIndex s → Bool) + (c : ((Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) × + (Card s × Card r → Bool)) : + assembleBits (r+1) s lo ((highStepEquiv r s).symm c) = + (coinStepEquiv (s+r)).symm + ((assembleBits r s (fun j => lo (Fin.cons false j.1,j.2)) c.1.1, + assembleBits r s (fun j => lo (Fin.cons true j.1,j.2)) c.1.2), + fun y => c.2 ((cardSplit r s y).2,(cardSplit r s y).1)) := by + funext i + rcases i with y | ⟨b,i⟩ + · rfl + · cases b <;> rfl + +noncomputable def palindromeLevelCost (t : ℕ) : (d : ℕ) → {ι : Type*} → [Fintype ι] → + (ι ↪ Card d) → BenesCoins d → ℕ + | 0, _, _, _, _ => 0 + | d+1, _, _, e, ω => + let σ := benesStepEquiv d ω + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x σ.2.1 + let hc := PairRouting.colors_compatible x σ.2.1 + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x σ.2.1) + (fun b => palindromePerm d (if b then σ.1.2 else σ.1.1)) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) σ.1.1 + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) σ.1.2 + +lemma palindromeLevelCost_step (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card (d+1)) (X Y : (SwitchIndex d → Bool) × (SwitchIndex d → Bool)) + (ξ η : Card d → Bool) : + palindromeLevelCost t (d+1) e + ((coinStepEquiv d).symm (Y,η),(coinStepEquiv d).symm (X,ξ)) = + let x := e.trans (headTailEquiv d).toEmbedding + let c := PairRouting.colors x ξ + let hc := PairRouting.colors_compatible x ξ + if t = d+1 then PairRouting.alternatingCycles (PairRouting.switchedEmbedding x ξ) + (fun b => palindromePerm d (if b then (Y.2,X.2) else (Y.1,X.1))) else + palindromeLevelCost t d (PairRouting.childEmbedding x c hc false) (Y.1,X.1) + + palindromeLevelCost t d (PairRouting.childEmbedding x c hc true) (Y.2,X.2) := by + rw [palindromeLevelCost] + rfl + +lemma palindromeLevelCost_gt (t d : ℕ) (h : d < t) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeLevelCost t d e ω = 0 := by + classical + induction d generalizing ι with + | zero => rfl + | succ d ih => + rw [palindromeLevelCost,ite_eq_right (by omega : t ≠ d+1),ih (by omega),ih (by omega),Nat.zero_add] + + +theorem palindrome_level_partial_mgf (r s u : ℕ) (hu : u < r) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeLevelCost (s+u+1) (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * cycleCoefficient u J q) := by + classical + induction r generalizing u ι with + | zero => omega + | succ r ih => + simp only [Nat.add_succ] at * + let χ := coinStepEquiv (s+r) X + let x := e.trans (headTailEquiv (s+r)).toEmbedding + let c := PairRouting.colors x χ.2 + let hc := PairRouting.colors_compatible x χ.2 + let e₀ := PairRouting.childEmbedding x c hc false + let e₁ := PairRouting.childEmbedding x c hc true + let e' := PairRouting.switchedEmbedding x χ.2 + let lo₀ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons false j.1,j.2) + let lo₁ : Card r × SwitchIndex s → Bool := fun j => lo (Fin.cons true j.1,j.2) + let Y₀ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₀ hi + let Y₁ := fun hi : Card s × SwitchIndex r → Bool => assembleBits r s lo₁ hi + let N := fun hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool) => + PairRouting.alternatingCycles e' (fun b => if b then palindromePerm (s+r) (Y₁ hi.2,χ.1.2) + else palindromePerm (s+r) (Y₀ hi.1,χ.1.1)) + let L₀ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₀ (Y₀ hi,χ.1.1) + let L₁ := fun hi : Card s × SwitchIndex r → Bool => + palindromeLevelCost (s+u+1) (s+r) e₁ (Y₁ hi,χ.1.2) + have hs (hi : (Card s × SwitchIndex r → Bool) × (Card s × SwitchIndex r → Bool)) + (η : Card s × Card r → Bool) : + palindromeLevelCost (s+u+1) (s+r+1) e + (assembleBits (r+1) s lo ((highStepEquiv r s).symm (hi,η)),X) = + if u = r then N hi else L₀ hi.1 + L₁ hi.2 := by + rw [assembleBits_step] + conv_lhs => rw [←(coinStepEquiv (s+r)).symm_apply_apply X] + rw [palindromeLevelCost_step] + simp only [Nat.add_right_cancel_iff,Nat.add_left_cancel_iff] + dsimp only [χ,x,c,hc,e₀,e₁,e',lo₀,lo₁,Y₀,Y₁,N,L₀,L₁] + congr 2 + funext b + cases b <;> rfl + rw [finiteMean_equiv (highStepEquiv r s),finiteMean_prod] + simp_rw [hs,finiteMean_const] + by_cases hur : u = r + · subst u + simp only [ite_true] + rw [finiteMean_prod,finiteMean_comm] + calc + _ ≤ finiteMean (fun _hi : Card s × SwitchIndex r → Bool => + Real.exp (Fintype.card ι * cycleCoefficient r J q)) := by + apply finiteMean_mono + intro hi + have hn := node_partial_mgf r s e' + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.1)) + (butterflyPerm (s+r) (decodeButterfly (s+r) χ.1.2)) + (butterflyPerm (s+r) (decodeButterfly (s+r) (Y₁ hi))) lo₀ J hJ q hq + exact hn + _ = _ := finiteMean_const _ + · simp only [ite_eq_right hur,pow_add] + rw [finiteMean_prod_mul (fun hi => q ^ L₀ hi) (fun hi => q ^ L₁ hi)] + have hu' : u < r := by omega + have h₀ := ih u hu' e₀ χ.1.1 lo₀ + have h₁ := ih u hu' e₁ χ.1.2 lo₁ + have hp := mul_le_mul h₀ h₁ (finiteMean_nonneg (fun _ => pow_nonneg (by linarith) _)) + (Real.exp_nonneg _) + refine hp.trans_eq ?_ + rw [←Real.exp_add] + congr 1 + have hcount := PairRouting.color_card_add c + have hcount' : (Fintype.card {i : ι // c i = false} : ℝ) + + Fintype.card {i : ι // c i = true} = Fintype.card ι := by exact_mod_cast hcount + change (Fintype.card {i : ι // c i = false} : ℝ) * cycleCoefficient u J q + + Fintype.card {i : ι // c i = true} * cycleCoefficient u J q = _ + rw [←add_mul,hcount'] + + +def switchHeight : (d : ℕ) → SwitchIndex d → ℕ + | 0, i => nomatch i + | d+1, Sum.inl _ => d+1 + | d+1, Sum.inr (_,i) => switchHeight d i + +lemma switchHeight_le (d : ℕ) (i : SwitchIndex d) : switchHeight d i ≤ d := by + induction d with + | zero => exact Empty.elim i + | succ d ih => + rcases i with y | ⟨b,i⟩ + · exact le_refl _ + · exact (ih i).trans (Nat.le_succ d) + +def AgreeThrough (d s : ℕ) (Y Y' : SwitchIndex d → Bool) : Prop := + ∀ i, switchHeight d i ≤ s → Y i = Y' i + +def LayerAdapted (d s : ℕ) {β : Type*} (f : (SwitchIndex d → Bool) → β) : Prop := + ∀ Y Y', AgreeThrough d s Y Y' → f Y = f Y' + +lemma agreeThrough_mono {d s t : ℕ} (h : s ≤ t) {Y Y' : SwitchIndex d → Bool} + (hh : AgreeThrough d t Y Y') : AgreeThrough d s Y Y' := + fun i hi => hh i (hi.trans h) + +lemma layerAdapted_mono {d s t : ℕ} {β : Type*} {f : (SwitchIndex d → Bool) → β} + (hf : LayerAdapted d s f) (h : s ≤ t) : LayerAdapted d t f := + fun Y Y' hh => hf Y Y' (agreeThrough_mono h hh) + +lemma layerAdapted_comp {d s : ℕ} {α β : Type*} {f : (SwitchIndex d → Bool) → α} + (hf : LayerAdapted d s f) (g : α → β) : LayerAdapted d s (g ∘ f) := + fun Y Y' h => congrArg g (hf Y Y' h) + +lemma layerAdapted_sum {d s : ℕ} {ι : Type*} (A : Finset ι) + (f : ι → (SwitchIndex d → Bool) → ℕ) + (hf : ∀ i ∈ A, LayerAdapted d s (f i)) : + LayerAdapted d s (fun Y => ∑ i ∈ A, f i Y) := by + intro Y Y' h + exact Finset.sum_congr rfl (fun i hi => hf i hi Y Y' h) + +lemma assembleBits_agree (r s : ℕ) (lo : Card r × SwitchIndex s → Bool) + (hi hi' : Card s × SwitchIndex r → Bool) : + AgreeThrough (s+r) s (assembleBits r s lo hi) (assembleBits r s lo hi') := by + induction r with + | zero => intro i _; rfl + | succ r ih => + intro i h + rcases i with y | ⟨b,i⟩ + · have : s+r+1 ≤ s := h + omega + · exact ih (fun j => lo (Fin.cons b j.1,j.2)) + (fun j => hi (j.1,Sum.inr (b,j.2))) (fun j => hi' (j.1,Sum.inr (b,j.2))) i h + +lemma palindromeLevelCost_adapted (t d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (t-1) (fun Y => palindromeLevelCost t d e (Y,X)) := by + classical + induction d generalizing ι with + | zero => intro Y Y' _; rfl + | succ d ih => + intro Y Y' h + change palindromeLevelCost t (d+1) e (Y,X) = palindromeLevelCost t (d+1) e (Y',X) + conv_lhs => rw [←(coinStepEquiv d).symm_apply_apply Y,←(coinStepEquiv d).symm_apply_apply X] + conv_rhs => rw [←(coinStepEquiv d).symm_apply_apply Y',←(coinStepEquiv d).symm_apply_apply X] + rw [palindromeLevelCost_step,palindromeLevelCost_step] + by_cases ht : t = d+1 + · subst t + rw [ite_eq_left rfl,ite_eq_left rfl] + have he₀ : (coinStepEquiv d Y).1.1 = (coinStepEquiv d Y').1.1 := by + funext i + exact h (Sum.inr (false,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + have he₁ : (coinStepEquiv d Y).1.2 = (coinStepEquiv d Y').1.2 := by + funext i + exact h (Sum.inr (true,i)) (by simpa only [switchHeight,Nat.add_sub_cancel] using switchHeight_le d i) + rw [he₀,he₁] + · rw [ite_eq_right ht,ite_eq_right ht] + congr 1 + · apply ih + intro i hi + exact h (Sum.inr (false,i)) hi + · apply ih + intro i hi + exact h (Sum.inr (true,i)) hi + +lemma adapted_mul_mean_le (r s : ℕ) (F G : (SwitchIndex (s+r) → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted (s+r) s F) (B : ℝ) + (hG : ∀ lo : Card r × SwitchIndex s → Bool, + finiteMean (fun hi : Card s × SwitchIndex r → Bool => G (assembleBits r s lo hi)) ≤ B) : + finiteMean (fun Y => F Y*G Y) ≤ finiteMean F * B := by + rw [finiteMean_split r s,finiteMean_split r s F,←finiteMean_mul_const] + apply finiteMean_mono + intro lo + let H : Card s × SwitchIndex r → Bool := fun _ => false + have hh (hi : Card s × SwitchIndex r → Bool) : + F (assembleBits r s lo hi) = F (assembleBits r s lo H) := + hA _ _ (assembleBits_agree r s lo hi H) + simp_rw [hh,finiteMean_const] + rw [show (fun hi => F (assembleBits r s lo H) * G (assembleBits r s lo hi)) = + (fun hi => G (assembleBits r s lo hi) * F (assembleBits r s lo H)) by + funext hi; exact mul_comm _ _,finiteMean_mul_const] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hG lo) (hF _) + + +theorem cycleCoefficient_decay (l r : ℕ) (hr : (l:ℝ)/2 ≤ r) + (q : ℝ) (hq : 1 ≤ q) (hlog : Real.log q ≤ (l:ℝ)/250) : + cycleCoefficient r ⌈Real.exp ((l:ℝ)/32)⌉₊ q ≤ + 68 * Real.exp (-(l:ℝ)/64) := by + let E := Real.exp ((l:ℝ)/32) + let J := ⌈E⌉₊ + have hl : (0:ℝ) ≤ l := Nat.cast_nonneg _ + have hE : 1 ≤ E := Real.one_le_exp_iff.mpr (by positivity) + have hEpos : 0 < E := Real.exp_pos _ + have hEJ : E ≤ (J:ℝ) := Nat.le_ceil E + have hJ : (1:ℝ) ≤ J := hE.trans hEJ + have hJpos : (0:ℝ) < J := lt_of_lt_of_le (by norm_num) hJ + have hJE : (J:ℝ) ≤ 2*E := by + have h := Nat.ceil_lt_add_one (le_of_lt hEpos) + change (J:ℝ) < E+1 at h + linarith + have hsqJ : Real.sqrt J ≤ (J:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + have hqE : q ≤ Real.exp ((l:ℝ)/250) := by + rw [←Real.exp_log hqp] + exact Real.exp_le_exp.mpr hlog + have hln : (1/2:ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢ + exact hh + have hden : Real.exp ((l:ℝ)/8) ≤ Real.sqrt ((2:ℝ)^r) := by + have he : (2:ℝ)^r = Real.exp ((r:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he,Real.sqrt_eq_rpow,Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] + apply Real.exp_le_exp.mpr + have hrn : (0:ℝ) ≤ r := Nat.cast_nonneg _ + nlinarith + have hlog' : Real.log q ≤ (l:ℝ) := by linarith + have h₁ : Real.log q / (J:ℝ) ≤ 64*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (l:ℝ)/E := div_le_div₀ (by positivity) hlog' hEpos hEJ + _ ≤ (64*Real.exp ((l:ℝ)/64))/E := by + apply div_le_div_of_nonneg_right _ (le_of_lt hEpos) + have hh := Real.add_one_le_exp ((l:ℝ)/64) + linarith + _ = _ := by + dsimp [E] + rw [mul_div_assoc,←Real.exp_sub] + congr 2 + ring + have h₂ : 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ + 4*Real.exp (-(l:ℝ)/64) := by + calc + _ ≤ (4*Real.exp ((l:ℝ)/250)*E)/Real.exp ((l:ℝ)/8) := by + apply div_le_div₀ (by positivity) _ (Real.exp_pos _) hden + have hs := hsqJ.trans hJE + have hm := mul_le_mul hqE hs (Real.sqrt_nonneg _) (Real.exp_nonneg _) + nlinarith + _ = 4*Real.exp ((l:ℝ)/250+(l:ℝ)/32-(l:ℝ)/8) := by + dsimp [E] + rw [mul_assoc,←Real.exp_add,mul_div_assoc,←Real.exp_sub] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr _) (by norm_num) + linarith + change Real.log q / (J:ℝ) + 2*q*Real.sqrt J / Real.sqrt ((2:ℝ)^r) ≤ _ + linarith + +lemma cycleCutoff_pos (l : ℕ) : 0 < ⌈Real.exp ((l:ℝ)/32)⌉₊ := by + have h := Nat.le_ceil (Real.exp ((l:ℝ)/32)) + have he := Real.exp_pos ((l:ℝ)/32) + have : (0:ℝ) < ⌈Real.exp ((l:ℝ)/32)⌉₊ := lt_of_lt_of_le he h + exact_mod_cast this + + +lemma pow_sum_le_mean_powers {ι : Type*} [Fintype ι] [Nonempty ι] + (z : ι → ℕ) (q : ℝ) (hq : 0 < q) : + q^(∑ i, z i) ≤ finiteMean (fun i => q^(Fintype.card ι*z i)) := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hm : finiteMean (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) = + (∑ i, z i:ℕ)*Real.log q := by + simp only [finiteMean,Nat.cast_mul,Nat.cast_sum,←Finset.mul_sum,←Finset.sum_mul] + field_simp + have he := exp_finiteMean_le (fun i => (Fintype.card ι*z i:ℕ)*Real.log q) + rw [hm,Real.exp_nat_mul,Real.exp_log hq] at he + simpa only [Real.exp_nat_mul,Real.exp_log hq] using he + +noncomputable def palindromeSlabCost (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ i : Fin l, palindromeLevelCost (l+i.1+1) d e ω + +lemma palindromeSlabCost_adapted (l d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (2*l) (fun Y => palindromeSlabCost l d e (Y,X)) := by + apply layerAdapted_sum + intro i _ + exact layerAdapted_mono (palindromeLevelCost_adapted (l+i.1+1) d e X) (by omega) + +theorem palindrome_slab_partial_mgf (r s l : ℕ) (hl : 0 < l) (hs : 2*s ≤ l) + {ι : Type*} [Fintype ι] (e : ι ↪ Card (s+r)) (X : SwitchIndex (s+r) → Bool) + (lo : Card r × SwitchIndex s → Bool) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(palindromeSlabCost l (s+r) e (assembleBits r s lo hi,X))) ≤ + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + classical + let : NeZero l := ⟨ne_of_gt hl⟩ + have hqp : 0 < q := lt_of_lt_of_le (by norm_num) hq + calc + _ ≤ finiteMean (fun hi : Card s × SwitchIndex r → Bool => + finiteMean (fun i : Fin l => q^(l*palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)))) := by + apply finiteMean_mono + intro hi + simpa only [palindromeSlabCost,Fintype.card_fin] using + pow_sum_le_mean_powers (fun i : Fin l => palindromeLevelCost (l+i.1+1) (s+r) e + (assembleBits r s lo hi,X)) q hqp + _ = finiteMean (fun i : Fin l => finiteMean (fun hi : Card s × SwitchIndex r → Bool => + q^(l*palindromeLevelCost (l+i.1+1) (s+r) e (assembleBits r s lo hi,X)))) := finiteMean_comm _ + _ ≤ finiteMean (fun _i : Fin l => + Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64)))) := by + apply finiteMean_mono + intro i + by_cases ht : l+i.1+1 ≤ s+r + · have hs' : s ≤ l+i.1 := by omega + have he : l+i.1+1 = s+(l+i.1-s)+1 := by omega + have hu : l+i.1-s < r := by omega + have hm := palindrome_level_partial_mgf r s (l+i.1-s) hu e X lo + ⌈Real.exp ((l:ℝ)/32)⌉₊ (cycleCutoff_pos l) (q^l) (one_le_pow₀ hq) + have hc := cycleCoefficient_decay l (l+i.1-s) (by + rw [Nat.cast_sub hs',Nat.cast_add] + have hsr : (2:ℝ)*s ≤ l := by exact_mod_cast hs + have hi : (0:ℝ) ≤ i.1 := Nat.cast_nonneg _ + linarith) (q^l) (one_le_pow₀ hq) (by + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg l)]) + simp_rw [he,pow_mul] + exact hm.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (Nat.cast_nonneg _))) + · have hz := palindromeLevelCost_gt (l+i.1+1) (s+r) (by omega) e + simp only [hz,Nat.mul_zero,pow_zero,finiteMean_const] + exact Real.one_le_exp_iff.mpr (by positivity) + _ = _ := finiteMean_const _ + + +lemma palindromeSlabCost_gt (l d : ℕ) (h : d ≤ l) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : palindromeSlabCost l d e ω = 0 := by + apply Finset.sum_eq_zero + intro i _ + exact palindromeLevelCost_gt _ _ (by omega) _ _ + +lemma palindrome_slab_adapted_mul_le (d s l : ℕ) (hsd : s ≤ d) (hl : 0 < l) + (hs : 2*s ≤ l) {ι : Type*} [Fintype ι] (e : ι ↪ Card d) + (X : SwitchIndex d → Bool) (F : (SwitchIndex d → Bool) → ℝ) + (hF : ∀ Y, 0 ≤ F Y) (hA : LayerAdapted d s F) (q : ℝ) (hq : 1 ≤ q) + (hlog : Real.log q ≤ 1/250) : + finiteMean (fun Y => F Y*q^(palindromeSlabCost l d e (Y,X))) ≤ + finiteMean F * Real.exp (Fintype.card ι * (68*Real.exp (-(l:ℝ)/64))) := by + obtain ⟨r,rfl⟩ := Nat.exists_eq_add_of_le hsd + exact adapted_mul_mean_le r s F _ hF hA _ + (fun lo => palindrome_slab_partial_mgf r s l hl hs e X lo q hq hlog) + +def familyEnd (L n : ℕ) : ℕ := if n = 0 then 0 else 2*(L*4^(n-1)) + +lemma familyEnd_two (L n : ℕ) : 2*familyEnd L n ≤ L*4^n := by + cases n with + | zero => simp [familyEnd] + | succ n => simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one,pow_succ]; nlinarith + +lemma familyEnd_ge (L n j : ℕ) (hj : j < n) : 2*(L*4^j) ≤ familyEnd L n := by + cases n with + | zero => omega + | succ n => + simp only [familyEnd,Nat.succ_ne_zero,ite_false,Nat.add_one_sub_one] + apply Nat.mul_le_mul_left + exact Nat.mul_le_mul_left L (Nat.pow_le_pow_right (by decide) (by omega : j ≤ n)) + +noncomputable def palindromeFamilyCost (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (ω : BenesCoins d) : ℕ := + ∑ j ∈ Finset.range n, palindromeSlabCost (L*4^j) d e ω + +lemma palindromeFamilyCost_adapted (L n d : ℕ) {ι : Type*} [Fintype ι] + (e : ι ↪ Card d) (X : SwitchIndex d → Bool) : + LayerAdapted d (familyEnd L n) (fun Y => palindromeFamilyCost L n d e (Y,X)) := by + apply layerAdapted_sum + intro j hj + exact layerAdapted_mono (palindromeSlabCost_adapted (L*4^j) d e X) + (familyEnd_ge L n j (Finset.mem_range.mp hj)) + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/PriorPaths.lean b/lean/OAI/Probability/ThorpRouting/Tail/PriorPaths.lean index ddfcaeec5cc0a335cf99cbce628913b9f9264f0b..52f76f1bf375e197116a89f843094972fcef4070 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/PriorPaths.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/PriorPaths.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.AssignmentSlots - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter -namespace RoutingNetwork -variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] - {d : ℕ} (R : RoutingNetwork α ι d) -lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : - s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) - (hz : z ∉ V) : - (terminalCharge R b z V : ℝ) = ∑ s : ι, - ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + - (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : R.path b z ∩ exposedPaths R b V = - Finset.univ.filter (fun s => - ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ - ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (R.users b s).1 = z <;> - by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -omit [DecidableEq α] in -@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) (i : Fin A) : - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : ι, - ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := R.users_ne b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (R.users b s).1 <;> - by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) - (z : Terminal o) (u v : α) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : α) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : α) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) - (b : ι → Bool) (z : Terminal o) : - rotationCharge R o b z = ∑ i : Fin A, - (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -omit [DecidableEq α] in -@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -omit [DecidableEq α] in -lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree -open Thorp.QueryTree - -lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := R.perm ω - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles R S L ∅).succeeds ω = true ∧ - ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by - classical - let b := ω - let p := R.perm b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ - -end QueryTree -section Collections -variable {A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) - (o : α → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {o : α → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -omit [DecidableEq α] in -lemma owner_ext {o o' : α → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : - (∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := R.perm ω - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by - classical - let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound R hm (ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : ι → Bool) : ℝ := - if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : ι → Bool) : - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (R.perm ω) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) - _ = ∑ c : RootedSlots (R.perm ω) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le R S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) - -lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment R S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -section CycleCounting -variable {A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := - {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} - (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} - (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : α) (i : Fin A) : - assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by - classical - unfold assignmentOwner - split_ifs with h - · constructor - · intro hi - have hx := Classical.choose_spec h - rw [Option.some.inj hi] at hx - exact hx - · intro hx - have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx - exact congrArg some (f.property.1 he) - · constructor - · intro hi; contradiction - · intro hx; exact (h ⟨i,hx⟩).elim - -lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by - ext x - simp only [mem_cycleFiber,assignmentOwner_eq_some] - -noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : CycleSlots p S r := - ⟨assignmentOwner f,by - refine ⟨?_,?_,?_⟩ - · intro i - rw [assignmentOwner_fiber] - exact f.property.2 i - · intro i - rw [assignmentOwner_fiber] - exact (f.val i).property.2 - · intro i x hx - rw [assignmentOwner_fiber] - exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ - -noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - CycleSlots p S r ≃ SlotAssignment p S r where - toFun := slotsToAssignment - invFun := assignmentToSlots - left_inv c := by - apply Subtype.ext - apply owner_ext - intro i - rw [assignmentToSlots,assignmentOwner_fiber] - rfl - right_inv f := by - apply Subtype.ext - funext i - apply Subtype.ext - exact assignmentOwner_fiber f i - -end CycleCounting - -section GroupedCounting -variable {A : ℕ} - -abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} - -def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := - ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ - -abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} -abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := - {C : SelectedCycle p S // C.val.card = j} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : - Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ - -abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := - ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val - -noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => - { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ - inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } - -noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := - ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans - (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans - ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans - (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) - -noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} - (F : GroupedAssignments p S r) : SlotAssignment p S r := - ⟨groupsEmbedding F, (groupsEmbedding F).injective, - fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ - -noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - SlotAssignment p S r ≃ GroupedAssignments p S r where - toFun := assignmentToGroups - invFun := groupsToAssignment - left_inv f := by - apply Subtype.ext - rfl - right_inv F := by - funext j - apply Function.Embedding.ext - intro i - rcases i with ⟨i,hi⟩ - subst j - rfl - -lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : - Fintype.card (CycleSlots p S r) = - ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) := by - classical - rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), - Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] - simp only [Fintype.card_embedding_eq] - -lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : ι → Bool => - (∏ j : LengthClass r, - (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial - (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr - -end GroupedCounting - -section AllLengths -variable {A : ℕ} - -noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where - toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ - invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by - simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ - left_inv f := by apply Subtype.ext; funext i; simp - right_inv f := by apply Subtype.ext; funext i; simp - -lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) - (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : - Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by - exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans - ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) - -lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : - finiteMean (fun ω : ι → Bool => - (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) - simp_rw [←card_cycleSlots_relabel] at h - have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) - simpa only [Function.comp_apply,hp] using h - -abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // C.val.card ≤ J} - -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (ShortCycle p S J) := Fintype.ofFinite _ - -noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : Fin J := - ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ - -lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} - (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by - have := C.val.nonempty.card_pos - simp only [shortCycleLength] - omega - -noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fin A ↪ ShortCycle p S J) ≃ - Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where - toFun f := ⟨fun i => shortCycleLength (f i), - ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), - fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ - invFun c := - { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ - inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } - left_inv f := by - apply Function.Embedding.ext - intro i - rfl - right_inv c := by - rcases c with ⟨r,f⟩ - have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by - funext i - apply Fin.ext - simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] - apply Sigma.ext he - apply (Subtype.heq_iff_coe_eq (by - intro x - change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ - simp only [f.property.2,Nat.add_sub_cancel])).mpr - rfl - -lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - (Fintype.card (ShortCycle p S J)).descFactorial A = - ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by - classical - have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) - simp only [Fintype.card_fin] at hc - rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] - apply Finset.sum_congr rfl - intro r _ - exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm - -end AllLengths - -section CycleMGF - -lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : - finiteMean (fun ω : ι → Bool => - ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by - classical - simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] - calc - _ ≤ ∑ r : Fin A → Fin J, - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by - apply Finset.sum_le_sum - intro r _ - exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) - _ = _ := by - rw [←Finset.mul_sum,mul_pow] - congr 1 - rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - -noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := - ∑ C : SelectedCycle p S, C.val.card - -lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by - classical - let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := - fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ - have hi : Function.Injective f := by - intro c e h - have hx : c.2.val = e.2.val := congrArg Subtype.val h - have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) - rcases c with ⟨c,x⟩ - rcases e with ⟨e,y⟩ - dsimp only at hC - subst e - have he : x=y := Subtype.ext hx - cases he - rfl - have hh := Fintype.card_le_of_injective f hi - simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh - -lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (ShortCycle p S J) ≤ S.card := by - classical - calc - _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ - _ = ∑ _ : SelectedCycle p S, 1 := by simp - _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) - _ ≤ _ := cycleMass_le p S - -lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : - finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ - Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by - apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) - · positivity - · exact hq - · exact butterfly_shortCycle_moment R S J - -end CycleMGF - - -abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := - {C : SelectedCycle p S // ¬ C.val.card ≤ J} -noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype (LongCycle p S J) := Fintype.ofFinite _ - -lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - Fintype.card (SelectedCycle p S) = - Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by - classical - rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] - -lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : - J * Fintype.card (LongCycle p S J) ≤ S.card := by - classical - have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) - (fun C : SelectedCycle p S => C.val.card) - rw [Fintype.sum_sum_type] at hs - have h0 : J * Fintype.card (LongCycle p S J) ≤ - ∑ C : LongCycle p S J, C.val.val.card := by - calc - _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] - _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) - have hh := cycleMass_le p S - unfold cycleMass at hh - rw [←hs] at hh - exact h0.trans ((Nat.le_add_left _ _).trans hh) - -lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) - (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : - q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by - have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq - have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by - apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr - have hh := longCycle_card_bound p S J - exact_mod_cast (by simpa only [mul_comm] using hh) - calc - _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by - rw [Real.exp_nat_mul,Real.exp_log hq0] - _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) - -lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) - (q : ℝ) (hq : 1 ≤ q) : - Real.log (finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ - (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) - let c : ℝ := (S.card : ℝ)/J * Real.log q - have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by - have hsum := sum_inv_sqrt J - have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity - have h0 : 0 ≤ 2*Real.sqrt J := by positivity - have hh := mul_le_mul_of_nonneg_left hsum hp - have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq - calc - _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_left hh hq1 - _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := - mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) - _ = _ := by ring - have hm : finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ - Real.exp (c+(q-1)*lam) := by - calc - _ ≤ finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by - apply finiteMean_mono - intro ω - rw [selectedCycle_card_split _ _ J,pow_add] - exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) - _ = finiteMean (fun ω : ι → Bool => - q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := - finiteMean_mul_const _ _ - _ ≤ Real.exp ((q-1)*lam) * Real.exp c := - mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) - _ = _ := by rw [←Real.exp_add,add_comm] - have hpos : 0 < finiteMean (fun ω : ι → Bool => - q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by - apply finiteMean_pos - intro ω - positivity - have hlog := Real.log_le_log hpos hm - rw [Real.log_exp] at hlog - dsimp [c] at hlog - linarith - - -end RoutingNetwork - -variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} - -def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where - toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) - invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) - left_inv x := by simp - right_inv y := by simp - -def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) - (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := - (pre.trans (parallelPerm ω)).trans post - -noncomputable def parallelPath (pre : α ≃ B × Card d) - (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := - (routeDomain d (pre x).2 - (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image - (fun i => ((pre x).1,i)) - -def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : α × α := - let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 - (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) - -omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in -lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by - intro h - exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) - (x : α) (i : B × SwitchIndex d) : - i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by - classical - obtain ⟨b,j⟩ := i - simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] - constructor - · rintro ⟨k,hk,hb,rfl⟩ - subst b - rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h - · left - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · right - apply pre.injective - change pre (pre.symm ((pre x).1,_)) = pre x - rw [Equiv.apply_symm_apply] - exact Prod.ext rfl h - · intro h - have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ - (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by - rcases h with h | h - · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) - have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) - subst b - refine ⟨j,?_,rfl,rfl⟩ - apply (mem_routeDomain_iff_user d _ _ _).mpr - exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) - -omit [Fintype α] [DecidableEq α] [Fintype B] in -lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : - (parallelPath pre ω x).card = d := by - classical - rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] - -noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := - Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) - -omit [Fintype α] [Fintype B] [DecidableEq B] in -@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : - x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by - classical - simp [blockMarks] - -omit [DecidableEq B] in -lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : - ∑ b : B, (blockMarks pre S b).card = S.card := by - classical - calc - _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by - simp only [blockMarks,Finset.card_filter] - _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm - _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) - _ = _ := by simp - -omit [DecidableEq B] in -lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : - (blockMarks pre S b).card ≤ S.card := by - rw [←sum_card_blockMarks pre S] - exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.AssignmentSlots + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter +namespace RoutingNetwork +variable {α ι : Type*} [Fintype α] [DecidableEq α] [Fintype ι] [DecidableEq ι] + {d : ℕ} (R : RoutingNetwork α ι d) +lemma mem_exposedPaths (b : ι → Bool) (V : Finset (α)) (s : ι) : + s ∈ exposedPaths R b V ↔ (R.users b s).1 ∈ V ∨ (R.users b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,R.mem_path] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (b : ι → Bool) (z : α) (V : Finset (α)) + (hz : z ∉ V) : + (terminalCharge R b z V : ℝ) = ∑ s : ι, + ((if (R.users b s).1 = z ∧ (R.users b s).2 ∈ V then (1:ℝ) else 0) + + (if (R.users b s).2 = z ∧ (R.users b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : R.path b z ∩ exposedPaths R b V = + Finset.univ.filter (fun s => + ((R.users b s).1 = z ∧ (R.users b s).2 ∈ V) ∨ + ((R.users b s).2 = z ∧ (R.users b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,R.mem_path,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (R.users b s).1 = z <;> + by_cases h₂ : (R.users b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) : Finset (α) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +omit [DecidableEq α] in +@[simp] lemma mem_priorPaths {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (x : α) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) (i : Fin A) : + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : ι, + ((if (z i).val = (R.users b s).1 ∧ (R.users b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (R.users b s).2 ∧ (R.users b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := R.users_ne b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (R.users b s).1 <;> + by_cases h₂ : (z i).val = (R.users b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {A : ℕ} (o : α → Option (Fin A)) + (z : Terminal o) (u v : α) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : α) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : α) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : α) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {A : ℕ} (o : α → Option (Fin A)) + (b : ι → Bool) (z : Terminal o) : + rotationCharge R o b z = ∑ i : Fin A, + (terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +omit [DecidableEq α] in +@[simp] lemma priorPaths_zero {A : ℕ} (o : α → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {A : ℕ} (o : α → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +omit [DecidableEq α] in +lemma priorPaths_disjoint {A : ℕ} (o : α → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree +open Thorp.QueryTree + +lemma seekCycles_owned {A : ℕ} (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) (z : Terminal o) (ω : ι → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (R.perm ω) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := R.perm ω + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles R S L ∅).succeeds ω = true ∧ + ((seekCycles R S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge R o (ω) z := by + classical + let b := ω + let p := R.perm b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge R b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles R S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths R b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,Thorp.QueryTree.succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit R S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles R S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum R o b z).symm⟩ + +end QueryTree +section Collections +variable {A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) + (o : α → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {o : α → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : α // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +omit [DecidableEq α] in +lemma owner_ext {o o' : α → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma rooted_weight_sum_le (S : Finset (α)) (r : Fin A → ℕ) (ω : ι → Bool) : + (∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := R.perm ω + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned R S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles R S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +lemma collection_rotation_lower (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : ι → Bool) (c : CycleSlots (R.perm ω) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := by + classical + let (i : Fin A) : Nonempty {x : α // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound R hm (ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : ι → Bool) : ℝ := + if (QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles R S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : ι → Bool) : + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (R.perm ω) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (R.perm ω) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.val (ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower R S r hr ω c) + _ = ∑ c : RootedSlots (R.perm ω) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (R.perm ω) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge R c.1.val (ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le R S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success R S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment R S r hr) + +lemma butterfly_cycleSlots_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment R S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +section CycleCounting +variable {A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (α)) (S : Finset (α)) := + {C : Finset (α) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (α)} {S : Finset (α)} + (C : SelectedCycle p S) {x : α} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (α)} {S : Finset (α)} + (C D : SelectedCycle p S) {x : α} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +lemma assignmentOwner_eq_some {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : α) (i : Fin A) : + assignmentOwner f x = some i ↔ x ∈ (f.val i).val := by + classical + unfold assignmentOwner + split_ifs with h + · constructor + · intro hi + have hx := Classical.choose_spec h + rw [Option.some.inj hi] at hx + exact hx + · intro hx + have he := (f.val (Classical.choose h)).eq_of_mem (f.val i) (Classical.choose_spec h) hx + exact congrArg some (f.property.1 he) + · constructor + · intro hi; contradiction + · intro hx; exact (h ⟨i,hx⟩).elim + +lemma assignmentOwner_fiber {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (i : Fin A) : cycleFiber (assignmentOwner f) i = (f.val i).val := by + ext x + simp only [mem_cycleFiber,assignmentOwner_eq_some] + +noncomputable def assignmentToSlots {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : CycleSlots p S r := + ⟨assignmentOwner f,by + refine ⟨?_,?_,?_⟩ + · intro i + rw [assignmentOwner_fiber] + exact f.property.2 i + · intro i + rw [assignmentOwner_fiber] + exact (f.val i).property.2 + · intro i x hx + rw [assignmentOwner_fiber] + exact (f.val i).orbit_eq ((assignmentOwner_eq_some f x i).mp hx)⟩ + +noncomputable def cycleSlotsEquivAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + CycleSlots p S r ≃ SlotAssignment p S r where + toFun := slotsToAssignment + invFun := assignmentToSlots + left_inv c := by + apply Subtype.ext + apply owner_ext + intro i + rw [assignmentToSlots,assignmentOwner_fiber] + rfl + right_inv f := by + apply Subtype.ext + funext i + apply Subtype.ext + exact assignmentOwner_fiber f i + +end CycleCounting + +section GroupedCounting +variable {A : ℕ} + +abbrev LengthClass (r : Fin A → ℕ) := {j : ℕ // j ∈ Finset.univ.image (fun i => r i + 1)} + +def slotClass (r : Fin A → ℕ) (i : Fin A) : LengthClass r := + ⟨r i+1, Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩⟩ + +abbrev SlotsOfLength (r : Fin A → ℕ) (j : LengthClass r) := {i : Fin A // slotClass r i = j} +abbrev CyclesOfLength (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) := + {C : SelectedCycle p S // C.val.card = j} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (j : ℕ) : + Fintype (CyclesOfLength p S j) := Fintype.ofFinite _ + +abbrev GroupedAssignments (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) := + ∀ j : LengthClass r, SlotsOfLength r j ↪ CyclesOfLength p S j.val + +noncomputable def assignmentToGroups {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) : GroupedAssignments p S r := fun _j => + { toFun := fun i => ⟨f.val i.val, (f.property.2 i.val).trans (congrArg Subtype.val i.property)⟩ + inj' := fun _i _k h => Subtype.ext (f.property.1 (congrArg Subtype.val h)) } + +noncomputable def groupsEmbedding {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : Fin A ↪ SelectedCycle p S := + ((Equiv.sigmaFiberEquiv (slotClass r)).symm.toEmbedding.trans + (Function.Embedding.sigmaMap (Function.Embedding.refl _) F)).trans + ((Function.Embedding.sigmaMap (Function.Embedding.subtype _) (fun _ => Function.Embedding.refl _)).trans + (Equiv.sigmaFiberEquiv (fun C : SelectedCycle p S => C.val.card)).toEmbedding) + +noncomputable def groupsToAssignment {p : Equiv.Perm (α)} {S : Finset (α)} {r : Fin A → ℕ} + (F : GroupedAssignments p S r) : SlotAssignment p S r := + ⟨groupsEmbedding F, (groupsEmbedding F).injective, + fun i => (F (slotClass r i) ⟨i,rfl⟩).property⟩ + +noncomputable def assignmentEquivGroups (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + SlotAssignment p S r ≃ GroupedAssignments p S r where + toFun := assignmentToGroups + invFun := groupsToAssignment + left_inv f := by + apply Subtype.ext + rfl + right_inv F := by + funext j + apply Function.Embedding.ext + intro i + rcases i with ⟨i,hi⟩ + subst j + rfl + +lemma card_cycleSlots_factorial (p : Equiv.Perm (α)) (S : Finset (α)) (r : Fin A → ℕ) : + Fintype.card (CycleSlots p S r) = + ∏ j : LengthClass r, (Fintype.card (CyclesOfLength p S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) := by + classical + rw [Fintype.card_congr (cycleSlotsEquivAssignments p S r), + Fintype.card_congr (assignmentEquivGroups p S r), Fintype.card_pi] + simp only [Fintype.card_embedding_eq] + +lemma butterfly_factorial_moment (S : Finset (α)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : ι → Bool => + (∏ j : LengthClass r, + (Fintype.card (CyclesOfLength (R.perm ω) S j.val)).descFactorial + (Fintype.card (SlotsOfLength r j)) : ℕ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + simpa only [←card_cycleSlots_factorial] using butterfly_cycleSlots_moment R S r hr + +end GroupedCounting + +section AllLengths +variable {A : ℕ} + +noncomputable def assignmentRelabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + SlotAssignment p S r ≃ SlotAssignment p S (r ∘ e) where + toFun f := ⟨f.val ∘ e, f.property.1.comp e.injective, fun i => f.property.2 (e i)⟩ + invFun f := ⟨f.val ∘ e.symm, f.property.1.comp e.symm.injective, fun i => by + simpa only [Function.comp_apply,Equiv.apply_symm_apply] using f.property.2 (e.symm i)⟩ + left_inv f := by apply Subtype.ext; funext i; simp + right_inv f := by apply Subtype.ext; funext i; simp + +lemma card_cycleSlots_relabel (p : Equiv.Perm (α)) (S : Finset (α)) + (r : Fin A → ℕ) (e : Equiv.Perm (Fin A)) : + Fintype.card (CycleSlots p S r) = Fintype.card (CycleSlots p S (r ∘ e)) := by + exact Fintype.card_congr ((cycleSlotsEquivAssignments p S r).trans + ((assignmentRelabel p S r e).trans (cycleSlotsEquivAssignments p S (r ∘ e)).symm)) + +lemma butterfly_cycleSlots_moment_all (S : Finset (α)) (r : Fin A → ℕ) : + finiteMean (fun ω : ι → Bool => + (Fintype.card (CycleSlots (R.perm ω) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := butterfly_cycleSlots_moment R S (r ∘ Tuple.sort r) (Tuple.monotone_sort r) + simp_rw [←card_cycleSlots_relabel] at h + have hp := Equiv.prod_comp (Tuple.sort r) (fun i : Fin A => (1 / Real.sqrt (r i+1) : ℝ)) + simpa only [Function.comp_apply,hp] using h + +abbrev ShortCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // C.val.card ≤ J} + +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (ShortCycle p S J) := Fintype.ofFinite _ + +noncomputable def shortCycleLength {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : Fin J := + ⟨C.val.val.card-1, by have := C.val.nonempty.card_pos; have := C.property; omega⟩ + +lemma shortCycleLength_add_one {p : Equiv.Perm (α)} {S : Finset (α)} {J : ℕ} + (C : ShortCycle p S J) : (shortCycleLength C : ℕ)+1 = C.val.val.card := by + have := C.val.nonempty.card_pos + simp only [shortCycleLength] + omega + +noncomputable def shortEmbeddingEquiv (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fin A ↪ ShortCycle p S J) ≃ + Σ r : Fin A → Fin J, SlotAssignment p S (fun i => (r i : ℕ)) where + toFun f := ⟨fun i => shortCycleLength (f i), + ⟨fun i => (f i).val, fun i j h => f.injective (Subtype.ext h), + fun i => (shortCycleLength_add_one (f i)).symm⟩⟩ + invFun c := + { toFun := fun i => ⟨c.2.val i, by rw [c.2.property.2]; exact (c.1 i).isLt⟩ + inj' := fun _i _j h => c.2.property.1 (congrArg Subtype.val h) } + left_inv f := by + apply Function.Embedding.ext + intro i + rfl + right_inv c := by + rcases c with ⟨r,f⟩ + have he : (fun i => shortCycleLength (⟨f.val i, by rw [f.property.2]; exact (r i).isLt⟩ : ShortCycle p S J)) = r := by + funext i + apply Fin.ext + simp only [shortCycleLength,f.property.2,Nat.add_sub_cancel] + apply Sigma.ext he + apply (Subtype.heq_iff_coe_eq (by + intro x + change (Function.Injective x ∧ ∀ i, (x i).val.card = (f.val i).val.card - 1 + 1) ↔ _ + simp only [f.property.2,Nat.add_sub_cancel])).mpr + rfl + +lemma shortCycle_factorial_eq (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + (Fintype.card (ShortCycle p S J)).descFactorial A = + ∑ r : Fin A → Fin J, Fintype.card (CycleSlots p S (fun i => (r i : ℕ))) := by + classical + have hc := Fintype.card_embedding_eq (α := Fin A) (β := ShortCycle p S J) + simp only [Fintype.card_fin] at hc + rw [←hc, Fintype.card_congr (shortEmbeddingEquiv p S J),Fintype.card_sigma] + apply Finset.sum_congr rfl + intro r _ + exact (Fintype.card_congr (cycleSlotsEquivAssignments p S (fun i => (r i : ℕ)))).symm + +end AllLengths + +section CycleMGF + +lemma butterfly_shortCycle_moment (S : Finset (α)) (J A : ℕ) : + finiteMean (fun ω : ι → Bool => + ((Fintype.card (ShortCycle (R.perm ω) S J)).descFactorial A : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))^A := by + classical + simp_rw [shortCycle_factorial_eq,Nat.cast_sum,finiteMean_sum] + calc + _ ≤ ∑ r : Fin A → Fin J, + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt ((r i : ℕ)+1)) := by + apply Finset.sum_le_sum + intro r _ + exact butterfly_cycleSlots_moment_all R S (fun i => (r i : ℕ)) + _ = _ := by + rw [←Finset.mul_sum,mul_pow] + congr 1 + rw [←Fintype.prod_sum (fun (_ : Fin A) (j : Fin J) => (1 / Real.sqrt ((j:ℕ)+1) : ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +noncomputable def cycleMass (p : Equiv.Perm (α)) (S : Finset (α)) : ℕ := + ∑ C : SelectedCycle p S, C.val.card + +lemma cycleMass_le (p : Equiv.Perm (α)) (S : Finset (α)) : cycleMass p S ≤ S.card := by + classical + let f : (Σ C : SelectedCycle p S, {x : α // x ∈ C.val}) → S := + fun c => ⟨c.2.val,c.1.property.2 c.2.property⟩ + have hi : Function.Injective f := by + intro c e h + have hx : c.2.val = e.2.val := congrArg Subtype.val h + have hC : c.1 = e.1 := c.1.eq_of_mem e.1 c.2.property (hx ▸ e.2.property) + rcases c with ⟨c,x⟩ + rcases e with ⟨e,y⟩ + dsimp only at hC + subst e + have he : x=y := Subtype.ext hx + cases he + rfl + have hh := Fintype.card_le_of_injective f hi + simpa only [Fintype.card_sigma,Fintype.card_coe,cycleMass] using hh + +lemma shortCycle_card_le (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (ShortCycle p S J) ≤ S.card := by + classical + calc + _ ≤ Fintype.card (SelectedCycle p S) := Fintype.card_subtype_le _ + _ = ∑ _ : SelectedCycle p S, 1 := by simp + _ ≤ cycleMass p S := Finset.sum_le_sum (fun C _ => C.nonempty.card_pos) + _ ≤ _ := cycleMass_le p S + +lemma butterfly_shortCycle_mgf (S : Finset (α)) (J : ℕ) (q : ℝ) (hq : 1 ≤ q) : + finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) ≤ + Real.exp ((q-1)*((S.card : ℝ) / Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1))) := by + apply factorial_mgf _ S.card _ q (fun ω => shortCycle_card_le _ _ _) + · positivity + · exact hq + · exact butterfly_shortCycle_moment R S J + +end CycleMGF + + +abbrev LongCycle (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) := + {C : SelectedCycle p S // ¬ C.val.card ≤ J} +noncomputable instance (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype (LongCycle p S J) := Fintype.ofFinite _ + +lemma selectedCycle_card_split (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + Fintype.card (SelectedCycle p S) = + Fintype.card (ShortCycle p S J) + Fintype.card (LongCycle p S J) := by + classical + rw [←Fintype.card_congr (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)),Fintype.card_sum] + +lemma longCycle_card_bound (p : Equiv.Perm (α)) (S : Finset (α)) (J : ℕ) : + J * Fintype.card (LongCycle p S J) ≤ S.card := by + classical + have hs := Equiv.sum_comp (Equiv.sumCompl (fun C : SelectedCycle p S => C.val.card ≤ J)) + (fun C : SelectedCycle p S => C.val.card) + rw [Fintype.sum_sum_type] at hs + have h0 : J * Fintype.card (LongCycle p S J) ≤ + ∑ C : LongCycle p S J, C.val.val.card := by + calc + _ = ∑ _C : LongCycle p S J, J := by simp [mul_comm] + _ ≤ _ := Finset.sum_le_sum (fun C _ => Nat.le_of_lt (Nat.lt_of_not_ge C.property)) + have hh := cycleMass_le p S + unfold cycleMass at hh + rw [←hs] at hh + exact h0.trans ((Nat.le_add_left _ _).trans hh) + +lemma longCycle_pow_bound (p : Equiv.Perm (α)) (S : Finset (α)) + (J : ℕ) (hJ : 0 < J) (q : ℝ) (hq : 1 ≤ q) : + q^(Fintype.card (LongCycle p S J)) ≤ Real.exp ((S.card : ℝ)/J * Real.log q) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hc : (Fintype.card (LongCycle p S J) : ℝ) ≤ (S.card : ℝ)/J := by + apply (le_div_iff₀ (by exact_mod_cast hJ)).mpr + have hh := longCycle_card_bound p S J + exact_mod_cast (by simpa only [mul_comm] using hh) + calc + _ = Real.exp ((Fintype.card (LongCycle p S J) : ℝ)*Real.log q) := by + rw [Real.exp_nat_mul,Real.exp_log hq0] + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (Real.log_nonneg hq)) + +lemma butterfly_cycle_log_mgf (S : Finset (α)) (J : ℕ) (hJ : 0 < J) + (q : ℝ) (hq : 1 ≤ q) : + Real.log (finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S)))) ≤ + (S.card : ℝ)/J * Real.log q + 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + let lam : ℝ := (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) * ∑ j : Fin J, 1 / Real.sqrt ((j:ℕ)+1) + let c : ℝ := (S.card : ℝ)/J * Real.log q + have hnum : (q-1)*lam ≤ 2*q*S.card*Real.sqrt J / Real.sqrt ((2:ℝ)^d) := by + have hsum := sum_inv_sqrt J + have hp : 0 ≤ (S.card : ℝ)/Real.sqrt ((2:ℝ)^d) := by positivity + have h0 : 0 ≤ 2*Real.sqrt J := by positivity + have hh := mul_le_mul_of_nonneg_left hsum hp + have hq1 : 0 ≤ q-1 := sub_nonneg.mpr hq + calc + _ ≤ (q-1)*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_left hh hq1 + _ ≤ q*((S.card : ℝ)/Real.sqrt ((2:ℝ)^d)*(2*Real.sqrt J)) := + mul_le_mul_of_nonneg_right (by linarith) (mul_nonneg hp h0) + _ = _ := by ring + have hm : finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) ≤ + Real.exp (c+(q-1)*lam) := by + calc + _ ≤ finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))*Real.exp c) := by + apply finiteMean_mono + intro ω + rw [selectedCycle_card_split _ _ J,pow_add] + exact mul_le_mul_of_nonneg_left (longCycle_pow_bound _ S J hJ q hq) (by positivity) + _ = finiteMean (fun ω : ι → Bool => + q^(Fintype.card (ShortCycle (R.perm ω) S J))) * Real.exp c := + finiteMean_mul_const _ _ + _ ≤ Real.exp ((q-1)*lam) * Real.exp c := + mul_le_mul_of_nonneg_right (butterfly_shortCycle_mgf R S J q hq) (Real.exp_nonneg _) + _ = _ := by rw [←Real.exp_add,add_comm] + have hpos : 0 < finiteMean (fun ω : ι → Bool => + q^(Fintype.card (SelectedCycle (R.perm ω) S))) := by + apply finiteMean_pos + intro ω + positivity + have hlog := Real.log_le_log hpos hm + rw [Real.log_exp] at hlog + dsimp [c] at hlog + linarith + + +end RoutingNetwork + +variable {α B : Type*} [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] {d : ℕ} + +def parallelPerm (ω : B × SwitchIndex d → Bool) : Equiv.Perm (B × Card d) where + toFun x := (x.1,butterflyPerm d (decodeButterfly d (fun i => ω (x.1,i))) x.2) + invFun y := (y.1,(butterflyPerm d (decodeButterfly d (fun i => ω (y.1,i)))).symm y.2) + left_inv x := by simp + right_inv y := by simp + +def relabeledPerm (pre : α ≃ B × Card d) (post : B × Card d ≃ α) + (ω : B × SwitchIndex d → Bool) : Equiv.Perm α := + (pre.trans (parallelPerm ω)).trans post + +noncomputable def parallelPath (pre : α ≃ B × Card d) + (ω : B × SwitchIndex d → Bool) (x : α) : Finset (B × SwitchIndex d) := + (routeDomain d (pre x).2 + (butterflyPerm d (decodeButterfly d (fun i => ω ((pre x).1,i))) (pre x).2)).image + (fun i => ((pre x).1,i)) + +def parallelUsers (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : α × α := + let u := switchUsers d (decodeButterfly d (fun j => ω (i.1,j))) i.2 + (pre.symm (i.1,u.1),pre.symm (i.1,u.2)) + +omit [Fintype α] [DecidableEq α] [Fintype B] [DecidableEq B] in +lemma parallelUsers_ne (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (i : B × SwitchIndex d) : (parallelUsers pre ω i).1 ≠ (parallelUsers pre ω i).2 := by + intro h + exact switchUsers_ne d _ _ (congrArg Prod.snd (pre.symm.injective h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma mem_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) + (x : α) (i : B × SwitchIndex d) : + i ∈ parallelPath pre ω x ↔ (parallelUsers pre ω i).1 = x ∨ (parallelUsers pre ω i).2 = x := by + classical + obtain ⟨b,j⟩ := i + simp only [parallelPath,Finset.mem_image,Prod.mk.injEq] + constructor + · rintro ⟨k,hk,hb,rfl⟩ + subst b + rcases (mem_routeDomain_iff_user d _ _ _).mp hk with h | h + · left + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · right + apply pre.injective + change pre (pre.symm ((pre x).1,_)) = pre x + rw [Equiv.apply_symm_apply] + exact Prod.ext rfl h + · intro h + have hh : (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).1) = pre x ∨ + (b,(switchUsers d (decodeButterfly d (fun j => ω (b,j))) j).2) = pre x := by + rcases h with h | h + · exact Or.inl (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + · exact Or.inr (by simpa only [parallelUsers,Equiv.apply_symm_apply] using congrArg pre h) + have hb : b = (pre x).1 := hh.elim (congrArg Prod.fst) (congrArg Prod.fst) + subst b + refine ⟨j,?_,rfl,rfl⟩ + apply (mem_routeDomain_iff_user d _ _ _).mpr + exact hh.elim (fun h => Or.inl (congrArg Prod.snd h)) (fun h => Or.inr (congrArg Prod.snd h)) + +omit [Fintype α] [DecidableEq α] [Fintype B] in +lemma card_parallelPath (pre : α ≃ B × Card d) (ω : B × SwitchIndex d → Bool) (x : α) : + (parallelPath pre ω x).card = d := by + classical + rw [parallelPath,Finset.card_image_of_injective _ (fun _ _ h => Prod.mk.inj h |>.2),card_routeDomain] + +noncomputable def blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) : Finset (Card d) := + Finset.univ.filter (fun x => pre.symm (b,x) ∈ S) + +omit [Fintype α] [Fintype B] [DecidableEq B] in +@[simp] lemma mem_blockMarks (pre : α ≃ B × Card d) (S : Finset α) (b : B) (x : Card d) : + x ∈ blockMarks pre S b ↔ pre.symm (b,x) ∈ S := by + classical + simp [blockMarks] + +omit [DecidableEq B] in +lemma sum_card_blockMarks (pre : α ≃ B × Card d) (S : Finset α) : + ∑ b : B, (blockMarks pre S b).card = S.card := by + classical + calc + _ = ∑ b : B, ∑ x : Card d, if pre.symm (b,x) ∈ S then 1 else 0 := by + simp only [blockMarks,Finset.card_filter] + _ = ∑ u : B × Card d, if pre.symm u ∈ S then 1 else 0 := (Fintype.sum_prod_type (fun u : B × Card d => if pre.symm u ∈ S then (1:ℕ) else 0)).symm + _ = ∑ x : α, if x ∈ S then 1 else 0 := Equiv.sum_comp pre.symm (fun x : α => if x ∈ S then (1:ℕ) else 0) + _ = _ := by simp + +omit [DecidableEq B] in +lemma card_blockMarks_le (pre : α ≃ B × Card d) (S : Finset α) (b : B) : + (blockMarks pre S b).card ≤ S.card := by + rw [←sum_card_blockMarks pre S] + exact Finset.single_le_sum (f := fun b : B => (blockMarks pre S b).card) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/Representative.lean b/lean/OAI/Probability/ThorpRouting/Tail/Representative.lean index 6bef312e9bd6b4a09ae9c810e06e97c0dc59a898..c83efd8041159acf3daf609ae2cd01dab4773ad7 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/Representative.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/Representative.lean @@ -1,893 +1,893 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ShapePartitionEquiv - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] -omit [FiniteDimensional ℂ V] in -lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : - LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = - (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by - change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ - rw [map_sum] - have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by - rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] - simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - -lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (A : Module.End ℂ V) : - ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ - c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by - obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) - have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by - rw [←hc] - rfl - refine ⟨c,he,?_⟩ - rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] - -theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (u v w z : V) : - (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = - (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by - obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap - rw [InnerProductSpace.trace_rankOne] at htrace - have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc - change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ - simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ - have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by - simpa only [mul_comm] using happ - rw [hsum] - calc - _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring - _ = _ := by rw [htrace] - -end Thorp.UnitaryFinite -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X : Type*} [Group G] [Fintype G] [Fintype X] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) - -noncomputable def representative (x : X) : G := Classical.choose (ha x) - -omit [Fintype G] [Fintype X] in -lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := - Classical.choose_spec (ha x) - -include ha in -lemma orbit_sum (F : X → ℂ) : - (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by - have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by - obtain ⟨t,rfl⟩ := ha x - symm - apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) - intro g - simp - calc - _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm - _ = ∑ g : G, ∑ x : X, F x := by - apply Finset.sum_congr rfl - intro g _ - exact Equiv.sum_comp (a g) F - _ = _ := by simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) - -def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w - -noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : - coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by - let r := representative a x₀ ha (a g x₀) - have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ - have hs : a (g⁻¹*r) x₀=x₀ := by - simp only [map_mul,Equiv.Perm.mul_apply] - rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] - rfl - have he := congrArg (ρ g) (hw (g⁻¹*r) hs) - have hh : ρ r w=ρ g w := by - simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, - mul_inv_cancel_left] using he - change inner ℂ (ρ r w) v= _ - rw [hh] - -lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = - (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by - have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) - simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs - simp only [←starRingEnd_apply,inner_conj_symm] at hs - simp only [starRingEnd_apply] at hs - have ho := coefficient_orthogonality ρ hρ v w z t - have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - apply mul_left_cancel₀ hcard - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,starRingEnd_apply] - have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = - ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by - apply Finset.sum_congr rfl - intro x _ - ring - rw [hsum] - calc - _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, - star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring - _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, - inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring - _ = _ := by rw [ho]; ring - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) - (v : V) (g : G) (x : X) : - coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by - obtain ⟨r,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, - coefficient_at a x₀ ha ρ w hw] - simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] - -noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := - (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v - -lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = - inner ℂ z w*inner ℂ v t := by - let : Nonempty X := ⟨x₀⟩ - have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = - (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by - rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] - simp - simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] - simp only [Complex.conj_ofReal] - rw [←mul_assoc,←pow_two,hs] - have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t - field_simp - simpa only [mul_assoc] using hi - -lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) - (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : - Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by - rw [orthonormal_iff_ite] at hw ⊢ - intro i j - rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, - inner_self_eq_norm_sq_to_K,hv] - simp [eq_comm] - -lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : - ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by - have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v - rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he - simp only [inner_self_eq_norm_sq_to_K] at he - norm_num at he - have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he - nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] - -end Thorp.UnitaryFinite - -namespace Thorp.FiniteConvolution -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) -noncomputable def power (p : G → ℝ) : ℕ → G → ℝ - | 0 => fun g => if g=1 then 1 else 0 - | n+1 => conv p (power p n) - -lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : - ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) - -lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) - {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by - apply lt_of_lt_of_le (mul_pos ha hb) - have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) - (Finset.mem_univ a) - simpa [conv] using h - -lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by - unfold conv - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [←Finset.mul_sum] - congr 1 - exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) - -lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by - intro n - induction n with - | zero => intro g; simp only [power]; split_ifs <;> norm_num - | succ n ih => exact conv_nonneg hp ih - -lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by - intro n - induction n with - | zero => simp [power] - | succ n ih => rw [power,sum_conv,hp,ih,one_mul] - -lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) - (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by - induction l with - | nil => simp [power] - | cons a l ih => - simpa only [List.length_cons,List.prod_cons,power] using - conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) - (ih (fun g hg => hl g (by simp [hg]))) - -lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by - induction m, hnm using Nat.le_induction with - | base => exact hg - | succ m _ ih => - simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih - -theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - (hgen : Subgroup.closure {g | 0 < p g}=⊤) : - ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by - have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by - rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] - trivial - choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) - let n := Finset.univ.sup (fun g => (l g).length) - refine ⟨n,fun g => ?_⟩ - have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) - have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) - have hpos := power_list_pos hp (l g) (hl g) - rw [hprod g] at hpos - exact power_pos_mono hp h1 (hlen.trans hpow) hpos - -structure Minorant (p : G → ℝ) where - exponent : ℕ - mass : ℝ - mass_pos : 0 < mass - mass_le_one : mass ≤ 1 - lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g - -noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) - (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by - let n := Classical.choose (exists_positive_power hp h1 hgen) - have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) - let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) - have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) - have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) - have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos - have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' - refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ - have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp - rw [he] - exact hag g - -end Thorp.FiniteConvolution -namespace Thorp.UnitaryFinite - -section -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : - continuousRepresentation ρ g v=ρ g v := rfl - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : - ‖ρ g v‖=‖v‖ := by - rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] - -omit [Fintype G] in -lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - ‖continuousRepresentation ρ g‖≤1 := by - apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one - intro v - simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] - -omit [Fintype G] in -lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by - ext w - apply ext_inner_left ℂ - intro v - rw [ContinuousLinearMap.adjoint_inner_right] - exact (unitary_inner_inv ρ hρ g v w).symm - -noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := - ∑ g, (p g : ℂ) • continuousRepresentation ρ g - -lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro g _ - rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] - exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) - -lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by - change (weightedOperator ρ p).adjoint=weightedOperator ρ p - unfold weightedOperator - rw [map_sum] - simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] - apply Fintype.sum_equiv (Equiv.inv G) - intro g - simp [hp] - -noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := - weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) - -lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) - -lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : - continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,←map_mul] - exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) - -lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : - uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,←map_mul] - exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) - -lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : - IsIdempotentElem (uniformOperator ρ) := by - change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ - nth_rw 1 [uniformOperator,weightedOperator] - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, - ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] - rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsStarProjection (uniformOperator ρ) := - ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ - -lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : - weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : - uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) - (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : - ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by - let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) - have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) - have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hsum : ∑ g,q g=1-ε := by - simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by - simp only [uniformOperator,weightedOperator] - rw [Finset.smul_sum,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro g _ - simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, - Complex.ofReal_inv,Complex.ofReal_natCast] - congr 1 - field_simp - ring - have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by - rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] - rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] - calc - _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ - _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) - ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) - (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) - _ = _ := mul_one _ - -end -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : - weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by - unfold weightedOperator FiniteConvolution.conv - simp only [Complex.ofReal_sum,Finset.sum_smul] - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [Finset.mul_sum] - simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp [Complex.ofReal_mul,mul_comm] - -lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : - weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by - induction n with - | zero => simp [FiniteConvolution.power,weightedOperator] - | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] - -lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) - (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : - (weightedOperator ρ p-uniformOperator ρ)^n= - (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by - have hAP := weighted_uniform_left ρ p - have hPA := weighted_uniform_right ρ p - rw [hp,one_smul] at hAP hPA - have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by - show _*_= _*_ - rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] - have he : weightedOperator ρ p-uniformOperator ρ= - weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] - rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] - -noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := - 1-c.mass/(2*(2:ℝ)^c.exponent) - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - unfold minorantGap - linarith - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by - unfold minorantGap - exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) - -theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) - (c : FiniteConvolution.Minorant p) : - ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by - have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) - have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) - (FiniteConvolution.sum_power hp _) c.mass c.lower - rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), - hself.norm_pow_two_pow] at hbound - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - have hbern := one_add_mul_le_pow - (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) - (2^c.exponent) - have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by - push_cast - field_simp - ring - rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern - by_contra h - have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h - have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) - linarith [c.mass_pos] - -end Thorp.UnitaryFinite -namespace Thorp -open scoped BigOperators Classical - -def butterflyIdentity : (d : ℕ) → Butterfly d - | 0 => () - | d+1 => (fun _ => false,fun _ => butterflyIdentity d) - -lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by - apply Equiv.ext - intro x - change switchFun (fun _ => false) x=x - simp [switchFun] - -lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by - ext x i - simp [childLift] - -lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by - induction d with - | zero => rfl - | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] - -noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where - toFun p := childLift (fun c => if c=b then p else 1) - map_one' := by simpa only [ite_self] using childLift_one d - map_mul' p q := by - rw [childLift_mul] - congr 1 - funext c - split_ifs <;> simp - -lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : - childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ - by_cases hc : c=b - · subst c - simp only [↓reduceIte] - rw [Equiv.swap_apply_def] - split_ifs with h₁ h₂ - · subst w; simp - · subst w; simp - · rw [Equiv.swap_apply_of_ne_of_ne] - · exact fun h => h₁ (by simpa using congrArg Fin.tail h) - · exact fun h => h₂ (by simpa using congrArg Fin.tail h) - · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) - -lemma pairSwitch_single (d : ℕ) (u : Card d) : - pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by - apply Equiv.ext - intro x - obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ - change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ - by_cases h : w=u - · subst w - cases c <;> simp [switchFun] - · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) - have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) - simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] - -theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) - (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by - induction d with - | zero => - apply top_unique - intro p _ - have hp : p=1 := Subsingleton.elim _ _ - rw [hp] - exact H.one_mem - | succ d ih => - have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by - have hc : H.comap (childInjection d b)=⊤ := by - apply ih - intro ω - change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H - have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) - simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h - have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial - exact hp - have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by - rw [←pairSwitch_single] - have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) - simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h - have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by - have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by - cases a <;> cases b - · rw [Equiv.swap_self]; exact H.one_mem - · exact hpair _ - · rw [Equiv.swap_comm]; exact hpair _ - · rw [Equiv.swap_self]; exact H.one_mem - have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by - convert ht (x 0) (y 0) (Fin.tail x) using 1 - rw [Fin.cons_self_tail] - have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) - rw [childInjection_swap,Fin.cons_self_tail] at h₂ - exact SubmonoidClass.swap_mem_trans H h₁ h₂ - rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] - rintro _ ⟨x,y,_,rfl⟩ - exact hswap x y - -lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := - butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) - -variable {Ω G : Type*} [Fintype Ω] [Fintype G] - -noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := - finiteMean (fun ω => if P ω=g then 1 else 0) - -omit [Fintype G] in -lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := - finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) - -lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by - unfold sampleLaw - rw [←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype G] in -lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : - 0 by split_ifs <;> norm_num)] - simp only [Finset.mem_univ,true_and] - apply exists_congr - intro ω - split_ifs <;> simp_all - -omit [Fintype G] in -lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : - sampleLaw (P ∘ e)=sampleLaw P := by - funext g - simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) - -variable [Group G] -omit [Fintype G] in -lemma sampleLaw_inverse (P : Ω → G) (g : G) : - sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by - apply finiteMean_congr - intro ω - rw [inv_eq_iff_eq_inv] - -omit [Fintype G] in -lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) - (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by - rw [←sampleLaw_inverse] - have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) - rw [hh,sampleLaw_equiv] - -end Thorp - -namespace Thorp -open scoped BigOperators Classical - -lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by - refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), - (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - exact mul_inv_cancel _ - -lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : - ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by - refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ - unfold palindromePerm - have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := - (butterflyCoinEquiv d).apply_symm_apply β - rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] - -lemma palindrome_support_generates (d : ℕ) : - Subgroup.closure {g | 0 P i v) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) - rw [hsplit] at hp - have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) - rw [hsplit] at ha - have he (i : ι) : P i (A v)=(A*P i) (P i v) := by - change (P i*A) v=(A*P i*P i) v - rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] - have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by - rw [he] - exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) - have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) - simp_rw [mul_pow] at hsq - rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq - exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq - -theorem sector_sandwich_le (T P A B : V →L[ℂ] V) - (hT : IsStarProjection T) (hP : IsStarProjection P) - (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : - ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by - have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by - change _=star (T*B)*A*(T*B) - rw [star_mul,hT.isSelfAdjoint.star_eq] - change _=B.adjoint*T*A*(T*B) - rw [mul_assoc B.adjoint T A,←hcomm.eq] - simp only [mul_assoc] - rw [←mul_assoc T T B,hT.isIdempotentElem.eq] - have hTB : ‖T*B‖≤‖P*B‖ := by - have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] - rw [he] - exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) - rw [he,projection_sandwich_norm P B hP] - calc - _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] - _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 - -omit [CompleteSpace V] [Fintype ι] in -lemma resolution_commute (P : ι → V →L[ℂ] V) - (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by - by_cases hij : i=j - · subst j; exact Commute.refl _ - · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm - -omit [Fintype ι] in -lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : - (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by - rw [Finset.sum_mul] - have he (i : ι) : P i*P j=if i=j then P j else 0 := by - split_ifs with h - · subst i; exact (hP j).isIdempotentElem.eq - · exact horth i j h - simp only [he,Finset.sum_ite_eq'] - -lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) - (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) - (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : - ‖A*(∑ i∈S,P i)‖≤c := by - apply resolution_norm_bound P hP horth hsum _ _ c hc - · intro i - rw [mul_assoc,resolution_sum_mul P hP horth] - split_ifs with hi - · exact hbound i hi - · simp [hc] - · intro i - exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) - -theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) - (hT : ∀ i, IsStarProjection (T i)) - (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) - (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) - (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) - (hA : ‖A‖≤1) (hB : ‖B‖≤1) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : - ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by - have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm - Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) - have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by - rw [Finset.sum_compl_add_sum,hsum] - have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ - ∑ i∈S,B.adjoint*A*T i*B := by - rw [←Finset.sum_mul,←Finset.mul_sum] - rw [←add_mul] - simp only [mul_assoc] - rw [←mul_add,←mul_add,hsplit] - simp only [mul_one,mul_assoc] - rw [he] - apply (norm_add_le _ _).trans - apply add_le_add - · calc - _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := - (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) - hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) - _ = c := by ring - · apply (norm_sum_le _ _).trans - exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA - -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) - -noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1-P i else P i - -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma choice_commute (E F : Finset ι) (i j : ι) : - Commute (choice P E i) (choice P F j) := by - unfold choice - split_ifs - · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) - · exact (Commute.one_left _).sub_left (hcomm i j) - · exact (Commute.one_right _).sub_right (hcomm i j) - · exact hcomm i j - -noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := - s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : - sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by - exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : - sector P hcomm s E=sector P hcomm s F := by - apply Finset.noncommProd_congr rfl - intro i hi - simp only [choice,h i hi] - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_factor_commute (s E F : Finset ι) (i : ι) : - Commute (choice P E i) (sector P hcomm s F) := - Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) - -omit [Fintype ι] in -lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : - IsStarProjection (sector P hcomm s E) := by - induction s using Finset.induction_on with - | empty => exact IsStarProjection.one _ - | @insert a s ha ih => - rw [sector_insert P hcomm s E a ha] - have hc : IsStarProjection (choice P E a) := by - unfold choice - split_ifs - · exact (hP a).one_sub - · exact hP a - exact hc.mul ih (sector_factor_commute P hcomm s E E a) - -end Thorp.CommutingBlocks - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ShapePartitionEquiv + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] +omit [FiniteDimensional ℂ V] in +lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : + LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = + (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by + change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ + rw [map_sum] + have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by + rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] + simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + +lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (A : Module.End ℂ V) : + ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ + c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by + obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) + have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by + rw [←hc] + rfl + refine ⟨c,he,?_⟩ + rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] + +theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (u v w z : V) : + (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = + (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by + obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap + rw [InnerProductSpace.trace_rankOne] at htrace + have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc + change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ + simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ + have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by + simpa only [mul_comm] using happ + rw [hsum] + calc + _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring + _ = _ := by rw [htrace] + +end Thorp.UnitaryFinite +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X : Type*} [Group G] [Fintype G] [Fintype X] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) + +noncomputable def representative (x : X) : G := Classical.choose (ha x) + +omit [Fintype G] [Fintype X] in +lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := + Classical.choose_spec (ha x) + +include ha in +lemma orbit_sum (F : X → ℂ) : + (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by + have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by + obtain ⟨t,rfl⟩ := ha x + symm + apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) + intro g + simp + calc + _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm + _ = ∑ g : G, ∑ x : X, F x := by + apply Finset.sum_congr rfl + intro g _ + exact Equiv.sum_comp (a g) F + _ = _ := by simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) + +def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w + +noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : + coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by + let r := representative a x₀ ha (a g x₀) + have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ + have hs : a (g⁻¹*r) x₀=x₀ := by + simp only [map_mul,Equiv.Perm.mul_apply] + rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] + rfl + have he := congrArg (ρ g) (hw (g⁻¹*r) hs) + have hh : ρ r w=ρ g w := by + simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, + mul_inv_cancel_left] using he + change inner ℂ (ρ r w) v= _ + rw [hh] + +lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = + (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by + have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) + simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs + simp only [←starRingEnd_apply,inner_conj_symm] at hs + simp only [starRingEnd_apply] at hs + have ho := coefficient_orthogonality ρ hρ v w z t + have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + apply mul_left_cancel₀ hcard + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,starRingEnd_apply] + have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = + ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by + apply Finset.sum_congr rfl + intro x _ + ring + rw [hsum] + calc + _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, + star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring + _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, + inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring + _ = _ := by rw [ho]; ring + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) + (v : V) (g : G) (x : X) : + coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by + obtain ⟨r,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, + coefficient_at a x₀ ha ρ w hw] + simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] + +noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := + (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v + +lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = + inner ℂ z w*inner ℂ v t := by + let : Nonempty X := ⟨x₀⟩ + have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = + (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by + rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] + simp + simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] + simp only [Complex.conj_ofReal] + rw [←mul_assoc,←pow_two,hs] + have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t + field_simp + simpa only [mul_assoc] using hi + +lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) + (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : + Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by + rw [orthonormal_iff_ite] at hw ⊢ + intro i j + rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, + inner_self_eq_norm_sq_to_K,hv] + simp [eq_comm] + +lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : + ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by + have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v + rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he + simp only [inner_self_eq_norm_sq_to_K] at he + norm_num at he + have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he + nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] + +end Thorp.UnitaryFinite + +namespace Thorp.FiniteConvolution +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) +noncomputable def power (p : G → ℝ) : ℕ → G → ℝ + | 0 => fun g => if g=1 then 1 else 0 + | n+1 => conv p (power p n) + +lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : + ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) + +lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) + {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by + apply lt_of_lt_of_le (mul_pos ha hb) + have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) + (Finset.mem_univ a) + simpa [conv] using h + +lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by + unfold conv + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [←Finset.mul_sum] + congr 1 + exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) + +lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by + intro n + induction n with + | zero => intro g; simp only [power]; split_ifs <;> norm_num + | succ n ih => exact conv_nonneg hp ih + +lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by + intro n + induction n with + | zero => simp [power] + | succ n ih => rw [power,sum_conv,hp,ih,one_mul] + +lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) + (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by + induction l with + | nil => simp [power] + | cons a l ih => + simpa only [List.length_cons,List.prod_cons,power] using + conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) + (ih (fun g hg => hl g (by simp [hg]))) + +lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by + induction m, hnm using Nat.le_induction with + | base => exact hg + | succ m _ ih => + simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih + +theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + (hgen : Subgroup.closure {g | 0 < p g}=⊤) : + ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by + have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by + rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] + trivial + choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) + let n := Finset.univ.sup (fun g => (l g).length) + refine ⟨n,fun g => ?_⟩ + have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) + have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) + have hpos := power_list_pos hp (l g) (hl g) + rw [hprod g] at hpos + exact power_pos_mono hp h1 (hlen.trans hpow) hpos + +structure Minorant (p : G → ℝ) where + exponent : ℕ + mass : ℝ + mass_pos : 0 < mass + mass_le_one : mass ≤ 1 + lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g + +noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) + (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by + let n := Classical.choose (exists_positive_power hp h1 hgen) + have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) + let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) + have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) + have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) + have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos + have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' + refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ + have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp + rw [he] + exact hag g + +end Thorp.FiniteConvolution +namespace Thorp.UnitaryFinite + +section +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : + continuousRepresentation ρ g v=ρ g v := rfl + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : + ‖ρ g v‖=‖v‖ := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] + +omit [Fintype G] in +lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + ‖continuousRepresentation ρ g‖≤1 := by + apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one + intro v + simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] + +omit [Fintype G] in +lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by + ext w + apply ext_inner_left ℂ + intro v + rw [ContinuousLinearMap.adjoint_inner_right] + exact (unitary_inner_inv ρ hρ g v w).symm + +noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := + ∑ g, (p g : ℂ) • continuousRepresentation ρ g + +lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro g _ + rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] + exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) + +lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by + change (weightedOperator ρ p).adjoint=weightedOperator ρ p + unfold weightedOperator + rw [map_sum] + simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] + apply Fintype.sum_equiv (Equiv.inv G) + intro g + simp [hp] + +noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := + weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) + +lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) + +lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : + continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,←map_mul] + exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) + +lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : + uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,←map_mul] + exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) + +lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : + IsIdempotentElem (uniformOperator ρ) := by + change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ + nth_rw 1 [uniformOperator,weightedOperator] + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, + ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] + rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsStarProjection (uniformOperator ρ) := + ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ + +lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : + weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : + uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) + (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : + ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by + let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) + have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) + have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hsum : ∑ g,q g=1-ε := by + simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by + simp only [uniformOperator,weightedOperator] + rw [Finset.smul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro g _ + simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, + Complex.ofReal_inv,Complex.ofReal_natCast] + congr 1 + field_simp + ring + have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by + rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] + rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] + calc + _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ + _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) + ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) + (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) + _ = _ := mul_one _ + +end +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : + weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by + unfold weightedOperator FiniteConvolution.conv + simp only [Complex.ofReal_sum,Finset.sum_smul] + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [Finset.mul_sum] + simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp [Complex.ofReal_mul,mul_comm] + +lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : + weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by + induction n with + | zero => simp [FiniteConvolution.power,weightedOperator] + | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] + +lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) + (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : + (weightedOperator ρ p-uniformOperator ρ)^n= + (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by + have hAP := weighted_uniform_left ρ p + have hPA := weighted_uniform_right ρ p + rw [hp,one_smul] at hAP hPA + have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by + show _*_= _*_ + rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] + have he : weightedOperator ρ p-uniformOperator ρ= + weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] + rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] + +noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := + 1-c.mass/(2*(2:ℝ)^c.exponent) + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + unfold minorantGap + linarith + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by + unfold minorantGap + exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) + +theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) + (c : FiniteConvolution.Minorant p) : + ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by + have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) + have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) + (FiniteConvolution.sum_power hp _) c.mass c.lower + rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), + hself.norm_pow_two_pow] at hbound + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + have hbern := one_add_mul_le_pow + (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) + (2^c.exponent) + have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by + push_cast + field_simp + ring + rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern + by_contra h + have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h + have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) + linarith [c.mass_pos] + +end Thorp.UnitaryFinite +namespace Thorp +open scoped BigOperators Classical + +def butterflyIdentity : (d : ℕ) → Butterfly d + | 0 => () + | d+1 => (fun _ => false,fun _ => butterflyIdentity d) + +lemma pairSwitch_false (d : ℕ) : pairSwitch (d := d) (fun _ => false)=1 := by + apply Equiv.ext + intro x + change switchFun (fun _ => false) x=x + simp [switchFun] + +lemma childLift_one (d : ℕ) : childLift (d := d) (fun _ => 1)=1 := by + ext x i + simp [childLift] + +lemma butterflyIdentity_perm (d : ℕ) : butterflyPerm d (butterflyIdentity d)=1 := by + induction d with + | zero => rfl + | succ d ih => simp only [butterflyIdentity,butterflyPerm,ih,pairSwitch_false,childLift_one,mul_one] + +noncomputable def childInjection (d : ℕ) (b : Bool) : Equiv.Perm (Card d) →* Equiv.Perm (Card (d+1)) where + toFun p := childLift (fun c => if c=b then p else 1) + map_one' := by simpa only [ite_self] using childLift_one d + map_mul' p q := by + rw [childLift_mul] + congr 1 + funext c + split_ifs <;> simp + +lemma childInjection_swap (d : ℕ) (b : Bool) (u v : Card d) : + childInjection d b (Equiv.swap u v)=Equiv.swap (Fin.cons b u) (Fin.cons b v) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change (Fin.cons c ((if c=b then Equiv.swap u v else 1) w) : Card (d+1))=_ + by_cases hc : c=b + · subst c + simp only [↓reduceIte] + rw [Equiv.swap_apply_def] + split_ifs with h₁ h₂ + · subst w; simp + · subst w; simp + · rw [Equiv.swap_apply_of_ne_of_ne] + · exact fun h => h₁ (by simpa using congrArg Fin.tail h) + · exact fun h => h₂ (by simpa using congrArg Fin.tail h) + · rw [ite_eq_right hc,Equiv.Perm.one_apply,Equiv.swap_apply_of_ne_of_ne] + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + · intro h; exact hc (by simpa using congrArg (fun z => z 0) h) + +lemma pairSwitch_single (d : ℕ) (u : Card d) : + pairSwitch (fun v => decide (v=u))=Equiv.swap (Fin.cons false u) (Fin.cons true u) := by + apply Equiv.ext + intro x + obtain ⟨c,w,rfl⟩ : ∃ c w, x=Fin.cons c w := ⟨x 0,Fin.tail x,(Fin.cons_self_tail x).symm⟩ + change switchFun (fun v => decide (v=u)) (Fin.cons c w)=_ + by_cases h : w=u + · subst w + cases c <;> simp [switchFun] + · have ha : (Fin.cons c w : Card (d+1))≠Fin.cons false u := fun he => h (by simpa using congrArg Fin.tail he) + have hb : (Fin.cons c w : Card (d+1))≠Fin.cons true u := fun he => h (by simpa using congrArg Fin.tail he) + simp [switchFun,h,Equiv.swap_apply_of_ne_of_ne ha hb] + +theorem butterfly_generates (d : ℕ) (H : Subgroup (Equiv.Perm (Card d))) + (hH : ∀ ω : Butterfly d, butterflyPerm d ω∈H) : H=⊤ := by + induction d with + | zero => + apply top_unique + intro p _ + have hp : p=1 := Subsingleton.elim _ _ + rw [hp] + exact H.one_mem + | succ d ih => + have hchild (b : Bool) (p : Equiv.Perm (Card d)) : childInjection d b p∈H := by + have hc : H.comap (childInjection d b)=⊤ := by + apply ih + intro ω + change childLift (fun c => if c=b then butterflyPerm d ω else 1)∈H + have h := hH ((fun _ => false),fun c => if c=b then ω else butterflyIdentity d) + simpa only [butterflyPerm,pairSwitch_false,one_mul,apply_ite,butterflyIdentity_perm] using h + have hp : p∈H.comap (childInjection d b) := by rw [hc]; trivial + exact hp + have hpair (u : Card d) : Equiv.swap (Fin.cons false u) (Fin.cons true u)∈H := by + rw [←pairSwitch_single] + have h := hH ((fun v => decide (v=u)),fun _ => butterflyIdentity d) + simpa only [butterflyPerm,butterflyIdentity_perm,childLift_one,mul_one] using h + have hswap (x y : Card (d+1)) : Equiv.swap x y∈H := by + have ht (a b : Bool) (u : Card d) : Equiv.swap (Fin.cons a u) (Fin.cons b u)∈H := by + cases a <;> cases b + · rw [Equiv.swap_self]; exact H.one_mem + · exact hpair _ + · rw [Equiv.swap_comm]; exact hpair _ + · rw [Equiv.swap_self]; exact H.one_mem + have h₁ : Equiv.swap x (Fin.cons (y 0) (Fin.tail x))∈H := by + convert ht (x 0) (y 0) (Fin.tail x) using 1 + rw [Fin.cons_self_tail] + have h₂ := hchild (y 0) (Equiv.swap (Fin.tail x) (Fin.tail y)) + rw [childInjection_swap,Fin.cons_self_tail] at h₂ + exact SubmonoidClass.swap_mem_trans H h₁ h₂ + rw [eq_top_iff,←Equiv.Perm.closure_isSwap,Subgroup.closure_le] + rintro _ ⟨x,y,_,rfl⟩ + exact hswap x y + +lemma butterfly_closure (d : ℕ) : Subgroup.closure (Set.range (butterflyPerm d))=⊤ := + butterfly_generates d _ (fun ω => Subgroup.subset_closure ⟨ω,rfl⟩) + +variable {Ω G : Type*} [Fintype Ω] [Fintype G] + +noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := + finiteMean (fun ω => if P ω=g then 1 else 0) + +omit [Fintype G] in +lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := + finiteMean_nonneg (fun _ => by split_ifs <;> norm_num) + +lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by + unfold sampleLaw + rw [←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype G] in +lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : + 0 by split_ifs <;> norm_num)] + simp only [Finset.mem_univ,true_and] + apply exists_congr + intro ω + split_ifs <;> simp_all + +omit [Fintype G] in +lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : + sampleLaw (P ∘ e)=sampleLaw P := by + funext g + simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) + +variable [Group G] +omit [Fintype G] in +lemma sampleLaw_inverse (P : Ω → G) (g : G) : + sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by + apply finiteMean_congr + intro ω + rw [inv_eq_iff_eq_inv] + +omit [Fintype G] in +lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) + (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by + rw [←sampleLaw_inverse] + have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) + rw [hh,sampleLaw_equiv] + +end Thorp + +namespace Thorp +open scoped BigOperators Classical + +lemma palindrome_identity (d : ℕ) : ∃ ω,palindromePerm d ω=1 := by + refine ⟨((butterflyCoinEquiv d).symm (butterflyIdentity d), + (butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + exact mul_inv_cancel _ + +lemma palindrome_range_contains_butterfly (d : ℕ) (ω : Butterfly d) : + ∃ ξ,palindromePerm d ξ=butterflyPerm d ω := by + refine ⟨((butterflyCoinEquiv d).symm ω,(butterflyCoinEquiv d).symm (butterflyIdentity d)),?_⟩ + unfold palindromePerm + have h (β : Butterfly d) : decodeButterfly d ((butterflyCoinEquiv d).symm β)=β := + (butterflyCoinEquiv d).apply_symm_apply β + rw [h,h,butterflyIdentity_perm,show (1 : Equiv.Perm (Card d)).symm=1 from rfl,mul_one] + +lemma palindrome_support_generates (d : ℕ) : + Subgroup.closure {g | 0 P i v) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) + rw [hsplit] at hp + have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) + rw [hsplit] at ha + have he (i : ι) : P i (A v)=(A*P i) (P i v) := by + change (P i*A) v=(A*P i*P i) v + rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] + have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by + rw [he] + exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) + have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) + simp_rw [mul_pow] at hsq + rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq + exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq + +theorem sector_sandwich_le (T P A B : V →L[ℂ] V) + (hT : IsStarProjection T) (hP : IsStarProjection P) + (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : + ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by + have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by + change _=star (T*B)*A*(T*B) + rw [star_mul,hT.isSelfAdjoint.star_eq] + change _=B.adjoint*T*A*(T*B) + rw [mul_assoc B.adjoint T A,←hcomm.eq] + simp only [mul_assoc] + rw [←mul_assoc T T B,hT.isIdempotentElem.eq] + have hTB : ‖T*B‖≤‖P*B‖ := by + have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] + rw [he] + exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) + rw [he,projection_sandwich_norm P B hP] + calc + _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] + _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 + +omit [CompleteSpace V] [Fintype ι] in +lemma resolution_commute (P : ι → V →L[ℂ] V) + (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by + by_cases hij : i=j + · subst j; exact Commute.refl _ + · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm + +omit [Fintype ι] in +lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : + (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by + rw [Finset.sum_mul] + have he (i : ι) : P i*P j=if i=j then P j else 0 := by + split_ifs with h + · subst i; exact (hP j).isIdempotentElem.eq + · exact horth i j h + simp only [he,Finset.sum_ite_eq'] + +lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) + (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) + (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : + ‖A*(∑ i∈S,P i)‖≤c := by + apply resolution_norm_bound P hP horth hsum _ _ c hc + · intro i + rw [mul_assoc,resolution_sum_mul P hP horth] + split_ifs with hi + · exact hbound i hi + · simp [hc] + · intro i + exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) + +theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) + (hT : ∀ i, IsStarProjection (T i)) + (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) + (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) + (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) + (hA : ‖A‖≤1) (hB : ‖B‖≤1) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : + ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by + have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm + Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) + have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by + rw [Finset.sum_compl_add_sum,hsum] + have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ + ∑ i∈S,B.adjoint*A*T i*B := by + rw [←Finset.sum_mul,←Finset.mul_sum] + rw [←add_mul] + simp only [mul_assoc] + rw [←mul_add,←mul_add,hsplit] + simp only [mul_one,mul_assoc] + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add + · calc + _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) + hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) + _ = c := by ring + · apply (norm_sum_le _ _).trans + exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA + +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) + +noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1-P i else P i + +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma choice_commute (E F : Finset ι) (i j : ι) : + Commute (choice P E i) (choice P F j) := by + unfold choice + split_ifs + · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) + · exact (Commute.one_left _).sub_left (hcomm i j) + · exact (Commute.one_right _).sub_right (hcomm i j) + · exact hcomm i j + +noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := + s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : + sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by + exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : + sector P hcomm s E=sector P hcomm s F := by + apply Finset.noncommProd_congr rfl + intro i hi + simp only [choice,h i hi] + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_factor_commute (s E F : Finset ι) (i : ι) : + Commute (choice P E i) (sector P hcomm s F) := + Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) + +omit [Fintype ι] in +lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : + IsStarProjection (sector P hcomm s E) := by + induction s using Finset.induction_on with + | empty => exact IsStarProjection.one _ + | @insert a s ha ih => + rw [sector_insert P hcomm s E a ha] + have hc : IsStarProjection (choice P E a) := by + unfold choice + split_ifs + · exact (hP a).one_sub + · exact hP a + exact hc.mul ih (sector_factor_commute P hcomm s E E a) + +end Thorp.CommutingBlocks + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/RotationMeeting.lean b/lean/OAI/Probability/ThorpRouting/Tail/RotationMeeting.lean index 89c647041ba230346896ee180ea4ea8c8e31cf6b..e9f2de5b6b1d7762caff841bf2a89c050f4ae057 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/RotationMeeting.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/RotationMeeting.lean @@ -1,881 +1,881 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ExposedCoins - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp -open scoped BigOperators -open Filter -section Rotation -variable {d A : ℕ} - -noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) - (u v : Card d) : ℝ := - match o u, o v with - | some i, some j => if i < j then (if (z j).val = v then 1 else 0) - else if j < i then (if (z i).val = u then 1 else 0) - else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) - | _, _ => 0 - -lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : - Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by - classical - simp [cycleFiber,Fintype.card_subtype] - -lemma terminal_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (i : Fin A) (x : Card d) (hx : o x = some i) : - finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by - classical - have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) - i (fun z => if z.val = x then (1:ℝ) else 0) - rw [hev] - have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = - (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by - funext z - simp only [Subtype.ext_iff] - rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] - -lemma slotWeight_antitone (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) - (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by - intro i j hij - unfold slotWeight - apply one_div_le_one_div_of_le - · exact_mod_cast Finset.card_pos.mpr (hn i) - · exact_mod_cast hm hij - -lemma rotationMeeting_mean {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : - finiteMean (fun z : Terminal o => rotationMeeting o z u v) = - min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - have hw := slotWeight_antitone o hn hm - cases hu : o u with - | none => - cases hv : o v with - | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] - | some j => - have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] - | some i => - cases hv : o v with - | none => - have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity - simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] - | some j => - simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] - rcases lt_trichotomy i j with hij | rfl | hji - · simp only [hij,↓reduceIte,ne_of_lt hij] - rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] - · simp only [lt_self_iff_false,↓reduceIte,min_self] - rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] - · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] - rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] - -lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : - ∑ x : Card d, pathWeight o x = (A : ℝ) := by - classical - have he (x : Card d) : pathWeight o x = - ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by - cases hx : o x with - | none => simp [pathWeight,hx] - | some j => simp [pathWeight,hx] - simp only [he] - rw [Finset.sum_comm] - have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by - rw [← Finset.sum_filter] - change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 - simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] - exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') - simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] - -lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) - (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : - (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have he (u v : Card d) : withinWeight o u v = - ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by - simp only [mem_cycleFiber] - cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.sum_mul] - have hi := marked_switch_entropy_bound d b (cycleFiber o i) - have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) - have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) - calc - _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / - (2 * Real.log 2) * slotWeight o i := hmul - _ = _ := by unfold slotWeight; field_simp - -noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) - (z : Terminal o) : ℝ := - ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 - -lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by - classical - have hn : ∀ i, (cycleFiber o i).Nonempty := by - intro i - obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) - exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ - unfold rotationCharge - rw [finiteMean_sum] - simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] - have h₁ := weighted_switch_min_bound d b (pathWeight o) - rw [pathWeight_sum o hn] at h₁ - have h₂ := withinWeight_sum_bound o hn b - linarith - -lemma rotation_exp_bound {o : Card d → Option (Fin A)} - [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] - (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ - finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by - have hb := rotationCharge_mean_bound hm b - have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) - have hm' : -Real.log 2 * ((A:ℝ)*d/2 + - ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ - finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by - have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) - simp only [mul_comm] at he - rw [he] - exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) - exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) - -end Rotation - -section OrbitCore -variable {α : Type*} [Fintype α] [DecidableEq α] - -noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := - Finset.univ.filter (p.SameCycle x) - -@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : - y ∈ orbitSet p x ↔ p.SameCycle x y := by - classical - simp [orbitSet] - -lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := - ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ - -lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : - orbitSet p x = orbitSet p y := by - ext z - simp only [mem_orbitSet] - exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ - -@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by - ext y - simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] - -lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : - orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by - classical - by_cases h : p.SameCycle x y - · exact Or.inl (orbitSet_eq p h) - · right - apply Finset.disjoint_left.mpr - intro z hz hz' - exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) - -omit [DecidableEq α] in -lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : - 0 < Function.minimalPeriod p x := - Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) - -lemma orbitSet_card (p : Equiv.Perm α) (x : α) : - (orbitSet p x).card = Function.minimalPeriod p x := by - classical - let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => - ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ - have hf : Function.Bijective f := by - constructor - · intro i j hij - apply Fin.ext - exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) - · intro y - obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq - refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ - apply Subtype.ext - change p^[n % Function.minimalPeriod p x] x = y.val - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - have hc := Fintype.card_congr (Equiv.ofBijective f hf) - simpa [orbitSet,Fintype.card_subtype] using hc.symm - -def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := - (Finset.range r).image (fun n => p^[n] x) - -omit [Fintype α] in -@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : - y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by - simp [walkSet] - -omit [Fintype α] in -@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by - simp [walkSet] - -omit [Fintype α] in -lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by - simp [walkSet,Finset.range_add_one] - -omit [Fintype α] in -lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p (r+1) x = insert x (walkSet p r (p x)) := by - ext y - simp only [mem_walkSet,Finset.mem_insert] - constructor - · rintro ⟨n,hn,hny⟩ - cases n with - | zero => exact Or.inl (by simpa using hny.symm) - | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - · rintro (rfl | ⟨n,hn,hny⟩) - · exact ⟨0,by omega,rfl⟩ - · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ - -omit [Fintype α] in -lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by - rintro hx - obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx - have hperiod : Function.IsPeriodicPt p (n+1) x := by - simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx - have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) - omega - -lemma walkSet_period (p : Equiv.Perm α) (x : α) : - walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by - ext y - simp only [mem_walkSet,mem_orbitSet] - constructor - · rintro ⟨n,_,rfl⟩ - rw [Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - · intro h - obtain ⟨n,hn⟩ := h.exists_nat_pow_eq - refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ - rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] - -omit [Fintype α] in -lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} - (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by - rw [walkSet,Finset.card_image_of_injOn] - · exact Finset.card_range _ - · intro i hi j hj hij - exact Function.iterate_injOn_Iio_minimalPeriod - (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) - (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij - -lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : - walkSet p r x ⊆ orbitSet p x := by - intro y hy - obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy - rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] - exact ⟨(n:ℤ),by simp⟩ - -def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : - ℕ → α → Finset α → Option (Finset α × α) - | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none - | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none - -lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) - (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) - (hV : Disjoint V (walkSet p (r+1) x)) : - cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by - induction r generalizing x V with - | zero => - have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) - simp [cycleTrace,hxS,hxV,walkSet_succ_first] - | succ r ih => - have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h - (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) - have hr' : r < Function.minimalPeriod p (p x) := by - rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] - omega - have hS' : walkSet p (r+1) (p x) ⊆ S := by - intro y hy - apply hS - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy - have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by - apply Finset.disjoint_left.mpr - intro y hy hy' - rcases Finset.mem_insert.mp hy with hy | hy - · subst y - exact not_mem_short_walk p x hr hy' - · apply Finset.disjoint_left.mp hV hy - rw [walkSet_succ_first] - exact Finset.mem_insert_of_mem hy' - rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, - ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] - simp only [Finset.insert_union,Finset.union_insert] - -lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) - (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : - cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = - some (V ∪ orbitSet p z,z) := by - have hpos := perm_minimalPeriod_pos p z - have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := - Function.minimalPeriod_apply (p.injective.mem_periodicPts z) - have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega - have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by - rw [hp,←he,walkSet_period,orbitSet_apply] - have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega - have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr - (by simpa only [hw] using hS) (by simpa only [hw] using hV) - have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by - rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = - Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] - have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by - rw [hp,←he,Function.iterate_minimalPeriod] - simpa only [ha,ht,hw] using h - -end OrbitCore - -noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : - Finset (SwitchIndex d) := - V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) - -@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by - classical - simp [exposedPaths] - -lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : - exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by - classical - simp [exposedPaths,Finset.union_comm] - -noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := - (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card - -namespace QueryTree - -lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] - (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) - (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : - staleCharge (followPath d e x k) R ω = - staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by - have h₀ := fresh_add_stale (followPath d e x k) R ω - have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) - (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω - rw [followPath_charge,followPath_raw_charge] at h₀ - omega - -lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) - (x : Card d) (V W : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : - (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - classical - induction r generalizing x V with - | zero => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV,hxa⟩ := hv - obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) - simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] - constructor - · trivial - · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, - Finset.erase_insert hxV] - simp only [terminalCharge,hxa] - | succ r ih => - simp only [cycleTrace] at h - split_ifs at h with hv - obtain ⟨hxS,hxV⟩ := hv - rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] - simp only [Function.comp_id,Finset.image_id] - rw [← exposedPaths_insert] - exact ih _ _ h - -lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) - (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) - (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) - (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : - let p := butterflyPerm d (decodeButterfly d ω) - let W := V ∪ orbitSet p z - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ - (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge - (exposedPaths d (decodeButterfly d ω) V) ω = - (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + - terminalCharge d (decodeButterfly d ω) z (W.erase z) := by - exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) - -end QueryTree - -lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : - s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by - classical - simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] - constructor - · rintro ⟨x,hx,h | h⟩ - · exact Or.inl (h ▸ hx) - · exact Or.inr (h ▸ hx) - · rintro (h | h) - · exact ⟨_,h,Or.inl rfl⟩ - · exact ⟨_,h,Or.inr rfl⟩ - -lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) - (hz : z ∉ V) : - (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, - ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + - (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by - classical - have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = - Finset.univ.filter (fun s => - ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ - ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by - ext s - simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, - Finset.mem_filter,Finset.mem_univ,true_and] - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - rw [terminalCharge,he] - simp only [← Finset.sum_boole] - apply Finset.sum_congr rfl - intro s _ - by_cases h₁ : (switchUsers d b s).1 = z <;> - by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] - -noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := - Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) - -@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : - x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by - classical - simp [priorPaths] - -lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) (i : Fin A) : - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = - ∑ s : SwitchIndex d, - ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0) + - (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) - then (1:ℝ) else 0)) := by - classical - rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] - apply Finset.sum_congr rfl - intro s _ - have hn := switchUsers_ne d b s - simp only [Finset.mem_erase] - by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> - by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] - -lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (z : Terminal o) (u v : Card d) : - rotationMeeting o z u v = ∑ i : Fin A, - ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + - (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by - classical - have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) - (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - exact hia (Option.some.inj hi).symm - have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = - if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by - apply Finset.sum_eq_single a - · intro i _ hia - simp [only_owner u a hou i hia] - · simp - have sum_none (u v : Card d) (hou : o u = none) : - (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by - apply Finset.sum_eq_zero - intro i _ - have hn : (z i).val ≠ u := by - intro h - have hi := (z i).property - rw [h,hou] at hi - contradiction - simp [hn] - rw [Finset.sum_add_distrib] - cases hou : o u with - | none => - rw [sum_none u v hou] - simp [rotationMeeting,hou,mem_priorPaths] - | some a => - rw [sum_one u v a hou] - cases hov : o v with - | none => - rw [sum_none v u hov] - simp [rotationMeeting,hou,hov,mem_priorPaths] - | some b => - rw [sum_one v u b hov] - simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] - rcases lt_trichotomy a b with hab | rfl | hba - · have hn : ¬ b.val < a.val+1 := by omega - have hy : a.val < b.val+1 := by omega - simp [hab,hn,hy] - · simp - · have hn : ¬ a.val < b.val+1 := by omega - have hy : b.val < a.val+1 := by omega - simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] - -lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) - (b : Butterfly d) (z : Terminal o) : - rotationCharge o b z = ∑ i : Fin A, - (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by - simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] - exact Finset.sum_comm - -@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by - classical - ext x - simp - -lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : - priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by - classical - ext x - simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] - constructor - · rintro ⟨i,hi,hit⟩ - by_cases h : i.val < t - · exact Or.inl ⟨i,hi,h⟩ - · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) - exact Or.inr (he ▸ hi) - · rintro (⟨i,hi,hit⟩ | hi) - · exact ⟨i,hi,by omega⟩ - · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ - -lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : - Disjoint (priorPaths o i.val) (cycleFiber o i) := by - classical - apply Finset.disjoint_left.mpr - intro x hx hx' - obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx - have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) - subst j - exact (lt_irrefl _ hji) - -namespace QueryTree - -lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) - (hS : ∀ i, cycleFiber o i ⊆ S) - (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) - (hC : ∀ i, (cycleFiber o i).card = r i+1) : - let p := butterflyPerm d (decodeButterfly d ω) - let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) - (seekCycles d S L ∅).succeeds ω = true ∧ - ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by - classical - let b := decodeButterfly d ω - let p := butterflyPerm d b - let f (i : Fin A) := (p (z i).val,r i) - let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) - have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by - have he := orbitSet_card p (z i).val - rw [hO,hC] at he - omega - have hs (t : ℕ) (ht : t ≤ A) : - (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ - ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = - ((List.ofFn c).drop t).sum := by - induction ht using Nat.decreasingInduction with - | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] - | of_succ t ht ih => - have htf : t < (List.ofFn f).length := by simpa using ht - have htc : t < (List.ofFn c).length := by simpa using ht - rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] - simp only [List.getElem_ofFn,List.sum_cons,seekCycles] - have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val - (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω - (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) - dsimp only at h - rw [hc,hO,←priorPaths_succ o t ht] at h - dsimp only [f] - constructor - · exact h.1.trans ih.1 - · rw [h.2,Nat.cast_add,ih.2] - exact add_comm _ _ - have h := hs 0 (Nat.zero_le _) - simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h - dsimp only - exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ - -end QueryTree - -section Collections -variable {d A : ℕ} - -def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) - (o : Card d → Option (Fin A)) : Prop := - (∀ i, (cycleFiber o i).card = r i + 1) ∧ - (∀ i, cycleFiber o i ⊆ S) ∧ - (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) - -abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (CycleSlots p S r) := Fintype.ofFinite _ - -lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by - have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) - obtain ⟨x,hx⟩ := hn - exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ - -lemma owner_ext {o o' : Card d → Option (Fin A)} - (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by - funext x - have he (i : Fin A) : o x = some i ↔ o' x = some i := by - simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) - cases ho : o x with - | some i => exact ((he i).mp ho).symm - | none => - cases ho' : o' x with - | none => rfl - | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction - -abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - Σ c : CycleSlots p S r, Terminal c.val - -noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : RootedSlots p S r) : Fin A → S := fun i => - ⟨p (c.2 i).val,c.1.property.2.1 i (by - rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] - exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ - -lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : - Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by - rintro ⟨c,z⟩ ⟨c',z'⟩ h - have hz (i : Fin A) : (z i).val = (z' i).val := - p.injective (congrArg Subtype.val (congrFun h i)) - have hc : c = c' := Subtype.ext (owner_ext (fun i => by - rw [←c.property.2.2 i (z i).val (z i).property, - ←c'.property.2.2 i (z' i).val (z' i).property,hz])) - subst c' - have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) - subst z' - rfl - -lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] - (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : - ∑ a, f (e a) ≤ ∑ b, f b := by - classical - calc - _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) - -lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : - (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ - ∑ a : Fin A → S, - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 := by - classical - let p := butterflyPerm d (decodeButterfly d ω) - let g (a : Fin A → S) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have he (c : RootedSlots p S r) : - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = - g (rootedStart c) := by - have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 - (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 - dsimp only at hs - unfold g - rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] - rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - rfl - simp_rw [he] - exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) - -noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) - -noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := - ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r - -lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by - unfold collectionWeight rotationLower - positivity - -lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) - (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : - collectionWeight d r ≤ ∑ z : Terminal c.val, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by - classical - let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i - have hm : Monotone (fun i => (cycleFiber c.val i).card) := by - intro i j hij - dsimp only - rw [c.property.1,c.property.1] - exact Nat.add_le_add_right (hr hij) 1 - have hb := rotation_exp_bound hm (decodeButterfly d ω) - have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by - rw [Fintype.card_pi,Nat.cast_prod] - apply Finset.prod_congr rfl - intro i _ - rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] - have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos - have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by - simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb - have hh := (le_div_iff₀ hp).mp hl - rw [hcard] at hh - unfold collectionWeight - rw [← Finset.mul_sum] - calc - _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) - -lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * - collectionWeight d r ≤ (S.card : ℝ)^A := by - classical - let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := - if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then - ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω - else 0 - have hω (ω : SwitchIndex d → Bool) : - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ - ∑ a : Fin A → S, g a ω := by - calc - _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp - _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := - Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) - _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := - (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => - ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm - _ ≤ _ := rooted_weight_sum_le S r ω - have hb := finiteMean_mono hω - rw [finiteMean_mul_const,finiteMean_sum] at hb - calc - _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb - _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) - simpa only [List.length_ofFn] using hh - _ = _ := by simp - -lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - (S.card : ℝ)^A / collectionWeight d r := by - exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) - -lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : - collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by - have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by - rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] - have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by - rw [Real.exp_sum] - apply Finset.prod_congr rfl - intro i _ - exact (Real.exp_log (by positivity)).symm - have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] - congr 1 - ring - have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by - rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] - congr 1 - ring - simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] - rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] - congr 1 - rw [←Finset.sum_div,←Finset.sum_div] - have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) - field_simp - ring - -lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : - finiteMean (fun ω : SwitchIndex d → Bool => - (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ - ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * - ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by - have h := cycleSlots_moment S r hr - rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h - rw [div_pow] - simpa only [one_div,Finset.prod_inv_distrib] using h - -end Collections - -variable {d A : ℕ} - -abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := - {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : - Fintype (SelectedCycle p S) := Fintype.ofFinite _ - -lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) : C.val.Nonempty := by - obtain ⟨x,hx⟩ := C.property.1 - rw [hx] - exact orbitSet_nonempty p x - -lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by - obtain ⟨y,hy⟩ := C.property.1 - rw [hy] at hx ⊢ - exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm - -lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} - (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by - apply Subtype.ext - exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) - -abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := - {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} - -noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : - Fintype (SlotAssignment p S r) := Fintype.ofFinite _ - -noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (c : CycleSlots p S r) : SlotAssignment p S r := by - classical - let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by - obtain ⟨x,hx⟩ := c.terminal_nonempty i - exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ - refine ⟨f,?_,fun i => c.property.1 i⟩ - intro i j hij - have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij - obtain ⟨x,hx⟩ := c.terminal_nonempty i - have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx - rw [he] at hxi - exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) - -noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} - (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by - classical - exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none - -end Thorp - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ExposedCoins + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp +open scoped BigOperators +open Filter +section Rotation +variable {d A : ℕ} + +noncomputable def rotationMeeting (o : Card d → Option (Fin A)) (z : Terminal o) + (u v : Card d) : ℝ := + match o u, o v with + | some i, some j => if i < j then (if (z j).val = v then 1 else 0) + else if j < i then (if (z i).val = u then 1 else 0) + else (if (z i).val = u then 1 else 0) + (if (z i).val = v then 1 else 0) + | _, _ => 0 + +lemma card_cycleFiber (o : Card d → Option (Fin A)) (i : Fin A) : + Fintype.card {x : Card d // o x = some i} = (cycleFiber o i).card := by + classical + simp [cycleFiber,Fintype.card_subtype] + +lemma terminal_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (i : Fin A) (x : Card d) (hx : o x = some i) : + finiteMean (fun z : Terminal o => if (z i).val = x then (1:ℝ) else 0) = slotWeight o i := by + classical + have hev := finiteMean_pi_eval (A := fun i : Fin A => {x : Card d // o x = some i}) + i (fun z => if z.val = x then (1:ℝ) else 0) + rw [hev] + have he : (fun z : {x : Card d // o x = some i} => if z.val = x then (1:ℝ) else 0) = + (fun z => if z = ⟨x,hx⟩ then 1 else 0) := by + funext z + simp only [Subtype.ext_iff] + rw [he,finiteMean_eq_indicator,card_cycleFiber,slotWeight] + +lemma slotWeight_antitone (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) + (hm : Monotone (fun i => (cycleFiber o i).card)) : Antitone (slotWeight o) := by + intro i j hij + unfold slotWeight + apply one_div_le_one_div_of_le + · exact_mod_cast Finset.card_pos.mpr (hn i) + · exact_mod_cast hm hij + +lemma rotationMeeting_mean {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (u v : Card d) : + finiteMean (fun z : Terminal o => rotationMeeting o z u v) = + min (pathWeight o u) (pathWeight o v) + withinWeight o u v := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + have hw := slotWeight_antitone o hn hm + cases hu : o u with + | none => + cases hv : o v with + | none => simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean] + | some j => + have hj : 0 ≤ slotWeight o j := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_left hj] + | some i => + cases hv : o v with + | none => + have hi : 0 ≤ slotWeight o i := by unfold slotWeight; positivity + simp [rotationMeeting,pathWeight,withinWeight,hu,hv,finiteMean,min_eq_right hi] + | some j => + simp only [rotationMeeting,pathWeight,withinWeight,hu,hv] + rcases lt_trichotomy i j with hij | rfl | hji + · simp only [hij,↓reduceIte,ne_of_lt hij] + rw [terminal_mean j v hv,min_eq_right (hw (le_of_lt hij)),add_zero] + · simp only [lt_self_iff_false,↓reduceIte,min_self] + rw [finiteMean_add,terminal_mean i u hu,terminal_mean i v hv] + · simp only [not_lt_of_ge (le_of_lt hji),hji,↓reduceIte,ne_of_gt hji] + rw [terminal_mean i u hu,min_eq_left (hw (le_of_lt hji)),add_zero] + +lemma pathWeight_sum (o : Card d → Option (Fin A)) (hn : ∀ i, (cycleFiber o i).Nonempty) : + ∑ x : Card d, pathWeight o x = (A : ℝ) := by + classical + have he (x : Card d) : pathWeight o x = + ∑ i : Fin A, if o x = some i then slotWeight o i else 0 := by + cases hx : o x with + | none => simp [pathWeight,hx] + | some j => simp [pathWeight,hx] + simp only [he] + rw [Finset.sum_comm] + have hf (i : Fin A) : (∑ x : Card d, if o x = some i then slotWeight o i else 0) = 1 := by + rw [← Finset.sum_filter] + change (∑ _x ∈ cycleFiber o i, slotWeight o i) = 1 + simp only [Finset.sum_const,nsmul_eq_mul,slotWeight] + exact mul_one_div_cancel (by exact_mod_cast (Finset.card_pos.mpr (hn i)).ne') + simp only [hf,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + +lemma withinWeight_sum_bound (o : Card d → Option (Fin A)) + (hn : ∀ i, (cycleFiber o i).Nonempty) (b : Butterfly d) : + (∑ s : SwitchIndex d, withinWeight o (switchUsers d b s).1 (switchUsers d b s).2) ≤ + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have he (u v : Card d) : withinWeight o u v = + ∑ i : Fin A, (if u ∈ cycleFiber o i ∧ v ∈ cycleFiber o i then (1:ℝ) else 0) * slotWeight o i := by + simp only [mem_cycleFiber] + cases hu : o u <;> cases hv : o v <;> simp [withinWeight,hu,hv,ite_and,eq_comm] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + have hi := marked_switch_entropy_bound d b (cycleFiber o i) + have hpos : (0:ℝ) < (cycleFiber o i).card := by exact_mod_cast Finset.card_pos.mpr (hn i) + have hmul := mul_le_mul_of_nonneg_right hi (show 0 ≤ slotWeight o i by unfold slotWeight; positivity) + calc + _ ≤ ((cycleFiber o i).card : ℝ) * Real.log (cycleFiber o i).card / + (2 * Real.log 2) * slotWeight o i := hmul + _ = _ := by unfold slotWeight; field_simp + +noncomputable def rotationCharge (o : Card d → Option (Fin A)) (b : Butterfly d) + (z : Terminal o) : ℝ := + ∑ s : SwitchIndex d, rotationMeeting o z (switchUsers d b s).1 (switchUsers d b s).2 + +lemma rotationCharge_mean_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + finiteMean (rotationCharge o b) ≤ (A:ℝ) * d / 2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2) := by + classical + have hn : ∀ i, (cycleFiber o i).Nonempty := by + intro i + obtain ⟨x,hx⟩ := (inferInstance : Nonempty {x : Card d // o x = some i}) + exact ⟨x,mem_cycleFiber _ _ _ |>.mpr hx⟩ + unfold rotationCharge + rw [finiteMean_sum] + simp only [rotationMeeting_mean hm,Finset.sum_add_distrib] + have h₁ := weighted_switch_min_bound d b (pathWeight o) + rw [pathWeight_sum o hn] at h₁ + have h₂ := withinWeight_sum_bound o hn b + linarith + +lemma rotation_exp_bound {o : Card d → Option (Fin A)} + [∀ i : Fin A, Nonempty {x : Card d // o x = some i}] + (hm : Monotone (fun i => (cycleFiber o i).card)) (b : Butterfly d) : + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2))) ≤ + finiteMean (fun z : Terminal o => Real.exp (-Real.log 2 * rotationCharge o b z)) := by + have hb := rotationCharge_mean_bound hm b + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hm' : -Real.log 2 * ((A:ℝ)*d/2 + + ∑ i : Fin A, Real.log (cycleFiber o i).card / (2 * Real.log 2)) ≤ + finiteMean (fun z : Terminal o => -Real.log 2 * rotationCharge o b z) := by + have he := finiteMean_mul_const (rotationCharge o b) (-Real.log 2) + simp only [mul_comm] at he + rw [he] + exact mul_le_mul_of_nonpos_left hb (neg_nonpos.mpr hlog) + exact (Real.exp_le_exp.mpr hm').trans (exp_finiteMean_le _) + +end Rotation + +section OrbitCore +variable {α : Type*} [Fintype α] [DecidableEq α] + +noncomputable def orbitSet (p : Equiv.Perm α) (x : α) : Finset α := + Finset.univ.filter (p.SameCycle x) + +@[simp] lemma mem_orbitSet (p : Equiv.Perm α) (x y : α) : + y ∈ orbitSet p x ↔ p.SameCycle x y := by + classical + simp [orbitSet] + +lemma orbitSet_nonempty (p : Equiv.Perm α) (x : α) : (orbitSet p x).Nonempty := + ⟨x,(mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.refl _ _)⟩ + +lemma orbitSet_eq (p : Equiv.Perm α) {x y : α} (h : p.SameCycle x y) : + orbitSet p x = orbitSet p y := by + ext z + simp only [mem_orbitSet] + exact ⟨fun hz => h.symm.trans hz,fun hz => h.trans hz⟩ + +@[simp] lemma orbitSet_apply (p : Equiv.Perm α) (x : α) : orbitSet p (p x) = orbitSet p x := by + ext y + simp only [mem_orbitSet,Equiv.Perm.sameCycle_apply_left] + +lemma orbitSet_eq_or_disjoint (p : Equiv.Perm α) (x y : α) : + orbitSet p x = orbitSet p y ∨ Disjoint (orbitSet p x) (orbitSet p y) := by + classical + by_cases h : p.SameCycle x y + · exact Or.inl (orbitSet_eq p h) + · right + apply Finset.disjoint_left.mpr + intro z hz hz' + exact h (((mem_orbitSet _ _ _).mp hz).trans ((mem_orbitSet _ _ _).mp hz').symm) + +omit [DecidableEq α] in +lemma perm_minimalPeriod_pos (p : Equiv.Perm α) (x : α) : + 0 < Function.minimalPeriod p x := + Function.minimalPeriod_pos_of_mem_periodicPts (p.injective.mem_periodicPts x) + +lemma orbitSet_card (p : Equiv.Perm α) (x : α) : + (orbitSet p x).card = Function.minimalPeriod p x := by + classical + let f : Fin (Function.minimalPeriod p x) → {y // p.SameCycle x y} := fun n => + ⟨p^[n.val] x,by rw [Equiv.Perm.iterate_eq_pow]; exact ⟨(n.val:ℤ),by simp⟩⟩ + have hf : Function.Bijective f := by + constructor + · intro i j hij + apply Fin.ext + exact Function.iterate_injOn_Iio_minimalPeriod i.isLt j.isLt (congrArg Subtype.val hij) + · intro y + obtain ⟨n,hn⟩ := y.property.exists_nat_pow_eq + refine ⟨⟨n % Function.minimalPeriod p x, Nat.mod_lt _ (perm_minimalPeriod_pos p x)⟩,?_⟩ + apply Subtype.ext + change p^[n % Function.minimalPeriod p x] x = y.val + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + have hc := Fintype.card_congr (Equiv.ofBijective f hf) + simpa [orbitSet,Fintype.card_subtype] using hc.symm + +def walkSet (p : Equiv.Perm α) (r : ℕ) (x : α) : Finset α := + (Finset.range r).image (fun n => p^[n] x) + +omit [Fintype α] in +@[simp] lemma mem_walkSet (p : Equiv.Perm α) (r : ℕ) (x y : α) : + y ∈ walkSet p r x ↔ ∃ n < r, p^[n] x = y := by + simp [walkSet] + +omit [Fintype α] in +@[simp] lemma walkSet_zero (p : Equiv.Perm α) (x : α) : walkSet p 0 x = ∅ := by + simp [walkSet] + +omit [Fintype α] in +lemma walkSet_succ_last (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert (p^[r] x) (walkSet p r x) := by + simp [walkSet,Finset.range_add_one] + +omit [Fintype α] in +lemma walkSet_succ_first (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p (r+1) x = insert x (walkSet p r (p x)) := by + ext y + simp only [mem_walkSet,Finset.mem_insert] + constructor + · rintro ⟨n,hn,hny⟩ + cases n with + | zero => exact Or.inl (by simpa using hny.symm) + | succ n => exact Or.inr ⟨n,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + · rintro (rfl | ⟨n,hn,hny⟩) + · exact ⟨0,by omega,rfl⟩ + · exact ⟨n+1,by omega,by simpa only [Function.iterate_succ_apply] using hny⟩ + +omit [Fintype α] in +lemma not_mem_short_walk (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r < Function.minimalPeriod p x) : x ∉ walkSet p r (p x) := by + rintro hx + obtain ⟨n,hn,hnx⟩ := (mem_walkSet _ _ _ _).mp hx + have hperiod : Function.IsPeriodicPt p (n+1) x := by + simpa only [Function.IsPeriodicPt,Function.IsFixedPt,Function.iterate_succ_apply] using hnx + have hp := hperiod.minimalPeriod_le (by omega : 0 < n+1) + omega + +lemma walkSet_period (p : Equiv.Perm α) (x : α) : + walkSet p (Function.minimalPeriod p x) x = orbitSet p x := by + ext y + simp only [mem_walkSet,mem_orbitSet] + constructor + · rintro ⟨n,_,rfl⟩ + rw [Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + · intro h + obtain ⟨n,hn⟩ := h.exists_nat_pow_eq + refine ⟨n % Function.minimalPeriod p x,Nat.mod_lt _ (perm_minimalPeriod_pos p x),?_⟩ + rw [Function.iterate_mod_minimalPeriod_eq,Equiv.Perm.iterate_eq_pow,hn] + +omit [Fintype α] in +lemma walkSet_card (p : Equiv.Perm α) (x : α) {r : ℕ} + (hr : r ≤ Function.minimalPeriod p x) : (walkSet p r x).card = r := by + rw [walkSet,Finset.card_image_of_injOn] + · exact Finset.card_range _ + · intro i hi j hj hij + exact Function.iterate_injOn_Iio_minimalPeriod + (lt_of_lt_of_le (Finset.mem_range.mp hi) hr) + (lt_of_lt_of_le (Finset.mem_range.mp hj) hr) hij + +lemma walkSet_subset_orbit (p : Equiv.Perm α) (r : ℕ) (x : α) : + walkSet p r x ⊆ orbitSet p x := by + intro y hy + obtain ⟨n,_,rfl⟩ := (mem_walkSet _ _ _ _).mp hy + rw [mem_orbitSet,Equiv.Perm.iterate_eq_pow] + exact ⟨(n:ℤ),by simp⟩ + +def cycleTrace (p : Equiv.Perm α) (S : Finset α) (a : α) : + ℕ → α → Finset α → Option (Finset α × α) + | 0, x, V => if x ∈ S ∧ x ∉ V ∧ p x = a then some (insert x V,x) else none + | r+1, x, V => if x ∈ S ∧ x ∉ V then cycleTrace p S a r (p x) (insert x V) else none + +lemma cycleTrace_walk (p : Equiv.Perm α) (S : Finset α) (r : ℕ) (x : α) (V : Finset α) + (hr : r < Function.minimalPeriod p x) (hS : walkSet p (r+1) x ⊆ S) + (hV : Disjoint V (walkSet p (r+1) x)) : + cycleTrace p S (p^[r+1] x) r x V = some (V ∪ walkSet p (r+1) x,p^[r] x) := by + induction r generalizing x V with + | zero => + have hxS : x ∈ S := hS (by simp [walkSet_succ_first]) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h (by simp [walkSet_succ_first]) + simp [cycleTrace,hxS,hxV,walkSet_succ_first] + | succ r ih => + have hxS : x ∈ S := hS (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hxV : x ∉ V := fun h => Finset.disjoint_left.mp hV h + (by rw [walkSet_succ_first]; exact Finset.mem_insert_self _ _) + have hr' : r < Function.minimalPeriod p (p x) := by + rw [Function.minimalPeriod_apply (p.injective.mem_periodicPts x)] + omega + have hS' : walkSet p (r+1) (p x) ⊆ S := by + intro y hy + apply hS + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy + have hV' : Disjoint (insert x V) (walkSet p (r+1) (p x)) := by + apply Finset.disjoint_left.mpr + intro y hy hy' + rcases Finset.mem_insert.mp hy with hy | hy + · subst y + exact not_mem_short_walk p x hr hy' + · apply Finset.disjoint_left.mp hV hy + rw [walkSet_succ_first] + exact Finset.mem_insert_of_mem hy' + rw [cycleTrace,ite_eq_left ⟨hxS,hxV⟩,Function.iterate_succ_apply p (r+1) x, + ih _ _ hr' hS' hV',walkSet_succ_first p (r+1) x,Function.iterate_succ_apply] + simp only [Finset.insert_union,Finset.union_insert] + +lemma cycleTrace_orbit (p : Equiv.Perm α) (S V : Finset α) (z : α) + (hS : orbitSet p z ⊆ S) (hV : Disjoint V (orbitSet p z)) : + cycleTrace p S (p z) (Function.minimalPeriod p z - 1) (p z) V = + some (V ∪ orbitSet p z,z) := by + have hpos := perm_minimalPeriod_pos p z + have he : Function.minimalPeriod p (p z) = Function.minimalPeriod p z := + Function.minimalPeriod_apply (p.injective.mem_periodicPts z) + have hp : Function.minimalPeriod p z - 1 + 1 = Function.minimalPeriod p z := by omega + have hw : walkSet p (Function.minimalPeriod p z - 1 + 1) (p z) = orbitSet p z := by + rw [hp,←he,walkSet_period,orbitSet_apply] + have hr : Function.minimalPeriod p z - 1 < Function.minimalPeriod p (p z) := by rw [he]; omega + have h := cycleTrace_walk p S (Function.minimalPeriod p z-1) (p z) V hr + (by simpa only [hw] using hS) (by simpa only [hw] using hV) + have ht : p^[Function.minimalPeriod p z-1] (p z) = z := by + rw [← Function.iterate_succ_apply,show (Function.minimalPeriod p z-1).succ = + Function.minimalPeriod p z by omega,Function.iterate_minimalPeriod] + have ha : p^[Function.minimalPeriod p z-1+1] (p z) = p z := by + rw [hp,←he,Function.iterate_minimalPeriod] + simpa only [ha,ht,hw] using h + +end OrbitCore + +noncomputable def exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) : + Finset (SwitchIndex d) := + V.biUnion (fun x => routeDomain d x (butterflyPerm d b x)) + +@[simp] lemma exposedPaths_empty (d : ℕ) (b : Butterfly d) : exposedPaths d b ∅ = ∅ := by + classical + simp [exposedPaths] + +lemma exposedPaths_insert (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (x : Card d) : + exposedPaths d b (insert x V) = exposedPaths d b V ∪ routeDomain d x (butterflyPerm d b x) := by + classical + simp [exposedPaths,Finset.union_comm] + +noncomputable def terminalCharge (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) : ℕ := + (routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V).card + +namespace QueryTree + +lemma followPath_stale_charge {ι : Type*} [DecidableEq ι] + (d : ℕ) (e : SwitchIndex d → ι) (x : Card d) + (k : Card d → QueryTree ι) (R : Finset ι) (ω : ι → Bool) : + staleCharge (followPath d e x k) R ω = + staleCharge (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω := by + have h₀ := fresh_add_stale (followPath d e x k) R ω + have h₁ := fresh_add_stale (k (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)) + (R ∪ (routeDomain d x (butterflyPerm d (decodeButterfly d (ω ∘ e)) x)).image e) ω + rw [followPath_charge,followPath_raw_charge] at h₀ + omega + +lemma seekCycle_semantics (d : ℕ) (S : Finset (Card d)) (a : Card d) (r : ℕ) + (x : Card d) (V W : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (h : cycleTrace (butterflyPerm d (decodeButterfly d ω)) S a r x V = some (W,z)) : + (seekCycle d S a r x V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S a r x V k).staleCharge (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + classical + induction r generalizing x V with + | zero => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV,hxa⟩ := hv + obtain ⟨rfl,rfl⟩ := Prod.mk.inj (Option.some.inj h) + simp only [seekCycle,ite_eq_left (show x ∈ S ∧ x ∉ V from ⟨hxS,hxV⟩),closePath_succeeds,ite_eq_left hxa] + constructor + · trivial + · rw [closePath_stale_charge _ _ _ _ _ _ hxa,exposedPaths_insert, + Finset.erase_insert hxV] + simp only [terminalCharge,hxa] + | succ r ih => + simp only [cycleTrace] at h + split_ifs at h with hv + obtain ⟨hxS,hxV⟩ := hv + rw [seekCycle,ite_eq_left ⟨hxS,hxV⟩,followPath_succeeds,followPath_stale_charge] + simp only [Function.comp_id,Finset.image_id] + rw [← exposedPaths_insert] + exact ih _ _ h + +lemma seekCycle_orbit (d : ℕ) (S V : Finset (Card d)) (z : Card d) + (k : Finset (Card d) → QueryTree (SwitchIndex d)) (ω : SwitchIndex d → Bool) + (hS : orbitSet (butterflyPerm d (decodeButterfly d ω)) z ⊆ S) + (hV : Disjoint V (orbitSet (butterflyPerm d (decodeButterfly d ω)) z)) : + let p := butterflyPerm d (decodeButterfly d ω) + let W := V ∪ orbitSet p z + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).succeeds ω = (k W).succeeds ω ∧ + (seekCycle d S (p z) (Function.minimalPeriod p z-1) (p z) V k).staleCharge + (exposedPaths d (decodeButterfly d ω) V) ω = + (k W).staleCharge (exposedPaths d (decodeButterfly d ω) W) ω + + terminalCharge d (decodeButterfly d ω) z (W.erase z) := by + exact seekCycle_semantics _ _ _ _ _ _ _ _ _ _ (cycleTrace_orbit _ _ _ _ hS hV) + +end QueryTree + +lemma mem_exposedPaths (d : ℕ) (b : Butterfly d) (V : Finset (Card d)) (s : SwitchIndex d) : + s ∈ exposedPaths d b V ↔ (switchUsers d b s).1 ∈ V ∨ (switchUsers d b s).2 ∈ V := by + classical + simp only [exposedPaths,Finset.mem_biUnion,mem_routeDomain_iff_user] + constructor + · rintro ⟨x,hx,h | h⟩ + · exact Or.inl (h ▸ hx) + · exact Or.inr (h ▸ hx) + · rintro (h | h) + · exact ⟨_,h,Or.inl rfl⟩ + · exact ⟨_,h,Or.inr rfl⟩ + +lemma terminalCharge_sum (d : ℕ) (b : Butterfly d) (z : Card d) (V : Finset (Card d)) + (hz : z ∉ V) : + (terminalCharge d b z V : ℝ) = ∑ s : SwitchIndex d, + ((if (switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V then (1:ℝ) else 0) + + (if (switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V then (1:ℝ) else 0)) := by + classical + have he : routeDomain d z (butterflyPerm d b z) ∩ exposedPaths d b V = + Finset.univ.filter (fun s => + ((switchUsers d b s).1 = z ∧ (switchUsers d b s).2 ∈ V) ∨ + ((switchUsers d b s).2 = z ∧ (switchUsers d b s).1 ∈ V)) := by + ext s + simp only [Finset.mem_inter,mem_routeDomain_iff_user,mem_exposedPaths, + Finset.mem_filter,Finset.mem_univ,true_and] + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + rw [terminalCharge,he] + simp only [← Finset.sum_boole] + apply Finset.sum_congr rfl + intro s _ + by_cases h₁ : (switchUsers d b s).1 = z <;> + by_cases h₂ : (switchUsers d b s).2 = z <;> simp [h₁,h₂,hz] + +noncomputable def priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) : Finset (Card d) := + Finset.univ.filter (fun x => ∃ i : Fin A, o x = some i ∧ i.val < t) + +@[simp] lemma mem_priorPaths {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (x : Card d) : + x ∈ priorPaths o t ↔ ∃ i : Fin A, o x = some i ∧ i.val < t := by + classical + simp [priorPaths] + +lemma terminalCharge_prior_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) (i : Fin A) : + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) = + ∑ s : SwitchIndex d, + ((if (z i).val = (switchUsers d b s).1 ∧ (switchUsers d b s).2 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0) + + (if (z i).val = (switchUsers d b s).2 ∧ (switchUsers d b s).1 ∈ priorPaths o (i.val+1) + then (1:ℝ) else 0)) := by + classical + rw [terminalCharge_sum _ _ _ _ (Finset.notMem_erase _ _)] + apply Finset.sum_congr rfl + intro s _ + have hn := switchUsers_ne d b s + simp only [Finset.mem_erase] + by_cases h₁ : (z i).val = (switchUsers d b s).1 <;> + by_cases h₂ : (z i).val = (switchUsers d b s).2 <;> simp_all [eq_comm] + +lemma rotationMeeting_eq_slot_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (z : Terminal o) (u v : Card d) : + rotationMeeting o z u v = ∑ i : Fin A, + ((if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) + + (if (z i).val = v ∧ u ∈ priorPaths o (i.val+1) then (1:ℝ) else 0)) := by + classical + have only_owner (u : Card d) (a : Fin A) (hou : o u = some a) + (i : Fin A) (hia : i ≠ a) : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + exact hia (Option.some.inj hi).symm + have sum_one (u v : Card d) (a : Fin A) (hou : o u = some a) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = + if (z a).val = u ∧ v ∈ priorPaths o (a.val+1) then 1 else 0 := by + apply Finset.sum_eq_single a + · intro i _ hia + simp [only_owner u a hou i hia] + · simp + have sum_none (u v : Card d) (hou : o u = none) : + (∑ i : Fin A, if (z i).val = u ∧ v ∈ priorPaths o (i.val+1) then (1:ℝ) else 0) = 0 := by + apply Finset.sum_eq_zero + intro i _ + have hn : (z i).val ≠ u := by + intro h + have hi := (z i).property + rw [h,hou] at hi + contradiction + simp [hn] + rw [Finset.sum_add_distrib] + cases hou : o u with + | none => + rw [sum_none u v hou] + simp [rotationMeeting,hou,mem_priorPaths] + | some a => + rw [sum_one u v a hou] + cases hov : o v with + | none => + rw [sum_none v u hov] + simp [rotationMeeting,hou,hov,mem_priorPaths] + | some b => + rw [sum_one v u b hov] + simp only [rotationMeeting,hou,hov,mem_priorPaths,Option.some.injEq] + rcases lt_trichotomy a b with hab | rfl | hba + · have hn : ¬ b.val < a.val+1 := by omega + have hy : a.val < b.val+1 := by omega + simp [hab,hn,hy] + · simp + · have hn : ¬ a.val < b.val+1 := by omega + have hy : b.val < a.val+1 := by omega + simp [hba,not_lt_of_ge (le_of_lt hba),hn,hy] + +lemma rotationCharge_eq_terminal_sum {d A : ℕ} (o : Card d → Option (Fin A)) + (b : Butterfly d) (z : Terminal o) : + rotationCharge o b z = ∑ i : Fin A, + (terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) : ℝ) := by + simp only [rotationCharge,rotationMeeting_eq_slot_sum,terminalCharge_prior_sum] + exact Finset.sum_comm + +@[simp] lemma priorPaths_zero {d A : ℕ} (o : Card d → Option (Fin A)) : priorPaths o 0 = ∅ := by + classical + ext x + simp + +lemma priorPaths_succ {d A : ℕ} (o : Card d → Option (Fin A)) (t : ℕ) (ht : t < A) : + priorPaths o (t+1) = priorPaths o t ∪ cycleFiber o ⟨t,ht⟩ := by + classical + ext x + simp only [mem_priorPaths,Finset.mem_union,mem_cycleFiber] + constructor + · rintro ⟨i,hi,hit⟩ + by_cases h : i.val < t + · exact Or.inl ⟨i,hi,h⟩ + · have he : i = ⟨t,ht⟩ := Fin.ext (by change i.val = t; omega) + exact Or.inr (he ▸ hi) + · rintro (⟨i,hi,hit⟩ | hi) + · exact ⟨i,hi,by omega⟩ + · exact ⟨⟨t,ht⟩,hi,by change t < t+1; omega⟩ + +lemma priorPaths_disjoint {d A : ℕ} (o : Card d → Option (Fin A)) (i : Fin A) : + Disjoint (priorPaths o i.val) (cycleFiber o i) := by + classical + apply Finset.disjoint_left.mpr + intro x hx hx' + obtain ⟨j,hj,hji⟩ := (mem_priorPaths _ _ _).mp hx + have he : j = i := Option.some.inj (hj.symm.trans ((mem_cycleFiber _ _ _).mp hx')) + subst j + exact (lt_irrefl _ hji) + +namespace QueryTree + +lemma seekCycles_owned {d A : ℕ} (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) (z : Terminal o) (ω : SwitchIndex d → Bool) + (hS : ∀ i, cycleFiber o i ⊆ S) + (hO : ∀ i, orbitSet (butterflyPerm d (decodeButterfly d ω)) (z i).val = cycleFiber o i) + (hC : ∀ i, (cycleFiber o i).card = r i+1) : + let p := butterflyPerm d (decodeButterfly d ω) + let L := List.ofFn (fun i : Fin A => (p (z i).val,r i)) + (seekCycles d S L ∅).succeeds ω = true ∧ + ((seekCycles d S L ∅).staleCharge ∅ ω : ℝ) = rotationCharge o (decodeButterfly d ω) z := by + classical + let b := decodeButterfly d ω + let p := butterflyPerm d b + let f (i : Fin A) := (p (z i).val,r i) + let c (i : Fin A) : ℝ := terminalCharge d b (z i).val ((priorPaths o (i.val+1)).erase (z i).val) + have hc (i : Fin A) : Function.minimalPeriod p (z i).val - 1 = r i := by + have he := orbitSet_card p (z i).val + rw [hO,hC] at he + omega + have hs (t : ℕ) (ht : t ≤ A) : + (seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).succeeds ω = true ∧ + ((seekCycles d S ((List.ofFn f).drop t) (priorPaths o t)).staleCharge (exposedPaths d b (priorPaths o t)) ω : ℝ) = + ((List.ofFn c).drop t).sum := by + induction ht using Nat.decreasingInduction with + | self => simp only [List.length_ofFn,le_refl,List.drop_eq_nil_of_le,List.sum_nil,seekCycles,succeeds,staleCharge,Nat.cast_zero,and_self] + | of_succ t ht ih => + have htf : t < (List.ofFn f).length := by simpa using ht + have htc : t < (List.ofFn c).length := by simpa using ht + rw [List.drop_eq_getElem_cons htf,List.drop_eq_getElem_cons htc] + simp only [List.getElem_ofFn,List.sum_cons,seekCycles] + have h := seekCycle_orbit d S (priorPaths o t) (z ⟨t,ht⟩).val + (fun V => seekCycles d S ((List.ofFn f).drop (t+1)) V) ω + (by rw [hO]; exact hS _) (by rw [hO]; exact priorPaths_disjoint o ⟨t,ht⟩) + dsimp only at h + rw [hc,hO,←priorPaths_succ o t ht] at h + dsimp only [f] + constructor + · exact h.1.trans ih.1 + · rw [h.2,Nat.cast_add,ih.2] + exact add_comm _ _ + have h := hs 0 (Nat.zero_le _) + simp only [List.drop_zero,priorPaths_zero,exposedPaths_empty,List.sum_ofFn] at h + dsimp only + exact ⟨h.1,h.2.trans (rotationCharge_eq_terminal_sum o b z).symm⟩ + +end QueryTree + +section Collections +variable {d A : ℕ} + +def ValidCycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) + (o : Card d → Option (Fin A)) : Prop := + (∀ i, (cycleFiber o i).card = r i + 1) ∧ + (∀ i, cycleFiber o i ⊆ S) ∧ + (∀ i x, o x = some i → orbitSet p x = cycleFiber o i) + +abbrev CycleSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {o : Card d → Option (Fin A) // ValidCycleSlots p S r o} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (CycleSlots p S r) := Fintype.ofFinite _ + +lemma CycleSlots.terminal_nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := by + have hn : (cycleFiber c.val i).Nonempty := Finset.card_pos.mp (by rw [c.property.1]; omega) + obtain ⟨x,hx⟩ := hn + exact ⟨x,(mem_cycleFiber _ _ _).mp hx⟩ + +lemma owner_ext {o o' : Card d → Option (Fin A)} + (h : ∀ i, cycleFiber o i = cycleFiber o' i) : o = o' := by + funext x + have he (i : Fin A) : o x = some i ↔ o' x = some i := by + simpa only [mem_cycleFiber] using (Finset.ext_iff.mp (h i) x) + cases ho : o x with + | some i => exact ((he i).mp ho).symm + | none => + cases ho' : o' x with + | none => rfl + | some i => have hn := (he i).mpr ho'; rw [ho] at hn; contradiction + +abbrev RootedSlots (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + Σ c : CycleSlots p S r, Terminal c.val + +noncomputable def rootedStart {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : RootedSlots p S r) : Fin A → S := fun i => + ⟨p (c.2 i).val,c.1.property.2.1 i (by + rw [←c.1.property.2.2 i (c.2 i).val (c.2 i).property] + exact (mem_orbitSet _ _ _).mpr (Equiv.Perm.SameCycle.apply_right (Equiv.Perm.SameCycle.refl p _)))⟩ + +lemma rootedStart_injective {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} : + Function.Injective (rootedStart (p:=p) (S:=S) (r:=r)) := by + rintro ⟨c,z⟩ ⟨c',z'⟩ h + have hz (i : Fin A) : (z i).val = (z' i).val := + p.injective (congrArg Subtype.val (congrFun h i)) + have hc : c = c' := Subtype.ext (owner_ext (fun i => by + rw [←c.property.2.2 i (z i).val (z i).property, + ←c'.property.2.2 i (z' i).val (z' i).property,hz])) + subst c' + have hzz : z = z' := funext (fun i => Subtype.ext (hz i)) + subst z' + rfl + +lemma sum_comp_injective_le {α β : Type*} [Fintype α] [Fintype β] + (e : α → β) (he : Function.Injective e) (f : β → ℝ) (hf : ∀ b, 0 ≤ f b) : + ∑ a, f (e a) ≤ ∑ b, f b := by + classical + calc + _ = ∑ b ∈ Finset.univ.image e, f b := (Finset.sum_image (fun _ _ _ _ h => he h)).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun b _ _ => hf b) + +lemma rooted_weight_sum_le (S : Finset (Card d)) (r : Fin A → ℕ) (ω : SwitchIndex d → Bool) : + (∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2)) ≤ + ∑ a : Fin A → S, + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 := by + classical + let p := butterflyPerm d (decodeButterfly d ω) + let g (a : Fin A → S) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have he (c : RootedSlots p S r) : + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) = + g (rootedStart c) := by + have hs := QueryTree.seekCycles_owned S r c.1.val c.2 ω c.1.property.2.1 + (fun i => c.1.property.2.2 i (c.2 i).val (c.2 i).property) c.1.property.1 + dsimp only at hs + unfold g + rw [ite_eq_left (show (QueryTree.seekCycles d S (List.ofFn (fun i => ((rootedStart c i).val,r i))) ∅).succeeds ω = true from hs.1)] + rw [← hs.2,neg_mul,Real.exp_neg,mul_comm (Real.log 2),Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rfl + simp_rw [he] + exact sum_comp_injective_le rootedStart rootedStart_injective g (fun a => by dsimp [g]; split_ifs <;> positivity) + +noncomputable def rotationLower (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + Real.exp (-Real.log 2 * ((A:ℝ)*d/2 + ∑ i : Fin A, Real.log (r i+1) / (2 * Real.log 2))) + +noncomputable def collectionWeight (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : ℝ := + ((2:ℝ)^d)^A * (∏ i : Fin A, (r i+1 : ℝ)) * rotationLower d r + +lemma collectionWeight_pos (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : 0 < collectionWeight d r := by + unfold collectionWeight rotationLower + positivity + +lemma collection_rotation_lower (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) + (ω : SwitchIndex d → Bool) (c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : + collectionWeight d r ≤ ∑ z : Terminal c.val, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := by + classical + let (i : Fin A) : Nonempty {x : Card d // c.val x = some i} := c.terminal_nonempty i + have hm : Monotone (fun i => (cycleFiber c.val i).card) := by + intro i j hij + dsimp only + rw [c.property.1,c.property.1] + exact Nat.add_le_add_right (hr hij) 1 + have hb := rotation_exp_bound hm (decodeButterfly d ω) + have hcard : (Fintype.card (Terminal c.val) : ℝ) = ∏ i : Fin A, (r i+1 : ℝ) := by + rw [Fintype.card_pi,Nat.cast_prod] + apply Finset.prod_congr rfl + intro i _ + rw [card_cycleFiber,c.property.1,Nat.cast_add,Nat.cast_one] + have hp : (0:ℝ) < Fintype.card (Terminal c.val) := Nat.cast_pos.mpr Fintype.card_pos + have hl : rotationLower d r ≤ finiteMean (fun z : Terminal c.val => Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z)) := by + simpa only [rotationLower,c.property.1,Nat.cast_add,Nat.cast_one] using hb + have hh := (le_div_iff₀ hp).mp hl + rw [hcard] at hh + unfold collectionWeight + rw [← Finset.mul_sum] + calc + _ = ((2:ℝ)^d)^A * (rotationLower d r * ∏ i : Fin A, (r i+1 : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hh (by positivity) + +lemma cycleSlots_weighted_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) * + collectionWeight d r ≤ (S.card : ℝ)^A := by + classical + let g (a : Fin A → S) (ω : SwitchIndex d → Bool) : ℝ := + if (QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).succeeds ω then + ((2:ℝ)^d)^A / (2:ℝ)^(QueryTree.seekCycles d S (List.ofFn (fun i => ((a i).val,r i))) ∅).staleCharge ∅ ω + else 0 + have hω (ω : SwitchIndex d → Bool) : + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ) * collectionWeight d r ≤ + ∑ a : Fin A → S, g a ω := by + calc + _ = ∑ _c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, collectionWeight d r := by simp + _ ≤ ∑ c : CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ∑ z : Terminal c.val, ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.val (decodeButterfly d ω) z) := + Finset.sum_le_sum (fun c _ => collection_rotation_lower S r hr ω c) + _ = ∑ c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r, + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2) := + (Fintype.sum_sigma (fun c : RootedSlots (butterflyPerm d (decodeButterfly d ω)) S r => + ((2:ℝ)^d)^A * Real.exp (-Real.log 2 * rotationCharge c.1.val (decodeButterfly d ω) c.2))).symm + _ ≤ _ := rooted_weight_sum_le S r ω + have hb := finiteMean_mono hω + rw [finiteMean_mul_const,finiteMean_sum] at hb + calc + _ ≤ ∑ a : Fin A → S, finiteMean (g a) := hb + _ ≤ ∑ _a : Fin A → S, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + have hh := QueryTree.cycles_weighted_success d S (List.ofFn (fun i : Fin A => ((a i).val,r i))) + simpa only [List.length_ofFn] using hh + _ = _ := by simp + +lemma cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + (S.card : ℝ)^A / collectionWeight d r := by + exact (le_div_iff₀ (collectionWeight_pos d r)).mpr (cycleSlots_weighted_moment S r hr) + +lemma collectionWeight_eq_sqrt (d : ℕ) {A : ℕ} (r : Fin A → ℕ) : + collectionWeight d r = (Real.sqrt ((2:ℝ)^d))^A * ∏ i : Fin A, Real.sqrt (r i+1) := by + have hn : ((2:ℝ)^d)^A = Real.exp ((A:ℝ)*d*Real.log 2) := by + rw [mul_assoc,Real.exp_nat_mul,Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + have hp : (∏ i : Fin A, (r i+1 : ℝ)) = Real.exp (∑ i : Fin A, Real.log (r i+1)) := by + rw [Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + exact (Real.exp_log (by positivity)).symm + have hs : Real.sqrt ((2:ℝ)^d) = Real.exp ((d:ℝ)*Real.log 2/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity),Real.log_pow] + congr 1 + ring + have hj (i : Fin A) : Real.sqrt (r i+1) = Real.exp (Real.log (r i+1)/2) := by + rw [Real.sqrt_eq_rpow,Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + simp_rw [collectionWeight,hn,hp,rotationLower,hs,hj] + rw [←Real.exp_add,←Real.exp_add,←Real.exp_nat_mul,←Real.exp_sum,←Real.exp_add] + congr 1 + rw [←Finset.sum_div,←Finset.sum_div] + have hl : Real.log 2 ≠ 0 := ne_of_gt (Real.log_pos (by norm_num)) + field_simp + ring + +lemma butterfly_cycleSlots_moment (S : Finset (Card d)) (r : Fin A → ℕ) (hr : Monotone r) : + finiteMean (fun ω : SwitchIndex d → Bool => + (Fintype.card (CycleSlots (butterflyPerm d (decodeButterfly d ω)) S r) : ℝ)) ≤ + ((S.card : ℝ) / Real.sqrt ((2:ℝ)^d))^A * + ∏ i : Fin A, (1 / Real.sqrt (r i+1)) := by + have h := cycleSlots_moment S r hr + rw [collectionWeight_eq_sqrt,div_mul_eq_div_mul_one_div] at h + rw [div_pow] + simpa only [one_div,Finset.prod_inv_distrib] using h + +end Collections + +variable {d A : ℕ} + +abbrev SelectedCycle (p : Equiv.Perm (Card d)) (S : Finset (Card d)) := + {C : Finset (Card d) // (∃ x, C = orbitSet p x) ∧ C ⊆ S} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) : + Fintype (SelectedCycle p S) := Fintype.ofFinite _ + +lemma SelectedCycle.nonempty {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) : C.val.Nonempty := by + obtain ⟨x,hx⟩ := C.property.1 + rw [hx] + exact orbitSet_nonempty p x + +lemma SelectedCycle.orbit_eq {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C : SelectedCycle p S) {x : Card d} (hx : x ∈ C.val) : orbitSet p x = C.val := by + obtain ⟨y,hy⟩ := C.property.1 + rw [hy] at hx ⊢ + exact (orbitSet_eq p ((mem_orbitSet _ _ _).mp hx)).symm + +lemma SelectedCycle.eq_of_mem {p : Equiv.Perm (Card d)} {S : Finset (Card d)} + (C D : SelectedCycle p S) {x : Card d} (hC : x ∈ C.val) (hD : x ∈ D.val) : C = D := by + apply Subtype.ext + exact (C.orbit_eq hC).symm.trans (D.orbit_eq hD) + +abbrev SlotAssignment (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) := + {f : Fin A → SelectedCycle p S // Function.Injective f ∧ ∀ i, (f i).val.card = r i+1} + +noncomputable instance (p : Equiv.Perm (Card d)) (S : Finset (Card d)) (r : Fin A → ℕ) : + Fintype (SlotAssignment p S r) := Fintype.ofFinite _ + +noncomputable def slotsToAssignment {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (c : CycleSlots p S r) : SlotAssignment p S r := by + classical + let f (i : Fin A) : SelectedCycle p S := ⟨cycleFiber c.val i,by + obtain ⟨x,hx⟩ := c.terminal_nonempty i + exact ⟨⟨x,(c.property.2.2 i x hx).symm⟩,c.property.2.1 i⟩⟩ + refine ⟨f,?_,fun i => c.property.1 i⟩ + intro i j hij + have he : cycleFiber c.val i = cycleFiber c.val j := congrArg Subtype.val hij + obtain ⟨x,hx⟩ := c.terminal_nonempty i + have hxi : x ∈ cycleFiber c.val i := (mem_cycleFiber _ _ _).mpr hx + rw [he] at hxi + exact Option.some.inj (hx.symm.trans ((mem_cycleFiber _ _ _).mp hxi)) + +noncomputable def assignmentOwner {p : Equiv.Perm (Card d)} {S : Finset (Card d)} {r : Fin A → ℕ} + (f : SlotAssignment p S r) (x : Card d) : Option (Fin A) := by + classical + exact if h : ∃ i, x ∈ (f.val i).val then some (Classical.choose h) else none + +end Thorp + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/ShapePartitionEquiv.lean b/lean/OAI/Probability/ThorpRouting/Tail/ShapePartitionEquiv.lean index 4090d6d2144c9e44d7ea86a8445a93c7a9905aaf..786acb094fab0bfdc8678847d8444fe265ab1549 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/ShapePartitionEquiv.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/ShapePartitionEquiv.lean @@ -1,875 +1,875 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ModifiedReverseEquiv - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where - toFun μ := { parts := μ.1.rowLens - parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) - parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } - invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ - left_inv μ := by - apply Subtype.ext - obtain ⟨μ,rfl⟩ := μ - exact partitionDiagram_diagramPartition μ - right_inv p := by - apply Nat.Partition.ext - change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts - rw [partitionDiagram_rowLens,Multiset.sort_eq] - -noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm - -noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : - ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := - Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) - -lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : - Function.Injective (conjugacyPartition (α := α)) := by - intro p q - induction p using Quotient.inductionOn with | _ p => - induction q using Quotient.inductionOn with | _ q => - intro h - exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) - -lemma card_conjugacy_le_shapes (N : ℕ) : - Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by - have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) - simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h - -noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := - (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) - -noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : - Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := - (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom - -lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : - Representation.IsIrreducible (labelledRepresentation μ) := by - let e := (labels μ).symm.permCongrHom - let ρ := representation μ.1 - have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by - intro h - have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ - (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial - exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) - refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } - intro U - let U' : Subrepresentation ρ := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun p v hv => by - have hh := U.apply_mem_toSubmodule (e.symm p) hv - change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh - simpa using hh } - have := representation_irreducible μ.1 - obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' - · left - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - · right - apply Subrepresentation.toSubmodule_injective - exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h - -lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) - (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by - apply Subtype.ext - apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv - intro p v - have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v - change T.toLinearEquiv - (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = - representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh - have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by - apply Equiv.ext - intro x - simp [Equiv.permCongr_apply] - rw [hp] at hh - convert hh using 2 - congr 1 - -end Thorp.Specht - -namespace Thorp.FiniteCharacters -open scoped BigOperators Classical - -section Group -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose -omit [Fintype G] in -lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := - (ConjClasses.exists_rep c).choose_spec - -variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := - fun c => ρ.character (classRep c) - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : - characterClass ρ (ConjClasses.mk g) = ρ.character g := by - have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) - obtain ⟨p,hp⟩ := isConj_iff.mp h - change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g - exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) - -noncomputable def characterDual (ρ : Representation ℂ G V) : - (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where - toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ - map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] - map_smul' a f := by - simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] - simp_rw [mul_assoc] - rw [←Finset.mul_sum] - ring - -lemma characterDual_characterClass (ρ : Representation ℂ G V) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : - characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by - exact_mod_cast (Nat.card_pos (α := G)).ne') - change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ - simp only [characterClass_mk] - exact Representation.char_orthonormal σ ρ - -end Group - -theorem complete_of_card_conjugacy_le - {G ι : Type*} [Group G] [Fintype G] [Fintype ι] - (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] - (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] - (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : - ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases hij : i=j - · subst j - simp only [ite_true] - exact ite_eq_left ⟨Representation.Equiv.refl _⟩ - · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij - exact (horth i j).trans (ite_eq_right hij) - · intro i - simpa using horth i i - have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - have hspan := hLI.span_eq_top_of_card_eq_finrank' heq - by_contra h - push Not at h - have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ - (characterDual σ).ker := by - apply Submodule.span_le.mpr - rintro f ⟨i,rfl⟩ - change characterDual σ (characterClass (ρ i)) = 0 - rw [characterDual_characterClass,ite_eq_right] - rintro ⟨T⟩ - exact (h i).false T.symm - rw [hspan] at hker - have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) - rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz - exact one_ne_zero hz - -end Thorp.FiniteCharacters - -namespace Thorp.Specht -open scoped Classical - -theorem labelled_complete {N : ℕ} - {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : - ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by - let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := - labelledRepresentation_irreducible μ - apply FiniteCharacters.complete_of_card_conjugacy_le - (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ - intro μ ν h ⟨T⟩ - exact h (labelledRepresentation_equiv_shapes μ ν T) - -end Thorp.Specht - -namespace Thorp.PermutationHilbert - -section -open scoped BigOperators ComplexConjugate Classical -open Complex - -variable {X : Type*} [Fintype X] - -noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := - LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p - -@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : - act p v x = v (p⁻¹ x) := rfl - -lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : - act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by - exact EuclideanSpace.piLpCongrLeft_single p x 1 - -lemma trace_projection (W : Submodule ℂ (H X)) : - ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by - classical - have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by - constructor - · intro x; exact (W.orthogonalProjectionOnto x).2 - · intro x hx; exact W.starProjection_eq_self_iff.mpr hx - have ht := hp.trace - rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht - simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, - EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, - OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht - -lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : - (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - classical - have hh := W.inner_starProjection_left_eq_right - (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) - have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := - W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 - rw [hf] at hh - rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh - simpa using hh.symm - -lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) - (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : - act p (W.starProjection v) = W.starProjection (act p v) := by - have hh := (act p).toLinearIsometry.map_starProjection W v - change act p (W.starProjection v) = - (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh - simpa only [hW] using hh - -lemma uniform_diagonal (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : - (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = - Module.finrank ℂ W := by - classical - have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - obtain ⟨p,hp,hW⟩ := htrans x y - subst y - rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] - have ht := trace_projection W - simp_rw [hh] at ht - have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = - (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht - simpa using hhreal - -theorem uncertainty (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (v : H X) (hv : v ∈ W) (x : X) : - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by - classical - have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by - rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, - EuclideanSpace.inner_single_left] - simp - have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v - rw [hh] at hc - have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by - nlinarith [norm_nonneg (v x),norm_nonneg v, - norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] - calc - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ - (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := - mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) - _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] - -end -open scoped BigOperators Classical - -variable {X : Type*} [Fintype X] - -lemma trace_projection_real (W : Submodule ℂ (H X)) : - ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by - have hh := trace_projection W - simp_rw [projection_diagonal] at hh - exact_mod_cast hh - -theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : - (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ - (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by - have he (x : X) (hx : x ∈ S) : - K.starProjection (EuclideanSpace.single x (1:ℂ)) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := by - apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) - intro v hv - exact W.starProjection_inner_eq_zero _ v (hKW hv) - have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ - (Module.finrank ℂ K:ℝ) := by - rw [←trace_projection_real K] - calc - _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by - apply Finset.sum_congr rfl - intro x hx - rw [he x hx] - _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) - have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) - rw [Finset.mul_sum] at hmul - simp_rw [uniform_diagonal W htrans] at hmul - simpa using hmul - -end Thorp.PermutationHilbert -namespace Thorp.Specht -open scoped BigOperators Classical - -lemma finrank_hilbertSpace (μ : YoungDiagram) : - Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := - (hilbertEquiv μ).finrank_map_eq (space μ) - -lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : - hilbertEquiv μ (tabloidRep μ p v) = - PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by - ext f - simp [hilbertEquiv,PermutationHilbert.act_apply] - -lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : - (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = - hilbertSpace μ := by - apply le_antisymm - · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ - exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ - · rintro _ ⟨w,hw,rfl⟩ - refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), - ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ - change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w - rw [←hilbert_action] - change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ - rw [←map_mul,mul_inv_cancel,map_one] - rfl - -lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : - ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by - obtain ⟨q,hq⟩ := f.2 - obtain ⟨r,hr⟩ := g.2 - refine ⟨r⁻¹*q, ?_⟩ - apply Subtype.ext - funext x - simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, - Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] - -lemma polytabloid_pairing (μ : YoungDiagram) : - pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by - have h := alternator_pairing μ (polytabloid μ) - have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = - permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := - action_alternator_apply (colGroup μ) (tabloidRep μ) c _ - have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h - simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, - Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb - simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb - exact hb.symm - -lemma polytabloid_norm_sq (μ : YoungDiagram) : - ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by - have hp := polytabloid_pairing μ - change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp - rw [inner_self_eq_norm_sq_to_K] at hp - have hre := congrArg Complex.re hp - simpa [pow_two] using hre - -theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : - Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht - (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) - have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ - rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu - exact_mod_cast hu - - -section FiberGroup -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -noncomputable def fiberGroupEquiv (f : α → β) : - fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where - toFun p b := - { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ - invFun x := ⟨p.1⁻¹ x.1, by - have hh := p.2 (p.1⁻¹ x.1) - simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh - exact hh.symm.trans x.2⟩ - left_inv x := by apply Subtype.ext; simp - right_inv x := by apply Subtype.ext; simp } - invFun q := - ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), - fun x => (q (f x) ⟨x,rfl⟩).2⟩ - left_inv p := by - apply Subtype.ext - apply Equiv.ext - intro x - rfl - right_inv q := by - funext b - apply Equiv.ext - intro x - apply Subtype.ext - change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 - cases x with - | mk x hx => dsimp only at *; subst b; rfl - -lemma nat_card_fiberGroup (f : α → β) : - Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by - rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] - simp only [Nat.card_eq_fintype_card,Fintype.card_perm] - -omit [Fintype β] [Fintype γ] in - -lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) - (hinj : ∀ x y, f x = f y → g x = g y → x=y) : - Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by - have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by - intro p q hpq - dsimp only at hpq - have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by - apply inv_mul_eq_iff_eq_mul.mpr - rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] - have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 - have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) - have h1 : p.1.1⁻¹*q.1.1 = 1 := by - apply Equiv.ext - intro x - exact hinj _ x (hf x) (hg x) - have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) - have hpg : p.2=q.2 := by - apply Subtype.ext - have hh := hpq - rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh - exact mul_left_cancel hh - exact Prod.ext hpf hpg - have hc := Fintype.card_le_of_injective _ hi - simpa only [Fintype.card_prod,Fintype.card_perm] using hc - -end FiberGroup - -noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := - fiberGroup (rowIndex (μ := μ)) - -noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := - ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ - -lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by - ext p - constructor - · intro hp x; exact Fin.ext (hp x) - · intro hp x; exact congrArg Fin.val (hp x) - -noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where - smul p f := tabloidAct p f - one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl - mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl - -lemma tabloid_orbit_all (μ : YoungDiagram) : - MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by - ext f - simp only [Set.mem_univ,iff_true] - obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f - exact ⟨p,hp⟩ - -lemma tabloid_stabilizer (μ : YoungDiagram) : - MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by - ext p - change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x - constructor - · intro h x - have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h - simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm - · intro h - apply Subtype.ext - funext x - exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) - -lemma card_tabloid_mul_row (μ : YoungDiagram) : - Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by - have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group - (Equiv.Perm (Cell μ)) (baseTabloid μ) - have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = - Fintype.card (Tabloid μ) := by - rw [tabloid_orbit_all,Fintype.card_setUniv] - simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh - -theorem factorial_le_dimension_row_column (μ : YoungDiagram) : - μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by - rw [←card_tabloid_mul_row] - nlinarith [dimension_times_column_ge_tabloids μ] - - -lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by - let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] - -lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by - let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := - Equiv.subtypeEquivRight (fun x => Fin.ext_iff) - rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] - -lemma card_rowGroup (μ : YoungDiagram) : - Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by - rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_row_fiber] - -lemma card_colGroup (μ : YoungDiagram) : - Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by - rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card,card_col_fiber] - -abbrev TailCell (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} - -lemma tail_card (μ : YoungDiagram) : Fintype.card (TailCell μ) = μ.card - μ.rowLen 0 := by - have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) - rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh - exact hh - -lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by - have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) - rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h - -noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - {x : TailCell μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where - toFun x := ⟨row x.1.1-1, by - have hx := row_lt_colLen x.1.1 - have hc : col x.1.1 = j := congrArg Fin.val x.2 - rw [hc] at hx - have hz := x.1.2 - omega⟩ - invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ - left_inv x := by - apply Subtype.ext - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · change row x.1.1 - 1 + 1 = row x.1.1 - have := x.1.2 - omega - · exact (congrArg Fin.val x.2).symm - right_inv i := by apply Fin.ext; simp [row] - -lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : - Fintype.card {x : TailCell μ // colIndex x.1 = j} = μ.colLen j-1 := by - rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] - -lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : - Fintype.card {x : TailCell μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by - by_cases hi : i.val=0 - · rw [ite_eq_left hi] - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun x => x.1.2 ?_⟩ - exact (congrArg Fin.val x.2).trans hi - · rw [ite_eq_right hi] - let e : {x : TailCell μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := - { toFun := fun x => ⟨x.1.1,x.2⟩ - invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ - left_inv := fun x => rfl - right_inv := fun x => rfl } - rw [Fintype.card_congr e,card_row_fiber] - -lemma tail_row_group (μ : YoungDiagram) : - (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) = - Fintype.card (rowGroup μ) := by - rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : TailCell μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_row] - by_cases hn : μ.colLen 0=0 - · have hr : μ.rowLen 0=0 := by - by_contra h - have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) - have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem - omega - let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ - simp [hr] - · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ - have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] - simp only [hz] - have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = - ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by - rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] - simp only [ite_true,Nat.factorial_zero,mul_one] - apply Finset.prod_congr rfl - intro x hx - rw [ite_eq_right (Finset.mem_erase.mp hx).1] - rw [hprod] - exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) - -lemma sum_tail_columns (μ : YoungDiagram) : - ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by - simp_rw [←card_tail_col] - rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : TailCell μ => colIndex x.1)),tail_card] - -lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := - YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) - -lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num - | succ n ih => rw [pow_succ]; omega - -lemma column_group_le_tail (μ : YoungDiagram) : - Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * - Fintype.card (fiberGroup (fun x : TailCell μ => colIndex x.1)) := by - rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : TailCell μ => colIndex x.1)),nat_card_fiberGroup] - simp only [Nat.card_eq_fintype_card] - simp only [card_tail_col] - calc - _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by - apply Finset.prod_congr rfl - intro j hj - exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm - _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by - apply Finset.prod_le_prod - intro j hj - exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) - _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] - -theorem choose_tail_le_dimension (μ : YoungDiagram) : - μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - have htail := card_fiberGroups_mul_le - (fun x : TailCell μ => rowIndex x.1) (fun x : TailCell μ => colIndex x.1) - (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) - rw [tail_card] at htail - have hc := column_group_le_tail μ - have hr := tail_row_group μ - have hd := factorial_le_dimension_row_column μ - simp only [←Nat.card_eq_fintype_card] at htail hc hr hd - have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * - ((μ.rowLen 0).factorial * j.factorial) := by - calc - _ ≤ _ := hd - _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * - (2^j * Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc - _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * - (Nat.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) * - Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := by rw [←hr]; ring - _ ≤ _ := by - calc - _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := - Nat.mul_le_mul_left _ htail - _ = _ := by ring - have hj : j ≤ μ.card := Nat.sub_le _ _ - have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega - have hf := Nat.choose_mul_factorial_mul_factorial hj - rw [hs] at hf - rw [←hf] at hh - have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) - nlinarith - - -lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : - ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by - let e : s ≃ t := Finset.equivOfCardEq hc - let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by - simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) - let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) - refine ⟨p,fun x => ?_⟩ - by_cases hx : x ∈ s - · have hp : p x ∈ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t - rw [Equiv.sumCompl_symm_apply_of_pos hx] - exact (e ⟨x,hx⟩).2 - exact iff_of_true hp hx - · have hp : p x ∉ t := by - change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t - rw [Equiv.sumCompl_symm_apply_of_neg hx] - exact (ec ⟨x,hx⟩).2 - exact iff_of_false hp hx - -noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := - Finset.univ.filter (fun x => (f.1 x).val ≠ 0) - -@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : - x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] - -lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : - tailSet (tabloidAct p f) = (tailSet f).image p := by - ext x - simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] - constructor - · intro h; exact ⟨p⁻¹ x,h,by simp⟩ - · rintro ⟨y,hy,rfl⟩; simpa using hy - -lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : - (tailSet f).card = μ.card-μ.rowLen 0 := by - obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f - rw [tailSet_act,Finset.card_image_of_injective _ p.injective] - change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ - rw [←Fintype.card_subtype] - exact tail_card μ - -noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := - Finset.univ.filter (fun f => tailSet f ⊆ A) - -lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by - obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst - have he : s.image p=t := by - ext x - constructor - · intro hx - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx - exact (hp y).mpr hy - · intro hx - exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ - apply Finset.card_equiv (tabloidAct p) - intro f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] - exact (Finset.image_inj p.injective).symm - -lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : - (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = - Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by - let j := μ.card-μ.rowLen 0 - let s := tailSet (baseTabloid μ) - let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card - have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : - (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := - tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) - have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by - have h := Finset.sum_card_fiberwise_eq_card_filter - (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet - have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by - ext f - simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, - card_tailSet,footprint] - simp [j] - rw [he] at h - rw [←h] - calc - _ = ∑ _t ∈ A.powersetCard j, c := by - apply Finset.sum_congr rfl - intro t ht - exact hconstant t (Finset.mem_powersetCard.mp ht).2 - _ = _ := by simp [Finset.card_powersetCard] - have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by - simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] - have hN := hcount Finset.univ - rw [hfull,Finset.card_univ,card_cell] at hN - rw [hcount,hN] - ring - -lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) - (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) - (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by - have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 - apply Subtype.ext - funext x - change f.1 (p⁻¹ x) = f.1 x - by_cases hx : x ∈ A - · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] - · have hy : p⁻¹ x ∉ A := by - intro h - have hh := hp (p⁻¹ x) h - have he : x=p⁻¹ x := by simpa using hh - exact hx (he ▸ h) - apply Fin.ext - have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) - have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) - exact hy0.trans hx0.symm - -noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : - Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where - carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), - (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} - zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ - add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by - rw [map_add,hv.2 p hp,hw.2 p hp]⟩ - smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by - rw [map_smul,hv.2 p hp]⟩ - -lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := - fun _ hv => hv.1 - -theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : - Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ - Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by - let : DecidableEq (Tabloid μ) := Classical.decEq _ - have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ - (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by - obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g - exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ - have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : - (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by - refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ - rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), - PermutationHilbert.act_single,footprint_fixed A f hf p hp] - have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) - (fixedHilbert_le μ A) ht (footprint μ A) hproj - rw [finrank_hilbertSpace] at h - have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ - Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h - have hc := footprint_card_product μ A - have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ - have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn - nlinarith - -end Thorp.Specht - -namespace Thorp.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -def IsUnitary (ρ : Representation ℂ G V) : Prop := - ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : - inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by - have h := hρ g v (ρ g⁻¹ w) - have he : ρ g (ρ g⁻¹ w) = w := by - change (ρ g * ρ g⁻¹) w = w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [he] at h - exact h.symm - -noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where - toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) - isIntertwining' h := by - ext v - simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] - have hh (w : W) : σ h (σ h⁻¹ w)=w := by - change (σ h*σ h⁻¹) w=w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [hh] - -end Thorp.UnitaryFinite - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ModifiedReverseEquiv + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def shapePartitionEquiv (N : ℕ) : Shapes N ≃ Nat.Partition N where + toFun μ := { parts := μ.1.rowLens + parts_pos := fun {i} hi => μ.1.pos_of_mem_rowLens i (by simpa using hi) + parts_sum := by simpa using (sum_rowLens μ.1).trans μ.2 } + invFun p := ⟨partitionDiagram p,partitionDiagram_card p⟩ + left_inv μ := by + apply Subtype.ext + obtain ⟨μ,rfl⟩ := μ + exact partitionDiagram_diagramPartition μ + right_inv p := by + apply Nat.Partition.ext + change ((partitionDiagram p).rowLens : Multiset ℕ) = p.parts + rw [partitionDiagram_rowLens,Multiset.sort_eq] + +noncomputable instance (N : ℕ) : Fintype (Shapes N) := Fintype.ofEquiv _ (shapePartitionEquiv N).symm + +noncomputable def conjugacyPartition {α : Type*} [Fintype α] [DecidableEq α] : + ConjClasses (Equiv.Perm α) → Nat.Partition (Fintype.card α) := + Quotient.lift Equiv.Perm.partition (fun _ _ hpq => (Equiv.Perm.partition_eq_of_isConj).mp hpq) + +lemma conjugacyPartition_injective {α : Type*} [Fintype α] [DecidableEq α] : + Function.Injective (conjugacyPartition (α := α)) := by + intro p q + induction p using Quotient.inductionOn with | _ p => + induction q using Quotient.inductionOn with | _ q => + intro h + exact Quotient.sound ((Equiv.Perm.partition_eq_of_isConj).mpr h) + +lemma card_conjugacy_le_shapes (N : ℕ) : + Nat.card (ConjClasses (Equiv.Perm (Fin N))) ≤ Fintype.card (Shapes N) := by + have h := Nat.card_le_card_of_injective _ (conjugacyPartition_injective (α := Fin N)) + simpa only [Fintype.card_fin, Nat.card_eq_fintype_card, Fintype.card_congr (shapePartitionEquiv N)] using h + +noncomputable def labels {N : ℕ} (μ : Shapes N) : Cell μ.1 ≃ Fin N := + (Fintype.equivFin (Cell μ.1)).trans (finCongr ((card_cell μ.1).trans μ.2)) + +noncomputable def labelledRepresentation {N : ℕ} (μ : Shapes N) : + Representation ℂ (Equiv.Perm (Fin N)) (space μ.1) := + (representation μ.1).comp (labels μ).symm.permCongrHom.toMonoidHom + +lemma labelledRepresentation_irreducible {N : ℕ} (μ : Shapes N) : + Representation.IsIrreducible (labelledRepresentation μ) := by + let e := (labels μ).symm.permCongrHom + let ρ := representation μ.1 + have hn : (⊥ : Subrepresentation (labelledRepresentation μ)) ≠ ⊤ := by + intro h + have he : (⟨polytabloid μ.1,polytabloid_mem_space μ.1⟩ : space μ.1) ∈ + (⊥ : Subrepresentation (labelledRepresentation μ)) := by rw [h]; trivial + exact polytabloid_ne_zero μ.1 (congrArg Subtype.val he) + refine { exists_pair_ne := ⟨⊥,⊤,hn⟩,eq_bot_or_eq_top := ?_ } + intro U + let U' : Subrepresentation ρ := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun p v hv => by + have hh := U.apply_mem_toSubmodule (e.symm p) hv + change ρ (e (e.symm p)) v ∈ U.toSubmodule at hh + simpa using hh } + have := representation_irreducible μ.1 + obtain h | h := IsSimpleOrder.eq_bot_or_eq_top U' + · left + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + · right + apply Subrepresentation.toSubmodule_injective + exact congrArg (fun R : Subrepresentation ρ => R.toSubmodule) h + +lemma labelledRepresentation_equiv_shapes {N : ℕ} (μ ν : Shapes N) + (T : Representation.Equiv (labelledRepresentation μ) (labelledRepresentation ν)) : μ = ν := by + apply Subtype.ext + apply shapes_eq_of_equivariant_equiv μ.1 ν.1 ((labels μ).trans (labels ν).symm) T.toLinearEquiv + intro p v + have hh := Representation.IntertwiningMap.isIntertwining _ _ T.toIntertwiningMap ((labels μ).permCongr p) v + change T.toLinearEquiv + (representation μ.1 ((labels μ).symm.permCongr ((labels μ).permCongr p)) v) = + representation ν.1 ((labels ν).symm.permCongr ((labels μ).permCongr p)) (T.toLinearEquiv v) at hh + have hp : (labels μ).symm.permCongr ((labels μ).permCongr p) = p := by + apply Equiv.ext + intro x + simp [Equiv.permCongr_apply] + rw [hp] at hh + convert hh using 2 + congr 1 + +end Thorp.Specht + +namespace Thorp.FiniteCharacters +open scoped BigOperators Classical + +section Group +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose +omit [Fintype G] in +lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := + (ConjClasses.exists_rep c).choose_spec + +variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := + fun c => ρ.character (classRep c) + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : + characterClass ρ (ConjClasses.mk g) = ρ.character g := by + have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) + obtain ⟨p,hp⟩ := isConj_iff.mp h + change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g + exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) + +noncomputable def characterDual (ρ : Representation ℂ G V) : + (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where + toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ + map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] + map_smul' a f := by + simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] + simp_rw [mul_assoc] + rw [←Finset.mul_sum] + ring + +lemma characterDual_characterClass (ρ : Representation ℂ G V) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : + characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by + exact_mod_cast (Nat.card_pos (α := G)).ne') + change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ + simp only [characterClass_mk] + exact Representation.char_orthonormal σ ρ + +end Group + +theorem complete_of_card_conjugacy_le + {G ι : Type*} [Group G] [Fintype G] [Fintype ι] + (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] + (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] + (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : + ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases hij : i=j + · subst j + simp only [ite_true] + exact ite_eq_left ⟨Representation.Equiv.refl _⟩ + · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij + exact (horth i j).trans (ite_eq_right hij) + · intro i + simpa using horth i i + have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + have hspan := hLI.span_eq_top_of_card_eq_finrank' heq + by_contra h + push Not at h + have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ + (characterDual σ).ker := by + apply Submodule.span_le.mpr + rintro f ⟨i,rfl⟩ + change characterDual σ (characterClass (ρ i)) = 0 + rw [characterDual_characterClass,ite_eq_right] + rintro ⟨T⟩ + exact (h i).false T.symm + rw [hspan] at hker + have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) + rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz + exact one_ne_zero hz + +end Thorp.FiniteCharacters + +namespace Thorp.Specht +open scoped Classical + +theorem labelled_complete {N : ℕ} + {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (ρ : Representation ℂ (Equiv.Perm (Fin N)) V) [Representation.IsIrreducible ρ] : + ∃ μ : Shapes N, Nonempty (Representation.Equiv (labelledRepresentation μ) ρ) := by + let (μ : Shapes N) : Representation.IsIrreducible (labelledRepresentation μ) := + labelledRepresentation_irreducible μ + apply FiniteCharacters.complete_of_card_conjugacy_le + (fun μ : Shapes N => space μ.1) labelledRepresentation _ (card_conjugacy_le_shapes N) ρ + intro μ ν h ⟨T⟩ + exact h (labelledRepresentation_equiv_shapes μ ν T) + +end Thorp.Specht + +namespace Thorp.PermutationHilbert + +section +open scoped BigOperators ComplexConjugate Classical +open Complex + +variable {X : Type*} [Fintype X] + +noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p + +@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : + act p v x = v (p⁻¹ x) := rfl + +lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : + act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by + exact EuclideanSpace.piLpCongrLeft_single p x 1 + +lemma trace_projection (W : Submodule ℂ (H X)) : + ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by + classical + have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by + constructor + · intro x; exact (W.orthogonalProjectionOnto x).2 + · intro x hx; exact W.starProjection_eq_self_iff.mpr hx + have ht := hp.trace + rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht + simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, + EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, + OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht + +lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : + (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + classical + have hh := W.inner_starProjection_left_eq_right + (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) + have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := + W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 + rw [hf] at hh + rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh + simpa using hh.symm + +lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) + (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : + act p (W.starProjection v) = W.starProjection (act p v) := by + have hh := (act p).toLinearIsometry.map_starProjection W v + change act p (W.starProjection v) = + (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh + simpa only [hW] using hh + +lemma uniform_diagonal (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : + (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = + Module.finrank ℂ W := by + classical + have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + obtain ⟨p,hp,hW⟩ := htrans x y + subst y + rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] + have ht := trace_projection W + simp_rw [hh] at ht + have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = + (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht + simpa using hhreal + +theorem uncertainty (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (v : H X) (hv : v ∈ W) (x : X) : + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by + classical + have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by + rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, + EuclideanSpace.inner_single_left] + simp + have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v + rw [hh] at hc + have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by + nlinarith [norm_nonneg (v x),norm_nonneg v, + norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] + calc + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ + (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := + mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) + _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] + +end +open scoped BigOperators Classical + +variable {X : Type*} [Fintype X] + +lemma trace_projection_real (W : Submodule ℂ (H X)) : + ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by + have hh := trace_projection W + simp_rw [projection_diagonal] at hh + exact_mod_cast hh + +theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : + (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ + (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by + have he (x : X) (hx : x ∈ S) : + K.starProjection (EuclideanSpace.single x (1:ℂ)) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := by + apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) + intro v hv + exact W.starProjection_inner_eq_zero _ v (hKW hv) + have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ + (Module.finrank ℂ K:ℝ) := by + rw [←trace_projection_real K] + calc + _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by + apply Finset.sum_congr rfl + intro x hx + rw [he x hx] + _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) + have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) + rw [Finset.mul_sum] at hmul + simp_rw [uniform_diagonal W htrans] at hmul + simpa using hmul + +end Thorp.PermutationHilbert +namespace Thorp.Specht +open scoped BigOperators Classical + +lemma finrank_hilbertSpace (μ : YoungDiagram) : + Module.finrank ℂ (hilbertSpace μ) = Module.finrank ℂ (space μ) := + (hilbertEquiv μ).finrank_map_eq (space μ) + +lemma hilbert_action (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) (v : Tabloid μ → ℂ) : + hilbertEquiv μ (tabloidRep μ p v) = + PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ v) := by + ext f + simp [hilbertEquiv,PermutationHilbert.act_apply] + +lemma hilbertSpace_invariant (μ : YoungDiagram) (p : Equiv.Perm (Cell μ)) : + (hilbertSpace μ).map (PermutationHilbert.act (tabloidAct p)).toLinearEquiv.toLinearMap = + hilbertSpace μ := by + apply le_antisymm + · rintro _ ⟨v,⟨w,hw,rfl⟩,rfl⟩ + exact ⟨tabloidRep μ p w,action_mem_space μ p w hw,hilbert_action μ p w⟩ + · rintro _ ⟨w,hw,rfl⟩ + refine ⟨hilbertEquiv μ (tabloidRep μ p⁻¹ w), + ⟨tabloidRep μ p⁻¹ w,action_mem_space μ p⁻¹ w hw,rfl⟩, ?_⟩ + change PermutationHilbert.act (tabloidAct p) (hilbertEquiv μ (tabloidRep μ p⁻¹ w)) = hilbertEquiv μ w + rw [←hilbert_action] + change hilbertEquiv μ ((tabloidRep μ p * tabloidRep μ p⁻¹) w) = _ + rw [←map_mul,mul_inv_cancel,map_one] + rfl + +lemma tabloidAct_transitive (μ : YoungDiagram) (f g : Tabloid μ) : + ∃ p : Equiv.Perm (Cell μ), tabloidAct p f = g := by + obtain ⟨q,hq⟩ := f.2 + obtain ⟨r,hr⟩ := g.2 + refine ⟨r⁻¹*q, ?_⟩ + apply Subtype.ext + funext x + simp only [tabloidAct_apply,mul_inv_rev,Equiv.Perm.mul_apply,hq,hr, + Function.comp_apply,Equiv.Perm.inv_def,Equiv.apply_symm_apply,Equiv.symm_symm] + +lemma polytabloid_pairing (μ : YoungDiagram) : + pairing (polytabloid μ) (polytabloid μ) = Fintype.card (colGroup μ) := by + have h := alternator_pairing μ (polytabloid μ) + have he (c : colGroup μ) : tabloidRep μ c (polytabloid μ) = + permSign (c:Equiv.Perm (Cell μ)) • polytabloid μ := + action_alternator_apply (colGroup μ) (tabloidRep μ) c _ + have hb := congrArg (fun v : Tabloid μ → ℂ => v (baseTabloid μ)) h + simp only [alternator,LinearMap.sum_apply,LinearMap.smul_apply,he, + Pi.smul_apply,smul_eq_mul,Finset.sum_apply,polytabloid_base,mul_one] at hb + simp only [permSign_sq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb + exact hb.symm + +lemma polytabloid_norm_sq (μ : YoungDiagram) : + ‖hilbertEquiv μ (polytabloid μ)‖^2 = (Fintype.card (colGroup μ):ℝ) := by + have hp := polytabloid_pairing μ + change inner ℂ (hilbertEquiv μ (polytabloid μ)) (hilbertEquiv μ (polytabloid μ)) = _ at hp + rw [inner_self_eq_norm_sq_to_K] at hp + have hre := congrArg Complex.re hp + simpa [pow_two] using hre + +theorem dimension_times_column_ge_tabloids (μ : YoungDiagram) : + Fintype.card (Tabloid μ) ≤ Module.finrank ℂ (space μ) * Fintype.card (colGroup μ) := by + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f = g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hu := PermutationHilbert.uncertainty (hilbertSpace μ) ht + (hilbertEquiv μ (polytabloid μ)) ⟨polytabloid μ,polytabloid_mem_space μ,rfl⟩ (baseTabloid μ) + have he : hilbertEquiv μ (polytabloid μ) (baseTabloid μ) = 1 := polytabloid_base μ + rw [he,norm_one,one_pow,mul_one,finrank_hilbertSpace,polytabloid_norm_sq] at hu + exact_mod_cast hu + + +section FiberGroup +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +noncomputable def fiberGroupEquiv (f : α → β) : + fiberGroup f ≃ (∀ b, Equiv.Perm {x // f x = b}) where + toFun p b := + { toFun x := ⟨p.1 x.1,(p.2 x.1).trans x.2⟩ + invFun x := ⟨p.1⁻¹ x.1, by + have hh := p.2 (p.1⁻¹ x.1) + simp only [Equiv.Perm.inv_def,Equiv.apply_symm_apply] at hh + exact hh.symm.trans x.2⟩ + left_inv x := by apply Subtype.ext; simp + right_inv x := by apply Subtype.ext; simp } + invFun q := + ⟨(Equiv.sigmaFiberEquiv f).permCongr (Equiv.Perm.sigmaCongrRight q), + fun x => (q (f x) ⟨x,rfl⟩).2⟩ + left_inv p := by + apply Subtype.ext + apply Equiv.ext + intro x + rfl + right_inv q := by + funext b + apply Equiv.ext + intro x + apply Subtype.ext + change (q (f x.1) ⟨x.1,rfl⟩).1 = (q b x).1 + cases x with + | mk x hx => dsimp only at *; subst b; rfl + +lemma nat_card_fiberGroup (f : α → β) : + Nat.card (fiberGroup f) = ∏ b, (Nat.card {x // f x=b}).factorial := by + rw [Nat.card_congr (fiberGroupEquiv f),Nat.card_pi] + simp only [Nat.card_eq_fintype_card,Fintype.card_perm] + +omit [Fintype β] [Fintype γ] in + +lemma card_fiberGroups_mul_le (f : α → β) (g : α → γ) + (hinj : ∀ x y, f x = f y → g x = g y → x=y) : + Fintype.card (fiberGroup f) * Fintype.card (fiberGroup g) ≤ (Fintype.card α).factorial := by + have hi : Function.Injective (fun p : fiberGroup f × fiberGroup g => p.1.1*p.2.1) := by + intro p q hpq + dsimp only at hpq + have he : p.1.1⁻¹*q.1.1 = p.2.1*q.2.1⁻¹ := by + apply inv_mul_eq_iff_eq_mul.mpr + rw [←mul_assoc,hpq,mul_assoc,mul_inv_cancel,mul_one] + have hf : p.1.1⁻¹*q.1.1 ∈ fiberGroup f := (fiberGroup f).mul_mem ((fiberGroup f).inv_mem p.1.2) q.1.2 + have hg : p.1.1⁻¹*q.1.1 ∈ fiberGroup g := he ▸ (fiberGroup g).mul_mem p.2.2 ((fiberGroup g).inv_mem q.2.2) + have h1 : p.1.1⁻¹*q.1.1 = 1 := by + apply Equiv.ext + intro x + exact hinj _ x (hf x) (hg x) + have hpf : p.1=q.1 := Subtype.ext (inv_mul_eq_one.mp h1) + have hpg : p.2=q.2 := by + apply Subtype.ext + have hh := hpq + rw [show p.1.1=q.1.1 from congrArg Subtype.val hpf] at hh + exact mul_left_cancel hh + exact Prod.ext hpf hpg + have hc := Fintype.card_le_of_injective _ hi + simpa only [Fintype.card_prod,Fintype.card_perm] using hc + +end FiberGroup + +noncomputable def rowGroup (μ : YoungDiagram) : Subgroup (Equiv.Perm (Cell μ)) := + fiberGroup (rowIndex (μ := μ)) + +noncomputable def colIndex {μ : YoungDiagram} (x : Cell μ) : Fin (μ.rowLen 0) := + ⟨col x, (YoungDiagram.mem_iff_lt_rowLen.mp x.2).trans_le (μ.rowLen_anti 0 (row x) (Nat.zero_le _))⟩ + +lemma colGroup_eq (μ : YoungDiagram) : colGroup μ = fiberGroup (colIndex (μ := μ)) := by + ext p + constructor + · intro hp x; exact Fin.ext (hp x) + · intro hp x; exact congrArg Fin.val (hp x) + +noncomputable instance tabloidMulAction (μ : YoungDiagram) : MulAction (Equiv.Perm (Cell μ)) (Tabloid μ) where + smul p f := tabloidAct p f + one_smul f := by change tabloidAct 1 f = f; rw [tabloidAct_one]; rfl + mul_smul p q f := by change tabloidAct (p*q) f = tabloidAct p (tabloidAct q f); rw [tabloidAct_mul]; rfl + +lemma tabloid_orbit_all (μ : YoungDiagram) : + MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ) = Set.univ := by + ext f + simp only [Set.mem_univ,iff_true] + obtain ⟨p,hp⟩ := tabloidAct_transitive μ (baseTabloid μ) f + exact ⟨p,hp⟩ + +lemma tabloid_stabilizer (μ : YoungDiagram) : + MulAction.stabilizer (Equiv.Perm (Cell μ)) (baseTabloid μ) = rowGroup μ := by + ext p + change tabloidAct p (baseTabloid μ) = baseTabloid μ ↔ ∀ x, rowIndex (p x) = rowIndex x + constructor + · intro h x + have hh := congrArg (fun f : Tabloid μ => f.1 (p x)) h + simpa only [tabloidAct_apply,baseTabloid,Equiv.Perm.inv_def,Equiv.symm_apply_apply] using hh.symm + · intro h + apply Subtype.ext + funext x + exact (h (p⁻¹ x)).symm.trans (by simp [baseTabloid]) + +lemma card_tabloid_mul_row (μ : YoungDiagram) : + Fintype.card (Tabloid μ)*Fintype.card (rowGroup μ) = μ.card.factorial := by + have hh := MulAction.card_orbit_mul_card_stabilizer_eq_card_group + (Equiv.Perm (Cell μ)) (baseTabloid μ) + have hc : Fintype.card (MulAction.orbit (Equiv.Perm (Cell μ)) (baseTabloid μ)) = + Fintype.card (Tabloid μ) := by + rw [tabloid_orbit_all,Fintype.card_setUniv] + simpa only [hc,tabloid_stabilizer,Fintype.card_perm,card_cell] using hh + +theorem factorial_le_dimension_row_column (μ : YoungDiagram) : + μ.card.factorial ≤ Module.finrank ℂ (space μ)*Fintype.card (rowGroup μ)*Fintype.card (colGroup μ) := by + rw [←card_tabloid_mul_row] + nlinarith [dimension_times_column_ge_tabloids μ] + + +lemma card_row_fiber (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : Cell μ // rowIndex x = i} = μ.rowLen i := by + let e : {x : Cell μ // rowIndex x = i} ≃ {x : Cell μ // row x = i} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (rowEquiv μ i),Fintype.card_fin] + +lemma card_col_fiber (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : Cell μ // colIndex x = j} = μ.colLen j := by + let e : {x : Cell μ // colIndex x = j} ≃ {x : Cell μ // col x = j} := + Equiv.subtypeEquivRight (fun x => Fin.ext_iff) + rw [Fintype.card_congr e,Fintype.card_congr (columnEquiv μ j),Fintype.card_fin] + +lemma card_rowGroup (μ : YoungDiagram) : + Fintype.card (rowGroup μ) = ∏ i : Fin (μ.colLen 0), (μ.rowLen i).factorial := by + rw [←Nat.card_eq_fintype_card,rowGroup,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_row_fiber] + +lemma card_colGroup (μ : YoungDiagram) : + Fintype.card (colGroup μ) = ∏ j : Fin (μ.rowLen 0), (μ.colLen j).factorial := by + rw [←Nat.card_eq_fintype_card,colGroup_eq,nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card,card_col_fiber] + +abbrev TailCell (μ : YoungDiagram) := {x : Cell μ // row x ≠ 0} + +lemma tail_card (μ : YoungDiagram) : Fintype.card (TailCell μ) = μ.card - μ.rowLen 0 := by + have hh := Fintype.card_subtype_compl (p := fun x : Cell μ => row x=0) + rw [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at hh + exact hh + +lemma rowLen_zero_le_card (μ : YoungDiagram) : μ.rowLen 0 ≤ μ.card := by + have h := Fintype.card_subtype_le (fun x : Cell μ => row x=0) + rwa [Fintype.card_congr (rowEquiv μ 0),Fintype.card_fin,card_cell] at h + +noncomputable def tailColumnEquiv (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + {x : TailCell μ // colIndex x.1 = j} ≃ Fin (μ.colLen j-1) where + toFun x := ⟨row x.1.1-1, by + have hx := row_lt_colLen x.1.1 + have hc : col x.1.1 = j := congrArg Fin.val x.2 + rw [hc] at hx + have hz := x.1.2 + omega⟩ + invFun i := ⟨⟨⟨(i+1,j),YoungDiagram.mem_iff_lt_colLen.mpr (by omega)⟩,by simp [row]⟩,rfl⟩ + left_inv x := by + apply Subtype.ext + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · change row x.1.1 - 1 + 1 = row x.1.1 + have := x.1.2 + omega + · exact (congrArg Fin.val x.2).symm + right_inv i := by apply Fin.ext; simp [row] + +lemma card_tail_col (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : + Fintype.card {x : TailCell μ // colIndex x.1 = j} = μ.colLen j-1 := by + rw [Fintype.card_congr (tailColumnEquiv μ j),Fintype.card_fin] + +lemma card_tail_row (μ : YoungDiagram) (i : Fin (μ.colLen 0)) : + Fintype.card {x : TailCell μ // rowIndex x.1 = i} = if i.val=0 then 0 else μ.rowLen i := by + by_cases hi : i.val=0 + · rw [ite_eq_left hi] + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun x => x.1.2 ?_⟩ + exact (congrArg Fin.val x.2).trans hi + · rw [ite_eq_right hi] + let e : {x : TailCell μ // rowIndex x.1 = i} ≃ {x : Cell μ // rowIndex x=i} := + { toFun := fun x => ⟨x.1.1,x.2⟩ + invFun := fun x => ⟨⟨x.1,fun hz => hi ((congrArg Fin.val x.2).symm.trans hz)⟩,x.2⟩ + left_inv := fun x => rfl + right_inv := fun x => rfl } + rw [Fintype.card_congr e,card_row_fiber] + +lemma tail_row_group (μ : YoungDiagram) : + (μ.rowLen 0).factorial * Fintype.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) = + Fintype.card (rowGroup μ) := by + rw [←Nat.card_eq_fintype_card (α := fiberGroup (fun x : TailCell μ => rowIndex x.1)),nat_card_fiberGroup,card_rowGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_row] + by_cases hn : μ.colLen 0=0 + · have hr : μ.rowLen 0=0 := by + by_contra h + have hmem : (0,0) ∈ μ := YoungDiagram.mem_iff_lt_rowLen.mpr (Nat.pos_of_ne_zero h) + have hh := YoungDiagram.mem_iff_lt_colLen.mp hmem + omega + let : IsEmpty (Fin (μ.colLen 0)) := ⟨fun i => by have := i.isLt; omega⟩ + simp [hr] + · let z : Fin (μ.colLen 0) := ⟨0,Nat.pos_of_ne_zero hn⟩ + have hz : ∀ i : Fin (μ.colLen 0), i.val=0 ↔ i=z := fun i => by simp [z,Fin.ext_iff] + simp only [hz] + have hprod : (∏ x : Fin (μ.colLen 0), (if x=z then 0 else μ.rowLen x).factorial) = + ∏ x ∈ Finset.univ.erase z, (μ.rowLen x).factorial := by + rw [←Finset.prod_erase_mul Finset.univ (fun x : Fin (μ.colLen 0) => (if x=z then 0 else μ.rowLen x).factorial) (Finset.mem_univ z)] + simp only [ite_true,Nat.factorial_zero,mul_one] + apply Finset.prod_congr rfl + intro x hx + rw [ite_eq_right (Finset.mem_erase.mp hx).1] + rw [hprod] + exact Finset.mul_prod_erase Finset.univ (fun i : Fin (μ.colLen 0) => (μ.rowLen i).factorial) (Finset.mem_univ z) + +lemma sum_tail_columns (μ : YoungDiagram) : + ∑ j : Fin (μ.rowLen 0), (μ.colLen j-1) = μ.card-μ.rowLen 0 := by + simp_rw [←card_tail_col] + rw [←Fintype.card_sigma,Fintype.card_congr (Equiv.sigmaFiberEquiv (fun x : TailCell μ => colIndex x.1)),tail_card] + +lemma column_pos (μ : YoungDiagram) (j : Fin (μ.rowLen 0)) : 0 < μ.colLen j := + YoungDiagram.mem_iff_lt_colLen.mp (YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt) + +lemma nat_le_two_pow_pred (n : ℕ) (hn : 0 norm_num + | succ n ih => rw [pow_succ]; omega + +lemma column_group_le_tail (μ : YoungDiagram) : + Fintype.card (colGroup μ) ≤ 2^(μ.card-μ.rowLen 0) * + Fintype.card (fiberGroup (fun x : TailCell μ => colIndex x.1)) := by + rw [card_colGroup,←Nat.card_eq_fintype_card (α := fiberGroup (fun x : TailCell μ => colIndex x.1)),nat_card_fiberGroup] + simp only [Nat.card_eq_fintype_card] + simp only [card_tail_col] + calc + _ = ∏ j : Fin (μ.rowLen 0), μ.colLen j * (μ.colLen j-1).factorial := by + apply Finset.prod_congr rfl + intro j hj + exact (Nat.mul_factorial_pred (column_pos μ j).ne').symm + _ ≤ ∏ j : Fin (μ.rowLen 0), 2^(μ.colLen j-1) * (μ.colLen j-1).factorial := by + apply Finset.prod_le_prod + intro j hj + exact Nat.mul_le_mul_right _ (nat_le_two_pow_pred _ (column_pos μ j)) + _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum,sum_tail_columns] + +theorem choose_tail_le_dimension (μ : YoungDiagram) : + μ.card.choose (μ.card-μ.rowLen 0) ≤ Module.finrank ℂ (space μ) * 2^(μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + have htail := card_fiberGroups_mul_le + (fun x : TailCell μ => rowIndex x.1) (fun x : TailCell μ => colIndex x.1) + (fun x y hr hc => Subtype.ext (Subtype.ext (Prod.ext (congrArg Fin.val hr) (congrArg Fin.val hc)))) + rw [tail_card] at htail + have hc := column_group_le_tail μ + have hr := tail_row_group μ + have hd := factorial_le_dimension_row_column μ + simp only [←Nat.card_eq_fintype_card] at htail hc hr hd + have hh : μ.card.factorial ≤ Module.finrank ℂ (space μ) * 2^j * + ((μ.rowLen 0).factorial * j.factorial) := by + calc + _ ≤ _ := hd + _ ≤ Module.finrank ℂ (space μ) * Nat.card (rowGroup μ) * + (2^j * Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := Nat.mul_le_mul_left _ hc + _ = Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * + (Nat.card (fiberGroup (fun x : TailCell μ => rowIndex x.1)) * + Nat.card (fiberGroup (fun x : TailCell μ => colIndex x.1))) := by rw [←hr]; ring + _ ≤ _ := by + calc + _ ≤ Module.finrank ℂ (space μ) * 2^j * (μ.rowLen 0).factorial * j.factorial := + Nat.mul_le_mul_left _ htail + _ = _ := by ring + have hj : j ≤ μ.card := Nat.sub_le _ _ + have hs : μ.card-j = μ.rowLen 0 := by dsimp [j]; have := rowLen_zero_le_card μ; omega + have hf := Nat.choose_mul_factorial_mul_factorial hj + rw [hs] at hf + rw [←hf] at hh + have hpos : 0 < (μ.rowLen 0).factorial * j.factorial := Nat.mul_pos (Nat.factorial_pos _) (Nat.factorial_pos _) + nlinarith + + +lemma exists_perm_mem_iff {α : Type*} [Fintype α] (s t : Finset α) (hc : s.card=t.card) : + ∃ p : Equiv.Perm α, ∀ x, p x ∈ t ↔ x ∈ s := by + let e : s ≃ t := Finset.equivOfCardEq hc + let ec : {x : α // x ∉ s} ≃ {x : α // x ∉ t} := Fintype.equivOfCardEq (by + simp only [Fintype.card_subtype_compl,Fintype.card_coe,hc]) + let p := (Equiv.sumCompl (· ∈ s)).symm.trans ((Equiv.sumCongr e ec).trans (Equiv.sumCompl (· ∈ t))) + refine ⟨p,fun x => ?_⟩ + by_cases hx : x ∈ s + · have hp : p x ∈ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∈ t + rw [Equiv.sumCompl_symm_apply_of_pos hx] + exact (e ⟨x,hx⟩).2 + exact iff_of_true hp hx + · have hp : p x ∉ t := by + change ((Equiv.sumCompl (· ∈ t)) ((Equiv.sumCongr e ec) ((Equiv.sumCompl (· ∈ s)).symm x))) ∉ t + rw [Equiv.sumCompl_symm_apply_of_neg hx] + exact (ec ⟨x,hx⟩).2 + exact iff_of_false hp hx + +noncomputable def tailSet {μ : YoungDiagram} (f : Tabloid μ) : Finset (Cell μ) := + Finset.univ.filter (fun x => (f.1 x).val ≠ 0) + +@[simp] lemma mem_tailSet {μ : YoungDiagram} (f : Tabloid μ) (x : Cell μ) : + x ∈ tailSet f ↔ (f.1 x).val ≠ 0 := by simp [tailSet] + +lemma tailSet_act {μ : YoungDiagram} (p : Equiv.Perm (Cell μ)) (f : Tabloid μ) : + tailSet (tabloidAct p f) = (tailSet f).image p := by + ext x + simp only [mem_tailSet,tabloidAct_apply,Finset.mem_image] + constructor + · intro h; exact ⟨p⁻¹ x,h,by simp⟩ + · rintro ⟨y,hy,rfl⟩; simpa using hy + +lemma card_tailSet {μ : YoungDiagram} (f : Tabloid μ) : + (tailSet f).card = μ.card-μ.rowLen 0 := by + obtain ⟨p,rfl⟩ := tabloidAct_transitive μ (baseTabloid μ) f + rw [tailSet_act,Finset.card_image_of_injective _ p.injective] + change (Finset.univ.filter (fun x : Cell μ => row x ≠ 0)).card = _ + rw [←Fintype.card_subtype] + exact tail_card μ + +noncomputable def footprint (μ : YoungDiagram) (A : Finset (Cell μ)) : Finset (Tabloid μ) := + Finset.univ.filter (fun f => tailSet f ⊆ A) + +lemma tail_fiber_card_eq (μ : YoungDiagram) (s t : Finset (Cell μ)) (hst : s.card=t.card) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card = + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card := by + obtain ⟨p,hp⟩ := exists_perm_mem_iff s t hst + have he : s.image p=t := by + ext x + constructor + · intro hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + exact (hp y).mpr hy + · intro hx + exact Finset.mem_image.mpr ⟨p⁻¹ x,(hp (p⁻¹ x)).mp (by simpa using hx),by simp⟩ + apply Finset.card_equiv (tabloidAct p) + intro f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,tailSet_act,←he] + exact (Finset.image_inj p.injective).symm + +lemma footprint_card_product (μ : YoungDiagram) (A : Finset (Cell μ)) : + (footprint μ A).card * μ.card.choose (μ.card-μ.rowLen 0) = + Fintype.card (Tabloid μ) * A.card.choose (μ.card-μ.rowLen 0) := by + let j := μ.card-μ.rowLen 0 + let s := tailSet (baseTabloid μ) + let c := (Finset.univ.filter (fun f : Tabloid μ => tailSet f=s)).card + have hconstant (t : Finset (Cell μ)) (ht : t.card=j) : + (Finset.univ.filter (fun f : Tabloid μ => tailSet f=t)).card = c := + tail_fiber_card_eq μ t s (ht.trans (card_tailSet _).symm) + have hcount (A : Finset (Cell μ)) : (footprint μ A).card = A.card.choose j*c := by + have h := Finset.sum_card_fiberwise_eq_card_filter + (Finset.univ : Finset (Tabloid μ)) (A.powersetCard j) tailSet + have he : (Finset.univ.filter (fun f : Tabloid μ => tailSet f ∈ A.powersetCard j)) = footprint μ A := by + ext f + simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_powersetCard, + card_tailSet,footprint] + simp [j] + rw [he] at h + rw [←h] + calc + _ = ∑ _t ∈ A.powersetCard j, c := by + apply Finset.sum_congr rfl + intro t ht + exact hconstant t (Finset.mem_powersetCard.mp ht).2 + _ = _ := by simp [Finset.card_powersetCard] + have hfull : (footprint μ Finset.univ).card = Fintype.card (Tabloid μ) := by + simp only [footprint,Finset.subset_univ,Finset.filter_true,Finset.card_univ] + have hN := hcount Finset.univ + rw [hfull,Finset.card_univ,card_cell] at hN + rw [hcount,hN] + ring + +lemma footprint_fixed {μ : YoungDiagram} (A : Finset (Cell μ)) + (f : Tabloid μ) (hf : f ∈ footprint μ A) (p : Equiv.Perm (Cell μ)) + (hp : ∀ x ∈ A, p x=x) : tabloidAct p f=f := by + have htail : tailSet f ⊆ A := (Finset.mem_filter.mp hf).2 + apply Subtype.ext + funext x + change f.1 (p⁻¹ x) = f.1 x + by_cases hx : x ∈ A + · rw [show p⁻¹ x=x from p.injective (by simpa using (hp x hx).symm)] + · have hy : p⁻¹ x ∉ A := by + intro h + have hh := hp (p⁻¹ x) h + have he : x=p⁻¹ x := by simpa using hh + exact hx (he ▸ h) + apply Fin.ext + have hx0 : (f.1 x).val=0 := by by_contra h; exact hx (htail (mem_tailSet f x |>.mpr h)) + have hy0 : (f.1 (p⁻¹ x)).val=0 := by by_contra h; exact hy (htail (mem_tailSet f _ |>.mpr h)) + exact hy0.trans hx0.symm + +noncomputable def fixedHilbert (μ : YoungDiagram) (A : Finset (Cell μ)) : + Submodule ℂ (PermutationHilbert.H (Tabloid μ)) where + carrier := {v | v ∈ hilbertSpace μ ∧ ∀ p : Equiv.Perm (Cell μ), + (∀ x ∈ A, p x=x) → PermutationHilbert.act (tabloidAct p) v=v} + zero_mem' := ⟨Submodule.zero_mem _,fun p hp => map_zero _⟩ + add_mem' := fun hv hw => ⟨Submodule.add_mem _ hv.1 hw.1,fun p hp => by + rw [map_add,hv.2 p hp,hw.2 p hp]⟩ + smul_mem' := fun c v hv => ⟨Submodule.smul_mem _ c hv.1,fun p hp => by + rw [map_smul,hv.2 p hp]⟩ + +lemma fixedHilbert_le (μ : YoungDiagram) (A : Finset (Cell μ)) : fixedHilbert μ A ≤ hilbertSpace μ := + fun _ hv => hv.1 + +theorem fixedHilbert_dimension (μ : YoungDiagram) (A : Finset (Cell μ)) : + Module.finrank ℂ (space μ) * A.card.choose (μ.card-μ.rowLen 0) ≤ + Module.finrank ℂ (fixedHilbert μ A) * μ.card.choose (μ.card-μ.rowLen 0) := by + let : DecidableEq (Tabloid μ) := Classical.decEq _ + have ht (f g : Tabloid μ) : ∃ p : Equiv.Perm (Tabloid μ), p f=g ∧ + (hilbertSpace μ).map (PermutationHilbert.act p).toLinearEquiv.toLinearMap = hilbertSpace μ := by + obtain ⟨p,hp⟩ := tabloidAct_transitive μ f g + exact ⟨tabloidAct p,hp,hilbertSpace_invariant μ p⟩ + have hproj (f : Tabloid μ) (hf : f ∈ footprint μ A) : + (hilbertSpace μ).starProjection (EuclideanSpace.single f (1:ℂ)) ∈ fixedHilbert μ A := by + refine ⟨((hilbertSpace μ).orthogonalProjectionOnto _).2,fun p hp => ?_⟩ + rw [PermutationHilbert.projection_comm _ _ (hilbertSpace_invariant μ p), + PermutationHilbert.act_single,footprint_fixed A f hf p hp] + have h := PermutationHilbert.footprint_dimension (hilbertSpace μ) (fixedHilbert μ A) + (fixedHilbert_le μ A) ht (footprint μ A) hproj + rw [finrank_hilbertSpace] at h + have hn : (footprint μ A).card * Module.finrank ℂ (space μ) ≤ + Fintype.card (Tabloid μ)*Module.finrank ℂ (fixedHilbert μ A) := by exact_mod_cast h + have hc := footprint_card_product μ A + have hpos : 0 < Fintype.card (Tabloid μ) := Fintype.card_pos_iff.mpr ⟨baseTabloid μ⟩ + have hh := Nat.mul_le_mul_right (μ.card.choose (μ.card-μ.rowLen 0)) hn + nlinarith + +end Thorp.Specht + +namespace Thorp.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +def IsUnitary (ρ : Representation ℂ G V) : Prop := + ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : + inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by + have h := hρ g v (ρ g⁻¹ w) + have he : ρ g (ρ g⁻¹ w) = w := by + change (ρ g * ρ g⁻¹) w = w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [he] at h + exact h.symm + +noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where + toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) + isIntertwining' h := by + ext v + simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] + have hh (w : W) : σ h (σ h⁻¹ w)=w := by + change (σ h*σ h⁻¹) w=w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [hh] + +end Thorp.UnitaryFinite + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/TailShapes.lean b/lean/OAI/Probability/ThorpRouting/Tail/TailShapes.lean index a1f483db177428f6dd33537a5d930e5e417bec5e..561f96c297e39026ded1be4e7b6429ba14b77e5c 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/TailShapes.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/TailShapes.lean @@ -1,863 +1,863 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.InsertionPerm - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.Specht -open scoped BigOperators Classical - -abbrev TailShapes (N j : ℕ) := {μ : Shapes N // μ.1.card-μ.1.rowLen 0=j} - -noncomputable def tailShapePartition (N j : ℕ) (μ : TailShapes N j) : Nat.Partition j where - parts := μ.1.1.rowLens.tail - parts_pos := fun {x} hx => μ.1.1.pos_of_mem_rowLens x (List.mem_of_mem_tail (by simpa using hx)) - parts_sum := by simpa using (rowLens_tail_sum μ.1.1).trans μ.2 - -lemma tailShapePartition_injective (N j : ℕ) : Function.Injective (tailShapePartition N j) := by - intro μ ν he - have hh : (μ.1.1.rowLens.tail : Multiset ℕ)=(ν.1.1.rowLens.tail : Multiset ℕ) := - congrArg Nat.Partition.parts he - have ht : μ.1.1.rowLens.tail=ν.1.1.rowLens.tail := by - have hm := congrArg (fun s : Multiset ℕ => s.sort (· ≥ ·)) hh - simpa only [Multiset.coe_sort, - List.mergeSort_eq_self _ μ.1.1.rowLens_sorted.pairwise.tail, - List.mergeSort_eq_self _ ν.1.1.rowLens_sorted.pairwise.tail] using hm - have hl := positive_list_eq_of_tail_sum (μ.1.1.pos_of_mem_rowLens) (ν.1.1.pos_of_mem_rowLens) - ht (by rw [sum_rowLens,sum_rowLens,μ.1.2,ν.1.2]) - apply Subtype.ext - apply Subtype.ext - apply YoungDiagram.equivListRowLens.injective - exact Subtype.ext hl - -lemma tail_shapes_count (N j : ℕ) : Fintype.card (TailShapes N j)≤2^j := by - exact (Fintype.card_le_of_injective _ (tailShapePartition_injective N j)).trans (partition_count j) - -end Thorp.Specht - -namespace Thorp -open scoped BigOperators Classical - -lemma tail_preserving_pairSwitch (d : ℕ) (p : Equiv.Perm (Card (d+1))) - (hp : ∀ x, Fin.tail (p x)=Fin.tail x) : - pairSwitch (fun u => p (Fin.cons false u) 0)=p := by - apply Equiv.ext - intro x - rw [←Fin.cons_self_tail x] - generalize x 0=b - generalize Fin.tail x=u - apply funext - intro i - refine Fin.cases ?_ (fun j => ?_) i - · change Bool.xor b (p (Fin.cons false u) 0)=p (Fin.cons b u) 0 - cases b with - | false => simp - | true => - have hn : p (Fin.cons false u) 0 ≠ p (Fin.cons true u) 0 := by - intro he - have hh : p (Fin.cons false u)=p (Fin.cons true u) := by - rw [←Fin.cons_self_tail (p (Fin.cons false u)),←Fin.cons_self_tail (p (Fin.cons true u)), - hp,hp,Fin.tail_cons,Fin.tail_cons,he] - have hh := congrFun (p.injective hh) 0 - simp only [Fin.cons_zero] at hh - contradiction - cases h0 : p (Fin.cons false u) 0 <;> cases h1 : p (Fin.cons true u) 0 <;> simp_all - · change u j=p (Fin.cons b u) j.succ - have h := congrFun (hp (Fin.cons b u)) j - simpa only [Fin.tail_cons,Fin.tail,Fin.cons_succ] using h.symm - -lemma pairSwitch_injective (d : ℕ) : Function.Injective (pairSwitch (d := d)) := by - intro ξ η h - funext u - have hh := congrArg (fun p : Equiv.Perm (Card (d+1)) => p (Fin.cons false u) 0) h - change Bool.xor false (ξ u)=Bool.xor false (η u) at hh - simpa only [Bool.false_xor] using hh - -end Thorp -namespace Thorp.Specht -open scoped BigOperators Classical - -noncomputable def pairFiberEquiv (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) : - (Card d → Bool) ≃ fiberGroup (fun x => Fin.tail (e.symm x)) := - Equiv.ofBijective (fun ξ => ⟨e.permCongr (pairSwitch ξ),by - intro x - simp only [Equiv.permCongr_apply,e.symm_apply_apply] - exact Fin.tail_cons _ _⟩) - ⟨fun ξ η h => pairSwitch_injective d (e.permCongr.injective (congrArg Subtype.val h)),by - intro p - let q := e.symm.permCongr p.1 - have hq : ∀ x, Fin.tail (q x)=Fin.tail x := by - intro x - have h := p.2 (e x) - simpa only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply] using h - refine ⟨fun u => q (Fin.cons false u) 0,?_⟩ - apply Subtype.ext - change e.permCongr (pairSwitch (fun u => q (Fin.cons false u) 0))=p.1 - rw [tail_preserving_pairSwitch d q hq] - apply Equiv.ext - intro x - simp only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply]⟩ - -lemma pair_sum_taboid_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d < μ.colLen 0) (v : space μ) : - (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ))) v.1=0 := by - have he : (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)))= - symmetrizer (fiberGroup (fun x => Fin.tail (e.symm x))) (tabloidRep μ) := - Fintype.sum_equiv (pairFiberEquiv d μ e) _ _ (fun _ => rfl) - rw [he] - exact tall_column_average_zero μ _ 0 (by simpa only [card_positions] using hj) v.1 v.2 - -lemma pair_operator_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d < μ.colLen 0) : - UnitaryFinite.sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) pairSwitch=0 := by - apply ContinuousLinearMap.ext - intro v - obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v - have hh : (∑ ξ : Card d → Bool, representation μ (e.permCongr (pairSwitch ξ))) w=0 := by - apply Subtype.ext - simp only [LinearMap.sum_apply,Submodule.coe_sum,Submodule.coe_zero] - change (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)) w.1)=0 - simpa only [LinearMap.sum_apply] using pair_sum_taboid_zero d μ e hj w - have hh' := congrArg (spaceHilbertEquiv μ) hh - simp only [LinearMap.sum_apply,map_sum,map_zero] at hh' - change ((Fintype.card (Card d → Bool):ℂ)⁻¹ • - ∑ ξ : Card d → Bool, UnitaryFinite.continuousRepresentation (relabelledUnitary μ e) (pairSwitch ξ)) - (spaceHilbertEquiv μ w)=0 - rw [smul_apply,sum_apply] - change (Fintype.card (Card d → Bool):ℂ)⁻¹ • - (∑ ξ : Card d → Bool, spaceHilbertEquiv μ (representation μ (e.permCongr (pairSwitch ξ)) - ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ w))))=0 - simp only [LinearEquiv.symm_apply_apply,hh',smul_zero] - -open UnitaryFinite - -lemma palindrome_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) - (hj : 2^d<μ.colLen 0) : - sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm (d+1))=0 := by - let ρ := relabelledUnitary μ e - let : NormedAddCommGroup (hilbertSpace μ) := inferInstance - let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance - let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance - have hpair : sampleOperator (V := hilbertSpace μ) ρ (pairSwitch (d := d))=0 := pair_operator_tall_zero d μ e hj - have hi : sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)=0 := by - rw [inverse_butterfly_average_step,hpair,mul_zero] - rw [sampleOperator_inv ρ (relabelledUnitary_unitary μ e)] at hi - rw [sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e),hi,mul_zero] - -lemma palindrome_tall_zero_general (d : ℕ) (hd : 0 (2:ℝ)^d) atTop atTop := - tendsto_pow_atTop_atTop_of_one_lt (by norm_num) - -lemma twopow_nat_tendsto : Tendsto (fun d : ℕ => (2:ℕ)^d) atTop atTop := - tendsto_pow_atTop_atTop_of_one_lt (by norm_num) - -lemma twopow_mul_eventually (c : ℝ) (hc : 0.trans_eq (mul_comm _ _) - -lemma exp_two_absorb (β n : ℝ) (hx : Real.log 2≤β*n/2) : - Real.exp (-β*n)+Real.exp (-β*n)≤Real.exp (-β*n/2) := by - calc - _ = Real.exp (Real.log 2-β*n) := by rw [Real.exp_sub,Real.exp_log (by norm_num)]; rw [neg_mul,Real.exp_neg]; ring - _ ≤ _ := Real.exp_le_exp.mpr (by linarith) - -end Thorp.DimensionEstimates -namespace Thorp.Specht -open scoped BigOperators Classical -open Filter UnitaryFinite DimensionEstimates - -theorem exponential_dimension_spectral (h : ℝ) (hh : 0 (f x)^a) ≤ (finiteMean f)^a := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hh := (Real.concaveOn_rpow ha ha1).le_map_sum - (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) - (p := f) (fun _ _ => by positivity) - (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) - (fun x _ => hf x) - simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), - ←div_eq_mul_inv,finiteMean] using hh - -noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x - -omit [Nonempty X] in -lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := - Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) - -omit [Nonempty X] in -lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) - {b : ℝ} (hb : 1 ≤ b) (y : X) : - (act K f y)^b ≤ act K (fun x => (f x)^b) y := by - simpa only [smul_eq_mul,act] using - (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) - (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) - -lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - {p A : ℝ} (hp : 1 ≤ p) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by - classical - let s : ℝ := ∑ x, f x - have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - by_cases hz : s=0 - · have hfz : ∀ x, f x=0 := by - intro x - exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) - simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, - Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] - · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) - let w : X → ℝ := fun x => f x/s - have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs - have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz - have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by - simp only [act,w,finiteMean,Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - have hz' : (∑ x, f x) ≠ 0 := hz - dsimp [s] - field_simp [hz',ne_of_gt hN] - have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by - rw [hact,Real.mul_rpow (mean_nonneg f hf) - (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) - exact (convexOn_rpow hp).map_sum_le - (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) - have hh := finiteMean_mono hj - have he : finiteMean (fun y => (finiteMean f)^p* - ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = - (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by - simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, - finiteMean_sum, mul_comm (w _), finiteMean_mul_const] - rw [he] at hh - apply hh.trans - have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by - calc - _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum - (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) - _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] - simpa only [mul_comm (Real.exp A)] using - mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) - -lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : - finiteMean (fun y => (act K f y)^(b*p)) ≤ - Real.exp A*(finiteMean (fun x => (f x)^b))^p := by - calc - _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by - apply finiteMean_mono - intro y - rw [Real.rpow_mul (act_nonneg K hK f hf y)] - exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) - _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) - -variable [DecidableEq X] - -omit [Nonempty X] in -lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : - ∀ x y, 0 ≤ (K^r) x y := by - classical - induction r with - | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num - | succ r ih => - intro x y - rw [pow_succ,Matrix.mul_apply] - exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) - -omit [Nonempty X] in -lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : - ∀ x, ∑ y, (K^r) x y = 1 := by - classical - induction r with - | zero => intro x; simp [Matrix.one_apply] - | succ r ih => - intro x - simp only [pow_succ,Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hrow,mul_one,ih] - -noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := - (Fintype.card X:ℝ)*(K^r) x y - -omit [Nonempty X] in -lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : - 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) - -omit [Nonempty X] in -lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : - rowDensity K (r+1) x y = act K (rowDensity K r x) y := by - simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] - apply Finset.sum_congr rfl - intro z _ - ring - -lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : - finiteMean (rowDensity K r x) = 1 := by - have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) - simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] - -lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by - induction r with - | zero => simp [rowDensity_mean K hrow] - | succ r ih => - have hpr : 1 ≤ p^r := one_le_pow₀ hp - have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp - simp_rw [rowDensity_succ] - calc - _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by - rw [pow_succ] - exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) - _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by - apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le - exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) - _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring - _ ≤ _ := by - apply Real.exp_le_exp.mpr - have hh := mul_le_mul_of_nonneg_left hps hA - push_cast - nlinarith - -lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x : X) : - finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by - have hpos : 0 < p^r := by linarith - have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) - (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) - (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) - have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by - rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] - rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] - simp_rw [he] at hj - apply hj.trans - calc - _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := - Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg - (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) - (by positivity) - _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] - -lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) - (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) - (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) - (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : - (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by - have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos - have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z - have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = - finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by - simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] - rw [Finset.sum_div] - apply Finset.sum_congr rfl - intro z _ - field_simp - have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ - Real.exp (2*A*r) := by - calc - _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by - apply finiteMean_mono - intro z - nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] - _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ - finiteMean (fun z => (rowDensity K r y z)^2))/2 := by - simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] - _ ≤ _ := by - have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x - have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y - linarith - apply (le_div_iff₀ hN).mpr - simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh - -lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by - calc - (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num - _ ≤ _ := by simpa only [Nat.cast_ofNat] using - (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) - -end Thorp.StrongSmoothing - -namespace Thorp.StrongSmoothing.PermLaw -open scoped BigOperators -variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] - -noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := - fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) - -omit [Fintype X] in -lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by - exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) - -lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by - simp only [kernel,←finiteMean_sum] - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] - -omit [Fintype X] in -lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by - ext x y - apply finiteMean_congr - intro ω - have he : (P ω)⁻¹ x=y ↔ P ω y=x := by - change (P ω).symm x=y ↔ P ω y=x - exact (Equiv.symm_apply_eq (P ω)).trans eq_comm - simp only [he] - -lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by - have hh := row (fun ω => (P ω)⁻¹) y - rw [inverse] at hh - exact hh - -lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : - kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by - ext x y - simp only [Matrix.mul_apply,kernel] - have he (ω : Ω × Ω') : - (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = - ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by - simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] - rfl - change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ - simp_rw [he] - rw [finiteMean_sum] - apply Finset.sum_congr rfl - intro z _ - exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) - (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) - -omit [Fintype X] in -lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : - kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by - apply finiteMean_congr - intro ω - have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by - change e (P ω (e.symm x))=y ↔ _ - exact (Equiv.eq_symm_apply e).symm - simp only [he] - -end Thorp.StrongSmoothing.PermLaw - -namespace Thorp.StrongSmoothing -open scoped BigOperators - -section MatrixHelpers -variable {X : Type*} [Fintype X] [DecidableEq X] - -omit [DecidableEq X] in -lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := - Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) - -omit [DecidableEq X] in -lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) - (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.mul_sum,hB,mul_one,hA] - -omit [DecidableEq X] in -lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) - (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by - simp only [Matrix.mul_apply] - rw [Finset.sum_comm] - simp only [←Finset.sum_mul,hA,one_mul,hB] - -omit [DecidableEq X] in -lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) - (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) - _ = D := by rw [←Finset.sum_mul,hrow,one_mul] - -omit [DecidableEq X] in -lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) - (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : - ∀ x y, (A*B) x y ≤ D := by - intro x y - calc - _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) - _ = D := by rw [←Finset.mul_sum,hcol,mul_one] - -lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by - induction r with - | zero => simp - | succ r ih => - calc - _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring - _ = (A*B)^(r+1)*(A*B) := by rw [ih] - _ = _ := (pow_succ (A*B) (r+1)).symm - -end MatrixHelpers - -section TupleAction -variable {ι β Ω : Type*} [Fintype ι] [Fintype β] [DecidableEq β] [Fintype Ω] - -def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where - toFun x := x.trans P.toEmbedding - invFun x := x.trans P.symm.toEmbedding - left_inv x := by ext i; simp - right_inv x := by ext i; simp - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : - tuplePerm P x i = P (x i) := rfl - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -lemma tuplePerm_mul (P Q : Equiv.Perm β) : - tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by - ext x i - rfl - -omit [Fintype ι] [Fintype β] [DecidableEq β] in -lemma tuplePerm_inverse (P : Equiv.Perm β) : - tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by - ext x i - rfl - -omit [Fintype β] in -lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : - PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by - classical - apply finiteMean_congr - intro ω - have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by - constructor - · intro h; ext i; exact h i - · intro h i; exact congrArg (fun z : ι ↪ β => z i) h - simp only [he] -end TupleAction - -lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : - sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by - ext x y - exact tupleProbability_kernel _ x y - -lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - reflectedKernel d l order false x y = - PairRouting.tupleProbability (palindromePerm d) - ((tuplePerm (coordinateRelabel d order)).symm x) - ((tuplePerm (coordinateRelabel d order)).symm y) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) - have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by - rw [sweepKernel_law] - simp only [sweep,tuplePerm_mul,tuplePerm_inverse] - rfl - rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] - rw [←PermLaw.inverse,←PermLaw.mul] - have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = - fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by - funext ω - simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] - change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ - group - rw [hprod,PermLaw.conjugate,tupleProbability_kernel] - - -lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ - -lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.row _ _ - -lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, sweepKernel d l order x y = 1 := by - rw [sweepKernel_law] - exact PermLaw.col _ _ - -lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - 0 ≤ reflectedKernel d l order false x y := by - exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_nonneg d l order) x y - -lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - ∑ y, reflectedKernel d l order false x y = 1 := - mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x - -lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : - ∑ x, reflectedKernel d l order false x y = 1 := - mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y - -lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : - (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ - -lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : - finiteMean (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ - Real.exp (l*(1+heightDecay 1)) := by - classical - let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) - simp_rw [reflectedKernel_conjugate] - have he := finiteMean_equiv e (fun y : Tuples d l => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ - (1+(1/1000:ℝ))) - change finiteMean (fun y => - ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ - (1+(1/1000:ℝ))) ≤ _ - rw [←he] - simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) - -lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by - simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] - -lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : - ((reflectedKernel d l order false)^2000) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - let : Nonempty (Tuples d l) := ⟨x⟩ - have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) - (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) - (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) - (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) - (reflected_moment d l order) 1000 density_exponent_numeric x y - have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring - norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh - simpa only [he,tuples_card] using hh - -lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) - (x y : Tuples d l) : - ((reflectedKernel d l order orientation)^2001) x y ≤ - Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by - cases orientation - · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ - rw [pow_succ] - exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) - (canonical_pointwise d l order) x y - · let A := sweepKernel d l order - change ((A*A.transpose)^(2000+1)) x y ≤ _ - rw [←sandwich_power] - apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) - (sweepKernel_row d l order) - exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) - (canonical_pointwise d l order) - -lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : - regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by - have hn : 0 < Fintype.card (Tuples d (2^d)) := by - rw [tuples_card,Nat.descFactorial_self] - exact Nat.factorial_pos _ - have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) - calc - _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / - ((2^d).descFactorial (2^d):ℝ) := by - apply Finset.sum_le_sum - intro x _ - exact both_pointwise d (2^d) order false x x - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] - push_cast - field_simp - -theorem strong_smoothing : MainStatement := by - refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ - intro d l _ order orientation x y - exact both_pointwise d l order orientation x y - -end Thorp.StrongSmoothing - -namespace Thorp.StrongTail -open scoped BigOperators Classical -open Specht - -lemma mem_tailDiagram (μ : YoungDiagram) (i j : ℕ) : - (i,j) ∈ tailDiagram μ ↔ (i+1,j) ∈ μ := by - rw [tailDiagram, YoungDiagram.mem_ofRowLens] - constructor - · rintro ⟨hi,hj⟩ - rw [List.getElem_tail,YoungDiagram.get_rowLens] at hj - exact YoungDiagram.mem_iff_lt_rowLen.mpr hj - · intro h - have hi : i+1 < μ.colLen 0 := - (YoungDiagram.mem_iff_lt_colLen.mp h).trans_le (μ.colLen_anti 0 j (Nat.zero_le _)) - have hi' : i < μ.rowLens.tail.length := by simp only [List.length_tail,YoungDiagram.length_rowLens]; omega - refine ⟨hi', ?_⟩ - simpa only [List.getElem_tail,YoungDiagram.get_rowLens] using YoungDiagram.mem_iff_lt_rowLen.mp h - -lemma tail_height (μ : YoungDiagram) : (tailDiagram μ).colLen 0 = μ.colLen 0 - 1 := by - rw [←YoungDiagram.length_rowLens] - exact (YoungDiagram.rowLens_length_ofRowLens (fun x hx => μ.pos_of_mem_rowLens x (List.mem_of_mem_tail hx))).trans - (by simp only [List.length_tail,YoungDiagram.length_rowLens]) - -end Thorp.StrongTail - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.InsertionPerm + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.Specht +open scoped BigOperators Classical + +abbrev TailShapes (N j : ℕ) := {μ : Shapes N // μ.1.card-μ.1.rowLen 0=j} + +noncomputable def tailShapePartition (N j : ℕ) (μ : TailShapes N j) : Nat.Partition j where + parts := μ.1.1.rowLens.tail + parts_pos := fun {x} hx => μ.1.1.pos_of_mem_rowLens x (List.mem_of_mem_tail (by simpa using hx)) + parts_sum := by simpa using (rowLens_tail_sum μ.1.1).trans μ.2 + +lemma tailShapePartition_injective (N j : ℕ) : Function.Injective (tailShapePartition N j) := by + intro μ ν he + have hh : (μ.1.1.rowLens.tail : Multiset ℕ)=(ν.1.1.rowLens.tail : Multiset ℕ) := + congrArg Nat.Partition.parts he + have ht : μ.1.1.rowLens.tail=ν.1.1.rowLens.tail := by + have hm := congrArg (fun s : Multiset ℕ => s.sort (· ≥ ·)) hh + simpa only [Multiset.coe_sort, + List.mergeSort_eq_self _ μ.1.1.rowLens_sorted.pairwise.tail, + List.mergeSort_eq_self _ ν.1.1.rowLens_sorted.pairwise.tail] using hm + have hl := positive_list_eq_of_tail_sum (μ.1.1.pos_of_mem_rowLens) (ν.1.1.pos_of_mem_rowLens) + ht (by rw [sum_rowLens,sum_rowLens,μ.1.2,ν.1.2]) + apply Subtype.ext + apply Subtype.ext + apply YoungDiagram.equivListRowLens.injective + exact Subtype.ext hl + +lemma tail_shapes_count (N j : ℕ) : Fintype.card (TailShapes N j)≤2^j := by + exact (Fintype.card_le_of_injective _ (tailShapePartition_injective N j)).trans (partition_count j) + +end Thorp.Specht + +namespace Thorp +open scoped BigOperators Classical + +lemma tail_preserving_pairSwitch (d : ℕ) (p : Equiv.Perm (Card (d+1))) + (hp : ∀ x, Fin.tail (p x)=Fin.tail x) : + pairSwitch (fun u => p (Fin.cons false u) 0)=p := by + apply Equiv.ext + intro x + rw [←Fin.cons_self_tail x] + generalize x 0=b + generalize Fin.tail x=u + apply funext + intro i + refine Fin.cases ?_ (fun j => ?_) i + · change Bool.xor b (p (Fin.cons false u) 0)=p (Fin.cons b u) 0 + cases b with + | false => simp + | true => + have hn : p (Fin.cons false u) 0 ≠ p (Fin.cons true u) 0 := by + intro he + have hh : p (Fin.cons false u)=p (Fin.cons true u) := by + rw [←Fin.cons_self_tail (p (Fin.cons false u)),←Fin.cons_self_tail (p (Fin.cons true u)), + hp,hp,Fin.tail_cons,Fin.tail_cons,he] + have hh := congrFun (p.injective hh) 0 + simp only [Fin.cons_zero] at hh + contradiction + cases h0 : p (Fin.cons false u) 0 <;> cases h1 : p (Fin.cons true u) 0 <;> simp_all + · change u j=p (Fin.cons b u) j.succ + have h := congrFun (hp (Fin.cons b u)) j + simpa only [Fin.tail_cons,Fin.tail,Fin.cons_succ] using h.symm + +lemma pairSwitch_injective (d : ℕ) : Function.Injective (pairSwitch (d := d)) := by + intro ξ η h + funext u + have hh := congrArg (fun p : Equiv.Perm (Card (d+1)) => p (Fin.cons false u) 0) h + change Bool.xor false (ξ u)=Bool.xor false (η u) at hh + simpa only [Bool.false_xor] using hh + +end Thorp +namespace Thorp.Specht +open scoped BigOperators Classical + +noncomputable def pairFiberEquiv (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) : + (Card d → Bool) ≃ fiberGroup (fun x => Fin.tail (e.symm x)) := + Equiv.ofBijective (fun ξ => ⟨e.permCongr (pairSwitch ξ),by + intro x + simp only [Equiv.permCongr_apply,e.symm_apply_apply] + exact Fin.tail_cons _ _⟩) + ⟨fun ξ η h => pairSwitch_injective d (e.permCongr.injective (congrArg Subtype.val h)),by + intro p + let q := e.symm.permCongr p.1 + have hq : ∀ x, Fin.tail (q x)=Fin.tail x := by + intro x + have h := p.2 (e x) + simpa only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.symm_apply_apply] using h + refine ⟨fun u => q (Fin.cons false u) 0,?_⟩ + apply Subtype.ext + change e.permCongr (pairSwitch (fun u => q (Fin.cons false u) 0))=p.1 + rw [tail_preserving_pairSwitch d q hq] + apply Equiv.ext + intro x + simp only [q,Equiv.permCongr_apply,Equiv.symm_symm,e.apply_symm_apply]⟩ + +lemma pair_sum_taboid_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d < μ.colLen 0) (v : space μ) : + (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ))) v.1=0 := by + have he : (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)))= + symmetrizer (fiberGroup (fun x => Fin.tail (e.symm x))) (tabloidRep μ) := + Fintype.sum_equiv (pairFiberEquiv d μ e) _ _ (fun _ => rfl) + rw [he] + exact tall_column_average_zero μ _ 0 (by simpa only [card_positions] using hj) v.1 v.2 + +lemma pair_operator_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d < μ.colLen 0) : + UnitaryFinite.sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) pairSwitch=0 := by + apply ContinuousLinearMap.ext + intro v + obtain ⟨w,rfl⟩ := (spaceHilbertEquiv μ).surjective v + have hh : (∑ ξ : Card d → Bool, representation μ (e.permCongr (pairSwitch ξ))) w=0 := by + apply Subtype.ext + simp only [LinearMap.sum_apply,Submodule.coe_sum,Submodule.coe_zero] + change (∑ ξ : Card d → Bool, tabloidRep μ (e.permCongr (pairSwitch ξ)) w.1)=0 + simpa only [LinearMap.sum_apply] using pair_sum_taboid_zero d μ e hj w + have hh' := congrArg (spaceHilbertEquiv μ) hh + simp only [LinearMap.sum_apply,map_sum,map_zero] at hh' + change ((Fintype.card (Card d → Bool):ℂ)⁻¹ • + ∑ ξ : Card d → Bool, UnitaryFinite.continuousRepresentation (relabelledUnitary μ e) (pairSwitch ξ)) + (spaceHilbertEquiv μ w)=0 + rw [smul_apply,sum_apply] + change (Fintype.card (Card d → Bool):ℂ)⁻¹ • + (∑ ξ : Card d → Bool, spaceHilbertEquiv μ (representation μ (e.permCongr (pairSwitch ξ)) + ((spaceHilbertEquiv μ).symm (spaceHilbertEquiv μ w))))=0 + simp only [LinearEquiv.symm_apply_apply,hh',smul_zero] + +open UnitaryFinite + +lemma palindrome_tall_zero (d : ℕ) (μ : YoungDiagram) (e : Card (d+1) ≃ Cell μ) + (hj : 2^d<μ.colLen 0) : + sampleOperator (V := hilbertSpace μ) (relabelledUnitary μ e) (palindromePerm (d+1))=0 := by + let ρ := relabelledUnitary μ e + let : NormedAddCommGroup (hilbertSpace μ) := inferInstance + let : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance + let : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance + have hpair : sampleOperator (V := hilbertSpace μ) ρ (pairSwitch (d := d))=0 := pair_operator_tall_zero d μ e hj + have hi : sampleOperator ρ (fun ω => (butterflyPerm (d+1) (decodeButterfly (d+1) ω))⁻¹)=0 := by + rw [inverse_butterfly_average_step,hpair,mul_zero] + rw [sampleOperator_inv ρ (relabelledUnitary_unitary μ e)] at hi + rw [sampleOperator_palindrome _ _ (relabelledUnitary_unitary μ e),hi,mul_zero] + +lemma palindrome_tall_zero_general (d : ℕ) (hd : 0 (2:ℝ)^d) atTop atTop := + tendsto_pow_atTop_atTop_of_one_lt (by norm_num) + +lemma twopow_nat_tendsto : Tendsto (fun d : ℕ => (2:ℕ)^d) atTop atTop := + tendsto_pow_atTop_atTop_of_one_lt (by norm_num) + +lemma twopow_mul_eventually (c : ℝ) (hc : 0.trans_eq (mul_comm _ _) + +lemma exp_two_absorb (β n : ℝ) (hx : Real.log 2≤β*n/2) : + Real.exp (-β*n)+Real.exp (-β*n)≤Real.exp (-β*n/2) := by + calc + _ = Real.exp (Real.log 2-β*n) := by rw [Real.exp_sub,Real.exp_log (by norm_num)]; rw [neg_mul,Real.exp_neg]; ring + _ ≤ _ := Real.exp_le_exp.mpr (by linarith) + +end Thorp.DimensionEstimates +namespace Thorp.Specht +open scoped BigOperators Classical +open Filter UnitaryFinite DimensionEstimates + +theorem exponential_dimension_spectral (h : ℝ) (hh : 0 (f x)^a) ≤ (finiteMean f)^a := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hh := (Real.concaveOn_rpow ha ha1).le_map_sum + (t := Finset.univ) (w := fun _ : X => 1/(Fintype.card X:ℝ)) + (p := f) (fun _ _ => by positivity) + (by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; field_simp) + (fun x _ => hf x) + simpa only [smul_eq_mul,one_div,←Finset.mul_sum,mul_comm _ (∑ _ : X,_), + ←div_eq_mul_inv,finiteMean] using hh + +noncomputable def act (K : Matrix X X ℝ) (f : X → ℝ) (y : X) : ℝ := ∑ x, K x y*f x + +omit [Nonempty X] in +lemma act_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) (y : X) : 0 ≤ act K f y := + Finset.sum_nonneg (fun x _ => mul_nonneg (hK x y) (hf x)) + +omit [Nonempty X] in +lemma act_rpow_le (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) + {b : ℝ} (hb : 1 ≤ b) (y : X) : + (act K f y)^b ≤ act K (fun x => (f x)^b) y := by + simpa only [smul_eq_mul,act] using + (convexOn_rpow hb).map_sum_le (t := Finset.univ) (w := fun x => K x y) + (p := f) (fun x _ => hK x y) (hcol y) (fun x _ => hf x) + +lemma act_one_to_p (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + {p A : ℝ} (hp : 1 ≤ p) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^p) ≤ Real.exp A*(finiteMean f)^p := by + classical + let s : ℝ := ∑ x, f x + have hs : 0 ≤ s := Finset.sum_nonneg (fun x _ => hf x) + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + by_cases hz : s=0 + · have hfz : ∀ x, f x=0 := by + intro x + exact (Finset.sum_eq_zero_iff_of_nonneg (fun x _ => hf x)).mp hz x (Finset.mem_univ _) + simp only [act,hfz,mul_zero,Finset.sum_const_zero,finiteMean,zero_div, + Real.zero_rpow (show p ≠ 0 by linarith),mul_zero,le_refl] + · have hsp : 0 < s := lt_of_le_of_ne hs (Ne.symm hz) + let w : X → ℝ := fun x => f x/s + have hw : ∀ x, 0 ≤ w x := fun x => div_nonneg (hf x) hs + have hws : ∑ x, w x = 1 := by simp only [w,←Finset.sum_div]; exact div_self hz + have hact (y : X) : act K f y = finiteMean f * ∑ x, w x*((Fintype.card X:ℝ)*K x y) := by + simp only [act,w,finiteMean,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + have hz' : (∑ x, f x) ≠ 0 := hz + dsimp [s] + field_simp [hz',ne_of_gt hN] + have hj (y : X) : (act K f y)^p ≤ (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p := by + rw [hact,Real.mul_rpow (mean_nonneg f hf) + (Finset.sum_nonneg (fun x _ => mul_nonneg (hw x) (mul_nonneg hN.le (hK x y))))] + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (mean_nonneg f hf) _) + exact (convexOn_rpow hp).map_sum_le + (fun x _ => hw x) hws (fun x _ => mul_nonneg hN.le (hK x y)) + have hh := finiteMean_mono hj + have he : finiteMean (fun y => (finiteMean f)^p* + ∑ x, w x*((Fintype.card X:ℝ)*K x y)^p) = + (finiteMean f)^p * ∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) := by + simp_rw [mul_comm ((finiteMean f)^p), finiteMean_mul_const, + finiteMean_sum, mul_comm (w _), finiteMean_mul_const] + rw [he] at hh + apply hh.trans + have hsum : (∑ x, w x*finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p)) ≤ Real.exp A := by + calc + _ ≤ ∑ x, w x*Real.exp A := Finset.sum_le_sum + (fun x _ => mul_le_mul_of_nonneg_left (hm x) (hw x)) + _ = Real.exp A := by rw [←Finset.sum_mul,hws,one_mul] + simpa only [mul_comm (Real.exp A)] using + mul_le_mul_of_nonneg_left hsum (Real.rpow_nonneg (mean_nonneg f hf) _) + +lemma act_b_to_pb (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcol : ∀ y, ∑ x, K x y = 1) {p A b : ℝ} (hp : 1 ≤ p) (hb : 1 ≤ b) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (f : X → ℝ) (hf : ∀ x, 0 ≤ f x) : + finiteMean (fun y => (act K f y)^(b*p)) ≤ + Real.exp A*(finiteMean (fun x => (f x)^b))^p := by + calc + _ ≤ finiteMean (fun y => (act K (fun x => (f x)^b) y)^p) := by + apply finiteMean_mono + intro y + rw [Real.rpow_mul (act_nonneg K hK f hf y)] + exact Real.rpow_le_rpow (Real.rpow_nonneg (act_nonneg K hK f hf y) _) (act_rpow_le K hK hcol f hf hb y) (by linarith) + _ ≤ _ := act_one_to_p K hK hp hm _ (fun x => Real.rpow_nonneg (hf x) _) + +variable [DecidableEq X] + +omit [Nonempty X] in +lemma kernel_pow_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) : + ∀ x y, 0 ≤ (K^r) x y := by + classical + induction r with + | zero => intro x y; simp only [pow_zero,Matrix.one_apply]; split_ifs <;> norm_num + | succ r ih => + intro x y + rw [pow_succ,Matrix.mul_apply] + exact Finset.sum_nonneg (fun z _ => mul_nonneg (ih x z) (hK z y)) + +omit [Nonempty X] in +lemma kernel_pow_row (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) : + ∀ x, ∑ y, (K^r) x y = 1 := by + classical + induction r with + | zero => intro x; simp [Matrix.one_apply] + | succ r ih => + intro x + simp only [pow_succ,Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hrow,mul_one,ih] + +noncomputable def rowDensity (K : Matrix X X ℝ) (r : ℕ) (x y : X) : ℝ := + (Fintype.card X:ℝ)*(K^r) x y + +omit [Nonempty X] in +lemma rowDensity_nonneg (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) (r : ℕ) (x y : X) : + 0 ≤ rowDensity K r x y := mul_nonneg (Nat.cast_nonneg _) (kernel_pow_nonneg K hK r x y) + +omit [Nonempty X] in +lemma rowDensity_succ (K : Matrix X X ℝ) (r : ℕ) (x y : X) : + rowDensity K (r+1) x y = act K (rowDensity K r x) y := by + simp only [rowDensity,pow_succ,Matrix.mul_apply,act,Finset.mul_sum] + apply Finset.sum_congr rfl + intro z _ + ring + +lemma rowDensity_mean (K : Matrix X X ℝ) (hrow : ∀ x, ∑ y, K x y = 1) (r : ℕ) (x : X) : + finiteMean (rowDensity K r x) = 1 := by + have hN : (Fintype.card X:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos) + simp only [finiteMean,rowDensity,←Finset.mul_sum,kernel_pow_row K hrow,mul_one,div_self hN] + +lemma rowDensity_moment_iter (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^(p^r)) ≤ Real.exp (A*r*p^r) := by + induction r with + | zero => simp [rowDensity_mean K hrow] + | succ r ih => + have hpr : 1 ≤ p^r := one_le_pow₀ hp + have hps : 1 ≤ p^(r+1) := one_le_pow₀ hp + simp_rw [rowDensity_succ] + calc + _ ≤ Real.exp A*(finiteMean (fun y => (rowDensity K r x y)^(p^r)))^p := by + rw [pow_succ] + exact act_b_to_pb K hK hcol hp hpr hm _ (rowDensity_nonneg K hK r x) + _ ≤ Real.exp A*(Real.exp (A*r*p^r))^p := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + exact Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) ih (le_trans zero_le_one hp) + _ = Real.exp (A+A*r*p^(r+1)) := by rw [←Real.exp_mul,←Real.exp_add,pow_succ]; congr 1; ring + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left hps hA + push_cast + nlinarith + +lemma rowDensity_second_moment (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x : X) : + finiteMean (fun y => (rowDensity K r x y)^2) ≤ Real.exp (2*A*r) := by + have hpos : 0 < p^r := by linarith + have hj := mean_rpow_concave (fun y => (rowDensity K r x y)^(p^r)) + (fun y => Real.rpow_nonneg (rowDensity_nonneg K hK r x y) _) + (a := 2/(p^r)) (by positivity) ((div_le_one hpos).mpr hr) + have he (y : X) : ((rowDensity K r x y)^(p^r))^(2/(p^r)) = (rowDensity K r x y)^2 := by + rw [←Real.rpow_mul (rowDensity_nonneg K hK r x y)] + rw [mul_div_cancel₀ _ (ne_of_gt hpos),Real.rpow_two] + simp_rw [he] at hj + apply hj.trans + calc + _ ≤ (Real.exp (A*r*p^r))^(2/(p^r)) := + Real.rpow_le_rpow (mean_nonneg _ (fun y => Real.rpow_nonneg + (rowDensity_nonneg K hK r x y) _)) (rowDensity_moment_iter K hK hrow hcol hp hA hm r x) + (by positivity) + _ = _ := by rw [←Real.exp_mul]; congr 1; field_simp [ne_of_gt hpos] + +lemma symmetric_kernel_smoothing (K : Matrix X X ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hrow : ∀ x, ∑ y, K x y = 1) (hcol : ∀ y, ∑ x, K x y = 1) + (hsym : K.IsSymm) {p A : ℝ} (hp : 1 ≤ p) (hA : 0 ≤ A) + (hm : ∀ x, finiteMean (fun y => ((Fintype.card X:ℝ)*K x y)^p) ≤ Real.exp A) + (r : ℕ) (hr : 2 ≤ p^r) (x y : X) : + (K^(2*r)) x y ≤ Real.exp (2*A*r)/(Fintype.card X:ℝ) := by + have hN : (0:ℝ) < Fintype.card X := Nat.cast_pos.mpr Fintype.card_pos + have hs : ∀ z, (K^r) z y = (K^r) y z := fun z => (hsym.pow r).apply y z + have he : (Fintype.card X:ℝ)*(K^(2*r)) x y = + finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) := by + simp only [finiteMean,rowDensity,two_mul,pow_add,Matrix.mul_apply,hs,Finset.mul_sum] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro z _ + field_simp + have hh : finiteMean (fun z => rowDensity K r x z*rowDensity K r y z) ≤ + Real.exp (2*A*r) := by + calc + _ ≤ finiteMean (fun z => ((rowDensity K r x z)^2+(rowDensity K r y z)^2)/2) := by + apply finiteMean_mono + intro z + nlinarith [sq_nonneg (rowDensity K r x z-rowDensity K r y z)] + _ = (finiteMean (fun z => (rowDensity K r x z)^2)+ + finiteMean (fun z => (rowDensity K r y z)^2))/2 := by + simp only [div_eq_mul_inv,finiteMean_mul_const,finiteMean_add] + _ ≤ _ := by + have hx := rowDensity_second_moment K hK hrow hcol hp hA hm r hr x + have hy := rowDensity_second_moment K hK hrow hcol hp hA hm r hr y + linarith + apply (le_div_iff₀ hN).mpr + simpa only [←he,mul_comm (Fintype.card X:ℝ)] using hh + +lemma density_exponent_numeric : 2 ≤ (1+(1/1000:ℝ))^(1000:ℕ) := by + calc + (2:ℝ) = 1+(1000:ℝ)*(1/1000) := by norm_num + _ ≤ _ := by simpa only [Nat.cast_ofNat] using + (one_add_mul_le_pow (a := (1/1000:ℝ)) (by norm_num) 1000) + +end Thorp.StrongSmoothing + +namespace Thorp.StrongSmoothing.PermLaw +open scoped BigOperators +variable {X Ω Ω' : Type*} [Fintype X] [DecidableEq X] [Fintype Ω] [Fintype Ω'] + +noncomputable def kernel (P : Ω → Equiv.Perm X) : Matrix X X ℝ := + fun x y => finiteMean (fun ω => if P ω x = y then (1:ℝ) else 0) + +omit [Fintype X] in +lemma nonneg (P : Ω → Equiv.Perm X) (x y : X) : 0 ≤ kernel P x y := by + exact finiteMean_nonneg (fun ω => by split_ifs <;> norm_num) + +lemma row [Nonempty Ω] (P : Ω → Equiv.Perm X) (x : X) : ∑ y, kernel P x y = 1 := by + simp only [kernel,←finiteMean_sum] + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte,finiteMean_const] + +omit [Fintype X] in +lemma inverse (P : Ω → Equiv.Perm X) : kernel (fun ω => (P ω)⁻¹) = (kernel P).transpose := by + ext x y + apply finiteMean_congr + intro ω + have he : (P ω)⁻¹ x=y ↔ P ω y=x := by + change (P ω).symm x=y ↔ P ω y=x + exact (Equiv.symm_apply_eq (P ω)).trans eq_comm + simp only [he] + +lemma col [Nonempty Ω] (P : Ω → Equiv.Perm X) (y : X) : ∑ x, kernel P x y = 1 := by + have hh := row (fun ω => (P ω)⁻¹) y + rw [inverse] at hh + exact hh + +lemma mul (P : Ω → Equiv.Perm X) (Q : Ω' → Equiv.Perm X) : + kernel (fun ω : Ω × Ω' => P ω.1*Q ω.2) = kernel Q*kernel P := by + ext x y + simp only [Matrix.mul_apply,kernel] + have he (ω : Ω × Ω') : + (if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = + ∑ z : X, (if P ω.1 z=y then (1:ℝ) else 0)*(if Q ω.2 x=z then (1:ℝ) else 0) := by + simp only [mul_ite,mul_one,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] + rfl + change finiteMean (fun ω : Ω × Ω' => if (P ω.1*Q ω.2) x=y then (1:ℝ) else 0) = _ + simp_rw [he] + rw [finiteMean_sum] + apply Finset.sum_congr rfl + intro z _ + exact (finiteMean_prod_mul (fun ω : Ω => if P ω z=y then (1:ℝ) else 0) + (fun ω : Ω' => if Q ω x=z then (1:ℝ) else 0)).trans (mul_comm _ _) + +omit [Fintype X] in +lemma conjugate (P : Ω → Equiv.Perm X) (e : Equiv.Perm X) (x y : X) : + kernel (fun ω => e*P ω*e⁻¹) x y = kernel P (e.symm x) (e.symm y) := by + apply finiteMean_congr + intro ω + have he : (e*P ω*e⁻¹) x=y ↔ P ω (e.symm x)=e.symm y := by + change e (P ω (e.symm x))=y ↔ _ + exact (Equiv.eq_symm_apply e).symm + simp only [he] + +end Thorp.StrongSmoothing.PermLaw + +namespace Thorp.StrongSmoothing +open scoped BigOperators + +section MatrixHelpers +variable {X : Type*} [Fintype X] [DecidableEq X] + +omit [DecidableEq X] in +lemma mul_nonneg_entries (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hB : ∀ x y, 0 ≤ B x y) (x y : X) : 0 ≤ (A*B) x y := + Finset.sum_nonneg (fun z _ => mul_nonneg (hA x z) (hB z y)) + +omit [DecidableEq X] in +lemma mul_row (A B : Matrix X X ℝ) (hA : ∀ x, ∑ y, A x y = 1) + (hB : ∀ x, ∑ y, B x y = 1) (x : X) : ∑ y, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.mul_sum,hB,mul_one,hA] + +omit [DecidableEq X] in +lemma mul_col (A B : Matrix X X ℝ) (hA : ∀ y, ∑ x, A x y = 1) + (hB : ∀ y, ∑ x, B x y = 1) (y : X) : ∑ x, (A*B) x y = 1 := by + simp only [Matrix.mul_apply] + rw [Finset.sum_comm] + simp only [←Finset.sum_mul,hA,one_mul,hB] + +omit [DecidableEq X] in +lemma bound_mul_left (A B : Matrix X X ℝ) (hA : ∀ x y, 0 ≤ A x y) + (hrow : ∀ x, ∑ y, A x y = 1) {D : ℝ} (hB : ∀ x y, B x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, A x z*D := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_left (hB z y) (hA x z)) + _ = D := by rw [←Finset.sum_mul,hrow,one_mul] + +omit [DecidableEq X] in +lemma bound_mul_right (A B : Matrix X X ℝ) (hB : ∀ x y, 0 ≤ B x y) + (hcol : ∀ y, ∑ x, B x y = 1) {D : ℝ} (hA : ∀ x y, A x y ≤ D) : + ∀ x y, (A*B) x y ≤ D := by + intro x y + calc + _ ≤ ∑ z, D*B z y := Finset.sum_le_sum (fun z _ => mul_le_mul_of_nonneg_right (hA x z) (hB z y)) + _ = D := by rw [←Finset.mul_sum,hcol,mul_one] + +lemma sandwich_power (A B : Matrix X X ℝ) (r : ℕ) : A*(B*A)^r*B = (A*B)^(r+1) := by + induction r with + | zero => simp + | succ r ih => + calc + _ = (A*(B*A)^r*B)*(A*B) := by rw [pow_succ]; noncomm_ring + _ = (A*B)^(r+1)*(A*B) := by rw [ih] + _ = _ := (pow_succ (A*B) (r+1)).symm + +end MatrixHelpers + +section TupleAction +variable {ι β Ω : Type*} [Fintype ι] [Fintype β] [DecidableEq β] [Fintype Ω] + +def tuplePerm (P : Equiv.Perm β) : Equiv.Perm (ι ↪ β) where + toFun x := x.trans P.toEmbedding + invFun x := x.trans P.symm.toEmbedding + left_inv x := by ext i; simp + right_inv x := by ext i; simp + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +@[simp] lemma tuplePerm_apply (P : Equiv.Perm β) (x : ι ↪ β) (i : ι) : + tuplePerm P x i = P (x i) := rfl + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +lemma tuplePerm_mul (P Q : Equiv.Perm β) : + tuplePerm (ι := ι) (P*Q) = tuplePerm P*tuplePerm Q := by + ext x i + rfl + +omit [Fintype ι] [Fintype β] [DecidableEq β] in +lemma tuplePerm_inverse (P : Equiv.Perm β) : + tuplePerm (ι := ι) P⁻¹ = (tuplePerm P)⁻¹ := by + ext x i + rfl + +omit [Fintype β] in +lemma tupleProbability_kernel (P : Ω → Equiv.Perm β) (x y : ι ↪ β) : + PairRouting.tupleProbability P x y = PermLaw.kernel (fun ω => tuplePerm (P ω)) x y := by + classical + apply finiteMean_congr + intro ω + have he : (∀ i, P ω (x i) = y i) ↔ tuplePerm (P ω) x = y := by + constructor + · intro h; ext i; exact h i + · intro h i; exact congrArg (fun z : ι ↪ β => z i) h + simp only [he] +end TupleAction + +lemma sweepKernel_law (d l : ℕ) (order : Equiv.Perm (Fin d)) : + sweepKernel d l order = PermLaw.kernel (fun ω => tuplePerm (ι := Fin l) (sweep d order ω)) := by + ext x y + exact tupleProbability_kernel _ x y + +lemma reflectedKernel_conjugate (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + reflectedKernel d l order false x y = + PairRouting.tupleProbability (palindromePerm d) + ((tuplePerm (coordinateRelabel d order)).symm x) + ((tuplePerm (coordinateRelabel d order)).symm y) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + let P := fun ω => tuplePerm (ι := Fin l) (butterflyPerm d (decodeButterfly d ω)) + have hA : sweepKernel d l order = PermLaw.kernel (fun ω => e*P ω*e⁻¹) := by + rw [sweepKernel_law] + simp only [sweep,tuplePerm_mul,tuplePerm_inverse] + rfl + rw [reflectedKernel,ite_eq_right Bool.false_ne_true,hA] + rw [←PermLaw.inverse,←PermLaw.mul] + have hprod : (fun ω : BenesCoins d => (e*P ω.1*e⁻¹)*((e*P ω.2*e⁻¹)⁻¹)) = + fun ω : BenesCoins d => e*tuplePerm (ι := Fin l) (palindromePerm d ω)*e⁻¹ := by + funext ω + simp only [mul_inv_rev,inv_inv,palindromePerm,tuplePerm_mul] + change (e*P ω.1*e⁻¹)*(e*(P ω.2)⁻¹*e⁻¹) = e*(P ω.1*(P ω.2)⁻¹)*e⁻¹ + group + rw [hprod,PermLaw.conjugate,tupleProbability_kernel] + + +lemma sweepKernel_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ sweepKernel d l order x y := PairRouting.tupleProbability_nonneg _ _ _ + +lemma sweepKernel_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.row _ _ + +lemma sweepKernel_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, sweepKernel d l order x y = 1 := by + rw [sweepKernel_law] + exact PermLaw.col _ _ + +lemma reflected_nonneg (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + 0 ≤ reflectedKernel d l order false x y := by + exact mul_nonneg_entries _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_nonneg d l order) x y + +lemma reflected_row (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + ∑ y, reflectedKernel d l order false x y = 1 := + mul_row _ _ (sweepKernel_col d l order) (sweepKernel_row d l order) x + +lemma reflected_col (d l : ℕ) (order : Equiv.Perm (Fin d)) (y : Tuples d l) : + ∑ x, reflectedKernel d l order false x y = 1 := + mul_col _ _ (sweepKernel_row d l order) (sweepKernel_col d l order) y + +lemma reflected_symmetric (d l : ℕ) (order : Equiv.Perm (Fin d)) : + (reflectedKernel d l order false).IsSymm := Matrix.isSymm_transpose_mul_self _ + +lemma reflected_moment (d l : ℕ) (order : Equiv.Perm (Fin d)) (x : Tuples d l) : + finiteMean (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*reflectedKernel d l order false x y)^(1+(1/1000:ℝ))) ≤ + Real.exp (l*(1+heightDecay 1)) := by + classical + let e : Equiv.Perm (Tuples d l) := tuplePerm (coordinateRelabel d order) + simp_rw [reflectedKernel_conjugate] + have he := finiteMean_equiv e (fun y : Tuples d l => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) y)^ + (1+(1/1000:ℝ))) + change finiteMean (fun y => + ((Fintype.card (Tuples d l):ℝ)*PairRouting.tupleProbability (palindromePerm d) (e.symm x) (e.symm y))^ + (1+(1/1000:ℝ))) ≤ _ + rw [←he] + simpa only [palindromeRowMoment,Fintype.card_fin] using palindrome_row_moment_coarse d (e.symm x) + +lemma tuples_card (d l : ℕ) : Fintype.card (Tuples d l) = (2^d).descFactorial l := by + simp only [Tuples,Fintype.card_embedding_eq,Fintype.card_fin,card_positions] + +lemma canonical_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (x y : Tuples d l) : + ((reflectedKernel d l order false)^2000) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + let : Nonempty (Tuples d l) := ⟨x⟩ + have hh := symmetric_kernel_smoothing (reflectedKernel d l order false) + (reflected_nonneg d l order) (reflected_row d l order) (reflected_col d l order) + (reflected_symmetric d l order) (p := 1+(1/1000:ℝ)) (A := l*(1+heightDecay 1)) + (by norm_num) (mul_nonneg (Nat.cast_nonneg _) (by linarith [heightDecay_nonneg 1])) + (reflected_moment d l order) 1000 density_exponent_numeric x y + have he : 2*((l:ℝ)*(1+heightDecay 1))*(1000:ℝ) = (2000*(1+heightDecay 1))*l := by ring + norm_num only [show 2*1000=2000 by norm_num,Nat.cast_ofNat] at hh + simpa only [he,tuples_card] using hh + +lemma both_pointwise (d l : ℕ) (order : Equiv.Perm (Fin d)) (orientation : Bool) + (x y : Tuples d l) : + ((reflectedKernel d l order orientation)^2001) x y ≤ + Real.exp ((2000*(1+heightDecay 1))*l)/((2^d).descFactorial l:ℝ) := by + cases orientation + · change ((reflectedKernel d l order false)^(2000+1)) x y ≤ _ + rw [pow_succ] + exact bound_mul_right _ _ (reflected_nonneg d l order) (reflected_col d l order) + (canonical_pointwise d l order) x y + · let A := sweepKernel d l order + change ((A*A.transpose)^(2000+1)) x y ≤ _ + rw [←sandwich_power] + apply bound_mul_right _ _ (fun x y => sweepKernel_nonneg d l order y x) + (sweepKernel_row d l order) + exact bound_mul_left _ _ (sweepKernel_nonneg d l order) (sweepKernel_row d l order) + (canonical_pointwise d l order) + +lemma regular_trace_bound (d : ℕ) (order : Equiv.Perm (Fin d)) : + regularAbsoluteEvenTrace d order 2001 ≤ Real.exp ((2000*(1+heightDecay 1))*(2:ℝ)^d) := by + have hn : 0 < Fintype.card (Tuples d (2^d)) := by + rw [tuples_card,Nat.descFactorial_self] + exact Nat.factorial_pos _ + have hn' : (Fintype.card (Tuples d (2^d)):ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt hn) + calc + _ ≤ ∑ x : Tuples d (2^d), Real.exp ((2000*(1+heightDecay 1))*(2^d:ℕ)) / + ((2^d).descFactorial (2^d):ℝ) := by + apply Finset.sum_le_sum + intro x _ + exact both_pointwise d (2^d) order false x x + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←tuples_card] + push_cast + field_simp + +theorem strong_smoothing : MainStatement := by + refine ⟨2001,by norm_num,2000*(1+heightDecay 1),?_,regular_trace_bound⟩ + intro d l _ order orientation x y + exact both_pointwise d l order orientation x y + +end Thorp.StrongSmoothing + +namespace Thorp.StrongTail +open scoped BigOperators Classical +open Specht + +lemma mem_tailDiagram (μ : YoungDiagram) (i j : ℕ) : + (i,j) ∈ tailDiagram μ ↔ (i+1,j) ∈ μ := by + rw [tailDiagram, YoungDiagram.mem_ofRowLens] + constructor + · rintro ⟨hi,hj⟩ + rw [List.getElem_tail,YoungDiagram.get_rowLens] at hj + exact YoungDiagram.mem_iff_lt_rowLen.mpr hj + · intro h + have hi : i+1 < μ.colLen 0 := + (YoungDiagram.mem_iff_lt_colLen.mp h).trans_le (μ.colLen_anti 0 j (Nat.zero_le _)) + have hi' : i < μ.rowLens.tail.length := by simp only [List.length_tail,YoungDiagram.length_rowLens]; omega + refine ⟨hi', ?_⟩ + simpa only [List.getElem_tail,YoungDiagram.get_rowLens] using YoungDiagram.mem_iff_lt_rowLen.mp h + +lemma tail_height (μ : YoungDiagram) : (tailDiagram μ).colLen 0 = μ.colLen 0 - 1 := by + rw [←YoungDiagram.length_rowLens] + exact (YoungDiagram.rowLens_length_ofRowLens (fun x hx => μ.pos_of_mem_rowLens x (List.mem_of_mem_tail hx))).trans + (by simp only [List.length_tail,YoungDiagram.length_rowLens]) + +end Thorp.StrongTail + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/Tail/TypedMarks.lean b/lean/OAI/Probability/ThorpRouting/Tail/TypedMarks.lean index dadf09c4a09fa6c471deb1240693cf5a607b990e..991ebfbebe6638ec6e2b805b88ccd79398ee2035 100644 --- a/lean/OAI/Probability/ThorpRouting/Tail/TypedMarks.lean +++ b/lean/OAI/Probability/ThorpRouting/Tail/TypedMarks.lean @@ -1,882 +1,882 @@ -import Mathlib -import OAI.Probability.ThorpRouting.Tail.ModifiedStageEquiv - -namespace OAI - -namespace ThorpNine.Tail - -namespace Thorp.SparseContact -open scoped BigOperators Classical - -noncomputable def typedMarks {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : Finset (N × Card d) := - typedSet (fun t => butterflyMarks d (A t) (ω t)) - -lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : - (typedMarks d A ω).card = ∑ t, (A t).card := by - classical - rw [typedMarks, typedSet_card] - apply Finset.sum_congr rfl - intro t _ - exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective - -lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (D : Finset (N × Card d)) : - inclusionMoment (typedMarks d A) D ≤ - ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by - classical - have he : inclusionMoment (typedMarks d A) D = - ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by - rw [inclusionMoment_eq] - have hh (ω : N → (SwitchIndex d → Bool)) : - (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = - ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by - rw [Fintype.prod_boole] - simp only [typedMarks, subset_typedSet] - rw [finiteMean_congr hh] - simp only [inclusionMoment_eq] - exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) - (fun t (ω : SwitchIndex d → Bool) => - if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) - have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = - ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by - conv_lhs => rw [← typedSet_fiber D] - exact typedSet_prod _ _ - rw [he, hprod] - apply Finset.prod_le_prod₀ - · intro t _; exact inclusionMoment_nonneg _ _ - · intro t _ - simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) - -noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (v : N × Card d) : Finset (SwitchIndex d) := - routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 - -noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : - SimpleGraph (N × Card d) where - Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) - symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ - loopless := ⟨fun _ h => h.1 rfl⟩ - -lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : - (returnRoute d b v).card = d := card_routeDomain _ _ _ - -lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) - (t : N) (y : Card d) (i : SwitchIndex d) : - i ∈ returnRoute d b (t,y) ↔ - y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by - have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i - simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h - -lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (i : SwitchIndex d) : - (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = - 2 * ∑ t, p t := by - classical - rw [Fintype.sum_prod_type, Finset.mul_sum] - apply Finset.sum_congr rfl - intro t _ - have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ - butterflyPerm d (b t) (switchUsers d (b t) i).2 := - (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) - simp only [mem_returnRoute] - have he (y : Card d) : - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ - y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + - (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by - split_ifs <;> simp_all - simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] - ring - -lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) - (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : - (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ - 2*d*∑ t, p t := by - classical - calc - _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by - apply Finset.sum_le_sum - intro w _ - split_ifs with h - · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 - have hh := Finset.single_le_sum - (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) - (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi - simpa only [ite_eq_left hw] using hh - · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) - _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := - Finset.sum_comm - _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, - nsmul_eq_mul]; ring - -lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) : - (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro t _ - simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, - Nat.cast_ofNat, nsmul_eq_mul] - field_simp - -lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) - (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) - (hk : ∑ t, (A t).card = k) - (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : N → (SwitchIndex d → Bool) => - if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by - have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk - have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k - (fun ω => (typedMarks_card d A ω).trans hk) - (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) - (typedMarks_inclusion d A) _ hδ hδ1 - (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) - (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) - simpa only [typed_weight_sum, hs] using hm - - -lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] - (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) - (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : - finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = - finiteMean f / (2:ℝ)^s.card := by - induction s using Finset.induction_on with - | empty => simp [finiteMean] - | @insert i s hi ih => - let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 - have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by - intro ω - have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by - apply forall₂_congr - intro j hj - rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] - simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] - have he (ω : ι → Bool) : - (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = - (if ω i = v i then g ω else 0) := by - by_cases h : ω i = v i <;> simp [h,g] - rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] - have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) - change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ - rw [hs, Finset.card_insert_of_notMem hi, pow_succ] - ring - -noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := by - classical - exact finiteMean (fun ω : SwitchIndex d → Bool => - if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) - -lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ endpointProb d A x y := by - classical - exact finiteMean_nonneg (fun _ => by positivity) - -lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by - classical - let f := fun ω : SwitchIndex d → Bool => - if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 - have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by - intro t ht ω - have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ - ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by - apply forall₂_congr - intro j hj - rw [butterfly_endpoint_iff, butterfly_endpoint_iff] - apply forall₂_congr - intro s hs - rw [QueryTree.flipCoin_apply_ne t s (fun h => - Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] - simp only [f, he] - have he (ω : SwitchIndex d → Bool) : - (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = - (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by - by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i - · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h - rw [ite_eq_left hh] - simp only [Finset.forall_mem_insert, h, true_and, f] - · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h - simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] - change finiteMean _ = _ - rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] - rfl - -noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : ℝ := - ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y - -lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) (i : L) (hi : i ∉ A) - (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : - partialKernel d (insert i A) x y = partialKernel d A x y := by - classical - rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, - Finset.card_insert_of_notMem hi, pow_succ, partialKernel] - field_simp - -def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := - ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) - -lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) - (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : - (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by - classical - have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ - rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] - · rw [← Finset.sum_add_distrib] - apply Finset.sum_eq_zero - intro A hA - have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ - ((Finset.mem_powerset.mp hA) hh) - rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] - ring - · exact Finset.notMem_erase _ _ - -lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) - (x y : L → Card d) (h : ¬ContactEvent d x y) : - (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by - classical - unfold ContactEvent at h - push Not at h - obtain ⟨i, hi⟩ := h - apply alternating_cube_cancel _ i - intro A hiA - apply partialKernel_insert_isolated d A x y i hiA - intro j hj - exact hi j (fun hij => hiA (hij ▸ hj)) - - -noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by - classical - exact if i ∈ A then none else some i - -noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := - fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) - -noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := - fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) - -noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by - classical - exact fun t => match t with - | none => A - | some i => if i ∈ A then ∅ else {i} - -lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : - i ∈ labelsOf A t ↔ networkOf A i = t := by - classical - cases t with - | none => simp [labelsOf, networkOf] - | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction - -lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : - mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, - butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by - constructor - · intro h t i hi - have he := congrFun h i - simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he - · intro h - funext i - exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) - -lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) - (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : - mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by - constructor - · intro h - funext i - exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm - · intro h - funext i - exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm - -lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : - endpointProb d {i} x y = 1/(2:ℝ)^d := by - classical - simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) - -lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by - classical - have he (ω : Option L → (SwitchIndex d → Bool)) : - (if mixedTuple d A ω x = y then (1:ℝ) else 0) = - ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i - then (1:ℝ) else 0 := by - simp only [Fintype.prod_boole, mixedTuple_eq_iff] - rw [finiteMean_congr he] - rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] - have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => - if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = - endpointProb d (labelsOf A t) x y := by - unfold endpointProb - apply finiteMean_congr - intro w - split_ifs <;> rfl - simp only [hfac] - rw [Fintype.prod_option] - have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = - if i ∈ A then 1 else 1/(2:ℝ)^d := by - by_cases h : i ∈ A - · simp [labelsOf, h, endpointProb, finiteMean_const] - · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] - rw [show labelsOf A none = A from rfl] - simp only [hi] - have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = - (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by - rw [Finset.prod_ite] - simp only [Finset.prod_const_one, one_mul] - simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, - Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] - rw [hp, partialKernel, one_div, inv_pow] - have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ - have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = - ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] - have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity - have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity - field_simp - rw [← hn] - ring - -lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y z : L → Card d) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by - simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y - -noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (t : Option L) : Finset (Card d) := by - classical - exact (labelsOf A t).image x - -lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : - typedMarks d (mixedInitial d A x) ω = Finset.univ.image - (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - classical - ext v - simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, - Finset.mem_image, Finset.mem_univ, true_and] - constructor - · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ - have ht := mem_labelsOf A i v.1 |>.mp hi - exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ - · rintro ⟨i, hi⟩ - have ht := congrArg Prod.fst hi - have hv := congrArg Prod.snd hi - change networkOf A i = v.1 at ht - change mixedTuple d A ω x i = v.2 at hv - exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, - by simpa only [mixedTuple, ht] using hv⟩ - -lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω : Option L → (SwitchIndex d → Bool)) : - Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by - intro i j h - have ht := congrArg Prod.fst h - have hv := congrArg Prod.snd h - change networkOf A i = networkOf A j at ht - dsimp only [mixedTuple] at hv - rw [ht] at hv - exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) - -lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) : - (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by - classical - let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false - rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, - Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] - -lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (ω b : Option L → (SwitchIndex d → Bool)) : - ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ - NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) - (typedMarks d (mixedInitial d A x) ω) := by - classical - rw [typedMarks_mixedInitial] - let f := fun i => (networkOf A i, mixedTuple d A ω x i) - have hf : Function.Injective f := typedTuple_injective d A x hx ω - constructor - · intro h v hv - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv - obtain ⟨j,hij,hc⟩ := h i - exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, - hf.ne hij, hc⟩ - · intro h i - obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv - exact ⟨j, fun he => hij (congrArg f he), hc⟩ - -lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (hx : Function.Injective x) - (b : Option L → (SwitchIndex d → Bool)) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) - then (1:ℝ) else 0) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - simp only [contactEvent_mixedReturn_iff d A x hx] - convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) - (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 - congr 1 - exact Subsingleton.elim _ _ - - -lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] - (g : Ω → X) (f : X → ℝ) : - finiteMean (fun ω => f (g ω)) = - ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by - classical - simp_rw [← finiteMean_mul_const, ← finiteMean_sum] - apply finiteMean_congr - intro ω - simp - -lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = - ∑ y, partialKernel d A x y * f y := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] - apply Finset.sum_congr rfl - intro y _ - congr 1 - convert mixedTuple_mass d A x y using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (y : L → Card d) (f : (L → Card d) → ℝ) : - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = - ∑ z, partialKernel d A z y * f z := by - classical - rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] - apply Finset.sum_congr rfl - intro z _ - congr 1 - convert mixedReturn_mass d A y z using 1 - congr 1 - funext ω - split_ifs <;> rfl - -lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x y : L → Card d) : 0 ≤ partialKernel d A x y := - mul_nonneg (by positivity) (endpointProb_nonneg d A x y) - -noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : ℝ := by - classical - exact if ContactEvent d x y then partialKernel d A x y else 0 - -lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact partialKernel_nonneg d A x y - · exact le_rfl - -lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by - classical - unfold retainedKernel - split_ifs - · exact le_rfl - · exact partialKernel_nonneg d A x y - -lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (x : L ↪ Card d) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := by - classical - let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 - have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ - ∑ z : L → Card d, partialKernel d A z y * f y z := by - have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by - unfold retainedKernel f - split_ifs <;> ring - simp_rw [he] - rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) - (Function.Embedding.coe_injective.injOn)] - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro z _ _ - exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) - calc - _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by - rw [Finset.sum_comm] - simp only [Finset.mul_sum] - _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by - apply Finset.sum_le_sum - intro y _ - exact mul_le_mul (retainedKernel_le d A x y) (hsub y) - (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) - _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by - rw [mixedTuple_expectation d A x (fun y => - finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] - simp only [mixedReturn_expectation] - _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => - finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => - f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ - _ ≤ _ := by - apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq - exact finiteMean_const _ - -noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := - LinearMap.toContinuousLinearMap - { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) - map_add' := by - intro v w - ext x - simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] - map_smul' := by - intro c v - ext x - simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] - change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - ring } - -@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : - rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl - -lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = - rectOperator (fun y x => P x y) := by - apply Eq.symm - rw [ContinuousLinearMap.eq_adjoint_iff] - intro v w - simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, - map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = - rectOperator (fun x x' => ∑ y, P x y * P x' y) := by - ext v x - simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, - Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x' _ - apply Finset.sum_congr rfl - intro y _ - ring - -lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] - (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) - (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : - ‖rectOperator P‖^2 ≤ B := by - let S := fun x x' => ∑ y, P x y * P x' y - have hs : ∀ x x', S x x' = S x' x := by - intro x x' - unfold S - apply Finset.sum_congr rfl - intro y _ - ring - have hbound : ‖rectOperator S‖ ≤ B := by - apply ContinuousLinearMap.opNorm_le_bound _ hB - intro v - exact DensityTransfer.schur_bound S - (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB - hrow (fun x' => by - calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') - _ ≤ B := hrow x') v - have hn := ContinuousLinearMap.norm_adjoint_comp_self - (ContinuousLinearMap.adjoint (rectOperator P)) - rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), - rectOperator_adjoint, rectOperator_comp_transpose] at hn - rw [pow_two, ← hn] - exact hbound - -lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) - (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : - ‖rectOperator (retainedKernel d A)‖^2 ≤ - (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * - Real.exp (Real.exp 1*(Fintype.card L)) := - rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) - (fun x => retained_square_row d A x hδ hδ1) - - -noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where - carrier := {p | ∀ x ∈ A, p x = x} - one_mem' := by intro x _; rfl - mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] - inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm - -lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) - (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by - intro z hz - exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) - -lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : - Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by - classical - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨p,rfl⟩ := hv - let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := - { toFun := fun x => ⟨p x.1,x.2⟩ - invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ - left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ - right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } - have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by - rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] - have hr := Specht.rowLen_zero_le_card μ - omega - obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt - (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) - (by simpa only [Fintype.card_fin] using hc) - have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) - let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), - swap_mem_pointStabilizer A _ _ x.2 y.2⟩ - apply Specht.symmetrizer_eq_zero_of_neg _ _ h - change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) - (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) - rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] - rw [map_mul, Module.End.mul_apply, - Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] - | zero => exact map_zero _ - | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] - | smul a v hv ih => simp only [map_smul,ih,smul_zero] - -lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by - classical - have hz := point_symmetrizer_zero μ A hA v hv - have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = - (Fintype.card (pointStabilizer A) : ℂ) • v := by - simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), - Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] - rw [he] at hz - exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) - -lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) - (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by - let w := (Specht.spaceHilbertEquiv μ).symm v - have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by - intro p hp - have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) - change Specht.representation μ p w = w at he - exact congrArg Subtype.val he - have hz := point_fixed_zero μ A hA w.val w.prop hw - have hw0 : w = 0 := Subtype.ext hz - have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 - simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he - -lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) - (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) - (v : Specht.hilbertSpace μ) - (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by - classical - apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v - intro p hp - have hf : e.symm.permCongr p ∈ pointStabilizer A := by - intro x hx - have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) - simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] - have hh := hfix _ hf - change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh - have he : e.permCongr (e.symm.permCongr p) = p := by - apply Equiv.ext - intro x - simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] - simpa only [he] using hh - - -section Orbit -variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] - [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) - (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) - -noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -include hw in -lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by - apply ext_inner_right ℂ - intro v - exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -include hw in -lemma orbitVector_action (g : G) (x : X) : - orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by - obtain ⟨h,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, - orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] -end Orbit - -def Harmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := - ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, - (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 - -lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] - (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) - (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) - (w : Specht.hilbertSpace μ) - (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) - (v : Specht.hilbertSpace μ) : - Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by - classical - intro A hA z - let ρ := Specht.relabelledUnitary μ e - let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w - let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 - have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by - apply (Finset.card_image_le).trans_lt - rw [← hk] - exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) - have hz : S = 0 := by - apply point_relabelled_fixed_zero μ e (A.image z) hcard - intro p hp - change ρ p S = S - simp only [S, map_sum, apply_ite, map_zero] - apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) - intro y - have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by - apply forall₂_congr - intro i hi - have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) - change p (y i) = z i ↔ y i = z i - exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff - simp only [he] - split_ifs - · exact (orbitVector_action UnitaryFinite.tupleAction x₀ - (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm - · rfl - let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) - calc - _ = c * inner ℂ S v := by - dsimp only [S] - rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, - smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] - _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] - - -lemma sum_injections {L α M : Type*} [Fintype L] [Fintype α] [AddCommMonoid M] - (F : (L → α) → M) (hF : ∀ y, ¬Function.Injective y → F y = 0) : - (∑ y : L → α, F y) = ∑ y : L ↪ α, F y := by - classical - rw [← Finset.sum_image Function.Embedding.coe_injective.injOn] - apply Eq.symm - apply Finset.sum_subset (Finset.subset_univ _) - intro y _ hy - apply hF y - intro h - exact hy (Finset.mem_image.mpr ⟨⟨y,h⟩, Finset.mem_univ _, rfl⟩) - -noncomputable def zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : EuclideanSpace ℂ (L → α) := by - classical - exact WithLp.toLp 2 (fun y => if h : Function.Injective y then f ⟨y,h⟩ else 0) - -@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] - congr 1 - -lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by - classical - simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] - -lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : - (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by - rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] - simp only [zeroExtend_inj] - -lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] - (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by - have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by - rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, - sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] - simp only [zeroExtend_inj] - nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] - -lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) - (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : - rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by - classical - ext x - rw [rectOperator_apply, sum_zeroExtend_mul] - change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 - simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, - Complex.ofReal_sum, Complex.ofReal_natCast] - simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] - rw [mul_eq_zero] - right - simp only [Finset.sum_mul] - rw [Finset.sum_comm] - apply mul_eq_zero_of_right - apply Finset.sum_eq_zero - intro ω _ - calc - _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * - (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := - by - apply Finset.sum_congr rfl - intro y _ - have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ - (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := - forall₂_congr fun _ _ => eq_comm - by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i - · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] - · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] - _ = 0 := by - rw [← Finset.mul_sum] - apply mul_eq_zero_of_right - convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> rfl - -end Thorp.SparseContact - -end ThorpNine.Tail - -end OAI +import Mathlib +import OAI.Probability.ThorpRouting.Tail.ModifiedStageEquiv + +namespace OAI + +namespace ThorpNine.Tail + +namespace Thorp.SparseContact +open scoped BigOperators Classical + +noncomputable def typedMarks {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : Finset (N × Card d) := + typedSet (fun t => butterflyMarks d (A t) (ω t)) + +lemma typedMarks_card {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (ω : N → (SwitchIndex d → Bool)) : + (typedMarks d A ω).card = ∑ t, (A t).card := by + classical + rw [typedMarks, typedSet_card] + apply Finset.sum_congr rfl + intro t _ + exact Finset.card_image_of_injective _ (butterflyPerm d (decodeButterfly d (ω t))).injective + +lemma typedMarks_inclusion {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (D : Finset (N × Card d)) : + inclusionMoment (typedMarks d A) D ≤ + ∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d := by + classical + have he : inclusionMoment (typedMarks d A) D = + ∏ t, inclusionMoment (butterflyMarks d (A t)) (fiber D t) := by + rw [inclusionMoment_eq] + have hh (ω : N → (SwitchIndex d → Bool)) : + (if D ⊆ typedMarks d A ω then (1:ℝ) else 0) = + ∏ t, if fiber D t ⊆ butterflyMarks d (A t) (ω t) then (1:ℝ) else 0 := by + rw [Fintype.prod_boole] + simp only [typedMarks, subset_typedSet] + rw [finiteMean_congr hh] + simp only [inclusionMoment_eq] + exact finiteMean_pi_prod (ι := N) (Ω := fun _ => SwitchIndex d → Bool) + (fun t (ω : SwitchIndex d → Bool) => + if fiber D t ⊆ butterflyMarks d (A t) ω then (1:ℝ) else 0) + have hprod : (∏ v ∈ D, ((A v.1).card:ℝ)/(2:ℝ)^d) = + ∏ t, ∏ x ∈ fiber D t, ((A t).card:ℝ)/(2:ℝ)^d := by + conv_lhs => rw [← typedSet_fiber D] + exact typedSet_prod _ _ + rw [he, hprod] + apply Finset.prod_le_prod₀ + · intro t _; exact inclusionMoment_nonneg _ _ + · intro t _ + simpa only [Finset.prod_const] using butterflyMarks_inclusion d (A t) (fiber D t) + +noncomputable def returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (v : N × Card d) : Finset (SwitchIndex d) := + routeDomain d ((butterflyPerm d (b v.1)).symm v.2) v.2 + +noncomputable def returnGraph {N : Type*} (d : ℕ) (b : N → Butterfly d) : + SimpleGraph (N × Card d) where + Adj v w := v ≠ w ∧ ¬Disjoint (returnRoute d b v) (returnRoute d b w) + symm := ⟨fun _ _ h => ⟨h.1.symm, fun hh => h.2 hh.symm⟩⟩ + loopless := ⟨fun _ h => h.1 rfl⟩ + +lemma returnRoute_card {N : Type*} (d : ℕ) (b : N → Butterfly d) (v : N × Card d) : + (returnRoute d b v).card = d := card_routeDomain _ _ _ + +lemma mem_returnRoute {N : Type*} (d : ℕ) (b : N → Butterfly d) + (t : N) (y : Card d) (i : SwitchIndex d) : + i ∈ returnRoute d b (t,y) ↔ + y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 := by + have h := mem_routeDomain_iff_user d (b t) ((butterflyPerm d (b t)).symm y) i + simpa only [Equiv.apply_symm_apply, returnRoute, Equiv.eq_symm_apply, eq_comm] using h + +lemma returnRoute_incidence {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (i : SwitchIndex d) : + (∑ v : N × Card d, if i ∈ returnRoute d b v then p v.1 else 0) = + 2 * ∑ t, p t := by + classical + rw [Fintype.sum_prod_type, Finset.mul_sum] + apply Finset.sum_congr rfl + intro t _ + have hne : butterflyPerm d (b t) (switchUsers d (b t) i).1 ≠ + butterflyPerm d (b t) (switchUsers d (b t) i).2 := + (butterflyPerm d (b t)).injective.ne (switchUsers_ne d (b t) i) + simp only [mem_returnRoute] + have he (y : Card d) : + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 ∨ + y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) = + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).1 then p t else 0) + + (if y = butterflyPerm d (b t) (switchUsers d (b t) i).2 then p t else 0) := by + split_ifs <;> simp_all + simp only [he, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + ring + +lemma returnGraph_degree {N : Type*} [Fintype N] (d : ℕ) (b : N → Butterfly d) + (p : N → ℝ) (hp : ∀ t, 0 ≤ p t) (v : N × Card d) : + (∑ w, if (returnGraph d b).Adj v w then p w.1 else 0) ≤ + 2*d*∑ t, p t := by + classical + calc + _ ≤ ∑ w, ∑ i ∈ returnRoute d b v, if i ∈ returnRoute d b w then p w.1 else 0 := by + apply Finset.sum_le_sum + intro w _ + split_ifs with h + · obtain ⟨i, hi, hw⟩ := Finset.not_disjoint_iff.mp h.2 + have hh := Finset.single_le_sum + (f := fun i => if i ∈ returnRoute d b w then p w.1 else 0) + (fun i _ => by split_ifs; exact hp _; exact le_rfl) hi + simpa only [ite_eq_left hw] using hh + · exact Finset.sum_nonneg (fun i _ => by split_ifs; exact hp _; exact le_rfl) + _ = ∑ i ∈ returnRoute d b v, ∑ w, if i ∈ returnRoute d b w then p w.1 else 0 := + Finset.sum_comm + _ = _ := by simp only [returnRoute_incidence, Finset.sum_const, returnRoute_card, + nsmul_eq_mul]; ring + +lemma typed_weight_sum {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) : + (∑ v : N × Card d, ((A v.1).card:ℝ)/(2:ℝ)^d) = ∑ t, ((A t).card:ℝ) := by + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro t _ + simp only [Finset.sum_const, Finset.card_univ, card_positions, Nat.cast_pow, + Nat.cast_ofNat, nsmul_eq_mul] + field_simp + +lemma mixed_return_noIsolated {N : Type*} [Fintype N] (d : ℕ) + (A : N → Finset (Card d)) (b : N → Butterfly d) (k : ℕ) + (hk : ∑ t, (A t).card = k) + (hδ : 0 < 2*(d:ℝ)*k/(2:ℝ)^d) (hδ1 : 2*(d:ℝ)*k/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : N → (SwitchIndex d → Bool) => + if NoIsolated (returnGraph d b) (typedMarks d A ω) then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*k/(2:ℝ)^d)^((k:ℝ)/2) * Real.exp (Real.exp 1*k) := by + have hs : (∑ t, ((A t).card:ℝ)) = k := by exact_mod_cast hk + have hm := noIsolated_probability_le (returnGraph d b) (typedMarks d A) k + (fun ω => (typedMarks_card d A ω).trans hk) + (fun v => ((A v.1).card:ℝ)/(2:ℝ)^d) (fun v => by positivity) + (typedMarks_inclusion d A) _ hδ hδ1 + (fun v => (returnGraph_degree d b (fun t => ((A t).card:ℝ)/(2:ℝ)^d) + (fun t => by positivity) v).trans_eq (by rw [← Finset.sum_div, hs]; ring)) + simpa only [typed_weight_sum, hs] using hm + + +lemma mean_fresh_cylinder {ι : Type*} [Fintype ι] [DecidableEq ι] + (s : Finset ι) (v : ι → Bool) (f : (ι → Bool) → ℝ) + (hf : ∀ i ∈ s, ∀ ω, f (QueryTree.flipCoin i ω) = f ω) : + finiteMean (fun ω => if ∀ i ∈ s, ω i = v i then f ω else 0) = + finiteMean f / (2:ℝ)^s.card := by + induction s using Finset.induction_on with + | empty => simp [finiteMean] + | @insert i s hi ih => + let g := fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0 + have hg : ∀ ω, g (QueryTree.flipCoin i ω) = g ω := by + intro ω + have he : (∀ j ∈ s, QueryTree.flipCoin i ω j = v j) ↔ ∀ j ∈ s, ω j = v j := by + apply forall₂_congr + intro j hj + rw [QueryTree.flipCoin_apply_ne i j (fun h => hi (h ▸ hj))] + simp only [g, he, hf i (Finset.mem_insert_self _ _) ω] + have he (ω : ι → Bool) : + (if ∀ j ∈ insert i s, ω j = v j then f ω else 0) = + (if ω i = v i then g ω else 0) := by + by_cases h : ω i = v i <;> simp [h,g] + rw [finiteMean_congr he, QueryTree.mean_indicator_bit g i (v i) hg] + have hs := ih (fun j hj => hf j (Finset.mem_insert_of_mem hj)) + change finiteMean (fun ω => if ∀ j ∈ s, ω j = v j then f ω else 0) / 2 = _ + rw [hs, Finset.card_insert_of_notMem hi, pow_succ] + ring + +noncomputable def endpointProb {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := by + classical + exact finiteMean (fun ω : SwitchIndex d → Bool => + if ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i then (1:ℝ) else 0) + +lemma endpointProb_nonneg {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ endpointProb d A x y := by + classical + exact finiteMean_nonneg (fun _ => by positivity) + +lemma endpointProb_insert_isolated {L : Type*} (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + endpointProb d (insert i A) x y = endpointProb d A x y / (2:ℝ)^d := by + classical + let f := fun ω : SwitchIndex d → Bool => + if ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0 + have hf : ∀ t ∈ routeDomain d (x i) (y i), ∀ ω, f (QueryTree.flipCoin t ω) = f ω := by + intro t ht ω + have he : (∀ j ∈ A, butterflyPerm d (decodeButterfly d (QueryTree.flipCoin t ω)) (x j) = y j) ↔ + ∀ j ∈ A, butterflyPerm d (decodeButterfly d ω) (x j) = y j := by + apply forall₂_congr + intro j hj + rw [butterfly_endpoint_iff, butterfly_endpoint_iff] + apply forall₂_congr + intro s hs + rw [QueryTree.flipCoin_apply_ne t s (fun h => + Finset.disjoint_left.mp (hiso j hj) ht (h ▸ hs))] + simp only [f, he] + have he (ω : SwitchIndex d → Bool) : + (if ∀ j ∈ insert i A, butterflyPerm d (decodeButterfly d ω) (x j) = y j then (1:ℝ) else 0) = + (if ∀ t ∈ routeDomain d (x i) (y i), ω t = routeValue d (x i) (y i) t then f ω else 0) := by + by_cases h : butterflyPerm d (decodeButterfly d ω) (x i) = y i + · have hh := (butterfly_endpoint_iff d ω (x i) (y i)).mp h + rw [ite_eq_left hh] + simp only [Finset.forall_mem_insert, h, true_and, f] + · have hh := mt (butterfly_endpoint_iff d ω (x i) (y i)).mpr h + simp only [Finset.forall_mem_insert, h, false_and, hh, ite_false] + change finiteMean _ = _ + rw [finiteMean_congr he, mean_fresh_cylinder _ _ f hf, card_routeDomain] + rfl + +noncomputable def partialKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : ℝ := + ((2:ℝ)^d)^A.card / ((2:ℝ)^d)^(Fintype.card L) * endpointProb d A x y + +lemma partialKernel_insert_isolated {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) (i : L) (hi : i ∉ A) + (hiso : ∀ j ∈ A, Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j))) : + partialKernel d (insert i A) x y = partialKernel d A x y := by + classical + rw [partialKernel, endpointProb_insert_isolated d A x y i hiso, + Finset.card_insert_of_notMem hi, pow_succ, partialKernel] + field_simp + +def ContactEvent {L : Type*} (d : ℕ) (x y : L → Card d) : Prop := + ∀ i, ∃ j, i ≠ j ∧ ¬Disjoint (routeDomain d (x i) (y i)) (routeDomain d (x j) (y j)) + +lemma alternating_cube_cancel {L : Type*} [Fintype L] (f : Finset L → ℝ) + (i : L) (hf : ∀ A, i ∉ A → f (insert i A) = f A) : + (∑ A : Finset L, (-1:ℝ)^A.card * f A) = 0 := by + classical + have hi : i ∈ (Finset.univ : Finset L) := Finset.mem_univ _ + rw [← Finset.powerset_univ, ← Finset.insert_erase hi, Finset.sum_powerset_insert] + · rw [← Finset.sum_add_distrib] + apply Finset.sum_eq_zero + intro A hA + have hiA : i ∉ A := fun hh => Finset.notMem_erase i Finset.univ + ((Finset.mem_powerset.mp hA) hh) + rw [hf A hiA, Finset.card_insert_of_notMem hiA, pow_succ] + ring + · exact Finset.notMem_erase _ _ + +lemma alternating_kernel_cancel {L : Type*} [Fintype L] (d : ℕ) + (x y : L → Card d) (h : ¬ContactEvent d x y) : + (∑ A : Finset L, (-1:ℝ)^A.card * partialKernel d A x y) = 0 := by + classical + unfold ContactEvent at h + push Not at h + obtain ⟨i, hi⟩ := h + apply alternating_cube_cancel _ i + intro A hiA + apply partialKernel_insert_isolated d A x y i hiA + intro j hj + exact hi j (fun hij => hiA (hij ▸ hj)) + + +noncomputable def networkOf {L : Type*} (A : Finset L) (i : L) : Option L := by + classical + exact if i ∈ A then none else some i + +noncomputable def mixedTuple {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x : L → Card d) : L → Card d := + fun i => butterflyPerm d (decodeButterfly d (ω (networkOf A i))) (x i) + +noncomputable def mixedReturn {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y : L → Card d) : L → Card d := + fun i => (butterflyPerm d (decodeButterfly d (ω (networkOf A i)))).symm (y i) + +noncomputable def labelsOf {L : Type*} (A : Finset L) : Option L → Finset L := by + classical + exact fun t => match t with + | none => A + | some i => if i ∈ A then ∅ else {i} + +lemma mem_labelsOf {L : Type*} (A : Finset L) (i : L) (t : Option L) : + i ∈ labelsOf A t ↔ networkOf A i = t := by + classical + cases t with + | none => simp [labelsOf, networkOf] + | some j => by_cases hj : j ∈ A <;> by_cases hi : i ∈ A <;> simp_all [labelsOf, networkOf] <;> intro h <;> subst j <;> contradiction + +lemma mixedTuple_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (x y : L → Card d) : + mixedTuple d A ω x = y ↔ ∀ t, ∀ i ∈ labelsOf A t, + butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i := by + constructor + · intro h t i hi + have he := congrFun h i + simpa only [mixedTuple, mem_labelsOf A i t |>.mp hi] using he + · intro h + funext i + exact h (networkOf A i) i (mem_labelsOf A i _ |>.mpr rfl) + +lemma mixedReturn_eq_iff {L : Type*} (d : ℕ) (A : Finset L) + (ω : Option L → (SwitchIndex d → Bool)) (y z : L → Card d) : + mixedReturn d A ω y = z ↔ mixedTuple d A ω z = y := by + constructor + · intro h + funext i + exact (Equiv.symm_apply_eq _).mp (congrFun h i) |>.symm + · intro h + funext i + exact (Equiv.symm_apply_eq _).mpr (congrFun h i).symm + +lemma endpointProb_singleton {L : Type*} (d : ℕ) (i : L) (x y : L → Card d) : + endpointProb d {i} x y = 1/(2:ℝ)^d := by + classical + simpa [endpointProb] using butterfly_single_card_uniform d (x i) (y i) + +lemma mixedTuple_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedTuple d A ω x = y then (1:ℝ) else 0) = partialKernel d A x y := by + classical + have he (ω : Option L → (SwitchIndex d → Bool)) : + (if mixedTuple d A ω x = y then (1:ℝ) else 0) = + ∏ t, if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d (ω t)) (x i) = y i + then (1:ℝ) else 0 := by + simp only [Fintype.prod_boole, mixedTuple_eq_iff] + rw [finiteMean_congr he] + rw [finiteMean_pi_prod (fun t (w : SwitchIndex d → Bool) => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)] + have hfac (t : Option L) : (finiteMean (fun w : SwitchIndex d → Bool => + if ∀ i ∈ labelsOf A t, butterflyPerm d (decodeButterfly d w) (x i) = y i then (1:ℝ) else 0)) = + endpointProb d (labelsOf A t) x y := by + unfold endpointProb + apply finiteMean_congr + intro w + split_ifs <;> rfl + simp only [hfac] + rw [Fintype.prod_option] + have hi (i : L) : endpointProb d (labelsOf A (some i)) x y = + if i ∈ A then 1 else 1/(2:ℝ)^d := by + by_cases h : i ∈ A + · simp [labelsOf, h, endpointProb, finiteMean_const] + · simp only [labelsOf, ite_eq_right h, endpointProb_singleton] + rw [show labelsOf A none = A from rfl] + simp only [hi] + have hp : (∏ i : L, if i ∈ A then (1:ℝ) else 1/(2:ℝ)^d) = + (1/(2:ℝ)^d)^((Fintype.card L) - A.card) := by + rw [Finset.prod_ite] + simp only [Finset.prod_const_one, one_mul] + simp only [Finset.filter_not, Finset.filter_mem_eq_inter, Finset.univ_inter, + Finset.prod_const, Finset.card_sdiff, Finset.inter_univ, Finset.card_univ] + rw [hp, partialKernel, one_div, inv_pow] + have hc : A.card ≤ Fintype.card L := Finset.card_le_univ _ + have hn : (((2:ℝ)^d)^A.card) * (((2:ℝ)^d)^(Fintype.card L - A.card)) = + ((2:ℝ)^d)^(Fintype.card L) := by rw [← pow_add, Nat.add_sub_of_le hc] + have hnz : ((2:ℝ)^d)^(Fintype.card L) ≠ 0 := by positivity + have hmz : ((2:ℝ)^d)^(Fintype.card L - A.card) ≠ 0 := by positivity + field_simp + rw [← hn] + ring + +lemma mixedReturn_mass {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y z : L → Card d) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if mixedReturn d A ω y = z then (1:ℝ) else 0) = partialKernel d A z y := by + simpa only [mixedReturn_eq_iff] using mixedTuple_mass d A z y + +noncomputable def mixedInitial {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (t : Option L) : Finset (Card d) := by + classical + exact (labelsOf A t).image x + +lemma typedMarks_mixedInitial {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (ω : Option L → (SwitchIndex d → Bool)) : + typedMarks d (mixedInitial d A x) ω = Finset.univ.image + (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + classical + ext v + simp only [typedMarks, mem_typedSet, butterflyMarks, mixedInitial, + Finset.mem_image, Finset.mem_univ, true_and] + constructor + · rintro ⟨z, ⟨i,hi,rfl⟩, hv⟩ + have ht := mem_labelsOf A i v.1 |>.mp hi + exact ⟨i, Prod.ext ht (by simpa only [mixedTuple, ht] using hv)⟩ + · rintro ⟨i, hi⟩ + have ht := congrArg Prod.fst hi + have hv := congrArg Prod.snd hi + change networkOf A i = v.1 at ht + change mixedTuple d A ω x i = v.2 at hv + exact ⟨x i, ⟨i, mem_labelsOf A i v.1 |>.mpr ht, rfl⟩, + by simpa only [mixedTuple, ht] using hv⟩ + +lemma typedTuple_injective {L : Type*} (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω : Option L → (SwitchIndex d → Bool)) : + Function.Injective (fun i => (networkOf A i, mixedTuple d A ω x i)) := by + intro i j h + have ht := congrArg Prod.fst h + have hv := congrArg Prod.snd h + change networkOf A i = networkOf A j at ht + dsimp only [mixedTuple] at hv + rw [ht] at hv + exact hx ((butterflyPerm d (decodeButterfly d (ω (networkOf A j)))).injective hv) + +lemma mixedInitial_card {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) : + (∑ t, (mixedInitial d A x t).card) = Fintype.card L := by + classical + let ω : Option L → (SwitchIndex d → Bool) := fun _ _ => false + rw [← typedMarks_card d (mixedInitial d A x) ω, typedMarks_mixedInitial, + Finset.card_image_of_injective _ (typedTuple_injective d A x hx ω), Finset.card_univ] + +lemma contactEvent_mixedReturn_iff {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (ω b : Option L → (SwitchIndex d → Bool)) : + ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) ↔ + NoIsolated (returnGraph d (fun t => decodeButterfly d (b t))) + (typedMarks d (mixedInitial d A x) ω) := by + classical + rw [typedMarks_mixedInitial] + let f := fun i => (networkOf A i, mixedTuple d A ω x i) + have hf : Function.Injective f := typedTuple_injective d A x hx ω + constructor + · intro h v hv + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hv + obtain ⟨j,hij,hc⟩ := h i + exact ⟨f j, Finset.mem_image.mpr ⟨j, Finset.mem_univ _,rfl⟩, + hf.ne hij, hc⟩ + · intro h i + obtain ⟨v,hv,hij,hc⟩ := h (f i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hv + exact ⟨j, fun he => hij (congrArg f he), hc⟩ + +lemma probability_mixed_contact {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (hx : Function.Injective x) + (b : Option L → (SwitchIndex d → Bool)) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + if ContactEvent d (mixedReturn d A b (mixedTuple d A ω x)) (mixedTuple d A ω x) + then (1:ℝ) else 0) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + simp only [contactEvent_mixedReturn_iff d A x hx] + convert mixed_return_noIsolated d (mixedInitial d A x) (fun t => decodeButterfly d (b t)) + (Fintype.card L) (mixedInitial_card d A x hx) hδ hδ1 using 1 + congr 1 + exact Subsingleton.elim _ _ + + +lemma finiteMean_pushforward {Ω X : Type*} [Fintype Ω] [Fintype X] + (g : Ω → X) (f : X → ℝ) : + finiteMean (fun ω => f (g ω)) = + ∑ y, finiteMean (fun ω => if g ω = y then (1:ℝ) else 0) * f y := by + classical + simp_rw [← finiteMean_mul_const, ← finiteMean_sum] + apply finiteMean_congr + intro ω + simp + +lemma mixedTuple_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedTuple d A ω x)) = + ∑ y, partialKernel d A x y * f y := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedTuple d A ω x) f] + apply Finset.sum_congr rfl + intro y _ + congr 1 + convert mixedTuple_mass d A x y using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma mixedReturn_expectation {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (y : L → Card d) (f : (L → Card d) → ℝ) : + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => f (mixedReturn d A ω y)) = + ∑ z, partialKernel d A z y * f z := by + classical + rw [finiteMean_pushforward (fun ω : Option L → (SwitchIndex d → Bool) => mixedReturn d A ω y) f] + apply Finset.sum_congr rfl + intro z _ + congr 1 + convert mixedReturn_mass d A y z using 1 + congr 1 + funext ω + split_ifs <;> rfl + +lemma partialKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x y : L → Card d) : 0 ≤ partialKernel d A x y := + mul_nonneg (by positivity) (endpointProb_nonneg d A x y) + +noncomputable def retainedKernel {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : ℝ := by + classical + exact if ContactEvent d x y then partialKernel d A x y else 0 + +lemma retainedKernel_nonneg {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : 0 ≤ retainedKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact partialKernel_nonneg d A x y + · exact le_rfl + +lemma retainedKernel_le {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) (y : L → Card d) : retainedKernel d A x y ≤ partialKernel d A x y := by + classical + unfold retainedKernel + split_ifs + · exact le_rfl + · exact partialKernel_nonneg d A x y + +lemma retained_square_row {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (x : L ↪ Card d) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + (∑ x' : L ↪ Card d, ∑ y : L → Card d, retainedKernel d A x y * retainedKernel d A x' y) ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := by + classical + let f := fun y z : L → Card d => if ContactEvent d z y then (1:ℝ) else 0 + have hsub (y : L → Card d) : (∑ x' : L ↪ Card d, retainedKernel d A x' y) ≤ + ∑ z : L → Card d, partialKernel d A z y * f y z := by + have he (x' : L ↪ Card d) : retainedKernel d A x' y = partialKernel d A x' y * f y x' := by + unfold retainedKernel f + split_ifs <;> ring + simp_rw [he] + rw [← Finset.sum_image (f := fun z => partialKernel d A z y * f y z) + (Function.Embedding.coe_injective.injOn)] + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro z _ _ + exact mul_nonneg (partialKernel_nonneg d A z y) (by dsimp [f]; positivity) + calc + _ = ∑ y, retainedKernel d A x y * ∑ x' : L ↪ Card d, retainedKernel d A x' y := by + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + _ ≤ ∑ y, partialKernel d A x y * ∑ z : L → Card d, partialKernel d A z y * f y z := by + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul (retainedKernel_le d A x y) (hsub y) + (Finset.sum_nonneg (fun x' _ => retainedKernel_nonneg d A x' y)) (partialKernel_nonneg d A x y) + _ = finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := by + rw [mixedTuple_expectation d A x (fun y => + finiteMean (fun b : Option L → (SwitchIndex d → Bool) => f y (mixedReturn d A b y)))] + simp only [mixedReturn_expectation] + _ = finiteMean (fun b : Option L → (SwitchIndex d → Bool) => + finiteMean (fun ω : Option L → (SwitchIndex d → Bool) => + f (mixedTuple d A ω x) (mixedReturn d A b (mixedTuple d A ω x)))) := finiteMean_comm _ + _ ≤ _ := by + apply (finiteMean_mono (fun b => probability_mixed_contact d A x x.injective b hδ hδ1)).trans_eq + exact finiteMean_const _ + +noncomputable def rectOperator {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : EuclideanSpace ℂ Y →L[ℂ] EuclideanSpace ℂ X := + LinearMap.toContinuousLinearMap + { toFun := fun v => WithLp.toLp 2 (fun x => ∑ y, (P x y : ℂ)*v y) + map_add' := by + intro v w + ext x + simp only [PiLp.add_apply, mul_add, Finset.sum_add_distrib] + map_smul' := by + intro c v + ext x + simp only [PiLp.smul_apply, smul_eq_mul, RingHom.id_apply] + change (∑ y, (P x y : ℂ)*(c*v y)) = c*∑ y, (P x y : ℂ)*v y + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + ring } + +@[simp] lemma rectOperator_apply {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (v : EuclideanSpace ℂ Y) (x : X) : + rectOperator P v x = ∑ y, (P x y:ℂ)*v y := rfl + +lemma rectOperator_adjoint {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : ContinuousLinearMap.adjoint (rectOperator P) = + rectOperator (fun y x => P x y) := by + apply Eq.symm + rw [ContinuousLinearMap.eq_adjoint_iff] + intro v w + simp only [PiLp.inner_apply, RCLike.inner_apply, rectOperator_apply, + map_sum, map_mul, Complex.conj_ofReal, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_comp_transpose {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) : (rectOperator P).comp (rectOperator (fun y x => P x y)) = + rectOperator (fun x x' => ∑ y, P x y * P x' y) := by + ext v x + simp only [ContinuousLinearMap.comp_apply, rectOperator_apply, Finset.mul_sum, + Complex.ofReal_sum, Complex.ofReal_mul, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x' _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma rectOperator_norm_sq_le {X Y : Type*} [Fintype X] [Fintype Y] + (P : X → Y → ℝ) (hP : ∀ x y, 0 ≤ P x y) (B : ℝ) (hB : 0 ≤ B) + (hrow : ∀ x, (∑ x', ∑ y, P x y * P x' y) ≤ B) : + ‖rectOperator P‖^2 ≤ B := by + let S := fun x x' => ∑ y, P x y * P x' y + have hs : ∀ x x', S x x' = S x' x := by + intro x x' + unfold S + apply Finset.sum_congr rfl + intro y _ + ring + have hbound : ‖rectOperator S‖ ≤ B := by + apply ContinuousLinearMap.opNorm_le_bound _ hB + intro v + exact DensityTransfer.schur_bound S + (fun x x' => Finset.sum_nonneg (fun y _ => mul_nonneg (hP x y) (hP x' y))) B hB + hrow (fun x' => by + calc (∑ x, S x x') = ∑ x, S x' x := Finset.sum_congr rfl (fun x _ => hs x x') + _ ≤ B := hrow x') v + have hn := ContinuousLinearMap.norm_adjoint_comp_self + (ContinuousLinearMap.adjoint (rectOperator P)) + rw [ContinuousLinearMap.adjoint_adjoint, (ContinuousLinearMap.adjoint.norm_map _), + rectOperator_adjoint, rectOperator_comp_transpose] at hn + rw [pow_two, ← hn] + exact hbound + +lemma retained_norm_sq {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hδ : 0 < 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d) + (hδ1 : 2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d ≤ 1) : + ‖rectOperator (retainedKernel d A)‖^2 ≤ + (2*(d:ℝ)*(Fintype.card L)/(2:ℝ)^d)^((Fintype.card L:ℝ)/2) * + Real.exp (Real.exp 1*(Fintype.card L)) := + rectOperator_norm_sq_le _ (retainedKernel_nonneg d A) _ (by positivity) + (fun x => retained_square_row d A x hδ hδ1) + + +noncomputable def pointStabilizer {α : Type*} (A : Finset α) : Subgroup (Equiv.Perm α) where + carrier := {p | ∀ x ∈ A, p x = x} + one_mem' := by intro x _; rfl + mul_mem' := by intro p q hp hq x hx; change p (q x) = x; rw [hq x hx, hp x hx] + inv_mem' := by intro p hp x hx; exact (Equiv.Perm.inv_eq_iff_eq).mpr (hp x hx).symm + +lemma swap_mem_pointStabilizer {α : Type*} [DecidableEq α] (A : Finset α) + (x y : α) (hx : x ∉ A) (hy : y ∉ A) : Equiv.swap x y ∈ pointStabilizer A := by + intro z hz + exact Equiv.swap_apply_of_ne_of_ne (fun h => hx (h ▸ hz)) (fun h => hy (h ▸ hz)) + +lemma point_symmetrizer_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) : + Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = 0 := by + classical + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨p,rfl⟩ := hv + let e : {x : Specht.Cell μ // p x ∉ A} ≃ {x : Specht.Cell μ // x ∉ A} := + { toFun := fun x => ⟨p x.1,x.2⟩ + invFun := fun x => ⟨p.symm x.1, by simpa only [p.apply_symm_apply] using x.2⟩ + left_inv := fun x => by apply Subtype.ext; exact p.symm_apply_apply _ + right_inv := fun x => by apply Subtype.ext; exact p.apply_symm_apply _ } + have hc : μ.rowLen 0 < Fintype.card {x : Specht.Cell μ // p x ∉ A} := by + rw [Fintype.card_congr e, Fintype.card_subtype_compl, Specht.card_cell, Fintype.card_coe] + have hr := Specht.rowLen_zero_le_card μ + omega + obtain ⟨x,y,hne,hcol⟩ := Fintype.exists_ne_map_eq_of_card_lt + (fun x : {x : Specht.Cell μ // p x ∉ A} => Specht.colIndex x.1) + (by simpa only [Fintype.card_fin] using hc) + have hxy : x.1 ≠ y.1 := fun h => hne (Subtype.ext h) + let h : pointStabilizer A := ⟨Equiv.swap (p x.1) (p y.1), + swap_mem_pointStabilizer A _ _ x.2 y.2⟩ + apply Specht.symmetrizer_eq_zero_of_neg _ _ h + change Specht.tabloidRep μ (Equiv.swap (p x.1) (p y.1)) + (Specht.tabloidRep μ p (Specht.polytabloid μ)) = -Specht.tabloidRep μ p (Specht.polytabloid μ) + rw [←Module.End.mul_apply, ←map_mul, ←Equiv.mul_swap_eq_swap_mul] + rw [map_mul, Module.End.mul_apply, + Specht.swap_polytabloid x.1 y.1 hxy (congrArg Fin.val hcol), map_neg] + | zero => exact map_zero _ + | add v w hv hw ihv ihw => simp only [map_add,ihv,ihw,add_zero] + | smul a v hv ih => simp only [map_smul,ih,smul_zero] + +lemma point_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.Tabloid μ → ℂ) (hv : v ∈ Specht.space μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p v = v) : v = 0 := by + classical + have hz := point_symmetrizer_zero μ A hA v hv + have he : Specht.symmetrizer (pointStabilizer A) (Specht.tabloidRep μ) v = + (Fintype.card (pointStabilizer A) : ℂ) • v := by + simp only [Specht.symmetrizer, LinearMap.sum_apply, hfix _ (Subtype.prop _), + Finset.sum_const, Finset.card_univ, nsmul_eq_mul, Nat.cast_smul_eq_nsmul] + rw [he] at hz + exact (smul_eq_zero.mp hz).resolve_left (by exact_mod_cast Fintype.card_ne_zero) + +lemma point_unitary_fixed_zero (μ : YoungDiagram) (A : Finset (Specht.Cell μ)) + (hA : A.card < μ.card - μ.rowLen 0) (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.unitaryRepresentation μ p v = v) : v = 0 := by + let w := (Specht.spaceHilbertEquiv μ).symm v + have hw : ∀ p, p ∈ pointStabilizer A → Specht.tabloidRep μ p w.val = w.val := by + intro p hp + have he := congrArg ((Specht.spaceHilbertEquiv μ).symm) (hfix p hp) + change Specht.representation μ p w = w at he + exact congrArg Subtype.val he + have hz := point_fixed_zero μ A hA w.val w.prop hw + have hw0 : w = 0 := Subtype.ext hz + have he := congrArg (Specht.spaceHilbertEquiv μ) hw0 + simpa only [w, LinearEquiv.apply_symm_apply, map_zero] using he + +lemma point_relabelled_fixed_zero {α : Type*} [Fintype α] (μ : YoungDiagram) + (e : α ≃ Specht.Cell μ) (A : Finset α) (hA : A.card < μ.card - μ.rowLen 0) + (v : Specht.hilbertSpace μ) + (hfix : ∀ p, p ∈ pointStabilizer A → Specht.relabelledUnitary μ e p v = v) : v = 0 := by + classical + apply point_unitary_fixed_zero μ (A.image e) (by simpa only [Finset.card_image_of_injective _ e.injective] using hA) v + intro p hp + have hf : e.symm.permCongr p ∈ pointStabilizer A := by + intro x hx + have hh := hp (e x) (Finset.mem_image.mpr ⟨x,hx,rfl⟩) + simp only [Equiv.permCongr_apply, Equiv.symm_symm, hh, e.symm_apply_apply] + have hh := hfix _ hf + change Specht.unitaryRepresentation μ (e.permCongr (e.symm.permCongr p)) v = v at hh + have he : e.permCongr (e.symm.permCongr p) = p := by + apply Equiv.ext + intro x + simp only [Equiv.permCongr_apply, Equiv.symm_symm, e.apply_symm_apply] + simpa only [he] using hh + + +section Orbit +variable {G X V : Type*} [Group G] [Fintype G] [Fintype X] + [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀ = x) + (ρ : Representation ℂ G V) (w : V) (hw : UnitaryFinite.IsFixed a x₀ ρ w) + +noncomputable def orbitVector (x : X) : V := ρ (UnitaryFinite.representative a x₀ ha x) w + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +include hw in +lemma orbitVector_at (g : G) : orbitVector a x₀ ha ρ w (a g x₀) = ρ g w := by + apply ext_inner_right ℂ + intro v + exact UnitaryFinite.coefficient_at a x₀ ha ρ w hw v g + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +include hw in +lemma orbitVector_action (g : G) (x : X) : + orbitVector a x₀ ha ρ w (a g x) = ρ g (orbitVector a x₀ ha ρ w x) := by + obtain ⟨h,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply, ←map_mul, orbitVector_at a x₀ ha ρ w hw, + orbitVector_at a x₀ ha ρ w hw, map_mul, Module.End.mul_apply] +end Orbit + +def Harmonic {L α : Type*} [Fintype L] [Fintype α] (f : EuclideanSpace ℂ (L ↪ α)) : Prop := + ∀ (A : Finset L), A ≠ Finset.univ → ∀ z : L → α, + (∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then f y else 0) = 0 + +lemma normalizedCoefficient_harmonic {L α : Type*} [Fintype L] [Fintype α] + (μ : YoungDiagram) (e : α ≃ Specht.Cell μ) + (hk : Fintype.card L = μ.card - μ.rowLen 0) (x₀ : L ↪ α) + (w : Specht.hilbertSpace μ) + (hw : UnitaryFinite.IsFixed UnitaryFinite.tupleAction x₀ (Specht.relabelledUnitary μ e) w) + (v : Specht.hilbertSpace μ) : + Harmonic (UnitaryFinite.normalizedCoefficient UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) (Specht.relabelledUnitary μ e) w v) := by + classical + intro A hA z + let ρ := Specht.relabelledUnitary μ e + let F := orbitVector UnitaryFinite.tupleAction x₀ (UnitaryFinite.tupleAction_transitive x₀) ρ w + let S : Specht.hilbertSpace μ := ∑ y : L ↪ α, if ∀ i ∈ A, y i = z i then F y else 0 + have hcard : (A.image z).card < μ.card - μ.rowLen 0 := by + apply (Finset.card_image_le).trans_lt + rw [← hk] + exact Finset.card_lt_card (Finset.ssubset_univ_iff.mpr hA) + have hz : S = 0 := by + apply point_relabelled_fixed_zero μ e (A.image z) hcard + intro p hp + change ρ p S = S + simp only [S, map_sum, apply_ite, map_zero] + apply Fintype.sum_equiv (UnitaryFinite.tupleAction p) + intro y + have he : (∀ i ∈ A, UnitaryFinite.tupleAction p y i = z i) ↔ ∀ i ∈ A, y i = z i := by + apply forall₂_congr + intro i hi + have hpi : p (z i) = z i := hp _ (Finset.mem_image.mpr ⟨i, hi,rfl⟩) + change p (y i) = z i ↔ y i = z i + exact (show (p (y i) = z i) ↔ p (y i) = p (z i) by rw [hpi]).trans p.injective.eq_iff + simp only [he] + split_ifs + · exact (orbitVector_action UnitaryFinite.tupleAction x₀ + (UnitaryFinite.tupleAction_transitive x₀) ρ w hw p y).symm + · rfl + let c : ℂ := Real.sqrt ((Module.finrank ℂ (Specht.hilbertSpace μ):ℝ)/(Fintype.card (L ↪ α):ℝ)) + calc + _ = c * inner ℂ S v := by + dsimp only [S] + rw [sum_inner (𝕜 := ℂ) Finset.univ _ v, Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all only [UnitaryFinite.normalizedCoefficient, PiLp.smul_apply, + smul_eq_mul, UnitaryFinite.coefficient, F, orbitVector, inner_zero_left (𝕜 := ℂ), mul_zero, c, ρ] + _ = 0 := by rw [hz, inner_zero_left (𝕜 := ℂ) v, mul_zero] + + +lemma sum_injections {L α M : Type*} [Fintype L] [Fintype α] [AddCommMonoid M] + (F : (L → α) → M) (hF : ∀ y, ¬Function.Injective y → F y = 0) : + (∑ y : L → α, F y) = ∑ y : L ↪ α, F y := by + classical + rw [← Finset.sum_image Function.Embedding.coe_injective.injOn] + apply Eq.symm + apply Finset.sum_subset (Finset.subset_univ _) + intro y _ hy + apply hF y + intro h + exact hy (Finset.mem_image.mpr ⟨⟨y,h⟩, Finset.mem_univ _, rfl⟩) + +noncomputable def zeroExtend {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) : EuclideanSpace ℂ (L → α) := by + classical + exact WithLp.toLp 2 (fun y => if h : Function.Injective y then f ⟨y,h⟩ else 0) + +@[simp] lemma zeroExtend_inj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L ↪ α) : zeroExtend f y = f y := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_left y.injective] + congr 1 + +lemma zeroExtend_noninj {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (y : L → α) (hy : ¬Function.Injective y) : zeroExtend f y = 0 := by + classical + simp only [zeroExtend, WithLp.ofLp_toLp, dite_eq_right hy] + +lemma sum_zeroExtend_mul {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) (g : (L → α) → ℂ) : + (∑ y : L → α, g y * zeroExtend f y) = ∑ y : L ↪ α, g y * f y := by + rw [sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy, mul_zero])] + simp only [zeroExtend_inj] + +lemma norm_zeroExtend {L α : Type*} [Fintype L] [Fintype α] + (f : EuclideanSpace ℂ (L ↪ α)) : ‖zeroExtend f‖ = ‖f‖ := by + have hs : ‖zeroExtend f‖^2 = ‖f‖^2 := by + rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, + sum_injections _ (fun y hy => by rw [zeroExtend_noninj f y hy]; simp)] + simp only [zeroExtend_inj] + nlinarith [norm_nonneg (zeroExtend f), norm_nonneg f] + +lemma partial_proper_zero {L : Type*} [Fintype L] (d : ℕ) (A : Finset L) + (hA : A ≠ Finset.univ) (f : EuclideanSpace ℂ (L ↪ Card d)) (hf : Harmonic f) : + rectOperator (fun (x : L ↪ Card d) (y : L → Card d) => partialKernel d A x y) (zeroExtend f) = 0 := by + classical + ext x + rw [rectOperator_apply, sum_zeroExtend_mul] + change (∑ y : L ↪ Card d, (partialKernel d A x y : ℂ) * f y) = 0 + simp only [partialKernel, endpointProb, finiteMean, Complex.ofReal_mul, Complex.ofReal_div, + Complex.ofReal_sum, Complex.ofReal_natCast] + simp_rw [div_eq_mul_inv, mul_assoc, ← Finset.mul_sum] + rw [mul_eq_zero] + right + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply mul_eq_zero_of_right + apply Finset.sum_eq_zero + intro ω _ + calc + _ = ∑ y : L ↪ Card d, (↑(Fintype.card (SwitchIndex d → Bool)) : ℂ)⁻¹ * + (if ∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i) then f y else 0) := + by + apply Finset.sum_congr rfl + intro y _ + have hh : (∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i) ↔ + (∀ i ∈ A, y i = butterflyPerm d (decodeButterfly d ω) (x i)) := + forall₂_congr fun _ _ => eq_comm + by_cases h : ∀ i ∈ A, butterflyPerm d (decodeButterfly d ω) (x i) = y i + · simp only [ite_eq_left h, ite_eq_left (hh.mp h), Complex.ofReal_one, one_mul] + · simp only [ite_eq_right h, ite_eq_right (mt hh.mpr h), Complex.ofReal_zero, zero_mul, mul_zero] + _ = 0 := by + rw [← Finset.mul_sum] + apply mul_eq_zero_of_right + convert hf A hA (fun i => butterflyPerm d (decodeButterfly d ω) (x i)) using 1 + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> rfl + +end Thorp.SparseContact + +end ThorpNine.Tail + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/TraceBound.lean b/lean/OAI/Probability/ThorpRouting/TraceBound.lean index 0f5fc27fffb6402d6cfab7bdef0e0c0cdd6d883d..33065ea3a5cb37155f8547f2552e2f47dc51369c 100644 --- a/lean/OAI/Probability/ThorpRouting/TraceBound.lean +++ b/lean/OAI/Probability/ThorpRouting/TraceBound.lean @@ -1,105 +1,105 @@ -import OAI.Probability.ThorpRouting.TraceDecay - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.LowPlanes -open scoped BigOperators Classical -open Casimir Specht UnitaryFinite - -attribute [local instance] hsNorm hsInner hsFinite - -lemma trace_re_le_dimension_norm {V : Type*} [NormedAddCommGroup V] - [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] (A : V →L[ℂ] V) : - (LinearMap.trace ℂ V A.toLinearMap).re ≤ (Module.finrank ℂ V : ℝ) * ‖A‖ := by - let B := stdOrthonormalBasis ℂ V - rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] - simp only [Matrix.trace, Matrix.diag, Complex.re_sum, LinearMap.toMatrix_apply, - OrthonormalBasis.coe_toBasis_repr_apply, OrthonormalBasis.repr_apply_apply] - calc - _ ≤ ∑ j : Fin (Module.finrank ℂ V), ‖A‖ := by - apply Finset.sum_le_sum - intro j _ - change (inner ℂ (B j) (A (B j))).re ≤ ‖A‖ - apply (Complex.re_le_norm _).trans - apply (norm_inner_le_norm _ _).trans - simpa only [B.norm_eq_one, one_mul, mul_one] using A.le_opNorm (B j) - _ = _ := by simp - -lemma trace_power_le_dimension_norm {V : Type*} [NormedAddCommGroup V] - [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (A : V →L[ℂ] V) (u : ℕ) (hu : 0 < u) : - (LinearMap.trace ℂ V (A^u).toLinearMap).re ≤ - (Module.finrank ℂ V : ℝ) * ‖A‖^u := - (trace_re_le_dimension_norm (A^u)).trans - (mul_le_mul_of_nonneg_left (norm_pow_le' A hu) (Nat.cast_nonneg _)) - -lemma full_row_dimension (μ : YoungDiagram) (hμ : μ.rowLen 0 = μ.card) : - Module.finrank ℂ (hilbertSpace μ) = 1 := by - rw [finrank_hilbertSpace] - have hle := Submodule.finrank_le (space μ) - rw [Module.finrank_fintype_fun_eq_card] at hle - have hc : Fintype.card (Tabloid μ) ≤ 1 := by - let := tabloid_subsingleton_of_full_row μ hμ - exact Fintype.card_le_one_iff.mpr (fun _ _ => Subsingleton.elim _ _) - exact Nat.le_antisymm (hle.trans hc) (dimension_pos μ) - -lemma full_row_unique (n : ℕ) (μ ν : Shapes n) - (hμ : μ.1.card - μ.1.rowLen 0 = 0) (hν : ν.1.card - ν.1.rowLen 0 = 0) : μ = ν := by - have hcells (γ : Shapes n) (hγ : γ.1.card - γ.1.rowLen 0 = 0) : - γ.1.cells = {0} ×ˢ Finset.range n := by - have hrow : γ.1.rowLen 0 = γ.1.card := by have := rowLen_zero_le_card γ.1; omega - have he : γ.1.row 0 = γ.1.cells := Finset.eq_of_subset_of_card_le - (Finset.filter_subset _ _) (by rw [←γ.1.rowLen_eq_card]; exact hrow.ge) - rw [←he, YoungDiagram.row_eq_prod, hrow, γ.2] - apply Subtype.ext - apply YoungDiagram.ext - exact (hcells μ hμ).trans (hcells ν hν).symm - -lemma full_row_count (n : ℕ) : - (∑ μ : Shapes n, if μ.1.card - μ.1.rowLen 0 = 0 then (1 : ℝ) else 0) ≤ 1 := by - have hc : (Finset.univ.filter (fun μ : Shapes n => μ.1.card - μ.1.rowLen 0 = 0)).card ≤ 1 := by - apply Finset.card_le_one.mpr - intro μ hμ ν hν - exact full_row_unique n μ ν (Finset.mem_filter.mp hμ).2 (Finset.mem_filter.mp hν).2 - rw [Finset.sum_boole] - exact_mod_cast hc - -lemma full_row_trace (d u : ℕ) (μ : Shapes (2^d)) (hμ : μ.1.card - μ.1.rowLen 0 = 0) : - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * - absoluteTrace (V := hilbertSpace μ.1) (Q d μ) (2 * (u : ℝ)) = 1 := by - have hrow : μ.1.rowLen 0 = μ.1.card := by have := rowLen_zero_le_card μ.1; omega - have hK : K d μ.1 (cardLabels d μ) = 1 := - sampleOperator_trivial (V := hilbertSpace μ.1) _ - (relabelled_full_row μ.1 hrow (cardLabels d μ)) _ - rw [absoluteTrace_even, Q_square, hK, one_pow, full_row_dimension μ.1 hrow] - simp [full_row_dimension μ.1 hrow] - -lemma regularTrace_le (d u : ℕ) (hu : 0 < u) : - regularTrace d (2 * (u : ℝ)) ≤ 1 + tailBound d u := by - have hterm (μ : Shapes (2^d)) : - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * - absoluteTrace (V := hilbertSpace μ.1) (Q d μ) (2 * (u : ℝ)) ≤ - (if μ.1.card - μ.1.rowLen 0 = 0 then 1 else 0) + - (if μ.1.card - μ.1.rowLen 0 = 0 then 0 else - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^u) := by - by_cases hz : μ.1.card - μ.1.rowLen 0 = 0 - · simp only [hz, ite_true, add_zero, full_row_trace d u μ hz, le_refl] - · simp only [hz, ite_false, zero_add] - rw [absoluteTrace_even, Q_square, pow_two, mul_assoc] - exact mul_le_mul_of_nonneg_left - (trace_power_le_dimension_norm (V := hilbertSpace μ.1) (K d μ.1 (cardLabels d μ)) u hu) (Nat.cast_nonneg _) - calc - regularTrace d (2 * (u : ℝ)) ≤ - (∑ μ : Shapes (2^d), if μ.1.card - μ.1.rowLen 0 = 0 then (1 : ℝ) else 0) + - tailBound d u := by - rw [tailBound, ←Finset.sum_add_distrib] - exact Finset.sum_le_sum (fun μ _ => hterm μ) - _ ≤ _ := add_le_add (full_row_count _) le_rfl - -end Thorp.LowPlanes - -end ThorpNine.Harmonic - -end OAI +import OAI.Probability.ThorpRouting.TraceDecay + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.LowPlanes +open scoped BigOperators Classical +open Casimir Specht UnitaryFinite + +attribute [local instance] hsNorm hsInner hsFinite + +lemma trace_re_le_dimension_norm {V : Type*} [NormedAddCommGroup V] + [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] (A : V →L[ℂ] V) : + (LinearMap.trace ℂ V A.toLinearMap).re ≤ (Module.finrank ℂ V : ℝ) * ‖A‖ := by + let B := stdOrthonormalBasis ℂ V + rw [LinearMap.trace_eq_matrix_trace ℂ B.toBasis] + simp only [Matrix.trace, Matrix.diag, Complex.re_sum, LinearMap.toMatrix_apply, + OrthonormalBasis.coe_toBasis_repr_apply, OrthonormalBasis.repr_apply_apply] + calc + _ ≤ ∑ j : Fin (Module.finrank ℂ V), ‖A‖ := by + apply Finset.sum_le_sum + intro j _ + change (inner ℂ (B j) (A (B j))).re ≤ ‖A‖ + apply (Complex.re_le_norm _).trans + apply (norm_inner_le_norm _ _).trans + simpa only [B.norm_eq_one, one_mul, mul_one] using A.le_opNorm (B j) + _ = _ := by simp + +lemma trace_power_le_dimension_norm {V : Type*} [NormedAddCommGroup V] + [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (A : V →L[ℂ] V) (u : ℕ) (hu : 0 < u) : + (LinearMap.trace ℂ V (A^u).toLinearMap).re ≤ + (Module.finrank ℂ V : ℝ) * ‖A‖^u := + (trace_re_le_dimension_norm (A^u)).trans + (mul_le_mul_of_nonneg_left (norm_pow_le' A hu) (Nat.cast_nonneg _)) + +lemma full_row_dimension (μ : YoungDiagram) (hμ : μ.rowLen 0 = μ.card) : + Module.finrank ℂ (hilbertSpace μ) = 1 := by + rw [finrank_hilbertSpace] + have hle := Submodule.finrank_le (space μ) + rw [Module.finrank_fintype_fun_eq_card] at hle + have hc : Fintype.card (Tabloid μ) ≤ 1 := by + let := tabloid_subsingleton_of_full_row μ hμ + exact Fintype.card_le_one_iff.mpr (fun _ _ => Subsingleton.elim _ _) + exact Nat.le_antisymm (hle.trans hc) (dimension_pos μ) + +lemma full_row_unique (n : ℕ) (μ ν : Shapes n) + (hμ : μ.1.card - μ.1.rowLen 0 = 0) (hν : ν.1.card - ν.1.rowLen 0 = 0) : μ = ν := by + have hcells (γ : Shapes n) (hγ : γ.1.card - γ.1.rowLen 0 = 0) : + γ.1.cells = {0} ×ˢ Finset.range n := by + have hrow : γ.1.rowLen 0 = γ.1.card := by have := rowLen_zero_le_card γ.1; omega + have he : γ.1.row 0 = γ.1.cells := Finset.eq_of_subset_of_card_le + (Finset.filter_subset _ _) (by rw [←γ.1.rowLen_eq_card]; exact hrow.ge) + rw [←he, YoungDiagram.row_eq_prod, hrow, γ.2] + apply Subtype.ext + apply YoungDiagram.ext + exact (hcells μ hμ).trans (hcells ν hν).symm + +lemma full_row_count (n : ℕ) : + (∑ μ : Shapes n, if μ.1.card - μ.1.rowLen 0 = 0 then (1 : ℝ) else 0) ≤ 1 := by + have hc : (Finset.univ.filter (fun μ : Shapes n => μ.1.card - μ.1.rowLen 0 = 0)).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro μ hμ ν hν + exact full_row_unique n μ ν (Finset.mem_filter.mp hμ).2 (Finset.mem_filter.mp hν).2 + rw [Finset.sum_boole] + exact_mod_cast hc + +lemma full_row_trace (d u : ℕ) (μ : Shapes (2^d)) (hμ : μ.1.card - μ.1.rowLen 0 = 0) : + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * + absoluteTrace (V := hilbertSpace μ.1) (Q d μ) (2 * (u : ℝ)) = 1 := by + have hrow : μ.1.rowLen 0 = μ.1.card := by have := rowLen_zero_le_card μ.1; omega + have hK : K d μ.1 (cardLabels d μ) = 1 := + sampleOperator_trivial (V := hilbertSpace μ.1) _ + (relabelled_full_row μ.1 hrow (cardLabels d μ)) _ + rw [absoluteTrace_even, Q_square, hK, one_pow, full_row_dimension μ.1 hrow] + simp [full_row_dimension μ.1 hrow] + +lemma regularTrace_le (d u : ℕ) (hu : 0 < u) : + regularTrace d (2 * (u : ℝ)) ≤ 1 + tailBound d u := by + have hterm (μ : Shapes (2^d)) : + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * + absoluteTrace (V := hilbertSpace μ.1) (Q d μ) (2 * (u : ℝ)) ≤ + (if μ.1.card - μ.1.rowLen 0 = 0 then 1 else 0) + + (if μ.1.card - μ.1.rowLen 0 = 0 then 0 else + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^u) := by + by_cases hz : μ.1.card - μ.1.rowLen 0 = 0 + · simp only [hz, ite_true, add_zero, full_row_trace d u μ hz, le_refl] + · simp only [hz, ite_false, zero_add] + rw [absoluteTrace_even, Q_square, pow_two, mul_assoc] + exact mul_le_mul_of_nonneg_left + (trace_power_le_dimension_norm (V := hilbertSpace μ.1) (K d μ.1 (cardLabels d μ)) u hu) (Nat.cast_nonneg _) + calc + regularTrace d (2 * (u : ℝ)) ≤ + (∑ μ : Shapes (2^d), if μ.1.card - μ.1.rowLen 0 = 0 then (1 : ℝ) else 0) + + tailBound d u := by + rw [tailBound, ←Finset.sum_add_distrib] + exact Finset.sum_le_sum (fun μ _ => hterm μ) + _ ≤ _ := add_le_add (full_row_count _) le_rfl + +end Thorp.LowPlanes + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/TraceDecay.lean b/lean/OAI/Probability/ThorpRouting/TraceDecay.lean index 183b3f6ae350bfa1f05f2f6806354e8757d375a3..c686074972f8f31b045929bcfd94724cd243511f 100644 --- a/lean/OAI/Probability/ThorpRouting/TraceDecay.lean +++ b/lean/OAI/Probability/ThorpRouting/TraceDecay.lean @@ -1,180 +1,180 @@ -import OAI.Probability.ThorpRouting.TraceModel - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.LowPlanes -open scoped BigOperators Classical -open Casimir Specht UnitaryFinite - -attribute [local instance] hsNorm hsInner hsFinite - -lemma absoluteTrace_even {V : Type*} [NormedAddCommGroup V] - [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (A : V →L[ℂ] V) (u : ℕ) : - absoluteTrace A (2 * (u : ℝ)) = - (LinearMap.trace ℂ V ((star A * A)^u).toLinearMap).re := by - have he : (2 : ℝ) * u = ((2*u : ℕ) : ℝ) := by simp - unfold absoluteTrace - rw [he, CFC.rpow_eq_pow, CFC.rpow_natCast _ _ (CFC.sqrt_nonneg _), - pow_mul, pow_two, CFC.sqrt_mul_sqrt_self _ (star_mul_self_nonneg A)] - -lemma Q_square (d : ℕ) (μ : Shapes (2^d)) : - star (Q d μ) * Q d μ = K d μ.1 (cardLabels d μ) := by - unfold Q - rw [physical_sweep_adjoint _ _ (cardRepresentation_unitary d μ)] - change _ = sampleOperator (cardRepresentation d μ) (palindromePerm d) - rw [sampleOperator_palindrome _ _ (cardRepresentation_unitary d μ)] - simp only [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_adjoint] - -lemma levelScale_log (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : - Real.log n ≤ levelScale n k := by - have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk - have hkp : (0 : ℝ) < k := by exact_mod_cast (show 0 < k by omega) - have hn : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) - have hratio : 1 ≤ (n : ℝ) / k := (le_div_iff₀ hkp).mpr (by simpa using (show (k : ℝ) ≤ n by exact_mod_cast hkn)) - have hp := mul_le_mul_of_nonneg_right hkR (Real.log_nonneg hratio) - have hl := Real.log_le_sub_one_of_pos hkp - have he : Real.log ((n : ℝ) / k) = Real.log n - Real.log k := - Real.log_div hn.ne' hkp.ne' - dsimp [levelScale] - rw [he] at hp ⊢ - nlinarith - -lemma level_shape_term (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : - Real.exp (-14 * levelScale n k) ≤ ((n : ℝ)^12)⁻¹ * (1/4 : ℝ)^k := by - have hn : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) - have hl := levelScale_log n k hk hkn - have hj := levelScale_ge n k hkn - have hlog4 : Real.log (4 : ℝ) ≤ 2 := by - have h2 : Real.log (2 : ℝ) ≤ 1 := by - have ht := Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 2) - norm_num at ht - exact ht - rw [show (4 : ℝ) = 2^2 by norm_num, Real.log_pow] - norm_num - linarith - calc - _ ≤ Real.exp (-(12 * Real.log n + (k : ℝ) * Real.log 4)) := by - apply Real.exp_le_exp.mpr - have hm := mul_le_mul_of_nonneg_left hlog4 (Nat.cast_nonneg k : (0 : ℝ) ≤ k) - linarith - _ = _ := by - rw [neg_add, Real.exp_add] - congr 1 - · have he : Real.log ((n : ℝ)^12) = 12 * Real.log n := by - norm_num [Real.log_pow] - rw [Real.exp_neg, ←he, Real.exp_log (pow_pos hn _)] - · rw [show -((k : ℝ) * Real.log 4) = (k : ℝ) * (-Real.log 4) by ring, - Real.exp_nat_mul, Real.exp_neg, Real.exp_log (by norm_num : (0 : ℝ) < 4)] - norm_num - -lemma uniform_nonconstant_decay : - ∃ u : ℕ, 1 ≤ u ∧ ∀ v : ℕ, u ≤ v → - ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ), - 0 < μ.card - μ.rowLen 0 → - (Module.finrank ℂ (hilbertSpace μ) : ℝ)^2 * ‖K d μ e‖^v ≤ - Real.exp (-14 * levelScale (2^d) (μ.card - μ.rowLen 0)) := by - obtain ⟨a, ha, hlevel⟩ := level_contraction - obtain ⟨b, hb, hdim⟩ := HarmonicBounds.dimension_contraction - obtain ⟨m, hm⟩ := exists_nat_ge (max (14/a) (2/b)) - have hma : 14 ≤ a * m := by - have ht := (div_le_iff₀ ha).mp ((le_max_left _ _).trans hm) - linarith - have hmb : 2 ≤ b * m := by - have ht := (div_le_iff₀ hb).mp ((le_max_right _ _).trans hm) - linarith - have hmp : 0 < m := by - by_contra hn - have hz : m = 0 := by omega - simp only [hz, Nat.cast_zero, mul_zero] at hma - norm_num at hma - refine ⟨2*m, by omega, ?_⟩ - intro v hv d μ e hk - let D : ℝ := Module.finrank ℂ (space μ) - let L : ℝ := levelScale (2^d) (μ.card - μ.rowLen 0) - have hD : 0 < D := by dsimp [D]; exact_mod_cast dimension_pos μ - have hlogD : 0 ≤ Real.log D := Real.log_nonneg (by - dsimp [D]; exact_mod_cast dimension_pos μ) - have hμ : μ.card = 2^d := by - rw [←card_cell, ←Fintype.card_congr e, card_positions] - have hkn : μ.card - μ.rowLen 0 ≤ 2^d := by omega - have hL : 0 ≤ L := (Nat.cast_nonneg _).trans (levelScale_ge _ _ hkn) - have h₁ := pow_le_pow_left₀ (norm_nonneg (K d μ e)) (hlevel d μ e hk) m - have h₂ := pow_le_pow_left₀ (norm_nonneg (K d μ e)) (hdim d μ e hk) m - change ‖K d μ e‖^m ≤ (Real.exp (-a*L))^m at h₁ - change ‖K d μ e‖^m ≤ (Real.exp (-b*Real.log D))^m at h₂ - have hp : ‖K d μ e‖^v ≤ (Real.exp (-a*L))^m * (Real.exp (-b*Real.log D))^m := by - apply (pow_le_pow_of_le_one (norm_nonneg _) (K_norm_le_one d μ e) hv).trans - rw [two_mul, pow_add] - exact mul_le_mul h₁ h₂ (pow_nonneg (norm_nonneg _) _) (by positivity) - rw [finrank_hilbertSpace] - change D^2 * ‖K d μ e‖^v ≤ Real.exp (-14*L) - calc - _ ≤ D^2 * ((Real.exp (-a*L))^m * (Real.exp (-b*Real.log D))^m) := - mul_le_mul_of_nonneg_left hp (sq_nonneg _) - _ = Real.exp ((2-b*m)*Real.log D - (a*m)*L) := by - rw [← Real.exp_log hD, ←Real.exp_nat_mul, ←Real.exp_nat_mul, - ←Real.exp_nat_mul, ←Real.exp_add, ←Real.exp_add, Real.log_exp] - congr 1 - ring - _ ≤ _ := by - apply Real.exp_le_exp.mpr - have hfirst : (2-b*m)*Real.log D ≤ 0 := - mul_nonpos_of_nonpos_of_nonneg (by linarith) hlogD - have hlast := mul_le_mul_of_nonneg_right hma hL - linarith - -noncomputable def tailBound (d v : ℕ) : ℝ := - ∑ μ : Shapes (2^d), if μ.1.card - μ.1.rowLen 0 = 0 then 0 else - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^v - -lemma two_inverse_twelfth_le (x : ℝ) (hx : 2 ≤ x) : - (x^12)⁻¹ * 2 ≤ x^(-10 : ℤ) := by - have hxp : 0 < x := by linarith - have hsq : 2 ≤ x^2 := by nlinarith - rw [zpow_neg, zpow_ofNat] - change (x^12)⁻¹ * 2 ≤ (x^10)⁻¹ - have hpow : x^12 = x^10 * x^2 := by ring - rw [inv_mul_eq_div, inv_eq_one_div] - apply (div_le_div_iff₀ (pow_pos hxp _) (pow_pos hxp _)).mpr - rw [hpow] - nlinarith [mul_le_mul_of_nonneg_left hsq (pow_nonneg hxp.le 10)] - -lemma uniform_tail_bound : - ∃ u : ℕ, 1 ≤ u ∧ ∀ d : ℕ, 1 ≤ d → ∀ v : ℕ, u ≤ v → - tailBound d v ≤ ((2 : ℝ)^d)^(-10 : ℤ) := by - obtain ⟨u, hu, hdec⟩ := uniform_nonconstant_decay - refine ⟨u, hu, ?_⟩ - intro d hd v hv - have hn : (2 : ℝ) ≤ (2 : ℝ)^d := by - calc - (2 : ℝ) = 2^1 := by norm_num - _ ≤ 2^d := pow_le_pow_right₀ (by norm_num) hd - have hterm (μ : Shapes (2^d)) : - (if μ.1.card - μ.1.rowLen 0 = 0 then 0 else - (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^v) ≤ - (((2 : ℝ)^d)^12)⁻¹ * (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := by - split_ifs with hz - · positivity - · have hk : 0 < μ.1.card - μ.1.rowLen 0 := by omega - have hkn : μ.1.card - μ.1.rowLen 0 ≤ 2^d := by have := μ.2; omega - apply (hdec v hv d μ.1 (cardLabels d μ) hk).trans - simpa only [Nat.cast_pow, Nat.cast_ofNat] using - level_shape_term (2^d) (μ.1.card - μ.1.rowLen 0) hk hkn - calc - tailBound d v ≤ ∑ μ : Shapes (2^d), - (((2 : ℝ)^d)^12)⁻¹ * (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := - Finset.sum_le_sum (fun μ _ => hterm μ) - _ = (((2 : ℝ)^d)^12)⁻¹ * ∑ μ : Shapes (2^d), (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := - (Finset.mul_sum ..).symm - _ ≤ (((2 : ℝ)^d)^12)⁻¹ * 2 := - mul_le_mul_of_nonneg_left (shape_weight_sum _) (by positivity) - _ ≤ _ := two_inverse_twelfth_le _ hn - -end Thorp.LowPlanes - -end ThorpNine.Harmonic - -end OAI +import OAI.Probability.ThorpRouting.TraceModel + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.LowPlanes +open scoped BigOperators Classical +open Casimir Specht UnitaryFinite + +attribute [local instance] hsNorm hsInner hsFinite + +lemma absoluteTrace_even {V : Type*} [NormedAddCommGroup V] + [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (A : V →L[ℂ] V) (u : ℕ) : + absoluteTrace A (2 * (u : ℝ)) = + (LinearMap.trace ℂ V ((star A * A)^u).toLinearMap).re := by + have he : (2 : ℝ) * u = ((2*u : ℕ) : ℝ) := by simp + unfold absoluteTrace + rw [he, CFC.rpow_eq_pow, CFC.rpow_natCast _ _ (CFC.sqrt_nonneg _), + pow_mul, pow_two, CFC.sqrt_mul_sqrt_self _ (star_mul_self_nonneg A)] + +lemma Q_square (d : ℕ) (μ : Shapes (2^d)) : + star (Q d μ) * Q d μ = K d μ.1 (cardLabels d μ) := by + unfold Q + rw [physical_sweep_adjoint _ _ (cardRepresentation_unitary d μ)] + change _ = sampleOperator (cardRepresentation d μ) (palindromePerm d) + rw [sampleOperator_palindrome _ _ (cardRepresentation_unitary d μ)] + simp only [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_adjoint] + +lemma levelScale_log (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : + Real.log n ≤ levelScale n k := by + have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk + have hkp : (0 : ℝ) < k := by exact_mod_cast (show 0 < k by omega) + have hn : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hratio : 1 ≤ (n : ℝ) / k := (le_div_iff₀ hkp).mpr (by simpa using (show (k : ℝ) ≤ n by exact_mod_cast hkn)) + have hp := mul_le_mul_of_nonneg_right hkR (Real.log_nonneg hratio) + have hl := Real.log_le_sub_one_of_pos hkp + have he : Real.log ((n : ℝ) / k) = Real.log n - Real.log k := + Real.log_div hn.ne' hkp.ne' + dsimp [levelScale] + rw [he] at hp ⊢ + nlinarith + +lemma level_shape_term (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : + Real.exp (-14 * levelScale n k) ≤ ((n : ℝ)^12)⁻¹ * (1/4 : ℝ)^k := by + have hn : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hl := levelScale_log n k hk hkn + have hj := levelScale_ge n k hkn + have hlog4 : Real.log (4 : ℝ) ≤ 2 := by + have h2 : Real.log (2 : ℝ) ≤ 1 := by + have ht := Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at ht + exact ht + rw [show (4 : ℝ) = 2^2 by norm_num, Real.log_pow] + norm_num + linarith + calc + _ ≤ Real.exp (-(12 * Real.log n + (k : ℝ) * Real.log 4)) := by + apply Real.exp_le_exp.mpr + have hm := mul_le_mul_of_nonneg_left hlog4 (Nat.cast_nonneg k : (0 : ℝ) ≤ k) + linarith + _ = _ := by + rw [neg_add, Real.exp_add] + congr 1 + · have he : Real.log ((n : ℝ)^12) = 12 * Real.log n := by + norm_num [Real.log_pow] + rw [Real.exp_neg, ←he, Real.exp_log (pow_pos hn _)] + · rw [show -((k : ℝ) * Real.log 4) = (k : ℝ) * (-Real.log 4) by ring, + Real.exp_nat_mul, Real.exp_neg, Real.exp_log (by norm_num : (0 : ℝ) < 4)] + norm_num + +lemma uniform_nonconstant_decay : + ∃ u : ℕ, 1 ≤ u ∧ ∀ v : ℕ, u ≤ v → + ∀ (d : ℕ) (μ : YoungDiagram) (e : Card d ≃ Cell μ), + 0 < μ.card - μ.rowLen 0 → + (Module.finrank ℂ (hilbertSpace μ) : ℝ)^2 * ‖K d μ e‖^v ≤ + Real.exp (-14 * levelScale (2^d) (μ.card - μ.rowLen 0)) := by + obtain ⟨a, ha, hlevel⟩ := level_contraction + obtain ⟨b, hb, hdim⟩ := HarmonicBounds.dimension_contraction + obtain ⟨m, hm⟩ := exists_nat_ge (max (14/a) (2/b)) + have hma : 14 ≤ a * m := by + have ht := (div_le_iff₀ ha).mp ((le_max_left _ _).trans hm) + linarith + have hmb : 2 ≤ b * m := by + have ht := (div_le_iff₀ hb).mp ((le_max_right _ _).trans hm) + linarith + have hmp : 0 < m := by + by_contra hn + have hz : m = 0 := by omega + simp only [hz, Nat.cast_zero, mul_zero] at hma + norm_num at hma + refine ⟨2*m, by omega, ?_⟩ + intro v hv d μ e hk + let D : ℝ := Module.finrank ℂ (space μ) + let L : ℝ := levelScale (2^d) (μ.card - μ.rowLen 0) + have hD : 0 < D := by dsimp [D]; exact_mod_cast dimension_pos μ + have hlogD : 0 ≤ Real.log D := Real.log_nonneg (by + dsimp [D]; exact_mod_cast dimension_pos μ) + have hμ : μ.card = 2^d := by + rw [←card_cell, ←Fintype.card_congr e, card_positions] + have hkn : μ.card - μ.rowLen 0 ≤ 2^d := by omega + have hL : 0 ≤ L := (Nat.cast_nonneg _).trans (levelScale_ge _ _ hkn) + have h₁ := pow_le_pow_left₀ (norm_nonneg (K d μ e)) (hlevel d μ e hk) m + have h₂ := pow_le_pow_left₀ (norm_nonneg (K d μ e)) (hdim d μ e hk) m + change ‖K d μ e‖^m ≤ (Real.exp (-a*L))^m at h₁ + change ‖K d μ e‖^m ≤ (Real.exp (-b*Real.log D))^m at h₂ + have hp : ‖K d μ e‖^v ≤ (Real.exp (-a*L))^m * (Real.exp (-b*Real.log D))^m := by + apply (pow_le_pow_of_le_one (norm_nonneg _) (K_norm_le_one d μ e) hv).trans + rw [two_mul, pow_add] + exact mul_le_mul h₁ h₂ (pow_nonneg (norm_nonneg _) _) (by positivity) + rw [finrank_hilbertSpace] + change D^2 * ‖K d μ e‖^v ≤ Real.exp (-14*L) + calc + _ ≤ D^2 * ((Real.exp (-a*L))^m * (Real.exp (-b*Real.log D))^m) := + mul_le_mul_of_nonneg_left hp (sq_nonneg _) + _ = Real.exp ((2-b*m)*Real.log D - (a*m)*L) := by + rw [← Real.exp_log hD, ←Real.exp_nat_mul, ←Real.exp_nat_mul, + ←Real.exp_nat_mul, ←Real.exp_add, ←Real.exp_add, Real.log_exp] + congr 1 + ring + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have hfirst : (2-b*m)*Real.log D ≤ 0 := + mul_nonpos_of_nonpos_of_nonneg (by linarith) hlogD + have hlast := mul_le_mul_of_nonneg_right hma hL + linarith + +noncomputable def tailBound (d v : ℕ) : ℝ := + ∑ μ : Shapes (2^d), if μ.1.card - μ.1.rowLen 0 = 0 then 0 else + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^v + +lemma two_inverse_twelfth_le (x : ℝ) (hx : 2 ≤ x) : + (x^12)⁻¹ * 2 ≤ x^(-10 : ℤ) := by + have hxp : 0 < x := by linarith + have hsq : 2 ≤ x^2 := by nlinarith + rw [zpow_neg, zpow_ofNat] + change (x^12)⁻¹ * 2 ≤ (x^10)⁻¹ + have hpow : x^12 = x^10 * x^2 := by ring + rw [inv_mul_eq_div, inv_eq_one_div] + apply (div_le_div_iff₀ (pow_pos hxp _) (pow_pos hxp _)).mpr + rw [hpow] + nlinarith [mul_le_mul_of_nonneg_left hsq (pow_nonneg hxp.le 10)] + +lemma uniform_tail_bound : + ∃ u : ℕ, 1 ≤ u ∧ ∀ d : ℕ, 1 ≤ d → ∀ v : ℕ, u ≤ v → + tailBound d v ≤ ((2 : ℝ)^d)^(-10 : ℤ) := by + obtain ⟨u, hu, hdec⟩ := uniform_nonconstant_decay + refine ⟨u, hu, ?_⟩ + intro d hd v hv + have hn : (2 : ℝ) ≤ (2 : ℝ)^d := by + calc + (2 : ℝ) = 2^1 := by norm_num + _ ≤ 2^d := pow_le_pow_right₀ (by norm_num) hd + have hterm (μ : Shapes (2^d)) : + (if μ.1.card - μ.1.rowLen 0 = 0 then 0 else + (Module.finrank ℂ (hilbertSpace μ.1) : ℝ)^2 * ‖K d μ.1 (cardLabels d μ)‖^v) ≤ + (((2 : ℝ)^d)^12)⁻¹ * (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := by + split_ifs with hz + · positivity + · have hk : 0 < μ.1.card - μ.1.rowLen 0 := by omega + have hkn : μ.1.card - μ.1.rowLen 0 ≤ 2^d := by have := μ.2; omega + apply (hdec v hv d μ.1 (cardLabels d μ) hk).trans + simpa only [Nat.cast_pow, Nat.cast_ofNat] using + level_shape_term (2^d) (μ.1.card - μ.1.rowLen 0) hk hkn + calc + tailBound d v ≤ ∑ μ : Shapes (2^d), + (((2 : ℝ)^d)^12)⁻¹ * (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := + Finset.sum_le_sum (fun μ _ => hterm μ) + _ = (((2 : ℝ)^d)^12)⁻¹ * ∑ μ : Shapes (2^d), (1/4 : ℝ)^(μ.1.card - μ.1.rowLen 0) := + (Finset.mul_sum ..).symm + _ ≤ (((2 : ℝ)^d)^12)⁻¹ * 2 := + mul_le_mul_of_nonneg_left (shape_weight_sum _) (by positivity) + _ ≤ _ := two_inverse_twelfth_le _ hn + +end Thorp.LowPlanes + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpRouting/TraceModel.lean b/lean/OAI/Probability/ThorpRouting/TraceModel.lean index f254d523b4d3de79827b0e71125f1637a994d80e..2626a7ec177edd1d73427bf8b62b0177b5f956f0 100644 --- a/lean/OAI/Probability/ThorpRouting/TraceModel.lean +++ b/lean/OAI/Probability/ThorpRouting/TraceModel.lean @@ -1,42 +1,42 @@ -import OAI.Probability.ThorpRouting.Harmonic.Main - -namespace OAI - -namespace ThorpNine.Harmonic - -namespace Thorp.LowPlanes -open scoped BigOperators Classical -open Casimir Specht UnitaryFinite - -noncomputable local instance hsNorm (μ : YoungDiagram) : NormedAddCommGroup (hilbertSpace μ) := inferInstance -noncomputable local instance hsInner (μ : YoungDiagram) : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance -noncomputable local instance hsFinite (μ : YoungDiagram) : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance - -noncomputable def Q (d : ℕ) (μ : Shapes (2^d)) : - hilbertSpace μ.1 →L[ℂ] hilbertSpace μ.1 := - sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d d) - -noncomputable def absoluteTrace {V : Type*} [NormedAddCommGroup V] - [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - (A : V →L[ℂ] V) (P : ℝ) : ℝ := - (LinearMap.trace ℂ V (CFC.rpow (CFC.sqrt (star A * A)) P).toLinearMap).re - -noncomputable def regularTrace (d : ℕ) (P : ℝ) : ℝ := - ∑ μ : Shapes (2^d), (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * - absoluteTrace (V := hilbertSpace μ.1) (Q d μ) P - -noncomputable def sweepDistance (d v : ℕ) (σ : Equiv.Perm (Card d)) : ℝ := - (1/2:ℝ) * ∑ g : Equiv.Perm (Card d), - |law d (v*d) (g*σ⁻¹) - 1/(Nat.factorial (2^d):ℝ)| - -def MainStatement : Prop := - ∃ P : ℝ, 2 ≤ P ∧ ∀ d : ℕ, 1 ≤ d → - regularTrace d P ≤ 1 + ((2 : ℝ)^d) ^ (-10 : ℤ) ∧ - ∀ v : ℤ, P ≤ 2 * (v : ℝ) → ∀ σ : Equiv.Perm (Card d), - sweepDistance d v.toNat σ ≤ (1/2 : ℝ) * ((2 : ℝ)^d) ^ (-5 : ℤ) - -end Thorp.LowPlanes - -end ThorpNine.Harmonic - -end OAI +import OAI.Probability.ThorpRouting.Harmonic.Main + +namespace OAI + +namespace ThorpNine.Harmonic + +namespace Thorp.LowPlanes +open scoped BigOperators Classical +open Casimir Specht UnitaryFinite + +noncomputable local instance hsNorm (μ : YoungDiagram) : NormedAddCommGroup (hilbertSpace μ) := inferInstance +noncomputable local instance hsInner (μ : YoungDiagram) : InnerProductSpace ℂ (hilbertSpace μ) := inferInstance +noncomputable local instance hsFinite (μ : YoungDiagram) : FiniteDimensional ℂ (hilbertSpace μ) := inferInstance + +noncomputable def Q (d : ℕ) (μ : Shapes (2^d)) : + hilbertSpace μ.1 →L[ℂ] hilbertSpace μ.1 := + sampleOperator (V := hilbertSpace μ.1) (cardRepresentation d μ) (run d d) + +noncomputable def absoluteTrace {V : Type*} [NormedAddCommGroup V] + [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + (A : V →L[ℂ] V) (P : ℝ) : ℝ := + (LinearMap.trace ℂ V (CFC.rpow (CFC.sqrt (star A * A)) P).toLinearMap).re + +noncomputable def regularTrace (d : ℕ) (P : ℝ) : ℝ := + ∑ μ : Shapes (2^d), (Module.finrank ℂ (hilbertSpace μ.1) : ℝ) * + absoluteTrace (V := hilbertSpace μ.1) (Q d μ) P + +noncomputable def sweepDistance (d v : ℕ) (σ : Equiv.Perm (Card d)) : ℝ := + (1/2:ℝ) * ∑ g : Equiv.Perm (Card d), + |law d (v*d) (g*σ⁻¹) - 1/(Nat.factorial (2^d):ℝ)| + +def MainStatement : Prop := + ∃ P : ℝ, 2 ≤ P ∧ ∀ d : ℕ, 1 ≤ d → + regularTrace d P ≤ 1 + ((2 : ℝ)^d) ^ (-10 : ℤ) ∧ + ∀ v : ℤ, P ≤ 2 * (v : ℝ) → ∀ σ : Equiv.Perm (Card d), + sweepDistance d v.toNat σ ≤ (1/2 : ℝ) * ((2 : ℝ)^d) ^ (-5 : ℤ) + +end Thorp.LowPlanes + +end ThorpNine.Harmonic + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/BlockEmbedding.lean b/lean/OAI/Probability/ThorpShuffle/BlockEmbedding.lean index e53b46a92574929d0ff053dd743b724f817c5187..f6f61dc1240f942b88040e612774c855c5b0081d 100644 --- a/lean/OAI/Probability/ThorpShuffle/BlockEmbedding.lean +++ b/lean/OAI/Probability/ThorpShuffle/BlockEmbedding.lean @@ -1,135 +1,135 @@ -import OAI.Probability.ThorpShuffle.FourierPerturbation - -namespace OAI - -universe uI uβ uα - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Block -open scoped Classical -variable {I : Type uI} {β : Type uβ} {α : Type uα} - -attribute [-simp] Thorp.Specht.perm_apply_inv Thorp.Specht.perm_inv_apply in -def perm (p : I → Equiv.Perm β) : Equiv.Perm (I × β) where - toFun x := (x.1, p x.1 x.2) - invFun x := (x.1, (p x.1)⁻¹ x.2) - left_inv x := by simp - right_inv x := by simp - -def hom : (I → Equiv.Perm β) →* Equiv.Perm (I × β) where - toFun := perm - map_one' := by ext ⟨i,b⟩ <;> rfl - map_mul' p q := by ext ⟨i,b⟩ <;> rfl - -def embedding (e : α ≃ I × β) : (I → Equiv.Perm β) →* Equiv.Perm α := - (e.symm.permCongrHom).toMonoidHom.comp hom - -def complement (i : I) := {j : I // j ≠ i} × β - -instance [Fintype I] [Fintype β] (i : I) : Fintype (complement (β:=β) i) := - inferInstanceAs (Fintype ({j : I // j ≠ i} × β)) - -lemma card_complement [Fintype I] [Fintype β] (i : I) : - Fintype.card (complement (β:=β) i) = (Fintype.card I - 1) * Fintype.card β := by - change Fintype.card ({j : I // j ≠ i} × β) = _ - rw [Fintype.card_prod, Fintype.card_subtype_compl, Fintype.card_subtype_eq] - -def complementIn (e : α ≃ I × β) (i : I) (x : complement (β:=β) i) : α := - e.symm (x.1.val, x.2) - -lemma complementIn_injective (e : α ≃ I × β) (i : I) : - Function.Injective (complementIn (β:=β) e i) := by - intro x y h - have hh := e.symm.injective h - exact Prod.ext (Subtype.ext (congrArg Prod.fst hh)) (congrArg (fun p : I × β => p.2) hh) - -def restriction (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : complement (β:=β) i → α := - g ∘ complementIn e i - -lemma perm_single_apply (i j : I) (h : Equiv.Perm β) (b : β) : - perm (Pi.mulSingle i h) (j,b) = if j = i then (j,h b) else (j,b) := by - by_cases hj : j = i - · subst j; simp [perm] - · simp [perm, hj] - -lemma embedding_apply (e : α ≃ I × β) (p : I → Equiv.Perm β) (x : α) : - embedding e p x = e.symm (perm p (e x)) := rfl - -lemma restriction_right (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) (h : Equiv.Perm β) : - restriction e i (g * embedding e (Pi.mulSingle i h)) = restriction e i g := by - funext x - simp only [restriction, Function.comp_apply, Equiv.Perm.coe_mul, embedding_apply, - complementIn, e.apply_symm_apply, perm_single_apply, x.1.property, ↓reduceIte] - -lemma fixes_inside (i : I) (r : Equiv.Perm (I × β)) - (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) (b : β) : (r (i,b)).1 = i := by - by_contra h - have hh := hr (r (i,b)).1 (r (i,b)).2 h - have he : (i,b) = r (i,b) := r.injective (by simpa only [Prod.mk.eta] using hh.symm) - exact h (congrArg Prod.fst he).symm - -lemma fixes_outside_inv (i : I) (r : Equiv.Perm (I × β)) - (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) (j : I) (b : β) (hj : j ≠ i) : - r⁻¹ (j,b) = (j,b) := by - apply r.injective - simpa only [Equiv.Perm.inv_def, Equiv.apply_symm_apply] using (hr j b hj).symm - -def extract (i : I) (r : Equiv.Perm (I × β)) - (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) : Equiv.Perm β where - toFun b := (r (i,b)).2 - invFun b := (r⁻¹ (i,b)).2 - left_inv b := by - have he : (i, (r (i,b)).2) = r (i,b) := Prod.ext (fixes_inside i r hr b).symm rfl - change (r⁻¹ (i, (r (i,b)).2)).2 = b - rw [he, Equiv.Perm.inv_def, Equiv.symm_apply_apply] - right_inv b := by - have he : (i, (r⁻¹ (i,b)).2) = r⁻¹ (i,b) := - Prod.ext (fixes_inside i r⁻¹ (fixes_outside_inv i r hr) b).symm rfl - change (r (i, (r⁻¹ (i,b)).2)).2 = b - rw [he, Equiv.Perm.inv_def, Equiv.apply_symm_apply] - -lemma perm_extract (i : I) (r : Equiv.Perm (I × β)) - (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) : perm (Pi.mulSingle i (extract i r hr)) = r := by - apply Equiv.ext - rintro ⟨j,b⟩ - rw [perm_single_apply] - by_cases hj : j = i - · subst j - simp only [↓reduceIte] - exact Prod.ext (fixes_inside i r hr b).symm rfl - · rw [ite_eq_right hj, hr j b hj] - -lemma restriction_fiber (e : α ≃ I × β) (i : I) (g k : Equiv.Perm α) - (hk : restriction e i k = restriction e i g) : - ∃ h : Equiv.Perm β, g * embedding e (Pi.mulSingle i h) = k := by - let r : Equiv.Perm (I × β) := e.permCongr (g⁻¹ * k) - have hr (j : I) (b : β) (hj : j ≠ i) : r (j,b) = (j,b) := by - have hh := congrFun hk (⟨j,hj⟩,b) - change k (e.symm (j,b)) = g (e.symm (j,b)) at hh - change e (g⁻¹ (k (e.symm (j,b)))) = (j,b) - rw [hh, Equiv.Perm.inv_def, Equiv.symm_apply_apply, e.apply_symm_apply] - refine ⟨extract i r hr, ?_⟩ - apply mul_left_cancel (a:=g⁻¹) - rw [← mul_assoc, inv_mul_cancel, one_mul] - have he := perm_extract i r hr - apply (Equiv.permCongrHom e).injective - change e.permCongr (e.symm.permCongr (perm (Pi.mulSingle i (extract i r hr)))) = r - simpa only [← Equiv.permCongr_symm, Equiv.apply_symm_apply] using he - -lemma single_embedding_injective (e : α ≃ I × β) (i : I) : - Function.Injective (fun h : Equiv.Perm β => embedding e (Pi.mulSingle i h)) := by - intro h k hh - ext b - have he := DFunLike.congr_fun hh (e.symm (i,b)) - simp only [embedding_apply, e.apply_symm_apply, perm_single_apply, ↓reduceIte] at he - exact congrArg Prod.snd (e.symm.injective he) - -end Thorp.Block - -end - -end OAI +import OAI.Probability.ThorpShuffle.FourierPerturbation + +namespace OAI + +universe uI uβ uα + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Block +open scoped Classical +variable {I : Type uI} {β : Type uβ} {α : Type uα} + +attribute [-simp] Thorp.Specht.perm_apply_inv Thorp.Specht.perm_inv_apply in +def perm (p : I → Equiv.Perm β) : Equiv.Perm (I × β) where + toFun x := (x.1, p x.1 x.2) + invFun x := (x.1, (p x.1)⁻¹ x.2) + left_inv x := by simp + right_inv x := by simp + +def hom : (I → Equiv.Perm β) →* Equiv.Perm (I × β) where + toFun := perm + map_one' := by ext ⟨i,b⟩ <;> rfl + map_mul' p q := by ext ⟨i,b⟩ <;> rfl + +def embedding (e : α ≃ I × β) : (I → Equiv.Perm β) →* Equiv.Perm α := + (e.symm.permCongrHom).toMonoidHom.comp hom + +def complement (i : I) := {j : I // j ≠ i} × β + +instance [Fintype I] [Fintype β] (i : I) : Fintype (complement (β:=β) i) := + inferInstanceAs (Fintype ({j : I // j ≠ i} × β)) + +lemma card_complement [Fintype I] [Fintype β] (i : I) : + Fintype.card (complement (β:=β) i) = (Fintype.card I - 1) * Fintype.card β := by + change Fintype.card ({j : I // j ≠ i} × β) = _ + rw [Fintype.card_prod, Fintype.card_subtype_compl, Fintype.card_subtype_eq] + +def complementIn (e : α ≃ I × β) (i : I) (x : complement (β:=β) i) : α := + e.symm (x.1.val, x.2) + +lemma complementIn_injective (e : α ≃ I × β) (i : I) : + Function.Injective (complementIn (β:=β) e i) := by + intro x y h + have hh := e.symm.injective h + exact Prod.ext (Subtype.ext (congrArg Prod.fst hh)) (congrArg (fun p : I × β => p.2) hh) + +def restriction (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : complement (β:=β) i → α := + g ∘ complementIn e i + +lemma perm_single_apply (i j : I) (h : Equiv.Perm β) (b : β) : + perm (Pi.mulSingle i h) (j,b) = if j = i then (j,h b) else (j,b) := by + by_cases hj : j = i + · subst j; simp [perm] + · simp [perm, hj] + +lemma embedding_apply (e : α ≃ I × β) (p : I → Equiv.Perm β) (x : α) : + embedding e p x = e.symm (perm p (e x)) := rfl + +lemma restriction_right (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) (h : Equiv.Perm β) : + restriction e i (g * embedding e (Pi.mulSingle i h)) = restriction e i g := by + funext x + simp only [restriction, Function.comp_apply, Equiv.Perm.coe_mul, embedding_apply, + complementIn, e.apply_symm_apply, perm_single_apply, x.1.property, ↓reduceIte] + +lemma fixes_inside (i : I) (r : Equiv.Perm (I × β)) + (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) (b : β) : (r (i,b)).1 = i := by + by_contra h + have hh := hr (r (i,b)).1 (r (i,b)).2 h + have he : (i,b) = r (i,b) := r.injective (by simpa only [Prod.mk.eta] using hh.symm) + exact h (congrArg Prod.fst he).symm + +lemma fixes_outside_inv (i : I) (r : Equiv.Perm (I × β)) + (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) (j : I) (b : β) (hj : j ≠ i) : + r⁻¹ (j,b) = (j,b) := by + apply r.injective + simpa only [Equiv.Perm.inv_def, Equiv.apply_symm_apply] using (hr j b hj).symm + +def extract (i : I) (r : Equiv.Perm (I × β)) + (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) : Equiv.Perm β where + toFun b := (r (i,b)).2 + invFun b := (r⁻¹ (i,b)).2 + left_inv b := by + have he : (i, (r (i,b)).2) = r (i,b) := Prod.ext (fixes_inside i r hr b).symm rfl + change (r⁻¹ (i, (r (i,b)).2)).2 = b + rw [he, Equiv.Perm.inv_def, Equiv.symm_apply_apply] + right_inv b := by + have he : (i, (r⁻¹ (i,b)).2) = r⁻¹ (i,b) := + Prod.ext (fixes_inside i r⁻¹ (fixes_outside_inv i r hr) b).symm rfl + change (r (i, (r⁻¹ (i,b)).2)).2 = b + rw [he, Equiv.Perm.inv_def, Equiv.apply_symm_apply] + +lemma perm_extract (i : I) (r : Equiv.Perm (I × β)) + (hr : ∀ j b, j ≠ i → r (j,b) = (j,b)) : perm (Pi.mulSingle i (extract i r hr)) = r := by + apply Equiv.ext + rintro ⟨j,b⟩ + rw [perm_single_apply] + by_cases hj : j = i + · subst j + simp only [↓reduceIte] + exact Prod.ext (fixes_inside i r hr b).symm rfl + · rw [ite_eq_right hj, hr j b hj] + +lemma restriction_fiber (e : α ≃ I × β) (i : I) (g k : Equiv.Perm α) + (hk : restriction e i k = restriction e i g) : + ∃ h : Equiv.Perm β, g * embedding e (Pi.mulSingle i h) = k := by + let r : Equiv.Perm (I × β) := e.permCongr (g⁻¹ * k) + have hr (j : I) (b : β) (hj : j ≠ i) : r (j,b) = (j,b) := by + have hh := congrFun hk (⟨j,hj⟩,b) + change k (e.symm (j,b)) = g (e.symm (j,b)) at hh + change e (g⁻¹ (k (e.symm (j,b)))) = (j,b) + rw [hh, Equiv.Perm.inv_def, Equiv.symm_apply_apply, e.apply_symm_apply] + refine ⟨extract i r hr, ?_⟩ + apply mul_left_cancel (a:=g⁻¹) + rw [← mul_assoc, inv_mul_cancel, one_mul] + have he := perm_extract i r hr + apply (Equiv.permCongrHom e).injective + change e.permCongr (e.symm.permCongr (perm (Pi.mulSingle i (extract i r hr)))) = r + simpa only [← Equiv.permCongr_symm, Equiv.apply_symm_apply] using he + +lemma single_embedding_injective (e : α ≃ I × β) (i : I) : + Function.Injective (fun h : Equiv.Perm β => embedding e (Pi.mulSingle i h)) := by + intro h k hh + ext b + have he := DFunLike.congr_fun hh (e.symm (i,b)) + simp only [embedding_apply, e.apply_symm_apply, perm_single_apply, ↓reduceIte] at he + exact congrArg Prod.snd (e.symm.injective he) + +end Thorp.Block + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/BlockFibers.lean b/lean/OAI/Probability/ThorpShuffle/BlockFibers.lean index 30b5ecae230c3457ef1428df62cbdfdb22a5ab1f..5178ffd03870f8f679a7f81b1a57e335264dd02a 100644 --- a/lean/OAI/Probability/ThorpShuffle/BlockFibers.lean +++ b/lean/OAI/Probability/ThorpShuffle/BlockFibers.lean @@ -1,162 +1,162 @@ -import OAI.Probability.ThorpShuffle.BlockEmbedding - -namespace OAI - -universe uI uβ uα uK - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp - -namespace Block -open scoped Classical -variable {I : Type uI} {β : Type uβ} {α : Type uα} [Fintype I] [Fintype β] [Fintype α] [DecidableEq α] [DecidableEq β] - -def fiberEquiv (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : - Equiv.Perm β ≃ {k : Equiv.Perm α // restriction e i k = restriction e i g} := - Equiv.ofBijective (fun h => ⟨g * embedding e (Pi.mulSingle i h), restriction_right e i g h⟩) - ⟨fun h k hh => single_embedding_injective e i (mul_left_cancel (congrArg Subtype.val hh)), - fun ⟨k,hk⟩ => by - obtain ⟨h, hh⟩ := restriction_fiber e i g k hk - exact ⟨h, Subtype.ext hh⟩⟩ - -lemma push_restriction (e : α ≃ I × β) (i : I) (μ : Equiv.Perm α → ℝ) (g : Equiv.Perm α) : - Trim.push μ (restriction e i) (restriction e i g) = Trim.cosetMass (embedding e) μ i g := by - calc - _ = ∑ k : {k : Equiv.Perm α // restriction e i k = restriction e i g}, μ k.val := by - rw [← Finset.sum_subtype (Finset.univ.filter (fun k : Equiv.Perm α => restriction e i k = restriction e i g)) (by simp), - Finset.sum_filter] - unfold Trim.push - apply Finset.sum_congr rfl - intro k _ - split_ifs <;> rfl - _ = _ := (Equiv.sum_comp (fiberEquiv e i g) (fun k => μ k.val)).symm - -lemma push_uniform_restriction (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : - Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) - (restriction e i) (restriction e i g) = - (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by - rw [push_restriction] - simp only [Trim.cosetMass, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, div_eq_mul_inv] - -variable {K : Type uK} [Fintype K] - -def orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) (g : Equiv.Perm α) : K → α := - restriction e i g ∘ o - -omit [Fintype I] [Fintype β] [Fintype α] [DecidableEq α] [DecidableEq β] [Fintype K] in -lemma orderedRestriction_eq_iff (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) - (g k : Equiv.Perm α) : orderedRestriction e i o g = orderedRestriction e i o k ↔ - restriction e i g = restriction e i k := by - constructor - · intro h - funext x - obtain ⟨k,rfl⟩ := o.surjective x - exact congrFun h k - · intro h - unfold orderedRestriction - rw [h] - -omit [Fintype K] in -lemma push_orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) - (μ : Equiv.Perm α → ℝ) (g : Equiv.Perm α) : - Trim.push μ (orderedRestriction e i o) (orderedRestriction e i o g) = - Trim.cosetMass (embedding e) μ i g := by - rw [← push_restriction e i μ g] - unfold Trim.push - apply Finset.sum_congr rfl - intro k _ - by_cases hk : restriction e i k = restriction e i g - · have ho := (orderedRestriction_eq_iff e i o k g).mpr hk - simp only [ite_eq_left hk, ite_eq_left ho] - · have ho := mt (orderedRestriction_eq_iff e i o k g).mp hk - simp only [ite_eq_right hk, ite_eq_right ho] - -omit [Fintype K] in -lemma uniform_orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) - (g : Equiv.Perm α) : - Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) - (orderedRestriction e i o) (orderedRestriction e i o g) = - (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by - rw [push_orderedRestriction] - simp only [Trim.cosetMass, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, div_eq_mul_inv] - -lemma discarded_ordered_bound [DecidableEq K] (e : α ≃ I × β) (o : ∀ i, K ≃ complement (β:=β) i) - (μ : Equiv.Perm α → ℝ) (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) : - Trim.discarded (embedding e) μ ≤ - 2 * ∑ i, tv (Trim.push μ (orderedRestriction e i (o i))) - (Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) (orderedRestriction e i (o i))) := by - exact Trim.discarded_bound (embedding e) μ hμ h1 (fun _ : I => K → α) - (fun i => orderedRestriction e i (o i)) - (fun i g => push_orderedRestriction e i (o i) μ g) - (fun i g => uniform_orderedRestriction e i (o i) g) - -end Block - -lemma law_nonneg (d t : ℕ) (g : State d) : 0 ≤ law d t g := fairMass_nonneg (run d t) g - -lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := fairMass_sum (run d t) - -namespace Block -open scoped Classical - -def eightEquiv (d : ℕ) : Position (d+1+2) ≃ Fin 8 × Position d := - Fintype.equivOfCardEq (by simp only [card_position, Fintype.card_prod, Fintype.card_fin, pow_add]; norm_num; omega) - -lemma complement_card (d : ℕ) (i : Fin 8) : - Fintype.card (complement (β:=Position d) i) = 7 * 2^d := by - rw [card_complement, Fintype.card_fin, card_position] - -def ordering (d : ℕ) (i : Fin 8) : Fin (7 * 2^d) ≃ complement (β:=Position d) i := - Fintype.equivOfCardEq (by rw [Fintype.card_fin, complement_card]) - -def domain (d : ℕ) (i : Fin 8) : Fin (7*2^d) → Position (d+1+2) := - complementIn (eightEquiv d) i ∘ ordering d i - -lemma domain_injective (d : ℕ) (i : Fin 8) : Function.Injective (domain d i) := - (complementIn_injective _ _).comp (ordering d i).injective - -lemma push_law_ordered (d : ℕ) (i : Fin 8) : - Trim.push (law (d+1+2) (200*(d+1+2))) (orderedRestriction (eightEquiv d) i (ordering d i)) = - fairMass (fun ω : History (d+1+2) (200*(d+1+2)) => run (d+1+2) (200*(d+1+2)) ω ∘ domain d i) := by - simpa only [law, Function.comp_def, orderedRestriction, restriction, domain] using - Trim.push_fairMass (run (d+1+2) (200*(d+1+2))) (orderedRestriction (eightEquiv d) i (ordering d i)) - -lemma push_uniform_ordered (d : ℕ) (i : Fin 8) : - Trim.push (fun _ : State (d+1+2) => (Fintype.card (State (d+1+2)) : ℝ)⁻¹) - (orderedRestriction (eightEquiv d) i (ordering d i)) = - fairMass (fun g : State (d+1+2) => g ∘ domain d i) := by - rw [Trim.uniform_eq_fairMass_id] - simpa only [Function.comp_def, orderedRestriction, restriction, domain, id_eq] using - Trim.push_fairMass (id : State (d+1+2) → State (d+1+2)) (orderedRestriction (eightEquiv d) i (ordering d i)) - -def discarded (d : ℕ) : ℝ := - Trim.discarded (embedding (eightEquiv d)) (law (d+1+2) (200*(d+1+2))) - -lemma discarded_nonneg (d : ℕ) : 0 ≤ discarded d := - Trim.discarded_nonneg _ _ (law_nonneg _ _) - -lemma discarded_le (d : ℕ) : discarded d ≤ 16 * Conditional.marginalRate d := by - have h := discarded_ordered_bound (eightEquiv d) (ordering d) (law (d+1+2) (200*(d+1+2))) - (law_nonneg (d+1+2) (200*(d+1+2))) (law_sum (d+1+2) (200*(d+1+2))) - simp only [push_law_ordered, push_uniform_ordered] at h - have hb := Finset.sum_le_sum (s:=Finset.univ) (fun i _ => Conditional.marginal_tv_rate d (domain d i) (domain_injective d i)) - have hc : (∑ _ : Fin 8, Conditional.marginalRate d) = 8 * Conditional.marginalRate d := by simp - rw [hc] at hb - exact h.trans (by linarith) - -lemma discarded_tendsto : Tendsto discarded atTop (nhds 0) := - tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds - (by simpa using Conditional.marginalRate_tendsto.const_mul 16) - discarded_nonneg discarded_le - -end Block - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.BlockEmbedding + +namespace OAI + +universe uI uβ uα uK + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp + +namespace Block +open scoped Classical +variable {I : Type uI} {β : Type uβ} {α : Type uα} [Fintype I] [Fintype β] [Fintype α] [DecidableEq α] [DecidableEq β] + +def fiberEquiv (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : + Equiv.Perm β ≃ {k : Equiv.Perm α // restriction e i k = restriction e i g} := + Equiv.ofBijective (fun h => ⟨g * embedding e (Pi.mulSingle i h), restriction_right e i g h⟩) + ⟨fun h k hh => single_embedding_injective e i (mul_left_cancel (congrArg Subtype.val hh)), + fun ⟨k,hk⟩ => by + obtain ⟨h, hh⟩ := restriction_fiber e i g k hk + exact ⟨h, Subtype.ext hh⟩⟩ + +lemma push_restriction (e : α ≃ I × β) (i : I) (μ : Equiv.Perm α → ℝ) (g : Equiv.Perm α) : + Trim.push μ (restriction e i) (restriction e i g) = Trim.cosetMass (embedding e) μ i g := by + calc + _ = ∑ k : {k : Equiv.Perm α // restriction e i k = restriction e i g}, μ k.val := by + rw [← Finset.sum_subtype (Finset.univ.filter (fun k : Equiv.Perm α => restriction e i k = restriction e i g)) (by simp), + Finset.sum_filter] + unfold Trim.push + apply Finset.sum_congr rfl + intro k _ + split_ifs <;> rfl + _ = _ := (Equiv.sum_comp (fiberEquiv e i g) (fun k => μ k.val)).symm + +lemma push_uniform_restriction (e : α ≃ I × β) (i : I) (g : Equiv.Perm α) : + Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) + (restriction e i) (restriction e i g) = + (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by + rw [push_restriction] + simp only [Trim.cosetMass, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, div_eq_mul_inv] + +variable {K : Type uK} [Fintype K] + +def orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) (g : Equiv.Perm α) : K → α := + restriction e i g ∘ o + +omit [Fintype I] [Fintype β] [Fintype α] [DecidableEq α] [DecidableEq β] [Fintype K] in +lemma orderedRestriction_eq_iff (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) + (g k : Equiv.Perm α) : orderedRestriction e i o g = orderedRestriction e i o k ↔ + restriction e i g = restriction e i k := by + constructor + · intro h + funext x + obtain ⟨k,rfl⟩ := o.surjective x + exact congrFun h k + · intro h + unfold orderedRestriction + rw [h] + +omit [Fintype K] in +lemma push_orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) + (μ : Equiv.Perm α → ℝ) (g : Equiv.Perm α) : + Trim.push μ (orderedRestriction e i o) (orderedRestriction e i o g) = + Trim.cosetMass (embedding e) μ i g := by + rw [← push_restriction e i μ g] + unfold Trim.push + apply Finset.sum_congr rfl + intro k _ + by_cases hk : restriction e i k = restriction e i g + · have ho := (orderedRestriction_eq_iff e i o k g).mpr hk + simp only [ite_eq_left hk, ite_eq_left ho] + · have ho := mt (orderedRestriction_eq_iff e i o k g).mp hk + simp only [ite_eq_right hk, ite_eq_right ho] + +omit [Fintype K] in +lemma uniform_orderedRestriction (e : α ≃ I × β) (i : I) (o : K ≃ complement (β:=β) i) + (g : Equiv.Perm α) : + Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) + (orderedRestriction e i o) (orderedRestriction e i o g) = + (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by + rw [push_orderedRestriction] + simp only [Trim.cosetMass, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, div_eq_mul_inv] + +lemma discarded_ordered_bound [DecidableEq K] (e : α ≃ I × β) (o : ∀ i, K ≃ complement (β:=β) i) + (μ : Equiv.Perm α → ℝ) (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) : + Trim.discarded (embedding e) μ ≤ + 2 * ∑ i, tv (Trim.push μ (orderedRestriction e i (o i))) + (Trim.push (fun _ : Equiv.Perm α => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) (orderedRestriction e i (o i))) := by + exact Trim.discarded_bound (embedding e) μ hμ h1 (fun _ : I => K → α) + (fun i => orderedRestriction e i (o i)) + (fun i g => push_orderedRestriction e i (o i) μ g) + (fun i g => uniform_orderedRestriction e i (o i) g) + +end Block + +lemma law_nonneg (d t : ℕ) (g : State d) : 0 ≤ law d t g := fairMass_nonneg (run d t) g + +lemma law_sum (d t : ℕ) : ∑ g, law d t g = 1 := fairMass_sum (run d t) + +namespace Block +open scoped Classical + +def eightEquiv (d : ℕ) : Position (d+1+2) ≃ Fin 8 × Position d := + Fintype.equivOfCardEq (by simp only [card_position, Fintype.card_prod, Fintype.card_fin, pow_add]; norm_num; omega) + +lemma complement_card (d : ℕ) (i : Fin 8) : + Fintype.card (complement (β:=Position d) i) = 7 * 2^d := by + rw [card_complement, Fintype.card_fin, card_position] + +def ordering (d : ℕ) (i : Fin 8) : Fin (7 * 2^d) ≃ complement (β:=Position d) i := + Fintype.equivOfCardEq (by rw [Fintype.card_fin, complement_card]) + +def domain (d : ℕ) (i : Fin 8) : Fin (7*2^d) → Position (d+1+2) := + complementIn (eightEquiv d) i ∘ ordering d i + +lemma domain_injective (d : ℕ) (i : Fin 8) : Function.Injective (domain d i) := + (complementIn_injective _ _).comp (ordering d i).injective + +lemma push_law_ordered (d : ℕ) (i : Fin 8) : + Trim.push (law (d+1+2) (200*(d+1+2))) (orderedRestriction (eightEquiv d) i (ordering d i)) = + fairMass (fun ω : History (d+1+2) (200*(d+1+2)) => run (d+1+2) (200*(d+1+2)) ω ∘ domain d i) := by + simpa only [law, Function.comp_def, orderedRestriction, restriction, domain] using + Trim.push_fairMass (run (d+1+2) (200*(d+1+2))) (orderedRestriction (eightEquiv d) i (ordering d i)) + +lemma push_uniform_ordered (d : ℕ) (i : Fin 8) : + Trim.push (fun _ : State (d+1+2) => (Fintype.card (State (d+1+2)) : ℝ)⁻¹) + (orderedRestriction (eightEquiv d) i (ordering d i)) = + fairMass (fun g : State (d+1+2) => g ∘ domain d i) := by + rw [Trim.uniform_eq_fairMass_id] + simpa only [Function.comp_def, orderedRestriction, restriction, domain, id_eq] using + Trim.push_fairMass (id : State (d+1+2) → State (d+1+2)) (orderedRestriction (eightEquiv d) i (ordering d i)) + +def discarded (d : ℕ) : ℝ := + Trim.discarded (embedding (eightEquiv d)) (law (d+1+2) (200*(d+1+2))) + +lemma discarded_nonneg (d : ℕ) : 0 ≤ discarded d := + Trim.discarded_nonneg _ _ (law_nonneg _ _) + +lemma discarded_le (d : ℕ) : discarded d ≤ 16 * Conditional.marginalRate d := by + have h := discarded_ordered_bound (eightEquiv d) (ordering d) (law (d+1+2) (200*(d+1+2))) + (law_nonneg (d+1+2) (200*(d+1+2))) (law_sum (d+1+2) (200*(d+1+2))) + simp only [push_law_ordered, push_uniform_ordered] at h + have hb := Finset.sum_le_sum (s:=Finset.univ) (fun i _ => Conditional.marginal_tv_rate d (domain d i) (domain_injective d i)) + have hc : (∑ _ : Fin 8, Conditional.marginalRate d) = 8 * Conditional.marginalRate d := by simp + rw [hc] at hb + exact h.trans (by linarith) + +lemma discarded_tendsto : Tendsto discarded atTop (nhds 0) := + tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds + (by simpa using Conditional.marginalRate_tendsto.const_mul 16) + discarded_nonneg discarded_le + +end Block + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/BlockLaws.lean b/lean/OAI/Probability/ThorpShuffle/BlockLaws.lean index 0e5a7e61f550368dd216df69cc5200a0616d3996..ef3f6637d2ef21b67a837d5b943e44b6a56bdad2 100644 --- a/lean/OAI/Probability/ThorpShuffle/BlockLaws.lean +++ b/lean/OAI/Probability/ThorpShuffle/BlockLaws.lean @@ -1,75 +1,75 @@ -import OAI.Probability.ThorpShuffle.BlockFibers - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp -open scoped Classical - -theorem law_realPower (d t k : ℕ) : - law d (k*t) = Fourier.realPower (law d t) k := by - induction k with - | zero => - funext g - simp only [Nat.zero_mul, law, run, List.ofFn_zero, List.reverse_nil, List.prod_nil, - fairMass, Fourier.realPower] - by_cases hg : g = 1 - · subst g - simp - · simp [hg, Ne.symm hg] - | succ k ih => - rw [Nat.succ_mul, law_add, ih] - rfl - -namespace Specht -open Thorp.Fourier -variable {α β : Type} [Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β] [Nontrivial α] - -theorem trimmed_eight_tv (hn : 16 ≤ Fintype.card α) - (ψ : (Fin 8 → Equiv.Perm β) →* Equiv.Perm α) (μ : Equiv.Perm α → ℝ) - (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) - (hb : ∑ g, (μ g : ℂ) * complexSign g = 0) - (hδ : Trim.discarded ψ μ ≤ 1/2) : - tv (realPower μ 8) (fun _ => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) ≤ - 8 * Trim.discarded ψ μ + (1/2 : ℝ) * Real.sqrt - (2 * (2 * Trim.discarded ψ μ)^16 + - (32 * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α)) := by - let ν := Trim.normalized ψ μ - have hd : Trim.discarded ψ μ < 1 := by linarith - have hν : ∀ g, 0 ≤ ν g := Trim.normalized_nonneg ψ μ hμ hd - have hν1 : ∑ g, ν g = 1 := Trim.normalized_sum ψ μ h1 hd - have hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ - 4 * (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by - intro i g - convert Trim.normalized_coset ψ μ hμ hδ i g using 1 - apply Finset.sum_congr rfl - intro h _ - congr 4 - exact Subsingleton.elim _ _ - have hpar := Trim.normalized_bias ψ μ hμ h1 hd complexSign - (fun g => (complexSign_norm g).le) hb - have hfour := permutation_eight_bound hn ψ ν 4 hν hν1 (by norm_num) hcoset - have hpow := pow_le_pow_left₀ (norm_nonneg _) hpar 16 - have hsq : (∑ g, |realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹|)^2 ≤ - 2 * (2 * Trim.discarded ψ μ)^16 + - (32 * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α) := by - norm_num only [show (8:ℝ)*4 = 32 by norm_num] at hfour - exact hfour.trans (by gcongr) - have hnorm := Real.le_sqrt_of_sq_le hsq - calc - _ ≤ tv (realPower μ 8) (realPower ν 8) + - tv (realPower ν 8) (fun _ => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) := tv_triangle _ _ _ - _ ≤ 8 * Trim.discarded ψ μ + _ := add_le_add - (by simpa only [ν, Nat.cast_ofNat, Trim.normalized_tv ψ μ hμ h1 hd] using tv_realPower μ ν hμ h1 hν hν1 8) - (mul_le_mul_of_nonneg_left hnorm (by norm_num : (0:ℝ) ≤ 1/2)) - -end Specht -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.BlockFibers + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp +open scoped Classical + +theorem law_realPower (d t k : ℕ) : + law d (k*t) = Fourier.realPower (law d t) k := by + induction k with + | zero => + funext g + simp only [Nat.zero_mul, law, run, List.ofFn_zero, List.reverse_nil, List.prod_nil, + fairMass, Fourier.realPower] + by_cases hg : g = 1 + · subst g + simp + · simp [hg, Ne.symm hg] + | succ k ih => + rw [Nat.succ_mul, law_add, ih] + rfl + +namespace Specht +open Thorp.Fourier +variable {α β : Type} [Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β] [Nontrivial α] + +theorem trimmed_eight_tv (hn : 16 ≤ Fintype.card α) + (ψ : (Fin 8 → Equiv.Perm β) →* Equiv.Perm α) (μ : Equiv.Perm α → ℝ) + (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) + (hb : ∑ g, (μ g : ℂ) * complexSign g = 0) + (hδ : Trim.discarded ψ μ ≤ 1/2) : + tv (realPower μ 8) (fun _ => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) ≤ + 8 * Trim.discarded ψ μ + (1/2 : ℝ) * Real.sqrt + (2 * (2 * Trim.discarded ψ μ)^16 + + (32 * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α)) := by + let ν := Trim.normalized ψ μ + have hd : Trim.discarded ψ μ < 1 := by linarith + have hν : ∀ g, 0 ≤ ν g := Trim.normalized_nonneg ψ μ hμ hd + have hν1 : ∑ g, ν g = 1 := Trim.normalized_sum ψ μ h1 hd + have hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ + 4 * (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α) := by + intro i g + convert Trim.normalized_coset ψ μ hμ hδ i g using 1 + apply Finset.sum_congr rfl + intro h _ + congr 4 + exact Subsingleton.elim _ _ + have hpar := Trim.normalized_bias ψ μ hμ h1 hd complexSign + (fun g => (complexSign_norm g).le) hb + have hfour := permutation_eight_bound hn ψ ν 4 hν hν1 (by norm_num) hcoset + have hpow := pow_le_pow_left₀ (norm_nonneg _) hpar 16 + have hsq : (∑ g, |realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹|)^2 ≤ + 2 * (2 * Trim.discarded ψ μ)^16 + + (32 * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α) := by + norm_num only [show (8:ℝ)*4 = 32 by norm_num] at hfour + exact hfour.trans (by gcongr) + have hnorm := Real.le_sqrt_of_sq_le hsq + calc + _ ≤ tv (realPower μ 8) (realPower ν 8) + + tv (realPower ν 8) (fun _ => (Fintype.card (Equiv.Perm α) : ℝ)⁻¹) := tv_triangle _ _ _ + _ ≤ 8 * Trim.discarded ψ μ + _ := add_le_add + (by simpa only [ν, Nat.cast_ofNat, Trim.normalized_tv ψ μ hμ h1 hd] using tv_realPower μ ν hμ h1 hν hν1 8) + (mul_le_mul_of_nonneg_left hnorm (by norm_num : (0:ℝ) ≤ 1/2)) + +end Specht +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Classification.lean b/lean/OAI/Probability/ThorpShuffle/Classification.lean index b0d3725f35ee4704b9d82ac96ad417511be156c1..4e8e01e91dfeaba7c64e8d8007cc4b820e7b73dd 100644 --- a/lean/OAI/Probability/ThorpShuffle/Classification.lean +++ b/lean/OAI/Probability/ThorpShuffle/Classification.lean @@ -1,242 +1,242 @@ -import OAI.Probability.ThorpShuffle.Irreducibility - -namespace OAI - -universe uG uI uV uα - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical - -def rowCellsEquiv (D : YoungDiagram) : Cells D ≃ (i : Fin (D.colLen 0)) × Fin (D.rowLen i) where - toFun x := ⟨⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp (D.up_left_mem le_rfl (Nat.zero_le _) x.property)⟩, - ⟨x.val.2, YoungDiagram.mem_iff_lt_rowLen.mp x.property⟩⟩ - invFun x := ⟨(x.1, x.2), YoungDiagram.mem_iff_lt_rowLen.mpr x.2.isLt⟩ - left_inv x := rfl - right_inv x := by cases x; rfl - -lemma card_cells_eq_sum (D : YoungDiagram) : Fintype.card (Cells D) = D.rowLens.sum := by - rw [Fintype.card_congr (rowCellsEquiv D), Fintype.card_sigma] - simp only [Fintype.card_fin, YoungDiagram.rowLens] - rw [← List.sum_toFinset _ List.nodup_range, List.toFinset_range, Finset.sum_range] - -def ofPartition {n : ℕ} (p : Nat.Partition n) : YoungDiagram := - YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE - -lemma rowLens_ofPartition {n : ℕ} (p : Nat.Partition n) : - (ofPartition p).rowLens = p.parts.sort (· ≥ ·) := by - apply YoungDiagram.rowLens_ofRowLens_eq_self - intro x hx - exact p.parts_pos ((Multiset.mem_sort _).mp hx) - -lemma card_ofPartition {n : ℕ} (p : Nat.Partition n) : Fintype.card (Cells (ofPartition p)) = n := by - rw [card_cells_eq_sum, rowLens_ofPartition] - simpa only [← Multiset.sum_coe, Multiset.sort_eq] using p.parts_sum - -lemma ofPartition_injective {n : ℕ} : Function.Injective (ofPartition (n := n)) := by - intro p q hpq - apply Nat.Partition.ext - have hh := congrArg YoungDiagram.rowLens hpq - rw [rowLens_ofPartition, rowLens_ofPartition] at hh - simpa only [Multiset.sort_eq] using congrArg (fun x : List ℕ => (x : Multiset ℕ)) hh - -def toPartition (D : YoungDiagram) (n : ℕ) (hn : Fintype.card (Cells D) = n) : Nat.Partition n where - parts := D.rowLens - parts_pos := fun hx => D.pos_of_mem_rowLens _ hx - parts_sum := by simpa only [Multiset.sum_coe, ← card_cells_eq_sum] using hn - -lemma of_toPartition (D : YoungDiagram) (n : ℕ) (hn : Fintype.card (Cells D) = n) : - ofPartition (toPartition D n hn) = D := by - have hs : (D.rowLens : Multiset ℕ).sort (· ≥ ·) = D.rowLens := by - rw [Multiset.coe_sort] - exact List.mergeSort_eq_self _ D.rowLens_sorted.pairwise - unfold ofPartition toPartition - simp only [hs] - exact YoungDiagram.ofRowLens_to_rowLens_eq_self - -end Thorp.Young - -namespace Thorp.Fourier -open scoped Classical - -variable {G : Type uG} [Group G] [Fintype G] - -def charPair (f h : G → ℂ) : ℂ := (Nat.card G : ℂ)⁻¹ * ∑ g, f g * h g⁻¹ - -lemma charPair_sum {I : Type uI} (s : Finset I) (a : I → ℂ) (f : I → G → ℂ) (h : G → ℂ) : - charPair (∑ i ∈ s, a i • f i) h = ∑ i ∈ s, a i * charPair (f i) h := by - simp only [charPair, Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Finset.sum_mul] - rw [Finset.sum_comm, Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - simp_rw [mul_assoc (a i)] - rw [← Finset.mul_sum] - ring - -lemma charPair_zero (h : G → ℂ) : charPair (0 : G → ℂ) h = 0 := by simp [charPair] - -lemma irreducible_char_independent {I : Type uI} {V : I → Type uV} - [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] [∀ i, FiniteDimensional ℂ (V i)] - (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] - (hne : ∀ i j, Nonempty (Representation.Equiv (ρ i) (ρ j)) → i = j) : - LinearIndependent ℂ (fun i => (ρ i).character) := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (NeZero.ne _) - have ho (i j : I) : charPair (ρ i).character (ρ j).character = if i = j then 1 else 0 := by - rw [charPair, Representation.char_orthonormal] - congr 1 - apply propext - constructor - · exact fun h => (hne j i h).symm - · intro h; subst j; exact ⟨Representation.Equiv.refl _⟩ - rw [linearIndependent_iff'] - intro s a ha i hi - have hh := congrArg (fun f => charPair f (ρ i).character) ha - rw [charPair_sum, charPair_zero] at hh - simp only [ho] at hh - simpa only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', ite_eq_left hi] using hh - -end Thorp.Fourier - -namespace Thorp.Specht -open scoped Classical -variable {α : Type uα} [Fintype α] - -abbrev Shape (α : Type uα) [Fintype α] := Nat.Partition (Fintype.card α) - -def canonicalTableau (p : Shape α) : α ≃ Thorp.Young.Cells (Thorp.Young.ofPartition p) := by - have card_cells_eq_sum (D : YoungDiagram) : Fintype.card (Thorp.Young.Cells D) = D.rowLens.sum := by - rw [Fintype.card_congr (Thorp.Young.rowCellsEquiv D), Fintype.card_sigma] - simp only [Fintype.card_fin, YoungDiagram.rowLens] - rw [← List.sum_toFinset _ List.nodup_range, List.toFinset_range, Finset.sum_range] - have rowLens_ofPartition {n : ℕ} (p : Nat.Partition n) : - (Thorp.Young.ofPartition p).rowLens = p.parts.sort (· ≥ ·) := by - apply YoungDiagram.rowLens_ofRowLens_eq_self - intro x hx - exact p.parts_pos ((Multiset.mem_sort _).mp hx) - have card_ofPartition {n : ℕ} (p : Nat.Partition n) : Fintype.card (Thorp.Young.Cells (Thorp.Young.ofPartition p)) = n := by - rw [card_cells_eq_sum, rowLens_ofPartition] - simpa only [← Multiset.sum_coe, Multiset.sort_eq] using p.parts_sum - exact Fintype.equivOfCardEq (card_ofPartition p).symm - -abbrev Space (p : Shape α) := (module (Thorp.Young.ofPartition p) (canonicalTableau p)).toSubmodule - -def family (p : Shape α) : Representation ℂ (Equiv.Perm α) (Space p) := - (module (Thorp.Young.ofPartition p) (canonicalTableau p)).toRepresentation - -instance family_irreducible (p : Shape α) : Representation.IsIrreducible (family p) := - irreducible (Thorp.Young.ofPartition p) (canonicalTableau p) - -lemma family_inequiv (p q : Shape α) (he : Nonempty (Representation.Equiv (family p) (family q))) : p = q := by - obtain ⟨e⟩ := he - apply Thorp.Young.ofPartition_injective - exact shape_eq_of_equiv _ _ _ _ e - -lemma characters_independent : LinearIndependent ℂ (fun p : Shape α => (family p).character) := - Thorp.Fourier.irreducible_char_independent family family_inequiv - -def classLift (f : Equiv.Perm α → ℂ) (p : Shape α) : ℂ := - if h : ∃ g : Equiv.Perm α, g.partition = p then f h.choose else 0 - -lemma classLift_apply (f : Equiv.Perm α → ℂ) - (hf : ∀ g h, IsConj g h → f g = f h) (g : Equiv.Perm α) : - classLift f g.partition = f g := by - unfold classLift - have hh : ∃ a : Equiv.Perm α, a.partition = g.partition := ⟨g, rfl⟩ - rw [dite_eq_left hh] - exact hf _ g (Equiv.Perm.partition_eq_of_isConj.mpr hh.choose_spec) - -lemma character_isClass (p : Shape α) (g h : Equiv.Perm α) (hgh : IsConj g h) : - (family p).character g = (family p).character h := by - obtain ⟨x, hx⟩ := isConj_iff.mp hgh - rw [← hx] - exact (Representation.char_conj (family p) g x).symm - -lemma liftedCharacters_independent : - LinearIndependent ℂ (fun p : Shape α => classLift (family p).character) := by - let E : (Shape α → ℂ) →ₗ[ℂ] (Equiv.Perm α → ℂ) := { - toFun := fun f g => f g.partition - map_add' := by intro f h; rfl - map_smul' := by intro a f; rfl } - apply LinearIndependent.of_comp E - convert characters_independent (α := α) using 1 - funext p g - exact classLift_apply _ (character_isClass p) g - -def characterBasis : Module.Basis (Shape α) ℂ (Shape α → ℂ) := - basisOfPiSpaceOfLinearIndependent liftedCharacters_independent - -lemma characterBasis_apply (p : Shape α) : characterBasis p = classLift (family p).character := by - exact congrFun (coe_basisOfPiSpaceOfLinearIndependent liftedCharacters_independent) p - -end Thorp.Specht - -namespace Thorp.Specht -open scoped Classical -variable {α : Type uα} [Fintype α] - -lemma class_expansion (f : Equiv.Perm α → ℂ) - (hf : ∀ g h, IsConj g h → f g = f h) : - (∑ p : Shape α, (characterBasis.repr (classLift f)) p • (family p).character) = f := by - funext g - have he := congrFun (characterBasis.sum_repr (classLift f)) g.partition - simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, characterBasis_apply, - classLift_apply _ (character_isClass _), classLift_apply _ hf] at he - simpa only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] using he - -lemma char_orthogonal (p q : Shape α) : - Thorp.Fourier.charPair (family p).character (family q).character = if p = q then 1 else 0 := by - let : Invertible (Nat.card (Equiv.Perm α) : ℂ) := invertibleOfNonzero (NeZero.ne _) - rw [Thorp.Fourier.charPair, Representation.char_orthonormal] - congr 1 - apply propext - exact ⟨fun h => (family_inequiv q p h).symm, - fun h => by subst q; exact ⟨Representation.Equiv.refl _⟩⟩ - -lemma class_coeff (f : Equiv.Perm α → ℂ) - (hf : ∀ g h, IsConj g h → f g = f h) (q : Shape α) : - characterBasis.repr (classLift f) q = Thorp.Fourier.charPair f (family q).character := by - have he := congrArg (fun x => Thorp.Fourier.charPair x (family q).character) (class_expansion f hf) - rw [Thorp.Fourier.charPair_sum] at he - simp only [char_orthogonal, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, - ↓reduceIte] at he - exact he - -def degree (p : Shape α) : ℕ := Module.finrank ℂ (Space p) - -theorem regular_char (g : Equiv.Perm α) : - ∑ p : Shape α, (degree p : ℂ) * (family p).character g = - if g = 1 then (Nat.card (Equiv.Perm α) : ℂ) else 0 := by - let δ : Equiv.Perm α → ℂ := fun h => if h = 1 then Nat.card (Equiv.Perm α) else 0 - have hδ : ∀ a b, IsConj a b → δ a = δ b := by - intro a b hab - have hh : a = 1 ↔ b = 1 := by - obtain ⟨c, hc⟩ := isConj_iff.mp hab - rw [← hc] - constructor - · intro ha; simp [ha] - · intro hb - have hh := congrArg (fun z => c⁻¹ * z * c) hb - simpa only [mul_assoc, inv_mul_cancel_left, inv_mul_cancel_right, inv_mul_cancel, one_mul, mul_one] using hh - simp only [δ, hh] - have hc (p : Shape α) : Thorp.Fourier.charPair δ (family p).character = degree p := by - rw [Thorp.Fourier.charPair] - simp only [δ, ite_mul, zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, inv_one, - Representation.char_one] - rw [← mul_assoc, inv_mul_cancel₀ (NeZero.ne _), one_mul] - rfl - have he := congrFun (class_expansion δ hδ) g - simpa only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, class_coeff δ hδ, hc] using he - -theorem degree_sq_sum : ∑ p : Shape α, (degree p : ℂ) ^ 2 = Nat.card (Equiv.Perm α) := by - have hh := regular_char (α := α) 1 - simpa only [Representation.char_one, degree, pow_two, ↓reduceIte] using hh - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.Irreducibility + +namespace OAI + +universe uG uI uV uα + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical + +def rowCellsEquiv (D : YoungDiagram) : Cells D ≃ (i : Fin (D.colLen 0)) × Fin (D.rowLen i) where + toFun x := ⟨⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp (D.up_left_mem le_rfl (Nat.zero_le _) x.property)⟩, + ⟨x.val.2, YoungDiagram.mem_iff_lt_rowLen.mp x.property⟩⟩ + invFun x := ⟨(x.1, x.2), YoungDiagram.mem_iff_lt_rowLen.mpr x.2.isLt⟩ + left_inv x := rfl + right_inv x := by cases x; rfl + +lemma card_cells_eq_sum (D : YoungDiagram) : Fintype.card (Cells D) = D.rowLens.sum := by + rw [Fintype.card_congr (rowCellsEquiv D), Fintype.card_sigma] + simp only [Fintype.card_fin, YoungDiagram.rowLens] + rw [← List.sum_toFinset _ List.nodup_range, List.toFinset_range, Finset.sum_range] + +def ofPartition {n : ℕ} (p : Nat.Partition n) : YoungDiagram := + YoungDiagram.ofRowLens (p.parts.sort (· ≥ ·)) (Multiset.pairwise_sort _ _).sortedGE + +lemma rowLens_ofPartition {n : ℕ} (p : Nat.Partition n) : + (ofPartition p).rowLens = p.parts.sort (· ≥ ·) := by + apply YoungDiagram.rowLens_ofRowLens_eq_self + intro x hx + exact p.parts_pos ((Multiset.mem_sort _).mp hx) + +lemma card_ofPartition {n : ℕ} (p : Nat.Partition n) : Fintype.card (Cells (ofPartition p)) = n := by + rw [card_cells_eq_sum, rowLens_ofPartition] + simpa only [← Multiset.sum_coe, Multiset.sort_eq] using p.parts_sum + +lemma ofPartition_injective {n : ℕ} : Function.Injective (ofPartition (n := n)) := by + intro p q hpq + apply Nat.Partition.ext + have hh := congrArg YoungDiagram.rowLens hpq + rw [rowLens_ofPartition, rowLens_ofPartition] at hh + simpa only [Multiset.sort_eq] using congrArg (fun x : List ℕ => (x : Multiset ℕ)) hh + +def toPartition (D : YoungDiagram) (n : ℕ) (hn : Fintype.card (Cells D) = n) : Nat.Partition n where + parts := D.rowLens + parts_pos := fun hx => D.pos_of_mem_rowLens _ hx + parts_sum := by simpa only [Multiset.sum_coe, ← card_cells_eq_sum] using hn + +lemma of_toPartition (D : YoungDiagram) (n : ℕ) (hn : Fintype.card (Cells D) = n) : + ofPartition (toPartition D n hn) = D := by + have hs : (D.rowLens : Multiset ℕ).sort (· ≥ ·) = D.rowLens := by + rw [Multiset.coe_sort] + exact List.mergeSort_eq_self _ D.rowLens_sorted.pairwise + unfold ofPartition toPartition + simp only [hs] + exact YoungDiagram.ofRowLens_to_rowLens_eq_self + +end Thorp.Young + +namespace Thorp.Fourier +open scoped Classical + +variable {G : Type uG} [Group G] [Fintype G] + +def charPair (f h : G → ℂ) : ℂ := (Nat.card G : ℂ)⁻¹ * ∑ g, f g * h g⁻¹ + +lemma charPair_sum {I : Type uI} (s : Finset I) (a : I → ℂ) (f : I → G → ℂ) (h : G → ℂ) : + charPair (∑ i ∈ s, a i • f i) h = ∑ i ∈ s, a i * charPair (f i) h := by + simp only [charPair, Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Finset.sum_mul] + rw [Finset.sum_comm, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + simp_rw [mul_assoc (a i)] + rw [← Finset.mul_sum] + ring + +lemma charPair_zero (h : G → ℂ) : charPair (0 : G → ℂ) h = 0 := by simp [charPair] + +lemma irreducible_char_independent {I : Type uI} {V : I → Type uV} + [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] [∀ i, FiniteDimensional ℂ (V i)] + (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] + (hne : ∀ i j, Nonempty (Representation.Equiv (ρ i) (ρ j)) → i = j) : + LinearIndependent ℂ (fun i => (ρ i).character) := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (NeZero.ne _) + have ho (i j : I) : charPair (ρ i).character (ρ j).character = if i = j then 1 else 0 := by + rw [charPair, Representation.char_orthonormal] + congr 1 + apply propext + constructor + · exact fun h => (hne j i h).symm + · intro h; subst j; exact ⟨Representation.Equiv.refl _⟩ + rw [linearIndependent_iff'] + intro s a ha i hi + have hh := congrArg (fun f => charPair f (ρ i).character) ha + rw [charPair_sum, charPair_zero] at hh + simp only [ho] at hh + simpa only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', ite_eq_left hi] using hh + +end Thorp.Fourier + +namespace Thorp.Specht +open scoped Classical +variable {α : Type uα} [Fintype α] + +abbrev Shape (α : Type uα) [Fintype α] := Nat.Partition (Fintype.card α) + +def canonicalTableau (p : Shape α) : α ≃ Thorp.Young.Cells (Thorp.Young.ofPartition p) := by + have card_cells_eq_sum (D : YoungDiagram) : Fintype.card (Thorp.Young.Cells D) = D.rowLens.sum := by + rw [Fintype.card_congr (Thorp.Young.rowCellsEquiv D), Fintype.card_sigma] + simp only [Fintype.card_fin, YoungDiagram.rowLens] + rw [← List.sum_toFinset _ List.nodup_range, List.toFinset_range, Finset.sum_range] + have rowLens_ofPartition {n : ℕ} (p : Nat.Partition n) : + (Thorp.Young.ofPartition p).rowLens = p.parts.sort (· ≥ ·) := by + apply YoungDiagram.rowLens_ofRowLens_eq_self + intro x hx + exact p.parts_pos ((Multiset.mem_sort _).mp hx) + have card_ofPartition {n : ℕ} (p : Nat.Partition n) : Fintype.card (Thorp.Young.Cells (Thorp.Young.ofPartition p)) = n := by + rw [card_cells_eq_sum, rowLens_ofPartition] + simpa only [← Multiset.sum_coe, Multiset.sort_eq] using p.parts_sum + exact Fintype.equivOfCardEq (card_ofPartition p).symm + +abbrev Space (p : Shape α) := (module (Thorp.Young.ofPartition p) (canonicalTableau p)).toSubmodule + +def family (p : Shape α) : Representation ℂ (Equiv.Perm α) (Space p) := + (module (Thorp.Young.ofPartition p) (canonicalTableau p)).toRepresentation + +instance family_irreducible (p : Shape α) : Representation.IsIrreducible (family p) := + irreducible (Thorp.Young.ofPartition p) (canonicalTableau p) + +lemma family_inequiv (p q : Shape α) (he : Nonempty (Representation.Equiv (family p) (family q))) : p = q := by + obtain ⟨e⟩ := he + apply Thorp.Young.ofPartition_injective + exact shape_eq_of_equiv _ _ _ _ e + +lemma characters_independent : LinearIndependent ℂ (fun p : Shape α => (family p).character) := + Thorp.Fourier.irreducible_char_independent family family_inequiv + +def classLift (f : Equiv.Perm α → ℂ) (p : Shape α) : ℂ := + if h : ∃ g : Equiv.Perm α, g.partition = p then f h.choose else 0 + +lemma classLift_apply (f : Equiv.Perm α → ℂ) + (hf : ∀ g h, IsConj g h → f g = f h) (g : Equiv.Perm α) : + classLift f g.partition = f g := by + unfold classLift + have hh : ∃ a : Equiv.Perm α, a.partition = g.partition := ⟨g, rfl⟩ + rw [dite_eq_left hh] + exact hf _ g (Equiv.Perm.partition_eq_of_isConj.mpr hh.choose_spec) + +lemma character_isClass (p : Shape α) (g h : Equiv.Perm α) (hgh : IsConj g h) : + (family p).character g = (family p).character h := by + obtain ⟨x, hx⟩ := isConj_iff.mp hgh + rw [← hx] + exact (Representation.char_conj (family p) g x).symm + +lemma liftedCharacters_independent : + LinearIndependent ℂ (fun p : Shape α => classLift (family p).character) := by + let E : (Shape α → ℂ) →ₗ[ℂ] (Equiv.Perm α → ℂ) := { + toFun := fun f g => f g.partition + map_add' := by intro f h; rfl + map_smul' := by intro a f; rfl } + apply LinearIndependent.of_comp E + convert characters_independent (α := α) using 1 + funext p g + exact classLift_apply _ (character_isClass p) g + +def characterBasis : Module.Basis (Shape α) ℂ (Shape α → ℂ) := + basisOfPiSpaceOfLinearIndependent liftedCharacters_independent + +lemma characterBasis_apply (p : Shape α) : characterBasis p = classLift (family p).character := by + exact congrFun (coe_basisOfPiSpaceOfLinearIndependent liftedCharacters_independent) p + +end Thorp.Specht + +namespace Thorp.Specht +open scoped Classical +variable {α : Type uα} [Fintype α] + +lemma class_expansion (f : Equiv.Perm α → ℂ) + (hf : ∀ g h, IsConj g h → f g = f h) : + (∑ p : Shape α, (characterBasis.repr (classLift f)) p • (family p).character) = f := by + funext g + have he := congrFun (characterBasis.sum_repr (classLift f)) g.partition + simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, characterBasis_apply, + classLift_apply _ (character_isClass _), classLift_apply _ hf] at he + simpa only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] using he + +lemma char_orthogonal (p q : Shape α) : + Thorp.Fourier.charPair (family p).character (family q).character = if p = q then 1 else 0 := by + let : Invertible (Nat.card (Equiv.Perm α) : ℂ) := invertibleOfNonzero (NeZero.ne _) + rw [Thorp.Fourier.charPair, Representation.char_orthonormal] + congr 1 + apply propext + exact ⟨fun h => (family_inequiv q p h).symm, + fun h => by subst q; exact ⟨Representation.Equiv.refl _⟩⟩ + +lemma class_coeff (f : Equiv.Perm α → ℂ) + (hf : ∀ g h, IsConj g h → f g = f h) (q : Shape α) : + characterBasis.repr (classLift f) q = Thorp.Fourier.charPair f (family q).character := by + have he := congrArg (fun x => Thorp.Fourier.charPair x (family q).character) (class_expansion f hf) + rw [Thorp.Fourier.charPair_sum] at he + simp only [char_orthogonal, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, + ↓reduceIte] at he + exact he + +def degree (p : Shape α) : ℕ := Module.finrank ℂ (Space p) + +theorem regular_char (g : Equiv.Perm α) : + ∑ p : Shape α, (degree p : ℂ) * (family p).character g = + if g = 1 then (Nat.card (Equiv.Perm α) : ℂ) else 0 := by + let δ : Equiv.Perm α → ℂ := fun h => if h = 1 then Nat.card (Equiv.Perm α) else 0 + have hδ : ∀ a b, IsConj a b → δ a = δ b := by + intro a b hab + have hh : a = 1 ↔ b = 1 := by + obtain ⟨c, hc⟩ := isConj_iff.mp hab + rw [← hc] + constructor + · intro ha; simp [ha] + · intro hb + have hh := congrArg (fun z => c⁻¹ * z * c) hb + simpa only [mul_assoc, inv_mul_cancel_left, inv_mul_cancel_right, inv_mul_cancel, one_mul, mul_one] using hh + simp only [δ, hh] + have hc (p : Shape α) : Thorp.Fourier.charPair δ (family p).character = degree p := by + rw [Thorp.Fourier.charPair] + simp only [δ, ite_mul, zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, inv_one, + Representation.char_one] + rw [← mul_assoc, inv_mul_cancel₀ (NeZero.ne _), one_mul] + rfl + have he := congrFun (class_expansion δ hδ) g + simpa only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, class_coeff δ hδ, hc] using he + +theorem degree_sq_sum : ∑ p : Shape α, (degree p : ℂ) ^ 2 = Nat.card (Equiv.Perm α) := by + have hh := regular_char (α := α) 1 + simpa only [Representation.char_one, degree, pow_two, ↓reduceIte] using hh + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ConditionalFlow.lean b/lean/OAI/Probability/ThorpShuffle/ConditionalFlow.lean index 62dfc45e17bdcbc1d743d03f0a54af819ca26892..8016ad6cf1da7ca8854e6504c78c028d353efcbe 100644 --- a/lean/OAI/Probability/ThorpShuffle/ConditionalFlow.lean +++ b/lean/OAI/Probability/ThorpShuffle/ConditionalFlow.lean @@ -1,192 +1,192 @@ -import OAI.Probability.ThorpShuffle.SpectralDecay - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def splitPosition (d : ℕ) : Position (d + 1) ≃ Bool × Position d := - (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)).symm - -def scatterPosition (d : ℕ) : Bool × Position d ≃ Position (d + 1) := - (splitPosition d).symm.trans (rotate (d + 1)) - -def physicalFlow (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (x : Position (d + 1)) : ℝ := - flow (B ∘ (splitPosition d).symm) (w ∘ (splitPosition d).symm) c - ((scatterPosition d).symm x) - -def physicalFree (d : ℕ) (B : Position (d + 1) → Bool) - (c : Coins (d + 1)) (x : Position (d + 1)) : Bool := - B ((step (d + 1) c).symm x) - -theorem step_symm_scatter (d : ℕ) (c : Coins (d + 1)) (p : Bool × Position d) : - (step (d + 1) c).symm (scatterPosition d p) = - (splitPosition d).symm (pairMap c p) := by - simp [step, scatterPosition, splitPosition, pairSwitch, pairMap] - -@[simp] theorem physicalFlow_scatter (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (p : Bool × Position d) : - physicalFlow d B w c (scatterPosition d p) = - flow (B ∘ (splitPosition d).symm) (w ∘ (splitPosition d).symm) c p := by - simp [physicalFlow] - -@[simp] theorem physicalFree_scatter (d : ℕ) (B : Position (d + 1) → Bool) - (c : Coins (d + 1)) (p : Bool × Position d) : - physicalFree d B c (scatterPosition d p) = - B ((splitPosition d).symm (pairMap c p)) := by - rw [physicalFree, step_symm_scatter] - -theorem physicalFlow_sum (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) : - (∑ x, physicalFlow d B w c x) = ∑ x, w x := by - calc - _ = ∑ p, physicalFlow d B w c (scatterPosition d p) := - (Equiv.sum_comp (scatterPosition d) (physicalFlow d B w c)).symm - _ = ∑ p, w ((splitPosition d).symm p) := by - simp only [physicalFlow_scatter] - exact flow_sum (B ∘ (splitPosition d).symm) - (w ∘ (splitPosition d).symm) c - _ = _ := Equiv.sum_comp (splitPosition d).symm w - -theorem physicalFlow_energy_le (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) : - (∑ x, physicalFlow d B w c x ^ 2) ≤ ∑ x, w x ^ 2 := by - calc - _ = ∑ p, physicalFlow d B w c (scatterPosition d p) ^ 2 := - (Equiv.sum_comp (scatterPosition d) (fun x => physicalFlow d B w c x ^ 2)).symm - _ ≤ ∑ p, w ((splitPosition d).symm p) ^ 2 := by - simp only [physicalFlow_scatter] - exact flow_energy_le (B ∘ (splitPosition d).symm) - (w ∘ (splitPosition d).symm) c - _ = _ := Equiv.sum_comp (splitPosition d).symm (fun x => w x ^ 2) - -theorem physicalFlow_support (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (hw : ∀ x, B x = false → w x = 0) - (c : Coins (d + 1)) (x : Position (d + 1)) - (hx : physicalFree d B c x = false) : physicalFlow d B w c x = 0 := by - obtain ⟨p, rfl⟩ := (scatterPosition d).surjective x - rw [physicalFree_scatter] at hx - rw [physicalFlow_scatter] - exact flow_support _ _ (fun p => hw ((splitPosition d).symm p)) c p hx - -theorem physicalFlow_uniform (d : ℕ) (B : Position (d + 1) → Bool) - (r : ℝ) (c : Coins (d + 1)) (x : Position (d + 1)) : - physicalFlow d B (fun y => if B y then r else 0) c x = - if physicalFree d B c x then r else 0 := by - obtain ⟨p, rfl⟩ := (scatterPosition d).surjective x - rw [physicalFlow_scatter, physicalFree_scatter] - exact flow_uniform _ r c p - -def freeCount {α : Type uα} [Fintype α] (B : α → Bool) : ℕ := - (Finset.univ.filter (fun x => B x = true)).card - -def centeredPoint {α : Type uα} [Fintype α] [DecidableEq α] - (B : α → Bool) (tag : α) (x : α) : ℝ := - (if x = tag then 1 else 0) - (1 / (freeCount B : ℝ)) * (if B x then 1 else 0) - -theorem freeCount_pos {α : Type uα} [Fintype α] (B : α → Bool) (tag : α) - (ht : B tag = true) : 0 < freeCount B := by - apply Finset.card_pos.mpr - exact ⟨tag, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ht⟩⟩ - -theorem sum_free_indicator {α : Type uα} [Fintype α] (B : α → Bool) : - (∑ x : α, if B x then (1 : ℝ) else 0) = freeCount B := by - exact Finset.sum_boole _ _ - -theorem centeredPoint_sum {α : Type uα} [Fintype α] [DecidableEq α] - (B : α → Bool) (tag : α) (ht : B tag = true) : - (∑ x, centeredPoint B tag x) = 0 := by - have hm : (freeCount B : ℝ) ≠ 0 := by exact_mod_cast (freeCount_pos B tag ht).ne' - unfold centeredPoint - rw [Finset.sum_sub_distrib, ← Finset.mul_sum, sum_free_indicator] - simp [hm] - -theorem centeredPoint_support {α : Type uα} [Fintype α] [DecidableEq α] - (B : α → Bool) (tag : α) (ht : B tag = true) - (x : α) (hx : B x = false) : centeredPoint B tag x = 0 := by - have hxt : x ≠ tag := by intro h; subst x; simp_all - simp [centeredPoint, hx, hxt] - -theorem centeredPoint_energy {α : Type uα} [Fintype α] [DecidableEq α] - (B : α → Bool) (tag : α) (ht : B tag = true) : - (∑ x, centeredPoint B tag x ^ 2) = 1 - 1 / (freeCount B : ℝ) := by - have hm : (freeCount B : ℝ) ≠ 0 := by exact_mod_cast (freeCount_pos B tag ht).ne' - have hpoint (x : α) : centeredPoint B tag x ^ 2 = - (if x = tag then (1 - 2 / (freeCount B : ℝ)) else 0) + - (1 / (freeCount B : ℝ)) ^ 2 * (if B x then 1 else 0) := by - by_cases hx : x = tag - · subst x - simp [centeredPoint, ht] - ring - · cases hB : B x <;> simp [centeredPoint, hx, hB] - simp_rw [hpoint] - rw [Finset.sum_add_distrib, ← Finset.mul_sum, sum_free_indicator] - simp only [Finset.sum_ite_eq', Finset.mem_univ, ite_true] - field_simp - ring - -structure CenteredState (d : ℕ) where - free : Position d → Bool - weight : Position d → ℝ - mass_zero : ∑ x, weight x = 0 - supported : ∀ x, free x = false → weight x = 0 - energy_le_one : ∑ x, weight x ^ 2 ≤ 1 - -def initialState (d : ℕ) (B : Position d → Bool) (tag : Position d) - (ht : B tag = true) : CenteredState d where - free := B - weight := centeredPoint B tag - mass_zero := centeredPoint_sum B tag ht - supported := centeredPoint_support B tag ht - energy_le_one := by - rw [centeredPoint_energy B tag ht] - exact sub_le_self _ (by positivity) - -def nextState (d : ℕ) (v : CenteredState (d + 1)) (c : Coins (d + 1)) : - CenteredState (d + 1) where - free := physicalFree d v.free c - weight := physicalFlow d v.free v.weight c - mass_zero := by rw [physicalFlow_sum]; exact v.mass_zero - supported := physicalFlow_support d v.free v.weight v.supported c - energy_le_one := (physicalFlow_energy_le d v.free v.weight c).trans v.energy_le_one - -def iterateState (d : ℕ) (v : CenteredState (d + 1)) : - (t : ℕ) → History (d + 1) t → CenteredState (d + 1) - | 0, _ => v - | t + 1, ω => nextState d (iterateState d v t (fun i => ω i.castSucc)) (ω (Fin.last t)) - -def expectedEnergy (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : ℝ := - mean (fun ω : History (d + 1) t => ∑ x, (iterateState d v t ω).weight x ^ 2) - -theorem expectedEnergy_nonneg (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - 0 ≤ expectedEnergy d v t := by - unfold expectedEnergy mean - positivity - -theorem expectedEnergy_le_one (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - expectedEnergy d v t ≤ 1 := by - unfold expectedEnergy mean - have hc : (0 : ℝ) < Fintype.card (History (d + 1) t) := by - exact_mod_cast Fintype.card_pos - apply (div_le_iff₀ hc).mpr - calc - _ ≤ ∑ _ω : History (d + 1) t, (1 : ℝ) := - Finset.sum_le_sum (fun ω _ => (iterateState d v t ω).energy_le_one) - _ = _ := by simp - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.SpectralDecay + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def splitPosition (d : ℕ) : Position (d + 1) ≃ Bool × Position d := + (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)).symm + +def scatterPosition (d : ℕ) : Bool × Position d ≃ Position (d + 1) := + (splitPosition d).symm.trans (rotate (d + 1)) + +def physicalFlow (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (x : Position (d + 1)) : ℝ := + flow (B ∘ (splitPosition d).symm) (w ∘ (splitPosition d).symm) c + ((scatterPosition d).symm x) + +def physicalFree (d : ℕ) (B : Position (d + 1) → Bool) + (c : Coins (d + 1)) (x : Position (d + 1)) : Bool := + B ((step (d + 1) c).symm x) + +theorem step_symm_scatter (d : ℕ) (c : Coins (d + 1)) (p : Bool × Position d) : + (step (d + 1) c).symm (scatterPosition d p) = + (splitPosition d).symm (pairMap c p) := by + simp [step, scatterPosition, splitPosition, pairSwitch, pairMap] + +@[simp] theorem physicalFlow_scatter (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (p : Bool × Position d) : + physicalFlow d B w c (scatterPosition d p) = + flow (B ∘ (splitPosition d).symm) (w ∘ (splitPosition d).symm) c p := by + simp [physicalFlow] + +@[simp] theorem physicalFree_scatter (d : ℕ) (B : Position (d + 1) → Bool) + (c : Coins (d + 1)) (p : Bool × Position d) : + physicalFree d B c (scatterPosition d p) = + B ((splitPosition d).symm (pairMap c p)) := by + rw [physicalFree, step_symm_scatter] + +theorem physicalFlow_sum (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) : + (∑ x, physicalFlow d B w c x) = ∑ x, w x := by + calc + _ = ∑ p, physicalFlow d B w c (scatterPosition d p) := + (Equiv.sum_comp (scatterPosition d) (physicalFlow d B w c)).symm + _ = ∑ p, w ((splitPosition d).symm p) := by + simp only [physicalFlow_scatter] + exact flow_sum (B ∘ (splitPosition d).symm) + (w ∘ (splitPosition d).symm) c + _ = _ := Equiv.sum_comp (splitPosition d).symm w + +theorem physicalFlow_energy_le (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) : + (∑ x, physicalFlow d B w c x ^ 2) ≤ ∑ x, w x ^ 2 := by + calc + _ = ∑ p, physicalFlow d B w c (scatterPosition d p) ^ 2 := + (Equiv.sum_comp (scatterPosition d) (fun x => physicalFlow d B w c x ^ 2)).symm + _ ≤ ∑ p, w ((splitPosition d).symm p) ^ 2 := by + simp only [physicalFlow_scatter] + exact flow_energy_le (B ∘ (splitPosition d).symm) + (w ∘ (splitPosition d).symm) c + _ = _ := Equiv.sum_comp (splitPosition d).symm (fun x => w x ^ 2) + +theorem physicalFlow_support (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (hw : ∀ x, B x = false → w x = 0) + (c : Coins (d + 1)) (x : Position (d + 1)) + (hx : physicalFree d B c x = false) : physicalFlow d B w c x = 0 := by + obtain ⟨p, rfl⟩ := (scatterPosition d).surjective x + rw [physicalFree_scatter] at hx + rw [physicalFlow_scatter] + exact flow_support _ _ (fun p => hw ((splitPosition d).symm p)) c p hx + +theorem physicalFlow_uniform (d : ℕ) (B : Position (d + 1) → Bool) + (r : ℝ) (c : Coins (d + 1)) (x : Position (d + 1)) : + physicalFlow d B (fun y => if B y then r else 0) c x = + if physicalFree d B c x then r else 0 := by + obtain ⟨p, rfl⟩ := (scatterPosition d).surjective x + rw [physicalFlow_scatter, physicalFree_scatter] + exact flow_uniform _ r c p + +def freeCount {α : Type uα} [Fintype α] (B : α → Bool) : ℕ := + (Finset.univ.filter (fun x => B x = true)).card + +def centeredPoint {α : Type uα} [Fintype α] [DecidableEq α] + (B : α → Bool) (tag : α) (x : α) : ℝ := + (if x = tag then 1 else 0) - (1 / (freeCount B : ℝ)) * (if B x then 1 else 0) + +theorem freeCount_pos {α : Type uα} [Fintype α] (B : α → Bool) (tag : α) + (ht : B tag = true) : 0 < freeCount B := by + apply Finset.card_pos.mpr + exact ⟨tag, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ht⟩⟩ + +theorem sum_free_indicator {α : Type uα} [Fintype α] (B : α → Bool) : + (∑ x : α, if B x then (1 : ℝ) else 0) = freeCount B := by + exact Finset.sum_boole _ _ + +theorem centeredPoint_sum {α : Type uα} [Fintype α] [DecidableEq α] + (B : α → Bool) (tag : α) (ht : B tag = true) : + (∑ x, centeredPoint B tag x) = 0 := by + have hm : (freeCount B : ℝ) ≠ 0 := by exact_mod_cast (freeCount_pos B tag ht).ne' + unfold centeredPoint + rw [Finset.sum_sub_distrib, ← Finset.mul_sum, sum_free_indicator] + simp [hm] + +theorem centeredPoint_support {α : Type uα} [Fintype α] [DecidableEq α] + (B : α → Bool) (tag : α) (ht : B tag = true) + (x : α) (hx : B x = false) : centeredPoint B tag x = 0 := by + have hxt : x ≠ tag := by intro h; subst x; simp_all + simp [centeredPoint, hx, hxt] + +theorem centeredPoint_energy {α : Type uα} [Fintype α] [DecidableEq α] + (B : α → Bool) (tag : α) (ht : B tag = true) : + (∑ x, centeredPoint B tag x ^ 2) = 1 - 1 / (freeCount B : ℝ) := by + have hm : (freeCount B : ℝ) ≠ 0 := by exact_mod_cast (freeCount_pos B tag ht).ne' + have hpoint (x : α) : centeredPoint B tag x ^ 2 = + (if x = tag then (1 - 2 / (freeCount B : ℝ)) else 0) + + (1 / (freeCount B : ℝ)) ^ 2 * (if B x then 1 else 0) := by + by_cases hx : x = tag + · subst x + simp [centeredPoint, ht] + ring + · cases hB : B x <;> simp [centeredPoint, hx, hB] + simp_rw [hpoint] + rw [Finset.sum_add_distrib, ← Finset.mul_sum, sum_free_indicator] + simp only [Finset.sum_ite_eq', Finset.mem_univ, ite_true] + field_simp + ring + +structure CenteredState (d : ℕ) where + free : Position d → Bool + weight : Position d → ℝ + mass_zero : ∑ x, weight x = 0 + supported : ∀ x, free x = false → weight x = 0 + energy_le_one : ∑ x, weight x ^ 2 ≤ 1 + +def initialState (d : ℕ) (B : Position d → Bool) (tag : Position d) + (ht : B tag = true) : CenteredState d where + free := B + weight := centeredPoint B tag + mass_zero := centeredPoint_sum B tag ht + supported := centeredPoint_support B tag ht + energy_le_one := by + rw [centeredPoint_energy B tag ht] + exact sub_le_self _ (by positivity) + +def nextState (d : ℕ) (v : CenteredState (d + 1)) (c : Coins (d + 1)) : + CenteredState (d + 1) where + free := physicalFree d v.free c + weight := physicalFlow d v.free v.weight c + mass_zero := by rw [physicalFlow_sum]; exact v.mass_zero + supported := physicalFlow_support d v.free v.weight v.supported c + energy_le_one := (physicalFlow_energy_le d v.free v.weight c).trans v.energy_le_one + +def iterateState (d : ℕ) (v : CenteredState (d + 1)) : + (t : ℕ) → History (d + 1) t → CenteredState (d + 1) + | 0, _ => v + | t + 1, ω => nextState d (iterateState d v t (fun i => ω i.castSucc)) (ω (Fin.last t)) + +def expectedEnergy (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : ℝ := + mean (fun ω : History (d + 1) t => ∑ x, (iterateState d v t ω).weight x ^ 2) + +theorem expectedEnergy_nonneg (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + 0 ≤ expectedEnergy d v t := by + unfold expectedEnergy mean + positivity + +theorem expectedEnergy_le_one (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + expectedEnergy d v t ≤ 1 := by + unfold expectedEnergy mean + have hc : (0 : ℝ) < Fintype.card (History (d + 1) t) := by + exact_mod_cast Fintype.card_pos + apply (div_le_iff₀ hc).mpr + calc + _ ≤ ∑ _ω : History (d + 1) t, (1 : ℝ) := + Finset.sum_le_sum (fun ω _ => (iterateState d v t ω).energy_le_one) + _ = _ := by simp + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ConditionalLaw.lean b/lean/OAI/Probability/ThorpShuffle/ConditionalLaw.lean index 9e743044ee6cccf7ebf8b9c0958eab6df550993b..38d640c5c722d0ea8a20ad383707a542f50a37a2 100644 --- a/lean/OAI/Probability/ThorpShuffle/ConditionalLaw.lean +++ b/lean/OAI/Probability/ThorpShuffle/ConditionalLaw.lean @@ -1,113 +1,113 @@ -import OAI.Probability.ThorpShuffle.MaskedResampling - -namespace OAI - -universe uι uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -@[simp] theorem run_snoc (d t : ℕ) (ω : History d t) (c : Coins d) : - run d (t + 1) (Fin.snoc ω c) = step d c * run d t ω := by - rw [run_succ] - simp - -theorem flow_joint_identity {ι : Type uι} (d : ℕ) (v : RawState (d + 1)) - (e : ι → Position (d + 1)) (he : ∀ i, v.free (e i) = false) - (t : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : - mean (fun ω : History (d + 1) t => - ∑ x, v.weight x * f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) = - mean (fun ω : History (d + 1) t => - ∑ y, (rawIterate d v t ω).weight y * f ((run (d + 1) t ω) ∘ e) y) := by - induction t generalizing f with - | zero => simp only [run_zero, rawIterate]; rfl - | succ t ih => - let F (e' : ι → Position (d + 1)) (x : Position (d + 1)) : ℝ := - mean (fun c : Coins (d + 1) => f ((step (d + 1) c) ∘ e') (step (d + 1) c x)) - have hleft : - mean (fun ω : History (d + 1) (t + 1) => - ∑ x, v.weight x * f ((run (d + 1) (t + 1) ω) ∘ e) (run (d + 1) (t + 1) ω x)) = - mean (fun ω : History (d + 1) t => - ∑ x, v.weight x * F ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) := by - rw [mean_history_succ] - apply mean_congr - intro ω - simp only [run_snoc] - rw [mean_sum] - simp_rw [mean_const_mul] - rfl - have hright : - mean (fun ω : History (d + 1) (t + 1) => - ∑ y, (rawIterate d v (t + 1) ω).weight y * f ((run (d + 1) (t + 1) ω) ∘ e) y) = - mean (fun ω : History (d + 1) t => - ∑ y, (rawIterate d v t ω).weight y * F ((run (d + 1) t ω) ∘ e) y) := by - rw [mean_history_succ] - apply mean_congr - intro ω - simp only [run_snoc, rawIterate_snoc] - change mean (fun c : Position d → Bool => - ∑ y, physicalFlow d (rawIterate d v t ω).free (rawIterate d v t ω).weight c y * - f ((step (d + 1) c) ∘ ((run (d + 1) t ω) ∘ e)) y) = _ - rw [physicalFlow_joint d (rawIterate d v t ω).free (rawIterate d v t ω).weight - ((run (d + 1) t ω) ∘ e) (by - intro i - simp only [Function.comp_apply, rawIterate_free, Equiv.symm_apply_apply] - exact he i)] - rw [mean_sum] - simp_rw [mean_const_mul] - rfl - exact hleft.trans ((ih F).trans hright.symm) - -theorem centered_joint_identity {ι : Type uι} (d : ℕ) (v : CenteredState (d + 1)) - (e : ι → Position (d + 1)) (he : ∀ i, v.free (e i) = false) - (t : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : - mean (fun ω : History (d + 1) t => - ∑ x, v.weight x * f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) = - mean (fun ω : History (d + 1) t => - ∑ y, (iterateState d v t ω).weight y * f ((run (d + 1) t ω) ∘ e) y) := by - have hh := flow_joint_identity d v.raw e he t f - simp_rw [← iterateState_raw] at hh - exact hh - -theorem centeredPoint_test {α : Type uα} [Fintype α] [DecidableEq α] - (B : α → Bool) (tag : α) (f : α → ℝ) : - (∑ x, centeredPoint B tag x * f x) = - f tag - (1 / (freeCount B : ℝ)) * (∑ x, if B x then f x else 0) := by - simp only [centeredPoint, sub_mul, mul_assoc, Finset.sum_sub_distrib, - ← Finset.mul_sum, ite_mul, one_mul, zero_mul] - simp - -theorem tagged_deviation_identity {ι : Type uι} (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 : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : - mean (fun ω : History (d + 1) t => - f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω tag) - - (1 / (freeCount B : ℝ)) * - (∑ y, if B ((run (d + 1) t ω).symm y) then f ((run (d + 1) t ω) ∘ e) y else 0)) = - mean (fun ω : History (d + 1) t => - ∑ y, (iterateState d (initialState (d + 1) B tag ht) t ω).weight y * - f ((run (d + 1) t ω) ∘ e) y) := by - rw [← centered_joint_identity d (initialState (d + 1) B tag ht) e he t f] - apply mean_congr - intro ω - change _ = ∑ x, centeredPoint B tag x * f ((run (d + 1) t ω) ∘ e) (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 ((run (d + 1) t ω) ∘ e) y else 0)).symm - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.MaskedResampling + +namespace OAI + +universe uι uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +@[simp] theorem run_snoc (d t : ℕ) (ω : History d t) (c : Coins d) : + run d (t + 1) (Fin.snoc ω c) = step d c * run d t ω := by + rw [run_succ] + simp + +theorem flow_joint_identity {ι : Type uι} (d : ℕ) (v : RawState (d + 1)) + (e : ι → Position (d + 1)) (he : ∀ i, v.free (e i) = false) + (t : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : + mean (fun ω : History (d + 1) t => + ∑ x, v.weight x * f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) = + mean (fun ω : History (d + 1) t => + ∑ y, (rawIterate d v t ω).weight y * f ((run (d + 1) t ω) ∘ e) y) := by + induction t generalizing f with + | zero => simp only [run_zero, rawIterate]; rfl + | succ t ih => + let F (e' : ι → Position (d + 1)) (x : Position (d + 1)) : ℝ := + mean (fun c : Coins (d + 1) => f ((step (d + 1) c) ∘ e') (step (d + 1) c x)) + have hleft : + mean (fun ω : History (d + 1) (t + 1) => + ∑ x, v.weight x * f ((run (d + 1) (t + 1) ω) ∘ e) (run (d + 1) (t + 1) ω x)) = + mean (fun ω : History (d + 1) t => + ∑ x, v.weight x * F ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) := by + rw [mean_history_succ] + apply mean_congr + intro ω + simp only [run_snoc] + rw [mean_sum] + simp_rw [mean_const_mul] + rfl + have hright : + mean (fun ω : History (d + 1) (t + 1) => + ∑ y, (rawIterate d v (t + 1) ω).weight y * f ((run (d + 1) (t + 1) ω) ∘ e) y) = + mean (fun ω : History (d + 1) t => + ∑ y, (rawIterate d v t ω).weight y * F ((run (d + 1) t ω) ∘ e) y) := by + rw [mean_history_succ] + apply mean_congr + intro ω + simp only [run_snoc, rawIterate_snoc] + change mean (fun c : Position d → Bool => + ∑ y, physicalFlow d (rawIterate d v t ω).free (rawIterate d v t ω).weight c y * + f ((step (d + 1) c) ∘ ((run (d + 1) t ω) ∘ e)) y) = _ + rw [physicalFlow_joint d (rawIterate d v t ω).free (rawIterate d v t ω).weight + ((run (d + 1) t ω) ∘ e) (by + intro i + simp only [Function.comp_apply, rawIterate_free, Equiv.symm_apply_apply] + exact he i)] + rw [mean_sum] + simp_rw [mean_const_mul] + rfl + exact hleft.trans ((ih F).trans hright.symm) + +theorem centered_joint_identity {ι : Type uι} (d : ℕ) (v : CenteredState (d + 1)) + (e : ι → Position (d + 1)) (he : ∀ i, v.free (e i) = false) + (t : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : + mean (fun ω : History (d + 1) t => + ∑ x, v.weight x * f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω x)) = + mean (fun ω : History (d + 1) t => + ∑ y, (iterateState d v t ω).weight y * f ((run (d + 1) t ω) ∘ e) y) := by + have hh := flow_joint_identity d v.raw e he t f + simp_rw [← iterateState_raw] at hh + exact hh + +theorem centeredPoint_test {α : Type uα} [Fintype α] [DecidableEq α] + (B : α → Bool) (tag : α) (f : α → ℝ) : + (∑ x, centeredPoint B tag x * f x) = + f tag - (1 / (freeCount B : ℝ)) * (∑ x, if B x then f x else 0) := by + simp only [centeredPoint, sub_mul, mul_assoc, Finset.sum_sub_distrib, + ← Finset.mul_sum, ite_mul, one_mul, zero_mul] + simp + +theorem tagged_deviation_identity {ι : Type uι} (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 : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : + mean (fun ω : History (d + 1) t => + f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω tag) - + (1 / (freeCount B : ℝ)) * + (∑ y, if B ((run (d + 1) t ω).symm y) then f ((run (d + 1) t ω) ∘ e) y else 0)) = + mean (fun ω : History (d + 1) t => + ∑ y, (iterateState d (initialState (d + 1) B tag ht) t ω).weight y * + f ((run (d + 1) t ω) ∘ e) y) := by + rw [← centered_joint_identity d (initialState (d + 1) B tag ht) e he t f] + apply mean_congr + intro ω + change _ = ∑ x, centeredPoint B tag x * f ((run (d + 1) t ω) ∘ e) (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 ((run (d + 1) t ω) ∘ e) y else 0)).symm + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ConvolutionBounds.lean b/lean/OAI/Probability/ThorpShuffle/ConvolutionBounds.lean index a29ad0108a6295301284aec6ce96347c3b27ed62..ba54a0ab38537338702a533a4eed33499438410d 100644 --- a/lean/OAI/Probability/ThorpShuffle/ConvolutionBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/ConvolutionBounds.lean @@ -1,154 +1,154 @@ -import OAI.Probability.ThorpShuffle.PermutationCharacters - -namespace OAI - -universe uE - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier -open scoped Classical -variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -lemma hsSq_power_le (A : Module.End ℂ E) (R : ℝ) (hR : 0 ≤ R) - (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) (k : ℕ) : - hsSq (A ^ k) ≤ (Module.finrank ℂ E : ℝ) * R ^ k := by - unfold hsSq - calc - _ ≤ ∑ i, R ^ k * ‖stdOrthonormalBasis ℂ E i‖ ^ 2 := - Finset.sum_le_sum (fun i _ => power_norm_sq A R hR hA k _) - _ = _ := by simp [(stdOrthonormalBasis ℂ E).norm_eq_one, mul_comm] - -lemma Family.eight_transform_bound (F : Family H) (ρ : Representation ℂ G E) - [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (hd : 0 < Module.finrank ℂ E) (ψ : (Fin 8 → H) →* G) (ν : G → ℝ) (B : ℝ) - (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) - (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ - B * (Fintype.card H : ℝ) / Fintype.card G) : - (Module.finrank ℂ E : ℝ) * hsSq (integrated ρ (fun g => (realPower ν 8 g : ℂ))) ≤ - (8 * B * F.reciprocalSum)^8 * ((Module.finrank ℂ E : ℝ)^2)⁻¹ := by - let S : ℝ := ∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ Module.finrank ℂ E), (F.degree b : ℝ)^2 - let R : ℝ := 8 * B * S / Module.finrank ℂ E - have hD : (0 : ℝ) < Module.finrank ℂ E := by exact_mod_cast hd - have hR : 0 ≤ R := by dsimp [R, S]; positivity - have hA (v : E) : ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ R * ‖v‖ ^ 2 := by - simpa only [R, S, Fintype.card_fin, Nat.cast_ofNat] using F.integrated_norm_sq ρ hu (Nat.ne_of_gt hd) ψ ν B hν h1 hB (by - intro i g - convert hcoset i g using 1 - apply Finset.sum_congr rfl - intro h _ - congr 4 - exact Subsingleton.elim _ _) v - rw [integrated_realPower] - calc - _ ≤ (Module.finrank ℂ E : ℝ) * ((Module.finrank ℂ E : ℝ) * R^8) := - mul_le_mul_of_nonneg_left (hsSq_power_le _ R hR hA 8) hD.le - _ = (Module.finrank ℂ E : ℝ)^2 * R^8 := by ring - _ ≤ _ := eight_degree_bound _ hD B S F.reciprocalSum (F.low_degree_sq _) - -omit [FiniteDimensional ℂ E] in -lemma integrated_uniform_real (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hd : 1 < Module.finrank ℂ E) : - integrated ρ (fun _ => (((Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = 0 := by - simpa only [Complex.ofReal_inv, Complex.ofReal_natCast] using integrated_uniform_zero ρ hd - -omit [FiniteDimensional ℂ E] in -lemma centered_trivial (ρ : Representation ℂ G E) (hρ : ∀ g v, ρ g v = v) - (ν : G → ℝ) (h1 : ∑ g, ν g = 1) : - integrated ρ (fun g => ((realPower ν 8 g - (Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = 0 := by - rw [integrated_real_sub] - have htr (g : G) (v : E) : ρ g v = (1 : ℂ) • v := by simpa using hρ g v - rw [integrated_scalar ρ (fun _ => 1) htr, integrated_scalar ρ (fun _ => 1) htr] - simp only [mul_one, ← Complex.ofReal_sum, realPower_sum ν h1, Complex.ofReal_one, - Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - simp [Complex.ofReal_inv, Complex.ofReal_natCast, Fintype.card_ne_zero] - -omit [FiniteDimensional ℂ E] in -lemma centered_character (ρ : Representation ℂ G E) (χ : G → ℂ) - (hρ : ∀ g v, ρ g v = χ g • v) (hχ : ∑ g, χ g = 0) - (ν : G → ℝ) : - integrated ρ (fun g => ((realPower ν 8 g - (Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = - (∑ g, (ν g : ℂ) * χ g)^8 • LinearMap.id := by - rw [integrated_real_sub, integrated_realPower, integrated_scalar ρ χ hρ, - integrated_scalar ρ χ hρ] - simp only [← Finset.mul_sum, hχ, mul_zero, zero_smul, sub_zero] - simp only [smul_pow, show (LinearMap.id : Module.End ℂ E) = 1 from rfl, one_pow] - -end Thorp.Fourier - -namespace Thorp.Specht -open scoped Classical -open Thorp.Fourier -variable {α β : Type} [Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β] [Nontrivial α] - -theorem permutation_eight_bound (hn : 16 ≤ Fintype.card α) - (ψ : (Fin 8 → Equiv.Perm β) →* Equiv.Perm α) (ν : Equiv.Perm α → ℝ) (B : ℝ) - (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) - (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ - B * (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α)) : - (∑ g, |realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹|)^2 ≤ - 2 * ‖∑ g, (ν g : ℂ) * complexSign g‖^16 + - (8 * B * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α) := by - let F := permutationFamily α - let H := permutationFamily β - let bias : ℝ := ‖∑ g, (ν g : ℂ) * complexSign g‖^16 - let K : ℝ := (8 * B * H.reciprocalSum)^8 - let f : Equiv.Perm α → ℝ := fun g => realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹ - have hp (p : F.Index) : - (F.degree p : ℝ) * hsSq (integrated (F.rep p) (fun g => (f g : ℂ))) ≤ - if defect p = 0 then bias else K * inverseDegree p := by - by_cases hz : defect p = 0 - · rw [ite_eq_left hz] - obtain ⟨hd, htr | hsign⟩ := permutation_exceptional_action (α:=α) p hz - · have hh := centered_trivial (F.rep p) htr ν h1 - change integrated (F.rep p) (fun g => (f g : ℂ)) = 0 at hh - rw [hh] - simp only [hsSq, LinearMap.zero_apply, norm_zero, zero_pow (by decide : 2 ≠ 0), - Finset.sum_const_zero, mul_zero] - exact pow_nonneg (norm_nonneg _) _ - · have hh := centered_character (F.rep p) complexSign hsign (complexSign_sum (α:=α)) ν - change integrated (F.rep p) (fun g => (f g : ℂ)) = _ at hh - rw [hh, hsSq_scalar] - change (F.degree p : ℝ) * ((F.degree p : ℝ) * ‖(∑ g, (ν g : ℂ) * complexSign g)^8‖^2) ≤ bias - rw [show F.degree p = 1 from hd] - simp only [Nat.cast_one, one_mul, norm_pow, ← pow_mul] - exact le_rfl - · rw [ite_eq_right hz] - have hgt : 1 < Module.finrank ℂ (F.Space p) := degree_gt_one p hn (Nat.pos_of_ne_zero hz) - have hu := integrated_uniform_real (F.rep p) hgt - have he : integrated (F.rep p) (fun g => (f g : ℂ)) = - integrated (F.rep p) (fun g => (realPower ν 8 g : ℂ)) := by - rw [show (fun g => (f g : ℂ)) = (fun g => ((realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹ : ℝ) : ℂ)) from rfl, - integrated_real_sub, hu, sub_zero] - rw [he] - exact H.eight_transform_bound (F.rep p) (F.unitary p) (by omega) ψ ν B hν h1 hB hcoset - have hs : (∑ p : NShape (Fintype.card α), if defect p = 0 then bias else K * inverseDegree p) = - (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) * bias + - K * exceptionalReciprocalSum (Fintype.card α) := by - rw [show (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) * bias = - ∑ p : NShape (Fintype.card α), if defect p = 0 then bias else 0 by rw [← Finset.sum_filter]; simp [Fintype.card_subtype], - exceptionalReciprocalSum, Finset.mul_sum, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro p _ - by_cases hz : defect p = 0 - · simp only [hz, lt_self_iff_false, ↓reduceIte, mul_zero, add_zero] - · simp only [hz, Nat.pos_of_ne_zero hz, ↓reduceIte, zero_add] - have hc : (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) ≤ 2 := by - exact_mod_cast exceptional_count (Fintype.card α) - calc - _ ≤ ∑ p, (F.degree p : ℝ) * hsSq (integrated (F.rep p) (fun g => (f g : ℂ))) := F.l1_sq_le_parseval f - _ ≤ ∑ p : NShape (Fintype.card α), if defect p = 0 then bias else K * inverseDegree p := - Finset.sum_le_sum (fun p _ => hp p) - _ = _ := hs - _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right hc (pow_nonneg (norm_nonneg _) _)) le_rfl - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.PermutationCharacters + +namespace OAI + +universe uE + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier +open scoped Classical +variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +lemma hsSq_power_le (A : Module.End ℂ E) (R : ℝ) (hR : 0 ≤ R) + (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) (k : ℕ) : + hsSq (A ^ k) ≤ (Module.finrank ℂ E : ℝ) * R ^ k := by + unfold hsSq + calc + _ ≤ ∑ i, R ^ k * ‖stdOrthonormalBasis ℂ E i‖ ^ 2 := + Finset.sum_le_sum (fun i _ => power_norm_sq A R hR hA k _) + _ = _ := by simp [(stdOrthonormalBasis ℂ E).norm_eq_one, mul_comm] + +lemma Family.eight_transform_bound (F : Family H) (ρ : Representation ℂ G E) + [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (hd : 0 < Module.finrank ℂ E) (ψ : (Fin 8 → H) →* G) (ν : G → ℝ) (B : ℝ) + (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) + (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ + B * (Fintype.card H : ℝ) / Fintype.card G) : + (Module.finrank ℂ E : ℝ) * hsSq (integrated ρ (fun g => (realPower ν 8 g : ℂ))) ≤ + (8 * B * F.reciprocalSum)^8 * ((Module.finrank ℂ E : ℝ)^2)⁻¹ := by + let S : ℝ := ∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ Module.finrank ℂ E), (F.degree b : ℝ)^2 + let R : ℝ := 8 * B * S / Module.finrank ℂ E + have hD : (0 : ℝ) < Module.finrank ℂ E := by exact_mod_cast hd + have hR : 0 ≤ R := by dsimp [R, S]; positivity + have hA (v : E) : ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ R * ‖v‖ ^ 2 := by + simpa only [R, S, Fintype.card_fin, Nat.cast_ofNat] using F.integrated_norm_sq ρ hu (Nat.ne_of_gt hd) ψ ν B hν h1 hB (by + intro i g + convert hcoset i g using 1 + apply Finset.sum_congr rfl + intro h _ + congr 4 + exact Subsingleton.elim _ _) v + rw [integrated_realPower] + calc + _ ≤ (Module.finrank ℂ E : ℝ) * ((Module.finrank ℂ E : ℝ) * R^8) := + mul_le_mul_of_nonneg_left (hsSq_power_le _ R hR hA 8) hD.le + _ = (Module.finrank ℂ E : ℝ)^2 * R^8 := by ring + _ ≤ _ := eight_degree_bound _ hD B S F.reciprocalSum (F.low_degree_sq _) + +omit [FiniteDimensional ℂ E] in +lemma integrated_uniform_real (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hd : 1 < Module.finrank ℂ E) : + integrated ρ (fun _ => (((Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = 0 := by + simpa only [Complex.ofReal_inv, Complex.ofReal_natCast] using integrated_uniform_zero ρ hd + +omit [FiniteDimensional ℂ E] in +lemma centered_trivial (ρ : Representation ℂ G E) (hρ : ∀ g v, ρ g v = v) + (ν : G → ℝ) (h1 : ∑ g, ν g = 1) : + integrated ρ (fun g => ((realPower ν 8 g - (Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = 0 := by + rw [integrated_real_sub] + have htr (g : G) (v : E) : ρ g v = (1 : ℂ) • v := by simpa using hρ g v + rw [integrated_scalar ρ (fun _ => 1) htr, integrated_scalar ρ (fun _ => 1) htr] + simp only [mul_one, ← Complex.ofReal_sum, realPower_sum ν h1, Complex.ofReal_one, + Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + simp [Complex.ofReal_inv, Complex.ofReal_natCast, Fintype.card_ne_zero] + +omit [FiniteDimensional ℂ E] in +lemma centered_character (ρ : Representation ℂ G E) (χ : G → ℂ) + (hρ : ∀ g v, ρ g v = χ g • v) (hχ : ∑ g, χ g = 0) + (ν : G → ℝ) : + integrated ρ (fun g => ((realPower ν 8 g - (Fintype.card G : ℝ)⁻¹ : ℝ) : ℂ)) = + (∑ g, (ν g : ℂ) * χ g)^8 • LinearMap.id := by + rw [integrated_real_sub, integrated_realPower, integrated_scalar ρ χ hρ, + integrated_scalar ρ χ hρ] + simp only [← Finset.mul_sum, hχ, mul_zero, zero_smul, sub_zero] + simp only [smul_pow, show (LinearMap.id : Module.End ℂ E) = 1 from rfl, one_pow] + +end Thorp.Fourier + +namespace Thorp.Specht +open scoped Classical +open Thorp.Fourier +variable {α β : Type} [Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β] [Nontrivial α] + +theorem permutation_eight_bound (hn : 16 ≤ Fintype.card α) + (ψ : (Fin 8 → Equiv.Perm β) →* Equiv.Perm α) (ν : Equiv.Perm α → ℝ) (B : ℝ) + (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) + (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ + B * (Fintype.card (Equiv.Perm β) : ℝ) / Fintype.card (Equiv.Perm α)) : + (∑ g, |realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹|)^2 ≤ + 2 * ‖∑ g, (ν g : ℂ) * complexSign g‖^16 + + (8 * B * (permutationFamily β).reciprocalSum)^8 * exceptionalReciprocalSum (Fintype.card α) := by + let F := permutationFamily α + let H := permutationFamily β + let bias : ℝ := ‖∑ g, (ν g : ℂ) * complexSign g‖^16 + let K : ℝ := (8 * B * H.reciprocalSum)^8 + let f : Equiv.Perm α → ℝ := fun g => realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹ + have hp (p : F.Index) : + (F.degree p : ℝ) * hsSq (integrated (F.rep p) (fun g => (f g : ℂ))) ≤ + if defect p = 0 then bias else K * inverseDegree p := by + by_cases hz : defect p = 0 + · rw [ite_eq_left hz] + obtain ⟨hd, htr | hsign⟩ := permutation_exceptional_action (α:=α) p hz + · have hh := centered_trivial (F.rep p) htr ν h1 + change integrated (F.rep p) (fun g => (f g : ℂ)) = 0 at hh + rw [hh] + simp only [hsSq, LinearMap.zero_apply, norm_zero, zero_pow (by decide : 2 ≠ 0), + Finset.sum_const_zero, mul_zero] + exact pow_nonneg (norm_nonneg _) _ + · have hh := centered_character (F.rep p) complexSign hsign (complexSign_sum (α:=α)) ν + change integrated (F.rep p) (fun g => (f g : ℂ)) = _ at hh + rw [hh, hsSq_scalar] + change (F.degree p : ℝ) * ((F.degree p : ℝ) * ‖(∑ g, (ν g : ℂ) * complexSign g)^8‖^2) ≤ bias + rw [show F.degree p = 1 from hd] + simp only [Nat.cast_one, one_mul, norm_pow, ← pow_mul] + exact le_rfl + · rw [ite_eq_right hz] + have hgt : 1 < Module.finrank ℂ (F.Space p) := degree_gt_one p hn (Nat.pos_of_ne_zero hz) + have hu := integrated_uniform_real (F.rep p) hgt + have he : integrated (F.rep p) (fun g => (f g : ℂ)) = + integrated (F.rep p) (fun g => (realPower ν 8 g : ℂ)) := by + rw [show (fun g => (f g : ℂ)) = (fun g => ((realPower ν 8 g - (Fintype.card (Equiv.Perm α) : ℝ)⁻¹ : ℝ) : ℂ)) from rfl, + integrated_real_sub, hu, sub_zero] + rw [he] + exact H.eight_transform_bound (F.rep p) (F.unitary p) (by omega) ψ ν B hν h1 hB hcoset + have hs : (∑ p : NShape (Fintype.card α), if defect p = 0 then bias else K * inverseDegree p) = + (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) * bias + + K * exceptionalReciprocalSum (Fintype.card α) := by + rw [show (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) * bias = + ∑ p : NShape (Fintype.card α), if defect p = 0 then bias else 0 by rw [← Finset.sum_filter]; simp [Fintype.card_subtype], + exceptionalReciprocalSum, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + by_cases hz : defect p = 0 + · simp only [hz, lt_self_iff_false, ↓reduceIte, mul_zero, add_zero] + · simp only [hz, Nat.pos_of_ne_zero hz, ↓reduceIte, zero_add] + have hc : (Fintype.card {p : NShape (Fintype.card α) // defect p = 0} : ℝ) ≤ 2 := by + exact_mod_cast exceptional_count (Fintype.card α) + calc + _ ≤ ∑ p, (F.degree p : ℝ) * hsSq (integrated (F.rep p) (fun g => (f g : ℂ))) := F.l1_sq_le_parseval f + _ ≤ ∑ p : NShape (Fintype.card α), if defect p = 0 then bias else K * inverseDegree p := + Finset.sum_le_sum (fun p _ => hp p) + _ = _ := hs + _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right hc (pow_nonneg (norm_nonneg _) _)) le_rfl + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/CosetBounds.lean b/lean/OAI/Probability/ThorpShuffle/CosetBounds.lean index 71e0e606c8b4eb90c41b26d99a6c3c7c2443da3c..1a1e78385dae02e24ccb7d383c8f4a594b78f19e 100644 --- a/lean/OAI/Probability/ThorpShuffle/CosetBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/CosetBounds.lean @@ -1,192 +1,192 @@ -import OAI.Probability.ThorpShuffle.ProductProjectors - -namespace OAI - -universe uG uH uE uJ - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] - -lemma coset_sum_reindex (φ : H →* G) (ν f : G → ℝ) : - ∑ g, ν g * ∑ h, f (g * φ h) = ∑ g, (∑ h, ν (g * φ h)) * f g := by - simp only [Finset.mul_sum, Finset.sum_mul] - rw [Finset.sum_comm, Finset.sum_comm (f := fun g h => ν (g * φ h) * f g)] - have he := Equiv.sum_comp (Equiv.inv H) (fun h => ∑ g, ν (g * φ h) * f g) - rw [← he] - apply Finset.sum_congr rfl - intro h _ - have hh := Equiv.sum_comp (Equiv.mulRight ((φ h)⁻¹)) (fun g => ν g * f (g * φ h)) - rw [← hh] - simp only [Equiv.coe_mulRight, Equiv.inv_apply, map_inv, inv_mul_cancel_right] - -lemma weighted_coset_bound (φ : H →* G) (ν f : G → ℝ) (S C : ℝ) - (hν : ∀ g, 0 ≤ ν g) (hf : ∀ g, 0 ≤ f g) (hS : 0 ≤ S) - (heval : ∀ g, (Fintype.card H : ℝ) * f g ≤ S * ∑ h, f (g * φ h)) - (hcoset : ∀ g, ∑ h, ν (g * φ h) ≤ C) : - (Fintype.card H : ℝ) * ∑ g, ν g * f g ≤ S * C * ∑ g, f g := by - calc - _ = ∑ g, ν g * ((Fintype.card H : ℝ) * f g) := by rw [Finset.mul_sum]; congr 1; funext g; ring - _ ≤ ∑ g, ν g * (S * ∑ h, f (g * φ h)) := - Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_left (heval g) (hν g)) - _ = S * ∑ g, (∑ h, ν (g * φ h)) * f g := by - rw [← coset_sum_reindex φ ν f, Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - _ ≤ S * ∑ g, C * f g := mul_le_mul_of_nonneg_left - (Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_right (hcoset g) (hf g))) hS - _ = _ := by rw [← Finset.mul_sum]; ring - -namespace Family -variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] (F : Family H) -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -omit [Fintype G] [FiniteDimensional ℂ E] in -lemma coset_coefficient_evaluation (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (φ : H →* G) (s : Finset F.Index) (v w : E) - (hv : (∑ i ∈ s, F.projector (ρ.comp φ) i) v = v) (g : G) : - (Fintype.card H : ℝ) * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ - (∑ i ∈ s, (F.degree i : ℝ)^2) * ∑ h, ‖⟪w, ρ (g * φ h) v⟫_ℂ‖ ^ 2 := by - have he := F.coefficient_evaluation (ρ.comp φ) s v (ρ g⁻¹ w) hv - have hh (x : E) : ⟪ρ g⁻¹ w, x⟫_ℂ = ⟪w, ρ g x⟫_ℂ := by - simpa only [inv_inv] using (inner_inv ρ hu g⁻¹ w x).symm - simpa only [hh, MonoidHom.comp_apply, map_mul, Module.End.mul_apply] using he - -theorem weighted_coefficient (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (hE : Module.finrank ℂ E ≠ 0) (φ : H →* G) (s : Finset F.Index) (ν : G → ℝ) (B : ℝ) - (hν : ∀ g, 0 ≤ ν g) - (hcoset : ∀ g, ∑ h, ν (g * φ h) ≤ B * (Fintype.card H : ℝ) / Fintype.card G) - (v w : E) (hv : (∑ i ∈ s, F.projector (ρ.comp φ) i) v = v) : - ∑ g, ν g * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ - B * (∑ i ∈ s, (F.degree i : ℝ)^2) / Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2) := by - have hh := weighted_coset_bound φ ν (fun g => ‖⟪w, ρ g v⟫_ℂ‖ ^ 2) - (∑ i ∈ s, (F.degree i : ℝ)^2) (B * (Fintype.card H : ℝ) / Fintype.card G) - hν (fun _ => sq_nonneg _) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) - (F.coset_coefficient_evaluation ρ hu φ s v w hv) hcoset - have hcG : (Fintype.card G : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - have hcH : (0 : ℝ) < Fintype.card H := by exact_mod_cast Fintype.card_pos - have hd : (Module.finrank ℂ E : ℝ) ≠ 0 := by exact_mod_cast hE - have hs := coefficient_second_moment ρ hu hE v w - have hs' : ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = - (Fintype.card G : ℝ) * (‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E) := by - calc - _ = (Fintype.card G : ℝ) * ((Fintype.card G : ℝ)⁻¹ * ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2) := by field_simp - _ = _ := by rw [hs] - rw [hs'] at hh - have he : (∑ i ∈ s, (F.degree i : ℝ)^2) * (B * (Fintype.card H : ℝ) / Fintype.card G) * - ((Fintype.card G : ℝ) * (‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E)) = - (Fintype.card H : ℝ) * (B * (∑ i ∈ s, (F.degree i : ℝ)^2) / - Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2)) := by field_simp - rw [he] at hh - exact (mul_le_mul_iff_right₀ hcH).mp hh - -end Family -end Thorp.Fourier - -namespace Thorp.Fourier -open scoped Classical - -lemma norm_weighted_sum_sq {J : Type uJ} [Fintype J] (ν : J → ℝ) (f : J → ℂ) - (hν : ∀ j, 0 ≤ ν j) (h1 : ∑ j, ν j = 1) : - ‖∑ j, (ν j : ℂ) * f j‖ ^ 2 ≤ ∑ j, ν j * ‖f j‖ ^ 2 := by - have ht : ‖∑ j, (ν j : ℂ) * f j‖ ≤ ∑ j, ν j * ‖f j‖ := by - simpa only [norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (hν _)] using - norm_sum_le Finset.univ (fun j => (ν j : ℂ) * f j) - have hc := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (f := ν) (g := fun j => ν j * ‖f j‖ ^ 2) (r := fun j => ν j * ‖f j‖) - (fun j _ => hν j) (fun j _ => mul_nonneg (hν j) (sq_nonneg _)) - (fun j _ => by nlinarith [sq_nonneg (ν j * ‖f j‖)]) - rw [h1, one_mul] at hc - exact (pow_le_pow_left₀ (norm_nonneg _) ht 2).trans hc - -namespace Family -variable {G H I : Type} [Group G] [Fintype G] [Group H] [Fintype H] - [Fintype I] [Nonempty I] (F : Family H) -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -theorem split_weighted_coefficient (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (hE : Module.finrank ℂ E ≠ 0) (ψ : (I → H) →* G) (ν : G → ℝ) (B : ℝ) - (hν : ∀ g, 0 ≤ ν g) - (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ - B * (Fintype.card H : ℝ) / Fintype.card G) (v w : E) : - ∑ g, ν g * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ - (Fintype.card I : ℝ) * B * - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), - (F.degree b : ℝ)^2) / Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2) := by - let z := F.splitVector (ρ.comp ψ) v - let s := Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E) - let S : ℝ := ∑ b ∈ s, (F.degree b : ℝ)^2 - have hz : ∑ i, z i = v := F.splitVector_sum (ρ.comp ψ) v - have hz2 : ∑ i, ‖z i‖ ^ 2 = ‖v‖ ^ 2 := F.splitVector_sq_sum (ρ.comp ψ) (fun g => hu (ψ g)) v - have hpoint (g : G) : ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ (Fintype.card I : ℝ) * ∑ i, ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 := by - have hh := complex_cauchy Finset.univ (fun _ : I => 1) (fun i => ⟪w, ρ g (z i)⟫_ℂ) - simpa only [one_mul, norm_one, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, - mul_one, ← inner_sum, ← map_sum, hz] using hh - have hi (i : I) : ∑ g, ν g * ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 ≤ - B * S / Module.finrank ℂ E * (‖z i‖ ^ 2 * ‖w‖ ^ 2) := by - exact F.weighted_coefficient ρ hu hE (ψ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) - s ν B hν (hcoset i) (z i) w (F.splitVector_low (ρ.comp ψ) v i) - calc - _ ≤ ∑ g, ν g * ((Fintype.card I : ℝ) * ∑ i, ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2) := - Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_left (hpoint g) (hν g)) - _ = (Fintype.card I : ℝ) * ∑ i, ∑ g, ν g * ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 := by - rw [Finset.sum_comm, Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - rw [← Finset.mul_sum] - ring - _ ≤ (Fintype.card I : ℝ) * ∑ i, B * S / Module.finrank ℂ E * (‖z i‖ ^ 2 * ‖w‖ ^ 2) := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hi i)) (Nat.cast_nonneg _) - _ = _ := by - simp only [← Finset.mul_sum, ← Finset.sum_mul, hz2] - dsimp [S, s] - ring - -theorem integrated_norm_sq (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (hE : Module.finrank ℂ E ≠ 0) (ψ : (I → H) →* G) (ν : G → ℝ) (B : ℝ) - (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) - (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ - B * (Fintype.card H : ℝ) / Fintype.card G) (v : E) : - ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ - (Fintype.card I : ℝ) * B * - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), - (F.degree b : ℝ)^2) / Module.finrank ℂ E * ‖v‖ ^ 2 := by - let A := integrated ρ (fun g => (ν g : ℂ)) - let R := (Fintype.card I : ℝ) * B * - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), - (F.degree b : ℝ)^2) / Module.finrank ℂ E - have hc : ‖⟪A v, A v⟫_ℂ‖ ^ 2 ≤ R * (‖v‖ ^ 2 * ‖A v‖ ^ 2) := by - calc - _ = ‖∑ g, (ν g : ℂ) * ⟪A v, ρ g v⟫_ℂ‖ ^ 2 := by - congr 2 - simp only [A, integrated, LinearMap.sum_apply, LinearMap.smul_apply, - inner_sum, inner_smul_right] - _ ≤ ∑ g, ν g * ‖⟪A v, ρ g v⟫_ℂ‖ ^ 2 := norm_weighted_sum_sq ν _ hν h1 - _ ≤ _ := F.split_weighted_coefficient ρ hu hE ψ ν B hν hcoset v (A v) - have hinner : ‖⟪A v, A v⟫_ℂ‖ = ‖A v‖ ^ 2 := by simp [inner_self_eq_norm_sq_to_K] - rw [hinner] at hc - have hR : 0 ≤ R := by positivity - by_cases hz : ‖A v‖ ^ 2 = 0 - · change ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2 - rw [hz] - exact mul_nonneg hR (sq_nonneg _) - · have hp : 0 < ‖A v‖ ^ 2 := lt_of_le_of_ne (sq_nonneg _) (Ne.symm hz) - change ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2 - nlinarith - -end Family -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.ProductProjectors + +namespace OAI + +universe uG uH uE uJ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] + +lemma coset_sum_reindex (φ : H →* G) (ν f : G → ℝ) : + ∑ g, ν g * ∑ h, f (g * φ h) = ∑ g, (∑ h, ν (g * φ h)) * f g := by + simp only [Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm, Finset.sum_comm (f := fun g h => ν (g * φ h) * f g)] + have he := Equiv.sum_comp (Equiv.inv H) (fun h => ∑ g, ν (g * φ h) * f g) + rw [← he] + apply Finset.sum_congr rfl + intro h _ + have hh := Equiv.sum_comp (Equiv.mulRight ((φ h)⁻¹)) (fun g => ν g * f (g * φ h)) + rw [← hh] + simp only [Equiv.coe_mulRight, Equiv.inv_apply, map_inv, inv_mul_cancel_right] + +lemma weighted_coset_bound (φ : H →* G) (ν f : G → ℝ) (S C : ℝ) + (hν : ∀ g, 0 ≤ ν g) (hf : ∀ g, 0 ≤ f g) (hS : 0 ≤ S) + (heval : ∀ g, (Fintype.card H : ℝ) * f g ≤ S * ∑ h, f (g * φ h)) + (hcoset : ∀ g, ∑ h, ν (g * φ h) ≤ C) : + (Fintype.card H : ℝ) * ∑ g, ν g * f g ≤ S * C * ∑ g, f g := by + calc + _ = ∑ g, ν g * ((Fintype.card H : ℝ) * f g) := by rw [Finset.mul_sum]; congr 1; funext g; ring + _ ≤ ∑ g, ν g * (S * ∑ h, f (g * φ h)) := + Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_left (heval g) (hν g)) + _ = S * ∑ g, (∑ h, ν (g * φ h)) * f g := by + rw [← coset_sum_reindex φ ν f, Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + _ ≤ S * ∑ g, C * f g := mul_le_mul_of_nonneg_left + (Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_right (hcoset g) (hf g))) hS + _ = _ := by rw [← Finset.mul_sum]; ring + +namespace Family +variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] (F : Family H) +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [Fintype G] [FiniteDimensional ℂ E] in +lemma coset_coefficient_evaluation (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (φ : H →* G) (s : Finset F.Index) (v w : E) + (hv : (∑ i ∈ s, F.projector (ρ.comp φ) i) v = v) (g : G) : + (Fintype.card H : ℝ) * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ + (∑ i ∈ s, (F.degree i : ℝ)^2) * ∑ h, ‖⟪w, ρ (g * φ h) v⟫_ℂ‖ ^ 2 := by + have he := F.coefficient_evaluation (ρ.comp φ) s v (ρ g⁻¹ w) hv + have hh (x : E) : ⟪ρ g⁻¹ w, x⟫_ℂ = ⟪w, ρ g x⟫_ℂ := by + simpa only [inv_inv] using (inner_inv ρ hu g⁻¹ w x).symm + simpa only [hh, MonoidHom.comp_apply, map_mul, Module.End.mul_apply] using he + +theorem weighted_coefficient (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (hE : Module.finrank ℂ E ≠ 0) (φ : H →* G) (s : Finset F.Index) (ν : G → ℝ) (B : ℝ) + (hν : ∀ g, 0 ≤ ν g) + (hcoset : ∀ g, ∑ h, ν (g * φ h) ≤ B * (Fintype.card H : ℝ) / Fintype.card G) + (v w : E) (hv : (∑ i ∈ s, F.projector (ρ.comp φ) i) v = v) : + ∑ g, ν g * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ + B * (∑ i ∈ s, (F.degree i : ℝ)^2) / Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2) := by + have hh := weighted_coset_bound φ ν (fun g => ‖⟪w, ρ g v⟫_ℂ‖ ^ 2) + (∑ i ∈ s, (F.degree i : ℝ)^2) (B * (Fintype.card H : ℝ) / Fintype.card G) + hν (fun _ => sq_nonneg _) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + (F.coset_coefficient_evaluation ρ hu φ s v w hv) hcoset + have hcG : (Fintype.card G : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hcH : (0 : ℝ) < Fintype.card H := by exact_mod_cast Fintype.card_pos + have hd : (Module.finrank ℂ E : ℝ) ≠ 0 := by exact_mod_cast hE + have hs := coefficient_second_moment ρ hu hE v w + have hs' : ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = + (Fintype.card G : ℝ) * (‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E) := by + calc + _ = (Fintype.card G : ℝ) * ((Fintype.card G : ℝ)⁻¹ * ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2) := by field_simp + _ = _ := by rw [hs] + rw [hs'] at hh + have he : (∑ i ∈ s, (F.degree i : ℝ)^2) * (B * (Fintype.card H : ℝ) / Fintype.card G) * + ((Fintype.card G : ℝ) * (‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E)) = + (Fintype.card H : ℝ) * (B * (∑ i ∈ s, (F.degree i : ℝ)^2) / + Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2)) := by field_simp + rw [he] at hh + exact (mul_le_mul_iff_right₀ hcH).mp hh + +end Family +end Thorp.Fourier + +namespace Thorp.Fourier +open scoped Classical + +lemma norm_weighted_sum_sq {J : Type uJ} [Fintype J] (ν : J → ℝ) (f : J → ℂ) + (hν : ∀ j, 0 ≤ ν j) (h1 : ∑ j, ν j = 1) : + ‖∑ j, (ν j : ℂ) * f j‖ ^ 2 ≤ ∑ j, ν j * ‖f j‖ ^ 2 := by + have ht : ‖∑ j, (ν j : ℂ) * f j‖ ≤ ∑ j, ν j * ‖f j‖ := by + simpa only [norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (hν _)] using + norm_sum_le Finset.univ (fun j => (ν j : ℂ) * f j) + have hc := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (f := ν) (g := fun j => ν j * ‖f j‖ ^ 2) (r := fun j => ν j * ‖f j‖) + (fun j _ => hν j) (fun j _ => mul_nonneg (hν j) (sq_nonneg _)) + (fun j _ => by nlinarith [sq_nonneg (ν j * ‖f j‖)]) + rw [h1, one_mul] at hc + exact (pow_le_pow_left₀ (norm_nonneg _) ht 2).trans hc + +namespace Family +variable {G H I : Type} [Group G] [Fintype G] [Group H] [Fintype H] + [Fintype I] [Nonempty I] (F : Family H) +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +theorem split_weighted_coefficient (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (hE : Module.finrank ℂ E ≠ 0) (ψ : (I → H) →* G) (ν : G → ℝ) (B : ℝ) + (hν : ∀ g, 0 ≤ ν g) + (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ + B * (Fintype.card H : ℝ) / Fintype.card G) (v w : E) : + ∑ g, ν g * ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ + (Fintype.card I : ℝ) * B * + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), + (F.degree b : ℝ)^2) / Module.finrank ℂ E * (‖v‖ ^ 2 * ‖w‖ ^ 2) := by + let z := F.splitVector (ρ.comp ψ) v + let s := Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E) + let S : ℝ := ∑ b ∈ s, (F.degree b : ℝ)^2 + have hz : ∑ i, z i = v := F.splitVector_sum (ρ.comp ψ) v + have hz2 : ∑ i, ‖z i‖ ^ 2 = ‖v‖ ^ 2 := F.splitVector_sq_sum (ρ.comp ψ) (fun g => hu (ψ g)) v + have hpoint (g : G) : ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 ≤ (Fintype.card I : ℝ) * ∑ i, ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 := by + have hh := complex_cauchy Finset.univ (fun _ : I => 1) (fun i => ⟪w, ρ g (z i)⟫_ℂ) + simpa only [one_mul, norm_one, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, + mul_one, ← inner_sum, ← map_sum, hz] using hh + have hi (i : I) : ∑ g, ν g * ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 ≤ + B * S / Module.finrank ℂ E * (‖z i‖ ^ 2 * ‖w‖ ^ 2) := by + exact F.weighted_coefficient ρ hu hE (ψ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) + s ν B hν (hcoset i) (z i) w (F.splitVector_low (ρ.comp ψ) v i) + calc + _ ≤ ∑ g, ν g * ((Fintype.card I : ℝ) * ∑ i, ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2) := + Finset.sum_le_sum (fun g _ => mul_le_mul_of_nonneg_left (hpoint g) (hν g)) + _ = (Fintype.card I : ℝ) * ∑ i, ∑ g, ν g * ‖⟪w, ρ g (z i)⟫_ℂ‖ ^ 2 := by + rw [Finset.sum_comm, Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + rw [← Finset.mul_sum] + ring + _ ≤ (Fintype.card I : ℝ) * ∑ i, B * S / Module.finrank ℂ E * (‖z i‖ ^ 2 * ‖w‖ ^ 2) := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hi i)) (Nat.cast_nonneg _) + _ = _ := by + simp only [← Finset.mul_sum, ← Finset.sum_mul, hz2] + dsimp [S, s] + ring + +theorem integrated_norm_sq (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (hE : Module.finrank ℂ E ≠ 0) (ψ : (I → H) →* G) (ν : G → ℝ) (B : ℝ) + (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) (hB : 0 ≤ B) + (hcoset : ∀ i g, ∑ h, ν (g * ψ (Pi.mulSingle i h)) ≤ + B * (Fintype.card H : ℝ) / Fintype.card G) (v : E) : + ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ + (Fintype.card I : ℝ) * B * + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), + (F.degree b : ℝ)^2) / Module.finrank ℂ E * ‖v‖ ^ 2 := by + let A := integrated ρ (fun g => (ν g : ℂ)) + let R := (Fintype.card I : ℝ) * B * + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), + (F.degree b : ℝ)^2) / Module.finrank ℂ E + have hc : ‖⟪A v, A v⟫_ℂ‖ ^ 2 ≤ R * (‖v‖ ^ 2 * ‖A v‖ ^ 2) := by + calc + _ = ‖∑ g, (ν g : ℂ) * ⟪A v, ρ g v⟫_ℂ‖ ^ 2 := by + congr 2 + simp only [A, integrated, LinearMap.sum_apply, LinearMap.smul_apply, + inner_sum, inner_smul_right] + _ ≤ ∑ g, ν g * ‖⟪A v, ρ g v⟫_ℂ‖ ^ 2 := norm_weighted_sum_sq ν _ hν h1 + _ ≤ _ := F.split_weighted_coefficient ρ hu hE ψ ν B hν hcoset v (A v) + have hinner : ‖⟪A v, A v⟫_ℂ‖ = ‖A v‖ ^ 2 := by simp [inner_self_eq_norm_sq_to_K] + rw [hinner] at hc + have hR : 0 ≤ R := by positivity + by_cases hz : ‖A v‖ ^ 2 = 0 + · change ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2 + rw [hz] + exact mul_nonneg hR (sq_nonneg _) + · have hp : 0 < ‖A v‖ ^ 2 := lt_of_le_of_ne (sq_nonneg _) (Ne.symm hz) + change ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2 + nlinarith + +end Family +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Cyclic.lean b/lean/OAI/Probability/ThorpShuffle/Cyclic.lean index 4f00b5398dfca78f739d534016f88fdae81301ad..761c70faaf2c0f68298686bc8749cc39e00654bc 100644 --- a/lean/OAI/Probability/ThorpShuffle/Cyclic.lean +++ b/lean/OAI/Probability/ThorpShuffle/Cyclic.lean @@ -1,246 +1,246 @@ -import OAI.Probability.ThorpShuffle.Parity - -namespace OAI - -universe uG uE uX uH - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Specht - -variable {G : Type uG} [Group G] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - -def cyclic (ρ : Representation ℂ G E) (e : E) : Subrepresentation ρ where - toSubmodule := Submodule.span ℂ (Set.range fun g => ρ g e) - apply_mem_toSubmodule g := by - intro v hv - induction hv using Submodule.span_induction with - | mem v hv => - obtain ⟨h, rfl⟩ := hv - exact Submodule.subset_span ⟨g * h, by simp⟩ - | zero => simp - | add x y hx hy ihx ihy => - simpa using (Submodule.span ℂ (Set.range fun h => ρ h e)).add_mem ihx ihy - | smul a x hx ih => - simpa using (Submodule.span ℂ (Set.range fun h => ρ h e)).smul_mem a ih - -lemma self_mem_cyclic (ρ : Representation ℂ G E) (e : E) : e ∈ cyclic ρ e := by - exact Submodule.subset_span ⟨1, by simp⟩ - -theorem submodule_alternative (ρ : Representation ℂ G E) (e : E) - (hunit : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (K : Module.End ℂ E) (hK : ∀ v, K v = ⟪e, v⟫_ℂ • e) - (hstable : ∀ U : Subrepresentation ρ, ∀ v ∈ U, K v ∈ U) - (U : Subrepresentation ρ) : - cyclic ρ e ≤ U ∨ ∀ u ∈ U, ∀ v ∈ cyclic ρ e, ⟪v, u⟫_ℂ = 0 := by - classical - by_cases he : e ∈ U - · left - exact Submodule.span_le.mpr (by rintro _ ⟨g, rfl⟩; exact U.apply_mem_toSubmodule g he) - · right - intro u hu v hv - have horth (g : G) : ⟪ρ g e, u⟫_ℂ = 0 := by - have hgu : ρ g⁻¹ u ∈ U := U.apply_mem_toSubmodule g⁻¹ hu - have hk := hstable U _ hgu - rw [hK] at hk - have hz : ⟪e, ρ g⁻¹ u⟫_ℂ = 0 := by - by_contra hne - apply he - have hh := U.toSubmodule.smul_mem (⟪e, ρ g⁻¹ u⟫_ℂ)⁻¹ hk - change e ∈ U.toSubmodule - simpa [smul_smul, hne] using hh - have hi := hunit g e (ρ g⁻¹ u) - simpa only [← Module.End.mul_apply, ← map_mul, mul_inv_cancel, map_one, - Module.End.one_apply] using hi.trans hz - induction hv using Submodule.span_induction with - | mem v hv => obtain ⟨g, rfl⟩ := hv; exact horth g - | zero => simp - | add x y hx hy ihx ihy => simp [ihx, ihy] - | smul a x hx ih => simp [ih] - -theorem cyclic_irreducible (ρ : Representation ℂ G E) (e : E) (he : e ≠ 0) - (hunit : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (K : Module.End ℂ E) (hK : ∀ v, K v = ⟪e, v⟫_ℂ • e) - (hstable : ∀ U : Subrepresentation ρ, ∀ v ∈ U, K v ∈ U) : - Representation.IsIrreducible (cyclic ρ e).toRepresentation := by - let S := cyclic ρ e - let eS : S.toSubmodule := ⟨e, self_mem_cyclic ρ e⟩ - have heS : eS ≠ 0 := by intro hh; apply he; exact congrArg Subtype.val hh - have htb : (⊤ : Subrepresentation S.toRepresentation) ≠ ⊥ := by - intro hh - have hel : eS ∈ (⊤ : Subrepresentation S.toRepresentation) := by trivial - rw [hh] at hel - exact heS hel - let : Nontrivial (Subrepresentation S.toRepresentation) := ⟨⟨⊤, ⊥, htb⟩⟩ - refine ⟨fun U => ?_⟩ - let U' : Subrepresentation ρ := { - toSubmodule := U.toSubmodule.map S.toSubmodule.subtype - apply_mem_toSubmodule := by - intro g v hv - obtain ⟨u, hu, rfl⟩ := hv - exact ⟨S.toRepresentation g u, U.apply_mem_toSubmodule g hu, rfl⟩ } - rcases submodule_alternative ρ e hunit K hK hstable U' with h | h - · right - apply top_unique - intro u _ - obtain ⟨v, hv, heq⟩ := h u.property - have hvu : v = u := Subtype.ext heq - exact hvu ▸ hv - · left - apply bot_unique - intro u hu - have hum : (u : E) ∈ U' := ⟨u, hu, rfl⟩ - have hh := h _ hum _ u.property - have hz : (u : E) = 0 := inner_self_eq_zero.mp hh - exact Subtype.ext hz - -namespace PermutationSpace -open scoped Classical - -variable {X : Type uX} [Fintype X] [MulAction G X] - -def rep : Representation ℂ G (EuclideanSpace ℂ X) where - toFun g := { - toFun v := WithLp.toLp 2 (fun x => v (g⁻¹ • x)) - map_add' := by intro v w; rfl - map_smul' := by intro a v; rfl } - map_one' := by ext v x; simp - map_mul' := by - intro g h - ext v x - change v ((g * h)⁻¹ • x) = v (h⁻¹ • g⁻¹ • x) - simp [mul_smul] - -omit [Fintype X] in -@[simp] lemma rep_apply (g : G) (v : EuclideanSpace ℂ X) (x : X) : - rep g v x = v (g⁻¹ • x) := rfl - -lemma rep_unitary (g : G) (v w : EuclideanSpace ℂ X) : - ⟪rep g v, rep g w⟫_ℂ = ⟪v, w⟫_ℂ := by - simp only [PiLp.inner_apply, rep_apply] - exact Equiv.sum_comp (MulAction.toPerm g⁻¹) (fun x => inner ℂ (v x) (w x)) - -omit [Fintype X] in -lemma rep_single (g : G) (x : X) : - rep g (EuclideanSpace.single x (1 : ℂ)) = EuclideanSpace.single (g • x) (1 : ℂ) := by - classical - ext y - simp only [rep_apply, PiLp.single_apply, inv_smul_eq_iff] - -variable {H : Type uH} [Group H] [Fintype H] - -def alternator (ι : H →* G) (χ : H →* ℂ) : Module.End ℂ (EuclideanSpace ℂ X) := - ∑ h, χ h • rep (ι h) - -omit [Fintype X] in -lemma alternator_apply (ι : H →* G) (χ : H →* ℂ) (v : EuclideanSpace ℂ X) : - alternator ι χ v = ∑ h, χ h • rep (ι h) v := by - simp [alternator, LinearMap.sum_apply] - -omit [Fintype X] in -lemma alternator_stable (ι : H →* G) (χ : H →* ℂ) - (U : Subrepresentation (rep : Representation ℂ G (EuclideanSpace ℂ X))) - (v : EuclideanSpace ℂ X) (hv : v ∈ U) : alternator ι χ v ∈ U := by - rw [alternator_apply] - exact U.toSubmodule.sum_mem fun h _ => U.toSubmodule.smul_mem _ (U.apply_mem_toSubmodule _ hv) - -omit [Fintype X] in -lemma alternator_translate (ι : H →* G) (χ : H →* ℂ) (a : H) - (v : EuclideanSpace ℂ X) : - alternator ι χ (rep (ι a) v) = χ a⁻¹ • alternator ι χ v := by - rw [alternator_apply, alternator_apply, Finset.smul_sum] - have he := Equiv.sum_comp (Equiv.mulRight a) - (fun h => χ a⁻¹ • (χ h • (rep (ι h) v : EuclideanSpace ℂ X))) - rw [← he] - apply Finset.sum_congr rfl - intro h _ - simp only [Equiv.coe_mulRight, smul_smul, map_mul] - rw [show χ a⁻¹ * (χ h * χ a) = χ h by - calc - _ = χ h * (χ a⁻¹ * χ a) := by ring - _ = χ h := by rw [← map_mul, inv_mul_cancel, map_one, mul_one]] - simp only [Module.End.mul_apply] - -omit [Fintype X] in -lemma alternator_single_zero (ι : H →* G) (χ : H →* ℂ) - (x : X) (a : H) (ha : ι a • x = x) (hs : χ a = -1) : - alternator ι χ (EuclideanSpace.single x (1 : ℂ)) = 0 := by - have hh := alternator_translate ι χ a (EuclideanSpace.single x (1 : ℂ)) - rw [rep_single, ha, map_inv, hs, inv_neg, inv_one, neg_smul, one_smul] at hh - have hz := congrArg (fun z => z + alternator ι χ (EuclideanSpace.single x (1 : ℂ))) hh - have ht : (2 : ℂ) • alternator ι χ (EuclideanSpace.single x (1 : ℂ)) = 0 := by - simpa [two_smul] using hz - exact (smul_eq_zero.mp ht).resolve_left (by norm_num) - -omit [Fintype X] in -lemma alternator_coeff (ι : H →* G) (χ : H →* ℂ) (v : EuclideanSpace ℂ X) (x : X) : - alternator ι χ v x = ∑ h, χ h * v ((ι h)⁻¹ • x) := by - simp [alternator_apply, WithLp.ofLp_sum, Finset.sum_apply] - -omit [Fintype X] in -lemma polytabloid_base (ι : H →* G) (χ : H →* ℂ) (b : X) - (hfree : ∀ h : H, ι h • b = b → h = 1) : - alternator ι χ (EuclideanSpace.single b (1 : ℂ)) b = 1 := by - classical - rw [alternator_coeff, Finset.sum_eq_single 1] - · simp - · intro h _ hh - have hn : (ι h)⁻¹ • b ≠ b := by - intro he - have hi : h⁻¹ = 1 := hfree h⁻¹ (by simpa using he) - exact hh (inv_eq_one.mp hi) - simp [hn] - · simp - -lemma polytabloid_inner (ι : H →* G) (χ : H →* ℂ) (b : X) - (hreal : ∀ h, conj (χ h) = χ h) (hinv : ∀ h, χ h⁻¹ = χ h) - (v : EuclideanSpace ℂ X) : - ⟪alternator ι χ (EuclideanSpace.single b (1 : ℂ)), v⟫_ℂ = alternator ι χ v b := by - classical - rw [alternator_apply, sum_inner, alternator_coeff] - simp only [inner_smul_left, rep_single, EuclideanSpace.inner_single_left, map_one, - one_mul, hreal] - have hh := Equiv.sum_comp (Equiv.inv H) (fun h => χ h * v ((ι h)⁻¹ • b)) - simpa only [Equiv.inv_apply, map_inv, inv_inv, hinv] using hh - -theorem alternator_rank_one (ι : H →* G) (χ : H →* ℂ) (b : X) - (hreal : ∀ h, conj (χ h) = χ h) (hinv : ∀ h, χ h⁻¹ = χ h) - (hfree : ∀ h : H, ι h • b = b → h = 1) - (halt : ∀ x : X, (∃ a : H, ι a • x = x ∧ χ a = -1) ∨ - ∃ a : H, x = ι a • b) (v : EuclideanSpace ℂ X) : - alternator ι χ v = - ⟪alternator ι χ (EuclideanSpace.single b (1 : ℂ)), v⟫_ℂ • - alternator ι χ (EuclideanSpace.single b (1 : ℂ)) := by - classical - let e := alternator ι χ (EuclideanSpace.single b (1 : ℂ)) - have hs (x : X) : alternator ι χ (EuclideanSpace.single x (1 : ℂ)) ∈ Submodule.span ℂ {e} := by - rcases halt x with ⟨a, ha, hχ⟩ | ⟨a, rfl⟩ - · rw [alternator_single_zero ι χ x a ha hχ] - exact Submodule.zero_mem _ - · rw [← rep_single, alternator_translate] - exact Submodule.smul_mem _ _ (Submodule.subset_span (Set.mem_singleton e)) - have hv : alternator ι χ v ∈ Submodule.span ℂ {e} := by - have hexp := (EuclideanSpace.basisFun X ℂ).sum_repr v - simp only [EuclideanSpace.basisFun_repr, EuclideanSpace.basisFun_apply] at hexp - rw [← hexp, map_sum] - exact Submodule.sum_mem _ fun x _ => by - rw [map_smul] - exact Submodule.smul_mem _ _ (hs x) - obtain ⟨a, ha⟩ := Submodule.mem_span_singleton.mp hv - have heb : e b = 1 := polytabloid_base ι χ b hfree - have hab : a = alternator ι χ v b := by - have hh := congrArg (fun z : EuclideanSpace ℂ X => z b) ha - simpa only [PiLp.smul_apply, smul_eq_mul, heb, mul_one] using hh - rw [← ha, hab, polytabloid_inner ι χ b hreal hinv] - -end PermutationSpace - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.Parity + +namespace OAI + +universe uG uE uX uH + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Specht + +variable {G : Type uG} [Group G] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def cyclic (ρ : Representation ℂ G E) (e : E) : Subrepresentation ρ where + toSubmodule := Submodule.span ℂ (Set.range fun g => ρ g e) + apply_mem_toSubmodule g := by + intro v hv + induction hv using Submodule.span_induction with + | mem v hv => + obtain ⟨h, rfl⟩ := hv + exact Submodule.subset_span ⟨g * h, by simp⟩ + | zero => simp + | add x y hx hy ihx ihy => + simpa using (Submodule.span ℂ (Set.range fun h => ρ h e)).add_mem ihx ihy + | smul a x hx ih => + simpa using (Submodule.span ℂ (Set.range fun h => ρ h e)).smul_mem a ih + +lemma self_mem_cyclic (ρ : Representation ℂ G E) (e : E) : e ∈ cyclic ρ e := by + exact Submodule.subset_span ⟨1, by simp⟩ + +theorem submodule_alternative (ρ : Representation ℂ G E) (e : E) + (hunit : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (K : Module.End ℂ E) (hK : ∀ v, K v = ⟪e, v⟫_ℂ • e) + (hstable : ∀ U : Subrepresentation ρ, ∀ v ∈ U, K v ∈ U) + (U : Subrepresentation ρ) : + cyclic ρ e ≤ U ∨ ∀ u ∈ U, ∀ v ∈ cyclic ρ e, ⟪v, u⟫_ℂ = 0 := by + classical + by_cases he : e ∈ U + · left + exact Submodule.span_le.mpr (by rintro _ ⟨g, rfl⟩; exact U.apply_mem_toSubmodule g he) + · right + intro u hu v hv + have horth (g : G) : ⟪ρ g e, u⟫_ℂ = 0 := by + have hgu : ρ g⁻¹ u ∈ U := U.apply_mem_toSubmodule g⁻¹ hu + have hk := hstable U _ hgu + rw [hK] at hk + have hz : ⟪e, ρ g⁻¹ u⟫_ℂ = 0 := by + by_contra hne + apply he + have hh := U.toSubmodule.smul_mem (⟪e, ρ g⁻¹ u⟫_ℂ)⁻¹ hk + change e ∈ U.toSubmodule + simpa [smul_smul, hne] using hh + have hi := hunit g e (ρ g⁻¹ u) + simpa only [← Module.End.mul_apply, ← map_mul, mul_inv_cancel, map_one, + Module.End.one_apply] using hi.trans hz + induction hv using Submodule.span_induction with + | mem v hv => obtain ⟨g, rfl⟩ := hv; exact horth g + | zero => simp + | add x y hx hy ihx ihy => simp [ihx, ihy] + | smul a x hx ih => simp [ih] + +theorem cyclic_irreducible (ρ : Representation ℂ G E) (e : E) (he : e ≠ 0) + (hunit : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (K : Module.End ℂ E) (hK : ∀ v, K v = ⟪e, v⟫_ℂ • e) + (hstable : ∀ U : Subrepresentation ρ, ∀ v ∈ U, K v ∈ U) : + Representation.IsIrreducible (cyclic ρ e).toRepresentation := by + let S := cyclic ρ e + let eS : S.toSubmodule := ⟨e, self_mem_cyclic ρ e⟩ + have heS : eS ≠ 0 := by intro hh; apply he; exact congrArg Subtype.val hh + have htb : (⊤ : Subrepresentation S.toRepresentation) ≠ ⊥ := by + intro hh + have hel : eS ∈ (⊤ : Subrepresentation S.toRepresentation) := by trivial + rw [hh] at hel + exact heS hel + let : Nontrivial (Subrepresentation S.toRepresentation) := ⟨⟨⊤, ⊥, htb⟩⟩ + refine ⟨fun U => ?_⟩ + let U' : Subrepresentation ρ := { + toSubmodule := U.toSubmodule.map S.toSubmodule.subtype + apply_mem_toSubmodule := by + intro g v hv + obtain ⟨u, hu, rfl⟩ := hv + exact ⟨S.toRepresentation g u, U.apply_mem_toSubmodule g hu, rfl⟩ } + rcases submodule_alternative ρ e hunit K hK hstable U' with h | h + · right + apply top_unique + intro u _ + obtain ⟨v, hv, heq⟩ := h u.property + have hvu : v = u := Subtype.ext heq + exact hvu ▸ hv + · left + apply bot_unique + intro u hu + have hum : (u : E) ∈ U' := ⟨u, hu, rfl⟩ + have hh := h _ hum _ u.property + have hz : (u : E) = 0 := inner_self_eq_zero.mp hh + exact Subtype.ext hz + +namespace PermutationSpace +open scoped Classical + +variable {X : Type uX} [Fintype X] [MulAction G X] + +def rep : Representation ℂ G (EuclideanSpace ℂ X) where + toFun g := { + toFun v := WithLp.toLp 2 (fun x => v (g⁻¹ • x)) + map_add' := by intro v w; rfl + map_smul' := by intro a v; rfl } + map_one' := by ext v x; simp + map_mul' := by + intro g h + ext v x + change v ((g * h)⁻¹ • x) = v (h⁻¹ • g⁻¹ • x) + simp [mul_smul] + +omit [Fintype X] in +@[simp] lemma rep_apply (g : G) (v : EuclideanSpace ℂ X) (x : X) : + rep g v x = v (g⁻¹ • x) := rfl + +lemma rep_unitary (g : G) (v w : EuclideanSpace ℂ X) : + ⟪rep g v, rep g w⟫_ℂ = ⟪v, w⟫_ℂ := by + simp only [PiLp.inner_apply, rep_apply] + exact Equiv.sum_comp (MulAction.toPerm g⁻¹) (fun x => inner ℂ (v x) (w x)) + +omit [Fintype X] in +lemma rep_single (g : G) (x : X) : + rep g (EuclideanSpace.single x (1 : ℂ)) = EuclideanSpace.single (g • x) (1 : ℂ) := by + classical + ext y + simp only [rep_apply, PiLp.single_apply, inv_smul_eq_iff] + +variable {H : Type uH} [Group H] [Fintype H] + +def alternator (ι : H →* G) (χ : H →* ℂ) : Module.End ℂ (EuclideanSpace ℂ X) := + ∑ h, χ h • rep (ι h) + +omit [Fintype X] in +lemma alternator_apply (ι : H →* G) (χ : H →* ℂ) (v : EuclideanSpace ℂ X) : + alternator ι χ v = ∑ h, χ h • rep (ι h) v := by + simp [alternator, LinearMap.sum_apply] + +omit [Fintype X] in +lemma alternator_stable (ι : H →* G) (χ : H →* ℂ) + (U : Subrepresentation (rep : Representation ℂ G (EuclideanSpace ℂ X))) + (v : EuclideanSpace ℂ X) (hv : v ∈ U) : alternator ι χ v ∈ U := by + rw [alternator_apply] + exact U.toSubmodule.sum_mem fun h _ => U.toSubmodule.smul_mem _ (U.apply_mem_toSubmodule _ hv) + +omit [Fintype X] in +lemma alternator_translate (ι : H →* G) (χ : H →* ℂ) (a : H) + (v : EuclideanSpace ℂ X) : + alternator ι χ (rep (ι a) v) = χ a⁻¹ • alternator ι χ v := by + rw [alternator_apply, alternator_apply, Finset.smul_sum] + have he := Equiv.sum_comp (Equiv.mulRight a) + (fun h => χ a⁻¹ • (χ h • (rep (ι h) v : EuclideanSpace ℂ X))) + rw [← he] + apply Finset.sum_congr rfl + intro h _ + simp only [Equiv.coe_mulRight, smul_smul, map_mul] + rw [show χ a⁻¹ * (χ h * χ a) = χ h by + calc + _ = χ h * (χ a⁻¹ * χ a) := by ring + _ = χ h := by rw [← map_mul, inv_mul_cancel, map_one, mul_one]] + simp only [Module.End.mul_apply] + +omit [Fintype X] in +lemma alternator_single_zero (ι : H →* G) (χ : H →* ℂ) + (x : X) (a : H) (ha : ι a • x = x) (hs : χ a = -1) : + alternator ι χ (EuclideanSpace.single x (1 : ℂ)) = 0 := by + have hh := alternator_translate ι χ a (EuclideanSpace.single x (1 : ℂ)) + rw [rep_single, ha, map_inv, hs, inv_neg, inv_one, neg_smul, one_smul] at hh + have hz := congrArg (fun z => z + alternator ι χ (EuclideanSpace.single x (1 : ℂ))) hh + have ht : (2 : ℂ) • alternator ι χ (EuclideanSpace.single x (1 : ℂ)) = 0 := by + simpa [two_smul] using hz + exact (smul_eq_zero.mp ht).resolve_left (by norm_num) + +omit [Fintype X] in +lemma alternator_coeff (ι : H →* G) (χ : H →* ℂ) (v : EuclideanSpace ℂ X) (x : X) : + alternator ι χ v x = ∑ h, χ h * v ((ι h)⁻¹ • x) := by + simp [alternator_apply, WithLp.ofLp_sum, Finset.sum_apply] + +omit [Fintype X] in +lemma polytabloid_base (ι : H →* G) (χ : H →* ℂ) (b : X) + (hfree : ∀ h : H, ι h • b = b → h = 1) : + alternator ι χ (EuclideanSpace.single b (1 : ℂ)) b = 1 := by + classical + rw [alternator_coeff, Finset.sum_eq_single 1] + · simp + · intro h _ hh + have hn : (ι h)⁻¹ • b ≠ b := by + intro he + have hi : h⁻¹ = 1 := hfree h⁻¹ (by simpa using he) + exact hh (inv_eq_one.mp hi) + simp [hn] + · simp + +lemma polytabloid_inner (ι : H →* G) (χ : H →* ℂ) (b : X) + (hreal : ∀ h, conj (χ h) = χ h) (hinv : ∀ h, χ h⁻¹ = χ h) + (v : EuclideanSpace ℂ X) : + ⟪alternator ι χ (EuclideanSpace.single b (1 : ℂ)), v⟫_ℂ = alternator ι χ v b := by + classical + rw [alternator_apply, sum_inner, alternator_coeff] + simp only [inner_smul_left, rep_single, EuclideanSpace.inner_single_left, map_one, + one_mul, hreal] + have hh := Equiv.sum_comp (Equiv.inv H) (fun h => χ h * v ((ι h)⁻¹ • b)) + simpa only [Equiv.inv_apply, map_inv, inv_inv, hinv] using hh + +theorem alternator_rank_one (ι : H →* G) (χ : H →* ℂ) (b : X) + (hreal : ∀ h, conj (χ h) = χ h) (hinv : ∀ h, χ h⁻¹ = χ h) + (hfree : ∀ h : H, ι h • b = b → h = 1) + (halt : ∀ x : X, (∃ a : H, ι a • x = x ∧ χ a = -1) ∨ + ∃ a : H, x = ι a • b) (v : EuclideanSpace ℂ X) : + alternator ι χ v = + ⟪alternator ι χ (EuclideanSpace.single b (1 : ℂ)), v⟫_ℂ • + alternator ι χ (EuclideanSpace.single b (1 : ℂ)) := by + classical + let e := alternator ι χ (EuclideanSpace.single b (1 : ℂ)) + have hs (x : X) : alternator ι χ (EuclideanSpace.single x (1 : ℂ)) ∈ Submodule.span ℂ {e} := by + rcases halt x with ⟨a, ha, hχ⟩ | ⟨a, rfl⟩ + · rw [alternator_single_zero ι χ x a ha hχ] + exact Submodule.zero_mem _ + · rw [← rep_single, alternator_translate] + exact Submodule.smul_mem _ _ (Submodule.subset_span (Set.mem_singleton e)) + have hv : alternator ι χ v ∈ Submodule.span ℂ {e} := by + have hexp := (EuclideanSpace.basisFun X ℂ).sum_repr v + simp only [EuclideanSpace.basisFun_repr, EuclideanSpace.basisFun_apply] at hexp + rw [← hexp, map_sum] + exact Submodule.sum_mem _ fun x _ => by + rw [map_smul] + exact Submodule.smul_mem _ _ (hs x) + obtain ⟨a, ha⟩ := Submodule.mem_span_singleton.mp hv + have heb : e b = 1 := polytabloid_base ι χ b hfree + have hab : a = alternator ι χ v b := by + have hh := congrArg (fun z : EuclideanSpace ℂ X => z b) ha + simpa only [PiLp.smul_apply, smul_eq_mul, heb, mul_one] using hh + rw [← ha, hab, polytabloid_inner ι χ b hreal hinv] + +end PermutationSpace + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/DegreeBounds.lean b/lean/OAI/Probability/ThorpShuffle/DegreeBounds.lean index 93051a355f6644d559e0d85613ee2f27acdad7c5..6b778df155333be7a9e63a0e45c7737e51be5a59 100644 --- a/lean/OAI/Probability/ThorpShuffle/DegreeBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/DegreeBounds.lean @@ -1,238 +1,238 @@ -import OAI.Probability.ThorpShuffle.PartitionBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical - -def rowTail (D : YoungDiagram) : YoungDiagram where - cells := (D.cells.filter (fun p => p.1 ≠ 0)).image (fun p => (p.1 - 1, p.2)) - isLowerSet := by - intro y x hxy hy - obtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hy - obtain ⟨hpD, hp0⟩ := Finset.mem_filter.mp hp - apply Finset.mem_image.mpr - refine ⟨(x.1 + 1, x.2), Finset.mem_filter.mpr ⟨?_, by omega⟩, ?_⟩ - · exact D.up_left_mem (by have := hxy.1; omega) hxy.2 hpD - · simp - -lemma mem_rowTail (D : YoungDiagram) (i j : ℕ) : (i, j) ∈ rowTail D ↔ (i + 1, j) ∈ D := by - change (i, j) ∈ (D.cells.filter (fun p => p.1 ≠ 0)).image (fun p => (p.1 - 1, p.2)) ↔ _ - constructor - · intro h - obtain ⟨p, hp, he⟩ := Finset.mem_image.mp h - obtain ⟨hpD, hp0⟩ := Finset.mem_filter.mp hp - have h₁ := congrArg Prod.fst he - have h₂ := congrArg Prod.snd he - have hp : p = (i + 1, j) := Prod.ext (by dsimp at h₁; omega) h₂ - simpa only [← hp, YoungDiagram.mem_cells] using hpD - · intro h - exact Finset.mem_image.mpr ⟨(i + 1, j), Finset.mem_filter.mpr ⟨h, by omega⟩, by simp⟩ - -def rowTailCells (D : YoungDiagram) : Cells (rowTail D) ≃ Lower D where - toFun x := ⟨⟨(x.val.1 + 1, x.val.2), (mem_rowTail D _ _).mp x.property⟩, by simp⟩ - invFun x := ⟨(x.val.val.1 - 1, x.val.val.2), (mem_rowTail D _ _).mpr (by - have h : x.val.val.1 - 1 + 1 = x.val.val.1 := by have := x.property; omega - simpa only [h, YoungDiagram.mem_cells, Prod.mk.eta] using x.val.property)⟩ - left_inv x := by apply Subtype.ext; simp - right_inv x := by - apply Subtype.ext; apply Subtype.ext - exact Prod.ext (by have := x.property; dsimp; omega) rfl - -lemma rowTail_ext {D E : YoungDiagram} (hrow : D.rowLen 0 = E.rowLen 0) (ht : rowTail D = rowTail E) : D = E := by - apply YoungDiagram.ext - ext p - rcases p with ⟨i, j⟩ - cases i with - | zero => simp only [YoungDiagram.mem_cells, YoungDiagram.mem_iff_lt_rowLen, hrow] - | succ i => simp only [YoungDiagram.mem_cells, ← mem_rowTail, ht] - -def orient (D : YoungDiagram) : YoungDiagram := - if D.colLen 0 ≤ D.rowLen 0 then D else D.transpose - -def orientation (D : YoungDiagram) : Bool := decide (D.colLen 0 ≤ D.rowLen 0) - -lemma orient_rowLen (D : YoungDiagram) : (orient D).rowLen 0 = longest D := by - unfold orient longest - split_ifs with h - · exact (max_eq_left h).symm - · rw [YoungDiagram.rowLen_transpose, max_eq_right (by omega)] - -lemma orient_card (D : YoungDiagram) : Fintype.card (Cells (orient D)) = Fintype.card (Cells D) := by - unfold orient - split_ifs - · rfl - · exact (Fintype.card_congr (transposeCells D).toEquiv).symm - -lemma orient_extensions (D : YoungDiagram) : - Fintype.card (Extensions (Cells (orient D))) = Fintype.card (Extensions (Cells D)) := by - by_cases h : D.colLen 0 ≤ D.rowLen 0 - · exact congrArg (fun E : YoungDiagram => Fintype.card (Extensions (Cells E))) (show orient D = D by simp [orient, h]) - · exact (congrArg (fun E : YoungDiagram => Fintype.card (Extensions (Cells E))) - (show orient D = D.transpose by simp [orient, h])).trans - (extensions_card_orderIso (transposeCells D)).symm - -lemma recover_orientation (D : YoungDiagram) : - (if orientation D then orient D else (orient D).transpose) = D := by - unfold orientation orient - split_ifs <;> simp_all - -lemma longest_le_card (D : YoungDiagram) : longest D ≤ Fintype.card (Cells D) := - max_le (rowLen_le_card D 0) (colLen_le_card D 0) - -theorem defect_count_le (n u : ℕ) : - Fintype.card {p : Nat.Partition n // n - longest (ofPartition p) = u} ≤ - 2 * Fintype.card (Nat.Partition u) := by - let T := {p : Nat.Partition n // n - longest (ofPartition p) = u} - have hcard (p : T) : Fintype.card (Cells (rowTail (orient (ofPartition p.val)))) = u := by - rw [Fintype.card_congr (rowTailCells _)] - have hh := card_lower_add (orient (ofPartition p.val)) - rw [orient_rowLen, orient_card, card_ofPartition] at hh - have hp := p.property - omega - let f (p : T) : Bool × Nat.Partition u := - (orientation (ofPartition p.val), toPartition (rowTail (orient (ofPartition p.val))) u (hcard p)) - have hf : Function.Injective f := by - intro p q hpq - apply Subtype.ext - apply ofPartition_injective - have hflag : orientation (ofPartition p.val) = orientation (ofPartition q.val) := congrArg Prod.fst hpq - have ht : rowTail (orient (ofPartition p.val)) = rowTail (orient (ofPartition q.val)) := by - have he := congrArg (fun z : Bool × Nat.Partition u => ofPartition z.2) hpq - simpa only [f, of_toPartition] using he - have hr : (orient (ofPartition p.val)).rowLen 0 = (orient (ofPartition q.val)).rowLen 0 := by - simp only [orient_rowLen] - have hp := p.property - have hq := q.property - have hp' := longest_le_card (ofPartition p.val) - have hq' := longest_le_card (ofPartition q.val) - rw [card_ofPartition] at hp' hq' - omega - have ho := rowTail_ext hr ht - rw [← recover_orientation (ofPartition p.val), ← recover_orientation (ofPartition q.val), hflag, ho] - have hh := Fintype.card_le_of_injective f hf - simpa only [Fintype.card_prod, Fintype.card_bool] using hh - -end Thorp.Young - -namespace Thorp.Specht -open scoped Classical -open Thorp.Young - -abbrev NShape (n : ℕ) := Shape (Fin n) - -def defect {n : ℕ} (p : NShape n) : ℕ := n - longest (ofPartition p) - -lemma diagram_card {n : ℕ} (p : NShape n) : Fintype.card (Cells (ofPartition p)) = n := by - simpa only [Fintype.card_fin] using card_ofPartition p - -lemma extensions_le_degree {n : ℕ} (p : NShape n) : - Fintype.card (Extensions (Cells (ofPartition p))) ≤ degree p := - extensions_card_le_degree (ofPartition p) (canonicalTableau p) - -lemma degree_pos {n : ℕ} (p : NShape n) : 0 < degree p := by - let := extensions_nonempty (Cells (ofPartition p)) - exact (Fintype.card_pos).trans_le (extensions_le_degree p) - -lemma defect_add_longest {n : ℕ} (p : NShape n) : defect p + longest (ofPartition p) = n := by - have h := longest_le_card (ofPartition p) - rw [diagram_card] at h - exact Nat.sub_add_cancel h - -lemma choose_longest_le_degree {n : ℕ} (p : NShape n) (k : ℕ) - (hk : k ≤ defect p) (hL : k ≤ longest (ofPartition p)) : - (longest (ofPartition p)).choose k ≤ degree p := by - have hc : Fintype.card (Lower (orient (ofPartition p))) = defect p := by - have hh := card_lower_add (orient (ofPartition p)) - rw [orient_rowLen, orient_card, diagram_card] at hh - have hd := defect_add_longest p - omega - have hh := choose_le_extensions (orient (ofPartition p)) k (by rwa [hc]) (by rwa [orient_rowLen]) - rw [orient_rowLen, orient_extensions] at hh - exact hh.trans (extensions_le_degree p) - -lemma small_defect_degree {n : ℕ} (p : NShape n) (h : 4 * defect p ≤ n) : - 3 ^ defect p ≤ degree p := by - have hd := defect_add_longest p - exact (pow_le_choose_of_mul_le 3 _ _ (by omega)).trans - (choose_longest_le_degree p _ le_rfl (by omega)) - -lemma fixed_defect_degree {n : ℕ} (p : NShape n) (hp : 0 < defect p) (h : 2 * defect p ≤ n) : - n - 2 * defect p + 1 ≤ degree p := by - have hd := defect_add_longest p - have hh := sub_add_one_le_choose (longest (ofPartition p)) (defect p) hp (by omega) - have he : longest (ofPartition p) - defect p = n - 2 * defect p := by omega - rw [he] at hh - exact hh.trans (choose_longest_le_degree p _ le_rfl (by omega)) - -lemma factorial_third_bound (n : ℕ) : ((n : ℝ) / 3) ^ n ≤ (n.factorial : ℝ) := by - rcases n with _ | n - · norm_num - have hn : (1 : ℝ) ≤ n + 1 := by have := Nat.cast_nonneg (α := ℝ) n; linarith - have hs : (1 : ℝ) ≤ Real.sqrt (2 * Real.pi * (n + 1)) := by - apply Real.le_sqrt_of_sq_le - nlinarith [Real.pi_gt_three] - have he : (n + 1 : ℝ) / 3 ≤ (n + 1) / Real.exp 1 := by - apply div_le_div_of_nonneg_left (by positivity) (Real.exp_pos 1) Real.exp_one_lt_three.le - have hh := Stirling.le_factorial_stirling (n + 1) - push_cast at hh - simpa only [Nat.cast_add, Nat.cast_one] using (pow_le_pow_left₀ (by positivity) he (n+1)).trans - ((le_mul_of_one_le_left (by positivity) hs).trans hh) - -lemma small_longest_degree {n : ℕ} (p : NShape n) (hn : 0 < n) - (hL : 8 * longest (ofPartition p) ≤ n) : - (4 / 3 : ℝ) ^ n ≤ degree p := by - have hf := factorial_le_rank_degree (ofPartition p) (canonicalTableau p) - have hf' : (n.factorial : ℝ) ≤ (2 * (longest (ofPartition p) : ℝ)) ^ n * (degree p : ℝ) := by - exact_mod_cast hf - have he : (2 * (longest (ofPartition p) : ℝ)) ≤ (n : ℝ) / 4 := by - have hh : (8 : ℝ) * longest (ofPartition p) ≤ n := by exact_mod_cast hL - linarith - have hd : (0 : ℝ) ≤ degree p := Nat.cast_nonneg _ - have hh := (factorial_third_bound n).trans (hf'.trans (mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by positivity) he n) hd)) - have hn' : (0 : ℝ) < n := by exact_mod_cast hn - have hid : ((n : ℝ) / 3) ^ n = ((n : ℝ) / 4) ^ n * (4 / 3 : ℝ)^n := by rw [← mul_pow]; congr 1; ring - rw [hid] at hh - exact le_of_mul_le_mul_left hh (pow_pos (by positivity : (0 : ℝ) < n / 4) n) - -lemma bulk_degree {n : ℕ} (p : NShape n) (hn : 0 < n) (hu : n < 4 * defect p) : - (2 : ℝ) ^ (n / 16) ≤ degree p := by - by_cases hL : 8 * longest (ofPartition p) ≤ n - · have hh : (2 : ℝ) ^ (n / 16) ≤ (4 / 3 : ℝ)^n := by - have hbase : (2 : ℝ) ≤ (4 / 3 : ℝ)^16 := by norm_num - calc - _ ≤ ((4 / 3 : ℝ)^16)^(n/16) := pow_le_pow_left₀ (by norm_num) hbase _ - _ = (4 / 3 : ℝ)^(16 * (n/16)) := by rw [pow_mul] - _ ≤ _ := pow_le_pow_right₀ (by norm_num) (by omega) - exact hh.trans (small_longest_degree p hn hL) - · have hd := defect_add_longest p - have hk : n / 16 ≤ defect p := by omega - have hm : 2 * (n / 16) ≤ longest (ofPartition p) := by omega - exact_mod_cast (pow_le_choose_of_mul_le 2 _ _ hm).trans - (choose_longest_le_degree p _ hk (by omega)) - -lemma defect_card_bound (n u : ℕ) : - Fintype.card {p : NShape n // defect p = u} ≤ 2 ^ (u + 1) := by - have hh : Nat.card {p : Nat.Partition n // n - longest (ofPartition p) = u} ≤ 2 ^ (u+1) := by - rw [← Fintype.card_eq_nat_card] - calc - _ ≤ 2 * Fintype.card (Nat.Partition u) := defect_count_le n u - _ ≤ 2 * 2^u := Nat.mul_le_mul_left 2 (partition_count_le_pow u) - _ = _ := by ring - rw [Fintype.card_eq_nat_card] - change Nat.card {p : Nat.Partition (Fintype.card (Fin n)) // n - longest (ofPartition p) = u} ≤ _ - have he (m k : ℕ) (h : m = k) : - Nat.card {p : Nat.Partition m // n - longest (ofPartition p) = u} = - Nat.card {p : Nat.Partition k // n - longest (ofPartition p) = u} := by subst k; rfl - exact (he _ _ (Fintype.card_fin n)).trans_le hh - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.PartitionBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical + +def rowTail (D : YoungDiagram) : YoungDiagram where + cells := (D.cells.filter (fun p => p.1 ≠ 0)).image (fun p => (p.1 - 1, p.2)) + isLowerSet := by + intro y x hxy hy + obtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hy + obtain ⟨hpD, hp0⟩ := Finset.mem_filter.mp hp + apply Finset.mem_image.mpr + refine ⟨(x.1 + 1, x.2), Finset.mem_filter.mpr ⟨?_, by omega⟩, ?_⟩ + · exact D.up_left_mem (by have := hxy.1; omega) hxy.2 hpD + · simp + +lemma mem_rowTail (D : YoungDiagram) (i j : ℕ) : (i, j) ∈ rowTail D ↔ (i + 1, j) ∈ D := by + change (i, j) ∈ (D.cells.filter (fun p => p.1 ≠ 0)).image (fun p => (p.1 - 1, p.2)) ↔ _ + constructor + · intro h + obtain ⟨p, hp, he⟩ := Finset.mem_image.mp h + obtain ⟨hpD, hp0⟩ := Finset.mem_filter.mp hp + have h₁ := congrArg Prod.fst he + have h₂ := congrArg Prod.snd he + have hp : p = (i + 1, j) := Prod.ext (by dsimp at h₁; omega) h₂ + simpa only [← hp, YoungDiagram.mem_cells] using hpD + · intro h + exact Finset.mem_image.mpr ⟨(i + 1, j), Finset.mem_filter.mpr ⟨h, by omega⟩, by simp⟩ + +def rowTailCells (D : YoungDiagram) : Cells (rowTail D) ≃ Lower D where + toFun x := ⟨⟨(x.val.1 + 1, x.val.2), (mem_rowTail D _ _).mp x.property⟩, by simp⟩ + invFun x := ⟨(x.val.val.1 - 1, x.val.val.2), (mem_rowTail D _ _).mpr (by + have h : x.val.val.1 - 1 + 1 = x.val.val.1 := by have := x.property; omega + simpa only [h, YoungDiagram.mem_cells, Prod.mk.eta] using x.val.property)⟩ + left_inv x := by apply Subtype.ext; simp + right_inv x := by + apply Subtype.ext; apply Subtype.ext + exact Prod.ext (by have := x.property; dsimp; omega) rfl + +lemma rowTail_ext {D E : YoungDiagram} (hrow : D.rowLen 0 = E.rowLen 0) (ht : rowTail D = rowTail E) : D = E := by + apply YoungDiagram.ext + ext p + rcases p with ⟨i, j⟩ + cases i with + | zero => simp only [YoungDiagram.mem_cells, YoungDiagram.mem_iff_lt_rowLen, hrow] + | succ i => simp only [YoungDiagram.mem_cells, ← mem_rowTail, ht] + +def orient (D : YoungDiagram) : YoungDiagram := + if D.colLen 0 ≤ D.rowLen 0 then D else D.transpose + +def orientation (D : YoungDiagram) : Bool := decide (D.colLen 0 ≤ D.rowLen 0) + +lemma orient_rowLen (D : YoungDiagram) : (orient D).rowLen 0 = longest D := by + unfold orient longest + split_ifs with h + · exact (max_eq_left h).symm + · rw [YoungDiagram.rowLen_transpose, max_eq_right (by omega)] + +lemma orient_card (D : YoungDiagram) : Fintype.card (Cells (orient D)) = Fintype.card (Cells D) := by + unfold orient + split_ifs + · rfl + · exact (Fintype.card_congr (transposeCells D).toEquiv).symm + +lemma orient_extensions (D : YoungDiagram) : + Fintype.card (Extensions (Cells (orient D))) = Fintype.card (Extensions (Cells D)) := by + by_cases h : D.colLen 0 ≤ D.rowLen 0 + · exact congrArg (fun E : YoungDiagram => Fintype.card (Extensions (Cells E))) (show orient D = D by simp [orient, h]) + · exact (congrArg (fun E : YoungDiagram => Fintype.card (Extensions (Cells E))) + (show orient D = D.transpose by simp [orient, h])).trans + (extensions_card_orderIso (transposeCells D)).symm + +lemma recover_orientation (D : YoungDiagram) : + (if orientation D then orient D else (orient D).transpose) = D := by + unfold orientation orient + split_ifs <;> simp_all + +lemma longest_le_card (D : YoungDiagram) : longest D ≤ Fintype.card (Cells D) := + max_le (rowLen_le_card D 0) (colLen_le_card D 0) + +theorem defect_count_le (n u : ℕ) : + Fintype.card {p : Nat.Partition n // n - longest (ofPartition p) = u} ≤ + 2 * Fintype.card (Nat.Partition u) := by + let T := {p : Nat.Partition n // n - longest (ofPartition p) = u} + have hcard (p : T) : Fintype.card (Cells (rowTail (orient (ofPartition p.val)))) = u := by + rw [Fintype.card_congr (rowTailCells _)] + have hh := card_lower_add (orient (ofPartition p.val)) + rw [orient_rowLen, orient_card, card_ofPartition] at hh + have hp := p.property + omega + let f (p : T) : Bool × Nat.Partition u := + (orientation (ofPartition p.val), toPartition (rowTail (orient (ofPartition p.val))) u (hcard p)) + have hf : Function.Injective f := by + intro p q hpq + apply Subtype.ext + apply ofPartition_injective + have hflag : orientation (ofPartition p.val) = orientation (ofPartition q.val) := congrArg Prod.fst hpq + have ht : rowTail (orient (ofPartition p.val)) = rowTail (orient (ofPartition q.val)) := by + have he := congrArg (fun z : Bool × Nat.Partition u => ofPartition z.2) hpq + simpa only [f, of_toPartition] using he + have hr : (orient (ofPartition p.val)).rowLen 0 = (orient (ofPartition q.val)).rowLen 0 := by + simp only [orient_rowLen] + have hp := p.property + have hq := q.property + have hp' := longest_le_card (ofPartition p.val) + have hq' := longest_le_card (ofPartition q.val) + rw [card_ofPartition] at hp' hq' + omega + have ho := rowTail_ext hr ht + rw [← recover_orientation (ofPartition p.val), ← recover_orientation (ofPartition q.val), hflag, ho] + have hh := Fintype.card_le_of_injective f hf + simpa only [Fintype.card_prod, Fintype.card_bool] using hh + +end Thorp.Young + +namespace Thorp.Specht +open scoped Classical +open Thorp.Young + +abbrev NShape (n : ℕ) := Shape (Fin n) + +def defect {n : ℕ} (p : NShape n) : ℕ := n - longest (ofPartition p) + +lemma diagram_card {n : ℕ} (p : NShape n) : Fintype.card (Cells (ofPartition p)) = n := by + simpa only [Fintype.card_fin] using card_ofPartition p + +lemma extensions_le_degree {n : ℕ} (p : NShape n) : + Fintype.card (Extensions (Cells (ofPartition p))) ≤ degree p := + extensions_card_le_degree (ofPartition p) (canonicalTableau p) + +lemma degree_pos {n : ℕ} (p : NShape n) : 0 < degree p := by + let := extensions_nonempty (Cells (ofPartition p)) + exact (Fintype.card_pos).trans_le (extensions_le_degree p) + +lemma defect_add_longest {n : ℕ} (p : NShape n) : defect p + longest (ofPartition p) = n := by + have h := longest_le_card (ofPartition p) + rw [diagram_card] at h + exact Nat.sub_add_cancel h + +lemma choose_longest_le_degree {n : ℕ} (p : NShape n) (k : ℕ) + (hk : k ≤ defect p) (hL : k ≤ longest (ofPartition p)) : + (longest (ofPartition p)).choose k ≤ degree p := by + have hc : Fintype.card (Lower (orient (ofPartition p))) = defect p := by + have hh := card_lower_add (orient (ofPartition p)) + rw [orient_rowLen, orient_card, diagram_card] at hh + have hd := defect_add_longest p + omega + have hh := choose_le_extensions (orient (ofPartition p)) k (by rwa [hc]) (by rwa [orient_rowLen]) + rw [orient_rowLen, orient_extensions] at hh + exact hh.trans (extensions_le_degree p) + +lemma small_defect_degree {n : ℕ} (p : NShape n) (h : 4 * defect p ≤ n) : + 3 ^ defect p ≤ degree p := by + have hd := defect_add_longest p + exact (pow_le_choose_of_mul_le 3 _ _ (by omega)).trans + (choose_longest_le_degree p _ le_rfl (by omega)) + +lemma fixed_defect_degree {n : ℕ} (p : NShape n) (hp : 0 < defect p) (h : 2 * defect p ≤ n) : + n - 2 * defect p + 1 ≤ degree p := by + have hd := defect_add_longest p + have hh := sub_add_one_le_choose (longest (ofPartition p)) (defect p) hp (by omega) + have he : longest (ofPartition p) - defect p = n - 2 * defect p := by omega + rw [he] at hh + exact hh.trans (choose_longest_le_degree p _ le_rfl (by omega)) + +lemma factorial_third_bound (n : ℕ) : ((n : ℝ) / 3) ^ n ≤ (n.factorial : ℝ) := by + rcases n with _ | n + · norm_num + have hn : (1 : ℝ) ≤ n + 1 := by have := Nat.cast_nonneg (α := ℝ) n; linarith + have hs : (1 : ℝ) ≤ Real.sqrt (2 * Real.pi * (n + 1)) := by + apply Real.le_sqrt_of_sq_le + nlinarith [Real.pi_gt_three] + have he : (n + 1 : ℝ) / 3 ≤ (n + 1) / Real.exp 1 := by + apply div_le_div_of_nonneg_left (by positivity) (Real.exp_pos 1) Real.exp_one_lt_three.le + have hh := Stirling.le_factorial_stirling (n + 1) + push_cast at hh + simpa only [Nat.cast_add, Nat.cast_one] using (pow_le_pow_left₀ (by positivity) he (n+1)).trans + ((le_mul_of_one_le_left (by positivity) hs).trans hh) + +lemma small_longest_degree {n : ℕ} (p : NShape n) (hn : 0 < n) + (hL : 8 * longest (ofPartition p) ≤ n) : + (4 / 3 : ℝ) ^ n ≤ degree p := by + have hf := factorial_le_rank_degree (ofPartition p) (canonicalTableau p) + have hf' : (n.factorial : ℝ) ≤ (2 * (longest (ofPartition p) : ℝ)) ^ n * (degree p : ℝ) := by + exact_mod_cast hf + have he : (2 * (longest (ofPartition p) : ℝ)) ≤ (n : ℝ) / 4 := by + have hh : (8 : ℝ) * longest (ofPartition p) ≤ n := by exact_mod_cast hL + linarith + have hd : (0 : ℝ) ≤ degree p := Nat.cast_nonneg _ + have hh := (factorial_third_bound n).trans (hf'.trans (mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by positivity) he n) hd)) + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hid : ((n : ℝ) / 3) ^ n = ((n : ℝ) / 4) ^ n * (4 / 3 : ℝ)^n := by rw [← mul_pow]; congr 1; ring + rw [hid] at hh + exact le_of_mul_le_mul_left hh (pow_pos (by positivity : (0 : ℝ) < n / 4) n) + +lemma bulk_degree {n : ℕ} (p : NShape n) (hn : 0 < n) (hu : n < 4 * defect p) : + (2 : ℝ) ^ (n / 16) ≤ degree p := by + by_cases hL : 8 * longest (ofPartition p) ≤ n + · have hh : (2 : ℝ) ^ (n / 16) ≤ (4 / 3 : ℝ)^n := by + have hbase : (2 : ℝ) ≤ (4 / 3 : ℝ)^16 := by norm_num + calc + _ ≤ ((4 / 3 : ℝ)^16)^(n/16) := pow_le_pow_left₀ (by norm_num) hbase _ + _ = (4 / 3 : ℝ)^(16 * (n/16)) := by rw [pow_mul] + _ ≤ _ := pow_le_pow_right₀ (by norm_num) (by omega) + exact hh.trans (small_longest_degree p hn hL) + · have hd := defect_add_longest p + have hk : n / 16 ≤ defect p := by omega + have hm : 2 * (n / 16) ≤ longest (ofPartition p) := by omega + exact_mod_cast (pow_le_choose_of_mul_le 2 _ _ hm).trans + (choose_longest_le_degree p _ hk (by omega)) + +lemma defect_card_bound (n u : ℕ) : + Fintype.card {p : NShape n // defect p = u} ≤ 2 ^ (u + 1) := by + have hh : Nat.card {p : Nat.Partition n // n - longest (ofPartition p) = u} ≤ 2 ^ (u+1) := by + rw [← Fintype.card_eq_nat_card] + calc + _ ≤ 2 * Fintype.card (Nat.Partition u) := defect_count_le n u + _ ≤ 2 * 2^u := Nat.mul_le_mul_left 2 (partition_count_le_pow u) + _ = _ := by ring + rw [Fintype.card_eq_nat_card] + change Nat.card {p : Nat.Partition (Fintype.card (Fin n)) // n - longest (ofPartition p) = u} ≤ _ + have he (m k : ℕ) (h : m = k) : + Nat.card {p : Nat.Partition m // n - longest (ofPartition p) = u} = + Nat.card {p : Nat.Partition k // n - longest (ofPartition p) = u} := by subst k; rfl + exact (he _ _ (Fintype.card_fin n)).trans_le hh + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/EightBlocks.lean b/lean/OAI/Probability/ThorpShuffle/EightBlocks.lean index 456e632eb209ca80ad1b896112dbb6a8e4bce7a0..2a42947dc82b39056f924c5cb0db4fc11720230b 100644 --- a/lean/OAI/Probability/ThorpShuffle/EightBlocks.lean +++ b/lean/OAI/Probability/ThorpShuffle/EightBlocks.lean @@ -1,98 +1,98 @@ -import OAI.Probability.ThorpShuffle.BlockLaws - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp -open scoped Classical - -lemma law_complexSign_zero (d t : ℕ) (hd : 1 ≤ d) (ht : 1 ≤ t) : - (∑ g : State d, (law d t g : ℂ) * Specht.complexSign g) = 0 := by - obtain ⟨d,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) - obtain ⟨t,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : t ≠ 0) - have h := congrArg (fun x : ℝ => (x : ℂ)) (Parity.law_sign_zero d t) - simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_zero, Parity.sign, - Specht.complexSign_eq, Complex.ofReal_intCast] using h - -namespace Block -open Thorp.Fourier Thorp.Specht - -def fullRate (d : ℕ) : ℝ := - 8 * discarded d + (1/2 : ℝ) * Real.sqrt - (2 * (2 * discarded d)^16 + (96 : ℝ)^8 * exceptionalReciprocalSum (2^(d+1+2))) - -lemma exceptional_cube_tendsto : - Tendsto (fun d : ℕ => exceptionalReciprocalSum (2^d)) atTop (nhds 0) := - exceptionalReciprocalSum_tendsto.comp - (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) - -lemma fullRate_tendsto : Tendsto fullRate atTop (nhds 0) := by - change Tendsto (fun d : ℕ => 8 * discarded d + (1/2 : ℝ) * Real.sqrt - (2 * (2 * discarded d)^16 + (96 : ℝ)^8 * exceptionalReciprocalSum (2^(d+1+2)))) atTop (nhds 0) - have he := exceptional_cube_tendsto.comp (tendsto_add_atTop_nat 3) - have hb := ((discarded_tendsto.const_mul 2).pow 16).const_mul 2 - have hs := (hb.add (he.const_mul ((96:ℝ)^8))).sqrt - simpa only [Nat.add_assoc, Function.comp_def, mul_zero, zero_pow (by decide : 16 ≠ 0), - add_zero, Real.sqrt_zero] using (discarded_tendsto.const_mul 8).add (hs.const_mul (1/2 : ℝ)) - -lemma reciprocal_atMost_three : - ∀ᶠ d : ℕ in atTop, (permutationFamily (Position d)).reciprocalSum ≤ 3 := by - have he : ∀ᶠ d : ℕ in atTop, exceptionalReciprocalSum (2^d) < 1 := - (tendsto_order.1 exceptional_cube_tendsto).2 1 (by norm_num) - filter_upwards [he] with d hd - have h := full_reciprocal_bound (2^d) - have hc : (permutationFamily (Position d)).reciprocalSum = (symmetricFamily (2^d)).reciprocalSum := by - change (symmetricFamily (Fintype.card (Position d))).reciprocalSum = _ - rw [card_position] - rw [hc] - linarith - -lemma distance_eight_eventually : - ∀ᶠ d : ℕ in atTop, distance (d+1+2) (1600*(d+1+2)) ≤ fullRate d := by - have hd : ∀ᶠ d : ℕ in atTop, discarded d ≤ 1/2 := - ((tendsto_order.1 discarded_tendsto).2 (1/2) (by norm_num)).mono (fun _ h => h.le) - filter_upwards [hd, reciprocal_atMost_three, eventually_ge_atTop 1] with d hδ hR hd1 - have hn : 16 ≤ Fintype.card (Position (d+1+2)) := by - rw [card_position] - calc - 16 = 2^4 := by norm_num - _ ≤ 2^(d+1+2) := Nat.pow_le_pow_right (by norm_num) (by omega) - let : Nontrivial (Position (d+1+2)) := Fintype.one_lt_card_iff_nontrivial.mp (by omega) - have hbound := trimmed_eight_tv hn (embedding (eightEquiv d)) (law (d+1+2) (200*(d+1+2))) - (law_nonneg (d+1+2) (200*(d+1+2))) (law_sum (d+1+2) (200*(d+1+2))) - (law_complexSign_zero _ _ (by omega) (by omega)) hδ - have hpower : law (d+1+2) (1600*(d+1+2)) = realPower (law (d+1+2) (200*(d+1+2))) 8 := by - rw [show 1600*(d+1+2) = 8 * (200*(d+1+2)) by omega] - exact law_realPower (d+1+2) (200*(d+1+2)) 8 - change tv (law (d+1+2) (1600*(d+1+2))) - (fun _ => 1 / (Fintype.card (State (d+1+2)) : ℝ)) ≤ fullRate d - simp only [one_div] - rw [hpower] - apply hbound.trans - unfold fullRate - refine add_le_add (le_refl _) ?_ - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.sqrt_le_sqrt - refine add_le_add (le_refl _) ?_ - rw [card_position] - apply mul_le_mul_of_nonneg_right _ (Finset.sum_nonneg (fun p _ => by - change 0 ≤ (if 0 < defect p then inverseDegree p else 0) - split_ifs <;> first | exact inverseDegree_nonneg p | exact le_rfl)) - apply pow_le_pow_left₀ (mul_nonneg (by norm_num) (permutationFamily (Position d)).reciprocalSum_nonneg) - linarith - -lemma full_mixing_shift : - Tendsto (fun d : ℕ => distance (d+1+2) (1600*(d+1+2))) atTop (nhds 0) := by - apply squeeze_zero' (Eventually.of_forall (fun d => by unfold distance tv; positivity)) - distance_eight_eventually fullRate_tendsto - -end Block -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.BlockLaws + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp +open scoped Classical + +lemma law_complexSign_zero (d t : ℕ) (hd : 1 ≤ d) (ht : 1 ≤ t) : + (∑ g : State d, (law d t g : ℂ) * Specht.complexSign g) = 0 := by + obtain ⟨d,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) + obtain ⟨t,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : t ≠ 0) + have h := congrArg (fun x : ℝ => (x : ℂ)) (Parity.law_sign_zero d t) + simpa only [Complex.ofReal_sum, Complex.ofReal_mul, Complex.ofReal_zero, Parity.sign, + Specht.complexSign_eq, Complex.ofReal_intCast] using h + +namespace Block +open Thorp.Fourier Thorp.Specht + +def fullRate (d : ℕ) : ℝ := + 8 * discarded d + (1/2 : ℝ) * Real.sqrt + (2 * (2 * discarded d)^16 + (96 : ℝ)^8 * exceptionalReciprocalSum (2^(d+1+2))) + +lemma exceptional_cube_tendsto : + Tendsto (fun d : ℕ => exceptionalReciprocalSum (2^d)) atTop (nhds 0) := + exceptionalReciprocalSum_tendsto.comp + (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) + +lemma fullRate_tendsto : Tendsto fullRate atTop (nhds 0) := by + change Tendsto (fun d : ℕ => 8 * discarded d + (1/2 : ℝ) * Real.sqrt + (2 * (2 * discarded d)^16 + (96 : ℝ)^8 * exceptionalReciprocalSum (2^(d+1+2)))) atTop (nhds 0) + have he := exceptional_cube_tendsto.comp (tendsto_add_atTop_nat 3) + have hb := ((discarded_tendsto.const_mul 2).pow 16).const_mul 2 + have hs := (hb.add (he.const_mul ((96:ℝ)^8))).sqrt + simpa only [Nat.add_assoc, Function.comp_def, mul_zero, zero_pow (by decide : 16 ≠ 0), + add_zero, Real.sqrt_zero] using (discarded_tendsto.const_mul 8).add (hs.const_mul (1/2 : ℝ)) + +lemma reciprocal_atMost_three : + ∀ᶠ d : ℕ in atTop, (permutationFamily (Position d)).reciprocalSum ≤ 3 := by + have he : ∀ᶠ d : ℕ in atTop, exceptionalReciprocalSum (2^d) < 1 := + (tendsto_order.1 exceptional_cube_tendsto).2 1 (by norm_num) + filter_upwards [he] with d hd + have h := full_reciprocal_bound (2^d) + have hc : (permutationFamily (Position d)).reciprocalSum = (symmetricFamily (2^d)).reciprocalSum := by + change (symmetricFamily (Fintype.card (Position d))).reciprocalSum = _ + rw [card_position] + rw [hc] + linarith + +lemma distance_eight_eventually : + ∀ᶠ d : ℕ in atTop, distance (d+1+2) (1600*(d+1+2)) ≤ fullRate d := by + have hd : ∀ᶠ d : ℕ in atTop, discarded d ≤ 1/2 := + ((tendsto_order.1 discarded_tendsto).2 (1/2) (by norm_num)).mono (fun _ h => h.le) + filter_upwards [hd, reciprocal_atMost_three, eventually_ge_atTop 1] with d hδ hR hd1 + have hn : 16 ≤ Fintype.card (Position (d+1+2)) := by + rw [card_position] + calc + 16 = 2^4 := by norm_num + _ ≤ 2^(d+1+2) := Nat.pow_le_pow_right (by norm_num) (by omega) + let : Nontrivial (Position (d+1+2)) := Fintype.one_lt_card_iff_nontrivial.mp (by omega) + have hbound := trimmed_eight_tv hn (embedding (eightEquiv d)) (law (d+1+2) (200*(d+1+2))) + (law_nonneg (d+1+2) (200*(d+1+2))) (law_sum (d+1+2) (200*(d+1+2))) + (law_complexSign_zero _ _ (by omega) (by omega)) hδ + have hpower : law (d+1+2) (1600*(d+1+2)) = realPower (law (d+1+2) (200*(d+1+2))) 8 := by + rw [show 1600*(d+1+2) = 8 * (200*(d+1+2)) by omega] + exact law_realPower (d+1+2) (200*(d+1+2)) 8 + change tv (law (d+1+2) (1600*(d+1+2))) + (fun _ => 1 / (Fintype.card (State (d+1+2)) : ℝ)) ≤ fullRate d + simp only [one_div] + rw [hpower] + apply hbound.trans + unfold fullRate + refine add_le_add (le_refl _) ?_ + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.sqrt_le_sqrt + refine add_le_add (le_refl _) ?_ + rw [card_position] + apply mul_le_mul_of_nonneg_right _ (Finset.sum_nonneg (fun p _ => by + change 0 ≤ (if 0 < defect p then inverseDegree p else 0) + split_ifs <;> first | exact inverseDegree_nonneg p | exact le_rfl)) + apply pow_le_pow_left₀ (mul_nonneg (by norm_num) (permutationFamily (Position d)).reciprocalSum_nonneg) + linarith + +lemma full_mixing_shift : + Tendsto (fun d : ℕ => distance (d+1+2) (1600*(d+1+2))) atTop (nhds 0) := by + apply squeeze_zero' (Eventually.of_forall (fun d => by unfold distance tv; positivity)) + distance_eight_eventually fullRate_tendsto + +end Block +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/EnergyDecay.lean b/lean/OAI/Probability/ThorpShuffle/EnergyDecay.lean index 44113119a6efedcb43f1c1be76bd4ddf5e2b8c3c..d2c749b7f2db418db9478bd43c60e49504f03fee 100644 --- a/lean/OAI/Probability/ThorpShuffle/EnergyDecay.lean +++ b/lean/OAI/Probability/ThorpShuffle/EnergyDecay.lean @@ -1,203 +1,203 @@ -import OAI.Probability.ThorpShuffle.NoiseEnergy - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem mean_rawFree_sweep (d : ℕ) (v : RawState (d + 1)) (x : Position (d + 1)) : - mean (fun ω : History (d + 1) (d + 1) => - if (rawIterate d v (d + 1) ω).free x then (1 : ℝ) else 0) = - (freeCount v.free : ℝ) / Fintype.card (Position (d + 1)) := by - simp only [rawIterate_free] - exact mean_free_after_sweep d v.free x - -theorem rawIterate_half_weight (d : ℕ) (v : RawState (d + 2)) (h : Bool) - (ω : History (d + 2) (d + 1)) (x : Position (d + 1)) : - (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) = - (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) - (halfHistory d (d + 1) h ω)).weight x := by - have hz := congrArg (fun u : RawState (d + 1) => u.weight x) - (rawIterate_half d (d + 1) le_rfl h v ω) - simpa only [halfMarker_end, halfRaw, insertBit_zero] using hz - -theorem rawIterate_half_free (d : ℕ) (v : RawState (d + 2)) (h : Bool) - (ω : History (d + 2) (d + 1)) (x : Position (d + 1)) : - (rawIterate (d + 1) v (d + 1) ω).free (Fin.cons h x) = - (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) - (halfHistory d (d + 1) h ω)).free x := by - have hz := congrArg (fun u : RawState (d + 1) => u.free x) - (rawIterate_half d (d + 1) le_rfl h v ω) - simpa only [halfMarker_end, halfRaw, insertBit_zero] using hz - -theorem mean_half_single (d t : ℕ) (h : Bool) (f : History (d + 1) t → ℝ) : - mean (fun ω : History (d + 2) t => f (halfHistory d t h ω)) = mean f := by - simpa only [mean_const, mul_one] using - mean_opposite_half_product d t h f (fun _ => (1 : ℝ)) - -theorem mean_half_factorization (d : ℕ) (v : RawState (d + 2)) (h : Bool) - (x : Position (d + 1)) : - mean (fun ω : History (d + 2) (d + 1) => - (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) ^ 2 * - (if (rawIterate (d + 1) v (d + 1) ω).free (Fin.cons (!h) x) then (1 : ℝ) else 0)) = - ((freeCount (halfRaw (d + 1) (Fin.last (d + 1)) (!h) v).free : ℝ) / - Fintype.card (Position (d + 1))) * - mean (fun ω : History (d + 2) (d + 1) => - (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) ^ 2) := by - simp_rw [rawIterate_half_weight, rawIterate_half_free] - rw [mean_opposite_half_product d (d + 1) h - (fun ω => (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) ω).weight x ^ 2) - (fun ω => if (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) (!h) v) - (d + 1) ω).free x then (1 : ℝ) else 0)] - rw [mean_rawFree_sweep, mean_half_single d (d + 1) h - (fun ω => (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) ω).weight x ^ 2), - mul_comm] - - def rawEnergy {d : ℕ} (v : RawState d) : ℝ := ∑ x, v.weight x ^ 2 - def halfEnergy (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := - ∑ x : Position d, v.weight (Fin.cons h x) ^ 2 - def partnerEnergy (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := - ∑ x : Position d, v.weight (Fin.cons h x) ^ 2 * - (if v.free (Fin.cons (!h) x) then 1 else 0) - def startHalfDensity (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := - (freeCount (halfRaw d (Fin.last d) h v).free : ℝ) / Fintype.card (Position d) - - theorem halfEnergy_nonneg (d : ℕ) (v : RawState (d + 1)) (h : Bool) : - 0 ≤ halfEnergy d v h := Finset.sum_nonneg (fun _ _ => sq_nonneg _) - - theorem rawEnergy_halves (d : ℕ) (v : RawState (d + 1)) : - rawEnergy v = halfEnergy d v false + halfEnergy d v true := by - unfold rawEnergy halfEnergy - have he := Equiv.sum_comp (splitPosition d).symm (fun x => v.weight x ^ 2) - rw [← he, Fintype.sum_prod_type, Fintype.sum_bool, add_comm] - rfl - - theorem oneFreeEnergy_partner (d : ℕ) (v : RawState (d + 1)) : - oneFreeEnergy d v.free v.weight + partnerEnergy d v false + partnerEnergy d v true = - rawEnergy v := by - rw [rawEnergy_halves] - unfold oneFreeEnergy partnerEnergy halfEnergy - simp only [Bool.not_false, Bool.not_true, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro x _ - cases v.free (Fin.cons false x) <;> cases v.free (Fin.cons true x) <;> simp [add_comm] - - theorem mean_half_energy_factorization (d : ℕ) (v : RawState (d + 2)) (h : Bool) : - mean (fun ω : History (d + 2) (d + 1) => - partnerEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω) h) = - startHalfDensity (d + 1) v (!h) * - mean (fun ω : History (d + 2) (d + 1) => - halfEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω) h) := by - unfold partnerEnergy halfEnergy startHalfDensity - rw [mean_sum, mean_sum, Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - exact mean_half_factorization d v h x - -theorem noise_bound_balanced_halves (d : ℕ) (v : RawState (d + 2)) - (β : ℝ) (hb : ∀ h, β ≤ startHalfDensity (d + 1) v h) : - mean (fun ω : History (d + 2) (d + 1) => - oneFreeEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω).free - (rawIterate (d + 1) v (d + 1) ω).weight) ≤ - (1 - β) * mean (fun ω : History (d + 2) (d + 1) => - rawEnergy (rawIterate (d + 1) v (d + 1) ω)) := by - have hid := mean_congr (fun ω : History (d + 2) (d + 1) => - oneFreeEnergy_partner (d + 1) (rawIterate (d + 1) v (d + 1) ω)) - rw [mean_add, mean_add, mean_half_energy_factorization, - mean_half_energy_factorization] at hid - have he := mean_congr (fun ω : History (d + 2) (d + 1) => - rawEnergy_halves (d + 1) (rawIterate (d + 1) v (d + 1) ω)) - rw [mean_add] at he - have hfalse := mul_le_mul_of_nonneg_right (hb true) - (mean_nonneg (fun ω : History (d + 2) (d + 1) => - halfEnergy_nonneg (d + 1) (rawIterate (d + 1) v (d + 1) ω) false)) - have htrue := mul_le_mul_of_nonneg_right (hb false) - (mean_nonneg (fun ω : History (d + 2) (d + 1) => - halfEnergy_nonneg (d + 1) (rawIterate (d + 1) v (d + 1) ω) true)) - simp only [Bool.not_false, Bool.not_true] at hid - rw [he] at hid ⊢ - nlinarith - -end Conditional - -namespace Conditional - -def splitHistory (d s t : ℕ) : History d (s + t) ≃ History d s × History d t where - toFun ω := (fun i => ω (Fin.castAdd t i), fun i => ω (Fin.natAdd s i)) - invFun p := Fin.append p.1 p.2 - left_inv ω := by - funext i - refine Fin.addCases (fun j => ?_) (fun j => ?_) i - · exact Fin.append_left _ _ _ - · exact Fin.append_right _ _ _ - right_inv p := by - apply Prod.ext <;> funext i - · exact Fin.append_left _ _ _ - · exact Fin.append_right _ _ _ - -theorem mean_history_add (d s t : ℕ) (f : History d (s + t) → ℝ) : - mean f = mean (fun a : History d s => - mean (fun b : History d t => f (Fin.append a b))) := by - have he := mean_equiv (splitHistory d s t).symm f - rw [mean_prod] at he - exact he.symm - -@[simp] theorem rawIterate_snoc (d t : ℕ) (v : RawState (d + 1)) - (ω : History (d + 1) t) (c : Coins (d + 1)) : - rawIterate d v (t + 1) (Fin.snoc ω c) = rawNext d (rawIterate d v t ω) c := by - simp [rawIterate] - -@[simp] theorem iterateState_snoc (d t : ℕ) (v : CenteredState (d + 1)) - (ω : History (d + 1) t) (c : Coins (d + 1)) : - iterateState d v (t + 1) (Fin.snoc ω c) = nextState d (iterateState d v t ω) c := by - simp [iterateState] - -theorem rawIterate_append (d s t : ℕ) (v : RawState (d + 1)) - (a : History (d + 1) s) (b : History (d + 1) t) : - rawIterate d v (s + t) (Fin.append a b) = rawIterate d (rawIterate d v s a) t b := by - induction t with - | zero => - have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i - rw [hz]; rfl - | succ t ih => - obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins (d + 1))).surjective b - erw [Fin.append_snoc, rawIterate_snoc, rawIterate_snoc, ih] - -theorem iterateState_append (d s t : ℕ) (v : CenteredState (d + 1)) - (a : History (d + 1) s) (b : History (d + 1) t) : - iterateState d v (s + t) (Fin.append a b) = iterateState d (iterateState d v s a) t b := by - induction t with - | zero => - have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i - rw [hz]; rfl - | succ t ih => - obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins (d + 1))).surjective b - erw [Fin.append_snoc, iterateState_snoc, iterateState_snoc, ih] - -theorem expectedEnergy_add (d s t : ℕ) (v : CenteredState (d + 1)) : - expectedEnergy d v (s + t) = mean (fun a : History (d + 1) s => - expectedEnergy d (iterateState d v s a) t) := by - unfold expectedEnergy - rw [mean_history_add] - simp_rw [iterateState_append] - -theorem expectedNoise_add (d s t : ℕ) (v : CenteredState (d + 1)) : - expectedNoise d v (s + t) = mean (fun a : History (d + 1) s => - expectedNoise d (iterateState d v s a) t) := by - unfold expectedNoise - rw [mean_history_add] - simp_rw [iterateState_append] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.NoiseEnergy + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem mean_rawFree_sweep (d : ℕ) (v : RawState (d + 1)) (x : Position (d + 1)) : + mean (fun ω : History (d + 1) (d + 1) => + if (rawIterate d v (d + 1) ω).free x then (1 : ℝ) else 0) = + (freeCount v.free : ℝ) / Fintype.card (Position (d + 1)) := by + simp only [rawIterate_free] + exact mean_free_after_sweep d v.free x + +theorem rawIterate_half_weight (d : ℕ) (v : RawState (d + 2)) (h : Bool) + (ω : History (d + 2) (d + 1)) (x : Position (d + 1)) : + (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) = + (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) + (halfHistory d (d + 1) h ω)).weight x := by + have hz := congrArg (fun u : RawState (d + 1) => u.weight x) + (rawIterate_half d (d + 1) le_rfl h v ω) + simpa only [halfMarker_end, halfRaw, insertBit_zero] using hz + +theorem rawIterate_half_free (d : ℕ) (v : RawState (d + 2)) (h : Bool) + (ω : History (d + 2) (d + 1)) (x : Position (d + 1)) : + (rawIterate (d + 1) v (d + 1) ω).free (Fin.cons h x) = + (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) + (halfHistory d (d + 1) h ω)).free x := by + have hz := congrArg (fun u : RawState (d + 1) => u.free x) + (rawIterate_half d (d + 1) le_rfl h v ω) + simpa only [halfMarker_end, halfRaw, insertBit_zero] using hz + +theorem mean_half_single (d t : ℕ) (h : Bool) (f : History (d + 1) t → ℝ) : + mean (fun ω : History (d + 2) t => f (halfHistory d t h ω)) = mean f := by + simpa only [mean_const, mul_one] using + mean_opposite_half_product d t h f (fun _ => (1 : ℝ)) + +theorem mean_half_factorization (d : ℕ) (v : RawState (d + 2)) (h : Bool) + (x : Position (d + 1)) : + mean (fun ω : History (d + 2) (d + 1) => + (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) ^ 2 * + (if (rawIterate (d + 1) v (d + 1) ω).free (Fin.cons (!h) x) then (1 : ℝ) else 0)) = + ((freeCount (halfRaw (d + 1) (Fin.last (d + 1)) (!h) v).free : ℝ) / + Fintype.card (Position (d + 1))) * + mean (fun ω : History (d + 2) (d + 1) => + (rawIterate (d + 1) v (d + 1) ω).weight (Fin.cons h x) ^ 2) := by + simp_rw [rawIterate_half_weight, rawIterate_half_free] + rw [mean_opposite_half_product d (d + 1) h + (fun ω => (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) ω).weight x ^ 2) + (fun ω => if (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) (!h) v) + (d + 1) ω).free x then (1 : ℝ) else 0)] + rw [mean_rawFree_sweep, mean_half_single d (d + 1) h + (fun ω => (rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) (d + 1) ω).weight x ^ 2), + mul_comm] + + def rawEnergy {d : ℕ} (v : RawState d) : ℝ := ∑ x, v.weight x ^ 2 + def halfEnergy (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := + ∑ x : Position d, v.weight (Fin.cons h x) ^ 2 + def partnerEnergy (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := + ∑ x : Position d, v.weight (Fin.cons h x) ^ 2 * + (if v.free (Fin.cons (!h) x) then 1 else 0) + def startHalfDensity (d : ℕ) (v : RawState (d + 1)) (h : Bool) : ℝ := + (freeCount (halfRaw d (Fin.last d) h v).free : ℝ) / Fintype.card (Position d) + + theorem halfEnergy_nonneg (d : ℕ) (v : RawState (d + 1)) (h : Bool) : + 0 ≤ halfEnergy d v h := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + + theorem rawEnergy_halves (d : ℕ) (v : RawState (d + 1)) : + rawEnergy v = halfEnergy d v false + halfEnergy d v true := by + unfold rawEnergy halfEnergy + have he := Equiv.sum_comp (splitPosition d).symm (fun x => v.weight x ^ 2) + rw [← he, Fintype.sum_prod_type, Fintype.sum_bool, add_comm] + rfl + + theorem oneFreeEnergy_partner (d : ℕ) (v : RawState (d + 1)) : + oneFreeEnergy d v.free v.weight + partnerEnergy d v false + partnerEnergy d v true = + rawEnergy v := by + rw [rawEnergy_halves] + unfold oneFreeEnergy partnerEnergy halfEnergy + simp only [Bool.not_false, Bool.not_true, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro x _ + cases v.free (Fin.cons false x) <;> cases v.free (Fin.cons true x) <;> simp [add_comm] + + theorem mean_half_energy_factorization (d : ℕ) (v : RawState (d + 2)) (h : Bool) : + mean (fun ω : History (d + 2) (d + 1) => + partnerEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω) h) = + startHalfDensity (d + 1) v (!h) * + mean (fun ω : History (d + 2) (d + 1) => + halfEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω) h) := by + unfold partnerEnergy halfEnergy startHalfDensity + rw [mean_sum, mean_sum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + exact mean_half_factorization d v h x + +theorem noise_bound_balanced_halves (d : ℕ) (v : RawState (d + 2)) + (β : ℝ) (hb : ∀ h, β ≤ startHalfDensity (d + 1) v h) : + mean (fun ω : History (d + 2) (d + 1) => + oneFreeEnergy (d + 1) (rawIterate (d + 1) v (d + 1) ω).free + (rawIterate (d + 1) v (d + 1) ω).weight) ≤ + (1 - β) * mean (fun ω : History (d + 2) (d + 1) => + rawEnergy (rawIterate (d + 1) v (d + 1) ω)) := by + have hid := mean_congr (fun ω : History (d + 2) (d + 1) => + oneFreeEnergy_partner (d + 1) (rawIterate (d + 1) v (d + 1) ω)) + rw [mean_add, mean_add, mean_half_energy_factorization, + mean_half_energy_factorization] at hid + have he := mean_congr (fun ω : History (d + 2) (d + 1) => + rawEnergy_halves (d + 1) (rawIterate (d + 1) v (d + 1) ω)) + rw [mean_add] at he + have hfalse := mul_le_mul_of_nonneg_right (hb true) + (mean_nonneg (fun ω : History (d + 2) (d + 1) => + halfEnergy_nonneg (d + 1) (rawIterate (d + 1) v (d + 1) ω) false)) + have htrue := mul_le_mul_of_nonneg_right (hb false) + (mean_nonneg (fun ω : History (d + 2) (d + 1) => + halfEnergy_nonneg (d + 1) (rawIterate (d + 1) v (d + 1) ω) true)) + simp only [Bool.not_false, Bool.not_true] at hid + rw [he] at hid ⊢ + nlinarith + +end Conditional + +namespace Conditional + +def splitHistory (d s t : ℕ) : History d (s + t) ≃ History d s × History d t where + toFun ω := (fun i => ω (Fin.castAdd t i), fun i => ω (Fin.natAdd s i)) + invFun p := Fin.append p.1 p.2 + left_inv ω := by + funext i + refine Fin.addCases (fun j => ?_) (fun j => ?_) i + · exact Fin.append_left _ _ _ + · exact Fin.append_right _ _ _ + right_inv p := by + apply Prod.ext <;> funext i + · exact Fin.append_left _ _ _ + · exact Fin.append_right _ _ _ + +theorem mean_history_add (d s t : ℕ) (f : History d (s + t) → ℝ) : + mean f = mean (fun a : History d s => + mean (fun b : History d t => f (Fin.append a b))) := by + have he := mean_equiv (splitHistory d s t).symm f + rw [mean_prod] at he + exact he.symm + +@[simp] theorem rawIterate_snoc (d t : ℕ) (v : RawState (d + 1)) + (ω : History (d + 1) t) (c : Coins (d + 1)) : + rawIterate d v (t + 1) (Fin.snoc ω c) = rawNext d (rawIterate d v t ω) c := by + simp [rawIterate] + +@[simp] theorem iterateState_snoc (d t : ℕ) (v : CenteredState (d + 1)) + (ω : History (d + 1) t) (c : Coins (d + 1)) : + iterateState d v (t + 1) (Fin.snoc ω c) = nextState d (iterateState d v t ω) c := by + simp [iterateState] + +theorem rawIterate_append (d s t : ℕ) (v : RawState (d + 1)) + (a : History (d + 1) s) (b : History (d + 1) t) : + rawIterate d v (s + t) (Fin.append a b) = rawIterate d (rawIterate d v s a) t b := by + induction t with + | zero => + have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i + rw [hz]; rfl + | succ t ih => + obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins (d + 1))).surjective b + erw [Fin.append_snoc, rawIterate_snoc, rawIterate_snoc, ih] + +theorem iterateState_append (d s t : ℕ) (v : CenteredState (d + 1)) + (a : History (d + 1) s) (b : History (d + 1) t) : + iterateState d v (s + t) (Fin.append a b) = iterateState d (iterateState d v s a) t b := by + induction t with + | zero => + have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i + rw [hz]; rfl + | succ t ih => + obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins (d + 1))).surjective b + erw [Fin.append_snoc, iterateState_snoc, iterateState_snoc, ih] + +theorem expectedEnergy_add (d s t : ℕ) (v : CenteredState (d + 1)) : + expectedEnergy d v (s + t) = mean (fun a : History (d + 1) s => + expectedEnergy d (iterateState d v s a) t) := by + unfold expectedEnergy + rw [mean_history_add] + simp_rw [iterateState_append] + +theorem expectedNoise_add (d s t : ℕ) (v : CenteredState (d + 1)) : + expectedNoise d v (s + t) = mean (fun a : History (d + 1) s => + expectedNoise d (iterateState d v s a) t) := by + unfold expectedNoise + rw [mean_history_add] + simp_rw [iterateState_append] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ExceptionalShapes.lean b/lean/OAI/Probability/ThorpShuffle/ExceptionalShapes.lean index 69cd79c87451d69692e3a152c3048477ade155ac..55d7a8c2ebb2a2b1c070d32962982c031e2783ac 100644 --- a/lean/OAI/Probability/ThorpShuffle/ExceptionalShapes.lean +++ b/lean/OAI/Probability/ThorpShuffle/ExceptionalShapes.lean @@ -1,70 +1,70 @@ -import OAI.Probability.ThorpShuffle.FirstMoment - -namespace OAI - -noncomputable section - -namespace Thorp.Current -open scoped BigOperators Classical -open Thorp.Specht Thorp.Young - -/-- Verification that the index predicate in `exceptionalFirst` excludes exactly -the row and the column, rather than a merely degree-based surrogate. -/ -lemma full_row_iff (D : YoungDiagram) : - D.rowLen 0 = Fintype.card (Cells D) ↔ ∀ x : Cells D, x.val.1 = 0 := by - constructor - · intro h - have hc : Fintype.card (Lower D) = 0 := by have hh := card_lower_add D; omega - have he : IsEmpty (Lower D) := Fintype.card_eq_zero_iff.mp hc - intro x - by_contra hx - exact he.false ⟨x, hx⟩ - · intro h - have he : IsEmpty (Lower D) := ⟨fun x => x.property (h x.val)⟩ - have hc : Fintype.card (Lower D) = 0 := Fintype.card_eq_zero_iff.mpr he - have hh := card_lower_add D - omega - -lemma full_column_iff (D : YoungDiagram) : - D.colLen 0 = Fintype.card (Cells D) ↔ ∀ x : Cells D, x.val.2 = 0 := by - have hc := Fintype.card_congr (transposeCells D).toEquiv - constructor - · intro h x - have hT : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := by - rw [YoungDiagram.rowLen_transpose, ← hc, h] - exact (full_row_iff D.transpose).mp hT (transposeCells D x) - · intro h - have hT : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := - (full_row_iff D.transpose).mpr (fun x => h ((transposeCells D).symm x)) - simpa only [YoungDiagram.rowLen_transpose, ← hc] using hT - -lemma defect_zero_iff_row_or_column {n : ℕ} (p : NShape n) : - defect p = 0 ↔ - (∀ x : Cells (ofPartition p), x.val.1 = 0) ∨ - (∀ x : Cells (ofPartition p), x.val.2 = 0) := by - rw [← full_row_iff, ← full_column_iff, diagram_card] - have hd := defect_add_longest p - have hL := longest_le_card (ofPartition p) - rw [diagram_card] at hL - unfold longest at hd hL - omega - -lemma exceptionalFirst_exact_nonrow_noncolumn (n : ℕ) : - exceptionalFirst n = ∑ p : NShape n, - if (¬∀ x : Cells (ofPartition p), x.val.1 = 0) ∧ - (¬∀ x : Cells (ofPartition p), x.val.2 = 0) - then (degree p : ℝ)⁻¹ else 0 := by - unfold exceptionalFirst - apply Finset.sum_congr rfl - intro p _ - have h : 0 < defect p ↔ - (¬∀ x : Cells (ofPartition p), x.val.1 = 0) ∧ - (¬∀ x : Cells (ofPartition p), x.val.2 = 0) := by - rw [Nat.pos_iff_ne_zero, ne_eq, defect_zero_iff_row_or_column, not_or] - simp only [h] - -end Thorp.Current - -end - -end OAI +import OAI.Probability.ThorpShuffle.FirstMoment + +namespace OAI + +noncomputable section + +namespace Thorp.Current +open scoped BigOperators Classical +open Thorp.Specht Thorp.Young + +/-- Verification that the index predicate in `exceptionalFirst` excludes exactly +the row and the column, rather than a merely degree-based surrogate. -/ +lemma full_row_iff (D : YoungDiagram) : + D.rowLen 0 = Fintype.card (Cells D) ↔ ∀ x : Cells D, x.val.1 = 0 := by + constructor + · intro h + have hc : Fintype.card (Lower D) = 0 := by have hh := card_lower_add D; omega + have he : IsEmpty (Lower D) := Fintype.card_eq_zero_iff.mp hc + intro x + by_contra hx + exact he.false ⟨x, hx⟩ + · intro h + have he : IsEmpty (Lower D) := ⟨fun x => x.property (h x.val)⟩ + have hc : Fintype.card (Lower D) = 0 := Fintype.card_eq_zero_iff.mpr he + have hh := card_lower_add D + omega + +lemma full_column_iff (D : YoungDiagram) : + D.colLen 0 = Fintype.card (Cells D) ↔ ∀ x : Cells D, x.val.2 = 0 := by + have hc := Fintype.card_congr (transposeCells D).toEquiv + constructor + · intro h x + have hT : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := by + rw [YoungDiagram.rowLen_transpose, ← hc, h] + exact (full_row_iff D.transpose).mp hT (transposeCells D x) + · intro h + have hT : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := + (full_row_iff D.transpose).mpr (fun x => h ((transposeCells D).symm x)) + simpa only [YoungDiagram.rowLen_transpose, ← hc] using hT + +lemma defect_zero_iff_row_or_column {n : ℕ} (p : NShape n) : + defect p = 0 ↔ + (∀ x : Cells (ofPartition p), x.val.1 = 0) ∨ + (∀ x : Cells (ofPartition p), x.val.2 = 0) := by + rw [← full_row_iff, ← full_column_iff, diagram_card] + have hd := defect_add_longest p + have hL := longest_le_card (ofPartition p) + rw [diagram_card] at hL + unfold longest at hd hL + omega + +lemma exceptionalFirst_exact_nonrow_noncolumn (n : ℕ) : + exceptionalFirst n = ∑ p : NShape n, + if (¬∀ x : Cells (ofPartition p), x.val.1 = 0) ∧ + (¬∀ x : Cells (ofPartition p), x.val.2 = 0) + then (degree p : ℝ)⁻¹ else 0 := by + unfold exceptionalFirst + apply Finset.sum_congr rfl + intro p _ + have h : 0 < defect p ↔ + (¬∀ x : Cells (ofPartition p), x.val.1 = 0) ∧ + (¬∀ x : Cells (ofPartition p), x.val.2 = 0) := by + rw [Nat.pos_iff_ne_zero, ne_eq, defect_zero_iff_row_or_column, not_or] + simp only [h] + +end Thorp.Current + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ExtensionBounds.lean b/lean/OAI/Probability/ThorpShuffle/ExtensionBounds.lean index 31aaed4e55ad300a80dcc67dfaf65bbb7af58535..92113235ea824eb9927e95e724d2b6ac4d09a63d 100644 --- a/lean/OAI/Probability/ThorpShuffle/ExtensionBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/ExtensionBounds.lean @@ -1,237 +1,237 @@ -import OAI.Probability.ThorpShuffle.LinearExtensions - -namespace OAI - -universe uA - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical -variable {A : Type uA} [Fintype A] [PartialOrder A] - -lemma extensions_card_ideal (s : Set A) (hs : IsLowerSet s) : - Fintype.card (Extensions s) ≤ Fintype.card (Extensions A) := by - obtain ⟨c⟩ := extensions_nonempty (sᶜ : Set A) - have hc : Fintype.card s + Fintype.card (sᶜ : Set A) = Fintype.card A := by - simpa only [Fintype.card_sum] using Fintype.card_congr (Equiv.Set.sumCompl s) - let F (e : Extensions s) : A ≃ Fin (Fintype.card A) := - ((Equiv.Set.sumCompl s).symm.trans (Equiv.sumCongr e.val c.val)).trans - (finSumFinEquiv.trans (finCongr hc)) - have hFs (e : Extensions s) (x : s) : (F e x).val = (e.val x).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] - have hFc (e : Extensions s) (x : (sᶜ : Set A)) : - (F e x).val = Fintype.card s + (c.val x).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] - have hF (e : Extensions s) : StrictMono (F e) := by - intro x y hxy - change (F e x).val < (F e y).val - by_cases hx : x ∈ s <;> by_cases hy : y ∈ s - · rw [hFs e ⟨x, hx⟩, hFs e ⟨y, hy⟩] - exact e.property hxy - · rw [hFs e ⟨x, hx⟩, hFc e ⟨y, hy⟩] - exact (e.val ⟨x, hx⟩).isLt.trans_le (Nat.le_add_right _ _) - · exact False.elim (hx (hs hxy.le hy)) - · rw [hFc e ⟨x, hx⟩, hFc e ⟨y, hy⟩] - exact Nat.add_lt_add_left (c.property hxy) _ - let f (e : Extensions s) : Extensions A := ⟨F e, hF e⟩ - apply Fintype.card_le_of_injective f - intro e d hed - apply Subtype.ext - apply Equiv.ext - intro x - apply Fin.ext - have hh := congrArg (fun z : Extensions A => (z.val x).val) hed - change (F e x).val = (F d x).val at hh - simpa only [hFs] using hh - -lemma extensions_card_compl_ideal (s : Set A) (hs : IsLowerSet s) : - Fintype.card (Extensions (sᶜ : Set A)) ≤ Fintype.card (Extensions A) := by - obtain ⟨a⟩ := extensions_nonempty s - have hc : Fintype.card s + Fintype.card (sᶜ : Set A) = Fintype.card A := by - simpa only [Fintype.card_sum] using Fintype.card_congr (Equiv.Set.sumCompl s) - let F (e : Extensions (sᶜ : Set A)) : A ≃ Fin (Fintype.card A) := - ((Equiv.Set.sumCompl s).symm.trans (Equiv.sumCongr a.val e.val)).trans - (finSumFinEquiv.trans (finCongr hc)) - have hFs (e : Extensions (sᶜ : Set A)) (x : s) : (F e x).val = (a.val x).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] - have hFc (e : Extensions (sᶜ : Set A)) (x : (sᶜ : Set A)) : - (F e x).val = Fintype.card s + (e.val x).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] - have hF (e : Extensions (sᶜ : Set A)) : StrictMono (F e) := by - intro x y hxy - change (F e x).val < (F e y).val - by_cases hx : x ∈ s <;> by_cases hy : y ∈ s - · rw [hFs e ⟨x, hx⟩, hFs e ⟨y, hy⟩] - exact a.property hxy - · rw [hFs e ⟨x, hx⟩, hFc e ⟨y, hy⟩] - exact (a.val ⟨x, hx⟩).isLt.trans_le (Nat.le_add_right _ _) - · exact False.elim (hx (hs hxy.le hy)) - · rw [hFc e ⟨x, hx⟩, hFc e ⟨y, hy⟩] - exact Nat.add_lt_add_left (e.property hxy) _ - let f (e : Extensions (sᶜ : Set A)) : Extensions A := ⟨F e, hF e⟩ - apply Fintype.card_le_of_injective f - intro e d hed - apply Subtype.ext - apply Equiv.ext - intro x - apply Fin.ext - have hh := congrArg (fun z : Extensions A => (z.val x).val) hed - change (F e x).val = (F d x).val at hh - have h := congrArg (fun z : ℕ => z - Fintype.card s) hh - simpa only [hFc, Nat.add_sub_cancel_left] using h - -end Thorp.Young - -namespace Thorp.Young -open scoped Classical -variable {A : Type uA} [Fintype A] [PartialOrder A] - -lemma choose_le_extensions_split (s : Set A) - (hs : ∀ x y : A, x < y → (x ∈ s ↔ y ∈ s)) : - (Fintype.card A).choose (Fintype.card s) ≤ Fintype.card (Extensions A) := by - obtain ⟨a⟩ := extensions_nonempty s - obtain ⟨b⟩ := extensions_nonempty (sᶜ : Set A) - let I := {S : Finset (Fin (Fintype.card A)) // S.card = Fintype.card s} - have hi : Fintype.card I = (Fintype.card A).choose (Fintype.card s) := by - calc - Fintype.card I = ((Finset.univ : Finset (Fin (Fintype.card A))).powersetCard (Fintype.card s)).card := by - rw [Fintype.card_subtype] - congr 1 - ext S - simp - _ = _ := by rw [Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] - let P (S : I) : Set (Fin (Fintype.card A)) := S.val - have hP (S : I) : Fintype.card (P S) = Fintype.card s := by - simpa [P] using S.property - have hC (S : I) : Fintype.card ((P S)ᶜ : Set (Fin (Fintype.card A))) = - Fintype.card (sᶜ : Set A) := by - have h₁ := Fintype.card_congr (Equiv.Set.sumCompl (P S)) - have h₂ := Fintype.card_congr (Equiv.Set.sumCompl s) - simp only [Fintype.card_sum, Fintype.card_fin, hP] at h₁ h₂ - omega - let ea (S : I) := (Fintype.orderIsoFinOfCardEq (P S) (hP S)) - let eb (S : I) := (Fintype.orderIsoFinOfCardEq ((P S)ᶜ : Set _) (hC S)) - let F (S : I) : A ≃ Fin (Fintype.card A) := - ((Equiv.Set.sumCompl s).symm.trans - (Equiv.sumCongr (a.val.trans (ea S).toEquiv) (b.val.trans (eb S).toEquiv))).trans - (Equiv.Set.sumCompl (P S)) - have hFa (S : I) (x : s) : F S x = (ea S (a.val x)).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] - have hFb (S : I) (x : (sᶜ : Set A)) : F S x = (eb S (b.val x)).val := by - simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] - have hFm (S : I) (x : A) : F S x ∈ P S ↔ x ∈ s := by - by_cases hx : x ∈ s - · rw [hFa S ⟨x, hx⟩] - exact iff_of_true (ea S (a.val ⟨x, hx⟩)).property hx - · rw [hFb S ⟨x, hx⟩] - exact iff_of_false (eb S (b.val ⟨x, hx⟩)).property hx - have hF (S : I) : StrictMono (F S) := by - intro x y hxy - by_cases hx : x ∈ s - · have hy := (hs x y hxy).mp hx - rw [hFa S ⟨x, hx⟩, hFa S ⟨y, hy⟩] - exact (ea S).strictMono (a.property hxy) - · have hy : y ∉ s := fun h => hx ((hs x y hxy).mpr h) - rw [hFb S ⟨x, hx⟩, hFb S ⟨y, hy⟩] - exact (eb S).strictMono (b.property hxy) - let f (S : I) : Extensions A := ⟨F S, hF S⟩ - rw [← hi] - apply Fintype.card_le_of_injective f - intro S T hST - apply Subtype.ext - ext z - obtain ⟨x, rfl⟩ := (F S).surjective z - have he : F S x = F T x := congrArg (fun e : Extensions A => e.val x) hST - change F S x ∈ P S ↔ F S x ∈ P T - rw [hFm, he, hFm] - -end Thorp.Young - -namespace Thorp.Young -open scoped Classical - -abbrev Lower (D : YoungDiagram) := {x : Cells D // x.val.1 ≠ 0} - -def topPrefix (D : YoungDiagram) (u : ℕ) : Set (Cells D) := - {x | x.val.1 = 0 ∧ x.val.2 < u} - -lemma topPrefix_lower (D : YoungDiagram) (u : ℕ) : IsLowerSet (topPrefix D u) := by - intro y x hxy hy - change y.val.1 = 0 ∧ y.val.2 < u at hy - change x.val.1 = 0 ∧ x.val.2 < u - exact ⟨by have := hxy.1; omega, lt_of_le_of_lt hxy.2 hy.2⟩ - -lemma card_topPrefix (D : YoungDiagram) (u : ℕ) (hu : u ≤ D.rowLen 0) : - Fintype.card (topPrefix D u) = u := by - let e : topPrefix D u ≃ Fin u := { - toFun := fun x => ⟨x.val.val.2, x.property.2⟩ - invFun := fun j => ⟨⟨(0, j), YoungDiagram.mem_iff_lt_rowLen.mpr (j.isLt.trans_le hu)⟩, rfl, j.isLt⟩ - left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.property.1.symm rfl - right_inv := fun _ => rfl } - exact (Fintype.card_congr e).trans (Fintype.card_fin u) - -lemma card_lower_add (D : YoungDiagram) : - D.rowLen 0 + Fintype.card (Lower D) = Fintype.card (Cells D) := by - have h := Fintype.card_congr (Equiv.sumCompl (fun x : Cells D => x.val.1 = 0)) - simpa only [Fintype.card_sum, card_row_subtype] using h - -lemma lower_col_lt (D : YoungDiagram) (x : Lower D) : x.val.val.2 < Fintype.card (Lower D) := by - let f : Fin (x.val.val.2 + 1) → Lower D := fun j => - ⟨⟨(1, j), D.up_left_mem (i2 := x.val.val.1) (j2 := x.val.val.2) (by have := x.property; omega) (by have := j.isLt; omega) x.val.property⟩, by simp⟩ - have hf : Function.Injective f := by - intro j k hjk - exact Fin.ext (congrArg (fun z : Lower D => z.val.val.2) hjk) - have hh := Fintype.card_le_of_injective f hf - rw [Fintype.card_fin] at hh - omega - -theorem choose_row_le_extensions (D : YoungDiagram) - (hu : Fintype.card (Lower D) ≤ D.rowLen 0) : - (D.rowLen 0).choose (Fintype.card (Lower D)) ≤ Fintype.card (Extensions (Cells D)) := by - let u := Fintype.card (Lower D) - let s := topPrefix D u - let A := (sᶜ : Set (Cells D)) - let r : Set A := {x | x.val.val.1 ≠ 0} - have hc : Fintype.card A = D.rowLen 0 := by - have hh := Fintype.card_congr (Equiv.Set.sumCompl s) - simp only [Fintype.card_sum] at hh - have hs : Fintype.card s = u := card_topPrefix D u hu - have hl := card_lower_add D - change D.rowLen 0 + u = Fintype.card (Cells D) at hl - change Fintype.card s + Fintype.card A = Fintype.card (Cells D) at hh - omega - let e : r ≃ Lower D := { - toFun := fun x => ⟨x.val.val, x.property⟩ - invFun := fun x => ⟨⟨x.val, fun h => x.property h.1⟩, x.property⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - have hr : Fintype.card r = u := Fintype.card_congr e - have hsplit : ∀ x y : A, x < y → (x ∈ r ↔ y ∈ r) := by - intro x y hxy - have h₁ := hxy.le.1 - have h₂ := hxy.le.2 - change x.val.val.1 ≠ 0 ↔ y.val.val.1 ≠ 0 - constructor - · intro hx hy; exact hx (by omega) - · intro hy hx - have hcol := lower_col_lt D ⟨y.val, hy⟩ - have hp := x.property - change ¬(x.val.val.1 = 0 ∧ x.val.val.2 < u) at hp - change y.val.val.2 < u at hcol - exact hp ⟨hx, lt_of_le_of_lt h₂ hcol⟩ - have hh := choose_le_extensions_split r hsplit - have hrN : Nat.card r = u := by simpa only [Fintype.card_eq_nat_card] using hr - have hcN : Nat.card A = D.rowLen 0 := by simpa only [Fintype.card_eq_nat_card] using hc - have hh' : (D.rowLen 0).choose u ≤ Fintype.card (Extensions A) := by - simpa only [Fintype.card_eq_nat_card, hrN, hcN] using hh - exact hh'.trans (extensions_card_compl_ideal s (topPrefix_lower D u)) - -end Thorp.Young - -end - -end OAI +import OAI.Probability.ThorpShuffle.LinearExtensions + +namespace OAI + +universe uA + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical +variable {A : Type uA} [Fintype A] [PartialOrder A] + +lemma extensions_card_ideal (s : Set A) (hs : IsLowerSet s) : + Fintype.card (Extensions s) ≤ Fintype.card (Extensions A) := by + obtain ⟨c⟩ := extensions_nonempty (sᶜ : Set A) + have hc : Fintype.card s + Fintype.card (sᶜ : Set A) = Fintype.card A := by + simpa only [Fintype.card_sum] using Fintype.card_congr (Equiv.Set.sumCompl s) + let F (e : Extensions s) : A ≃ Fin (Fintype.card A) := + ((Equiv.Set.sumCompl s).symm.trans (Equiv.sumCongr e.val c.val)).trans + (finSumFinEquiv.trans (finCongr hc)) + have hFs (e : Extensions s) (x : s) : (F e x).val = (e.val x).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] + have hFc (e : Extensions s) (x : (sᶜ : Set A)) : + (F e x).val = Fintype.card s + (c.val x).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] + have hF (e : Extensions s) : StrictMono (F e) := by + intro x y hxy + change (F e x).val < (F e y).val + by_cases hx : x ∈ s <;> by_cases hy : y ∈ s + · rw [hFs e ⟨x, hx⟩, hFs e ⟨y, hy⟩] + exact e.property hxy + · rw [hFs e ⟨x, hx⟩, hFc e ⟨y, hy⟩] + exact (e.val ⟨x, hx⟩).isLt.trans_le (Nat.le_add_right _ _) + · exact False.elim (hx (hs hxy.le hy)) + · rw [hFc e ⟨x, hx⟩, hFc e ⟨y, hy⟩] + exact Nat.add_lt_add_left (c.property hxy) _ + let f (e : Extensions s) : Extensions A := ⟨F e, hF e⟩ + apply Fintype.card_le_of_injective f + intro e d hed + apply Subtype.ext + apply Equiv.ext + intro x + apply Fin.ext + have hh := congrArg (fun z : Extensions A => (z.val x).val) hed + change (F e x).val = (F d x).val at hh + simpa only [hFs] using hh + +lemma extensions_card_compl_ideal (s : Set A) (hs : IsLowerSet s) : + Fintype.card (Extensions (sᶜ : Set A)) ≤ Fintype.card (Extensions A) := by + obtain ⟨a⟩ := extensions_nonempty s + have hc : Fintype.card s + Fintype.card (sᶜ : Set A) = Fintype.card A := by + simpa only [Fintype.card_sum] using Fintype.card_congr (Equiv.Set.sumCompl s) + let F (e : Extensions (sᶜ : Set A)) : A ≃ Fin (Fintype.card A) := + ((Equiv.Set.sumCompl s).symm.trans (Equiv.sumCongr a.val e.val)).trans + (finSumFinEquiv.trans (finCongr hc)) + have hFs (e : Extensions (sᶜ : Set A)) (x : s) : (F e x).val = (a.val x).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] + have hFc (e : Extensions (sᶜ : Set A)) (x : (sᶜ : Set A)) : + (F e x).val = Fintype.card s + (e.val x).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] + have hF (e : Extensions (sᶜ : Set A)) : StrictMono (F e) := by + intro x y hxy + change (F e x).val < (F e y).val + by_cases hx : x ∈ s <;> by_cases hy : y ∈ s + · rw [hFs e ⟨x, hx⟩, hFs e ⟨y, hy⟩] + exact a.property hxy + · rw [hFs e ⟨x, hx⟩, hFc e ⟨y, hy⟩] + exact (a.val ⟨x, hx⟩).isLt.trans_le (Nat.le_add_right _ _) + · exact False.elim (hx (hs hxy.le hy)) + · rw [hFc e ⟨x, hx⟩, hFc e ⟨y, hy⟩] + exact Nat.add_lt_add_left (e.property hxy) _ + let f (e : Extensions (sᶜ : Set A)) : Extensions A := ⟨F e, hF e⟩ + apply Fintype.card_le_of_injective f + intro e d hed + apply Subtype.ext + apply Equiv.ext + intro x + apply Fin.ext + have hh := congrArg (fun z : Extensions A => (z.val x).val) hed + change (F e x).val = (F d x).val at hh + have h := congrArg (fun z : ℕ => z - Fintype.card s) hh + simpa only [hFc, Nat.add_sub_cancel_left] using h + +end Thorp.Young + +namespace Thorp.Young +open scoped Classical +variable {A : Type uA} [Fintype A] [PartialOrder A] + +lemma choose_le_extensions_split (s : Set A) + (hs : ∀ x y : A, x < y → (x ∈ s ↔ y ∈ s)) : + (Fintype.card A).choose (Fintype.card s) ≤ Fintype.card (Extensions A) := by + obtain ⟨a⟩ := extensions_nonempty s + obtain ⟨b⟩ := extensions_nonempty (sᶜ : Set A) + let I := {S : Finset (Fin (Fintype.card A)) // S.card = Fintype.card s} + have hi : Fintype.card I = (Fintype.card A).choose (Fintype.card s) := by + calc + Fintype.card I = ((Finset.univ : Finset (Fin (Fintype.card A))).powersetCard (Fintype.card s)).card := by + rw [Fintype.card_subtype] + congr 1 + ext S + simp + _ = _ := by rw [Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] + let P (S : I) : Set (Fin (Fintype.card A)) := S.val + have hP (S : I) : Fintype.card (P S) = Fintype.card s := by + simpa [P] using S.property + have hC (S : I) : Fintype.card ((P S)ᶜ : Set (Fin (Fintype.card A))) = + Fintype.card (sᶜ : Set A) := by + have h₁ := Fintype.card_congr (Equiv.Set.sumCompl (P S)) + have h₂ := Fintype.card_congr (Equiv.Set.sumCompl s) + simp only [Fintype.card_sum, Fintype.card_fin, hP] at h₁ h₂ + omega + let ea (S : I) := (Fintype.orderIsoFinOfCardEq (P S) (hP S)) + let eb (S : I) := (Fintype.orderIsoFinOfCardEq ((P S)ᶜ : Set _) (hC S)) + let F (S : I) : A ≃ Fin (Fintype.card A) := + ((Equiv.Set.sumCompl s).symm.trans + (Equiv.sumCongr (a.val.trans (ea S).toEquiv) (b.val.trans (eb S).toEquiv))).trans + (Equiv.Set.sumCompl (P S)) + have hFa (S : I) (x : s) : F S x = (ea S (a.val x)).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_mem x.property] + have hFb (S : I) (x : (sᶜ : Set A)) : F S x = (eb S (b.val x)).val := by + simp [F, Equiv.Set.sumCompl_symm_apply_of_notMem x.property] + have hFm (S : I) (x : A) : F S x ∈ P S ↔ x ∈ s := by + by_cases hx : x ∈ s + · rw [hFa S ⟨x, hx⟩] + exact iff_of_true (ea S (a.val ⟨x, hx⟩)).property hx + · rw [hFb S ⟨x, hx⟩] + exact iff_of_false (eb S (b.val ⟨x, hx⟩)).property hx + have hF (S : I) : StrictMono (F S) := by + intro x y hxy + by_cases hx : x ∈ s + · have hy := (hs x y hxy).mp hx + rw [hFa S ⟨x, hx⟩, hFa S ⟨y, hy⟩] + exact (ea S).strictMono (a.property hxy) + · have hy : y ∉ s := fun h => hx ((hs x y hxy).mpr h) + rw [hFb S ⟨x, hx⟩, hFb S ⟨y, hy⟩] + exact (eb S).strictMono (b.property hxy) + let f (S : I) : Extensions A := ⟨F S, hF S⟩ + rw [← hi] + apply Fintype.card_le_of_injective f + intro S T hST + apply Subtype.ext + ext z + obtain ⟨x, rfl⟩ := (F S).surjective z + have he : F S x = F T x := congrArg (fun e : Extensions A => e.val x) hST + change F S x ∈ P S ↔ F S x ∈ P T + rw [hFm, he, hFm] + +end Thorp.Young + +namespace Thorp.Young +open scoped Classical + +abbrev Lower (D : YoungDiagram) := {x : Cells D // x.val.1 ≠ 0} + +def topPrefix (D : YoungDiagram) (u : ℕ) : Set (Cells D) := + {x | x.val.1 = 0 ∧ x.val.2 < u} + +lemma topPrefix_lower (D : YoungDiagram) (u : ℕ) : IsLowerSet (topPrefix D u) := by + intro y x hxy hy + change y.val.1 = 0 ∧ y.val.2 < u at hy + change x.val.1 = 0 ∧ x.val.2 < u + exact ⟨by have := hxy.1; omega, lt_of_le_of_lt hxy.2 hy.2⟩ + +lemma card_topPrefix (D : YoungDiagram) (u : ℕ) (hu : u ≤ D.rowLen 0) : + Fintype.card (topPrefix D u) = u := by + let e : topPrefix D u ≃ Fin u := { + toFun := fun x => ⟨x.val.val.2, x.property.2⟩ + invFun := fun j => ⟨⟨(0, j), YoungDiagram.mem_iff_lt_rowLen.mpr (j.isLt.trans_le hu)⟩, rfl, j.isLt⟩ + left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.property.1.symm rfl + right_inv := fun _ => rfl } + exact (Fintype.card_congr e).trans (Fintype.card_fin u) + +lemma card_lower_add (D : YoungDiagram) : + D.rowLen 0 + Fintype.card (Lower D) = Fintype.card (Cells D) := by + have h := Fintype.card_congr (Equiv.sumCompl (fun x : Cells D => x.val.1 = 0)) + simpa only [Fintype.card_sum, card_row_subtype] using h + +lemma lower_col_lt (D : YoungDiagram) (x : Lower D) : x.val.val.2 < Fintype.card (Lower D) := by + let f : Fin (x.val.val.2 + 1) → Lower D := fun j => + ⟨⟨(1, j), D.up_left_mem (i2 := x.val.val.1) (j2 := x.val.val.2) (by have := x.property; omega) (by have := j.isLt; omega) x.val.property⟩, by simp⟩ + have hf : Function.Injective f := by + intro j k hjk + exact Fin.ext (congrArg (fun z : Lower D => z.val.val.2) hjk) + have hh := Fintype.card_le_of_injective f hf + rw [Fintype.card_fin] at hh + omega + +theorem choose_row_le_extensions (D : YoungDiagram) + (hu : Fintype.card (Lower D) ≤ D.rowLen 0) : + (D.rowLen 0).choose (Fintype.card (Lower D)) ≤ Fintype.card (Extensions (Cells D)) := by + let u := Fintype.card (Lower D) + let s := topPrefix D u + let A := (sᶜ : Set (Cells D)) + let r : Set A := {x | x.val.val.1 ≠ 0} + have hc : Fintype.card A = D.rowLen 0 := by + have hh := Fintype.card_congr (Equiv.Set.sumCompl s) + simp only [Fintype.card_sum] at hh + have hs : Fintype.card s = u := card_topPrefix D u hu + have hl := card_lower_add D + change D.rowLen 0 + u = Fintype.card (Cells D) at hl + change Fintype.card s + Fintype.card A = Fintype.card (Cells D) at hh + omega + let e : r ≃ Lower D := { + toFun := fun x => ⟨x.val.val, x.property⟩ + invFun := fun x => ⟨⟨x.val, fun h => x.property h.1⟩, x.property⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + have hr : Fintype.card r = u := Fintype.card_congr e + have hsplit : ∀ x y : A, x < y → (x ∈ r ↔ y ∈ r) := by + intro x y hxy + have h₁ := hxy.le.1 + have h₂ := hxy.le.2 + change x.val.val.1 ≠ 0 ↔ y.val.val.1 ≠ 0 + constructor + · intro hx hy; exact hx (by omega) + · intro hy hx + have hcol := lower_col_lt D ⟨y.val, hy⟩ + have hp := x.property + change ¬(x.val.val.1 = 0 ∧ x.val.val.2 < u) at hp + change y.val.val.2 < u at hcol + exact hp ⟨hx, lt_of_le_of_lt h₂ hcol⟩ + have hh := choose_le_extensions_split r hsplit + have hrN : Nat.card r = u := by simpa only [Fintype.card_eq_nat_card] using hr + have hcN : Nat.card A = D.rowLen 0 := by simpa only [Fintype.card_eq_nat_card] using hc + have hh' : (D.rowLen 0).choose u ≤ Fintype.card (Extensions A) := by + simpa only [Fintype.card_eq_nat_card, hrN, hcN] using hh + exact hh'.trans (extensions_card_compl_ideal s (topPrefix_lower D u)) + +end Thorp.Young + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FiniteExpectation.lean b/lean/OAI/Probability/ThorpShuffle/FiniteExpectation.lean index f6a1fa60b314495edeed1be614d0d8e5ec3caecf..ff62f4f4a65ddc8725be16d61d9385cac4e662b8 100644 --- a/lean/OAI/Probability/ThorpShuffle/FiniteExpectation.lean +++ b/lean/OAI/Probability/ThorpShuffle/FiniteExpectation.lean @@ -1,134 +1,134 @@ -import OAI.Probability.ThorpShuffle.ConditionalFlow - -namespace OAI - -universe uΩ uι uΩ' - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem mean_congr {Ω : Type uΩ} [Fintype Ω] {f g : Ω → ℝ} (h : ∀ ω, f ω = g ω) : - mean f = mean g := by - unfold mean - congr 1 - exact Finset.sum_congr rfl (fun ω _ => h ω) - -theorem mean_zero {Ω : Type uΩ} [Fintype Ω] : mean (fun _ : Ω => (0 : ℝ)) = 0 := by - simp [mean] - -theorem mean_const {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] (a : ℝ) : - mean (fun _ : Ω => a) = a := by - have hc : (Fintype.card Ω : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - simp [mean, hc] - -theorem mean_add {Ω : Type uΩ} [Fintype Ω] (f g : Ω → ℝ) : - mean (fun ω => f ω + g ω) = mean f + mean g := by - simp only [mean, Finset.sum_add_distrib, add_div] - -theorem mean_mul_const {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : - mean (fun ω => f ω * a) = mean f * a := by - simp only [mean, ← Finset.sum_mul] - ring - -theorem mean_const_mul {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : - mean (fun ω => a * f ω) = a * mean f := by - simpa only [mul_comm] using mean_mul_const f a - -theorem mean_sum {Ω : Type uΩ} {ι : Type uι} [Fintype Ω] (s : Finset ι) (f : Ω → ι → ℝ) : - mean (fun ω => ∑ i ∈ s, f ω i) = ∑ i ∈ s, mean (fun ω => f ω i) := by - unfold mean - rw [Finset.sum_comm, Finset.sum_div] - -theorem mean_nonneg {Ω : Type uΩ} [Fintype Ω] {f : Ω → ℝ} (hf : ∀ ω, 0 ≤ f ω) : - 0 ≤ mean f := by - exact div_nonneg (Finset.sum_nonneg (fun ω _ => hf ω)) (Nat.cast_nonneg _) - -theorem mean_le_mean {Ω : Type uΩ} [Fintype Ω] {f g : Ω → ℝ} (h : ∀ ω, f ω ≤ g ω) : - mean f ≤ mean g := by - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) - -theorem mean_le_const {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} {a : ℝ} - (h : ∀ ω, f ω ≤ a) : mean f ≤ a := by - simpa only [mean_const] using mean_le_mean h - -theorem mean_equiv {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] - (e : Ω ≃ Ω') (f : Ω' → ℝ) : mean (f ∘ e) = mean f := by - unfold mean - rw [Fintype.card_congr e] - congr 1 - exact Equiv.sum_comp e f - -theorem mean_prod {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] - (f : Ω × Ω' → ℝ) : mean f = mean (fun ω => mean (fun ω' => f (ω, ω'))) := by - simp only [mean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, - ← Finset.sum_div] - ring - -theorem mean_comm {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : - mean (fun ω => mean (f ω)) = mean (fun ω' => mean (fun ω => f ω ω')) := by - simp only [mean, ← Finset.sum_div] - rw [Finset.sum_comm] - ring - -theorem mean_history_succ (d t : ℕ) (f : History d (t + 1) → ℝ) : - mean f = mean (fun ω : History d t => mean (fun c : Coins d => f (Fin.snoc ω c))) := by - have h := mean_equiv (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins d)) f - rw [mean_prod] at h - rw [← h, mean_comm] - rfl - -end Conditional - -@[simp] theorem run_zero (d : ℕ) (ω : History d 0) : run d 0 ω = 1 := by - simp [run] - -theorem run_succ (d t : ℕ) (ω : History d (t + 1)) : - run d (t + 1) ω = step d (ω (Fin.last t)) * - run d t (fun i => ω i.castSucc) := by - simp only [run, List.ofFn_succ'] - rw [List.concat_eq_append, List.reverse_concat', List.prod_cons] - -namespace Conditional - -theorem iterateState_free (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) - (ω : History (d + 1) t) (x : Position (d + 1)) : - (iterateState d v t ω).free x = v.free ((run (d + 1) t ω).symm x) := by - induction t generalizing x with - | zero => simp only [iterateState, run_zero]; rfl - | succ t ih => - change (iterateState d v t (fun i => ω i.castSucc)).free - ((step (d + 1) (ω (Fin.last t))).symm x) = _ - rw [ih, run_succ] - rfl - -theorem iterateState_freeCount (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) - (ω : History (d + 1) t) : freeCount (iterateState d v t ω).free = freeCount v.free := by - apply Nat.cast_injective (R := ℝ) - rw [← sum_free_indicator, ← sum_free_indicator] - simp only [iterateState_free] - exact Equiv.sum_comp (run (d + 1) t ω).symm (fun x => if v.free x then (1 : ℝ) else 0) - -theorem expectedEnergy_succ (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - expectedEnergy d v (t + 1) = mean (fun ω : History (d + 1) t => - mean (fun c : Coins (d + 1) => ∑ x, (nextState d (iterateState d v t ω) c).weight x ^ 2)) := by - unfold expectedEnergy - rw [mean_history_succ] - apply mean_congr - intro ω - apply mean_congr - intro c - simp [iterateState] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.ConditionalFlow + +namespace OAI + +universe uΩ uι uΩ' + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem mean_congr {Ω : Type uΩ} [Fintype Ω] {f g : Ω → ℝ} (h : ∀ ω, f ω = g ω) : + mean f = mean g := by + unfold mean + congr 1 + exact Finset.sum_congr rfl (fun ω _ => h ω) + +theorem mean_zero {Ω : Type uΩ} [Fintype Ω] : mean (fun _ : Ω => (0 : ℝ)) = 0 := by + simp [mean] + +theorem mean_const {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] (a : ℝ) : + mean (fun _ : Ω => a) = a := by + have hc : (Fintype.card Ω : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + simp [mean, hc] + +theorem mean_add {Ω : Type uΩ} [Fintype Ω] (f g : Ω → ℝ) : + mean (fun ω => f ω + g ω) = mean f + mean g := by + simp only [mean, Finset.sum_add_distrib, add_div] + +theorem mean_mul_const {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : + mean (fun ω => f ω * a) = mean f * a := by + simp only [mean, ← Finset.sum_mul] + ring + +theorem mean_const_mul {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : + mean (fun ω => a * f ω) = a * mean f := by + simpa only [mul_comm] using mean_mul_const f a + +theorem mean_sum {Ω : Type uΩ} {ι : Type uι} [Fintype Ω] (s : Finset ι) (f : Ω → ι → ℝ) : + mean (fun ω => ∑ i ∈ s, f ω i) = ∑ i ∈ s, mean (fun ω => f ω i) := by + unfold mean + rw [Finset.sum_comm, Finset.sum_div] + +theorem mean_nonneg {Ω : Type uΩ} [Fintype Ω] {f : Ω → ℝ} (hf : ∀ ω, 0 ≤ f ω) : + 0 ≤ mean f := by + exact div_nonneg (Finset.sum_nonneg (fun ω _ => hf ω)) (Nat.cast_nonneg _) + +theorem mean_le_mean {Ω : Type uΩ} [Fintype Ω] {f g : Ω → ℝ} (h : ∀ ω, f ω ≤ g ω) : + mean f ≤ mean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun ω _ => h ω)) (Nat.cast_nonneg _) + +theorem mean_le_const {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] {f : Ω → ℝ} {a : ℝ} + (h : ∀ ω, f ω ≤ a) : mean f ≤ a := by + simpa only [mean_const] using mean_le_mean h + +theorem mean_equiv {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] + (e : Ω ≃ Ω') (f : Ω' → ℝ) : mean (f ∘ e) = mean f := by + unfold mean + rw [Fintype.card_congr e] + congr 1 + exact Equiv.sum_comp e f + +theorem mean_prod {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] + (f : Ω × Ω' → ℝ) : mean f = mean (fun ω => mean (fun ω' => f (ω, ω'))) := by + simp only [mean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ← Finset.sum_div] + ring + +theorem mean_comm {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] (f : Ω → Ω' → ℝ) : + mean (fun ω => mean (f ω)) = mean (fun ω' => mean (fun ω => f ω ω')) := by + simp only [mean, ← Finset.sum_div] + rw [Finset.sum_comm] + ring + +theorem mean_history_succ (d t : ℕ) (f : History d (t + 1) → ℝ) : + mean f = mean (fun ω : History d t => mean (fun c : Coins d => f (Fin.snoc ω c))) := by + have h := mean_equiv (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins d)) f + rw [mean_prod] at h + rw [← h, mean_comm] + rfl + +end Conditional + +@[simp] theorem run_zero (d : ℕ) (ω : History d 0) : run d 0 ω = 1 := by + simp [run] + +theorem run_succ (d t : ℕ) (ω : History d (t + 1)) : + run d (t + 1) ω = step d (ω (Fin.last t)) * + run d t (fun i => ω i.castSucc) := by + simp only [run, List.ofFn_succ'] + rw [List.concat_eq_append, List.reverse_concat', List.prod_cons] + +namespace Conditional + +theorem iterateState_free (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) + (ω : History (d + 1) t) (x : Position (d + 1)) : + (iterateState d v t ω).free x = v.free ((run (d + 1) t ω).symm x) := by + induction t generalizing x with + | zero => simp only [iterateState, run_zero]; rfl + | succ t ih => + change (iterateState d v t (fun i => ω i.castSucc)).free + ((step (d + 1) (ω (Fin.last t))).symm x) = _ + rw [ih, run_succ] + rfl + +theorem iterateState_freeCount (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) + (ω : History (d + 1) t) : freeCount (iterateState d v t ω).free = freeCount v.free := by + apply Nat.cast_injective (R := ℝ) + rw [← sum_free_indicator, ← sum_free_indicator] + simp only [iterateState_free] + exact Equiv.sum_comp (run (d + 1) t ω).symm (fun x => if v.free x then (1 : ℝ) else 0) + +theorem expectedEnergy_succ (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + expectedEnergy d v (t + 1) = mean (fun ω : History (d + 1) t => + mean (fun c : Coins (d + 1) => ∑ x, (nextState d (iterateState d v t ω) c).weight x ^ 2)) := by + unfold expectedEnergy + rw [mean_history_succ] + apply mean_congr + intro ω + apply mean_congr + intro c + simp [iterateState] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FiniteLaw.lean b/lean/OAI/Probability/ThorpShuffle/FiniteLaw.lean index 45ec9541772878ed2fc5e6da07e6d2ee5f0aec72..5a1a160d7591b3f32fdde38f2da0b159cfa0fdbb 100644 --- a/lean/OAI/Probability/ThorpShuffle/FiniteLaw.lean +++ b/lean/OAI/Probability/ThorpShuffle/FiniteLaw.lean @@ -1,141 +1,141 @@ -import OAI.Probability.ThorpShuffle.Reachability - -namespace OAI - -universe uG uΩ uΩ' uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace FiniteLaw -open Conditional - -variable {G : Type uG} [Fintype G] [Group G] - -def conv (μ ν : G → ℝ) (z : G) : ℝ := ∑ g, μ g * ν (g⁻¹ * z) - -theorem conv_fairMass {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] - (a : Ω → G) (b : Ω' → G) : - conv (fairMass a) (fairMass b) = fairMass (fun p : Ω × Ω' => a p.1 * b p.2) := by - classical - funext z - unfold conv - rw [fairMass_test] - change mean (fun ω => mean (fun ω' => if b ω' = (a ω)⁻¹ * z then 1 else 0)) = - mean (fun p : Ω × Ω' => if a p.1 * b p.2 = z then 1 else 0) - rw [mean_prod] - apply mean_congr - intro ω - apply mean_congr - intro ω' - rw [eq_inv_mul_iff_mul_eq] - -theorem sum_inv_mul (f : G → ℝ) (z : G) : ∑ g, f (g⁻¹ * z) = ∑ g, f g := by - exact Equiv.sum_comp ((Equiv.inv G).trans (Equiv.mulRight z)) f - -theorem sum_mul_left (f : G → ℝ) (g : G) : ∑ z, f (g * z) = ∑ z, f z := - Equiv.sum_comp (Equiv.mulLeft g) f - -theorem conv_uniform (μ : G → ℝ) (hμ : ∑ g, μ g = 1) : - conv μ (fun _ => (1 : ℝ) / Fintype.card G) = fun _ => (1 : ℝ) / Fintype.card G := by - funext z - simp only [conv, ← Finset.sum_mul, hμ, one_mul] - -theorem tv_conv_contract (μ ν : G → ℝ) (hμ : ∑ g, μ g = 1) - (hν : ∑ g, ν g = 1) (c : ℝ) (hc : ∀ g, c ≤ μ g) : - tv (conv μ ν) (fun _ => (1 : ℝ) / Fintype.card G) ≤ - (1 - (Fintype.card G : ℝ) * c) * tv ν (fun _ => (1 : ℝ) / Fintype.card G) := by - let u : ℝ := 1 / Fintype.card G - have hu : ∑ _ : G, u = 1 := by simp [u, Fintype.card_ne_zero] - have hcenter (z : G) : ∑ g, (ν (g⁻¹ * z) - u) = 0 := by - rw [Finset.sum_sub_distrib, sum_inv_mul, hν, hu, sub_self] - have hid (z : G) : conv μ ν z - u = ∑ g, (μ g - c) * (ν (g⁻¹ * z) - u) := by - simp only [sub_mul, Finset.sum_sub_distrib] - rw [← Finset.mul_sum, hcenter, mul_zero, sub_zero] - simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hμ, one_mul, conv] - have hb : ∑ z, |conv μ ν z - u| ≤ - (1 - (Fintype.card G : ℝ) * c) * ∑ z, |ν z - u| := by - calc - _ = ∑ z, |∑ g, (μ g - c) * (ν (g⁻¹ * z) - u)| := by simp_rw [hid] - _ ≤ ∑ z, ∑ g, (μ g - c) * |ν (g⁻¹ * z) - u| := by - apply Finset.sum_le_sum - intro z _ - have h := Finset.abs_sum_le_sum_abs (fun g => (μ g - c) * (ν (g⁻¹ * z) - u)) Finset.univ - simpa only [abs_mul, abs_of_nonneg (sub_nonneg.mpr (hc _))] using h - _ = (∑ g, (μ g - c)) * ∑ z, |ν z - u| := by - rw [Finset.sum_comm, Finset.sum_mul] - apply Finset.sum_congr rfl - intro g _ - rw [← Finset.mul_sum, sum_mul_left (fun z => |ν z - u|)] - _ = _ := by simp [Finset.sum_sub_distrib, hμ] - unfold tv - change (1 / 2 : ℝ) * (∑ z, |conv μ ν z - u|) ≤ _ - nlinarith - -omit [Fintype G] [Group G] in - -theorem fairMass_lower_of_surjective {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] - (a : Ω → G) (ha : Function.Surjective a) (g : G) : - 1 / (Fintype.card Ω : ℝ) ≤ fairMass a g := by - classical - obtain ⟨ω, hω⟩ := ha g - unfold fairMass - apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - have h := Finset.single_le_sum (f := fun ω => if a ω = g then (1 : ℝ) else 0) - (fun _ _ => by split_ifs <;> norm_num) (Finset.mem_univ ω) - simpa only [hω, ↓reduceIte] using h - -end FiniteLaw - -theorem fairMass_eq_mean {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [DecidableEq α] (f : Ω → α) (a : α) : - fairMass f a = Conditional.mean (fun ω => if f ω = a then (1 : ℝ) else 0) := by - classical - unfold fairMass Conditional.mean - congr 1 - apply Finset.sum_congr rfl - intro ω _ - dsimp only - split_ifs <;> rfl - -theorem law_add (d s t : ℕ) : - law d (s + t) = FiniteLaw.conv (law d t) (law d s) := by - classical - rw [law, law, law, FiniteLaw.conv_fairMass] - funext z - rw [fairMass_eq_mean, fairMass_eq_mean] - rw [Conditional.mean_history_add, Conditional.mean_prod, Conditional.mean_comm] - simp only [Reachability.run_append] - -namespace Reachability - -theorem exists_surjective_run (d : ℕ) : - ∃ T : ℕ, Function.Surjective (run (d + 1) T) := by - classical - choose t ht ω hω using attainable_return d - let T : ℕ := ∑ g : State (d + 1), t g - have hT : orderOf (rotate (d + 1)) ∣ T := Finset.dvd_sum (fun g _ => ht g) - refine ⟨T, fun g => ?_⟩ - have hle : t g ≤ T := Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_univ g) - have hdvd : orderOf (rotate (d + 1)) ∣ T - t g := Nat.dvd_sub hT (ht g) - have hid : run (d + 1) (T - t g) (fun _ => zeroCoins d) = 1 := by - rw [run_false] - exact orderOf_dvd_iff_pow_eq_one.mp hdvd - have hh : ∃ a : History (d + 1) (t g + (T - t g)), - run (d + 1) (t g + (T - t g)) a = g := by - refine ⟨Fin.append (ω g) (fun _ => zeroCoins d), ?_⟩ - rw [run_append, hid, one_mul, hω] - have he : t g + (T - t g) = T := by omega - rw [he] at hh - exact hh - -end Reachability - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Reachability + +namespace OAI + +universe uG uΩ uΩ' uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace FiniteLaw +open Conditional + +variable {G : Type uG} [Fintype G] [Group G] + +def conv (μ ν : G → ℝ) (z : G) : ℝ := ∑ g, μ g * ν (g⁻¹ * z) + +theorem conv_fairMass {Ω : Type uΩ} {Ω' : Type uΩ'} [Fintype Ω] [Fintype Ω'] + (a : Ω → G) (b : Ω' → G) : + conv (fairMass a) (fairMass b) = fairMass (fun p : Ω × Ω' => a p.1 * b p.2) := by + classical + funext z + unfold conv + rw [fairMass_test] + change mean (fun ω => mean (fun ω' => if b ω' = (a ω)⁻¹ * z then 1 else 0)) = + mean (fun p : Ω × Ω' => if a p.1 * b p.2 = z then 1 else 0) + rw [mean_prod] + apply mean_congr + intro ω + apply mean_congr + intro ω' + rw [eq_inv_mul_iff_mul_eq] + +theorem sum_inv_mul (f : G → ℝ) (z : G) : ∑ g, f (g⁻¹ * z) = ∑ g, f g := by + exact Equiv.sum_comp ((Equiv.inv G).trans (Equiv.mulRight z)) f + +theorem sum_mul_left (f : G → ℝ) (g : G) : ∑ z, f (g * z) = ∑ z, f z := + Equiv.sum_comp (Equiv.mulLeft g) f + +theorem conv_uniform (μ : G → ℝ) (hμ : ∑ g, μ g = 1) : + conv μ (fun _ => (1 : ℝ) / Fintype.card G) = fun _ => (1 : ℝ) / Fintype.card G := by + funext z + simp only [conv, ← Finset.sum_mul, hμ, one_mul] + +theorem tv_conv_contract (μ ν : G → ℝ) (hμ : ∑ g, μ g = 1) + (hν : ∑ g, ν g = 1) (c : ℝ) (hc : ∀ g, c ≤ μ g) : + tv (conv μ ν) (fun _ => (1 : ℝ) / Fintype.card G) ≤ + (1 - (Fintype.card G : ℝ) * c) * tv ν (fun _ => (1 : ℝ) / Fintype.card G) := by + let u : ℝ := 1 / Fintype.card G + have hu : ∑ _ : G, u = 1 := by simp [u, Fintype.card_ne_zero] + have hcenter (z : G) : ∑ g, (ν (g⁻¹ * z) - u) = 0 := by + rw [Finset.sum_sub_distrib, sum_inv_mul, hν, hu, sub_self] + have hid (z : G) : conv μ ν z - u = ∑ g, (μ g - c) * (ν (g⁻¹ * z) - u) := by + simp only [sub_mul, Finset.sum_sub_distrib] + rw [← Finset.mul_sum, hcenter, mul_zero, sub_zero] + simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hμ, one_mul, conv] + have hb : ∑ z, |conv μ ν z - u| ≤ + (1 - (Fintype.card G : ℝ) * c) * ∑ z, |ν z - u| := by + calc + _ = ∑ z, |∑ g, (μ g - c) * (ν (g⁻¹ * z) - u)| := by simp_rw [hid] + _ ≤ ∑ z, ∑ g, (μ g - c) * |ν (g⁻¹ * z) - u| := by + apply Finset.sum_le_sum + intro z _ + have h := Finset.abs_sum_le_sum_abs (fun g => (μ g - c) * (ν (g⁻¹ * z) - u)) Finset.univ + simpa only [abs_mul, abs_of_nonneg (sub_nonneg.mpr (hc _))] using h + _ = (∑ g, (μ g - c)) * ∑ z, |ν z - u| := by + rw [Finset.sum_comm, Finset.sum_mul] + apply Finset.sum_congr rfl + intro g _ + rw [← Finset.mul_sum, sum_mul_left (fun z => |ν z - u|)] + _ = _ := by simp [Finset.sum_sub_distrib, hμ] + unfold tv + change (1 / 2 : ℝ) * (∑ z, |conv μ ν z - u|) ≤ _ + nlinarith + +omit [Fintype G] [Group G] in + +theorem fairMass_lower_of_surjective {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] + (a : Ω → G) (ha : Function.Surjective a) (g : G) : + 1 / (Fintype.card Ω : ℝ) ≤ fairMass a g := by + classical + obtain ⟨ω, hω⟩ := ha g + unfold fairMass + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + have h := Finset.single_le_sum (f := fun ω => if a ω = g then (1 : ℝ) else 0) + (fun _ _ => by split_ifs <;> norm_num) (Finset.mem_univ ω) + simpa only [hω, ↓reduceIte] using h + +end FiniteLaw + +theorem fairMass_eq_mean {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [DecidableEq α] (f : Ω → α) (a : α) : + fairMass f a = Conditional.mean (fun ω => if f ω = a then (1 : ℝ) else 0) := by + classical + unfold fairMass Conditional.mean + congr 1 + apply Finset.sum_congr rfl + intro ω _ + dsimp only + split_ifs <;> rfl + +theorem law_add (d s t : ℕ) : + law d (s + t) = FiniteLaw.conv (law d t) (law d s) := by + classical + rw [law, law, law, FiniteLaw.conv_fairMass] + funext z + rw [fairMass_eq_mean, fairMass_eq_mean] + rw [Conditional.mean_history_add, Conditional.mean_prod, Conditional.mean_comm] + simp only [Reachability.run_append] + +namespace Reachability + +theorem exists_surjective_run (d : ℕ) : + ∃ T : ℕ, Function.Surjective (run (d + 1) T) := by + classical + choose t ht ω hω using attainable_return d + let T : ℕ := ∑ g : State (d + 1), t g + have hT : orderOf (rotate (d + 1)) ∣ T := Finset.dvd_sum (fun g _ => ht g) + refine ⟨T, fun g => ?_⟩ + have hle : t g ≤ T := Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_univ g) + have hdvd : orderOf (rotate (d + 1)) ∣ T - t g := Nat.dvd_sub hT (ht g) + have hid : run (d + 1) (T - t g) (fun _ => zeroCoins d) = 1 := by + rw [run_false] + exact orderOf_dvd_iff_pow_eq_one.mp hdvd + have hh : ∃ a : History (d + 1) (t g + (T - t g)), + run (d + 1) (t g + (T - t g)) a = g := by + refine ⟨Fin.append (ω g) (fun _ => zeroCoins d), ?_⟩ + rw [run_append, hid, one_mul, hω] + have he : t g + (T - t g) = T := by omega + rw [he] at hh + exact hh + +end Reachability + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FirstFourier.lean b/lean/OAI/Probability/ThorpShuffle/FirstFourier.lean index 44f529eebb91047c2532689ed0f3d7e566ff245f..22a10bed1a388aaaa921cf78953ed9594b38f098 100644 --- a/lean/OAI/Probability/ThorpShuffle/FirstFourier.lean +++ b/lean/OAI/Probability/ThorpShuffle/FirstFourier.lean @@ -1,121 +1,121 @@ -import OAI.Probability.ThorpShuffle.ExceptionalShapes -import OAI.Probability.ThorpShuffle.BlockEmbedding -import OAI.Probability.ThorpShuffle.Model - -namespace OAI - -universe uE - -noncomputable section - -namespace Thorp.Current -open scoped BigOperators Classical ComplexConjugate InnerProductSpace -open Thorp.Fourier - -/-- The first inverse-degree moment yields a `D^(3/8)` orbit bound. -The filter is precisely `degree ≤ D^(1/8)`, written without a root. -/ -lemma low_degree_first {H : Type} [Group H] [Fintype H] - (F : Fourier.Family H) (D : ℕ) : - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2) ≤ - (D : ℝ) ^ (3 / 8 : ℝ) * ∑ b, (F.degree b : ℝ)⁻¹ := by - let s := Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D) - have hp (b : F.Index) : (0 : ℝ) < F.degree b := by exact_mod_cast F.positive b - have hsmall : ∑ b ∈ s, (F.degree b : ℝ)⁻¹ ≤ ∑ b, (F.degree b : ℝ)⁻¹ := - Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) - (fun b _ _ => inv_nonneg.mpr (hp b).le) - calc - _ ≤ ∑ b ∈ s, (D : ℝ) ^ (3 / 8 : ℝ) * (F.degree b : ℝ)⁻¹ := by - apply Finset.sum_le_sum - intro b hb - have hbD : (F.degree b : ℝ)^8 ≤ D := by - exact_mod_cast (Finset.mem_filter.mp hb).2 - apply (le_mul_inv_iff₀ (hp b)).mpr - calc - (F.degree b : ℝ)^2 * F.degree b = (F.degree b : ℝ)^3 := by ring - _ = ((F.degree b : ℝ)^8) ^ (3 / 8 : ℝ) := by - rw [← Real.rpow_natCast_mul (hp b).le] - norm_num - _ ≤ _ := Real.rpow_le_rpow (by positivity) hbD (by norm_num) - _ = (D : ℝ) ^ (3 / 8 : ℝ) * ∑ b ∈ s, (F.degree b : ℝ)⁻¹ := by - rw [Finset.mul_sum] - _ ≤ _ := mul_le_mul_of_nonneg_left hsmall (Real.rpow_nonneg (Nat.cast_nonneg D) _) - -/-- The integrated operator norm bound for an eight-fold block action -with a common probability mass function satisfying all eight coset caps. -/ -lemma eight_block_of_cap {G : Type} [Group G] [Fintype G] - (s : ℕ) (hs : 1 ≤ s) - {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (ψ : (Fin 8 → Equiv.Perm (Fin s)) →* G) - (ν : G → ℝ) (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) - (hcoset : ∀ (i : Fin 8) g, - ∑ h : Equiv.Perm (Fin s), ν (g * ψ (Pi.mulSingle i h)) ≤ - 4 * (Fintype.card (Equiv.Perm (Fin s)) : ℝ) / Fintype.card G) : - ‖LinearMap.toContinuousLinearMap (integrated ρ (fun g => (ν g : ℂ)))‖ ≤ - Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ) := by - let : Nontrivial E := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) ρ.asModule - have hD : (0 : ℝ) < Module.finrank ℂ E := by exact_mod_cast (Module.finrank_pos (R:=ℂ) (M:=E)) - let D := Module.finrank ℂ E - let F := Specht.symmetricFamily s - have hsum : (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2) ≤ - (D : ℝ) ^ (3 / 8 : ℝ) * C1 := by - refine (low_degree_first F D).trans (mul_le_mul_of_nonneg_left ?_ (by positivity)) - exact reciprocalFirst_le_C1 s hs - have hconst : 0 ≤ Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ) := by positivity - have hconst_sq : (Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ))^2 = - 8 * 4 * ((D : ℝ) ^ (3 / 8 : ℝ) * C1) / D := by - rw [mul_pow, Real.sq_sqrt (mul_nonneg (by norm_num) C1_nonneg), - ← Real.rpow_mul_natCast (Nat.cast_nonneg D)] - rw [show (-5 / 16 : ℝ) * (2 : ℕ) = (3 / 8 : ℝ) - 1 by norm_num, - Real.rpow_sub hD, Real.rpow_one] - ring - apply ContinuousLinearMap.opNorm_le_bound _ hconst - intro v - have hb := F.integrated_norm_sq ρ hu (Nat.ne_of_gt Module.finrank_pos) ψ ν 4 hν h1 - (by norm_num) (fun i g => by - convert hcoset i g using 1 - apply Finset.sum_congr rfl - intro h _ - congr 3 - funext j - by_cases hij : j = i <;> simp [hij]) v - simp only [Fintype.card_fin, Nat.cast_ofNat] at hb - have hv : ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ - (Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ) * ‖v‖)^2 := by - rw [mul_pow, hconst_sq] - exact hb.trans (mul_le_mul_of_nonneg_right - (div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left hsum (by norm_num)) hD.le) (sq_nonneg _)) - change ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ≤ _ - nlinarith [norm_nonneg (integrated ρ (fun g => (ν g : ℂ)) v), - mul_nonneg hconst (norm_nonneg v)] - -/-- The integrated operator norm bound for permutations of binary positions -under any equivalence with eight equal blocks. -/ -theorem eight_block_fourier_bound - (d : ℕ) (_hd : 3 ≤ d) - (e : Position d ≃ Fin 8 × Fin (2 ^ (d - 3))) - {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - (ρ : Representation ℂ (Equiv.Perm (Position d)) E) - [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (ν : Equiv.Perm (Position d) → ℝ) - (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) - (hcoset : ∀ (i : Fin 8) (g : Equiv.Perm (Position d)), - ∑ h : Equiv.Perm (Fin (2 ^ (d - 3))), - ν (g * Block.embedding e (Pi.mulSingle i h)) ≤ - 4 * (Fintype.card (Equiv.Perm (Fin (2 ^ (d - 3)))) : ℝ) / - Fintype.card (Equiv.Perm (Position d))) : - ‖LinearMap.toContinuousLinearMap (Fourier.integrated ρ (fun g => (ν g : ℂ)))‖ ≤ - Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ) := by - exact eight_block_of_cap (2 ^ (d - 3)) (Nat.one_le_pow _ _ (by norm_num)) ρ hu - (Block.embedding e) ν hν h1 hcoset - -end Thorp.Current - -end - -end OAI +import OAI.Probability.ThorpShuffle.ExceptionalShapes +import OAI.Probability.ThorpShuffle.BlockEmbedding +import OAI.Probability.ThorpShuffle.Model + +namespace OAI + +universe uE + +noncomputable section + +namespace Thorp.Current +open scoped BigOperators Classical ComplexConjugate InnerProductSpace +open Thorp.Fourier + +/-- The first inverse-degree moment yields a `D^(3/8)` orbit bound. +The filter is precisely `degree ≤ D^(1/8)`, written without a root. -/ +lemma low_degree_first {H : Type} [Group H] [Fintype H] + (F : Fourier.Family H) (D : ℕ) : + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2) ≤ + (D : ℝ) ^ (3 / 8 : ℝ) * ∑ b, (F.degree b : ℝ)⁻¹ := by + let s := Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D) + have hp (b : F.Index) : (0 : ℝ) < F.degree b := by exact_mod_cast F.positive b + have hsmall : ∑ b ∈ s, (F.degree b : ℝ)⁻¹ ≤ ∑ b, (F.degree b : ℝ)⁻¹ := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun b _ _ => inv_nonneg.mpr (hp b).le) + calc + _ ≤ ∑ b ∈ s, (D : ℝ) ^ (3 / 8 : ℝ) * (F.degree b : ℝ)⁻¹ := by + apply Finset.sum_le_sum + intro b hb + have hbD : (F.degree b : ℝ)^8 ≤ D := by + exact_mod_cast (Finset.mem_filter.mp hb).2 + apply (le_mul_inv_iff₀ (hp b)).mpr + calc + (F.degree b : ℝ)^2 * F.degree b = (F.degree b : ℝ)^3 := by ring + _ = ((F.degree b : ℝ)^8) ^ (3 / 8 : ℝ) := by + rw [← Real.rpow_natCast_mul (hp b).le] + norm_num + _ ≤ _ := Real.rpow_le_rpow (by positivity) hbD (by norm_num) + _ = (D : ℝ) ^ (3 / 8 : ℝ) * ∑ b ∈ s, (F.degree b : ℝ)⁻¹ := by + rw [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left hsmall (Real.rpow_nonneg (Nat.cast_nonneg D) _) + +/-- The integrated operator norm bound for an eight-fold block action +with a common probability mass function satisfying all eight coset caps. -/ +lemma eight_block_of_cap {G : Type} [Group G] [Fintype G] + (s : ℕ) (hs : 1 ≤ s) + {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (ψ : (Fin 8 → Equiv.Perm (Fin s)) →* G) + (ν : G → ℝ) (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) + (hcoset : ∀ (i : Fin 8) g, + ∑ h : Equiv.Perm (Fin s), ν (g * ψ (Pi.mulSingle i h)) ≤ + 4 * (Fintype.card (Equiv.Perm (Fin s)) : ℝ) / Fintype.card G) : + ‖LinearMap.toContinuousLinearMap (integrated ρ (fun g => (ν g : ℂ)))‖ ≤ + Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ) := by + let : Nontrivial E := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) ρ.asModule + have hD : (0 : ℝ) < Module.finrank ℂ E := by exact_mod_cast (Module.finrank_pos (R:=ℂ) (M:=E)) + let D := Module.finrank ℂ E + let F := Specht.symmetricFamily s + have hsum : (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2) ≤ + (D : ℝ) ^ (3 / 8 : ℝ) * C1 := by + refine (low_degree_first F D).trans (mul_le_mul_of_nonneg_left ?_ (by positivity)) + exact reciprocalFirst_le_C1 s hs + have hconst : 0 ≤ Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ) := by positivity + have hconst_sq : (Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ))^2 = + 8 * 4 * ((D : ℝ) ^ (3 / 8 : ℝ) * C1) / D := by + rw [mul_pow, Real.sq_sqrt (mul_nonneg (by norm_num) C1_nonneg), + ← Real.rpow_mul_natCast (Nat.cast_nonneg D)] + rw [show (-5 / 16 : ℝ) * (2 : ℕ) = (3 / 8 : ℝ) - 1 by norm_num, + Real.rpow_sub hD, Real.rpow_one] + ring + apply ContinuousLinearMap.opNorm_le_bound _ hconst + intro v + have hb := F.integrated_norm_sq ρ hu (Nat.ne_of_gt Module.finrank_pos) ψ ν 4 hν h1 + (by norm_num) (fun i g => by + convert hcoset i g using 1 + apply Finset.sum_congr rfl + intro h _ + congr 3 + funext j + by_cases hij : j = i <;> simp [hij]) v + simp only [Fintype.card_fin, Nat.cast_ofNat] at hb + have hv : ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ^ 2 ≤ + (Real.sqrt (32 * C1) * (D : ℝ) ^ (-5 / 16 : ℝ) * ‖v‖)^2 := by + rw [mul_pow, hconst_sq] + exact hb.trans (mul_le_mul_of_nonneg_right + (div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left hsum (by norm_num)) hD.le) (sq_nonneg _)) + change ‖integrated ρ (fun g => (ν g : ℂ)) v‖ ≤ _ + nlinarith [norm_nonneg (integrated ρ (fun g => (ν g : ℂ)) v), + mul_nonneg hconst (norm_nonneg v)] + +/-- The integrated operator norm bound for permutations of binary positions +under any equivalence with eight equal blocks. -/ +theorem eight_block_fourier_bound + (d : ℕ) (_hd : 3 ≤ d) + (e : Position d ≃ Fin 8 × Fin (2 ^ (d - 3))) + {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + (ρ : Representation ℂ (Equiv.Perm (Position d)) E) + [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (ν : Equiv.Perm (Position d) → ℝ) + (hν : ∀ g, 0 ≤ ν g) (h1 : ∑ g, ν g = 1) + (hcoset : ∀ (i : Fin 8) (g : Equiv.Perm (Position d)), + ∑ h : Equiv.Perm (Fin (2 ^ (d - 3))), + ν (g * Block.embedding e (Pi.mulSingle i h)) ≤ + 4 * (Fintype.card (Equiv.Perm (Fin (2 ^ (d - 3)))) : ℝ) / + Fintype.card (Equiv.Perm (Position d))) : + ‖LinearMap.toContinuousLinearMap (Fourier.integrated ρ (fun g => (ν g : ℂ)))‖ ≤ + Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ) := by + exact eight_block_of_cap (2 ^ (d - 3)) (Nat.one_le_pow _ _ (by norm_num)) ρ hu + (Block.embedding e) ν hν h1 hcoset + +end Thorp.Current + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FirstMain.lean b/lean/OAI/Probability/ThorpShuffle/FirstMain.lean index bea01810ccaf0a02f22e03b81479b0650fc88d85..16d534400804ba0f7ee07e4eae7c11f51fdb6149 100644 --- a/lean/OAI/Probability/ThorpShuffle/FirstMain.lean +++ b/lean/OAI/Probability/ThorpShuffle/FirstMain.lean @@ -1,39 +1,39 @@ -import OAI.Probability.ThorpShuffle.FirstFourier - -namespace OAI - -universe uE - -noncomputable section - -namespace Thorp.Current -open scoped BigOperators Classical ComplexConjugate InnerProductSpace -open Filter Topology - -theorem first_reciprocal_main : - (BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) ∧ - (∀ n : ℕ, 1 ≤ n → reciprocalFirst n ≤ C1) ∧ - Tendsto exceptionalFirst atTop (nhds 0)) ∧ - (∀ (d : ℕ) (_hd : 3 ≤ d) - (e : Position d ≃ Fin 8 × Fin (2 ^ (d - 3))) - {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - (ρ : Representation ℂ (Equiv.Perm (Position d)) E) - [Representation.IsIrreducible ρ] - (_ : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (ν : Equiv.Perm (Position d) → ℝ) - (_ : ∀ g, 0 ≤ ν g) (_ : ∑ g, ν g = 1) - (_ : ∀ (i : Fin 8) (g : Equiv.Perm (Position d)), - ∑ h : Equiv.Perm (Fin (2 ^ (d - 3))), - ν (g * Block.embedding e (Pi.mulSingle i h)) ≤ - 4 * (Fintype.card (Equiv.Perm (Fin (2 ^ (d - 3)))) : ℝ) / - Fintype.card (Equiv.Perm (Position d))), - ‖LinearMap.toContinuousLinearMap (Fourier.integrated ρ (fun g => (ν g : ℂ)))‖ ≤ - Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ)) := by - exact ⟨reciprocal_degrees, eight_block_fourier_bound⟩ - -end Thorp.Current - -end - -end OAI +import OAI.Probability.ThorpShuffle.FirstFourier + +namespace OAI + +universe uE + +noncomputable section + +namespace Thorp.Current +open scoped BigOperators Classical ComplexConjugate InnerProductSpace +open Filter Topology + +theorem first_reciprocal_main : + (BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) ∧ + (∀ n : ℕ, 1 ≤ n → reciprocalFirst n ≤ C1) ∧ + Tendsto exceptionalFirst atTop (nhds 0)) ∧ + (∀ (d : ℕ) (_hd : 3 ≤ d) + (e : Position d ≃ Fin 8 × Fin (2 ^ (d - 3))) + {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + (ρ : Representation ℂ (Equiv.Perm (Position d)) E) + [Representation.IsIrreducible ρ] + (_ : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (ν : Equiv.Perm (Position d) → ℝ) + (_ : ∀ g, 0 ≤ ν g) (_ : ∑ g, ν g = 1) + (_ : ∀ (i : Fin 8) (g : Equiv.Perm (Position d)), + ∑ h : Equiv.Perm (Fin (2 ^ (d - 3))), + ν (g * Block.embedding e (Pi.mulSingle i h)) ≤ + 4 * (Fintype.card (Equiv.Perm (Fin (2 ^ (d - 3)))) : ℝ) / + Fintype.card (Equiv.Perm (Position d))), + ‖LinearMap.toContinuousLinearMap (Fourier.integrated ρ (fun g => (ν g : ℂ)))‖ ≤ + Real.sqrt (32 * C1) * (Module.finrank ℂ E : ℝ) ^ (-5 / 16 : ℝ)) := by + exact ⟨reciprocal_degrees, eight_block_fourier_bound⟩ + +end Thorp.Current + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FirstMoment.lean b/lean/OAI/Probability/ThorpShuffle/FirstMoment.lean index f77e58520dbc372bcfc790dc923278b87966c34a..2cafec6e32bf34496bc17d191b682715c126397b 100644 --- a/lean/OAI/Probability/ThorpShuffle/FirstMoment.lean +++ b/lean/OAI/Probability/ThorpShuffle/FirstMoment.lean @@ -1,272 +1,272 @@ -import OAI.Probability.ThorpShuffle.ReciprocalDegrees - -namespace OAI - -noncomputable section - -namespace Thorp.Current -open scoped BigOperators Classical ComplexConjugate InnerProductSpace -open Filter Topology - -/-- The FIRST reciprocal degree moment of the concrete symmetric-group -irreducible family. `Specht.degree` is the actual complex dimension. -/ -def reciprocalFirst (n : ℕ) : ℝ := - ∑ p : Specht.NShape n, (Specht.degree p : ℝ)⁻¹ - -/-- Exactly the non-row, non-column shapes: defect is size minus the maximum -of first row length and first column length. For size≥1 defect=0 precisely -for the row or column; at size=1 they coincide and are counted once. -/ -def exceptionalFirst (n : ℕ) : ℝ := - ∑ p : Specht.NShape n, if 0 < Specht.defect p then (Specht.degree p : ℝ)⁻¹ else 0 - -/-- The supremum of the first reciprocal degree moments over positive sizes. Boundedness is proved in `reciprocal_degrees`. -/ -def C1 : ℝ := sSup (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) - -open Thorp.Specht Thorp.Young -variable {n : ℕ} - -lemma partition_first_exponential_decay : - Tendsto (fun n : ℕ => ((n : ℝ) + 1) ^ (2 * Nat.sqrt n) / (2 : ℝ) ^ (n / 16)) atTop (𝓝 0) := by - have hc : 0 < Real.log 2 / 256 := by positivity - have he := Thorp.Analysis.sqrt_log_small (Real.log 2 / 256) hc - have ht : Tendsto (fun n : ℕ => Real.exp (-(Real.log 2 / 64) * n)) atTop (𝓝 0) := by - apply Real.tendsto_exp_atBot.comp - exact tendsto_natCast_atTop_atTop.const_mul_atTop_of_neg (neg_neg_of_pos (by positivity)) - apply squeeze_zero' (Eventually.of_forall (fun n => by positivity)) _ ht - filter_upwards [he, eventually_ge_atTop 32] with n hn hn32 - have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast (show 1 ≤ n by omega) - have hs : (Nat.sqrt n : ℝ) ≤ Real.sqrt (n + 1) := by - apply Real.le_sqrt_of_sq_le - have hh : ((Nat.sqrt n : ℝ)^2) ≤ n := by exact_mod_cast (show (Nat.sqrt n)^2 ≤ n by simpa only [pow_two] using Nat.sqrt_le n) - linarith - have hdiv : (n : ℝ) / 32 ≤ (n / 16 : ℕ) := by - have hh : n ≤ 32 * (n / 16) := by omega - exact (div_le_iff₀ (by norm_num : (0 : ℝ) < 32)).mpr (by exact_mod_cast (by omega : n ≤ n / 16 * 32)) - have hp : 2 * (Nat.sqrt n : ℝ) * Real.log (n + 1) ≤ (Real.log 2 / 64) * n := by - have hl : 0 ≤ Real.log (n + 1) := Real.log_nonneg (by linarith) - have h₁ := mul_le_mul_of_nonneg_right hs hl - have h₂ := mul_le_mul_of_nonneg_left hn (Real.sqrt_nonneg ((n : ℝ) + 1)) - have hh := Real.sq_sqrt (by positivity : (0 : ℝ) ≤ n + 1) - have hc0 : 0 ≤ Real.log 2 / 256 := hc.le - have hsq : Real.sqrt (n + 1) * ((Real.log 2 / 256) * Real.sqrt (n + 1)) = (Real.log 2 / 256) * (n + 1) := by calc - _ = (Real.log 2 / 256) * (Real.sqrt (n + 1))^2 := by ring - _ = _ := by rw [hh] - rw [hsq] at h₂ - have h₃ := mul_le_mul_of_nonneg_left (show (n : ℝ) + 1 ≤ 2 * n by linarith) hc0 - linarith only [h₁, h₂, h₃] - have hq : -(Real.log 2 / 64) * n ≥ - (2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 2 := by - push_cast - have hh := mul_le_mul_of_nonneg_right hdiv (Real.log_nonneg (by norm_num : (1 : ℝ) ≤ 2)) - linarith - calc - _ = Real.exp ((2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 2) := by - rw [Real.exp_sub, Real.exp_nat_mul, Real.exp_nat_mul, Real.exp_log (by positivity), Real.exp_log (by norm_num : (0 : ℝ) < 2)] - _ ≤ _ := Real.exp_le_exp.mpr hq - - -def inverseFirst (p : NShape n) : ℝ := (degree p : ℝ)⁻¹ - -def slice (n u : ℕ) : ℝ := ∑ p : {p : NShape n // defect p = u}, inverseFirst p.val - -def smallSlice (n u : ℕ) : ℝ := if 0 < u ∧ 4 * u ≤ n then slice n u else 0 - - -lemma inverseFirst_nonneg (p : NShape n) : 0 ≤ inverseFirst p := by unfold inverseFirst; positivity -lemma slice_nonneg (n u : ℕ) : 0 ≤ slice n u := Finset.sum_nonneg (fun _ _ => inverseFirst_nonneg _) -lemma smallSlice_nonneg (n u : ℕ) : 0 ≤ smallSlice n u := by unfold smallSlice; split_ifs; exact slice_nonneg _ _; rfl - -lemma slice_bound (n u : ℕ) (K : ℝ) (hK : 0 < K) - (hk : ∀ p : NShape n, defect p = u → K ≤ degree p) : - slice n u ≤ (2 : ℝ)^(u+1) / K := by - have hI (p : {p : NShape n // defect p = u}) : inverseFirst p.val ≤ K⁻¹ := by - exact inv_anti₀ hK (hk p.val p.property) - calc - _ ≤ ∑ _ : {p : NShape n // defect p = u}, K⁻¹ := Finset.sum_le_sum (fun p _ => hI p) - _ = (Fintype.card {p : NShape n // defect p = u} : ℝ) * K⁻¹ := by simp - _ ≤ (2 : ℝ)^(u+1) * K⁻¹ := mul_le_mul_of_nonneg_right (by exact_mod_cast defect_card_bound n u) (by positivity) - _ = _ := rfl - -lemma smallSlice_bound (n u : ℕ) : smallSlice n u ≤ 2 * (2 / 3 : ℝ)^u := by - unfold smallSlice - split_ifs with h - · have hk : ∀ p : NShape n, defect p = u → (3 : ℝ)^u ≤ degree p := by - intro p hp - have hh := small_defect_degree p (by rw [hp]; exact h.2) - rw [hp] at hh - exact_mod_cast hh - have hh := slice_bound n u (3^u) (by positivity) hk - have he : (2 : ℝ)^(u+1) / 3^u = 2 * (2/3 :ℝ)^u := by - rw [pow_succ, div_pow] - ring - exact hh.trans_eq he - · positivity - -lemma smallSlice_tendsto (u : ℕ) : Tendsto (fun n => smallSlice n u) atTop (𝓝 0) := by - by_cases hu : 0 < u - · have ht : Tendsto (fun n : ℕ => ((n - 2*u + 1 : ℕ) : ℝ)) atTop atTop := by - exact (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop).comp - ((tendsto_add_atTop_nat 1).comp (tendsto_sub_atTop_nat (2*u))) - have hi : Tendsto (fun n : ℕ => (((n - 2*u + 1 : ℕ) : ℝ))⁻¹) atTop (𝓝 0) := - tendsto_inv_atTop_zero.comp ht - have he := hi.const_mul ((2 : ℝ)^(u+1)) - rw [mul_zero] at he - apply squeeze_zero' (Eventually.of_forall (fun n => smallSlice_nonneg n u)) _ he - filter_upwards [eventually_ge_atTop (4*u)] with n hn - rw [smallSlice, ite_eq_left ⟨hu, hn⟩] - exact slice_bound n u _ (by positivity) (fun p hp => by - have hh := fixed_defect_degree p (by rwa [hp]) (by rw [hp]; omega) - rw [hp] at hh - exact_mod_cast hh) - · simp only [smallSlice, hu, false_and, ↓reduceIte] - exact tendsto_const_nhds - -lemma smallSum_tendsto : Tendsto (fun n => ∑' u, smallSlice n u) atTop (𝓝 0) := by - have hs : Summable (fun u : ℕ => 2 * (2/3 : ℝ)^u) := - (summable_geometric_of_norm_lt_one (by norm_num : ‖(2/3 : ℝ)‖ < 1)).mul_left 2 - have h := tendsto_tsum_of_dominated_convergence hs smallSlice_tendsto - (Eventually.of_forall (fun n u => by rw [Real.norm_of_nonneg (smallSlice_nonneg n u)]; exact smallSlice_bound n u)) - simpa only [tsum_zero] using h - -end Thorp.Current - -namespace Thorp.Current -open scoped Classical -open Filter Topology Thorp.Young Thorp.Specht - -lemma smallSlice_as_sum (n u : ℕ) : - smallSlice n u = ∑ p : NShape n, - if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0 := by - unfold smallSlice slice - rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = u)) (by simp), Finset.sum_filter] - by_cases h : 0 < u ∧ 4 * u ≤ n - · rw [ite_eq_left h] - apply Finset.sum_congr rfl - intro p _ - by_cases hp : defect p = u - · simp only [hp, h.1, h.2, true_and, ↓reduceIte] - · simp only [hp, false_and, ↓reduceIte] - · rw [ite_eq_right h] - apply Eq.symm - apply Finset.sum_eq_zero - intro p _ - split_ifs with hp - · exact (h (by simpa only [hp.1] using hp.2)).elim - · rfl - -lemma smallSlice_support (n u : ℕ) (hu : u ∉ Finset.range (n+1)) : smallSlice n u = 0 := by - unfold smallSlice - have hh : ¬(0 < u ∧ 4*u ≤ n) := by have := (Finset.mem_range.not.mp hu); omega - exact ite_eq_right hh - -lemma smallSum_eq (n : ℕ) : - (∑' u, smallSlice n u) = ∑ p : NShape n, - if 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0 := by - rw [tsum_eq_sum (smallSlice_support n)] - simp_rw [smallSlice_as_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro p _ - have hd : defect p ∈ Finset.range (n+1) := Finset.mem_range.mpr (by have := defect_add_longest p; omega) - have he (u : ℕ) : (if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0) = - if defect p = u then (if 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0) else 0 := by - split_ifs <;> tauto - simp only [he, Finset.sum_ite_eq, hd, ↓reduceIte] - -lemma bulkSum_bound (n : ℕ) (hn : 0 < n) : - (∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) ≤ - ((n : ℝ)+1)^(2*Nat.sqrt n) / (2:ℝ)^(n/16) := by - have hb (p : NShape n) : (if n < 4*defect p then inverseFirst p else 0) ≤ ((2:ℝ)^(n/16))⁻¹ := by - by_cases hp : n < 4*defect p - · rw [ite_eq_left hp] - have hh := bulk_degree p hn hp - exact inv_anti₀ (by positivity) hh - · rw [ite_eq_right hp]; positivity - have hc : Fintype.card (NShape n) ≤ (n+1)^(2*Nat.sqrt n) := by - rw [Fintype.card_eq_nat_card] - change Nat.card (Nat.Partition (Fintype.card (Fin n))) ≤ _ - rw [Fintype.card_fin, ← Fintype.card_eq_nat_card] - exact partition_count_le_sqrt_pow n - calc - _ ≤ ∑ _ : NShape n, ((2:ℝ)^(n/16))⁻¹ := Finset.sum_le_sum (fun p _ => hb p) - _ = (Fintype.card (NShape n) : ℝ) * ((2:ℝ)^(n/16))⁻¹ := by simp - _ ≤ ((n:ℝ)+1)^(2*Nat.sqrt n) * ((2:ℝ)^(n/16))⁻¹ := - mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (by positivity) - _ = _ := rfl - -lemma exceptionalFirst_split (n : ℕ) : exceptionalFirst n = - (∑' u, smallSlice n u) + (∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) := by - unfold exceptionalFirst - change (∑ p : NShape n, if 0 < defect p then inverseFirst p else 0) = _ - rw [smallSum_eq, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro p _ - split_ifs <;> simp_all - all_goals omega - -/-- The contribution of positive-defect Specht modules tends to zero. -/ -theorem exceptionalFirst_tendsto : Tendsto exceptionalFirst atTop (𝓝 0) := by - have hb : Tendsto (fun n => ∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) atTop (𝓝 0) := by - apply squeeze_zero' (Eventually.of_forall (fun n => Finset.sum_nonneg (fun p _ => by split_ifs; exact inverseFirst_nonneg p; rfl))) - ((eventually_gt_atTop 0).mono (fun n hn => bulkSum_bound n hn)) Thorp.Current.partition_first_exponential_decay - have he : exceptionalFirst = (fun n => (∑' u, smallSlice n u) + ∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) := funext exceptionalFirst_split - rw [he] - simpa only [zero_add] using smallSum_tendsto.add hb - -end Thorp.Current - -namespace Thorp.Current -open scoped Classical -open Thorp.Specht Filter Topology - -lemma reciprocalFirst_nonneg (n : ℕ) : 0 ≤ reciprocalFirst n := - Finset.sum_nonneg (fun _p _ => inv_nonneg.mpr (Nat.cast_nonneg _)) - -lemma full_reciprocalFirst_bound (n : ℕ) : - reciprocalFirst n ≤ 2 + exceptionalFirst n := by - have hzero : slice n 0 ≤ 2 := by - have h := slice_bound n 0 1 (by norm_num) - (fun p _ => by exact_mod_cast degree_pos p) - norm_num at h - exact h - have he : reciprocalFirst n = slice n 0 + exceptionalFirst n := by - unfold slice - rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = 0)) - (by simp), Finset.sum_filter] - unfold exceptionalFirst reciprocalFirst - rw [← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro p _ - change inverseFirst p = _ - by_cases hp : defect p = 0 - · simp only [hp, lt_self_iff_false, ↓reduceIte, add_zero] - · simp only [hp, Nat.pos_of_ne_zero hp, ↓reduceIte, zero_add] - rfl - rw [he] - linarith - -/-- Uniform first-moment bound, including the finitely many initial sizes. -/ -lemma reciprocalFirst_bddAbove : - BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) := by - obtain ⟨B, hB⟩ := exceptionalFirst_tendsto.bddAbove_range - refine ⟨2 + B, ?_⟩ - rintro _ ⟨n, rfl⟩ - exact (full_reciprocalFirst_bound n).trans (add_le_add le_rfl (hB ⟨n.val, rfl⟩)) - -lemma reciprocalFirst_le_C1 (n : ℕ) (hn : 1 ≤ n) : reciprocalFirst n ≤ C1 := - le_csSup reciprocalFirst_bddAbove ⟨⟨n, hn⟩, rfl⟩ - -lemma C1_nonneg : 0 ≤ C1 := - (reciprocalFirst_nonneg 1).trans (reciprocalFirst_le_C1 1 le_rfl) - -theorem reciprocal_degrees : - BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) ∧ - (∀ n : ℕ, 1 ≤ n → reciprocalFirst n ≤ C1) ∧ - Tendsto exceptionalFirst atTop (nhds 0) := - ⟨reciprocalFirst_bddAbove, reciprocalFirst_le_C1, exceptionalFirst_tendsto⟩ - -end Thorp.Current - -end - -end OAI +import OAI.Probability.ThorpShuffle.ReciprocalDegrees + +namespace OAI + +noncomputable section + +namespace Thorp.Current +open scoped BigOperators Classical ComplexConjugate InnerProductSpace +open Filter Topology + +/-- The FIRST reciprocal degree moment of the concrete symmetric-group +irreducible family. `Specht.degree` is the actual complex dimension. -/ +def reciprocalFirst (n : ℕ) : ℝ := + ∑ p : Specht.NShape n, (Specht.degree p : ℝ)⁻¹ + +/-- Exactly the non-row, non-column shapes: defect is size minus the maximum +of first row length and first column length. For size≥1 defect=0 precisely +for the row or column; at size=1 they coincide and are counted once. -/ +def exceptionalFirst (n : ℕ) : ℝ := + ∑ p : Specht.NShape n, if 0 < Specht.defect p then (Specht.degree p : ℝ)⁻¹ else 0 + +/-- The supremum of the first reciprocal degree moments over positive sizes. Boundedness is proved in `reciprocal_degrees`. -/ +def C1 : ℝ := sSup (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) + +open Thorp.Specht Thorp.Young +variable {n : ℕ} + +lemma partition_first_exponential_decay : + Tendsto (fun n : ℕ => ((n : ℝ) + 1) ^ (2 * Nat.sqrt n) / (2 : ℝ) ^ (n / 16)) atTop (𝓝 0) := by + have hc : 0 < Real.log 2 / 256 := by positivity + have he := Thorp.Analysis.sqrt_log_small (Real.log 2 / 256) hc + have ht : Tendsto (fun n : ℕ => Real.exp (-(Real.log 2 / 64) * n)) atTop (𝓝 0) := by + apply Real.tendsto_exp_atBot.comp + exact tendsto_natCast_atTop_atTop.const_mul_atTop_of_neg (neg_neg_of_pos (by positivity)) + apply squeeze_zero' (Eventually.of_forall (fun n => by positivity)) _ ht + filter_upwards [he, eventually_ge_atTop 32] with n hn hn32 + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast (show 1 ≤ n by omega) + have hs : (Nat.sqrt n : ℝ) ≤ Real.sqrt (n + 1) := by + apply Real.le_sqrt_of_sq_le + have hh : ((Nat.sqrt n : ℝ)^2) ≤ n := by exact_mod_cast (show (Nat.sqrt n)^2 ≤ n by simpa only [pow_two] using Nat.sqrt_le n) + linarith + have hdiv : (n : ℝ) / 32 ≤ (n / 16 : ℕ) := by + have hh : n ≤ 32 * (n / 16) := by omega + exact (div_le_iff₀ (by norm_num : (0 : ℝ) < 32)).mpr (by exact_mod_cast (by omega : n ≤ n / 16 * 32)) + have hp : 2 * (Nat.sqrt n : ℝ) * Real.log (n + 1) ≤ (Real.log 2 / 64) * n := by + have hl : 0 ≤ Real.log (n + 1) := Real.log_nonneg (by linarith) + have h₁ := mul_le_mul_of_nonneg_right hs hl + have h₂ := mul_le_mul_of_nonneg_left hn (Real.sqrt_nonneg ((n : ℝ) + 1)) + have hh := Real.sq_sqrt (by positivity : (0 : ℝ) ≤ n + 1) + have hc0 : 0 ≤ Real.log 2 / 256 := hc.le + have hsq : Real.sqrt (n + 1) * ((Real.log 2 / 256) * Real.sqrt (n + 1)) = (Real.log 2 / 256) * (n + 1) := by calc + _ = (Real.log 2 / 256) * (Real.sqrt (n + 1))^2 := by ring + _ = _ := by rw [hh] + rw [hsq] at h₂ + have h₃ := mul_le_mul_of_nonneg_left (show (n : ℝ) + 1 ≤ 2 * n by linarith) hc0 + linarith only [h₁, h₂, h₃] + have hq : -(Real.log 2 / 64) * n ≥ + (2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 2 := by + push_cast + have hh := mul_le_mul_of_nonneg_right hdiv (Real.log_nonneg (by norm_num : (1 : ℝ) ≤ 2)) + linarith + calc + _ = Real.exp ((2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 2) := by + rw [Real.exp_sub, Real.exp_nat_mul, Real.exp_nat_mul, Real.exp_log (by positivity), Real.exp_log (by norm_num : (0 : ℝ) < 2)] + _ ≤ _ := Real.exp_le_exp.mpr hq + + +def inverseFirst (p : NShape n) : ℝ := (degree p : ℝ)⁻¹ + +def slice (n u : ℕ) : ℝ := ∑ p : {p : NShape n // defect p = u}, inverseFirst p.val + +def smallSlice (n u : ℕ) : ℝ := if 0 < u ∧ 4 * u ≤ n then slice n u else 0 + + +lemma inverseFirst_nonneg (p : NShape n) : 0 ≤ inverseFirst p := by unfold inverseFirst; positivity +lemma slice_nonneg (n u : ℕ) : 0 ≤ slice n u := Finset.sum_nonneg (fun _ _ => inverseFirst_nonneg _) +lemma smallSlice_nonneg (n u : ℕ) : 0 ≤ smallSlice n u := by unfold smallSlice; split_ifs; exact slice_nonneg _ _; rfl + +lemma slice_bound (n u : ℕ) (K : ℝ) (hK : 0 < K) + (hk : ∀ p : NShape n, defect p = u → K ≤ degree p) : + slice n u ≤ (2 : ℝ)^(u+1) / K := by + have hI (p : {p : NShape n // defect p = u}) : inverseFirst p.val ≤ K⁻¹ := by + exact inv_anti₀ hK (hk p.val p.property) + calc + _ ≤ ∑ _ : {p : NShape n // defect p = u}, K⁻¹ := Finset.sum_le_sum (fun p _ => hI p) + _ = (Fintype.card {p : NShape n // defect p = u} : ℝ) * K⁻¹ := by simp + _ ≤ (2 : ℝ)^(u+1) * K⁻¹ := mul_le_mul_of_nonneg_right (by exact_mod_cast defect_card_bound n u) (by positivity) + _ = _ := rfl + +lemma smallSlice_bound (n u : ℕ) : smallSlice n u ≤ 2 * (2 / 3 : ℝ)^u := by + unfold smallSlice + split_ifs with h + · have hk : ∀ p : NShape n, defect p = u → (3 : ℝ)^u ≤ degree p := by + intro p hp + have hh := small_defect_degree p (by rw [hp]; exact h.2) + rw [hp] at hh + exact_mod_cast hh + have hh := slice_bound n u (3^u) (by positivity) hk + have he : (2 : ℝ)^(u+1) / 3^u = 2 * (2/3 :ℝ)^u := by + rw [pow_succ, div_pow] + ring + exact hh.trans_eq he + · positivity + +lemma smallSlice_tendsto (u : ℕ) : Tendsto (fun n => smallSlice n u) atTop (𝓝 0) := by + by_cases hu : 0 < u + · have ht : Tendsto (fun n : ℕ => ((n - 2*u + 1 : ℕ) : ℝ)) atTop atTop := by + exact (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop).comp + ((tendsto_add_atTop_nat 1).comp (tendsto_sub_atTop_nat (2*u))) + have hi : Tendsto (fun n : ℕ => (((n - 2*u + 1 : ℕ) : ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp ht + have he := hi.const_mul ((2 : ℝ)^(u+1)) + rw [mul_zero] at he + apply squeeze_zero' (Eventually.of_forall (fun n => smallSlice_nonneg n u)) _ he + filter_upwards [eventually_ge_atTop (4*u)] with n hn + rw [smallSlice, ite_eq_left ⟨hu, hn⟩] + exact slice_bound n u _ (by positivity) (fun p hp => by + have hh := fixed_defect_degree p (by rwa [hp]) (by rw [hp]; omega) + rw [hp] at hh + exact_mod_cast hh) + · simp only [smallSlice, hu, false_and, ↓reduceIte] + exact tendsto_const_nhds + +lemma smallSum_tendsto : Tendsto (fun n => ∑' u, smallSlice n u) atTop (𝓝 0) := by + have hs : Summable (fun u : ℕ => 2 * (2/3 : ℝ)^u) := + (summable_geometric_of_norm_lt_one (by norm_num : ‖(2/3 : ℝ)‖ < 1)).mul_left 2 + have h := tendsto_tsum_of_dominated_convergence hs smallSlice_tendsto + (Eventually.of_forall (fun n u => by rw [Real.norm_of_nonneg (smallSlice_nonneg n u)]; exact smallSlice_bound n u)) + simpa only [tsum_zero] using h + +end Thorp.Current + +namespace Thorp.Current +open scoped Classical +open Filter Topology Thorp.Young Thorp.Specht + +lemma smallSlice_as_sum (n u : ℕ) : + smallSlice n u = ∑ p : NShape n, + if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0 := by + unfold smallSlice slice + rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = u)) (by simp), Finset.sum_filter] + by_cases h : 0 < u ∧ 4 * u ≤ n + · rw [ite_eq_left h] + apply Finset.sum_congr rfl + intro p _ + by_cases hp : defect p = u + · simp only [hp, h.1, h.2, true_and, ↓reduceIte] + · simp only [hp, false_and, ↓reduceIte] + · rw [ite_eq_right h] + apply Eq.symm + apply Finset.sum_eq_zero + intro p _ + split_ifs with hp + · exact (h (by simpa only [hp.1] using hp.2)).elim + · rfl + +lemma smallSlice_support (n u : ℕ) (hu : u ∉ Finset.range (n+1)) : smallSlice n u = 0 := by + unfold smallSlice + have hh : ¬(0 < u ∧ 4*u ≤ n) := by have := (Finset.mem_range.not.mp hu); omega + exact ite_eq_right hh + +lemma smallSum_eq (n : ℕ) : + (∑' u, smallSlice n u) = ∑ p : NShape n, + if 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0 := by + rw [tsum_eq_sum (smallSlice_support n)] + simp_rw [smallSlice_as_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro p _ + have hd : defect p ∈ Finset.range (n+1) := Finset.mem_range.mpr (by have := defect_add_longest p; omega) + have he (u : ℕ) : (if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0) = + if defect p = u then (if 0 < defect p ∧ 4 * defect p ≤ n then inverseFirst p else 0) else 0 := by + split_ifs <;> tauto + simp only [he, Finset.sum_ite_eq, hd, ↓reduceIte] + +lemma bulkSum_bound (n : ℕ) (hn : 0 < n) : + (∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) ≤ + ((n : ℝ)+1)^(2*Nat.sqrt n) / (2:ℝ)^(n/16) := by + have hb (p : NShape n) : (if n < 4*defect p then inverseFirst p else 0) ≤ ((2:ℝ)^(n/16))⁻¹ := by + by_cases hp : n < 4*defect p + · rw [ite_eq_left hp] + have hh := bulk_degree p hn hp + exact inv_anti₀ (by positivity) hh + · rw [ite_eq_right hp]; positivity + have hc : Fintype.card (NShape n) ≤ (n+1)^(2*Nat.sqrt n) := by + rw [Fintype.card_eq_nat_card] + change Nat.card (Nat.Partition (Fintype.card (Fin n))) ≤ _ + rw [Fintype.card_fin, ← Fintype.card_eq_nat_card] + exact partition_count_le_sqrt_pow n + calc + _ ≤ ∑ _ : NShape n, ((2:ℝ)^(n/16))⁻¹ := Finset.sum_le_sum (fun p _ => hb p) + _ = (Fintype.card (NShape n) : ℝ) * ((2:ℝ)^(n/16))⁻¹ := by simp + _ ≤ ((n:ℝ)+1)^(2*Nat.sqrt n) * ((2:ℝ)^(n/16))⁻¹ := + mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (by positivity) + _ = _ := rfl + +lemma exceptionalFirst_split (n : ℕ) : exceptionalFirst n = + (∑' u, smallSlice n u) + (∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) := by + unfold exceptionalFirst + change (∑ p : NShape n, if 0 < defect p then inverseFirst p else 0) = _ + rw [smallSum_eq, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + split_ifs <;> simp_all + all_goals omega + +/-- The contribution of positive-defect Specht modules tends to zero. -/ +theorem exceptionalFirst_tendsto : Tendsto exceptionalFirst atTop (𝓝 0) := by + have hb : Tendsto (fun n => ∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun n => Finset.sum_nonneg (fun p _ => by split_ifs; exact inverseFirst_nonneg p; rfl))) + ((eventually_gt_atTop 0).mono (fun n hn => bulkSum_bound n hn)) Thorp.Current.partition_first_exponential_decay + have he : exceptionalFirst = (fun n => (∑' u, smallSlice n u) + ∑ p : NShape n, if n < 4 * defect p then inverseFirst p else 0) := funext exceptionalFirst_split + rw [he] + simpa only [zero_add] using smallSum_tendsto.add hb + +end Thorp.Current + +namespace Thorp.Current +open scoped Classical +open Thorp.Specht Filter Topology + +lemma reciprocalFirst_nonneg (n : ℕ) : 0 ≤ reciprocalFirst n := + Finset.sum_nonneg (fun _p _ => inv_nonneg.mpr (Nat.cast_nonneg _)) + +lemma full_reciprocalFirst_bound (n : ℕ) : + reciprocalFirst n ≤ 2 + exceptionalFirst n := by + have hzero : slice n 0 ≤ 2 := by + have h := slice_bound n 0 1 (by norm_num) + (fun p _ => by exact_mod_cast degree_pos p) + norm_num at h + exact h + have he : reciprocalFirst n = slice n 0 + exceptionalFirst n := by + unfold slice + rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = 0)) + (by simp), Finset.sum_filter] + unfold exceptionalFirst reciprocalFirst + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + change inverseFirst p = _ + by_cases hp : defect p = 0 + · simp only [hp, lt_self_iff_false, ↓reduceIte, add_zero] + · simp only [hp, Nat.pos_of_ne_zero hp, ↓reduceIte, zero_add] + rfl + rw [he] + linarith + +/-- Uniform first-moment bound, including the finitely many initial sizes. -/ +lemma reciprocalFirst_bddAbove : + BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) := by + obtain ⟨B, hB⟩ := exceptionalFirst_tendsto.bddAbove_range + refine ⟨2 + B, ?_⟩ + rintro _ ⟨n, rfl⟩ + exact (full_reciprocalFirst_bound n).trans (add_le_add le_rfl (hB ⟨n.val, rfl⟩)) + +lemma reciprocalFirst_le_C1 (n : ℕ) (hn : 1 ≤ n) : reciprocalFirst n ≤ C1 := + le_csSup reciprocalFirst_bddAbove ⟨⟨n, hn⟩, rfl⟩ + +lemma C1_nonneg : 0 ≤ C1 := + (reciprocalFirst_nonneg 1).trans (reciprocalFirst_le_C1 1 le_rfl) + +theorem reciprocal_degrees : + BddAbove (Set.range (fun n : {n : ℕ // 1 ≤ n} => reciprocalFirst n.val)) ∧ + (∀ n : ℕ, 1 ≤ n → reciprocalFirst n ≤ C1) ∧ + Tendsto exceptionalFirst atTop (nhds 0) := + ⟨reciprocalFirst_bddAbove, reciprocalFirst_le_C1, exceptionalFirst_tendsto⟩ + +end Thorp.Current + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/Asymptotics.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/Asymptotics.lean index 88e8269fea2f0f481a556cfa9ab582820ff2a434..d8cf37c008b91533b8389bdda614573238bb232d 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/Asymptotics.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/Asymptotics.lean @@ -1,97 +1,97 @@ -import OAI.Probability.ThorpShuffle.FixedLists.Energy - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter -namespace Thorp.FixedLists - -def energyEnvelope (C d : ℕ) : ℝ := - (63 / 64 : ℝ) ^ (C * (d + 4)) + 64 * (9 / 10 : ℝ) ^ (2 ^ d) - -lemma energyEnvelope_nonneg (C d : ℕ) : 0 ≤ energyEnvelope C d := by - unfold energyEnvelope - positivity - -lemma geometric_base_256 : (2 : ℝ) ^ 3 * (63 / 64 : ℝ) ^ 254 < 1 := by - have h : (63 / 64 : ℝ) ^ 64 ≤ 1 / 2 := by norm_num - have h' : (63 / 64 : ℝ) ^ 192 ≤ (1 / 2) ^ 3 := by - rw [show 192 = 64 * 3 by norm_num, pow_mul] - exact pow_le_pow_left₀ (by positivity) h 3 - have h'' : (63 / 64 : ℝ) ^ 254 ≤ (63 / 64 : ℝ) ^ 193 := - pow_le_pow_of_le_one (by norm_num) (by norm_num) (by norm_num) - have h''' : (63 / 64 : ℝ) ^ 193 ≤ (1 / 2) ^ 3 * (63 / 64) := by - rw [show 193 = 192 + 1 by norm_num, pow_succ] - exact mul_le_mul_of_nonneg_right h' (by norm_num) - have he := h''.trans h''' - calc - _ ≤ (2 : ℝ) ^ 3 * ((1 / 2) ^ 3 * (63 / 64)) := - mul_le_mul_of_nonneg_left he (by norm_num) - _ < 1 := by norm_num - -lemma geometric_base_1024 : (2 : ℝ) ^ 6 * (63 / 64 : ℝ) ^ 1022 < 1 := by - have h : (63 / 64 : ℝ) ^ 64 ≤ 1 / 2 := by norm_num - have h' : (63 / 64 : ℝ) ^ 448 ≤ (1 / 2) ^ 7 := by - rw [show 448 = 64 * 7 by norm_num, pow_mul] - exact pow_le_pow_left₀ (by positivity) h 7 - have h'' : (63 / 64 : ℝ) ^ 1022 ≤ (63 / 64 : ℝ) ^ 448 := - pow_le_pow_of_le_one (by norm_num) (by norm_num) (by norm_num) - have hb : (1 / 2 : ℝ) ^ 7 = 1 / 128 := by norm_num - rw [hb] at h' - calc - _ ≤ (2 : ℝ) ^ 6 * (1 / 128 : ℝ) := mul_le_mul_of_nonneg_left (h''.trans h') (by norm_num) - _ < 1 := by norm_num - -lemma scaledEnergy_tendsto (C p : ℕ) - (hbase : (2 : ℝ) ^ p * (63 / 64 : ℝ) ^ C < 1) : - Tendsto (fun d : ℕ => ((2 : ℝ) ^ (d + 4)) ^ p * energyEnvelope C d) - atTop (nhds 0) := by - have h₁ := (tendsto_pow_atTop_nhds_zero_of_lt_one - (by positivity : (0 : ℝ) ≤ 2 ^ p * (63 / 64 : ℝ) ^ C) hbase).comp - (tendsto_add_atTop_nat 4) - have h₂ := (tendsto_pow_const_mul_const_pow_of_lt_one p - (by norm_num : (0 : ℝ) ≤ 9 / 10) (by norm_num : (9 / 10 : ℝ) < 1)).comp - (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) - have hh := h₁.add (h₂.const_mul (64 * (16 : ℝ) ^ p)) - convert hh using 1 - · funext d - simp only [energyEnvelope, Function.comp_def, Nat.cast_pow, Nat.cast_ofNat] - rw [mul_add] - congr 1 - · rw [← pow_mul, Nat.mul_comm (d + 4) p, pow_mul, pow_mul, ← mul_pow] - · rw [pow_add, mul_pow] - norm_num - ring - · simp - -def listRate (d : ℕ) : ℝ := - Real.sqrt (((2 : ℝ) ^ (d + 4)) ^ 3 * energyEnvelope 254 d) - -lemma listRate_tendsto : Tendsto listRate atTop (nhds 0) := by - unfold listRate - simpa only [Real.sqrt_zero] using (scaledEnergy_tendsto 254 3 geometric_base_256).sqrt - -lemma scalar_tv_finish (n a : ℝ) (hn : 0 < n) (ha : 0 ≤ a) - (h : n ^ 6 * a ≤ 2) : n / 2 * Real.sqrt (n * a) ≤ Real.rpow n (-(3 : ℝ) / 2) := by - simp only [Real.rpow_eq_pow] - have hr : (n ^ (-(3 : ℝ) / 2)) ^ (2 : ℕ) = 1 / n ^ 3 := by - rw [← Real.rpow_mul_natCast hn.le] - norm_num only [Nat.cast_ofNat, neg_div, div_mul_cancel₀ _ (by norm_num : (2 : ℝ) ≠ 0)] - rw [Real.rpow_neg hn.le, Real.rpow_ofNat] - simp only [one_div] - apply (sq_le_sq₀ (by positivity) (Real.rpow_nonneg hn.le _)).mp - rw [hr] - apply (le_div_iff₀ (pow_pos hn 3)).mpr - calc - (n / 2 * Real.sqrt (n * a)) ^ 2 * n ^ 3 = n ^ 6 * a / 4 := by - rw [mul_pow, div_pow, Real.sq_sqrt (mul_nonneg hn.le ha)] - ring - _ ≤ 1 := by linarith - -end Thorp.FixedLists - -end - -end OAI +import OAI.Probability.ThorpShuffle.FixedLists.Energy + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter +namespace Thorp.FixedLists + +def energyEnvelope (C d : ℕ) : ℝ := + (63 / 64 : ℝ) ^ (C * (d + 4)) + 64 * (9 / 10 : ℝ) ^ (2 ^ d) + +lemma energyEnvelope_nonneg (C d : ℕ) : 0 ≤ energyEnvelope C d := by + unfold energyEnvelope + positivity + +lemma geometric_base_256 : (2 : ℝ) ^ 3 * (63 / 64 : ℝ) ^ 254 < 1 := by + have h : (63 / 64 : ℝ) ^ 64 ≤ 1 / 2 := by norm_num + have h' : (63 / 64 : ℝ) ^ 192 ≤ (1 / 2) ^ 3 := by + rw [show 192 = 64 * 3 by norm_num, pow_mul] + exact pow_le_pow_left₀ (by positivity) h 3 + have h'' : (63 / 64 : ℝ) ^ 254 ≤ (63 / 64 : ℝ) ^ 193 := + pow_le_pow_of_le_one (by norm_num) (by norm_num) (by norm_num) + have h''' : (63 / 64 : ℝ) ^ 193 ≤ (1 / 2) ^ 3 * (63 / 64) := by + rw [show 193 = 192 + 1 by norm_num, pow_succ] + exact mul_le_mul_of_nonneg_right h' (by norm_num) + have he := h''.trans h''' + calc + _ ≤ (2 : ℝ) ^ 3 * ((1 / 2) ^ 3 * (63 / 64)) := + mul_le_mul_of_nonneg_left he (by norm_num) + _ < 1 := by norm_num + +lemma geometric_base_1024 : (2 : ℝ) ^ 6 * (63 / 64 : ℝ) ^ 1022 < 1 := by + have h : (63 / 64 : ℝ) ^ 64 ≤ 1 / 2 := by norm_num + have h' : (63 / 64 : ℝ) ^ 448 ≤ (1 / 2) ^ 7 := by + rw [show 448 = 64 * 7 by norm_num, pow_mul] + exact pow_le_pow_left₀ (by positivity) h 7 + have h'' : (63 / 64 : ℝ) ^ 1022 ≤ (63 / 64 : ℝ) ^ 448 := + pow_le_pow_of_le_one (by norm_num) (by norm_num) (by norm_num) + have hb : (1 / 2 : ℝ) ^ 7 = 1 / 128 := by norm_num + rw [hb] at h' + calc + _ ≤ (2 : ℝ) ^ 6 * (1 / 128 : ℝ) := mul_le_mul_of_nonneg_left (h''.trans h') (by norm_num) + _ < 1 := by norm_num + +lemma scaledEnergy_tendsto (C p : ℕ) + (hbase : (2 : ℝ) ^ p * (63 / 64 : ℝ) ^ C < 1) : + Tendsto (fun d : ℕ => ((2 : ℝ) ^ (d + 4)) ^ p * energyEnvelope C d) + atTop (nhds 0) := by + have h₁ := (tendsto_pow_atTop_nhds_zero_of_lt_one + (by positivity : (0 : ℝ) ≤ 2 ^ p * (63 / 64 : ℝ) ^ C) hbase).comp + (tendsto_add_atTop_nat 4) + have h₂ := (tendsto_pow_const_mul_const_pow_of_lt_one p + (by norm_num : (0 : ℝ) ≤ 9 / 10) (by norm_num : (9 / 10 : ℝ) < 1)).comp + (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) + have hh := h₁.add (h₂.const_mul (64 * (16 : ℝ) ^ p)) + convert hh using 1 + · funext d + simp only [energyEnvelope, Function.comp_def, Nat.cast_pow, Nat.cast_ofNat] + rw [mul_add] + congr 1 + · rw [← pow_mul, Nat.mul_comm (d + 4) p, pow_mul, pow_mul, ← mul_pow] + · rw [pow_add, mul_pow] + norm_num + ring + · simp + +def listRate (d : ℕ) : ℝ := + Real.sqrt (((2 : ℝ) ^ (d + 4)) ^ 3 * energyEnvelope 254 d) + +lemma listRate_tendsto : Tendsto listRate atTop (nhds 0) := by + unfold listRate + simpa only [Real.sqrt_zero] using (scaledEnergy_tendsto 254 3 geometric_base_256).sqrt + +lemma scalar_tv_finish (n a : ℝ) (hn : 0 < n) (ha : 0 ≤ a) + (h : n ^ 6 * a ≤ 2) : n / 2 * Real.sqrt (n * a) ≤ Real.rpow n (-(3 : ℝ) / 2) := by + simp only [Real.rpow_eq_pow] + have hr : (n ^ (-(3 : ℝ) / 2)) ^ (2 : ℕ) = 1 / n ^ 3 := by + rw [← Real.rpow_mul_natCast hn.le] + norm_num only [Nat.cast_ofNat, neg_div, div_mul_cancel₀ _ (by norm_num : (2 : ℝ) ≠ 0)] + rw [Real.rpow_neg hn.le, Real.rpow_ofNat] + simp only [one_div] + apply (sq_le_sq₀ (by positivity) (Real.rpow_nonneg hn.le _)).mp + rw [hr] + apply (le_div_iff₀ (pow_pos hn 3)).mpr + calc + (n / 2 * Real.sqrt (n * a)) ^ 2 * n ^ 3 = n ^ 6 * a / 4 := by + rw [mul_pow, div_pow, Real.sq_sqrt (mul_nonneg hn.le ha)] + ring + _ ≤ 1 := by linarith + +end Thorp.FixedLists + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/Energy.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/Energy.lean index 59ffb067058c7e017cf08c023610cad7a445ac47..b4cf2b0782774e696bfe9e2aa075e04c3dc69f45 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/Energy.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/Energy.lean @@ -1,160 +1,160 @@ -import OAI.Probability.ThorpShuffle.Main - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter -namespace Thorp -namespace Conditional - -theorem halfDensity_after_step_sixteen (d : ℕ) (v : RawState (d + 1)) - (c : Coins (d + 1)) (h : Bool) - (hm : Fintype.card (Position (d + 1)) ≤ 16 * freeCount v.free) - (hc : freeCount v.free ≤ 4 * pairHalfCount (v.free ∘ (splitPosition d).symm) c h) : - (1 / 32 : ℝ) ≤ startHalfDensity d (rawNext d v c) h := by - unfold startHalfDensity - rw [halfCount_after_step] - have hn : Fintype.card (Position (d + 1)) = 2 * Fintype.card (Position d) := by - simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin, pow_succ, Nat.mul_comm] - rw [hn] at hm - have hm' : (2 : ℝ) * Fintype.card (Position d) ≤ 16 * (freeCount v.free : ℝ) := by - exact_mod_cast hm - have hc' : (freeCount v.free : ℝ) ≤ - 4 * (pairHalfCount (v.free ∘ (splitPosition d).symm) c h : ℝ) := by exact_mod_cast hc - apply (le_div_iff₀ (by exact_mod_cast Fintype.card_pos (α := Position d))).mpr - nlinarith - -theorem expectedNoise_dimension_sixteen (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) : - expectedNoise (d + 1) v (d + 2) ≤ (31 / 32 : ℝ) * expectedEnergy (d + 1) v (d + 2) + - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - let B := v.free ∘ (splitPosition (d + 1)).symm - let bad (c : Coins (d + 2)) : Prop := - 4 * pairHalfCount B c false < pairFreeCount B ∨ - 4 * pairHalfCount B c true < pairFreeCount B - have hlocal (c : Coins (d + 2)) : - expectedNoise (d + 1) (nextState (d + 1) v c) (d + 1) ≤ - (31 / 32 : ℝ) * expectedEnergy (d + 1) (nextState (d + 1) v c) (d + 1) + - (if bad c then 1 else 0) := by - by_cases hc : bad c - · rw [ite_eq_left hc] - have hle := expectedNoise_le_energy (d + 1) (nextState (d + 1) v c) (d + 1) - have hone := expectedEnergy_le_one (d + 1) (nextState (d + 1) v c) (d + 1) - linarith - · rw [ite_eq_right hc, add_zero] - have hb (h : Bool) : (1 / 32 : ℝ) ≤ - startHalfDensity (d + 1) (nextState (d + 1) v c).raw h := by - apply halfDensity_after_step_sixteen (d + 1) v.raw c h hm - have hf : ¬ 4 * pairHalfCount B c false < freeCount v.free := by - simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.1 - have ht : ¬ 4 * pairHalfCount B c true < freeCount v.free := by - simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.2 - change freeCount v.free ≤ 4 * pairHalfCount B c h - cases h - · exact Nat.le_of_not_gt hf - · exact Nat.le_of_not_gt ht - convert noise_bound_balanced_state d (nextState (d + 1) v c) (1 / 32) hb using 1; norm_num - have hmean := mean_le_mean hlocal - rw [mean_add, mean_const_mul, ← expectedNoise_first, ← expectedEnergy_first] at hmean - have hbad := pair_both_half_balance B - have hbad' : mean (fun c : Coins (d + 2) => if bad c then (1 : ℝ) else 0) ≤ - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - change mean (fun c : Position (d + 1) → Bool => if bad c then (1 : ℝ) else 0) ≤ _ - simpa only [bad, B, pairFreeCount_physical] using hbad - exact hmean.trans (add_le_add (le_refl _) hbad') - -theorem expectedNoise_bound_sixteen (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) - (s : ℕ) (hs : d + 2 ≤ s) : - expectedNoise (d + 1) v s ≤ (31 / 32 : ℝ) * expectedEnergy (d + 1) v s + - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hs - rw [Nat.add_comm (d + 2) a, expectedNoise_add, expectedEnergy_add] - have he := mean_le_mean (fun ω : History (d + 2) a => - expectedNoise_dimension_sixteen d (iterateState (d + 1) v a ω) - (by simpa only [iterateState_freeCount] using hm)) - simpa only [iterateState_freeCount, mean_add, mean_const_mul, mean_const] using he - -theorem expectedEnergy_decay_sixteen (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) (t : ℕ) : - expectedEnergy (d + 1) v t ≤ - (63 / 64 : ℝ) ^ t / (63 / 64 : ℝ) ^ (2 * (d + 2)) + - 64 * (9 / 10 : ℝ) ^ freeCount v.free := by - have he := scalar_decay (d + 2) (expectedEnergy (d + 1) v) - (expectedNoise (d + 1) v) (1 / 32) (63 / 64) - (2 * (9 / 10 : ℝ) ^ freeCount v.free) - (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by norm_num) (by positivity) (expectedEnergy_le_one (d + 1) v) - (expectedEnergy_recurrence (d + 1) v) - (by intro s hs; convert expectedNoise_bound_sixteen d v hm s hs using 1; norm_num) t - convert he using 1; ring - -theorem expectedEnergy_long (d C : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) : - expectedEnergy (d + 1) v ((C + 2) * (d + 2)) ≤ - (63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ freeCount v.free := by - have he := expectedEnergy_decay_sixteen d v hm ((C + 2) * (d + 2)) - rw [Nat.add_mul, pow_add, mul_div_cancel_right₀ _ (by positivity)] at he - simpa only [Nat.add_mul] using he - -theorem prefix_test_bound_sixteen (d C m : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) - (k : ℕ) (hk : k + m ≤ Fintype.card (Position (d + 2))) - (e : Fin k → Position (d + 2)) (he : Function.Injective e) - (f : (Fin k → Position (d + 2)) → ℝ) (hf : ∀ z, |f z| ≤ 1) : - |mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ e)) - - mean (fun g : State (d + 2) => f (g ∘ e))| ≤ - (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by - induction k with - | zero => - have hz (g : State (d + 2)) : g ∘ e = e := by funext i; exact Fin.elim0 i - simp only [hz, mean_const, sub_self, abs_zero, Nat.cast_zero, zero_mul, le_refl] - | 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) - have hcount : m ≤ freeCount (freeOf (Fin.init e)) := by - rw [freeCount_freeOf _ he0] - omega - have henergy := expectedEnergy_long d C - (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) (by - change Fintype.card (Position (d + 2)) ≤ 16 * freeCount (freeOf (Fin.init e)) - omega) - have hpower : (9 / 10 : ℝ) ^ freeCount (freeOf (Fin.init e)) ≤ (9 / 10 : ℝ) ^ m := - pow_le_pow_of_le_one (by norm_num) (by norm_num) hcount - have hz := prefix_one_step_bound (d + 1) ((C + 2) * (d + 2)) k e he f hf - have hestimate : - Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - expectedEnergy (d + 1) (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) - ((C + 2) * (d + 2))) ≤ - Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by - apply Real.sqrt_le_sqrt - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - exact henergy.trans (add_le_add (le_refl _) (mul_le_mul_of_nonneg_left hpower (by norm_num : (0 : ℝ) ≤ 64))) - have hnext := ih (by omega) (Fin.init e) he0 (completeTest f) (completeTest_bound f hf) - rw [uniform_prefix_step k e he f] - have htri := abs_sub_le - (mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ e))) - (mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - completeTest f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ Fin.init e))) - (mean (fun g : State (d + 2) => completeTest f (g ∘ Fin.init e))) - have hz' := hz.trans hestimate - push_cast - nlinarith - -end Conditional -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Main + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter +namespace Thorp +namespace Conditional + +theorem halfDensity_after_step_sixteen (d : ℕ) (v : RawState (d + 1)) + (c : Coins (d + 1)) (h : Bool) + (hm : Fintype.card (Position (d + 1)) ≤ 16 * freeCount v.free) + (hc : freeCount v.free ≤ 4 * pairHalfCount (v.free ∘ (splitPosition d).symm) c h) : + (1 / 32 : ℝ) ≤ startHalfDensity d (rawNext d v c) h := by + unfold startHalfDensity + rw [halfCount_after_step] + have hn : Fintype.card (Position (d + 1)) = 2 * Fintype.card (Position d) := by + simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin, pow_succ, Nat.mul_comm] + rw [hn] at hm + have hm' : (2 : ℝ) * Fintype.card (Position d) ≤ 16 * (freeCount v.free : ℝ) := by + exact_mod_cast hm + have hc' : (freeCount v.free : ℝ) ≤ + 4 * (pairHalfCount (v.free ∘ (splitPosition d).symm) c h : ℝ) := by exact_mod_cast hc + apply (le_div_iff₀ (by exact_mod_cast Fintype.card_pos (α := Position d))).mpr + nlinarith + +theorem expectedNoise_dimension_sixteen (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) : + expectedNoise (d + 1) v (d + 2) ≤ (31 / 32 : ℝ) * expectedEnergy (d + 1) v (d + 2) + + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + let B := v.free ∘ (splitPosition (d + 1)).symm + let bad (c : Coins (d + 2)) : Prop := + 4 * pairHalfCount B c false < pairFreeCount B ∨ + 4 * pairHalfCount B c true < pairFreeCount B + have hlocal (c : Coins (d + 2)) : + expectedNoise (d + 1) (nextState (d + 1) v c) (d + 1) ≤ + (31 / 32 : ℝ) * expectedEnergy (d + 1) (nextState (d + 1) v c) (d + 1) + + (if bad c then 1 else 0) := by + by_cases hc : bad c + · rw [ite_eq_left hc] + have hle := expectedNoise_le_energy (d + 1) (nextState (d + 1) v c) (d + 1) + have hone := expectedEnergy_le_one (d + 1) (nextState (d + 1) v c) (d + 1) + linarith + · rw [ite_eq_right hc, add_zero] + have hb (h : Bool) : (1 / 32 : ℝ) ≤ + startHalfDensity (d + 1) (nextState (d + 1) v c).raw h := by + apply halfDensity_after_step_sixteen (d + 1) v.raw c h hm + have hf : ¬ 4 * pairHalfCount B c false < freeCount v.free := by + simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.1 + have ht : ¬ 4 * pairHalfCount B c true < freeCount v.free := by + simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.2 + change freeCount v.free ≤ 4 * pairHalfCount B c h + cases h + · exact Nat.le_of_not_gt hf + · exact Nat.le_of_not_gt ht + convert noise_bound_balanced_state d (nextState (d + 1) v c) (1 / 32) hb using 1; norm_num + have hmean := mean_le_mean hlocal + rw [mean_add, mean_const_mul, ← expectedNoise_first, ← expectedEnergy_first] at hmean + have hbad := pair_both_half_balance B + have hbad' : mean (fun c : Coins (d + 2) => if bad c then (1 : ℝ) else 0) ≤ + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + change mean (fun c : Position (d + 1) → Bool => if bad c then (1 : ℝ) else 0) ≤ _ + simpa only [bad, B, pairFreeCount_physical] using hbad + exact hmean.trans (add_le_add (le_refl _) hbad') + +theorem expectedNoise_bound_sixteen (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) + (s : ℕ) (hs : d + 2 ≤ s) : + expectedNoise (d + 1) v s ≤ (31 / 32 : ℝ) * expectedEnergy (d + 1) v s + + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hs + rw [Nat.add_comm (d + 2) a, expectedNoise_add, expectedEnergy_add] + have he := mean_le_mean (fun ω : History (d + 2) a => + expectedNoise_dimension_sixteen d (iterateState (d + 1) v a ω) + (by simpa only [iterateState_freeCount] using hm)) + simpa only [iterateState_freeCount, mean_add, mean_const_mul, mean_const] using he + +theorem expectedEnergy_decay_sixteen (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) (t : ℕ) : + expectedEnergy (d + 1) v t ≤ + (63 / 64 : ℝ) ^ t / (63 / 64 : ℝ) ^ (2 * (d + 2)) + + 64 * (9 / 10 : ℝ) ^ freeCount v.free := by + have he := scalar_decay (d + 2) (expectedEnergy (d + 1) v) + (expectedNoise (d + 1) v) (1 / 32) (63 / 64) + (2 * (9 / 10 : ℝ) ^ freeCount v.free) + (by norm_num) (by norm_num) (by norm_num) (by norm_num) + (by norm_num) (by positivity) (expectedEnergy_le_one (d + 1) v) + (expectedEnergy_recurrence (d + 1) v) + (by intro s hs; convert expectedNoise_bound_sixteen d v hm s hs using 1; norm_num) t + convert he using 1; ring + +theorem expectedEnergy_long (d C : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * freeCount v.free) : + expectedEnergy (d + 1) v ((C + 2) * (d + 2)) ≤ + (63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ freeCount v.free := by + have he := expectedEnergy_decay_sixteen d v hm ((C + 2) * (d + 2)) + rw [Nat.add_mul, pow_add, mul_div_cancel_right₀ _ (by positivity)] at he + simpa only [Nat.add_mul] using he + +theorem prefix_test_bound_sixteen (d C m : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) + (k : ℕ) (hk : k + m ≤ Fintype.card (Position (d + 2))) + (e : Fin k → Position (d + 2)) (he : Function.Injective e) + (f : (Fin k → Position (d + 2)) → ℝ) (hf : ∀ z, |f z| ≤ 1) : + |mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ e)) - + mean (fun g : State (d + 2) => f (g ∘ e))| ≤ + (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by + induction k with + | zero => + have hz (g : State (d + 2)) : g ∘ e = e := by funext i; exact Fin.elim0 i + simp only [hz, mean_const, sub_self, abs_zero, Nat.cast_zero, zero_mul, le_refl] + | 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) + have hcount : m ≤ freeCount (freeOf (Fin.init e)) := by + rw [freeCount_freeOf _ he0] + omega + have henergy := expectedEnergy_long d C + (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) (by + change Fintype.card (Position (d + 2)) ≤ 16 * freeCount (freeOf (Fin.init e)) + omega) + have hpower : (9 / 10 : ℝ) ^ freeCount (freeOf (Fin.init e)) ≤ (9 / 10 : ℝ) ^ m := + pow_le_pow_of_le_one (by norm_num) (by norm_num) hcount + have hz := prefix_one_step_bound (d + 1) ((C + 2) * (d + 2)) k e he f hf + have hestimate : + Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + expectedEnergy (d + 1) (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) + ((C + 2) * (d + 2))) ≤ + Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by + apply Real.sqrt_le_sqrt + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + exact henergy.trans (add_le_add (le_refl _) (mul_le_mul_of_nonneg_left hpower (by norm_num : (0 : ℝ) ≤ 64))) + have hnext := ih (by omega) (Fin.init e) he0 (completeTest f) (completeTest_bound f hf) + rw [uniform_prefix_step k e he f] + have htri := abs_sub_le + (mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ e))) + (mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + completeTest f ((run (d + 2) ((C + 2) * (d + 2)) ω) ∘ Fin.init e))) + (mean (fun g : State (d + 2) => completeTest f (g ∘ Fin.init e))) + have hz' := hz.trans hestimate + push_cast + nlinarith + +end Conditional +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/FullDeck.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/FullDeck.lean index 07feb6a7c4ca7158eeb150288ef44e8102c39ee7..f7dceafa63853180768f4e5a5461be88dda577e5 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/FullDeck.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/FullDeck.lean @@ -1,32 +1,32 @@ -import OAI.Probability.ThorpShuffle.Main - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter -namespace Thorp - -lemma distance_add_le (d s t : ℕ) : distance d (s + t) ≤ distance d s := by - unfold distance - rw [law_add] - have h := FiniteLaw.tv_conv_contract (law d t) (law d s) - (law_sum d t) (law_sum d s) 0 (law_nonneg d t) - change tv (FiniteLaw.conv (law d t) (law d s)) - (fun _ => (1 : ℝ) / Fintype.card (State d)) ≤ - tv (law d s) (fun _ => (1 : ℝ) / Fintype.card (State d)) - simpa only [mul_zero, sub_zero, one_mul] using h - -theorem full_mixing_2048 : - Tendsto (fun d : ℕ => distance d (2048 * d)) atTop (nhds 0) := by - apply squeeze_zero (fun d => by unfold distance tv; positivity) _ full_mixing - intro d - rw [show 2048 * d = 1600 * d + 448 * d by omega] - exact distance_add_le d (1600 * d) (448 * d) - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Main + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter +namespace Thorp + +lemma distance_add_le (d s t : ℕ) : distance d (s + t) ≤ distance d s := by + unfold distance + rw [law_add] + have h := FiniteLaw.tv_conv_contract (law d t) (law d s) + (law_sum d t) (law_sum d s) 0 (law_nonneg d t) + change tv (FiniteLaw.conv (law d t) (law d s)) + (fun _ => (1 : ℝ) / Fintype.card (State d)) ≤ + tv (law d s) (fun _ => (1 : ℝ) / Fintype.card (State d)) + simpa only [mul_zero, sub_zero, one_mul] using h + +theorem full_mixing_2048 : + Tendsto (fun d : ℕ => distance d (2048 * d)) atTop (nhds 0) := by + apply squeeze_zero (fun d => by unfold distance tv; positivity) _ full_mixing + intro d + rw [show 2048 * d = 1600 * d + 448 * d by omega] + exact distance_add_le d (1600 * d) (448 * d) + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/Lists.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/Lists.lean index 8faa4d280463676fa4c9446c43ea9ab543f987a2..0ccf2197ed7451383062f202309934152010a06e 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/Lists.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/Lists.lean @@ -1,142 +1,142 @@ -import OAI.Probability.ThorpShuffle.FixedLists.Objects -import OAI.Probability.ThorpShuffle.FixedLists.Asymptotics - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter -namespace Thorp -namespace FixedLists -open Conditional - -theorem list_test_bound_raw (d C m k : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) - (hk : k + m ≤ Fintype.card (Position (d + 2))) - (e : LabelList (d + 2) k) (r : State (d + 2)) - (f : LabelList (d + 2) k → ℝ) (hf : ∀ z, |f z| ≤ 1) : - |mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - f (e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding))) - - mean (fun g : State (d + 2) => f (e.trans ((r * g).toEmbedding)))| ≤ - (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by - let F : (Fin k → Position (d + 2)) → ℝ := fun z => - if hz : Function.Injective z then f ((⟨z, hz⟩ : LabelList (d + 2) k).trans r.toEmbedding) - else 0 - have hF : ∀ z, |F z| ≤ 1 := by - intro z - dsimp only [F] - split_ifs - · exact hf _ - · norm_num - have hmap (g : State (d + 2)) : - F (g ∘ e) = f (e.trans ((r * g).toEmbedding)) := by - dsimp only [F] - rw [dite_eq_left (g.injective.comp e.injective)] - rfl - have hb := prefix_test_bound_sixteen d C m hm k hk e e.injective F hF - simpa only [hmap] using hb - -theorem list_tv_bound_raw (d C m k : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) - (hk : k + m ≤ Fintype.card (Position (d + 2))) - (e : LabelList (d + 2) k) (r : State (d + 2)) : - tv (fairMass (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding))) - (fun _ => (1 : ℝ) / Fintype.card (LabelList (d + 2) k)) ≤ - (k : ℝ) / 2 * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by - rw [← uniform_list_mass_frame e r] - have hh := fairMass_tv_le_of_test - (fun ω : History (d + 2) ((C + 2) * (d + 2)) => - e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding)) - (fun g : State (d + 2) => e.trans ((r * g).toEmbedding)) - ((k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m))) - (list_test_bound_raw d C m k hm hk e r) - calc - _ ≤ (↑k * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m))) / 2 := hh - _ = _ := by ring - -lemma images_factor {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) - (ω : History d t) : - images t start labels ω = - (labels.trans start.toEmbedding).trans - (((rotate d)⁻¹ ^ t * run d t ω).toEmbedding) := by - ext i - rfl - -theorem listTV_bound_raw (d C m k : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) - (hk : k + m ≤ Fintype.card (Position (d + 2))) - (start : State (d + 2)) (labels : LabelList (d + 2) k) : - listTV ((C + 2) * (d + 2)) start labels ≤ - (k : ℝ) / 2 * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by - simp only [listTV] - exact list_tv_bound_raw d C m k hm hk (labels.trans start.toEmbedding) - ((rotate (d + 2))⁻¹ ^ ((C + 2) * (d + 2))) - -theorem listTV_bound (d C k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ (d + 4)) - (start : State (d + 4)) (labels : LabelList (d + 4) k) : - listTV ((C + 2) * (d + 4)) start labels ≤ - (k : ℝ) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope C d) := by - have hn : Fintype.card (Position (d + 2 + 2)) = 16 * 2 ^ d := by - rw [card_position] - simp only [pow_add] - norm_num - omega - have hk' : k + 2 ^ d ≤ Fintype.card (Position (d + 2 + 2)) := by - have hn' : 2 ^ (d + 4) = 16 * 2 ^ d := by simp [pow_add, Nat.mul_comm] - rw [hn' ] at hk - rw [hn] - omega - have hh := listTV_bound_raw (d + 2) C (2 ^ d) k (by rw [hn]) hk' start labels - simpa only [Nat.add_assoc, card_position, Nat.cast_pow, Nat.cast_ofNat, energyEnvelope] using hh - -lemma k_le_size (d k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ d) : (k : ℝ) ≤ (2 : ℝ) ^ d := by - have h : k ≤ 2 ^ d := by omega - exact_mod_cast h - -theorem listTV_256 (d k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ (d + 4)) - (start : State (d + 4)) (labels : LabelList (d + 4) k) : - listTV (256 * (d + 4)) start labels ≤ listRate d := by - have h := listTV_bound d 254 k hk start labels - have hk' := k_le_size (d + 4) k hk - have ha := energyEnvelope_nonneg 254 d - have hb : (k : ℝ) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope 254 d) ≤ listRate d := by - calc - _ ≤ ((2 : ℝ) ^ (d + 4)) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope 254 d) := - mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right hk' (by norm_num)) (Real.sqrt_nonneg _) - _ ≤ listRate d := by - unfold listRate - apply Real.le_sqrt_of_sq_le - rw [mul_pow, div_pow, Real.sq_sqrt (mul_nonneg (by positivity) ha)] - have hp : 0 ≤ ((2 : ℝ) ^ (d + 4)) ^ 3 * energyEnvelope 254 d := mul_nonneg (by positivity) ha - nlinarith - exact h.trans hb - -theorem listTV_1024_eventually : - ∀ᶠ d : ℕ in atTop, ∀ k, 16 * k ≤ 15 * 2 ^ (d + 4) → - ∀ (start : State (d + 4)) (labels : LabelList (d + 4) k), - listTV (1024 * (d + 4)) start labels ≤ Real.rpow ((2 : ℝ) ^ (d + 4)) (-(3 : ℝ) / 2) := by - have he : ∀ᶠ d : ℕ in atTop, - ((2 : ℝ) ^ (d + 4)) ^ 6 * energyEnvelope 1022 d ≤ 2 := - (scaledEnergy_tendsto 1022 6 geometric_base_1024).eventually - (eventually_le_nhds (by norm_num : (0 : ℝ) < 2)) - filter_upwards [he] with d hd - intro k hk start labels - have h := listTV_bound d 1022 k hk start labels - have hk' := k_le_size (d + 4) k hk - exact h.trans ((mul_le_mul_of_nonneg_right - (div_le_div_of_nonneg_right hk' (by norm_num)) (Real.sqrt_nonneg _)).trans - (scalar_tv_finish _ _ (by positivity) (energyEnvelope_nonneg _ _) hd)) - -end FixedLists -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.FixedLists.Objects +import OAI.Probability.ThorpShuffle.FixedLists.Asymptotics + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter +namespace Thorp +namespace FixedLists +open Conditional + +theorem list_test_bound_raw (d C m k : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) + (hk : k + m ≤ Fintype.card (Position (d + 2))) + (e : LabelList (d + 2) k) (r : State (d + 2)) + (f : LabelList (d + 2) k → ℝ) (hf : ∀ z, |f z| ≤ 1) : + |mean (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + f (e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding))) - + mean (fun g : State (d + 2) => f (e.trans ((r * g).toEmbedding)))| ≤ + (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by + let F : (Fin k → Position (d + 2)) → ℝ := fun z => + if hz : Function.Injective z then f ((⟨z, hz⟩ : LabelList (d + 2) k).trans r.toEmbedding) + else 0 + have hF : ∀ z, |F z| ≤ 1 := by + intro z + dsimp only [F] + split_ifs + · exact hf _ + · norm_num + have hmap (g : State (d + 2)) : + F (g ∘ e) = f (e.trans ((r * g).toEmbedding)) := by + dsimp only [F] + rw [dite_eq_left (g.injective.comp e.injective)] + rfl + have hb := prefix_test_bound_sixteen d C m hm k hk e e.injective F hF + simpa only [hmap] using hb + +theorem list_tv_bound_raw (d C m k : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) + (hk : k + m ≤ Fintype.card (Position (d + 2))) + (e : LabelList (d + 2) k) (r : State (d + 2)) : + tv (fairMass (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding))) + (fun _ => (1 : ℝ) / Fintype.card (LabelList (d + 2) k)) ≤ + (k : ℝ) / 2 * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by + rw [← uniform_list_mass_frame e r] + have hh := fairMass_tv_le_of_test + (fun ω : History (d + 2) ((C + 2) * (d + 2)) => + e.trans ((r * run (d + 2) ((C + 2) * (d + 2)) ω).toEmbedding)) + (fun g : State (d + 2) => e.trans ((r * g).toEmbedding)) + ((k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m))) + (list_test_bound_raw d C m k hm hk e r) + calc + _ ≤ (↑k * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m))) / 2 := hh + _ = _ := by ring + +lemma images_factor {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) + (ω : History d t) : + images t start labels ω = + (labels.trans start.toEmbedding).trans + (((rotate d)⁻¹ ^ t * run d t ω).toEmbedding) := by + ext i + rfl + +theorem listTV_bound_raw (d C m k : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 16 * m) + (hk : k + m ≤ Fintype.card (Position (d + 2))) + (start : State (d + 2)) (labels : LabelList (d + 2) k) : + listTV ((C + 2) * (d + 2)) start labels ≤ + (k : ℝ) / 2 * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((63 / 64 : ℝ) ^ (C * (d + 2)) + 64 * (9 / 10 : ℝ) ^ m)) := by + simp only [listTV] + exact list_tv_bound_raw d C m k hm hk (labels.trans start.toEmbedding) + ((rotate (d + 2))⁻¹ ^ ((C + 2) * (d + 2))) + +theorem listTV_bound (d C k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ (d + 4)) + (start : State (d + 4)) (labels : LabelList (d + 4) k) : + listTV ((C + 2) * (d + 4)) start labels ≤ + (k : ℝ) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope C d) := by + have hn : Fintype.card (Position (d + 2 + 2)) = 16 * 2 ^ d := by + rw [card_position] + simp only [pow_add] + norm_num + omega + have hk' : k + 2 ^ d ≤ Fintype.card (Position (d + 2 + 2)) := by + have hn' : 2 ^ (d + 4) = 16 * 2 ^ d := by simp [pow_add, Nat.mul_comm] + rw [hn' ] at hk + rw [hn] + omega + have hh := listTV_bound_raw (d + 2) C (2 ^ d) k (by rw [hn]) hk' start labels + simpa only [Nat.add_assoc, card_position, Nat.cast_pow, Nat.cast_ofNat, energyEnvelope] using hh + +lemma k_le_size (d k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ d) : (k : ℝ) ≤ (2 : ℝ) ^ d := by + have h : k ≤ 2 ^ d := by omega + exact_mod_cast h + +theorem listTV_256 (d k : ℕ) (hk : 16 * k ≤ 15 * 2 ^ (d + 4)) + (start : State (d + 4)) (labels : LabelList (d + 4) k) : + listTV (256 * (d + 4)) start labels ≤ listRate d := by + have h := listTV_bound d 254 k hk start labels + have hk' := k_le_size (d + 4) k hk + have ha := energyEnvelope_nonneg 254 d + have hb : (k : ℝ) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope 254 d) ≤ listRate d := by + calc + _ ≤ ((2 : ℝ) ^ (d + 4)) / 2 * Real.sqrt ((2 : ℝ) ^ (d + 4) * energyEnvelope 254 d) := + mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right hk' (by norm_num)) (Real.sqrt_nonneg _) + _ ≤ listRate d := by + unfold listRate + apply Real.le_sqrt_of_sq_le + rw [mul_pow, div_pow, Real.sq_sqrt (mul_nonneg (by positivity) ha)] + have hp : 0 ≤ ((2 : ℝ) ^ (d + 4)) ^ 3 * energyEnvelope 254 d := mul_nonneg (by positivity) ha + nlinarith + exact h.trans hb + +theorem listTV_1024_eventually : + ∀ᶠ d : ℕ in atTop, ∀ k, 16 * k ≤ 15 * 2 ^ (d + 4) → + ∀ (start : State (d + 4)) (labels : LabelList (d + 4) k), + listTV (1024 * (d + 4)) start labels ≤ Real.rpow ((2 : ℝ) ^ (d + 4)) (-(3 : ℝ) / 2) := by + have he : ∀ᶠ d : ℕ in atTop, + ((2 : ℝ) ^ (d + 4)) ^ 6 * energyEnvelope 1022 d ≤ 2 := + (scaledEnergy_tendsto 1022 6 geometric_base_1024).eventually + (eventually_le_nhds (by norm_num : (0 : ℝ) < 2)) + filter_upwards [he] with d hd + intro k hk start labels + have h := listTV_bound d 1022 k hk start labels + have hk' := k_le_size (d + 4) k hk + exact h.trans ((mul_le_mul_of_nonneg_right + (div_le_div_of_nonneg_right hk' (by norm_num)) (Real.sqrt_nonneg _)).trans + (scalar_tv_finish _ _ (by positivity) (energyEnvelope_nonneg _ _) hd)) + +end FixedLists +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/Main.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/Main.lean index 0e97f25f67ca55850f2d6531f6971462e7226626..51d7f8a7f66fb3d38129827e488923531c93edec 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/Main.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/Main.lean @@ -1,61 +1,61 @@ -import OAI.Probability.ThorpShuffle.FixedLists.Lists -import OAI.Probability.ThorpShuffle.FixedLists.FullDeck - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter - -namespace Thorp -namespace FixedLists - -lemma eventually_unshift {P : ℕ → Prop} - (h : ∀ᶠ d : ℕ in atTop, P (d + 4)) : ∀ᶠ d : ℕ in atTop, P d := by - rw [← map_add_atTop_eq_nat 4] - exact h - -lemma lists_256_uniform : - ∀ ε : ℝ, 0 < ε → ∀ᶠ d : ℕ in atTop, - ∀ k : ℕ, 8 * k ≤ 7 * 2 ^ d → - ∀ (start : State d) (labels : LabelList d k), - listTV (256 * d) start labels < ε := by - intro ε hε - apply eventually_unshift - have he : ∀ᶠ d : ℕ in atTop, listRate d < ε := - listRate_tendsto.eventually (eventually_lt_nhds hε) - filter_upwards [he] with d hd - intro k hk start labels - have hk' : 16 * k ≤ 15 * 2 ^ (d + 4) := by omega - exact (listTV_256 d k hk' start labels).trans_lt hd - -lemma lists_1024_uniform : - ∀ᶠ d : ℕ in atTop, - ∀ k : ℕ, 16 * k ≤ 15 * 2 ^ d → - ∀ (start : State d) (labels : LabelList d k), - listTV (1024 * d) start labels ≤ Real.rpow ((2 : ℝ) ^ d) (-(3 : ℝ) / 2) := - eventually_unshift listTV_1024_eventually - -end FixedLists - -theorem first_main : - (∀ ε : ℝ, 0 < ε → ∀ᶠ d : ℕ in atTop, - ∀ k : ℕ, 8 * k ≤ 7 * 2 ^ d → - ∀ (start : State d) (labels : LabelList d k), - listTV (256 * d) start labels < ε) ∧ - (∀ᶠ d : ℕ in atTop, - ∀ k : ℕ, 16 * k ≤ 15 * 2 ^ d → - ∀ (start : State d) (labels : LabelList d k), - listTV (1024 * d) start labels ≤ Real.rpow ((2 : ℝ) ^ d) (-(3 : ℝ) / 2)) ∧ - (Tendsto (fun d : ℕ => distance d (2048 * d)) atTop (nhds 0) ∧ - ∀ (d : ℕ) (start : State d), - tv (lawFrom d (2048 * d) start) (uniform d) = distance d (2048 * d)) := by - exact ⟨FixedLists.lists_256_uniform, FixedLists.lists_1024_uniform, - full_mixing_2048, fun d start => worst_start_eq d (2048 * d) start⟩ - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.FixedLists.Lists +import OAI.Probability.ThorpShuffle.FixedLists.FullDeck + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter + +namespace Thorp +namespace FixedLists + +lemma eventually_unshift {P : ℕ → Prop} + (h : ∀ᶠ d : ℕ in atTop, P (d + 4)) : ∀ᶠ d : ℕ in atTop, P d := by + rw [← map_add_atTop_eq_nat 4] + exact h + +lemma lists_256_uniform : + ∀ ε : ℝ, 0 < ε → ∀ᶠ d : ℕ in atTop, + ∀ k : ℕ, 8 * k ≤ 7 * 2 ^ d → + ∀ (start : State d) (labels : LabelList d k), + listTV (256 * d) start labels < ε := by + intro ε hε + apply eventually_unshift + have he : ∀ᶠ d : ℕ in atTop, listRate d < ε := + listRate_tendsto.eventually (eventually_lt_nhds hε) + filter_upwards [he] with d hd + intro k hk start labels + have hk' : 16 * k ≤ 15 * 2 ^ (d + 4) := by omega + exact (listTV_256 d k hk' start labels).trans_lt hd + +lemma lists_1024_uniform : + ∀ᶠ d : ℕ in atTop, + ∀ k : ℕ, 16 * k ≤ 15 * 2 ^ d → + ∀ (start : State d) (labels : LabelList d k), + listTV (1024 * d) start labels ≤ Real.rpow ((2 : ℝ) ^ d) (-(3 : ℝ) / 2) := + eventually_unshift listTV_1024_eventually + +end FixedLists + +theorem first_main : + (∀ ε : ℝ, 0 < ε → ∀ᶠ d : ℕ in atTop, + ∀ k : ℕ, 8 * k ≤ 7 * 2 ^ d → + ∀ (start : State d) (labels : LabelList d k), + listTV (256 * d) start labels < ε) ∧ + (∀ᶠ d : ℕ in atTop, + ∀ k : ℕ, 16 * k ≤ 15 * 2 ^ d → + ∀ (start : State d) (labels : LabelList d k), + listTV (1024 * d) start labels ≤ Real.rpow ((2 : ℝ) ^ d) (-(3 : ℝ) / 2)) ∧ + (Tendsto (fun d : ℕ => distance d (2048 * d)) atTop (nhds 0) ∧ + ∀ (d : ℕ) (start : State d), + tv (lawFrom d (2048 * d) start) (uniform d) = distance d (2048 * d)) := by + exact ⟨FixedLists.lists_256_uniform, FixedLists.lists_1024_uniform, + full_mixing_2048, fun d start => worst_start_eq d (2048 * d) start⟩ + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FixedLists/Objects.lean b/lean/OAI/Probability/ThorpShuffle/FixedLists/Objects.lean index 578347babc008ae2d8341b22ab901d38153c6051..1d20a4dd6ec7cea786f92d3a3864f233402050be 100644 --- a/lean/OAI/Probability/ThorpShuffle/FixedLists/Objects.lean +++ b/lean/OAI/Probability/ThorpShuffle/FixedLists/Objects.lean @@ -1,78 +1,78 @@ -import OAI.Probability.ThorpShuffle.Main - -namespace OAI - - -noncomputable section -open scoped BigOperators -open Filter - -namespace Thorp - -abbrev LabelList (d k : ℕ) := Fin k ↪ Position d - -def coordinateRun (d t : ℕ) (ω : History d t) : State d := - (rotate d)⁻¹ ^ t * run d t ω - -def images {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) - (ω : History d t) : LabelList d k := - labels.trans ((coordinateRun d t ω * start).toEmbedding) - -def listTV {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) : ℝ := - tv (fairMass (images t start labels)) (fun _ => 1 / Fintype.card (LabelList d k)) - -namespace FixedLists -open Conditional - -theorem uniform_list_mass {α : Type*} [Fintype α] [DecidableEq α] {k : ℕ} (e : Fin k ↪ α) : - fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) = - fun _ => (1 : ℝ) / Fintype.card (Fin k ↪ α) := by - classical - let : Nonempty (Fin k ↪ α) := ⟨e⟩ - let μ := fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) - have hconst (z w : Fin k ↪ α) : μ z = μ w := by - obtain ⟨σ, hσ⟩ := Equiv.Perm.exists_extending_pair z w z.injective w.injective - have heq (g : Equiv.Perm α) : e.trans ((σ * g).toEmbedding) = w ↔ e.trans g.toEmbedding = z := by - constructor - · intro h - ext i - apply σ.injective - exact (congrArg (fun a : Fin k ↪ α => a i) h).trans (hσ i).symm - · intro h - ext i - change σ (g (e i)) = w i - rw [show g (e i) = z i from congrArg (fun a : Fin k ↪ α => a i) h, hσ] - have hh := mean_equiv (Equiv.mulLeft σ) - (fun g : Equiv.Perm α => if e.trans g.toEmbedding = w then (1 : ℝ) else 0) - change mean (fun g : Equiv.Perm α => if e.trans ((σ * g).toEmbedding) = w then (1 : ℝ) else 0) = _ at hh - dsimp only [μ] - simp only [fairMass_eq_mean] - simpa only [heq] using hh - have hs : ∑ z, μ z = 1 := fairMass_sum _ - funext z - have hz : (Fintype.card (Fin k ↪ α) : ℝ) * μ z = 1 := by - have hh : (∑ w, μ w) = (Fintype.card (Fin k ↪ α) : ℝ) * μ z := by - simp only [hconst _ z, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - linarith - change μ z = _ - exact (eq_div_iff (by exact_mod_cast Fintype.card_ne_zero (α := Fin k ↪ α))).mpr (by linarith) - -theorem uniform_list_mass_frame {α : Type*} [Fintype α] [DecidableEq α] {k : ℕ} - (e : Fin k ↪ α) (r : Equiv.Perm α) : - fairMass (fun g : Equiv.Perm α => e.trans ((r * g).toEmbedding)) = - fun _ => (1 : ℝ) / Fintype.card (Fin k ↪ α) := by - classical - calc - _ = fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) := by - funext z - simp only [fairMass_eq_mean] - exact mean_equiv (Equiv.mulLeft r) - (fun g : Equiv.Perm α => if e.trans g.toEmbedding = z then (1 : ℝ) else 0) - _ = _ := uniform_list_mass e - -end FixedLists -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Main + +namespace OAI + + +noncomputable section +open scoped BigOperators +open Filter + +namespace Thorp + +abbrev LabelList (d k : ℕ) := Fin k ↪ Position d + +def coordinateRun (d t : ℕ) (ω : History d t) : State d := + (rotate d)⁻¹ ^ t * run d t ω + +def images {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) + (ω : History d t) : LabelList d k := + labels.trans ((coordinateRun d t ω * start).toEmbedding) + +def listTV {d k : ℕ} (t : ℕ) (start : State d) (labels : LabelList d k) : ℝ := + tv (fairMass (images t start labels)) (fun _ => 1 / Fintype.card (LabelList d k)) + +namespace FixedLists +open Conditional + +theorem uniform_list_mass {α : Type*} [Fintype α] [DecidableEq α] {k : ℕ} (e : Fin k ↪ α) : + fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) = + fun _ => (1 : ℝ) / Fintype.card (Fin k ↪ α) := by + classical + let : Nonempty (Fin k ↪ α) := ⟨e⟩ + let μ := fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) + have hconst (z w : Fin k ↪ α) : μ z = μ w := by + obtain ⟨σ, hσ⟩ := Equiv.Perm.exists_extending_pair z w z.injective w.injective + have heq (g : Equiv.Perm α) : e.trans ((σ * g).toEmbedding) = w ↔ e.trans g.toEmbedding = z := by + constructor + · intro h + ext i + apply σ.injective + exact (congrArg (fun a : Fin k ↪ α => a i) h).trans (hσ i).symm + · intro h + ext i + change σ (g (e i)) = w i + rw [show g (e i) = z i from congrArg (fun a : Fin k ↪ α => a i) h, hσ] + have hh := mean_equiv (Equiv.mulLeft σ) + (fun g : Equiv.Perm α => if e.trans g.toEmbedding = w then (1 : ℝ) else 0) + change mean (fun g : Equiv.Perm α => if e.trans ((σ * g).toEmbedding) = w then (1 : ℝ) else 0) = _ at hh + dsimp only [μ] + simp only [fairMass_eq_mean] + simpa only [heq] using hh + have hs : ∑ z, μ z = 1 := fairMass_sum _ + funext z + have hz : (Fintype.card (Fin k ↪ α) : ℝ) * μ z = 1 := by + have hh : (∑ w, μ w) = (Fintype.card (Fin k ↪ α) : ℝ) * μ z := by + simp only [hconst _ z, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + linarith + change μ z = _ + exact (eq_div_iff (by exact_mod_cast Fintype.card_ne_zero (α := Fin k ↪ α))).mpr (by linarith) + +theorem uniform_list_mass_frame {α : Type*} [Fintype α] [DecidableEq α] {k : ℕ} + (e : Fin k ↪ α) (r : Equiv.Perm α) : + fairMass (fun g : Equiv.Perm α => e.trans ((r * g).toEmbedding)) = + fun _ => (1 : ℝ) / Fintype.card (Fin k ↪ α) := by + classical + calc + _ = fairMass (fun g : Equiv.Perm α => e.trans g.toEmbedding) := by + funext z + simp only [fairMass_eq_mean] + exact mean_equiv (Equiv.mulLeft r) + (fun g : Equiv.Perm α => if e.trans g.toEmbedding = z then (1 : ℝ) else 0) + _ = _ := uniform_list_mass e + +end FixedLists +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FourierBounds.lean b/lean/OAI/Probability/ThorpShuffle/FourierBounds.lean index a084d7b05605457589f98b9aa485690af92a26cd..f162c672d5b4b388f0ec45268378a02b7fc3a553 100644 --- a/lean/OAI/Probability/ThorpShuffle/FourierBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/FourierBounds.lean @@ -1,172 +1,172 @@ -import OAI.Probability.ThorpShuffle.CosetBounds - -namespace OAI - -universe uG uE - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier.Family -open scoped Classical -variable {H : Type} [Group H] [Fintype H] (F : Family H) - -def reciprocalSum : ℝ := ∑ b, ((F.degree b : ℝ) ^ 2)⁻¹ - -lemma reciprocalSum_nonneg : 0 ≤ F.reciprocalSum := - Finset.sum_nonneg (fun _ _ => inv_nonneg.mpr (sq_nonneg _)) - -lemma low_degree_sq (D : ℕ) : - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2)^2 ≤ - (D : ℝ) * F.reciprocalSum ^ 2 := by - let s := Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D) - have hpos (b : F.Index) : (0 : ℝ) < F.degree b := by exact_mod_cast F.positive b - have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul s - (r := fun b => (F.degree b : ℝ)^2) (f := fun b => ((F.degree b : ℝ)^2)⁻¹) - (g := fun b => (F.degree b : ℝ)^6) - (fun b _ => inv_nonneg.mpr (sq_nonneg _)) (fun b _ => pow_nonneg (hpos b).le _) - (fun b _ => by apply le_of_eq; field_simp) - have hsmall : ∑ b ∈ s, ((F.degree b : ℝ)^2)⁻¹ ≤ F.reciprocalSum := - Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun b _ _ => inv_nonneg.mpr (sq_nonneg _)) - have hlarge : ∑ b ∈ s, (F.degree b : ℝ)^6 ≤ (D : ℝ) * F.reciprocalSum := by - calc - _ ≤ ∑ b ∈ s, (D : ℝ) * ((F.degree b : ℝ)^2)⁻¹ := by - apply Finset.sum_le_sum - intro b hb - have hh : (F.degree b : ℝ)^8 ≤ D := by exact_mod_cast (Finset.mem_filter.mp hb).2 - apply (le_mul_inv_iff₀ (pow_pos (hpos b) 2)).mpr - calc - _ = (F.degree b : ℝ)^8 := by ring - _ ≤ _ := hh - _ = (D : ℝ) * ∑ b ∈ s, ((F.degree b : ℝ)^2)⁻¹ := by rw [Finset.mul_sum] - _ ≤ _ := mul_le_mul_of_nonneg_left hsmall (Nat.cast_nonneg _) - calc - _ ≤ _ := hcs - _ ≤ F.reciprocalSum * ((D : ℝ) * F.reciprocalSum) := - mul_le_mul hsmall hlarge (Finset.sum_nonneg (fun b _ => pow_nonneg (hpos b).le _)) F.reciprocalSum_nonneg - _ = _ := by ring - -end Thorp.Fourier.Family - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type uG} [Group G] [Fintype G] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -noncomputable def hsSq (A : Module.End ℂ E) : ℝ := - ∑ k, ‖A (stdOrthonormalBasis ℂ E k)‖ ^ 2 - -lemma hsSq_nonneg (A : Module.End ℂ E) : 0 ≤ hsSq A := - Finset.sum_nonneg (fun _ _ => sq_nonneg _) - -lemma hsSq_le (A : Module.End ℂ E) (R : ℝ) (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) : - hsSq A ≤ (Module.finrank ℂ E : ℝ) * R := by - calc - _ ≤ ∑ k, R * ‖stdOrthonormalBasis ℂ E k‖ ^ 2 := Finset.sum_le_sum (fun k _ => hA _) - _ = _ := by simp - -omit [FiniteDimensional ℂ E] in -lemma norm_integrated_sq (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (f : G → ℂ) (v : E) : - ((‖integrated ρ f v‖ ^ 2 : ℝ) : ℂ) = - ∑ g, ∑ h, conj (f g) * f h * ⟪v, ρ (g⁻¹ * h) v⟫_ℂ := by - rw [Complex.ofReal_pow, ← RCLike.ofReal_eq_complex_ofReal, ← inner_self_eq_norm_sq_to_K] - simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply] - rw [sum_inner] - simp only [inner_sum, inner_smul_left, inner_smul_right] - apply Finset.sum_congr rfl - intro g _ - apply Finset.sum_congr rfl - intro h _ - rw [map_mul, Module.End.mul_apply, inner_inv ρ hu] - ring - -lemma hsSq_integrated (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (f : G → ℂ) : - (hsSq (integrated ρ f) : ℂ) = - ∑ g, ∑ h, conj (f g) * f h * ρ.character (g⁻¹ * h) := by - simp only [hsSq, Complex.ofReal_sum, norm_integrated_sq ρ hu] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro g _ - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro h _ - rw [← Finset.mul_sum] - congr 1 - exact (LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℂ E)).symm - -namespace Family -variable {G : Type} [Group G] [Fintype G] (F : Family G) - -theorem parseval (f : G → ℂ) : - (Fintype.card G : ℝ) * ∑ g, ‖f g‖ ^ 2 = - ∑ i, (F.degree i : ℝ) * hsSq (integrated (F.rep i) f) := by - apply Complex.ofReal_injective - push_cast - symm - simp only [hsSq_integrated _ (F.unitary _), Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro g _ - rw [Finset.sum_comm] - have he (h : G) : ∑ i, (F.degree i : ℂ) * - (conj (f g) * f h * (F.rep i).character (g⁻¹ * h)) = - conj (f g) * f h * (if g⁻¹ * h = 1 then (Fintype.card G : ℂ) else 0) := by - rw [← F.regular, Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - dsimp [degree] - ring - simp only [he, inv_mul_eq_one, mul_ite, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, - ↓reduceIte, Complex.conj_mul'] - ring - -end Family -end Thorp.Fourier - -namespace Thorp.Fourier -open scoped Classical -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -omit [FiniteDimensional ℂ E] in -lemma power_norm_sq (A : Module.End ℂ E) (R : ℝ) (hR : 0 ≤ R) - (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) (k : ℕ) (v : E) : - ‖(A ^ k) v‖ ^ 2 ≤ R ^ k * ‖v‖ ^ 2 := by - induction k with - | zero => simp - | succ k ih => - rw [pow_succ' A k, Module.End.mul_apply, pow_succ' R k] - exact (hA _).trans (by nlinarith [mul_le_mul_of_nonneg_left ih hR]) - -lemma eight_degree_bound (D : ℝ) (hD : 0 < D) (B S C : ℝ) - (hs : S ^ 2 ≤ D * C ^ 2) : - D ^ 2 * (8 * B * S / D) ^ 8 ≤ (8 * B * C) ^ 8 * (D ^ 2)⁻¹ := by - have hh := pow_le_pow_left₀ (sq_nonneg S) hs 4 - have hscalar : 0 ≤ (8 * B)^8 := by positivity - have ht := mul_le_mul_of_nonneg_left hh hscalar - apply (le_mul_inv_iff₀ (pow_pos hD 2)).mpr - field_simp - field_simp at ht - nlinarith - -namespace Family -variable {G : Type} [Group G] [Fintype G] (F : Family G) - -lemma l1_sq_le_parseval (f : G → ℝ) : - (∑ g, |f g|)^2 ≤ ∑ i, (F.degree i : ℝ) * hsSq (integrated (F.rep i) (fun g => (f g : ℂ))) := by - have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : G => (1 : ℝ)) (fun g => |f g|) - simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one, - sq_abs] at hc - have hp := F.parseval (fun g => (f g : ℂ)) - simp only [Complex.norm_real, Real.norm_eq_abs, sq_abs] at hp - exact hc.trans_eq hp - -end Family -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.CosetBounds + +namespace OAI + +universe uG uE + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier.Family +open scoped Classical +variable {H : Type} [Group H] [Fintype H] (F : Family H) + +def reciprocalSum : ℝ := ∑ b, ((F.degree b : ℝ) ^ 2)⁻¹ + +lemma reciprocalSum_nonneg : 0 ≤ F.reciprocalSum := + Finset.sum_nonneg (fun _ _ => inv_nonneg.mpr (sq_nonneg _)) + +lemma low_degree_sq (D : ℕ) : + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D), (F.degree b : ℝ)^2)^2 ≤ + (D : ℝ) * F.reciprocalSum ^ 2 := by + let s := Finset.univ.filter (fun b => F.degree b ^ 8 ≤ D) + have hpos (b : F.Index) : (0 : ℝ) < F.degree b := by exact_mod_cast F.positive b + have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul s + (r := fun b => (F.degree b : ℝ)^2) (f := fun b => ((F.degree b : ℝ)^2)⁻¹) + (g := fun b => (F.degree b : ℝ)^6) + (fun b _ => inv_nonneg.mpr (sq_nonneg _)) (fun b _ => pow_nonneg (hpos b).le _) + (fun b _ => by apply le_of_eq; field_simp) + have hsmall : ∑ b ∈ s, ((F.degree b : ℝ)^2)⁻¹ ≤ F.reciprocalSum := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun b _ _ => inv_nonneg.mpr (sq_nonneg _)) + have hlarge : ∑ b ∈ s, (F.degree b : ℝ)^6 ≤ (D : ℝ) * F.reciprocalSum := by + calc + _ ≤ ∑ b ∈ s, (D : ℝ) * ((F.degree b : ℝ)^2)⁻¹ := by + apply Finset.sum_le_sum + intro b hb + have hh : (F.degree b : ℝ)^8 ≤ D := by exact_mod_cast (Finset.mem_filter.mp hb).2 + apply (le_mul_inv_iff₀ (pow_pos (hpos b) 2)).mpr + calc + _ = (F.degree b : ℝ)^8 := by ring + _ ≤ _ := hh + _ = (D : ℝ) * ∑ b ∈ s, ((F.degree b : ℝ)^2)⁻¹ := by rw [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left hsmall (Nat.cast_nonneg _) + calc + _ ≤ _ := hcs + _ ≤ F.reciprocalSum * ((D : ℝ) * F.reciprocalSum) := + mul_le_mul hsmall hlarge (Finset.sum_nonneg (fun b _ => pow_nonneg (hpos b).le _)) F.reciprocalSum_nonneg + _ = _ := by ring + +end Thorp.Fourier.Family + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type uG} [Group G] [Fintype G] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +noncomputable def hsSq (A : Module.End ℂ E) : ℝ := + ∑ k, ‖A (stdOrthonormalBasis ℂ E k)‖ ^ 2 + +lemma hsSq_nonneg (A : Module.End ℂ E) : 0 ≤ hsSq A := + Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +lemma hsSq_le (A : Module.End ℂ E) (R : ℝ) (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) : + hsSq A ≤ (Module.finrank ℂ E : ℝ) * R := by + calc + _ ≤ ∑ k, R * ‖stdOrthonormalBasis ℂ E k‖ ^ 2 := Finset.sum_le_sum (fun k _ => hA _) + _ = _ := by simp + +omit [FiniteDimensional ℂ E] in +lemma norm_integrated_sq (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (f : G → ℂ) (v : E) : + ((‖integrated ρ f v‖ ^ 2 : ℝ) : ℂ) = + ∑ g, ∑ h, conj (f g) * f h * ⟪v, ρ (g⁻¹ * h) v⟫_ℂ := by + rw [Complex.ofReal_pow, ← RCLike.ofReal_eq_complex_ofReal, ← inner_self_eq_norm_sq_to_K] + simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply] + rw [sum_inner] + simp only [inner_sum, inner_smul_left, inner_smul_right] + apply Finset.sum_congr rfl + intro g _ + apply Finset.sum_congr rfl + intro h _ + rw [map_mul, Module.End.mul_apply, inner_inv ρ hu] + ring + +lemma hsSq_integrated (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (f : G → ℂ) : + (hsSq (integrated ρ f) : ℂ) = + ∑ g, ∑ h, conj (f g) * f h * ρ.character (g⁻¹ * h) := by + simp only [hsSq, Complex.ofReal_sum, norm_integrated_sq ρ hu] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro g _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro h _ + rw [← Finset.mul_sum] + congr 1 + exact (LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℂ E)).symm + +namespace Family +variable {G : Type} [Group G] [Fintype G] (F : Family G) + +theorem parseval (f : G → ℂ) : + (Fintype.card G : ℝ) * ∑ g, ‖f g‖ ^ 2 = + ∑ i, (F.degree i : ℝ) * hsSq (integrated (F.rep i) f) := by + apply Complex.ofReal_injective + push_cast + symm + simp only [hsSq_integrated _ (F.unitary _), Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro g _ + rw [Finset.sum_comm] + have he (h : G) : ∑ i, (F.degree i : ℂ) * + (conj (f g) * f h * (F.rep i).character (g⁻¹ * h)) = + conj (f g) * f h * (if g⁻¹ * h = 1 then (Fintype.card G : ℂ) else 0) := by + rw [← F.regular, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + dsimp [degree] + ring + simp only [he, inv_mul_eq_one, mul_ite, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, + ↓reduceIte, Complex.conj_mul'] + ring + +end Family +end Thorp.Fourier + +namespace Thorp.Fourier +open scoped Classical +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [FiniteDimensional ℂ E] in +lemma power_norm_sq (A : Module.End ℂ E) (R : ℝ) (hR : 0 ≤ R) + (hA : ∀ v, ‖A v‖ ^ 2 ≤ R * ‖v‖ ^ 2) (k : ℕ) (v : E) : + ‖(A ^ k) v‖ ^ 2 ≤ R ^ k * ‖v‖ ^ 2 := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ' A k, Module.End.mul_apply, pow_succ' R k] + exact (hA _).trans (by nlinarith [mul_le_mul_of_nonneg_left ih hR]) + +lemma eight_degree_bound (D : ℝ) (hD : 0 < D) (B S C : ℝ) + (hs : S ^ 2 ≤ D * C ^ 2) : + D ^ 2 * (8 * B * S / D) ^ 8 ≤ (8 * B * C) ^ 8 * (D ^ 2)⁻¹ := by + have hh := pow_le_pow_left₀ (sq_nonneg S) hs 4 + have hscalar : 0 ≤ (8 * B)^8 := by positivity + have ht := mul_le_mul_of_nonneg_left hh hscalar + apply (le_mul_inv_iff₀ (pow_pos hD 2)).mpr + field_simp + field_simp at ht + nlinarith + +namespace Family +variable {G : Type} [Group G] [Fintype G] (F : Family G) + +lemma l1_sq_le_parseval (f : G → ℝ) : + (∑ g, |f g|)^2 ≤ ∑ i, (F.degree i : ℝ) * hsSq (integrated (F.rep i) (fun g => (f g : ℂ))) := by + have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : G => (1 : ℝ)) (fun g => |f g|) + simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one, + sq_abs] at hc + have hp := F.parseval (fun g => (f g : ℂ)) + simp only [Complex.norm_real, Real.norm_eq_abs, sq_abs] at hp + exact hc.trans_eq hp + +end Family +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FourierFamilies.lean b/lean/OAI/Probability/ThorpShuffle/FourierFamilies.lean index 51f4f5730ffd724cf411b0297dbbeff2b56e3e26..39189a1b7d31bf13e9a53d962b6c6050fc86e226 100644 --- a/lean/OAI/Probability/ThorpShuffle/FourierFamilies.lean +++ b/lean/OAI/Probability/ThorpShuffle/FourierFamilies.lean @@ -1,227 +1,227 @@ -import OAI.Probability.ThorpShuffle.Reynolds - -namespace OAI - -universe uG uE uV - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier -open scoped Classical - -structure Family (G : Type) [Group G] [Fintype G] where - Index : Type - [finiteIndex : Fintype Index] - Space : Index → Type - [normed : ∀ i, NormedAddCommGroup (Space i)] - [innerSpace : ∀ i, InnerProductSpace ℂ (Space i)] - [finiteDim : ∀ i, FiniteDimensional ℂ (Space i)] - rep : ∀ i, Representation ℂ G (Space i) - [irreducible : ∀ i, Representation.IsIrreducible (rep i)] - positive : ∀ i, 0 < Module.finrank ℂ (Space i) - unitary : ∀ i g x y, ⟪rep i g x, rep i g y⟫_ℂ = ⟪x, y⟫_ℂ - distinct : ∀ i j, Nonempty (Representation.Equiv (rep i) (rep j)) → i = j - regular : ∀ g, ∑ i, (Module.finrank ℂ (Space i) : ℂ) * (rep i).character g = - if g = 1 then (Fintype.card G : ℂ) else 0 - -attribute [instance] Family.finiteIndex Family.normed Family.innerSpace Family.finiteDim Family.irreducible - -namespace Family -variable {G : Type} [Group G] [Fintype G] (F : Family G) - -def degree (i : F.Index) : ℕ := Module.finrank ℂ (F.Space i) - -lemma orthogonal (i j : F.Index) : - (Fintype.card G : ℂ)⁻¹ * ∑ g, (F.rep i).character g * (F.rep j).character g⁻¹ = - if i = j then 1 else 0 := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (NeZero.ne _) - rw [Fintype.card_eq_nat_card, Representation.char_orthonormal] - congr 1 - apply propext - exact ⟨fun h => (F.distinct j i h).symm, fun h => by subst j; exact ⟨Representation.Equiv.refl _⟩⟩ - -lemma integrated_faithful (f : G → ℂ) (hf : ∀ i, integrated (F.rep i) f = 0) : f = 0 := by - funext x - have hh : ∑ i, (F.degree i : ℂ) * LinearMap.trace ℂ (F.Space i) - (integrated (F.rep i) f * F.rep i x⁻¹) = 0 := by simp [hf] - simp only [integrated, Finset.sum_mul, smul_mul_assoc, ← map_mul, map_sum, map_smul, smul_eq_mul] at hh - change ∑ i, (F.degree i : ℂ) * ∑ g, f g * (F.rep i).character (g * x⁻¹) = 0 at hh - simp_rw [Finset.mul_sum] at hh - rw [Finset.sum_comm] at hh - have he (g : G) : ∑ i, (F.degree i : ℂ) * (f g * (F.rep i).character (g * x⁻¹)) = - f g * (if g * x⁻¹ = 1 then (Fintype.card G : ℂ) else 0) := by - rw [← F.regular] - simp only [Finset.mul_sum, degree] - apply Finset.sum_congr rfl - intro i _ - ring - simp only [he, mul_inv_eq_one, mul_ite, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, - ↓reduceIte] at hh - exact (mul_eq_zero.mp hh).resolve_right (by exact_mod_cast Fintype.card_ne_zero) - -lemma integrated_injective (f k : G → ℂ) (h : ∀ i, integrated (F.rep i) f = integrated (F.rep i) k) : f = k := by - apply sub_eq_zero.mp - apply F.integrated_faithful - intro i - rw [integrated_sub, h i, sub_self] - -def kernel (i : F.Index) (g : G) : ℂ := - (F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g⁻¹ - -lemma kernel_central (i : F.Index) (g h : G) : F.kernel i (h * g * h⁻¹) = F.kernel i g := by - simp only [kernel, mul_inv_rev, inv_inv] - rw [← mul_assoc, Representation.char_conj] - -lemma integrated_kernel (i j : F.Index) : integrated (F.rep j) (F.kernel i) = if i = j then 1 else 0 := by - obtain ⟨c, hc⟩ := central_scalar (F.rep j) (F.kernel i) (F.kernel_central i) - have ht := congrArg (LinearMap.trace ℂ (F.Space j)) hc - rw [trace_integrated, map_smul, LinearMap.trace_id, smul_eq_mul] at ht - have hh : ∑ g, F.kernel i g * (F.rep j).character g = - (F.degree i : ℂ) * (if j = i then 1 else 0) := by - rw [← F.orthogonal j i] - simp only [kernel, Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - rw [hh] at ht - have hd : (F.degree j : ℂ) ≠ 0 := by exact_mod_cast (F.positive j).ne' - by_cases hij : i = j - · subst j - simp only [↓reduceIte, mul_one] at ht ⊢ - have he : c = 1 := (mul_right_cancel₀ hd (ht.symm.trans (one_mul _).symm)) - simpa only [he, one_smul, Module.End.one_eq_id] using hc - · simp only [ite_eq_right (Ne.symm hij), mul_zero] at ht - have he : c = 0 := (mul_eq_zero.mp ht.symm).resolve_right hd - simp only [ite_eq_right hij, hc, he, zero_smul] - -lemma kernel_convolution (i j : F.Index) : convolution (F.kernel i) (F.kernel j) = - if i = j then F.kernel i else 0 := by - apply F.integrated_injective - intro k - rw [integrated_convolution, F.integrated_kernel, F.integrated_kernel] - by_cases hij : i = j - · subst j - simp only [↓reduceIte, integrated_kernel] - split_ifs <;> simp - · rw [ite_eq_right hij] - simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] - by_cases hik : i = k - · subst k; simp [Ne.symm hij] - · simp [hik] - -lemma kernel_sum : (∑ i, F.kernel i) = delta := by - apply F.integrated_injective - intro j - rw [integrated_sum, integrated_delta] - simp only [integrated_kernel, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] - -end Family -end Thorp.Fourier - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type uG} [Group G] [Fintype G] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -omit [Fintype G] in -lemma character_inv (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (g : G) : - ρ.character g⁻¹ = conj (ρ.character g) := by - let b := stdOrthonormalBasis ℂ E - simp only [Representation.character, LinearMap.trace_eq_sum_inner _ b, map_sum, - inner_inv ρ hu, inner_conj_symm] - -omit [FiniteDimensional ℂ E] in -lemma integrated_symmetric (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (f : G → ℂ) (hf : ∀ g, conj (f g⁻¹) = f g) : (integrated ρ f).IsSymmetric := by - intro x y - simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, sum_inner, - inner_sum, inner_smul_left, inner_smul_right] - have he := Equiv.sum_comp (Equiv.inv G) (fun g => conj (f g) * ⟪ρ g x, y⟫_ℂ) - rw [← he] - apply Finset.sum_congr rfl - intro g _ - simp only [Equiv.inv_apply, hf] - rw [← inner_inv ρ hu, inv_inv] - -namespace Family -variable {G : Type} [Group G] [Fintype G] (F : Family G) - -lemma kernel_star (i : F.Index) (g : G) : conj (F.kernel i g⁻¹) = F.kernel i g := by - simp only [kernel, inv_inv, map_mul, map_inv₀, map_natCast, character_inv _ (F.unitary i)] - -variable {V : Type uV} [AddCommGroup V] [Module ℂ V] - -def projector (ρ : Representation ℂ G V) (i : F.Index) : Module.End ℂ V := integrated ρ (F.kernel i) - -lemma projector_mul (ρ : Representation ℂ G V) (i j : F.Index) : - F.projector ρ i * F.projector ρ j = if i = j then F.projector ρ i else 0 := by - rw [projector, projector, ← integrated_convolution, F.kernel_convolution] - split_ifs <;> simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] - -lemma projector_idempotent (ρ : Representation ℂ G V) (i : F.Index) : - IsIdempotentElem (F.projector ρ i) := by - simpa only [IsIdempotentElem, ↓reduceIte] using F.projector_mul ρ i i - -lemma projector_sum (ρ : Representation ℂ G V) : ∑ i, F.projector ρ i = 1 := by - simp only [projector] - rw [← integrated_sum, F.kernel_sum, integrated_delta] - -lemma projector_commute (ρ : Representation ℂ G V) (i : F.Index) (g : G) : - Commute (F.projector ρ i) (ρ g) := integrated_central ρ _ (F.kernel_central i) g - -omit [FiniteDimensional ℂ E] in -lemma projector_symmetric (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (i : F.Index) : - (F.projector ρ i).IsSymmetric := integrated_symmetric ρ hu _ (F.kernel_star i) - -lemma kernel_sum_sq (s : Finset F.Index) : - (Fintype.card G : ℝ) * ∑ g, ‖∑ i ∈ s, F.kernel i g‖ ^ 2 = ∑ i ∈ s, (F.degree i : ℝ) ^ 2 := by - have hh (i j : F.Index) : (Fintype.card G : ℂ) * ∑ g, conj (F.kernel i g) * F.kernel j g = - if i = j then (F.degree i : ℂ) ^ 2 else 0 := by - have hc : ∀ g, conj (F.kernel i g) = - (F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g := by - intro g - calc - _ = F.kernel i g⁻¹ := by simpa only [inv_inv] using F.kernel_star i g⁻¹ - _ = _ := by rw [kernel, inv_inv] - simp_rw [hc] - simp only [kernel] - have he : (Fintype.card G : ℂ) * ∑ g, - ((F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g) * - ((F.degree j : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep j).character g⁻¹) = - (F.degree i : ℂ) * (F.degree j : ℂ) * - ((Fintype.card G : ℂ)⁻¹ * ∑ g, (F.rep i).character g * (F.rep j).character g⁻¹) := by - rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - field_simp - rw [he, F.orthogonal] - split_ifs with h - · subst j; ring - · ring - have he : (Fintype.card G : ℂ) * ∑ g, conj (∑ i ∈ s, F.kernel i g) * (∑ i ∈ s, F.kernel i g) = - ∑ i ∈ s, (F.degree i : ℂ) ^ 2 := by - simp only [map_sum, Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro j hj - rw [Finset.sum_comm] - have hz (i : F.Index) : ∑ g, (Fintype.card G : ℂ) * (conj (F.kernel i g) * F.kernel j g) = - if i = j then (F.degree i : ℂ)^2 else 0 := by rw [← Finset.mul_sum, hh] - simp only [hz, Finset.sum_ite_eq', hj, ↓reduceIte] - simp only [Complex.conj_mul'] at he - apply Complex.ofReal_injective - push_cast - exact he - -end Family -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.Reynolds + +namespace OAI + +universe uG uE uV + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier +open scoped Classical + +structure Family (G : Type) [Group G] [Fintype G] where + Index : Type + [finiteIndex : Fintype Index] + Space : Index → Type + [normed : ∀ i, NormedAddCommGroup (Space i)] + [innerSpace : ∀ i, InnerProductSpace ℂ (Space i)] + [finiteDim : ∀ i, FiniteDimensional ℂ (Space i)] + rep : ∀ i, Representation ℂ G (Space i) + [irreducible : ∀ i, Representation.IsIrreducible (rep i)] + positive : ∀ i, 0 < Module.finrank ℂ (Space i) + unitary : ∀ i g x y, ⟪rep i g x, rep i g y⟫_ℂ = ⟪x, y⟫_ℂ + distinct : ∀ i j, Nonempty (Representation.Equiv (rep i) (rep j)) → i = j + regular : ∀ g, ∑ i, (Module.finrank ℂ (Space i) : ℂ) * (rep i).character g = + if g = 1 then (Fintype.card G : ℂ) else 0 + +attribute [instance] Family.finiteIndex Family.normed Family.innerSpace Family.finiteDim Family.irreducible + +namespace Family +variable {G : Type} [Group G] [Fintype G] (F : Family G) + +def degree (i : F.Index) : ℕ := Module.finrank ℂ (F.Space i) + +lemma orthogonal (i j : F.Index) : + (Fintype.card G : ℂ)⁻¹ * ∑ g, (F.rep i).character g * (F.rep j).character g⁻¹ = + if i = j then 1 else 0 := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (NeZero.ne _) + rw [Fintype.card_eq_nat_card, Representation.char_orthonormal] + congr 1 + apply propext + exact ⟨fun h => (F.distinct j i h).symm, fun h => by subst j; exact ⟨Representation.Equiv.refl _⟩⟩ + +lemma integrated_faithful (f : G → ℂ) (hf : ∀ i, integrated (F.rep i) f = 0) : f = 0 := by + funext x + have hh : ∑ i, (F.degree i : ℂ) * LinearMap.trace ℂ (F.Space i) + (integrated (F.rep i) f * F.rep i x⁻¹) = 0 := by simp [hf] + simp only [integrated, Finset.sum_mul, smul_mul_assoc, ← map_mul, map_sum, map_smul, smul_eq_mul] at hh + change ∑ i, (F.degree i : ℂ) * ∑ g, f g * (F.rep i).character (g * x⁻¹) = 0 at hh + simp_rw [Finset.mul_sum] at hh + rw [Finset.sum_comm] at hh + have he (g : G) : ∑ i, (F.degree i : ℂ) * (f g * (F.rep i).character (g * x⁻¹)) = + f g * (if g * x⁻¹ = 1 then (Fintype.card G : ℂ) else 0) := by + rw [← F.regular] + simp only [Finset.mul_sum, degree] + apply Finset.sum_congr rfl + intro i _ + ring + simp only [he, mul_inv_eq_one, mul_ite, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, + ↓reduceIte] at hh + exact (mul_eq_zero.mp hh).resolve_right (by exact_mod_cast Fintype.card_ne_zero) + +lemma integrated_injective (f k : G → ℂ) (h : ∀ i, integrated (F.rep i) f = integrated (F.rep i) k) : f = k := by + apply sub_eq_zero.mp + apply F.integrated_faithful + intro i + rw [integrated_sub, h i, sub_self] + +def kernel (i : F.Index) (g : G) : ℂ := + (F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g⁻¹ + +lemma kernel_central (i : F.Index) (g h : G) : F.kernel i (h * g * h⁻¹) = F.kernel i g := by + simp only [kernel, mul_inv_rev, inv_inv] + rw [← mul_assoc, Representation.char_conj] + +lemma integrated_kernel (i j : F.Index) : integrated (F.rep j) (F.kernel i) = if i = j then 1 else 0 := by + obtain ⟨c, hc⟩ := central_scalar (F.rep j) (F.kernel i) (F.kernel_central i) + have ht := congrArg (LinearMap.trace ℂ (F.Space j)) hc + rw [trace_integrated, map_smul, LinearMap.trace_id, smul_eq_mul] at ht + have hh : ∑ g, F.kernel i g * (F.rep j).character g = + (F.degree i : ℂ) * (if j = i then 1 else 0) := by + rw [← F.orthogonal j i] + simp only [kernel, Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + rw [hh] at ht + have hd : (F.degree j : ℂ) ≠ 0 := by exact_mod_cast (F.positive j).ne' + by_cases hij : i = j + · subst j + simp only [↓reduceIte, mul_one] at ht ⊢ + have he : c = 1 := (mul_right_cancel₀ hd (ht.symm.trans (one_mul _).symm)) + simpa only [he, one_smul, Module.End.one_eq_id] using hc + · simp only [ite_eq_right (Ne.symm hij), mul_zero] at ht + have he : c = 0 := (mul_eq_zero.mp ht.symm).resolve_right hd + simp only [ite_eq_right hij, hc, he, zero_smul] + +lemma kernel_convolution (i j : F.Index) : convolution (F.kernel i) (F.kernel j) = + if i = j then F.kernel i else 0 := by + apply F.integrated_injective + intro k + rw [integrated_convolution, F.integrated_kernel, F.integrated_kernel] + by_cases hij : i = j + · subst j + simp only [↓reduceIte, integrated_kernel] + split_ifs <;> simp + · rw [ite_eq_right hij] + simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] + by_cases hik : i = k + · subst k; simp [Ne.symm hij] + · simp [hik] + +lemma kernel_sum : (∑ i, F.kernel i) = delta := by + apply F.integrated_injective + intro j + rw [integrated_sum, integrated_delta] + simp only [integrated_kernel, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + +end Family +end Thorp.Fourier + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type uG} [Group G] [Fintype G] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [Fintype G] in +lemma character_inv (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (g : G) : + ρ.character g⁻¹ = conj (ρ.character g) := by + let b := stdOrthonormalBasis ℂ E + simp only [Representation.character, LinearMap.trace_eq_sum_inner _ b, map_sum, + inner_inv ρ hu, inner_conj_symm] + +omit [FiniteDimensional ℂ E] in +lemma integrated_symmetric (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (f : G → ℂ) (hf : ∀ g, conj (f g⁻¹) = f g) : (integrated ρ f).IsSymmetric := by + intro x y + simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, sum_inner, + inner_sum, inner_smul_left, inner_smul_right] + have he := Equiv.sum_comp (Equiv.inv G) (fun g => conj (f g) * ⟪ρ g x, y⟫_ℂ) + rw [← he] + apply Finset.sum_congr rfl + intro g _ + simp only [Equiv.inv_apply, hf] + rw [← inner_inv ρ hu, inv_inv] + +namespace Family +variable {G : Type} [Group G] [Fintype G] (F : Family G) + +lemma kernel_star (i : F.Index) (g : G) : conj (F.kernel i g⁻¹) = F.kernel i g := by + simp only [kernel, inv_inv, map_mul, map_inv₀, map_natCast, character_inv _ (F.unitary i)] + +variable {V : Type uV} [AddCommGroup V] [Module ℂ V] + +def projector (ρ : Representation ℂ G V) (i : F.Index) : Module.End ℂ V := integrated ρ (F.kernel i) + +lemma projector_mul (ρ : Representation ℂ G V) (i j : F.Index) : + F.projector ρ i * F.projector ρ j = if i = j then F.projector ρ i else 0 := by + rw [projector, projector, ← integrated_convolution, F.kernel_convolution] + split_ifs <;> simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] + +lemma projector_idempotent (ρ : Representation ℂ G V) (i : F.Index) : + IsIdempotentElem (F.projector ρ i) := by + simpa only [IsIdempotentElem, ↓reduceIte] using F.projector_mul ρ i i + +lemma projector_sum (ρ : Representation ℂ G V) : ∑ i, F.projector ρ i = 1 := by + simp only [projector] + rw [← integrated_sum, F.kernel_sum, integrated_delta] + +lemma projector_commute (ρ : Representation ℂ G V) (i : F.Index) (g : G) : + Commute (F.projector ρ i) (ρ g) := integrated_central ρ _ (F.kernel_central i) g + +omit [FiniteDimensional ℂ E] in +lemma projector_symmetric (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (i : F.Index) : + (F.projector ρ i).IsSymmetric := integrated_symmetric ρ hu _ (F.kernel_star i) + +lemma kernel_sum_sq (s : Finset F.Index) : + (Fintype.card G : ℝ) * ∑ g, ‖∑ i ∈ s, F.kernel i g‖ ^ 2 = ∑ i ∈ s, (F.degree i : ℝ) ^ 2 := by + have hh (i j : F.Index) : (Fintype.card G : ℂ) * ∑ g, conj (F.kernel i g) * F.kernel j g = + if i = j then (F.degree i : ℂ) ^ 2 else 0 := by + have hc : ∀ g, conj (F.kernel i g) = + (F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g := by + intro g + calc + _ = F.kernel i g⁻¹ := by simpa only [inv_inv] using F.kernel_star i g⁻¹ + _ = _ := by rw [kernel, inv_inv] + simp_rw [hc] + simp only [kernel] + have he : (Fintype.card G : ℂ) * ∑ g, + ((F.degree i : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep i).character g) * + ((F.degree j : ℂ) * (Fintype.card G : ℂ)⁻¹ * (F.rep j).character g⁻¹) = + (F.degree i : ℂ) * (F.degree j : ℂ) * + ((Fintype.card G : ℂ)⁻¹ * ∑ g, (F.rep i).character g * (F.rep j).character g⁻¹) := by + rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + field_simp + rw [he, F.orthogonal] + split_ifs with h + · subst j; ring + · ring + have he : (Fintype.card G : ℂ) * ∑ g, conj (∑ i ∈ s, F.kernel i g) * (∑ i ∈ s, F.kernel i g) = + ∑ i ∈ s, (F.degree i : ℂ) ^ 2 := by + simp only [map_sum, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j hj + rw [Finset.sum_comm] + have hz (i : F.Index) : ∑ g, (Fintype.card G : ℂ) * (conj (F.kernel i g) * F.kernel j g) = + if i = j then (F.degree i : ℂ)^2 else 0 := by rw [← Finset.mul_sum, hh] + simp only [hz, Finset.sum_ite_eq', hj, ↓reduceIte] + simp only [Complex.conj_mul'] at he + apply Complex.ofReal_injective + push_cast + exact he + +end Family +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FourierPerturbation.lean b/lean/OAI/Probability/ThorpShuffle/FourierPerturbation.lean index fa606f589b97e9409c39e82f0bbe2634e3c1cfb6..5be4a08f8dfdbe9bfaa8ed81bc3467af195e676c 100644 --- a/lean/OAI/Probability/ThorpShuffle/FourierPerturbation.lean +++ b/lean/OAI/Probability/ThorpShuffle/FourierPerturbation.lean @@ -1,92 +1,92 @@ -import OAI.Probability.ThorpShuffle.Trimming - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp - -namespace Fourier -open scoped Classical -variable {G : Type} [Fintype G] [Group G] - -omit [Group G] in -lemma tv_nonneg (μ ν : G → ℝ) : 0 ≤ tv μ ν := by unfold tv; positivity - -omit [Group G] in -lemma tv_triangle (μ ν η : G → ℝ) : tv μ η ≤ tv μ ν + tv ν η := by - unfold tv - rw [← mul_add, ← Finset.sum_add_distrib] - apply mul_le_mul_of_nonneg_left _ (by norm_num) - exact Finset.sum_le_sum (fun g _ => by simpa only [sub_add_sub_cancel] using abs_add_le (μ g-ν g) (ν g-η g)) - -lemma tv_realConv_left (μ ν η : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) : - tv (realConv μ ν) (realConv μ η) ≤ tv ν η := by - have hb : (∑ z, |realConv μ ν z - realConv μ η z|) ≤ ∑ z, |ν z-η z| := by - calc - _ = ∑ z, |∑ g, μ g * (ν (g⁻¹*z)-η (g⁻¹*z))| := by - simp only [realConv, mul_sub, Finset.sum_sub_distrib] - _ ≤ ∑ z, ∑ g, μ g * |ν (g⁻¹*z)-η (g⁻¹*z)| := by - apply Finset.sum_le_sum - intro z _ - simpa only [abs_mul, abs_of_nonneg (hμ _)] using - Finset.abs_sum_le_sum_abs (fun g => μ g * (ν (g⁻¹*z)-η (g⁻¹*z))) Finset.univ - _ = (∑ g, μ g) * ∑ z, |ν z-η z| := by - rw [Finset.sum_comm, Finset.sum_mul] - apply Finset.sum_congr rfl - intro g _ - rw [← Finset.mul_sum] - congr 1 - exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) (fun z => |ν z-η z|) - _ = _ := by rw [h1, one_mul] - exact mul_le_mul_of_nonneg_left hb (by norm_num : (0:ℝ) ≤ 1/2) - -lemma tv_realConv_right (μ ν η : G → ℝ) (hη : ∀ g, 0 ≤ η g) (h1 : ∑ g, η g = 1) : - tv (realConv μ η) (realConv ν η) ≤ tv μ ν := by - have hb : (∑ z, |realConv μ η z - realConv ν η z|) ≤ ∑ z, |μ z-ν z| := by - calc - _ = ∑ z, |∑ g, (μ g-ν g) * η (g⁻¹*z)| := by - simp only [realConv, sub_mul, Finset.sum_sub_distrib] - _ ≤ ∑ z, ∑ g, |μ g-ν g| * η (g⁻¹*z) := by - apply Finset.sum_le_sum - intro z _ - simpa only [abs_mul, abs_of_nonneg (hη _)] using - Finset.abs_sum_le_sum_abs (fun g => (μ g-ν g) * η (g⁻¹*z)) Finset.univ - _ = (∑ g, |μ g-ν g|) * ∑ z, η z := by - rw [Finset.sum_comm, Finset.sum_mul] - apply Finset.sum_congr rfl - intro g _ - rw [← Finset.mul_sum] - congr 1 - exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) η - _ = _ := by rw [h1, mul_one] - exact mul_le_mul_of_nonneg_left hb (by norm_num : (0:ℝ) ≤ 1/2) - -lemma tv_realConv (μ ν μ' ν' : G → ℝ) (hμ' : ∀ g, 0 ≤ μ' g) (hμ1 : ∑ g, μ' g = 1) - (hν : ∀ g, 0 ≤ ν g) (hν1 : ∑ g, ν g = 1) : - tv (realConv μ ν) (realConv μ' ν') ≤ tv μ μ' + tv ν ν' := by - exact (tv_triangle _ (realConv μ' ν) _).trans - (add_le_add (tv_realConv_right μ μ' ν hν hν1) (tv_realConv_left μ' ν ν' hμ' hμ1)) - -lemma tv_realPower (μ ν : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (hμ1 : ∑ g, μ g = 1) - (hν : ∀ g, 0 ≤ ν g) (hν1 : ∑ g, ν g = 1) (k : ℕ) : - tv (realPower μ k) (realPower ν k) ≤ (k : ℝ) * tv μ ν := by - induction k with - | zero => simp [realPower, tv] - | succ k ih => - calc - _ ≤ tv μ ν + tv (realPower μ k) (realPower ν k) := - tv_realConv μ (realPower μ k) ν (realPower ν k) hν hν1 (realPower_nonneg μ hμ k) (realPower_sum μ hμ1 k) - _ ≤ tv μ ν + (k : ℝ) * tv μ ν := add_le_add_right ih _ - _ = _ := by push_cast; ring - -end Fourier - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Trimming + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp + +namespace Fourier +open scoped Classical +variable {G : Type} [Fintype G] [Group G] + +omit [Group G] in +lemma tv_nonneg (μ ν : G → ℝ) : 0 ≤ tv μ ν := by unfold tv; positivity + +omit [Group G] in +lemma tv_triangle (μ ν η : G → ℝ) : tv μ η ≤ tv μ ν + tv ν η := by + unfold tv + rw [← mul_add, ← Finset.sum_add_distrib] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact Finset.sum_le_sum (fun g _ => by simpa only [sub_add_sub_cancel] using abs_add_le (μ g-ν g) (ν g-η g)) + +lemma tv_realConv_left (μ ν η : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (h1 : ∑ g, μ g = 1) : + tv (realConv μ ν) (realConv μ η) ≤ tv ν η := by + have hb : (∑ z, |realConv μ ν z - realConv μ η z|) ≤ ∑ z, |ν z-η z| := by + calc + _ = ∑ z, |∑ g, μ g * (ν (g⁻¹*z)-η (g⁻¹*z))| := by + simp only [realConv, mul_sub, Finset.sum_sub_distrib] + _ ≤ ∑ z, ∑ g, μ g * |ν (g⁻¹*z)-η (g⁻¹*z)| := by + apply Finset.sum_le_sum + intro z _ + simpa only [abs_mul, abs_of_nonneg (hμ _)] using + Finset.abs_sum_le_sum_abs (fun g => μ g * (ν (g⁻¹*z)-η (g⁻¹*z))) Finset.univ + _ = (∑ g, μ g) * ∑ z, |ν z-η z| := by + rw [Finset.sum_comm, Finset.sum_mul] + apply Finset.sum_congr rfl + intro g _ + rw [← Finset.mul_sum] + congr 1 + exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) (fun z => |ν z-η z|) + _ = _ := by rw [h1, one_mul] + exact mul_le_mul_of_nonneg_left hb (by norm_num : (0:ℝ) ≤ 1/2) + +lemma tv_realConv_right (μ ν η : G → ℝ) (hη : ∀ g, 0 ≤ η g) (h1 : ∑ g, η g = 1) : + tv (realConv μ η) (realConv ν η) ≤ tv μ ν := by + have hb : (∑ z, |realConv μ η z - realConv ν η z|) ≤ ∑ z, |μ z-ν z| := by + calc + _ = ∑ z, |∑ g, (μ g-ν g) * η (g⁻¹*z)| := by + simp only [realConv, sub_mul, Finset.sum_sub_distrib] + _ ≤ ∑ z, ∑ g, |μ g-ν g| * η (g⁻¹*z) := by + apply Finset.sum_le_sum + intro z _ + simpa only [abs_mul, abs_of_nonneg (hη _)] using + Finset.abs_sum_le_sum_abs (fun g => (μ g-ν g) * η (g⁻¹*z)) Finset.univ + _ = (∑ g, |μ g-ν g|) * ∑ z, η z := by + rw [Finset.sum_comm, Finset.sum_mul] + apply Finset.sum_congr rfl + intro g _ + rw [← Finset.mul_sum] + congr 1 + exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) η + _ = _ := by rw [h1, mul_one] + exact mul_le_mul_of_nonneg_left hb (by norm_num : (0:ℝ) ≤ 1/2) + +lemma tv_realConv (μ ν μ' ν' : G → ℝ) (hμ' : ∀ g, 0 ≤ μ' g) (hμ1 : ∑ g, μ' g = 1) + (hν : ∀ g, 0 ≤ ν g) (hν1 : ∑ g, ν g = 1) : + tv (realConv μ ν) (realConv μ' ν') ≤ tv μ μ' + tv ν ν' := by + exact (tv_triangle _ (realConv μ' ν) _).trans + (add_le_add (tv_realConv_right μ μ' ν hν hν1) (tv_realConv_left μ' ν ν' hμ' hμ1)) + +lemma tv_realPower (μ ν : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (hμ1 : ∑ g, μ g = 1) + (hν : ∀ g, 0 ≤ ν g) (hν1 : ∑ g, ν g = 1) (k : ℕ) : + tv (realPower μ k) (realPower ν k) ≤ (k : ℝ) * tv μ ν := by + induction k with + | zero => simp [realPower, tv] + | succ k ih => + calc + _ ≤ tv μ ν + tv (realPower μ k) (realPower ν k) := + tv_realConv μ (realPower μ k) ν (realPower ν k) hν hν1 (realPower_nonneg μ hμ k) (realPower_sum μ hμ1 k) + _ ≤ tv μ ν + (k : ℝ) * tv μ ν := add_le_add_right ih _ + _ = _ := by push_cast; ring + +end Fourier + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/FreshCoins.lean b/lean/OAI/Probability/ThorpShuffle/FreshCoins.lean index 3e2f5d769d40e5cdcdcefd4b844220321127bfbd..fb58ab88f6546ced8810e4c84421fde25feac7ea 100644 --- a/lean/OAI/Probability/ThorpShuffle/FreshCoins.lean +++ b/lean/OAI/Probability/ThorpShuffle/FreshCoins.lean @@ -1,175 +1,175 @@ -import OAI.Probability.ThorpShuffle.WalshFlow - -namespace OAI - -universe uΩ uι uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def expectedBand (d : ℕ) (v : CenteredState (d + 1)) (t j : ℕ) : ℝ := - mean (fun ω : History (d + 1) t => - bandEnergy (d + 1) (iterateState d v t ω).weight j / 2 ^ (d + 1)) - -def expectedNoise (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : ℝ := - mean (fun ω : History (d + 1) t => - oneFreeEnergy d (iterateState d v t ω).free (iterateState d v t ω).weight) - -theorem mean_div_const {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : - mean (fun ω => f ω / a) = mean f / a := by - simpa only [div_eq_mul_inv] using mean_mul_const f a⁻¹ - -@[simp] theorem expectedBand_zero (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - expectedBand d v t 0 = expectedEnergy d v t := by - unfold expectedBand expectedEnergy - apply mean_congr - intro ω - rw [bandEnergy_zero] - simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin] - -@[simp] theorem expectedBand_full (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - expectedBand d v t (d + 1) = 0 := by - unfold expectedBand - have hz (ω : History (d + 1) t) : - bandEnergy (d + 1) (iterateState d v t ω).weight (d + 1) / 2 ^ (d + 1) = 0 := by - rw [bandEnergy_full, (iterateState d v t ω).mass_zero] - simp - simp_rw [hz] - exact mean_zero - -theorem two_pow_ratio (d j : ℕ) (hj : j ≤ d) : - (2 : ℝ) ^ (d - j) / 2 ^ (d + 1) = (1 / 2 : ℝ) ^ (j + 1) := by - have hd : d + 1 = (d - j) + (j + 1) := by omega - rw [hd, pow_add, div_mul_eq_div_div, div_self (by positivity), div_pow, one_pow] - -theorem expectedBand_succ (d : ℕ) (v : CenteredState (d + 1)) (t j : ℕ) - (hj : j < d + 1) : - expectedBand d v (t + 1) j = expectedBand d v t (j + 1) + - (1 / 2 : ℝ) ^ (j + 1) * expectedNoise d v t := by - unfold expectedBand expectedNoise - rw [mean_history_succ] - have hstep (ω : History (d + 1) t) : - mean (fun c : Coins (d + 1) => - bandEnergy (d + 1) (iterateState d v (t + 1) (Fin.snoc ω c)).weight j / - 2 ^ (d + 1)) = - bandEnergy (d + 1) (iterateState d v t ω).weight (j + 1) / 2 ^ (d + 1) + - (1 / 2 : ℝ) ^ (j + 1) * - oneFreeEnergy d (iterateState d v t ω).free (iterateState d v t ω).weight := by - simp only [iterateState, Fin.snoc_last, Fin.snoc_castSucc, nextState] - rw [mean_div_const, mean_bandEnergy_physicalFlow d j (by omega) - _ _ (iterateState d v t ω).supported, add_div] - rw [← div_mul_eq_mul_div, two_pow_ratio d j (by omega)] - simp_rw [hstep] - rw [mean_add, mean_const_mul] - -theorem expectedEnergy_recurrence (d : ℕ) (v : CenteredState (d + 1)) - (t : ℕ) (ht : d + 1 ≤ t) : - expectedEnergy d v t = ∑ j ∈ Finset.range (d + 1), - (1 / 2 : ℝ) ^ (j + 1) * expectedNoise d v (t - 1 - j) := by - simpa only [expectedBand_zero] using - energy_of_spectral_tracks (d + 1) (expectedBand d v) (expectedNoise d v) - (expectedBand_succ d v) (expectedBand_full d v) t ht - -end Conditional - -namespace Conditional - -theorem mean_product_bits {ι : Type uι} [Fintype ι] [DecidableEq ι] (f : ι → Bool → ℝ) : - mean (fun c : ι → Bool => ∏ i, f i (c i)) = - ∏ i, (f i false + f i true) / 2 := by - classical - unfold mean - rw [← Fintype.prod_sum] - simp only [Fintype.sum_bool, add_comm (f _ true)] - rw [Finset.prod_div_distrib] - simp [Fintype.card_pi, Fintype.card_bool] - -def pairFreeCount {α : Type uα} [Fintype α] (B : Bool × α → Bool) : ℕ := - ∑ i, ((B (false, i)).toNat + (B (true, i)).toNat) - -def pairHalfCount {α : Type uα} [Fintype α] (B : Bool × α → Bool) - (c : α → Bool) (h : Bool) : ℕ := - ∑ i, (B (h ^^ c i, i)).toNat - -theorem local_balance_factor (u v h : Bool) : - mean (fun c : Bool => (5 / 4 : ℝ) ^ (u.toNat + v.toNat) * - (4 / 5 : ℝ) ^ (4 * (if h ^^ c then v else u).toNat)) ≤ - (9 / 10 : ℝ) ^ (u.toNat + v.toNat) := by - cases u <;> cases v <;> cases h <;> norm_num [mean, Fintype.sum_bool] - -theorem balance_exponential_mean {α : Type uα} [Fintype α] [DecidableEq α] - (B : Bool × α → Bool) (h : Bool) : - mean (fun c : α → Bool => (5 / 4 : ℝ) ^ pairFreeCount B * - (4 / 5 : ℝ) ^ (4 * pairHalfCount B c h)) ≤ - (9 / 10 : ℝ) ^ pairFreeCount B := by - classical - have hprod (c : α → Bool) : - (5 / 4 : ℝ) ^ pairFreeCount B * (4 / 5 : ℝ) ^ (4 * pairHalfCount B c h) = - ∏ i, ((5 / 4 : ℝ) ^ ((B (false, i)).toNat + (B (true, i)).toNat) * - (4 / 5 : ℝ) ^ (4 * (B (h ^^ c i, i)).toNat)) := by - simp only [pairFreeCount, pairHalfCount, Finset.mul_sum, ← Finset.prod_pow_eq_pow_sum, - Finset.prod_mul_distrib] - simp_rw [hprod] - rw [mean_product_bits (fun i (c : Bool) => - (5 / 4 : ℝ) ^ ((B (false, i)).toNat + (B (true, i)).toNat) * - (4 / 5 : ℝ) ^ (4 * (B (h ^^ c, i)).toNat))] - rw [pairFreeCount, ← Finset.prod_pow_eq_pow_sum] - apply Finset.prod_le_prod₀ - · intro i _ - positivity - · intro i _ - have hlocal := local_balance_factor (B (false, i)) (B (true, i)) h - have hbit (c : Bool) : B (h ^^ c, i) = if h ^^ c then B (true, i) else B (false, i) := by - cases (h ^^ c) <;> rfl - simp only [hbit] - cases h <;> simpa [mean, Fintype.sum_bool, add_comm] using hlocal - -theorem pair_half_balance {α : Type uα} [Fintype α] [DecidableEq α] - (B : Bool × α → Bool) (h : Bool) : - mean (fun c : α → Bool => - if 4 * pairHalfCount B c h < pairFreeCount B then (1 : ℝ) else 0) ≤ - (9 / 10 : ℝ) ^ pairFreeCount B := by - apply le_trans (mean_le_mean (fun c => ?_)) (balance_exponential_mean B h) - by_cases hc : 4 * pairHalfCount B c h < pairFreeCount B - · rw [ite_eq_left hc] - have hp : (5 / 4 : ℝ) ^ (4 * pairHalfCount B c h) ≤ - (5 / 4 : ℝ) ^ pairFreeCount B := - pow_le_pow_right₀ (by norm_num) hc.le - have hr : (4 / 5 : ℝ) = (5 / 4 : ℝ)⁻¹ := by norm_num - rw [hr, inv_pow, ← div_eq_mul_inv] - exact (le_div_iff₀ (by positivity)).mpr (by simpa using hp) - · rw [ite_eq_right hc] - positivity - -theorem pair_both_half_balance {α : Type uα} [Fintype α] [DecidableEq α] - (B : Bool × α → Bool) : - mean (fun c : α → Bool => - if (4 * pairHalfCount B c false < pairFreeCount B) ∨ - (4 * pairHalfCount B c true < pairFreeCount B) then (1 : ℝ) else 0) ≤ - 2 * (9 / 10 : ℝ) ^ pairFreeCount B := by - have hm : mean (fun c : α → Bool => - if (4 * pairHalfCount B c false < pairFreeCount B) ∨ - (4 * pairHalfCount B c true < pairFreeCount B) then (1 : ℝ) else 0) ≤ - mean (fun c : α → Bool => - (if 4 * pairHalfCount B c false < pairFreeCount B then (1 : ℝ) else 0) + - (if 4 * pairHalfCount B c true < pairFreeCount B then (1 : ℝ) else 0)) := by - apply mean_le_mean - intro c - split_ifs <;> norm_num at * - all_goals omega - rw [mean_add] at hm - linarith [pair_half_balance B false, pair_half_balance B true] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.WalshFlow + +namespace OAI + +universe uΩ uι uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def expectedBand (d : ℕ) (v : CenteredState (d + 1)) (t j : ℕ) : ℝ := + mean (fun ω : History (d + 1) t => + bandEnergy (d + 1) (iterateState d v t ω).weight j / 2 ^ (d + 1)) + +def expectedNoise (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : ℝ := + mean (fun ω : History (d + 1) t => + oneFreeEnergy d (iterateState d v t ω).free (iterateState d v t ω).weight) + +theorem mean_div_const {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) (a : ℝ) : + mean (fun ω => f ω / a) = mean f / a := by + simpa only [div_eq_mul_inv] using mean_mul_const f a⁻¹ + +@[simp] theorem expectedBand_zero (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + expectedBand d v t 0 = expectedEnergy d v t := by + unfold expectedBand expectedEnergy + apply mean_congr + intro ω + rw [bandEnergy_zero] + simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin] + +@[simp] theorem expectedBand_full (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + expectedBand d v t (d + 1) = 0 := by + unfold expectedBand + have hz (ω : History (d + 1) t) : + bandEnergy (d + 1) (iterateState d v t ω).weight (d + 1) / 2 ^ (d + 1) = 0 := by + rw [bandEnergy_full, (iterateState d v t ω).mass_zero] + simp + simp_rw [hz] + exact mean_zero + +theorem two_pow_ratio (d j : ℕ) (hj : j ≤ d) : + (2 : ℝ) ^ (d - j) / 2 ^ (d + 1) = (1 / 2 : ℝ) ^ (j + 1) := by + have hd : d + 1 = (d - j) + (j + 1) := by omega + rw [hd, pow_add, div_mul_eq_div_div, div_self (by positivity), div_pow, one_pow] + +theorem expectedBand_succ (d : ℕ) (v : CenteredState (d + 1)) (t j : ℕ) + (hj : j < d + 1) : + expectedBand d v (t + 1) j = expectedBand d v t (j + 1) + + (1 / 2 : ℝ) ^ (j + 1) * expectedNoise d v t := by + unfold expectedBand expectedNoise + rw [mean_history_succ] + have hstep (ω : History (d + 1) t) : + mean (fun c : Coins (d + 1) => + bandEnergy (d + 1) (iterateState d v (t + 1) (Fin.snoc ω c)).weight j / + 2 ^ (d + 1)) = + bandEnergy (d + 1) (iterateState d v t ω).weight (j + 1) / 2 ^ (d + 1) + + (1 / 2 : ℝ) ^ (j + 1) * + oneFreeEnergy d (iterateState d v t ω).free (iterateState d v t ω).weight := by + simp only [iterateState, Fin.snoc_last, Fin.snoc_castSucc, nextState] + rw [mean_div_const, mean_bandEnergy_physicalFlow d j (by omega) + _ _ (iterateState d v t ω).supported, add_div] + rw [← div_mul_eq_mul_div, two_pow_ratio d j (by omega)] + simp_rw [hstep] + rw [mean_add, mean_const_mul] + +theorem expectedEnergy_recurrence (d : ℕ) (v : CenteredState (d + 1)) + (t : ℕ) (ht : d + 1 ≤ t) : + expectedEnergy d v t = ∑ j ∈ Finset.range (d + 1), + (1 / 2 : ℝ) ^ (j + 1) * expectedNoise d v (t - 1 - j) := by + simpa only [expectedBand_zero] using + energy_of_spectral_tracks (d + 1) (expectedBand d v) (expectedNoise d v) + (expectedBand_succ d v) (expectedBand_full d v) t ht + +end Conditional + +namespace Conditional + +theorem mean_product_bits {ι : Type uι} [Fintype ι] [DecidableEq ι] (f : ι → Bool → ℝ) : + mean (fun c : ι → Bool => ∏ i, f i (c i)) = + ∏ i, (f i false + f i true) / 2 := by + classical + unfold mean + rw [← Fintype.prod_sum] + simp only [Fintype.sum_bool, add_comm (f _ true)] + rw [Finset.prod_div_distrib] + simp [Fintype.card_pi, Fintype.card_bool] + +def pairFreeCount {α : Type uα} [Fintype α] (B : Bool × α → Bool) : ℕ := + ∑ i, ((B (false, i)).toNat + (B (true, i)).toNat) + +def pairHalfCount {α : Type uα} [Fintype α] (B : Bool × α → Bool) + (c : α → Bool) (h : Bool) : ℕ := + ∑ i, (B (h ^^ c i, i)).toNat + +theorem local_balance_factor (u v h : Bool) : + mean (fun c : Bool => (5 / 4 : ℝ) ^ (u.toNat + v.toNat) * + (4 / 5 : ℝ) ^ (4 * (if h ^^ c then v else u).toNat)) ≤ + (9 / 10 : ℝ) ^ (u.toNat + v.toNat) := by + cases u <;> cases v <;> cases h <;> norm_num [mean, Fintype.sum_bool] + +theorem balance_exponential_mean {α : Type uα} [Fintype α] [DecidableEq α] + (B : Bool × α → Bool) (h : Bool) : + mean (fun c : α → Bool => (5 / 4 : ℝ) ^ pairFreeCount B * + (4 / 5 : ℝ) ^ (4 * pairHalfCount B c h)) ≤ + (9 / 10 : ℝ) ^ pairFreeCount B := by + classical + have hprod (c : α → Bool) : + (5 / 4 : ℝ) ^ pairFreeCount B * (4 / 5 : ℝ) ^ (4 * pairHalfCount B c h) = + ∏ i, ((5 / 4 : ℝ) ^ ((B (false, i)).toNat + (B (true, i)).toNat) * + (4 / 5 : ℝ) ^ (4 * (B (h ^^ c i, i)).toNat)) := by + simp only [pairFreeCount, pairHalfCount, Finset.mul_sum, ← Finset.prod_pow_eq_pow_sum, + Finset.prod_mul_distrib] + simp_rw [hprod] + rw [mean_product_bits (fun i (c : Bool) => + (5 / 4 : ℝ) ^ ((B (false, i)).toNat + (B (true, i)).toNat) * + (4 / 5 : ℝ) ^ (4 * (B (h ^^ c, i)).toNat))] + rw [pairFreeCount, ← Finset.prod_pow_eq_pow_sum] + apply Finset.prod_le_prod₀ + · intro i _ + positivity + · intro i _ + have hlocal := local_balance_factor (B (false, i)) (B (true, i)) h + have hbit (c : Bool) : B (h ^^ c, i) = if h ^^ c then B (true, i) else B (false, i) := by + cases (h ^^ c) <;> rfl + simp only [hbit] + cases h <;> simpa [mean, Fintype.sum_bool, add_comm] using hlocal + +theorem pair_half_balance {α : Type uα} [Fintype α] [DecidableEq α] + (B : Bool × α → Bool) (h : Bool) : + mean (fun c : α → Bool => + if 4 * pairHalfCount B c h < pairFreeCount B then (1 : ℝ) else 0) ≤ + (9 / 10 : ℝ) ^ pairFreeCount B := by + apply le_trans (mean_le_mean (fun c => ?_)) (balance_exponential_mean B h) + by_cases hc : 4 * pairHalfCount B c h < pairFreeCount B + · rw [ite_eq_left hc] + have hp : (5 / 4 : ℝ) ^ (4 * pairHalfCount B c h) ≤ + (5 / 4 : ℝ) ^ pairFreeCount B := + pow_le_pow_right₀ (by norm_num) hc.le + have hr : (4 / 5 : ℝ) = (5 / 4 : ℝ)⁻¹ := by norm_num + rw [hr, inv_pow, ← div_eq_mul_inv] + exact (le_div_iff₀ (by positivity)).mpr (by simpa using hp) + · rw [ite_eq_right hc] + positivity + +theorem pair_both_half_balance {α : Type uα} [Fintype α] [DecidableEq α] + (B : Bool × α → Bool) : + mean (fun c : α → Bool => + if (4 * pairHalfCount B c false < pairFreeCount B) ∨ + (4 * pairHalfCount B c true < pairFreeCount B) then (1 : ℝ) else 0) ≤ + 2 * (9 / 10 : ℝ) ^ pairFreeCount B := by + have hm : mean (fun c : α → Bool => + if (4 * pairHalfCount B c false < pairFreeCount B) ∨ + (4 * pairHalfCount B c true < pairFreeCount B) then (1 : ℝ) else 0) ≤ + mean (fun c : α → Bool => + (if 4 * pairHalfCount B c false < pairFreeCount B then (1 : ℝ) else 0) + + (if 4 * pairHalfCount B c true < pairFreeCount B then (1 : ℝ) else 0)) := by + apply mean_le_mean + intro c + split_ifs <;> norm_num at * + all_goals omega + rw [mean_add] at hm + linarith [pair_half_balance B false, pair_half_balance B true] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/HalfHistories.lean b/lean/OAI/Probability/ThorpShuffle/HalfHistories.lean index f442d88234344f690c54a65b4d500dd55090d191..0f0ee21f065a9b549a77da73112cd17ced43e902 100644 --- a/lean/OAI/Probability/ThorpShuffle/HalfHistories.lean +++ b/lean/OAI/Probability/ThorpShuffle/HalfHistories.lean @@ -1,225 +1,225 @@ -import OAI.Probability.ThorpShuffle.FreshCoins - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -structure RawState (d : ℕ) where - free : Position d → Bool - weight : Position d → ℝ - -def rawNext (d : ℕ) (v : RawState (d + 1)) (c : Coins (d + 1)) : RawState (d + 1) where - free := physicalFree d v.free c - weight := physicalFlow d v.free v.weight c - -def rawIterate (d : ℕ) (v : RawState (d + 1)) : - (t : ℕ) → History (d + 1) t → RawState (d + 1) - | 0, _ => v - | t + 1, ω => rawNext d (rawIterate d v t (fun i => ω i.castSucc)) (ω (Fin.last t)) - -def CenteredState.raw {d : ℕ} (v : CenteredState d) : RawState d := ⟨v.free, v.weight⟩ - -theorem iterateState_raw (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) - (ω : History (d + 1) t) : - (iterateState d v t ω).raw = rawIterate d v.raw t ω := by - induction t with - | zero => rfl - | succ t ih => - change rawNext d (iterateState d v t (fun i => ω i.castSucc)).raw (ω (Fin.last t)) = _ - rw [ih] - rfl - -theorem rawIterate_free (d : ℕ) (v : RawState (d + 1)) (t : ℕ) - (ω : History (d + 1) t) (x : Position (d + 1)) : - (rawIterate d v t ω).free x = v.free ((run (d + 1) t ω).symm x) := by - induction t generalizing x with - | zero => simp only [rawIterate, run_zero]; rfl - | succ t ih => - change (rawIterate d v t (fun i => ω i.castSucc)).free - ((step (d + 1) (ω (Fin.last t))).symm x) = _ - rw [ih, run_succ] - rfl - -theorem mean_bool (f : Bool → ℝ) : mean f = (f false + f true) / 2 := by - simp [mean, add_comm] - -theorem pairUpdate_mean_fst (u v : Bool) (a b : ℝ) : - mean (fun c : Bool => (pairUpdate u v a b c).1) = (a + b) / 2 := by - cases u <;> cases v <;> simp [mean_bool, pairUpdate] - -theorem pairUpdate_mean_snd (u v : Bool) (a b : ℝ) : - mean (fun c : Bool => (pairUpdate u v a b c).2) = (a + b) / 2 := by - cases u <;> cases v <;> simp [mean_bool, pairUpdate] - all_goals ring - -theorem mean_sign {α : Type uα} [Fintype α] [DecidableEq α] (i : α) : - mean (fun c : α → Bool => sign (c i)) = 0 := by - simp [mean, sum_sign] - -theorem mean_coin_eval {α : Type uα} [Fintype α] [DecidableEq α] - (i : α) (f : Bool → ℝ) : mean (fun c : α → Bool => f (c i)) = mean f := by - have hfun (b : Bool) : f b = (f false + f true) / 2 + - sign b * ((f false - f true) / 2) := by - cases b <;> simp [sign] <;> ring - calc - _ = mean (fun c : α → Bool => (f false + f true) / 2 + - sign (c i) * ((f false - f true) / 2)) := mean_congr (fun c => hfun (c i)) - _ = mean f := by - rw [mean_add, mean_const, mean_mul_const] - simp only [mean_sign, zero_mul, add_zero, mean_bool] - -theorem mean_physicalFlow_snoc (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (x : Position d) (b : Bool) : - mean (fun c : Coins (d + 1) => physicalFlow d B w c (Fin.snoc x b)) = - (w (Fin.cons false x) + w (Fin.cons true x)) / 2 := by - rw [← scatterPosition_eq_snoc] - simp only [physicalFlow_scatter] - cases b - · change mean (fun c : Position d → Bool => - (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1) = _ - rw [mean_coin_eval x (fun c => (pairUpdate (B (Fin.cons false x)) - (B (Fin.cons true x)) (w (Fin.cons false x)) (w (Fin.cons true x)) c).1), - pairUpdate_mean_fst] - · change mean (fun c : Position d → Bool => - (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2) = _ - rw [mean_coin_eval x (fun c => (pairUpdate (B (Fin.cons false x)) - (B (Fin.cons true x)) (w (Fin.cons false x)) (w (Fin.cons true x)) c).2), - pairUpdate_mean_snd] - -end Conditional - -namespace Conditional - -def firstMean (d : ℕ) (w : Position (d + 1) → ℝ) (x : Position d) : ℝ := - mean (fun b : Bool => w (Fin.cons b x)) - -def meanLayer : (d : ℕ) → (Position d → ℝ) → Position d → ℝ - | 0, w => w - | d + 1, w => fun x => firstMean d w (Fin.init x) - -theorem mean_physicalFlow (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (x : Position (d + 1)) : - mean (fun c : Coins (d + 1) => physicalFlow d B w c x) = - meanLayer (d + 1) w x := by - conv_lhs => rw [← Fin.snoc_init_self x] - rw [mean_physicalFlow_snoc] - change _ = mean (fun b : Bool => w (Fin.cons b (Fin.init x))) - exact (mean_bool (fun b : Bool => w (Fin.cons b (Fin.init x)))).symm - -theorem init_cons (d : ℕ) (b : Bool) (x : Position (d + 1)) : - (Fin.init (Fin.cons b x : Position (d + 2)) : Position (d + 1)) = - (Fin.cons b (Fin.init x) : Position (d + 1)) := by - funext i - refine Fin.cases ?_ (fun j => ?_) i <;> rfl - -theorem meanLayer_lift (d : ℕ) (w : Position d → ℝ) : - meanLayer (d + 1) (fun x => w (Fin.init x)) = - fun x => meanLayer d w (Fin.init x) := by - funext x - cases d with - | zero => - have hall (b : Bool) : Fin.init (Fin.cons b (Fin.init x) : Position 1) = Fin.init x := - Subsingleton.elim _ _ - simp only [meanLayer, firstMean, hall, mean_const] - | succ d => - simp only [meanLayer, firstMean, init_cons] - -theorem mean_iterations_dimension (d t : ℕ) (w : Position (d + 1) → ℝ) - (x : Position (d + 1)) : - (meanLayer (d + 1))^[t + 1] w x = - (meanLayer d)^[t] (firstMean d w) (Fin.init x) := by - have hs : Function.Semiconj (fun w : Position d → ℝ => fun x : Position (d + 1) => w (Fin.init x)) - (meanLayer d) (meanLayer (d + 1)) := fun w => (meanLayer_lift d w).symm - rw [Function.iterate_succ_apply] - exact (congrFun (hs.iterate_right t (firstMean d w)) x).symm - -theorem mean_firstMean (d : ℕ) (w : Position (d + 1) → ℝ) : - mean (firstMean d w) = mean w := by - have h := mean_equiv (splitPosition d).symm w - rw [mean_prod] at h - rw [← h, mean_comm] - rfl - -theorem mean_iterations_sweep (d : ℕ) (w : Position d → ℝ) (x : Position d) : - (meanLayer d)^[d] w x = mean w := by - induction d with - | zero => - change w x = mean w - have hw : w = fun _ => w x := funext (fun y => congrArg w (Subsingleton.elim y x)) - rw [hw, mean_const] - | succ d ih => - rw [mean_iterations_dimension, ih, mean_firstMean] - -theorem mean_rawIterate_weight (d : ℕ) (v : RawState (d + 1)) (t : ℕ) - (x : Position (d + 1)) : - mean (fun ω : History (d + 1) t => (rawIterate d v t ω).weight x) = - (meanLayer (d + 1))^[t] v.weight x := by - induction t generalizing x with - | zero => simp [rawIterate, mean_const] - | succ t ih => - rw [mean_history_succ] - have hi (ω : History (d + 1) t) : - mean (fun c : Coins (d + 1) => - (rawIterate d v (t + 1) (Fin.snoc ω c)).weight x) = - meanLayer (d + 1) (rawIterate d v t ω).weight x := by - simp only [rawIterate, Fin.snoc_castSucc, Fin.snoc_last, rawNext] - exact mean_physicalFlow _ _ _ _ - simp_rw [hi] - change mean (fun ω : History (d + 1) t => - mean (fun b : Bool => (rawIterate d v t ω).weight (Fin.cons b (Fin.init x)))) = _ - rw [mean_comm] - simp_rw [ih] - rw [Function.iterate_succ_apply'] - rfl - -theorem mean_rawIterate_sweep (d : ℕ) (v : RawState (d + 1)) - (x : Position (d + 1)) : - mean (fun ω : History (d + 1) (d + 1) => (rawIterate d v (d + 1) ω).weight x) = - mean v.weight := by - rw [mean_rawIterate_weight, mean_iterations_sweep] - -theorem rawIterate_indicator (d : ℕ) (B : Position (d + 1) → Bool) (t : ℕ) - (ω : History (d + 1) t) (x : Position (d + 1)) : - (rawIterate d ⟨B, fun y => if B y then 1 else 0⟩ t ω).weight x = - if (rawIterate d ⟨B, fun y => if B y then 1 else 0⟩ t ω).free x then 1 else 0 := by - induction t generalizing x with - | zero => rfl - | succ t ih => - change physicalFlow d _ (rawIterate d _ t (fun i => ω i.castSucc)).weight - (ω (Fin.last t)) x = _ - rw [funext (ih (fun i => ω i.castSucc))] - exact physicalFlow_uniform _ _ _ _ _ - -theorem mean_free_after_sweep (d : ℕ) (B : Position (d + 1) → Bool) - (x : Position (d + 1)) : - mean (fun ω : History (d + 1) (d + 1) => - if B ((run (d + 1) (d + 1) ω).symm x) then (1 : ℝ) else 0) = - (freeCount B : ℝ) / Fintype.card (Position (d + 1)) := by - let v : RawState (d + 1) := ⟨B, fun y => if B y then 1 else 0⟩ - have h (ω : History (d + 1) (d + 1)) : - (if B ((run (d + 1) (d + 1) ω).symm x) then (1 : ℝ) else 0) = - (rawIterate d v (d + 1) ω).weight x := by - rw [rawIterate_indicator, rawIterate_free] - simp_rw [h] - rw [mean_rawIterate_sweep] - change (∑ y, if B y then (1 : ℝ) else 0) / _ = _ - rw [sum_free_indicator] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.FreshCoins + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +structure RawState (d : ℕ) where + free : Position d → Bool + weight : Position d → ℝ + +def rawNext (d : ℕ) (v : RawState (d + 1)) (c : Coins (d + 1)) : RawState (d + 1) where + free := physicalFree d v.free c + weight := physicalFlow d v.free v.weight c + +def rawIterate (d : ℕ) (v : RawState (d + 1)) : + (t : ℕ) → History (d + 1) t → RawState (d + 1) + | 0, _ => v + | t + 1, ω => rawNext d (rawIterate d v t (fun i => ω i.castSucc)) (ω (Fin.last t)) + +def CenteredState.raw {d : ℕ} (v : CenteredState d) : RawState d := ⟨v.free, v.weight⟩ + +theorem iterateState_raw (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) + (ω : History (d + 1) t) : + (iterateState d v t ω).raw = rawIterate d v.raw t ω := by + induction t with + | zero => rfl + | succ t ih => + change rawNext d (iterateState d v t (fun i => ω i.castSucc)).raw (ω (Fin.last t)) = _ + rw [ih] + rfl + +theorem rawIterate_free (d : ℕ) (v : RawState (d + 1)) (t : ℕ) + (ω : History (d + 1) t) (x : Position (d + 1)) : + (rawIterate d v t ω).free x = v.free ((run (d + 1) t ω).symm x) := by + induction t generalizing x with + | zero => simp only [rawIterate, run_zero]; rfl + | succ t ih => + change (rawIterate d v t (fun i => ω i.castSucc)).free + ((step (d + 1) (ω (Fin.last t))).symm x) = _ + rw [ih, run_succ] + rfl + +theorem mean_bool (f : Bool → ℝ) : mean f = (f false + f true) / 2 := by + simp [mean, add_comm] + +theorem pairUpdate_mean_fst (u v : Bool) (a b : ℝ) : + mean (fun c : Bool => (pairUpdate u v a b c).1) = (a + b) / 2 := by + cases u <;> cases v <;> simp [mean_bool, pairUpdate] + +theorem pairUpdate_mean_snd (u v : Bool) (a b : ℝ) : + mean (fun c : Bool => (pairUpdate u v a b c).2) = (a + b) / 2 := by + cases u <;> cases v <;> simp [mean_bool, pairUpdate] + all_goals ring + +theorem mean_sign {α : Type uα} [Fintype α] [DecidableEq α] (i : α) : + mean (fun c : α → Bool => sign (c i)) = 0 := by + simp [mean, sum_sign] + +theorem mean_coin_eval {α : Type uα} [Fintype α] [DecidableEq α] + (i : α) (f : Bool → ℝ) : mean (fun c : α → Bool => f (c i)) = mean f := by + have hfun (b : Bool) : f b = (f false + f true) / 2 + + sign b * ((f false - f true) / 2) := by + cases b <;> simp [sign] <;> ring + calc + _ = mean (fun c : α → Bool => (f false + f true) / 2 + + sign (c i) * ((f false - f true) / 2)) := mean_congr (fun c => hfun (c i)) + _ = mean f := by + rw [mean_add, mean_const, mean_mul_const] + simp only [mean_sign, zero_mul, add_zero, mean_bool] + +theorem mean_physicalFlow_snoc (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (x : Position d) (b : Bool) : + mean (fun c : Coins (d + 1) => physicalFlow d B w c (Fin.snoc x b)) = + (w (Fin.cons false x) + w (Fin.cons true x)) / 2 := by + rw [← scatterPosition_eq_snoc] + simp only [physicalFlow_scatter] + cases b + · change mean (fun c : Position d → Bool => + (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1) = _ + rw [mean_coin_eval x (fun c => (pairUpdate (B (Fin.cons false x)) + (B (Fin.cons true x)) (w (Fin.cons false x)) (w (Fin.cons true x)) c).1), + pairUpdate_mean_fst] + · change mean (fun c : Position d → Bool => + (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2) = _ + rw [mean_coin_eval x (fun c => (pairUpdate (B (Fin.cons false x)) + (B (Fin.cons true x)) (w (Fin.cons false x)) (w (Fin.cons true x)) c).2), + pairUpdate_mean_snd] + +end Conditional + +namespace Conditional + +def firstMean (d : ℕ) (w : Position (d + 1) → ℝ) (x : Position d) : ℝ := + mean (fun b : Bool => w (Fin.cons b x)) + +def meanLayer : (d : ℕ) → (Position d → ℝ) → Position d → ℝ + | 0, w => w + | d + 1, w => fun x => firstMean d w (Fin.init x) + +theorem mean_physicalFlow (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (x : Position (d + 1)) : + mean (fun c : Coins (d + 1) => physicalFlow d B w c x) = + meanLayer (d + 1) w x := by + conv_lhs => rw [← Fin.snoc_init_self x] + rw [mean_physicalFlow_snoc] + change _ = mean (fun b : Bool => w (Fin.cons b (Fin.init x))) + exact (mean_bool (fun b : Bool => w (Fin.cons b (Fin.init x)))).symm + +theorem init_cons (d : ℕ) (b : Bool) (x : Position (d + 1)) : + (Fin.init (Fin.cons b x : Position (d + 2)) : Position (d + 1)) = + (Fin.cons b (Fin.init x) : Position (d + 1)) := by + funext i + refine Fin.cases ?_ (fun j => ?_) i <;> rfl + +theorem meanLayer_lift (d : ℕ) (w : Position d → ℝ) : + meanLayer (d + 1) (fun x => w (Fin.init x)) = + fun x => meanLayer d w (Fin.init x) := by + funext x + cases d with + | zero => + have hall (b : Bool) : Fin.init (Fin.cons b (Fin.init x) : Position 1) = Fin.init x := + Subsingleton.elim _ _ + simp only [meanLayer, firstMean, hall, mean_const] + | succ d => + simp only [meanLayer, firstMean, init_cons] + +theorem mean_iterations_dimension (d t : ℕ) (w : Position (d + 1) → ℝ) + (x : Position (d + 1)) : + (meanLayer (d + 1))^[t + 1] w x = + (meanLayer d)^[t] (firstMean d w) (Fin.init x) := by + have hs : Function.Semiconj (fun w : Position d → ℝ => fun x : Position (d + 1) => w (Fin.init x)) + (meanLayer d) (meanLayer (d + 1)) := fun w => (meanLayer_lift d w).symm + rw [Function.iterate_succ_apply] + exact (congrFun (hs.iterate_right t (firstMean d w)) x).symm + +theorem mean_firstMean (d : ℕ) (w : Position (d + 1) → ℝ) : + mean (firstMean d w) = mean w := by + have h := mean_equiv (splitPosition d).symm w + rw [mean_prod] at h + rw [← h, mean_comm] + rfl + +theorem mean_iterations_sweep (d : ℕ) (w : Position d → ℝ) (x : Position d) : + (meanLayer d)^[d] w x = mean w := by + induction d with + | zero => + change w x = mean w + have hw : w = fun _ => w x := funext (fun y => congrArg w (Subsingleton.elim y x)) + rw [hw, mean_const] + | succ d ih => + rw [mean_iterations_dimension, ih, mean_firstMean] + +theorem mean_rawIterate_weight (d : ℕ) (v : RawState (d + 1)) (t : ℕ) + (x : Position (d + 1)) : + mean (fun ω : History (d + 1) t => (rawIterate d v t ω).weight x) = + (meanLayer (d + 1))^[t] v.weight x := by + induction t generalizing x with + | zero => simp [rawIterate, mean_const] + | succ t ih => + rw [mean_history_succ] + have hi (ω : History (d + 1) t) : + mean (fun c : Coins (d + 1) => + (rawIterate d v (t + 1) (Fin.snoc ω c)).weight x) = + meanLayer (d + 1) (rawIterate d v t ω).weight x := by + simp only [rawIterate, Fin.snoc_castSucc, Fin.snoc_last, rawNext] + exact mean_physicalFlow _ _ _ _ + simp_rw [hi] + change mean (fun ω : History (d + 1) t => + mean (fun b : Bool => (rawIterate d v t ω).weight (Fin.cons b (Fin.init x)))) = _ + rw [mean_comm] + simp_rw [ih] + rw [Function.iterate_succ_apply'] + rfl + +theorem mean_rawIterate_sweep (d : ℕ) (v : RawState (d + 1)) + (x : Position (d + 1)) : + mean (fun ω : History (d + 1) (d + 1) => (rawIterate d v (d + 1) ω).weight x) = + mean v.weight := by + rw [mean_rawIterate_weight, mean_iterations_sweep] + +theorem rawIterate_indicator (d : ℕ) (B : Position (d + 1) → Bool) (t : ℕ) + (ω : History (d + 1) t) (x : Position (d + 1)) : + (rawIterate d ⟨B, fun y => if B y then 1 else 0⟩ t ω).weight x = + if (rawIterate d ⟨B, fun y => if B y then 1 else 0⟩ t ω).free x then 1 else 0 := by + induction t generalizing x with + | zero => rfl + | succ t ih => + change physicalFlow d _ (rawIterate d _ t (fun i => ω i.castSucc)).weight + (ω (Fin.last t)) x = _ + rw [funext (ih (fun i => ω i.castSucc))] + exact physicalFlow_uniform _ _ _ _ _ + +theorem mean_free_after_sweep (d : ℕ) (B : Position (d + 1) → Bool) + (x : Position (d + 1)) : + mean (fun ω : History (d + 1) (d + 1) => + if B ((run (d + 1) (d + 1) ω).symm x) then (1 : ℝ) else 0) = + (freeCount B : ℝ) / Fintype.card (Position (d + 1)) := by + let v : RawState (d + 1) := ⟨B, fun y => if B y then 1 else 0⟩ + have h (ω : History (d + 1) (d + 1)) : + (if B ((run (d + 1) (d + 1) ω).symm x) then (1 : ℝ) else 0) = + (rawIterate d v (d + 1) ω).weight x := by + rw [rawIterate_indicator, rawIterate_free] + simp_rw [h] + rw [mean_rawIterate_sweep] + change (∑ y, if B y then (1 : ℝ) else 0) / _ = _ + rw [sum_free_indicator] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Irreducibility.lean b/lean/OAI/Probability/ThorpShuffle/Irreducibility.lean index 3885d1c845dbed16569bad7da4dff15ac5afc138..5333473ef82eacc00d65b2b2fb6d28baf6cb9503 100644 --- a/lean/OAI/Probability/ThorpShuffle/Irreducibility.lean +++ b/lean/OAI/Probability/ThorpShuffle/Irreducibility.lean @@ -1,230 +1,230 @@ -import OAI.Probability.ThorpShuffle.Polytabloids - -namespace OAI - -universe uI uX uK - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical - -variable {n : ℕ} {D : YoungDiagram} - -def Standard (t : Fin n ≃ Cells D) : Prop := StrictMono t.symm - -lemma standard_row_lt_iff (t : Fin n ≃ Cells D) (ht : Standard t) (x y : Fin n) - (hr : (t x).val.1 = (t y).val.1) : x < y ↔ (t x).val.2 < (t y).val.2 := by - constructor - · intro hxy - by_contra hn - have hc : (t y).val.2 ≤ (t x).val.2 := Nat.le_of_not_gt hn - have hyx : t y ≤ t x := ⟨by omega, hc⟩ - have hh : y ≤ x := by simpa only [Equiv.symm_apply_apply] using ht.monotone hyx - exact not_le_of_gt hxy hh - · intro hc - have hxy : t x < t y := by - refine lt_iff_le_not_ge.mpr ⟨⟨by omega, hc.le⟩, ?_⟩ - intro hh - exact not_le_of_gt hc hh.2 - simpa only [Equiv.symm_apply_apply] using ht hxy - -lemma standard_col_lt_iff (t : Fin n ≃ Cells D) (ht : Standard t) (x y : Fin n) - (hc : (t x).val.2 = (t y).val.2) : x < y ↔ (t x).val.1 < (t y).val.1 := by - constructor - · intro hxy - by_contra hn - have hr : (t y).val.1 ≤ (t x).val.1 := Nat.le_of_not_gt hn - have hyx : t y ≤ t x := ⟨hr, by omega⟩ - have hh : y ≤ x := by simpa only [Equiv.symm_apply_apply] using ht.monotone hyx - exact not_le_of_gt hxy hh - · intro hr - have hxy : t x < t y := by - refine lt_iff_le_not_ge.mpr ⟨⟨hr.le, by omega⟩, ?_⟩ - intro hh - exact not_le_of_gt hr hh.1 - simpa only [Equiv.symm_apply_apply] using ht hxy - -lemma column_eq_rowRank (t : Fin n ≃ Cells D) (ht : Standard t) (x : Fin n) : - Fintype.card {y : Fin n // y < x ∧ (t y).val.1 = (t x).val.1} = (t x).val.2 := by - let e : {y : Fin n // y < x ∧ (t y).val.1 = (t x).val.1} ≃ Fin ((t x).val.2) := { - toFun := fun y => ⟨(t y.val).val.2, (standard_row_lt_iff t ht y.val x y.property.2).mp y.property.1⟩ - invFun := fun j => ⟨t.symm ⟨((t x).val.1, j), D.up_left_mem le_rfl j.isLt.le (t x).property⟩, by - constructor - · apply (standard_row_lt_iff t ht _ x (by simp)).mpr - simpa only [Equiv.apply_symm_apply] using j.isLt - · simp⟩ - left_inv := by - intro y - apply Subtype.ext - apply t.injective - simp only [Equiv.apply_symm_apply] - apply Subtype.ext - exact Prod.ext y.property.2.symm rfl - right_inv := by intro j; apply Fin.ext; simp } - exact (Fintype.card_congr e).trans (Fintype.card_fin _) - -lemma standard_eq_of_rows (t u : Fin n ≃ Cells D) (ht : Standard t) (hu : Standard u) - (hr : ∀ x, (t x).val.1 = (u x).val.1) : t = u := by - apply Equiv.ext - intro x - apply Subtype.ext - apply Prod.ext (hr x) - rw [← column_eq_rowRank t ht x, ← column_eq_rowRank u hu x] - exact Fintype.card_congr ((Equiv.refl (Fin n)).subtypeEquiv (fun y => by simp only [Equiv.refl_apply, hr])) - -end Thorp.Young - -namespace Thorp.Specht -open scoped Classical - -theorem independent_of_leading {I : Type uI} {X : Type uX} {K : Type uK} [Fintype I] [Fintype X] [LinearOrder K] - (e : I → EuclideanSpace ℂ X) (b : I → X) (key : X → K) - (hinj : Function.Injective (key ∘ b)) (hdiag : ∀ i, e i (b i) ≠ 0) - (htri : ∀ i x, e i x ≠ 0 → key (b i) ≤ key x) : LinearIndependent ℂ e := by - let : LinearOrder I := LinearOrder.lift' (key ∘ b) hinj - rw [linearIndependent_iff'] - intro s a ha i hi - by_contra hai - let S := s.filter fun j => a j ≠ 0 - have hs : S.Nonempty := ⟨i, Finset.mem_filter.mpr ⟨hi, hai⟩⟩ - let j := S.min' hs - have hj : j ∈ S := S.min'_mem hs - have hj' : j ∈ s := (Finset.mem_filter.mp hj).1 - have haz : a j ≠ 0 := (Finset.mem_filter.mp hj).2 - have hval := congrArg (fun v : EuclideanSpace ℂ X => v (b j)) ha - simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, smul_eq_mul, PiLp.zero_apply] at hval - rw [Finset.sum_eq_single_of_mem j hj'] at hval - · exact (mul_ne_zero haz (hdiag j)) hval - · intro k hk hkj - by_cases hak : a k = 0 - · simp [hak] - have hks : k ∈ S := Finset.mem_filter.mpr ⟨hk, hak⟩ - have hjk : j ≤ k := S.min'_le k hks - have hjk' : j < k := lt_of_le_of_ne hjk (Ne.symm hkj) - have hzero : e k (b j) = 0 := by - by_contra hn - have hh := htri k (b j) hn - exact not_le_of_gt hjk' hh - simp [hzero] - -end Thorp.Specht - -namespace Thorp.Specht -open scoped Classical - -variable {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Thorp.Young.Cells D) - -lemma column_word_le (ht : Thorp.Young.Standard t) (c : fiberGroup (tableauCol D t)) : - toLex (tableauRow D t) ≤ toLex (fun x => tableauRow D t (c.val⁻¹ x)) := by - by_cases hc : c.val = 1 - · simp [hc] - let S := Finset.univ.filter fun x : Fin n => c.val⁻¹ x ≠ x - have hs : S.Nonempty := by - by_contra hn - apply hc - have he : c.val⁻¹ = 1 := by - apply Equiv.ext - intro x - by_contra hx - exact hn ⟨x, Finset.mem_filter.mpr ⟨Finset.mem_univ x, hx⟩⟩ - exact inv_eq_one.mp he - let x := S.min' hs - have hx : c.val⁻¹ x ≠ x := (Finset.mem_filter.mp (S.min'_mem hs)).2 - have hbefore (y : Fin n) (hy : y < x) : c.val⁻¹ y = y := by - by_contra hn - have hm : y ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ y, hn⟩ - exact not_le_of_gt hy (S.min'_le y hm) - have hlt : x < c.val⁻¹ x := by - apply lt_of_le_of_ne - · by_contra hn - have hh := hbefore (c.val⁻¹ x) (lt_of_not_ge hn) - exact hx (c.val.symm.injective hh) - · exact Ne.symm hx - have hcol : (t x).val.2 = (t (c.val⁻¹ x)).val.2 := by - have hh := c.property (c.val⁻¹ x) - simpa only [tableauCol, perm_apply_inv] using hh - have hrow := (Thorp.Young.standard_col_lt_iff t ht x (c.val⁻¹ x) hcol).mp hlt - apply le_of_lt - change Pi.Lex (· < ·) (· < ·) (tableauRow D t) (fun y => tableauRow D t (c.val⁻¹ y)) - exact ⟨x, fun y hy => congrArg (tableauRow D t) (hbefore y hy).symm, hrow⟩ - -def movedTableau (g : Equiv.Perm (Fin n)) : Fin n ≃ Thorp.Young.Cells D := (g⁻¹).trans t - -def StandardPerm := {g : Equiv.Perm (Fin n) // Thorp.Young.Standard (movedTableau D t g)} - -instance : Fintype (StandardPerm D t) := inferInstanceAs (Fintype {g : Equiv.Perm (Fin n) // Thorp.Young.Standard (movedTableau D t g)}) - -def movedWord (g : Equiv.Perm (Fin n)) : Tabloid (tableauRow D t) := g • baseTabloid (tableauRow D t) - -lemma movedWord_apply (g : Equiv.Perm (Fin n)) (x : Fin n) : - (movedWord D t g).val x = tableauRow D (movedTableau D t g) x := rfl - -lemma moved_diag (g : Equiv.Perm (Fin n)) : - tabloidRep D t g (polytabloid D t) (movedWord D t g) = 1 := by - change polytabloid D t (g⁻¹ • (g • baseTabloid (tableauRow D t))) = 1 - rw [inv_smul_smul] - exact polytabloid_diag D t - -lemma moved_leading (g : Equiv.Perm (Fin n)) (hg : Thorp.Young.Standard (movedTableau D t g)) - (f : Tabloid (tableauRow D t)) (hf : tabloidRep D t g (polytabloid D t) f ≠ 0) : - toLex (movedWord D t g).val ≤ toLex f.val := by - obtain ⟨h, hh⟩ := polytabloid_support D t (g⁻¹ • f) hf - have he : f = (g * h.val) • baseTabloid (tableauRow D t) := by - rw [mul_smul] - exact inv_smul_eq_iff.mp hh - let c : Equiv.Perm (Fin n) := g * h.val * g⁻¹ - have hc : c ∈ fiberGroup (tableauCol D (movedTableau D t g)) := by - intro x - change (t (g⁻¹ (g (h.val (g⁻¹ x))))).val.2 = (t (g⁻¹ x)).val.2 - rw [perm_inv_apply] - exact h.property (g⁻¹ x) - have hcword : c • movedWord D t g = f := by - rw [he] - change (g * h.val * g⁻¹) • (g • baseTabloid _) = (g * h.val) • baseTabloid _ - simp only [← mul_smul, inv_mul_cancel_right] - have hw := column_word_le D (movedTableau D t g) hg ⟨c, hc⟩ - change toLex (movedWord D t g).val ≤ toLex (c • movedWord D t g).val at hw - rw [hcword] at hw - exact hw - -lemma standardWord_injective : Function.Injective (fun g : StandardPerm D t => toLex (movedWord D t g.val).val) := by - intro g h he - have hr : ∀ x, (movedTableau D t g.val x).val.1 = (movedTableau D t h.val x).val.1 := - fun x => congrFun he x - have ht := Thorp.Young.standard_eq_of_rows _ _ g.property h.property hr - apply Subtype.ext - apply inv_injective - apply Equiv.ext - intro x - apply t.injective - exact congrArg (fun z : Fin n ≃ Thorp.Young.Cells D => z x) ht - -theorem standard_polytabloids_independent : - LinearIndependent ℂ (fun g : StandardPerm D t => tabloidRep D t g.val (polytabloid D t)) := by - apply independent_of_leading _ (fun g => movedWord D t g.val) (fun f => toLex f.val) - (standardWord_injective D t) - · intro i - rw [moved_diag] - exact one_ne_zero - · intro i f hf - exact moved_leading D t i.val i.property f hf - -def orbitVector (g : Equiv.Perm (Fin n)) : (module D t).toSubmodule := - ⟨tabloidRep D t g (polytabloid D t), - (module D t).apply_mem_toSubmodule g (self_mem_cyclic _ _)⟩ - -theorem standardPerm_card_le_degree : - Fintype.card (StandardPerm D t) ≤ Module.finrank ℂ (module D t).toSubmodule := by - have hi : LinearIndependent ℂ (fun g : StandardPerm D t => orbitVector D t g.val) := - LinearIndependent.of_comp (module D t).toSubmodule.subtype (standard_polytabloids_independent D t) - exact hi.fintype_card_le_finrank - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.Polytabloids + +namespace OAI + +universe uI uX uK + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical + +variable {n : ℕ} {D : YoungDiagram} + +def Standard (t : Fin n ≃ Cells D) : Prop := StrictMono t.symm + +lemma standard_row_lt_iff (t : Fin n ≃ Cells D) (ht : Standard t) (x y : Fin n) + (hr : (t x).val.1 = (t y).val.1) : x < y ↔ (t x).val.2 < (t y).val.2 := by + constructor + · intro hxy + by_contra hn + have hc : (t y).val.2 ≤ (t x).val.2 := Nat.le_of_not_gt hn + have hyx : t y ≤ t x := ⟨by omega, hc⟩ + have hh : y ≤ x := by simpa only [Equiv.symm_apply_apply] using ht.monotone hyx + exact not_le_of_gt hxy hh + · intro hc + have hxy : t x < t y := by + refine lt_iff_le_not_ge.mpr ⟨⟨by omega, hc.le⟩, ?_⟩ + intro hh + exact not_le_of_gt hc hh.2 + simpa only [Equiv.symm_apply_apply] using ht hxy + +lemma standard_col_lt_iff (t : Fin n ≃ Cells D) (ht : Standard t) (x y : Fin n) + (hc : (t x).val.2 = (t y).val.2) : x < y ↔ (t x).val.1 < (t y).val.1 := by + constructor + · intro hxy + by_contra hn + have hr : (t y).val.1 ≤ (t x).val.1 := Nat.le_of_not_gt hn + have hyx : t y ≤ t x := ⟨hr, by omega⟩ + have hh : y ≤ x := by simpa only [Equiv.symm_apply_apply] using ht.monotone hyx + exact not_le_of_gt hxy hh + · intro hr + have hxy : t x < t y := by + refine lt_iff_le_not_ge.mpr ⟨⟨hr.le, by omega⟩, ?_⟩ + intro hh + exact not_le_of_gt hr hh.1 + simpa only [Equiv.symm_apply_apply] using ht hxy + +lemma column_eq_rowRank (t : Fin n ≃ Cells D) (ht : Standard t) (x : Fin n) : + Fintype.card {y : Fin n // y < x ∧ (t y).val.1 = (t x).val.1} = (t x).val.2 := by + let e : {y : Fin n // y < x ∧ (t y).val.1 = (t x).val.1} ≃ Fin ((t x).val.2) := { + toFun := fun y => ⟨(t y.val).val.2, (standard_row_lt_iff t ht y.val x y.property.2).mp y.property.1⟩ + invFun := fun j => ⟨t.symm ⟨((t x).val.1, j), D.up_left_mem le_rfl j.isLt.le (t x).property⟩, by + constructor + · apply (standard_row_lt_iff t ht _ x (by simp)).mpr + simpa only [Equiv.apply_symm_apply] using j.isLt + · simp⟩ + left_inv := by + intro y + apply Subtype.ext + apply t.injective + simp only [Equiv.apply_symm_apply] + apply Subtype.ext + exact Prod.ext y.property.2.symm rfl + right_inv := by intro j; apply Fin.ext; simp } + exact (Fintype.card_congr e).trans (Fintype.card_fin _) + +lemma standard_eq_of_rows (t u : Fin n ≃ Cells D) (ht : Standard t) (hu : Standard u) + (hr : ∀ x, (t x).val.1 = (u x).val.1) : t = u := by + apply Equiv.ext + intro x + apply Subtype.ext + apply Prod.ext (hr x) + rw [← column_eq_rowRank t ht x, ← column_eq_rowRank u hu x] + exact Fintype.card_congr ((Equiv.refl (Fin n)).subtypeEquiv (fun y => by simp only [Equiv.refl_apply, hr])) + +end Thorp.Young + +namespace Thorp.Specht +open scoped Classical + +theorem independent_of_leading {I : Type uI} {X : Type uX} {K : Type uK} [Fintype I] [Fintype X] [LinearOrder K] + (e : I → EuclideanSpace ℂ X) (b : I → X) (key : X → K) + (hinj : Function.Injective (key ∘ b)) (hdiag : ∀ i, e i (b i) ≠ 0) + (htri : ∀ i x, e i x ≠ 0 → key (b i) ≤ key x) : LinearIndependent ℂ e := by + let : LinearOrder I := LinearOrder.lift' (key ∘ b) hinj + rw [linearIndependent_iff'] + intro s a ha i hi + by_contra hai + let S := s.filter fun j => a j ≠ 0 + have hs : S.Nonempty := ⟨i, Finset.mem_filter.mpr ⟨hi, hai⟩⟩ + let j := S.min' hs + have hj : j ∈ S := S.min'_mem hs + have hj' : j ∈ s := (Finset.mem_filter.mp hj).1 + have haz : a j ≠ 0 := (Finset.mem_filter.mp hj).2 + have hval := congrArg (fun v : EuclideanSpace ℂ X => v (b j)) ha + simp only [WithLp.ofLp_sum, Finset.sum_apply, PiLp.smul_apply, smul_eq_mul, PiLp.zero_apply] at hval + rw [Finset.sum_eq_single_of_mem j hj'] at hval + · exact (mul_ne_zero haz (hdiag j)) hval + · intro k hk hkj + by_cases hak : a k = 0 + · simp [hak] + have hks : k ∈ S := Finset.mem_filter.mpr ⟨hk, hak⟩ + have hjk : j ≤ k := S.min'_le k hks + have hjk' : j < k := lt_of_le_of_ne hjk (Ne.symm hkj) + have hzero : e k (b j) = 0 := by + by_contra hn + have hh := htri k (b j) hn + exact not_le_of_gt hjk' hh + simp [hzero] + +end Thorp.Specht + +namespace Thorp.Specht +open scoped Classical + +variable {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Thorp.Young.Cells D) + +lemma column_word_le (ht : Thorp.Young.Standard t) (c : fiberGroup (tableauCol D t)) : + toLex (tableauRow D t) ≤ toLex (fun x => tableauRow D t (c.val⁻¹ x)) := by + by_cases hc : c.val = 1 + · simp [hc] + let S := Finset.univ.filter fun x : Fin n => c.val⁻¹ x ≠ x + have hs : S.Nonempty := by + by_contra hn + apply hc + have he : c.val⁻¹ = 1 := by + apply Equiv.ext + intro x + by_contra hx + exact hn ⟨x, Finset.mem_filter.mpr ⟨Finset.mem_univ x, hx⟩⟩ + exact inv_eq_one.mp he + let x := S.min' hs + have hx : c.val⁻¹ x ≠ x := (Finset.mem_filter.mp (S.min'_mem hs)).2 + have hbefore (y : Fin n) (hy : y < x) : c.val⁻¹ y = y := by + by_contra hn + have hm : y ∈ S := Finset.mem_filter.mpr ⟨Finset.mem_univ y, hn⟩ + exact not_le_of_gt hy (S.min'_le y hm) + have hlt : x < c.val⁻¹ x := by + apply lt_of_le_of_ne + · by_contra hn + have hh := hbefore (c.val⁻¹ x) (lt_of_not_ge hn) + exact hx (c.val.symm.injective hh) + · exact Ne.symm hx + have hcol : (t x).val.2 = (t (c.val⁻¹ x)).val.2 := by + have hh := c.property (c.val⁻¹ x) + simpa only [tableauCol, perm_apply_inv] using hh + have hrow := (Thorp.Young.standard_col_lt_iff t ht x (c.val⁻¹ x) hcol).mp hlt + apply le_of_lt + change Pi.Lex (· < ·) (· < ·) (tableauRow D t) (fun y => tableauRow D t (c.val⁻¹ y)) + exact ⟨x, fun y hy => congrArg (tableauRow D t) (hbefore y hy).symm, hrow⟩ + +def movedTableau (g : Equiv.Perm (Fin n)) : Fin n ≃ Thorp.Young.Cells D := (g⁻¹).trans t + +def StandardPerm := {g : Equiv.Perm (Fin n) // Thorp.Young.Standard (movedTableau D t g)} + +instance : Fintype (StandardPerm D t) := inferInstanceAs (Fintype {g : Equiv.Perm (Fin n) // Thorp.Young.Standard (movedTableau D t g)}) + +def movedWord (g : Equiv.Perm (Fin n)) : Tabloid (tableauRow D t) := g • baseTabloid (tableauRow D t) + +lemma movedWord_apply (g : Equiv.Perm (Fin n)) (x : Fin n) : + (movedWord D t g).val x = tableauRow D (movedTableau D t g) x := rfl + +lemma moved_diag (g : Equiv.Perm (Fin n)) : + tabloidRep D t g (polytabloid D t) (movedWord D t g) = 1 := by + change polytabloid D t (g⁻¹ • (g • baseTabloid (tableauRow D t))) = 1 + rw [inv_smul_smul] + exact polytabloid_diag D t + +lemma moved_leading (g : Equiv.Perm (Fin n)) (hg : Thorp.Young.Standard (movedTableau D t g)) + (f : Tabloid (tableauRow D t)) (hf : tabloidRep D t g (polytabloid D t) f ≠ 0) : + toLex (movedWord D t g).val ≤ toLex f.val := by + obtain ⟨h, hh⟩ := polytabloid_support D t (g⁻¹ • f) hf + have he : f = (g * h.val) • baseTabloid (tableauRow D t) := by + rw [mul_smul] + exact inv_smul_eq_iff.mp hh + let c : Equiv.Perm (Fin n) := g * h.val * g⁻¹ + have hc : c ∈ fiberGroup (tableauCol D (movedTableau D t g)) := by + intro x + change (t (g⁻¹ (g (h.val (g⁻¹ x))))).val.2 = (t (g⁻¹ x)).val.2 + rw [perm_inv_apply] + exact h.property (g⁻¹ x) + have hcword : c • movedWord D t g = f := by + rw [he] + change (g * h.val * g⁻¹) • (g • baseTabloid _) = (g * h.val) • baseTabloid _ + simp only [← mul_smul, inv_mul_cancel_right] + have hw := column_word_le D (movedTableau D t g) hg ⟨c, hc⟩ + change toLex (movedWord D t g).val ≤ toLex (c • movedWord D t g).val at hw + rw [hcword] at hw + exact hw + +lemma standardWord_injective : Function.Injective (fun g : StandardPerm D t => toLex (movedWord D t g.val).val) := by + intro g h he + have hr : ∀ x, (movedTableau D t g.val x).val.1 = (movedTableau D t h.val x).val.1 := + fun x => congrFun he x + have ht := Thorp.Young.standard_eq_of_rows _ _ g.property h.property hr + apply Subtype.ext + apply inv_injective + apply Equiv.ext + intro x + apply t.injective + exact congrArg (fun z : Fin n ≃ Thorp.Young.Cells D => z x) ht + +theorem standard_polytabloids_independent : + LinearIndependent ℂ (fun g : StandardPerm D t => tabloidRep D t g.val (polytabloid D t)) := by + apply independent_of_leading _ (fun g => movedWord D t g.val) (fun f => toLex f.val) + (standardWord_injective D t) + · intro i + rw [moved_diag] + exact one_ne_zero + · intro i f hf + exact moved_leading D t i.val i.property f hf + +def orbitVector (g : Equiv.Perm (Fin n)) : (module D t).toSubmodule := + ⟨tabloidRep D t g (polytabloid D t), + (module D t).apply_mem_toSubmodule g (self_mem_cyclic _ _)⟩ + +theorem standardPerm_card_le_degree : + Fintype.card (StandardPerm D t) ≤ Module.finrank ℂ (module D t).toSubmodule := by + have hi : LinearIndependent ℂ (fun g : StandardPerm D t => orbitVector D t g.val) := + LinearIndependent.of_comp (module D t).toSubmodule.subtype (standard_polytabloids_independent D t) + exact hi.fintype_card_le_finrank + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/JointProjectors.lean b/lean/OAI/Probability/ThorpShuffle/JointProjectors.lean index 4a16375087a203d39144b68d550cf890f98528b3..50fe0aac680dc9427577a9a4030d0f01d8c3223c 100644 --- a/lean/OAI/Probability/ThorpShuffle/JointProjectors.lean +++ b/lean/OAI/Probability/ThorpShuffle/JointProjectors.lean @@ -1,177 +1,177 @@ -import OAI.Probability.ThorpShuffle.FourierFamilies - -namespace OAI - -universe uI uE - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier -open scoped Classical - -lemma complex_cauchy {I : Type uI} (s : Finset I) (a b : I → ℂ) : - ‖∑ i ∈ s, a i * b i‖ ^ 2 ≤ (∑ i ∈ s, ‖a i‖ ^ 2) * ∑ i ∈ s, ‖b i‖ ^ 2 := by - have ht : ‖∑ i ∈ s, a i * b i‖ ≤ ∑ i ∈ s, ‖a i‖ * ‖b i‖ := by - simpa only [norm_mul] using norm_sum_le s (fun i => a i * b i) - exact (pow_le_pow_left₀ (norm_nonneg _) ht 2).trans - (Finset.sum_mul_sq_le_sq_mul_sq s (fun i => ‖a i‖) (fun i => ‖b i‖)) - -namespace Family -variable {G : Type} [Group G] [Fintype G] (F : Family G) -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - -theorem coefficient_evaluation (ρ : Representation ℂ G E) (s : Finset F.Index) - (v w : E) (hv : (∑ i ∈ s, F.projector ρ i) v = v) : - (Fintype.card G : ℝ) * ‖⟪w, v⟫_ℂ‖ ^ 2 ≤ - (∑ i ∈ s, (F.degree i : ℝ)^2) * ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 := by - have he : ⟪w, v⟫_ℂ = ∑ g, (∑ i ∈ s, F.kernel i g) * ⟪w, ρ g v⟫_ℂ := by - conv_lhs => rw [← hv] - conv_lhs => rw [show ∑ i ∈ s, F.projector ρ i = integrated ρ (∑ i ∈ s, F.kernel i) by - simp only [projector, integrated_sum]] - simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, inner_sum, inner_smul_right, - Finset.sum_apply] - have hh := mul_le_mul_of_nonneg_left - (complex_cauchy Finset.univ (fun g => ∑ i ∈ s, F.kernel i g) (fun g => ⟪w, ρ g v⟫_ℂ)) - (Nat.cast_nonneg (α := ℝ) (Fintype.card G)) - rw [← he, ← mul_assoc, F.kernel_sum_sq] at hh - exact hh - -end Family -end Thorp.Fourier - -namespace Thorp.Fourier.Family -open scoped Classical -variable {H : Type} [Group H] [Fintype H] (F : Family H) -variable {I : Type} [Fintype I] - -def jointKernel (a : I → F.Index) (g : I → H) : ℂ := ∏ i, F.kernel (a i) (g i) - -lemma jointKernel_sum : (∑ a : I → F.Index, F.jointKernel a) = delta := by - funext g - simp only [Finset.sum_apply, jointKernel] - rw [← Fintype.prod_sum (fun i (j : F.Index) => F.kernel j (g i))] - have hh (i : I) : ∑ j : F.Index, F.kernel j (g i) = if g i = 1 then 1 else 0 := - by simpa only [Finset.sum_apply, delta] using congrFun F.kernel_sum (g i) - simp only [hh] - by_cases hg : g = 1 - · subst g; simp [delta] - · have hn : ∃ i, g i ≠ 1 := by - by_contra hn - push Not at hn - exact hg (funext hn) - obtain ⟨i, hi⟩ := hn - rw [Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)] - simp [delta, hg] - -lemma jointKernel_convolution (a b : I → F.Index) : - convolution (F.jointKernel a) (F.jointKernel b) = if a = b then F.jointKernel a else 0 := by - funext g - simp only [convolution, jointKernel, Pi.mul_apply, Pi.inv_apply, ← Finset.prod_mul_distrib] - rw [← Fintype.prod_sum (fun i (h : H) => F.kernel (a i) h * F.kernel (b i) (h⁻¹ * g i))] - have hh (i : I) : ∑ h, F.kernel (a i) h * F.kernel (b i) (h⁻¹ * g i) = - if a i = b i then F.kernel (a i) (g i) else 0 := by - have he := congrFun (F.kernel_convolution (a i) (b i)) (g i) - simpa only [convolution, ite_apply, Pi.zero_apply] using he - simp only [hh] - by_cases hab : a = b - · subst b; simp only [↓reduceIte, jointKernel] - · rw [ite_eq_right hab] - obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by - by_contra hn; push Not at hn; exact hab (funext hn) - exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) - -lemma jointKernel_star (a : I → F.Index) (g : I → H) : - conj (F.jointKernel a g⁻¹) = F.jointKernel a g := by - simp only [jointKernel, map_prod, Pi.inv_apply, F.kernel_star] - -variable {E : Type uE} [AddCommGroup E] [Module ℂ E] - -def jointProjector (ρ : Representation ℂ (I → H) E) (a : I → F.Index) : Module.End ℂ E := - integrated ρ (F.jointKernel a) - -lemma jointProjector_mul (ρ : Representation ℂ (I → H) E) (a b : I → F.Index) : - F.jointProjector ρ a * F.jointProjector ρ b = if a = b then F.jointProjector ρ a else 0 := by - rw [jointProjector, jointProjector, ← integrated_convolution, jointKernel_convolution] - split_ifs <;> simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] - -lemma jointProjector_idempotent (ρ : Representation ℂ (I → H) E) (a : I → F.Index) : - IsIdempotentElem (F.jointProjector ρ a) := by - simpa only [IsIdempotentElem, ↓reduceIte] using F.jointProjector_mul ρ a a - -lemma jointProjector_sum (ρ : Representation ℂ (I → H) E) : ∑ a, F.jointProjector ρ a = 1 := by - simp only [jointProjector] - rw [← integrated_sum, F.jointKernel_sum, integrated_delta] - -def tensorList (a : I → F.Index) : List I → FDRep ℂ (I → H) - | [] => FDRep.of (Representation.trivial ℂ (I → H) ℂ) - | i :: l => FDRep.of (Representation.tprod ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) (tensorList a l).ρ) - -omit [Fintype I] in -lemma tensorList_character (a : I → F.Index) (l : List I) (g : I → H) : - Representation.character (F.tensorList a l).ρ g = (l.map (fun i => (F.rep (a i)).character (g i))).prod := by - induction l with - | nil => - change LinearMap.trace ℂ ℂ (1 : Module.End ℂ ℂ) = 1 - simp - | cons i l ih => - change (Representation.tprod ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) - (F.tensorList a l).ρ).character g = _ - rw [Representation.char_tensor ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) - (F.tensorList a l).ρ] - change (F.rep (a i)).character (g i) * Representation.character (F.tensorList a l).ρ g = _ - rw [ih] - rfl - -def tensorFamily (a : I → F.Index) : FDRep ℂ (I → H) := F.tensorList a Finset.univ.toList - -lemma tensorFamily_character (a : I → F.Index) (g : I → H) : - Representation.character (F.tensorFamily a).ρ g = ∏ i, (F.rep (a i)).character (g i) := by - rw [tensorFamily, tensorList_character] - exact Finset.prod_map_toList _ _ - -lemma jointKernel_formula (a : I → F.Index) (g : I → H) : - F.jointKernel a g = (∏ i, (F.degree (a i) : ℂ)) * (Fintype.card (I → H) : ℂ)⁻¹ * - Representation.character (F.tensorFamily a).ρ g⁻¹ := by - simp only [jointKernel, kernel, Finset.prod_mul_distrib, Finset.prod_const, - Finset.card_univ, tensorFamily_character, Pi.inv_apply, Fintype.card_fun, Nat.cast_pow, inv_pow] - -lemma trace_jointProjector [FiniteDimensional ℂ E] (ρ : Representation ℂ (I → H) E) - (a : I → F.Index) : LinearMap.trace ℂ E (F.jointProjector ρ a) = - (∏ i, (F.degree (a i) : ℂ)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := by - let : Invertible (Nat.card (I → H) : ℂ) := invertibleOfNonzero (NeZero.ne _) - rw [jointProjector, trace_integrated] - simp only [jointKernel_formula] - rw [← Representation.card_inv_mul_sum_char_mul_char_eq_finrank] - simp only [Finset.mul_sum, Fintype.card_eq_nat_card] - apply Finset.sum_congr rfl - intro g _ - ring - -theorem joint_degree_le [FiniteDimensional ℂ E] (ρ : Representation ℂ (I → H) E) - (a : I → F.Index) (ha : F.jointProjector ρ a ≠ 0) : - (∏ i, F.degree (a i)) ≤ Module.finrank ℂ E := by - have hp := F.jointProjector_idempotent ρ a - have ht := F.trace_jointProjector ρ a - rw [(LinearMap.IsIdempotentElem.isProj_range _ hp).trace] at ht - have hm : Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) ≠ 0 := by - intro hz - have hh := F.trace_jointProjector ρ a - rw [hz, Nat.cast_zero, mul_zero] at hh - exact ha (LinearMap.IsIdempotentElem.eq_zero_of_trace_eq_zero hp hh) - have hn : Module.finrank ℂ (LinearMap.range (F.jointProjector ρ a)) = - (∏ i, F.degree (a i)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := by - exact_mod_cast ht - calc - _ ≤ (∏ i, F.degree (a i)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := - Nat.le_mul_of_pos_right _ (Nat.pos_of_ne_zero hm) - _ = _ := hn.symm - _ ≤ Module.finrank ℂ E := Submodule.finrank_le _ - -end Thorp.Fourier.Family - -end - -end OAI +import OAI.Probability.ThorpShuffle.FourierFamilies + +namespace OAI + +universe uI uE + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier +open scoped Classical + +lemma complex_cauchy {I : Type uI} (s : Finset I) (a b : I → ℂ) : + ‖∑ i ∈ s, a i * b i‖ ^ 2 ≤ (∑ i ∈ s, ‖a i‖ ^ 2) * ∑ i ∈ s, ‖b i‖ ^ 2 := by + have ht : ‖∑ i ∈ s, a i * b i‖ ≤ ∑ i ∈ s, ‖a i‖ * ‖b i‖ := by + simpa only [norm_mul] using norm_sum_le s (fun i => a i * b i) + exact (pow_le_pow_left₀ (norm_nonneg _) ht 2).trans + (Finset.sum_mul_sq_le_sq_mul_sq s (fun i => ‖a i‖) (fun i => ‖b i‖)) + +namespace Family +variable {G : Type} [Group G] [Fintype G] (F : Family G) +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem coefficient_evaluation (ρ : Representation ℂ G E) (s : Finset F.Index) + (v w : E) (hv : (∑ i ∈ s, F.projector ρ i) v = v) : + (Fintype.card G : ℝ) * ‖⟪w, v⟫_ℂ‖ ^ 2 ≤ + (∑ i ∈ s, (F.degree i : ℝ)^2) * ∑ g, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 := by + have he : ⟪w, v⟫_ℂ = ∑ g, (∑ i ∈ s, F.kernel i g) * ⟪w, ρ g v⟫_ℂ := by + conv_lhs => rw [← hv] + conv_lhs => rw [show ∑ i ∈ s, F.projector ρ i = integrated ρ (∑ i ∈ s, F.kernel i) by + simp only [projector, integrated_sum]] + simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, inner_sum, inner_smul_right, + Finset.sum_apply] + have hh := mul_le_mul_of_nonneg_left + (complex_cauchy Finset.univ (fun g => ∑ i ∈ s, F.kernel i g) (fun g => ⟪w, ρ g v⟫_ℂ)) + (Nat.cast_nonneg (α := ℝ) (Fintype.card G)) + rw [← he, ← mul_assoc, F.kernel_sum_sq] at hh + exact hh + +end Family +end Thorp.Fourier + +namespace Thorp.Fourier.Family +open scoped Classical +variable {H : Type} [Group H] [Fintype H] (F : Family H) +variable {I : Type} [Fintype I] + +def jointKernel (a : I → F.Index) (g : I → H) : ℂ := ∏ i, F.kernel (a i) (g i) + +lemma jointKernel_sum : (∑ a : I → F.Index, F.jointKernel a) = delta := by + funext g + simp only [Finset.sum_apply, jointKernel] + rw [← Fintype.prod_sum (fun i (j : F.Index) => F.kernel j (g i))] + have hh (i : I) : ∑ j : F.Index, F.kernel j (g i) = if g i = 1 then 1 else 0 := + by simpa only [Finset.sum_apply, delta] using congrFun F.kernel_sum (g i) + simp only [hh] + by_cases hg : g = 1 + · subst g; simp [delta] + · have hn : ∃ i, g i ≠ 1 := by + by_contra hn + push Not at hn + exact hg (funext hn) + obtain ⟨i, hi⟩ := hn + rw [Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)] + simp [delta, hg] + +lemma jointKernel_convolution (a b : I → F.Index) : + convolution (F.jointKernel a) (F.jointKernel b) = if a = b then F.jointKernel a else 0 := by + funext g + simp only [convolution, jointKernel, Pi.mul_apply, Pi.inv_apply, ← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun i (h : H) => F.kernel (a i) h * F.kernel (b i) (h⁻¹ * g i))] + have hh (i : I) : ∑ h, F.kernel (a i) h * F.kernel (b i) (h⁻¹ * g i) = + if a i = b i then F.kernel (a i) (g i) else 0 := by + have he := congrFun (F.kernel_convolution (a i) (b i)) (g i) + simpa only [convolution, ite_apply, Pi.zero_apply] using he + simp only [hh] + by_cases hab : a = b + · subst b; simp only [↓reduceIte, jointKernel] + · rw [ite_eq_right hab] + obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by + by_contra hn; push Not at hn; exact hab (funext hn) + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +lemma jointKernel_star (a : I → F.Index) (g : I → H) : + conj (F.jointKernel a g⁻¹) = F.jointKernel a g := by + simp only [jointKernel, map_prod, Pi.inv_apply, F.kernel_star] + +variable {E : Type uE} [AddCommGroup E] [Module ℂ E] + +def jointProjector (ρ : Representation ℂ (I → H) E) (a : I → F.Index) : Module.End ℂ E := + integrated ρ (F.jointKernel a) + +lemma jointProjector_mul (ρ : Representation ℂ (I → H) E) (a b : I → F.Index) : + F.jointProjector ρ a * F.jointProjector ρ b = if a = b then F.jointProjector ρ a else 0 := by + rw [jointProjector, jointProjector, ← integrated_convolution, jointKernel_convolution] + split_ifs <;> simp only [integrated, Pi.zero_apply, zero_smul, Finset.sum_const_zero] + +lemma jointProjector_idempotent (ρ : Representation ℂ (I → H) E) (a : I → F.Index) : + IsIdempotentElem (F.jointProjector ρ a) := by + simpa only [IsIdempotentElem, ↓reduceIte] using F.jointProjector_mul ρ a a + +lemma jointProjector_sum (ρ : Representation ℂ (I → H) E) : ∑ a, F.jointProjector ρ a = 1 := by + simp only [jointProjector] + rw [← integrated_sum, F.jointKernel_sum, integrated_delta] + +def tensorList (a : I → F.Index) : List I → FDRep ℂ (I → H) + | [] => FDRep.of (Representation.trivial ℂ (I → H) ℂ) + | i :: l => FDRep.of (Representation.tprod ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) (tensorList a l).ρ) + +omit [Fintype I] in +lemma tensorList_character (a : I → F.Index) (l : List I) (g : I → H) : + Representation.character (F.tensorList a l).ρ g = (l.map (fun i => (F.rep (a i)).character (g i))).prod := by + induction l with + | nil => + change LinearMap.trace ℂ ℂ (1 : Module.End ℂ ℂ) = 1 + simp + | cons i l ih => + change (Representation.tprod ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) + (F.tensorList a l).ρ).character g = _ + rw [Representation.char_tensor ((F.rep (a i)).comp (Pi.evalMonoidHom (fun _ : I => H) i)) + (F.tensorList a l).ρ] + change (F.rep (a i)).character (g i) * Representation.character (F.tensorList a l).ρ g = _ + rw [ih] + rfl + +def tensorFamily (a : I → F.Index) : FDRep ℂ (I → H) := F.tensorList a Finset.univ.toList + +lemma tensorFamily_character (a : I → F.Index) (g : I → H) : + Representation.character (F.tensorFamily a).ρ g = ∏ i, (F.rep (a i)).character (g i) := by + rw [tensorFamily, tensorList_character] + exact Finset.prod_map_toList _ _ + +lemma jointKernel_formula (a : I → F.Index) (g : I → H) : + F.jointKernel a g = (∏ i, (F.degree (a i) : ℂ)) * (Fintype.card (I → H) : ℂ)⁻¹ * + Representation.character (F.tensorFamily a).ρ g⁻¹ := by + simp only [jointKernel, kernel, Finset.prod_mul_distrib, Finset.prod_const, + Finset.card_univ, tensorFamily_character, Pi.inv_apply, Fintype.card_fun, Nat.cast_pow, inv_pow] + +lemma trace_jointProjector [FiniteDimensional ℂ E] (ρ : Representation ℂ (I → H) E) + (a : I → F.Index) : LinearMap.trace ℂ E (F.jointProjector ρ a) = + (∏ i, (F.degree (a i) : ℂ)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := by + let : Invertible (Nat.card (I → H) : ℂ) := invertibleOfNonzero (NeZero.ne _) + rw [jointProjector, trace_integrated] + simp only [jointKernel_formula] + rw [← Representation.card_inv_mul_sum_char_mul_char_eq_finrank] + simp only [Finset.mul_sum, Fintype.card_eq_nat_card] + apply Finset.sum_congr rfl + intro g _ + ring + +theorem joint_degree_le [FiniteDimensional ℂ E] (ρ : Representation ℂ (I → H) E) + (a : I → F.Index) (ha : F.jointProjector ρ a ≠ 0) : + (∏ i, F.degree (a i)) ≤ Module.finrank ℂ E := by + have hp := F.jointProjector_idempotent ρ a + have ht := F.trace_jointProjector ρ a + rw [(LinearMap.IsIdempotentElem.isProj_range _ hp).trace] at ht + have hm : Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) ≠ 0 := by + intro hz + have hh := F.trace_jointProjector ρ a + rw [hz, Nat.cast_zero, mul_zero] at hh + exact ha (LinearMap.IsIdempotentElem.eq_zero_of_trace_eq_zero hp hh) + have hn : Module.finrank ℂ (LinearMap.range (F.jointProjector ρ a)) = + (∏ i, F.degree (a i)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := by + exact_mod_cast ht + calc + _ ≤ (∏ i, F.degree (a i)) * Module.finrank ℂ (Representation.IntertwiningMap (F.tensorFamily a).ρ ρ) := + Nat.le_mul_of_pos_right _ (Nat.pos_of_ne_zero hm) + _ = _ := hn.symm + _ ≤ Module.finrank ℂ E := Submodule.finrank_le _ + +end Thorp.Fourier.Family + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/LinearExtensions.lean b/lean/OAI/Probability/ThorpShuffle/LinearExtensions.lean index cb1e94f24fc8451f8f3f3c9bb77efd7408bdd963..5cc265127ad1fa4c64abc93807c8f0c7959d913d 100644 --- a/lean/OAI/Probability/ThorpShuffle/LinearExtensions.lean +++ b/lean/OAI/Probability/ThorpShuffle/LinearExtensions.lean @@ -1,227 +1,227 @@ -import OAI.Probability.ThorpShuffle.Classification - -namespace OAI - -universe uA uα uI uB - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical - -variable (A : Type uA) [Fintype A] [PartialOrder A] - -def Extensions := {e : A ≃ Fin (Fintype.card A) // StrictMono e} - -instance : Fintype (Extensions A) := inferInstanceAs (Fintype {e : A ≃ Fin (Fintype.card A) // StrictMono e}) - -omit [PartialOrder A] in - -lemma labelByKey (k : A → ℕ) (hk : Function.Injective k) : - ∃ e : A ≃ Fin (Fintype.card A), ∀ x y, e x < e y ↔ k x < k y := by - let e : A ≃ Set.range k := Equiv.ofInjective k hk - let : Fintype (Set.range k) := Fintype.ofEquiv A e - let o := (Fintype.orderIsoFinOfCardEq (Set.range k) (Fintype.card_congr e.symm)).symm - exact ⟨e.trans o.toEquiv, fun x y => o.lt_iff_lt⟩ - -omit [PartialOrder A] in - -lemma labelByRank (r : A → ℕ) : - ∃ e : A ≃ Fin (Fintype.card A), ∀ x y, r x < r y → e x < e y := by - let b := Fintype.equivFin A - let k (x : A) := r x * (Fintype.card A + 1) + (b x).val - have hk : Function.Injective k := by - intro x y h - have hx := (b x).isLt - have hy := (b y).isLt - have hr : r x = r y := by - change r x * (Fintype.card A + 1) + (b x).val = r y * (Fintype.card A + 1) + (b y).val at h - nlinarith - apply b.injective - apply Fin.ext - change r x * (Fintype.card A + 1) + (b x).val = r y * (Fintype.card A + 1) + (b y).val at h - rw [hr] at h - omega - obtain ⟨e, he⟩ := labelByKey A k hk - refine ⟨e, fun x y hxy => (he x y).mpr ?_⟩ - dsimp [k] - have hx := (b x).isLt - nlinarith - -lemma extensions_nonempty : Nonempty (Extensions A) := by - let h : A ≃ LinearExtension A := Equiv.refl A - let : Fintype (LinearExtension A) := Fintype.ofEquiv A h - let e := (Fintype.orderIsoFinOfCardEq (LinearExtension A) (Fintype.card_congr h.symm)).symm - refine ⟨⟨h.trans e.toEquiv, ?_⟩⟩ - exact e.strictMono.comp - (toLinearExtension.monotone.strictMono_of_injective fun _ _ hh => hh) - -lemma fiberPerm_le_extensions (r : A → ℕ) (hr : StrictMono r) : - Fintype.card (Thorp.Specht.fiberGroup r) ≤ Fintype.card (Extensions A) := by - obtain ⟨e, he⟩ := labelByRank A r - let F (g : Thorp.Specht.fiberGroup r) : Extensions A := ⟨g.val.trans e, by - intro x y hxy - apply he - rw [g.property x, g.property y] - exact hr hxy⟩ - apply Fintype.card_le_of_injective F - intro g h hgh - apply Subtype.ext - apply Equiv.ext - intro x - apply e.injective - exact congrArg (fun z : Extensions A => z.val x) hgh - -end Thorp.Young - -namespace Thorp.Specht -open scoped Classical -variable {α : Type uα} [Fintype α] - -lemma tabloid_card_mul (r : α → ℕ) : - Fintype.card (Tabloid r) * Fintype.card (fiberGroup r) = (Fintype.card α).factorial := by - let G := Equiv.Perm α - let b := baseTabloid r - let e : MulAction.orbit G b ≃ Tabloid r := { - toFun := Subtype.val - invFun := fun f => ⟨f, by - obtain ⟨g, hg⟩ := f.property - refine ⟨g⁻¹, ?_⟩ - apply Subtype.ext - funext x - change r ((g⁻¹ : Equiv.Perm α)⁻¹ x) = f.val x - rw [inv_inv] - exact (congrFun hg x).symm⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - let u : MulAction.stabilizer G b ≃ fiberGroup r := { - toFun := fun g => ⟨g.val, (stabilizes_tabloid_iff r g.val b).mp g.property⟩ - invFun := fun g => ⟨g.val, (stabilizes_tabloid_iff r g.val b).mpr g.property⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - rw [← Fintype.card_congr e, ← Fintype.card_congr u, - MulAction.card_orbit_mul_card_stabilizer_eq_card_group, Fintype.card_perm] - -lemma tabloid_card_le (r : α → ℕ) (m : ℕ) (hr : ∀ x, r x < m) : - Fintype.card (Tabloid r) ≤ m ^ Fintype.card α := by - have hb (f : Tabloid r) (x : α) : f.val x < m := by - obtain ⟨g, hg⟩ := f.property - rw [hg] - exact hr (g x) - let F (f : Tabloid r) : α → Fin m := fun x => ⟨f.val x, hb f x⟩ - have hi : Function.Injective F := by - intro f h hfh - apply Subtype.ext - funext x - exact congrArg Fin.val (congrFun hfh x) - have hh := Fintype.card_le_of_injective F hi - simpa only [Fintype.card_fun, Fintype.card_fin] using hh - -end Thorp.Specht - -namespace Thorp.Young -open scoped Classical -variable (A : Type uA) [Fintype A] [PartialOrder A] - -theorem rank_extension_bound (r : A → ℕ) (hr : StrictMono r) (m : ℕ) (hm : ∀ x, r x < m) : - (Fintype.card A).factorial ≤ m ^ Fintype.card A * Fintype.card (Extensions A) := by - rw [← Thorp.Specht.tabloid_card_mul r] - exact Nat.mul_le_mul (Thorp.Specht.tabloid_card_le r m hm) (fiberPerm_le_extensions A r hr) - -end Thorp.Young - -namespace Thorp.Specht -open scoped Classical -variable {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Thorp.Young.Cells D) - -lemma labels_card_le_degree {I : Type uI} [Fintype I] - (l : I → Thorp.Young.Cells D ≃ Fin n) (hl : ∀ i, StrictMono (l i)) - (hi : Function.Injective l) : Fintype.card I ≤ Module.finrank ℂ (module D t).toSubmodule := by - let F (i : I) : StandardPerm D t := ⟨t.trans (l i), by - intro x y hxy - change l i (t (t.symm x)) < l i (t (t.symm y)) - simpa only [Equiv.apply_symm_apply] using hl i hxy⟩ - have hF : Function.Injective F := by - intro i j hij - apply hi - apply Equiv.ext - intro x - have hh := congrArg (fun g : StandardPerm D t => g.val (t.symm x)) hij - simpa only [F, Equiv.trans_apply, Equiv.apply_symm_apply] using hh - exact (Fintype.card_le_of_injective F hF).trans (standardPerm_card_le_degree D t) - -lemma extensions_card_le_degree : - Fintype.card (Thorp.Young.Extensions (Thorp.Young.Cells D)) ≤ - Module.finrank ℂ (module D t).toSubmodule := by - have hc : Fintype.card (Thorp.Young.Cells D) = n := (Fintype.card_congr t.symm).trans (Fintype.card_fin n) - let c := finCongr hc - apply labels_card_le_degree D t (fun e => e.val.trans c) - · intro e x y hxy - exact e.property hxy - · intro e f hef - apply Subtype.ext - apply Equiv.ext - intro x - apply c.injective - exact congrArg (fun z : Thorp.Young.Cells D ≃ Fin n => z x) hef - -end Thorp.Specht - -namespace Thorp.Young -open scoped Classical - -def transposeCells (D : YoungDiagram) : Cells D ≃o Cells D.transpose where - toFun x := ⟨x.val.swap, by - change x.val.swap ∈ D.transpose - rw [YoungDiagram.mem_transpose, Prod.swap_swap] - exact x.property⟩ - invFun x := ⟨x.val.swap, (YoungDiagram.mem_transpose.mp x.property)⟩ - left_inv x := by apply Subtype.ext; exact Prod.swap_swap x.val - right_inv x := by apply Subtype.ext; exact Prod.swap_swap x.val - map_rel_iff' := by intro x y; exact and_comm - -lemma extensions_card_orderIso {A : Type uA} {B : Type uB} [Fintype A] [Fintype B] [PartialOrder A] [PartialOrder B] - (e : A ≃o B) : Fintype.card (Extensions A) = Fintype.card (Extensions B) := by - let c := finCongr (Fintype.card_congr e.toEquiv) - let F : Extensions A ≃ Extensions B := { - toFun := fun l => ⟨(e.symm.toEquiv.trans l.val).trans c, fun _ _ h => l.property (e.symm.strictMono h)⟩ - invFun := fun l => ⟨(e.toEquiv.trans l.val).trans c.symm, fun _ _ h => l.property (e.strictMono h)⟩ - left_inv := by intro l; apply Subtype.ext; ext x; simp [c] - right_inv := by intro l; apply Subtype.ext; ext x; simp [c] } - exact Fintype.card_congr F - -lemma rank_strictMono (D : YoungDiagram) : StrictMono (fun x : Cells D => x.val.1 + x.val.2) := by - intro x y hxy - have hle := hxy.le - have hn : x.val ≠ y.val := fun h => hxy.ne (Subtype.ext h) - have he : x.val.1 ≠ y.val.1 ∨ x.val.2 ≠ y.val.2 := by - by_contra hh - push Not at hh - exact hn (Prod.ext hh.1 hh.2) - change x.val.1 + x.val.2 < y.val.1 + y.val.2 - rcases he with he | he <;> have := hle.1 <;> have := hle.2 <;> omega - -def longest (D : YoungDiagram) : ℕ := max (D.rowLen 0) (D.colLen 0) - -lemma coord_lt_longest (D : YoungDiagram) (x : Cells D) : - x.val.1 < longest D ∧ x.val.2 < longest D := by - constructor - · exact (YoungDiagram.mem_iff_lt_colLen.mp (D.up_left_mem le_rfl (Nat.zero_le _) x.property)).trans_le (le_max_right _ _) - · exact (YoungDiagram.mem_iff_lt_rowLen.mp (D.up_left_mem (Nat.zero_le _) le_rfl x.property)).trans_le (le_max_left _ _) - -theorem factorial_le_rank_degree {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Cells D) : - n.factorial ≤ (2 * longest D) ^ n * Module.finrank ℂ (Thorp.Specht.module D t).toSubmodule := by - have hh := rank_extension_bound (Cells D) (fun x => x.val.1 + x.val.2) (rank_strictMono D) - (2 * longest D) (fun x => by have := coord_lt_longest D x; omega) - have hc : Fintype.card (Cells D) = n := (Fintype.card_congr t.symm).trans (Fintype.card_fin n) - rw [hc] at hh - exact hh.trans (Nat.mul_le_mul_left _ (Thorp.Specht.extensions_card_le_degree D t)) - -end Thorp.Young - -end - -end OAI +import OAI.Probability.ThorpShuffle.Classification + +namespace OAI + +universe uA uα uI uB + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical + +variable (A : Type uA) [Fintype A] [PartialOrder A] + +def Extensions := {e : A ≃ Fin (Fintype.card A) // StrictMono e} + +instance : Fintype (Extensions A) := inferInstanceAs (Fintype {e : A ≃ Fin (Fintype.card A) // StrictMono e}) + +omit [PartialOrder A] in + +lemma labelByKey (k : A → ℕ) (hk : Function.Injective k) : + ∃ e : A ≃ Fin (Fintype.card A), ∀ x y, e x < e y ↔ k x < k y := by + let e : A ≃ Set.range k := Equiv.ofInjective k hk + let : Fintype (Set.range k) := Fintype.ofEquiv A e + let o := (Fintype.orderIsoFinOfCardEq (Set.range k) (Fintype.card_congr e.symm)).symm + exact ⟨e.trans o.toEquiv, fun x y => o.lt_iff_lt⟩ + +omit [PartialOrder A] in + +lemma labelByRank (r : A → ℕ) : + ∃ e : A ≃ Fin (Fintype.card A), ∀ x y, r x < r y → e x < e y := by + let b := Fintype.equivFin A + let k (x : A) := r x * (Fintype.card A + 1) + (b x).val + have hk : Function.Injective k := by + intro x y h + have hx := (b x).isLt + have hy := (b y).isLt + have hr : r x = r y := by + change r x * (Fintype.card A + 1) + (b x).val = r y * (Fintype.card A + 1) + (b y).val at h + nlinarith + apply b.injective + apply Fin.ext + change r x * (Fintype.card A + 1) + (b x).val = r y * (Fintype.card A + 1) + (b y).val at h + rw [hr] at h + omega + obtain ⟨e, he⟩ := labelByKey A k hk + refine ⟨e, fun x y hxy => (he x y).mpr ?_⟩ + dsimp [k] + have hx := (b x).isLt + nlinarith + +lemma extensions_nonempty : Nonempty (Extensions A) := by + let h : A ≃ LinearExtension A := Equiv.refl A + let : Fintype (LinearExtension A) := Fintype.ofEquiv A h + let e := (Fintype.orderIsoFinOfCardEq (LinearExtension A) (Fintype.card_congr h.symm)).symm + refine ⟨⟨h.trans e.toEquiv, ?_⟩⟩ + exact e.strictMono.comp + (toLinearExtension.monotone.strictMono_of_injective fun _ _ hh => hh) + +lemma fiberPerm_le_extensions (r : A → ℕ) (hr : StrictMono r) : + Fintype.card (Thorp.Specht.fiberGroup r) ≤ Fintype.card (Extensions A) := by + obtain ⟨e, he⟩ := labelByRank A r + let F (g : Thorp.Specht.fiberGroup r) : Extensions A := ⟨g.val.trans e, by + intro x y hxy + apply he + rw [g.property x, g.property y] + exact hr hxy⟩ + apply Fintype.card_le_of_injective F + intro g h hgh + apply Subtype.ext + apply Equiv.ext + intro x + apply e.injective + exact congrArg (fun z : Extensions A => z.val x) hgh + +end Thorp.Young + +namespace Thorp.Specht +open scoped Classical +variable {α : Type uα} [Fintype α] + +lemma tabloid_card_mul (r : α → ℕ) : + Fintype.card (Tabloid r) * Fintype.card (fiberGroup r) = (Fintype.card α).factorial := by + let G := Equiv.Perm α + let b := baseTabloid r + let e : MulAction.orbit G b ≃ Tabloid r := { + toFun := Subtype.val + invFun := fun f => ⟨f, by + obtain ⟨g, hg⟩ := f.property + refine ⟨g⁻¹, ?_⟩ + apply Subtype.ext + funext x + change r ((g⁻¹ : Equiv.Perm α)⁻¹ x) = f.val x + rw [inv_inv] + exact (congrFun hg x).symm⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + let u : MulAction.stabilizer G b ≃ fiberGroup r := { + toFun := fun g => ⟨g.val, (stabilizes_tabloid_iff r g.val b).mp g.property⟩ + invFun := fun g => ⟨g.val, (stabilizes_tabloid_iff r g.val b).mpr g.property⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + rw [← Fintype.card_congr e, ← Fintype.card_congr u, + MulAction.card_orbit_mul_card_stabilizer_eq_card_group, Fintype.card_perm] + +lemma tabloid_card_le (r : α → ℕ) (m : ℕ) (hr : ∀ x, r x < m) : + Fintype.card (Tabloid r) ≤ m ^ Fintype.card α := by + have hb (f : Tabloid r) (x : α) : f.val x < m := by + obtain ⟨g, hg⟩ := f.property + rw [hg] + exact hr (g x) + let F (f : Tabloid r) : α → Fin m := fun x => ⟨f.val x, hb f x⟩ + have hi : Function.Injective F := by + intro f h hfh + apply Subtype.ext + funext x + exact congrArg Fin.val (congrFun hfh x) + have hh := Fintype.card_le_of_injective F hi + simpa only [Fintype.card_fun, Fintype.card_fin] using hh + +end Thorp.Specht + +namespace Thorp.Young +open scoped Classical +variable (A : Type uA) [Fintype A] [PartialOrder A] + +theorem rank_extension_bound (r : A → ℕ) (hr : StrictMono r) (m : ℕ) (hm : ∀ x, r x < m) : + (Fintype.card A).factorial ≤ m ^ Fintype.card A * Fintype.card (Extensions A) := by + rw [← Thorp.Specht.tabloid_card_mul r] + exact Nat.mul_le_mul (Thorp.Specht.tabloid_card_le r m hm) (fiberPerm_le_extensions A r hr) + +end Thorp.Young + +namespace Thorp.Specht +open scoped Classical +variable {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Thorp.Young.Cells D) + +lemma labels_card_le_degree {I : Type uI} [Fintype I] + (l : I → Thorp.Young.Cells D ≃ Fin n) (hl : ∀ i, StrictMono (l i)) + (hi : Function.Injective l) : Fintype.card I ≤ Module.finrank ℂ (module D t).toSubmodule := by + let F (i : I) : StandardPerm D t := ⟨t.trans (l i), by + intro x y hxy + change l i (t (t.symm x)) < l i (t (t.symm y)) + simpa only [Equiv.apply_symm_apply] using hl i hxy⟩ + have hF : Function.Injective F := by + intro i j hij + apply hi + apply Equiv.ext + intro x + have hh := congrArg (fun g : StandardPerm D t => g.val (t.symm x)) hij + simpa only [F, Equiv.trans_apply, Equiv.apply_symm_apply] using hh + exact (Fintype.card_le_of_injective F hF).trans (standardPerm_card_le_degree D t) + +lemma extensions_card_le_degree : + Fintype.card (Thorp.Young.Extensions (Thorp.Young.Cells D)) ≤ + Module.finrank ℂ (module D t).toSubmodule := by + have hc : Fintype.card (Thorp.Young.Cells D) = n := (Fintype.card_congr t.symm).trans (Fintype.card_fin n) + let c := finCongr hc + apply labels_card_le_degree D t (fun e => e.val.trans c) + · intro e x y hxy + exact e.property hxy + · intro e f hef + apply Subtype.ext + apply Equiv.ext + intro x + apply c.injective + exact congrArg (fun z : Thorp.Young.Cells D ≃ Fin n => z x) hef + +end Thorp.Specht + +namespace Thorp.Young +open scoped Classical + +def transposeCells (D : YoungDiagram) : Cells D ≃o Cells D.transpose where + toFun x := ⟨x.val.swap, by + change x.val.swap ∈ D.transpose + rw [YoungDiagram.mem_transpose, Prod.swap_swap] + exact x.property⟩ + invFun x := ⟨x.val.swap, (YoungDiagram.mem_transpose.mp x.property)⟩ + left_inv x := by apply Subtype.ext; exact Prod.swap_swap x.val + right_inv x := by apply Subtype.ext; exact Prod.swap_swap x.val + map_rel_iff' := by intro x y; exact and_comm + +lemma extensions_card_orderIso {A : Type uA} {B : Type uB} [Fintype A] [Fintype B] [PartialOrder A] [PartialOrder B] + (e : A ≃o B) : Fintype.card (Extensions A) = Fintype.card (Extensions B) := by + let c := finCongr (Fintype.card_congr e.toEquiv) + let F : Extensions A ≃ Extensions B := { + toFun := fun l => ⟨(e.symm.toEquiv.trans l.val).trans c, fun _ _ h => l.property (e.symm.strictMono h)⟩ + invFun := fun l => ⟨(e.toEquiv.trans l.val).trans c.symm, fun _ _ h => l.property (e.strictMono h)⟩ + left_inv := by intro l; apply Subtype.ext; ext x; simp [c] + right_inv := by intro l; apply Subtype.ext; ext x; simp [c] } + exact Fintype.card_congr F + +lemma rank_strictMono (D : YoungDiagram) : StrictMono (fun x : Cells D => x.val.1 + x.val.2) := by + intro x y hxy + have hle := hxy.le + have hn : x.val ≠ y.val := fun h => hxy.ne (Subtype.ext h) + have he : x.val.1 ≠ y.val.1 ∨ x.val.2 ≠ y.val.2 := by + by_contra hh + push Not at hh + exact hn (Prod.ext hh.1 hh.2) + change x.val.1 + x.val.2 < y.val.1 + y.val.2 + rcases he with he | he <;> have := hle.1 <;> have := hle.2 <;> omega + +def longest (D : YoungDiagram) : ℕ := max (D.rowLen 0) (D.colLen 0) + +lemma coord_lt_longest (D : YoungDiagram) (x : Cells D) : + x.val.1 < longest D ∧ x.val.2 < longest D := by + constructor + · exact (YoungDiagram.mem_iff_lt_colLen.mp (D.up_left_mem le_rfl (Nat.zero_le _) x.property)).trans_le (le_max_right _ _) + · exact (YoungDiagram.mem_iff_lt_rowLen.mp (D.up_left_mem (Nat.zero_le _) le_rfl x.property)).trans_le (le_max_left _ _) + +theorem factorial_le_rank_degree {n : ℕ} (D : YoungDiagram) (t : Fin n ≃ Cells D) : + n.factorial ≤ (2 * longest D) ^ n * Module.finrank ℂ (Thorp.Specht.module D t).toSubmodule := by + have hh := rank_extension_bound (Cells D) (fun x => x.val.1 + x.val.2) (rank_strictMono D) + (2 * longest D) (fun x => by have := coord_lt_longest D x; omega) + have hc : Fintype.card (Cells D) = n := (Fintype.card_congr t.symm).trans (Fintype.card_fin n) + rw [hc] at hh + exact hh.trans (Nat.mul_le_mul_left _ (Thorp.Specht.extensions_card_le_degree D t)) + +end Thorp.Young + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Main.lean b/lean/OAI/Probability/ThorpShuffle/Main.lean index 1591c20cc523c7fab723bf2797c8a29110ed70b4..53a54949d4e9f65f28d13952c30675e1d0a68781 100644 --- a/lean/OAI/Probability/ThorpShuffle/Main.lean +++ b/lean/OAI/Probability/ThorpShuffle/Main.lean @@ -1,59 +1,59 @@ -import OAI.Probability.ThorpShuffle.EightBlocks - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp - -theorem full_mixing : - Tendsto (fun d : ℕ => distance d (1600 * d)) atTop (nhds 0) := by - apply (tendsto_add_atTop_iff_nat 3).mp - simpa only [Nat.add_assoc] using Block.full_mixing_shift - -theorem mixingTime_isBigO_orderFunction : - Asymptotics.IsBigO atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction := by - rw [Asymptotics.isBigO_iff] - refine ⟨1600, ?_⟩ - have he : ∀ᶠ d : ℕ in atTop, distance d (1600*d) < 1/4 := - full_mixing.eventually (eventually_lt_nhds (by norm_num : (0:ℝ) < 1/4)) - filter_upwards [he] with d hd - have ht : mixingTime d ≤ 1600*d := Nat.sInf_le hd.le - simp only [orderFunction, Real.norm_eq_abs, abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) (mixingTime d)), - abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) d)] - exact_mod_cast ht - -theorem mixingTime_isTheta_orderFunction : - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction := - ⟨mixingTime_isBigO_orderFunction, orderFunction_isBigO_mixingTime⟩ - -theorem mixingTime_isTheta_log : - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) - (fun d : ℕ => Real.log (2^d : ℝ)) := by - have h := Asymptotics.IsTheta.const_mul_right - (show Real.log 2 ≠ 0 from (Real.log_pos (by norm_num : (1:ℝ) < 2)).ne') - mixingTime_isTheta_orderFunction - simpa only [orderFunction, Real.log_pow, mul_comm] using h - -theorem main : - Tendsto (fun d : ℕ => distance d (1600 * d)) atTop (nhds 0) ∧ - (∀ d : ℕ, 1 ≤ d → ∃ t : ℕ, distance d t ≤ 1 / 4) ∧ - (∀ (d t : ℕ) (g₀ : State d), tv (lawFrom d t g₀) (uniform d) = distance d t) ∧ - (∀ d : ℕ, 1 ≤ d → supportThreshold d ≤ (mixingTime d : ℤ)) ∧ - Asymptotics.IsBigO atTop - (fun d : ℕ => (supportThreshold d : ℝ) - 2 * (d : ℝ)) (fun _ => (1 : ℝ)) ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction ∧ - Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) - (fun d : ℕ => Real.log (2 ^ d : ℝ)) := by - exact ⟨full_mixing, fun _ hd => exists_mixing_time hd, worst_start_eq, - fun _ hd => exact_support_lower hd, supportThreshold_isBigO, - mixingTime_isTheta_orderFunction, mixingTime_isTheta_log⟩ - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.EightBlocks + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp + +theorem full_mixing : + Tendsto (fun d : ℕ => distance d (1600 * d)) atTop (nhds 0) := by + apply (tendsto_add_atTop_iff_nat 3).mp + simpa only [Nat.add_assoc] using Block.full_mixing_shift + +theorem mixingTime_isBigO_orderFunction : + Asymptotics.IsBigO atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction := by + rw [Asymptotics.isBigO_iff] + refine ⟨1600, ?_⟩ + have he : ∀ᶠ d : ℕ in atTop, distance d (1600*d) < 1/4 := + full_mixing.eventually (eventually_lt_nhds (by norm_num : (0:ℝ) < 1/4)) + filter_upwards [he] with d hd + have ht : mixingTime d ≤ 1600*d := Nat.sInf_le hd.le + simp only [orderFunction, Real.norm_eq_abs, abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) (mixingTime d)), + abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) d)] + exact_mod_cast ht + +theorem mixingTime_isTheta_orderFunction : + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction := + ⟨mixingTime_isBigO_orderFunction, orderFunction_isBigO_mixingTime⟩ + +theorem mixingTime_isTheta_log : + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) + (fun d : ℕ => Real.log (2^d : ℝ)) := by + have h := Asymptotics.IsTheta.const_mul_right + (show Real.log 2 ≠ 0 from (Real.log_pos (by norm_num : (1:ℝ) < 2)).ne') + mixingTime_isTheta_orderFunction + simpa only [orderFunction, Real.log_pow, mul_comm] using h + +theorem main : + Tendsto (fun d : ℕ => distance d (1600 * d)) atTop (nhds 0) ∧ + (∀ d : ℕ, 1 ≤ d → ∃ t : ℕ, distance d t ≤ 1 / 4) ∧ + (∀ (d t : ℕ) (g₀ : State d), tv (lawFrom d t g₀) (uniform d) = distance d t) ∧ + (∀ d : ℕ, 1 ≤ d → supportThreshold d ≤ (mixingTime d : ℤ)) ∧ + Asymptotics.IsBigO atTop + (fun d : ℕ => (supportThreshold d : ℝ) - 2 * (d : ℝ)) (fun _ => (1 : ℝ)) ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) orderFunction ∧ + Asymptotics.IsTheta atTop (fun d : ℕ => (mixingTime d : ℝ)) + (fun d : ℕ => Real.log (2 ^ d : ℝ)) := by + exact ⟨full_mixing, fun _ hd => exists_mixing_time hd, worst_start_eq, + fun _ hd => exact_support_lower hd, supportThreshold_isBigO, + mixingTime_isTheta_orderFunction, mixingTime_isTheta_log⟩ + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/MarginalBounds.lean b/lean/OAI/Probability/ThorpShuffle/MarginalBounds.lean index 3f2dc96aca856999805624515a96f1d84ba329a7..486f1aa8aac72a17f183cf8462e22b5cc45ded82 100644 --- a/lean/OAI/Probability/ThorpShuffle/MarginalBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/MarginalBounds.lean @@ -1,141 +1,141 @@ -import OAI.Probability.ThorpShuffle.PrefixTests - -namespace OAI - -universe uΩ uα uΩ' - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem fairMass_test {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Fintype α] - (a : Ω → α) (f : α → ℝ) : - (∑ x, fairMass a x * f x) = mean (fun ω => f (a ω)) := by - classical - unfold fairMass mean - simp only [div_mul_eq_mul_div, ← Finset.sum_div, Finset.sum_mul] - congr 1 - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - simp - -theorem fairMass_tv_le_of_test {Ω : Type uΩ} {Ω' : Type uΩ'} {α : Type uα} [Fintype Ω] [Fintype Ω'] [Fintype α] - (a : Ω → α) (b : Ω' → α) (δ : ℝ) - (h : ∀ f : α → ℝ, (∀ x, |f x| ≤ 1) → - |mean (fun ω => f (a ω)) - mean (fun ω => f (b ω))| ≤ δ) : - tv (fairMass a) (fairMass b) ≤ δ / 2 := by - classical - let f : α → ℝ := fun x => if 0 ≤ fairMass a x - fairMass b x then 1 else -1 - have hf : ∀ x, |f x| ≤ 1 := by intro x; dsimp [f]; split_ifs <;> norm_num - have hh := h f hf - rw [← fairMass_test, ← fairMass_test, ← Finset.sum_sub_distrib] at hh - have hid (x : α) : fairMass a x * f x - fairMass b x * f x = |fairMass a x - fairMass b x| := by - dsimp [f] - split_ifs with hx - · rw [abs_of_nonneg hx]; ring - · rw [abs_of_neg (lt_of_not_ge hx)]; ring - simp_rw [hid] at hh - rw [abs_of_nonneg (Finset.sum_nonneg (fun _ _ => abs_nonneg _))] at hh - unfold tv - linarith - -theorem marginal_tv_200 (d m k : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * m) - (hk : k + m ≤ Fintype.card (Position (d + 2))) - (e : Fin k → Position (d + 2)) (he : Function.Injective e) : - tv (fairMass (fun ω : History (d + 2) (200 * (d + 2)) => - (run (d + 2) (200 * (d + 2)) ω) ∘ e)) - (fairMass (fun g : State (d + 2) => g ∘ e)) ≤ - ((k : ℝ) / 2) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by - have h := fairMass_tv_le_of_test - (fun ω : History (d + 2) (200 * (d + 2)) => (run (d + 2) (200 * (d + 2)) ω) ∘ e) - (fun g : State (d + 2) => g ∘ e) - ((k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m))) - (prefix_test_bound d m hm k hk e he) - convert h using 1; ring - -end Conditional - -namespace Conditional - -def marginalRate (d : ℕ) : ℝ := - Real.sqrt (3136 * ((1 / 32 : ℝ) ^ d + (2 ^ d : ℝ) ^ 3 * (9 / 10 : ℝ) ^ (2 ^ d))) - -theorem marginalRate_tendsto : Tendsto marginalRate atTop (nhds 0) := by - have h₁ := tendsto_pow_atTop_nhds_zero_of_lt_one - (by norm_num : (0 : ℝ) ≤ 1 / 32) (by norm_num : (1 / 32 : ℝ) < 1) - have h₂ := (tendsto_pow_const_mul_const_pow_of_lt_one 3 - (by norm_num : (0 : ℝ) ≤ 9 / 10) (by norm_num : (9 / 10 : ℝ) < 1)).comp - (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) - have hh := ((h₁.add h₂).const_mul 3136).sqrt - unfold marginalRate - simpa only [Nat.cast_pow, Nat.cast_ofNat, Function.comp_def, - add_zero, mul_zero, Real.sqrt_zero] using hh - -theorem marginal_tv_rate (d : ℕ) (e : Fin (7 * 2 ^ d) → Position (d + 1 + 2)) - (he : Function.Injective e) : - tv (fairMass (fun ω : History (d + 1 + 2) (200 * (d + 1 + 2)) => - (run (d + 1 + 2) (200 * (d + 1 + 2)) ω) ∘ e)) - (fairMass (fun g : State (d + 1 + 2) => g ∘ e)) ≤ marginalRate d := by - have hc : Fintype.card (Position (d + 1 + 2)) = 8 * 2 ^ d := by - simp only [card_position, pow_add] - norm_num - omega - have hh := marginal_tv_200 (d + 1) (2 ^ d) (7 * 2 ^ d) - (by rw [hc]) (by rw [hc]; omega) e he - simp only [Nat.add_assoc] at hh - have hbound : - (((7 * 2 ^ d : ℕ) : ℝ) / 2) * - Real.sqrt ((Fintype.card (Position (d + 1 + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d))) ≤ marginalRate d := by - unfold marginalRate - apply Real.le_sqrt_of_sq_le - have hp : (1 / 2 : ℝ) ^ (8 * (d + 3)) ≤ (1 / 2 : ℝ) ^ (8 * d) := - pow_le_pow_of_le_one (by norm_num) (by norm_num) (by omega) - have hid : (2 ^ d : ℝ) ^ 3 * (1 / 2 : ℝ) ^ (8 * d) = (1 / 32 : ℝ) ^ d := by - rw [← pow_mul, Nat.mul_comm d 3, pow_mul, pow_mul, ← mul_pow] - norm_num - have hp' := mul_le_mul_of_nonneg_left hp (by positivity : (0 : ℝ) ≤ (2 ^ d : ℝ) ^ 3) - rw [hid] at hp' - have hsq : - (((7 * 2 ^ d : ℕ) : ℝ) / 2 * - Real.sqrt ((Fintype.card (Position (d + 1 + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d)))) ^ 2 = - 98 * (2 ^ d : ℝ) ^ 3 * - ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d)) := by - rw [mul_pow, Real.sq_sqrt (by positivity), hc] - push_cast - ring - rw [hsq] - nlinarith [pow_nonneg (by norm_num : (0 : ℝ) ≤ 1 / 32) d] - have hone := le_trans hh hbound - exact hone - -theorem marginal_tendsto (e : ∀ d : ℕ, Fin (7 * 2 ^ d) → Position (d + 1 + 2)) - (he : ∀ d, Function.Injective (e d)) : - Tendsto (fun d : ℕ => - tv (fairMass (fun ω : History (d + 1 + 2) (200 * (d + 1 + 2)) => - (run (d + 1 + 2) (200 * (d + 1 + 2)) ω) ∘ e d)) - (fairMass (fun g : State (d + 1 + 2) => g ∘ e d))) atTop (nhds 0) := by - apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds marginalRate_tendsto - · intro d - unfold tv - positivity - · intro d - exact marginal_tv_rate d (e d) (he d) - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.PrefixTests + +namespace OAI + +universe uΩ uα uΩ' + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem fairMass_test {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Fintype α] + (a : Ω → α) (f : α → ℝ) : + (∑ x, fairMass a x * f x) = mean (fun ω => f (a ω)) := by + classical + unfold fairMass mean + simp only [div_mul_eq_mul_div, ← Finset.sum_div, Finset.sum_mul] + congr 1 + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + simp + +theorem fairMass_tv_le_of_test {Ω : Type uΩ} {Ω' : Type uΩ'} {α : Type uα} [Fintype Ω] [Fintype Ω'] [Fintype α] + (a : Ω → α) (b : Ω' → α) (δ : ℝ) + (h : ∀ f : α → ℝ, (∀ x, |f x| ≤ 1) → + |mean (fun ω => f (a ω)) - mean (fun ω => f (b ω))| ≤ δ) : + tv (fairMass a) (fairMass b) ≤ δ / 2 := by + classical + let f : α → ℝ := fun x => if 0 ≤ fairMass a x - fairMass b x then 1 else -1 + have hf : ∀ x, |f x| ≤ 1 := by intro x; dsimp [f]; split_ifs <;> norm_num + have hh := h f hf + rw [← fairMass_test, ← fairMass_test, ← Finset.sum_sub_distrib] at hh + have hid (x : α) : fairMass a x * f x - fairMass b x * f x = |fairMass a x - fairMass b x| := by + dsimp [f] + split_ifs with hx + · rw [abs_of_nonneg hx]; ring + · rw [abs_of_neg (lt_of_not_ge hx)]; ring + simp_rw [hid] at hh + rw [abs_of_nonneg (Finset.sum_nonneg (fun _ _ => abs_nonneg _))] at hh + unfold tv + linarith + +theorem marginal_tv_200 (d m k : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * m) + (hk : k + m ≤ Fintype.card (Position (d + 2))) + (e : Fin k → Position (d + 2)) (he : Function.Injective e) : + tv (fairMass (fun ω : History (d + 2) (200 * (d + 2)) => + (run (d + 2) (200 * (d + 2)) ω) ∘ e)) + (fairMass (fun g : State (d + 2) => g ∘ e)) ≤ + ((k : ℝ) / 2) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by + have h := fairMass_tv_le_of_test + (fun ω : History (d + 2) (200 * (d + 2)) => (run (d + 2) (200 * (d + 2)) ω) ∘ e) + (fun g : State (d + 2) => g ∘ e) + ((k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m))) + (prefix_test_bound d m hm k hk e he) + convert h using 1; ring + +end Conditional + +namespace Conditional + +def marginalRate (d : ℕ) : ℝ := + Real.sqrt (3136 * ((1 / 32 : ℝ) ^ d + (2 ^ d : ℝ) ^ 3 * (9 / 10 : ℝ) ^ (2 ^ d))) + +theorem marginalRate_tendsto : Tendsto marginalRate atTop (nhds 0) := by + have h₁ := tendsto_pow_atTop_nhds_zero_of_lt_one + (by norm_num : (0 : ℝ) ≤ 1 / 32) (by norm_num : (1 / 32 : ℝ) < 1) + have h₂ := (tendsto_pow_const_mul_const_pow_of_lt_one 3 + (by norm_num : (0 : ℝ) ≤ 9 / 10) (by norm_num : (9 / 10 : ℝ) < 1)).comp + (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1 : ℕ) < 2)) + have hh := ((h₁.add h₂).const_mul 3136).sqrt + unfold marginalRate + simpa only [Nat.cast_pow, Nat.cast_ofNat, Function.comp_def, + add_zero, mul_zero, Real.sqrt_zero] using hh + +theorem marginal_tv_rate (d : ℕ) (e : Fin (7 * 2 ^ d) → Position (d + 1 + 2)) + (he : Function.Injective e) : + tv (fairMass (fun ω : History (d + 1 + 2) (200 * (d + 1 + 2)) => + (run (d + 1 + 2) (200 * (d + 1 + 2)) ω) ∘ e)) + (fairMass (fun g : State (d + 1 + 2) => g ∘ e)) ≤ marginalRate d := by + have hc : Fintype.card (Position (d + 1 + 2)) = 8 * 2 ^ d := by + simp only [card_position, pow_add] + norm_num + omega + have hh := marginal_tv_200 (d + 1) (2 ^ d) (7 * 2 ^ d) + (by rw [hc]) (by rw [hc]; omega) e he + simp only [Nat.add_assoc] at hh + have hbound : + (((7 * 2 ^ d : ℕ) : ℝ) / 2) * + Real.sqrt ((Fintype.card (Position (d + 1 + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d))) ≤ marginalRate d := by + unfold marginalRate + apply Real.le_sqrt_of_sq_le + have hp : (1 / 2 : ℝ) ^ (8 * (d + 3)) ≤ (1 / 2 : ℝ) ^ (8 * d) := + pow_le_pow_of_le_one (by norm_num) (by norm_num) (by omega) + have hid : (2 ^ d : ℝ) ^ 3 * (1 / 2 : ℝ) ^ (8 * d) = (1 / 32 : ℝ) ^ d := by + rw [← pow_mul, Nat.mul_comm d 3, pow_mul, pow_mul, ← mul_pow] + norm_num + have hp' := mul_le_mul_of_nonneg_left hp (by positivity : (0 : ℝ) ≤ (2 ^ d : ℝ) ^ 3) + rw [hid] at hp' + have hsq : + (((7 * 2 ^ d : ℕ) : ℝ) / 2 * + Real.sqrt ((Fintype.card (Position (d + 1 + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d)))) ^ 2 = + 98 * (2 ^ d : ℝ) ^ 3 * + ((1 / 2 : ℝ) ^ (8 * (d + 3)) + 32 * (9 / 10 : ℝ) ^ (2 ^ d)) := by + rw [mul_pow, Real.sq_sqrt (by positivity), hc] + push_cast + ring + rw [hsq] + nlinarith [pow_nonneg (by norm_num : (0 : ℝ) ≤ 1 / 32) d] + have hone := le_trans hh hbound + exact hone + +theorem marginal_tendsto (e : ∀ d : ℕ, Fin (7 * 2 ^ d) → Position (d + 1 + 2)) + (he : ∀ d, Function.Injective (e d)) : + Tendsto (fun d : ℕ => + tv (fairMass (fun ω : History (d + 1 + 2) (200 * (d + 1 + 2)) => + (run (d + 1 + 2) (200 * (d + 1 + 2)) ω) ∘ e d)) + (fairMass (fun g : State (d + 1 + 2) => g ∘ e d))) atTop (nhds 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds marginalRate_tendsto + · intro d + unfold tv + positivity + · intro d + exact marginal_tv_rate d (e d) (he d) + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/MarginalEnergy.lean b/lean/OAI/Probability/ThorpShuffle/MarginalEnergy.lean index 07b63596e928beba9df65748b1b5e6770835d6b6..467212277683d3ca8af89ab9bcaa02a82c213697 100644 --- a/lean/OAI/Probability/ThorpShuffle/MarginalEnergy.lean +++ b/lean/OAI/Probability/ThorpShuffle/MarginalEnergy.lean @@ -1,208 +1,208 @@ -import OAI.Probability.ThorpShuffle.EnergyDecay - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem freeCount_eq_sum {α : Type uα} [Fintype α] (B : α → Bool) : - freeCount B = ∑ x, (B x).toNat := by - classical - calc - freeCount B = ∑ x, if B x = true then (1 : ℕ) else 0 := (Finset.sum_boole _ _).symm - _ = _ := Finset.sum_congr rfl (fun x _ => by cases B x <;> rfl) - -theorem pairFreeCount_physical (d : ℕ) (B : Position (d + 1) → Bool) : - pairFreeCount (B ∘ (splitPosition d).symm) = freeCount B := by - rw [freeCount_eq_sum] - have he := Equiv.sum_comp (splitPosition d).symm (fun x => (B x).toNat) - rw [← he, Fintype.sum_prod_type, Fintype.sum_bool] - simp only [pairFreeCount, Function.comp_apply, Finset.sum_add_distrib] - exact Nat.add_comm _ _ - -theorem halfCount_after_step (d : ℕ) (v : RawState (d + 1)) - (c : Coins (d + 1)) (h : Bool) : - freeCount (halfRaw d (Fin.last d) h (rawNext d v c)).free = - pairHalfCount (v.free ∘ (splitPosition d).symm) c h := by - rw [freeCount_eq_sum] - unfold halfRaw rawNext pairHalfCount - simp only [insertBit_last] - apply Finset.sum_congr rfl - intro x _ - erw [physicalFree_snoc] - rfl - -theorem halfDensity_after_step (d : ℕ) (v : RawState (d + 1)) - (c : Coins (d + 1)) (h : Bool) - (hm : Fintype.card (Position (d + 1)) ≤ 8 * freeCount v.free) - (hc : freeCount v.free ≤ 4 * pairHalfCount (v.free ∘ (splitPosition d).symm) c h) : - (1 / 16 : ℝ) ≤ startHalfDensity d (rawNext d v c) h := by - unfold startHalfDensity - rw [halfCount_after_step] - have hn : Fintype.card (Position (d + 1)) = 2 * Fintype.card (Position d) := by - simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin, pow_succ, Nat.mul_comm] - rw [hn] at hm - have hm' : (2 : ℝ) * Fintype.card (Position d) ≤ 8 * (freeCount v.free : ℝ) := by - exact_mod_cast hm - have hc' : (freeCount v.free : ℝ) ≤ - 4 * (pairHalfCount (v.free ∘ (splitPosition d).symm) c h : ℝ) := by exact_mod_cast hc - apply (le_div_iff₀ (by exact_mod_cast Fintype.card_pos (α := Position d))).mpr - nlinarith - -theorem partnerEnergy_nonneg (d : ℕ) (v : RawState (d + 1)) (h : Bool) : - 0 ≤ partnerEnergy d v h := by - unfold partnerEnergy - exact Finset.sum_nonneg (fun _ _ => mul_nonneg (sq_nonneg _) (by split_ifs <;> norm_num)) - -theorem oneFreeEnergy_le (d : ℕ) (v : RawState (d + 1)) : - oneFreeEnergy d v.free v.weight ≤ rawEnergy v := by - have hid := oneFreeEnergy_partner d v - linarith [partnerEnergy_nonneg d v false, partnerEnergy_nonneg d v true] - -theorem expectedNoise_le_energy (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : - expectedNoise d v t ≤ expectedEnergy d v t := by - apply mean_le_mean - intro ω - exact oneFreeEnergy_le d (iterateState d v t ω).raw - -theorem noise_bound_balanced_state (d : ℕ) (v : CenteredState (d + 2)) - (β : ℝ) (hb : ∀ h, β ≤ startHalfDensity (d + 1) v.raw h) : - expectedNoise (d + 1) v (d + 1) ≤ (1 - β) * expectedEnergy (d + 1) v (d + 1) := by - have he := noise_bound_balanced_halves d v.raw β hb - simp_rw [← iterateState_raw] at he - exact he - -def singleHistory (d : ℕ) : Coins d ≃ History d 1 where - toFun c := fun _ => c - invFun ω := ω 0 - left_inv _ := rfl - right_inv ω := by - funext i - change ω 0 = ω i - rw [Subsingleton.elim i 0] - -theorem mean_history_one (d : ℕ) (f : History d 1 → ℝ) : - mean f = mean (fun c : Coins d => f (fun _ => c)) := - (mean_equiv (singleHistory d) f).symm - -@[simp] theorem iterateState_one (d : ℕ) (v : CenteredState (d + 1)) (c : Coins (d + 1)) : - iterateState d v 1 (fun _ => c) = nextState d v c := rfl - -theorem expectedEnergy_first (d t : ℕ) (v : CenteredState (d + 1)) : - expectedEnergy d v (t + 1) = - mean (fun c : Coins (d + 1) => expectedEnergy d (nextState d v c) t) := by - rw [Nat.add_comm t 1, expectedEnergy_add, mean_history_one] - rfl - -theorem expectedNoise_first (d t : ℕ) (v : CenteredState (d + 1)) : - expectedNoise d v (t + 1) = - mean (fun c : Coins (d + 1) => expectedNoise d (nextState d v c) t) := by - rw [Nat.add_comm t 1, expectedNoise_add, mean_history_one] - rfl - -theorem expectedNoise_dimension (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) : - expectedNoise (d + 1) v (d + 2) ≤ (15 / 16 : ℝ) * expectedEnergy (d + 1) v (d + 2) + - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - let B := v.free ∘ (splitPosition (d + 1)).symm - let bad (c : Coins (d + 2)) : Prop := - 4 * pairHalfCount B c false < pairFreeCount B ∨ - 4 * pairHalfCount B c true < pairFreeCount B - have hlocal (c : Coins (d + 2)) : - expectedNoise (d + 1) (nextState (d + 1) v c) (d + 1) ≤ - (15 / 16 : ℝ) * expectedEnergy (d + 1) (nextState (d + 1) v c) (d + 1) + - (if bad c then 1 else 0) := by - by_cases hc : bad c - · rw [ite_eq_left hc] - have hle := expectedNoise_le_energy (d + 1) (nextState (d + 1) v c) (d + 1) - have hone := expectedEnergy_le_one (d + 1) (nextState (d + 1) v c) (d + 1) - linarith - · rw [ite_eq_right hc, add_zero] - have hb (h : Bool) : (1 / 16 : ℝ) ≤ - startHalfDensity (d + 1) (nextState (d + 1) v c).raw h := by - apply halfDensity_after_step (d + 1) v.raw c h hm - have hf : ¬ 4 * pairHalfCount B c false < freeCount v.free := by - simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.1 - have ht : ¬ 4 * pairHalfCount B c true < freeCount v.free := by - simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.2 - change freeCount v.free ≤ 4 * pairHalfCount B c h - cases h - · exact Nat.le_of_not_gt hf - · exact Nat.le_of_not_gt ht - convert noise_bound_balanced_state d (nextState (d + 1) v c) (1 / 16) hb using 1; norm_num - have hmean := mean_le_mean hlocal - rw [mean_add, mean_const_mul, ← expectedNoise_first, ← expectedEnergy_first] at hmean - have hbad := pair_both_half_balance B - have hbad' : mean (fun c : Coins (d + 2) => if bad c then (1 : ℝ) else 0) ≤ - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - change mean (fun c : Position (d + 1) → Bool => if bad c then (1 : ℝ) else 0) ≤ _ - simpa only [bad, B, pairFreeCount_physical] using hbad - exact hmean.trans (add_le_add (le_refl _) hbad') - -theorem expectedNoise_bound (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) - (s : ℕ) (hs : d + 2 ≤ s) : - expectedNoise (d + 1) v s ≤ (15 / 16 : ℝ) * expectedEnergy (d + 1) v s + - 2 * (9 / 10 : ℝ) ^ freeCount v.free := by - obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hs - rw [Nat.add_comm (d + 2) a, expectedNoise_add, expectedEnergy_add] - have he := mean_le_mean (fun ω : History (d + 2) a => - expectedNoise_dimension d (iterateState (d + 1) v a ω) - (by simpa only [iterateState_freeCount] using hm)) - simpa only [iterateState_freeCount, mean_add, mean_const_mul, mean_const] using he - -end Conditional - -namespace Conditional - -theorem expectedEnergy_decay (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) (t : ℕ) : - expectedEnergy (d + 1) v t ≤ - (31 / 32 : ℝ) ^ t / (31 / 32 : ℝ) ^ (2 * (d + 2)) + - 32 * (9 / 10 : ℝ) ^ freeCount v.free := by - have he := scalar_decay (d + 2) (expectedEnergy (d + 1) v) - (expectedNoise (d + 1) v) (1 / 16) (31 / 32) - (2 * (9 / 10 : ℝ) ^ freeCount v.free) - (by norm_num) (by norm_num) (by norm_num) (by norm_num) - (by norm_num) (by positivity) (expectedEnergy_le_one (d + 1) v) - (expectedEnergy_recurrence (d + 1) v) - (by intro s hs; convert expectedNoise_bound d v hm s hs using 1; norm_num) t - convert he using 1; ring - -theorem expectedEnergy_200 (d : ℕ) (v : CenteredState (d + 2)) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) : - expectedEnergy (d + 1) v (200 * (d + 2)) ≤ - (1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ freeCount v.free := by - have he := expectedEnergy_decay d v hm (200 * (d + 2)) - have hp : (31 / 32 : ℝ) ^ (200 * (d + 2)) / (31 / 32 : ℝ) ^ (2 * (d + 2)) = - (31 / 32 : ℝ) ^ (198 * (d + 2)) := by - have hn : 200 * (d + 2) = 198 * (d + 2) + 2 * (d + 2) := by omega - rw [hn, pow_add, mul_div_cancel_right₀ _ (by positivity)] - rw [hp] at he - have hpow := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ (31 / 32) ^ 198) - eight_block_geometric_choice (d + 2) - rw [← pow_mul, ← pow_mul] at hpow - exact he.trans (add_le_add hpow (le_refl _)) - -theorem centeredPoint_energy_200 (d : ℕ) (B : Position (d + 2) → Bool) - (tag : Position (d + 2)) (ht : B tag = true) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount B) : - expectedEnergy (d + 1) (initialState (d + 2) B tag ht) (200 * (d + 2)) ≤ - (1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ freeCount B := - expectedEnergy_200 d _ hm - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.EnergyDecay + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem freeCount_eq_sum {α : Type uα} [Fintype α] (B : α → Bool) : + freeCount B = ∑ x, (B x).toNat := by + classical + calc + freeCount B = ∑ x, if B x = true then (1 : ℕ) else 0 := (Finset.sum_boole _ _).symm + _ = _ := Finset.sum_congr rfl (fun x _ => by cases B x <;> rfl) + +theorem pairFreeCount_physical (d : ℕ) (B : Position (d + 1) → Bool) : + pairFreeCount (B ∘ (splitPosition d).symm) = freeCount B := by + rw [freeCount_eq_sum] + have he := Equiv.sum_comp (splitPosition d).symm (fun x => (B x).toNat) + rw [← he, Fintype.sum_prod_type, Fintype.sum_bool] + simp only [pairFreeCount, Function.comp_apply, Finset.sum_add_distrib] + exact Nat.add_comm _ _ + +theorem halfCount_after_step (d : ℕ) (v : RawState (d + 1)) + (c : Coins (d + 1)) (h : Bool) : + freeCount (halfRaw d (Fin.last d) h (rawNext d v c)).free = + pairHalfCount (v.free ∘ (splitPosition d).symm) c h := by + rw [freeCount_eq_sum] + unfold halfRaw rawNext pairHalfCount + simp only [insertBit_last] + apply Finset.sum_congr rfl + intro x _ + erw [physicalFree_snoc] + rfl + +theorem halfDensity_after_step (d : ℕ) (v : RawState (d + 1)) + (c : Coins (d + 1)) (h : Bool) + (hm : Fintype.card (Position (d + 1)) ≤ 8 * freeCount v.free) + (hc : freeCount v.free ≤ 4 * pairHalfCount (v.free ∘ (splitPosition d).symm) c h) : + (1 / 16 : ℝ) ≤ startHalfDensity d (rawNext d v c) h := by + unfold startHalfDensity + rw [halfCount_after_step] + have hn : Fintype.card (Position (d + 1)) = 2 * Fintype.card (Position d) := by + simp [Fintype.card_pi, Fintype.card_bool, Fintype.card_fin, pow_succ, Nat.mul_comm] + rw [hn] at hm + have hm' : (2 : ℝ) * Fintype.card (Position d) ≤ 8 * (freeCount v.free : ℝ) := by + exact_mod_cast hm + have hc' : (freeCount v.free : ℝ) ≤ + 4 * (pairHalfCount (v.free ∘ (splitPosition d).symm) c h : ℝ) := by exact_mod_cast hc + apply (le_div_iff₀ (by exact_mod_cast Fintype.card_pos (α := Position d))).mpr + nlinarith + +theorem partnerEnergy_nonneg (d : ℕ) (v : RawState (d + 1)) (h : Bool) : + 0 ≤ partnerEnergy d v h := by + unfold partnerEnergy + exact Finset.sum_nonneg (fun _ _ => mul_nonneg (sq_nonneg _) (by split_ifs <;> norm_num)) + +theorem oneFreeEnergy_le (d : ℕ) (v : RawState (d + 1)) : + oneFreeEnergy d v.free v.weight ≤ rawEnergy v := by + have hid := oneFreeEnergy_partner d v + linarith [partnerEnergy_nonneg d v false, partnerEnergy_nonneg d v true] + +theorem expectedNoise_le_energy (d : ℕ) (v : CenteredState (d + 1)) (t : ℕ) : + expectedNoise d v t ≤ expectedEnergy d v t := by + apply mean_le_mean + intro ω + exact oneFreeEnergy_le d (iterateState d v t ω).raw + +theorem noise_bound_balanced_state (d : ℕ) (v : CenteredState (d + 2)) + (β : ℝ) (hb : ∀ h, β ≤ startHalfDensity (d + 1) v.raw h) : + expectedNoise (d + 1) v (d + 1) ≤ (1 - β) * expectedEnergy (d + 1) v (d + 1) := by + have he := noise_bound_balanced_halves d v.raw β hb + simp_rw [← iterateState_raw] at he + exact he + +def singleHistory (d : ℕ) : Coins d ≃ History d 1 where + toFun c := fun _ => c + invFun ω := ω 0 + left_inv _ := rfl + right_inv ω := by + funext i + change ω 0 = ω i + rw [Subsingleton.elim i 0] + +theorem mean_history_one (d : ℕ) (f : History d 1 → ℝ) : + mean f = mean (fun c : Coins d => f (fun _ => c)) := + (mean_equiv (singleHistory d) f).symm + +@[simp] theorem iterateState_one (d : ℕ) (v : CenteredState (d + 1)) (c : Coins (d + 1)) : + iterateState d v 1 (fun _ => c) = nextState d v c := rfl + +theorem expectedEnergy_first (d t : ℕ) (v : CenteredState (d + 1)) : + expectedEnergy d v (t + 1) = + mean (fun c : Coins (d + 1) => expectedEnergy d (nextState d v c) t) := by + rw [Nat.add_comm t 1, expectedEnergy_add, mean_history_one] + rfl + +theorem expectedNoise_first (d t : ℕ) (v : CenteredState (d + 1)) : + expectedNoise d v (t + 1) = + mean (fun c : Coins (d + 1) => expectedNoise d (nextState d v c) t) := by + rw [Nat.add_comm t 1, expectedNoise_add, mean_history_one] + rfl + +theorem expectedNoise_dimension (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) : + expectedNoise (d + 1) v (d + 2) ≤ (15 / 16 : ℝ) * expectedEnergy (d + 1) v (d + 2) + + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + let B := v.free ∘ (splitPosition (d + 1)).symm + let bad (c : Coins (d + 2)) : Prop := + 4 * pairHalfCount B c false < pairFreeCount B ∨ + 4 * pairHalfCount B c true < pairFreeCount B + have hlocal (c : Coins (d + 2)) : + expectedNoise (d + 1) (nextState (d + 1) v c) (d + 1) ≤ + (15 / 16 : ℝ) * expectedEnergy (d + 1) (nextState (d + 1) v c) (d + 1) + + (if bad c then 1 else 0) := by + by_cases hc : bad c + · rw [ite_eq_left hc] + have hle := expectedNoise_le_energy (d + 1) (nextState (d + 1) v c) (d + 1) + have hone := expectedEnergy_le_one (d + 1) (nextState (d + 1) v c) (d + 1) + linarith + · rw [ite_eq_right hc, add_zero] + have hb (h : Bool) : (1 / 16 : ℝ) ≤ + startHalfDensity (d + 1) (nextState (d + 1) v c).raw h := by + apply halfDensity_after_step (d + 1) v.raw c h hm + have hf : ¬ 4 * pairHalfCount B c false < freeCount v.free := by + simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.1 + have ht : ¬ 4 * pairHalfCount B c true < freeCount v.free := by + simpa only [B, pairFreeCount_physical] using not_or.mp hc |>.2 + change freeCount v.free ≤ 4 * pairHalfCount B c h + cases h + · exact Nat.le_of_not_gt hf + · exact Nat.le_of_not_gt ht + convert noise_bound_balanced_state d (nextState (d + 1) v c) (1 / 16) hb using 1; norm_num + have hmean := mean_le_mean hlocal + rw [mean_add, mean_const_mul, ← expectedNoise_first, ← expectedEnergy_first] at hmean + have hbad := pair_both_half_balance B + have hbad' : mean (fun c : Coins (d + 2) => if bad c then (1 : ℝ) else 0) ≤ + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + change mean (fun c : Position (d + 1) → Bool => if bad c then (1 : ℝ) else 0) ≤ _ + simpa only [bad, B, pairFreeCount_physical] using hbad + exact hmean.trans (add_le_add (le_refl _) hbad') + +theorem expectedNoise_bound (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) + (s : ℕ) (hs : d + 2 ≤ s) : + expectedNoise (d + 1) v s ≤ (15 / 16 : ℝ) * expectedEnergy (d + 1) v s + + 2 * (9 / 10 : ℝ) ^ freeCount v.free := by + obtain ⟨a, rfl⟩ := Nat.exists_eq_add_of_le hs + rw [Nat.add_comm (d + 2) a, expectedNoise_add, expectedEnergy_add] + have he := mean_le_mean (fun ω : History (d + 2) a => + expectedNoise_dimension d (iterateState (d + 1) v a ω) + (by simpa only [iterateState_freeCount] using hm)) + simpa only [iterateState_freeCount, mean_add, mean_const_mul, mean_const] using he + +end Conditional + +namespace Conditional + +theorem expectedEnergy_decay (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) (t : ℕ) : + expectedEnergy (d + 1) v t ≤ + (31 / 32 : ℝ) ^ t / (31 / 32 : ℝ) ^ (2 * (d + 2)) + + 32 * (9 / 10 : ℝ) ^ freeCount v.free := by + have he := scalar_decay (d + 2) (expectedEnergy (d + 1) v) + (expectedNoise (d + 1) v) (1 / 16) (31 / 32) + (2 * (9 / 10 : ℝ) ^ freeCount v.free) + (by norm_num) (by norm_num) (by norm_num) (by norm_num) + (by norm_num) (by positivity) (expectedEnergy_le_one (d + 1) v) + (expectedEnergy_recurrence (d + 1) v) + (by intro s hs; convert expectedNoise_bound d v hm s hs using 1; norm_num) t + convert he using 1; ring + +theorem expectedEnergy_200 (d : ℕ) (v : CenteredState (d + 2)) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount v.free) : + expectedEnergy (d + 1) v (200 * (d + 2)) ≤ + (1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ freeCount v.free := by + have he := expectedEnergy_decay d v hm (200 * (d + 2)) + have hp : (31 / 32 : ℝ) ^ (200 * (d + 2)) / (31 / 32 : ℝ) ^ (2 * (d + 2)) = + (31 / 32 : ℝ) ^ (198 * (d + 2)) := by + have hn : 200 * (d + 2) = 198 * (d + 2) + 2 * (d + 2) := by omega + rw [hn, pow_add, mul_div_cancel_right₀ _ (by positivity)] + rw [hp] at he + have hpow := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ (31 / 32) ^ 198) + eight_block_geometric_choice (d + 2) + rw [← pow_mul, ← pow_mul] at hpow + exact he.trans (add_le_add hpow (le_refl _)) + +theorem centeredPoint_energy_200 (d : ℕ) (B : Position (d + 2) → Bool) + (tag : Position (d + 2)) (ht : B tag = true) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * freeCount B) : + expectedEnergy (d + 1) (initialState (d + 2) B tag ht) (200 * (d + 2)) ≤ + (1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ freeCount B := + expectedEnergy_200 d _ hm + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/MaskedResampling.lean b/lean/OAI/Probability/ThorpShuffle/MaskedResampling.lean index b26da45440ccc6b448bd04b2c34ecf0a6e94f4cc..7c43a5e603ae568e09f34f9a053909d9fcfaa240 100644 --- a/lean/OAI/Probability/ThorpShuffle/MaskedResampling.lean +++ b/lean/OAI/Probability/ThorpShuffle/MaskedResampling.lean @@ -1,129 +1,129 @@ -import OAI.Probability.ThorpShuffle.MarginalEnergy - -namespace OAI - -universe uα uι - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def maskedCoin {α : Type uα} (mask : α → Bool) (c r : α → Bool) : α → Bool := - fun x => if mask x then r x else c x - -def maskSwap {α : Type uα} (mask : α → Bool) : - Equiv.Perm ((α → Bool) × (α → Bool)) := - Function.Involutive.toPerm - (fun p => (maskedCoin mask p.1 p.2, maskedCoin mask p.2 p.1)) (by - intro p - apply Prod.ext <;> funext x <;> - cases hm : mask x <;> simp [maskedCoin, hm]) - -theorem mean_maskedCoin {α : Type uα} [Fintype α] [DecidableEq α] - (mask : α → Bool) (f : (α → Bool) → ℝ) : - mean (fun c : α → Bool => mean (fun r : α → Bool => f (maskedCoin mask c r))) = - mean f := by - have he := mean_equiv (maskSwap mask) (fun p => f p.1) - change mean (fun p : (α → Bool) × (α → Bool) => f (maskedCoin mask p.1 p.2)) = _ at he - rw [mean_prod, mean_prod] at he - simpa only [mean_const] using he - -def freePairMask (d : ℕ) (B : Position (d + 1) → Bool) : Position d → Bool := - fun x => B (Fin.cons false x) && B (Fin.cons true x) - -theorem step_cons (d : ℕ) (c : Position d → Bool) (b : Bool) (x : Position d) : - step (d + 1) c (Fin.cons b x) = scatterPosition d (b ^^ c x, x) := by - simp [step, scatterPosition, splitPosition, pairSwitch] - -theorem masked_step_occupied (d : ℕ) (B : Position (d + 1) → Bool) - (c r : Position d → Bool) (x : Position (d + 1)) (hx : B x = false) : - step (d + 1) (maskedCoin (freePairMask d B) c r) x = step (d + 1) c x := by - obtain ⟨⟨b, y⟩, rfl⟩ := (splitPosition d).symm.surjective x - change B (Fin.cons b y) = false at hx - change step (d + 1) (maskedCoin (freePairMask d B) c r) (Fin.cons b y) = - step (d + 1) c (Fin.cons b y) - rw [step_cons, step_cons] - cases b <;> simp [maskedCoin, freePairMask, hx] - -theorem physicalFlow_resampling (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Position d → Bool) (y : Position (d + 1)) : - physicalFlow d B w c y = mean (fun r : Position d → Bool => - w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y)) := by - obtain ⟨⟨b, x⟩, rfl⟩ := (scatterPosition d).surjective y - have hs : mean (fun r : Position d → Bool => - w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm - (scatterPosition d (b, x)))) = - mean (fun r : Position d → Bool => - w (Fin.cons (b ^^ maskedCoin (freePairMask d B) c r x) x)) := by - apply mean_congr - intro r - exact congrArg w (step_symm_scatter d (maskedCoin (freePairMask d B) c r) (b, x)) - rw [hs] - erw [physicalFlow_scatter] - change (if b then (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2 - else (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1) = - mean (fun r : Position d → Bool => - w (Fin.cons (b ^^ (if freePairMask d B x then r x else c x)) x)) - rw [mean_coin_eval x (fun z => w (Fin.cons (b ^^ (if freePairMask d B x then z else c x)) x))] - cases h0 : B (Fin.cons false x) <;> cases h1 : B (Fin.cons true x) <;> - cases b <;> cases c x <;> - simp [pairUpdate, freePairMask, h0, h1, mean_bool] <;> ring - -theorem masked_step_exposed {ι : Type uι} (d : ℕ) (B : Position (d + 1) → Bool) - (e : ι → Position (d + 1)) (he : ∀ i, B (e i) = false) (c r : Position d → Bool) : - (step (d + 1) (maskedCoin (freePairMask d B) c r)) ∘ e = (step (d + 1) c) ∘ e := by - funext i - exact masked_step_occupied d B c r (e i) (he i) - -theorem physicalFlow_joint {ι : Type uι} (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (e : ι → Position (d + 1)) - (he : ∀ i, B (e i) = false) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : - mean (fun c : Position d → Bool => ∑ y, physicalFlow d B w c y * f ((step (d + 1) c) ∘ e) y) = - mean (fun c : Position d → Bool => ∑ x, w x * f ((step (d + 1) c) ∘ e) (step (d + 1) c x)) := by - calc - _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => - ∑ y, w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y) * - f ((step (d + 1) c) ∘ e) y)) := by - apply mean_congr - intro c - rw [mean_sum] - apply Finset.sum_congr rfl - intro y _ - rw [mean_mul_const, physicalFlow_resampling] - _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => - ∑ x, w x * f ((step (d + 1) c) ∘ e) - (step (d + 1) (maskedCoin (freePairMask d B) c r) x))) := by - apply mean_congr - intro c - apply mean_congr - intro r - simpa only [Equiv.symm_apply_apply] using - (Equiv.sum_comp (step (d + 1) (maskedCoin (freePairMask d B) c r)) - (fun y => w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y) * - f ((step (d + 1) c) ∘ e) y)).symm - _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => - ∑ x, w x * f ((step (d + 1) (maskedCoin (freePairMask d B) c r)) ∘ e) - (step (d + 1) (maskedCoin (freePairMask d B) c r) x))) := by - apply mean_congr - intro c - apply mean_congr - intro r - rw [masked_step_exposed d B e he c r] - _ = _ := by - exact mean_maskedCoin (freePairMask d B) (fun c => ∑ x, w x * - f ((step (d + 1) c) ∘ e) (step (d + 1) c x)) - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.MarginalEnergy + +namespace OAI + +universe uα uι + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def maskedCoin {α : Type uα} (mask : α → Bool) (c r : α → Bool) : α → Bool := + fun x => if mask x then r x else c x + +def maskSwap {α : Type uα} (mask : α → Bool) : + Equiv.Perm ((α → Bool) × (α → Bool)) := + Function.Involutive.toPerm + (fun p => (maskedCoin mask p.1 p.2, maskedCoin mask p.2 p.1)) (by + intro p + apply Prod.ext <;> funext x <;> + cases hm : mask x <;> simp [maskedCoin, hm]) + +theorem mean_maskedCoin {α : Type uα} [Fintype α] [DecidableEq α] + (mask : α → Bool) (f : (α → Bool) → ℝ) : + mean (fun c : α → Bool => mean (fun r : α → Bool => f (maskedCoin mask c r))) = + mean f := by + have he := mean_equiv (maskSwap mask) (fun p => f p.1) + change mean (fun p : (α → Bool) × (α → Bool) => f (maskedCoin mask p.1 p.2)) = _ at he + rw [mean_prod, mean_prod] at he + simpa only [mean_const] using he + +def freePairMask (d : ℕ) (B : Position (d + 1) → Bool) : Position d → Bool := + fun x => B (Fin.cons false x) && B (Fin.cons true x) + +theorem step_cons (d : ℕ) (c : Position d → Bool) (b : Bool) (x : Position d) : + step (d + 1) c (Fin.cons b x) = scatterPosition d (b ^^ c x, x) := by + simp [step, scatterPosition, splitPosition, pairSwitch] + +theorem masked_step_occupied (d : ℕ) (B : Position (d + 1) → Bool) + (c r : Position d → Bool) (x : Position (d + 1)) (hx : B x = false) : + step (d + 1) (maskedCoin (freePairMask d B) c r) x = step (d + 1) c x := by + obtain ⟨⟨b, y⟩, rfl⟩ := (splitPosition d).symm.surjective x + change B (Fin.cons b y) = false at hx + change step (d + 1) (maskedCoin (freePairMask d B) c r) (Fin.cons b y) = + step (d + 1) c (Fin.cons b y) + rw [step_cons, step_cons] + cases b <;> simp [maskedCoin, freePairMask, hx] + +theorem physicalFlow_resampling (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Position d → Bool) (y : Position (d + 1)) : + physicalFlow d B w c y = mean (fun r : Position d → Bool => + w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y)) := by + obtain ⟨⟨b, x⟩, rfl⟩ := (scatterPosition d).surjective y + have hs : mean (fun r : Position d → Bool => + w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm + (scatterPosition d (b, x)))) = + mean (fun r : Position d → Bool => + w (Fin.cons (b ^^ maskedCoin (freePairMask d B) c r x) x)) := by + apply mean_congr + intro r + exact congrArg w (step_symm_scatter d (maskedCoin (freePairMask d B) c r) (b, x)) + rw [hs] + erw [physicalFlow_scatter] + change (if b then (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2 + else (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1) = + mean (fun r : Position d → Bool => + w (Fin.cons (b ^^ (if freePairMask d B x then r x else c x)) x)) + rw [mean_coin_eval x (fun z => w (Fin.cons (b ^^ (if freePairMask d B x then z else c x)) x))] + cases h0 : B (Fin.cons false x) <;> cases h1 : B (Fin.cons true x) <;> + cases b <;> cases c x <;> + simp [pairUpdate, freePairMask, h0, h1, mean_bool] <;> ring + +theorem masked_step_exposed {ι : Type uι} (d : ℕ) (B : Position (d + 1) → Bool) + (e : ι → Position (d + 1)) (he : ∀ i, B (e i) = false) (c r : Position d → Bool) : + (step (d + 1) (maskedCoin (freePairMask d B) c r)) ∘ e = (step (d + 1) c) ∘ e := by + funext i + exact masked_step_occupied d B c r (e i) (he i) + +theorem physicalFlow_joint {ι : Type uι} (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (e : ι → Position (d + 1)) + (he : ∀ i, B (e i) = false) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) : + mean (fun c : Position d → Bool => ∑ y, physicalFlow d B w c y * f ((step (d + 1) c) ∘ e) y) = + mean (fun c : Position d → Bool => ∑ x, w x * f ((step (d + 1) c) ∘ e) (step (d + 1) c x)) := by + calc + _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => + ∑ y, w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y) * + f ((step (d + 1) c) ∘ e) y)) := by + apply mean_congr + intro c + rw [mean_sum] + apply Finset.sum_congr rfl + intro y _ + rw [mean_mul_const, physicalFlow_resampling] + _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => + ∑ x, w x * f ((step (d + 1) c) ∘ e) + (step (d + 1) (maskedCoin (freePairMask d B) c r) x))) := by + apply mean_congr + intro c + apply mean_congr + intro r + simpa only [Equiv.symm_apply_apply] using + (Equiv.sum_comp (step (d + 1) (maskedCoin (freePairMask d B) c r)) + (fun y => w ((step (d + 1) (maskedCoin (freePairMask d B) c r)).symm y) * + f ((step (d + 1) c) ∘ e) y)).symm + _ = mean (fun c : Position d → Bool => mean (fun r : Position d → Bool => + ∑ x, w x * f ((step (d + 1) (maskedCoin (freePairMask d B) c r)) ∘ e) + (step (d + 1) (maskedCoin (freePairMask d B) c r) x))) := by + apply mean_congr + intro c + apply mean_congr + intro r + rw [masked_step_exposed d B e he c r] + _ = _ := by + exact mean_maskedCoin (freePairMask d B) (fun c => ∑ x, w x * + f ((step (d + 1) c) ∘ e) (step (d + 1) c x)) + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/MixingBounds.lean b/lean/OAI/Probability/ThorpShuffle/MixingBounds.lean index 21bd6fb71f9384e1631c2e971b02143b81d4f7df..cdd34f24afa6d0e61f2b10412ec7ebd7a468769e 100644 --- a/lean/OAI/Probability/ThorpShuffle/MixingBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/MixingBounds.lean @@ -1,155 +1,155 @@ -import OAI.Probability.ThorpShuffle.FiniteLaw - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -theorem exists_mixing_time_succ (d : ℕ) : ∃ t : ℕ, distance (d + 1) t ≤ 1 / 4 := by - classical - obtain ⟨T, hT⟩ := Reachability.exists_surjective_run d - let c : ℝ := 1 / Fintype.card (History (d + 1) T) - let r : ℝ := 1 - (Fintype.card (State (d + 1)) : ℝ) * c - have hcpos : 0 < c := by dsimp [c]; positivity - have hminor (g : State (d + 1)) : c ≤ law (d + 1) T g := - FiniteLaw.fairMass_lower_of_surjective _ hT g - have hr : 0 ≤ r := by - have hh := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hminor g) - simp only [law, fairMass_sum] at hh - simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] using sub_nonneg.mpr hh - have hrlt : r < 1 := by - dsimp [r] - have hn : (0 : ℝ) < Fintype.card (State (d + 1)) := by positivity - nlinarith - have hcontract (s : ℕ) : distance (d + 1) (s + T) ≤ r * distance (d + 1) s := by - unfold distance uniform - rw [law_add] - exact FiniteLaw.tv_conv_contract _ _ (fairMass_sum _) (fairMass_sum _) c hminor - have hgeom (n : ℕ) : distance (d + 1) (n * T) ≤ r ^ n * distance (d + 1) 0 := by - induction n with - | zero => simp - | succ n ih => - rw [Nat.succ_mul] - calc - _ ≤ r * distance (d + 1) (n * T) := hcontract _ - _ ≤ r * (r ^ n * distance (d + 1) 0) := mul_le_mul_of_nonneg_left ih hr - _ = _ := by rw [pow_succ']; ring - have hlim : Tendsto (fun n : ℕ => r ^ n * distance (d + 1) 0) atTop (nhds 0) := by - simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hr hrlt).mul_const (distance (d + 1) 0) - have hev : ∀ᶠ n : ℕ in atTop, r ^ n * distance (d + 1) 0 < 1 / 4 := - hlim.eventually (eventually_lt_nhds (by norm_num : (0 : ℝ) < 1 / 4)) - obtain ⟨n, hn⟩ := hev.exists - exact ⟨n * T, (hgeom n).trans hn.le⟩ - -theorem exists_mixing_time {d : ℕ} (hd : 1 ≤ d) : ∃ t : ℕ, distance d t ≤ 1 / 4 := by - obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) - exact exists_mixing_time_succ k - -theorem exact_support_lower {d : ℕ} (hd : 1 ≤ d) : - supportThreshold d ≤ (mixingTime d : ℤ) := - supportThreshold_le_mixingTime hd (exists_mixing_time hd) - -theorem log_factorial_lower (n : ℕ) (hn : 0 < n) : - (n : ℝ) * Real.log n - n ≤ Real.log (n.factorial : ℝ) := by - have hpos : (0 : ℝ) < n := by exact_mod_cast hn - have hf : (0 : ℝ) < n.factorial := by exact_mod_cast Nat.factorial_pos n - have hh := Real.pow_div_factorial_le_exp (n : ℝ) hpos.le n - have hlog := Real.log_le_log (by positivity : (0 : ℝ) < (n : ℝ) ^ n / (n.factorial : ℝ)) hh - rw [Real.log_exp, Real.log_div (by positivity) hf.ne', Real.log_pow] at hlog - linarith - -theorem supportThreshold_bounds (d : ℕ) : - 2 * (d : ℝ) - 6 ≤ (supportThreshold d : ℝ) ∧ - (supportThreshold d : ℝ) ≤ 2 * (d : ℝ) := by - let n : ℕ := 2 ^ d - have hn : 0 < n := by dsimp [n]; positivity - have hnR : (0 : ℝ) < n := by exact_mod_cast hn - have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn - have hfact : (0 : ℝ) < n.factorial := by exact_mod_cast Nat.factorial_pos n - have hl2 : (1 / 2 : ℝ) ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2) - norm_num at hh ⊢ - exact hh - have hl2pos : 0 < Real.log 2 := by linarith - have hlfrac : -(1 / 3 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by - have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 3 / 4) - norm_num at hh ⊢ - exact hh - have hlogn : Real.log (n : ℝ) = (d : ℝ) * Real.log 2 := by - simp only [n, Nat.cast_pow, Nat.cast_ofNat, Real.log_pow] - have hlow := log_factorial_lower n hn - have hupp : Real.log (n.factorial : ℝ) ≤ (n : ℝ) * Real.log n := by - have hh : (n.factorial : ℝ) ≤ (n : ℝ) ^ n := by exact_mod_cast Nat.factorial_le_pow n - simpa only [Real.log_pow] using Real.log_le_log hfact hh - have hprod : Real.log (3 * (n.factorial : ℝ) / 4) = - Real.log (3 / 4 : ℝ) + Real.log (n.factorial : ℝ) := by - rw [show 3 * (n.factorial : ℝ) / 4 = (3 / 4) * n.factorial by ring] - exact Real.log_mul (by norm_num) hfact.ne' - have hlowlog : (n : ℝ) * ((d : ℝ) * Real.log 2) - n - 1 / 3 ≤ - Real.log (3 * (n.factorial : ℝ) / 4) := by - rw [hprod, ← hlogn] - linarith - have hupplog : Real.log (3 * (n.factorial : ℝ) / 4) ≤ - (n : ℝ) * ((d : ℝ) * Real.log 2) := by - rw [hprod, ← hlogn] - have hh : Real.log (3 / 4 : ℝ) ≤ 0 := Real.log_nonpos (by norm_num) (by norm_num) - linarith - let a : ℝ := (2 / (n : ℝ)) * Real.logb 2 (3 * (n.factorial : ℝ) / 4) - have ha_low : 2 * (d : ℝ) - 6 ≤ a := by - dsimp [a] - rw [Real.logb] - have he : (2 / (n : ℝ)) * - (Real.log (3 * (n.factorial : ℝ) / 4) / Real.log 2) = - (2 * Real.log (3 * (n.factorial : ℝ) / 4)) / ((n : ℝ) * Real.log 2) := by ring - rw [he] - apply (le_div_iff₀ (mul_pos hnR hl2pos)).mpr - nlinarith [mul_le_mul_of_nonneg_left hl2 (by positivity : (0 : ℝ) ≤ n)] - have ha_upp : a ≤ 2 * (d : ℝ) := by - dsimp [a] - rw [Real.logb] - have hscale := mul_le_mul_of_nonneg_left hupplog (by positivity : (0 : ℝ) ≤ 2 / n / Real.log 2) - have hid : (2 / (n : ℝ) / Real.log 2) * ((n : ℝ) * ((d : ℝ) * Real.log 2)) = 2 * d := by - field_simp - rw [hid] at hscale - calc - _ = (2 / (n : ℝ) / Real.log 2) * Real.log (3 * (n.factorial : ℝ) / 4) := by ring - _ ≤ 2 * (d : ℝ) := hscale - have hceil : supportThreshold d = ⌈a⌉ := by - simp only [supportThreshold, a, n, Nat.cast_pow, Nat.cast_ofNat] - rw [hceil] - constructor - · exact ha_low.trans (Int.le_ceil a) - · have hh : ⌈a⌉ ≤ (2 * d : ℤ) := Int.ceil_le.mpr (by exact_mod_cast ha_upp) - exact_mod_cast hh - -theorem supportThreshold_isBigO : - Asymptotics.IsBigO atTop - (fun d : ℕ => (supportThreshold d : ℝ) - 2 * (d : ℝ)) (fun _ => (1 : ℝ)) := by - rw [Asymptotics.isBigO_iff] - refine ⟨6, Filter.Eventually.of_forall (fun d => ?_)⟩ - have h := supportThreshold_bounds d - simp only [Real.norm_eq_abs, norm_one, mul_one] - apply abs_le.mpr - constructor <;> linarith - -theorem orderFunction_isBigO_mixingTime : - Asymptotics.IsBigO atTop orderFunction (fun d : ℕ => (mixingTime d : ℝ)) := by - rw [Asymptotics.isBigO_iff] - refine ⟨1, Filter.eventually_atTop.2 ⟨6, fun d hd => ?_⟩⟩ - have hs := (supportThreshold_bounds d).1 - have hl : (supportThreshold d : ℝ) ≤ mixingTime d := by - exact_mod_cast exact_support_lower (by omega : 1 ≤ d) - have hdR : (6 : ℝ) ≤ d := by exact_mod_cast hd - simp only [orderFunction, Real.norm_eq_abs, one_mul] - rw [abs_of_nonneg (Nat.cast_nonneg d), abs_of_nonneg (Nat.cast_nonneg (mixingTime d))] - linarith - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.FiniteLaw + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +theorem exists_mixing_time_succ (d : ℕ) : ∃ t : ℕ, distance (d + 1) t ≤ 1 / 4 := by + classical + obtain ⟨T, hT⟩ := Reachability.exists_surjective_run d + let c : ℝ := 1 / Fintype.card (History (d + 1) T) + let r : ℝ := 1 - (Fintype.card (State (d + 1)) : ℝ) * c + have hcpos : 0 < c := by dsimp [c]; positivity + have hminor (g : State (d + 1)) : c ≤ law (d + 1) T g := + FiniteLaw.fairMass_lower_of_surjective _ hT g + have hr : 0 ≤ r := by + have hh := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hminor g) + simp only [law, fairMass_sum] at hh + simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] using sub_nonneg.mpr hh + have hrlt : r < 1 := by + dsimp [r] + have hn : (0 : ℝ) < Fintype.card (State (d + 1)) := by positivity + nlinarith + have hcontract (s : ℕ) : distance (d + 1) (s + T) ≤ r * distance (d + 1) s := by + unfold distance uniform + rw [law_add] + exact FiniteLaw.tv_conv_contract _ _ (fairMass_sum _) (fairMass_sum _) c hminor + have hgeom (n : ℕ) : distance (d + 1) (n * T) ≤ r ^ n * distance (d + 1) 0 := by + induction n with + | zero => simp + | succ n ih => + rw [Nat.succ_mul] + calc + _ ≤ r * distance (d + 1) (n * T) := hcontract _ + _ ≤ r * (r ^ n * distance (d + 1) 0) := mul_le_mul_of_nonneg_left ih hr + _ = _ := by rw [pow_succ']; ring + have hlim : Tendsto (fun n : ℕ => r ^ n * distance (d + 1) 0) atTop (nhds 0) := by + simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hr hrlt).mul_const (distance (d + 1) 0) + have hev : ∀ᶠ n : ℕ in atTop, r ^ n * distance (d + 1) 0 < 1 / 4 := + hlim.eventually (eventually_lt_nhds (by norm_num : (0 : ℝ) < 1 / 4)) + obtain ⟨n, hn⟩ := hev.exists + exact ⟨n * T, (hgeom n).trans hn.le⟩ + +theorem exists_mixing_time {d : ℕ} (hd : 1 ≤ d) : ∃ t : ℕ, distance d t ≤ 1 / 4 := by + obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) + exact exists_mixing_time_succ k + +theorem exact_support_lower {d : ℕ} (hd : 1 ≤ d) : + supportThreshold d ≤ (mixingTime d : ℤ) := + supportThreshold_le_mixingTime hd (exists_mixing_time hd) + +theorem log_factorial_lower (n : ℕ) (hn : 0 < n) : + (n : ℝ) * Real.log n - n ≤ Real.log (n.factorial : ℝ) := by + have hpos : (0 : ℝ) < n := by exact_mod_cast hn + have hf : (0 : ℝ) < n.factorial := by exact_mod_cast Nat.factorial_pos n + have hh := Real.pow_div_factorial_le_exp (n : ℝ) hpos.le n + have hlog := Real.log_le_log (by positivity : (0 : ℝ) < (n : ℝ) ^ n / (n.factorial : ℝ)) hh + rw [Real.log_exp, Real.log_div (by positivity) hf.ne', Real.log_pow] at hlog + linarith + +theorem supportThreshold_bounds (d : ℕ) : + 2 * (d : ℝ) - 6 ≤ (supportThreshold d : ℝ) ∧ + (supportThreshold d : ℝ) ≤ 2 * (d : ℝ) := by + let n : ℕ := 2 ^ d + have hn : 0 < n := by dsimp [n]; positivity + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hfact : (0 : ℝ) < n.factorial := by exact_mod_cast Nat.factorial_pos n + have hl2 : (1 / 2 : ℝ) ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at hh ⊢ + exact hh + have hl2pos : 0 < Real.log 2 := by linarith + have hlfrac : -(1 / 3 : ℝ) ≤ Real.log (3 / 4 : ℝ) := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 3 / 4) + norm_num at hh ⊢ + exact hh + have hlogn : Real.log (n : ℝ) = (d : ℝ) * Real.log 2 := by + simp only [n, Nat.cast_pow, Nat.cast_ofNat, Real.log_pow] + have hlow := log_factorial_lower n hn + have hupp : Real.log (n.factorial : ℝ) ≤ (n : ℝ) * Real.log n := by + have hh : (n.factorial : ℝ) ≤ (n : ℝ) ^ n := by exact_mod_cast Nat.factorial_le_pow n + simpa only [Real.log_pow] using Real.log_le_log hfact hh + have hprod : Real.log (3 * (n.factorial : ℝ) / 4) = + Real.log (3 / 4 : ℝ) + Real.log (n.factorial : ℝ) := by + rw [show 3 * (n.factorial : ℝ) / 4 = (3 / 4) * n.factorial by ring] + exact Real.log_mul (by norm_num) hfact.ne' + have hlowlog : (n : ℝ) * ((d : ℝ) * Real.log 2) - n - 1 / 3 ≤ + Real.log (3 * (n.factorial : ℝ) / 4) := by + rw [hprod, ← hlogn] + linarith + have hupplog : Real.log (3 * (n.factorial : ℝ) / 4) ≤ + (n : ℝ) * ((d : ℝ) * Real.log 2) := by + rw [hprod, ← hlogn] + have hh : Real.log (3 / 4 : ℝ) ≤ 0 := Real.log_nonpos (by norm_num) (by norm_num) + linarith + let a : ℝ := (2 / (n : ℝ)) * Real.logb 2 (3 * (n.factorial : ℝ) / 4) + have ha_low : 2 * (d : ℝ) - 6 ≤ a := by + dsimp [a] + rw [Real.logb] + have he : (2 / (n : ℝ)) * + (Real.log (3 * (n.factorial : ℝ) / 4) / Real.log 2) = + (2 * Real.log (3 * (n.factorial : ℝ) / 4)) / ((n : ℝ) * Real.log 2) := by ring + rw [he] + apply (le_div_iff₀ (mul_pos hnR hl2pos)).mpr + nlinarith [mul_le_mul_of_nonneg_left hl2 (by positivity : (0 : ℝ) ≤ n)] + have ha_upp : a ≤ 2 * (d : ℝ) := by + dsimp [a] + rw [Real.logb] + have hscale := mul_le_mul_of_nonneg_left hupplog (by positivity : (0 : ℝ) ≤ 2 / n / Real.log 2) + have hid : (2 / (n : ℝ) / Real.log 2) * ((n : ℝ) * ((d : ℝ) * Real.log 2)) = 2 * d := by + field_simp + rw [hid] at hscale + calc + _ = (2 / (n : ℝ) / Real.log 2) * Real.log (3 * (n.factorial : ℝ) / 4) := by ring + _ ≤ 2 * (d : ℝ) := hscale + have hceil : supportThreshold d = ⌈a⌉ := by + simp only [supportThreshold, a, n, Nat.cast_pow, Nat.cast_ofNat] + rw [hceil] + constructor + · exact ha_low.trans (Int.le_ceil a) + · have hh : ⌈a⌉ ≤ (2 * d : ℤ) := Int.ceil_le.mpr (by exact_mod_cast ha_upp) + exact_mod_cast hh + +theorem supportThreshold_isBigO : + Asymptotics.IsBigO atTop + (fun d : ℕ => (supportThreshold d : ℝ) - 2 * (d : ℝ)) (fun _ => (1 : ℝ)) := by + rw [Asymptotics.isBigO_iff] + refine ⟨6, Filter.Eventually.of_forall (fun d => ?_)⟩ + have h := supportThreshold_bounds d + simp only [Real.norm_eq_abs, norm_one, mul_one] + apply abs_le.mpr + constructor <;> linarith + +theorem orderFunction_isBigO_mixingTime : + Asymptotics.IsBigO atTop orderFunction (fun d : ℕ => (mixingTime d : ℝ)) := by + rw [Asymptotics.isBigO_iff] + refine ⟨1, Filter.eventually_atTop.2 ⟨6, fun d hd => ?_⟩⟩ + have hs := (supportThreshold_bounds d).1 + have hl : (supportThreshold d : ℝ) ≤ mixingTime d := by + exact_mod_cast exact_support_lower (by omega : 1 ≤ d) + have hdR : (6 : ℝ) ≤ d := by exact_mod_cast hd + simp only [orderFunction, Real.norm_eq_abs, one_mul] + rw [abs_of_nonneg (Nat.cast_nonneg d), abs_of_nonneg (Nat.cast_nonneg (mixingTime d))] + linarith + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Model.lean b/lean/OAI/Probability/ThorpShuffle/Model.lean index ffb3d0030db96ad9164777198407176cb34964e3..b1d74acafdaaa5fdda4bdf49c67f3e22ab88dffb 100644 --- a/lean/OAI/Probability/ThorpShuffle/Model.lean +++ b/lean/OAI/Probability/ThorpShuffle/Model.lean @@ -1,78 +1,78 @@ -import Mathlib - -namespace OAI - -universe u v - -noncomputable section -open scoped BigOperators -open Filter - -namespace Thorp - -abbrev Position (d : ℕ) := Fin d → Bool -abbrev State (d : ℕ) := Equiv.Perm (Position d) - -def Coins : ℕ → Type - | 0 => Unit - | d + 1 => Position d → Bool - -instance coinsFintype (d : ℕ) : Fintype (Coins d) := by - cases d <;> simp only [Coins] <;> infer_instance - -instance coinsInhabited (d : ℕ) : Inhabited (Coins d) := by - cases d <;> simp only [Coins] <;> infer_instance - -def pairSwitch (d : ℕ) (c : Position d → Bool) : Equiv.Perm (Bool × Position d) where - toFun p := (p.1 ^^ c p.2, p.2) - invFun p := (p.1 ^^ c p.2, p.2) - left_inv p := by - rcases p with ⟨b, s⟩ - cases b <;> cases h : c s <;> simp [h] - right_inv p := by - rcases p with ⟨b, s⟩ - cases b <;> cases h : c s <;> simp [h] - -def rotate (d : ℕ) : State d := - Equiv.piCongrLeft (fun _ : Fin d => Bool) (finRotate d).symm - -def step : (d : ℕ) → Coins d → State d - | 0, _ => Equiv.refl _ - | d + 1, c => - (((Fin.consEquiv (fun _ : Fin (d + 1) => Bool)).symm.trans - (pairSwitch d c)).trans - (Fin.consEquiv (fun _ : Fin (d + 1) => Bool))).trans (rotate (d + 1)) - -abbrev History (d t : ℕ) := Fin t → Coins d - -def run (d t : ℕ) (ω : History d t) : State d := - ((List.ofFn fun i : Fin t => step d (ω i)).reverse).prod - -def fairMass {Ω : Type u} {α : Type v} [Fintype Ω] (f : Ω → α) (a : α) : ℝ := by - classical - exact (∑ ω : Ω, if f ω = a then (1 : ℝ) else 0) / Fintype.card Ω - -def law (d t : ℕ) : State d → ℝ := fairMass (run d t) - -def uniform (d : ℕ) (_ : State d) : ℝ := 1 / Fintype.card (State d) - -def tv {α : Type u} [Fintype α] (μ ν : α → ℝ) : ℝ := - (1 / 2 : ℝ) * ∑ a : α, |μ a - ν a| - -def distance (d t : ℕ) : ℝ := tv (law d t) (uniform d) - -def lawFrom (d t : ℕ) (g₀ : State d) : State d → ℝ := - fairMass (fun ω : History d t => run d t ω * g₀) - -def mixingTime (d : ℕ) : ℕ := sInf {t : ℕ | distance d t ≤ 1 / 4} - -def supportThreshold (d : ℕ) : ℤ := - ⌈(2 / (2 ^ d : ℝ)) * Real.logb 2 (3 * ((2 ^ d).factorial : ℝ) / 4)⌉ - -def orderFunction (d : ℕ) : ℝ := d - -end Thorp - -end - -end OAI +import Mathlib + +namespace OAI + +universe u v + +noncomputable section +open scoped BigOperators +open Filter + +namespace Thorp + +abbrev Position (d : ℕ) := Fin d → Bool +abbrev State (d : ℕ) := Equiv.Perm (Position d) + +def Coins : ℕ → Type + | 0 => Unit + | d + 1 => Position d → Bool + +instance coinsFintype (d : ℕ) : Fintype (Coins d) := by + cases d <;> simp only [Coins] <;> infer_instance + +instance coinsInhabited (d : ℕ) : Inhabited (Coins d) := by + cases d <;> simp only [Coins] <;> infer_instance + +def pairSwitch (d : ℕ) (c : Position d → Bool) : Equiv.Perm (Bool × Position d) where + toFun p := (p.1 ^^ c p.2, p.2) + invFun p := (p.1 ^^ c p.2, p.2) + left_inv p := by + rcases p with ⟨b, s⟩ + cases b <;> cases h : c s <;> simp [h] + right_inv p := by + rcases p with ⟨b, s⟩ + cases b <;> cases h : c s <;> simp [h] + +def rotate (d : ℕ) : State d := + Equiv.piCongrLeft (fun _ : Fin d => Bool) (finRotate d).symm + +def step : (d : ℕ) → Coins d → State d + | 0, _ => Equiv.refl _ + | d + 1, c => + (((Fin.consEquiv (fun _ : Fin (d + 1) => Bool)).symm.trans + (pairSwitch d c)).trans + (Fin.consEquiv (fun _ : Fin (d + 1) => Bool))).trans (rotate (d + 1)) + +abbrev History (d t : ℕ) := Fin t → Coins d + +def run (d t : ℕ) (ω : History d t) : State d := + ((List.ofFn fun i : Fin t => step d (ω i)).reverse).prod + +def fairMass {Ω : Type u} {α : Type v} [Fintype Ω] (f : Ω → α) (a : α) : ℝ := by + classical + exact (∑ ω : Ω, if f ω = a then (1 : ℝ) else 0) / Fintype.card Ω + +def law (d t : ℕ) : State d → ℝ := fairMass (run d t) + +def uniform (d : ℕ) (_ : State d) : ℝ := 1 / Fintype.card (State d) + +def tv {α : Type u} [Fintype α] (μ ν : α → ℝ) : ℝ := + (1 / 2 : ℝ) * ∑ a : α, |μ a - ν a| + +def distance (d t : ℕ) : ℝ := tv (law d t) (uniform d) + +def lawFrom (d t : ℕ) (g₀ : State d) : State d → ℝ := + fairMass (fun ω : History d t => run d t ω * g₀) + +def mixingTime (d : ℕ) : ℕ := sInf {t : ℕ | distance d t ≤ 1 / 4} + +def supportThreshold (d : ℕ) : ℤ := + ⌈(2 / (2 ^ d : ℝ)) * Real.logb 2 (3 * ((2 ^ d).factorial : ℝ) / 4)⌉ + +def orderFunction (d : ℕ) : ℝ := d + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/NoiseEnergy.lean b/lean/OAI/Probability/ThorpShuffle/NoiseEnergy.lean index 1cae4d611c1311e2c97b5d2849ca9f92705b9c67..10e479bcb229dd7188ec4bc215022f7d9ed7b068 100644 --- a/lean/OAI/Probability/ThorpShuffle/NoiseEnergy.lean +++ b/lean/OAI/Probability/ThorpShuffle/NoiseEnergy.lean @@ -1,188 +1,188 @@ -import OAI.Probability.ThorpShuffle.HalfHistories - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def insertBit (d : ℕ) (i : Fin (d + 1)) (b : Bool) (x : Position d) : Position (d + 1) := - Fin.insertNth i b x - -def halfPositionEquiv (d : ℕ) (i : Fin (d + 1)) : Bool × Position d ≃ Position (d + 1) := - Fin.insertNthEquiv (fun _ => Bool) i - -@[simp] theorem halfPositionEquiv_apply (d : ℕ) (i : Fin (d + 1)) (p : Bool × Position d) : - halfPositionEquiv d i p = insertBit d i p.1 p.2 := rfl - -@[simp] theorem insertBit_zero (d : ℕ) (b : Bool) (x : Position d) : - insertBit d 0 b x = Fin.cons b x := Fin.insertNth_zero' _ _ - -@[simp] theorem insertBit_last (d : ℕ) (b : Bool) (x : Position d) : - insertBit d (Fin.last d) b x = Fin.snoc x b := Fin.insertNth_last' _ _ - - theorem insertBit_cons (d : ℕ) (k : Fin (d + 1)) (h b : Bool) (x : Position d) : - insertBit (d + 1) k.succ h (Fin.cons b x) = Fin.cons b (insertBit d k h x) := by - change Fin.insertNth (α := fun _ => Bool) k.succ h (Fin.cons b x) = _ - apply Fin.insertNth_eq_iff.mpr - constructor - · simp [insertBit] - · change Fin.cons b x = Fin.cons b (insertBit d k h x) ∘ k.succ.succAbove - erw [Fin.cons_comp_succ_succAbove] - simp [insertBit] - - theorem insertBit_snoc (d : ℕ) (k : Fin (d + 1)) (h b : Bool) (x : Position d) : - insertBit (d + 1) k.castSucc h (Fin.snoc x b) = Fin.snoc (insertBit d k h x) b := by - change Fin.insertNth (α := fun _ => Bool) k.castSucc h (Fin.snoc x b) = _ - apply Fin.insertNth_eq_iff.mpr - constructor - · simp [insertBit] - · funext j - refine Fin.lastCases ?_ (fun i => ?_) j - · simp [Fin.removeNth, Fin.succAbove_ne_last_last, insertBit] - · simp [Fin.removeNth, Fin.castSucc_succAbove_castSucc, insertBit] - - theorem physicalFree_snoc (d : ℕ) (B : Position (d + 1) → Bool) - (c : Position d → Bool) (x : Position d) (b : Bool) : - physicalFree d B c (Fin.snoc x b) = B (Fin.cons (b ^^ c x) x) := by - erw [← scatterPosition_eq_snoc, physicalFree_scatter] - rfl - - theorem physicalFlow_snoc (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Position d → Bool) (x : Position d) (b : Bool) : - physicalFlow d B w c (Fin.snoc x b) = - if b then (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2 - else (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1 := by - erw [← scatterPosition_eq_snoc, physicalFlow_scatter] - rfl - -@[ext] theorem RawState.ext {d : ℕ} {v u : RawState d} - (hf : v.free = u.free) (hw : v.weight = u.weight) : v = u := by - cases v; cases u; simp_all - -def halfRaw (d : ℕ) (i : Fin (d + 1)) (h : Bool) (v : RawState (d + 1)) : RawState d where - free x := v.free (insertBit d i h x) - weight x := v.weight (insertBit d i h x) - -theorem rawNext_half (d : ℕ) (k : Fin (d + 1)) (h : Bool) - (v : RawState (d + 2)) (c : Position (d + 1) → Bool) : - halfRaw (d + 1) k.castSucc h (rawNext (d + 1) v c) = - rawNext d (halfRaw (d + 1) k.succ h v) (fun x => c (insertBit d k h x)) := by - apply RawState.ext - · funext x - obtain ⟨⟨b, y⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)).surjective x - change physicalFree (d + 1) v.free c (insertBit (d + 1) k.castSucc h (Fin.snoc y b)) = - physicalFree d (fun z => v.free (insertBit (d + 1) k.succ h z)) - (fun z => c (insertBit d k h z)) (Fin.snoc y b) - erw [insertBit_snoc, physicalFree_snoc, physicalFree_snoc, insertBit_cons] - · funext x - obtain ⟨⟨b, y⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)).surjective x - change physicalFlow (d + 1) v.free v.weight c - (insertBit (d + 1) k.castSucc h (Fin.snoc y b)) = - physicalFlow d (fun z => v.free (insertBit (d + 1) k.succ h z)) - (fun z => v.weight (insertBit (d + 1) k.succ h z)) - (fun z => c (insertBit d k h z)) (Fin.snoc y b) - erw [insertBit_snoc, physicalFlow_snoc, physicalFlow_snoc] - simp only [insertBit_cons] - -end Conditional - -namespace Conditional - -def halfMarker (d t : ℕ) : Fin (d + 2) := ⟨d + 1 - t, by omega⟩ -def coinHalfMarker (d t : ℕ) : Fin (d + 1) := ⟨d - t, by omega⟩ - -@[simp] theorem halfMarker_zero (d : ℕ) : halfMarker d 0 = Fin.last (d + 1) := rfl -@[simp] theorem halfMarker_end (d : ℕ) : halfMarker d (d + 1) = 0 := by - apply Fin.ext; simp [halfMarker] - -theorem halfMarker_next (d t : ℕ) (ht : t ≤ d) : - halfMarker d (t + 1) = (coinHalfMarker d t).castSucc := by - apply Fin.ext; simp only [halfMarker, coinHalfMarker, Fin.val_castSucc]; omega - -theorem halfMarker_previous (d t : ℕ) (ht : t ≤ d) : - halfMarker d t = (coinHalfMarker d t).succ := by - apply Fin.ext; simp only [halfMarker, coinHalfMarker, Fin.val_succ]; omega - -def halfHistory (d t : ℕ) (h : Bool) (ω : History (d + 2) t) : History (d + 1) t := - fun i x => ω i (insertBit d (coinHalfMarker d i.val) h x) - -@[simp] theorem halfHistory_snoc (d t : ℕ) (h : Bool) - (ω : History (d + 2) t) (c : Coins (d + 2)) : - halfHistory d (t + 1) h (Fin.snoc ω c) = - Fin.snoc (halfHistory d t h ω) (fun x => c (insertBit d (coinHalfMarker d t) h x)) := by - funext i x - refine Fin.lastCases ?_ (fun j => ?_) i - · change (Fin.snoc (α := fun _ => Coins (d + 2)) ω c (Fin.last t)) (insertBit d (coinHalfMarker d t) h x) = - (Fin.snoc (α := fun _ => Coins (d + 1)) (halfHistory d t h ω) - (fun z => c (insertBit d (coinHalfMarker d t) h z)) (Fin.last t)) x - erw [Fin.snoc_last, Fin.snoc_last] - · change (Fin.snoc (α := fun _ => Coins (d + 2)) ω c j.castSucc) (insertBit d (coinHalfMarker d j.val) h x) = - (Fin.snoc (α := fun _ => Coins (d + 1)) (halfHistory d t h ω) - (fun z => c (insertBit d (coinHalfMarker d t) h z)) j.castSucc) x - erw [Fin.snoc_castSucc, Fin.snoc_castSucc] - rfl - -theorem rawIterate_half (d t : ℕ) (ht : t ≤ d + 1) (h : Bool) - (v : RawState (d + 2)) (ω : History (d + 2) t) : - halfRaw (d + 1) (halfMarker d t) h (rawIterate (d + 1) v t ω) = - rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) t (halfHistory d t h ω) := by - induction t with - | zero => rfl - | succ t ih => - change halfRaw (d + 1) (halfMarker d (t + 1)) h - (rawNext (d + 1) (rawIterate (d + 1) v t (fun i => ω i.castSucc)) (ω (Fin.last t))) = _ - erw [halfMarker_next d t (by omega), rawNext_half, - ← halfMarker_previous d t (by omega), ih (by omega)] - rfl - -def splitHalfHistory (d t : ℕ) : - History (d + 2) t ≃ History (d + 1) t × History (d + 1) t where - toFun ω := (halfHistory d t false ω, halfHistory d t true ω) - invFun p := fun i y => - if y (coinHalfMarker d i.val) then - p.2 i (Fin.removeNth (coinHalfMarker d i.val) y) - else p.1 i (Fin.removeNth (coinHalfMarker d i.val) y) - left_inv ω := by - funext i y - obtain ⟨⟨h, x⟩, rfl⟩ := (halfPositionEquiv d (coinHalfMarker d i.val)).surjective y - simp only [halfPositionEquiv_apply, insertBit, Fin.insertNth_apply_same, - halfHistory, Fin.removeNth_insertNth] - cases h <;> rfl - right_inv p := by - apply Prod.ext <;> funext i x <;> - simp [halfHistory, insertBit, Fin.insertNth_apply_same, Fin.removeNth_insertNth] - -theorem mean_half_product (d t : ℕ) (f g : History (d + 1) t → ℝ) : - mean (fun ω : History (d + 2) t => f (halfHistory d t false ω) * - g (halfHistory d t true ω)) = mean f * mean g := by - have he := mean_equiv (splitHalfHistory d t) (fun p => f p.1 * g p.2) - change mean (fun ω : History (d + 2) t => f (halfHistory d t false ω) * - g (halfHistory d t true ω)) = _ at he - erw [he, mean_prod] - simp_rw [mean_const_mul] - exact mean_mul_const _ _ - -theorem mean_opposite_half_product (d t : ℕ) (h : Bool) - (f g : History (d + 1) t → ℝ) : - mean (fun ω : History (d + 2) t => f (halfHistory d t h ω) * - g (halfHistory d t (!h) ω)) = mean f * mean g := by - cases h - · exact mean_half_product d t f g - · simp only [Bool.not_true] - simpa only [mul_comm] using mean_half_product d t g f - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.HalfHistories + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def insertBit (d : ℕ) (i : Fin (d + 1)) (b : Bool) (x : Position d) : Position (d + 1) := + Fin.insertNth i b x + +def halfPositionEquiv (d : ℕ) (i : Fin (d + 1)) : Bool × Position d ≃ Position (d + 1) := + Fin.insertNthEquiv (fun _ => Bool) i + +@[simp] theorem halfPositionEquiv_apply (d : ℕ) (i : Fin (d + 1)) (p : Bool × Position d) : + halfPositionEquiv d i p = insertBit d i p.1 p.2 := rfl + +@[simp] theorem insertBit_zero (d : ℕ) (b : Bool) (x : Position d) : + insertBit d 0 b x = Fin.cons b x := Fin.insertNth_zero' _ _ + +@[simp] theorem insertBit_last (d : ℕ) (b : Bool) (x : Position d) : + insertBit d (Fin.last d) b x = Fin.snoc x b := Fin.insertNth_last' _ _ + + theorem insertBit_cons (d : ℕ) (k : Fin (d + 1)) (h b : Bool) (x : Position d) : + insertBit (d + 1) k.succ h (Fin.cons b x) = Fin.cons b (insertBit d k h x) := by + change Fin.insertNth (α := fun _ => Bool) k.succ h (Fin.cons b x) = _ + apply Fin.insertNth_eq_iff.mpr + constructor + · simp [insertBit] + · change Fin.cons b x = Fin.cons b (insertBit d k h x) ∘ k.succ.succAbove + erw [Fin.cons_comp_succ_succAbove] + simp [insertBit] + + theorem insertBit_snoc (d : ℕ) (k : Fin (d + 1)) (h b : Bool) (x : Position d) : + insertBit (d + 1) k.castSucc h (Fin.snoc x b) = Fin.snoc (insertBit d k h x) b := by + change Fin.insertNth (α := fun _ => Bool) k.castSucc h (Fin.snoc x b) = _ + apply Fin.insertNth_eq_iff.mpr + constructor + · simp [insertBit] + · funext j + refine Fin.lastCases ?_ (fun i => ?_) j + · simp [Fin.removeNth, Fin.succAbove_ne_last_last, insertBit] + · simp [Fin.removeNth, Fin.castSucc_succAbove_castSucc, insertBit] + + theorem physicalFree_snoc (d : ℕ) (B : Position (d + 1) → Bool) + (c : Position d → Bool) (x : Position d) (b : Bool) : + physicalFree d B c (Fin.snoc x b) = B (Fin.cons (b ^^ c x) x) := by + erw [← scatterPosition_eq_snoc, physicalFree_scatter] + rfl + + theorem physicalFlow_snoc (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Position d → Bool) (x : Position d) (b : Bool) : + physicalFlow d B w c (Fin.snoc x b) = + if b then (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).2 + else (pairUpdate (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x)).1 := by + erw [← scatterPosition_eq_snoc, physicalFlow_scatter] + rfl + +@[ext] theorem RawState.ext {d : ℕ} {v u : RawState d} + (hf : v.free = u.free) (hw : v.weight = u.weight) : v = u := by + cases v; cases u; simp_all + +def halfRaw (d : ℕ) (i : Fin (d + 1)) (h : Bool) (v : RawState (d + 1)) : RawState d where + free x := v.free (insertBit d i h x) + weight x := v.weight (insertBit d i h x) + +theorem rawNext_half (d : ℕ) (k : Fin (d + 1)) (h : Bool) + (v : RawState (d + 2)) (c : Position (d + 1) → Bool) : + halfRaw (d + 1) k.castSucc h (rawNext (d + 1) v c) = + rawNext d (halfRaw (d + 1) k.succ h v) (fun x => c (insertBit d k h x)) := by + apply RawState.ext + · funext x + obtain ⟨⟨b, y⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)).surjective x + change physicalFree (d + 1) v.free c (insertBit (d + 1) k.castSucc h (Fin.snoc y b)) = + physicalFree d (fun z => v.free (insertBit (d + 1) k.succ h z)) + (fun z => c (insertBit d k h z)) (Fin.snoc y b) + erw [insertBit_snoc, physicalFree_snoc, physicalFree_snoc, insertBit_cons] + · funext x + obtain ⟨⟨b, y⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)).surjective x + change physicalFlow (d + 1) v.free v.weight c + (insertBit (d + 1) k.castSucc h (Fin.snoc y b)) = + physicalFlow d (fun z => v.free (insertBit (d + 1) k.succ h z)) + (fun z => v.weight (insertBit (d + 1) k.succ h z)) + (fun z => c (insertBit d k h z)) (Fin.snoc y b) + erw [insertBit_snoc, physicalFlow_snoc, physicalFlow_snoc] + simp only [insertBit_cons] + +end Conditional + +namespace Conditional + +def halfMarker (d t : ℕ) : Fin (d + 2) := ⟨d + 1 - t, by omega⟩ +def coinHalfMarker (d t : ℕ) : Fin (d + 1) := ⟨d - t, by omega⟩ + +@[simp] theorem halfMarker_zero (d : ℕ) : halfMarker d 0 = Fin.last (d + 1) := rfl +@[simp] theorem halfMarker_end (d : ℕ) : halfMarker d (d + 1) = 0 := by + apply Fin.ext; simp [halfMarker] + +theorem halfMarker_next (d t : ℕ) (ht : t ≤ d) : + halfMarker d (t + 1) = (coinHalfMarker d t).castSucc := by + apply Fin.ext; simp only [halfMarker, coinHalfMarker, Fin.val_castSucc]; omega + +theorem halfMarker_previous (d t : ℕ) (ht : t ≤ d) : + halfMarker d t = (coinHalfMarker d t).succ := by + apply Fin.ext; simp only [halfMarker, coinHalfMarker, Fin.val_succ]; omega + +def halfHistory (d t : ℕ) (h : Bool) (ω : History (d + 2) t) : History (d + 1) t := + fun i x => ω i (insertBit d (coinHalfMarker d i.val) h x) + +@[simp] theorem halfHistory_snoc (d t : ℕ) (h : Bool) + (ω : History (d + 2) t) (c : Coins (d + 2)) : + halfHistory d (t + 1) h (Fin.snoc ω c) = + Fin.snoc (halfHistory d t h ω) (fun x => c (insertBit d (coinHalfMarker d t) h x)) := by + funext i x + refine Fin.lastCases ?_ (fun j => ?_) i + · change (Fin.snoc (α := fun _ => Coins (d + 2)) ω c (Fin.last t)) (insertBit d (coinHalfMarker d t) h x) = + (Fin.snoc (α := fun _ => Coins (d + 1)) (halfHistory d t h ω) + (fun z => c (insertBit d (coinHalfMarker d t) h z)) (Fin.last t)) x + erw [Fin.snoc_last, Fin.snoc_last] + · change (Fin.snoc (α := fun _ => Coins (d + 2)) ω c j.castSucc) (insertBit d (coinHalfMarker d j.val) h x) = + (Fin.snoc (α := fun _ => Coins (d + 1)) (halfHistory d t h ω) + (fun z => c (insertBit d (coinHalfMarker d t) h z)) j.castSucc) x + erw [Fin.snoc_castSucc, Fin.snoc_castSucc] + rfl + +theorem rawIterate_half (d t : ℕ) (ht : t ≤ d + 1) (h : Bool) + (v : RawState (d + 2)) (ω : History (d + 2) t) : + halfRaw (d + 1) (halfMarker d t) h (rawIterate (d + 1) v t ω) = + rawIterate d (halfRaw (d + 1) (Fin.last (d + 1)) h v) t (halfHistory d t h ω) := by + induction t with + | zero => rfl + | succ t ih => + change halfRaw (d + 1) (halfMarker d (t + 1)) h + (rawNext (d + 1) (rawIterate (d + 1) v t (fun i => ω i.castSucc)) (ω (Fin.last t))) = _ + erw [halfMarker_next d t (by omega), rawNext_half, + ← halfMarker_previous d t (by omega), ih (by omega)] + rfl + +def splitHalfHistory (d t : ℕ) : + History (d + 2) t ≃ History (d + 1) t × History (d + 1) t where + toFun ω := (halfHistory d t false ω, halfHistory d t true ω) + invFun p := fun i y => + if y (coinHalfMarker d i.val) then + p.2 i (Fin.removeNth (coinHalfMarker d i.val) y) + else p.1 i (Fin.removeNth (coinHalfMarker d i.val) y) + left_inv ω := by + funext i y + obtain ⟨⟨h, x⟩, rfl⟩ := (halfPositionEquiv d (coinHalfMarker d i.val)).surjective y + simp only [halfPositionEquiv_apply, insertBit, Fin.insertNth_apply_same, + halfHistory, Fin.removeNth_insertNth] + cases h <;> rfl + right_inv p := by + apply Prod.ext <;> funext i x <;> + simp [halfHistory, insertBit, Fin.insertNth_apply_same, Fin.removeNth_insertNth] + +theorem mean_half_product (d t : ℕ) (f g : History (d + 1) t → ℝ) : + mean (fun ω : History (d + 2) t => f (halfHistory d t false ω) * + g (halfHistory d t true ω)) = mean f * mean g := by + have he := mean_equiv (splitHalfHistory d t) (fun p => f p.1 * g p.2) + change mean (fun ω : History (d + 2) t => f (halfHistory d t false ω) * + g (halfHistory d t true ω)) = _ at he + erw [he, mean_prod] + simp_rw [mean_const_mul] + exact mean_mul_const _ _ + +theorem mean_opposite_half_product (d t : ℕ) (h : Bool) + (f g : History (d + 1) t → ℝ) : + mean (fun ω : History (d + 2) t => f (halfHistory d t h ω) * + g (halfHistory d t (!h) ω)) = mean f * mean g := by + cases h + · exact mean_half_product d t f g + · simp only [Bool.not_true] + simpa only [mul_comm] using mean_half_product d t g f + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/PairAveraging.lean b/lean/OAI/Probability/ThorpShuffle/PairAveraging.lean index c68172483d97682b936390b0a6341225b357c4b5..de51433df0a4c8a8dd058d1629c63a181e12f9c1 100644 --- a/lean/OAI/Probability/ThorpShuffle/PairAveraging.lean +++ b/lean/OAI/Probability/ThorpShuffle/PairAveraging.lean @@ -1,232 +1,232 @@ -import OAI.Probability.ThorpShuffle.Model - -namespace OAI - -universe uΩ uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def mean {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) : ℝ := - (∑ ω, f ω) / Fintype.card Ω - -def sign (b : Bool) : ℝ := if b then -1 else 1 - -@[simp] theorem sign_not (b : Bool) : sign (!b) = -sign b := by - cases b <;> norm_num [sign] - -@[simp] theorem sign_sq (b : Bool) : sign b ^ 2 = 1 := by - cases b <;> norm_num [sign] - -@[simp] theorem sign_mul_self (b : Bool) : sign b * sign b = 1 := by - simpa only [pow_two] using sign_sq b - -def toggleCoin {α : Type uα} [DecidableEq α] (i : α) : Equiv.Perm (α → Bool) := - Function.Involutive.toPerm (fun c => Function.update c i (!(c i))) (by - intro c - funext j - by_cases h : j = i - · subst j - simp - · simp [h]) - -@[simp] theorem toggleCoin_apply {α : Type uα} [DecidableEq α] - (i : α) (c : α → Bool) (j : α) : - toggleCoin i c j = Function.update c i (!(c i)) j := rfl - -theorem sum_sign {α : Type uα} [Fintype α] [DecidableEq α] (i : α) : - ∑ c : α → Bool, sign (c i) = 0 := by - have h := Equiv.sum_comp (toggleCoin i) (fun c : α → Bool => sign (c i)) - simp only [toggleCoin_apply, Function.update_self, sign_not, Finset.sum_neg_distrib] at h - linarith - -theorem sum_sign_pair {α : Type uα} [Fintype α] [DecidableEq α] (i j : α) : - (∑ c : α → Bool, sign (c i) * sign (c j)) = - if i = j then (Fintype.card (α → Bool) : ℝ) else 0 := by - by_cases h : i = j - · subst j - simp - · have he := Equiv.sum_comp (toggleCoin i) (fun c : α → Bool => sign (c i) * sign (c j)) - simp only [toggleCoin_apply, Function.update_self, - Function.update_of_ne (Ne.symm h), sign_not, neg_mul, - Finset.sum_neg_distrib] at he - rw [ite_eq_right h] - linarith - -theorem mean_signed_sum_sq {α : Type uα} [Fintype α] [DecidableEq α] (a : α → ℝ) : - mean (fun c : α → Bool => (∑ i, sign (c i) * a i) ^ 2) = ∑ i, a i ^ 2 := by - have hs : - (∑ c : α → Bool, (∑ i, sign (c i) * a i) ^ 2) = - (Fintype.card (α → Bool) : ℝ) * ∑ i, a i ^ 2 := by - calc - _ = ∑ c : α → Bool, ∑ i, ∑ j, - (sign (c i) * sign (c j)) * (a i * a j) := by - apply Finset.sum_congr rfl - intro c _ - simp only [pow_two, Finset.sum_mul, Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - apply Finset.sum_congr rfl - intro j _ - ring - _ = ∑ i, ∑ j, (∑ c : α → Bool, sign (c i) * sign (c j)) * (a i * a j) := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_comm] - simp only [Finset.sum_mul] - _ = _ := by - simp only [sum_sign_pair, ite_mul, zero_mul] - simp [Finset.mul_sum, pow_two] - unfold mean - rw [hs] - have hcard : (Fintype.card (α → Bool) : ℝ) ≠ 0 := by - exact_mod_cast Fintype.card_ne_zero - exact mul_div_cancel_left₀ _ hcard - -def pairUpdate (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : ℝ × ℝ := - if free₀ && free₁ then ((a + b) / 2, (a + b) / 2) - else if coin then (b, a) else (a, b) - -@[simp] theorem pairUpdate_sum (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : - (pairUpdate free₀ free₁ a b coin).1 + (pairUpdate free₀ free₁ a b coin).2 = a + b := by - cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate] <;> ring - -theorem pairUpdate_difference (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : - (pairUpdate free₀ free₁ a b coin).1 - (pairUpdate free₀ free₁ a b coin).2 = - sign coin * (if free₀ && free₁ then 0 else a - b) := by - cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] - -theorem pairUpdate_mean_first (free₀ free₁ : Bool) (a b : ℝ) : - mean (fun coin : Bool => (pairUpdate free₀ free₁ a b coin).1) = (a + b) / 2 := by - cases free₀ <;> cases free₁ <;> simp [mean, pairUpdate] <;> ring - -theorem pairUpdate_difference_sq (free₀ free₁ : Bool) (a b : ℝ) - (ha : free₀ = false → a = 0) (hb : free₁ = false → b = 0) : - (if free₀ && free₁ then (0 : ℝ) else a - b) ^ 2 = - (if free₁ then 0 else a ^ 2) + (if free₀ then 0 else b ^ 2) := by - cases free₀ <;> cases free₁ <;> simp_all - -def flow {α : Type uα} (B : Bool × α → Bool) (w : Bool × α → ℝ) - (c : α → Bool) (x : Bool × α) : ℝ := - let p := pairUpdate (B (false, x.2)) (B (true, x.2)) - (w (false, x.2)) (w (true, x.2)) (c x.2) - if x.1 then p.2 else p.1 - -def oddCoefficient {α : Type uα} [Fintype α] (ε : α → ℝ) (w : Bool × α → ℝ) : ℝ := - ∑ i, ε i * (w (false, i) - w (true, i)) - -theorem mean_oddCoefficient_sq {α : Type uα} [Fintype α] [DecidableEq α] - (B : Bool × α → Bool) (w : Bool × α → ℝ) (ε : α → ℝ) - (hw : ∀ x, B x = false → w x = 0) (hε : ∀ i, ε i ^ 2 = 1) : - mean (fun c : α → Bool => oddCoefficient ε (flow B w c) ^ 2) = - ∑ i, ((if B (true, i) then 0 else w (false, i) ^ 2) + - (if B (false, i) then 0 else w (true, i) ^ 2)) := by - have he (c : α → Bool) : - oddCoefficient ε (flow B w c) = - ∑ i, sign (c i) * (ε i * - (if B (false, i) && B (true, i) then 0 else w (false, i) - w (true, i))) := by - unfold oddCoefficient - apply Finset.sum_congr rfl - intro i _ - simp only [flow, Bool.false_eq_true, ↓reduceIte] - rw [pairUpdate_difference] - ring - simp_rw [he] - rw [mean_signed_sum_sq] - apply Finset.sum_congr rfl - intro i _ - rw [mul_pow, hε, one_mul] - exact pairUpdate_difference_sq _ _ _ _ (hw _) (hw _) - -end Conditional - -namespace Conditional - -def pairMap {α : Type uα} (c : α → Bool) (x : Bool × α) : Bool × α := - (x.1 ^^ c x.2, x.2) - -theorem pairMap_involutive {α : Type uα} (c : α → Bool) : - Function.Involutive (pairMap c) := by - rintro ⟨b, i⟩ - cases b <;> cases h : c i <;> simp [pairMap, h] - -theorem flow_sub {α : Type uα} (B : Bool × α → Bool) (u v : Bool × α → ℝ) - (c : α → Bool) (x : Bool × α) : - flow B (fun y => u y - v y) c x = flow B u c x - flow B v c x := by - rcases x with ⟨b, i⟩ - cases b <;> cases h₀ : B (false, i) <;> cases h₁ : B (true, i) <;> - cases hc : c i <;> simp [flow, pairUpdate, h₀, h₁, hc] <;> ring - -theorem flow_uniform {α : Type uα} (B : Bool × α → Bool) (r : ℝ) - (c : α → Bool) (x : Bool × α) : - flow B (fun y => if B y then r else 0) c x = - if B (pairMap c x) then r else 0 := by - rcases x with ⟨b, i⟩ - cases b <;> cases h₀ : B (false, i) <;> cases h₁ : B (true, i) <;> - cases hc : c i <;> simp [flow, pairUpdate, pairMap, h₀, h₁, hc] - -theorem flow_support {α : Type uα} (B : Bool × α → Bool) (w : Bool × α → ℝ) - (hw : ∀ x, B x = false → w x = 0) (c : α → Bool) (x : Bool × α) - (hx : B (pairMap c x) = false) : flow B w c x = 0 := by - rcases x with ⟨b, i⟩ - have h₀ := hw (false, i) - have h₁ := hw (true, i) - cases b <;> cases hb₀ : B (false, i) <;> cases hb₁ : B (true, i) <;> - cases hc : c i <;> simp_all [flow, pairUpdate, pairMap] - -theorem flow_evenCoefficient {α : Type uα} [Fintype α] - (B : Bool × α → Bool) (w : Bool × α → ℝ) (ε : α → ℝ) (c : α → Bool) : - (∑ i, ε i * (flow B w c (false, i) + flow B w c (true, i))) = - ∑ i, ε i * (w (false, i) + w (true, i)) := by - apply Finset.sum_congr rfl - intro i _ - simp only [flow, Bool.false_eq_true, ↓reduceIte, pairUpdate_sum] - -theorem flow_sum {α : Type uα} [Fintype α] (B : Bool × α → Bool) - (w : Bool × α → ℝ) (c : α → Bool) : - (∑ x, flow B w c x) = ∑ x, w x := by - simp only [Fintype.sum_prod_type, Fintype.sum_bool, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro i _ - simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm] using - (pairUpdate_sum (B (false, i)) (B (true, i)) (w (false, i)) (w (true, i)) (c i)) - -theorem pairUpdate_energy_le (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : - (pairUpdate free₀ free₁ a b coin).1 ^ 2 + - (pairUpdate free₀ free₁ a b coin).2 ^ 2 ≤ a ^ 2 + b ^ 2 := by - have h := sq_nonneg (a - b) - cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate] <;> nlinarith - -theorem flow_energy_le {α : Type uα} [Fintype α] (B : Bool × α → Bool) - (w : Bool × α → ℝ) (c : α → Bool) : - (∑ x, flow B w c x ^ 2) ≤ ∑ x, w x ^ 2 := by - simp only [Fintype.sum_prod_type, Fintype.sum_bool, ← Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro i _ - simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm] using - pairUpdate_energy_le (B (false, i)) (B (true, i)) (w (false, i)) (w (true, i)) (c i) - -theorem pairUpdate_first_noise (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : - (pairUpdate free₀ free₁ a b coin).1 = (a + b) / 2 + - sign coin * (if free₀ && free₁ then 0 else (a - b) / 2) := by - cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] <;> ring - -theorem pairUpdate_second_noise (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : - (pairUpdate free₀ free₁ a b coin).2 = (a + b) / 2 - - sign coin * (if free₀ && free₁ then 0 else (a - b) / 2) := by - cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] <;> ring - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Model + +namespace OAI + +universe uΩ uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def mean {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) : ℝ := + (∑ ω, f ω) / Fintype.card Ω + +def sign (b : Bool) : ℝ := if b then -1 else 1 + +@[simp] theorem sign_not (b : Bool) : sign (!b) = -sign b := by + cases b <;> norm_num [sign] + +@[simp] theorem sign_sq (b : Bool) : sign b ^ 2 = 1 := by + cases b <;> norm_num [sign] + +@[simp] theorem sign_mul_self (b : Bool) : sign b * sign b = 1 := by + simpa only [pow_two] using sign_sq b + +def toggleCoin {α : Type uα} [DecidableEq α] (i : α) : Equiv.Perm (α → Bool) := + Function.Involutive.toPerm (fun c => Function.update c i (!(c i))) (by + intro c + funext j + by_cases h : j = i + · subst j + simp + · simp [h]) + +@[simp] theorem toggleCoin_apply {α : Type uα} [DecidableEq α] + (i : α) (c : α → Bool) (j : α) : + toggleCoin i c j = Function.update c i (!(c i)) j := rfl + +theorem sum_sign {α : Type uα} [Fintype α] [DecidableEq α] (i : α) : + ∑ c : α → Bool, sign (c i) = 0 := by + have h := Equiv.sum_comp (toggleCoin i) (fun c : α → Bool => sign (c i)) + simp only [toggleCoin_apply, Function.update_self, sign_not, Finset.sum_neg_distrib] at h + linarith + +theorem sum_sign_pair {α : Type uα} [Fintype α] [DecidableEq α] (i j : α) : + (∑ c : α → Bool, sign (c i) * sign (c j)) = + if i = j then (Fintype.card (α → Bool) : ℝ) else 0 := by + by_cases h : i = j + · subst j + simp + · have he := Equiv.sum_comp (toggleCoin i) (fun c : α → Bool => sign (c i) * sign (c j)) + simp only [toggleCoin_apply, Function.update_self, + Function.update_of_ne (Ne.symm h), sign_not, neg_mul, + Finset.sum_neg_distrib] at he + rw [ite_eq_right h] + linarith + +theorem mean_signed_sum_sq {α : Type uα} [Fintype α] [DecidableEq α] (a : α → ℝ) : + mean (fun c : α → Bool => (∑ i, sign (c i) * a i) ^ 2) = ∑ i, a i ^ 2 := by + have hs : + (∑ c : α → Bool, (∑ i, sign (c i) * a i) ^ 2) = + (Fintype.card (α → Bool) : ℝ) * ∑ i, a i ^ 2 := by + calc + _ = ∑ c : α → Bool, ∑ i, ∑ j, + (sign (c i) * sign (c j)) * (a i * a j) := by + apply Finset.sum_congr rfl + intro c _ + simp only [pow_two, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + _ = ∑ i, ∑ j, (∑ c : α → Bool, sign (c i) * sign (c j)) * (a i * a j) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + simp only [Finset.sum_mul] + _ = _ := by + simp only [sum_sign_pair, ite_mul, zero_mul] + simp [Finset.mul_sum, pow_two] + unfold mean + rw [hs] + have hcard : (Fintype.card (α → Bool) : ℝ) ≠ 0 := by + exact_mod_cast Fintype.card_ne_zero + exact mul_div_cancel_left₀ _ hcard + +def pairUpdate (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : ℝ × ℝ := + if free₀ && free₁ then ((a + b) / 2, (a + b) / 2) + else if coin then (b, a) else (a, b) + +@[simp] theorem pairUpdate_sum (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : + (pairUpdate free₀ free₁ a b coin).1 + (pairUpdate free₀ free₁ a b coin).2 = a + b := by + cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate] <;> ring + +theorem pairUpdate_difference (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : + (pairUpdate free₀ free₁ a b coin).1 - (pairUpdate free₀ free₁ a b coin).2 = + sign coin * (if free₀ && free₁ then 0 else a - b) := by + cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] + +theorem pairUpdate_mean_first (free₀ free₁ : Bool) (a b : ℝ) : + mean (fun coin : Bool => (pairUpdate free₀ free₁ a b coin).1) = (a + b) / 2 := by + cases free₀ <;> cases free₁ <;> simp [mean, pairUpdate] <;> ring + +theorem pairUpdate_difference_sq (free₀ free₁ : Bool) (a b : ℝ) + (ha : free₀ = false → a = 0) (hb : free₁ = false → b = 0) : + (if free₀ && free₁ then (0 : ℝ) else a - b) ^ 2 = + (if free₁ then 0 else a ^ 2) + (if free₀ then 0 else b ^ 2) := by + cases free₀ <;> cases free₁ <;> simp_all + +def flow {α : Type uα} (B : Bool × α → Bool) (w : Bool × α → ℝ) + (c : α → Bool) (x : Bool × α) : ℝ := + let p := pairUpdate (B (false, x.2)) (B (true, x.2)) + (w (false, x.2)) (w (true, x.2)) (c x.2) + if x.1 then p.2 else p.1 + +def oddCoefficient {α : Type uα} [Fintype α] (ε : α → ℝ) (w : Bool × α → ℝ) : ℝ := + ∑ i, ε i * (w (false, i) - w (true, i)) + +theorem mean_oddCoefficient_sq {α : Type uα} [Fintype α] [DecidableEq α] + (B : Bool × α → Bool) (w : Bool × α → ℝ) (ε : α → ℝ) + (hw : ∀ x, B x = false → w x = 0) (hε : ∀ i, ε i ^ 2 = 1) : + mean (fun c : α → Bool => oddCoefficient ε (flow B w c) ^ 2) = + ∑ i, ((if B (true, i) then 0 else w (false, i) ^ 2) + + (if B (false, i) then 0 else w (true, i) ^ 2)) := by + have he (c : α → Bool) : + oddCoefficient ε (flow B w c) = + ∑ i, sign (c i) * (ε i * + (if B (false, i) && B (true, i) then 0 else w (false, i) - w (true, i))) := by + unfold oddCoefficient + apply Finset.sum_congr rfl + intro i _ + simp only [flow, Bool.false_eq_true, ↓reduceIte] + rw [pairUpdate_difference] + ring + simp_rw [he] + rw [mean_signed_sum_sq] + apply Finset.sum_congr rfl + intro i _ + rw [mul_pow, hε, one_mul] + exact pairUpdate_difference_sq _ _ _ _ (hw _) (hw _) + +end Conditional + +namespace Conditional + +def pairMap {α : Type uα} (c : α → Bool) (x : Bool × α) : Bool × α := + (x.1 ^^ c x.2, x.2) + +theorem pairMap_involutive {α : Type uα} (c : α → Bool) : + Function.Involutive (pairMap c) := by + rintro ⟨b, i⟩ + cases b <;> cases h : c i <;> simp [pairMap, h] + +theorem flow_sub {α : Type uα} (B : Bool × α → Bool) (u v : Bool × α → ℝ) + (c : α → Bool) (x : Bool × α) : + flow B (fun y => u y - v y) c x = flow B u c x - flow B v c x := by + rcases x with ⟨b, i⟩ + cases b <;> cases h₀ : B (false, i) <;> cases h₁ : B (true, i) <;> + cases hc : c i <;> simp [flow, pairUpdate, h₀, h₁, hc] <;> ring + +theorem flow_uniform {α : Type uα} (B : Bool × α → Bool) (r : ℝ) + (c : α → Bool) (x : Bool × α) : + flow B (fun y => if B y then r else 0) c x = + if B (pairMap c x) then r else 0 := by + rcases x with ⟨b, i⟩ + cases b <;> cases h₀ : B (false, i) <;> cases h₁ : B (true, i) <;> + cases hc : c i <;> simp [flow, pairUpdate, pairMap, h₀, h₁, hc] + +theorem flow_support {α : Type uα} (B : Bool × α → Bool) (w : Bool × α → ℝ) + (hw : ∀ x, B x = false → w x = 0) (c : α → Bool) (x : Bool × α) + (hx : B (pairMap c x) = false) : flow B w c x = 0 := by + rcases x with ⟨b, i⟩ + have h₀ := hw (false, i) + have h₁ := hw (true, i) + cases b <;> cases hb₀ : B (false, i) <;> cases hb₁ : B (true, i) <;> + cases hc : c i <;> simp_all [flow, pairUpdate, pairMap] + +theorem flow_evenCoefficient {α : Type uα} [Fintype α] + (B : Bool × α → Bool) (w : Bool × α → ℝ) (ε : α → ℝ) (c : α → Bool) : + (∑ i, ε i * (flow B w c (false, i) + flow B w c (true, i))) = + ∑ i, ε i * (w (false, i) + w (true, i)) := by + apply Finset.sum_congr rfl + intro i _ + simp only [flow, Bool.false_eq_true, ↓reduceIte, pairUpdate_sum] + +theorem flow_sum {α : Type uα} [Fintype α] (B : Bool × α → Bool) + (w : Bool × α → ℝ) (c : α → Bool) : + (∑ x, flow B w c x) = ∑ x, w x := by + simp only [Fintype.sum_prod_type, Fintype.sum_bool, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm] using + (pairUpdate_sum (B (false, i)) (B (true, i)) (w (false, i)) (w (true, i)) (c i)) + +theorem pairUpdate_energy_le (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : + (pairUpdate free₀ free₁ a b coin).1 ^ 2 + + (pairUpdate free₀ free₁ a b coin).2 ^ 2 ≤ a ^ 2 + b ^ 2 := by + have h := sq_nonneg (a - b) + cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate] <;> nlinarith + +theorem flow_energy_le {α : Type uα} [Fintype α] (B : Bool × α → Bool) + (w : Bool × α → ℝ) (c : α → Bool) : + (∑ x, flow B w c x ^ 2) ≤ ∑ x, w x ^ 2 := by + simp only [Fintype.sum_prod_type, Fintype.sum_bool, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i _ + simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm] using + pairUpdate_energy_le (B (false, i)) (B (true, i)) (w (false, i)) (w (true, i)) (c i) + +theorem pairUpdate_first_noise (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : + (pairUpdate free₀ free₁ a b coin).1 = (a + b) / 2 + + sign coin * (if free₀ && free₁ then 0 else (a - b) / 2) := by + cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] <;> ring + +theorem pairUpdate_second_noise (free₀ free₁ : Bool) (a b : ℝ) (coin : Bool) : + (pairUpdate free₀ free₁ a b coin).2 = (a + b) / 2 - + sign coin * (if free₀ && free₁ then 0 else (a - b) / 2) := by + cases free₀ <;> cases free₁ <;> cases coin <;> simp [pairUpdate, sign] <;> ring + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Parity.lean b/lean/OAI/Probability/ThorpShuffle/Parity.lean index 9e7f486ef25b6de7cd920bbfcd664d6f45d82093..6bccef7bd6483b2c152867ec3e1c6551051e8f0e 100644 --- a/lean/OAI/Probability/ThorpShuffle/Parity.lean +++ b/lean/OAI/Probability/ThorpShuffle/Parity.lean @@ -1,101 +1,101 @@ -import OAI.Probability.ThorpShuffle.MixingBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Parity -open Conditional - -def sign (d : ℕ) (g : State d) : ℝ := ((Equiv.Perm.sign g : ℤˣ) : ℤ) - -theorem sign_mul (d : ℕ) (g h : State d) : sign d (g * h) = sign d g * sign d h := by - simp [sign] - -theorem step_toggle (d : ℕ) (s : Position d) (c : Coins (d + 1)) : - step (d + 1) (toggleCoin s c) = - step (d + 1) c * Equiv.swap (Fin.cons false s) (Fin.cons true s) := by - classical - change Position d → Bool at c - apply Equiv.Perm.ext - intro x - obtain ⟨⟨b, t⟩, rfl⟩ := (splitPosition d).symm.surjective x - change (rotate (d + 1)) (Fin.cons (b ^^ toggleCoin s c t) t) = - step (d + 1) c (Equiv.swap (Fin.cons false s) (Fin.cons true s) (Fin.cons b t)) - by_cases ht : t = s - · subst t - cases b <;> simp only [Equiv.swap_apply_left, Equiv.swap_apply_right] - · change rotate (d + 1) (Fin.cons (false ^^ toggleCoin s c s) s) = - rotate (d + 1) (Fin.cons (true ^^ c s) s) - have hh : toggleCoin s c s = !(c s) := by - change Function.update c s (!(c s)) s = !(c s) - simp - rw [hh] - simp - · change rotate (d + 1) (Fin.cons (true ^^ toggleCoin s c s) s) = - rotate (d + 1) (Fin.cons (false ^^ c s) s) - have hh : toggleCoin s c s = !(c s) := by - change Function.update c s (!(c s)) s = !(c s) - simp - rw [hh] - simp - · have hf : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons false s := by - intro he; apply ht; simpa using congrArg Fin.tail he - have htr : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons true s := by - intro he; apply ht; simpa using congrArg Fin.tail he - rw [Equiv.swap_apply_of_ne_of_ne hf htr] - change rotate (d + 1) (Fin.cons (b ^^ toggleCoin s c t) t) = - rotate (d + 1) (Fin.cons (b ^^ c t) t) - have hh : toggleCoin s c t = c t := by - change Function.update c s (!(c s)) t = c t - exact Function.update_of_ne ht _ _ - rw [hh] - -theorem sign_step_toggle (d : ℕ) (s : Position d) (c : Coins (d + 1)) : - sign (d + 1) (step (d + 1) (toggleCoin s c)) = - -sign (d + 1) (step (d + 1) c) := by - classical - rw [step_toggle, sign_mul] - have hne : (Fin.cons false s : Position (d + 1)) ≠ Fin.cons true s := by - intro he - have hh := congrFun he 0 - simp at hh - simp [sign, Equiv.Perm.sign_swap hne] - -theorem mean_sign_step (d : ℕ) : - mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) = 0 := by - classical - let s : Position d := fun _ => false - have hh := mean_equiv (toggleCoin s) - (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) - change mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) (toggleCoin s c))) = - mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) at hh - simp_rw [sign_step_toggle] at hh - have hn : mean (fun c : Coins (d + 1) => -sign (d + 1) (step (d + 1) c)) = - -mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) := by - simp only [mean, Finset.sum_neg_distrib, neg_div] - rw [hn] at hh - linarith - -theorem mean_sign_run (d t : ℕ) : - mean (fun ω : History (d + 1) (t + 1) => sign (d + 1) (run (d + 1) (t + 1) ω)) = 0 := by - rw [mean_history_succ] - simp only [run_snoc, sign_mul, mean_mul_const, mean_sign_step, zero_mul, mean_zero] - -theorem law_sign_zero (d t : ℕ) : - (∑ g : State (d + 1), law (d + 1) (t + 1) g * sign (d + 1) g) = 0 := by - rw [law, fairMass_test] - exact mean_sign_run d t - -end Parity - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.MixingBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Parity +open Conditional + +def sign (d : ℕ) (g : State d) : ℝ := ((Equiv.Perm.sign g : ℤˣ) : ℤ) + +theorem sign_mul (d : ℕ) (g h : State d) : sign d (g * h) = sign d g * sign d h := by + simp [sign] + +theorem step_toggle (d : ℕ) (s : Position d) (c : Coins (d + 1)) : + step (d + 1) (toggleCoin s c) = + step (d + 1) c * Equiv.swap (Fin.cons false s) (Fin.cons true s) := by + classical + change Position d → Bool at c + apply Equiv.Perm.ext + intro x + obtain ⟨⟨b, t⟩, rfl⟩ := (splitPosition d).symm.surjective x + change (rotate (d + 1)) (Fin.cons (b ^^ toggleCoin s c t) t) = + step (d + 1) c (Equiv.swap (Fin.cons false s) (Fin.cons true s) (Fin.cons b t)) + by_cases ht : t = s + · subst t + cases b <;> simp only [Equiv.swap_apply_left, Equiv.swap_apply_right] + · change rotate (d + 1) (Fin.cons (false ^^ toggleCoin s c s) s) = + rotate (d + 1) (Fin.cons (true ^^ c s) s) + have hh : toggleCoin s c s = !(c s) := by + change Function.update c s (!(c s)) s = !(c s) + simp + rw [hh] + simp + · change rotate (d + 1) (Fin.cons (true ^^ toggleCoin s c s) s) = + rotate (d + 1) (Fin.cons (false ^^ c s) s) + have hh : toggleCoin s c s = !(c s) := by + change Function.update c s (!(c s)) s = !(c s) + simp + rw [hh] + simp + · have hf : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons false s := by + intro he; apply ht; simpa using congrArg Fin.tail he + have htr : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons true s := by + intro he; apply ht; simpa using congrArg Fin.tail he + rw [Equiv.swap_apply_of_ne_of_ne hf htr] + change rotate (d + 1) (Fin.cons (b ^^ toggleCoin s c t) t) = + rotate (d + 1) (Fin.cons (b ^^ c t) t) + have hh : toggleCoin s c t = c t := by + change Function.update c s (!(c s)) t = c t + exact Function.update_of_ne ht _ _ + rw [hh] + +theorem sign_step_toggle (d : ℕ) (s : Position d) (c : Coins (d + 1)) : + sign (d + 1) (step (d + 1) (toggleCoin s c)) = + -sign (d + 1) (step (d + 1) c) := by + classical + rw [step_toggle, sign_mul] + have hne : (Fin.cons false s : Position (d + 1)) ≠ Fin.cons true s := by + intro he + have hh := congrFun he 0 + simp at hh + simp [sign, Equiv.Perm.sign_swap hne] + +theorem mean_sign_step (d : ℕ) : + mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) = 0 := by + classical + let s : Position d := fun _ => false + have hh := mean_equiv (toggleCoin s) + (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) + change mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) (toggleCoin s c))) = + mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) at hh + simp_rw [sign_step_toggle] at hh + have hn : mean (fun c : Coins (d + 1) => -sign (d + 1) (step (d + 1) c)) = + -mean (fun c : Coins (d + 1) => sign (d + 1) (step (d + 1) c)) := by + simp only [mean, Finset.sum_neg_distrib, neg_div] + rw [hn] at hh + linarith + +theorem mean_sign_run (d t : ℕ) : + mean (fun ω : History (d + 1) (t + 1) => sign (d + 1) (run (d + 1) (t + 1) ω)) = 0 := by + rw [mean_history_succ] + simp only [run_snoc, sign_mul, mean_mul_const, mean_sign_step, zero_mul, mean_zero] + +theorem law_sign_zero (d t : ℕ) : + (∑ g : State (d + 1), law (d + 1) (t + 1) g * sign (d + 1) g) = 0 := by + rw [law, fairMass_test] + exact mean_sign_run d t + +end Parity + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/PartitionBounds.lean b/lean/OAI/Probability/ThorpShuffle/PartitionBounds.lean index 55de68fede73d0c73b049eae6951fa8300bf0a6a..5c0a3d73bf52a2a38512a61df45ca2eeee1d8354 100644 --- a/lean/OAI/Probability/ThorpShuffle/PartitionBounds.lean +++ b/lean/OAI/Probability/ThorpShuffle/PartitionBounds.lean @@ -1,221 +1,221 @@ -import OAI.Probability.ThorpShuffle.ExtensionBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young -open scoped Classical - -def idealDiagram (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : YoungDiagram where - cells := (Finset.univ.filter (· ∈ s)).image Subtype.val - isLowerSet := by - intro y x hxy hy - obtain ⟨z, hz, hzy⟩ := Finset.mem_image.mp hy - have hyD : y ∈ D := by rw [← hzy]; exact z.property - have hxD : x ∈ D := D.isLowerSet hxy hyD - refine Finset.mem_image.mpr ⟨⟨x, hxD⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, rfl⟩ - apply hs (show (⟨x, hxD⟩ : Cells D) ≤ z from by change x ≤ z.val; rwa [hzy]) - exact (Finset.mem_filter.mp hz).2 - -lemma mem_idealDiagram (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) (p : ℕ × ℕ) : - p ∈ idealDiagram D s hs ↔ ∃ h : p ∈ D, (⟨p, h⟩ : Cells D) ∈ s := by - constructor - · intro hp - obtain ⟨x, hx, hxp⟩ := Finset.mem_image.mp hp - subst p - exact ⟨x.property, (Finset.mem_filter.mp hx).2⟩ - · rintro ⟨h, hp⟩ - exact Finset.mem_image.mpr ⟨⟨p, h⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hp⟩, rfl⟩ - -def idealCells (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : - Cells (idealDiagram D s hs) ≃o s where - toFun x := ⟨⟨x.val, (mem_idealDiagram D s hs x.val).mp x.property |>.choose⟩, - (mem_idealDiagram D s hs x.val).mp x.property |>.choose_spec⟩ - invFun x := ⟨x.val.val, (mem_idealDiagram D s hs x.val.val).mpr ⟨x.val.property, x.property⟩⟩ - left_inv _ := rfl - right_inv _ := rfl - map_rel_iff' := Iff.rfl - -lemma idealDiagram_extensions_le (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : - Fintype.card (Extensions (Cells (idealDiagram D s hs))) ≤ Fintype.card (Extensions (Cells D)) := by - rw [extensions_card_orderIso (idealCells D s hs)] - exact extensions_card_ideal s hs - -theorem exists_trimLower (D : YoungDiagram) (k : ℕ) (hk : k ≤ Fintype.card (Lower D)) : - ∃ E : YoungDiagram, E.rowLen 0 = D.rowLen 0 ∧ Fintype.card (Lower E) = k ∧ - Fintype.card (Extensions (Cells E)) ≤ Fintype.card (Extensions (Cells D)) := by - obtain ⟨e⟩ := extensions_nonempty (Lower D) - let s : Set (Cells D) := {x | ∀ h : x.val.1 ≠ 0, (e.val ⟨x, h⟩).val < k} - have hs : IsLowerSet s := by - intro y x hxy hy hx - have hy' : y.val.1 ≠ 0 := by have := hxy.1; omega - exact lt_of_le_of_lt (e.property.monotone (show (⟨x, hx⟩ : Lower D) ≤ ⟨y, hy'⟩ from hxy)) (hy hy') - let E := idealDiagram D s hs - have htop : E.rowLen 0 = D.rowLen 0 := by - apply eq_of_forall_lt_iff - intro j - rw [← YoungDiagram.mem_iff_lt_rowLen, ← YoungDiagram.mem_iff_lt_rowLen] - change (0, j) ∈ idealDiagram D s hs ↔ (0, j) ∈ D - rw [mem_idealDiagram] - exact ⟨fun h => h.choose, fun h => ⟨h, fun hn => (hn rfl).elim⟩⟩ - let f : Lower E ≃ Fin k := { - toFun := fun x => - let z := idealCells D s hs x.val - ⟨(e.val ⟨z.val, x.property⟩).val, z.property x.property⟩ - invFun := fun j => - let z := e.val.symm ⟨j.val, j.isLt.trans_le hk⟩ - ⟨(idealCells D s hs).symm ⟨z.val, by - intro h - have hh : (⟨z.val, h⟩ : Lower D) = z := rfl - rw [hh, Equiv.apply_symm_apply] - exact j.isLt⟩, z.property⟩ - left_inv := by - intro x - apply Subtype.ext - apply (idealCells D s hs).injective - apply Subtype.ext - have hh := e.val.symm_apply_apply ⟨(idealCells D s hs x.val).val, x.property⟩ - simpa only [OrderIso.apply_symm_apply] using congrArg Subtype.val hh - right_inv := by - intro j - apply Fin.ext - simpa only [OrderIso.apply_symm_apply] using congrArg Fin.val (e.val.apply_symm_apply ⟨j.val, j.isLt.trans_le hk⟩) } - exact ⟨E, htop, (Fintype.card_congr f).trans (Fintype.card_fin k), idealDiagram_extensions_le D s hs⟩ - -theorem choose_le_extensions (D : YoungDiagram) (k : ℕ) - (hk : k ≤ Fintype.card (Lower D)) (hL : k ≤ D.rowLen 0) : - (D.rowLen 0).choose k ≤ Fintype.card (Extensions (Cells D)) := by - obtain ⟨E, htop, hsize, hle⟩ := exists_trimLower D k hk - have hh := choose_row_le_extensions E (by rw [hsize, htop]; exact hL) - rw [htop, hsize] at hh - exact hh.trans hle - -end Thorp.Young - -namespace Thorp.Young -open scoped Classical - -lemma partition_count_le_pow (n : ℕ) : Fintype.card (Nat.Partition n) ≤ 2 ^ n := by - have h := Fintype.card_le_of_surjective (Nat.Partition.ofComposition n) Nat.Partition.ofComposition_surj - rw [composition_card] at h - exact h.trans (Nat.pow_le_pow_right (by omega) (Nat.sub_le _ _)) - -lemma rectangle_card_le (D : YoungDiagram) (x : Cells D) : - (x.val.1 + 1) * (x.val.2 + 1) ≤ Fintype.card (Cells D) := by - let f : Fin (x.val.1 + 1) × Fin (x.val.2 + 1) → Cells D := fun p => - ⟨(p.1, p.2), D.up_left_mem (i2 := x.val.1) (j2 := x.val.2) - (by have := p.1.isLt; omega) (by have := p.2.isLt; omega) x.property⟩ - have hf : Function.Injective f := by - intro p q hpq - apply Prod.ext <;> apply Fin.ext - · exact congrArg (fun z : Cells D => z.val.1) hpq - · exact congrArg (fun z : Cells D => z.val.2) hpq - simpa only [Fintype.card_prod, Fintype.card_fin] using Fintype.card_le_of_injective f hf - -lemma cell_small_coord (D : YoungDiagram) (x : Cells D) : - x.val.1 < Nat.sqrt (Fintype.card (Cells D)) ∨ x.val.2 < Nat.sqrt (Fintype.card (Cells D)) := by - by_contra h - push Not at h - have hh := rectangle_card_le D x - have hs := Nat.lt_succ_sqrt' (Fintype.card (Cells D)) - have hm := Nat.mul_le_mul (Nat.succ_le_succ h.1) (Nat.succ_le_succ h.2) - nlinarith - -lemma rowLen_le_card (D : YoungDiagram) (i : ℕ) : D.rowLen i ≤ Fintype.card (Cells D) := by - rw [← card_row_subtype D i] - exact Fintype.card_le_of_injective Subtype.val Subtype.val_injective - -lemma colLen_le_card (D : YoungDiagram) (j : ℕ) : D.colLen j ≤ Fintype.card (Cells D) := by - rw [← card_column D j] - exact (Finset.card_le_card (Finset.filter_subset _ _)).trans_eq (Finset.card_univ) - -theorem partition_count_le_sqrt_pow (n : ℕ) : - Fintype.card (Nat.Partition n) ≤ (n + 1) ^ (2 * Nat.sqrt n) := by - let F (p : Nat.Partition n) : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) := - (fun i => ⟨(ofPartition p).rowLen i, by - have := rowLen_le_card (ofPartition p) i - rw [card_ofPartition] at this - omega⟩, - fun j => ⟨(ofPartition p).colLen j, by - have := colLen_le_card (ofPartition p) j - rw [card_ofPartition] at this - omega⟩) - have hf : Function.Injective F := by - intro p q hpq - apply ofPartition_injective - apply YoungDiagram.ext - ext z - have aux (p q : Nat.Partition n) (hpq : F p = F q) (hz : z ∈ ofPartition p) : z ∈ ofPartition q := by - have hs := cell_small_coord (ofPartition p) ⟨z, hz⟩ - rw [card_ofPartition] at hs - rcases hs with hs | hs - · have he := congrArg (fun v : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) => - (v.1 ⟨z.1, hs⟩).val) hpq - change (ofPartition p).rowLen z.1 = (ofPartition q).rowLen z.1 at he - apply YoungDiagram.mem_iff_lt_rowLen.mpr - rw [← he] - exact YoungDiagram.mem_iff_lt_rowLen.mp hz - · have he := congrArg (fun v : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) => - (v.2 ⟨z.2, hs⟩).val) hpq - change (ofPartition p).colLen z.2 = (ofPartition q).colLen z.2 at he - apply YoungDiagram.mem_iff_lt_colLen.mpr - rw [← he] - exact YoungDiagram.mem_iff_lt_colLen.mp hz - exact ⟨aux p q hpq, aux q p hpq.symm⟩ - have hh := Fintype.card_le_of_injective F hf - simpa only [Fintype.card_prod, Fintype.card_fun, Fintype.card_fin, two_mul, pow_add] using hh - -end Thorp.Young - -namespace Thorp.Young -open scoped Classical - -lemma pow_le_choose_mul (a k : ℕ) : a ^ k ≤ (k * a).choose k := by - let X := Fin k × Fin a - let S := {s : Finset X // s.card = k} - let f (v : Fin k → Fin a) : S := ⟨Finset.univ.image (fun i => (i, v i)), by - rw [Finset.card_image_of_injective _ (by intro i j h; exact congrArg Prod.fst h), Finset.card_univ, Fintype.card_fin]⟩ - have hf : Function.Injective f := by - intro v w hvw - funext i - have he := congrArg Subtype.val hvw - have hm : (i, v i) ∈ (f w).val := by rw [← he]; exact Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩ - obtain ⟨j, _, hj⟩ := Finset.mem_image.mp hm - have hji : j = i := congrArg Prod.fst hj - subst j - exact (congrArg Prod.snd hj).symm - have hS : Fintype.card S = (k * a).choose k := by - calc - _ = ((Finset.univ : Finset X).powersetCard k).card := by - rw [Fintype.card_subtype] - congr 1 - ext s - simp - _ = _ := by simp [X] - have hh := Fintype.card_le_of_injective f hf - simpa only [Fintype.card_fun, Fintype.card_fin, hS] using hh - -lemma pow_le_choose_of_mul_le (a k L : ℕ) (h : a * k ≤ L) : a ^ k ≤ L.choose k := by - exact (pow_le_choose_mul a k).trans (Nat.choose_le_choose k (by simpa only [Nat.mul_comm] using h)) - -lemma sub_add_one_le_choose (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : n - k + 1 ≤ n.choose k := by - obtain ⟨r, rfl⟩ := Nat.exists_eq_add_of_le hkn - simp only [Nat.add_sub_cancel_left] - induction r with - | zero => simp - | succ r ih => - obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : k ≠ 0) - rw [show j + 1 + (r + 1) = (j + 1 + r) + 1 by omega, Nat.choose_succ_succ] - have hp : 1 ≤ (j + 1 + r).choose j := Nat.one_le_iff_ne_zero.mpr (Nat.choose_ne_zero (by omega)) - simp only [Nat.succ_eq_add_one] at ih ⊢ - omega - -end Thorp.Young - -end - -end OAI +import OAI.Probability.ThorpShuffle.ExtensionBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young +open scoped Classical + +def idealDiagram (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : YoungDiagram where + cells := (Finset.univ.filter (· ∈ s)).image Subtype.val + isLowerSet := by + intro y x hxy hy + obtain ⟨z, hz, hzy⟩ := Finset.mem_image.mp hy + have hyD : y ∈ D := by rw [← hzy]; exact z.property + have hxD : x ∈ D := D.isLowerSet hxy hyD + refine Finset.mem_image.mpr ⟨⟨x, hxD⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩, rfl⟩ + apply hs (show (⟨x, hxD⟩ : Cells D) ≤ z from by change x ≤ z.val; rwa [hzy]) + exact (Finset.mem_filter.mp hz).2 + +lemma mem_idealDiagram (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) (p : ℕ × ℕ) : + p ∈ idealDiagram D s hs ↔ ∃ h : p ∈ D, (⟨p, h⟩ : Cells D) ∈ s := by + constructor + · intro hp + obtain ⟨x, hx, hxp⟩ := Finset.mem_image.mp hp + subst p + exact ⟨x.property, (Finset.mem_filter.mp hx).2⟩ + · rintro ⟨h, hp⟩ + exact Finset.mem_image.mpr ⟨⟨p, h⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hp⟩, rfl⟩ + +def idealCells (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : + Cells (idealDiagram D s hs) ≃o s where + toFun x := ⟨⟨x.val, (mem_idealDiagram D s hs x.val).mp x.property |>.choose⟩, + (mem_idealDiagram D s hs x.val).mp x.property |>.choose_spec⟩ + invFun x := ⟨x.val.val, (mem_idealDiagram D s hs x.val.val).mpr ⟨x.val.property, x.property⟩⟩ + left_inv _ := rfl + right_inv _ := rfl + map_rel_iff' := Iff.rfl + +lemma idealDiagram_extensions_le (D : YoungDiagram) (s : Set (Cells D)) (hs : IsLowerSet s) : + Fintype.card (Extensions (Cells (idealDiagram D s hs))) ≤ Fintype.card (Extensions (Cells D)) := by + rw [extensions_card_orderIso (idealCells D s hs)] + exact extensions_card_ideal s hs + +theorem exists_trimLower (D : YoungDiagram) (k : ℕ) (hk : k ≤ Fintype.card (Lower D)) : + ∃ E : YoungDiagram, E.rowLen 0 = D.rowLen 0 ∧ Fintype.card (Lower E) = k ∧ + Fintype.card (Extensions (Cells E)) ≤ Fintype.card (Extensions (Cells D)) := by + obtain ⟨e⟩ := extensions_nonempty (Lower D) + let s : Set (Cells D) := {x | ∀ h : x.val.1 ≠ 0, (e.val ⟨x, h⟩).val < k} + have hs : IsLowerSet s := by + intro y x hxy hy hx + have hy' : y.val.1 ≠ 0 := by have := hxy.1; omega + exact lt_of_le_of_lt (e.property.monotone (show (⟨x, hx⟩ : Lower D) ≤ ⟨y, hy'⟩ from hxy)) (hy hy') + let E := idealDiagram D s hs + have htop : E.rowLen 0 = D.rowLen 0 := by + apply eq_of_forall_lt_iff + intro j + rw [← YoungDiagram.mem_iff_lt_rowLen, ← YoungDiagram.mem_iff_lt_rowLen] + change (0, j) ∈ idealDiagram D s hs ↔ (0, j) ∈ D + rw [mem_idealDiagram] + exact ⟨fun h => h.choose, fun h => ⟨h, fun hn => (hn rfl).elim⟩⟩ + let f : Lower E ≃ Fin k := { + toFun := fun x => + let z := idealCells D s hs x.val + ⟨(e.val ⟨z.val, x.property⟩).val, z.property x.property⟩ + invFun := fun j => + let z := e.val.symm ⟨j.val, j.isLt.trans_le hk⟩ + ⟨(idealCells D s hs).symm ⟨z.val, by + intro h + have hh : (⟨z.val, h⟩ : Lower D) = z := rfl + rw [hh, Equiv.apply_symm_apply] + exact j.isLt⟩, z.property⟩ + left_inv := by + intro x + apply Subtype.ext + apply (idealCells D s hs).injective + apply Subtype.ext + have hh := e.val.symm_apply_apply ⟨(idealCells D s hs x.val).val, x.property⟩ + simpa only [OrderIso.apply_symm_apply] using congrArg Subtype.val hh + right_inv := by + intro j + apply Fin.ext + simpa only [OrderIso.apply_symm_apply] using congrArg Fin.val (e.val.apply_symm_apply ⟨j.val, j.isLt.trans_le hk⟩) } + exact ⟨E, htop, (Fintype.card_congr f).trans (Fintype.card_fin k), idealDiagram_extensions_le D s hs⟩ + +theorem choose_le_extensions (D : YoungDiagram) (k : ℕ) + (hk : k ≤ Fintype.card (Lower D)) (hL : k ≤ D.rowLen 0) : + (D.rowLen 0).choose k ≤ Fintype.card (Extensions (Cells D)) := by + obtain ⟨E, htop, hsize, hle⟩ := exists_trimLower D k hk + have hh := choose_row_le_extensions E (by rw [hsize, htop]; exact hL) + rw [htop, hsize] at hh + exact hh.trans hle + +end Thorp.Young + +namespace Thorp.Young +open scoped Classical + +lemma partition_count_le_pow (n : ℕ) : Fintype.card (Nat.Partition n) ≤ 2 ^ n := by + have h := Fintype.card_le_of_surjective (Nat.Partition.ofComposition n) Nat.Partition.ofComposition_surj + rw [composition_card] at h + exact h.trans (Nat.pow_le_pow_right (by omega) (Nat.sub_le _ _)) + +lemma rectangle_card_le (D : YoungDiagram) (x : Cells D) : + (x.val.1 + 1) * (x.val.2 + 1) ≤ Fintype.card (Cells D) := by + let f : Fin (x.val.1 + 1) × Fin (x.val.2 + 1) → Cells D := fun p => + ⟨(p.1, p.2), D.up_left_mem (i2 := x.val.1) (j2 := x.val.2) + (by have := p.1.isLt; omega) (by have := p.2.isLt; omega) x.property⟩ + have hf : Function.Injective f := by + intro p q hpq + apply Prod.ext <;> apply Fin.ext + · exact congrArg (fun z : Cells D => z.val.1) hpq + · exact congrArg (fun z : Cells D => z.val.2) hpq + simpa only [Fintype.card_prod, Fintype.card_fin] using Fintype.card_le_of_injective f hf + +lemma cell_small_coord (D : YoungDiagram) (x : Cells D) : + x.val.1 < Nat.sqrt (Fintype.card (Cells D)) ∨ x.val.2 < Nat.sqrt (Fintype.card (Cells D)) := by + by_contra h + push Not at h + have hh := rectangle_card_le D x + have hs := Nat.lt_succ_sqrt' (Fintype.card (Cells D)) + have hm := Nat.mul_le_mul (Nat.succ_le_succ h.1) (Nat.succ_le_succ h.2) + nlinarith + +lemma rowLen_le_card (D : YoungDiagram) (i : ℕ) : D.rowLen i ≤ Fintype.card (Cells D) := by + rw [← card_row_subtype D i] + exact Fintype.card_le_of_injective Subtype.val Subtype.val_injective + +lemma colLen_le_card (D : YoungDiagram) (j : ℕ) : D.colLen j ≤ Fintype.card (Cells D) := by + rw [← card_column D j] + exact (Finset.card_le_card (Finset.filter_subset _ _)).trans_eq (Finset.card_univ) + +theorem partition_count_le_sqrt_pow (n : ℕ) : + Fintype.card (Nat.Partition n) ≤ (n + 1) ^ (2 * Nat.sqrt n) := by + let F (p : Nat.Partition n) : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) := + (fun i => ⟨(ofPartition p).rowLen i, by + have := rowLen_le_card (ofPartition p) i + rw [card_ofPartition] at this + omega⟩, + fun j => ⟨(ofPartition p).colLen j, by + have := colLen_le_card (ofPartition p) j + rw [card_ofPartition] at this + omega⟩) + have hf : Function.Injective F := by + intro p q hpq + apply ofPartition_injective + apply YoungDiagram.ext + ext z + have aux (p q : Nat.Partition n) (hpq : F p = F q) (hz : z ∈ ofPartition p) : z ∈ ofPartition q := by + have hs := cell_small_coord (ofPartition p) ⟨z, hz⟩ + rw [card_ofPartition] at hs + rcases hs with hs | hs + · have he := congrArg (fun v : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) => + (v.1 ⟨z.1, hs⟩).val) hpq + change (ofPartition p).rowLen z.1 = (ofPartition q).rowLen z.1 at he + apply YoungDiagram.mem_iff_lt_rowLen.mpr + rw [← he] + exact YoungDiagram.mem_iff_lt_rowLen.mp hz + · have he := congrArg (fun v : (Fin (Nat.sqrt n) → Fin (n + 1)) × (Fin (Nat.sqrt n) → Fin (n + 1)) => + (v.2 ⟨z.2, hs⟩).val) hpq + change (ofPartition p).colLen z.2 = (ofPartition q).colLen z.2 at he + apply YoungDiagram.mem_iff_lt_colLen.mpr + rw [← he] + exact YoungDiagram.mem_iff_lt_colLen.mp hz + exact ⟨aux p q hpq, aux q p hpq.symm⟩ + have hh := Fintype.card_le_of_injective F hf + simpa only [Fintype.card_prod, Fintype.card_fun, Fintype.card_fin, two_mul, pow_add] using hh + +end Thorp.Young + +namespace Thorp.Young +open scoped Classical + +lemma pow_le_choose_mul (a k : ℕ) : a ^ k ≤ (k * a).choose k := by + let X := Fin k × Fin a + let S := {s : Finset X // s.card = k} + let f (v : Fin k → Fin a) : S := ⟨Finset.univ.image (fun i => (i, v i)), by + rw [Finset.card_image_of_injective _ (by intro i j h; exact congrArg Prod.fst h), Finset.card_univ, Fintype.card_fin]⟩ + have hf : Function.Injective f := by + intro v w hvw + funext i + have he := congrArg Subtype.val hvw + have hm : (i, v i) ∈ (f w).val := by rw [← he]; exact Finset.mem_image.mpr ⟨i, Finset.mem_univ _, rfl⟩ + obtain ⟨j, _, hj⟩ := Finset.mem_image.mp hm + have hji : j = i := congrArg Prod.fst hj + subst j + exact (congrArg Prod.snd hj).symm + have hS : Fintype.card S = (k * a).choose k := by + calc + _ = ((Finset.univ : Finset X).powersetCard k).card := by + rw [Fintype.card_subtype] + congr 1 + ext s + simp + _ = _ := by simp [X] + have hh := Fintype.card_le_of_injective f hf + simpa only [Fintype.card_fun, Fintype.card_fin, hS] using hh + +lemma pow_le_choose_of_mul_le (a k L : ℕ) (h : a * k ≤ L) : a ^ k ≤ L.choose k := by + exact (pow_le_choose_mul a k).trans (Nat.choose_le_choose k (by simpa only [Nat.mul_comm] using h)) + +lemma sub_add_one_le_choose (n k : ℕ) (hk : 1 ≤ k) (hkn : k ≤ n) : n - k + 1 ≤ n.choose k := by + obtain ⟨r, rfl⟩ := Nat.exists_eq_add_of_le hkn + simp only [Nat.add_sub_cancel_left] + induction r with + | zero => simp + | succ r ih => + obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : k ≠ 0) + rw [show j + 1 + (r + 1) = (j + 1 + r) + 1 by omega, Nat.choose_succ_succ] + have hp : 1 ≤ (j + 1 + r).choose j := Nat.one_le_iff_ne_zero.mpr (Nat.choose_ne_zero (by omega)) + simp only [Nat.succ_eq_add_one] at ih ⊢ + omega + +end Thorp.Young + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/PermutationCharacters.lean b/lean/OAI/Probability/ThorpShuffle/PermutationCharacters.lean index db26504bdded22929ffe612eab6ae6f11a9059f7..e78e0abbb11bb3fa0c342ee7e019c386f5633200 100644 --- a/lean/OAI/Probability/ThorpShuffle/PermutationCharacters.lean +++ b/lean/OAI/Probability/ThorpShuffle/PermutationCharacters.lean @@ -1,153 +1,153 @@ -import OAI.Probability.ThorpShuffle.VectorOrbits - -namespace OAI - -universe uE - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Specht -open scoped Classical -open Thorp.Young - -lemma degree_gt_one {n : ℕ} (p : NShape n) (hn : 16 ≤ n) (hp : 0 < defect p) : - 1 < degree p := by - by_cases hs : 4 * defect p ≤ n - · have hh := small_defect_degree p hs - have h3 : 3 ≤ 3 ^ defect p := by simpa using Nat.pow_le_pow_right (by omega : 0 < 3) (show 1 ≤ defect p by omega) - omega - · have hb := bulk_degree p (by omega) (by omega) - have h2 : (2 : ℝ) ≤ (2 : ℝ)^(n/16) := by - simpa using pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 2) (show 1 ≤ n/16 by omega) - have : (1 : ℝ) < degree p := lt_of_lt_of_le (by norm_num) (h2.trans hb) - exact_mod_cast this - -lemma full_reciprocal_bound (n : ℕ) : - (symmetricFamily n).reciprocalSum ≤ 2 + exceptionalReciprocalSum n := by - have hzero : slice n 0 ≤ 2 := by - have h := slice_bound n 0 1 (by norm_num) (fun p _ => by exact_mod_cast degree_pos p) - norm_num at h - exact h - have he : (symmetricFamily n).reciprocalSum = slice n 0 + exceptionalReciprocalSum n := by - unfold slice - rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = 0)) (by simp), Finset.sum_filter] - unfold exceptionalReciprocalSum - rw [← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro p _ - change inverseDegree p = _ - by_cases hp : defect p = 0 - · simp only [hp, lt_self_iff_false, ↓reduceIte, add_zero] - · simp only [hp, Nat.pos_of_ne_zero hp, ↓reduceIte, zero_add] - rw [he] - linarith - -lemma exceptional_count (n : ℕ) : Fintype.card {p : NShape n // defect p = 0} ≤ 2 := by - simpa using defect_card_bound n 0 - -end Thorp.Specht - -namespace Thorp.Specht -open scoped Classical - -variable {α : Type} [Fintype α] - -def permutationFamily (α : Type) [Fintype α] [DecidableEq α] : Thorp.Fourier.Family (Equiv.Perm α) := - (symmetricFamily (Fintype.card α)).pull (Equiv.permCongrHom (Fintype.equivFin α)) - -lemma complexSign_permCongr {β : Type} [Fintype β] (e : α ≃ β) (g : Equiv.Perm α) : - complexSign (e.permCongr g) = complexSign g := by - simp only [complexSign, MonoidHom.coe_mk, OneHom.coe_mk, Equiv.Perm.sign_permCongr] - -lemma complexSign_norm (g : Equiv.Perm α) : ‖complexSign g‖ = 1 := by - rcases Int.units_eq_one_or (Equiv.Perm.sign g) with h | h <;> simp [complexSign, h] - -lemma complexSign_eq [DecidableEq α] (g : Equiv.Perm α) : - complexSign g = (((Equiv.Perm.sign g : ℤˣ) : ℤ) : ℂ) := by - change (((@Equiv.Perm.sign α (Classical.typeDecidableEq α) _ g : ℤˣ) : ℤ) : ℂ) = _ - rw [Subsingleton.elim (Classical.typeDecidableEq α) (inferInstance : DecidableEq α)] - -lemma complexSign_sum [DecidableEq α] [Nontrivial α] : (∑ g : Equiv.Perm α, complexSign g) = 0 := by - obtain ⟨a, ha⟩ := Equiv.Perm.sign_surjective α (-1) - have he : complexSign a = -1 := by rw [complexSign_eq, ha]; simp - have hh := Equiv.sum_comp (Equiv.mulLeft a) (fun g : Equiv.Perm α => complexSign g) - simp only [Equiv.coe_mulLeft, map_mul, he, neg_one_mul, Finset.sum_neg_distrib] at hh - linear_combination - (1/2 : ℂ) * hh - -lemma permutation_exceptional_action [DecidableEq α] (p : NShape (Fintype.card α)) (hp : defect p = 0) : - (permutationFamily α).degree p = 1 ∧ - ((∀ (g : Equiv.Perm α) (v : Space (α:=Fin (Fintype.card α)) p), (permutationFamily α).rep p g v = v) ∨ - (∀ (g : Equiv.Perm α) (v : Space (α:=Fin (Fintype.card α)) p), (permutationFamily α).rep p g v = complexSign g • v)) := by - obtain ⟨hd, htr | hsign⟩ := exceptional_action p hp - · exact ⟨hd, Or.inl fun g v => htr _ v⟩ - · refine ⟨hd, Or.inr ?_⟩ - intro g v - change family p ((Fintype.equivFin α).permCongr g) v = _ - rw [hsign, complexSign_permCongr] - -end Thorp.Specht - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type} [Group G] [Fintype G] - -def realConv (μ ν : G → ℝ) (g : G) : ℝ := ∑ h, μ h * ν (h⁻¹ * g) - -def realPower (ν : G → ℝ) : ℕ → G → ℝ - | 0 => fun g => if g = 1 then 1 else 0 - | k+1 => realConv ν (realPower ν k) - -lemma realConv_nonneg (μ ν : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (hν : ∀ g, 0 ≤ ν g) : - ∀ g, 0 ≤ realConv μ ν g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hμ h) (hν _)) - -lemma realConv_sum (μ ν : G → ℝ) : ∑ g, realConv μ ν g = (∑ g, μ g) * (∑ g, ν g) := by - unfold realConv - rw [Finset.sum_comm, Finset.sum_mul] - apply Finset.sum_congr rfl - intro g _ - rw [← Finset.mul_sum] - congr 1 - exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) ν - -lemma realPower_nonneg (ν : G → ℝ) (hν : ∀ g, 0 ≤ ν g) (k : ℕ) : ∀ g, 0 ≤ realPower ν k g := by - induction k with - | zero => intro g; simp only [realPower]; split_ifs <;> norm_num - | succ k ih => exact realConv_nonneg ν (realPower ν k) hν ih - -lemma realPower_sum (ν : G → ℝ) (hν : ∑ g, ν g = 1) (k : ℕ) : ∑ g, realPower ν k g = 1 := by - induction k with - | zero => simp [realPower] - | succ k ih => rw [realPower, realConv_sum, hν, ih, mul_one] - -variable {E : Type uE} [AddCommGroup E] [Module ℂ E] - -lemma integrated_realConv (ρ : Representation ℂ G E) (μ ν : G → ℝ) : - integrated ρ (fun g => (realConv μ ν g : ℂ)) = integrated ρ (fun g => (μ g : ℂ)) * - integrated ρ (fun g => (ν g : ℂ)) := by - rw [← integrated_convolution] - congr 1 - funext g - simp only [realConv, convolution, Complex.ofReal_sum, Complex.ofReal_mul] - -lemma integrated_realPower (ρ : Representation ℂ G E) (ν : G → ℝ) (k : ℕ) : - integrated ρ (fun g => (realPower ν k g : ℂ)) = (integrated ρ (fun g => (ν g : ℂ)))^k := by - induction k with - | zero => - rw [pow_zero] - have he : (fun g => (realPower ν 0 g : ℂ)) = delta := by funext g; simp only [realPower, delta]; split_ifs <;> norm_num - rw [he, integrated_delta] - | succ k ih => rw [realPower, integrated_realConv, ih, pow_succ'] - -lemma integrated_real_sub (ρ : Representation ℂ G E) (μ ν : G → ℝ) : - integrated ρ (fun g => ((μ g - ν g : ℝ) : ℂ)) = - integrated ρ (fun g => (μ g : ℂ)) - integrated ρ (fun g => (ν g : ℂ)) := by - simp only [integrated, Complex.ofReal_sub, sub_smul, Finset.sum_sub_distrib] - -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.VectorOrbits + +namespace OAI + +universe uE + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Specht +open scoped Classical +open Thorp.Young + +lemma degree_gt_one {n : ℕ} (p : NShape n) (hn : 16 ≤ n) (hp : 0 < defect p) : + 1 < degree p := by + by_cases hs : 4 * defect p ≤ n + · have hh := small_defect_degree p hs + have h3 : 3 ≤ 3 ^ defect p := by simpa using Nat.pow_le_pow_right (by omega : 0 < 3) (show 1 ≤ defect p by omega) + omega + · have hb := bulk_degree p (by omega) (by omega) + have h2 : (2 : ℝ) ≤ (2 : ℝ)^(n/16) := by + simpa using pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 2) (show 1 ≤ n/16 by omega) + have : (1 : ℝ) < degree p := lt_of_lt_of_le (by norm_num) (h2.trans hb) + exact_mod_cast this + +lemma full_reciprocal_bound (n : ℕ) : + (symmetricFamily n).reciprocalSum ≤ 2 + exceptionalReciprocalSum n := by + have hzero : slice n 0 ≤ 2 := by + have h := slice_bound n 0 1 (by norm_num) (fun p _ => by exact_mod_cast degree_pos p) + norm_num at h + exact h + have he : (symmetricFamily n).reciprocalSum = slice n 0 + exceptionalReciprocalSum n := by + unfold slice + rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = 0)) (by simp), Finset.sum_filter] + unfold exceptionalReciprocalSum + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + change inverseDegree p = _ + by_cases hp : defect p = 0 + · simp only [hp, lt_self_iff_false, ↓reduceIte, add_zero] + · simp only [hp, Nat.pos_of_ne_zero hp, ↓reduceIte, zero_add] + rw [he] + linarith + +lemma exceptional_count (n : ℕ) : Fintype.card {p : NShape n // defect p = 0} ≤ 2 := by + simpa using defect_card_bound n 0 + +end Thorp.Specht + +namespace Thorp.Specht +open scoped Classical + +variable {α : Type} [Fintype α] + +def permutationFamily (α : Type) [Fintype α] [DecidableEq α] : Thorp.Fourier.Family (Equiv.Perm α) := + (symmetricFamily (Fintype.card α)).pull (Equiv.permCongrHom (Fintype.equivFin α)) + +lemma complexSign_permCongr {β : Type} [Fintype β] (e : α ≃ β) (g : Equiv.Perm α) : + complexSign (e.permCongr g) = complexSign g := by + simp only [complexSign, MonoidHom.coe_mk, OneHom.coe_mk, Equiv.Perm.sign_permCongr] + +lemma complexSign_norm (g : Equiv.Perm α) : ‖complexSign g‖ = 1 := by + rcases Int.units_eq_one_or (Equiv.Perm.sign g) with h | h <;> simp [complexSign, h] + +lemma complexSign_eq [DecidableEq α] (g : Equiv.Perm α) : + complexSign g = (((Equiv.Perm.sign g : ℤˣ) : ℤ) : ℂ) := by + change (((@Equiv.Perm.sign α (Classical.typeDecidableEq α) _ g : ℤˣ) : ℤ) : ℂ) = _ + rw [Subsingleton.elim (Classical.typeDecidableEq α) (inferInstance : DecidableEq α)] + +lemma complexSign_sum [DecidableEq α] [Nontrivial α] : (∑ g : Equiv.Perm α, complexSign g) = 0 := by + obtain ⟨a, ha⟩ := Equiv.Perm.sign_surjective α (-1) + have he : complexSign a = -1 := by rw [complexSign_eq, ha]; simp + have hh := Equiv.sum_comp (Equiv.mulLeft a) (fun g : Equiv.Perm α => complexSign g) + simp only [Equiv.coe_mulLeft, map_mul, he, neg_one_mul, Finset.sum_neg_distrib] at hh + linear_combination - (1/2 : ℂ) * hh + +lemma permutation_exceptional_action [DecidableEq α] (p : NShape (Fintype.card α)) (hp : defect p = 0) : + (permutationFamily α).degree p = 1 ∧ + ((∀ (g : Equiv.Perm α) (v : Space (α:=Fin (Fintype.card α)) p), (permutationFamily α).rep p g v = v) ∨ + (∀ (g : Equiv.Perm α) (v : Space (α:=Fin (Fintype.card α)) p), (permutationFamily α).rep p g v = complexSign g • v)) := by + obtain ⟨hd, htr | hsign⟩ := exceptional_action p hp + · exact ⟨hd, Or.inl fun g v => htr _ v⟩ + · refine ⟨hd, Or.inr ?_⟩ + intro g v + change family p ((Fintype.equivFin α).permCongr g) v = _ + rw [hsign, complexSign_permCongr] + +end Thorp.Specht + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type} [Group G] [Fintype G] + +def realConv (μ ν : G → ℝ) (g : G) : ℝ := ∑ h, μ h * ν (h⁻¹ * g) + +def realPower (ν : G → ℝ) : ℕ → G → ℝ + | 0 => fun g => if g = 1 then 1 else 0 + | k+1 => realConv ν (realPower ν k) + +lemma realConv_nonneg (μ ν : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) (hν : ∀ g, 0 ≤ ν g) : + ∀ g, 0 ≤ realConv μ ν g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hμ h) (hν _)) + +lemma realConv_sum (μ ν : G → ℝ) : ∑ g, realConv μ ν g = (∑ g, μ g) * (∑ g, ν g) := by + unfold realConv + rw [Finset.sum_comm, Finset.sum_mul] + apply Finset.sum_congr rfl + intro g _ + rw [← Finset.mul_sum] + congr 1 + exact Equiv.sum_comp (Equiv.mulLeft g⁻¹) ν + +lemma realPower_nonneg (ν : G → ℝ) (hν : ∀ g, 0 ≤ ν g) (k : ℕ) : ∀ g, 0 ≤ realPower ν k g := by + induction k with + | zero => intro g; simp only [realPower]; split_ifs <;> norm_num + | succ k ih => exact realConv_nonneg ν (realPower ν k) hν ih + +lemma realPower_sum (ν : G → ℝ) (hν : ∑ g, ν g = 1) (k : ℕ) : ∑ g, realPower ν k g = 1 := by + induction k with + | zero => simp [realPower] + | succ k ih => rw [realPower, realConv_sum, hν, ih, mul_one] + +variable {E : Type uE} [AddCommGroup E] [Module ℂ E] + +lemma integrated_realConv (ρ : Representation ℂ G E) (μ ν : G → ℝ) : + integrated ρ (fun g => (realConv μ ν g : ℂ)) = integrated ρ (fun g => (μ g : ℂ)) * + integrated ρ (fun g => (ν g : ℂ)) := by + rw [← integrated_convolution] + congr 1 + funext g + simp only [realConv, convolution, Complex.ofReal_sum, Complex.ofReal_mul] + +lemma integrated_realPower (ρ : Representation ℂ G E) (ν : G → ℝ) (k : ℕ) : + integrated ρ (fun g => (realPower ν k g : ℂ)) = (integrated ρ (fun g => (ν g : ℂ)))^k := by + induction k with + | zero => + rw [pow_zero] + have he : (fun g => (realPower ν 0 g : ℂ)) = delta := by funext g; simp only [realPower, delta]; split_ifs <;> norm_num + rw [he, integrated_delta] + | succ k ih => rw [realPower, integrated_realConv, ih, pow_succ'] + +lemma integrated_real_sub (ρ : Representation ℂ G E) (μ ν : G → ℝ) : + integrated ρ (fun g => ((μ g - ν g : ℝ) : ℂ)) = + integrated ρ (fun g => (μ g : ℂ)) - integrated ρ (fun g => (ν g : ℂ)) := by + simp only [integrated, Complex.ofReal_sub, sub_smul, Finset.sum_sub_distrib] + +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Polytabloids.lean b/lean/OAI/Probability/ThorpShuffle/Polytabloids.lean index eb78e715c56233fd363de06e7d56ce72021bbb94..33a6807af77b1ae51455fd24e4b7a69c2431cc2a 100644 --- a/lean/OAI/Probability/ThorpShuffle/Polytabloids.lean +++ b/lean/OAI/Probability/ThorpShuffle/Polytabloids.lean @@ -1,142 +1,142 @@ -import OAI.Probability.ThorpShuffle.Specht - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Specht -open scoped Classical - -variable {α : Type uα} [Fintype α] - -lemma tabloid_sum (r : α → ℕ) (f : Tabloid r) : ∑ x, f.val x = ∑ x, r x := by - obtain ⟨g, hg⟩ := f.property - rw [hg] - exact Equiv.sum_comp g r - -lemma collision_zero (r c : α → ℕ) (f : Tabloid r) - (x y : α) (hxy : x ≠ y) (hc : c x = c y) (hf : f.val x = f.val y) : - PermutationSpace.alternator (fiberGroup c).subtype - (complexSign.comp (fiberGroup c).subtype) (EuclideanSpace.single f 1) = 0 := by - apply PermutationSpace.alternator_single_zero _ _ f (⟨Equiv.swap x y, swap_preserves hc⟩ : fiberGroup c) - · rw [stabilizes_tabloid_iff] - exact swap_preserves hf - · exact complexSign_swap x y hxy - -lemma alternator_nonzero_nocollision (r c : α → ℕ) - (v : EuclideanSpace ℂ (Tabloid r)) - (hv : PermutationSpace.alternator (fiberGroup c).subtype - (complexSign.comp (fiberGroup c).subtype) v ≠ 0) : - ∃ f : Tabloid r, ∀ x y, c x = c y → f.val x = f.val y → x = y := by - by_contra hn - push Not at hn - apply hv - have hexp := (EuclideanSpace.basisFun (Tabloid r) ℂ).sum_repr v - simp only [EuclideanSpace.basisFun_repr, EuclideanSpace.basisFun_apply] at hexp - rw [← hexp, map_sum] - apply Finset.sum_eq_zero - intro f _ - obtain ⟨x, y, hcol, hrow, hne⟩ := hn f - rw [map_smul, collision_zero r c f x y hne hcol hrow, smul_zero] - -lemma rowRankSum_tableau (D : YoungDiagram) (t : α ≃ Thorp.Young.Cells D) : - ∑ x : α, tableauRow D t x = ∑ z : Thorp.Young.Cells D, z.val.1 := - Equiv.sum_comp t (fun z => z.val.1) - -lemma rankSum_le_of_nocollision (D E : YoungDiagram) - (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) - (f : Tabloid (tableauRow E u)) - (hf : ∀ x y, tableauCol D t x = tableauCol D t y → f.val x = f.val y → x = y) : - ∑ z : Thorp.Young.Cells D, z.val.1 ≤ ∑ z : Thorp.Young.Cells E, z.val.1 := by - have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → - f.val (t.symm x) = f.val (t.symm y) → x = y := by - intro x y hc hr - apply t.symm.injective - apply hf _ _ _ hr - simpa only [tableauCol, Equiv.apply_symm_apply] using hc - have hh := Thorp.Young.rowRankSum_le D (fun z => f.val (t.symm z)) hi - rw [Equiv.sum_comp t.symm, tabloid_sum, rowRankSum_tableau] at hh - exact hh - -lemma shape_eq_of_nocollision_equal_sum (D E : YoungDiagram) - (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) - (f : Tabloid (tableauRow E u)) - (hf : ∀ x y, tableauCol D t x = tableauCol D t y → f.val x = f.val y → x = y) - (hs : ∑ z : Thorp.Young.Cells D, z.val.1 = ∑ z : Thorp.Young.Cells E, z.val.1) : D = E := by - have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → - f.val (t.symm x) = f.val (t.symm y) → x = y := by - intro x y hc hr - apply t.symm.injective - apply hf _ _ _ hr - simpa only [tableauCol, Equiv.apply_symm_apply] using hc - have hsum : ∑ z : Thorp.Young.Cells D, f.val (t.symm z) = ∑ z : Thorp.Young.Cells D, z.val.1 := by - rw [Equiv.sum_comp t.symm, tabloid_sum, rowRankSum_tableau, hs] - obtain ⟨σ, -, hσ⟩ := Thorp.Young.column_sort D (fun z => f.val (t.symm z)) hi hsum - obtain ⟨g, hg⟩ := f.property - apply Thorp.Young.eq_of_rowPreserving D E (((σ.trans t.symm).trans g).trans u) - intro x - have hh := hσ x - rw [hg] at hh - exact hh - -lemma mapped_column_nonzero (D E : YoungDiagram) - (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) - (F : Representation.IntertwiningMap (module D t).toRepresentation (module E u).toRepresentation) - (hF : Function.Injective F) : - ∃ v : EuclideanSpace ℂ (Tabloid (tableauRow E u)), - PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) v ≠ 0 := by - let e : (module D t).toSubmodule := ⟨polytabloid D t, self_mem_cyclic _ _⟩ - have he : e ≠ 0 := by - intro h - exact polytabloid_ne_zero D t (congrArg Subtype.val h) - have heig : ∑ h : fiberGroup (tableauCol D t), complexSign h.val • - (module D t).toRepresentation h.val e = ⟪polytabloid D t, polytabloid D t⟫_ℂ • e := by - apply Subtype.ext - simp only [Submodule.coe_sum, Submodule.coe_smul] - change (∑ h : fiberGroup (tableauCol D t), complexSign h.val • - tabloidRep D t h.val (polytabloid D t)) = _ - exact (PermutationSpace.alternator_apply _ _ _).symm.trans (columnAlternator_rank_one D t _) - have hh := congrArg (fun z => (F z : EuclideanSpace ℂ (Tabloid (tableauRow E u)))) heig - simp only [map_sum, map_smul, F.isIntertwining, Submodule.coe_sum, Submodule.coe_smul] at hh - refine ⟨F e, ?_⟩ - intro hz - have heq : PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) (F e : EuclideanSpace ℂ (Tabloid (tableauRow E u))) = - ⟪polytabloid D t, polytabloid D t⟫_ℂ • (F e : EuclideanSpace ℂ (Tabloid (tableauRow E u))) := by - rw [PermutationSpace.alternator_apply] - exact hh - rw [hz] at heq - rcases smul_eq_zero.mp heq.symm with hs | hs - · exact polytabloid_ne_zero D t (inner_self_eq_zero.mp hs) - · have hh' : F e = 0 := Subtype.ext hs - exact he (hF (by simpa using hh')) - -lemma rankSum_le_of_injective_intertwiner (D E : YoungDiagram) - (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) - (F : Representation.IntertwiningMap (module D t).toRepresentation (module E u).toRepresentation) - (hF : Function.Injective F) : - ∑ z : Thorp.Young.Cells D, z.val.1 ≤ ∑ z : Thorp.Young.Cells E, z.val.1 := by - obtain ⟨v, hv⟩ := mapped_column_nonzero D E t u F hF - obtain ⟨f, hf⟩ := alternator_nonzero_nocollision _ _ v hv - exact rankSum_le_of_nocollision D E t u f hf - -theorem shape_eq_of_equiv (D E : YoungDiagram) - (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) - (F : Representation.Equiv (module D t).toRepresentation (module E u).toRepresentation) : D = E := by - have hle := rankSum_le_of_injective_intertwiner D E t u F.toIntertwiningMap F.toLinearEquiv.injective - have hge := rankSum_le_of_injective_intertwiner E D u t F.symm.toIntertwiningMap F.symm.toLinearEquiv.injective - obtain ⟨v, hv⟩ := mapped_column_nonzero D E t u F.toIntertwiningMap F.toLinearEquiv.injective - obtain ⟨f, hf⟩ := alternator_nonzero_nocollision _ _ v hv - exact shape_eq_of_nocollision_equal_sum D E t u f hf (le_antisymm hle hge) - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.Specht + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Specht +open scoped Classical + +variable {α : Type uα} [Fintype α] + +lemma tabloid_sum (r : α → ℕ) (f : Tabloid r) : ∑ x, f.val x = ∑ x, r x := by + obtain ⟨g, hg⟩ := f.property + rw [hg] + exact Equiv.sum_comp g r + +lemma collision_zero (r c : α → ℕ) (f : Tabloid r) + (x y : α) (hxy : x ≠ y) (hc : c x = c y) (hf : f.val x = f.val y) : + PermutationSpace.alternator (fiberGroup c).subtype + (complexSign.comp (fiberGroup c).subtype) (EuclideanSpace.single f 1) = 0 := by + apply PermutationSpace.alternator_single_zero _ _ f (⟨Equiv.swap x y, swap_preserves hc⟩ : fiberGroup c) + · rw [stabilizes_tabloid_iff] + exact swap_preserves hf + · exact complexSign_swap x y hxy + +lemma alternator_nonzero_nocollision (r c : α → ℕ) + (v : EuclideanSpace ℂ (Tabloid r)) + (hv : PermutationSpace.alternator (fiberGroup c).subtype + (complexSign.comp (fiberGroup c).subtype) v ≠ 0) : + ∃ f : Tabloid r, ∀ x y, c x = c y → f.val x = f.val y → x = y := by + by_contra hn + push Not at hn + apply hv + have hexp := (EuclideanSpace.basisFun (Tabloid r) ℂ).sum_repr v + simp only [EuclideanSpace.basisFun_repr, EuclideanSpace.basisFun_apply] at hexp + rw [← hexp, map_sum] + apply Finset.sum_eq_zero + intro f _ + obtain ⟨x, y, hcol, hrow, hne⟩ := hn f + rw [map_smul, collision_zero r c f x y hne hcol hrow, smul_zero] + +lemma rowRankSum_tableau (D : YoungDiagram) (t : α ≃ Thorp.Young.Cells D) : + ∑ x : α, tableauRow D t x = ∑ z : Thorp.Young.Cells D, z.val.1 := + Equiv.sum_comp t (fun z => z.val.1) + +lemma rankSum_le_of_nocollision (D E : YoungDiagram) + (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) + (f : Tabloid (tableauRow E u)) + (hf : ∀ x y, tableauCol D t x = tableauCol D t y → f.val x = f.val y → x = y) : + ∑ z : Thorp.Young.Cells D, z.val.1 ≤ ∑ z : Thorp.Young.Cells E, z.val.1 := by + have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → + f.val (t.symm x) = f.val (t.symm y) → x = y := by + intro x y hc hr + apply t.symm.injective + apply hf _ _ _ hr + simpa only [tableauCol, Equiv.apply_symm_apply] using hc + have hh := Thorp.Young.rowRankSum_le D (fun z => f.val (t.symm z)) hi + rw [Equiv.sum_comp t.symm, tabloid_sum, rowRankSum_tableau] at hh + exact hh + +lemma shape_eq_of_nocollision_equal_sum (D E : YoungDiagram) + (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) + (f : Tabloid (tableauRow E u)) + (hf : ∀ x y, tableauCol D t x = tableauCol D t y → f.val x = f.val y → x = y) + (hs : ∑ z : Thorp.Young.Cells D, z.val.1 = ∑ z : Thorp.Young.Cells E, z.val.1) : D = E := by + have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → + f.val (t.symm x) = f.val (t.symm y) → x = y := by + intro x y hc hr + apply t.symm.injective + apply hf _ _ _ hr + simpa only [tableauCol, Equiv.apply_symm_apply] using hc + have hsum : ∑ z : Thorp.Young.Cells D, f.val (t.symm z) = ∑ z : Thorp.Young.Cells D, z.val.1 := by + rw [Equiv.sum_comp t.symm, tabloid_sum, rowRankSum_tableau, hs] + obtain ⟨σ, -, hσ⟩ := Thorp.Young.column_sort D (fun z => f.val (t.symm z)) hi hsum + obtain ⟨g, hg⟩ := f.property + apply Thorp.Young.eq_of_rowPreserving D E (((σ.trans t.symm).trans g).trans u) + intro x + have hh := hσ x + rw [hg] at hh + exact hh + +lemma mapped_column_nonzero (D E : YoungDiagram) + (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) + (F : Representation.IntertwiningMap (module D t).toRepresentation (module E u).toRepresentation) + (hF : Function.Injective F) : + ∃ v : EuclideanSpace ℂ (Tabloid (tableauRow E u)), + PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) v ≠ 0 := by + let e : (module D t).toSubmodule := ⟨polytabloid D t, self_mem_cyclic _ _⟩ + have he : e ≠ 0 := by + intro h + exact polytabloid_ne_zero D t (congrArg Subtype.val h) + have heig : ∑ h : fiberGroup (tableauCol D t), complexSign h.val • + (module D t).toRepresentation h.val e = ⟪polytabloid D t, polytabloid D t⟫_ℂ • e := by + apply Subtype.ext + simp only [Submodule.coe_sum, Submodule.coe_smul] + change (∑ h : fiberGroup (tableauCol D t), complexSign h.val • + tabloidRep D t h.val (polytabloid D t)) = _ + exact (PermutationSpace.alternator_apply _ _ _).symm.trans (columnAlternator_rank_one D t _) + have hh := congrArg (fun z => (F z : EuclideanSpace ℂ (Tabloid (tableauRow E u)))) heig + simp only [map_sum, map_smul, F.isIntertwining, Submodule.coe_sum, Submodule.coe_smul] at hh + refine ⟨F e, ?_⟩ + intro hz + have heq : PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) (F e : EuclideanSpace ℂ (Tabloid (tableauRow E u))) = + ⟪polytabloid D t, polytabloid D t⟫_ℂ • (F e : EuclideanSpace ℂ (Tabloid (tableauRow E u))) := by + rw [PermutationSpace.alternator_apply] + exact hh + rw [hz] at heq + rcases smul_eq_zero.mp heq.symm with hs | hs + · exact polytabloid_ne_zero D t (inner_self_eq_zero.mp hs) + · have hh' : F e = 0 := Subtype.ext hs + exact he (hF (by simpa using hh')) + +lemma rankSum_le_of_injective_intertwiner (D E : YoungDiagram) + (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) + (F : Representation.IntertwiningMap (module D t).toRepresentation (module E u).toRepresentation) + (hF : Function.Injective F) : + ∑ z : Thorp.Young.Cells D, z.val.1 ≤ ∑ z : Thorp.Young.Cells E, z.val.1 := by + obtain ⟨v, hv⟩ := mapped_column_nonzero D E t u F hF + obtain ⟨f, hf⟩ := alternator_nonzero_nocollision _ _ v hv + exact rankSum_le_of_nocollision D E t u f hf + +theorem shape_eq_of_equiv (D E : YoungDiagram) + (t : α ≃ Thorp.Young.Cells D) (u : α ≃ Thorp.Young.Cells E) + (F : Representation.Equiv (module D t).toRepresentation (module E u).toRepresentation) : D = E := by + have hle := rankSum_le_of_injective_intertwiner D E t u F.toIntertwiningMap F.toLinearEquiv.injective + have hge := rankSum_le_of_injective_intertwiner E D u t F.symm.toIntertwiningMap F.symm.toLinearEquiv.injective + obtain ⟨v, hv⟩ := mapped_column_nonzero D E t u F.toIntertwiningMap F.toLinearEquiv.injective + obtain ⟨f, hf⟩ := alternator_nonzero_nocollision _ _ v hv + exact shape_eq_of_nocollision_equal_sum D E t u f hf (le_antisymm hle hge) + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/PrefixTests.lean b/lean/OAI/Probability/ThorpShuffle/PrefixTests.lean index 504d173ecd93c36c9dff73c018027a1259c33e5d..40fb20c696b202945b8b95f9fb01470fc910a1af 100644 --- a/lean/OAI/Probability/ThorpShuffle/PrefixTests.lean +++ b/lean/OAI/Probability/ThorpShuffle/PrefixTests.lean @@ -1,109 +1,109 @@ -import OAI.Probability.ThorpShuffle.TaggedCompletion - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem prefix_one_step_bound (d t k : ℕ) (e : Fin (k + 1) → Position (d + 1)) - (he : Function.Injective e) (f : (Fin (k + 1) → Position (d + 1)) → ℝ) - (hf : ∀ z, |f z| ≤ 1) : - |mean (fun ω : History (d + 1) t => f ((run (d + 1) t ω) ∘ e)) - - mean (fun ω : History (d + 1) t => completeTest f ((run (d + 1) t ω) ∘ Fin.init e))| ≤ - Real.sqrt ((Fintype.card (Position (d + 1)) : ℝ) * - expectedEnergy d (initialState (d + 1) (freeOf (Fin.init e)) (e (Fin.last k)) - (by - apply (freeOf_true _ _).mpr - intro i hi - exact Fin.castSucc_ne_last i (he hi))) t) := by - 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) - have hh := tagged_deviation_bound d (freeOf (Fin.init e)) (e (Fin.last k)) ht - (Fin.init e) (freeOf_exposed _) t (fun z y => f (Fin.snoc z y)) (fun z y => hf _) - convert hh using 1 - congr 1 - rw [← mean_sub] - apply mean_congr - intro ω - rw [← Fin.comp_snoc, Fin.snoc_init_self] - unfold completeTest - rw [freeCount_perm] - simp only [freeOf_perm] - -theorem uniform_prefix_step {α : Type uα} [Fintype α] [DecidableEq α] - (k : ℕ) (e : Fin (k + 1) → α) (he : Function.Injective e) - (f : (Fin (k + 1) → α) → ℝ) : - mean (fun g : Equiv.Perm α => f (g ∘ e)) = - mean (fun g : Equiv.Perm α => completeTest f (g ∘ Fin.init e)) := by - 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) - have h := uniform_tagged_completion (Fin.init e) (e (Fin.last k)) ht - (fun z y => f (Fin.snoc z y)) - simpa only [← Fin.comp_snoc, Fin.snoc_init_self, completeTest, freeCount_perm] using h - -theorem prefix_test_bound (d m : ℕ) - (hm : Fintype.card (Position (d + 2)) ≤ 8 * m) - (k : ℕ) (hk : k + m ≤ Fintype.card (Position (d + 2))) - (e : Fin k → Position (d + 2)) (he : Function.Injective e) - (f : (Fin k → Position (d + 2)) → ℝ) (hf : ∀ z, |f z| ≤ 1) : - |mean (fun ω : History (d + 2) (200 * (d + 2)) => f ((run (d + 2) (200 * (d + 2)) ω) ∘ e)) - - mean (fun g : State (d + 2) => f (g ∘ e))| ≤ - (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by - induction k with - | zero => - have hz (g : State (d + 2)) : g ∘ e = e := by funext i; exact Fin.elim0 i - simp only [hz, mean_const, sub_self, abs_zero, Nat.cast_zero, zero_mul, le_refl] - | 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) - have hcount : m ≤ freeCount (freeOf (Fin.init e)) := by - rw [freeCount_freeOf _ he0] - omega - have henergy := centeredPoint_energy_200 d (freeOf (Fin.init e)) (e (Fin.last k)) ht (by omega) - have hpower : (9 / 10 : ℝ) ^ freeCount (freeOf (Fin.init e)) ≤ (9 / 10 : ℝ) ^ m := - pow_le_pow_of_le_one (by norm_num) (by norm_num) hcount - have hz := prefix_one_step_bound (d + 1) (200 * (d + 2)) k e he f hf - have hestimate : - Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - expectedEnergy (d + 1) (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) - (200 * (d + 2))) ≤ - Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * - ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by - apply Real.sqrt_le_sqrt - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - exact henergy.trans (by linarith) - have hnext := ih (by omega) (Fin.init e) he0 (completeTest f) (completeTest_bound f hf) - rw [uniform_prefix_step k e he f] - have htri := abs_sub_le - (mean (fun ω : History (d + 2) (200 * (d + 2)) => f ((run (d + 2) (200 * (d + 2)) ω) ∘ e))) - (mean (fun ω : History (d + 2) (200 * (d + 2)) => completeTest f ((run (d + 2) (200 * (d + 2)) ω) ∘ Fin.init e))) - (mean (fun g : State (d + 2) => completeTest f (g ∘ Fin.init e))) - have hz' := hz.trans hestimate - push_cast - nlinarith - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.TaggedCompletion + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem prefix_one_step_bound (d t k : ℕ) (e : Fin (k + 1) → Position (d + 1)) + (he : Function.Injective e) (f : (Fin (k + 1) → Position (d + 1)) → ℝ) + (hf : ∀ z, |f z| ≤ 1) : + |mean (fun ω : History (d + 1) t => f ((run (d + 1) t ω) ∘ e)) - + mean (fun ω : History (d + 1) t => completeTest f ((run (d + 1) t ω) ∘ Fin.init e))| ≤ + Real.sqrt ((Fintype.card (Position (d + 1)) : ℝ) * + expectedEnergy d (initialState (d + 1) (freeOf (Fin.init e)) (e (Fin.last k)) + (by + apply (freeOf_true _ _).mpr + intro i hi + exact Fin.castSucc_ne_last i (he hi))) t) := by + 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) + have hh := tagged_deviation_bound d (freeOf (Fin.init e)) (e (Fin.last k)) ht + (Fin.init e) (freeOf_exposed _) t (fun z y => f (Fin.snoc z y)) (fun z y => hf _) + convert hh using 1 + congr 1 + rw [← mean_sub] + apply mean_congr + intro ω + rw [← Fin.comp_snoc, Fin.snoc_init_self] + unfold completeTest + rw [freeCount_perm] + simp only [freeOf_perm] + +theorem uniform_prefix_step {α : Type uα} [Fintype α] [DecidableEq α] + (k : ℕ) (e : Fin (k + 1) → α) (he : Function.Injective e) + (f : (Fin (k + 1) → α) → ℝ) : + mean (fun g : Equiv.Perm α => f (g ∘ e)) = + mean (fun g : Equiv.Perm α => completeTest f (g ∘ Fin.init e)) := by + 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) + have h := uniform_tagged_completion (Fin.init e) (e (Fin.last k)) ht + (fun z y => f (Fin.snoc z y)) + simpa only [← Fin.comp_snoc, Fin.snoc_init_self, completeTest, freeCount_perm] using h + +theorem prefix_test_bound (d m : ℕ) + (hm : Fintype.card (Position (d + 2)) ≤ 8 * m) + (k : ℕ) (hk : k + m ≤ Fintype.card (Position (d + 2))) + (e : Fin k → Position (d + 2)) (he : Function.Injective e) + (f : (Fin k → Position (d + 2)) → ℝ) (hf : ∀ z, |f z| ≤ 1) : + |mean (fun ω : History (d + 2) (200 * (d + 2)) => f ((run (d + 2) (200 * (d + 2)) ω) ∘ e)) - + mean (fun g : State (d + 2) => f (g ∘ e))| ≤ + (k : ℝ) * Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by + induction k with + | zero => + have hz (g : State (d + 2)) : g ∘ e = e := by funext i; exact Fin.elim0 i + simp only [hz, mean_const, sub_self, abs_zero, Nat.cast_zero, zero_mul, le_refl] + | 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) + have hcount : m ≤ freeCount (freeOf (Fin.init e)) := by + rw [freeCount_freeOf _ he0] + omega + have henergy := centeredPoint_energy_200 d (freeOf (Fin.init e)) (e (Fin.last k)) ht (by omega) + have hpower : (9 / 10 : ℝ) ^ freeCount (freeOf (Fin.init e)) ≤ (9 / 10 : ℝ) ^ m := + pow_le_pow_of_le_one (by norm_num) (by norm_num) hcount + have hz := prefix_one_step_bound (d + 1) (200 * (d + 2)) k e he f hf + have hestimate : + Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + expectedEnergy (d + 1) (initialState (d + 2) (freeOf (Fin.init e)) (e (Fin.last k)) ht) + (200 * (d + 2))) ≤ + Real.sqrt ((Fintype.card (Position (d + 2)) : ℝ) * + ((1 / 2 : ℝ) ^ (8 * (d + 2)) + 32 * (9 / 10 : ℝ) ^ m)) := by + apply Real.sqrt_le_sqrt + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + exact henergy.trans (by linarith) + have hnext := ih (by omega) (Fin.init e) he0 (completeTest f) (completeTest_bound f hf) + rw [uniform_prefix_step k e he f] + have htri := abs_sub_le + (mean (fun ω : History (d + 2) (200 * (d + 2)) => f ((run (d + 2) (200 * (d + 2)) ω) ∘ e))) + (mean (fun ω : History (d + 2) (200 * (d + 2)) => completeTest f ((run (d + 2) (200 * (d + 2)) ω) ∘ Fin.init e))) + (mean (fun g : State (d + 2) => completeTest f (g ∘ Fin.init e))) + have hz' := hz.trans hestimate + push_cast + nlinarith + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ProductProjectors.lean b/lean/OAI/Probability/ThorpShuffle/ProductProjectors.lean index e077164d23a875a473dab585e0d7c9ccf27b9480..e39d80f63414cf42e84672e2cae5391d886bf53c 100644 --- a/lean/OAI/Probability/ThorpShuffle/ProductProjectors.lean +++ b/lean/OAI/Probability/ThorpShuffle/ProductProjectors.lean @@ -1,193 +1,193 @@ -import OAI.Probability.ThorpShuffle.JointProjectors - -namespace OAI - -universe uH uI uE uJ - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Fourier -open scoped Classical -variable {H : Type uH} {I : Type uI} {E : Type uE} [Group H] [Fintype H] [Fintype I] [AddCommGroup E] [Module ℂ E] - -lemma integrated_single_mul (ρ : Representation ℂ (I → H) E) (i : I) (k : H → ℂ) (f : (I → H) → ℂ) : - integrated (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) k * integrated ρ f = - integrated ρ (fun g => ∑ h, k h * f (Pi.mulSingle i h⁻¹ * g)) := by - simp only [integrated, Finset.sum_mul, Finset.mul_sum, Finset.sum_smul] - conv_rhs => rw [Finset.sum_comm] - conv_lhs => rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro h _ - have he := Equiv.sum_comp (Equiv.mulLeft (Pi.mulSingle i h)) - (fun g : I → H => (k h * f (Pi.mulSingle i h⁻¹ * g)) • ρ g) - rw [← he] - apply Finset.sum_congr rfl - intro g _ - have hi : Pi.mulSingle i h⁻¹ = (Pi.mulSingle i h : I → H)⁻¹ := - (map_inv (MonoidHom.mulSingle (fun _ : I => H) i) h).symm.symm - simp only [Equiv.coe_mulLeft, hi, inv_mul_cancel_left, smul_mul_smul, - MonoidHom.comp_apply, MonoidHom.mulSingle_apply, map_mul] - -end Thorp.Fourier - -namespace Thorp.Fourier.Family -open scoped Classical -variable {H : Type} [Group H] [Fintype H] (F : Family H) -variable {I : Type} [Fintype I] - -lemma jointKernel_single (a : I → F.Index) (i : I) (h : H) (g : I → H) : - F.jointKernel a (Pi.mulSingle i h * g) = - F.kernel (a i) (h * g i) * ∏ j ∈ Finset.univ.erase i, F.kernel (a j) (g j) := by - rw [jointKernel, ← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] - simp only [Pi.mul_apply, Pi.mulSingle_eq_same] - congr 1 - apply Finset.prod_congr rfl - intro j hj - have hji := (Finset.mem_erase.mp hj).1 - simp only [Pi.mulSingle_eq_of_ne hji, one_mul] - -lemma jointKernel_split (a : I → F.Index) (i : I) (g : I → H) : - F.jointKernel a g = F.kernel (a i) (g i) * ∏ j ∈ Finset.univ.erase i, F.kernel (a j) (g j) := - (Finset.mul_prod_erase Finset.univ (fun j => F.kernel (a j) (g j)) (Finset.mem_univ i)).symm - -lemma jointKernel_single_convolution (a : I → F.Index) (i : I) (b : F.Index) (g : I → H) : - ∑ h, F.kernel b h * F.jointKernel a (Pi.mulSingle i h⁻¹ * g) = - if b = a i then F.jointKernel a g else 0 := by - simp only [F.jointKernel_single, ← mul_assoc, ← Finset.sum_mul] - change convolution (F.kernel b) (F.kernel (a i)) (g i) * _ = _ - rw [F.kernel_convolution] - split_ifs with hb - · simp only [hb] - exact (F.jointKernel_split a i g).symm - · simp - -variable {E : Type uE} [AddCommGroup E] [Module ℂ E] - -lemma projector_jointProjector (ρ : Representation ℂ (I → H) E) (a : I → F.Index) - (i : I) (b : F.Index) : - F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b * F.jointProjector ρ a = - if b = a i then F.jointProjector ρ a else 0 := by - rw [projector, jointProjector, integrated_single_mul] - simp only [F.jointKernel_single_convolution] - split_ifs <;> simp only [integrated, zero_smul, Finset.sum_const_zero] - -lemma low_fixes_joint (ρ : Representation ℂ (I → H) E) (a : I → F.Index) - (i : I) (s : Finset F.Index) (ha : a i ∈ s) : - (∑ b ∈ s, F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b) * F.jointProjector ρ a = - F.jointProjector ρ a := by - rw [Finset.sum_mul] - simp only [F.projector_jointProjector, Finset.sum_ite_eq', ha, ↓reduceIte] - -end Thorp.Fourier.Family - -namespace Thorp.Fourier -open scoped Classical - -lemma norm_sum_sq_of_orthogonal {J : Type uJ} {E : Type uE} [Fintype J] - [NormedAddCommGroup E] [InnerProductSpace ℂ E] (v : J → E) - (hv : ∀ i j, i ≠ j → ⟪v i, v j⟫_ℂ = 0) : - ‖∑ i, v i‖ ^ 2 = ∑ i, ‖v i‖ ^ 2 := by - have he : ⟪∑ i, v i, ∑ i, v i⟫_ℂ = ∑ i, ⟪v i, v i⟫_ℂ := by - simp only [sum_inner, inner_sum] - apply Finset.sum_congr rfl - intro i _ - exact Finset.sum_eq_single i (fun j _ hji => hv j i hji) (by simp) - have hr := congrArg Complex.re he - simpa only [inner_self_eq_norm_sq_to_K, RCLike.ofReal_eq_complex_ofReal, ← Complex.ofReal_pow, - ← Complex.ofReal_sum, Complex.ofReal_re] using hr - -namespace Family -variable {H I : Type} [Group H] [Fintype H] [Fintype I] [Nonempty I] (F : Family H) - -noncomputable def leastFactor (a : I → F.Index) : I := - Classical.choose (Finset.exists_min_image Finset.univ (fun i => F.degree (a i)) Finset.univ_nonempty) - -lemma leastFactor_le (a : I → F.Index) (i : I) : - F.degree (a (F.leastFactor a)) ≤ F.degree (a i) := - (Classical.choose_spec (Finset.exists_min_image Finset.univ - (fun i => F.degree (a i)) Finset.univ_nonempty)).2 i (Finset.mem_univ i) - -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -omit [Nonempty I] [FiniteDimensional ℂ E] in -lemma jointProjector_symmetric (ρ : Representation ℂ (I → H) E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (a : I → F.Index) : - (F.jointProjector ρ a).IsSymmetric := integrated_symmetric ρ hu _ (F.jointKernel_star a) - -omit [Nonempty I] [FiniteDimensional ℂ E] in -lemma jointProjector_orthogonal (ρ : Representation ℂ (I → H) E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (a b : I → F.Index) (hab : a ≠ b) (x y : E) : - ⟪F.jointProjector ρ a x, F.jointProjector ρ b y⟫_ℂ = 0 := by - rw [F.jointProjector_symmetric ρ hu a] - change ⟪x, (F.jointProjector ρ a * F.jointProjector ρ b) y⟫_ℂ = 0 - rw [F.jointProjector_mul, ite_eq_right hab] - simp - -noncomputable def splitVector (ρ : Representation ℂ (I → H) E) (v : E) (i : I) : E := - ∑ a : I → F.Index, if F.leastFactor a = i then F.jointProjector ρ a v else 0 - -omit [FiniteDimensional ℂ E] in -lemma splitVector_sum (ρ : Representation ℂ (I → H) E) (v : E) : - ∑ i, F.splitVector ρ v i = v := by - simp only [splitVector] - rw [Finset.sum_comm] - simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] - rw [← LinearMap.sum_apply, F.jointProjector_sum] - rfl - -omit [FiniteDimensional ℂ E] in -lemma splitVector_orthogonal (ρ : Representation ℂ (I → H) E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (v : E) (i j : I) (hij : i ≠ j) : - ⟪F.splitVector ρ v i, F.splitVector ρ v j⟫_ℂ = 0 := by - simp only [splitVector, sum_inner, inner_sum] - apply Finset.sum_eq_zero - intro a _ - apply Finset.sum_eq_zero - intro b _ - split_ifs with hai hbj - · exact F.jointProjector_orthogonal ρ hu b a (by intro h; subst b; exact hij (hai.symm.trans hbj)) v v - all_goals simp - -omit [FiniteDimensional ℂ E] in -lemma splitVector_sq_sum (ρ : Representation ℂ (I → H) E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (v : E) : - ∑ i, ‖F.splitVector ρ v i‖ ^ 2 = ‖v‖ ^ 2 := by - rw [← norm_sum_sq_of_orthogonal _ (F.splitVector_orthogonal ρ hu v), F.splitVector_sum] - -lemma leastFactor_pow_le (ρ : Representation ℂ (I → H) E) - (a : I → F.Index) (ha : F.jointProjector ρ a ≠ 0) : - F.degree (a (F.leastFactor a)) ^ Fintype.card I ≤ Module.finrank ℂ E := by - calc - _ = ∏ _ : I, F.degree (a (F.leastFactor a)) := by simp - _ ≤ ∏ i, F.degree (a i) := Finset.prod_le_prod (fun i _ => F.leastFactor_le a i) - _ ≤ _ := F.joint_degree_le ρ a ha - -lemma splitVector_low (ρ : Representation ℂ (I → H) E) (v : E) (i : I) : - (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), - F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b) (F.splitVector ρ v i) = - F.splitVector ρ v i := by - unfold splitVector - rw [map_sum] - apply Finset.sum_congr rfl - intro a _ - by_cases hai : F.leastFactor a = i - · simp only [ite_eq_left hai] - by_cases ha : F.jointProjector ρ a = 0 - · simp [ha] - · have hb : a i ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E) := by - simp only [Finset.mem_filter, Finset.mem_univ, true_and] - simpa only [hai] using F.leastFactor_pow_le ρ a ha - exact congrArg (fun f : Module.End ℂ E => f v) (F.low_fixes_joint ρ a i _ hb) - · simp [hai] - -end Family -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.JointProjectors + +namespace OAI + +universe uH uI uE uJ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Fourier +open scoped Classical +variable {H : Type uH} {I : Type uI} {E : Type uE} [Group H] [Fintype H] [Fintype I] [AddCommGroup E] [Module ℂ E] + +lemma integrated_single_mul (ρ : Representation ℂ (I → H) E) (i : I) (k : H → ℂ) (f : (I → H) → ℂ) : + integrated (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) k * integrated ρ f = + integrated ρ (fun g => ∑ h, k h * f (Pi.mulSingle i h⁻¹ * g)) := by + simp only [integrated, Finset.sum_mul, Finset.mul_sum, Finset.sum_smul] + conv_rhs => rw [Finset.sum_comm] + conv_lhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro h _ + have he := Equiv.sum_comp (Equiv.mulLeft (Pi.mulSingle i h)) + (fun g : I → H => (k h * f (Pi.mulSingle i h⁻¹ * g)) • ρ g) + rw [← he] + apply Finset.sum_congr rfl + intro g _ + have hi : Pi.mulSingle i h⁻¹ = (Pi.mulSingle i h : I → H)⁻¹ := + (map_inv (MonoidHom.mulSingle (fun _ : I => H) i) h).symm.symm + simp only [Equiv.coe_mulLeft, hi, inv_mul_cancel_left, smul_mul_smul, + MonoidHom.comp_apply, MonoidHom.mulSingle_apply, map_mul] + +end Thorp.Fourier + +namespace Thorp.Fourier.Family +open scoped Classical +variable {H : Type} [Group H] [Fintype H] (F : Family H) +variable {I : Type} [Fintype I] + +lemma jointKernel_single (a : I → F.Index) (i : I) (h : H) (g : I → H) : + F.jointKernel a (Pi.mulSingle i h * g) = + F.kernel (a i) (h * g i) * ∏ j ∈ Finset.univ.erase i, F.kernel (a j) (g j) := by + rw [jointKernel, ← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] + simp only [Pi.mul_apply, Pi.mulSingle_eq_same] + congr 1 + apply Finset.prod_congr rfl + intro j hj + have hji := (Finset.mem_erase.mp hj).1 + simp only [Pi.mulSingle_eq_of_ne hji, one_mul] + +lemma jointKernel_split (a : I → F.Index) (i : I) (g : I → H) : + F.jointKernel a g = F.kernel (a i) (g i) * ∏ j ∈ Finset.univ.erase i, F.kernel (a j) (g j) := + (Finset.mul_prod_erase Finset.univ (fun j => F.kernel (a j) (g j)) (Finset.mem_univ i)).symm + +lemma jointKernel_single_convolution (a : I → F.Index) (i : I) (b : F.Index) (g : I → H) : + ∑ h, F.kernel b h * F.jointKernel a (Pi.mulSingle i h⁻¹ * g) = + if b = a i then F.jointKernel a g else 0 := by + simp only [F.jointKernel_single, ← mul_assoc, ← Finset.sum_mul] + change convolution (F.kernel b) (F.kernel (a i)) (g i) * _ = _ + rw [F.kernel_convolution] + split_ifs with hb + · simp only [hb] + exact (F.jointKernel_split a i g).symm + · simp + +variable {E : Type uE} [AddCommGroup E] [Module ℂ E] + +lemma projector_jointProjector (ρ : Representation ℂ (I → H) E) (a : I → F.Index) + (i : I) (b : F.Index) : + F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b * F.jointProjector ρ a = + if b = a i then F.jointProjector ρ a else 0 := by + rw [projector, jointProjector, integrated_single_mul] + simp only [F.jointKernel_single_convolution] + split_ifs <;> simp only [integrated, zero_smul, Finset.sum_const_zero] + +lemma low_fixes_joint (ρ : Representation ℂ (I → H) E) (a : I → F.Index) + (i : I) (s : Finset F.Index) (ha : a i ∈ s) : + (∑ b ∈ s, F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b) * F.jointProjector ρ a = + F.jointProjector ρ a := by + rw [Finset.sum_mul] + simp only [F.projector_jointProjector, Finset.sum_ite_eq', ha, ↓reduceIte] + +end Thorp.Fourier.Family + +namespace Thorp.Fourier +open scoped Classical + +lemma norm_sum_sq_of_orthogonal {J : Type uJ} {E : Type uE} [Fintype J] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] (v : J → E) + (hv : ∀ i j, i ≠ j → ⟪v i, v j⟫_ℂ = 0) : + ‖∑ i, v i‖ ^ 2 = ∑ i, ‖v i‖ ^ 2 := by + have he : ⟪∑ i, v i, ∑ i, v i⟫_ℂ = ∑ i, ⟪v i, v i⟫_ℂ := by + simp only [sum_inner, inner_sum] + apply Finset.sum_congr rfl + intro i _ + exact Finset.sum_eq_single i (fun j _ hji => hv j i hji) (by simp) + have hr := congrArg Complex.re he + simpa only [inner_self_eq_norm_sq_to_K, RCLike.ofReal_eq_complex_ofReal, ← Complex.ofReal_pow, + ← Complex.ofReal_sum, Complex.ofReal_re] using hr + +namespace Family +variable {H I : Type} [Group H] [Fintype H] [Fintype I] [Nonempty I] (F : Family H) + +noncomputable def leastFactor (a : I → F.Index) : I := + Classical.choose (Finset.exists_min_image Finset.univ (fun i => F.degree (a i)) Finset.univ_nonempty) + +lemma leastFactor_le (a : I → F.Index) (i : I) : + F.degree (a (F.leastFactor a)) ≤ F.degree (a i) := + (Classical.choose_spec (Finset.exists_min_image Finset.univ + (fun i => F.degree (a i)) Finset.univ_nonempty)).2 i (Finset.mem_univ i) + +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [Nonempty I] [FiniteDimensional ℂ E] in +lemma jointProjector_symmetric (ρ : Representation ℂ (I → H) E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (a : I → F.Index) : + (F.jointProjector ρ a).IsSymmetric := integrated_symmetric ρ hu _ (F.jointKernel_star a) + +omit [Nonempty I] [FiniteDimensional ℂ E] in +lemma jointProjector_orthogonal (ρ : Representation ℂ (I → H) E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (a b : I → F.Index) (hab : a ≠ b) (x y : E) : + ⟪F.jointProjector ρ a x, F.jointProjector ρ b y⟫_ℂ = 0 := by + rw [F.jointProjector_symmetric ρ hu a] + change ⟪x, (F.jointProjector ρ a * F.jointProjector ρ b) y⟫_ℂ = 0 + rw [F.jointProjector_mul, ite_eq_right hab] + simp + +noncomputable def splitVector (ρ : Representation ℂ (I → H) E) (v : E) (i : I) : E := + ∑ a : I → F.Index, if F.leastFactor a = i then F.jointProjector ρ a v else 0 + +omit [FiniteDimensional ℂ E] in +lemma splitVector_sum (ρ : Representation ℂ (I → H) E) (v : E) : + ∑ i, F.splitVector ρ v i = v := by + simp only [splitVector] + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] + rw [← LinearMap.sum_apply, F.jointProjector_sum] + rfl + +omit [FiniteDimensional ℂ E] in +lemma splitVector_orthogonal (ρ : Representation ℂ (I → H) E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (v : E) (i j : I) (hij : i ≠ j) : + ⟪F.splitVector ρ v i, F.splitVector ρ v j⟫_ℂ = 0 := by + simp only [splitVector, sum_inner, inner_sum] + apply Finset.sum_eq_zero + intro a _ + apply Finset.sum_eq_zero + intro b _ + split_ifs with hai hbj + · exact F.jointProjector_orthogonal ρ hu b a (by intro h; subst b; exact hij (hai.symm.trans hbj)) v v + all_goals simp + +omit [FiniteDimensional ℂ E] in +lemma splitVector_sq_sum (ρ : Representation ℂ (I → H) E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (v : E) : + ∑ i, ‖F.splitVector ρ v i‖ ^ 2 = ‖v‖ ^ 2 := by + rw [← norm_sum_sq_of_orthogonal _ (F.splitVector_orthogonal ρ hu v), F.splitVector_sum] + +lemma leastFactor_pow_le (ρ : Representation ℂ (I → H) E) + (a : I → F.Index) (ha : F.jointProjector ρ a ≠ 0) : + F.degree (a (F.leastFactor a)) ^ Fintype.card I ≤ Module.finrank ℂ E := by + calc + _ = ∏ _ : I, F.degree (a (F.leastFactor a)) := by simp + _ ≤ ∏ i, F.degree (a i) := Finset.prod_le_prod (fun i _ => F.leastFactor_le a i) + _ ≤ _ := F.joint_degree_le ρ a ha + +lemma splitVector_low (ρ : Representation ℂ (I → H) E) (v : E) (i : I) : + (∑ b ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E), + F.projector (ρ.comp (MonoidHom.mulSingle (fun _ : I => H) i)) b) (F.splitVector ρ v i) = + F.splitVector ρ v i := by + unfold splitVector + rw [map_sum] + apply Finset.sum_congr rfl + intro a _ + by_cases hai : F.leastFactor a = i + · simp only [ite_eq_left hai] + by_cases ha : F.jointProjector ρ a = 0 + · simp [ha] + · have hb : a i ∈ Finset.univ.filter (fun b => F.degree b ^ Fintype.card I ≤ Module.finrank ℂ E) := by + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + simpa only [hai] using F.leastFactor_pow_le ρ a ha + exact congrArg (fun f : Module.End ℂ E => f v) (F.low_fixes_joint ρ a i _ hb) + · simp [hai] + +end Family +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Reachability.lean b/lean/OAI/Probability/ThorpShuffle/Reachability.lean index 47591790909e0eb93ea8fef8768907cdd72ae3b1..e0cbd3f0931d90520d794a70b271b28b8ca4913f 100644 --- a/lean/OAI/Probability/ThorpShuffle/Reachability.lean +++ b/lean/OAI/Probability/ThorpShuffle/Reachability.lean @@ -1,224 +1,224 @@ -import OAI.Probability.ThorpShuffle.MarginalBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Reachability -open Conditional - -theorem run_append (d s t : ℕ) (a : History d s) (b : History d t) : - run d (s + t) (Fin.append a b) = run d t b * run d s a := by - induction t with - | zero => - have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i - rw [hz, run_zero, one_mul] - rfl - | succ t ih => - obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins d)).surjective b - erw [Fin.append_snoc, run_snoc, run_snoc, ih, mul_assoc] - -def zeroCoins (d : ℕ) : Coins (d + 1) := fun _ => false - -theorem step_false (d : ℕ) : step (d + 1) (zeroCoins d) = rotate (d + 1) := by - ext x i - simp only [step, Equiv.trans_apply, Fin.consEquiv_symm_apply, pairSwitch, zeroCoins, Bool.xor_false] - change (rotate (d + 1)) (Fin.cons (x 0) (Fin.tail x)) i = _ - rw [Fin.cons_self_tail] - -theorem run_false (d t : ℕ) : - run (d + 1) t (fun _ => zeroCoins d) = rotate (d + 1) ^ t := by - induction t with - | zero => simp - | succ t ih => - rw [run_succ] - change step (d + 1) (zeroCoins d) * run (d + 1) t (fun _ => zeroCoins d) = _ - rw [step_false, ih, pow_succ'] - -def returnMonoid (d : ℕ) : Submonoid (State (d + 1)) where - carrier := {g | ∃ t, orderOf (rotate (d + 1)) ∣ t ∧ ∃ ω : History (d + 1) t, run (d + 1) t ω = g} - one_mem' := ⟨0, dvd_zero _, fun i => i.elim0, run_zero _ _⟩ - mul_mem' := by - rintro g h ⟨s, hs, a, rfl⟩ ⟨t, ht, b, rfl⟩ - exact ⟨t + s, dvd_add ht hs, Fin.append b a, run_append _ _ _ _ _⟩ - -def returnGroup (d : ℕ) : Subgroup (State (d + 1)) := - Subgroup.closure (returnMonoid d : Set (State (d + 1))) - -@[simp] theorem mem_returnGroup (d : ℕ) (g : State (d + 1)) : - g ∈ returnGroup d ↔ g ∈ returnMonoid d := by - change g ∈ (Subgroup.closure (returnMonoid d : Set (State (d + 1)))).toSubmonoid ↔ _ - rw [Subgroup.closure_toSubmonoid_of_finite, Submonoid.closure_eq] - -theorem rotate_inv_pow (d : ℕ) : - rotate (d + 1) ^ (orderOf (rotate (d + 1)) - 1) = (rotate (d + 1))⁻¹ := by - apply eq_inv_iff_mul_eq_one.mpr - rw [← pow_succ, Nat.sub_add_cancel (orderOf_pos _), pow_orderOf_eq_one] - -theorem inverse_conj_mem (d : ℕ) {g : State (d + 1)} (hg : g ∈ returnGroup d) : - (rotate (d + 1))⁻¹ * g * rotate (d + 1) ∈ returnGroup d := by - rw [mem_returnGroup] at hg ⊢ - rcases hg with ⟨t, ht, ω, rfl⟩ - refine ⟨(1 + t) + (orderOf (rotate (d + 1)) - 1), ?_, - Fin.append (Fin.append (fun _ => zeroCoins d) ω) (fun _ => zeroCoins d), ?_⟩ - · have hp := orderOf_pos (rotate (d + 1)) - have he : (1 + t) + (orderOf (rotate (d + 1)) - 1) = t + orderOf (rotate (d + 1)) := by omega - rw [he]; exact dvd_add ht (dvd_refl _) - · rw [run_append, run_append, run_false, run_false, pow_one, rotate_inv_pow, mul_assoc] - -theorem inverse_conj_pow_mem (d t : ℕ) {g : State (d + 1)} (hg : g ∈ returnGroup d) : - (rotate (d + 1) ^ t)⁻¹ * g * rotate (d + 1) ^ t ∈ returnGroup d := by - induction t with - | zero => simpa using hg - | succ t ih => - have h := inverse_conj_mem d ih - simpa only [pow_succ, mul_inv_rev, mul_assoc] using h - -theorem canceled_step_mem (d : ℕ) (c : Coins (d + 1)) : - (rotate (d + 1))⁻¹ * step (d + 1) c ∈ returnGroup d := by - rw [mem_returnGroup] - refine ⟨1 + (orderOf (rotate (d + 1)) - 1), ?_, - Fin.append (fun _ => c) (fun _ => zeroCoins d), ?_⟩ - · rw [Nat.add_sub_of_le (orderOf_pos _)] - · rw [run_append, run_false, rotate_inv_pow, run_succ, run_zero, mul_one] - -end Reachability - -namespace Reachability -open Conditional - -theorem first_pair_swap (d : ℕ) (s : Position d) : - (rotate (d + 1))⁻¹ * step (d + 1) (fun x => decide (x = s)) = - Equiv.swap (Fin.cons false s) (Fin.cons true s) := by - classical - apply Equiv.Perm.ext - intro x - obtain ⟨⟨b, t⟩, rfl⟩ := (splitPosition d).symm.surjective x - have hc : ((rotate (d + 1))⁻¹ * step (d + 1) (fun x => decide (x = s))) - ((splitPosition d).symm (b, t)) = - (splitPosition d).symm (b ^^ decide (t = s), t) := by - simp [step, splitPosition, pairSwitch] - rw [hc] - change (Fin.cons (b ^^ decide (t = s)) t : Position (d + 1)) = - Equiv.swap (Fin.cons false s) (Fin.cons true s) (Fin.cons b t) - by_cases ht : t = s - · subst t; cases b <;> simp - · have hf : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons false s := by - intro h; apply ht; simpa using congrArg Fin.tail h - have htr : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons true s := by - intro h; apply ht; simpa using congrArg Fin.tail h - simp [ht, Equiv.swap_apply_of_ne_of_ne hf htr] - -theorem first_pair_mem (d : ℕ) (s : Position d) : - Equiv.swap (Fin.cons false s) (Fin.cons true s) ∈ returnGroup d := by - classical - rw [← first_pair_swap] - exact canceled_step_mem d _ - -theorem first_edge_mem (d : ℕ) (x y : Position (d + 1)) - (h : Fin.tail x = Fin.tail y) : Equiv.swap x y ∈ returnGroup d := by - classical - rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y] - rw [h] - cases hx : x 0 <;> cases hy : y 0 - · simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem - · exact first_pair_mem d _ - · rw [Equiv.swap_comm]; exact first_pair_mem d _ - · simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem - -theorem rotate_pow_apply (d t : ℕ) (x : Position d) (j : Fin d) : - (rotate d ^ t) x j = x ((finRotate d ^ t) j) := by - induction t generalizing j with - | zero => rfl - | succ t ih => - rw [pow_succ', Equiv.Perm.mul_apply] - simp only [rotate, Equiv.piCongrLeft_apply, Equiv.symm_symm] at * - simp only [ih, pow_succ, Equiv.Perm.mul_apply] - simp - -theorem finRotate_pow_zero (d : ℕ) (i : Fin (d + 1)) : - (finRotate (d + 1) ^ i.val) 0 = i := by - rw [Equiv.Perm.coe_pow, ← finCycle_eq_finRotate_iterate] - simp - -theorem edge_swap_mem (d : ℕ) (i : Fin (d + 1)) (x y : Position (d + 1)) - (h : ∀ j, j ≠ i → x j = y j) : Equiv.swap x y ∈ returnGroup d := by - classical - have ht : Fin.tail ((rotate (d + 1) ^ i.val) x) = - Fin.tail ((rotate (d + 1) ^ i.val) y) := by - funext j - simp only [Fin.tail, rotate_pow_apply] - apply h - intro he - have hz : j.succ = 0 := (finRotate (d + 1) ^ i.val).injective - (he.trans (finRotate_pow_zero d i).symm) - exact Fin.succ_ne_zero j hz - have hm := inverse_conj_pow_mem d i.val (first_edge_mem d _ _ ht) - rw [Equiv.mul_swap_eq_swap_mul, mul_assoc, inv_mul_cancel, mul_one] at hm - simpa using hm - -theorem cube_connected (d : ℕ) (R : Position d → Position d → Prop) - (hrefl : ∀ x, R x x) (htrans : ∀ x y z, R x y → R y z → R x z) - (hedge : ∀ (i : Fin d) x y, (∀ j, j ≠ i → x j = y j) → R x y) - (x y : Position d) : R x y := by - induction d with - | zero => have : x = y := Subsingleton.elim _ _; subst y; exact hrefl x - | succ d ih => - let z : Position (d + 1) := Fin.cons (y 0) (Fin.tail x) - apply htrans x z y - · apply hedge 0 - intro j hj - obtain ⟨j, rfl⟩ := Fin.eq_succ_of_ne_zero hj - rfl - · have hh := ih (fun a b => R (Fin.cons (y 0) a) (Fin.cons (y 0) b)) - (fun a => hrefl _) (fun a b c hab hbc => htrans _ _ _ hab hbc) - (fun i a b hab => hedge i.succ _ _ (by - intro j - refine Fin.cases (fun _ => rfl) (fun j hj => ?_) j - exact hab j (by intro he; subst j; exact hj rfl))) - (Fin.tail x) (Fin.tail y) - simpa only [Fin.cons_self_tail] using hh - -theorem all_swap_mem (d : ℕ) (x y : Position (d + 1)) : - Equiv.swap x y ∈ returnGroup d := by - classical - apply cube_connected (d + 1) (fun x y => Equiv.swap x y ∈ returnGroup d) - (fun x => by simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem) ?_ (edge_swap_mem d) x y - intro a b c hab hbc - by_cases hac : a = c - · subst c; simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem - by_cases hab' : a = b - · subst b; exact hbc - by_cases hbc' : b = c - · subst c; exact hab - have hh := (returnGroup d).mul_mem ((returnGroup d).mul_mem hab hbc) hab - rw [Equiv.mul_swap_eq_swap_mul (Equiv.swap a b) b c, Equiv.swap_apply_right, - Equiv.swap_apply_of_ne_of_ne (Ne.symm hac) (Ne.symm hbc'), - mul_assoc, Equiv.swap_mul_self, mul_one] at hh - exact hh - -theorem returnGroup_eq_top (d : ℕ) : returnGroup d = ⊤ := by - apply top_unique - intro g hg - clear hg - induction g using Equiv.Perm.swap_induction_on with - | one => exact (returnGroup d).one_mem - | swap_mul g x y _ hg => exact (returnGroup d).mul_mem (all_swap_mem d x y) hg - -theorem attainable_return (d : ℕ) (g : State (d + 1)) : - ∃ t, orderOf (rotate (d + 1)) ∣ t ∧ ∃ ω : History (d + 1) t, run (d + 1) t ω = g := by - have hg : g ∈ returnGroup d := by rw [returnGroup_eq_top]; trivial - rwa [mem_returnGroup] at hg - -end Reachability - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.MarginalBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Reachability +open Conditional + +theorem run_append (d s t : ℕ) (a : History d s) (b : History d t) : + run d (s + t) (Fin.append a b) = run d t b * run d s a := by + induction t with + | zero => + have hz : Fin.append a b = a := by funext i; exact Fin.append_left a b i + rw [hz, run_zero, one_mul] + rfl + | succ t ih => + obtain ⟨⟨c, b⟩, rfl⟩ := (Fin.snocEquiv (fun _ : Fin (t + 1) => Coins d)).surjective b + erw [Fin.append_snoc, run_snoc, run_snoc, ih, mul_assoc] + +def zeroCoins (d : ℕ) : Coins (d + 1) := fun _ => false + +theorem step_false (d : ℕ) : step (d + 1) (zeroCoins d) = rotate (d + 1) := by + ext x i + simp only [step, Equiv.trans_apply, Fin.consEquiv_symm_apply, pairSwitch, zeroCoins, Bool.xor_false] + change (rotate (d + 1)) (Fin.cons (x 0) (Fin.tail x)) i = _ + rw [Fin.cons_self_tail] + +theorem run_false (d t : ℕ) : + run (d + 1) t (fun _ => zeroCoins d) = rotate (d + 1) ^ t := by + induction t with + | zero => simp + | succ t ih => + rw [run_succ] + change step (d + 1) (zeroCoins d) * run (d + 1) t (fun _ => zeroCoins d) = _ + rw [step_false, ih, pow_succ'] + +def returnMonoid (d : ℕ) : Submonoid (State (d + 1)) where + carrier := {g | ∃ t, orderOf (rotate (d + 1)) ∣ t ∧ ∃ ω : History (d + 1) t, run (d + 1) t ω = g} + one_mem' := ⟨0, dvd_zero _, fun i => i.elim0, run_zero _ _⟩ + mul_mem' := by + rintro g h ⟨s, hs, a, rfl⟩ ⟨t, ht, b, rfl⟩ + exact ⟨t + s, dvd_add ht hs, Fin.append b a, run_append _ _ _ _ _⟩ + +def returnGroup (d : ℕ) : Subgroup (State (d + 1)) := + Subgroup.closure (returnMonoid d : Set (State (d + 1))) + +@[simp] theorem mem_returnGroup (d : ℕ) (g : State (d + 1)) : + g ∈ returnGroup d ↔ g ∈ returnMonoid d := by + change g ∈ (Subgroup.closure (returnMonoid d : Set (State (d + 1)))).toSubmonoid ↔ _ + rw [Subgroup.closure_toSubmonoid_of_finite, Submonoid.closure_eq] + +theorem rotate_inv_pow (d : ℕ) : + rotate (d + 1) ^ (orderOf (rotate (d + 1)) - 1) = (rotate (d + 1))⁻¹ := by + apply eq_inv_iff_mul_eq_one.mpr + rw [← pow_succ, Nat.sub_add_cancel (orderOf_pos _), pow_orderOf_eq_one] + +theorem inverse_conj_mem (d : ℕ) {g : State (d + 1)} (hg : g ∈ returnGroup d) : + (rotate (d + 1))⁻¹ * g * rotate (d + 1) ∈ returnGroup d := by + rw [mem_returnGroup] at hg ⊢ + rcases hg with ⟨t, ht, ω, rfl⟩ + refine ⟨(1 + t) + (orderOf (rotate (d + 1)) - 1), ?_, + Fin.append (Fin.append (fun _ => zeroCoins d) ω) (fun _ => zeroCoins d), ?_⟩ + · have hp := orderOf_pos (rotate (d + 1)) + have he : (1 + t) + (orderOf (rotate (d + 1)) - 1) = t + orderOf (rotate (d + 1)) := by omega + rw [he]; exact dvd_add ht (dvd_refl _) + · rw [run_append, run_append, run_false, run_false, pow_one, rotate_inv_pow, mul_assoc] + +theorem inverse_conj_pow_mem (d t : ℕ) {g : State (d + 1)} (hg : g ∈ returnGroup d) : + (rotate (d + 1) ^ t)⁻¹ * g * rotate (d + 1) ^ t ∈ returnGroup d := by + induction t with + | zero => simpa using hg + | succ t ih => + have h := inverse_conj_mem d ih + simpa only [pow_succ, mul_inv_rev, mul_assoc] using h + +theorem canceled_step_mem (d : ℕ) (c : Coins (d + 1)) : + (rotate (d + 1))⁻¹ * step (d + 1) c ∈ returnGroup d := by + rw [mem_returnGroup] + refine ⟨1 + (orderOf (rotate (d + 1)) - 1), ?_, + Fin.append (fun _ => c) (fun _ => zeroCoins d), ?_⟩ + · rw [Nat.add_sub_of_le (orderOf_pos _)] + · rw [run_append, run_false, rotate_inv_pow, run_succ, run_zero, mul_one] + +end Reachability + +namespace Reachability +open Conditional + +theorem first_pair_swap (d : ℕ) (s : Position d) : + (rotate (d + 1))⁻¹ * step (d + 1) (fun x => decide (x = s)) = + Equiv.swap (Fin.cons false s) (Fin.cons true s) := by + classical + apply Equiv.Perm.ext + intro x + obtain ⟨⟨b, t⟩, rfl⟩ := (splitPosition d).symm.surjective x + have hc : ((rotate (d + 1))⁻¹ * step (d + 1) (fun x => decide (x = s))) + ((splitPosition d).symm (b, t)) = + (splitPosition d).symm (b ^^ decide (t = s), t) := by + simp [step, splitPosition, pairSwitch] + rw [hc] + change (Fin.cons (b ^^ decide (t = s)) t : Position (d + 1)) = + Equiv.swap (Fin.cons false s) (Fin.cons true s) (Fin.cons b t) + by_cases ht : t = s + · subst t; cases b <;> simp + · have hf : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons false s := by + intro h; apply ht; simpa using congrArg Fin.tail h + have htr : (Fin.cons b t : Position (d + 1)) ≠ Fin.cons true s := by + intro h; apply ht; simpa using congrArg Fin.tail h + simp [ht, Equiv.swap_apply_of_ne_of_ne hf htr] + +theorem first_pair_mem (d : ℕ) (s : Position d) : + Equiv.swap (Fin.cons false s) (Fin.cons true s) ∈ returnGroup d := by + classical + rw [← first_pair_swap] + exact canceled_step_mem d _ + +theorem first_edge_mem (d : ℕ) (x y : Position (d + 1)) + (h : Fin.tail x = Fin.tail y) : Equiv.swap x y ∈ returnGroup d := by + classical + rw [← Fin.cons_self_tail x, ← Fin.cons_self_tail y] + rw [h] + cases hx : x 0 <;> cases hy : y 0 + · simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem + · exact first_pair_mem d _ + · rw [Equiv.swap_comm]; exact first_pair_mem d _ + · simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem + +theorem rotate_pow_apply (d t : ℕ) (x : Position d) (j : Fin d) : + (rotate d ^ t) x j = x ((finRotate d ^ t) j) := by + induction t generalizing j with + | zero => rfl + | succ t ih => + rw [pow_succ', Equiv.Perm.mul_apply] + simp only [rotate, Equiv.piCongrLeft_apply, Equiv.symm_symm] at * + simp only [ih, pow_succ, Equiv.Perm.mul_apply] + simp + +theorem finRotate_pow_zero (d : ℕ) (i : Fin (d + 1)) : + (finRotate (d + 1) ^ i.val) 0 = i := by + rw [Equiv.Perm.coe_pow, ← finCycle_eq_finRotate_iterate] + simp + +theorem edge_swap_mem (d : ℕ) (i : Fin (d + 1)) (x y : Position (d + 1)) + (h : ∀ j, j ≠ i → x j = y j) : Equiv.swap x y ∈ returnGroup d := by + classical + have ht : Fin.tail ((rotate (d + 1) ^ i.val) x) = + Fin.tail ((rotate (d + 1) ^ i.val) y) := by + funext j + simp only [Fin.tail, rotate_pow_apply] + apply h + intro he + have hz : j.succ = 0 := (finRotate (d + 1) ^ i.val).injective + (he.trans (finRotate_pow_zero d i).symm) + exact Fin.succ_ne_zero j hz + have hm := inverse_conj_pow_mem d i.val (first_edge_mem d _ _ ht) + rw [Equiv.mul_swap_eq_swap_mul, mul_assoc, inv_mul_cancel, mul_one] at hm + simpa using hm + +theorem cube_connected (d : ℕ) (R : Position d → Position d → Prop) + (hrefl : ∀ x, R x x) (htrans : ∀ x y z, R x y → R y z → R x z) + (hedge : ∀ (i : Fin d) x y, (∀ j, j ≠ i → x j = y j) → R x y) + (x y : Position d) : R x y := by + induction d with + | zero => have : x = y := Subsingleton.elim _ _; subst y; exact hrefl x + | succ d ih => + let z : Position (d + 1) := Fin.cons (y 0) (Fin.tail x) + apply htrans x z y + · apply hedge 0 + intro j hj + obtain ⟨j, rfl⟩ := Fin.eq_succ_of_ne_zero hj + rfl + · have hh := ih (fun a b => R (Fin.cons (y 0) a) (Fin.cons (y 0) b)) + (fun a => hrefl _) (fun a b c hab hbc => htrans _ _ _ hab hbc) + (fun i a b hab => hedge i.succ _ _ (by + intro j + refine Fin.cases (fun _ => rfl) (fun j hj => ?_) j + exact hab j (by intro he; subst j; exact hj rfl))) + (Fin.tail x) (Fin.tail y) + simpa only [Fin.cons_self_tail] using hh + +theorem all_swap_mem (d : ℕ) (x y : Position (d + 1)) : + Equiv.swap x y ∈ returnGroup d := by + classical + apply cube_connected (d + 1) (fun x y => Equiv.swap x y ∈ returnGroup d) + (fun x => by simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem) ?_ (edge_swap_mem d) x y + intro a b c hab hbc + by_cases hac : a = c + · subst c; simpa only [Equiv.swap_self, Equiv.Perm.one_def] using (returnGroup d).one_mem + by_cases hab' : a = b + · subst b; exact hbc + by_cases hbc' : b = c + · subst c; exact hab + have hh := (returnGroup d).mul_mem ((returnGroup d).mul_mem hab hbc) hab + rw [Equiv.mul_swap_eq_swap_mul (Equiv.swap a b) b c, Equiv.swap_apply_right, + Equiv.swap_apply_of_ne_of_ne (Ne.symm hac) (Ne.symm hbc'), + mul_assoc, Equiv.swap_mul_self, mul_one] at hh + exact hh + +theorem returnGroup_eq_top (d : ℕ) : returnGroup d = ⊤ := by + apply top_unique + intro g hg + clear hg + induction g using Equiv.Perm.swap_induction_on with + | one => exact (returnGroup d).one_mem + | swap_mul g x y _ hg => exact (returnGroup d).mul_mem (all_swap_mem d x y) hg + +theorem attainable_return (d : ℕ) (g : State (d + 1)) : + ∃ t, orderOf (rotate (d + 1)) ∣ t ∧ ∃ ω : History (d + 1) t, run (d + 1) t ω = g := by + have hg : g ∈ returnGroup d := by rw [returnGroup_eq_top]; trivial + rwa [mem_returnGroup] at hg + +end Reachability + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/ReciprocalDegrees.lean b/lean/OAI/Probability/ThorpShuffle/ReciprocalDegrees.lean index 3ec3353387c3404e380cc2f35baa73e3db8f9772..ea9f7d66380c85dcb923af4da1de85a8d90b61e6 100644 --- a/lean/OAI/Probability/ThorpShuffle/ReciprocalDegrees.lean +++ b/lean/OAI/Probability/ThorpShuffle/ReciprocalDegrees.lean @@ -1,230 +1,230 @@ -import OAI.Probability.ThorpShuffle.DegreeBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -open Filter Topology - -namespace Thorp.Analysis - -lemma sqrt_log_small (c : ℝ) (hc : 0 < c) : - ∀ᶠ n : ℕ in atTop, Real.log (n + 1) ≤ c * Real.sqrt (n + 1) := by - have ht : Tendsto (fun n : ℕ => (n : ℝ) + 1) atTop atTop := tendsto_atTop_add_const_right atTop 1 tendsto_natCast_atTop_atTop - have h := (isLittleO_log_rpow_atTop (by norm_num : (0 : ℝ) < 1/2)).tendsto_div_nhds_zero.comp ht - have he := h.eventually (gt_mem_nhds hc) - filter_upwards [he] with n hn - dsimp only [Function.comp_apply] at hn - rw [← Real.sqrt_eq_rpow] at hn - exact ((div_lt_iff₀ (Real.sqrt_pos.mpr (by positivity))).mp hn).le - -lemma partition_exponential_decay : - Tendsto (fun n : ℕ => ((n : ℝ) + 1) ^ (2 * Nat.sqrt n) / (4 : ℝ) ^ (n / 16)) atTop (𝓝 0) := by - have hc : 0 < Real.log 4 / 256 := by positivity - have he := sqrt_log_small (Real.log 4 / 256) hc - have ht : Tendsto (fun n : ℕ => Real.exp (-(Real.log 4 / 64) * n)) atTop (𝓝 0) := by - apply Real.tendsto_exp_atBot.comp - exact tendsto_natCast_atTop_atTop.const_mul_atTop_of_neg (neg_neg_of_pos (by positivity)) - apply squeeze_zero' (Eventually.of_forall (fun n => by positivity)) _ ht - filter_upwards [he, eventually_ge_atTop 32] with n hn hn32 - have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast (show 1 ≤ n by omega) - have hs : (Nat.sqrt n : ℝ) ≤ Real.sqrt (n + 1) := by - apply Real.le_sqrt_of_sq_le - have hh : ((Nat.sqrt n : ℝ)^2) ≤ n := by exact_mod_cast (show (Nat.sqrt n)^2 ≤ n by simpa only [pow_two] using Nat.sqrt_le n) - linarith - have hdiv : (n : ℝ) / 32 ≤ (n / 16 : ℕ) := by - have hh : n ≤ 32 * (n / 16) := by omega - exact (div_le_iff₀ (by norm_num : (0 : ℝ) < 32)).mpr (by exact_mod_cast (by omega : n ≤ n / 16 * 32)) - have hp : 2 * (Nat.sqrt n : ℝ) * Real.log (n + 1) ≤ (Real.log 4 / 64) * n := by - have hl : 0 ≤ Real.log (n + 1) := Real.log_nonneg (by linarith) - have h₁ := mul_le_mul_of_nonneg_right hs hl - have h₂ := mul_le_mul_of_nonneg_left hn (Real.sqrt_nonneg ((n : ℝ) + 1)) - have hh := Real.sq_sqrt (by positivity : (0 : ℝ) ≤ n + 1) - have hc0 : 0 ≤ Real.log 4 / 256 := hc.le - have hsq : Real.sqrt (n + 1) * ((Real.log 4 / 256) * Real.sqrt (n + 1)) = (Real.log 4 / 256) * (n + 1) := by calc - _ = (Real.log 4 / 256) * (Real.sqrt (n + 1))^2 := by ring - _ = _ := by rw [hh] - rw [hsq] at h₂ - have h₃ := mul_le_mul_of_nonneg_left (show (n : ℝ) + 1 ≤ 2 * n by linarith) hc0 - linarith only [h₁, h₂, h₃] - have hq : -(Real.log 4 / 64) * n ≥ - (2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 4 := by - push_cast - have hh := mul_le_mul_of_nonneg_right hdiv (Real.log_nonneg (by norm_num : (1 : ℝ) ≤ 4)) - linarith - calc - _ = Real.exp ((2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 4) := by - rw [Real.exp_sub, Real.exp_nat_mul, Real.exp_nat_mul, Real.exp_log (by positivity), Real.exp_log (by norm_num : (0 : ℝ) < 4)] - _ ≤ _ := Real.exp_le_exp.mpr hq - -end Thorp.Analysis - -namespace Thorp.Specht -open scoped Classical -open Filter Topology Thorp.Young - -variable {n : ℕ} - -def inverseDegree (p : NShape n) : ℝ := ((degree p : ℝ)^2)⁻¹ - -def slice (n u : ℕ) : ℝ := ∑ p : {p : NShape n // defect p = u}, inverseDegree p.val - -def smallSlice (n u : ℕ) : ℝ := if 0 < u ∧ 4 * u ≤ n then slice n u else 0 - -def exceptionalReciprocalSum (n : ℕ) : ℝ := ∑ p : NShape n, if 0 < defect p then inverseDegree p else 0 - -lemma inverseDegree_nonneg (p : NShape n) : 0 ≤ inverseDegree p := by unfold inverseDegree; positivity -lemma slice_nonneg (n u : ℕ) : 0 ≤ slice n u := Finset.sum_nonneg (fun _ _ => inverseDegree_nonneg _) -lemma smallSlice_nonneg (n u : ℕ) : 0 ≤ smallSlice n u := by unfold smallSlice; split_ifs; exact slice_nonneg _ _; rfl - -lemma slice_bound (n u : ℕ) (K : ℝ) (hK : 0 < K) - (hk : ∀ p : NShape n, defect p = u → K ≤ degree p) : - slice n u ≤ (2 : ℝ)^(u+1) / K^2 := by - have hI (p : {p : NShape n // defect p = u}) : inverseDegree p.val ≤ (K^2)⁻¹ := by - apply inv_anti₀ (pow_pos hK 2) - exact pow_le_pow_left₀ hK.le (hk p.val p.property) 2 - calc - _ ≤ ∑ _ : {p : NShape n // defect p = u}, (K^2)⁻¹ := Finset.sum_le_sum (fun p _ => hI p) - _ = (Fintype.card {p : NShape n // defect p = u} : ℝ) * (K^2)⁻¹ := by simp - _ ≤ (2 : ℝ)^(u+1) * (K^2)⁻¹ := mul_le_mul_of_nonneg_right (by exact_mod_cast defect_card_bound n u) (by positivity) - _ = _ := rfl - -lemma smallSlice_bound (n u : ℕ) : smallSlice n u ≤ 2 * (2 / 9 : ℝ)^u := by - unfold smallSlice - split_ifs with h - · have hk : ∀ p : NShape n, defect p = u → (3 : ℝ)^u ≤ degree p := by - intro p hp - have hh := small_defect_degree p (by rw [hp]; exact h.2) - rw [hp] at hh - exact_mod_cast hh - have hh := slice_bound n u (3^u) (by positivity) hk - have he : (2 : ℝ)^(u+1) / (3^u)^2 = 2 * (2/9 :ℝ)^u := by - rw [pow_succ, div_pow] - have hp : ((3 : ℝ)^u) ^ 2 = 9^u := by rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num - rw [hp] - ring - exact hh.trans_eq he - · positivity - -lemma smallSlice_tendsto (u : ℕ) : Tendsto (fun n => smallSlice n u) atTop (𝓝 0) := by - by_cases hu : 0 < u - · have ht : Tendsto (fun n : ℕ => ((n - 2*u + 1 : ℕ) : ℝ)) atTop atTop := by - exact (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop).comp - ((tendsto_add_atTop_nat 1).comp (tendsto_sub_atTop_nat (2*u))) - have hi : Tendsto (fun n : ℕ => (((n - 2*u + 1 : ℕ) : ℝ)^2)⁻¹) atTop (𝓝 0) := by - apply tendsto_inv_atTop_zero.comp - simpa only [pow_two] using ht.atTop_mul_atTop₀ ht - have he := hi.const_mul ((2 : ℝ)^(u+1)) - rw [mul_zero] at he - apply squeeze_zero' (Eventually.of_forall (fun n => smallSlice_nonneg n u)) _ he - filter_upwards [eventually_ge_atTop (4*u)] with n hn - rw [smallSlice, ite_eq_left ⟨hu, hn⟩] - exact slice_bound n u _ (by positivity) (fun p hp => by - have hh := fixed_defect_degree p (by rwa [hp]) (by rw [hp]; omega) - rw [hp] at hh - exact_mod_cast hh) - · simp only [smallSlice, hu, false_and, ↓reduceIte] - exact tendsto_const_nhds - -lemma smallSum_tendsto : Tendsto (fun n => ∑' u, smallSlice n u) atTop (𝓝 0) := by - have hs : Summable (fun u : ℕ => 2 * (2/9 : ℝ)^u) := - (summable_geometric_of_norm_lt_one (by norm_num : ‖(2/9 : ℝ)‖ < 1)).mul_left 2 - have h := tendsto_tsum_of_dominated_convergence hs smallSlice_tendsto - (Eventually.of_forall (fun n u => by rw [Real.norm_of_nonneg (smallSlice_nonneg n u)]; exact smallSlice_bound n u)) - simpa only [tsum_zero] using h - -end Thorp.Specht - -namespace Thorp.Specht -open scoped Classical -open Filter Topology Thorp.Young - -lemma smallSlice_as_sum (n u : ℕ) : - smallSlice n u = ∑ p : NShape n, - if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0 := by - unfold smallSlice slice - rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = u)) (by simp), Finset.sum_filter] - by_cases h : 0 < u ∧ 4 * u ≤ n - · rw [ite_eq_left h] - apply Finset.sum_congr rfl - intro p _ - by_cases hp : defect p = u - · simp only [hp, h.1, h.2, true_and, ↓reduceIte] - · simp only [hp, false_and, ↓reduceIte] - · rw [ite_eq_right h] - apply Eq.symm - apply Finset.sum_eq_zero - intro p _ - split_ifs with hp - · exact (h (by simpa only [hp.1] using hp.2)).elim - · rfl - -lemma smallSlice_support (n u : ℕ) (hu : u ∉ Finset.range (n+1)) : smallSlice n u = 0 := by - unfold smallSlice - have hh : ¬(0 < u ∧ 4*u ≤ n) := by have := (Finset.mem_range.not.mp hu); omega - exact ite_eq_right hh - -lemma smallSum_eq (n : ℕ) : - (∑' u, smallSlice n u) = ∑ p : NShape n, - if 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0 := by - rw [tsum_eq_sum (smallSlice_support n)] - simp_rw [smallSlice_as_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro p _ - have hd : defect p ∈ Finset.range (n+1) := Finset.mem_range.mpr (by have := defect_add_longest p; omega) - have he (u : ℕ) : (if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0) = - if defect p = u then (if 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0) else 0 := by - split_ifs <;> tauto - simp only [he, Finset.sum_ite_eq, hd, ↓reduceIte] - -lemma bulkSum_bound (n : ℕ) (hn : 0 < n) : - (∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) ≤ - ((n : ℝ)+1)^(2*Nat.sqrt n) / (4:ℝ)^(n/16) := by - have hb (p : NShape n) : (if n < 4*defect p then inverseDegree p else 0) ≤ ((4:ℝ)^(n/16))⁻¹ := by - by_cases hp : n < 4*defect p - · rw [ite_eq_left hp] - have hh := bulk_degree p hn hp - have he : ((2 : ℝ)^(n/16))^2 = (4:ℝ)^(n/16) := by - rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num - apply inv_anti₀ (by positivity) - change (4:ℝ)^(n/16) ≤ (degree p : ℝ)^2 - rw [← he] - exact pow_le_pow_left₀ (by positivity) hh 2 - · rw [ite_eq_right hp]; positivity - have hc : Fintype.card (NShape n) ≤ (n+1)^(2*Nat.sqrt n) := by - rw [Fintype.card_eq_nat_card] - change Nat.card (Nat.Partition (Fintype.card (Fin n))) ≤ _ - rw [Fintype.card_fin, ← Fintype.card_eq_nat_card] - exact partition_count_le_sqrt_pow n - calc - _ ≤ ∑ _ : NShape n, ((4:ℝ)^(n/16))⁻¹ := Finset.sum_le_sum (fun p _ => hb p) - _ = (Fintype.card (NShape n) : ℝ) * ((4:ℝ)^(n/16))⁻¹ := by simp - _ ≤ ((n:ℝ)+1)^(2*Nat.sqrt n) * ((4:ℝ)^(n/16))⁻¹ := - mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (by positivity) - _ = _ := rfl - -lemma exceptionalReciprocalSum_split (n : ℕ) : exceptionalReciprocalSum n = - (∑' u, smallSlice n u) + (∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) := by - rw [smallSum_eq, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro p _ - split_ifs <;> simp_all - all_goals omega - -theorem exceptionalReciprocalSum_tendsto : Tendsto exceptionalReciprocalSum atTop (𝓝 0) := by - have hb : Tendsto (fun n => ∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) atTop (𝓝 0) := by - apply squeeze_zero' (Eventually.of_forall (fun n => Finset.sum_nonneg (fun p _ => by split_ifs; exact inverseDegree_nonneg p; rfl))) - ((eventually_gt_atTop 0).mono (fun n hn => bulkSum_bound n hn)) Thorp.Analysis.partition_exponential_decay - have he : exceptionalReciprocalSum = (fun n => (∑' u, smallSlice n u) + ∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) := funext exceptionalReciprocalSum_split - rw [he] - simpa only [zero_add] using smallSum_tendsto.add hb - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.DegreeBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +open Filter Topology + +namespace Thorp.Analysis + +lemma sqrt_log_small (c : ℝ) (hc : 0 < c) : + ∀ᶠ n : ℕ in atTop, Real.log (n + 1) ≤ c * Real.sqrt (n + 1) := by + have ht : Tendsto (fun n : ℕ => (n : ℝ) + 1) atTop atTop := tendsto_atTop_add_const_right atTop 1 tendsto_natCast_atTop_atTop + have h := (isLittleO_log_rpow_atTop (by norm_num : (0 : ℝ) < 1/2)).tendsto_div_nhds_zero.comp ht + have he := h.eventually (gt_mem_nhds hc) + filter_upwards [he] with n hn + dsimp only [Function.comp_apply] at hn + rw [← Real.sqrt_eq_rpow] at hn + exact ((div_lt_iff₀ (Real.sqrt_pos.mpr (by positivity))).mp hn).le + +lemma partition_exponential_decay : + Tendsto (fun n : ℕ => ((n : ℝ) + 1) ^ (2 * Nat.sqrt n) / (4 : ℝ) ^ (n / 16)) atTop (𝓝 0) := by + have hc : 0 < Real.log 4 / 256 := by positivity + have he := sqrt_log_small (Real.log 4 / 256) hc + have ht : Tendsto (fun n : ℕ => Real.exp (-(Real.log 4 / 64) * n)) atTop (𝓝 0) := by + apply Real.tendsto_exp_atBot.comp + exact tendsto_natCast_atTop_atTop.const_mul_atTop_of_neg (neg_neg_of_pos (by positivity)) + apply squeeze_zero' (Eventually.of_forall (fun n => by positivity)) _ ht + filter_upwards [he, eventually_ge_atTop 32] with n hn hn32 + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast (show 1 ≤ n by omega) + have hs : (Nat.sqrt n : ℝ) ≤ Real.sqrt (n + 1) := by + apply Real.le_sqrt_of_sq_le + have hh : ((Nat.sqrt n : ℝ)^2) ≤ n := by exact_mod_cast (show (Nat.sqrt n)^2 ≤ n by simpa only [pow_two] using Nat.sqrt_le n) + linarith + have hdiv : (n : ℝ) / 32 ≤ (n / 16 : ℕ) := by + have hh : n ≤ 32 * (n / 16) := by omega + exact (div_le_iff₀ (by norm_num : (0 : ℝ) < 32)).mpr (by exact_mod_cast (by omega : n ≤ n / 16 * 32)) + have hp : 2 * (Nat.sqrt n : ℝ) * Real.log (n + 1) ≤ (Real.log 4 / 64) * n := by + have hl : 0 ≤ Real.log (n + 1) := Real.log_nonneg (by linarith) + have h₁ := mul_le_mul_of_nonneg_right hs hl + have h₂ := mul_le_mul_of_nonneg_left hn (Real.sqrt_nonneg ((n : ℝ) + 1)) + have hh := Real.sq_sqrt (by positivity : (0 : ℝ) ≤ n + 1) + have hc0 : 0 ≤ Real.log 4 / 256 := hc.le + have hsq : Real.sqrt (n + 1) * ((Real.log 4 / 256) * Real.sqrt (n + 1)) = (Real.log 4 / 256) * (n + 1) := by calc + _ = (Real.log 4 / 256) * (Real.sqrt (n + 1))^2 := by ring + _ = _ := by rw [hh] + rw [hsq] at h₂ + have h₃ := mul_le_mul_of_nonneg_left (show (n : ℝ) + 1 ≤ 2 * n by linarith) hc0 + linarith only [h₁, h₂, h₃] + have hq : -(Real.log 4 / 64) * n ≥ + (2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 4 := by + push_cast + have hh := mul_le_mul_of_nonneg_right hdiv (Real.log_nonneg (by norm_num : (1 : ℝ) ≤ 4)) + linarith + calc + _ = Real.exp ((2 * Nat.sqrt n : ℕ) * Real.log (n + 1) - (n / 16 : ℕ) * Real.log 4) := by + rw [Real.exp_sub, Real.exp_nat_mul, Real.exp_nat_mul, Real.exp_log (by positivity), Real.exp_log (by norm_num : (0 : ℝ) < 4)] + _ ≤ _ := Real.exp_le_exp.mpr hq + +end Thorp.Analysis + +namespace Thorp.Specht +open scoped Classical +open Filter Topology Thorp.Young + +variable {n : ℕ} + +def inverseDegree (p : NShape n) : ℝ := ((degree p : ℝ)^2)⁻¹ + +def slice (n u : ℕ) : ℝ := ∑ p : {p : NShape n // defect p = u}, inverseDegree p.val + +def smallSlice (n u : ℕ) : ℝ := if 0 < u ∧ 4 * u ≤ n then slice n u else 0 + +def exceptionalReciprocalSum (n : ℕ) : ℝ := ∑ p : NShape n, if 0 < defect p then inverseDegree p else 0 + +lemma inverseDegree_nonneg (p : NShape n) : 0 ≤ inverseDegree p := by unfold inverseDegree; positivity +lemma slice_nonneg (n u : ℕ) : 0 ≤ slice n u := Finset.sum_nonneg (fun _ _ => inverseDegree_nonneg _) +lemma smallSlice_nonneg (n u : ℕ) : 0 ≤ smallSlice n u := by unfold smallSlice; split_ifs; exact slice_nonneg _ _; rfl + +lemma slice_bound (n u : ℕ) (K : ℝ) (hK : 0 < K) + (hk : ∀ p : NShape n, defect p = u → K ≤ degree p) : + slice n u ≤ (2 : ℝ)^(u+1) / K^2 := by + have hI (p : {p : NShape n // defect p = u}) : inverseDegree p.val ≤ (K^2)⁻¹ := by + apply inv_anti₀ (pow_pos hK 2) + exact pow_le_pow_left₀ hK.le (hk p.val p.property) 2 + calc + _ ≤ ∑ _ : {p : NShape n // defect p = u}, (K^2)⁻¹ := Finset.sum_le_sum (fun p _ => hI p) + _ = (Fintype.card {p : NShape n // defect p = u} : ℝ) * (K^2)⁻¹ := by simp + _ ≤ (2 : ℝ)^(u+1) * (K^2)⁻¹ := mul_le_mul_of_nonneg_right (by exact_mod_cast defect_card_bound n u) (by positivity) + _ = _ := rfl + +lemma smallSlice_bound (n u : ℕ) : smallSlice n u ≤ 2 * (2 / 9 : ℝ)^u := by + unfold smallSlice + split_ifs with h + · have hk : ∀ p : NShape n, defect p = u → (3 : ℝ)^u ≤ degree p := by + intro p hp + have hh := small_defect_degree p (by rw [hp]; exact h.2) + rw [hp] at hh + exact_mod_cast hh + have hh := slice_bound n u (3^u) (by positivity) hk + have he : (2 : ℝ)^(u+1) / (3^u)^2 = 2 * (2/9 :ℝ)^u := by + rw [pow_succ, div_pow] + have hp : ((3 : ℝ)^u) ^ 2 = 9^u := by rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num + rw [hp] + ring + exact hh.trans_eq he + · positivity + +lemma smallSlice_tendsto (u : ℕ) : Tendsto (fun n => smallSlice n u) atTop (𝓝 0) := by + by_cases hu : 0 < u + · have ht : Tendsto (fun n : ℕ => ((n - 2*u + 1 : ℕ) : ℝ)) atTop atTop := by + exact (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop).comp + ((tendsto_add_atTop_nat 1).comp (tendsto_sub_atTop_nat (2*u))) + have hi : Tendsto (fun n : ℕ => (((n - 2*u + 1 : ℕ) : ℝ)^2)⁻¹) atTop (𝓝 0) := by + apply tendsto_inv_atTop_zero.comp + simpa only [pow_two] using ht.atTop_mul_atTop₀ ht + have he := hi.const_mul ((2 : ℝ)^(u+1)) + rw [mul_zero] at he + apply squeeze_zero' (Eventually.of_forall (fun n => smallSlice_nonneg n u)) _ he + filter_upwards [eventually_ge_atTop (4*u)] with n hn + rw [smallSlice, ite_eq_left ⟨hu, hn⟩] + exact slice_bound n u _ (by positivity) (fun p hp => by + have hh := fixed_defect_degree p (by rwa [hp]) (by rw [hp]; omega) + rw [hp] at hh + exact_mod_cast hh) + · simp only [smallSlice, hu, false_and, ↓reduceIte] + exact tendsto_const_nhds + +lemma smallSum_tendsto : Tendsto (fun n => ∑' u, smallSlice n u) atTop (𝓝 0) := by + have hs : Summable (fun u : ℕ => 2 * (2/9 : ℝ)^u) := + (summable_geometric_of_norm_lt_one (by norm_num : ‖(2/9 : ℝ)‖ < 1)).mul_left 2 + have h := tendsto_tsum_of_dominated_convergence hs smallSlice_tendsto + (Eventually.of_forall (fun n u => by rw [Real.norm_of_nonneg (smallSlice_nonneg n u)]; exact smallSlice_bound n u)) + simpa only [tsum_zero] using h + +end Thorp.Specht + +namespace Thorp.Specht +open scoped Classical +open Filter Topology Thorp.Young + +lemma smallSlice_as_sum (n u : ℕ) : + smallSlice n u = ∑ p : NShape n, + if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0 := by + unfold smallSlice slice + rw [← Finset.sum_subtype (Finset.univ.filter (fun p : NShape n => defect p = u)) (by simp), Finset.sum_filter] + by_cases h : 0 < u ∧ 4 * u ≤ n + · rw [ite_eq_left h] + apply Finset.sum_congr rfl + intro p _ + by_cases hp : defect p = u + · simp only [hp, h.1, h.2, true_and, ↓reduceIte] + · simp only [hp, false_and, ↓reduceIte] + · rw [ite_eq_right h] + apply Eq.symm + apply Finset.sum_eq_zero + intro p _ + split_ifs with hp + · exact (h (by simpa only [hp.1] using hp.2)).elim + · rfl + +lemma smallSlice_support (n u : ℕ) (hu : u ∉ Finset.range (n+1)) : smallSlice n u = 0 := by + unfold smallSlice + have hh : ¬(0 < u ∧ 4*u ≤ n) := by have := (Finset.mem_range.not.mp hu); omega + exact ite_eq_right hh + +lemma smallSum_eq (n : ℕ) : + (∑' u, smallSlice n u) = ∑ p : NShape n, + if 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0 := by + rw [tsum_eq_sum (smallSlice_support n)] + simp_rw [smallSlice_as_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro p _ + have hd : defect p ∈ Finset.range (n+1) := Finset.mem_range.mpr (by have := defect_add_longest p; omega) + have he (u : ℕ) : (if defect p = u ∧ 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0) = + if defect p = u then (if 0 < defect p ∧ 4 * defect p ≤ n then inverseDegree p else 0) else 0 := by + split_ifs <;> tauto + simp only [he, Finset.sum_ite_eq, hd, ↓reduceIte] + +lemma bulkSum_bound (n : ℕ) (hn : 0 < n) : + (∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) ≤ + ((n : ℝ)+1)^(2*Nat.sqrt n) / (4:ℝ)^(n/16) := by + have hb (p : NShape n) : (if n < 4*defect p then inverseDegree p else 0) ≤ ((4:ℝ)^(n/16))⁻¹ := by + by_cases hp : n < 4*defect p + · rw [ite_eq_left hp] + have hh := bulk_degree p hn hp + have he : ((2 : ℝ)^(n/16))^2 = (4:ℝ)^(n/16) := by + rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num + apply inv_anti₀ (by positivity) + change (4:ℝ)^(n/16) ≤ (degree p : ℝ)^2 + rw [← he] + exact pow_le_pow_left₀ (by positivity) hh 2 + · rw [ite_eq_right hp]; positivity + have hc : Fintype.card (NShape n) ≤ (n+1)^(2*Nat.sqrt n) := by + rw [Fintype.card_eq_nat_card] + change Nat.card (Nat.Partition (Fintype.card (Fin n))) ≤ _ + rw [Fintype.card_fin, ← Fintype.card_eq_nat_card] + exact partition_count_le_sqrt_pow n + calc + _ ≤ ∑ _ : NShape n, ((4:ℝ)^(n/16))⁻¹ := Finset.sum_le_sum (fun p _ => hb p) + _ = (Fintype.card (NShape n) : ℝ) * ((4:ℝ)^(n/16))⁻¹ := by simp + _ ≤ ((n:ℝ)+1)^(2*Nat.sqrt n) * ((4:ℝ)^(n/16))⁻¹ := + mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (by positivity) + _ = _ := rfl + +lemma exceptionalReciprocalSum_split (n : ℕ) : exceptionalReciprocalSum n = + (∑' u, smallSlice n u) + (∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) := by + rw [smallSum_eq, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + split_ifs <;> simp_all + all_goals omega + +theorem exceptionalReciprocalSum_tendsto : Tendsto exceptionalReciprocalSum atTop (𝓝 0) := by + have hb : Tendsto (fun n => ∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun n => Finset.sum_nonneg (fun p _ => by split_ifs; exact inverseDegree_nonneg p; rfl))) + ((eventually_gt_atTop 0).mono (fun n hn => bulkSum_bound n hn)) Thorp.Analysis.partition_exponential_decay + have he : exceptionalReciprocalSum = (fun n => (∑' u, smallSlice n u) + ∑ p : NShape n, if n < 4 * defect p then inverseDegree p else 0) := funext exceptionalReciprocalSum_split + rw [he] + simpa only [zero_add] using smallSum_tendsto.add hb + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Reynolds.lean b/lean/OAI/Probability/ThorpShuffle/Reynolds.lean index 20ad85a87029aff63c48c59c8115b8a4520c0e87..ab2cd5858413e26aecd730f77d030dabbefc9679 100644 --- a/lean/OAI/Probability/ThorpShuffle/Reynolds.lean +++ b/lean/OAI/Probability/ThorpShuffle/Reynolds.lean @@ -1,183 +1,183 @@ -import OAI.Probability.ThorpShuffle.ReciprocalDegrees - -namespace OAI - -universe uG uV uW uE uI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -open scoped BigOperators ComplexConjugate InnerProductSpace - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type uG} [Group G] [Fintype G] -variable {V : Type uV} {W : Type uW} [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - -def integrated (ρ : Representation ℂ G V) (f : G → ℂ) : Module.End ℂ V := - ∑ g, f g • ρ g - -def reynolds (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) : V →ₗ[ℂ] W := - (Fintype.card G : ℂ)⁻¹ • ∑ g : G, σ g ∘ₗ A ∘ₗ ρ g⁻¹ - -lemma reynolds_intertwines (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) - (h : G) (v : V) : reynolds ρ σ A (ρ h v) = σ h (reynolds ρ σ A v) := by - simp only [reynolds, LinearMap.smul_apply, LinearMap.sum_apply, LinearMap.comp_apply, - map_smul, map_sum] - congr 1 - have he := Equiv.sum_comp (Equiv.mulLeft h) (fun g : G => σ g (A (ρ g⁻¹ (ρ h v)))) - rw [← he] - apply Finset.sum_congr rfl - intro g _ - change σ (h * g) (A (ρ (h * g)⁻¹ (ρ h v))) = σ h (σ g (A (ρ g⁻¹ v))) - simp only [mul_inv_rev, map_mul, Module.End.mul_apply] - congr 2 - simp only [← Module.End.mul_apply, ← map_mul, inv_mul_cancel, map_one, Module.End.one_apply] - -def reynoldsMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) : - Representation.IntertwiningMap ρ σ := - (reynolds ρ σ A).intertwiningMap_of_isIntertwiningMap ρ σ (reynolds_intertwines ρ σ A) - -lemma reynolds_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - [FiniteDimensional ℂ V] (A : Module.End ℂ V) : - ∃ c : ℂ, reynolds ρ ρ A = c • LinearMap.id := by - obtain ⟨c, hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed - (ρ := ρ)).surjective (reynoldsMap ρ ρ A) - refine ⟨c, ?_⟩ - have hh := congrArg Representation.IntertwiningMap.toLinearMap hc - exact hh.symm - -lemma reynolds_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hne : ¬ Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : reynolds ρ σ A = 0 := by - rcases Representation.IsIrreducible.bijective_or_eq_zero (reynoldsMap ρ σ A) with h | h - · exact (hne ⟨(reynoldsMap ρ σ A).ofBijective h⟩).elim - · exact congrArg Representation.IntertwiningMap.toLinearMap h - -lemma trace_reynolds (ρ : Representation ℂ G V) [FiniteDimensional ℂ V] (A : Module.End ℂ V) : - LinearMap.trace ℂ V (reynolds ρ ρ A) = LinearMap.trace ℂ V A := by - simp only [reynolds, map_smul, map_sum] - have hh (g : G) : LinearMap.trace ℂ V (ρ g ∘ₗ A ∘ₗ ρ g⁻¹) = LinearMap.trace ℂ V A := by - rw [LinearMap.trace_comp_comm'] - rw [LinearMap.comp_assoc] - have he : ρ g⁻¹ ∘ₗ ρ g = LinearMap.id := by - change ρ g⁻¹ * ρ g = 1 - rw [← map_mul, inv_mul_cancel, map_one] - rw [he, LinearMap.comp_id] - simp only [hh, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, smul_eq_mul] - rw [← mul_assoc, inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero), one_mul] - -lemma reynolds_eq_trace (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - [FiniteDimensional ℂ V] (hV : Module.finrank ℂ V ≠ 0) (A : Module.End ℂ V) : - reynolds ρ ρ A = (LinearMap.trace ℂ V A / Module.finrank ℂ V) • LinearMap.id := by - obtain ⟨c, hc⟩ := reynolds_scalar ρ A - have ht := trace_reynolds ρ A - rw [hc, map_smul, LinearMap.trace_id, smul_eq_mul] at ht - have hD : (Module.finrank ℂ V : ℂ) ≠ 0 := by exact_mod_cast hV - rw [hc, ← ht, mul_div_cancel_right₀ _ hD] - -section Unitary -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -omit [Fintype G] [FiniteDimensional ℂ E] in -lemma inner_inv (ρ : Representation ℂ G E) - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (g : G) (x y : E) : - ⟪x, ρ g⁻¹ y⟫_ℂ = ⟪ρ g x, y⟫_ℂ := by - have hh := hu g x (ρ g⁻¹ y) - simpa only [← Module.End.mul_apply, ← map_mul, mul_inv_cancel, map_one, - Module.End.one_apply] using hh.symm - -theorem coefficient_second_moment (ρ : Representation ℂ G E) - [Representation.IsIrreducible ρ] - (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) - (hE : Module.finrank ℂ E ≠ 0) (v w : E) : - (Fintype.card G : ℝ)⁻¹ * ∑ g : G, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = - ‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E := by - have hh := congrArg (fun A : Module.End ℂ E => ⟪w, A w⟫_ℂ) - (reynolds_eq_trace ρ hE (InnerProductSpace.rankOne ℂ v v).toLinearMap) - simp only [reynolds, LinearMap.smul_apply, LinearMap.sum_apply, LinearMap.comp_apply, - inner_smul_right, inner_sum, ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply, map_smul, inner_inv ρ hu, - InnerProductSpace.trace_rankOne, LinearMap.id_apply] at hh - have hc (g : G) : ⟪ρ g v, w⟫_ℂ * ⟪w, ρ g v⟫_ℂ = (‖⟪w, ρ g v⟫_ℂ‖ ^ 2 : ℝ) := by - rw [← inner_conj_symm (ρ g v) w, Complex.conj_mul', Complex.ofReal_pow] - simp only [hc, inner_self_eq_norm_sq_to_K] at hh - have hr : (Fintype.card G : ℝ)⁻¹ * ∑ g : G, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = - ‖v‖ ^ 2 / Module.finrank ℂ E * ‖w‖ ^ 2 := by - apply Complex.ofReal_injective - push_cast - simpa only [Complex.ofReal_pow, RCLike.ofReal_eq_complex_ofReal] using hh - simpa only [div_mul_eq_mul_div] using hr - -end Unitary -end Thorp.Fourier - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type uG} [Group G] [Fintype G] -variable {V : Type uV} [AddCommGroup V] [Module ℂ V] - -def convolution (f k : G → ℂ) (x : G) : ℂ := ∑ g, f g * k (g⁻¹ * x) - -def delta : G → ℂ := fun g => if g = 1 then 1 else 0 - -lemma integrated_delta (ρ : Representation ℂ G V) : integrated ρ delta = 1 := by - simp [integrated, delta] - -lemma integrated_sum {I : Type uI} (ρ : Representation ℂ G V) (s : Finset I) (f : I → G → ℂ) : - integrated ρ (∑ i ∈ s, f i) = ∑ i ∈ s, integrated ρ (f i) := by - simp only [integrated, Finset.sum_apply, Finset.sum_smul] - rw [Finset.sum_comm] - -lemma integrated_sub (ρ : Representation ℂ G V) (f k : G → ℂ) : - integrated ρ (f - k) = integrated ρ f - integrated ρ k := by - simp only [integrated, Pi.sub_apply, sub_smul, Finset.sum_sub_distrib] - -lemma integrated_convolution (ρ : Representation ℂ G V) (f k : G → ℂ) : - integrated ρ (convolution f k) = integrated ρ f * integrated ρ k := by - simp only [integrated, convolution, Finset.sum_smul, Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - conv_rhs => rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro g _ - have he := Equiv.sum_comp (Equiv.mulLeft g) (fun x => (f g * k (g⁻¹ * x)) • ρ x) - rw [← he] - apply Finset.sum_congr rfl - intro h _ - simp only [Equiv.coe_mulLeft, inv_mul_cancel_left, map_mul, smul_mul_smul] - -lemma integrated_central (ρ : Representation ℂ G V) (f : G → ℂ) - (hf : ∀ g h, f (h * g * h⁻¹) = f g) (h : G) : - integrated ρ f * ρ h = ρ h * integrated ρ f := by - rw [integrated, Finset.sum_mul, Finset.mul_sum] - have he := Equiv.sum_comp (Equiv.mulLeft h |>.trans (Equiv.mulRight h⁻¹)) - (fun g => (f g • ρ g) * ρ h) - rw [← he] - apply Finset.sum_congr rfl - intro g _ - simp only [Equiv.trans_apply, Equiv.coe_mulLeft, Equiv.coe_mulRight, hf, - smul_mul_assoc, mul_smul_comm, ← map_mul, inv_mul_cancel_right] - -lemma central_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - [FiniteDimensional ℂ V] (f : G → ℂ) (hf : ∀ g h, f (h * g * h⁻¹) = f g) : - ∃ c : ℂ, integrated ρ f = c • LinearMap.id := by - let A : Representation.IntertwiningMap ρ ρ := - (integrated ρ f).intertwiningMap_of_isIntertwiningMap ρ ρ (by - intro g v - exact congrArg (fun A : Module.End ℂ V => A v) (integrated_central ρ f hf g)) - obtain ⟨c, hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed - (ρ := ρ)).surjective A - exact ⟨c, (congrArg Representation.IntertwiningMap.toLinearMap hc).symm⟩ - -lemma trace_integrated (ρ : Representation ℂ G V) (f : G → ℂ) : - LinearMap.trace ℂ V (integrated ρ f) = ∑ g, f g * ρ.character g := by - simp only [integrated, map_sum, map_smul, smul_eq_mul, Representation.character] - -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.ReciprocalDegrees + +namespace OAI + +universe uG uV uW uE uI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +open scoped BigOperators ComplexConjugate InnerProductSpace + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type uG} [Group G] [Fintype G] +variable {V : Type uV} {W : Type uW} [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + +def integrated (ρ : Representation ℂ G V) (f : G → ℂ) : Module.End ℂ V := + ∑ g, f g • ρ g + +def reynolds (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) : V →ₗ[ℂ] W := + (Fintype.card G : ℂ)⁻¹ • ∑ g : G, σ g ∘ₗ A ∘ₗ ρ g⁻¹ + +lemma reynolds_intertwines (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) + (h : G) (v : V) : reynolds ρ σ A (ρ h v) = σ h (reynolds ρ σ A v) := by + simp only [reynolds, LinearMap.smul_apply, LinearMap.sum_apply, LinearMap.comp_apply, + map_smul, map_sum] + congr 1 + have he := Equiv.sum_comp (Equiv.mulLeft h) (fun g : G => σ g (A (ρ g⁻¹ (ρ h v)))) + rw [← he] + apply Finset.sum_congr rfl + intro g _ + change σ (h * g) (A (ρ (h * g)⁻¹ (ρ h v))) = σ h (σ g (A (ρ g⁻¹ v))) + simp only [mul_inv_rev, map_mul, Module.End.mul_apply] + congr 2 + simp only [← Module.End.mul_apply, ← map_mul, inv_mul_cancel, map_one, Module.End.one_apply] + +def reynoldsMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) (A : V →ₗ[ℂ] W) : + Representation.IntertwiningMap ρ σ := + (reynolds ρ σ A).intertwiningMap_of_isIntertwiningMap ρ σ (reynolds_intertwines ρ σ A) + +lemma reynolds_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + [FiniteDimensional ℂ V] (A : Module.End ℂ V) : + ∃ c : ℂ, reynolds ρ ρ A = c • LinearMap.id := by + obtain ⟨c, hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed + (ρ := ρ)).surjective (reynoldsMap ρ ρ A) + refine ⟨c, ?_⟩ + have hh := congrArg Representation.IntertwiningMap.toLinearMap hc + exact hh.symm + +lemma reynolds_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hne : ¬ Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : reynolds ρ σ A = 0 := by + rcases Representation.IsIrreducible.bijective_or_eq_zero (reynoldsMap ρ σ A) with h | h + · exact (hne ⟨(reynoldsMap ρ σ A).ofBijective h⟩).elim + · exact congrArg Representation.IntertwiningMap.toLinearMap h + +lemma trace_reynolds (ρ : Representation ℂ G V) [FiniteDimensional ℂ V] (A : Module.End ℂ V) : + LinearMap.trace ℂ V (reynolds ρ ρ A) = LinearMap.trace ℂ V A := by + simp only [reynolds, map_smul, map_sum] + have hh (g : G) : LinearMap.trace ℂ V (ρ g ∘ₗ A ∘ₗ ρ g⁻¹) = LinearMap.trace ℂ V A := by + rw [LinearMap.trace_comp_comm'] + rw [LinearMap.comp_assoc] + have he : ρ g⁻¹ ∘ₗ ρ g = LinearMap.id := by + change ρ g⁻¹ * ρ g = 1 + rw [← map_mul, inv_mul_cancel, map_one] + rw [he, LinearMap.comp_id] + simp only [hh, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, smul_eq_mul] + rw [← mul_assoc, inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero), one_mul] + +lemma reynolds_eq_trace (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + [FiniteDimensional ℂ V] (hV : Module.finrank ℂ V ≠ 0) (A : Module.End ℂ V) : + reynolds ρ ρ A = (LinearMap.trace ℂ V A / Module.finrank ℂ V) • LinearMap.id := by + obtain ⟨c, hc⟩ := reynolds_scalar ρ A + have ht := trace_reynolds ρ A + rw [hc, map_smul, LinearMap.trace_id, smul_eq_mul] at ht + have hD : (Module.finrank ℂ V : ℂ) ≠ 0 := by exact_mod_cast hV + rw [hc, ← ht, mul_div_cancel_right₀ _ hD] + +section Unitary +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +omit [Fintype G] [FiniteDimensional ℂ E] in +lemma inner_inv (ρ : Representation ℂ G E) + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) (g : G) (x y : E) : + ⟪x, ρ g⁻¹ y⟫_ℂ = ⟪ρ g x, y⟫_ℂ := by + have hh := hu g x (ρ g⁻¹ y) + simpa only [← Module.End.mul_apply, ← map_mul, mul_inv_cancel, map_one, + Module.End.one_apply] using hh.symm + +theorem coefficient_second_moment (ρ : Representation ℂ G E) + [Representation.IsIrreducible ρ] + (hu : ∀ g x y, ⟪ρ g x, ρ g y⟫_ℂ = ⟪x, y⟫_ℂ) + (hE : Module.finrank ℂ E ≠ 0) (v w : E) : + (Fintype.card G : ℝ)⁻¹ * ∑ g : G, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = + ‖v‖ ^ 2 * ‖w‖ ^ 2 / Module.finrank ℂ E := by + have hh := congrArg (fun A : Module.End ℂ E => ⟪w, A w⟫_ℂ) + (reynolds_eq_trace ρ hE (InnerProductSpace.rankOne ℂ v v).toLinearMap) + simp only [reynolds, LinearMap.smul_apply, LinearMap.sum_apply, LinearMap.comp_apply, + inner_smul_right, inner_sum, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, map_smul, inner_inv ρ hu, + InnerProductSpace.trace_rankOne, LinearMap.id_apply] at hh + have hc (g : G) : ⟪ρ g v, w⟫_ℂ * ⟪w, ρ g v⟫_ℂ = (‖⟪w, ρ g v⟫_ℂ‖ ^ 2 : ℝ) := by + rw [← inner_conj_symm (ρ g v) w, Complex.conj_mul', Complex.ofReal_pow] + simp only [hc, inner_self_eq_norm_sq_to_K] at hh + have hr : (Fintype.card G : ℝ)⁻¹ * ∑ g : G, ‖⟪w, ρ g v⟫_ℂ‖ ^ 2 = + ‖v‖ ^ 2 / Module.finrank ℂ E * ‖w‖ ^ 2 := by + apply Complex.ofReal_injective + push_cast + simpa only [Complex.ofReal_pow, RCLike.ofReal_eq_complex_ofReal] using hh + simpa only [div_mul_eq_mul_div] using hr + +end Unitary +end Thorp.Fourier + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type uG} [Group G] [Fintype G] +variable {V : Type uV} [AddCommGroup V] [Module ℂ V] + +def convolution (f k : G → ℂ) (x : G) : ℂ := ∑ g, f g * k (g⁻¹ * x) + +def delta : G → ℂ := fun g => if g = 1 then 1 else 0 + +lemma integrated_delta (ρ : Representation ℂ G V) : integrated ρ delta = 1 := by + simp [integrated, delta] + +lemma integrated_sum {I : Type uI} (ρ : Representation ℂ G V) (s : Finset I) (f : I → G → ℂ) : + integrated ρ (∑ i ∈ s, f i) = ∑ i ∈ s, integrated ρ (f i) := by + simp only [integrated, Finset.sum_apply, Finset.sum_smul] + rw [Finset.sum_comm] + +lemma integrated_sub (ρ : Representation ℂ G V) (f k : G → ℂ) : + integrated ρ (f - k) = integrated ρ f - integrated ρ k := by + simp only [integrated, Pi.sub_apply, sub_smul, Finset.sum_sub_distrib] + +lemma integrated_convolution (ρ : Representation ℂ G V) (f k : G → ℂ) : + integrated ρ (convolution f k) = integrated ρ f * integrated ρ k := by + simp only [integrated, convolution, Finset.sum_smul, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + conv_rhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro g _ + have he := Equiv.sum_comp (Equiv.mulLeft g) (fun x => (f g * k (g⁻¹ * x)) • ρ x) + rw [← he] + apply Finset.sum_congr rfl + intro h _ + simp only [Equiv.coe_mulLeft, inv_mul_cancel_left, map_mul, smul_mul_smul] + +lemma integrated_central (ρ : Representation ℂ G V) (f : G → ℂ) + (hf : ∀ g h, f (h * g * h⁻¹) = f g) (h : G) : + integrated ρ f * ρ h = ρ h * integrated ρ f := by + rw [integrated, Finset.sum_mul, Finset.mul_sum] + have he := Equiv.sum_comp (Equiv.mulLeft h |>.trans (Equiv.mulRight h⁻¹)) + (fun g => (f g • ρ g) * ρ h) + rw [← he] + apply Finset.sum_congr rfl + intro g _ + simp only [Equiv.trans_apply, Equiv.coe_mulLeft, Equiv.coe_mulRight, hf, + smul_mul_assoc, mul_smul_comm, ← map_mul, inv_mul_cancel_right] + +lemma central_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + [FiniteDimensional ℂ V] (f : G → ℂ) (hf : ∀ g h, f (h * g * h⁻¹) = f g) : + ∃ c : ℂ, integrated ρ f = c • LinearMap.id := by + let A : Representation.IntertwiningMap ρ ρ := + (integrated ρ f).intertwiningMap_of_isIntertwiningMap ρ ρ (by + intro g v + exact congrArg (fun A : Module.End ℂ V => A v) (integrated_central ρ f hf g)) + obtain ⟨c, hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed + (ρ := ρ)).surjective A + exact ⟨c, (congrArg Representation.IntertwiningMap.toLinearMap hc).symm⟩ + +lemma trace_integrated (ρ : Representation ℂ G V) (f : G → ℂ) : + LinearMap.trace ℂ V (integrated ρ f) = ∑ g, f g * ρ.character g := by + simp only [integrated, map_sum, map_smul, smul_eq_mul, Representation.character] + +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Specht.lean b/lean/OAI/Probability/ThorpShuffle/Specht.lean index 35b686a6066633a655c1324003760e0c36f65f69..f30bfbee8ee8e294573f32f0ddb1ac96ea3fe191 100644 --- a/lean/OAI/Probability/ThorpShuffle/Specht.lean +++ b/lean/OAI/Probability/ThorpShuffle/Specht.lean @@ -1,227 +1,227 @@ -import OAI.Probability.ThorpShuffle.Tableaux - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Specht -open scoped Classical - -variable {α : Type uα} [Fintype α] - -omit [Fintype α] in -@[simp] lemma perm_apply_inv (g : Equiv.Perm α) (x : α) : g (g⁻¹ x) = x := g.apply_symm_apply x - -omit [Fintype α] in -@[simp] lemma perm_inv_apply (g : Equiv.Perm α) (x : α) : g⁻¹ (g x) = x := g.symm_apply_apply x - -def Tabloid (r : α → ℕ) := {f : α → ℕ // ∃ g : Equiv.Perm α, f = r ∘ g} - -instance tabloidFinite (r : α → ℕ) : Finite (Tabloid r) := by - apply Finite.of_surjective (fun g : Equiv.Perm α => (⟨r ∘ g, g, rfl⟩ : Tabloid r)) - rintro ⟨f, g, rfl⟩ - exact ⟨g, rfl⟩ - -instance tabloidFintype (r : α → ℕ) : Fintype (Tabloid r) := Fintype.ofFinite _ - -instance tabloidAction (r : α → ℕ) : MulAction (Equiv.Perm α) (Tabloid r) where - smul g f := ⟨f.val ∘ ⇑(g⁻¹ : Equiv.Perm α), by - obtain ⟨h, hh⟩ := f.property - refine ⟨h * g⁻¹, ?_⟩ - funext x - simp only [Function.comp_apply, hh, Equiv.Perm.mul_apply]⟩ - one_smul f := by apply Subtype.ext; funext x; rfl - mul_smul g h f := by - apply Subtype.ext - funext x - change f.val ((g * h)⁻¹ x) = f.val (h⁻¹ (g⁻¹ x)) - rw [mul_inv_rev, Equiv.Perm.mul_apply] - -omit [Fintype α] in -@[simp] lemma tabloid_smul_apply (r : α → ℕ) (g : Equiv.Perm α) (f : Tabloid r) (x : α) : - (g • f).val x = f.val (g⁻¹ x) := rfl - -def baseTabloid (r : α → ℕ) : Tabloid r := ⟨r, 1, by funext x; rfl⟩ - -omit [Fintype α] in -@[simp] lemma baseTabloid_apply (r : α → ℕ) (x : α) : (baseTabloid r).val x = r x := rfl - -def fiberGroup (c : α → ℕ) : Subgroup (Equiv.Perm α) where - carrier := {g | ∀ x, c (g x) = c x} - one_mem' := by intro x; rfl - mul_mem' := by intro g h hg hh x; exact (hg (h x)).trans (hh x) - inv_mem' := by - intro g hg x - have hh := hg (g⁻¹ x) - change c (g (g.symm x)) = c (g.symm x) at hh - rw [g.apply_symm_apply] at hh - exact hh.symm - -omit [Fintype α] in -lemma stabilizes_tabloid_iff (r : α → ℕ) (g : Equiv.Perm α) (f : Tabloid r) : - g • f = f ↔ ∀ x, f.val (g x) = f.val x := by - constructor - · intro h x - have hh := congrArg (fun t : Tabloid r => t.val (g x)) h - simpa only [tabloid_smul_apply, perm_inv_apply] using hh.symm - · intro h - apply Subtype.ext - funext x - have hh := h (g⁻¹ x) - simpa only [tabloid_smul_apply, perm_apply_inv] using hh.symm - -omit [Fintype α] in -lemma swap_preserves {c : α → ℕ} {x y : α} (hc : c x = c y) : - Equiv.swap x y ∈ fiberGroup c := by - intro z - by_cases hzx : z = x - · subst z; simp [hc] - by_cases hzy : z = y - · subst z; simp [hc] - rw [Equiv.swap_apply_of_ne_of_ne hzx hzy] - -def complexSign : Equiv.Perm α →* ℂ where - toFun g := ((Equiv.Perm.sign g : ℤˣ) : ℤ) - map_one' := by simp - map_mul' := by intro g h; simp - -@[simp] lemma complexSign_conj (g : Equiv.Perm α) : conj (complexSign g) = complexSign g := by - simp [complexSign] - -@[simp] lemma complexSign_inv (g : Equiv.Perm α) : complexSign g⁻¹ = complexSign g := by - simp [complexSign] - -@[simp] lemma complexSign_swap (x y : α) (h : x ≠ y) : complexSign (Equiv.swap x y) = -1 := by - simp [complexSign, Equiv.Perm.sign_swap h] - -variable (D : YoungDiagram) (t : α ≃ Thorp.Young.Cells D) - -def tableauRow (x : α) : ℕ := (t x).val.1 - -def tableauCol (x : α) : ℕ := (t x).val.2 - -omit [Fintype α] in - -lemma row_col_free (g : fiberGroup (tableauCol D t)) - (hg : (g : Equiv.Perm α) • baseTabloid (tableauRow D t) = baseTabloid (tableauRow D t)) : g = 1 := by - apply Subtype.ext - apply Equiv.Perm.ext - intro x - apply t.injective - apply Subtype.ext - apply Prod.ext - · exact (stabilizes_tabloid_iff _ _ _).mp hg x - · exact g.property x - -lemma collision_odd (f : Tabloid (tableauRow D t)) (x y : α) (hxy : x ≠ y) - (hc : tableauCol D t x = tableauCol D t y) (hr : f.val x = f.val y) : - ∃ g : fiberGroup (tableauCol D t), (g : Equiv.Perm α) • f = f ∧ complexSign (g : Equiv.Perm α) = -1 := by - refine ⟨⟨Equiv.swap x y, swap_preserves hc⟩, ?_, complexSign_swap x y hxy⟩ - rw [stabilizes_tabloid_iff] - exact swap_preserves hr - -lemma collision_or_column (f : Tabloid (tableauRow D t)) : - (∃ a : fiberGroup (tableauCol D t), (a : Equiv.Perm α) • f = f ∧ - complexSign (a : Equiv.Perm α) = -1) ∨ - ∃ a : fiberGroup (tableauCol D t), f = (a : Equiv.Perm α) • baseTabloid (tableauRow D t) := by - classical - by_cases hc : ∃ x y : α, x ≠ y ∧ tableauCol D t x = tableauCol D t y ∧ f.val x = f.val y - · obtain ⟨x, y, hxy, hx, hy⟩ := hc - exact Or.inl (collision_odd D t f x y hxy hx hy) - right - let r : Thorp.Young.Cells D → ℕ := fun z => f.val (t.symm z) - have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → r x = r y → x = y := by - intro x y hcol hr - by_contra hxy - apply hc - refine ⟨t.symm x, t.symm y, ?_, ?_, hr⟩ - · exact fun h => hxy (t.symm.injective h) - · simpa only [tableauCol, Equiv.apply_symm_apply] using hcol - have hs : ∑ z : Thorp.Young.Cells D, r z = ∑ z : Thorp.Young.Cells D, z.val.1 := by - change ∑ z, f.val (t.symm z) = _ - rw [Equiv.sum_comp t.symm] - obtain ⟨g, hg⟩ := f.property - rw [hg] - change ∑ x, tableauRow D t (g x) = _ - rw [Equiv.sum_comp g] - exact Equiv.sum_comp t (fun z : Thorp.Young.Cells D => z.val.1) - obtain ⟨σ, hσc, hσr⟩ := Thorp.Young.column_sort D r hi hs - let a : Equiv.Perm α := (t.trans σ).trans t.symm - have hac : a ∈ fiberGroup (tableauCol D t) := by - intro x - change (t (t.symm (σ (t x)))).val.2 = (t x).val.2 - simpa only [Equiv.apply_symm_apply] using hσc (t x) - have har (x : α) : f.val (a x) = tableauRow D t x := hσr (t x) - refine ⟨⟨a, hac⟩, ?_⟩ - apply Subtype.ext - funext x - have hh := har (a⁻¹ x) - simpa only [tabloid_smul_apply, baseTabloid_apply, perm_apply_inv] using hh - -def tabloidRep : Representation ℂ (Equiv.Perm α) (EuclideanSpace ℂ (Tabloid (tableauRow D t))) := - PermutationSpace.rep - -def columnAlternator : Module.End ℂ (EuclideanSpace ℂ (Tabloid (tableauRow D t))) := - PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) - -def polytabloid : EuclideanSpace ℂ (Tabloid (tableauRow D t)) := - columnAlternator D t (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) - -lemma polytabloid_support (f : Tabloid (tableauRow D t)) (hf : polytabloid D t f ≠ 0) : - ∃ h : fiberGroup (tableauCol D t), f = h.val • baseTabloid (tableauRow D t) := by - by_contra hn - push Not at hn - apply hf - change PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) - (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) f = 0 - rw [PermutationSpace.alternator_coeff] - apply Finset.sum_eq_zero - intro h _ - have hne : h.val⁻¹ • f ≠ baseTabloid (tableauRow D t) := by - intro he - exact hn h (inv_smul_eq_iff.mp he) - rw [PiLp.single_apply] - change complexSign h.val * (if h.val⁻¹ • f = baseTabloid (tableauRow D t) then 1 else 0) = 0 - rw [ite_eq_right hne, mul_zero] - -lemma polytabloid_diag : polytabloid D t (baseTabloid (tableauRow D t)) = 1 := by - exact PermutationSpace.polytabloid_base (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) - (baseTabloid (tableauRow D t)) (row_col_free D t) - -lemma polytabloid_ne_zero : polytabloid D t ≠ 0 := by - have hh := PermutationSpace.polytabloid_base (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) - (baseTabloid (tableauRow D t)) (row_col_free D t) - intro hz - change polytabloid D t (baseTabloid (tableauRow D t)) = 1 at hh - rw [hz] at hh - norm_num at hh - -lemma columnAlternator_rank_one (v : EuclideanSpace ℂ (Tabloid (tableauRow D t))) : - columnAlternator D t v = ⟪polytabloid D t, v⟫_ℂ • polytabloid D t := by - exact PermutationSpace.alternator_rank_one (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) - (baseTabloid (tableauRow D t)) (fun h => complexSign_conj h.val) - (fun h => complexSign_inv h.val) (row_col_free D t) (collision_or_column D t) v - -def module : Subrepresentation (tabloidRep D t) := cyclic (tabloidRep D t) (polytabloid D t) - -theorem irreducible : Representation.IsIrreducible (module D t).toRepresentation := by - exact cyclic_irreducible (tabloidRep D t) (polytabloid D t) (polytabloid_ne_zero D t) - PermutationSpace.rep_unitary (columnAlternator D t) (columnAlternator_rank_one D t) - (PermutationSpace.alternator_stable (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype)) - -end Thorp.Specht - -end - -end OAI +import OAI.Probability.ThorpShuffle.Tableaux + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Specht +open scoped Classical + +variable {α : Type uα} [Fintype α] + +omit [Fintype α] in +@[simp] lemma perm_apply_inv (g : Equiv.Perm α) (x : α) : g (g⁻¹ x) = x := g.apply_symm_apply x + +omit [Fintype α] in +@[simp] lemma perm_inv_apply (g : Equiv.Perm α) (x : α) : g⁻¹ (g x) = x := g.symm_apply_apply x + +def Tabloid (r : α → ℕ) := {f : α → ℕ // ∃ g : Equiv.Perm α, f = r ∘ g} + +instance tabloidFinite (r : α → ℕ) : Finite (Tabloid r) := by + apply Finite.of_surjective (fun g : Equiv.Perm α => (⟨r ∘ g, g, rfl⟩ : Tabloid r)) + rintro ⟨f, g, rfl⟩ + exact ⟨g, rfl⟩ + +instance tabloidFintype (r : α → ℕ) : Fintype (Tabloid r) := Fintype.ofFinite _ + +instance tabloidAction (r : α → ℕ) : MulAction (Equiv.Perm α) (Tabloid r) where + smul g f := ⟨f.val ∘ ⇑(g⁻¹ : Equiv.Perm α), by + obtain ⟨h, hh⟩ := f.property + refine ⟨h * g⁻¹, ?_⟩ + funext x + simp only [Function.comp_apply, hh, Equiv.Perm.mul_apply]⟩ + one_smul f := by apply Subtype.ext; funext x; rfl + mul_smul g h f := by + apply Subtype.ext + funext x + change f.val ((g * h)⁻¹ x) = f.val (h⁻¹ (g⁻¹ x)) + rw [mul_inv_rev, Equiv.Perm.mul_apply] + +omit [Fintype α] in +@[simp] lemma tabloid_smul_apply (r : α → ℕ) (g : Equiv.Perm α) (f : Tabloid r) (x : α) : + (g • f).val x = f.val (g⁻¹ x) := rfl + +def baseTabloid (r : α → ℕ) : Tabloid r := ⟨r, 1, by funext x; rfl⟩ + +omit [Fintype α] in +@[simp] lemma baseTabloid_apply (r : α → ℕ) (x : α) : (baseTabloid r).val x = r x := rfl + +def fiberGroup (c : α → ℕ) : Subgroup (Equiv.Perm α) where + carrier := {g | ∀ x, c (g x) = c x} + one_mem' := by intro x; rfl + mul_mem' := by intro g h hg hh x; exact (hg (h x)).trans (hh x) + inv_mem' := by + intro g hg x + have hh := hg (g⁻¹ x) + change c (g (g.symm x)) = c (g.symm x) at hh + rw [g.apply_symm_apply] at hh + exact hh.symm + +omit [Fintype α] in +lemma stabilizes_tabloid_iff (r : α → ℕ) (g : Equiv.Perm α) (f : Tabloid r) : + g • f = f ↔ ∀ x, f.val (g x) = f.val x := by + constructor + · intro h x + have hh := congrArg (fun t : Tabloid r => t.val (g x)) h + simpa only [tabloid_smul_apply, perm_inv_apply] using hh.symm + · intro h + apply Subtype.ext + funext x + have hh := h (g⁻¹ x) + simpa only [tabloid_smul_apply, perm_apply_inv] using hh.symm + +omit [Fintype α] in +lemma swap_preserves {c : α → ℕ} {x y : α} (hc : c x = c y) : + Equiv.swap x y ∈ fiberGroup c := by + intro z + by_cases hzx : z = x + · subst z; simp [hc] + by_cases hzy : z = y + · subst z; simp [hc] + rw [Equiv.swap_apply_of_ne_of_ne hzx hzy] + +def complexSign : Equiv.Perm α →* ℂ where + toFun g := ((Equiv.Perm.sign g : ℤˣ) : ℤ) + map_one' := by simp + map_mul' := by intro g h; simp + +@[simp] lemma complexSign_conj (g : Equiv.Perm α) : conj (complexSign g) = complexSign g := by + simp [complexSign] + +@[simp] lemma complexSign_inv (g : Equiv.Perm α) : complexSign g⁻¹ = complexSign g := by + simp [complexSign] + +@[simp] lemma complexSign_swap (x y : α) (h : x ≠ y) : complexSign (Equiv.swap x y) = -1 := by + simp [complexSign, Equiv.Perm.sign_swap h] + +variable (D : YoungDiagram) (t : α ≃ Thorp.Young.Cells D) + +def tableauRow (x : α) : ℕ := (t x).val.1 + +def tableauCol (x : α) : ℕ := (t x).val.2 + +omit [Fintype α] in + +lemma row_col_free (g : fiberGroup (tableauCol D t)) + (hg : (g : Equiv.Perm α) • baseTabloid (tableauRow D t) = baseTabloid (tableauRow D t)) : g = 1 := by + apply Subtype.ext + apply Equiv.Perm.ext + intro x + apply t.injective + apply Subtype.ext + apply Prod.ext + · exact (stabilizes_tabloid_iff _ _ _).mp hg x + · exact g.property x + +lemma collision_odd (f : Tabloid (tableauRow D t)) (x y : α) (hxy : x ≠ y) + (hc : tableauCol D t x = tableauCol D t y) (hr : f.val x = f.val y) : + ∃ g : fiberGroup (tableauCol D t), (g : Equiv.Perm α) • f = f ∧ complexSign (g : Equiv.Perm α) = -1 := by + refine ⟨⟨Equiv.swap x y, swap_preserves hc⟩, ?_, complexSign_swap x y hxy⟩ + rw [stabilizes_tabloid_iff] + exact swap_preserves hr + +lemma collision_or_column (f : Tabloid (tableauRow D t)) : + (∃ a : fiberGroup (tableauCol D t), (a : Equiv.Perm α) • f = f ∧ + complexSign (a : Equiv.Perm α) = -1) ∨ + ∃ a : fiberGroup (tableauCol D t), f = (a : Equiv.Perm α) • baseTabloid (tableauRow D t) := by + classical + by_cases hc : ∃ x y : α, x ≠ y ∧ tableauCol D t x = tableauCol D t y ∧ f.val x = f.val y + · obtain ⟨x, y, hxy, hx, hy⟩ := hc + exact Or.inl (collision_odd D t f x y hxy hx hy) + right + let r : Thorp.Young.Cells D → ℕ := fun z => f.val (t.symm z) + have hi : ∀ x y : Thorp.Young.Cells D, x.val.2 = y.val.2 → r x = r y → x = y := by + intro x y hcol hr + by_contra hxy + apply hc + refine ⟨t.symm x, t.symm y, ?_, ?_, hr⟩ + · exact fun h => hxy (t.symm.injective h) + · simpa only [tableauCol, Equiv.apply_symm_apply] using hcol + have hs : ∑ z : Thorp.Young.Cells D, r z = ∑ z : Thorp.Young.Cells D, z.val.1 := by + change ∑ z, f.val (t.symm z) = _ + rw [Equiv.sum_comp t.symm] + obtain ⟨g, hg⟩ := f.property + rw [hg] + change ∑ x, tableauRow D t (g x) = _ + rw [Equiv.sum_comp g] + exact Equiv.sum_comp t (fun z : Thorp.Young.Cells D => z.val.1) + obtain ⟨σ, hσc, hσr⟩ := Thorp.Young.column_sort D r hi hs + let a : Equiv.Perm α := (t.trans σ).trans t.symm + have hac : a ∈ fiberGroup (tableauCol D t) := by + intro x + change (t (t.symm (σ (t x)))).val.2 = (t x).val.2 + simpa only [Equiv.apply_symm_apply] using hσc (t x) + have har (x : α) : f.val (a x) = tableauRow D t x := hσr (t x) + refine ⟨⟨a, hac⟩, ?_⟩ + apply Subtype.ext + funext x + have hh := har (a⁻¹ x) + simpa only [tabloid_smul_apply, baseTabloid_apply, perm_apply_inv] using hh + +def tabloidRep : Representation ℂ (Equiv.Perm α) (EuclideanSpace ℂ (Tabloid (tableauRow D t))) := + PermutationSpace.rep + +def columnAlternator : Module.End ℂ (EuclideanSpace ℂ (Tabloid (tableauRow D t))) := + PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) + +def polytabloid : EuclideanSpace ℂ (Tabloid (tableauRow D t)) := + columnAlternator D t (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) + +lemma polytabloid_support (f : Tabloid (tableauRow D t)) (hf : polytabloid D t f ≠ 0) : + ∃ h : fiberGroup (tableauCol D t), f = h.val • baseTabloid (tableauRow D t) := by + by_contra hn + push Not at hn + apply hf + change PermutationSpace.alternator (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) + (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) f = 0 + rw [PermutationSpace.alternator_coeff] + apply Finset.sum_eq_zero + intro h _ + have hne : h.val⁻¹ • f ≠ baseTabloid (tableauRow D t) := by + intro he + exact hn h (inv_smul_eq_iff.mp he) + rw [PiLp.single_apply] + change complexSign h.val * (if h.val⁻¹ • f = baseTabloid (tableauRow D t) then 1 else 0) = 0 + rw [ite_eq_right hne, mul_zero] + +lemma polytabloid_diag : polytabloid D t (baseTabloid (tableauRow D t)) = 1 := by + exact PermutationSpace.polytabloid_base (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) + (baseTabloid (tableauRow D t)) (row_col_free D t) + +lemma polytabloid_ne_zero : polytabloid D t ≠ 0 := by + have hh := PermutationSpace.polytabloid_base (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) + (baseTabloid (tableauRow D t)) (row_col_free D t) + intro hz + change polytabloid D t (baseTabloid (tableauRow D t)) = 1 at hh + rw [hz] at hh + norm_num at hh + +lemma columnAlternator_rank_one (v : EuclideanSpace ℂ (Tabloid (tableauRow D t))) : + columnAlternator D t v = ⟪polytabloid D t, v⟫_ℂ • polytabloid D t := by + exact PermutationSpace.alternator_rank_one (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) + (baseTabloid (tableauRow D t)) (fun h => complexSign_conj h.val) + (fun h => complexSign_inv h.val) (row_col_free D t) (collision_or_column D t) v + +def module : Subrepresentation (tabloidRep D t) := cyclic (tabloidRep D t) (polytabloid D t) + +theorem irreducible : Representation.IsIrreducible (module D t).toRepresentation := by + exact cyclic_irreducible (tabloidRep D t) (polytabloid D t) (polytabloid_ne_zero D t) + PermutationSpace.rep_unitary (columnAlternator D t) (columnAlternator_rank_one D t) + (PermutationSpace.alternator_stable (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype)) + +end Thorp.Specht + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/SpectralDecay.lean b/lean/OAI/Probability/ThorpShuffle/SpectralDecay.lean index 27b05982dc48b190212599703caf5eb43562ccf2..1f4bfc6b7cd7cf6a414816038698caa05054b7a1 100644 --- a/lean/OAI/Probability/ThorpShuffle/SpectralDecay.lean +++ b/lean/OAI/Probability/ThorpShuffle/SpectralDecay.lean @@ -1,147 +1,147 @@ -import OAI.Probability.ThorpShuffle.Support - -namespace OAI - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem half_weight_sum (d : ℕ) : - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) = 1 - (1 / 2 : ℝ) ^ d := by - induction d with - | zero => simp - | succ d ih => - rw [Finset.sum_range_succ, ih, pow_succ] - ring - -theorem half_weight_geometric_identity (γ : ℝ) (d t : ℕ) (hdt : d ≤ t) : - (2 * γ - 1) * - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) = - γ ^ t - (1 / 2 : ℝ) ^ d * γ ^ (t - d) := by - induction d with - | zero => simp - | succ d ih => - have hd : d ≤ t := by omega - have ht : t - d = (t - 1 - d) + 1 := by omega - have ht' : t - (d + 1) = t - 1 - d := by omega - rw [Finset.sum_range_succ, mul_add, ih hd, ht, ht', pow_succ, pow_succ] - ring - -theorem half_weight_geometric_bound (β γ : ℝ) (d t : ℕ) - (hγ : 0 ≤ γ) (hrel : 1 - β ≤ 2 * γ - 1) (hdt : d ≤ t) : - (1 - β) * - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) ≤ γ ^ t := by - have hs : 0 ≤ ∑ j ∈ Finset.range d, - (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j) := by positivity - calc - _ ≤ (2 * γ - 1) * - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) := - mul_le_mul_of_nonneg_right hrel hs - _ = γ ^ t - (1 / 2 : ℝ) ^ d * γ ^ (t - d) := - half_weight_geometric_identity γ d t hdt - _ ≤ γ ^ t := sub_le_self _ (by positivity) - -theorem spectral_track_unroll (d : ℕ) (H : ℕ → ℕ → ℝ) (b : ℕ → ℝ) - (hstep : ∀ t j, j < d → H (t + 1) j = - H t (j + 1) + (1 / 2 : ℝ) ^ (j + 1) * b t) - (t j k : ℕ) (hjk : j + k ≤ d) (hkt : k ≤ t) : - H t j = H (t - k) (j + k) + - ∑ r ∈ Finset.range k, (1 / 2 : ℝ) ^ (j + r + 1) * b (t - 1 - r) := by - induction k with - | zero => simp - | succ k ih => - have hk : k ≤ t := by omega - have hjk' : j + k ≤ d := by omega - rw [ih hjk' hk, Finset.sum_range_succ] - have ht : t - k = (t - 1 - k) + 1 := by omega - have hj : j + k < d := by omega - rw [ht, hstep _ _ hj] - have ht' : t - (k + 1) = t - 1 - k := by omega - rw [ht'] - simp only [Nat.add_assoc] - ring - -theorem energy_of_spectral_tracks (d : ℕ) (H : ℕ → ℕ → ℝ) (b : ℕ → ℝ) - (hstep : ∀ t j, j < d → H (t + 1) j = - H t (j + 1) + (1 / 2 : ℝ) ^ (j + 1) * b t) - (hzero : ∀ t, H t d = 0) (t : ℕ) (ht : d ≤ t) : - H t 0 = ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j) := by - simpa only [zero_add, hzero] using - spectral_track_unroll d H b hstep t 0 d (by omega) ht - -theorem scalar_decay (d : ℕ) (E b : ℕ → ℝ) (β γ η : ℝ) - (hβ : 0 < β) (hβ₁ : β ≤ 1) (hγ : 0 < γ) (hγ₁ : γ ≤ 1) - (hrel : 1 - β ≤ 2 * γ - 1) (hη : 0 ≤ η) - (hE : ∀ t, E t ≤ 1) - (henergy : ∀ t, d ≤ t → E t = - ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j)) - (hnoise : ∀ s, d ≤ s → b s ≤ (1 - β) * E s + η) : - ∀ t, E t ≤ γ ^ t / γ ^ (2 * d) + η / β := by - intro t - induction t using Nat.strong_induction_on with - | h t ih => - by_cases ht : t ≤ 2 * d - · have hp : γ ^ (2 * d) ≤ γ ^ t := pow_le_pow_of_le_one hγ.le hγ₁ ht - have hquot : (1 : ℝ) ≤ γ ^ t / γ ^ (2 * d) := - (le_div_iff₀ (pow_pos hγ _)).mpr (by simpa using hp) - have hc : 0 ≤ η / β := div_nonneg hη hβ.le - linarith [hE t] - · have hdt : d ≤ t := by omega - rw [henergy t hdt] - have hbound : - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j)) ≤ - ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * - ((1 - β) * (γ ^ (t - 1 - j) / γ ^ (2 * d) + η / β) + η) := by - apply Finset.sum_le_sum - intro j hj - have hjd := Finset.mem_range.mp hj - have hsd : d ≤ t - 1 - j := by omega - have hst : t - 1 - j < t := by omega - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact (hnoise _ hsd).trans - (add_le_add (mul_le_mul_of_nonneg_left (ih _ hst) - (show 0 ≤ 1 - β by linarith)) (le_refl η)) - have hconstant : (1 - β) * (η / β) + η = η / β := by - field_simp - ring - have hsplit : - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * - ((1 - β) * (γ ^ (t - 1 - j) / γ ^ (2 * d) + η / β) + η)) = - ((1 - β) * (∑ j ∈ Finset.range d, - (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j))) / γ ^ (2 * d) + - (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) * (η / β) := by - calc - _ = ∑ j ∈ Finset.range d, - (((1 - β) * ((1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j))) / - γ ^ (2 * d) + (1 / 2 : ℝ) ^ (j + 1) * (η / β)) := by - apply Finset.sum_congr rfl - intro j _ - linear_combination (1 / 2 : ℝ) ^ (j + 1) * hconstant - _ = _ := by - rw [Finset.sum_add_distrib, ← Finset.sum_div, ← Finset.mul_sum, - ← Finset.sum_mul] - rw [hsplit] at hbound - have hgeom := half_weight_geometric_bound β γ d t hγ.le hrel hdt - have hgeom' := div_le_div_of_nonneg_right hgeom (pow_nonneg hγ.le (2 * d)) - have hc : (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) * (η / β) ≤ η / β := by - rw [half_weight_sum] - have hz : 0 ≤ (1 / 2 : ℝ) ^ d := by positivity - have hηβ : 0 ≤ η / β := div_nonneg hη hβ.le - nlinarith - linarith - -theorem eight_block_geometric_choice : (31 / 32 : ℝ) ^ 198 ≤ (1 / 2 : ℝ) ^ 8 := by - norm_num - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Support + +namespace OAI + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem half_weight_sum (d : ℕ) : + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) = 1 - (1 / 2 : ℝ) ^ d := by + induction d with + | zero => simp + | succ d ih => + rw [Finset.sum_range_succ, ih, pow_succ] + ring + +theorem half_weight_geometric_identity (γ : ℝ) (d t : ℕ) (hdt : d ≤ t) : + (2 * γ - 1) * + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) = + γ ^ t - (1 / 2 : ℝ) ^ d * γ ^ (t - d) := by + induction d with + | zero => simp + | succ d ih => + have hd : d ≤ t := by omega + have ht : t - d = (t - 1 - d) + 1 := by omega + have ht' : t - (d + 1) = t - 1 - d := by omega + rw [Finset.sum_range_succ, mul_add, ih hd, ht, ht', pow_succ, pow_succ] + ring + +theorem half_weight_geometric_bound (β γ : ℝ) (d t : ℕ) + (hγ : 0 ≤ γ) (hrel : 1 - β ≤ 2 * γ - 1) (hdt : d ≤ t) : + (1 - β) * + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) ≤ γ ^ t := by + have hs : 0 ≤ ∑ j ∈ Finset.range d, + (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j) := by positivity + calc + _ ≤ (2 * γ - 1) * + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j)) := + mul_le_mul_of_nonneg_right hrel hs + _ = γ ^ t - (1 / 2 : ℝ) ^ d * γ ^ (t - d) := + half_weight_geometric_identity γ d t hdt + _ ≤ γ ^ t := sub_le_self _ (by positivity) + +theorem spectral_track_unroll (d : ℕ) (H : ℕ → ℕ → ℝ) (b : ℕ → ℝ) + (hstep : ∀ t j, j < d → H (t + 1) j = + H t (j + 1) + (1 / 2 : ℝ) ^ (j + 1) * b t) + (t j k : ℕ) (hjk : j + k ≤ d) (hkt : k ≤ t) : + H t j = H (t - k) (j + k) + + ∑ r ∈ Finset.range k, (1 / 2 : ℝ) ^ (j + r + 1) * b (t - 1 - r) := by + induction k with + | zero => simp + | succ k ih => + have hk : k ≤ t := by omega + have hjk' : j + k ≤ d := by omega + rw [ih hjk' hk, Finset.sum_range_succ] + have ht : t - k = (t - 1 - k) + 1 := by omega + have hj : j + k < d := by omega + rw [ht, hstep _ _ hj] + have ht' : t - (k + 1) = t - 1 - k := by omega + rw [ht'] + simp only [Nat.add_assoc] + ring + +theorem energy_of_spectral_tracks (d : ℕ) (H : ℕ → ℕ → ℝ) (b : ℕ → ℝ) + (hstep : ∀ t j, j < d → H (t + 1) j = + H t (j + 1) + (1 / 2 : ℝ) ^ (j + 1) * b t) + (hzero : ∀ t, H t d = 0) (t : ℕ) (ht : d ≤ t) : + H t 0 = ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j) := by + simpa only [zero_add, hzero] using + spectral_track_unroll d H b hstep t 0 d (by omega) ht + +theorem scalar_decay (d : ℕ) (E b : ℕ → ℝ) (β γ η : ℝ) + (hβ : 0 < β) (hβ₁ : β ≤ 1) (hγ : 0 < γ) (hγ₁ : γ ≤ 1) + (hrel : 1 - β ≤ 2 * γ - 1) (hη : 0 ≤ η) + (hE : ∀ t, E t ≤ 1) + (henergy : ∀ t, d ≤ t → E t = + ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j)) + (hnoise : ∀ s, d ≤ s → b s ≤ (1 - β) * E s + η) : + ∀ t, E t ≤ γ ^ t / γ ^ (2 * d) + η / β := by + intro t + induction t using Nat.strong_induction_on with + | h t ih => + by_cases ht : t ≤ 2 * d + · have hp : γ ^ (2 * d) ≤ γ ^ t := pow_le_pow_of_le_one hγ.le hγ₁ ht + have hquot : (1 : ℝ) ≤ γ ^ t / γ ^ (2 * d) := + (le_div_iff₀ (pow_pos hγ _)).mpr (by simpa using hp) + have hc : 0 ≤ η / β := div_nonneg hη hβ.le + linarith [hE t] + · have hdt : d ≤ t := by omega + rw [henergy t hdt] + have hbound : + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * b (t - 1 - j)) ≤ + ∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * + ((1 - β) * (γ ^ (t - 1 - j) / γ ^ (2 * d) + η / β) + η) := by + apply Finset.sum_le_sum + intro j hj + have hjd := Finset.mem_range.mp hj + have hsd : d ≤ t - 1 - j := by omega + have hst : t - 1 - j < t := by omega + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact (hnoise _ hsd).trans + (add_le_add (mul_le_mul_of_nonneg_left (ih _ hst) + (show 0 ≤ 1 - β by linarith)) (le_refl η)) + have hconstant : (1 - β) * (η / β) + η = η / β := by + field_simp + ring + have hsplit : + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1) * + ((1 - β) * (γ ^ (t - 1 - j) / γ ^ (2 * d) + η / β) + η)) = + ((1 - β) * (∑ j ∈ Finset.range d, + (1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j))) / γ ^ (2 * d) + + (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) * (η / β) := by + calc + _ = ∑ j ∈ Finset.range d, + (((1 - β) * ((1 / 2 : ℝ) ^ (j + 1) * γ ^ (t - 1 - j))) / + γ ^ (2 * d) + (1 / 2 : ℝ) ^ (j + 1) * (η / β)) := by + apply Finset.sum_congr rfl + intro j _ + linear_combination (1 / 2 : ℝ) ^ (j + 1) * hconstant + _ = _ := by + rw [Finset.sum_add_distrib, ← Finset.sum_div, ← Finset.mul_sum, + ← Finset.sum_mul] + rw [hsplit] at hbound + have hgeom := half_weight_geometric_bound β γ d t hγ.le hrel hdt + have hgeom' := div_le_div_of_nonneg_right hgeom (pow_nonneg hγ.le (2 * d)) + have hc : (∑ j ∈ Finset.range d, (1 / 2 : ℝ) ^ (j + 1)) * (η / β) ≤ η / β := by + rw [half_weight_sum] + have hz : 0 ≤ (1 / 2 : ℝ) ^ d := by positivity + have hηβ : 0 ≤ η / β := div_nonneg hη hβ.le + nlinarith + linarith + +theorem eight_block_geometric_choice : (31 / 32 : ℝ) ^ 198 ≤ (1 / 2 : ℝ) ^ 8 := by + norm_num + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Support.lean b/lean/OAI/Probability/ThorpShuffle/Support.lean index cbd8dacdd4c5b13223e62e791eae3c4786267c18..d422e36cfdeb1047fa854c65370f367a734d41ee 100644 --- a/lean/OAI/Probability/ThorpShuffle/Support.lean +++ b/lean/OAI/Probability/ThorpShuffle/Support.lean @@ -1,145 +1,145 @@ -import OAI.Probability.ThorpShuffle.Walsh - -namespace OAI - -universe uΩ uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -theorem fairMass_nonneg {Ω : Type uΩ} {α : Type uα} [Fintype Ω] (f : Ω → α) (a : α) : - 0 ≤ fairMass f a := by - classical - exact div_nonneg (Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num)) - (Nat.cast_nonneg _) - -theorem fairMass_sum {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] - (f : Ω → α) : ∑ a, fairMass f a = 1 := by - classical - unfold fairMass - rw [← Finset.sum_div, Finset.sum_comm] - simp [Fintype.card_ne_zero] - -theorem sum_sub_le_tv {α : Type uα} [Fintype α] [DecidableEq α] - (μ ν : α → ℝ) (hm : ∑ a, μ a = ∑ a, ν a) (s : Finset α) : - (∑ a ∈ s, (μ a - ν a)) ≤ tv μ ν := by - have h0 : ∑ a, (μ a - ν a) = 0 := by rw [Finset.sum_sub_distrib, hm, sub_self] - have hsplit := s.sum_add_sum_compl (fun a => μ a - ν a) - have hsplitabs := s.sum_add_sum_compl (fun a => |μ a - ν a|) - have h₁ : (∑ a ∈ s, (μ a - ν a)) ≤ ∑ a ∈ s, |μ a - ν a| := - Finset.sum_le_sum (fun a _ => le_abs_self (μ a - ν a)) - have h₂ : -(∑ a ∈ sᶜ, (μ a - ν a)) ≤ ∑ a ∈ sᶜ, |μ a - ν a| := by - rw [← Finset.sum_neg_distrib] - exact Finset.sum_le_sum (fun a _ => neg_le_abs (μ a - ν a)) - unfold tv - linarith - -theorem fairMass_tv_lower {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] - [Fintype α] [Nonempty α] (f : Ω → α) : - 1 - (Fintype.card Ω : ℝ) / Fintype.card α ≤ tv (fairMass f) - (fun _ => 1 / Fintype.card α) := by - classical - let s : Finset α := Finset.univ.image f - have hm : ∑ a, fairMass f a = ∑ a : α, (1 / Fintype.card α : ℝ) := by - rw [fairMass_sum] - simp [Fintype.card_ne_zero] - have hz (a : α) (ha : a ∉ s) : fairMass f a = 0 := by - unfold fairMass - have hne (ω : Ω) : f ω ≠ a := by - intro h - apply ha - exact Finset.mem_image.mpr ⟨ω, Finset.mem_univ _, h⟩ - simp [hne] - have hs : ∑ a ∈ s, fairMass f a = 1 := by - rw [← fairMass_sum f] - exact Finset.sum_subset (Finset.subset_univ _) (fun a _ ha => hz a ha) - have hbound := sum_sub_le_tv (fairMass f) (fun _ => 1 / Fintype.card α) hm s - rw [Finset.sum_sub_distrib, hs] at hbound - simp only [Finset.sum_const, nsmul_eq_mul, mul_one_div] at hbound - have hc : (s.card : ℝ) ≤ Fintype.card Ω := by - exact_mod_cast (Finset.card_image_le (s := Finset.univ) (f := f)) - have hd : 0 ≤ (Fintype.card α : ℝ) := Nat.cast_nonneg _ - have hdiv := div_le_div_of_nonneg_right hc hd - linarith - -@[simp] theorem card_position (d : ℕ) : Fintype.card (Position d) = 2 ^ d := by - simp [Position] - -@[simp] theorem card_state (d : ℕ) : Fintype.card (State d) = (2 ^ d).factorial := by - classical - rw [Fintype.card_perm, card_position] - -@[simp] theorem card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by - simp [Coins] - -@[simp] theorem card_history_succ (d t : ℕ) : - Fintype.card (History (d + 1) t) = 2 ^ (2 ^ d * t) := by - simp [History, ← pow_mul] - -theorem distance_support_lower (d t : ℕ) : - 1 - (2 : ℝ) ^ (2 ^ d * t) / ((2 ^ (d + 1)).factorial : ℝ) ≤ - distance (d + 1) t := by - let : Nonempty (State (d + 1)) := ⟨Equiv.refl _⟩ - have h := fairMass_tv_lower (run (d + 1) t) - change 1 - _ / _ ≤ tv (fairMass (run (d + 1) t)) - (fun _ => 1 / Fintype.card (State (d + 1))) - simpa only [card_history_succ, card_state, Nat.cast_pow, Nat.cast_ofNat] using h - -theorem worst_start_eq (d t : ℕ) (g₀ : State d) : - tv (lawFrom d t g₀) (uniform d) = distance d t := by - classical - have hmass (g : State d) : lawFrom d t g₀ (g * g₀) = law d t g := by - unfold lawFrom law fairMass - congr 1 - apply Finset.sum_congr rfl - intro ω _ - by_cases h : run d t ω = g <;> simp [h] - unfold tv distance - congr 1 - have h := Equiv.sum_comp (Equiv.mulRight g₀) - (fun g : State d => |lawFrom d t g₀ g - uniform d g|) - change (∑ g, |lawFrom d t g₀ (g * g₀) - (1 / Fintype.card (State d) : ℝ)|) = _ at h - simp only [hmass] at h - exact h.symm - -theorem supportThreshold_le_of_distance {d t : ℕ} (hd : 1 ≤ d) - (ht : distance d t ≤ 1 / 4) : supportThreshold d ≤ (t : ℤ) := by - obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) - have hfact : (0 : ℝ) < ((2 ^ (k + 1)).factorial : ℝ) := by - exact_mod_cast Nat.factorial_pos _ - have hlower := distance_support_lower k t - have hdiv : (3 : ℝ) / 4 ≤ 2 ^ (2 ^ k * t) / ((2 ^ (k + 1)).factorial : ℝ) := by - linarith - have hpow : 3 * ((2 ^ (k + 1)).factorial : ℝ) / 4 ≤ (2 : ℝ) ^ (2 ^ k * t) := by - have h := (le_div_iff₀ hfact).mp hdiv - nlinarith - have hlog := (Real.logb_le_logb (by norm_num : (1 : ℝ) < 2) - (by positivity : (0 : ℝ) < 3 * ((2 ^ (k + 1)).factorial : ℝ) / 4) - (by positivity : (0 : ℝ) < 2 ^ (2 ^ k * t))).mpr hpow - rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num)] at hlog - simp only [mul_one] at hlog - unfold supportThreshold - apply Int.ceil_le.mpr - push_cast - have hden : (0 : ℝ) < 2 ^ (k + 1) := by positivity - have hscale := mul_le_mul_of_nonneg_left hlog (by positivity : (0 : ℝ) ≤ 2 / 2 ^ (k + 1)) - have hid : (2 / (2 : ℝ) ^ (k + 1)) * ((2 ^ k * t : ℕ) : ℝ) = t := by - push_cast - rw [pow_succ] - field_simp - rwa [hid] at hscale - -theorem supportThreshold_le_mixingTime {d : ℕ} (hd : 1 ≤ d) - (hex : ∃ t, distance d t ≤ 1 / 4) : supportThreshold d ≤ (mixingTime d : ℤ) := by - apply supportThreshold_le_of_distance hd - exact Nat.sInf_mem hex - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.Walsh + +namespace OAI + +universe uΩ uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +theorem fairMass_nonneg {Ω : Type uΩ} {α : Type uα} [Fintype Ω] (f : Ω → α) (a : α) : + 0 ≤ fairMass f a := by + classical + exact div_nonneg (Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num)) + (Nat.cast_nonneg _) + +theorem fairMass_sum {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] + (f : Ω → α) : ∑ a, fairMass f a = 1 := by + classical + unfold fairMass + rw [← Finset.sum_div, Finset.sum_comm] + simp [Fintype.card_ne_zero] + +theorem sum_sub_le_tv {α : Type uα} [Fintype α] [DecidableEq α] + (μ ν : α → ℝ) (hm : ∑ a, μ a = ∑ a, ν a) (s : Finset α) : + (∑ a ∈ s, (μ a - ν a)) ≤ tv μ ν := by + have h0 : ∑ a, (μ a - ν a) = 0 := by rw [Finset.sum_sub_distrib, hm, sub_self] + have hsplit := s.sum_add_sum_compl (fun a => μ a - ν a) + have hsplitabs := s.sum_add_sum_compl (fun a => |μ a - ν a|) + have h₁ : (∑ a ∈ s, (μ a - ν a)) ≤ ∑ a ∈ s, |μ a - ν a| := + Finset.sum_le_sum (fun a _ => le_abs_self (μ a - ν a)) + have h₂ : -(∑ a ∈ sᶜ, (μ a - ν a)) ≤ ∑ a ∈ sᶜ, |μ a - ν a| := by + rw [← Finset.sum_neg_distrib] + exact Finset.sum_le_sum (fun a _ => neg_le_abs (μ a - ν a)) + unfold tv + linarith + +theorem fairMass_tv_lower {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] + [Fintype α] [Nonempty α] (f : Ω → α) : + 1 - (Fintype.card Ω : ℝ) / Fintype.card α ≤ tv (fairMass f) + (fun _ => 1 / Fintype.card α) := by + classical + let s : Finset α := Finset.univ.image f + have hm : ∑ a, fairMass f a = ∑ a : α, (1 / Fintype.card α : ℝ) := by + rw [fairMass_sum] + simp [Fintype.card_ne_zero] + have hz (a : α) (ha : a ∉ s) : fairMass f a = 0 := by + unfold fairMass + have hne (ω : Ω) : f ω ≠ a := by + intro h + apply ha + exact Finset.mem_image.mpr ⟨ω, Finset.mem_univ _, h⟩ + simp [hne] + have hs : ∑ a ∈ s, fairMass f a = 1 := by + rw [← fairMass_sum f] + exact Finset.sum_subset (Finset.subset_univ _) (fun a _ ha => hz a ha) + have hbound := sum_sub_le_tv (fairMass f) (fun _ => 1 / Fintype.card α) hm s + rw [Finset.sum_sub_distrib, hs] at hbound + simp only [Finset.sum_const, nsmul_eq_mul, mul_one_div] at hbound + have hc : (s.card : ℝ) ≤ Fintype.card Ω := by + exact_mod_cast (Finset.card_image_le (s := Finset.univ) (f := f)) + have hd : 0 ≤ (Fintype.card α : ℝ) := Nat.cast_nonneg _ + have hdiv := div_le_div_of_nonneg_right hc hd + linarith + +@[simp] theorem card_position (d : ℕ) : Fintype.card (Position d) = 2 ^ d := by + simp [Position] + +@[simp] theorem card_state (d : ℕ) : Fintype.card (State d) = (2 ^ d).factorial := by + classical + rw [Fintype.card_perm, card_position] + +@[simp] theorem card_coins_succ (d : ℕ) : Fintype.card (Coins (d + 1)) = 2 ^ (2 ^ d) := by + simp [Coins] + +@[simp] theorem card_history_succ (d t : ℕ) : + Fintype.card (History (d + 1) t) = 2 ^ (2 ^ d * t) := by + simp [History, ← pow_mul] + +theorem distance_support_lower (d t : ℕ) : + 1 - (2 : ℝ) ^ (2 ^ d * t) / ((2 ^ (d + 1)).factorial : ℝ) ≤ + distance (d + 1) t := by + let : Nonempty (State (d + 1)) := ⟨Equiv.refl _⟩ + have h := fairMass_tv_lower (run (d + 1) t) + change 1 - _ / _ ≤ tv (fairMass (run (d + 1) t)) + (fun _ => 1 / Fintype.card (State (d + 1))) + simpa only [card_history_succ, card_state, Nat.cast_pow, Nat.cast_ofNat] using h + +theorem worst_start_eq (d t : ℕ) (g₀ : State d) : + tv (lawFrom d t g₀) (uniform d) = distance d t := by + classical + have hmass (g : State d) : lawFrom d t g₀ (g * g₀) = law d t g := by + unfold lawFrom law fairMass + congr 1 + apply Finset.sum_congr rfl + intro ω _ + by_cases h : run d t ω = g <;> simp [h] + unfold tv distance + congr 1 + have h := Equiv.sum_comp (Equiv.mulRight g₀) + (fun g : State d => |lawFrom d t g₀ g - uniform d g|) + change (∑ g, |lawFrom d t g₀ (g * g₀) - (1 / Fintype.card (State d) : ℝ)|) = _ at h + simp only [hmass] at h + exact h.symm + +theorem supportThreshold_le_of_distance {d t : ℕ} (hd : 1 ≤ d) + (ht : distance d t ≤ 1 / 4) : supportThreshold d ≤ (t : ℤ) := by + obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : d ≠ 0) + have hfact : (0 : ℝ) < ((2 ^ (k + 1)).factorial : ℝ) := by + exact_mod_cast Nat.factorial_pos _ + have hlower := distance_support_lower k t + have hdiv : (3 : ℝ) / 4 ≤ 2 ^ (2 ^ k * t) / ((2 ^ (k + 1)).factorial : ℝ) := by + linarith + have hpow : 3 * ((2 ^ (k + 1)).factorial : ℝ) / 4 ≤ (2 : ℝ) ^ (2 ^ k * t) := by + have h := (le_div_iff₀ hfact).mp hdiv + nlinarith + have hlog := (Real.logb_le_logb (by norm_num : (1 : ℝ) < 2) + (by positivity : (0 : ℝ) < 3 * ((2 ^ (k + 1)).factorial : ℝ) / 4) + (by positivity : (0 : ℝ) < 2 ^ (2 ^ k * t))).mpr hpow + rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num)] at hlog + simp only [mul_one] at hlog + unfold supportThreshold + apply Int.ceil_le.mpr + push_cast + have hden : (0 : ℝ) < 2 ^ (k + 1) := by positivity + have hscale := mul_le_mul_of_nonneg_left hlog (by positivity : (0 : ℝ) ≤ 2 / 2 ^ (k + 1)) + have hid : (2 / (2 : ℝ) ^ (k + 1)) * ((2 ^ k * t : ℕ) : ℝ) = t := by + push_cast + rw [pow_succ] + field_simp + rwa [hid] at hscale + +theorem supportThreshold_le_mixingTime {d : ℕ} (hd : 1 ≤ d) + (hex : ∃ t, distance d t ≤ 1 / 4) : supportThreshold d ≤ (mixingTime d : ℤ) := by + apply supportThreshold_le_of_distance hd + exact Nat.sInf_mem hex + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/SymmetricFamilies.lean b/lean/OAI/Probability/ThorpShuffle/SymmetricFamilies.lean index 4c59c6908fe4fd8d229e19a0e49dca15381a3d8f..4011a283f816167abb6f575761b791a9d5a05438 100644 --- a/lean/OAI/Probability/ThorpShuffle/SymmetricFamilies.lean +++ b/lean/OAI/Probability/ThorpShuffle/SymmetricFamilies.lean @@ -1,92 +1,92 @@ -import OAI.Probability.ThorpShuffle.FourierBounds - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Specht -open scoped Classical -open Thorp.Young - -lemma family_unitary {α : Type} [Fintype α] (p : Shape α) (g : Equiv.Perm α) (v w : Space (α:=α) p) : - ⟪family p g v, family p g w⟫_ℂ = ⟪v, w⟫_ℂ := by - change ⟪tabloidRep _ _ g v.val, tabloidRep _ _ g w.val⟫_ℂ = ⟪v.val, w.val⟫_ℂ - exact PermutationSpace.rep_unitary g v.val w.val - -lemma regular_char_fin (n : ℕ) (g : Equiv.Perm (Fin n)) : - ∑ p : NShape n, (Module.finrank ℂ (Space (α:=Fin n) p) : ℂ) * (family (α:=Fin n) p).character g = - if g = 1 then (Fintype.card (Equiv.Perm (Fin n)) : ℂ) else 0 := by - have hc : Fintype.card (Equiv.Perm (Fin n)) = Nat.card (Equiv.Perm (Fin n)) := Fintype.card_eq_nat_card - rw [hc] - by_cases h : g = 1 - · simpa only [degree, ite_eq_left h] using regular_char g - · simpa only [degree, ite_eq_right h] using regular_char g - -def symmetricFamily (n : ℕ) : Thorp.Fourier.Family (Equiv.Perm (Fin n)) where - Index := NShape n - Space := fun p => Space (α:=Fin n) p - rep := fun p => family (α:=Fin n) p - positive := by - intro p - simpa only [degree] using degree_pos p - unitary := fun p g v w => family_unitary (α:=Fin n) p g v w - distinct := fun p q h => family_inequiv (α:=Fin n) p q h - regular := by - intro g - by_cases h : g = 1 - · simpa only [ite_eq_left h] using regular_char_fin n g - · simpa only [ite_eq_right h] using regular_char_fin n g - -end Thorp.Specht - -namespace Thorp.Fourier -open scoped Classical - -variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] - -variable {V : Type} [AddCommGroup V] [Module ℂ V] - -def subrepPull (ρ : Representation ℂ G V) (e : H ≃* G) : - Subrepresentation ρ ≃o Subrepresentation (ρ.comp e.toMonoidHom) where - toFun U := { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun h => U.apply_mem_toSubmodule (e h) } - invFun U := { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := by - intro g v hv - have hh := U.apply_mem_toSubmodule (e.symm g) hv - simpa only [MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom, e.apply_symm_apply] using hh } - left_inv U := by rfl - right_inv U := by rfl - map_rel_iff' := by rfl - -def Family.pull (F : Family G) (e : H ≃* G) : Family H where - Index := F.Index - Space := F.Space - rep i := (F.rep i).comp e.toMonoidHom - irreducible i := (subrepPull (F.rep i) e).symm.isSimpleOrder - positive := F.positive - unitary := fun i h => F.unitary i (e h) - distinct := by - intro i j hh - obtain ⟨A⟩ := hh - apply F.distinct i j - refine ⟨{ A.toLinearEquiv with isIntertwining' := ?_ }⟩ - intro g - ext v - have ha := DFunLike.congr_fun (A.isIntertwining' (e.symm g)) v - simpa only [MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom, e.apply_symm_apply] using ha - regular := by - intro h - have hh := F.regular (e h) - have hc : Fintype.card G = Fintype.card H := (Fintype.card_congr e.toEquiv).symm - change ∑ i, (Module.finrank ℂ (F.Space i) : ℂ) * (F.rep i).character (e h) = _ - simpa only [e.map_eq_one_iff, hc] using hh - -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.FourierBounds + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Specht +open scoped Classical +open Thorp.Young + +lemma family_unitary {α : Type} [Fintype α] (p : Shape α) (g : Equiv.Perm α) (v w : Space (α:=α) p) : + ⟪family p g v, family p g w⟫_ℂ = ⟪v, w⟫_ℂ := by + change ⟪tabloidRep _ _ g v.val, tabloidRep _ _ g w.val⟫_ℂ = ⟪v.val, w.val⟫_ℂ + exact PermutationSpace.rep_unitary g v.val w.val + +lemma regular_char_fin (n : ℕ) (g : Equiv.Perm (Fin n)) : + ∑ p : NShape n, (Module.finrank ℂ (Space (α:=Fin n) p) : ℂ) * (family (α:=Fin n) p).character g = + if g = 1 then (Fintype.card (Equiv.Perm (Fin n)) : ℂ) else 0 := by + have hc : Fintype.card (Equiv.Perm (Fin n)) = Nat.card (Equiv.Perm (Fin n)) := Fintype.card_eq_nat_card + rw [hc] + by_cases h : g = 1 + · simpa only [degree, ite_eq_left h] using regular_char g + · simpa only [degree, ite_eq_right h] using regular_char g + +def symmetricFamily (n : ℕ) : Thorp.Fourier.Family (Equiv.Perm (Fin n)) where + Index := NShape n + Space := fun p => Space (α:=Fin n) p + rep := fun p => family (α:=Fin n) p + positive := by + intro p + simpa only [degree] using degree_pos p + unitary := fun p g v w => family_unitary (α:=Fin n) p g v w + distinct := fun p q h => family_inequiv (α:=Fin n) p q h + regular := by + intro g + by_cases h : g = 1 + · simpa only [ite_eq_left h] using regular_char_fin n g + · simpa only [ite_eq_right h] using regular_char_fin n g + +end Thorp.Specht + +namespace Thorp.Fourier +open scoped Classical + +variable {G H : Type} [Group G] [Fintype G] [Group H] [Fintype H] + +variable {V : Type} [AddCommGroup V] [Module ℂ V] + +def subrepPull (ρ : Representation ℂ G V) (e : H ≃* G) : + Subrepresentation ρ ≃o Subrepresentation (ρ.comp e.toMonoidHom) where + toFun U := { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun h => U.apply_mem_toSubmodule (e h) } + invFun U := { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := by + intro g v hv + have hh := U.apply_mem_toSubmodule (e.symm g) hv + simpa only [MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom, e.apply_symm_apply] using hh } + left_inv U := by rfl + right_inv U := by rfl + map_rel_iff' := by rfl + +def Family.pull (F : Family G) (e : H ≃* G) : Family H where + Index := F.Index + Space := F.Space + rep i := (F.rep i).comp e.toMonoidHom + irreducible i := (subrepPull (F.rep i) e).symm.isSimpleOrder + positive := F.positive + unitary := fun i h => F.unitary i (e h) + distinct := by + intro i j hh + obtain ⟨A⟩ := hh + apply F.distinct i j + refine ⟨{ A.toLinearEquiv with isIntertwining' := ?_ }⟩ + intro g + ext v + have ha := DFunLike.congr_fun (A.isIntertwining' (e.symm g)) v + simpa only [MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom, e.apply_symm_apply] using ha + regular := by + intro h + have hh := F.regular (e h) + have hc : Fintype.card G = Fintype.card H := (Fintype.card_congr e.toEquiv).symm + change ∑ i, (Module.finrank ℂ (F.Space i) : ℂ) * (F.rep i).character (e h) = _ + simpa only [e.map_eq_one_iff, hc] using hh + +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Tableaux.lean b/lean/OAI/Probability/ThorpShuffle/Tableaux.lean index 4fd819b2095e39b201430f9192a305e634861d2f..d5e9ea416b3f56f21393481d5c00ba09b6569936 100644 --- a/lean/OAI/Probability/ThorpShuffle/Tableaux.lean +++ b/lean/OAI/Probability/ThorpShuffle/Tableaux.lean @@ -1,130 +1,130 @@ -import OAI.Probability.ThorpShuffle.Cyclic - -namespace OAI - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter - -namespace Thorp.Young - -abbrev Cells (D : YoungDiagram) := {p : ℕ × ℕ // p ∈ D.cells} - -lemma fin_le_strictMono {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) (i : Fin n) : - i.val ≤ f i := by - have aux : ∀ k (hk : k < n), k ≤ f ⟨k, hk⟩ := by - intro k - induction k with - | zero => intro hk; exact Nat.zero_le _ - | succ k ih => - intro hk - have hk' : k < n := by omega - have hl := hf (show (⟨k, hk'⟩ : Fin n) < ⟨k + 1, hk⟩ from by simp) - have hi := ih hk' - omega - exact aux i.val i.isLt - -lemma card_column (D : YoungDiagram) (j : ℕ) : - (Finset.univ.filter fun x : Cells D => x.val.2 = j).card = D.colLen j := by - classical - let e : {x : Cells D // x.val.2 = j} ≃ Fin (D.colLen j) := { - toFun := fun x => ⟨x.val.val.1, YoungDiagram.mem_iff_lt_colLen.mp (by - have hx : (x.val.val.1, x.val.val.2) ∈ D := x.val.property - simpa only [x.property] using hx)⟩ - invFun := fun i => ⟨⟨(i, j), YoungDiagram.mem_iff_lt_colLen.mpr i.isLt⟩, rfl⟩ - left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.property.symm - right_inv := by intro i; rfl } - rw [← Fintype.card_subtype] - exact (Fintype.card_congr e).trans (Fintype.card_fin _) - -lemma card_row_subtype (D : YoungDiagram) (i : ℕ) : - Fintype.card {x : Cells D // x.val.1 = i} = D.rowLen i := by - let e : {x : Cells D // x.val.1 = i} ≃ Fin (D.rowLen i) := { - toFun := fun x => ⟨x.val.val.2, YoungDiagram.mem_iff_lt_rowLen.mp (by - have hx : (x.val.val.1, x.val.val.2) ∈ D := x.val.property - simpa only [x.property] using hx)⟩ - invFun := fun j => ⟨⟨(i, j), YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt⟩, rfl⟩ - left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.property.symm rfl - right_inv := by intro j; rfl } - exact (Fintype.card_congr e).trans (Fintype.card_fin _) - -lemma eq_of_rowPreserving (D E : YoungDiagram) (e : Cells D ≃ Cells E) - (he : ∀ x, (e x).val.1 = x.val.1) : D = E := by - have hr (i : ℕ) : D.rowLen i = E.rowLen i := by - rw [← card_row_subtype D i, ← card_row_subtype E i] - exact Fintype.card_congr (e.subtypeEquiv (fun x => by rw [he])) - apply YoungDiagram.ext - ext p - obtain ⟨i, j⟩ := p - change (i, j) ∈ D ↔ (i, j) ∈ E - simp only [YoungDiagram.mem_iff_lt_rowLen, hr] - -theorem column_sort_le (D : YoungDiagram) (r : Cells D → ℕ) - (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) - : - ∃ σ : Equiv.Perm (Cells D), (∀ x, (σ x).val.2 = x.val.2) ∧ - ∀ x, x.val.1 ≤ r (σ x) := by - classical - let S (j : ℕ) : Finset ℕ := (Finset.univ.filter fun x : Cells D => x.val.2 = j).image r - have hc (j : ℕ) : (S j).card = D.colLen j := by - change ((Finset.univ.filter fun x : Cells D => x.val.2 = j).image r).card = _ - rw [Finset.card_image_iff.mpr (show Set.InjOn r ↑(Finset.univ.filter fun x : Cells D => x.val.2 = j) from by - intro x hx y hy hxy - exact hinj x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) hxy)] - exact card_column D j - let F (j : ℕ) := (S j).orderEmbOfFin (hc j) - have hpre (x : Cells D) : ∃ y : Cells D, y.val.2 = x.val.2 ∧ - r y = F x.val.2 ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ := by - have hm := (S x.val.2).orderEmbOfFin_mem (hc _) ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ - obtain ⟨y, hy, he⟩ := Finset.mem_image.mp hm - exact ⟨y, (Finset.mem_filter.mp hy).2, he⟩ - choose f hcol hr using hpre - have hf : Function.Injective f := by - intro x y he - have hj : x.val.2 = y.val.2 := (hcol x).symm.trans ((congrArg (fun z : Cells D => z.val.2) he).trans (hcol y)) - have hi : x.val.1 = y.val.1 := by - have hval : F x.val.2 ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ = - F y.val.2 ⟨y.val.1, YoungDiagram.mem_iff_lt_colLen.mp y.property⟩ := by - rw [← hr x, ← hr y, he] - have hy : y.val.1 < D.colLen x.val.2 := by rw [hj]; exact YoungDiagram.mem_iff_lt_colLen.mp y.property - have hid : F y.val.2 ⟨y.val.1, YoungDiagram.mem_iff_lt_colLen.mp y.property⟩ = F x.val.2 ⟨y.val.1, hy⟩ := by - have aux (j k i : ℕ) (hk : j = k) (hi : i < D.colLen j) (hi' : i < D.colLen k) : - F j ⟨i, hi⟩ = F k ⟨i, hi'⟩ := by subst k; rfl - exact aux _ _ _ hj.symm _ _ - rw [hid] at hval - exact congrArg Fin.val ((F x.val.2).injective hval) - exact Subtype.ext (Prod.ext hi hj) - let σ : Equiv.Perm (Cells D) := Equiv.ofBijective f ⟨hf, Finite.surjective_of_injective hf⟩ - refine ⟨σ, hcol, ?_⟩ - have hle (x : Cells D) : x.val.1 ≤ r (σ x) := by - change x.val.1 ≤ r (f x) - rw [hr] - exact fin_le_strictMono _ (F x.val.2).strictMono ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ - exact hle - -lemma rowRankSum_le (D : YoungDiagram) (r : Cells D → ℕ) - (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) : - ∑ x : Cells D, x.val.1 ≤ ∑ x : Cells D, r x := by - obtain ⟨σ, -, hσ⟩ := column_sort_le D r hinj - rw [← Equiv.sum_comp σ r] - exact Finset.sum_le_sum fun x _ => hσ x - -theorem column_sort (D : YoungDiagram) (r : Cells D → ℕ) - (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) - (hsum : ∑ x : Cells D, r x = ∑ x : Cells D, x.val.1) : - ∃ σ : Equiv.Perm (Cells D), (∀ x, (σ x).val.2 = x.val.2) ∧ - ∀ x, r (σ x) = x.val.1 := by - obtain ⟨σ, hc, hle⟩ := column_sort_le D r hinj - refine ⟨σ, hc, ?_⟩ - have heq : ∑ x : Cells D, x.val.1 = ∑ x : Cells D, r (σ x) := by - rw [Equiv.sum_comp σ r, hsum] - have hh := (Finset.sum_eq_sum_iff_of_le (s := Finset.univ) (fun x _ => hle x)).mp heq - intro x - exact (hh x (Finset.mem_univ x)).symm - -end Thorp.Young - -end - -end OAI +import OAI.Probability.ThorpShuffle.Cyclic + +namespace OAI + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter + +namespace Thorp.Young + +abbrev Cells (D : YoungDiagram) := {p : ℕ × ℕ // p ∈ D.cells} + +lemma fin_le_strictMono {n : ℕ} (f : Fin n → ℕ) (hf : StrictMono f) (i : Fin n) : + i.val ≤ f i := by + have aux : ∀ k (hk : k < n), k ≤ f ⟨k, hk⟩ := by + intro k + induction k with + | zero => intro hk; exact Nat.zero_le _ + | succ k ih => + intro hk + have hk' : k < n := by omega + have hl := hf (show (⟨k, hk'⟩ : Fin n) < ⟨k + 1, hk⟩ from by simp) + have hi := ih hk' + omega + exact aux i.val i.isLt + +lemma card_column (D : YoungDiagram) (j : ℕ) : + (Finset.univ.filter fun x : Cells D => x.val.2 = j).card = D.colLen j := by + classical + let e : {x : Cells D // x.val.2 = j} ≃ Fin (D.colLen j) := { + toFun := fun x => ⟨x.val.val.1, YoungDiagram.mem_iff_lt_colLen.mp (by + have hx : (x.val.val.1, x.val.val.2) ∈ D := x.val.property + simpa only [x.property] using hx)⟩ + invFun := fun i => ⟨⟨(i, j), YoungDiagram.mem_iff_lt_colLen.mpr i.isLt⟩, rfl⟩ + left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext rfl x.property.symm + right_inv := by intro i; rfl } + rw [← Fintype.card_subtype] + exact (Fintype.card_congr e).trans (Fintype.card_fin _) + +lemma card_row_subtype (D : YoungDiagram) (i : ℕ) : + Fintype.card {x : Cells D // x.val.1 = i} = D.rowLen i := by + let e : {x : Cells D // x.val.1 = i} ≃ Fin (D.rowLen i) := { + toFun := fun x => ⟨x.val.val.2, YoungDiagram.mem_iff_lt_rowLen.mp (by + have hx : (x.val.val.1, x.val.val.2) ∈ D := x.val.property + simpa only [x.property] using hx)⟩ + invFun := fun j => ⟨⟨(i, j), YoungDiagram.mem_iff_lt_rowLen.mpr j.isLt⟩, rfl⟩ + left_inv := by intro x; apply Subtype.ext; apply Subtype.ext; exact Prod.ext x.property.symm rfl + right_inv := by intro j; rfl } + exact (Fintype.card_congr e).trans (Fintype.card_fin _) + +lemma eq_of_rowPreserving (D E : YoungDiagram) (e : Cells D ≃ Cells E) + (he : ∀ x, (e x).val.1 = x.val.1) : D = E := by + have hr (i : ℕ) : D.rowLen i = E.rowLen i := by + rw [← card_row_subtype D i, ← card_row_subtype E i] + exact Fintype.card_congr (e.subtypeEquiv (fun x => by rw [he])) + apply YoungDiagram.ext + ext p + obtain ⟨i, j⟩ := p + change (i, j) ∈ D ↔ (i, j) ∈ E + simp only [YoungDiagram.mem_iff_lt_rowLen, hr] + +theorem column_sort_le (D : YoungDiagram) (r : Cells D → ℕ) + (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) + : + ∃ σ : Equiv.Perm (Cells D), (∀ x, (σ x).val.2 = x.val.2) ∧ + ∀ x, x.val.1 ≤ r (σ x) := by + classical + let S (j : ℕ) : Finset ℕ := (Finset.univ.filter fun x : Cells D => x.val.2 = j).image r + have hc (j : ℕ) : (S j).card = D.colLen j := by + change ((Finset.univ.filter fun x : Cells D => x.val.2 = j).image r).card = _ + rw [Finset.card_image_iff.mpr (show Set.InjOn r ↑(Finset.univ.filter fun x : Cells D => x.val.2 = j) from by + intro x hx y hy hxy + exact hinj x y ((Finset.mem_filter.mp hx).2.trans (Finset.mem_filter.mp hy).2.symm) hxy)] + exact card_column D j + let F (j : ℕ) := (S j).orderEmbOfFin (hc j) + have hpre (x : Cells D) : ∃ y : Cells D, y.val.2 = x.val.2 ∧ + r y = F x.val.2 ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ := by + have hm := (S x.val.2).orderEmbOfFin_mem (hc _) ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ + obtain ⟨y, hy, he⟩ := Finset.mem_image.mp hm + exact ⟨y, (Finset.mem_filter.mp hy).2, he⟩ + choose f hcol hr using hpre + have hf : Function.Injective f := by + intro x y he + have hj : x.val.2 = y.val.2 := (hcol x).symm.trans ((congrArg (fun z : Cells D => z.val.2) he).trans (hcol y)) + have hi : x.val.1 = y.val.1 := by + have hval : F x.val.2 ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ = + F y.val.2 ⟨y.val.1, YoungDiagram.mem_iff_lt_colLen.mp y.property⟩ := by + rw [← hr x, ← hr y, he] + have hy : y.val.1 < D.colLen x.val.2 := by rw [hj]; exact YoungDiagram.mem_iff_lt_colLen.mp y.property + have hid : F y.val.2 ⟨y.val.1, YoungDiagram.mem_iff_lt_colLen.mp y.property⟩ = F x.val.2 ⟨y.val.1, hy⟩ := by + have aux (j k i : ℕ) (hk : j = k) (hi : i < D.colLen j) (hi' : i < D.colLen k) : + F j ⟨i, hi⟩ = F k ⟨i, hi'⟩ := by subst k; rfl + exact aux _ _ _ hj.symm _ _ + rw [hid] at hval + exact congrArg Fin.val ((F x.val.2).injective hval) + exact Subtype.ext (Prod.ext hi hj) + let σ : Equiv.Perm (Cells D) := Equiv.ofBijective f ⟨hf, Finite.surjective_of_injective hf⟩ + refine ⟨σ, hcol, ?_⟩ + have hle (x : Cells D) : x.val.1 ≤ r (σ x) := by + change x.val.1 ≤ r (f x) + rw [hr] + exact fin_le_strictMono _ (F x.val.2).strictMono ⟨x.val.1, YoungDiagram.mem_iff_lt_colLen.mp x.property⟩ + exact hle + +lemma rowRankSum_le (D : YoungDiagram) (r : Cells D → ℕ) + (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) : + ∑ x : Cells D, x.val.1 ≤ ∑ x : Cells D, r x := by + obtain ⟨σ, -, hσ⟩ := column_sort_le D r hinj + rw [← Equiv.sum_comp σ r] + exact Finset.sum_le_sum fun x _ => hσ x + +theorem column_sort (D : YoungDiagram) (r : Cells D → ℕ) + (hinj : ∀ x y : Cells D, x.val.2 = y.val.2 → r x = r y → x = y) + (hsum : ∑ x : Cells D, r x = ∑ x : Cells D, x.val.1) : + ∃ σ : Equiv.Perm (Cells D), (∀ x, (σ x).val.2 = x.val.2) ∧ + ∀ x, r (σ x) = x.val.1 := by + obtain ⟨σ, hc, hle⟩ := column_sort_le D r hinj + refine ⟨σ, hc, ?_⟩ + have heq : ∑ x : Cells D, x.val.1 = ∑ x : Cells D, r (σ x) := by + rw [Equiv.sum_comp σ r, hsum] + have hh := (Finset.sum_eq_sum_iff_of_le (s := Finset.univ) (fun x _ => hle x)).mp heq + intro x + exact (hh x (Finset.mem_univ x)).symm + +end Thorp.Young + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/TaggedCompletion.lean b/lean/OAI/Probability/ThorpShuffle/TaggedCompletion.lean index 46bce02174ce9a214bcf406fa671d51be140251b..42f3b0e29f2c5c5da38402a868f943c7da8627b0 100644 --- a/lean/OAI/Probability/ThorpShuffle/TaggedCompletion.lean +++ b/lean/OAI/Probability/ThorpShuffle/TaggedCompletion.lean @@ -1,129 +1,129 @@ -import OAI.Probability.ThorpShuffle.TaggedDeviation - -namespace OAI - -universe uα - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def freeOf {α : Type uα} [DecidableEq α] {k : ℕ} (e : Fin k → α) : α → Bool := - fun y => decide (∀ i, e i ≠ y) - -@[simp] theorem freeOf_exposed {α : Type uα} [DecidableEq α] {k : ℕ} - (e : Fin k → α) (i : Fin k) : freeOf e (e i) = false := by - simp [freeOf] - -@[simp] theorem freeOf_true {α : Type uα} [DecidableEq α] {k : ℕ} - (e : Fin k → α) (y : α) : freeOf e y = true ↔ ∀ i, e i ≠ y := by - simp [freeOf] - -theorem freeOf_perm {α : Type uα} [DecidableEq α] {k : ℕ} - (e : Fin k → α) (g : Equiv.Perm α) (y : α) : - freeOf (g ∘ e) y = freeOf e (g.symm y) := by - simp [freeOf, ← g.eq_symm_apply] - -theorem freeCount_perm {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} - (e : Fin k → α) (g : Equiv.Perm α) : freeCount (freeOf (g ∘ e)) = freeCount (freeOf e) := by - apply Nat.cast_injective (R := ℝ) - rw [← sum_free_indicator, ← sum_free_indicator] - simp only [freeOf_perm] - exact Equiv.sum_comp g.symm (fun x => if freeOf e x then (1 : ℝ) else 0) - -theorem freeCount_freeOf {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} - (e : Fin k → α) (he : Function.Injective e) : freeCount (freeOf e) = Fintype.card α - k := by - have hs : Finset.univ.filter (fun x => freeOf e x = true) = (Finset.univ.image e)ᶜ := by - ext x - simp [freeOf] - unfold freeCount - rw [hs, Finset.card_compl, Finset.card_image_of_injective _ he] - simp - -def completeTest {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} - (f : (Fin (k + 1) → α) → ℝ) (e : Fin k → α) : ℝ := - (1 / (freeCount (freeOf e) : ℝ)) * ∑ y, if freeOf e y then f (Fin.snoc e y) else 0 - -theorem completeTest_bound {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} - (f : (Fin (k + 1) → α) → ℝ) (hf : ∀ e, |f e| ≤ 1) (e : Fin k → α) : - |completeTest f e| ≤ 1 := by - unfold completeTest - rw [abs_mul, abs_of_nonneg (by positivity : (0 : ℝ) ≤ 1 / (freeCount (freeOf e) : ℝ))] - have hs : |∑ y, if freeOf e y then f (Fin.snoc e y) else 0| ≤ freeCount (freeOf e) := by - calc - _ ≤ ∑ y, |if freeOf e y then f (Fin.snoc e y) else 0| := Finset.abs_sum_le_sum_abs _ _ - _ ≤ ∑ y, if freeOf e y then (1 : ℝ) else 0 := Finset.sum_le_sum (fun y _ => by - by_cases h : freeOf e y = true - · simpa only [h, ↓reduceIte] using hf (Fin.snoc e y) - · simp [h]) - _ = _ := sum_free_indicator _ - have hh := mul_le_mul_of_nonneg_left hs - (by positivity : (0 : ℝ) ≤ 1 / (freeCount (freeOf e) : ℝ)) - by_cases hz : freeCount (freeOf e) = 0 - · simp [hz] - · have hn : (freeCount (freeOf e) : ℝ) ≠ 0 := by exact_mod_cast hz - simpa [hn] using hh - -theorem uniform_tagged_completion {α : Type uα} [Fintype α] [DecidableEq α] - {k : ℕ} (e : Fin k → α) (tag : α) (ht : freeOf e tag = true) - (f : (Fin k → α) → α → ℝ) : - mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) = - mean (fun g : Equiv.Perm α => (1 / (freeCount (freeOf e) : ℝ)) * - ∑ y, if freeOf (g ∘ e) y then f (g ∘ e) y else 0) := by - have hm : (freeCount (freeOf e) : ℝ) ≠ 0 := by - exact_mod_cast (freeCount_pos _ tag ht).ne' - have hs (x : α) (hx : freeOf e x = true) : - mean (fun g : Equiv.Perm α => f (g ∘ e) (g x)) = - mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) := by - have heq : (Equiv.swap tag x) ∘ e = e := by - funext i - exact Equiv.swap_apply_of_ne_of_ne ((freeOf_true e tag).mp ht i) - ((freeOf_true e x).mp hx i) - have h := mean_equiv (Equiv.mulRight (Equiv.swap tag x)) - (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) - convert h using 1 - apply mean_congr - intro g - change f (g ∘ e) (g x) = f (g ∘ ((Equiv.swap tag x) ∘ e)) (g (Equiv.swap tag x tag)) - rw [heq, Equiv.swap_apply_left] - symm - calc - _ = mean (fun g : Equiv.Perm α => (1 / (freeCount (freeOf e) : ℝ)) * - ∑ x, if freeOf e x then f (g ∘ e) (g x) else 0) := by - apply mean_congr - intro g - congr 1 - simp only [freeOf_perm] - exact (Equiv.sum_comp g (fun y => if freeOf e (g.symm y) then f (g ∘ e) y else 0)).symm.trans - (by simp only [Equiv.symm_apply_apply]) - _ = (1 / (freeCount (freeOf e) : ℝ)) * - ∑ x, mean (fun g : Equiv.Perm α => if freeOf e x then f (g ∘ e) (g x) else 0) := by - rw [mean_const_mul, mean_sum] - _ = (1 / (freeCount (freeOf e) : ℝ)) * - ∑ x, if freeOf e x then mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) else 0 := by - congr 1 - apply Finset.sum_congr rfl - intro x _ - cases hx : freeOf e x - · simp [mean_zero] - · simpa only [hx, ↓reduceIte] using hs x hx - _ = _ := by - have hid (x : α) : (if freeOf e x then mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) else 0) = - (if freeOf e x then (1 : ℝ) else 0) * mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) := by - cases freeOf e x <;> simp - simp_rw [hid] - rw [← Finset.sum_mul, sum_free_indicator] - field_simp - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.TaggedDeviation + +namespace OAI + +universe uα + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def freeOf {α : Type uα} [DecidableEq α] {k : ℕ} (e : Fin k → α) : α → Bool := + fun y => decide (∀ i, e i ≠ y) + +@[simp] theorem freeOf_exposed {α : Type uα} [DecidableEq α] {k : ℕ} + (e : Fin k → α) (i : Fin k) : freeOf e (e i) = false := by + simp [freeOf] + +@[simp] theorem freeOf_true {α : Type uα} [DecidableEq α] {k : ℕ} + (e : Fin k → α) (y : α) : freeOf e y = true ↔ ∀ i, e i ≠ y := by + simp [freeOf] + +theorem freeOf_perm {α : Type uα} [DecidableEq α] {k : ℕ} + (e : Fin k → α) (g : Equiv.Perm α) (y : α) : + freeOf (g ∘ e) y = freeOf e (g.symm y) := by + simp [freeOf, ← g.eq_symm_apply] + +theorem freeCount_perm {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} + (e : Fin k → α) (g : Equiv.Perm α) : freeCount (freeOf (g ∘ e)) = freeCount (freeOf e) := by + apply Nat.cast_injective (R := ℝ) + rw [← sum_free_indicator, ← sum_free_indicator] + simp only [freeOf_perm] + exact Equiv.sum_comp g.symm (fun x => if freeOf e x then (1 : ℝ) else 0) + +theorem freeCount_freeOf {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} + (e : Fin k → α) (he : Function.Injective e) : freeCount (freeOf e) = Fintype.card α - k := by + have hs : Finset.univ.filter (fun x => freeOf e x = true) = (Finset.univ.image e)ᶜ := by + ext x + simp [freeOf] + unfold freeCount + rw [hs, Finset.card_compl, Finset.card_image_of_injective _ he] + simp + +def completeTest {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} + (f : (Fin (k + 1) → α) → ℝ) (e : Fin k → α) : ℝ := + (1 / (freeCount (freeOf e) : ℝ)) * ∑ y, if freeOf e y then f (Fin.snoc e y) else 0 + +theorem completeTest_bound {α : Type uα} [Fintype α] [DecidableEq α] {k : ℕ} + (f : (Fin (k + 1) → α) → ℝ) (hf : ∀ e, |f e| ≤ 1) (e : Fin k → α) : + |completeTest f e| ≤ 1 := by + unfold completeTest + rw [abs_mul, abs_of_nonneg (by positivity : (0 : ℝ) ≤ 1 / (freeCount (freeOf e) : ℝ))] + have hs : |∑ y, if freeOf e y then f (Fin.snoc e y) else 0| ≤ freeCount (freeOf e) := by + calc + _ ≤ ∑ y, |if freeOf e y then f (Fin.snoc e y) else 0| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ y, if freeOf e y then (1 : ℝ) else 0 := Finset.sum_le_sum (fun y _ => by + by_cases h : freeOf e y = true + · simpa only [h, ↓reduceIte] using hf (Fin.snoc e y) + · simp [h]) + _ = _ := sum_free_indicator _ + have hh := mul_le_mul_of_nonneg_left hs + (by positivity : (0 : ℝ) ≤ 1 / (freeCount (freeOf e) : ℝ)) + by_cases hz : freeCount (freeOf e) = 0 + · simp [hz] + · have hn : (freeCount (freeOf e) : ℝ) ≠ 0 := by exact_mod_cast hz + simpa [hn] using hh + +theorem uniform_tagged_completion {α : Type uα} [Fintype α] [DecidableEq α] + {k : ℕ} (e : Fin k → α) (tag : α) (ht : freeOf e tag = true) + (f : (Fin k → α) → α → ℝ) : + mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) = + mean (fun g : Equiv.Perm α => (1 / (freeCount (freeOf e) : ℝ)) * + ∑ y, if freeOf (g ∘ e) y then f (g ∘ e) y else 0) := by + have hm : (freeCount (freeOf e) : ℝ) ≠ 0 := by + exact_mod_cast (freeCount_pos _ tag ht).ne' + have hs (x : α) (hx : freeOf e x = true) : + mean (fun g : Equiv.Perm α => f (g ∘ e) (g x)) = + mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) := by + have heq : (Equiv.swap tag x) ∘ e = e := by + funext i + exact Equiv.swap_apply_of_ne_of_ne ((freeOf_true e tag).mp ht i) + ((freeOf_true e x).mp hx i) + have h := mean_equiv (Equiv.mulRight (Equiv.swap tag x)) + (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) + convert h using 1 + apply mean_congr + intro g + change f (g ∘ e) (g x) = f (g ∘ ((Equiv.swap tag x) ∘ e)) (g (Equiv.swap tag x tag)) + rw [heq, Equiv.swap_apply_left] + symm + calc + _ = mean (fun g : Equiv.Perm α => (1 / (freeCount (freeOf e) : ℝ)) * + ∑ x, if freeOf e x then f (g ∘ e) (g x) else 0) := by + apply mean_congr + intro g + congr 1 + simp only [freeOf_perm] + exact (Equiv.sum_comp g (fun y => if freeOf e (g.symm y) then f (g ∘ e) y else 0)).symm.trans + (by simp only [Equiv.symm_apply_apply]) + _ = (1 / (freeCount (freeOf e) : ℝ)) * + ∑ x, mean (fun g : Equiv.Perm α => if freeOf e x then f (g ∘ e) (g x) else 0) := by + rw [mean_const_mul, mean_sum] + _ = (1 / (freeCount (freeOf e) : ℝ)) * + ∑ x, if freeOf e x then mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) else 0 := by + congr 1 + apply Finset.sum_congr rfl + intro x _ + cases hx : freeOf e x + · simp [mean_zero] + · simpa only [hx, ↓reduceIte] using hs x hx + _ = _ := by + have hid (x : α) : (if freeOf e x then mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) else 0) = + (if freeOf e x then (1 : ℝ) else 0) * mean (fun g : Equiv.Perm α => f (g ∘ e) (g tag)) := by + cases freeOf e x <;> simp + simp_rw [hid] + rw [← Finset.sum_mul, sum_free_indicator] + field_simp + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/TaggedDeviation.lean b/lean/OAI/Probability/ThorpShuffle/TaggedDeviation.lean index 0f8d4575551f1d792434b9bc67c72aa8683433bb..ffa6a7d66641fcd5eb53b7b0559e3590f2918388 100644 --- a/lean/OAI/Probability/ThorpShuffle/TaggedDeviation.lean +++ b/lean/OAI/Probability/ThorpShuffle/TaggedDeviation.lean @@ -1,84 +1,84 @@ -import OAI.Probability.ThorpShuffle.ConditionalLaw - -namespace OAI - -universe uΩ uα uι - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem mean_sub {Ω : Type uΩ} [Fintype Ω] (f g : Ω → ℝ) : - mean (fun ω => f ω - g ω) = mean f - mean g := by - simp only [mean, Finset.sum_sub_distrib, sub_div] - -theorem abs_mean_le {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) : - |mean f| ≤ mean (fun ω => |f ω|) := by - unfold mean - rw [abs_div, abs_of_nonneg (Nat.cast_nonneg (Fintype.card Ω) : (0 : ℝ) ≤ Fintype.card Ω)] - exact div_le_div_of_nonneg_right (Finset.abs_sum_le_sum_abs _ _) (Nat.cast_nonneg _) - -theorem mean_sq_le {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : - mean f ^ 2 ≤ mean (fun ω => f ω ^ 2) := by - have h := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ f (fun _ => (1 : ℝ)) - simpa only [mul_one, one_pow, Finset.expect_const (Finset.univ_nonempty), - Finset.expect_eq_sum_div_card, Finset.card_univ, mean] using h - -theorem mean_l1_le_sqrt {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] - (w : Ω → α → ℝ) : - mean (fun ω => ∑ x, |w ω x|) ≤ - Real.sqrt ((Fintype.card α : ℝ) * mean (fun ω => ∑ x, w ω x ^ 2)) := by - apply Real.le_sqrt_of_sq_le - calc - _ ≤ mean (fun ω => (∑ x, |w ω x|) ^ 2) := mean_sq_le _ - _ ≤ mean (fun ω => (Fintype.card α : ℝ) * ∑ x, w ω x ^ 2) := by - apply mean_le_mean - intro ω - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ - (fun _ : α => (1 : ℝ)) (fun x => |w ω x|) - simpa only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, - nsmul_eq_mul, mul_one, sq_abs] using h - _ = _ := mean_const_mul _ _ - -theorem mean_weighted_test_le {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] - (w f : Ω → α → ℝ) (hf : ∀ ω x, |f ω x| ≤ 1) : - |mean (fun ω => ∑ x, w ω x * f ω x)| ≤ - Real.sqrt ((Fintype.card α : ℝ) * mean (fun ω => ∑ x, w ω x ^ 2)) := by - calc - _ ≤ mean (fun ω => |∑ x, w ω x * f ω x|) := abs_mean_le _ - _ ≤ mean (fun ω => ∑ x, |w ω x|) := by - apply mean_le_mean - intro ω - calc - _ ≤ ∑ x, |w ω x * f ω x| := Finset.abs_sum_le_sum_abs _ _ - _ ≤ _ := Finset.sum_le_sum (fun x _ => by - rw [abs_mul] - simpa only [mul_one] using mul_le_mul_of_nonneg_left (hf ω x) (abs_nonneg _)) - _ ≤ _ := mean_l1_le_sqrt w - -theorem tagged_deviation_bound {ι : Type uι} (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 : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) - (hf : ∀ e' y, |f e' y| ≤ 1) : - |mean (fun ω : History (d + 1) t => - f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω tag) - - (1 / (freeCount B : ℝ)) * - (∑ y, if B ((run (d + 1) t ω).symm y) then f ((run (d + 1) t ω) ∘ e) y else 0))| ≤ - Real.sqrt ((Fintype.card (Position (d + 1)) : ℝ) * - expectedEnergy d (initialState (d + 1) B tag ht) t) := by - rw [tagged_deviation_identity d B tag ht e he] - exact mean_weighted_test_le _ _ (fun ω y => hf _ y) - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.ConditionalLaw + +namespace OAI + +universe uΩ uα uι + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem mean_sub {Ω : Type uΩ} [Fintype Ω] (f g : Ω → ℝ) : + mean (fun ω => f ω - g ω) = mean f - mean g := by + simp only [mean, Finset.sum_sub_distrib, sub_div] + +theorem abs_mean_le {Ω : Type uΩ} [Fintype Ω] (f : Ω → ℝ) : + |mean f| ≤ mean (fun ω => |f ω|) := by + unfold mean + rw [abs_div, abs_of_nonneg (Nat.cast_nonneg (Fintype.card Ω) : (0 : ℝ) ≤ Fintype.card Ω)] + exact div_le_div_of_nonneg_right (Finset.abs_sum_le_sum_abs _ _) (Nat.cast_nonneg _) + +theorem mean_sq_le {Ω : Type uΩ} [Fintype Ω] [Nonempty Ω] (f : Ω → ℝ) : + mean f ^ 2 ≤ mean (fun ω => f ω ^ 2) := by + have h := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ f (fun _ => (1 : ℝ)) + simpa only [mul_one, one_pow, Finset.expect_const (Finset.univ_nonempty), + Finset.expect_eq_sum_div_card, Finset.card_univ, mean] using h + +theorem mean_l1_le_sqrt {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] + (w : Ω → α → ℝ) : + mean (fun ω => ∑ x, |w ω x|) ≤ + Real.sqrt ((Fintype.card α : ℝ) * mean (fun ω => ∑ x, w ω x ^ 2)) := by + apply Real.le_sqrt_of_sq_le + calc + _ ≤ mean (fun ω => (∑ x, |w ω x|) ^ 2) := mean_sq_le _ + _ ≤ mean (fun ω => (Fintype.card α : ℝ) * ∑ x, w ω x ^ 2) := by + apply mean_le_mean + intro ω + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun _ : α => (1 : ℝ)) (fun x => |w ω x|) + simpa only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, mul_one, sq_abs] using h + _ = _ := mean_const_mul _ _ + +theorem mean_weighted_test_le {Ω : Type uΩ} {α : Type uα} [Fintype Ω] [Nonempty Ω] [Fintype α] + (w f : Ω → α → ℝ) (hf : ∀ ω x, |f ω x| ≤ 1) : + |mean (fun ω => ∑ x, w ω x * f ω x)| ≤ + Real.sqrt ((Fintype.card α : ℝ) * mean (fun ω => ∑ x, w ω x ^ 2)) := by + calc + _ ≤ mean (fun ω => |∑ x, w ω x * f ω x|) := abs_mean_le _ + _ ≤ mean (fun ω => ∑ x, |w ω x|) := by + apply mean_le_mean + intro ω + calc + _ ≤ ∑ x, |w ω x * f ω x| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ _ := Finset.sum_le_sum (fun x _ => by + rw [abs_mul] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (hf ω x) (abs_nonneg _)) + _ ≤ _ := mean_l1_le_sqrt w + +theorem tagged_deviation_bound {ι : Type uι} (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 : ℕ) (f : (ι → Position (d + 1)) → Position (d + 1) → ℝ) + (hf : ∀ e' y, |f e' y| ≤ 1) : + |mean (fun ω : History (d + 1) t => + f ((run (d + 1) t ω) ∘ e) (run (d + 1) t ω tag) - + (1 / (freeCount B : ℝ)) * + (∑ y, if B ((run (d + 1) t ω).symm y) then f ((run (d + 1) t ω) ∘ e) y else 0))| ≤ + Real.sqrt ((Fintype.card (Position (d + 1)) : ℝ) * + expectedEnergy d (initialState (d + 1) B tag ht) t) := by + rw [tagged_deviation_identity d B tag ht e he] + exact mean_weighted_test_le _ _ (fun ω y => hf _ y) + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Trimming.lean b/lean/OAI/Probability/ThorpShuffle/Trimming.lean index 11a8986ea7b6138036cf6d9e78170aae332d5fd1..3bbaf45f5e97a7835c12bec44b584c0eee24ddfc 100644 --- a/lean/OAI/Probability/ThorpShuffle/Trimming.lean +++ b/lean/OAI/Probability/ThorpShuffle/Trimming.lean @@ -1,235 +1,235 @@ -import OAI.Probability.ThorpShuffle.ConvolutionBounds - -namespace OAI - -universe uX uY uΩ uI uG uH uA - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp - -namespace Trim -open scoped Classical - -variable {X : Type uX} {Y : Type uY} [Fintype X] [Fintype Y] - -def push (μ : X → ℝ) (f : X → Y) (y : Y) : ℝ := ∑ x, if f x = y then μ x else 0 - -omit [Fintype Y] in -lemma push_nonneg (μ : X → ℝ) (hμ : ∀ x, 0 ≤ μ x) (f : X → Y) (y : Y) : - 0 ≤ push μ f y := Finset.sum_nonneg (fun x _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) - -lemma push_sum (μ : X → ℝ) (f : X → Y) : ∑ y, push μ f y = ∑ x, μ x := by - unfold push - rw [Finset.sum_comm] - simp - -lemma push_test (μ : X → ℝ) (f : X → Y) (s : Y → ℝ) : - ∑ y, push μ f y * s y = ∑ x, μ x * s (f x) := by - unfold push - simp only [Finset.sum_mul, ite_mul, zero_mul] - rw [Finset.sum_comm] - simp - -omit [Fintype Y] in -lemma push_fairMass {Ω : Type uΩ} [Fintype Ω] (a : Ω → X) (f : X → Y) : - push (fairMass a) f = fairMass (f ∘ a) := by - funext y - have he (x : X) : (if f x = y then fairMass a x else 0) = - (∑ ω, if a ω = x then (if f x = y then (1:ℝ) else 0) else 0) / Fintype.card Ω := by - by_cases h : f x = y <;> simp [h, fairMass] - unfold push - simp_rw [he] - rw [← Finset.sum_div] - unfold fairMass - congr 1 - rw [Finset.sum_comm] - simp - -lemma push_bad_mass (μ υ : X → ℝ) (f : X → Y) - (hm : ∑ x, μ x = ∑ x, υ x) : - (∑ x, if 2 * push υ f (f x) < push μ f (f x) then μ x else 0) ≤ - 2 * tv (push μ f) (push υ f) := by - let s := Finset.univ.filter (fun y => 2 * push υ f y < push μ f y) - have he : (∑ x, if 2 * push υ f (f x) < push μ f (f x) then μ x else 0) = - ∑ y ∈ s, push μ f y := by - rw [Finset.sum_filter] - have ht := push_test μ f (fun y => if 2 * push υ f y < push μ f y then 1 else 0) - simpa only [mul_ite, mul_one, mul_zero] using ht.symm - have ht := sum_sub_le_tv (push μ f) (push υ f) (by simp only [push_sum, hm]) s - have hs : ∑ y ∈ s, push μ f y ≤ 2 * ∑ y ∈ s, (push μ f y - push υ f y) := by - rw [Finset.mul_sum] - exact Finset.sum_le_sum (fun y hy => by have hh := (Finset.mem_filter.mp hy).2; linarith) - rw [he] - linarith - -lemma uniform_eq_fairMass_id : (fun _ : X => (Fintype.card X : ℝ)⁻¹) = fairMass id := by - funext x - simp [fairMass] - -variable {I : Type uI} [Fintype I] -variable {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] - -def cosetMass (ψ : (I → H) →* G) (μ : G → ℝ) (i : I) (g : G) : ℝ := - ∑ h, μ (g * ψ (Pi.mulSingle i h)) - -omit [Fintype I] [Fintype G] in -lemma cosetMass_right (ψ : (I → H) →* G) (μ : G → ℝ) (i : I) (g : G) (a : H) : - cosetMass ψ μ i (g * ψ (Pi.mulSingle i a)) = cosetMass ψ μ i g := by - unfold cosetMass - have he (h : H) : g * ψ (Pi.mulSingle i a) * ψ (Pi.mulSingle i h) = - g * ψ (Pi.mulSingle i (a * h)) := by rw [Pi.mulSingle_mul, map_mul, mul_assoc] - simp_rw [he] - exact Equiv.sum_comp (Equiv.mulLeft a) (fun h => μ (g * ψ (Pi.mulSingle i h))) - -def good (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : Prop := - ∀ i, cosetMass ψ μ i g ≤ 2 * ((Fintype.card H : ℝ) / Fintype.card G) - -def discarded (ψ : (I → H) →* G) (μ : G → ℝ) : ℝ := - ∑ g, if good ψ μ g then 0 else μ g - -def kept (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : ℝ := - if good ψ μ g then μ g else 0 - -def normalized (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : ℝ := - kept ψ μ g / (1 - discarded ψ μ) - -omit [Fintype I] in -lemma discarded_nonneg (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) : - 0 ≤ discarded ψ μ := Finset.sum_nonneg (fun g _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) - -omit [Fintype I] in -lemma kept_add_discarded (ψ : (I → H) →* G) (μ : G → ℝ) : - (∑ g, kept ψ μ g) + discarded ψ μ = ∑ g, μ g := by - rw [discarded, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro g _ - unfold kept - split_ifs <;> ring - -lemma discarded_bound (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) - (h1 : ∑ g, μ g = 1) (A : I → Type uA) [∀ i, Fintype (A i)] (f : ∀ i, G → A i) - (hM : ∀ i g, push μ (f i) (f i g) = cosetMass ψ μ i g) - (hU : ∀ i g, push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) = - (Fintype.card H : ℝ) / Fintype.card G) : - discarded ψ μ ≤ 2 * ∑ i, tv (push μ (f i)) (push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i)) := by - have hu : (∑ _ : G, (Fintype.card G : ℝ)⁻¹) = 1 := by simp [Fintype.card_ne_zero] - have hpoint (g : G) : (if good ψ μ g then 0 else μ g) ≤ - ∑ i, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) - then μ g else 0 := by - simp only [hM, hU] - by_cases hg : good ψ μ g - · rw [ite_eq_left hg] - exact Finset.sum_nonneg (fun i _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) - · rw [ite_eq_right hg] - have ⟨i, hi⟩ : ∃ i, 2 * ((Fintype.card H : ℝ) / Fintype.card G) < cosetMass ψ μ i g := by - simpa only [good, not_forall, not_le] using hg - have hh := Finset.single_le_sum (s := Finset.univ) - (f := fun i => if 2 * ((Fintype.card H : ℝ) / Fintype.card G) < cosetMass ψ μ i g then μ g else 0) - (fun j _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) (Finset.mem_univ i) - simpa only [ite_eq_left hi] using hh - calc - _ ≤ ∑ g, ∑ i, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) - then μ g else 0 := Finset.sum_le_sum (fun g _ => hpoint g) - _ = ∑ i, ∑ g, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) - then μ g else 0 := Finset.sum_comm - _ ≤ ∑ i, 2 * tv (push μ (f i)) (push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i)) := - Finset.sum_le_sum (fun i _ => push_bad_mass _ _ (f i) (h1.trans hu.symm)) - _ = _ := by rw [Finset.mul_sum] - -end Trim - -namespace Trim -open scoped Classical -variable {I : Type uI} {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] - -lemma normalized_nonneg (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) - (hδ : discarded ψ μ < 1) (g : G) : 0 ≤ normalized ψ μ g := by - unfold normalized kept - exact div_nonneg (by split_ifs <;> first | exact hμ _ | exact le_rfl) (by linarith) - -lemma normalized_sum (ψ : (I → H) →* G) (μ : G → ℝ) (h1 : ∑ g, μ g = 1) - (hδ : discarded ψ μ < 1) : ∑ g, normalized ψ μ g = 1 := by - have hk : ∑ g, kept ψ μ g = 1 - discarded ψ μ := by - have hh := kept_add_discarded ψ μ - rw [h1] at hh - linarith - simp only [normalized, ← Finset.sum_div, hk] - exact div_self (by linarith) - -lemma normalized_tv (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) - (h1 : ∑ g, μ g = 1) (hδ : discarded ψ μ < 1) : - tv μ (normalized ψ μ) = discarded ψ μ := by - have hden : 0 < 1 - discarded ψ μ := by linarith - have hd0 := discarded_nonneg ψ μ hμ - have hpt (g : G) : |μ g - normalized ψ μ g| = - normalized ψ μ g - μ g + 2 * (if good ψ μ g then 0 else μ g) := by - by_cases hg : good ψ μ g - · have he : normalized ψ μ g = μ g / (1 - discarded ψ μ) := by simp only [normalized, kept, ite_eq_left hg] - have hle : μ g ≤ normalized ψ μ g := by rw [he]; apply (le_div_iff₀ hden).mpr; nlinarith [hμ g] - rw [abs_of_nonpos (sub_nonpos.mpr hle), ite_eq_left hg] - ring - · simp only [normalized, kept, ite_eq_right hg, zero_div, sub_zero, abs_of_nonneg (hμ g)] - ring - unfold tv - simp only [hpt, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, - normalized_sum ψ μ h1 hδ, h1] - change (1/2 : ℝ) * (1-1+2*discarded ψ μ) = discarded ψ μ - ring - -lemma normalized_coset (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) - (hδ : discarded ψ μ ≤ 1/2) (i : I) (g : G) : - cosetMass ψ (normalized ψ μ) i g ≤ 4 * (Fintype.card H : ℝ) / Fintype.card G := by - have hden : 0 < 1 - discarded ψ μ := by linarith - have hu : 0 ≤ (Fintype.card H : ℝ) / Fintype.card G := by positivity - by_cases hg : cosetMass ψ μ i g ≤ 2 * ((Fintype.card H : ℝ) / Fintype.card G) - · have hle : cosetMass ψ (normalized ψ μ) i g ≤ cosetMass ψ μ i g / (1-discarded ψ μ) := by - simp only [cosetMass, normalized, ← Finset.sum_div] - apply div_le_div_of_nonneg_right _ hden.le - apply Finset.sum_le_sum - intro h _ - unfold kept - split_ifs <;> simp [hμ] - apply hle.trans - apply (div_le_iff₀ hden).mpr - have hh := mul_le_mul_of_nonneg_left (show (1/2 : ℝ) ≤ 1-discarded ψ μ by linarith) (show 0 ≤ 4*((Fintype.card H : ℝ)/Fintype.card G) by positivity) - rw [mul_div_assoc] - nlinarith - · have hz (h : H) : normalized ψ μ (g * ψ (Pi.mulSingle i h)) = 0 := by - have hn : ¬ good ψ μ (g * ψ (Pi.mulSingle i h)) := by - intro hh - have hi := hh i - rw [cosetMass_right] at hi - exact hg hi - simp only [normalized, kept, ite_eq_right hn, zero_div] - simp only [cosetMass, hz, Finset.sum_const_zero] - positivity - -lemma normalized_bias (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) - (h1 : ∑ g, μ g = 1) (hδ : discarded ψ μ < 1) (χ : G → ℂ) - (hχ : ∀ g, ‖χ g‖ ≤ 1) (hb : ∑ g, (μ g : ℂ) * χ g = 0) : - ‖∑ g, (normalized ψ μ g : ℂ) * χ g‖ ≤ 2 * discarded ψ μ := by - have he : (∑ g, (normalized ψ μ g : ℂ) * χ g) = - ∑ g, ((normalized ψ μ g - μ g : ℝ) : ℂ) * χ g := by - simp only [Complex.ofReal_sub, sub_mul, Finset.sum_sub_distrib, hb, sub_zero] - rw [he] - calc - _ ≤ ∑ g, ‖((normalized ψ μ g - μ g : ℝ) : ℂ) * χ g‖ := norm_sum_le _ _ - _ ≤ ∑ g, |normalized ψ μ g - μ g| := by - apply Finset.sum_le_sum - intro g _ - simp only [norm_mul, Complex.norm_real, Real.norm_eq_abs] - simpa only [mul_one] using mul_le_mul_of_nonneg_left (hχ g) (abs_nonneg (normalized ψ μ g - μ g)) - _ = 2 * tv μ (normalized ψ μ) := by simp only [tv, abs_sub_comm]; ring - _ = _ := by rw [normalized_tv ψ μ hμ h1 hδ] - -end Trim - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.ConvolutionBounds + +namespace OAI + +universe uX uY uΩ uI uG uH uA + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp + +namespace Trim +open scoped Classical + +variable {X : Type uX} {Y : Type uY} [Fintype X] [Fintype Y] + +def push (μ : X → ℝ) (f : X → Y) (y : Y) : ℝ := ∑ x, if f x = y then μ x else 0 + +omit [Fintype Y] in +lemma push_nonneg (μ : X → ℝ) (hμ : ∀ x, 0 ≤ μ x) (f : X → Y) (y : Y) : + 0 ≤ push μ f y := Finset.sum_nonneg (fun x _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) + +lemma push_sum (μ : X → ℝ) (f : X → Y) : ∑ y, push μ f y = ∑ x, μ x := by + unfold push + rw [Finset.sum_comm] + simp + +lemma push_test (μ : X → ℝ) (f : X → Y) (s : Y → ℝ) : + ∑ y, push μ f y * s y = ∑ x, μ x * s (f x) := by + unfold push + simp only [Finset.sum_mul, ite_mul, zero_mul] + rw [Finset.sum_comm] + simp + +omit [Fintype Y] in +lemma push_fairMass {Ω : Type uΩ} [Fintype Ω] (a : Ω → X) (f : X → Y) : + push (fairMass a) f = fairMass (f ∘ a) := by + funext y + have he (x : X) : (if f x = y then fairMass a x else 0) = + (∑ ω, if a ω = x then (if f x = y then (1:ℝ) else 0) else 0) / Fintype.card Ω := by + by_cases h : f x = y <;> simp [h, fairMass] + unfold push + simp_rw [he] + rw [← Finset.sum_div] + unfold fairMass + congr 1 + rw [Finset.sum_comm] + simp + +lemma push_bad_mass (μ υ : X → ℝ) (f : X → Y) + (hm : ∑ x, μ x = ∑ x, υ x) : + (∑ x, if 2 * push υ f (f x) < push μ f (f x) then μ x else 0) ≤ + 2 * tv (push μ f) (push υ f) := by + let s := Finset.univ.filter (fun y => 2 * push υ f y < push μ f y) + have he : (∑ x, if 2 * push υ f (f x) < push μ f (f x) then μ x else 0) = + ∑ y ∈ s, push μ f y := by + rw [Finset.sum_filter] + have ht := push_test μ f (fun y => if 2 * push υ f y < push μ f y then 1 else 0) + simpa only [mul_ite, mul_one, mul_zero] using ht.symm + have ht := sum_sub_le_tv (push μ f) (push υ f) (by simp only [push_sum, hm]) s + have hs : ∑ y ∈ s, push μ f y ≤ 2 * ∑ y ∈ s, (push μ f y - push υ f y) := by + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun y hy => by have hh := (Finset.mem_filter.mp hy).2; linarith) + rw [he] + linarith + +lemma uniform_eq_fairMass_id : (fun _ : X => (Fintype.card X : ℝ)⁻¹) = fairMass id := by + funext x + simp [fairMass] + +variable {I : Type uI} [Fintype I] +variable {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] + +def cosetMass (ψ : (I → H) →* G) (μ : G → ℝ) (i : I) (g : G) : ℝ := + ∑ h, μ (g * ψ (Pi.mulSingle i h)) + +omit [Fintype I] [Fintype G] in +lemma cosetMass_right (ψ : (I → H) →* G) (μ : G → ℝ) (i : I) (g : G) (a : H) : + cosetMass ψ μ i (g * ψ (Pi.mulSingle i a)) = cosetMass ψ μ i g := by + unfold cosetMass + have he (h : H) : g * ψ (Pi.mulSingle i a) * ψ (Pi.mulSingle i h) = + g * ψ (Pi.mulSingle i (a * h)) := by rw [Pi.mulSingle_mul, map_mul, mul_assoc] + simp_rw [he] + exact Equiv.sum_comp (Equiv.mulLeft a) (fun h => μ (g * ψ (Pi.mulSingle i h))) + +def good (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : Prop := + ∀ i, cosetMass ψ μ i g ≤ 2 * ((Fintype.card H : ℝ) / Fintype.card G) + +def discarded (ψ : (I → H) →* G) (μ : G → ℝ) : ℝ := + ∑ g, if good ψ μ g then 0 else μ g + +def kept (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : ℝ := + if good ψ μ g then μ g else 0 + +def normalized (ψ : (I → H) →* G) (μ : G → ℝ) (g : G) : ℝ := + kept ψ μ g / (1 - discarded ψ μ) + +omit [Fintype I] in +lemma discarded_nonneg (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) : + 0 ≤ discarded ψ μ := Finset.sum_nonneg (fun g _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) + +omit [Fintype I] in +lemma kept_add_discarded (ψ : (I → H) →* G) (μ : G → ℝ) : + (∑ g, kept ψ μ g) + discarded ψ μ = ∑ g, μ g := by + rw [discarded, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro g _ + unfold kept + split_ifs <;> ring + +lemma discarded_bound (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) + (h1 : ∑ g, μ g = 1) (A : I → Type uA) [∀ i, Fintype (A i)] (f : ∀ i, G → A i) + (hM : ∀ i g, push μ (f i) (f i g) = cosetMass ψ μ i g) + (hU : ∀ i g, push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) = + (Fintype.card H : ℝ) / Fintype.card G) : + discarded ψ μ ≤ 2 * ∑ i, tv (push μ (f i)) (push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i)) := by + have hu : (∑ _ : G, (Fintype.card G : ℝ)⁻¹) = 1 := by simp [Fintype.card_ne_zero] + have hpoint (g : G) : (if good ψ μ g then 0 else μ g) ≤ + ∑ i, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) + then μ g else 0 := by + simp only [hM, hU] + by_cases hg : good ψ μ g + · rw [ite_eq_left hg] + exact Finset.sum_nonneg (fun i _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) + · rw [ite_eq_right hg] + have ⟨i, hi⟩ : ∃ i, 2 * ((Fintype.card H : ℝ) / Fintype.card G) < cosetMass ψ μ i g := by + simpa only [good, not_forall, not_le] using hg + have hh := Finset.single_le_sum (s := Finset.univ) + (f := fun i => if 2 * ((Fintype.card H : ℝ) / Fintype.card G) < cosetMass ψ μ i g then μ g else 0) + (fun j _ => by split_ifs <;> first | exact hμ _ | exact le_rfl) (Finset.mem_univ i) + simpa only [ite_eq_left hi] using hh + calc + _ ≤ ∑ g, ∑ i, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) + then μ g else 0 := Finset.sum_le_sum (fun g _ => hpoint g) + _ = ∑ i, ∑ g, if 2 * push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i) (f i g) < push μ (f i) (f i g) + then μ g else 0 := Finset.sum_comm + _ ≤ ∑ i, 2 * tv (push μ (f i)) (push (fun _ : G => (Fintype.card G : ℝ)⁻¹) (f i)) := + Finset.sum_le_sum (fun i _ => push_bad_mass _ _ (f i) (h1.trans hu.symm)) + _ = _ := by rw [Finset.mul_sum] + +end Trim + +namespace Trim +open scoped Classical +variable {I : Type uI} {G : Type uG} {H : Type uH} [Group G] [Fintype G] [Group H] [Fintype H] + +lemma normalized_nonneg (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) + (hδ : discarded ψ μ < 1) (g : G) : 0 ≤ normalized ψ μ g := by + unfold normalized kept + exact div_nonneg (by split_ifs <;> first | exact hμ _ | exact le_rfl) (by linarith) + +lemma normalized_sum (ψ : (I → H) →* G) (μ : G → ℝ) (h1 : ∑ g, μ g = 1) + (hδ : discarded ψ μ < 1) : ∑ g, normalized ψ μ g = 1 := by + have hk : ∑ g, kept ψ μ g = 1 - discarded ψ μ := by + have hh := kept_add_discarded ψ μ + rw [h1] at hh + linarith + simp only [normalized, ← Finset.sum_div, hk] + exact div_self (by linarith) + +lemma normalized_tv (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) + (h1 : ∑ g, μ g = 1) (hδ : discarded ψ μ < 1) : + tv μ (normalized ψ μ) = discarded ψ μ := by + have hden : 0 < 1 - discarded ψ μ := by linarith + have hd0 := discarded_nonneg ψ μ hμ + have hpt (g : G) : |μ g - normalized ψ μ g| = + normalized ψ μ g - μ g + 2 * (if good ψ μ g then 0 else μ g) := by + by_cases hg : good ψ μ g + · have he : normalized ψ μ g = μ g / (1 - discarded ψ μ) := by simp only [normalized, kept, ite_eq_left hg] + have hle : μ g ≤ normalized ψ μ g := by rw [he]; apply (le_div_iff₀ hden).mpr; nlinarith [hμ g] + rw [abs_of_nonpos (sub_nonpos.mpr hle), ite_eq_left hg] + ring + · simp only [normalized, kept, ite_eq_right hg, zero_div, sub_zero, abs_of_nonneg (hμ g)] + ring + unfold tv + simp only [hpt, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, + normalized_sum ψ μ h1 hδ, h1] + change (1/2 : ℝ) * (1-1+2*discarded ψ μ) = discarded ψ μ + ring + +lemma normalized_coset (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) + (hδ : discarded ψ μ ≤ 1/2) (i : I) (g : G) : + cosetMass ψ (normalized ψ μ) i g ≤ 4 * (Fintype.card H : ℝ) / Fintype.card G := by + have hden : 0 < 1 - discarded ψ μ := by linarith + have hu : 0 ≤ (Fintype.card H : ℝ) / Fintype.card G := by positivity + by_cases hg : cosetMass ψ μ i g ≤ 2 * ((Fintype.card H : ℝ) / Fintype.card G) + · have hle : cosetMass ψ (normalized ψ μ) i g ≤ cosetMass ψ μ i g / (1-discarded ψ μ) := by + simp only [cosetMass, normalized, ← Finset.sum_div] + apply div_le_div_of_nonneg_right _ hden.le + apply Finset.sum_le_sum + intro h _ + unfold kept + split_ifs <;> simp [hμ] + apply hle.trans + apply (div_le_iff₀ hden).mpr + have hh := mul_le_mul_of_nonneg_left (show (1/2 : ℝ) ≤ 1-discarded ψ μ by linarith) (show 0 ≤ 4*((Fintype.card H : ℝ)/Fintype.card G) by positivity) + rw [mul_div_assoc] + nlinarith + · have hz (h : H) : normalized ψ μ (g * ψ (Pi.mulSingle i h)) = 0 := by + have hn : ¬ good ψ μ (g * ψ (Pi.mulSingle i h)) := by + intro hh + have hi := hh i + rw [cosetMass_right] at hi + exact hg hi + simp only [normalized, kept, ite_eq_right hn, zero_div] + simp only [cosetMass, hz, Finset.sum_const_zero] + positivity + +lemma normalized_bias (ψ : (I → H) →* G) (μ : G → ℝ) (hμ : ∀ g, 0 ≤ μ g) + (h1 : ∑ g, μ g = 1) (hδ : discarded ψ μ < 1) (χ : G → ℂ) + (hχ : ∀ g, ‖χ g‖ ≤ 1) (hb : ∑ g, (μ g : ℂ) * χ g = 0) : + ‖∑ g, (normalized ψ μ g : ℂ) * χ g‖ ≤ 2 * discarded ψ μ := by + have he : (∑ g, (normalized ψ μ g : ℂ) * χ g) = + ∑ g, ((normalized ψ μ g - μ g : ℝ) : ℂ) * χ g := by + simp only [Complex.ofReal_sub, sub_mul, Finset.sum_sub_distrib, hb, sub_zero] + rw [he] + calc + _ ≤ ∑ g, ‖((normalized ψ μ g - μ g : ℝ) : ℂ) * χ g‖ := norm_sum_le _ _ + _ ≤ ∑ g, |normalized ψ μ g - μ g| := by + apply Finset.sum_le_sum + intro g _ + simp only [norm_mul, Complex.norm_real, Real.norm_eq_abs] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (hχ g) (abs_nonneg (normalized ψ μ g - μ g)) + _ = 2 * tv μ (normalized ψ μ) := by simp only [tv, abs_sub_comm]; ring + _ = _ := by rw [normalized_tv ψ μ hμ h1 hδ] + +end Trim + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/VectorOrbits.lean b/lean/OAI/Probability/ThorpShuffle/VectorOrbits.lean index 8d4077cfe38a1fa46af0ce8cfcd66c9d373fa11e..b86552a0e78698ace96a977b39920c79f4d0dc1c 100644 --- a/lean/OAI/Probability/ThorpShuffle/VectorOrbits.lean +++ b/lean/OAI/Probability/ThorpShuffle/VectorOrbits.lean @@ -1,187 +1,187 @@ -import OAI.Probability.ThorpShuffle.SymmetricFamilies - -namespace OAI - -universe uG uE uX uH uα - -noncomputable section - -open scoped BigOperators ComplexConjugate InnerProductSpace -open Filter Topology - -namespace Thorp.Specht -open scoped Classical -open Thorp.Young - -variable {G : Type uG} [Group G] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - -lemma cyclic_scalar_mem (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) - (he : ∀ g, ρ g e = χ g • e) (v : E) (hv : v ∈ cyclic ρ e) : - ∃ c : ℂ, c • e = v := by - induction hv using Submodule.span_induction with - | mem v hv => obtain ⟨g, rfl⟩ := hv; exact ⟨χ g, (he g).symm⟩ - | zero => exact ⟨0, zero_smul _ _⟩ - | add x y hx hy ihx ihy => - obtain ⟨a, rfl⟩ := ihx - obtain ⟨b, rfl⟩ := ihy - exact ⟨a+b, add_smul _ _ _⟩ - | smul a x hx ih => - obtain ⟨b, rfl⟩ := ih - exact ⟨a*b, mul_smul _ _ _⟩ - -lemma cyclic_scalar_action (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) - (he : ∀ g, ρ g e = χ g • e) (g : G) (v : (cyclic ρ e).toSubmodule) : - (cyclic ρ e).toRepresentation g v = χ g • v := by - obtain ⟨a, ha⟩ := cyclic_scalar_mem ρ e χ he v.val v.property - apply Subtype.ext - change ρ g v.val = χ g • v.val - rw [← ha, map_smul, he, smul_comm] - -lemma cyclic_scalar_finrank (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) - (he : ∀ g, ρ g e = χ g • e) : Module.finrank ℂ (cyclic ρ e).toSubmodule ≤ 1 := by - apply finrank_le_one (⟨e, self_mem_cyclic ρ e⟩ : (cyclic ρ e).toSubmodule) - intro v - obtain ⟨a, ha⟩ := cyclic_scalar_mem ρ e χ he v.val v.property - exact ⟨a, Subtype.ext ha⟩ - -namespace PermutationSpace -variable {X : Type uX} {H : Type uH} [Fintype X] [MulAction G X] [Group H] [Fintype H] -omit [Fintype X] in -lemma translate_alternator (ι : H →* G) (χ : H →* ℂ) (a : H) - (v : EuclideanSpace ℂ X) : - rep (ι a) (alternator ι χ v) = χ a⁻¹ • alternator ι χ v := by - simp only [alternator_apply, map_sum, Finset.smul_sum] - simp only [map_smul] - have hh := Equiv.sum_comp (Equiv.mulLeft a) - (fun h => χ a⁻¹ • (χ h • (rep (ι h) v : EuclideanSpace ℂ X))) - rw [← hh] - apply Finset.sum_congr rfl - intro h _ - simp only [Equiv.coe_mulLeft, smul_smul, map_mul] - rw [show χ a⁻¹ * (χ a * χ h) = χ h by rw [← mul_assoc, ← map_mul, inv_mul_cancel, map_one, one_mul]] - rfl -end PermutationSpace - -lemma row_zero_of_full (D : YoungDiagram) (h : D.rowLen 0 = Fintype.card (Cells D)) : - ∀ x : Cells D, x.val.1 = 0 := by - have hc : Fintype.card (Lower D) = 0 := by have hh := card_lower_add D; omega - have he : IsEmpty (Lower D) := Fintype.card_eq_zero_iff.mp hc - intro x - by_contra hx - exact he.false ⟨x, hx⟩ - -lemma col_zero_of_full (D : YoungDiagram) (h : D.colLen 0 = Fintype.card (Cells D)) : - ∀ x : Cells D, x.val.2 = 0 := by - have hc : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := by - rw [YoungDiagram.rowLen_transpose, ← Fintype.card_congr (transposeCells D).toEquiv, h] - intro x - exact row_zero_of_full D.transpose hc (transposeCells D x) - -variable {α : Type uα} [Fintype α] - -omit [Fintype α] in -lemma row_rep_action (D : YoungDiagram) (t : α ≃ Cells D) - (h : ∀ x : Cells D, x.val.1 = 0) (g : Equiv.Perm α) - (v : EuclideanSpace ℂ (Tabloid (tableauRow D t))) : tabloidRep D t g v = v := by - ext f - change v (g⁻¹ • f) = v f - apply congrArg (fun a => v a) - apply Subtype.ext - funext x - obtain ⟨a, ha⟩ := f.property - simp only [tabloid_smul_apply, ha, Function.comp_apply, tableauRow, h] - -lemma column_poly_action (D : YoungDiagram) (t : α ≃ Cells D) - (h : ∀ x : Cells D, x.val.2 = 0) (g : Equiv.Perm α) : - tabloidRep D t g (polytabloid D t) = complexSign g • polytabloid D t := by - have hg : g ∈ fiberGroup (tableauCol D t) := by intro x; simp only [tableauCol, h] - have hh := PermutationSpace.translate_alternator (fiberGroup (tableauCol D t)).subtype - (complexSign.comp (fiberGroup (tableauCol D t)).subtype) ⟨g, hg⟩ - (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) - change tabloidRep D t g (polytabloid D t) = complexSign g⁻¹ • polytabloid D t at hh - rwa [complexSign_inv] at hh - -lemma exceptional_action {n : ℕ} (p : NShape n) (hp : defect p = 0) : - degree p = 1 ∧ ((∀ g v, family p g v = v) ∨ - (∀ g v, family p g v = complexSign g • v)) := by - let D := ofPartition p - let t := canonicalTableau p - have hL : longest D = Fintype.card (Cells D) := by - have hh := defect_add_longest p - rw [hp, zero_add] at hh - exact hh.trans (diagram_card p).symm - have hor : D.rowLen 0 = Fintype.card (Cells D) ∨ D.colLen 0 = Fintype.card (Cells D) := by - unfold longest at hL - rcases le_total (D.colLen 0) (D.rowLen 0) with h | h - · exact Or.inl (by rwa [max_eq_left h] at hL) - · exact Or.inr (by rwa [max_eq_right h] at hL) - rcases hor with hr | hc - · have he : ∀ g, tabloidRep D t g (polytabloid D t) = (1 : ℂ) • polytabloid D t := by - intro g; rw [one_smul]; exact row_rep_action D t (row_zero_of_full D hr) g _ - have hd := cyclic_scalar_finrank (tabloidRep D t) (polytabloid D t) (fun _ => 1) he - refine ⟨Nat.le_antisymm hd (degree_pos p), Or.inl ?_⟩ - intro g v - apply Subtype.ext - exact row_rep_action D t (row_zero_of_full D hr) g v.val - · have he := column_poly_action D t (col_zero_of_full D hc) - have hd := cyclic_scalar_finrank (tabloidRep D t) (polytabloid D t) complexSign he - refine ⟨Nat.le_antisymm hd (degree_pos p), Or.inr ?_⟩ - exact cyclic_scalar_action (tabloidRep D t) (polytabloid D t) complexSign he - -end Thorp.Specht - -namespace Thorp.Fourier -open scoped Classical -variable {G : Type} [Group G] [Fintype G] -variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -omit [FiniteDimensional ℂ E] in -lemma sum_rep_invariant (ρ : Representation ℂ G E) (g : G) (v : E) : - ρ g (∑ h, ρ h v) = ∑ h, ρ h v := by - rw [map_sum] - simp only [← Module.End.mul_apply, ← map_mul] - exact Equiv.sum_comp (Equiv.mulLeft g) (fun h => ρ h v) - -omit [Fintype G] [FiniteDimensional ℂ E] in -lemma invariant_finrank_le_one (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (v : E) (hv : v ≠ 0) (hinv : ∀ g, ρ g v = v) : Module.finrank ℂ E ≤ 1 := by - let A : Representation.IntertwiningMap (Representation.trivial ℂ G ℂ) ρ := { - toLinearMap := LinearMap.toSpanSingleton ℂ E v - isIntertwining' := by intro g; ext; simp [Representation.trivial, hinv] } - have hA : A ≠ 0 := by - intro ha - have hh := DFunLike.congr_fun ha 1 - exact hv (by simpa [A] using hh) - have hs := (Representation.IsIrreducible.surjective_or_eq_zero A).resolve_right hA - exact finrank_le_one v hs - -omit [FiniteDimensional ℂ E] in -lemma integrated_uniform_zero (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] - (hd : 1 < Module.finrank ℂ E) : - integrated ρ (fun _ => (Fintype.card G : ℂ)⁻¹) = 0 := by - have hz (v : E) : (∑ h, ρ h v) = 0 := by - by_contra hn - have hh := invariant_finrank_le_one ρ _ hn (fun g => sum_rep_invariant ρ g v) - omega - ext v - simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, ← Finset.smul_sum, hz, smul_zero, - LinearMap.zero_apply] - -omit [FiniteDimensional ℂ E] in -lemma integrated_scalar (ρ : Representation ℂ G E) (χ : G → ℂ) - (hχ : ∀ g v, ρ g v = χ g • v) (f : G → ℂ) : - integrated ρ f = (∑ g, f g * χ g) • LinearMap.id := by - ext v - simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, hχ, smul_smul, - Finset.sum_smul, LinearMap.id_apply] - -lemma hsSq_scalar (c : ℂ) : hsSq (c • (LinearMap.id : Module.End ℂ E)) = - (Module.finrank ℂ E : ℝ) * ‖c‖^2 := by - simp [hsSq, norm_smul, (stdOrthonormalBasis ℂ E).norm_eq_one] - -end Thorp.Fourier - -end - -end OAI +import OAI.Probability.ThorpShuffle.SymmetricFamilies + +namespace OAI + +universe uG uE uX uH uα + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace +open Filter Topology + +namespace Thorp.Specht +open scoped Classical +open Thorp.Young + +variable {G : Type uG} [Group G] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +lemma cyclic_scalar_mem (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) + (he : ∀ g, ρ g e = χ g • e) (v : E) (hv : v ∈ cyclic ρ e) : + ∃ c : ℂ, c • e = v := by + induction hv using Submodule.span_induction with + | mem v hv => obtain ⟨g, rfl⟩ := hv; exact ⟨χ g, (he g).symm⟩ + | zero => exact ⟨0, zero_smul _ _⟩ + | add x y hx hy ihx ihy => + obtain ⟨a, rfl⟩ := ihx + obtain ⟨b, rfl⟩ := ihy + exact ⟨a+b, add_smul _ _ _⟩ + | smul a x hx ih => + obtain ⟨b, rfl⟩ := ih + exact ⟨a*b, mul_smul _ _ _⟩ + +lemma cyclic_scalar_action (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) + (he : ∀ g, ρ g e = χ g • e) (g : G) (v : (cyclic ρ e).toSubmodule) : + (cyclic ρ e).toRepresentation g v = χ g • v := by + obtain ⟨a, ha⟩ := cyclic_scalar_mem ρ e χ he v.val v.property + apply Subtype.ext + change ρ g v.val = χ g • v.val + rw [← ha, map_smul, he, smul_comm] + +lemma cyclic_scalar_finrank (ρ : Representation ℂ G E) (e : E) (χ : G → ℂ) + (he : ∀ g, ρ g e = χ g • e) : Module.finrank ℂ (cyclic ρ e).toSubmodule ≤ 1 := by + apply finrank_le_one (⟨e, self_mem_cyclic ρ e⟩ : (cyclic ρ e).toSubmodule) + intro v + obtain ⟨a, ha⟩ := cyclic_scalar_mem ρ e χ he v.val v.property + exact ⟨a, Subtype.ext ha⟩ + +namespace PermutationSpace +variable {X : Type uX} {H : Type uH} [Fintype X] [MulAction G X] [Group H] [Fintype H] +omit [Fintype X] in +lemma translate_alternator (ι : H →* G) (χ : H →* ℂ) (a : H) + (v : EuclideanSpace ℂ X) : + rep (ι a) (alternator ι χ v) = χ a⁻¹ • alternator ι χ v := by + simp only [alternator_apply, map_sum, Finset.smul_sum] + simp only [map_smul] + have hh := Equiv.sum_comp (Equiv.mulLeft a) + (fun h => χ a⁻¹ • (χ h • (rep (ι h) v : EuclideanSpace ℂ X))) + rw [← hh] + apply Finset.sum_congr rfl + intro h _ + simp only [Equiv.coe_mulLeft, smul_smul, map_mul] + rw [show χ a⁻¹ * (χ a * χ h) = χ h by rw [← mul_assoc, ← map_mul, inv_mul_cancel, map_one, one_mul]] + rfl +end PermutationSpace + +lemma row_zero_of_full (D : YoungDiagram) (h : D.rowLen 0 = Fintype.card (Cells D)) : + ∀ x : Cells D, x.val.1 = 0 := by + have hc : Fintype.card (Lower D) = 0 := by have hh := card_lower_add D; omega + have he : IsEmpty (Lower D) := Fintype.card_eq_zero_iff.mp hc + intro x + by_contra hx + exact he.false ⟨x, hx⟩ + +lemma col_zero_of_full (D : YoungDiagram) (h : D.colLen 0 = Fintype.card (Cells D)) : + ∀ x : Cells D, x.val.2 = 0 := by + have hc : D.transpose.rowLen 0 = Fintype.card (Cells D.transpose) := by + rw [YoungDiagram.rowLen_transpose, ← Fintype.card_congr (transposeCells D).toEquiv, h] + intro x + exact row_zero_of_full D.transpose hc (transposeCells D x) + +variable {α : Type uα} [Fintype α] + +omit [Fintype α] in +lemma row_rep_action (D : YoungDiagram) (t : α ≃ Cells D) + (h : ∀ x : Cells D, x.val.1 = 0) (g : Equiv.Perm α) + (v : EuclideanSpace ℂ (Tabloid (tableauRow D t))) : tabloidRep D t g v = v := by + ext f + change v (g⁻¹ • f) = v f + apply congrArg (fun a => v a) + apply Subtype.ext + funext x + obtain ⟨a, ha⟩ := f.property + simp only [tabloid_smul_apply, ha, Function.comp_apply, tableauRow, h] + +lemma column_poly_action (D : YoungDiagram) (t : α ≃ Cells D) + (h : ∀ x : Cells D, x.val.2 = 0) (g : Equiv.Perm α) : + tabloidRep D t g (polytabloid D t) = complexSign g • polytabloid D t := by + have hg : g ∈ fiberGroup (tableauCol D t) := by intro x; simp only [tableauCol, h] + have hh := PermutationSpace.translate_alternator (fiberGroup (tableauCol D t)).subtype + (complexSign.comp (fiberGroup (tableauCol D t)).subtype) ⟨g, hg⟩ + (EuclideanSpace.single (baseTabloid (tableauRow D t)) (1 : ℂ)) + change tabloidRep D t g (polytabloid D t) = complexSign g⁻¹ • polytabloid D t at hh + rwa [complexSign_inv] at hh + +lemma exceptional_action {n : ℕ} (p : NShape n) (hp : defect p = 0) : + degree p = 1 ∧ ((∀ g v, family p g v = v) ∨ + (∀ g v, family p g v = complexSign g • v)) := by + let D := ofPartition p + let t := canonicalTableau p + have hL : longest D = Fintype.card (Cells D) := by + have hh := defect_add_longest p + rw [hp, zero_add] at hh + exact hh.trans (diagram_card p).symm + have hor : D.rowLen 0 = Fintype.card (Cells D) ∨ D.colLen 0 = Fintype.card (Cells D) := by + unfold longest at hL + rcases le_total (D.colLen 0) (D.rowLen 0) with h | h + · exact Or.inl (by rwa [max_eq_left h] at hL) + · exact Or.inr (by rwa [max_eq_right h] at hL) + rcases hor with hr | hc + · have he : ∀ g, tabloidRep D t g (polytabloid D t) = (1 : ℂ) • polytabloid D t := by + intro g; rw [one_smul]; exact row_rep_action D t (row_zero_of_full D hr) g _ + have hd := cyclic_scalar_finrank (tabloidRep D t) (polytabloid D t) (fun _ => 1) he + refine ⟨Nat.le_antisymm hd (degree_pos p), Or.inl ?_⟩ + intro g v + apply Subtype.ext + exact row_rep_action D t (row_zero_of_full D hr) g v.val + · have he := column_poly_action D t (col_zero_of_full D hc) + have hd := cyclic_scalar_finrank (tabloidRep D t) (polytabloid D t) complexSign he + refine ⟨Nat.le_antisymm hd (degree_pos p), Or.inr ?_⟩ + exact cyclic_scalar_action (tabloidRep D t) (polytabloid D t) complexSign he + +end Thorp.Specht + +namespace Thorp.Fourier +open scoped Classical +variable {G : Type} [Group G] [Fintype G] +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +omit [FiniteDimensional ℂ E] in +lemma sum_rep_invariant (ρ : Representation ℂ G E) (g : G) (v : E) : + ρ g (∑ h, ρ h v) = ∑ h, ρ h v := by + rw [map_sum] + simp only [← Module.End.mul_apply, ← map_mul] + exact Equiv.sum_comp (Equiv.mulLeft g) (fun h => ρ h v) + +omit [Fintype G] [FiniteDimensional ℂ E] in +lemma invariant_finrank_le_one (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (v : E) (hv : v ≠ 0) (hinv : ∀ g, ρ g v = v) : Module.finrank ℂ E ≤ 1 := by + let A : Representation.IntertwiningMap (Representation.trivial ℂ G ℂ) ρ := { + toLinearMap := LinearMap.toSpanSingleton ℂ E v + isIntertwining' := by intro g; ext; simp [Representation.trivial, hinv] } + have hA : A ≠ 0 := by + intro ha + have hh := DFunLike.congr_fun ha 1 + exact hv (by simpa [A] using hh) + have hs := (Representation.IsIrreducible.surjective_or_eq_zero A).resolve_right hA + exact finrank_le_one v hs + +omit [FiniteDimensional ℂ E] in +lemma integrated_uniform_zero (ρ : Representation ℂ G E) [Representation.IsIrreducible ρ] + (hd : 1 < Module.finrank ℂ E) : + integrated ρ (fun _ => (Fintype.card G : ℂ)⁻¹) = 0 := by + have hz (v : E) : (∑ h, ρ h v) = 0 := by + by_contra hn + have hh := invariant_finrank_le_one ρ _ hn (fun g => sum_rep_invariant ρ g v) + omega + ext v + simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, ← Finset.smul_sum, hz, smul_zero, + LinearMap.zero_apply] + +omit [FiniteDimensional ℂ E] in +lemma integrated_scalar (ρ : Representation ℂ G E) (χ : G → ℂ) + (hχ : ∀ g v, ρ g v = χ g • v) (f : G → ℂ) : + integrated ρ f = (∑ g, f g * χ g) • LinearMap.id := by + ext v + simp only [integrated, LinearMap.sum_apply, LinearMap.smul_apply, hχ, smul_smul, + Finset.sum_smul, LinearMap.id_apply] + +lemma hsSq_scalar (c : ℂ) : hsSq (c • (LinearMap.id : Module.End ℂ E)) = + (Module.finrank ℂ E : ℝ) * ‖c‖^2 := by + simp [hsSq, norm_smul, (stdOrthonormalBasis ℂ E).norm_eq_one] + +end Thorp.Fourier + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/Walsh.lean b/lean/OAI/Probability/ThorpShuffle/Walsh.lean index ec528adc915029628e1ab5503207d0232b0b1a38..3245991198375b7bf33d017c2d120e4a3889b50d 100644 --- a/lean/OAI/Probability/ThorpShuffle/Walsh.lean +++ b/lean/OAI/Probability/ThorpShuffle/Walsh.lean @@ -1,132 +1,132 @@ -import OAI.Probability.ThorpShuffle.PairAveraging - -namespace OAI - -universe uι uκ - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -def character {ι : Type uι} [Fintype ι] (a x : ι → Bool) : ℝ := - ∏ i, if a i then sign (x i) else 1 - -theorem character_symm {ι : Type uι} [Fintype ι] (a x : ι → Bool) : - character a x = character x a := by - apply Finset.prod_congr rfl - intro i _ - cases a i <;> cases x i <;> rfl - -@[simp] theorem character_false {ι : Type uι} [Fintype ι] (x : ι → Bool) : - character (fun _ => false) x = 1 := by - simp [character] - -@[simp] theorem character_sq {ι : Type uι} [Fintype ι] (a x : ι → Bool) : - character a x ^ 2 = 1 := by - unfold character - rw [← Finset.prod_pow] - have h (i : ι) : (if a i then sign (x i) else (1 : ℝ)) ^ 2 = 1 := by - cases a i <;> simp - simp only [h, Finset.prod_const_one] - -theorem sum_character_pair {ι : Type uι} [Fintype ι] [DecidableEq ι] - (a b : ι → Bool) : - (∑ x : ι → Bool, character a x * character b x) = - if a = b then (Fintype.card (ι → Bool) : ℝ) else 0 := by - have hlocal (u v : Bool) : - (∑ x : Bool, (if u then sign x else (1 : ℝ)) * (if v then sign x else 1)) = - if u = v then 2 else 0 := by - cases u <;> cases v <;> norm_num [sign] - have hf : (∑ x : ι → Bool, character a x * character b x) = - ∏ i, (if a i = b i then (2 : ℝ) else 0) := by - calc - _ = ∑ x : ι → Bool, ∏ i, - (if a i then sign (x i) else (1 : ℝ)) * (if b i then sign (x i) else 1) := by - apply Finset.sum_congr rfl - intro x _ - exact (Finset.prod_mul_distrib).symm - _ = ∏ i, ∑ x : Bool, - (if a i then sign x else (1 : ℝ)) * (if b i then sign x else 1) := - (Fintype.prod_sum (fun (i : ι) (x : Bool) => - (if a i then sign x else (1 : ℝ)) * (if b i then sign x else 1))).symm - _ = _ := by simp only [hlocal] - rw [hf] - by_cases h : a = b - · subst b - simp - · rw [ite_eq_right h] - have hn : ¬ ∀ i, a i = b i := fun he => h (funext he) - obtain ⟨i, hi⟩ := not_forall.mp hn - exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [hi]) - -theorem sum_character_pair_dual {ι : Type uι} [Fintype ι] [DecidableEq ι] - (x y : ι → Bool) : - (∑ a : ι → Bool, character a x * character a y) = - if x = y then (Fintype.card (ι → Bool) : ℝ) else 0 := by - calc - _ = ∑ a : ι → Bool, character x a * character y a := by - apply Finset.sum_congr rfl - intro a _ - rw [character_symm a x, character_symm a y] - _ = _ := sum_character_pair x y - -def coefficient {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) (a : ι → Bool) : ℝ := - ∑ x, w x * character a x - -theorem parseval {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) : - mean (fun a : ι → Bool => coefficient w a ^ 2) = ∑ x, w x ^ 2 := by - have hs : - (∑ a : ι → Bool, coefficient w a ^ 2) = - (Fintype.card (ι → Bool) : ℝ) * ∑ x, w x ^ 2 := by - calc - _ = ∑ a : ι → Bool, ∑ x, ∑ y, - (character a x * character a y) * (w x * w y) := by - apply Finset.sum_congr rfl - intro a _ - simp only [coefficient, pow_two, Finset.sum_mul, Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - ring - _ = ∑ x, ∑ y, (∑ a : ι → Bool, character a x * character a y) * (w x * w y) := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - rw [Finset.sum_comm] - simp only [Finset.sum_mul] - _ = _ := by - simp only [sum_character_pair_dual, ite_mul, zero_mul] - simp [Finset.mul_sum, pow_two] - unfold mean - rw [hs] - have hcard : (Fintype.card (ι → Bool) : ℝ) ≠ 0 := by - exact_mod_cast Fintype.card_ne_zero - exact mul_div_cancel_left₀ _ hcard - -@[simp] theorem coefficient_false {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) : - coefficient w (fun _ => false) = ∑ x, w x := by - simp [coefficient] - -theorem character_reindex {ι : Type uι} {κ : Type uκ} [Fintype ι] [Fintype κ] - (e : ι ≃ κ) (a x : κ → Bool) : - character (a ∘ e) (x ∘ e) = character a x := by - exact Equiv.prod_comp e (fun i => if a i then sign (x i) else 1) - -theorem character_cons (d : ℕ) (h b : Bool) (a x : Position d) : - character (Fin.cons h a) (Fin.cons b x) = - (if h then sign b else 1) * character a x := by - simp [character, Fin.prod_univ_succ] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.PairAveraging + +namespace OAI + +universe uι uκ + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +def character {ι : Type uι} [Fintype ι] (a x : ι → Bool) : ℝ := + ∏ i, if a i then sign (x i) else 1 + +theorem character_symm {ι : Type uι} [Fintype ι] (a x : ι → Bool) : + character a x = character x a := by + apply Finset.prod_congr rfl + intro i _ + cases a i <;> cases x i <;> rfl + +@[simp] theorem character_false {ι : Type uι} [Fintype ι] (x : ι → Bool) : + character (fun _ => false) x = 1 := by + simp [character] + +@[simp] theorem character_sq {ι : Type uι} [Fintype ι] (a x : ι → Bool) : + character a x ^ 2 = 1 := by + unfold character + rw [← Finset.prod_pow] + have h (i : ι) : (if a i then sign (x i) else (1 : ℝ)) ^ 2 = 1 := by + cases a i <;> simp + simp only [h, Finset.prod_const_one] + +theorem sum_character_pair {ι : Type uι} [Fintype ι] [DecidableEq ι] + (a b : ι → Bool) : + (∑ x : ι → Bool, character a x * character b x) = + if a = b then (Fintype.card (ι → Bool) : ℝ) else 0 := by + have hlocal (u v : Bool) : + (∑ x : Bool, (if u then sign x else (1 : ℝ)) * (if v then sign x else 1)) = + if u = v then 2 else 0 := by + cases u <;> cases v <;> norm_num [sign] + have hf : (∑ x : ι → Bool, character a x * character b x) = + ∏ i, (if a i = b i then (2 : ℝ) else 0) := by + calc + _ = ∑ x : ι → Bool, ∏ i, + (if a i then sign (x i) else (1 : ℝ)) * (if b i then sign (x i) else 1) := by + apply Finset.sum_congr rfl + intro x _ + exact (Finset.prod_mul_distrib).symm + _ = ∏ i, ∑ x : Bool, + (if a i then sign x else (1 : ℝ)) * (if b i then sign x else 1) := + (Fintype.prod_sum (fun (i : ι) (x : Bool) => + (if a i then sign x else (1 : ℝ)) * (if b i then sign x else 1))).symm + _ = _ := by simp only [hlocal] + rw [hf] + by_cases h : a = b + · subst b + simp + · rw [ite_eq_right h] + have hn : ¬ ∀ i, a i = b i := fun he => h (funext he) + obtain ⟨i, hi⟩ := not_forall.mp hn + exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [hi]) + +theorem sum_character_pair_dual {ι : Type uι} [Fintype ι] [DecidableEq ι] + (x y : ι → Bool) : + (∑ a : ι → Bool, character a x * character a y) = + if x = y then (Fintype.card (ι → Bool) : ℝ) else 0 := by + calc + _ = ∑ a : ι → Bool, character x a * character y a := by + apply Finset.sum_congr rfl + intro a _ + rw [character_symm a x, character_symm a y] + _ = _ := sum_character_pair x y + +def coefficient {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) (a : ι → Bool) : ℝ := + ∑ x, w x * character a x + +theorem parseval {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) : + mean (fun a : ι → Bool => coefficient w a ^ 2) = ∑ x, w x ^ 2 := by + have hs : + (∑ a : ι → Bool, coefficient w a ^ 2) = + (Fintype.card (ι → Bool) : ℝ) * ∑ x, w x ^ 2 := by + calc + _ = ∑ a : ι → Bool, ∑ x, ∑ y, + (character a x * character a y) * (w x * w y) := by + apply Finset.sum_congr rfl + intro a _ + simp only [coefficient, pow_two, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + _ = ∑ x, ∑ y, (∑ a : ι → Bool, character a x * character a y) * (w x * w y) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_comm] + simp only [Finset.sum_mul] + _ = _ := by + simp only [sum_character_pair_dual, ite_mul, zero_mul] + simp [Finset.mul_sum, pow_two] + unfold mean + rw [hs] + have hcard : (Fintype.card (ι → Bool) : ℝ) ≠ 0 := by + exact_mod_cast Fintype.card_ne_zero + exact mul_div_cancel_left₀ _ hcard + +@[simp] theorem coefficient_false {ι : Type uι} [Fintype ι] [DecidableEq ι] (w : (ι → Bool) → ℝ) : + coefficient w (fun _ => false) = ∑ x, w x := by + simp [coefficient] + +theorem character_reindex {ι : Type uι} {κ : Type uκ} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (a x : κ → Bool) : + character (a ∘ e) (x ∘ e) = character a x := by + exact Equiv.prod_comp e (fun i => if a i then sign (x i) else 1) + +theorem character_cons (d : ℕ) (h b : Bool) (a x : Position d) : + character (Fin.cons h a) (Fin.cons b x) = + (if h then sign b else 1) * character a x := by + simp [character, Fin.prod_univ_succ] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThorpShuffle/WalshFlow.lean b/lean/OAI/Probability/ThorpShuffle/WalshFlow.lean index dc5bc6423d3a7d6b6fe6d205d0a870e41141b6a1..258c232a796d4187ec206cc49185226793483be2 100644 --- a/lean/OAI/Probability/ThorpShuffle/WalshFlow.lean +++ b/lean/OAI/Probability/ThorpShuffle/WalshFlow.lean @@ -1,231 +1,231 @@ -import OAI.Probability.ThorpShuffle.FiniteExpectation - -namespace OAI - -universe uΩ - -noncomputable section - -open scoped BigOperators -open Filter - -namespace Thorp - -namespace Conditional - -theorem scatterPosition_eq_snoc (d : ℕ) (b : Bool) (x : Position d) : - scatterPosition d (b, x) = Fin.snoc x b := by - rw [Fin.snoc_eq_cons_rotate] - ext i - simp only [scatterPosition, splitPosition, Equiv.trans_apply, Equiv.symm_symm, - Fin.consEquiv_apply, rotate, Equiv.piCongrLeft_apply] - simp - -theorem character_snoc (d : ℕ) (h b : Bool) (a x : Position d) : - character (Fin.snoc a h) (Fin.snoc x b) = - character a x * (if h then sign b else 1) := by - simp [character, Fin.prod_univ_castSucc] - -theorem coefficient_physicalFlow_even (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (a : Position d) : - coefficient (physicalFlow d B w c) (Fin.snoc a false) = - coefficient w (Fin.cons false a) := by - unfold coefficient - rw [← Equiv.sum_comp (scatterPosition d) - (fun x => physicalFlow d B w c x * character (Fin.snoc a false) x)] - rw [← Equiv.sum_comp (splitPosition d).symm - (fun x => w x * character (Fin.cons false a) x)] - simp only [Fintype.sum_prod_type] - simp only [Fintype.sum_bool] - rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro x _ - simp only [physicalFlow_scatter] - simp only [scatterPosition_eq_snoc, character_snoc, - Bool.false_eq_true, ↓reduceIte, mul_one] - change flow _ _ c (true, x) * character a x + - flow _ _ c (false, x) * character a x = - w (Fin.cons true x) * character (Fin.cons false a) (Fin.cons true x) + - w (Fin.cons false x) * character (Fin.cons false a) (Fin.cons false x) - rw [character_cons, character_cons] - simp only [Bool.false_eq_true, ↓reduceIte, one_mul] - rw [← add_mul, ← add_mul] - congr 1 - simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm, Function.comp_apply, - splitPosition, Equiv.symm_symm, Fin.consEquiv, Equiv.coe_fn_mk] using - pairUpdate_sum (B (Fin.cons false x)) (B (Fin.cons true x)) - (w (Fin.cons false x)) (w (Fin.cons true x)) (c x) - -theorem coefficient_physicalFlow_odd (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (a : Position d) : - coefficient (physicalFlow d B w c) (Fin.snoc a true) = - oddCoefficient (character a) (flow (B ∘ (splitPosition d).symm) - (w ∘ (splitPosition d).symm) c) := by - unfold coefficient - rw [← Equiv.sum_comp (scatterPosition d) - (fun x => physicalFlow d B w c x * character (Fin.snoc a true) x)] - simp only [Fintype.sum_prod_type, Fintype.sum_bool] - rw [← Finset.sum_add_distrib] - unfold oddCoefficient - apply Finset.sum_congr rfl - intro x _ - simp only [physicalFlow_scatter] - simp only [scatterPosition_eq_snoc, character_snoc, - ↓reduceIte, sign, Bool.false_eq_true] - ring - -def oneFreeEnergy (d : ℕ) (B : Position (d + 1) → Bool) - (w : Position (d + 1) → ℝ) : ℝ := - ∑ x : Position d, - ((if B (Fin.cons true x) then 0 else w (Fin.cons false x) ^ 2) + - (if B (Fin.cons false x) then 0 else w (Fin.cons true x) ^ 2)) - -theorem mean_coefficient_physicalFlow_odd_sq (d : ℕ) - (B : Position (d + 1) → Bool) (w : Position (d + 1) → ℝ) - (hw : ∀ x, B x = false → w x = 0) (a : Position d) : - mean (fun c : Coins (d + 1) => - coefficient (physicalFlow d B w c) (Fin.snoc a true) ^ 2) = - oneFreeEnergy d B w := by - simp_rw [coefficient_physicalFlow_odd] - exact mean_oddCoefficient_sq _ _ _ (fun p => hw ((splitPosition d).symm p)) - (character_sq a) - -end Conditional - -namespace Conditional - -def prefixZero {d : ℕ} (j : ℕ) (a : Position d) : Prop := - ∀ i : Fin d, i.val < j → a i = false - -instance prefixZeroDecidable {d : ℕ} (j : ℕ) (a : Position d) : - Decidable (prefixZero j a) := by - unfold prefixZero - infer_instance - -@[simp] theorem prefixZero_zero {d : ℕ} (a : Position d) : prefixZero 0 a := by - intro i hi - omega - -theorem prefixZero_full {d : ℕ} (a : Position d) : - prefixZero d a ↔ a = fun _ => false := by - constructor - · intro h - funext i - exact h i i.isLt - · intro h - subst a - intro i _ - rfl - -theorem prefixZero_cons (j d : ℕ) (h : Bool) (a : Position d) : - prefixZero (j + 1) (Fin.cons h a) ↔ h = false ∧ prefixZero j a := by - constructor - · intro hp - refine ⟨?_, ?_⟩ - · simpa using hp 0 (by simp) - · intro i hi - simpa using hp i.succ (by simpa using hi) - · rintro ⟨rfl, hp⟩ i - refine Fin.cases ?_ (fun k => ?_) i - · intro _; rfl - · intro hi - exact hp k (by simpa using hi) - -theorem prefixZero_snoc (j d : ℕ) (hj : j ≤ d) (h : Bool) (a : Position d) : - prefixZero j (Fin.snoc a h) ↔ prefixZero j a := by - constructor - · intro hp i hi - simpa using hp i.castSucc hi - · intro hp i hi - have hid : i.val < d := lt_of_lt_of_le hi hj - rw [Fin.snoc, dite_eq_left hid] - exact hp _ hi - -theorem prefixZero_count (j d : ℕ) (hj : j ≤ d) : - (∑ a : Position d, if prefixZero j a then (1 : ℝ) else 0) = 2 ^ (d - j) := by - classical - induction d generalizing j with - | zero => - have : j = 0 := by omega - subst j - simp - | succ d ih => - cases j with - | zero => simp [Fintype.card_pi, Fintype.card_bool] - | succ j => - rw [← Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)) - (fun a => if prefixZero (j + 1) a then (1 : ℝ) else 0)] - simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_prod_type, Fintype.sum_bool, - prefixZero_cons] - simpa using ih j (by omega) - -def bandEnergy (d : ℕ) (w : Position d → ℝ) (j : ℕ) : ℝ := by - classical - exact ∑ a : Position d, if prefixZero j a then coefficient w a ^ 2 else 0 - -@[simp] theorem bandEnergy_zero (d : ℕ) (w : Position d → ℝ) : - bandEnergy d w 0 = (Fintype.card (Position d) : ℝ) * ∑ x, w x ^ 2 := by - have hp := parseval w - unfold mean at hp - have hc : (Fintype.card (Position d) : ℝ) ≠ 0 := by - exact_mod_cast Fintype.card_ne_zero - have hsum : (∑ a, coefficient w a ^ 2) = - (Fintype.card (Position d) : ℝ) * ∑ x, w x ^ 2 := by - rw [div_eq_iff hc] at hp - linarith - simpa [bandEnergy] using hsum - -@[simp] theorem bandEnergy_full (d : ℕ) (w : Position d → ℝ) : - bandEnergy d w d = (∑ x, w x) ^ 2 := by - classical - simp [bandEnergy, prefixZero_full] - -theorem bandEnergy_cons (d j : ℕ) (w : Position (d + 1) → ℝ) : - bandEnergy (d + 1) w (j + 1) = - ∑ a : Position d, if prefixZero j a then coefficient w (Fin.cons false a) ^ 2 else 0 := by - classical - unfold bandEnergy - rw [← Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)) - (fun a => if prefixZero (j + 1) a then coefficient w a ^ 2 else 0)] - simp [Fintype.sum_prod_type, prefixZero_cons, Fin.consEquiv] - -theorem mean_indicator {Ω : Type uΩ} [Fintype Ω] (p : Prop) [Decidable p] (f : Ω → ℝ) : - mean (fun ω => if p then f ω else 0) = if p then mean f else 0 := by - by_cases hp : p <;> simp [hp, mean_zero] - -theorem mean_bandEnergy_physicalFlow (d j : ℕ) (hj : j ≤ d) - (B : Position (d + 1) → Bool) (w : Position (d + 1) → ℝ) - (hw : ∀ x, B x = false → w x = 0) : - mean (fun c : Coins (d + 1) => bandEnergy (d + 1) (physicalFlow d B w c) j) = - bandEnergy (d + 1) w (j + 1) + 2 ^ (d - j) * oneFreeEnergy d B w := by - classical - have hs (c : Coins (d + 1)) : - bandEnergy (d + 1) (physicalFlow d B w c) j = - (∑ a : Position d, if prefixZero j a then - coefficient (physicalFlow d B w c) (Fin.snoc a true) ^ 2 else 0) + - (∑ a : Position d, if prefixZero j a then - coefficient w (Fin.cons false a) ^ 2 else 0) := by - unfold bandEnergy - rw [← Equiv.sum_comp (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)) - (fun a => if prefixZero j a then coefficient (physicalFlow d B w c) a ^ 2 else 0)] - simp only [Fintype.sum_prod_type, Fintype.sum_bool, Fin.snocEquiv, Equiv.coe_fn_mk, - prefixZero_snoc j d hj, coefficient_physicalFlow_even] - simp_rw [hs] - rw [mean_add, mean_sum, mean_const, bandEnergy_cons] - simp_rw [mean_indicator, mean_coefficient_physicalFlow_odd_sq d B w hw] - have hcount : - (∑ a : Position d, if prefixZero j a then oneFreeEnergy d B w else 0) = - 2 ^ (d - j) * oneFreeEnergy d B w := by - rw [← prefixZero_count j d hj, Finset.sum_mul] - apply Finset.sum_congr rfl - intro a _ - split_ifs <;> simp - rw [hcount, add_comm] - -end Conditional - -end Thorp - -end - -end OAI +import OAI.Probability.ThorpShuffle.FiniteExpectation + +namespace OAI + +universe uΩ + +noncomputable section + +open scoped BigOperators +open Filter + +namespace Thorp + +namespace Conditional + +theorem scatterPosition_eq_snoc (d : ℕ) (b : Bool) (x : Position d) : + scatterPosition d (b, x) = Fin.snoc x b := by + rw [Fin.snoc_eq_cons_rotate] + ext i + simp only [scatterPosition, splitPosition, Equiv.trans_apply, Equiv.symm_symm, + Fin.consEquiv_apply, rotate, Equiv.piCongrLeft_apply] + simp + +theorem character_snoc (d : ℕ) (h b : Bool) (a x : Position d) : + character (Fin.snoc a h) (Fin.snoc x b) = + character a x * (if h then sign b else 1) := by + simp [character, Fin.prod_univ_castSucc] + +theorem coefficient_physicalFlow_even (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (a : Position d) : + coefficient (physicalFlow d B w c) (Fin.snoc a false) = + coefficient w (Fin.cons false a) := by + unfold coefficient + rw [← Equiv.sum_comp (scatterPosition d) + (fun x => physicalFlow d B w c x * character (Fin.snoc a false) x)] + rw [← Equiv.sum_comp (splitPosition d).symm + (fun x => w x * character (Fin.cons false a) x)] + simp only [Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro x _ + simp only [physicalFlow_scatter] + simp only [scatterPosition_eq_snoc, character_snoc, + Bool.false_eq_true, ↓reduceIte, mul_one] + change flow _ _ c (true, x) * character a x + + flow _ _ c (false, x) * character a x = + w (Fin.cons true x) * character (Fin.cons false a) (Fin.cons true x) + + w (Fin.cons false x) * character (Fin.cons false a) (Fin.cons false x) + rw [character_cons, character_cons] + simp only [Bool.false_eq_true, ↓reduceIte, one_mul] + rw [← add_mul, ← add_mul] + congr 1 + simpa only [flow, Bool.false_eq_true, ↓reduceIte, add_comm, Function.comp_apply, + splitPosition, Equiv.symm_symm, Fin.consEquiv, Equiv.coe_fn_mk] using + pairUpdate_sum (B (Fin.cons false x)) (B (Fin.cons true x)) + (w (Fin.cons false x)) (w (Fin.cons true x)) (c x) + +theorem coefficient_physicalFlow_odd (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) (c : Coins (d + 1)) (a : Position d) : + coefficient (physicalFlow d B w c) (Fin.snoc a true) = + oddCoefficient (character a) (flow (B ∘ (splitPosition d).symm) + (w ∘ (splitPosition d).symm) c) := by + unfold coefficient + rw [← Equiv.sum_comp (scatterPosition d) + (fun x => physicalFlow d B w c x * character (Fin.snoc a true) x)] + simp only [Fintype.sum_prod_type, Fintype.sum_bool] + rw [← Finset.sum_add_distrib] + unfold oddCoefficient + apply Finset.sum_congr rfl + intro x _ + simp only [physicalFlow_scatter] + simp only [scatterPosition_eq_snoc, character_snoc, + ↓reduceIte, sign, Bool.false_eq_true] + ring + +def oneFreeEnergy (d : ℕ) (B : Position (d + 1) → Bool) + (w : Position (d + 1) → ℝ) : ℝ := + ∑ x : Position d, + ((if B (Fin.cons true x) then 0 else w (Fin.cons false x) ^ 2) + + (if B (Fin.cons false x) then 0 else w (Fin.cons true x) ^ 2)) + +theorem mean_coefficient_physicalFlow_odd_sq (d : ℕ) + (B : Position (d + 1) → Bool) (w : Position (d + 1) → ℝ) + (hw : ∀ x, B x = false → w x = 0) (a : Position d) : + mean (fun c : Coins (d + 1) => + coefficient (physicalFlow d B w c) (Fin.snoc a true) ^ 2) = + oneFreeEnergy d B w := by + simp_rw [coefficient_physicalFlow_odd] + exact mean_oddCoefficient_sq _ _ _ (fun p => hw ((splitPosition d).symm p)) + (character_sq a) + +end Conditional + +namespace Conditional + +def prefixZero {d : ℕ} (j : ℕ) (a : Position d) : Prop := + ∀ i : Fin d, i.val < j → a i = false + +instance prefixZeroDecidable {d : ℕ} (j : ℕ) (a : Position d) : + Decidable (prefixZero j a) := by + unfold prefixZero + infer_instance + +@[simp] theorem prefixZero_zero {d : ℕ} (a : Position d) : prefixZero 0 a := by + intro i hi + omega + +theorem prefixZero_full {d : ℕ} (a : Position d) : + prefixZero d a ↔ a = fun _ => false := by + constructor + · intro h + funext i + exact h i i.isLt + · intro h + subst a + intro i _ + rfl + +theorem prefixZero_cons (j d : ℕ) (h : Bool) (a : Position d) : + prefixZero (j + 1) (Fin.cons h a) ↔ h = false ∧ prefixZero j a := by + constructor + · intro hp + refine ⟨?_, ?_⟩ + · simpa using hp 0 (by simp) + · intro i hi + simpa using hp i.succ (by simpa using hi) + · rintro ⟨rfl, hp⟩ i + refine Fin.cases ?_ (fun k => ?_) i + · intro _; rfl + · intro hi + exact hp k (by simpa using hi) + +theorem prefixZero_snoc (j d : ℕ) (hj : j ≤ d) (h : Bool) (a : Position d) : + prefixZero j (Fin.snoc a h) ↔ prefixZero j a := by + constructor + · intro hp i hi + simpa using hp i.castSucc hi + · intro hp i hi + have hid : i.val < d := lt_of_lt_of_le hi hj + rw [Fin.snoc, dite_eq_left hid] + exact hp _ hi + +theorem prefixZero_count (j d : ℕ) (hj : j ≤ d) : + (∑ a : Position d, if prefixZero j a then (1 : ℝ) else 0) = 2 ^ (d - j) := by + classical + induction d generalizing j with + | zero => + have : j = 0 := by omega + subst j + simp + | succ d ih => + cases j with + | zero => simp [Fintype.card_pi, Fintype.card_bool] + | succ j => + rw [← Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)) + (fun a => if prefixZero (j + 1) a then (1 : ℝ) else 0)] + simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_prod_type, Fintype.sum_bool, + prefixZero_cons] + simpa using ih j (by omega) + +def bandEnergy (d : ℕ) (w : Position d → ℝ) (j : ℕ) : ℝ := by + classical + exact ∑ a : Position d, if prefixZero j a then coefficient w a ^ 2 else 0 + +@[simp] theorem bandEnergy_zero (d : ℕ) (w : Position d → ℝ) : + bandEnergy d w 0 = (Fintype.card (Position d) : ℝ) * ∑ x, w x ^ 2 := by + have hp := parseval w + unfold mean at hp + have hc : (Fintype.card (Position d) : ℝ) ≠ 0 := by + exact_mod_cast Fintype.card_ne_zero + have hsum : (∑ a, coefficient w a ^ 2) = + (Fintype.card (Position d) : ℝ) * ∑ x, w x ^ 2 := by + rw [div_eq_iff hc] at hp + linarith + simpa [bandEnergy] using hsum + +@[simp] theorem bandEnergy_full (d : ℕ) (w : Position d → ℝ) : + bandEnergy d w d = (∑ x, w x) ^ 2 := by + classical + simp [bandEnergy, prefixZero_full] + +theorem bandEnergy_cons (d j : ℕ) (w : Position (d + 1) → ℝ) : + bandEnergy (d + 1) w (j + 1) = + ∑ a : Position d, if prefixZero j a then coefficient w (Fin.cons false a) ^ 2 else 0 := by + classical + unfold bandEnergy + rw [← Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (d + 1) => Bool)) + (fun a => if prefixZero (j + 1) a then coefficient w a ^ 2 else 0)] + simp [Fintype.sum_prod_type, prefixZero_cons, Fin.consEquiv] + +theorem mean_indicator {Ω : Type uΩ} [Fintype Ω] (p : Prop) [Decidable p] (f : Ω → ℝ) : + mean (fun ω => if p then f ω else 0) = if p then mean f else 0 := by + by_cases hp : p <;> simp [hp, mean_zero] + +theorem mean_bandEnergy_physicalFlow (d j : ℕ) (hj : j ≤ d) + (B : Position (d + 1) → Bool) (w : Position (d + 1) → ℝ) + (hw : ∀ x, B x = false → w x = 0) : + mean (fun c : Coins (d + 1) => bandEnergy (d + 1) (physicalFlow d B w c) j) = + bandEnergy (d + 1) w (j + 1) + 2 ^ (d - j) * oneFreeEnergy d B w := by + classical + have hs (c : Coins (d + 1)) : + bandEnergy (d + 1) (physicalFlow d B w c) j = + (∑ a : Position d, if prefixZero j a then + coefficient (physicalFlow d B w c) (Fin.snoc a true) ^ 2 else 0) + + (∑ a : Position d, if prefixZero j a then + coefficient w (Fin.cons false a) ^ 2 else 0) := by + unfold bandEnergy + rw [← Equiv.sum_comp (Fin.snocEquiv (fun _ : Fin (d + 1) => Bool)) + (fun a => if prefixZero j a then coefficient (physicalFlow d B w c) a ^ 2 else 0)] + simp only [Fintype.sum_prod_type, Fintype.sum_bool, Fin.snocEquiv, Equiv.coe_fn_mk, + prefixZero_snoc j d hj, coefficient_physicalFlow_even] + simp_rw [hs] + rw [mean_add, mean_sum, mean_const, bandEnergy_cons] + simp_rw [mean_indicator, mean_coefficient_physicalFlow_odd_sq d B w hw] + have hcount : + (∑ a : Position d, if prefixZero j a then oneFreeEnergy d B w else 0) = + 2 ^ (d - j) * oneFreeEnergy d B w := by + rw [← prefixZero_count j d hj, Finset.sum_mul] + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + rw [hcount, add_comm] + +end Conditional + +end Thorp + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Basic.lean b/lean/OAI/Probability/ThreeState/Basic.lean index 9d016426a824db3aae7a54ff89cf30301aebeec9..f7d00d16fbca29621cc2e6fd8c848035c8e742d2 100644 --- a/lean/OAI/Probability/ThreeState/Basic.lean +++ b/lean/OAI/Probability/ThreeState/Basic.lean @@ -1,285 +1,285 @@ -import Mathlib - -namespace OAI - -/-! Three-state symmetric broadcast experiments, posterior advantage and total variation. -/ - -namespace ThreeState - -abbrev Spin := Fin 3 - - -def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1 - - -noncomputable def channel (lam : ℝ) (i j : Spin) : ℝ := - if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3 - - - -def Observation : ℕ → Type - | 0 => Spin - | n + 1 => Multiset (Observation n) - -theorem channel_nonneg {lam : ℝ} (h : Admissible lam) (i j : Spin) : - 0 ≤ channel lam i j := by - unfold channel - split_ifs - · dsimp [Admissible] at h - linarith [h.1] - · dsimp [Admissible] at h - linarith [h.2] - -theorem channel_sum (lam : ℝ) (i : Spin) : ∑ j, channel lam i j = 1 := by - fin_cases i <;> simp [channel, Fin.sum_univ_succ] <;> ring - -noncomputable def channelPMF (lam : ℝ) (h : Admissible lam) (i : Spin) : PMF Spin := - PMF.ofFintype (fun j => ENNReal.ofReal (channel lam i j)) (by - rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ => channel_nonneg h i j)] - simp [channel_sum]) - - -noncomputable def iidList {α : Type*} (p : PMF α) : ℕ → PMF (List α) - | 0 => PMF.pure [] - | n + 1 => p.bind fun a => (iidList p n).map (List.cons a) - - - -noncomputable def observedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - (n : ℕ) → Spin → PMF (Observation n) - | 0, i => PMF.pure i - | n + 1, i => offspring.bind fun k => - (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h n)) k).map - (fun xs : List (Observation n) => (xs : Multiset (Observation n))) - -noncomputable def uniformSpin : PMF Spin := PMF.ofFintype (fun _ => 1 / 3) (by - simp - exact ENNReal.mul_inv_cancel (by norm_num) (by finiteness)) - - -noncomputable def marginal {α : Type*} (law : Spin → PMF α) : PMF α := - uniformSpin.bind law - - -noncomputable def posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : ℝ := - if marginal law y = 0 then 1 / 3 - else (law i y).toReal / (3 * (marginal law y).toReal) - - - -noncomputable def advantage {α : Type*} (law : Spin → PMF α) : ℝ := - ∑' y, (marginal law y).toReal * - ((∑ i : Spin, |posterior law y i - 1 / 3|) / 2) - -noncomputable def regularLaw (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) := - observedLaw (PMF.pure b) lam h n - - -noncomputable def poissonOffspring (d : ℝ) (hd : 0 ≤ d) : PMF ℕ := by - refine ⟨fun k => ENNReal.ofReal (Real.exp (-d) * d ^ k / (k.factorial : ℝ)), ?_⟩ - apply ENNReal.hasSum_coe.2 - have hsum : HasSum (fun k : ℕ => Real.exp (-d) * d ^ k / (k.factorial : ℝ)) 1 := - ProbabilityTheory.hasSum_one_poissonMeasure ⟨d, hd⟩ - simpa using hsum.toNNReal (fun k => by positivity) - -noncomputable def poissonLaw (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) - (h : Admissible lam) (n : ℕ) := - observedLaw (poissonOffspring d hd) lam h n - -noncomputable def regularAdvantage (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : ℝ := - advantage (regularLaw b lam h n) - -noncomputable def poissonAdvantage (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) (n : ℕ) : ℝ := - advantage (poissonLaw d (le_trans (by norm_num) hd.le) lam h n) - - -def Reconstructs (a : ℕ → ℝ) : Prop := - ∃ L : ℝ, 0 < L ∧ Filter.Tendsto a Filter.atTop (nhds L) - - -def Nonreconstructs (a : ℕ → ℝ) : Prop := - Filter.Tendsto a Filter.atTop (nhds 0) - -end ThreeState -namespace ThreeState - -noncomputable def mass {α : Type*} (p : PMF α) (a : α) : ℝ := (p a).toReal - -lemma mass_nonneg {α : Type*} (p : PMF α) (a : α) : 0 ≤ mass p a := ENNReal.toReal_nonneg -lemma mass_sum {α : Type*} (p : PMF α) : ∑' a, mass p a = 1 := by - simp only [mass, ← ENNReal.tsum_toReal_eq (fun a => p.apply_ne_top a), p.tsum_coe, - ENNReal.toReal_one] -lemma mass_summable {α : Type*} (p : PMF α) : Summable (mass p) := - ENNReal.summable_toReal p.tsum_coe_ne_top - -lemma mass_bind {α β : Type*} (p : PMF α) (k : α → PMF β) (b : β) : - mass (p.bind k) b = ∑' a, mass p a * mass (k a) b := by - simp only [mass, PMF.bind_apply, ENNReal.tsum_toReal_eq - (fun a => ENNReal.mul_ne_top (p.apply_ne_top a) ((k a).apply_ne_top b)), ENNReal.toReal_mul] - -lemma mass_uniform (i : Spin) : mass uniformSpin i = 1/3 := by - simp [mass, uniformSpin, PMF.ofFintype_apply] - -lemma mass_marginal {α : Type*} (law : Spin → PMF α) (y : α) : - mass (marginal law) y = (∑ i : Spin, mass (law i) y)/3 := by - simp only [marginal, mass_bind, tsum_fintype, mass_uniform] - rw [← Finset.mul_sum] - ring - -lemma mass_eq_zero {α : Type*} (p : PMF α) (a : α) : mass p a = 0 ↔ p a = 0 := by - simp [mass, ENNReal.toReal_eq_zero_iff, p.apply_ne_top a] - -lemma marginal_zero {α : Type*} (law : Spin → PMF α) (y : α) - (h : marginal law y = 0) (i : Spin) : law i y = 0 := by - apply (mass_eq_zero (law i) y).mp - have hh : mass (marginal law) y = 0 := (mass_eq_zero _ _).mpr h - rw [mass_marginal] at hh - have hs : ∑ j : Spin, mass (law j) y = 0 := by linarith - exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => mass_nonneg (law j) y)).mp hs i (by simp) - -lemma posterior_nonneg {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - 0 ≤ posterior law y i := by - unfold posterior - split_ifs <;> positivity - -lemma posterior_sum {α : Type*} (law : Spin → PMF α) (y : α) : - ∑ i : Spin, posterior law y i = 1 := by - classical - have hn := (marginal law).apply_ne_top y - by_cases h : marginal law y = 0 - · simp [posterior, h] - · have hm : mass (marginal law) y ≠ 0 := mt (mass_eq_zero _ _).mp h - simp only [posterior, ite_eq_right h, ← Finset.sum_div] - change (∑ i : Spin, mass (law i) y)/(3*mass (marginal law) y) = 1 - have he := mass_marginal law y - field_simp - linarith - - -lemma weighted_posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - mass (marginal law) y * (posterior law y i-1/3) = - (mass (law i) y-mass (marginal law) y)/3 := by - classical - by_cases h : marginal law y = 0 - · have hi := marginal_zero law y h i - simp [mass, h, hi, posterior] - · have hm : mass (marginal law) y ≠ 0 := mt (mass_eq_zero _ _).mp h - simp only [posterior, ite_eq_right h] - change mass (marginal law) y * (mass (law i) y / (3*mass (marginal law) y)-1/3) = _ - field_simp - -lemma weighted_abs_posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - mass (marginal law) y * |posterior law y i-1/3| = - |mass (law i) y-mass (marginal law) y|/3 := by - calc - mass (marginal law) y * |posterior law y i-1/3| = - |mass (marginal law) y * (posterior law y i-1/3)| := by - rw [abs_mul, abs_of_nonneg (mass_nonneg (marginal law) y)] - _ = _ := by rw [weighted_posterior, abs_div]; norm_num - -lemma mass_le_one {α : Type*} (p : PMF α) (a : α) : mass p a ≤ 1 := by - simpa [mass] using ENNReal.toReal_mono (by finiteness) (p.coe_le_one a) - -noncomputable def tvMass {α : Type*} (p q : PMF α) : ℝ := - (∑' a, |mass p a-mass q a|)/2 - -lemma mass_diff_summable {α : Type*} (p q : PMF α) : - Summable (fun a => |mass p a-mass q a|) := - ((mass_summable p).sub (mass_summable q)).abs - -lemma tvMass_nonneg {α : Type*} (p q : PMF α) : 0 ≤ tvMass p q := by - exact div_nonneg (tsum_nonneg (fun a => abs_nonneg _)) (by norm_num) - -lemma tvMass_le_one {α : Type*} (p q : PMF α) : tvMass p q ≤ 1 := by - have h := (mass_diff_summable p q).tsum_le_tsum - (fun a => (abs_sub (mass p a) (mass q a)).trans_eq (by - rw [abs_of_nonneg (mass_nonneg p a), abs_of_nonneg (mass_nonneg q a)])) - ((mass_summable p).add (mass_summable q)) - rw [(mass_summable p).tsum_add (mass_summable q), mass_sum, mass_sum] at h - dsimp [tvMass] - linarith - -lemma advantage_eq_tvMass {α : Type*} (law : Spin → PMF α) : - advantage law = (∑ i : Spin, tvMass (law i) (marginal law))/3 := by - have ht (y : α) : mass (marginal law) y * - ((∑ i : Spin, |posterior law y i-1/3|)/2) = - (∑ i : Spin, |mass (law i) y-mass (marginal law) y|)/6 := by - rw [← mul_div_assoc, Finset.mul_sum] - simp_rw [weighted_abs_posterior] - rw [← Finset.sum_div] - ring - change (∑' y, mass (marginal law) y * - ((∑ i : Spin, |posterior law y i-1/3|)/2)) = _ - simp_rw [ht] - rw [tsum_div_const, Summable.tsum_finsetSum (fun i _ => mass_diff_summable (law i) (marginal law))] - simp only [tvMass, ← Finset.sum_div] - ring - -lemma advantage_nonneg {α : Type*} (law : Spin → PMF α) : 0 ≤ advantage law := by - rw [advantage_eq_tvMass] - exact div_nonneg (Finset.sum_nonneg (fun i _ => tvMass_nonneg _ _)) (by norm_num) - -lemma advantage_le_one {α : Type*} (law : Spin → PMF α) : advantage law ≤ 1 := by - rw [advantage_eq_tvMass] - have h := Finset.sum_le_sum (s := Finset.univ) (fun (i : Spin) _ => tvMass_le_one (law i) (marginal law)) - norm_num at h - linarith - -lemma kernel_mass_summable {α β : Type*} (p : PMF α) (k : α → PMF β) (b : β) : - Summable (fun a => mass p a*mass (k a) b) := by - apply Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (mass_nonneg (k a) b)) - (fun a => mul_le_of_le_one_right (mass_nonneg p a) (mass_le_one (k a) b)) - (mass_summable p) - -lemma weighted_kernel_summable {α β : Type*} (p q : PMF α) (k : α → PMF β) (b : β) : - Summable (fun a => |mass p a-mass q a| *mass (k a) b) := by - apply Summable.of_nonneg_of_le (fun a => mul_nonneg (abs_nonneg _) (mass_nonneg (k a) b)) - (fun a => mul_le_of_le_one_right (abs_nonneg _) (mass_le_one (k a) b)) - (mass_diff_summable p q) - -lemma mass_diff_bind_le {α β : Type*} (p q : PMF α) (k : α → PMF β) (b : β) : - |mass (p.bind k) b-mass (q.bind k) b| ≤ - ∑' a, |mass p a-mass q a| *mass (k a) b := by - rw [mass_bind, mass_bind, ← (kernel_mass_summable p k b).tsum_sub (kernel_mass_summable q k b)] - simp_rw [← sub_mul] - have hnorm : Summable (fun a => ‖(mass p a-mass q a)*mass (k a) b‖) := - (weighted_kernel_summable p q k b).congr (fun a => by - rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg (k a) b)]) - simpa only [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg (k _) b)] using - norm_tsum_le_tsum_norm hnorm - -lemma tvMass_bind_le {α β : Type*} (p q : PMF α) (k : α → PMF β) : - tvMass (p.bind k) (q.bind k) ≤ tvMass p q := by - have hrow (a : α) : (∑' b, |mass p a-mass q a| *mass (k a) b) = - |mass p a-mass q a| := by - rw [(mass_summable (k a)).tsum_mul_left, mass_sum, mul_one] - have hs : Summable (Function.uncurry (fun a b => |mass p a-mass q a| *mass (k a) b)) := by - apply (summable_prod_of_nonneg (fun ab => mul_nonneg (abs_nonneg _) (mass_nonneg _ _))).mpr - change (∀ a, Summable (fun b => |mass p a-mass q a| * mass (k a) b)) ∧ - Summable (fun a => ∑' b, |mass p a-mass q a| * mass (k a) b) - constructor - · intro a - exact (mass_summable (k a)).mul_left |mass p a-mass q a| - · - simpa only [hrow] using mass_diff_summable p q - have h := Summable.tsum_le_tsum (mass_diff_bind_le p q k) - (mass_diff_summable (p.bind k) (q.bind k)) hs.prod_symm.prod - rw [hs.tsum_comm] at h - simp_rw [hrow] at h - exact div_le_div_of_nonneg_right h (by norm_num) - -lemma marginal_bind {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - marginal (fun i => (law i).bind k) = (marginal law).bind k := by - simp only [marginal, PMF.bind_bind] - - -theorem advantage_bind_le {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - advantage (fun i => (law i).bind k) ≤ advantage law := by - rw [advantage_eq_tvMass, advantage_eq_tvMass, marginal_bind] - exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun i _ => tvMass_bind_le (law i) (marginal law) k)) - (by norm_num) - -end ThreeState - -end OAI +import Mathlib + +namespace OAI + +/-! Three-state symmetric broadcast experiments, posterior advantage and total variation. -/ + +namespace ThreeState + +abbrev Spin := Fin 3 + + +def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1 + + +noncomputable def channel (lam : ℝ) (i j : Spin) : ℝ := + if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3 + + + +def Observation : ℕ → Type + | 0 => Spin + | n + 1 => Multiset (Observation n) + +theorem channel_nonneg {lam : ℝ} (h : Admissible lam) (i j : Spin) : + 0 ≤ channel lam i j := by + unfold channel + split_ifs + · dsimp [Admissible] at h + linarith [h.1] + · dsimp [Admissible] at h + linarith [h.2] + +theorem channel_sum (lam : ℝ) (i : Spin) : ∑ j, channel lam i j = 1 := by + fin_cases i <;> simp [channel, Fin.sum_univ_succ] <;> ring + +noncomputable def channelPMF (lam : ℝ) (h : Admissible lam) (i : Spin) : PMF Spin := + PMF.ofFintype (fun j => ENNReal.ofReal (channel lam i j)) (by + rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ => channel_nonneg h i j)] + simp [channel_sum]) + + +noncomputable def iidList {α : Type*} (p : PMF α) : ℕ → PMF (List α) + | 0 => PMF.pure [] + | n + 1 => p.bind fun a => (iidList p n).map (List.cons a) + + + +noncomputable def observedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + (n : ℕ) → Spin → PMF (Observation n) + | 0, i => PMF.pure i + | n + 1, i => offspring.bind fun k => + (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h n)) k).map + (fun xs : List (Observation n) => (xs : Multiset (Observation n))) + +noncomputable def uniformSpin : PMF Spin := PMF.ofFintype (fun _ => 1 / 3) (by + simp + exact ENNReal.mul_inv_cancel (by norm_num) (by finiteness)) + + +noncomputable def marginal {α : Type*} (law : Spin → PMF α) : PMF α := + uniformSpin.bind law + + +noncomputable def posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : ℝ := + if marginal law y = 0 then 1 / 3 + else (law i y).toReal / (3 * (marginal law y).toReal) + + + +noncomputable def advantage {α : Type*} (law : Spin → PMF α) : ℝ := + ∑' y, (marginal law y).toReal * + ((∑ i : Spin, |posterior law y i - 1 / 3|) / 2) + +noncomputable def regularLaw (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) := + observedLaw (PMF.pure b) lam h n + + +noncomputable def poissonOffspring (d : ℝ) (hd : 0 ≤ d) : PMF ℕ := by + refine ⟨fun k => ENNReal.ofReal (Real.exp (-d) * d ^ k / (k.factorial : ℝ)), ?_⟩ + apply ENNReal.hasSum_coe.2 + have hsum : HasSum (fun k : ℕ => Real.exp (-d) * d ^ k / (k.factorial : ℝ)) 1 := + ProbabilityTheory.hasSum_one_poissonMeasure ⟨d, hd⟩ + simpa using hsum.toNNReal (fun k => by positivity) + +noncomputable def poissonLaw (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) + (h : Admissible lam) (n : ℕ) := + observedLaw (poissonOffspring d hd) lam h n + +noncomputable def regularAdvantage (b : ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : ℝ := + advantage (regularLaw b lam h n) + +noncomputable def poissonAdvantage (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) (n : ℕ) : ℝ := + advantage (poissonLaw d (le_trans (by norm_num) hd.le) lam h n) + + +def Reconstructs (a : ℕ → ℝ) : Prop := + ∃ L : ℝ, 0 < L ∧ Filter.Tendsto a Filter.atTop (nhds L) + + +def Nonreconstructs (a : ℕ → ℝ) : Prop := + Filter.Tendsto a Filter.atTop (nhds 0) + +end ThreeState +namespace ThreeState + +noncomputable def mass {α : Type*} (p : PMF α) (a : α) : ℝ := (p a).toReal + +lemma mass_nonneg {α : Type*} (p : PMF α) (a : α) : 0 ≤ mass p a := ENNReal.toReal_nonneg +lemma mass_sum {α : Type*} (p : PMF α) : ∑' a, mass p a = 1 := by + simp only [mass, ← ENNReal.tsum_toReal_eq (fun a => p.apply_ne_top a), p.tsum_coe, + ENNReal.toReal_one] +lemma mass_summable {α : Type*} (p : PMF α) : Summable (mass p) := + ENNReal.summable_toReal p.tsum_coe_ne_top + +lemma mass_bind {α β : Type*} (p : PMF α) (k : α → PMF β) (b : β) : + mass (p.bind k) b = ∑' a, mass p a * mass (k a) b := by + simp only [mass, PMF.bind_apply, ENNReal.tsum_toReal_eq + (fun a => ENNReal.mul_ne_top (p.apply_ne_top a) ((k a).apply_ne_top b)), ENNReal.toReal_mul] + +lemma mass_uniform (i : Spin) : mass uniformSpin i = 1/3 := by + simp [mass, uniformSpin, PMF.ofFintype_apply] + +lemma mass_marginal {α : Type*} (law : Spin → PMF α) (y : α) : + mass (marginal law) y = (∑ i : Spin, mass (law i) y)/3 := by + simp only [marginal, mass_bind, tsum_fintype, mass_uniform] + rw [← Finset.mul_sum] + ring + +lemma mass_eq_zero {α : Type*} (p : PMF α) (a : α) : mass p a = 0 ↔ p a = 0 := by + simp [mass, ENNReal.toReal_eq_zero_iff, p.apply_ne_top a] + +lemma marginal_zero {α : Type*} (law : Spin → PMF α) (y : α) + (h : marginal law y = 0) (i : Spin) : law i y = 0 := by + apply (mass_eq_zero (law i) y).mp + have hh : mass (marginal law) y = 0 := (mass_eq_zero _ _).mpr h + rw [mass_marginal] at hh + have hs : ∑ j : Spin, mass (law j) y = 0 := by linarith + exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => mass_nonneg (law j) y)).mp hs i (by simp) + +lemma posterior_nonneg {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + 0 ≤ posterior law y i := by + unfold posterior + split_ifs <;> positivity + +lemma posterior_sum {α : Type*} (law : Spin → PMF α) (y : α) : + ∑ i : Spin, posterior law y i = 1 := by + classical + have hn := (marginal law).apply_ne_top y + by_cases h : marginal law y = 0 + · simp [posterior, h] + · have hm : mass (marginal law) y ≠ 0 := mt (mass_eq_zero _ _).mp h + simp only [posterior, ite_eq_right h, ← Finset.sum_div] + change (∑ i : Spin, mass (law i) y)/(3*mass (marginal law) y) = 1 + have he := mass_marginal law y + field_simp + linarith + + +lemma weighted_posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + mass (marginal law) y * (posterior law y i-1/3) = + (mass (law i) y-mass (marginal law) y)/3 := by + classical + by_cases h : marginal law y = 0 + · have hi := marginal_zero law y h i + simp [mass, h, hi, posterior] + · have hm : mass (marginal law) y ≠ 0 := mt (mass_eq_zero _ _).mp h + simp only [posterior, ite_eq_right h] + change mass (marginal law) y * (mass (law i) y / (3*mass (marginal law) y)-1/3) = _ + field_simp + +lemma weighted_abs_posterior {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + mass (marginal law) y * |posterior law y i-1/3| = + |mass (law i) y-mass (marginal law) y|/3 := by + calc + mass (marginal law) y * |posterior law y i-1/3| = + |mass (marginal law) y * (posterior law y i-1/3)| := by + rw [abs_mul, abs_of_nonneg (mass_nonneg (marginal law) y)] + _ = _ := by rw [weighted_posterior, abs_div]; norm_num + +lemma mass_le_one {α : Type*} (p : PMF α) (a : α) : mass p a ≤ 1 := by + simpa [mass] using ENNReal.toReal_mono (by finiteness) (p.coe_le_one a) + +noncomputable def tvMass {α : Type*} (p q : PMF α) : ℝ := + (∑' a, |mass p a-mass q a|)/2 + +lemma mass_diff_summable {α : Type*} (p q : PMF α) : + Summable (fun a => |mass p a-mass q a|) := + ((mass_summable p).sub (mass_summable q)).abs + +lemma tvMass_nonneg {α : Type*} (p q : PMF α) : 0 ≤ tvMass p q := by + exact div_nonneg (tsum_nonneg (fun a => abs_nonneg _)) (by norm_num) + +lemma tvMass_le_one {α : Type*} (p q : PMF α) : tvMass p q ≤ 1 := by + have h := (mass_diff_summable p q).tsum_le_tsum + (fun a => (abs_sub (mass p a) (mass q a)).trans_eq (by + rw [abs_of_nonneg (mass_nonneg p a), abs_of_nonneg (mass_nonneg q a)])) + ((mass_summable p).add (mass_summable q)) + rw [(mass_summable p).tsum_add (mass_summable q), mass_sum, mass_sum] at h + dsimp [tvMass] + linarith + +lemma advantage_eq_tvMass {α : Type*} (law : Spin → PMF α) : + advantage law = (∑ i : Spin, tvMass (law i) (marginal law))/3 := by + have ht (y : α) : mass (marginal law) y * + ((∑ i : Spin, |posterior law y i-1/3|)/2) = + (∑ i : Spin, |mass (law i) y-mass (marginal law) y|)/6 := by + rw [← mul_div_assoc, Finset.mul_sum] + simp_rw [weighted_abs_posterior] + rw [← Finset.sum_div] + ring + change (∑' y, mass (marginal law) y * + ((∑ i : Spin, |posterior law y i-1/3|)/2)) = _ + simp_rw [ht] + rw [tsum_div_const, Summable.tsum_finsetSum (fun i _ => mass_diff_summable (law i) (marginal law))] + simp only [tvMass, ← Finset.sum_div] + ring + +lemma advantage_nonneg {α : Type*} (law : Spin → PMF α) : 0 ≤ advantage law := by + rw [advantage_eq_tvMass] + exact div_nonneg (Finset.sum_nonneg (fun i _ => tvMass_nonneg _ _)) (by norm_num) + +lemma advantage_le_one {α : Type*} (law : Spin → PMF α) : advantage law ≤ 1 := by + rw [advantage_eq_tvMass] + have h := Finset.sum_le_sum (s := Finset.univ) (fun (i : Spin) _ => tvMass_le_one (law i) (marginal law)) + norm_num at h + linarith + +lemma kernel_mass_summable {α β : Type*} (p : PMF α) (k : α → PMF β) (b : β) : + Summable (fun a => mass p a*mass (k a) b) := by + apply Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (mass_nonneg (k a) b)) + (fun a => mul_le_of_le_one_right (mass_nonneg p a) (mass_le_one (k a) b)) + (mass_summable p) + +lemma weighted_kernel_summable {α β : Type*} (p q : PMF α) (k : α → PMF β) (b : β) : + Summable (fun a => |mass p a-mass q a| *mass (k a) b) := by + apply Summable.of_nonneg_of_le (fun a => mul_nonneg (abs_nonneg _) (mass_nonneg (k a) b)) + (fun a => mul_le_of_le_one_right (abs_nonneg _) (mass_le_one (k a) b)) + (mass_diff_summable p q) + +lemma mass_diff_bind_le {α β : Type*} (p q : PMF α) (k : α → PMF β) (b : β) : + |mass (p.bind k) b-mass (q.bind k) b| ≤ + ∑' a, |mass p a-mass q a| *mass (k a) b := by + rw [mass_bind, mass_bind, ← (kernel_mass_summable p k b).tsum_sub (kernel_mass_summable q k b)] + simp_rw [← sub_mul] + have hnorm : Summable (fun a => ‖(mass p a-mass q a)*mass (k a) b‖) := + (weighted_kernel_summable p q k b).congr (fun a => by + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg (k a) b)]) + simpa only [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg (k _) b)] using + norm_tsum_le_tsum_norm hnorm + +lemma tvMass_bind_le {α β : Type*} (p q : PMF α) (k : α → PMF β) : + tvMass (p.bind k) (q.bind k) ≤ tvMass p q := by + have hrow (a : α) : (∑' b, |mass p a-mass q a| *mass (k a) b) = + |mass p a-mass q a| := by + rw [(mass_summable (k a)).tsum_mul_left, mass_sum, mul_one] + have hs : Summable (Function.uncurry (fun a b => |mass p a-mass q a| *mass (k a) b)) := by + apply (summable_prod_of_nonneg (fun ab => mul_nonneg (abs_nonneg _) (mass_nonneg _ _))).mpr + change (∀ a, Summable (fun b => |mass p a-mass q a| * mass (k a) b)) ∧ + Summable (fun a => ∑' b, |mass p a-mass q a| * mass (k a) b) + constructor + · intro a + exact (mass_summable (k a)).mul_left |mass p a-mass q a| + · + simpa only [hrow] using mass_diff_summable p q + have h := Summable.tsum_le_tsum (mass_diff_bind_le p q k) + (mass_diff_summable (p.bind k) (q.bind k)) hs.prod_symm.prod + rw [hs.tsum_comm] at h + simp_rw [hrow] at h + exact div_le_div_of_nonneg_right h (by norm_num) + +lemma marginal_bind {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + marginal (fun i => (law i).bind k) = (marginal law).bind k := by + simp only [marginal, PMF.bind_bind] + + +theorem advantage_bind_le {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + advantage (fun i => (law i).bind k) ≤ advantage law := by + rw [advantage_eq_tvMass, advantage_eq_tvMass, marginal_bind] + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun i _ => tvMass_bind_le (law i) (marginal law) k)) + (by norm_num) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Couplings.lean b/lean/OAI/Probability/ThreeState/Couplings.lean index 964b4dceea1a34e0f4d0c6c5961b1f306d8c92f8..b3992be6fd4f4d8fa284629ec4ac41c39ba424a3 100644 --- a/lean/OAI/Probability/ThreeState/Couplings.lean +++ b/lean/OAI/Probability/ThreeState/Couplings.lean @@ -1,164 +1,164 @@ -import Mathlib -import OAI.Probability.ThreeState.Update - -namespace OAI - -/-! Common-mass couplings and total variation bounds for products and mixtures. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -noncomputable section - - - -def commonMass {α : Type*} (p q:PMF α) : ℝ := ∑'a,min (mass p a) (mass q a) -lemma commonMass_summable {α : Type*} (p q:PMF α) : - Summable (fun a=>min (mass p a) (mass q a)) := - Summable.of_nonneg_of_le (fun a=>le_min (mass_nonneg p a) (mass_nonneg q a)) - (fun value => min_le_left (mass p value) (mass q value)) (mass_summable p) -lemma commonMass_nonneg {α : Type*} (p q:PMF α) : 0≤commonMass p q := - tsum_nonneg (fun a=>le_min (mass_nonneg p a) (mass_nonneg q a)) -lemma commonMass_eq {α : Type*} (p q:PMF α) : commonMass p q=1-tvMass p q := by - have he (a:α) : min (mass p a) (mass q a)=(mass p a+mass q a-|mass p a-mass q a|)/2 := by - rw [min_def];split_ifs with h - · rw [abs_of_nonpos (sub_nonpos.mpr h)];ring - · rw [abs_of_nonneg (sub_nonneg.mpr (le_of_not_ge h))];ring - simp_rw [commonMass,he] - rw [tsum_div_const,((mass_summable p).add (mass_summable q)).tsum_sub (mass_diff_summable p q), - (mass_summable p).tsum_add (mass_summable q),mass_sum,mass_sum] - unfold tvMass - ring -lemma commonMass_le_one {α : Type*} (p q:PMF α) : commonMass p q≤1 := by - rw [commonMass_eq];linarith [tvMass_nonneg p q] - - - -def sharedPMF {α : Type*} (p q:PMF α) (hc:0ENNReal.ofReal (min (mass p a) (mass q a)/commonMass p q),?_⟩ - have hs : HasSum (fun a=>min (mass p a) (mass q a)/commonMass p q) 1 := by - convert! (commonMass_summable p q).hasSum.div_const (commonMass p q) using 1 - exact (div_self hc.ne').symm - apply ENNReal.hasSum_coe.2 - simpa using (hs.toNNReal (fun a=>div_nonneg - (le_min (mass_nonneg p a) (mass_nonneg q a)) hc.le)) -lemma mass_sharedPMF {α : Type*} (p q:PMF α) (hc:0 le_min (mass_nonneg p (v index)) (mass_nonneg q (v index))) - (fun index _ => min_le_left (mass p (v index)) (mass q (v index)))) - (Finset.prod_le_prod₀ - (fun index _ => le_min (mass_nonneg p (v index)) (mass_nonneg q (v index))) - (fun index _ => min_le_right (mass p (v index)) (mass q (v index)))) - have hh:=(mass_summable (iidVector r (n+1))).mul_left ((commonMass p q)^(n+1)) - have ht:=Summable.tsum_le_tsum hpoint hh (commonMass_summable _ _) - rw [tsum_mul_left] at ht - simpa only [mass_sum,mul_one,commonMass] using ht - -lemma tvMass_iidVector_le {α : Type*} (p q:PMF α) (n:ℕ) : - tvMass (iidVector p n) (iidVector q n)≤1-(1-tvMass p q)^n := by - have hh:=commonMass_iidVector p q n - rw [commonMass_eq,commonMass_eq] at hh - linarith -end -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -noncomputable section - -lemma tvMass_map_le {α β:Type*} (p q:PMF α) (f:α→β) : tvMass (p.map f) (q.map f)≤tvMass p q := - tvMass_bind_le p q (fun a=>PMF.pure (f a)) - -lemma mass_edge_difference {α:Type*} (law:Spin→PMF α) (lam:ℝ) (h:Admissible lam) - (i j:Spin) (a:α) : - mass (edgeLaw law lam h i) a-mass (edgeLaw law lam h j) a= - lam*(mass (law i) a-mass (law j) a) := by - rw [mass_edgeLaw,mass_edgeLaw,←weighted_likelihood law a i,←weighted_likelihood law a j] - change _*(1+lam*(_-1))-_*(1+lam*(_-1))=_ - ring -lemma tvMass_edge {α:Type*} (law:Spin→PMF α) (lam:ℝ) (h:Admissible lam) (i j:Spin) : - tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)= |lam| *tvMass (law i) (law j) := by - unfold tvMass - simp_rw [mass_edge_difference,abs_mul] - rw [tsum_mul_left] - ring - -lemma tvMass_marginal_le {α:Type*} (law:Spin→PMF α) (i:Spin) : - tvMass (law i) (marginal law)≤(∑j:Spin,tvMass (law i) (law j))/3 := by - have he (a:α) : mass (law i) a-mass (marginal law) a= - (∑j:Spin,(mass (law i) a-mass (law j) a))/3 := by - rw [mass_marginal,Finset.sum_sub_distrib] - simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - ring - have hp (a:α) : |mass (law i) a-mass (marginal law) a|≤ - (∑j:Spin,|mass (law i) a-mass (law j) a|)/3 := by - rw [he,abs_div] - rw [abs_of_nonneg (by norm_num : (0:ℝ)≤3)] - exact div_le_div_of_nonneg_right (Finset.abs_sum_le_sum_abs _ _) (by norm_num) - have hs : Summable (fun a=>∑j:Spin,|mass (law i) a-mass (law j) a|) := - summable_sum (fun j _=>mass_diff_summable _ _) - have hh:=Summable.tsum_le_tsum hp (mass_diff_summable _ _) (hs.div_const 3) - rw [tsum_div_const,Summable.tsum_finsetSum (fun j _=>mass_diff_summable (law i) (law j))] at hh - unfold tvMass - rw [←Finset.sum_div] - exact (div_le_div_of_nonneg_right hh (by norm_num : (0:ℝ)≤2)).trans_eq (by ring) - -lemma advantage_le_pair_bound {α:Type*} (law:Spin→PMF α) (x:ℝ) - (hx:∀i j,tvMass (law i) (law j)≤x) : advantage law≤x := by - rw [advantage_eq_tvMass] - have hb (i:Spin):tvMass (law i) (marginal law)≤x := by - calc - _ ≤ (∑j:Spin,tvMass (law i) (law j))/3 := tvMass_marginal_le law i - _ ≤ (∑j:Spin,x)/3 := div_le_div_of_nonneg_right (Finset.sum_le_sum (fun j _=>hx i j)) (by norm_num) - _ = x := by simp - have hh:=Finset.sum_le_sum (s:=Finset.univ) (fun i _=>hb i) - have hd:=div_le_div_of_nonneg_right hh (by norm_num : (0:ℝ)≤3) - simpa using hd - -lemma tvMass_sigmaPMF {ι:Type*} {α:ι→Type*} (p:PMF ι) (q r:∀i,PMF (α i)) : - tvMass (sigmaPMF p q) (sigmaPMF p r)=∑'i,mass p i*tvMass (q i) (r i) := by - unfold tvMass - rw [(mass_diff_summable (sigmaPMF p q) (sigmaPMF p r)).tsum_sigma] - simp_rw [mass_sigmaPMF,←mul_sub,abs_mul,abs_of_nonneg (mass_nonneg p _),tsum_mul_left] - rw [←tsum_div_const] - congr 1 - funext i - ring - -lemma summable_weighted_tv {ι:Type*} {α:ι→Type*} (p:PMF ι) (q r:∀i,PMF (α i)) : - Summable (fun i=>mass p i*tvMass (q i) (r i)) := - Summable.of_nonneg_of_le (fun i=>mul_nonneg (mass_nonneg p i) (tvMass_nonneg _ _)) - (fun i=>mul_le_of_le_one_right (mass_nonneg p i) (tvMass_le_one _ _)) (mass_summable p) -end -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Update + +namespace OAI + +/-! Common-mass couplings and total variation bounds for products and mixtures. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +noncomputable section + + + +def commonMass {α : Type*} (p q:PMF α) : ℝ := ∑'a,min (mass p a) (mass q a) +lemma commonMass_summable {α : Type*} (p q:PMF α) : + Summable (fun a=>min (mass p a) (mass q a)) := + Summable.of_nonneg_of_le (fun a=>le_min (mass_nonneg p a) (mass_nonneg q a)) + (fun value => min_le_left (mass p value) (mass q value)) (mass_summable p) +lemma commonMass_nonneg {α : Type*} (p q:PMF α) : 0≤commonMass p q := + tsum_nonneg (fun a=>le_min (mass_nonneg p a) (mass_nonneg q a)) +lemma commonMass_eq {α : Type*} (p q:PMF α) : commonMass p q=1-tvMass p q := by + have he (a:α) : min (mass p a) (mass q a)=(mass p a+mass q a-|mass p a-mass q a|)/2 := by + rw [min_def];split_ifs with h + · rw [abs_of_nonpos (sub_nonpos.mpr h)];ring + · rw [abs_of_nonneg (sub_nonneg.mpr (le_of_not_ge h))];ring + simp_rw [commonMass,he] + rw [tsum_div_const,((mass_summable p).add (mass_summable q)).tsum_sub (mass_diff_summable p q), + (mass_summable p).tsum_add (mass_summable q),mass_sum,mass_sum] + unfold tvMass + ring +lemma commonMass_le_one {α : Type*} (p q:PMF α) : commonMass p q≤1 := by + rw [commonMass_eq];linarith [tvMass_nonneg p q] + + + +def sharedPMF {α : Type*} (p q:PMF α) (hc:0ENNReal.ofReal (min (mass p a) (mass q a)/commonMass p q),?_⟩ + have hs : HasSum (fun a=>min (mass p a) (mass q a)/commonMass p q) 1 := by + convert! (commonMass_summable p q).hasSum.div_const (commonMass p q) using 1 + exact (div_self hc.ne').symm + apply ENNReal.hasSum_coe.2 + simpa using (hs.toNNReal (fun a=>div_nonneg + (le_min (mass_nonneg p a) (mass_nonneg q a)) hc.le)) +lemma mass_sharedPMF {α : Type*} (p q:PMF α) (hc:0 le_min (mass_nonneg p (v index)) (mass_nonneg q (v index))) + (fun index _ => min_le_left (mass p (v index)) (mass q (v index)))) + (Finset.prod_le_prod₀ + (fun index _ => le_min (mass_nonneg p (v index)) (mass_nonneg q (v index))) + (fun index _ => min_le_right (mass p (v index)) (mass q (v index)))) + have hh:=(mass_summable (iidVector r (n+1))).mul_left ((commonMass p q)^(n+1)) + have ht:=Summable.tsum_le_tsum hpoint hh (commonMass_summable _ _) + rw [tsum_mul_left] at ht + simpa only [mass_sum,mul_one,commonMass] using ht + +lemma tvMass_iidVector_le {α : Type*} (p q:PMF α) (n:ℕ) : + tvMass (iidVector p n) (iidVector q n)≤1-(1-tvMass p q)^n := by + have hh:=commonMass_iidVector p q n + rw [commonMass_eq,commonMass_eq] at hh + linarith +end +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +noncomputable section + +lemma tvMass_map_le {α β:Type*} (p q:PMF α) (f:α→β) : tvMass (p.map f) (q.map f)≤tvMass p q := + tvMass_bind_le p q (fun a=>PMF.pure (f a)) + +lemma mass_edge_difference {α:Type*} (law:Spin→PMF α) (lam:ℝ) (h:Admissible lam) + (i j:Spin) (a:α) : + mass (edgeLaw law lam h i) a-mass (edgeLaw law lam h j) a= + lam*(mass (law i) a-mass (law j) a) := by + rw [mass_edgeLaw,mass_edgeLaw,←weighted_likelihood law a i,←weighted_likelihood law a j] + change _*(1+lam*(_-1))-_*(1+lam*(_-1))=_ + ring +lemma tvMass_edge {α:Type*} (law:Spin→PMF α) (lam:ℝ) (h:Admissible lam) (i j:Spin) : + tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)= |lam| *tvMass (law i) (law j) := by + unfold tvMass + simp_rw [mass_edge_difference,abs_mul] + rw [tsum_mul_left] + ring + +lemma tvMass_marginal_le {α:Type*} (law:Spin→PMF α) (i:Spin) : + tvMass (law i) (marginal law)≤(∑j:Spin,tvMass (law i) (law j))/3 := by + have he (a:α) : mass (law i) a-mass (marginal law) a= + (∑j:Spin,(mass (law i) a-mass (law j) a))/3 := by + rw [mass_marginal,Finset.sum_sub_distrib] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + ring + have hp (a:α) : |mass (law i) a-mass (marginal law) a|≤ + (∑j:Spin,|mass (law i) a-mass (law j) a|)/3 := by + rw [he,abs_div] + rw [abs_of_nonneg (by norm_num : (0:ℝ)≤3)] + exact div_le_div_of_nonneg_right (Finset.abs_sum_le_sum_abs _ _) (by norm_num) + have hs : Summable (fun a=>∑j:Spin,|mass (law i) a-mass (law j) a|) := + summable_sum (fun j _=>mass_diff_summable _ _) + have hh:=Summable.tsum_le_tsum hp (mass_diff_summable _ _) (hs.div_const 3) + rw [tsum_div_const,Summable.tsum_finsetSum (fun j _=>mass_diff_summable (law i) (law j))] at hh + unfold tvMass + rw [←Finset.sum_div] + exact (div_le_div_of_nonneg_right hh (by norm_num : (0:ℝ)≤2)).trans_eq (by ring) + +lemma advantage_le_pair_bound {α:Type*} (law:Spin→PMF α) (x:ℝ) + (hx:∀i j,tvMass (law i) (law j)≤x) : advantage law≤x := by + rw [advantage_eq_tvMass] + have hb (i:Spin):tvMass (law i) (marginal law)≤x := by + calc + _ ≤ (∑j:Spin,tvMass (law i) (law j))/3 := tvMass_marginal_le law i + _ ≤ (∑j:Spin,x)/3 := div_le_div_of_nonneg_right (Finset.sum_le_sum (fun j _=>hx i j)) (by norm_num) + _ = x := by simp + have hh:=Finset.sum_le_sum (s:=Finset.univ) (fun i _=>hb i) + have hd:=div_le_div_of_nonneg_right hh (by norm_num : (0:ℝ)≤3) + simpa using hd + +lemma tvMass_sigmaPMF {ι:Type*} {α:ι→Type*} (p:PMF ι) (q r:∀i,PMF (α i)) : + tvMass (sigmaPMF p q) (sigmaPMF p r)=∑'i,mass p i*tvMass (q i) (r i) := by + unfold tvMass + rw [(mass_diff_summable (sigmaPMF p q) (sigmaPMF p r)).tsum_sigma] + simp_rw [mass_sigmaPMF,←mul_sub,abs_mul,abs_of_nonneg (mass_nonneg p _),tsum_mul_left] + rw [←tsum_div_const] + congr 1 + funext i + ring + +lemma summable_weighted_tv {ι:Type*} {α:ι→Type*} (p:PMF ι) (q r:∀i,PMF (α i)) : + Summable (fun i=>mass p i*tvMass (q i) (r i)) := + Summable.of_nonneg_of_le (fun i=>mul_nonneg (mass_nonneg p i) (tvMass_nonneg _ _)) + (fun i=>mul_le_of_le_one_right (mass_nonneg p i) (tvMass_le_one _ _)) (mass_summable p) +end +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/DegreePosterior.lean b/lean/OAI/Probability/ThreeState/DegreePosterior.lean index 1883acae8ce5450763fb68d505e3500d4a3397f7..7b04d1082e95f6ef13d946a6becaf94b5ddd085e 100644 --- a/lean/OAI/Probability/ThreeState/DegreePosterior.lean +++ b/lean/OAI/Probability/ThreeState/DegreePosterior.lean @@ -1,205 +1,205 @@ -import Mathlib -import OAI.Probability.ThreeState.PairCorrelation - -namespace OAI - -/-! Posterior laws by offspring degree and monotonicity of their moments. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma continuous_integral_message {f : Message → Message → ℝ} (hf : Continuous f.uncurry) - (Q : ProbabilityMeasure Message) : Continuous (fun a => ∫ b, f a b ∂(Q : Measure Message)) := by - simpa only [Measure.restrict_univ] using continuous_parametric_integral_of_continuous hf isCompact_univ - -lemma continuous_pairIncrement (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) : Continuous (pairIncrement lam h Q) := - continuous_integral_message (f := fun a b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) (continuous_pairIntegrand lam h hl0 hl1) Q - -noncomputable def degreePosterior (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) : ProbabilityMeasure Message := - ⟨degreeOutput lam h Q n, degreeOutput_probability lam h Q hQ n⟩ - -lemma integral_iid_cons (Q : ProbabilityMeasure Message) (n : ℕ) - (f : (Fin (n+1) → Message) → ℝ) (hf : Continuous f) : - (∫ m, f m ∂(iidMeasure Q (n+1) : Measure (Fin (n+1) → Message))) = - ∫ m : Fin n → Message, ∫ b, f (Fin.cons b m) ∂(Q : Measure Message) - ∂(iidMeasure Q n : Measure (Fin n → Message)) := by - change (∫ m, f m ∂Measure.pi (fun _ : Fin (n+1) => (Q : Measure Message))) = _ - rw [← ((measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => (Q : Measure Message)) 0).symm).integral_comp'] - simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, - Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq] - apply integral_prod_symm - exact (show Continuous (fun p : Message × (Fin n → Message) => f (Fin.cons p.1 p.2)) by - apply hf.comp - apply continuous_pi - intro j - refine Fin.cases ?_ (fun i => ?_) j - · simpa using (continuous_fst : Continuous (Prod.fst : Message × (Fin n → Message) → Message)) - · simpa only [Fin.cons_succ, Function.comp_def] using ((continuous_apply i).comp continuous_snd : Continuous (fun p : Message × (Fin n → Message) => p.2 i))).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -lemma normalizer_cons (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (b : Message) : - normalizer lam h (Fin.cons b m) = normalizer lam h m * pairNormalizer lam h (combineMessage lam h m) b := by - have he (i : Spin) : productWeight lam h (Fin.cons b m) i = edgeMessage lam h b i*productWeight lam h m i := by - simp [productWeight, Fin.prod_univ_succ] - have hn := ne_of_gt (normalizer_pos lam h hl0 hl1 m) - change avg (productWeight lam h (Fin.cons b m)) = normalizer lam h m*avg (fun i => combineMessage lam h m i*edgeMessage lam h b i) - simp only [Radial.avg_expand, he, combineMessage, dite_eq_right hn] - field_simp - -lemma combineMessage_cons (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (b : Message) : - combineMessage lam h (Fin.cons b m) = pairMessage lam h hl0 hl1 (combineMessage lam h m) b := by - apply Subtype.ext - funext i - have hp := ne_of_gt (normalizer_pos lam h hl0 hl1 m) - have hp' := ne_of_gt (normalizer_pos lam h hl0 hl1 (Fin.cons b m)) - change (combineMessage lam h (Fin.cons b m)) i = (combineMessage lam h m) i*edgeMessage lam h b i / pairNormalizer lam h (combineMessage lam h m) b - conv_lhs => rw [combineMessage, dite_eq_right hp'] - change productWeight lam h (Fin.cons b m) i/normalizer lam h (Fin.cons b m) = _ - rw [normalizer_cons lam h hl0 hl1] - have hw := weighted_combineMessage lam h m i - have he : productWeight lam h (Fin.cons b m) i = edgeMessage lam h b i*productWeight lam h m i := by - simp [productWeight, Fin.prod_univ_succ] - rw [he, ← hw] - field_simp [hp, ne_of_gt (pairNormalizer_pos lam h hl0 hl1 _ _)] - -noncomputable def pairOperator (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (f : C(Message,ℝ)) : C(Message,ℝ) := - ⟨fun a => ∫ b, pairNormalizer lam h a b*f (pairMessage lam h hl0 hl1 a b) ∂(Q : Measure Message), - continuous_integral_message (f := fun a b => pairNormalizer lam h a b*f (pairMessage lam h hl0 hl1 a b)) ((continuous_pairNormalizer lam h).mul (f.continuous.comp (continuous_pairMessage lam h hl0 hl1))) Q⟩ - -lemma integral_degree_succ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (n : ℕ) (f : C(Message,ℝ)) : - (∫ m, f m ∂degreeOutput lam h Q (n+1)) = - ∫ a, pairOperator lam h hl0 hl1 Q f a ∂degreeOutput lam h Q n := by - rw [integral_degreeOutput lam h Q (n+1) f f.continuous.measurable, - integral_iid_cons Q n (fun m => normalizer lam h m*f (combineMessage lam h m)) ((continuous_normalizer lam h (n+1)).mul - (f.continuous.comp (continuous_combineMessage_positive lam h hl0 hl1 (n+1)))), - integral_degreeOutput lam h Q n _ (pairOperator lam h hl0 hl1 Q f).continuous.measurable] - apply integral_congr_ae - filter_upwards with m - simp only [normalizer_cons lam h hl0 hl1, combineMessage_cons lam h hl0 hl1, mul_assoc, pairOperator] - exact integral_const_mul _ _ - -lemma correlationEntropy_zero (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) : - correlationEntropy lam h Q 0 = 0 := by - simp [correlationEntropy, normalizer, productWeight] - -lemma correlationEntropy_succ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : - correlationEntropy lam h Q (n+1) = correlationEntropy lam h Q n + - ∫ a, pairIncrement lam h Q a ∂degreeOutput lam h Q n := by - unfold correlationEntropy - rw [integral_iid_cons Q n (fun m => normalizer lam h m*Real.log (normalizer lam h m)) ((continuous_normalizer lam h (n+1)).mul (continuous_log_normalizer lam h hl0 hl1 (n+1)))] - have he (m : Fin n → Message) : - (∫ b, normalizer lam h (Fin.cons b m)*Real.log (normalizer lam h (Fin.cons b m)) ∂(Q : Measure Message)) = - normalizer lam h m*Real.log (normalizer lam h m)+normalizer lam h m*pairIncrement lam h Q (combineMessage lam h m) := by - let a := combineMessage lam h m - have hpn : Continuous (fun b => pairNormalizer lam h a b) := - (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) - have hpi : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := - (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) - have hfun (b : Message) : normalizer lam h (Fin.cons b m)*Real.log (normalizer lam h (Fin.cons b m)) = - (normalizer lam h m*Real.log (normalizer lam h m))*pairNormalizer lam h a b+ - normalizer lam h m*(pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := by - rw [normalizer_cons lam h hl0 hl1, Real.log_mul (ne_of_gt (normalizer_pos lam h hl0 hl1 m)) - (ne_of_gt (pairNormalizer_pos lam h hl0 hl1 _ _))] - dsimp only [a] - ring - simp_rw [hfun] - rw [integral_add ((integrable_continuous_message Q hpn).const_mul _) ((integrable_continuous_message Q hpi).const_mul _), - integral_const_mul, integral_const_mul, integral_pairNormalizer lam h Q hQ, mul_one] - rfl - simp_rw [he] - rw [integral_add] - · rw [integral_degreeOutput lam h Q n _ (continuous_pairIncrement lam h hl0 hl1 Q).measurable] - · exact ((continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - · exact ((continuous_normalizer lam h n).mul ((continuous_pairIncrement lam h hl0 hl1 Q).comp - (continuous_combineMessage_positive lam h hl0 hl1 n))).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma messageX_sq_tangent (a c : Message) : - (messageX a)^2+2*messageX a*avg (fun i => (a i-1)*(c i-a i)) ≤ (messageX c)^2 := by - let D := avg (fun i => (c i-a i)^2)/2 - have hD : 0 ≤ D := div_nonneg (avg_nonneg (fun i => sq_nonneg (c i-a i))) (by norm_num) - have he : messageX c-messageX a = avg (fun i => (a i-1)*(c i-a i))+D := by - dsimp only [messageX, Radial.momentX, messageDeviation, D] - simp only [Radial.avg_expand] - ring - have hm := mul_nonneg (messageX_nonneg a) hD - have hx := congrArg (fun t : ℝ => 2*messageX a*t) he - nlinarith only [hx, hm, sq_nonneg (messageX c-messageX a)] - -lemma integral_weighted_pair_deviation (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) (i : Spin) : - (∫ b, pairNormalizer lam h a b*(pairMessage lam h hl0 hl1 a b i-a i) ∂(Q : Measure Message)) = 0 := by - have he (b : Message) : pairNormalizer lam h a b*(pairMessage lam h hl0 hl1 a b i-a i) = - a i*(edgeMessage lam h b i-pairNormalizer lam h a b) := by - change pairNormalizer lam h a b*(a i*edgeMessage lam h b i/pairNormalizer lam h a b-a i) = _ - field_simp [ne_of_gt (pairNormalizer_pos lam h hl0 hl1 a b)] - simp_rw [he] - have hi : Integrable (fun b => edgeMessage lam h b i) (Q : Measure Message) := - integrable_continuous_message Q (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)) - have hp : Integrable (fun b => pairNormalizer lam h a b) (Q : Measure Message) := - integrable_continuous_message Q ((continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id)) - rw [integral_const_mul, integral_sub hi hp, integral_edgeMessage lam h Q hQ, - integral_pairNormalizer lam h Q hQ] - ring - -lemma pairOperator_square_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) : - (messageX a)^2 ≤ pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ a := by - let N : Message → ℝ := fun b => pairNormalizer lam h a b - let P : Message → Message := fun b => pairMessage lam h hl0 hl1 a b - let G : Message → Spin → ℝ := fun b i => N b*(P b i-a i) - have hn : Continuous N := (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) - have hp : Continuous P := (continuous_pairMessage lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) - have hg (i : Spin) : Continuous (fun b => G b i) := hn.mul ((((continuous_apply i).comp continuous_subtype_val).comp hp).sub continuous_const) - have hl : Continuous (fun b => N b*(messageX a)^2+2*messageX a*avg (fun i => (a i-1)*G b i)) := - (hn.mul continuous_const).add (continuous_const.mul (continuous_avg _ (fun i => continuous_const.mul (hg i)))) - have hr : Continuous (fun b => N b*(messageX (P b))^2) := hn.mul ((continuous_messageX.comp hp).pow 2) - have hin (b : Message) : N b*(messageX a)^2+2*messageX a*avg (fun i => (a i-1)*G b i) ≤ N b*(messageX (P b))^2 := by - have hh := mul_le_mul_of_nonneg_left (messageX_sq_tangent a (P b)) (pairNormalizer_pos lam h hl0 hl1 a b).le - convert hh using 1 - first | rfl | (simp only [G, Radial.avg_expand]; ring) - have hh := integral_mono (integrable_continuous_message Q hl) (integrable_continuous_message Q hr) hin - have hil : Integrable (fun b => N b*(messageX a)^2) (Q : Measure Message) := integrable_continuous_message Q (hn.mul continuous_const) - have hig : Integrable (fun b => 2*messageX a*avg (fun i => (a i-1)*G b i)) (Q : Measure Message) := - integrable_continuous_message Q (continuous_const.mul (continuous_avg _ (fun i => continuous_const.mul (hg i)))) - rw [integral_add hil hig, integral_mul_const, integral_const_mul, - integral_avg _ _ (fun i => (integrable_continuous_message Q (hg i)).const_mul _)] at hh - simp only [G,N,P, integral_const_mul, integral_weighted_pair_deviation lam h hl0 hl1 Q hQ, - integral_pairNormalizer lam h Q hQ, mul_zero, avg, Finset.sum_const_zero, zero_div, one_mul, add_zero] at hh - exact hh - -lemma degree_nu_monotone (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : - Monotone (fun n => posteriorNu (degreePosterior lam h Q hQ n)) := by - apply monotone_nat_of_le_succ - intro n - change (∫ m, (messageX m)^2 ∂degreeOutput lam h Q n) ≤ ∫ m, (messageX m)^2 ∂degreeOutput lam h Q (n+1) - have he : (∫ m, (messageX m)^2 ∂degreeOutput lam h Q (n+1)) = - ∫ a, pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ a ∂degreeOutput lam h Q n := by - exact integral_degree_succ lam h hl0 hl1 Q n ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ - rw [he] - let := degreeOutput_probability lam h Q hQ n - apply integral_mono - · exact (continuous_messageX.pow 2).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - · exact (pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩).continuous.integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - · exact pairOperator_square_lower lam h hl0 hl1 Q hQ - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.PairCorrelation + +namespace OAI + +/-! Posterior laws by offspring degree and monotonicity of their moments. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma continuous_integral_message {f : Message → Message → ℝ} (hf : Continuous f.uncurry) + (Q : ProbabilityMeasure Message) : Continuous (fun a => ∫ b, f a b ∂(Q : Measure Message)) := by + simpa only [Measure.restrict_univ] using continuous_parametric_integral_of_continuous hf isCompact_univ + +lemma continuous_pairIncrement (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) : Continuous (pairIncrement lam h Q) := + continuous_integral_message (f := fun a b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) (continuous_pairIntegrand lam h hl0 hl1) Q + +noncomputable def degreePosterior (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) : ProbabilityMeasure Message := + ⟨degreeOutput lam h Q n, degreeOutput_probability lam h Q hQ n⟩ + +lemma integral_iid_cons (Q : ProbabilityMeasure Message) (n : ℕ) + (f : (Fin (n+1) → Message) → ℝ) (hf : Continuous f) : + (∫ m, f m ∂(iidMeasure Q (n+1) : Measure (Fin (n+1) → Message))) = + ∫ m : Fin n → Message, ∫ b, f (Fin.cons b m) ∂(Q : Measure Message) + ∂(iidMeasure Q n : Measure (Fin n → Message)) := by + change (∫ m, f m ∂Measure.pi (fun _ : Fin (n+1) => (Q : Measure Message))) = _ + rw [← ((measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => (Q : Measure Message)) 0).symm).integral_comp'] + simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, + Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq] + apply integral_prod_symm + exact (show Continuous (fun p : Message × (Fin n → Message) => f (Fin.cons p.1 p.2)) by + apply hf.comp + apply continuous_pi + intro j + refine Fin.cases ?_ (fun i => ?_) j + · simpa using (continuous_fst : Continuous (Prod.fst : Message × (Fin n → Message) → Message)) + · simpa only [Fin.cons_succ, Function.comp_def] using ((continuous_apply i).comp continuous_snd : Continuous (fun p : Message × (Fin n → Message) => p.2 i))).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma normalizer_cons (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (b : Message) : + normalizer lam h (Fin.cons b m) = normalizer lam h m * pairNormalizer lam h (combineMessage lam h m) b := by + have he (i : Spin) : productWeight lam h (Fin.cons b m) i = edgeMessage lam h b i*productWeight lam h m i := by + simp [productWeight, Fin.prod_univ_succ] + have hn := ne_of_gt (normalizer_pos lam h hl0 hl1 m) + change avg (productWeight lam h (Fin.cons b m)) = normalizer lam h m*avg (fun i => combineMessage lam h m i*edgeMessage lam h b i) + simp only [Radial.avg_expand, he, combineMessage, dite_eq_right hn] + field_simp + +lemma combineMessage_cons (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (b : Message) : + combineMessage lam h (Fin.cons b m) = pairMessage lam h hl0 hl1 (combineMessage lam h m) b := by + apply Subtype.ext + funext i + have hp := ne_of_gt (normalizer_pos lam h hl0 hl1 m) + have hp' := ne_of_gt (normalizer_pos lam h hl0 hl1 (Fin.cons b m)) + change (combineMessage lam h (Fin.cons b m)) i = (combineMessage lam h m) i*edgeMessage lam h b i / pairNormalizer lam h (combineMessage lam h m) b + conv_lhs => rw [combineMessage, dite_eq_right hp'] + change productWeight lam h (Fin.cons b m) i/normalizer lam h (Fin.cons b m) = _ + rw [normalizer_cons lam h hl0 hl1] + have hw := weighted_combineMessage lam h m i + have he : productWeight lam h (Fin.cons b m) i = edgeMessage lam h b i*productWeight lam h m i := by + simp [productWeight, Fin.prod_univ_succ] + rw [he, ← hw] + field_simp [hp, ne_of_gt (pairNormalizer_pos lam h hl0 hl1 _ _)] + +noncomputable def pairOperator (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (f : C(Message,ℝ)) : C(Message,ℝ) := + ⟨fun a => ∫ b, pairNormalizer lam h a b*f (pairMessage lam h hl0 hl1 a b) ∂(Q : Measure Message), + continuous_integral_message (f := fun a b => pairNormalizer lam h a b*f (pairMessage lam h hl0 hl1 a b)) ((continuous_pairNormalizer lam h).mul (f.continuous.comp (continuous_pairMessage lam h hl0 hl1))) Q⟩ + +lemma integral_degree_succ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (n : ℕ) (f : C(Message,ℝ)) : + (∫ m, f m ∂degreeOutput lam h Q (n+1)) = + ∫ a, pairOperator lam h hl0 hl1 Q f a ∂degreeOutput lam h Q n := by + rw [integral_degreeOutput lam h Q (n+1) f f.continuous.measurable, + integral_iid_cons Q n (fun m => normalizer lam h m*f (combineMessage lam h m)) ((continuous_normalizer lam h (n+1)).mul + (f.continuous.comp (continuous_combineMessage_positive lam h hl0 hl1 (n+1)))), + integral_degreeOutput lam h Q n _ (pairOperator lam h hl0 hl1 Q f).continuous.measurable] + apply integral_congr_ae + filter_upwards with m + simp only [normalizer_cons lam h hl0 hl1, combineMessage_cons lam h hl0 hl1, mul_assoc, pairOperator] + exact integral_const_mul _ _ + +lemma correlationEntropy_zero (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) : + correlationEntropy lam h Q 0 = 0 := by + simp [correlationEntropy, normalizer, productWeight] + +lemma correlationEntropy_succ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : + correlationEntropy lam h Q (n+1) = correlationEntropy lam h Q n + + ∫ a, pairIncrement lam h Q a ∂degreeOutput lam h Q n := by + unfold correlationEntropy + rw [integral_iid_cons Q n (fun m => normalizer lam h m*Real.log (normalizer lam h m)) ((continuous_normalizer lam h (n+1)).mul (continuous_log_normalizer lam h hl0 hl1 (n+1)))] + have he (m : Fin n → Message) : + (∫ b, normalizer lam h (Fin.cons b m)*Real.log (normalizer lam h (Fin.cons b m)) ∂(Q : Measure Message)) = + normalizer lam h m*Real.log (normalizer lam h m)+normalizer lam h m*pairIncrement lam h Q (combineMessage lam h m) := by + let a := combineMessage lam h m + have hpn : Continuous (fun b => pairNormalizer lam h a b) := + (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) + have hpi : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := + (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) + have hfun (b : Message) : normalizer lam h (Fin.cons b m)*Real.log (normalizer lam h (Fin.cons b m)) = + (normalizer lam h m*Real.log (normalizer lam h m))*pairNormalizer lam h a b+ + normalizer lam h m*(pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := by + rw [normalizer_cons lam h hl0 hl1, Real.log_mul (ne_of_gt (normalizer_pos lam h hl0 hl1 m)) + (ne_of_gt (pairNormalizer_pos lam h hl0 hl1 _ _))] + dsimp only [a] + ring + simp_rw [hfun] + rw [integral_add ((integrable_continuous_message Q hpn).const_mul _) ((integrable_continuous_message Q hpi).const_mul _), + integral_const_mul, integral_const_mul, integral_pairNormalizer lam h Q hQ, mul_one] + rfl + simp_rw [he] + rw [integral_add] + · rw [integral_degreeOutput lam h Q n _ (continuous_pairIncrement lam h hl0 hl1 Q).measurable] + · exact ((continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + · exact ((continuous_normalizer lam h n).mul ((continuous_pairIncrement lam h hl0 hl1 Q).comp + (continuous_combineMessage_positive lam h hl0 hl1 n))).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma messageX_sq_tangent (a c : Message) : + (messageX a)^2+2*messageX a*avg (fun i => (a i-1)*(c i-a i)) ≤ (messageX c)^2 := by + let D := avg (fun i => (c i-a i)^2)/2 + have hD : 0 ≤ D := div_nonneg (avg_nonneg (fun i => sq_nonneg (c i-a i))) (by norm_num) + have he : messageX c-messageX a = avg (fun i => (a i-1)*(c i-a i))+D := by + dsimp only [messageX, Radial.momentX, messageDeviation, D] + simp only [Radial.avg_expand] + ring + have hm := mul_nonneg (messageX_nonneg a) hD + have hx := congrArg (fun t : ℝ => 2*messageX a*t) he + nlinarith only [hx, hm, sq_nonneg (messageX c-messageX a)] + +lemma integral_weighted_pair_deviation (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) (i : Spin) : + (∫ b, pairNormalizer lam h a b*(pairMessage lam h hl0 hl1 a b i-a i) ∂(Q : Measure Message)) = 0 := by + have he (b : Message) : pairNormalizer lam h a b*(pairMessage lam h hl0 hl1 a b i-a i) = + a i*(edgeMessage lam h b i-pairNormalizer lam h a b) := by + change pairNormalizer lam h a b*(a i*edgeMessage lam h b i/pairNormalizer lam h a b-a i) = _ + field_simp [ne_of_gt (pairNormalizer_pos lam h hl0 hl1 a b)] + simp_rw [he] + have hi : Integrable (fun b => edgeMessage lam h b i) (Q : Measure Message) := + integrable_continuous_message Q (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)) + have hp : Integrable (fun b => pairNormalizer lam h a b) (Q : Measure Message) := + integrable_continuous_message Q ((continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id)) + rw [integral_const_mul, integral_sub hi hp, integral_edgeMessage lam h Q hQ, + integral_pairNormalizer lam h Q hQ] + ring + +lemma pairOperator_square_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) : + (messageX a)^2 ≤ pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ a := by + let N : Message → ℝ := fun b => pairNormalizer lam h a b + let P : Message → Message := fun b => pairMessage lam h hl0 hl1 a b + let G : Message → Spin → ℝ := fun b i => N b*(P b i-a i) + have hn : Continuous N := (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) + have hp : Continuous P := (continuous_pairMessage lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) + have hg (i : Spin) : Continuous (fun b => G b i) := hn.mul ((((continuous_apply i).comp continuous_subtype_val).comp hp).sub continuous_const) + have hl : Continuous (fun b => N b*(messageX a)^2+2*messageX a*avg (fun i => (a i-1)*G b i)) := + (hn.mul continuous_const).add (continuous_const.mul (continuous_avg _ (fun i => continuous_const.mul (hg i)))) + have hr : Continuous (fun b => N b*(messageX (P b))^2) := hn.mul ((continuous_messageX.comp hp).pow 2) + have hin (b : Message) : N b*(messageX a)^2+2*messageX a*avg (fun i => (a i-1)*G b i) ≤ N b*(messageX (P b))^2 := by + have hh := mul_le_mul_of_nonneg_left (messageX_sq_tangent a (P b)) (pairNormalizer_pos lam h hl0 hl1 a b).le + convert hh using 1 + first | rfl | (simp only [G, Radial.avg_expand]; ring) + have hh := integral_mono (integrable_continuous_message Q hl) (integrable_continuous_message Q hr) hin + have hil : Integrable (fun b => N b*(messageX a)^2) (Q : Measure Message) := integrable_continuous_message Q (hn.mul continuous_const) + have hig : Integrable (fun b => 2*messageX a*avg (fun i => (a i-1)*G b i)) (Q : Measure Message) := + integrable_continuous_message Q (continuous_const.mul (continuous_avg _ (fun i => continuous_const.mul (hg i)))) + rw [integral_add hil hig, integral_mul_const, integral_const_mul, + integral_avg _ _ (fun i => (integrable_continuous_message Q (hg i)).const_mul _)] at hh + simp only [G,N,P, integral_const_mul, integral_weighted_pair_deviation lam h hl0 hl1 Q hQ, + integral_pairNormalizer lam h Q hQ, mul_zero, avg, Finset.sum_const_zero, zero_div, one_mul, add_zero] at hh + exact hh + +lemma degree_nu_monotone (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : + Monotone (fun n => posteriorNu (degreePosterior lam h Q hQ n)) := by + apply monotone_nat_of_le_succ + intro n + change (∫ m, (messageX m)^2 ∂degreeOutput lam h Q n) ≤ ∫ m, (messageX m)^2 ∂degreeOutput lam h Q (n+1) + have he : (∫ m, (messageX m)^2 ∂degreeOutput lam h Q (n+1)) = + ∫ a, pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ a ∂degreeOutput lam h Q n := by + exact integral_degree_succ lam h hl0 hl1 Q n ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ + rw [he] + let := degreeOutput_probability lam h Q hQ n + apply integral_mono + · exact (continuous_messageX.pow 2).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + · exact (pairOperator lam h hl0 hl1 Q ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩).continuous.integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + · exact pairOperator_square_lower lam h hl0 hl1 Q hQ + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Entropy.lean b/lean/OAI/Probability/ThreeState/Entropy.lean index cae795d41acbe5d69d85ec76e2cacd04b44566b1..98ab8c0e78cb9c1e802c4a265efe0d3aceed5d11 100644 --- a/lean/OAI/Probability/ThreeState/Entropy.lean +++ b/lean/OAI/Probability/ThreeState/Entropy.lean @@ -1,326 +1,326 @@ -import Mathlib -import OAI.Probability.ThreeState.RadialDerivatives -import OAI.Probability.ThreeState.Symmetry - -namespace OAI - -/-! Message entropy and its integrability. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma average_message (m : Message) : avg (fun i => m i) = 1 := by - simp [avg, Message.sum] - -lemma message_last (m : Message) : m 2 = 3-m 0-m 1 := by - have hh := average_message m - rw [Radial.avg_expand] at hh - linarith - -lemma avg_nonneg {v : Spin → ℝ} (h : ∀ i, 0 ≤ v i) : 0 ≤ avg v := - div_nonneg (Finset.sum_nonneg (fun i _ => h i)) (by norm_num) - -lemma avg_le_const {v : Spin → ℝ} {c : ℝ} (h : ∀ i, v i ≤ c) : avg v ≤ c := by - rw [Radial.avg_expand] - linarith [h 0,h 1,h 2] - -lemma abs_avg_le {v : Spin → ℝ} {c : ℝ} (h : ∀ i, |v i| ≤ c) : |avg v| ≤ c := by - apply abs_le.mpr - constructor - · have h0 := (abs_le.mp (h 0)).1 - have h1 := (abs_le.mp (h 1)).1 - have h2 := (abs_le.mp (h 2)).1 - rw [Radial.avg_expand] - linarith - · exact avg_le_const (fun i => (abs_le.mp (h i)).2) - -lemma edgeMessage_bounds (lam : ℝ) (h : Admissible lam) (hl : 0 ≤ lam) (m : Message) (i : Spin) : - 1-lam ≤ edgeMessage lam h m i ∧ edgeMessage lam h m i ≤ 1+2*lam := by - change 1-lam ≤ 1+lam*(m i-1) ∧ 1+lam*(m i-1) ≤ 1+2*lam - constructor <;> nlinarith [Message.nonneg m i, Message.le_three m i] - -lemma edgeMessage_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (m : Message) (i : Spin) : 0 < edgeMessage lam h m i := by - have hh := (edgeMessage_bounds lam h hl0 m i).1 - linarith - -lemma productWeight_bounds (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (i : Spin) : - (1-lam)^n ≤ productWeight lam h m i ∧ productWeight lam h m i ≤ (1+2*lam)^n := by - constructor - · calc - (1-lam)^n = ∏ _j : Fin n, (1-lam) := by simp - _ ≤ productWeight lam h m i := Finset.prod_le_prod₀ (fun _ _ => by linarith) - (fun j _ => (edgeMessage_bounds lam h hl0 (m j) i).1) - · calc - productWeight lam h m i ≤ ∏ _j : Fin n, (1+2*lam) := - Finset.prod_le_prod₀ (fun j _ => Message.nonneg (edgeMessage lam h (m j)) i) - (fun j _ => (edgeMessage_bounds lam h hl0 (m j) i).2) - _ = (1+2*lam)^n := by simp - -lemma normalizer_bounds (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) : - (1-lam)^n ≤ normalizer lam h m ∧ normalizer lam h m ≤ (1+2*lam)^n := by - have hh := productWeight_bounds lam h hl0 hl1 m - change (1-lam)^n ≤ avg (productWeight lam h m) ∧ avg (productWeight lam h m) ≤ (1+2*lam)^n - constructor - · rw [Radial.avg_expand] - linarith [(hh 0).1,(hh 1).1,(hh 2).1] - · exact avg_le_const (fun i => (hh i).2) - -lemma normalizer_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) : 0 < normalizer lam h m := - lt_of_lt_of_le (pow_pos (by linarith) _) (normalizer_bounds lam h hl0 hl1 m).1 - -lemma combineMessage_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (i : Spin) : 0 < combineMessage lam h m i := by - have hz := normalizer_pos lam h hl0 hl1 m - rw [combineMessage, dite_eq_right (ne_of_gt hz)] - exact div_pos (lt_of_lt_of_le (pow_pos (by linarith) n) (productWeight_bounds lam h hl0 hl1 m i).1) hz - -lemma continuous_combineMessage_positive (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) - (hl1 : lam < 1) (n : ℕ) : Continuous (combineMessage lam h : (Fin n → Message) → Message) := - continuous_iff_continuousAt.mpr (fun m => continuousAt_combineMessage lam h m - (ne_of_gt (normalizer_pos lam h hl0 hl1 m))) - -lemma positive_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) : - ∀ᵐ m ∂(Q : Measure Message), ∀ i : Spin, 0 < m i := by - apply ae_fixedpoint_of_output offspring lam h Q hQ - · simpa only [Set.ofPred_forall, Function.comp_def] using MeasurableSet.iInter (fun i : Spin => - measurableSet_lt (f := fun _ : Message => (0:ℝ)) measurable_const - ((continuous_apply i).comp continuous_subtype_val).measurable) - · intro n m i - exact combineMessage_pos lam h hl0 hl1 m i - -noncomputable def edgeLogBound (lam : ℝ) : ℝ := |Real.log (1-lam)|+|Real.log (1+2*lam)| - -lemma edgeLogBound_nonneg (lam : ℝ) : 0 ≤ edgeLogBound lam := add_nonneg (abs_nonneg _) (abs_nonneg _) - -lemma abs_log_of_bounds (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) (a : ℝ) - (ha : (1-lam)^n ≤ a) (hb : a ≤ (1+2*lam)^n) : |Real.log a| ≤ n*edgeLogBound lam := by - have ha0 : 0 < (1-lam)^n := pow_pos (by linarith) _ - have hap : 0 < a := lt_of_lt_of_le ha0 ha - have hlo := Real.log_le_log ha0 ha - have hhi : Real.log a ≤ Real.log ((1+2*lam)^n) := - (Real.log_le_log_iff hap (pow_pos (by linarith [hl0]) n)).mpr hb - rw [Real.log_pow] at hlo hhi - have hn : (0:ℝ) ≤ n := Nat.cast_nonneg n - have ha1 := neg_abs_le (Real.log (1-lam)) - have ha2 := le_abs_self (Real.log (1+2*lam)) - dsimp [edgeLogBound] - apply abs_le.mpr - constructor - · nlinarith [mul_nonneg hn (abs_nonneg (Real.log (1+2*lam)))] - · nlinarith [mul_nonneg hn (abs_nonneg (Real.log (1-lam)))] - -lemma log_combineMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (i : Spin) : - Real.log (combineMessage lam h m i) = - (∑ j, Real.log (edgeMessage lam h (m j) i))-Real.log (normalizer lam h m) := by - have hz := normalizer_pos lam h hl0 hl1 m - have hw : productWeight lam h m i ≠ 0 := ne_of_gt - (lt_of_lt_of_le (pow_pos (by linarith) n) (productWeight_bounds lam h hl0 hl1 m i).1) - rw [combineMessage, dite_eq_right (ne_of_gt hz), Real.log_div hw (ne_of_gt hz)] - rw [productWeight, Real.log_prod (fun j _ => ne_of_gt (edgeMessage_pos lam h hl0 hl1 (m j) i))] - -lemma log_combineMessage_bound (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (i : Spin) : - |Real.log (combineMessage lam h m i)| ≤ 2*n*edgeLogBound lam := by - have hz := normalizer_pos lam h hl0 hl1 m - have hw := productWeight_bounds lam h hl0 hl1 m i - have hn := normalizer_bounds lam h hl0 hl1 m - have hw0 : productWeight lam h m i ≠ 0 := ne_of_gt (lt_of_lt_of_le (pow_pos (by linarith) n) hw.1) - rw [combineMessage, dite_eq_right (ne_of_gt hz), Real.log_div hw0 (ne_of_gt hz)] - calc - |Real.log (productWeight lam h m i)-Real.log (normalizer lam h m)| ≤ - |Real.log (productWeight lam h m i)|+|Real.log (normalizer lam h m)| := abs_sub _ _ - _ ≤ n*edgeLogBound lam+n*edgeLogBound lam := add_le_add - (abs_log_of_bounds lam hl0 hl1 n _ hw.1 hw.2) (abs_log_of_bounds lam hl0 hl1 n _ hn.1 hn.2) - _ = _ := by ring - -noncomputable def mLog (m : Message) (i : Spin) : ℝ := Real.log (m i) -noncomputable def mCenteredLog (m : Message) (i : Spin) : ℝ := mLog m i-avg (mLog m) -noncomputable def entropyI (m : Message) : ℝ := avg (fun i => m i*mLog m i) -noncomputable def entropyJ (m : Message) : ℝ := avg (fun i => (m i-1)*mLog m i)/2 -noncomputable def entropyB (m : Message) : ℝ := avg (fun i => m i*(mCenteredLog m i)^2)/2 -noncomputable def entropyF (m : Message) : ℝ := 3*entropyI m-2*entropyJ m+(4/5:ℝ)*entropyB m - -lemma measurable_mLog (i : Spin) : Measurable (fun m : Message => mLog m i) := - Real.measurable_log.comp ((continuous_apply i).comp continuous_subtype_val).measurable -lemma measurable_avg (f : Message → Spin → ℝ) (hf : ∀ i, Measurable (fun m => f m i)) : - Measurable (fun m => avg (f m)) := by - simp only [Radial.avg_expand] - exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 -lemma measurable_mCenteredLog (i : Spin) : Measurable (fun m : Message => mCenteredLog m i) := - (measurable_mLog i).sub (measurable_avg mLog measurable_mLog) -lemma measurable_entropyI : Measurable entropyI := - measurable_avg _ (fun i => ((continuous_apply i).comp continuous_subtype_val).measurable.mul (measurable_mLog i)) -lemma measurable_entropyJ : Measurable entropyJ := - (measurable_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).measurable.sub_const 1).mul (measurable_mLog i))).div_const 2 -lemma measurable_entropyB : Measurable entropyB := - (measurable_avg _ (fun i => ((continuous_apply i).comp continuous_subtype_val).measurable.mul ((measurable_mCenteredLog i).pow_const 2))).div_const 2 -lemma measurable_entropyF : Measurable entropyF := by - exact ((measurable_entropyI.const_mul 3).sub (measurable_entropyJ.const_mul 2)).add - (measurable_entropyB.const_mul (4/5:ℝ)) - -lemma centeredLog_combine (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) (i : Spin) : - mCenteredLog (combineMessage lam h m) i = ∑ j, mCenteredLog (edgeMessage lam h (m j)) i := by - simp only [mCenteredLog, mLog, Radial.avg_expand, log_combineMessage lam h hl0 hl1, - Finset.sum_sub_distrib, add_div, ← Finset.sum_div, Finset.sum_add_distrib] - ring - -lemma centeredLog_J (m : Message) : avg (fun i => m i*mCenteredLog m i) = 2*entropyJ m := by - simp only [mCenteredLog, entropyJ, mLog, Radial.avg_expand, message_last m] - ring - -lemma entropyF_radial (m : Message) : entropyF m = Radial.sourceF (fun i => m i) := by - simp only [entropyF, entropyI, entropyJ, entropyB, mCenteredLog, mLog, Radial.sourceF, - Radial.avg_expand] - ring - -lemma centeredLog_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) (i : Spin) : - |mCenteredLog m i| ≤ 2*C := by - calc - |mCenteredLog m i| ≤ |mLog m i|+|avg (mLog m)| := abs_sub _ _ - _ ≤ C+C := add_le_add (hc i) (abs_avg_le hc) - _ = _ := by ring - -lemma entropyI_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyI m| ≤ 3*C := by - apply abs_avg_le - intro i - rw [abs_mul, abs_of_nonneg (Message.nonneg m i)] - exact mul_le_mul (Message.le_three m i) (hc i) (abs_nonneg _) (by norm_num) - -lemma entropyJ_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyJ m| ≤ C := by - have hv (i : Spin) : |m i-1| ≤ 2 := abs_le.mpr ⟨by linarith [Message.nonneg m i], by linarith [Message.le_three m i]⟩ - have ha : |avg (fun i => (m i-1)*mLog m i)| ≤ 2*C := by - apply abs_avg_le - intro i - rw [abs_mul] - exact mul_le_mul (hv i) (hc i) (abs_nonneg _) (by norm_num) - dsimp only [entropyJ] - rw [abs_div, abs_of_pos (by norm_num : (0:ℝ)<2)] - linarith - -lemma entropyB_nonneg (m : Message) : 0 ≤ entropyB m := - div_nonneg (avg_nonneg (fun i => mul_nonneg (Message.nonneg m i) (sq_nonneg _))) (by norm_num) - -lemma entropyB_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyB m| ≤ 6*C^2 := by - have hC : 0 ≤ C := le_trans (abs_nonneg _) (hc 0) - have hu (i : Spin) : (mCenteredLog m i)^2 ≤ (2*C)^2 := by - have hh := (sq_le_sq₀ (abs_nonneg (mCenteredLog m i)) (by positivity : 0 ≤ 2*C)).mpr (centeredLog_bound m C hc i) - simpa only [sq_abs] using hh - have ha : avg (fun i => m i*(mCenteredLog m i)^2) ≤ 12*C^2 := by - apply avg_le_const - intro i - have hh := mul_le_mul (Message.le_three m i) (hu i) (sq_nonneg _) (by norm_num : (0:ℝ)≤3) - nlinarith - rw [abs_of_nonneg (entropyB_nonneg m)] - dsimp only [entropyB] - linarith - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma continuous_avg {α : Type*} [TopologicalSpace α] (f : α → Spin → ℝ) - (hf : ∀ i, Continuous (fun m => f m i)) : Continuous (fun m => avg (f m)) := by - simp only [Radial.avg_expand] - exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 - -lemma continuous_mLog_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (i : Spin) : - Continuous (fun m => mLog (edgeMessage lam h m) i) := - (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).log - (fun m => ne_of_gt (edgeMessage_pos lam h hl0 hl1 m i)) - -lemma continuous_mCenteredLog_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (i : Spin) : - Continuous (fun m => mCenteredLog (edgeMessage lam h m) i) := - (continuous_mLog_edge lam h hl0 hl1 i).sub - (continuous_avg _ (continuous_mLog_edge lam h hl0 hl1)) - -lemma continuous_entropyI_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun m => entropyI (edgeMessage lam h m)) := - continuous_avg _ (fun i => - (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul - (continuous_mLog_edge lam h hl0 hl1 i)) - -lemma continuous_entropyJ_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun m => entropyJ (edgeMessage lam h m)) := - (continuous_avg _ (fun i => - ((((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).sub continuous_const).mul - (continuous_mLog_edge lam h hl0 hl1 i))).div_const 2 - -lemma continuous_entropyB_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun m => entropyB (edgeMessage lam h m)) := - (continuous_avg _ (fun i => - (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul - ((continuous_mCenteredLog_edge lam h hl0 hl1 i).pow 2))).div_const 2 - -lemma integrable_mLog_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (i : Spin) : - Integrable (fun m => mLog m i) (Q : Measure Message) := by - apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ (measurable_mLog i) - (fun n => (n:ℝ)*(2*edgeLogBound lam)) (hD.mul_const _) - intro n m - have hh := log_combineMessage_bound lam h hl0 hl1 m i - dsimp only [mLog] - nlinarith - -lemma integrable_entropyI_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : - Integrable entropyI (Q : Measure Message) := by - apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyI - (fun n => (n:ℝ)*(6*edgeLogBound lam)) (hD.mul_const _) - intro n m - have hh := entropyI_bound (combineMessage lam h m) (2*n*edgeLogBound lam) - (log_combineMessage_bound lam h hl0 hl1 m) - nlinarith - -lemma integrable_entropyJ_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : - Integrable entropyJ (Q : Measure Message) := by - apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyJ - (fun n => (n:ℝ)*(2*edgeLogBound lam)) (hD.mul_const _) - intro n m - have hh := entropyJ_bound (combineMessage lam h m) (2*n*edgeLogBound lam) - (log_combineMessage_bound lam h hl0 hl1 m) - nlinarith - -lemma integrable_entropyB_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - Integrable entropyB (Q : Measure Message) := by - apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyB - (fun n => (n:ℝ)^2*(24*(edgeLogBound lam)^2)) (hD2.mul_const _) - intro n m - have hh := entropyB_bound (combineMessage lam h m) (2*n*edgeLogBound lam) - (log_combineMessage_bound lam h hl0 hl1 m) - nlinarith - -lemma integrable_entropyF_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - Integrable entropyF (Q : Measure Message) := by - have hD := hasMean_of_square hD2 - exact (((integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 3).sub - ((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 2)).add - ((integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2).const_mul (4/5:ℝ)) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.RadialDerivatives +import OAI.Probability.ThreeState.Symmetry + +namespace OAI + +/-! Message entropy and its integrability. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma average_message (m : Message) : avg (fun i => m i) = 1 := by + simp [avg, Message.sum] + +lemma message_last (m : Message) : m 2 = 3-m 0-m 1 := by + have hh := average_message m + rw [Radial.avg_expand] at hh + linarith + +lemma avg_nonneg {v : Spin → ℝ} (h : ∀ i, 0 ≤ v i) : 0 ≤ avg v := + div_nonneg (Finset.sum_nonneg (fun i _ => h i)) (by norm_num) + +lemma avg_le_const {v : Spin → ℝ} {c : ℝ} (h : ∀ i, v i ≤ c) : avg v ≤ c := by + rw [Radial.avg_expand] + linarith [h 0,h 1,h 2] + +lemma abs_avg_le {v : Spin → ℝ} {c : ℝ} (h : ∀ i, |v i| ≤ c) : |avg v| ≤ c := by + apply abs_le.mpr + constructor + · have h0 := (abs_le.mp (h 0)).1 + have h1 := (abs_le.mp (h 1)).1 + have h2 := (abs_le.mp (h 2)).1 + rw [Radial.avg_expand] + linarith + · exact avg_le_const (fun i => (abs_le.mp (h i)).2) + +lemma edgeMessage_bounds (lam : ℝ) (h : Admissible lam) (hl : 0 ≤ lam) (m : Message) (i : Spin) : + 1-lam ≤ edgeMessage lam h m i ∧ edgeMessage lam h m i ≤ 1+2*lam := by + change 1-lam ≤ 1+lam*(m i-1) ∧ 1+lam*(m i-1) ≤ 1+2*lam + constructor <;> nlinarith [Message.nonneg m i, Message.le_three m i] + +lemma edgeMessage_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (m : Message) (i : Spin) : 0 < edgeMessage lam h m i := by + have hh := (edgeMessage_bounds lam h hl0 m i).1 + linarith + +lemma productWeight_bounds (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (i : Spin) : + (1-lam)^n ≤ productWeight lam h m i ∧ productWeight lam h m i ≤ (1+2*lam)^n := by + constructor + · calc + (1-lam)^n = ∏ _j : Fin n, (1-lam) := by simp + _ ≤ productWeight lam h m i := Finset.prod_le_prod₀ (fun _ _ => by linarith) + (fun j _ => (edgeMessage_bounds lam h hl0 (m j) i).1) + · calc + productWeight lam h m i ≤ ∏ _j : Fin n, (1+2*lam) := + Finset.prod_le_prod₀ (fun j _ => Message.nonneg (edgeMessage lam h (m j)) i) + (fun j _ => (edgeMessage_bounds lam h hl0 (m j) i).2) + _ = (1+2*lam)^n := by simp + +lemma normalizer_bounds (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) : + (1-lam)^n ≤ normalizer lam h m ∧ normalizer lam h m ≤ (1+2*lam)^n := by + have hh := productWeight_bounds lam h hl0 hl1 m + change (1-lam)^n ≤ avg (productWeight lam h m) ∧ avg (productWeight lam h m) ≤ (1+2*lam)^n + constructor + · rw [Radial.avg_expand] + linarith [(hh 0).1,(hh 1).1,(hh 2).1] + · exact avg_le_const (fun i => (hh i).2) + +lemma normalizer_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) : 0 < normalizer lam h m := + lt_of_lt_of_le (pow_pos (by linarith) _) (normalizer_bounds lam h hl0 hl1 m).1 + +lemma combineMessage_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (i : Spin) : 0 < combineMessage lam h m i := by + have hz := normalizer_pos lam h hl0 hl1 m + rw [combineMessage, dite_eq_right (ne_of_gt hz)] + exact div_pos (lt_of_lt_of_le (pow_pos (by linarith) n) (productWeight_bounds lam h hl0 hl1 m i).1) hz + +lemma continuous_combineMessage_positive (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) + (hl1 : lam < 1) (n : ℕ) : Continuous (combineMessage lam h : (Fin n → Message) → Message) := + continuous_iff_continuousAt.mpr (fun m => continuousAt_combineMessage lam h m + (ne_of_gt (normalizer_pos lam h hl0 hl1 m))) + +lemma positive_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) : + ∀ᵐ m ∂(Q : Measure Message), ∀ i : Spin, 0 < m i := by + apply ae_fixedpoint_of_output offspring lam h Q hQ + · simpa only [Set.ofPred_forall, Function.comp_def] using MeasurableSet.iInter (fun i : Spin => + measurableSet_lt (f := fun _ : Message => (0:ℝ)) measurable_const + ((continuous_apply i).comp continuous_subtype_val).measurable) + · intro n m i + exact combineMessage_pos lam h hl0 hl1 m i + +noncomputable def edgeLogBound (lam : ℝ) : ℝ := |Real.log (1-lam)|+|Real.log (1+2*lam)| + +lemma edgeLogBound_nonneg (lam : ℝ) : 0 ≤ edgeLogBound lam := add_nonneg (abs_nonneg _) (abs_nonneg _) + +lemma abs_log_of_bounds (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) (a : ℝ) + (ha : (1-lam)^n ≤ a) (hb : a ≤ (1+2*lam)^n) : |Real.log a| ≤ n*edgeLogBound lam := by + have ha0 : 0 < (1-lam)^n := pow_pos (by linarith) _ + have hap : 0 < a := lt_of_lt_of_le ha0 ha + have hlo := Real.log_le_log ha0 ha + have hhi : Real.log a ≤ Real.log ((1+2*lam)^n) := + (Real.log_le_log_iff hap (pow_pos (by linarith [hl0]) n)).mpr hb + rw [Real.log_pow] at hlo hhi + have hn : (0:ℝ) ≤ n := Nat.cast_nonneg n + have ha1 := neg_abs_le (Real.log (1-lam)) + have ha2 := le_abs_self (Real.log (1+2*lam)) + dsimp [edgeLogBound] + apply abs_le.mpr + constructor + · nlinarith [mul_nonneg hn (abs_nonneg (Real.log (1+2*lam)))] + · nlinarith [mul_nonneg hn (abs_nonneg (Real.log (1-lam)))] + +lemma log_combineMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (i : Spin) : + Real.log (combineMessage lam h m i) = + (∑ j, Real.log (edgeMessage lam h (m j) i))-Real.log (normalizer lam h m) := by + have hz := normalizer_pos lam h hl0 hl1 m + have hw : productWeight lam h m i ≠ 0 := ne_of_gt + (lt_of_lt_of_le (pow_pos (by linarith) n) (productWeight_bounds lam h hl0 hl1 m i).1) + rw [combineMessage, dite_eq_right (ne_of_gt hz), Real.log_div hw (ne_of_gt hz)] + rw [productWeight, Real.log_prod (fun j _ => ne_of_gt (edgeMessage_pos lam h hl0 hl1 (m j) i))] + +lemma log_combineMessage_bound (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (i : Spin) : + |Real.log (combineMessage lam h m i)| ≤ 2*n*edgeLogBound lam := by + have hz := normalizer_pos lam h hl0 hl1 m + have hw := productWeight_bounds lam h hl0 hl1 m i + have hn := normalizer_bounds lam h hl0 hl1 m + have hw0 : productWeight lam h m i ≠ 0 := ne_of_gt (lt_of_lt_of_le (pow_pos (by linarith) n) hw.1) + rw [combineMessage, dite_eq_right (ne_of_gt hz), Real.log_div hw0 (ne_of_gt hz)] + calc + |Real.log (productWeight lam h m i)-Real.log (normalizer lam h m)| ≤ + |Real.log (productWeight lam h m i)|+|Real.log (normalizer lam h m)| := abs_sub _ _ + _ ≤ n*edgeLogBound lam+n*edgeLogBound lam := add_le_add + (abs_log_of_bounds lam hl0 hl1 n _ hw.1 hw.2) (abs_log_of_bounds lam hl0 hl1 n _ hn.1 hn.2) + _ = _ := by ring + +noncomputable def mLog (m : Message) (i : Spin) : ℝ := Real.log (m i) +noncomputable def mCenteredLog (m : Message) (i : Spin) : ℝ := mLog m i-avg (mLog m) +noncomputable def entropyI (m : Message) : ℝ := avg (fun i => m i*mLog m i) +noncomputable def entropyJ (m : Message) : ℝ := avg (fun i => (m i-1)*mLog m i)/2 +noncomputable def entropyB (m : Message) : ℝ := avg (fun i => m i*(mCenteredLog m i)^2)/2 +noncomputable def entropyF (m : Message) : ℝ := 3*entropyI m-2*entropyJ m+(4/5:ℝ)*entropyB m + +lemma measurable_mLog (i : Spin) : Measurable (fun m : Message => mLog m i) := + Real.measurable_log.comp ((continuous_apply i).comp continuous_subtype_val).measurable +lemma measurable_avg (f : Message → Spin → ℝ) (hf : ∀ i, Measurable (fun m => f m i)) : + Measurable (fun m => avg (f m)) := by + simp only [Radial.avg_expand] + exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 +lemma measurable_mCenteredLog (i : Spin) : Measurable (fun m : Message => mCenteredLog m i) := + (measurable_mLog i).sub (measurable_avg mLog measurable_mLog) +lemma measurable_entropyI : Measurable entropyI := + measurable_avg _ (fun i => ((continuous_apply i).comp continuous_subtype_val).measurable.mul (measurable_mLog i)) +lemma measurable_entropyJ : Measurable entropyJ := + (measurable_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).measurable.sub_const 1).mul (measurable_mLog i))).div_const 2 +lemma measurable_entropyB : Measurable entropyB := + (measurable_avg _ (fun i => ((continuous_apply i).comp continuous_subtype_val).measurable.mul ((measurable_mCenteredLog i).pow_const 2))).div_const 2 +lemma measurable_entropyF : Measurable entropyF := by + exact ((measurable_entropyI.const_mul 3).sub (measurable_entropyJ.const_mul 2)).add + (measurable_entropyB.const_mul (4/5:ℝ)) + +lemma centeredLog_combine (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) (i : Spin) : + mCenteredLog (combineMessage lam h m) i = ∑ j, mCenteredLog (edgeMessage lam h (m j)) i := by + simp only [mCenteredLog, mLog, Radial.avg_expand, log_combineMessage lam h hl0 hl1, + Finset.sum_sub_distrib, add_div, ← Finset.sum_div, Finset.sum_add_distrib] + ring + +lemma centeredLog_J (m : Message) : avg (fun i => m i*mCenteredLog m i) = 2*entropyJ m := by + simp only [mCenteredLog, entropyJ, mLog, Radial.avg_expand, message_last m] + ring + +lemma entropyF_radial (m : Message) : entropyF m = Radial.sourceF (fun i => m i) := by + simp only [entropyF, entropyI, entropyJ, entropyB, mCenteredLog, mLog, Radial.sourceF, + Radial.avg_expand] + ring + +lemma centeredLog_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) (i : Spin) : + |mCenteredLog m i| ≤ 2*C := by + calc + |mCenteredLog m i| ≤ |mLog m i|+|avg (mLog m)| := abs_sub _ _ + _ ≤ C+C := add_le_add (hc i) (abs_avg_le hc) + _ = _ := by ring + +lemma entropyI_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyI m| ≤ 3*C := by + apply abs_avg_le + intro i + rw [abs_mul, abs_of_nonneg (Message.nonneg m i)] + exact mul_le_mul (Message.le_three m i) (hc i) (abs_nonneg _) (by norm_num) + +lemma entropyJ_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyJ m| ≤ C := by + have hv (i : Spin) : |m i-1| ≤ 2 := abs_le.mpr ⟨by linarith [Message.nonneg m i], by linarith [Message.le_three m i]⟩ + have ha : |avg (fun i => (m i-1)*mLog m i)| ≤ 2*C := by + apply abs_avg_le + intro i + rw [abs_mul] + exact mul_le_mul (hv i) (hc i) (abs_nonneg _) (by norm_num) + dsimp only [entropyJ] + rw [abs_div, abs_of_pos (by norm_num : (0:ℝ)<2)] + linarith + +lemma entropyB_nonneg (m : Message) : 0 ≤ entropyB m := + div_nonneg (avg_nonneg (fun i => mul_nonneg (Message.nonneg m i) (sq_nonneg _))) (by norm_num) + +lemma entropyB_bound (m : Message) (C : ℝ) (hc : ∀ i, |mLog m i| ≤ C) : |entropyB m| ≤ 6*C^2 := by + have hC : 0 ≤ C := le_trans (abs_nonneg _) (hc 0) + have hu (i : Spin) : (mCenteredLog m i)^2 ≤ (2*C)^2 := by + have hh := (sq_le_sq₀ (abs_nonneg (mCenteredLog m i)) (by positivity : 0 ≤ 2*C)).mpr (centeredLog_bound m C hc i) + simpa only [sq_abs] using hh + have ha : avg (fun i => m i*(mCenteredLog m i)^2) ≤ 12*C^2 := by + apply avg_le_const + intro i + have hh := mul_le_mul (Message.le_three m i) (hu i) (sq_nonneg _) (by norm_num : (0:ℝ)≤3) + nlinarith + rw [abs_of_nonneg (entropyB_nonneg m)] + dsimp only [entropyB] + linarith + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma continuous_avg {α : Type*} [TopologicalSpace α] (f : α → Spin → ℝ) + (hf : ∀ i, Continuous (fun m => f m i)) : Continuous (fun m => avg (f m)) := by + simp only [Radial.avg_expand] + exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 + +lemma continuous_mLog_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (i : Spin) : + Continuous (fun m => mLog (edgeMessage lam h m) i) := + (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).log + (fun m => ne_of_gt (edgeMessage_pos lam h hl0 hl1 m i)) + +lemma continuous_mCenteredLog_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (i : Spin) : + Continuous (fun m => mCenteredLog (edgeMessage lam h m) i) := + (continuous_mLog_edge lam h hl0 hl1 i).sub + (continuous_avg _ (continuous_mLog_edge lam h hl0 hl1)) + +lemma continuous_entropyI_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun m => entropyI (edgeMessage lam h m)) := + continuous_avg _ (fun i => + (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul + (continuous_mLog_edge lam h hl0 hl1 i)) + +lemma continuous_entropyJ_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun m => entropyJ (edgeMessage lam h m)) := + (continuous_avg _ (fun i => + ((((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).sub continuous_const).mul + (continuous_mLog_edge lam h hl0 hl1 i))).div_const 2 + +lemma continuous_entropyB_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun m => entropyB (edgeMessage lam h m)) := + (continuous_avg _ (fun i => + (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul + ((continuous_mCenteredLog_edge lam h hl0 hl1 i).pow 2))).div_const 2 + +lemma integrable_mLog_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (i : Spin) : + Integrable (fun m => mLog m i) (Q : Measure Message) := by + apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ (measurable_mLog i) + (fun n => (n:ℝ)*(2*edgeLogBound lam)) (hD.mul_const _) + intro n m + have hh := log_combineMessage_bound lam h hl0 hl1 m i + dsimp only [mLog] + nlinarith + +lemma integrable_entropyI_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : + Integrable entropyI (Q : Measure Message) := by + apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyI + (fun n => (n:ℝ)*(6*edgeLogBound lam)) (hD.mul_const _) + intro n m + have hh := entropyI_bound (combineMessage lam h m) (2*n*edgeLogBound lam) + (log_combineMessage_bound lam h hl0 hl1 m) + nlinarith + +lemma integrable_entropyJ_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : + Integrable entropyJ (Q : Measure Message) := by + apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyJ + (fun n => (n:ℝ)*(2*edgeLogBound lam)) (hD.mul_const _) + intro n m + have hh := entropyJ_bound (combineMessage lam h m) (2*n*edgeLogBound lam) + (log_combineMessage_bound lam h hl0 hl1 m) + nlinarith + +lemma integrable_entropyB_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + Integrable entropyB (Q : Measure Message) := by + apply integrable_fixedpoint_of_growth offspring lam h Q hQ _ measurable_entropyB + (fun n => (n:ℝ)^2*(24*(edgeLogBound lam)^2)) (hD2.mul_const _) + intro n m + have hh := entropyB_bound (combineMessage lam h m) (2*n*edgeLogBound lam) + (log_combineMessage_bound lam h hl0 hl1 m) + nlinarith + +lemma integrable_entropyF_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + Integrable entropyF (Q : Measure Message) := by + have hD := hasMean_of_square hD2 + exact (((integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 3).sub + ((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 2)).add + ((integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2).const_mul (4/5:ℝ)) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/EntropyRecursion.lean b/lean/OAI/Probability/ThreeState/EntropyRecursion.lean index 7ad525ada548b5b47e9db62f5d502441ba02dab3..0c44c5d6dd6902ee1cd5ed7c033b213890bab6ae 100644 --- a/lean/OAI/Probability/ThreeState/EntropyRecursion.lean +++ b/lean/OAI/Probability/ThreeState/EntropyRecursion.lean @@ -1,464 +1,464 @@ -import Mathlib -import OAI.Probability.ThreeState.Entropy - -namespace OAI - -/-! Independent-branch entropy identities and correlation corrections. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma iid_integral_weighted_single (Q : ProbabilityMeasure Message) (n : ℕ) - (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) (a : Fin n) : - ∫ m : Fin n → Message, (∏ j, w (m j))*g (m a) ∂(iidMeasure Q n : Measure (Fin n → Message)) = - ∫ m, w m*g m ∂(Q : Measure Message) := by - have he (m : Fin n → Message) : (∏ j, w (m j))*g (m a) = - ∏ j, w (m j)*(if j=a then g (m j) else 1) := by - rw [Finset.prod_mul_distrib] - simp - simp_rw [he] - change (∫ m : Fin n → Message, ∏ j, w (m j)*(if j=a then g (m j) else 1) - ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = _ - rw [integral_fintype_prod_eq_prod (fun j (m : Message) => w m*(if j=a then g m else 1))] - have hi (j : Fin n) : (∫ m, w m*(if j=a then g m else 1) ∂(Q : Measure Message)) = - if j=a then ∫ m, w m*g m ∂(Q : Measure Message) else 1 := by - by_cases hj : j=a <;> simp [hj, hw] - simp_rw [hi] - simp - -lemma iid_integral_weighted_pair (Q : ProbabilityMeasure Message) (n : ℕ) - (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) (a b : Fin n) (hab : a ≠ b) : - ∫ m : Fin n → Message, (∏ j, w (m j))*g (m a)*g (m b) ∂(iidMeasure Q n : Measure (Fin n → Message)) = - (∫ m, w m*g m ∂(Q : Measure Message))^2 := by - have he (m : Fin n → Message) : (∏ j, w (m j))*g (m a)*g (m b) = - ∏ j, w (m j)*(if j=a then g (m j) else 1)*(if j=b then g (m j) else 1) := by - simp only [Finset.prod_mul_distrib, Finset.prod_ite_eq', Finset.mem_univ, ite_true] - simp_rw [he] - change (∫ m : Fin n → Message, ∏ j, w (m j)*(if j=a then g (m j) else 1)*(if j=b then g (m j) else 1) - ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = _ - rw [integral_fintype_prod_eq_prod (fun j (m : Message) => w m*(if j=a then g m else 1)*(if j=b then g m else 1))] - have hi (j : Fin n) : - (∫ m, w m*(if j=a then g m else 1)*(if j=b then g m else 1) ∂(Q : Measure Message)) = - (if j=a then ∫ m, w m*g m ∂(Q : Measure Message) else 1)* - (if j=b then ∫ m, w m*g m ∂(Q : Measure Message) else 1) := by - by_cases hja : j=a - · subst j - simp [hab] - · by_cases hjb : j=b - · subst j - simp [hja] - · simp [hja, hjb, hw] - simp_rw [hi] - simp only [Finset.prod_mul_distrib, Finset.prod_ite_eq', Finset.mem_univ, ite_true, pow_two] - -lemma iid_integral_weighted_sum (Q : ProbabilityMeasure Message) (n : ℕ) - (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) : - ∫ m : Fin n → Message, (∏ j, w (m j))*(∑ j, g (m j)) ∂(iidMeasure Q n : Measure (Fin n → Message)) = - n*(∫ m, w m*g m ∂(Q : Measure Message)) := by - simp_rw [Finset.mul_sum] - rw [integral_finsetSum] - · simp_rw [iid_integral_weighted_single Q n w g hw] - simp - · intro j _ - exact (show Continuous (fun m : Fin n → Message => (∏ k, w (m k))*g (m j)) by fun_prop).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -lemma iid_integral_weighted_sum_sq (Q : ProbabilityMeasure Message) (n : ℕ) - (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) : - ∫ m : Fin n → Message, (∏ j, w (m j))*(∑ j, g (m j))^2 ∂(iidMeasure Q n : Measure (Fin n → Message)) = - n*(∫ m, w m*(g m)^2 ∂(Q : Measure Message))+ - (n:ℝ)*(n-1)*(∫ m, w m*g m ∂(Q : Measure Message))^2 := by - have he (m : Fin n → Message) : (∏ j, w (m j))*(∑ j, g (m j))^2 = - ∑ a, ∑ b, (∏ j, w (m j))*g (m a)*g (m b) := by - simp only [pow_two, Finset.mul_sum, Finset.sum_mul, mul_assoc] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - ring - simp_rw [he] - have hi (a b : Fin n) : Integrable - (fun m : Fin n → Message => (∏ j, w (m j))*g (m a)*g (m b)) - (iidMeasure Q n : Measure (Fin n → Message)) := - (show Continuous _ by fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - rw [integral_finsetSum Finset.univ (fun a _ => integrable_finsetSum _ (fun b _ => hi a b))] - simp_rw [integral_finsetSum Finset.univ (fun b _ => hi _ b)] - have hj (a b : Fin n) : - (∫ m : Fin n → Message, (∏ j, w (m j))*g (m a)*g (m b) ∂(iidMeasure Q n : Measure (Fin n → Message))) = - (∫ m, w m*g m ∂(Q : Measure Message))^2 + - if a=b then (∫ m, w m*(g m)^2 ∂(Q : Measure Message))-(∫ m, w m*g m ∂(Q : Measure Message))^2 else 0 := by - by_cases hab : a=b - · subst b - have hp : (fun m : Fin n → Message => (∏ j, w (m j))*g (m a)*g (m a)) = - (fun m => (∏ j, w (m j))*(g (m a))^2) := by funext m; ring - rw [hp] - have hh := iid_integral_weighted_single Q n w (g*g) hw a - change (∫ m : Fin n → Message, (∏ j, w (m j))*(g (m a)*g (m a)) ∂(iidMeasure Q n : Measure (Fin n → Message))) = - (∫ m, w m*(g m*g m) ∂(Q : Measure Message)) at hh - simpa only [pow_two, ite_true, add_sub_cancel] using hh - · rw [iid_integral_weighted_pair Q n w g hw a b hab] - simp [hab] - simp_rw [hj] - simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, - Fintype.card_fin, nsmul_eq_mul, Finset.sum_ite_eq, Finset.mem_univ, ite_true] - ring - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma integral_avg {α : Type*} [MeasurableSpace α] (μ : Measure α) (f : α → Spin → ℝ) - (hf : ∀ i, Integrable (fun m => f m i) μ) : - ∫ m, avg (f m) ∂μ = avg (fun i => ∫ m, f m i ∂μ) := by - unfold avg - rw [integral_div, integral_finsetSum Finset.univ (fun i _ => hf i)] - -lemma integral_permMessage (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) - (π : Equiv.Perm Spin) (f : Message → ℝ) (hf : Measurable f) : - ∫ m, f (permMessage π m) ∂(Q : Measure Message) = ∫ m, f m ∂(Q : Measure Message) := by - have he : Measure.map (permMessage π) (Q : Measure Message) = (Q : Measure Message) := - congrArg ProbabilityMeasure.toMeasure (hQ π) - rw [← integral_map (continuous_permMessage π).measurable.aemeasurable hf.aestronglyMeasurable, he] - -lemma symmetric_integral_coordinate (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) - (f : Message → Spin → ℝ) (hf : ∀ i, Measurable (fun m => f m i)) - (he : ∀ (π : Equiv.Perm Spin) m i, f (permMessage π m) i = f m (π.symm i)) (i j : Spin) : - ∫ m, f m i ∂(Q : Measure Message) = ∫ m, f m j ∂(Q : Measure Message) := by - rw [← integral_permMessage Q hQ (Equiv.swap i j) (fun m => f m i) (hf i)] - apply integral_congr_ae - filter_upwards with m - rw [he] - simp - -lemma mLog_perm (π : Equiv.Perm Spin) (m : Message) (i : Spin) : - mLog (permMessage π m) i = mLog m (π.symm i) := rfl - -lemma mCenteredLog_perm (π : Equiv.Perm Spin) (m : Message) (i : Spin) : - mCenteredLog (permMessage π m) i = mCenteredLog m (π.symm i) := by - simp only [mCenteredLog, mLog_perm, avg, Equiv.sum_comp π.symm] - -lemma edgeMessage_perm (lam : ℝ) (h : Admissible lam) (π : Equiv.Perm Spin) (m : Message) : - edgeMessage lam h (permMessage π m) = permMessage π (edgeMessage lam h m) := rfl - -lemma integral_avg_eq_coordinate (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) - (f : Message → Spin → ℝ) (hf : ∀ i, Continuous (fun m => f m i)) - (he : ∀ (π : Equiv.Perm Spin) m i, f (permMessage π m) i = f m (π.symm i)) (i : Spin) : - ∫ m, avg (f m) ∂(Q : Measure Message) = ∫ m, f m i ∂(Q : Measure Message) := by - rw [integral_avg _ _ (fun j => (hf j).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] - have hh (j : Spin) := symmetric_integral_coordinate Q hQ f (fun j => (hf j).measurable) he j i - simp_rw [hh] - simp [avg] - -lemma integral_edge_centered (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) (i : Spin) : - ∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message) = - 2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by - have hc (j : Spin) : Continuous (fun m => edgeMessage lam h m j*mCenteredLog (edgeMessage lam h m) j) := - (((continuous_apply j).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul - (continuous_mCenteredLog_edge lam h hl0 hl1 j) - rw [← integral_avg_eq_coordinate Q hQ _ hc] - · simp_rw [centeredLog_J] - exact integral_const_mul _ _ - · intro π m j - rw [edgeMessage_perm, mCenteredLog_perm] - rfl - -lemma integral_edge_centered_sq (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) (i : Spin) : - ∫ m, edgeMessage lam h m i*(mCenteredLog (edgeMessage lam h m) i)^2 ∂(Q : Measure Message) = - 2*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message)) := by - have hc (j : Spin) : Continuous (fun m => edgeMessage lam h m j*(mCenteredLog (edgeMessage lam h m) j)^2) := - (((continuous_apply j).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul - ((continuous_mCenteredLog_edge lam h hl0 hl1 j).pow 2) - rw [← integral_avg_eq_coordinate Q hQ _ hc] - · have he (m : Message) : avg (fun j => edgeMessage lam h m j*(mCenteredLog (edgeMessage lam h m) j)^2) = - 2*entropyB (edgeMessage lam h m) := by unfold entropyB; ring - simp_rw [he] - exact integral_const_mul _ _ - · intro π m j - rw [edgeMessage_perm, mCenteredLog_perm] - rfl - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma weighted_avg_combine (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (v : Spin → ℝ) : - normalizer lam h m * avg (fun i => combineMessage lam h m i*v i) = - avg (fun i => productWeight lam h m i*v i) := by - unfold avg - rw [← mul_div_assoc, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro i _ - rw [← mul_assoc, weighted_combineMessage] - -lemma weighted_entropyJ (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - normalizer lam h m * entropyJ (combineMessage lam h m) = - avg (fun i => productWeight lam h m i*mCenteredLog (combineMessage lam h m) i)/2 := by - have hh := weighted_avg_combine lam h m (mCenteredLog (combineMessage lam h m)) - rw [centeredLog_J] at hh - linarith - -lemma weighted_entropyB (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - normalizer lam h m * entropyB (combineMessage lam h m) = - avg (fun i => productWeight lam h m i*(mCenteredLog (combineMessage lam h m) i)^2)/2 := by - rw [entropyB, ← mul_div_assoc, weighted_avg_combine] - -noncomputable def edgeCoordinateMap (lam : ℝ) (h : Admissible lam) (i : Spin) : C(Message,ℝ) := - ⟨fun m => edgeMessage lam h m i, ((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)⟩ - -noncomputable def edgeCenteredMap (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (i : Spin) : C(Message,ℝ) := - ⟨fun m => mCenteredLog (edgeMessage lam h m) i, continuous_mCenteredLog_edge lam h hl0 hl1 i⟩ - -lemma integral_degree_entropyJ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : - ∫ m : Fin n → Message, normalizer lam h m*entropyJ (combineMessage lam h m) - ∂(iidMeasure Q n : Measure (Fin n → Message)) = - n*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by - simp_rw [weighted_entropyJ, centeredLog_combine lam h hl0 hl1] - rw [integral_div, integral_avg] - · have hi (i : Spin) : - (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mCenteredLog (edgeMessage lam h (m j)) i) - ∂(iidMeasure Q n : Measure (Fin n → Message))) = - n*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) := by - have hh := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeCenteredMap lam h hl0 hl1 i) - (integral_edgeMessage lam h Q hQ i) - change _ = n*(∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message)) at hh - rw [integral_edge_centered lam h hl0 hl1 Q hs i] at hh - exact hh - simp_rw [hi] - simp [avg] - ring - · intro i - apply Continuous.integrable_of_hasCompactSupport _ (HasCompactSupport.of_compactSpace _) - exact (continuous_productWeight lam h n i).mul - (continuous_finsetSum _ (fun j _ => (continuous_mCenteredLog_edge lam h hl0 hl1 i).comp (continuous_apply j))) - -lemma integral_degree_entropyB (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : - ∫ m : Fin n → Message, normalizer lam h m*entropyB (combineMessage lam h m) - ∂(iidMeasure Q n : Measure (Fin n → Message)) = - n*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ - 2*(n:ℝ)*(n-1)*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by - simp_rw [weighted_entropyB, centeredLog_combine lam h hl0 hl1] - rw [integral_div, integral_avg] - · have hi (i : Spin) : - (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mCenteredLog (edgeMessage lam h (m j)) i)^2 - ∂(iidMeasure Q n : Measure (Fin n → Message))) = - n*(2*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message)))+ - (n:ℝ)*(n-1)*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)))^2 := by - have hh := iid_integral_weighted_sum_sq Q n (edgeCoordinateMap lam h i) (edgeCenteredMap lam h hl0 hl1 i) - (integral_edgeMessage lam h Q hQ i) - change _ = n*(∫ m, edgeMessage lam h m i*(mCenteredLog (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ - (n:ℝ)*(n-1)*(∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message))^2 at hh - rw [integral_edge_centered lam h hl0 hl1 Q hs i, integral_edge_centered_sq lam h hl0 hl1 Q hs i] at hh - exact hh - simp_rw [hi] - simp [avg] - ring - · intro i - apply Continuous.integrable_of_hasCompactSupport _ (HasCompactSupport.of_compactSpace _) - exact (continuous_productWeight lam h n i).mul - ((continuous_finsetSum _ (fun j _ => (continuous_mCenteredLog_edge lam h hl0 hl1 i).comp (continuous_apply j))).pow 2) - -lemma additive_entropyJ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : - ∫ m, entropyJ m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* - (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by - rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyJ - (integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD)] - simp_rw [integral_degree_entropyJ lam h hl0 hl1 Q hQ.1 hs] - exact mean_mul_const _ _ _ - -lemma hasMean_factorialSecond {offspring : PMF ℕ} (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - HasMean offspring (fun n : ℕ => (n:ℝ)*(n-1)) := by - have hD := hasMean_of_square hD2 - exact (hD2.add (hD.mul_const (-1))).congr (fun n => by ring) - -lemma additive_entropyB (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - ∫ m, entropyB m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* - (∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ - 2*mean offspring (fun n : ℕ => (n:ℝ)*(n-1))*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by - rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyB - (integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2)] - simp_rw [integral_degree_entropyB lam h hl0 hl1 Q hQ.1 hs] - have he (n : ℕ) : - (n:ℝ)*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ - 2*(n:ℝ)*(n-1)*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 = - (n:ℝ)*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ - ((n:ℝ)*(n-1))*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2) := by ring - simp_rw [he] - rw [mean_add ((hasMean_of_square hD2).mul_const _) ((hasMean_factorialSecond hD2).mul_const _), - mean_mul_const, mean_mul_const] - ring - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -noncomputable def correlationEntropy (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (n : ℕ) : ℝ := - ∫ m : Fin n → Message, normalizer lam h m * Real.log (normalizer lam h m) - ∂(iidMeasure Q n : Measure (Fin n → Message)) - -lemma continuous_log_normalizer (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) : - Continuous (fun m : Fin n → Message => Real.log (normalizer lam h m)) := - (continuous_normalizer lam h n).log (fun m => ne_of_gt (normalizer_pos lam h hl0 hl1 m)) - -lemma continuous_entropyI_combine (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) : - Continuous (fun m : Fin n → Message => entropyI (combineMessage lam h m)) := by - apply continuous_avg - intro i - have hc := ((continuous_apply i).comp continuous_subtype_val).comp - (continuous_combineMessage_positive lam h hl0 hl1 n) - exact hc.mul (hc.log (fun m => ne_of_gt (combineMessage_pos lam h hl0 hl1 m i))) - -lemma weighted_entropyI (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - {n : ℕ} (m : Fin n → Message) : - normalizer lam h m * entropyI (combineMessage lam h m) = - avg (fun i => productWeight lam h m i * (∑ j, mLog (edgeMessage lam h (m j)) i)) - - normalizer lam h m * Real.log (normalizer lam h m) := by - rw [entropyI, weighted_avg_combine] - simp only [mLog, log_combineMessage lam h hl0 hl1, Radial.avg_expand] - have hn : normalizer lam h m = (productWeight lam h m 0+productWeight lam h m 1+productWeight lam h m 2)/3 := by - simp [normalizer, Fin.sum_univ_succ]; ring - rw [hn] - ring - -noncomputable def edgeLogMap (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (i : Spin) : C(Message,ℝ) := - ⟨fun m => mLog (edgeMessage lam h m) i, continuous_mLog_edge lam h hl0 hl1 i⟩ - -lemma integral_degree_entropyI (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : - ∫ m : Fin n → Message, normalizer lam h m*entropyI (combineMessage lam h m) - ∂(iidMeasure Q n : Measure (Fin n → Message)) = - n*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-correlationEntropy lam h Q n := by - have hc (i : Spin) : Continuous (fun m : Fin n → Message => productWeight lam h m i * - (∑ j, mLog (edgeMessage lam h (m j)) i)) := - (continuous_productWeight lam h n i).mul - (continuous_finsetSum _ (fun j _ => (continuous_mLog_edge lam h hl0 hl1 i).comp (continuous_apply j))) - have hz : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := - (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) - simp_rw [weighted_entropyI lam h hl0 hl1] - rw [integral_sub ((continuous_avg _ hc).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) - (hz.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] - congr 1 - rw [integral_avg _ _ (fun i => (hc i).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] - have hi (i : Spin) := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeLogMap lam h hl0 hl1 i) - (integral_edgeMessage lam h Q hQ i) - change ∀ i : Spin, (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mLog (edgeMessage lam h (m j)) i) - ∂(iidMeasure Q n : Measure (Fin n → Message))) = n*(∫ m, edgeMessage lam h m i*mLog (edgeMessage lam h m) i - ∂(Q : Measure Message)) at hi - simp_rw [hi] - simp only [entropyI] - rw [integral_avg] - · simp only [Radial.avg_expand]; ring - · intro i - exact (((edgeCoordinateMap lam h i).continuous).mul (continuous_mLog_edge lam h hl0 hl1 i)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -lemma correlationEntropy_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : 0 ≤ correlationEntropy lam h Q n := by - have hc : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := - (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) - have hi : Integrable (normalizer lam h) (iidMeasure Q n : Measure (Fin n → Message)) := (continuous_normalizer lam h n).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hs (m : Fin n → Message) : normalizer lam h m-1 ≤ normalizer lam h m*Real.log (normalizer lam h m) := by - have hz := normalizer_pos lam h hl0 hl1 m - have hh := Real.one_sub_inv_le_log_of_pos hz - have hm := mul_le_mul_of_nonneg_left hh hz.le - rw [mul_sub, mul_one, mul_inv_cancel₀ (ne_of_gt hz)] at hm - exact hm - have hh := integral_mono (hi.sub (integrable_const 1)) (hc.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) hs - simp only [Pi.sub_apply] at hh - rw [integral_sub hi (integrable_const 1), integral_normalizer lam h Q hQ n] at hh - simpa [correlationEntropy] using hh - -lemma correlationEntropy_bound (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : |correlationEntropy lam h Q n| ≤ n*edgeLogBound lam := by - have hb (m : Fin n → Message) : |Real.log (normalizer lam h m)| ≤ n*edgeLogBound lam := - abs_log_of_bounds lam hl0 hl1 n _ (normalizer_bounds lam h hl0 hl1 m).1 (normalizer_bounds lam h hl0 hl1 m).2 - have hc : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := - (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) - have hi : Integrable (fun m : Fin n → Message => |normalizer lam h m*Real.log (normalizer lam h m)|) - (iidMeasure Q n : Measure (Fin n → Message)) := hc.abs.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hj : Integrable (fun m : Fin n → Message => normalizer lam h m*(n*edgeLogBound lam)) - (iidMeasure Q n : Measure (Fin n → Message)) := ((continuous_normalizer lam h n).mul_const (n*edgeLogBound lam)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - calc - |correlationEntropy lam h Q n| ≤ ∫ m, |normalizer lam h m*Real.log (normalizer lam h m)| - ∂(iidMeasure Q n : Measure (Fin n → Message)) := abs_integral_le_integral_abs - _ ≤ ∫ m, normalizer lam h m*(n*edgeLogBound lam) ∂(iidMeasure Q n : Measure (Fin n → Message)) := by - apply integral_mono hi hj - intro m - dsimp only - rw [abs_mul, abs_of_nonneg (normalizer_nonneg lam h m)] - exact mul_le_mul_of_nonneg_left (hb m) (normalizer_nonneg lam h m) - _ = _ := by rw [integral_mul_const, integral_normalizer lam h Q hQ n, one_mul] - -lemma hasMean_correlationEntropy (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) (hQ : Balanced Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : HasMean offspring (correlationEntropy lam h Q) := by - apply HasMean.of_abs - exact (hD.mul_const (edgeLogBound lam)).mono (fun n => abs_nonneg _) - (correlationEntropy_bound lam h hl0 hl1 Q hQ) - -lemma additive_entropyI (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : - ∫ m, entropyI m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* - (∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-mean offspring (correlationEntropy lam h Q) := by - rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyI - (integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD)] - simp_rw [integral_degree_entropyI lam h hl0 hl1 Q hQ.1] - have he (n : ℕ) : (n:ℝ)*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-correlationEntropy lam h Q n = - (n:ℝ)*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))+correlationEntropy lam h Q n*(-1) := by ring - simp_rw [he] - rw [mean_add (hD.mul_const _) ((hasMean_correlationEntropy offspring lam h hl0 hl1 Q hQ.1 hD).mul_const _), - mean_mul_const, mean_mul_const] - ring - -lemma entropy_identity (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - (∫ m, entropyF m ∂(Q : Measure Message)) - mean offspring (fun n : ℕ => (n:ℝ))* - (∫ m, entropyF (edgeMessage lam h m) ∂(Q : Measure Message)) = - -3*mean offspring (correlationEntropy lam h Q) + - (8/5:ℝ)*mean offspring (fun n : ℕ => (n:ℝ)*(n-1))*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by - have hD := hasMean_of_square hD2 - have hi := integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD - have hj := integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD - have hb := integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2 - have hie : Integrable (fun m => entropyI (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyI_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hje : Integrable (fun m => entropyJ (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyJ_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hbe : Integrable (fun m => entropyB (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyB_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hlin (f g k : Message → ℝ) (hf : Integrable f (Q : Measure Message)) - (hg : Integrable g (Q : Measure Message)) (hk : Integrable k (Q : Measure Message)) : - (∫ m, 3*f m-2*g m+(4/5:ℝ)*k m ∂(Q : Measure Message)) = - 3*(∫ m, f m ∂(Q : Measure Message))-2*(∫ m, g m ∂(Q : Measure Message))+ - (4/5:ℝ)*(∫ m, k m ∂(Q : Measure Message)) := by - have hsub : Integrable (fun m => 3*f m-2*g m) (Q : Measure Message) := (hf.const_mul 3).sub (hg.const_mul 2) - rw [integral_add hsub (hk.const_mul (4/5:ℝ)), integral_sub (hf.const_mul 3) (hg.const_mul 2)] - simp only [integral_const_mul] - simp only [entropyF] - rw [hlin _ _ _ hi hj hb, hlin _ _ _ hie hje hbe] - rw [additive_entropyI offspring lam h hl0 hl1 Q hQ hD, - additive_entropyJ offspring lam h hl0 hl1 Q hQ hs hD, - additive_entropyB offspring lam h hl0 hl1 Q hQ hs hD2] - ring - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Entropy + +namespace OAI + +/-! Independent-branch entropy identities and correlation corrections. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma iid_integral_weighted_single (Q : ProbabilityMeasure Message) (n : ℕ) + (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) (a : Fin n) : + ∫ m : Fin n → Message, (∏ j, w (m j))*g (m a) ∂(iidMeasure Q n : Measure (Fin n → Message)) = + ∫ m, w m*g m ∂(Q : Measure Message) := by + have he (m : Fin n → Message) : (∏ j, w (m j))*g (m a) = + ∏ j, w (m j)*(if j=a then g (m j) else 1) := by + rw [Finset.prod_mul_distrib] + simp + simp_rw [he] + change (∫ m : Fin n → Message, ∏ j, w (m j)*(if j=a then g (m j) else 1) + ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = _ + rw [integral_fintype_prod_eq_prod (fun j (m : Message) => w m*(if j=a then g m else 1))] + have hi (j : Fin n) : (∫ m, w m*(if j=a then g m else 1) ∂(Q : Measure Message)) = + if j=a then ∫ m, w m*g m ∂(Q : Measure Message) else 1 := by + by_cases hj : j=a <;> simp [hj, hw] + simp_rw [hi] + simp + +lemma iid_integral_weighted_pair (Q : ProbabilityMeasure Message) (n : ℕ) + (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) (a b : Fin n) (hab : a ≠ b) : + ∫ m : Fin n → Message, (∏ j, w (m j))*g (m a)*g (m b) ∂(iidMeasure Q n : Measure (Fin n → Message)) = + (∫ m, w m*g m ∂(Q : Measure Message))^2 := by + have he (m : Fin n → Message) : (∏ j, w (m j))*g (m a)*g (m b) = + ∏ j, w (m j)*(if j=a then g (m j) else 1)*(if j=b then g (m j) else 1) := by + simp only [Finset.prod_mul_distrib, Finset.prod_ite_eq', Finset.mem_univ, ite_true] + simp_rw [he] + change (∫ m : Fin n → Message, ∏ j, w (m j)*(if j=a then g (m j) else 1)*(if j=b then g (m j) else 1) + ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = _ + rw [integral_fintype_prod_eq_prod (fun j (m : Message) => w m*(if j=a then g m else 1)*(if j=b then g m else 1))] + have hi (j : Fin n) : + (∫ m, w m*(if j=a then g m else 1)*(if j=b then g m else 1) ∂(Q : Measure Message)) = + (if j=a then ∫ m, w m*g m ∂(Q : Measure Message) else 1)* + (if j=b then ∫ m, w m*g m ∂(Q : Measure Message) else 1) := by + by_cases hja : j=a + · subst j + simp [hab] + · by_cases hjb : j=b + · subst j + simp [hja] + · simp [hja, hjb, hw] + simp_rw [hi] + simp only [Finset.prod_mul_distrib, Finset.prod_ite_eq', Finset.mem_univ, ite_true, pow_two] + +lemma iid_integral_weighted_sum (Q : ProbabilityMeasure Message) (n : ℕ) + (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) : + ∫ m : Fin n → Message, (∏ j, w (m j))*(∑ j, g (m j)) ∂(iidMeasure Q n : Measure (Fin n → Message)) = + n*(∫ m, w m*g m ∂(Q : Measure Message)) := by + simp_rw [Finset.mul_sum] + rw [integral_finsetSum] + · simp_rw [iid_integral_weighted_single Q n w g hw] + simp + · intro j _ + exact (show Continuous (fun m : Fin n → Message => (∏ k, w (m k))*g (m j)) by fun_prop).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma iid_integral_weighted_sum_sq (Q : ProbabilityMeasure Message) (n : ℕ) + (w g : C(Message,ℝ)) (hw : ∫ m, w m ∂(Q : Measure Message) = 1) : + ∫ m : Fin n → Message, (∏ j, w (m j))*(∑ j, g (m j))^2 ∂(iidMeasure Q n : Measure (Fin n → Message)) = + n*(∫ m, w m*(g m)^2 ∂(Q : Measure Message))+ + (n:ℝ)*(n-1)*(∫ m, w m*g m ∂(Q : Measure Message))^2 := by + have he (m : Fin n → Message) : (∏ j, w (m j))*(∑ j, g (m j))^2 = + ∑ a, ∑ b, (∏ j, w (m j))*g (m a)*g (m b) := by + simp only [pow_two, Finset.mul_sum, Finset.sum_mul, mul_assoc] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + ring + simp_rw [he] + have hi (a b : Fin n) : Integrable + (fun m : Fin n → Message => (∏ j, w (m j))*g (m a)*g (m b)) + (iidMeasure Q n : Measure (Fin n → Message)) := + (show Continuous _ by fun_prop).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + rw [integral_finsetSum Finset.univ (fun a _ => integrable_finsetSum _ (fun b _ => hi a b))] + simp_rw [integral_finsetSum Finset.univ (fun b _ => hi _ b)] + have hj (a b : Fin n) : + (∫ m : Fin n → Message, (∏ j, w (m j))*g (m a)*g (m b) ∂(iidMeasure Q n : Measure (Fin n → Message))) = + (∫ m, w m*g m ∂(Q : Measure Message))^2 + + if a=b then (∫ m, w m*(g m)^2 ∂(Q : Measure Message))-(∫ m, w m*g m ∂(Q : Measure Message))^2 else 0 := by + by_cases hab : a=b + · subst b + have hp : (fun m : Fin n → Message => (∏ j, w (m j))*g (m a)*g (m a)) = + (fun m => (∏ j, w (m j))*(g (m a))^2) := by funext m; ring + rw [hp] + have hh := iid_integral_weighted_single Q n w (g*g) hw a + change (∫ m : Fin n → Message, (∏ j, w (m j))*(g (m a)*g (m a)) ∂(iidMeasure Q n : Measure (Fin n → Message))) = + (∫ m, w m*(g m*g m) ∂(Q : Measure Message)) at hh + simpa only [pow_two, ite_true, add_sub_cancel] using hh + · rw [iid_integral_weighted_pair Q n w g hw a b hab] + simp [hab] + simp_rw [hj] + simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + ring + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma integral_avg {α : Type*} [MeasurableSpace α] (μ : Measure α) (f : α → Spin → ℝ) + (hf : ∀ i, Integrable (fun m => f m i) μ) : + ∫ m, avg (f m) ∂μ = avg (fun i => ∫ m, f m i ∂μ) := by + unfold avg + rw [integral_div, integral_finsetSum Finset.univ (fun i _ => hf i)] + +lemma integral_permMessage (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) + (π : Equiv.Perm Spin) (f : Message → ℝ) (hf : Measurable f) : + ∫ m, f (permMessage π m) ∂(Q : Measure Message) = ∫ m, f m ∂(Q : Measure Message) := by + have he : Measure.map (permMessage π) (Q : Measure Message) = (Q : Measure Message) := + congrArg ProbabilityMeasure.toMeasure (hQ π) + rw [← integral_map (continuous_permMessage π).measurable.aemeasurable hf.aestronglyMeasurable, he] + +lemma symmetric_integral_coordinate (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) + (f : Message → Spin → ℝ) (hf : ∀ i, Measurable (fun m => f m i)) + (he : ∀ (π : Equiv.Perm Spin) m i, f (permMessage π m) i = f m (π.symm i)) (i j : Spin) : + ∫ m, f m i ∂(Q : Measure Message) = ∫ m, f m j ∂(Q : Measure Message) := by + rw [← integral_permMessage Q hQ (Equiv.swap i j) (fun m => f m i) (hf i)] + apply integral_congr_ae + filter_upwards with m + rw [he] + simp + +lemma mLog_perm (π : Equiv.Perm Spin) (m : Message) (i : Spin) : + mLog (permMessage π m) i = mLog m (π.symm i) := rfl + +lemma mCenteredLog_perm (π : Equiv.Perm Spin) (m : Message) (i : Spin) : + mCenteredLog (permMessage π m) i = mCenteredLog m (π.symm i) := by + simp only [mCenteredLog, mLog_perm, avg, Equiv.sum_comp π.symm] + +lemma edgeMessage_perm (lam : ℝ) (h : Admissible lam) (π : Equiv.Perm Spin) (m : Message) : + edgeMessage lam h (permMessage π m) = permMessage π (edgeMessage lam h m) := rfl + +lemma integral_avg_eq_coordinate (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) + (f : Message → Spin → ℝ) (hf : ∀ i, Continuous (fun m => f m i)) + (he : ∀ (π : Equiv.Perm Spin) m i, f (permMessage π m) i = f m (π.symm i)) (i : Spin) : + ∫ m, avg (f m) ∂(Q : Measure Message) = ∫ m, f m i ∂(Q : Measure Message) := by + rw [integral_avg _ _ (fun j => (hf j).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] + have hh (j : Spin) := symmetric_integral_coordinate Q hQ f (fun j => (hf j).measurable) he j i + simp_rw [hh] + simp [avg] + +lemma integral_edge_centered (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) (i : Spin) : + ∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message) = + 2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by + have hc (j : Spin) : Continuous (fun m => edgeMessage lam h m j*mCenteredLog (edgeMessage lam h m) j) := + (((continuous_apply j).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul + (continuous_mCenteredLog_edge lam h hl0 hl1 j) + rw [← integral_avg_eq_coordinate Q hQ _ hc] + · simp_rw [centeredLog_J] + exact integral_const_mul _ _ + · intro π m j + rw [edgeMessage_perm, mCenteredLog_perm] + rfl + +lemma integral_edge_centered_sq (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : SpinSymmetric Q) (i : Spin) : + ∫ m, edgeMessage lam h m i*(mCenteredLog (edgeMessage lam h m) i)^2 ∂(Q : Measure Message) = + 2*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message)) := by + have hc (j : Spin) : Continuous (fun m => edgeMessage lam h m j*(mCenteredLog (edgeMessage lam h m) j)^2) := + (((continuous_apply j).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)).mul + ((continuous_mCenteredLog_edge lam h hl0 hl1 j).pow 2) + rw [← integral_avg_eq_coordinate Q hQ _ hc] + · have he (m : Message) : avg (fun j => edgeMessage lam h m j*(mCenteredLog (edgeMessage lam h m) j)^2) = + 2*entropyB (edgeMessage lam h m) := by unfold entropyB; ring + simp_rw [he] + exact integral_const_mul _ _ + · intro π m j + rw [edgeMessage_perm, mCenteredLog_perm] + rfl + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma weighted_avg_combine (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (v : Spin → ℝ) : + normalizer lam h m * avg (fun i => combineMessage lam h m i*v i) = + avg (fun i => productWeight lam h m i*v i) := by + unfold avg + rw [← mul_div_assoc, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro i _ + rw [← mul_assoc, weighted_combineMessage] + +lemma weighted_entropyJ (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + normalizer lam h m * entropyJ (combineMessage lam h m) = + avg (fun i => productWeight lam h m i*mCenteredLog (combineMessage lam h m) i)/2 := by + have hh := weighted_avg_combine lam h m (mCenteredLog (combineMessage lam h m)) + rw [centeredLog_J] at hh + linarith + +lemma weighted_entropyB (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + normalizer lam h m * entropyB (combineMessage lam h m) = + avg (fun i => productWeight lam h m i*(mCenteredLog (combineMessage lam h m) i)^2)/2 := by + rw [entropyB, ← mul_div_assoc, weighted_avg_combine] + +noncomputable def edgeCoordinateMap (lam : ℝ) (h : Admissible lam) (i : Spin) : C(Message,ℝ) := + ⟨fun m => edgeMessage lam h m i, ((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h)⟩ + +noncomputable def edgeCenteredMap (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (i : Spin) : C(Message,ℝ) := + ⟨fun m => mCenteredLog (edgeMessage lam h m) i, continuous_mCenteredLog_edge lam h hl0 hl1 i⟩ + +lemma integral_degree_entropyJ (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : + ∫ m : Fin n → Message, normalizer lam h m*entropyJ (combineMessage lam h m) + ∂(iidMeasure Q n : Measure (Fin n → Message)) = + n*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by + simp_rw [weighted_entropyJ, centeredLog_combine lam h hl0 hl1] + rw [integral_div, integral_avg] + · have hi (i : Spin) : + (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mCenteredLog (edgeMessage lam h (m j)) i) + ∂(iidMeasure Q n : Measure (Fin n → Message))) = + n*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) := by + have hh := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeCenteredMap lam h hl0 hl1 i) + (integral_edgeMessage lam h Q hQ i) + change _ = n*(∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message)) at hh + rw [integral_edge_centered lam h hl0 hl1 Q hs i] at hh + exact hh + simp_rw [hi] + simp [avg] + ring + · intro i + apply Continuous.integrable_of_hasCompactSupport _ (HasCompactSupport.of_compactSpace _) + exact (continuous_productWeight lam h n i).mul + (continuous_finsetSum _ (fun j _ => (continuous_mCenteredLog_edge lam h hl0 hl1 i).comp (continuous_apply j))) + +lemma integral_degree_entropyB (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : + ∫ m : Fin n → Message, normalizer lam h m*entropyB (combineMessage lam h m) + ∂(iidMeasure Q n : Measure (Fin n → Message)) = + n*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ + 2*(n:ℝ)*(n-1)*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by + simp_rw [weighted_entropyB, centeredLog_combine lam h hl0 hl1] + rw [integral_div, integral_avg] + · have hi (i : Spin) : + (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mCenteredLog (edgeMessage lam h (m j)) i)^2 + ∂(iidMeasure Q n : Measure (Fin n → Message))) = + n*(2*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message)))+ + (n:ℝ)*(n-1)*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)))^2 := by + have hh := iid_integral_weighted_sum_sq Q n (edgeCoordinateMap lam h i) (edgeCenteredMap lam h hl0 hl1 i) + (integral_edgeMessage lam h Q hQ i) + change _ = n*(∫ m, edgeMessage lam h m i*(mCenteredLog (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ + (n:ℝ)*(n-1)*(∫ m, edgeMessage lam h m i*mCenteredLog (edgeMessage lam h m) i ∂(Q : Measure Message))^2 at hh + rw [integral_edge_centered lam h hl0 hl1 Q hs i, integral_edge_centered_sq lam h hl0 hl1 Q hs i] at hh + exact hh + simp_rw [hi] + simp [avg] + ring + · intro i + apply Continuous.integrable_of_hasCompactSupport _ (HasCompactSupport.of_compactSpace _) + exact (continuous_productWeight lam h n i).mul + ((continuous_finsetSum _ (fun j _ => (continuous_mCenteredLog_edge lam h hl0 hl1 i).comp (continuous_apply j))).pow 2) + +lemma additive_entropyJ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : + ∫ m, entropyJ m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* + (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) := by + rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyJ + (integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD)] + simp_rw [integral_degree_entropyJ lam h hl0 hl1 Q hQ.1 hs] + exact mean_mul_const _ _ _ + +lemma hasMean_factorialSecond {offspring : PMF ℕ} (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + HasMean offspring (fun n : ℕ => (n:ℝ)*(n-1)) := by + have hD := hasMean_of_square hD2 + exact (hD2.add (hD.mul_const (-1))).congr (fun n => by ring) + +lemma additive_entropyB (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + ∫ m, entropyB m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* + (∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ + 2*mean offspring (fun n : ℕ => (n:ℝ)*(n-1))*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by + rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyB + (integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2)] + simp_rw [integral_degree_entropyB lam h hl0 hl1 Q hQ.1 hs] + have he (n : ℕ) : + (n:ℝ)*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ + 2*(n:ℝ)*(n-1)*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 = + (n:ℝ)*(∫ m, entropyB (edgeMessage lam h m) ∂(Q : Measure Message))+ + ((n:ℝ)*(n-1))*(2*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2) := by ring + simp_rw [he] + rw [mean_add ((hasMean_of_square hD2).mul_const _) ((hasMean_factorialSecond hD2).mul_const _), + mean_mul_const, mean_mul_const] + ring + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +noncomputable def correlationEntropy (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (n : ℕ) : ℝ := + ∫ m : Fin n → Message, normalizer lam h m * Real.log (normalizer lam h m) + ∂(iidMeasure Q n : Measure (Fin n → Message)) + +lemma continuous_log_normalizer (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) : + Continuous (fun m : Fin n → Message => Real.log (normalizer lam h m)) := + (continuous_normalizer lam h n).log (fun m => ne_of_gt (normalizer_pos lam h hl0 hl1 m)) + +lemma continuous_entropyI_combine (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) (n : ℕ) : + Continuous (fun m : Fin n → Message => entropyI (combineMessage lam h m)) := by + apply continuous_avg + intro i + have hc := ((continuous_apply i).comp continuous_subtype_val).comp + (continuous_combineMessage_positive lam h hl0 hl1 n) + exact hc.mul (hc.log (fun m => ne_of_gt (combineMessage_pos lam h hl0 hl1 m i))) + +lemma weighted_entropyI (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + {n : ℕ} (m : Fin n → Message) : + normalizer lam h m * entropyI (combineMessage lam h m) = + avg (fun i => productWeight lam h m i * (∑ j, mLog (edgeMessage lam h (m j)) i)) - + normalizer lam h m * Real.log (normalizer lam h m) := by + rw [entropyI, weighted_avg_combine] + simp only [mLog, log_combineMessage lam h hl0 hl1, Radial.avg_expand] + have hn : normalizer lam h m = (productWeight lam h m 0+productWeight lam h m 1+productWeight lam h m 2)/3 := by + simp [normalizer, Fin.sum_univ_succ]; ring + rw [hn] + ring + +noncomputable def edgeLogMap (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (i : Spin) : C(Message,ℝ) := + ⟨fun m => mLog (edgeMessage lam h m) i, continuous_mLog_edge lam h hl0 hl1 i⟩ + +lemma integral_degree_entropyI (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : + ∫ m : Fin n → Message, normalizer lam h m*entropyI (combineMessage lam h m) + ∂(iidMeasure Q n : Measure (Fin n → Message)) = + n*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-correlationEntropy lam h Q n := by + have hc (i : Spin) : Continuous (fun m : Fin n → Message => productWeight lam h m i * + (∑ j, mLog (edgeMessage lam h (m j)) i)) := + (continuous_productWeight lam h n i).mul + (continuous_finsetSum _ (fun j _ => (continuous_mLog_edge lam h hl0 hl1 i).comp (continuous_apply j))) + have hz : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := + (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) + simp_rw [weighted_entropyI lam h hl0 hl1] + rw [integral_sub ((continuous_avg _ hc).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) + (hz.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] + congr 1 + rw [integral_avg _ _ (fun i => (hc i).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] + have hi (i : Spin) := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeLogMap lam h hl0 hl1 i) + (integral_edgeMessage lam h Q hQ i) + change ∀ i : Spin, (∫ m : Fin n → Message, productWeight lam h m i*(∑ j, mLog (edgeMessage lam h (m j)) i) + ∂(iidMeasure Q n : Measure (Fin n → Message))) = n*(∫ m, edgeMessage lam h m i*mLog (edgeMessage lam h m) i + ∂(Q : Measure Message)) at hi + simp_rw [hi] + simp only [entropyI] + rw [integral_avg] + · simp only [Radial.avg_expand]; ring + · intro i + exact (((edgeCoordinateMap lam h i).continuous).mul (continuous_mLog_edge lam h hl0 hl1 i)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma correlationEntropy_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : 0 ≤ correlationEntropy lam h Q n := by + have hc : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := + (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) + have hi : Integrable (normalizer lam h) (iidMeasure Q n : Measure (Fin n → Message)) := (continuous_normalizer lam h n).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hs (m : Fin n → Message) : normalizer lam h m-1 ≤ normalizer lam h m*Real.log (normalizer lam h m) := by + have hz := normalizer_pos lam h hl0 hl1 m + have hh := Real.one_sub_inv_le_log_of_pos hz + have hm := mul_le_mul_of_nonneg_left hh hz.le + rw [mul_sub, mul_one, mul_inv_cancel₀ (ne_of_gt hz)] at hm + exact hm + have hh := integral_mono (hi.sub (integrable_const 1)) (hc.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) hs + simp only [Pi.sub_apply] at hh + rw [integral_sub hi (integrable_const 1), integral_normalizer lam h Q hQ n] at hh + simpa [correlationEntropy] using hh + +lemma correlationEntropy_bound (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (n : ℕ) : |correlationEntropy lam h Q n| ≤ n*edgeLogBound lam := by + have hb (m : Fin n → Message) : |Real.log (normalizer lam h m)| ≤ n*edgeLogBound lam := + abs_log_of_bounds lam hl0 hl1 n _ (normalizer_bounds lam h hl0 hl1 m).1 (normalizer_bounds lam h hl0 hl1 m).2 + have hc : Continuous (fun m : Fin n → Message => normalizer lam h m*Real.log (normalizer lam h m)) := + (continuous_normalizer lam h n).mul (continuous_log_normalizer lam h hl0 hl1 n) + have hi : Integrable (fun m : Fin n → Message => |normalizer lam h m*Real.log (normalizer lam h m)|) + (iidMeasure Q n : Measure (Fin n → Message)) := hc.abs.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hj : Integrable (fun m : Fin n → Message => normalizer lam h m*(n*edgeLogBound lam)) + (iidMeasure Q n : Measure (Fin n → Message)) := ((continuous_normalizer lam h n).mul_const (n*edgeLogBound lam)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + calc + |correlationEntropy lam h Q n| ≤ ∫ m, |normalizer lam h m*Real.log (normalizer lam h m)| + ∂(iidMeasure Q n : Measure (Fin n → Message)) := abs_integral_le_integral_abs + _ ≤ ∫ m, normalizer lam h m*(n*edgeLogBound lam) ∂(iidMeasure Q n : Measure (Fin n → Message)) := by + apply integral_mono hi hj + intro m + dsimp only + rw [abs_mul, abs_of_nonneg (normalizer_nonneg lam h m)] + exact mul_le_mul_of_nonneg_left (hb m) (normalizer_nonneg lam h m) + _ = _ := by rw [integral_mul_const, integral_normalizer lam h Q hQ n, one_mul] + +lemma hasMean_correlationEntropy (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) (hQ : Balanced Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : HasMean offspring (correlationEntropy lam h Q) := by + apply HasMean.of_abs + exact (hD.mul_const (edgeLogBound lam)).mono (fun n => abs_nonneg _) + (correlationEntropy_bound lam h hl0 hl1 Q hQ) + +lemma additive_entropyI (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : + ∫ m, entropyI m ∂(Q : Measure Message) = mean offspring (fun n : ℕ => (n:ℝ))* + (∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-mean offspring (correlationEntropy lam h Q) := by + rw [integral_fixedpoint offspring lam h Q hQ _ measurable_entropyI + (integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD)] + simp_rw [integral_degree_entropyI lam h hl0 hl1 Q hQ.1] + have he (n : ℕ) : (n:ℝ)*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))-correlationEntropy lam h Q n = + (n:ℝ)*(∫ m, entropyI (edgeMessage lam h m) ∂(Q : Measure Message))+correlationEntropy lam h Q n*(-1) := by ring + simp_rw [he] + rw [mean_add (hD.mul_const _) ((hasMean_correlationEntropy offspring lam h hl0 hl1 Q hQ.1 hD).mul_const _), + mean_mul_const, mean_mul_const] + ring + +lemma entropy_identity (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + (∫ m, entropyF m ∂(Q : Measure Message)) - mean offspring (fun n : ℕ => (n:ℝ))* + (∫ m, entropyF (edgeMessage lam h m) ∂(Q : Measure Message)) = + -3*mean offspring (correlationEntropy lam h Q) + + (8/5:ℝ)*mean offspring (fun n : ℕ => (n:ℝ)*(n-1))*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))^2 := by + have hD := hasMean_of_square hD2 + have hi := integrable_entropyI_fixedpoint offspring lam h hl0 hl1 Q hQ hD + have hj := integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD + have hb := integrable_entropyB_fixedpoint offspring lam h hl0 hl1 Q hQ hD2 + have hie : Integrable (fun m => entropyI (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyI_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hje : Integrable (fun m => entropyJ (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyJ_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hbe : Integrable (fun m => entropyB (edgeMessage lam h m)) (Q : Measure Message) := (continuous_entropyB_edge lam h hl0 hl1).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hlin (f g k : Message → ℝ) (hf : Integrable f (Q : Measure Message)) + (hg : Integrable g (Q : Measure Message)) (hk : Integrable k (Q : Measure Message)) : + (∫ m, 3*f m-2*g m+(4/5:ℝ)*k m ∂(Q : Measure Message)) = + 3*(∫ m, f m ∂(Q : Measure Message))-2*(∫ m, g m ∂(Q : Measure Message))+ + (4/5:ℝ)*(∫ m, k m ∂(Q : Measure Message)) := by + have hsub : Integrable (fun m => 3*f m-2*g m) (Q : Measure Message) := (hf.const_mul 3).sub (hg.const_mul 2) + rw [integral_add hsub (hk.const_mul (4/5:ℝ)), integral_sub (hf.const_mul 3) (hg.const_mul 2)] + simp only [integral_const_mul] + simp only [entropyF] + rw [hlin _ _ _ hi hj hb, hlin _ _ _ hie hje hbe] + rw [additive_entropyI offspring lam h hl0 hl1 Q hQ hD, + additive_entropyJ offspring lam h hl0 hl1 Q hQ hs hD, + additive_entropyB offspring lam h hl0 hl1 Q hQ hs hD2] + ring + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Expectations.lean b/lean/OAI/Probability/ThreeState/Expectations.lean index e8b5370678a2baf21631a53c64dd216bc6289e87..b0c93d36b48ea7ac882047e4a3ae62ee9aab0a05 100644 --- a/lean/OAI/Probability/ThreeState/Expectations.lean +++ b/lean/OAI/Probability/ThreeState/Expectations.lean @@ -1,384 +1,384 @@ -import Mathlib -import OAI.Probability.ThreeState.Basic - -namespace OAI - -/-! Expectations, second moments and the regular and Poisson offspring laws. -/ - -namespace ThreeState -open scoped Classical - - -noncomputable def mean {α : Type*} (p : PMF α) (f : α → ℝ) : ℝ := - ∑' a, mass p a * f a - -def HasMean {α : Type*} (p : PMF α) (f : α → ℝ) : Prop := - Summable (fun a => mass p a * f a) - -lemma HasMean.abs {α : Type*} {p : PMF α} {f : α → ℝ} (h : HasMean p f) : - HasMean p (fun a => |f a|) := by - simpa only [HasMean, abs_mul, abs_of_nonneg (mass_nonneg p _)] using Summable.abs h - -lemma HasMean.of_abs {α : Type*} {p : PMF α} {f : α → ℝ} - (h : HasMean p (fun a => |f a|)) : HasMean p f := by - apply summable_norm_iff.mp - simpa only [HasMean, Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg p _)] using h - -lemma hasMean_const {α : Type*} (p : PMF α) (c : ℝ) : HasMean p (fun _ => c) := - (mass_summable p).mul_right c - -lemma mean_const {α : Type*} (p : PMF α) (c : ℝ) : mean p (fun _ => c) = c := by - rw [mean, (mass_summable p).tsum_mul_right, mass_sum, one_mul] - -lemma HasMean.add {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) (hg : HasMean p g) : - HasMean p (fun a => f a+g a) := by - simpa only [HasMean, mul_add] using Summable.add hf hg - -lemma mean_add {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) (hg : HasMean p g) : - mean p (fun a => f a+g a) = mean p f+mean p g := by - simp only [mean, mul_add, hf.tsum_add hg] - -lemma HasMean.mul_const {α : Type*} {p : PMF α} {f : α → ℝ} (hf : HasMean p f) (c : ℝ) : - HasMean p (fun a => f a*c) := by - simpa only [HasMean, mul_assoc] using hf.mul_right c - -lemma mean_mul_const {α : Type*} (p : PMF α) (f : α → ℝ) (c : ℝ) : - mean p (fun a => f a*c) = mean p f*c := by - simp only [mean, ← mul_assoc, tsum_mul_right] - -lemma HasMean.const_mul {α : Type*} {p : PMF α} {f : α → ℝ} (hf : HasMean p f) (c : ℝ) : - HasMean p (fun a => c*f a) := by - simpa only [mul_comm c] using hf.mul_const c - -lemma mean_const_mul {α : Type*} (p : PMF α) (f : α → ℝ) (c : ℝ) : - mean p (fun a => c*f a) = c*mean p f := by - simp only [mul_comm c, mean_mul_const] - -lemma hasMean_of_square {α : Type*} {p : PMF α} {f : α → ℝ} - (h : HasMean p (fun a => (f a)^2)) : HasMean p f := by - apply HasMean.of_abs - apply Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (abs_nonneg _)) - (fun a => mul_le_mul_of_nonneg_left (by nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)]) - (mass_nonneg p a)) ((hasMean_const p 1).add h) - -lemma mass_pure {α : Type*} (a b : α) : mass (PMF.pure a) b = if b=a then 1 else 0 := by - classical - by_cases h : b=a <;> simp [mass, PMF.pure_apply, h] - -lemma mean_pure {α : Type*} (a : α) (f : α → ℝ) : mean (PMF.pure a) f = f a := by - classical - simp [mean, mass_pure] - -lemma hasMean_pure {α : Type*} (a : α) (f : α → ℝ) : HasMean (PMF.pure a) f := by - classical - simp only [HasMean, mass_pure, ite_mul, one_mul, zero_mul] - exact summable_of_ne_finset_zero (s := {a}) (fun b hb => by simp at hb; simp [hb]) - -lemma mean_nonneg {α : Type*} (p : PMF α) {f : α → ℝ} (hf : ∀ a, 0 ≤ f a) : - 0 ≤ mean p f := tsum_nonneg (fun a => mul_nonneg (mass_nonneg p a) (hf a)) - -lemma HasMean.bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) f) - (hp : HasMean p (fun a => mean (k a) (fun b => |f b|))) : - HasMean (p.bind k) f := by - have hs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * |f b|))) := by - apply (summable_prod_of_nonneg (fun ab => - mul_nonneg (mass_nonneg p ab.1) (mul_nonneg (mass_nonneg _ _) (abs_nonneg _)))).mpr - change (∀ a, Summable (fun b => mass p a * (mass (k a) b * |f b|))) ∧ - Summable (fun a => ∑' b, mass p a * (mass (k a) b * |f b|)) - constructor - · intro a - exact (hk a).abs.mul_left (mass p a) - · simpa only [tsum_mul_left, mean, HasMean] using hp - apply HasMean.of_abs - apply hs.prod_symm.prod.congr - intro b - change (∑' a, mass p a * (mass (k a) b * |f b|)) = mass (p.bind k) b * |f b| - rw [mass_bind, ← tsum_mul_right] - congr 1 - funext a - ring - -lemma mean_bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) f) - (hp : HasMean p (fun a => mean (k a) (fun b => |f b|))) : - mean (p.bind k) f = mean p (fun a => mean (k a) f) := by - have hsabs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * |f b|))) := by - apply (summable_prod_of_nonneg (fun ab => - mul_nonneg (mass_nonneg p ab.1) (mul_nonneg (mass_nonneg _ _) (abs_nonneg _)))).mpr - change (∀ a, Summable (fun b => mass p a * (mass (k a) b * |f b|))) ∧ - Summable (fun a => ∑' b, mass p a * (mass (k a) b * |f b|)) - constructor - · intro a - exact (hk a).abs.mul_left (mass p a) - · simpa only [tsum_mul_left, mean, HasMean] using hp - have hs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * f b))) := by - apply summable_norm_iff.mp - apply hsabs.congr - rintro ⟨a,b⟩ - change mass p a * (mass (k a) b * |f b|) = ‖mass p a * (mass (k a) b * f b)‖ - rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_of_nonneg (mass_nonneg p a), - abs_of_nonneg (mass_nonneg (k a) b)] - unfold mean - simp_rw [mass_bind, ← tsum_mul_right, mul_assoc] - rw [hs.tsum_comm] - simp only [tsum_mul_left] - -lemma HasMean.map {α β : Type*} {p : PMF α} {g : α → β} {f : β → ℝ} - (h : HasMean p (fun a => f (g a))) : HasMean (p.map g) f := by - change HasMean (p.bind (fun a => PMF.pure (g a))) f - apply HasMean.bind (fun a => hasMean_pure _ _) - simpa only [mean_pure] using h.abs - -lemma mean_map {α β : Type*} {p : PMF α} {g : α → β} {f : β → ℝ} - (h : HasMean p (fun a => f (g a))) : mean (p.map g) f = mean p (fun a => f (g a)) := by - change mean (p.bind (fun a => PMF.pure (g a))) f = _ - rw [mean_bind (fun a => hasMean_pure _ _) (by simpa only [mean_pure] using h.abs)] - simp only [mean_pure] - -end ThreeState -namespace ThreeState -open scoped Classical - -lemma HasMean.mono {α : Type*} {p : PMF α} {f g : α → ℝ} (hg : HasMean p g) - (hf : ∀ a, 0 ≤ f a) (hle : ∀ a, f a ≤ g a) : HasMean p f := by - exact Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (hf a)) - (fun a => mul_le_mul_of_nonneg_left (hle a) (mass_nonneg p a)) hg - -lemma mean_le {α : Type*} {p : PMF α} {f g : α → ℝ} - (hf : HasMean p f) (hg : HasMean p g) (hle : ∀ a, f a ≤ g a) : mean p f ≤ mean p g := by - exact Summable.tsum_le_tsum (fun a => mul_le_mul_of_nonneg_left (hle a) (mass_nonneg p a)) hf hg - -lemma mean_abs_le_one_add_square {α : Type*} {p : PMF α} {f : α → ℝ} - (hf : HasMean p (fun a => (f a)^2)) : - mean p (fun a => |f a|) ≤ 1+mean p (fun a => (f a)^2) := by - have h := mean_le (hasMean_of_square hf).abs ((hasMean_const p 1).add hf) - (fun a => (show |f a| ≤ 1+(f a)^2 by nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)])) - simpa only [mean_add (hasMean_const p 1) hf, mean_const] using h - -lemma hasMean_bind_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) - (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : - HasMean (p.bind k) (fun b => (f b)^2) := by - apply HasMean.bind hk - simpa only [abs_sq] using hp - -lemma hasMean_bind_abs_of_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) - (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : - HasMean p (fun a => mean (k a) (fun b => |f b|)) := by - exact ((hasMean_const p 1).add hp).mono - (fun a => mean_nonneg _ (fun b => abs_nonneg _)) - (fun a => mean_abs_le_one_add_square (hk a)) - -lemma mean_bind_of_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) - (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : - mean (p.bind k) f = mean p (fun a => mean (k a) f) := - mean_bind (fun a => hasMean_of_square (hk a)) (hasMean_bind_abs_of_square hk hp) - -lemma mean_bind_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) - (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : - mean (p.bind k) (fun b => (f b)^2) = mean p (fun a => mean (k a) (fun b => (f b)^2)) := by - apply mean_bind hk - simpa only [abs_sq] using hp - -lemma HasMean.congr {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) - (hfg : ∀ a, f a = g a) : HasMean p g := by - exact Summable.congr hf (fun a => congrArg (fun x => mass p a*x) (hfg a)) - -lemma mean_congr {α : Type*} (p : PMF α) {f g : α → ℝ} (hfg : ∀ a, f a = g a) : - mean p f = mean p g := tsum_congr (fun a => congrArg (fun x => mass p a*x) (hfg a)) - -lemma hasMean_shift_square {α : Type*} {p : PMF α} {f : α → ℝ} - (hf : HasMean p (fun a => (f a)^2)) (c : ℝ) : HasMean p (fun a => (c+f a)^2) := by - exact (((hasMean_const p (c^2)).add ((hasMean_of_square hf).const_mul (2*c))).add hf).congr - (fun a => by ring) - -lemma mean_shift_square {α : Type*} {p : PMF α} {f : α → ℝ} - (hf : HasMean p (fun a => (f a)^2)) (c : ℝ) : - mean p (fun a => (c+f a)^2) = c^2+2*c*mean p f+mean p (fun a => (f a)^2) := by - rw [mean_congr p (g := fun a => c^2+(2*c)*f a+(f a)^2) (fun a => by ring), - mean_add ((hasMean_const p (c^2)).add ((hasMean_of_square hf).const_mul (2*c))) hf, - mean_add (hasMean_const p (c^2)) ((hasMean_of_square hf).const_mul (2*c)), - mean_const, mean_const_mul] - -lemma hasMean_fintype {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : HasMean p f := - summable_of_hasFiniteSupport (Set.toFinite _) - -lemma mean_fintype {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : - mean p f = ∑ a, mass p a * f a := tsum_fintype _ - - - -structure Moments {α : Type*} (p : PMF α) (f : α → ℝ) (m s : ℝ) : Prop where - square : HasMean p (fun a => (f a)^2) - first : mean p f = m - second : mean p (fun a => (f a)^2) = s - -lemma Moments.hasMean {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} - (h : Moments p f m s) : HasMean p f := hasMean_of_square h.square - -lemma Moments.map {α β : Type*} {p : PMF α} {f : β → ℝ} {g : α → β} {m s : ℝ} - (h : Moments p (fun a => f (g a)) m s) : Moments (p.map g) f m s := by - refine ⟨HasMean.map (g := g) (f := fun b => (f b)^2) h.square, ?_, ?_⟩ - · exact (mean_map (g := g) (f := f) h.hasMean).trans h.first - · exact (mean_map (g := g) (f := fun b => (f b)^2) h.square).trans h.second - -lemma Moments.pure {α : Type*} (a : α) (f : α → ℝ) : - Moments (PMF.pure a) f (f a) ((f a)^2) := - ⟨hasMean_pure _ _, mean_pure _ _, mean_pure _ _⟩ - -lemma Moments.shift {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} - (h : Moments p f m s) (c : ℝ) : - Moments p (fun a => c+f a) (c+m) (c^2+2*c*m+s) := by - refine ⟨hasMean_shift_square h.square c, ?_, ?_⟩ - · rw [mean_add (hasMean_const p c) h.hasMean, mean_const, h.first] - · rw [mean_shift_square h.square, h.first, h.second] - -lemma Moments.bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} - {m s : α → ℝ} {M S : ℝ} (hk : ∀ a, Moments (k a) f (m a) (s a)) - (hs : HasMean p s) (hm : mean p m = M) (hS : mean p s = S) : - Moments (p.bind k) f M S := by - have hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2)) := - hs.congr (fun a => (hk a).second.symm) - refine ⟨hasMean_bind_square (fun a => (hk a).square) hp, ?_, ?_⟩ - · rw [mean_bind_of_square (fun a => (hk a).square) hp] - simpa only [(hk _).first] using hm - · rw [mean_bind_square (fun a => (hk a).square) hp] - simpa only [(hk _).second] using hS - -lemma Moments.independent_add {α β : Type*} {p : PMF α} {q : PMF β} - {f : α → ℝ} {g : β → ℝ} {m s n t : ℝ} - (hf : Moments p f m s) (hg : Moments q g n t) : - Moments (p.bind (fun a => q.map (fun b => (a,b)))) - (fun ab => f ab.1+g ab.2) (m+n) (s+2*m*n+t) := by - apply Moments.bind (m := fun a => f a+n) (s := fun a => (f a)^2+2*f a*n+t) - (fun a => Moments.map (g := fun b => (a,b)) (f := fun ab => f ab.1+g ab.2) (hg.shift (f a))) - · exact (hf.square.add (hf.hasMean.mul_const (2*n))).add (hasMean_const p t) |>.congr - (fun a => by ring) - · rw [mean_add hf.hasMean (hasMean_const p n), hf.first, mean_const] - · have he := mean_add (hf.square.add (hf.hasMean.mul_const (2*n))) (hasMean_const p t) - rw [mean_congr p (g := fun a => ((f a)^2+f a*(2*n))+t) (fun a => by ring), he, - mean_add hf.square (hf.hasMean.mul_const (2*n)), mean_mul_const, hf.first, hf.second, mean_const] - ring - -end ThreeState -namespace ThreeState - -lemma hasMean_bounded {α : Type*} (p : PMF α) {f : α → ℝ} (C : ℝ) - (hf : ∀ a, |f a| ≤ C) : HasMean p f := - HasMean.of_abs ((hasMean_const p C).mono (fun value => abs_nonneg (f value)) hf) - -lemma abs_mean_le {α : Type*} (p : PMF α) {f : α → ℝ} (C : ℝ) - (hf : ∀ a, |f a| ≤ C) : |mean p f| ≤ C := by - have hi := hasMean_bounded p C hf - rw [abs_le] - constructor - · simpa only [mean_const] using mean_le (hasMean_const p (-C)) hi (fun a => (abs_le.mp (hf a)).1) - · simpa only [mean_const] using mean_le hi (hasMean_const p C) (fun a => (abs_le.mp (hf a)).2) - -lemma mean_bind_bounded {α β : Type*} (p : PMF α) (k : α → PMF β) (f : β → ℝ) - (C : ℝ) (hf : ∀ b, |f b| ≤ C) : - mean (p.bind k) f = mean p (fun a => mean (k a) f) := by - apply mean_bind (fun a => hasMean_bounded (k a) C hf) - exact hasMean_bounded p C (fun a => abs_mean_le (k a) C (fun b => by simpa using hf b)) - -lemma mean_map_bounded {α β : Type*} (p : PMF α) (g : α → β) (f : β → ℝ) - (C : ℝ) (hf : ∀ a, |f (g a)| ≤ C) : - mean (p.map g) f = mean p (fun a => f (g a)) := - mean_map (hasMean_bounded p C hf) - - -noncomputable def joint {α β : Type*} (p : PMF α) (k : α → PMF β) : PMF (α × β) := - p.bind (fun a => (k a).map (fun b => (a,b))) - -lemma mean_joint_bounded {α β : Type*} (p : PMF α) (k : α → PMF β) (f : α × β → ℝ) - (C : ℝ) (hf : ∀ ab, |f ab| ≤ C) : - mean (joint p k) f = mean p (fun a => mean (k a) (fun b => f (a,b))) := by - rw [joint, mean_bind_bounded p _ f C hf] - apply mean_congr - intro a - exact mean_map_bounded (k a) _ f C (fun b => hf (a,b)) - -lemma mean_joint_fst {α β : Type*} (p : PMF α) (k : α → PMF β) (f : α → ℝ) - (C : ℝ) (hf : ∀ a, |f a| ≤ C) : - mean (joint p k) (fun ab => f ab.1) = mean p f := by - rw [mean_joint_bounded p k _ C (fun ab => hf ab.1)] - simp only [mean_const] - -lemma mean_joint_snd {α β : Type*} (p : PMF α) (k : α → PMF β) (f : β → ℝ) - (C : ℝ) (hf : ∀ b, |f b| ≤ C) : - mean (joint p k) (fun ab => f ab.2) = mean (p.bind k) f := by - rw [mean_joint_bounded p k _ C (fun ab => hf ab.2), mean_bind_bounded p k f C hf] - -end ThreeState - -namespace ThreeState - -lemma HasMean.sub {α : Type*} {p : PMF α} {f g : α → ℝ} - (hf : HasMean p f) (hg : HasMean p g) : HasMean p (fun a => f a-g a) := by - simpa only [HasMean, mul_sub] using Summable.sub hf hg - -lemma mean_sub {α : Type*} {p : PMF α} {f g : α → ℝ} - (hf : HasMean p f) (hg : HasMean p g) : - mean p (fun a => f a-g a) = mean p f-mean p g := by - simp only [mean, mul_sub, hf.tsum_sub hg] - -lemma poisson_mass (d : ℝ) (hd : 0 ≤ d) (k : ℕ) : - mass (poissonOffspring d hd) k = Real.exp (-d)*d^k/(k.factorial : ℝ) := by - change (ENNReal.ofReal _).toReal = _ - apply ENNReal.toReal_ofReal - positivity - -lemma poisson_mass_succ (d : ℝ) (hd : 0 ≤ d) (k : ℕ) : - mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ) = - d*mass (poissonOffspring d hd) k := by - rw [poisson_mass, poisson_mass, Nat.factorial_succ, Nat.cast_mul, pow_succ] - have hk : ((k+1 : ℕ) : ℝ) ≠ 0 := by positivity - have hf : (k.factorial : ℝ) ≠ 0 := by positivity - field_simp - -lemma poisson_first_hasSum (d : ℝ) (hd : 0 ≤ d) : - HasSum (fun k : ℕ => mass (poissonOffspring d hd) k * (k : ℝ)) d := by - have h : HasSum (fun k : ℕ => mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) d := by - simpa only [poisson_mass_succ, mass_sum, mul_one] using - (mass_summable (poissonOffspring d hd)).hasSum.mul_left d - have hz : mass (poissonOffspring d hd) 0*(0:ℝ) = 0 := mul_zero _ - exact (hasSum_nat_add_iff' 1).mp (by simpa [hz, mass_sum] using h) - -lemma poisson_second_factorial_hasSum (d : ℝ) (hd : 0 ≤ d) : - HasSum (fun k : ℕ => mass (poissonOffspring d hd) k * ((k : ℝ)*((k : ℝ)-1))) (d^2) := by - have hh (k : ℕ) : - mass (poissonOffspring d hd) (k+2) * (((k+2 : ℕ) : ℝ)*(((k+2 : ℕ) : ℝ)-1)) = - d*(mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) := by - have he := poisson_mass_succ d hd (k+1) - push_cast at he ⊢ - nlinarith [congrArg (fun x => x*((k:ℝ)+1)) he] - have h : HasSum (fun k : ℕ => - mass (poissonOffspring d hd) (k+2) * (((k+2 : ℕ) : ℝ)*(((k+2 : ℕ) : ℝ)-1))) (d^2) := by - have h1 : HasSum (fun k : ℕ => mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) d := by - simpa only [poisson_mass_succ, mass_sum, mul_one] using - (mass_summable (poissonOffspring d hd)).hasSum.mul_left d - simpa only [hh, pow_two] using h1.mul_left d - exact (hasSum_nat_add_iff' 2).mp (by simpa [Finset.sum_range_succ] using h) - - -theorem poisson_moments (d : ℝ) (hd : 0 ≤ d) : - Moments (poissonOffspring d hd) (fun k : ℕ => (k : ℝ)) d (d^2+d) := by - have h1 := poisson_first_hasSum d hd - have h2 := poisson_second_factorial_hasSum d hd - have hs : HasSum (fun k : ℕ => mass (poissonOffspring d hd) k*(k:ℝ)^2) (d^2+d) := by - convert h2.add h1 using 1 - funext k - ring - exact ⟨hs.summable, h1.tsum_eq, hs.tsum_eq⟩ - -lemma regular_moments (b : ℕ) : - Moments (PMF.pure b) (fun k : ℕ => (k : ℝ)) (b:ℝ) ((b:ℝ)^2) := - Moments.pure b _ - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Basic + +namespace OAI + +/-! Expectations, second moments and the regular and Poisson offspring laws. -/ + +namespace ThreeState +open scoped Classical + + +noncomputable def mean {α : Type*} (p : PMF α) (f : α → ℝ) : ℝ := + ∑' a, mass p a * f a + +def HasMean {α : Type*} (p : PMF α) (f : α → ℝ) : Prop := + Summable (fun a => mass p a * f a) + +lemma HasMean.abs {α : Type*} {p : PMF α} {f : α → ℝ} (h : HasMean p f) : + HasMean p (fun a => |f a|) := by + simpa only [HasMean, abs_mul, abs_of_nonneg (mass_nonneg p _)] using Summable.abs h + +lemma HasMean.of_abs {α : Type*} {p : PMF α} {f : α → ℝ} + (h : HasMean p (fun a => |f a|)) : HasMean p f := by + apply summable_norm_iff.mp + simpa only [HasMean, Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg p _)] using h + +lemma hasMean_const {α : Type*} (p : PMF α) (c : ℝ) : HasMean p (fun _ => c) := + (mass_summable p).mul_right c + +lemma mean_const {α : Type*} (p : PMF α) (c : ℝ) : mean p (fun _ => c) = c := by + rw [mean, (mass_summable p).tsum_mul_right, mass_sum, one_mul] + +lemma HasMean.add {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) (hg : HasMean p g) : + HasMean p (fun a => f a+g a) := by + simpa only [HasMean, mul_add] using Summable.add hf hg + +lemma mean_add {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) (hg : HasMean p g) : + mean p (fun a => f a+g a) = mean p f+mean p g := by + simp only [mean, mul_add, hf.tsum_add hg] + +lemma HasMean.mul_const {α : Type*} {p : PMF α} {f : α → ℝ} (hf : HasMean p f) (c : ℝ) : + HasMean p (fun a => f a*c) := by + simpa only [HasMean, mul_assoc] using hf.mul_right c + +lemma mean_mul_const {α : Type*} (p : PMF α) (f : α → ℝ) (c : ℝ) : + mean p (fun a => f a*c) = mean p f*c := by + simp only [mean, ← mul_assoc, tsum_mul_right] + +lemma HasMean.const_mul {α : Type*} {p : PMF α} {f : α → ℝ} (hf : HasMean p f) (c : ℝ) : + HasMean p (fun a => c*f a) := by + simpa only [mul_comm c] using hf.mul_const c + +lemma mean_const_mul {α : Type*} (p : PMF α) (f : α → ℝ) (c : ℝ) : + mean p (fun a => c*f a) = c*mean p f := by + simp only [mul_comm c, mean_mul_const] + +lemma hasMean_of_square {α : Type*} {p : PMF α} {f : α → ℝ} + (h : HasMean p (fun a => (f a)^2)) : HasMean p f := by + apply HasMean.of_abs + apply Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (abs_nonneg _)) + (fun a => mul_le_mul_of_nonneg_left (by nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)]) + (mass_nonneg p a)) ((hasMean_const p 1).add h) + +lemma mass_pure {α : Type*} (a b : α) : mass (PMF.pure a) b = if b=a then 1 else 0 := by + classical + by_cases h : b=a <;> simp [mass, PMF.pure_apply, h] + +lemma mean_pure {α : Type*} (a : α) (f : α → ℝ) : mean (PMF.pure a) f = f a := by + classical + simp [mean, mass_pure] + +lemma hasMean_pure {α : Type*} (a : α) (f : α → ℝ) : HasMean (PMF.pure a) f := by + classical + simp only [HasMean, mass_pure, ite_mul, one_mul, zero_mul] + exact summable_of_ne_finset_zero (s := {a}) (fun b hb => by simp at hb; simp [hb]) + +lemma mean_nonneg {α : Type*} (p : PMF α) {f : α → ℝ} (hf : ∀ a, 0 ≤ f a) : + 0 ≤ mean p f := tsum_nonneg (fun a => mul_nonneg (mass_nonneg p a) (hf a)) + +lemma HasMean.bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) f) + (hp : HasMean p (fun a => mean (k a) (fun b => |f b|))) : + HasMean (p.bind k) f := by + have hs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * |f b|))) := by + apply (summable_prod_of_nonneg (fun ab => + mul_nonneg (mass_nonneg p ab.1) (mul_nonneg (mass_nonneg _ _) (abs_nonneg _)))).mpr + change (∀ a, Summable (fun b => mass p a * (mass (k a) b * |f b|))) ∧ + Summable (fun a => ∑' b, mass p a * (mass (k a) b * |f b|)) + constructor + · intro a + exact (hk a).abs.mul_left (mass p a) + · simpa only [tsum_mul_left, mean, HasMean] using hp + apply HasMean.of_abs + apply hs.prod_symm.prod.congr + intro b + change (∑' a, mass p a * (mass (k a) b * |f b|)) = mass (p.bind k) b * |f b| + rw [mass_bind, ← tsum_mul_right] + congr 1 + funext a + ring + +lemma mean_bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) f) + (hp : HasMean p (fun a => mean (k a) (fun b => |f b|))) : + mean (p.bind k) f = mean p (fun a => mean (k a) f) := by + have hsabs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * |f b|))) := by + apply (summable_prod_of_nonneg (fun ab => + mul_nonneg (mass_nonneg p ab.1) (mul_nonneg (mass_nonneg _ _) (abs_nonneg _)))).mpr + change (∀ a, Summable (fun b => mass p a * (mass (k a) b * |f b|))) ∧ + Summable (fun a => ∑' b, mass p a * (mass (k a) b * |f b|)) + constructor + · intro a + exact (hk a).abs.mul_left (mass p a) + · simpa only [tsum_mul_left, mean, HasMean] using hp + have hs : Summable (Function.uncurry (fun a b => mass p a * (mass (k a) b * f b))) := by + apply summable_norm_iff.mp + apply hsabs.congr + rintro ⟨a,b⟩ + change mass p a * (mass (k a) b * |f b|) = ‖mass p a * (mass (k a) b * f b)‖ + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_of_nonneg (mass_nonneg p a), + abs_of_nonneg (mass_nonneg (k a) b)] + unfold mean + simp_rw [mass_bind, ← tsum_mul_right, mul_assoc] + rw [hs.tsum_comm] + simp only [tsum_mul_left] + +lemma HasMean.map {α β : Type*} {p : PMF α} {g : α → β} {f : β → ℝ} + (h : HasMean p (fun a => f (g a))) : HasMean (p.map g) f := by + change HasMean (p.bind (fun a => PMF.pure (g a))) f + apply HasMean.bind (fun a => hasMean_pure _ _) + simpa only [mean_pure] using h.abs + +lemma mean_map {α β : Type*} {p : PMF α} {g : α → β} {f : β → ℝ} + (h : HasMean p (fun a => f (g a))) : mean (p.map g) f = mean p (fun a => f (g a)) := by + change mean (p.bind (fun a => PMF.pure (g a))) f = _ + rw [mean_bind (fun a => hasMean_pure _ _) (by simpa only [mean_pure] using h.abs)] + simp only [mean_pure] + +end ThreeState +namespace ThreeState +open scoped Classical + +lemma HasMean.mono {α : Type*} {p : PMF α} {f g : α → ℝ} (hg : HasMean p g) + (hf : ∀ a, 0 ≤ f a) (hle : ∀ a, f a ≤ g a) : HasMean p f := by + exact Summable.of_nonneg_of_le (fun a => mul_nonneg (mass_nonneg p a) (hf a)) + (fun a => mul_le_mul_of_nonneg_left (hle a) (mass_nonneg p a)) hg + +lemma mean_le {α : Type*} {p : PMF α} {f g : α → ℝ} + (hf : HasMean p f) (hg : HasMean p g) (hle : ∀ a, f a ≤ g a) : mean p f ≤ mean p g := by + exact Summable.tsum_le_tsum (fun a => mul_le_mul_of_nonneg_left (hle a) (mass_nonneg p a)) hf hg + +lemma mean_abs_le_one_add_square {α : Type*} {p : PMF α} {f : α → ℝ} + (hf : HasMean p (fun a => (f a)^2)) : + mean p (fun a => |f a|) ≤ 1+mean p (fun a => (f a)^2) := by + have h := mean_le (hasMean_of_square hf).abs ((hasMean_const p 1).add hf) + (fun a => (show |f a| ≤ 1+(f a)^2 by nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)])) + simpa only [mean_add (hasMean_const p 1) hf, mean_const] using h + +lemma hasMean_bind_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) + (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : + HasMean (p.bind k) (fun b => (f b)^2) := by + apply HasMean.bind hk + simpa only [abs_sq] using hp + +lemma hasMean_bind_abs_of_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) + (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : + HasMean p (fun a => mean (k a) (fun b => |f b|)) := by + exact ((hasMean_const p 1).add hp).mono + (fun a => mean_nonneg _ (fun b => abs_nonneg _)) + (fun a => mean_abs_le_one_add_square (hk a)) + +lemma mean_bind_of_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) + (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : + mean (p.bind k) f = mean p (fun a => mean (k a) f) := + mean_bind (fun a => hasMean_of_square (hk a)) (hasMean_bind_abs_of_square hk hp) + +lemma mean_bind_square {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + (hk : ∀ a, HasMean (k a) (fun b => (f b)^2)) + (hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2))) : + mean (p.bind k) (fun b => (f b)^2) = mean p (fun a => mean (k a) (fun b => (f b)^2)) := by + apply mean_bind hk + simpa only [abs_sq] using hp + +lemma HasMean.congr {α : Type*} {p : PMF α} {f g : α → ℝ} (hf : HasMean p f) + (hfg : ∀ a, f a = g a) : HasMean p g := by + exact Summable.congr hf (fun a => congrArg (fun x => mass p a*x) (hfg a)) + +lemma mean_congr {α : Type*} (p : PMF α) {f g : α → ℝ} (hfg : ∀ a, f a = g a) : + mean p f = mean p g := tsum_congr (fun a => congrArg (fun x => mass p a*x) (hfg a)) + +lemma hasMean_shift_square {α : Type*} {p : PMF α} {f : α → ℝ} + (hf : HasMean p (fun a => (f a)^2)) (c : ℝ) : HasMean p (fun a => (c+f a)^2) := by + exact (((hasMean_const p (c^2)).add ((hasMean_of_square hf).const_mul (2*c))).add hf).congr + (fun a => by ring) + +lemma mean_shift_square {α : Type*} {p : PMF α} {f : α → ℝ} + (hf : HasMean p (fun a => (f a)^2)) (c : ℝ) : + mean p (fun a => (c+f a)^2) = c^2+2*c*mean p f+mean p (fun a => (f a)^2) := by + rw [mean_congr p (g := fun a => c^2+(2*c)*f a+(f a)^2) (fun a => by ring), + mean_add ((hasMean_const p (c^2)).add ((hasMean_of_square hf).const_mul (2*c))) hf, + mean_add (hasMean_const p (c^2)) ((hasMean_of_square hf).const_mul (2*c)), + mean_const, mean_const_mul] + +lemma hasMean_fintype {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : HasMean p f := + summable_of_hasFiniteSupport (Set.toFinite _) + +lemma mean_fintype {α : Type*} [Fintype α] (p : PMF α) (f : α → ℝ) : + mean p f = ∑ a, mass p a * f a := tsum_fintype _ + + + +structure Moments {α : Type*} (p : PMF α) (f : α → ℝ) (m s : ℝ) : Prop where + square : HasMean p (fun a => (f a)^2) + first : mean p f = m + second : mean p (fun a => (f a)^2) = s + +lemma Moments.hasMean {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} + (h : Moments p f m s) : HasMean p f := hasMean_of_square h.square + +lemma Moments.map {α β : Type*} {p : PMF α} {f : β → ℝ} {g : α → β} {m s : ℝ} + (h : Moments p (fun a => f (g a)) m s) : Moments (p.map g) f m s := by + refine ⟨HasMean.map (g := g) (f := fun b => (f b)^2) h.square, ?_, ?_⟩ + · exact (mean_map (g := g) (f := f) h.hasMean).trans h.first + · exact (mean_map (g := g) (f := fun b => (f b)^2) h.square).trans h.second + +lemma Moments.pure {α : Type*} (a : α) (f : α → ℝ) : + Moments (PMF.pure a) f (f a) ((f a)^2) := + ⟨hasMean_pure _ _, mean_pure _ _, mean_pure _ _⟩ + +lemma Moments.shift {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} + (h : Moments p f m s) (c : ℝ) : + Moments p (fun a => c+f a) (c+m) (c^2+2*c*m+s) := by + refine ⟨hasMean_shift_square h.square c, ?_, ?_⟩ + · rw [mean_add (hasMean_const p c) h.hasMean, mean_const, h.first] + · rw [mean_shift_square h.square, h.first, h.second] + +lemma Moments.bind {α β : Type*} {p : PMF α} {k : α → PMF β} {f : β → ℝ} + {m s : α → ℝ} {M S : ℝ} (hk : ∀ a, Moments (k a) f (m a) (s a)) + (hs : HasMean p s) (hm : mean p m = M) (hS : mean p s = S) : + Moments (p.bind k) f M S := by + have hp : HasMean p (fun a => mean (k a) (fun b => (f b)^2)) := + hs.congr (fun a => (hk a).second.symm) + refine ⟨hasMean_bind_square (fun a => (hk a).square) hp, ?_, ?_⟩ + · rw [mean_bind_of_square (fun a => (hk a).square) hp] + simpa only [(hk _).first] using hm + · rw [mean_bind_square (fun a => (hk a).square) hp] + simpa only [(hk _).second] using hS + +lemma Moments.independent_add {α β : Type*} {p : PMF α} {q : PMF β} + {f : α → ℝ} {g : β → ℝ} {m s n t : ℝ} + (hf : Moments p f m s) (hg : Moments q g n t) : + Moments (p.bind (fun a => q.map (fun b => (a,b)))) + (fun ab => f ab.1+g ab.2) (m+n) (s+2*m*n+t) := by + apply Moments.bind (m := fun a => f a+n) (s := fun a => (f a)^2+2*f a*n+t) + (fun a => Moments.map (g := fun b => (a,b)) (f := fun ab => f ab.1+g ab.2) (hg.shift (f a))) + · exact (hf.square.add (hf.hasMean.mul_const (2*n))).add (hasMean_const p t) |>.congr + (fun a => by ring) + · rw [mean_add hf.hasMean (hasMean_const p n), hf.first, mean_const] + · have he := mean_add (hf.square.add (hf.hasMean.mul_const (2*n))) (hasMean_const p t) + rw [mean_congr p (g := fun a => ((f a)^2+f a*(2*n))+t) (fun a => by ring), he, + mean_add hf.square (hf.hasMean.mul_const (2*n)), mean_mul_const, hf.first, hf.second, mean_const] + ring + +end ThreeState +namespace ThreeState + +lemma hasMean_bounded {α : Type*} (p : PMF α) {f : α → ℝ} (C : ℝ) + (hf : ∀ a, |f a| ≤ C) : HasMean p f := + HasMean.of_abs ((hasMean_const p C).mono (fun value => abs_nonneg (f value)) hf) + +lemma abs_mean_le {α : Type*} (p : PMF α) {f : α → ℝ} (C : ℝ) + (hf : ∀ a, |f a| ≤ C) : |mean p f| ≤ C := by + have hi := hasMean_bounded p C hf + rw [abs_le] + constructor + · simpa only [mean_const] using mean_le (hasMean_const p (-C)) hi (fun a => (abs_le.mp (hf a)).1) + · simpa only [mean_const] using mean_le hi (hasMean_const p C) (fun a => (abs_le.mp (hf a)).2) + +lemma mean_bind_bounded {α β : Type*} (p : PMF α) (k : α → PMF β) (f : β → ℝ) + (C : ℝ) (hf : ∀ b, |f b| ≤ C) : + mean (p.bind k) f = mean p (fun a => mean (k a) f) := by + apply mean_bind (fun a => hasMean_bounded (k a) C hf) + exact hasMean_bounded p C (fun a => abs_mean_le (k a) C (fun b => by simpa using hf b)) + +lemma mean_map_bounded {α β : Type*} (p : PMF α) (g : α → β) (f : β → ℝ) + (C : ℝ) (hf : ∀ a, |f (g a)| ≤ C) : + mean (p.map g) f = mean p (fun a => f (g a)) := + mean_map (hasMean_bounded p C hf) + + +noncomputable def joint {α β : Type*} (p : PMF α) (k : α → PMF β) : PMF (α × β) := + p.bind (fun a => (k a).map (fun b => (a,b))) + +lemma mean_joint_bounded {α β : Type*} (p : PMF α) (k : α → PMF β) (f : α × β → ℝ) + (C : ℝ) (hf : ∀ ab, |f ab| ≤ C) : + mean (joint p k) f = mean p (fun a => mean (k a) (fun b => f (a,b))) := by + rw [joint, mean_bind_bounded p _ f C hf] + apply mean_congr + intro a + exact mean_map_bounded (k a) _ f C (fun b => hf (a,b)) + +lemma mean_joint_fst {α β : Type*} (p : PMF α) (k : α → PMF β) (f : α → ℝ) + (C : ℝ) (hf : ∀ a, |f a| ≤ C) : + mean (joint p k) (fun ab => f ab.1) = mean p f := by + rw [mean_joint_bounded p k _ C (fun ab => hf ab.1)] + simp only [mean_const] + +lemma mean_joint_snd {α β : Type*} (p : PMF α) (k : α → PMF β) (f : β → ℝ) + (C : ℝ) (hf : ∀ b, |f b| ≤ C) : + mean (joint p k) (fun ab => f ab.2) = mean (p.bind k) f := by + rw [mean_joint_bounded p k _ C (fun ab => hf ab.2), mean_bind_bounded p k f C hf] + +end ThreeState + +namespace ThreeState + +lemma HasMean.sub {α : Type*} {p : PMF α} {f g : α → ℝ} + (hf : HasMean p f) (hg : HasMean p g) : HasMean p (fun a => f a-g a) := by + simpa only [HasMean, mul_sub] using Summable.sub hf hg + +lemma mean_sub {α : Type*} {p : PMF α} {f g : α → ℝ} + (hf : HasMean p f) (hg : HasMean p g) : + mean p (fun a => f a-g a) = mean p f-mean p g := by + simp only [mean, mul_sub, hf.tsum_sub hg] + +lemma poisson_mass (d : ℝ) (hd : 0 ≤ d) (k : ℕ) : + mass (poissonOffspring d hd) k = Real.exp (-d)*d^k/(k.factorial : ℝ) := by + change (ENNReal.ofReal _).toReal = _ + apply ENNReal.toReal_ofReal + positivity + +lemma poisson_mass_succ (d : ℝ) (hd : 0 ≤ d) (k : ℕ) : + mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ) = + d*mass (poissonOffspring d hd) k := by + rw [poisson_mass, poisson_mass, Nat.factorial_succ, Nat.cast_mul, pow_succ] + have hk : ((k+1 : ℕ) : ℝ) ≠ 0 := by positivity + have hf : (k.factorial : ℝ) ≠ 0 := by positivity + field_simp + +lemma poisson_first_hasSum (d : ℝ) (hd : 0 ≤ d) : + HasSum (fun k : ℕ => mass (poissonOffspring d hd) k * (k : ℝ)) d := by + have h : HasSum (fun k : ℕ => mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) d := by + simpa only [poisson_mass_succ, mass_sum, mul_one] using + (mass_summable (poissonOffspring d hd)).hasSum.mul_left d + have hz : mass (poissonOffspring d hd) 0*(0:ℝ) = 0 := mul_zero _ + exact (hasSum_nat_add_iff' 1).mp (by simpa [hz, mass_sum] using h) + +lemma poisson_second_factorial_hasSum (d : ℝ) (hd : 0 ≤ d) : + HasSum (fun k : ℕ => mass (poissonOffspring d hd) k * ((k : ℝ)*((k : ℝ)-1))) (d^2) := by + have hh (k : ℕ) : + mass (poissonOffspring d hd) (k+2) * (((k+2 : ℕ) : ℝ)*(((k+2 : ℕ) : ℝ)-1)) = + d*(mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) := by + have he := poisson_mass_succ d hd (k+1) + push_cast at he ⊢ + nlinarith [congrArg (fun x => x*((k:ℝ)+1)) he] + have h : HasSum (fun k : ℕ => + mass (poissonOffspring d hd) (k+2) * (((k+2 : ℕ) : ℝ)*(((k+2 : ℕ) : ℝ)-1))) (d^2) := by + have h1 : HasSum (fun k : ℕ => mass (poissonOffspring d hd) (k+1) * ((k+1 : ℕ) : ℝ)) d := by + simpa only [poisson_mass_succ, mass_sum, mul_one] using + (mass_summable (poissonOffspring d hd)).hasSum.mul_left d + simpa only [hh, pow_two] using h1.mul_left d + exact (hasSum_nat_add_iff' 2).mp (by simpa [Finset.sum_range_succ] using h) + + +theorem poisson_moments (d : ℝ) (hd : 0 ≤ d) : + Moments (poissonOffspring d hd) (fun k : ℕ => (k : ℝ)) d (d^2+d) := by + have h1 := poisson_first_hasSum d hd + have h2 := poisson_second_factorial_hasSum d hd + have hs : HasSum (fun k : ℕ => mass (poissonOffspring d hd) k*(k:ℝ)^2) (d^2+d) := by + convert h2.add h1 using 1 + funext k + ring + exact ⟨hs.summable, h1.tsum_eq, hs.tsum_eq⟩ + +lemma regular_moments (b : ℕ) : + Moments (PMF.pure b) (fun k : ℕ => (k : ℝ)) (b:ℝ) ((b:ℝ)^2) := + Moments.pure b _ + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/FixedPoints.lean b/lean/OAI/Probability/ThreeState/FixedPoints.lean index c59636a8655ef94dea7134f88f54e2b8179a4e66..c2e1671ba202351d807fefd702acff05535127b9 100644 --- a/lean/OAI/Probability/ThreeState/FixedPoints.lean +++ b/lean/OAI/Probability/ThreeState/FixedPoints.lean @@ -1,290 +1,290 @@ -import Mathlib -import OAI.Probability.ThreeState.Update - -namespace OAI - -/-! Continuity of posterior updates and fixed points of the likelihood law. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma continuous_productWeight (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : - Continuous (fun m : Fin n → Message => productWeight lam h m i) := by - apply continuous_finsetProd - intro j _ - exact (continuous_apply i).comp - (continuous_subtype_val.comp ((continuous_edgeMessage lam h).comp (continuous_apply j))) - -lemma continuous_normalizer (lam : ℝ) (h : Admissible lam) (n : ℕ) : - Continuous (fun m : Fin n → Message => normalizer lam h m) := - (continuous_finsetSum _ (fun i _ => continuous_productWeight lam h n i)).div_const 3 - -lemma continuousAt_combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} - (m : Fin n → Message) (hm : normalizer lam h m ≠ 0) : - ContinuousAt (combineMessage lam h) m := by - apply tendsto_subtype_rng.mpr - apply tendsto_pi_nhds.mpr - intro i - have hn : ContinuousAt (fun v : Fin n → Message => normalizer lam h v) m := - (continuous_normalizer lam h n).continuousAt - have hw : ContinuousAt (fun v : Fin n → Message => productWeight lam h v i) m := - (continuous_productWeight lam h n i).continuousAt - have ht := hw.div hn hm - have he : ∀ᶠ v in 𝓝 m, normalizer lam h v ≠ 0 := hn.eventually (eventually_ne_nhds hm) - have heq : (fun v => productWeight lam h v i / normalizer lam h v) =ᶠ[𝓝 m] - (fun v => combineMessage lam h v i) := by - filter_upwards [he] with v hv - simp only [combineMessage, dite_eq_right hv] - have hp : productWeight lam h m i / normalizer lam h m = combineMessage lam h m i := by - simp only [combineMessage, dite_eq_right hm] - change Tendsto _ (𝓝 m) (𝓝 (productWeight lam h m i / normalizer lam h m)) at ht - rw [hp] at ht - exact ht.congr' heq - - -noncomputable def weightedTest (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) (m : Fin n → Message) : ℝ := - normalizer lam h m * f (combineMessage lam h m) - -lemma weightedTest_bound (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) (C : ℝ) (hC : ∀ m, |f m| ≤ C) (m : Fin n → Message) : - |weightedTest lam h n f m| ≤ C * normalizer lam h m := by - dsimp only [weightedTest] - rw [abs_mul, abs_of_nonneg (normalizer_nonneg _ _ _), mul_comm C] - exact mul_le_mul_of_nonneg_left (hC _) (normalizer_nonneg _ _ _) - -lemma continuous_weightedTest (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) : Continuous (weightedTest lam h n f) := by - apply continuous_iff_continuousAt.mpr - intro m - by_cases hm : normalizer lam h m = 0 - · obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - have hh : ∀ v, |weightedTest lam h n f v| ≤ C * normalizer lam h v := - weightedTest_bound lam h n f C (fun v => by simpa only [Real.norm_eq_abs] using hC v (Set.mem_univ _)) - have ht : Tendsto (fun v : Fin n → Message => C * normalizer lam h v) (𝓝 m) (𝓝 0) := by - simpa only [hm, mul_zero] using - (tendsto_const_nhds.mul (continuous_normalizer lam h n).continuousAt : - Tendsto (fun v => C * normalizer lam h v) (𝓝 m) (𝓝 (C*normalizer lam h m))) - have hz : weightedTest lam h n f m = 0 := by simp [weightedTest, hm] - rw [ContinuousAt, hz] - exact squeeze_zero_norm (fun v => by simpa only [Real.norm_eq_abs] using hh v) ht - · exact (continuous_normalizer lam h n).continuousAt.mul - (f.continuous.continuousAt.comp (continuousAt_combineMessage lam h m hm)) - -noncomputable def weightedTestMap (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) : C((Fin n → Message),ℝ) := - ⟨weightedTest lam h n f, continuous_weightedTest lam h n f⟩ - -noncomputable def degreeTest (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) (Q : ProbabilityMeasure Message) : ℝ := - ∫ m, weightedTest lam h n f m ∂(iidMeasure Q n : Measure (Fin n → Message)) - -lemma continuous_degreeTest (lam : ℝ) (h : Admissible lam) (n : ℕ) - (f : C(Message,ℝ)) : Continuous (degreeTest lam h n f) := - (ProbabilityMeasure.continuous_integral_continuousMap (weightedTestMap lam h n f)).comp - (continuous_iidMeasure n) - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma mean_sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) - (f : Sigma α → ℝ) (hf : HasMean (sigmaPMF p q) f) : - mean (sigmaPMF p q) f = mean p (fun i => mean (q i) (fun a => f ⟨i,a⟩)) := by - change (∑' x, mass (sigmaPMF p q) x * f x) = _ - rw [hf.tsum_sigma] - unfold mean - apply tsum_congr - intro i - simp only [mass_sigmaPMF, mul_assoc, tsum_mul_left] - -lemma degreeTest_likelihood {α : Type*} (law : Spin → PMF α) (lam : ℝ) - (h : Admissible lam) (n : ℕ) (f : C(Message,ℝ)) : - degreeTest lam h n f (likelihoodLaw law) = - mean (iidVector (marginal law) n) (fun v => - normalizer lam h (fun j => likelihood law (v j)) * - f (combineMessage lam h (fun j => likelihood law (v j)))) := - integral_iid_likelihood law n (weightedTestMap lam h n f) - - - -lemma test_compose_identity {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (f : C(Message,ℝ)) : - ∫ m, f m ∂(likelihoodLaw (composeLaw offspring law lam h) : Measure Message) = - mean offspring (fun n => degreeTest lam h n f (likelihoodLaw law)) := by - rw [integral_likelihoodLaw, mean_test_compose] - obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - have hi := hasMean_weighted_compose offspring law lam h f C - (fun m => by simpa only [Real.norm_eq_abs] using hC m (Set.mem_univ _)) - rw [productReference, mean_sigmaPMF _ _ _ hi] - apply mean_congr - intro n - exact (degreeTest_likelihood law lam h n f).symm - -noncomputable def coordinateMap (i : Spin) : C(Message,ℝ) := - ⟨fun m => m i, (continuous_apply i).comp continuous_subtype_val⟩ - - -def Balanced (Q : ProbabilityMeasure Message) : Prop := - ∀ i : Spin, ∫ m, m i ∂(Q : Measure Message) = 1 - -lemma balanced_likelihoodLaw {α : Type*} (law : Spin → PMF α) : Balanced (likelihoodLaw law) := by - intro i - change (∫ m, coordinateMap i m ∂(likelihoodLaw law : Measure Message)) = 1 - rw [integral_likelihoodLaw] - exact mean_likelihood law i - -lemma balanced_limit {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} - (hn : ∀ n, Balanced (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : Balanced Q := by - intro i - have hh := ((ProbabilityMeasure.continuous_integral_continuousMap (coordinateMap i)).tendsto Q).comp hlim - have he : (fun n => ∫ m, coordinateMap i m ∂(Qn n : Measure Message)) = (fun _ : ℕ => (1:ℝ)) := - funext (fun n => hn n i) - simp only [Function.comp_def, he] at hh - exact tendsto_nhds_unique hh tendsto_const_nhds - -lemma integral_edgeMessage (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (i : Spin) : ∫ m, edgeMessage lam h m i ∂(Q : Measure Message) = 1 := by - have hi : Integrable (fun m : Message => m i) (Q : Measure Message) := - (coordinateMap i).continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - change (∫ m, 1+lam*(m i-1) ∂(Q : Measure Message)) = 1 - have hs : Integrable (fun m : Message => m i-1) (Q : Measure Message) := - hi.sub (integrable_const (1:ℝ)) - have ht : Integrable (fun m : Message => lam*(m i-1)) (Q : Measure Message) := hs.const_mul lam - rw [integral_add (integrable_const (1:ℝ)) ht, integral_const_mul, - integral_sub hi (integrable_const (1:ℝ)), integral_const, hQ i] - simp - -lemma integral_productWeight (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) (i : Spin) : - ∫ m, productWeight lam h m i ∂(iidMeasure Q n : Measure (Fin n → Message)) = 1 := by - change (∫ m : Fin n → Message, ∏ j, edgeMessage lam h (m j) i - ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = 1 - rw [integral_fintype_prod_eq_prod (fun (_ : Fin n) (m : Message) => edgeMessage lam h m i)] - simp [integral_edgeMessage lam h Q hQ i] - -lemma integral_normalizer (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) : - ∫ m, normalizer lam h m ∂(iidMeasure Q n : Measure (Fin n → Message)) = 1 := by - change (∫ m, (∑ i, productWeight lam h m i)/3 ∂(iidMeasure Q n : Measure (Fin n → Message))) = 1 - rw [integral_div, integral_finsetSum] - · simp [integral_productWeight lam h Q hQ n] - · intro i _ - exact (continuous_productWeight lam h n i).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - -lemma degreeTest_bound (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) (f : C(Message,ℝ)) (C : ℝ) (hC : ∀ m, |f m| ≤ C) : - |degreeTest lam h n f Q| ≤ C := by - have hi : Integrable (fun m : Fin n → Message => |weightedTest lam h n f m|) - (iidMeasure Q n : Measure (Fin n → Message)) := - (continuous_weightedTest lam h n f).abs.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hj : Integrable (fun m : Fin n → Message => C*normalizer lam h m) - (iidMeasure Q n : Measure (Fin n → Message)) := - (continuous_const.mul (continuous_normalizer lam h n)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - calc - |degreeTest lam h n f Q| ≤ ∫ m, |weightedTest lam h n f m| ∂(iidMeasure Q n : Measure (Fin n → Message)) := - abs_integral_le_integral_abs - _ ≤ ∫ m, C*normalizer lam h m ∂(iidMeasure Q n : Measure (Fin n → Message)) := - integral_mono hi hj (weightedTest_bound lam h n f C hC) - _ = C := by rw [integral_const_mul, integral_normalizer lam h Q hQ n, mul_one] - -lemma mean_degreeTest_tendsto (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (f : C(Message,ℝ)) {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} - (hn : ∀ n, Balanced (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : - Tendsto (fun k => mean offspring (fun n => degreeTest lam h n f (Qn k))) atTop - (𝓝 (mean offspring (fun n => degreeTest lam h n f Q))) := by - obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - apply tendsto_tsum_of_dominated_convergence ((mass_summable offspring).mul_right C) - · intro n - exact tendsto_const_nhds.mul (((continuous_degreeTest lam h n f).tendsto Q).comp hlim) - · apply Eventually.of_forall - intro k n - rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg offspring n)] - exact mul_le_mul_of_nonneg_left (degreeTest_bound lam h (Qn k) (hn k) n f C - (fun m => by simpa only [Real.norm_eq_abs] using hC m (Set.mem_univ _))) (mass_nonneg offspring n) - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - - -def IsPosteriorFixedPoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) : Prop := - Balanced Q ∧ ∀ f : C(Message,ℝ), ∫ m, f m ∂(Q : Measure Message) = - mean offspring (fun n => degreeTest lam h n f Q) - -lemma orderedLaw_succ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : - orderedLaw offspring lam h (n+1) = composeLaw offspring (orderedLaw offspring lam h n) lam h := rfl - -lemma ordered_exists_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - ∃ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q ∧ - ∃ φ : ℕ → ℕ, StrictMono φ ∧ - Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) atTop (𝓝 Q) := by - obtain ⟨Q,φ,hφ,hleft,hright⟩ := ordered_likelihood_common_subsequence offspring lam h - refine ⟨Q, ⟨balanced_limit (fun n => balanced_likelihoodLaw _) hleft, ?_⟩,φ,hφ,hleft⟩ - intro f - have hl := ((ProbabilityMeasure.continuous_integral_continuousMap f).tendsto Q).comp hright - have hr := mean_degreeTest_tendsto offspring lam h f - (fun n => balanced_likelihoodLaw (orderedLaw offspring lam h (φ n))) hleft - have he : (fun n => ∫ m, f m ∂(likelihoodLaw (orderedLaw offspring lam h (φ n+1)) : Measure Message)) = - (fun n => mean offspring (fun k => degreeTest lam h k f (likelihoodLaw (orderedLaw offspring lam h (φ n))))) := by - funext n - rw [orderedLaw_succ, test_compose_identity] - simp only [Function.comp_def, he] at hl - exact tendsto_nhds_unique hl hr - -noncomputable def messageTV (m : Message) : ℝ := (∑ i : Spin, |m i-1|)/6 - -lemma continuous_messageTV : Continuous messageTV := by - apply Continuous.div_const - apply continuous_finsetSum - intro i _ - exact (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).abs - -noncomputable def messageTVMap : C(Message,ℝ) := ⟨messageTV, continuous_messageTV⟩ - -lemma posterior_tv_likelihood {α : Type*} (law : Spin → PMF α) (y : α) : - (∑ i : Spin, |posterior law y i - 1/3|)/2 = messageTV (likelihood law y) := by - have he (i : Spin) : |likelihood law y i - 1| = 3 * |posterior law y i - 1/3| := by - rw [likelihood_apply] - have hr : 3*posterior law y i-1 = 3*(posterior law y i-1/3) := by ring - rw [hr, abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 3)] - simp only [messageTV, he, ← Finset.mul_sum] - ring - -lemma integral_messageTV_likelihood {α : Type*} (law : Spin → PMF α) : - ∫ m, messageTV m ∂(likelihoodLaw law : Measure Message) = advantage law := by - change (∫ m, messageTVMap m ∂(likelihoodLaw law : Measure Message)) = _ - rw [integral_likelihoodLaw] - unfold mean advantage - apply tsum_congr - intro y - rw [posterior_tv_likelihood] - rfl - -lemma advantage_tendsto_of_likelihood {α : ℕ → Type*} (law : ∀ n, Spin → PMF (α n)) - {Q : ProbabilityMeasure Message} (hlim : Tendsto (fun n => likelihoodLaw (law n)) atTop (𝓝 Q)) : - Tendsto (fun n => advantage (law n)) atTop (𝓝 (∫ m, messageTV m ∂(Q : Measure Message))) := by - have hh := ((ProbabilityMeasure.continuous_integral_continuousMap messageTVMap).tendsto Q).comp hlim - simpa only [Function.comp_def, messageTVMap, ContinuousMap.coe_mk, integral_messageTV_likelihood] using hh - - - -lemma exists_fixedpoint_advantage (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - ∃ L : ℝ, ∃ Q : ProbabilityMeasure Message, - 0 ≤ L ∧ Tendsto (fun n => advantage (observedLaw offspring lam h n)) atTop (𝓝 L) ∧ - IsPosteriorFixedPoint offspring lam h Q ∧ - L ≤ ∫ m, messageTV m ∂(Q : Measure Message) := by - obtain ⟨Q,hQ,φ,hφ,hlim⟩ := ordered_exists_fixedpoint offspring lam h - have htop := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim - obtain ⟨L,hL,_hL1,hactual⟩ := observedAdvantage_tendsto offspring lam h - refine ⟨L,Q,hL,hactual,hQ,?_⟩ - exact le_of_tendsto_of_tendsto (hactual.comp hφ.tendsto_atTop) htop - (Eventually.of_forall (fun n => orderedAdvantage_dominates offspring lam h (φ n))) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Update + +namespace OAI + +/-! Continuity of posterior updates and fixed points of the likelihood law. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma continuous_productWeight (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : + Continuous (fun m : Fin n → Message => productWeight lam h m i) := by + apply continuous_finsetProd + intro j _ + exact (continuous_apply i).comp + (continuous_subtype_val.comp ((continuous_edgeMessage lam h).comp (continuous_apply j))) + +lemma continuous_normalizer (lam : ℝ) (h : Admissible lam) (n : ℕ) : + Continuous (fun m : Fin n → Message => normalizer lam h m) := + (continuous_finsetSum _ (fun i _ => continuous_productWeight lam h n i)).div_const 3 + +lemma continuousAt_combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} + (m : Fin n → Message) (hm : normalizer lam h m ≠ 0) : + ContinuousAt (combineMessage lam h) m := by + apply tendsto_subtype_rng.mpr + apply tendsto_pi_nhds.mpr + intro i + have hn : ContinuousAt (fun v : Fin n → Message => normalizer lam h v) m := + (continuous_normalizer lam h n).continuousAt + have hw : ContinuousAt (fun v : Fin n → Message => productWeight lam h v i) m := + (continuous_productWeight lam h n i).continuousAt + have ht := hw.div hn hm + have he : ∀ᶠ v in 𝓝 m, normalizer lam h v ≠ 0 := hn.eventually (eventually_ne_nhds hm) + have heq : (fun v => productWeight lam h v i / normalizer lam h v) =ᶠ[𝓝 m] + (fun v => combineMessage lam h v i) := by + filter_upwards [he] with v hv + simp only [combineMessage, dite_eq_right hv] + have hp : productWeight lam h m i / normalizer lam h m = combineMessage lam h m i := by + simp only [combineMessage, dite_eq_right hm] + change Tendsto _ (𝓝 m) (𝓝 (productWeight lam h m i / normalizer lam h m)) at ht + rw [hp] at ht + exact ht.congr' heq + + +noncomputable def weightedTest (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) (m : Fin n → Message) : ℝ := + normalizer lam h m * f (combineMessage lam h m) + +lemma weightedTest_bound (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) (C : ℝ) (hC : ∀ m, |f m| ≤ C) (m : Fin n → Message) : + |weightedTest lam h n f m| ≤ C * normalizer lam h m := by + dsimp only [weightedTest] + rw [abs_mul, abs_of_nonneg (normalizer_nonneg _ _ _), mul_comm C] + exact mul_le_mul_of_nonneg_left (hC _) (normalizer_nonneg _ _ _) + +lemma continuous_weightedTest (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) : Continuous (weightedTest lam h n f) := by + apply continuous_iff_continuousAt.mpr + intro m + by_cases hm : normalizer lam h m = 0 + · obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + have hh : ∀ v, |weightedTest lam h n f v| ≤ C * normalizer lam h v := + weightedTest_bound lam h n f C (fun v => by simpa only [Real.norm_eq_abs] using hC v (Set.mem_univ _)) + have ht : Tendsto (fun v : Fin n → Message => C * normalizer lam h v) (𝓝 m) (𝓝 0) := by + simpa only [hm, mul_zero] using + (tendsto_const_nhds.mul (continuous_normalizer lam h n).continuousAt : + Tendsto (fun v => C * normalizer lam h v) (𝓝 m) (𝓝 (C*normalizer lam h m))) + have hz : weightedTest lam h n f m = 0 := by simp [weightedTest, hm] + rw [ContinuousAt, hz] + exact squeeze_zero_norm (fun v => by simpa only [Real.norm_eq_abs] using hh v) ht + · exact (continuous_normalizer lam h n).continuousAt.mul + (f.continuous.continuousAt.comp (continuousAt_combineMessage lam h m hm)) + +noncomputable def weightedTestMap (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) : C((Fin n → Message),ℝ) := + ⟨weightedTest lam h n f, continuous_weightedTest lam h n f⟩ + +noncomputable def degreeTest (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) (Q : ProbabilityMeasure Message) : ℝ := + ∫ m, weightedTest lam h n f m ∂(iidMeasure Q n : Measure (Fin n → Message)) + +lemma continuous_degreeTest (lam : ℝ) (h : Admissible lam) (n : ℕ) + (f : C(Message,ℝ)) : Continuous (degreeTest lam h n f) := + (ProbabilityMeasure.continuous_integral_continuousMap (weightedTestMap lam h n f)).comp + (continuous_iidMeasure n) + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma mean_sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) + (f : Sigma α → ℝ) (hf : HasMean (sigmaPMF p q) f) : + mean (sigmaPMF p q) f = mean p (fun i => mean (q i) (fun a => f ⟨i,a⟩)) := by + change (∑' x, mass (sigmaPMF p q) x * f x) = _ + rw [hf.tsum_sigma] + unfold mean + apply tsum_congr + intro i + simp only [mass_sigmaPMF, mul_assoc, tsum_mul_left] + +lemma degreeTest_likelihood {α : Type*} (law : Spin → PMF α) (lam : ℝ) + (h : Admissible lam) (n : ℕ) (f : C(Message,ℝ)) : + degreeTest lam h n f (likelihoodLaw law) = + mean (iidVector (marginal law) n) (fun v => + normalizer lam h (fun j => likelihood law (v j)) * + f (combineMessage lam h (fun j => likelihood law (v j)))) := + integral_iid_likelihood law n (weightedTestMap lam h n f) + + + +lemma test_compose_identity {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (f : C(Message,ℝ)) : + ∫ m, f m ∂(likelihoodLaw (composeLaw offspring law lam h) : Measure Message) = + mean offspring (fun n => degreeTest lam h n f (likelihoodLaw law)) := by + rw [integral_likelihoodLaw, mean_test_compose] + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + have hi := hasMean_weighted_compose offspring law lam h f C + (fun m => by simpa only [Real.norm_eq_abs] using hC m (Set.mem_univ _)) + rw [productReference, mean_sigmaPMF _ _ _ hi] + apply mean_congr + intro n + exact (degreeTest_likelihood law lam h n f).symm + +noncomputable def coordinateMap (i : Spin) : C(Message,ℝ) := + ⟨fun m => m i, (continuous_apply i).comp continuous_subtype_val⟩ + + +def Balanced (Q : ProbabilityMeasure Message) : Prop := + ∀ i : Spin, ∫ m, m i ∂(Q : Measure Message) = 1 + +lemma balanced_likelihoodLaw {α : Type*} (law : Spin → PMF α) : Balanced (likelihoodLaw law) := by + intro i + change (∫ m, coordinateMap i m ∂(likelihoodLaw law : Measure Message)) = 1 + rw [integral_likelihoodLaw] + exact mean_likelihood law i + +lemma balanced_limit {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} + (hn : ∀ n, Balanced (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : Balanced Q := by + intro i + have hh := ((ProbabilityMeasure.continuous_integral_continuousMap (coordinateMap i)).tendsto Q).comp hlim + have he : (fun n => ∫ m, coordinateMap i m ∂(Qn n : Measure Message)) = (fun _ : ℕ => (1:ℝ)) := + funext (fun n => hn n i) + simp only [Function.comp_def, he] at hh + exact tendsto_nhds_unique hh tendsto_const_nhds + +lemma integral_edgeMessage (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (i : Spin) : ∫ m, edgeMessage lam h m i ∂(Q : Measure Message) = 1 := by + have hi : Integrable (fun m : Message => m i) (Q : Measure Message) := + (coordinateMap i).continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + change (∫ m, 1+lam*(m i-1) ∂(Q : Measure Message)) = 1 + have hs : Integrable (fun m : Message => m i-1) (Q : Measure Message) := + hi.sub (integrable_const (1:ℝ)) + have ht : Integrable (fun m : Message => lam*(m i-1)) (Q : Measure Message) := hs.const_mul lam + rw [integral_add (integrable_const (1:ℝ)) ht, integral_const_mul, + integral_sub hi (integrable_const (1:ℝ)), integral_const, hQ i] + simp + +lemma integral_productWeight (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) (i : Spin) : + ∫ m, productWeight lam h m i ∂(iidMeasure Q n : Measure (Fin n → Message)) = 1 := by + change (∫ m : Fin n → Message, ∏ j, edgeMessage lam h (m j) i + ∂Measure.pi (fun _ : Fin n => (Q : Measure Message))) = 1 + rw [integral_fintype_prod_eq_prod (fun (_ : Fin n) (m : Message) => edgeMessage lam h m i)] + simp [integral_edgeMessage lam h Q hQ i] + +lemma integral_normalizer (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) : + ∫ m, normalizer lam h m ∂(iidMeasure Q n : Measure (Fin n → Message)) = 1 := by + change (∫ m, (∑ i, productWeight lam h m i)/3 ∂(iidMeasure Q n : Measure (Fin n → Message))) = 1 + rw [integral_div, integral_finsetSum] + · simp [integral_productWeight lam h Q hQ n] + · intro i _ + exact (continuous_productWeight lam h n i).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + +lemma degreeTest_bound (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) (f : C(Message,ℝ)) (C : ℝ) (hC : ∀ m, |f m| ≤ C) : + |degreeTest lam h n f Q| ≤ C := by + have hi : Integrable (fun m : Fin n → Message => |weightedTest lam h n f m|) + (iidMeasure Q n : Measure (Fin n → Message)) := + (continuous_weightedTest lam h n f).abs.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hj : Integrable (fun m : Fin n → Message => C*normalizer lam h m) + (iidMeasure Q n : Measure (Fin n → Message)) := + (continuous_const.mul (continuous_normalizer lam h n)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + calc + |degreeTest lam h n f Q| ≤ ∫ m, |weightedTest lam h n f m| ∂(iidMeasure Q n : Measure (Fin n → Message)) := + abs_integral_le_integral_abs + _ ≤ ∫ m, C*normalizer lam h m ∂(iidMeasure Q n : Measure (Fin n → Message)) := + integral_mono hi hj (weightedTest_bound lam h n f C hC) + _ = C := by rw [integral_const_mul, integral_normalizer lam h Q hQ n, mul_one] + +lemma mean_degreeTest_tendsto (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (f : C(Message,ℝ)) {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} + (hn : ∀ n, Balanced (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : + Tendsto (fun k => mean offspring (fun n => degreeTest lam h n f (Qn k))) atTop + (𝓝 (mean offspring (fun n => degreeTest lam h n f Q))) := by + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + apply tendsto_tsum_of_dominated_convergence ((mass_summable offspring).mul_right C) + · intro n + exact tendsto_const_nhds.mul (((continuous_degreeTest lam h n f).tendsto Q).comp hlim) + · apply Eventually.of_forall + intro k n + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (mass_nonneg offspring n)] + exact mul_le_mul_of_nonneg_left (degreeTest_bound lam h (Qn k) (hn k) n f C + (fun m => by simpa only [Real.norm_eq_abs] using hC m (Set.mem_univ _))) (mass_nonneg offspring n) + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + + +def IsPosteriorFixedPoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) : Prop := + Balanced Q ∧ ∀ f : C(Message,ℝ), ∫ m, f m ∂(Q : Measure Message) = + mean offspring (fun n => degreeTest lam h n f Q) + +lemma orderedLaw_succ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : + orderedLaw offspring lam h (n+1) = composeLaw offspring (orderedLaw offspring lam h n) lam h := rfl + +lemma ordered_exists_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + ∃ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q ∧ + ∃ φ : ℕ → ℕ, StrictMono φ ∧ + Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) atTop (𝓝 Q) := by + obtain ⟨Q,φ,hφ,hleft,hright⟩ := ordered_likelihood_common_subsequence offspring lam h + refine ⟨Q, ⟨balanced_limit (fun n => balanced_likelihoodLaw _) hleft, ?_⟩,φ,hφ,hleft⟩ + intro f + have hl := ((ProbabilityMeasure.continuous_integral_continuousMap f).tendsto Q).comp hright + have hr := mean_degreeTest_tendsto offspring lam h f + (fun n => balanced_likelihoodLaw (orderedLaw offspring lam h (φ n))) hleft + have he : (fun n => ∫ m, f m ∂(likelihoodLaw (orderedLaw offspring lam h (φ n+1)) : Measure Message)) = + (fun n => mean offspring (fun k => degreeTest lam h k f (likelihoodLaw (orderedLaw offspring lam h (φ n))))) := by + funext n + rw [orderedLaw_succ, test_compose_identity] + simp only [Function.comp_def, he] at hl + exact tendsto_nhds_unique hl hr + +noncomputable def messageTV (m : Message) : ℝ := (∑ i : Spin, |m i-1|)/6 + +lemma continuous_messageTV : Continuous messageTV := by + apply Continuous.div_const + apply continuous_finsetSum + intro i _ + exact (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).abs + +noncomputable def messageTVMap : C(Message,ℝ) := ⟨messageTV, continuous_messageTV⟩ + +lemma posterior_tv_likelihood {α : Type*} (law : Spin → PMF α) (y : α) : + (∑ i : Spin, |posterior law y i - 1/3|)/2 = messageTV (likelihood law y) := by + have he (i : Spin) : |likelihood law y i - 1| = 3 * |posterior law y i - 1/3| := by + rw [likelihood_apply] + have hr : 3*posterior law y i-1 = 3*(posterior law y i-1/3) := by ring + rw [hr, abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 3)] + simp only [messageTV, he, ← Finset.mul_sum] + ring + +lemma integral_messageTV_likelihood {α : Type*} (law : Spin → PMF α) : + ∫ m, messageTV m ∂(likelihoodLaw law : Measure Message) = advantage law := by + change (∫ m, messageTVMap m ∂(likelihoodLaw law : Measure Message)) = _ + rw [integral_likelihoodLaw] + unfold mean advantage + apply tsum_congr + intro y + rw [posterior_tv_likelihood] + rfl + +lemma advantage_tendsto_of_likelihood {α : ℕ → Type*} (law : ∀ n, Spin → PMF (α n)) + {Q : ProbabilityMeasure Message} (hlim : Tendsto (fun n => likelihoodLaw (law n)) atTop (𝓝 Q)) : + Tendsto (fun n => advantage (law n)) atTop (𝓝 (∫ m, messageTV m ∂(Q : Measure Message))) := by + have hh := ((ProbabilityMeasure.continuous_integral_continuousMap messageTVMap).tendsto Q).comp hlim + simpa only [Function.comp_def, messageTVMap, ContinuousMap.coe_mk, integral_messageTV_likelihood] using hh + + + +lemma exists_fixedpoint_advantage (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + ∃ L : ℝ, ∃ Q : ProbabilityMeasure Message, + 0 ≤ L ∧ Tendsto (fun n => advantage (observedLaw offspring lam h n)) atTop (𝓝 L) ∧ + IsPosteriorFixedPoint offspring lam h Q ∧ + L ≤ ∫ m, messageTV m ∂(Q : Measure Message) := by + obtain ⟨Q,hQ,φ,hφ,hlim⟩ := ordered_exists_fixedpoint offspring lam h + have htop := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim + obtain ⟨L,hL,_hL1,hactual⟩ := observedAdvantage_tendsto offspring lam h + refine ⟨L,Q,hL,hactual,hQ,?_⟩ + exact le_of_tendsto_of_tendsto (hactual.comp hφ.tendsto_atTop) htop + (Eventually.of_forall (fun n => orderedAdvantage_dominates offspring lam h (φ n))) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Main.lean b/lean/OAI/Probability/ThreeState/Main.lean index cbf89478d95464b86817e4fc4edf2f53b04a9a73..fcdfb5f0cacb148882249426c169b38b92729ac7 100644 --- a/lean/OAI/Probability/ThreeState/Main.lean +++ b/lean/OAI/Probability/ThreeState/Main.lean @@ -1 +1 @@ -import OAI.Probability.ThreeState.Region +import OAI.Probability.ThreeState.Region diff --git a/lean/OAI/Probability/ThreeState/Messages.lean b/lean/OAI/Probability/ThreeState/Messages.lean index b2ca98973567af21f954e780c513eabf75c32644..c0af0fc3841f1a7b562187e850713bec8aee3957 100644 --- a/lean/OAI/Probability/ThreeState/Messages.lean +++ b/lean/OAI/Probability/ThreeState/Messages.lean @@ -1,307 +1,307 @@ -import Mathlib -import OAI.Probability.ThreeState.Expectations - -namespace OAI - -/-! Likelihood messages, compact couplings and subsequential posterior limits. -/ - -namespace ThreeState -open MeasureTheory - - -abbrev Message := {m : Spin → ℝ // (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} - -instance : CoeFun Message (fun _ => Spin → ℝ) := ⟨Subtype.val⟩ - -lemma Message.nonneg (m : Message) (i : Spin) : 0 ≤ m i := m.2.1 i -lemma Message.sum (m : Message) : ∑ i, m i = 3 := m.2.2 -lemma Message.le_three (m : Message) (i : Spin) : m i ≤ 3 := by - calc - m i ≤ ∑ j, m j := Finset.single_le_sum (fun j _ => Message.nonneg m j) (Finset.mem_univ i) - _ = 3 := Message.sum m - -lemma message_isCompact : IsCompact {m : Spin → ℝ | (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} := by - have hc : IsClosed {m : Spin → ℝ | (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} := by - apply IsClosed.inter - · have he : {m : Spin → ℝ | ∀ i, 0 ≤ m i} = - ⋂ i : Spin, {m : Spin → ℝ | 0 ≤ m i} := by ext m; simp - change IsClosed {m : Spin → ℝ | ∀ i, 0 ≤ m i} - rw [he] - exact isClosed_iInter (fun i : Spin => isClosed_le (continuous_const (y := (0:ℝ))) - (continuous_apply i : Continuous (fun m : Spin → ℝ => m i))) - · exact isClosed_eq (continuous_finsetSum _ (fun i _ => continuous_apply i)) continuous_const - apply (isCompact_Icc (a := (fun _ : Spin => (0:ℝ))) (b := fun _ => (3:ℝ))).of_isClosed_subset hc - intro m hm - exact ⟨hm.1, fun i => Message.le_three ⟨m,hm⟩ i⟩ - -instance : CompactSpace Message := isCompact_iff_compactSpace.mp message_isCompact -noncomputable def uninformative : Message := ⟨fun _ => 1, by simp⟩ - - -noncomputable def likelihood {α : Type*} (law : Spin → PMF α) (y : α) : Message := - ⟨fun i => 3*posterior law y i, by - constructor - · intro i; exact mul_nonneg (by norm_num) (posterior_nonneg law y i) - · rw [← Finset.mul_sum, posterior_sum]; norm_num⟩ - -lemma likelihood_apply {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - likelihood law y i = 3*posterior law y i := rfl - -lemma weighted_likelihood {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - mass (marginal law) y * likelihood law y i = mass (law i) y := by - rw [likelihood_apply] - have hh := weighted_posterior law y i - nlinarith - -lemma hasMean_likelihood {α : Type*} (law : Spin → PMF α) (i : Spin) : - HasMean (marginal law) (fun y => likelihood law y i) := by - exact (mass_summable (law i)).congr (fun y => (weighted_likelihood law y i).symm) - -lemma mean_likelihood {α : Type*} (law : Spin → PMF α) (i : Spin) : - mean (marginal law) (fun y => likelihood law y i) = 1 := by - unfold mean - simp_rw [weighted_likelihood] - exact mass_sum _ - -noncomputable def likelihoodPMF {α : Type*} (law : Spin → PMF α) : PMF Message := - (marginal law).map (likelihood law) - -noncomputable def likelihoodLaw {α : Type*} (law : Spin → PMF α) : ProbabilityMeasure Message := - ⟨(likelihoodPMF law).toMeasure, inferInstance⟩ - -lemma mean_likelihoodPMF {α : Type*} (law : Spin → PMF α) (f : Message → ℝ) - (hf : HasMean (marginal law) (fun y => f (likelihood law y))) : - mean (likelihoodPMF law) f = mean (marginal law) (fun y => f (likelihood law y)) := - mean_map hf - -lemma integral_likelihoodLaw {α : Type*} (law : Spin → PMF α) (f : C(Message,ℝ)) : - ∫ m, f m ∂(likelihoodLaw law : Measure Message) = - mean (marginal law) (fun y => f (likelihood law y)) := by - have hf : Integrable f (likelihoodPMF law).toMeasure := f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) - change (∫ m, f m ∂(likelihoodPMF law).toMeasure) = _ - rw [PMF.integral_eq_tsum _ _ hf] - change mean (likelihoodPMF law) f = _ - apply mean_likelihoodPMF - obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - apply HasMean.of_abs - apply (hasMean_const (marginal law) C).mono (fun y => abs_nonneg _) - intro y - simpa only [Real.norm_eq_abs] using hC (likelihood law y) (Set.mem_univ _) - -end ThreeState - -namespace ThreeState -open MeasureTheory - -lemma abs_likelihood {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - |likelihood law y i| ≤ 3 := by - rw [abs_of_nonneg (Message.nonneg _ _)] - exact Message.le_three _ _ - -lemma abs_likelihood_square {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - |(likelihood law y i)^2| ≤ 9 := by - rw [abs_sq] - have h := abs_likelihood law y i - have hl := (abs_le.mp h).1 - have hu := (abs_le.mp h).2 - nlinarith - -lemma mean_likelihood_mul {α : Type*} (law : Spin → PMF α) (i : Spin) (f : α → ℝ) : - mean (marginal law) (fun y => likelihood law y i * f y) = mean (law i) f := by - unfold mean - apply tsum_congr - intro y - rw [← mul_assoc, weighted_likelihood] - - -lemma mean_joint_likelihood_mul {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) - (i : Spin) (f : β → ℝ) (C : ℝ) (hC : 0 ≤ C) (hf : ∀ b, |f b| ≤ C) : - mean (joint (marginal law) k) (fun ab => likelihood law ab.1 i * f ab.2) = - mean (marginal (fun j => (law j).bind k)) - (fun b => likelihood (fun j => (law j).bind k) b i * f b) := by - rw [mean_joint_bounded _ _ _ (3*C) (fun ab => by - rw [abs_mul] - exact (mul_le_mul_of_nonneg_left (hf _) (abs_nonneg _)).trans - (mul_le_mul_of_nonneg_right (abs_likelihood _ _ _) hC))] - simp_rw [mean_const_mul] - rw [mean_likelihood_mul, mean_likelihood_mul, mean_bind_bounded _ _ _ C hf] - -lemma mean_joint_likelihood_square {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) - (i : Spin) : - mean (joint (marginal law) k) (fun ab => - (likelihood law ab.1 i - likelihood (fun j => (law j).bind k) ab.2 i)^2) = - mean (marginal law) (fun a => (likelihood law a i)^2) - - mean (marginal (fun j => (law j).bind k)) - (fun b => (likelihood (fun j => (law j).bind k) b i)^2) := by - let p := joint (marginal law) k - let u := fun ab : α × β => likelihood law ab.1 i - let v := fun ab : α × β => likelihood (fun j => (law j).bind k) ab.2 i - have hu : ∀ ab, |u ab| ≤ 3 := fun ab => abs_likelihood _ _ _ - have hv : ∀ ab, |v ab| ≤ 3 := fun ab => abs_likelihood _ _ _ - have husq : ∀ ab, |(u ab)^2| ≤ 9 := fun ab => by - rw [abs_sq]; nlinarith [sq_le_sq₀ (abs_nonneg (u ab)) (by norm_num : (0:ℝ) ≤ 3) |>.2 (hu ab), sq_abs (u ab)] - have hvsq : ∀ ab, |(v ab)^2| ≤ 9 := fun ab => by - rw [abs_sq]; nlinarith [sq_le_sq₀ (abs_nonneg (v ab)) (by norm_num : (0:ℝ) ≤ 3) |>.2 (hv ab), sq_abs (v ab)] - have huv : ∀ ab, |u ab * v ab| ≤ 9 := fun ab => by - rw [abs_mul]; exact (mul_le_mul (hu ab) (hv ab) (abs_nonneg _) (by norm_num)).trans_eq (by norm_num) - change mean p (fun ab => (u ab-v ab)^2) = _ - rw [mean_congr p (g := fun ab => ((u ab)^2+(v ab)^2)+ (-2)*(u ab*v ab)) (fun ab => by ring), - mean_add ((hasMean_bounded p 9 husq).add (hasMean_bounded p 9 hvsq)) - ((hasMean_bounded p 9 huv).const_mul (-2)), - mean_add (hasMean_bounded p 9 husq) (hasMean_bounded p 9 hvsq), mean_const_mul] - change mean (joint (marginal law) k) (fun ab => (likelihood law ab.1 i)^2) + - mean (joint (marginal law) k) (fun ab => (likelihood (fun j => (law j).bind k) ab.2 i)^2) + - -2 * mean (joint (marginal law) k) (fun ab => likelihood law ab.1 i * likelihood (fun j => (law j).bind k) ab.2 i) = _ - rw [mean_joint_fst (marginal law) k (fun a => (likelihood law a i)^2) 9 - (fun a => abs_likelihood_square law a i), - mean_joint_snd (marginal law) k (fun b => (likelihood (fun j => (law j).bind k) b i)^2) 9 - (fun b => abs_likelihood_square _ b i), - mean_joint_likelihood_mul law k i (fun b => likelihood (fun j => (law j).bind k) b i) 3 - (by norm_num) (fun b => abs_likelihood (fun j => (law j).bind k) b i), - ← marginal_bind] - simp only [← sq] - ring - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology - -lemma joint_map_fst {α β : Type*} (p : PMF α) (k : α → PMF β) : - (joint p k).map Prod.fst = p := by - simp only [joint, PMF.map_bind, PMF.map_comp, Function.comp_def] - change (p.bind (fun a => (k a).map (Function.const β a))) = _ - simp only [PMF.map_const, PMF.bind_pure] - -lemma joint_map_snd {α β : Type*} (p : PMF α) (k : α → PMF β) : - (joint p k).map Prod.snd = p.bind k := by - simp only [joint, PMF.map_bind, PMF.map_comp, Function.comp_def] - change (p.bind (fun a => (k a).map id)) = _ - simp only [PMF.map_id] - -noncomputable def messageCouplingPMF {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - PMF (Message × Message) := - (joint (marginal law) k).map (fun ab => (likelihood law ab.1, likelihood (fun j => (law j).bind k) ab.2)) - -noncomputable def messageCoupling {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - ProbabilityMeasure (Message × Message) := ⟨(messageCouplingPMF law k).toMeasure, inferInstance⟩ - -lemma messageCouplingPMF_fst {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - (messageCouplingPMF law k).map Prod.fst = likelihoodPMF law := by - rw [messageCouplingPMF, PMF.map_comp] - change (joint (marginal law) k).map (likelihood law ∘ Prod.fst) = _ - rw [← PMF.map_comp, joint_map_fst] - rfl - -lemma messageCouplingPMF_snd {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - (messageCouplingPMF law k).map Prod.snd = likelihoodPMF (fun j => (law j).bind k) := by - rw [messageCouplingPMF, PMF.map_comp] - change (joint (marginal law) k).map (likelihood (fun j => (law j).bind k) ∘ Prod.snd) = _ - rw [← PMF.map_comp, joint_map_snd, ← marginal_bind] - rfl - -lemma messageCoupling_fst {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - (messageCoupling law k).map Prod.fst = likelihoodLaw law := by - apply Subtype.ext - change (messageCouplingPMF law k).toMeasure.map Prod.fst = (likelihoodPMF law).toMeasure - rw [PMF.toMeasure_map _ _ measurable_fst, messageCouplingPMF_fst] - -lemma messageCoupling_snd {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : - (messageCoupling law k).map Prod.snd = likelihoodLaw (fun j => (law j).bind k) := by - apply Subtype.ext - change (messageCouplingPMF law k).toMeasure.map Prod.snd = (likelihoodPMF _).toMeasure - rw [PMF.toMeasure_map _ _ measurable_snd, messageCouplingPMF_snd] - -lemma integral_messageCoupling {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) - (f : C(Message × Message,ℝ)) : - ∫ mm, f mm ∂(messageCoupling law k : Measure (Message × Message)) = - mean (joint (marginal law) k) (fun ab => f (likelihood law ab.1, likelihood (fun j => (law j).bind k) ab.2)) := by - have hi : Integrable f (messageCouplingPMF law k).toMeasure := - f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) - change (∫ mm, f mm ∂(messageCouplingPMF law k).toMeasure) = _ - rw [PMF.integral_eq_tsum _ _ hi] - change mean ((joint (marginal law) k).map _) f = _ - obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - exact mean_map_bounded _ _ _ C (fun ab => by simpa only [Real.norm_eq_abs] using hC _ (Set.mem_univ _)) - -noncomputable def coordinateSecond {α : Type*} (law : Spin → PMF α) (i : Spin) : ℝ := - mean (marginal law) (fun a => (likelihood law a i)^2) - -lemma coordinateSecond_nonneg {α : Type*} (law : Spin → PMF α) (i : Spin) : - 0 ≤ coordinateSecond law i := mean_nonneg _ (fun value => sq_nonneg (likelihood law value i)) - -lemma coordinateSecond_bind_le {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) (i : Spin) : - coordinateSecond (fun j => (law j).bind k) i ≤ coordinateSecond law i := by - have hn := mean_nonneg (joint (marginal law) k) (fun ab => - sq_nonneg (likelihood law ab.1 i - likelihood (fun j => (law j).bind k) ab.2 i)) - rw [mean_joint_likelihood_square] at hn - exact sub_nonneg.mp hn - -noncomputable def squareJump (i : Spin) : C(Message × Message,ℝ) := - ⟨fun mm => (mm.1 i-mm.2 i)^2, - (((continuous_apply i).comp (continuous_subtype_val.comp continuous_fst)).sub - ((continuous_apply i).comp (continuous_subtype_val.comp continuous_snd))).pow 2⟩ - -lemma squareJump_nonneg (i : Spin) (mm : Message × Message) : 0 ≤ squareJump i mm := sq_nonneg _ - -lemma integral_squareJump {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) (i : Spin) : - ∫ mm, squareJump i mm ∂(messageCoupling law k : Measure (Message × Message)) = - coordinateSecond law i - coordinateSecond (fun j => (law j).bind k) i := by - rw [integral_messageCoupling] - exact mean_joint_likelihood_square law k i - - - -theorem likelihood_common_subsequence {α : ℕ → Type*} (law : ∀ n, Spin → PMF (α n)) - (k : ∀ n, α n → PMF (α (n+1))) - (hstep : ∀ n i, law (n+1) i = (law n i).bind (k n)) : - ∃ Q : ProbabilityMeasure Message, ∃ φ : ℕ → ℕ, StrictMono φ ∧ - Tendsto (fun n => likelihoodLaw (law (φ n))) atTop (𝓝 Q) ∧ - Tendsto (fun n => likelihoodLaw (law (φ n+1))) atTop (𝓝 Q) := by - have he (n : ℕ) : law (n+1) = (fun i => (law n i).bind (k n)) := funext (hstep n) - have ha (i : Spin) : Antitone (fun n => coordinateSecond (law n) i) := by - apply antitone_nat_of_succ_le - intro n - rw [he n] - exact coordinateSecond_bind_le _ _ _ - have hb (i : Spin) : BddBelow (Set.range (fun n => coordinateSecond (law n) i)) := - ⟨0, by rintro _ ⟨n,rfl⟩; exact coordinateSecond_nonneg _ _⟩ - have ht (i : Spin) := tendsto_atTop_ciInf (ha i) (hb i) - let Pn := fun n => messageCoupling (law n) (k n) - obtain ⟨P,_,φ,hφ,hlim⟩ := isCompact_univ.tendsto_subseq (fun n => Set.mem_univ (Pn n)) - have hzero (i : Spin) : ∫ mm, squareJump i mm ∂(P : Measure (Message × Message)) = 0 := by - have hdiff : Tendsto (fun n => coordinateSecond (law n) i - coordinateSecond (law (n+1)) i) - atTop (𝓝 0) := by - convert (ht i).sub ((ht i).comp (tendsto_add_atTop_nat 1)) using 1 <;> simp - have hint := (ProbabilityMeasure.continuous_integral_continuousMap (squareJump i)).continuousAt.tendsto.comp hlim - have hn : (fun n => ∫ mm, squareJump i mm ∂(Pn (φ n) : Measure (Message × Message))) = - (fun n => coordinateSecond (law (φ n)) i - coordinateSecond (law (φ n+1)) i) := by - funext n - dsimp [Pn] - rw [integral_squareJump, ← he] - simp only [Function.comp_def] at hint - rw [hn] at hint - exact tendsto_nhds_unique hint (hdiff.comp hφ.tendsto_atTop) - have hdiag : ∀ᵐ mm ∂(P : Measure (Message × Message)), mm.1 = mm.2 := by - have hi (i : Spin) : ∀ᵐ mm ∂(P : Measure (Message × Message)), squareJump i mm = 0 := - (integral_eq_zero_iff_of_nonneg (squareJump_nonneg i) - ((squareJump i).continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))).mp (hzero i) - filter_upwards [ae_all_iff.mpr hi] with mm hmm - apply Subtype.ext - funext i - have h := hmm i - change (mm.1 i-mm.2 i)^2 = 0 at h - exact sub_eq_zero.mp (sq_eq_zero_iff.mp h) - have hmaps : P.map Prod.snd = P.map Prod.fst := by - apply Subtype.ext - exact Measure.map_congr (hdiag.mono (fun mm hm => hm.symm)) - refine ⟨P.map Prod.fst, φ, hφ, ?_, ?_⟩ - · have hh := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (@Prod.fst Message Message))).tendsto P |>.comp hlim - simpa only [Function.comp_def, Pn, messageCoupling_fst] using hh - · have hh := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (@Prod.snd Message Message))).tendsto P |>.comp hlim - simp only [Function.comp_def, Pn, messageCoupling_snd, ← he, hmaps] at hh - exact hh - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Expectations + +namespace OAI + +/-! Likelihood messages, compact couplings and subsequential posterior limits. -/ + +namespace ThreeState +open MeasureTheory + + +abbrev Message := {m : Spin → ℝ // (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} + +instance : CoeFun Message (fun _ => Spin → ℝ) := ⟨Subtype.val⟩ + +lemma Message.nonneg (m : Message) (i : Spin) : 0 ≤ m i := m.2.1 i +lemma Message.sum (m : Message) : ∑ i, m i = 3 := m.2.2 +lemma Message.le_three (m : Message) (i : Spin) : m i ≤ 3 := by + calc + m i ≤ ∑ j, m j := Finset.single_le_sum (fun j _ => Message.nonneg m j) (Finset.mem_univ i) + _ = 3 := Message.sum m + +lemma message_isCompact : IsCompact {m : Spin → ℝ | (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} := by + have hc : IsClosed {m : Spin → ℝ | (∀ i, 0 ≤ m i) ∧ ∑ i, m i = 3} := by + apply IsClosed.inter + · have he : {m : Spin → ℝ | ∀ i, 0 ≤ m i} = + ⋂ i : Spin, {m : Spin → ℝ | 0 ≤ m i} := by ext m; simp + change IsClosed {m : Spin → ℝ | ∀ i, 0 ≤ m i} + rw [he] + exact isClosed_iInter (fun i : Spin => isClosed_le (continuous_const (y := (0:ℝ))) + (continuous_apply i : Continuous (fun m : Spin → ℝ => m i))) + · exact isClosed_eq (continuous_finsetSum _ (fun i _ => continuous_apply i)) continuous_const + apply (isCompact_Icc (a := (fun _ : Spin => (0:ℝ))) (b := fun _ => (3:ℝ))).of_isClosed_subset hc + intro m hm + exact ⟨hm.1, fun i => Message.le_three ⟨m,hm⟩ i⟩ + +instance : CompactSpace Message := isCompact_iff_compactSpace.mp message_isCompact +noncomputable def uninformative : Message := ⟨fun _ => 1, by simp⟩ + + +noncomputable def likelihood {α : Type*} (law : Spin → PMF α) (y : α) : Message := + ⟨fun i => 3*posterior law y i, by + constructor + · intro i; exact mul_nonneg (by norm_num) (posterior_nonneg law y i) + · rw [← Finset.mul_sum, posterior_sum]; norm_num⟩ + +lemma likelihood_apply {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + likelihood law y i = 3*posterior law y i := rfl + +lemma weighted_likelihood {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + mass (marginal law) y * likelihood law y i = mass (law i) y := by + rw [likelihood_apply] + have hh := weighted_posterior law y i + nlinarith + +lemma hasMean_likelihood {α : Type*} (law : Spin → PMF α) (i : Spin) : + HasMean (marginal law) (fun y => likelihood law y i) := by + exact (mass_summable (law i)).congr (fun y => (weighted_likelihood law y i).symm) + +lemma mean_likelihood {α : Type*} (law : Spin → PMF α) (i : Spin) : + mean (marginal law) (fun y => likelihood law y i) = 1 := by + unfold mean + simp_rw [weighted_likelihood] + exact mass_sum _ + +noncomputable def likelihoodPMF {α : Type*} (law : Spin → PMF α) : PMF Message := + (marginal law).map (likelihood law) + +noncomputable def likelihoodLaw {α : Type*} (law : Spin → PMF α) : ProbabilityMeasure Message := + ⟨(likelihoodPMF law).toMeasure, inferInstance⟩ + +lemma mean_likelihoodPMF {α : Type*} (law : Spin → PMF α) (f : Message → ℝ) + (hf : HasMean (marginal law) (fun y => f (likelihood law y))) : + mean (likelihoodPMF law) f = mean (marginal law) (fun y => f (likelihood law y)) := + mean_map hf + +lemma integral_likelihoodLaw {α : Type*} (law : Spin → PMF α) (f : C(Message,ℝ)) : + ∫ m, f m ∂(likelihoodLaw law : Measure Message) = + mean (marginal law) (fun y => f (likelihood law y)) := by + have hf : Integrable f (likelihoodPMF law).toMeasure := f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) + change (∫ m, f m ∂(likelihoodPMF law).toMeasure) = _ + rw [PMF.integral_eq_tsum _ _ hf] + change mean (likelihoodPMF law) f = _ + apply mean_likelihoodPMF + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + apply HasMean.of_abs + apply (hasMean_const (marginal law) C).mono (fun y => abs_nonneg _) + intro y + simpa only [Real.norm_eq_abs] using hC (likelihood law y) (Set.mem_univ _) + +end ThreeState + +namespace ThreeState +open MeasureTheory + +lemma abs_likelihood {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + |likelihood law y i| ≤ 3 := by + rw [abs_of_nonneg (Message.nonneg _ _)] + exact Message.le_three _ _ + +lemma abs_likelihood_square {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + |(likelihood law y i)^2| ≤ 9 := by + rw [abs_sq] + have h := abs_likelihood law y i + have hl := (abs_le.mp h).1 + have hu := (abs_le.mp h).2 + nlinarith + +lemma mean_likelihood_mul {α : Type*} (law : Spin → PMF α) (i : Spin) (f : α → ℝ) : + mean (marginal law) (fun y => likelihood law y i * f y) = mean (law i) f := by + unfold mean + apply tsum_congr + intro y + rw [← mul_assoc, weighted_likelihood] + + +lemma mean_joint_likelihood_mul {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) + (i : Spin) (f : β → ℝ) (C : ℝ) (hC : 0 ≤ C) (hf : ∀ b, |f b| ≤ C) : + mean (joint (marginal law) k) (fun ab => likelihood law ab.1 i * f ab.2) = + mean (marginal (fun j => (law j).bind k)) + (fun b => likelihood (fun j => (law j).bind k) b i * f b) := by + rw [mean_joint_bounded _ _ _ (3*C) (fun ab => by + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left (hf _) (abs_nonneg _)).trans + (mul_le_mul_of_nonneg_right (abs_likelihood _ _ _) hC))] + simp_rw [mean_const_mul] + rw [mean_likelihood_mul, mean_likelihood_mul, mean_bind_bounded _ _ _ C hf] + +lemma mean_joint_likelihood_square {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) + (i : Spin) : + mean (joint (marginal law) k) (fun ab => + (likelihood law ab.1 i - likelihood (fun j => (law j).bind k) ab.2 i)^2) = + mean (marginal law) (fun a => (likelihood law a i)^2) - + mean (marginal (fun j => (law j).bind k)) + (fun b => (likelihood (fun j => (law j).bind k) b i)^2) := by + let p := joint (marginal law) k + let u := fun ab : α × β => likelihood law ab.1 i + let v := fun ab : α × β => likelihood (fun j => (law j).bind k) ab.2 i + have hu : ∀ ab, |u ab| ≤ 3 := fun ab => abs_likelihood _ _ _ + have hv : ∀ ab, |v ab| ≤ 3 := fun ab => abs_likelihood _ _ _ + have husq : ∀ ab, |(u ab)^2| ≤ 9 := fun ab => by + rw [abs_sq]; nlinarith [sq_le_sq₀ (abs_nonneg (u ab)) (by norm_num : (0:ℝ) ≤ 3) |>.2 (hu ab), sq_abs (u ab)] + have hvsq : ∀ ab, |(v ab)^2| ≤ 9 := fun ab => by + rw [abs_sq]; nlinarith [sq_le_sq₀ (abs_nonneg (v ab)) (by norm_num : (0:ℝ) ≤ 3) |>.2 (hv ab), sq_abs (v ab)] + have huv : ∀ ab, |u ab * v ab| ≤ 9 := fun ab => by + rw [abs_mul]; exact (mul_le_mul (hu ab) (hv ab) (abs_nonneg _) (by norm_num)).trans_eq (by norm_num) + change mean p (fun ab => (u ab-v ab)^2) = _ + rw [mean_congr p (g := fun ab => ((u ab)^2+(v ab)^2)+ (-2)*(u ab*v ab)) (fun ab => by ring), + mean_add ((hasMean_bounded p 9 husq).add (hasMean_bounded p 9 hvsq)) + ((hasMean_bounded p 9 huv).const_mul (-2)), + mean_add (hasMean_bounded p 9 husq) (hasMean_bounded p 9 hvsq), mean_const_mul] + change mean (joint (marginal law) k) (fun ab => (likelihood law ab.1 i)^2) + + mean (joint (marginal law) k) (fun ab => (likelihood (fun j => (law j).bind k) ab.2 i)^2) + + -2 * mean (joint (marginal law) k) (fun ab => likelihood law ab.1 i * likelihood (fun j => (law j).bind k) ab.2 i) = _ + rw [mean_joint_fst (marginal law) k (fun a => (likelihood law a i)^2) 9 + (fun a => abs_likelihood_square law a i), + mean_joint_snd (marginal law) k (fun b => (likelihood (fun j => (law j).bind k) b i)^2) 9 + (fun b => abs_likelihood_square _ b i), + mean_joint_likelihood_mul law k i (fun b => likelihood (fun j => (law j).bind k) b i) 3 + (by norm_num) (fun b => abs_likelihood (fun j => (law j).bind k) b i), + ← marginal_bind] + simp only [← sq] + ring + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology + +lemma joint_map_fst {α β : Type*} (p : PMF α) (k : α → PMF β) : + (joint p k).map Prod.fst = p := by + simp only [joint, PMF.map_bind, PMF.map_comp, Function.comp_def] + change (p.bind (fun a => (k a).map (Function.const β a))) = _ + simp only [PMF.map_const, PMF.bind_pure] + +lemma joint_map_snd {α β : Type*} (p : PMF α) (k : α → PMF β) : + (joint p k).map Prod.snd = p.bind k := by + simp only [joint, PMF.map_bind, PMF.map_comp, Function.comp_def] + change (p.bind (fun a => (k a).map id)) = _ + simp only [PMF.map_id] + +noncomputable def messageCouplingPMF {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + PMF (Message × Message) := + (joint (marginal law) k).map (fun ab => (likelihood law ab.1, likelihood (fun j => (law j).bind k) ab.2)) + +noncomputable def messageCoupling {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + ProbabilityMeasure (Message × Message) := ⟨(messageCouplingPMF law k).toMeasure, inferInstance⟩ + +lemma messageCouplingPMF_fst {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + (messageCouplingPMF law k).map Prod.fst = likelihoodPMF law := by + rw [messageCouplingPMF, PMF.map_comp] + change (joint (marginal law) k).map (likelihood law ∘ Prod.fst) = _ + rw [← PMF.map_comp, joint_map_fst] + rfl + +lemma messageCouplingPMF_snd {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + (messageCouplingPMF law k).map Prod.snd = likelihoodPMF (fun j => (law j).bind k) := by + rw [messageCouplingPMF, PMF.map_comp] + change (joint (marginal law) k).map (likelihood (fun j => (law j).bind k) ∘ Prod.snd) = _ + rw [← PMF.map_comp, joint_map_snd, ← marginal_bind] + rfl + +lemma messageCoupling_fst {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + (messageCoupling law k).map Prod.fst = likelihoodLaw law := by + apply Subtype.ext + change (messageCouplingPMF law k).toMeasure.map Prod.fst = (likelihoodPMF law).toMeasure + rw [PMF.toMeasure_map _ _ measurable_fst, messageCouplingPMF_fst] + +lemma messageCoupling_snd {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) : + (messageCoupling law k).map Prod.snd = likelihoodLaw (fun j => (law j).bind k) := by + apply Subtype.ext + change (messageCouplingPMF law k).toMeasure.map Prod.snd = (likelihoodPMF _).toMeasure + rw [PMF.toMeasure_map _ _ measurable_snd, messageCouplingPMF_snd] + +lemma integral_messageCoupling {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) + (f : C(Message × Message,ℝ)) : + ∫ mm, f mm ∂(messageCoupling law k : Measure (Message × Message)) = + mean (joint (marginal law) k) (fun ab => f (likelihood law ab.1, likelihood (fun j => (law j).bind k) ab.2)) := by + have hi : Integrable f (messageCouplingPMF law k).toMeasure := + f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) + change (∫ mm, f mm ∂(messageCouplingPMF law k).toMeasure) = _ + rw [PMF.integral_eq_tsum _ _ hi] + change mean ((joint (marginal law) k).map _) f = _ + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + exact mean_map_bounded _ _ _ C (fun ab => by simpa only [Real.norm_eq_abs] using hC _ (Set.mem_univ _)) + +noncomputable def coordinateSecond {α : Type*} (law : Spin → PMF α) (i : Spin) : ℝ := + mean (marginal law) (fun a => (likelihood law a i)^2) + +lemma coordinateSecond_nonneg {α : Type*} (law : Spin → PMF α) (i : Spin) : + 0 ≤ coordinateSecond law i := mean_nonneg _ (fun value => sq_nonneg (likelihood law value i)) + +lemma coordinateSecond_bind_le {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) (i : Spin) : + coordinateSecond (fun j => (law j).bind k) i ≤ coordinateSecond law i := by + have hn := mean_nonneg (joint (marginal law) k) (fun ab => + sq_nonneg (likelihood law ab.1 i - likelihood (fun j => (law j).bind k) ab.2 i)) + rw [mean_joint_likelihood_square] at hn + exact sub_nonneg.mp hn + +noncomputable def squareJump (i : Spin) : C(Message × Message,ℝ) := + ⟨fun mm => (mm.1 i-mm.2 i)^2, + (((continuous_apply i).comp (continuous_subtype_val.comp continuous_fst)).sub + ((continuous_apply i).comp (continuous_subtype_val.comp continuous_snd))).pow 2⟩ + +lemma squareJump_nonneg (i : Spin) (mm : Message × Message) : 0 ≤ squareJump i mm := sq_nonneg _ + +lemma integral_squareJump {α β : Type*} (law : Spin → PMF α) (k : α → PMF β) (i : Spin) : + ∫ mm, squareJump i mm ∂(messageCoupling law k : Measure (Message × Message)) = + coordinateSecond law i - coordinateSecond (fun j => (law j).bind k) i := by + rw [integral_messageCoupling] + exact mean_joint_likelihood_square law k i + + + +theorem likelihood_common_subsequence {α : ℕ → Type*} (law : ∀ n, Spin → PMF (α n)) + (k : ∀ n, α n → PMF (α (n+1))) + (hstep : ∀ n i, law (n+1) i = (law n i).bind (k n)) : + ∃ Q : ProbabilityMeasure Message, ∃ φ : ℕ → ℕ, StrictMono φ ∧ + Tendsto (fun n => likelihoodLaw (law (φ n))) atTop (𝓝 Q) ∧ + Tendsto (fun n => likelihoodLaw (law (φ n+1))) atTop (𝓝 Q) := by + have he (n : ℕ) : law (n+1) = (fun i => (law n i).bind (k n)) := funext (hstep n) + have ha (i : Spin) : Antitone (fun n => coordinateSecond (law n) i) := by + apply antitone_nat_of_succ_le + intro n + rw [he n] + exact coordinateSecond_bind_le _ _ _ + have hb (i : Spin) : BddBelow (Set.range (fun n => coordinateSecond (law n) i)) := + ⟨0, by rintro _ ⟨n,rfl⟩; exact coordinateSecond_nonneg _ _⟩ + have ht (i : Spin) := tendsto_atTop_ciInf (ha i) (hb i) + let Pn := fun n => messageCoupling (law n) (k n) + obtain ⟨P,_,φ,hφ,hlim⟩ := isCompact_univ.tendsto_subseq (fun n => Set.mem_univ (Pn n)) + have hzero (i : Spin) : ∫ mm, squareJump i mm ∂(P : Measure (Message × Message)) = 0 := by + have hdiff : Tendsto (fun n => coordinateSecond (law n) i - coordinateSecond (law (n+1)) i) + atTop (𝓝 0) := by + convert (ht i).sub ((ht i).comp (tendsto_add_atTop_nat 1)) using 1 <;> simp + have hint := (ProbabilityMeasure.continuous_integral_continuousMap (squareJump i)).continuousAt.tendsto.comp hlim + have hn : (fun n => ∫ mm, squareJump i mm ∂(Pn (φ n) : Measure (Message × Message))) = + (fun n => coordinateSecond (law (φ n)) i - coordinateSecond (law (φ n+1)) i) := by + funext n + dsimp [Pn] + rw [integral_squareJump, ← he] + simp only [Function.comp_def] at hint + rw [hn] at hint + exact tendsto_nhds_unique hint (hdiff.comp hφ.tendsto_atTop) + have hdiag : ∀ᵐ mm ∂(P : Measure (Message × Message)), mm.1 = mm.2 := by + have hi (i : Spin) : ∀ᵐ mm ∂(P : Measure (Message × Message)), squareJump i mm = 0 := + (integral_eq_zero_iff_of_nonneg (squareJump_nonneg i) + ((squareJump i).continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))).mp (hzero i) + filter_upwards [ae_all_iff.mpr hi] with mm hmm + apply Subtype.ext + funext i + have h := hmm i + change (mm.1 i-mm.2 i)^2 = 0 at h + exact sub_eq_zero.mp (sq_eq_zero_iff.mp h) + have hmaps : P.map Prod.snd = P.map Prod.fst := by + apply Subtype.ext + exact Measure.map_congr (hdiag.mono (fun mm hm => hm.symm)) + refine ⟨P.map Prod.fst, φ, hφ, ?_, ?_⟩ + · have hh := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (@Prod.fst Message Message))).tendsto P |>.comp hlim + simpa only [Function.comp_def, Pn, messageCoupling_fst] using hh + · have hh := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (@Prod.snd Message Message))).tendsto P |>.comp hlim + simp only [Function.comp_def, Pn, messageCoupling_snd, ← he, hmaps] at hh + exact hh + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Negative.lean b/lean/OAI/Probability/ThreeState/Negative.lean index 47bb29db6841a5ee6a4c65185c31b6ad3ec3447a..d092c1e3c3bbd10324e08892406c43d86a1b3a77 100644 --- a/lean/OAI/Probability/ThreeState/Negative.lean +++ b/lean/OAI/Probability/ThreeState/Negative.lean @@ -1,222 +1,222 @@ -import Mathlib -import OAI.Probability.ThreeState.Couplings -import OAI.Probability.ThreeState.Noise - -namespace OAI - -/-! Signed small-channel and Dobrushin non-reconstruction regions. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - - - -theorem regular_small_negative_nonreconstruction (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) - (h : Admissible lam) (hl : lam ≤ 0) (hc : 4*(b:ℝ)*lam^2 ≤ 1) : - Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by - have hb0 : (0:ℝ) < b := by exact_mod_cast (show 0 advantage_nonneg (regularLaw b lam h n)) - (g := fun n => advantage (orderedLaw (PMF.pure b) L hL n)) _ ht - intro n - have hg := orderedAdvantage_degrade (PMF.pure b) L r hL hr hp n - have heLaw : orderedLaw (PMF.pure b) (L*r) hp n = orderedLaw (PMF.pure b) lam h n := by congr 1 - rw [heLaw] at hg - exact (orderedAdvantage_dominates (PMF.pure b) lam h n).trans hg - - - -theorem poisson_small_negative_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) (hl : lam ≤ 0) (hc : 4*d*lam^2 ≤ 1) : - Tendsto (poissonAdvantage d hd lam h) atTop (𝓝 0) := by - have hd0 : 0 < d := by linarith - let L := Real.sqrt d⁻¹ - have hL0 : 0 < L := Real.sqrt_pos.mpr (inv_pos.mpr hd0) - have hLsq : L^2=d⁻¹ := Real.sq_sqrt (inv_nonneg.mpr hd0.le) - have hK : d*L^2=1 := by rw [hLsq, mul_inv_cancel₀ hd0.ne'] - have hL1 : L≤1 := by - have hi : d⁻¹≤1 := (inv_le_one₀ hd0).mpr hd.le - nlinarith [sq_nonneg L] - have hL : Admissible L := ⟨by linarith, hL1⟩ - have hlow : -L/2≤lam := by - have hh : 4*lam^2≤L^2 := (mul_le_mul_iff_right₀ hd0).mp (by nlinarith only [hc,hK]) - nlinarith - let r := lam/L - have hr0 : -(1/2:ℝ)≤r := (le_div_iff₀ hL0).mpr (by linarith) - have hr1 : r≤1 := (div_le_one hL0).mpr (by linarith) - have hr : Admissible r := ⟨hr0,hr1⟩ - have heq : L*r=lam := by dsimp [r]; field_simp - have hp : Admissible (L*r) := by rwa [heq] - have ht := ordered_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d hd0.le) L hL - (poisson_positive_critical_uniform d hd L hL hL0 hK) - apply squeeze_zero (fun n => advantage_nonneg (poissonLaw d hd0.le lam h n)) - (g := fun n => advantage (orderedLaw (poissonOffspring d hd0.le) L hL n)) _ ht - intro n - have hg := orderedAdvantage_degrade (poissonOffspring d hd0.le) L r hL hr hp n - have heLaw : orderedLaw (poissonOffspring d hd0.le) (L*r) hp n = orderedLaw (poissonOffspring d hd0.le) lam h n := by congr 1 - rw [heLaw] at hg - exact (orderedAdvantage_dominates (poissonOffspring d hd0.le) lam h n).trans hg - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -noncomputable section - - - -lemma compose_pairTV_bound {α:Type*} (p:PMF ℕ) (law:Spin→PMF α) (d lam x:ℝ) - (h:Admissible lam) (hD:HasMean p (fun k:ℕ=>(k:ℝ))) - (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) (K:ℕ) (hK:2≤K) - (hx0:0≤x) (hx1:x≤1) (hx:∀i j,tvMass (law i) (law j)≤x) (i j:Spin) : - tvMass (composeLaw p law lam h i) (composeLaw p law lam h j) ≤ - d*|lam| *x-mass p K*(|lam| *x)^2 := by - let t:ℝ:=|lam| *x - have hl:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ - have ht0:0≤t:=mul_nonneg (abs_nonneg _) hx0 - have ht1:t≤1 := calc - t ≤ 1*x := mul_le_mul_of_nonneg_right hl hx0 - _ = x := one_mul x - _ ≤ 1 := hx1 - have he:tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)≤t := by - rw [tvMass_edge] - exact mul_le_mul_of_nonneg_left (hx i j) (abs_nonneg _) - have hpoint (k:ℕ) : tvMass (iidVector (edgeLaw law lam h i) k) (iidVector (edgeLaw law lam h j) k)≤ - 1-(1-t)^k := by - apply (tvMass_iidVector_le _ _ k).trans - have hp:=pow_le_pow_left₀ (by linarith : 0≤1-t) (by linarith : 1-t≤1-tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)) k - linarith - have hs1:Summable (fun k:ℕ=>mass p k*((k:ℝ)*t)):=hD.mul_const t - have hs2:Summable (fun k:ℕ=>if k=K then mass p K*t^2 else 0):=(hasSum_ite_eq K (mass p K*t^2)).summable - have hu (k:ℕ) : mass p k*tvMass (iidVector (edgeLaw law lam h i) k) (iidVector (edgeLaw law lam h j) k)≤ - mass p k*((k:ℝ)*t)-(if k=K then mass p K*t^2 else 0) := by - by_cases hk:k=K - · subst k - simp only [ite_true] - have hb:=bernoulli_quadratic_lower t ht0 ht1 K hK - have hv:=hpoint K - have hh:=mul_le_mul_of_nonneg_left (show tvMass (iidVector (edgeLaw law lam h i) K) (iidVector (edgeLaw law lam h j) K)≤(K:ℝ)*t-t^2 by linarith) (mass_nonneg p K) - nlinarith only [hh] - · rw [ite_eq_right hk,sub_zero] - have hb:=bernoulli_lower t ht0 ht1 k - exact mul_le_mul_of_nonneg_left (by linarith [hpoint k]) (mass_nonneg p k) - have hh:=Summable.tsum_le_tsum hu (summable_weighted_tv p - (fun k=>iidVector (edgeLaw law lam h i) k) (fun k=>iidVector (edgeLaw law lam h j) k)) (hs1.sub hs2) - have hsum: (∑'k:ℕ,mass p k*((k:ℝ)*t))=d*t := by - change mean p (fun k:ℕ=>(k:ℝ)*t)=_ - rw [mean_mul_const,hmean] - rw [hs1.tsum_sub hs2,hsum,tsum_ite_eq] at hh - simpa only [composeLaw,tvMass_sigmaPMF,t,mul_assoc] using hh - -lemma ordered_pairTV_decay (p:PMF ℕ) (d lam:ℝ) (h:Admissible lam) - (hD:HasMean p (fun k:ℕ=>(k:ℝ))) (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) - (K:ℕ) (hK:2≤K) (hd:d*|lam|≤1) (n:ℕ) (i j:Spin) : - tvMass (orderedLaw p lam h n i) (orderedLaw p lam h n j)≤decaySeq (mass p K*lam^2) n := by - have hl:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ - have hl2:lam^2≤1:=by nlinarith [sq_abs lam,abs_nonneg lam] - have hc0:0 ≤ mass p K*lam^2:=mul_nonneg (mass_nonneg p K) (sq_nonneg lam) - have hc1:mass p K*lam^2≤1 := calc - mass p K*lam^2 ≤ 1*lam^2 := mul_le_mul_of_nonneg_right (mass_le_one p K) (sq_nonneg lam) - _ = lam^2 := one_mul (lam^2) - _ ≤ 1 := hl2 - induction n generalizing i j with - | zero => exact tvMass_le_one _ _ - | succ n ih => - have hb:=decaySeq_bounds (mass p K*lam^2) hc0 hc1 n - have hh:=compose_pairTV_bound p (orderedLaw p lam h n) d lam (decaySeq (mass p K*lam^2) n) - h hD hmean K hK hb.1 hb.2 (fun i j=>ih i j) i j - have hg:=mul_le_mul_of_nonneg_right hd hb.1 - change tvMass (composeLaw p (orderedLaw p lam h n) lam h i) - (composeLaw p (orderedLaw p lam h n) lam h j)≤_ - change _≤decaySeq (mass p K*lam^2) n-(mass p K*lam^2)*(decaySeq (mass p K*lam^2) n)^2 - simp only [mul_pow,sq_abs] at hh - nlinarith only [hh,hg] - - - -theorem nonreconstruction_dobrushin (p:PMF ℕ) (d lam:ℝ) (h:Admissible lam) - (hD:HasMean p (fun k:ℕ=>(k:ℝ))) (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) - (K:ℕ) (hK:2≤K) (hp:0 < mass p K) (hl:lam≠0) (hd:d*|lam|≤1) : - Tendsto (fun n=>advantage (observedLaw p lam h n)) atTop (𝓝 0) := by - have hal:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ - have hl2:lam^2≤1:=by nlinarith [sq_abs lam,abs_nonneg lam] - have hc:0 < mass p K*lam^2:=mul_pos hp (sq_pos_of_ne_zero hl) - have hc1:mass p K*lam^2≤1 := calc - mass p K*lam^2 ≤ 1*lam^2 := mul_le_mul_of_nonneg_right (mass_le_one p K) (sq_nonneg lam) - _ = lam^2 := one_mul (lam^2) - _ ≤ 1 := hl2 - apply squeeze_zero (fun n=>advantage_nonneg (observedLaw p lam h n)) _ (decaySeq_tendsto _ hc hc1) - intro n - exact (orderedAdvantage_dominates p lam h n).trans (advantage_le_pair_bound _ _ - (ordered_pairTV_decay p d lam h hD hmean K hK hd n)) -end -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -noncomputable section - - -theorem regular_dobrushin_nonreconstruction (b:ℕ) (hb:2≤b) (lam:ℝ) - (h:Admissible lam) (hd:(b:ℝ)*|lam|≤1) : - Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by - by_cases hl:lam=0 - · apply regular_small_negative_nonreconstruction b hb lam h (by simp [hl]) - simp [hl] - · exact nonreconstruction_dobrushin (PMF.pure b) (b:ℝ) lam h - (regular_moments b).hasMean (regular_moments b).first b hb - (by simp [mass_pure]) hl hd - - - -theorem poisson_dobrushin_nonreconstruction (d:ℝ) (hd:1 advantage_nonneg (regularLaw b lam h n)) + (g := fun n => advantage (orderedLaw (PMF.pure b) L hL n)) _ ht + intro n + have hg := orderedAdvantage_degrade (PMF.pure b) L r hL hr hp n + have heLaw : orderedLaw (PMF.pure b) (L*r) hp n = orderedLaw (PMF.pure b) lam h n := by congr 1 + rw [heLaw] at hg + exact (orderedAdvantage_dominates (PMF.pure b) lam h n).trans hg + + + +theorem poisson_small_negative_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) (hl : lam ≤ 0) (hc : 4*d*lam^2 ≤ 1) : + Tendsto (poissonAdvantage d hd lam h) atTop (𝓝 0) := by + have hd0 : 0 < d := by linarith + let L := Real.sqrt d⁻¹ + have hL0 : 0 < L := Real.sqrt_pos.mpr (inv_pos.mpr hd0) + have hLsq : L^2=d⁻¹ := Real.sq_sqrt (inv_nonneg.mpr hd0.le) + have hK : d*L^2=1 := by rw [hLsq, mul_inv_cancel₀ hd0.ne'] + have hL1 : L≤1 := by + have hi : d⁻¹≤1 := (inv_le_one₀ hd0).mpr hd.le + nlinarith [sq_nonneg L] + have hL : Admissible L := ⟨by linarith, hL1⟩ + have hlow : -L/2≤lam := by + have hh : 4*lam^2≤L^2 := (mul_le_mul_iff_right₀ hd0).mp (by nlinarith only [hc,hK]) + nlinarith + let r := lam/L + have hr0 : -(1/2:ℝ)≤r := (le_div_iff₀ hL0).mpr (by linarith) + have hr1 : r≤1 := (div_le_one hL0).mpr (by linarith) + have hr : Admissible r := ⟨hr0,hr1⟩ + have heq : L*r=lam := by dsimp [r]; field_simp + have hp : Admissible (L*r) := by rwa [heq] + have ht := ordered_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d hd0.le) L hL + (poisson_positive_critical_uniform d hd L hL hL0 hK) + apply squeeze_zero (fun n => advantage_nonneg (poissonLaw d hd0.le lam h n)) + (g := fun n => advantage (orderedLaw (poissonOffspring d hd0.le) L hL n)) _ ht + intro n + have hg := orderedAdvantage_degrade (poissonOffspring d hd0.le) L r hL hr hp n + have heLaw : orderedLaw (poissonOffspring d hd0.le) (L*r) hp n = orderedLaw (poissonOffspring d hd0.le) lam h n := by congr 1 + rw [heLaw] at hg + exact (orderedAdvantage_dominates (poissonOffspring d hd0.le) lam h n).trans hg + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +noncomputable section + + + +lemma compose_pairTV_bound {α:Type*} (p:PMF ℕ) (law:Spin→PMF α) (d lam x:ℝ) + (h:Admissible lam) (hD:HasMean p (fun k:ℕ=>(k:ℝ))) + (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) (K:ℕ) (hK:2≤K) + (hx0:0≤x) (hx1:x≤1) (hx:∀i j,tvMass (law i) (law j)≤x) (i j:Spin) : + tvMass (composeLaw p law lam h i) (composeLaw p law lam h j) ≤ + d*|lam| *x-mass p K*(|lam| *x)^2 := by + let t:ℝ:=|lam| *x + have hl:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ + have ht0:0≤t:=mul_nonneg (abs_nonneg _) hx0 + have ht1:t≤1 := calc + t ≤ 1*x := mul_le_mul_of_nonneg_right hl hx0 + _ = x := one_mul x + _ ≤ 1 := hx1 + have he:tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)≤t := by + rw [tvMass_edge] + exact mul_le_mul_of_nonneg_left (hx i j) (abs_nonneg _) + have hpoint (k:ℕ) : tvMass (iidVector (edgeLaw law lam h i) k) (iidVector (edgeLaw law lam h j) k)≤ + 1-(1-t)^k := by + apply (tvMass_iidVector_le _ _ k).trans + have hp:=pow_le_pow_left₀ (by linarith : 0≤1-t) (by linarith : 1-t≤1-tvMass (edgeLaw law lam h i) (edgeLaw law lam h j)) k + linarith + have hs1:Summable (fun k:ℕ=>mass p k*((k:ℝ)*t)):=hD.mul_const t + have hs2:Summable (fun k:ℕ=>if k=K then mass p K*t^2 else 0):=(hasSum_ite_eq K (mass p K*t^2)).summable + have hu (k:ℕ) : mass p k*tvMass (iidVector (edgeLaw law lam h i) k) (iidVector (edgeLaw law lam h j) k)≤ + mass p k*((k:ℝ)*t)-(if k=K then mass p K*t^2 else 0) := by + by_cases hk:k=K + · subst k + simp only [ite_true] + have hb:=bernoulli_quadratic_lower t ht0 ht1 K hK + have hv:=hpoint K + have hh:=mul_le_mul_of_nonneg_left (show tvMass (iidVector (edgeLaw law lam h i) K) (iidVector (edgeLaw law lam h j) K)≤(K:ℝ)*t-t^2 by linarith) (mass_nonneg p K) + nlinarith only [hh] + · rw [ite_eq_right hk,sub_zero] + have hb:=bernoulli_lower t ht0 ht1 k + exact mul_le_mul_of_nonneg_left (by linarith [hpoint k]) (mass_nonneg p k) + have hh:=Summable.tsum_le_tsum hu (summable_weighted_tv p + (fun k=>iidVector (edgeLaw law lam h i) k) (fun k=>iidVector (edgeLaw law lam h j) k)) (hs1.sub hs2) + have hsum: (∑'k:ℕ,mass p k*((k:ℝ)*t))=d*t := by + change mean p (fun k:ℕ=>(k:ℝ)*t)=_ + rw [mean_mul_const,hmean] + rw [hs1.tsum_sub hs2,hsum,tsum_ite_eq] at hh + simpa only [composeLaw,tvMass_sigmaPMF,t,mul_assoc] using hh + +lemma ordered_pairTV_decay (p:PMF ℕ) (d lam:ℝ) (h:Admissible lam) + (hD:HasMean p (fun k:ℕ=>(k:ℝ))) (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) + (K:ℕ) (hK:2≤K) (hd:d*|lam|≤1) (n:ℕ) (i j:Spin) : + tvMass (orderedLaw p lam h n i) (orderedLaw p lam h n j)≤decaySeq (mass p K*lam^2) n := by + have hl:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ + have hl2:lam^2≤1:=by nlinarith [sq_abs lam,abs_nonneg lam] + have hc0:0 ≤ mass p K*lam^2:=mul_nonneg (mass_nonneg p K) (sq_nonneg lam) + have hc1:mass p K*lam^2≤1 := calc + mass p K*lam^2 ≤ 1*lam^2 := mul_le_mul_of_nonneg_right (mass_le_one p K) (sq_nonneg lam) + _ = lam^2 := one_mul (lam^2) + _ ≤ 1 := hl2 + induction n generalizing i j with + | zero => exact tvMass_le_one _ _ + | succ n ih => + have hb:=decaySeq_bounds (mass p K*lam^2) hc0 hc1 n + have hh:=compose_pairTV_bound p (orderedLaw p lam h n) d lam (decaySeq (mass p K*lam^2) n) + h hD hmean K hK hb.1 hb.2 (fun i j=>ih i j) i j + have hg:=mul_le_mul_of_nonneg_right hd hb.1 + change tvMass (composeLaw p (orderedLaw p lam h n) lam h i) + (composeLaw p (orderedLaw p lam h n) lam h j)≤_ + change _≤decaySeq (mass p K*lam^2) n-(mass p K*lam^2)*(decaySeq (mass p K*lam^2) n)^2 + simp only [mul_pow,sq_abs] at hh + nlinarith only [hh,hg] + + + +theorem nonreconstruction_dobrushin (p:PMF ℕ) (d lam:ℝ) (h:Admissible lam) + (hD:HasMean p (fun k:ℕ=>(k:ℝ))) (hmean:mean p (fun k:ℕ=>(k:ℝ))=d) + (K:ℕ) (hK:2≤K) (hp:0 < mass p K) (hl:lam≠0) (hd:d*|lam|≤1) : + Tendsto (fun n=>advantage (observedLaw p lam h n)) atTop (𝓝 0) := by + have hal:|lam|≤1:=abs_le.mpr ⟨by linarith [h.1],h.2⟩ + have hl2:lam^2≤1:=by nlinarith [sq_abs lam,abs_nonneg lam] + have hc:0 < mass p K*lam^2:=mul_pos hp (sq_pos_of_ne_zero hl) + have hc1:mass p K*lam^2≤1 := calc + mass p K*lam^2 ≤ 1*lam^2 := mul_le_mul_of_nonneg_right (mass_le_one p K) (sq_nonneg lam) + _ = lam^2 := one_mul (lam^2) + _ ≤ 1 := hl2 + apply squeeze_zero (fun n=>advantage_nonneg (observedLaw p lam h n)) _ (decaySeq_tendsto _ hc hc1) + intro n + exact (orderedAdvantage_dominates p lam h n).trans (advantage_le_pair_bound _ _ + (ordered_pairTV_decay p d lam h hD hmean K hK hd n)) +end +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +noncomputable section + + +theorem regular_dobrushin_nonreconstruction (b:ℕ) (hb:2≤b) (lam:ℝ) + (h:Admissible lam) (hd:(b:ℝ)*|lam|≤1) : + Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by + by_cases hl:lam=0 + · apply regular_small_negative_nonreconstruction b hb lam h (by simp [hl]) + simp [hl] + · exact nonreconstruction_dobrushin (PMF.pure b) (b:ℝ) lam h + (regular_moments b).hasMean (regular_moments b).first b hb + (by simp [mass_pure]) hl hd + + + +theorem poisson_dobrushin_nonreconstruction (d:ℝ) (hd:1 fin_cases j <;> simp [channel, Fin.sum_univ_succ] <;> ring - -noncomputable def orderedExtraNoise (r : ℝ) (hr : Admissible r) (n : ℕ) - (y : OrderedObservation n) : PMF (OrderedObservation n) := - (channelPMF r hr 0).map (fun j : Spin => renameOrdered n (Equiv.addRight j) y) - -lemma orderedLaw_extraNoise (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (r : ℝ) (hr : Admissible r) (n : ℕ) (i : Spin) : - (orderedLaw offspring lam h n i).bind (orderedExtraNoise r hr n) = - (channelPMF r hr i).bind (orderedLaw offspring lam h n) := by - unfold orderedExtraNoise - simp only [PMF.map, Function.comp_def] - rw [PMF.bind_comm] - have he (j : Spin) : (orderedLaw offspring lam h n i).bind - (fun y => PMF.pure (renameOrdered n (Equiv.addRight j) y)) = orderedLaw offspring lam h n (i+j) := by - exact orderedLaw_rename offspring lam h (Equiv.addRight j) n i - simp_rw [he] - have hm : (channelPMF r hr 0).map (Equiv.addLeft i) = channelPMF r hr i := by - simpa using channelPMF_map r hr (Equiv.addLeft i) 0 - rw [← hm, PMF.bind_map] - rfl - - - -noncomputable def orderedDegrade (r : ℝ) (hr : Admissible r) : - (n : ℕ) → OrderedObservation n → PMF (OrderedObservation n) - | 0 => PMF.pure - | n+1 => fun ⟨k,v⟩ => (vectorTraverse (fun y => (orderedDegrade r hr n y).bind (orderedExtraNoise r hr n)) k v).map (Sigma.mk k) - -lemma orderedLaw_degrade (offspring : PMF ℕ) (lam r : ℝ) (h : Admissible lam) - (hr : Admissible r) (hp : Admissible (lam*r)) (n : ℕ) (i : Spin) : - (orderedLaw offspring lam h n i).bind (orderedDegrade r hr n) = - orderedLaw offspring (lam*r) hp n i := by - induction n generalizing i with - | zero => simp only [orderedLaw, orderedDegrade, PMF.bind_pure] - | succ n ih => - simp only [orderedLaw, orderedDegrade, PMF.bind_bind, PMF.bind_map, Function.comp_def] - apply congrArg (PMF.bind offspring) - funext k - rw [← PMF.map_bind, iidVector_bind_traverse, PMF.bind_bind] - have he (j : Spin) : (orderedLaw offspring lam h n j).bind - (fun y => (orderedDegrade r hr n y).bind (orderedExtraNoise r hr n)) = - (channelPMF r hr j).bind (orderedLaw offspring (lam*r) hp n) := by - rw [← PMF.bind_bind, ih, orderedLaw_extraNoise] - simp_rw [he] - rw [← PMF.bind_bind, channelPMF_comp lam r h hr hp] - -lemma orderedAdvantage_degrade (offspring : PMF ℕ) (lam r : ℝ) (h : Admissible lam) - (hr : Admissible r) (hp : Admissible (lam*r)) (n : ℕ) : - advantage (orderedLaw offspring (lam*r) hp n) ≤ advantage (orderedLaw offspring lam h n) := by - have he : orderedLaw offspring (lam*r) hp n = fun i => - (orderedLaw offspring lam h n i).bind (orderedDegrade r hr n) := funext (fun i => (orderedLaw_degrade offspring lam r h hr hp n i).symm) - rw [he] - exact advantage_bind_le _ _ - -lemma orderedAdvantage_antitone (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - Antitone (fun n => advantage (orderedLaw offspring lam h n)) := by - apply antitone_nat_of_succ_le - intro n - have he : orderedLaw offspring lam h (n+1) = fun i => - (orderedLaw offspring lam h n i).bind (orderedGrow offspring lam h n) := funext (fun i => (orderedLaw_grow offspring lam h n i).symm) - rw [he] - exact advantage_bind_le _ _ - -lemma ordered_tendsto_zero_of_uniform_fixedpoints (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hunif : ∀ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q → SpinSymmetric Q → posteriorMu Q=0) : - Tendsto (fun n => advantage (orderedLaw offspring lam h n)) atTop (𝓝 0) := by - obtain ⟨Q,hQ,hs,φ,hφ,hlim⟩ := ordered_exists_symmetric_fixedpoint offspring lam h - have htv := integral_tv_zero_of_mu_zero Q (hunif Q hQ hs) - have hordered := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim - rw [htv] at hordered - let a := fun n => advantage (orderedLaw offspring lam h n) - have hb : BddBelow (Set.range a) := ⟨0, by rintro x ⟨n,rfl⟩; exact advantage_nonneg _⟩ - have hall := tendsto_atTop_ciInf (orderedAdvantage_antitone offspring lam h) hb - have hz : (⨅ n, a n)=0 := tendsto_nhds_unique (hall.comp hφ.tendsto_atTop) hordered - rwa [hz] at hall - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - - - -theorem poisson_nonnegative_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) (hl0 : 0 ≤ lam) (hc : d*lam^2 ≤ 1) : - Tendsto (poissonAdvantage d (by linarith) lam h) atTop (𝓝 0) := by - have hd0 : 0 < d := by linarith - let L := Real.sqrt d⁻¹ - have hL0 : 0 < L := Real.sqrt_pos.mpr (inv_pos.mpr hd0) - have hLsq : L^2=d⁻¹ := Real.sq_sqrt (inv_nonneg.mpr hd0.le) - have hK : d*L^2=1 := by rw [hLsq, mul_inv_cancel₀ hd0.ne'] - have hL1 : L≤1 := by - have hi : d⁻¹≤1 := (inv_le_one₀ hd0).mpr hd.le - nlinarith [sq_nonneg L] - have hL : Admissible L := ⟨by linarith, hL1⟩ - have hlL : lam≤L := by - have hh : lam^2≤L^2 := (mul_le_mul_iff_right₀ hd0).mp (by nlinarith only [hc,hK]) - nlinarith - let r := lam/L - have hr0 : 0≤r := div_nonneg hl0 hL0.le - have hr1 : r≤1 := (div_le_one hL0).mpr hlL - have hr : Admissible r := ⟨by linarith, hr1⟩ - have heq : L*r=lam := by dsimp [r]; field_simp - have hp : Admissible (L*r) := by rwa [heq] - have ht := ordered_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d hd0.le) L hL - (poisson_positive_critical_uniform d hd L hL hL0 hK) - apply squeeze_zero (fun n => advantage_nonneg _) - (g := fun n => advantage (orderedLaw (poissonOffspring d hd0.le) L hL n)) _ ht - intro n - have hg := orderedAdvantage_degrade (poissonOffspring d hd0.le) L r hL hr hp n - have heLaw : orderedLaw (poissonOffspring d hd0.le) (L*r) hp n = orderedLaw (poissonOffspring d hd0.le) lam h n := by - congr 1 - rw [heLaw] at hg - exact (orderedAdvantage_dominates (poissonOffspring d hd0.le) lam h n).trans hg - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - - -theorem regular_nonnegative_nonreconstruction (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) - (h : Admissible lam) (hl0 : 0 ≤ lam) (hc : (b:ℝ)*lam^2 ≤ 1) : - Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by - have hb0 : (0:ℝ) < b := by exact_mod_cast (show 0 advantage_nonneg _) - (g := fun n => advantage (orderedLaw (PMF.pure b) L hL n)) _ ht - intro n - have hg := orderedAdvantage_degrade (PMF.pure b) L r hL hr hp n - have heLaw : orderedLaw (PMF.pure b) (L*r) hp n = orderedLaw (PMF.pure b) lam h n := by - congr 1 - rw [heLaw] at hg - exact (orderedAdvantage_dominates (PMF.pure b) lam h n).trans hg - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.PoissonCritical + +namespace OAI + +/-! Additional channel noise and nonnegative-channel non-reconstruction. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma pmf_ext_mass {α : Type*} {p q : PMF α} (he : ∀ a, mass p a=mass q a) : p=q := by + apply PMF.ext + intro a + rcases (ENNReal.toReal_eq_toReal_iff (p a) (q a)).mp (he a) with he | he | he + · exact he + · exact False.elim ((q.apply_ne_top a) he.2) + · exact False.elim ((p.apply_ne_top a) he.1) + +lemma channelPMF_comp (a b : ℝ) (ha : Admissible a) (hb : Admissible b) (hab : Admissible (a*b)) (i : Spin) : + (channelPMF a ha i).bind (channelPMF b hb) = channelPMF (a*b) hab i := by + apply pmf_ext_mass + intro j + rw [mass_bind] + simp only [tsum_fintype, mass_channelPMF] + fin_cases i <;> fin_cases j <;> simp [channel, Fin.sum_univ_succ] <;> ring + +noncomputable def orderedExtraNoise (r : ℝ) (hr : Admissible r) (n : ℕ) + (y : OrderedObservation n) : PMF (OrderedObservation n) := + (channelPMF r hr 0).map (fun j : Spin => renameOrdered n (Equiv.addRight j) y) + +lemma orderedLaw_extraNoise (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (r : ℝ) (hr : Admissible r) (n : ℕ) (i : Spin) : + (orderedLaw offspring lam h n i).bind (orderedExtraNoise r hr n) = + (channelPMF r hr i).bind (orderedLaw offspring lam h n) := by + unfold orderedExtraNoise + simp only [PMF.map, Function.comp_def] + rw [PMF.bind_comm] + have he (j : Spin) : (orderedLaw offspring lam h n i).bind + (fun y => PMF.pure (renameOrdered n (Equiv.addRight j) y)) = orderedLaw offspring lam h n (i+j) := by + exact orderedLaw_rename offspring lam h (Equiv.addRight j) n i + simp_rw [he] + have hm : (channelPMF r hr 0).map (Equiv.addLeft i) = channelPMF r hr i := by + simpa using channelPMF_map r hr (Equiv.addLeft i) 0 + rw [← hm, PMF.bind_map] + rfl + + + +noncomputable def orderedDegrade (r : ℝ) (hr : Admissible r) : + (n : ℕ) → OrderedObservation n → PMF (OrderedObservation n) + | 0 => PMF.pure + | n+1 => fun ⟨k,v⟩ => (vectorTraverse (fun y => (orderedDegrade r hr n y).bind (orderedExtraNoise r hr n)) k v).map (Sigma.mk k) + +lemma orderedLaw_degrade (offspring : PMF ℕ) (lam r : ℝ) (h : Admissible lam) + (hr : Admissible r) (hp : Admissible (lam*r)) (n : ℕ) (i : Spin) : + (orderedLaw offspring lam h n i).bind (orderedDegrade r hr n) = + orderedLaw offspring (lam*r) hp n i := by + induction n generalizing i with + | zero => simp only [orderedLaw, orderedDegrade, PMF.bind_pure] + | succ n ih => + simp only [orderedLaw, orderedDegrade, PMF.bind_bind, PMF.bind_map, Function.comp_def] + apply congrArg (PMF.bind offspring) + funext k + rw [← PMF.map_bind, iidVector_bind_traverse, PMF.bind_bind] + have he (j : Spin) : (orderedLaw offspring lam h n j).bind + (fun y => (orderedDegrade r hr n y).bind (orderedExtraNoise r hr n)) = + (channelPMF r hr j).bind (orderedLaw offspring (lam*r) hp n) := by + rw [← PMF.bind_bind, ih, orderedLaw_extraNoise] + simp_rw [he] + rw [← PMF.bind_bind, channelPMF_comp lam r h hr hp] + +lemma orderedAdvantage_degrade (offspring : PMF ℕ) (lam r : ℝ) (h : Admissible lam) + (hr : Admissible r) (hp : Admissible (lam*r)) (n : ℕ) : + advantage (orderedLaw offspring (lam*r) hp n) ≤ advantage (orderedLaw offspring lam h n) := by + have he : orderedLaw offspring (lam*r) hp n = fun i => + (orderedLaw offspring lam h n i).bind (orderedDegrade r hr n) := funext (fun i => (orderedLaw_degrade offspring lam r h hr hp n i).symm) + rw [he] + exact advantage_bind_le _ _ + +lemma orderedAdvantage_antitone (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + Antitone (fun n => advantage (orderedLaw offspring lam h n)) := by + apply antitone_nat_of_succ_le + intro n + have he : orderedLaw offspring lam h (n+1) = fun i => + (orderedLaw offspring lam h n i).bind (orderedGrow offspring lam h n) := funext (fun i => (orderedLaw_grow offspring lam h n i).symm) + rw [he] + exact advantage_bind_le _ _ + +lemma ordered_tendsto_zero_of_uniform_fixedpoints (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hunif : ∀ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q → SpinSymmetric Q → posteriorMu Q=0) : + Tendsto (fun n => advantage (orderedLaw offspring lam h n)) atTop (𝓝 0) := by + obtain ⟨Q,hQ,hs,φ,hφ,hlim⟩ := ordered_exists_symmetric_fixedpoint offspring lam h + have htv := integral_tv_zero_of_mu_zero Q (hunif Q hQ hs) + have hordered := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim + rw [htv] at hordered + let a := fun n => advantage (orderedLaw offspring lam h n) + have hb : BddBelow (Set.range a) := ⟨0, by rintro x ⟨n,rfl⟩; exact advantage_nonneg _⟩ + have hall := tendsto_atTop_ciInf (orderedAdvantage_antitone offspring lam h) hb + have hz : (⨅ n, a n)=0 := tendsto_nhds_unique (hall.comp hφ.tendsto_atTop) hordered + rwa [hz] at hall + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + + + +theorem poisson_nonnegative_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) (hl0 : 0 ≤ lam) (hc : d*lam^2 ≤ 1) : + Tendsto (poissonAdvantage d (by linarith) lam h) atTop (𝓝 0) := by + have hd0 : 0 < d := by linarith + let L := Real.sqrt d⁻¹ + have hL0 : 0 < L := Real.sqrt_pos.mpr (inv_pos.mpr hd0) + have hLsq : L^2=d⁻¹ := Real.sq_sqrt (inv_nonneg.mpr hd0.le) + have hK : d*L^2=1 := by rw [hLsq, mul_inv_cancel₀ hd0.ne'] + have hL1 : L≤1 := by + have hi : d⁻¹≤1 := (inv_le_one₀ hd0).mpr hd.le + nlinarith [sq_nonneg L] + have hL : Admissible L := ⟨by linarith, hL1⟩ + have hlL : lam≤L := by + have hh : lam^2≤L^2 := (mul_le_mul_iff_right₀ hd0).mp (by nlinarith only [hc,hK]) + nlinarith + let r := lam/L + have hr0 : 0≤r := div_nonneg hl0 hL0.le + have hr1 : r≤1 := (div_le_one hL0).mpr hlL + have hr : Admissible r := ⟨by linarith, hr1⟩ + have heq : L*r=lam := by dsimp [r]; field_simp + have hp : Admissible (L*r) := by rwa [heq] + have ht := ordered_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d hd0.le) L hL + (poisson_positive_critical_uniform d hd L hL hL0 hK) + apply squeeze_zero (fun n => advantage_nonneg _) + (g := fun n => advantage (orderedLaw (poissonOffspring d hd0.le) L hL n)) _ ht + intro n + have hg := orderedAdvantage_degrade (poissonOffspring d hd0.le) L r hL hr hp n + have heLaw : orderedLaw (poissonOffspring d hd0.le) (L*r) hp n = orderedLaw (poissonOffspring d hd0.le) lam h n := by + congr 1 + rw [heLaw] at hg + exact (orderedAdvantage_dominates (poissonOffspring d hd0.le) lam h n).trans hg + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + + +theorem regular_nonnegative_nonreconstruction (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) + (h : Admissible lam) (hl0 : 0 ≤ lam) (hc : (b:ℝ)*lam^2 ≤ 1) : + Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by + have hb0 : (0:ℝ) < b := by exact_mod_cast (show 0 advantage_nonneg _) + (g := fun n => advantage (orderedLaw (PMF.pure b) L hL n)) _ ht + intro n + have hg := orderedAdvantage_degrade (PMF.pure b) L r hL hr hp n + have heLaw : orderedLaw (PMF.pure b) (L*r) hp n = orderedLaw (PMF.pure b) lam h n := by + congr 1 + rw [heLaw] at hg + exact (orderedAdvantage_dominates (PMF.pure b) lam h n).trans hg + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Observation.lean b/lean/OAI/Probability/ThreeState/Observation.lean index 7b60dc631ee4d9eb367fed570b348f51022e70bf..1542b1566cd2f8b58da84cf1d82605a153bb7ecb 100644 --- a/lean/OAI/Probability/ThreeState/Observation.lean +++ b/lean/OAI/Probability/ThreeState/Observation.lean @@ -1,271 +1,271 @@ -import Mathlib -import OAI.Probability.ThreeState.Messages - -namespace OAI - -/-! Ordered and unlabelled boundary observations and information degradation. -/ - -namespace ThreeState - - - -noncomputable def iidVector {α : Type*} (p : PMF α) : (n : ℕ) → PMF (Fin n → α) - | 0 => PMF.pure Fin.elim0 - | n+1 => p.bind (fun a => (iidVector p n).map (Fin.cons a)) - -lemma iidVector_map {α β : Type*} (p : PMF α) (f : α → β) (n : ℕ) : - (iidVector p n).map (fun as => f ∘ as) = iidVector (p.map f) n := by - induction n with - | zero => - simp only [iidVector, PMF.pure_map] - congr 1 - funext i - exact Fin.elim0 i - | succ n ih => - simp only [iidVector, PMF.map_bind, PMF.map_comp, PMF.bind_map] - apply congrArg (PMF.bind p) - funext a - rw [← ih] - dsimp only [Function.comp_def] - rw [PMF.map_comp] - congr 1 - funext v j - cases j using Fin.cases <;> simp - -lemma iidVector_ofFn {α : Type*} (p : PMF α) (n : ℕ) : - (iidVector p n).map List.ofFn = iidList p n := by - induction n with - | zero => simp [iidVector, iidList, PMF.pure_map] - | succ n ih => - simp only [iidVector, iidList, PMF.map_bind, PMF.map_comp] - apply congrArg (PMF.bind p) - funext a - rw [← ih, PMF.map_comp] - congr 1 - funext v - simp [List.ofFn_succ] - -lemma iidVector_apply {α : Type*} (p : PMF α) (n : ℕ) (v : Fin n → α) : - iidVector p n v = ∏ j, p (v j) := by - classical - induction n with - | zero => - have he : v = Fin.elim0 := by funext j; exact Fin.elim0 j - simp [iidVector, he] - | succ n ih => - simp only [iidVector, PMF.bind_apply, PMF.map_apply] - have he (a : α) (w : Fin n → α) : (v = Fin.cons a w) ↔ (a=v 0 ∧ w=Fin.tail v) := by - constructor - · intro h - subst v - simp - · rintro ⟨rfl,rfl⟩ - exact (Fin.cons_self_tail v).symm - simp_rw [he] - simp only [ite_and] - rw [tsum_eq_single (v 0)] - · simp [ih, Fin.prod_univ_succ, Fin.tail] - · intro a ha - simp [ha] - - -abbrev OrderedObservation : ℕ → Type - | 0 => Spin - | n+1 => Σ k : ℕ, Fin k → OrderedObservation n - -noncomputable def orderedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - (n : ℕ) → Spin → PMF (OrderedObservation n) - | 0, i => PMF.pure i - | n+1, i => offspring.bind (fun k => - (iidVector ((channelPMF lam h i).bind (orderedLaw offspring lam h n)) k).map (Sigma.mk k)) - -def forgetOrder : (n : ℕ) → OrderedObservation n → Observation n - | 0, i => i - | n+1, ⟨k,v⟩ => (List.ofFn (fun j : Fin k => forgetOrder n (v j)) : Multiset (Observation n)) - -lemma orderedLaw_forget (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : - (orderedLaw offspring lam h n i).map (forgetOrder n) = observedLaw offspring lam h n i := by - induction n generalizing i with - | zero => - change (PMF.pure i).map id = PMF.pure i - exact PMF.map_id _ - | succ n ih => - simp only [orderedLaw, observedLaw, PMF.map_bind, PMF.map_comp] - apply congrArg (PMF.bind offspring) - funext k - let p := (channelPMF lam h i).bind (orderedLaw offspring lam h n) - change (iidVector p k).map - ((fun xs : List (Observation n) => (xs : Multiset (Observation n))) ∘ List.ofFn ∘ - (fun v => forgetOrder n ∘ v)) = _ - rw [← PMF.map_comp, ← PMF.map_comp, iidVector_map, iidVector_ofFn] - congr 2 - rw [PMF.map_bind] - congr 1 - funext j - exact ih j - -lemma orderedAdvantage_dominates (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : - advantage (observedLaw offspring lam h n) ≤ advantage (orderedLaw offspring lam h n) := by - have hh := advantage_bind_le (orderedLaw offspring lam h n) (fun y => PMF.pure (forgetOrder n y)) - have he : (fun i => (orderedLaw offspring lam h n i).bind (fun y => PMF.pure (forgetOrder n y))) = - observedLaw offspring lam h n := by - funext i - exact orderedLaw_forget offspring lam h n i - rw [he] at hh - exact hh - -end ThreeState - -namespace ThreeState - -noncomputable def vectorTraverse {α β : Type*} (k : α → PMF β) : - (n : ℕ) → (Fin n → α) → PMF (Fin n → β) - | 0, _ => PMF.pure Fin.elim0 - | n+1, v => (k (v 0)).bind (fun b => (vectorTraverse k n (Fin.tail v)).map (Fin.cons b)) - -lemma vectorTraverse_cons {α β : Type*} (k : α → PMF β) (n : ℕ) (a : α) (v : Fin n → α) : - vectorTraverse k (n+1) (Fin.cons a v) = - (k a).bind (fun b => (vectorTraverse k n v).map (Fin.cons b)) := by - simp only [vectorTraverse, Fin.cons_zero, Fin.tail_cons] - -lemma iidVector_bind_traverse {α β : Type*} (p : PMF α) (k : α → PMF β) (n : ℕ) : - (iidVector p n).bind (vectorTraverse k n) = iidVector (p.bind k) n := by - induction n with - | zero => simp only [iidVector, PMF.pure_bind, vectorTraverse] - | succ n ih => - simp only [iidVector, PMF.bind_bind, PMF.bind_map, Function.comp_def, vectorTraverse_cons] - apply congrArg (PMF.bind p) - funext a - rw [PMF.bind_comm] - apply congrArg (PMF.bind (k a)) - funext b - rw [← PMF.map_bind, ih] - -noncomputable def orderedGrow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - (n : ℕ) → OrderedObservation n → PMF (OrderedObservation (n+1)) - | 0 => orderedLaw offspring lam h 1 - | n+1 => fun ⟨k,v⟩ => (vectorTraverse (orderedGrow offspring lam h n) k v).map (Sigma.mk k) - -lemma orderedLaw_grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : - (orderedLaw offspring lam h n i).bind (orderedGrow offspring lam h n) = - orderedLaw offspring lam h (n+1) i := by - induction n generalizing i with - | zero => exact PMF.pure_bind i _ - | succ n ih => - simp only [orderedLaw, orderedGrow, PMF.bind_bind, PMF.bind_map, Function.comp_def] - apply congrArg (PMF.bind offspring) - funext k - rw [← PMF.map_bind, iidVector_bind_traverse, PMF.bind_bind] - have he : (fun j => (orderedLaw offspring lam h n j).bind (orderedGrow offspring lam h n)) = - orderedLaw offspring lam h (n+1) := funext ih - rw [he] - rfl - -lemma ordered_likelihood_common_subsequence (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - ∃ Q : MeasureTheory.ProbabilityMeasure Message, ∃ φ : ℕ → ℕ, StrictMono φ ∧ - Filter.Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) Filter.atTop (nhds Q) ∧ - Filter.Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n+1))) Filter.atTop (nhds Q) := by - exact likelihood_common_subsequence (orderedLaw offspring lam h) (orderedGrow offspring lam h) - (fun n i => (orderedLaw_grow offspring lam h n i).symm) - -end ThreeState -universe u -namespace ThreeState - -instance pmfCommApplicative : CommApplicative PMF where - commutative_prod a b := by - change ((a.map Prod.mk).bind (fun f => b.map f)) = - ((b.map (fun y x => (x,y))).bind (fun f => a.map f)) - simp only [PMF.map, PMF.bind_bind, PMF.pure_bind, Function.comp_def] - exact PMF.bind_comm a b (fun x y => PMF.pure (x,y)) - -lemma list_traverse_nil {α β : Type u} (k : α → PMF β) : - Traversable.traverse k [] = PMF.pure [] := rfl - -lemma list_traverse_cons {α β : Type u} (k : α → PMF β) (a : α) (as : List α) : - Traversable.traverse k (a::as) = (k a).bind (fun b => (Traversable.traverse k as).map (List.cons b)) := by - rw [List.traverse_cons, seq_eq_bind_map] - change ((k a).map List.cons).bind _ = _ - rw [PMF.bind_map] - rfl - -lemma multiset_traverse_list {α β : Type u} (k : α → PMF β) (as : List α) : - Multiset.traverse k (as : Multiset α) = - (Traversable.traverse k as).map (fun bs : List β => (bs : Multiset β)) := rfl - -lemma iidList_bind_traverse {α β : Type u} (p : PMF α) (k : α → PMF β) (n : ℕ) : - (iidList p n).bind (Traversable.traverse k) = iidList (p.bind k) n := by - induction n with - | zero => simp only [iidList, PMF.pure_bind, list_traverse_nil] - | succ n ih => - simp only [iidList, PMF.bind_bind, PMF.bind_map, Function.comp_def, list_traverse_cons] - apply congrArg (PMF.bind p) - funext a - rw [PMF.bind_comm] - apply congrArg (PMF.bind (k a)) - funext b - rw [← PMF.map_bind, ih] - -lemma iidList_multiset_bind {α β : Type u} (p : PMF α) (k : α → PMF β) (n : ℕ) : - ((iidList p n).map (fun as : List α => (as : Multiset α))).bind (Multiset.traverse k) = - (iidList (p.bind k) n).map (fun bs : List β => (bs : Multiset β)) := by - rw [PMF.bind_map] - change (iidList p n).bind (fun as => ((Traversable.traverse k as).map (fun bs : List β => (bs : Multiset β)))) = _ - rw [← PMF.map_bind, iidList_bind_traverse] - - - -noncomputable def grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - (n : ℕ) → Observation n → PMF (Observation (n+1)) - | 0 => observedLaw offspring lam h 1 - | n+1 => Multiset.traverse (grow offspring lam h n) - - -theorem observedLaw_grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (n : ℕ) (i : Spin) : - (observedLaw offspring lam h n i).bind (grow offspring lam h n) = - observedLaw offspring lam h (n+1) i := by - induction n generalizing i with - | zero => exact PMF.pure_bind i _ - | succ n ih => - change (offspring.bind (fun k => - (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h n)) k).map - (fun xs : List (Observation n) => (xs : Multiset (Observation n))))).bind - (Multiset.traverse (grow offspring lam h n)) = - offspring.bind (fun k => - (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h (n+1))) k).map - (fun xs : List (Observation (n+1)) => (xs : Multiset (Observation (n+1))))) - rw [PMF.bind_bind] - apply congrArg (PMF.bind offspring) - funext k - rw [iidList_multiset_bind, PMF.bind_bind] - have he : (fun j => (observedLaw offspring lam h n j).bind (grow offspring lam h n)) = - observedLaw offspring lam h (n+1) := funext ih - rw [he] - - -theorem observedAdvantage_antitone (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - Antitone (fun n => advantage (observedLaw offspring lam h n)) := by - apply antitone_nat_of_succ_le - intro n - have he : observedLaw offspring lam h (n+1) = - fun i => (observedLaw offspring lam h n i).bind (grow offspring lam h n) := by - funext i - exact (observedLaw_grow offspring lam h n i).symm - rw [he] - exact advantage_bind_le _ _ - - -theorem observedAdvantage_tendsto (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - ∃ L : ℝ, 0 ≤ L ∧ L ≤ 1 ∧ - Filter.Tendsto (fun n => advantage (observedLaw offspring lam h n)) - Filter.atTop (nhds L) := by - let a := fun n => advantage (observedLaw offspring lam h n) - have hb : BddBelow (Set.range a) := ⟨0, by rintro x ⟨n,rfl⟩; exact advantage_nonneg _⟩ - refine ⟨⨅ n, a n, ?_, ?_, tendsto_atTop_ciInf (observedAdvantage_antitone offspring lam h) hb⟩ - · exact le_ciInf (fun n => advantage_nonneg _) - · exact (ciInf_le hb 0).trans (advantage_le_one _) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Messages + +namespace OAI + +/-! Ordered and unlabelled boundary observations and information degradation. -/ + +namespace ThreeState + + + +noncomputable def iidVector {α : Type*} (p : PMF α) : (n : ℕ) → PMF (Fin n → α) + | 0 => PMF.pure Fin.elim0 + | n+1 => p.bind (fun a => (iidVector p n).map (Fin.cons a)) + +lemma iidVector_map {α β : Type*} (p : PMF α) (f : α → β) (n : ℕ) : + (iidVector p n).map (fun as => f ∘ as) = iidVector (p.map f) n := by + induction n with + | zero => + simp only [iidVector, PMF.pure_map] + congr 1 + funext i + exact Fin.elim0 i + | succ n ih => + simp only [iidVector, PMF.map_bind, PMF.map_comp, PMF.bind_map] + apply congrArg (PMF.bind p) + funext a + rw [← ih] + dsimp only [Function.comp_def] + rw [PMF.map_comp] + congr 1 + funext v j + cases j using Fin.cases <;> simp + +lemma iidVector_ofFn {α : Type*} (p : PMF α) (n : ℕ) : + (iidVector p n).map List.ofFn = iidList p n := by + induction n with + | zero => simp [iidVector, iidList, PMF.pure_map] + | succ n ih => + simp only [iidVector, iidList, PMF.map_bind, PMF.map_comp] + apply congrArg (PMF.bind p) + funext a + rw [← ih, PMF.map_comp] + congr 1 + funext v + simp [List.ofFn_succ] + +lemma iidVector_apply {α : Type*} (p : PMF α) (n : ℕ) (v : Fin n → α) : + iidVector p n v = ∏ j, p (v j) := by + classical + induction n with + | zero => + have he : v = Fin.elim0 := by funext j; exact Fin.elim0 j + simp [iidVector, he] + | succ n ih => + simp only [iidVector, PMF.bind_apply, PMF.map_apply] + have he (a : α) (w : Fin n → α) : (v = Fin.cons a w) ↔ (a=v 0 ∧ w=Fin.tail v) := by + constructor + · intro h + subst v + simp + · rintro ⟨rfl,rfl⟩ + exact (Fin.cons_self_tail v).symm + simp_rw [he] + simp only [ite_and] + rw [tsum_eq_single (v 0)] + · simp [ih, Fin.prod_univ_succ, Fin.tail] + · intro a ha + simp [ha] + + +abbrev OrderedObservation : ℕ → Type + | 0 => Spin + | n+1 => Σ k : ℕ, Fin k → OrderedObservation n + +noncomputable def orderedLaw (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + (n : ℕ) → Spin → PMF (OrderedObservation n) + | 0, i => PMF.pure i + | n+1, i => offspring.bind (fun k => + (iidVector ((channelPMF lam h i).bind (orderedLaw offspring lam h n)) k).map (Sigma.mk k)) + +def forgetOrder : (n : ℕ) → OrderedObservation n → Observation n + | 0, i => i + | n+1, ⟨k,v⟩ => (List.ofFn (fun j : Fin k => forgetOrder n (v j)) : Multiset (Observation n)) + +lemma orderedLaw_forget (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : + (orderedLaw offspring lam h n i).map (forgetOrder n) = observedLaw offspring lam h n i := by + induction n generalizing i with + | zero => + change (PMF.pure i).map id = PMF.pure i + exact PMF.map_id _ + | succ n ih => + simp only [orderedLaw, observedLaw, PMF.map_bind, PMF.map_comp] + apply congrArg (PMF.bind offspring) + funext k + let p := (channelPMF lam h i).bind (orderedLaw offspring lam h n) + change (iidVector p k).map + ((fun xs : List (Observation n) => (xs : Multiset (Observation n))) ∘ List.ofFn ∘ + (fun v => forgetOrder n ∘ v)) = _ + rw [← PMF.map_comp, ← PMF.map_comp, iidVector_map, iidVector_ofFn] + congr 2 + rw [PMF.map_bind] + congr 1 + funext j + exact ih j + +lemma orderedAdvantage_dominates (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) : + advantage (observedLaw offspring lam h n) ≤ advantage (orderedLaw offspring lam h n) := by + have hh := advantage_bind_le (orderedLaw offspring lam h n) (fun y => PMF.pure (forgetOrder n y)) + have he : (fun i => (orderedLaw offspring lam h n i).bind (fun y => PMF.pure (forgetOrder n y))) = + observedLaw offspring lam h n := by + funext i + exact orderedLaw_forget offspring lam h n i + rw [he] at hh + exact hh + +end ThreeState + +namespace ThreeState + +noncomputable def vectorTraverse {α β : Type*} (k : α → PMF β) : + (n : ℕ) → (Fin n → α) → PMF (Fin n → β) + | 0, _ => PMF.pure Fin.elim0 + | n+1, v => (k (v 0)).bind (fun b => (vectorTraverse k n (Fin.tail v)).map (Fin.cons b)) + +lemma vectorTraverse_cons {α β : Type*} (k : α → PMF β) (n : ℕ) (a : α) (v : Fin n → α) : + vectorTraverse k (n+1) (Fin.cons a v) = + (k a).bind (fun b => (vectorTraverse k n v).map (Fin.cons b)) := by + simp only [vectorTraverse, Fin.cons_zero, Fin.tail_cons] + +lemma iidVector_bind_traverse {α β : Type*} (p : PMF α) (k : α → PMF β) (n : ℕ) : + (iidVector p n).bind (vectorTraverse k n) = iidVector (p.bind k) n := by + induction n with + | zero => simp only [iidVector, PMF.pure_bind, vectorTraverse] + | succ n ih => + simp only [iidVector, PMF.bind_bind, PMF.bind_map, Function.comp_def, vectorTraverse_cons] + apply congrArg (PMF.bind p) + funext a + rw [PMF.bind_comm] + apply congrArg (PMF.bind (k a)) + funext b + rw [← PMF.map_bind, ih] + +noncomputable def orderedGrow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + (n : ℕ) → OrderedObservation n → PMF (OrderedObservation (n+1)) + | 0 => orderedLaw offspring lam h 1 + | n+1 => fun ⟨k,v⟩ => (vectorTraverse (orderedGrow offspring lam h n) k v).map (Sigma.mk k) + +lemma orderedLaw_grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : + (orderedLaw offspring lam h n i).bind (orderedGrow offspring lam h n) = + orderedLaw offspring lam h (n+1) i := by + induction n generalizing i with + | zero => exact PMF.pure_bind i _ + | succ n ih => + simp only [orderedLaw, orderedGrow, PMF.bind_bind, PMF.bind_map, Function.comp_def] + apply congrArg (PMF.bind offspring) + funext k + rw [← PMF.map_bind, iidVector_bind_traverse, PMF.bind_bind] + have he : (fun j => (orderedLaw offspring lam h n j).bind (orderedGrow offspring lam h n)) = + orderedLaw offspring lam h (n+1) := funext ih + rw [he] + rfl + +lemma ordered_likelihood_common_subsequence (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + ∃ Q : MeasureTheory.ProbabilityMeasure Message, ∃ φ : ℕ → ℕ, StrictMono φ ∧ + Filter.Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) Filter.atTop (nhds Q) ∧ + Filter.Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n+1))) Filter.atTop (nhds Q) := by + exact likelihood_common_subsequence (orderedLaw offspring lam h) (orderedGrow offspring lam h) + (fun n i => (orderedLaw_grow offspring lam h n i).symm) + +end ThreeState +universe u +namespace ThreeState + +instance pmfCommApplicative : CommApplicative PMF where + commutative_prod a b := by + change ((a.map Prod.mk).bind (fun f => b.map f)) = + ((b.map (fun y x => (x,y))).bind (fun f => a.map f)) + simp only [PMF.map, PMF.bind_bind, PMF.pure_bind, Function.comp_def] + exact PMF.bind_comm a b (fun x y => PMF.pure (x,y)) + +lemma list_traverse_nil {α β : Type u} (k : α → PMF β) : + Traversable.traverse k [] = PMF.pure [] := rfl + +lemma list_traverse_cons {α β : Type u} (k : α → PMF β) (a : α) (as : List α) : + Traversable.traverse k (a::as) = (k a).bind (fun b => (Traversable.traverse k as).map (List.cons b)) := by + rw [List.traverse_cons, seq_eq_bind_map] + change ((k a).map List.cons).bind _ = _ + rw [PMF.bind_map] + rfl + +lemma multiset_traverse_list {α β : Type u} (k : α → PMF β) (as : List α) : + Multiset.traverse k (as : Multiset α) = + (Traversable.traverse k as).map (fun bs : List β => (bs : Multiset β)) := rfl + +lemma iidList_bind_traverse {α β : Type u} (p : PMF α) (k : α → PMF β) (n : ℕ) : + (iidList p n).bind (Traversable.traverse k) = iidList (p.bind k) n := by + induction n with + | zero => simp only [iidList, PMF.pure_bind, list_traverse_nil] + | succ n ih => + simp only [iidList, PMF.bind_bind, PMF.bind_map, Function.comp_def, list_traverse_cons] + apply congrArg (PMF.bind p) + funext a + rw [PMF.bind_comm] + apply congrArg (PMF.bind (k a)) + funext b + rw [← PMF.map_bind, ih] + +lemma iidList_multiset_bind {α β : Type u} (p : PMF α) (k : α → PMF β) (n : ℕ) : + ((iidList p n).map (fun as : List α => (as : Multiset α))).bind (Multiset.traverse k) = + (iidList (p.bind k) n).map (fun bs : List β => (bs : Multiset β)) := by + rw [PMF.bind_map] + change (iidList p n).bind (fun as => ((Traversable.traverse k as).map (fun bs : List β => (bs : Multiset β)))) = _ + rw [← PMF.map_bind, iidList_bind_traverse] + + + +noncomputable def grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + (n : ℕ) → Observation n → PMF (Observation (n+1)) + | 0 => observedLaw offspring lam h 1 + | n+1 => Multiset.traverse (grow offspring lam h n) + + +theorem observedLaw_grow (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (n : ℕ) (i : Spin) : + (observedLaw offspring lam h n i).bind (grow offspring lam h n) = + observedLaw offspring lam h (n+1) i := by + induction n generalizing i with + | zero => exact PMF.pure_bind i _ + | succ n ih => + change (offspring.bind (fun k => + (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h n)) k).map + (fun xs : List (Observation n) => (xs : Multiset (Observation n))))).bind + (Multiset.traverse (grow offspring lam h n)) = + offspring.bind (fun k => + (iidList ((channelPMF lam h i).bind (observedLaw offspring lam h (n+1))) k).map + (fun xs : List (Observation (n+1)) => (xs : Multiset (Observation (n+1))))) + rw [PMF.bind_bind] + apply congrArg (PMF.bind offspring) + funext k + rw [iidList_multiset_bind, PMF.bind_bind] + have he : (fun j => (observedLaw offspring lam h n j).bind (grow offspring lam h n)) = + observedLaw offspring lam h (n+1) := funext ih + rw [he] + + +theorem observedAdvantage_antitone (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + Antitone (fun n => advantage (observedLaw offspring lam h n)) := by + apply antitone_nat_of_succ_le + intro n + have he : observedLaw offspring lam h (n+1) = + fun i => (observedLaw offspring lam h n i).bind (grow offspring lam h n) := by + funext i + exact (observedLaw_grow offspring lam h n i).symm + rw [he] + exact advantage_bind_le _ _ + + +theorem observedAdvantage_tendsto (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + ∃ L : ℝ, 0 ≤ L ∧ L ≤ 1 ∧ + Filter.Tendsto (fun n => advantage (observedLaw offspring lam h n)) + Filter.atTop (nhds L) := by + let a := fun n => advantage (observedLaw offspring lam h n) + have hb : BddBelow (Set.range a) := ⟨0, by rintro x ⟨n,rfl⟩; exact advantage_nonneg _⟩ + refine ⟨⨅ n, a n, ?_, ?_, tendsto_atTop_ciInf (observedAdvantage_antitone offspring lam h) hb⟩ + · exact le_ciInf (fun n => advantage_nonneg _) + · exact (ciInf_le hb 0).trans (advantage_le_one _) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/PairCorrelation.lean b/lean/OAI/Probability/ThreeState/PairCorrelation.lean index c4af19d3aec030746acdf0ee65bfaac3042233d3..9a6a3ab5040761023b748a02cc2cd884d23729e9 100644 --- a/lean/OAI/Probability/ThreeState/PairCorrelation.lean +++ b/lean/OAI/Probability/ThreeState/PairCorrelation.lean @@ -1,258 +1,258 @@ -import Mathlib -import OAI.Probability.ThreeState.PosteriorMoments - -namespace OAI - -/-! Two-message correlation and quantitative entropy increments. -/ - -namespace ThreeState -open Set - -lemma log_correlation_cubic (a : ℝ) (ha : 0 < a) : - (a-1)+(a-1)^2/2-(a-1)^3/6 ≤ a*Real.log a := by - let f : ℝ → ℝ := fun x => x*Real.log x-((x-1)+(x-1)^2/2-(x-1)^3/6) - let g : ℝ → ℝ := fun x => Real.log x-(x-1)+(x-1)^2/2 - have hd (x : ℝ) (hx : 0 < x) : HasDerivAt f (g x) x := by - have hh := ((hasDerivAt_id x).mul (Real.hasDerivAt_log hx.ne')).sub - ((((hasDerivAt_id x).sub_const 1).add (((hasDerivAt_id x).sub_const 1).pow 2 |>.div_const 2)).sub - (((hasDerivAt_id x).sub_const 1).pow 3 |>.div_const 6)) - convert hh using 1 <;> first | rfl | (dsimp only [g, id]; field_simp; ring) - have hdg (x : ℝ) (hx : 0 < x) : HasDerivAt g ((x-1)^2/x) x := by - have hh := ((Real.hasDerivAt_log hx.ne').sub ((hasDerivAt_id x).sub_const 1)).add - (((hasDerivAt_id x).sub_const 1).pow 2 |>.div_const 2) - convert hh using 1 <;> first | rfl | (simp only [id_eq]; field_simp; ring) - have hconv : ConvexOn ℝ (Ioi 0) f := by - apply convexOn_of_hasDerivWithinAt2_nonneg (f' := g) (f'' := fun x => (x-1)^2/x) (convex_Ioi 0) - · exact fun x hx => (hd x hx).continuousAt.continuousWithinAt - · intro x hx - rw [interior_Ioi] at hx - exact (hd x hx).hasDerivWithinAt - · intro x hx - rw [interior_Ioi] at hx - exact (hdg x hx).hasDerivWithinAt - · intro x hx - rw [interior_Ioi] at hx - exact div_nonneg (sq_nonneg _) hx.le - have hf1 : f 1 = 0 := by simp [f] - have hg1 : g 1 = 0 := by simp [g] - have hf0 : 0 ≤ f a := by - rcases lt_trichotomy a 1 with hl | he | hg - · have hh := hconv.slope_le_of_hasDerivAt ha (by norm_num : (1:ℝ) ∈ Ioi 0) hl (hd 1 (by norm_num)) - rw [hg1, slope_def_field, hf1] at hh - have hp := (div_le_iff₀ (sub_pos.mpr hl)).mp hh - linarith - · simp [he, hf1] - · have hh := hconv.le_slope_of_hasDerivAt (by norm_num : (1:ℝ) ∈ Ioi 0) ha hg (hd 1 (by norm_num)) - rw [hg1, slope_def_field, hf1] at hh - have hp := (le_div_iff₀ (sub_pos.mpr hg)).mp hh - linarith - dsimp only [f] at hf0 - linarith - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -noncomputable def correlationZ (a b : Message) : ℝ := avg (fun i => messageDeviation a i * messageDeviation b i) -lemma continuous_correlationZ : Continuous (fun p : Message × Message => correlationZ p.1 p.2) := by - apply continuous_avg - intro i - exact ((((continuous_apply i).comp continuous_subtype_val).comp continuous_fst).sub continuous_const).mul - ((((continuous_apply i).comp continuous_subtype_val).comp continuous_snd).sub continuous_const) - -noncomputable def symPerm : Fin 6 → Equiv.Perm Spin := - ![Equiv.refl _, Equiv.swap 0 1, Equiv.swap 0 2, Equiv.swap 1 2, - (Equiv.swap 0 1).trans (Equiv.swap 1 2), (Equiv.swap 1 2).trans (Equiv.swap 0 1)] -noncomputable def symAvg (f : Message → ℝ) (m : Message) : ℝ := - (∑ i : Fin 6, f (permMessage (symPerm i) m))/6 - -lemma integral_symAvg (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) - (f : Message → ℝ) (hf : Continuous f) : - (∫ m, symAvg f m ∂(Q : Measure Message)) = ∫ m, f m ∂(Q : Measure Message) := by - simp only [symAvg, integral_div] - have hi (i : Fin 6) : Integrable (fun m => f (permMessage (symPerm i) m)) (Q : Measure Message) := - integrable_continuous_message Q (hf.comp (continuous_permMessage _)) - rw [integral_finsetSum _ (fun i _ => hi i)] - simp only [integral_permMessage Q hs _ _ hf.measurable] - simp - -lemma symAvg_correlationZ (a b : Message) : symAvg (fun m => correlationZ m b) a = 0 := by - have ha := average_message a - have hb := average_message b - simp only [Radial.avg_expand] at ha hb - have ha2 : a 2 = 3-a 0-a 1 := by linarith - have hb2 : b 2 = 3-b 0-b 1 := by linarith - norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, - Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff] - rw [ha2, hb2] - ring - -lemma symAvg_correlationZ_sq (a b : Message) : - symAvg (fun m => (correlationZ m b)^2) a = 2*messageX a*messageX b := by - have ha := average_message a - have hb := average_message b - simp only [Radial.avg_expand] at ha hb - have ha2 : a 2 = 3-a 0-a 1 := by linarith - have hb2 : b 2 = 3-b 0-b 1 := by linarith - norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, - Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff, - messageX, Radial.momentX] - rw [ha2, hb2] - ring - -lemma symAvg_correlationZ_cube (a b : Message) : - symAvg (fun m => (correlationZ m b)^3) a = 2*messageY a*messageY b := by - have ha := average_message a - have hb := average_message b - simp only [Radial.avg_expand] at ha hb - have ha2 : a 2 = 3-a 0-a 1 := by linarith - have hb2 : b 2 = 3-b 0-b 1 := by linarith - norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, - Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff, - messageY, Radial.momentY] - rw [ha2, hb2] - ring - -lemma integral_correlationZ (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : - (∫ m, correlationZ m b ∂(Q : Measure Message)) = 0 := by - rw [← integral_symAvg Q hs (fun m => correlationZ m b) (continuous_correlationZ.comp (continuous_id.prodMk continuous_const))] - simp only [symAvg_correlationZ, integral_zero] - -lemma integral_correlationZ_sq (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : - (∫ m, (correlationZ m b)^2 ∂(Q : Measure Message)) = 2*posteriorMu Q*messageX b := by - rw [← integral_symAvg Q hs (fun m => (correlationZ m b)^2) ((continuous_correlationZ.comp (continuous_id.prodMk continuous_const)).pow 2)] - simp only [symAvg_correlationZ_sq, integral_mul_const, integral_const_mul, posteriorMu] - -lemma integral_correlationZ_cube (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : - (∫ m, (correlationZ m b)^3 ∂(Q : Measure Message)) = 2*posteriorEta Q*messageY b := by - rw [← integral_symAvg Q hs (fun m => (correlationZ m b)^3) ((continuous_correlationZ.comp (continuous_id.prodMk continuous_const)).pow 3)] - simp only [symAvg_correlationZ_cube, integral_mul_const, integral_const_mul, posteriorEta] - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma correlationZ_comm (a b : Message) : correlationZ a b = correlationZ b a := by - simp [correlationZ, mul_comm] - -noncomputable def pairNormalizer (lam : ℝ) (h : Admissible lam) (a b : Message) : ℝ := - avg (fun i => a i*edgeMessage lam h b i) - -lemma pairNormalizer_eq (lam : ℝ) (h : Admissible lam) (a b : Message) : - pairNormalizer lam h a b = 1+lam*correlationZ a b := by - have ha := average_message a - have hb := average_message b - simp only [Radial.avg_expand] at ha hb - simp only [pairNormalizer, correlationZ, messageDeviation, edgeMessage, Radial.avg_expand] - rw [message_last a, message_last b] - ring - -lemma continuous_pairNormalizer (lam : ℝ) (h : Admissible lam) : - Continuous (fun p : Message × Message => pairNormalizer lam h p.1 p.2) := by - simp only [pairNormalizer_eq] - exact continuous_const.add (continuous_const.mul continuous_correlationZ) - -lemma pairNormalizer_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (a b : Message) : 0 < pairNormalizer lam h a b := by - have he (i : Spin) : (1-lam)*a i ≤ a i*edgeMessage lam h b i := by - nlinarith [mul_le_mul_of_nonneg_left (edgeMessage_bounds lam h hl0 b i).1 (Message.nonneg a i)] - have ha := average_message a - simp only [pairNormalizer, Radial.avg_expand] at * - nlinarith [he 0, he 1, he 2] - -noncomputable def pairMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (a b : Message) : Message := - ⟨fun i => a i*edgeMessage lam h b i/pairNormalizer lam h a b, by - constructor - · intro i - exact div_nonneg (mul_nonneg (Message.nonneg a i) (Message.nonneg _ _)) (pairNormalizer_pos lam h hl0 hl1 a b).le - · rw [← Finset.sum_div] - change (∑ i, a i*edgeMessage lam h b i)/((∑ i, a i*edgeMessage lam h b i)/3) = 3 - have hh := ne_of_gt (pairNormalizer_pos lam h hl0 hl1 a b) - dsimp only [pairNormalizer, avg] at hh - have hs : (∑ i, a i*edgeMessage lam h b i) ≠ 0 := by - intro he - apply hh - rw [he] - norm_num - field_simp [hs]⟩ - -lemma continuous_pairMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun p : Message × Message => pairMessage lam h hl0 hl1 p.1 p.2) := by - apply Continuous.subtype_mk - apply continuous_pi - intro i - exact ((((continuous_apply i).comp continuous_subtype_val).comp continuous_fst).mul - (((continuous_apply i).comp continuous_subtype_val).comp ((continuous_edgeMessage lam h).comp continuous_snd))).div - (continuous_pairNormalizer lam h) (fun p => ne_of_gt (pairNormalizer_pos lam h hl0 hl1 p.1 p.2)) - -lemma integral_pairNormalizer (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (a : Message) : - (∫ b, pairNormalizer lam h a b ∂(Q : Measure Message)) = 1 := by - change (∫ b, avg (fun i => a i*edgeMessage lam h b i) ∂(Q : Measure Message)) = 1 - rw [integral_avg] - · simp only [integral_const_mul, integral_edgeMessage lam h Q hQ, mul_one] - exact average_message a - · intro i - exact integrable_continuous_message Q (continuous_const.mul (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h))) - -noncomputable def pairIncrement (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (a : Message) : ℝ := - ∫ b, pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) ∂(Q : Measure Message) - -lemma continuous_pairIntegrand (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun p : Message × Message => pairNormalizer lam h p.1 p.2*Real.log (pairNormalizer lam h p.1 p.2)) := - (continuous_pairNormalizer lam h).mul ((continuous_pairNormalizer lam h).log - (fun p => ne_of_gt (pairNormalizer_pos lam h hl0 hl1 p.1 p.2))) - -lemma pairIncrement_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) : 0 ≤ pairIncrement lam h Q a := by - have hf : Continuous (fun b => pairNormalizer lam h a b) := - (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) - have hg : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := - (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) - have hin (b : Message) : pairNormalizer lam h a b-1 ≤ pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) := by - have hp := pairNormalizer_pos lam h hl0 hl1 a b - have hh := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le - rw [mul_sub, mul_one, mul_inv_cancel₀ hp.ne'] at hh - exact hh - have hif : Integrable (fun b => pairNormalizer lam h a b-1) (Q : Measure Message) := - integrable_continuous_message Q (hf.sub continuous_const) - have hh := integral_mono hif (integrable_continuous_message Q hg) hin - rw [integral_sub (integrable_continuous_message Q hf) (integrable_const 1), integral_pairNormalizer lam h Q hQ] at hh - simpa [pairIncrement] using hh - -lemma pairIncrement_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (a : Message) : - lam^2*posteriorMu Q*messageX a-lam^3*posteriorEta Q*messageY a/3 ≤ pairIncrement lam h Q a := by - let z : Message → ℝ := fun b => correlationZ b a - have hz : Continuous z := continuous_correlationZ.comp (continuous_id.prodMk continuous_const) - have h1 : (∫ b, z b ∂(Q : Measure Message)) = 0 := integral_correlationZ Q hs a - have h2 : (∫ b, (z b)^2 ∂(Q : Measure Message)) = 2*posteriorMu Q*messageX a := integral_correlationZ_sq Q hs a - have h3 : (∫ b, (z b)^3 ∂(Q : Measure Message)) = 2*posteriorEta Q*messageY a := integral_correlationZ_cube Q hs a - have hin (b : Message) : lam*z b+lam^2*(z b)^2/2-lam^3*(z b)^3/6 ≤ pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) := by - have hh := log_correlation_cubic _ (pairNormalizer_pos lam h hl0 hl1 a b) - rw [pairNormalizer_eq, correlationZ_comm a b] at hh ⊢ - dsimp only [z] - convert hh using 1 - ring - have hf : Continuous (fun b => lam*z b+lam^2*(z b)^2/2-lam^3*(z b)^3/6) := by fun_prop - have hg : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := - (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) - have hh := integral_mono (integrable_continuous_message Q hf) (integrable_continuous_message Q hg) hin - have hi1 := integrable_continuous_message Q hz - have hi2 : Integrable (fun b => (z b)^2) (Q : Measure Message) := integrable_continuous_message Q (hz.pow 2) - have hi3 : Integrable (fun b => (z b)^3) (Q : Measure Message) := integrable_continuous_message Q (hz.pow 3) - have hiadd : Integrable (fun b => lam*z b+lam^2*(z b)^2/2) (Q : Measure Message) := - (hi1.const_mul _).add ((hi2.const_mul _).div_const _) - rw [integral_sub hiadd ((hi3.const_mul _).div_const _), integral_add (hi1.const_mul _) ((hi2.const_mul _).div_const _), - integral_div, integral_div, integral_const_mul, integral_const_mul, integral_const_mul, h1,h2,h3] at hh - dsimp only [pairIncrement] - linarith - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.PosteriorMoments + +namespace OAI + +/-! Two-message correlation and quantitative entropy increments. -/ + +namespace ThreeState +open Set + +lemma log_correlation_cubic (a : ℝ) (ha : 0 < a) : + (a-1)+(a-1)^2/2-(a-1)^3/6 ≤ a*Real.log a := by + let f : ℝ → ℝ := fun x => x*Real.log x-((x-1)+(x-1)^2/2-(x-1)^3/6) + let g : ℝ → ℝ := fun x => Real.log x-(x-1)+(x-1)^2/2 + have hd (x : ℝ) (hx : 0 < x) : HasDerivAt f (g x) x := by + have hh := ((hasDerivAt_id x).mul (Real.hasDerivAt_log hx.ne')).sub + ((((hasDerivAt_id x).sub_const 1).add (((hasDerivAt_id x).sub_const 1).pow 2 |>.div_const 2)).sub + (((hasDerivAt_id x).sub_const 1).pow 3 |>.div_const 6)) + convert hh using 1 <;> first | rfl | (dsimp only [g, id]; field_simp; ring) + have hdg (x : ℝ) (hx : 0 < x) : HasDerivAt g ((x-1)^2/x) x := by + have hh := ((Real.hasDerivAt_log hx.ne').sub ((hasDerivAt_id x).sub_const 1)).add + (((hasDerivAt_id x).sub_const 1).pow 2 |>.div_const 2) + convert hh using 1 <;> first | rfl | (simp only [id_eq]; field_simp; ring) + have hconv : ConvexOn ℝ (Ioi 0) f := by + apply convexOn_of_hasDerivWithinAt2_nonneg (f' := g) (f'' := fun x => (x-1)^2/x) (convex_Ioi 0) + · exact fun x hx => (hd x hx).continuousAt.continuousWithinAt + · intro x hx + rw [interior_Ioi] at hx + exact (hd x hx).hasDerivWithinAt + · intro x hx + rw [interior_Ioi] at hx + exact (hdg x hx).hasDerivWithinAt + · intro x hx + rw [interior_Ioi] at hx + exact div_nonneg (sq_nonneg _) hx.le + have hf1 : f 1 = 0 := by simp [f] + have hg1 : g 1 = 0 := by simp [g] + have hf0 : 0 ≤ f a := by + rcases lt_trichotomy a 1 with hl | he | hg + · have hh := hconv.slope_le_of_hasDerivAt ha (by norm_num : (1:ℝ) ∈ Ioi 0) hl (hd 1 (by norm_num)) + rw [hg1, slope_def_field, hf1] at hh + have hp := (div_le_iff₀ (sub_pos.mpr hl)).mp hh + linarith + · simp [he, hf1] + · have hh := hconv.le_slope_of_hasDerivAt (by norm_num : (1:ℝ) ∈ Ioi 0) ha hg (hd 1 (by norm_num)) + rw [hg1, slope_def_field, hf1] at hh + have hp := (le_div_iff₀ (sub_pos.mpr hg)).mp hh + linarith + dsimp only [f] at hf0 + linarith + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +noncomputable def correlationZ (a b : Message) : ℝ := avg (fun i => messageDeviation a i * messageDeviation b i) +lemma continuous_correlationZ : Continuous (fun p : Message × Message => correlationZ p.1 p.2) := by + apply continuous_avg + intro i + exact ((((continuous_apply i).comp continuous_subtype_val).comp continuous_fst).sub continuous_const).mul + ((((continuous_apply i).comp continuous_subtype_val).comp continuous_snd).sub continuous_const) + +noncomputable def symPerm : Fin 6 → Equiv.Perm Spin := + ![Equiv.refl _, Equiv.swap 0 1, Equiv.swap 0 2, Equiv.swap 1 2, + (Equiv.swap 0 1).trans (Equiv.swap 1 2), (Equiv.swap 1 2).trans (Equiv.swap 0 1)] +noncomputable def symAvg (f : Message → ℝ) (m : Message) : ℝ := + (∑ i : Fin 6, f (permMessage (symPerm i) m))/6 + +lemma integral_symAvg (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) + (f : Message → ℝ) (hf : Continuous f) : + (∫ m, symAvg f m ∂(Q : Measure Message)) = ∫ m, f m ∂(Q : Measure Message) := by + simp only [symAvg, integral_div] + have hi (i : Fin 6) : Integrable (fun m => f (permMessage (symPerm i) m)) (Q : Measure Message) := + integrable_continuous_message Q (hf.comp (continuous_permMessage _)) + rw [integral_finsetSum _ (fun i _ => hi i)] + simp only [integral_permMessage Q hs _ _ hf.measurable] + simp + +lemma symAvg_correlationZ (a b : Message) : symAvg (fun m => correlationZ m b) a = 0 := by + have ha := average_message a + have hb := average_message b + simp only [Radial.avg_expand] at ha hb + have ha2 : a 2 = 3-a 0-a 1 := by linarith + have hb2 : b 2 = 3-b 0-b 1 := by linarith + norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, + Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff] + rw [ha2, hb2] + ring + +lemma symAvg_correlationZ_sq (a b : Message) : + symAvg (fun m => (correlationZ m b)^2) a = 2*messageX a*messageX b := by + have ha := average_message a + have hb := average_message b + simp only [Radial.avg_expand] at ha hb + have ha2 : a 2 = 3-a 0-a 1 := by linarith + have hb2 : b 2 = 3-b 0-b 1 := by linarith + norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, + Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff, + messageX, Radial.momentX] + rw [ha2, hb2] + ring + +lemma symAvg_correlationZ_cube (a b : Message) : + symAvg (fun m => (correlationZ m b)^3) a = 2*messageY a*messageY b := by + have ha := average_message a + have hb := average_message b + simp only [Radial.avg_expand] at ha hb + have ha2 : a 2 = 3-a 0-a 1 := by linarith + have hb2 : b 2 = 3-b 0-b 1 := by linarith + norm_num [symAvg, symPerm, Fin.sum_univ_succ, correlationZ, messageDeviation, + Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, Equiv.symm_trans_apply, Fin.ext_iff, + messageY, Radial.momentY] + rw [ha2, hb2] + ring + +lemma integral_correlationZ (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : + (∫ m, correlationZ m b ∂(Q : Measure Message)) = 0 := by + rw [← integral_symAvg Q hs (fun m => correlationZ m b) (continuous_correlationZ.comp (continuous_id.prodMk continuous_const))] + simp only [symAvg_correlationZ, integral_zero] + +lemma integral_correlationZ_sq (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : + (∫ m, (correlationZ m b)^2 ∂(Q : Measure Message)) = 2*posteriorMu Q*messageX b := by + rw [← integral_symAvg Q hs (fun m => (correlationZ m b)^2) ((continuous_correlationZ.comp (continuous_id.prodMk continuous_const)).pow 2)] + simp only [symAvg_correlationZ_sq, integral_mul_const, integral_const_mul, posteriorMu] + +lemma integral_correlationZ_cube (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (b : Message) : + (∫ m, (correlationZ m b)^3 ∂(Q : Measure Message)) = 2*posteriorEta Q*messageY b := by + rw [← integral_symAvg Q hs (fun m => (correlationZ m b)^3) ((continuous_correlationZ.comp (continuous_id.prodMk continuous_const)).pow 3)] + simp only [symAvg_correlationZ_cube, integral_mul_const, integral_const_mul, posteriorEta] + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma correlationZ_comm (a b : Message) : correlationZ a b = correlationZ b a := by + simp [correlationZ, mul_comm] + +noncomputable def pairNormalizer (lam : ℝ) (h : Admissible lam) (a b : Message) : ℝ := + avg (fun i => a i*edgeMessage lam h b i) + +lemma pairNormalizer_eq (lam : ℝ) (h : Admissible lam) (a b : Message) : + pairNormalizer lam h a b = 1+lam*correlationZ a b := by + have ha := average_message a + have hb := average_message b + simp only [Radial.avg_expand] at ha hb + simp only [pairNormalizer, correlationZ, messageDeviation, edgeMessage, Radial.avg_expand] + rw [message_last a, message_last b] + ring + +lemma continuous_pairNormalizer (lam : ℝ) (h : Admissible lam) : + Continuous (fun p : Message × Message => pairNormalizer lam h p.1 p.2) := by + simp only [pairNormalizer_eq] + exact continuous_const.add (continuous_const.mul continuous_correlationZ) + +lemma pairNormalizer_pos (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (a b : Message) : 0 < pairNormalizer lam h a b := by + have he (i : Spin) : (1-lam)*a i ≤ a i*edgeMessage lam h b i := by + nlinarith [mul_le_mul_of_nonneg_left (edgeMessage_bounds lam h hl0 b i).1 (Message.nonneg a i)] + have ha := average_message a + simp only [pairNormalizer, Radial.avg_expand] at * + nlinarith [he 0, he 1, he 2] + +noncomputable def pairMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (a b : Message) : Message := + ⟨fun i => a i*edgeMessage lam h b i/pairNormalizer lam h a b, by + constructor + · intro i + exact div_nonneg (mul_nonneg (Message.nonneg a i) (Message.nonneg _ _)) (pairNormalizer_pos lam h hl0 hl1 a b).le + · rw [← Finset.sum_div] + change (∑ i, a i*edgeMessage lam h b i)/((∑ i, a i*edgeMessage lam h b i)/3) = 3 + have hh := ne_of_gt (pairNormalizer_pos lam h hl0 hl1 a b) + dsimp only [pairNormalizer, avg] at hh + have hs : (∑ i, a i*edgeMessage lam h b i) ≠ 0 := by + intro he + apply hh + rw [he] + norm_num + field_simp [hs]⟩ + +lemma continuous_pairMessage (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun p : Message × Message => pairMessage lam h hl0 hl1 p.1 p.2) := by + apply Continuous.subtype_mk + apply continuous_pi + intro i + exact ((((continuous_apply i).comp continuous_subtype_val).comp continuous_fst).mul + (((continuous_apply i).comp continuous_subtype_val).comp ((continuous_edgeMessage lam h).comp continuous_snd))).div + (continuous_pairNormalizer lam h) (fun p => ne_of_gt (pairNormalizer_pos lam h hl0 hl1 p.1 p.2)) + +lemma integral_pairNormalizer (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (a : Message) : + (∫ b, pairNormalizer lam h a b ∂(Q : Measure Message)) = 1 := by + change (∫ b, avg (fun i => a i*edgeMessage lam h b i) ∂(Q : Measure Message)) = 1 + rw [integral_avg] + · simp only [integral_const_mul, integral_edgeMessage lam h Q hQ, mul_one] + exact average_message a + · intro i + exact integrable_continuous_message Q (continuous_const.mul (((continuous_apply i).comp continuous_subtype_val).comp (continuous_edgeMessage lam h))) + +noncomputable def pairIncrement (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (a : Message) : ℝ := + ∫ b, pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) ∂(Q : Measure Message) + +lemma continuous_pairIntegrand (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun p : Message × Message => pairNormalizer lam h p.1 p.2*Real.log (pairNormalizer lam h p.1 p.2)) := + (continuous_pairNormalizer lam h).mul ((continuous_pairNormalizer lam h).log + (fun p => ne_of_gt (pairNormalizer_pos lam h hl0 hl1 p.1 p.2))) + +lemma pairIncrement_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (a : Message) : 0 ≤ pairIncrement lam h Q a := by + have hf : Continuous (fun b => pairNormalizer lam h a b) := + (continuous_pairNormalizer lam h).comp (continuous_const.prodMk continuous_id) + have hg : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := + (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) + have hin (b : Message) : pairNormalizer lam h a b-1 ≤ pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) := by + have hp := pairNormalizer_pos lam h hl0 hl1 a b + have hh := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le + rw [mul_sub, mul_one, mul_inv_cancel₀ hp.ne'] at hh + exact hh + have hif : Integrable (fun b => pairNormalizer lam h a b-1) (Q : Measure Message) := + integrable_continuous_message Q (hf.sub continuous_const) + have hh := integral_mono hif (integrable_continuous_message Q hg) hin + rw [integral_sub (integrable_continuous_message Q hf) (integrable_const 1), integral_pairNormalizer lam h Q hQ] at hh + simpa [pairIncrement] using hh + +lemma pairIncrement_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (a : Message) : + lam^2*posteriorMu Q*messageX a-lam^3*posteriorEta Q*messageY a/3 ≤ pairIncrement lam h Q a := by + let z : Message → ℝ := fun b => correlationZ b a + have hz : Continuous z := continuous_correlationZ.comp (continuous_id.prodMk continuous_const) + have h1 : (∫ b, z b ∂(Q : Measure Message)) = 0 := integral_correlationZ Q hs a + have h2 : (∫ b, (z b)^2 ∂(Q : Measure Message)) = 2*posteriorMu Q*messageX a := integral_correlationZ_sq Q hs a + have h3 : (∫ b, (z b)^3 ∂(Q : Measure Message)) = 2*posteriorEta Q*messageY a := integral_correlationZ_cube Q hs a + have hin (b : Message) : lam*z b+lam^2*(z b)^2/2-lam^3*(z b)^3/6 ≤ pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b) := by + have hh := log_correlation_cubic _ (pairNormalizer_pos lam h hl0 hl1 a b) + rw [pairNormalizer_eq, correlationZ_comm a b] at hh ⊢ + dsimp only [z] + convert hh using 1 + ring + have hf : Continuous (fun b => lam*z b+lam^2*(z b)^2/2-lam^3*(z b)^3/6) := by fun_prop + have hg : Continuous (fun b => pairNormalizer lam h a b*Real.log (pairNormalizer lam h a b)) := + (continuous_pairIntegrand lam h hl0 hl1).comp (continuous_const.prodMk continuous_id) + have hh := integral_mono (integrable_continuous_message Q hf) (integrable_continuous_message Q hg) hin + have hi1 := integrable_continuous_message Q hz + have hi2 : Integrable (fun b => (z b)^2) (Q : Measure Message) := integrable_continuous_message Q (hz.pow 2) + have hi3 : Integrable (fun b => (z b)^3) (Q : Measure Message) := integrable_continuous_message Q (hz.pow 3) + have hiadd : Integrable (fun b => lam*z b+lam^2*(z b)^2/2) (Q : Measure Message) := + (hi1.const_mul _).add ((hi2.const_mul _).div_const _) + rw [integral_sub hiadd ((hi3.const_mul _).div_const _), integral_add (hi1.const_mul _) ((hi2.const_mul _).div_const _), + integral_div, integral_div, integral_const_mul, integral_const_mul, integral_const_mul, h1,h2,h3] at hh + dsimp only [pairIncrement] + linarith + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/PoissonBounds.lean b/lean/OAI/Probability/ThreeState/PoissonBounds.lean index e8673d458f02f4b4322f190bff4253a9ede827ce..8cdfed7605831e642e54e2f2dcdc12d29bc3ee85 100644 --- a/lean/OAI/Probability/ThreeState/PoissonBounds.lean +++ b/lean/OAI/Probability/ThreeState/PoissonBounds.lean @@ -1,263 +1,263 @@ -import Mathlib -import OAI.Probability.ThreeState.PoissonCalculus -import OAI.Probability.ThreeState.RegularCritical - -namespace OAI - -/-! Poisson posterior projection and entropy bounds. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -noncomputable def offspringPosterior (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : ProbabilityMeasure Message := - ⟨densityEvolution offspring lam h Q, densityEvolution_probability offspring lam h Q hQ⟩ - -lemma integral_offspringPosterior (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (f : C(Message,ℝ)) : - (∫ m, f m ∂(offspringPosterior offspring lam h Q hQ : Measure Message)) = - mean offspring (fun n => ∫ m, f m ∂(degreePosterior lam h Q hQ n : Measure Message)) := by - rw [show (offspringPosterior offspring lam h Q hQ : Measure Message) = densityEvolution offspring lam h Q by rfl, - integral_densityEvolution_continuous offspring lam h Q hQ f] - apply mean_congr - intro n - exact (integral_degreeOutput lam h Q n f f.continuous.measurable).symm - -lemma posteriorMu_le_one (Q : ProbabilityMeasure Message) : posteriorMu Q ≤ 1 := by - simpa [posteriorMu, posteriorNu] using - integral_mono (integrable_continuous_message Q continuous_messageX) (integrable_const (1:ℝ)) messageX_le_one - -lemma posteriorNu_le_one (Q : ProbabilityMeasure Message) : posteriorNu Q ≤ 1 := by - have hp (m : Message) : (messageX m)^2≤1 := by nlinarith [messageX_nonneg m, messageX_le_one m] - simpa [posteriorMu, posteriorNu] using - integral_mono (integrable_continuous_message Q (continuous_messageX.pow 2)) (integrable_const (1:ℝ)) hp - -lemma posteriorMu_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : - posteriorMu (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => posteriorMu (degreePosterior lam h Q hQ n)) := - integral_offspringPosterior offspring lam h Q hQ ⟨messageX,continuous_messageX⟩ - -lemma posteriorNu_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : - posteriorNu (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => posteriorNu (degreePosterior lam h Q hQ n)) := by - unfold posteriorNu - exact integral_offspringPosterior offspring lam h Q hQ ⟨fun m => (messageX m)^2,continuous_messageX.pow 2⟩ - -lemma pairCorrelation_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : - pairCorrelation lam h Q (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => pairCorrelation lam h Q (degreePosterior lam h Q hQ n)) := - integral_offspringPosterior offspring lam h Q hQ ⟨pairIncrement lam h Q,continuous_pairIncrement lam h hl0 hl1 Q⟩ - -lemma poisson_projection_quadratic (t : ℝ) (ht : 0 ≤ t) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (s : ℝ) : - 0 ≤ posteriorMu (offspringPosterior (poissonOffspring t ht) lam h Q hQ)*s^2- - 2*(t*(lam^2*posteriorMu Q))*s+(t*(lam^2*posteriorMu Q)+t^2*(lam^2*posteriorMu Q)^2) := by - let p := poissonOffspring t ht - let beta := lam^2*posteriorMu Q - let muj := fun n => posteriorMu (degreePosterior lam h Q hQ n) - have hi : HasMean p muj := hasMean_bounded p 1 (fun n => by rw [abs_of_nonneg (posteriorMu_nonneg _)]; exact posteriorMu_le_one _) - have h1 : HasMean p (fun n : ℕ => (n:ℝ)) := (poisson_moments t ht).hasMean - have h2 : HasMean p (fun n : ℕ => (n:ℝ)*((n:ℝ)-1)) := (poisson_second_factorial_hasSum t ht).summable - have hh := mean_nonneg p (fun n => degree_projection_quadratic lam h hl0 hl1 Q hQ hs n s) - change 0 ≤ mean p (fun n => muj n*s^2-2*((n:ℝ)*beta)*s+((n:ℝ)*beta+(n:ℝ)*(n-1)*beta^2)) at hh - have ha : HasMean p (fun n : ℕ => 2*((n:ℝ)*beta)*s) := ((h1.mul_const beta).const_mul 2).mul_const s - rw [mean_add ((hi.mul_const _).sub ha) ((h1.mul_const _).add (h2.mul_const _)), - mean_sub (hi.mul_const _) ha, mean_mul_const, mean_mul_const, mean_const_mul, mean_mul_const, - mean_add (h1.mul_const _) (h2.mul_const _), mean_mul_const, mean_mul_const] at hh - have hm1 : mean p (fun n : ℕ => (n:ℝ))=t := (poisson_moments t ht).first - have hm2 : mean p (fun n : ℕ => (n:ℝ)*((n:ℝ)-1))=t^2 := (poisson_second_factorial_hasSum t ht).tsum_eq - rw [hm1,hm2, ← posteriorMu_offspring (poissonOffspring t ht) lam h Q hQ] at hh - exact hh - -lemma poisson_projection (t : ℝ) (ht : 0 ≤ t) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) : - t*(lam^2*posteriorMu Q)/(1+t*(lam^2*posteriorMu Q)) ≤ posteriorMu (offspringPosterior (poissonOffspring t ht) lam h Q hQ) := by - let x := t*(lam^2*posteriorMu Q) - have hx : 0 ≤ x := mul_nonneg ht (mul_nonneg (sq_nonneg _) (posteriorMu_nonneg Q)) - have hd : 0 < 1+x := by positivity - by_cases hx0 : x=0 - · change x/(1+x) ≤ _ - rw [hx0,zero_div] - exact posteriorMu_nonneg _ - · have hxpos : 0 f (n+1)-f n)) - · intro t _ - exact (poissonAverage_hasDerivAt f C hC hf t).continuousAt.continuousWithinAt - · intro t _ - exact (poissonAverage_hasDerivAt f C hC hf t).hasDerivWithinAt - · intro t ht - have ht0 : 0 ≤ t := interior_subset ht - rw [poissonAverage_eq_mean _ t ht0] - apply mean_nonneg - intro n - exact sub_nonneg.mpr (hmono (Nat.le_succ n)) - -lemma poisson_nu_le_fixedpoint (d : ℝ) (hd : 0 ≤ d) (t : ℝ) (ht : 0 ≤ t) (htd : t ≤ d) - (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) : - posteriorNu (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) ≤ posteriorNu Q := by - let f := fun n => posteriorNu (degreePosterior lam h Q hQ.1 n) - have hf (n : ℕ) : |f n| ≤ 1*((n:ℝ)+1) := by - rw [abs_of_nonneg (posteriorNu_nonneg _)] - have hh := posteriorNu_le_one (degreePosterior lam h Q hQ.1 n) - change posteriorNu (degreePosterior lam h Q hQ.1 n) ≤ _ - nlinarith [show (0:ℝ)≤n by positivity] - have he : offspringPosterior (poissonOffspring d hd) lam h Q hQ.1 = Q := by - apply Subtype.ext - exact (fixedpoint_measure (poissonOffspring d hd) lam h Q hQ).symm - have hm := poissonAverage_monotoneOn f 1 (by norm_num) hf (degree_nu_monotone lam h hl0 hl1 Q hQ.1) ht hd htd - rw [poissonAverage_eq_mean _ t ht, poissonAverage_eq_mean _ d hd] at hm - change mean (poissonOffspring t ht) (fun n => posteriorNu (degreePosterior lam h Q hQ.1 n)) ≤ - mean (poissonOffspring d hd) (fun n => posteriorNu (degreePosterior lam h Q hQ.1 n)) at hm - rwa [← posteriorNu_offspring, ← posteriorNu_offspring, he] at hm - -lemma poisson_correlation_hasDerivAt (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (t : ℝ) (ht : 0 ≤ t) : - HasDerivAt (poissonAverage (correlationEntropy lam h Q)) - (pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ)) t := by - have hf (n : ℕ) : |correlationEntropy lam h Q n| ≤ edgeLogBound lam*((n:ℝ)+1) := by - have hh := correlationEntropy_bound lam h hl0 hl1 Q hQ n - nlinarith only [hh,edgeLogBound_nonneg lam] - have hh := poissonAverage_hasDerivAt (correlationEntropy lam h Q) (edgeLogBound lam) (edgeLogBound_nonneg lam) hf t - rw [poissonAverage_eq_mean _ t ht] at hh - convert hh using 1 - rw [pairCorrelation_offspring (poissonOffspring t ht) lam h hl0 hl1 Q hQ] - apply mean_congr - intro n - have he := correlationEntropy_succ lam h hl0 hl1 Q hQ n - change _ = _ at he - change (∫ a, pairIncrement lam h Q a ∂degreeOutput lam h Q n) = _ - linarith only [he] - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma poisson_increment_bound (d : ℝ) (hd : 0 ≤ d) (t : ℝ) (ht : 0 ≤ t) (htd : t ≤ d) - (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) - (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : - 3*lam^4*(posteriorMu Q)^2*t/(1+t*lam^2*posteriorMu Q)- - lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt t ≤ - 3*pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) := by - have hm := posteriorMu_nonneg Q - have hn := posteriorNu_nonneg Q - let L := t*(lam^2*posteriorMu Q)/(1+t*(lam^2*posteriorMu Q)) - have hb : 0 ≤ lam^2*posteriorMu Q := mul_nonneg (sq_nonneg _) hm - have hL : 0 ≤ L := div_nonneg (mul_nonneg ht hb) (by positivity) - have hh := pairCorrelation_truncated lam h hl0 hl1 Q _ hQ.1 hs he - (poisson_nu_le_fixedpoint d hd t ht htd lam h hl0 hl1 Q hQ) hL - (poisson_projection t ht lam h hl0 hl1 Q hQ.1 hs) - have hsqrt : Real.sqrt L ≤ lam*Real.sqrt (posteriorMu Q)*Real.sqrt t := by - have hh := Real.sqrt_le_sqrt (div_le_self (mul_nonneg ht hb) (show 1 ≤ 1+t*(lam^2*posteriorMu Q) by nlinarith only [mul_nonneg ht hb])) - rw [Real.sqrt_mul ht, Real.sqrt_mul (sq_nonneg lam), Real.sqrt_sq_eq_abs, abs_of_nonneg hl0] at hh - dsimp only [L] - nlinarith only [hh] - have hmul := mul_le_mul_of_nonneg_left hsqrt (show 0 ≤ lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q by positivity) - have hsq := Real.sq_sqrt hm - have hlead : 3*lam^2*posteriorMu Q*L = - 3*lam^4*(posteriorMu Q)^2*t/(1+t*lam^2*posteriorMu Q) := by dsimp only [L]; ring - rw [hlead] at hh - have hloss : lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*(lam*Real.sqrt (posteriorMu Q)*Real.sqrt t) = - lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt t := by - calc - _ = lam^4*(Real.sqrt (posteriorMu Q))^2*posteriorNu Q*Real.sqrt t := by ring - _ = _ := by rw [hsq] - rw [hloss] at hmul - linarith only [hh, hmul] - -lemma poisson_correlation_bound (d : ℝ) (hd : 0 < d) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hl1 : lam < 1) (hc : d*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd.le) lam h Q) - (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : - 3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- - lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ 3*mean (poissonOffspring d hd.le) (correlationEntropy lam h Q) := by - let H := poissonAverage (correlationEntropy lam h Q) - let C := poissonAverage (fun n => correlationEntropy lam h Q (n+1)-correlationEntropy lam h Q n) - have hderiv (t : ℝ) : HasDerivAt H (C t) t := - poissonAverage_hasDerivAt (correlationEntropy lam h Q) (edgeLogBound lam) (edgeLogBound_nonneg lam) - (fun n => by - have hh := correlationEntropy_bound lam h hl0.le hl1 Q hQ.1 n - nlinarith only [hh,edgeLogBound_nonneg lam]) t - have heq (t : ℝ) (ht : 0 ≤ t) : C t=pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) := - (hderiv t).unique (poisson_correlation_hasDerivAt lam h hl0.le hl1 Q hQ.1 t ht) - have hh := poisson_correlation_scalar d lam (posteriorMu Q) (posteriorNu Q) hd hl0 - (posteriorMu_nonneg Q) (posteriorNu_nonneg Q) hc H C - (by dsimp only [H]; rw [poissonAverage_zero,correlationEntropy_zero]) - (fun t _ => hderiv t) (fun t ht => by - rw [heq t ht.1] - exact poisson_increment_bound d hd.le t ht.1 ht.2 lam h hl0.le hl1 Q hQ hs he) - simpa only [H,poissonAverage_eq_mean _ d hd.le] using hh - -lemma poisson_entropy_bound (d : ℝ) (hd : 0 < d) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hl1 : lam < 1) (hc : d*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd.le) lam h Q) - (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : - (1-lam^2)/2*posteriorNu Q+3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- - lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ - (8/5:ℝ)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by - have hD := (poisson_moments d hd.le).hasMean - have hD2 := (poisson_moments d hd.le).square - have hid := entropy_identity (poissonOffspring d hd.le) lam h hl0.le hl1 Q hQ hs hD2 - have hrad := integral_entropyF_radial (poissonOffspring d hd.le) lam h hl0 hl1 Q hQ hD2 - have hcorr := poisson_correlation_bound d hd lam h hl0 hl1 hc Q hQ hs he - have hJ := additive_entropyJ (poissonOffspring d hd.le) lam h hl0.le hl1 Q hQ hs hD - have hfacmean : mean (poissonOffspring d hd.le) (fun n : ℕ => (n:ℝ)*((n:ℝ)-1)) = d^2 := (poisson_second_factorial_hasSum d hd.le).tsum_eq - rw [(poisson_moments d hd.le).first, hfacmean] at hid - rw [(poisson_moments d hd.le).first] at hJ - have hl : lam⁻¹^2 = d := by field_simp; nlinarith only [hc] - rw [hl] at hrad - have hJe : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = - lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by - nlinarith only [hJ, congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] - rw [hJe] at hid - have hfac : d^2*lam^4=1 := by - calc _ = (d*lam^2)^2 := by ring - _ = 1 := by rw [hc]; norm_num - nlinarith only [hid,hrad,hcorr, - congrArg (fun x : ℝ => (8/5:ℝ)*x*(∫ m, entropyJ m ∂(Q : Measure Message))^2) hfac] - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.PoissonCalculus +import OAI.Probability.ThreeState.RegularCritical + +namespace OAI + +/-! Poisson posterior projection and entropy bounds. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +noncomputable def offspringPosterior (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : ProbabilityMeasure Message := + ⟨densityEvolution offspring lam h Q, densityEvolution_probability offspring lam h Q hQ⟩ + +lemma integral_offspringPosterior (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (f : C(Message,ℝ)) : + (∫ m, f m ∂(offspringPosterior offspring lam h Q hQ : Measure Message)) = + mean offspring (fun n => ∫ m, f m ∂(degreePosterior lam h Q hQ n : Measure Message)) := by + rw [show (offspringPosterior offspring lam h Q hQ : Measure Message) = densityEvolution offspring lam h Q by rfl, + integral_densityEvolution_continuous offspring lam h Q hQ f] + apply mean_congr + intro n + exact (integral_degreeOutput lam h Q n f f.continuous.measurable).symm + +lemma posteriorMu_le_one (Q : ProbabilityMeasure Message) : posteriorMu Q ≤ 1 := by + simpa [posteriorMu, posteriorNu] using + integral_mono (integrable_continuous_message Q continuous_messageX) (integrable_const (1:ℝ)) messageX_le_one + +lemma posteriorNu_le_one (Q : ProbabilityMeasure Message) : posteriorNu Q ≤ 1 := by + have hp (m : Message) : (messageX m)^2≤1 := by nlinarith [messageX_nonneg m, messageX_le_one m] + simpa [posteriorMu, posteriorNu] using + integral_mono (integrable_continuous_message Q (continuous_messageX.pow 2)) (integrable_const (1:ℝ)) hp + +lemma posteriorMu_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : + posteriorMu (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => posteriorMu (degreePosterior lam h Q hQ n)) := + integral_offspringPosterior offspring lam h Q hQ ⟨messageX,continuous_messageX⟩ + +lemma posteriorNu_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : + posteriorNu (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => posteriorNu (degreePosterior lam h Q hQ n)) := by + unfold posteriorNu + exact integral_offspringPosterior offspring lam h Q hQ ⟨fun m => (messageX m)^2,continuous_messageX.pow 2⟩ + +lemma pairCorrelation_offspring (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : + pairCorrelation lam h Q (offspringPosterior offspring lam h Q hQ) = mean offspring (fun n => pairCorrelation lam h Q (degreePosterior lam h Q hQ n)) := + integral_offspringPosterior offspring lam h Q hQ ⟨pairIncrement lam h Q,continuous_pairIncrement lam h hl0 hl1 Q⟩ + +lemma poisson_projection_quadratic (t : ℝ) (ht : 0 ≤ t) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (s : ℝ) : + 0 ≤ posteriorMu (offspringPosterior (poissonOffspring t ht) lam h Q hQ)*s^2- + 2*(t*(lam^2*posteriorMu Q))*s+(t*(lam^2*posteriorMu Q)+t^2*(lam^2*posteriorMu Q)^2) := by + let p := poissonOffspring t ht + let beta := lam^2*posteriorMu Q + let muj := fun n => posteriorMu (degreePosterior lam h Q hQ n) + have hi : HasMean p muj := hasMean_bounded p 1 (fun n => by rw [abs_of_nonneg (posteriorMu_nonneg _)]; exact posteriorMu_le_one _) + have h1 : HasMean p (fun n : ℕ => (n:ℝ)) := (poisson_moments t ht).hasMean + have h2 : HasMean p (fun n : ℕ => (n:ℝ)*((n:ℝ)-1)) := (poisson_second_factorial_hasSum t ht).summable + have hh := mean_nonneg p (fun n => degree_projection_quadratic lam h hl0 hl1 Q hQ hs n s) + change 0 ≤ mean p (fun n => muj n*s^2-2*((n:ℝ)*beta)*s+((n:ℝ)*beta+(n:ℝ)*(n-1)*beta^2)) at hh + have ha : HasMean p (fun n : ℕ => 2*((n:ℝ)*beta)*s) := ((h1.mul_const beta).const_mul 2).mul_const s + rw [mean_add ((hi.mul_const _).sub ha) ((h1.mul_const _).add (h2.mul_const _)), + mean_sub (hi.mul_const _) ha, mean_mul_const, mean_mul_const, mean_const_mul, mean_mul_const, + mean_add (h1.mul_const _) (h2.mul_const _), mean_mul_const, mean_mul_const] at hh + have hm1 : mean p (fun n : ℕ => (n:ℝ))=t := (poisson_moments t ht).first + have hm2 : mean p (fun n : ℕ => (n:ℝ)*((n:ℝ)-1))=t^2 := (poisson_second_factorial_hasSum t ht).tsum_eq + rw [hm1,hm2, ← posteriorMu_offspring (poissonOffspring t ht) lam h Q hQ] at hh + exact hh + +lemma poisson_projection (t : ℝ) (ht : 0 ≤ t) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) : + t*(lam^2*posteriorMu Q)/(1+t*(lam^2*posteriorMu Q)) ≤ posteriorMu (offspringPosterior (poissonOffspring t ht) lam h Q hQ) := by + let x := t*(lam^2*posteriorMu Q) + have hx : 0 ≤ x := mul_nonneg ht (mul_nonneg (sq_nonneg _) (posteriorMu_nonneg Q)) + have hd : 0 < 1+x := by positivity + by_cases hx0 : x=0 + · change x/(1+x) ≤ _ + rw [hx0,zero_div] + exact posteriorMu_nonneg _ + · have hxpos : 0 f (n+1)-f n)) + · intro t _ + exact (poissonAverage_hasDerivAt f C hC hf t).continuousAt.continuousWithinAt + · intro t _ + exact (poissonAverage_hasDerivAt f C hC hf t).hasDerivWithinAt + · intro t ht + have ht0 : 0 ≤ t := interior_subset ht + rw [poissonAverage_eq_mean _ t ht0] + apply mean_nonneg + intro n + exact sub_nonneg.mpr (hmono (Nat.le_succ n)) + +lemma poisson_nu_le_fixedpoint (d : ℝ) (hd : 0 ≤ d) (t : ℝ) (ht : 0 ≤ t) (htd : t ≤ d) + (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) : + posteriorNu (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) ≤ posteriorNu Q := by + let f := fun n => posteriorNu (degreePosterior lam h Q hQ.1 n) + have hf (n : ℕ) : |f n| ≤ 1*((n:ℝ)+1) := by + rw [abs_of_nonneg (posteriorNu_nonneg _)] + have hh := posteriorNu_le_one (degreePosterior lam h Q hQ.1 n) + change posteriorNu (degreePosterior lam h Q hQ.1 n) ≤ _ + nlinarith [show (0:ℝ)≤n by positivity] + have he : offspringPosterior (poissonOffspring d hd) lam h Q hQ.1 = Q := by + apply Subtype.ext + exact (fixedpoint_measure (poissonOffspring d hd) lam h Q hQ).symm + have hm := poissonAverage_monotoneOn f 1 (by norm_num) hf (degree_nu_monotone lam h hl0 hl1 Q hQ.1) ht hd htd + rw [poissonAverage_eq_mean _ t ht, poissonAverage_eq_mean _ d hd] at hm + change mean (poissonOffspring t ht) (fun n => posteriorNu (degreePosterior lam h Q hQ.1 n)) ≤ + mean (poissonOffspring d hd) (fun n => posteriorNu (degreePosterior lam h Q hQ.1 n)) at hm + rwa [← posteriorNu_offspring, ← posteriorNu_offspring, he] at hm + +lemma poisson_correlation_hasDerivAt (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (t : ℝ) (ht : 0 ≤ t) : + HasDerivAt (poissonAverage (correlationEntropy lam h Q)) + (pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ)) t := by + have hf (n : ℕ) : |correlationEntropy lam h Q n| ≤ edgeLogBound lam*((n:ℝ)+1) := by + have hh := correlationEntropy_bound lam h hl0 hl1 Q hQ n + nlinarith only [hh,edgeLogBound_nonneg lam] + have hh := poissonAverage_hasDerivAt (correlationEntropy lam h Q) (edgeLogBound lam) (edgeLogBound_nonneg lam) hf t + rw [poissonAverage_eq_mean _ t ht] at hh + convert hh using 1 + rw [pairCorrelation_offspring (poissonOffspring t ht) lam h hl0 hl1 Q hQ] + apply mean_congr + intro n + have he := correlationEntropy_succ lam h hl0 hl1 Q hQ n + change _ = _ at he + change (∫ a, pairIncrement lam h Q a ∂degreeOutput lam h Q n) = _ + linarith only [he] + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma poisson_increment_bound (d : ℝ) (hd : 0 ≤ d) (t : ℝ) (ht : 0 ≤ t) (htd : t ≤ d) + (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) + (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : + 3*lam^4*(posteriorMu Q)^2*t/(1+t*lam^2*posteriorMu Q)- + lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt t ≤ + 3*pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) := by + have hm := posteriorMu_nonneg Q + have hn := posteriorNu_nonneg Q + let L := t*(lam^2*posteriorMu Q)/(1+t*(lam^2*posteriorMu Q)) + have hb : 0 ≤ lam^2*posteriorMu Q := mul_nonneg (sq_nonneg _) hm + have hL : 0 ≤ L := div_nonneg (mul_nonneg ht hb) (by positivity) + have hh := pairCorrelation_truncated lam h hl0 hl1 Q _ hQ.1 hs he + (poisson_nu_le_fixedpoint d hd t ht htd lam h hl0 hl1 Q hQ) hL + (poisson_projection t ht lam h hl0 hl1 Q hQ.1 hs) + have hsqrt : Real.sqrt L ≤ lam*Real.sqrt (posteriorMu Q)*Real.sqrt t := by + have hh := Real.sqrt_le_sqrt (div_le_self (mul_nonneg ht hb) (show 1 ≤ 1+t*(lam^2*posteriorMu Q) by nlinarith only [mul_nonneg ht hb])) + rw [Real.sqrt_mul ht, Real.sqrt_mul (sq_nonneg lam), Real.sqrt_sq_eq_abs, abs_of_nonneg hl0] at hh + dsimp only [L] + nlinarith only [hh] + have hmul := mul_le_mul_of_nonneg_left hsqrt (show 0 ≤ lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q by positivity) + have hsq := Real.sq_sqrt hm + have hlead : 3*lam^2*posteriorMu Q*L = + 3*lam^4*(posteriorMu Q)^2*t/(1+t*lam^2*posteriorMu Q) := by dsimp only [L]; ring + rw [hlead] at hh + have hloss : lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*(lam*Real.sqrt (posteriorMu Q)*Real.sqrt t) = + lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt t := by + calc + _ = lam^4*(Real.sqrt (posteriorMu Q))^2*posteriorNu Q*Real.sqrt t := by ring + _ = _ := by rw [hsq] + rw [hloss] at hmul + linarith only [hh, hmul] + +lemma poisson_correlation_bound (d : ℝ) (hd : 0 < d) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hl1 : lam < 1) (hc : d*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd.le) lam h Q) + (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : + 3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- + lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ 3*mean (poissonOffspring d hd.le) (correlationEntropy lam h Q) := by + let H := poissonAverage (correlationEntropy lam h Q) + let C := poissonAverage (fun n => correlationEntropy lam h Q (n+1)-correlationEntropy lam h Q n) + have hderiv (t : ℝ) : HasDerivAt H (C t) t := + poissonAverage_hasDerivAt (correlationEntropy lam h Q) (edgeLogBound lam) (edgeLogBound_nonneg lam) + (fun n => by + have hh := correlationEntropy_bound lam h hl0.le hl1 Q hQ.1 n + nlinarith only [hh,edgeLogBound_nonneg lam]) t + have heq (t : ℝ) (ht : 0 ≤ t) : C t=pairCorrelation lam h Q (offspringPosterior (poissonOffspring t ht) lam h Q hQ.1) := + (hderiv t).unique (poisson_correlation_hasDerivAt lam h hl0.le hl1 Q hQ.1 t ht) + have hh := poisson_correlation_scalar d lam (posteriorMu Q) (posteriorNu Q) hd hl0 + (posteriorMu_nonneg Q) (posteriorNu_nonneg Q) hc H C + (by dsimp only [H]; rw [poissonAverage_zero,correlationEntropy_zero]) + (fun t _ => hderiv t) (fun t ht => by + rw [heq t ht.1] + exact poisson_increment_bound d hd.le t ht.1 ht.2 lam h hl0.le hl1 Q hQ hs he) + simpa only [H,poissonAverage_eq_mean _ d hd.le] using hh + +lemma poisson_entropy_bound (d : ℝ) (hd : 0 < d) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hl1 : lam < 1) (hc : d*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd.le) lam h Q) + (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : + (1-lam^2)/2*posteriorNu Q+3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- + lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ + (8/5:ℝ)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by + have hD := (poisson_moments d hd.le).hasMean + have hD2 := (poisson_moments d hd.le).square + have hid := entropy_identity (poissonOffspring d hd.le) lam h hl0.le hl1 Q hQ hs hD2 + have hrad := integral_entropyF_radial (poissonOffspring d hd.le) lam h hl0 hl1 Q hQ hD2 + have hcorr := poisson_correlation_bound d hd lam h hl0 hl1 hc Q hQ hs he + have hJ := additive_entropyJ (poissonOffspring d hd.le) lam h hl0.le hl1 Q hQ hs hD + have hfacmean : mean (poissonOffspring d hd.le) (fun n : ℕ => (n:ℝ)*((n:ℝ)-1)) = d^2 := (poisson_second_factorial_hasSum d hd.le).tsum_eq + rw [(poisson_moments d hd.le).first, hfacmean] at hid + rw [(poisson_moments d hd.le).first] at hJ + have hl : lam⁻¹^2 = d := by field_simp; nlinarith only [hc] + rw [hl] at hrad + have hJe : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = + lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by + nlinarith only [hJ, congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] + rw [hJe] at hid + have hfac : d^2*lam^4=1 := by + calc _ = (d*lam^2)^2 := by ring + _ = 1 := by rw [hc]; norm_num + nlinarith only [hid,hrad,hcorr, + congrArg (fun x : ℝ => (8/5:ℝ)*x*(∫ m, entropyJ m ∂(Q : Measure Message))^2) hfac] + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/PoissonCalculus.lean b/lean/OAI/Probability/ThreeState/PoissonCalculus.lean index c00ac103c93208a9253f7e1ef69af2f9481fbc49..52dd5adbe28d00d286db3a5cfc5549d91c617c1f 100644 --- a/lean/OAI/Probability/ThreeState/PoissonCalculus.lean +++ b/lean/OAI/Probability/ThreeState/PoissonCalculus.lean @@ -1,118 +1,118 @@ -import Mathlib - -namespace OAI - -/-! Exponential generating functions and differentiation of Poisson averages. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -noncomputable def expGenerating (f : ℕ → ℝ) (t : ℝ) : ℝ := - ∑' n : ℕ, t^n/(n.factorial:ℝ)*f n -noncomputable def poissonAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := - Real.exp (-t)*expGenerating f t - -lemma summable_expGenerating_linear (R : ℝ) : - Summable (fun n : ℕ => R^n/(n.factorial:ℝ)*((n:ℝ)+2)) := by - have h0 := (NormedSpace.expSeries_div_hasSum_exp R).summable - have h1 : Summable (fun n : ℕ => R^n/(n.factorial:ℝ)*(n:ℝ)) := by - apply (summable_nat_add_iff 1).mp - convert! h0.mul_left R using 1 - funext n - rw [pow_succ, Nat.factorial_succ, Nat.cast_mul] - have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity - have hf : (n.factorial:ℝ) ≠ 0 := by positivity - field_simp - convert h1.add (h0.mul_right 2) using 1 - funext n - ring - -lemma summable_expGenerating_deriv_bound (R C : ℝ) : - Summable (fun n : ℕ => (n:ℝ)*R^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1))) := by - apply (summable_nat_add_iff 1).mp - convert! (summable_expGenerating_linear R).mul_left C using 1 - funext n - rw [Nat.add_sub_cancel, Nat.factorial_succ, Nat.cast_mul] - push_cast - have hn : (n:ℝ)+1 ≠ 0 := by positivity - field_simp - ring - -lemma expGenerating_hasDerivAt (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) - (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : - HasDerivAt (expGenerating f) (expGenerating (fun n => f (n+1)) t) t := by - let R := |t|+1 - have hR : 0 < R := by dsimp [R]; positivity - have ht : t ∈ Set.Ioo (-R) R := by dsimp [R]; constructor <;> linarith [neg_abs_le t, le_abs_self t] - have hzero : (0:ℝ) ∈ Set.Ioo (-R) R := by constructor <;> linarith - have hsum0 : Summable (fun n : ℕ => (0:ℝ)^n/(n.factorial:ℝ)*f n) := by - apply summable_of_ne_finset_zero (s := {0}) - intro n hn - have hn0 : n ≠ 0 := by simpa using hn - simp [hn0] - have hb (n : ℕ) (y : ℝ) (hy : y ∈ Set.Ioo (-R) R) : - ‖(n:ℝ)*y^(n-1)/(n.factorial:ℝ)*f n‖ ≤ - (n:ℝ)*R^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := by - rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, abs_of_nonneg (by positivity : (0:ℝ)≤n), - abs_pow, abs_of_nonneg (by positivity : (0:ℝ)≤n.factorial)] - calc - _ ≤ (n:ℝ)*|y|^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := - mul_le_mul_of_nonneg_left (hf n) (by positivity) - _ ≤ _ := by - apply mul_le_mul_of_nonneg_right _ (mul_nonneg hC (by positivity)) - gcongr - exact le_of_lt (abs_lt.mpr hy) - have hh := hasDerivAt_tsum_of_isPreconnected (summable_expGenerating_deriv_bound R C) - isOpen_Ioo (convex_Ioo (-R) R).isPreconnected - (g := fun n y => y^n/(n.factorial:ℝ)*f n) - (g' := fun n y => (n:ℝ)*y^(n-1)/(n.factorial:ℝ)*f n) - (fun n y _ => ((hasDerivAt_pow n y).div_const (n.factorial:ℝ)).mul_const (f n)) - hb hzero hsum0 ht - have hs : Summable (fun n : ℕ => (n:ℝ)*t^(n-1)/(n.factorial:ℝ)*f n) := - Summable.of_norm_bounded (summable_expGenerating_deriv_bound R C) (fun n => hb n t ht) - have hid : (∑' n : ℕ, (n:ℝ)*t^(n-1)/(n.factorial:ℝ)*f n) = expGenerating (fun n => f (n+1)) t := by - rw [← hs.sum_add_tsum_nat_add 1] - simp only [Finset.sum_range_one, Nat.cast_zero, zero_mul, zero_div, zero_add] - apply tsum_congr - intro n - rw [Nat.add_sub_cancel, Nat.factorial_succ, Nat.cast_mul] - have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity - have hc : (n.factorial:ℝ) ≠ 0 := by positivity - field_simp - rwa [hid] at hh - -lemma expGenerating_summable (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) - (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : - Summable (fun n : ℕ => t^n/(n.factorial:ℝ)*f n) := by - apply Summable.of_norm_bounded ((summable_expGenerating_linear |t|).mul_left C) - intro n - rw [Real.norm_eq_abs, abs_mul, abs_div, abs_pow, abs_of_nonneg (by positivity : (0:ℝ)≤n.factorial)] - calc - _ ≤ |t|^n/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := mul_le_mul_of_nonneg_left (hf n) (by positivity) - _ ≤ _ := by nlinarith [mul_nonneg (show 0 ≤ |t|^n/(n.factorial:ℝ) by positivity) hC] - -lemma poissonAverage_hasDerivAt (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) - (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : - HasDerivAt (poissonAverage f) (poissonAverage (fun n => f (n+1)-f n) t) t := by - have hf' (n : ℕ) : |f (n+1)| ≤ (2*C)*((n:ℝ)+1) := by - have hh := hf (n+1) - push_cast at hh - nlinarith [mul_nonneg hC (show (0:ℝ)≤n by positivity)] - have hs := expGenerating_summable f C hC hf t - have hs' := expGenerating_summable (fun n => f (n+1)) (2*C) (by positivity) hf' t - have hdiff : expGenerating (fun n => f (n+1)-f n) t = - expGenerating (fun n => f (n+1)) t-expGenerating f t := by - unfold expGenerating - simp only [mul_sub, hs'.tsum_sub hs] - have hh := ((Real.hasDerivAt_exp (-t)).comp t (hasDerivAt_neg t)).mul (expGenerating_hasDerivAt f C hC hf t) - change HasDerivAt (poissonAverage f) _ t at hh - convert hh using 1 - dsimp only [poissonAverage] - rw [hdiff] - simp only [Function.comp_apply] - ring - -end ThreeState - -end OAI +import Mathlib + +namespace OAI + +/-! Exponential generating functions and differentiation of Poisson averages. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +noncomputable def expGenerating (f : ℕ → ℝ) (t : ℝ) : ℝ := + ∑' n : ℕ, t^n/(n.factorial:ℝ)*f n +noncomputable def poissonAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := + Real.exp (-t)*expGenerating f t + +lemma summable_expGenerating_linear (R : ℝ) : + Summable (fun n : ℕ => R^n/(n.factorial:ℝ)*((n:ℝ)+2)) := by + have h0 := (NormedSpace.expSeries_div_hasSum_exp R).summable + have h1 : Summable (fun n : ℕ => R^n/(n.factorial:ℝ)*(n:ℝ)) := by + apply (summable_nat_add_iff 1).mp + convert! h0.mul_left R using 1 + funext n + rw [pow_succ, Nat.factorial_succ, Nat.cast_mul] + have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + have hf : (n.factorial:ℝ) ≠ 0 := by positivity + field_simp + convert h1.add (h0.mul_right 2) using 1 + funext n + ring + +lemma summable_expGenerating_deriv_bound (R C : ℝ) : + Summable (fun n : ℕ => (n:ℝ)*R^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1))) := by + apply (summable_nat_add_iff 1).mp + convert! (summable_expGenerating_linear R).mul_left C using 1 + funext n + rw [Nat.add_sub_cancel, Nat.factorial_succ, Nat.cast_mul] + push_cast + have hn : (n:ℝ)+1 ≠ 0 := by positivity + field_simp + ring + +lemma expGenerating_hasDerivAt (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : + HasDerivAt (expGenerating f) (expGenerating (fun n => f (n+1)) t) t := by + let R := |t|+1 + have hR : 0 < R := by dsimp [R]; positivity + have ht : t ∈ Set.Ioo (-R) R := by dsimp [R]; constructor <;> linarith [neg_abs_le t, le_abs_self t] + have hzero : (0:ℝ) ∈ Set.Ioo (-R) R := by constructor <;> linarith + have hsum0 : Summable (fun n : ℕ => (0:ℝ)^n/(n.factorial:ℝ)*f n) := by + apply summable_of_ne_finset_zero (s := {0}) + intro n hn + have hn0 : n ≠ 0 := by simpa using hn + simp [hn0] + have hb (n : ℕ) (y : ℝ) (hy : y ∈ Set.Ioo (-R) R) : + ‖(n:ℝ)*y^(n-1)/(n.factorial:ℝ)*f n‖ ≤ + (n:ℝ)*R^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_mul, abs_of_nonneg (by positivity : (0:ℝ)≤n), + abs_pow, abs_of_nonneg (by positivity : (0:ℝ)≤n.factorial)] + calc + _ ≤ (n:ℝ)*|y|^(n-1)/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := + mul_le_mul_of_nonneg_left (hf n) (by positivity) + _ ≤ _ := by + apply mul_le_mul_of_nonneg_right _ (mul_nonneg hC (by positivity)) + gcongr + exact le_of_lt (abs_lt.mpr hy) + have hh := hasDerivAt_tsum_of_isPreconnected (summable_expGenerating_deriv_bound R C) + isOpen_Ioo (convex_Ioo (-R) R).isPreconnected + (g := fun n y => y^n/(n.factorial:ℝ)*f n) + (g' := fun n y => (n:ℝ)*y^(n-1)/(n.factorial:ℝ)*f n) + (fun n y _ => ((hasDerivAt_pow n y).div_const (n.factorial:ℝ)).mul_const (f n)) + hb hzero hsum0 ht + have hs : Summable (fun n : ℕ => (n:ℝ)*t^(n-1)/(n.factorial:ℝ)*f n) := + Summable.of_norm_bounded (summable_expGenerating_deriv_bound R C) (fun n => hb n t ht) + have hid : (∑' n : ℕ, (n:ℝ)*t^(n-1)/(n.factorial:ℝ)*f n) = expGenerating (fun n => f (n+1)) t := by + rw [← hs.sum_add_tsum_nat_add 1] + simp only [Finset.sum_range_one, Nat.cast_zero, zero_mul, zero_div, zero_add] + apply tsum_congr + intro n + rw [Nat.add_sub_cancel, Nat.factorial_succ, Nat.cast_mul] + have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + have hc : (n.factorial:ℝ) ≠ 0 := by positivity + field_simp + rwa [hid] at hh + +lemma expGenerating_summable (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : + Summable (fun n : ℕ => t^n/(n.factorial:ℝ)*f n) := by + apply Summable.of_norm_bounded ((summable_expGenerating_linear |t|).mul_left C) + intro n + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_pow, abs_of_nonneg (by positivity : (0:ℝ)≤n.factorial)] + calc + _ ≤ |t|^n/(n.factorial:ℝ)*(C*((n:ℝ)+1)) := mul_le_mul_of_nonneg_left (hf n) (by positivity) + _ ≤ _ := by nlinarith [mul_nonneg (show 0 ≤ |t|^n/(n.factorial:ℝ) by positivity) hC] + +lemma poissonAverage_hasDerivAt (f : ℕ → ℝ) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ n, |f n| ≤ C*((n:ℝ)+1)) (t : ℝ) : + HasDerivAt (poissonAverage f) (poissonAverage (fun n => f (n+1)-f n) t) t := by + have hf' (n : ℕ) : |f (n+1)| ≤ (2*C)*((n:ℝ)+1) := by + have hh := hf (n+1) + push_cast at hh + nlinarith [mul_nonneg hC (show (0:ℝ)≤n by positivity)] + have hs := expGenerating_summable f C hC hf t + have hs' := expGenerating_summable (fun n => f (n+1)) (2*C) (by positivity) hf' t + have hdiff : expGenerating (fun n => f (n+1)-f n) t = + expGenerating (fun n => f (n+1)) t-expGenerating f t := by + unfold expGenerating + simp only [mul_sub, hs'.tsum_sub hs] + have hh := ((Real.hasDerivAt_exp (-t)).comp t (hasDerivAt_neg t)).mul (expGenerating_hasDerivAt f C hC hf t) + change HasDerivAt (poissonAverage f) _ t at hh + convert hh using 1 + dsimp only [poissonAverage] + rw [hdiff] + simp only [Function.comp_apply] + ring + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/PoissonCritical.lean b/lean/OAI/Probability/ThreeState/PoissonCritical.lean index f22b9cfb3446c592bf1eca55724ebf635c152b3a..ec0a3a9793ebf62d693c077bbae219bbe5cb5578 100644 --- a/lean/OAI/Probability/ThreeState/PoissonCritical.lean +++ b/lean/OAI/Probability/ThreeState/PoissonCritical.lean @@ -1,207 +1,207 @@ -import Mathlib -import OAI.Probability.ThreeState.PoissonBounds - -namespace OAI - -/-! Informative posterior mass and positive critical Poisson non-reconstruction. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -@[simp] lemma normalizer_uninformative (lam : ℝ) (h : Admissible lam) (n : ℕ) : - normalizer lam h (fun _ : Fin n => uninformative) = 1 := by - simp [normalizer,productWeight,edgeMessage,uninformative] - -@[simp] lemma combineMessage_uninformative (lam : ℝ) (h : Admissible lam) (n : ℕ) : - combineMessage lam h (fun _ : Fin n => uninformative) = uninformative := by - simp only [combineMessage,normalizer_uninformative,one_ne_zero,↓reduceDIte,div_one] - apply Subtype.ext - funext i - simp [productWeight,edgeMessage,uninformative] - -lemma degreeOutput_atom (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : - (Q : Measure Message) {uninformative}^n ≤ degreeOutput lam h Q n {uninformative} := by - have hsub : {fun _ : Fin n => uninformative} ⊆ (combineMessage lam h) ⁻¹' {uninformative} := by - intro m hm - rcases Set.mem_singleton_iff.mp hm with rfl - exact combineMessage_uninformative lam h n - rw [degreeOutput, Measure.map_apply (measurable_combineMessage lam h n) (measurableSet_singleton _)] - have hh := measure_mono (μ := degreeInput lam h Q n) hsub - rw [degreeInput,withDensity_apply _ (measurableSet_singleton _),lintegral_singleton, - normalizer_uninformative,ENNReal.ofReal_one,one_mul] at hh - change (Measure.pi (fun _ : Fin n => (Q : Measure Message))) {fun _ => uninformative} ≤ _ at hh - simpa [degreeInput] using hh - -lemma densityEvolution_real (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (s : Set Message) (hs : MeasurableSet s) : - (densityEvolution offspring lam h Q).real s = mean offspring (fun n => (degreeOutput lam h Q n).real s) := by - rw [Measure.real,densityEvolution,Measure.sum_apply _ hs,ENNReal.tsum_toReal_eq] - · simp only [Measure.smul_apply,smul_eq_mul,ENNReal.toReal_mul,mean,mass,Measure.real] - · intro n - let := degreeOutput_probability lam h Q hQ n - simp only [Measure.smul_apply,smul_eq_mul] - exact ENNReal.mul_ne_top (offspring.apply_ne_top n) (measure_ne_top _ _) - -lemma poisson_power_mean (d a : ℝ) (hd : 0 ≤ d) : - mean (poissonOffspring d hd) (fun n => a^n) = Real.exp (d*(a-1)) := by - have he (n : ℕ) : mass (poissonOffspring d hd) n*a^n = Real.exp (-d)*((d*a)^n/(n.factorial : ℝ)) := by - rw [poisson_mass,mul_pow] - ring - unfold mean - simp_rw [he] - rw [tsum_mul_left] - have hh := NormedSpace.expSeries_div_hasSum_exp (d*a) - have he : (∑' n : ℕ, (d*a)^n/(n.factorial : ℝ)) = Real.exp (d*a) := by - simpa only [← Real.exp_eq_exp_ℝ] using hh.tsum_eq - rw [he,← Real.exp_add] - congr 1 - ring - -noncomputable def informativeMass (Q : ProbabilityMeasure Message) : ℝ := - 1-(Q : Measure Message).real {uninformative} - -lemma informativeMass_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ informativeMass Q := by - simp [informativeMass] - -lemma informativeMass_le_one (Q : ProbabilityMeasure Message) : informativeMass Q ≤ 1 := by - have hh := measureReal_nonneg (μ := (Q : Measure Message)) (s := {uninformative}) - dsimp only [informativeMass] - linarith - -lemma poisson_informative_recursion (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) : - Real.exp (-d*informativeMass Q) ≤ 1-informativeMass Q := by - have hdegree (n : ℕ) : ((Q : Measure Message).real {uninformative})^n ≤ (degreeOutput lam h Q n).real {uninformative} := by - let := degreeOutput_probability lam h Q hQ.1 n - have ht := ENNReal.toReal_mono (measure_ne_top (degreeOutput lam h Q n) {uninformative}) (degreeOutput_atom lam h Q n) - simpa only [ENNReal.toReal_pow,Measure.real] using ht - have hf : HasMean (poissonOffspring d hd) (fun n => ((Q : Measure Message).real {uninformative})^n) := by - apply hasMean_bounded _ 1 - intro n - rw [abs_of_nonneg (by positivity)] - apply pow_le_one₀ (measureReal_nonneg) _ - simp - have hg : HasMean (poissonOffspring d hd) (fun n => (degreeOutput lam h Q n).real {uninformative}) := by - apply hasMean_bounded _ 1 - intro n - let := degreeOutput_probability lam h Q hQ.1 n - rw [abs_of_nonneg measureReal_nonneg] - simp - have hh := mean_nonneg (poissonOffspring d hd) (fun n => sub_nonneg.mpr (hdegree n)) - rw [mean_sub hg hf] at hh - replace hh := sub_nonneg.mp hh - rw [poisson_power_mean] at hh - have he := congrArg (fun M : Measure Message => M.real {uninformative}) (fixedpoint_measure (poissonOffspring d hd) lam h Q hQ) - rw [densityEvolution_real _ _ _ _ hQ.1 _ (measurableSet_singleton _)] at he - rw [← he] at hh - convert hh using 1 <;> dsimp only [informativeMass] <;> congr 1 <;> ring - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma integral_real_cauchy {α : Type*} [MeasurableSpace α] (M : Measure α) (f g : α → ℝ) - (hf2 : Integrable (fun a => (f a)^2) M) (hg2 : Integrable (fun a => (g a)^2) M) - (hfg : Integrable (fun a => f a*g a) M) : - (∫ a, f a*g a ∂M)^2 ≤ (∫ a, (f a)^2 ∂M)*(∫ a, (g a)^2 ∂M) := by - have hp (t : ℝ) : 0 ≤ - (∫ a, (f a)^2 ∂M)*(t*t)+(-2*(∫ a, f a*g a ∂M))*t+(∫ a, (g a)^2 ∂M) := by - have hnon : 0 ≤ ∫ a, (t*f a-g a)^2 ∂M := integral_nonneg (fun value => sq_nonneg (t*f value-g value)) - have he (a : α) : (t*f a-g a)^2 = t^2*(f a)^2+(-2*t)*(f a*g a)+(g a)^2 := by ring - simp_rw [he] at hnon - have his : Integrable (fun a => t^2*(f a)^2+(-2*t)*(f a*g a)) M := (hf2.const_mul _).add (hfg.const_mul _) - rw [integral_add his hg2, integral_add (hf2.const_mul _) (hfg.const_mul _), integral_const_mul, integral_const_mul] at hnon - nlinarith only [hnon] - have hh := discrim_le_zero hp - simp only [discrim] at hh - nlinarith only [hh] - -@[simp] lemma messageX_uninformative : messageX uninformative = 0 := by - simp [messageX,Radial.momentX,Radial.avg_expand,messageDeviation,uninformative] - -lemma posteriorMu_sq_le_informative (Q : ProbabilityMeasure Message) : - (posteriorMu Q)^2 ≤ informativeMass Q*posteriorNu Q := by - let s : Set Message := {uninformative}ᶜ - have hs : MeasurableSet s := (measurableSet_singleton _).compl - let g : Message → ℝ := s.indicator (fun _ => 1) - have hg : Integrable g (Q : Measure Message) := (integrable_const (1:ℝ)).indicator hs - have hg2 : (fun m => (g m)^2) = g := by - funext m - by_cases hm : m∈s <;> simp [g,Set.indicator_of_mem,Set.indicator_of_notMem,hm] - have hfg : (fun m => messageX m*g m) = messageX := by - funext m - by_cases hm : m∈s - · simp [g,hm] - · have he : m=uninformative := by simpa only [s,Set.mem_compl_iff,Set.mem_singleton_iff,not_not] using hm - subst m - simp - have hh := integral_real_cauchy (Q : Measure Message) messageX g - (integrable_continuous_message Q (continuous_messageX.pow 2)) - (by rw [hg2]; exact hg) (by rw [hfg]; exact integrable_continuous_message Q continuous_messageX) - rw [hg2,hfg] at hh - have hgint : (∫ m, g m ∂(Q : Measure Message))=informativeMass Q := by - rw [show g=s.indicator (fun _ => (1:ℝ)) by rfl,integral_indicator hs] - simp only [integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] - change (Q : Measure Message).real {uninformative}ᶜ = 1-(Q : Measure Message).real {uninformative} - rw [measureReal_compl (measurableSet_singleton _)] - simp - rw [hgint] at hh - simpa only [posteriorMu,posteriorNu,mul_comm] using hh - -lemma informativeMass_pos_of_mu_pos (Q : ProbabilityMeasure Message) (hm : 0 < posteriorMu Q) : - 0 < informativeMass Q := by - have hh := posteriorMu_sq_le_informative Q - apply lt_of_le_of_ne (informativeMass_nonneg Q) - intro hzero - rw [← hzero,zero_mul] at hh - nlinarith only [hh,sq_pos_of_pos hm] - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma poisson_positive_critical_uniform (d : ℝ) (hd : 1 < d) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hc : d*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d (by linarith)) lam h Q) - (hs : SpinSymmetric Q) : posteriorMu Q = 0 := by - have hd0 : 0 < d := by linarith - have hl1 : lam < 1 := by - by_contra hn - have hh : 1 ≤ lam^2 := by nlinarith [sq_nonneg (lam-1)] - have hm := mul_le_mul_of_nonneg_left hh hd0.le - nlinarith only [hm,hc,hd] - have hD := (poisson_moments d hd0.le).hasMean - have hc' : mean (poissonOffspring d hd0.le) (fun n : ℕ => (n:ℝ))*lam^2=1 := by - simpa only [(poisson_moments d hd0.le).first] using hc - have hh := positive_moment_estimates (poissonOffspring d hd0.le) lam h hl0 hl1 Q hQ hs hD hc' - dsimp only at hh - have hm := posteriorMu_nonneg Q - have hn := posteriorNu_nonneg Q - have he : 0 ≤ posteriorEta Q := (show 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q by positivity).trans hh.2.2.1 - have hent := poisson_entropy_bound d hd0 lam h hl0 hl1 hc Q hQ hs he - have hcnu := critical_moment_nu_bound (poissonOffspring d hd0.le) lam h hl0 hl1 Q hQ hs hD hc' - by_contra hzero - have hmpos : 0 < posteriorMu Q := lt_of_le_of_ne hm (Ne.symm hzero) - have hsp := informativeMass_pos_of_mu_pos Q hmpos - apply PositiveScalar.moment_scalar_contradiction lam (posteriorMu Q) (posteriorNu Q) - (∫ m, entropyJ m ∂(Q : Measure Message)) (informativeMass Q) hl0 hl1 hmpos hn hsp - (informativeMass_le_one Q) (posteriorMu_sq_le_informative Q) hcnu hh.1 hh.2.1 hent - intro _ - have hsb := poisson_support_bound d (informativeMass Q) hd0 hsp - (poisson_informative_recursion d hd0.le lam h Q hQ) - have heq : d⁻¹=lam^2 := by field_simp; nlinarith only [hc] - rwa [heq] at hsb - - -theorem poisson_positive_critical_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) (hl0 : 0 < lam) (hc : d*lam^2=1) : - Tendsto (poissonAdvantage d (by linarith) lam h) atTop (𝓝 0) := by - exact observed_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d (by linarith)) lam h - (poisson_positive_critical_uniform d hd lam h hl0 hc) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.PoissonBounds + +namespace OAI + +/-! Informative posterior mass and positive critical Poisson non-reconstruction. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +@[simp] lemma normalizer_uninformative (lam : ℝ) (h : Admissible lam) (n : ℕ) : + normalizer lam h (fun _ : Fin n => uninformative) = 1 := by + simp [normalizer,productWeight,edgeMessage,uninformative] + +@[simp] lemma combineMessage_uninformative (lam : ℝ) (h : Admissible lam) (n : ℕ) : + combineMessage lam h (fun _ : Fin n => uninformative) = uninformative := by + simp only [combineMessage,normalizer_uninformative,one_ne_zero,↓reduceDIte,div_one] + apply Subtype.ext + funext i + simp [productWeight,edgeMessage,uninformative] + +lemma degreeOutput_atom (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : + (Q : Measure Message) {uninformative}^n ≤ degreeOutput lam h Q n {uninformative} := by + have hsub : {fun _ : Fin n => uninformative} ⊆ (combineMessage lam h) ⁻¹' {uninformative} := by + intro m hm + rcases Set.mem_singleton_iff.mp hm with rfl + exact combineMessage_uninformative lam h n + rw [degreeOutput, Measure.map_apply (measurable_combineMessage lam h n) (measurableSet_singleton _)] + have hh := measure_mono (μ := degreeInput lam h Q n) hsub + rw [degreeInput,withDensity_apply _ (measurableSet_singleton _),lintegral_singleton, + normalizer_uninformative,ENNReal.ofReal_one,one_mul] at hh + change (Measure.pi (fun _ : Fin n => (Q : Measure Message))) {fun _ => uninformative} ≤ _ at hh + simpa [degreeInput] using hh + +lemma densityEvolution_real (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (s : Set Message) (hs : MeasurableSet s) : + (densityEvolution offspring lam h Q).real s = mean offspring (fun n => (degreeOutput lam h Q n).real s) := by + rw [Measure.real,densityEvolution,Measure.sum_apply _ hs,ENNReal.tsum_toReal_eq] + · simp only [Measure.smul_apply,smul_eq_mul,ENNReal.toReal_mul,mean,mass,Measure.real] + · intro n + let := degreeOutput_probability lam h Q hQ n + simp only [Measure.smul_apply,smul_eq_mul] + exact ENNReal.mul_ne_top (offspring.apply_ne_top n) (measure_ne_top _ _) + +lemma poisson_power_mean (d a : ℝ) (hd : 0 ≤ d) : + mean (poissonOffspring d hd) (fun n => a^n) = Real.exp (d*(a-1)) := by + have he (n : ℕ) : mass (poissonOffspring d hd) n*a^n = Real.exp (-d)*((d*a)^n/(n.factorial : ℝ)) := by + rw [poisson_mass,mul_pow] + ring + unfold mean + simp_rw [he] + rw [tsum_mul_left] + have hh := NormedSpace.expSeries_div_hasSum_exp (d*a) + have he : (∑' n : ℕ, (d*a)^n/(n.factorial : ℝ)) = Real.exp (d*a) := by + simpa only [← Real.exp_eq_exp_ℝ] using hh.tsum_eq + rw [he,← Real.exp_add] + congr 1 + ring + +noncomputable def informativeMass (Q : ProbabilityMeasure Message) : ℝ := + 1-(Q : Measure Message).real {uninformative} + +lemma informativeMass_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ informativeMass Q := by + simp [informativeMass] + +lemma informativeMass_le_one (Q : ProbabilityMeasure Message) : informativeMass Q ≤ 1 := by + have hh := measureReal_nonneg (μ := (Q : Measure Message)) (s := {uninformative}) + dsimp only [informativeMass] + linarith + +lemma poisson_informative_recursion (d : ℝ) (hd : 0 ≤ d) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d hd) lam h Q) : + Real.exp (-d*informativeMass Q) ≤ 1-informativeMass Q := by + have hdegree (n : ℕ) : ((Q : Measure Message).real {uninformative})^n ≤ (degreeOutput lam h Q n).real {uninformative} := by + let := degreeOutput_probability lam h Q hQ.1 n + have ht := ENNReal.toReal_mono (measure_ne_top (degreeOutput lam h Q n) {uninformative}) (degreeOutput_atom lam h Q n) + simpa only [ENNReal.toReal_pow,Measure.real] using ht + have hf : HasMean (poissonOffspring d hd) (fun n => ((Q : Measure Message).real {uninformative})^n) := by + apply hasMean_bounded _ 1 + intro n + rw [abs_of_nonneg (by positivity)] + apply pow_le_one₀ (measureReal_nonneg) _ + simp + have hg : HasMean (poissonOffspring d hd) (fun n => (degreeOutput lam h Q n).real {uninformative}) := by + apply hasMean_bounded _ 1 + intro n + let := degreeOutput_probability lam h Q hQ.1 n + rw [abs_of_nonneg measureReal_nonneg] + simp + have hh := mean_nonneg (poissonOffspring d hd) (fun n => sub_nonneg.mpr (hdegree n)) + rw [mean_sub hg hf] at hh + replace hh := sub_nonneg.mp hh + rw [poisson_power_mean] at hh + have he := congrArg (fun M : Measure Message => M.real {uninformative}) (fixedpoint_measure (poissonOffspring d hd) lam h Q hQ) + rw [densityEvolution_real _ _ _ _ hQ.1 _ (measurableSet_singleton _)] at he + rw [← he] at hh + convert hh using 1 <;> dsimp only [informativeMass] <;> congr 1 <;> ring + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma integral_real_cauchy {α : Type*} [MeasurableSpace α] (M : Measure α) (f g : α → ℝ) + (hf2 : Integrable (fun a => (f a)^2) M) (hg2 : Integrable (fun a => (g a)^2) M) + (hfg : Integrable (fun a => f a*g a) M) : + (∫ a, f a*g a ∂M)^2 ≤ (∫ a, (f a)^2 ∂M)*(∫ a, (g a)^2 ∂M) := by + have hp (t : ℝ) : 0 ≤ + (∫ a, (f a)^2 ∂M)*(t*t)+(-2*(∫ a, f a*g a ∂M))*t+(∫ a, (g a)^2 ∂M) := by + have hnon : 0 ≤ ∫ a, (t*f a-g a)^2 ∂M := integral_nonneg (fun value => sq_nonneg (t*f value-g value)) + have he (a : α) : (t*f a-g a)^2 = t^2*(f a)^2+(-2*t)*(f a*g a)+(g a)^2 := by ring + simp_rw [he] at hnon + have his : Integrable (fun a => t^2*(f a)^2+(-2*t)*(f a*g a)) M := (hf2.const_mul _).add (hfg.const_mul _) + rw [integral_add his hg2, integral_add (hf2.const_mul _) (hfg.const_mul _), integral_const_mul, integral_const_mul] at hnon + nlinarith only [hnon] + have hh := discrim_le_zero hp + simp only [discrim] at hh + nlinarith only [hh] + +@[simp] lemma messageX_uninformative : messageX uninformative = 0 := by + simp [messageX,Radial.momentX,Radial.avg_expand,messageDeviation,uninformative] + +lemma posteriorMu_sq_le_informative (Q : ProbabilityMeasure Message) : + (posteriorMu Q)^2 ≤ informativeMass Q*posteriorNu Q := by + let s : Set Message := {uninformative}ᶜ + have hs : MeasurableSet s := (measurableSet_singleton _).compl + let g : Message → ℝ := s.indicator (fun _ => 1) + have hg : Integrable g (Q : Measure Message) := (integrable_const (1:ℝ)).indicator hs + have hg2 : (fun m => (g m)^2) = g := by + funext m + by_cases hm : m∈s <;> simp [g,Set.indicator_of_mem,Set.indicator_of_notMem,hm] + have hfg : (fun m => messageX m*g m) = messageX := by + funext m + by_cases hm : m∈s + · simp [g,hm] + · have he : m=uninformative := by simpa only [s,Set.mem_compl_iff,Set.mem_singleton_iff,not_not] using hm + subst m + simp + have hh := integral_real_cauchy (Q : Measure Message) messageX g + (integrable_continuous_message Q (continuous_messageX.pow 2)) + (by rw [hg2]; exact hg) (by rw [hfg]; exact integrable_continuous_message Q continuous_messageX) + rw [hg2,hfg] at hh + have hgint : (∫ m, g m ∂(Q : Measure Message))=informativeMass Q := by + rw [show g=s.indicator (fun _ => (1:ℝ)) by rfl,integral_indicator hs] + simp only [integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] + change (Q : Measure Message).real {uninformative}ᶜ = 1-(Q : Measure Message).real {uninformative} + rw [measureReal_compl (measurableSet_singleton _)] + simp + rw [hgint] at hh + simpa only [posteriorMu,posteriorNu,mul_comm] using hh + +lemma informativeMass_pos_of_mu_pos (Q : ProbabilityMeasure Message) (hm : 0 < posteriorMu Q) : + 0 < informativeMass Q := by + have hh := posteriorMu_sq_le_informative Q + apply lt_of_le_of_ne (informativeMass_nonneg Q) + intro hzero + rw [← hzero,zero_mul] at hh + nlinarith only [hh,sq_pos_of_pos hm] + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma poisson_positive_critical_uniform (d : ℝ) (hd : 1 < d) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hc : d*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (poissonOffspring d (by linarith)) lam h Q) + (hs : SpinSymmetric Q) : posteriorMu Q = 0 := by + have hd0 : 0 < d := by linarith + have hl1 : lam < 1 := by + by_contra hn + have hh : 1 ≤ lam^2 := by nlinarith [sq_nonneg (lam-1)] + have hm := mul_le_mul_of_nonneg_left hh hd0.le + nlinarith only [hm,hc,hd] + have hD := (poisson_moments d hd0.le).hasMean + have hc' : mean (poissonOffspring d hd0.le) (fun n : ℕ => (n:ℝ))*lam^2=1 := by + simpa only [(poisson_moments d hd0.le).first] using hc + have hh := positive_moment_estimates (poissonOffspring d hd0.le) lam h hl0 hl1 Q hQ hs hD hc' + dsimp only at hh + have hm := posteriorMu_nonneg Q + have hn := posteriorNu_nonneg Q + have he : 0 ≤ posteriorEta Q := (show 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q by positivity).trans hh.2.2.1 + have hent := poisson_entropy_bound d hd0 lam h hl0 hl1 hc Q hQ hs he + have hcnu := critical_moment_nu_bound (poissonOffspring d hd0.le) lam h hl0 hl1 Q hQ hs hD hc' + by_contra hzero + have hmpos : 0 < posteriorMu Q := lt_of_le_of_ne hm (Ne.symm hzero) + have hsp := informativeMass_pos_of_mu_pos Q hmpos + apply PositiveScalar.moment_scalar_contradiction lam (posteriorMu Q) (posteriorNu Q) + (∫ m, entropyJ m ∂(Q : Measure Message)) (informativeMass Q) hl0 hl1 hmpos hn hsp + (informativeMass_le_one Q) (posteriorMu_sq_le_informative Q) hcnu hh.1 hh.2.1 hent + intro _ + have hsb := poisson_support_bound d (informativeMass Q) hd0 hsp + (poisson_informative_recursion d hd0.le lam h Q hQ) + have heq : d⁻¹=lam^2 := by field_simp; nlinarith only [hc] + rwa [heq] at hsb + + +theorem poisson_positive_critical_nonreconstruction (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) (hl0 : 0 < lam) (hc : d*lam^2=1) : + Tendsto (poissonAdvantage d (by linarith) lam h) atTop (𝓝 0) := by + exact observed_tendsto_zero_of_uniform_fixedpoints (poissonOffspring d (by linarith)) lam h + (poisson_positive_critical_uniform d hd lam h hl0 hc) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/PosteriorMoments.lean b/lean/OAI/Probability/ThreeState/PosteriorMoments.lean index 20ec6970838ddda406f04f87f38db588b60187d1..d28cdb9c4f41155a038744d37470b9bb47063bc8 100644 --- a/lean/OAI/Probability/ThreeState/PosteriorMoments.lean +++ b/lean/OAI/Probability/ThreeState/PosteriorMoments.lean @@ -1,216 +1,216 @@ -import Mathlib -import OAI.Probability.ThreeState.EntropyRecursion -import OAI.Probability.ThreeState.Resolvents - -namespace OAI - -/-! Posterior deviation moments and positive-channel estimates. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -noncomputable def messageDeviation (m : Message) : Spin → ℝ := fun i => m i-1 -noncomputable def messageX (m : Message) : ℝ := Radial.momentX (messageDeviation m) -noncomputable def messageY (m : Message) : ℝ := Radial.momentY (messageDeviation m) - -lemma avg_messageDeviation (m : Message) : avg (messageDeviation m) = 0 := by - have hh := average_message m - simp only [messageDeviation, Radial.avg_expand] at * - linarith - -lemma messageX_nonneg (m : Message) : 0 ≤ messageX m := Radial.momentX_nonneg _ - -lemma messageX_le_one (m : Message) : messageX m ≤ 1 := by - have hi (i : Spin) : (m i)^2 ≤ 3*m i := by nlinarith [Message.nonneg m i, Message.le_three m i] - have hh := average_message m - simp only [messageX, messageDeviation, Radial.momentX, Radial.avg_expand] at * - nlinarith [hi 0,hi 1,hi 2] - -lemma continuous_messageX : Continuous messageX := by - change Continuous (fun m : Message => avg (fun i => (m i-1)^2)/2) - exact (continuous_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).pow 2)).div_const 2 - -lemma continuous_messageY : Continuous messageY := by - change Continuous (fun m : Message => avg (fun i => (m i-1)^3)/2) - exact (continuous_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).pow 3)).div_const 2 - -lemma integrable_continuous_message (Q : ProbabilityMeasure Message) {f : Message → ℝ} (hf : Continuous f) : - Integrable f (Q : Measure Message) := hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - -lemma entropyJ_functionJ (m : Message) : entropyJ m = Radial.functionJ (messageDeviation m) := by - simp [entropyJ, Radial.functionJ, messageDeviation, mLog] - -lemma messageDeviation_edge (lam : ℝ) (h : Admissible lam) (m : Message) : - messageDeviation (edgeMessage lam h m) = fun i => lam*messageDeviation m i := by - funext i - simp [messageDeviation, edgeMessage] - -lemma entropyJ_nonneg (m : Message) (hp : ∀ i, 0 < m i) : 0 ≤ entropyJ m := by - apply div_nonneg (avg_nonneg _) (by norm_num) - intro i - dsimp only [mLog] - rcases le_total (m i) 1 with hi | hi - · exact mul_nonneg_of_nonpos_of_nonpos (by linarith) (Real.log_nonpos (le_of_lt (hp i)) hi) - · exact mul_nonneg (by linarith) (Real.log_nonneg hi) - - - -noncomputable def messageA (m : Message) : ℝ := 2*entropyJ m-2*messageX m+messageY m -noncomputable def messageQ (lam : ℝ) (h : Admissible lam) (m : Message) : ℝ := - (lam^3*entropyJ m-entropyJ (edgeMessage lam h m)+lam^2*(1-lam)*messageX m)/(lam^3*(1-lam)) - -lemma messageA_eq_resolvent (m : Message) (hp : ∀ i, 0 < m i) : - messageA m = Radial.resolventA (messageDeviation m) := by - rw [Radial.resolventA_identity _ (by simpa [messageDeviation] using hp)] - simp [messageA, entropyJ_functionJ, messageX, messageY] - -lemma messageQ_eq_resolvent (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) - (m : Message) (hp : ∀ i, 0 < m i) : - messageQ lam h m = Radial.resolventQ (messageDeviation m) lam := by - apply (div_eq_iff (ne_of_gt (mul_pos (pow_pos hl0 _) (sub_pos.mpr hl1)))).mpr - have hh := Radial.resolventQ_identity (messageDeviation m) (by simpa [messageDeviation] using hp) lam hl0.le hl1.le - simp only [entropyJ_functionJ, messageDeviation_edge, messageX] - linarith only [hh] - -lemma messageA_lower (m : Message) (hp : ∀ i, 0 < m i) : - (37/27:ℝ)*(messageX m)^2 ≤ messageA m := by - rw [messageA_eq_resolvent m hp] - exact Radial.resolventA_lower _ (avg_messageDeviation m) (by simpa [messageDeviation] using hp) - -lemma messageQ_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) - (m : Message) (hp : ∀ i, 0 < m i) : messageA m/(2+lam) ≤ messageQ lam h m := by - rw [messageA_eq_resolvent m hp, messageQ_eq_resolvent lam h hl0 hl1 m hp] - exact Radial.resolventQ_lower _ (avg_messageDeviation m) (by simpa [messageDeviation] using hp) lam hl0.le hl1.le - -lemma messageY_upper (m : Message) : messageY m ≤ messageX m*Real.sqrt (messageX m) := by - have hh := (Radial.momentY_sqrt_bound _ (avg_messageDeviation m)).2 - change messageY m ≤ (Real.sqrt (messageX m))^3 at hh - have he : (Real.sqrt (messageX m))^3 = messageX m*Real.sqrt (messageX m) := by - calc - (Real.sqrt (messageX m))^3 = (Real.sqrt (messageX m))^2*Real.sqrt (messageX m) := by ring - _ = _ := by rw [Real.sq_sqrt (messageX_nonneg m)] - rwa [he] at hh - -lemma integral_continuous_cauchy (Q : ProbabilityMeasure Message) (f g : Message → ℝ) - (hf : Continuous f) (hg : Continuous g) : - (∫ m, f m*g m ∂(Q : Measure Message))^2 ≤ - (∫ m, (f m)^2 ∂(Q : Measure Message))*(∫ m, (g m)^2 ∂(Q : Measure Message)) := by - have hf2 : Integrable (fun m => (f m)^2) (Q : Measure Message) := integrable_continuous_message Q (hf.pow 2) - have hg2 : Integrable (fun m => (g m)^2) (Q : Measure Message) := integrable_continuous_message Q (hg.pow 2) - have hfg : Integrable (fun m => f m*g m) (Q : Measure Message) := integrable_continuous_message Q (hf.mul hg) - have hp (t : ℝ) : 0 ≤ - (∫ m, (f m)^2 ∂(Q : Measure Message))*(t*t)+ - (-2*(∫ m, f m*g m ∂(Q : Measure Message)))*t+(∫ m, (g m)^2 ∂(Q : Measure Message)) := by - have hnon : 0 ≤ ∫ m, (t*f m-g m)^2 ∂(Q : Measure Message) := integral_nonneg (fun message => sq_nonneg (t*f message-g message)) - have he (m : Message) : (t*f m-g m)^2 = t^2*(f m)^2+(-2*t)*(f m*g m)+(g m)^2 := by ring - simp_rw [he] at hnon - have his : Integrable (fun m => t^2*(f m)^2+(-2*t)*(f m*g m)) (Q : Measure Message) := (hf2.const_mul _).add (hfg.const_mul _) - rw [integral_add his hg2, - integral_add (hf2.const_mul _) (hfg.const_mul _), integral_const_mul, integral_const_mul] at hnon - nlinarith only [hnon] - have hh := discrim_le_zero hp - simp only [discrim] at hh - nlinarith only [hh] - -noncomputable def posteriorMu (Q : ProbabilityMeasure Message) : ℝ := ∫ m, messageX m ∂(Q : Measure Message) -noncomputable def posteriorNu (Q : ProbabilityMeasure Message) : ℝ := ∫ m, (messageX m)^2 ∂(Q : Measure Message) -noncomputable def posteriorEta (Q : ProbabilityMeasure Message) : ℝ := ∫ m, messageY m ∂(Q : Measure Message) - -lemma posteriorMu_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ posteriorMu Q := integral_nonneg messageX_nonneg -lemma posteriorNu_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ posteriorNu Q := integral_nonneg (fun message => sq_nonneg (messageX message)) - -lemma posteriorMu_sq_le (Q : ProbabilityMeasure Message) : (posteriorMu Q)^2 ≤ posteriorNu Q := by - have hh := integral_continuous_cauchy Q messageX (fun _ => 1) continuous_messageX continuous_const - simpa [posteriorMu, posteriorNu] using hh - -lemma posteriorEta_upper (Q : ProbabilityMeasure Message) : posteriorEta Q ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by - let r : Message → ℝ := fun m => Real.sqrt (messageX m) - have hc : Continuous r := continuous_messageX.sqrt - have hh := integral_continuous_cauchy Q r messageX hc continuous_messageX - have hs : ∀ m, (r m)^2 = messageX m := fun m => Real.sq_sqrt (messageX_nonneg m) - simp_rw [hs] at hh - have hi : Integrable (fun m => messageX m*r m) (Q : Measure Message) := integrable_continuous_message Q (continuous_messageX.mul hc) - have h0 : 0 ≤ ∫ m, messageX m*r m ∂(Q : Measure Message) := integral_nonneg (fun m => mul_nonneg (messageX_nonneg m) (Real.sqrt_nonneg _)) - have he : (∫ m, messageX m*r m ∂(Q : Measure Message)) ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by - apply (Real.le_sqrt h0 (mul_nonneg (posteriorMu_nonneg Q) (posteriorNu_nonneg Q))).mpr - simpa only [posteriorMu, posteriorNu, mul_comm] using hh - exact (integral_mono (integrable_continuous_message Q continuous_messageY) hi messageY_upper).trans he - -lemma integrable_messageA (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : Integrable messageA (Q : Measure Message) := by - exact (((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 2).sub - ((integrable_continuous_message Q continuous_messageX).const_mul 2)).add - (integrable_continuous_message Q continuous_messageY) - -lemma integrable_messageQ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : Integrable (messageQ lam h) (Q : Measure Message) := by - exact ((((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul _).sub - (integrable_continuous_message Q (continuous_entropyJ_edge lam h hl0 hl1))).add - ((integrable_continuous_message Q continuous_messageX).const_mul _)).div_const _ - -lemma integral_messageA (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : - (∫ m, messageA m ∂(Q : Measure Message)) = 2*(∫ m, entropyJ m ∂(Q : Measure Message))-2*posteriorMu Q+posteriorEta Q := by - have hj := integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD - have hx := integrable_continuous_message Q continuous_messageX - have hy := integrable_continuous_message Q continuous_messageY - change (∫ m, 2*entropyJ m-2*messageX m+messageY m ∂(Q : Measure Message)) = _ - have his : Integrable (fun m => 2*entropyJ m-2*messageX m) (Q : Measure Message) := (hj.const_mul 2).sub (hx.const_mul 2) - rw [integral_add his hy, integral_sub (hj.const_mul 2) (hx.const_mul 2), integral_const_mul, integral_const_mul] - rfl - -lemma integral_messageQ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2 = 1) : - (∫ m, entropyJ m ∂(Q : Measure Message)) = posteriorMu Q-lam*(∫ m, messageQ lam h m ∂(Q : Measure Message)) := by - have hj := integrable_entropyJ_fixedpoint offspring lam h hl0.le hl1 Q hQ hD - have hje := integrable_continuous_message Q (continuous_entropyJ_edge lam h hl0.le hl1) - have hx := integrable_continuous_message Q continuous_messageX - have hadd := additive_entropyJ offspring lam h hl0.le hl1 Q hQ hs hD - have he : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = - lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by nlinarith [congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] - simp only [messageQ] - have his : Integrable (fun m => lam^3*entropyJ m-entropyJ (edgeMessage lam h m)) (Q : Measure Message) := (hj.const_mul _).sub hje - rw [integral_div, integral_add his (hx.const_mul _), - integral_sub (hj.const_mul _) hje, integral_const_mul, integral_const_mul, he] - dsimp only [posteriorMu] - field_simp [ne_of_gt hl0, ne_of_gt (sub_pos.mpr hl1)] - ring - -lemma positive_moment_estimates (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2 = 1) : - let q : ℝ := (37/27:ℝ)/(2+lam) - let c : ℝ := (37/27:ℝ)+2*lam*q - 0 ≤ (∫ m, entropyJ m ∂(Q : Measure Message)) ∧ - (∫ m, entropyJ m ∂(Q : Measure Message)) ≤ posteriorMu Q-lam*q*posteriorNu Q ∧ - c*posteriorNu Q ≤ posteriorEta Q ∧ posteriorEta Q ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by - dsimp only - have hp := positive_fixedpoint offspring lam h hl0.le hl1 Q hQ - have hiA := integrable_messageA offspring lam h hl0.le hl1 Q hQ hD - have hiQ := integrable_messageQ offspring lam h hl0.le hl1 Q hQ hD - have hA : (37/27:ℝ)*posteriorNu Q ≤ ∫ m, messageA m ∂(Q : Measure Message) := by - have hh := integral_mono_ae ((integrable_continuous_message Q (continuous_messageX.pow 2)).const_mul (37/27:ℝ)) hiA - (hp.mono (fun m hm => messageA_lower m hm)) - simpa only [integral_const_mul, posteriorNu, Pi.pow_apply] using hh - have hQ' : (∫ m, messageA m ∂(Q : Measure Message))/(2+lam) ≤ ∫ m, messageQ lam h m ∂(Q : Measure Message) := by - have hh := integral_mono_ae (hiA.div_const (2+lam)) hiQ - (hp.mono (fun m hm => messageQ_lower lam h hl0 hl1 m hm)) - simpa only [integral_div] using hh - have hQl : (37/27:ℝ)/(2+lam)*posteriorNu Q ≤ ∫ m, messageQ lam h m ∂(Q : Measure Message) := by - have hh := (div_le_div_of_nonneg_right hA (by linarith : 0 ≤ 2+lam)).trans hQ' - simpa only [div_mul_eq_mul_div] using hh - have hJ := integral_messageQ offspring lam h hl0 hl1 Q hQ hs hD hc - have hAi := integral_messageA offspring lam h hl0.le hl1 Q hQ hD - refine ⟨integral_nonneg_of_ae (hp.mono (fun m hm => entropyJ_nonneg m hm)), ?_, ?_, posteriorEta_upper Q⟩ - · nlinarith only [hQl, hJ, hl0] - · nlinarith only [hQl, hJ, hAi, hA, hl0] - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.EntropyRecursion +import OAI.Probability.ThreeState.Resolvents + +namespace OAI + +/-! Posterior deviation moments and positive-channel estimates. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +noncomputable def messageDeviation (m : Message) : Spin → ℝ := fun i => m i-1 +noncomputable def messageX (m : Message) : ℝ := Radial.momentX (messageDeviation m) +noncomputable def messageY (m : Message) : ℝ := Radial.momentY (messageDeviation m) + +lemma avg_messageDeviation (m : Message) : avg (messageDeviation m) = 0 := by + have hh := average_message m + simp only [messageDeviation, Radial.avg_expand] at * + linarith + +lemma messageX_nonneg (m : Message) : 0 ≤ messageX m := Radial.momentX_nonneg _ + +lemma messageX_le_one (m : Message) : messageX m ≤ 1 := by + have hi (i : Spin) : (m i)^2 ≤ 3*m i := by nlinarith [Message.nonneg m i, Message.le_three m i] + have hh := average_message m + simp only [messageX, messageDeviation, Radial.momentX, Radial.avg_expand] at * + nlinarith [hi 0,hi 1,hi 2] + +lemma continuous_messageX : Continuous messageX := by + change Continuous (fun m : Message => avg (fun i => (m i-1)^2)/2) + exact (continuous_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).pow 2)).div_const 2 + +lemma continuous_messageY : Continuous messageY := by + change Continuous (fun m : Message => avg (fun i => (m i-1)^3)/2) + exact (continuous_avg _ (fun i => (((continuous_apply i).comp continuous_subtype_val).sub continuous_const).pow 3)).div_const 2 + +lemma integrable_continuous_message (Q : ProbabilityMeasure Message) {f : Message → ℝ} (hf : Continuous f) : + Integrable f (Q : Measure Message) := hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + +lemma entropyJ_functionJ (m : Message) : entropyJ m = Radial.functionJ (messageDeviation m) := by + simp [entropyJ, Radial.functionJ, messageDeviation, mLog] + +lemma messageDeviation_edge (lam : ℝ) (h : Admissible lam) (m : Message) : + messageDeviation (edgeMessage lam h m) = fun i => lam*messageDeviation m i := by + funext i + simp [messageDeviation, edgeMessage] + +lemma entropyJ_nonneg (m : Message) (hp : ∀ i, 0 < m i) : 0 ≤ entropyJ m := by + apply div_nonneg (avg_nonneg _) (by norm_num) + intro i + dsimp only [mLog] + rcases le_total (m i) 1 with hi | hi + · exact mul_nonneg_of_nonpos_of_nonpos (by linarith) (Real.log_nonpos (le_of_lt (hp i)) hi) + · exact mul_nonneg (by linarith) (Real.log_nonneg hi) + + + +noncomputable def messageA (m : Message) : ℝ := 2*entropyJ m-2*messageX m+messageY m +noncomputable def messageQ (lam : ℝ) (h : Admissible lam) (m : Message) : ℝ := + (lam^3*entropyJ m-entropyJ (edgeMessage lam h m)+lam^2*(1-lam)*messageX m)/(lam^3*(1-lam)) + +lemma messageA_eq_resolvent (m : Message) (hp : ∀ i, 0 < m i) : + messageA m = Radial.resolventA (messageDeviation m) := by + rw [Radial.resolventA_identity _ (by simpa [messageDeviation] using hp)] + simp [messageA, entropyJ_functionJ, messageX, messageY] + +lemma messageQ_eq_resolvent (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) + (m : Message) (hp : ∀ i, 0 < m i) : + messageQ lam h m = Radial.resolventQ (messageDeviation m) lam := by + apply (div_eq_iff (ne_of_gt (mul_pos (pow_pos hl0 _) (sub_pos.mpr hl1)))).mpr + have hh := Radial.resolventQ_identity (messageDeviation m) (by simpa [messageDeviation] using hp) lam hl0.le hl1.le + simp only [entropyJ_functionJ, messageDeviation_edge, messageX] + linarith only [hh] + +lemma messageA_lower (m : Message) (hp : ∀ i, 0 < m i) : + (37/27:ℝ)*(messageX m)^2 ≤ messageA m := by + rw [messageA_eq_resolvent m hp] + exact Radial.resolventA_lower _ (avg_messageDeviation m) (by simpa [messageDeviation] using hp) + +lemma messageQ_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) + (m : Message) (hp : ∀ i, 0 < m i) : messageA m/(2+lam) ≤ messageQ lam h m := by + rw [messageA_eq_resolvent m hp, messageQ_eq_resolvent lam h hl0 hl1 m hp] + exact Radial.resolventQ_lower _ (avg_messageDeviation m) (by simpa [messageDeviation] using hp) lam hl0.le hl1.le + +lemma messageY_upper (m : Message) : messageY m ≤ messageX m*Real.sqrt (messageX m) := by + have hh := (Radial.momentY_sqrt_bound _ (avg_messageDeviation m)).2 + change messageY m ≤ (Real.sqrt (messageX m))^3 at hh + have he : (Real.sqrt (messageX m))^3 = messageX m*Real.sqrt (messageX m) := by + calc + (Real.sqrt (messageX m))^3 = (Real.sqrt (messageX m))^2*Real.sqrt (messageX m) := by ring + _ = _ := by rw [Real.sq_sqrt (messageX_nonneg m)] + rwa [he] at hh + +lemma integral_continuous_cauchy (Q : ProbabilityMeasure Message) (f g : Message → ℝ) + (hf : Continuous f) (hg : Continuous g) : + (∫ m, f m*g m ∂(Q : Measure Message))^2 ≤ + (∫ m, (f m)^2 ∂(Q : Measure Message))*(∫ m, (g m)^2 ∂(Q : Measure Message)) := by + have hf2 : Integrable (fun m => (f m)^2) (Q : Measure Message) := integrable_continuous_message Q (hf.pow 2) + have hg2 : Integrable (fun m => (g m)^2) (Q : Measure Message) := integrable_continuous_message Q (hg.pow 2) + have hfg : Integrable (fun m => f m*g m) (Q : Measure Message) := integrable_continuous_message Q (hf.mul hg) + have hp (t : ℝ) : 0 ≤ + (∫ m, (f m)^2 ∂(Q : Measure Message))*(t*t)+ + (-2*(∫ m, f m*g m ∂(Q : Measure Message)))*t+(∫ m, (g m)^2 ∂(Q : Measure Message)) := by + have hnon : 0 ≤ ∫ m, (t*f m-g m)^2 ∂(Q : Measure Message) := integral_nonneg (fun message => sq_nonneg (t*f message-g message)) + have he (m : Message) : (t*f m-g m)^2 = t^2*(f m)^2+(-2*t)*(f m*g m)+(g m)^2 := by ring + simp_rw [he] at hnon + have his : Integrable (fun m => t^2*(f m)^2+(-2*t)*(f m*g m)) (Q : Measure Message) := (hf2.const_mul _).add (hfg.const_mul _) + rw [integral_add his hg2, + integral_add (hf2.const_mul _) (hfg.const_mul _), integral_const_mul, integral_const_mul] at hnon + nlinarith only [hnon] + have hh := discrim_le_zero hp + simp only [discrim] at hh + nlinarith only [hh] + +noncomputable def posteriorMu (Q : ProbabilityMeasure Message) : ℝ := ∫ m, messageX m ∂(Q : Measure Message) +noncomputable def posteriorNu (Q : ProbabilityMeasure Message) : ℝ := ∫ m, (messageX m)^2 ∂(Q : Measure Message) +noncomputable def posteriorEta (Q : ProbabilityMeasure Message) : ℝ := ∫ m, messageY m ∂(Q : Measure Message) + +lemma posteriorMu_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ posteriorMu Q := integral_nonneg messageX_nonneg +lemma posteriorNu_nonneg (Q : ProbabilityMeasure Message) : 0 ≤ posteriorNu Q := integral_nonneg (fun message => sq_nonneg (messageX message)) + +lemma posteriorMu_sq_le (Q : ProbabilityMeasure Message) : (posteriorMu Q)^2 ≤ posteriorNu Q := by + have hh := integral_continuous_cauchy Q messageX (fun _ => 1) continuous_messageX continuous_const + simpa [posteriorMu, posteriorNu] using hh + +lemma posteriorEta_upper (Q : ProbabilityMeasure Message) : posteriorEta Q ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by + let r : Message → ℝ := fun m => Real.sqrt (messageX m) + have hc : Continuous r := continuous_messageX.sqrt + have hh := integral_continuous_cauchy Q r messageX hc continuous_messageX + have hs : ∀ m, (r m)^2 = messageX m := fun m => Real.sq_sqrt (messageX_nonneg m) + simp_rw [hs] at hh + have hi : Integrable (fun m => messageX m*r m) (Q : Measure Message) := integrable_continuous_message Q (continuous_messageX.mul hc) + have h0 : 0 ≤ ∫ m, messageX m*r m ∂(Q : Measure Message) := integral_nonneg (fun m => mul_nonneg (messageX_nonneg m) (Real.sqrt_nonneg _)) + have he : (∫ m, messageX m*r m ∂(Q : Measure Message)) ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by + apply (Real.le_sqrt h0 (mul_nonneg (posteriorMu_nonneg Q) (posteriorNu_nonneg Q))).mpr + simpa only [posteriorMu, posteriorNu, mul_comm] using hh + exact (integral_mono (integrable_continuous_message Q continuous_messageY) hi messageY_upper).trans he + +lemma integrable_messageA (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : Integrable messageA (Q : Measure Message) := by + exact (((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul 2).sub + ((integrable_continuous_message Q continuous_messageX).const_mul 2)).add + (integrable_continuous_message Q continuous_messageY) + +lemma integrable_messageQ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : Integrable (messageQ lam h) (Q : Measure Message) := by + exact ((((integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD).const_mul _).sub + (integrable_continuous_message Q (continuous_entropyJ_edge lam h hl0 hl1))).add + ((integrable_continuous_message Q continuous_messageX).const_mul _)).div_const _ + +lemma integral_messageA (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) : + (∫ m, messageA m ∂(Q : Measure Message)) = 2*(∫ m, entropyJ m ∂(Q : Measure Message))-2*posteriorMu Q+posteriorEta Q := by + have hj := integrable_entropyJ_fixedpoint offspring lam h hl0 hl1 Q hQ hD + have hx := integrable_continuous_message Q continuous_messageX + have hy := integrable_continuous_message Q continuous_messageY + change (∫ m, 2*entropyJ m-2*messageX m+messageY m ∂(Q : Measure Message)) = _ + have his : Integrable (fun m => 2*entropyJ m-2*messageX m) (Q : Measure Message) := (hj.const_mul 2).sub (hx.const_mul 2) + rw [integral_add his hy, integral_sub (hj.const_mul 2) (hx.const_mul 2), integral_const_mul, integral_const_mul] + rfl + +lemma integral_messageQ (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2 = 1) : + (∫ m, entropyJ m ∂(Q : Measure Message)) = posteriorMu Q-lam*(∫ m, messageQ lam h m ∂(Q : Measure Message)) := by + have hj := integrable_entropyJ_fixedpoint offspring lam h hl0.le hl1 Q hQ hD + have hje := integrable_continuous_message Q (continuous_entropyJ_edge lam h hl0.le hl1) + have hx := integrable_continuous_message Q continuous_messageX + have hadd := additive_entropyJ offspring lam h hl0.le hl1 Q hQ hs hD + have he : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = + lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by nlinarith [congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] + simp only [messageQ] + have his : Integrable (fun m => lam^3*entropyJ m-entropyJ (edgeMessage lam h m)) (Q : Measure Message) := (hj.const_mul _).sub hje + rw [integral_div, integral_add his (hx.const_mul _), + integral_sub (hj.const_mul _) hje, integral_const_mul, integral_const_mul, he] + dsimp only [posteriorMu] + field_simp [ne_of_gt hl0, ne_of_gt (sub_pos.mpr hl1)] + ring + +lemma positive_moment_estimates (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 < lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2 = 1) : + let q : ℝ := (37/27:ℝ)/(2+lam) + let c : ℝ := (37/27:ℝ)+2*lam*q + 0 ≤ (∫ m, entropyJ m ∂(Q : Measure Message)) ∧ + (∫ m, entropyJ m ∂(Q : Measure Message)) ≤ posteriorMu Q-lam*q*posteriorNu Q ∧ + c*posteriorNu Q ≤ posteriorEta Q ∧ posteriorEta Q ≤ Real.sqrt (posteriorMu Q*posteriorNu Q) := by + dsimp only + have hp := positive_fixedpoint offspring lam h hl0.le hl1 Q hQ + have hiA := integrable_messageA offspring lam h hl0.le hl1 Q hQ hD + have hiQ := integrable_messageQ offspring lam h hl0.le hl1 Q hQ hD + have hA : (37/27:ℝ)*posteriorNu Q ≤ ∫ m, messageA m ∂(Q : Measure Message) := by + have hh := integral_mono_ae ((integrable_continuous_message Q (continuous_messageX.pow 2)).const_mul (37/27:ℝ)) hiA + (hp.mono (fun m hm => messageA_lower m hm)) + simpa only [integral_const_mul, posteriorNu, Pi.pow_apply] using hh + have hQ' : (∫ m, messageA m ∂(Q : Measure Message))/(2+lam) ≤ ∫ m, messageQ lam h m ∂(Q : Measure Message) := by + have hh := integral_mono_ae (hiA.div_const (2+lam)) hiQ + (hp.mono (fun m hm => messageQ_lower lam h hl0 hl1 m hm)) + simpa only [integral_div] using hh + have hQl : (37/27:ℝ)/(2+lam)*posteriorNu Q ≤ ∫ m, messageQ lam h m ∂(Q : Measure Message) := by + have hh := (div_le_div_of_nonneg_right hA (by linarith : 0 ≤ 2+lam)).trans hQ' + simpa only [div_mul_eq_mul_div] using hh + have hJ := integral_messageQ offspring lam h hl0 hl1 Q hQ hs hD hc + have hAi := integral_messageA offspring lam h hl0.le hl1 Q hQ hD + refine ⟨integral_nonneg_of_ae (hp.mono (fun m hm => entropyJ_nonneg m hm)), ?_, ?_, posteriorEta_upper Q⟩ + · nlinarith only [hQl, hJ, hl0] + · nlinarith only [hQl, hJ, hAi, hA, hl0] + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Projection.lean b/lean/OAI/Probability/ThreeState/Projection.lean index 77e17207688eca63f16a93d3b438472d58299e9c..af9089850c06cf0b18027d29e100d11ac8438992 100644 --- a/lean/OAI/Probability/ThreeState/Projection.lean +++ b/lean/OAI/Probability/ThreeState/Projection.lean @@ -1,370 +1,370 @@ -import Mathlib -import OAI.Probability.ThreeState.DegreePosterior - -namespace OAI - -/-! Quadratic projections, covariance and truncated correlation estimates. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma symAvg_deviation_mul (a : Message) (i j : Spin) : - symAvg (fun m => messageDeviation m i*messageDeviation m j) a = - (if i=j then 2 else -1)*messageX a := by - fin_cases i <;> fin_cases j <;> - norm_num [symAvg, symPerm, Fin.sum_univ_succ, messageDeviation, - Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, - Equiv.symm_trans_apply, Fin.ext_iff, messageX, Radial.momentX] <;> - (try rw [message_last a]) <;> ring - -lemma continuous_messageDeviation (i : Spin) : Continuous (fun m => messageDeviation m i) := - ((continuous_apply i).comp continuous_subtype_val).sub continuous_const - -lemma integral_deviation (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (i : Spin) : - (∫ m, messageDeviation m i ∂(Q : Measure Message)) = 0 := by - change (∫ m : Message, m i-1 ∂(Q : Measure Message)) = 0 - have hi : Integrable (fun m : Message => m i) (Q : Measure Message) := - integrable_continuous_message Q (coordinateMap i).continuous - rw [integral_sub hi (integrable_const (1:ℝ)), hQ i] - simp - -lemma integral_deviation_mul (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (i j : Spin) : - (∫ m, messageDeviation m i*messageDeviation m j ∂(Q : Measure Message)) = - (if i=j then 2 else -1)*posteriorMu Q := by - rw [← integral_symAvg Q hs (fun m => messageDeviation m i*messageDeviation m j) ((continuous_messageDeviation i).mul (continuous_messageDeviation j))] - simp only [symAvg_deviation_mul, integral_const_mul, posteriorMu] - -noncomputable def edgeDeviationMap (lam : ℝ) (h : Admissible lam) (i : Spin) : C(Message,ℝ) := - ⟨fun m => messageDeviation (edgeMessage lam h m) i, - (continuous_messageDeviation i).comp (continuous_edgeMessage lam h)⟩ - -lemma edge_deviation (lam : ℝ) (h : Admissible lam) (m : Message) (i : Spin) : - messageDeviation (edgeMessage lam h m) i = lam*messageDeviation m i := by - change 1+lam*(m i-1)-1 = lam*(m i-1) - ring - -lemma integral_edge_covariance (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (hs : SpinSymmetric Q) (i j : Spin) : - (∫ m, edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) j ∂(Q : Measure Message)) = - lam^2*posteriorMu Q*(if i=j then 2 else -1) := by - have he (m : Message) : edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) j = - lam*messageDeviation m j + lam^2*(messageDeviation m i*messageDeviation m j) := by - rw [edge_deviation] - change (1+lam*(m i-1))*(lam*(m j-1)) = _ - simp only [messageDeviation] - ring - simp_rw [he] - have hi : Integrable (fun m => lam*messageDeviation m j) (Q : Measure Message) := - (integrable_continuous_message Q (continuous_messageDeviation j)).const_mul _ - have hj : Integrable (fun m => lam^2*(messageDeviation m i*messageDeviation m j)) (Q : Measure Message) := - (integrable_continuous_message Q ((continuous_messageDeviation i).mul (continuous_messageDeviation j))).const_mul _ - rw [integral_add hi hj, - integral_const_mul, integral_const_mul, integral_deviation Q hQ, - integral_deviation_mul Q hs] - ring - -lemma integral_edge_deviation_sq (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hs : SpinSymmetric Q) (i : Spin) : - (∫ m, (messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message)) = 2*lam^2*posteriorMu Q := by - have he (m : Message) : (messageDeviation (edgeMessage lam h m) i)^2 = - lam^2*(messageDeviation m i*messageDeviation m i) := by rw [edge_deviation]; ring - simp_rw [he] - rw [integral_const_mul, integral_deviation_mul Q hs] - simp only [ite_true] - ring - -lemma avg_swap (f : Spin → Spin → ℝ) : avg (fun i => avg (f i)) = avg (fun j => avg (fun i => f i j)) := by - simp only [Radial.avg_expand] - ring -lemma avg_add (a b : Spin → ℝ) : avg (fun i => a i+b i) = avg a+avg b := by - simp only [Radial.avg_expand] - ring -lemma avg_mul_const (a : Spin → ℝ) (c : ℝ) : avg (fun i => a i*c) = avg a*c := by - simp only [Radial.avg_expand] - ring -lemma avg_const_mul (c : ℝ) (a : Spin → ℝ) : avg (fun i => c*a i) = c*avg a := by - simp only [Radial.avg_expand] - ring -lemma avg_covariance_coeff (j : Spin) : avg (fun i : Spin => (if i=j then (2:ℝ) else -1)^2) = 2 := by - have he (i : Spin) : (if i=j then (2:ℝ) else -1)^2 = 1+(if i=j then (3:ℝ) else 0) := by - split_ifs <;> norm_num - simp only [he, avg, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, - Fintype.card_fin, nsmul_eq_mul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] - norm_num - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -noncomputable def branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : ℝ := - ∑ j, messageDeviation (edgeMessage lam h (m j)) i -lemma continuous_branchSum (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : - Continuous (fun m : Fin n → Message => branchSum lam h m i) := by - apply continuous_finsetSum - intro j _ - exact ((continuous_messageDeviation i).comp (continuous_edgeMessage lam h)).comp (continuous_apply j) -lemma avg_branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - avg (branchSum lam h m) = 0 := by - have he : avg (branchSum lam h m) = ∑ j, avg (messageDeviation (edgeMessage lam h (m j))) := by - simp only [branchSum, Radial.avg_expand] - rw [← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib] - rw [he] - simp only [avg_messageDeviation, Finset.sum_const_zero] - -lemma weighted_deviation_branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - normalizer lam h m * avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i) = - avg (fun i => productWeight lam h m i*branchSum lam h m i) := by - have hh := weighted_avg_combine lam h m (branchSum lam h m) - have hz := avg_branchSum lam h m - simp only [messageDeviation, Radial.avg_expand] at * - nlinarith only [hh, mul_eq_zero_of_right (normalizer lam h m) hz] - -lemma integral_projection_cross (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : - (∫ m : Fin n → Message, normalizer lam h m * - (avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i)/2) - ∂(iidMeasure Q n : Measure (Fin n → Message))) = n*(lam^2*posteriorMu Q) := by - have he (m : Fin n → Message) : normalizer lam h m * - (avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i)/2) = - avg (fun i => productWeight lam h m i*branchSum lam h m i)/2 := by - rw [← mul_div_assoc, weighted_deviation_branchSum] - simp_rw [he] - rw [integral_div, integral_avg] - · have hi (i : Spin) : - (∫ m : Fin n → Message, productWeight lam h m i*branchSum lam h m i - ∂(iidMeasure Q n : Measure (Fin n → Message))) = (n:ℝ)*(lam^2*posteriorMu Q*2) := by - have hh := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeDeviationMap lam h i) - (integral_edgeMessage lam h Q hQ i) - change _ = n*(∫ m, edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) i ∂(Q : Measure Message)) at hh - rw [integral_edge_covariance lam h Q hQ hs] at hh - simpa only [edgeCoordinateMap, edgeDeviationMap, ContinuousMap.coe_mk, productWeight, branchSum, ite_true] using hh - simp_rw [hi] - simp [Radial.avg_expand] - ring - · intro i - exact ((continuous_productWeight lam h n i).mul (continuous_branchSum lam h n i)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -lemma avg_integral_edge_sq (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hs : SpinSymmetric Q) (i : Spin) : - avg (fun k => ∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message)) = - 2*lam^2*posteriorMu Q := by - rw [← integral_avg] - · have he (m : Message) : avg (fun k => edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2) = - (messageDeviation (edgeMessage lam h m) i)^2 := by - rw [avg_mul_const, average_message, one_mul] - simp_rw [he] - exact integral_edge_deviation_sq lam h Q hs i - · intro k - exact integrable_continuous_message Q ((edgeCoordinateMap lam h k).continuous.mul ((edgeDeviationMap lam h i).continuous.pow 2)) - -lemma integral_projection_variance_coordinate (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (i : Spin) : - (∫ m : Fin n → Message, normalizer lam h m*(branchSum lam h m i)^2 - ∂(iidMeasure Q n : Measure (Fin n → Message))) = - 2*((n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2) := by - have he (m : Fin n → Message) : normalizer lam h m*(branchSum lam h m i)^2 = - avg (fun k => productWeight lam h m k*(branchSum lam h m i)^2) := (avg_mul_const _ _).symm - simp_rw [he] - rw [integral_avg] - · have hi (k : Spin) : - (∫ m : Fin n → Message, productWeight lam h m k*(branchSum lam h m i)^2 - ∂(iidMeasure Q n : Measure (Fin n → Message))) = - (n:ℝ)*(∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ - ((n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2)*(if k=i then (2:ℝ) else -1)^2 := by - have hh := iid_integral_weighted_sum_sq Q n (edgeCoordinateMap lam h k) (edgeDeviationMap lam h i) - (integral_edgeMessage lam h Q hQ k) - change _ = n*(∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ - (n:ℝ)*(n-1)*(∫ m, edgeMessage lam h m k*messageDeviation (edgeMessage lam h m) i ∂(Q : Measure Message))^2 at hh - rw [integral_edge_covariance lam h Q hQ hs] at hh - change (∫ m : Fin n → Message, productWeight lam h m k*(branchSum lam h m i)^2 - ∂(iidMeasure Q n : Measure (Fin n → Message))) = _ at hh - rw [hh] - ring - simp_rw [hi] - rw [avg_add, avg_const_mul, avg_const_mul, avg_integral_edge_sq lam h Q hs, avg_covariance_coeff] - ring - · intro k - exact ((continuous_productWeight lam h n k).mul ((continuous_branchSum lam h n i).pow 2)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -lemma integral_projection_variance (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : - (∫ m : Fin n → Message, normalizer lam h m*(avg (fun i => (branchSum lam h m i)^2)/2) - ∂(iidMeasure Q n : Measure (Fin n → Message))) = - (n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2 := by - have he (m : Fin n → Message) : normalizer lam h m*(avg (fun i => (branchSum lam h m i)^2)/2) = - avg (fun i => normalizer lam h m*(branchSum lam h m i)^2)/2 := by rw [avg_const_mul]; ring - simp_rw [he] - rw [integral_div, integral_avg] - · simp_rw [integral_projection_variance_coordinate lam h Q hQ hs] - simp [Radial.avg_expand] - ring - · intro i - exact ((continuous_normalizer lam h n).mul ((continuous_branchSum lam h n i).pow 2)).integrable_of_hasCompactSupport - (HasCompactSupport.of_compactSpace _) - -end ThreeState -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -open Radial (avg) - -lemma weighted_vector_quadratic {α : Type*} [TopologicalSpace α] [CompactSpace α] - [MeasurableSpace α] [BorelSpace α] (M : Measure α) [IsFiniteMeasure M] - (w : α → ℝ) (hw : Continuous w) (hw0 : ∀ a, 0 ≤ w a) - (f g : α → Spin → ℝ) (hf : ∀ i, Continuous (fun a => f a i)) (hg : ∀ i, Continuous (fun a => g a i)) (t : ℝ) : - 0 ≤ (∫ a, w a*(avg (fun i => (f a i)^2)/2) ∂M)*t^2- - 2*(∫ a, w a*(avg (fun i => f a i*g a i)/2) ∂M)*t+ - (∫ a, w a*(avg (fun i => (g a i)^2)/2) ∂M) := by - have hA : Integrable (fun a => w a*(avg (fun i => (f a i)^2)/2)) M := - (hw.mul ((continuous_avg _ (fun i => (hf i).pow 2)).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hB : Integrable (fun a => w a*(avg (fun i => (g a i)^2)/2)) M := - (hw.mul ((continuous_avg _ (fun i => (hg i).pow 2)).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hC : Integrable (fun a => w a*(avg (fun i => f a i*g a i)/2)) M := - (hw.mul ((continuous_avg _ (fun i => (hf i).mul (hg i))).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - have hp : 0 ≤ ∫ a, w a*(avg (fun i => (t*f a i-g a i)^2)/2) ∂M := by - apply integral_nonneg - intro a - apply mul_nonneg (hw0 a) - rw [Radial.avg_expand] - positivity - have he (a : α) : w a*(avg (fun i => (t*f a i-g a i)^2)/2) = - t^2*(w a*(avg (fun i => (f a i)^2)/2))+(-2*t)*(w a*(avg (fun i => f a i*g a i)/2))+ - w a*(avg (fun i => (g a i)^2)/2) := by simp only [Radial.avg_expand]; ring - simp_rw [he] at hp - have hAC : Integrable (fun a => t^2*(w a*(avg (fun i => (f a i)^2)/2))+ - (-2*t)*(w a*(avg (fun i => f a i*g a i)/2))) M := (hA.const_mul _).add (hC.const_mul _) - rw [integral_add hAC hB, - integral_add (hA.const_mul _) (hC.const_mul _), integral_const_mul, integral_const_mul] at hp - nlinarith only [hp] - -lemma degree_projection_quadratic (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (t : ℝ) : - 0 ≤ posteriorMu (degreePosterior lam h Q hQ n)*t^2-2*((n:ℝ)*(lam^2*posteriorMu Q))*t+ - ((n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2) := by - have hh := weighted_vector_quadratic (iidMeasure Q n : Measure (Fin n → Message)) (normalizer lam h) - (continuous_normalizer lam h n) (normalizer_nonneg lam h) - (fun m i => messageDeviation (combineMessage lam h m) i) (branchSum lam h) - (fun i => (continuous_messageDeviation i).comp (continuous_combineMessage_positive lam h hl0 hl1 n)) - (continuous_branchSum lam h n) t - rw [integral_projection_cross lam h Q hQ hs, integral_projection_variance lam h Q hQ hs] at hh - have he : (∫ m : Fin n → Message, normalizer lam h m * - (avg (fun i => (messageDeviation (combineMessage lam h m) i)^2)/2) - ∂(iidMeasure Q n : Measure (Fin n → Message))) = posteriorMu (degreePosterior lam h Q hQ n) := by - change _ = ∫ m, messageX m ∂degreeOutput lam h Q n - rw [integral_degreeOutput lam h Q n messageX continuous_messageX.measurable] - rfl - rwa [he] at hh - -lemma degree_projection (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (hn : 1 ≤ n) : - (n:ℝ)*(lam^2*posteriorMu Q)/(1+((n:ℝ)-1)*(lam^2*posteriorMu Q)) ≤ - posteriorMu (degreePosterior lam h Q hQ n) := by - let beta := lam^2*posteriorMu Q - have hb : 0 ≤ beta := mul_nonneg (sq_nonneg _) (posteriorMu_nonneg Q) - have hn0 : (0:ℝ) A*x) hl] - have hg : 0 ≤ A*(Real.sqrt u+Real.sqrt L)-B := by - nlinarith only [hf, mul_nonneg hA (Real.sqrt_nonneg u)] - have hp := mul_nonneg (sub_nonneg.mpr hroot) hg - nlinarith only [hp, congrArg (fun x => A*x) hl, congrArg (fun x => A*x) hu, hCu] - -noncomputable def pairCorrelation (lam : ℝ) (h : Admissible lam) (Q P : ProbabilityMeasure Message) : ℝ := - ∫ a, pairIncrement lam h Q a ∂(P : Measure Message) - -lemma pairCorrelation_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q P : ProbabilityMeasure Message) (hQ : Balanced Q) : 0 ≤ pairCorrelation lam h Q P := - integral_nonneg (pairIncrement_nonneg lam h hl0 hl1 Q hQ) - -lemma pairCorrelation_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q P : ProbabilityMeasure Message) (hs : SpinSymmetric Q) : - 3*lam^2*posteriorMu Q*posteriorMu P-lam^3*posteriorEta Q*posteriorEta P ≤ 3*pairCorrelation lam h Q P := by - have hi : Integrable (fun a => lam^2*posteriorMu Q*messageX a-lam^3*posteriorEta Q*messageY a/3) (P : Measure Message) := - ((integrable_continuous_message P continuous_messageX).const_mul _).sub - (((integrable_continuous_message P continuous_messageY).const_mul _).div_const _) - have hh := integral_mono hi (integrable_continuous_message P (continuous_pairIncrement lam h hl0 hl1 Q)) - (pairIncrement_lower lam h hl0 hl1 Q hs) - have hix : Integrable (fun a => lam^2*posteriorMu Q*messageX a) (P : Measure Message) := - (integrable_continuous_message P continuous_messageX).const_mul _ - have hiy : Integrable (fun a => lam^3*posteriorEta Q*messageY a/3) (P : Measure Message) := - ((integrable_continuous_message P continuous_messageY).const_mul _).div_const _ - rw [integral_sub hix hiy, integral_div, integral_const_mul, integral_const_mul] at hh - change lam^2*posteriorMu Q*posteriorMu P-lam^3*posteriorEta Q*posteriorEta P/3 ≤ pairCorrelation lam h Q P at hh - linarith - -lemma eta_product_lower_control (Q P : ProbabilityMeasure Message) (he : 0 ≤ posteriorEta Q) - (hn : posteriorNu P ≤ posteriorNu Q) : - posteriorEta Q*posteriorEta P ≤ Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt (posteriorMu P) := by - have hQ := posteriorEta_upper Q - have hP := posteriorEta_upper P - rw [Real.sqrt_mul (posteriorMu_nonneg Q)] at hQ - rw [Real.sqrt_mul (posteriorMu_nonneg P)] at hP - have hP' : posteriorEta P ≤ Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q) := - hP.trans (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hn) (Real.sqrt_nonneg _)) - have hh : posteriorEta Q*posteriorEta P ≤ - (Real.sqrt (posteriorMu Q)*Real.sqrt (posteriorNu Q))*(Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q)) := - (mul_le_mul_of_nonneg_left hP' he).trans - (mul_le_mul_of_nonneg_right hQ (mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _))) - have heq : (Real.sqrt (posteriorMu Q)*Real.sqrt (posteriorNu Q))*(Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q)) = - Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt (posteriorMu P) := by - calc - _ = Real.sqrt (posteriorMu Q)*(Real.sqrt (posteriorNu Q))^2*Real.sqrt (posteriorMu P) := by ring - _ = _ := by rw [Real.sq_sqrt (posteriorNu_nonneg Q)] - rwa [heq] at hh - -lemma pairCorrelation_truncated (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q P : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) - (he : 0 ≤ posteriorEta Q) (hn : posteriorNu P ≤ posteriorNu Q) {L : ℝ} (hL : 0 ≤ L) (hLP : L ≤ posteriorMu P) : - 3*lam^2*posteriorMu Q*L-lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt L ≤ - 3*pairCorrelation lam h Q P := by - have hm := posteriorMu_nonneg Q - have hh := pairCorrelation_lower lam h hl0 hl1 Q P hs - have hg := mul_le_mul_of_nonneg_left (eta_product_lower_control Q P he hn) (pow_nonneg hl0 3) - apply truncated_quadratic_lower (show 0 ≤ 3*lam^2*posteriorMu Q by positivity) hL hLP - (mul_nonneg (by norm_num) (pairCorrelation_nonneg lam h hl0 hl1 Q P hQ)) - nlinarith only [hh,hg] - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.DegreePosterior + +namespace OAI + +/-! Quadratic projections, covariance and truncated correlation estimates. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma symAvg_deviation_mul (a : Message) (i j : Spin) : + symAvg (fun m => messageDeviation m i*messageDeviation m j) a = + (if i=j then 2 else -1)*messageX a := by + fin_cases i <;> fin_cases j <;> + norm_num [symAvg, symPerm, Fin.sum_univ_succ, messageDeviation, + Radial.avg_expand, permMessage, Equiv.swap_apply_def, Equiv.trans_apply, + Equiv.symm_trans_apply, Fin.ext_iff, messageX, Radial.momentX] <;> + (try rw [message_last a]) <;> ring + +lemma continuous_messageDeviation (i : Spin) : Continuous (fun m => messageDeviation m i) := + ((continuous_apply i).comp continuous_subtype_val).sub continuous_const + +lemma integral_deviation (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (i : Spin) : + (∫ m, messageDeviation m i ∂(Q : Measure Message)) = 0 := by + change (∫ m : Message, m i-1 ∂(Q : Measure Message)) = 0 + have hi : Integrable (fun m : Message => m i) (Q : Measure Message) := + integrable_continuous_message Q (coordinateMap i).continuous + rw [integral_sub hi (integrable_const (1:ℝ)), hQ i] + simp + +lemma integral_deviation_mul (Q : ProbabilityMeasure Message) (hs : SpinSymmetric Q) (i j : Spin) : + (∫ m, messageDeviation m i*messageDeviation m j ∂(Q : Measure Message)) = + (if i=j then 2 else -1)*posteriorMu Q := by + rw [← integral_symAvg Q hs (fun m => messageDeviation m i*messageDeviation m j) ((continuous_messageDeviation i).mul (continuous_messageDeviation j))] + simp only [symAvg_deviation_mul, integral_const_mul, posteriorMu] + +noncomputable def edgeDeviationMap (lam : ℝ) (h : Admissible lam) (i : Spin) : C(Message,ℝ) := + ⟨fun m => messageDeviation (edgeMessage lam h m) i, + (continuous_messageDeviation i).comp (continuous_edgeMessage lam h)⟩ + +lemma edge_deviation (lam : ℝ) (h : Admissible lam) (m : Message) (i : Spin) : + messageDeviation (edgeMessage lam h m) i = lam*messageDeviation m i := by + change 1+lam*(m i-1)-1 = lam*(m i-1) + ring + +lemma integral_edge_covariance (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (hs : SpinSymmetric Q) (i j : Spin) : + (∫ m, edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) j ∂(Q : Measure Message)) = + lam^2*posteriorMu Q*(if i=j then 2 else -1) := by + have he (m : Message) : edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) j = + lam*messageDeviation m j + lam^2*(messageDeviation m i*messageDeviation m j) := by + rw [edge_deviation] + change (1+lam*(m i-1))*(lam*(m j-1)) = _ + simp only [messageDeviation] + ring + simp_rw [he] + have hi : Integrable (fun m => lam*messageDeviation m j) (Q : Measure Message) := + (integrable_continuous_message Q (continuous_messageDeviation j)).const_mul _ + have hj : Integrable (fun m => lam^2*(messageDeviation m i*messageDeviation m j)) (Q : Measure Message) := + (integrable_continuous_message Q ((continuous_messageDeviation i).mul (continuous_messageDeviation j))).const_mul _ + rw [integral_add hi hj, + integral_const_mul, integral_const_mul, integral_deviation Q hQ, + integral_deviation_mul Q hs] + ring + +lemma integral_edge_deviation_sq (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hs : SpinSymmetric Q) (i : Spin) : + (∫ m, (messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message)) = 2*lam^2*posteriorMu Q := by + have he (m : Message) : (messageDeviation (edgeMessage lam h m) i)^2 = + lam^2*(messageDeviation m i*messageDeviation m i) := by rw [edge_deviation]; ring + simp_rw [he] + rw [integral_const_mul, integral_deviation_mul Q hs] + simp only [ite_true] + ring + +lemma avg_swap (f : Spin → Spin → ℝ) : avg (fun i => avg (f i)) = avg (fun j => avg (fun i => f i j)) := by + simp only [Radial.avg_expand] + ring +lemma avg_add (a b : Spin → ℝ) : avg (fun i => a i+b i) = avg a+avg b := by + simp only [Radial.avg_expand] + ring +lemma avg_mul_const (a : Spin → ℝ) (c : ℝ) : avg (fun i => a i*c) = avg a*c := by + simp only [Radial.avg_expand] + ring +lemma avg_const_mul (c : ℝ) (a : Spin → ℝ) : avg (fun i => c*a i) = c*avg a := by + simp only [Radial.avg_expand] + ring +lemma avg_covariance_coeff (j : Spin) : avg (fun i : Spin => (if i=j then (2:ℝ) else -1)^2) = 2 := by + have he (i : Spin) : (if i=j then (2:ℝ) else -1)^2 = 1+(if i=j then (3:ℝ) else 0) := by + split_ifs <;> norm_num + simp only [he, avg, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + norm_num + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +noncomputable def branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : ℝ := + ∑ j, messageDeviation (edgeMessage lam h (m j)) i +lemma continuous_branchSum (lam : ℝ) (h : Admissible lam) (n : ℕ) (i : Spin) : + Continuous (fun m : Fin n → Message => branchSum lam h m i) := by + apply continuous_finsetSum + intro j _ + exact ((continuous_messageDeviation i).comp (continuous_edgeMessage lam h)).comp (continuous_apply j) +lemma avg_branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + avg (branchSum lam h m) = 0 := by + have he : avg (branchSum lam h m) = ∑ j, avg (messageDeviation (edgeMessage lam h (m j))) := by + simp only [branchSum, Radial.avg_expand] + rw [← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib] + rw [he] + simp only [avg_messageDeviation, Finset.sum_const_zero] + +lemma weighted_deviation_branchSum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + normalizer lam h m * avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i) = + avg (fun i => productWeight lam h m i*branchSum lam h m i) := by + have hh := weighted_avg_combine lam h m (branchSum lam h m) + have hz := avg_branchSum lam h m + simp only [messageDeviation, Radial.avg_expand] at * + nlinarith only [hh, mul_eq_zero_of_right (normalizer lam h m) hz] + +lemma integral_projection_cross (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : + (∫ m : Fin n → Message, normalizer lam h m * + (avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i)/2) + ∂(iidMeasure Q n : Measure (Fin n → Message))) = n*(lam^2*posteriorMu Q) := by + have he (m : Fin n → Message) : normalizer lam h m * + (avg (fun i => messageDeviation (combineMessage lam h m) i*branchSum lam h m i)/2) = + avg (fun i => productWeight lam h m i*branchSum lam h m i)/2 := by + rw [← mul_div_assoc, weighted_deviation_branchSum] + simp_rw [he] + rw [integral_div, integral_avg] + · have hi (i : Spin) : + (∫ m : Fin n → Message, productWeight lam h m i*branchSum lam h m i + ∂(iidMeasure Q n : Measure (Fin n → Message))) = (n:ℝ)*(lam^2*posteriorMu Q*2) := by + have hh := iid_integral_weighted_sum Q n (edgeCoordinateMap lam h i) (edgeDeviationMap lam h i) + (integral_edgeMessage lam h Q hQ i) + change _ = n*(∫ m, edgeMessage lam h m i*messageDeviation (edgeMessage lam h m) i ∂(Q : Measure Message)) at hh + rw [integral_edge_covariance lam h Q hQ hs] at hh + simpa only [edgeCoordinateMap, edgeDeviationMap, ContinuousMap.coe_mk, productWeight, branchSum, ite_true] using hh + simp_rw [hi] + simp [Radial.avg_expand] + ring + · intro i + exact ((continuous_productWeight lam h n i).mul (continuous_branchSum lam h n i)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma avg_integral_edge_sq (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hs : SpinSymmetric Q) (i : Spin) : + avg (fun k => ∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message)) = + 2*lam^2*posteriorMu Q := by + rw [← integral_avg] + · have he (m : Message) : avg (fun k => edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2) = + (messageDeviation (edgeMessage lam h m) i)^2 := by + rw [avg_mul_const, average_message, one_mul] + simp_rw [he] + exact integral_edge_deviation_sq lam h Q hs i + · intro k + exact integrable_continuous_message Q ((edgeCoordinateMap lam h k).continuous.mul ((edgeDeviationMap lam h i).continuous.pow 2)) + +lemma integral_projection_variance_coordinate (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (i : Spin) : + (∫ m : Fin n → Message, normalizer lam h m*(branchSum lam h m i)^2 + ∂(iidMeasure Q n : Measure (Fin n → Message))) = + 2*((n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2) := by + have he (m : Fin n → Message) : normalizer lam h m*(branchSum lam h m i)^2 = + avg (fun k => productWeight lam h m k*(branchSum lam h m i)^2) := (avg_mul_const _ _).symm + simp_rw [he] + rw [integral_avg] + · have hi (k : Spin) : + (∫ m : Fin n → Message, productWeight lam h m k*(branchSum lam h m i)^2 + ∂(iidMeasure Q n : Measure (Fin n → Message))) = + (n:ℝ)*(∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ + ((n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2)*(if k=i then (2:ℝ) else -1)^2 := by + have hh := iid_integral_weighted_sum_sq Q n (edgeCoordinateMap lam h k) (edgeDeviationMap lam h i) + (integral_edgeMessage lam h Q hQ k) + change _ = n*(∫ m, edgeMessage lam h m k*(messageDeviation (edgeMessage lam h m) i)^2 ∂(Q : Measure Message))+ + (n:ℝ)*(n-1)*(∫ m, edgeMessage lam h m k*messageDeviation (edgeMessage lam h m) i ∂(Q : Measure Message))^2 at hh + rw [integral_edge_covariance lam h Q hQ hs] at hh + change (∫ m : Fin n → Message, productWeight lam h m k*(branchSum lam h m i)^2 + ∂(iidMeasure Q n : Measure (Fin n → Message))) = _ at hh + rw [hh] + ring + simp_rw [hi] + rw [avg_add, avg_const_mul, avg_const_mul, avg_integral_edge_sq lam h Q hs, avg_covariance_coeff] + ring + · intro k + exact ((continuous_productWeight lam h n k).mul ((continuous_branchSum lam h n i).pow 2)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma integral_projection_variance (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) : + (∫ m : Fin n → Message, normalizer lam h m*(avg (fun i => (branchSum lam h m i)^2)/2) + ∂(iidMeasure Q n : Measure (Fin n → Message))) = + (n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2 := by + have he (m : Fin n → Message) : normalizer lam h m*(avg (fun i => (branchSum lam h m i)^2)/2) = + avg (fun i => normalizer lam h m*(branchSum lam h m i)^2)/2 := by rw [avg_const_mul]; ring + simp_rw [he] + rw [integral_div, integral_avg] + · simp_rw [integral_projection_variance_coordinate lam h Q hQ hs] + simp [Radial.avg_expand] + ring + · intro i + exact ((continuous_normalizer lam h n).mul ((continuous_branchSum lam h n i).pow 2)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +end ThreeState +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +open Radial (avg) + +lemma weighted_vector_quadratic {α : Type*} [TopologicalSpace α] [CompactSpace α] + [MeasurableSpace α] [BorelSpace α] (M : Measure α) [IsFiniteMeasure M] + (w : α → ℝ) (hw : Continuous w) (hw0 : ∀ a, 0 ≤ w a) + (f g : α → Spin → ℝ) (hf : ∀ i, Continuous (fun a => f a i)) (hg : ∀ i, Continuous (fun a => g a i)) (t : ℝ) : + 0 ≤ (∫ a, w a*(avg (fun i => (f a i)^2)/2) ∂M)*t^2- + 2*(∫ a, w a*(avg (fun i => f a i*g a i)/2) ∂M)*t+ + (∫ a, w a*(avg (fun i => (g a i)^2)/2) ∂M) := by + have hA : Integrable (fun a => w a*(avg (fun i => (f a i)^2)/2)) M := + (hw.mul ((continuous_avg _ (fun i => (hf i).pow 2)).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hB : Integrable (fun a => w a*(avg (fun i => (g a i)^2)/2)) M := + (hw.mul ((continuous_avg _ (fun i => (hg i).pow 2)).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hC : Integrable (fun a => w a*(avg (fun i => f a i*g a i)/2)) M := + (hw.mul ((continuous_avg _ (fun i => (hf i).mul (hg i))).div_const 2)).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hp : 0 ≤ ∫ a, w a*(avg (fun i => (t*f a i-g a i)^2)/2) ∂M := by + apply integral_nonneg + intro a + apply mul_nonneg (hw0 a) + rw [Radial.avg_expand] + positivity + have he (a : α) : w a*(avg (fun i => (t*f a i-g a i)^2)/2) = + t^2*(w a*(avg (fun i => (f a i)^2)/2))+(-2*t)*(w a*(avg (fun i => f a i*g a i)/2))+ + w a*(avg (fun i => (g a i)^2)/2) := by simp only [Radial.avg_expand]; ring + simp_rw [he] at hp + have hAC : Integrable (fun a => t^2*(w a*(avg (fun i => (f a i)^2)/2))+ + (-2*t)*(w a*(avg (fun i => f a i*g a i)/2))) M := (hA.const_mul _).add (hC.const_mul _) + rw [integral_add hAC hB, + integral_add (hA.const_mul _) (hC.const_mul _), integral_const_mul, integral_const_mul] at hp + nlinarith only [hp] + +lemma degree_projection_quadratic (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (t : ℝ) : + 0 ≤ posteriorMu (degreePosterior lam h Q hQ n)*t^2-2*((n:ℝ)*(lam^2*posteriorMu Q))*t+ + ((n:ℝ)*(lam^2*posteriorMu Q)+(n:ℝ)*(n-1)*(lam^2*posteriorMu Q)^2) := by + have hh := weighted_vector_quadratic (iidMeasure Q n : Measure (Fin n → Message)) (normalizer lam h) + (continuous_normalizer lam h n) (normalizer_nonneg lam h) + (fun m i => messageDeviation (combineMessage lam h m) i) (branchSum lam h) + (fun i => (continuous_messageDeviation i).comp (continuous_combineMessage_positive lam h hl0 hl1 n)) + (continuous_branchSum lam h n) t + rw [integral_projection_cross lam h Q hQ hs, integral_projection_variance lam h Q hQ hs] at hh + have he : (∫ m : Fin n → Message, normalizer lam h m * + (avg (fun i => (messageDeviation (combineMessage lam h m) i)^2)/2) + ∂(iidMeasure Q n : Measure (Fin n → Message))) = posteriorMu (degreePosterior lam h Q hQ n) := by + change _ = ∫ m, messageX m ∂degreeOutput lam h Q n + rw [integral_degreeOutput lam h Q n messageX continuous_messageX.measurable] + rfl + rwa [he] at hh + +lemma degree_projection (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) (n : ℕ) (hn : 1 ≤ n) : + (n:ℝ)*(lam^2*posteriorMu Q)/(1+((n:ℝ)-1)*(lam^2*posteriorMu Q)) ≤ + posteriorMu (degreePosterior lam h Q hQ n) := by + let beta := lam^2*posteriorMu Q + have hb : 0 ≤ beta := mul_nonneg (sq_nonneg _) (posteriorMu_nonneg Q) + have hn0 : (0:ℝ) A*x) hl] + have hg : 0 ≤ A*(Real.sqrt u+Real.sqrt L)-B := by + nlinarith only [hf, mul_nonneg hA (Real.sqrt_nonneg u)] + have hp := mul_nonneg (sub_nonneg.mpr hroot) hg + nlinarith only [hp, congrArg (fun x => A*x) hl, congrArg (fun x => A*x) hu, hCu] + +noncomputable def pairCorrelation (lam : ℝ) (h : Admissible lam) (Q P : ProbabilityMeasure Message) : ℝ := + ∫ a, pairIncrement lam h Q a ∂(P : Measure Message) + +lemma pairCorrelation_nonneg (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q P : ProbabilityMeasure Message) (hQ : Balanced Q) : 0 ≤ pairCorrelation lam h Q P := + integral_nonneg (pairIncrement_nonneg lam h hl0 hl1 Q hQ) + +lemma pairCorrelation_lower (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q P : ProbabilityMeasure Message) (hs : SpinSymmetric Q) : + 3*lam^2*posteriorMu Q*posteriorMu P-lam^3*posteriorEta Q*posteriorEta P ≤ 3*pairCorrelation lam h Q P := by + have hi : Integrable (fun a => lam^2*posteriorMu Q*messageX a-lam^3*posteriorEta Q*messageY a/3) (P : Measure Message) := + ((integrable_continuous_message P continuous_messageX).const_mul _).sub + (((integrable_continuous_message P continuous_messageY).const_mul _).div_const _) + have hh := integral_mono hi (integrable_continuous_message P (continuous_pairIncrement lam h hl0 hl1 Q)) + (pairIncrement_lower lam h hl0 hl1 Q hs) + have hix : Integrable (fun a => lam^2*posteriorMu Q*messageX a) (P : Measure Message) := + (integrable_continuous_message P continuous_messageX).const_mul _ + have hiy : Integrable (fun a => lam^3*posteriorEta Q*messageY a/3) (P : Measure Message) := + ((integrable_continuous_message P continuous_messageY).const_mul _).div_const _ + rw [integral_sub hix hiy, integral_div, integral_const_mul, integral_const_mul] at hh + change lam^2*posteriorMu Q*posteriorMu P-lam^3*posteriorEta Q*posteriorEta P/3 ≤ pairCorrelation lam h Q P at hh + linarith + +lemma eta_product_lower_control (Q P : ProbabilityMeasure Message) (he : 0 ≤ posteriorEta Q) + (hn : posteriorNu P ≤ posteriorNu Q) : + posteriorEta Q*posteriorEta P ≤ Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt (posteriorMu P) := by + have hQ := posteriorEta_upper Q + have hP := posteriorEta_upper P + rw [Real.sqrt_mul (posteriorMu_nonneg Q)] at hQ + rw [Real.sqrt_mul (posteriorMu_nonneg P)] at hP + have hP' : posteriorEta P ≤ Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q) := + hP.trans (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hn) (Real.sqrt_nonneg _)) + have hh : posteriorEta Q*posteriorEta P ≤ + (Real.sqrt (posteriorMu Q)*Real.sqrt (posteriorNu Q))*(Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q)) := + (mul_le_mul_of_nonneg_left hP' he).trans + (mul_le_mul_of_nonneg_right hQ (mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _))) + have heq : (Real.sqrt (posteriorMu Q)*Real.sqrt (posteriorNu Q))*(Real.sqrt (posteriorMu P)*Real.sqrt (posteriorNu Q)) = + Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt (posteriorMu P) := by + calc + _ = Real.sqrt (posteriorMu Q)*(Real.sqrt (posteriorNu Q))^2*Real.sqrt (posteriorMu P) := by ring + _ = _ := by rw [Real.sq_sqrt (posteriorNu_nonneg Q)] + rwa [heq] at hh + +lemma pairCorrelation_truncated (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q P : ProbabilityMeasure Message) (hQ : Balanced Q) (hs : SpinSymmetric Q) + (he : 0 ≤ posteriorEta Q) (hn : posteriorNu P ≤ posteriorNu Q) {L : ℝ} (hL : 0 ≤ L) (hLP : L ≤ posteriorMu P) : + 3*lam^2*posteriorMu Q*L-lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*Real.sqrt L ≤ + 3*pairCorrelation lam h Q P := by + have hm := posteriorMu_nonneg Q + have hh := pairCorrelation_lower lam h hl0 hl1 Q P hs + have hg := mul_le_mul_of_nonneg_left (eta_product_lower_control Q P he hn) (pow_nonneg hl0 3) + apply truncated_quadratic_lower (show 0 ≤ 3*lam^2*posteriorMu Q by positivity) hL hLP + (mul_nonneg (by norm_num) (pairCorrelation_nonneg lam h hl0 hl1 Q P hQ)) + nlinarith only [hh,hg] + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/RadialDerivatives.lean b/lean/OAI/Probability/ThreeState/RadialDerivatives.lean index 2acee507e3ebb14d26395e8ae8e0c123b363fdb7..c10844e8dc8f8515b7d0d10a0b68a730b23b905e 100644 --- a/lean/OAI/Probability/ThreeState/RadialDerivatives.lean +++ b/lean/OAI/Probability/ThreeState/RadialDerivatives.lean @@ -1,452 +1,452 @@ -import Mathlib -import OAI.Probability.ThreeState.RadialMoments - -namespace OAI - -/-! Radial logarithmic derivatives and the entropy inequality. -/ - -namespace ThreeState.Radial - -noncomputable def ray (v : Fin 3 → ℝ) (t : ℝ) : Fin 3 → ℝ := fun i => t*v i -noncomputable def logAvg (v : Fin 3 → ℝ) := avg (fun i => Real.log (1+v i)) -noncomputable def logVariance (v : Fin 3 → ℝ) := avg (fun i => (centeredLog v i)^2) -noncomputable def weightedLogVariance (v : Fin 3 → ℝ) := - avg (fun i => (1+v i)*(centeredLog v i)^2) - -noncomputable def energy (v : Fin 3 → ℝ) := - 3*logAvg v+2*logMoment v+(2/5 : ℝ)*weightedLogVariance v - -noncomputable def gapY (v : Fin 3 → ℝ) := - 1-invMoment v 1-6*logAvg v-2*logMoment v-(2/5 : ℝ)*weightedLogVariance v- - (2/5 : ℝ)*logVariance v+(4/5 : ℝ)*invMoment v 1*logMoment v-(momentX v)^2 - -noncomputable def gapZ (v : Fin 3 → ℝ) := - 6*logAvg v-5+(26/5 : ℝ)*invMoment v 1-invMoment v 2+ - (4/5 : ℝ)*logVariance v+(4/5 : ℝ)*(invMoment v 2-2*invMoment v 1)*logMoment v+ - (4/5 : ℝ)*logInvMoment v 1+(4/5 : ℝ)*(invMoment v 1)^2-3*(momentX v)^2 - -lemma avg_hasDerivAt (f : Fin 3 → ℝ → ℝ) (f' : Fin 3 → ℝ) (t : ℝ) - (hf : ∀ i, HasDerivAt (f i) (f' i) t) : - HasDerivAt (fun t => avg (fun i => f i t)) (avg f') t := by - simp only [avg_expand] - exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 - -lemma avg_ray (v : Fin 3 → ℝ) (t : ℝ) : avg (ray v t) = t*avg v := by - simp only [avg_expand, ray]; ring -lemma X_ray (v : Fin 3 → ℝ) (t : ℝ) : momentX (ray v t) = t^2*momentX v := by - simp only [momentX, avg_expand, ray]; ring -lemma centeredLog_avg_zero (v : Fin 3 → ℝ) : avg (centeredLog v) = 0 := by - simp only [centeredLog, avg_expand]; ring - -lemma ray_log_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) - (i : Fin 3) : HasDerivAt (fun t => Real.log (1+t*v i)) (v i/(1+t*v i)) t := by - simpa using (((hasDerivAt_id t).mul_const (v i)).const_add 1).log (hp i) -lemma ray_inv_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) - (i : Fin 3) : HasDerivAt (fun t => (1+t*v i)⁻¹) (-v i/(1+t*v i)^2) t := by - convert (((hasDerivAt_id t).mul_const (v i)).const_add 1).inv (hp i) using 1 <;> - first | rfl | norm_num - -lemma logAvg_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => logAvg (ray v t)) ((1-invMoment (ray v t) 1)/t) t := by - have hh := avg_hasDerivAt (fun i t => Real.log (1+t*v i)) (fun i => v i/(1+t*v i)) t - (ray_log_hasDerivAt v t hp) - convert hh using 1 - · rfl - · simp only [invMoment, avg_expand, ray, pow_one] - field_simp [hp 0, hp 1, hp 2] - ring - -lemma centeredLog_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) (i : Fin 3) : - HasDerivAt (fun t => centeredLog (ray v t) i) - ((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t) t := by - have hh := (ray_log_hasDerivAt v t hp i).sub (logAvg_hasDerivAt v t ht hp) - convert hh using 1 <;> first | rfl | (field_simp [hp i]; ring) - -lemma invMoment_one_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => invMoment (ray v t) 1) - ((invMoment (ray v t) 2-invMoment (ray v t) 1)/t) t := by - have hh := avg_hasDerivAt (fun i t => (1+t*v i)⁻¹) - (fun i => -v i/(1+t*v i)^2) t (ray_inv_hasDerivAt v t hp) - convert hh using 1 - · simp only [invMoment, ray, pow_one] - · simp only [invMoment, avg_expand, ray, pow_one] - field_simp [hp 0, hp 1, hp 2] - ring - -lemma invMoment_two_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => invMoment (ray v t) 2) - ((2*(invMoment (ray v t) 3-invMoment (ray v t) 2))/t) t := by - have hh := avg_hasDerivAt (fun i t => ((1+t*v i)⁻¹)^2) - (fun i => 2*(1+t*v i)⁻¹*(-v i/(1+t*v i)^2)) t - (fun i => by - convert (ray_inv_hasDerivAt v t hp i).pow 2 using 1; first | rfl | norm_num) - convert hh using 1 - · rfl - · simp only [invMoment, avg_expand, ray] - field_simp [hp 0, hp 1, hp 2] - ring - -lemma logMoment_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => logMoment (ray v t)) - ((logMoment (ray v t)+invMoment (ray v t) 1-1)/t) t := by - have hh := avg_hasDerivAt - (fun i t => t*v i*centeredLog (ray v t) i) - (fun i => v i*centeredLog (ray v t) i+t*v i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)) t - (fun i => by - convert ((hasDerivAt_id t).mul_const (v i)).mul (centeredLog_hasDerivAt v t ht hp i) using 1 <;> - first | rfl | simp) - have hv2 := zero_sum_elim v hv - convert hh using 1 - · rfl - · simp only [logMoment, invMoment, avg_expand, ray, pow_one] - field_simp [hp 0, hp 1, hp 2] - rw [hv2] - ring - -lemma logVariance_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => logVariance (ray v t)) - ((-2*logInvMoment (ray v t) 1)/t) t := by - have hh := avg_hasDerivAt - (fun i t => (centeredLog (ray v t) i)^2) - (fun i => 2*centeredLog (ray v t) i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)) t - (fun i => by - convert (centeredLog_hasDerivAt v t ht hp i).pow 2 using 1; first | rfl | norm_num) - have hu2 := zero_sum_elim (centeredLog (ray v t)) (centeredLog_avg_zero (ray v t)) - convert hh using 1 - · rfl - · simp only [logInvMoment, invMoment, avg_expand, pow_one] - simp only [hu2, ray] - ring - -lemma weightedLogVariance_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => weightedLogVariance (ray v t)) - ((weightedLogVariance (ray v t)-logVariance (ray v t)+ - 2*invMoment (ray v t) 1*logMoment (ray v t))/t) t := by - have hh := avg_hasDerivAt - (fun i t => (1+t*v i)*(centeredLog (ray v t) i)^2) - (fun i => v i*(centeredLog (ray v t) i)^2+(1+t*v i)* - (2*centeredLog (ray v t) i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t))) t - (fun i => by - convert (((hasDerivAt_id t).mul_const (v i)).const_add 1).mul - ((centeredLog_hasDerivAt v t ht hp i).pow 2) using 1 <;> first | rfl | norm_num) - have hu2 := zero_sum_elim (centeredLog (ray v t)) (centeredLog_avg_zero (ray v t)) - convert hh using 1 - · rfl - · simp only [weightedLogVariance, logVariance, logMoment, invMoment, avg_expand, pow_one] - simp only [hu2, ray] - field_simp [hp 0, hp 1, hp 2] - ring - -lemma logInvMoment_one_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => logInvMoment (ray v t) 1) - (((invMoment (ray v t) 1)^2-invMoment (ray v t) 2- - logInvMoment (ray v t) 1+logInvMoment (ray v t) 2)/t) t := by - have hh := avg_hasDerivAt - (fun i t => centeredLog (ray v t) i*(1+t*v i)⁻¹) - (fun i => ((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)*(1+t*v i)⁻¹+ - centeredLog (ray v t) i*(-v i/(1+t*v i)^2)) t - (fun i => (centeredLog_hasDerivAt v t ht hp i).mul (ray_inv_hasDerivAt v t hp i)) - convert hh using 1 - · simp only [logInvMoment, ray, pow_one] - · simp only [logInvMoment, invMoment, avg_expand, pow_one, ray] - field_simp [hp 0, hp 1, hp 2] - ring - -lemma X_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) : - HasDerivAt (fun t => momentX (ray v t)) (2*t*momentX v) t := by - simp_rw [X_ray] - convert ((hasDerivAt_id t).pow 2).mul_const (momentX v) using 1 <;> first | rfl | norm_num - -lemma energy_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => energy (ray v t)) - ((gapY (ray v t)+2*energy (ray v t)+(momentX (ray v t))^2)/t) t := by - have hh := (((logAvg_hasDerivAt v t ht hp).const_mul 3).add - ((logMoment_hasDerivAt v hv t ht hp).const_mul 2)).add - ((weightedLogVariance_hasDerivAt v t ht hp).const_mul (2/5 : ℝ)) - convert hh using 1 <;> first | rfl | (simp only [gapY, energy]; ring) - -lemma gapY_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => gapY (ray v t)) - ((gapZ (ray v t)+gapY (ray v t))/t) t := by - have hg := logAvg_hasDerivAt v t ht hp - have hm := logMoment_hasDerivAt v hv t ht hp - have hu := invMoment_one_hasDerivAt v t ht hp - have hvv := weightedLogVariance_hasDerivAt v t ht hp - have hw := logVariance_hasDerivAt v t ht hp - have hx := X_hasDerivAt v t - have hh := (((((((hasDerivAt_const t (1 : ℝ)).sub hu).sub (hg.const_mul 6)).sub - (hm.const_mul 2)).sub (hvv.const_mul (2/5 : ℝ))).sub (hw.const_mul (2/5 : ℝ))).add - ((hu.const_mul (4/5 : ℝ)).mul hm)).sub (hx.pow 2) - convert hh using 1 <;> first | rfl | (simp only [gapY, gapZ, X_ray]; field_simp; ring) - -lemma gapZ_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) - (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => gapZ (ray v t)) - ((gExpr (ray v t)-12*(momentX (ray v t))^2)/t) t := by - have hg := logAvg_hasDerivAt v t ht hp - have hm := logMoment_hasDerivAt v hv t ht hp - have hu := invMoment_one_hasDerivAt v t ht hp - have hu2 := invMoment_two_hasDerivAt v t ht hp - have hw := logVariance_hasDerivAt v t ht hp - have hs := logInvMoment_one_hasDerivAt v t ht hp - have hx := X_hasDerivAt v t - have hh := ((((((((hg.const_mul 6).sub_const 5).add (hu.const_mul (26/5 : ℝ))).sub hu2).add - (hw.const_mul (4/5 : ℝ))).add - (((hu2.sub (hu.const_mul 2)).const_mul (4/5 : ℝ)).mul hm)).add - (hs.const_mul (4/5 : ℝ))).add ((hu.pow 2).const_mul (4/5 : ℝ))).sub - ((hx.pow 2).const_mul 3) - convert hh using 1 <;> first | rfl | (simp only [gExpr, X_ray, Pi.sub_apply]; field_simp; ring) - -end ThreeState.Radial -namespace ThreeState.Radial - -@[simp] lemma ray_zero (v : Fin 3 → ℝ) : ray v 0 = 0 := by ext i; simp [ray] -@[simp] lemma ray_one (v : Fin 3 → ℝ) : ray v 1 = v := by ext i; simp [ray] -@[simp] lemma logAvg_zero : logAvg 0 = 0 := by norm_num [logAvg, avg_expand] -@[simp] lemma centeredLog_zero (i : Fin 3) : centeredLog 0 i = 0 := by - norm_num [centeredLog, avg_expand] -@[simp] lemma logMoment_zero : logMoment 0 = 0 := by norm_num [logMoment, avg_expand] -@[simp] lemma logVariance_zero : logVariance 0 = 0 := by norm_num [logVariance, avg_expand] -@[simp] lemma weightedLogVariance_zero : weightedLogVariance 0 = 0 := by - norm_num [weightedLogVariance, avg_expand] -@[simp] lemma invMoment_zero (n : ℕ) : invMoment 0 n = 1 := by - norm_num [invMoment, avg_expand] -@[simp] lemma logInvMoment_zero (n : ℕ) : logInvMoment 0 n = 0 := by - norm_num [logInvMoment, avg_expand] -@[simp] lemma momentX_zero : momentX 0 = 0 := by norm_num [momentX, avg_expand] -@[simp] lemma energy_zero : energy 0 = 0 := by norm_num [energy] -@[simp] lemma gapY_zero : gapY 0 = 0 := by norm_num [gapY] -@[simp] lemma gapZ_zero : gapZ 0 = 0 := by norm_num [gapZ] - -lemma logAvg_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => logAvg (ray v t)) 0 0 := by - have hh := avg_hasDerivAt (fun i t => Real.log (1+t*v i)) v 0 (fun i => by - simpa using ray_log_hasDerivAt v 0 (by simp) i) - simpa [logAvg, ray, hv] using hh - -lemma centeredLog_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : - HasDerivAt (fun t => centeredLog (ray v t) i) (v i) 0 := by - have hh := (ray_log_hasDerivAt v 0 (by simp) i).sub (logAvg_hasDerivAt_zero v hv) - convert hh using 1 <;> first | rfl | simp - -lemma invMoment_one_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => invMoment (ray v t) 1) 0 0 := by - have hh := avg_hasDerivAt (fun i t => (1+t*v i)⁻¹) (fun i => -v i) 0 - (fun i => by simpa using ray_inv_hasDerivAt v 0 (by simp) i) - have hz : avg (fun i => -v i) = 0 := by simp only [avg_expand] at *; linarith - simpa [invMoment, ray, hz] using hh - -lemma logMoment_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => logMoment (ray v t)) 0 0 := by - have hh := avg_hasDerivAt (fun i t => t*v i*centeredLog (ray v t) i) (fun _ => 0) 0 - (fun i => by - convert ((hasDerivAt_id (0 : ℝ)).mul_const (v i)).mul - (centeredLog_hasDerivAt_zero v hv i) using 1 <;> first | rfl | simp) - simpa [logMoment, ray, avg_expand, centeredLog] using hh - -lemma logVariance_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => logVariance (ray v t)) 0 0 := by - have hh := avg_hasDerivAt (fun i t => (centeredLog (ray v t) i)^2) (fun _ => 0) 0 - (fun i => by - convert (centeredLog_hasDerivAt_zero v hv i).pow 2 using 1; first | rfl | simp) - simpa [logVariance, avg_expand] using hh - -lemma weightedLogVariance_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => weightedLogVariance (ray v t)) 0 0 := by - have hh := avg_hasDerivAt (fun i t => (1+t*v i)*(centeredLog (ray v t) i)^2) (fun _ => 0) 0 - (fun i => by - convert (((hasDerivAt_id (0 : ℝ)).mul_const (v i)).const_add 1).mul - ((centeredLog_hasDerivAt_zero v hv i).pow 2) using 1 <;> first | rfl | simp) - simpa [weightedLogVariance, ray, avg_expand, centeredLog] using hh - -lemma gapY_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - HasDerivAt (fun t => gapY (ray v t)) 0 0 := by - have hu := invMoment_one_hasDerivAt_zero v hv - have hm := logMoment_hasDerivAt_zero v hv - have hh := (((((((hasDerivAt_const (0 : ℝ) (1 : ℝ)).sub hu).sub - ((logAvg_hasDerivAt_zero v hv).const_mul 6)).sub (hm.const_mul 2)).sub - ((weightedLogVariance_hasDerivAt_zero v hv).const_mul (2/5 : ℝ))).sub - ((logVariance_hasDerivAt_zero v hv).const_mul (2/5 : ℝ))).add - ((hu.const_mul (4/5 : ℝ)).mul hm)).sub ((X_hasDerivAt v 0).pow 2) - convert hh using 1 <;> first | rfl | simp - -lemma logAvg_continuousAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) : - ContinuousAt (fun t => logAvg (ray v t)) t := by - have hh (i : Fin 3) := (ray_log_hasDerivAt v t hp i).continuousAt - simp only [logAvg, avg_expand, ray] - exact (((hh 0).add (hh 1)).add (hh 2)).div_const 3 - -lemma centeredLog_continuousAt (v : Fin 3 → ℝ) (t : ℝ) - (hp : ∀ i, 1+t*v i ≠ 0) (i : Fin 3) : - ContinuousAt (fun t => centeredLog (ray v t) i) t := - ((ray_log_hasDerivAt v t hp i).continuousAt).sub (logAvg_continuousAt v t hp) - -lemma gapZ_continuousAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) : - ContinuousAt (fun t => gapZ (ray v t)) t := by - have hg := logAvg_continuousAt v t hp - have hu (i : Fin 3) := centeredLog_continuousAt v t hp i - have hinv (i : Fin 3) := (ray_inv_hasDerivAt v t hp i).continuousAt - unfold gapZ invMoment logMoment logVariance logInvMoment momentX - simp only [avg_expand, ray] - fun_prop - -lemma normalized_gapY_continuousAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : - ContinuousAt (fun t => gapY (ray v t)/t) 0 := by - have hh := (gapY_hasDerivAt_zero v hv).continuousAt_div - simp only [ray_zero, gapY_zero, sub_zero] at hh - have heq : Function.update (fun t => gapY (ray v t)/t) 0 0 = - (fun t => gapY (ray v t)/t) := by - ext t - by_cases ht : t = 0 - · simp [ht] - · simp [Function.update, ht] - rwa [heq] at hh - -lemma gapZ_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ gapZ (ray v t) := by - have hmono : MonotoneOn (fun t => gapZ (ray v t)) (Set.Icc (0 : ℝ) 1) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => - (gExpr (ray v t)-12*(momentX (ray v t))^2)/t) (convex_Icc _ _) - · intro s hs - exact (gapZ_continuousAt v s (fun i => - ne_of_gt (message_segment_pos v hp s hs.1 hs.2 i))).continuousWithinAt - · intro s hs - rw [interior_Icc] at hs - exact (gapZ_hasDerivAt v hv s hs.1.ne' (fun i => - ne_of_gt (message_segment_pos v hp s hs.1.le hs.2.le i))).hasDerivWithinAt - · intro s hs - rw [interior_Icc] at hs - apply div_nonneg _ hs.1.le - apply sub_nonneg.mpr - apply gExpr_lower (ray v s) - · rw [avg_ray, hv, mul_zero] - · exact fun i => message_segment_pos v hp s hs.1.le hs.2.le i - simpa using hmono (by simp) ⟨ht0, ht1⟩ ht0 - -lemma normalized_gapY_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) - (t : ℝ) (ht : t ≠ 0) (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => gapY (ray v t)/t) (gapZ (ray v t)/t^2) t := by - have hh := (gapY_hasDerivAt v hv t ht hp).div (hasDerivAt_id t) ht - convert hh using 1 <;> first | rfl | (simp only [id_eq]; field_simp; ring) - -lemma gapY_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ gapY (ray v t) := by - have hmono : MonotoneOn (fun t => gapY (ray v t)/t) (Set.Icc (0 : ℝ) 1) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => - gapZ (ray v t)/t^2) (convex_Icc _ _) - · intro s hs - rcases eq_or_lt_of_le hs.1 with h | h - · rw [← h] - exact (normalized_gapY_continuousAt_zero v hv).continuousWithinAt - · exact (normalized_gapY_hasDerivAt v hv s h.ne' (fun i => - ne_of_gt (message_segment_pos v hp s hs.1 hs.2 i))).continuousAt.continuousWithinAt - · intro s hs - rw [interior_Icc] at hs - exact (normalized_gapY_hasDerivAt v hv s hs.1.ne' (fun i => - ne_of_gt (message_segment_pos v hp s hs.1.le hs.2.le i))).hasDerivWithinAt - · intro s hs - rw [interior_Icc] at hs - exact div_nonneg (gapZ_nonneg v hv hp s hs.1.le hs.2.le) (sq_nonneg s) - have h := hmono (by simp) ⟨ht0, ht1⟩ ht0 - simp only [div_zero] at h - rcases eq_or_lt_of_le ht0 with h0 | h0 - · simp [← h0] - · simpa using (le_div_iff₀ h0).mp h - -lemma normalized_energy_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) - (t : ℝ) (ht : t ≠ 0) (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (fun t => (energy (ray v t)-(1/2 : ℝ)*(momentX (ray v t))^2)/t^2) - (gapY (ray v t)/t^3) t := by - have hh := ((energy_hasDerivAt v hv t ht hp).sub - (((X_hasDerivAt v t).pow 2).const_mul (1/2 : ℝ))).div ((hasDerivAt_id t).pow 2) - (pow_ne_zero 2 ht) - convert hh using 1 <;> first | rfl | (simp only [X_ray, id_eq, Pi.pow_apply, Pi.sub_apply]; field_simp; ring) - - -theorem radial_inequality (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (l : ℝ) (hl0 : 0 < l) (hl1 : l < 1) : - (1-l^2)/2*(momentX v)^2 ≤ energy v-l⁻¹^2*energy (ray v l) := by - have hmono : MonotoneOn - (fun t => (energy (ray v t)-(1/2 : ℝ)*(momentX (ray v t))^2)/t^2) - (Set.Icc l 1) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => - gapY (ray v t)/t^3) (convex_Icc _ _) - · intro s hs - exact (normalized_energy_hasDerivAt v hv s (lt_of_lt_of_le hl0 hs.1).ne' (fun i => - ne_of_gt (message_segment_pos v hp s (le_trans hl0.le hs.1) hs.2 i))).continuousAt.continuousWithinAt - · intro s hs - rw [interior_Icc] at hs - exact (normalized_energy_hasDerivAt v hv s (lt_trans hl0 hs.1).ne' (fun i => - ne_of_gt (message_segment_pos v hp s (lt_trans hl0 hs.1).le hs.2.le i))).hasDerivWithinAt - · intro s hs - rw [interior_Icc] at hs - exact div_nonneg (gapY_nonneg v hv hp s (lt_trans hl0 hs.1).le hs.2.le) - (pow_nonneg (lt_trans hl0 hs.1).le 3) - have hh := hmono ⟨le_rfl, hl1.le⟩ ⟨hl1.le, le_rfl⟩ hl1.le - simp only [ray_one, X_ray, one_pow, div_one] at hh - have hl : l ≠ 0 := hl0.ne' - have hsq : 0 < l^2 := sq_pos_of_pos hl0 - rw [div_le_iff₀ hsq] at hh - apply (mul_le_mul_iff_left₀ hsq).mp - field_simp [hl] - nlinarith [hh] - -end ThreeState.Radial -namespace ThreeState.Radial - - -noncomputable def sourceF (m : Fin 3 → ℝ) : ℝ := - 3*avg (fun i => Real.log (m i)) + - 4*((1/2 : ℝ)*avg (fun i => (m i-1)*Real.log (m i))) + - (4/5 : ℝ)*((1/2 : ℝ)*avg (fun i => m i* - (Real.log (m i)-avg (fun j => Real.log (m j)))^2)) - -lemma avg_message_deviation (m : Fin 3 → ℝ) (hm : avg m = 1) : - avg (fun i => m i-1) = 0 := by - simp only [avg_expand] at * - linarith - -lemma logMoment_uncentered (v : Fin 3 → ℝ) (hv : avg v = 0) : - logMoment v = avg (fun i => v i*Real.log (1+v i)) := by - have hv2 := zero_sum_elim v hv - simp only [logMoment, centeredLog, avg_expand, hv2] - ring - -lemma energy_sourceF (m : Fin 3 → ℝ) (hm : avg m = 1) : - energy (fun i => m i-1) = sourceF m := by - rw [energy, logMoment_uncentered _ (avg_message_deviation m hm)] - simp only [logAvg, weightedLogVariance, centeredLog, sourceF] - have he (i : Fin 3) : 1+(m i-1) = m i := by ring - simp only [he] - ring - - -theorem radial_source (m : Fin 3 → ℝ) (hm : avg m = 1) (hp : ∀ i, 0 < m i) - (l : ℝ) (hl0 : 0 < l) (hl1 : l < 1) : - sourceF m-l⁻¹^2*sourceF (fun i => 1+l*(m i-1)) ≥ - (1-l^2)/2*((1/2 : ℝ)*avg (fun i => (m i-1)^2))^2 := by - have hv := avg_message_deviation m hm - have h := radial_inequality (fun i => m i-1) hv (by simpa using hp) l hl0 hl1 - have he : avg (fun i => 1+l*(m i-1)) = 1 := by - simp only [avg_expand] at * - nlinarith [hm] - have hr : ray (fun i => m i-1) l = (fun i => (1+l*(m i-1))-1) := by - ext i; simp [ray] - rw [energy_sourceF m hm, hr, energy_sourceF _ he] at h - convert h using 1 - simp only [momentX] - ring - -end ThreeState.Radial - -end OAI +import Mathlib +import OAI.Probability.ThreeState.RadialMoments + +namespace OAI + +/-! Radial logarithmic derivatives and the entropy inequality. -/ + +namespace ThreeState.Radial + +noncomputable def ray (v : Fin 3 → ℝ) (t : ℝ) : Fin 3 → ℝ := fun i => t*v i +noncomputable def logAvg (v : Fin 3 → ℝ) := avg (fun i => Real.log (1+v i)) +noncomputable def logVariance (v : Fin 3 → ℝ) := avg (fun i => (centeredLog v i)^2) +noncomputable def weightedLogVariance (v : Fin 3 → ℝ) := + avg (fun i => (1+v i)*(centeredLog v i)^2) + +noncomputable def energy (v : Fin 3 → ℝ) := + 3*logAvg v+2*logMoment v+(2/5 : ℝ)*weightedLogVariance v + +noncomputable def gapY (v : Fin 3 → ℝ) := + 1-invMoment v 1-6*logAvg v-2*logMoment v-(2/5 : ℝ)*weightedLogVariance v- + (2/5 : ℝ)*logVariance v+(4/5 : ℝ)*invMoment v 1*logMoment v-(momentX v)^2 + +noncomputable def gapZ (v : Fin 3 → ℝ) := + 6*logAvg v-5+(26/5 : ℝ)*invMoment v 1-invMoment v 2+ + (4/5 : ℝ)*logVariance v+(4/5 : ℝ)*(invMoment v 2-2*invMoment v 1)*logMoment v+ + (4/5 : ℝ)*logInvMoment v 1+(4/5 : ℝ)*(invMoment v 1)^2-3*(momentX v)^2 + +lemma avg_hasDerivAt (f : Fin 3 → ℝ → ℝ) (f' : Fin 3 → ℝ) (t : ℝ) + (hf : ∀ i, HasDerivAt (f i) (f' i) t) : + HasDerivAt (fun t => avg (fun i => f i t)) (avg f') t := by + simp only [avg_expand] + exact (((hf 0).add (hf 1)).add (hf 2)).div_const 3 + +lemma avg_ray (v : Fin 3 → ℝ) (t : ℝ) : avg (ray v t) = t*avg v := by + simp only [avg_expand, ray]; ring +lemma X_ray (v : Fin 3 → ℝ) (t : ℝ) : momentX (ray v t) = t^2*momentX v := by + simp only [momentX, avg_expand, ray]; ring +lemma centeredLog_avg_zero (v : Fin 3 → ℝ) : avg (centeredLog v) = 0 := by + simp only [centeredLog, avg_expand]; ring + +lemma ray_log_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) + (i : Fin 3) : HasDerivAt (fun t => Real.log (1+t*v i)) (v i/(1+t*v i)) t := by + simpa using (((hasDerivAt_id t).mul_const (v i)).const_add 1).log (hp i) +lemma ray_inv_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) + (i : Fin 3) : HasDerivAt (fun t => (1+t*v i)⁻¹) (-v i/(1+t*v i)^2) t := by + convert (((hasDerivAt_id t).mul_const (v i)).const_add 1).inv (hp i) using 1 <;> + first | rfl | norm_num + +lemma logAvg_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => logAvg (ray v t)) ((1-invMoment (ray v t) 1)/t) t := by + have hh := avg_hasDerivAt (fun i t => Real.log (1+t*v i)) (fun i => v i/(1+t*v i)) t + (ray_log_hasDerivAt v t hp) + convert hh using 1 + · rfl + · simp only [invMoment, avg_expand, ray, pow_one] + field_simp [hp 0, hp 1, hp 2] + ring + +lemma centeredLog_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) (i : Fin 3) : + HasDerivAt (fun t => centeredLog (ray v t) i) + ((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t) t := by + have hh := (ray_log_hasDerivAt v t hp i).sub (logAvg_hasDerivAt v t ht hp) + convert hh using 1 <;> first | rfl | (field_simp [hp i]; ring) + +lemma invMoment_one_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => invMoment (ray v t) 1) + ((invMoment (ray v t) 2-invMoment (ray v t) 1)/t) t := by + have hh := avg_hasDerivAt (fun i t => (1+t*v i)⁻¹) + (fun i => -v i/(1+t*v i)^2) t (ray_inv_hasDerivAt v t hp) + convert hh using 1 + · simp only [invMoment, ray, pow_one] + · simp only [invMoment, avg_expand, ray, pow_one] + field_simp [hp 0, hp 1, hp 2] + ring + +lemma invMoment_two_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => invMoment (ray v t) 2) + ((2*(invMoment (ray v t) 3-invMoment (ray v t) 2))/t) t := by + have hh := avg_hasDerivAt (fun i t => ((1+t*v i)⁻¹)^2) + (fun i => 2*(1+t*v i)⁻¹*(-v i/(1+t*v i)^2)) t + (fun i => by + convert (ray_inv_hasDerivAt v t hp i).pow 2 using 1; first | rfl | norm_num) + convert hh using 1 + · rfl + · simp only [invMoment, avg_expand, ray] + field_simp [hp 0, hp 1, hp 2] + ring + +lemma logMoment_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => logMoment (ray v t)) + ((logMoment (ray v t)+invMoment (ray v t) 1-1)/t) t := by + have hh := avg_hasDerivAt + (fun i t => t*v i*centeredLog (ray v t) i) + (fun i => v i*centeredLog (ray v t) i+t*v i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)) t + (fun i => by + convert ((hasDerivAt_id t).mul_const (v i)).mul (centeredLog_hasDerivAt v t ht hp i) using 1 <;> + first | rfl | simp) + have hv2 := zero_sum_elim v hv + convert hh using 1 + · rfl + · simp only [logMoment, invMoment, avg_expand, ray, pow_one] + field_simp [hp 0, hp 1, hp 2] + rw [hv2] + ring + +lemma logVariance_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => logVariance (ray v t)) + ((-2*logInvMoment (ray v t) 1)/t) t := by + have hh := avg_hasDerivAt + (fun i t => (centeredLog (ray v t) i)^2) + (fun i => 2*centeredLog (ray v t) i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)) t + (fun i => by + convert (centeredLog_hasDerivAt v t ht hp i).pow 2 using 1; first | rfl | norm_num) + have hu2 := zero_sum_elim (centeredLog (ray v t)) (centeredLog_avg_zero (ray v t)) + convert hh using 1 + · rfl + · simp only [logInvMoment, invMoment, avg_expand, pow_one] + simp only [hu2, ray] + ring + +lemma weightedLogVariance_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => weightedLogVariance (ray v t)) + ((weightedLogVariance (ray v t)-logVariance (ray v t)+ + 2*invMoment (ray v t) 1*logMoment (ray v t))/t) t := by + have hh := avg_hasDerivAt + (fun i t => (1+t*v i)*(centeredLog (ray v t) i)^2) + (fun i => v i*(centeredLog (ray v t) i)^2+(1+t*v i)* + (2*centeredLog (ray v t) i*((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t))) t + (fun i => by + convert (((hasDerivAt_id t).mul_const (v i)).const_add 1).mul + ((centeredLog_hasDerivAt v t ht hp i).pow 2) using 1 <;> first | rfl | norm_num) + have hu2 := zero_sum_elim (centeredLog (ray v t)) (centeredLog_avg_zero (ray v t)) + convert hh using 1 + · rfl + · simp only [weightedLogVariance, logVariance, logMoment, invMoment, avg_expand, pow_one] + simp only [hu2, ray] + field_simp [hp 0, hp 1, hp 2] + ring + +lemma logInvMoment_one_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => logInvMoment (ray v t) 1) + (((invMoment (ray v t) 1)^2-invMoment (ray v t) 2- + logInvMoment (ray v t) 1+logInvMoment (ray v t) 2)/t) t := by + have hh := avg_hasDerivAt + (fun i t => centeredLog (ray v t) i*(1+t*v i)⁻¹) + (fun i => ((invMoment (ray v t) 1-(1+t*v i)⁻¹)/t)*(1+t*v i)⁻¹+ + centeredLog (ray v t) i*(-v i/(1+t*v i)^2)) t + (fun i => (centeredLog_hasDerivAt v t ht hp i).mul (ray_inv_hasDerivAt v t hp i)) + convert hh using 1 + · simp only [logInvMoment, ray, pow_one] + · simp only [logInvMoment, invMoment, avg_expand, pow_one, ray] + field_simp [hp 0, hp 1, hp 2] + ring + +lemma X_hasDerivAt (v : Fin 3 → ℝ) (t : ℝ) : + HasDerivAt (fun t => momentX (ray v t)) (2*t*momentX v) t := by + simp_rw [X_ray] + convert ((hasDerivAt_id t).pow 2).mul_const (momentX v) using 1 <;> first | rfl | norm_num + +lemma energy_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => energy (ray v t)) + ((gapY (ray v t)+2*energy (ray v t)+(momentX (ray v t))^2)/t) t := by + have hh := (((logAvg_hasDerivAt v t ht hp).const_mul 3).add + ((logMoment_hasDerivAt v hv t ht hp).const_mul 2)).add + ((weightedLogVariance_hasDerivAt v t ht hp).const_mul (2/5 : ℝ)) + convert hh using 1 <;> first | rfl | (simp only [gapY, energy]; ring) + +lemma gapY_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => gapY (ray v t)) + ((gapZ (ray v t)+gapY (ray v t))/t) t := by + have hg := logAvg_hasDerivAt v t ht hp + have hm := logMoment_hasDerivAt v hv t ht hp + have hu := invMoment_one_hasDerivAt v t ht hp + have hvv := weightedLogVariance_hasDerivAt v t ht hp + have hw := logVariance_hasDerivAt v t ht hp + have hx := X_hasDerivAt v t + have hh := (((((((hasDerivAt_const t (1 : ℝ)).sub hu).sub (hg.const_mul 6)).sub + (hm.const_mul 2)).sub (hvv.const_mul (2/5 : ℝ))).sub (hw.const_mul (2/5 : ℝ))).add + ((hu.const_mul (4/5 : ℝ)).mul hm)).sub (hx.pow 2) + convert hh using 1 <;> first | rfl | (simp only [gapY, gapZ, X_ray]; field_simp; ring) + +lemma gapZ_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) (ht : t ≠ 0) + (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => gapZ (ray v t)) + ((gExpr (ray v t)-12*(momentX (ray v t))^2)/t) t := by + have hg := logAvg_hasDerivAt v t ht hp + have hm := logMoment_hasDerivAt v hv t ht hp + have hu := invMoment_one_hasDerivAt v t ht hp + have hu2 := invMoment_two_hasDerivAt v t ht hp + have hw := logVariance_hasDerivAt v t ht hp + have hs := logInvMoment_one_hasDerivAt v t ht hp + have hx := X_hasDerivAt v t + have hh := ((((((((hg.const_mul 6).sub_const 5).add (hu.const_mul (26/5 : ℝ))).sub hu2).add + (hw.const_mul (4/5 : ℝ))).add + (((hu2.sub (hu.const_mul 2)).const_mul (4/5 : ℝ)).mul hm)).add + (hs.const_mul (4/5 : ℝ))).add ((hu.pow 2).const_mul (4/5 : ℝ))).sub + ((hx.pow 2).const_mul 3) + convert hh using 1 <;> first | rfl | (simp only [gExpr, X_ray, Pi.sub_apply]; field_simp; ring) + +end ThreeState.Radial +namespace ThreeState.Radial + +@[simp] lemma ray_zero (v : Fin 3 → ℝ) : ray v 0 = 0 := by ext i; simp [ray] +@[simp] lemma ray_one (v : Fin 3 → ℝ) : ray v 1 = v := by ext i; simp [ray] +@[simp] lemma logAvg_zero : logAvg 0 = 0 := by norm_num [logAvg, avg_expand] +@[simp] lemma centeredLog_zero (i : Fin 3) : centeredLog 0 i = 0 := by + norm_num [centeredLog, avg_expand] +@[simp] lemma logMoment_zero : logMoment 0 = 0 := by norm_num [logMoment, avg_expand] +@[simp] lemma logVariance_zero : logVariance 0 = 0 := by norm_num [logVariance, avg_expand] +@[simp] lemma weightedLogVariance_zero : weightedLogVariance 0 = 0 := by + norm_num [weightedLogVariance, avg_expand] +@[simp] lemma invMoment_zero (n : ℕ) : invMoment 0 n = 1 := by + norm_num [invMoment, avg_expand] +@[simp] lemma logInvMoment_zero (n : ℕ) : logInvMoment 0 n = 0 := by + norm_num [logInvMoment, avg_expand] +@[simp] lemma momentX_zero : momentX 0 = 0 := by norm_num [momentX, avg_expand] +@[simp] lemma energy_zero : energy 0 = 0 := by norm_num [energy] +@[simp] lemma gapY_zero : gapY 0 = 0 := by norm_num [gapY] +@[simp] lemma gapZ_zero : gapZ 0 = 0 := by norm_num [gapZ] + +lemma logAvg_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => logAvg (ray v t)) 0 0 := by + have hh := avg_hasDerivAt (fun i t => Real.log (1+t*v i)) v 0 (fun i => by + simpa using ray_log_hasDerivAt v 0 (by simp) i) + simpa [logAvg, ray, hv] using hh + +lemma centeredLog_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : + HasDerivAt (fun t => centeredLog (ray v t) i) (v i) 0 := by + have hh := (ray_log_hasDerivAt v 0 (by simp) i).sub (logAvg_hasDerivAt_zero v hv) + convert hh using 1 <;> first | rfl | simp + +lemma invMoment_one_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => invMoment (ray v t) 1) 0 0 := by + have hh := avg_hasDerivAt (fun i t => (1+t*v i)⁻¹) (fun i => -v i) 0 + (fun i => by simpa using ray_inv_hasDerivAt v 0 (by simp) i) + have hz : avg (fun i => -v i) = 0 := by simp only [avg_expand] at *; linarith + simpa [invMoment, ray, hz] using hh + +lemma logMoment_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => logMoment (ray v t)) 0 0 := by + have hh := avg_hasDerivAt (fun i t => t*v i*centeredLog (ray v t) i) (fun _ => 0) 0 + (fun i => by + convert ((hasDerivAt_id (0 : ℝ)).mul_const (v i)).mul + (centeredLog_hasDerivAt_zero v hv i) using 1 <;> first | rfl | simp) + simpa [logMoment, ray, avg_expand, centeredLog] using hh + +lemma logVariance_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => logVariance (ray v t)) 0 0 := by + have hh := avg_hasDerivAt (fun i t => (centeredLog (ray v t) i)^2) (fun _ => 0) 0 + (fun i => by + convert (centeredLog_hasDerivAt_zero v hv i).pow 2 using 1; first | rfl | simp) + simpa [logVariance, avg_expand] using hh + +lemma weightedLogVariance_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => weightedLogVariance (ray v t)) 0 0 := by + have hh := avg_hasDerivAt (fun i t => (1+t*v i)*(centeredLog (ray v t) i)^2) (fun _ => 0) 0 + (fun i => by + convert (((hasDerivAt_id (0 : ℝ)).mul_const (v i)).const_add 1).mul + ((centeredLog_hasDerivAt_zero v hv i).pow 2) using 1 <;> first | rfl | simp) + simpa [weightedLogVariance, ray, avg_expand, centeredLog] using hh + +lemma gapY_hasDerivAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + HasDerivAt (fun t => gapY (ray v t)) 0 0 := by + have hu := invMoment_one_hasDerivAt_zero v hv + have hm := logMoment_hasDerivAt_zero v hv + have hh := (((((((hasDerivAt_const (0 : ℝ) (1 : ℝ)).sub hu).sub + ((logAvg_hasDerivAt_zero v hv).const_mul 6)).sub (hm.const_mul 2)).sub + ((weightedLogVariance_hasDerivAt_zero v hv).const_mul (2/5 : ℝ))).sub + ((logVariance_hasDerivAt_zero v hv).const_mul (2/5 : ℝ))).add + ((hu.const_mul (4/5 : ℝ)).mul hm)).sub ((X_hasDerivAt v 0).pow 2) + convert hh using 1 <;> first | rfl | simp + +lemma logAvg_continuousAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) : + ContinuousAt (fun t => logAvg (ray v t)) t := by + have hh (i : Fin 3) := (ray_log_hasDerivAt v t hp i).continuousAt + simp only [logAvg, avg_expand, ray] + exact (((hh 0).add (hh 1)).add (hh 2)).div_const 3 + +lemma centeredLog_continuousAt (v : Fin 3 → ℝ) (t : ℝ) + (hp : ∀ i, 1+t*v i ≠ 0) (i : Fin 3) : + ContinuousAt (fun t => centeredLog (ray v t) i) t := + ((ray_log_hasDerivAt v t hp i).continuousAt).sub (logAvg_continuousAt v t hp) + +lemma gapZ_continuousAt (v : Fin 3 → ℝ) (t : ℝ) (hp : ∀ i, 1+t*v i ≠ 0) : + ContinuousAt (fun t => gapZ (ray v t)) t := by + have hg := logAvg_continuousAt v t hp + have hu (i : Fin 3) := centeredLog_continuousAt v t hp i + have hinv (i : Fin 3) := (ray_inv_hasDerivAt v t hp i).continuousAt + unfold gapZ invMoment logMoment logVariance logInvMoment momentX + simp only [avg_expand, ray] + fun_prop + +lemma normalized_gapY_continuousAt_zero (v : Fin 3 → ℝ) (hv : avg v = 0) : + ContinuousAt (fun t => gapY (ray v t)/t) 0 := by + have hh := (gapY_hasDerivAt_zero v hv).continuousAt_div + simp only [ray_zero, gapY_zero, sub_zero] at hh + have heq : Function.update (fun t => gapY (ray v t)/t) 0 0 = + (fun t => gapY (ray v t)/t) := by + ext t + by_cases ht : t = 0 + · simp [ht] + · simp [Function.update, ht] + rwa [heq] at hh + +lemma gapZ_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ gapZ (ray v t) := by + have hmono : MonotoneOn (fun t => gapZ (ray v t)) (Set.Icc (0 : ℝ) 1) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => + (gExpr (ray v t)-12*(momentX (ray v t))^2)/t) (convex_Icc _ _) + · intro s hs + exact (gapZ_continuousAt v s (fun i => + ne_of_gt (message_segment_pos v hp s hs.1 hs.2 i))).continuousWithinAt + · intro s hs + rw [interior_Icc] at hs + exact (gapZ_hasDerivAt v hv s hs.1.ne' (fun i => + ne_of_gt (message_segment_pos v hp s hs.1.le hs.2.le i))).hasDerivWithinAt + · intro s hs + rw [interior_Icc] at hs + apply div_nonneg _ hs.1.le + apply sub_nonneg.mpr + apply gExpr_lower (ray v s) + · rw [avg_ray, hv, mul_zero] + · exact fun i => message_segment_pos v hp s hs.1.le hs.2.le i + simpa using hmono (by simp) ⟨ht0, ht1⟩ ht0 + +lemma normalized_gapY_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) + (t : ℝ) (ht : t ≠ 0) (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => gapY (ray v t)/t) (gapZ (ray v t)/t^2) t := by + have hh := (gapY_hasDerivAt v hv t ht hp).div (hasDerivAt_id t) ht + convert hh using 1 <;> first | rfl | (simp only [id_eq]; field_simp; ring) + +lemma gapY_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ gapY (ray v t) := by + have hmono : MonotoneOn (fun t => gapY (ray v t)/t) (Set.Icc (0 : ℝ) 1) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => + gapZ (ray v t)/t^2) (convex_Icc _ _) + · intro s hs + rcases eq_or_lt_of_le hs.1 with h | h + · rw [← h] + exact (normalized_gapY_continuousAt_zero v hv).continuousWithinAt + · exact (normalized_gapY_hasDerivAt v hv s h.ne' (fun i => + ne_of_gt (message_segment_pos v hp s hs.1 hs.2 i))).continuousAt.continuousWithinAt + · intro s hs + rw [interior_Icc] at hs + exact (normalized_gapY_hasDerivAt v hv s hs.1.ne' (fun i => + ne_of_gt (message_segment_pos v hp s hs.1.le hs.2.le i))).hasDerivWithinAt + · intro s hs + rw [interior_Icc] at hs + exact div_nonneg (gapZ_nonneg v hv hp s hs.1.le hs.2.le) (sq_nonneg s) + have h := hmono (by simp) ⟨ht0, ht1⟩ ht0 + simp only [div_zero] at h + rcases eq_or_lt_of_le ht0 with h0 | h0 + · simp [← h0] + · simpa using (le_div_iff₀ h0).mp h + +lemma normalized_energy_hasDerivAt (v : Fin 3 → ℝ) (hv : avg v = 0) + (t : ℝ) (ht : t ≠ 0) (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (fun t => (energy (ray v t)-(1/2 : ℝ)*(momentX (ray v t))^2)/t^2) + (gapY (ray v t)/t^3) t := by + have hh := ((energy_hasDerivAt v hv t ht hp).sub + (((X_hasDerivAt v t).pow 2).const_mul (1/2 : ℝ))).div ((hasDerivAt_id t).pow 2) + (pow_ne_zero 2 ht) + convert hh using 1 <;> first | rfl | (simp only [X_ray, id_eq, Pi.pow_apply, Pi.sub_apply]; field_simp; ring) + + +theorem radial_inequality (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (l : ℝ) (hl0 : 0 < l) (hl1 : l < 1) : + (1-l^2)/2*(momentX v)^2 ≤ energy v-l⁻¹^2*energy (ray v l) := by + have hmono : MonotoneOn + (fun t => (energy (ray v t)-(1/2 : ℝ)*(momentX (ray v t))^2)/t^2) + (Set.Icc l 1) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (f' := fun t => + gapY (ray v t)/t^3) (convex_Icc _ _) + · intro s hs + exact (normalized_energy_hasDerivAt v hv s (lt_of_lt_of_le hl0 hs.1).ne' (fun i => + ne_of_gt (message_segment_pos v hp s (le_trans hl0.le hs.1) hs.2 i))).continuousAt.continuousWithinAt + · intro s hs + rw [interior_Icc] at hs + exact (normalized_energy_hasDerivAt v hv s (lt_trans hl0 hs.1).ne' (fun i => + ne_of_gt (message_segment_pos v hp s (lt_trans hl0 hs.1).le hs.2.le i))).hasDerivWithinAt + · intro s hs + rw [interior_Icc] at hs + exact div_nonneg (gapY_nonneg v hv hp s (lt_trans hl0 hs.1).le hs.2.le) + (pow_nonneg (lt_trans hl0 hs.1).le 3) + have hh := hmono ⟨le_rfl, hl1.le⟩ ⟨hl1.le, le_rfl⟩ hl1.le + simp only [ray_one, X_ray, one_pow, div_one] at hh + have hl : l ≠ 0 := hl0.ne' + have hsq : 0 < l^2 := sq_pos_of_pos hl0 + rw [div_le_iff₀ hsq] at hh + apply (mul_le_mul_iff_left₀ hsq).mp + field_simp [hl] + nlinarith [hh] + +end ThreeState.Radial +namespace ThreeState.Radial + + +noncomputable def sourceF (m : Fin 3 → ℝ) : ℝ := + 3*avg (fun i => Real.log (m i)) + + 4*((1/2 : ℝ)*avg (fun i => (m i-1)*Real.log (m i))) + + (4/5 : ℝ)*((1/2 : ℝ)*avg (fun i => m i* + (Real.log (m i)-avg (fun j => Real.log (m j)))^2)) + +lemma avg_message_deviation (m : Fin 3 → ℝ) (hm : avg m = 1) : + avg (fun i => m i-1) = 0 := by + simp only [avg_expand] at * + linarith + +lemma logMoment_uncentered (v : Fin 3 → ℝ) (hv : avg v = 0) : + logMoment v = avg (fun i => v i*Real.log (1+v i)) := by + have hv2 := zero_sum_elim v hv + simp only [logMoment, centeredLog, avg_expand, hv2] + ring + +lemma energy_sourceF (m : Fin 3 → ℝ) (hm : avg m = 1) : + energy (fun i => m i-1) = sourceF m := by + rw [energy, logMoment_uncentered _ (avg_message_deviation m hm)] + simp only [logAvg, weightedLogVariance, centeredLog, sourceF] + have he (i : Fin 3) : 1+(m i-1) = m i := by ring + simp only [he] + ring + + +theorem radial_source (m : Fin 3 → ℝ) (hm : avg m = 1) (hp : ∀ i, 0 < m i) + (l : ℝ) (hl0 : 0 < l) (hl1 : l < 1) : + sourceF m-l⁻¹^2*sourceF (fun i => 1+l*(m i-1)) ≥ + (1-l^2)/2*((1/2 : ℝ)*avg (fun i => (m i-1)^2))^2 := by + have hv := avg_message_deviation m hm + have h := radial_inequality (fun i => m i-1) hv (by simpa using hp) l hl0 hl1 + have he : avg (fun i => 1+l*(m i-1)) = 1 := by + simp only [avg_expand] at * + nlinarith [hm] + have hr : ray (fun i => m i-1) l = (fun i => (1+l*(m i-1))-1) := by + ext i; simp [ray] + rw [energy_sourceF m hm, hr, energy_sourceF _ he] at h + convert h using 1 + simp only [momentX] + ring + +end ThreeState.Radial + +end OAI diff --git a/lean/OAI/Probability/ThreeState/RadialMoments.lean b/lean/OAI/Probability/ThreeState/RadialMoments.lean index 6a87ca4cdd441ef1948317cd4daa3321b3e50b81..1c0e76d64f530dc865960be0ec39f5217cb53412 100644 --- a/lean/OAI/Probability/ThreeState/RadialMoments.lean +++ b/lean/OAI/Probability/ThreeState/RadialMoments.lean @@ -1,585 +1,585 @@ -import Mathlib - -namespace OAI - -/-! Three-coordinate moment identities and positive radial polynomials. -/ - -namespace ThreeState.Radial - -noncomputable def f0 (r : ℝ) : ℝ := 480*r^4-842*r^3-117*r^2+445*r+160 -noncomputable def f1 (r : ℝ) : ℝ := - 336*r^6-1008*r^5+1096*r^4-896*r^3+63*r^2+685*r+240 -noncomputable def f2 (r : ℝ) : ℝ := 440*r^4-1104*r^3+368*r^2+413*r+210 - -lemma tail0_pos (p : ℝ) : 0 < 12267*p^2-1161*p+174 := by - nlinarith [sq_nonneg (24534*p-1161)] -lemma tail1_pos (p : ℝ) : 0 < 20184*p^2-2724*p+522 := by - nlinarith [sq_nonneg (40368*p-2724)] -lemma tail2_pos (p : ℝ) : 0 < 12366*p^2-1842*p+1044 := by - nlinarith [sq_nonneg (24732*p-1842)] - -lemma transform_f0 (p : ℝ) (hp : 1+p ≠ 0) : - 4*(1+p)^4*f0 ((p-1/2)/(1+p)) = - 504*p^4+4386*p^3+12267*p^2-1161*p+174 := by - unfold f0 - field_simp - ring - -lemma transform_f1 (p : ℝ) (hp : 1+p ≠ 0) : - 4*(1+p)^6*f1 ((p-1/2)/(1+p)) = - 2064*p^6+15486*p^5+36669*p^4+31368*p^3+20184*p^2-2724*p+522 := by - unfold f1 - field_simp - ring - -lemma transform_f2 (p : ℝ) (hp : 1+p ≠ 0) : - 4*(1+p)^4*f2 ((p-1/2)/(1+p)) = - 1308*p^4+7650*p^3+12366*p^2-1842*p+1044 := by - unfold f2 - field_simp - ring - -lemma f0_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f0 r := by - let p := (r+1/2)/(1-r) - have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) - have hden : 1+p ≠ 0 := ne_of_gt (by linarith) - have hr : (p-1/2)/(1+p) = r := by - apply (div_eq_iff hden).2 - dsimp [p] - have h1 : 1-r ≠ 0 := by linarith - field_simp - ring - have ht := transform_f0 p hden - rw [hr] at ht - have hrest : 0 ≤ 504*p^4+4386*p^3 := by positivity - have hmul : 0 < 4*(1+p)^4 * f0 r := by linarith [tail0_pos p] - exact pos_of_mul_pos_right hmul (by positivity) - -lemma f1_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f1 r := by - let p := (r+1/2)/(1-r) - have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) - have hden : 1+p ≠ 0 := ne_of_gt (by linarith) - have hr : (p-1/2)/(1+p) = r := by - apply (div_eq_iff hden).2 - dsimp [p] - have h1 : 1-r ≠ 0 := by linarith - field_simp - ring - have ht := transform_f1 p hden - rw [hr] at ht - have hrest : 0 ≤ 2064*p^6+15486*p^5+36669*p^4+31368*p^3 := by positivity - have hmul : 0 < 4*(1+p)^6 * f1 r := by linarith [tail1_pos p] - exact pos_of_mul_pos_right hmul (by positivity) - -lemma f2_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f2 r := by - let p := (r+1/2)/(1-r) - have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) - have hden : 1+p ≠ 0 := ne_of_gt (by linarith) - have hr : (p-1/2)/(1+p) = r := by - apply (div_eq_iff hden).2 - dsimp [p] - have h1 : 1-r ≠ 0 := by linarith - field_simp - ring - have ht := transform_f2 p hden - rw [hr] at ht - have hrest : 0 ≤ 1308*p^4+7650*p^3 := by positivity - have hmul : 0 < 4*(1+p)^4 * f2 r := by linarith [tail2_pos p] - exact pos_of_mul_pos_right hmul (by positivity) - -noncomputable def A (x y : ℝ) : ℝ := - 3*x^4+12*x^3+x^2+(-6*x^3-28*x^2-2*x)*y+(26*x-2)*y^2-4*y^3 -noncomputable def C (x y : ℝ) : ℝ := - 6*x^4-2*x^3+(-13*x^3-10*x^2-x)*y+(10*x^2+22*x+4)*y^2-16*y^3 -noncomputable def Lscaled (x y : ℝ) : ℝ := - 1500*x^5-1020*x^4+240*x^3+168*y^4+(-480*x^2-756*x-52)*y^3+ - (2114*x^3+710*x^2+48*x-80)*y^2+(-3093*x^4+736*x^3-35*x^2)*y - -lemma N1_factor (x y : ℝ) : - A x y + C x y = (x-y)*(9*x-10*y+1)*(x^2+x-2*y) := by - unfold A C - ring - -noncomputable def xa (r z : ℝ) : ℝ := (r^2+z/(3-2*r))/(1+z) -noncomputable def a0 (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*(10*r^2+r+1) -noncomputable def a1 (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*(9+5*r+20*r^2-4*r^3) -noncomputable def a2 (r : ℝ) : ℝ := 48*(1-r)^3 -noncomputable def b0 (r : ℝ) : ℝ := r^2*(1-r)^3*(3-2*r)^3*f0 r -noncomputable def b1 (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*f1 r -noncomputable def b2 (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*f2 r -noncomputable def b3 (r : ℝ) : ℝ := 24*(1-r)^3*(25-4*r^2-10*r) - -lemma a_nonneg (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : - 0 ≤ a0 r ∧ 0 ≤ a1 r ∧ 0 ≤ a2 r := by - have h1 : 0 ≤ 1-r := by linarith - have h2 : 0 ≤ 3-2*r := by linarith - have h3 : 0 ≤ 10*r^2+r+1 := by nlinarith [sq_nonneg (20*r+1)] - have h4a : 0 ≤ r^2*(20-4*r) := mul_nonneg (sq_nonneg _) (by linarith) - have h4 : 0 ≤ 9+5*r+20*r^2-4*r^3 := by nlinarith - dsimp [a0, a1, a2] - exact ⟨by positivity, by positivity, by positivity⟩ - -lemma b_nonneg (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : - 0 ≤ b0 r ∧ 0 ≤ b1 r ∧ 0 ≤ b2 r ∧ 0 ≤ b3 r := by - have h1 : 0 ≤ 1-r := by linarith - have h2 : 0 ≤ 3-2*r := by linarith - have h3a : 0 ≤ (1-r)*(4*r+14) := mul_nonneg h1 (by linarith) - have h3 : 0 ≤ 25-4*r^2-10*r := by nlinarith - have hf0 := (f0_pos r hl hu).le - have hf1 := (f1_pos r hl hu).le - have hf2 := (f2_pos r hl hu).le - dsimp [b0, b1, b2, b3] - exact ⟨by positivity, by positivity, by positivity, by positivity⟩ - -lemma A_certificate (r z : ℝ) (hr : 3-2*r ≠ 0) (hz : 1+z ≠ 0) : - (1+z)^2*(3-2*r)^2 * A (xa r z) (r*xa r z) = - (xa r z)^2*(a0 r+a1 r*z+a2 r*z^2) := by - dsimp [A, xa, a0, a1, a2] - field_simp - ring - -lemma L_certificate (r z : ℝ) (hr : 3-2*r ≠ 0) (hz : 1+z ≠ 0) : - (1+z)^3*(3-2*r)^3 * Lscaled (xa r z) (r*xa r z) = - (xa r z)^2*(b0 r+b1 r*z+b2 r*z^2+b3 r*z^3) := by - dsimp [Lscaled, xa, b0, b1, b2, b3, f0, f1, f2] - field_simp - ring - -lemma A_nonneg_param (r z : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) - (hz : 0 ≤ z) : 0 ≤ A (xa r z) (r*xa r z) := by - have h1 : 0 < 1+z := by linarith - have h2 : 0 < 3-2*r := by linarith - obtain ⟨h0, ha1, ha2⟩ := a_nonneg r hl hu - have hrhs : 0 ≤ (xa r z)^2*(a0 r+a1 r*z+a2 r*z^2) := by positivity - rw [← A_certificate r z (ne_of_gt h2) (ne_of_gt h1)] at hrhs - exact nonneg_of_mul_nonneg_right hrhs (by positivity) - -lemma L_nonneg_param (r z : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) - (hz : 0 ≤ z) : 0 ≤ Lscaled (xa r z) (r*xa r z) := by - have h1 : 0 < 1+z := by linarith - have h2 : 0 < 3-2*r := by linarith - obtain ⟨h0, hb1, hb2, hb3⟩ := b_nonneg r hl hu - have hrhs : 0 ≤ (xa r z)^2*(b0 r+b1 r*z+b2 r*z^2+b3 r*z^3) := by positivity - rw [← L_certificate r z (ne_of_gt h2) (ne_of_gt h1)] at hrhs - exact nonneg_of_mul_nonneg_right hrhs (by positivity) - -lemma physical_parameterization (x y : ℝ) (hx : 0 < x) (hx1 : x < 1) - (hdisc : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : - ∃ r z : ℝ, -(1/2 : ℝ) ≤ r ∧ r < 1 ∧ 0 ≤ z ∧ - x = xa r z ∧ y = r * x := by - let r := y/x - have hylt : y < x := by - nlinarith [mul_pos (sq_pos_of_pos hx) (sub_pos.mpr hx1)] - have hr1 : r < 1 := (div_lt_one hx).2 hylt - have hyr : y = r*x := by dsimp [r]; field_simp - have hrsq : r^2 ≤ x := by - dsimp [r] - rw [div_pow] - apply (div_le_iff₀ (sq_pos_of_pos hx)).2 - nlinarith - have hden : 0 < 3-2*r := by linarith - have hupper : x < 1/(3-2*r) := by - apply (lt_div_iff₀ hden).2 - nlinarith [hD] - have hdsq : r^2*(3-2*r) < 1 := lt_of_le_of_lt - (mul_le_mul_of_nonneg_right hrsq hden.le) ((lt_div_iff₀ hden).1 hupper) - have hpos : 0 < (1-r)^2*(1+2*r) := by nlinarith - have hrlo : -(1/2 : ℝ) ≤ r := by - have := pos_of_mul_pos_right hpos (sq_nonneg (1-r)) - linarith - let z := (x-r^2)/(1/(3-2*r)-x) - have hz : 0 ≤ z := div_nonneg (by linarith) (by linarith) - have hfrep : x = xa r z := by - dsimp [xa] - apply (eq_div_iff (ne_of_gt (show 0 < 1+z by linarith))).2 - have hn0 : 1/(3-2*r)-x ≠ 0 := ne_of_gt (sub_pos.mpr hupper) - have hzEq : z * (1/(3-2*r)-x) = x-r^2 := div_mul_cancel₀ _ hn0 - simp only [div_eq_mul_inv, one_mul] at hzEq ⊢ - nlinarith only [hzEq] - exact ⟨r, z, hrlo, hr1, hz, hfrep, hyr⟩ - -lemma physical_signs (x y : ℝ) (hx : 0 ≤ x) (hx1 : x < 1) - (hdisc : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : - 0 ≤ A x y ∧ 0 ≤ A x y + C x y ∧ 0 ≤ Lscaled x y := by - have hyx : y ≤ x := by - have hpow : x^3 ≤ x^2 := by nlinarith [mul_nonneg (sq_nonneg x) (by linarith : 0 ≤ 1-x)] - nlinarith [sq_nonneg (y-x)] - have hlast : 0 ≤ x^2+x-2*y := by - by_contra hn - have hn' : x^2+x < 2*y := by linarith - have hy : 0 < y := by nlinarith [sq_nonneg x] - have hp : (x^2+x)^2 < (2*y)^2 := by - nlinarith [mul_pos (by linarith : 0 < 2*y-(x^2+x)) - (by nlinarith [sq_nonneg x] : 0 < 2*y+(x^2+x))] - nlinarith [sq_nonneg (x^2-x)] - have hN1 : 0 ≤ A x y + C x y := by - rw [N1_factor] - exact mul_nonneg (mul_nonneg (by linarith) (by linarith)) hlast - rcases eq_or_lt_of_le hx with hzero | hpos - · have hxzero : x = 0 := hzero.symm - have hyzero : y = 0 := by rw [hxzero] at hdisc; nlinarith [sq_nonneg y] - subst x; subst y - norm_num [A, C, Lscaled] - · obtain ⟨r, z, hl, hu, hz, hxr, hyr⟩ := physical_parameterization x y hpos hx1 hdisc hD - have hA : 0 ≤ A x y := by rw [hyr, hxr]; exact A_nonneg_param r z hl hu hz - have hL : 0 ≤ Lscaled x y := by rw [hyr, hxr]; exact L_nonneg_param r z hl hu hz - exact ⟨hA, hN1, hL⟩ - -end ThreeState.Radial - - - -namespace ThreeState.Radial - -noncomputable def avg (v : Fin 3 → ℝ) : ℝ := (∑ i, v i) / 3 -noncomputable def momentX (v : Fin 3 → ℝ) : ℝ := avg (fun i => (v i)^2) / 2 -noncomputable def momentY (v : Fin 3 → ℝ) : ℝ := avg (fun i => (v i)^3) / 2 -noncomputable def denom (v : Fin 3 → ℝ) (t : ℝ) : ℝ := - 1 - 3*t^2*momentX v + 2*t^3*momentY v -noncomputable def cofactor (v : Fin 3 → ℝ) (i : Fin 3) : ℝ := - 1-v i+(v i)^2-3*momentX v -noncomputable def kernel (v : Fin 3 → ℝ) (t : ℝ) (i : Fin 3) : ℝ := - v i-t*((v i)^2-2*momentX v) -noncomputable def centeredLog (v : Fin 3 → ℝ) (i : Fin 3) : ℝ := - Real.log (1+v i) - avg (fun j => Real.log (1+v j)) - -lemma avg_expand (v : Fin 3 → ℝ) : avg v = (v 0+v 1+v 2)/3 := by - simp [avg, Fin.sum_univ_succ]; ring - -lemma zero_sum_elim (v : Fin 3 → ℝ) (hv : avg v = 0) : v 2 = -v 0-v 1 := by - rw [avg_expand] at hv; linarith - -lemma cubic_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : - (v i)^3 = 3*momentX v*v i+2*momentY v := by - have h2 := zero_sum_elim v hv - fin_cases i - · change (v 0)^3 = 3*momentX v*v 0+2*momentY v - simp only [momentX, momentY, avg_expand, h2]; ring - · change (v 1)^3 = 3*momentX v*v 1+2*momentY v - simp only [momentX, momentY, avg_expand, h2]; ring - · change (v 2)^3 = 3*momentX v*v 2+2*momentY v - simp only [momentX, momentY, avg_expand, h2]; ring - -lemma denom_product (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) : - denom v t = (1+t*v 0)*(1+t*v 1)*(1+t*v 2) := by - have h2 := zero_sum_elim v hv - simp only [denom, momentX, momentY, avg_expand, h2] - ring - -lemma cofactor_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : - (1+v i) * cofactor v i = denom v 1 := by - dsimp [cofactor, denom] - nlinarith only [cubic_identity v hv i] - -lemma message_segment_pos (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (i : Fin 3) : 0 < 1+t*v i := by - have hv := hp i - rcases eq_or_lt_of_le ht0 with h | h - · rw [← h]; norm_num - · have : 0 < t*(1+v i) := mul_pos h hv - nlinarith - -lemma denom_pos (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 < denom v t := by - rw [denom_product v hv t] - exact mul_pos (mul_pos (message_segment_pos v hp t ht0 ht1 0) - (message_segment_pos v hp t ht0 ht1 1)) (message_segment_pos v hp t ht0 ht1 2) - -lemma momentX_nonneg (v : Fin 3 → ℝ) : 0 ≤ momentX v := by - simp only [momentX, avg_expand]; positivity - -lemma discriminant (v : Fin 3 → ℝ) (hv : avg v = 0) : - (v 0-v 1)^2*(v 0-v 2)^2*(v 1-v 2)^2 = - 108*((momentX v)^3-(momentY v)^2) := by - have h2 := zero_sum_elim v hv - simp only [momentX, momentY, avg_expand, h2] - ring - -lemma discriminant_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) : - (momentY v)^2 ≤ (momentX v)^3 := by - have h := discriminant v hv - have : 0 ≤ (v 0-v 1)^2*(v 0-v 2)^2*(v 1-v 2)^2 := by positivity - linarith - -lemma momentX_lt_one (v : Fin 3 → ℝ) (hv : avg v = 0) - (hp : ∀ i, 0 < 1+v i) : momentX v < 1 := by - have hu := zero_sum_elim v hv - have h01 := mul_pos (hp 0) (hp 1) - have h02 := mul_pos (hp 0) (hp 2) - have h12 := mul_pos (hp 1) (hp 2) - simp only [momentX, avg_expand] - rw [hu] at * - nlinarith - -lemma momentY_le_X (v : Fin 3 → ℝ) (hv : avg v = 0) - (hp : ∀ i, 0 < 1+v i) : momentY v ≤ momentX v := by - have hX := momentX_nonneg v - have hX1 := momentX_lt_one v hv hp - have hdisc := discriminant_nonneg v hv - have hpow : (momentX v)^3 ≤ (momentX v)^2 := by - nlinarith [mul_nonneg (sq_nonneg (momentX v)) (by linarith : 0 ≤ 1-momentX v)] - nlinarith [sq_nonneg (momentY v-momentX v)] - -lemma denom_le_one (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : denom v t ≤ 1 := by - have h1 := mul_le_mul_of_nonneg_left (momentY_le_X v hv hp) (pow_nonneg ht0 3) - have h2 := mul_nonneg (mul_nonneg (sq_nonneg t) (momentX_nonneg v)) - (show 0 ≤ 1-t by linarith) - have h3 : 0 ≤ t^2*momentX v := mul_nonneg (sq_nonneg t) (momentX_nonneg v) - dsimp [denom] - nlinarith - -noncomputable def cofMoment (v : Fin 3 → ℝ) (j : ℕ) := - avg (fun i => (cofactor v i)^j) - -lemma cofMoment_one (v : Fin 3 → ℝ) (hv : avg v = 0) : - cofMoment v 1 = 1-momentX v := by - have h2 := zero_sum_elim v hv - simp only [cofMoment, cofactor, momentX, avg_expand, h2] - ring - -lemma cofMoment_two (v : Fin 3 → ℝ) (hv : avg v = 0) : - cofMoment v 2 = 3*(momentX v)^2-4*momentY v+1 := by - have h2 := zero_sum_elim v hv - simp only [cofMoment, cofactor, momentX, momentY, avg_expand, h2] - ring - -lemma cofMoment_three (v : Fin 3 → ℝ) (hv : avg v = 0) : - cofMoment v 3 = -9*(momentX v)^3+9*(momentX v)^2+ - 6*momentX v*momentY v+3*momentX v+4*(momentY v)^2-14*momentY v+1 := by - have h2 := zero_sum_elim v hv - simp only [cofMoment, cofactor, momentX, momentY, avg_expand, h2] - ring - -noncomputable def numerator (v : Fin 3 → ℝ) (t : ℝ) := - (4/5 : ℝ) * avg (fun i => kernel v t i * - ((cofactor v i)^2*denom v 1-3*cofactor v i*(denom v 1)^2+ - (2*cofMoment v 3-3*cofMoment v 2*denom v 1)*v i)) - -lemma numerator_expansion (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) : - numerator v t = (24/5 : ℝ)*(A (momentX v) (momentY v)+t*C (momentX v) (momentY v)) := by - unfold numerator - rw [cofMoment_two v hv, cofMoment_three v hv] - have h2 := zero_sum_elim v hv - simp only [cofactor, kernel, denom, A, C, momentX, momentY, avg_expand, h2] - ring - -lemma integral_avg (f : Fin 3 → ℝ → ℝ) - (hf : ∀ i, IntervalIntegrable (f i) MeasureTheory.volume 0 1) : - (∫ t in (0 : ℝ)..1, avg (fun i => f i t)) = avg (fun i => ∫ t in (0 : ℝ)..1, f i t) := by - unfold avg - rw [intervalIntegral.integral_div, intervalIntegral.integral_finsetSum (fun i _ => hf i)] - -lemma log_integral (a : ℝ) (ha : 0 < 1+a) : - Real.log (1+a) = ∫ t in (0 : ℝ)..1, a/(1+t*a) := by - have hp : ∀ t ∈ Set.Icc (0 : ℝ) 1, 0 < 1+t*a := by - intro t ht - rcases eq_or_lt_of_le ht.1 with hz | hz - · rw [← hz]; norm_num - · nlinarith [mul_pos hz ha, ht.2] - have hc : ContinuousOn (fun t : ℝ => a/(1+t*a)) (Set.Icc 0 1) := - continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (hp t ht)) - have hi : IntervalIntegrable (fun t : ℝ => a/(1+t*a)) MeasureTheory.volume 0 1 := - hc.intervalIntegrable_of_Icc (by norm_num) - have hD : ∀ t ∈ Set.uIcc (0 : ℝ) 1, - HasDerivAt (fun t : ℝ => Real.log (1+t*a)) (a/(1+t*a)) t := by - intro t ht - have ht' : t ∈ Set.Icc (0 : ℝ) 1 := by simpa using ht - simpa using (((hasDerivAt_id t).mul_const a).const_add 1).log (ne_of_gt (hp t ht')) - simpa using (intervalIntegral.integral_eq_sub_of_hasDerivAt hD hi).symm - -lemma kernel_div_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (i : Fin 3) : - v i/(1+t*v i)-avg (fun j => v j/(1+t*v j)) = kernel v t i/denom v t := by - have h0 := ne_of_gt (message_segment_pos v hp t ht0 ht1 0) - have h1 := ne_of_gt (message_segment_pos v hp t ht0 ht1 1) - have h2 := ne_of_gt (message_segment_pos v hp t ht0 ht1 2) - have h0c : 1+v 0*t ≠ 0 := by simpa [mul_comm] using h0 - have h1c : 1+v 1*t ≠ 0 := by simpa [mul_comm] using h1 - have h2c : 1+v 2*t ≠ 0 := by simpa [mul_comm] using h2 - have hv2 := zero_sum_elim v hv - rw [denom_product v hv t] - fin_cases i - · change v 0/(1+t*v 0)-avg (fun j => v j/(1+t*v j)) = - kernel v t 0/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) - simp only [avg_expand, kernel, momentX] - field_simp [h0, h1, h2, h0c, h1c, h2c] - rw [hv2] - ring - · change v 1/(1+t*v 1)-avg (fun j => v j/(1+t*v j)) = - kernel v t 1/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) - simp only [avg_expand, kernel, momentX] - field_simp [h0, h1, h2, h0c, h1c, h2c] - rw [hv2] - ring - · change v 2/(1+t*v 2)-avg (fun j => v j/(1+t*v j)) = - kernel v t 2/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) - simp only [avg_expand, kernel, momentX] - field_simp [h0, h1, h2, h0c, h1c, h2c] - rw [hv2] - ring - -lemma centeredLog_integral (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (i : Fin 3) : centeredLog v i = ∫ t in (0 : ℝ)..1, kernel v t i / denom v t := by - have hi : ∀ j, IntervalIntegrable (fun t : ℝ => v j/(1+t*v j)) MeasureTheory.volume 0 1 := by - intro j - apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) - refine continuousOn_const.div (by fun_prop) ?_ - intro t ht - exact ne_of_gt (message_segment_pos v hp t ht.1 ht.2 j) - have ha : IntervalIntegrable (fun t : ℝ => avg (fun j => v j/(1+t*v j))) - MeasureTheory.volume 0 1 := by - unfold avg - exact (IntervalIntegrable.sum Finset.univ (fun j _ => hi j)).div_const 3 - unfold centeredLog - rw [log_integral (v i) (hp i)] - have hlogs : (fun j => Real.log (1+v j)) = (fun j => ∫ t in (0 : ℝ)..1, v j/(1+t*v j)) := by - funext j; exact log_integral (v j) (hp j) - rw [hlogs, ← integral_avg _ hi, ← intervalIntegral.integral_sub (hi i) ha] - apply intervalIntegral.integral_congr - intro t ht - have ht' : t ∈ Set.Icc (0 : ℝ) 1 := by simpa using ht - exact kernel_div_identity v hv hp t ht'.1 ht'.2 i - -noncomputable def invMoment (v : Fin 3 → ℝ) (j : ℕ) := - avg (fun i => ((1+v i)⁻¹)^j) -noncomputable def logInvMoment (v : Fin 3 → ℝ) (j : ℕ) := - avg (fun i => centeredLog v i*((1+v i)⁻¹)^j) -noncomputable def logMoment (v : Fin 3 → ℝ) := avg (fun i => v i*centeredLog v i) - - -noncomputable def gExpr (v : Fin 3 → ℝ) := - 6-12*invMoment v 1+8*invMoment v 2-2*invMoment v 3+ - (4/5 : ℝ)*(logInvMoment v 2-3*logInvMoment v 1+ - (2*invMoment v 3-3*invMoment v 2)*logMoment v+ - 3*(invMoment v 1-1)*(invMoment v 2-invMoment v 1)) -noncomputable def rCore (v : Fin 3 → ℝ) := - (6-12*(momentX v)^2)*(denom v 1)^3-12*cofMoment v 1*(denom v 1)^2+ - 8*cofMoment v 2*denom v 1-2*cofMoment v 3+ - (12/5 : ℝ)*(cofMoment v 1-denom v 1)*(cofMoment v 2-cofMoment v 1*denom v 1) -noncomputable def logCoeff (v : Fin 3 → ℝ) (i : Fin 3) := - (cofactor v i)^2*denom v 1-3*cofactor v i*(denom v 1)^2+ - (2*cofMoment v 3-3*cofMoment v 2*denom v 1)*v i - -lemma inv_cofactor (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (i : Fin 3) : (1+v i)⁻¹ = cofactor v i / denom v 1 := by - apply (eq_div_iff (ne_of_gt (denom_pos v hv hp 1 (by norm_num) le_rfl))).2 - rw [← cofactor_identity v hv i] - field_simp [ne_of_gt (hp i)] - -lemma RN_algebra (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : - (denom v 1)^3*(gExpr v-12*(momentX v)^2) = - rCore v + (4/5 : ℝ)*avg (fun i => centeredLog v i*logCoeff v i) := by - have hD := ne_of_gt (denom_pos v hv hp 1 (by norm_num) le_rfl) - unfold gExpr invMoment logInvMoment logMoment rCore logCoeff - simp_rw [inv_cofactor v hv hp] - simp only [cofMoment, avg_expand] - field_simp - ring - -lemma kernel_div_integrable (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (i : Fin 3) : IntervalIntegrable (fun t : ℝ => kernel v t i/denom v t) - MeasureTheory.volume 0 1 := by - apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) - unfold kernel denom - refine ContinuousOn.div (by fun_prop) (by fun_prop) ?_ - intro t ht - exact ne_of_gt (denom_pos v hv hp t ht.1 ht.2) - -lemma RN_representation (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : - (denom v 1)^3*(gExpr v-12*(momentX v)^2) = - rCore v + ∫ t in (0 : ℝ)..1, numerator v t / denom v t := by - rw [RN_algebra v hv hp] - congr 1 - have hg : ∀ t : ℝ, numerator v t/denom v t = (4/5 : ℝ)* - avg (fun i => (kernel v t i/denom v t)*logCoeff v i) := by - intro t - simp only [numerator, logCoeff, avg_expand] - ring - simp_rw [hg] - rw [intervalIntegral.integral_const_mul, integral_avg _ - (fun i => (kernel_div_integrable v hv hp i).mul_const (logCoeff v i))] - congr 1 - congr 1 - funext i - rw [intervalIntegral.integral_mul_const, centeredLog_integral v hv hp i] - -lemma integrate_N_lower (a c x y : ℝ) : - (∫ t in (0 : ℝ)..1, (24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) = - (24/5 : ℝ)*(a+c/2+a*x+(3*c*x-2*a*y)/4-2*c*y/5) := by - let P := fun t : ℝ => (24/5 : ℝ)*(a*t+c*t^2/2+a*x*t^3+ - (3*c*x-2*a*y)*t^4/4-2*c*y*t^5/5) - have hd : ∀ t : ℝ, HasDerivAt P ((24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) t := by - intro t - dsimp [P] - convert (((((hasDerivAt_id t).const_mul a).add - (((hasDerivAt_id t).pow 2).const_mul c |>.div_const 2)).add - (((hasDerivAt_id t).pow 3).const_mul (a*x))).add - (((hasDerivAt_id t).pow 4).const_mul (3*c*x-2*a*y) |>.div_const 4) |>.sub - (((hasDerivAt_id t).pow 5).const_mul (2*c*y) |>.div_const 5)).const_mul (24/5 : ℝ) using 1 <;> - first | rfl | (norm_num; ring) - have hi : IntervalIntegrable (fun t : ℝ => (24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) - MeasureTheory.volume 0 1 := Continuous.intervalIntegrable (by fun_prop) 0 1 - rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) hi] - dsimp [P]; ring - -lemma L_expansion (v : Fin 3 → ℝ) (hv : avg v = 0) : - rCore v + (∫ t in (0 : ℝ)..1, numerator v t*(2-denom v t)) = - (6/25 : ℝ)*Lscaled (momentX v) (momentY v) := by - have hg : (fun t : ℝ => numerator v t*(2-denom v t)) = - (fun t : ℝ => (24/5 : ℝ)*(A (momentX v) (momentY v)+t*C (momentX v) (momentY v))* - (1+3*t^2*momentX v-2*t^3*momentY v)) := by - funext t - rw [numerator_expansion v hv t] - dsimp [denom]; ring - rw [hg, integrate_N_lower] - unfold rCore - rw [cofMoment_one v hv, cofMoment_two v hv, cofMoment_three v hv] - dsimp [denom, A, C, Lscaled] - ring - -lemma numerator_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ numerator v t := by - have hD : 0 < 1-3*momentX v+2*momentY v := by - simpa [denom] using denom_pos v hv hp 1 (by norm_num) le_rfl - obtain ⟨ha, hac, _⟩ := physical_signs (momentX v) (momentY v) - (momentX_nonneg v) (momentX_lt_one v hv hp) (discriminant_nonneg v hv) hD - rw [numerator_expansion v hv t] - have h := add_nonneg (mul_nonneg (show 0 ≤ 1-t by linarith) ha) (mul_nonneg ht0 hac) - nlinarith only [h] - - - -lemma gExpr_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : - 12*(momentX v)^2 ≤ gExpr v := by - have hi1 : IntervalIntegrable (fun t => numerator v t*(2-denom v t)) - MeasureTheory.volume 0 1 := by - apply Continuous.intervalIntegrable - unfold numerator kernel denom avg - fun_prop - have hi2 : IntervalIntegrable (fun t => numerator v t/denom v t) - MeasureTheory.volume 0 1 := by - apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) - apply ContinuousOn.div - · unfold numerator kernel avg; fun_prop - · unfold denom; fun_prop - · intro t ht; exact ne_of_gt (denom_pos v hv hp t ht.1 ht.2) - have hbound : ∀ t ∈ Set.Icc (0 : ℝ) 1, numerator v t*(2-denom v t) ≤ numerator v t/denom v t := by - intro t ht - have hD := denom_pos v hv hp t ht.1 ht.2 - apply (le_div_iff₀ hD).2 - nlinarith [mul_nonneg (numerator_nonneg v hv hp t ht.1 ht.2) (sq_nonneg (1-denom v t))] - have hint := intervalIntegral.integral_mono_on (by norm_num) hi1 hi2 hbound - have hR := RN_representation v hv hp - have hL := L_expansion v hv - have hd := denom_pos v hv hp 1 (by norm_num) le_rfl - have hdom : 0 < 1-3*momentX v+2*momentY v := by simpa [denom] using hd - have hLpos := (physical_signs (momentX v) (momentY v) (momentX_nonneg v) - (momentX_lt_one v hv hp) (discriminant_nonneg v hv) hdom).2.2 - have hprod : 0 ≤ (denom v 1)^3*(gExpr v-12*(momentX v)^2) := by linarith - have := nonneg_of_mul_nonneg_right hprod (pow_pos hd 3) - linarith - -end ThreeState.Radial - -end OAI +import Mathlib + +namespace OAI + +/-! Three-coordinate moment identities and positive radial polynomials. -/ + +namespace ThreeState.Radial + +noncomputable def f0 (r : ℝ) : ℝ := 480*r^4-842*r^3-117*r^2+445*r+160 +noncomputable def f1 (r : ℝ) : ℝ := + 336*r^6-1008*r^5+1096*r^4-896*r^3+63*r^2+685*r+240 +noncomputable def f2 (r : ℝ) : ℝ := 440*r^4-1104*r^3+368*r^2+413*r+210 + +lemma tail0_pos (p : ℝ) : 0 < 12267*p^2-1161*p+174 := by + nlinarith [sq_nonneg (24534*p-1161)] +lemma tail1_pos (p : ℝ) : 0 < 20184*p^2-2724*p+522 := by + nlinarith [sq_nonneg (40368*p-2724)] +lemma tail2_pos (p : ℝ) : 0 < 12366*p^2-1842*p+1044 := by + nlinarith [sq_nonneg (24732*p-1842)] + +lemma transform_f0 (p : ℝ) (hp : 1+p ≠ 0) : + 4*(1+p)^4*f0 ((p-1/2)/(1+p)) = + 504*p^4+4386*p^3+12267*p^2-1161*p+174 := by + unfold f0 + field_simp + ring + +lemma transform_f1 (p : ℝ) (hp : 1+p ≠ 0) : + 4*(1+p)^6*f1 ((p-1/2)/(1+p)) = + 2064*p^6+15486*p^5+36669*p^4+31368*p^3+20184*p^2-2724*p+522 := by + unfold f1 + field_simp + ring + +lemma transform_f2 (p : ℝ) (hp : 1+p ≠ 0) : + 4*(1+p)^4*f2 ((p-1/2)/(1+p)) = + 1308*p^4+7650*p^3+12366*p^2-1842*p+1044 := by + unfold f2 + field_simp + ring + +lemma f0_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f0 r := by + let p := (r+1/2)/(1-r) + have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) + have hden : 1+p ≠ 0 := ne_of_gt (by linarith) + have hr : (p-1/2)/(1+p) = r := by + apply (div_eq_iff hden).2 + dsimp [p] + have h1 : 1-r ≠ 0 := by linarith + field_simp + ring + have ht := transform_f0 p hden + rw [hr] at ht + have hrest : 0 ≤ 504*p^4+4386*p^3 := by positivity + have hmul : 0 < 4*(1+p)^4 * f0 r := by linarith [tail0_pos p] + exact pos_of_mul_pos_right hmul (by positivity) + +lemma f1_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f1 r := by + let p := (r+1/2)/(1-r) + have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) + have hden : 1+p ≠ 0 := ne_of_gt (by linarith) + have hr : (p-1/2)/(1+p) = r := by + apply (div_eq_iff hden).2 + dsimp [p] + have h1 : 1-r ≠ 0 := by linarith + field_simp + ring + have ht := transform_f1 p hden + rw [hr] at ht + have hrest : 0 ≤ 2064*p^6+15486*p^5+36669*p^4+31368*p^3 := by positivity + have hmul : 0 < 4*(1+p)^6 * f1 r := by linarith [tail1_pos p] + exact pos_of_mul_pos_right hmul (by positivity) + +lemma f2_pos (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : 0 < f2 r := by + let p := (r+1/2)/(1-r) + have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) + have hden : 1+p ≠ 0 := ne_of_gt (by linarith) + have hr : (p-1/2)/(1+p) = r := by + apply (div_eq_iff hden).2 + dsimp [p] + have h1 : 1-r ≠ 0 := by linarith + field_simp + ring + have ht := transform_f2 p hden + rw [hr] at ht + have hrest : 0 ≤ 1308*p^4+7650*p^3 := by positivity + have hmul : 0 < 4*(1+p)^4 * f2 r := by linarith [tail2_pos p] + exact pos_of_mul_pos_right hmul (by positivity) + +noncomputable def A (x y : ℝ) : ℝ := + 3*x^4+12*x^3+x^2+(-6*x^3-28*x^2-2*x)*y+(26*x-2)*y^2-4*y^3 +noncomputable def C (x y : ℝ) : ℝ := + 6*x^4-2*x^3+(-13*x^3-10*x^2-x)*y+(10*x^2+22*x+4)*y^2-16*y^3 +noncomputable def Lscaled (x y : ℝ) : ℝ := + 1500*x^5-1020*x^4+240*x^3+168*y^4+(-480*x^2-756*x-52)*y^3+ + (2114*x^3+710*x^2+48*x-80)*y^2+(-3093*x^4+736*x^3-35*x^2)*y + +lemma N1_factor (x y : ℝ) : + A x y + C x y = (x-y)*(9*x-10*y+1)*(x^2+x-2*y) := by + unfold A C + ring + +noncomputable def xa (r z : ℝ) : ℝ := (r^2+z/(3-2*r))/(1+z) +noncomputable def a0 (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*(10*r^2+r+1) +noncomputable def a1 (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*(9+5*r+20*r^2-4*r^3) +noncomputable def a2 (r : ℝ) : ℝ := 48*(1-r)^3 +noncomputable def b0 (r : ℝ) : ℝ := r^2*(1-r)^3*(3-2*r)^3*f0 r +noncomputable def b1 (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*f1 r +noncomputable def b2 (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*f2 r +noncomputable def b3 (r : ℝ) : ℝ := 24*(1-r)^3*(25-4*r^2-10*r) + +lemma a_nonneg (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : + 0 ≤ a0 r ∧ 0 ≤ a1 r ∧ 0 ≤ a2 r := by + have h1 : 0 ≤ 1-r := by linarith + have h2 : 0 ≤ 3-2*r := by linarith + have h3 : 0 ≤ 10*r^2+r+1 := by nlinarith [sq_nonneg (20*r+1)] + have h4a : 0 ≤ r^2*(20-4*r) := mul_nonneg (sq_nonneg _) (by linarith) + have h4 : 0 ≤ 9+5*r+20*r^2-4*r^3 := by nlinarith + dsimp [a0, a1, a2] + exact ⟨by positivity, by positivity, by positivity⟩ + +lemma b_nonneg (r : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) : + 0 ≤ b0 r ∧ 0 ≤ b1 r ∧ 0 ≤ b2 r ∧ 0 ≤ b3 r := by + have h1 : 0 ≤ 1-r := by linarith + have h2 : 0 ≤ 3-2*r := by linarith + have h3a : 0 ≤ (1-r)*(4*r+14) := mul_nonneg h1 (by linarith) + have h3 : 0 ≤ 25-4*r^2-10*r := by nlinarith + have hf0 := (f0_pos r hl hu).le + have hf1 := (f1_pos r hl hu).le + have hf2 := (f2_pos r hl hu).le + dsimp [b0, b1, b2, b3] + exact ⟨by positivity, by positivity, by positivity, by positivity⟩ + +lemma A_certificate (r z : ℝ) (hr : 3-2*r ≠ 0) (hz : 1+z ≠ 0) : + (1+z)^2*(3-2*r)^2 * A (xa r z) (r*xa r z) = + (xa r z)^2*(a0 r+a1 r*z+a2 r*z^2) := by + dsimp [A, xa, a0, a1, a2] + field_simp + ring + +lemma L_certificate (r z : ℝ) (hr : 3-2*r ≠ 0) (hz : 1+z ≠ 0) : + (1+z)^3*(3-2*r)^3 * Lscaled (xa r z) (r*xa r z) = + (xa r z)^2*(b0 r+b1 r*z+b2 r*z^2+b3 r*z^3) := by + dsimp [Lscaled, xa, b0, b1, b2, b3, f0, f1, f2] + field_simp + ring + +lemma A_nonneg_param (r z : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) + (hz : 0 ≤ z) : 0 ≤ A (xa r z) (r*xa r z) := by + have h1 : 0 < 1+z := by linarith + have h2 : 0 < 3-2*r := by linarith + obtain ⟨h0, ha1, ha2⟩ := a_nonneg r hl hu + have hrhs : 0 ≤ (xa r z)^2*(a0 r+a1 r*z+a2 r*z^2) := by positivity + rw [← A_certificate r z (ne_of_gt h2) (ne_of_gt h1)] at hrhs + exact nonneg_of_mul_nonneg_right hrhs (by positivity) + +lemma L_nonneg_param (r z : ℝ) (hl : -(1/2 : ℝ) ≤ r) (hu : r < 1) + (hz : 0 ≤ z) : 0 ≤ Lscaled (xa r z) (r*xa r z) := by + have h1 : 0 < 1+z := by linarith + have h2 : 0 < 3-2*r := by linarith + obtain ⟨h0, hb1, hb2, hb3⟩ := b_nonneg r hl hu + have hrhs : 0 ≤ (xa r z)^2*(b0 r+b1 r*z+b2 r*z^2+b3 r*z^3) := by positivity + rw [← L_certificate r z (ne_of_gt h2) (ne_of_gt h1)] at hrhs + exact nonneg_of_mul_nonneg_right hrhs (by positivity) + +lemma physical_parameterization (x y : ℝ) (hx : 0 < x) (hx1 : x < 1) + (hdisc : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : + ∃ r z : ℝ, -(1/2 : ℝ) ≤ r ∧ r < 1 ∧ 0 ≤ z ∧ + x = xa r z ∧ y = r * x := by + let r := y/x + have hylt : y < x := by + nlinarith [mul_pos (sq_pos_of_pos hx) (sub_pos.mpr hx1)] + have hr1 : r < 1 := (div_lt_one hx).2 hylt + have hyr : y = r*x := by dsimp [r]; field_simp + have hrsq : r^2 ≤ x := by + dsimp [r] + rw [div_pow] + apply (div_le_iff₀ (sq_pos_of_pos hx)).2 + nlinarith + have hden : 0 < 3-2*r := by linarith + have hupper : x < 1/(3-2*r) := by + apply (lt_div_iff₀ hden).2 + nlinarith [hD] + have hdsq : r^2*(3-2*r) < 1 := lt_of_le_of_lt + (mul_le_mul_of_nonneg_right hrsq hden.le) ((lt_div_iff₀ hden).1 hupper) + have hpos : 0 < (1-r)^2*(1+2*r) := by nlinarith + have hrlo : -(1/2 : ℝ) ≤ r := by + have := pos_of_mul_pos_right hpos (sq_nonneg (1-r)) + linarith + let z := (x-r^2)/(1/(3-2*r)-x) + have hz : 0 ≤ z := div_nonneg (by linarith) (by linarith) + have hfrep : x = xa r z := by + dsimp [xa] + apply (eq_div_iff (ne_of_gt (show 0 < 1+z by linarith))).2 + have hn0 : 1/(3-2*r)-x ≠ 0 := ne_of_gt (sub_pos.mpr hupper) + have hzEq : z * (1/(3-2*r)-x) = x-r^2 := div_mul_cancel₀ _ hn0 + simp only [div_eq_mul_inv, one_mul] at hzEq ⊢ + nlinarith only [hzEq] + exact ⟨r, z, hrlo, hr1, hz, hfrep, hyr⟩ + +lemma physical_signs (x y : ℝ) (hx : 0 ≤ x) (hx1 : x < 1) + (hdisc : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : + 0 ≤ A x y ∧ 0 ≤ A x y + C x y ∧ 0 ≤ Lscaled x y := by + have hyx : y ≤ x := by + have hpow : x^3 ≤ x^2 := by nlinarith [mul_nonneg (sq_nonneg x) (by linarith : 0 ≤ 1-x)] + nlinarith [sq_nonneg (y-x)] + have hlast : 0 ≤ x^2+x-2*y := by + by_contra hn + have hn' : x^2+x < 2*y := by linarith + have hy : 0 < y := by nlinarith [sq_nonneg x] + have hp : (x^2+x)^2 < (2*y)^2 := by + nlinarith [mul_pos (by linarith : 0 < 2*y-(x^2+x)) + (by nlinarith [sq_nonneg x] : 0 < 2*y+(x^2+x))] + nlinarith [sq_nonneg (x^2-x)] + have hN1 : 0 ≤ A x y + C x y := by + rw [N1_factor] + exact mul_nonneg (mul_nonneg (by linarith) (by linarith)) hlast + rcases eq_or_lt_of_le hx with hzero | hpos + · have hxzero : x = 0 := hzero.symm + have hyzero : y = 0 := by rw [hxzero] at hdisc; nlinarith [sq_nonneg y] + subst x; subst y + norm_num [A, C, Lscaled] + · obtain ⟨r, z, hl, hu, hz, hxr, hyr⟩ := physical_parameterization x y hpos hx1 hdisc hD + have hA : 0 ≤ A x y := by rw [hyr, hxr]; exact A_nonneg_param r z hl hu hz + have hL : 0 ≤ Lscaled x y := by rw [hyr, hxr]; exact L_nonneg_param r z hl hu hz + exact ⟨hA, hN1, hL⟩ + +end ThreeState.Radial + + + +namespace ThreeState.Radial + +noncomputable def avg (v : Fin 3 → ℝ) : ℝ := (∑ i, v i) / 3 +noncomputable def momentX (v : Fin 3 → ℝ) : ℝ := avg (fun i => (v i)^2) / 2 +noncomputable def momentY (v : Fin 3 → ℝ) : ℝ := avg (fun i => (v i)^3) / 2 +noncomputable def denom (v : Fin 3 → ℝ) (t : ℝ) : ℝ := + 1 - 3*t^2*momentX v + 2*t^3*momentY v +noncomputable def cofactor (v : Fin 3 → ℝ) (i : Fin 3) : ℝ := + 1-v i+(v i)^2-3*momentX v +noncomputable def kernel (v : Fin 3 → ℝ) (t : ℝ) (i : Fin 3) : ℝ := + v i-t*((v i)^2-2*momentX v) +noncomputable def centeredLog (v : Fin 3 → ℝ) (i : Fin 3) : ℝ := + Real.log (1+v i) - avg (fun j => Real.log (1+v j)) + +lemma avg_expand (v : Fin 3 → ℝ) : avg v = (v 0+v 1+v 2)/3 := by + simp [avg, Fin.sum_univ_succ]; ring + +lemma zero_sum_elim (v : Fin 3 → ℝ) (hv : avg v = 0) : v 2 = -v 0-v 1 := by + rw [avg_expand] at hv; linarith + +lemma cubic_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : + (v i)^3 = 3*momentX v*v i+2*momentY v := by + have h2 := zero_sum_elim v hv + fin_cases i + · change (v 0)^3 = 3*momentX v*v 0+2*momentY v + simp only [momentX, momentY, avg_expand, h2]; ring + · change (v 1)^3 = 3*momentX v*v 1+2*momentY v + simp only [momentX, momentY, avg_expand, h2]; ring + · change (v 2)^3 = 3*momentX v*v 2+2*momentY v + simp only [momentX, momentY, avg_expand, h2]; ring + +lemma denom_product (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) : + denom v t = (1+t*v 0)*(1+t*v 1)*(1+t*v 2) := by + have h2 := zero_sum_elim v hv + simp only [denom, momentX, momentY, avg_expand, h2] + ring + +lemma cofactor_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (i : Fin 3) : + (1+v i) * cofactor v i = denom v 1 := by + dsimp [cofactor, denom] + nlinarith only [cubic_identity v hv i] + +lemma message_segment_pos (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (i : Fin 3) : 0 < 1+t*v i := by + have hv := hp i + rcases eq_or_lt_of_le ht0 with h | h + · rw [← h]; norm_num + · have : 0 < t*(1+v i) := mul_pos h hv + nlinarith + +lemma denom_pos (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 < denom v t := by + rw [denom_product v hv t] + exact mul_pos (mul_pos (message_segment_pos v hp t ht0 ht1 0) + (message_segment_pos v hp t ht0 ht1 1)) (message_segment_pos v hp t ht0 ht1 2) + +lemma momentX_nonneg (v : Fin 3 → ℝ) : 0 ≤ momentX v := by + simp only [momentX, avg_expand]; positivity + +lemma discriminant (v : Fin 3 → ℝ) (hv : avg v = 0) : + (v 0-v 1)^2*(v 0-v 2)^2*(v 1-v 2)^2 = + 108*((momentX v)^3-(momentY v)^2) := by + have h2 := zero_sum_elim v hv + simp only [momentX, momentY, avg_expand, h2] + ring + +lemma discriminant_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) : + (momentY v)^2 ≤ (momentX v)^3 := by + have h := discriminant v hv + have : 0 ≤ (v 0-v 1)^2*(v 0-v 2)^2*(v 1-v 2)^2 := by positivity + linarith + +lemma momentX_lt_one (v : Fin 3 → ℝ) (hv : avg v = 0) + (hp : ∀ i, 0 < 1+v i) : momentX v < 1 := by + have hu := zero_sum_elim v hv + have h01 := mul_pos (hp 0) (hp 1) + have h02 := mul_pos (hp 0) (hp 2) + have h12 := mul_pos (hp 1) (hp 2) + simp only [momentX, avg_expand] + rw [hu] at * + nlinarith + +lemma momentY_le_X (v : Fin 3 → ℝ) (hv : avg v = 0) + (hp : ∀ i, 0 < 1+v i) : momentY v ≤ momentX v := by + have hX := momentX_nonneg v + have hX1 := momentX_lt_one v hv hp + have hdisc := discriminant_nonneg v hv + have hpow : (momentX v)^3 ≤ (momentX v)^2 := by + nlinarith [mul_nonneg (sq_nonneg (momentX v)) (by linarith : 0 ≤ 1-momentX v)] + nlinarith [sq_nonneg (momentY v-momentX v)] + +lemma denom_le_one (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : denom v t ≤ 1 := by + have h1 := mul_le_mul_of_nonneg_left (momentY_le_X v hv hp) (pow_nonneg ht0 3) + have h2 := mul_nonneg (mul_nonneg (sq_nonneg t) (momentX_nonneg v)) + (show 0 ≤ 1-t by linarith) + have h3 : 0 ≤ t^2*momentX v := mul_nonneg (sq_nonneg t) (momentX_nonneg v) + dsimp [denom] + nlinarith + +noncomputable def cofMoment (v : Fin 3 → ℝ) (j : ℕ) := + avg (fun i => (cofactor v i)^j) + +lemma cofMoment_one (v : Fin 3 → ℝ) (hv : avg v = 0) : + cofMoment v 1 = 1-momentX v := by + have h2 := zero_sum_elim v hv + simp only [cofMoment, cofactor, momentX, avg_expand, h2] + ring + +lemma cofMoment_two (v : Fin 3 → ℝ) (hv : avg v = 0) : + cofMoment v 2 = 3*(momentX v)^2-4*momentY v+1 := by + have h2 := zero_sum_elim v hv + simp only [cofMoment, cofactor, momentX, momentY, avg_expand, h2] + ring + +lemma cofMoment_three (v : Fin 3 → ℝ) (hv : avg v = 0) : + cofMoment v 3 = -9*(momentX v)^3+9*(momentX v)^2+ + 6*momentX v*momentY v+3*momentX v+4*(momentY v)^2-14*momentY v+1 := by + have h2 := zero_sum_elim v hv + simp only [cofMoment, cofactor, momentX, momentY, avg_expand, h2] + ring + +noncomputable def numerator (v : Fin 3 → ℝ) (t : ℝ) := + (4/5 : ℝ) * avg (fun i => kernel v t i * + ((cofactor v i)^2*denom v 1-3*cofactor v i*(denom v 1)^2+ + (2*cofMoment v 3-3*cofMoment v 2*denom v 1)*v i)) + +lemma numerator_expansion (v : Fin 3 → ℝ) (hv : avg v = 0) (t : ℝ) : + numerator v t = (24/5 : ℝ)*(A (momentX v) (momentY v)+t*C (momentX v) (momentY v)) := by + unfold numerator + rw [cofMoment_two v hv, cofMoment_three v hv] + have h2 := zero_sum_elim v hv + simp only [cofactor, kernel, denom, A, C, momentX, momentY, avg_expand, h2] + ring + +lemma integral_avg (f : Fin 3 → ℝ → ℝ) + (hf : ∀ i, IntervalIntegrable (f i) MeasureTheory.volume 0 1) : + (∫ t in (0 : ℝ)..1, avg (fun i => f i t)) = avg (fun i => ∫ t in (0 : ℝ)..1, f i t) := by + unfold avg + rw [intervalIntegral.integral_div, intervalIntegral.integral_finsetSum (fun i _ => hf i)] + +lemma log_integral (a : ℝ) (ha : 0 < 1+a) : + Real.log (1+a) = ∫ t in (0 : ℝ)..1, a/(1+t*a) := by + have hp : ∀ t ∈ Set.Icc (0 : ℝ) 1, 0 < 1+t*a := by + intro t ht + rcases eq_or_lt_of_le ht.1 with hz | hz + · rw [← hz]; norm_num + · nlinarith [mul_pos hz ha, ht.2] + have hc : ContinuousOn (fun t : ℝ => a/(1+t*a)) (Set.Icc 0 1) := + continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (hp t ht)) + have hi : IntervalIntegrable (fun t : ℝ => a/(1+t*a)) MeasureTheory.volume 0 1 := + hc.intervalIntegrable_of_Icc (by norm_num) + have hD : ∀ t ∈ Set.uIcc (0 : ℝ) 1, + HasDerivAt (fun t : ℝ => Real.log (1+t*a)) (a/(1+t*a)) t := by + intro t ht + have ht' : t ∈ Set.Icc (0 : ℝ) 1 := by simpa using ht + simpa using (((hasDerivAt_id t).mul_const a).const_add 1).log (ne_of_gt (hp t ht')) + simpa using (intervalIntegral.integral_eq_sub_of_hasDerivAt hD hi).symm + +lemma kernel_div_identity (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (i : Fin 3) : + v i/(1+t*v i)-avg (fun j => v j/(1+t*v j)) = kernel v t i/denom v t := by + have h0 := ne_of_gt (message_segment_pos v hp t ht0 ht1 0) + have h1 := ne_of_gt (message_segment_pos v hp t ht0 ht1 1) + have h2 := ne_of_gt (message_segment_pos v hp t ht0 ht1 2) + have h0c : 1+v 0*t ≠ 0 := by simpa [mul_comm] using h0 + have h1c : 1+v 1*t ≠ 0 := by simpa [mul_comm] using h1 + have h2c : 1+v 2*t ≠ 0 := by simpa [mul_comm] using h2 + have hv2 := zero_sum_elim v hv + rw [denom_product v hv t] + fin_cases i + · change v 0/(1+t*v 0)-avg (fun j => v j/(1+t*v j)) = + kernel v t 0/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) + simp only [avg_expand, kernel, momentX] + field_simp [h0, h1, h2, h0c, h1c, h2c] + rw [hv2] + ring + · change v 1/(1+t*v 1)-avg (fun j => v j/(1+t*v j)) = + kernel v t 1/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) + simp only [avg_expand, kernel, momentX] + field_simp [h0, h1, h2, h0c, h1c, h2c] + rw [hv2] + ring + · change v 2/(1+t*v 2)-avg (fun j => v j/(1+t*v j)) = + kernel v t 2/((1+t*v 0)*(1+t*v 1)*(1+t*v 2)) + simp only [avg_expand, kernel, momentX] + field_simp [h0, h1, h2, h0c, h1c, h2c] + rw [hv2] + ring + +lemma centeredLog_integral (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (i : Fin 3) : centeredLog v i = ∫ t in (0 : ℝ)..1, kernel v t i / denom v t := by + have hi : ∀ j, IntervalIntegrable (fun t : ℝ => v j/(1+t*v j)) MeasureTheory.volume 0 1 := by + intro j + apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) + refine continuousOn_const.div (by fun_prop) ?_ + intro t ht + exact ne_of_gt (message_segment_pos v hp t ht.1 ht.2 j) + have ha : IntervalIntegrable (fun t : ℝ => avg (fun j => v j/(1+t*v j))) + MeasureTheory.volume 0 1 := by + unfold avg + exact (IntervalIntegrable.sum Finset.univ (fun j _ => hi j)).div_const 3 + unfold centeredLog + rw [log_integral (v i) (hp i)] + have hlogs : (fun j => Real.log (1+v j)) = (fun j => ∫ t in (0 : ℝ)..1, v j/(1+t*v j)) := by + funext j; exact log_integral (v j) (hp j) + rw [hlogs, ← integral_avg _ hi, ← intervalIntegral.integral_sub (hi i) ha] + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (0 : ℝ) 1 := by simpa using ht + exact kernel_div_identity v hv hp t ht'.1 ht'.2 i + +noncomputable def invMoment (v : Fin 3 → ℝ) (j : ℕ) := + avg (fun i => ((1+v i)⁻¹)^j) +noncomputable def logInvMoment (v : Fin 3 → ℝ) (j : ℕ) := + avg (fun i => centeredLog v i*((1+v i)⁻¹)^j) +noncomputable def logMoment (v : Fin 3 → ℝ) := avg (fun i => v i*centeredLog v i) + + +noncomputable def gExpr (v : Fin 3 → ℝ) := + 6-12*invMoment v 1+8*invMoment v 2-2*invMoment v 3+ + (4/5 : ℝ)*(logInvMoment v 2-3*logInvMoment v 1+ + (2*invMoment v 3-3*invMoment v 2)*logMoment v+ + 3*(invMoment v 1-1)*(invMoment v 2-invMoment v 1)) +noncomputable def rCore (v : Fin 3 → ℝ) := + (6-12*(momentX v)^2)*(denom v 1)^3-12*cofMoment v 1*(denom v 1)^2+ + 8*cofMoment v 2*denom v 1-2*cofMoment v 3+ + (12/5 : ℝ)*(cofMoment v 1-denom v 1)*(cofMoment v 2-cofMoment v 1*denom v 1) +noncomputable def logCoeff (v : Fin 3 → ℝ) (i : Fin 3) := + (cofactor v i)^2*denom v 1-3*cofactor v i*(denom v 1)^2+ + (2*cofMoment v 3-3*cofMoment v 2*denom v 1)*v i + +lemma inv_cofactor (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (i : Fin 3) : (1+v i)⁻¹ = cofactor v i / denom v 1 := by + apply (eq_div_iff (ne_of_gt (denom_pos v hv hp 1 (by norm_num) le_rfl))).2 + rw [← cofactor_identity v hv i] + field_simp [ne_of_gt (hp i)] + +lemma RN_algebra (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : + (denom v 1)^3*(gExpr v-12*(momentX v)^2) = + rCore v + (4/5 : ℝ)*avg (fun i => centeredLog v i*logCoeff v i) := by + have hD := ne_of_gt (denom_pos v hv hp 1 (by norm_num) le_rfl) + unfold gExpr invMoment logInvMoment logMoment rCore logCoeff + simp_rw [inv_cofactor v hv hp] + simp only [cofMoment, avg_expand] + field_simp + ring + +lemma kernel_div_integrable (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (i : Fin 3) : IntervalIntegrable (fun t : ℝ => kernel v t i/denom v t) + MeasureTheory.volume 0 1 := by + apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) + unfold kernel denom + refine ContinuousOn.div (by fun_prop) (by fun_prop) ?_ + intro t ht + exact ne_of_gt (denom_pos v hv hp t ht.1 ht.2) + +lemma RN_representation (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : + (denom v 1)^3*(gExpr v-12*(momentX v)^2) = + rCore v + ∫ t in (0 : ℝ)..1, numerator v t / denom v t := by + rw [RN_algebra v hv hp] + congr 1 + have hg : ∀ t : ℝ, numerator v t/denom v t = (4/5 : ℝ)* + avg (fun i => (kernel v t i/denom v t)*logCoeff v i) := by + intro t + simp only [numerator, logCoeff, avg_expand] + ring + simp_rw [hg] + rw [intervalIntegral.integral_const_mul, integral_avg _ + (fun i => (kernel_div_integrable v hv hp i).mul_const (logCoeff v i))] + congr 1 + congr 1 + funext i + rw [intervalIntegral.integral_mul_const, centeredLog_integral v hv hp i] + +lemma integrate_N_lower (a c x y : ℝ) : + (∫ t in (0 : ℝ)..1, (24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) = + (24/5 : ℝ)*(a+c/2+a*x+(3*c*x-2*a*y)/4-2*c*y/5) := by + let P := fun t : ℝ => (24/5 : ℝ)*(a*t+c*t^2/2+a*x*t^3+ + (3*c*x-2*a*y)*t^4/4-2*c*y*t^5/5) + have hd : ∀ t : ℝ, HasDerivAt P ((24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) t := by + intro t + dsimp [P] + convert (((((hasDerivAt_id t).const_mul a).add + (((hasDerivAt_id t).pow 2).const_mul c |>.div_const 2)).add + (((hasDerivAt_id t).pow 3).const_mul (a*x))).add + (((hasDerivAt_id t).pow 4).const_mul (3*c*x-2*a*y) |>.div_const 4) |>.sub + (((hasDerivAt_id t).pow 5).const_mul (2*c*y) |>.div_const 5)).const_mul (24/5 : ℝ) using 1 <;> + first | rfl | (norm_num; ring) + have hi : IntervalIntegrable (fun t : ℝ => (24/5 : ℝ)*(a+t*c)*(1+3*t^2*x-2*t^3*y)) + MeasureTheory.volume 0 1 := Continuous.intervalIntegrable (by fun_prop) 0 1 + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) hi] + dsimp [P]; ring + +lemma L_expansion (v : Fin 3 → ℝ) (hv : avg v = 0) : + rCore v + (∫ t in (0 : ℝ)..1, numerator v t*(2-denom v t)) = + (6/25 : ℝ)*Lscaled (momentX v) (momentY v) := by + have hg : (fun t : ℝ => numerator v t*(2-denom v t)) = + (fun t : ℝ => (24/5 : ℝ)*(A (momentX v) (momentY v)+t*C (momentX v) (momentY v))* + (1+3*t^2*momentX v-2*t^3*momentY v)) := by + funext t + rw [numerator_expansion v hv t] + dsimp [denom]; ring + rw [hg, integrate_N_lower] + unfold rCore + rw [cofMoment_one v hv, cofMoment_two v hv, cofMoment_three v hv] + dsimp [denom, A, C, Lscaled] + ring + +lemma numerator_nonneg (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 0 ≤ numerator v t := by + have hD : 0 < 1-3*momentX v+2*momentY v := by + simpa [denom] using denom_pos v hv hp 1 (by norm_num) le_rfl + obtain ⟨ha, hac, _⟩ := physical_signs (momentX v) (momentY v) + (momentX_nonneg v) (momentX_lt_one v hv hp) (discriminant_nonneg v hv) hD + rw [numerator_expansion v hv t] + have h := add_nonneg (mul_nonneg (show 0 ≤ 1-t by linarith) ha) (mul_nonneg ht0 hac) + nlinarith only [h] + + + +lemma gExpr_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : + 12*(momentX v)^2 ≤ gExpr v := by + have hi1 : IntervalIntegrable (fun t => numerator v t*(2-denom v t)) + MeasureTheory.volume 0 1 := by + apply Continuous.intervalIntegrable + unfold numerator kernel denom avg + fun_prop + have hi2 : IntervalIntegrable (fun t => numerator v t/denom v t) + MeasureTheory.volume 0 1 := by + apply ContinuousOn.intervalIntegrable_of_Icc (by norm_num) + apply ContinuousOn.div + · unfold numerator kernel avg; fun_prop + · unfold denom; fun_prop + · intro t ht; exact ne_of_gt (denom_pos v hv hp t ht.1 ht.2) + have hbound : ∀ t ∈ Set.Icc (0 : ℝ) 1, numerator v t*(2-denom v t) ≤ numerator v t/denom v t := by + intro t ht + have hD := denom_pos v hv hp t ht.1 ht.2 + apply (le_div_iff₀ hD).2 + nlinarith [mul_nonneg (numerator_nonneg v hv hp t ht.1 ht.2) (sq_nonneg (1-denom v t))] + have hint := intervalIntegral.integral_mono_on (by norm_num) hi1 hi2 hbound + have hR := RN_representation v hv hp + have hL := L_expansion v hv + have hd := denom_pos v hv hp 1 (by norm_num) le_rfl + have hdom : 0 < 1-3*momentX v+2*momentY v := by simpa [denom] using hd + have hLpos := (physical_signs (momentX v) (momentY v) (momentX_nonneg v) + (momentX_lt_one v hv hp) (discriminant_nonneg v hv) hdom).2.2 + have hprod : 0 ≤ (denom v 1)^3*(gExpr v-12*(momentX v)^2) := by linarith + have := nonneg_of_mul_nonneg_right hprod (pow_pos hd 3) + linarith + +end ThreeState.Radial + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Region.lean b/lean/OAI/Probability/ThreeState/Region.lean index 25e7426a23c14f7e6ab8dc0abf4ff2ba39233496..491426d25eee97eebdfa41739d2089d74c9794e5 100644 --- a/lean/OAI/Probability/ThreeState/Region.lean +++ b/lean/OAI/Probability/ThreeState/Region.lean @@ -1,139 +1,139 @@ -import Mathlib -import OAI.Probability.ThreeState.Negative -import OAI.Probability.ThreeState.Supercritical - -namespace OAI - -/-! Threshold consequences on the proved parameter regions. -/ - -namespace ThreeState -open Filter Topology - -lemma Nonreconstructs.not_reconstructs {a : ℕ → ℝ} (hz : Nonreconstructs a) : - ¬ Reconstructs a := by - rintro ⟨L, hL, hlim⟩ - have he : L = 0 := tendsto_nhds_unique hlim hz - exact (ne_of_gt hL) he - - - -theorem observed_nonreconstructs_iff_not_reconstructs (offspring : PMF ℕ) - (lam : ℝ) (h : Admissible lam) : - Nonreconstructs (fun n => advantage (observedLaw offspring lam h n)) ↔ - ¬ Reconstructs (fun n => advantage (observedLaw offspring lam h n)) := by - refine ⟨Nonreconstructs.not_reconstructs, ?_⟩ - intro hn - obtain ⟨L, hL, _, hlim⟩ := observedAdvantage_tendsto offspring lam h - have he : L = 0 := by - by_contra hne - exact hn ⟨L, lt_of_le_of_ne hL (Ne.symm hne), hlim⟩ - simpa only [Nonreconstructs, he] using hlim - - - -theorem regular_nonreconstruction_in_proved_region (b : ℕ) (hb : 2 ≤ b) - (lam : ℝ) (h : Admissible lam) (hc : (b : ℝ) * lam ^ 2 ≤ 1) - (hregion : 0 ≤ lam ∨ (b : ℝ) * |lam| ≤ 1 ∨ 4 * (b : ℝ) * lam ^ 2 ≤ 1) : - Nonreconstructs (regularAdvantage b lam h) := by - rcases hregion with hn | hD | hs - · exact regular_nonnegative_nonreconstruction b hb lam h hn hc - · exact regular_dobrushin_nonreconstruction b hb lam h hD - · by_cases hn : 0 ≤ lam - · exact regular_nonnegative_nonreconstruction b hb lam h hn hc - · exact regular_small_negative_nonreconstruction b hb lam h (lt_of_not_ge hn).le hs - - - -theorem poisson_nonreconstruction_in_proved_region (d : ℝ) (hd : 1 < d) - (lam : ℝ) (h : Admissible lam) (hc : d * lam ^ 2 ≤ 1) - (hregion : 0 ≤ lam ∨ d * |lam| ≤ 1 ∨ 4 * d * lam ^ 2 ≤ 1) : - Nonreconstructs (poissonAdvantage d hd lam h) := by - rcases hregion with hn | hD | hs - · exact poisson_nonnegative_nonreconstruction d hd lam h hn hc - · exact poisson_dobrushin_nonreconstruction d hd lam h hD - · by_cases hn : 0 ≤ lam - · exact poisson_nonnegative_nonreconstruction d hd lam h hn hc - · exact poisson_small_negative_nonreconstruction d hd lam h (lt_of_not_ge hn).le hs - - - -theorem regular_threshold_in_proved_region (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) - (h : Admissible lam) - (hregion : 1 < (b : ℝ) * lam ^ 2 ∨ 0 ≤ lam ∨ - (b : ℝ) * |lam| ≤ 1 ∨ 4 * (b : ℝ) * lam ^ 2 ≤ 1) : - (Reconstructs (regularAdvantage b lam h) ↔ 1 < (b : ℝ) * lam ^ 2) ∧ - ((b : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage b lam h)) := by - have hz (hc : (b : ℝ) * lam ^ 2 ≤ 1) : - Nonreconstructs (regularAdvantage b lam h) := by - rcases hregion with hsuper | hknown - · exact False.elim ((not_lt_of_ge hc) hsuper) - · exact regular_nonreconstruction_in_proved_region b hb lam h hc hknown - refine ⟨⟨?_, regular_supercritical b hb lam h⟩, hz⟩ - intro hr - by_contra hcrit - exact (hz (le_of_not_gt hcrit)).not_reconstructs hr - - - -theorem poisson_threshold_in_proved_region (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) - (hregion : 1 < d * lam ^ 2 ∨ 0 ≤ lam ∨ d * |lam| ≤ 1 ∨ 4 * d * lam ^ 2 ≤ 1) : - (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ - (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := by - have hz (hc : d * lam ^ 2 ≤ 1) : Nonreconstructs (poissonAdvantage d hd lam h) := by - rcases hregion with hsuper | hknown - · exact False.elim ((not_lt_of_ge hc) hsuper) - · exact poisson_nonreconstruction_in_proved_region d hd lam h hc hknown - refine ⟨⟨?_, poisson_supercritical d hd lam h⟩, hz⟩ - intro hr - by_contra hcrit - exact (hz (le_of_not_gt hcrit)).not_reconstructs hr - - - -theorem regular_nonnegative_threshold (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) - (h : Admissible lam) (hn : 0 ≤ lam) : - (Reconstructs (regularAdvantage b lam h) ↔ 1 < (b : ℝ) * lam ^ 2) ∧ - ((b : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage b lam h)) := - regular_threshold_in_proved_region b hb lam h (Or.inr (Or.inl hn)) - - - -theorem poisson_nonnegative_threshold (d : ℝ) (hd : 1 < d) (lam : ℝ) - (h : Admissible lam) (hn : 0 ≤ lam) : - (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ - (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := - poisson_threshold_in_proved_region d hd lam h (Or.inr (Or.inl hn)) - - - -theorem binary_exact_threshold (lam : ℝ) (h : Admissible lam) : - (Reconstructs (regularAdvantage 2 lam h) ↔ 1 < (2 : ℝ) * lam ^ 2) ∧ - ((2 : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage 2 lam h)) := by - apply regular_threshold_in_proved_region 2 (by omega) lam h - by_cases hn : 0 ≤ lam - · exact Or.inr (Or.inl hn) - · refine Or.inr (Or.inr (Or.inl ?_)) - rw [abs_of_nonpos (lt_of_not_ge hn).le] - norm_num - linarith [h.1] - - - -theorem poisson_le_two_exact_threshold (d : ℝ) (hd : 1 < d) (hupper : d ≤ 2) - (lam : ℝ) (h : Admissible lam) : - (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ - (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := by - apply poisson_threshold_in_proved_region d hd lam h - by_cases hn : 0 ≤ lam - · exact Or.inr (Or.inl hn) - · refine Or.inr (Or.inr (Or.inl ?_)) - have hs : |lam| ≤ 1 / 2 := by - rw [abs_of_nonpos (lt_of_not_ge hn).le] - linarith [h.1] - nlinarith [mul_nonneg (show 0 ≤ d by linarith) - (show 0 ≤ 1 / 2 - |lam| by linarith)] - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Negative +import OAI.Probability.ThreeState.Supercritical + +namespace OAI + +/-! Threshold consequences on the proved parameter regions. -/ + +namespace ThreeState +open Filter Topology + +lemma Nonreconstructs.not_reconstructs {a : ℕ → ℝ} (hz : Nonreconstructs a) : + ¬ Reconstructs a := by + rintro ⟨L, hL, hlim⟩ + have he : L = 0 := tendsto_nhds_unique hlim hz + exact (ne_of_gt hL) he + + + +theorem observed_nonreconstructs_iff_not_reconstructs (offspring : PMF ℕ) + (lam : ℝ) (h : Admissible lam) : + Nonreconstructs (fun n => advantage (observedLaw offspring lam h n)) ↔ + ¬ Reconstructs (fun n => advantage (observedLaw offspring lam h n)) := by + refine ⟨Nonreconstructs.not_reconstructs, ?_⟩ + intro hn + obtain ⟨L, hL, _, hlim⟩ := observedAdvantage_tendsto offspring lam h + have he : L = 0 := by + by_contra hne + exact hn ⟨L, lt_of_le_of_ne hL (Ne.symm hne), hlim⟩ + simpa only [Nonreconstructs, he] using hlim + + + +theorem regular_nonreconstruction_in_proved_region (b : ℕ) (hb : 2 ≤ b) + (lam : ℝ) (h : Admissible lam) (hc : (b : ℝ) * lam ^ 2 ≤ 1) + (hregion : 0 ≤ lam ∨ (b : ℝ) * |lam| ≤ 1 ∨ 4 * (b : ℝ) * lam ^ 2 ≤ 1) : + Nonreconstructs (regularAdvantage b lam h) := by + rcases hregion with hn | hD | hs + · exact regular_nonnegative_nonreconstruction b hb lam h hn hc + · exact regular_dobrushin_nonreconstruction b hb lam h hD + · by_cases hn : 0 ≤ lam + · exact regular_nonnegative_nonreconstruction b hb lam h hn hc + · exact regular_small_negative_nonreconstruction b hb lam h (lt_of_not_ge hn).le hs + + + +theorem poisson_nonreconstruction_in_proved_region (d : ℝ) (hd : 1 < d) + (lam : ℝ) (h : Admissible lam) (hc : d * lam ^ 2 ≤ 1) + (hregion : 0 ≤ lam ∨ d * |lam| ≤ 1 ∨ 4 * d * lam ^ 2 ≤ 1) : + Nonreconstructs (poissonAdvantage d hd lam h) := by + rcases hregion with hn | hD | hs + · exact poisson_nonnegative_nonreconstruction d hd lam h hn hc + · exact poisson_dobrushin_nonreconstruction d hd lam h hD + · by_cases hn : 0 ≤ lam + · exact poisson_nonnegative_nonreconstruction d hd lam h hn hc + · exact poisson_small_negative_nonreconstruction d hd lam h (lt_of_not_ge hn).le hs + + + +theorem regular_threshold_in_proved_region (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) + (h : Admissible lam) + (hregion : 1 < (b : ℝ) * lam ^ 2 ∨ 0 ≤ lam ∨ + (b : ℝ) * |lam| ≤ 1 ∨ 4 * (b : ℝ) * lam ^ 2 ≤ 1) : + (Reconstructs (regularAdvantage b lam h) ↔ 1 < (b : ℝ) * lam ^ 2) ∧ + ((b : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage b lam h)) := by + have hz (hc : (b : ℝ) * lam ^ 2 ≤ 1) : + Nonreconstructs (regularAdvantage b lam h) := by + rcases hregion with hsuper | hknown + · exact False.elim ((not_lt_of_ge hc) hsuper) + · exact regular_nonreconstruction_in_proved_region b hb lam h hc hknown + refine ⟨⟨?_, regular_supercritical b hb lam h⟩, hz⟩ + intro hr + by_contra hcrit + exact (hz (le_of_not_gt hcrit)).not_reconstructs hr + + + +theorem poisson_threshold_in_proved_region (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) + (hregion : 1 < d * lam ^ 2 ∨ 0 ≤ lam ∨ d * |lam| ≤ 1 ∨ 4 * d * lam ^ 2 ≤ 1) : + (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ + (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := by + have hz (hc : d * lam ^ 2 ≤ 1) : Nonreconstructs (poissonAdvantage d hd lam h) := by + rcases hregion with hsuper | hknown + · exact False.elim ((not_lt_of_ge hc) hsuper) + · exact poisson_nonreconstruction_in_proved_region d hd lam h hc hknown + refine ⟨⟨?_, poisson_supercritical d hd lam h⟩, hz⟩ + intro hr + by_contra hcrit + exact (hz (le_of_not_gt hcrit)).not_reconstructs hr + + + +theorem regular_nonnegative_threshold (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) + (h : Admissible lam) (hn : 0 ≤ lam) : + (Reconstructs (regularAdvantage b lam h) ↔ 1 < (b : ℝ) * lam ^ 2) ∧ + ((b : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage b lam h)) := + regular_threshold_in_proved_region b hb lam h (Or.inr (Or.inl hn)) + + + +theorem poisson_nonnegative_threshold (d : ℝ) (hd : 1 < d) (lam : ℝ) + (h : Admissible lam) (hn : 0 ≤ lam) : + (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ + (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := + poisson_threshold_in_proved_region d hd lam h (Or.inr (Or.inl hn)) + + + +theorem binary_exact_threshold (lam : ℝ) (h : Admissible lam) : + (Reconstructs (regularAdvantage 2 lam h) ↔ 1 < (2 : ℝ) * lam ^ 2) ∧ + ((2 : ℝ) * lam ^ 2 ≤ 1 → Nonreconstructs (regularAdvantage 2 lam h)) := by + apply regular_threshold_in_proved_region 2 (by omega) lam h + by_cases hn : 0 ≤ lam + · exact Or.inr (Or.inl hn) + · refine Or.inr (Or.inr (Or.inl ?_)) + rw [abs_of_nonpos (lt_of_not_ge hn).le] + norm_num + linarith [h.1] + + + +theorem poisson_le_two_exact_threshold (d : ℝ) (hd : 1 < d) (hupper : d ≤ 2) + (lam : ℝ) (h : Admissible lam) : + (Reconstructs (poissonAdvantage d hd lam h) ↔ 1 < d * lam ^ 2) ∧ + (d * lam ^ 2 ≤ 1 → Nonreconstructs (poissonAdvantage d hd lam h)) := by + apply poisson_threshold_in_proved_region d hd lam h + by_cases hn : 0 ≤ lam + · exact Or.inr (Or.inl hn) + · refine Or.inr (Or.inr (Or.inl ?_)) + have hs : |lam| ≤ 1 / 2 := by + rw [abs_of_nonpos (lt_of_not_ge hn).le] + linarith [h.1] + nlinarith [mul_nonneg (show 0 ≤ d by linarith) + (show 0 ≤ 1 / 2 - |lam| by linarith)] + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/RegularCritical.lean b/lean/OAI/Probability/ThreeState/RegularCritical.lean index 68a375045ca1af1222ea7f4ba107995bcbf89990..ef9e48eec73c93fd0ac6301a12d0ca434a73e2e4 100644 --- a/lean/OAI/Probability/ThreeState/RegularCritical.lean +++ b/lean/OAI/Probability/ThreeState/RegularCritical.lean @@ -1,373 +1,373 @@ -import Mathlib -import OAI.Probability.ThreeState.Projection -import OAI.Probability.ThreeState.ScalarBounds - -namespace OAI - -/-! Entropy bounds and non-reconstruction at the positive regular-tree threshold. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma regular_fixedpoint_degree_nu (b : ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) : - posteriorNu (degreePosterior lam h Q hQ.1 b) = posteriorNu Q := by - have hh := hQ.2 ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ - rw [mean_pure] at hh - change (∫ m, (messageX m)^2 ∂(Q : Measure Message)) = - ∫ m : Fin b → Message, normalizer lam h m*(messageX (combineMessage lam h m))^2 ∂(iidMeasure Q b : Measure (Fin b → Message)) at hh - change (∫ m, (messageX m)^2 ∂degreeOutput lam h Q b) = _ - rw [integral_degreeOutput lam h Q b (fun m => (messageX m)^2) (continuous_messageX.pow 2).measurable] - exact hh.symm - -lemma partial_nu_le_regular (b : ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) {j : ℕ} (hj : j ≤ b) : - posteriorNu (degreePosterior lam h Q hQ.1 j) ≤ posteriorNu Q := by - rw [← regular_fixedpoint_degree_nu b lam h Q hQ] - exact degree_nu_monotone lam h hl0 hl1 Q hQ.1 hj - -lemma correlationEntropy_sum (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (b : ℕ) : - correlationEntropy lam h Q b = - ∑ j ∈ Finset.range b, pairCorrelation lam h Q (degreePosterior lam h Q hQ j) := by - induction b with - | zero => simp [correlationEntropy_zero] - | succ b ih => - rw [Finset.sum_range_succ, ← ih] - have hh := correlationEntropy_succ lam h hl0 hl1 Q hQ b - change correlationEntropy lam h Q (b+1) = correlationEntropy lam h Q b + - pairCorrelation lam h Q (degreePosterior lam h Q hQ b) at hh - exact hh - -lemma scalar_sqrt_projection_bound {j beta : ℝ} (hj : 1 ≤ j) (hb : 0 ≤ beta) : - Real.sqrt (j*beta/(1+(j-1)*beta)) ≤ Real.sqrt (j*beta) := by - apply Real.sqrt_le_sqrt - have hd : 1 ≤ 1+(j-1)*beta := by nlinarith - exact div_le_self (mul_nonneg (by linarith) hb) hd - -lemma regular_increment_bound (b : ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) (hs : SpinSymmetric Q) - (he : 0 ≤ posteriorEta Q) (j : ℕ) (hj : j < b) : - 3*lam^4*(posteriorMu Q)^2*((j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q)))- - lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt j ≤ - 3*pairCorrelation lam h Q (degreePosterior lam h Q hQ.1 j) := by - by_cases hj0 : j=0 - · subst j - simp only [Nat.cast_zero, zero_div, mul_zero, Real.sqrt_zero, sub_zero] - exact mul_nonneg (by norm_num) (pairCorrelation_nonneg lam h hl0 hl1 Q _ hQ.1) - · have hj1 : 1 ≤ j := by omega - have hjr : (1:ℝ) ≤ j := by exact_mod_cast hj1 - have hm := posteriorMu_nonneg Q - have hn := posteriorNu_nonneg Q - let L := (j:ℝ)*(lam^2*posteriorMu Q)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q)) - have hb : 0 ≤ lam^2*posteriorMu Q := mul_nonneg (sq_nonneg _) hm - have hL : 0 ≤ L := div_nonneg (mul_nonneg (by positivity) hb) (by positivity) - have hh := pairCorrelation_truncated lam h hl0 hl1 Q (degreePosterior lam h Q hQ.1 j) hQ.1 hs he - (partial_nu_le_regular b lam h hl0 hl1 Q hQ (Nat.le_of_lt hj)) hL - (degree_projection lam h hl0 hl1 Q hQ.1 hs j hj1) - have hsqrt : Real.sqrt L ≤ lam*Real.sqrt (posteriorMu Q)*Real.sqrt j := by - have hh := scalar_sqrt_projection_bound hjr hb - rw [Real.sqrt_mul (show (0:ℝ)≤j by positivity), Real.sqrt_mul (sq_nonneg lam), Real.sqrt_sq_eq_abs, abs_of_nonneg hl0] at hh - dsimp only [L] - nlinarith only [hh] - have hmul := mul_le_mul_of_nonneg_left hsqrt (show 0 ≤ lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q by positivity) - have hsq := Real.sq_sqrt hm - have hlead : 3*lam^2*posteriorMu Q*L = - 3*lam^4*(posteriorMu Q)^2*((j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q))) := by dsimp only [L]; ring - rw [hlead] at hh - have hloss : lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*(lam*Real.sqrt (posteriorMu Q)*Real.sqrt j) = - lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt j := by - calc - _ = lam^4*(Real.sqrt (posteriorMu Q))^2*posteriorNu Q*Real.sqrt j := by ring - _ = _ := by rw [hsq] - rw [hloss] at hmul - linarith only [hh, hmul] - -end ThreeState - -namespace ThreeState -open scoped BigOperators - -lemma sum_range_real (b : ℕ) : (∑ j ∈ Finset.range b, (j:ℝ)) = (b:ℝ)*(b-1)/2 := by - induction b with - | zero => norm_num - | succ b ih => rw [Finset.sum_range_succ, ih]; push_cast; ring - -lemma sum_range_factorial_two (b : ℕ) : - (∑ j ∈ Finset.range b, (j:ℝ)*((j:ℝ)-1)) = (b:ℝ)*(b-1)*(b-2)/3 := by - induction b with - | zero => norm_num - | succ b ih => rw [Finset.sum_range_succ, ih]; push_cast; ring - -lemma reciprocal_tangent {x y D : ℝ} (hx : 0 ≤ x) (hy : 0 < y) (hD : 0 < D) : - x*(2*D-y)/D^2 ≤ x/y := by - apply (div_le_div_iff₀ (sq_pos_of_pos hD) hy).mpr - nlinarith only [mul_nonneg hx (sq_nonneg (D-y))] - -lemma regular_rational_sum (b : ℕ) (hb : 2 ≤ b) (lam mu : ℝ) (hc : (b:ℝ)*lam^2=1) (hm : 0 ≤ mu) : - (1-lam^2)/(2*(1+2*mu/3)) ≤ - lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu))) := by - let D := 1+2*mu/3 - have hD : 0 < D := by dsimp [D]; positivity - have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb - have hb0 : (0:ℝ) ≤ b := by positivity - have hbm : 0 ≤ (b:ℝ)-1 := by linarith - have hterm (j : ℕ) : - ((2*D-1)/D^2)*(j:ℝ)-((lam^2*mu)/D^2)*((j:ℝ)*((j:ℝ)-1)) ≤ - (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu)) := by - by_cases hj : j=0 - · subst j; norm_num - · have hjr : (1:ℝ) ≤ j := by exact_mod_cast (show 1≤j by omega) - have hd : 0<1+((j:ℝ)-1)*(lam^2*mu) := by positivity - have hh := reciprocal_tangent (show (0:ℝ)≤j by positivity) hd hD - convert hh using 1 - ring - have hs := Finset.sum_le_sum (s := Finset.range b) (fun j _ => hterm j) - rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, - sum_range_real, sum_range_factorial_two] at hs - have haux : (b:ℝ)*(b-1)/(2*D) ≤ - ((2*D-1)/D^2)*((b:ℝ)*(b-1)/2)-((lam^2*mu)/D^2)*((b:ℝ)*(b-1)*(b-2)/3) := by - apply (le_sub_iff_add_le).mpr - field_simp [ne_of_gt hD] - dsimp only [D] - have hp : 0 ≤ mu*((b:ℝ)-1)*lam^2 := by positivity - nlinarith only [hp, congrArg (fun x => mu*((b:ℝ)-1)*x) hc] - have hh := mul_le_mul_of_nonneg_left (haux.trans hs) (show (0:ℝ) ≤ lam^4 by positivity) - have he : lam^4*((b:ℝ)*(b-1)/(2*D)) = (1-lam^2)/(2*D) := by - have ht : lam^4*((b:ℝ)*(b-1)) = 1-lam^2 := by - calc - _ = ((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2) := by ring - _ = _ := by rw [hc]; ring - calc - _ = (lam^4*((b:ℝ)*(b-1)))/(2*D) := by ring - _ = _ := by rw [ht] - change lam^4*((b:ℝ)*(b-1)/(2*D)) ≤ lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu))) at hh - rwa [he] at hh - -lemma regular_sqrt_sum_sq (b : ℕ) (hb : 1 ≤ b) : - (∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2 ≤ (b:ℝ)*(b-1)^2/2 := by - let f : ℕ → ℝ := fun j => if j=0 then 0 else 1 - let g : ℕ → ℝ := fun j => Real.sqrt (j:ℝ) - have hf : (∑ j ∈ Finset.range b, (f j)^2) = (b:ℝ)-1 := by - have hzero : 0 ∈ Finset.range b := Finset.mem_range.mpr (by omega) - have he (j : ℕ) : (f j)^2 = 1-(if j=0 then (1:ℝ) else 0) := by dsimp only [f]; split_ifs <;> norm_num - simp only [he, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul, - Finset.sum_ite_eq', hzero, ite_true, mul_one] - have hg : (∑ j ∈ Finset.range b, (g j)^2) = (b:ℝ)*(b-1)/2 := by - simp only [g, Real.sq_sqrt (Nat.cast_nonneg _), sum_range_real] - have hfg : (∑ j ∈ Finset.range b, f j*g j) = ∑ j ∈ Finset.range b, Real.sqrt (j:ℝ) := by - apply Finset.sum_congr rfl - intro j _ - by_cases hj : j=0 <;> simp [f,g,hj] - have hh := Finset.sum_mul_sq_le_sq_mul_sq (Finset.range b) f g - rw [hf,hg,hfg] at hh - nlinarith only [hh] - -lemma regular_sqrt_sum (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (hl : 0 ≤ lam) (hc : (b:ℝ)*lam^2=1) : - lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ)) ≤ (1-lam^2)*lam/Real.sqrt 2 := by - have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb - have ha : 0 ≤ 1-lam^2 := by nlinarith [sq_nonneg lam] - have hs := regular_sqrt_sum_sq b (by omega) - have hp := mul_le_mul_of_nonneg_left hs (show 0 ≤ 2*lam^8 by positivity) - have he : 2*lam^8*((b:ℝ)*(b-1)^2/2) = ((1-lam^2)*lam)^2 := by - calc - _ = lam^2*((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2)^2 := by ring - _ = _ := by rw [hc]; ring - rw [he] at hp - have hs0 : 0 ≤ ∑ j ∈ Finset.range b, Real.sqrt (j:ℝ) := Finset.sum_nonneg (fun j _ => Real.sqrt_nonneg _) - have hr : 0 < Real.sqrt 2 := by positivity - apply (le_div_iff₀ hr).mpr - have hroot : (Real.sqrt 2)^2=2 := Real.sq_sqrt (by norm_num) - have hx : 0 ≤ lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))*Real.sqrt 2 := by positivity - have hy : 0 ≤ (1-lam^2)*lam := mul_nonneg ha hl - apply (sq_le_sq₀ hx hy).mp - have hsq : (lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))*Real.sqrt 2)^2 = - 2*lam^8*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2 := by - calc - _ = lam^8*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2*(Real.sqrt 2)^2 := by ring - _ = _ := by rw [hroot]; ring - rwa [hsq] - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma regular_correlation_bound (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 ≤ lam) (hl1 : lam < 1) (hc : (b:ℝ)*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) - (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : - (1-lam^2)*(3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- - lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2) ≤ 3*correlationEntropy lam h Q b := by - have hm := posteriorMu_nonneg Q - have hn := posteriorNu_nonneg Q - have hsum := Finset.sum_le_sum (s := Finset.range b) (fun j hj => - regular_increment_bound b lam h hl0 hl1 Q hQ hs he j (Finset.mem_range.mp hj)) - rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, - ← correlationEntropy_sum lam h hl0 hl1 Q hQ.1 b] at hsum - have hpos := mul_le_mul_of_nonneg_left (regular_rational_sum b hb lam (posteriorMu Q) hc hm) - (show 0 ≤ 3*(posteriorMu Q)^2 by positivity) - have hneg := mul_le_mul_of_nonneg_left (regular_sqrt_sum b hb lam hl0 hc) - (mul_nonneg hm hn) - calc - _ = 3*(posteriorMu Q)^2*((1-lam^2)/(2*(1+2*posteriorMu Q/3)))- - (posteriorMu Q*posteriorNu Q)*((1-lam^2)*lam/Real.sqrt 2) := by ring - _ ≤ 3*(posteriorMu Q)^2*(lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q))))- - (posteriorMu Q*posteriorNu Q)*(lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))) := sub_le_sub hpos hneg - _ = _ := by ring - _ ≤ _ := hsum - -lemma entropyF_sourceF (m : Message) : entropyF m = Radial.sourceF (fun i => m i) := by - simp only [entropyF, entropyI, entropyJ, entropyB, Radial.sourceF, mLog, mCenteredLog, - Radial.avg_expand] - ring - -lemma continuous_entropyF_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : - Continuous (fun m => entropyF (edgeMessage lam h m)) := - (((continuous_entropyI_edge lam h hl0 hl1).const_mul 3).sub - ((continuous_entropyJ_edge lam h hl0 hl1).const_mul 2)).add - ((continuous_entropyB_edge lam h hl0 hl1).const_mul (4/5:ℝ)) - -lemma integral_entropyF_radial (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) - (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : - (1-lam^2)/2*posteriorNu Q ≤ (∫ m, entropyF m ∂(Q : Measure Message))- - lam⁻¹^2*(∫ m, entropyF (edgeMessage lam h m) ∂(Q : Measure Message)) := by - have hi := integrable_entropyF_fixedpoint offspring lam h hl0.le hl1 Q hQ hD2 - have hie := integrable_continuous_message Q (continuous_entropyF_edge lam h hl0.le hl1) - have hp := positive_fixedpoint offspring lam h hl0.le hl1 Q hQ - have hh := integral_mono_ae ((integrable_continuous_message Q (continuous_messageX.pow 2)).const_mul ((1-lam^2)/2)) - (show Integrable (fun m => entropyF m-lam⁻¹^2*entropyF (edgeMessage lam h m)) (Q : Measure Message) from hi.sub (hie.const_mul _)) - (hp.mono (fun m hm => by - have hh := Radial.radial_source (fun i => m i) (average_message m) hm lam hl0 hl1 - change (1-lam^2)/2*(messageX m)^2 ≤ entropyF m-lam⁻¹^2*entropyF (edgeMessage lam h m) - rw [entropyF_sourceF, entropyF_sourceF] - convert hh using 1 <;> simp only [edgeMessage, messageX, messageDeviation, Radial.momentX] - ring)) - rw [integral_const_mul, integral_sub hi (hie.const_mul _), integral_const_mul] at hh - exact hh - -lemma regular_entropy_bound (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hl1 : lam < 1) (hc : (b:ℝ)*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) - (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : - posteriorNu Q/2+3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- - lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ - (8/5:ℝ)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by - have hD2 : HasMean (PMF.pure b) (fun n : ℕ => (n:ℝ)^2) := hasMean_pure _ _ - have hD := hasMean_of_square hD2 - have hid := entropy_identity (PMF.pure b) lam h hl0.le hl1 Q hQ hs hD2 - have hrad := integral_entropyF_radial (PMF.pure b) lam h hl0 hl1 Q hQ hD2 - have hcorr := regular_correlation_bound b hb lam h hl0.le hl1 hc Q hQ hs he - have hJ := additive_entropyJ (PMF.pure b) lam h hl0.le hl1 Q hQ hs hD - simp only [mean_pure] at hid hJ - have hl : lam⁻¹^2 = (b:ℝ) := by field_simp; nlinarith only [hc] - rw [hl] at hrad - have hJe : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = - lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by - nlinarith only [hJ, congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] - rw [hJe] at hid - have hfac : (b:ℝ)*(b-1)*lam^4=1-lam^2 := by - calc - _ = ((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2) := by ring - _ = _ := by rw [hc]; ring - have hid' : (1-lam^2)/2*posteriorNu Q+3*correlationEntropy lam h Q b ≤ - (8/5:ℝ)*(1-lam^2)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by - nlinarith only [hid, hrad, congrArg (fun x : ℝ => (8/5:ℝ)*x*(∫ m, entropyJ m ∂(Q : Measure Message))^2) hfac] - have ha : 0 < 1-lam^2 := by nlinarith - apply (mul_le_mul_iff_left₀ ha).mp - nlinarith only [hid', hcorr] - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma critical_moment_nu_bound (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) - (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) - (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) - (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2=1) : - ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*posteriorNu Q ≤ posteriorMu Q := by - have hh := positive_moment_estimates offspring lam h hl0 hl1 Q hQ hs hD hc - dsimp only at hh - have hnu := posteriorNu_nonneg Q - have hmu := posteriorMu_nonneg Q - by_cases hzero : posteriorNu Q=0 - · simp only [hzero,mul_zero] - exact hmu - · have hnupos : 0 < posteriorNu Q := lt_of_le_of_ne hnu (Ne.symm hzero) - have he : 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q := by positivity - have hsq := (Real.le_sqrt he (mul_nonneg hmu hnu)).mp (hh.2.2.1.trans hh.2.2.2) - apply (mul_le_mul_iff_left₀ hnupos).mp - nlinarith only [hsq] - -lemma regular_positive_critical_uniform (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) - (hl0 : 0 < lam) (hc : (b:ℝ)*lam^2=1) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) - (hs : SpinSymmetric Q) : posteriorMu Q = 0 := by - have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb - have hlhalf : lam^2 ≤ 1/2 := by nlinarith [sq_nonneg lam] - have hl1 : lam < 1 := by nlinarith - have hD : HasMean (PMF.pure b) (fun n : ℕ => (n:ℝ)) := hasMean_pure _ _ - have hc' : mean (PMF.pure b) (fun n : ℕ => (n:ℝ))*lam^2=1 := by simpa only [mean_pure] using hc - have hh := positive_moment_estimates (PMF.pure b) lam h hl0 hl1 Q hQ hs hD hc' - dsimp only at hh - have hm := posteriorMu_nonneg Q - have hn := posteriorNu_nonneg Q - have he : 0 ≤ posteriorEta Q := (show 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q by positivity).trans hh.2.2.1 - have hent := regular_entropy_bound b hb lam h hl0 hl1 hc Q hQ hs he - have hcnu := critical_moment_nu_bound (PMF.pure b) lam h hl0 hl1 Q hQ hs hD hc' - by_contra hzero - have hmpos : 0 < posteriorMu Q := lt_of_le_of_ne hm (Ne.symm hzero) - apply PositiveScalar.moment_scalar_contradiction lam (posteriorMu Q) (posteriorNu Q) - (∫ m, entropyJ m ∂(Q : Measure Message)) 1 hl0 hl1 hmpos hn (by norm_num) (by norm_num) - (by simpa only [one_mul] using posteriorMu_sq_le Q) hcnu hh.1 hh.2.1 - · nlinarith only [hent, mul_nonneg (sq_nonneg lam) hn] - · intro hhigher - linarith only [hhigher,hlhalf] - -lemma messageX_zero_tv {m : Message} (hm : messageX m=0) : messageTV m=0 := by - have hc : ∀ i : Spin, m i=1 := by - have h0 := sq_nonneg (m 0-1) - have h1 := sq_nonneg (m 1-1) - have h2 := sq_nonneg (m 2-1) - simp only [messageX, Radial.momentX, Radial.avg_expand, messageDeviation] at hm - intro i - fin_cases i <;> (try change m 0=1) <;> (try change m 1=1) <;> (try change m 2=1) <;> nlinarith - simp [messageTV,hc] - -lemma integral_tv_zero_of_mu_zero (Q : ProbabilityMeasure Message) (hmu : posteriorMu Q=0) : - ∫ m, messageTV m ∂(Q : Measure Message) = 0 := by - have ha := (integral_eq_zero_iff_of_nonneg messageX_nonneg (integrable_continuous_message Q continuous_messageX)).mp hmu - calc - _ = ∫ _m : Message, (0:ℝ) ∂(Q : Measure Message) := integral_congr_ae (ha.mono (fun m hm => messageX_zero_tv hm)) - _ = 0 := integral_zero _ _ - -lemma observed_tendsto_zero_of_uniform_fixedpoints (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (hunif : ∀ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q → SpinSymmetric Q → posteriorMu Q=0) : - Tendsto (fun n => advantage (observedLaw offspring lam h n)) atTop (𝓝 0) := by - obtain ⟨Q,hQ,hs,φ,hφ,hlim⟩ := ordered_exists_symmetric_fixedpoint offspring lam h - have htv := integral_tv_zero_of_mu_zero Q (hunif Q hQ hs) - have hordered := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim - rw [htv] at hordered - obtain ⟨L,hL,_hL1,hactual⟩ := observedAdvantage_tendsto offspring lam h - have hle := le_of_tendsto_of_tendsto (hactual.comp hφ.tendsto_atTop) hordered - (Eventually.of_forall (fun n => orderedAdvantage_dominates offspring lam h (φ n))) - have heq : L=0 := le_antisymm hle hL - simpa only [heq] using hactual - - -theorem regular_positive_critical_nonreconstruction (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) - (h : Admissible lam) (hl0 : 0 < lam) (hc : (b:ℝ)*lam^2=1) : - Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by - exact observed_tendsto_zero_of_uniform_fixedpoints (PMF.pure b) lam h - (regular_positive_critical_uniform b hb lam h hl0 hc) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Projection +import OAI.Probability.ThreeState.ScalarBounds + +namespace OAI + +/-! Entropy bounds and non-reconstruction at the positive regular-tree threshold. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma regular_fixedpoint_degree_nu (b : ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) : + posteriorNu (degreePosterior lam h Q hQ.1 b) = posteriorNu Q := by + have hh := hQ.2 ⟨fun m => (messageX m)^2, continuous_messageX.pow 2⟩ + rw [mean_pure] at hh + change (∫ m, (messageX m)^2 ∂(Q : Measure Message)) = + ∫ m : Fin b → Message, normalizer lam h m*(messageX (combineMessage lam h m))^2 ∂(iidMeasure Q b : Measure (Fin b → Message)) at hh + change (∫ m, (messageX m)^2 ∂degreeOutput lam h Q b) = _ + rw [integral_degreeOutput lam h Q b (fun m => (messageX m)^2) (continuous_messageX.pow 2).measurable] + exact hh.symm + +lemma partial_nu_le_regular (b : ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) {j : ℕ} (hj : j ≤ b) : + posteriorNu (degreePosterior lam h Q hQ.1 j) ≤ posteriorNu Q := by + rw [← regular_fixedpoint_degree_nu b lam h Q hQ] + exact degree_nu_monotone lam h hl0 hl1 Q hQ.1 hj + +lemma correlationEntropy_sum (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (b : ℕ) : + correlationEntropy lam h Q b = + ∑ j ∈ Finset.range b, pairCorrelation lam h Q (degreePosterior lam h Q hQ j) := by + induction b with + | zero => simp [correlationEntropy_zero] + | succ b ih => + rw [Finset.sum_range_succ, ← ih] + have hh := correlationEntropy_succ lam h hl0 hl1 Q hQ b + change correlationEntropy lam h Q (b+1) = correlationEntropy lam h Q b + + pairCorrelation lam h Q (degreePosterior lam h Q hQ b) at hh + exact hh + +lemma scalar_sqrt_projection_bound {j beta : ℝ} (hj : 1 ≤ j) (hb : 0 ≤ beta) : + Real.sqrt (j*beta/(1+(j-1)*beta)) ≤ Real.sqrt (j*beta) := by + apply Real.sqrt_le_sqrt + have hd : 1 ≤ 1+(j-1)*beta := by nlinarith + exact div_le_self (mul_nonneg (by linarith) hb) hd + +lemma regular_increment_bound (b : ℕ) (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) (hs : SpinSymmetric Q) + (he : 0 ≤ posteriorEta Q) (j : ℕ) (hj : j < b) : + 3*lam^4*(posteriorMu Q)^2*((j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q)))- + lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt j ≤ + 3*pairCorrelation lam h Q (degreePosterior lam h Q hQ.1 j) := by + by_cases hj0 : j=0 + · subst j + simp only [Nat.cast_zero, zero_div, mul_zero, Real.sqrt_zero, sub_zero] + exact mul_nonneg (by norm_num) (pairCorrelation_nonneg lam h hl0 hl1 Q _ hQ.1) + · have hj1 : 1 ≤ j := by omega + have hjr : (1:ℝ) ≤ j := by exact_mod_cast hj1 + have hm := posteriorMu_nonneg Q + have hn := posteriorNu_nonneg Q + let L := (j:ℝ)*(lam^2*posteriorMu Q)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q)) + have hb : 0 ≤ lam^2*posteriorMu Q := mul_nonneg (sq_nonneg _) hm + have hL : 0 ≤ L := div_nonneg (mul_nonneg (by positivity) hb) (by positivity) + have hh := pairCorrelation_truncated lam h hl0 hl1 Q (degreePosterior lam h Q hQ.1 j) hQ.1 hs he + (partial_nu_le_regular b lam h hl0 hl1 Q hQ (Nat.le_of_lt hj)) hL + (degree_projection lam h hl0 hl1 Q hQ.1 hs j hj1) + have hsqrt : Real.sqrt L ≤ lam*Real.sqrt (posteriorMu Q)*Real.sqrt j := by + have hh := scalar_sqrt_projection_bound hjr hb + rw [Real.sqrt_mul (show (0:ℝ)≤j by positivity), Real.sqrt_mul (sq_nonneg lam), Real.sqrt_sq_eq_abs, abs_of_nonneg hl0] at hh + dsimp only [L] + nlinarith only [hh] + have hmul := mul_le_mul_of_nonneg_left hsqrt (show 0 ≤ lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q by positivity) + have hsq := Real.sq_sqrt hm + have hlead : 3*lam^2*posteriorMu Q*L = + 3*lam^4*(posteriorMu Q)^2*((j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q))) := by dsimp only [L]; ring + rw [hlead] at hh + have hloss : lam^3*Real.sqrt (posteriorMu Q)*posteriorNu Q*(lam*Real.sqrt (posteriorMu Q)*Real.sqrt j) = + lam^4*posteriorMu Q*posteriorNu Q*Real.sqrt j := by + calc + _ = lam^4*(Real.sqrt (posteriorMu Q))^2*posteriorNu Q*Real.sqrt j := by ring + _ = _ := by rw [hsq] + rw [hloss] at hmul + linarith only [hh, hmul] + +end ThreeState + +namespace ThreeState +open scoped BigOperators + +lemma sum_range_real (b : ℕ) : (∑ j ∈ Finset.range b, (j:ℝ)) = (b:ℝ)*(b-1)/2 := by + induction b with + | zero => norm_num + | succ b ih => rw [Finset.sum_range_succ, ih]; push_cast; ring + +lemma sum_range_factorial_two (b : ℕ) : + (∑ j ∈ Finset.range b, (j:ℝ)*((j:ℝ)-1)) = (b:ℝ)*(b-1)*(b-2)/3 := by + induction b with + | zero => norm_num + | succ b ih => rw [Finset.sum_range_succ, ih]; push_cast; ring + +lemma reciprocal_tangent {x y D : ℝ} (hx : 0 ≤ x) (hy : 0 < y) (hD : 0 < D) : + x*(2*D-y)/D^2 ≤ x/y := by + apply (div_le_div_iff₀ (sq_pos_of_pos hD) hy).mpr + nlinarith only [mul_nonneg hx (sq_nonneg (D-y))] + +lemma regular_rational_sum (b : ℕ) (hb : 2 ≤ b) (lam mu : ℝ) (hc : (b:ℝ)*lam^2=1) (hm : 0 ≤ mu) : + (1-lam^2)/(2*(1+2*mu/3)) ≤ + lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu))) := by + let D := 1+2*mu/3 + have hD : 0 < D := by dsimp [D]; positivity + have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb + have hb0 : (0:ℝ) ≤ b := by positivity + have hbm : 0 ≤ (b:ℝ)-1 := by linarith + have hterm (j : ℕ) : + ((2*D-1)/D^2)*(j:ℝ)-((lam^2*mu)/D^2)*((j:ℝ)*((j:ℝ)-1)) ≤ + (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu)) := by + by_cases hj : j=0 + · subst j; norm_num + · have hjr : (1:ℝ) ≤ j := by exact_mod_cast (show 1≤j by omega) + have hd : 0<1+((j:ℝ)-1)*(lam^2*mu) := by positivity + have hh := reciprocal_tangent (show (0:ℝ)≤j by positivity) hd hD + convert hh using 1 + ring + have hs := Finset.sum_le_sum (s := Finset.range b) (fun j _ => hterm j) + rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, + sum_range_real, sum_range_factorial_two] at hs + have haux : (b:ℝ)*(b-1)/(2*D) ≤ + ((2*D-1)/D^2)*((b:ℝ)*(b-1)/2)-((lam^2*mu)/D^2)*((b:ℝ)*(b-1)*(b-2)/3) := by + apply (le_sub_iff_add_le).mpr + field_simp [ne_of_gt hD] + dsimp only [D] + have hp : 0 ≤ mu*((b:ℝ)-1)*lam^2 := by positivity + nlinarith only [hp, congrArg (fun x => mu*((b:ℝ)-1)*x) hc] + have hh := mul_le_mul_of_nonneg_left (haux.trans hs) (show (0:ℝ) ≤ lam^4 by positivity) + have he : lam^4*((b:ℝ)*(b-1)/(2*D)) = (1-lam^2)/(2*D) := by + have ht : lam^4*((b:ℝ)*(b-1)) = 1-lam^2 := by + calc + _ = ((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2) := by ring + _ = _ := by rw [hc]; ring + calc + _ = (lam^4*((b:ℝ)*(b-1)))/(2*D) := by ring + _ = _ := by rw [ht] + change lam^4*((b:ℝ)*(b-1)/(2*D)) ≤ lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*mu))) at hh + rwa [he] at hh + +lemma regular_sqrt_sum_sq (b : ℕ) (hb : 1 ≤ b) : + (∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2 ≤ (b:ℝ)*(b-1)^2/2 := by + let f : ℕ → ℝ := fun j => if j=0 then 0 else 1 + let g : ℕ → ℝ := fun j => Real.sqrt (j:ℝ) + have hf : (∑ j ∈ Finset.range b, (f j)^2) = (b:ℝ)-1 := by + have hzero : 0 ∈ Finset.range b := Finset.mem_range.mpr (by omega) + have he (j : ℕ) : (f j)^2 = 1-(if j=0 then (1:ℝ) else 0) := by dsimp only [f]; split_ifs <;> norm_num + simp only [he, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul, + Finset.sum_ite_eq', hzero, ite_true, mul_one] + have hg : (∑ j ∈ Finset.range b, (g j)^2) = (b:ℝ)*(b-1)/2 := by + simp only [g, Real.sq_sqrt (Nat.cast_nonneg _), sum_range_real] + have hfg : (∑ j ∈ Finset.range b, f j*g j) = ∑ j ∈ Finset.range b, Real.sqrt (j:ℝ) := by + apply Finset.sum_congr rfl + intro j _ + by_cases hj : j=0 <;> simp [f,g,hj] + have hh := Finset.sum_mul_sq_le_sq_mul_sq (Finset.range b) f g + rw [hf,hg,hfg] at hh + nlinarith only [hh] + +lemma regular_sqrt_sum (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (hl : 0 ≤ lam) (hc : (b:ℝ)*lam^2=1) : + lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ)) ≤ (1-lam^2)*lam/Real.sqrt 2 := by + have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb + have ha : 0 ≤ 1-lam^2 := by nlinarith [sq_nonneg lam] + have hs := regular_sqrt_sum_sq b (by omega) + have hp := mul_le_mul_of_nonneg_left hs (show 0 ≤ 2*lam^8 by positivity) + have he : 2*lam^8*((b:ℝ)*(b-1)^2/2) = ((1-lam^2)*lam)^2 := by + calc + _ = lam^2*((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2)^2 := by ring + _ = _ := by rw [hc]; ring + rw [he] at hp + have hs0 : 0 ≤ ∑ j ∈ Finset.range b, Real.sqrt (j:ℝ) := Finset.sum_nonneg (fun j _ => Real.sqrt_nonneg _) + have hr : 0 < Real.sqrt 2 := by positivity + apply (le_div_iff₀ hr).mpr + have hroot : (Real.sqrt 2)^2=2 := Real.sq_sqrt (by norm_num) + have hx : 0 ≤ lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))*Real.sqrt 2 := by positivity + have hy : 0 ≤ (1-lam^2)*lam := mul_nonneg ha hl + apply (sq_le_sq₀ hx hy).mp + have hsq : (lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))*Real.sqrt 2)^2 = + 2*lam^8*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2 := by + calc + _ = lam^8*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))^2*(Real.sqrt 2)^2 := by ring + _ = _ := by rw [hroot]; ring + rwa [hsq] + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma regular_correlation_bound (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 ≤ lam) (hl1 : lam < 1) (hc : (b:ℝ)*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) + (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : + (1-lam^2)*(3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- + lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2) ≤ 3*correlationEntropy lam h Q b := by + have hm := posteriorMu_nonneg Q + have hn := posteriorNu_nonneg Q + have hsum := Finset.sum_le_sum (s := Finset.range b) (fun j hj => + regular_increment_bound b lam h hl0 hl1 Q hQ hs he j (Finset.mem_range.mp hj)) + rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum, + ← correlationEntropy_sum lam h hl0 hl1 Q hQ.1 b] at hsum + have hpos := mul_le_mul_of_nonneg_left (regular_rational_sum b hb lam (posteriorMu Q) hc hm) + (show 0 ≤ 3*(posteriorMu Q)^2 by positivity) + have hneg := mul_le_mul_of_nonneg_left (regular_sqrt_sum b hb lam hl0 hc) + (mul_nonneg hm hn) + calc + _ = 3*(posteriorMu Q)^2*((1-lam^2)/(2*(1+2*posteriorMu Q/3)))- + (posteriorMu Q*posteriorNu Q)*((1-lam^2)*lam/Real.sqrt 2) := by ring + _ ≤ 3*(posteriorMu Q)^2*(lam^4*(∑ j ∈ Finset.range b, (j:ℝ)/(1+((j:ℝ)-1)*(lam^2*posteriorMu Q))))- + (posteriorMu Q*posteriorNu Q)*(lam^4*(∑ j ∈ Finset.range b, Real.sqrt (j:ℝ))) := sub_le_sub hpos hneg + _ = _ := by ring + _ ≤ _ := hsum + +lemma entropyF_sourceF (m : Message) : entropyF m = Radial.sourceF (fun i => m i) := by + simp only [entropyF, entropyI, entropyJ, entropyB, Radial.sourceF, mLog, mCenteredLog, + Radial.avg_expand] + ring + +lemma continuous_entropyF_edge (lam : ℝ) (h : Admissible lam) (hl0 : 0 ≤ lam) (hl1 : lam < 1) : + Continuous (fun m => entropyF (edgeMessage lam h m)) := + (((continuous_entropyI_edge lam h hl0 hl1).const_mul 3).sub + ((continuous_entropyJ_edge lam h hl0 hl1).const_mul 2)).add + ((continuous_entropyB_edge lam h hl0 hl1).const_mul (4/5:ℝ)) + +lemma integral_entropyF_radial (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) + (hD2 : HasMean offspring (fun n : ℕ => (n:ℝ)^2)) : + (1-lam^2)/2*posteriorNu Q ≤ (∫ m, entropyF m ∂(Q : Measure Message))- + lam⁻¹^2*(∫ m, entropyF (edgeMessage lam h m) ∂(Q : Measure Message)) := by + have hi := integrable_entropyF_fixedpoint offspring lam h hl0.le hl1 Q hQ hD2 + have hie := integrable_continuous_message Q (continuous_entropyF_edge lam h hl0.le hl1) + have hp := positive_fixedpoint offspring lam h hl0.le hl1 Q hQ + have hh := integral_mono_ae ((integrable_continuous_message Q (continuous_messageX.pow 2)).const_mul ((1-lam^2)/2)) + (show Integrable (fun m => entropyF m-lam⁻¹^2*entropyF (edgeMessage lam h m)) (Q : Measure Message) from hi.sub (hie.const_mul _)) + (hp.mono (fun m hm => by + have hh := Radial.radial_source (fun i => m i) (average_message m) hm lam hl0 hl1 + change (1-lam^2)/2*(messageX m)^2 ≤ entropyF m-lam⁻¹^2*entropyF (edgeMessage lam h m) + rw [entropyF_sourceF, entropyF_sourceF] + convert hh using 1 <;> simp only [edgeMessage, messageX, messageDeviation, Radial.momentX] + ring)) + rw [integral_const_mul, integral_sub hi (hie.const_mul _), integral_const_mul] at hh + exact hh + +lemma regular_entropy_bound (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hl1 : lam < 1) (hc : (b:ℝ)*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) + (hs : SpinSymmetric Q) (he : 0 ≤ posteriorEta Q) : + posteriorNu Q/2+3*(posteriorMu Q)^2/(2*(1+2*posteriorMu Q/3))- + lam*posteriorMu Q*posteriorNu Q/Real.sqrt 2 ≤ + (8/5:ℝ)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by + have hD2 : HasMean (PMF.pure b) (fun n : ℕ => (n:ℝ)^2) := hasMean_pure _ _ + have hD := hasMean_of_square hD2 + have hid := entropy_identity (PMF.pure b) lam h hl0.le hl1 Q hQ hs hD2 + have hrad := integral_entropyF_radial (PMF.pure b) lam h hl0 hl1 Q hQ hD2 + have hcorr := regular_correlation_bound b hb lam h hl0.le hl1 hc Q hQ hs he + have hJ := additive_entropyJ (PMF.pure b) lam h hl0.le hl1 Q hQ hs hD + simp only [mean_pure] at hid hJ + have hl : lam⁻¹^2 = (b:ℝ) := by field_simp; nlinarith only [hc] + rw [hl] at hrad + have hJe : (∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message)) = + lam^2*(∫ m, entropyJ m ∂(Q : Measure Message)) := by + nlinarith only [hJ, congrArg (fun x : ℝ => x*(∫ m, entropyJ (edgeMessage lam h m) ∂(Q : Measure Message))) hc] + rw [hJe] at hid + have hfac : (b:ℝ)*(b-1)*lam^4=1-lam^2 := by + calc + _ = ((b:ℝ)*lam^2)*(((b:ℝ)*lam^2)-lam^2) := by ring + _ = _ := by rw [hc]; ring + have hid' : (1-lam^2)/2*posteriorNu Q+3*correlationEntropy lam h Q b ≤ + (8/5:ℝ)*(1-lam^2)*(∫ m, entropyJ m ∂(Q : Measure Message))^2 := by + nlinarith only [hid, hrad, congrArg (fun x : ℝ => (8/5:ℝ)*x*(∫ m, entropyJ m ∂(Q : Measure Message))^2) hfac] + have ha : 0 < 1-lam^2 := by nlinarith + apply (mul_le_mul_iff_left₀ ha).mp + nlinarith only [hid', hcorr] + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma critical_moment_nu_bound (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hl1 : lam < 1) (Q : ProbabilityMeasure Message) + (hQ : IsPosteriorFixedPoint offspring lam h Q) (hs : SpinSymmetric Q) + (hD : HasMean offspring (fun n : ℕ => (n:ℝ))) + (hc : mean offspring (fun n : ℕ => (n:ℝ))*lam^2=1) : + ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*posteriorNu Q ≤ posteriorMu Q := by + have hh := positive_moment_estimates offspring lam h hl0 hl1 Q hQ hs hD hc + dsimp only at hh + have hnu := posteriorNu_nonneg Q + have hmu := posteriorMu_nonneg Q + by_cases hzero : posteriorNu Q=0 + · simp only [hzero,mul_zero] + exact hmu + · have hnupos : 0 < posteriorNu Q := lt_of_le_of_ne hnu (Ne.symm hzero) + have he : 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q := by positivity + have hsq := (Real.le_sqrt he (mul_nonneg hmu hnu)).mp (hh.2.2.1.trans hh.2.2.2) + apply (mul_le_mul_iff_left₀ hnupos).mp + nlinarith only [hsq] + +lemma regular_positive_critical_uniform (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) + (hl0 : 0 < lam) (hc : (b:ℝ)*lam^2=1) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint (PMF.pure b) lam h Q) + (hs : SpinSymmetric Q) : posteriorMu Q = 0 := by + have hbr : (2:ℝ) ≤ b := by exact_mod_cast hb + have hlhalf : lam^2 ≤ 1/2 := by nlinarith [sq_nonneg lam] + have hl1 : lam < 1 := by nlinarith + have hD : HasMean (PMF.pure b) (fun n : ℕ => (n:ℝ)) := hasMean_pure _ _ + have hc' : mean (PMF.pure b) (fun n : ℕ => (n:ℝ))*lam^2=1 := by simpa only [mean_pure] using hc + have hh := positive_moment_estimates (PMF.pure b) lam h hl0 hl1 Q hQ hs hD hc' + dsimp only at hh + have hm := posteriorMu_nonneg Q + have hn := posteriorNu_nonneg Q + have he : 0 ≤ posteriorEta Q := (show 0 ≤ ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))*posteriorNu Q by positivity).trans hh.2.2.1 + have hent := regular_entropy_bound b hb lam h hl0 hl1 hc Q hQ hs he + have hcnu := critical_moment_nu_bound (PMF.pure b) lam h hl0 hl1 Q hQ hs hD hc' + by_contra hzero + have hmpos : 0 < posteriorMu Q := lt_of_le_of_ne hm (Ne.symm hzero) + apply PositiveScalar.moment_scalar_contradiction lam (posteriorMu Q) (posteriorNu Q) + (∫ m, entropyJ m ∂(Q : Measure Message)) 1 hl0 hl1 hmpos hn (by norm_num) (by norm_num) + (by simpa only [one_mul] using posteriorMu_sq_le Q) hcnu hh.1 hh.2.1 + · nlinarith only [hent, mul_nonneg (sq_nonneg lam) hn] + · intro hhigher + linarith only [hhigher,hlhalf] + +lemma messageX_zero_tv {m : Message} (hm : messageX m=0) : messageTV m=0 := by + have hc : ∀ i : Spin, m i=1 := by + have h0 := sq_nonneg (m 0-1) + have h1 := sq_nonneg (m 1-1) + have h2 := sq_nonneg (m 2-1) + simp only [messageX, Radial.momentX, Radial.avg_expand, messageDeviation] at hm + intro i + fin_cases i <;> (try change m 0=1) <;> (try change m 1=1) <;> (try change m 2=1) <;> nlinarith + simp [messageTV,hc] + +lemma integral_tv_zero_of_mu_zero (Q : ProbabilityMeasure Message) (hmu : posteriorMu Q=0) : + ∫ m, messageTV m ∂(Q : Measure Message) = 0 := by + have ha := (integral_eq_zero_iff_of_nonneg messageX_nonneg (integrable_continuous_message Q continuous_messageX)).mp hmu + calc + _ = ∫ _m : Message, (0:ℝ) ∂(Q : Measure Message) := integral_congr_ae (ha.mono (fun m hm => messageX_zero_tv hm)) + _ = 0 := integral_zero _ _ + +lemma observed_tendsto_zero_of_uniform_fixedpoints (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (hunif : ∀ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q → SpinSymmetric Q → posteriorMu Q=0) : + Tendsto (fun n => advantage (observedLaw offspring lam h n)) atTop (𝓝 0) := by + obtain ⟨Q,hQ,hs,φ,hφ,hlim⟩ := ordered_exists_symmetric_fixedpoint offspring lam h + have htv := integral_tv_zero_of_mu_zero Q (hunif Q hQ hs) + have hordered := advantage_tendsto_of_likelihood (fun n => orderedLaw offspring lam h (φ n)) hlim + rw [htv] at hordered + obtain ⟨L,hL,_hL1,hactual⟩ := observedAdvantage_tendsto offspring lam h + have hle := le_of_tendsto_of_tendsto (hactual.comp hφ.tendsto_atTop) hordered + (Eventually.of_forall (fun n => orderedAdvantage_dominates offspring lam h (φ n))) + have heq : L=0 := le_antisymm hle hL + simpa only [heq] using hactual + + +theorem regular_positive_critical_nonreconstruction (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) + (h : Admissible lam) (hl0 : 0 < lam) (hc : (b:ℝ)*lam^2=1) : + Tendsto (regularAdvantage b lam h) atTop (𝓝 0) := by + exact observed_tendsto_zero_of_uniform_fixedpoints (PMF.pure b) lam h + (regular_positive_critical_uniform b hb lam h hl0 hc) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Resolvents.lean b/lean/OAI/Probability/ThreeState/Resolvents.lean index 0ce424a9e5711f65388269d6f87ff8419576fd12..1f6e30eb047857c0bc987aeed6612cc8be5486d5 100644 --- a/lean/OAI/Probability/ThreeState/Resolvents.lean +++ b/lean/OAI/Probability/ThreeState/Resolvents.lean @@ -1,286 +1,286 @@ -import Mathlib -import OAI.Probability.ThreeState.RadialMoments - -namespace OAI - -/-! Fourth-moment resolvents and their lower bounds. -/ - -namespace ThreeState.Radial -open MeasureTheory - -noncomputable def fourthResolvent (v : Fin 3 → ℝ) (t : ℝ) : ℝ := avg (fun i => (v i)^4/(1+t*v i)) -noncomputable def doubleFourthResolvent (v : Fin 3 → ℝ) (lam t : ℝ) : ℝ := - avg (fun i => (v i)^4/((1+t*v i)*(1+lam*t*v i))) - -lemma fourth_moment (v : Fin 3 → ℝ) (hv : avg v = 0) : avg (fun i => (v i)^4) = 6*(momentX v)^2 := by - simp only [momentX, avg_expand, zero_sum_elim v hv] - ring - -lemma fourthResolvent_eq (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : - fourthResolvent v t = (6*(momentX v)^2-10*t*momentX v*momentY v+4*t^2*(momentY v)^2)/denom v t := by - have h0 := ne_of_gt (message_segment_pos v hp t ht0 ht1 0) - have h1 := ne_of_gt (message_segment_pos v hp t ht0 ht1 1) - have h2 := ne_of_gt (message_segment_pos v hp t ht0 ht1 2) - have h0c : 1+v 0*t ≠ 0 := by simpa [mul_comm] using h0 - have h1c : 1+v 1*t ≠ 0 := by simpa [mul_comm] using h1 - have h2c : 1+v 2*t ≠ 0 := by simpa [mul_comm] using h2 - rw [denom_product v hv t] - simp only [fourthResolvent, momentX, momentY, avg_expand] - field_simp [h0, h1, h2, h0c, h1c, h2c] - rw [zero_sum_elim v hv] - ring - -lemma h_polynomial_bound (z : ℝ) (hz0 : 0 ≤ z) (hz1 : z < 1) : - (1-3*z^2+2*z^3)*(4+(64/9:ℝ)*(z-1/2)^2) ≤ 6-10*z+4*z^2 := by - rcases hz0.eq_or_lt with hzero | _ - · rw [← hzero] - norm_num - have hE : 1+z-2*z^2 ≤ (9/8:ℝ) := by nlinarith [sq_nonneg (z-1/4)] - have hh : (1+z-2*z^2)*(4+(64/9:ℝ)*(z-1/2)^2) ≤ 6-4*z := by - nlinarith [mul_nonneg (show 0 ≤ (9/8:ℝ)-(1+z-2*z^2) by linarith) (sq_nonneg (z-1/2))] - have he := mul_le_mul_of_nonneg_left hh (show 0 ≤ 1-z by linarith) - nlinarith only [he] - -lemma momentY_sqrt_bound (v : Fin 3 → ℝ) (hv : avg v = 0) : - -(Real.sqrt (momentX v))^3 ≤ momentY v ∧ momentY v ≤ (Real.sqrt (momentX v))^3 := by - have h := discriminant_nonneg v hv - have hs := Real.sq_sqrt (momentX_nonneg v) - have he : (momentX v)^3 = ((Real.sqrt (momentX v))^3)^2 := by - calc - (momentX v)^3 = ((Real.sqrt (momentX v))^2)^3 := congrArg (fun x : ℝ => x^3) hs.symm - _ = _ := by ring - rw [he] at h - have hr : 0 ≤ (Real.sqrt (momentX v))^3 := by positivity - exact abs_le.mp ((sq_le_sq₀ (abs_nonneg (momentY v)) hr).mp (by simpa only [sq_abs] using h)) - -lemma fourthResolvent_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : - (momentX v)^2*(4+(64/9:ℝ)*(t*Real.sqrt (momentX v)-1/2)^2) ≤ fourthResolvent v t := by - let r := Real.sqrt (momentX v) - have hr0 : 0 ≤ r := Real.sqrt_nonneg _ - have hr2 : r^2 = momentX v := Real.sq_sqrt (momentX_nonneg v) - have hr1 : r < 1 := by nlinarith [momentX_lt_one v hv hp] - have hy := momentY_sqrt_bound v hv - change -r^3 ≤ momentY v ∧ momentY v ≤ r^3 at hy - have hz0 : 0 ≤ t*r := mul_nonneg ht0 hr0 - have hz1 : t*r < 1 := lt_of_le_of_lt (mul_le_of_le_one_left hr0 ht1) hr1 - have hn : (momentX v)^2*(6-10*(t*r)+4*(t*r)^2) ≤ - 6*(momentX v)^2-10*t*momentX v*momentY v+4*t^2*(momentY v)^2 := by - have htr : t*r ≤ 1 := hz1.le - have hfac : 0 ≤ 10*momentX v-4*t*(momentY v+r^3) := by - have h1 := mul_le_mul_of_nonneg_left hy.2 (by positivity : 0 ≤ 4*t) - have h2 := mul_le_mul_of_nonneg_left htr (by positivity : 0 ≤ 8*r^2) - nlinarith only [h1,h2, sq_nonneg r,hr2] - have hh := mul_nonneg (mul_nonneg ht0 (sub_nonneg.mpr hy.2)) hfac - rw [← hr2] at hh ⊢ - nlinarith only [hh] - have hd : denom v t ≤ 1-3*(t*r)^2+2*(t*r)^3 := by - have hh := mul_le_mul_of_nonneg_left hy.2 (by positivity : 0 ≤ 2*t^3) - dsimp only [denom] - rw [← hr2] - nlinarith only [hh] - have hg : 0 ≤ (momentX v)^2*(4+(64/9:ℝ)*(t*r-1/2)^2) := by positivity - have hh := mul_le_mul_of_nonneg_left hd hg - have hpoly := mul_le_mul_of_nonneg_left (h_polynomial_bound (t*r) hz0 hz1) (sq_nonneg (momentX v)) - rw [fourthResolvent_eq v hv hp t ht0 ht1] - apply (le_div_iff₀ (denom_pos v hv hp t ht0 ht1)).mpr - dsimp only [r] at hh hpoly - nlinarith only [hh,hpoly,hn] - -lemma fourthResolvent_four (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 4*(momentX v)^2 ≤ fourthResolvent v t := by - have hh := fourthResolvent_lower v hv hp t ht0 ht1 - nlinarith [mul_nonneg (sq_nonneg (momentX v)) (sq_nonneg (t*Real.sqrt (momentX v)-1/2))] - -end ThreeState.Radial -namespace ThreeState.Radial -open MeasureTheory - -lemma doubleFourthResolvent_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : - 2*fourthResolvent v t ≤ (2+lam)*doubleFourthResolvent v lam t := by - let c := 1+lam/2 - have hc : 0 < c := by dsimp [c]; linarith - have hlt0 : 0 ≤ lam*t := mul_nonneg hl0 ht0 - have hlt1 : lam*t ≤ 1 := (mul_le_of_le_one_left ht0 hl1).trans ht1 - have hi (i : Fin 3) : (2*c-1+lam)*(v i)^4/(1+t*v i)-lam*(v i)^4 ≤ - c^2*(v i)^4/((1+t*v i)*(1+lam*t*v i)) := by - have hd := message_segment_pos v hp t ht0 ht1 i - have he := message_segment_pos v hp (lam*t) hlt0 hlt1 i - have hdc : 1+v i*t ≠ 0 := by simpa [mul_comm] using (ne_of_gt hd) - have hec : 1+v i*t*lam ≠ 0 := by convert ne_of_gt he using 1; ring - have hh : 0 ≤ (v i)^4*(c-(1+lam*t*v i))^2/((1+t*v i)*(1+lam*t*v i)) := by positivity - have hid : c^2*(v i)^4/((1+t*v i)*(1+lam*t*v i))- - ((2*c-1+lam)*(v i)^4/(1+t*v i)-lam*(v i)^4) = - (v i)^4*(c-(1+lam*t*v i))^2/((1+t*v i)*(1+lam*t*v i)) := by - field_simp [ne_of_gt hd, ne_of_gt he, hdc, hec] - ring - linarith - have hh : (2*c-1+lam)*fourthResolvent v t-lam*(6*(momentX v)^2) ≤ - c^2*doubleFourthResolvent v lam t := by - rw [← fourth_moment v hv] - simp only [fourthResolvent, doubleFourthResolvent, avg_expand] - have hi0 := hi 0 - have hi1 := hi 1 - have hi2 := hi 2 - simp only [mul_div_assoc] at hi0 hi1 hi2 - nlinarith only [hi0,hi1,hi2] - have hw := fourthResolvent_four v hv hp t ht0 ht1 - have hnon := mul_nonneg hl0 (show 0 ≤ fourthResolvent v t-4*(momentX v)^2 by linarith) - have hcW : c*fourthResolvent v t ≤ c^2*doubleFourthResolvent v lam t := by - dsimp only [c] at * - nlinarith only [hh,hnon] - have hres : fourthResolvent v t ≤ c*doubleFourthResolvent v lam t := by - apply (mul_le_mul_iff_right₀ hc).mp - nlinarith only [hcW] - dsimp only [c] at hres - linarith - -lemma continuousOn_fourthResolvent (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) : - ContinuousOn (fourthResolvent v) (Set.Icc 0 1) := by - have hi (i : Fin 3) : ContinuousOn (fun t : ℝ => (v i)^4/(1+t*v i)) (Set.Icc 0 1) := - continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (message_segment_pos v hp t ht.1 ht.2 i)) - convert (((hi 0).add (hi 1)).add (hi 2)).div_const 3 using 1 - funext t - exact avg_expand _ - -lemma continuousOn_doubleFourthResolvent (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) - (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : - ContinuousOn (doubleFourthResolvent v lam) (Set.Icc 0 1) := by - have hi (i : Fin 3) : ContinuousOn (fun t : ℝ => (v i)^4/((1+t*v i)*(1+lam*t*v i))) (Set.Icc 0 1) := - continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (mul_pos - (message_segment_pos v hp t ht.1 ht.2 i) - (message_segment_pos v hp (lam*t) (mul_nonneg hl0 ht.1) ((mul_le_of_le_one_left ht.1 hl1).trans ht.2) i))) - convert (((hi 0).add (hi 1)).add (hi 2)).div_const 3 using 1 - funext t - exact avg_expand _ - -noncomputable def resolventA (v : Fin 3 → ℝ) : ℝ := ∫ t in (0:ℝ)..1, t^2*fourthResolvent v t -noncomputable def resolventQ (v : Fin 3 → ℝ) (lam : ℝ) : ℝ := (∫ t in (0:ℝ)..1, t^2*doubleFourthResolvent v lam t)/2 -noncomputable def functionJ (v : Fin 3 → ℝ) : ℝ := avg (fun i => v i*Real.log (1+v i))/2 - -lemma integral_h_lower (r : ℝ) : - (∫ t in (0:ℝ)..1, t^2*(4+(64/9:ℝ)*(t*r-1/2)^2)) = (37/27:ℝ)+(64/45:ℝ)*(r-5/8)^2 := by - let P := fun t : ℝ => (52/27:ℝ)*t^3-(16/9:ℝ)*r*t^4+(64/45:ℝ)*r^2*t^5 - have hd (t : ℝ) : HasDerivAt P (t^2*(4+(64/9:ℝ)*(t*r-1/2)^2)) t := by - dsimp only [P] - convert ((((hasDerivAt_id t).pow 3).const_mul (52/27:ℝ)).sub - (((hasDerivAt_id t).pow 4).const_mul ((16/9:ℝ)*r))).add - (((hasDerivAt_id t).pow 5).const_mul ((64/45:ℝ)*r^2)) using 1 <;> first | rfl | (norm_num; ring) - rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) - (Continuous.intervalIntegrable (by fun_prop) 0 1)] - dsimp [P] - ring - -lemma resolventA_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : - (37/27:ℝ)*(momentX v)^2 ≤ resolventA v := by - have hi : IntervalIntegrable (fun t : ℝ => (momentX v)^2*(t^2*(4+(64/9:ℝ)*(t*Real.sqrt (momentX v)-1/2)^2))) - volume 0 1 := Continuous.intervalIntegrable (by fun_prop) 0 1 - have hj : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent v t) volume 0 1 := - ((by fun_prop : ContinuousOn (fun t : ℝ => t^2) (Set.Icc 0 1)).mul (continuousOn_fourthResolvent v hp)).intervalIntegrable_of_Icc (by norm_num) - have hh := intervalIntegral.integral_mono_on (by norm_num : (0:ℝ) ≤ 1) hi hj (fun t ht => by - have he := mul_le_mul_of_nonneg_left (fourthResolvent_lower v hv hp t ht.1 ht.2) (sq_nonneg t) - nlinarith only [he]) - rw [intervalIntegral.integral_const_mul, integral_h_lower] at hh - dsimp only [resolventA] - nlinarith [mul_nonneg (sq_nonneg (momentX v)) (sq_nonneg (Real.sqrt (momentX v)-5/8))] - -lemma resolventQ_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) - (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : resolventA v/(2+lam) ≤ resolventQ v lam := by - have hi : IntervalIntegrable (fun t : ℝ => 2*(t^2*fourthResolvent v t)) volume 0 1 := - (continuousOn_const.mul ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent v hp))).intervalIntegrable_of_Icc (by norm_num) - have hj : IntervalIntegrable (fun t : ℝ => (2+lam)*(t^2*doubleFourthResolvent v lam t)) volume 0 1 := - (continuousOn_const.mul ((continuousOn_id.pow 2).mul (continuousOn_doubleFourthResolvent v hp lam hl0 hl1))).intervalIntegrable_of_Icc (by norm_num) - have hh := intervalIntegral.integral_mono_on (by norm_num : (0:ℝ) ≤ 1) hi hj (fun t ht => by - have he := mul_le_mul_of_nonneg_left (doubleFourthResolvent_lower v hv hp lam hl0 hl1 t ht.1 ht.2) (sq_nonneg t) - nlinarith only [he]) - rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at hh - apply (div_le_iff₀ (by linarith : 0 < 2+lam)).mpr - dsimp only [resolventQ, resolventA] - linarith - -lemma scalar_resolventA (a : ℝ) (ha : 0 < 1+a) : - (∫ t in (0:ℝ)..1, t^2*a^4/(1+t*a)) = a^3/2-a^2+a*Real.log (1+a) := by - have hp (t : ℝ) (ht : t ∈ Set.Icc (0:ℝ) 1) : 0 < 1+t*a := by - rcases eq_or_lt_of_le ht.1 with hz | hz - · rw [← hz]; norm_num - · nlinarith [mul_pos hz ha, ht.2] - have hc : ContinuousOn (fun t : ℝ => a/(1+t*a)) (Set.Icc 0 1) := - continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (hp t ht)) - have hi : IntervalIntegrable (fun t : ℝ => a/(1+t*a)) volume 0 1 := hc.intervalIntegrable_of_Icc (by norm_num : (0:ℝ) ≤ 1) - have he : (∫ t in (0:ℝ)..1, t^2*a^4/(1+t*a)) = - ∫ t in (0:ℝ)..1, (a^3*t-a^2)+a*(a/(1+t*a)) := by - apply intervalIntegral.integral_congr - intro t ht - have ht' : t ∈ Set.Icc (0:ℝ) 1 := by simpa using ht - field_simp [ne_of_gt (hp t ht')] - ring - rw [he, intervalIntegral.integral_add (Continuous.intervalIntegrable (by fun_prop) 0 1) (hi.const_mul a), - intervalIntegral.integral_sub (Continuous.intervalIntegrable (by fun_prop) 0 1) (intervalIntegrable_const), - intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul, integral_id, - intervalIntegral.integral_const, ← log_integral a ha] - norm_num - ring - -lemma resolventA_identity (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) : - resolventA v = 2*functionJ v-2*momentX v+momentY v := by - have he (t : ℝ) : t^2*fourthResolvent v t = avg (fun i => t^2*(v i)^4/(1+t*v i)) := by - simp only [fourthResolvent, avg_expand]; ring - dsimp only [resolventA] - simp_rw [he] - rw [integral_avg] - · simp_rw [scalar_resolventA _ (hp _)] - simp only [functionJ, momentX, momentY, avg_expand] - ring - · intro i - exact ((by fun_prop : ContinuousOn (fun t : ℝ => t^2*(v i)^4) (Set.Icc 0 1)).div - (by fun_prop) (fun t ht => ne_of_gt (message_segment_pos v hp t ht.1 ht.2 i))).intervalIntegrable_of_Icc (by norm_num) - -lemma resolvent_scaling (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) - (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : - lam^3*resolventA v-resolventA (fun i => lam*v i) = 2*lam^3*(1-lam)*resolventQ v lam := by - have hpe (i : Fin 3) : 0 < 1+lam*v i := message_segment_pos v hp lam hl0 hl1 i - have hvI : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent v t) volume 0 1 := - ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent v hp)).intervalIntegrable_of_Icc (by norm_num) - have heI : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent (fun i => lam*v i) t) volume 0 1 := - ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent _ hpe)).intervalIntegrable_of_Icc (by norm_num) - have he : (∫ t in (0:ℝ)..1, lam^3*(t^2*fourthResolvent v t)-t^2*fourthResolvent (fun i => lam*v i) t) = - ∫ t in (0:ℝ)..1, (lam^3*(1-lam))*(t^2*doubleFourthResolvent v lam t) := by - apply intervalIntegral.integral_congr - intro t ht - have ht' : t ∈ Set.Icc (0:ℝ) 1 := by simpa using ht - have hi (i : Fin 3) : lam^3*((v i)^4/(1+t*v i))-(lam*v i)^4/(1+t*(lam*v i)) = - lam^3*(1-lam)*((v i)^4/((1+t*v i)*(1+lam*t*v i))) := by - have ha := ne_of_gt (message_segment_pos v hp t ht'.1 ht'.2 i) - have hb := ne_of_gt (message_segment_pos _ hpe t ht'.1 ht'.2 i) - have ha' : 1+v i*t ≠ 0 := by simpa [mul_comm] using ha - have hb' : 1+v i*t*lam ≠ 0 := by convert hb using 1; ring - have hb'' : 1+lam*v i*t ≠ 0 := by convert hb using 1; ring - have hb''' : 1+lam*t*v i ≠ 0 := by convert hb using 1; ring - field_simp [ha, hb, ha', hb', hb'', hb'''] - ring - simp only [fourthResolvent, doubleFourthResolvent, avg_expand] - linear_combination t^2/3*(hi 0)+t^2/3*(hi 1)+t^2/3*(hi 2) - rw [intervalIntegral.integral_sub (hvI.const_mul _) heI, - intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at he - dsimp only [resolventA, resolventQ] - linarith only [he] - -lemma momentX_scale (v : Fin 3 → ℝ) (lam : ℝ) : momentX (fun i => lam*v i) = lam^2*momentX v := by - simp only [momentX, avg_expand]; ring - -lemma momentY_scale (v : Fin 3 → ℝ) (lam : ℝ) : momentY (fun i => lam*v i) = lam^3*momentY v := by - simp only [momentY, avg_expand]; ring - -lemma resolventQ_identity (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) - (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : - lam^3*(1-lam)*resolventQ v lam = lam^3*functionJ v-functionJ (fun i => lam*v i)+lam^2*(1-lam)*momentX v := by - have hh := resolvent_scaling v hp lam hl0 hl1 - rw [resolventA_identity v hp, resolventA_identity _ (fun i => message_segment_pos v hp lam hl0 hl1 i), - momentX_scale, momentY_scale] at hh - nlinarith only [hh] - -end ThreeState.Radial - -end OAI +import Mathlib +import OAI.Probability.ThreeState.RadialMoments + +namespace OAI + +/-! Fourth-moment resolvents and their lower bounds. -/ + +namespace ThreeState.Radial +open MeasureTheory + +noncomputable def fourthResolvent (v : Fin 3 → ℝ) (t : ℝ) : ℝ := avg (fun i => (v i)^4/(1+t*v i)) +noncomputable def doubleFourthResolvent (v : Fin 3 → ℝ) (lam t : ℝ) : ℝ := + avg (fun i => (v i)^4/((1+t*v i)*(1+lam*t*v i))) + +lemma fourth_moment (v : Fin 3 → ℝ) (hv : avg v = 0) : avg (fun i => (v i)^4) = 6*(momentX v)^2 := by + simp only [momentX, avg_expand, zero_sum_elim v hv] + ring + +lemma fourthResolvent_eq (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + fourthResolvent v t = (6*(momentX v)^2-10*t*momentX v*momentY v+4*t^2*(momentY v)^2)/denom v t := by + have h0 := ne_of_gt (message_segment_pos v hp t ht0 ht1 0) + have h1 := ne_of_gt (message_segment_pos v hp t ht0 ht1 1) + have h2 := ne_of_gt (message_segment_pos v hp t ht0 ht1 2) + have h0c : 1+v 0*t ≠ 0 := by simpa [mul_comm] using h0 + have h1c : 1+v 1*t ≠ 0 := by simpa [mul_comm] using h1 + have h2c : 1+v 2*t ≠ 0 := by simpa [mul_comm] using h2 + rw [denom_product v hv t] + simp only [fourthResolvent, momentX, momentY, avg_expand] + field_simp [h0, h1, h2, h0c, h1c, h2c] + rw [zero_sum_elim v hv] + ring + +lemma h_polynomial_bound (z : ℝ) (hz0 : 0 ≤ z) (hz1 : z < 1) : + (1-3*z^2+2*z^3)*(4+(64/9:ℝ)*(z-1/2)^2) ≤ 6-10*z+4*z^2 := by + rcases hz0.eq_or_lt with hzero | _ + · rw [← hzero] + norm_num + have hE : 1+z-2*z^2 ≤ (9/8:ℝ) := by nlinarith [sq_nonneg (z-1/4)] + have hh : (1+z-2*z^2)*(4+(64/9:ℝ)*(z-1/2)^2) ≤ 6-4*z := by + nlinarith [mul_nonneg (show 0 ≤ (9/8:ℝ)-(1+z-2*z^2) by linarith) (sq_nonneg (z-1/2))] + have he := mul_le_mul_of_nonneg_left hh (show 0 ≤ 1-z by linarith) + nlinarith only [he] + +lemma momentY_sqrt_bound (v : Fin 3 → ℝ) (hv : avg v = 0) : + -(Real.sqrt (momentX v))^3 ≤ momentY v ∧ momentY v ≤ (Real.sqrt (momentX v))^3 := by + have h := discriminant_nonneg v hv + have hs := Real.sq_sqrt (momentX_nonneg v) + have he : (momentX v)^3 = ((Real.sqrt (momentX v))^3)^2 := by + calc + (momentX v)^3 = ((Real.sqrt (momentX v))^2)^3 := congrArg (fun x : ℝ => x^3) hs.symm + _ = _ := by ring + rw [he] at h + have hr : 0 ≤ (Real.sqrt (momentX v))^3 := by positivity + exact abs_le.mp ((sq_le_sq₀ (abs_nonneg (momentY v)) hr).mp (by simpa only [sq_abs] using h)) + +lemma fourthResolvent_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + (momentX v)^2*(4+(64/9:ℝ)*(t*Real.sqrt (momentX v)-1/2)^2) ≤ fourthResolvent v t := by + let r := Real.sqrt (momentX v) + have hr0 : 0 ≤ r := Real.sqrt_nonneg _ + have hr2 : r^2 = momentX v := Real.sq_sqrt (momentX_nonneg v) + have hr1 : r < 1 := by nlinarith [momentX_lt_one v hv hp] + have hy := momentY_sqrt_bound v hv + change -r^3 ≤ momentY v ∧ momentY v ≤ r^3 at hy + have hz0 : 0 ≤ t*r := mul_nonneg ht0 hr0 + have hz1 : t*r < 1 := lt_of_le_of_lt (mul_le_of_le_one_left hr0 ht1) hr1 + have hn : (momentX v)^2*(6-10*(t*r)+4*(t*r)^2) ≤ + 6*(momentX v)^2-10*t*momentX v*momentY v+4*t^2*(momentY v)^2 := by + have htr : t*r ≤ 1 := hz1.le + have hfac : 0 ≤ 10*momentX v-4*t*(momentY v+r^3) := by + have h1 := mul_le_mul_of_nonneg_left hy.2 (by positivity : 0 ≤ 4*t) + have h2 := mul_le_mul_of_nonneg_left htr (by positivity : 0 ≤ 8*r^2) + nlinarith only [h1,h2, sq_nonneg r,hr2] + have hh := mul_nonneg (mul_nonneg ht0 (sub_nonneg.mpr hy.2)) hfac + rw [← hr2] at hh ⊢ + nlinarith only [hh] + have hd : denom v t ≤ 1-3*(t*r)^2+2*(t*r)^3 := by + have hh := mul_le_mul_of_nonneg_left hy.2 (by positivity : 0 ≤ 2*t^3) + dsimp only [denom] + rw [← hr2] + nlinarith only [hh] + have hg : 0 ≤ (momentX v)^2*(4+(64/9:ℝ)*(t*r-1/2)^2) := by positivity + have hh := mul_le_mul_of_nonneg_left hd hg + have hpoly := mul_le_mul_of_nonneg_left (h_polynomial_bound (t*r) hz0 hz1) (sq_nonneg (momentX v)) + rw [fourthResolvent_eq v hv hp t ht0 ht1] + apply (le_div_iff₀ (denom_pos v hv hp t ht0 ht1)).mpr + dsimp only [r] at hh hpoly + nlinarith only [hh,hpoly,hn] + +lemma fourthResolvent_four (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : 4*(momentX v)^2 ≤ fourthResolvent v t := by + have hh := fourthResolvent_lower v hv hp t ht0 ht1 + nlinarith [mul_nonneg (sq_nonneg (momentX v)) (sq_nonneg (t*Real.sqrt (momentX v)-1/2))] + +end ThreeState.Radial +namespace ThreeState.Radial +open MeasureTheory + +lemma doubleFourthResolvent_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) (t : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + 2*fourthResolvent v t ≤ (2+lam)*doubleFourthResolvent v lam t := by + let c := 1+lam/2 + have hc : 0 < c := by dsimp [c]; linarith + have hlt0 : 0 ≤ lam*t := mul_nonneg hl0 ht0 + have hlt1 : lam*t ≤ 1 := (mul_le_of_le_one_left ht0 hl1).trans ht1 + have hi (i : Fin 3) : (2*c-1+lam)*(v i)^4/(1+t*v i)-lam*(v i)^4 ≤ + c^2*(v i)^4/((1+t*v i)*(1+lam*t*v i)) := by + have hd := message_segment_pos v hp t ht0 ht1 i + have he := message_segment_pos v hp (lam*t) hlt0 hlt1 i + have hdc : 1+v i*t ≠ 0 := by simpa [mul_comm] using (ne_of_gt hd) + have hec : 1+v i*t*lam ≠ 0 := by convert ne_of_gt he using 1; ring + have hh : 0 ≤ (v i)^4*(c-(1+lam*t*v i))^2/((1+t*v i)*(1+lam*t*v i)) := by positivity + have hid : c^2*(v i)^4/((1+t*v i)*(1+lam*t*v i))- + ((2*c-1+lam)*(v i)^4/(1+t*v i)-lam*(v i)^4) = + (v i)^4*(c-(1+lam*t*v i))^2/((1+t*v i)*(1+lam*t*v i)) := by + field_simp [ne_of_gt hd, ne_of_gt he, hdc, hec] + ring + linarith + have hh : (2*c-1+lam)*fourthResolvent v t-lam*(6*(momentX v)^2) ≤ + c^2*doubleFourthResolvent v lam t := by + rw [← fourth_moment v hv] + simp only [fourthResolvent, doubleFourthResolvent, avg_expand] + have hi0 := hi 0 + have hi1 := hi 1 + have hi2 := hi 2 + simp only [mul_div_assoc] at hi0 hi1 hi2 + nlinarith only [hi0,hi1,hi2] + have hw := fourthResolvent_four v hv hp t ht0 ht1 + have hnon := mul_nonneg hl0 (show 0 ≤ fourthResolvent v t-4*(momentX v)^2 by linarith) + have hcW : c*fourthResolvent v t ≤ c^2*doubleFourthResolvent v lam t := by + dsimp only [c] at * + nlinarith only [hh,hnon] + have hres : fourthResolvent v t ≤ c*doubleFourthResolvent v lam t := by + apply (mul_le_mul_iff_right₀ hc).mp + nlinarith only [hcW] + dsimp only [c] at hres + linarith + +lemma continuousOn_fourthResolvent (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) : + ContinuousOn (fourthResolvent v) (Set.Icc 0 1) := by + have hi (i : Fin 3) : ContinuousOn (fun t : ℝ => (v i)^4/(1+t*v i)) (Set.Icc 0 1) := + continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (message_segment_pos v hp t ht.1 ht.2 i)) + convert (((hi 0).add (hi 1)).add (hi 2)).div_const 3 using 1 + funext t + exact avg_expand _ + +lemma continuousOn_doubleFourthResolvent (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) + (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : + ContinuousOn (doubleFourthResolvent v lam) (Set.Icc 0 1) := by + have hi (i : Fin 3) : ContinuousOn (fun t : ℝ => (v i)^4/((1+t*v i)*(1+lam*t*v i))) (Set.Icc 0 1) := + continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (mul_pos + (message_segment_pos v hp t ht.1 ht.2 i) + (message_segment_pos v hp (lam*t) (mul_nonneg hl0 ht.1) ((mul_le_of_le_one_left ht.1 hl1).trans ht.2) i))) + convert (((hi 0).add (hi 1)).add (hi 2)).div_const 3 using 1 + funext t + exact avg_expand _ + +noncomputable def resolventA (v : Fin 3 → ℝ) : ℝ := ∫ t in (0:ℝ)..1, t^2*fourthResolvent v t +noncomputable def resolventQ (v : Fin 3 → ℝ) (lam : ℝ) : ℝ := (∫ t in (0:ℝ)..1, t^2*doubleFourthResolvent v lam t)/2 +noncomputable def functionJ (v : Fin 3 → ℝ) : ℝ := avg (fun i => v i*Real.log (1+v i))/2 + +lemma integral_h_lower (r : ℝ) : + (∫ t in (0:ℝ)..1, t^2*(4+(64/9:ℝ)*(t*r-1/2)^2)) = (37/27:ℝ)+(64/45:ℝ)*(r-5/8)^2 := by + let P := fun t : ℝ => (52/27:ℝ)*t^3-(16/9:ℝ)*r*t^4+(64/45:ℝ)*r^2*t^5 + have hd (t : ℝ) : HasDerivAt P (t^2*(4+(64/9:ℝ)*(t*r-1/2)^2)) t := by + dsimp only [P] + convert ((((hasDerivAt_id t).pow 3).const_mul (52/27:ℝ)).sub + (((hasDerivAt_id t).pow 4).const_mul ((16/9:ℝ)*r))).add + (((hasDerivAt_id t).pow 5).const_mul ((64/45:ℝ)*r^2)) using 1 <;> first | rfl | (norm_num; ring) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) + (Continuous.intervalIntegrable (by fun_prop) 0 1)] + dsimp [P] + ring + +lemma resolventA_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) : + (37/27:ℝ)*(momentX v)^2 ≤ resolventA v := by + have hi : IntervalIntegrable (fun t : ℝ => (momentX v)^2*(t^2*(4+(64/9:ℝ)*(t*Real.sqrt (momentX v)-1/2)^2))) + volume 0 1 := Continuous.intervalIntegrable (by fun_prop) 0 1 + have hj : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent v t) volume 0 1 := + ((by fun_prop : ContinuousOn (fun t : ℝ => t^2) (Set.Icc 0 1)).mul (continuousOn_fourthResolvent v hp)).intervalIntegrable_of_Icc (by norm_num) + have hh := intervalIntegral.integral_mono_on (by norm_num : (0:ℝ) ≤ 1) hi hj (fun t ht => by + have he := mul_le_mul_of_nonneg_left (fourthResolvent_lower v hv hp t ht.1 ht.2) (sq_nonneg t) + nlinarith only [he]) + rw [intervalIntegral.integral_const_mul, integral_h_lower] at hh + dsimp only [resolventA] + nlinarith [mul_nonneg (sq_nonneg (momentX v)) (sq_nonneg (Real.sqrt (momentX v)-5/8))] + +lemma resolventQ_lower (v : Fin 3 → ℝ) (hv : avg v = 0) (hp : ∀ i, 0 < 1+v i) + (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : resolventA v/(2+lam) ≤ resolventQ v lam := by + have hi : IntervalIntegrable (fun t : ℝ => 2*(t^2*fourthResolvent v t)) volume 0 1 := + (continuousOn_const.mul ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent v hp))).intervalIntegrable_of_Icc (by norm_num) + have hj : IntervalIntegrable (fun t : ℝ => (2+lam)*(t^2*doubleFourthResolvent v lam t)) volume 0 1 := + (continuousOn_const.mul ((continuousOn_id.pow 2).mul (continuousOn_doubleFourthResolvent v hp lam hl0 hl1))).intervalIntegrable_of_Icc (by norm_num) + have hh := intervalIntegral.integral_mono_on (by norm_num : (0:ℝ) ≤ 1) hi hj (fun t ht => by + have he := mul_le_mul_of_nonneg_left (doubleFourthResolvent_lower v hv hp lam hl0 hl1 t ht.1 ht.2) (sq_nonneg t) + nlinarith only [he]) + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at hh + apply (div_le_iff₀ (by linarith : 0 < 2+lam)).mpr + dsimp only [resolventQ, resolventA] + linarith + +lemma scalar_resolventA (a : ℝ) (ha : 0 < 1+a) : + (∫ t in (0:ℝ)..1, t^2*a^4/(1+t*a)) = a^3/2-a^2+a*Real.log (1+a) := by + have hp (t : ℝ) (ht : t ∈ Set.Icc (0:ℝ) 1) : 0 < 1+t*a := by + rcases eq_or_lt_of_le ht.1 with hz | hz + · rw [← hz]; norm_num + · nlinarith [mul_pos hz ha, ht.2] + have hc : ContinuousOn (fun t : ℝ => a/(1+t*a)) (Set.Icc 0 1) := + continuousOn_const.div (by fun_prop) (fun t ht => ne_of_gt (hp t ht)) + have hi : IntervalIntegrable (fun t : ℝ => a/(1+t*a)) volume 0 1 := hc.intervalIntegrable_of_Icc (by norm_num : (0:ℝ) ≤ 1) + have he : (∫ t in (0:ℝ)..1, t^2*a^4/(1+t*a)) = + ∫ t in (0:ℝ)..1, (a^3*t-a^2)+a*(a/(1+t*a)) := by + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (0:ℝ) 1 := by simpa using ht + field_simp [ne_of_gt (hp t ht')] + ring + rw [he, intervalIntegral.integral_add (Continuous.intervalIntegrable (by fun_prop) 0 1) (hi.const_mul a), + intervalIntegral.integral_sub (Continuous.intervalIntegrable (by fun_prop) 0 1) (intervalIntegrable_const), + intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul, integral_id, + intervalIntegral.integral_const, ← log_integral a ha] + norm_num + ring + +lemma resolventA_identity (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) : + resolventA v = 2*functionJ v-2*momentX v+momentY v := by + have he (t : ℝ) : t^2*fourthResolvent v t = avg (fun i => t^2*(v i)^4/(1+t*v i)) := by + simp only [fourthResolvent, avg_expand]; ring + dsimp only [resolventA] + simp_rw [he] + rw [integral_avg] + · simp_rw [scalar_resolventA _ (hp _)] + simp only [functionJ, momentX, momentY, avg_expand] + ring + · intro i + exact ((by fun_prop : ContinuousOn (fun t : ℝ => t^2*(v i)^4) (Set.Icc 0 1)).div + (by fun_prop) (fun t ht => ne_of_gt (message_segment_pos v hp t ht.1 ht.2 i))).intervalIntegrable_of_Icc (by norm_num) + +lemma resolvent_scaling (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) + (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : + lam^3*resolventA v-resolventA (fun i => lam*v i) = 2*lam^3*(1-lam)*resolventQ v lam := by + have hpe (i : Fin 3) : 0 < 1+lam*v i := message_segment_pos v hp lam hl0 hl1 i + have hvI : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent v t) volume 0 1 := + ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent v hp)).intervalIntegrable_of_Icc (by norm_num) + have heI : IntervalIntegrable (fun t : ℝ => t^2*fourthResolvent (fun i => lam*v i) t) volume 0 1 := + ((continuousOn_id.pow 2).mul (continuousOn_fourthResolvent _ hpe)).intervalIntegrable_of_Icc (by norm_num) + have he : (∫ t in (0:ℝ)..1, lam^3*(t^2*fourthResolvent v t)-t^2*fourthResolvent (fun i => lam*v i) t) = + ∫ t in (0:ℝ)..1, (lam^3*(1-lam))*(t^2*doubleFourthResolvent v lam t) := by + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (0:ℝ) 1 := by simpa using ht + have hi (i : Fin 3) : lam^3*((v i)^4/(1+t*v i))-(lam*v i)^4/(1+t*(lam*v i)) = + lam^3*(1-lam)*((v i)^4/((1+t*v i)*(1+lam*t*v i))) := by + have ha := ne_of_gt (message_segment_pos v hp t ht'.1 ht'.2 i) + have hb := ne_of_gt (message_segment_pos _ hpe t ht'.1 ht'.2 i) + have ha' : 1+v i*t ≠ 0 := by simpa [mul_comm] using ha + have hb' : 1+v i*t*lam ≠ 0 := by convert hb using 1; ring + have hb'' : 1+lam*v i*t ≠ 0 := by convert hb using 1; ring + have hb''' : 1+lam*t*v i ≠ 0 := by convert hb using 1; ring + field_simp [ha, hb, ha', hb', hb'', hb'''] + ring + simp only [fourthResolvent, doubleFourthResolvent, avg_expand] + linear_combination t^2/3*(hi 0)+t^2/3*(hi 1)+t^2/3*(hi 2) + rw [intervalIntegral.integral_sub (hvI.const_mul _) heI, + intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at he + dsimp only [resolventA, resolventQ] + linarith only [he] + +lemma momentX_scale (v : Fin 3 → ℝ) (lam : ℝ) : momentX (fun i => lam*v i) = lam^2*momentX v := by + simp only [momentX, avg_expand]; ring + +lemma momentY_scale (v : Fin 3 → ℝ) (lam : ℝ) : momentY (fun i => lam*v i) = lam^3*momentY v := by + simp only [momentY, avg_expand]; ring + +lemma resolventQ_identity (v : Fin 3 → ℝ) (hp : ∀ i, 0 < 1+v i) + (lam : ℝ) (hl0 : 0 ≤ lam) (hl1 : lam ≤ 1) : + lam^3*(1-lam)*resolventQ v lam = lam^3*functionJ v-functionJ (fun i => lam*v i)+lam^2*(1-lam)*momentX v := by + have hh := resolvent_scaling v hp lam hl0 hl1 + rw [resolventA_identity v hp, resolventA_identity _ (fun i => message_segment_pos v hp lam hl0 hl1 i), + momentX_scale, momentY_scale] at hh + nlinarith only [hh] + +end ThreeState.Radial + +end OAI diff --git a/lean/OAI/Probability/ThreeState/ScalarBounds.lean b/lean/OAI/Probability/ThreeState/ScalarBounds.lean index 28c8a987850efbdb09c63b1cd8c2ff1f801a9eaa..0f3d00d9472b08dbe4f0242b46add0877d5f4adc 100644 --- a/lean/OAI/Probability/ThreeState/ScalarBounds.lean +++ b/lean/OAI/Probability/ThreeState/ScalarBounds.lean @@ -1,387 +1,387 @@ -import Mathlib - -namespace OAI - -/-! Scalar inequalities for criticality, Poisson survival and nonlinear decay. -/ - -namespace ThreeState.PositiveScalar - -noncomputable def lowerC (lam : ℝ) : ℝ := (37/27:ℝ)*(1+2*lam/3) - -lemma small_polynomial (lam : ℝ) (h0 : 0 < lam) (h1 : lam ≤ 3/10) : - (2/5-lam^2/2)*(lowerC lam)^2 > (2/3:ℝ)*(11/10+lam^2/2) := by - have hnon : 0 ≤ (3/10:ℝ)-lam := by linarith - have he : (2/5-lam^2/2)*(lowerC lam)^2-(2/3:ℝ)*(11/10+lam^2/2) = - (130000/59049:ℝ)*(3/10-lam)^4+(2710400/59049:ℝ)*lam*(3/10-lam)^3+ - (6735490/59049:ℝ)*lam^2*(3/10-lam)^2+(1871120/19683:ℝ)*lam^3*(3/10-lam)+ - (159292/6561:ℝ)*lam^4 := by dsimp only [lowerC]; ring - have hp : 0 < (130000/59049:ℝ)*(3/10-lam)^4+(2710400/59049:ℝ)*lam*(3/10-lam)^3+ - (6735490/59049:ℝ)*lam^2*(3/10-lam)^2+(1871120/19683:ℝ)*lam^3*(3/10-lam)+ - (159292/6561:ℝ)*lam^4 := by positivity - linarith - -lemma middle_polynomial (lam : ℝ) (h0 : 3/10 ≤ lam) (h1 : lam^2 ≤ 1/2) : - 1-17*lam/25 < (2/5-lam^2/2)*(lowerC lam)^2 := by - have ha : 0 ≤ lam-(3/10:ℝ) := by linarith - have hb : 0 < (71/100:ℝ)-lam := by nlinarith - have he : (2/5-lam^2/2)*(lowerC lam)^2-(1-17*lam/25) = - (1328320000/228886641:ℝ)*(71/100-lam)^4+ - (75777584000/2059979769:ℝ)*(lam-3/10)*(71/100-lam)^3+ - (1184570339800/18539817921:ℝ)*(lam-3/10)^2*(71/100-lam)^2+ - (674265198440/18539817921:ℝ)*(lam-3/10)^3*(71/100-lam)+ - (56362261022/18539817921:ℝ)*(lam-3/10)^4 := by dsimp only [lowerC]; ring - have hp : 0 < (1328320000/228886641:ℝ)*(71/100-lam)^4+ - (75777584000/2059979769:ℝ)*(lam-3/10)*(71/100-lam)^3+ - (1184570339800/18539817921:ℝ)*(lam-3/10)^2*(71/100-lam)^2+ - (674265198440/18539817921:ℝ)*(lam-3/10)^3*(71/100-lam)+ - (56362261022/18539817921:ℝ)*(lam-3/10)^4 := by positivity - linarith - -lemma rational_lower (mu : ℝ) (hm : 0 ≤ mu) : 3/2-mu ≤ 3/(2*(1+2*mu/3)) := by - apply (le_div_iff₀ (by positivity : 0 < 2*(1+2*mu/3))).mpr - nlinarith [sq_nonneg mu] - -lemma regular_scalar (lam mu c : ℝ) (h0 : 0 < lam) (hl : lam^2 ≤ 1/2) - (hm : 0 ≤ mu) (hc : lowerC lam ≤ c) (hb : mu*c^2 ≤ 1) : - 8/5 < (1-lam^2)/2+3/(2*(1+2*mu/3))+17*lam*mu/25 := by - have hl1 : lam < 1 := by nlinarith - have hc0 : 0 < lowerC lam := by dsimp only [lowerC]; positivity - have hc2 : (lowerC lam)^2 ≤ c^2 := sq_le_sq₀ hc0.le (hc0.trans_le hc).le |>.mpr hc - have hcpos : 0 < c := hc0.trans_le hc - have hden : 0 < 2*(1+2*mu/3) := by positivity - rcases le_total lam (3/10) with hs | hs - · have hp := small_polynomial lam h0 hs - have hfac : 0 < 2/5-lam^2/2 := by nlinarith - have hpc : (2/3:ℝ)*(11/10+lam^2/2) < (2/5-lam^2/2)*c^2 := - hp.trans_le (mul_le_mul_of_nonneg_left hc2 hfac.le) - have ht : (11/10+lam^2/2)*mu < (3/2:ℝ)*(2/5-lam^2/2) := by - have hh := mul_le_mul_of_nonneg_left hb (show 0 ≤ 11/10+lam^2/2 by positivity) - have hh' := mul_lt_mul_of_pos_left hpc (show 0 < (3/2:ℝ) by norm_num) - have he : ((11/10+lam^2/2)*mu)*c^2 < ((3/2:ℝ)*(2/5-lam^2/2))*c^2 := by nlinarith only [hh,hh'] - exact (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp he - have he : 11/10+lam^2/2 < 3/(2*(1+2*mu/3)) := by - apply (lt_div_iff₀ hden).mpr - nlinarith only [ht] - have hlast : 0 ≤ 17*lam*mu/25 := by positivity - linarith - · have hpoly := middle_polynomial lam hs hl - have hfac : 0 < 2/5-lam^2/2 := by nlinarith - have hpc : 1-17*lam/25 < (2/5-lam^2/2)*c^2 := - hpoly.trans_le (mul_le_mul_of_nonneg_left hc2 hfac.le) - have hcoef : 0 < 1-17*lam/25 := by linarith - have hh := mul_le_mul_of_nonneg_left hb hcoef.le - have ht : (1-17*lam/25)*mu < 2/5-lam^2/2 := by - apply (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp - nlinarith only [hpc,hh] - have hr := rational_lower mu hm - nlinarith only [ht,hr] - -lemma high_scalar (lam mu c : ℝ) (h0 : 0 < lam) (hl1 : lam < 1) (hl : 1/2 < lam^2) - (hm : 0 ≤ mu) (hc : lowerC lam ≤ c) (hb : mu*c^2 ≤ 1) : - 8/5 < (1/4:ℝ)+3/(2*(1+2*mu/3))+17*lam*mu/25 := by - have hx : (707/1000:ℝ) < lam := by nlinarith - have hc' : (37/27:ℝ)*(1+2*(707/1000:ℝ)/3) < c := by dsimp only [lowerC] at hc; linarith - have hcpos : 0 < c := by linarith - have hp : 1-17*lam/25 < (3/20:ℝ)*c^2 := by nlinarith [sq_nonneg (c-(37/27:ℝ)*(1+2*(707/1000:ℝ)/3))] - have hcoef : 0 < 1-17*lam/25 := by linarith - have hh := mul_le_mul_of_nonneg_left hb hcoef.le - have ht : (1-17*lam/25)*mu < (3/20:ℝ) := by - apply (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp - nlinarith only [hp,hh] - have hr := rational_lower mu hm - nlinarith only [ht,hr] - - - -theorem scalar_contradiction (lam mu c s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) - (hm : 0 ≤ mu) (hs0 : 0 < s) (hs1 : s ≤ 1) (hc : lowerC lam ≤ c) - (hb : mu*c^2 ≤ s) (hsurv : 1/2 < lam^2 → s ≤ 2*(1-lam^2)) : - 8/5 < (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s) := by - have hlast : 17*lam*mu/25 ≤ 17*lam*mu/(25*s) := by - apply (le_div_iff₀ (by positivity : 0 < 25*s)).mpr - nlinarith [mul_nonneg (show 0 ≤ 17*lam*mu by positivity) (show 0 ≤ 1-s by linarith)] - rcases le_or_gt (lam^2) (1/2) with hl | hl - · have hh := regular_scalar lam mu c h0 hl hm hc (hb.trans hs1) - have hf : (1-lam^2)/2 ≤ (1-lam^2)/(2*s) := by - apply (le_div_iff₀ (by positivity : 0 < 2*s)).mpr - nlinarith [mul_nonneg (show 0 ≤ 1-lam^2 by nlinarith) (show 0 ≤ 1-s by linarith)] - linarith - · have hh := high_scalar lam mu c h0 h1 hl hm hc (hb.trans hs1) - have hf : (1/4:ℝ) ≤ (1-lam^2)/(2*s) := by - apply (le_div_iff₀ (by positivity : 0 < 2*s)).mpr - linarith [hsurv hl] - linarith - -end ThreeState.PositiveScalar - -namespace ThreeState.PositiveScalar - -lemma q_lower (lam : ℝ) (h0 : 0 ≤ lam) (h1 : lam ≤ 1) : - (37/81:ℝ) ≤ (37/27:ℝ)/(2+lam) := by - apply (le_div_iff₀ (by linarith : 0 < 2+lam)).mpr - linarith - -lemma root_loss : (1:ℝ)/Real.sqrt 2 < 113/81-17/25 := by - have hr : 0 < Real.sqrt 2 := by positivity - have hs : (Real.sqrt 2)^2=2 := Real.sq_sqrt (by norm_num) - apply (div_lt_iff₀ hr).mpr - nlinarith only [hs, Real.sqrt_nonneg 2] - -lemma J_square_bound (lam mu nu J : ℝ) (h0 : 0 < lam) (h1 : lam < 1) - (hm : 0 ≤ mu) (hn : 0 ≤ nu) (hJ0 : 0 ≤ J) - (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) - (hc : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) : - (8/5:ℝ)*J^2 ≤ (8/5:ℝ)*mu^2-(113/81:ℝ)*lam*mu*nu := by - let q : ℝ := (37/27:ℝ)/(2+lam) - let A := lam*q*nu - have hq := q_lower lam h0.le h1.le - change (37/81:ℝ) ≤ q at hq - have hA0 : 0 ≤ A := by dsimp only [A]; positivity - have hAc : 8*(37/27:ℝ)*A ≤ mu := by - have hh := mul_le_mul_of_nonneg_right (sq_nonneg ((37/27:ℝ)-2*lam*q)) hn - dsimp only [A,q] at * - nlinarith only [hh,hc] - have hA : A ≤ (27/296:ℝ)*mu := by linarith only [hAc] - have hs := mul_le_mul_of_nonneg_right hA hA0 - change J ≤ mu-A at hJ - have hj2 : J^2 ≤ (mu-A)^2 := (sq_le_sq₀ hJ0 (hJ0.trans hJ)).mpr hJ - have hqmu := mul_le_mul_of_nonneg_right hq (show 0 ≤ lam*mu*nu by positivity) - have hlead : mu*A = q*(lam*mu*nu) := by dsimp only [A]; ring - rw [← hlead] at hqmu - nlinarith only [hj2,hs,hqmu] - -lemma scalar_from_moments (lam mu nu J s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) - (hm : 0 < mu) (hn : 0 ≤ nu) (hs0 : 0 < s) (_ : s ≤ 1) - (hsecond : mu^2 ≤ s*nu) - (hcnu : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) - (hJ0 : 0 ≤ J) (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) - (hentropy : (1-lam^2)/2*nu+3*mu^2/(2*(1+2*mu/3))-lam*mu*nu/Real.sqrt 2 ≤ (8/5:ℝ)*J^2) : - 8/5 ≥ (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s) := by - have hj2 := J_square_bound lam mu nu J h0 h1 hm.le hn hJ0 hJ hcnu - have hroot := mul_le_mul_of_nonneg_right root_loss.le (show 0 ≤ lam*mu*nu by positivity) - have he : ((1-lam^2)/2+17*lam*mu/25)*nu+3*mu^2/(2*(1+2*mu/3)) ≤ (8/5:ℝ)*mu^2 := by - simp only [div_eq_mul_inv] at hentropy hj2 hroot ⊢ - nlinarith only [hentropy,hj2,hroot] - have ha : 0 ≤ (1-lam^2)/2+17*lam*mu/25 := by - have hh : 0 ≤ 1-lam^2 := by nlinarith - positivity - have hh := mul_le_mul_of_nonneg_left ((div_le_iff₀ hs0).mpr (show mu^2 ≤ nu*s by nlinarith only [hsecond])) ha - have hneed : ((1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s))*mu^2 ≤ (8/5:ℝ)*mu^2 := by - simp only [div_eq_mul_inv, mul_inv_rev] at he hh ⊢ - nlinarith only [he,hh] - exact (mul_le_mul_iff_left₀ (sq_pos_of_pos hm)).mp hneed - -lemma moment_scalar_contradiction (lam mu nu J s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) - (hm : 0 < mu) (hn : 0 ≤ nu) (hs0 : 0 < s) (hs1 : s ≤ 1) - (hsecond : mu^2 ≤ s*nu) - (hcnu : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) - (hJ0 : 0 ≤ J) (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) - (hentropy : (1-lam^2)/2*nu+3*mu^2/(2*(1+2*mu/3))-lam*mu*nu/Real.sqrt 2 ≤ (8/5:ℝ)*J^2) - (hsurv : 1/2 < lam^2 → s ≤ 2*(1-lam^2)) : False := by - let c : ℝ := (37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)) - have hc : 0 < c := by dsimp only [c]; positivity - have hcL : lowerC lam ≤ c := by - have hh := q_lower lam h0.le h1.le - dsimp only [lowerC,c] - nlinarith only [hh,h0] - have hb : mu*c^2 ≤ s := by - have hh := mul_le_mul_of_nonneg_right hsecond (sq_nonneg c) - have hh' := mul_le_mul_of_nonneg_left hcnu hs0.le - apply (mul_le_mul_iff_left₀ hm).mp - dsimp only [c] at * - nlinarith only [hh,hh'] - have hfalse := scalar_contradiction lam mu c s h0 h1 hm.le hs0 hs1 hcL hb hsurv - have hneed := scalar_from_moments lam mu nu J s h0 h1 hm hn hs0 hs1 hsecond hcnu hJ0 hJ hentropy - linarith only [hfalse,hneed] - -end ThreeState.PositiveScalar - -namespace ThreeState -open Filter Topology - -lemma poisson_sqrt_tangent (d lam t : ℝ) (_ : 0 (3*lam^4*mu^2/D^2)*((2*D-1)*t^2/2-(lam^2*mu)*t^3/3)- - (lam^5*mu*nu/Real.sqrt 2)*(t^2/2+d*t/2) - let P' := fun t : ℝ => (3*lam^4*mu^2/D^2)*((2*D-1)*t-(lam^2*mu)*t^2)- - (lam^5*mu*nu/Real.sqrt 2)*(t+d/2) - have hp (t : ℝ) : HasDerivAt P (P' t) t := by - have hh := (((((hasDerivAt_pow 2 t).const_mul (2*D-1)).div_const 2).sub - (((hasDerivAt_pow 3 t).const_mul (lam^2*mu)).div_const 3)).const_mul (3*lam^4*mu^2/D^2)).sub - ((((hasDerivAt_pow 2 t).div_const 2).add (((hasDerivAt_id t).const_mul d).div_const 2)).const_mul (lam^5*mu*nu/Real.sqrt 2)) - convert hh using 1 <;> try rfl - dsimp only [P'] - ring - have hpd (t : ℝ) (ht : t ∈ Set.Icc 0 d) : P' t ≤ 3*C t := by - have hr := mul_le_mul_of_nonneg_left (poisson_reciprocal_tangent t (lam^2*mu) D ht.1 (by positivity) hD) - (show 0≤3*lam^4*mu^2 by positivity) - have hs := mul_le_mul_of_nonneg_left (poisson_sqrt_tangent d lam t hd hl ht.1 hc) - (show 0≤lam^4*mu*nu by positivity) - calc - P' t = 3*lam^4*mu^2*(t*(2*D-1-(lam^2*mu)*t)/D^2)-lam^4*mu*nu*(lam*(t+d/2)/Real.sqrt 2) := by dsimp only [P']; ring - _ ≤ 3*lam^4*mu^2*(t/(1+(lam^2*mu)*t))-lam^4*mu*nu*Real.sqrt t := sub_le_sub hr hs - _ = 3*lam^4*mu^2*t/(1+t*lam^2*mu)-lam^4*mu*nu*Real.sqrt t := by ring - _ ≤ _ := hlower t ht - have hmono : MonotoneOn (fun t => 3*H t-P t) (Set.Icc 0 d) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 d) (f' := fun t => 3*C t-P' t) - · intro t ht - exact (((hderiv t ht).const_mul 3).sub (hp t)).continuousAt.continuousWithinAt - · intro t ht - exact (((hderiv t (interior_subset ht)).const_mul 3).sub (hp t)).hasDerivWithinAt - · intro t ht - exact sub_nonneg.mpr (hpd t (interior_subset ht)) - have hh := hmono (show (0:ℝ)∈Set.Icc 0 d from ⟨le_rfl,hd.le⟩) (show d∈Set.Icc 0 d from ⟨hd.le,le_rfl⟩) hd.le - have hp0 : P 0=0 := by simp [P] - have hpend : P d=3*mu^2/(2*D)-lam*mu*nu/Real.sqrt 2 := by - have hd2 : d^2*lam^4=1 := by nlinarith [sq_nonneg (d*lam^2-1)] - have hd3 : d^3*lam^6=1 := by - calc - _ = (d*lam^2)^3 := by ring - _ = 1 := by rw [hc]; norm_num - dsimp only [P] - field_simp [ne_of_gt hD] - dsimp only [D] - nlinarith only [congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^2) hd2, - congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^3) hd2, - congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^3) hd3, - congrArg (fun x : ℝ => x*lam*mu*nu) hd2, - congrArg (fun x : ℝ => x*lam*mu^2*nu) hd2, - congrArg (fun x : ℝ => x*lam*mu^3*nu) hd2] - change 3*H 0-P 0 ≤ 3*H d-P d at hh - rw [hH0,hp0,hpend] at hh - dsimp only [D] at hh - linarith - -end ThreeState - -namespace ThreeState -open Filter Topology - -lemma log_survival_bound (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s < 1) : - 2*s/(2-s) ≤ -Real.log (1-s) := by - let F := fun x : ℝ => -Real.log (1-x)-2*x/(2-x) - have hd (x : ℝ) (hx : x ∈ Set.Icc 0 s) : HasDerivAt F - (1/(1-x)-4/(2-x)^2) x := by - have h1 : 1-x ≠ 0 := by linarith [hx.2] - have h2 : 2-x ≠ 0 := by linarith [hx.2] - convert (((hasDerivAt_const x (1:ℝ)).sub (hasDerivAt_id x)).log h1).neg.sub - (((hasDerivAt_id x).const_mul 2).div ((hasDerivAt_const x (2:ℝ)).sub (hasDerivAt_id x)) h2) using 1 <;> try rfl - dsimp - field_simp - ring - have hder (x : ℝ) (hx : x ∈ Set.Icc 0 s) : 0 ≤ 1/(1-x)-4/(2-x)^2 := by - have h1 : 0 < 1-x := by linarith [hx.2] - have h2 : 0 < 2-x := by linarith [hx.2] - apply sub_nonneg.mpr - apply (div_le_div_iff₀ (sq_pos_of_pos h2) h1).mpr - nlinarith [sq_nonneg x] - have hmono : MonotoneOn F (Set.Icc 0 s) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 s) - (f' := fun x => 1/(1-x)-4/(2-x)^2) - · intro x hx; exact (hd x hx).continuousAt.continuousWithinAt - · intro x hx; exact (hd x (interior_subset hx)).hasDerivWithinAt - · intro x hx; exact hder x (interior_subset hx) - have hh := hmono (show (0:ℝ)∈Set.Icc 0 s from ⟨le_rfl,hs0⟩) (show s∈Set.Icc 0 s from ⟨hs0,le_rfl⟩) hs0 - dsimp only [F] at hh - norm_num at hh - linarith - -lemma poisson_support_bound (d s : ℝ) (hd : 0 < d) (hs : 0 < s) - (hfp : Real.exp (-d*s) ≤ 1-s) : s ≤ 2*(1-d⁻¹) := by - have hs1 : s < 1 := by linarith [Real.exp_pos (-d*s)] - have hlog := Real.log_le_log (Real.exp_pos (-d*s)) hfp - rw [Real.log_exp] at hlog - have hh := log_survival_bound s hs.le hs1 - have hden : 0 < 2-s := by linarith - have hrat : 2*s/(2-s) ≤ d*s := by linarith - have hr := (div_le_iff₀ hden).mp hrat - have hsd : 2 ≤ d*(2-s) := (mul_le_mul_iff_right₀ hs).mp (by nlinarith only [hr]) - apply (mul_le_mul_iff_left₀ hd).mp - have he : (2*(1-d⁻¹))*d=2*d-2 := by field_simp - rw [he] - nlinarith only [hsd] -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical -noncomputable section - -lemma bernoulli_lower (t:ℝ) (ht0:0≤t) (ht1:t≤1) (k:ℕ) : 1-k*t≤(1-t)^k := by - induction k with - | zero => simp - | succ k ih => - have hh:=mul_le_mul_of_nonneg_right ih (by linarith : 0≤1-t) - rw [pow_succ (1-t) k,Nat.cast_succ] - nlinarith [mul_nonneg (Nat.cast_nonneg (α:=ℝ) k) (mul_nonneg ht0 ht0)] - -lemma bernoulli_quadratic_lower (t:ℝ) (ht0:0≤t) (ht1:t≤1) (k:ℕ) (hk:2≤k) : - 1-k*t+t^2≤(1-t)^k := by - induction k,hk using Nat.le_induction with - | base => norm_num;ring_nf;exact le_refl _ - | succ k hk ih => - have hh:=mul_le_mul_of_nonneg_right ih (by linarith : 0≤1-t) - have hkr:(2:ℝ)≤k:=by exact_mod_cast hk - have hp:=mul_nonneg (show 0≤(k:ℝ)-t by linarith) (show 0≤t^2 by exact pow_nonneg ht0 2) - rw [pow_succ (1-t) k,Nat.cast_succ] - nlinarith - - -def decaySeq (c:ℝ) : ℕ→ℝ - | 0=>1 - | n+1=>decaySeq c n-c*(decaySeq c n)^2 -lemma decaySeq_bounds (c:ℝ) (hc0:0≤c) (hc1:c≤1) (n:ℕ) : - 0≤decaySeq c n ∧ decaySeq c n≤1 := by - induction n with - | zero => simp [decaySeq] - | succ n ih => - have hp:0≤c*(decaySeq c n)^2:=mul_nonneg hc0 (sq_nonneg _) - have ht:c*decaySeq c n≤1:=(mul_le_mul_of_nonneg_right hc1 ih.1).trans (by simpa using ih.2) - have hh:=mul_nonneg ih.1 (show 0≤1-c*decaySeq c n by linarith) - simp only [decaySeq] - constructor <;> nlinarith -lemma decaySeq_antitone (c:ℝ) (hc:0≤c) : Antitone (decaySeq c) := - antitone_nat_of_succ_le (fun n=>by dsimp [decaySeq];nlinarith [mul_nonneg hc (sq_nonneg (decaySeq c n))]) -lemma decaySeq_tendsto (c:ℝ) (hc:0decaySeq c (n+1)) atTop (𝓝 L):=hl.comp (Filter.tendsto_add_atTop_nat 1) - have hrec:Tendsto (fun n=>decaySeq c (n+1)) atTop (𝓝 (L-c*L^2)):=hl.sub (tendsto_const_nhds.mul (hl.pow 2)) - have he:L=L-c*L^2:=tendsto_nhds_unique hl' hrec - have hzero:c*L^2=0:=by linarith - have hz:L=0:= (eq_zero_of_pow_eq_zero ((mul_eq_zero.mp hzero).resolve_left hc.ne')) - have hlast:Tendsto (decaySeq c) atTop (𝓝 L):=hl - rwa [hz] at hlast -end -end ThreeState - -end OAI +import Mathlib + +namespace OAI + +/-! Scalar inequalities for criticality, Poisson survival and nonlinear decay. -/ + +namespace ThreeState.PositiveScalar + +noncomputable def lowerC (lam : ℝ) : ℝ := (37/27:ℝ)*(1+2*lam/3) + +lemma small_polynomial (lam : ℝ) (h0 : 0 < lam) (h1 : lam ≤ 3/10) : + (2/5-lam^2/2)*(lowerC lam)^2 > (2/3:ℝ)*(11/10+lam^2/2) := by + have hnon : 0 ≤ (3/10:ℝ)-lam := by linarith + have he : (2/5-lam^2/2)*(lowerC lam)^2-(2/3:ℝ)*(11/10+lam^2/2) = + (130000/59049:ℝ)*(3/10-lam)^4+(2710400/59049:ℝ)*lam*(3/10-lam)^3+ + (6735490/59049:ℝ)*lam^2*(3/10-lam)^2+(1871120/19683:ℝ)*lam^3*(3/10-lam)+ + (159292/6561:ℝ)*lam^4 := by dsimp only [lowerC]; ring + have hp : 0 < (130000/59049:ℝ)*(3/10-lam)^4+(2710400/59049:ℝ)*lam*(3/10-lam)^3+ + (6735490/59049:ℝ)*lam^2*(3/10-lam)^2+(1871120/19683:ℝ)*lam^3*(3/10-lam)+ + (159292/6561:ℝ)*lam^4 := by positivity + linarith + +lemma middle_polynomial (lam : ℝ) (h0 : 3/10 ≤ lam) (h1 : lam^2 ≤ 1/2) : + 1-17*lam/25 < (2/5-lam^2/2)*(lowerC lam)^2 := by + have ha : 0 ≤ lam-(3/10:ℝ) := by linarith + have hb : 0 < (71/100:ℝ)-lam := by nlinarith + have he : (2/5-lam^2/2)*(lowerC lam)^2-(1-17*lam/25) = + (1328320000/228886641:ℝ)*(71/100-lam)^4+ + (75777584000/2059979769:ℝ)*(lam-3/10)*(71/100-lam)^3+ + (1184570339800/18539817921:ℝ)*(lam-3/10)^2*(71/100-lam)^2+ + (674265198440/18539817921:ℝ)*(lam-3/10)^3*(71/100-lam)+ + (56362261022/18539817921:ℝ)*(lam-3/10)^4 := by dsimp only [lowerC]; ring + have hp : 0 < (1328320000/228886641:ℝ)*(71/100-lam)^4+ + (75777584000/2059979769:ℝ)*(lam-3/10)*(71/100-lam)^3+ + (1184570339800/18539817921:ℝ)*(lam-3/10)^2*(71/100-lam)^2+ + (674265198440/18539817921:ℝ)*(lam-3/10)^3*(71/100-lam)+ + (56362261022/18539817921:ℝ)*(lam-3/10)^4 := by positivity + linarith + +lemma rational_lower (mu : ℝ) (hm : 0 ≤ mu) : 3/2-mu ≤ 3/(2*(1+2*mu/3)) := by + apply (le_div_iff₀ (by positivity : 0 < 2*(1+2*mu/3))).mpr + nlinarith [sq_nonneg mu] + +lemma regular_scalar (lam mu c : ℝ) (h0 : 0 < lam) (hl : lam^2 ≤ 1/2) + (hm : 0 ≤ mu) (hc : lowerC lam ≤ c) (hb : mu*c^2 ≤ 1) : + 8/5 < (1-lam^2)/2+3/(2*(1+2*mu/3))+17*lam*mu/25 := by + have hl1 : lam < 1 := by nlinarith + have hc0 : 0 < lowerC lam := by dsimp only [lowerC]; positivity + have hc2 : (lowerC lam)^2 ≤ c^2 := sq_le_sq₀ hc0.le (hc0.trans_le hc).le |>.mpr hc + have hcpos : 0 < c := hc0.trans_le hc + have hden : 0 < 2*(1+2*mu/3) := by positivity + rcases le_total lam (3/10) with hs | hs + · have hp := small_polynomial lam h0 hs + have hfac : 0 < 2/5-lam^2/2 := by nlinarith + have hpc : (2/3:ℝ)*(11/10+lam^2/2) < (2/5-lam^2/2)*c^2 := + hp.trans_le (mul_le_mul_of_nonneg_left hc2 hfac.le) + have ht : (11/10+lam^2/2)*mu < (3/2:ℝ)*(2/5-lam^2/2) := by + have hh := mul_le_mul_of_nonneg_left hb (show 0 ≤ 11/10+lam^2/2 by positivity) + have hh' := mul_lt_mul_of_pos_left hpc (show 0 < (3/2:ℝ) by norm_num) + have he : ((11/10+lam^2/2)*mu)*c^2 < ((3/2:ℝ)*(2/5-lam^2/2))*c^2 := by nlinarith only [hh,hh'] + exact (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp he + have he : 11/10+lam^2/2 < 3/(2*(1+2*mu/3)) := by + apply (lt_div_iff₀ hden).mpr + nlinarith only [ht] + have hlast : 0 ≤ 17*lam*mu/25 := by positivity + linarith + · have hpoly := middle_polynomial lam hs hl + have hfac : 0 < 2/5-lam^2/2 := by nlinarith + have hpc : 1-17*lam/25 < (2/5-lam^2/2)*c^2 := + hpoly.trans_le (mul_le_mul_of_nonneg_left hc2 hfac.le) + have hcoef : 0 < 1-17*lam/25 := by linarith + have hh := mul_le_mul_of_nonneg_left hb hcoef.le + have ht : (1-17*lam/25)*mu < 2/5-lam^2/2 := by + apply (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp + nlinarith only [hpc,hh] + have hr := rational_lower mu hm + nlinarith only [ht,hr] + +lemma high_scalar (lam mu c : ℝ) (h0 : 0 < lam) (hl1 : lam < 1) (hl : 1/2 < lam^2) + (hm : 0 ≤ mu) (hc : lowerC lam ≤ c) (hb : mu*c^2 ≤ 1) : + 8/5 < (1/4:ℝ)+3/(2*(1+2*mu/3))+17*lam*mu/25 := by + have hx : (707/1000:ℝ) < lam := by nlinarith + have hc' : (37/27:ℝ)*(1+2*(707/1000:ℝ)/3) < c := by dsimp only [lowerC] at hc; linarith + have hcpos : 0 < c := by linarith + have hp : 1-17*lam/25 < (3/20:ℝ)*c^2 := by nlinarith [sq_nonneg (c-(37/27:ℝ)*(1+2*(707/1000:ℝ)/3))] + have hcoef : 0 < 1-17*lam/25 := by linarith + have hh := mul_le_mul_of_nonneg_left hb hcoef.le + have ht : (1-17*lam/25)*mu < (3/20:ℝ) := by + apply (mul_lt_mul_iff_left₀ (sq_pos_of_pos hcpos)).mp + nlinarith only [hp,hh] + have hr := rational_lower mu hm + nlinarith only [ht,hr] + + + +theorem scalar_contradiction (lam mu c s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) + (hm : 0 ≤ mu) (hs0 : 0 < s) (hs1 : s ≤ 1) (hc : lowerC lam ≤ c) + (hb : mu*c^2 ≤ s) (hsurv : 1/2 < lam^2 → s ≤ 2*(1-lam^2)) : + 8/5 < (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s) := by + have hlast : 17*lam*mu/25 ≤ 17*lam*mu/(25*s) := by + apply (le_div_iff₀ (by positivity : 0 < 25*s)).mpr + nlinarith [mul_nonneg (show 0 ≤ 17*lam*mu by positivity) (show 0 ≤ 1-s by linarith)] + rcases le_or_gt (lam^2) (1/2) with hl | hl + · have hh := regular_scalar lam mu c h0 hl hm hc (hb.trans hs1) + have hf : (1-lam^2)/2 ≤ (1-lam^2)/(2*s) := by + apply (le_div_iff₀ (by positivity : 0 < 2*s)).mpr + nlinarith [mul_nonneg (show 0 ≤ 1-lam^2 by nlinarith) (show 0 ≤ 1-s by linarith)] + linarith + · have hh := high_scalar lam mu c h0 h1 hl hm hc (hb.trans hs1) + have hf : (1/4:ℝ) ≤ (1-lam^2)/(2*s) := by + apply (le_div_iff₀ (by positivity : 0 < 2*s)).mpr + linarith [hsurv hl] + linarith + +end ThreeState.PositiveScalar + +namespace ThreeState.PositiveScalar + +lemma q_lower (lam : ℝ) (h0 : 0 ≤ lam) (h1 : lam ≤ 1) : + (37/81:ℝ) ≤ (37/27:ℝ)/(2+lam) := by + apply (le_div_iff₀ (by linarith : 0 < 2+lam)).mpr + linarith + +lemma root_loss : (1:ℝ)/Real.sqrt 2 < 113/81-17/25 := by + have hr : 0 < Real.sqrt 2 := by positivity + have hs : (Real.sqrt 2)^2=2 := Real.sq_sqrt (by norm_num) + apply (div_lt_iff₀ hr).mpr + nlinarith only [hs, Real.sqrt_nonneg 2] + +lemma J_square_bound (lam mu nu J : ℝ) (h0 : 0 < lam) (h1 : lam < 1) + (hm : 0 ≤ mu) (hn : 0 ≤ nu) (hJ0 : 0 ≤ J) + (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) + (hc : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) : + (8/5:ℝ)*J^2 ≤ (8/5:ℝ)*mu^2-(113/81:ℝ)*lam*mu*nu := by + let q : ℝ := (37/27:ℝ)/(2+lam) + let A := lam*q*nu + have hq := q_lower lam h0.le h1.le + change (37/81:ℝ) ≤ q at hq + have hA0 : 0 ≤ A := by dsimp only [A]; positivity + have hAc : 8*(37/27:ℝ)*A ≤ mu := by + have hh := mul_le_mul_of_nonneg_right (sq_nonneg ((37/27:ℝ)-2*lam*q)) hn + dsimp only [A,q] at * + nlinarith only [hh,hc] + have hA : A ≤ (27/296:ℝ)*mu := by linarith only [hAc] + have hs := mul_le_mul_of_nonneg_right hA hA0 + change J ≤ mu-A at hJ + have hj2 : J^2 ≤ (mu-A)^2 := (sq_le_sq₀ hJ0 (hJ0.trans hJ)).mpr hJ + have hqmu := mul_le_mul_of_nonneg_right hq (show 0 ≤ lam*mu*nu by positivity) + have hlead : mu*A = q*(lam*mu*nu) := by dsimp only [A]; ring + rw [← hlead] at hqmu + nlinarith only [hj2,hs,hqmu] + +lemma scalar_from_moments (lam mu nu J s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) + (hm : 0 < mu) (hn : 0 ≤ nu) (hs0 : 0 < s) (_ : s ≤ 1) + (hsecond : mu^2 ≤ s*nu) + (hcnu : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) + (hJ0 : 0 ≤ J) (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) + (hentropy : (1-lam^2)/2*nu+3*mu^2/(2*(1+2*mu/3))-lam*mu*nu/Real.sqrt 2 ≤ (8/5:ℝ)*J^2) : + 8/5 ≥ (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s) := by + have hj2 := J_square_bound lam mu nu J h0 h1 hm.le hn hJ0 hJ hcnu + have hroot := mul_le_mul_of_nonneg_right root_loss.le (show 0 ≤ lam*mu*nu by positivity) + have he : ((1-lam^2)/2+17*lam*mu/25)*nu+3*mu^2/(2*(1+2*mu/3)) ≤ (8/5:ℝ)*mu^2 := by + simp only [div_eq_mul_inv] at hentropy hj2 hroot ⊢ + nlinarith only [hentropy,hj2,hroot] + have ha : 0 ≤ (1-lam^2)/2+17*lam*mu/25 := by + have hh : 0 ≤ 1-lam^2 := by nlinarith + positivity + have hh := mul_le_mul_of_nonneg_left ((div_le_iff₀ hs0).mpr (show mu^2 ≤ nu*s by nlinarith only [hsecond])) ha + have hneed : ((1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+17*lam*mu/(25*s))*mu^2 ≤ (8/5:ℝ)*mu^2 := by + simp only [div_eq_mul_inv, mul_inv_rev] at he hh ⊢ + nlinarith only [he,hh] + exact (mul_le_mul_iff_left₀ (sq_pos_of_pos hm)).mp hneed + +lemma moment_scalar_contradiction (lam mu nu J s : ℝ) (h0 : 0 < lam) (h1 : lam < 1) + (hm : 0 < mu) (hn : 0 ≤ nu) (hs0 : 0 < s) (hs1 : s ≤ 1) + (hsecond : mu^2 ≤ s*nu) + (hcnu : ((37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)))^2*nu ≤ mu) + (hJ0 : 0 ≤ J) (hJ : J ≤ mu-lam*((37/27:ℝ)/(2+lam))*nu) + (hentropy : (1-lam^2)/2*nu+3*mu^2/(2*(1+2*mu/3))-lam*mu*nu/Real.sqrt 2 ≤ (8/5:ℝ)*J^2) + (hsurv : 1/2 < lam^2 → s ≤ 2*(1-lam^2)) : False := by + let c : ℝ := (37/27:ℝ)+2*lam*((37/27:ℝ)/(2+lam)) + have hc : 0 < c := by dsimp only [c]; positivity + have hcL : lowerC lam ≤ c := by + have hh := q_lower lam h0.le h1.le + dsimp only [lowerC,c] + nlinarith only [hh,h0] + have hb : mu*c^2 ≤ s := by + have hh := mul_le_mul_of_nonneg_right hsecond (sq_nonneg c) + have hh' := mul_le_mul_of_nonneg_left hcnu hs0.le + apply (mul_le_mul_iff_left₀ hm).mp + dsimp only [c] at * + nlinarith only [hh,hh'] + have hfalse := scalar_contradiction lam mu c s h0 h1 hm.le hs0 hs1 hcL hb hsurv + have hneed := scalar_from_moments lam mu nu J s h0 h1 hm hn hs0 hs1 hsecond hcnu hJ0 hJ hentropy + linarith only [hfalse,hneed] + +end ThreeState.PositiveScalar + +namespace ThreeState +open Filter Topology + +lemma poisson_sqrt_tangent (d lam t : ℝ) (_ : 0 (3*lam^4*mu^2/D^2)*((2*D-1)*t^2/2-(lam^2*mu)*t^3/3)- + (lam^5*mu*nu/Real.sqrt 2)*(t^2/2+d*t/2) + let P' := fun t : ℝ => (3*lam^4*mu^2/D^2)*((2*D-1)*t-(lam^2*mu)*t^2)- + (lam^5*mu*nu/Real.sqrt 2)*(t+d/2) + have hp (t : ℝ) : HasDerivAt P (P' t) t := by + have hh := (((((hasDerivAt_pow 2 t).const_mul (2*D-1)).div_const 2).sub + (((hasDerivAt_pow 3 t).const_mul (lam^2*mu)).div_const 3)).const_mul (3*lam^4*mu^2/D^2)).sub + ((((hasDerivAt_pow 2 t).div_const 2).add (((hasDerivAt_id t).const_mul d).div_const 2)).const_mul (lam^5*mu*nu/Real.sqrt 2)) + convert hh using 1 <;> try rfl + dsimp only [P'] + ring + have hpd (t : ℝ) (ht : t ∈ Set.Icc 0 d) : P' t ≤ 3*C t := by + have hr := mul_le_mul_of_nonneg_left (poisson_reciprocal_tangent t (lam^2*mu) D ht.1 (by positivity) hD) + (show 0≤3*lam^4*mu^2 by positivity) + have hs := mul_le_mul_of_nonneg_left (poisson_sqrt_tangent d lam t hd hl ht.1 hc) + (show 0≤lam^4*mu*nu by positivity) + calc + P' t = 3*lam^4*mu^2*(t*(2*D-1-(lam^2*mu)*t)/D^2)-lam^4*mu*nu*(lam*(t+d/2)/Real.sqrt 2) := by dsimp only [P']; ring + _ ≤ 3*lam^4*mu^2*(t/(1+(lam^2*mu)*t))-lam^4*mu*nu*Real.sqrt t := sub_le_sub hr hs + _ = 3*lam^4*mu^2*t/(1+t*lam^2*mu)-lam^4*mu*nu*Real.sqrt t := by ring + _ ≤ _ := hlower t ht + have hmono : MonotoneOn (fun t => 3*H t-P t) (Set.Icc 0 d) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 d) (f' := fun t => 3*C t-P' t) + · intro t ht + exact (((hderiv t ht).const_mul 3).sub (hp t)).continuousAt.continuousWithinAt + · intro t ht + exact (((hderiv t (interior_subset ht)).const_mul 3).sub (hp t)).hasDerivWithinAt + · intro t ht + exact sub_nonneg.mpr (hpd t (interior_subset ht)) + have hh := hmono (show (0:ℝ)∈Set.Icc 0 d from ⟨le_rfl,hd.le⟩) (show d∈Set.Icc 0 d from ⟨hd.le,le_rfl⟩) hd.le + have hp0 : P 0=0 := by simp [P] + have hpend : P d=3*mu^2/(2*D)-lam*mu*nu/Real.sqrt 2 := by + have hd2 : d^2*lam^4=1 := by nlinarith [sq_nonneg (d*lam^2-1)] + have hd3 : d^3*lam^6=1 := by + calc + _ = (d*lam^2)^3 := by ring + _ = 1 := by rw [hc]; norm_num + dsimp only [P] + field_simp [ne_of_gt hD] + dsimp only [D] + nlinarith only [congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^2) hd2, + congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^3) hd2, + congrArg (fun x : ℝ => x*(Real.sqrt 2)*mu^3) hd3, + congrArg (fun x : ℝ => x*lam*mu*nu) hd2, + congrArg (fun x : ℝ => x*lam*mu^2*nu) hd2, + congrArg (fun x : ℝ => x*lam*mu^3*nu) hd2] + change 3*H 0-P 0 ≤ 3*H d-P d at hh + rw [hH0,hp0,hpend] at hh + dsimp only [D] at hh + linarith + +end ThreeState + +namespace ThreeState +open Filter Topology + +lemma log_survival_bound (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s < 1) : + 2*s/(2-s) ≤ -Real.log (1-s) := by + let F := fun x : ℝ => -Real.log (1-x)-2*x/(2-x) + have hd (x : ℝ) (hx : x ∈ Set.Icc 0 s) : HasDerivAt F + (1/(1-x)-4/(2-x)^2) x := by + have h1 : 1-x ≠ 0 := by linarith [hx.2] + have h2 : 2-x ≠ 0 := by linarith [hx.2] + convert (((hasDerivAt_const x (1:ℝ)).sub (hasDerivAt_id x)).log h1).neg.sub + (((hasDerivAt_id x).const_mul 2).div ((hasDerivAt_const x (2:ℝ)).sub (hasDerivAt_id x)) h2) using 1 <;> try rfl + dsimp + field_simp + ring + have hder (x : ℝ) (hx : x ∈ Set.Icc 0 s) : 0 ≤ 1/(1-x)-4/(2-x)^2 := by + have h1 : 0 < 1-x := by linarith [hx.2] + have h2 : 0 < 2-x := by linarith [hx.2] + apply sub_nonneg.mpr + apply (div_le_div_iff₀ (sq_pos_of_pos h2) h1).mpr + nlinarith [sq_nonneg x] + have hmono : MonotoneOn F (Set.Icc 0 s) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 s) + (f' := fun x => 1/(1-x)-4/(2-x)^2) + · intro x hx; exact (hd x hx).continuousAt.continuousWithinAt + · intro x hx; exact (hd x (interior_subset hx)).hasDerivWithinAt + · intro x hx; exact hder x (interior_subset hx) + have hh := hmono (show (0:ℝ)∈Set.Icc 0 s from ⟨le_rfl,hs0⟩) (show s∈Set.Icc 0 s from ⟨hs0,le_rfl⟩) hs0 + dsimp only [F] at hh + norm_num at hh + linarith + +lemma poisson_support_bound (d s : ℝ) (hd : 0 < d) (hs : 0 < s) + (hfp : Real.exp (-d*s) ≤ 1-s) : s ≤ 2*(1-d⁻¹) := by + have hs1 : s < 1 := by linarith [Real.exp_pos (-d*s)] + have hlog := Real.log_le_log (Real.exp_pos (-d*s)) hfp + rw [Real.log_exp] at hlog + have hh := log_survival_bound s hs.le hs1 + have hden : 0 < 2-s := by linarith + have hrat : 2*s/(2-s) ≤ d*s := by linarith + have hr := (div_le_iff₀ hden).mp hrat + have hsd : 2 ≤ d*(2-s) := (mul_le_mul_iff_right₀ hs).mp (by nlinarith only [hr]) + apply (mul_le_mul_iff_left₀ hd).mp + have he : (2*(1-d⁻¹))*d=2*d-2 := by field_simp + rw [he] + nlinarith only [hsd] +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical +noncomputable section + +lemma bernoulli_lower (t:ℝ) (ht0:0≤t) (ht1:t≤1) (k:ℕ) : 1-k*t≤(1-t)^k := by + induction k with + | zero => simp + | succ k ih => + have hh:=mul_le_mul_of_nonneg_right ih (by linarith : 0≤1-t) + rw [pow_succ (1-t) k,Nat.cast_succ] + nlinarith [mul_nonneg (Nat.cast_nonneg (α:=ℝ) k) (mul_nonneg ht0 ht0)] + +lemma bernoulli_quadratic_lower (t:ℝ) (ht0:0≤t) (ht1:t≤1) (k:ℕ) (hk:2≤k) : + 1-k*t+t^2≤(1-t)^k := by + induction k,hk using Nat.le_induction with + | base => norm_num;ring_nf;exact le_refl _ + | succ k hk ih => + have hh:=mul_le_mul_of_nonneg_right ih (by linarith : 0≤1-t) + have hkr:(2:ℝ)≤k:=by exact_mod_cast hk + have hp:=mul_nonneg (show 0≤(k:ℝ)-t by linarith) (show 0≤t^2 by exact pow_nonneg ht0 2) + rw [pow_succ (1-t) k,Nat.cast_succ] + nlinarith + + +def decaySeq (c:ℝ) : ℕ→ℝ + | 0=>1 + | n+1=>decaySeq c n-c*(decaySeq c n)^2 +lemma decaySeq_bounds (c:ℝ) (hc0:0≤c) (hc1:c≤1) (n:ℕ) : + 0≤decaySeq c n ∧ decaySeq c n≤1 := by + induction n with + | zero => simp [decaySeq] + | succ n ih => + have hp:0≤c*(decaySeq c n)^2:=mul_nonneg hc0 (sq_nonneg _) + have ht:c*decaySeq c n≤1:=(mul_le_mul_of_nonneg_right hc1 ih.1).trans (by simpa using ih.2) + have hh:=mul_nonneg ih.1 (show 0≤1-c*decaySeq c n by linarith) + simp only [decaySeq] + constructor <;> nlinarith +lemma decaySeq_antitone (c:ℝ) (hc:0≤c) : Antitone (decaySeq c) := + antitone_nat_of_succ_le (fun n=>by dsimp [decaySeq];nlinarith [mul_nonneg hc (sq_nonneg (decaySeq c n))]) +lemma decaySeq_tendsto (c:ℝ) (hc:0decaySeq c (n+1)) atTop (𝓝 L):=hl.comp (Filter.tendsto_add_atTop_nat 1) + have hrec:Tendsto (fun n=>decaySeq c (n+1)) atTop (𝓝 (L-c*L^2)):=hl.sub (tendsto_const_nhds.mul (hl.pow 2)) + have he:L=L-c*L^2:=tendsto_nhds_unique hl' hrec + have hzero:c*L^2=0:=by linarith + have hz:L=0:= (eq_zero_of_pow_eq_zero ((mul_eq_zero.mp hzero).resolve_left hc.ne')) + have hlast:Tendsto (decaySeq c) atTop (𝓝 L):=hl + rwa [hz] at hlast +end +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Supercritical.lean b/lean/OAI/Probability/ThreeState/Supercritical.lean index 95ddeb6ab3daf44ed0e86593cfb2a8e32aaca5f1..db425d942267c4424d32576e24cea60e7f5e9c63 100644 --- a/lean/OAI/Probability/ThreeState/Supercritical.lean +++ b/lean/OAI/Probability/ThreeState/Supercritical.lean @@ -1,373 +1,373 @@ -import Mathlib -import OAI.Probability.ThreeState.Observation - -namespace OAI - -/-! Boundary score moments and reconstruction above the Kesten–Stigum threshold. -/ - -namespace ThreeState - -noncomputable def listScore {α : Type*} (f : α → ℝ) (as : List α) : ℝ := (as.map f).sum -noncomputable def multisetScore {α : Type*} (f : α → ℝ) (as : Multiset α) : ℝ := (as.map f).sum - -lemma listScore_cons {α : Type*} (f : α → ℝ) (a : α) (as : List α) : - listScore f (a::as) = f a+listScore f as := by simp [listScore] - -lemma multisetScore_coe {α : Type*} (f : α → ℝ) (as : List α) : - multisetScore f (as : Multiset α) = listScore f as := by - simp [multisetScore, listScore] - -lemma iidList_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} - (h : Moments p f m s) (n : ℕ) : - Moments (iidList p n) (listScore f) - ((n:ℝ)*m) ((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2) := by - induction n with - | zero => simpa [iidList, listScore] using Moments.pure ([] : List α) (listScore f) - | succ n ih => - have hi := Moments.independent_add h ih - have hm := Moments.map (g := fun ab : α × List α => ab.1::ab.2) (f := listScore f) hi - simp only [PMF.map_bind, PMF.map_comp, Function.comp_def] at hm - change Moments (iidList p (n+1)) (listScore f) - (m+(n:ℝ)*m) (s+2*m*((n:ℝ)*m)+((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2)) at hm - convert hm using 1 <;> push_cast <;> ring - -lemma iidMultiset_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} - (h : Moments p f m s) (n : ℕ) : - Moments ((iidList p n).map (fun as : List α => (as : Multiset α))) (multisetScore f) - ((n:ℝ)*m) ((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2) := by - apply Moments.map (g := fun as : List α => (as : Multiset α)) - simpa only [multisetScore_coe] using iidList_moments h n - - - -lemma compound_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s d e : ℝ} - {offspring : PMF ℕ} (hp : Moments p f m s) - (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) : - Moments (offspring.bind (fun k => - (iidList p k).map (fun as : List α => (as : Multiset α)))) (multisetScore f) - (d*m) (d*s+e*m^2) := by - apply Moments.bind (fun k => iidMultiset_moments hp k) - · exact ((hD.hasMean.mul_const s).add ((hD.square.sub hD.hasMean).mul_const (m^2))).congr - (fun k => by ring) - · rw [mean_mul_const, hD.first] - · rw [mean_congr offspring (g := fun k => (k:ℝ)*s+((k:ℝ)^2-(k:ℝ))*m^2) (fun k => by ring), - mean_add (hD.hasMean.mul_const s) ((hD.square.sub hD.hasMean).mul_const (m^2)), - mean_mul_const, mean_mul_const, mean_sub hD.square hD.hasMean, hD.first, hD.second] - ring - - - -def spinScore (i : Spin) : ℝ := if i=0 then 2 else -1 - -noncomputable def boundaryScore : (n : ℕ) → Observation n → ℝ - | 0 => spinScore - | n+1 => multisetScore (boundaryScore n) - -lemma mass_channel (lam : ℝ) (h : Admissible lam) (i j : Spin) : - mass (channelPMF lam h i) j = channel lam i j := by - exact ENNReal.toReal_ofReal (channel_nonneg h i j) - -lemma channel_score (lam : ℝ) (h : Admissible lam) (i : Spin) : - mean (channelPMF lam h i) spinScore = lam*spinScore i := by - rw [mean_fintype] - simp only [mass_channel] - fin_cases i <;> simp [Fin.sum_univ_succ, channel, spinScore] <;> ring - -noncomputable def scoreSecond (d e lam : ℝ) (h : Admissible lam) : ℕ → Spin → ℝ - | 0, i => (spinScore i)^2 - | n+1, i => d*mean (channelPMF lam h i) (scoreSecond d e lam h n) + - e*((d*lam)^n*lam*spinScore i)^2 - - -theorem boundaryScore_moments (offspring : PMF ℕ) (d e lam : ℝ) (h : Admissible lam) - (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) (n : ℕ) (i : Spin) : - Moments (observedLaw offspring lam h n i) (boundaryScore n) - ((d*lam)^n*spinScore i) (scoreSecond d e lam h n i) := by - induction n generalizing i with - | zero => - change Moments (PMF.pure i) spinScore ((d*lam)^0*spinScore i) ((spinScore i)^2) - simpa only [pow_zero, one_mul] using Moments.pure i spinScore - | succ n ih => - have hedge : Moments ((channelPMF lam h i).bind (observedLaw offspring lam h n)) - (boundaryScore n) ((d*lam)^n*lam*spinScore i) - (mean (channelPMF lam h i) (scoreSecond d e lam h n)) := by - apply Moments.bind ih (hasMean_fintype _ _) ?_ rfl - rw [mean_const_mul, channel_score] - ring - have hh := compound_moments hedge hD - change Moments (observedLaw offspring lam h (n+1) i) (boundaryScore (n+1)) - (d*((d*lam)^n*lam*spinScore i)) (scoreSecond d e lam h (n+1) i) at hh - convert hh using 1 - rw [pow_succ] - ring - -lemma hasMean_marginal {α : Type*} {law : Spin → PMF α} {f : α → ℝ} - (h : ∀ i, HasMean (law i) f) : HasMean (marginal law) f := - HasMean.bind h (hasMean_fintype _ _) - -lemma mean_uniform (f : Spin → ℝ) : mean uniformSpin f = (∑ i : Spin, f i)/3 := by - rw [mean_fintype] - simp only [mass_uniform, ← Finset.mul_sum] - ring - -lemma mean_marginal {α : Type*} {law : Spin → PMF α} {f : α → ℝ} - (h : ∀ i, HasMean (law i) f) : - mean (marginal law) f = mean uniformSpin (fun i => mean (law i) f) := - mean_bind h (hasMean_fintype _ _) - -lemma mean_uniform_spinScore : mean uniformSpin spinScore = 0 := by - simp [mean_uniform, Fin.sum_univ_succ, spinScore] - -lemma mean_uniform_spinScore_square : mean uniformSpin (fun i => (spinScore i)^2) = 2 := by - norm_num [mean_uniform, Fin.sum_univ_succ, spinScore] - -lemma mean_uniform_channel (lam : ℝ) (h : Admissible lam) (f : Spin → ℝ) : - mean uniformSpin (fun i => mean (channelPMF lam h i) f) = mean uniformSpin f := by - simp [mean_fintype, mass_uniform, mass_channel, Fin.sum_univ_succ, channel] - ring - -lemma pow_square_comm (a : ℝ) (n : ℕ) : (a^n)^2 = (a^2)^n := by - rw [← pow_mul, ← pow_mul, Nat.mul_comm n 2] - -lemma scoreSecond_average_zero (d e lam : ℝ) (h : Admissible lam) : - mean uniformSpin (scoreSecond d e lam h 0) = 2 := mean_uniform_spinScore_square - -lemma scoreSecond_average_succ (d e lam : ℝ) (h : Admissible lam) (n : ℕ) : - mean uniformSpin (scoreSecond d e lam h (n+1)) = - d*mean uniformSpin (scoreSecond d e lam h n)+2*e*lam^2*((d*lam)^2)^n := by - change mean uniformSpin (fun i => - d*mean (channelPMF lam h i) (scoreSecond d e lam h n) + - e*((d*lam)^n*lam*spinScore i)^2) = _ - rw [mean_add (hasMean_fintype _ _) (hasMean_fintype _ _), mean_const_mul, - mean_uniform_channel] - congr 1 - rw [mean_congr uniformSpin (g := fun i => (e*lam^2*((d*lam)^2)^n)*(spinScore i)^2) - (fun i => by rw [mul_pow, mul_pow, pow_square_comm]; ring), mean_const_mul, - mean_uniform_spinScore_square] - ring - - - -lemma scoreSecond_bound (d e lam C : ℝ) (h : Admissible lam) - (hd : 0 ≤ d) (hC : 2 ≤ C) (hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2) (n : ℕ) : - mean uniformSpin (scoreSecond d e lam h n) ≤ C*((d*lam)^2)^n := by - induction n with - | zero => simpa only [scoreSecond_average_zero, pow_zero, mul_one] using hC - | succ n ih => - rw [scoreSecond_average_succ, pow_succ ((d*lam)^2) n] - have h1 := mul_le_mul_of_nonneg_left ih hd - have h2 := mul_le_mul_of_nonneg_right hstep (pow_nonneg (sq_nonneg (d*lam)) n) - nlinarith - -lemma boundaryScore_marginal_moments (offspring : PMF ℕ) (d e lam : ℝ) (h : Admissible lam) - (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) (n : ℕ) : - Moments (marginal (observedLaw offspring lam h n)) (boundaryScore n) 0 - (mean uniformSpin (scoreSecond d e lam h n)) := by - apply Moments.bind (fun i => boundaryScore_moments offspring d e lam h hD n i) - (hasMean_fintype _ _) ?_ rfl - rw [mean_const_mul, mean_uniform_spinScore, mul_zero] - -end ThreeState - -namespace ThreeState - -lemma HasMean.mul_of_square {α : Type*} {p : PMF α} {f g : α → ℝ} - (hf : HasMean p (fun a => (f a)^2)) (hg : HasMean p (fun a => (g a)^2)) : - HasMean p (fun a => f a*g a) := by - apply HasMean.of_abs - apply ((hf.add hg).mul_const (1/2)).mono (fun a => abs_nonneg _) - intro a - rw [abs_mul] - nlinarith [sq_nonneg (|f a|-|g a|), sq_abs (f a), sq_abs (g a)] - - -lemma mean_cauchy_square {α : Type*} {p : PMF α} {f g : α → ℝ} - (hf : HasMean p (fun a => (f a)^2)) (hg : HasMean p (fun a => (g a)^2)) : - (mean p (fun a => f a*g a))^2 ≤ - mean p (fun a => (f a)^2)*mean p (fun a => (g a)^2) := by - have hfg := hf.mul_of_square hg - have hp (t : ℝ) : 0 ≤ mean p (fun a => (g a)^2)*(t*t) + - (-2*mean p (fun a => f a*g a))*t + mean p (fun a => (f a)^2) := by - have hn := mean_nonneg p (fun a => sq_nonneg (f a-t*g a)) - have he : mean p (fun a => (f a-t*g a)^2) = - mean p (fun a => (g a)^2)*(t*t) + - (-2*mean p (fun a => f a*g a))*t + mean p (fun a => (f a)^2) := by - rw [mean_congr p (g := fun a => (g a)^2*(t*t)+(f a*g a)*(-2*t)+(f a)^2) - (fun a => by ring), - mean_add ((hg.mul_const (t*t)).add (hfg.mul_const (-2*t))) hf, - mean_add (hg.mul_const (t*t)) (hfg.mul_const (-2*t)), mean_mul_const, mean_mul_const] - ring - rwa [he] at hn - have hd := discrim_le_zero hp - dsimp [discrim] at hd - nlinarith - -lemma posterior_le_one {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : - posterior law y i ≤ 1 := by - have h := Finset.single_le_sum (fun j (_ : j ∈ Finset.univ) => posterior_nonneg law y j) - (Finset.mem_univ i) - simpa only [posterior_sum] using h - -noncomputable def posteriorTV {α : Type*} (law : Spin → PMF α) (y : α) : ℝ := - (∑ i : Spin, |posterior law y i-1/3|)/2 - -lemma posteriorTV_nonneg {α : Type*} (law : Spin → PMF α) (y : α) : - 0 ≤ posteriorTV law y := by - exact div_nonneg (Finset.sum_nonneg (fun i _ => abs_nonneg _)) (by norm_num) - -lemma posteriorTV_le_two {α : Type*} (law : Spin → PMF α) (y : α) : - posteriorTV law y ≤ 2 := by - have hh (i : Spin) : |posterior law y i-1/3| ≤ 1 := by - rw [abs_le] - constructor <;> linarith [posterior_nonneg law y i, posterior_le_one law y i] - have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hh i) - norm_num at h - dsimp [posteriorTV] - linarith - -lemma hasMean_posteriorTV {α : Type*} (law : Spin → PMF α) : - HasMean (marginal law) (posteriorTV law) := - (hasMean_const (marginal law) 2).mono (posteriorTV_nonneg law) (posteriorTV_le_two law) - -lemma mean_posteriorTV {α : Type*} (law : Spin → PMF α) : - mean (marginal law) (posteriorTV law) = advantage law := rfl - -noncomputable def posteriorScore {α : Type*} (law : Spin → PMF α) (y : α) : ℝ := - 3*posterior law y 0-1 - -lemma posteriorScore_square_le {α : Type*} (law : Spin → PMF α) (y : α) : - (posteriorScore law y)^2 ≤ 12*posteriorTV law y := by - have hn := posterior_nonneg law y 0 - have hu := posterior_le_one law y 0 - have hr : |posteriorScore law y| ≤ 2 := by - rw [abs_le] - dsimp [posteriorScore] - constructor <;> linarith - have he : |posteriorScore law y| = 3*|posterior law y 0-1/3| := by - rw [show posteriorScore law y = 3*(posterior law y 0-1/3) by dsimp [posteriorScore]; ring, abs_mul] - norm_num - have h0 := Finset.single_le_sum (fun i (_ : i ∈ Finset.univ) => abs_nonneg (posterior law y i-1/3)) - (Finset.mem_univ (0:Spin)) - dsimp [posteriorTV] - nlinarith [sq_abs (posteriorScore law y), - mul_nonneg (abs_nonneg (posteriorScore law y)) (sub_nonneg.mpr hr)] - -lemma hasMean_posteriorScore_square {α : Type*} (law : Spin → PMF α) : - HasMean (marginal law) (fun y => (posteriorScore law y)^2) := - ((hasMean_posteriorTV law).const_mul 12).mono - (fun y => sq_nonneg (posteriorScore law y)) (posteriorScore_square_le law) - -lemma mean_posteriorScore_square_le {α : Type*} (law : Spin → PMF α) : - mean (marginal law) (fun y => (posteriorScore law y)^2) ≤ 12*advantage law := by - have h := mean_le (hasMean_posteriorScore_square law) ((hasMean_posteriorTV law).const_mul 12) - (posteriorScore_square_le law) - simpa only [mean_const_mul, mean_posteriorTV] using h - -lemma weighted_posteriorScore {α : Type*} (law : Spin → PMF α) (y : α) : - mass (marginal law) y*posteriorScore law y = mass (law 0) y-mass (marginal law) y := by - have h := weighted_posterior law y 0 - dsimp [posteriorScore] - linarith - -lemma mean_score_correlation {α : Type*} (law : Spin → PMF α) (f : α → ℝ) - (h0 : HasMean (law 0) f) (hm : HasMean (marginal law) f) : - mean (marginal law) (fun y => posteriorScore law y*f y) = mean (law 0) f-mean (marginal law) f := by - unfold mean - rw [← h0.tsum_sub hm] - apply tsum_congr - intro y - rw [← mul_assoc, weighted_posteriorScore] - ring - - - -theorem advantage_lower_from_score {α : Type*} (law : Spin → PMF α) (f : α → ℝ) - (h0 : HasMean (law 0) f) (hf : HasMean (marginal law) (fun y => (f y)^2)) : - (mean (law 0) f-mean (marginal law) f)^2 ≤ - 12*advantage law*mean (marginal law) (fun y => (f y)^2) := by - have h := mean_cauchy_square (hasMean_posteriorScore_square law) hf - rw [mean_score_correlation law f h0 (hasMean_of_square hf)] at h - exact h.trans (mul_le_mul_of_nonneg_right (mean_posteriorScore_square_le law) - (mean_nonneg _ (fun y => sq_nonneg _))) - -end ThreeState - -namespace ThreeState - - - -lemma supercritical_advantage_bound (offspring : PMF ℕ) (d e lam C : ℝ) - (h : Admissible lam) (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) - (hd : 0 ≤ d) (hq : 0 < (d*lam)^2) (hC : 2 ≤ C) - (hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2) (n : ℕ) : - 1/(3*C) ≤ advantage (observedLaw offspring lam h n) := by - have hm := boundaryScore_marginal_moments offspring d e lam h hD n - have h0 := boundaryScore_moments offspring d e lam h hD n (0:Spin) - have hc := advantage_lower_from_score (observedLaw offspring lam h n) (boundaryScore n) - h0.hasMean hm.square - rw [h0.first, hm.first, hm.second] at hc - have hs := scoreSecond_bound d e lam C h hd hC hstep n - have ha := advantage_nonneg (observedLaw offspring lam h n) - have hp := pow_pos hq n - have hu := mul_le_mul_of_nonneg_left hs (mul_nonneg (by norm_num : (0:ℝ) ≤ 12) ha) - have he : (((d*lam)^n*spinScore (0:Spin))-0)^2 = 4*((d*lam)^2)^n := by - simp only [spinScore, ↓reduceIte, sub_zero, mul_pow, pow_square_comm] - ring - rw [he] at hc - have hh : (4:ℝ)*((d*lam)^2)^n ≤ - (12*C*advantage (observedLaw offspring lam h n))*((d*lam)^2)^n := by - calc - _ ≤ 12*advantage (observedLaw offspring lam h n) * - (C*((d*lam)^2)^n) := hc.trans hu - _ = _ := by ring - have hh' := (mul_le_mul_iff_left₀ hp).mp hh - apply (div_le_iff₀ (show 0 < 3*C by linarith)).mpr - nlinarith - - - -theorem reconstructs_supercritical_of_moments (offspring : PMF ℕ) (d e lam : ℝ) - (h : Admissible lam) (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) - (hd : 0 < d) (he : 0 ≤ e) (hcrit : 1 < d*lam^2) : - Reconstructs (fun n => advantage (observedLaw offspring lam h n)) := by - have hgap : 0 < (d*lam)^2-d := by - have hp := mul_pos hd (sub_pos.mpr hcrit) - nlinarith - have hq : 0 < (d*lam)^2 := by linarith - let C : ℝ := 2+2*e*lam^2/((d*lam)^2-d) - have hC : 2 ≤ C := by - dsimp [C] - have hh : 0 ≤ 2*e*lam^2/((d*lam)^2-d) := by positivity - linarith - have hCpos : 0 < C := by linarith - have hCeq : C*((d*lam)^2-d) = 2*((d*lam)^2-d)+2*e*lam^2 := by - dsimp [C] - rw [add_mul, div_mul_cancel₀ _ (ne_of_gt hgap)] - have hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2 := by nlinarith - obtain ⟨L,hL0,hL1,hL⟩ := observedAdvantage_tendsto offspring lam h - have hb : 1/(3*C) ≤ L := ge_of_tendsto' hL - (fun n => supercritical_advantage_bound offspring d e lam C h hD hd.le hq hC hstep n) - exact ⟨L, (by positivity : 0 < 1/(3*C)).trans_le hb, hL⟩ - - - -theorem regular_supercritical (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) - (hcrit : 1 < (b:ℝ)*lam^2) : Reconstructs (regularAdvantage b lam h) := by - have hd : 0 < (b:ℝ) := by exact_mod_cast (show 0 < b by omega) - have he : 0 ≤ (b:ℝ)^2-(b:ℝ) := by - have hb' : (2:ℝ) ≤ (b:ℝ) := by exact_mod_cast hb - nlinarith - apply reconstructs_supercritical_of_moments (PMF.pure b) (b:ℝ) ((b:ℝ)^2-(b:ℝ)) lam h - ?_ hd he hcrit - simpa only [sub_add_cancel] using regular_moments b - - - -theorem poisson_supercritical (d : ℝ) (hd : 1 < d) (lam : ℝ) (h : Admissible lam) - (hcrit : 1 < d*lam^2) : Reconstructs (poissonAdvantage d hd lam h) := by - apply reconstructs_supercritical_of_moments (poissonOffspring d (le_trans (by norm_num) hd.le)) - d (d^2) lam h (poisson_moments d _) (by linarith) (sq_nonneg d) hcrit - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Observation + +namespace OAI + +/-! Boundary score moments and reconstruction above the Kesten–Stigum threshold. -/ + +namespace ThreeState + +noncomputable def listScore {α : Type*} (f : α → ℝ) (as : List α) : ℝ := (as.map f).sum +noncomputable def multisetScore {α : Type*} (f : α → ℝ) (as : Multiset α) : ℝ := (as.map f).sum + +lemma listScore_cons {α : Type*} (f : α → ℝ) (a : α) (as : List α) : + listScore f (a::as) = f a+listScore f as := by simp [listScore] + +lemma multisetScore_coe {α : Type*} (f : α → ℝ) (as : List α) : + multisetScore f (as : Multiset α) = listScore f as := by + simp [multisetScore, listScore] + +lemma iidList_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} + (h : Moments p f m s) (n : ℕ) : + Moments (iidList p n) (listScore f) + ((n:ℝ)*m) ((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2) := by + induction n with + | zero => simpa [iidList, listScore] using Moments.pure ([] : List α) (listScore f) + | succ n ih => + have hi := Moments.independent_add h ih + have hm := Moments.map (g := fun ab : α × List α => ab.1::ab.2) (f := listScore f) hi + simp only [PMF.map_bind, PMF.map_comp, Function.comp_def] at hm + change Moments (iidList p (n+1)) (listScore f) + (m+(n:ℝ)*m) (s+2*m*((n:ℝ)*m)+((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2)) at hm + convert hm using 1 <;> push_cast <;> ring + +lemma iidMultiset_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s : ℝ} + (h : Moments p f m s) (n : ℕ) : + Moments ((iidList p n).map (fun as : List α => (as : Multiset α))) (multisetScore f) + ((n:ℝ)*m) ((n:ℝ)*s+(n:ℝ)*((n:ℝ)-1)*m^2) := by + apply Moments.map (g := fun as : List α => (as : Multiset α)) + simpa only [multisetScore_coe] using iidList_moments h n + + + +lemma compound_moments {α : Type*} {p : PMF α} {f : α → ℝ} {m s d e : ℝ} + {offspring : PMF ℕ} (hp : Moments p f m s) + (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) : + Moments (offspring.bind (fun k => + (iidList p k).map (fun as : List α => (as : Multiset α)))) (multisetScore f) + (d*m) (d*s+e*m^2) := by + apply Moments.bind (fun k => iidMultiset_moments hp k) + · exact ((hD.hasMean.mul_const s).add ((hD.square.sub hD.hasMean).mul_const (m^2))).congr + (fun k => by ring) + · rw [mean_mul_const, hD.first] + · rw [mean_congr offspring (g := fun k => (k:ℝ)*s+((k:ℝ)^2-(k:ℝ))*m^2) (fun k => by ring), + mean_add (hD.hasMean.mul_const s) ((hD.square.sub hD.hasMean).mul_const (m^2)), + mean_mul_const, mean_mul_const, mean_sub hD.square hD.hasMean, hD.first, hD.second] + ring + + + +def spinScore (i : Spin) : ℝ := if i=0 then 2 else -1 + +noncomputable def boundaryScore : (n : ℕ) → Observation n → ℝ + | 0 => spinScore + | n+1 => multisetScore (boundaryScore n) + +lemma mass_channel (lam : ℝ) (h : Admissible lam) (i j : Spin) : + mass (channelPMF lam h i) j = channel lam i j := by + exact ENNReal.toReal_ofReal (channel_nonneg h i j) + +lemma channel_score (lam : ℝ) (h : Admissible lam) (i : Spin) : + mean (channelPMF lam h i) spinScore = lam*spinScore i := by + rw [mean_fintype] + simp only [mass_channel] + fin_cases i <;> simp [Fin.sum_univ_succ, channel, spinScore] <;> ring + +noncomputable def scoreSecond (d e lam : ℝ) (h : Admissible lam) : ℕ → Spin → ℝ + | 0, i => (spinScore i)^2 + | n+1, i => d*mean (channelPMF lam h i) (scoreSecond d e lam h n) + + e*((d*lam)^n*lam*spinScore i)^2 + + +theorem boundaryScore_moments (offspring : PMF ℕ) (d e lam : ℝ) (h : Admissible lam) + (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) (n : ℕ) (i : Spin) : + Moments (observedLaw offspring lam h n i) (boundaryScore n) + ((d*lam)^n*spinScore i) (scoreSecond d e lam h n i) := by + induction n generalizing i with + | zero => + change Moments (PMF.pure i) spinScore ((d*lam)^0*spinScore i) ((spinScore i)^2) + simpa only [pow_zero, one_mul] using Moments.pure i spinScore + | succ n ih => + have hedge : Moments ((channelPMF lam h i).bind (observedLaw offspring lam h n)) + (boundaryScore n) ((d*lam)^n*lam*spinScore i) + (mean (channelPMF lam h i) (scoreSecond d e lam h n)) := by + apply Moments.bind ih (hasMean_fintype _ _) ?_ rfl + rw [mean_const_mul, channel_score] + ring + have hh := compound_moments hedge hD + change Moments (observedLaw offspring lam h (n+1) i) (boundaryScore (n+1)) + (d*((d*lam)^n*lam*spinScore i)) (scoreSecond d e lam h (n+1) i) at hh + convert hh using 1 + rw [pow_succ] + ring + +lemma hasMean_marginal {α : Type*} {law : Spin → PMF α} {f : α → ℝ} + (h : ∀ i, HasMean (law i) f) : HasMean (marginal law) f := + HasMean.bind h (hasMean_fintype _ _) + +lemma mean_uniform (f : Spin → ℝ) : mean uniformSpin f = (∑ i : Spin, f i)/3 := by + rw [mean_fintype] + simp only [mass_uniform, ← Finset.mul_sum] + ring + +lemma mean_marginal {α : Type*} {law : Spin → PMF α} {f : α → ℝ} + (h : ∀ i, HasMean (law i) f) : + mean (marginal law) f = mean uniformSpin (fun i => mean (law i) f) := + mean_bind h (hasMean_fintype _ _) + +lemma mean_uniform_spinScore : mean uniformSpin spinScore = 0 := by + simp [mean_uniform, Fin.sum_univ_succ, spinScore] + +lemma mean_uniform_spinScore_square : mean uniformSpin (fun i => (spinScore i)^2) = 2 := by + norm_num [mean_uniform, Fin.sum_univ_succ, spinScore] + +lemma mean_uniform_channel (lam : ℝ) (h : Admissible lam) (f : Spin → ℝ) : + mean uniformSpin (fun i => mean (channelPMF lam h i) f) = mean uniformSpin f := by + simp [mean_fintype, mass_uniform, mass_channel, Fin.sum_univ_succ, channel] + ring + +lemma pow_square_comm (a : ℝ) (n : ℕ) : (a^n)^2 = (a^2)^n := by + rw [← pow_mul, ← pow_mul, Nat.mul_comm n 2] + +lemma scoreSecond_average_zero (d e lam : ℝ) (h : Admissible lam) : + mean uniformSpin (scoreSecond d e lam h 0) = 2 := mean_uniform_spinScore_square + +lemma scoreSecond_average_succ (d e lam : ℝ) (h : Admissible lam) (n : ℕ) : + mean uniformSpin (scoreSecond d e lam h (n+1)) = + d*mean uniformSpin (scoreSecond d e lam h n)+2*e*lam^2*((d*lam)^2)^n := by + change mean uniformSpin (fun i => + d*mean (channelPMF lam h i) (scoreSecond d e lam h n) + + e*((d*lam)^n*lam*spinScore i)^2) = _ + rw [mean_add (hasMean_fintype _ _) (hasMean_fintype _ _), mean_const_mul, + mean_uniform_channel] + congr 1 + rw [mean_congr uniformSpin (g := fun i => (e*lam^2*((d*lam)^2)^n)*(spinScore i)^2) + (fun i => by rw [mul_pow, mul_pow, pow_square_comm]; ring), mean_const_mul, + mean_uniform_spinScore_square] + ring + + + +lemma scoreSecond_bound (d e lam C : ℝ) (h : Admissible lam) + (hd : 0 ≤ d) (hC : 2 ≤ C) (hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2) (n : ℕ) : + mean uniformSpin (scoreSecond d e lam h n) ≤ C*((d*lam)^2)^n := by + induction n with + | zero => simpa only [scoreSecond_average_zero, pow_zero, mul_one] using hC + | succ n ih => + rw [scoreSecond_average_succ, pow_succ ((d*lam)^2) n] + have h1 := mul_le_mul_of_nonneg_left ih hd + have h2 := mul_le_mul_of_nonneg_right hstep (pow_nonneg (sq_nonneg (d*lam)) n) + nlinarith + +lemma boundaryScore_marginal_moments (offspring : PMF ℕ) (d e lam : ℝ) (h : Admissible lam) + (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) (n : ℕ) : + Moments (marginal (observedLaw offspring lam h n)) (boundaryScore n) 0 + (mean uniformSpin (scoreSecond d e lam h n)) := by + apply Moments.bind (fun i => boundaryScore_moments offspring d e lam h hD n i) + (hasMean_fintype _ _) ?_ rfl + rw [mean_const_mul, mean_uniform_spinScore, mul_zero] + +end ThreeState + +namespace ThreeState + +lemma HasMean.mul_of_square {α : Type*} {p : PMF α} {f g : α → ℝ} + (hf : HasMean p (fun a => (f a)^2)) (hg : HasMean p (fun a => (g a)^2)) : + HasMean p (fun a => f a*g a) := by + apply HasMean.of_abs + apply ((hf.add hg).mul_const (1/2)).mono (fun a => abs_nonneg _) + intro a + rw [abs_mul] + nlinarith [sq_nonneg (|f a|-|g a|), sq_abs (f a), sq_abs (g a)] + + +lemma mean_cauchy_square {α : Type*} {p : PMF α} {f g : α → ℝ} + (hf : HasMean p (fun a => (f a)^2)) (hg : HasMean p (fun a => (g a)^2)) : + (mean p (fun a => f a*g a))^2 ≤ + mean p (fun a => (f a)^2)*mean p (fun a => (g a)^2) := by + have hfg := hf.mul_of_square hg + have hp (t : ℝ) : 0 ≤ mean p (fun a => (g a)^2)*(t*t) + + (-2*mean p (fun a => f a*g a))*t + mean p (fun a => (f a)^2) := by + have hn := mean_nonneg p (fun a => sq_nonneg (f a-t*g a)) + have he : mean p (fun a => (f a-t*g a)^2) = + mean p (fun a => (g a)^2)*(t*t) + + (-2*mean p (fun a => f a*g a))*t + mean p (fun a => (f a)^2) := by + rw [mean_congr p (g := fun a => (g a)^2*(t*t)+(f a*g a)*(-2*t)+(f a)^2) + (fun a => by ring), + mean_add ((hg.mul_const (t*t)).add (hfg.mul_const (-2*t))) hf, + mean_add (hg.mul_const (t*t)) (hfg.mul_const (-2*t)), mean_mul_const, mean_mul_const] + ring + rwa [he] at hn + have hd := discrim_le_zero hp + dsimp [discrim] at hd + nlinarith + +lemma posterior_le_one {α : Type*} (law : Spin → PMF α) (y : α) (i : Spin) : + posterior law y i ≤ 1 := by + have h := Finset.single_le_sum (fun j (_ : j ∈ Finset.univ) => posterior_nonneg law y j) + (Finset.mem_univ i) + simpa only [posterior_sum] using h + +noncomputable def posteriorTV {α : Type*} (law : Spin → PMF α) (y : α) : ℝ := + (∑ i : Spin, |posterior law y i-1/3|)/2 + +lemma posteriorTV_nonneg {α : Type*} (law : Spin → PMF α) (y : α) : + 0 ≤ posteriorTV law y := by + exact div_nonneg (Finset.sum_nonneg (fun i _ => abs_nonneg _)) (by norm_num) + +lemma posteriorTV_le_two {α : Type*} (law : Spin → PMF α) (y : α) : + posteriorTV law y ≤ 2 := by + have hh (i : Spin) : |posterior law y i-1/3| ≤ 1 := by + rw [abs_le] + constructor <;> linarith [posterior_nonneg law y i, posterior_le_one law y i] + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hh i) + norm_num at h + dsimp [posteriorTV] + linarith + +lemma hasMean_posteriorTV {α : Type*} (law : Spin → PMF α) : + HasMean (marginal law) (posteriorTV law) := + (hasMean_const (marginal law) 2).mono (posteriorTV_nonneg law) (posteriorTV_le_two law) + +lemma mean_posteriorTV {α : Type*} (law : Spin → PMF α) : + mean (marginal law) (posteriorTV law) = advantage law := rfl + +noncomputable def posteriorScore {α : Type*} (law : Spin → PMF α) (y : α) : ℝ := + 3*posterior law y 0-1 + +lemma posteriorScore_square_le {α : Type*} (law : Spin → PMF α) (y : α) : + (posteriorScore law y)^2 ≤ 12*posteriorTV law y := by + have hn := posterior_nonneg law y 0 + have hu := posterior_le_one law y 0 + have hr : |posteriorScore law y| ≤ 2 := by + rw [abs_le] + dsimp [posteriorScore] + constructor <;> linarith + have he : |posteriorScore law y| = 3*|posterior law y 0-1/3| := by + rw [show posteriorScore law y = 3*(posterior law y 0-1/3) by dsimp [posteriorScore]; ring, abs_mul] + norm_num + have h0 := Finset.single_le_sum (fun i (_ : i ∈ Finset.univ) => abs_nonneg (posterior law y i-1/3)) + (Finset.mem_univ (0:Spin)) + dsimp [posteriorTV] + nlinarith [sq_abs (posteriorScore law y), + mul_nonneg (abs_nonneg (posteriorScore law y)) (sub_nonneg.mpr hr)] + +lemma hasMean_posteriorScore_square {α : Type*} (law : Spin → PMF α) : + HasMean (marginal law) (fun y => (posteriorScore law y)^2) := + ((hasMean_posteriorTV law).const_mul 12).mono + (fun y => sq_nonneg (posteriorScore law y)) (posteriorScore_square_le law) + +lemma mean_posteriorScore_square_le {α : Type*} (law : Spin → PMF α) : + mean (marginal law) (fun y => (posteriorScore law y)^2) ≤ 12*advantage law := by + have h := mean_le (hasMean_posteriorScore_square law) ((hasMean_posteriorTV law).const_mul 12) + (posteriorScore_square_le law) + simpa only [mean_const_mul, mean_posteriorTV] using h + +lemma weighted_posteriorScore {α : Type*} (law : Spin → PMF α) (y : α) : + mass (marginal law) y*posteriorScore law y = mass (law 0) y-mass (marginal law) y := by + have h := weighted_posterior law y 0 + dsimp [posteriorScore] + linarith + +lemma mean_score_correlation {α : Type*} (law : Spin → PMF α) (f : α → ℝ) + (h0 : HasMean (law 0) f) (hm : HasMean (marginal law) f) : + mean (marginal law) (fun y => posteriorScore law y*f y) = mean (law 0) f-mean (marginal law) f := by + unfold mean + rw [← h0.tsum_sub hm] + apply tsum_congr + intro y + rw [← mul_assoc, weighted_posteriorScore] + ring + + + +theorem advantage_lower_from_score {α : Type*} (law : Spin → PMF α) (f : α → ℝ) + (h0 : HasMean (law 0) f) (hf : HasMean (marginal law) (fun y => (f y)^2)) : + (mean (law 0) f-mean (marginal law) f)^2 ≤ + 12*advantage law*mean (marginal law) (fun y => (f y)^2) := by + have h := mean_cauchy_square (hasMean_posteriorScore_square law) hf + rw [mean_score_correlation law f h0 (hasMean_of_square hf)] at h + exact h.trans (mul_le_mul_of_nonneg_right (mean_posteriorScore_square_le law) + (mean_nonneg _ (fun y => sq_nonneg _))) + +end ThreeState + +namespace ThreeState + + + +lemma supercritical_advantage_bound (offspring : PMF ℕ) (d e lam C : ℝ) + (h : Admissible lam) (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) + (hd : 0 ≤ d) (hq : 0 < (d*lam)^2) (hC : 2 ≤ C) + (hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2) (n : ℕ) : + 1/(3*C) ≤ advantage (observedLaw offspring lam h n) := by + have hm := boundaryScore_marginal_moments offspring d e lam h hD n + have h0 := boundaryScore_moments offspring d e lam h hD n (0:Spin) + have hc := advantage_lower_from_score (observedLaw offspring lam h n) (boundaryScore n) + h0.hasMean hm.square + rw [h0.first, hm.first, hm.second] at hc + have hs := scoreSecond_bound d e lam C h hd hC hstep n + have ha := advantage_nonneg (observedLaw offspring lam h n) + have hp := pow_pos hq n + have hu := mul_le_mul_of_nonneg_left hs (mul_nonneg (by norm_num : (0:ℝ) ≤ 12) ha) + have he : (((d*lam)^n*spinScore (0:Spin))-0)^2 = 4*((d*lam)^2)^n := by + simp only [spinScore, ↓reduceIte, sub_zero, mul_pow, pow_square_comm] + ring + rw [he] at hc + have hh : (4:ℝ)*((d*lam)^2)^n ≤ + (12*C*advantage (observedLaw offspring lam h n))*((d*lam)^2)^n := by + calc + _ ≤ 12*advantage (observedLaw offspring lam h n) * + (C*((d*lam)^2)^n) := hc.trans hu + _ = _ := by ring + have hh' := (mul_le_mul_iff_left₀ hp).mp hh + apply (div_le_iff₀ (show 0 < 3*C by linarith)).mpr + nlinarith + + + +theorem reconstructs_supercritical_of_moments (offspring : PMF ℕ) (d e lam : ℝ) + (h : Admissible lam) (hD : Moments offspring (fun k : ℕ => (k:ℝ)) d (e+d)) + (hd : 0 < d) (he : 0 ≤ e) (hcrit : 1 < d*lam^2) : + Reconstructs (fun n => advantage (observedLaw offspring lam h n)) := by + have hgap : 0 < (d*lam)^2-d := by + have hp := mul_pos hd (sub_pos.mpr hcrit) + nlinarith + have hq : 0 < (d*lam)^2 := by linarith + let C : ℝ := 2+2*e*lam^2/((d*lam)^2-d) + have hC : 2 ≤ C := by + dsimp [C] + have hh : 0 ≤ 2*e*lam^2/((d*lam)^2-d) := by positivity + linarith + have hCpos : 0 < C := by linarith + have hCeq : C*((d*lam)^2-d) = 2*((d*lam)^2-d)+2*e*lam^2 := by + dsimp [C] + rw [add_mul, div_mul_cancel₀ _ (ne_of_gt hgap)] + have hstep : d*C+2*e*lam^2 ≤ C*(d*lam)^2 := by nlinarith + obtain ⟨L,hL0,hL1,hL⟩ := observedAdvantage_tendsto offspring lam h + have hb : 1/(3*C) ≤ L := ge_of_tendsto' hL + (fun n => supercritical_advantage_bound offspring d e lam C h hD hd.le hq hC hstep n) + exact ⟨L, (by positivity : 0 < 1/(3*C)).trans_le hb, hL⟩ + + + +theorem regular_supercritical (b : ℕ) (hb : 2 ≤ b) (lam : ℝ) (h : Admissible lam) + (hcrit : 1 < (b:ℝ)*lam^2) : Reconstructs (regularAdvantage b lam h) := by + have hd : 0 < (b:ℝ) := by exact_mod_cast (show 0 < b by omega) + have he : 0 ≤ (b:ℝ)^2-(b:ℝ) := by + have hb' : (2:ℝ) ≤ (b:ℝ) := by exact_mod_cast hb + nlinarith + apply reconstructs_supercritical_of_moments (PMF.pure b) (b:ℝ) ((b:ℝ)^2-(b:ℝ)) lam h + ?_ hd he hcrit + simpa only [sub_add_cancel] using regular_moments b + + + +theorem poisson_supercritical (d : ℝ) (hd : 1 < d) (lam : ℝ) (h : Admissible lam) + (hcrit : 1 < d*lam^2) : Reconstructs (poissonAdvantage d hd lam h) := by + apply reconstructs_supercritical_of_moments (poissonOffspring d (le_trans (by norm_num) hd.le)) + d (d^2) lam h (poisson_moments d _) (by linarith) (sq_nonneg d) hcrit + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Symmetry.lean b/lean/OAI/Probability/ThreeState/Symmetry.lean index bd9ec88f30f081c2e7f47322994352fca2f20de6..fb22f2d374bafa472dcad8e55f30bdd1b6714166 100644 --- a/lean/OAI/Probability/ThreeState/Symmetry.lean +++ b/lean/OAI/Probability/ThreeState/Symmetry.lean @@ -1,305 +1,305 @@ -import Mathlib -import OAI.Probability.ThreeState.FixedPoints - -namespace OAI - -/-! Spin symmetry and measure identities for posterior fixed points. -/ - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma pmf_map_equiv_apply {α β : Type*} (p : PMF α) (e : α ≃ β) (a : α) : - p.map e (e a) = p a := by simp [PMF.map_apply] - -lemma uniformSpin_map (π : Equiv.Perm Spin) : uniformSpin.map π = uniformSpin := by - apply PMF.ext - intro j - obtain ⟨i,rfl⟩ := π.surjective j - rw [pmf_map_equiv_apply] - simp [uniformSpin, PMF.ofFintype_apply] - -lemma channelPMF_map (lam : ℝ) (h : Admissible lam) (π : Equiv.Perm Spin) (i : Spin) : - (channelPMF lam h i).map π = channelPMF lam h (π i) := by - apply PMF.ext - intro j - obtain ⟨k,rfl⟩ := π.surjective j - rw [pmf_map_equiv_apply] - simp [channelPMF, PMF.ofFintype_apply, channel] - -noncomputable def permMessage (π : Equiv.Perm Spin) (m : Message) : Message := - ⟨fun i => m (π.symm i), by - constructor - · intro i; exact Message.nonneg m _ - · rw [Equiv.sum_comp π.symm] - exact Message.sum m⟩ - -lemma continuous_permMessage (π : Equiv.Perm Spin) : Continuous (permMessage π) := by - apply Continuous.subtype_mk - apply continuous_pi - intro i - exact (continuous_apply (π.symm i)).comp continuous_subtype_val - -noncomputable def renameOrdered : (n : ℕ) → Equiv.Perm Spin → Equiv.Perm (OrderedObservation n) - | 0, π => π - | n+1, π => Equiv.sigmaCongrRight (fun k => Equiv.piCongrRight (fun _ : Fin k => renameOrdered n π)) - -lemma orderedLaw_rename (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (π : Equiv.Perm Spin) (n : ℕ) (i : Spin) : - (orderedLaw offspring lam h n i).map (renameOrdered n π) = orderedLaw offspring lam h n (π i) := by - induction n generalizing i with - | zero => exact PMF.pure_map _ _ - | succ n ih => - simp only [orderedLaw, PMF.map_bind, PMF.map_comp] - apply congrArg (PMF.bind offspring) - funext k - change (iidVector ((channelPMF lam h i).bind (orderedLaw offspring lam h n)) k).map - ((Sigma.mk (β := fun k => Fin k → OrderedObservation n) k) ∘ - (fun v : Fin k → OrderedObservation n => renameOrdered n π ∘ v)) = _ - rw [← PMF.map_comp, iidVector_map] - congr 2 - rw [PMF.map_bind] - simp_rw [ih] - change (channelPMF lam h i).bind ((orderedLaw offspring lam h n) ∘ π) = _ - rw [← PMF.bind_map, channelPMF_map] - -lemma marginal_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) - (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) : - (marginal law).map e = marginal law := by - rw [marginal, PMF.map_bind] - simp_rw [he] - change uniformSpin.bind (law ∘ π) = _ - rw [← PMF.bind_map, uniformSpin_map] - -lemma posterior_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) - (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) (y : α) (i : Spin) : - posterior law (e y) (π i) = posterior law y i := by - have hm : marginal law (e y) = marginal law y := by - calc - marginal law (e y) = (marginal law).map e (e y) := by rw [marginal_equivariant law π e he] - _ = _ := pmf_map_equiv_apply _ _ _ - have hi : law (π i) (e y) = law i y := by - rw [← he i] - exact pmf_map_equiv_apply _ _ _ - simp only [posterior, hm, hi] - -lemma likelihood_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) - (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) (y : α) : - likelihood law (e y) = permMessage π (likelihood law y) := by - apply Subtype.ext - funext i - have hh := posterior_equivariant law π e he y (π.symm i) - simp only [Equiv.apply_symm_apply] at hh - change 3*posterior law (e y) i = 3*posterior law y (π.symm i) - rw [hh] - -lemma likelihoodPMF_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) - (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) : - (likelihoodPMF law).map (permMessage π) = likelihoodPMF law := by - rw [likelihoodPMF, PMF.map_comp] - have hh : permMessage π ∘ likelihood law = likelihood law ∘ e := by - funext y - exact (likelihood_equivariant law π e he y).symm - rw [hh, ← PMF.map_comp, marginal_equivariant law π e he] - - -def SpinSymmetric (Q : ProbabilityMeasure Message) : Prop := - ∀ π : Equiv.Perm Spin, Q.map (permMessage π) = Q - -lemma ordered_likelihood_symmetric (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (n : ℕ) : SpinSymmetric (likelihoodLaw (orderedLaw offspring lam h n)) := by - intro π - apply Subtype.ext - change (likelihoodPMF (orderedLaw offspring lam h n)).toMeasure.map (permMessage π) = _ - rw [PMF.toMeasure_map _ _ (continuous_permMessage π).measurable] - rw [likelihoodPMF_equivariant _ π (renameOrdered n π) - (fun i => orderedLaw_rename offspring lam h π n i)] - rfl - -lemma symmetric_limit {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} - (hn : ∀ n, SpinSymmetric (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : SpinSymmetric Q := by - intro π - have hh := ((ProbabilityMeasure.continuous_map (continuous_permMessage π)).tendsto Q).comp hlim - have he : (fun n => (Qn n).map (permMessage π)) = Qn := - funext (fun n => hn n π) - simp only [Function.comp_def, he] at hh - exact tendsto_nhds_unique hh hlim - -lemma ordered_exists_symmetric_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : - ∃ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q ∧ SpinSymmetric Q ∧ - ∃ φ : ℕ → ℕ, StrictMono φ ∧ - Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) atTop (𝓝 Q) := by - obtain ⟨Q,hQ,φ,hφ,hlim⟩ := ordered_exists_fixedpoint offspring lam h - exact ⟨Q,hQ,symmetric_limit (fun n => ordered_likelihood_symmetric offspring lam h (φ n)) hlim,φ,hφ,hlim⟩ - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma measurable_combineMessage (lam : ℝ) (h : Admissible lam) (n : ℕ) : - Measurable (combineMessage lam h : (Fin n → Message) → Message) := by - apply Measurable.subtype_mk - apply Measurable.of_eval - intro i - have he : (fun m : Fin n → Message => combineMessage lam h m i) = - (fun m => if normalizer lam h m = 0 then uninformative i else - productWeight lam h m i / normalizer lam h m) := by - funext m - by_cases hm : normalizer lam h m = 0 <;> simp [combineMessage, hm] - change Measurable (fun m : Fin n → Message => combineMessage lam h m i) - rw [he] - exact Measurable.ite ((continuous_normalizer lam h n).measurable (measurableSet_singleton 0)) - measurable_const ((continuous_productWeight lam h n i).measurable.div - (continuous_normalizer lam h n).measurable) - - -noncomputable def degreeInput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : - Measure (Fin n → Message) := - (iidMeasure Q n : Measure (Fin n → Message)).withDensity (fun m => ENNReal.ofReal (normalizer lam h m)) - -lemma degreeInput_probability (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) : IsProbabilityMeasure (degreeInput lam h Q n) := by - constructor - rw [degreeInput, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, - ← ofReal_integral_eq_lintegral_ofReal - ((continuous_normalizer lam h n).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) - (Eventually.of_forall (normalizer_nonneg lam h)), integral_normalizer lam h Q hQ n] - simp - -noncomputable def degreeOutput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : - Measure Message := Measure.map (combineMessage lam h) (degreeInput lam h Q n) - -lemma degreeOutput_probability (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) : IsProbabilityMeasure (degreeOutput lam h Q n) := by - let := degreeInput_probability lam h Q hQ n - constructor - rw [degreeOutput, Measure.map_apply (measurable_combineMessage lam h n) MeasurableSet.univ] - simp - - -noncomputable def densityEvolution (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) : Measure Message := - Measure.sum (fun n => offspring n • degreeOutput lam h Q n) - -lemma densityEvolution_probability (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : IsProbabilityMeasure (densityEvolution offspring lam h Q) := by - constructor - rw [densityEvolution, Measure.sum_apply _ MeasurableSet.univ] - convert offspring.tsum_coe using 1 - apply tsum_congr - intro n - let := degreeOutput_probability lam h Q hQ n - simp - -lemma integral_degreeOutput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) - (f : Message → ℝ) (hf : Measurable f) : - ∫ m, f m ∂degreeOutput lam h Q n = - ∫ m, normalizer lam h m * f (combineMessage lam h m) ∂(iidMeasure Q n : Measure (Fin n → Message)) := by - rw [degreeOutput, integral_map (measurable_combineMessage lam h n).aemeasurable hf.aestronglyMeasurable, - degreeInput, integral_withDensity_eq_integral_toReal_smul - ((continuous_normalizer lam h n).measurable.ennreal_ofReal) - (Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top))] - apply integral_congr_ae - filter_upwards with m - simp [ENNReal.toReal_ofReal (normalizer_nonneg lam h m)] - -lemma integral_densityEvolution_continuous (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (f : C(Message,ℝ)) : - ∫ m, f m ∂densityEvolution offspring lam h Q = - mean offspring (fun n => degreeTest lam h n f Q) := by - let := densityEvolution_probability offspring lam h Q hQ - have hi : Integrable f (densityEvolution offspring lam h Q) := - f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) - rw [densityEvolution, integral_sum_measure hi] - unfold mean - apply tsum_congr - intro n - rw [integral_smul_measure, integral_degreeOutput lam h Q n f f.continuous.measurable] - rfl - -lemma fixedpoint_measure (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) : - (Q : Measure Message) = densityEvolution offspring lam h Q := by - let := densityEvolution_probability offspring lam h Q hQ.1 - apply ext_of_forall_integral_eq_of_IsFiniteMeasure - intro f - change (∫ m, f.toContinuousMap m ∂(Q : Measure Message)) = - ∫ m, f.toContinuousMap m ∂densityEvolution offspring lam h Q - rw [integral_densityEvolution_continuous offspring lam h Q hQ.1 f.toContinuousMap] - exact hQ.2 f.toContinuousMap - -end ThreeState - -namespace ThreeState -open MeasureTheory Filter Topology -open scoped Classical - -lemma ae_degreeOutput_of_forall (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) - (P : Message → Prop) (hP : MeasurableSet {m | P m}) - (hp : ∀ m : Fin n → Message, P (combineMessage lam h m)) : - ∀ᵐ m ∂degreeOutput lam h Q n, P m := by - exact (ae_map_iff (measurable_combineMessage lam h n).aemeasurable hP).mpr - (Eventually.of_forall hp) - -lemma ae_fixedpoint_of_output (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (P : Message → Prop) (hP : MeasurableSet {m | P m}) - (hp : ∀ n (m : Fin n → Message), P (combineMessage lam h m)) : - ∀ᵐ m ∂(Q : Measure Message), P m := by - rw [fixedpoint_measure offspring lam h Q hQ, densityEvolution] - apply Measure.ae_sum_iff.mpr - intro n - exact Measure.ae_smul_measure (ae_degreeOutput_of_forall lam h Q n P hP (hp n)) (offspring n) - -lemma integrable_degreeOutput_bound (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) - (hQ : Balanced Q) (n : ℕ) (f : Message → ℝ) (hf : Measurable f) (C : ℝ) - (hC : ∀ m : Fin n → Message, |f (combineMessage lam h m)| ≤ C) : - Integrable f (degreeOutput lam h Q n) ∧ - (∫ m, ‖f m‖ ∂degreeOutput lam h Q n) ≤ C := by - let := degreeOutput_probability lam h Q hQ n - have hb : ∀ᵐ m ∂degreeOutput lam h Q n, ‖f m‖ ≤ C := - ae_degreeOutput_of_forall lam h Q n _ (measurableSet_le hf.norm measurable_const) - (fun m => by simpa only [Real.norm_eq_abs] using hC m) - have hi : Integrable f (degreeOutput lam h Q n) := - (integrable_const C).mono' hf.aestronglyMeasurable hb - refine ⟨hi,?_⟩ - calc - (∫ m, ‖f m‖ ∂degreeOutput lam h Q n) ≤ ∫ _, C ∂degreeOutput lam h Q n := - integral_mono_ae hi.norm (integrable_const C) hb - _ = C := by simp - -lemma integrable_fixedpoint_of_growth (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (f : Message → ℝ) (hf : Measurable f) (C : ℕ → ℝ) (hC : HasMean offspring C) - (hb : ∀ n (m : Fin n → Message), |f (combineMessage lam h m)| ≤ C n) : - Integrable f (Q : Measure Message) := by - rw [fixedpoint_measure offspring lam h Q hQ, densityEvolution] - apply integrable_sum_measure - · intro n - exact (integrable_degreeOutput_bound lam h Q hQ.1 n f hf (C n) (hb n)).1.smul_measure (offspring.apply_ne_top n) - · apply hC.of_norm_bounded - intro n - rw [integral_smul_measure, norm_smul, Real.norm_eq_abs, - abs_of_nonneg (ENNReal.toReal_nonneg)] - rw [Real.norm_eq_abs, abs_of_nonneg (integral_nonneg (fun _ => norm_nonneg _))] - exact mul_le_mul_of_nonneg_left - (integrable_degreeOutput_bound lam h Q hQ.1 n f hf (C n) (hb n)).2 (mass_nonneg offspring n) - -lemma integral_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) - (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) - (f : Message → ℝ) (hf : Measurable f) (hi : Integrable f (Q : Measure Message)) : - ∫ m, f m ∂(Q : Measure Message) = mean offspring (fun n => - ∫ m, normalizer lam h m * f (combineMessage lam h m) ∂(iidMeasure Q n : Measure (Fin n → Message))) := by - rw [fixedpoint_measure offspring lam h Q hQ] at hi ⊢ - rw [densityEvolution, integral_sum_measure hi] - unfold mean - apply tsum_congr - intro n - rw [integral_smul_measure, integral_degreeOutput lam h Q n f hf] - rfl - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.FixedPoints + +namespace OAI + +/-! Spin symmetry and measure identities for posterior fixed points. -/ + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma pmf_map_equiv_apply {α β : Type*} (p : PMF α) (e : α ≃ β) (a : α) : + p.map e (e a) = p a := by simp [PMF.map_apply] + +lemma uniformSpin_map (π : Equiv.Perm Spin) : uniformSpin.map π = uniformSpin := by + apply PMF.ext + intro j + obtain ⟨i,rfl⟩ := π.surjective j + rw [pmf_map_equiv_apply] + simp [uniformSpin, PMF.ofFintype_apply] + +lemma channelPMF_map (lam : ℝ) (h : Admissible lam) (π : Equiv.Perm Spin) (i : Spin) : + (channelPMF lam h i).map π = channelPMF lam h (π i) := by + apply PMF.ext + intro j + obtain ⟨k,rfl⟩ := π.surjective j + rw [pmf_map_equiv_apply] + simp [channelPMF, PMF.ofFintype_apply, channel] + +noncomputable def permMessage (π : Equiv.Perm Spin) (m : Message) : Message := + ⟨fun i => m (π.symm i), by + constructor + · intro i; exact Message.nonneg m _ + · rw [Equiv.sum_comp π.symm] + exact Message.sum m⟩ + +lemma continuous_permMessage (π : Equiv.Perm Spin) : Continuous (permMessage π) := by + apply Continuous.subtype_mk + apply continuous_pi + intro i + exact (continuous_apply (π.symm i)).comp continuous_subtype_val + +noncomputable def renameOrdered : (n : ℕ) → Equiv.Perm Spin → Equiv.Perm (OrderedObservation n) + | 0, π => π + | n+1, π => Equiv.sigmaCongrRight (fun k => Equiv.piCongrRight (fun _ : Fin k => renameOrdered n π)) + +lemma orderedLaw_rename (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (π : Equiv.Perm Spin) (n : ℕ) (i : Spin) : + (orderedLaw offspring lam h n i).map (renameOrdered n π) = orderedLaw offspring lam h n (π i) := by + induction n generalizing i with + | zero => exact PMF.pure_map _ _ + | succ n ih => + simp only [orderedLaw, PMF.map_bind, PMF.map_comp] + apply congrArg (PMF.bind offspring) + funext k + change (iidVector ((channelPMF lam h i).bind (orderedLaw offspring lam h n)) k).map + ((Sigma.mk (β := fun k => Fin k → OrderedObservation n) k) ∘ + (fun v : Fin k → OrderedObservation n => renameOrdered n π ∘ v)) = _ + rw [← PMF.map_comp, iidVector_map] + congr 2 + rw [PMF.map_bind] + simp_rw [ih] + change (channelPMF lam h i).bind ((orderedLaw offspring lam h n) ∘ π) = _ + rw [← PMF.bind_map, channelPMF_map] + +lemma marginal_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) + (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) : + (marginal law).map e = marginal law := by + rw [marginal, PMF.map_bind] + simp_rw [he] + change uniformSpin.bind (law ∘ π) = _ + rw [← PMF.bind_map, uniformSpin_map] + +lemma posterior_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) + (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) (y : α) (i : Spin) : + posterior law (e y) (π i) = posterior law y i := by + have hm : marginal law (e y) = marginal law y := by + calc + marginal law (e y) = (marginal law).map e (e y) := by rw [marginal_equivariant law π e he] + _ = _ := pmf_map_equiv_apply _ _ _ + have hi : law (π i) (e y) = law i y := by + rw [← he i] + exact pmf_map_equiv_apply _ _ _ + simp only [posterior, hm, hi] + +lemma likelihood_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) + (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) (y : α) : + likelihood law (e y) = permMessage π (likelihood law y) := by + apply Subtype.ext + funext i + have hh := posterior_equivariant law π e he y (π.symm i) + simp only [Equiv.apply_symm_apply] at hh + change 3*posterior law (e y) i = 3*posterior law y (π.symm i) + rw [hh] + +lemma likelihoodPMF_equivariant {α : Type*} (law : Spin → PMF α) (π : Equiv.Perm Spin) + (e : Equiv.Perm α) (he : ∀ i, (law i).map e = law (π i)) : + (likelihoodPMF law).map (permMessage π) = likelihoodPMF law := by + rw [likelihoodPMF, PMF.map_comp] + have hh : permMessage π ∘ likelihood law = likelihood law ∘ e := by + funext y + exact (likelihood_equivariant law π e he y).symm + rw [hh, ← PMF.map_comp, marginal_equivariant law π e he] + + +def SpinSymmetric (Q : ProbabilityMeasure Message) : Prop := + ∀ π : Equiv.Perm Spin, Q.map (permMessage π) = Q + +lemma ordered_likelihood_symmetric (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (n : ℕ) : SpinSymmetric (likelihoodLaw (orderedLaw offspring lam h n)) := by + intro π + apply Subtype.ext + change (likelihoodPMF (orderedLaw offspring lam h n)).toMeasure.map (permMessage π) = _ + rw [PMF.toMeasure_map _ _ (continuous_permMessage π).measurable] + rw [likelihoodPMF_equivariant _ π (renameOrdered n π) + (fun i => orderedLaw_rename offspring lam h π n i)] + rfl + +lemma symmetric_limit {Qn : ℕ → ProbabilityMeasure Message} {Q : ProbabilityMeasure Message} + (hn : ∀ n, SpinSymmetric (Qn n)) (hlim : Tendsto Qn atTop (𝓝 Q)) : SpinSymmetric Q := by + intro π + have hh := ((ProbabilityMeasure.continuous_map (continuous_permMessage π)).tendsto Q).comp hlim + have he : (fun n => (Qn n).map (permMessage π)) = Qn := + funext (fun n => hn n π) + simp only [Function.comp_def, he] at hh + exact tendsto_nhds_unique hh hlim + +lemma ordered_exists_symmetric_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) : + ∃ Q : ProbabilityMeasure Message, IsPosteriorFixedPoint offspring lam h Q ∧ SpinSymmetric Q ∧ + ∃ φ : ℕ → ℕ, StrictMono φ ∧ + Tendsto (fun n => likelihoodLaw (orderedLaw offspring lam h (φ n))) atTop (𝓝 Q) := by + obtain ⟨Q,hQ,φ,hφ,hlim⟩ := ordered_exists_fixedpoint offspring lam h + exact ⟨Q,hQ,symmetric_limit (fun n => ordered_likelihood_symmetric offspring lam h (φ n)) hlim,φ,hφ,hlim⟩ + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma measurable_combineMessage (lam : ℝ) (h : Admissible lam) (n : ℕ) : + Measurable (combineMessage lam h : (Fin n → Message) → Message) := by + apply Measurable.subtype_mk + apply Measurable.of_eval + intro i + have he : (fun m : Fin n → Message => combineMessage lam h m i) = + (fun m => if normalizer lam h m = 0 then uninformative i else + productWeight lam h m i / normalizer lam h m) := by + funext m + by_cases hm : normalizer lam h m = 0 <;> simp [combineMessage, hm] + change Measurable (fun m : Fin n → Message => combineMessage lam h m i) + rw [he] + exact Measurable.ite ((continuous_normalizer lam h n).measurable (measurableSet_singleton 0)) + measurable_const ((continuous_productWeight lam h n i).measurable.div + (continuous_normalizer lam h n).measurable) + + +noncomputable def degreeInput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : + Measure (Fin n → Message) := + (iidMeasure Q n : Measure (Fin n → Message)).withDensity (fun m => ENNReal.ofReal (normalizer lam h m)) + +lemma degreeInput_probability (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) : IsProbabilityMeasure (degreeInput lam h Q n) := by + constructor + rw [degreeInput, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal + ((continuous_normalizer lam h n).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _)) + (Eventually.of_forall (normalizer_nonneg lam h)), integral_normalizer lam h Q hQ n] + simp + +noncomputable def degreeOutput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) : + Measure Message := Measure.map (combineMessage lam h) (degreeInput lam h Q n) + +lemma degreeOutput_probability (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) : IsProbabilityMeasure (degreeOutput lam h Q n) := by + let := degreeInput_probability lam h Q hQ n + constructor + rw [degreeOutput, Measure.map_apply (measurable_combineMessage lam h n) MeasurableSet.univ] + simp + + +noncomputable def densityEvolution (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) : Measure Message := + Measure.sum (fun n => offspring n • degreeOutput lam h Q n) + +lemma densityEvolution_probability (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) : IsProbabilityMeasure (densityEvolution offspring lam h Q) := by + constructor + rw [densityEvolution, Measure.sum_apply _ MeasurableSet.univ] + convert offspring.tsum_coe using 1 + apply tsum_congr + intro n + let := degreeOutput_probability lam h Q hQ n + simp + +lemma integral_degreeOutput (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) + (f : Message → ℝ) (hf : Measurable f) : + ∫ m, f m ∂degreeOutput lam h Q n = + ∫ m, normalizer lam h m * f (combineMessage lam h m) ∂(iidMeasure Q n : Measure (Fin n → Message)) := by + rw [degreeOutput, integral_map (measurable_combineMessage lam h n).aemeasurable hf.aestronglyMeasurable, + degreeInput, integral_withDensity_eq_integral_toReal_smul + ((continuous_normalizer lam h n).measurable.ennreal_ofReal) + (Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top))] + apply integral_congr_ae + filter_upwards with m + simp [ENNReal.toReal_ofReal (normalizer_nonneg lam h m)] + +lemma integral_densityEvolution_continuous (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : Balanced Q) (f : C(Message,ℝ)) : + ∫ m, f m ∂densityEvolution offspring lam h Q = + mean offspring (fun n => degreeTest lam h n f Q) := by + let := densityEvolution_probability offspring lam h Q hQ + have hi : Integrable f (densityEvolution offspring lam h Q) := + f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + rw [densityEvolution, integral_sum_measure hi] + unfold mean + apply tsum_congr + intro n + rw [integral_smul_measure, integral_degreeOutput lam h Q n f f.continuous.measurable] + rfl + +lemma fixedpoint_measure (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) : + (Q : Measure Message) = densityEvolution offspring lam h Q := by + let := densityEvolution_probability offspring lam h Q hQ.1 + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro f + change (∫ m, f.toContinuousMap m ∂(Q : Measure Message)) = + ∫ m, f.toContinuousMap m ∂densityEvolution offspring lam h Q + rw [integral_densityEvolution_continuous offspring lam h Q hQ.1 f.toContinuousMap] + exact hQ.2 f.toContinuousMap + +end ThreeState + +namespace ThreeState +open MeasureTheory Filter Topology +open scoped Classical + +lemma ae_degreeOutput_of_forall (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) (n : ℕ) + (P : Message → Prop) (hP : MeasurableSet {m | P m}) + (hp : ∀ m : Fin n → Message, P (combineMessage lam h m)) : + ∀ᵐ m ∂degreeOutput lam h Q n, P m := by + exact (ae_map_iff (measurable_combineMessage lam h n).aemeasurable hP).mpr + (Eventually.of_forall hp) + +lemma ae_fixedpoint_of_output (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (P : Message → Prop) (hP : MeasurableSet {m | P m}) + (hp : ∀ n (m : Fin n → Message), P (combineMessage lam h m)) : + ∀ᵐ m ∂(Q : Measure Message), P m := by + rw [fixedpoint_measure offspring lam h Q hQ, densityEvolution] + apply Measure.ae_sum_iff.mpr + intro n + exact Measure.ae_smul_measure (ae_degreeOutput_of_forall lam h Q n P hP (hp n)) (offspring n) + +lemma integrable_degreeOutput_bound (lam : ℝ) (h : Admissible lam) (Q : ProbabilityMeasure Message) + (hQ : Balanced Q) (n : ℕ) (f : Message → ℝ) (hf : Measurable f) (C : ℝ) + (hC : ∀ m : Fin n → Message, |f (combineMessage lam h m)| ≤ C) : + Integrable f (degreeOutput lam h Q n) ∧ + (∫ m, ‖f m‖ ∂degreeOutput lam h Q n) ≤ C := by + let := degreeOutput_probability lam h Q hQ n + have hb : ∀ᵐ m ∂degreeOutput lam h Q n, ‖f m‖ ≤ C := + ae_degreeOutput_of_forall lam h Q n _ (measurableSet_le hf.norm measurable_const) + (fun m => by simpa only [Real.norm_eq_abs] using hC m) + have hi : Integrable f (degreeOutput lam h Q n) := + (integrable_const C).mono' hf.aestronglyMeasurable hb + refine ⟨hi,?_⟩ + calc + (∫ m, ‖f m‖ ∂degreeOutput lam h Q n) ≤ ∫ _, C ∂degreeOutput lam h Q n := + integral_mono_ae hi.norm (integrable_const C) hb + _ = C := by simp + +lemma integrable_fixedpoint_of_growth (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (f : Message → ℝ) (hf : Measurable f) (C : ℕ → ℝ) (hC : HasMean offspring C) + (hb : ∀ n (m : Fin n → Message), |f (combineMessage lam h m)| ≤ C n) : + Integrable f (Q : Measure Message) := by + rw [fixedpoint_measure offspring lam h Q hQ, densityEvolution] + apply integrable_sum_measure + · intro n + exact (integrable_degreeOutput_bound lam h Q hQ.1 n f hf (C n) (hb n)).1.smul_measure (offspring.apply_ne_top n) + · apply hC.of_norm_bounded + intro n + rw [integral_smul_measure, norm_smul, Real.norm_eq_abs, + abs_of_nonneg (ENNReal.toReal_nonneg)] + rw [Real.norm_eq_abs, abs_of_nonneg (integral_nonneg (fun _ => norm_nonneg _))] + exact mul_le_mul_of_nonneg_left + (integrable_degreeOutput_bound lam h Q hQ.1 n f hf (C n) (hb n)).2 (mass_nonneg offspring n) + +lemma integral_fixedpoint (offspring : PMF ℕ) (lam : ℝ) (h : Admissible lam) + (Q : ProbabilityMeasure Message) (hQ : IsPosteriorFixedPoint offspring lam h Q) + (f : Message → ℝ) (hf : Measurable f) (hi : Integrable f (Q : Measure Message)) : + ∫ m, f m ∂(Q : Measure Message) = mean offspring (fun n => + ∫ m, normalizer lam h m * f (combineMessage lam h m) ∂(iidMeasure Q n : Measure (Fin n → Message))) := by + rw [fixedpoint_measure offspring lam h Q hQ] at hi ⊢ + rw [densityEvolution, integral_sum_measure hi] + unfold mean + apply tsum_congr + intro n + rw [integral_smul_measure, integral_degreeOutput lam h Q n f hf] + rfl + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeState/Update.lean b/lean/OAI/Probability/ThreeState/Update.lean index 51a691fa098c01f965aada130b1900a185c4e32e..54bba587883b0d38d90076d4d17ac5e88bd6fd70 100644 --- a/lean/OAI/Probability/ThreeState/Update.lean +++ b/lean/OAI/Probability/ThreeState/Update.lean @@ -1,258 +1,258 @@ -import Mathlib -import OAI.Probability.ThreeState.Observation - -namespace OAI - -/-! Branchwise likelihood updates and their independent product measures. -/ - -namespace ThreeState -open MeasureTheory -open scoped Classical - -noncomputable def edgeMessage (lam : ℝ) (h : Admissible lam) (m : Message) : Message := - ⟨fun i => 1+lam*(m i-1), by - constructor - · intro i - have hl := Message.nonneg m i - have hu := Message.le_three m i - by_cases hp : 0 ≤ lam - · nlinarith [h.2] - · have hn : lam ≤ 0 := le_of_not_ge hp - nlinarith [h.1] - · simp only [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib, - Message.sum, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] - norm_num⟩ - -lemma continuous_edgeMessage (lam : ℝ) (h : Admissible lam) : Continuous (edgeMessage lam h) := by - apply Continuous.subtype_mk - apply continuous_pi - intro i - exact continuous_const.add (continuous_const.mul (((continuous_apply i).comp continuous_subtype_val).sub continuous_const)) - -lemma channel_decompose (lam : ℝ) (i j : Spin) : - channel lam i j = (1-lam)/3 + if i=j then lam else 0 := by - unfold channel - split_ifs <;> ring - -lemma channel_message (lam : ℝ) (m : Message) (i : Spin) : - ∑ j, channel lam i j * m j = 1+lam*(m i-1) := by - simp_rw [channel_decompose, add_mul, ite_mul, zero_mul] - rw [Finset.sum_add_distrib, ← Finset.mul_sum, Message.sum] - simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true] - ring - -lemma mass_channelPMF (lam : ℝ) (h : Admissible lam) (i j : Spin) : - mass (channelPMF lam h i) j = channel lam i j := by - simp [mass, channelPMF, PMF.ofFintype_apply, ENNReal.toReal_ofReal (channel_nonneg h i j)] - -noncomputable def edgeLaw {α : Type*} (law : Spin → PMF α) (lam : ℝ) (h : Admissible lam) : Spin → PMF α := - fun i => (channelPMF lam h i).bind law - -lemma mass_edgeLaw {α : Type*} (law : Spin → PMF α) (lam : ℝ) (h : Admissible lam) (i : Spin) (y : α) : - mass (edgeLaw law lam h i) y = mass (marginal law) y * edgeMessage lam h (likelihood law y) i := by - rw [edgeLaw, mass_bind, tsum_fintype] - simp_rw [mass_channelPMF, ← weighted_likelihood law y] - calc - (∑ j, channel lam i j * (mass (marginal law) y * likelihood law y j)) = - mass (marginal law) y * (∑ j, channel lam i j * likelihood law y j) := by - rw [Finset.mul_sum] - congr 1 - funext j - ring - _ = _ := by rw [channel_message]; rfl - -noncomputable def sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) : PMF (Sigma α) := - p.bind (fun i => (q i).map (Sigma.mk i)) - -lemma sigmaPMF_apply {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) - (i : ι) (a : α i) : sigmaPMF p q ⟨i,a⟩ = p i * q i a := by - classical - rw [sigmaPMF, PMF.bind_apply, tsum_eq_single i] - · simp [PMF.map_apply] - · intro j hj - have he (b : α j) : (⟨i,a⟩ : Sigma α) ≠ ⟨j,b⟩ := by - intro hh - exact hj (congrArg Sigma.fst hh).symm - simp [PMF.map_apply, he] - -lemma mass_sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) - (i : ι) (a : α i) : mass (sigmaPMF p q) ⟨i,a⟩ = mass p i * mass (q i) a := by - simp only [mass, sigmaPMF_apply, ENNReal.toReal_mul] - -lemma mass_iidVector {α : Type*} (p : PMF α) (n : ℕ) (v : Fin n → α) : - mass (iidVector p n) v = ∏ j, mass p (v j) := by - simp only [mass, iidVector_apply, ENNReal.toReal_prod] - - -noncomputable def productReference {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) : - PMF (Σ n : ℕ, Fin n → α) := sigmaPMF offspring (iidVector (marginal law)) - -noncomputable def composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) : Spin → PMF (Σ n : ℕ, Fin n → α) := - fun i => sigmaPMF offspring (iidVector (edgeLaw law lam h i)) - -noncomputable def productWeight (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : ℝ := - ∏ j, edgeMessage lam h (m j) i - -noncomputable def normalizer (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : ℝ := - (∑ i : Spin, productWeight lam h m i)/3 - -lemma productWeight_nonneg (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : - 0 ≤ productWeight lam h m i := - Finset.prod_nonneg (fun index _ => Message.nonneg (edgeMessage lam h (m index)) i) - -lemma normalizer_nonneg (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - 0 ≤ normalizer lam h m := div_nonneg (Finset.sum_nonneg (fun i _ => productWeight_nonneg _ _ _ _)) (by norm_num) - -lemma productWeight_sum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : - ∑ i, productWeight lam h m i = 3*normalizer lam h m := by dsimp [normalizer]; ring - -noncomputable def combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : Message := - if hz : normalizer lam h m = 0 then uninformative else - ⟨fun i => productWeight lam h m i / normalizer lam h m, by - constructor - · intro i - exact div_nonneg (productWeight_nonneg _ _ _ _) (normalizer_nonneg _ _ _) - · rw [← Finset.sum_div, productWeight_sum] - field_simp⟩ - -lemma mass_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) (i : Spin) : - mass (composeLaw offspring law lam h i) ⟨n,v⟩ = - mass (productReference offspring law) ⟨n,v⟩ * productWeight lam h (fun j => likelihood law (v j)) i := by - simp only [composeLaw, productReference, mass_sigmaPMF, mass_iidVector, mass_edgeLaw, - Finset.prod_mul_distrib, productWeight, mul_assoc] - -lemma mass_marginal_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) : - mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ = - mass (productReference offspring law) ⟨n,v⟩ * normalizer lam h (fun j => likelihood law (v j)) := by - rw [mass_marginal] - simp_rw [mass_composeLaw] - rw [← Finset.mul_sum] - simp [normalizer] - ring - -lemma weighted_combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} - (m : Fin n → Message) (i : Spin) : - normalizer lam h m * combineMessage lam h m i = productWeight lam h m i := by - by_cases hz : normalizer lam h m = 0 - · have hs := productWeight_sum lam h m - have hi := Finset.single_le_sum (fun j _ => productWeight_nonneg lam h m j) (Finset.mem_univ i) - have hn := productWeight_nonneg lam h m i - simp only [hz, mul_zero] at hs - have hw : productWeight lam h m i = 0 := le_antisymm (by simpa [hs] using hi) hn - simp [hz, hw] - · simp only [combineMessage, dite_eq_right hz] - field_simp - -lemma likelihood_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) - (hm : mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ ≠ 0) : - likelihood (composeLaw offspring law lam h) ⟨n,v⟩ = - combineMessage lam h (fun j => likelihood law (v j)) := by - apply Subtype.ext - funext i - apply mul_left_cancel₀ hm - rw [weighted_likelihood, mass_composeLaw, mass_marginal_composeLaw, mul_assoc, - weighted_combineMessage] - -lemma weighted_test_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) (n : ℕ) (v : Fin n → α) : - mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ * - f (likelihood (composeLaw offspring law lam h) ⟨n,v⟩) = - mass (productReference offspring law) ⟨n,v⟩ * - (normalizer lam h (fun j => likelihood law (v j)) * - f (combineMessage lam h (fun j => likelihood law (v j)))) := by - by_cases hm : mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ = 0 - · rw [mass_marginal_composeLaw] at hm - rw [← mul_assoc, ← mass_marginal_composeLaw, mass_marginal_composeLaw, hm] - simp - · rw [likelihood_composeLaw offspring law lam h n v hm, mass_marginal_composeLaw, mul_assoc] - -lemma hasMean_weighted_compose {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) (C : ℝ) (hf : ∀ m, |f m| ≤ C) : - HasMean (productReference offspring law) (fun nv => - normalizer lam h (fun j => likelihood law (nv.2 j)) * - f (combineMessage lam h (fun j => likelihood law (nv.2 j)))) := by - have hs : Summable (fun nv => mass (marginal (composeLaw offspring law lam h)) nv * - f (likelihood (composeLaw offspring law lam h) nv)) := - hasMean_bounded (marginal (composeLaw offspring law lam h)) C - (fun nv => hf (likelihood (composeLaw offspring law lam h) nv)) - exact hs.congr (fun ⟨n,v⟩ => weighted_test_composeLaw offspring law lam h f n v) - -lemma mean_test_compose {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) - (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) : - mean (marginal (composeLaw offspring law lam h)) (fun nv => f (likelihood (composeLaw offspring law lam h) nv)) = - mean (productReference offspring law) (fun nv => - normalizer lam h (fun j => likelihood law (nv.2 j)) * - f (combineMessage lam h (fun j => likelihood law (nv.2 j)))) := by - apply tsum_congr - rintro ⟨n,v⟩ - exact weighted_test_composeLaw offspring law lam h f n v - -end ThreeState -namespace ThreeState -open MeasureTheory -open scoped Classical - -lemma iidVector_outer_pi {α : Type*} (p : PMF α) (n : ℕ) (s : Fin n → Set α) : - (iidVector p n).toOuterMeasure (Set.univ.pi s) = ∏ j, p.toOuterMeasure (s j) := by - induction n with - | zero => - simp [iidVector] - funext i - exact Fin.elim0 i - | succ n ih => - rw [iidVector, PMF.toOuterMeasure_bind_apply] - simp only [PMF.toOuterMeasure_map_apply] - have he (a : α) : Fin.cons a ⁻¹' (Set.univ.pi s) = - if a ∈ s 0 then Set.univ.pi (fun j : Fin n => s j.succ) else ∅ := by - ext v - simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, forall_true_left] - rw [Fin.forall_fin_succ] - by_cases ha : a ∈ s 0 <;> simp [ha] - simp_rw [he] - have hh (a : α) : p a * (iidVector p n).toOuterMeasure - (if a ∈ s 0 then Set.univ.pi (fun j : Fin n => s j.succ) else ∅) = - (s 0).indicator p a * ∏ j : Fin n, p.toOuterMeasure (s j.succ) := by - by_cases ha : a ∈ s 0 <;> simp [ha, ih] - simp_rw [hh] - rw [ENNReal.tsum_mul_right, ← PMF.toOuterMeasure_apply, Fin.prod_univ_succ] - -lemma iidVector_toMeasure {α : Type*} [MeasurableSpace α] (p : PMF α) (n : ℕ) : - (iidVector p n).toMeasure = Measure.pi (fun _ : Fin n => p.toMeasure) := by - symm - apply Measure.pi_eq - intro s hs - rw [PMF.toMeasure_apply_eq_toOuterMeasure_apply _ (MeasurableSet.univ_pi hs), iidVector_outer_pi] - congr 1 - funext j - exact (PMF.toMeasure_apply_eq_toOuterMeasure_apply p (hs j)).symm - -noncomputable def iidMeasure (Q : ProbabilityMeasure Message) (n : ℕ) : - ProbabilityMeasure (Fin n → Message) := ProbabilityMeasure.pi (fun _ => Q) - -lemma continuous_iidMeasure (n : ℕ) : Continuous (fun Q => iidMeasure Q n) := - ProbabilityMeasure.continuous_pi.comp (continuous_pi (fun _ => continuous_id)) - -lemma likelihoodPMF_iid_toMeasure {α : Type*} (law : Spin → PMF α) (n : ℕ) : - (iidVector (likelihoodPMF law) n).toMeasure = - (iidMeasure (likelihoodLaw law) n : Measure (Fin n → Message)) := by - exact iidVector_toMeasure _ n - -lemma integral_iid_likelihood {α : Type*} (law : Spin → PMF α) (n : ℕ) - (f : C((Fin n → Message),ℝ)) : - ∫ m, f m ∂(iidMeasure (likelihoodLaw law) n : Measure (Fin n → Message)) = - mean (iidVector (marginal law) n) (fun v => f (fun j => likelihood law (v j))) := by - rw [← likelihoodPMF_iid_toMeasure] - rw [PMF.integral_eq_tsum _ _ - (f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] - change mean (iidVector ((marginal law).map (likelihood law)) n) f = _ - rw [← iidVector_map] - obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn - exact mean_map_bounded _ _ _ C (fun v => by simpa only [Real.norm_eq_abs] using hC _ (Set.mem_univ _)) - -end ThreeState - -end OAI +import Mathlib +import OAI.Probability.ThreeState.Observation + +namespace OAI + +/-! Branchwise likelihood updates and their independent product measures. -/ + +namespace ThreeState +open MeasureTheory +open scoped Classical + +noncomputable def edgeMessage (lam : ℝ) (h : Admissible lam) (m : Message) : Message := + ⟨fun i => 1+lam*(m i-1), by + constructor + · intro i + have hl := Message.nonneg m i + have hu := Message.le_three m i + by_cases hp : 0 ≤ lam + · nlinarith [h.2] + · have hn : lam ≤ 0 := le_of_not_ge hp + nlinarith [h.1] + · simp only [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib, + Message.sum, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + norm_num⟩ + +lemma continuous_edgeMessage (lam : ℝ) (h : Admissible lam) : Continuous (edgeMessage lam h) := by + apply Continuous.subtype_mk + apply continuous_pi + intro i + exact continuous_const.add (continuous_const.mul (((continuous_apply i).comp continuous_subtype_val).sub continuous_const)) + +lemma channel_decompose (lam : ℝ) (i j : Spin) : + channel lam i j = (1-lam)/3 + if i=j then lam else 0 := by + unfold channel + split_ifs <;> ring + +lemma channel_message (lam : ℝ) (m : Message) (i : Spin) : + ∑ j, channel lam i j * m j = 1+lam*(m i-1) := by + simp_rw [channel_decompose, add_mul, ite_mul, zero_mul] + rw [Finset.sum_add_distrib, ← Finset.mul_sum, Message.sum] + simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true] + ring + +lemma mass_channelPMF (lam : ℝ) (h : Admissible lam) (i j : Spin) : + mass (channelPMF lam h i) j = channel lam i j := by + simp [mass, channelPMF, PMF.ofFintype_apply, ENNReal.toReal_ofReal (channel_nonneg h i j)] + +noncomputable def edgeLaw {α : Type*} (law : Spin → PMF α) (lam : ℝ) (h : Admissible lam) : Spin → PMF α := + fun i => (channelPMF lam h i).bind law + +lemma mass_edgeLaw {α : Type*} (law : Spin → PMF α) (lam : ℝ) (h : Admissible lam) (i : Spin) (y : α) : + mass (edgeLaw law lam h i) y = mass (marginal law) y * edgeMessage lam h (likelihood law y) i := by + rw [edgeLaw, mass_bind, tsum_fintype] + simp_rw [mass_channelPMF, ← weighted_likelihood law y] + calc + (∑ j, channel lam i j * (mass (marginal law) y * likelihood law y j)) = + mass (marginal law) y * (∑ j, channel lam i j * likelihood law y j) := by + rw [Finset.mul_sum] + congr 1 + funext j + ring + _ = _ := by rw [channel_message]; rfl + +noncomputable def sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) : PMF (Sigma α) := + p.bind (fun i => (q i).map (Sigma.mk i)) + +lemma sigmaPMF_apply {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) + (i : ι) (a : α i) : sigmaPMF p q ⟨i,a⟩ = p i * q i a := by + classical + rw [sigmaPMF, PMF.bind_apply, tsum_eq_single i] + · simp [PMF.map_apply] + · intro j hj + have he (b : α j) : (⟨i,a⟩ : Sigma α) ≠ ⟨j,b⟩ := by + intro hh + exact hj (congrArg Sigma.fst hh).symm + simp [PMF.map_apply, he] + +lemma mass_sigmaPMF {ι : Type*} {α : ι → Type*} (p : PMF ι) (q : ∀ i, PMF (α i)) + (i : ι) (a : α i) : mass (sigmaPMF p q) ⟨i,a⟩ = mass p i * mass (q i) a := by + simp only [mass, sigmaPMF_apply, ENNReal.toReal_mul] + +lemma mass_iidVector {α : Type*} (p : PMF α) (n : ℕ) (v : Fin n → α) : + mass (iidVector p n) v = ∏ j, mass p (v j) := by + simp only [mass, iidVector_apply, ENNReal.toReal_prod] + + +noncomputable def productReference {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) : + PMF (Σ n : ℕ, Fin n → α) := sigmaPMF offspring (iidVector (marginal law)) + +noncomputable def composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) : Spin → PMF (Σ n : ℕ, Fin n → α) := + fun i => sigmaPMF offspring (iidVector (edgeLaw law lam h i)) + +noncomputable def productWeight (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : ℝ := + ∏ j, edgeMessage lam h (m j) i + +noncomputable def normalizer (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : ℝ := + (∑ i : Spin, productWeight lam h m i)/3 + +lemma productWeight_nonneg (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) (i : Spin) : + 0 ≤ productWeight lam h m i := + Finset.prod_nonneg (fun index _ => Message.nonneg (edgeMessage lam h (m index)) i) + +lemma normalizer_nonneg (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + 0 ≤ normalizer lam h m := div_nonneg (Finset.sum_nonneg (fun i _ => productWeight_nonneg _ _ _ _)) (by norm_num) + +lemma productWeight_sum (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : + ∑ i, productWeight lam h m i = 3*normalizer lam h m := by dsimp [normalizer]; ring + +noncomputable def combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} (m : Fin n → Message) : Message := + if hz : normalizer lam h m = 0 then uninformative else + ⟨fun i => productWeight lam h m i / normalizer lam h m, by + constructor + · intro i + exact div_nonneg (productWeight_nonneg _ _ _ _) (normalizer_nonneg _ _ _) + · rw [← Finset.sum_div, productWeight_sum] + field_simp⟩ + +lemma mass_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) (i : Spin) : + mass (composeLaw offspring law lam h i) ⟨n,v⟩ = + mass (productReference offspring law) ⟨n,v⟩ * productWeight lam h (fun j => likelihood law (v j)) i := by + simp only [composeLaw, productReference, mass_sigmaPMF, mass_iidVector, mass_edgeLaw, + Finset.prod_mul_distrib, productWeight, mul_assoc] + +lemma mass_marginal_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) : + mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ = + mass (productReference offspring law) ⟨n,v⟩ * normalizer lam h (fun j => likelihood law (v j)) := by + rw [mass_marginal] + simp_rw [mass_composeLaw] + rw [← Finset.mul_sum] + simp [normalizer] + ring + +lemma weighted_combineMessage (lam : ℝ) (h : Admissible lam) {n : ℕ} + (m : Fin n → Message) (i : Spin) : + normalizer lam h m * combineMessage lam h m i = productWeight lam h m i := by + by_cases hz : normalizer lam h m = 0 + · have hs := productWeight_sum lam h m + have hi := Finset.single_le_sum (fun j _ => productWeight_nonneg lam h m j) (Finset.mem_univ i) + have hn := productWeight_nonneg lam h m i + simp only [hz, mul_zero] at hs + have hw : productWeight lam h m i = 0 := le_antisymm (by simpa [hs] using hi) hn + simp [hz, hw] + · simp only [combineMessage, dite_eq_right hz] + field_simp + +lemma likelihood_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (n : ℕ) (v : Fin n → α) + (hm : mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ ≠ 0) : + likelihood (composeLaw offspring law lam h) ⟨n,v⟩ = + combineMessage lam h (fun j => likelihood law (v j)) := by + apply Subtype.ext + funext i + apply mul_left_cancel₀ hm + rw [weighted_likelihood, mass_composeLaw, mass_marginal_composeLaw, mul_assoc, + weighted_combineMessage] + +lemma weighted_test_composeLaw {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) (n : ℕ) (v : Fin n → α) : + mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ * + f (likelihood (composeLaw offspring law lam h) ⟨n,v⟩) = + mass (productReference offspring law) ⟨n,v⟩ * + (normalizer lam h (fun j => likelihood law (v j)) * + f (combineMessage lam h (fun j => likelihood law (v j)))) := by + by_cases hm : mass (marginal (composeLaw offspring law lam h)) ⟨n,v⟩ = 0 + · rw [mass_marginal_composeLaw] at hm + rw [← mul_assoc, ← mass_marginal_composeLaw, mass_marginal_composeLaw, hm] + simp + · rw [likelihood_composeLaw offspring law lam h n v hm, mass_marginal_composeLaw, mul_assoc] + +lemma hasMean_weighted_compose {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) (C : ℝ) (hf : ∀ m, |f m| ≤ C) : + HasMean (productReference offspring law) (fun nv => + normalizer lam h (fun j => likelihood law (nv.2 j)) * + f (combineMessage lam h (fun j => likelihood law (nv.2 j)))) := by + have hs : Summable (fun nv => mass (marginal (composeLaw offspring law lam h)) nv * + f (likelihood (composeLaw offspring law lam h) nv)) := + hasMean_bounded (marginal (composeLaw offspring law lam h)) C + (fun nv => hf (likelihood (composeLaw offspring law lam h) nv)) + exact hs.congr (fun ⟨n,v⟩ => weighted_test_composeLaw offspring law lam h f n v) + +lemma mean_test_compose {α : Type*} (offspring : PMF ℕ) (law : Spin → PMF α) + (lam : ℝ) (h : Admissible lam) (f : Message → ℝ) : + mean (marginal (composeLaw offspring law lam h)) (fun nv => f (likelihood (composeLaw offspring law lam h) nv)) = + mean (productReference offspring law) (fun nv => + normalizer lam h (fun j => likelihood law (nv.2 j)) * + f (combineMessage lam h (fun j => likelihood law (nv.2 j)))) := by + apply tsum_congr + rintro ⟨n,v⟩ + exact weighted_test_composeLaw offspring law lam h f n v + +end ThreeState +namespace ThreeState +open MeasureTheory +open scoped Classical + +lemma iidVector_outer_pi {α : Type*} (p : PMF α) (n : ℕ) (s : Fin n → Set α) : + (iidVector p n).toOuterMeasure (Set.univ.pi s) = ∏ j, p.toOuterMeasure (s j) := by + induction n with + | zero => + simp [iidVector] + funext i + exact Fin.elim0 i + | succ n ih => + rw [iidVector, PMF.toOuterMeasure_bind_apply] + simp only [PMF.toOuterMeasure_map_apply] + have he (a : α) : Fin.cons a ⁻¹' (Set.univ.pi s) = + if a ∈ s 0 then Set.univ.pi (fun j : Fin n => s j.succ) else ∅ := by + ext v + simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, forall_true_left] + rw [Fin.forall_fin_succ] + by_cases ha : a ∈ s 0 <;> simp [ha] + simp_rw [he] + have hh (a : α) : p a * (iidVector p n).toOuterMeasure + (if a ∈ s 0 then Set.univ.pi (fun j : Fin n => s j.succ) else ∅) = + (s 0).indicator p a * ∏ j : Fin n, p.toOuterMeasure (s j.succ) := by + by_cases ha : a ∈ s 0 <;> simp [ha, ih] + simp_rw [hh] + rw [ENNReal.tsum_mul_right, ← PMF.toOuterMeasure_apply, Fin.prod_univ_succ] + +lemma iidVector_toMeasure {α : Type*} [MeasurableSpace α] (p : PMF α) (n : ℕ) : + (iidVector p n).toMeasure = Measure.pi (fun _ : Fin n => p.toMeasure) := by + symm + apply Measure.pi_eq + intro s hs + rw [PMF.toMeasure_apply_eq_toOuterMeasure_apply _ (MeasurableSet.univ_pi hs), iidVector_outer_pi] + congr 1 + funext j + exact (PMF.toMeasure_apply_eq_toOuterMeasure_apply p (hs j)).symm + +noncomputable def iidMeasure (Q : ProbabilityMeasure Message) (n : ℕ) : + ProbabilityMeasure (Fin n → Message) := ProbabilityMeasure.pi (fun _ => Q) + +lemma continuous_iidMeasure (n : ℕ) : Continuous (fun Q => iidMeasure Q n) := + ProbabilityMeasure.continuous_pi.comp (continuous_pi (fun _ => continuous_id)) + +lemma likelihoodPMF_iid_toMeasure {α : Type*} (law : Spin → PMF α) (n : ℕ) : + (iidVector (likelihoodPMF law) n).toMeasure = + (iidMeasure (likelihoodLaw law) n : Measure (Fin n → Message)) := by + exact iidVector_toMeasure _ n + +lemma integral_iid_likelihood {α : Type*} (law : Spin → PMF α) (n : ℕ) + (f : C((Fin n → Message),ℝ)) : + ∫ m, f m ∂(iidMeasure (likelihoodLaw law) n : Measure (Fin n → Message)) = + mean (iidVector (marginal law) n) (fun v => f (fun j => likelihood law (v j))) := by + rw [← likelihoodPMF_iid_toMeasure] + rw [PMF.integral_eq_tsum _ _ + (f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] + change mean (iidVector ((marginal law).map (likelihood law)) n) f = _ + rw [← iidVector_map] + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn f.continuous.continuousOn + exact mean_map_bounded _ _ _ C (fun v => by simpa only [Real.norm_eq_abs] using hC _ (Set.mem_univ _)) + +end ThreeState + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Basic.lean b/lean/OAI/Probability/ThreeStateClauses/Basic.lean index 5d2615d8c018606c98b38a64f8ed67413488f5f4..d863af141acb1a9183db6999caf069db71c69725 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Basic.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Basic.lean @@ -1,89 +1,89 @@ -import Mathlib - -namespace OAI - -/-! Basic. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open scoped BigOperators ENNReal NNReal -open Filter - -namespace ThreeState.TreeClauses - -abbrev Spin := Fin 3 - -def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1 - -def channelWeight (lam : ℝ) (i j : Spin) : ℝ := - if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3 - -lemma channelWeight_nonneg {lam : ℝ} (hlam : Admissible lam) (i j : Spin) : - 0 ≤ channelWeight lam i j := by - unfold channelWeight - split_ifs <;> dsimp [Admissible] at hlam <;> linarith [hlam.1, hlam.2] - -lemma channelWeight_sum (lam : ℝ) (i : Spin) : ∑ j, channelWeight lam i j = 1 := by - fin_cases i <;> simp [channelWeight, Fin.sum_univ_three] <;> ring - -def channel (lam : ℝ) (hlam : Admissible lam) (i : Spin) : PMF Spin := - PMF.ofFintype (fun j ↦ ENNReal.ofReal (channelWeight lam i j)) (by - rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ ↦ channelWeight_nonneg hlam i j), - channelWeight_sum] - norm_num) - -def Observation : ℕ → Type - | 0 => Spin - | n + 1 => Multiset (Observation n) - -def iidList {α : Type} (p : PMF α) : ℕ → PMF (List α) - | 0 => PMF.pure [] - | n + 1 => p.bind fun x ↦ (iidList p n).map (List.cons x) - -def observationLaw (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : - (ℓ : ℕ) → Spin → PMF (Observation ℓ) - | 0, i => PMF.pure i - | ℓ + 1, i => offspring.bind fun n ↦ - (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map - (fun xs ↦ (xs : Multiset (Observation ℓ))) - -def jointWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (i : Spin) (o : Observation ℓ) : ℝ≥0∞ := - (1 / 3 : ℝ≥0∞) * observationLaw lam hlam offspring ℓ i o - -def marginalWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (o : Observation ℓ) : ℝ≥0∞ := - ∑ i, jointWeight lam hlam offspring ℓ i o - -def posterior (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (o : Observation ℓ) (i : Spin) : ℝ := - (jointWeight lam hlam offspring ℓ i o / marginalWeight lam hlam offspring ℓ o).toReal - -def advantage (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : ℝ := - ∑' o : Observation ℓ, (marginalWeight lam hlam offspring ℓ o).toReal * - ((∑ i : Spin, |posterior lam hlam offspring ℓ o i - (1 / 3 : ℝ)|) / 2) - -def Reconstructs (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : Prop := - ∃ a : ℝ, 0 < a ∧ Tendsto (advantage lam hlam offspring) atTop (nhds a) - -def ThresholdAt (d lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : Prop := - (Reconstructs lam hlam offspring ↔ 1 < d * lam ^ 2) ∧ - (d * lam ^ 2 ≤ 1 → Tendsto (advantage lam hlam offspring) atTop (nhds 0)) - -def ExactThreshold : Prop := - (∀ (b : ℕ), 2 ≤ b → ∀ (lam : ℝ) (hlam : Admissible lam), - ThresholdAt (b : ℝ) lam hlam (PMF.pure b)) ∧ - (∀ (d : ℝ) (hd : 1 < d) (lam : ℝ) (hlam : Admissible lam), - ThresholdAt d lam hlam (by - let rate : ℝ≥0 := ⟨d, le_trans (by norm_num) hd.le⟩ - haveI : MeasureTheory.IsProbabilityMeasure (ProbabilityTheory.poissonMeasure rate) := - (ProbabilityTheory.hasSum_one_poissonMeasure rate).isProbabilityMeasure_sum_dirac - (fun _ ↦ by positivity) - exact (ProbabilityTheory.poissonMeasure rate).toPMF)) - -end ThreeState.TreeClauses - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Basic. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open scoped BigOperators ENNReal NNReal +open Filter + +namespace ThreeState.TreeClauses + +abbrev Spin := Fin 3 + +def Admissible (lam : ℝ) : Prop := -(1 / 2 : ℝ) ≤ lam ∧ lam ≤ 1 + +def channelWeight (lam : ℝ) (i j : Spin) : ℝ := + if i = j then (1 + 2 * lam) / 3 else (1 - lam) / 3 + +lemma channelWeight_nonneg {lam : ℝ} (hlam : Admissible lam) (i j : Spin) : + 0 ≤ channelWeight lam i j := by + unfold channelWeight + split_ifs <;> dsimp [Admissible] at hlam <;> linarith [hlam.1, hlam.2] + +lemma channelWeight_sum (lam : ℝ) (i : Spin) : ∑ j, channelWeight lam i j = 1 := by + fin_cases i <;> simp [channelWeight, Fin.sum_univ_three] <;> ring + +def channel (lam : ℝ) (hlam : Admissible lam) (i : Spin) : PMF Spin := + PMF.ofFintype (fun j ↦ ENNReal.ofReal (channelWeight lam i j)) (by + rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ ↦ channelWeight_nonneg hlam i j), + channelWeight_sum] + norm_num) + +def Observation : ℕ → Type + | 0 => Spin + | n + 1 => Multiset (Observation n) + +def iidList {α : Type} (p : PMF α) : ℕ → PMF (List α) + | 0 => PMF.pure [] + | n + 1 => p.bind fun x ↦ (iidList p n).map (List.cons x) + +def observationLaw (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : + (ℓ : ℕ) → Spin → PMF (Observation ℓ) + | 0, i => PMF.pure i + | ℓ + 1, i => offspring.bind fun n ↦ + (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map + (fun xs ↦ (xs : Multiset (Observation ℓ))) + +def jointWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (i : Spin) (o : Observation ℓ) : ℝ≥0∞ := + (1 / 3 : ℝ≥0∞) * observationLaw lam hlam offspring ℓ i o + +def marginalWeight (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (o : Observation ℓ) : ℝ≥0∞ := + ∑ i, jointWeight lam hlam offspring ℓ i o + +def posterior (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (o : Observation ℓ) (i : Spin) : ℝ := + (jointWeight lam hlam offspring ℓ i o / marginalWeight lam hlam offspring ℓ o).toReal + +def advantage (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : ℝ := + ∑' o : Observation ℓ, (marginalWeight lam hlam offspring ℓ o).toReal * + ((∑ i : Spin, |posterior lam hlam offspring ℓ o i - (1 / 3 : ℝ)|) / 2) + +def Reconstructs (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : Prop := + ∃ a : ℝ, 0 < a ∧ Tendsto (advantage lam hlam offspring) atTop (nhds a) + +def ThresholdAt (d lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : Prop := + (Reconstructs lam hlam offspring ↔ 1 < d * lam ^ 2) ∧ + (d * lam ^ 2 ≤ 1 → Tendsto (advantage lam hlam offspring) atTop (nhds 0)) + +def ExactThreshold : Prop := + (∀ (b : ℕ), 2 ≤ b → ∀ (lam : ℝ) (hlam : Admissible lam), + ThresholdAt (b : ℝ) lam hlam (PMF.pure b)) ∧ + (∀ (d : ℝ) (hd : 1 < d) (lam : ℝ) (hlam : Admissible lam), + ThresholdAt d lam hlam (by + let rate : ℝ≥0 := ⟨d, le_trans (by norm_num) hd.le⟩ + haveI : MeasureTheory.IsProbabilityMeasure (ProbabilityTheory.poissonMeasure rate) := + (ProbabilityTheory.hasSum_one_poissonMeasure rate).isProbabilityMeasure_sum_dirac + (fun _ ↦ by positivity) + exact (ProbabilityTheory.poissonMeasure rate).toPMF)) + +end ThreeState.TreeClauses + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/BranchGrowth.lean b/lean/OAI/Probability/ThreeStateClauses/BranchGrowth.lean index de5615470138ca380329c19bb8330c21db25f17d..7ba0f858fac5c335edbd598e44cacb7d9fcf2511 100644 --- a/lean/OAI/Probability/ThreeStateClauses/BranchGrowth.lean +++ b/lean/OAI/Probability/ThreeStateClauses/BranchGrowth.lean @@ -1,211 +1,211 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.Projection - -namespace OAI - -/-! Branch Growth. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma continuous_compact_integral {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] - [MeasurableSpace Y] [BorelSpace Y] [CompactSpace Y] {μ : Measure Y} [IsFiniteMeasure μ] - {f : X × Y → ℝ} (hf : Continuous f) : Continuous (fun x ↦ ∫ y, f (x,y) ∂μ) := by - apply continuousOn_univ.mp - apply continuousOn_integral_of_compact_support (k := (univ : Set Y)) isCompact_univ - · exact hf.continuousOn - · simp - -lemma continuous_cons (n : ℕ) : Continuous (fun p : Message × (Fin n → Message) ↦ (Fin.cons p.1 p.2 : Fin (n+1) → Message)) := by - apply continuous_pi - intro j - refine Fin.cases ?_ (fun k ↦ ?_) j - · simpa using (continuous_fst : Continuous (fun p : Message × (Fin n → Message) ↦ p.1)) - · change Continuous (fun p : Message × (Fin n → Message) ↦ p.2 k) - fun_prop - -lemma integral_pi_cons (Q : Law) (n : ℕ) {f : (Fin (n+1) → Message) → ℝ} (hf : Continuous f) : - (∫ m, f m ∂(Measure.pi fun _ : Fin (n+1) ↦ Q.probability.toMeasure)) = - ∫ m : Fin n → Message, (∫ e, f (Fin.cons e m) ∂Q.probability.toMeasure) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by - have he : (∫ m, f m ∂(Measure.pi fun _ : Fin (n+1) ↦ Q.probability.toMeasure)) = - ∫ p : Message × (Fin n → Message), f (Fin.cons p.1 p.2) - ∂Q.probability.toMeasure.prod (Measure.pi fun _ ↦ Q.probability.toMeasure) := by - rw [← (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) ↦ Q.probability.toMeasure) 0).symm.integral_comp'] - simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, - Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq] - rw [he] - exact integral_prod_symm _ (compact_integrable (hf.comp (continuous_cons n))) - -lemma branchProduct_cons (lam : ℝ) {n : ℕ} (e : Message) (m : Fin n → Message) (i : Fin 3) : - branchProduct (branchEdges lam (Fin.cons e m)) i = edgeMessage lam e i*branchProduct (branchEdges lam m) i := by - simp [branchProduct, branchEdges, Fin.prod_univ_succ] - -lemma normalizer_cons {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (e : Message) (m : Fin n → Message) : - normalizer (branchEdges lam (Fin.cons e m)) = - normalizer (branchEdges lam m)*pairZ lam (branchOutput hl₀ hl₁ m) e := by - unfold normalizer pairZ - change avg (fun i ↦ branchProduct (branchEdges lam (Fin.cons e m)) i) = _ - simp_rw [branchProduct_cons] - change avg (fun i ↦ edgeMessage lam e i*branchProduct (branchEdges lam m) i) = - avg (branchProduct (branchEdges lam m))*avg (fun i ↦ - (branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m))*edgeMessage lam e i) - have hz := ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)) - change normalizer (branchEdges lam m) ≠ 0 at hz - have hid : avg (branchProduct (branchEdges lam m)) = normalizer (branchEdges lam m) := rfl - rw [hid] - dsimp only [avg] - field_simp [hz] - -lemma branchOutput_cons {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (e : Message) (m : Fin n → Message) : - branchOutput hl₀ hl₁ (Fin.cons e m) = pairPosterior hl₀ hl₁ (branchOutput hl₀ hl₁ m) e := by - apply Subtype.ext - funext i - change branchProduct (branchEdges lam (Fin.cons e m)) i/normalizer (branchEdges lam (Fin.cons e m)) = - (branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m))*edgeMessage lam e i/ - pairZ lam (branchOutput hl₀ hl₁ m) e - rw [branchProduct_cons, normalizer_cons hl₀ hl₁] - ring - -lemma finite_succ_integral (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - {f : Message → ℝ} (hf : Continuous f) : - (∫ m, f m ∂(finiteProbability Q hl₀ hl₁ (n+1)).toMeasure) = - ∫ r, (∫ m, pairZ lam r m*f (pairPosterior hl₀ hl₁ r m) ∂Q.probability.toMeasure) - ∂(finiteProbability Q hl₀ hl₁ n).toMeasure := by - have hk : Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2*f (pairPosterior hl₀ hl₁ p.1 p.2)) := - (continuous_pairZ lam).mul (hf.comp (continuous_pairPosterior hl₀ hl₁)) - rw [integral_finiteProbability Q hl₀ hl₁ (n+1) hf.measurable, - integral_pi_cons Q n (f := fun m ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m)) ((continuous_normalizer (n+1) lam).mul (hf.comp (continuous_branchOutput hl₀ hl₁ (n+1)))), - integral_finiteProbability Q hl₀ hl₁ n (continuous_compact_integral hk).measurable] - congr 1 - funext m - simp_rw [normalizer_cons hl₀ hl₁, branchOutput_cons hl₀ hl₁, mul_assoc, integral_const_mul] - -theorem correlationEntropy_succ (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - correlationEntropy Q lam (n+1) = correlationEntropy Q lam n + pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam := by - let c : Message → ℝ := fun r ↦ ∫ e, pairZ lam r e*Real.log (pairZ lam r e) ∂Q.probability.toMeasure - have hc : Continuous c := continuous_compact_integral (continuous_pairEntropy hl₀ hl₁) - have he (m : Fin n → Message) : - (∫ e, normalizer (branchEdges lam (Fin.cons e m))*Real.log (normalizer (branchEdges lam (Fin.cons e m))) - ∂Q.probability.toMeasure) = - normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))+ - normalizer (branchEdges lam m)*c (branchOutput hl₀ hl₁ m) := by - have hp := normalizer_positive (branchEdges_positive hl₀ hl₁ m) - have hpp (e : Message) := pairZ_positive hl₀ hl₁ (branchOutput hl₀ hl₁ m) e - have hid (e : Message) : - normalizer (branchEdges lam (Fin.cons e m))*Real.log (normalizer (branchEdges lam (Fin.cons e m))) = - (normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)))*pairZ lam (branchOutput hl₀ hl₁ m) e+ - normalizer (branchEdges lam m)*(pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e)) := by - rw [normalizer_cons hl₀ hl₁, Real.log_mul (ne_of_gt hp) (ne_of_gt (hpp e))] - ring - simp_rw [hid] - have hz : Continuous (fun e ↦ pairZ lam (branchOutput hl₀ hl₁ m) e) := - (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) - have hj : Continuous (fun e ↦ pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e)) := - (continuous_pairEntropy hl₀ hl₁).comp (continuous_const.prodMk continuous_id) - rw [integral_add (f := fun e ↦ - (normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)))*pairZ lam (branchOutput hl₀ hl₁ m) e) - (g := fun e ↦ normalizer (branchEdges lam m)*(pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e))) - ((compact_integrable hz).const_mul _) ((compact_integrable hj).const_mul _), - integral_const_mul, integral_const_mul, integral_pairZ, mul_one] - unfold correlationEntropy - rw [integral_pi_cons Q n (continuous_correlationIntegrand hl₀ hl₁ (n+1))] - simp_rw [he] - rw [integral_add (f := fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) - (g := fun m ↦ normalizer (branchEdges lam m)*c (branchOutput hl₀ hl₁ m)) - (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n)) - (compact_integrable ((continuous_normalizer n lam).mul (hc.comp (continuous_branchOutput hl₀ hl₁ n))))] - congr 1 - exact (integral_finiteProbability Q hl₀ hl₁ n hc.measurable).symm - -lemma xMoment_tangent (r s : Message) : - xMoment r+avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) ≤ xMoment s := by - have hp : 0 ≤ avg (fun i ↦ (s.1 i-r.1 i)^2)/2 := - by - dsimp [avg] - positivity - have he : xMoment s-xMoment r-avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) = - avg (fun i ↦ (s.1 i-r.1 i)^2)/2 := by - dsimp [xMoment, momentX, centered, avg]; ring - linarith - -lemma xMoment_sq_tangent (r s : Message) : - xMoment r^2+avg (fun i ↦ 2*xMoment r*(r.1 i-1)*(s.1 i-r.1 i)) ≤ xMoment s^2 := by - have ht := xMoment_tangent r s - have he : avg (fun i ↦ 2*xMoment r*(r.1 i-1)*(s.1 i-r.1 i)) = - 2*xMoment r*avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) := by - dsimp [avg]; ring - rw [he] - nlinarith [mul_nonneg (xMoment_nonneg r) (sub_nonneg.mpr ht), sq_nonneg (xMoment s-xMoment r)] - -lemma integral_pair_linear (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (r : Message) (a : Vec) : - (∫ m, pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)) - ∂Q.probability.toMeasure) = 0 := by - have hc (i : Fin 3) : Continuous (fun m : Message ↦ (pairPosterior hl₀ hl₁ r m).1 i) := - (continuous_coordinate i).comp ((continuous_pairPosterior hl₀ hl₁).comp (continuous_const.prodMk continuous_id)) - have hz : Continuous (fun m : Message ↦ pairZ lam r m) := - (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) - have he (m : Message) : pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)) = - avg (fun i ↦ a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m)) := by - dsimp [avg]; ring - simp_rw [he] - rw [integral_avg_measure (f := fun m : Message ↦ fun i ↦ a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m)) - (fun i ↦ compact_integrable (continuous_const.mul ((hz.mul (hc i)).sub (continuous_const.mul hz))))] - have hzero (i : Fin 3) : (∫ m, a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m) - ∂Q.probability.toMeasure) = 0 := by - rw [integral_const_mul, integral_sub (f := fun m ↦ pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i) - (g := fun m ↦ r.1 i*pairZ lam r m) - (compact_integrable (hz.mul (hc i))) ((compact_integrable hz).const_mul _), - integral_pair_coordinate, integral_const_mul, integral_pairZ] - ring - simp_rw [hzero] - exact avg_const 0 - -lemma integral_pair_tangent_lower (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - {f : Message → ℝ} (hf : Continuous f) (r : Message) (a : Vec) - (ht : ∀ s, f r+avg (fun i ↦ a i*(s.1 i-r.1 i)) ≤ f s) : - f r ≤ ∫ m, pairZ lam r m*f (pairPosterior hl₀ hl₁ r m) ∂Q.probability.toMeasure := by - have hz : Continuous (fun m : Message ↦ pairZ lam r m) := - (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) - have hp : Continuous (fun m : Message ↦ pairPosterior hl₀ hl₁ r m) := - (continuous_pairPosterior hl₀ hl₁).comp (continuous_const.prodMk continuous_id) - have hc : Continuous (fun m : Message ↦ avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i))) := - continuous_avg.comp (continuous_pi (fun i ↦ continuous_const.mul (((continuous_coordinate i).comp hp).sub continuous_const))) - have hh := integral_mono (μ := Q.probability.toMeasure) - (f := fun m ↦ pairZ lam r m*(f r+avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)))) - (g := fun m ↦ pairZ lam r m*f (pairPosterior hl₀ hl₁ r m)) - (compact_integrable (hz.mul (continuous_const.add hc))) - (compact_integrable (hz.mul (hf.comp hp))) - (fun m ↦ mul_le_mul_of_nonneg_left (ht _) (pairZ_positive hl₀ hl₁ r m).le) - simp_rw [mul_add] at hh - rw [integral_add (f := fun m ↦ pairZ lam r m*f r) - (g := fun m ↦ pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i))) - ((compact_integrable hz).mul_const _) (compact_integrable (hz.mul hc)), - integral_mul_const, integral_pairZ, integral_pair_linear, one_mul, add_zero] at hh - exact hh - -theorem finite_nu_mono (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Monotone (fun n ↦ (finiteLaw Q hl₀ hl₁ n).nu) := by - apply monotone_nat_of_le_succ - intro n - change (∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) ≤ - ∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ (n+1)).toMeasure - rw [finite_succ_integral Q hl₀ hl₁ n (f := fun m ↦ xMoment m^2) (continuous_xMoment.pow 2)] - apply integral_mono (compact_integrable (continuous_xMoment.pow 2)) - (compact_integrable (continuous_compact_integral - ((continuous_pairZ lam).mul ((continuous_xMoment.pow 2).comp (continuous_pairPosterior hl₀ hl₁))))) - intro r - exact integral_pair_tangent_lower Q hl₀ hl₁ (continuous_xMoment.pow 2) r - (fun i ↦ 2*xMoment r*(r.1 i-1)) (xMoment_sq_tangent r) - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.Projection + +namespace OAI + +/-! Branch Growth. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma continuous_compact_integral {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] + [MeasurableSpace Y] [BorelSpace Y] [CompactSpace Y] {μ : Measure Y} [IsFiniteMeasure μ] + {f : X × Y → ℝ} (hf : Continuous f) : Continuous (fun x ↦ ∫ y, f (x,y) ∂μ) := by + apply continuousOn_univ.mp + apply continuousOn_integral_of_compact_support (k := (univ : Set Y)) isCompact_univ + · exact hf.continuousOn + · simp + +lemma continuous_cons (n : ℕ) : Continuous (fun p : Message × (Fin n → Message) ↦ (Fin.cons p.1 p.2 : Fin (n+1) → Message)) := by + apply continuous_pi + intro j + refine Fin.cases ?_ (fun k ↦ ?_) j + · simpa using (continuous_fst : Continuous (fun p : Message × (Fin n → Message) ↦ p.1)) + · change Continuous (fun p : Message × (Fin n → Message) ↦ p.2 k) + fun_prop + +lemma integral_pi_cons (Q : Law) (n : ℕ) {f : (Fin (n+1) → Message) → ℝ} (hf : Continuous f) : + (∫ m, f m ∂(Measure.pi fun _ : Fin (n+1) ↦ Q.probability.toMeasure)) = + ∫ m : Fin n → Message, (∫ e, f (Fin.cons e m) ∂Q.probability.toMeasure) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by + have he : (∫ m, f m ∂(Measure.pi fun _ : Fin (n+1) ↦ Q.probability.toMeasure)) = + ∫ p : Message × (Fin n → Message), f (Fin.cons p.1 p.2) + ∂Q.probability.toMeasure.prod (Measure.pi fun _ ↦ Q.probability.toMeasure) := by + rw [← (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) ↦ Q.probability.toMeasure) 0).symm.integral_comp'] + simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, + Fin.insertNth_zero, Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq] + rw [he] + exact integral_prod_symm _ (compact_integrable (hf.comp (continuous_cons n))) + +lemma branchProduct_cons (lam : ℝ) {n : ℕ} (e : Message) (m : Fin n → Message) (i : Fin 3) : + branchProduct (branchEdges lam (Fin.cons e m)) i = edgeMessage lam e i*branchProduct (branchEdges lam m) i := by + simp [branchProduct, branchEdges, Fin.prod_univ_succ] + +lemma normalizer_cons {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (e : Message) (m : Fin n → Message) : + normalizer (branchEdges lam (Fin.cons e m)) = + normalizer (branchEdges lam m)*pairZ lam (branchOutput hl₀ hl₁ m) e := by + unfold normalizer pairZ + change avg (fun i ↦ branchProduct (branchEdges lam (Fin.cons e m)) i) = _ + simp_rw [branchProduct_cons] + change avg (fun i ↦ edgeMessage lam e i*branchProduct (branchEdges lam m) i) = + avg (branchProduct (branchEdges lam m))*avg (fun i ↦ + (branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m))*edgeMessage lam e i) + have hz := ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)) + change normalizer (branchEdges lam m) ≠ 0 at hz + have hid : avg (branchProduct (branchEdges lam m)) = normalizer (branchEdges lam m) := rfl + rw [hid] + dsimp only [avg] + field_simp [hz] + +lemma branchOutput_cons {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (e : Message) (m : Fin n → Message) : + branchOutput hl₀ hl₁ (Fin.cons e m) = pairPosterior hl₀ hl₁ (branchOutput hl₀ hl₁ m) e := by + apply Subtype.ext + funext i + change branchProduct (branchEdges lam (Fin.cons e m)) i/normalizer (branchEdges lam (Fin.cons e m)) = + (branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m))*edgeMessage lam e i/ + pairZ lam (branchOutput hl₀ hl₁ m) e + rw [branchProduct_cons, normalizer_cons hl₀ hl₁] + ring + +lemma finite_succ_integral (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + {f : Message → ℝ} (hf : Continuous f) : + (∫ m, f m ∂(finiteProbability Q hl₀ hl₁ (n+1)).toMeasure) = + ∫ r, (∫ m, pairZ lam r m*f (pairPosterior hl₀ hl₁ r m) ∂Q.probability.toMeasure) + ∂(finiteProbability Q hl₀ hl₁ n).toMeasure := by + have hk : Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2*f (pairPosterior hl₀ hl₁ p.1 p.2)) := + (continuous_pairZ lam).mul (hf.comp (continuous_pairPosterior hl₀ hl₁)) + rw [integral_finiteProbability Q hl₀ hl₁ (n+1) hf.measurable, + integral_pi_cons Q n (f := fun m ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m)) ((continuous_normalizer (n+1) lam).mul (hf.comp (continuous_branchOutput hl₀ hl₁ (n+1)))), + integral_finiteProbability Q hl₀ hl₁ n (continuous_compact_integral hk).measurable] + congr 1 + funext m + simp_rw [normalizer_cons hl₀ hl₁, branchOutput_cons hl₀ hl₁, mul_assoc, integral_const_mul] + +theorem correlationEntropy_succ (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + correlationEntropy Q lam (n+1) = correlationEntropy Q lam n + pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam := by + let c : Message → ℝ := fun r ↦ ∫ e, pairZ lam r e*Real.log (pairZ lam r e) ∂Q.probability.toMeasure + have hc : Continuous c := continuous_compact_integral (continuous_pairEntropy hl₀ hl₁) + have he (m : Fin n → Message) : + (∫ e, normalizer (branchEdges lam (Fin.cons e m))*Real.log (normalizer (branchEdges lam (Fin.cons e m))) + ∂Q.probability.toMeasure) = + normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))+ + normalizer (branchEdges lam m)*c (branchOutput hl₀ hl₁ m) := by + have hp := normalizer_positive (branchEdges_positive hl₀ hl₁ m) + have hpp (e : Message) := pairZ_positive hl₀ hl₁ (branchOutput hl₀ hl₁ m) e + have hid (e : Message) : + normalizer (branchEdges lam (Fin.cons e m))*Real.log (normalizer (branchEdges lam (Fin.cons e m))) = + (normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)))*pairZ lam (branchOutput hl₀ hl₁ m) e+ + normalizer (branchEdges lam m)*(pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e)) := by + rw [normalizer_cons hl₀ hl₁, Real.log_mul (ne_of_gt hp) (ne_of_gt (hpp e))] + ring + simp_rw [hid] + have hz : Continuous (fun e ↦ pairZ lam (branchOutput hl₀ hl₁ m) e) := + (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) + have hj : Continuous (fun e ↦ pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e)) := + (continuous_pairEntropy hl₀ hl₁).comp (continuous_const.prodMk continuous_id) + rw [integral_add (f := fun e ↦ + (normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)))*pairZ lam (branchOutput hl₀ hl₁ m) e) + (g := fun e ↦ normalizer (branchEdges lam m)*(pairZ lam (branchOutput hl₀ hl₁ m) e*Real.log (pairZ lam (branchOutput hl₀ hl₁ m) e))) + ((compact_integrable hz).const_mul _) ((compact_integrable hj).const_mul _), + integral_const_mul, integral_const_mul, integral_pairZ, mul_one] + unfold correlationEntropy + rw [integral_pi_cons Q n (continuous_correlationIntegrand hl₀ hl₁ (n+1))] + simp_rw [he] + rw [integral_add (f := fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) + (g := fun m ↦ normalizer (branchEdges lam m)*c (branchOutput hl₀ hl₁ m)) + (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n)) + (compact_integrable ((continuous_normalizer n lam).mul (hc.comp (continuous_branchOutput hl₀ hl₁ n))))] + congr 1 + exact (integral_finiteProbability Q hl₀ hl₁ n hc.measurable).symm + +lemma xMoment_tangent (r s : Message) : + xMoment r+avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) ≤ xMoment s := by + have hp : 0 ≤ avg (fun i ↦ (s.1 i-r.1 i)^2)/2 := + by + dsimp [avg] + positivity + have he : xMoment s-xMoment r-avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) = + avg (fun i ↦ (s.1 i-r.1 i)^2)/2 := by + dsimp [xMoment, momentX, centered, avg]; ring + linarith + +lemma xMoment_sq_tangent (r s : Message) : + xMoment r^2+avg (fun i ↦ 2*xMoment r*(r.1 i-1)*(s.1 i-r.1 i)) ≤ xMoment s^2 := by + have ht := xMoment_tangent r s + have he : avg (fun i ↦ 2*xMoment r*(r.1 i-1)*(s.1 i-r.1 i)) = + 2*xMoment r*avg (fun i ↦ (r.1 i-1)*(s.1 i-r.1 i)) := by + dsimp [avg]; ring + rw [he] + nlinarith [mul_nonneg (xMoment_nonneg r) (sub_nonneg.mpr ht), sq_nonneg (xMoment s-xMoment r)] + +lemma integral_pair_linear (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (r : Message) (a : Vec) : + (∫ m, pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)) + ∂Q.probability.toMeasure) = 0 := by + have hc (i : Fin 3) : Continuous (fun m : Message ↦ (pairPosterior hl₀ hl₁ r m).1 i) := + (continuous_coordinate i).comp ((continuous_pairPosterior hl₀ hl₁).comp (continuous_const.prodMk continuous_id)) + have hz : Continuous (fun m : Message ↦ pairZ lam r m) := + (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) + have he (m : Message) : pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)) = + avg (fun i ↦ a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m)) := by + dsimp [avg]; ring + simp_rw [he] + rw [integral_avg_measure (f := fun m : Message ↦ fun i ↦ a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m)) + (fun i ↦ compact_integrable (continuous_const.mul ((hz.mul (hc i)).sub (continuous_const.mul hz))))] + have hzero (i : Fin 3) : (∫ m, a i*(pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i-r.1 i*pairZ lam r m) + ∂Q.probability.toMeasure) = 0 := by + rw [integral_const_mul, integral_sub (f := fun m ↦ pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i) + (g := fun m ↦ r.1 i*pairZ lam r m) + (compact_integrable (hz.mul (hc i))) ((compact_integrable hz).const_mul _), + integral_pair_coordinate, integral_const_mul, integral_pairZ] + ring + simp_rw [hzero] + exact avg_const 0 + +lemma integral_pair_tangent_lower (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + {f : Message → ℝ} (hf : Continuous f) (r : Message) (a : Vec) + (ht : ∀ s, f r+avg (fun i ↦ a i*(s.1 i-r.1 i)) ≤ f s) : + f r ≤ ∫ m, pairZ lam r m*f (pairPosterior hl₀ hl₁ r m) ∂Q.probability.toMeasure := by + have hz : Continuous (fun m : Message ↦ pairZ lam r m) := + (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) + have hp : Continuous (fun m : Message ↦ pairPosterior hl₀ hl₁ r m) := + (continuous_pairPosterior hl₀ hl₁).comp (continuous_const.prodMk continuous_id) + have hc : Continuous (fun m : Message ↦ avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i))) := + continuous_avg.comp (continuous_pi (fun i ↦ continuous_const.mul (((continuous_coordinate i).comp hp).sub continuous_const))) + have hh := integral_mono (μ := Q.probability.toMeasure) + (f := fun m ↦ pairZ lam r m*(f r+avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i)))) + (g := fun m ↦ pairZ lam r m*f (pairPosterior hl₀ hl₁ r m)) + (compact_integrable (hz.mul (continuous_const.add hc))) + (compact_integrable (hz.mul (hf.comp hp))) + (fun m ↦ mul_le_mul_of_nonneg_left (ht _) (pairZ_positive hl₀ hl₁ r m).le) + simp_rw [mul_add] at hh + rw [integral_add (f := fun m ↦ pairZ lam r m*f r) + (g := fun m ↦ pairZ lam r m*avg (fun i ↦ a i*((pairPosterior hl₀ hl₁ r m).1 i-r.1 i))) + ((compact_integrable hz).mul_const _) (compact_integrable (hz.mul hc)), + integral_mul_const, integral_pairZ, integral_pair_linear, one_mul, add_zero] at hh + exact hh + +theorem finite_nu_mono (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Monotone (fun n ↦ (finiteLaw Q hl₀ hl₁ n).nu) := by + apply monotone_nat_of_le_succ + intro n + change (∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) ≤ + ∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ (n+1)).toMeasure + rw [finite_succ_integral Q hl₀ hl₁ n (f := fun m ↦ xMoment m^2) (continuous_xMoment.pow 2)] + apply integral_mono (compact_integrable (continuous_xMoment.pow 2)) + (compact_integrable (continuous_compact_integral + ((continuous_pairZ lam).mul ((continuous_xMoment.pow 2).comp (continuous_pairPosterior hl₀ hl₁))))) + intro r + exact integral_pair_tangent_lower Q hl₀ hl₁ (continuous_xMoment.pow 2) r + (fun i ↦ 2*xMoment r*(r.1 i-1)) (xMoment_sq_tangent r) + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/BranchMoments.lean b/lean/OAI/Probability/ThreeStateClauses/BranchMoments.lean index baf994be3b922ba38641c2ff5d90c28c12c04240..8e46de22c79fba2bf4e64280ed6be36503f0bbe1 100644 --- a/lean/OAI/Probability/ThreeStateClauses/BranchMoments.lean +++ b/lean/OAI/Probability/ThreeStateClauses/BranchMoments.lean @@ -1,362 +1,362 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.PosteriorLaw - -namespace OAI - -/-! Branch Moments. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {ι : Type*} [Fintype ι] - -def branchProduct (a : ι → Vec) : Vec := fun i ↦ ∏ j, a j i - -def normalizer (a : ι → Vec) : ℝ := avg (branchProduct a) - -def normalizedProduct (a : ι → Vec) : Vec := fun i ↦ branchProduct a i / normalizer a - -lemma avg_sum (f : ι → Vec) : avg (fun i ↦ ∑ j, f j i) = ∑ j, avg (f j) := by - dsimp only [avg] - rw [← Finset.sum_div] - congr 1 - simp only [Finset.sum_add_distrib] - -lemma avg_div (f : Vec) (c : ℝ) : avg (fun i ↦ f i/c) = avg f/c := by - simp only [avg]; ring - -lemma normalizer_positive {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : 0 < normalizer a := by - have h (i) : 0 < branchProduct a i := Finset.prod_pos (fun j _ ↦ ha j i) - dsimp only [normalizer, avg] - exact div_pos (add_pos (add_pos (h 0) (h 1)) (h 2)) (by norm_num) - -lemma normalizedProduct_positive {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : - PositiveMessage (normalizedProduct a) := by - refine ⟨fun i ↦ div_pos (Finset.prod_pos (fun j _ ↦ ha j i)) (normalizer_positive ha), ?_⟩ - change avg (fun i ↦ branchProduct a i/normalizer a) = 1 - rw [avg_div] - exact div_self (ne_of_gt (normalizer_positive ha)) - -lemma log_normalizedProduct {a : ι → Vec} (ha : ∀ j i, 0 < a j i) (i : Fin 3) : - Real.log (normalizedProduct a i) = (∑ j, Real.log (a j i))-Real.log (normalizer a) := by - rw [normalizedProduct, branchProduct, Real.log_div (ne_of_gt (Finset.prod_pos (fun j _ ↦ ha j i))) - (ne_of_gt (normalizer_positive ha))] - congr 1 - exact Real.log_prod (fun j _ ↦ ne_of_gt (ha j i)) - -lemma logCentered_normalizedProduct {a : ι → Vec} (ha : ∀ j i, 0 < a j i) (i : Fin 3) : - logCentered (normalizedProduct a) i = ∑ j, logCentered (a j) i := by - simp only [logCentered, logAverage, log_normalizedProduct ha] - rw [avg_sub, avg_sum, avg_const, Finset.sum_sub_distrib] - ring - -lemma symEntropy_centeredLog {m : Vec} (hm : avg m = 1) : - symEntropy m = avg (fun i ↦ m i*logCentered m i)/2 := by - have h : avg (fun i ↦ m i*logAverage m) = logAverage m := by - calc - _ = logAverage m*avg m := by simp only [avg]; ring - _ = _ := by rw [hm]; ring - unfold symEntropy logCentered - simp_rw [mul_sub, sub_mul, one_mul] - rw [avg_sub, avg_sub, h] - rfl - -lemma weighted_symEntropy {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : - normalizer a*symEntropy (normalizedProduct a) = - avg (fun i ↦ branchProduct a i*(∑ j, logCentered (a j) i))/2 := by - rw [symEntropy_centeredLog (normalizedProduct_positive ha).2] - simp_rw [logCentered_normalizedProduct ha] - change normalizer a*(avg (fun i ↦ (branchProduct a i/normalizer a)*(∑ j, logCentered (a j) i))/2) = _ - dsimp only [avg] - field_simp [ne_of_gt (normalizer_positive ha)] - -lemma weighted_correction {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : - normalizer a*correction (normalizedProduct a) = - avg (fun i ↦ branchProduct a i*(∑ j, logCentered (a j) i)^2)/2 := by - simp only [correction, logCentered_normalizedProduct ha, normalizedProduct, avg] - field_simp [ne_of_gt (normalizer_positive ha)] - -lemma weighted_info {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : - normalizer a*info (normalizedProduct a) = - avg (fun i ↦ branchProduct a i*(∑ j, Real.log (a j i))) - - normalizer a*Real.log (normalizer a) := by - unfold info - simp_rw [log_normalizedProduct ha] - simp only [normalizedProduct, avg] - field_simp [ne_of_gt (normalizer_positive ha)] - dsimp only [normalizer, avg] - ring - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment - -variable {ι X : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace X] - {μ : Measure X} [SigmaFinite μ] {a u : X → ℝ} - -def weightProduct (a : X → ℝ) (x : ι → X) : ℝ := ∏ i, a (x i) - -omit [MeasurableSpace X] in -lemma select_product (a u : X → ℝ) (x : ι → X) (j : ι) : - weightProduct a x*u (x j) = ∏ i, a (x i)*(if i=j then u (x i) else 1) := by - rw [Finset.prod_mul_distrib] - simp only [weightProduct, Fintype.prod_ite_eq'] - -lemma integrable_weighted_single (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) - (j : ι) : Integrable (fun x : ι → X ↦ weightProduct a x*u (x j)) (Measure.pi fun _ ↦ μ) := by - have hi : ∀ i : ι, Integrable (fun x ↦ a x*(if i=j then u x else 1)) μ := by - intro i - by_cases h : i=j - · simpa [h] using hau - · simpa [h] using ha - simpa only [← select_product] using Integrable.fintype_prod hi - -lemma integral_weighted_single (ha : ∫ x, a x ∂μ = 1) (j : ι) : - (∫ x : ι → X, weightProduct a x*u (x j) ∂(Measure.pi fun _ ↦ μ)) = ∫ x, a x*u x ∂μ := by - simp_rw [select_product] - rw [integral_fintype_prod_eq_prod (fun i x ↦ a x*(if i=j then u x else 1))] - have he (i : ι) : (∫ x, a x*(if i=j then u x else 1) ∂μ) = - if i=j then (∫ x, a x*u x ∂μ) else 1 := by - by_cases h : i=j <;> simp [h, ha] - simp_rw [he] - simp - -omit [MeasurableSpace X] in -lemma select_pair_product (a u : X → ℝ) (x : ι → X) (j k : ι) : - weightProduct a x*(u (x j)*u (x k)) = - ∏ i, a (x i)*(if i=j then u (x i) else 1)*(if i=k then u (x i) else 1) := by - rw [Finset.prod_mul_distrib, Finset.prod_mul_distrib] - simp only [weightProduct, Fintype.prod_ite_eq'] - ring - -lemma integrable_weighted_pair (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) - (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) (j k : ι) : - Integrable (fun x : ι → X ↦ weightProduct a x*(u (x j)*u (x k))) (Measure.pi fun _ ↦ μ) := by - have hi : ∀ i : ι, Integrable (fun x ↦ a x*(if i=j then u x else 1)*(if i=k then u x else 1)) μ := by - intro i - by_cases h : i=j <;> by_cases h' : i=k - · simpa only [ite_eq_left h, ite_eq_left h', pow_two, mul_assoc] using hau₂ - · simpa only [ite_eq_left h, ite_eq_right h', mul_one] using hau - · simpa only [ite_eq_right h, ite_eq_left h', mul_one] using hau - · simpa [h, h'] using ha - simpa only [← select_pair_product] using Integrable.fintype_prod hi - -lemma integral_weighted_pair (ha : ∫ x, a x ∂μ = 1) (j k : ι) : - (∫ x : ι → X, weightProduct a x*(u (x j)*u (x k)) ∂(Measure.pi fun _ ↦ μ)) = - if j=k then (∫ x, a x*u x^2 ∂μ) else (∫ x, a x*u x ∂μ)^2 := by - by_cases hjk : j=k - · subst k - simp only [ite_true, pow_two] - exact integral_weighted_single (u := fun x ↦ u x*u x) ha j - · simp_rw [select_pair_product] - rw [integral_fintype_prod_eq_prod (fun i x ↦ a x*(if i=j then u x else 1)*(if i=k then u x else 1)), ite_eq_right hjk] - have he (i : ι) : (∫ x, a x*(if i=j then u x else 1)*(if i=k then u x else 1) ∂μ) = - (if i=j then (∫ x, a x*u x ∂μ) else 1)*(if i=k then (∫ x, a x*u x ∂μ) else 1) := by - by_cases h : i=j <;> by_cases h' : i=k - · exact (hjk (h.symm.trans h')).elim - · simp only [ite_eq_left h, ite_eq_right h', mul_one] - · simp only [ite_eq_right h, ite_eq_left h', mul_one, one_mul] - · simp only [ite_eq_right h, ite_eq_right h', mul_one, ha] - simp_rw [he] - rw [Finset.prod_mul_distrib] - simp [sq] - -lemma integrable_weighted_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) : - Integrable (fun x : ι → X ↦ weightProduct a x*(∑ j, u (x j))) (Measure.pi fun _ ↦ μ) := by - simp_rw [Finset.mul_sum] - exact integrable_finsetSum _ (fun j _ ↦ integrable_weighted_single ha hau j) - -lemma integral_weighted_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) - (hbal : ∫ x, a x ∂μ = 1) : - (∫ x : ι → X, weightProduct a x*(∑ j, u (x j)) ∂(Measure.pi fun _ ↦ μ)) = - (Fintype.card ι : ℝ)*(∫ x, a x*u x ∂μ) := by - simp_rw [Finset.mul_sum] - rw [integral_finsetSum _ (fun j _ ↦ integrable_weighted_single ha hau j)] - simp only [integral_weighted_single hbal, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - -lemma integrable_weighted_sq_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) - (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) : - Integrable (fun x : ι → X ↦ weightProduct a x*(∑ j, u (x j))^2) (Measure.pi fun _ ↦ μ) := by - have he (x : ι → X) : weightProduct a x*(∑ j, u (x j))^2 = - ∑ j, ∑ k, weightProduct a x*(u (x j)*u (x k)) := by - rw [sq, Finset.sum_mul_sum] - simp_rw [Finset.mul_sum] - simp_rw [he] - exact integrable_finsetSum _ (fun j _ ↦ integrable_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ j k)) - -theorem integral_weighted_sq_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) - (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) (hbal : ∫ x, a x ∂μ = 1) : - (∫ x : ι → X, weightProduct a x*(∑ j, u (x j))^2 ∂(Measure.pi fun _ ↦ μ)) = - (Fintype.card ι : ℝ)*(∫ x, a x*u x^2 ∂μ)+ - ((Fintype.card ι : ℝ)^2-(Fintype.card ι : ℝ))*(∫ x, a x*u x ∂μ)^2 := by - have he (x : ι → X) : weightProduct a x*(∑ j, u (x j))^2 = - ∑ j, ∑ k, weightProduct a x*(u (x j)*u (x k)) := by - rw [sq, Finset.sum_mul_sum] - simp_rw [Finset.mul_sum] - simp_rw [he] - rw [integral_finsetSum _ (fun j _ ↦ integrable_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ j k))] - simp_rw [integral_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ _ k), integral_weighted_pair hbal] - have he' (j k : ι) : (if j=k then (∫ x, a x*u x^2 ∂μ) else (∫ x, a x*u x ∂μ)^2) = - (if j=k then (∫ x, a x*u x^2 ∂μ)-(∫ x, a x*u x ∂μ)^2 else 0)+(∫ x, a x*u x ∂μ)^2 := by - split_ifs <;> ring - simp_rw [he', Finset.sum_add_distrib] - simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - ring - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -abbrev branchEdges {n : ℕ} (lam : ℝ) (m : Fin n → Message) : Fin n → Vec := fun j ↦ edgeMessage lam (m j) - -def finiteBranchExpectation (Q : Law) (lam : ℝ) (n : ℕ) (f : Vec → ℝ) : ℝ := - ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (normalizedProduct (branchEdges lam m)) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) - -def correlationEntropy (Q : Law) (lam : ℝ) (n : ℕ) : ℝ := - ∫ m : Fin n → Message, normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) - -lemma branchEdges_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (m : Fin n → Message) : - ∀ j i, 0 < branchEdges lam m j i := fun j i ↦ (edge_positive hl₀ hl₁ (m j)).1 i - -lemma continuous_branchProduct {n : ℕ} (lam : ℝ) (i : Fin 3) : - Continuous (fun m : Fin n → Message ↦ branchProduct (branchEdges lam m) i) := by - unfold branchProduct branchEdges - exact continuous_finsetProd _ (fun j _ ↦ ((continuous_apply i).comp (continuous_edgeMessage lam)).comp (continuous_apply j)) - -lemma continuous_normalizer (n : ℕ) (lam : ℝ) : - Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)) := - continuous_avg.comp (continuous_pi (continuous_branchProduct lam)) - -lemma continuous_correlationIntegrand {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) := - (continuous_normalizer n lam).mul ((continuous_normalizer n lam).log - (fun m ↦ ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)))) - -lemma integral_normalizer (Q : Law) (lam : ℝ) (n : ℕ) : - (∫ m : Fin n → Message, normalizer (branchEdges lam m) ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 := by - unfold normalizer - rw [integral_avg_measure (fun i ↦ compact_integrable (continuous_branchProduct lam i))] - have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 := by - change (∫ m : Fin n → Message, ∏ j, edgeMessage lam (m j) i ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 - rw [integral_fintype_prod_eq_pow (fun m ↦ edgeMessage lam m i), Q.edge_balanced] - simp - simp_rw [he] - exact avg_const 1 - -lemma correlationEntropy_nonneg (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - 0 ≤ correlationEntropy Q lam n := by - have he (m : Fin n → Message) : normalizer (branchEdges lam m)-1 ≤ - normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)) := by - have hp := normalizer_positive (branchEdges_positive hl₀ hl₁ m) - have h := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le - simpa [mul_sub, ne_of_gt hp] using h - have h := integral_mono (μ := Measure.pi fun _ : Fin n ↦ Q.probability.toMeasure) - (f := fun m ↦ normalizer (branchEdges lam m)-1) - (g := fun m ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) - ((compact_integrable (continuous_normalizer n lam)).sub (integrable_const 1)) - (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n)) he - rw [integral_sub (f := fun m : Fin n → Message ↦ normalizer (branchEdges lam m)) - (g := fun _ ↦ (1:ℝ)) (compact_integrable (continuous_normalizer n lam)) (integrable_const _), - integral_normalizer] at h - simpa [correlationEntropy] using h - -theorem finite_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - finiteBranchExpectation Q lam n symEntropy = - n*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by - have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := - compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) - have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) Q.probability.toMeasure := - compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edge_centeredLog hl₀ hl₁ i)) - unfold finiteBranchExpectation - simp_rw [weighted_symEntropy (branchEdges_positive hl₀ hl₁ _)] - rw [integral_div] - rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)) - (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))] - have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - n*(2*∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by - have h := integral_weighted_sum (ι := Fin n) (ha i) (hau i) (Q.edge_balanced lam i) - rw [Q.edge_centeredLog_mean hl₀ hl₁] at h - simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using h - simp_rw [he] - rw [avg_const] - ring - -theorem finite_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - finiteBranchExpectation Q lam n correction = - n*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - 2*((n:ℝ)^2-n)*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by - have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := - compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) - have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) Q.probability.toMeasure := - compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edge_centeredLog hl₀ hl₁ i)) - have hau₂ (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i^2) Q.probability.toMeasure := - compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - ((continuous_edge_centeredLog hl₀ hl₁ i).pow 2)) - unfold finiteBranchExpectation - simp_rw [weighted_correction (branchEdges_positive hl₀ hl₁ _)] - rw [integral_div] - rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)^2) - (fun i ↦ integrable_weighted_sq_sum (ι := Fin n) (ha i) (hau i) (hau₂ i))] - have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)^2 - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - n*(2*∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - ((n:ℝ)^2-n)*(2*∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by - have h := integral_weighted_sq_sum (ι := Fin n) (ha i) (hau i) (hau₂ i) (Q.edge_balanced lam i) - rw [Q.edge_centeredLog_mean hl₀ hl₁, Q.edge_centeredLog_sq hl₀ hl₁] at h - simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using h - simp_rw [he] - rw [avg_const] - ring - -theorem finite_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - finiteBranchExpectation Q lam n info = - n*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n := by - have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := - compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) - have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*Real.log (edgeMessage lam m i)) Q.probability.toMeasure := - compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edge_log hl₀ hl₁ i)) - unfold finiteBranchExpectation - simp_rw [weighted_info (branchEdges_positive hl₀ hl₁ _)] - rw [integral_sub (f := fun m : Fin n → Message ↦ avg (fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i)))) - (g := fun m ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) - (integrable_avg (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))) - (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n))] - congr 1 - rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i))) - (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))] - have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i)) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - n*(∫ m, edgeMessage lam m i*Real.log (edgeMessage lam m i) ∂Q.probability.toMeasure) := by - simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using integral_weighted_sum (ι := Fin n) (ha i) (hau i) (Q.edge_balanced lam i) - simp_rw [he] - rw [avg_mul, ← integral_avg_measure hau] - rfl - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.PosteriorLaw + +namespace OAI + +/-! Branch Moments. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {ι : Type*} [Fintype ι] + +def branchProduct (a : ι → Vec) : Vec := fun i ↦ ∏ j, a j i + +def normalizer (a : ι → Vec) : ℝ := avg (branchProduct a) + +def normalizedProduct (a : ι → Vec) : Vec := fun i ↦ branchProduct a i / normalizer a + +lemma avg_sum (f : ι → Vec) : avg (fun i ↦ ∑ j, f j i) = ∑ j, avg (f j) := by + dsimp only [avg] + rw [← Finset.sum_div] + congr 1 + simp only [Finset.sum_add_distrib] + +lemma avg_div (f : Vec) (c : ℝ) : avg (fun i ↦ f i/c) = avg f/c := by + simp only [avg]; ring + +lemma normalizer_positive {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : 0 < normalizer a := by + have h (i) : 0 < branchProduct a i := Finset.prod_pos (fun j _ ↦ ha j i) + dsimp only [normalizer, avg] + exact div_pos (add_pos (add_pos (h 0) (h 1)) (h 2)) (by norm_num) + +lemma normalizedProduct_positive {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : + PositiveMessage (normalizedProduct a) := by + refine ⟨fun i ↦ div_pos (Finset.prod_pos (fun j _ ↦ ha j i)) (normalizer_positive ha), ?_⟩ + change avg (fun i ↦ branchProduct a i/normalizer a) = 1 + rw [avg_div] + exact div_self (ne_of_gt (normalizer_positive ha)) + +lemma log_normalizedProduct {a : ι → Vec} (ha : ∀ j i, 0 < a j i) (i : Fin 3) : + Real.log (normalizedProduct a i) = (∑ j, Real.log (a j i))-Real.log (normalizer a) := by + rw [normalizedProduct, branchProduct, Real.log_div (ne_of_gt (Finset.prod_pos (fun j _ ↦ ha j i))) + (ne_of_gt (normalizer_positive ha))] + congr 1 + exact Real.log_prod (fun j _ ↦ ne_of_gt (ha j i)) + +lemma logCentered_normalizedProduct {a : ι → Vec} (ha : ∀ j i, 0 < a j i) (i : Fin 3) : + logCentered (normalizedProduct a) i = ∑ j, logCentered (a j) i := by + simp only [logCentered, logAverage, log_normalizedProduct ha] + rw [avg_sub, avg_sum, avg_const, Finset.sum_sub_distrib] + ring + +lemma symEntropy_centeredLog {m : Vec} (hm : avg m = 1) : + symEntropy m = avg (fun i ↦ m i*logCentered m i)/2 := by + have h : avg (fun i ↦ m i*logAverage m) = logAverage m := by + calc + _ = logAverage m*avg m := by simp only [avg]; ring + _ = _ := by rw [hm]; ring + unfold symEntropy logCentered + simp_rw [mul_sub, sub_mul, one_mul] + rw [avg_sub, avg_sub, h] + rfl + +lemma weighted_symEntropy {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : + normalizer a*symEntropy (normalizedProduct a) = + avg (fun i ↦ branchProduct a i*(∑ j, logCentered (a j) i))/2 := by + rw [symEntropy_centeredLog (normalizedProduct_positive ha).2] + simp_rw [logCentered_normalizedProduct ha] + change normalizer a*(avg (fun i ↦ (branchProduct a i/normalizer a)*(∑ j, logCentered (a j) i))/2) = _ + dsimp only [avg] + field_simp [ne_of_gt (normalizer_positive ha)] + +lemma weighted_correction {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : + normalizer a*correction (normalizedProduct a) = + avg (fun i ↦ branchProduct a i*(∑ j, logCentered (a j) i)^2)/2 := by + simp only [correction, logCentered_normalizedProduct ha, normalizedProduct, avg] + field_simp [ne_of_gt (normalizer_positive ha)] + +lemma weighted_info {a : ι → Vec} (ha : ∀ j i, 0 < a j i) : + normalizer a*info (normalizedProduct a) = + avg (fun i ↦ branchProduct a i*(∑ j, Real.log (a j i))) - + normalizer a*Real.log (normalizer a) := by + unfold info + simp_rw [log_normalizedProduct ha] + simp only [normalizedProduct, avg] + field_simp [ne_of_gt (normalizer_positive ha)] + dsimp only [normalizer, avg] + ring + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment + +variable {ι X : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace X] + {μ : Measure X} [SigmaFinite μ] {a u : X → ℝ} + +def weightProduct (a : X → ℝ) (x : ι → X) : ℝ := ∏ i, a (x i) + +omit [MeasurableSpace X] in +lemma select_product (a u : X → ℝ) (x : ι → X) (j : ι) : + weightProduct a x*u (x j) = ∏ i, a (x i)*(if i=j then u (x i) else 1) := by + rw [Finset.prod_mul_distrib] + simp only [weightProduct, Fintype.prod_ite_eq'] + +lemma integrable_weighted_single (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) + (j : ι) : Integrable (fun x : ι → X ↦ weightProduct a x*u (x j)) (Measure.pi fun _ ↦ μ) := by + have hi : ∀ i : ι, Integrable (fun x ↦ a x*(if i=j then u x else 1)) μ := by + intro i + by_cases h : i=j + · simpa [h] using hau + · simpa [h] using ha + simpa only [← select_product] using Integrable.fintype_prod hi + +lemma integral_weighted_single (ha : ∫ x, a x ∂μ = 1) (j : ι) : + (∫ x : ι → X, weightProduct a x*u (x j) ∂(Measure.pi fun _ ↦ μ)) = ∫ x, a x*u x ∂μ := by + simp_rw [select_product] + rw [integral_fintype_prod_eq_prod (fun i x ↦ a x*(if i=j then u x else 1))] + have he (i : ι) : (∫ x, a x*(if i=j then u x else 1) ∂μ) = + if i=j then (∫ x, a x*u x ∂μ) else 1 := by + by_cases h : i=j <;> simp [h, ha] + simp_rw [he] + simp + +omit [MeasurableSpace X] in +lemma select_pair_product (a u : X → ℝ) (x : ι → X) (j k : ι) : + weightProduct a x*(u (x j)*u (x k)) = + ∏ i, a (x i)*(if i=j then u (x i) else 1)*(if i=k then u (x i) else 1) := by + rw [Finset.prod_mul_distrib, Finset.prod_mul_distrib] + simp only [weightProduct, Fintype.prod_ite_eq'] + ring + +lemma integrable_weighted_pair (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) + (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) (j k : ι) : + Integrable (fun x : ι → X ↦ weightProduct a x*(u (x j)*u (x k))) (Measure.pi fun _ ↦ μ) := by + have hi : ∀ i : ι, Integrable (fun x ↦ a x*(if i=j then u x else 1)*(if i=k then u x else 1)) μ := by + intro i + by_cases h : i=j <;> by_cases h' : i=k + · simpa only [ite_eq_left h, ite_eq_left h', pow_two, mul_assoc] using hau₂ + · simpa only [ite_eq_left h, ite_eq_right h', mul_one] using hau + · simpa only [ite_eq_right h, ite_eq_left h', mul_one] using hau + · simpa [h, h'] using ha + simpa only [← select_pair_product] using Integrable.fintype_prod hi + +lemma integral_weighted_pair (ha : ∫ x, a x ∂μ = 1) (j k : ι) : + (∫ x : ι → X, weightProduct a x*(u (x j)*u (x k)) ∂(Measure.pi fun _ ↦ μ)) = + if j=k then (∫ x, a x*u x^2 ∂μ) else (∫ x, a x*u x ∂μ)^2 := by + by_cases hjk : j=k + · subst k + simp only [ite_true, pow_two] + exact integral_weighted_single (u := fun x ↦ u x*u x) ha j + · simp_rw [select_pair_product] + rw [integral_fintype_prod_eq_prod (fun i x ↦ a x*(if i=j then u x else 1)*(if i=k then u x else 1)), ite_eq_right hjk] + have he (i : ι) : (∫ x, a x*(if i=j then u x else 1)*(if i=k then u x else 1) ∂μ) = + (if i=j then (∫ x, a x*u x ∂μ) else 1)*(if i=k then (∫ x, a x*u x ∂μ) else 1) := by + by_cases h : i=j <;> by_cases h' : i=k + · exact (hjk (h.symm.trans h')).elim + · simp only [ite_eq_left h, ite_eq_right h', mul_one] + · simp only [ite_eq_right h, ite_eq_left h', mul_one, one_mul] + · simp only [ite_eq_right h, ite_eq_right h', mul_one, ha] + simp_rw [he] + rw [Finset.prod_mul_distrib] + simp [sq] + +lemma integrable_weighted_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) : + Integrable (fun x : ι → X ↦ weightProduct a x*(∑ j, u (x j))) (Measure.pi fun _ ↦ μ) := by + simp_rw [Finset.mul_sum] + exact integrable_finsetSum _ (fun j _ ↦ integrable_weighted_single ha hau j) + +lemma integral_weighted_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) + (hbal : ∫ x, a x ∂μ = 1) : + (∫ x : ι → X, weightProduct a x*(∑ j, u (x j)) ∂(Measure.pi fun _ ↦ μ)) = + (Fintype.card ι : ℝ)*(∫ x, a x*u x ∂μ) := by + simp_rw [Finset.mul_sum] + rw [integral_finsetSum _ (fun j _ ↦ integrable_weighted_single ha hau j)] + simp only [integral_weighted_single hbal, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + +lemma integrable_weighted_sq_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) + (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) : + Integrable (fun x : ι → X ↦ weightProduct a x*(∑ j, u (x j))^2) (Measure.pi fun _ ↦ μ) := by + have he (x : ι → X) : weightProduct a x*(∑ j, u (x j))^2 = + ∑ j, ∑ k, weightProduct a x*(u (x j)*u (x k)) := by + rw [sq, Finset.sum_mul_sum] + simp_rw [Finset.mul_sum] + simp_rw [he] + exact integrable_finsetSum _ (fun j _ ↦ integrable_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ j k)) + +theorem integral_weighted_sq_sum (ha : Integrable a μ) (hau : Integrable (fun x ↦ a x*u x) μ) + (hau₂ : Integrable (fun x ↦ a x*u x^2) μ) (hbal : ∫ x, a x ∂μ = 1) : + (∫ x : ι → X, weightProduct a x*(∑ j, u (x j))^2 ∂(Measure.pi fun _ ↦ μ)) = + (Fintype.card ι : ℝ)*(∫ x, a x*u x^2 ∂μ)+ + ((Fintype.card ι : ℝ)^2-(Fintype.card ι : ℝ))*(∫ x, a x*u x ∂μ)^2 := by + have he (x : ι → X) : weightProduct a x*(∑ j, u (x j))^2 = + ∑ j, ∑ k, weightProduct a x*(u (x j)*u (x k)) := by + rw [sq, Finset.sum_mul_sum] + simp_rw [Finset.mul_sum] + simp_rw [he] + rw [integral_finsetSum _ (fun j _ ↦ integrable_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ j k))] + simp_rw [integral_finsetSum _ (fun k _ ↦ integrable_weighted_pair ha hau hau₂ _ k), integral_weighted_pair hbal] + have he' (j k : ι) : (if j=k then (∫ x, a x*u x^2 ∂μ) else (∫ x, a x*u x ∂μ)^2) = + (if j=k then (∫ x, a x*u x^2 ∂μ)-(∫ x, a x*u x ∂μ)^2 else 0)+(∫ x, a x*u x ∂μ)^2 := by + split_ifs <;> ring + simp_rw [he', Finset.sum_add_distrib] + simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + ring + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +abbrev branchEdges {n : ℕ} (lam : ℝ) (m : Fin n → Message) : Fin n → Vec := fun j ↦ edgeMessage lam (m j) + +def finiteBranchExpectation (Q : Law) (lam : ℝ) (n : ℕ) (f : Vec → ℝ) : ℝ := + ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (normalizedProduct (branchEdges lam m)) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) + +def correlationEntropy (Q : Law) (lam : ℝ) (n : ℕ) : ℝ := + ∫ m : Fin n → Message, normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) + +lemma branchEdges_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} (m : Fin n → Message) : + ∀ j i, 0 < branchEdges lam m j i := fun j i ↦ (edge_positive hl₀ hl₁ (m j)).1 i + +lemma continuous_branchProduct {n : ℕ} (lam : ℝ) (i : Fin 3) : + Continuous (fun m : Fin n → Message ↦ branchProduct (branchEdges lam m) i) := by + unfold branchProduct branchEdges + exact continuous_finsetProd _ (fun j _ ↦ ((continuous_apply i).comp (continuous_edgeMessage lam)).comp (continuous_apply j)) + +lemma continuous_normalizer (n : ℕ) (lam : ℝ) : + Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)) := + continuous_avg.comp (continuous_pi (continuous_branchProduct lam)) + +lemma continuous_correlationIntegrand {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) := + (continuous_normalizer n lam).mul ((continuous_normalizer n lam).log + (fun m ↦ ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)))) + +lemma integral_normalizer (Q : Law) (lam : ℝ) (n : ℕ) : + (∫ m : Fin n → Message, normalizer (branchEdges lam m) ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 := by + unfold normalizer + rw [integral_avg_measure (fun i ↦ compact_integrable (continuous_branchProduct lam i))] + have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 := by + change (∫ m : Fin n → Message, ∏ j, edgeMessage lam (m j) i ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 1 + rw [integral_fintype_prod_eq_pow (fun m ↦ edgeMessage lam m i), Q.edge_balanced] + simp + simp_rw [he] + exact avg_const 1 + +lemma correlationEntropy_nonneg (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + 0 ≤ correlationEntropy Q lam n := by + have he (m : Fin n → Message) : normalizer (branchEdges lam m)-1 ≤ + normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m)) := by + have hp := normalizer_positive (branchEdges_positive hl₀ hl₁ m) + have h := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le + simpa [mul_sub, ne_of_gt hp] using h + have h := integral_mono (μ := Measure.pi fun _ : Fin n ↦ Q.probability.toMeasure) + (f := fun m ↦ normalizer (branchEdges lam m)-1) + (g := fun m ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) + ((compact_integrable (continuous_normalizer n lam)).sub (integrable_const 1)) + (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n)) he + rw [integral_sub (f := fun m : Fin n → Message ↦ normalizer (branchEdges lam m)) + (g := fun _ ↦ (1:ℝ)) (compact_integrable (continuous_normalizer n lam)) (integrable_const _), + integral_normalizer] at h + simpa [correlationEntropy] using h + +theorem finite_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + finiteBranchExpectation Q lam n symEntropy = + n*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by + have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := + compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) + have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) Q.probability.toMeasure := + compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edge_centeredLog hl₀ hl₁ i)) + unfold finiteBranchExpectation + simp_rw [weighted_symEntropy (branchEdges_positive hl₀ hl₁ _)] + rw [integral_div] + rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)) + (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))] + have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + n*(2*∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by + have h := integral_weighted_sum (ι := Fin n) (ha i) (hau i) (Q.edge_balanced lam i) + rw [Q.edge_centeredLog_mean hl₀ hl₁] at h + simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using h + simp_rw [he] + rw [avg_const] + ring + +theorem finite_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + finiteBranchExpectation Q lam n correction = + n*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + 2*((n:ℝ)^2-n)*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by + have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := + compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) + have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) Q.probability.toMeasure := + compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edge_centeredLog hl₀ hl₁ i)) + have hau₂ (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i^2) Q.probability.toMeasure := + compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + ((continuous_edge_centeredLog hl₀ hl₁ i).pow 2)) + unfold finiteBranchExpectation + simp_rw [weighted_correction (branchEdges_positive hl₀ hl₁ _)] + rw [integral_div] + rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)^2) + (fun i ↦ integrable_weighted_sq_sum (ι := Fin n) (ha i) (hau i) (hau₂ i))] + have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, logCentered (branchEdges lam m j) i)^2 + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + n*(2*∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + ((n:ℝ)^2-n)*(2*∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by + have h := integral_weighted_sq_sum (ι := Fin n) (ha i) (hau i) (hau₂ i) (Q.edge_balanced lam i) + rw [Q.edge_centeredLog_mean hl₀ hl₁, Q.edge_centeredLog_sq hl₀ hl₁] at h + simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using h + simp_rw [he] + rw [avg_const] + ring + +theorem finite_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + finiteBranchExpectation Q lam n info = + n*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n := by + have ha (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i) Q.probability.toMeasure := + compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam)) + have hau (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*Real.log (edgeMessage lam m i)) Q.probability.toMeasure := + compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edge_log hl₀ hl₁ i)) + unfold finiteBranchExpectation + simp_rw [weighted_info (branchEdges_positive hl₀ hl₁ _)] + rw [integral_sub (f := fun m : Fin n → Message ↦ avg (fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i)))) + (g := fun m ↦ normalizer (branchEdges lam m)*Real.log (normalizer (branchEdges lam m))) + (integrable_avg (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))) + (compact_integrable (continuous_correlationIntegrand hl₀ hl₁ n))] + congr 1 + rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i))) + (fun i ↦ integrable_weighted_sum (ι := Fin n) (ha i) (hau i))] + have he (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*(∑ j, Real.log (branchEdges lam m j i)) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + n*(∫ m, edgeMessage lam m i*Real.log (edgeMessage lam m i) ∂Q.probability.toMeasure) := by + simpa only [Fintype.card_fin, weightProduct, branchProduct, branchEdges] using integral_weighted_sum (ι := Fin n) (ha i) (hau i) (Q.edge_balanced lam i) + simp_rw [he] + rw [avg_mul, ← integral_avg_measure hau] + rfl + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/CompactLimits.lean b/lean/OAI/Probability/ThreeStateClauses/CompactLimits.lean index 6b510c94f4933169e4f332b298be1ba776ab83df..6eee225578f4bbbe7352774632ced76c7873ff77 100644 --- a/lean/OAI/Probability/ThreeStateClauses/CompactLimits.lean +++ b/lean/OAI/Probability/ThreeStateClauses/CompactLimits.lean @@ -1,438 +1,438 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.Degradation -import OAI.Probability.ThreeStateClauses.RegularLaw -import OAI.Probability.ThreeStateClauses.Projection - -namespace OAI - -/-! Compact Limits. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def quadraticGap (z : Message × Message) : ℝ := avg (fun i ↦ (z.1.1 i-z.2.1 i)^2)/2 - -lemma continuous_quadraticGap : Continuous quadraticGap := by - unfold quadraticGap - exact (continuous_avg.comp (continuous_pi (fun i ↦ - ((continuous_coordinate i).comp continuous_fst |>.sub ((continuous_coordinate i).comp continuous_snd)).pow 2))).div_const 2 - -lemma quadraticGap_nonneg (z : Message × Message) : 0 ≤ quadraticGap z := by - dsimp [quadraticGap, avg]; positivity - -lemma quadraticGap_zero_iff (z : Message × Message) : quadraticGap z = 0 ↔ z.1 = z.2 := by - constructor - · intro h - apply Subtype.ext - funext i - have h₀ := sq_nonneg (z.1.1 0-z.2.1 0) - have h₁ := sq_nonneg (z.1.1 1-z.2.1 1) - have h₂ := sq_nonneg (z.1.1 2-z.2.1 2) - dsimp [quadraticGap, avg] at h - fin_cases i <;> dsimp <;> nlinarith - · intro h; simp [quadraticGap, h, avg] - -lemma quadraticGap_expand (z : Message × Message) : - quadraticGap z = xMoment z.1-xMoment z.2- - avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) := by - dsimp [quadraticGap, xMoment, momentX, avg, centered]; ring - -lemma continuous_centeredProduct (i : Fin 3) : - Continuous (fun z : Message × Message ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) := - (((continuous_coordinate i).comp continuous_fst).sub ((continuous_coordinate i).comp continuous_snd)).mul - (((continuous_coordinate i).comp continuous_snd).sub continuous_const) - -section Discrete -variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] - -def degradationCoupling (p : Fin 3 → PMF α) (K : α → PMF β) : ProbabilityMeasure (Message × Message) := - ⟨((kernelJoint (discreteMarginal p) K).map (fun z ↦ - (discreteMessage p z.1, discreteMessage (fun i ↦ (p i).bind K) z.2))).toMeasure, inferInstance⟩ - -lemma integral_degradationCoupling (p : Fin 3 → PMF α) (K : α → PMF β) - {f : Message × Message → ℝ} (hf : Measurable f) : - (∫ z, f z ∂(degradationCoupling p K).toMeasure) = - ∫ z, f (discreteMessage p z.1, discreteMessage (fun i ↦ (p i).bind K) z.2) - ∂(kernelJoint (discreteMarginal p) K).toMeasure := by - change (∫ z, f z ∂(PMF.map _ _).toMeasure) = _ - rw [← PMF.toMeasure_map _ _ (measurable_of_countable _)] - exact integral_map (measurable_of_countable _).aemeasurable hf.aestronglyMeasurable - -omit [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] in -lemma degradationCoupling_fst (p : Fin 3 → PMF α) (K : α → PMF β) : - (degradationCoupling p K).map Prod.fst = discreteProbability p := by - apply Subtype.ext - change Measure.map Prod.fst (PMF.map _ _).toMeasure = Measure.map _ (discreteMarginal p).toMeasure - rw [PMF.toMeasure_map _ _ measurable_fst, PMF.map_comp] - change (PMF.map ((discreteMessage p) ∘ Prod.fst) _).toMeasure = _ - rw [← PMF.map_comp, kernelJoint_fst, PMF.toMeasure_map _ _ (measurable_of_countable _)] - -omit [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] in -lemma degradationCoupling_snd (p : Fin 3 → PMF α) (K : α → PMF β) : - (degradationCoupling p K).map Prod.snd = - discreteProbability (fun i ↦ (p i).bind K) := by - apply Subtype.ext - change Measure.map Prod.snd (PMF.map _ _).toMeasure = Measure.map _ (discreteMarginal _).toMeasure - rw [PMF.toMeasure_map _ _ measurable_snd, PMF.map_comp] - change (PMF.map ((discreteMessage (fun i ↦ (p i).bind K)) ∘ Prod.snd) _).toMeasure = _ - rw [← PMF.map_comp, kernelJoint_snd, ← discreteMarginal_bind, - PMF.toMeasure_map _ _ (measurable_of_countable _)] - -lemma degradationCoupling_centered (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) : - (∫ z, (z.1.1 i-z.2.1 i)*(z.2.1 i-1) ∂(degradationCoupling p K).toMeasure) = 0 := by - rw [integral_degradationCoupling _ _ (continuous_centeredProduct i).measurable] - exact discrete_degradation_centered p K i - (g := fun b ↦ (discreteMessage (fun j ↦ (p j).bind K) b).1 i-1) (C := 2) (fun b ↦ by - apply abs_le.mpr - constructor <;> linarith [coordinate_nonneg (discreteMessage (fun j ↦ (p j).bind K) b) i, - coordinate_le_three (discreteMessage (fun j ↦ (p j).bind K) b) i]) - -lemma degradationCoupling_loss (p : Fin 3 → PMF α) (K : α → PMF β) : - (∫ z, quadraticGap z ∂(degradationCoupling p K).toMeasure) = - (∫ m, xMoment m ∂(discreteProbability p).toMeasure)- - ∫ m, xMoment m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure := by - let C := degradationCoupling p K - have hx : Integrable (fun z : Message × Message ↦ xMoment z.1) C.toMeasure := - compact_integrable (continuous_xMoment.comp continuous_fst) - have hy : Integrable (fun z : Message × Message ↦ xMoment z.2) C.toMeasure := - compact_integrable (continuous_xMoment.comp continuous_snd) - have hc (i : Fin 3) : Integrable (fun z : Message × Message ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) C.toMeasure := - compact_integrable (continuous_centeredProduct i) - have hz : (∫ z, avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) ∂C.toMeasure) = 0 := by - rw [integral_avg_measure hc] - simp only [C, degradationCoupling_centered, avg] - norm_num - simp_rw [quadraticGap_expand] - rw [integral_sub (f := fun z : Message × Message ↦ xMoment z.1-xMoment z.2) - (g := fun z : Message × Message ↦ avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1))) - (hx.sub hy) (integrable_avg hc), - integral_sub (f := fun z : Message × Message ↦ xMoment z.1) - (g := fun z : Message × Message ↦ xMoment z.2) hx hy, hz, sub_zero] - congr 1 - · rw [← degradationCoupling_fst p K] - exact (integral_map measurable_fst.aemeasurable continuous_xMoment.measurable.aestronglyMeasurable).symm - · rw [← degradationCoupling_snd p K] - exact (integral_map measurable_snd.aemeasurable continuous_xMoment.measurable.aestronglyMeasurable).symm - -lemma discrete_degradation_mu (p : Fin 3 → PMF α) (K : α → PMF β) : - (∫ m, xMoment m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure) ≤ - ∫ m, xMoment m ∂(discreteProbability p).toMeasure := by - have h := MeasureTheory.integral_nonneg (μ := (degradationCoupling p K).toMeasure) - (f := quadraticGap) quadraticGap_nonneg - rw [degradationCoupling_loss] at h - linarith - -end Discrete -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def vertex (i : Spin) : Message := - ⟨fun j ↦ if i = j then 3 else 0, fun j ↦ by dsimp; split_ifs <;> norm_num, by - fin_cases i <;> norm_num [avg, Fin.ext_iff]⟩ - -lemma discreteMessage_pure (i : Spin) : discreteMessage (fun j : Spin ↦ PMF.pure j) i = vertex i := by - apply Subtype.ext - funext j - fin_cases i <;> fin_cases j <;> norm_num [discreteMessage, discreteWeight, avg, PMF.pure_apply, vertex, Fin.ext_iff] - -lemma vertex_permute (σ : Equiv.Perm Spin) (i : Spin) : permute σ (vertex i) = vertex (σ.symm i) := by - apply Subtype.ext - funext j - change (if i = σ j then (3:ℝ) else 0) = if σ.symm i = j then 3 else 0 - simp only [σ.symm_apply_eq] - -lemma pureMarginal : discreteMarginal (fun i : Spin ↦ PMF.pure i) = uniformSpin := PMF.bind_pure _ - -lemma integral_rootProbability {f : Message → ℝ} (hf : Measurable f) : - (∫ m, f m ∂(discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure) = - (∑ i : Spin, f (vertex i))/3 := by - rw [integral_discreteProbability _ hf, pureMarginal, PMF.integral_eq_sum] - simp only [discreteMessage_pure, smul_eq_mul, uniformSpin_apply, ENNReal.toReal_div, - ENNReal.toReal_one, ENNReal.toReal_ofNat] - rw [← Finset.mul_sum] - ring - -lemma rootProbability_symmetric (σ : Equiv.Perm Spin) : - MeasurePreserving (permute σ) (discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure - (discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure := by - refine ⟨(continuous_permute σ).measurable, ?_⟩ - have h : (discreteProbability (fun i : Spin ↦ PMF.pure i)).map - (permute σ) = discreteProbability (fun i : Spin ↦ PMF.pure i) := by - apply probability_ext_continuous - intro f hf - change (∫ m, f m ∂Measure.map (permute σ) _) = _ - rw [integral_map (continuous_permute σ).measurable.aemeasurable hf.measurable.aestronglyMeasurable, - integral_rootProbability (f := fun m ↦ f (permute σ m)) (hf.comp (continuous_permute σ)).measurable, - integral_rootProbability hf.measurable] - simp only [vertex_permute] - exact congrArg (fun x : ℝ ↦ x/3) (Equiv.sum_comp σ.symm (fun i ↦ f (vertex i))) - exact congrArg ProbabilityMeasure.toMeasure h - -def rootLaw : Law where - probability := discreteProbability (fun i : Spin ↦ PMF.pure i) - balanced := discreteProbability_balanced _ - symmetric := rootProbability_symmetric - -def regularPosteriorLaw (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : ℕ → Law - | 0 => rootLaw - | ℓ+1 => finiteLaw (regularPosteriorLaw b hl₀ hl₁ ℓ) hl₀ hl₁ b - -lemma regularPosteriorLaw_probability (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (ℓ : ℕ) : - (regularPosteriorLaw b hl₀ hl₁ ℓ).probability = discreteProbability (regularLaw b lam hlam ℓ) := by - induction ℓ with - | zero => rfl - | succ ℓ ih => - exact (discreteBranchLaw_probability (regularLaw b lam hlam ℓ) - (regularPosteriorLaw b hl₀ hl₁ ℓ) ih hl₀ hl₁ hlam b).symm - -lemma regularPosteriorLaw_antitone (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) : Antitone (fun ℓ ↦ (regularPosteriorLaw b hl₀ hl₁ ℓ).mu) := by - apply antitone_nat_of_succ_le - intro ℓ - unfold Law.mu - rw [regularPosteriorLaw_probability b hl₀ hl₁ hlam ℓ, - regularPosteriorLaw_probability b hl₀ hl₁ hlam (ℓ+1)] - have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (regularExpansion b lam hlam ℓ) - simpa only [regularLaw_degrades] using h - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped Topology -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma probability_continuous_integral {X : Type*} [TopologicalSpace X] [CompactSpace X] - [MeasurableSpace X] [OpensMeasurableSpace X] {f : X → ℝ} (hf : Continuous f) : - Continuous (fun P : ProbabilityMeasure X ↦ ∫ x, f x ∂P.toMeasure) := - ProbabilityMeasure.continuous_integral_continuousMap (⟨f, hf⟩ : C(X, ℝ)) - -section Limits -variable {ι : Type*} {F : Filter ι} [F.NeBot] {Q : ι → Law} {P : ProbabilityMeasure Message} - -lemma limit_balanced (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) (j : Fin 3) : - (∫ m, m.1 j ∂P.toMeasure) = 1 := by - have h := (probability_continuous_integral (continuous_coordinate j)).tendsto P |>.comp hP - simp only [Function.comp_def, Law.balanced] at h - exact tendsto_nhds_unique h tendsto_const_nhds - -lemma limit_symmetric (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) - (σ : Equiv.Perm (Fin 3)) : MeasurePreserving (permute σ) P.toMeasure P.toMeasure := by - refine ⟨(continuous_permute σ).measurable, ?_⟩ - have hm := (ProbabilityMeasure.continuous_map (continuous_permute σ)).tendsto P |>.comp hP - have he (i : ι) : (Q i).probability.map (permute σ) = - (Q i).probability := Subtype.ext ((Q i).symmetric σ).map_eq - simp only [Function.comp_def, he] at hm - exact congrArg ProbabilityMeasure.toMeasure (tendsto_nhds_unique hm hP) - -def limitLaw (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) : Law where - probability := P - balanced := limit_balanced hP - symmetric := limit_symmetric hP - -end Limits - -lemma finiteProbability_tendsto {ι : Type*} {F : Filter ι} {Q : ι → Law} {R : Law} - (hQ : Tendsto (fun i ↦ (Q i).probability) F (𝓝 R.probability)) - {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - Tendsto (fun i ↦ finiteProbability (Q i) hl₀ hl₁ n) F (𝓝 (finiteProbability R hl₀ hl₁ n)) := by - apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr - intro f - have hp : Tendsto (fun i ↦ ProbabilityMeasure.pi (fun _ : Fin n ↦ (Q i).probability)) F - (𝓝 (ProbabilityMeasure.pi (fun _ : Fin n ↦ R.probability))) := - ProbabilityMeasure.continuous_pi.tendsto _ |>.comp (tendsto_pi_nhds.mpr (fun _ ↦ hQ)) - have hfun : Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m)) := - (continuous_normalizer n lam).mul (f.continuous.comp (continuous_branchOutput hl₀ hl₁ n)) - have h := (probability_continuous_integral hfun).tendsto _ |>.comp hp - simpa only [Function.comp_def, ProbabilityMeasure.toMeasure_pi, - integral_finiteProbability _ hl₀ hl₁ n f.continuous.measurable] using h - -lemma coupling_diagonal_of_loss_zero (C : ProbabilityMeasure (Message × Message)) - (h : (∫ z, quadraticGap z ∂C.toMeasure) = 0) : - C.map Prod.fst = C.map Prod.snd := by - have he := (integral_eq_zero_iff_of_nonneg quadraticGap_nonneg - (compact_integrable continuous_quadraticGap)).mp h - apply Subtype.ext - exact Measure.map_congr (he.mono (fun z hz ↦ (quadraticGap_zero_iff z).mp hz)) - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped Topology -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma degrading_finite_fixed_point (Q : ℕ → Law) (C : ℕ → ProbabilityMeasure (Message × Message)) - (hfst : ∀ ℓ, (C ℓ).map Prod.fst = (Q ℓ).probability) - (hsnd : ∀ ℓ, (C ℓ).map Prod.snd = (Q (ℓ+1)).probability) - (hloss : ∀ ℓ, (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu) - {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - (hrec : ∀ ℓ, (Q (ℓ+1)).probability = finiteProbability (Q ℓ) hl₀ hl₁ n) : - ∃ R : Law, R.probability = finiteProbability R hl₀ hl₁ n ∧ - Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 R.mu) := by - have hanti : Antitone (fun ℓ ↦ (Q ℓ).mu) := by - apply antitone_nat_of_succ_le - intro ℓ - have h := MeasureTheory.integral_nonneg (μ := (C ℓ).toMeasure) (f := quadraticGap) quadraticGap_nonneg - rw [hloss] at h - linarith - let a := ⨅ ℓ, (Q ℓ).mu - have hlim : Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 a) := - tendsto_atTop_ciInf hanti ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact (Q ℓ).mu_nonneg⟩ - have hdiff : Tendsto (fun ℓ ↦ (Q ℓ).mu-(Q (ℓ+1)).mu) atTop (𝓝 0) := by - simpa using hlim.sub (hlim.comp (tendsto_add_atTop_nat 1)) - obtain ⟨D, hD⟩ := exists_clusterPt_of_compactSpace (Filter.map C atTop) - let F : Filter ℕ := Filter.comap C (𝓝 D) ⊓ atTop - have : F.NeBot := neBot_inf_comap_iff_map'.mpr hD - have hF : F ≤ atTop := inf_le_right - have hC : Tendsto C F (𝓝 D) := tendsto_comap.mono_left inf_le_left - have hgap : (∫ z, quadraticGap z ∂D.toMeasure) = 0 := by - have hg := (probability_continuous_integral continuous_quadraticGap).tendsto D |>.comp hC - simp only [Function.comp_def, hloss] at hg - exact tendsto_nhds_unique hg (hdiff.mono_left hF) - have hdiag := coupling_diagonal_of_loss_zero D hgap - have hP := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (Prod.fst : Message × Message → Message))).tendsto D |>.comp hC - simp only [Function.comp_def, hfst] at hP - let R : Law := limitLaw hP - have hS := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (Prod.snd : Message × Message → Message))).tendsto D |>.comp hC - simp only [Function.comp_def, hsnd] at hS - rw [← hdiag] at hS - have hR : R.probability = finiteProbability R hl₀ hl₁ n := by - have hr := finiteProbability_tendsto (R := R) hP hl₀ hl₁ n - simp only [← hrec] at hr - exact tendsto_nhds_unique hS hr - have hm : a = R.mu := by - have hp := (probability_continuous_integral continuous_xMoment).tendsto R.probability |>.comp hP - exact tendsto_nhds_unique (hlim.mono_left hF) hp - exact ⟨R, hR, hm ▸ hlim⟩ - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def tvMessage (m : Message) : ℝ := avg (fun i ↦ |m.1 i-1|)/2 - -lemma continuous_tvMessage : Continuous tvMessage := - (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).abs))).div_const 2 - -lemma tvMessage_nonneg (m : Message) : 0 ≤ tvMessage m := by - dsimp [tvMessage, avg]; positivity - -lemma tvMessage_formula (m : Message) : - tvMessage m = (∑ i : Spin, |m.1 i/3-(1/3:ℝ)|)/2 := by - simp only [tvMessage, avg, ← sub_div, abs_div, abs_of_pos (by norm_num : (0:ℝ) < 3), Fin.sum_univ_three] - ring - -lemma tvMessage_sq_bound (m : Message) : tvMessage m^2 ≤ xMoment m/2 := by - have h₀ := sq_nonneg (|m.1 0-1|-|m.1 1-1|) - have h₁ := sq_nonneg (|m.1 1-1|-|m.1 2-1|) - have h₂ := sq_nonneg (|m.1 2-1|-|m.1 0-1|) - dsimp [tvMessage, xMoment, momentX, centered, avg] - nlinarith only [h₀,h₁,h₂, sq_abs (m.1 0-1), sq_abs (m.1 1-1), sq_abs (m.1 2-1)] - -lemma integral_tvMessage_sq_bound (P : ProbabilityMeasure Message) : - (∫ m, tvMessage m ∂P.toMeasure)^2 ≤ (∫ m, xMoment m ∂P.toMeasure)/2 := by - let t := ∫ m, tvMessage m ∂P.toMeasure - have hi := compact_integrable continuous_tvMessage (μ := P.toMeasure) - have hi₂ := compact_integrable (continuous_tvMessage.pow 2) (μ := P.toMeasure) - have h := MeasureTheory.integral_nonneg (μ := P.toMeasure) (f := fun m ↦ (tvMessage m-t)^2) - (fun m ↦ sq_nonneg (tvMessage m-t)) - have he : (fun m : Message ↦ (tvMessage m-t)^2) = fun m ↦ tvMessage m^2-2*t*tvMessage m+t^2 := by - funext m; ring - rw [he, integral_add (f := fun m ↦ tvMessage m^2-2*t*tvMessage m) (g := fun _ ↦ t^2) - (hi₂.sub (hi.const_mul _)) (integrable_const _), - integral_sub (f := fun m ↦ tvMessage m^2) (g := fun m ↦ 2*t*tvMessage m) hi₂ (hi.const_mul _), - integral_const_mul] at h - simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, smul_eq_mul, one_mul] at h - have hb := integral_mono (μ := P.toMeasure) hi₂ (compact_integrable (continuous_xMoment.div_const 2)) tvMessage_sq_bound - rw [integral_div] at hb - change (∫ m, tvMessage m^2 ∂P.toMeasure) ≤ (∫ m, xMoment m ∂P.toMeasure)/2 at hb - change 0 ≤ (∫ m, tvMessage m^2 ∂P.toMeasure)-2*t*t+t^2 at h - change t^2 ≤ _ - nlinarith - -lemma main_marginal_eq (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (o : Observation ℓ) : - marginalWeight lam hlam offspring ℓ o = discreteMarginal (observationLaw lam hlam offspring ℓ) o := by - simp only [marginalWeight, jointWeight, discreteMarginal, PMF.bind_apply, tsum_fintype, uniformSpin_apply] - -lemma main_posterior_eq (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (o : Observation ℓ) (ho : discreteWeight (observationLaw lam hlam offspring ℓ) o ≠ 0) (i : Spin) : - posterior lam hlam offspring ℓ o i = (discreteMessage (observationLaw lam hlam offspring ℓ) o).1 i/3 := by - rw [posterior, ENNReal.toReal_div, main_marginal_eq, discreteMarginal_real, jointWeight, - ENNReal.toReal_mul, discrete_coord ho] - norm_num - ring - -lemma tvMessage_le_one (m : Message) : tvMessage m ≤ 1 := by - have hb (i : Spin) : |m.1 i-1| ≤ 2 := abs_le.mpr ⟨by linarith [coordinate_nonneg m i], - by linarith [coordinate_le_three m i]⟩ - dsimp [tvMessage, avg] - linarith [hb 0, hb 1, hb 2] - -lemma integrable_tv_discrete {α : Type*} [Countable α] [MeasurableSpace α] - [MeasurableSingletonClass α] (p : Spin → PMF α) : - Integrable (fun o ↦ tvMessage (discreteMessage p o)) (discreteMarginal p).toMeasure := by - apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 - exact Filter.Eventually.of_forall (fun a ↦ by - rw [Real.norm_eq_abs, abs_of_nonneg (tvMessage_nonneg _)] - exact tvMessage_le_one _) - -lemma advantage_eq_integral (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : - advantage lam hlam offspring ℓ = - ∫ m, tvMessage m ∂(discreteProbability (observationLaw lam hlam offspring ℓ)).toMeasure := by - have hi : Integrable (fun o ↦ tvMessage (discreteMessage (observationLaw lam hlam offspring ℓ) o)) - (discreteMarginal (observationLaw lam hlam offspring ℓ)).toMeasure := - integrable_tv_discrete (observationLaw lam hlam offspring ℓ) - rw [integral_discreteProbability _ continuous_tvMessage.measurable, PMF.integral_eq_tsum _ _ hi] - unfold advantage - apply tsum_congr - intro o - rw [main_marginal_eq, discreteMarginal_real] - simp only [smul_eq_mul] - by_cases ho : discreteWeight (observationLaw lam hlam offspring ℓ) o = 0 - · simp only [ho, zero_mul] - · simp only [main_posterior_eq lam hlam offspring ℓ o ho, tvMessage_formula] - -lemma advantage_nonneg (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : - 0 ≤ advantage lam hlam offspring ℓ := by - rw [advantage_eq_integral] - exact MeasureTheory.integral_nonneg tvMessage_nonneg - -lemma advantage_sq_bound (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : - (advantage lam hlam offspring ℓ)^2 ≤ - (∫ m, xMoment m ∂(discreteProbability (observationLaw lam hlam offspring ℓ)).toMeasure)/2 := by - rw [advantage_eq_integral] - exact integral_tvMessage_sq_bound _ - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.Degradation +import OAI.Probability.ThreeStateClauses.RegularLaw +import OAI.Probability.ThreeStateClauses.Projection + +namespace OAI + +/-! Compact Limits. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def quadraticGap (z : Message × Message) : ℝ := avg (fun i ↦ (z.1.1 i-z.2.1 i)^2)/2 + +lemma continuous_quadraticGap : Continuous quadraticGap := by + unfold quadraticGap + exact (continuous_avg.comp (continuous_pi (fun i ↦ + ((continuous_coordinate i).comp continuous_fst |>.sub ((continuous_coordinate i).comp continuous_snd)).pow 2))).div_const 2 + +lemma quadraticGap_nonneg (z : Message × Message) : 0 ≤ quadraticGap z := by + dsimp [quadraticGap, avg]; positivity + +lemma quadraticGap_zero_iff (z : Message × Message) : quadraticGap z = 0 ↔ z.1 = z.2 := by + constructor + · intro h + apply Subtype.ext + funext i + have h₀ := sq_nonneg (z.1.1 0-z.2.1 0) + have h₁ := sq_nonneg (z.1.1 1-z.2.1 1) + have h₂ := sq_nonneg (z.1.1 2-z.2.1 2) + dsimp [quadraticGap, avg] at h + fin_cases i <;> dsimp <;> nlinarith + · intro h; simp [quadraticGap, h, avg] + +lemma quadraticGap_expand (z : Message × Message) : + quadraticGap z = xMoment z.1-xMoment z.2- + avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) := by + dsimp [quadraticGap, xMoment, momentX, avg, centered]; ring + +lemma continuous_centeredProduct (i : Fin 3) : + Continuous (fun z : Message × Message ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) := + (((continuous_coordinate i).comp continuous_fst).sub ((continuous_coordinate i).comp continuous_snd)).mul + (((continuous_coordinate i).comp continuous_snd).sub continuous_const) + +section Discrete +variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] + +def degradationCoupling (p : Fin 3 → PMF α) (K : α → PMF β) : ProbabilityMeasure (Message × Message) := + ⟨((kernelJoint (discreteMarginal p) K).map (fun z ↦ + (discreteMessage p z.1, discreteMessage (fun i ↦ (p i).bind K) z.2))).toMeasure, inferInstance⟩ + +lemma integral_degradationCoupling (p : Fin 3 → PMF α) (K : α → PMF β) + {f : Message × Message → ℝ} (hf : Measurable f) : + (∫ z, f z ∂(degradationCoupling p K).toMeasure) = + ∫ z, f (discreteMessage p z.1, discreteMessage (fun i ↦ (p i).bind K) z.2) + ∂(kernelJoint (discreteMarginal p) K).toMeasure := by + change (∫ z, f z ∂(PMF.map _ _).toMeasure) = _ + rw [← PMF.toMeasure_map _ _ (measurable_of_countable _)] + exact integral_map (measurable_of_countable _).aemeasurable hf.aestronglyMeasurable + +omit [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] in +lemma degradationCoupling_fst (p : Fin 3 → PMF α) (K : α → PMF β) : + (degradationCoupling p K).map Prod.fst = discreteProbability p := by + apply Subtype.ext + change Measure.map Prod.fst (PMF.map _ _).toMeasure = Measure.map _ (discreteMarginal p).toMeasure + rw [PMF.toMeasure_map _ _ measurable_fst, PMF.map_comp] + change (PMF.map ((discreteMessage p) ∘ Prod.fst) _).toMeasure = _ + rw [← PMF.map_comp, kernelJoint_fst, PMF.toMeasure_map _ _ (measurable_of_countable _)] + +omit [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] in +lemma degradationCoupling_snd (p : Fin 3 → PMF α) (K : α → PMF β) : + (degradationCoupling p K).map Prod.snd = + discreteProbability (fun i ↦ (p i).bind K) := by + apply Subtype.ext + change Measure.map Prod.snd (PMF.map _ _).toMeasure = Measure.map _ (discreteMarginal _).toMeasure + rw [PMF.toMeasure_map _ _ measurable_snd, PMF.map_comp] + change (PMF.map ((discreteMessage (fun i ↦ (p i).bind K)) ∘ Prod.snd) _).toMeasure = _ + rw [← PMF.map_comp, kernelJoint_snd, ← discreteMarginal_bind, + PMF.toMeasure_map _ _ (measurable_of_countable _)] + +lemma degradationCoupling_centered (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) : + (∫ z, (z.1.1 i-z.2.1 i)*(z.2.1 i-1) ∂(degradationCoupling p K).toMeasure) = 0 := by + rw [integral_degradationCoupling _ _ (continuous_centeredProduct i).measurable] + exact discrete_degradation_centered p K i + (g := fun b ↦ (discreteMessage (fun j ↦ (p j).bind K) b).1 i-1) (C := 2) (fun b ↦ by + apply abs_le.mpr + constructor <;> linarith [coordinate_nonneg (discreteMessage (fun j ↦ (p j).bind K) b) i, + coordinate_le_three (discreteMessage (fun j ↦ (p j).bind K) b) i]) + +lemma degradationCoupling_loss (p : Fin 3 → PMF α) (K : α → PMF β) : + (∫ z, quadraticGap z ∂(degradationCoupling p K).toMeasure) = + (∫ m, xMoment m ∂(discreteProbability p).toMeasure)- + ∫ m, xMoment m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure := by + let C := degradationCoupling p K + have hx : Integrable (fun z : Message × Message ↦ xMoment z.1) C.toMeasure := + compact_integrable (continuous_xMoment.comp continuous_fst) + have hy : Integrable (fun z : Message × Message ↦ xMoment z.2) C.toMeasure := + compact_integrable (continuous_xMoment.comp continuous_snd) + have hc (i : Fin 3) : Integrable (fun z : Message × Message ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) C.toMeasure := + compact_integrable (continuous_centeredProduct i) + have hz : (∫ z, avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1)) ∂C.toMeasure) = 0 := by + rw [integral_avg_measure hc] + simp only [C, degradationCoupling_centered, avg] + norm_num + simp_rw [quadraticGap_expand] + rw [integral_sub (f := fun z : Message × Message ↦ xMoment z.1-xMoment z.2) + (g := fun z : Message × Message ↦ avg (fun i ↦ (z.1.1 i-z.2.1 i)*(z.2.1 i-1))) + (hx.sub hy) (integrable_avg hc), + integral_sub (f := fun z : Message × Message ↦ xMoment z.1) + (g := fun z : Message × Message ↦ xMoment z.2) hx hy, hz, sub_zero] + congr 1 + · rw [← degradationCoupling_fst p K] + exact (integral_map measurable_fst.aemeasurable continuous_xMoment.measurable.aestronglyMeasurable).symm + · rw [← degradationCoupling_snd p K] + exact (integral_map measurable_snd.aemeasurable continuous_xMoment.measurable.aestronglyMeasurable).symm + +lemma discrete_degradation_mu (p : Fin 3 → PMF α) (K : α → PMF β) : + (∫ m, xMoment m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure) ≤ + ∫ m, xMoment m ∂(discreteProbability p).toMeasure := by + have h := MeasureTheory.integral_nonneg (μ := (degradationCoupling p K).toMeasure) + (f := quadraticGap) quadraticGap_nonneg + rw [degradationCoupling_loss] at h + linarith + +end Discrete +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def vertex (i : Spin) : Message := + ⟨fun j ↦ if i = j then 3 else 0, fun j ↦ by dsimp; split_ifs <;> norm_num, by + fin_cases i <;> norm_num [avg, Fin.ext_iff]⟩ + +lemma discreteMessage_pure (i : Spin) : discreteMessage (fun j : Spin ↦ PMF.pure j) i = vertex i := by + apply Subtype.ext + funext j + fin_cases i <;> fin_cases j <;> norm_num [discreteMessage, discreteWeight, avg, PMF.pure_apply, vertex, Fin.ext_iff] + +lemma vertex_permute (σ : Equiv.Perm Spin) (i : Spin) : permute σ (vertex i) = vertex (σ.symm i) := by + apply Subtype.ext + funext j + change (if i = σ j then (3:ℝ) else 0) = if σ.symm i = j then 3 else 0 + simp only [σ.symm_apply_eq] + +lemma pureMarginal : discreteMarginal (fun i : Spin ↦ PMF.pure i) = uniformSpin := PMF.bind_pure _ + +lemma integral_rootProbability {f : Message → ℝ} (hf : Measurable f) : + (∫ m, f m ∂(discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure) = + (∑ i : Spin, f (vertex i))/3 := by + rw [integral_discreteProbability _ hf, pureMarginal, PMF.integral_eq_sum] + simp only [discreteMessage_pure, smul_eq_mul, uniformSpin_apply, ENNReal.toReal_div, + ENNReal.toReal_one, ENNReal.toReal_ofNat] + rw [← Finset.mul_sum] + ring + +lemma rootProbability_symmetric (σ : Equiv.Perm Spin) : + MeasurePreserving (permute σ) (discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure + (discreteProbability (fun i : Spin ↦ PMF.pure i)).toMeasure := by + refine ⟨(continuous_permute σ).measurable, ?_⟩ + have h : (discreteProbability (fun i : Spin ↦ PMF.pure i)).map + (permute σ) = discreteProbability (fun i : Spin ↦ PMF.pure i) := by + apply probability_ext_continuous + intro f hf + change (∫ m, f m ∂Measure.map (permute σ) _) = _ + rw [integral_map (continuous_permute σ).measurable.aemeasurable hf.measurable.aestronglyMeasurable, + integral_rootProbability (f := fun m ↦ f (permute σ m)) (hf.comp (continuous_permute σ)).measurable, + integral_rootProbability hf.measurable] + simp only [vertex_permute] + exact congrArg (fun x : ℝ ↦ x/3) (Equiv.sum_comp σ.symm (fun i ↦ f (vertex i))) + exact congrArg ProbabilityMeasure.toMeasure h + +def rootLaw : Law where + probability := discreteProbability (fun i : Spin ↦ PMF.pure i) + balanced := discreteProbability_balanced _ + symmetric := rootProbability_symmetric + +def regularPosteriorLaw (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : ℕ → Law + | 0 => rootLaw + | ℓ+1 => finiteLaw (regularPosteriorLaw b hl₀ hl₁ ℓ) hl₀ hl₁ b + +lemma regularPosteriorLaw_probability (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (ℓ : ℕ) : + (regularPosteriorLaw b hl₀ hl₁ ℓ).probability = discreteProbability (regularLaw b lam hlam ℓ) := by + induction ℓ with + | zero => rfl + | succ ℓ ih => + exact (discreteBranchLaw_probability (regularLaw b lam hlam ℓ) + (regularPosteriorLaw b hl₀ hl₁ ℓ) ih hl₀ hl₁ hlam b).symm + +lemma regularPosteriorLaw_antitone (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) : Antitone (fun ℓ ↦ (regularPosteriorLaw b hl₀ hl₁ ℓ).mu) := by + apply antitone_nat_of_succ_le + intro ℓ + unfold Law.mu + rw [regularPosteriorLaw_probability b hl₀ hl₁ hlam ℓ, + regularPosteriorLaw_probability b hl₀ hl₁ hlam (ℓ+1)] + have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (regularExpansion b lam hlam ℓ) + simpa only [regularLaw_degrades] using h + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped Topology +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma probability_continuous_integral {X : Type*} [TopologicalSpace X] [CompactSpace X] + [MeasurableSpace X] [OpensMeasurableSpace X] {f : X → ℝ} (hf : Continuous f) : + Continuous (fun P : ProbabilityMeasure X ↦ ∫ x, f x ∂P.toMeasure) := + ProbabilityMeasure.continuous_integral_continuousMap (⟨f, hf⟩ : C(X, ℝ)) + +section Limits +variable {ι : Type*} {F : Filter ι} [F.NeBot] {Q : ι → Law} {P : ProbabilityMeasure Message} + +lemma limit_balanced (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) (j : Fin 3) : + (∫ m, m.1 j ∂P.toMeasure) = 1 := by + have h := (probability_continuous_integral (continuous_coordinate j)).tendsto P |>.comp hP + simp only [Function.comp_def, Law.balanced] at h + exact tendsto_nhds_unique h tendsto_const_nhds + +lemma limit_symmetric (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) + (σ : Equiv.Perm (Fin 3)) : MeasurePreserving (permute σ) P.toMeasure P.toMeasure := by + refine ⟨(continuous_permute σ).measurable, ?_⟩ + have hm := (ProbabilityMeasure.continuous_map (continuous_permute σ)).tendsto P |>.comp hP + have he (i : ι) : (Q i).probability.map (permute σ) = + (Q i).probability := Subtype.ext ((Q i).symmetric σ).map_eq + simp only [Function.comp_def, he] at hm + exact congrArg ProbabilityMeasure.toMeasure (tendsto_nhds_unique hm hP) + +def limitLaw (hP : Tendsto (fun i ↦ (Q i).probability) F (𝓝 P)) : Law where + probability := P + balanced := limit_balanced hP + symmetric := limit_symmetric hP + +end Limits + +lemma finiteProbability_tendsto {ι : Type*} {F : Filter ι} {Q : ι → Law} {R : Law} + (hQ : Tendsto (fun i ↦ (Q i).probability) F (𝓝 R.probability)) + {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + Tendsto (fun i ↦ finiteProbability (Q i) hl₀ hl₁ n) F (𝓝 (finiteProbability R hl₀ hl₁ n)) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro f + have hp : Tendsto (fun i ↦ ProbabilityMeasure.pi (fun _ : Fin n ↦ (Q i).probability)) F + (𝓝 (ProbabilityMeasure.pi (fun _ : Fin n ↦ R.probability))) := + ProbabilityMeasure.continuous_pi.tendsto _ |>.comp (tendsto_pi_nhds.mpr (fun _ ↦ hQ)) + have hfun : Continuous (fun m : Fin n → Message ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m)) := + (continuous_normalizer n lam).mul (f.continuous.comp (continuous_branchOutput hl₀ hl₁ n)) + have h := (probability_continuous_integral hfun).tendsto _ |>.comp hp + simpa only [Function.comp_def, ProbabilityMeasure.toMeasure_pi, + integral_finiteProbability _ hl₀ hl₁ n f.continuous.measurable] using h + +lemma coupling_diagonal_of_loss_zero (C : ProbabilityMeasure (Message × Message)) + (h : (∫ z, quadraticGap z ∂C.toMeasure) = 0) : + C.map Prod.fst = C.map Prod.snd := by + have he := (integral_eq_zero_iff_of_nonneg quadraticGap_nonneg + (compact_integrable continuous_quadraticGap)).mp h + apply Subtype.ext + exact Measure.map_congr (he.mono (fun z hz ↦ (quadraticGap_zero_iff z).mp hz)) + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped Topology +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma degrading_finite_fixed_point (Q : ℕ → Law) (C : ℕ → ProbabilityMeasure (Message × Message)) + (hfst : ∀ ℓ, (C ℓ).map Prod.fst = (Q ℓ).probability) + (hsnd : ∀ ℓ, (C ℓ).map Prod.snd = (Q (ℓ+1)).probability) + (hloss : ∀ ℓ, (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu) + {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + (hrec : ∀ ℓ, (Q (ℓ+1)).probability = finiteProbability (Q ℓ) hl₀ hl₁ n) : + ∃ R : Law, R.probability = finiteProbability R hl₀ hl₁ n ∧ + Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 R.mu) := by + have hanti : Antitone (fun ℓ ↦ (Q ℓ).mu) := by + apply antitone_nat_of_succ_le + intro ℓ + have h := MeasureTheory.integral_nonneg (μ := (C ℓ).toMeasure) (f := quadraticGap) quadraticGap_nonneg + rw [hloss] at h + linarith + let a := ⨅ ℓ, (Q ℓ).mu + have hlim : Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 a) := + tendsto_atTop_ciInf hanti ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact (Q ℓ).mu_nonneg⟩ + have hdiff : Tendsto (fun ℓ ↦ (Q ℓ).mu-(Q (ℓ+1)).mu) atTop (𝓝 0) := by + simpa using hlim.sub (hlim.comp (tendsto_add_atTop_nat 1)) + obtain ⟨D, hD⟩ := exists_clusterPt_of_compactSpace (Filter.map C atTop) + let F : Filter ℕ := Filter.comap C (𝓝 D) ⊓ atTop + have : F.NeBot := neBot_inf_comap_iff_map'.mpr hD + have hF : F ≤ atTop := inf_le_right + have hC : Tendsto C F (𝓝 D) := tendsto_comap.mono_left inf_le_left + have hgap : (∫ z, quadraticGap z ∂D.toMeasure) = 0 := by + have hg := (probability_continuous_integral continuous_quadraticGap).tendsto D |>.comp hC + simp only [Function.comp_def, hloss] at hg + exact tendsto_nhds_unique hg (hdiff.mono_left hF) + have hdiag := coupling_diagonal_of_loss_zero D hgap + have hP := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (Prod.fst : Message × Message → Message))).tendsto D |>.comp hC + simp only [Function.comp_def, hfst] at hP + let R : Law := limitLaw hP + have hS := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (Prod.snd : Message × Message → Message))).tendsto D |>.comp hC + simp only [Function.comp_def, hsnd] at hS + rw [← hdiag] at hS + have hR : R.probability = finiteProbability R hl₀ hl₁ n := by + have hr := finiteProbability_tendsto (R := R) hP hl₀ hl₁ n + simp only [← hrec] at hr + exact tendsto_nhds_unique hS hr + have hm : a = R.mu := by + have hp := (probability_continuous_integral continuous_xMoment).tendsto R.probability |>.comp hP + exact tendsto_nhds_unique (hlim.mono_left hF) hp + exact ⟨R, hR, hm ▸ hlim⟩ + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def tvMessage (m : Message) : ℝ := avg (fun i ↦ |m.1 i-1|)/2 + +lemma continuous_tvMessage : Continuous tvMessage := + (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).abs))).div_const 2 + +lemma tvMessage_nonneg (m : Message) : 0 ≤ tvMessage m := by + dsimp [tvMessage, avg]; positivity + +lemma tvMessage_formula (m : Message) : + tvMessage m = (∑ i : Spin, |m.1 i/3-(1/3:ℝ)|)/2 := by + simp only [tvMessage, avg, ← sub_div, abs_div, abs_of_pos (by norm_num : (0:ℝ) < 3), Fin.sum_univ_three] + ring + +lemma tvMessage_sq_bound (m : Message) : tvMessage m^2 ≤ xMoment m/2 := by + have h₀ := sq_nonneg (|m.1 0-1|-|m.1 1-1|) + have h₁ := sq_nonneg (|m.1 1-1|-|m.1 2-1|) + have h₂ := sq_nonneg (|m.1 2-1|-|m.1 0-1|) + dsimp [tvMessage, xMoment, momentX, centered, avg] + nlinarith only [h₀,h₁,h₂, sq_abs (m.1 0-1), sq_abs (m.1 1-1), sq_abs (m.1 2-1)] + +lemma integral_tvMessage_sq_bound (P : ProbabilityMeasure Message) : + (∫ m, tvMessage m ∂P.toMeasure)^2 ≤ (∫ m, xMoment m ∂P.toMeasure)/2 := by + let t := ∫ m, tvMessage m ∂P.toMeasure + have hi := compact_integrable continuous_tvMessage (μ := P.toMeasure) + have hi₂ := compact_integrable (continuous_tvMessage.pow 2) (μ := P.toMeasure) + have h := MeasureTheory.integral_nonneg (μ := P.toMeasure) (f := fun m ↦ (tvMessage m-t)^2) + (fun m ↦ sq_nonneg (tvMessage m-t)) + have he : (fun m : Message ↦ (tvMessage m-t)^2) = fun m ↦ tvMessage m^2-2*t*tvMessage m+t^2 := by + funext m; ring + rw [he, integral_add (f := fun m ↦ tvMessage m^2-2*t*tvMessage m) (g := fun _ ↦ t^2) + (hi₂.sub (hi.const_mul _)) (integrable_const _), + integral_sub (f := fun m ↦ tvMessage m^2) (g := fun m ↦ 2*t*tvMessage m) hi₂ (hi.const_mul _), + integral_const_mul] at h + simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, smul_eq_mul, one_mul] at h + have hb := integral_mono (μ := P.toMeasure) hi₂ (compact_integrable (continuous_xMoment.div_const 2)) tvMessage_sq_bound + rw [integral_div] at hb + change (∫ m, tvMessage m^2 ∂P.toMeasure) ≤ (∫ m, xMoment m ∂P.toMeasure)/2 at hb + change 0 ≤ (∫ m, tvMessage m^2 ∂P.toMeasure)-2*t*t+t^2 at h + change t^2 ≤ _ + nlinarith + +lemma main_marginal_eq (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (o : Observation ℓ) : + marginalWeight lam hlam offspring ℓ o = discreteMarginal (observationLaw lam hlam offspring ℓ) o := by + simp only [marginalWeight, jointWeight, discreteMarginal, PMF.bind_apply, tsum_fintype, uniformSpin_apply] + +lemma main_posterior_eq (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (o : Observation ℓ) (ho : discreteWeight (observationLaw lam hlam offspring ℓ) o ≠ 0) (i : Spin) : + posterior lam hlam offspring ℓ o i = (discreteMessage (observationLaw lam hlam offspring ℓ) o).1 i/3 := by + rw [posterior, ENNReal.toReal_div, main_marginal_eq, discreteMarginal_real, jointWeight, + ENNReal.toReal_mul, discrete_coord ho] + norm_num + ring + +lemma tvMessage_le_one (m : Message) : tvMessage m ≤ 1 := by + have hb (i : Spin) : |m.1 i-1| ≤ 2 := abs_le.mpr ⟨by linarith [coordinate_nonneg m i], + by linarith [coordinate_le_three m i]⟩ + dsimp [tvMessage, avg] + linarith [hb 0, hb 1, hb 2] + +lemma integrable_tv_discrete {α : Type*} [Countable α] [MeasurableSpace α] + [MeasurableSingletonClass α] (p : Spin → PMF α) : + Integrable (fun o ↦ tvMessage (discreteMessage p o)) (discreteMarginal p).toMeasure := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Filter.Eventually.of_forall (fun a ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (tvMessage_nonneg _)] + exact tvMessage_le_one _) + +lemma advantage_eq_integral (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : + advantage lam hlam offspring ℓ = + ∫ m, tvMessage m ∂(discreteProbability (observationLaw lam hlam offspring ℓ)).toMeasure := by + have hi : Integrable (fun o ↦ tvMessage (discreteMessage (observationLaw lam hlam offspring ℓ) o)) + (discreteMarginal (observationLaw lam hlam offspring ℓ)).toMeasure := + integrable_tv_discrete (observationLaw lam hlam offspring ℓ) + rw [integral_discreteProbability _ continuous_tvMessage.measurable, PMF.integral_eq_tsum _ _ hi] + unfold advantage + apply tsum_congr + intro o + rw [main_marginal_eq, discreteMarginal_real] + simp only [smul_eq_mul] + by_cases ho : discreteWeight (observationLaw lam hlam offspring ℓ) o = 0 + · simp only [ho, zero_mul] + · simp only [main_posterior_eq lam hlam offspring ℓ o ho, tvMessage_formula] + +lemma advantage_nonneg (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : + 0 ≤ advantage lam hlam offspring ℓ := by + rw [advantage_eq_integral] + exact MeasureTheory.integral_nonneg tvMessage_nonneg + +lemma advantage_sq_bound (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) (ℓ : ℕ) : + (advantage lam hlam offspring ℓ)^2 ≤ + (∫ m, xMoment m ∂(discreteProbability (observationLaw lam hlam offspring ℓ)).toMeasure)/2 := by + rw [advantage_eq_integral] + exact integral_tvMessage_sq_bound _ + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Correlation.lean b/lean/OAI/Probability/ThreeStateClauses/Correlation.lean index 1156b1116601f5cfae9acab11ab3a0d211d52c7d..f0c96e3d5bf81e56c3c802088e3faa410a899baa 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Correlation.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Correlation.lean @@ -1,316 +1,316 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RadialCalculus -import OAI.Probability.ThreeStateClauses.BranchMoments - -namespace OAI - -/-! Correlation. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set -namespace ThreeState.TreeClauses.Positive -open Radial - -lemma log_cubic_lower {z : ℝ} (hz : -1 < z) : - z+z^2/2-z^3/6 ≤ (1+z)*Real.log (1+z) := by - let f : ℝ → ℝ := fun r ↦ r*Real.log r-(r-1)-(r-1)^2/2+(r-1)^3/6 - let g : ℝ → ℝ := fun r ↦ Real.log r-(r-1)+(r-1)^2/2 - have df (r : ℝ) (hr : 0 < r) : HasDerivAt f (g r) r := by - have hd := ((((hasDerivAt_id r).mul (Real.hasDerivAt_log (ne_of_gt hr))).sub - ((hasDerivAt_id r).sub_const 1)).sub - ((((hasDerivAt_id r).sub_const 1).pow 2).div_const 2)).add - ((((hasDerivAt_id r).sub_const 1).pow 3).div_const 6) - apply hd.congr_deriv - dsimp [g] - field_simp [ne_of_gt hr] - ring - have dg (r : ℝ) (hr : 0 < r) : HasDerivAt g ((r-1)^2/r) r := by - have hd := ((Real.hasDerivAt_log (ne_of_gt hr)).sub ((hasDerivAt_id r).sub_const 1)).add - ((((hasDerivAt_id r).sub_const 1).pow 2).div_const 2) - apply hd.congr_deriv - dsimp only [id] - field_simp [ne_of_gt hr] - ring - have gm {a b : ℝ} (ha : 0 < a) : MonotoneOn g (Icc a b) := by - apply monotoneOn_Icc_of_hasDerivAt_nonneg (fun r hr ↦ dg r (lt_of_lt_of_le ha hr.1)) - intro r hr - exact div_nonneg (sq_nonneg _) (lt_trans ha hr.1).le - have hg₁ : g 1 = 0 := by simp [g] - have hf₁ : f 1 = 0 := by simp [f] - have hmin (r : ℝ) (hr : 0 < r) : 0 ≤ f r := by - rcases le_total 1 r with h | h - · have hg (t : ℝ) (ht : t ∈ Icc 1 r) : 0 ≤ g t := by - have hh := gm (b := r) (by norm_num : (0:ℝ) < 1) ⟨le_rfl, h⟩ ht ht.1 - rwa [hg₁] at hh - have hmono : MonotoneOn f (Icc 1 r) := - monotoneOn_Icc_of_hasDerivAt_nonneg (fun t ht ↦ df t (by linarith [ht.1])) - (fun t ht ↦ hg t ⟨ht.1.le, ht.2.le⟩) - have hh := hmono ⟨le_rfl, h⟩ ⟨h, le_rfl⟩ h - rwa [hf₁] at hh - · have hg (t : ℝ) (ht : t ∈ Icc r 1) : g t ≤ 0 := by - have hh := gm (b := 1) hr ht ⟨h, le_rfl⟩ ht.2 - rwa [hg₁] at hh - have hmono : MonotoneOn (fun t ↦ -f t) (Icc r 1) := - monotoneOn_Icc_of_hasDerivAt_nonneg (fun t ht ↦ (df t (lt_of_lt_of_le hr ht.1)).neg) - (fun t ht ↦ neg_nonneg.mpr (hg t ⟨ht.1.le, ht.2.le⟩)) - have hh := hmono ⟨le_rfl, h⟩ ⟨h, le_rfl⟩ h - change -f r ≤ -f 1 at hh - rw [hf₁] at hh - linarith - have hh := hmin (1+z) (by linarith) - dsimp [f] at hh - nlinarith - -def orbit (v : Vec) : Fin 6 → Vec := - ![ ![v 0,v 1,v 2], ![v 0,v 2,v 1], ![v 1,v 0,v 2], - ![v 1,v 2,v 0], ![v 2,v 0,v 1], ![v 2,v 1,v 0] ] - -def avgSix (f : Fin 6 → ℝ) : ℝ := - (f 0+f 1+f 2+f 3+f 4+f 5)/6 - -def dotAvg (v w : Vec) : ℝ := avg (fun i ↦ v i*w i) - -lemma avgSix_dot {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : - avgSix (fun k ↦ dotAvg v (orbit w k)) = 0 := by - simp [avgSix, dotAvg, orbit, avg, third_eq hv, third_eq hw] - ring - -lemma avgSix_dot_sq {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : - avgSix (fun k ↦ dotAvg v (orbit w k)^2) = 2*momentX v*momentX w := by - simp [avgSix, dotAvg, orbit, momentX, avg, third_eq hv, third_eq hw] - ring - -lemma avgSix_dot_cube {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : - avgSix (fun k ↦ dotAvg v (orbit w k)^3) = 2*momentY v*momentY w := by - simp [avgSix, dotAvg, orbit, momentY, avg, third_eq hv, third_eq hw] - ring - -lemma avgSix_mono {f g : Fin 6 → ℝ} (h : ∀ k, f k ≤ g k) : avgSix f ≤ avgSix g := by - dsimp [avgSix] - linarith [h 0, h 1, h 2, h 3, h 4, h 5] - -theorem correlation_orbit_lower {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) - (hZ : ∀ k, -1 < dotAvg v (orbit w k)) : - 3*momentX v*momentX w-momentY v*momentY w ≤ - 3*avgSix (fun k ↦ (1+dotAvg v (orbit w k))*Real.log (1+dotAvg v (orbit w k))) := by - have h := avgSix_mono (fun k ↦ log_cubic_lower (hZ k)) - have he : avgSix (fun k ↦ dotAvg v (orbit w k)+dotAvg v (orbit w k)^2/2-dotAvg v (orbit w k)^3/6) = - avgSix (fun k ↦ dotAvg v (orbit w k))+ - avgSix (fun k ↦ dotAvg v (orbit w k)^2)/2- - avgSix (fun k ↦ dotAvg v (orbit w k)^3)/6 := by - dsimp [avgSix]; ring - rw [he, avgSix_dot hv hw, avgSix_dot_sq hv hw, avgSix_dot_cube hv hw] at h - linarith - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def pairZ (lam : ℝ) (r m : Message) : ℝ := avg (fun i ↦ r.1 i*edgeMessage lam m i) - -def pairPosterior {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (r m : Message) : Message := by - have hz : 0 < pairZ lam r m := by - have h := avg_mono (fun i ↦ mul_le_mul_of_nonneg_left (edge_lower hl₀ m i) (coordinate_nonneg r i)) - have he : avg (fun i ↦ r.1 i*(1-lam)) = 1-lam := by - calc - _ = (1-lam)*avg r.1 := by simp only [avg]; ring - _ = _ := by rw [r.2.2]; ring - rw [he] at h - exact lt_of_lt_of_le (sub_pos.mpr hl₁) h - refine ⟨fun i ↦ r.1 i*edgeMessage lam m i/pairZ lam r m, ?_, ?_⟩ - · intro i - exact div_nonneg (mul_nonneg (coordinate_nonneg r i) ((edge_positive hl₀ hl₁ m).1 i).le) hz.le - · rw [avg_div] - exact div_self (ne_of_gt hz) - -lemma pairZ_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (r m : Message) : 1-lam ≤ pairZ lam r m := by - have h := avg_mono (fun i ↦ mul_le_mul_of_nonneg_left (edge_lower hl₀ m i) (coordinate_nonneg r i)) - have he : avg (fun i ↦ r.1 i*(1-lam)) = 1-lam := by - calc - _ = (1-lam)*avg r.1 := by simp only [avg]; ring - _ = _ := by rw [r.2.2]; ring - rwa [he] at h - -lemma pairZ_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (r m : Message) : - 0 < pairZ lam r m := lt_of_lt_of_le (sub_pos.mpr hl₁) (pairZ_lower hl₀ r m) - -lemma continuous_pairZ (lam : ℝ) : Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2) := - continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).comp continuous_fst).mul - (((continuous_apply i).comp (continuous_edgeMessage lam)).comp continuous_snd))) - -lemma continuous_pairPosterior {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Continuous (fun p : Message × Message ↦ pairPosterior hl₀ hl₁ p.1 p.2) := by - apply Continuous.subtype_mk - exact continuous_pi (fun i ↦ (((continuous_coordinate i).comp continuous_fst).mul - (((continuous_apply i).comp (continuous_edgeMessage lam)).comp continuous_snd)).div - (continuous_pairZ lam) (fun p ↦ ne_of_gt (pairZ_positive hl₀ hl₁ p.1 p.2))) - -lemma pairZ_dot (lam : ℝ) (r m : Message) : pairZ lam r m = - 1+dotAvg (centered r.1) (centered (edgeMessage lam m)) := by - have hr := r.2.2 - have hm := m.2.2 - dsimp only [pairZ, dotAvg, centered, edgeMessage, edge, avg] at * - linear_combination hr + lam*hm - -lemma integral_pairZ (Q : Law) (lam : ℝ) (r : Message) : - (∫ m, pairZ lam r m ∂Q.probability.toMeasure) = 1 := by - have hi (i : Fin 3) : Integrable (fun m ↦ r.1 i*edgeMessage lam m i) Q.probability.toMeasure := - (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))).const_mul _ - unfold pairZ - rw [integral_avg_measure hi] - simp_rw [integral_const_mul, Q.edge_balanced, mul_one] - exact r.2.2 - -lemma integral_pair_coordinate (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (r : Message) (i : Fin 3) : - (∫ m, pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i ∂Q.probability.toMeasure) = r.1 i := by - have he (m : Message) : pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i = r.1 i*edgeMessage lam m i := by - change pairZ lam r m*(r.1 i*edgeMessage lam m i/pairZ lam r m) = _ - field_simp [ne_of_gt (pairZ_positive hl₀ hl₁ r m)] - simp_rw [he] - rw [integral_const_mul, Q.edge_balanced, mul_one] - -lemma continuous_pairEntropy {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2*Real.log (pairZ lam p.1 p.2)) := - (continuous_pairZ lam).mul ((continuous_pairZ lam).log (fun p ↦ ne_of_gt (pairZ_positive hl₀ hl₁ p.1 p.2))) - -def pairCorrelation (R Q : Law) (lam : ℝ) : ℝ := - ∫ r, (∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) ∂ R.probability.toMeasure - -lemma pairCorrelation_nonneg (R Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - 0 ≤ pairCorrelation R Q lam := by - apply integral_nonneg - intro r - have hc : Continuous (fun m ↦ pairZ lam r m) := (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) - have hi := compact_integrable hc (μ := Q.probability.toMeasure) - have he : Integrable (fun m : Message ↦ pairZ lam r m*Real.log (pairZ lam r m)) Q.probability.toMeasure := - compact_integrable ((continuous_pairEntropy hl₀ hl₁).comp (continuous_const.prodMk continuous_id)) - have h := integral_mono (f := fun m : Message ↦ pairZ lam r m-1) - (g := fun m ↦ pairZ lam r m*Real.log (pairZ lam r m)) (hi.sub (integrable_const _)) he - (fun m ↦ by - have hp := pairZ_positive hl₀ hl₁ r m - have hh := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le - simpa [mul_sub, ne_of_gt hp] using hh) - rw [integral_sub (f := fun m ↦ pairZ lam r m) (g := fun _ ↦ (1:ℝ)) hi (integrable_const _), integral_pairZ] at h - simpa using h - -def orbitIndex : Fin 6 → (Fin 3 → Fin 3) := - ![ ![0,1,2], ![0,2,1], ![1,0,2], ![1,2,0], ![2,0,1], ![2,1,0] ] - -def orbitPerm (k : Fin 6) : Equiv.Perm (Fin 3) := - Equiv.ofBijective (orbitIndex k) (by fin_cases k <;> decide) - -lemma orbitPerm_apply (v : Vec) (k : Fin 6) (i : Fin 3) : - v (orbitPerm k i) = orbit v k i := by - fin_cases k <;> fin_cases i <;> rfl - -lemma pairZ_orbit (lam : ℝ) (r m : Message) (k : Fin 6) : - pairZ lam r (permute (orbitPerm k) m) = - 1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k) := by - rw [pairZ_dot] - congr 2 - funext i - change edgeMessage lam m (orbitPerm k i)-1 = _ - exact orbitPerm_apply (centered (edgeMessage lam m)) k i - -lemma integral_avgSix_measure {X : Type*} [MeasurableSpace X] {ρ : Measure X} - {f : X → Fin 6 → ℝ} (hf : ∀ k, Integrable (fun x ↦ f x k) ρ) : - (∫ x, avgSix (f x) ∂ρ) = avgSix (fun k ↦ ∫ x, f x k ∂ρ) := by - unfold avgSix - rw [integral_div, - integral_add (f := fun x ↦ f x 0+f x 1+f x 2+f x 3+f x 4) (g := fun x ↦ f x 5) - (((((hf 0).add (hf 1)).add (hf 2)).add (hf 3)).add (hf 4)) (hf 5), - integral_add (f := fun x ↦ f x 0+f x 1+f x 2+f x 3) (g := fun x ↦ f x 4) - ((((hf 0).add (hf 1)).add (hf 2)).add (hf 3)) (hf 4), - integral_add (f := fun x ↦ f x 0+f x 1+f x 2) (g := fun x ↦ f x 3) - (((hf 0).add (hf 1)).add (hf 2)) (hf 3), - integral_add (f := fun x ↦ f x 0+f x 1) (g := fun x ↦ f x 2) - ((hf 0).add (hf 1)) (hf 2), - integral_add (f := fun x ↦ f x 0) (g := fun x ↦ f x 1) (hf 0) (hf 1)] - -lemma xMoment_edge (lam : ℝ) (m : Message) : - momentX (centered (edgeMessage lam m)) = lam^2*xMoment m := by - dsimp [momentX, centered, edgeMessage, edge, xMoment, avg] - ring - -lemma yMoment_edge (lam : ℝ) (m : Message) : - momentY (centered (edgeMessage lam m)) = lam^3*yMoment m := by - dsimp [momentY, centered, edgeMessage, edge, yMoment, avg] - ring - -lemma pairCorrelation_increment_at (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (r : Message) : - 3*lam^2*Q.mu*xMoment r-lam^3*Q.eta*yMoment r ≤ - 3*(∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) := by - let f : Message → Fin 6 → ℝ := fun m k ↦ - pairZ lam r (permute (orbitPerm k) m)*Real.log (pairZ lam r (permute (orbitPerm k) m)) - have hi (k : Fin 6) : Integrable (fun m ↦ f m k) Q.probability.toMeasure := - compact_integrable ((continuous_pairEntropy hl₀ hl₁).comp - (continuous_const.prodMk (continuous_permute (orbitPerm k)))) - have havg : Integrable (fun m ↦ avgSix (f m)) Q.probability.toMeasure := - (((((hi 0).add (hi 1)).add (hi 2)).add (hi 3)).add (hi 4) |>.add (hi 5)).div_const 6 - have hpoint (m : Message) : 3*lam^2*xMoment r*xMoment m-lam^3*yMoment r*yMoment m ≤ - 3*avgSix (f m) := by - have h := correlation_orbit_lower (message_centered_avg r) - (show avg (centered (edgeMessage lam m)) = 0 from by - change avg (fun i ↦ edgeMessage lam m i-1) = 0 - rw [avg_sub, avg_const, (edge_positive hl₀ hl₁ m).2]; ring) - (fun k ↦ by - have hh := pairZ_positive hl₀ hl₁ r (permute (orbitPerm k) m) - rw [pairZ_orbit] at hh; linarith) - simp only [xMoment_edge, yMoment_edge] at h - have he : (fun k ↦ (1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k))* - Real.log (1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k))) = f m := by - funext k; dsimp only [f]; rw [pairZ_orbit] - rw [he] at h - change 3*xMoment r*(lam^2*xMoment m)-yMoment r*(lam^3*yMoment m) ≤ _ at h - nlinarith [h] - have h := integral_mono - (((compact_integrable continuous_xMoment).const_mul (3*lam^2*xMoment r)).sub - ((compact_integrable continuous_yMoment).const_mul (lam^3*yMoment r))) - (havg.const_mul 3) hpoint - simp only [Pi.sub_apply] at h - rw [integral_sub (f := fun m ↦ 3*lam^2*xMoment r*xMoment m) - (g := fun m ↦ lam^3*yMoment r*yMoment m) - ((compact_integrable continuous_xMoment).const_mul _) - ((compact_integrable continuous_yMoment).const_mul _), - integral_const_mul, integral_const_mul, integral_const_mul, integral_avgSix_measure hi] at h - have hev (k : Fin 6) : (∫ m, f m k ∂Q.probability.toMeasure) = - ∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure := by - exact (show MeasurePreserving (permuteMeasurableEquiv (orbitPerm k)) - Q.probability.toMeasure Q.probability.toMeasure from Q.symmetric _).integral_comp' (fun m ↦ pairZ lam r m*Real.log (pairZ lam r m)) - simp_rw [hev] at h - dsimp only [avgSix] at h - change 3*lam^2*xMoment r*Q.mu-lam^3*yMoment r*Q.eta ≤ _ at h - linarith - -theorem pairCorrelation_increment (R Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - 3*lam^2*Q.mu*R.mu-lam^3*Q.eta*R.eta ≤ 3*pairCorrelation R Q lam := by - have hc : Integrable (fun r ↦ ∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) - R.probability.toMeasure := - (compact_integrable (continuous_pairEntropy hl₀ hl₁) - (μ := R.probability.toMeasure.prod Q.probability.toMeasure)).integral_prod_left - have h := integral_mono - (((compact_integrable continuous_xMoment).const_mul (3*lam^2*Q.mu)).sub - ((compact_integrable continuous_yMoment).const_mul (lam^3*Q.eta))) (hc.const_mul 3) - (pairCorrelation_increment_at Q hl₀ hl₁) - simp only [Pi.sub_apply] at h - rw [integral_sub (f := fun r ↦ 3*lam^2*Q.mu*xMoment r) - (g := fun r ↦ lam^3*Q.eta*yMoment r) - ((compact_integrable continuous_xMoment).const_mul _) - ((compact_integrable continuous_yMoment).const_mul _), - integral_const_mul, integral_const_mul, integral_const_mul] at h - exact h - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RadialCalculus +import OAI.Probability.ThreeStateClauses.BranchMoments + +namespace OAI + +/-! Correlation. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set +namespace ThreeState.TreeClauses.Positive +open Radial + +lemma log_cubic_lower {z : ℝ} (hz : -1 < z) : + z+z^2/2-z^3/6 ≤ (1+z)*Real.log (1+z) := by + let f : ℝ → ℝ := fun r ↦ r*Real.log r-(r-1)-(r-1)^2/2+(r-1)^3/6 + let g : ℝ → ℝ := fun r ↦ Real.log r-(r-1)+(r-1)^2/2 + have df (r : ℝ) (hr : 0 < r) : HasDerivAt f (g r) r := by + have hd := ((((hasDerivAt_id r).mul (Real.hasDerivAt_log (ne_of_gt hr))).sub + ((hasDerivAt_id r).sub_const 1)).sub + ((((hasDerivAt_id r).sub_const 1).pow 2).div_const 2)).add + ((((hasDerivAt_id r).sub_const 1).pow 3).div_const 6) + apply hd.congr_deriv + dsimp [g] + field_simp [ne_of_gt hr] + ring + have dg (r : ℝ) (hr : 0 < r) : HasDerivAt g ((r-1)^2/r) r := by + have hd := ((Real.hasDerivAt_log (ne_of_gt hr)).sub ((hasDerivAt_id r).sub_const 1)).add + ((((hasDerivAt_id r).sub_const 1).pow 2).div_const 2) + apply hd.congr_deriv + dsimp only [id] + field_simp [ne_of_gt hr] + ring + have gm {a b : ℝ} (ha : 0 < a) : MonotoneOn g (Icc a b) := by + apply monotoneOn_Icc_of_hasDerivAt_nonneg (fun r hr ↦ dg r (lt_of_lt_of_le ha hr.1)) + intro r hr + exact div_nonneg (sq_nonneg _) (lt_trans ha hr.1).le + have hg₁ : g 1 = 0 := by simp [g] + have hf₁ : f 1 = 0 := by simp [f] + have hmin (r : ℝ) (hr : 0 < r) : 0 ≤ f r := by + rcases le_total 1 r with h | h + · have hg (t : ℝ) (ht : t ∈ Icc 1 r) : 0 ≤ g t := by + have hh := gm (b := r) (by norm_num : (0:ℝ) < 1) ⟨le_rfl, h⟩ ht ht.1 + rwa [hg₁] at hh + have hmono : MonotoneOn f (Icc 1 r) := + monotoneOn_Icc_of_hasDerivAt_nonneg (fun t ht ↦ df t (by linarith [ht.1])) + (fun t ht ↦ hg t ⟨ht.1.le, ht.2.le⟩) + have hh := hmono ⟨le_rfl, h⟩ ⟨h, le_rfl⟩ h + rwa [hf₁] at hh + · have hg (t : ℝ) (ht : t ∈ Icc r 1) : g t ≤ 0 := by + have hh := gm (b := 1) hr ht ⟨h, le_rfl⟩ ht.2 + rwa [hg₁] at hh + have hmono : MonotoneOn (fun t ↦ -f t) (Icc r 1) := + monotoneOn_Icc_of_hasDerivAt_nonneg (fun t ht ↦ (df t (lt_of_lt_of_le hr ht.1)).neg) + (fun t ht ↦ neg_nonneg.mpr (hg t ⟨ht.1.le, ht.2.le⟩)) + have hh := hmono ⟨le_rfl, h⟩ ⟨h, le_rfl⟩ h + change -f r ≤ -f 1 at hh + rw [hf₁] at hh + linarith + have hh := hmin (1+z) (by linarith) + dsimp [f] at hh + nlinarith + +def orbit (v : Vec) : Fin 6 → Vec := + ![ ![v 0,v 1,v 2], ![v 0,v 2,v 1], ![v 1,v 0,v 2], + ![v 1,v 2,v 0], ![v 2,v 0,v 1], ![v 2,v 1,v 0] ] + +def avgSix (f : Fin 6 → ℝ) : ℝ := + (f 0+f 1+f 2+f 3+f 4+f 5)/6 + +def dotAvg (v w : Vec) : ℝ := avg (fun i ↦ v i*w i) + +lemma avgSix_dot {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : + avgSix (fun k ↦ dotAvg v (orbit w k)) = 0 := by + simp [avgSix, dotAvg, orbit, avg, third_eq hv, third_eq hw] + ring + +lemma avgSix_dot_sq {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : + avgSix (fun k ↦ dotAvg v (orbit w k)^2) = 2*momentX v*momentX w := by + simp [avgSix, dotAvg, orbit, momentX, avg, third_eq hv, third_eq hw] + ring + +lemma avgSix_dot_cube {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) : + avgSix (fun k ↦ dotAvg v (orbit w k)^3) = 2*momentY v*momentY w := by + simp [avgSix, dotAvg, orbit, momentY, avg, third_eq hv, third_eq hw] + ring + +lemma avgSix_mono {f g : Fin 6 → ℝ} (h : ∀ k, f k ≤ g k) : avgSix f ≤ avgSix g := by + dsimp [avgSix] + linarith [h 0, h 1, h 2, h 3, h 4, h 5] + +theorem correlation_orbit_lower {v w : Vec} (hv : avg v = 0) (hw : avg w = 0) + (hZ : ∀ k, -1 < dotAvg v (orbit w k)) : + 3*momentX v*momentX w-momentY v*momentY w ≤ + 3*avgSix (fun k ↦ (1+dotAvg v (orbit w k))*Real.log (1+dotAvg v (orbit w k))) := by + have h := avgSix_mono (fun k ↦ log_cubic_lower (hZ k)) + have he : avgSix (fun k ↦ dotAvg v (orbit w k)+dotAvg v (orbit w k)^2/2-dotAvg v (orbit w k)^3/6) = + avgSix (fun k ↦ dotAvg v (orbit w k))+ + avgSix (fun k ↦ dotAvg v (orbit w k)^2)/2- + avgSix (fun k ↦ dotAvg v (orbit w k)^3)/6 := by + dsimp [avgSix]; ring + rw [he, avgSix_dot hv hw, avgSix_dot_sq hv hw, avgSix_dot_cube hv hw] at h + linarith + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def pairZ (lam : ℝ) (r m : Message) : ℝ := avg (fun i ↦ r.1 i*edgeMessage lam m i) + +def pairPosterior {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (r m : Message) : Message := by + have hz : 0 < pairZ lam r m := by + have h := avg_mono (fun i ↦ mul_le_mul_of_nonneg_left (edge_lower hl₀ m i) (coordinate_nonneg r i)) + have he : avg (fun i ↦ r.1 i*(1-lam)) = 1-lam := by + calc + _ = (1-lam)*avg r.1 := by simp only [avg]; ring + _ = _ := by rw [r.2.2]; ring + rw [he] at h + exact lt_of_lt_of_le (sub_pos.mpr hl₁) h + refine ⟨fun i ↦ r.1 i*edgeMessage lam m i/pairZ lam r m, ?_, ?_⟩ + · intro i + exact div_nonneg (mul_nonneg (coordinate_nonneg r i) ((edge_positive hl₀ hl₁ m).1 i).le) hz.le + · rw [avg_div] + exact div_self (ne_of_gt hz) + +lemma pairZ_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (r m : Message) : 1-lam ≤ pairZ lam r m := by + have h := avg_mono (fun i ↦ mul_le_mul_of_nonneg_left (edge_lower hl₀ m i) (coordinate_nonneg r i)) + have he : avg (fun i ↦ r.1 i*(1-lam)) = 1-lam := by + calc + _ = (1-lam)*avg r.1 := by simp only [avg]; ring + _ = _ := by rw [r.2.2]; ring + rwa [he] at h + +lemma pairZ_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (r m : Message) : + 0 < pairZ lam r m := lt_of_lt_of_le (sub_pos.mpr hl₁) (pairZ_lower hl₀ r m) + +lemma continuous_pairZ (lam : ℝ) : Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2) := + continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).comp continuous_fst).mul + (((continuous_apply i).comp (continuous_edgeMessage lam)).comp continuous_snd))) + +lemma continuous_pairPosterior {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Continuous (fun p : Message × Message ↦ pairPosterior hl₀ hl₁ p.1 p.2) := by + apply Continuous.subtype_mk + exact continuous_pi (fun i ↦ (((continuous_coordinate i).comp continuous_fst).mul + (((continuous_apply i).comp (continuous_edgeMessage lam)).comp continuous_snd)).div + (continuous_pairZ lam) (fun p ↦ ne_of_gt (pairZ_positive hl₀ hl₁ p.1 p.2))) + +lemma pairZ_dot (lam : ℝ) (r m : Message) : pairZ lam r m = + 1+dotAvg (centered r.1) (centered (edgeMessage lam m)) := by + have hr := r.2.2 + have hm := m.2.2 + dsimp only [pairZ, dotAvg, centered, edgeMessage, edge, avg] at * + linear_combination hr + lam*hm + +lemma integral_pairZ (Q : Law) (lam : ℝ) (r : Message) : + (∫ m, pairZ lam r m ∂Q.probability.toMeasure) = 1 := by + have hi (i : Fin 3) : Integrable (fun m ↦ r.1 i*edgeMessage lam m i) Q.probability.toMeasure := + (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))).const_mul _ + unfold pairZ + rw [integral_avg_measure hi] + simp_rw [integral_const_mul, Q.edge_balanced, mul_one] + exact r.2.2 + +lemma integral_pair_coordinate (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (r : Message) (i : Fin 3) : + (∫ m, pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i ∂Q.probability.toMeasure) = r.1 i := by + have he (m : Message) : pairZ lam r m*(pairPosterior hl₀ hl₁ r m).1 i = r.1 i*edgeMessage lam m i := by + change pairZ lam r m*(r.1 i*edgeMessage lam m i/pairZ lam r m) = _ + field_simp [ne_of_gt (pairZ_positive hl₀ hl₁ r m)] + simp_rw [he] + rw [integral_const_mul, Q.edge_balanced, mul_one] + +lemma continuous_pairEntropy {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Continuous (fun p : Message × Message ↦ pairZ lam p.1 p.2*Real.log (pairZ lam p.1 p.2)) := + (continuous_pairZ lam).mul ((continuous_pairZ lam).log (fun p ↦ ne_of_gt (pairZ_positive hl₀ hl₁ p.1 p.2))) + +def pairCorrelation (R Q : Law) (lam : ℝ) : ℝ := + ∫ r, (∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) ∂ R.probability.toMeasure + +lemma pairCorrelation_nonneg (R Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + 0 ≤ pairCorrelation R Q lam := by + apply integral_nonneg + intro r + have hc : Continuous (fun m ↦ pairZ lam r m) := (continuous_pairZ lam).comp (continuous_const.prodMk continuous_id) + have hi := compact_integrable hc (μ := Q.probability.toMeasure) + have he : Integrable (fun m : Message ↦ pairZ lam r m*Real.log (pairZ lam r m)) Q.probability.toMeasure := + compact_integrable ((continuous_pairEntropy hl₀ hl₁).comp (continuous_const.prodMk continuous_id)) + have h := integral_mono (f := fun m : Message ↦ pairZ lam r m-1) + (g := fun m ↦ pairZ lam r m*Real.log (pairZ lam r m)) (hi.sub (integrable_const _)) he + (fun m ↦ by + have hp := pairZ_positive hl₀ hl₁ r m + have hh := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos hp) hp.le + simpa [mul_sub, ne_of_gt hp] using hh) + rw [integral_sub (f := fun m ↦ pairZ lam r m) (g := fun _ ↦ (1:ℝ)) hi (integrable_const _), integral_pairZ] at h + simpa using h + +def orbitIndex : Fin 6 → (Fin 3 → Fin 3) := + ![ ![0,1,2], ![0,2,1], ![1,0,2], ![1,2,0], ![2,0,1], ![2,1,0] ] + +def orbitPerm (k : Fin 6) : Equiv.Perm (Fin 3) := + Equiv.ofBijective (orbitIndex k) (by fin_cases k <;> decide) + +lemma orbitPerm_apply (v : Vec) (k : Fin 6) (i : Fin 3) : + v (orbitPerm k i) = orbit v k i := by + fin_cases k <;> fin_cases i <;> rfl + +lemma pairZ_orbit (lam : ℝ) (r m : Message) (k : Fin 6) : + pairZ lam r (permute (orbitPerm k) m) = + 1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k) := by + rw [pairZ_dot] + congr 2 + funext i + change edgeMessage lam m (orbitPerm k i)-1 = _ + exact orbitPerm_apply (centered (edgeMessage lam m)) k i + +lemma integral_avgSix_measure {X : Type*} [MeasurableSpace X] {ρ : Measure X} + {f : X → Fin 6 → ℝ} (hf : ∀ k, Integrable (fun x ↦ f x k) ρ) : + (∫ x, avgSix (f x) ∂ρ) = avgSix (fun k ↦ ∫ x, f x k ∂ρ) := by + unfold avgSix + rw [integral_div, + integral_add (f := fun x ↦ f x 0+f x 1+f x 2+f x 3+f x 4) (g := fun x ↦ f x 5) + (((((hf 0).add (hf 1)).add (hf 2)).add (hf 3)).add (hf 4)) (hf 5), + integral_add (f := fun x ↦ f x 0+f x 1+f x 2+f x 3) (g := fun x ↦ f x 4) + ((((hf 0).add (hf 1)).add (hf 2)).add (hf 3)) (hf 4), + integral_add (f := fun x ↦ f x 0+f x 1+f x 2) (g := fun x ↦ f x 3) + (((hf 0).add (hf 1)).add (hf 2)) (hf 3), + integral_add (f := fun x ↦ f x 0+f x 1) (g := fun x ↦ f x 2) + ((hf 0).add (hf 1)) (hf 2), + integral_add (f := fun x ↦ f x 0) (g := fun x ↦ f x 1) (hf 0) (hf 1)] + +lemma xMoment_edge (lam : ℝ) (m : Message) : + momentX (centered (edgeMessage lam m)) = lam^2*xMoment m := by + dsimp [momentX, centered, edgeMessage, edge, xMoment, avg] + ring + +lemma yMoment_edge (lam : ℝ) (m : Message) : + momentY (centered (edgeMessage lam m)) = lam^3*yMoment m := by + dsimp [momentY, centered, edgeMessage, edge, yMoment, avg] + ring + +lemma pairCorrelation_increment_at (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (r : Message) : + 3*lam^2*Q.mu*xMoment r-lam^3*Q.eta*yMoment r ≤ + 3*(∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) := by + let f : Message → Fin 6 → ℝ := fun m k ↦ + pairZ lam r (permute (orbitPerm k) m)*Real.log (pairZ lam r (permute (orbitPerm k) m)) + have hi (k : Fin 6) : Integrable (fun m ↦ f m k) Q.probability.toMeasure := + compact_integrable ((continuous_pairEntropy hl₀ hl₁).comp + (continuous_const.prodMk (continuous_permute (orbitPerm k)))) + have havg : Integrable (fun m ↦ avgSix (f m)) Q.probability.toMeasure := + (((((hi 0).add (hi 1)).add (hi 2)).add (hi 3)).add (hi 4) |>.add (hi 5)).div_const 6 + have hpoint (m : Message) : 3*lam^2*xMoment r*xMoment m-lam^3*yMoment r*yMoment m ≤ + 3*avgSix (f m) := by + have h := correlation_orbit_lower (message_centered_avg r) + (show avg (centered (edgeMessage lam m)) = 0 from by + change avg (fun i ↦ edgeMessage lam m i-1) = 0 + rw [avg_sub, avg_const, (edge_positive hl₀ hl₁ m).2]; ring) + (fun k ↦ by + have hh := pairZ_positive hl₀ hl₁ r (permute (orbitPerm k) m) + rw [pairZ_orbit] at hh; linarith) + simp only [xMoment_edge, yMoment_edge] at h + have he : (fun k ↦ (1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k))* + Real.log (1+dotAvg (centered r.1) (orbit (centered (edgeMessage lam m)) k))) = f m := by + funext k; dsimp only [f]; rw [pairZ_orbit] + rw [he] at h + change 3*xMoment r*(lam^2*xMoment m)-yMoment r*(lam^3*yMoment m) ≤ _ at h + nlinarith [h] + have h := integral_mono + (((compact_integrable continuous_xMoment).const_mul (3*lam^2*xMoment r)).sub + ((compact_integrable continuous_yMoment).const_mul (lam^3*yMoment r))) + (havg.const_mul 3) hpoint + simp only [Pi.sub_apply] at h + rw [integral_sub (f := fun m ↦ 3*lam^2*xMoment r*xMoment m) + (g := fun m ↦ lam^3*yMoment r*yMoment m) + ((compact_integrable continuous_xMoment).const_mul _) + ((compact_integrable continuous_yMoment).const_mul _), + integral_const_mul, integral_const_mul, integral_const_mul, integral_avgSix_measure hi] at h + have hev (k : Fin 6) : (∫ m, f m k ∂Q.probability.toMeasure) = + ∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure := by + exact (show MeasurePreserving (permuteMeasurableEquiv (orbitPerm k)) + Q.probability.toMeasure Q.probability.toMeasure from Q.symmetric _).integral_comp' (fun m ↦ pairZ lam r m*Real.log (pairZ lam r m)) + simp_rw [hev] at h + dsimp only [avgSix] at h + change 3*lam^2*xMoment r*Q.mu-lam^3*yMoment r*Q.eta ≤ _ at h + linarith + +theorem pairCorrelation_increment (R Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + 3*lam^2*Q.mu*R.mu-lam^3*Q.eta*R.eta ≤ 3*pairCorrelation R Q lam := by + have hc : Integrable (fun r ↦ ∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) + R.probability.toMeasure := + (compact_integrable (continuous_pairEntropy hl₀ hl₁) + (μ := R.probability.toMeasure.prod Q.probability.toMeasure)).integral_prod_left + have h := integral_mono + (((compact_integrable continuous_xMoment).const_mul (3*lam^2*Q.mu)).sub + ((compact_integrable continuous_yMoment).const_mul (lam^3*Q.eta))) (hc.const_mul 3) + (pairCorrelation_increment_at Q hl₀ hl₁) + simp only [Pi.sub_apply] at h + rw [integral_sub (f := fun r ↦ 3*lam^2*Q.mu*xMoment r) + (g := fun r ↦ lam^3*Q.eta*yMoment r) + ((compact_integrable continuous_xMoment).const_mul _) + ((compact_integrable continuous_yMoment).const_mul _), + integral_const_mul, integral_const_mul, integral_const_mul] at h + exact h + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/CountableStatistics.lean b/lean/OAI/Probability/ThreeStateClauses/CountableStatistics.lean index 9ecea8337d74eaf2635a0607a3962aa87f954058..1a769f7177da05c7d0f4be977276ad6248036a00 100644 --- a/lean/OAI/Probability/ThreeStateClauses/CountableStatistics.lean +++ b/lean/OAI/Probability/ThreeStateClauses/CountableStatistics.lean @@ -1,208 +1,208 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.InformationLoss -import OAI.Probability.ThreeStateClauses.ObservedMixtures - -namespace OAI - -/-! Countable Statistics. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] - -lemma pmf_measure_sum_dirac (p : PMF α) : - p.toMeasure = Measure.sum (fun a ↦ p a • Measure.dirac a) := by - simpa only [PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _)] using - (Measure.sum_smul_dirac p.toMeasure).symm - -lemma pmf_integrable_iff (p : PMF α) (f : α → ℝ) : - Integrable f p.toMeasure ↔ Summable (fun a ↦ (p a).toReal*|f a|) := by - rw [pmf_measure_sum_dirac, integrable_sum_dirac_iff (fun a ↦ p.apply_ne_top a)] - rfl - -lemma integral_pmf_tsum (p : PMF α) (f : α → ℝ) : - (∫ a, f a ∂p.toMeasure) = ∑' a, (p a).toReal*f a := by - rw [pmf_measure_sum_dirac, integral_sum_dirac (fun a ↦ p.apply_ne_top a)] - rfl - -omit [Countable β] [MeasurableSingletonClass β] in -lemma pmf_integrable_bind (p : PMF α) (K : α → PMF β) {f : β → ℝ} - (hf : ∀ a, Integrable f (K a).toMeasure) - (hn : Integrable (fun a ↦ ∫ b, |f b| ∂(K a).toMeasure) p.toMeasure) : - Integrable f (p.bind K).toMeasure := by - rw [pmf_measure_bind] - apply integrable_sum_measure (fun a ↦ (hf a).smul_measure (p.apply_ne_top a)) - have h := (pmf_integrable_iff p _).mp hn - simpa only [integral_smul_measure, smul_eq_mul, Real.norm_eq_abs, - abs_of_nonneg (integral_nonneg (fun _ ↦ abs_nonneg _))] using h - -omit [Countable β] [MeasurableSingletonClass β] in -lemma integral_pmf_bind_integrable (p : PMF α) (K : α → PMF β) {f : β → ℝ} - (hf : Integrable f (p.bind K).toMeasure) : - (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by - rw [pmf_measure_bind] at hf ⊢ - rw [integral_sum_measure hf, integral_pmf_tsum] - simp only [integral_smul_measure, smul_eq_mul] - -omit [Countable α] [MeasurableSingletonClass α] in -lemma pmf_integrable_bind_finite {ι : Type*} [Fintype ι] [MeasurableSpace ι] - [MeasurableSingletonClass ι] (p : PMF ι) (K : ι → PMF α) {f : α → ℝ} - (hf : ∀ i, Integrable f (K i).toMeasure) : Integrable f (p.bind K).toMeasure := - pmf_integrable_bind p K hf Integrable.of_finite - -lemma pmf_integrable_map_iff (p : PMF α) (g : α → β) (f : β → ℝ) : - Integrable f (p.map g).toMeasure ↔ Integrable (fun a ↦ f (g a)) p.toMeasure := by - rw [← PMF.toMeasure_map g p (measurable_of_countable g)] - exact integrable_map_measure (measurable_of_countable _).aestronglyMeasurable - (measurable_of_countable _).aemeasurable - -lemma pmf_integrable_of_square (p : PMF α) {f : α → ℝ} - (hf : Integrable (fun a ↦ f a^2) p.toMeasure) : Integrable f p.toMeasure := by - apply ((integrable_const (1:ℝ)).add hf).mono' (measurable_of_countable _).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun a ↦ by - simp only [Real.norm_eq_abs, Pi.add_apply] - nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)]) - -lemma discrete_bayes_integral_integrable (p : Spin → PMF α) (i : Spin) {f : α → ℝ} - (hf : Integrable f (discreteMarginal p).toMeasure) (hi : Integrable f (p i).toMeasure) : - (∫ a, (discreteMessage p a).1 i*f a ∂(discreteMarginal p).toMeasure) = - ∫ a, f a ∂(p i).toMeasure := by - have hl := hf.bdd_mul (measurable_of_countable (fun a ↦ (discreteMessage p a).1 i)).aestronglyMeasurable - (Filter.Eventually.of_forall (fun a ↦ show ‖(discreteMessage p a).1 i‖ ≤ (3:ℝ) by - rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)]; exact coordinate_le_three _ _)) - rw [PMF.integral_eq_tsum _ _ hl, PMF.integral_eq_tsum _ _ hi] - apply tsum_congr - intro a - simp only [smul_eq_mul, discreteMarginal_real, ← mul_assoc, discrete_bayes] - -omit [Countable α] [MeasurableSingletonClass α] in -lemma integral_discreteMarginal_integrable (p : Spin → PMF α) {f : α → ℝ} - (hf : ∀ i, Integrable f (p i).toMeasure) : - (∫ a, f a ∂(discreteMarginal p).toMeasure) = - ((∫ a, f a ∂(p 0).toMeasure)+(∫ a, f a ∂(p 1).toMeasure)+(∫ a, f a ∂(p 2).toMeasure))/3 := by - rw [discreteMarginal, integral_pmf_bind_integrable _ _ (pmf_integrable_bind_finite _ _ hf), PMF.integral_eq_sum] - simp only [Fin.sum_univ_three, uniformSpin_apply, ENNReal.toReal_div, - ENNReal.toReal_one, ENNReal.toReal_ofNat, smul_eq_mul] - ring - -lemma estimator_tv_lower_integrable (p : Spin → PMF α) {f : α → ℝ} {C : ℝ} - (hf : ∀ i, Integrable (fun a ↦ f a^2) (p i).toMeasure) (hC : 0 < C) - (hzero : (∫ a, f a ∂(discreteMarginal p).toMeasure) = 0) - (hroot : (∫ a, f a ∂(p 0).toMeasure) = 2) - (hsecond : (∫ a, f a^2 ∂(discreteMarginal p).toMeasure) ≤ C) : - 1/(3*C) ≤ ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by - let v : α → ℝ := fun a ↦ (discreteMessage p a).1 0-1 - have hv (a : α) : |v a| ≤ 2 := coord_center_abs_le_two _ _ - have hf₂ : Integrable (fun a ↦ f a^2) (discreteMarginal p).toMeasure := - pmf_integrable_bind_finite _ _ hf - have hf₁ := pmf_integrable_of_square _ hf₂ - have hv₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a^2| ≤ (2:ℝ)^2 by - rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hv a, abs_nonneg (v a), sq_abs (v a)]) - have hvf := hf₁.bdd_mul (measurable_of_countable v).aestronglyMeasurable - (Filter.Eventually.of_forall (fun a ↦ show ‖v a‖ ≤ (2:ℝ) from hv a)) - have hcross : (∫ a, v a*f a ∂(discreteMarginal p).toMeasure) = 2 := by - have he (a : α) : v a*f a = (discreteMessage p a).1 0*f a-f a := by dsimp [v]; ring - simp_rw [he] - rw [integral_sub (hf₁.bdd_mul (measurable_of_countable _).aestronglyMeasurable - (Filter.Eventually.of_forall (fun a ↦ show ‖(discreteMessage p a).1 0‖ ≤ (3:ℝ) by - rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)]; exact coordinate_le_three _ _))) hf₁, - discrete_bayes_integral_integrable p 0 hf₁ (pmf_integrable_of_square _ (hf 0)), hroot, hzero, sub_zero] - let r := 2/C - have hr : r*C = 2 := div_mul_cancel₀ 2 hC.ne' - have h := MeasureTheory.integral_nonneg (μ := (discreteMarginal p).toMeasure) - (f := fun a ↦ (v a-r*f a)^2) (fun _ ↦ sq_nonneg _) - rw [integral_scaled_square _ r hv₂ hf₂ hvf, hcross] at h - have hb := mul_le_mul_of_nonneg_left hsecond (sq_nonneg r) - have hr2 : r^2*C = 2*r := by - have hh := congrArg (fun x : ℝ ↦ r*x) hr - nlinarith only [hh] - have hD : 4 ≤ C*(∫ a, v a^2 ∂(discreteMarginal p).toMeasure) := by - have hs : 2*r ≤ ∫ a, v a^2 ∂(discreteMarginal p).toMeasure := by - nlinarith only [h, hb, hr2] - have hh := mul_le_mul_of_nonneg_left hs hC.le - nlinarith only [hh, hr] - have hT := integral_mono hv₂ (pmf_bounded_integrable (discreteMarginal p) - (fun a ↦ show |12*tvMessage (discreteMessage p a)| ≤ 12 by - rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 12), abs_of_nonneg (tvMessage_nonneg _)]; - nlinarith [tvMessage_le_one (discreteMessage p a)])) - (fun a ↦ coord_sq_le_tv (discreteMessage p a) 0) - rw [integral_const_mul, ← integral_discreteProbability p continuous_tvMessage.measurable] at hT - apply (div_le_iff₀ (by positivity : 0 < 3*C)).2 - have hh := mul_le_mul_of_nonneg_left hT hC.le - nlinarith only [hD, hh] - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment - -variable {α : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - -lemma product_sum_integrable (p : PMF α) {f : α → ℝ} (hf : Integrable f p.toMeasure) (n : ℕ) : - Integrable (fun v : Fin n → α ↦ ∑ j, f (v j)) (productPMF (fun _ ↦ p)).toMeasure := by - rw [productPMF_measure] - simpa [weightProduct] using integrable_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) (by simpa using hf) - -lemma product_square_sum_integrable (p : PMF α) {f : α → ℝ} - (hf : Integrable (fun a ↦ f a^2) p.toMeasure) (n : ℕ) : - Integrable (fun v : Fin n → α ↦ (∑ j, f (v j))^2) (productPMF (fun _ ↦ p)).toMeasure := by - rw [productPMF_measure] - simpa [weightProduct] using integrable_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) (by simpa using pmf_integrable_of_square p hf) (by simpa using hf) - -lemma integral_product_sum_integrable (p : PMF α) {f : α → ℝ} - (hf : Integrable f p.toMeasure) (n : ℕ) : - (∫ v : Fin n → α, (∑ j, f (v j)) ∂(productPMF (fun _ ↦ p)).toMeasure) = - (n:ℝ)*(∫ a, f a ∂p.toMeasure) := by - rw [productPMF_measure] - simpa [weightProduct] using integral_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) (by simpa using hf) (by simp) - -lemma integral_product_sq_sum_integrable (p : PMF α) {f : α → ℝ} - (hf : Integrable (fun a ↦ f a^2) p.toMeasure) (n : ℕ) : - (∫ v : Fin n → α, (∑ j, f (v j))^2 ∂(productPMF (fun _ ↦ p)).toMeasure) = - (n:ℝ)*(∫ a, f a^2 ∂p.toMeasure)+((n:ℝ)^2-n)*(∫ a, f a ∂p.toMeasure)^2 := by - rw [productPMF_measure] - simpa [weightProduct] using integral_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) (by simpa using pmf_integrable_of_square p hf) - (by simpa using hf) (by simp) - -section Sigma -variable {β : ℕ → Type*} [∀ n, Countable (β n)] [∀ n, MeasurableSpace (β n)] - [∀ n, MeasurableSingletonClass (β n)] - -lemma sigmaPMF_integrable (ρ : PMF ℕ) (p : ∀ n, PMF (β n)) {f : Sigma β → ℝ} - (hf : ∀ n, Integrable (fun a ↦ f ⟨n,a⟩) (p n).toMeasure) - (hn : Integrable (fun n ↦ ∫ a, |f ⟨n,a⟩| ∂(p n).toMeasure) ρ.toMeasure) : - Integrable f (sigmaPMF ρ p).toMeasure := by - rw [sigmaPMF_eq_bind] - apply pmf_integrable_bind - · intro n - exact (pmf_integrable_map_iff (p n) (Sigma.mk n) f).2 (hf n) - · simpa only [integral_pmf_map] using hn - -lemma integral_sigmaPMF_integrable (ρ : PMF ℕ) (p : ∀ n, PMF (β n)) {f : Sigma β → ℝ} - (hf : Integrable f (sigmaPMF ρ p).toMeasure) : - (∫ z, f z ∂(sigmaPMF ρ p).toMeasure) = ∫ n, (∫ a, f ⟨n,a⟩ ∂(p n).toMeasure) ∂ρ.toMeasure := by - rw [sigmaPMF_eq_bind] at hf ⊢ - rw [integral_pmf_bind_integrable _ _ hf] - simp only [integral_pmf_map] - -end Sigma -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.InformationLoss +import OAI.Probability.ThreeStateClauses.ObservedMixtures + +namespace OAI + +/-! Countable Statistics. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] + +lemma pmf_measure_sum_dirac (p : PMF α) : + p.toMeasure = Measure.sum (fun a ↦ p a • Measure.dirac a) := by + simpa only [PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _)] using + (Measure.sum_smul_dirac p.toMeasure).symm + +lemma pmf_integrable_iff (p : PMF α) (f : α → ℝ) : + Integrable f p.toMeasure ↔ Summable (fun a ↦ (p a).toReal*|f a|) := by + rw [pmf_measure_sum_dirac, integrable_sum_dirac_iff (fun a ↦ p.apply_ne_top a)] + rfl + +lemma integral_pmf_tsum (p : PMF α) (f : α → ℝ) : + (∫ a, f a ∂p.toMeasure) = ∑' a, (p a).toReal*f a := by + rw [pmf_measure_sum_dirac, integral_sum_dirac (fun a ↦ p.apply_ne_top a)] + rfl + +omit [Countable β] [MeasurableSingletonClass β] in +lemma pmf_integrable_bind (p : PMF α) (K : α → PMF β) {f : β → ℝ} + (hf : ∀ a, Integrable f (K a).toMeasure) + (hn : Integrable (fun a ↦ ∫ b, |f b| ∂(K a).toMeasure) p.toMeasure) : + Integrable f (p.bind K).toMeasure := by + rw [pmf_measure_bind] + apply integrable_sum_measure (fun a ↦ (hf a).smul_measure (p.apply_ne_top a)) + have h := (pmf_integrable_iff p _).mp hn + simpa only [integral_smul_measure, smul_eq_mul, Real.norm_eq_abs, + abs_of_nonneg (integral_nonneg (fun _ ↦ abs_nonneg _))] using h + +omit [Countable β] [MeasurableSingletonClass β] in +lemma integral_pmf_bind_integrable (p : PMF α) (K : α → PMF β) {f : β → ℝ} + (hf : Integrable f (p.bind K).toMeasure) : + (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by + rw [pmf_measure_bind] at hf ⊢ + rw [integral_sum_measure hf, integral_pmf_tsum] + simp only [integral_smul_measure, smul_eq_mul] + +omit [Countable α] [MeasurableSingletonClass α] in +lemma pmf_integrable_bind_finite {ι : Type*} [Fintype ι] [MeasurableSpace ι] + [MeasurableSingletonClass ι] (p : PMF ι) (K : ι → PMF α) {f : α → ℝ} + (hf : ∀ i, Integrable f (K i).toMeasure) : Integrable f (p.bind K).toMeasure := + pmf_integrable_bind p K hf Integrable.of_finite + +lemma pmf_integrable_map_iff (p : PMF α) (g : α → β) (f : β → ℝ) : + Integrable f (p.map g).toMeasure ↔ Integrable (fun a ↦ f (g a)) p.toMeasure := by + rw [← PMF.toMeasure_map g p (measurable_of_countable g)] + exact integrable_map_measure (measurable_of_countable _).aestronglyMeasurable + (measurable_of_countable _).aemeasurable + +lemma pmf_integrable_of_square (p : PMF α) {f : α → ℝ} + (hf : Integrable (fun a ↦ f a^2) p.toMeasure) : Integrable f p.toMeasure := by + apply ((integrable_const (1:ℝ)).add hf).mono' (measurable_of_countable _).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun a ↦ by + simp only [Real.norm_eq_abs, Pi.add_apply] + nlinarith [sq_nonneg (|f a|-1), sq_abs (f a)]) + +lemma discrete_bayes_integral_integrable (p : Spin → PMF α) (i : Spin) {f : α → ℝ} + (hf : Integrable f (discreteMarginal p).toMeasure) (hi : Integrable f (p i).toMeasure) : + (∫ a, (discreteMessage p a).1 i*f a ∂(discreteMarginal p).toMeasure) = + ∫ a, f a ∂(p i).toMeasure := by + have hl := hf.bdd_mul (measurable_of_countable (fun a ↦ (discreteMessage p a).1 i)).aestronglyMeasurable + (Filter.Eventually.of_forall (fun a ↦ show ‖(discreteMessage p a).1 i‖ ≤ (3:ℝ) by + rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)]; exact coordinate_le_three _ _)) + rw [PMF.integral_eq_tsum _ _ hl, PMF.integral_eq_tsum _ _ hi] + apply tsum_congr + intro a + simp only [smul_eq_mul, discreteMarginal_real, ← mul_assoc, discrete_bayes] + +omit [Countable α] [MeasurableSingletonClass α] in +lemma integral_discreteMarginal_integrable (p : Spin → PMF α) {f : α → ℝ} + (hf : ∀ i, Integrable f (p i).toMeasure) : + (∫ a, f a ∂(discreteMarginal p).toMeasure) = + ((∫ a, f a ∂(p 0).toMeasure)+(∫ a, f a ∂(p 1).toMeasure)+(∫ a, f a ∂(p 2).toMeasure))/3 := by + rw [discreteMarginal, integral_pmf_bind_integrable _ _ (pmf_integrable_bind_finite _ _ hf), PMF.integral_eq_sum] + simp only [Fin.sum_univ_three, uniformSpin_apply, ENNReal.toReal_div, + ENNReal.toReal_one, ENNReal.toReal_ofNat, smul_eq_mul] + ring + +lemma estimator_tv_lower_integrable (p : Spin → PMF α) {f : α → ℝ} {C : ℝ} + (hf : ∀ i, Integrable (fun a ↦ f a^2) (p i).toMeasure) (hC : 0 < C) + (hzero : (∫ a, f a ∂(discreteMarginal p).toMeasure) = 0) + (hroot : (∫ a, f a ∂(p 0).toMeasure) = 2) + (hsecond : (∫ a, f a^2 ∂(discreteMarginal p).toMeasure) ≤ C) : + 1/(3*C) ≤ ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by + let v : α → ℝ := fun a ↦ (discreteMessage p a).1 0-1 + have hv (a : α) : |v a| ≤ 2 := coord_center_abs_le_two _ _ + have hf₂ : Integrable (fun a ↦ f a^2) (discreteMarginal p).toMeasure := + pmf_integrable_bind_finite _ _ hf + have hf₁ := pmf_integrable_of_square _ hf₂ + have hv₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a^2| ≤ (2:ℝ)^2 by + rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hv a, abs_nonneg (v a), sq_abs (v a)]) + have hvf := hf₁.bdd_mul (measurable_of_countable v).aestronglyMeasurable + (Filter.Eventually.of_forall (fun a ↦ show ‖v a‖ ≤ (2:ℝ) from hv a)) + have hcross : (∫ a, v a*f a ∂(discreteMarginal p).toMeasure) = 2 := by + have he (a : α) : v a*f a = (discreteMessage p a).1 0*f a-f a := by dsimp [v]; ring + simp_rw [he] + rw [integral_sub (hf₁.bdd_mul (measurable_of_countable _).aestronglyMeasurable + (Filter.Eventually.of_forall (fun a ↦ show ‖(discreteMessage p a).1 0‖ ≤ (3:ℝ) by + rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)]; exact coordinate_le_three _ _))) hf₁, + discrete_bayes_integral_integrable p 0 hf₁ (pmf_integrable_of_square _ (hf 0)), hroot, hzero, sub_zero] + let r := 2/C + have hr : r*C = 2 := div_mul_cancel₀ 2 hC.ne' + have h := MeasureTheory.integral_nonneg (μ := (discreteMarginal p).toMeasure) + (f := fun a ↦ (v a-r*f a)^2) (fun _ ↦ sq_nonneg _) + rw [integral_scaled_square _ r hv₂ hf₂ hvf, hcross] at h + have hb := mul_le_mul_of_nonneg_left hsecond (sq_nonneg r) + have hr2 : r^2*C = 2*r := by + have hh := congrArg (fun x : ℝ ↦ r*x) hr + nlinarith only [hh] + have hD : 4 ≤ C*(∫ a, v a^2 ∂(discreteMarginal p).toMeasure) := by + have hs : 2*r ≤ ∫ a, v a^2 ∂(discreteMarginal p).toMeasure := by + nlinarith only [h, hb, hr2] + have hh := mul_le_mul_of_nonneg_left hs hC.le + nlinarith only [hh, hr] + have hT := integral_mono hv₂ (pmf_bounded_integrable (discreteMarginal p) + (fun a ↦ show |12*tvMessage (discreteMessage p a)| ≤ 12 by + rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 12), abs_of_nonneg (tvMessage_nonneg _)]; + nlinarith [tvMessage_le_one (discreteMessage p a)])) + (fun a ↦ coord_sq_le_tv (discreteMessage p a) 0) + rw [integral_const_mul, ← integral_discreteProbability p continuous_tvMessage.measurable] at hT + apply (div_le_iff₀ (by positivity : 0 < 3*C)).2 + have hh := mul_le_mul_of_nonneg_left hT hC.le + nlinarith only [hD, hh] + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment + +variable {α : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + +lemma product_sum_integrable (p : PMF α) {f : α → ℝ} (hf : Integrable f p.toMeasure) (n : ℕ) : + Integrable (fun v : Fin n → α ↦ ∑ j, f (v j)) (productPMF (fun _ ↦ p)).toMeasure := by + rw [productPMF_measure] + simpa [weightProduct] using integrable_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) (by simpa using hf) + +lemma product_square_sum_integrable (p : PMF α) {f : α → ℝ} + (hf : Integrable (fun a ↦ f a^2) p.toMeasure) (n : ℕ) : + Integrable (fun v : Fin n → α ↦ (∑ j, f (v j))^2) (productPMF (fun _ ↦ p)).toMeasure := by + rw [productPMF_measure] + simpa [weightProduct] using integrable_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) (by simpa using pmf_integrable_of_square p hf) (by simpa using hf) + +lemma integral_product_sum_integrable (p : PMF α) {f : α → ℝ} + (hf : Integrable f p.toMeasure) (n : ℕ) : + (∫ v : Fin n → α, (∑ j, f (v j)) ∂(productPMF (fun _ ↦ p)).toMeasure) = + (n:ℝ)*(∫ a, f a ∂p.toMeasure) := by + rw [productPMF_measure] + simpa [weightProduct] using integral_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) (by simpa using hf) (by simp) + +lemma integral_product_sq_sum_integrable (p : PMF α) {f : α → ℝ} + (hf : Integrable (fun a ↦ f a^2) p.toMeasure) (n : ℕ) : + (∫ v : Fin n → α, (∑ j, f (v j))^2 ∂(productPMF (fun _ ↦ p)).toMeasure) = + (n:ℝ)*(∫ a, f a^2 ∂p.toMeasure)+((n:ℝ)^2-n)*(∫ a, f a ∂p.toMeasure)^2 := by + rw [productPMF_measure] + simpa [weightProduct] using integral_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) (by simpa using pmf_integrable_of_square p hf) + (by simpa using hf) (by simp) + +section Sigma +variable {β : ℕ → Type*} [∀ n, Countable (β n)] [∀ n, MeasurableSpace (β n)] + [∀ n, MeasurableSingletonClass (β n)] + +lemma sigmaPMF_integrable (ρ : PMF ℕ) (p : ∀ n, PMF (β n)) {f : Sigma β → ℝ} + (hf : ∀ n, Integrable (fun a ↦ f ⟨n,a⟩) (p n).toMeasure) + (hn : Integrable (fun n ↦ ∫ a, |f ⟨n,a⟩| ∂(p n).toMeasure) ρ.toMeasure) : + Integrable f (sigmaPMF ρ p).toMeasure := by + rw [sigmaPMF_eq_bind] + apply pmf_integrable_bind + · intro n + exact (pmf_integrable_map_iff (p n) (Sigma.mk n) f).2 (hf n) + · simpa only [integral_pmf_map] using hn + +lemma integral_sigmaPMF_integrable (ρ : PMF ℕ) (p : ∀ n, PMF (β n)) {f : Sigma β → ℝ} + (hf : Integrable f (sigmaPMF ρ p).toMeasure) : + (∫ z, f z ∂(sigmaPMF ρ p).toMeasure) = ∫ n, (∫ a, f ⟨n,a⟩ ∂(p n).toMeasure) ∂ρ.toMeasure := by + rw [sigmaPMF_eq_bind] at hf ⊢ + rw [integral_pmf_bind_integrable _ _ hf] + simp only [integral_pmf_map] + +end Sigma +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Degradation.lean b/lean/OAI/Probability/ThreeStateClauses/Degradation.lean index 066c3217ca481b641ce1b7da883828fff3521a57..c0b0181ec752850509a93d9df1f5790f9b9a1711 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Degradation.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Degradation.lean @@ -1,97 +1,97 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.DiscreteLaw - -namespace OAI - -/-! Degradation. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α β : Type*} - -def kernelJoint (p : PMF α) (K : α → PMF β) : PMF (α × β) := - p.bind (fun a ↦ (K a).map (fun b ↦ (a,b))) - -lemma kernelJoint_fst (p : PMF α) (K : α → PMF β) : - (kernelJoint p K).map Prod.fst = p := by - simp only [kernelJoint, PMF.map_bind, PMF.map_comp, Function.comp_def] - have h (a : α) : ((K a).map (fun _ ↦ a)) = PMF.pure a := PMF.map_const _ _ - simp only [h, PMF.bind_pure] - -lemma kernelJoint_snd (p : PMF α) (K : α → PMF β) : - (kernelJoint p K).map Prod.snd = p.bind K := by - simp only [kernelJoint, PMF.map_bind, PMF.map_comp, Function.comp_def] - have h (a : α) : ((K a).map (fun b ↦ b)) = K a := PMF.map_id _ - simp only [h] - -lemma discreteMarginal_bind (p : Fin 3 → PMF α) (K : α → PMF β) : - discreteMarginal (fun i ↦ (p i).bind K) = (discreteMarginal p).bind K := by - simp only [discreteMarginal, PMF.bind_bind] - -section Measures -variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] - -lemma integral_kernelJoint (p : PMF α) (K : α → PMF β) {f : α × β → ℝ} {C : ℝ} - (hf : ∀ z, |f z| ≤ C) : - (∫ z, f z ∂(kernelJoint p K).toMeasure) = - ∫ a, (∫ b, f (a,b) ∂(K a).toMeasure) ∂p.toMeasure := by - rw [kernelJoint, integral_pmf_bind p _ hf] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun a ↦ integral_pmf_map (K a) _ f) - -lemma integral_kernelJoint_fst (p : PMF α) (K : α → PMF β) (f : α → ℝ) : - (∫ z, f z.1 ∂(kernelJoint p K).toMeasure) = ∫ a, f a ∂p.toMeasure := by - rw [← integral_pmf_map, kernelJoint_fst] - -lemma integral_kernelJoint_snd (p : PMF α) (K : α → PMF β) (f : β → ℝ) : - (∫ z, f z.2 ∂(kernelJoint p K).toMeasure) = ∫ b, f b ∂(p.bind K).toMeasure := by - rw [← integral_pmf_map, kernelJoint_snd] - -lemma discrete_degradation_identity (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) - {g : β → ℝ} {C : ℝ} (hg : ∀ b, |g b| ≤ C) : - (∫ z, (discreteMessage p z.1).1 i*g z.2 ∂(kernelJoint (discreteMarginal p) K).toMeasure) = - ∫ b, (discreteMessage (fun j ↦ (p j).bind K) b).1 i*g b - ∂(discreteMarginal (fun j ↦ (p j).bind K)).toMeasure := by - have hb (z : α × β) : |(discreteMessage p z.1).1 i*g z.2| ≤ 3*C := by - rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] - exact mul_le_mul (coordinate_le_three _ _) (hg z.2) (abs_nonneg _) (by norm_num) - rw [integral_kernelJoint _ _ hb] - simp only [integral_const_mul] - have hbound (a : α) : |∫ b, g b ∂(K a).toMeasure| ≤ C := by - calc - |∫ b, g b ∂(K a).toMeasure| ≤ ∫ b, |g b| ∂(K a).toMeasure := abs_integral_le_integral_abs - _ ≤ ∫ _, C ∂(K a).toMeasure := integral_mono (pmf_bounded_integrable (K a) hg).abs - (integrable_const C) hg - _ = C := by simp - rw [discrete_bayes_integral p i hbound, discrete_bayes_integral _ i hg, - integral_pmf_bind (p i) K hg] - -lemma discrete_degradation_centered (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) - {g : β → ℝ} {C : ℝ} (hg : ∀ b, |g b| ≤ C) : - (∫ z, ((discreteMessage p z.1).1 i-(discreteMessage (fun j ↦ (p j).bind K) z.2).1 i)*g z.2 - ∂(kernelJoint (discreteMarginal p) K).toMeasure) = 0 := by - have hb (m : Message) (b : β) : |m.1 i*g b| ≤ 3*C := by - rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] - exact mul_le_mul (coordinate_le_three _ _) (hg b) (abs_nonneg _) (by norm_num) - simp_rw [sub_mul] - rw [integral_sub (f := fun z : α × β ↦ (discreteMessage p z.1).1 i*g z.2) - (g := fun z : α × β ↦ (discreteMessage (fun j ↦ (p j).bind K) z.2).1 i*g z.2) - (pmf_bounded_integrable _ (fun z ↦ hb _ z.2)) - (pmf_bounded_integrable _ (fun z ↦ hb _ z.2)), - discrete_degradation_identity p K i hg, - integral_kernelJoint_snd (f := fun b ↦ (discreteMessage (fun j ↦ (p j).bind K) b).1 i*g b), - ← discreteMarginal_bind, sub_self] - -end Measures -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.DiscreteLaw + +namespace OAI + +/-! Degradation. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α β : Type*} + +def kernelJoint (p : PMF α) (K : α → PMF β) : PMF (α × β) := + p.bind (fun a ↦ (K a).map (fun b ↦ (a,b))) + +lemma kernelJoint_fst (p : PMF α) (K : α → PMF β) : + (kernelJoint p K).map Prod.fst = p := by + simp only [kernelJoint, PMF.map_bind, PMF.map_comp, Function.comp_def] + have h (a : α) : ((K a).map (fun _ ↦ a)) = PMF.pure a := PMF.map_const _ _ + simp only [h, PMF.bind_pure] + +lemma kernelJoint_snd (p : PMF α) (K : α → PMF β) : + (kernelJoint p K).map Prod.snd = p.bind K := by + simp only [kernelJoint, PMF.map_bind, PMF.map_comp, Function.comp_def] + have h (a : α) : ((K a).map (fun b ↦ b)) = K a := PMF.map_id _ + simp only [h] + +lemma discreteMarginal_bind (p : Fin 3 → PMF α) (K : α → PMF β) : + discreteMarginal (fun i ↦ (p i).bind K) = (discreteMarginal p).bind K := by + simp only [discreteMarginal, PMF.bind_bind] + +section Measures +variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] + +lemma integral_kernelJoint (p : PMF α) (K : α → PMF β) {f : α × β → ℝ} {C : ℝ} + (hf : ∀ z, |f z| ≤ C) : + (∫ z, f z ∂(kernelJoint p K).toMeasure) = + ∫ a, (∫ b, f (a,b) ∂(K a).toMeasure) ∂p.toMeasure := by + rw [kernelJoint, integral_pmf_bind p _ hf] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun a ↦ integral_pmf_map (K a) _ f) + +lemma integral_kernelJoint_fst (p : PMF α) (K : α → PMF β) (f : α → ℝ) : + (∫ z, f z.1 ∂(kernelJoint p K).toMeasure) = ∫ a, f a ∂p.toMeasure := by + rw [← integral_pmf_map, kernelJoint_fst] + +lemma integral_kernelJoint_snd (p : PMF α) (K : α → PMF β) (f : β → ℝ) : + (∫ z, f z.2 ∂(kernelJoint p K).toMeasure) = ∫ b, f b ∂(p.bind K).toMeasure := by + rw [← integral_pmf_map, kernelJoint_snd] + +lemma discrete_degradation_identity (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) + {g : β → ℝ} {C : ℝ} (hg : ∀ b, |g b| ≤ C) : + (∫ z, (discreteMessage p z.1).1 i*g z.2 ∂(kernelJoint (discreteMarginal p) K).toMeasure) = + ∫ b, (discreteMessage (fun j ↦ (p j).bind K) b).1 i*g b + ∂(discreteMarginal (fun j ↦ (p j).bind K)).toMeasure := by + have hb (z : α × β) : |(discreteMessage p z.1).1 i*g z.2| ≤ 3*C := by + rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] + exact mul_le_mul (coordinate_le_three _ _) (hg z.2) (abs_nonneg _) (by norm_num) + rw [integral_kernelJoint _ _ hb] + simp only [integral_const_mul] + have hbound (a : α) : |∫ b, g b ∂(K a).toMeasure| ≤ C := by + calc + |∫ b, g b ∂(K a).toMeasure| ≤ ∫ b, |g b| ∂(K a).toMeasure := abs_integral_le_integral_abs + _ ≤ ∫ _, C ∂(K a).toMeasure := integral_mono (pmf_bounded_integrable (K a) hg).abs + (integrable_const C) hg + _ = C := by simp + rw [discrete_bayes_integral p i hbound, discrete_bayes_integral _ i hg, + integral_pmf_bind (p i) K hg] + +lemma discrete_degradation_centered (p : Fin 3 → PMF α) (K : α → PMF β) (i : Fin 3) + {g : β → ℝ} {C : ℝ} (hg : ∀ b, |g b| ≤ C) : + (∫ z, ((discreteMessage p z.1).1 i-(discreteMessage (fun j ↦ (p j).bind K) z.2).1 i)*g z.2 + ∂(kernelJoint (discreteMarginal p) K).toMeasure) = 0 := by + have hb (m : Message) (b : β) : |m.1 i*g b| ≤ 3*C := by + rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] + exact mul_le_mul (coordinate_le_three _ _) (hg b) (abs_nonneg _) (by norm_num) + simp_rw [sub_mul] + rw [integral_sub (f := fun z : α × β ↦ (discreteMessage p z.1).1 i*g z.2) + (g := fun z : α × β ↦ (discreteMessage (fun j ↦ (p j).bind K) z.2).1 i*g z.2) + (pmf_bounded_integrable _ (fun z ↦ hb _ z.2)) + (pmf_bounded_integrable _ (fun z ↦ hb _ z.2)), + discrete_degradation_identity p K i hg, + integral_kernelJoint_snd (f := fun b ↦ (discreteMessage (fun j ↦ (p j).bind K) b).1 i*g b), + ← discreteMarginal_bind, sub_self] + +end Measures +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/DiscreteLaw.lean b/lean/OAI/Probability/ThreeStateClauses/DiscreteLaw.lean index 677e1bcdd2a0a6838385ffdf9d89951f8adeda39..f6322ad25f5b598ede4e0367170ffde119f4326a 100644 --- a/lean/OAI/Probability/ThreeStateClauses/DiscreteLaw.lean +++ b/lean/OAI/Probability/ThreeStateClauses/DiscreteLaw.lean @@ -1,172 +1,172 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.PosteriorLaw - -namespace OAI - -/-! Discrete Law. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α : Type*} - -def uniformSpin : PMF (Fin 3) := PMF.ofFintype (fun _ ↦ (1/3 : ℝ≥0∞)) (by - norm_num - exact ENNReal.mul_inv_cancel (by norm_num) (by norm_num)) - -@[simp] lemma uniformSpin_apply (i : Fin 3) : uniformSpin i = (1/3 : ℝ≥0∞) := rfl - -def discreteMarginal (p : Fin 3 → PMF α) : PMF α := uniformSpin.bind p - -def discreteWeight (p : Fin 3 → PMF α) (a : α) : ℝ := avg (fun i ↦ (p i a).toReal) - -lemma discreteWeight_nonneg (p : Fin 3 → PMF α) (a : α) : 0 ≤ discreteWeight p a := by - unfold discreteWeight avg; positivity - -lemma discreteMarginal_apply (p : Fin 3 → PMF α) (a : α) : - discreteMarginal p a = (p 0 a+p 1 a+p 2 a)/3 := by - simp [discreteMarginal, PMF.bind_apply, tsum_fintype, Fin.sum_univ_three, div_eq_mul_inv] - ring - -lemma discreteMarginal_real (p : Fin 3 → PMF α) (a : α) : - (discreteMarginal p a).toReal = discreteWeight p a := by - rw [discreteMarginal_apply, ENNReal.toReal_div, - ENNReal.toReal_add (ENNReal.add_ne_top.mpr ⟨(p 0).apply_ne_top a, (p 1).apply_ne_top a⟩) - ((p 2).apply_ne_top a), - ENNReal.toReal_add ((p 0).apply_ne_top a) ((p 1).apply_ne_top a)] - norm_num [discreteWeight, avg] - -lemma discreteWeight_zero (p : Fin 3 → PMF α) (a : α) (h : discreteWeight p a = 0) (i : Fin 3) : - (p i a).toReal = 0 := by - dsimp [discreteWeight, avg] at h - fin_cases i <;> dsimp <;> linarith [ENNReal.toReal_nonneg (a := p 0 a), - ENNReal.toReal_nonneg (a := p 1 a), ENNReal.toReal_nonneg (a := p 2 a)] - -def discreteMessage (p : Fin 3 → PMF α) (a : α) : Message := by - by_cases h : discreteWeight p a = 0 - · exact ⟨fun _ ↦ 1, fun _ ↦ by norm_num, by norm_num [avg]⟩ - · refine ⟨fun i ↦ (p i a).toReal/discreteWeight p a, fun _ ↦ div_nonneg (by positivity) - (discreteWeight_nonneg p a), ?_⟩ - change ((p 0 a).toReal/discreteWeight p a+(p 1 a).toReal/discreteWeight p a+ - (p 2 a).toReal/discreteWeight p a)/3 = 1 - rw [← add_div, ← add_div, div_div, mul_comm] - have hw : (p 0 a).toReal+(p 1 a).toReal+(p 2 a).toReal = 3*discreteWeight p a := by - dsimp [discreteWeight, avg]; ring - rw [hw, div_self (mul_ne_zero (by norm_num) h)] - -lemma discrete_bayes (p : Fin 3 → PMF α) (a : α) (i : Fin 3) : - discreteWeight p a*(discreteMessage p a).1 i = (p i a).toReal := by - unfold discreteMessage - split_ifs with h - · simpa [h] using (discreteWeight_zero p a h i).symm - · exact mul_div_cancel₀ _ h - -lemma discrete_coord {p : Fin 3 → PMF α} {a : α} (h : discreteWeight p a ≠ 0) (i : Fin 3) : - (discreteMessage p a).1 i = (p i a).toReal/discreteWeight p a := by - simp only [discreteMessage, dite_eq_right h] - -lemma pmf_real_sum (p : PMF α) : ∑' a, (p a).toReal = 1 := by - rw [← ENNReal.tsum_toReal_eq p.apply_ne_top, p.tsum_coe] - norm_num - -section Measures -variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - -lemma discreteCoordinate_integrable (p : Fin 3 → PMF α) (i : Fin 3) : - Integrable (fun a ↦ (discreteMessage p a).1 i) (discreteMarginal p).toMeasure := - Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 3 - (Filter.Eventually.of_forall (fun a ↦ by - rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)] - exact coordinate_le_three _ _)) - -def discreteProbability (p : Fin 3 → PMF α) : ProbabilityMeasure Message := - ProbabilityMeasure.map (⟨(discreteMarginal p).toMeasure, inferInstance⟩ : ProbabilityMeasure α) - (discreteMessage p) - -lemma integral_discreteProbability (p : Fin 3 → PMF α) {f : Message → ℝ} (hf : Measurable f) : - (∫ m, f m ∂(discreteProbability p).toMeasure) = - ∫ a, f (discreteMessage p a) ∂(discreteMarginal p).toMeasure := by - change (∫ m, f m ∂Measure.map (discreteMessage p) (discreteMarginal p).toMeasure) = _ - exact integral_map (measurable_of_countable _).aemeasurable hf.aestronglyMeasurable - -lemma discreteProbability_balanced (p : Fin 3 → PMF α) (i : Fin 3) : - (∫ m, m.1 i ∂(discreteProbability p).toMeasure) = 1 := by - rw [integral_discreteProbability p (continuous_coordinate i).measurable, - PMF.integral_eq_tsum _ _ (discreteCoordinate_integrable p i)] - simpa only [smul_eq_mul, discreteMarginal_real, discrete_bayes] using pmf_real_sum (p i) - -end Measures - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] - -lemma pmf_bounded_integrable (p : PMF α) {f : α → ℝ} {C : ℝ} (hf : ∀ a, |f a| ≤ C) : - Integrable f p.toMeasure := - Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable C - (Filter.Eventually.of_forall (fun a ↦ by simpa only [Real.norm_eq_abs] using hf a)) - -omit [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSingletonClass β] in -lemma pmf_measure_bind (p : PMF α) (K : α → PMF β) : - (p.bind K).toMeasure = Measure.sum (fun a ↦ p a • (K a).toMeasure) := by - apply Measure.ext - intro s hs - rw [PMF.toMeasure_bind_apply _ _ _ hs, Measure.sum_apply _ hs] - simp only [Measure.smul_apply, smul_eq_mul] - -lemma integral_pmf_bind (p : PMF α) (K : α → PMF β) {f : β → ℝ} {C : ℝ} - (hf : ∀ b, |f b| ≤ C) : - (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by - have hi := pmf_bounded_integrable (p.bind K) hf - rw [pmf_measure_bind] at hi ⊢ - rw [integral_sum_measure hi] - simp only [integral_smul_measure, smul_eq_mul] - rw [PMF.integral_eq_tsum] - · rfl - · apply pmf_bounded_integrable - intro a - calc - |∫ b, f b ∂(K a).toMeasure| ≤ ∫ b, |f b| ∂(K a).toMeasure := abs_integral_le_integral_abs - _ ≤ ∫ _, C ∂(K a).toMeasure := integral_mono (pmf_bounded_integrable (K a) hf).abs - (integrable_const C) hf - _ = C := by simp - -lemma integral_pmf_map (p : PMF α) (T : α → β) (f : β → ℝ) : - (∫ b, f b ∂(p.map T).toMeasure) = ∫ a, f (T a) ∂p.toMeasure := by - rw [← PMF.toMeasure_map T p (measurable_of_countable T)] - exact integral_map (measurable_of_countable _).aemeasurable - (measurable_of_countable _).aestronglyMeasurable - -lemma discrete_bayes_integral (p : Fin 3 → PMF α) (i : Fin 3) {g : α → ℝ} {C : ℝ} - (hg : ∀ a, |g a| ≤ C) : - (∫ a, (discreteMessage p a).1 i*g a ∂(discreteMarginal p).toMeasure) = - ∫ a, g a ∂(p i).toMeasure := by - rw [PMF.integral_eq_tsum, PMF.integral_eq_tsum _ _ (pmf_bounded_integrable (p i) hg)] - · apply tsum_congr - intro a - simp only [smul_eq_mul, discreteMarginal_real, ← mul_assoc, discrete_bayes] - · apply pmf_bounded_integrable (C := 3*C) - intro a - rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] - exact mul_le_mul (coordinate_le_three _ _) (hg a) (abs_nonneg _) (by norm_num) - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.PosteriorLaw + +namespace OAI + +/-! Discrete Law. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α : Type*} + +def uniformSpin : PMF (Fin 3) := PMF.ofFintype (fun _ ↦ (1/3 : ℝ≥0∞)) (by + norm_num + exact ENNReal.mul_inv_cancel (by norm_num) (by norm_num)) + +@[simp] lemma uniformSpin_apply (i : Fin 3) : uniformSpin i = (1/3 : ℝ≥0∞) := rfl + +def discreteMarginal (p : Fin 3 → PMF α) : PMF α := uniformSpin.bind p + +def discreteWeight (p : Fin 3 → PMF α) (a : α) : ℝ := avg (fun i ↦ (p i a).toReal) + +lemma discreteWeight_nonneg (p : Fin 3 → PMF α) (a : α) : 0 ≤ discreteWeight p a := by + unfold discreteWeight avg; positivity + +lemma discreteMarginal_apply (p : Fin 3 → PMF α) (a : α) : + discreteMarginal p a = (p 0 a+p 1 a+p 2 a)/3 := by + simp [discreteMarginal, PMF.bind_apply, tsum_fintype, Fin.sum_univ_three, div_eq_mul_inv] + ring + +lemma discreteMarginal_real (p : Fin 3 → PMF α) (a : α) : + (discreteMarginal p a).toReal = discreteWeight p a := by + rw [discreteMarginal_apply, ENNReal.toReal_div, + ENNReal.toReal_add (ENNReal.add_ne_top.mpr ⟨(p 0).apply_ne_top a, (p 1).apply_ne_top a⟩) + ((p 2).apply_ne_top a), + ENNReal.toReal_add ((p 0).apply_ne_top a) ((p 1).apply_ne_top a)] + norm_num [discreteWeight, avg] + +lemma discreteWeight_zero (p : Fin 3 → PMF α) (a : α) (h : discreteWeight p a = 0) (i : Fin 3) : + (p i a).toReal = 0 := by + dsimp [discreteWeight, avg] at h + fin_cases i <;> dsimp <;> linarith [ENNReal.toReal_nonneg (a := p 0 a), + ENNReal.toReal_nonneg (a := p 1 a), ENNReal.toReal_nonneg (a := p 2 a)] + +def discreteMessage (p : Fin 3 → PMF α) (a : α) : Message := by + by_cases h : discreteWeight p a = 0 + · exact ⟨fun _ ↦ 1, fun _ ↦ by norm_num, by norm_num [avg]⟩ + · refine ⟨fun i ↦ (p i a).toReal/discreteWeight p a, fun _ ↦ div_nonneg (by positivity) + (discreteWeight_nonneg p a), ?_⟩ + change ((p 0 a).toReal/discreteWeight p a+(p 1 a).toReal/discreteWeight p a+ + (p 2 a).toReal/discreteWeight p a)/3 = 1 + rw [← add_div, ← add_div, div_div, mul_comm] + have hw : (p 0 a).toReal+(p 1 a).toReal+(p 2 a).toReal = 3*discreteWeight p a := by + dsimp [discreteWeight, avg]; ring + rw [hw, div_self (mul_ne_zero (by norm_num) h)] + +lemma discrete_bayes (p : Fin 3 → PMF α) (a : α) (i : Fin 3) : + discreteWeight p a*(discreteMessage p a).1 i = (p i a).toReal := by + unfold discreteMessage + split_ifs with h + · simpa [h] using (discreteWeight_zero p a h i).symm + · exact mul_div_cancel₀ _ h + +lemma discrete_coord {p : Fin 3 → PMF α} {a : α} (h : discreteWeight p a ≠ 0) (i : Fin 3) : + (discreteMessage p a).1 i = (p i a).toReal/discreteWeight p a := by + simp only [discreteMessage, dite_eq_right h] + +lemma pmf_real_sum (p : PMF α) : ∑' a, (p a).toReal = 1 := by + rw [← ENNReal.tsum_toReal_eq p.apply_ne_top, p.tsum_coe] + norm_num + +section Measures +variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + +lemma discreteCoordinate_integrable (p : Fin 3 → PMF α) (i : Fin 3) : + Integrable (fun a ↦ (discreteMessage p a).1 i) (discreteMarginal p).toMeasure := + Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 3 + (Filter.Eventually.of_forall (fun a ↦ by + rw [Real.norm_eq_abs, abs_of_nonneg (coordinate_nonneg _ _)] + exact coordinate_le_three _ _)) + +def discreteProbability (p : Fin 3 → PMF α) : ProbabilityMeasure Message := + ProbabilityMeasure.map (⟨(discreteMarginal p).toMeasure, inferInstance⟩ : ProbabilityMeasure α) + (discreteMessage p) + +lemma integral_discreteProbability (p : Fin 3 → PMF α) {f : Message → ℝ} (hf : Measurable f) : + (∫ m, f m ∂(discreteProbability p).toMeasure) = + ∫ a, f (discreteMessage p a) ∂(discreteMarginal p).toMeasure := by + change (∫ m, f m ∂Measure.map (discreteMessage p) (discreteMarginal p).toMeasure) = _ + exact integral_map (measurable_of_countable _).aemeasurable hf.aestronglyMeasurable + +lemma discreteProbability_balanced (p : Fin 3 → PMF α) (i : Fin 3) : + (∫ m, m.1 i ∂(discreteProbability p).toMeasure) = 1 := by + rw [integral_discreteProbability p (continuous_coordinate i).measurable, + PMF.integral_eq_tsum _ _ (discreteCoordinate_integrable p i)] + simpa only [smul_eq_mul, discreteMarginal_real, discrete_bayes] using pmf_real_sum (p i) + +end Measures + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] + +lemma pmf_bounded_integrable (p : PMF α) {f : α → ℝ} {C : ℝ} (hf : ∀ a, |f a| ≤ C) : + Integrable f p.toMeasure := + Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable C + (Filter.Eventually.of_forall (fun a ↦ by simpa only [Real.norm_eq_abs] using hf a)) + +omit [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSingletonClass β] in +lemma pmf_measure_bind (p : PMF α) (K : α → PMF β) : + (p.bind K).toMeasure = Measure.sum (fun a ↦ p a • (K a).toMeasure) := by + apply Measure.ext + intro s hs + rw [PMF.toMeasure_bind_apply _ _ _ hs, Measure.sum_apply _ hs] + simp only [Measure.smul_apply, smul_eq_mul] + +lemma integral_pmf_bind (p : PMF α) (K : α → PMF β) {f : β → ℝ} {C : ℝ} + (hf : ∀ b, |f b| ≤ C) : + (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by + have hi := pmf_bounded_integrable (p.bind K) hf + rw [pmf_measure_bind] at hi ⊢ + rw [integral_sum_measure hi] + simp only [integral_smul_measure, smul_eq_mul] + rw [PMF.integral_eq_tsum] + · rfl + · apply pmf_bounded_integrable + intro a + calc + |∫ b, f b ∂(K a).toMeasure| ≤ ∫ b, |f b| ∂(K a).toMeasure := abs_integral_le_integral_abs + _ ≤ ∫ _, C ∂(K a).toMeasure := integral_mono (pmf_bounded_integrable (K a) hf).abs + (integrable_const C) hf + _ = C := by simp + +lemma integral_pmf_map (p : PMF α) (T : α → β) (f : β → ℝ) : + (∫ b, f b ∂(p.map T).toMeasure) = ∫ a, f (T a) ∂p.toMeasure := by + rw [← PMF.toMeasure_map T p (measurable_of_countable T)] + exact integral_map (measurable_of_countable _).aemeasurable + (measurable_of_countable _).aestronglyMeasurable + +lemma discrete_bayes_integral (p : Fin 3 → PMF α) (i : Fin 3) {g : α → ℝ} {C : ℝ} + (hg : ∀ a, |g a| ≤ C) : + (∫ a, (discreteMessage p a).1 i*g a ∂(discreteMarginal p).toMeasure) = + ∫ a, g a ∂(p i).toMeasure := by + rw [PMF.integral_eq_tsum, PMF.integral_eq_tsum _ _ (pmf_bounded_integrable (p i) hg)] + · apply tsum_congr + intro a + simp only [smul_eq_mul, discreteMarginal_real, ← mul_assoc, discrete_bayes] + · apply pmf_bounded_integrable (C := 3*C) + intro a + rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)] + exact mul_le_mul (coordinate_le_three _ _) (hg a) (abs_nonneg _) (by norm_num) + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/FiniteUpdate.lean b/lean/OAI/Probability/ThreeStateClauses/FiniteUpdate.lean index 56e9e3e985d1fd708d5f65e21d175401e4ceec34..b49620c4f725d84ff2e3fed883ca3155f8994227 100644 --- a/lean/OAI/Probability/ThreeStateClauses/FiniteUpdate.lean +++ b/lean/OAI/Probability/ThreeStateClauses/FiniteUpdate.lean @@ -1,372 +1,372 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.Basic -import OAI.Probability.ThreeStateClauses.DiscreteLaw -import OAI.Probability.ThreeStateClauses.Products -import OAI.Probability.ThreeStateClauses.BranchMoments - -namespace OAI - -/-! Finite Update. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def branchOutput {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} - (m : Fin n → Message) : Message := - ⟨normalizedProduct (branchEdges lam m), - (fun i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i |>.le), - (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).2⟩ - -lemma continuous_branchOutput {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - Continuous (branchOutput hl₀ hl₁ (n := n)) := by - apply Continuous.subtype_mk - exact continuous_pi (fun i ↦ (continuous_branchProduct lam i).div (continuous_normalizer n lam) - (fun m ↦ ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)))) - -def tiltedProduct (Q : Law) (lam : ℝ) (n : ℕ) : Measure (Fin n → Message) := - (Measure.pi fun _ ↦ Q.probability.toMeasure).withDensity - (fun m ↦ ENNReal.ofReal (normalizer (branchEdges lam m))) - -lemma tiltedProduct_isProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - IsProbabilityMeasure (tiltedProduct Q lam n) := by - constructor - rw [tiltedProduct, withDensity_apply _ MeasurableSet.univ, setLIntegral_univ, - ← ofReal_integral_eq_lintegral_ofReal (compact_integrable (continuous_normalizer n lam)) - (Filter.Eventually.of_forall (fun m ↦ (normalizer_positive (branchEdges_positive hl₀ hl₁ m)).le)), - integral_normalizer] - norm_num - -lemma integral_tiltedProduct (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - (f : (Fin n → Message) → ℝ) : - (∫ m, f m ∂tiltedProduct Q lam n) = - ∫ m, normalizer (branchEdges lam m)*f m ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by - rw [tiltedProduct, integral_withDensity_eq_integral_toReal_smul - (show Measurable (fun m : Fin n → Message ↦ ENNReal.ofReal (normalizer (branchEdges lam m))) from - ENNReal.measurable_ofReal.comp (continuous_normalizer n lam).measurable) - (Filter.Eventually.of_forall (fun _ ↦ ENNReal.ofReal_lt_top))] - congr 1; funext m - rw [ENNReal.toReal_ofReal (normalizer_positive (branchEdges_positive hl₀ hl₁ m)).le] - rfl - -lemma measurePreserving_density {X : Type*} [MeasurableSpace X] {μ : Measure X} - {T : X → X} (hT : MeasurePreserving T μ μ) {w : X → ENNReal} (hw : Measurable w) - (hinv : ∀ x, w (T x) = w x) : - MeasurePreserving T (μ.withDensity w) (μ.withDensity w) := by - refine ⟨hT.measurable, Measure.ext (fun s hs ↦ ?_)⟩ - rw [Measure.map_apply hT.measurable hs, withDensity_apply _ (hT.measurable hs), withDensity_apply _ hs] - have h := hT.setLIntegral_comp_preimage hs hw - simpa only [hinv] using h - -lemma branchProduct_permute {n : ℕ} (lam : ℝ) (σ : Equiv.Perm (Fin 3)) - (m : Fin n → Message) (i : Fin 3) : - branchProduct (branchEdges lam (fun j ↦ permute σ (m j))) i = - branchProduct (branchEdges lam m) (σ i) := rfl - -lemma normalizer_permute {n : ℕ} (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Fin n → Message) : - normalizer (branchEdges lam (fun j ↦ permute σ (m j))) = normalizer (branchEdges lam m) := by - unfold normalizer - change avg (fun i ↦ branchProduct (branchEdges lam m) (σ i)) = _ - exact avg_permute_vec σ (branchProduct (branchEdges lam m)) - -lemma branchOutput_permute {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} - (σ : Equiv.Perm (Fin 3)) (m : Fin n → Message) : - branchOutput hl₀ hl₁ (fun j ↦ permute σ (m j)) = permute σ (branchOutput hl₀ hl₁ m) := by - apply Subtype.ext; funext i - change branchProduct (branchEdges lam (fun j ↦ permute σ (m j))) i / - normalizer (branchEdges lam (fun j ↦ permute σ (m j))) = - branchProduct (branchEdges lam m) (σ i) / normalizer (branchEdges lam m) - rw [branchProduct_permute, normalizer_permute] - -lemma tiltedProduct_symmetric (Q : Law) {lam : ℝ} (_hl₀ : 0 ≤ lam) (_hl₁ : lam < 1) (n : ℕ) - (σ : Equiv.Perm (Fin 3)) : - MeasurePreserving (fun m : Fin n → Message ↦ fun j ↦ permute σ (m j)) - (tiltedProduct Q lam n) (tiltedProduct Q lam n) := by - apply measurePreserving_density - (measurePreserving_pi (fun _ ↦ Q.probability.toMeasure) (fun _ ↦ Q.probability.toMeasure) - (fun _ ↦ Q.symmetric σ)) - (ENNReal.measurable_ofReal.comp (continuous_normalizer n lam).measurable) - intro m - change ENNReal.ofReal (normalizer (branchEdges lam (fun j ↦ permute σ (m j)))) = _ - rw [normalizer_permute] - rfl - -def finiteProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - ProbabilityMeasure Message := by - let ν : ProbabilityMeasure (Fin n → Message) := ⟨tiltedProduct Q lam n, tiltedProduct_isProbability Q hl₀ hl₁ n⟩ - exact ν.map (branchOutput hl₀ hl₁) - -lemma integral_finiteProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - {f : Message → ℝ} (hf : Measurable f) : - (∫ m, f m ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = - ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by - change (∫ m, f m ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ - rw [integral_map (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable hf.aestronglyMeasurable, - integral_tiltedProduct Q hl₀ hl₁] - -lemma finiteProbability_balanced (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) (i : Fin 3) : - (∫ m, m.1 i ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = 1 := by - rw [integral_finiteProbability Q hl₀ hl₁ n (continuous_coordinate i).measurable] - have he (m : Fin n → Message) : - normalizer (branchEdges lam m)*(branchOutput hl₀ hl₁ m).1 i = branchProduct (branchEdges lam m) i := by - change normalizer (branchEdges lam m)*(branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m)) = _ - field_simp [ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m))] - simp_rw [he] - change (∫ m : Fin n → Message, ∏ j, edgeMessage lam (m j) i ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = _ - rw [integral_fintype_prod_eq_pow (fun m : Message ↦ edgeMessage lam m i), Q.edge_balanced] - simp - -lemma finiteProbability_symmetric (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - (σ : Equiv.Perm (Fin 3)) : - MeasurePreserving (permute σ) (finiteProbability Q hl₀ hl₁ n).toMeasure - (finiteProbability Q hl₀ hl₁ n).toMeasure := by - refine ⟨(continuous_permute σ).measurable, ?_⟩ - change Measure.map (permute σ) (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = - Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n) - rw [Measure.map_map (continuous_permute σ).measurable (continuous_branchOutput hl₀ hl₁ n).measurable] - have he : permute σ ∘ branchOutput hl₀ hl₁ = - branchOutput hl₀ hl₁ ∘ (fun m : Fin n → Message ↦ fun j ↦ permute σ (m j)) := by - funext m; exact (branchOutput_permute hl₀ hl₁ σ m).symm - rw [he, ← Measure.map_map (continuous_branchOutput hl₀ hl₁ n).measurable - (tiltedProduct_symmetric Q hl₀ hl₁ n σ).measurable, - (tiltedProduct_symmetric Q hl₀ hl₁ n σ).map_eq] - -def finiteLaw (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : Law where - probability := finiteProbability Q hl₀ hl₁ n - balanced := finiteProbability_balanced Q hl₀ hl₁ n - symmetric := finiteProbability_symmetric Q hl₀ hl₁ n - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α : Type*} - -lemma channel_real {lam : ℝ} (hlam : Admissible lam) (i j : Spin) : - (channel lam hlam i j).toReal = channelWeight lam i j := by - exact ENNReal.toReal_ofReal (channelWeight_nonneg hlam i j) - -lemma edge_pmf_real {lam : ℝ} (hlam : Admissible lam) (p : Spin → PMF α) (i : Spin) (a : α) : - (((channel lam hlam i).bind p) a).toReal = - discreteWeight p a*edgeMessage lam (discreteMessage p a) i := by - rw [PMF.bind_apply, tsum_fintype, - ENNReal.toReal_sum (fun j _ ↦ ENNReal.mul_ne_top ((channel lam hlam i).apply_ne_top j) ((p j).apply_ne_top a))] - simp only [ENNReal.toReal_mul, channel_real] - have he : discreteWeight p a*edgeMessage lam (discreteMessage p a) i = - lam*(p i a).toReal+(1-lam)*discreteWeight p a := by - dsimp only [edgeMessage, edge, centered] - calc - _ = lam*(discreteWeight p a*(discreteMessage p a : Spin → ℝ) i) + - (1-lam)*discreteWeight p a := by ring - _ = _ := by rw [discrete_bayes] - rw [he] - fin_cases i <;> simp [Fin.sum_univ_three, channelWeight, discreteWeight, avg] <;> ring - -def discreteBranchLaw (p : Spin → PMF α) (lam : ℝ) (hlam : Admissible lam) (n : ℕ) (i : Spin) : - PMF (Fin n → α) := productPMF (fun _ ↦ (channel lam hlam i).bind p) - -lemma discreteBranchLaw_real (p : Spin → PMF α) {lam : ℝ} (hlam : Admissible lam) - (n : ℕ) (i : Spin) (v : Fin n → α) : - (discreteBranchLaw p lam hlam n i v).toReal = - (∏ j, discreteWeight p (v j))*branchProduct (branchEdges lam (fun j ↦ discreteMessage p (v j))) i := by - simp only [discreteBranchLaw, productPMF_apply, ENNReal.toReal_prod, edge_pmf_real, - Finset.prod_mul_distrib, branchProduct, branchEdges] - -lemma discreteBranchWeight (p : Spin → PMF α) {lam : ℝ} (hlam : Admissible lam) - (n : ℕ) (v : Fin n → α) : - discreteWeight (discreteBranchLaw p lam hlam n) v = - (∏ j, discreteWeight p (v j))*normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j))) := by - unfold discreteWeight - simp only [discreteBranchLaw_real] - exact avg_mul _ _ - -lemma discreteBranchMessage (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (n : ℕ) (v : Fin n → α) (hv : (∏ j, discreteWeight p (v j)) ≠ 0) : - discreteMessage (discreteBranchLaw p lam hlam n) v = - branchOutput hl₀ hl₁ (fun j ↦ discreteMessage p (v j)) := by - have hz := normalizer_positive (branchEdges_positive hl₀ hl₁ (fun j ↦ discreteMessage p (v j))) - have hw : discreteWeight (discreteBranchLaw p lam hlam n) v ≠ 0 := by - rw [discreteBranchWeight]; exact mul_ne_zero hv (ne_of_gt hz) - apply Subtype.ext - funext i - rw [discrete_coord hw, discreteBranchLaw_real, discreteBranchWeight] - change _ = branchProduct (branchEdges lam (fun j ↦ discreteMessage p (v j))) i / - normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j))) - exact mul_div_mul_left _ _ hv - -lemma discreteBranch_integrand (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (n : ℕ) (v : Fin n → α) (f : Message → ℝ) : - discreteWeight (discreteBranchLaw p lam hlam n) v*f (discreteMessage (discreteBranchLaw p lam hlam n) v) = - (∏ j, discreteWeight p (v j))* - (normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j)))* - f (branchOutput hl₀ hl₁ (fun j ↦ discreteMessage p (v j)))) := by - rw [discreteBranchWeight] - by_cases hv : (∏ j, discreteWeight p (v j)) = 0 - · simp [hv] - · rw [discreteBranchMessage p hl₀ hl₁ hlam n v hv, mul_assoc] - -section Measures -variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - -lemma discreteMessage_preserving (p : Spin → PMF α) : - MeasurePreserving (discreteMessage p) (discreteMarginal p).toMeasure (discreteProbability p).toMeasure := - ⟨measurable_of_countable _, rfl⟩ - -lemma integral_discreteBranchLaw (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (n : ℕ) {f : Message → ℝ} (hf : Continuous f) : - (∫ m, f m ∂(discreteProbability (discreteBranchLaw p lam hlam n)).toMeasure) = - ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) - ∂(Measure.pi fun _ ↦ (discreteProbability p).toMeasure) := by - let g : (Fin n → Message) → ℝ := fun m ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) - have hg : Continuous g := (continuous_normalizer n lam).mul (hf.comp (continuous_branchOutput hl₀ hl₁ n)) - have hp := measurePreserving_pi (fun _ : Fin n ↦ (discreteMarginal p).toMeasure) - (fun _ : Fin n ↦ (discreteProbability p).toMeasure) (fun _ ↦ discreteMessage_preserving p) - conv_rhs => rw [← hp.map_eq, integral_map hp.measurable.aemeasurable hg.measurable.aestronglyMeasurable] - rw [integral_discreteProbability _ hf.measurable, ← productPMF_measure] - rw [PMF.integral_eq_tsum, PMF.integral_eq_tsum] - · apply tsum_congr - intro v - simp only [smul_eq_mul, productPMF_apply, ENNReal.toReal_prod, discreteMarginal_real] - exact discreteBranch_integrand p hl₀ hl₁ hlam n v f - · rw [productPMF_measure] - exact hp.integrable_comp_of_integrable (compact_integrable hg) - · exact (discreteMessage_preserving _).integrable_comp_of_integrable (compact_integrable hf) - -lemma probability_ext_continuous {X : Type*} [TopologicalSpace X] [MeasurableSpace X] - [BorelSpace X] [HasOuterApproxClosed X] {P Q : ProbabilityMeasure X} - (h : ∀ (f : X → ℝ), Continuous f → (∫ x, f x ∂P.toMeasure) = ∫ x, f x ∂Q.toMeasure) : P = Q := by - apply Subtype.ext - exact congrArg FiniteMeasure.toMeasure (FiniteMeasure.ext_of_forall_integral_eq - (μ := P.toFiniteMeasure) (ν := Q.toFiniteMeasure) (fun f ↦ h f f.continuous)) - -lemma discreteBranchLaw_probability (p : Spin → PMF α) (Q : Law) - (hQ : Q.probability = discreteProbability p) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (n : ℕ) : - discreteProbability (discreteBranchLaw p lam hlam n) = finiteProbability Q hl₀ hl₁ n := by - apply probability_ext_continuous - intro f hf - rw [integral_discreteBranchLaw p hl₀ hl₁ hlam n hf, - integral_finiteProbability Q hl₀ hl₁ n hf.measurable, hQ] - -end Measures - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma measurable_symEntropy : Measurable (fun m : Message ↦ symEntropy m.1) := by - have h (i : Fin 3) : Measurable (fun m : Message ↦ (m.1 i-1)*Real.log (m.1 i)) := - ((continuous_coordinate i).measurable.sub measurable_const).mul - (Real.measurable_log.comp (continuous_coordinate i).measurable) - exact (((h 0).add (h 1)).add (h 2)).div_const 3 |>.div_const 2 - -lemma measurable_info : Measurable (fun m : Message ↦ info m.1) := by - have h (i : Fin 3) : Measurable (fun m : Message ↦ m.1 i*Real.log (m.1 i)) := - (continuous_coordinate i).measurable.mul (Real.measurable_log.comp (continuous_coordinate i).measurable) - exact (((h 0).add (h 1)).add (h 2)).div_const 3 - -lemma measurable_correction : Measurable (fun m : Message ↦ correction m.1) := by - have hl (i : Fin 3) : Measurable (fun m : Message ↦ Real.log (m.1 i)) := - Real.measurable_log.comp (continuous_coordinate i).measurable - have hu (i : Fin 3) : Measurable (fun m : Message ↦ logCentered m.1 i) := - (hl i).sub ((((hl 0).add (hl 1)).add (hl 2)).div_const 3) - have h (i : Fin 3) : Measurable (fun m : Message ↦ m.1 i*logCentered m.1 i^2) := - (continuous_coordinate i).measurable.mul ((hu i).pow_const 2) - exact (((h 0).add (h 1)).add (h 2)).div_const 3 |>.div_const 2 - -lemma continuous_symEntropy_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} - (hf : Continuous f) (hp : ∀ x i, 0 < f x i) : Continuous (fun x ↦ symEntropy (f x)) := by - unfold symEntropy - exact (continuous_avg.comp (continuous_pi (fun i ↦ - (((continuous_apply i).comp hf).sub continuous_const).mul - (((continuous_apply i).comp hf).log (fun x ↦ ne_of_gt (hp x i)))))).div_const 2 - -lemma continuous_correction_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} - (hf : Continuous f) (hp : ∀ x i, 0 < f x i) : Continuous (fun x ↦ correction (f x)) := by - have hl (i : Fin 3) : Continuous (fun x ↦ Real.log (f x i)) := - ((continuous_apply i).comp hf).log (fun x ↦ ne_of_gt (hp x i)) - have hu (i : Fin 3) : Continuous (fun x ↦ logCentered (f x) i) := - (hl i).sub (continuous_avg.comp (continuous_pi hl)) - exact (continuous_avg.comp (continuous_pi (fun i ↦ - ((continuous_apply i).comp hf).mul ((hu i).pow 2)))).div_const 2 - -lemma continuous_info_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} - (hf : Continuous f) : Continuous (fun x ↦ info (f x)) := - continuous_avg.comp (continuous_pi (fun i ↦ Real.continuous_mul_log.comp ((continuous_apply i).comp hf))) - -lemma finite_integrable_of_comp (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) - {f : Message → ℝ} (hf : Measurable f) (hc : Continuous (fun m : Fin n → Message ↦ f (branchOutput hl₀ hl₁ m))) : - Integrable f (finiteProbability Q hl₀ hl₁ n).toMeasure := by - have := tiltedProduct_isProbability Q hl₀ hl₁ n - change Integrable f (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) - exact (integrable_map_measure hf.aestronglyMeasurable - (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable).2 (compact_integrable hc) - -lemma finite_integrable_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - Integrable (fun m : Message ↦ symEntropy m.1) (finiteProbability Q hl₀ hl₁ n).toMeasure := - finite_integrable_of_comp Q hl₀ hl₁ n measurable_symEntropy - (continuous_symEntropy_comp (continuous_subtype_val.comp (continuous_branchOutput hl₀ hl₁ n)) - (fun m i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i)) - -lemma finite_integrable_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - Integrable (fun m : Message ↦ correction m.1) (finiteProbability Q hl₀ hl₁ n).toMeasure := - finite_integrable_of_comp Q hl₀ hl₁ n measurable_correction - (continuous_correction_comp (continuous_subtype_val.comp (continuous_branchOutput hl₀ hl₁ n)) - (fun m i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i)) - -lemma measurableSet_positive : MeasurableSet {m : Message | PositiveMessage m.1} := by - have he : {m : Message | PositiveMessage m.1} = {m : Message | ∀ i, 0 < m.1 i} := by - ext m; exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, m.2.2⟩⟩ - rw [he] - simp only [ofPred_forall] - exact MeasurableSet.iInter (fun i ↦ measurableSet_lt measurable_const (continuous_coordinate i).measurable) - -lemma finite_positive (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - ∀ᵐ m ∂(finiteProbability Q hl₀ hl₁ n).toMeasure, PositiveMessage m.1 := by - change ∀ᵐ m ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n), PositiveMessage m.1 - rw [ae_map_iff (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable measurableSet_positive] - exact Filter.Eventually.of_forall (fun m ↦ normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)) - -lemma finiteLaw_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - (∫ m, symEntropy m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = - n*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by - change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ - rw [integral_finiteProbability Q hl₀ hl₁ n measurable_symEntropy] - exact finite_symEntropy Q hl₀ hl₁ n - -lemma finiteLaw_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - (∫ m, correction m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = - n*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - 2*((n:ℝ)^2-n)*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by - change (∫ m, correction m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ - rw [integral_finiteProbability Q hl₀ hl₁ n measurable_correction] - exact finite_correction Q hl₀ hl₁ n - -lemma finiteLaw_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - (∫ m, info m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = - n*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n := by - change (∫ m, info m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ - rw [integral_finiteProbability Q hl₀ hl₁ n measurable_info] - exact finite_info Q hl₀ hl₁ n - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.Basic +import OAI.Probability.ThreeStateClauses.DiscreteLaw +import OAI.Probability.ThreeStateClauses.Products +import OAI.Probability.ThreeStateClauses.BranchMoments + +namespace OAI + +/-! Finite Update. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def branchOutput {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} + (m : Fin n → Message) : Message := + ⟨normalizedProduct (branchEdges lam m), + (fun i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i |>.le), + (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).2⟩ + +lemma continuous_branchOutput {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + Continuous (branchOutput hl₀ hl₁ (n := n)) := by + apply Continuous.subtype_mk + exact continuous_pi (fun i ↦ (continuous_branchProduct lam i).div (continuous_normalizer n lam) + (fun m ↦ ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m)))) + +def tiltedProduct (Q : Law) (lam : ℝ) (n : ℕ) : Measure (Fin n → Message) := + (Measure.pi fun _ ↦ Q.probability.toMeasure).withDensity + (fun m ↦ ENNReal.ofReal (normalizer (branchEdges lam m))) + +lemma tiltedProduct_isProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + IsProbabilityMeasure (tiltedProduct Q lam n) := by + constructor + rw [tiltedProduct, withDensity_apply _ MeasurableSet.univ, setLIntegral_univ, + ← ofReal_integral_eq_lintegral_ofReal (compact_integrable (continuous_normalizer n lam)) + (Filter.Eventually.of_forall (fun m ↦ (normalizer_positive (branchEdges_positive hl₀ hl₁ m)).le)), + integral_normalizer] + norm_num + +lemma integral_tiltedProduct (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + (f : (Fin n → Message) → ℝ) : + (∫ m, f m ∂tiltedProduct Q lam n) = + ∫ m, normalizer (branchEdges lam m)*f m ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by + rw [tiltedProduct, integral_withDensity_eq_integral_toReal_smul + (show Measurable (fun m : Fin n → Message ↦ ENNReal.ofReal (normalizer (branchEdges lam m))) from + ENNReal.measurable_ofReal.comp (continuous_normalizer n lam).measurable) + (Filter.Eventually.of_forall (fun _ ↦ ENNReal.ofReal_lt_top))] + congr 1; funext m + rw [ENNReal.toReal_ofReal (normalizer_positive (branchEdges_positive hl₀ hl₁ m)).le] + rfl + +lemma measurePreserving_density {X : Type*} [MeasurableSpace X] {μ : Measure X} + {T : X → X} (hT : MeasurePreserving T μ μ) {w : X → ENNReal} (hw : Measurable w) + (hinv : ∀ x, w (T x) = w x) : + MeasurePreserving T (μ.withDensity w) (μ.withDensity w) := by + refine ⟨hT.measurable, Measure.ext (fun s hs ↦ ?_)⟩ + rw [Measure.map_apply hT.measurable hs, withDensity_apply _ (hT.measurable hs), withDensity_apply _ hs] + have h := hT.setLIntegral_comp_preimage hs hw + simpa only [hinv] using h + +lemma branchProduct_permute {n : ℕ} (lam : ℝ) (σ : Equiv.Perm (Fin 3)) + (m : Fin n → Message) (i : Fin 3) : + branchProduct (branchEdges lam (fun j ↦ permute σ (m j))) i = + branchProduct (branchEdges lam m) (σ i) := rfl + +lemma normalizer_permute {n : ℕ} (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Fin n → Message) : + normalizer (branchEdges lam (fun j ↦ permute σ (m j))) = normalizer (branchEdges lam m) := by + unfold normalizer + change avg (fun i ↦ branchProduct (branchEdges lam m) (σ i)) = _ + exact avg_permute_vec σ (branchProduct (branchEdges lam m)) + +lemma branchOutput_permute {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) {n : ℕ} + (σ : Equiv.Perm (Fin 3)) (m : Fin n → Message) : + branchOutput hl₀ hl₁ (fun j ↦ permute σ (m j)) = permute σ (branchOutput hl₀ hl₁ m) := by + apply Subtype.ext; funext i + change branchProduct (branchEdges lam (fun j ↦ permute σ (m j))) i / + normalizer (branchEdges lam (fun j ↦ permute σ (m j))) = + branchProduct (branchEdges lam m) (σ i) / normalizer (branchEdges lam m) + rw [branchProduct_permute, normalizer_permute] + +lemma tiltedProduct_symmetric (Q : Law) {lam : ℝ} (_hl₀ : 0 ≤ lam) (_hl₁ : lam < 1) (n : ℕ) + (σ : Equiv.Perm (Fin 3)) : + MeasurePreserving (fun m : Fin n → Message ↦ fun j ↦ permute σ (m j)) + (tiltedProduct Q lam n) (tiltedProduct Q lam n) := by + apply measurePreserving_density + (measurePreserving_pi (fun _ ↦ Q.probability.toMeasure) (fun _ ↦ Q.probability.toMeasure) + (fun _ ↦ Q.symmetric σ)) + (ENNReal.measurable_ofReal.comp (continuous_normalizer n lam).measurable) + intro m + change ENNReal.ofReal (normalizer (branchEdges lam (fun j ↦ permute σ (m j)))) = _ + rw [normalizer_permute] + rfl + +def finiteProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + ProbabilityMeasure Message := by + let ν : ProbabilityMeasure (Fin n → Message) := ⟨tiltedProduct Q lam n, tiltedProduct_isProbability Q hl₀ hl₁ n⟩ + exact ν.map (branchOutput hl₀ hl₁) + +lemma integral_finiteProbability (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + {f : Message → ℝ} (hf : Measurable f) : + (∫ m, f m ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = + ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure) := by + change (∫ m, f m ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ + rw [integral_map (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable hf.aestronglyMeasurable, + integral_tiltedProduct Q hl₀ hl₁] + +lemma finiteProbability_balanced (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) (i : Fin 3) : + (∫ m, m.1 i ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = 1 := by + rw [integral_finiteProbability Q hl₀ hl₁ n (continuous_coordinate i).measurable] + have he (m : Fin n → Message) : + normalizer (branchEdges lam m)*(branchOutput hl₀ hl₁ m).1 i = branchProduct (branchEdges lam m) i := by + change normalizer (branchEdges lam m)*(branchProduct (branchEdges lam m) i/normalizer (branchEdges lam m)) = _ + field_simp [ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m))] + simp_rw [he] + change (∫ m : Fin n → Message, ∏ j, edgeMessage lam (m j) i ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = _ + rw [integral_fintype_prod_eq_pow (fun m : Message ↦ edgeMessage lam m i), Q.edge_balanced] + simp + +lemma finiteProbability_symmetric (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + (σ : Equiv.Perm (Fin 3)) : + MeasurePreserving (permute σ) (finiteProbability Q hl₀ hl₁ n).toMeasure + (finiteProbability Q hl₀ hl₁ n).toMeasure := by + refine ⟨(continuous_permute σ).measurable, ?_⟩ + change Measure.map (permute σ) (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = + Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n) + rw [Measure.map_map (continuous_permute σ).measurable (continuous_branchOutput hl₀ hl₁ n).measurable] + have he : permute σ ∘ branchOutput hl₀ hl₁ = + branchOutput hl₀ hl₁ ∘ (fun m : Fin n → Message ↦ fun j ↦ permute σ (m j)) := by + funext m; exact (branchOutput_permute hl₀ hl₁ σ m).symm + rw [he, ← Measure.map_map (continuous_branchOutput hl₀ hl₁ n).measurable + (tiltedProduct_symmetric Q hl₀ hl₁ n σ).measurable, + (tiltedProduct_symmetric Q hl₀ hl₁ n σ).map_eq] + +def finiteLaw (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : Law where + probability := finiteProbability Q hl₀ hl₁ n + balanced := finiteProbability_balanced Q hl₀ hl₁ n + symmetric := finiteProbability_symmetric Q hl₀ hl₁ n + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α : Type*} + +lemma channel_real {lam : ℝ} (hlam : Admissible lam) (i j : Spin) : + (channel lam hlam i j).toReal = channelWeight lam i j := by + exact ENNReal.toReal_ofReal (channelWeight_nonneg hlam i j) + +lemma edge_pmf_real {lam : ℝ} (hlam : Admissible lam) (p : Spin → PMF α) (i : Spin) (a : α) : + (((channel lam hlam i).bind p) a).toReal = + discreteWeight p a*edgeMessage lam (discreteMessage p a) i := by + rw [PMF.bind_apply, tsum_fintype, + ENNReal.toReal_sum (fun j _ ↦ ENNReal.mul_ne_top ((channel lam hlam i).apply_ne_top j) ((p j).apply_ne_top a))] + simp only [ENNReal.toReal_mul, channel_real] + have he : discreteWeight p a*edgeMessage lam (discreteMessage p a) i = + lam*(p i a).toReal+(1-lam)*discreteWeight p a := by + dsimp only [edgeMessage, edge, centered] + calc + _ = lam*(discreteWeight p a*(discreteMessage p a : Spin → ℝ) i) + + (1-lam)*discreteWeight p a := by ring + _ = _ := by rw [discrete_bayes] + rw [he] + fin_cases i <;> simp [Fin.sum_univ_three, channelWeight, discreteWeight, avg] <;> ring + +def discreteBranchLaw (p : Spin → PMF α) (lam : ℝ) (hlam : Admissible lam) (n : ℕ) (i : Spin) : + PMF (Fin n → α) := productPMF (fun _ ↦ (channel lam hlam i).bind p) + +lemma discreteBranchLaw_real (p : Spin → PMF α) {lam : ℝ} (hlam : Admissible lam) + (n : ℕ) (i : Spin) (v : Fin n → α) : + (discreteBranchLaw p lam hlam n i v).toReal = + (∏ j, discreteWeight p (v j))*branchProduct (branchEdges lam (fun j ↦ discreteMessage p (v j))) i := by + simp only [discreteBranchLaw, productPMF_apply, ENNReal.toReal_prod, edge_pmf_real, + Finset.prod_mul_distrib, branchProduct, branchEdges] + +lemma discreteBranchWeight (p : Spin → PMF α) {lam : ℝ} (hlam : Admissible lam) + (n : ℕ) (v : Fin n → α) : + discreteWeight (discreteBranchLaw p lam hlam n) v = + (∏ j, discreteWeight p (v j))*normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j))) := by + unfold discreteWeight + simp only [discreteBranchLaw_real] + exact avg_mul _ _ + +lemma discreteBranchMessage (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (n : ℕ) (v : Fin n → α) (hv : (∏ j, discreteWeight p (v j)) ≠ 0) : + discreteMessage (discreteBranchLaw p lam hlam n) v = + branchOutput hl₀ hl₁ (fun j ↦ discreteMessage p (v j)) := by + have hz := normalizer_positive (branchEdges_positive hl₀ hl₁ (fun j ↦ discreteMessage p (v j))) + have hw : discreteWeight (discreteBranchLaw p lam hlam n) v ≠ 0 := by + rw [discreteBranchWeight]; exact mul_ne_zero hv (ne_of_gt hz) + apply Subtype.ext + funext i + rw [discrete_coord hw, discreteBranchLaw_real, discreteBranchWeight] + change _ = branchProduct (branchEdges lam (fun j ↦ discreteMessage p (v j))) i / + normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j))) + exact mul_div_mul_left _ _ hv + +lemma discreteBranch_integrand (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (n : ℕ) (v : Fin n → α) (f : Message → ℝ) : + discreteWeight (discreteBranchLaw p lam hlam n) v*f (discreteMessage (discreteBranchLaw p lam hlam n) v) = + (∏ j, discreteWeight p (v j))* + (normalizer (branchEdges lam (fun j ↦ discreteMessage p (v j)))* + f (branchOutput hl₀ hl₁ (fun j ↦ discreteMessage p (v j)))) := by + rw [discreteBranchWeight] + by_cases hv : (∏ j, discreteWeight p (v j)) = 0 + · simp [hv] + · rw [discreteBranchMessage p hl₀ hl₁ hlam n v hv, mul_assoc] + +section Measures +variable [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + +lemma discreteMessage_preserving (p : Spin → PMF α) : + MeasurePreserving (discreteMessage p) (discreteMarginal p).toMeasure (discreteProbability p).toMeasure := + ⟨measurable_of_countable _, rfl⟩ + +lemma integral_discreteBranchLaw (p : Spin → PMF α) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (n : ℕ) {f : Message → ℝ} (hf : Continuous f) : + (∫ m, f m ∂(discreteProbability (discreteBranchLaw p lam hlam n)).toMeasure) = + ∫ m : Fin n → Message, normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) + ∂(Measure.pi fun _ ↦ (discreteProbability p).toMeasure) := by + let g : (Fin n → Message) → ℝ := fun m ↦ normalizer (branchEdges lam m)*f (branchOutput hl₀ hl₁ m) + have hg : Continuous g := (continuous_normalizer n lam).mul (hf.comp (continuous_branchOutput hl₀ hl₁ n)) + have hp := measurePreserving_pi (fun _ : Fin n ↦ (discreteMarginal p).toMeasure) + (fun _ : Fin n ↦ (discreteProbability p).toMeasure) (fun _ ↦ discreteMessage_preserving p) + conv_rhs => rw [← hp.map_eq, integral_map hp.measurable.aemeasurable hg.measurable.aestronglyMeasurable] + rw [integral_discreteProbability _ hf.measurable, ← productPMF_measure] + rw [PMF.integral_eq_tsum, PMF.integral_eq_tsum] + · apply tsum_congr + intro v + simp only [smul_eq_mul, productPMF_apply, ENNReal.toReal_prod, discreteMarginal_real] + exact discreteBranch_integrand p hl₀ hl₁ hlam n v f + · rw [productPMF_measure] + exact hp.integrable_comp_of_integrable (compact_integrable hg) + · exact (discreteMessage_preserving _).integrable_comp_of_integrable (compact_integrable hf) + +lemma probability_ext_continuous {X : Type*} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [HasOuterApproxClosed X] {P Q : ProbabilityMeasure X} + (h : ∀ (f : X → ℝ), Continuous f → (∫ x, f x ∂P.toMeasure) = ∫ x, f x ∂Q.toMeasure) : P = Q := by + apply Subtype.ext + exact congrArg FiniteMeasure.toMeasure (FiniteMeasure.ext_of_forall_integral_eq + (μ := P.toFiniteMeasure) (ν := Q.toFiniteMeasure) (fun f ↦ h f f.continuous)) + +lemma discreteBranchLaw_probability (p : Spin → PMF α) (Q : Law) + (hQ : Q.probability = discreteProbability p) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (n : ℕ) : + discreteProbability (discreteBranchLaw p lam hlam n) = finiteProbability Q hl₀ hl₁ n := by + apply probability_ext_continuous + intro f hf + rw [integral_discreteBranchLaw p hl₀ hl₁ hlam n hf, + integral_finiteProbability Q hl₀ hl₁ n hf.measurable, hQ] + +end Measures + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma measurable_symEntropy : Measurable (fun m : Message ↦ symEntropy m.1) := by + have h (i : Fin 3) : Measurable (fun m : Message ↦ (m.1 i-1)*Real.log (m.1 i)) := + ((continuous_coordinate i).measurable.sub measurable_const).mul + (Real.measurable_log.comp (continuous_coordinate i).measurable) + exact (((h 0).add (h 1)).add (h 2)).div_const 3 |>.div_const 2 + +lemma measurable_info : Measurable (fun m : Message ↦ info m.1) := by + have h (i : Fin 3) : Measurable (fun m : Message ↦ m.1 i*Real.log (m.1 i)) := + (continuous_coordinate i).measurable.mul (Real.measurable_log.comp (continuous_coordinate i).measurable) + exact (((h 0).add (h 1)).add (h 2)).div_const 3 + +lemma measurable_correction : Measurable (fun m : Message ↦ correction m.1) := by + have hl (i : Fin 3) : Measurable (fun m : Message ↦ Real.log (m.1 i)) := + Real.measurable_log.comp (continuous_coordinate i).measurable + have hu (i : Fin 3) : Measurable (fun m : Message ↦ logCentered m.1 i) := + (hl i).sub ((((hl 0).add (hl 1)).add (hl 2)).div_const 3) + have h (i : Fin 3) : Measurable (fun m : Message ↦ m.1 i*logCentered m.1 i^2) := + (continuous_coordinate i).measurable.mul ((hu i).pow_const 2) + exact (((h 0).add (h 1)).add (h 2)).div_const 3 |>.div_const 2 + +lemma continuous_symEntropy_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} + (hf : Continuous f) (hp : ∀ x i, 0 < f x i) : Continuous (fun x ↦ symEntropy (f x)) := by + unfold symEntropy + exact (continuous_avg.comp (continuous_pi (fun i ↦ + (((continuous_apply i).comp hf).sub continuous_const).mul + (((continuous_apply i).comp hf).log (fun x ↦ ne_of_gt (hp x i)))))).div_const 2 + +lemma continuous_correction_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} + (hf : Continuous f) (hp : ∀ x i, 0 < f x i) : Continuous (fun x ↦ correction (f x)) := by + have hl (i : Fin 3) : Continuous (fun x ↦ Real.log (f x i)) := + ((continuous_apply i).comp hf).log (fun x ↦ ne_of_gt (hp x i)) + have hu (i : Fin 3) : Continuous (fun x ↦ logCentered (f x) i) := + (hl i).sub (continuous_avg.comp (continuous_pi hl)) + exact (continuous_avg.comp (continuous_pi (fun i ↦ + ((continuous_apply i).comp hf).mul ((hu i).pow 2)))).div_const 2 + +lemma continuous_info_comp {X : Type*} [TopologicalSpace X] {f : X → Vec} + (hf : Continuous f) : Continuous (fun x ↦ info (f x)) := + continuous_avg.comp (continuous_pi (fun i ↦ Real.continuous_mul_log.comp ((continuous_apply i).comp hf))) + +lemma finite_integrable_of_comp (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) + {f : Message → ℝ} (hf : Measurable f) (hc : Continuous (fun m : Fin n → Message ↦ f (branchOutput hl₀ hl₁ m))) : + Integrable f (finiteProbability Q hl₀ hl₁ n).toMeasure := by + have := tiltedProduct_isProbability Q hl₀ hl₁ n + change Integrable f (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) + exact (integrable_map_measure hf.aestronglyMeasurable + (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable).2 (compact_integrable hc) + +lemma finite_integrable_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + Integrable (fun m : Message ↦ symEntropy m.1) (finiteProbability Q hl₀ hl₁ n).toMeasure := + finite_integrable_of_comp Q hl₀ hl₁ n measurable_symEntropy + (continuous_symEntropy_comp (continuous_subtype_val.comp (continuous_branchOutput hl₀ hl₁ n)) + (fun m i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i)) + +lemma finite_integrable_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + Integrable (fun m : Message ↦ correction m.1) (finiteProbability Q hl₀ hl₁ n).toMeasure := + finite_integrable_of_comp Q hl₀ hl₁ n measurable_correction + (continuous_correction_comp (continuous_subtype_val.comp (continuous_branchOutput hl₀ hl₁ n)) + (fun m i ↦ (normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)).1 i)) + +lemma measurableSet_positive : MeasurableSet {m : Message | PositiveMessage m.1} := by + have he : {m : Message | PositiveMessage m.1} = {m : Message | ∀ i, 0 < m.1 i} := by + ext m; exact ⟨fun h ↦ h.1, fun h ↦ ⟨h, m.2.2⟩⟩ + rw [he] + simp only [ofPred_forall] + exact MeasurableSet.iInter (fun i ↦ measurableSet_lt measurable_const (continuous_coordinate i).measurable) + +lemma finite_positive (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + ∀ᵐ m ∂(finiteProbability Q hl₀ hl₁ n).toMeasure, PositiveMessage m.1 := by + change ∀ᵐ m ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n), PositiveMessage m.1 + rw [ae_map_iff (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable measurableSet_positive] + exact Filter.Eventually.of_forall (fun m ↦ normalizedProduct_positive (branchEdges_positive hl₀ hl₁ m)) + +lemma finiteLaw_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + (∫ m, symEntropy m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = + n*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by + change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ + rw [integral_finiteProbability Q hl₀ hl₁ n measurable_symEntropy] + exact finite_symEntropy Q hl₀ hl₁ n + +lemma finiteLaw_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + (∫ m, correction m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = + n*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + 2*((n:ℝ)^2-n)*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure)^2 := by + change (∫ m, correction m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ + rw [integral_finiteProbability Q hl₀ hl₁ n measurable_correction] + exact finite_correction Q hl₀ hl₁ n + +lemma finiteLaw_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + (∫ m, info m.1 ∂(finiteLaw Q hl₀ hl₁ n).probability.toMeasure) = + n*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n := by + change (∫ m, info m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ + rw [integral_finiteProbability Q hl₀ hl₁ n measurable_info] + exact finite_info Q hl₀ hl₁ n + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/InformationLoss.lean b/lean/OAI/Probability/ThreeStateClauses/InformationLoss.lean index 86119ce05c3e53ab0cfcd9ab7d37cbae559a3f9c..d6d8eb786bd80adfee38e88f446304bbaf15505a 100644 --- a/lean/OAI/Probability/ThreeStateClauses/InformationLoss.lean +++ b/lean/OAI/Probability/ThreeStateClauses/InformationLoss.lean @@ -1,261 +1,261 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.CompactLimits - -namespace OAI - -/-! Information Loss. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment - -variable {α β γ : Type} - -def multisetKernel (K : α → PMF β) (s : Multiset α) : PMF (Multiset β) := - Multiset.recOn s (PMF.pure 0) - (fun a _ p ↦ (K a).bind (fun b ↦ p.map (Multiset.cons b))) (by - intro a a' s p - apply heq_of_eq - simp only [PMF.map_bind, PMF.map_comp] - rw [PMF.bind_comm (K a) (K a')] - congr 1 - funext b' - congr 1 - funext b - congr 1 - funext t - exact Multiset.cons_swap _ _ _) - -@[simp] lemma multisetKernel_zero (K : α → PMF β) : multisetKernel K 0 = PMF.pure 0 := by - rw [multisetKernel, Multiset.recOn_0] - -@[simp] lemma multisetKernel_cons (K : α → PMF β) (a : α) (s : Multiset α) : - multisetKernel K (a ::ₘ s) = (K a).bind (fun b ↦ (multisetKernel K s).map (Multiset.cons b)) := by - rw [multisetKernel, Multiset.recOn_cons] - rfl - -lemma multisetKernel_iid (p : PMF α) (K : α → PMF β) (n : ℕ) : - ((iidList p n).map (fun xs : List α ↦ (xs : Multiset α))).bind (multisetKernel K) = - (iidList (p.bind K) n).map (fun xs : List β ↦ (xs : Multiset β)) := by - induction n with - | zero => simp [iidList, PMF.pure_map] - | succ n ih => - simp only [iidList, PMF.map_bind, PMF.map_comp, PMF.bind_bind, PMF.bind_map] - congr 1 - funext a - simp only [Function.comp_def, ← Multiset.cons_coe, multisetKernel_cons] - rw [PMF.bind_comm (iidList p n) (K a)] - congr 1 - funext b - rw [← PMF.map_bind] - have hi := ih - rw [PMF.bind_map] at hi - dsimp only [Function.comp_def] at hi - rw [hi, PMF.map_comp] - rfl - -lemma observationLaw_succ (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (i : Spin) : - observationLaw lam hlam offspring (ℓ+1) i = offspring.bind (fun n ↦ - (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map - (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ)))) := by - rw [observationLaw] - congr 1 - funext n - exact PMF.map_id _ - -def observationExpansion (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : - (ℓ : ℕ) → Observation ℓ → PMF (Observation (ℓ+1)) - | 0, i => observationLaw lam hlam offspring 1 i - | ℓ+1, s => multisetKernel (observationExpansion lam hlam offspring ℓ) s - -lemma observationLaw_degrades (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) - (ℓ : ℕ) (i : Spin) : - (observationLaw lam hlam offspring ℓ i).bind (observationExpansion lam hlam offspring ℓ) = - observationLaw lam hlam offspring (ℓ+1) i := by - induction ℓ generalizing i with - | zero => exact PMF.pure_bind _ _ - | succ ℓ ih => - rw [observationLaw_succ, observationLaw_succ] - change ((offspring.bind (fun n ↦ (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map - (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))))).bind - (multisetKernel (observationExpansion lam hlam offspring ℓ))) = _ - rw [PMF.bind_bind] - congr 1 - funext n - rw [multisetKernel_iid] - congr 2 - rw [PMF.bind_bind] - congr 1 - funext j - exact ih j - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped BigOperators Topology -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma coord_center_abs_le_two (m : Message) (i : Spin) : |m.1 i-1| ≤ 2 := - abs_le.mpr ⟨by linarith [coordinate_nonneg m i], by linarith [coordinate_le_three m i]⟩ - -variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] - -lemma discrete_degradation_abs (p : Spin → PMF α) (K : α → PMF β) (i : Spin) : - (∫ b, |(discreteMessage (fun j ↦ (p j).bind K) b).1 i-1| - ∂(discreteMarginal (fun j ↦ (p j).bind K)).toMeasure) ≤ - ∫ a, |(discreteMessage p a).1 i-1| ∂(discreteMarginal p).toMeasure := by - let q := fun j ↦ (p j).bind K - let g : β → ℝ := fun b ↦ if 0 ≤ (discreteMessage q b).1 i-1 then 1 else -1 - have hg (b : β) : |g b| ≤ 1 := by dsimp [g]; split_ifs <;> norm_num - have he (b : β) : ((discreteMessage q b).1 i-1)*g b = |(discreteMessage q b).1 i-1| := by - dsimp [g]; split_ifs with h - · simp [abs_of_nonneg h] - · simp [abs_of_neg (lt_of_not_ge h)] - have hb (z : α × β) : |((discreteMessage p z.1).1 i-1)*g z.2| ≤ 2 := by - rw [abs_mul] - exact (mul_le_mul (coord_center_abs_le_two _ _) (hg _) (abs_nonneg _) (by norm_num)).trans_eq (by norm_num) - have hi := discrete_degradation_centered p K i hg - have hid (z : α × β) : ((discreteMessage p z.1).1 i-(discreteMessage q z.2).1 i)*g z.2 = - ((discreteMessage p z.1).1 i-1)*g z.2-|(discreteMessage q z.2).1 i-1| := by - rw [← he]; ring - change (∫ z : α × β, ((discreteMessage p z.1).1 i-(discreteMessage q z.2).1 i)*g z.2 ∂_) = 0 at hi - simp_rw [hid] at hi - rw [integral_sub (pmf_bounded_integrable _ hb) - (pmf_bounded_integrable _ (fun z : α × β ↦ by simpa using coord_center_abs_le_two (discreteMessage q z.2) i))] at hi - have hle : (∫ z, ((discreteMessage p z.1).1 i-1)*g z.2 ∂(kernelJoint (discreteMarginal p) K).toMeasure) ≤ - ∫ z, |(discreteMessage p z.1).1 i-1| ∂(kernelJoint (discreteMarginal p) K).toMeasure := - integral_mono (μ := (kernelJoint (discreteMarginal p) K).toMeasure) - (pmf_bounded_integrable _ hb) - (pmf_bounded_integrable _ (fun z : α × β ↦ by simpa using coord_center_abs_le_two (discreteMessage p z.1) i)) - (fun z : α × β ↦ (le_abs_self _).trans (by - rw [abs_mul]; exact mul_le_of_le_one_right (abs_nonneg _) (hg _))) - rw [integral_kernelJoint_fst (f := fun a ↦ |(discreteMessage p a).1 i-1|)] at hle - rw [integral_kernelJoint_snd (f := fun b ↦ |(discreteMessage q b).1 i-1|), ← discreteMarginal_bind] at hi - change _ - (∫ b, |(discreteMessage q b).1 i-1| ∂(discreteMarginal q).toMeasure) = 0 at hi - linarith - -lemma discrete_degradation_tv (p : Spin → PMF α) (K : α → PMF β) : - (∫ m, tvMessage m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure) ≤ - ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by - rw [integral_discreteProbability _ continuous_tvMessage.measurable, - integral_discreteProbability _ continuous_tvMessage.measurable] - unfold tvMessage - rw [integral_div, integral_div, integral_avg_measure, integral_avg_measure] - · exact div_le_div_of_nonneg_right (by - dsimp [avg] - linarith [discrete_degradation_abs p K 0, discrete_degradation_abs p K 1, - discrete_degradation_abs p K 2]) (by norm_num) - all_goals intro i; exact pmf_bounded_integrable _ (fun a ↦ by simpa using coord_center_abs_le_two _ i) - -lemma advantage_antitone (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : - Antitone (advantage lam hlam offspring) := by - apply antitone_nat_of_succ_le - intro ℓ - simp only [advantage_eq_integral] - have h := discrete_degradation_tv (observationLaw lam hlam offspring ℓ) - (observationExpansion lam hlam offspring ℓ) - simpa only [observationLaw_degrades] using h - -lemma advantage_tendsto (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : - Tendsto (advantage lam hlam offspring) atTop (𝓝 (⨅ ℓ, advantage lam hlam offspring ℓ)) := - tendsto_atTop_ciInf (advantage_antitone lam hlam offspring) - ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact advantage_nonneg lam hlam offspring ℓ⟩ - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - -lemma integral_discreteMarginal (p : Spin → PMF α) {f : α → ℝ} {B : ℝ} (hB : ∀ a, |f a| ≤ B) : - (∫ a, f a ∂(discreteMarginal p).toMeasure) = - ((∫ a, f a ∂(p 0).toMeasure)+(∫ a, f a ∂(p 1).toMeasure)+(∫ a, f a ∂(p 2).toMeasure))/3 := by - rw [discreteMarginal, integral_pmf_bind _ _ hB, PMF.integral_eq_sum] - simp only [Fin.sum_univ_three, uniformSpin_apply, ENNReal.toReal_div, - ENNReal.toReal_one, ENNReal.toReal_ofNat, smul_eq_mul] - ring - -lemma coord_sq_le_tv (m : Message) (i : Spin) : (m.1 i-1)^2 ≤ 12*tvMessage m := by - have h := mul_le_mul_of_nonneg_left (coord_center_abs_le_two m i) (abs_nonneg (m.1 i-1)) - rw [← sq, sq_abs] at h - have hs : |m.1 i-1| ≤ ∑ j : Spin, |m.1 j-1| := - Finset.single_le_sum (f := fun j : Spin ↦ |m.1 j-1|) (fun j _ ↦ abs_nonneg _) (Finset.mem_univ i) - simp only [Fin.sum_univ_three] at hs - dsimp [tvMessage, avg] - linarith - -omit [Countable α] [MeasurableSingletonClass α] in -lemma integral_scaled_square (μ : Measure α) {v f : α → ℝ} (r : ℝ) - (hv : Integrable (fun a ↦ v a^2) μ) (hf : Integrable (fun a ↦ f a^2) μ) - (hc : Integrable (fun a ↦ v a*f a) μ) : - (∫ a, (v a-r*f a)^2 ∂μ) = (∫ a, v a^2 ∂μ)-2*r*(∫ a, v a*f a ∂μ)+r^2*(∫ a, f a^2 ∂μ) := by - have he (a : α) : (v a-r*f a)^2 = (v a^2-(2*r)*(v a*f a))+r^2*f a^2 := by ring - simp_rw [he] - rw [integral_add (f := fun a ↦ v a^2-(2*r)*(v a*f a)) (g := fun a ↦ r^2*f a^2) - (hv.sub (hc.const_mul (2*r))) (hf.const_mul (r^2))] - rw [integral_sub hv (hc.const_mul (2*r))] - rw [integral_const_mul, integral_const_mul] - -lemma estimator_tv_lower (p : Spin → PMF α) {f : α → ℝ} {B C : ℝ} - (hB : ∀ a, |f a| ≤ B) (hC : 0 < C) - (hzero : (∫ a, f a ∂(discreteMarginal p).toMeasure) = 0) - (hroot : (∫ a, f a ∂(p 0).toMeasure) = 2) - (hsecond : (∫ a, f a^2 ∂(discreteMarginal p).toMeasure) ≤ C) : - 1/(3*C) ≤ ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by - let v : α → ℝ := fun a ↦ (discreteMessage p a).1 0-1 - have hv (a : α) : |v a| ≤ 2 := coord_center_abs_le_two _ _ - have hf₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |f a^2| ≤ B^2 by - rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hB a, abs_nonneg (f a), sq_abs (f a)]) - have hv₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a^2| ≤ (2:ℝ)^2 by - rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hv a, abs_nonneg (v a), sq_abs (v a)]) - have hvf := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a*f a| ≤ 2*B by - rw [abs_mul]; exact mul_le_mul (hv a) (hB a) (abs_nonneg _) (by norm_num)) - have hcross : (∫ a, v a*f a ∂(discreteMarginal p).toMeasure) = 2 := by - have he (a : α) : v a*f a = (discreteMessage p a).1 0*f a-f a := by dsimp [v]; ring - simp_rw [he] - rw [integral_sub (pmf_bounded_integrable _ (fun a ↦ show |(discreteMessage p a).1 0*f a| ≤ 3*B by - rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)]; exact mul_le_mul (coordinate_le_three _ _) (hB a) (abs_nonneg _) (by norm_num))) - (pmf_bounded_integrable _ hB), discrete_bayes_integral p 0 hB, hroot, hzero, sub_zero] - let r := 2/C - have hr : r*C = 2 := div_mul_cancel₀ 2 hC.ne' - have h := MeasureTheory.integral_nonneg (μ := (discreteMarginal p).toMeasure) - (f := fun a ↦ (v a-r*f a)^2) (fun _ ↦ sq_nonneg _) - rw [integral_scaled_square _ r hv₂ hf₂ hvf, hcross] at h - have hb := mul_le_mul_of_nonneg_left hsecond (sq_nonneg r) - have hr2 : r^2*C = 2*r := by - have hh := congrArg (fun x : ℝ ↦ r*x) hr - nlinarith only [hh] - have hD : 4 ≤ C*(∫ a, v a^2 ∂(discreteMarginal p).toMeasure) := by - have hs : 2*r ≤ ∫ a, v a^2 ∂(discreteMarginal p).toMeasure := by - nlinarith only [h, hb, hr2] - have hh := mul_le_mul_of_nonneg_left hs hC.le - nlinarith only [hh, hr] - have hT := integral_mono hv₂ (pmf_bounded_integrable (discreteMarginal p) - (fun a ↦ show |12*tvMessage (discreteMessage p a)| ≤ 12 by - rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 12), abs_of_nonneg (tvMessage_nonneg _)]; - nlinarith [tvMessage_le_one (discreteMessage p a)])) - (fun a ↦ coord_sq_le_tv (discreteMessage p a) 0) - rw [integral_const_mul, ← integral_discreteProbability p continuous_tvMessage.measurable] at hT - apply (div_le_iff₀ (by positivity : 0 < 3*C)).2 - have hh := mul_le_mul_of_nonneg_left hT hC.le - nlinarith only [hD, hh] - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.CompactLimits + +namespace OAI + +/-! Information Loss. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment + +variable {α β γ : Type} + +def multisetKernel (K : α → PMF β) (s : Multiset α) : PMF (Multiset β) := + Multiset.recOn s (PMF.pure 0) + (fun a _ p ↦ (K a).bind (fun b ↦ p.map (Multiset.cons b))) (by + intro a a' s p + apply heq_of_eq + simp only [PMF.map_bind, PMF.map_comp] + rw [PMF.bind_comm (K a) (K a')] + congr 1 + funext b' + congr 1 + funext b + congr 1 + funext t + exact Multiset.cons_swap _ _ _) + +@[simp] lemma multisetKernel_zero (K : α → PMF β) : multisetKernel K 0 = PMF.pure 0 := by + rw [multisetKernel, Multiset.recOn_0] + +@[simp] lemma multisetKernel_cons (K : α → PMF β) (a : α) (s : Multiset α) : + multisetKernel K (a ::ₘ s) = (K a).bind (fun b ↦ (multisetKernel K s).map (Multiset.cons b)) := by + rw [multisetKernel, Multiset.recOn_cons] + rfl + +lemma multisetKernel_iid (p : PMF α) (K : α → PMF β) (n : ℕ) : + ((iidList p n).map (fun xs : List α ↦ (xs : Multiset α))).bind (multisetKernel K) = + (iidList (p.bind K) n).map (fun xs : List β ↦ (xs : Multiset β)) := by + induction n with + | zero => simp [iidList, PMF.pure_map] + | succ n ih => + simp only [iidList, PMF.map_bind, PMF.map_comp, PMF.bind_bind, PMF.bind_map] + congr 1 + funext a + simp only [Function.comp_def, ← Multiset.cons_coe, multisetKernel_cons] + rw [PMF.bind_comm (iidList p n) (K a)] + congr 1 + funext b + rw [← PMF.map_bind] + have hi := ih + rw [PMF.bind_map] at hi + dsimp only [Function.comp_def] at hi + rw [hi, PMF.map_comp] + rfl + +lemma observationLaw_succ (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (i : Spin) : + observationLaw lam hlam offspring (ℓ+1) i = offspring.bind (fun n ↦ + (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map + (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ)))) := by + rw [observationLaw] + congr 1 + funext n + exact PMF.map_id _ + +def observationExpansion (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : + (ℓ : ℕ) → Observation ℓ → PMF (Observation (ℓ+1)) + | 0, i => observationLaw lam hlam offspring 1 i + | ℓ+1, s => multisetKernel (observationExpansion lam hlam offspring ℓ) s + +lemma observationLaw_degrades (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) + (ℓ : ℕ) (i : Spin) : + (observationLaw lam hlam offspring ℓ i).bind (observationExpansion lam hlam offspring ℓ) = + observationLaw lam hlam offspring (ℓ+1) i := by + induction ℓ generalizing i with + | zero => exact PMF.pure_bind _ _ + | succ ℓ ih => + rw [observationLaw_succ, observationLaw_succ] + change ((offspring.bind (fun n ↦ (iidList ((channel lam hlam i).bind (observationLaw lam hlam offspring ℓ)) n).map + (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))))).bind + (multisetKernel (observationExpansion lam hlam offspring ℓ))) = _ + rw [PMF.bind_bind] + congr 1 + funext n + rw [multisetKernel_iid] + congr 2 + rw [PMF.bind_bind] + congr 1 + funext j + exact ih j + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped BigOperators Topology +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma coord_center_abs_le_two (m : Message) (i : Spin) : |m.1 i-1| ≤ 2 := + abs_le.mpr ⟨by linarith [coordinate_nonneg m i], by linarith [coordinate_le_three m i]⟩ + +variable {α β : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Countable β] [MeasurableSpace β] [MeasurableSingletonClass β] + +lemma discrete_degradation_abs (p : Spin → PMF α) (K : α → PMF β) (i : Spin) : + (∫ b, |(discreteMessage (fun j ↦ (p j).bind K) b).1 i-1| + ∂(discreteMarginal (fun j ↦ (p j).bind K)).toMeasure) ≤ + ∫ a, |(discreteMessage p a).1 i-1| ∂(discreteMarginal p).toMeasure := by + let q := fun j ↦ (p j).bind K + let g : β → ℝ := fun b ↦ if 0 ≤ (discreteMessage q b).1 i-1 then 1 else -1 + have hg (b : β) : |g b| ≤ 1 := by dsimp [g]; split_ifs <;> norm_num + have he (b : β) : ((discreteMessage q b).1 i-1)*g b = |(discreteMessage q b).1 i-1| := by + dsimp [g]; split_ifs with h + · simp [abs_of_nonneg h] + · simp [abs_of_neg (lt_of_not_ge h)] + have hb (z : α × β) : |((discreteMessage p z.1).1 i-1)*g z.2| ≤ 2 := by + rw [abs_mul] + exact (mul_le_mul (coord_center_abs_le_two _ _) (hg _) (abs_nonneg _) (by norm_num)).trans_eq (by norm_num) + have hi := discrete_degradation_centered p K i hg + have hid (z : α × β) : ((discreteMessage p z.1).1 i-(discreteMessage q z.2).1 i)*g z.2 = + ((discreteMessage p z.1).1 i-1)*g z.2-|(discreteMessage q z.2).1 i-1| := by + rw [← he]; ring + change (∫ z : α × β, ((discreteMessage p z.1).1 i-(discreteMessage q z.2).1 i)*g z.2 ∂_) = 0 at hi + simp_rw [hid] at hi + rw [integral_sub (pmf_bounded_integrable _ hb) + (pmf_bounded_integrable _ (fun z : α × β ↦ by simpa using coord_center_abs_le_two (discreteMessage q z.2) i))] at hi + have hle : (∫ z, ((discreteMessage p z.1).1 i-1)*g z.2 ∂(kernelJoint (discreteMarginal p) K).toMeasure) ≤ + ∫ z, |(discreteMessage p z.1).1 i-1| ∂(kernelJoint (discreteMarginal p) K).toMeasure := + integral_mono (μ := (kernelJoint (discreteMarginal p) K).toMeasure) + (pmf_bounded_integrable _ hb) + (pmf_bounded_integrable _ (fun z : α × β ↦ by simpa using coord_center_abs_le_two (discreteMessage p z.1) i)) + (fun z : α × β ↦ (le_abs_self _).trans (by + rw [abs_mul]; exact mul_le_of_le_one_right (abs_nonneg _) (hg _))) + rw [integral_kernelJoint_fst (f := fun a ↦ |(discreteMessage p a).1 i-1|)] at hle + rw [integral_kernelJoint_snd (f := fun b ↦ |(discreteMessage q b).1 i-1|), ← discreteMarginal_bind] at hi + change _ - (∫ b, |(discreteMessage q b).1 i-1| ∂(discreteMarginal q).toMeasure) = 0 at hi + linarith + +lemma discrete_degradation_tv (p : Spin → PMF α) (K : α → PMF β) : + (∫ m, tvMessage m ∂(discreteProbability (fun i ↦ (p i).bind K)).toMeasure) ≤ + ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by + rw [integral_discreteProbability _ continuous_tvMessage.measurable, + integral_discreteProbability _ continuous_tvMessage.measurable] + unfold tvMessage + rw [integral_div, integral_div, integral_avg_measure, integral_avg_measure] + · exact div_le_div_of_nonneg_right (by + dsimp [avg] + linarith [discrete_degradation_abs p K 0, discrete_degradation_abs p K 1, + discrete_degradation_abs p K 2]) (by norm_num) + all_goals intro i; exact pmf_bounded_integrable _ (fun a ↦ by simpa using coord_center_abs_le_two _ i) + +lemma advantage_antitone (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : + Antitone (advantage lam hlam offspring) := by + apply antitone_nat_of_succ_le + intro ℓ + simp only [advantage_eq_integral] + have h := discrete_degradation_tv (observationLaw lam hlam offspring ℓ) + (observationExpansion lam hlam offspring ℓ) + simpa only [observationLaw_degrades] using h + +lemma advantage_tendsto (lam : ℝ) (hlam : Admissible lam) (offspring : PMF ℕ) : + Tendsto (advantage lam hlam offspring) atTop (𝓝 (⨅ ℓ, advantage lam hlam offspring ℓ)) := + tendsto_atTop_ciInf (advantage_antitone lam hlam offspring) + ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact advantage_nonneg lam hlam offspring ℓ⟩ + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α : Type*} [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + +lemma integral_discreteMarginal (p : Spin → PMF α) {f : α → ℝ} {B : ℝ} (hB : ∀ a, |f a| ≤ B) : + (∫ a, f a ∂(discreteMarginal p).toMeasure) = + ((∫ a, f a ∂(p 0).toMeasure)+(∫ a, f a ∂(p 1).toMeasure)+(∫ a, f a ∂(p 2).toMeasure))/3 := by + rw [discreteMarginal, integral_pmf_bind _ _ hB, PMF.integral_eq_sum] + simp only [Fin.sum_univ_three, uniformSpin_apply, ENNReal.toReal_div, + ENNReal.toReal_one, ENNReal.toReal_ofNat, smul_eq_mul] + ring + +lemma coord_sq_le_tv (m : Message) (i : Spin) : (m.1 i-1)^2 ≤ 12*tvMessage m := by + have h := mul_le_mul_of_nonneg_left (coord_center_abs_le_two m i) (abs_nonneg (m.1 i-1)) + rw [← sq, sq_abs] at h + have hs : |m.1 i-1| ≤ ∑ j : Spin, |m.1 j-1| := + Finset.single_le_sum (f := fun j : Spin ↦ |m.1 j-1|) (fun j _ ↦ abs_nonneg _) (Finset.mem_univ i) + simp only [Fin.sum_univ_three] at hs + dsimp [tvMessage, avg] + linarith + +omit [Countable α] [MeasurableSingletonClass α] in +lemma integral_scaled_square (μ : Measure α) {v f : α → ℝ} (r : ℝ) + (hv : Integrable (fun a ↦ v a^2) μ) (hf : Integrable (fun a ↦ f a^2) μ) + (hc : Integrable (fun a ↦ v a*f a) μ) : + (∫ a, (v a-r*f a)^2 ∂μ) = (∫ a, v a^2 ∂μ)-2*r*(∫ a, v a*f a ∂μ)+r^2*(∫ a, f a^2 ∂μ) := by + have he (a : α) : (v a-r*f a)^2 = (v a^2-(2*r)*(v a*f a))+r^2*f a^2 := by ring + simp_rw [he] + rw [integral_add (f := fun a ↦ v a^2-(2*r)*(v a*f a)) (g := fun a ↦ r^2*f a^2) + (hv.sub (hc.const_mul (2*r))) (hf.const_mul (r^2))] + rw [integral_sub hv (hc.const_mul (2*r))] + rw [integral_const_mul, integral_const_mul] + +lemma estimator_tv_lower (p : Spin → PMF α) {f : α → ℝ} {B C : ℝ} + (hB : ∀ a, |f a| ≤ B) (hC : 0 < C) + (hzero : (∫ a, f a ∂(discreteMarginal p).toMeasure) = 0) + (hroot : (∫ a, f a ∂(p 0).toMeasure) = 2) + (hsecond : (∫ a, f a^2 ∂(discreteMarginal p).toMeasure) ≤ C) : + 1/(3*C) ≤ ∫ m, tvMessage m ∂(discreteProbability p).toMeasure := by + let v : α → ℝ := fun a ↦ (discreteMessage p a).1 0-1 + have hv (a : α) : |v a| ≤ 2 := coord_center_abs_le_two _ _ + have hf₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |f a^2| ≤ B^2 by + rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hB a, abs_nonneg (f a), sq_abs (f a)]) + have hv₂ := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a^2| ≤ (2:ℝ)^2 by + rw [abs_of_nonneg (sq_nonneg _)]; nlinarith [hv a, abs_nonneg (v a), sq_abs (v a)]) + have hvf := pmf_bounded_integrable (discreteMarginal p) (fun a ↦ show |v a*f a| ≤ 2*B by + rw [abs_mul]; exact mul_le_mul (hv a) (hB a) (abs_nonneg _) (by norm_num)) + have hcross : (∫ a, v a*f a ∂(discreteMarginal p).toMeasure) = 2 := by + have he (a : α) : v a*f a = (discreteMessage p a).1 0*f a-f a := by dsimp [v]; ring + simp_rw [he] + rw [integral_sub (pmf_bounded_integrable _ (fun a ↦ show |(discreteMessage p a).1 0*f a| ≤ 3*B by + rw [abs_mul, abs_of_nonneg (coordinate_nonneg _ _)]; exact mul_le_mul (coordinate_le_three _ _) (hB a) (abs_nonneg _) (by norm_num))) + (pmf_bounded_integrable _ hB), discrete_bayes_integral p 0 hB, hroot, hzero, sub_zero] + let r := 2/C + have hr : r*C = 2 := div_mul_cancel₀ 2 hC.ne' + have h := MeasureTheory.integral_nonneg (μ := (discreteMarginal p).toMeasure) + (f := fun a ↦ (v a-r*f a)^2) (fun _ ↦ sq_nonneg _) + rw [integral_scaled_square _ r hv₂ hf₂ hvf, hcross] at h + have hb := mul_le_mul_of_nonneg_left hsecond (sq_nonneg r) + have hr2 : r^2*C = 2*r := by + have hh := congrArg (fun x : ℝ ↦ r*x) hr + nlinarith only [hh] + have hD : 4 ≤ C*(∫ a, v a^2 ∂(discreteMarginal p).toMeasure) := by + have hs : 2*r ≤ ∫ a, v a^2 ∂(discreteMarginal p).toMeasure := by + nlinarith only [h, hb, hr2] + have hh := mul_le_mul_of_nonneg_left hs hC.le + nlinarith only [hh, hr] + have hT := integral_mono hv₂ (pmf_bounded_integrable (discreteMarginal p) + (fun a ↦ show |12*tvMessage (discreteMessage p a)| ≤ 12 by + rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 12), abs_of_nonneg (tvMessage_nonneg _)]; + nlinarith [tvMessage_le_one (discreteMessage p a)])) + (fun a ↦ coord_sq_le_tv (discreteMessage p a) 0) + rw [integral_const_mul, ← integral_discreteProbability p continuous_tvMessage.measurable] at hT + apply (div_le_iff₀ (by positivity : 0 < 3*C)).2 + have hh := mul_le_mul_of_nonneg_left hT hC.le + nlinarith only [hD, hh] + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Main.lean b/lean/OAI/Probability/ThreeStateClauses/Main.lean index 50afbe5a7060cc8cec8e968062cf5d8a17d17227..2ae82e84f729678813f3ed15db23cff7c9a1d283 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Main.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Main.lean @@ -1,41 +1,41 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.Basic -import OAI.Probability.ThreeStateClauses.RadialAlgebra -import OAI.Probability.ThreeStateClauses.RadialBounds -import OAI.Probability.ThreeStateClauses.RadialCalculus -import OAI.Probability.ThreeStateClauses.PositiveMoments -import OAI.Probability.ThreeStateClauses.PosteriorLaw -import OAI.Probability.ThreeStateClauses.DiscreteLaw -import OAI.Probability.ThreeStateClauses.Products -import OAI.Probability.ThreeStateClauses.Degradation -import OAI.Probability.ThreeStateClauses.RegularLaw -import OAI.Probability.ThreeStateClauses.BranchMoments -import OAI.Probability.ThreeStateClauses.FiniteUpdate -import OAI.Probability.ThreeStateClauses.Correlation -import OAI.Probability.ThreeStateClauses.Projection -import OAI.Probability.ThreeStateClauses.BranchGrowth -import OAI.Probability.ThreeStateClauses.CompactLimits -import OAI.Probability.ThreeStateClauses.ScalarBounds -import OAI.Probability.ThreeStateClauses.PositiveFixed -import OAI.Probability.ThreeStateClauses.RegularCritical -import OAI.Probability.ThreeStateClauses.RegularStatistics -import OAI.Probability.ThreeStateClauses.InformationLoss -import OAI.Probability.ThreeStateClauses.RegularReconstruction -import OAI.Probability.ThreeStateClauses.ObservedMixtures -import OAI.Probability.ThreeStateClauses.OffspringLaws -import OAI.Probability.ThreeStateClauses.PoissonMoments -import OAI.Probability.ThreeStateClauses.PoissonLaw -import OAI.Probability.ThreeStateClauses.PoissonCalculus -import OAI.Probability.ThreeStateClauses.PoissonFixed -import OAI.Probability.ThreeStateClauses.CountableStatistics -import OAI.Probability.ThreeStateClauses.PoissonReconstruction - -namespace OAI - -/-! Positive-channel nonreconstruction and both-sign supercritical reconstruction for regular and observed Poisson trees. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter - - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.Basic +import OAI.Probability.ThreeStateClauses.RadialAlgebra +import OAI.Probability.ThreeStateClauses.RadialBounds +import OAI.Probability.ThreeStateClauses.RadialCalculus +import OAI.Probability.ThreeStateClauses.PositiveMoments +import OAI.Probability.ThreeStateClauses.PosteriorLaw +import OAI.Probability.ThreeStateClauses.DiscreteLaw +import OAI.Probability.ThreeStateClauses.Products +import OAI.Probability.ThreeStateClauses.Degradation +import OAI.Probability.ThreeStateClauses.RegularLaw +import OAI.Probability.ThreeStateClauses.BranchMoments +import OAI.Probability.ThreeStateClauses.FiniteUpdate +import OAI.Probability.ThreeStateClauses.Correlation +import OAI.Probability.ThreeStateClauses.Projection +import OAI.Probability.ThreeStateClauses.BranchGrowth +import OAI.Probability.ThreeStateClauses.CompactLimits +import OAI.Probability.ThreeStateClauses.ScalarBounds +import OAI.Probability.ThreeStateClauses.PositiveFixed +import OAI.Probability.ThreeStateClauses.RegularCritical +import OAI.Probability.ThreeStateClauses.RegularStatistics +import OAI.Probability.ThreeStateClauses.InformationLoss +import OAI.Probability.ThreeStateClauses.RegularReconstruction +import OAI.Probability.ThreeStateClauses.ObservedMixtures +import OAI.Probability.ThreeStateClauses.OffspringLaws +import OAI.Probability.ThreeStateClauses.PoissonMoments +import OAI.Probability.ThreeStateClauses.PoissonLaw +import OAI.Probability.ThreeStateClauses.PoissonCalculus +import OAI.Probability.ThreeStateClauses.PoissonFixed +import OAI.Probability.ThreeStateClauses.CountableStatistics +import OAI.Probability.ThreeStateClauses.PoissonReconstruction + +namespace OAI + +/-! Positive-channel nonreconstruction and both-sign supercritical reconstruction for regular and observed Poisson trees. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter + + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/ObservedMixtures.lean b/lean/OAI/Probability/ThreeStateClauses/ObservedMixtures.lean index 683ca33490e33aa717a30b084ea4d4916d36620a..095aef591f762a4159951359f04f3864b05b6b6d 100644 --- a/lean/OAI/Probability/ThreeStateClauses/ObservedMixtures.lean +++ b/lean/OAI/Probability/ThreeStateClauses/ObservedMixtures.lean @@ -1,215 +1,215 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.CompactLimits - -namespace OAI - -/-! Observed Mixtures. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory Filter -open scoped BigOperators Topology -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {X : Type*} [MeasurableSpace X] - -def mixtureProbability (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) : ProbabilityMeasure X := - ⟨Measure.sum (fun n ↦ ρ n • (P n).toMeasure), ⟨by - rw [Measure.sum_apply _ MeasurableSet.univ] - simpa only [Measure.smul_apply, measure_univ, smul_eq_mul, mul_one] using ρ.tsum_coe⟩⟩ - -lemma integral_mixtureProbability (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) - {f : X → ℝ} (hf : Integrable f (mixtureProbability ρ P).toMeasure) : - (∫ x, f x ∂(mixtureProbability ρ P).toMeasure) = - ∑' n, (ρ n).toReal*(∫ x, f x ∂(P n).toMeasure) := by - rw [show (mixtureProbability ρ P).toMeasure = Measure.sum (fun n ↦ ρ n • (P n).toMeasure) from rfl, - integral_sum_measure hf] - simp only [integral_smul_measure, smul_eq_mul] - -lemma pmf_hasSum_real (ρ : PMF ℕ) : HasSum (fun n ↦ (ρ n).toReal) 1 := by - have hs := ENNReal.summable_toReal ρ.tsum_coe_ne_top - convert hs.hasSum using 1 - rw [← ENNReal.tsum_toReal_eq (fun n ↦ ρ.apply_ne_top n), ρ.tsum_coe] - norm_num - -lemma mixture_balanced (ρ : PMF ℕ) (Q : ℕ → Law) (i : Fin 3) : - (∫ m, m.1 i ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = 1 := by - rw [integral_mixtureProbability _ _ (compact_integrable (continuous_coordinate i))] - simp only [Law.balanced, mul_one] - exact (pmf_hasSum_real ρ).tsum_eq - -lemma mixture_symmetric (ρ : PMF ℕ) (Q : ℕ → Law) (σ : Equiv.Perm (Fin 3)) : - MeasurePreserving (permute σ) (mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure - (mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure := by - refine ⟨(continuous_permute σ).measurable, ?_⟩ - change Measure.map _ (Measure.sum _) = Measure.sum _ - rw [Measure.map_sum (continuous_permute σ).measurable.aemeasurable] - congr 1; funext n - rw [Measure.map_smul _ (continuous_permute σ).measurable.aemeasurable, - (Q n).symmetric σ |>.map_eq] - -def mixtureLaw (ρ : PMF ℕ) (Q : ℕ → Law) : Law where - probability := mixtureProbability ρ (fun n ↦ (Q n).probability) - balanced := mixture_balanced ρ Q - symmetric := mixture_symmetric ρ Q - -def offspringLaw (ρ : PMF ℕ) (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : Law := - mixtureLaw ρ (finiteLaw Q hl₀ hl₁) - -lemma mixture_integrable (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) {f : X → ℝ} - (hf : ∀ n, Integrable f (P n).toMeasure) - (hs : Summable (fun n ↦ (ρ n).toReal*(∫ x, |f x| ∂(P n).toMeasure))) : - Integrable f (mixtureProbability ρ P).toMeasure := by - apply integrable_sum_measure - · intro n; exact (hf n).smul_measure (ρ.apply_ne_top n) - · simpa only [integral_smul_measure, smul_eq_mul, Real.norm_eq_abs] using hs - -variable [TopologicalSpace X] [CompactSpace X] [BorelSpace X] - -lemma mixtureProbability_tendsto {ι : Type*} {F : Filter ι} (ρ : PMF ℕ) - {P : ι → ℕ → ProbabilityMeasure X} {R : ℕ → ProbabilityMeasure X} - (hP : ∀ n, Tendsto (fun i ↦ P i n) F (𝓝 (R n))) : - Tendsto (fun i ↦ mixtureProbability ρ (P i)) F (𝓝 (mixtureProbability ρ R)) := by - apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr - intro f - simp_rw [integral_mixtureProbability _ _ (compact_integrable f.continuous)] - apply tendsto_tsum_of_dominated_convergence ((pmf_hasSum_real ρ).summable.mul_right ‖f‖) - · intro n - exact tendsto_const_nhds.mul ((probability_continuous_integral f.continuous).tendsto (R n) |>.comp (hP n)) - · exact Filter.Eventually.of_forall (fun i n ↦ by - rw [norm_mul, Real.norm_of_nonneg ENNReal.toReal_nonneg] - apply mul_le_mul_of_nonneg_left _ ENNReal.toReal_nonneg - exact (norm_integral_le_integral_norm _).trans (by - exact (integral_mono (compact_integrable f.continuous.norm) (integrable_const _) - (fun x ↦ f.norm_coe_le_norm x)).trans_eq (by simp))) - -lemma offspringLaw_tendsto {ι : Type*} {F : Filter ι} (ρ : PMF ℕ) {Q : ι → Law} {R : Law} - {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hQ : Tendsto (fun i ↦ (Q i).probability) F (𝓝 R.probability)) : - Tendsto (fun i ↦ (offspringLaw ρ (Q i) hl₀ hl₁).probability) F - (𝓝 (offspringLaw ρ R hl₀ hl₁).probability) := - mixtureProbability_tendsto ρ (fun n ↦ finiteProbability_tendsto hQ hl₀ hl₁ n) - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -variable {α : ℕ → Type*} - -def sigmaPMF (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) : PMF (Sigma α) := - ⟨fun z ↦ ρ z.1*p z.1 z.2, ENNReal.summable.hasSum_iff.2 (by - rw [ENNReal.tsum_sigma'] - simp only [ENNReal.tsum_mul_left] - have hs (n : ℕ) : (∑' a, p n a) = 1 := (p n).tsum_coe - simp only [hs, mul_one] - exact ρ.tsum_coe)⟩ - -@[simp] lemma sigmaPMF_apply (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) (n : ℕ) (a : α n) : - sigmaPMF ρ p ⟨n,a⟩ = ρ n*p n a := rfl - -lemma sigmaPMF_eq_bind (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) : - sigmaPMF ρ p = ρ.bind (fun n ↦ (p n).map (Sigma.mk n)) := by - classical - apply PMF.ext - rintro ⟨n,a⟩ - rw [PMF.bind_apply, tsum_eq_single n] - · simp [PMF.map_apply] - · intro m hm - have hn : n ≠ m := Ne.symm hm - simp [PMF.map_apply, hn] - -lemma sigmaPMF_bind {β : Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) - (K : Sigma α → PMF β) : - (sigmaPMF ρ p).bind K = ρ.bind (fun n ↦ (p n).bind (fun a ↦ K ⟨n,a⟩)) := by - rw [sigmaPMF_eq_bind, PMF.bind_bind] - simp only [PMF.bind_map, Function.comp_def] - -lemma sigmaPMF_map {β : Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) - (T : Sigma α → β) : - (sigmaPMF ρ p).map T = ρ.bind (fun n ↦ (p n).map (fun a ↦ T ⟨n,a⟩)) := - sigmaPMF_bind ρ p (fun z ↦ PMF.pure (T z)) - -lemma sigmaPMF_bind_components {β : ℕ → Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) - (K : ∀ n, α n → PMF (β n)) : - (sigmaPMF ρ p).bind (fun z ↦ (K z.1 z.2).map (Sigma.mk z.1)) = - sigmaPMF ρ (fun n ↦ (p n).bind (K n)) := by - rw [sigmaPMF_bind, sigmaPMF_eq_bind] - simp only [PMF.map_bind] - -lemma discreteSigma_marginal (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) : - discreteMarginal (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) = - sigmaPMF ρ (fun n ↦ discreteMarginal (p n)) := by - apply PMF.ext - rintro ⟨n,a⟩ - simp only [discreteMarginal_apply, sigmaPMF_apply, div_eq_mul_inv] - ring - -lemma discreteSigma_weight (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) (n : ℕ) (a : α n) : - discreteWeight (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) ⟨n,a⟩ = - (ρ n).toReal*discreteWeight (p n) a := by - simp only [discreteWeight, sigmaPMF_apply, ENNReal.toReal_mul] - exact avg_mul _ _ - -lemma discreteSigma_message (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) - (n : ℕ) (a : α n) (hρ : (ρ n).toReal ≠ 0) : - discreteMessage (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) ⟨n,a⟩ = discreteMessage (p n) a := by - by_cases ha : discreteWeight (p n) a = 0 - · simp only [discreteMessage, discreteSigma_weight, ha, mul_zero, dite_true] - · apply Subtype.ext - funext i - rw [discrete_coord (by rw [discreteSigma_weight]; exact mul_ne_zero hρ ha), - discrete_coord ha, sigmaPMF_apply, ENNReal.toReal_mul, discreteSigma_weight] - exact mul_div_mul_left _ _ hρ - -section Measures -variable [∀ n, Countable (α n)] [∀ n, MeasurableSpace (α n)] - [∀ n, MeasurableSingletonClass (α n)] - -instance sigmaMeasurableSingleton : MeasurableSingletonClass (Sigma α) := by - constructor - intro z - apply MeasurableSpace.measurableSet_iInf.mpr - intro n - change MeasurableSet ((Sigma.mk n) ⁻¹' {z}) - exact Set.Countable.measurableSet (Set.to_countable _) - -lemma integral_sigmaPMF (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) {f : Sigma α → ℝ} {B : ℝ} - (hf : ∀ a, |f a| ≤ B) : - (∫ a, f a ∂(sigmaPMF ρ p).toMeasure) = - ∑' n, (ρ n).toReal*(∫ a, f ⟨n,a⟩ ∂(p n).toMeasure) := by - rw [sigmaPMF_eq_bind, pmf_measure_bind, integral_sum_measure] - · simp only [integral_smul_measure, smul_eq_mul, integral_pmf_map] - · rw [← pmf_measure_bind] - exact pmf_bounded_integrable _ hf - -lemma discreteSigma_probability (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) : - discreteProbability (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) = - mixtureProbability ρ (fun n ↦ discreteProbability (p n)) := by - apply probability_ext_continuous - intro f hf - obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hf.continuousOn - have hbf (m : Message) : |f m| ≤ B := by simpa only [Real.norm_eq_abs] using hB m (mem_univ m) - rw [integral_discreteProbability _ hf.measurable, discreteSigma_marginal, - integral_sigmaPMF ρ _ (fun z ↦ hbf _), - integral_mixtureProbability _ _ (compact_integrable hf)] - apply tsum_congr - intro n - rw [integral_discreteProbability _ hf.measurable] - by_cases hρ : (ρ n).toReal = 0 - · simp [hρ] - · simp_rw [discreteSigma_message ρ p n _ hρ] - -end Measures -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.CompactLimits + +namespace OAI + +/-! Observed Mixtures. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory Filter +open scoped BigOperators Topology +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {X : Type*} [MeasurableSpace X] + +def mixtureProbability (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) : ProbabilityMeasure X := + ⟨Measure.sum (fun n ↦ ρ n • (P n).toMeasure), ⟨by + rw [Measure.sum_apply _ MeasurableSet.univ] + simpa only [Measure.smul_apply, measure_univ, smul_eq_mul, mul_one] using ρ.tsum_coe⟩⟩ + +lemma integral_mixtureProbability (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) + {f : X → ℝ} (hf : Integrable f (mixtureProbability ρ P).toMeasure) : + (∫ x, f x ∂(mixtureProbability ρ P).toMeasure) = + ∑' n, (ρ n).toReal*(∫ x, f x ∂(P n).toMeasure) := by + rw [show (mixtureProbability ρ P).toMeasure = Measure.sum (fun n ↦ ρ n • (P n).toMeasure) from rfl, + integral_sum_measure hf] + simp only [integral_smul_measure, smul_eq_mul] + +lemma pmf_hasSum_real (ρ : PMF ℕ) : HasSum (fun n ↦ (ρ n).toReal) 1 := by + have hs := ENNReal.summable_toReal ρ.tsum_coe_ne_top + convert hs.hasSum using 1 + rw [← ENNReal.tsum_toReal_eq (fun n ↦ ρ.apply_ne_top n), ρ.tsum_coe] + norm_num + +lemma mixture_balanced (ρ : PMF ℕ) (Q : ℕ → Law) (i : Fin 3) : + (∫ m, m.1 i ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = 1 := by + rw [integral_mixtureProbability _ _ (compact_integrable (continuous_coordinate i))] + simp only [Law.balanced, mul_one] + exact (pmf_hasSum_real ρ).tsum_eq + +lemma mixture_symmetric (ρ : PMF ℕ) (Q : ℕ → Law) (σ : Equiv.Perm (Fin 3)) : + MeasurePreserving (permute σ) (mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure + (mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure := by + refine ⟨(continuous_permute σ).measurable, ?_⟩ + change Measure.map _ (Measure.sum _) = Measure.sum _ + rw [Measure.map_sum (continuous_permute σ).measurable.aemeasurable] + congr 1; funext n + rw [Measure.map_smul _ (continuous_permute σ).measurable.aemeasurable, + (Q n).symmetric σ |>.map_eq] + +def mixtureLaw (ρ : PMF ℕ) (Q : ℕ → Law) : Law where + probability := mixtureProbability ρ (fun n ↦ (Q n).probability) + balanced := mixture_balanced ρ Q + symmetric := mixture_symmetric ρ Q + +def offspringLaw (ρ : PMF ℕ) (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : Law := + mixtureLaw ρ (finiteLaw Q hl₀ hl₁) + +lemma mixture_integrable (ρ : PMF ℕ) (P : ℕ → ProbabilityMeasure X) {f : X → ℝ} + (hf : ∀ n, Integrable f (P n).toMeasure) + (hs : Summable (fun n ↦ (ρ n).toReal*(∫ x, |f x| ∂(P n).toMeasure))) : + Integrable f (mixtureProbability ρ P).toMeasure := by + apply integrable_sum_measure + · intro n; exact (hf n).smul_measure (ρ.apply_ne_top n) + · simpa only [integral_smul_measure, smul_eq_mul, Real.norm_eq_abs] using hs + +variable [TopologicalSpace X] [CompactSpace X] [BorelSpace X] + +lemma mixtureProbability_tendsto {ι : Type*} {F : Filter ι} (ρ : PMF ℕ) + {P : ι → ℕ → ProbabilityMeasure X} {R : ℕ → ProbabilityMeasure X} + (hP : ∀ n, Tendsto (fun i ↦ P i n) F (𝓝 (R n))) : + Tendsto (fun i ↦ mixtureProbability ρ (P i)) F (𝓝 (mixtureProbability ρ R)) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro f + simp_rw [integral_mixtureProbability _ _ (compact_integrable f.continuous)] + apply tendsto_tsum_of_dominated_convergence ((pmf_hasSum_real ρ).summable.mul_right ‖f‖) + · intro n + exact tendsto_const_nhds.mul ((probability_continuous_integral f.continuous).tendsto (R n) |>.comp (hP n)) + · exact Filter.Eventually.of_forall (fun i n ↦ by + rw [norm_mul, Real.norm_of_nonneg ENNReal.toReal_nonneg] + apply mul_le_mul_of_nonneg_left _ ENNReal.toReal_nonneg + exact (norm_integral_le_integral_norm _).trans (by + exact (integral_mono (compact_integrable f.continuous.norm) (integrable_const _) + (fun x ↦ f.norm_coe_le_norm x)).trans_eq (by simp))) + +lemma offspringLaw_tendsto {ι : Type*} {F : Filter ι} (ρ : PMF ℕ) {Q : ι → Law} {R : Law} + {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hQ : Tendsto (fun i ↦ (Q i).probability) F (𝓝 R.probability)) : + Tendsto (fun i ↦ (offspringLaw ρ (Q i) hl₀ hl₁).probability) F + (𝓝 (offspringLaw ρ R hl₀ hl₁).probability) := + mixtureProbability_tendsto ρ (fun n ↦ finiteProbability_tendsto hQ hl₀ hl₁ n) + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +variable {α : ℕ → Type*} + +def sigmaPMF (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) : PMF (Sigma α) := + ⟨fun z ↦ ρ z.1*p z.1 z.2, ENNReal.summable.hasSum_iff.2 (by + rw [ENNReal.tsum_sigma'] + simp only [ENNReal.tsum_mul_left] + have hs (n : ℕ) : (∑' a, p n a) = 1 := (p n).tsum_coe + simp only [hs, mul_one] + exact ρ.tsum_coe)⟩ + +@[simp] lemma sigmaPMF_apply (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) (n : ℕ) (a : α n) : + sigmaPMF ρ p ⟨n,a⟩ = ρ n*p n a := rfl + +lemma sigmaPMF_eq_bind (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) : + sigmaPMF ρ p = ρ.bind (fun n ↦ (p n).map (Sigma.mk n)) := by + classical + apply PMF.ext + rintro ⟨n,a⟩ + rw [PMF.bind_apply, tsum_eq_single n] + · simp [PMF.map_apply] + · intro m hm + have hn : n ≠ m := Ne.symm hm + simp [PMF.map_apply, hn] + +lemma sigmaPMF_bind {β : Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) + (K : Sigma α → PMF β) : + (sigmaPMF ρ p).bind K = ρ.bind (fun n ↦ (p n).bind (fun a ↦ K ⟨n,a⟩)) := by + rw [sigmaPMF_eq_bind, PMF.bind_bind] + simp only [PMF.bind_map, Function.comp_def] + +lemma sigmaPMF_map {β : Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) + (T : Sigma α → β) : + (sigmaPMF ρ p).map T = ρ.bind (fun n ↦ (p n).map (fun a ↦ T ⟨n,a⟩)) := + sigmaPMF_bind ρ p (fun z ↦ PMF.pure (T z)) + +lemma sigmaPMF_bind_components {β : ℕ → Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) + (K : ∀ n, α n → PMF (β n)) : + (sigmaPMF ρ p).bind (fun z ↦ (K z.1 z.2).map (Sigma.mk z.1)) = + sigmaPMF ρ (fun n ↦ (p n).bind (K n)) := by + rw [sigmaPMF_bind, sigmaPMF_eq_bind] + simp only [PMF.map_bind] + +lemma discreteSigma_marginal (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) : + discreteMarginal (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) = + sigmaPMF ρ (fun n ↦ discreteMarginal (p n)) := by + apply PMF.ext + rintro ⟨n,a⟩ + simp only [discreteMarginal_apply, sigmaPMF_apply, div_eq_mul_inv] + ring + +lemma discreteSigma_weight (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) (n : ℕ) (a : α n) : + discreteWeight (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) ⟨n,a⟩ = + (ρ n).toReal*discreteWeight (p n) a := by + simp only [discreteWeight, sigmaPMF_apply, ENNReal.toReal_mul] + exact avg_mul _ _ + +lemma discreteSigma_message (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) + (n : ℕ) (a : α n) (hρ : (ρ n).toReal ≠ 0) : + discreteMessage (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) ⟨n,a⟩ = discreteMessage (p n) a := by + by_cases ha : discreteWeight (p n) a = 0 + · simp only [discreteMessage, discreteSigma_weight, ha, mul_zero, dite_true] + · apply Subtype.ext + funext i + rw [discrete_coord (by rw [discreteSigma_weight]; exact mul_ne_zero hρ ha), + discrete_coord ha, sigmaPMF_apply, ENNReal.toReal_mul, discreteSigma_weight] + exact mul_div_mul_left _ _ hρ + +section Measures +variable [∀ n, Countable (α n)] [∀ n, MeasurableSpace (α n)] + [∀ n, MeasurableSingletonClass (α n)] + +instance sigmaMeasurableSingleton : MeasurableSingletonClass (Sigma α) := by + constructor + intro z + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + change MeasurableSet ((Sigma.mk n) ⁻¹' {z}) + exact Set.Countable.measurableSet (Set.to_countable _) + +lemma integral_sigmaPMF (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) {f : Sigma α → ℝ} {B : ℝ} + (hf : ∀ a, |f a| ≤ B) : + (∫ a, f a ∂(sigmaPMF ρ p).toMeasure) = + ∑' n, (ρ n).toReal*(∫ a, f ⟨n,a⟩ ∂(p n).toMeasure) := by + rw [sigmaPMF_eq_bind, pmf_measure_bind, integral_sum_measure] + · simp only [integral_smul_measure, smul_eq_mul, integral_pmf_map] + · rw [← pmf_measure_bind] + exact pmf_bounded_integrable _ hf + +lemma discreteSigma_probability (ρ : PMF ℕ) (p : ∀ n, Spin → PMF (α n)) : + discreteProbability (fun i ↦ sigmaPMF ρ (fun n ↦ p n i)) = + mixtureProbability ρ (fun n ↦ discreteProbability (p n)) := by + apply probability_ext_continuous + intro f hf + obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hf.continuousOn + have hbf (m : Message) : |f m| ≤ B := by simpa only [Real.norm_eq_abs] using hB m (mem_univ m) + rw [integral_discreteProbability _ hf.measurable, discreteSigma_marginal, + integral_sigmaPMF ρ _ (fun z ↦ hbf _), + integral_mixtureProbability _ _ (compact_integrable hf)] + apply tsum_congr + intro n + rw [integral_discreteProbability _ hf.measurable] + by_cases hρ : (ρ n).toReal = 0 + · simp [hρ] + · simp_rw [discreteSigma_message ρ p n _ hρ] + +end Measures +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/OffspringLaws.lean b/lean/OAI/Probability/ThreeStateClauses/OffspringLaws.lean index 9a6ca26c1dae11d9de6e7c1355bb281b893963e3..f501f2de3e497aaf440a37d97671b5901e94d8ae 100644 --- a/lean/OAI/Probability/ThreeStateClauses/OffspringLaws.lean +++ b/lean/OAI/Probability/ThreeStateClauses/OffspringLaws.lean @@ -1,256 +1,256 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RegularCritical -import OAI.Probability.ThreeStateClauses.ObservedMixtures - -namespace OAI - -/-! Offspring Laws. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -@[reducible] def OrderedObservation : ℕ → Type - | 0 => Spin - | ℓ+1 => Σ n : ℕ, Fin n → OrderedObservation ℓ - -instance orderedObservationCountable : (ℓ : ℕ) → Countable (OrderedObservation ℓ) - | 0 => inferInstanceAs (Countable Spin) - | ℓ+1 => letI := orderedObservationCountable ℓ - inferInstanceAs (Countable (Σ n : ℕ, Fin n → OrderedObservation ℓ)) - -instance orderedObservationMeasurable : (ℓ : ℕ) → MeasurableSpace (OrderedObservation ℓ) - | 0 => inferInstanceAs (MeasurableSpace Spin) - | ℓ+1 => letI := orderedObservationMeasurable ℓ - inferInstanceAs (MeasurableSpace (Σ n : ℕ, Fin n → OrderedObservation ℓ)) - -instance orderedObservationSingleton : (ℓ : ℕ) → MeasurableSingletonClass (OrderedObservation ℓ) - | 0 => inferInstanceAs (MeasurableSingletonClass Spin) - | ℓ+1 => letI := orderedObservationSingleton ℓ - inferInstanceAs (MeasurableSingletonClass (Σ n : ℕ, Fin n → OrderedObservation ℓ)) - -def orderedLaw (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) : - (ℓ : ℕ) → Spin → PMF (OrderedObservation ℓ) - | 0, i => PMF.pure i - | ℓ+1, i => sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ - (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ))) - -def forgetOrdered : (ℓ : ℕ) → OrderedObservation ℓ → Observation ℓ - | 0, i => i - | ℓ+1, ⟨_,v⟩ => (List.ofFn (fun j ↦ forgetOrdered ℓ (v j)) : Multiset (Observation ℓ)) - -lemma orderedLaw_forget (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : - (orderedLaw ρ lam hlam ℓ i).map (forgetOrdered ℓ) = observationLaw lam hlam ρ ℓ i := by - induction ℓ generalizing i with - | zero => exact PMF.map_id _ - | succ ℓ ih => - rw [orderedLaw, sigmaPMF_map] - change ρ.bind _ = ρ.bind _ - congr 1 - funext n - change (productPMF (fun _ : Fin n ↦ (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ))).map - ((fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))) ∘ - List.ofFn ∘ (fun v j ↦ forgetOrdered ℓ (v j))) = _ - rw [← PMF.map_comp, ← PMF.map_comp, productPMF_map] - simp_rw [PMF.map_bind, ih] - rw [productPMF_list] - exact (PMF.map_id ((iidList ((channel lam hlam i).bind - (observationLaw lam hlam ρ ℓ)) n).map (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))))).symm - -def orderedExpansion (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) : - (ℓ : ℕ) → OrderedObservation ℓ → PMF (OrderedObservation (ℓ+1)) - | 0, i => sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ channel lam hlam i)) - | ℓ+1, ⟨n,v⟩ => (productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (v j))).map (Sigma.mk n) - -lemma orderedLaw_degrades (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : - (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ) = - orderedLaw ρ lam hlam (ℓ+1) i := by - induction ℓ generalizing i with - | zero => - change (PMF.pure i).bind _ = sigmaPMF ρ (fun n ↦ - productPMF (fun _ : Fin n ↦ (channel lam hlam i).bind PMF.pure)) - rw [PMF.pure_bind] - simp only [PMF.bind_pure] - rfl - | succ ℓ ih => - change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ - (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).bind - (fun z ↦ (productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (z.2 j))).map (Sigma.mk (β := fun n ↦ Fin n → OrderedObservation (ℓ+1)) z.1)) = _ - rw [sigmaPMF_bind_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) ↦ - productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (v j)))] - simp only [productPMF_bind, PMF.bind_bind] - simp_rw [ih] - rfl - -def offspringPosteriorLaw (ρ : PMF ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : ℕ → Law - | 0 => rootLaw - | ℓ+1 => offspringLaw ρ (offspringPosteriorLaw ρ hl₀ hl₁ ℓ) hl₀ hl₁ - -lemma offspringPosteriorLaw_probability (ρ : PMF ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (ℓ : ℕ) : - (offspringPosteriorLaw ρ hl₀ hl₁ ℓ).probability = discreteProbability (orderedLaw ρ lam hlam ℓ) := by - induction ℓ with - | zero => rfl - | succ ℓ ih => - change mixtureProbability ρ (fun n ↦ finiteProbability (offspringPosteriorLaw ρ hl₀ hl₁ ℓ) hl₀ hl₁ n) = - discreteProbability (fun i ↦ sigmaPMF ρ (fun n ↦ discreteBranchLaw (orderedLaw ρ lam hlam ℓ) lam hlam n i)) - rw [discreteSigma_probability] - congr 1 - funext n - exact (discreteBranchLaw_probability _ _ ih hl₀ hl₁ hlam n).symm - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment - -lemma sigmaPMF_map_components {α β : ℕ → Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) - (f : ∀ n, α n → β n) : - (sigmaPMF ρ p).map (fun z ↦ ⟨z.1,f z.1 z.2⟩) = sigmaPMF ρ (fun n ↦ (p n).map (f n)) := by - rw [sigmaPMF_map, sigmaPMF_eq_bind] - congr 1 - funext n - rw [PMF.map_comp] - rfl - -def relabelOrdered (σ : Equiv.Perm Spin) : (ℓ : ℕ) → OrderedObservation ℓ → OrderedObservation ℓ - | 0, i => σ i - | ℓ+1, ⟨n,v⟩ => ⟨n,fun j ↦ relabelOrdered σ ℓ (v j)⟩ - -lemma orderedLaw_permute (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (σ : Equiv.Perm Spin) - (ℓ : ℕ) (i : Spin) : - (orderedLaw ρ lam hlam ℓ i).map (relabelOrdered σ ℓ) = orderedLaw ρ lam hlam ℓ (σ i) := by - induction ℓ generalizing i with - | zero => exact PMF.pure_bind _ _ - | succ ℓ ih => - change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ - (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).map - (fun z ↦ Sigma.mk (β := fun n ↦ Fin n → OrderedObservation ℓ) z.1 - (fun j ↦ relabelOrdered σ ℓ (z.2 j))) = _ - rw [sigmaPMF_map_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) j ↦ relabelOrdered σ ℓ (v j))] - simp_rw [productPMF_map, PMF.map_bind, ih] - have he : (channel lam hlam i).bind (fun j ↦ orderedLaw ρ lam hlam ℓ (σ j)) = - (channel lam hlam (σ i)).bind (orderedLaw ρ lam hlam ℓ) := by - rw [← channel_permute hlam σ i, PMF.bind_map] - rfl - simp_rw [he] - rfl - -def orderedNoise (c : ℝ) (hc : Admissible c) : - (ℓ : ℕ) → OrderedObservation ℓ → PMF (OrderedObservation ℓ) - | 0, i => PMF.pure i - | ℓ+1, ⟨n,v⟩ => (productPMF (fun j ↦ - (channel c hc 0).bind (fun s ↦ (orderedNoise c hc ℓ (v j)).map - (relabelOrdered (Equiv.addRight s) ℓ)))).map (Sigma.mk n) - -lemma orderedLaw_noise (ρ : PMF ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) - (hprod : Admissible (lam*c)) (ℓ : ℕ) (i : Spin) : - (orderedLaw ρ lam hlam ℓ i).bind (orderedNoise c hc ℓ) = orderedLaw ρ (lam*c) hprod ℓ i := by - induction ℓ generalizing i with - | zero => exact PMF.pure_bind _ _ - | succ ℓ ih => - change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ - (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).bind - (fun z ↦ (productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ - (orderedNoise c hc ℓ (z.2 j)).map (relabelOrdered (Equiv.addRight s) ℓ)) )).map (Sigma.mk (β := fun n ↦ Fin n → OrderedObservation ℓ) z.1)) = _ - rw [sigmaPMF_bind_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) ↦ - productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ - (orderedNoise c hc ℓ (v j)).map (relabelOrdered (Equiv.addRight s) ℓ))))] - change sigmaPMF ρ _ = sigmaPMF ρ _ - congr 1 - funext n - rw [productPMF_bind (fun _ : Fin n ↦ (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)) - (fun _ a ↦ (channel c hc 0).bind (fun s ↦ - (orderedNoise c hc ℓ a).map (relabelOrdered (Equiv.addRight s) ℓ)))] - congr 1 - funext j - rw [PMF.bind_bind] - have he (k : Spin) : (orderedLaw ρ lam hlam ℓ k).bind (fun a ↦ (channel c hc 0).bind - (fun s ↦ (orderedNoise c hc ℓ a).map (relabelOrdered (Equiv.addRight s) ℓ))) = - (channel c hc k).bind (orderedLaw ρ (lam*c) hprod ℓ) := by - rw [PMF.bind_comm] - simp_rw [← PMF.map_bind, ih, orderedLaw_permute] - change (channel c hc 0).bind (fun s ↦ orderedLaw ρ (lam*c) hprod ℓ (k+s)) = _ - have hm := channel_permute hc (Equiv.addLeft k) 0 - simp only [Equiv.coe_addLeft, add_zero] at hm - rw [← hm, PMF.bind_map] - rfl - simp_rw [he, ← PMF.bind_bind, channel_compose hlam hc hprod] - -lemma ordered_channel_mu_le (ρ : PMF ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) - (hprod : Admissible (lam*c)) (ℓ : ℕ) : - (∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ (lam*c) hprod ℓ)).toMeasure) ≤ - ∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ lam hlam ℓ)).toMeasure := by - have h := discrete_degradation_mu (orderedLaw ρ lam hlam ℓ) (orderedNoise c hc ℓ) - change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ - (orderedLaw ρ lam hlam ℓ i).bind (orderedNoise c hc ℓ))).toMeasure) ≤ _ at h - simpa only [orderedLaw_noise ρ lam c hlam hc hprod] using h - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped Topology -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma degrading_offspring_fixed_point (Q : ℕ → Law) (C : ℕ → ProbabilityMeasure (Message × Message)) - (hfst : ∀ ℓ, (C ℓ).map Prod.fst = (Q ℓ).probability) - (hsnd : ∀ ℓ, (C ℓ).map Prod.snd = (Q (ℓ+1)).probability) - (hloss : ∀ ℓ, (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu) - {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (ρ : PMF ℕ) - (hrec : ∀ ℓ, (Q (ℓ+1)).probability = (offspringLaw ρ (Q ℓ) hl₀ hl₁).probability) : - ∃ R : Law, R.probability = (offspringLaw ρ R hl₀ hl₁).probability ∧ - Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 R.mu) := by - have hanti : Antitone (fun ℓ ↦ (Q ℓ).mu) := by - apply antitone_nat_of_succ_le - intro ℓ - have h := MeasureTheory.integral_nonneg (μ := (C ℓ).toMeasure) (f := quadraticGap) quadraticGap_nonneg - rw [hloss] at h - linarith - let a := ⨅ ℓ, (Q ℓ).mu - have hlim : Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 a) := - tendsto_atTop_ciInf hanti ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact (Q ℓ).mu_nonneg⟩ - have hdiff : Tendsto (fun ℓ ↦ (Q ℓ).mu-(Q (ℓ+1)).mu) atTop (𝓝 0) := by - simpa using hlim.sub (hlim.comp (tendsto_add_atTop_nat 1)) - obtain ⟨D, hD⟩ := exists_clusterPt_of_compactSpace (Filter.map C atTop) - let F : Filter ℕ := Filter.comap C (𝓝 D) ⊓ atTop - have : F.NeBot := neBot_inf_comap_iff_map'.mpr hD - have hF : F ≤ atTop := inf_le_right - have hC : Tendsto C F (𝓝 D) := tendsto_comap.mono_left inf_le_left - have hgap : (∫ z, quadraticGap z ∂D.toMeasure) = 0 := by - have hg := (probability_continuous_integral continuous_quadraticGap).tendsto D |>.comp hC - simp only [Function.comp_def, hloss] at hg - exact tendsto_nhds_unique hg (hdiff.mono_left hF) - have hdiag := coupling_diagonal_of_loss_zero D hgap - have hP := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (Prod.fst : Message × Message → Message))).tendsto D |>.comp hC - simp only [Function.comp_def, hfst] at hP - let R : Law := limitLaw hP - have hS := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (Prod.snd : Message × Message → Message))).tendsto D |>.comp hC - simp only [Function.comp_def, hsnd] at hS - rw [← hdiag] at hS - have hR : R.probability = (offspringLaw ρ R hl₀ hl₁).probability := by - have hr := offspringLaw_tendsto (R := R) ρ hl₀ hl₁ hP - simp only [← hrec] at hr - exact tendsto_nhds_unique hS hr - have hm : a = R.mu := by - have hp := (probability_continuous_integral continuous_xMoment).tendsto R.probability |>.comp hP - exact tendsto_nhds_unique (hlim.mono_left hF) hp - exact ⟨R, hR, hm ▸ hlim⟩ - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RegularCritical +import OAI.Probability.ThreeStateClauses.ObservedMixtures + +namespace OAI + +/-! Offspring Laws. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +@[reducible] def OrderedObservation : ℕ → Type + | 0 => Spin + | ℓ+1 => Σ n : ℕ, Fin n → OrderedObservation ℓ + +instance orderedObservationCountable : (ℓ : ℕ) → Countable (OrderedObservation ℓ) + | 0 => inferInstanceAs (Countable Spin) + | ℓ+1 => letI := orderedObservationCountable ℓ + inferInstanceAs (Countable (Σ n : ℕ, Fin n → OrderedObservation ℓ)) + +instance orderedObservationMeasurable : (ℓ : ℕ) → MeasurableSpace (OrderedObservation ℓ) + | 0 => inferInstanceAs (MeasurableSpace Spin) + | ℓ+1 => letI := orderedObservationMeasurable ℓ + inferInstanceAs (MeasurableSpace (Σ n : ℕ, Fin n → OrderedObservation ℓ)) + +instance orderedObservationSingleton : (ℓ : ℕ) → MeasurableSingletonClass (OrderedObservation ℓ) + | 0 => inferInstanceAs (MeasurableSingletonClass Spin) + | ℓ+1 => letI := orderedObservationSingleton ℓ + inferInstanceAs (MeasurableSingletonClass (Σ n : ℕ, Fin n → OrderedObservation ℓ)) + +def orderedLaw (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) : + (ℓ : ℕ) → Spin → PMF (OrderedObservation ℓ) + | 0, i => PMF.pure i + | ℓ+1, i => sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ + (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ))) + +def forgetOrdered : (ℓ : ℕ) → OrderedObservation ℓ → Observation ℓ + | 0, i => i + | ℓ+1, ⟨_,v⟩ => (List.ofFn (fun j ↦ forgetOrdered ℓ (v j)) : Multiset (Observation ℓ)) + +lemma orderedLaw_forget (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : + (orderedLaw ρ lam hlam ℓ i).map (forgetOrdered ℓ) = observationLaw lam hlam ρ ℓ i := by + induction ℓ generalizing i with + | zero => exact PMF.map_id _ + | succ ℓ ih => + rw [orderedLaw, sigmaPMF_map] + change ρ.bind _ = ρ.bind _ + congr 1 + funext n + change (productPMF (fun _ : Fin n ↦ (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ))).map + ((fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))) ∘ + List.ofFn ∘ (fun v j ↦ forgetOrdered ℓ (v j))) = _ + rw [← PMF.map_comp, ← PMF.map_comp, productPMF_map] + simp_rw [PMF.map_bind, ih] + rw [productPMF_list] + exact (PMF.map_id ((iidList ((channel lam hlam i).bind + (observationLaw lam hlam ρ ℓ)) n).map (fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))))).symm + +def orderedExpansion (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) : + (ℓ : ℕ) → OrderedObservation ℓ → PMF (OrderedObservation (ℓ+1)) + | 0, i => sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ channel lam hlam i)) + | ℓ+1, ⟨n,v⟩ => (productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (v j))).map (Sigma.mk n) + +lemma orderedLaw_degrades (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : + (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ) = + orderedLaw ρ lam hlam (ℓ+1) i := by + induction ℓ generalizing i with + | zero => + change (PMF.pure i).bind _ = sigmaPMF ρ (fun n ↦ + productPMF (fun _ : Fin n ↦ (channel lam hlam i).bind PMF.pure)) + rw [PMF.pure_bind] + simp only [PMF.bind_pure] + rfl + | succ ℓ ih => + change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ + (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).bind + (fun z ↦ (productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (z.2 j))).map (Sigma.mk (β := fun n ↦ Fin n → OrderedObservation (ℓ+1)) z.1)) = _ + rw [sigmaPMF_bind_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) ↦ + productPMF (fun j ↦ orderedExpansion ρ lam hlam ℓ (v j)))] + simp only [productPMF_bind, PMF.bind_bind] + simp_rw [ih] + rfl + +def offspringPosteriorLaw (ρ : PMF ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : ℕ → Law + | 0 => rootLaw + | ℓ+1 => offspringLaw ρ (offspringPosteriorLaw ρ hl₀ hl₁ ℓ) hl₀ hl₁ + +lemma offspringPosteriorLaw_probability (ρ : PMF ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (ℓ : ℕ) : + (offspringPosteriorLaw ρ hl₀ hl₁ ℓ).probability = discreteProbability (orderedLaw ρ lam hlam ℓ) := by + induction ℓ with + | zero => rfl + | succ ℓ ih => + change mixtureProbability ρ (fun n ↦ finiteProbability (offspringPosteriorLaw ρ hl₀ hl₁ ℓ) hl₀ hl₁ n) = + discreteProbability (fun i ↦ sigmaPMF ρ (fun n ↦ discreteBranchLaw (orderedLaw ρ lam hlam ℓ) lam hlam n i)) + rw [discreteSigma_probability] + congr 1 + funext n + exact (discreteBranchLaw_probability _ _ ih hl₀ hl₁ hlam n).symm + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment + +lemma sigmaPMF_map_components {α β : ℕ → Type*} (ρ : PMF ℕ) (p : ∀ n, PMF (α n)) + (f : ∀ n, α n → β n) : + (sigmaPMF ρ p).map (fun z ↦ ⟨z.1,f z.1 z.2⟩) = sigmaPMF ρ (fun n ↦ (p n).map (f n)) := by + rw [sigmaPMF_map, sigmaPMF_eq_bind] + congr 1 + funext n + rw [PMF.map_comp] + rfl + +def relabelOrdered (σ : Equiv.Perm Spin) : (ℓ : ℕ) → OrderedObservation ℓ → OrderedObservation ℓ + | 0, i => σ i + | ℓ+1, ⟨n,v⟩ => ⟨n,fun j ↦ relabelOrdered σ ℓ (v j)⟩ + +lemma orderedLaw_permute (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (σ : Equiv.Perm Spin) + (ℓ : ℕ) (i : Spin) : + (orderedLaw ρ lam hlam ℓ i).map (relabelOrdered σ ℓ) = orderedLaw ρ lam hlam ℓ (σ i) := by + induction ℓ generalizing i with + | zero => exact PMF.pure_bind _ _ + | succ ℓ ih => + change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ + (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).map + (fun z ↦ Sigma.mk (β := fun n ↦ Fin n → OrderedObservation ℓ) z.1 + (fun j ↦ relabelOrdered σ ℓ (z.2 j))) = _ + rw [sigmaPMF_map_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) j ↦ relabelOrdered σ ℓ (v j))] + simp_rw [productPMF_map, PMF.map_bind, ih] + have he : (channel lam hlam i).bind (fun j ↦ orderedLaw ρ lam hlam ℓ (σ j)) = + (channel lam hlam (σ i)).bind (orderedLaw ρ lam hlam ℓ) := by + rw [← channel_permute hlam σ i, PMF.bind_map] + rfl + simp_rw [he] + rfl + +def orderedNoise (c : ℝ) (hc : Admissible c) : + (ℓ : ℕ) → OrderedObservation ℓ → PMF (OrderedObservation ℓ) + | 0, i => PMF.pure i + | ℓ+1, ⟨n,v⟩ => (productPMF (fun j ↦ + (channel c hc 0).bind (fun s ↦ (orderedNoise c hc ℓ (v j)).map + (relabelOrdered (Equiv.addRight s) ℓ)))).map (Sigma.mk n) + +lemma orderedLaw_noise (ρ : PMF ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) + (hprod : Admissible (lam*c)) (ℓ : ℕ) (i : Spin) : + (orderedLaw ρ lam hlam ℓ i).bind (orderedNoise c hc ℓ) = orderedLaw ρ (lam*c) hprod ℓ i := by + induction ℓ generalizing i with + | zero => exact PMF.pure_bind _ _ + | succ ℓ ih => + change (sigmaPMF ρ (fun n ↦ productPMF (fun _ : Fin n ↦ + (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)))).bind + (fun z ↦ (productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ + (orderedNoise c hc ℓ (z.2 j)).map (relabelOrdered (Equiv.addRight s) ℓ)) )).map (Sigma.mk (β := fun n ↦ Fin n → OrderedObservation ℓ) z.1)) = _ + rw [sigmaPMF_bind_components ρ _ (fun n (v : Fin n → OrderedObservation ℓ) ↦ + productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ + (orderedNoise c hc ℓ (v j)).map (relabelOrdered (Equiv.addRight s) ℓ))))] + change sigmaPMF ρ _ = sigmaPMF ρ _ + congr 1 + funext n + rw [productPMF_bind (fun _ : Fin n ↦ (channel lam hlam i).bind (orderedLaw ρ lam hlam ℓ)) + (fun _ a ↦ (channel c hc 0).bind (fun s ↦ + (orderedNoise c hc ℓ a).map (relabelOrdered (Equiv.addRight s) ℓ)))] + congr 1 + funext j + rw [PMF.bind_bind] + have he (k : Spin) : (orderedLaw ρ lam hlam ℓ k).bind (fun a ↦ (channel c hc 0).bind + (fun s ↦ (orderedNoise c hc ℓ a).map (relabelOrdered (Equiv.addRight s) ℓ))) = + (channel c hc k).bind (orderedLaw ρ (lam*c) hprod ℓ) := by + rw [PMF.bind_comm] + simp_rw [← PMF.map_bind, ih, orderedLaw_permute] + change (channel c hc 0).bind (fun s ↦ orderedLaw ρ (lam*c) hprod ℓ (k+s)) = _ + have hm := channel_permute hc (Equiv.addLeft k) 0 + simp only [Equiv.coe_addLeft, add_zero] at hm + rw [← hm, PMF.bind_map] + rfl + simp_rw [he, ← PMF.bind_bind, channel_compose hlam hc hprod] + +lemma ordered_channel_mu_le (ρ : PMF ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) + (hprod : Admissible (lam*c)) (ℓ : ℕ) : + (∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ (lam*c) hprod ℓ)).toMeasure) ≤ + ∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ lam hlam ℓ)).toMeasure := by + have h := discrete_degradation_mu (orderedLaw ρ lam hlam ℓ) (orderedNoise c hc ℓ) + change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ + (orderedLaw ρ lam hlam ℓ i).bind (orderedNoise c hc ℓ))).toMeasure) ≤ _ at h + simpa only [orderedLaw_noise ρ lam c hlam hc hprod] using h + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped Topology +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma degrading_offspring_fixed_point (Q : ℕ → Law) (C : ℕ → ProbabilityMeasure (Message × Message)) + (hfst : ∀ ℓ, (C ℓ).map Prod.fst = (Q ℓ).probability) + (hsnd : ∀ ℓ, (C ℓ).map Prod.snd = (Q (ℓ+1)).probability) + (hloss : ∀ ℓ, (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu) + {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (ρ : PMF ℕ) + (hrec : ∀ ℓ, (Q (ℓ+1)).probability = (offspringLaw ρ (Q ℓ) hl₀ hl₁).probability) : + ∃ R : Law, R.probability = (offspringLaw ρ R hl₀ hl₁).probability ∧ + Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 R.mu) := by + have hanti : Antitone (fun ℓ ↦ (Q ℓ).mu) := by + apply antitone_nat_of_succ_le + intro ℓ + have h := MeasureTheory.integral_nonneg (μ := (C ℓ).toMeasure) (f := quadraticGap) quadraticGap_nonneg + rw [hloss] at h + linarith + let a := ⨅ ℓ, (Q ℓ).mu + have hlim : Tendsto (fun ℓ ↦ (Q ℓ).mu) atTop (𝓝 a) := + tendsto_atTop_ciInf hanti ⟨0, by rintro _ ⟨ℓ,rfl⟩; exact (Q ℓ).mu_nonneg⟩ + have hdiff : Tendsto (fun ℓ ↦ (Q ℓ).mu-(Q (ℓ+1)).mu) atTop (𝓝 0) := by + simpa using hlim.sub (hlim.comp (tendsto_add_atTop_nat 1)) + obtain ⟨D, hD⟩ := exists_clusterPt_of_compactSpace (Filter.map C atTop) + let F : Filter ℕ := Filter.comap C (𝓝 D) ⊓ atTop + have : F.NeBot := neBot_inf_comap_iff_map'.mpr hD + have hF : F ≤ atTop := inf_le_right + have hC : Tendsto C F (𝓝 D) := tendsto_comap.mono_left inf_le_left + have hgap : (∫ z, quadraticGap z ∂D.toMeasure) = 0 := by + have hg := (probability_continuous_integral continuous_quadraticGap).tendsto D |>.comp hC + simp only [Function.comp_def, hloss] at hg + exact tendsto_nhds_unique hg (hdiff.mono_left hF) + have hdiag := coupling_diagonal_of_loss_zero D hgap + have hP := (ProbabilityMeasure.continuous_map (continuous_fst : Continuous (Prod.fst : Message × Message → Message))).tendsto D |>.comp hC + simp only [Function.comp_def, hfst] at hP + let R : Law := limitLaw hP + have hS := (ProbabilityMeasure.continuous_map (continuous_snd : Continuous (Prod.snd : Message × Message → Message))).tendsto D |>.comp hC + simp only [Function.comp_def, hsnd] at hS + rw [← hdiag] at hS + have hR : R.probability = (offspringLaw ρ R hl₀ hl₁).probability := by + have hr := offspringLaw_tendsto (R := R) ρ hl₀ hl₁ hP + simp only [← hrec] at hr + exact tendsto_nhds_unique hS hr + have hm : a = R.mu := by + have hp := (probability_continuous_integral continuous_xMoment).tendsto R.probability |>.comp hP + exact tendsto_nhds_unique (hlim.mono_left hF) hp + exact ⟨R, hR, hm ▸ hlim⟩ + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PoissonCalculus.lean b/lean/OAI/Probability/ThreeStateClauses/PoissonCalculus.lean index 854395fa48a97e9004080a2df317bcf92ce0277e..69f261b2374e3711f75c20c68658ec22bf42eea6 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PoissonCalculus.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PoissonCalculus.lean @@ -1,545 +1,545 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.PositiveFixed -import OAI.Probability.ThreeStateClauses.PoissonLaw - -namespace OAI - -/-! Poisson Calculus. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set Filter MeasureTheory ProbabilityTheory -open scoped BigOperators NNReal -namespace ThreeState.TreeClauses.Probability - -def exponentialAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := ∑' n, t^n/(n.factorial:ℝ)*f n - -def poissonAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := Real.exp (-t)*exponentialAverage f t - -lemma exponentialAverage_summable {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - Summable (fun n ↦ t^n/(n.factorial:ℝ)*f n) := by - apply Summable.of_norm_bounded ((Real.summable_pow_div_factorial |t|).mul_right B) - intro n - rw [Real.norm_eq_abs, abs_mul, abs_div, abs_pow, Nat.abs_cast] - exact mul_le_mul_of_nonneg_left (hB n) (by positivity) - -private def exponentialDerivative (f : ℕ → ℝ) : ℕ → ℝ → ℝ - | 0, _ => 0 - | n+1, t => t^n/(n.factorial:ℝ)*f (n+1) - -private lemma exponentialDerivative_summable {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - Summable (fun n ↦ exponentialDerivative f n t) := by - apply (summable_nat_add_iff 1).mp - exact exponentialAverage_summable (fun n ↦ hB (n+1)) t - -private lemma exponentialDerivative_sum {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - (∑' n, exponentialDerivative f n t) = exponentialAverage (fun n ↦ f (n+1)) t := by - rw [← (exponentialDerivative_summable hB t).sum_add_tsum_nat_add 1] - simp [exponentialDerivative, exponentialAverage] - -lemma hasDerivAt_exponentialAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - HasDerivAt (exponentialAverage f) (exponentialAverage (fun n ↦ f (n+1)) t) t := by - let R := |t|+1 - have hR : 0 < R := by dsimp [R]; positivity - have ht : t ∈ Ioo (-R) R := by - constructor <;> dsimp [R] <;> linarith [le_abs_self t, neg_abs_le t] - let u : ℕ → ℝ := fun n ↦ exponentialDerivative (fun _ ↦ B) n R - have hu : Summable u := exponentialDerivative_summable (B := |B|) (fun _ ↦ le_refl _) R - have hd (n : ℕ) (y : ℝ) : HasDerivAt (fun z : ℝ ↦ z^n/(n.factorial:ℝ)*f n) - (exponentialDerivative f n y) y := by - cases n with - | zero => simpa [exponentialDerivative] using hasDerivAt_const y (f 0) - | succ n => - convert (((hasDerivAt_id y).pow (n+1)).div_const ((n+1).factorial:ℝ)).mul_const (f (n+1)) using 1 - all_goals try rfl - all_goals try simp only [exponentialDerivative, id_eq] - rw [Nat.factorial_succ, Nat.cast_mul] - simp only [Nat.add_sub_cancel, mul_one] - have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity - field_simp - have hb (n : ℕ) (y : ℝ) (hy : y ∈ Ioo (-R) R) : ‖exponentialDerivative f n y‖ ≤ u n := by - have hyR : |y| ≤ R := (abs_le).2 ⟨le_of_lt hy.1, le_of_lt hy.2⟩ - cases n with - | zero => simp [exponentialDerivative, u] - | succ n => - dsimp [exponentialDerivative, u] - rw [abs_mul, abs_div, abs_pow, Nat.abs_cast] - exact mul_le_mul (div_le_div_of_nonneg_right (pow_le_pow_left₀ (abs_nonneg y) hyR n) (by positivity)) - (hB (n+1)) (abs_nonneg _) (by positivity) - have hh := hasDerivAt_tsum_of_isPreconnected hu isOpen_Ioo (convex_Ioo (-R) R).isPreconnected - (fun n y _ ↦ hd n y) hb ht (exponentialAverage_summable hB t) ht - rw [exponentialDerivative_sum hB t] at hh - exact hh - -theorem hasDerivAt_poissonAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - HasDerivAt (poissonAverage f) - (poissonAverage (fun n ↦ f (n+1)) t-poissonAverage f t) t := by - have hd := ((hasDerivAt_neg t).exp).mul (hasDerivAt_exponentialAverage hB t) - exact hd.congr_deriv (by unfold poissonAverage; ring) - -lemma poissonAverage_eq_tsum {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : - poissonAverage f t = ∑' n, poissonWeight t n*f n := by - rw [poissonAverage, exponentialAverage, ← (exponentialAverage_summable hB t).tsum_mul_left] - apply tsum_congr; intro n; unfold poissonWeight; ring - -lemma poissonAverage_eq_integral {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ≥0) : - poissonAverage f t = ∫ n, f n ∂(poissonPMF t).toMeasure := by - rw [PMF.integral_eq_tsum] - · simp only [poissonPMF_real, smul_eq_mul] - exact poissonAverage_eq_tsum hB t - · exact Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable B - (Eventually.of_forall (fun n ↦ by simpa only [Real.norm_eq_abs] using hB n)) - -lemma continuous_poissonAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) : - Continuous (poissonAverage f) := continuous_iff_continuousAt.mpr - (fun t ↦ (hasDerivAt_poissonAverage hB t).continuousAt) - -lemma poissonAverage_zero (f : ℕ → ℝ) : poissonAverage f 0 = f 0 := by - rw [poissonAverage, neg_zero, Real.exp_zero, one_mul, exponentialAverage, tsum_eq_single 0] - · simp - · intro n hn - simp [zero_pow hn] - -end ThreeState.TreeClauses.Probability - -end - -noncomputable section -open Set MeasureTheory ProbabilityTheory -open scoped NNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability - -lemma offspring_positive (ρ : PMF ℕ) (Q : Law) {lam : ℝ} - (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - ∀ᵐ m ∂(offspringLaw ρ Q hl₀ hl₁).probability.toMeasure, PositiveMessage m.1 := by - apply Measure.ae_sum_iff.mpr - intro n - exact Measure.ae_smul_measure (finite_positive Q hl₀ hl₁ n) _ - -lemma correction_nonneg (m : Message) : 0 ≤ correction m.1 := by - unfold correction - apply div_nonneg _ (by norm_num) - have h := avg_mono (fun i ↦ mul_nonneg (coordinate_nonneg m i) (sq_nonneg (logCentered m.1 i))) - simpa only [avg_const] using h - -private lemma poisson_mixture_integrable_nonneg (t : ℝ≥0) (P : ℕ → ProbabilityMeasure Message) - {f : Message → ℝ} (hi : ∀ n, Integrable f (P n).toMeasure) - (hp : ∀ n, ∀ᵐ m ∂(P n).toMeasure, 0 ≤ f m) - (hs : Summable (fun n ↦ poissonWeight t n*(∫ m, f m ∂(P n).toMeasure))) : - Integrable f (mixtureProbability (poissonPMF t) P).toMeasure := by - apply mixture_integrable _ P hi - simp only [poissonPMF_real] - apply hs.congr - intro n - congr 1 - exact integral_congr_ae ((hp n).mono (fun m hm ↦ (abs_of_nonneg hm).symm)) - -lemma poisson_integrable_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (t : ℝ≥0) : Integrable (fun m : Message ↦ symEntropy m.1) (poissonLaw Q hl₀ hl₁ t).probability.toMeasure := by - apply poisson_mixture_integrable_nonneg t (fun n ↦ finiteProbability Q hl₀ hl₁ n) - (finite_integrable_symEntropy Q hl₀ hl₁) - (fun n ↦ (finite_positive Q hl₀ hl₁ n).mono (fun m hm ↦ symEntropy_nonneg hm)) - have he (n : ℕ) : (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = - (n:ℝ)*edgeJMean Q lam := finiteLaw_symEntropy Q hl₀ hl₁ n - simp_rw [he, ← mul_assoc] - exact (poissonWeight_mean t).summable.mul_right _ - -lemma poisson_integrable_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (t : ℝ≥0) : Integrable (fun m : Message ↦ correction m.1) (poissonLaw Q hl₀ hl₁ t).probability.toMeasure := by - apply poisson_mixture_integrable_nonneg t (fun n ↦ finiteProbability Q hl₀ hl₁ n) - (finite_integrable_correction Q hl₀ hl₁) - (fun _ ↦ Filter.Eventually.of_forall correction_nonneg) - have h := ((poissonWeight_mean t).summable.mul_right - (∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)).add - ((poissonWeight_factorial_second t).summable.mul_right (2*(edgeJMean Q lam)^2)) - apply h.congr - intro n - have he := finiteLaw_correction Q hl₀ hl₁ n - change (∫ m, correction m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at he - rw [he] - unfold edgeJMean - ring - -lemma poissonLaw_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (t : ℝ≥0) : - (∫ m, symEntropy m.1 ∂(poissonLaw Q hl₀ hl₁ t).probability.toMeasure) = (t:ℝ)*edgeJMean Q lam := by - rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) - (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, - integral_mixtureProbability _ _ (poisson_integrable_symEntropy Q hl₀ hl₁ t)] - simp only [poissonPMF_real, finiteLaw_symEntropy] - exact ((poissonWeight_mean t).mul_right (edgeJMean Q lam)).tsum_eq |> fun h ↦ by - simpa only [mul_assoc, edgeJMean] using h - -lemma poissonLaw_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (t : ℝ≥0) : - (∫ m, correction m.1 ∂(poissonLaw Q hl₀ hl₁ t).probability.toMeasure) = - (t:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - 2*(t:ℝ)^2*(edgeJMean Q lam)^2 := by - rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) - (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, - integral_mixtureProbability _ _ (poisson_integrable_correction Q hl₀ hl₁ t)] - simp only [poissonPMF_real, finiteLaw_correction] - have h := ((poissonWeight_mean t).mul_right - (∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)).add - ((poissonWeight_factorial_second t).mul_right (2*(edgeJMean Q lam)^2)) - convert h.tsum_eq using 1 - · apply tsum_congr; intro n; unfold edgeJMean; ring - · ring - -def iMean (Q : Law) : ℝ := ∫ m, info m.1 ∂Q.probability.toMeasure - -def edgeIMean (Q : Law) (lam : ℝ) : ℝ := ∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure - -lemma bounded_iMean : ∃ B : ℝ, ∀ Q : Law, |iMean Q| ≤ B := by - have hc : Continuous (fun m : Message ↦ info m.1) := continuous_info_comp continuous_subtype_val - obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hc.continuousOn - refine ⟨B, fun Q ↦ ?_⟩ - apply (abs_integral_le_integral_abs).trans - exact (integral_mono (compact_integrable (continuous_info_comp continuous_subtype_val).abs) - (integrable_const B) (fun m ↦ by simpa only [Real.norm_eq_abs] using hB m (mem_univ m))).trans_eq (by simp) - -def poissonCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : ℝ := - t*edgeIMean Q lam-poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t - -lemma poissonLaw_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : - iMean (poissonLaw Q hl₀ hl₁ t) = (t:ℝ)*edgeIMean Q lam-poissonCorrelation Q hl₀ hl₁ t := by - obtain ⟨B,hB⟩ := bounded_iMean - have he : iMean (poissonLaw Q hl₀ hl₁ t) = poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t := by - unfold iMean - rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) - (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, - integral_mixtureProbability _ _ (compact_integrable (continuous_info_comp continuous_subtype_val))] - change _ = poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t - rw [poissonAverage_eq_tsum (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))] - simp only [poissonPMF_real, iMean] - rw [he, poissonCorrelation] - ring - -lemma poissonCorrelation_continuous (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Continuous (poissonCorrelation Q hl₀ hl₁) := by - obtain ⟨B,hB⟩ := bounded_iMean - exact (continuous_id.mul continuous_const).sub - (continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))) - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped NNReal -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -lemma poisson_fixed_edgeJ (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) - (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : - edgeJMean Q lam = lam^2*jMean Q := by - have h := poissonLaw_symEntropy Q hl₀.le hl₁ d - change (∫ m, symEntropy m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at h - rw [← hfixed] at h - change jMean Q = (d:ℝ)*edgeJMean Q lam at h - rw [h] - calc - _ = ((d:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit, one_mul] - _ = _ := by ring - -lemma functional_integral {α : Type*} [MeasurableSpace α] (μ : Measure α) (f : α → Vec) - (hI : Integrable (fun m ↦ info (f m)) μ) - (hJ : Integrable (fun m ↦ symEntropy (f m)) μ) - (hB : Integrable (fun m ↦ correction (f m)) μ) : - (∫ m, functional (f m) ∂μ) = 3*(∫ m, info (f m) ∂μ)- - 2*(∫ m, symEntropy (f m) ∂μ)+(4/5)*(∫ m, correction (f m) ∂μ) := by - unfold functional - rw [integral_add (f := fun m ↦ 3*info (f m)-2*symEntropy (f m)) - (g := fun m ↦ (4/5)*correction (f m)) ((hI.const_mul _).sub (hJ.const_mul _)) (hB.const_mul _), - integral_sub (f := fun m ↦ 3*info (f m)) (g := fun m ↦ 2*symEntropy (f m)) - (hI.const_mul _) (hJ.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] - -lemma integrated_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) - (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) - (hB : Integrable (fun m : Message ↦ correction m.1) Q.probability.toMeasure) : - (1-lam^2)/2*Q.nu ≤ (∫ m, functional m.1 ∂Q.probability.toMeasure)- - (lam^2)⁻¹*(∫ m, functional (edgeMessage lam m) ∂Q.probability.toMeasure) := by - have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := - compact_integrable (continuous_info_comp continuous_subtype_val) - have hJe := edgeJ_integrable Q hl₀.le hl₁ - have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) - have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) - (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) - have hF : Integrable (fun m : Message ↦ functional m.1) Q.probability.toMeasure := - (hI.const_mul 3 |>.sub (hJ.const_mul 2)).add (hB.const_mul (4/5)) - have hFe : Integrable (fun m : Message ↦ functional (edgeMessage lam m)) Q.probability.toMeasure := - (hIe.const_mul 3 |>.sub (hJe.const_mul 2)).add (hBe.const_mul (4/5)) - have hrad := integral_mono_ae (μ := Q.probability.toMeasure) - (f := fun m : Message ↦ (1-lam^2)/2*xMoment m^2) - (g := fun m ↦ functional m.1-(lam^2)⁻¹*functional (edgeMessage lam m)) - ((compact_integrable (continuous_xMoment.pow 2)).const_mul _) (hF.sub (hFe.const_mul _)) - (hp.mono (fun m hm ↦ radial_inequality m.1 hm lam hl₀ hl₁)) - rw [integral_const_mul, integral_sub hF (hFe.const_mul _), integral_const_mul] at hrad - exact hrad - -lemma poisson_fixed_entropy_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) - (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : - (1-lam^2)/2*Q.nu ≤ (8/5)*(jMean Q)^2-3*poissonCorrelation Q hl₀.le hl₁ d := by - have hp := offspring_positive (poissonPMF d) Q hl₀.le hl₁ - have hJ := poisson_integrable_symEntropy Q hl₀.le hl₁ d - have hB := poisson_integrable_correction Q hl₀.le hl₁ d - change ∀ᵐ m ∂(poissonLaw Q hl₀.le hl₁ d).probability.toMeasure, PositiveMessage m.1 at hp - rw [← hfixed] at hp hJ hB - have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := - compact_integrable (continuous_info_comp continuous_subtype_val) - have hJe := edgeJ_integrable Q hl₀.le hl₁ - have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) - have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) - have hrad := integrated_radial Q hl₀ hl₁ hp hJ hB - have hJid := poissonLaw_symEntropy Q hl₀.le hl₁ d - have hBid := poissonLaw_correction Q hl₀.le hl₁ d - have hIid := poissonLaw_info Q hl₀.le hl₁ d - change (∫ m, symEntropy m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hJid - change (∫ m, correction m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hBid - change (∫ m, info m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hIid - rw [← hfixed] at hJid hBid hIid - have hninv : (lam^2)⁻¹ = (d:ℝ) := by - apply mul_left_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀)) - rw [mul_inv_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀))] - nlinarith [hcrit] - have hFid := functional_integral Q.probability.toMeasure (fun m : Message ↦ m.1) hI hJ hB - have hFeid := functional_integral Q.probability.toMeasure (edgeMessage lam) hIe hJe hBe - rw [hFid, hFeid, hninv, hIid, hBid] at hrad - change jMean Q = (d:ℝ)*edgeJMean Q lam at hJid - change _ ≤ 3*((d:ℝ)*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-poissonCorrelation Q hl₀.le hl₁ d)- - 2*jMean Q+(4/5)*((d:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - 2*((d:ℝ)^2)*(edgeJMean Q lam)^2)- - (d:ℝ)*(3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ - (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)) at hrad - have he : ((d:ℝ)^2)*(edgeJMean Q lam)^2 = (jMean Q)^2 := by - rw [poisson_fixed_edgeJ Q hl₀ hl₁ d hcrit hfixed] - have hn : ((d:ℝ)^2)*lam^4 = 1 := by - nlinarith [sq_nonneg ((d:ℝ)*lam^2-1), hcrit] - calc - _ = (((d:ℝ)^2)*lam^4)*(jMean Q)^2 := by ring - _ = _ := by rw [hn]; ring - nlinarith [hJid, he] - -lemma poisson_fixed_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) - (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : - 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by - have hp := offspring_positive (poissonPMF d) Q hl₀.le hl₁ - have hJ := poisson_integrable_symEntropy Q hl₀.le hl₁ d - change ∀ᵐ m ∂(poissonLaw Q hl₀.le hl₁ d).probability.toMeasure, PositiveMessage m.1 at hp - rw [← hfixed] at hp hJ - exact expected_moment_bounds Q hl₀ hl₁ hp hJ (poisson_fixed_edgeJ Q hl₀ hl₁ d hcrit hfixed) - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory ProbabilityTheory -open scoped NNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability - -lemma finite_iMean_succ (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - iMean (finiteLaw Q hl₀ hl₁ (n+1)) = iMean (finiteLaw Q hl₀ hl₁ n)+edgeIMean Q lam- - pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam := by - unfold iMean edgeIMean - rw [finiteLaw_info, finiteLaw_info, correlationEntropy_succ Q hl₀ hl₁, Nat.cast_add, Nat.cast_one] - ring - -lemma finite_iMean_zero (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - iMean (finiteLaw Q hl₀ hl₁ 0) = 0 := by - rw [iMean, finiteLaw_info] - norm_num [correlationEntropy, normalizer, branchProduct, avg] - -lemma poissonCorrelation_zero (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - poissonCorrelation Q hl₀ hl₁ 0 = 0 := by - simp [poissonCorrelation, poissonAverage_zero, finite_iMean_zero] - -def poissonSlope (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : ℝ := - edgeIMean Q lam-(poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ (n+1))) t- - poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t) - -lemma hasDerivAt_poissonCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : - HasDerivAt (poissonCorrelation Q hl₀ hl₁) (poissonSlope Q hl₀ hl₁ t) t := by - obtain ⟨B,hB⟩ := bounded_iMean - unfold poissonCorrelation poissonSlope - convert ((hasDerivAt_id t).mul_const (edgeIMean Q lam)).sub - (hasDerivAt_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)) t) using 1 <;> first | rfl | simp only [one_mul] - -lemma continuous_poissonSlope (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Continuous (poissonSlope Q hl₀ hl₁) := by - obtain ⟨B,hB⟩ := bounded_iMean - exact continuous_const.sub - ((continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1)))).sub - (continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)))) - -lemma bounded_pairCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - ∃ B : ℝ, ∀ R : Law, |pairCorrelation R Q lam| ≤ B := by - have hc := continuous_compact_integral (μ := Q.probability.toMeasure) (continuous_pairEntropy hl₀ hl₁) - obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hc.continuousOn - refine ⟨B, fun R ↦ ?_⟩ - apply (abs_integral_le_integral_abs).trans - exact (integral_mono (compact_integrable hc.abs) (integrable_const B) - (fun r ↦ by simpa only [Real.norm_eq_abs] using hB r (mem_univ r))).trans_eq (by simp) - -lemma poissonSlope_eq_pairCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : - poissonSlope Q hl₀ hl₁ t = pairCorrelation (poissonLaw Q hl₀ hl₁ t) Q lam := by - obtain ⟨B,hB⟩ := bounded_iMean - obtain ⟨C,hC⟩ := bounded_pairCorrelation Q hl₀ hl₁ - have hi := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)) - have hi' := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1))) - have hc := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hC (finiteLaw Q hl₀ hl₁ n)) - have he : pairCorrelation (poissonLaw Q hl₀ hl₁ t) Q lam = - ∫ n, pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam ∂(poissonPMF t).toMeasure := by - change (∫ r, (∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) - ∂(mixtureProbability (poissonPMF t) (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability)).toMeasure) = _ - rw [integral_mixtureProbability _ _ (compact_integrable (continuous_compact_integral (continuous_pairEntropy hl₀ hl₁))), - PMF.integral_eq_tsum _ _ hc] - rfl - rw [he, poissonSlope, poissonAverage_eq_integral (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1))), - poissonAverage_eq_integral (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))] - have he' := integral_congr_ae (μ := (poissonPMF t).toMeasure) - (Filter.Eventually.of_forall (finite_iMean_succ Q hl₀ hl₁)) - rw [integral_sub (f := fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)+edgeIMean Q lam) - (g := fun n ↦ pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam) (hi.add (integrable_const _)) hc, - integral_add (f := fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) - (g := fun _ ↦ edgeIMean Q lam) hi (integrable_const _)] at he' - simp only [integral_const, Measure.real, measure_univ, ENNReal.toReal_one, one_smul] at he' - linarith - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped NNReal -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -lemma poisson_increment_bound (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (d t : ℝ≥0) (htd : t ≤ d) - (hfixed : Q.probability = (poissonLaw Q hl₀ hl₁ d).probability) : - 3*lam^4*Q.mu^2*(t:ℝ)/(1+(t:ℝ)*(lam^2*Q.mu))- - lam^4*Q.mu*Q.nu*Real.sqrt t ≤ 3*poissonSlope Q hl₀ hl₁ t := by - have hmu := Q.mu_nonneg - have hnuQ := Q.nu_nonneg - let L : ℝ := (t:ℝ)*(lam^2*Q.mu)/(1+(t:ℝ)*(lam^2*Q.mu)) - have ht : 0 ≤ (t:ℝ) := t.coe_nonneg - have hd : 1 ≤ 1+(t:ℝ)*(lam^2*Q.mu) := by nlinarith only [mul_nonneg ht (mul_nonneg (sq_nonneg lam) hmu)] - have hL : 0 ≤ L := by dsimp [L]; positivity - have hproj := poisson_projection Q hl₀ hl₁ t - have hnu : (poissonLaw Q hl₀ hl₁ t).nu ≤ Q.nu := by - have hh := poisson_nu_mono Q hl₀ hl₁ htd - change _ ≤ ∫ m, xMoment m^2 ∂(poissonLaw Q hl₀ hl₁ d).probability.toMeasure at hh - rwa [← hfixed] at hh - have hc := correlation_truncated Q (poissonLaw Q hl₀ hl₁ t) hl₀ hl₁ hnu hL hproj - have hLu : L ≤ (t:ℝ)*(lam^2*Q.mu) := by - dsimp only [L] - exact div_le_self (by positivity) hd - have hs : Real.sqrt L ≤ lam*Real.sqrt Q.mu*Real.sqrt t := by - have he : (lam*Real.sqrt Q.mu*Real.sqrt t)^2 = (t:ℝ)*(lam^2*Q.mu) := by - calc - _ = lam^2*(Real.sqrt Q.mu)^2*(Real.sqrt t)^2 := by ring - _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt ht]; ring - have hp : 0 ≤ lam*Real.sqrt Q.mu*Real.sqrt t := by positivity - nlinarith only [he, hp, Real.sq_sqrt hL, Real.sqrt_nonneg L, hLu] - have hmul := mul_le_mul_of_nonneg_left hs (show 0 ≤ lam^3*Real.sqrt Q.mu*Q.nu by positivity) - have heq : (lam^3*Real.sqrt Q.mu*Q.nu)*(lam*Real.sqrt Q.mu*Real.sqrt t) = - lam^4*Q.mu*Q.nu*Real.sqrt t := by - calc - _ = lam^4*(Real.sqrt Q.mu)^2*Q.nu*Real.sqrt t := by ring - _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg] - rw [heq] at hmul - have hmain : 3*lam^2*Q.mu*L = 3*lam^4*Q.mu^2*(t:ℝ)/(1+(t:ℝ)*(lam^2*Q.mu)) := by - dsimp only [L]; ring - rw [hmain, ← poissonSlope_eq_pairCorrelation] at hc - linarith only [hc, hmul] - -lemma sqrt_intensity_tangent {lam t : ℝ} (hl : 0 < lam) (ht : 0 ≤ t) : - Real.sqrt t ≤ (2*lam^2*t+1)/(2*lam*Real.sqrt 2) := by - have hs2 := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) - have hst := Real.sq_sqrt ht - have hs2p := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) - apply (le_div_iff₀ (by positivity : 0 < 2*lam*Real.sqrt 2)).2 - have he : (lam*Real.sqrt 2*Real.sqrt t)^2 = 2*lam^2*t := by - calc - _ = lam^2*(Real.sqrt 2)^2*(Real.sqrt t)^2 := by ring - _ = _ := by rw [hs2, hst]; ring - nlinarith only [sq_nonneg (lam*Real.sqrt 2*Real.sqrt t-1), he] - -theorem poisson_fixed_correlation_bound (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (d : ℝ≥0) (hcrit : (d:ℝ)*lam^2 = 1) - (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : - 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu ≤ - 3*poissonCorrelation Q hl₀.le hl₁ d := by - let q := 2*Q.mu/3 - let β := lam^2*Q.mu - let A := 3*lam^4*Q.mu^2/(1+q)^2 - let B := lam^3*Q.mu*Q.nu/(2*Real.sqrt 2) - let P : ℝ → ℝ := fun t ↦ A*((1+2*q)*t^2/2-β*t^3/3)-B*(lam^2*t^2+t) - let P' : ℝ → ℝ := fun t ↦ A*((1+2*q)*t-β*t^2)-B*(2*lam^2*t+1) - have hmu := Q.mu_nonneg - have hnu := Q.nu_nonneg - have hq : 0 ≤ q := by dsimp [q]; positivity - have hβ : 0 ≤ β := by dsimp [β]; positivity - have hA : 0 ≤ A := by dsimp [A]; positivity - have hB : 0 ≤ B := by dsimp [B]; positivity - have hsq : 0 < 1+q := by positivity - have hs2 : 0 < Real.sqrt 2 := Real.sqrt_pos.mpr (by norm_num) - have dP (t : ℝ) : HasDerivAt P (P' t) t := by - apply ((((((hasDerivAt_id t).pow 2).const_mul (1+2*q)).div_const 2 |>.sub - ((((hasDerivAt_id t).pow 3).const_mul β).div_const 3)).const_mul A).sub - (((((hasDerivAt_id t).pow 2).const_mul (lam^2)).add (hasDerivAt_id t)).const_mul B)).congr_deriv - dsimp [P']; norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one]; ring - have hbound (t : ℝ) (ht : t ∈ Icc 0 (d:ℝ)) : P' t ≤ 3*poissonSlope Q hl₀.le hl₁ t := by - let u : ℝ≥0 := ⟨t,ht.1⟩ - have hi := poisson_increment_bound Q hl₀.le hl₁ d u ht.2 hfixed - have hr := mul_le_mul_of_nonneg_left (reciprocal_tangent (mul_nonneg ht.1 hβ) hq) - (mul_nonneg hA ht.1) - have hr' : A*((1+2*q)*t-β*t^2) ≤ 3*lam^4*Q.mu^2*t/(1+t*β) := by - calc - _ = A*t*(1+2*q-t*β) := by ring - _ ≤ A*t*((1+q)^2/(1+t*β)) := hr - _ = _ := by dsimp only [A]; field_simp - have hs := mul_le_mul_of_nonneg_left (sqrt_intensity_tangent hl₀ ht.1) - (show 0 ≤ lam^4*Q.mu*Q.nu by positivity) - have hs' : lam^4*Q.mu*Q.nu*Real.sqrt t ≤ B*(2*lam^2*t+1) := by - calc - _ ≤ lam^4*Q.mu*Q.nu*((2*lam^2*t+1)/(2*lam*Real.sqrt 2)) := hs - _ = _ := by dsimp only [B]; field_simp - change 3*lam^4*Q.mu^2*t/(1+t*β)-lam^4*Q.mu*Q.nu*Real.sqrt t ≤ - 3*poissonSlope Q hl₀.le hl₁ t at hi - dsimp only [P'] - linarith only [hr', hs', hi] - have hm : MonotoneOn (fun t ↦ 3*poissonCorrelation Q hl₀.le hl₁ t-P t) (Icc 0 (d:ℝ)) := by - apply monotoneOn_Icc_of_hasDerivAt_nonneg - (fun t _ ↦ ((hasDerivAt_poissonCorrelation Q hl₀.le hl₁ t).const_mul 3).sub (dP t)) - intro t ht - exact sub_nonneg.mpr (hbound t ⟨ht.1.le,ht.2.le⟩) - have hh := hm ⟨le_rfl,d.coe_nonneg⟩ ⟨d.coe_nonneg,le_rfl⟩ d.coe_nonneg - have hz : P 0 = 0 := by dsimp [P]; ring - change 3*poissonCorrelation Q hl₀.le hl₁ 0-P 0 ≤ 3*poissonCorrelation Q hl₀.le hl₁ d-P d at hh - rw [poissonCorrelation_zero, hz] at hh - have hd : (d:ℝ) = 1/lam^2 := (eq_div_iff (ne_of_gt (sq_pos_of_pos hl₀))).2 hcrit - have hp : P d = 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu := by - dsimp only [P,A,B,β,q] - rw [hd] - field_simp - ring - rw [hp] at hh - linarith only [hh] - -end ThreeState.TreeClauses.Positive - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.PositiveFixed +import OAI.Probability.ThreeStateClauses.PoissonLaw + +namespace OAI + +/-! Poisson Calculus. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set Filter MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal +namespace ThreeState.TreeClauses.Probability + +def exponentialAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := ∑' n, t^n/(n.factorial:ℝ)*f n + +def poissonAverage (f : ℕ → ℝ) (t : ℝ) : ℝ := Real.exp (-t)*exponentialAverage f t + +lemma exponentialAverage_summable {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + Summable (fun n ↦ t^n/(n.factorial:ℝ)*f n) := by + apply Summable.of_norm_bounded ((Real.summable_pow_div_factorial |t|).mul_right B) + intro n + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_pow, Nat.abs_cast] + exact mul_le_mul_of_nonneg_left (hB n) (by positivity) + +private def exponentialDerivative (f : ℕ → ℝ) : ℕ → ℝ → ℝ + | 0, _ => 0 + | n+1, t => t^n/(n.factorial:ℝ)*f (n+1) + +private lemma exponentialDerivative_summable {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + Summable (fun n ↦ exponentialDerivative f n t) := by + apply (summable_nat_add_iff 1).mp + exact exponentialAverage_summable (fun n ↦ hB (n+1)) t + +private lemma exponentialDerivative_sum {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + (∑' n, exponentialDerivative f n t) = exponentialAverage (fun n ↦ f (n+1)) t := by + rw [← (exponentialDerivative_summable hB t).sum_add_tsum_nat_add 1] + simp [exponentialDerivative, exponentialAverage] + +lemma hasDerivAt_exponentialAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + HasDerivAt (exponentialAverage f) (exponentialAverage (fun n ↦ f (n+1)) t) t := by + let R := |t|+1 + have hR : 0 < R := by dsimp [R]; positivity + have ht : t ∈ Ioo (-R) R := by + constructor <;> dsimp [R] <;> linarith [le_abs_self t, neg_abs_le t] + let u : ℕ → ℝ := fun n ↦ exponentialDerivative (fun _ ↦ B) n R + have hu : Summable u := exponentialDerivative_summable (B := |B|) (fun _ ↦ le_refl _) R + have hd (n : ℕ) (y : ℝ) : HasDerivAt (fun z : ℝ ↦ z^n/(n.factorial:ℝ)*f n) + (exponentialDerivative f n y) y := by + cases n with + | zero => simpa [exponentialDerivative] using hasDerivAt_const y (f 0) + | succ n => + convert (((hasDerivAt_id y).pow (n+1)).div_const ((n+1).factorial:ℝ)).mul_const (f (n+1)) using 1 + all_goals try rfl + all_goals try simp only [exponentialDerivative, id_eq] + rw [Nat.factorial_succ, Nat.cast_mul] + simp only [Nat.add_sub_cancel, mul_one] + have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + field_simp + have hb (n : ℕ) (y : ℝ) (hy : y ∈ Ioo (-R) R) : ‖exponentialDerivative f n y‖ ≤ u n := by + have hyR : |y| ≤ R := (abs_le).2 ⟨le_of_lt hy.1, le_of_lt hy.2⟩ + cases n with + | zero => simp [exponentialDerivative, u] + | succ n => + dsimp [exponentialDerivative, u] + rw [abs_mul, abs_div, abs_pow, Nat.abs_cast] + exact mul_le_mul (div_le_div_of_nonneg_right (pow_le_pow_left₀ (abs_nonneg y) hyR n) (by positivity)) + (hB (n+1)) (abs_nonneg _) (by positivity) + have hh := hasDerivAt_tsum_of_isPreconnected hu isOpen_Ioo (convex_Ioo (-R) R).isPreconnected + (fun n y _ ↦ hd n y) hb ht (exponentialAverage_summable hB t) ht + rw [exponentialDerivative_sum hB t] at hh + exact hh + +theorem hasDerivAt_poissonAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + HasDerivAt (poissonAverage f) + (poissonAverage (fun n ↦ f (n+1)) t-poissonAverage f t) t := by + have hd := ((hasDerivAt_neg t).exp).mul (hasDerivAt_exponentialAverage hB t) + exact hd.congr_deriv (by unfold poissonAverage; ring) + +lemma poissonAverage_eq_tsum {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ) : + poissonAverage f t = ∑' n, poissonWeight t n*f n := by + rw [poissonAverage, exponentialAverage, ← (exponentialAverage_summable hB t).tsum_mul_left] + apply tsum_congr; intro n; unfold poissonWeight; ring + +lemma poissonAverage_eq_integral {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) (t : ℝ≥0) : + poissonAverage f t = ∫ n, f n ∂(poissonPMF t).toMeasure := by + rw [PMF.integral_eq_tsum] + · simp only [poissonPMF_real, smul_eq_mul] + exact poissonAverage_eq_tsum hB t + · exact Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable B + (Eventually.of_forall (fun n ↦ by simpa only [Real.norm_eq_abs] using hB n)) + +lemma continuous_poissonAverage {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) : + Continuous (poissonAverage f) := continuous_iff_continuousAt.mpr + (fun t ↦ (hasDerivAt_poissonAverage hB t).continuousAt) + +lemma poissonAverage_zero (f : ℕ → ℝ) : poissonAverage f 0 = f 0 := by + rw [poissonAverage, neg_zero, Real.exp_zero, one_mul, exponentialAverage, tsum_eq_single 0] + · simp + · intro n hn + simp [zero_pow hn] + +end ThreeState.TreeClauses.Probability + +end + +noncomputable section +open Set MeasureTheory ProbabilityTheory +open scoped NNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability + +lemma offspring_positive (ρ : PMF ℕ) (Q : Law) {lam : ℝ} + (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + ∀ᵐ m ∂(offspringLaw ρ Q hl₀ hl₁).probability.toMeasure, PositiveMessage m.1 := by + apply Measure.ae_sum_iff.mpr + intro n + exact Measure.ae_smul_measure (finite_positive Q hl₀ hl₁ n) _ + +lemma correction_nonneg (m : Message) : 0 ≤ correction m.1 := by + unfold correction + apply div_nonneg _ (by norm_num) + have h := avg_mono (fun i ↦ mul_nonneg (coordinate_nonneg m i) (sq_nonneg (logCentered m.1 i))) + simpa only [avg_const] using h + +private lemma poisson_mixture_integrable_nonneg (t : ℝ≥0) (P : ℕ → ProbabilityMeasure Message) + {f : Message → ℝ} (hi : ∀ n, Integrable f (P n).toMeasure) + (hp : ∀ n, ∀ᵐ m ∂(P n).toMeasure, 0 ≤ f m) + (hs : Summable (fun n ↦ poissonWeight t n*(∫ m, f m ∂(P n).toMeasure))) : + Integrable f (mixtureProbability (poissonPMF t) P).toMeasure := by + apply mixture_integrable _ P hi + simp only [poissonPMF_real] + apply hs.congr + intro n + congr 1 + exact integral_congr_ae ((hp n).mono (fun m hm ↦ (abs_of_nonneg hm).symm)) + +lemma poisson_integrable_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (t : ℝ≥0) : Integrable (fun m : Message ↦ symEntropy m.1) (poissonLaw Q hl₀ hl₁ t).probability.toMeasure := by + apply poisson_mixture_integrable_nonneg t (fun n ↦ finiteProbability Q hl₀ hl₁ n) + (finite_integrable_symEntropy Q hl₀ hl₁) + (fun n ↦ (finite_positive Q hl₀ hl₁ n).mono (fun m hm ↦ symEntropy_nonneg hm)) + have he (n : ℕ) : (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = + (n:ℝ)*edgeJMean Q lam := finiteLaw_symEntropy Q hl₀ hl₁ n + simp_rw [he, ← mul_assoc] + exact (poissonWeight_mean t).summable.mul_right _ + +lemma poisson_integrable_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (t : ℝ≥0) : Integrable (fun m : Message ↦ correction m.1) (poissonLaw Q hl₀ hl₁ t).probability.toMeasure := by + apply poisson_mixture_integrable_nonneg t (fun n ↦ finiteProbability Q hl₀ hl₁ n) + (finite_integrable_correction Q hl₀ hl₁) + (fun _ ↦ Filter.Eventually.of_forall correction_nonneg) + have h := ((poissonWeight_mean t).summable.mul_right + (∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)).add + ((poissonWeight_factorial_second t).summable.mul_right (2*(edgeJMean Q lam)^2)) + apply h.congr + intro n + have he := finiteLaw_correction Q hl₀ hl₁ n + change (∫ m, correction m.1 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at he + rw [he] + unfold edgeJMean + ring + +lemma poissonLaw_symEntropy (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (t : ℝ≥0) : + (∫ m, symEntropy m.1 ∂(poissonLaw Q hl₀ hl₁ t).probability.toMeasure) = (t:ℝ)*edgeJMean Q lam := by + rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) + (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, + integral_mixtureProbability _ _ (poisson_integrable_symEntropy Q hl₀ hl₁ t)] + simp only [poissonPMF_real, finiteLaw_symEntropy] + exact ((poissonWeight_mean t).mul_right (edgeJMean Q lam)).tsum_eq |> fun h ↦ by + simpa only [mul_assoc, edgeJMean] using h + +lemma poissonLaw_correction (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (t : ℝ≥0) : + (∫ m, correction m.1 ∂(poissonLaw Q hl₀ hl₁ t).probability.toMeasure) = + (t:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + 2*(t:ℝ)^2*(edgeJMean Q lam)^2 := by + rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) + (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, + integral_mixtureProbability _ _ (poisson_integrable_correction Q hl₀ hl₁ t)] + simp only [poissonPMF_real, finiteLaw_correction] + have h := ((poissonWeight_mean t).mul_right + (∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)).add + ((poissonWeight_factorial_second t).mul_right (2*(edgeJMean Q lam)^2)) + convert h.tsum_eq using 1 + · apply tsum_congr; intro n; unfold edgeJMean; ring + · ring + +def iMean (Q : Law) : ℝ := ∫ m, info m.1 ∂Q.probability.toMeasure + +def edgeIMean (Q : Law) (lam : ℝ) : ℝ := ∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure + +lemma bounded_iMean : ∃ B : ℝ, ∀ Q : Law, |iMean Q| ≤ B := by + have hc : Continuous (fun m : Message ↦ info m.1) := continuous_info_comp continuous_subtype_val + obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hc.continuousOn + refine ⟨B, fun Q ↦ ?_⟩ + apply (abs_integral_le_integral_abs).trans + exact (integral_mono (compact_integrable (continuous_info_comp continuous_subtype_val).abs) + (integrable_const B) (fun m ↦ by simpa only [Real.norm_eq_abs] using hB m (mem_univ m))).trans_eq (by simp) + +def poissonCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : ℝ := + t*edgeIMean Q lam-poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t + +lemma poissonLaw_info (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : + iMean (poissonLaw Q hl₀ hl₁ t) = (t:ℝ)*edgeIMean Q lam-poissonCorrelation Q hl₀ hl₁ t := by + obtain ⟨B,hB⟩ := bounded_iMean + have he : iMean (poissonLaw Q hl₀ hl₁ t) = poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t := by + unfold iMean + rw [show (poissonLaw Q hl₀ hl₁ t).probability = mixtureProbability (poissonPMF t) + (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability) from rfl, + integral_mixtureProbability _ _ (compact_integrable (continuous_info_comp continuous_subtype_val))] + change _ = poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t + rw [poissonAverage_eq_tsum (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))] + simp only [poissonPMF_real, iMean] + rw [he, poissonCorrelation] + ring + +lemma poissonCorrelation_continuous (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Continuous (poissonCorrelation Q hl₀ hl₁) := by + obtain ⟨B,hB⟩ := bounded_iMean + exact (continuous_id.mul continuous_const).sub + (continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))) + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped NNReal +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +lemma poisson_fixed_edgeJ (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) + (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : + edgeJMean Q lam = lam^2*jMean Q := by + have h := poissonLaw_symEntropy Q hl₀.le hl₁ d + change (∫ m, symEntropy m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at h + rw [← hfixed] at h + change jMean Q = (d:ℝ)*edgeJMean Q lam at h + rw [h] + calc + _ = ((d:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit, one_mul] + _ = _ := by ring + +lemma functional_integral {α : Type*} [MeasurableSpace α] (μ : Measure α) (f : α → Vec) + (hI : Integrable (fun m ↦ info (f m)) μ) + (hJ : Integrable (fun m ↦ symEntropy (f m)) μ) + (hB : Integrable (fun m ↦ correction (f m)) μ) : + (∫ m, functional (f m) ∂μ) = 3*(∫ m, info (f m) ∂μ)- + 2*(∫ m, symEntropy (f m) ∂μ)+(4/5)*(∫ m, correction (f m) ∂μ) := by + unfold functional + rw [integral_add (f := fun m ↦ 3*info (f m)-2*symEntropy (f m)) + (g := fun m ↦ (4/5)*correction (f m)) ((hI.const_mul _).sub (hJ.const_mul _)) (hB.const_mul _), + integral_sub (f := fun m ↦ 3*info (f m)) (g := fun m ↦ 2*symEntropy (f m)) + (hI.const_mul _) (hJ.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] + +lemma integrated_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) + (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) + (hB : Integrable (fun m : Message ↦ correction m.1) Q.probability.toMeasure) : + (1-lam^2)/2*Q.nu ≤ (∫ m, functional m.1 ∂Q.probability.toMeasure)- + (lam^2)⁻¹*(∫ m, functional (edgeMessage lam m) ∂Q.probability.toMeasure) := by + have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := + compact_integrable (continuous_info_comp continuous_subtype_val) + have hJe := edgeJ_integrable Q hl₀.le hl₁ + have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) + have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) + (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) + have hF : Integrable (fun m : Message ↦ functional m.1) Q.probability.toMeasure := + (hI.const_mul 3 |>.sub (hJ.const_mul 2)).add (hB.const_mul (4/5)) + have hFe : Integrable (fun m : Message ↦ functional (edgeMessage lam m)) Q.probability.toMeasure := + (hIe.const_mul 3 |>.sub (hJe.const_mul 2)).add (hBe.const_mul (4/5)) + have hrad := integral_mono_ae (μ := Q.probability.toMeasure) + (f := fun m : Message ↦ (1-lam^2)/2*xMoment m^2) + (g := fun m ↦ functional m.1-(lam^2)⁻¹*functional (edgeMessage lam m)) + ((compact_integrable (continuous_xMoment.pow 2)).const_mul _) (hF.sub (hFe.const_mul _)) + (hp.mono (fun m hm ↦ radial_inequality m.1 hm lam hl₀ hl₁)) + rw [integral_const_mul, integral_sub hF (hFe.const_mul _), integral_const_mul] at hrad + exact hrad + +lemma poisson_fixed_entropy_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) + (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : + (1-lam^2)/2*Q.nu ≤ (8/5)*(jMean Q)^2-3*poissonCorrelation Q hl₀.le hl₁ d := by + have hp := offspring_positive (poissonPMF d) Q hl₀.le hl₁ + have hJ := poisson_integrable_symEntropy Q hl₀.le hl₁ d + have hB := poisson_integrable_correction Q hl₀.le hl₁ d + change ∀ᵐ m ∂(poissonLaw Q hl₀.le hl₁ d).probability.toMeasure, PositiveMessage m.1 at hp + rw [← hfixed] at hp hJ hB + have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := + compact_integrable (continuous_info_comp continuous_subtype_val) + have hJe := edgeJ_integrable Q hl₀.le hl₁ + have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) + have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) + have hrad := integrated_radial Q hl₀ hl₁ hp hJ hB + have hJid := poissonLaw_symEntropy Q hl₀.le hl₁ d + have hBid := poissonLaw_correction Q hl₀.le hl₁ d + have hIid := poissonLaw_info Q hl₀.le hl₁ d + change (∫ m, symEntropy m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hJid + change (∫ m, correction m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hBid + change (∫ m, info m.1 ∂((poissonLaw Q hl₀.le hl₁ d).probability).toMeasure) = _ at hIid + rw [← hfixed] at hJid hBid hIid + have hninv : (lam^2)⁻¹ = (d:ℝ) := by + apply mul_left_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀)) + rw [mul_inv_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀))] + nlinarith [hcrit] + have hFid := functional_integral Q.probability.toMeasure (fun m : Message ↦ m.1) hI hJ hB + have hFeid := functional_integral Q.probability.toMeasure (edgeMessage lam) hIe hJe hBe + rw [hFid, hFeid, hninv, hIid, hBid] at hrad + change jMean Q = (d:ℝ)*edgeJMean Q lam at hJid + change _ ≤ 3*((d:ℝ)*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-poissonCorrelation Q hl₀.le hl₁ d)- + 2*jMean Q+(4/5)*((d:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + 2*((d:ℝ)^2)*(edgeJMean Q lam)^2)- + (d:ℝ)*(3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ + (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)) at hrad + have he : ((d:ℝ)^2)*(edgeJMean Q lam)^2 = (jMean Q)^2 := by + rw [poisson_fixed_edgeJ Q hl₀ hl₁ d hcrit hfixed] + have hn : ((d:ℝ)^2)*lam^4 = 1 := by + nlinarith [sq_nonneg ((d:ℝ)*lam^2-1), hcrit] + calc + _ = (((d:ℝ)^2)*lam^4)*(jMean Q)^2 := by ring + _ = _ := by rw [hn]; ring + nlinarith [hJid, he] + +lemma poisson_fixed_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (d : ℝ≥0) + (hcrit : (d:ℝ)*lam^2 = 1) (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : + 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by + have hp := offspring_positive (poissonPMF d) Q hl₀.le hl₁ + have hJ := poisson_integrable_symEntropy Q hl₀.le hl₁ d + change ∀ᵐ m ∂(poissonLaw Q hl₀.le hl₁ d).probability.toMeasure, PositiveMessage m.1 at hp + rw [← hfixed] at hp hJ + exact expected_moment_bounds Q hl₀ hl₁ hp hJ (poisson_fixed_edgeJ Q hl₀ hl₁ d hcrit hfixed) + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory ProbabilityTheory +open scoped NNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability + +lemma finite_iMean_succ (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + iMean (finiteLaw Q hl₀ hl₁ (n+1)) = iMean (finiteLaw Q hl₀ hl₁ n)+edgeIMean Q lam- + pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam := by + unfold iMean edgeIMean + rw [finiteLaw_info, finiteLaw_info, correlationEntropy_succ Q hl₀ hl₁, Nat.cast_add, Nat.cast_one] + ring + +lemma finite_iMean_zero (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + iMean (finiteLaw Q hl₀ hl₁ 0) = 0 := by + rw [iMean, finiteLaw_info] + norm_num [correlationEntropy, normalizer, branchProduct, avg] + +lemma poissonCorrelation_zero (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + poissonCorrelation Q hl₀ hl₁ 0 = 0 := by + simp [poissonCorrelation, poissonAverage_zero, finite_iMean_zero] + +def poissonSlope (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : ℝ := + edgeIMean Q lam-(poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ (n+1))) t- + poissonAverage (fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) t) + +lemma hasDerivAt_poissonCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ) : + HasDerivAt (poissonCorrelation Q hl₀ hl₁) (poissonSlope Q hl₀ hl₁ t) t := by + obtain ⟨B,hB⟩ := bounded_iMean + unfold poissonCorrelation poissonSlope + convert ((hasDerivAt_id t).mul_const (edgeIMean Q lam)).sub + (hasDerivAt_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)) t) using 1 <;> first | rfl | simp only [one_mul] + +lemma continuous_poissonSlope (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Continuous (poissonSlope Q hl₀ hl₁) := by + obtain ⟨B,hB⟩ := bounded_iMean + exact continuous_const.sub + ((continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1)))).sub + (continuous_poissonAverage (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)))) + +lemma bounded_pairCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + ∃ B : ℝ, ∀ R : Law, |pairCorrelation R Q lam| ≤ B := by + have hc := continuous_compact_integral (μ := Q.probability.toMeasure) (continuous_pairEntropy hl₀ hl₁) + obtain ⟨B,hB⟩ := isCompact_univ.exists_bound_of_continuousOn hc.continuousOn + refine ⟨B, fun R ↦ ?_⟩ + apply (abs_integral_le_integral_abs).trans + exact (integral_mono (compact_integrable hc.abs) (integrable_const B) + (fun r ↦ by simpa only [Real.norm_eq_abs] using hB r (mem_univ r))).trans_eq (by simp) + +lemma poissonSlope_eq_pairCorrelation (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : + poissonSlope Q hl₀ hl₁ t = pairCorrelation (poissonLaw Q hl₀ hl₁ t) Q lam := by + obtain ⟨B,hB⟩ := bounded_iMean + obtain ⟨C,hC⟩ := bounded_pairCorrelation Q hl₀ hl₁ + have hi := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n)) + have hi' := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1))) + have hc := pmf_bounded_integrable (poissonPMF t) (fun n ↦ hC (finiteLaw Q hl₀ hl₁ n)) + have he : pairCorrelation (poissonLaw Q hl₀ hl₁ t) Q lam = + ∫ n, pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam ∂(poissonPMF t).toMeasure := by + change (∫ r, (∫ m, pairZ lam r m*Real.log (pairZ lam r m) ∂Q.probability.toMeasure) + ∂(mixtureProbability (poissonPMF t) (fun n ↦ (finiteLaw Q hl₀ hl₁ n).probability)).toMeasure) = _ + rw [integral_mixtureProbability _ _ (compact_integrable (continuous_compact_integral (continuous_pairEntropy hl₀ hl₁))), + PMF.integral_eq_tsum _ _ hc] + rfl + rw [he, poissonSlope, poissonAverage_eq_integral (fun n ↦ hB (finiteLaw Q hl₀ hl₁ (n+1))), + poissonAverage_eq_integral (fun n ↦ hB (finiteLaw Q hl₀ hl₁ n))] + have he' := integral_congr_ae (μ := (poissonPMF t).toMeasure) + (Filter.Eventually.of_forall (finite_iMean_succ Q hl₀ hl₁)) + rw [integral_sub (f := fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)+edgeIMean Q lam) + (g := fun n ↦ pairCorrelation (finiteLaw Q hl₀ hl₁ n) Q lam) (hi.add (integrable_const _)) hc, + integral_add (f := fun n ↦ iMean (finiteLaw Q hl₀ hl₁ n)) + (g := fun _ ↦ edgeIMean Q lam) hi (integrable_const _)] at he' + simp only [integral_const, Measure.real, measure_univ, ENNReal.toReal_one, one_smul] at he' + linarith + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped NNReal +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +lemma poisson_increment_bound (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (d t : ℝ≥0) (htd : t ≤ d) + (hfixed : Q.probability = (poissonLaw Q hl₀ hl₁ d).probability) : + 3*lam^4*Q.mu^2*(t:ℝ)/(1+(t:ℝ)*(lam^2*Q.mu))- + lam^4*Q.mu*Q.nu*Real.sqrt t ≤ 3*poissonSlope Q hl₀ hl₁ t := by + have hmu := Q.mu_nonneg + have hnuQ := Q.nu_nonneg + let L : ℝ := (t:ℝ)*(lam^2*Q.mu)/(1+(t:ℝ)*(lam^2*Q.mu)) + have ht : 0 ≤ (t:ℝ) := t.coe_nonneg + have hd : 1 ≤ 1+(t:ℝ)*(lam^2*Q.mu) := by nlinarith only [mul_nonneg ht (mul_nonneg (sq_nonneg lam) hmu)] + have hL : 0 ≤ L := by dsimp [L]; positivity + have hproj := poisson_projection Q hl₀ hl₁ t + have hnu : (poissonLaw Q hl₀ hl₁ t).nu ≤ Q.nu := by + have hh := poisson_nu_mono Q hl₀ hl₁ htd + change _ ≤ ∫ m, xMoment m^2 ∂(poissonLaw Q hl₀ hl₁ d).probability.toMeasure at hh + rwa [← hfixed] at hh + have hc := correlation_truncated Q (poissonLaw Q hl₀ hl₁ t) hl₀ hl₁ hnu hL hproj + have hLu : L ≤ (t:ℝ)*(lam^2*Q.mu) := by + dsimp only [L] + exact div_le_self (by positivity) hd + have hs : Real.sqrt L ≤ lam*Real.sqrt Q.mu*Real.sqrt t := by + have he : (lam*Real.sqrt Q.mu*Real.sqrt t)^2 = (t:ℝ)*(lam^2*Q.mu) := by + calc + _ = lam^2*(Real.sqrt Q.mu)^2*(Real.sqrt t)^2 := by ring + _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt ht]; ring + have hp : 0 ≤ lam*Real.sqrt Q.mu*Real.sqrt t := by positivity + nlinarith only [he, hp, Real.sq_sqrt hL, Real.sqrt_nonneg L, hLu] + have hmul := mul_le_mul_of_nonneg_left hs (show 0 ≤ lam^3*Real.sqrt Q.mu*Q.nu by positivity) + have heq : (lam^3*Real.sqrt Q.mu*Q.nu)*(lam*Real.sqrt Q.mu*Real.sqrt t) = + lam^4*Q.mu*Q.nu*Real.sqrt t := by + calc + _ = lam^4*(Real.sqrt Q.mu)^2*Q.nu*Real.sqrt t := by ring + _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg] + rw [heq] at hmul + have hmain : 3*lam^2*Q.mu*L = 3*lam^4*Q.mu^2*(t:ℝ)/(1+(t:ℝ)*(lam^2*Q.mu)) := by + dsimp only [L]; ring + rw [hmain, ← poissonSlope_eq_pairCorrelation] at hc + linarith only [hc, hmul] + +lemma sqrt_intensity_tangent {lam t : ℝ} (hl : 0 < lam) (ht : 0 ≤ t) : + Real.sqrt t ≤ (2*lam^2*t+1)/(2*lam*Real.sqrt 2) := by + have hs2 := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) + have hst := Real.sq_sqrt ht + have hs2p := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) + apply (le_div_iff₀ (by positivity : 0 < 2*lam*Real.sqrt 2)).2 + have he : (lam*Real.sqrt 2*Real.sqrt t)^2 = 2*lam^2*t := by + calc + _ = lam^2*(Real.sqrt 2)^2*(Real.sqrt t)^2 := by ring + _ = _ := by rw [hs2, hst]; ring + nlinarith only [sq_nonneg (lam*Real.sqrt 2*Real.sqrt t-1), he] + +theorem poisson_fixed_correlation_bound (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (d : ℝ≥0) (hcrit : (d:ℝ)*lam^2 = 1) + (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : + 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu ≤ + 3*poissonCorrelation Q hl₀.le hl₁ d := by + let q := 2*Q.mu/3 + let β := lam^2*Q.mu + let A := 3*lam^4*Q.mu^2/(1+q)^2 + let B := lam^3*Q.mu*Q.nu/(2*Real.sqrt 2) + let P : ℝ → ℝ := fun t ↦ A*((1+2*q)*t^2/2-β*t^3/3)-B*(lam^2*t^2+t) + let P' : ℝ → ℝ := fun t ↦ A*((1+2*q)*t-β*t^2)-B*(2*lam^2*t+1) + have hmu := Q.mu_nonneg + have hnu := Q.nu_nonneg + have hq : 0 ≤ q := by dsimp [q]; positivity + have hβ : 0 ≤ β := by dsimp [β]; positivity + have hA : 0 ≤ A := by dsimp [A]; positivity + have hB : 0 ≤ B := by dsimp [B]; positivity + have hsq : 0 < 1+q := by positivity + have hs2 : 0 < Real.sqrt 2 := Real.sqrt_pos.mpr (by norm_num) + have dP (t : ℝ) : HasDerivAt P (P' t) t := by + apply ((((((hasDerivAt_id t).pow 2).const_mul (1+2*q)).div_const 2 |>.sub + ((((hasDerivAt_id t).pow 3).const_mul β).div_const 3)).const_mul A).sub + (((((hasDerivAt_id t).pow 2).const_mul (lam^2)).add (hasDerivAt_id t)).const_mul B)).congr_deriv + dsimp [P']; norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one]; ring + have hbound (t : ℝ) (ht : t ∈ Icc 0 (d:ℝ)) : P' t ≤ 3*poissonSlope Q hl₀.le hl₁ t := by + let u : ℝ≥0 := ⟨t,ht.1⟩ + have hi := poisson_increment_bound Q hl₀.le hl₁ d u ht.2 hfixed + have hr := mul_le_mul_of_nonneg_left (reciprocal_tangent (mul_nonneg ht.1 hβ) hq) + (mul_nonneg hA ht.1) + have hr' : A*((1+2*q)*t-β*t^2) ≤ 3*lam^4*Q.mu^2*t/(1+t*β) := by + calc + _ = A*t*(1+2*q-t*β) := by ring + _ ≤ A*t*((1+q)^2/(1+t*β)) := hr + _ = _ := by dsimp only [A]; field_simp + have hs := mul_le_mul_of_nonneg_left (sqrt_intensity_tangent hl₀ ht.1) + (show 0 ≤ lam^4*Q.mu*Q.nu by positivity) + have hs' : lam^4*Q.mu*Q.nu*Real.sqrt t ≤ B*(2*lam^2*t+1) := by + calc + _ ≤ lam^4*Q.mu*Q.nu*((2*lam^2*t+1)/(2*lam*Real.sqrt 2)) := hs + _ = _ := by dsimp only [B]; field_simp + change 3*lam^4*Q.mu^2*t/(1+t*β)-lam^4*Q.mu*Q.nu*Real.sqrt t ≤ + 3*poissonSlope Q hl₀.le hl₁ t at hi + dsimp only [P'] + linarith only [hr', hs', hi] + have hm : MonotoneOn (fun t ↦ 3*poissonCorrelation Q hl₀.le hl₁ t-P t) (Icc 0 (d:ℝ)) := by + apply monotoneOn_Icc_of_hasDerivAt_nonneg + (fun t _ ↦ ((hasDerivAt_poissonCorrelation Q hl₀.le hl₁ t).const_mul 3).sub (dP t)) + intro t ht + exact sub_nonneg.mpr (hbound t ⟨ht.1.le,ht.2.le⟩) + have hh := hm ⟨le_rfl,d.coe_nonneg⟩ ⟨d.coe_nonneg,le_rfl⟩ d.coe_nonneg + have hz : P 0 = 0 := by dsimp [P]; ring + change 3*poissonCorrelation Q hl₀.le hl₁ 0-P 0 ≤ 3*poissonCorrelation Q hl₀.le hl₁ d-P d at hh + rw [poissonCorrelation_zero, hz] at hh + have hd : (d:ℝ) = 1/lam^2 := (eq_div_iff (ne_of_gt (sq_pos_of_pos hl₀))).2 hcrit + have hp : P d = 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu := by + dsimp only [P,A,B,β,q] + rw [hd] + field_simp + ring + rw [hp] at hh + linarith only [hh] + +end ThreeState.TreeClauses.Positive + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PoissonFixed.lean b/lean/OAI/Probability/ThreeStateClauses/PoissonFixed.lean index d48e42cddee5ffa72beeb4d086d98e47d391e56a..31fa4987dfe84cdfa34ac12d921d3f1f17ab437b 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PoissonFixed.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PoissonFixed.lean @@ -1,346 +1,346 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.OffspringLaws -import OAI.Probability.ThreeStateClauses.PoissonCalculus - -namespace OAI - -/-! Poisson Fixed. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory ProbabilityTheory -open scoped NNReal ENNReal BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability - -def uniformMessage : Message := ⟨fun _ ↦ 1, by norm_num, by norm_num [avg]⟩ - -lemma uniformMessage_x : xMoment uniformMessage = 0 := by norm_num [xMoment, momentX, centered, uniformMessage, avg] - -lemma branch_uniform (lam : ℝ) (n : ℕ) : - normalizer (branchEdges lam (fun _ : Fin n ↦ uniformMessage)) = 1 := by - norm_num [normalizer, branchEdges, branchProduct, edgeMessage, edge, centered, uniformMessage, avg] - -lemma branchOutput_uniform {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - branchOutput hl₀ hl₁ (fun _ : Fin n ↦ uniformMessage) = uniformMessage := by - apply Subtype.ext - funext i - norm_num [branchOutput, normalizedProduct, branch_uniform, branchProduct, branchEdges, - edgeMessage, edge, centered, uniformMessage, normalizer, avg] - -lemma finite_uniform_atom (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - (Q.probability.toMeasure {uniformMessage})^n ≤ - (finiteProbability Q hl₀ hl₁ n).toMeasure {uniformMessage} := by - change _ ≤ (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) {uniformMessage} - rw [Measure.map_apply (continuous_branchOutput hl₀ hl₁ n).measurable (measurableSet_singleton _)] - have he : (tiltedProduct Q lam n) {fun _ : Fin n ↦ uniformMessage} = - (Q.probability.toMeasure {uniformMessage})^n := by - rw [tiltedProduct, withDensity_apply _ (measurableSet_singleton _), lintegral_singleton] - simp only [branch_uniform, ENNReal.ofReal_one, one_mul, Measure.pi_singleton, - Finset.prod_const, Finset.card_univ, Fintype.card_fin] - rw [← he] - apply measure_mono - intro m hm - rcases hm with rfl - exact branchOutput_uniform hl₀ hl₁ n - -lemma poisson_generating (t q : ℝ) : - HasSum (fun n ↦ poissonWeight t n*q^n) (Real.exp (t*(q-1))) := by - have hx : HasSum (fun n : ℕ ↦ (t*q)^n/(n.factorial:ℝ)) (Real.exp (t*q)) := by - rw [Real.exp_eq_exp_ℝ] - exact NormedSpace.expSeries_div_hasSum_exp (t*q) - have h := hx.mul_left (Real.exp (-t)) - have he : Real.exp (-t)*Real.exp (t*q) = Real.exp (t*(q-1)) := by - rw [← Real.exp_add]; congr 1; ring - rw [he] at h - have hf : (fun n : ℕ ↦ poissonWeight t n*q^n) = - (fun n ↦ Real.exp (-t)*((t*q)^n/(n.factorial:ℝ))) := by - funext n - dsimp [poissonWeight] - rw [mul_pow] - ring - rw [hf] - exact h - -lemma poisson_uniform_atom (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : - Real.exp ((t:ℝ)*((Q.probability.toMeasure {uniformMessage}).toReal-1)) ≤ - ((poissonLaw Q hl₀ hl₁ t).probability.toMeasure {uniformMessage}).toReal := by - let q := (Q.probability.toMeasure {uniformMessage}).toReal - have hq : 0 ≤ q := ENNReal.toReal_nonneg - have he : ENNReal.ofReal q = Q.probability.toMeasure {uniformMessage} := - ENNReal.ofReal_toReal (measure_ne_top _ _) - have h : ENNReal.ofReal (Real.exp ((t:ℝ)*(q-1))) ≤ - (poissonLaw Q hl₀ hl₁ t).probability.toMeasure {uniformMessage} := by - rw [← (poisson_generating t q).tsum_eq, ENNReal.ofReal_tsum_of_nonneg - (fun n ↦ mul_nonneg (poissonWeight_nonneg t.coe_nonneg n) (pow_nonneg hq n)) - (poisson_generating t q).summable] - change _ ≤ (Measure.sum (fun n ↦ (poissonPMF t) n • (finiteProbability Q hl₀ hl₁ n).toMeasure)) _ - rw [Measure.sum_apply _ (measurableSet_singleton _)] - apply ENNReal.tsum_le_tsum - intro n - rw [ENNReal.ofReal_mul (poissonWeight_nonneg t.coe_nonneg n), ENNReal.ofReal_pow hq, he, - ← poissonPMF_real, ENNReal.ofReal_toReal ((poissonPMF t).apply_ne_top n)] - exact mul_le_mul' le_rfl (finite_uniform_atom Q hl₀ hl₁ n) - have hh := ENNReal.toReal_mono (measure_ne_top _ _) h - rwa [ENNReal.toReal_ofReal (Real.exp_pos _).le] at hh - -def Law.nonuniformMass (Q : Law) : ℝ := 1-(Q.probability.toMeasure {uniformMessage}).toReal - -lemma Law.nonuniformMass_nonneg (Q : Law) : 0 ≤ Q.nonuniformMass := by - apply sub_nonneg.mpr - exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.one_ne_top).2 (prob_le_one) - -lemma Law.nonuniformMass_le_one (Q : Law) : Q.nonuniformMass ≤ 1 := by - unfold Law.nonuniformMass - exact sub_le_self _ ENNReal.toReal_nonneg - -lemma Law.nonuniform_second_moment (Q : Law) : Q.mu^2 ≤ Q.nonuniformMass*Q.nu := by - have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) - have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) - have hquad (a : ℝ) : 0 ≤ Q.nonuniformMass*(a*a)+(-2*Q.mu)*a+Q.nu := by - have h := integral_nonneg (μ := Q.probability.toMeasure.restrict {uniformMessage}ᶜ) - (f := fun m : Message ↦ (xMoment m-a)^2) (fun m ↦ sq_nonneg (xMoment m-a)) - rw [setIntegral_compl (f := fun m : Message ↦ (xMoment m-a)^2) (measurableSet_singleton _) - (compact_integrable ((continuous_xMoment.sub continuous_const).pow 2)), - integral_singleton, uniformMessage_x] at h - have hf : (fun m : Message ↦ (xMoment m-a)^2) = - (fun m ↦ xMoment m^2-2*a*xMoment m+a^2) := by funext m; ring - rw [hf, integral_add (f := fun m ↦ xMoment m^2-2*a*xMoment m) - (g := fun _ ↦ a^2) (hi₂.sub (hi.const_mul _)) (integrable_const _), - integral_sub (f := fun m : Message ↦ xMoment m^2) (g := fun m ↦ 2*a*xMoment m) hi₂ (hi.const_mul _), integral_const_mul] at h - simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, - smul_eq_mul, one_mul, zero_sub, neg_sq] at h - change 0 ≤ Q.nu-2*a*Q.mu+a^2-(Q.probability.toMeasure {uniformMessage}).toReal*a^2 at h - dsimp only [Law.nonuniformMass] - nlinarith only [h] - have h := discrim_le_zero hquad - dsimp only [discrim] at h - nlinarith only [h] - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set -namespace ThreeState.TreeClauses.Probability -open ThreeState.TreeClauses.Radial - -lemma neg_log_one_sub_lower {s : ℝ} (hs₀ : 0 ≤ s) (hs₁ : s < 1) : - 2*s/(2-s) ≤ -Real.log (1-s) := by - let f : ℝ → ℝ := fun t ↦ -Real.log (1-t)-2*t/(2-t) - let f' : ℝ → ℝ := fun t ↦ t^2/((1-t)*(2-t)^2) - have hd (t : ℝ) (ht : t ∈ Icc 0 s) : HasDerivAt f (f' t) t := by - have ht1 : 0 < 1-t := by linarith [ht.2] - have ht2 : 0 < 2-t := by linarith - apply (((((hasDerivAt_id t).const_sub 1).log (ne_of_gt ht1)).neg).sub - (((hasDerivAt_id t).const_mul 2).div ((hasDerivAt_id t).const_sub 2) (ne_of_gt ht2))).congr_deriv - dsimp only [f', id_eq] - field_simp - ring - have hm : MonotoneOn f (Icc 0 s) := by - apply monotoneOn_Icc_of_hasDerivAt_nonneg hd - intro t ht - dsimp only [f', id_eq] - have : 0 < 1-t := by linarith [ht.2] - positivity - have h := hm ⟨le_rfl,hs₀⟩ ⟨hs₀,le_rfl⟩ hs₀ - dsimp only [f] at h - norm_num at h - linarith only [h] - -lemma poisson_subfixed_mass_bound {d s : ℝ} (hd : 1 < d) (hs₀ : 0 ≤ s) - (hs : Real.exp (-d*s) ≤ 1-s) : s ≤ 2*(1-1/d) := by - have hs₁ : s < 1 := by linarith [Real.exp_pos (-d*s)] - have hlog : -Real.log (1-s) ≤ d*s := by - have h := Real.log_le_log (Real.exp_pos (-d*s)) hs - rw [Real.log_exp] at h - linarith only [h] - have hl := neg_log_one_sub_lower hs₀ hs₁ - have hden : 0 < 2-s := by linarith - have hmul := (div_le_iff₀ hden).mp (hl.trans hlog) - rcases eq_or_lt_of_le hs₀ with h | h - · have he : s = 0 := h.symm - rw [he] - have hdiv : 1/d < 1 := (div_lt_one (by linarith : 0 < d)).2 hd - linarith only [hdiv] - · have hh : 2 ≤ d*(2-s) := (mul_le_mul_iff_right₀ h).mp (by nlinarith only [hmul]) - have he : 2*(1-1/d) = (2*d-2)/d := by field_simp - rw [he] - apply (le_div_iff₀ (by linarith : 0 < d)).2 - nlinarith only [hh] - -end ThreeState.TreeClauses.Probability - -end - -noncomputable section -open Set MeasureTheory -open scoped NNReal -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability - -lemma poisson_fixed_mass_bound (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (d : ℝ≥0) (hd : 1 < (d:ℝ)) (hcrit : (d:ℝ)*lam^2 = 1) - (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : - Q.nonuniformMass ≤ 2*(1-lam^2) := by - have ha := poisson_uniform_atom Q hl₀.le hl₁ d - rw [← hfixed] at ha - have hsub : Real.exp (-(d:ℝ)*Q.nonuniformMass) ≤ 1-Q.nonuniformMass := by - calc - _ = Real.exp ((d:ℝ)*((Q.probability.toMeasure {uniformMessage}).toReal-1)) := by - congr 1; dsimp only [Law.nonuniformMass]; ring - _ ≤ (Q.probability.toMeasure {uniformMessage}).toReal := ha - _ = _ := by dsimp only [Law.nonuniformMass]; ring - have hs := poisson_subfixed_mass_bound hd Q.nonuniformMass_nonneg hsub - have he : 1/(d:ℝ) = lam^2 := (div_eq_iff (by positivity : (d:ℝ) ≠ 0)).2 (by nlinarith only [hcrit]) - rwa [he] at hs - -theorem poisson_fixed_mu_zero (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (d : ℝ≥0) (hd : 1 < (d:ℝ)) (hcrit : (d:ℝ)*lam^2 = 1) - (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : Q.mu = 0 := by - by_contra hmu0 - have hmu : 0 < Q.mu := lt_of_le_of_ne Q.mu_nonneg (Ne.symm hmu0) - have hnu : 0 < Q.nu := (sq_pos_of_pos hmu).trans_le Q.second_moment_lower - have hmoment := Q.nonuniform_second_moment - have hs₀ : 0 < Q.nonuniformMass := by - by_contra h - have hh := mul_nonpos_of_nonpos_of_nonneg (le_of_not_gt h) hnu.le - nlinarith only [hmoment, hh, sq_pos_of_pos hmu] - have hinfo := poisson_fixed_moment_bounds Q hl₀ hl₁ d hcrit hfixed - have hcl := cExact_lower hl₀.le hl₁.le - have hc : 0 < cExact lam := (cLower_pos hl₀.le).trans_le hcl - have hetaNonneg : 0 ≤ Q.eta := (mul_nonneg hc.le hnu.le).trans hinfo.2.2 - have hsq : (cExact lam*Q.nu)^2 ≤ Q.eta^2 := - (sq_le_sq₀ (mul_nonneg hc.le hnu.le) hetaNonneg).2 hinfo.2.2 - have hregion : cExact lam^2*Q.nu ≤ Q.mu := by - apply (mul_le_mul_iff_right₀ hnu).mp - nlinarith [Q.moment_discriminant] - have hmuC : Q.mu*cExact lam^2 ≤ Q.nonuniformMass := by - apply (mul_le_mul_iff_right₀ hmu).mp - have hh := mul_le_mul_of_nonneg_left hmoment (sq_nonneg (cExact lam)) - have hh' := mul_le_mul_of_nonneg_left hregion hs₀.le - nlinarith only [hh, hh'] - have hregionLower : Q.mu*cLower lam^2 ≤ Q.nonuniformMass := by - have hs : cLower lam^2 ≤ cExact lam^2 := - (sq_le_sq₀ (cLower_pos hl₀.le).le hc.le).2 hcl - exact (mul_le_mul_of_nonneg_left hs hmu.le).trans hmuC - have hstrict := scalar_strict hl₀ hl₁ hmu.le hs₀ Q.nonuniformMass_le_one hregionLower - (Or.inr (poisson_fixed_mass_bound Q hl₀ hl₁ d hd hcrit hfixed)) - have hJ := jMean_square_bound hl₀.le hl₁.le hmu.le hnu.le hinfo.1 hinfo.2.1 hregion - have hH := poisson_fixed_correlation_bound Q hl₀ hl₁ d hcrit hfixed - have hrad := poisson_fixed_entropy_radial Q hl₀ hl₁ d hcrit hfixed - have hH' : 3*Q.mu^2/(2*(1+2*Q.mu/3))-(1/Real.sqrt 2)*(lam*Q.mu*Q.nu) ≤ - 3*poissonCorrelation Q hl₀.le hl₁ d := by - convert hH using 1 - ring - have hg := mul_le_mul_of_nonneg_right (le_of_lt strict_correlation_coefficient) - (show 0 ≤ lam*Q.mu*Q.nu by positivity) - have hb₀ : (1-lam^2)/2*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3))+ - (17/25)*lam*Q.mu*Q.nu ≤ (8/5)*Q.mu^2 := by - nlinarith only [hJ,hH',hrad,hg] - have hb : ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) ≤ - (8/5)*Q.mu^2 := by nlinarith only [hb₀] - have halpha : 0 < 1-lam^2 := by nlinarith only [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] - have hcoef : 0 ≤ ((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass := by positivity - have hsub := mul_le_mul_of_nonneg_left hmoment hcoef - have hnecessary : scalarT lam Q.mu Q.nonuniformMass*Q.mu^2 ≤ (8/5)*Q.mu^2 := by - calc - _ = (((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass)*Q.mu^2+ - 3*Q.mu^2/(2*(1+2*Q.mu/3)) := by unfold scalarT; ring - _ ≤ (((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass)*(Q.nonuniformMass*Q.nu)+ - 3*Q.mu^2/(2*(1+2*Q.mu/3)) := by linarith only [hsub] - _ = ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by - field_simp [ne_of_gt hs₀] - _ ≤ _ := hb - have hh := mul_lt_mul_of_pos_right hstrict (sq_pos_of_pos hmu) - linarith only [hh,hnecessary] - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped Topology NNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma ordered_advantage_sq_moment (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) : - (advantage lam hlam ρ ℓ)^2 ≤ - (∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ lam hlam ℓ)).toMeasure)/2 := by - have h := discrete_degradation_mu (orderedLaw ρ lam hlam ℓ) (fun v ↦ PMF.pure (forgetOrdered ℓ v)) - change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ - (orderedLaw ρ lam hlam ℓ i).map (forgetOrdered ℓ))).toMeasure) ≤ _ at h - simp only [orderedLaw_forget] at h - have ha := advantage_sq_bound lam hlam ρ ℓ - linarith - -lemma poisson_positive_critical_mu (d : ℝ≥0) (hd : 1 < (d:ℝ)) {lam : ℝ} - (hl₀ : 0 < lam) (hl₁ : lam < 1) (hlam : Admissible lam) (hcrit : (d:ℝ)*lam^2 = 1) : - Tendsto (fun ℓ ↦ (offspringPosteriorLaw (poissonPMF d) hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by - let ρ := poissonPMF d - let Q := offspringPosteriorLaw ρ hl₀.le hl₁ - let C := fun ℓ ↦ degradationCoupling (orderedLaw ρ lam hlam ℓ) (orderedExpansion ρ lam hlam ℓ) - have hf (ℓ : ℕ) : (C ℓ).map Prod.fst = (Q ℓ).probability := by - rw [degradationCoupling_fst, offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam ℓ] - have hs (ℓ : ℕ) : (C ℓ).map Prod.snd = (Q (ℓ+1)).probability := by - rw [degradationCoupling_snd] - have he : (fun i ↦ (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ)) = - orderedLaw ρ lam hlam (ℓ+1) := funext (orderedLaw_degrades ρ lam hlam ℓ) - rw [he] - exact (offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam (ℓ+1)).symm - have hl (ℓ : ℕ) : (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu := by - rw [degradationCoupling_loss] - have he : (fun i ↦ (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ)) = - orderedLaw ρ lam hlam (ℓ+1) := funext (orderedLaw_degrades ρ lam hlam ℓ) - rw [he] - simp only [Q, Law.mu, offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam] - obtain ⟨R,hR,hlim⟩ := degrading_offspring_fixed_point Q C hf hs hl hl₀.le hl₁ ρ (fun _ ↦ rfl) - rw [poisson_fixed_mu_zero R hl₀ hl₁ d hd hcrit hR] at hlim - exact hlim - -theorem poisson_positive_nonreconstruction (d : ℝ≥0) (hd : 1 < (d:ℝ)) - (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 ≤ lam) (hKS : (d:ℝ)*lam^2 ≤ 1) : - Tendsto (advantage lam hlam (poissonPMF d)) atTop (𝓝 0) := by - have hdpos : 0 < (d:ℝ) := by linarith - let t : ℝ := 1/Real.sqrt d - have ht : 0 < t := by dsimp [t]; exact div_pos (by norm_num) (Real.sqrt_pos.mpr hdpos) - have htsq : (d:ℝ)*t^2 = 1 := by - dsimp [t] - rw [div_pow, one_pow, Real.sq_sqrt hdpos.le, mul_one_div_cancel (ne_of_gt hdpos)] - have htone : t < 1 := by - have h := mul_lt_mul_of_pos_right hd (sq_pos_of_pos ht) - nlinarith only [h, htsq, ht] - have htadm : Admissible t := ⟨by linarith, htone.le⟩ - have hlt : lam ≤ t := by - have hs : lam^2 ≤ t^2 := (mul_le_mul_iff_right₀ hdpos).mp (by nlinarith only [hKS,htsq]) - nlinarith only [hs,hl₀,ht] - let c := lam/t - have hcpos : 0 ≤ c := div_nonneg hl₀ ht.le - have hcone : c ≤ 1 := (div_le_one ht).2 hlt - have hcadm : Admissible c := ⟨by linarith, hcone⟩ - have he : t*c = lam := by dsimp [c]; field_simp - have hprod : Admissible (t*c) := he.symm ▸ hlam - let ρ := poissonPMF d - have hm := poisson_positive_critical_mu d hd ht htone htadm htsq - have hu : Tendsto (fun ℓ ↦ Real.sqrt (offspringPosteriorLaw ρ ht.le htone ℓ).mu) atTop (𝓝 0) := by - simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm - apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam ρ ℓ) _ hu - intro ℓ - apply (sq_le_sq₀ (advantage_nonneg lam hlam ρ ℓ) (Real.sqrt_nonneg _)).mp - rw [Real.sq_sqrt (offspringPosteriorLaw ρ ht.le htone ℓ).mu_nonneg] - have h := ordered_channel_mu_le ρ t c htadm hcadm hprod ℓ - have hw := ordered_advantage_sq_moment ρ lam hlam ℓ - have heq : orderedLaw ρ (t*c) hprod ℓ = orderedLaw ρ lam hlam ℓ := by congr 1 - rw [heq] at h - rw [← offspringPosteriorLaw_probability ρ ht.le htone htadm ℓ] at h - change _ ≤ (offspringPosteriorLaw ρ ht.le htone ℓ).mu at h - linarith [(offspringPosteriorLaw ρ ht.le htone ℓ).mu_nonneg] - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.OffspringLaws +import OAI.Probability.ThreeStateClauses.PoissonCalculus + +namespace OAI + +/-! Poisson Fixed. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability + +def uniformMessage : Message := ⟨fun _ ↦ 1, by norm_num, by norm_num [avg]⟩ + +lemma uniformMessage_x : xMoment uniformMessage = 0 := by norm_num [xMoment, momentX, centered, uniformMessage, avg] + +lemma branch_uniform (lam : ℝ) (n : ℕ) : + normalizer (branchEdges lam (fun _ : Fin n ↦ uniformMessage)) = 1 := by + norm_num [normalizer, branchEdges, branchProduct, edgeMessage, edge, centered, uniformMessage, avg] + +lemma branchOutput_uniform {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + branchOutput hl₀ hl₁ (fun _ : Fin n ↦ uniformMessage) = uniformMessage := by + apply Subtype.ext + funext i + norm_num [branchOutput, normalizedProduct, branch_uniform, branchProduct, branchEdges, + edgeMessage, edge, centered, uniformMessage, normalizer, avg] + +lemma finite_uniform_atom (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + (Q.probability.toMeasure {uniformMessage})^n ≤ + (finiteProbability Q hl₀ hl₁ n).toMeasure {uniformMessage} := by + change _ ≤ (Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) {uniformMessage} + rw [Measure.map_apply (continuous_branchOutput hl₀ hl₁ n).measurable (measurableSet_singleton _)] + have he : (tiltedProduct Q lam n) {fun _ : Fin n ↦ uniformMessage} = + (Q.probability.toMeasure {uniformMessage})^n := by + rw [tiltedProduct, withDensity_apply _ (measurableSet_singleton _), lintegral_singleton] + simp only [branch_uniform, ENNReal.ofReal_one, one_mul, Measure.pi_singleton, + Finset.prod_const, Finset.card_univ, Fintype.card_fin] + rw [← he] + apply measure_mono + intro m hm + rcases hm with rfl + exact branchOutput_uniform hl₀ hl₁ n + +lemma poisson_generating (t q : ℝ) : + HasSum (fun n ↦ poissonWeight t n*q^n) (Real.exp (t*(q-1))) := by + have hx : HasSum (fun n : ℕ ↦ (t*q)^n/(n.factorial:ℝ)) (Real.exp (t*q)) := by + rw [Real.exp_eq_exp_ℝ] + exact NormedSpace.expSeries_div_hasSum_exp (t*q) + have h := hx.mul_left (Real.exp (-t)) + have he : Real.exp (-t)*Real.exp (t*q) = Real.exp (t*(q-1)) := by + rw [← Real.exp_add]; congr 1; ring + rw [he] at h + have hf : (fun n : ℕ ↦ poissonWeight t n*q^n) = + (fun n ↦ Real.exp (-t)*((t*q)^n/(n.factorial:ℝ))) := by + funext n + dsimp [poissonWeight] + rw [mul_pow] + ring + rw [hf] + exact h + +lemma poisson_uniform_atom (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : + Real.exp ((t:ℝ)*((Q.probability.toMeasure {uniformMessage}).toReal-1)) ≤ + ((poissonLaw Q hl₀ hl₁ t).probability.toMeasure {uniformMessage}).toReal := by + let q := (Q.probability.toMeasure {uniformMessage}).toReal + have hq : 0 ≤ q := ENNReal.toReal_nonneg + have he : ENNReal.ofReal q = Q.probability.toMeasure {uniformMessage} := + ENNReal.ofReal_toReal (measure_ne_top _ _) + have h : ENNReal.ofReal (Real.exp ((t:ℝ)*(q-1))) ≤ + (poissonLaw Q hl₀ hl₁ t).probability.toMeasure {uniformMessage} := by + rw [← (poisson_generating t q).tsum_eq, ENNReal.ofReal_tsum_of_nonneg + (fun n ↦ mul_nonneg (poissonWeight_nonneg t.coe_nonneg n) (pow_nonneg hq n)) + (poisson_generating t q).summable] + change _ ≤ (Measure.sum (fun n ↦ (poissonPMF t) n • (finiteProbability Q hl₀ hl₁ n).toMeasure)) _ + rw [Measure.sum_apply _ (measurableSet_singleton _)] + apply ENNReal.tsum_le_tsum + intro n + rw [ENNReal.ofReal_mul (poissonWeight_nonneg t.coe_nonneg n), ENNReal.ofReal_pow hq, he, + ← poissonPMF_real, ENNReal.ofReal_toReal ((poissonPMF t).apply_ne_top n)] + exact mul_le_mul' le_rfl (finite_uniform_atom Q hl₀ hl₁ n) + have hh := ENNReal.toReal_mono (measure_ne_top _ _) h + rwa [ENNReal.toReal_ofReal (Real.exp_pos _).le] at hh + +def Law.nonuniformMass (Q : Law) : ℝ := 1-(Q.probability.toMeasure {uniformMessage}).toReal + +lemma Law.nonuniformMass_nonneg (Q : Law) : 0 ≤ Q.nonuniformMass := by + apply sub_nonneg.mpr + exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.one_ne_top).2 (prob_le_one) + +lemma Law.nonuniformMass_le_one (Q : Law) : Q.nonuniformMass ≤ 1 := by + unfold Law.nonuniformMass + exact sub_le_self _ ENNReal.toReal_nonneg + +lemma Law.nonuniform_second_moment (Q : Law) : Q.mu^2 ≤ Q.nonuniformMass*Q.nu := by + have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) + have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) + have hquad (a : ℝ) : 0 ≤ Q.nonuniformMass*(a*a)+(-2*Q.mu)*a+Q.nu := by + have h := integral_nonneg (μ := Q.probability.toMeasure.restrict {uniformMessage}ᶜ) + (f := fun m : Message ↦ (xMoment m-a)^2) (fun m ↦ sq_nonneg (xMoment m-a)) + rw [setIntegral_compl (f := fun m : Message ↦ (xMoment m-a)^2) (measurableSet_singleton _) + (compact_integrable ((continuous_xMoment.sub continuous_const).pow 2)), + integral_singleton, uniformMessage_x] at h + have hf : (fun m : Message ↦ (xMoment m-a)^2) = + (fun m ↦ xMoment m^2-2*a*xMoment m+a^2) := by funext m; ring + rw [hf, integral_add (f := fun m ↦ xMoment m^2-2*a*xMoment m) + (g := fun _ ↦ a^2) (hi₂.sub (hi.const_mul _)) (integrable_const _), + integral_sub (f := fun m : Message ↦ xMoment m^2) (g := fun m ↦ 2*a*xMoment m) hi₂ (hi.const_mul _), integral_const_mul] at h + simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, + smul_eq_mul, one_mul, zero_sub, neg_sq] at h + change 0 ≤ Q.nu-2*a*Q.mu+a^2-(Q.probability.toMeasure {uniformMessage}).toReal*a^2 at h + dsimp only [Law.nonuniformMass] + nlinarith only [h] + have h := discrim_le_zero hquad + dsimp only [discrim] at h + nlinarith only [h] + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set +namespace ThreeState.TreeClauses.Probability +open ThreeState.TreeClauses.Radial + +lemma neg_log_one_sub_lower {s : ℝ} (hs₀ : 0 ≤ s) (hs₁ : s < 1) : + 2*s/(2-s) ≤ -Real.log (1-s) := by + let f : ℝ → ℝ := fun t ↦ -Real.log (1-t)-2*t/(2-t) + let f' : ℝ → ℝ := fun t ↦ t^2/((1-t)*(2-t)^2) + have hd (t : ℝ) (ht : t ∈ Icc 0 s) : HasDerivAt f (f' t) t := by + have ht1 : 0 < 1-t := by linarith [ht.2] + have ht2 : 0 < 2-t := by linarith + apply (((((hasDerivAt_id t).const_sub 1).log (ne_of_gt ht1)).neg).sub + (((hasDerivAt_id t).const_mul 2).div ((hasDerivAt_id t).const_sub 2) (ne_of_gt ht2))).congr_deriv + dsimp only [f', id_eq] + field_simp + ring + have hm : MonotoneOn f (Icc 0 s) := by + apply monotoneOn_Icc_of_hasDerivAt_nonneg hd + intro t ht + dsimp only [f', id_eq] + have : 0 < 1-t := by linarith [ht.2] + positivity + have h := hm ⟨le_rfl,hs₀⟩ ⟨hs₀,le_rfl⟩ hs₀ + dsimp only [f] at h + norm_num at h + linarith only [h] + +lemma poisson_subfixed_mass_bound {d s : ℝ} (hd : 1 < d) (hs₀ : 0 ≤ s) + (hs : Real.exp (-d*s) ≤ 1-s) : s ≤ 2*(1-1/d) := by + have hs₁ : s < 1 := by linarith [Real.exp_pos (-d*s)] + have hlog : -Real.log (1-s) ≤ d*s := by + have h := Real.log_le_log (Real.exp_pos (-d*s)) hs + rw [Real.log_exp] at h + linarith only [h] + have hl := neg_log_one_sub_lower hs₀ hs₁ + have hden : 0 < 2-s := by linarith + have hmul := (div_le_iff₀ hden).mp (hl.trans hlog) + rcases eq_or_lt_of_le hs₀ with h | h + · have he : s = 0 := h.symm + rw [he] + have hdiv : 1/d < 1 := (div_lt_one (by linarith : 0 < d)).2 hd + linarith only [hdiv] + · have hh : 2 ≤ d*(2-s) := (mul_le_mul_iff_right₀ h).mp (by nlinarith only [hmul]) + have he : 2*(1-1/d) = (2*d-2)/d := by field_simp + rw [he] + apply (le_div_iff₀ (by linarith : 0 < d)).2 + nlinarith only [hh] + +end ThreeState.TreeClauses.Probability + +end + +noncomputable section +open Set MeasureTheory +open scoped NNReal +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability + +lemma poisson_fixed_mass_bound (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (d : ℝ≥0) (hd : 1 < (d:ℝ)) (hcrit : (d:ℝ)*lam^2 = 1) + (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : + Q.nonuniformMass ≤ 2*(1-lam^2) := by + have ha := poisson_uniform_atom Q hl₀.le hl₁ d + rw [← hfixed] at ha + have hsub : Real.exp (-(d:ℝ)*Q.nonuniformMass) ≤ 1-Q.nonuniformMass := by + calc + _ = Real.exp ((d:ℝ)*((Q.probability.toMeasure {uniformMessage}).toReal-1)) := by + congr 1; dsimp only [Law.nonuniformMass]; ring + _ ≤ (Q.probability.toMeasure {uniformMessage}).toReal := ha + _ = _ := by dsimp only [Law.nonuniformMass]; ring + have hs := poisson_subfixed_mass_bound hd Q.nonuniformMass_nonneg hsub + have he : 1/(d:ℝ) = lam^2 := (div_eq_iff (by positivity : (d:ℝ) ≠ 0)).2 (by nlinarith only [hcrit]) + rwa [he] at hs + +theorem poisson_fixed_mu_zero (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (d : ℝ≥0) (hd : 1 < (d:ℝ)) (hcrit : (d:ℝ)*lam^2 = 1) + (hfixed : Q.probability = (poissonLaw Q hl₀.le hl₁ d).probability) : Q.mu = 0 := by + by_contra hmu0 + have hmu : 0 < Q.mu := lt_of_le_of_ne Q.mu_nonneg (Ne.symm hmu0) + have hnu : 0 < Q.nu := (sq_pos_of_pos hmu).trans_le Q.second_moment_lower + have hmoment := Q.nonuniform_second_moment + have hs₀ : 0 < Q.nonuniformMass := by + by_contra h + have hh := mul_nonpos_of_nonpos_of_nonneg (le_of_not_gt h) hnu.le + nlinarith only [hmoment, hh, sq_pos_of_pos hmu] + have hinfo := poisson_fixed_moment_bounds Q hl₀ hl₁ d hcrit hfixed + have hcl := cExact_lower hl₀.le hl₁.le + have hc : 0 < cExact lam := (cLower_pos hl₀.le).trans_le hcl + have hetaNonneg : 0 ≤ Q.eta := (mul_nonneg hc.le hnu.le).trans hinfo.2.2 + have hsq : (cExact lam*Q.nu)^2 ≤ Q.eta^2 := + (sq_le_sq₀ (mul_nonneg hc.le hnu.le) hetaNonneg).2 hinfo.2.2 + have hregion : cExact lam^2*Q.nu ≤ Q.mu := by + apply (mul_le_mul_iff_right₀ hnu).mp + nlinarith [Q.moment_discriminant] + have hmuC : Q.mu*cExact lam^2 ≤ Q.nonuniformMass := by + apply (mul_le_mul_iff_right₀ hmu).mp + have hh := mul_le_mul_of_nonneg_left hmoment (sq_nonneg (cExact lam)) + have hh' := mul_le_mul_of_nonneg_left hregion hs₀.le + nlinarith only [hh, hh'] + have hregionLower : Q.mu*cLower lam^2 ≤ Q.nonuniformMass := by + have hs : cLower lam^2 ≤ cExact lam^2 := + (sq_le_sq₀ (cLower_pos hl₀.le).le hc.le).2 hcl + exact (mul_le_mul_of_nonneg_left hs hmu.le).trans hmuC + have hstrict := scalar_strict hl₀ hl₁ hmu.le hs₀ Q.nonuniformMass_le_one hregionLower + (Or.inr (poisson_fixed_mass_bound Q hl₀ hl₁ d hd hcrit hfixed)) + have hJ := jMean_square_bound hl₀.le hl₁.le hmu.le hnu.le hinfo.1 hinfo.2.1 hregion + have hH := poisson_fixed_correlation_bound Q hl₀ hl₁ d hcrit hfixed + have hrad := poisson_fixed_entropy_radial Q hl₀ hl₁ d hcrit hfixed + have hH' : 3*Q.mu^2/(2*(1+2*Q.mu/3))-(1/Real.sqrt 2)*(lam*Q.mu*Q.nu) ≤ + 3*poissonCorrelation Q hl₀.le hl₁ d := by + convert hH using 1 + ring + have hg := mul_le_mul_of_nonneg_right (le_of_lt strict_correlation_coefficient) + (show 0 ≤ lam*Q.mu*Q.nu by positivity) + have hb₀ : (1-lam^2)/2*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3))+ + (17/25)*lam*Q.mu*Q.nu ≤ (8/5)*Q.mu^2 := by + nlinarith only [hJ,hH',hrad,hg] + have hb : ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) ≤ + (8/5)*Q.mu^2 := by nlinarith only [hb₀] + have halpha : 0 < 1-lam^2 := by nlinarith only [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] + have hcoef : 0 ≤ ((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass := by positivity + have hsub := mul_le_mul_of_nonneg_left hmoment hcoef + have hnecessary : scalarT lam Q.mu Q.nonuniformMass*Q.mu^2 ≤ (8/5)*Q.mu^2 := by + calc + _ = (((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass)*Q.mu^2+ + 3*Q.mu^2/(2*(1+2*Q.mu/3)) := by unfold scalarT; ring + _ ≤ (((1-lam^2)/2+17*lam*Q.mu/25)/Q.nonuniformMass)*(Q.nonuniformMass*Q.nu)+ + 3*Q.mu^2/(2*(1+2*Q.mu/3)) := by linarith only [hsub] + _ = ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by + field_simp [ne_of_gt hs₀] + _ ≤ _ := hb + have hh := mul_lt_mul_of_pos_right hstrict (sq_pos_of_pos hmu) + linarith only [hh,hnecessary] + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped Topology NNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma ordered_advantage_sq_moment (ρ : PMF ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) : + (advantage lam hlam ρ ℓ)^2 ≤ + (∫ m, xMoment m ∂(discreteProbability (orderedLaw ρ lam hlam ℓ)).toMeasure)/2 := by + have h := discrete_degradation_mu (orderedLaw ρ lam hlam ℓ) (fun v ↦ PMF.pure (forgetOrdered ℓ v)) + change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ + (orderedLaw ρ lam hlam ℓ i).map (forgetOrdered ℓ))).toMeasure) ≤ _ at h + simp only [orderedLaw_forget] at h + have ha := advantage_sq_bound lam hlam ρ ℓ + linarith + +lemma poisson_positive_critical_mu (d : ℝ≥0) (hd : 1 < (d:ℝ)) {lam : ℝ} + (hl₀ : 0 < lam) (hl₁ : lam < 1) (hlam : Admissible lam) (hcrit : (d:ℝ)*lam^2 = 1) : + Tendsto (fun ℓ ↦ (offspringPosteriorLaw (poissonPMF d) hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by + let ρ := poissonPMF d + let Q := offspringPosteriorLaw ρ hl₀.le hl₁ + let C := fun ℓ ↦ degradationCoupling (orderedLaw ρ lam hlam ℓ) (orderedExpansion ρ lam hlam ℓ) + have hf (ℓ : ℕ) : (C ℓ).map Prod.fst = (Q ℓ).probability := by + rw [degradationCoupling_fst, offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam ℓ] + have hs (ℓ : ℕ) : (C ℓ).map Prod.snd = (Q (ℓ+1)).probability := by + rw [degradationCoupling_snd] + have he : (fun i ↦ (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ)) = + orderedLaw ρ lam hlam (ℓ+1) := funext (orderedLaw_degrades ρ lam hlam ℓ) + rw [he] + exact (offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam (ℓ+1)).symm + have hl (ℓ : ℕ) : (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu := by + rw [degradationCoupling_loss] + have he : (fun i ↦ (orderedLaw ρ lam hlam ℓ i).bind (orderedExpansion ρ lam hlam ℓ)) = + orderedLaw ρ lam hlam (ℓ+1) := funext (orderedLaw_degrades ρ lam hlam ℓ) + rw [he] + simp only [Q, Law.mu, offspringPosteriorLaw_probability ρ hl₀.le hl₁ hlam] + obtain ⟨R,hR,hlim⟩ := degrading_offspring_fixed_point Q C hf hs hl hl₀.le hl₁ ρ (fun _ ↦ rfl) + rw [poisson_fixed_mu_zero R hl₀ hl₁ d hd hcrit hR] at hlim + exact hlim + +theorem poisson_positive_nonreconstruction (d : ℝ≥0) (hd : 1 < (d:ℝ)) + (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 ≤ lam) (hKS : (d:ℝ)*lam^2 ≤ 1) : + Tendsto (advantage lam hlam (poissonPMF d)) atTop (𝓝 0) := by + have hdpos : 0 < (d:ℝ) := by linarith + let t : ℝ := 1/Real.sqrt d + have ht : 0 < t := by dsimp [t]; exact div_pos (by norm_num) (Real.sqrt_pos.mpr hdpos) + have htsq : (d:ℝ)*t^2 = 1 := by + dsimp [t] + rw [div_pow, one_pow, Real.sq_sqrt hdpos.le, mul_one_div_cancel (ne_of_gt hdpos)] + have htone : t < 1 := by + have h := mul_lt_mul_of_pos_right hd (sq_pos_of_pos ht) + nlinarith only [h, htsq, ht] + have htadm : Admissible t := ⟨by linarith, htone.le⟩ + have hlt : lam ≤ t := by + have hs : lam^2 ≤ t^2 := (mul_le_mul_iff_right₀ hdpos).mp (by nlinarith only [hKS,htsq]) + nlinarith only [hs,hl₀,ht] + let c := lam/t + have hcpos : 0 ≤ c := div_nonneg hl₀ ht.le + have hcone : c ≤ 1 := (div_le_one ht).2 hlt + have hcadm : Admissible c := ⟨by linarith, hcone⟩ + have he : t*c = lam := by dsimp [c]; field_simp + have hprod : Admissible (t*c) := he.symm ▸ hlam + let ρ := poissonPMF d + have hm := poisson_positive_critical_mu d hd ht htone htadm htsq + have hu : Tendsto (fun ℓ ↦ Real.sqrt (offspringPosteriorLaw ρ ht.le htone ℓ).mu) atTop (𝓝 0) := by + simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm + apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam ρ ℓ) _ hu + intro ℓ + apply (sq_le_sq₀ (advantage_nonneg lam hlam ρ ℓ) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt (offspringPosteriorLaw ρ ht.le htone ℓ).mu_nonneg] + have h := ordered_channel_mu_le ρ t c htadm hcadm hprod ℓ + have hw := ordered_advantage_sq_moment ρ lam hlam ℓ + have heq : orderedLaw ρ (t*c) hprod ℓ = orderedLaw ρ lam hlam ℓ := by congr 1 + rw [heq] at h + rw [← offspringPosteriorLaw_probability ρ ht.le htone htadm ℓ] at h + change _ ≤ (offspringPosteriorLaw ρ ht.le htone ℓ).mu at h + linarith [(offspringPosteriorLaw ρ ht.le htone ℓ).mu_nonneg] + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PoissonLaw.lean b/lean/OAI/Probability/ThreeStateClauses/PoissonLaw.lean index bde325a6268509eae38590a1b4934d455a7e95a6..a256e603de4ccbacaf884da5f7e84211b35e0dd1 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PoissonLaw.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PoissonLaw.lean @@ -1,136 +1,136 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.BranchGrowth -import OAI.Probability.ThreeStateClauses.ObservedMixtures -import OAI.Probability.ThreeStateClauses.PoissonMoments - -namespace OAI - -/-! Poisson Law. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory ProbabilityTheory -open scoped BigOperators NNReal -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability - -def poissonLaw (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : Law := - offspringLaw (poissonPMF t) Q hl₀ hl₁ - -lemma mixture_mu (ρ : PMF ℕ) (Q : ℕ → Law) : - (mixtureLaw ρ Q).mu = ∫ n, (Q n).mu ∂ρ.toMeasure := by - change (∫ m, xMoment m ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = _ - rw [integral_mixtureProbability _ _ (compact_integrable continuous_xMoment), - PMF.integral_eq_tsum _ _ (pmf_bounded_integrable ρ (fun n ↦ show |(Q n).mu| ≤ 1 by - rw [abs_of_nonneg (Q n).mu_nonneg]; exact (Q n).mu_le_one))] - rfl - -lemma Law.nu_le_one (Q : Law) : Q.nu ≤ 1 := by - apply (integral_mono (compact_integrable (continuous_xMoment.pow 2)) (integrable_const (1:ℝ)) _).trans_eq - (by simp) - intro m - change xMoment m^2 ≤ 1 - nlinarith [xMoment_nonneg m, xMoment_le_one m] - -lemma mixture_nu (ρ : PMF ℕ) (Q : ℕ → Law) : - (mixtureLaw ρ Q).nu = ∫ n, (Q n).nu ∂ρ.toMeasure := by - change (∫ m, xMoment m^2 ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = _ - rw [integral_mixtureProbability _ _ (f := fun m ↦ xMoment m^2) (compact_integrable (continuous_xMoment.pow 2)), - PMF.integral_eq_tsum _ _ (pmf_bounded_integrable ρ (fun n ↦ show |(Q n).nu| ≤ 1 by - rw [abs_of_nonneg (Q n).nu_nonneg]; exact (Q n).nu_le_one))] - rfl - -private lemma poisson_quadratic_integral (t : ℝ≥0) (b a : ℝ) (M : ℕ → ℝ) - (hM : Integrable M (poissonPMF t).toMeasure) : - (∫ n : ℕ, (2*n*b+2*((n:ℝ)^2-n)*b^2)*(a*a)+(-4*n*b)*a+2*M n - ∂(poissonPMF t).toMeasure) = - (2*t*b+2*(t:ℝ)^2*b^2)*(a*a)+(-4*t*b)*a+2*(∫ n, M n ∂(poissonPMF t).toMeasure) := by - have hn := poisson_integrable_first t - have hn₂ := poisson_integrable_second t - have he (n : ℕ) : (2*n*b+2*((n:ℝ)^2-n)*b^2)*(a*a)+(-4*n*b)*a+2*M n = - (2*b*(a*a)-4*b*a)*(n:ℝ)+(2*b^2*(a*a))*((n:ℝ)^2-n)+2*M n := by ring - let A : ℝ := 2*b*(a*a)-4*b*a - let B : ℝ := 2*b^2*(a*a) - have hA : Integrable (fun n : ℕ ↦ A*(n:ℝ)) (poissonPMF t).toMeasure := hn.const_mul A - have hB : Integrable (fun n : ℕ ↦ B*((n:ℝ)^2-n)) (poissonPMF t).toMeasure := (hn₂.sub hn).const_mul B - calc - _ = ∫ n : ℕ, (A*(n:ℝ)+B*((n:ℝ)^2-n))+2*M n ∂(poissonPMF t).toMeasure := - integral_congr_ae (Filter.Eventually.of_forall he) - _ = (∫ n : ℕ, A*(n:ℝ)+B*((n:ℝ)^2-n) ∂(poissonPMF t).toMeasure)+ - (∫ n, 2*M n ∂(poissonPMF t).toMeasure) := integral_add (hA.add hB) (hM.const_mul 2) - _ = A*(t:ℝ)+B*(t:ℝ)^2+2*(∫ n, M n ∂(poissonPMF t).toMeasure) := by - rw [integral_add hA hB, integral_const_mul, integral_const_mul, integral_const_mul, - poisson_integral_first, poisson_integral_factorial_second] - _ = _ := by dsimp only [A,B]; ring - -lemma poisson_projection_quadratic (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (t : ℝ≥0) (a : ℝ) : - 0 ≤ (2*t*(lam^2*Q.mu)+2*(t:ℝ)^2*(lam^2*Q.mu)^2)*(a*a)+ - (-4*t*(lam^2*Q.mu))*a+2*(poissonLaw Q hl₀ hl₁ t).mu := by - have hmu := pmf_bounded_integrable (poissonPMF t) - (fun n ↦ show |(finiteLaw Q hl₀ hl₁ n).mu| ≤ 1 by - rw [abs_of_nonneg (finiteLaw Q hl₀ hl₁ n).mu_nonneg]; exact (finiteLaw Q hl₀ hl₁ n).mu_le_one) - have h := integral_nonneg (μ := (poissonPMF t).toMeasure) - (f := fun n : ℕ ↦ (2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2)*(a*a)+ - (-4*n*(lam^2*Q.mu))*a+2*(finiteLaw Q hl₀ hl₁ n).mu) - (fun n ↦ finite_projection_quadratic Q hl₀ hl₁ n a) - rw [poisson_quadratic_integral t (lam^2*Q.mu) a _ hmu] at h - have hm : (∫ n, (finiteLaw Q hl₀ hl₁ n).mu ∂(poissonPMF t).toMeasure) = - (poissonLaw Q hl₀ hl₁ t).mu := (mixture_mu _ _).symm - rwa [hm] at h - -theorem poisson_projection (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : - (t:ℝ)*(lam^2*Q.mu)/(1+(t:ℝ)*(lam^2*Q.mu)) ≤ (poissonLaw Q hl₀ hl₁ t).mu := by - let β := lam^2*Q.mu - have hb : 0 ≤ β := mul_nonneg (sq_nonneg _) Q.mu_nonneg - have ht : 0 ≤ (t:ℝ) := t.coe_nonneg - have hd : 0 < 1+(t:ℝ)*β := by positivity - have h := poisson_projection_quadratic Q hl₀ hl₁ t (1/(1+(t:ℝ)*β)) - change 0 ≤ (2*t*β+2*(t:ℝ)^2*β^2)*(1/(1+(t:ℝ)*β)*(1/(1+(t:ℝ)*β)))+ - (-4*t*β)*(1/(1+(t:ℝ)*β))+2*(poissonLaw Q hl₀ hl₁ t).mu at h - have he : (2*t*β+2*(t:ℝ)^2*β^2)*(1/(1+(t:ℝ)*β)*(1/(1+(t:ℝ)*β)))+ - (-4*t*β)*(1/(1+(t:ℝ)*β)) = -2*((t:ℝ)*β/(1+(t:ℝ)*β)) := by - field_simp; ring - rw [he] at h - linarith - -lemma poisson_integral_mono_intensity {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) - (hf : Monotone f) {s t : ℝ≥0} (hst : s ≤ t) : - (∫ n, f n ∂(poissonPMF s).toMeasure) ≤ ∫ n, f n ∂(poissonPMF t).toMeasure := by - have hts : s+(t-s) = t := add_tsub_cancel_of_le hst - have hi : Integrable f (poissonMeasure s ∗ poissonMeasure (t-s)) := by - rw [poissonMeasure_conv_poissonMeasure, hts, ← poissonPMF_toMeasure] - exact pmf_bounded_integrable _ hB - rw [poissonPMF_toMeasure, poissonPMF_toMeasure, ← hts, ← poissonMeasure_conv_poissonMeasure, - integral_conv hi] - apply integral_mono (by rw [← poissonPMF_toMeasure]; exact pmf_bounded_integrable _ hB) - · apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable B - exact Filter.Eventually.of_forall (fun n ↦ by - rw [Real.norm_eq_abs] - apply (abs_integral_le_integral_abs).trans - apply (integral_mono (by rw [← poissonPMF_toMeasure]; exact (pmf_bounded_integrable _ (fun m ↦ hB (n+m))).abs) - (integrable_const _) (fun m ↦ hB (n+m))).trans_eq - simp) - · intro n - calc - f n = ∫ _, f n ∂poissonMeasure (t-s) := by simp - _ ≤ _ := integral_mono (integrable_const _) (by - rw [← poissonPMF_toMeasure]; exact pmf_bounded_integrable _ (fun m ↦ hB (n+m))) - (fun m ↦ hf (Nat.le_add_right n m)) - -lemma poisson_nu_mono (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - {s t : ℝ≥0} (hst : s ≤ t) : - (poissonLaw Q hl₀ hl₁ s).nu ≤ (poissonLaw Q hl₀ hl₁ t).nu := by - change (mixtureLaw _ _).nu ≤ (mixtureLaw _ _).nu - rw [mixture_nu, mixture_nu] - apply poisson_integral_mono_intensity (B := 1) _ (fun _ _ h ↦ finite_nu_mono Q hl₀ hl₁ h) hst - intro n - rw [abs_of_nonneg (finiteLaw Q hl₀ hl₁ n).nu_nonneg] - exact (finiteLaw Q hl₀ hl₁ n).nu_le_one - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.BranchGrowth +import OAI.Probability.ThreeStateClauses.ObservedMixtures +import OAI.Probability.ThreeStateClauses.PoissonMoments + +namespace OAI + +/-! Poisson Law. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive ThreeState.TreeClauses.Probability + +def poissonLaw (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : Law := + offspringLaw (poissonPMF t) Q hl₀ hl₁ + +lemma mixture_mu (ρ : PMF ℕ) (Q : ℕ → Law) : + (mixtureLaw ρ Q).mu = ∫ n, (Q n).mu ∂ρ.toMeasure := by + change (∫ m, xMoment m ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = _ + rw [integral_mixtureProbability _ _ (compact_integrable continuous_xMoment), + PMF.integral_eq_tsum _ _ (pmf_bounded_integrable ρ (fun n ↦ show |(Q n).mu| ≤ 1 by + rw [abs_of_nonneg (Q n).mu_nonneg]; exact (Q n).mu_le_one))] + rfl + +lemma Law.nu_le_one (Q : Law) : Q.nu ≤ 1 := by + apply (integral_mono (compact_integrable (continuous_xMoment.pow 2)) (integrable_const (1:ℝ)) _).trans_eq + (by simp) + intro m + change xMoment m^2 ≤ 1 + nlinarith [xMoment_nonneg m, xMoment_le_one m] + +lemma mixture_nu (ρ : PMF ℕ) (Q : ℕ → Law) : + (mixtureLaw ρ Q).nu = ∫ n, (Q n).nu ∂ρ.toMeasure := by + change (∫ m, xMoment m^2 ∂(mixtureProbability ρ (fun n ↦ (Q n).probability)).toMeasure) = _ + rw [integral_mixtureProbability _ _ (f := fun m ↦ xMoment m^2) (compact_integrable (continuous_xMoment.pow 2)), + PMF.integral_eq_tsum _ _ (pmf_bounded_integrable ρ (fun n ↦ show |(Q n).nu| ≤ 1 by + rw [abs_of_nonneg (Q n).nu_nonneg]; exact (Q n).nu_le_one))] + rfl + +private lemma poisson_quadratic_integral (t : ℝ≥0) (b a : ℝ) (M : ℕ → ℝ) + (hM : Integrable M (poissonPMF t).toMeasure) : + (∫ n : ℕ, (2*n*b+2*((n:ℝ)^2-n)*b^2)*(a*a)+(-4*n*b)*a+2*M n + ∂(poissonPMF t).toMeasure) = + (2*t*b+2*(t:ℝ)^2*b^2)*(a*a)+(-4*t*b)*a+2*(∫ n, M n ∂(poissonPMF t).toMeasure) := by + have hn := poisson_integrable_first t + have hn₂ := poisson_integrable_second t + have he (n : ℕ) : (2*n*b+2*((n:ℝ)^2-n)*b^2)*(a*a)+(-4*n*b)*a+2*M n = + (2*b*(a*a)-4*b*a)*(n:ℝ)+(2*b^2*(a*a))*((n:ℝ)^2-n)+2*M n := by ring + let A : ℝ := 2*b*(a*a)-4*b*a + let B : ℝ := 2*b^2*(a*a) + have hA : Integrable (fun n : ℕ ↦ A*(n:ℝ)) (poissonPMF t).toMeasure := hn.const_mul A + have hB : Integrable (fun n : ℕ ↦ B*((n:ℝ)^2-n)) (poissonPMF t).toMeasure := (hn₂.sub hn).const_mul B + calc + _ = ∫ n : ℕ, (A*(n:ℝ)+B*((n:ℝ)^2-n))+2*M n ∂(poissonPMF t).toMeasure := + integral_congr_ae (Filter.Eventually.of_forall he) + _ = (∫ n : ℕ, A*(n:ℝ)+B*((n:ℝ)^2-n) ∂(poissonPMF t).toMeasure)+ + (∫ n, 2*M n ∂(poissonPMF t).toMeasure) := integral_add (hA.add hB) (hM.const_mul 2) + _ = A*(t:ℝ)+B*(t:ℝ)^2+2*(∫ n, M n ∂(poissonPMF t).toMeasure) := by + rw [integral_add hA hB, integral_const_mul, integral_const_mul, integral_const_mul, + poisson_integral_first, poisson_integral_factorial_second] + _ = _ := by dsimp only [A,B]; ring + +lemma poisson_projection_quadratic (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (t : ℝ≥0) (a : ℝ) : + 0 ≤ (2*t*(lam^2*Q.mu)+2*(t:ℝ)^2*(lam^2*Q.mu)^2)*(a*a)+ + (-4*t*(lam^2*Q.mu))*a+2*(poissonLaw Q hl₀ hl₁ t).mu := by + have hmu := pmf_bounded_integrable (poissonPMF t) + (fun n ↦ show |(finiteLaw Q hl₀ hl₁ n).mu| ≤ 1 by + rw [abs_of_nonneg (finiteLaw Q hl₀ hl₁ n).mu_nonneg]; exact (finiteLaw Q hl₀ hl₁ n).mu_le_one) + have h := integral_nonneg (μ := (poissonPMF t).toMeasure) + (f := fun n : ℕ ↦ (2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2)*(a*a)+ + (-4*n*(lam^2*Q.mu))*a+2*(finiteLaw Q hl₀ hl₁ n).mu) + (fun n ↦ finite_projection_quadratic Q hl₀ hl₁ n a) + rw [poisson_quadratic_integral t (lam^2*Q.mu) a _ hmu] at h + have hm : (∫ n, (finiteLaw Q hl₀ hl₁ n).mu ∂(poissonPMF t).toMeasure) = + (poissonLaw Q hl₀ hl₁ t).mu := (mixture_mu _ _).symm + rwa [hm] at h + +theorem poisson_projection (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (t : ℝ≥0) : + (t:ℝ)*(lam^2*Q.mu)/(1+(t:ℝ)*(lam^2*Q.mu)) ≤ (poissonLaw Q hl₀ hl₁ t).mu := by + let β := lam^2*Q.mu + have hb : 0 ≤ β := mul_nonneg (sq_nonneg _) Q.mu_nonneg + have ht : 0 ≤ (t:ℝ) := t.coe_nonneg + have hd : 0 < 1+(t:ℝ)*β := by positivity + have h := poisson_projection_quadratic Q hl₀ hl₁ t (1/(1+(t:ℝ)*β)) + change 0 ≤ (2*t*β+2*(t:ℝ)^2*β^2)*(1/(1+(t:ℝ)*β)*(1/(1+(t:ℝ)*β)))+ + (-4*t*β)*(1/(1+(t:ℝ)*β))+2*(poissonLaw Q hl₀ hl₁ t).mu at h + have he : (2*t*β+2*(t:ℝ)^2*β^2)*(1/(1+(t:ℝ)*β)*(1/(1+(t:ℝ)*β)))+ + (-4*t*β)*(1/(1+(t:ℝ)*β)) = -2*((t:ℝ)*β/(1+(t:ℝ)*β)) := by + field_simp; ring + rw [he] at h + linarith + +lemma poisson_integral_mono_intensity {f : ℕ → ℝ} {B : ℝ} (hB : ∀ n, |f n| ≤ B) + (hf : Monotone f) {s t : ℝ≥0} (hst : s ≤ t) : + (∫ n, f n ∂(poissonPMF s).toMeasure) ≤ ∫ n, f n ∂(poissonPMF t).toMeasure := by + have hts : s+(t-s) = t := add_tsub_cancel_of_le hst + have hi : Integrable f (poissonMeasure s ∗ poissonMeasure (t-s)) := by + rw [poissonMeasure_conv_poissonMeasure, hts, ← poissonPMF_toMeasure] + exact pmf_bounded_integrable _ hB + rw [poissonPMF_toMeasure, poissonPMF_toMeasure, ← hts, ← poissonMeasure_conv_poissonMeasure, + integral_conv hi] + apply integral_mono (by rw [← poissonPMF_toMeasure]; exact pmf_bounded_integrable _ hB) + · apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable B + exact Filter.Eventually.of_forall (fun n ↦ by + rw [Real.norm_eq_abs] + apply (abs_integral_le_integral_abs).trans + apply (integral_mono (by rw [← poissonPMF_toMeasure]; exact (pmf_bounded_integrable _ (fun m ↦ hB (n+m))).abs) + (integrable_const _) (fun m ↦ hB (n+m))).trans_eq + simp) + · intro n + calc + f n = ∫ _, f n ∂poissonMeasure (t-s) := by simp + _ ≤ _ := integral_mono (integrable_const _) (by + rw [← poissonPMF_toMeasure]; exact pmf_bounded_integrable _ (fun m ↦ hB (n+m))) + (fun m ↦ hf (Nat.le_add_right n m)) + +lemma poisson_nu_mono (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + {s t : ℝ≥0} (hst : s ≤ t) : + (poissonLaw Q hl₀ hl₁ s).nu ≤ (poissonLaw Q hl₀ hl₁ t).nu := by + change (mixtureLaw _ _).nu ≤ (mixtureLaw _ _).nu + rw [mixture_nu, mixture_nu] + apply poisson_integral_mono_intensity (B := 1) _ (fun _ _ h ↦ finite_nu_mono Q hl₀ hl₁ h) hst + intro n + rw [abs_of_nonneg (finiteLaw Q hl₀ hl₁ n).nu_nonneg] + exact (finiteLaw Q hl₀ hl₁ n).nu_le_one + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PoissonMoments.lean b/lean/OAI/Probability/ThreeStateClauses/PoissonMoments.lean index d116d6a39108924a13b2e6ae43823be5d0aec6e5..c6ccfca4d36bb6e4d57d7d0d169a6f5bafb069e2 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PoissonMoments.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PoissonMoments.lean @@ -1,98 +1,98 @@ -import Mathlib - -namespace OAI - -/-! Poisson Moments. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open MeasureTheory ProbabilityTheory -open scoped BigOperators NNReal -namespace ThreeState.TreeClauses.Probability - -def poissonWeight (t : ℝ) (n : ℕ) : ℝ := Real.exp (-t)*t^n/(n.factorial:ℝ) - -lemma poissonWeight_nonneg {t : ℝ} (ht : 0 ≤ t) (n : ℕ) : 0 ≤ poissonWeight t n := by - unfold poissonWeight; positivity - -lemma poissonWeight_mass (t : ℝ≥0) : HasSum (poissonWeight t) 1 := - hasSum_one_poissonMeasure t - -def _root_.OAI.ThreeState.TreeClauses.poissonPMF (rate : ℝ≥0) : PMF ℕ := by - refine ⟨fun count ↦ ENNReal.ofReal (poissonWeight rate count), ?_⟩ - apply ENNReal.hasSum_coe.mpr - rw [← Real.toNNReal_one] - exact (poissonWeight_mass rate).toNNReal (poissonWeight_nonneg rate.coe_nonneg) - -lemma poissonWeight_succ (t : ℝ) (n : ℕ) : - poissonWeight t (n+1)*((n:ℝ)+1) = t*poissonWeight t n := by - unfold poissonWeight - rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, pow_succ] - have hn : (n:ℝ)+1 ≠ 0 := by positivity - field_simp - -lemma poissonWeight_mean (t : ℝ≥0) : HasSum (fun n ↦ poissonWeight t n*(n:ℝ)) t := by - apply (hasSum_nat_add_iff' 1).mp - simp only [Finset.range_one, Finset.sum_singleton, Nat.cast_zero, mul_zero, sub_zero, - Nat.cast_add, Nat.cast_one, poissonWeight_succ] - simpa using (poissonWeight_mass t).mul_left (t:ℝ) - -lemma poissonWeight_factorial_second (t : ℝ≥0) : - HasSum (fun n ↦ poissonWeight t n*((n:ℝ)^2-n)) ((t:ℝ)^2) := by - apply (hasSum_nat_add_iff' 1).mp - simp only [Finset.range_one, Finset.sum_singleton, Nat.cast_zero, zero_pow (by decide : 2 ≠ 0), - sub_self, mul_zero, sub_zero] - have he (n : ℕ) : poissonWeight t (n+1)*(((n+1:ℕ):ℝ)^2-((n+1:ℕ):ℝ)) = - (t:ℝ)*(poissonWeight t n*(n:ℝ)) := by - push_cast - calc - _ = (poissonWeight t (n+1)*((n:ℝ)+1))*(n:ℝ) := by ring - _ = _ := by rw [poissonWeight_succ]; ring - simp_rw [he] - simpa [pow_two] using (poissonWeight_mean t).mul_left (t:ℝ) - -lemma poissonWeight_second (t : ℝ≥0) : - HasSum (fun n ↦ poissonWeight t n*(n:ℝ)^2) ((t:ℝ)^2+t) := by - have h := (poissonWeight_factorial_second t).add (poissonWeight_mean t) - convert h using 1 - ext n; ring - -lemma poissonPMF_real (t : ℝ≥0) (n : ℕ) : (poissonPMF t n).toReal = poissonWeight t n := by - change (ENNReal.ofReal (poissonWeight t n)).toReal = _ - exact ENNReal.toReal_ofReal (poissonWeight_nonneg t.coe_nonneg n) - -lemma poissonPMF_toMeasure (t : ℝ≥0) : (poissonPMF t).toMeasure = poissonMeasure t := by - apply Measure.ext_of_singleton - intro n - rw [PMF.toMeasure_apply_singleton, poissonMeasure_singleton] - · rfl - · exact measurableSet_singleton n - -lemma poisson_integrable_first (t : ℝ≥0) : Integrable (fun n : ℕ ↦ (n:ℝ)) (poissonPMF t).toMeasure := by - rw [poissonPMF_toMeasure, integrable_poissonMeasure_iff] - simpa only [Real.norm_eq_abs, Nat.abs_cast, smul_eq_mul, poissonWeight] using (poissonWeight_mean t).summable - -lemma poisson_integrable_second (t : ℝ≥0) : Integrable (fun n : ℕ ↦ (n:ℝ)^2) (poissonPMF t).toMeasure := by - rw [poissonPMF_toMeasure, integrable_poissonMeasure_iff] - simpa only [Real.norm_eq_abs, abs_pow, Nat.abs_cast, smul_eq_mul, poissonWeight] using (poissonWeight_second t).summable - -lemma poisson_integral_first (t : ℝ≥0) : (∫ n : ℕ, (n:ℝ) ∂(poissonPMF t).toMeasure) = t := by - rw [PMF.integral_eq_tsum _ _ (poisson_integrable_first t)] - simpa only [poissonPMF_real, smul_eq_mul] using (poissonWeight_mean t).tsum_eq - -lemma poisson_integral_second (t : ℝ≥0) : (∫ n : ℕ, (n:ℝ)^2 ∂(poissonPMF t).toMeasure) = (t:ℝ)^2+t := by - rw [PMF.integral_eq_tsum _ _ (poisson_integrable_second t)] - simpa only [poissonPMF_real, smul_eq_mul] using (poissonWeight_second t).tsum_eq - -lemma poisson_integral_factorial_second (t : ℝ≥0) : - (∫ n : ℕ, ((n:ℝ)^2-n) ∂(poissonPMF t).toMeasure) = (t:ℝ)^2 := by - rw [integral_sub (poisson_integrable_second t) (poisson_integrable_first t), - poisson_integral_second, poisson_integral_first] - ring - -end ThreeState.TreeClauses.Probability - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Poisson Moments. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal +namespace ThreeState.TreeClauses.Probability + +def poissonWeight (t : ℝ) (n : ℕ) : ℝ := Real.exp (-t)*t^n/(n.factorial:ℝ) + +lemma poissonWeight_nonneg {t : ℝ} (ht : 0 ≤ t) (n : ℕ) : 0 ≤ poissonWeight t n := by + unfold poissonWeight; positivity + +lemma poissonWeight_mass (t : ℝ≥0) : HasSum (poissonWeight t) 1 := + hasSum_one_poissonMeasure t + +def _root_.OAI.ThreeState.TreeClauses.poissonPMF (rate : ℝ≥0) : PMF ℕ := by + refine ⟨fun count ↦ ENNReal.ofReal (poissonWeight rate count), ?_⟩ + apply ENNReal.hasSum_coe.mpr + rw [← Real.toNNReal_one] + exact (poissonWeight_mass rate).toNNReal (poissonWeight_nonneg rate.coe_nonneg) + +lemma poissonWeight_succ (t : ℝ) (n : ℕ) : + poissonWeight t (n+1)*((n:ℝ)+1) = t*poissonWeight t n := by + unfold poissonWeight + rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, pow_succ] + have hn : (n:ℝ)+1 ≠ 0 := by positivity + field_simp + +lemma poissonWeight_mean (t : ℝ≥0) : HasSum (fun n ↦ poissonWeight t n*(n:ℝ)) t := by + apply (hasSum_nat_add_iff' 1).mp + simp only [Finset.range_one, Finset.sum_singleton, Nat.cast_zero, mul_zero, sub_zero, + Nat.cast_add, Nat.cast_one, poissonWeight_succ] + simpa using (poissonWeight_mass t).mul_left (t:ℝ) + +lemma poissonWeight_factorial_second (t : ℝ≥0) : + HasSum (fun n ↦ poissonWeight t n*((n:ℝ)^2-n)) ((t:ℝ)^2) := by + apply (hasSum_nat_add_iff' 1).mp + simp only [Finset.range_one, Finset.sum_singleton, Nat.cast_zero, zero_pow (by decide : 2 ≠ 0), + sub_self, mul_zero, sub_zero] + have he (n : ℕ) : poissonWeight t (n+1)*(((n+1:ℕ):ℝ)^2-((n+1:ℕ):ℝ)) = + (t:ℝ)*(poissonWeight t n*(n:ℝ)) := by + push_cast + calc + _ = (poissonWeight t (n+1)*((n:ℝ)+1))*(n:ℝ) := by ring + _ = _ := by rw [poissonWeight_succ]; ring + simp_rw [he] + simpa [pow_two] using (poissonWeight_mean t).mul_left (t:ℝ) + +lemma poissonWeight_second (t : ℝ≥0) : + HasSum (fun n ↦ poissonWeight t n*(n:ℝ)^2) ((t:ℝ)^2+t) := by + have h := (poissonWeight_factorial_second t).add (poissonWeight_mean t) + convert h using 1 + ext n; ring + +lemma poissonPMF_real (t : ℝ≥0) (n : ℕ) : (poissonPMF t n).toReal = poissonWeight t n := by + change (ENNReal.ofReal (poissonWeight t n)).toReal = _ + exact ENNReal.toReal_ofReal (poissonWeight_nonneg t.coe_nonneg n) + +lemma poissonPMF_toMeasure (t : ℝ≥0) : (poissonPMF t).toMeasure = poissonMeasure t := by + apply Measure.ext_of_singleton + intro n + rw [PMF.toMeasure_apply_singleton, poissonMeasure_singleton] + · rfl + · exact measurableSet_singleton n + +lemma poisson_integrable_first (t : ℝ≥0) : Integrable (fun n : ℕ ↦ (n:ℝ)) (poissonPMF t).toMeasure := by + rw [poissonPMF_toMeasure, integrable_poissonMeasure_iff] + simpa only [Real.norm_eq_abs, Nat.abs_cast, smul_eq_mul, poissonWeight] using (poissonWeight_mean t).summable + +lemma poisson_integrable_second (t : ℝ≥0) : Integrable (fun n : ℕ ↦ (n:ℝ)^2) (poissonPMF t).toMeasure := by + rw [poissonPMF_toMeasure, integrable_poissonMeasure_iff] + simpa only [Real.norm_eq_abs, abs_pow, Nat.abs_cast, smul_eq_mul, poissonWeight] using (poissonWeight_second t).summable + +lemma poisson_integral_first (t : ℝ≥0) : (∫ n : ℕ, (n:ℝ) ∂(poissonPMF t).toMeasure) = t := by + rw [PMF.integral_eq_tsum _ _ (poisson_integrable_first t)] + simpa only [poissonPMF_real, smul_eq_mul] using (poissonWeight_mean t).tsum_eq + +lemma poisson_integral_second (t : ℝ≥0) : (∫ n : ℕ, (n:ℝ)^2 ∂(poissonPMF t).toMeasure) = (t:ℝ)^2+t := by + rw [PMF.integral_eq_tsum _ _ (poisson_integrable_second t)] + simpa only [poissonPMF_real, smul_eq_mul] using (poissonWeight_second t).tsum_eq + +lemma poisson_integral_factorial_second (t : ℝ≥0) : + (∫ n : ℕ, ((n:ℝ)^2-n) ∂(poissonPMF t).toMeasure) = (t:ℝ)^2 := by + rw [integral_sub (poisson_integrable_second t) (poisson_integrable_first t), + poisson_integral_second, poisson_integral_first] + ring + +end ThreeState.TreeClauses.Probability + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PoissonReconstruction.lean b/lean/OAI/Probability/ThreeStateClauses/PoissonReconstruction.lean index 1975986f0ed656d9cd312ba2adab42ba3e3e09cc..978ac414f30396966974e8cce0b585c3329410a9 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PoissonReconstruction.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PoissonReconstruction.lean @@ -1,203 +1,203 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RegularStatistics -import OAI.Probability.ThreeStateClauses.OffspringLaws -import OAI.Probability.ThreeStateClauses.PoissonMoments -import OAI.Probability.ThreeStateClauses.CountableStatistics - -namespace OAI - -/-! Poisson Reconstruction. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators NNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability - -def orderedStatistic (d lam : ℝ) : (ℓ : ℕ) → OrderedObservation ℓ → ℝ - | 0, i => spinScore i - | ℓ+1, ⟨_,v⟩ => (∑ j, orderedStatistic d lam ℓ (v j))/(d*lam) - -def observedStatistic (d lam : ℝ) : (ℓ : ℕ) → Observation ℓ → ℝ - | 0, i => spinScore i - | ℓ+1, s => (s.map (observedStatistic d lam ℓ)).sum/(d*lam) - -lemma observedStatistic_forget (d lam : ℝ) (ℓ : ℕ) (v : OrderedObservation ℓ) : - observedStatistic d lam ℓ (forgetOrdered ℓ v) = orderedStatistic d lam ℓ v := by - induction ℓ with - | zero => rfl - | succ ℓ ih => - rcases v with ⟨n,v⟩ - simp only [forgetOrdered, observedStatistic, orderedStatistic] - congr 1 - simp only [Multiset.map_coe, Multiset.sum_coe, List.map_ofFn, Function.comp_def, ih, List.sum_ofFn] - -lemma poissonStatistic_square_integrable (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) - (ℓ : ℕ) (i : Spin) : - Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) - (orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure := by - induction ℓ generalizing i with - | zero => exact Integrable.of_finite - | succ ℓ ih => - let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) - have hp : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := - pmf_integrable_bind_finite _ _ ih - change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ - ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2) - (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure - apply sigmaPMF_integrable - · intro n - simpa only [div_pow] using (product_square_sum_integrable p hp n).div_const (((d:ℝ)*lam)^2) - · change Integrable (fun n ↦ ∫ v : Fin n → OrderedObservation ℓ, - |((∑ j, orderedStatistic d lam ℓ (v j))/((d:ℝ)*lam))^2| - ∂(productPMF (fun _ : Fin n ↦ p)).toMeasure) (poissonPMF d).toMeasure - have hab (x : ℝ) : |x^2| = x^2 := abs_of_nonneg (sq_nonneg x) - simp_rw [hab, div_pow, integral_div, - integral_product_sq_sum_integrable p hp] - exact (((poisson_integrable_first d).mul_const _).add - (((poisson_integrable_second d).sub (poisson_integrable_first d)).mul_const _)).div_const _ - -lemma poissonStatistic_mean (d : ℝ≥0) (hd : (d:ℝ) ≠ 0) (lam : ℝ) (hlam : Admissible lam) - (hl : lam ≠ 0) (ℓ : ℕ) (i : Spin) : - (∫ v, orderedStatistic d lam ℓ v - ∂(orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure) = spinScore i := by - induction ℓ generalizing i with - | zero => - change (∫ v : Spin, spinScore v ∂(PMF.pure i).toMeasure) = spinScore i - rw [PMF.toMeasure_pure, integral_dirac] - | succ ℓ ih => - let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) - have hp₂ : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := - pmf_integrable_bind_finite _ _ (poissonStatistic_square_integrable d lam hlam ℓ) - have hp := pmf_integrable_of_square p hp₂ - have hi := pmf_integrable_of_square _ (poissonStatistic_square_integrable d lam hlam (ℓ+1) i) - change (∫ z : Σ n, Fin n → OrderedObservation ℓ, - (∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam) - ∂(sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure) = _ - change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ - (∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam)) - (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure at hi - rw [integral_sigmaPMF_integrable _ _ hi] - simp_rw [integral_div, integral_product_sum_integrable p hp] - have hm : (∫ v, orderedStatistic d lam ℓ v ∂p.toMeasure) = lam*spinScore i := by - rw [integral_pmf_bind_integrable _ _ hp] - simp_rw [ih] - exact channel_spinScore lam hlam i - rw [hm, integral_mul_const, poisson_integral_first] - field_simp - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped BigOperators Topology NNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability - -def poissonKSConstant (d lam : ℝ) : ℝ := 4*(d*lam^2)/(d*lam^2-1) - -lemma poissonKSConstant_pos {d lam : ℝ} (hKS : 1 < d*lam^2) : 0 < poissonKSConstant d lam := by - unfold poissonKSConstant; positivity - -lemma poissonKSConstant_ge_four {d lam : ℝ} (hKS : 1 < d*lam^2) : 4 ≤ poissonKSConstant d lam := by - rw [poissonKSConstant, le_div_iff₀ (by linarith)] - linarith - -lemma poissonKSConstant_identity {d lam : ℝ} (hKS : 1 < d*lam^2) : - poissonKSConstant d lam*(d*lam^2-1) = 4*(d*lam^2) := by - rw [poissonKSConstant, div_mul_cancel₀ _ (by linarith)] - -lemma poissonStatistic_second (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (d:ℝ)*lam^2) (ℓ : ℕ) (i : Spin) : - (∫ v, orderedStatistic d lam ℓ v^2 - ∂(orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure) ≤ poissonKSConstant d lam := by - have hd : 0 < (d:ℝ) := by - by_contra h - have he : (d:ℝ) = 0 := le_antisymm (not_lt.mp h) d.coe_nonneg - norm_num [he] at hKS - have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS - have hden : 0 < ((d:ℝ)*lam)^2 := sq_pos_of_ne_zero (mul_ne_zero hd.ne' hl) - induction ℓ generalizing i with - | zero => - change (∫ v : Spin, spinScore v^2 ∂(PMF.pure i).toMeasure) ≤ _ - rw [PMF.toMeasure_pure, integral_dirac] - exact (spinScore_square i).trans (poissonKSConstant_ge_four hKS) - | succ ℓ ih => - let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) - have hp₂ : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := - pmf_integrable_bind_finite _ _ (poissonStatistic_square_integrable d lam hlam ℓ) - have hp := pmf_integrable_of_square p hp₂ - have hmean : (∫ v, orderedStatistic d lam ℓ v ∂p.toMeasure) = lam*spinScore i := by - rw [integral_pmf_bind_integrable _ _ hp] - simp_rw [poissonStatistic_mean d hd.ne' lam hlam hl ℓ] - exact channel_spinScore lam hlam i - have hsecond : (∫ v, orderedStatistic d lam ℓ v^2 ∂p.toMeasure) ≤ poissonKSConstant d lam := by - rw [integral_pmf_bind_integrable _ _ hp₂] - exact (integral_mono Integrable.of_finite (integrable_const _) ih).trans_eq (by simp) - have hi := poissonStatistic_square_integrable d lam hlam (ℓ+1) i - change (∫ z : Σ n, Fin n → OrderedObservation ℓ, - ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2 - ∂(sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure) ≤ _ - change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ - ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2) - (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure at hi - rw [integral_sigmaPMF_integrable _ _ hi] - simp_rw [div_pow, integral_div, integral_product_sq_sum_integrable p hp₂] - rw [hmean, integral_add - (f := fun n : ℕ ↦ (n:ℝ)*(∫ v, orderedStatistic d lam ℓ v^2 ∂p.toMeasure)) - (g := fun n : ℕ ↦ ((n:ℝ)^2-n)*(lam*spinScore i)^2) - ((poisson_integrable_first d).mul_const _) - (((poisson_integrable_second d).sub (poisson_integrable_first d)).mul_const _), - integral_mul_const, integral_mul_const, poisson_integral_first, poisson_integral_factorial_second] - apply (div_le_iff₀ hden).2 - have hs := mul_le_mul_of_nonneg_left (spinScore_square i) (sq_nonneg ((d:ℝ)*lam)) - have hm := mul_le_mul_of_nonneg_left hsecond hd.le - have hid := congrArg (fun x : ℝ ↦ x*(d:ℝ)) (poissonKSConstant_identity hKS) - nlinarith only [hs,hm,hid] - -lemma poisson_estimator_advantage (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (d:ℝ)*lam^2) (ℓ : ℕ) : - 1/(3*poissonKSConstant d lam) ≤ advantage lam hlam (poissonPMF d) ℓ := by - have hd : (d:ℝ) ≠ 0 := by intro h; norm_num [h] at hKS - have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS - let p := observationLaw lam hlam (poissonPMF d) ℓ - let f := observedStatistic d lam ℓ - have hInt (i : Spin) : Integrable (fun o ↦ f o^2) (p i).toMeasure := by - dsimp [p, f] - rw [← orderedLaw_forget _ lam hlam ℓ i, pmf_integrable_map_iff] - simpa only [observedStatistic_forget] using poissonStatistic_square_integrable d lam hlam ℓ i - have hmean (i : Spin) : (∫ o, f o ∂(p i).toMeasure) = spinScore i := by - dsimp [p, f] - rw [← orderedLaw_forget _ lam hlam ℓ i, integral_pmf_map] - simp_rw [observedStatistic_forget] - exact poissonStatistic_mean d hd lam hlam hl ℓ i - have hsecond (i : Spin) : (∫ o, f o^2 ∂(p i).toMeasure) ≤ poissonKSConstant d lam := by - dsimp [p, f] - rw [← orderedLaw_forget _ lam hlam ℓ i, integral_pmf_map] - simp_rw [observedStatistic_forget] - exact poissonStatistic_second d lam hlam hKS ℓ i - rw [advantage_eq_integral] - apply estimator_tv_lower_integrable (p := p) hInt (poissonKSConstant_pos hKS) - · rw [integral_discreteMarginal_integrable p (fun i ↦ pmf_integrable_of_square _ (hInt i)), - hmean 0, hmean 1, hmean 2] - norm_num [spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] - · exact hmean 0 - · rw [integral_discreteMarginal_integrable p hInt] - linarith [hsecond 0, hsecond 1, hsecond 2] - -theorem poisson_reconstructs_above_KS (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (d:ℝ)*lam^2) : Reconstructs lam hlam (poissonPMF d) := by - refine ⟨⨅ ℓ, advantage lam hlam (poissonPMF d) ℓ, ?_, advantage_tendsto _ _ _⟩ - have he : 1/(3*poissonKSConstant d lam) ≤ ⨅ ℓ, advantage lam hlam (poissonPMF d) ℓ := by - exact le_ciInf (fun ℓ ↦ poisson_estimator_advantage d lam hlam hKS ℓ) - exact (div_pos (by norm_num) (mul_pos (by norm_num) (poissonKSConstant_pos hKS))).trans_le he - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RegularStatistics +import OAI.Probability.ThreeStateClauses.OffspringLaws +import OAI.Probability.ThreeStateClauses.PoissonMoments +import OAI.Probability.ThreeStateClauses.CountableStatistics + +namespace OAI + +/-! Poisson Reconstruction. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators NNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability + +def orderedStatistic (d lam : ℝ) : (ℓ : ℕ) → OrderedObservation ℓ → ℝ + | 0, i => spinScore i + | ℓ+1, ⟨_,v⟩ => (∑ j, orderedStatistic d lam ℓ (v j))/(d*lam) + +def observedStatistic (d lam : ℝ) : (ℓ : ℕ) → Observation ℓ → ℝ + | 0, i => spinScore i + | ℓ+1, s => (s.map (observedStatistic d lam ℓ)).sum/(d*lam) + +lemma observedStatistic_forget (d lam : ℝ) (ℓ : ℕ) (v : OrderedObservation ℓ) : + observedStatistic d lam ℓ (forgetOrdered ℓ v) = orderedStatistic d lam ℓ v := by + induction ℓ with + | zero => rfl + | succ ℓ ih => + rcases v with ⟨n,v⟩ + simp only [forgetOrdered, observedStatistic, orderedStatistic] + congr 1 + simp only [Multiset.map_coe, Multiset.sum_coe, List.map_ofFn, Function.comp_def, ih, List.sum_ofFn] + +lemma poissonStatistic_square_integrable (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) + (ℓ : ℕ) (i : Spin) : + Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) + (orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure := by + induction ℓ generalizing i with + | zero => exact Integrable.of_finite + | succ ℓ ih => + let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) + have hp : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := + pmf_integrable_bind_finite _ _ ih + change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ + ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2) + (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure + apply sigmaPMF_integrable + · intro n + simpa only [div_pow] using (product_square_sum_integrable p hp n).div_const (((d:ℝ)*lam)^2) + · change Integrable (fun n ↦ ∫ v : Fin n → OrderedObservation ℓ, + |((∑ j, orderedStatistic d lam ℓ (v j))/((d:ℝ)*lam))^2| + ∂(productPMF (fun _ : Fin n ↦ p)).toMeasure) (poissonPMF d).toMeasure + have hab (x : ℝ) : |x^2| = x^2 := abs_of_nonneg (sq_nonneg x) + simp_rw [hab, div_pow, integral_div, + integral_product_sq_sum_integrable p hp] + exact (((poisson_integrable_first d).mul_const _).add + (((poisson_integrable_second d).sub (poisson_integrable_first d)).mul_const _)).div_const _ + +lemma poissonStatistic_mean (d : ℝ≥0) (hd : (d:ℝ) ≠ 0) (lam : ℝ) (hlam : Admissible lam) + (hl : lam ≠ 0) (ℓ : ℕ) (i : Spin) : + (∫ v, orderedStatistic d lam ℓ v + ∂(orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure) = spinScore i := by + induction ℓ generalizing i with + | zero => + change (∫ v : Spin, spinScore v ∂(PMF.pure i).toMeasure) = spinScore i + rw [PMF.toMeasure_pure, integral_dirac] + | succ ℓ ih => + let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) + have hp₂ : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := + pmf_integrable_bind_finite _ _ (poissonStatistic_square_integrable d lam hlam ℓ) + have hp := pmf_integrable_of_square p hp₂ + have hi := pmf_integrable_of_square _ (poissonStatistic_square_integrable d lam hlam (ℓ+1) i) + change (∫ z : Σ n, Fin n → OrderedObservation ℓ, + (∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam) + ∂(sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure) = _ + change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ + (∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam)) + (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure at hi + rw [integral_sigmaPMF_integrable _ _ hi] + simp_rw [integral_div, integral_product_sum_integrable p hp] + have hm : (∫ v, orderedStatistic d lam ℓ v ∂p.toMeasure) = lam*spinScore i := by + rw [integral_pmf_bind_integrable _ _ hp] + simp_rw [ih] + exact channel_spinScore lam hlam i + rw [hm, integral_mul_const, poisson_integral_first] + field_simp + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped BigOperators Topology NNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Probability + +def poissonKSConstant (d lam : ℝ) : ℝ := 4*(d*lam^2)/(d*lam^2-1) + +lemma poissonKSConstant_pos {d lam : ℝ} (hKS : 1 < d*lam^2) : 0 < poissonKSConstant d lam := by + unfold poissonKSConstant; positivity + +lemma poissonKSConstant_ge_four {d lam : ℝ} (hKS : 1 < d*lam^2) : 4 ≤ poissonKSConstant d lam := by + rw [poissonKSConstant, le_div_iff₀ (by linarith)] + linarith + +lemma poissonKSConstant_identity {d lam : ℝ} (hKS : 1 < d*lam^2) : + poissonKSConstant d lam*(d*lam^2-1) = 4*(d*lam^2) := by + rw [poissonKSConstant, div_mul_cancel₀ _ (by linarith)] + +lemma poissonStatistic_second (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (d:ℝ)*lam^2) (ℓ : ℕ) (i : Spin) : + (∫ v, orderedStatistic d lam ℓ v^2 + ∂(orderedLaw (poissonPMF d) lam hlam ℓ i).toMeasure) ≤ poissonKSConstant d lam := by + have hd : 0 < (d:ℝ) := by + by_contra h + have he : (d:ℝ) = 0 := le_antisymm (not_lt.mp h) d.coe_nonneg + norm_num [he] at hKS + have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS + have hden : 0 < ((d:ℝ)*lam)^2 := sq_pos_of_ne_zero (mul_ne_zero hd.ne' hl) + induction ℓ generalizing i with + | zero => + change (∫ v : Spin, spinScore v^2 ∂(PMF.pure i).toMeasure) ≤ _ + rw [PMF.toMeasure_pure, integral_dirac] + exact (spinScore_square i).trans (poissonKSConstant_ge_four hKS) + | succ ℓ ih => + let p := (channel lam hlam i).bind (orderedLaw (poissonPMF d) lam hlam ℓ) + have hp₂ : Integrable (fun v ↦ orderedStatistic d lam ℓ v^2) p.toMeasure := + pmf_integrable_bind_finite _ _ (poissonStatistic_square_integrable d lam hlam ℓ) + have hp := pmf_integrable_of_square p hp₂ + have hmean : (∫ v, orderedStatistic d lam ℓ v ∂p.toMeasure) = lam*spinScore i := by + rw [integral_pmf_bind_integrable _ _ hp] + simp_rw [poissonStatistic_mean d hd.ne' lam hlam hl ℓ] + exact channel_spinScore lam hlam i + have hsecond : (∫ v, orderedStatistic d lam ℓ v^2 ∂p.toMeasure) ≤ poissonKSConstant d lam := by + rw [integral_pmf_bind_integrable _ _ hp₂] + exact (integral_mono Integrable.of_finite (integrable_const _) ih).trans_eq (by simp) + have hi := poissonStatistic_square_integrable d lam hlam (ℓ+1) i + change (∫ z : Σ n, Fin n → OrderedObservation ℓ, + ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2 + ∂(sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure) ≤ _ + change Integrable (fun z : Σ n, Fin n → OrderedObservation ℓ ↦ + ((∑ j, orderedStatistic d lam ℓ (z.2 j))/((d:ℝ)*lam))^2) + (sigmaPMF (poissonPMF d) (fun n ↦ productPMF (fun _ : Fin n ↦ p))).toMeasure at hi + rw [integral_sigmaPMF_integrable _ _ hi] + simp_rw [div_pow, integral_div, integral_product_sq_sum_integrable p hp₂] + rw [hmean, integral_add + (f := fun n : ℕ ↦ (n:ℝ)*(∫ v, orderedStatistic d lam ℓ v^2 ∂p.toMeasure)) + (g := fun n : ℕ ↦ ((n:ℝ)^2-n)*(lam*spinScore i)^2) + ((poisson_integrable_first d).mul_const _) + (((poisson_integrable_second d).sub (poisson_integrable_first d)).mul_const _), + integral_mul_const, integral_mul_const, poisson_integral_first, poisson_integral_factorial_second] + apply (div_le_iff₀ hden).2 + have hs := mul_le_mul_of_nonneg_left (spinScore_square i) (sq_nonneg ((d:ℝ)*lam)) + have hm := mul_le_mul_of_nonneg_left hsecond hd.le + have hid := congrArg (fun x : ℝ ↦ x*(d:ℝ)) (poissonKSConstant_identity hKS) + nlinarith only [hs,hm,hid] + +lemma poisson_estimator_advantage (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (d:ℝ)*lam^2) (ℓ : ℕ) : + 1/(3*poissonKSConstant d lam) ≤ advantage lam hlam (poissonPMF d) ℓ := by + have hd : (d:ℝ) ≠ 0 := by intro h; norm_num [h] at hKS + have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS + let p := observationLaw lam hlam (poissonPMF d) ℓ + let f := observedStatistic d lam ℓ + have hInt (i : Spin) : Integrable (fun o ↦ f o^2) (p i).toMeasure := by + dsimp [p, f] + rw [← orderedLaw_forget _ lam hlam ℓ i, pmf_integrable_map_iff] + simpa only [observedStatistic_forget] using poissonStatistic_square_integrable d lam hlam ℓ i + have hmean (i : Spin) : (∫ o, f o ∂(p i).toMeasure) = spinScore i := by + dsimp [p, f] + rw [← orderedLaw_forget _ lam hlam ℓ i, integral_pmf_map] + simp_rw [observedStatistic_forget] + exact poissonStatistic_mean d hd lam hlam hl ℓ i + have hsecond (i : Spin) : (∫ o, f o^2 ∂(p i).toMeasure) ≤ poissonKSConstant d lam := by + dsimp [p, f] + rw [← orderedLaw_forget _ lam hlam ℓ i, integral_pmf_map] + simp_rw [observedStatistic_forget] + exact poissonStatistic_second d lam hlam hKS ℓ i + rw [advantage_eq_integral] + apply estimator_tv_lower_integrable (p := p) hInt (poissonKSConstant_pos hKS) + · rw [integral_discreteMarginal_integrable p (fun i ↦ pmf_integrable_of_square _ (hInt i)), + hmean 0, hmean 1, hmean 2] + norm_num [spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] + · exact hmean 0 + · rw [integral_discreteMarginal_integrable p hInt] + linarith [hsecond 0, hsecond 1, hsecond 2] + +theorem poisson_reconstructs_above_KS (d : ℝ≥0) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (d:ℝ)*lam^2) : Reconstructs lam hlam (poissonPMF d) := by + refine ⟨⨅ ℓ, advantage lam hlam (poissonPMF d) ℓ, ?_, advantage_tendsto _ _ _⟩ + have he : 1/(3*poissonKSConstant d lam) ≤ ⨅ ℓ, advantage lam hlam (poissonPMF d) ℓ := by + exact le_ciInf (fun ℓ ↦ poisson_estimator_advantage d lam hlam hKS ℓ) + exact (div_pos (by norm_num) (mul_pos (by norm_num) (poissonKSConstant_pos hKS))).trans_le he + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PositiveFixed.lean b/lean/OAI/Probability/ThreeStateClauses/PositiveFixed.lean index ddd52e8a033dcbe5761187374cf19a9e993c2686..9dd90458563da262e1d50122bf26ecd2c11a4291 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PositiveFixed.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PositiveFixed.lean @@ -1,605 +1,605 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.BranchGrowth -import OAI.Probability.ThreeStateClauses.ScalarBounds - -namespace OAI - -/-! Positive Fixed. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -def qExact (lam : ℝ) : ℝ := (37/27)/(2+lam) -def cExact (lam : ℝ) : ℝ := 37/27+2*lam*qExact lam - -def jMean (Q : Law) : ℝ := ∫ m, symEntropy m.1 ∂Q.probability.toMeasure - -def edgeJMean (Q : Law) (lam : ℝ) : ℝ := ∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure - -lemma edgeJ_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : - Integrable (fun m ↦ symEntropy (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_symEntropy_comp (continuous_edgeMessage lam) - (fun m i ↦ (edge_positive hl₀ hl₁ m).1 i)) - -lemma residual_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) - (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : - Integrable (fun m : Message ↦ residual m.1 lam) Q.probability.toMeasure := by - have h := (((edgeJ_integrable Q hl₀.le hl₁).div_const (lam^2)).sub hJ).const_mul (2/(1-lam)) - apply h.congr - filter_upwards [hp] with m hm - change 2/(1-lam)*(symEntropy (edge lam m.1)/lam^2-symEntropy m.1) = _ - rw [symEntropy_edge_residual hm ⟨hl₀.le,hl₁.le⟩] - field_simp [ne_of_gt hl₀, ne_of_gt (sub_pos.mpr hl₁)] - ring - -lemma momentA_integrable (Q : Law) - (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) - (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : - Integrable (fun m : Message ↦ momentA m.1) Q.probability.toMeasure := by - have h := ((compact_integrable continuous_yMoment).sub ((compact_integrable continuous_xMoment).const_mul 2)).add (hJ.const_mul 2) - apply h.congr - filter_upwards [hp] with m hm - exact (momentA_identity hm).symm - -lemma momentQ_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) - (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : - Integrable (fun m : Message ↦ momentQ m.1 lam) Q.probability.toMeasure := by - have hC := residual_integrable Q hl₀ hl₁ hp hJ - have h := (((compact_integrable continuous_xMoment).sub hJ).sub (hC.div_const 2)).div_const lam - apply h.congr - filter_upwards [hp] with m hm - have he := symEntropy_residual hm ⟨hl₀.le,hl₁.le⟩ - apply (div_eq_iff (ne_of_gt hl₀)).2 - change momentX (centered m.1)-symEntropy m.1-residual m.1 lam/2 = _ - linarith - -lemma expected_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) - (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) - (hadd : edgeJMean Q lam = lam^2*jMean Q) : - 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by - have hC := residual_integrable Q hl₀ hl₁ hp hJ - have hA := momentA_integrable Q hp hJ - have hQ := momentQ_integrable Q hl₀ hl₁ hp hJ - have hx := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) - have hx₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) - have hcx : (∫ m, residual m.1 lam ∂Q.probability.toMeasure) = 0 := by - have he := integral_congr_ae (hp.mono (fun m hm ↦ symEntropy_edge_residual hm ⟨hl₀.le,hl₁.le⟩)) - change edgeJMean Q lam = (∫ m : Message, lam^2*(symEntropy m.1+(1-lam)*residual m.1 lam/2) ∂Q.probability.toMeasure) at he - rw [integral_const_mul, - integral_add (f := fun m : Message ↦ symEntropy m.1) (g := fun m ↦ (1-lam)*residual m.1 lam/2) - hJ ((hC.const_mul _).div_const _), integral_div, integral_const_mul] at he - change edgeJMean Q lam = lam^2*(jMean Q+(1-lam)*(∫ m, residual m.1 lam ∂Q.probability.toMeasure)/2) at he - have hc : 0 < lam^2*(1-lam) := mul_pos (sq_pos_of_pos hl₀) (sub_pos.mpr hl₁) - nlinarith [hadd] - have hjx : jMean Q = Q.mu-lam*(∫ m, momentQ m.1 lam ∂Q.probability.toMeasure) := by - have he := integral_congr_ae (hp.mono (fun m hm ↦ symEntropy_residual hm ⟨hl₀.le,hl₁.le⟩)) - change jMean Q = (∫ m : Message, xMoment m-lam*momentQ m.1 lam-residual m.1 lam/2 ∂Q.probability.toMeasure) at he - rw [integral_sub (f := fun m : Message ↦ xMoment m-lam*momentQ m.1 lam) - (g := fun m ↦ residual m.1 lam/2) (hx.sub (hQ.const_mul _)) (hC.div_const _), - integral_sub (f := xMoment) (g := fun m ↦ lam*momentQ m.1 lam) hx (hQ.const_mul _), - integral_const_mul, integral_div, hcx] at he - simpa only [sub_zero, zero_div, jMean, Law.mu] using he - have hyx : Q.eta = (∫ m, momentA m.1 ∂Q.probability.toMeasure)+ - 2*lam*(∫ m, momentQ m.1 lam ∂Q.probability.toMeasure) := by - have he := integral_congr_ae (hp.mono (fun m hm ↦ momentY_residual hm ⟨hl₀.le,hl₁.le⟩)) - rw [integral_add (f := fun m : Message ↦ momentA m.1+2*lam*momentQ m.1 lam) - (g := fun m ↦ residual m.1 lam) (hA.add (hQ.const_mul _)) hC, - integral_add (f := fun m : Message ↦ momentA m.1) (g := fun m ↦ 2*lam*momentQ m.1 lam) hA (hQ.const_mul _), - integral_const_mul, hcx, add_zero] at he - exact he - have hAb : (37/27)*Q.nu ≤ ∫ m, momentA m.1 ∂Q.probability.toMeasure := by - have h := integral_mono_ae (f := fun m : Message ↦ (37/27)*xMoment m^2) - (g := fun m ↦ momentA m.1) (hx₂.const_mul (37/27)) hA - (hp.mono (fun m hm ↦ momentA_lower hm)) - rwa [integral_const_mul] at h - have hQb : qExact lam*Q.nu ≤ ∫ m, momentQ m.1 lam ∂Q.probability.toMeasure := by - have h := integral_mono_ae (f := fun m : Message ↦ momentA m.1/(2+lam)) - (g := fun m ↦ momentQ m.1 lam) (hA.div_const _) hQ - (hp.mono (fun m hm ↦ momentQ_lower hm hl₀.le hl₁.le)) - rw [integral_div] at h - have hden : 0 < 2+lam := by linarith - have hx := (div_le_div_iff_of_pos_right hden).2 hAb - have hh := hx.trans h - simpa only [qExact, div_mul_eq_mul_div] using hh - refine ⟨integral_nonneg_of_ae (hp.mono (fun m hm ↦ symEntropy_nonneg hm)), ?_, ?_⟩ - · rw [hjx]; nlinarith [mul_nonneg hl₀.le (sub_nonneg.mpr hQb)] - · rw [hyx] - dsimp only [cExact] - nlinarith [mul_nonneg hl₀.le (sub_nonneg.mpr hQb)] - -theorem regular_fixed_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) - (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : - 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by - have hp := finite_positive Q hl₀.le hl₁ n - have hJ := finite_integrable_symEntropy Q hl₀.le hl₁ n - rw [← hfixed] at hp hJ - apply expected_moment_bounds Q hl₀ hl₁ hp hJ - have he := finiteLaw_symEntropy Q hl₀.le hl₁ n - change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = (n:ℝ)*edgeJMean Q lam at he - rw [← hfixed] at he - change jMean Q = (n:ℝ)*edgeJMean Q lam at he - calc - edgeJMean Q lam = ((n:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit]; ring - _ = lam^2*((n:ℝ)*edgeJMean Q lam) := by ring - _ = lam^2*jMean Q := by rw [← he] - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open scoped BigOperators -namespace ThreeState.TreeClauses.Positive - -lemma branch_sum_first (k : ℕ) : - (∑ j ∈ Finset.range k, ((j:ℝ)+1)) = (k:ℝ)*((k:ℝ)+1)/2 := by - induction k with - | zero => simp - | succ k ih => - rw [Finset.sum_range_succ, ih] - push_cast - ring - -lemma branch_sum_second (k : ℕ) : - (∑ j ∈ Finset.range k, ((j:ℝ)+1)*(j:ℝ)) = (k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3 := by - induction k with - | zero => simp - | succ k ih => - rw [Finset.sum_range_succ, ih] - push_cast - ring - -lemma reciprocal_tangent {a q : ℝ} (ha : 0 ≤ a) (_hq : 0 ≤ q) : - 1+2*q-a ≤ (1+q)^2/(1+a) := by - apply (le_div_iff₀ (by positivity : 0 < 1+a)).2 - nlinarith [sq_nonneg (a-q)] - -lemma weighted_branch_jensen {lam mu : ℝ} (hmu : 0 ≤ mu) (k : ℕ) - (hcrit : ((k:ℝ)+1)*lam^2 = 1) : - (k:ℝ)*((k:ℝ)+1)/(2*(1+2*mu/3)) ≤ - ∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*mu)) := by - let q := 2*mu/3 - let beta := lam^2*mu - have hq : 0 ≤ q := by dsimp [q]; positivity - have hb : 0 ≤ beta := by dsimp [beta]; positivity - have hh := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ - mul_le_mul_of_nonneg_right (reciprocal_tangent (mul_nonneg (Nat.cast_nonneg j) hb) hq) - (show (0:ℝ) ≤ (j:ℝ)+1 by positivity)) - have hleft : (∑ j ∈ Finset.range k, (1+2*q-(j:ℝ)*beta)*((j:ℝ)+1)) = - (1+2*q)*((k:ℝ)*((k:ℝ)+1)/2)-beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) := by - simp_rw [sub_mul] - rw [Finset.sum_sub_distrib, ← Finset.mul_sum] - have hid : (∑ j ∈ Finset.range k, (j:ℝ)*beta*((j:ℝ)+1)) = - beta*∑ j ∈ Finset.range k, ((j:ℝ)+1)*(j:ℝ) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro j _; ring - rw [hid, branch_sum_first, branch_sum_second] - have hright : (∑ j ∈ Finset.range k, ((1+q)^2/(1+(j:ℝ)*beta))*((j:ℝ)+1)) = - (1+q)^2*∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*beta) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro j _; ring - rw [hleft, hright] at hh - have hbB : beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) ≤ q*((k:ℝ)*((k:ℝ)+1)/2) := by - have he : beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) = mu*(k:ℝ)*((k:ℝ)-1)/3 := by - dsimp [beta] - linear_combination (mu*(k:ℝ)*((k:ℝ)-1)/3)*hcrit - rw [he] - dsimp [q] - nlinarith [mul_nonneg hmu (Nat.cast_nonneg k)] - have hd : 0 < 1+q := by positivity - have hh' : (k:ℝ)*((k:ℝ)+1)/2 ≤ - (1+q)*(∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*beta)) := by - apply le_of_mul_le_mul_left (a := 1+q) _ hd - nlinarith - apply (div_le_iff₀ (show 0 < 2*(1+2*mu/3) by positivity)).2 - dsimp [q, beta] at hh' - nlinarith - -lemma sqrt_branch_sum {lam : ℝ} (hl : 0 < lam) (k : ℕ) - (hcrit : ((k:ℝ)+1)*lam^2 = 1) : - lam^4*(∑ j ∈ Finset.range k, Real.sqrt ((j:ℝ)+1)) ≤ - (1-lam^2)*lam/Real.sqrt 2 := by - have hs2 := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) - have hs2p := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) - have hl2 : 0 < lam^2 := sq_pos_of_pos hl - have hp := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ - sq_nonneg (Real.sqrt ((j:ℝ)+1)-1/(lam*Real.sqrt 2))) - have hpoint (j : ℕ) : - 2*lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1) ≤ 2*lam^2*((j:ℝ)+1)+1 := by - have hh := sq_nonneg (lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1)-1) - have he : (lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1))^2 = 2*lam^2*((j:ℝ)+1) := by - calc - _ = lam^2*(Real.sqrt 2)^2*(Real.sqrt ((j:ℝ)+1))^2 := by ring - _ = _ := by rw [hs2, Real.sq_sqrt (by positivity)]; ring - nlinarith - have hh := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ hpoint j) - rw [← Finset.mul_sum, Finset.sum_add_distrib, ← Finset.mul_sum, branch_sum_first] at hh - simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one] at hh - have he : 2*lam^2*((k:ℝ)*((k:ℝ)+1)/2)+(k:ℝ) = 2*(k:ℝ) := by - linear_combination (k:ℝ)*hcrit - rw [he] at hh - have he' : (k:ℝ)*lam^2 = 1-lam^2 := by nlinarith [hcrit] - apply (le_div_iff₀ hs2p).2 - have hm := mul_le_mul_of_nonneg_left hh (show 0 ≤ lam^3/2 by positivity) - nlinarith - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -lemma truncated_quadratic {a b t L C : ℝ} (ha : 0 ≤ a) (_hb : 0 ≤ b) - (hL : 0 ≤ L) (ht : L ≤ t) (hC : 0 ≤ C) - (hbound : a*t-b*Real.sqrt t ≤ C) : a*L-b*Real.sqrt L ≤ C := by - have hsL := Real.sqrt_nonneg L - have hst := Real.sqrt_nonneg t - have hsqL := Real.sq_sqrt hL - have hsqt := Real.sq_sqrt (hL.trans ht) - have hsle := Real.sqrt_le_sqrt ht - by_cases h : a*Real.sqrt L-b ≤ 0 - · have hh := mul_nonpos_of_nonneg_of_nonpos hsL h - nlinarith - · have hh := mul_nonneg (sub_nonneg.mpr hsle) (le_of_lt (lt_of_not_ge h)) - have hh' := mul_nonneg (mul_nonneg ha (sub_nonneg.mpr hsle)) hst - nlinarith - -lemma product_cubic_bound (Q R : Law) (hnu : R.nu ≤ Q.nu) : - Q.eta*R.eta ≤ Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu := by - have hmu := Q.mu_nonneg - have hnuQ := Q.nu_nonneg - have hR : R.eta^2 ≤ R.mu*Q.nu := - R.moment_discriminant.trans (mul_le_mul_of_nonneg_left hnu R.mu_nonneg) - have hprod := mul_le_mul Q.moment_discriminant hR (sq_nonneg R.eta) - (mul_nonneg Q.mu_nonneg Q.nu_nonneg) - have hs : (Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu)^2 = (Q.mu*Q.nu)*(R.mu*Q.nu) := by - calc - _ = (Real.sqrt Q.mu)^2*Q.nu^2*(Real.sqrt R.mu)^2 := by ring - _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt R.mu_nonneg]; ring - have hp : 0 ≤ Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu := by positivity - nlinarith [sq_nonneg (Q.eta*R.eta-Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu)] - -lemma correlation_truncated (Q R : Law) {lam L : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hnu : R.nu ≤ Q.nu) (hL : 0 ≤ L) (hproj : L ≤ R.mu) : - 3*lam^2*Q.mu*L-lam^3*Real.sqrt Q.mu*Q.nu*Real.sqrt L ≤ 3*pairCorrelation R Q lam := by - have hmu := Q.mu_nonneg - have hnuQ := Q.nu_nonneg - have hi := pairCorrelation_increment R Q hl₀ hl₁ - have he := product_cubic_bound Q R hnu - have hh : 3*lam^2*Q.mu*R.mu-(lam^3*Real.sqrt Q.mu*Q.nu)*Real.sqrt R.mu ≤ - 3*pairCorrelation R Q lam := by - nlinarith [mul_nonneg (pow_nonneg hl₀ 3) (sub_nonneg.mpr he)] - exact truncated_quadratic (by positivity) (by positivity) hL hproj - (mul_nonneg (by norm_num) (pairCorrelation_nonneg R Q hl₀ hl₁)) hh - -lemma finite_increment_bound (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (N j : ℕ) (hj : 1 ≤ j) (hjN : j ≤ N) - (hfixed : Q.probability = finiteProbability Q hl₀ hl₁ N) : - 3*lam^4*Q.mu^2*(j:ℝ)/(1+((j:ℝ)-1)*(lam^2*Q.mu))- - lam^4*Q.mu*Q.nu*Real.sqrt j ≤ 3*pairCorrelation (finiteLaw Q hl₀ hl₁ j) Q lam := by - have hmu := Q.mu_nonneg - have hnuQ := Q.nu_nonneg - let L : ℝ := (j:ℝ)*(lam^2*Q.mu)/(1+((j:ℝ)-1)*(lam^2*Q.mu)) - have hj' : (1:ℝ) ≤ j := by exact_mod_cast hj - have hd : 1 ≤ 1+((j:ℝ)-1)*(lam^2*Q.mu) := by - nlinarith [mul_nonneg (sub_nonneg.mpr hj') (mul_nonneg (sq_nonneg lam) Q.mu_nonneg)] - have hL : 0 ≤ L := by dsimp [L]; positivity - have hproj := finite_projection Q hl₀ hl₁ j hj - have hnu : (finiteLaw Q hl₀ hl₁ j).nu ≤ Q.nu := by - have hh := finite_nu_mono Q hl₀ hl₁ hjN - change _ ≤ ∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ N).toMeasure at hh - rw [← hfixed] at hh - exact hh - have hc := correlation_truncated Q (finiteLaw Q hl₀ hl₁ j) hl₀ hl₁ hnu hL hproj - have hLu : L ≤ (j:ℝ)*(lam^2*Q.mu) := by - dsimp only [L] - exact div_le_self (by positivity) hd - have hs : Real.sqrt L ≤ lam*Real.sqrt Q.mu*Real.sqrt j := by - have he : (lam*Real.sqrt Q.mu*Real.sqrt j)^2 = (j:ℝ)*(lam^2*Q.mu) := by - calc - _ = lam^2*(Real.sqrt Q.mu)^2*(Real.sqrt j)^2 := by ring - _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt (Nat.cast_nonneg j)]; ring - have hp : 0 ≤ lam*Real.sqrt Q.mu*Real.sqrt j := by positivity - nlinarith [Real.sq_sqrt hL, Real.sqrt_nonneg L] - have hmul := mul_le_mul_of_nonneg_left hs (show 0 ≤ lam^3*Real.sqrt Q.mu*Q.nu by positivity) - have heq : (lam^3*Real.sqrt Q.mu*Q.nu)*(lam*Real.sqrt Q.mu*Real.sqrt j) = - lam^4*Q.mu*Q.nu*Real.sqrt j := by - calc - _ = lam^4*(Real.sqrt Q.mu)^2*Q.nu*Real.sqrt j := by ring - _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg] - rw [heq] at hmul - have hmain : 3*lam^2*Q.mu*L = 3*lam^4*Q.mu^2*(j:ℝ)/(1+((j:ℝ)-1)*(lam^2*Q.mu)) := by - dsimp only [L]; ring - rw [hmain] at hc - linarith - -lemma finite_correlation_sum (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (N : ℕ) (hfixed : Q.probability = finiteProbability Q hl₀ hl₁ N) - (k : ℕ) (hk : k+1 ≤ N) : - (∑ j ∈ Finset.range k, - (3*lam^4*Q.mu^2*((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu))- - lam^4*Q.mu*Q.nu*Real.sqrt ((j:ℝ)+1))) ≤ 3*correlationEntropy Q lam (k+1) := by - induction k with - | zero => - simpa using mul_nonneg (by norm_num : (0:ℝ) ≤ 3) (correlationEntropy_nonneg Q hl₀ hl₁ 1) - | succ k ih => - have hprev := ih (by omega) - have hi := finite_increment_bound Q hl₀ hl₁ N (k+1) (by omega) (by omega) hfixed - simp only [Nat.cast_add, Nat.cast_one, add_sub_cancel_right] at hi - rw [Finset.sum_range_succ, correlationEntropy_succ Q hl₀ hl₁ (k+1)] - linarith - -theorem regular_fixed_correlation_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) - (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : - 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu ≤ - 3*correlationEntropy Q lam n/(1-lam^2) := by - obtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n ≠ 0) - have hc : ((k:ℝ)+1)*lam^2 = 1 := by simpa using hcrit - have halpha : 0 < 1-lam^2 := by nlinarith [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] - have hmu := Q.mu_nonneg - have hnu := Q.nu_nonneg - have hh := finite_correlation_sum Q hl₀.le hl₁ (k+1) hfixed k (by omega) - have hid : (∑ j ∈ Finset.range k, - (3*lam^4*Q.mu^2*((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu))- - lam^4*Q.mu*Q.nu*Real.sqrt ((j:ℝ)+1))) = - (3*lam^4*Q.mu^2)*(∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu)))- - (Q.mu*Q.nu)*(lam^4*∑ j ∈ Finset.range k, Real.sqrt ((j:ℝ)+1)) := by - rw [Finset.sum_sub_distrib, Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro j _ <;> ring - rw [hid] at hh - have hJ := mul_le_mul_of_nonneg_left (weighted_branch_jensen hmu k hc) - (show 0 ≤ 3*lam^4*Q.mu^2 by positivity) - have hS := mul_le_mul_of_nonneg_left (sqrt_branch_sum hl₀ k hc) (mul_nonneg hmu hnu) - have he : lam^4*(k:ℝ)*((k:ℝ)+1) = 1-lam^2 := by - calc - _ = ((k:ℝ)*lam^2)*(((k:ℝ)+1)*lam^2) := by ring - _ = 1-lam^2 := by rw [hc]; nlinarith [hc] - have heJ : 3*lam^4*Q.mu^2*((k:ℝ)*((k:ℝ)+1)/(2*(1+2*Q.mu/3))) = - (1-lam^2)*(3*Q.mu^2/(2*(1+2*Q.mu/3))) := by - calc - _ = (lam^4*(k:ℝ)*((k:ℝ)+1))*(3*Q.mu^2/(2*(1+2*Q.mu/3))) := by ring - _ = _ := by rw [he] - rw [heJ] at hJ - apply (le_div_iff₀ halpha).2 - calc - _ = (1-lam^2)*(3*Q.mu^2/(2*(1+2*Q.mu/3)))-Q.mu*Q.nu*((1-lam^2)*lam/Real.sqrt 2) := by ring - _ ≤ 3*correlationEntropy Q lam (k+1) := by linarith - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -lemma fixed_edgeJ (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) - (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : - edgeJMean Q lam = lam^2*jMean Q := by - have h := finiteLaw_symEntropy Q hl₀.le hl₁ n - change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at h - rw [← hfixed] at h - change jMean Q = (n:ℝ)*edgeJMean Q lam at h - rw [h] - calc - _ = ((n:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit, one_mul] - _ = _ := by ring - -lemma regular_fixed_entropy_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) - (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : - (1-lam^2)/2*Q.nu ≤ (8/5)*(1-lam^2)*(jMean Q)^2-3*correlationEntropy Q lam n := by - have hp := finite_positive Q hl₀.le hl₁ n - have hJ := finite_integrable_symEntropy Q hl₀.le hl₁ n - have hB := finite_integrable_correction Q hl₀.le hl₁ n - rw [← hfixed] at hp hJ hB - have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := - compact_integrable (continuous_info_comp continuous_subtype_val) - have hJe := edgeJ_integrable Q hl₀.le hl₁ - have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) - have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := - compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) - have hF : Integrable (fun m : Message ↦ functional m.1) Q.probability.toMeasure := - (hI.const_mul 3 |>.sub (hJ.const_mul 2)).add (hB.const_mul (4/5)) - have hFe : Integrable (fun m : Message ↦ functional (edgeMessage lam m)) Q.probability.toMeasure := - (hIe.const_mul 3 |>.sub (hJe.const_mul 2)).add (hBe.const_mul (4/5)) - have hrad := integral_mono_ae (μ := Q.probability.toMeasure) - (f := fun m : Message ↦ (1-lam^2)/2*xMoment m^2) - (g := fun m ↦ functional m.1-(lam^2)⁻¹*functional (edgeMessage lam m)) - ((compact_integrable (continuous_xMoment.pow 2)).const_mul _) (hF.sub (hFe.const_mul _)) - (hp.mono (fun m hm ↦ radial_inequality m.1 hm lam hl₀ hl₁)) - rw [integral_const_mul, integral_sub hF (hFe.const_mul _), integral_const_mul] at hrad - change (1-lam^2)/2*Q.nu ≤ _ at hrad - have hJid := finiteLaw_symEntropy Q hl₀.le hl₁ n - have hBid := finiteLaw_correction Q hl₀.le hl₁ n - have hIid := finiteLaw_info Q hl₀.le hl₁ n - change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hJid - change (∫ m, correction m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hBid - change (∫ m, info m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hIid - rw [← hfixed] at hJid hBid hIid - have hninv : (lam^2)⁻¹ = (n:ℝ) := by - apply mul_left_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀)) - rw [mul_inv_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀))] - nlinarith [hcrit] - have hFid : (∫ m, functional m.1 ∂Q.probability.toMeasure) = - 3*(∫ m, info m.1 ∂Q.probability.toMeasure)-2*jMean Q+ - (4/5)*(∫ m, correction m.1 ∂Q.probability.toMeasure) := by - unfold functional - rw [integral_add (f := fun m : Message ↦ 3*info m.1-2*symEntropy m.1) - (g := fun m ↦ (4/5)*correction m.1) ((hI.const_mul _).sub (hJ.const_mul _)) (hB.const_mul _), - integral_sub (f := fun m : Message ↦ 3*info m.1) (g := fun m ↦ 2*symEntropy m.1) - (hI.const_mul _) (hJ.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] - rfl - have hFeid : (∫ m, functional (edgeMessage lam m) ∂Q.probability.toMeasure) = - 3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ - (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure) := by - unfold functional - rw [integral_add (f := fun m : Message ↦ 3*info (edgeMessage lam m)-2*symEntropy (edgeMessage lam m)) - (g := fun m ↦ (4/5)*correction (edgeMessage lam m)) ((hIe.const_mul _).sub (hJe.const_mul _)) (hBe.const_mul _), - integral_sub (f := fun m : Message ↦ 3*info (edgeMessage lam m)) (g := fun m ↦ 2*symEntropy (edgeMessage lam m)) - (hIe.const_mul _) (hJe.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] - rfl - rw [hFid, hFeid, hninv, hIid, hBid] at hrad - change jMean Q = (n:ℝ)*edgeJMean Q lam at hJid - change _ ≤ 3*((n:ℝ)*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n)- - 2*jMean Q+(4/5)*((n:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ - 2*((n:ℝ)^2-n)*(edgeJMean Q lam)^2)- - (n:ℝ)*(3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ - (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)) at hrad - have he : ((n:ℝ)^2-n)*(edgeJMean Q lam)^2 = (1-lam^2)*(jMean Q)^2 := by - rw [fixed_edgeJ Q hl₀ hl₁ n hcrit hfixed] - have hn : ((n:ℝ)^2-n)*lam^4 = 1-lam^2 := by - nlinarith [sq_nonneg ((n:ℝ)*lam^2-1), hcrit] - calc - _ = (((n:ℝ)^2-n)*lam^4)*(jMean Q)^2 := by ring - _ = _ := by rw [hn] - nlinarith [hJid, he] - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -namespace ThreeState.TreeClauses.Positive - -lemma qExact_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : - (37/81:ℝ) ≤ qExact lam := by - unfold qExact - apply (le_div_iff₀ (by positivity : 0 < 2+lam)).2 - linarith - -lemma cExact_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : - cLower lam ≤ cExact lam := by - have hq := qExact_lower hl₀ hl₁ - unfold cExact cLower - nlinarith [mul_nonneg hl₀ (sub_nonneg.mpr hq)] - -lemma qExact_coefficient {lam : ℝ} : - 8*(37/27)*lam*qExact lam ≤ cExact lam^2 := by - unfold cExact - nlinarith [sq_nonneg ((37/27:ℝ)-2*lam*qExact lam)] - -lemma jMean_square_bound {lam mu nu J : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) - (hmu : 0 ≤ mu) (hnu : 0 ≤ nu) (hJ : 0 ≤ J) (hupper : J ≤ mu-lam*qExact lam*nu) - (hregion : cExact lam^2*nu ≤ mu) : - (8/5)*J^2 ≤ (8/5)*mu^2-(113/81)*lam*mu*nu := by - let t := lam*qExact lam*nu - have hq := qExact_lower hl₀ hl₁ - have ht : 0 ≤ t := by dsimp [t]; positivity - have hc := mul_le_mul_of_nonneg_right (qExact_coefficient (lam := lam)) hnu - have htu : 8*(37/27)*t ≤ mu := by dsimp [t]; nlinarith - have hJsq : J^2 ≤ (mu-t)^2 := by - have hu : J ≤ mu-t := hupper - nlinarith - have htt : t^2 ≤ (27/296)*mu*t := by - have hh := mul_le_mul_of_nonneg_right htu ht - nlinarith - have htl : (37/81)*lam*nu ≤ t := by - dsimp [t] - nlinarith [mul_nonneg (mul_nonneg hl₀ hnu) (sub_nonneg.mpr hq)] - have hm := mul_le_mul_of_nonneg_left htl hmu - nlinarith - -lemma strict_correlation_coefficient : (1:ℝ)/Real.sqrt 2+17/25 < 113/81 := by - have hs := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) - have hp := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) - have hh : (2025:ℝ)/1448 < Real.sqrt 2 := by nlinarith - have hfrac : (1:ℝ)/Real.sqrt 2 < 1448/2025 := (div_lt_iff₀ hp).2 (by nlinarith) - linarith - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Positive -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment - -theorem regular_fixed_mu_zero (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) - (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : Q.mu = 0 := by - by_contra hmu0 - have hmu : 0 < Q.mu := lt_of_le_of_ne Q.mu_nonneg (Ne.symm hmu0) - have hnu : 0 < Q.nu := (sq_pos_of_pos hmu).trans_le Q.second_moment_lower - have hinfo := regular_fixed_moment_bounds Q hl₀ hl₁ n hcrit hfixed - have hcl := cExact_lower hl₀.le hl₁.le - have hc : 0 < cExact lam := (cLower_pos hl₀.le).trans_le hcl - have hetaNonneg : 0 ≤ Q.eta := (mul_nonneg hc.le hnu.le).trans hinfo.2.2 - have hsq : (cExact lam*Q.nu)^2 ≤ Q.eta^2 := - (sq_le_sq₀ (mul_nonneg hc.le hnu.le) hetaNonneg).2 hinfo.2.2 - have hregion : cExact lam^2*Q.nu ≤ Q.mu := by - apply (mul_le_mul_iff_right₀ hnu).mp - nlinarith [Q.moment_discriminant] - have hmuC : Q.mu*cExact lam^2 ≤ 1 := by - apply (mul_le_mul_iff_right₀ hmu).mp - have hh := mul_le_mul_of_nonneg_left Q.second_moment_lower (sq_nonneg (cExact lam)) - nlinarith - have hregionLower : Q.mu*cLower lam^2 ≤ 1 := by - have hs : cLower lam^2 ≤ cExact lam^2 := - (sq_le_sq₀ (cLower_pos hl₀.le).le hc.le).2 hcl - exact (mul_le_mul_of_nonneg_left hs hmu.le).trans hmuC - have hlam : lam^2 ≤ 1/2 := by - have hn' : (2:ℝ) ≤ n := by exact_mod_cast hn - have hh := mul_le_mul_of_nonneg_right hn' (sq_nonneg lam) - nlinarith [hcrit] - have hstrict := scalar_strict hl₀ hl₁ hmu.le (by norm_num : (0:ℝ) < 1) - (le_refl (1:ℝ)) hregionLower (Or.inl hlam) - have hJ := jMean_square_bound hl₀.le hl₁.le hmu.le hnu.le hinfo.1 hinfo.2.1 hregion - have hH := regular_fixed_correlation_bounds Q hl₀ hl₁ n hn hcrit hfixed - have hrad := regular_fixed_entropy_radial Q hl₀ hl₁ n hcrit hfixed - have halpha : 0 < 1-lam^2 := by nlinarith - have hent : Q.nu/2+3*correlationEntropy Q lam n/(1-lam^2) ≤ (8/5)*(jMean Q)^2 := by - calc - _ = ((1-lam^2)/2*Q.nu+3*correlationEntropy Q lam n)/(1-lam^2) := by - field_simp [ne_of_gt halpha] - _ ≤ _ := (div_le_iff₀ halpha).2 (by nlinarith) - have hH' : 3*Q.mu^2/(2*(1+2*Q.mu/3))-(1/Real.sqrt 2)*(lam*Q.mu*Q.nu) ≤ - 3*correlationEntropy Q lam n/(1-lam^2) := by - convert hH using 1 - ring - have hg := mul_le_mul_of_nonneg_right (le_of_lt strict_correlation_coefficient) - (show 0 ≤ lam*Q.mu*Q.nu by positivity) - have hb : Q.nu/2+3*Q.mu^2/(2*(1+2*Q.mu/3))+(17/25)*lam*Q.mu*Q.nu ≤ (8/5)*Q.mu^2 := by - nlinarith - have hcoef : 0 ≤ (1-lam^2)/2+17*lam*Q.mu/25 := by positivity - have hsub := mul_le_mul_of_nonneg_left Q.second_moment_lower hcoef - have hnecessary : scalarT lam Q.mu 1*Q.mu^2 ≤ (8/5)*Q.mu^2 := by - calc - _ = ((1-lam^2)/2+17*lam*Q.mu/25)*Q.mu^2+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by - unfold scalarT; ring - _ ≤ ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by linarith - _ ≤ _ := by nlinarith [mul_nonneg (sq_nonneg lam) hnu.le] - have hh := mul_lt_mul_of_pos_right hstrict (sq_pos_of_pos hmu) - linarith - -lemma message_uniform_of_x_zero {m : Message} (h : xMoment m = 0) : m.1 = fun _ ↦ 1 := by - dsimp [xMoment, momentX, centered, avg] at h - funext i - fin_cases i <;> dsimp <;> nlinarith [sq_nonneg (m.1 0-1), sq_nonneg (m.1 1-1), sq_nonneg (m.1 2-1)] - -theorem regular_fixed_uniform (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) - (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : - ∀ᵐ m ∂Q.probability.toMeasure, m.1 = fun _ ↦ 1 := by - have hzero := regular_fixed_mu_zero Q hl₀ hl₁ n hn hcrit hfixed - have he : ∀ᵐ m ∂Q.probability.toMeasure, xMoment m = 0 := - (integral_eq_zero_iff_of_nonneg xMoment_nonneg (compact_integrable continuous_xMoment)).1 hzero - exact he.mono (fun _ hm ↦ message_uniform_of_x_zero hm) - -end ThreeState.TreeClauses.Positive - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.BranchGrowth +import OAI.Probability.ThreeStateClauses.ScalarBounds + +namespace OAI + +/-! Positive Fixed. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +def qExact (lam : ℝ) : ℝ := (37/27)/(2+lam) +def cExact (lam : ℝ) : ℝ := 37/27+2*lam*qExact lam + +def jMean (Q : Law) : ℝ := ∫ m, symEntropy m.1 ∂Q.probability.toMeasure + +def edgeJMean (Q : Law) (lam : ℝ) : ℝ := ∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure + +lemma edgeJ_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) : + Integrable (fun m ↦ symEntropy (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_symEntropy_comp (continuous_edgeMessage lam) + (fun m i ↦ (edge_positive hl₀ hl₁ m).1 i)) + +lemma residual_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) + (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : + Integrable (fun m : Message ↦ residual m.1 lam) Q.probability.toMeasure := by + have h := (((edgeJ_integrable Q hl₀.le hl₁).div_const (lam^2)).sub hJ).const_mul (2/(1-lam)) + apply h.congr + filter_upwards [hp] with m hm + change 2/(1-lam)*(symEntropy (edge lam m.1)/lam^2-symEntropy m.1) = _ + rw [symEntropy_edge_residual hm ⟨hl₀.le,hl₁.le⟩] + field_simp [ne_of_gt hl₀, ne_of_gt (sub_pos.mpr hl₁)] + ring + +lemma momentA_integrable (Q : Law) + (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) + (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : + Integrable (fun m : Message ↦ momentA m.1) Q.probability.toMeasure := by + have h := ((compact_integrable continuous_yMoment).sub ((compact_integrable continuous_xMoment).const_mul 2)).add (hJ.const_mul 2) + apply h.congr + filter_upwards [hp] with m hm + exact (momentA_identity hm).symm + +lemma momentQ_integrable (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) + (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) : + Integrable (fun m : Message ↦ momentQ m.1 lam) Q.probability.toMeasure := by + have hC := residual_integrable Q hl₀ hl₁ hp hJ + have h := (((compact_integrable continuous_xMoment).sub hJ).sub (hC.div_const 2)).div_const lam + apply h.congr + filter_upwards [hp] with m hm + have he := symEntropy_residual hm ⟨hl₀.le,hl₁.le⟩ + apply (div_eq_iff (ne_of_gt hl₀)).2 + change momentX (centered m.1)-symEntropy m.1-residual m.1 lam/2 = _ + linarith + +lemma expected_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (hp : ∀ᵐ m ∂Q.probability.toMeasure, PositiveMessage m.1) + (hJ : Integrable (fun m : Message ↦ symEntropy m.1) Q.probability.toMeasure) + (hadd : edgeJMean Q lam = lam^2*jMean Q) : + 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by + have hC := residual_integrable Q hl₀ hl₁ hp hJ + have hA := momentA_integrable Q hp hJ + have hQ := momentQ_integrable Q hl₀ hl₁ hp hJ + have hx := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) + have hx₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) + have hcx : (∫ m, residual m.1 lam ∂Q.probability.toMeasure) = 0 := by + have he := integral_congr_ae (hp.mono (fun m hm ↦ symEntropy_edge_residual hm ⟨hl₀.le,hl₁.le⟩)) + change edgeJMean Q lam = (∫ m : Message, lam^2*(symEntropy m.1+(1-lam)*residual m.1 lam/2) ∂Q.probability.toMeasure) at he + rw [integral_const_mul, + integral_add (f := fun m : Message ↦ symEntropy m.1) (g := fun m ↦ (1-lam)*residual m.1 lam/2) + hJ ((hC.const_mul _).div_const _), integral_div, integral_const_mul] at he + change edgeJMean Q lam = lam^2*(jMean Q+(1-lam)*(∫ m, residual m.1 lam ∂Q.probability.toMeasure)/2) at he + have hc : 0 < lam^2*(1-lam) := mul_pos (sq_pos_of_pos hl₀) (sub_pos.mpr hl₁) + nlinarith [hadd] + have hjx : jMean Q = Q.mu-lam*(∫ m, momentQ m.1 lam ∂Q.probability.toMeasure) := by + have he := integral_congr_ae (hp.mono (fun m hm ↦ symEntropy_residual hm ⟨hl₀.le,hl₁.le⟩)) + change jMean Q = (∫ m : Message, xMoment m-lam*momentQ m.1 lam-residual m.1 lam/2 ∂Q.probability.toMeasure) at he + rw [integral_sub (f := fun m : Message ↦ xMoment m-lam*momentQ m.1 lam) + (g := fun m ↦ residual m.1 lam/2) (hx.sub (hQ.const_mul _)) (hC.div_const _), + integral_sub (f := xMoment) (g := fun m ↦ lam*momentQ m.1 lam) hx (hQ.const_mul _), + integral_const_mul, integral_div, hcx] at he + simpa only [sub_zero, zero_div, jMean, Law.mu] using he + have hyx : Q.eta = (∫ m, momentA m.1 ∂Q.probability.toMeasure)+ + 2*lam*(∫ m, momentQ m.1 lam ∂Q.probability.toMeasure) := by + have he := integral_congr_ae (hp.mono (fun m hm ↦ momentY_residual hm ⟨hl₀.le,hl₁.le⟩)) + rw [integral_add (f := fun m : Message ↦ momentA m.1+2*lam*momentQ m.1 lam) + (g := fun m ↦ residual m.1 lam) (hA.add (hQ.const_mul _)) hC, + integral_add (f := fun m : Message ↦ momentA m.1) (g := fun m ↦ 2*lam*momentQ m.1 lam) hA (hQ.const_mul _), + integral_const_mul, hcx, add_zero] at he + exact he + have hAb : (37/27)*Q.nu ≤ ∫ m, momentA m.1 ∂Q.probability.toMeasure := by + have h := integral_mono_ae (f := fun m : Message ↦ (37/27)*xMoment m^2) + (g := fun m ↦ momentA m.1) (hx₂.const_mul (37/27)) hA + (hp.mono (fun m hm ↦ momentA_lower hm)) + rwa [integral_const_mul] at h + have hQb : qExact lam*Q.nu ≤ ∫ m, momentQ m.1 lam ∂Q.probability.toMeasure := by + have h := integral_mono_ae (f := fun m : Message ↦ momentA m.1/(2+lam)) + (g := fun m ↦ momentQ m.1 lam) (hA.div_const _) hQ + (hp.mono (fun m hm ↦ momentQ_lower hm hl₀.le hl₁.le)) + rw [integral_div] at h + have hden : 0 < 2+lam := by linarith + have hx := (div_le_div_iff_of_pos_right hden).2 hAb + have hh := hx.trans h + simpa only [qExact, div_mul_eq_mul_div] using hh + refine ⟨integral_nonneg_of_ae (hp.mono (fun m hm ↦ symEntropy_nonneg hm)), ?_, ?_⟩ + · rw [hjx]; nlinarith [mul_nonneg hl₀.le (sub_nonneg.mpr hQb)] + · rw [hyx] + dsimp only [cExact] + nlinarith [mul_nonneg hl₀.le (sub_nonneg.mpr hQb)] + +theorem regular_fixed_moment_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) + (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : + 0 ≤ jMean Q ∧ jMean Q ≤ Q.mu-lam*qExact lam*Q.nu ∧ cExact lam*Q.nu ≤ Q.eta := by + have hp := finite_positive Q hl₀.le hl₁ n + have hJ := finite_integrable_symEntropy Q hl₀.le hl₁ n + rw [← hfixed] at hp hJ + apply expected_moment_bounds Q hl₀ hl₁ hp hJ + have he := finiteLaw_symEntropy Q hl₀.le hl₁ n + change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = (n:ℝ)*edgeJMean Q lam at he + rw [← hfixed] at he + change jMean Q = (n:ℝ)*edgeJMean Q lam at he + calc + edgeJMean Q lam = ((n:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit]; ring + _ = lam^2*((n:ℝ)*edgeJMean Q lam) := by ring + _ = lam^2*jMean Q := by rw [← he] + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open scoped BigOperators +namespace ThreeState.TreeClauses.Positive + +lemma branch_sum_first (k : ℕ) : + (∑ j ∈ Finset.range k, ((j:ℝ)+1)) = (k:ℝ)*((k:ℝ)+1)/2 := by + induction k with + | zero => simp + | succ k ih => + rw [Finset.sum_range_succ, ih] + push_cast + ring + +lemma branch_sum_second (k : ℕ) : + (∑ j ∈ Finset.range k, ((j:ℝ)+1)*(j:ℝ)) = (k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3 := by + induction k with + | zero => simp + | succ k ih => + rw [Finset.sum_range_succ, ih] + push_cast + ring + +lemma reciprocal_tangent {a q : ℝ} (ha : 0 ≤ a) (_hq : 0 ≤ q) : + 1+2*q-a ≤ (1+q)^2/(1+a) := by + apply (le_div_iff₀ (by positivity : 0 < 1+a)).2 + nlinarith [sq_nonneg (a-q)] + +lemma weighted_branch_jensen {lam mu : ℝ} (hmu : 0 ≤ mu) (k : ℕ) + (hcrit : ((k:ℝ)+1)*lam^2 = 1) : + (k:ℝ)*((k:ℝ)+1)/(2*(1+2*mu/3)) ≤ + ∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*mu)) := by + let q := 2*mu/3 + let beta := lam^2*mu + have hq : 0 ≤ q := by dsimp [q]; positivity + have hb : 0 ≤ beta := by dsimp [beta]; positivity + have hh := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ + mul_le_mul_of_nonneg_right (reciprocal_tangent (mul_nonneg (Nat.cast_nonneg j) hb) hq) + (show (0:ℝ) ≤ (j:ℝ)+1 by positivity)) + have hleft : (∑ j ∈ Finset.range k, (1+2*q-(j:ℝ)*beta)*((j:ℝ)+1)) = + (1+2*q)*((k:ℝ)*((k:ℝ)+1)/2)-beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) := by + simp_rw [sub_mul] + rw [Finset.sum_sub_distrib, ← Finset.mul_sum] + have hid : (∑ j ∈ Finset.range k, (j:ℝ)*beta*((j:ℝ)+1)) = + beta*∑ j ∈ Finset.range k, ((j:ℝ)+1)*(j:ℝ) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro j _; ring + rw [hid, branch_sum_first, branch_sum_second] + have hright : (∑ j ∈ Finset.range k, ((1+q)^2/(1+(j:ℝ)*beta))*((j:ℝ)+1)) = + (1+q)^2*∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*beta) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro j _; ring + rw [hleft, hright] at hh + have hbB : beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) ≤ q*((k:ℝ)*((k:ℝ)+1)/2) := by + have he : beta*((k:ℝ)*((k:ℝ)+1)*((k:ℝ)-1)/3) = mu*(k:ℝ)*((k:ℝ)-1)/3 := by + dsimp [beta] + linear_combination (mu*(k:ℝ)*((k:ℝ)-1)/3)*hcrit + rw [he] + dsimp [q] + nlinarith [mul_nonneg hmu (Nat.cast_nonneg k)] + have hd : 0 < 1+q := by positivity + have hh' : (k:ℝ)*((k:ℝ)+1)/2 ≤ + (1+q)*(∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*beta)) := by + apply le_of_mul_le_mul_left (a := 1+q) _ hd + nlinarith + apply (div_le_iff₀ (show 0 < 2*(1+2*mu/3) by positivity)).2 + dsimp [q, beta] at hh' + nlinarith + +lemma sqrt_branch_sum {lam : ℝ} (hl : 0 < lam) (k : ℕ) + (hcrit : ((k:ℝ)+1)*lam^2 = 1) : + lam^4*(∑ j ∈ Finset.range k, Real.sqrt ((j:ℝ)+1)) ≤ + (1-lam^2)*lam/Real.sqrt 2 := by + have hs2 := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) + have hs2p := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) + have hl2 : 0 < lam^2 := sq_pos_of_pos hl + have hp := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ + sq_nonneg (Real.sqrt ((j:ℝ)+1)-1/(lam*Real.sqrt 2))) + have hpoint (j : ℕ) : + 2*lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1) ≤ 2*lam^2*((j:ℝ)+1)+1 := by + have hh := sq_nonneg (lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1)-1) + have he : (lam*Real.sqrt 2*Real.sqrt ((j:ℝ)+1))^2 = 2*lam^2*((j:ℝ)+1) := by + calc + _ = lam^2*(Real.sqrt 2)^2*(Real.sqrt ((j:ℝ)+1))^2 := by ring + _ = _ := by rw [hs2, Real.sq_sqrt (by positivity)]; ring + nlinarith + have hh := Finset.sum_le_sum (s := Finset.range k) (fun j _ ↦ hpoint j) + rw [← Finset.mul_sum, Finset.sum_add_distrib, ← Finset.mul_sum, branch_sum_first] at hh + simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one] at hh + have he : 2*lam^2*((k:ℝ)*((k:ℝ)+1)/2)+(k:ℝ) = 2*(k:ℝ) := by + linear_combination (k:ℝ)*hcrit + rw [he] at hh + have he' : (k:ℝ)*lam^2 = 1-lam^2 := by nlinarith [hcrit] + apply (le_div_iff₀ hs2p).2 + have hm := mul_le_mul_of_nonneg_left hh (show 0 ≤ lam^3/2 by positivity) + nlinarith + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +lemma truncated_quadratic {a b t L C : ℝ} (ha : 0 ≤ a) (_hb : 0 ≤ b) + (hL : 0 ≤ L) (ht : L ≤ t) (hC : 0 ≤ C) + (hbound : a*t-b*Real.sqrt t ≤ C) : a*L-b*Real.sqrt L ≤ C := by + have hsL := Real.sqrt_nonneg L + have hst := Real.sqrt_nonneg t + have hsqL := Real.sq_sqrt hL + have hsqt := Real.sq_sqrt (hL.trans ht) + have hsle := Real.sqrt_le_sqrt ht + by_cases h : a*Real.sqrt L-b ≤ 0 + · have hh := mul_nonpos_of_nonneg_of_nonpos hsL h + nlinarith + · have hh := mul_nonneg (sub_nonneg.mpr hsle) (le_of_lt (lt_of_not_ge h)) + have hh' := mul_nonneg (mul_nonneg ha (sub_nonneg.mpr hsle)) hst + nlinarith + +lemma product_cubic_bound (Q R : Law) (hnu : R.nu ≤ Q.nu) : + Q.eta*R.eta ≤ Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu := by + have hmu := Q.mu_nonneg + have hnuQ := Q.nu_nonneg + have hR : R.eta^2 ≤ R.mu*Q.nu := + R.moment_discriminant.trans (mul_le_mul_of_nonneg_left hnu R.mu_nonneg) + have hprod := mul_le_mul Q.moment_discriminant hR (sq_nonneg R.eta) + (mul_nonneg Q.mu_nonneg Q.nu_nonneg) + have hs : (Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu)^2 = (Q.mu*Q.nu)*(R.mu*Q.nu) := by + calc + _ = (Real.sqrt Q.mu)^2*Q.nu^2*(Real.sqrt R.mu)^2 := by ring + _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt R.mu_nonneg]; ring + have hp : 0 ≤ Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu := by positivity + nlinarith [sq_nonneg (Q.eta*R.eta-Real.sqrt Q.mu*Q.nu*Real.sqrt R.mu)] + +lemma correlation_truncated (Q R : Law) {lam L : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hnu : R.nu ≤ Q.nu) (hL : 0 ≤ L) (hproj : L ≤ R.mu) : + 3*lam^2*Q.mu*L-lam^3*Real.sqrt Q.mu*Q.nu*Real.sqrt L ≤ 3*pairCorrelation R Q lam := by + have hmu := Q.mu_nonneg + have hnuQ := Q.nu_nonneg + have hi := pairCorrelation_increment R Q hl₀ hl₁ + have he := product_cubic_bound Q R hnu + have hh : 3*lam^2*Q.mu*R.mu-(lam^3*Real.sqrt Q.mu*Q.nu)*Real.sqrt R.mu ≤ + 3*pairCorrelation R Q lam := by + nlinarith [mul_nonneg (pow_nonneg hl₀ 3) (sub_nonneg.mpr he)] + exact truncated_quadratic (by positivity) (by positivity) hL hproj + (mul_nonneg (by norm_num) (pairCorrelation_nonneg R Q hl₀ hl₁)) hh + +lemma finite_increment_bound (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (N j : ℕ) (hj : 1 ≤ j) (hjN : j ≤ N) + (hfixed : Q.probability = finiteProbability Q hl₀ hl₁ N) : + 3*lam^4*Q.mu^2*(j:ℝ)/(1+((j:ℝ)-1)*(lam^2*Q.mu))- + lam^4*Q.mu*Q.nu*Real.sqrt j ≤ 3*pairCorrelation (finiteLaw Q hl₀ hl₁ j) Q lam := by + have hmu := Q.mu_nonneg + have hnuQ := Q.nu_nonneg + let L : ℝ := (j:ℝ)*(lam^2*Q.mu)/(1+((j:ℝ)-1)*(lam^2*Q.mu)) + have hj' : (1:ℝ) ≤ j := by exact_mod_cast hj + have hd : 1 ≤ 1+((j:ℝ)-1)*(lam^2*Q.mu) := by + nlinarith [mul_nonneg (sub_nonneg.mpr hj') (mul_nonneg (sq_nonneg lam) Q.mu_nonneg)] + have hL : 0 ≤ L := by dsimp [L]; positivity + have hproj := finite_projection Q hl₀ hl₁ j hj + have hnu : (finiteLaw Q hl₀ hl₁ j).nu ≤ Q.nu := by + have hh := finite_nu_mono Q hl₀ hl₁ hjN + change _ ≤ ∫ m, xMoment m^2 ∂(finiteProbability Q hl₀ hl₁ N).toMeasure at hh + rw [← hfixed] at hh + exact hh + have hc := correlation_truncated Q (finiteLaw Q hl₀ hl₁ j) hl₀ hl₁ hnu hL hproj + have hLu : L ≤ (j:ℝ)*(lam^2*Q.mu) := by + dsimp only [L] + exact div_le_self (by positivity) hd + have hs : Real.sqrt L ≤ lam*Real.sqrt Q.mu*Real.sqrt j := by + have he : (lam*Real.sqrt Q.mu*Real.sqrt j)^2 = (j:ℝ)*(lam^2*Q.mu) := by + calc + _ = lam^2*(Real.sqrt Q.mu)^2*(Real.sqrt j)^2 := by ring + _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg, Real.sq_sqrt (Nat.cast_nonneg j)]; ring + have hp : 0 ≤ lam*Real.sqrt Q.mu*Real.sqrt j := by positivity + nlinarith [Real.sq_sqrt hL, Real.sqrt_nonneg L] + have hmul := mul_le_mul_of_nonneg_left hs (show 0 ≤ lam^3*Real.sqrt Q.mu*Q.nu by positivity) + have heq : (lam^3*Real.sqrt Q.mu*Q.nu)*(lam*Real.sqrt Q.mu*Real.sqrt j) = + lam^4*Q.mu*Q.nu*Real.sqrt j := by + calc + _ = lam^4*(Real.sqrt Q.mu)^2*Q.nu*Real.sqrt j := by ring + _ = _ := by rw [Real.sq_sqrt Q.mu_nonneg] + rw [heq] at hmul + have hmain : 3*lam^2*Q.mu*L = 3*lam^4*Q.mu^2*(j:ℝ)/(1+((j:ℝ)-1)*(lam^2*Q.mu)) := by + dsimp only [L]; ring + rw [hmain] at hc + linarith + +lemma finite_correlation_sum (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (N : ℕ) (hfixed : Q.probability = finiteProbability Q hl₀ hl₁ N) + (k : ℕ) (hk : k+1 ≤ N) : + (∑ j ∈ Finset.range k, + (3*lam^4*Q.mu^2*((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu))- + lam^4*Q.mu*Q.nu*Real.sqrt ((j:ℝ)+1))) ≤ 3*correlationEntropy Q lam (k+1) := by + induction k with + | zero => + simpa using mul_nonneg (by norm_num : (0:ℝ) ≤ 3) (correlationEntropy_nonneg Q hl₀ hl₁ 1) + | succ k ih => + have hprev := ih (by omega) + have hi := finite_increment_bound Q hl₀ hl₁ N (k+1) (by omega) (by omega) hfixed + simp only [Nat.cast_add, Nat.cast_one, add_sub_cancel_right] at hi + rw [Finset.sum_range_succ, correlationEntropy_succ Q hl₀ hl₁ (k+1)] + linarith + +theorem regular_fixed_correlation_bounds (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) + (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : + 3*Q.mu^2/(2*(1+2*Q.mu/3))-lam/Real.sqrt 2*Q.mu*Q.nu ≤ + 3*correlationEntropy Q lam n/(1-lam^2) := by + obtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n ≠ 0) + have hc : ((k:ℝ)+1)*lam^2 = 1 := by simpa using hcrit + have halpha : 0 < 1-lam^2 := by nlinarith [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] + have hmu := Q.mu_nonneg + have hnu := Q.nu_nonneg + have hh := finite_correlation_sum Q hl₀.le hl₁ (k+1) hfixed k (by omega) + have hid : (∑ j ∈ Finset.range k, + (3*lam^4*Q.mu^2*((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu))- + lam^4*Q.mu*Q.nu*Real.sqrt ((j:ℝ)+1))) = + (3*lam^4*Q.mu^2)*(∑ j ∈ Finset.range k, ((j:ℝ)+1)/(1+(j:ℝ)*(lam^2*Q.mu)))- + (Q.mu*Q.nu)*(lam^4*∑ j ∈ Finset.range k, Real.sqrt ((j:ℝ)+1)) := by + rw [Finset.sum_sub_distrib, Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro j _ <;> ring + rw [hid] at hh + have hJ := mul_le_mul_of_nonneg_left (weighted_branch_jensen hmu k hc) + (show 0 ≤ 3*lam^4*Q.mu^2 by positivity) + have hS := mul_le_mul_of_nonneg_left (sqrt_branch_sum hl₀ k hc) (mul_nonneg hmu hnu) + have he : lam^4*(k:ℝ)*((k:ℝ)+1) = 1-lam^2 := by + calc + _ = ((k:ℝ)*lam^2)*(((k:ℝ)+1)*lam^2) := by ring + _ = 1-lam^2 := by rw [hc]; nlinarith [hc] + have heJ : 3*lam^4*Q.mu^2*((k:ℝ)*((k:ℝ)+1)/(2*(1+2*Q.mu/3))) = + (1-lam^2)*(3*Q.mu^2/(2*(1+2*Q.mu/3))) := by + calc + _ = (lam^4*(k:ℝ)*((k:ℝ)+1))*(3*Q.mu^2/(2*(1+2*Q.mu/3))) := by ring + _ = _ := by rw [he] + rw [heJ] at hJ + apply (le_div_iff₀ halpha).2 + calc + _ = (1-lam^2)*(3*Q.mu^2/(2*(1+2*Q.mu/3)))-Q.mu*Q.nu*((1-lam^2)*lam/Real.sqrt 2) := by ring + _ ≤ 3*correlationEntropy Q lam (k+1) := by linarith + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +lemma fixed_edgeJ (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) + (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : + edgeJMean Q lam = lam^2*jMean Q := by + have h := finiteLaw_symEntropy Q hl₀.le hl₁ n + change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at h + rw [← hfixed] at h + change jMean Q = (n:ℝ)*edgeJMean Q lam at h + rw [h] + calc + _ = ((n:ℝ)*lam^2)*edgeJMean Q lam := by rw [hcrit, one_mul] + _ = _ := by ring + +lemma regular_fixed_entropy_radial (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) (n : ℕ) + (hcrit : (n:ℝ)*lam^2 = 1) (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : + (1-lam^2)/2*Q.nu ≤ (8/5)*(1-lam^2)*(jMean Q)^2-3*correlationEntropy Q lam n := by + have hp := finite_positive Q hl₀.le hl₁ n + have hJ := finite_integrable_symEntropy Q hl₀.le hl₁ n + have hB := finite_integrable_correction Q hl₀.le hl₁ n + rw [← hfixed] at hp hJ hB + have hI : Integrable (fun m : Message ↦ info m.1) Q.probability.toMeasure := + compact_integrable (continuous_info_comp continuous_subtype_val) + have hJe := edgeJ_integrable Q hl₀.le hl₁ + have hIe : Integrable (fun m : Message ↦ info (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_info_comp (continuous_edgeMessage lam)) + have hBe : Integrable (fun m : Message ↦ correction (edgeMessage lam m)) Q.probability.toMeasure := + compact_integrable (continuous_correction_comp (continuous_edgeMessage lam) (fun m i ↦ (edge_positive hl₀.le hl₁ m).1 i)) + have hF : Integrable (fun m : Message ↦ functional m.1) Q.probability.toMeasure := + (hI.const_mul 3 |>.sub (hJ.const_mul 2)).add (hB.const_mul (4/5)) + have hFe : Integrable (fun m : Message ↦ functional (edgeMessage lam m)) Q.probability.toMeasure := + (hIe.const_mul 3 |>.sub (hJe.const_mul 2)).add (hBe.const_mul (4/5)) + have hrad := integral_mono_ae (μ := Q.probability.toMeasure) + (f := fun m : Message ↦ (1-lam^2)/2*xMoment m^2) + (g := fun m ↦ functional m.1-(lam^2)⁻¹*functional (edgeMessage lam m)) + ((compact_integrable (continuous_xMoment.pow 2)).const_mul _) (hF.sub (hFe.const_mul _)) + (hp.mono (fun m hm ↦ radial_inequality m.1 hm lam hl₀ hl₁)) + rw [integral_const_mul, integral_sub hF (hFe.const_mul _), integral_const_mul] at hrad + change (1-lam^2)/2*Q.nu ≤ _ at hrad + have hJid := finiteLaw_symEntropy Q hl₀.le hl₁ n + have hBid := finiteLaw_correction Q hl₀.le hl₁ n + have hIid := finiteLaw_info Q hl₀.le hl₁ n + change (∫ m, symEntropy m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hJid + change (∫ m, correction m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hBid + change (∫ m, info m.1 ∂(finiteProbability Q hl₀.le hl₁ n).toMeasure) = _ at hIid + rw [← hfixed] at hJid hBid hIid + have hninv : (lam^2)⁻¹ = (n:ℝ) := by + apply mul_left_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀)) + rw [mul_inv_cancel₀ (ne_of_gt (sq_pos_of_pos hl₀))] + nlinarith [hcrit] + have hFid : (∫ m, functional m.1 ∂Q.probability.toMeasure) = + 3*(∫ m, info m.1 ∂Q.probability.toMeasure)-2*jMean Q+ + (4/5)*(∫ m, correction m.1 ∂Q.probability.toMeasure) := by + unfold functional + rw [integral_add (f := fun m : Message ↦ 3*info m.1-2*symEntropy m.1) + (g := fun m ↦ (4/5)*correction m.1) ((hI.const_mul _).sub (hJ.const_mul _)) (hB.const_mul _), + integral_sub (f := fun m : Message ↦ 3*info m.1) (g := fun m ↦ 2*symEntropy m.1) + (hI.const_mul _) (hJ.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] + rfl + have hFeid : (∫ m, functional (edgeMessage lam m) ∂Q.probability.toMeasure) = + 3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ + (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure) := by + unfold functional + rw [integral_add (f := fun m : Message ↦ 3*info (edgeMessage lam m)-2*symEntropy (edgeMessage lam m)) + (g := fun m ↦ (4/5)*correction (edgeMessage lam m)) ((hIe.const_mul _).sub (hJe.const_mul _)) (hBe.const_mul _), + integral_sub (f := fun m : Message ↦ 3*info (edgeMessage lam m)) (g := fun m ↦ 2*symEntropy (edgeMessage lam m)) + (hIe.const_mul _) (hJe.const_mul _), integral_const_mul, integral_const_mul, integral_const_mul] + rfl + rw [hFid, hFeid, hninv, hIid, hBid] at hrad + change jMean Q = (n:ℝ)*edgeJMean Q lam at hJid + change _ ≤ 3*((n:ℝ)*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-correlationEntropy Q lam n)- + 2*jMean Q+(4/5)*((n:ℝ)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)+ + 2*((n:ℝ)^2-n)*(edgeJMean Q lam)^2)- + (n:ℝ)*(3*(∫ m, info (edgeMessage lam m) ∂Q.probability.toMeasure)-2*edgeJMean Q lam+ + (4/5)*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure)) at hrad + have he : ((n:ℝ)^2-n)*(edgeJMean Q lam)^2 = (1-lam^2)*(jMean Q)^2 := by + rw [fixed_edgeJ Q hl₀ hl₁ n hcrit hfixed] + have hn : ((n:ℝ)^2-n)*lam^4 = 1-lam^2 := by + nlinarith [sq_nonneg ((n:ℝ)*lam^2-1), hcrit] + calc + _ = (((n:ℝ)^2-n)*lam^4)*(jMean Q)^2 := by ring + _ = _ := by rw [hn] + nlinarith [hJid, he] + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +namespace ThreeState.TreeClauses.Positive + +lemma qExact_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : + (37/81:ℝ) ≤ qExact lam := by + unfold qExact + apply (le_div_iff₀ (by positivity : 0 < 2+lam)).2 + linarith + +lemma cExact_lower {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : + cLower lam ≤ cExact lam := by + have hq := qExact_lower hl₀ hl₁ + unfold cExact cLower + nlinarith [mul_nonneg hl₀ (sub_nonneg.mpr hq)] + +lemma qExact_coefficient {lam : ℝ} : + 8*(37/27)*lam*qExact lam ≤ cExact lam^2 := by + unfold cExact + nlinarith [sq_nonneg ((37/27:ℝ)-2*lam*qExact lam)] + +lemma jMean_square_bound {lam mu nu J : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) + (hmu : 0 ≤ mu) (hnu : 0 ≤ nu) (hJ : 0 ≤ J) (hupper : J ≤ mu-lam*qExact lam*nu) + (hregion : cExact lam^2*nu ≤ mu) : + (8/5)*J^2 ≤ (8/5)*mu^2-(113/81)*lam*mu*nu := by + let t := lam*qExact lam*nu + have hq := qExact_lower hl₀ hl₁ + have ht : 0 ≤ t := by dsimp [t]; positivity + have hc := mul_le_mul_of_nonneg_right (qExact_coefficient (lam := lam)) hnu + have htu : 8*(37/27)*t ≤ mu := by dsimp [t]; nlinarith + have hJsq : J^2 ≤ (mu-t)^2 := by + have hu : J ≤ mu-t := hupper + nlinarith + have htt : t^2 ≤ (27/296)*mu*t := by + have hh := mul_le_mul_of_nonneg_right htu ht + nlinarith + have htl : (37/81)*lam*nu ≤ t := by + dsimp [t] + nlinarith [mul_nonneg (mul_nonneg hl₀ hnu) (sub_nonneg.mpr hq)] + have hm := mul_le_mul_of_nonneg_left htl hmu + nlinarith + +lemma strict_correlation_coefficient : (1:ℝ)/Real.sqrt 2+17/25 < 113/81 := by + have hs := Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2) + have hp := Real.sqrt_pos.mpr (by norm_num : (0:ℝ) < 2) + have hh : (2025:ℝ)/1448 < Real.sqrt 2 := by nlinarith + have hfrac : (1:ℝ)/Real.sqrt 2 < 1448/2025 := (div_lt_iff₀ hp).2 (by nlinarith) + linarith + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Positive +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Experiment + +theorem regular_fixed_mu_zero (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) + (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : Q.mu = 0 := by + by_contra hmu0 + have hmu : 0 < Q.mu := lt_of_le_of_ne Q.mu_nonneg (Ne.symm hmu0) + have hnu : 0 < Q.nu := (sq_pos_of_pos hmu).trans_le Q.second_moment_lower + have hinfo := regular_fixed_moment_bounds Q hl₀ hl₁ n hcrit hfixed + have hcl := cExact_lower hl₀.le hl₁.le + have hc : 0 < cExact lam := (cLower_pos hl₀.le).trans_le hcl + have hetaNonneg : 0 ≤ Q.eta := (mul_nonneg hc.le hnu.le).trans hinfo.2.2 + have hsq : (cExact lam*Q.nu)^2 ≤ Q.eta^2 := + (sq_le_sq₀ (mul_nonneg hc.le hnu.le) hetaNonneg).2 hinfo.2.2 + have hregion : cExact lam^2*Q.nu ≤ Q.mu := by + apply (mul_le_mul_iff_right₀ hnu).mp + nlinarith [Q.moment_discriminant] + have hmuC : Q.mu*cExact lam^2 ≤ 1 := by + apply (mul_le_mul_iff_right₀ hmu).mp + have hh := mul_le_mul_of_nonneg_left Q.second_moment_lower (sq_nonneg (cExact lam)) + nlinarith + have hregionLower : Q.mu*cLower lam^2 ≤ 1 := by + have hs : cLower lam^2 ≤ cExact lam^2 := + (sq_le_sq₀ (cLower_pos hl₀.le).le hc.le).2 hcl + exact (mul_le_mul_of_nonneg_left hs hmu.le).trans hmuC + have hlam : lam^2 ≤ 1/2 := by + have hn' : (2:ℝ) ≤ n := by exact_mod_cast hn + have hh := mul_le_mul_of_nonneg_right hn' (sq_nonneg lam) + nlinarith [hcrit] + have hstrict := scalar_strict hl₀ hl₁ hmu.le (by norm_num : (0:ℝ) < 1) + (le_refl (1:ℝ)) hregionLower (Or.inl hlam) + have hJ := jMean_square_bound hl₀.le hl₁.le hmu.le hnu.le hinfo.1 hinfo.2.1 hregion + have hH := regular_fixed_correlation_bounds Q hl₀ hl₁ n hn hcrit hfixed + have hrad := regular_fixed_entropy_radial Q hl₀ hl₁ n hcrit hfixed + have halpha : 0 < 1-lam^2 := by nlinarith + have hent : Q.nu/2+3*correlationEntropy Q lam n/(1-lam^2) ≤ (8/5)*(jMean Q)^2 := by + calc + _ = ((1-lam^2)/2*Q.nu+3*correlationEntropy Q lam n)/(1-lam^2) := by + field_simp [ne_of_gt halpha] + _ ≤ _ := (div_le_iff₀ halpha).2 (by nlinarith) + have hH' : 3*Q.mu^2/(2*(1+2*Q.mu/3))-(1/Real.sqrt 2)*(lam*Q.mu*Q.nu) ≤ + 3*correlationEntropy Q lam n/(1-lam^2) := by + convert hH using 1 + ring + have hg := mul_le_mul_of_nonneg_right (le_of_lt strict_correlation_coefficient) + (show 0 ≤ lam*Q.mu*Q.nu by positivity) + have hb : Q.nu/2+3*Q.mu^2/(2*(1+2*Q.mu/3))+(17/25)*lam*Q.mu*Q.nu ≤ (8/5)*Q.mu^2 := by + nlinarith + have hcoef : 0 ≤ (1-lam^2)/2+17*lam*Q.mu/25 := by positivity + have hsub := mul_le_mul_of_nonneg_left Q.second_moment_lower hcoef + have hnecessary : scalarT lam Q.mu 1*Q.mu^2 ≤ (8/5)*Q.mu^2 := by + calc + _ = ((1-lam^2)/2+17*lam*Q.mu/25)*Q.mu^2+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by + unfold scalarT; ring + _ ≤ ((1-lam^2)/2+17*lam*Q.mu/25)*Q.nu+3*Q.mu^2/(2*(1+2*Q.mu/3)) := by linarith + _ ≤ _ := by nlinarith [mul_nonneg (sq_nonneg lam) hnu.le] + have hh := mul_lt_mul_of_pos_right hstrict (sq_pos_of_pos hmu) + linarith + +lemma message_uniform_of_x_zero {m : Message} (h : xMoment m = 0) : m.1 = fun _ ↦ 1 := by + dsimp [xMoment, momentX, centered, avg] at h + funext i + fin_cases i <;> dsimp <;> nlinarith [sq_nonneg (m.1 0-1), sq_nonneg (m.1 1-1), sq_nonneg (m.1 2-1)] + +theorem regular_fixed_uniform (Q : Law) {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (n : ℕ) (hn : 2 ≤ n) (hcrit : (n:ℝ)*lam^2 = 1) + (hfixed : Q.probability = finiteProbability Q hl₀.le hl₁ n) : + ∀ᵐ m ∂Q.probability.toMeasure, m.1 = fun _ ↦ 1 := by + have hzero := regular_fixed_mu_zero Q hl₀ hl₁ n hn hcrit hfixed + have he : ∀ᵐ m ∂Q.probability.toMeasure, xMoment m = 0 := + (integral_eq_zero_iff_of_nonneg xMoment_nonneg (compact_integrable continuous_xMoment)).1 hzero + exact he.mono (fun _ hm ↦ message_uniform_of_x_zero hm) + +end ThreeState.TreeClauses.Positive + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PositiveMoments.lean b/lean/OAI/Probability/ThreeStateClauses/PositiveMoments.lean index fbc9e0ecef525f162de12bf4dd2f7ac401f12bd4..5e0f876ee879d0ced37e519d9f389beadb9d2fe4 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PositiveMoments.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PositiveMoments.lean @@ -1,429 +1,429 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RadialBounds - -namespace OAI - -/-! Positive Moments. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Positive -open Radial - -def fourthResolvent (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i^4/(1+t*v i)) - -def fourthEdgeResolvent (v : Vec) (lam t : ℝ) : ℝ := - avg (fun i ↦ v i^4/((1+t*v i)*(1+t*lam*v i))) - -def momentA (m : Vec) : ℝ := ∫ t in (0:ℝ)..1, t^2*fourthResolvent (centered m) t - -def momentQ (m : Vec) (lam : ℝ) : ℝ := - (1/2)*∫ t in (0:ℝ)..1, t^2*fourthEdgeResolvent (centered m) lam t - -lemma fourthMoment {v : Vec} (hv : avg v = 0) : - avg (fun i ↦ v i^4) = 6*momentX v^2 := by - simp only [momentX, avg]; rw [third_eq hv]; ring - -lemma fourthResolvent_eq {v : Vec} (hv : avg v = 0) {t : ℝ} - (hp : ∀ i, 1+t*v i ≠ 0) (hD : denom v t ≠ 0) : - fourthResolvent v t = - (6*momentX v^2-10*t*momentX v*momentY v+4*t^2*momentY v^2)/denom v t := by - have he (i : Fin 3) : v i^4/(1+t*v i) = - (v i^3*(v i-t*v i^2+2*t^2*momentY v))/denom v t := by - calc - _ = v i^3*(v i/(1+t*v i)) := by ring - _ = _ := by rw [rational_identity hv t i (hp i) hD]; ring - simp only [fourthResolvent, he, avg_div] - congr 1 - simp only [momentX, momentY, avg] - rw [third_eq hv]; ring - -lemma fraction_lower {z k : ℝ} (hz₀ : 0 ≤ z) (hz₁ : z < 1) - (_hk₀ : -1 ≤ k) (hk₁ : k ≤ 1) (hD : 0 < 1-3*z^2+2*z^3*k) : - 4+(64/9)*(z-1/2)^2 ≤ (6-10*z*k+4*z^2*k^2)/(1-3*z^2+2*z^3*k) := by - have hB : 0 < 1+z-2*z^2 := by nlinarith [mul_pos (by linarith : 0 < 1-z) (by linarith : 0 < 1+2*z)] - have hBtop : 1+z-2*z^2 ≤ 9/8 := by nlinarith [sq_nonneg (z-1/4)] - have hnum : 6-10*z+4*z^2 ≤ 6-10*z*k+4*z^2*k^2 := by - have hfac : 0 ≤ 10-4*z*(k+1) := by nlinarith [mul_nonneg hz₀ (by linarith : 0 ≤ 1-k)] - have := mul_nonneg (mul_nonneg hz₀ (by linarith : 0 ≤ 1-k)) hfac - nlinarith - have hnum0 : 0 ≤ 6-10*z+4*z^2 := by - nlinarith [mul_nonneg (by linarith : 0 ≤ 1-z) (by linarith : 0 ≤ 6-4*z)] - have hden : 1-3*z^2+2*z^3*k ≤ 1-3*z^2+2*z^3 := by - nlinarith [mul_nonneg (pow_nonneg hz₀ 3) (by linarith : 0 ≤ 1-k)] - have hdenpos : 0 < 1-3*z^2+2*z^3 := lt_of_lt_of_le hD hden - have heq : (6-10*z+4*z^2)/(1-3*z^2+2*z^3) = (6-4*z)/(1+z-2*z^2) := by - apply (div_eq_div_iff (ne_of_gt hdenpos) (ne_of_gt hB)).2 - ring - have hbase : 4+(64/9)*(z-1/2)^2 ≤ (6-4*z)/(1+z-2*z^2) := by - apply (le_div_iff₀ hB).2 - have := mul_nonneg (sq_nonneg (z-1/2)) (sub_nonneg.mpr hBtop) - nlinarith - calc - _ ≤ (6-4*z)/(1+z-2*z^2) := hbase - _ = (6-10*z+4*z^2)/(1-3*z^2+2*z^3) := heq.symm - _ ≤ (6-10*z+4*z^2)/(1-3*z^2+2*z^3*k) := - div_le_div_of_nonneg_left hnum0 hD hden - _ ≤ _ := (div_le_div_iff_of_pos_right hD).2 hnum - -lemma fourthResolvent_nonneg {m : Vec} (hm : PositiveMessage m) - {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ fourthResolvent (centered m) t := by - have hi (i : Fin 3) : 0 ≤ centered m i^4/(1+t*centered m i) := - div_nonneg (by positivity) (edge_pos hm ht i).le - unfold fourthResolvent avg - exact div_nonneg (add_nonneg (add_nonneg (hi 0) (hi 1)) (hi 2)) (by norm_num) - -lemma fourthResolvent_lower {m : Vec} (hm : PositiveMessage m) {t : ℝ} - (ht : t ∈ Icc (0:ℝ) 1) : - (4+(64/9)*(t*Real.sqrt (momentX (centered m))-1/2)^2)*momentX (centered m)^2 ≤ - fourthResolvent (centered m) t := by - let v := centered m - let x := momentX v - let y := momentY v - have hx₀ : 0 ≤ x := momentX_nonneg v - have hx₁ : x < 1 := momentX_lt_one hm - by_cases hx : x = 0 - · have hn := fourthResolvent_nonneg hm ht - change (4+(64/9)*(t*Real.sqrt x-1/2)^2)*x^2 ≤ fourthResolvent v t - simpa [hx] using hn - have hxpos : 0 < x := lt_of_le_of_ne hx₀ (Ne.symm hx) - let r := Real.sqrt x - have hrpos : 0 < r := Real.sqrt_pos.mpr hxpos - have hr2 : r^2 = x := Real.sq_sqrt hx₀ - have hr₁ : r < 1 := by nlinarith - let k := y/r^3 - have hyr : y = k*r^3 := (div_mul_cancel₀ _ (pow_ne_zero 3 (ne_of_gt hrpos))).symm - have hk2 : k^2 ≤ 1 := by - have hxy : y^2 ≤ x^3 := moment_discriminant (avg_centered hm) - have heq : k^2 = y^2/r^6 := by dsimp [k]; ring - rw [heq, div_le_iff₀ (pow_pos hrpos 6)] - rw [← hr2] at hxy - nlinarith [hxy] - have hk₀ : -1 ≤ k := by nlinarith [sq_nonneg (k+1)] - have hk₁ : k ≤ 1 := by nlinarith [sq_nonneg (k-1)] - have hz₀ : 0 ≤ t*r := mul_nonneg ht.1 hrpos.le - have hz₁ : t*r < 1 := by nlinarith [ht.2] - have hD := denom_pos hm ht - have hDeq : denom v t = 1-3*(t*r)^2+2*(t*r)^3*k := by - dsimp only [denom] - change 1-3*t^2*x+2*t^3*y = _ - rw [← hr2, hyr]; ring - have hD' : 0 < 1-3*(t*r)^2+2*(t*r)^3*k := by rw [← hDeq]; exact hD - have heq : fourthResolvent v t = x^2*((6-10*(t*r)*k+4*(t*r)^2*k^2)/(1-3*(t*r)^2+2*(t*r)^3*k)) := by - rw [fourthResolvent_eq (avg_centered hm) (fun i ↦ ne_of_gt (edge_pos hm ht i)) (ne_of_gt hD), hDeq] - change (6*x^2-10*t*x*y+4*t^2*y^2)/_ = _ - rw [← hr2, hyr]; ring - change (4+(64/9)*(t*r-1/2)^2)*x^2 ≤ fourthResolvent v t - rw [heq, mul_comm (x^2)] - exact mul_le_mul_of_nonneg_right (fraction_lower hz₀ hz₁ hk₀ hk₁ hD') (sq_nonneg x) - -lemma fourthResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) : - ContinuousOn (fourthResolvent (centered m)) (Icc (0:ℝ) 1) := by - have hi (i : Fin 3) : ContinuousOn (fun t : ℝ ↦ centered m i^4/(1+t*centered m i)) (Icc 0 1) := - continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht i)) - exact (((hi 0).add (hi 1)).add (hi 2)).div_const 3 - -lemma lower_integral (r x : ℝ) : - (∫ t in (0:ℝ)..1, t^2*((4+(64/9)*(t*r-1/2)^2)*x^2)) = - (37/27+(64/45)*(r-5/8)^2)*x^2 := by - conv_lhs => arg 1; ext t; ring_nf - simp (disch := apply Continuous.intervalIntegrable; fun_prop) only - [intervalIntegral.integral_add, intervalIntegral.integral_mul_const, integral_pow] - norm_num - ring - -theorem momentA_lower {m : Vec} (hm : PositiveMessage m) : - (37/27)*momentX (centered m)^2 ≤ momentA m := by - have hcr : ContinuousOn (fun t : ℝ ↦ t^2*fourthResolvent (centered m) t) (Icc 0 1) := - (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul (fourthResolvent_continuousOn hm) - have hcl : Continuous (fun t : ℝ ↦ t^2*((4+(64/9)*(t*Real.sqrt (momentX (centered m))-1/2)^2)*momentX (centered m)^2)) := by fun_prop - have hi := intervalIntegral.integral_mono_on (μ := volume) (by norm_num : (0:ℝ) ≤ 1) - (hcl.intervalIntegrable 0 1) (hcr.intervalIntegrable_of_Icc (by norm_num)) - (fun t ht ↦ mul_le_mul_of_nonneg_left (fourthResolvent_lower hm ht) (sq_nonneg t)) - rw [lower_integral] at hi - have hn : 0 ≤ (Real.sqrt (momentX (centered m))-5/8)^2*momentX (centered m)^2 := by positivity - dsimp only [momentA] - linarith - -lemma avg_mono {a b : Vec} (h : ∀ i, a i ≤ b i) : avg a ≤ avg b := by - unfold avg - exact div_le_div_of_nonneg_right (add_le_add (add_le_add (h 0) (h 1)) (h 2)) (by norm_num) - -lemma fourthResolvent_four {m : Vec} (hm : PositiveMessage m) {t : ℝ} - (ht : t ∈ Icc (0:ℝ) 1) : 4*momentX (centered m)^2 ≤ fourthResolvent (centered m) t := by - have h := fourthResolvent_lower hm ht - nlinarith [mul_nonneg (sq_nonneg (t*Real.sqrt (momentX (centered m))-1/2)) - (sq_nonneg (momentX (centered m)))] - -lemma fourthEdgeResolvent_lower {m : Vec} (hm : PositiveMessage m) {lam t : ℝ} - (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) (ht : t ∈ Icc (0:ℝ) 1) : - (2/(2+lam))*fourthResolvent (centered m) t ≤ fourthEdgeResolvent (centered m) lam t := by - let v := centered m - let a : Vec := fun i ↦ v i^4/(1+t*v i) - let b : Vec := fun i ↦ 1+t*lam*v i - let c : ℝ := 1+lam/2 - have hc : 0 < c := by dsimp [c]; linarith - have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl₀, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl₁ ht.1]⟩ - have hb (i : Fin 3) : 0 < b i := by dsimp [b]; exact edge_pos hm htl i - have ha (i : Fin 3) : 0 ≤ a i := div_nonneg (by positivity) (edge_pos hm ht i).le - have hab (i : Fin 3) : a i*b i = (1-lam)*a i+lam*v i^4 := by - dsimp only [a, b] - have hd : 1+t*v i ≠ 0 := ne_of_gt (edge_pos hm ht i) - calc - _ = (v i^4/(1+t*v i))*((1-lam)+lam*(1+t*v i)) := by ring - _ = (1-lam)*(v i^4/(1+t*v i))+lam*((v i^4/(1+t*v i))*(1+t*v i)) := by ring - _ = _ := by rw [div_mul_cancel₀ _ hd] - have habavg : avg (fun i ↦ a i*b i) = (1-lam)*fourthResolvent v t+6*lam*momentX v^2 := by - simp_rw [hab] - rw [avg_add, avg_mul, avg_mul, fourthMoment (avg_centered hm)] - change (1-lam)*fourthResolvent v t+lam*(6*momentX v^2) = _ - ring - have havga : avg a = fourthResolvent v t := rfl - have havgab : avg (fun i ↦ a i/b i) = fourthEdgeResolvent v lam t := by - simp only [a, b, fourthEdgeResolvent, div_div] - have htangent (i : Fin 3) : a i*(2*c-b i) ≤ c^2*(a i/b i) := by - rw [← mul_div_assoc] - apply (le_div_iff₀ (hb i)).2 - nlinarith [mul_nonneg (ha i) (sq_nonneg (b i-c))] - have hs : 2*c*fourthResolvent v t-((1-lam)*fourthResolvent v t+6*lam*momentX v^2) ≤ - c^2*fourthEdgeResolvent v lam t := by - calc - _ = avg (fun i ↦ a i*(2*c-b i)) := by - rw [← habavg, ← havga] - simp only [avg]; ring - _ ≤ avg (fun i ↦ c^2*(a i/b i)) := avg_mono htangent - _ = _ := by rw [avg_mul, havgab] - have hfour := fourthResolvent_four hm ht - have hh : 0 ≤ lam*((3/2)*fourthResolvent v t-6*momentX v^2) := - mul_nonneg hl₀ (by linarith) - have hd : 0 ≤ c*(c*fourthEdgeResolvent v lam t-fourthResolvent v t) := by - dsimp only [c] at hs ⊢ - nlinarith - have hh' := (mul_nonneg_iff_of_pos_left hc).mp hd - have hfinal : fourthResolvent v t/c ≤ fourthEdgeResolvent v lam t := by - apply (div_le_iff₀ hc).2 - nlinarith - have heq : (2/(2+lam))*fourthResolvent v t = fourthResolvent v t/c := by - dsimp [c] - field_simp - rw [heq] - exact hfinal - -lemma fourthEdgeResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : - ContinuousOn (fourthEdgeResolvent (centered m) lam) (Icc (0:ℝ) 1) := by - have hi (i : Fin 3) : ContinuousOn - (fun t : ℝ ↦ centered m i^4/((1+t*centered m i)*(1+t*lam*centered m i))) (Icc 0 1) := by - apply continuousOn_const.div (by fun_prop) - intro t ht - have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl₀, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl₁ ht.1]⟩ - exact ne_of_gt (mul_pos (edge_pos hm ht i) (edge_pos hm htl i)) - exact (((hi 0).add (hi 1)).add (hi 2)).div_const 3 - -theorem momentQ_lower {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : momentA m/(2+lam) ≤ momentQ m lam := by - have hcr : ContinuousOn (fun t : ℝ ↦ t^2*fourthEdgeResolvent (centered m) lam t) (Icc 0 1) := - (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul (fourthEdgeResolvent_continuousOn hm hl₀ hl₁) - have hcl : ContinuousOn (fun t : ℝ ↦ t^2*((2/(2+lam))*fourthResolvent (centered m) t)) (Icc 0 1) := - (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul - (continuousOn_const.mul (fourthResolvent_continuousOn hm)) - have hi := intervalIntegral.integral_mono_on (μ := volume) (by norm_num : (0:ℝ) ≤ 1) - (hcl.intervalIntegrable_of_Icc (by norm_num)) (hcr.intervalIntegrable_of_Icc (by norm_num)) - (fun t ht ↦ mul_le_mul_of_nonneg_left (fourthEdgeResolvent_lower hm hl₀ hl₁ ht) (sq_nonneg t)) - have he : (∫ t in (0:ℝ)..1, t^2*((2/(2+lam))*fourthResolvent (centered m) t)) = - (2/(2+lam))*momentA m := by - rw [momentA, ← intervalIntegral.integral_const_mul] - congr 1; funext t; ring - rw [he] at hi - have heq : (2/(2+lam))*momentA m = 2*(momentA m/(2+lam)) := by ring - rw [heq] at hi - dsimp only [momentQ] - linarith - -end ThreeState.TreeClauses.Positive - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Positive -open Radial - -def residual (m : Vec) (lam : ℝ) : ℝ := - ∫ t in (0:ℝ)..1, t*avg (fun i ↦ centered m i^3 / - ((1+t*centered m i)*(1+t*lam*centered m i))) - -lemma avg_integrable {f : ℝ → Vec} (h : ∀ i, IntervalIntegrable (fun t ↦ f t i) volume 0 1) : - IntervalIntegrable (fun t ↦ avg (f t)) volume 0 1 := - (((h 0).add (h 1)).add (h 2)).div_const 3 - -lemma avg_continuousOn {f : ℝ → Vec} {S : Set ℝ} (h : ∀ i, ContinuousOn (fun t ↦ f t i) S) : - ContinuousOn (fun t ↦ avg (f t)) S := - (((h 0).add (h 1)).add (h 2)).div_const 3 - -lemma edge_message {m : Vec} (hm : PositiveMessage m) {lam : ℝ} (hl : lam ∈ Icc (0:ℝ) 1) : - PositiveMessage (edge lam m) := by - refine ⟨fun i ↦ edge_pos hm hl i, ?_⟩ - change avg (fun i ↦ 1+lam*centered m i) = 1 - rw [avg_add, avg_const, avg_mul] - rw [avg_centered hm]; ring - -lemma centered_edge (m : Vec) (lam : ℝ) : centered (edge lam m) = fun i ↦ lam*centered m i := by - funext i; simp [centered, edge] - -lemma symEntropy_integral {m : Vec} (hm : PositiveMessage m) : - symEntropy m = (1/2)*∫ t in (0:ℝ)..1, avg (fun i ↦ centered m i^2/(1+t*centered m i)) := by - have hi (i : Fin 3) : IntervalIntegrable (fun t : ℝ ↦ centered m i^2/(1+t*centered m i)) volume 0 1 := - (continuousOn_const.div (by fun_prop : ContinuousOn (fun t : ℝ ↦ 1+t*centered m i) (Icc 0 1)) - (fun t ht ↦ ne_of_gt (edge_pos hm ht i))).intervalIntegrable_of_Icc (by norm_num) - rw [integral_avg hi] - have he (i : Fin 3) : (∫ t in (0:ℝ)..1, centered m i^2/(1+t*centered m i)) = - centered m i*Real.log (m i) := by - rw [← integral_log_edge hm i, ← intervalIntegral.integral_const_mul] - congr 1; funext t; ring - simp_rw [he] - simp only [symEntropy, centered, avg] - ring - -lemma symEntropy_nonneg {m : Vec} (hm : PositiveMessage m) : 0 ≤ symEntropy m := by - have hi (i : Fin 3) : 0 ≤ (m i-1)*Real.log (m i) := by - rcases le_total 1 (m i) with h | h - · exact mul_nonneg (sub_nonneg.mpr h) (Real.log_nonneg h) - · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr h) (Real.log_nonpos (hm.1 i).le h) - dsimp only [symEntropy, avg] - exact div_nonneg (div_nonneg (add_nonneg (add_nonneg (hi 0) (hi 1)) (hi 2)) (by norm_num)) (by norm_num) - -lemma residual_continuousOn {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl : lam ∈ Icc (0:ℝ) 1) : ContinuousOn - (fun t : ℝ ↦ t*avg (fun i ↦ centered m i^3/((1+t*centered m i)*(1+t*lam*centered m i)))) (Icc 0 1) := by - apply continuousOn_id.mul - apply avg_continuousOn - intro i - apply continuousOn_const.div (by fun_prop) - intro t ht - have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ - exact ne_of_gt (mul_pos (edge_pos hm ht i) (edge_pos hm htl i)) - -lemma symEntropy_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl : lam ∈ Icc (0:ℝ) 1) : - symEntropy m = momentX (centered m)-lam*momentQ m lam-residual m lam/2 := by - let v := centered m - have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by - apply (avg_continuousOn (fun i ↦ continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht i)))).intervalIntegrable_of_Icc - norm_num - have hq : IntervalIntegrable (fun t : ℝ ↦ t^2*fourthEdgeResolvent v lam t) volume 0 1 := - ((by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul - (fourthEdgeResolvent_continuousOn hm hl.1 hl.2)).intervalIntegrable_of_Icc (by norm_num) - have hr : IntervalIntegrable (fun t : ℝ ↦ t*avg (fun i ↦ centered m i^3/((1+t*centered m i)*(1+t*lam*centered m i)))) volume 0 1 := - (residual_continuousOn hm hl).intervalIntegrable_of_Icc (by norm_num) - have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*v i)) = - 2*momentX v-lam*(t^2*fourthEdgeResolvent v lam t)- - t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i))) := by - have he (i : Fin 3) : v i^2/(1+t*v i) = v i^2-lam*t^2*(v i^4/((1+t*v i)*(1+t*lam*v i)))- - t*(v i^3/((1+t*v i)*(1+t*lam*v i))) := by - have htlam : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ - have h₁ : 1+t*v i ≠ 0 := ne_of_gt (edge_pos hm ht i) - have h₂ : 1+t*lam*v i ≠ 0 := ne_of_gt (edge_pos hm htlam i) - have h₁' : 1+v i*t ≠ 0 := by simpa only [mul_comm] using h₁ - have h₂' : 1+v i*t*lam ≠ 0 := by convert h₂ using 1; ring - field_simp [h₁', h₂'] - ring - simp_rw [he] - rw [avg_sub, avg_sub, avg_mul, avg_mul] - dsimp only [momentX, fourthEdgeResolvent] - ring - rw [symEntropy_integral hm] - have hconvert := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) - rw [hconvert, intervalIntegral.integral_sub ((intervalIntegrable_const).sub (hq.const_mul lam)) hr, - intervalIntegral.integral_sub intervalIntegrable_const (hq.const_mul lam), - intervalIntegral.integral_const, intervalIntegral.integral_const_mul] - dsimp only [momentQ, residual] - ring - -lemma powerResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) (n : ℕ) - {lam : ℝ} (hl : lam ∈ Icc (0:ℝ) 1) : - ContinuousOn (fun t : ℝ ↦ avg (fun i ↦ centered m i^n/(1+t*lam*centered m i))) (Icc 0 1) := by - apply avg_continuousOn - intro i - apply continuousOn_const.div (by fun_prop) - intro t ht - have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ - exact ne_of_gt (edge_pos hm htl i) - -lemma edge_symEntropy_integral {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl : lam ∈ Icc (0:ℝ) 1) : - symEntropy (edge lam m) = (lam^2/2)*∫ t in (0:ℝ)..1, - avg (fun i ↦ centered m i^2/(1+t*lam*centered m i)) := by - rw [symEntropy_integral (edge_message hm hl), centered_edge] - have he (t : ℝ) : avg (fun i ↦ (lam*centered m i)^2/(1+t*(lam*centered m i))) = - lam^2*avg (fun i ↦ centered m i^2/(1+t*lam*centered m i)) := by - dsimp only [avg]; ring - simp_rw [he] - rw [intervalIntegral.integral_const_mul] - ring - -lemma symEntropy_edge_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl : lam ∈ Icc (0:ℝ) 1) : - symEntropy (edge lam m) = lam^2*(symEntropy m+(1-lam)*residual m lam/2) := by - let v := centered m - have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by - simpa using (powerResolvent_continuousOn hm 2 (by norm_num : (1:ℝ) ∈ Icc 0 1)).intervalIntegrable_of_Icc (μ := volume) (by norm_num) - have hr : IntervalIntegrable (fun t : ℝ ↦ t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i)))) volume 0 1 := - (residual_continuousOn hm hl).intervalIntegrable_of_Icc (by norm_num) - have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*lam*v i)) = - avg (fun i ↦ v i^2/(1+t*v i))+(1-lam)*(t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i)))) := by - have he (i : Fin 3) : v i^2/(1+t*lam*v i) = v i^2/(1+t*v i)+ - (1-lam)*t*(v i^3/((1+t*v i)*(1+t*lam*v i))) := by - have htlam : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ - have h₁ : 1+v i*t ≠ 0 := by simpa only [mul_comm] using ne_of_gt (edge_pos hm ht i) - have h₂ : 1+v i*t*lam ≠ 0 := by convert ne_of_gt (edge_pos hm htlam i) using 1; ring - field_simp [h₁, h₂] - ring - simp_rw [he] - rw [avg_add, avg_mul] - ring - rw [edge_symEntropy_integral hm hl, symEntropy_integral hm] - have he := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) - rw [he, intervalIntegral.integral_add hi (hr.const_mul (1-lam)), intervalIntegral.integral_const_mul] - dsimp only [residual] - ring - -lemma momentA_identity {m : Vec} (hm : PositiveMessage m) : - momentA m = momentY (centered m)-2*momentX (centered m)+2*symEntropy m := by - let v := centered m - have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by - simpa using (powerResolvent_continuousOn hm 2 (by norm_num : (1:ℝ) ∈ Icc 0 1)).intervalIntegrable_of_Icc (μ := volume) (by norm_num) - have ha : IntervalIntegrable (fun t : ℝ ↦ t^2*fourthResolvent v t) volume 0 1 := - ((by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul - (fourthResolvent_continuousOn hm)).intervalIntegrable_of_Icc (by norm_num) - have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*v i)) = - 2*momentX v-t*(2*momentY v)+t^2*fourthResolvent v t := by - have he (i : Fin 3) : v i^2/(1+t*v i) = v i^2-t*v i^3+t^2*(v i^4/(1+t*v i)) := by - have h₁ : 1+v i*t ≠ 0 := by simpa only [mul_comm] using ne_of_gt (edge_pos hm ht i) - field_simp [h₁] - ring - simp_rw [he] - rw [avg_add, avg_sub, avg_mul, avg_mul] - dsimp only [momentX, momentY, fourthResolvent] - ring - have he := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) - rw [symEntropy_integral hm, he] - rw [intervalIntegral.integral_add (by apply Continuous.intervalIntegrable; fun_prop) ha, - intervalIntegral.integral_sub intervalIntegrable_const (by apply Continuous.intervalIntegrable; fun_prop), - intervalIntegral.integral_const, intervalIntegral.integral_mul_const, integral_id] - dsimp only [momentA] - ring - -lemma momentY_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} - (hl : lam ∈ Icc (0:ℝ) 1) : - momentY (centered m) = momentA m+2*lam*momentQ m lam+residual m lam := by - rw [momentA_identity hm, symEntropy_residual hm hl] - ring - -end ThreeState.TreeClauses.Positive - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RadialBounds + +namespace OAI + +/-! Positive Moments. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Positive +open Radial + +def fourthResolvent (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i^4/(1+t*v i)) + +def fourthEdgeResolvent (v : Vec) (lam t : ℝ) : ℝ := + avg (fun i ↦ v i^4/((1+t*v i)*(1+t*lam*v i))) + +def momentA (m : Vec) : ℝ := ∫ t in (0:ℝ)..1, t^2*fourthResolvent (centered m) t + +def momentQ (m : Vec) (lam : ℝ) : ℝ := + (1/2)*∫ t in (0:ℝ)..1, t^2*fourthEdgeResolvent (centered m) lam t + +lemma fourthMoment {v : Vec} (hv : avg v = 0) : + avg (fun i ↦ v i^4) = 6*momentX v^2 := by + simp only [momentX, avg]; rw [third_eq hv]; ring + +lemma fourthResolvent_eq {v : Vec} (hv : avg v = 0) {t : ℝ} + (hp : ∀ i, 1+t*v i ≠ 0) (hD : denom v t ≠ 0) : + fourthResolvent v t = + (6*momentX v^2-10*t*momentX v*momentY v+4*t^2*momentY v^2)/denom v t := by + have he (i : Fin 3) : v i^4/(1+t*v i) = + (v i^3*(v i-t*v i^2+2*t^2*momentY v))/denom v t := by + calc + _ = v i^3*(v i/(1+t*v i)) := by ring + _ = _ := by rw [rational_identity hv t i (hp i) hD]; ring + simp only [fourthResolvent, he, avg_div] + congr 1 + simp only [momentX, momentY, avg] + rw [third_eq hv]; ring + +lemma fraction_lower {z k : ℝ} (hz₀ : 0 ≤ z) (hz₁ : z < 1) + (_hk₀ : -1 ≤ k) (hk₁ : k ≤ 1) (hD : 0 < 1-3*z^2+2*z^3*k) : + 4+(64/9)*(z-1/2)^2 ≤ (6-10*z*k+4*z^2*k^2)/(1-3*z^2+2*z^3*k) := by + have hB : 0 < 1+z-2*z^2 := by nlinarith [mul_pos (by linarith : 0 < 1-z) (by linarith : 0 < 1+2*z)] + have hBtop : 1+z-2*z^2 ≤ 9/8 := by nlinarith [sq_nonneg (z-1/4)] + have hnum : 6-10*z+4*z^2 ≤ 6-10*z*k+4*z^2*k^2 := by + have hfac : 0 ≤ 10-4*z*(k+1) := by nlinarith [mul_nonneg hz₀ (by linarith : 0 ≤ 1-k)] + have := mul_nonneg (mul_nonneg hz₀ (by linarith : 0 ≤ 1-k)) hfac + nlinarith + have hnum0 : 0 ≤ 6-10*z+4*z^2 := by + nlinarith [mul_nonneg (by linarith : 0 ≤ 1-z) (by linarith : 0 ≤ 6-4*z)] + have hden : 1-3*z^2+2*z^3*k ≤ 1-3*z^2+2*z^3 := by + nlinarith [mul_nonneg (pow_nonneg hz₀ 3) (by linarith : 0 ≤ 1-k)] + have hdenpos : 0 < 1-3*z^2+2*z^3 := lt_of_lt_of_le hD hden + have heq : (6-10*z+4*z^2)/(1-3*z^2+2*z^3) = (6-4*z)/(1+z-2*z^2) := by + apply (div_eq_div_iff (ne_of_gt hdenpos) (ne_of_gt hB)).2 + ring + have hbase : 4+(64/9)*(z-1/2)^2 ≤ (6-4*z)/(1+z-2*z^2) := by + apply (le_div_iff₀ hB).2 + have := mul_nonneg (sq_nonneg (z-1/2)) (sub_nonneg.mpr hBtop) + nlinarith + calc + _ ≤ (6-4*z)/(1+z-2*z^2) := hbase + _ = (6-10*z+4*z^2)/(1-3*z^2+2*z^3) := heq.symm + _ ≤ (6-10*z+4*z^2)/(1-3*z^2+2*z^3*k) := + div_le_div_of_nonneg_left hnum0 hD hden + _ ≤ _ := (div_le_div_iff_of_pos_right hD).2 hnum + +lemma fourthResolvent_nonneg {m : Vec} (hm : PositiveMessage m) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ fourthResolvent (centered m) t := by + have hi (i : Fin 3) : 0 ≤ centered m i^4/(1+t*centered m i) := + div_nonneg (by positivity) (edge_pos hm ht i).le + unfold fourthResolvent avg + exact div_nonneg (add_nonneg (add_nonneg (hi 0) (hi 1)) (hi 2)) (by norm_num) + +lemma fourthResolvent_lower {m : Vec} (hm : PositiveMessage m) {t : ℝ} + (ht : t ∈ Icc (0:ℝ) 1) : + (4+(64/9)*(t*Real.sqrt (momentX (centered m))-1/2)^2)*momentX (centered m)^2 ≤ + fourthResolvent (centered m) t := by + let v := centered m + let x := momentX v + let y := momentY v + have hx₀ : 0 ≤ x := momentX_nonneg v + have hx₁ : x < 1 := momentX_lt_one hm + by_cases hx : x = 0 + · have hn := fourthResolvent_nonneg hm ht + change (4+(64/9)*(t*Real.sqrt x-1/2)^2)*x^2 ≤ fourthResolvent v t + simpa [hx] using hn + have hxpos : 0 < x := lt_of_le_of_ne hx₀ (Ne.symm hx) + let r := Real.sqrt x + have hrpos : 0 < r := Real.sqrt_pos.mpr hxpos + have hr2 : r^2 = x := Real.sq_sqrt hx₀ + have hr₁ : r < 1 := by nlinarith + let k := y/r^3 + have hyr : y = k*r^3 := (div_mul_cancel₀ _ (pow_ne_zero 3 (ne_of_gt hrpos))).symm + have hk2 : k^2 ≤ 1 := by + have hxy : y^2 ≤ x^3 := moment_discriminant (avg_centered hm) + have heq : k^2 = y^2/r^6 := by dsimp [k]; ring + rw [heq, div_le_iff₀ (pow_pos hrpos 6)] + rw [← hr2] at hxy + nlinarith [hxy] + have hk₀ : -1 ≤ k := by nlinarith [sq_nonneg (k+1)] + have hk₁ : k ≤ 1 := by nlinarith [sq_nonneg (k-1)] + have hz₀ : 0 ≤ t*r := mul_nonneg ht.1 hrpos.le + have hz₁ : t*r < 1 := by nlinarith [ht.2] + have hD := denom_pos hm ht + have hDeq : denom v t = 1-3*(t*r)^2+2*(t*r)^3*k := by + dsimp only [denom] + change 1-3*t^2*x+2*t^3*y = _ + rw [← hr2, hyr]; ring + have hD' : 0 < 1-3*(t*r)^2+2*(t*r)^3*k := by rw [← hDeq]; exact hD + have heq : fourthResolvent v t = x^2*((6-10*(t*r)*k+4*(t*r)^2*k^2)/(1-3*(t*r)^2+2*(t*r)^3*k)) := by + rw [fourthResolvent_eq (avg_centered hm) (fun i ↦ ne_of_gt (edge_pos hm ht i)) (ne_of_gt hD), hDeq] + change (6*x^2-10*t*x*y+4*t^2*y^2)/_ = _ + rw [← hr2, hyr]; ring + change (4+(64/9)*(t*r-1/2)^2)*x^2 ≤ fourthResolvent v t + rw [heq, mul_comm (x^2)] + exact mul_le_mul_of_nonneg_right (fraction_lower hz₀ hz₁ hk₀ hk₁ hD') (sq_nonneg x) + +lemma fourthResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) : + ContinuousOn (fourthResolvent (centered m)) (Icc (0:ℝ) 1) := by + have hi (i : Fin 3) : ContinuousOn (fun t : ℝ ↦ centered m i^4/(1+t*centered m i)) (Icc 0 1) := + continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht i)) + exact (((hi 0).add (hi 1)).add (hi 2)).div_const 3 + +lemma lower_integral (r x : ℝ) : + (∫ t in (0:ℝ)..1, t^2*((4+(64/9)*(t*r-1/2)^2)*x^2)) = + (37/27+(64/45)*(r-5/8)^2)*x^2 := by + conv_lhs => arg 1; ext t; ring_nf + simp (disch := apply Continuous.intervalIntegrable; fun_prop) only + [intervalIntegral.integral_add, intervalIntegral.integral_mul_const, integral_pow] + norm_num + ring + +theorem momentA_lower {m : Vec} (hm : PositiveMessage m) : + (37/27)*momentX (centered m)^2 ≤ momentA m := by + have hcr : ContinuousOn (fun t : ℝ ↦ t^2*fourthResolvent (centered m) t) (Icc 0 1) := + (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul (fourthResolvent_continuousOn hm) + have hcl : Continuous (fun t : ℝ ↦ t^2*((4+(64/9)*(t*Real.sqrt (momentX (centered m))-1/2)^2)*momentX (centered m)^2)) := by fun_prop + have hi := intervalIntegral.integral_mono_on (μ := volume) (by norm_num : (0:ℝ) ≤ 1) + (hcl.intervalIntegrable 0 1) (hcr.intervalIntegrable_of_Icc (by norm_num)) + (fun t ht ↦ mul_le_mul_of_nonneg_left (fourthResolvent_lower hm ht) (sq_nonneg t)) + rw [lower_integral] at hi + have hn : 0 ≤ (Real.sqrt (momentX (centered m))-5/8)^2*momentX (centered m)^2 := by positivity + dsimp only [momentA] + linarith + +lemma avg_mono {a b : Vec} (h : ∀ i, a i ≤ b i) : avg a ≤ avg b := by + unfold avg + exact div_le_div_of_nonneg_right (add_le_add (add_le_add (h 0) (h 1)) (h 2)) (by norm_num) + +lemma fourthResolvent_four {m : Vec} (hm : PositiveMessage m) {t : ℝ} + (ht : t ∈ Icc (0:ℝ) 1) : 4*momentX (centered m)^2 ≤ fourthResolvent (centered m) t := by + have h := fourthResolvent_lower hm ht + nlinarith [mul_nonneg (sq_nonneg (t*Real.sqrt (momentX (centered m))-1/2)) + (sq_nonneg (momentX (centered m)))] + +lemma fourthEdgeResolvent_lower {m : Vec} (hm : PositiveMessage m) {lam t : ℝ} + (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) (ht : t ∈ Icc (0:ℝ) 1) : + (2/(2+lam))*fourthResolvent (centered m) t ≤ fourthEdgeResolvent (centered m) lam t := by + let v := centered m + let a : Vec := fun i ↦ v i^4/(1+t*v i) + let b : Vec := fun i ↦ 1+t*lam*v i + let c : ℝ := 1+lam/2 + have hc : 0 < c := by dsimp [c]; linarith + have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl₀, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl₁ ht.1]⟩ + have hb (i : Fin 3) : 0 < b i := by dsimp [b]; exact edge_pos hm htl i + have ha (i : Fin 3) : 0 ≤ a i := div_nonneg (by positivity) (edge_pos hm ht i).le + have hab (i : Fin 3) : a i*b i = (1-lam)*a i+lam*v i^4 := by + dsimp only [a, b] + have hd : 1+t*v i ≠ 0 := ne_of_gt (edge_pos hm ht i) + calc + _ = (v i^4/(1+t*v i))*((1-lam)+lam*(1+t*v i)) := by ring + _ = (1-lam)*(v i^4/(1+t*v i))+lam*((v i^4/(1+t*v i))*(1+t*v i)) := by ring + _ = _ := by rw [div_mul_cancel₀ _ hd] + have habavg : avg (fun i ↦ a i*b i) = (1-lam)*fourthResolvent v t+6*lam*momentX v^2 := by + simp_rw [hab] + rw [avg_add, avg_mul, avg_mul, fourthMoment (avg_centered hm)] + change (1-lam)*fourthResolvent v t+lam*(6*momentX v^2) = _ + ring + have havga : avg a = fourthResolvent v t := rfl + have havgab : avg (fun i ↦ a i/b i) = fourthEdgeResolvent v lam t := by + simp only [a, b, fourthEdgeResolvent, div_div] + have htangent (i : Fin 3) : a i*(2*c-b i) ≤ c^2*(a i/b i) := by + rw [← mul_div_assoc] + apply (le_div_iff₀ (hb i)).2 + nlinarith [mul_nonneg (ha i) (sq_nonneg (b i-c))] + have hs : 2*c*fourthResolvent v t-((1-lam)*fourthResolvent v t+6*lam*momentX v^2) ≤ + c^2*fourthEdgeResolvent v lam t := by + calc + _ = avg (fun i ↦ a i*(2*c-b i)) := by + rw [← habavg, ← havga] + simp only [avg]; ring + _ ≤ avg (fun i ↦ c^2*(a i/b i)) := avg_mono htangent + _ = _ := by rw [avg_mul, havgab] + have hfour := fourthResolvent_four hm ht + have hh : 0 ≤ lam*((3/2)*fourthResolvent v t-6*momentX v^2) := + mul_nonneg hl₀ (by linarith) + have hd : 0 ≤ c*(c*fourthEdgeResolvent v lam t-fourthResolvent v t) := by + dsimp only [c] at hs ⊢ + nlinarith + have hh' := (mul_nonneg_iff_of_pos_left hc).mp hd + have hfinal : fourthResolvent v t/c ≤ fourthEdgeResolvent v lam t := by + apply (div_le_iff₀ hc).2 + nlinarith + have heq : (2/(2+lam))*fourthResolvent v t = fourthResolvent v t/c := by + dsimp [c] + field_simp + rw [heq] + exact hfinal + +lemma fourthEdgeResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : + ContinuousOn (fourthEdgeResolvent (centered m) lam) (Icc (0:ℝ) 1) := by + have hi (i : Fin 3) : ContinuousOn + (fun t : ℝ ↦ centered m i^4/((1+t*centered m i)*(1+t*lam*centered m i))) (Icc 0 1) := by + apply continuousOn_const.div (by fun_prop) + intro t ht + have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl₀, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl₁ ht.1]⟩ + exact ne_of_gt (mul_pos (edge_pos hm ht i) (edge_pos hm htl i)) + exact (((hi 0).add (hi 1)).add (hi 2)).div_const 3 + +theorem momentQ_lower {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl₀ : 0 ≤ lam) (hl₁ : lam ≤ 1) : momentA m/(2+lam) ≤ momentQ m lam := by + have hcr : ContinuousOn (fun t : ℝ ↦ t^2*fourthEdgeResolvent (centered m) lam t) (Icc 0 1) := + (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul (fourthEdgeResolvent_continuousOn hm hl₀ hl₁) + have hcl : ContinuousOn (fun t : ℝ ↦ t^2*((2/(2+lam))*fourthResolvent (centered m) t)) (Icc 0 1) := + (by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul + (continuousOn_const.mul (fourthResolvent_continuousOn hm)) + have hi := intervalIntegral.integral_mono_on (μ := volume) (by norm_num : (0:ℝ) ≤ 1) + (hcl.intervalIntegrable_of_Icc (by norm_num)) (hcr.intervalIntegrable_of_Icc (by norm_num)) + (fun t ht ↦ mul_le_mul_of_nonneg_left (fourthEdgeResolvent_lower hm hl₀ hl₁ ht) (sq_nonneg t)) + have he : (∫ t in (0:ℝ)..1, t^2*((2/(2+lam))*fourthResolvent (centered m) t)) = + (2/(2+lam))*momentA m := by + rw [momentA, ← intervalIntegral.integral_const_mul] + congr 1; funext t; ring + rw [he] at hi + have heq : (2/(2+lam))*momentA m = 2*(momentA m/(2+lam)) := by ring + rw [heq] at hi + dsimp only [momentQ] + linarith + +end ThreeState.TreeClauses.Positive + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Positive +open Radial + +def residual (m : Vec) (lam : ℝ) : ℝ := + ∫ t in (0:ℝ)..1, t*avg (fun i ↦ centered m i^3 / + ((1+t*centered m i)*(1+t*lam*centered m i))) + +lemma avg_integrable {f : ℝ → Vec} (h : ∀ i, IntervalIntegrable (fun t ↦ f t i) volume 0 1) : + IntervalIntegrable (fun t ↦ avg (f t)) volume 0 1 := + (((h 0).add (h 1)).add (h 2)).div_const 3 + +lemma avg_continuousOn {f : ℝ → Vec} {S : Set ℝ} (h : ∀ i, ContinuousOn (fun t ↦ f t i) S) : + ContinuousOn (fun t ↦ avg (f t)) S := + (((h 0).add (h 1)).add (h 2)).div_const 3 + +lemma edge_message {m : Vec} (hm : PositiveMessage m) {lam : ℝ} (hl : lam ∈ Icc (0:ℝ) 1) : + PositiveMessage (edge lam m) := by + refine ⟨fun i ↦ edge_pos hm hl i, ?_⟩ + change avg (fun i ↦ 1+lam*centered m i) = 1 + rw [avg_add, avg_const, avg_mul] + rw [avg_centered hm]; ring + +lemma centered_edge (m : Vec) (lam : ℝ) : centered (edge lam m) = fun i ↦ lam*centered m i := by + funext i; simp [centered, edge] + +lemma symEntropy_integral {m : Vec} (hm : PositiveMessage m) : + symEntropy m = (1/2)*∫ t in (0:ℝ)..1, avg (fun i ↦ centered m i^2/(1+t*centered m i)) := by + have hi (i : Fin 3) : IntervalIntegrable (fun t : ℝ ↦ centered m i^2/(1+t*centered m i)) volume 0 1 := + (continuousOn_const.div (by fun_prop : ContinuousOn (fun t : ℝ ↦ 1+t*centered m i) (Icc 0 1)) + (fun t ht ↦ ne_of_gt (edge_pos hm ht i))).intervalIntegrable_of_Icc (by norm_num) + rw [integral_avg hi] + have he (i : Fin 3) : (∫ t in (0:ℝ)..1, centered m i^2/(1+t*centered m i)) = + centered m i*Real.log (m i) := by + rw [← integral_log_edge hm i, ← intervalIntegral.integral_const_mul] + congr 1; funext t; ring + simp_rw [he] + simp only [symEntropy, centered, avg] + ring + +lemma symEntropy_nonneg {m : Vec} (hm : PositiveMessage m) : 0 ≤ symEntropy m := by + have hi (i : Fin 3) : 0 ≤ (m i-1)*Real.log (m i) := by + rcases le_total 1 (m i) with h | h + · exact mul_nonneg (sub_nonneg.mpr h) (Real.log_nonneg h) + · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr h) (Real.log_nonpos (hm.1 i).le h) + dsimp only [symEntropy, avg] + exact div_nonneg (div_nonneg (add_nonneg (add_nonneg (hi 0) (hi 1)) (hi 2)) (by norm_num)) (by norm_num) + +lemma residual_continuousOn {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl : lam ∈ Icc (0:ℝ) 1) : ContinuousOn + (fun t : ℝ ↦ t*avg (fun i ↦ centered m i^3/((1+t*centered m i)*(1+t*lam*centered m i)))) (Icc 0 1) := by + apply continuousOn_id.mul + apply avg_continuousOn + intro i + apply continuousOn_const.div (by fun_prop) + intro t ht + have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ + exact ne_of_gt (mul_pos (edge_pos hm ht i) (edge_pos hm htl i)) + +lemma symEntropy_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl : lam ∈ Icc (0:ℝ) 1) : + symEntropy m = momentX (centered m)-lam*momentQ m lam-residual m lam/2 := by + let v := centered m + have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by + apply (avg_continuousOn (fun i ↦ continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht i)))).intervalIntegrable_of_Icc + norm_num + have hq : IntervalIntegrable (fun t : ℝ ↦ t^2*fourthEdgeResolvent v lam t) volume 0 1 := + ((by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul + (fourthEdgeResolvent_continuousOn hm hl.1 hl.2)).intervalIntegrable_of_Icc (by norm_num) + have hr : IntervalIntegrable (fun t : ℝ ↦ t*avg (fun i ↦ centered m i^3/((1+t*centered m i)*(1+t*lam*centered m i)))) volume 0 1 := + (residual_continuousOn hm hl).intervalIntegrable_of_Icc (by norm_num) + have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*v i)) = + 2*momentX v-lam*(t^2*fourthEdgeResolvent v lam t)- + t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i))) := by + have he (i : Fin 3) : v i^2/(1+t*v i) = v i^2-lam*t^2*(v i^4/((1+t*v i)*(1+t*lam*v i)))- + t*(v i^3/((1+t*v i)*(1+t*lam*v i))) := by + have htlam : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ + have h₁ : 1+t*v i ≠ 0 := ne_of_gt (edge_pos hm ht i) + have h₂ : 1+t*lam*v i ≠ 0 := ne_of_gt (edge_pos hm htlam i) + have h₁' : 1+v i*t ≠ 0 := by simpa only [mul_comm] using h₁ + have h₂' : 1+v i*t*lam ≠ 0 := by convert h₂ using 1; ring + field_simp [h₁', h₂'] + ring + simp_rw [he] + rw [avg_sub, avg_sub, avg_mul, avg_mul] + dsimp only [momentX, fourthEdgeResolvent] + ring + rw [symEntropy_integral hm] + have hconvert := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) + rw [hconvert, intervalIntegral.integral_sub ((intervalIntegrable_const).sub (hq.const_mul lam)) hr, + intervalIntegral.integral_sub intervalIntegrable_const (hq.const_mul lam), + intervalIntegral.integral_const, intervalIntegral.integral_const_mul] + dsimp only [momentQ, residual] + ring + +lemma powerResolvent_continuousOn {m : Vec} (hm : PositiveMessage m) (n : ℕ) + {lam : ℝ} (hl : lam ∈ Icc (0:ℝ) 1) : + ContinuousOn (fun t : ℝ ↦ avg (fun i ↦ centered m i^n/(1+t*lam*centered m i))) (Icc 0 1) := by + apply avg_continuousOn + intro i + apply continuousOn_const.div (by fun_prop) + intro t ht + have htl : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ + exact ne_of_gt (edge_pos hm htl i) + +lemma edge_symEntropy_integral {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl : lam ∈ Icc (0:ℝ) 1) : + symEntropy (edge lam m) = (lam^2/2)*∫ t in (0:ℝ)..1, + avg (fun i ↦ centered m i^2/(1+t*lam*centered m i)) := by + rw [symEntropy_integral (edge_message hm hl), centered_edge] + have he (t : ℝ) : avg (fun i ↦ (lam*centered m i)^2/(1+t*(lam*centered m i))) = + lam^2*avg (fun i ↦ centered m i^2/(1+t*lam*centered m i)) := by + dsimp only [avg]; ring + simp_rw [he] + rw [intervalIntegral.integral_const_mul] + ring + +lemma symEntropy_edge_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl : lam ∈ Icc (0:ℝ) 1) : + symEntropy (edge lam m) = lam^2*(symEntropy m+(1-lam)*residual m lam/2) := by + let v := centered m + have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by + simpa using (powerResolvent_continuousOn hm 2 (by norm_num : (1:ℝ) ∈ Icc 0 1)).intervalIntegrable_of_Icc (μ := volume) (by norm_num) + have hr : IntervalIntegrable (fun t : ℝ ↦ t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i)))) volume 0 1 := + (residual_continuousOn hm hl).intervalIntegrable_of_Icc (by norm_num) + have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*lam*v i)) = + avg (fun i ↦ v i^2/(1+t*v i))+(1-lam)*(t*avg (fun i ↦ v i^3/((1+t*v i)*(1+t*lam*v i)))) := by + have he (i : Fin 3) : v i^2/(1+t*lam*v i) = v i^2/(1+t*v i)+ + (1-lam)*t*(v i^3/((1+t*v i)*(1+t*lam*v i))) := by + have htlam : t*lam ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg ht.1 hl.1, by nlinarith [ht.2, mul_le_mul_of_nonneg_left hl.2 ht.1]⟩ + have h₁ : 1+v i*t ≠ 0 := by simpa only [mul_comm] using ne_of_gt (edge_pos hm ht i) + have h₂ : 1+v i*t*lam ≠ 0 := by convert ne_of_gt (edge_pos hm htlam i) using 1; ring + field_simp [h₁, h₂] + ring + simp_rw [he] + rw [avg_add, avg_mul] + ring + rw [edge_symEntropy_integral hm hl, symEntropy_integral hm] + have he := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) + rw [he, intervalIntegral.integral_add hi (hr.const_mul (1-lam)), intervalIntegral.integral_const_mul] + dsimp only [residual] + ring + +lemma momentA_identity {m : Vec} (hm : PositiveMessage m) : + momentA m = momentY (centered m)-2*momentX (centered m)+2*symEntropy m := by + let v := centered m + have hi : IntervalIntegrable (fun t : ℝ ↦ avg (fun i ↦ v i^2/(1+t*v i))) volume 0 1 := by + simpa using (powerResolvent_continuousOn hm 2 (by norm_num : (1:ℝ) ∈ Icc 0 1)).intervalIntegrable_of_Icc (μ := volume) (by norm_num) + have ha : IntervalIntegrable (fun t : ℝ ↦ t^2*fourthResolvent v t) volume 0 1 := + ((by fun_prop : ContinuousOn (fun t : ℝ ↦ t^2) (Icc 0 1)).mul + (fourthResolvent_continuousOn hm)).intervalIntegrable_of_Icc (by norm_num) + have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : avg (fun i ↦ v i^2/(1+t*v i)) = + 2*momentX v-t*(2*momentY v)+t^2*fourthResolvent v t := by + have he (i : Fin 3) : v i^2/(1+t*v i) = v i^2-t*v i^3+t^2*(v i^4/(1+t*v i)) := by + have h₁ : 1+v i*t ≠ 0 := by simpa only [mul_comm] using ne_of_gt (edge_pos hm ht i) + field_simp [h₁] + ring + simp_rw [he] + rw [avg_add, avg_sub, avg_mul, avg_mul] + dsimp only [momentX, momentY, fourthResolvent] + ring + have he := intervalIntegral.integral_congr (μ := volume) (a := (0:ℝ)) (b := 1) (fun t ht ↦ hp t (by simpa using ht)) + rw [symEntropy_integral hm, he] + rw [intervalIntegral.integral_add (by apply Continuous.intervalIntegrable; fun_prop) ha, + intervalIntegral.integral_sub intervalIntegrable_const (by apply Continuous.intervalIntegrable; fun_prop), + intervalIntegral.integral_const, intervalIntegral.integral_mul_const, integral_id] + dsimp only [momentA] + ring + +lemma momentY_residual {m : Vec} (hm : PositiveMessage m) {lam : ℝ} + (hl : lam ∈ Icc (0:ℝ) 1) : + momentY (centered m) = momentA m+2*lam*momentQ m lam+residual m lam := by + rw [momentA_identity hm, symEntropy_residual hm hl] + ring + +end ThreeState.TreeClauses.Positive + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/PosteriorLaw.lean b/lean/OAI/Probability/ThreeStateClauses/PosteriorLaw.lean index 0dd10f7adf9cf64ab038068c0542cc0a90312358..d68b235ffbd57e233b72f90c39efe091ebbfe11d 100644 --- a/lean/OAI/Probability/ThreeStateClauses/PosteriorLaw.lean +++ b/lean/OAI/Probability/ThreeStateClauses/PosteriorLaw.lean @@ -1,292 +1,292 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.PositiveMoments - -namespace OAI - -/-! Posterior Law. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Experiment -open Radial ThreeState.TreeClauses.Positive - -def messageSet : Set Vec := {m | (∀ i, 0 ≤ m i) ∧ avg m = 1} -abbrev Message := messageSet - -lemma coordinate_nonneg (m : Message) (i : Fin 3) : 0 ≤ m.1 i := m.2.1 i -lemma coordinate_le_three (m : Message) (i : Fin 3) : m.1 i ≤ 3 := by - have hs := m.2.2 - dsimp only [avg] at hs - have h₀ := m.2.1 0 - have h₁ := m.2.1 1 - have h₂ := m.2.1 2 - fin_cases i <;> dsimp at * <;> linarith - -lemma continuous_avg : Continuous (avg : Vec → ℝ) := - (((continuous_apply 0).add (continuous_apply 1)).add (continuous_apply 2)).div_const 3 - -lemma isClosed_messageSet : IsClosed messageSet := by - have h : IsClosed {m : Vec | ∀ i, 0 ≤ m i} := by - simp only [ofPred_forall] - exact isClosed_iInter (fun i ↦ isClosed_le continuous_const (continuous_apply i)) - exact h.inter (isClosed_eq continuous_avg continuous_const) - -lemma isCompact_messageSet : IsCompact messageSet := - (isCompact_Icc (a := fun _ : Fin 3 ↦ (0:ℝ)) (b := fun _ : Fin 3 ↦ (3:ℝ))).of_isClosed_subset - isClosed_messageSet (fun m hm ↦ ⟨hm.1, fun i ↦ coordinate_le_three ⟨m, hm⟩ i⟩) - -instance : CompactSpace Message := isCompact_iff_compactSpace.mp isCompact_messageSet - -lemma continuous_coordinate (i : Fin 3) : Continuous (fun m : Message ↦ m.1 i) := - (continuous_apply i).comp continuous_subtype_val - -lemma integral_avg_measure {X : Type*} [MeasurableSpace X] {ν : Measure X} {f : X → Vec} - (hf : ∀ i, Integrable (fun x ↦ f x i) ν) : - (∫ x, avg (f x) ∂ν) = avg (fun i ↦ ∫ x, f x i ∂ν) := by - simp only [avg, integral_div] - rw [integral_add (f := fun x ↦ f x 0+f x 1) (g := fun x ↦ f x 2) ((hf 0).add (hf 1)) (hf 2), - integral_add (f := fun x ↦ f x 0) (g := fun x ↦ f x 1) (hf 0) (hf 1)] - -lemma integrable_avg {X : Type*} [MeasurableSpace X] {ν : Measure X} {f : X → Vec} - (hf : ∀ i, Integrable (fun x ↦ f x i) ν) : Integrable (fun x ↦ avg (f x)) ν := - (((hf 0).add (hf 1)).add (hf 2)).div_const 3 - -def permute (σ : Equiv.Perm (Fin 3)) (m : Message) : Message := - ⟨fun i ↦ m.1 (σ i), fun i ↦ m.2.1 (σ i), by - have h : avg (fun i ↦ m.1 (σ i)) = avg m.1 := by - have he := Equiv.sum_comp σ m.1 - simpa only [Fin.sum_univ_three, avg, div_left_inj' (by norm_num : (3:ℝ) ≠ 0)] using he - rw [h]; exact m.2.2⟩ - -lemma continuous_permute (σ : Equiv.Perm (Fin 3)) : Continuous (permute σ) := by - apply Continuous.subtype_mk - exact continuous_pi (fun i ↦ continuous_coordinate (σ i)) - -structure Law where - probability : ProbabilityMeasure Message - balanced : ∀ i, ∫ m, m.1 i ∂probability.toMeasure = 1 - symmetric : ∀ σ, MeasurePreserving (permute σ) probability.toMeasure probability.toMeasure - -def edgeMessage (lam : ℝ) (m : Message) : Vec := edge lam m.1 - -lemma edge_lower {lam : ℝ} (hl : 0 ≤ lam) (m : Message) (i : Fin 3) : - 1-lam ≤ edgeMessage lam m i := by - dsimp [edgeMessage, edge] - nlinarith [mul_nonneg hl (coordinate_nonneg m i)] - -lemma edge_upper {lam : ℝ} (hl : 0 ≤ lam) (m : Message) (i : Fin 3) : - edgeMessage lam m i ≤ 1+2*lam := by - dsimp [edgeMessage, edge] - nlinarith [mul_nonneg hl (sub_nonneg.mpr (coordinate_le_three m i))] - -lemma edge_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (m : Message) : - PositiveMessage (edgeMessage lam m) := by - refine ⟨fun i ↦ lt_of_lt_of_le (sub_pos.mpr hl₁) (edge_lower hl₀ m i), ?_⟩ - have hc : avg (centered m.1) = 0 := by - change avg (fun i ↦ m.1 i-1) = 0 - rw [avg_sub, avg_const, m.2.2]; ring - change avg (fun i ↦ 1+lam*centered m.1 i) = 1 - rw [avg_add, avg_const, avg_mul, hc]; ring - -lemma continuous_edgeMessage (lam : ℝ) : Continuous (edgeMessage lam) := by - apply continuous_pi - intro i - exact continuous_const.add (continuous_const.mul ((continuous_coordinate i).sub continuous_const)) - -lemma continuous_edge_log {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : - Continuous (fun m : Message ↦ Real.log (edgeMessage lam m i)) := - ((continuous_apply i).comp (continuous_edgeMessage lam)).log - (fun m ↦ ne_of_gt ((edge_positive hl₀ hl₁ m).1 i)) - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma avg_permute_vec (σ : Equiv.Perm (Fin 3)) (v : Vec) : - avg (fun i ↦ v (σ i)) = avg v := by - have h := Equiv.sum_comp σ v - simpa only [Fin.sum_univ_three, avg, div_left_inj' (by norm_num : (3:ℝ) ≠ 0)] using h - -def permuteMeasurableEquiv (σ : Equiv.Perm (Fin 3)) : Message ≃ᵐ Message where - toFun := permute σ - invFun := permute σ.symm - left_inv m := by apply Subtype.ext; funext i; simp [permute] - right_inv m := by apply Subtype.ext; funext i; simp [permute] - measurable_toFun := (continuous_permute σ).measurable - measurable_invFun := (continuous_permute σ.symm).measurable - -lemma compact_integrable {X : Type*} [MeasurableSpace X] [TopologicalSpace X] - [BorelSpace X] [CompactSpace X] {μ : Measure X} [IsFiniteMeasure μ] - {f : X → ℝ} (hf : Continuous f) : Integrable f μ := - hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) - -lemma Law.integral_equivariant (Q : Law) {f : Message → Vec} - (hf : ∀ i, Integrable (fun m ↦ f m i) Q.probability.toMeasure) - (hs : ∀ σ m i, f (permute σ m) i = f m (σ i)) (i : Fin 3) : - (∫ m, f m i ∂Q.probability.toMeasure) = ∫ m, avg (f m) ∂Q.probability.toMeasure := by - have he (j : Fin 3) : (∫ m, f m j ∂Q.probability.toMeasure) = ∫ m, f m i ∂Q.probability.toMeasure := by - let σ := Equiv.swap i j - have hp : MeasurePreserving (permuteMeasurableEquiv σ) Q.probability.toMeasure Q.probability.toMeasure := Q.symmetric σ - have h := hp.integral_comp' (fun m ↦ f m i) - change (∫ m, f (permute σ m) i ∂Q.probability.toMeasure) = _ at h - simp_rw [hs] at h - simpa only [σ, Equiv.swap_apply_left] using h - rw [integral_avg_measure hf] - dsimp only [avg] - rw [he 0, he 1, he 2] - ring - -lemma continuous_edge_centeredLog {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : - Continuous (fun m : Message ↦ logCentered (edgeMessage lam m) i) := by - apply (continuous_edge_log hl₀ hl₁ i).sub - exact continuous_avg.comp (continuous_pi (fun j ↦ continuous_edge_log hl₀ hl₁ j)) - -lemma edge_permute (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Message) (i : Fin 3) : - edgeMessage lam (permute σ m) i = edgeMessage lam m (σ i) := rfl - -lemma edge_logCentered_permute (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Message) (i : Fin 3) : - logCentered (edgeMessage lam (permute σ m)) i = logCentered (edgeMessage lam m) (σ i) := by - unfold logCentered logAverage - simp_rw [edge_permute] - rw [avg_permute_vec σ (fun i ↦ Real.log (edgeMessage lam m i))] - -lemma Law.edge_balanced (Q : Law) (lam : ℝ) (i : Fin 3) : - (∫ m, edgeMessage lam m i ∂Q.probability.toMeasure) = 1 := by - have hi : Integrable (fun m : Message ↦ m.1 i) Q.probability.toMeasure := compact_integrable (continuous_coordinate i) - change (∫ m : Message, 1+lam*(m.1 i-1) ∂Q.probability.toMeasure) = 1 - rw [integral_add (f := fun _ : Message ↦ (1:ℝ)) (g := fun m ↦ lam*(m.1 i-1)) - (integrable_const _) ((hi.sub (integrable_const _)).const_mul _), - integral_const_mul, integral_sub (f := fun m : Message ↦ m.1 i) (g := fun _ ↦ (1:ℝ)) hi (integrable_const _), Q.balanced] - simp - -lemma symEntropy_centeredLog' {m : Vec} (hm : avg m = 1) : - avg (fun i ↦ m i*logCentered m i) = 2*symEntropy m := by - have he : avg (fun i ↦ m i*logAverage m) = logAverage m := by - calc - _ = logAverage m*avg m := by dsimp only [avg]; ring - _ = _ := by rw [hm]; ring - simp only [logCentered, mul_sub, avg_sub, he] - dsimp only [symEntropy, logAverage, avg] - ring - -lemma Law.edge_centeredLog_mean (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : - (∫ m, edgeMessage lam m i*logCentered (edgeMessage lam m) i ∂Q.probability.toMeasure) = - 2*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by - rw [Q.integral_equivariant (f := fun m i ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) - (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edge_centeredLog hl₀ hl₁ i))) (fun σ m i ↦ by rw [edge_permute, edge_logCentered_permute]) i] - simp_rw [symEntropy_centeredLog' (edge_positive hl₀ hl₁ _).2] - rw [integral_const_mul] - -lemma Law.edge_centeredLog_sq (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : - (∫ m, edgeMessage lam m i*logCentered (edgeMessage lam m) i^2 ∂Q.probability.toMeasure) = - 2*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure) := by - rw [Q.integral_equivariant (f := fun m i ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i^2) - (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - ((continuous_edge_centeredLog hl₀ hl₁ i).pow 2))) (fun σ m i ↦ by rw [edge_permute, edge_logCentered_permute]) i] - rw [← integral_const_mul] - congr 1; funext m; simp only [correction]; ring - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def xMoment (m : Message) : ℝ := momentX (centered m.1) -def yMoment (m : Message) : ℝ := momentY (centered m.1) - -lemma message_centered_avg (m : Message) : avg (centered m.1) = 0 := by - change avg (fun i ↦ m.1 i-1) = 0 - rw [avg_sub, avg_const, m.2.2]; ring - -lemma continuous_xMoment : Continuous xMoment := by - unfold xMoment momentX centered - exact (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).pow 2))).div_const 2 - -lemma continuous_yMoment : Continuous yMoment := by - unfold yMoment momentY centered - exact (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).pow 3))).div_const 2 - -lemma xMoment_nonneg (m : Message) : 0 ≤ xMoment m := momentX_nonneg _ - -lemma xMoment_le_one (m : Message) : xMoment m ≤ 1 := by - have h (i : Fin 3) : (m.1 i)^2 ≤ 3*m.1 i := by - nlinarith [mul_nonneg (coordinate_nonneg m i) (sub_nonneg.mpr (coordinate_le_three m i))] - have hs := m.2.2 - dsimp only [avg] at hs - dsimp only [xMoment, momentX, centered, avg] - nlinarith [h 0, h 1, h 2] - -lemma yMoment_discriminant (m : Message) : yMoment m^2 ≤ xMoment m^3 := - moment_discriminant (message_centered_avg m) - -lemma moment_quadratic_nonneg {x y a : ℝ} (hx : 0 ≤ x) (hy : y^2 ≤ x^3) : - 0 ≤ x*a^2+2*y*a+x^2 := by - rcases eq_or_lt_of_le hx with h | h - · have hx0 : x = 0 := h.symm - have hy0 : y = 0 := by rw [hx0] at hy; nlinarith [sq_nonneg y] - simp [hx0,hy0] - · have hh : 0 ≤ x*(x*a^2+2*y*a+x^2) := by nlinarith [sq_nonneg (x*a+y)] - exact nonneg_of_mul_nonneg_right hh h - -def Law.mu (Q : Law) := ∫ m, xMoment m ∂Q.probability.toMeasure -def Law.nu (Q : Law) := ∫ m, xMoment m^2 ∂Q.probability.toMeasure -def Law.eta (Q : Law) := ∫ m, yMoment m ∂Q.probability.toMeasure - -lemma Law.mu_nonneg (Q : Law) : 0 ≤ Q.mu := integral_nonneg xMoment_nonneg -lemma Law.nu_nonneg (Q : Law) : 0 ≤ Q.nu := integral_nonneg (fun _ ↦ sq_nonneg _) - -lemma Law.mu_le_one (Q : Law) : Q.mu ≤ 1 := by - have h := integral_mono (μ := Q.probability.toMeasure) - (compact_integrable continuous_xMoment) (integrable_const (1:ℝ)) xMoment_le_one - simpa [Law.mu] using h - -lemma Law.second_moment_lower (Q : Law) : Q.mu^2 ≤ Q.nu := by - have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) - have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) - have h := integral_nonneg (μ := Q.probability.toMeasure) (f := fun m : Message ↦ (xMoment m-Q.mu)^2) - (fun m ↦ sq_nonneg (xMoment m-Q.mu)) - have hfunc : (fun m : Message ↦ (xMoment m-Q.mu)^2) = - (fun m ↦ xMoment m^2 - 2*Q.mu*xMoment m + Q.mu^2) := by funext m; ring - rw [hfunc, integral_add (f := fun m ↦ xMoment m^2-2*Q.mu*xMoment m) - (g := fun _ ↦ Q.mu^2) (hi₂.sub (hi.const_mul _)) (integrable_const _), - integral_sub (f := fun m ↦ xMoment m^2) (g := fun m ↦ 2*Q.mu*xMoment m) hi₂ (hi.const_mul (2*Q.mu)), integral_const_mul] at h - simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, smul_eq_mul, one_mul] at h - change 0 ≤ Q.nu-2*Q.mu*Q.mu+Q.mu^2 at h - linarith - -lemma Law.moment_discriminant (Q : Law) : Q.eta^2 ≤ Q.mu*Q.nu := by - have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) - have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) - have hy := compact_integrable continuous_yMoment (μ := Q.probability.toMeasure) - have hquad (a : ℝ) : 0 ≤ Q.mu*(a*a)+(2*Q.eta)*a+Q.nu := by - have h := integral_nonneg (μ := Q.probability.toMeasure) - (f := fun m : Message ↦ xMoment m*a^2+2*yMoment m*a+xMoment m^2) - (fun m : Message ↦ moment_quadratic_nonneg (a := a) (xMoment_nonneg m) (yMoment_discriminant m)) - rw [integral_add (f := fun m ↦ xMoment m*a^2+2*yMoment m*a) (g := fun m ↦ xMoment m^2) - ((hi.mul_const _).add ((hy.const_mul _).mul_const _)) hi₂, - integral_add (f := fun m ↦ xMoment m*a^2) (g := fun m ↦ 2*yMoment m*a) - (hi.mul_const _) ((hy.const_mul _).mul_const _), - integral_mul_const, integral_mul_const, integral_const_mul] at h - change 0 ≤ Q.mu*a^2+2*Q.eta*a+Q.nu at h - nlinarith - have h := discrim_le_zero hquad - dsimp only [discrim] at h - nlinarith - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.PositiveMoments + +namespace OAI + +/-! Posterior Law. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Experiment +open Radial ThreeState.TreeClauses.Positive + +def messageSet : Set Vec := {m | (∀ i, 0 ≤ m i) ∧ avg m = 1} +abbrev Message := messageSet + +lemma coordinate_nonneg (m : Message) (i : Fin 3) : 0 ≤ m.1 i := m.2.1 i +lemma coordinate_le_three (m : Message) (i : Fin 3) : m.1 i ≤ 3 := by + have hs := m.2.2 + dsimp only [avg] at hs + have h₀ := m.2.1 0 + have h₁ := m.2.1 1 + have h₂ := m.2.1 2 + fin_cases i <;> dsimp at * <;> linarith + +lemma continuous_avg : Continuous (avg : Vec → ℝ) := + (((continuous_apply 0).add (continuous_apply 1)).add (continuous_apply 2)).div_const 3 + +lemma isClosed_messageSet : IsClosed messageSet := by + have h : IsClosed {m : Vec | ∀ i, 0 ≤ m i} := by + simp only [ofPred_forall] + exact isClosed_iInter (fun i ↦ isClosed_le continuous_const (continuous_apply i)) + exact h.inter (isClosed_eq continuous_avg continuous_const) + +lemma isCompact_messageSet : IsCompact messageSet := + (isCompact_Icc (a := fun _ : Fin 3 ↦ (0:ℝ)) (b := fun _ : Fin 3 ↦ (3:ℝ))).of_isClosed_subset + isClosed_messageSet (fun m hm ↦ ⟨hm.1, fun i ↦ coordinate_le_three ⟨m, hm⟩ i⟩) + +instance : CompactSpace Message := isCompact_iff_compactSpace.mp isCompact_messageSet + +lemma continuous_coordinate (i : Fin 3) : Continuous (fun m : Message ↦ m.1 i) := + (continuous_apply i).comp continuous_subtype_val + +lemma integral_avg_measure {X : Type*} [MeasurableSpace X] {ν : Measure X} {f : X → Vec} + (hf : ∀ i, Integrable (fun x ↦ f x i) ν) : + (∫ x, avg (f x) ∂ν) = avg (fun i ↦ ∫ x, f x i ∂ν) := by + simp only [avg, integral_div] + rw [integral_add (f := fun x ↦ f x 0+f x 1) (g := fun x ↦ f x 2) ((hf 0).add (hf 1)) (hf 2), + integral_add (f := fun x ↦ f x 0) (g := fun x ↦ f x 1) (hf 0) (hf 1)] + +lemma integrable_avg {X : Type*} [MeasurableSpace X] {ν : Measure X} {f : X → Vec} + (hf : ∀ i, Integrable (fun x ↦ f x i) ν) : Integrable (fun x ↦ avg (f x)) ν := + (((hf 0).add (hf 1)).add (hf 2)).div_const 3 + +def permute (σ : Equiv.Perm (Fin 3)) (m : Message) : Message := + ⟨fun i ↦ m.1 (σ i), fun i ↦ m.2.1 (σ i), by + have h : avg (fun i ↦ m.1 (σ i)) = avg m.1 := by + have he := Equiv.sum_comp σ m.1 + simpa only [Fin.sum_univ_three, avg, div_left_inj' (by norm_num : (3:ℝ) ≠ 0)] using he + rw [h]; exact m.2.2⟩ + +lemma continuous_permute (σ : Equiv.Perm (Fin 3)) : Continuous (permute σ) := by + apply Continuous.subtype_mk + exact continuous_pi (fun i ↦ continuous_coordinate (σ i)) + +structure Law where + probability : ProbabilityMeasure Message + balanced : ∀ i, ∫ m, m.1 i ∂probability.toMeasure = 1 + symmetric : ∀ σ, MeasurePreserving (permute σ) probability.toMeasure probability.toMeasure + +def edgeMessage (lam : ℝ) (m : Message) : Vec := edge lam m.1 + +lemma edge_lower {lam : ℝ} (hl : 0 ≤ lam) (m : Message) (i : Fin 3) : + 1-lam ≤ edgeMessage lam m i := by + dsimp [edgeMessage, edge] + nlinarith [mul_nonneg hl (coordinate_nonneg m i)] + +lemma edge_upper {lam : ℝ} (hl : 0 ≤ lam) (m : Message) (i : Fin 3) : + edgeMessage lam m i ≤ 1+2*lam := by + dsimp [edgeMessage, edge] + nlinarith [mul_nonneg hl (sub_nonneg.mpr (coordinate_le_three m i))] + +lemma edge_positive {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (m : Message) : + PositiveMessage (edgeMessage lam m) := by + refine ⟨fun i ↦ lt_of_lt_of_le (sub_pos.mpr hl₁) (edge_lower hl₀ m i), ?_⟩ + have hc : avg (centered m.1) = 0 := by + change avg (fun i ↦ m.1 i-1) = 0 + rw [avg_sub, avg_const, m.2.2]; ring + change avg (fun i ↦ 1+lam*centered m.1 i) = 1 + rw [avg_add, avg_const, avg_mul, hc]; ring + +lemma continuous_edgeMessage (lam : ℝ) : Continuous (edgeMessage lam) := by + apply continuous_pi + intro i + exact continuous_const.add (continuous_const.mul ((continuous_coordinate i).sub continuous_const)) + +lemma continuous_edge_log {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : + Continuous (fun m : Message ↦ Real.log (edgeMessage lam m i)) := + ((continuous_apply i).comp (continuous_edgeMessage lam)).log + (fun m ↦ ne_of_gt ((edge_positive hl₀ hl₁ m).1 i)) + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma avg_permute_vec (σ : Equiv.Perm (Fin 3)) (v : Vec) : + avg (fun i ↦ v (σ i)) = avg v := by + have h := Equiv.sum_comp σ v + simpa only [Fin.sum_univ_three, avg, div_left_inj' (by norm_num : (3:ℝ) ≠ 0)] using h + +def permuteMeasurableEquiv (σ : Equiv.Perm (Fin 3)) : Message ≃ᵐ Message where + toFun := permute σ + invFun := permute σ.symm + left_inv m := by apply Subtype.ext; funext i; simp [permute] + right_inv m := by apply Subtype.ext; funext i; simp [permute] + measurable_toFun := (continuous_permute σ).measurable + measurable_invFun := (continuous_permute σ.symm).measurable + +lemma compact_integrable {X : Type*} [MeasurableSpace X] [TopologicalSpace X] + [BorelSpace X] [CompactSpace X] {μ : Measure X} [IsFiniteMeasure μ] + {f : X → ℝ} (hf : Continuous f) : Integrable f μ := + hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace f) + +lemma Law.integral_equivariant (Q : Law) {f : Message → Vec} + (hf : ∀ i, Integrable (fun m ↦ f m i) Q.probability.toMeasure) + (hs : ∀ σ m i, f (permute σ m) i = f m (σ i)) (i : Fin 3) : + (∫ m, f m i ∂Q.probability.toMeasure) = ∫ m, avg (f m) ∂Q.probability.toMeasure := by + have he (j : Fin 3) : (∫ m, f m j ∂Q.probability.toMeasure) = ∫ m, f m i ∂Q.probability.toMeasure := by + let σ := Equiv.swap i j + have hp : MeasurePreserving (permuteMeasurableEquiv σ) Q.probability.toMeasure Q.probability.toMeasure := Q.symmetric σ + have h := hp.integral_comp' (fun m ↦ f m i) + change (∫ m, f (permute σ m) i ∂Q.probability.toMeasure) = _ at h + simp_rw [hs] at h + simpa only [σ, Equiv.swap_apply_left] using h + rw [integral_avg_measure hf] + dsimp only [avg] + rw [he 0, he 1, he 2] + ring + +lemma continuous_edge_centeredLog {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : + Continuous (fun m : Message ↦ logCentered (edgeMessage lam m) i) := by + apply (continuous_edge_log hl₀ hl₁ i).sub + exact continuous_avg.comp (continuous_pi (fun j ↦ continuous_edge_log hl₀ hl₁ j)) + +lemma edge_permute (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Message) (i : Fin 3) : + edgeMessage lam (permute σ m) i = edgeMessage lam m (σ i) := rfl + +lemma edge_logCentered_permute (lam : ℝ) (σ : Equiv.Perm (Fin 3)) (m : Message) (i : Fin 3) : + logCentered (edgeMessage lam (permute σ m)) i = logCentered (edgeMessage lam m) (σ i) := by + unfold logCentered logAverage + simp_rw [edge_permute] + rw [avg_permute_vec σ (fun i ↦ Real.log (edgeMessage lam m i))] + +lemma Law.edge_balanced (Q : Law) (lam : ℝ) (i : Fin 3) : + (∫ m, edgeMessage lam m i ∂Q.probability.toMeasure) = 1 := by + have hi : Integrable (fun m : Message ↦ m.1 i) Q.probability.toMeasure := compact_integrable (continuous_coordinate i) + change (∫ m : Message, 1+lam*(m.1 i-1) ∂Q.probability.toMeasure) = 1 + rw [integral_add (f := fun _ : Message ↦ (1:ℝ)) (g := fun m ↦ lam*(m.1 i-1)) + (integrable_const _) ((hi.sub (integrable_const _)).const_mul _), + integral_const_mul, integral_sub (f := fun m : Message ↦ m.1 i) (g := fun _ ↦ (1:ℝ)) hi (integrable_const _), Q.balanced] + simp + +lemma symEntropy_centeredLog' {m : Vec} (hm : avg m = 1) : + avg (fun i ↦ m i*logCentered m i) = 2*symEntropy m := by + have he : avg (fun i ↦ m i*logAverage m) = logAverage m := by + calc + _ = logAverage m*avg m := by dsimp only [avg]; ring + _ = _ := by rw [hm]; ring + simp only [logCentered, mul_sub, avg_sub, he] + dsimp only [symEntropy, logAverage, avg] + ring + +lemma Law.edge_centeredLog_mean (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : + (∫ m, edgeMessage lam m i*logCentered (edgeMessage lam m) i ∂Q.probability.toMeasure) = + 2*(∫ m, symEntropy (edgeMessage lam m) ∂Q.probability.toMeasure) := by + rw [Q.integral_equivariant (f := fun m i ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i) + (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edge_centeredLog hl₀ hl₁ i))) (fun σ m i ↦ by rw [edge_permute, edge_logCentered_permute]) i] + simp_rw [symEntropy_centeredLog' (edge_positive hl₀ hl₁ _).2] + rw [integral_const_mul] + +lemma Law.edge_centeredLog_sq (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (i : Fin 3) : + (∫ m, edgeMessage lam m i*logCentered (edgeMessage lam m) i^2 ∂Q.probability.toMeasure) = + 2*(∫ m, correction (edgeMessage lam m) ∂Q.probability.toMeasure) := by + rw [Q.integral_equivariant (f := fun m i ↦ edgeMessage lam m i*logCentered (edgeMessage lam m) i^2) + (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + ((continuous_edge_centeredLog hl₀ hl₁ i).pow 2))) (fun σ m i ↦ by rw [edge_permute, edge_logCentered_permute]) i] + rw [← integral_const_mul] + congr 1; funext m; simp only [correction]; ring + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def xMoment (m : Message) : ℝ := momentX (centered m.1) +def yMoment (m : Message) : ℝ := momentY (centered m.1) + +lemma message_centered_avg (m : Message) : avg (centered m.1) = 0 := by + change avg (fun i ↦ m.1 i-1) = 0 + rw [avg_sub, avg_const, m.2.2]; ring + +lemma continuous_xMoment : Continuous xMoment := by + unfold xMoment momentX centered + exact (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).pow 2))).div_const 2 + +lemma continuous_yMoment : Continuous yMoment := by + unfold yMoment momentY centered + exact (continuous_avg.comp (continuous_pi (fun i ↦ ((continuous_coordinate i).sub continuous_const).pow 3))).div_const 2 + +lemma xMoment_nonneg (m : Message) : 0 ≤ xMoment m := momentX_nonneg _ + +lemma xMoment_le_one (m : Message) : xMoment m ≤ 1 := by + have h (i : Fin 3) : (m.1 i)^2 ≤ 3*m.1 i := by + nlinarith [mul_nonneg (coordinate_nonneg m i) (sub_nonneg.mpr (coordinate_le_three m i))] + have hs := m.2.2 + dsimp only [avg] at hs + dsimp only [xMoment, momentX, centered, avg] + nlinarith [h 0, h 1, h 2] + +lemma yMoment_discriminant (m : Message) : yMoment m^2 ≤ xMoment m^3 := + moment_discriminant (message_centered_avg m) + +lemma moment_quadratic_nonneg {x y a : ℝ} (hx : 0 ≤ x) (hy : y^2 ≤ x^3) : + 0 ≤ x*a^2+2*y*a+x^2 := by + rcases eq_or_lt_of_le hx with h | h + · have hx0 : x = 0 := h.symm + have hy0 : y = 0 := by rw [hx0] at hy; nlinarith [sq_nonneg y] + simp [hx0,hy0] + · have hh : 0 ≤ x*(x*a^2+2*y*a+x^2) := by nlinarith [sq_nonneg (x*a+y)] + exact nonneg_of_mul_nonneg_right hh h + +def Law.mu (Q : Law) := ∫ m, xMoment m ∂Q.probability.toMeasure +def Law.nu (Q : Law) := ∫ m, xMoment m^2 ∂Q.probability.toMeasure +def Law.eta (Q : Law) := ∫ m, yMoment m ∂Q.probability.toMeasure + +lemma Law.mu_nonneg (Q : Law) : 0 ≤ Q.mu := integral_nonneg xMoment_nonneg +lemma Law.nu_nonneg (Q : Law) : 0 ≤ Q.nu := integral_nonneg (fun _ ↦ sq_nonneg _) + +lemma Law.mu_le_one (Q : Law) : Q.mu ≤ 1 := by + have h := integral_mono (μ := Q.probability.toMeasure) + (compact_integrable continuous_xMoment) (integrable_const (1:ℝ)) xMoment_le_one + simpa [Law.mu] using h + +lemma Law.second_moment_lower (Q : Law) : Q.mu^2 ≤ Q.nu := by + have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) + have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) + have h := integral_nonneg (μ := Q.probability.toMeasure) (f := fun m : Message ↦ (xMoment m-Q.mu)^2) + (fun m ↦ sq_nonneg (xMoment m-Q.mu)) + have hfunc : (fun m : Message ↦ (xMoment m-Q.mu)^2) = + (fun m ↦ xMoment m^2 - 2*Q.mu*xMoment m + Q.mu^2) := by funext m; ring + rw [hfunc, integral_add (f := fun m ↦ xMoment m^2-2*Q.mu*xMoment m) + (g := fun _ ↦ Q.mu^2) (hi₂.sub (hi.const_mul _)) (integrable_const _), + integral_sub (f := fun m ↦ xMoment m^2) (g := fun m ↦ 2*Q.mu*xMoment m) hi₂ (hi.const_mul (2*Q.mu)), integral_const_mul] at h + simp only [integral_const, measure_univ, Measure.real, ENNReal.toReal_one, smul_eq_mul, one_mul] at h + change 0 ≤ Q.nu-2*Q.mu*Q.mu+Q.mu^2 at h + linarith + +lemma Law.moment_discriminant (Q : Law) : Q.eta^2 ≤ Q.mu*Q.nu := by + have hi := compact_integrable continuous_xMoment (μ := Q.probability.toMeasure) + have hi₂ := compact_integrable (continuous_xMoment.pow 2) (μ := Q.probability.toMeasure) + have hy := compact_integrable continuous_yMoment (μ := Q.probability.toMeasure) + have hquad (a : ℝ) : 0 ≤ Q.mu*(a*a)+(2*Q.eta)*a+Q.nu := by + have h := integral_nonneg (μ := Q.probability.toMeasure) + (f := fun m : Message ↦ xMoment m*a^2+2*yMoment m*a+xMoment m^2) + (fun m : Message ↦ moment_quadratic_nonneg (a := a) (xMoment_nonneg m) (yMoment_discriminant m)) + rw [integral_add (f := fun m ↦ xMoment m*a^2+2*yMoment m*a) (g := fun m ↦ xMoment m^2) + ((hi.mul_const _).add ((hy.const_mul _).mul_const _)) hi₂, + integral_add (f := fun m ↦ xMoment m*a^2) (g := fun m ↦ 2*yMoment m*a) + (hi.mul_const _) ((hy.const_mul _).mul_const _), + integral_mul_const, integral_mul_const, integral_const_mul] at h + change 0 ≤ Q.mu*a^2+2*Q.eta*a+Q.nu at h + nlinarith + have h := discrim_le_zero hquad + dsimp only [discrim] at h + nlinarith + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Products.lean b/lean/OAI/Probability/ThreeStateClauses/Products.lean index 0b6996fc2d65afd4a4ca2f2782cae5bba7d7c90d..81b1550431a0df88cda0b4e1d75d7d48c3eb3244 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Products.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Products.lean @@ -1,100 +1,100 @@ -import Mathlib - -namespace OAI - -/-! Products. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Experiment - -variable {α β : Type*} - -lemma ennreal_tsum_fin_product (n : ℕ) (f : Fin n → α → ℝ≥0∞) : - (∑' v : Fin n → α, ∏ j, f j (v j)) = ∏ j, ∑' a, f j a := by - induction n with - | zero => simp - | succ n ih => - rw [← (Fin.consEquiv (fun _ : Fin (n+1) ↦ α)).tsum_eq] - change (∑' z : α × (Fin n → α), ∏ j, f j (Fin.cons (α := fun _ : Fin (n+1) ↦ α) z.1 z.2 j)) = _ - simp_rw [Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ] - rw [ENNReal.tsum_prod' (f := fun z : α × (Fin n → α) ↦ f 0 z.1*∏ j, f j.succ (z.2 j))] - simp_rw [ENNReal.tsum_mul_left, ih, ENNReal.tsum_mul_right] - -def productPMF {n : ℕ} (p : Fin n → PMF α) : PMF (Fin n → α) := - ⟨fun v ↦ ∏ j, p j (v j), ENNReal.summable.hasSum_iff.2 (by - rw [ennreal_tsum_fin_product] - simp only [PMF.tsum_coe, Finset.prod_const_one])⟩ - -@[simp] lemma productPMF_apply {n : ℕ} (p : Fin n → PMF α) (v : Fin n → α) : - productPMF p v = ∏ j, p j (v j) := rfl - -lemma productPMF_pure {n : ℕ} (v : Fin n → α) : - productPMF (fun j ↦ PMF.pure (v j)) = PMF.pure v := by - classical - apply PMF.ext - intro w - by_cases h : w = v - · subst w; simp - · have hn : ∃ j, w j ≠ v j := by simpa only [funext_iff, not_forall] using h - obtain ⟨j,hj⟩ := hn - simp only [productPMF_apply, PMF.pure_apply, ite_eq_right h] - exact Finset.prod_eq_zero (Finset.mem_univ j) (ite_eq_right hj) - -lemma productPMF_bind {n : ℕ} (p : Fin n → PMF α) (K : Fin n → α → PMF β) : - (productPMF p).bind (fun v ↦ productPMF (fun j ↦ K j (v j))) = - productPMF (fun j ↦ (p j).bind (K j)) := by - apply PMF.ext - intro w - simp only [PMF.bind_apply, productPMF_apply, ← Finset.prod_mul_distrib] - exact ennreal_tsum_fin_product n (fun j a ↦ p j a*K j a (w j)) - -lemma productPMF_map {n : ℕ} (p : Fin n → PMF α) (T : Fin n → α → β) : - (productPMF p).map (fun v j ↦ T j (v j)) = productPMF (fun j ↦ (p j).map (T j)) := by - change (productPMF p).bind (fun v ↦ PMF.pure (fun j ↦ T j (v j))) = _ - simp_rw [← productPMF_pure] - exact productPMF_bind p (fun j a ↦ PMF.pure (T j a)) - -lemma productPMF_measure [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] - {n : ℕ} (p : Fin n → PMF α) : - (productPMF p).toMeasure = Measure.pi (fun j ↦ (p j).toMeasure) := by - have h : productPMF p = (Measure.pi (fun j ↦ (p j).toMeasure)).toPMF := by - apply PMF.ext - intro v - simp [productPMF_apply, Measure.toPMF_apply, Measure.pi_singleton, PMF.toMeasure_apply_singleton] - rw [h, Measure.toPMF_toMeasure] - -lemma productPMF_cons {n : ℕ} (p : Fin (n+1) → PMF α) : - productPMF p = (p 0).bind (fun a ↦ (productPMF (fun j ↦ p j.succ)).map (Fin.cons a)) := by - classical - apply PMF.ext - intro v - rw [PMF.bind_apply, tsum_eq_single (v 0)] - · rw [PMF.map_apply, tsum_eq_single (Fin.tail v)] - · simp [productPMF_apply, Fin.prod_univ_succ, Fin.tail] - · intro w hw - have hn : v ≠ Fin.cons (v 0) w := by - intro he - have := congrArg Fin.tail he - simp only [Fin.tail_cons] at this - exact hw this.symm - simp [hn] - · intro a ha - have he : (productPMF (fun j ↦ p j.succ)).map (Fin.cons a) v = 0 := by - rw [PMF.map_apply] - apply ENNReal.tsum_eq_zero.mpr - intro w - have hn : v ≠ Fin.cons a w := by - intro h - exact ha (congrFun h 0).symm - simp [hn] - rw [he, mul_zero] - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Products. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Experiment + +variable {α β : Type*} + +lemma ennreal_tsum_fin_product (n : ℕ) (f : Fin n → α → ℝ≥0∞) : + (∑' v : Fin n → α, ∏ j, f j (v j)) = ∏ j, ∑' a, f j a := by + induction n with + | zero => simp + | succ n ih => + rw [← (Fin.consEquiv (fun _ : Fin (n+1) ↦ α)).tsum_eq] + change (∑' z : α × (Fin n → α), ∏ j, f j (Fin.cons (α := fun _ : Fin (n+1) ↦ α) z.1 z.2 j)) = _ + simp_rw [Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ] + rw [ENNReal.tsum_prod' (f := fun z : α × (Fin n → α) ↦ f 0 z.1*∏ j, f j.succ (z.2 j))] + simp_rw [ENNReal.tsum_mul_left, ih, ENNReal.tsum_mul_right] + +def productPMF {n : ℕ} (p : Fin n → PMF α) : PMF (Fin n → α) := + ⟨fun v ↦ ∏ j, p j (v j), ENNReal.summable.hasSum_iff.2 (by + rw [ennreal_tsum_fin_product] + simp only [PMF.tsum_coe, Finset.prod_const_one])⟩ + +@[simp] lemma productPMF_apply {n : ℕ} (p : Fin n → PMF α) (v : Fin n → α) : + productPMF p v = ∏ j, p j (v j) := rfl + +lemma productPMF_pure {n : ℕ} (v : Fin n → α) : + productPMF (fun j ↦ PMF.pure (v j)) = PMF.pure v := by + classical + apply PMF.ext + intro w + by_cases h : w = v + · subst w; simp + · have hn : ∃ j, w j ≠ v j := by simpa only [funext_iff, not_forall] using h + obtain ⟨j,hj⟩ := hn + simp only [productPMF_apply, PMF.pure_apply, ite_eq_right h] + exact Finset.prod_eq_zero (Finset.mem_univ j) (ite_eq_right hj) + +lemma productPMF_bind {n : ℕ} (p : Fin n → PMF α) (K : Fin n → α → PMF β) : + (productPMF p).bind (fun v ↦ productPMF (fun j ↦ K j (v j))) = + productPMF (fun j ↦ (p j).bind (K j)) := by + apply PMF.ext + intro w + simp only [PMF.bind_apply, productPMF_apply, ← Finset.prod_mul_distrib] + exact ennreal_tsum_fin_product n (fun j a ↦ p j a*K j a (w j)) + +lemma productPMF_map {n : ℕ} (p : Fin n → PMF α) (T : Fin n → α → β) : + (productPMF p).map (fun v j ↦ T j (v j)) = productPMF (fun j ↦ (p j).map (T j)) := by + change (productPMF p).bind (fun v ↦ PMF.pure (fun j ↦ T j (v j))) = _ + simp_rw [← productPMF_pure] + exact productPMF_bind p (fun j a ↦ PMF.pure (T j a)) + +lemma productPMF_measure [Countable α] [MeasurableSpace α] [MeasurableSingletonClass α] + {n : ℕ} (p : Fin n → PMF α) : + (productPMF p).toMeasure = Measure.pi (fun j ↦ (p j).toMeasure) := by + have h : productPMF p = (Measure.pi (fun j ↦ (p j).toMeasure)).toPMF := by + apply PMF.ext + intro v + simp [productPMF_apply, Measure.toPMF_apply, Measure.pi_singleton, PMF.toMeasure_apply_singleton] + rw [h, Measure.toPMF_toMeasure] + +lemma productPMF_cons {n : ℕ} (p : Fin (n+1) → PMF α) : + productPMF p = (p 0).bind (fun a ↦ (productPMF (fun j ↦ p j.succ)).map (Fin.cons a)) := by + classical + apply PMF.ext + intro v + rw [PMF.bind_apply, tsum_eq_single (v 0)] + · rw [PMF.map_apply, tsum_eq_single (Fin.tail v)] + · simp [productPMF_apply, Fin.prod_univ_succ, Fin.tail] + · intro w hw + have hn : v ≠ Fin.cons (v 0) w := by + intro he + have := congrArg Fin.tail he + simp only [Fin.tail_cons] at this + exact hw this.symm + simp [hn] + · intro a ha + have he : (productPMF (fun j ↦ p j.succ)).map (Fin.cons a) v = 0 := by + rw [PMF.map_apply] + apply ENNReal.tsum_eq_zero.mpr + intro w + have hn : v ≠ Fin.cons a w := by + intro h + exact ha (congrFun h 0).symm + simp [hn] + rw [he, mul_zero] + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/Projection.lean b/lean/OAI/Probability/ThreeStateClauses/Projection.lean index 9f8131aa8454ff2184ee453a75d68d0d1ef31ac8..acc05d7c87ae142f7a775e27211d303840d0617a 100644 --- a/lean/OAI/Probability/ThreeStateClauses/Projection.lean +++ b/lean/OAI/Probability/ThreeStateClauses/Projection.lean @@ -1,271 +1,271 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.FiniteUpdate -import OAI.Probability.ThreeStateClauses.Correlation - -namespace OAI - -/-! Projection. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment -open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -def edgeCentered (lam : ℝ) (m : Message) (i : Fin 3) : ℝ := edgeMessage lam m i-1 - -lemma continuous_edgeCentered (lam : ℝ) (i : Fin 3) : - Continuous (fun m : Message ↦ edgeCentered lam m i) := - ((continuous_apply i).comp (continuous_edgeMessage lam)).sub continuous_const - -lemma Law.edgeCentered_mean (Q : Law) (lam : ℝ) (i : Fin 3) : - (∫ m, edgeCentered lam m i ∂Q.probability.toMeasure) = 0 := by - unfold edgeCentered - rw [integral_sub (f := fun m ↦ edgeMessage lam m i) (g := fun _ ↦ (1:ℝ)) - (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) (integrable_const _), - Q.edge_balanced] - simp - -lemma Law.edgeCentered_second (Q : Law) (lam : ℝ) (i : Fin 3) : - (∫ m, edgeCentered lam m i^2 ∂Q.probability.toMeasure) = 2*lam^2*Q.mu := by - rw [Q.integral_equivariant (f := fun m i ↦ edgeCentered lam m i^2) - (fun i ↦ compact_integrable ((continuous_edgeCentered lam i).pow 2)) - (fun _ _ _ ↦ rfl)] - have he (m : Message) : avg (fun i ↦ edgeCentered lam m i^2) = 2*lam^2*xMoment m := by - have hh := xMoment_edge lam m - change (avg (fun i ↦ edgeCentered lam m i^2))/2 = _ at hh - linarith - simp_rw [he] - rw [integral_const_mul] - rfl - -lemma Law.edgeCentered_tilt_diag (Q : Law) (lam : ℝ) (i : Fin 3) : - (∫ m, edgeMessage lam m i*edgeCentered lam m i ∂Q.probability.toMeasure) = 2*lam^2*Q.mu := by - have he (m : Message) : edgeMessage lam m i*edgeCentered lam m i = - edgeCentered lam m i+edgeCentered lam m i^2 := by unfold edgeCentered; ring - simp_rw [he] - rw [integral_add (f := fun m ↦ edgeCentered lam m i) (g := fun m ↦ edgeCentered lam m i^2) - (compact_integrable (continuous_edgeCentered lam i)) - (compact_integrable ((continuous_edgeCentered lam i).pow 2)), - Q.edgeCentered_mean, Q.edgeCentered_second, zero_add] - -lemma Law.edgeCentered_tilt_mean (Q : Law) (lam : ℝ) (i : Fin 3) : - (∫ m, edgeMessage lam m i*edgeCentered lam m 0 ∂Q.probability.toMeasure) = - if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu) := by - have hi (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*edgeCentered lam m 0) Q.probability.toMeasure := - compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul (continuous_edgeCentered lam 0)) - have he : (∫ m, edgeMessage lam m 1*edgeCentered lam m 0 ∂Q.probability.toMeasure) = - ∫ m, edgeMessage lam m 2*edgeCentered lam m 0 ∂Q.probability.toMeasure := by - have hh := (show MeasurePreserving (permuteMeasurableEquiv (Equiv.swap 1 2)) - Q.probability.toMeasure Q.probability.toMeasure from Q.symmetric _).integral_comp' - (fun m ↦ edgeMessage lam m 1*edgeCentered lam m 0) - simpa [permuteMeasurableEquiv, edgeCentered, edge_permute, Equiv.swap_apply_def] using hh.symm - have hsum : avg (fun i ↦ ∫ m, edgeMessage lam m i*edgeCentered lam m 0 ∂Q.probability.toMeasure) = 0 := by - rw [← integral_avg_measure hi] - have hh (m : Message) : avg (fun i ↦ edgeMessage lam m i*edgeCentered lam m 0) = edgeCentered lam m 0 := by - have hav : avg (edgeMessage lam m) = 1 := by - dsimp only [edgeMessage, edge, avg] - have hm := m.2.2 - dsimp only [avg] at hm - linear_combination lam*hm - calc - _ = avg (edgeMessage lam m)*edgeCentered lam m 0 := by dsimp [avg]; ring - _ = _ := by rw [hav, one_mul] - simp_rw [hh] - exact Q.edgeCentered_mean lam 0 - dsimp only [avg] at hsum - rw [Q.edgeCentered_tilt_diag lam 0, he] at hsum - fin_cases i - · simp [Q.edgeCentered_tilt_diag]; ring - · change (∫ m, edgeMessage lam m 1*edgeCentered lam m 0 ∂Q.probability.toMeasure) = -(lam^2*Q.mu) - rw [he]; linarith - · change (∫ m, edgeMessage lam m 2*edgeCentered lam m 0 ∂Q.probability.toMeasure) = -(lam^2*Q.mu) - linarith - -def branchSum (lam : ℝ) {n : ℕ} (m : Fin n → Message) : ℝ := ∑ j, edgeCentered lam (m j) 0 - -lemma continuous_branchSum (lam : ℝ) (n : ℕ) : Continuous (branchSum lam (n := n)) := - continuous_finsetSum _ (fun j _ ↦ (continuous_edgeCentered lam 0).comp (continuous_apply j)) - -lemma integral_branchProduct_sum (Q : Law) (lam : ℝ) (n : ℕ) (i : Fin 3) : - (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*branchSum lam m - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - n*(if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu)) := by - have hh := integral_weighted_sum (ι := Fin n) - (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) - (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edgeCentered lam 0))) (Q.edge_balanced lam i) - simp only [Function.comp_apply] at hh - rw [Q.edgeCentered_tilt_mean] at hh - simpa only [weightProduct, branchProduct, branchEdges, branchSum, Fintype.card_fin, Function.comp_apply] using hh - -lemma integral_normalizer_sum (Q : Law) (lam : ℝ) (n : ℕ) : - (∫ m : Fin n → Message, normalizer (branchEdges lam m)*branchSum lam m - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 0 := by - have he (m : Fin n → Message) : normalizer (branchEdges lam m)*branchSum lam m = - avg (fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m) := by dsimp [normalizer, avg]; ring - simp_rw [he] - rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m) - (fun i ↦ compact_integrable ((continuous_branchProduct lam i).mul (continuous_branchSum lam n)))] - simp_rw [integral_branchProduct_sum] - norm_num [avg, show (2 : Fin 3) ≠ 0 from by decide] - ring - -lemma integral_normalizer_sq_sum (Q : Law) (lam : ℝ) (n : ℕ) : - (∫ m : Fin n → Message, normalizer (branchEdges lam m)*branchSum lam m^2 - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - 2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2 := by - have he (m : Fin n → Message) : normalizer (branchEdges lam m)*branchSum lam m^2 = - avg (fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m^2) := by dsimp [normalizer, avg]; ring - simp_rw [he] - rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m^2) - (fun i ↦ compact_integrable ((continuous_branchProduct lam i).mul ((continuous_branchSum lam n).pow 2)))] - have hh (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*branchSum lam m^2 - ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = - n*(∫ m, edgeMessage lam m i*edgeCentered lam m 0^2 ∂Q.probability.toMeasure)+ - ((n:ℝ)^2-n)*(if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu))^2 := by - have h := integral_weighted_sq_sum (ι := Fin n) - (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) - (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - (continuous_edgeCentered lam 0))) - (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - ((continuous_edgeCentered lam 0).pow 2))) (Q.edge_balanced lam i) - simp only [Function.comp_apply] at h - rw [Q.edgeCentered_tilt_mean] at h - simpa only [weightProduct, branchProduct, branchEdges, branchSum, Fintype.card_fin, Function.comp_apply] using h - simp_rw [hh] - rw [avg_add, avg_mul] - have hmean : avg (fun i ↦ ∫ m, edgeMessage lam m i*edgeCentered lam m 0^2 ∂Q.probability.toMeasure) = - 2*lam^2*Q.mu := by - rw [← integral_avg_measure (f := fun m : Message ↦ fun i ↦ edgeMessage lam m i*edgeCentered lam m 0^2) - (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul - ((continuous_edgeCentered lam 0).pow 2)))] - have hh (m : Message) : avg (fun i ↦ edgeMessage lam m i*edgeCentered lam m 0^2) = edgeCentered lam m 0^2 := by - have hm := m.2.2 - dsimp only [edgeMessage, edge, edgeCentered, avg] at * - linear_combination (1+lam*(m.1 0-1)-1)^2*lam*hm - simp_rw [hh] - exact Q.edgeCentered_second lam 0 - rw [hmean] - norm_num [avg, show (2 : Fin 3) ≠ 0 from by decide] - ring - -lemma Law.centered_second (Q : Law) (i : Fin 3) : - (∫ m, (m.1 i-1)^2 ∂Q.probability.toMeasure) = 2*Q.mu := by - simpa [edgeCentered, edgeMessage, edge] using Q.edgeCentered_second 1 i - -lemma integral_posterior_sum (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : - (∫ m : Fin n → Message, ((branchOutput hl₀ hl₁ m).1 0-1)*branchSum lam m - ∂tiltedProduct Q lam n) = 2*n*(lam^2*Q.mu) := by - rw [integral_tiltedProduct Q hl₀ hl₁] - have he (m : Fin n → Message) : - normalizer (branchEdges lam m)*(((branchOutput hl₀ hl₁ m).1 0-1)*branchSum lam m) = - branchProduct (branchEdges lam m) 0*branchSum lam m-normalizer (branchEdges lam m)*branchSum lam m := by - change normalizer (branchEdges lam m)*((branchProduct (branchEdges lam m) 0/normalizer (branchEdges lam m)-1)*branchSum lam m) = _ - field_simp [ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m))] - simp_rw [he] - rw [integral_sub (f := fun m : Fin n → Message ↦ branchProduct (branchEdges lam m) 0*branchSum lam m) - (g := fun m ↦ normalizer (branchEdges lam m)*branchSum lam m) - (compact_integrable ((continuous_branchProduct lam 0).mul (continuous_branchSum lam n))) - (compact_integrable ((continuous_normalizer n lam).mul (continuous_branchSum lam n))), - integral_branchProduct_sum, integral_normalizer_sum] - simp; ring - -lemma finite_projection_quadratic (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (n : ℕ) (a : ℝ) : - 0 ≤ (2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2)*(a*a)+ - (-4*n*(lam^2*Q.mu))*a+2*(finiteLaw Q hl₀ hl₁ n).mu := by - let beta := lam^2*Q.mu - have : IsProbabilityMeasure (tiltedProduct Q lam n) := tiltedProduct_isProbability Q hl₀ hl₁ n - let v : (Fin n → Message) → ℝ := fun m ↦ (branchOutput hl₀ hl₁ m).1 0-1 - have hv : Continuous v := ((continuous_coordinate 0).comp (continuous_branchOutput hl₀ hl₁ n)).sub continuous_const - have hv₂ : (∫ m, v m^2 ∂tiltedProduct Q lam n) = 2*(finiteLaw Q hl₀ hl₁ n).mu := by - have hh := (finiteLaw Q hl₀ hl₁ n).centered_second 0 - change (∫ m, (m.1 0-1)^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at hh - change (∫ m, (m.1 0-1)^2 ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ at hh - rw [integral_map (f := fun m : Message ↦ (m.1 0-1)^2) (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable - (((continuous_coordinate 0).sub continuous_const).pow 2).measurable.aestronglyMeasurable] at hh - exact hh - have hT₂ : (∫ m, branchSum lam m^2 ∂tiltedProduct Q lam n) = - 2*n*beta+2*((n:ℝ)^2-n)*beta^2 := by - rw [integral_tiltedProduct Q hl₀ hl₁] - exact integral_normalizer_sq_sum Q lam n - have hvT : (∫ m, v m*branchSum lam m ∂tiltedProduct Q lam n) = 2*n*beta := - integral_posterior_sum Q hl₀ hl₁ n - show 0 ≤ (2*n*beta+2*((n:ℝ)^2-n)*beta^2)*(a*a)+ - (-4*n*beta)*a+2*(finiteLaw Q hl₀ hl₁ n).mu - have hh := integral_nonneg (μ := tiltedProduct Q lam n) - (f := fun m : Fin n → Message ↦ (v m-a*branchSum lam m)^2) (fun m ↦ sq_nonneg (v m-a*branchSum lam m)) - have he (m : Fin n → Message) : (v m-a*branchSum lam m)^2 = - v m^2-2*a*(v m*branchSum lam m)+a^2*branchSum lam m^2 := by ring - simp_rw [he] at hh - rw [integral_add (f := fun m ↦ v m^2-2*a*(v m*branchSum lam m)) - (g := fun m ↦ a^2*branchSum lam m^2) - ((compact_integrable (hv.pow 2)).sub ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _)) - ((compact_integrable ((continuous_branchSum lam n).pow 2)).const_mul _), - integral_sub (f := fun m ↦ v m^2) (g := fun m ↦ 2*a*(v m*branchSum lam m)) - (compact_integrable (hv.pow 2)) ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _), - integral_const_mul, integral_const_mul, hv₂, hvT, hT₂] at hh - nlinarith [hh] - -theorem finite_projection (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (n : ℕ) (hn : 1 ≤ n) : - (n : ℝ)*(lam^2*Q.mu)/(1+((n:ℝ)-1)*(lam^2*Q.mu)) ≤ (finiteLaw Q hl₀ hl₁ n).mu := by - let beta := lam^2*Q.mu - have hb : 0 ≤ beta := mul_nonneg (sq_nonneg _) Q.mu_nonneg - have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn - have hd : 0 < 1+((n:ℝ)-1)*beta := by nlinarith [mul_nonneg (sub_nonneg.mpr hn') hb] - have : IsProbabilityMeasure (tiltedProduct Q lam n) := tiltedProduct_isProbability Q hl₀ hl₁ n - let v : (Fin n → Message) → ℝ := fun m ↦ (branchOutput hl₀ hl₁ m).1 0-1 - have hv : Continuous v := ((continuous_coordinate 0).comp (continuous_branchOutput hl₀ hl₁ n)).sub continuous_const - have hv₂ : (∫ m, v m^2 ∂tiltedProduct Q lam n) = 2*(finiteLaw Q hl₀ hl₁ n).mu := by - have hh := (finiteLaw Q hl₀ hl₁ n).centered_second 0 - change (∫ m, (m.1 0-1)^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at hh - change (∫ m, (m.1 0-1)^2 ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ at hh - rw [integral_map (f := fun m : Message ↦ (m.1 0-1)^2) (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable - (((continuous_coordinate 0).sub continuous_const).pow 2).measurable.aestronglyMeasurable] at hh - exact hh - have hT₂ : (∫ m, branchSum lam m^2 ∂tiltedProduct Q lam n) = - 2*n*beta+2*((n:ℝ)^2-n)*beta^2 := by - rw [integral_tiltedProduct Q hl₀ hl₁] - exact integral_normalizer_sq_sum Q lam n - have hvT : (∫ m, v m*branchSum lam m ∂tiltedProduct Q lam n) = 2*n*beta := - integral_posterior_sum Q hl₀ hl₁ n - have hquad (a : ℝ) : 0 ≤ (2*n*beta+2*((n:ℝ)^2-n)*beta^2)*(a*a)+ - (-4*n*beta)*a+2*(finiteLaw Q hl₀ hl₁ n).mu := by - have hh := integral_nonneg (μ := tiltedProduct Q lam n) - (f := fun m : Fin n → Message ↦ (v m-a*branchSum lam m)^2) (fun m ↦ sq_nonneg (v m-a*branchSum lam m)) - have he (m : Fin n → Message) : (v m-a*branchSum lam m)^2 = - v m^2-2*a*(v m*branchSum lam m)+a^2*branchSum lam m^2 := by ring - simp_rw [he] at hh - rw [integral_add (f := fun m ↦ v m^2-2*a*(v m*branchSum lam m)) - (g := fun m ↦ a^2*branchSum lam m^2) - ((compact_integrable (hv.pow 2)).sub ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _)) - ((compact_integrable ((continuous_branchSum lam n).pow 2)).const_mul _), - integral_sub (f := fun m ↦ v m^2) (g := fun m ↦ 2*a*(v m*branchSum lam m)) - (compact_integrable (hv.pow 2)) ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _), - integral_const_mul, integral_const_mul, hv₂, hvT, hT₂] at hh - nlinarith [hh] - have hh := discrim_le_zero hquad - dsimp only [discrim] at hh - have hcs : ((n:ℝ)*beta)^2 ≤ (finiteLaw Q hl₀ hl₁ n).mu*((n:ℝ)*beta+((n:ℝ)^2-n)*beta^2) := by nlinarith [hh] - rcases eq_or_lt_of_le hb with hb0 | hbpos - · have hb0' : beta = 0 := hb0.symm - change (n:ℝ)*beta/(1+((n:ℝ)-1)*beta) ≤ _ - simp only [hb0', mul_zero, add_zero, zero_div] - exact (finiteLaw Q hl₀ hl₁ n).mu_nonneg - · have hnb : 0 < (n:ℝ)*beta := mul_pos (lt_of_lt_of_le zero_lt_one hn') hbpos - apply (div_le_iff₀ hd).2 - apply le_of_mul_le_mul_left (a := (n:ℝ)*beta) (b := (n:ℝ)*beta) (c := (finiteLaw Q hl₀ hl₁ n).mu*(1+((n:ℝ)-1)*beta)) _ hnb - calc - (n:ℝ)*beta*((n:ℝ)*beta) = ((n:ℝ)*beta)^2 := by ring - _ ≤ _ := hcs - _ = _ := by ring - -end ThreeState.TreeClauses.Experiment - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.FiniteUpdate +import OAI.Probability.ThreeStateClauses.Correlation + +namespace OAI + +/-! Projection. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment +open ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +def edgeCentered (lam : ℝ) (m : Message) (i : Fin 3) : ℝ := edgeMessage lam m i-1 + +lemma continuous_edgeCentered (lam : ℝ) (i : Fin 3) : + Continuous (fun m : Message ↦ edgeCentered lam m i) := + ((continuous_apply i).comp (continuous_edgeMessage lam)).sub continuous_const + +lemma Law.edgeCentered_mean (Q : Law) (lam : ℝ) (i : Fin 3) : + (∫ m, edgeCentered lam m i ∂Q.probability.toMeasure) = 0 := by + unfold edgeCentered + rw [integral_sub (f := fun m ↦ edgeMessage lam m i) (g := fun _ ↦ (1:ℝ)) + (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) (integrable_const _), + Q.edge_balanced] + simp + +lemma Law.edgeCentered_second (Q : Law) (lam : ℝ) (i : Fin 3) : + (∫ m, edgeCentered lam m i^2 ∂Q.probability.toMeasure) = 2*lam^2*Q.mu := by + rw [Q.integral_equivariant (f := fun m i ↦ edgeCentered lam m i^2) + (fun i ↦ compact_integrable ((continuous_edgeCentered lam i).pow 2)) + (fun _ _ _ ↦ rfl)] + have he (m : Message) : avg (fun i ↦ edgeCentered lam m i^2) = 2*lam^2*xMoment m := by + have hh := xMoment_edge lam m + change (avg (fun i ↦ edgeCentered lam m i^2))/2 = _ at hh + linarith + simp_rw [he] + rw [integral_const_mul] + rfl + +lemma Law.edgeCentered_tilt_diag (Q : Law) (lam : ℝ) (i : Fin 3) : + (∫ m, edgeMessage lam m i*edgeCentered lam m i ∂Q.probability.toMeasure) = 2*lam^2*Q.mu := by + have he (m : Message) : edgeMessage lam m i*edgeCentered lam m i = + edgeCentered lam m i+edgeCentered lam m i^2 := by unfold edgeCentered; ring + simp_rw [he] + rw [integral_add (f := fun m ↦ edgeCentered lam m i) (g := fun m ↦ edgeCentered lam m i^2) + (compact_integrable (continuous_edgeCentered lam i)) + (compact_integrable ((continuous_edgeCentered lam i).pow 2)), + Q.edgeCentered_mean, Q.edgeCentered_second, zero_add] + +lemma Law.edgeCentered_tilt_mean (Q : Law) (lam : ℝ) (i : Fin 3) : + (∫ m, edgeMessage lam m i*edgeCentered lam m 0 ∂Q.probability.toMeasure) = + if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu) := by + have hi (i : Fin 3) : Integrable (fun m ↦ edgeMessage lam m i*edgeCentered lam m 0) Q.probability.toMeasure := + compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul (continuous_edgeCentered lam 0)) + have he : (∫ m, edgeMessage lam m 1*edgeCentered lam m 0 ∂Q.probability.toMeasure) = + ∫ m, edgeMessage lam m 2*edgeCentered lam m 0 ∂Q.probability.toMeasure := by + have hh := (show MeasurePreserving (permuteMeasurableEquiv (Equiv.swap 1 2)) + Q.probability.toMeasure Q.probability.toMeasure from Q.symmetric _).integral_comp' + (fun m ↦ edgeMessage lam m 1*edgeCentered lam m 0) + simpa [permuteMeasurableEquiv, edgeCentered, edge_permute, Equiv.swap_apply_def] using hh.symm + have hsum : avg (fun i ↦ ∫ m, edgeMessage lam m i*edgeCentered lam m 0 ∂Q.probability.toMeasure) = 0 := by + rw [← integral_avg_measure hi] + have hh (m : Message) : avg (fun i ↦ edgeMessage lam m i*edgeCentered lam m 0) = edgeCentered lam m 0 := by + have hav : avg (edgeMessage lam m) = 1 := by + dsimp only [edgeMessage, edge, avg] + have hm := m.2.2 + dsimp only [avg] at hm + linear_combination lam*hm + calc + _ = avg (edgeMessage lam m)*edgeCentered lam m 0 := by dsimp [avg]; ring + _ = _ := by rw [hav, one_mul] + simp_rw [hh] + exact Q.edgeCentered_mean lam 0 + dsimp only [avg] at hsum + rw [Q.edgeCentered_tilt_diag lam 0, he] at hsum + fin_cases i + · simp [Q.edgeCentered_tilt_diag]; ring + · change (∫ m, edgeMessage lam m 1*edgeCentered lam m 0 ∂Q.probability.toMeasure) = -(lam^2*Q.mu) + rw [he]; linarith + · change (∫ m, edgeMessage lam m 2*edgeCentered lam m 0 ∂Q.probability.toMeasure) = -(lam^2*Q.mu) + linarith + +def branchSum (lam : ℝ) {n : ℕ} (m : Fin n → Message) : ℝ := ∑ j, edgeCentered lam (m j) 0 + +lemma continuous_branchSum (lam : ℝ) (n : ℕ) : Continuous (branchSum lam (n := n)) := + continuous_finsetSum _ (fun j _ ↦ (continuous_edgeCentered lam 0).comp (continuous_apply j)) + +lemma integral_branchProduct_sum (Q : Law) (lam : ℝ) (n : ℕ) (i : Fin 3) : + (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*branchSum lam m + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + n*(if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu)) := by + have hh := integral_weighted_sum (ι := Fin n) + (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) + (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edgeCentered lam 0))) (Q.edge_balanced lam i) + simp only [Function.comp_apply] at hh + rw [Q.edgeCentered_tilt_mean] at hh + simpa only [weightProduct, branchProduct, branchEdges, branchSum, Fintype.card_fin, Function.comp_apply] using hh + +lemma integral_normalizer_sum (Q : Law) (lam : ℝ) (n : ℕ) : + (∫ m : Fin n → Message, normalizer (branchEdges lam m)*branchSum lam m + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = 0 := by + have he (m : Fin n → Message) : normalizer (branchEdges lam m)*branchSum lam m = + avg (fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m) := by dsimp [normalizer, avg]; ring + simp_rw [he] + rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m) + (fun i ↦ compact_integrable ((continuous_branchProduct lam i).mul (continuous_branchSum lam n)))] + simp_rw [integral_branchProduct_sum] + norm_num [avg, show (2 : Fin 3) ≠ 0 from by decide] + ring + +lemma integral_normalizer_sq_sum (Q : Law) (lam : ℝ) (n : ℕ) : + (∫ m : Fin n → Message, normalizer (branchEdges lam m)*branchSum lam m^2 + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + 2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2 := by + have he (m : Fin n → Message) : normalizer (branchEdges lam m)*branchSum lam m^2 = + avg (fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m^2) := by dsimp [normalizer, avg]; ring + simp_rw [he] + rw [integral_avg_measure (f := fun m : Fin n → Message ↦ fun i ↦ branchProduct (branchEdges lam m) i*branchSum lam m^2) + (fun i ↦ compact_integrable ((continuous_branchProduct lam i).mul ((continuous_branchSum lam n).pow 2)))] + have hh (i : Fin 3) : (∫ m : Fin n → Message, branchProduct (branchEdges lam m) i*branchSum lam m^2 + ∂(Measure.pi fun _ ↦ Q.probability.toMeasure)) = + n*(∫ m, edgeMessage lam m i*edgeCentered lam m 0^2 ∂Q.probability.toMeasure)+ + ((n:ℝ)^2-n)*(if i=0 then 2*(lam^2*Q.mu) else -(lam^2*Q.mu))^2 := by + have h := integral_weighted_sq_sum (ι := Fin n) + (compact_integrable ((continuous_apply i).comp (continuous_edgeMessage lam))) + (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + (continuous_edgeCentered lam 0))) + (compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + ((continuous_edgeCentered lam 0).pow 2))) (Q.edge_balanced lam i) + simp only [Function.comp_apply] at h + rw [Q.edgeCentered_tilt_mean] at h + simpa only [weightProduct, branchProduct, branchEdges, branchSum, Fintype.card_fin, Function.comp_apply] using h + simp_rw [hh] + rw [avg_add, avg_mul] + have hmean : avg (fun i ↦ ∫ m, edgeMessage lam m i*edgeCentered lam m 0^2 ∂Q.probability.toMeasure) = + 2*lam^2*Q.mu := by + rw [← integral_avg_measure (f := fun m : Message ↦ fun i ↦ edgeMessage lam m i*edgeCentered lam m 0^2) + (fun i ↦ compact_integrable (((continuous_apply i).comp (continuous_edgeMessage lam)).mul + ((continuous_edgeCentered lam 0).pow 2)))] + have hh (m : Message) : avg (fun i ↦ edgeMessage lam m i*edgeCentered lam m 0^2) = edgeCentered lam m 0^2 := by + have hm := m.2.2 + dsimp only [edgeMessage, edge, edgeCentered, avg] at * + linear_combination (1+lam*(m.1 0-1)-1)^2*lam*hm + simp_rw [hh] + exact Q.edgeCentered_second lam 0 + rw [hmean] + norm_num [avg, show (2 : Fin 3) ≠ 0 from by decide] + ring + +lemma Law.centered_second (Q : Law) (i : Fin 3) : + (∫ m, (m.1 i-1)^2 ∂Q.probability.toMeasure) = 2*Q.mu := by + simpa [edgeCentered, edgeMessage, edge] using Q.edgeCentered_second 1 i + +lemma integral_posterior_sum (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) (n : ℕ) : + (∫ m : Fin n → Message, ((branchOutput hl₀ hl₁ m).1 0-1)*branchSum lam m + ∂tiltedProduct Q lam n) = 2*n*(lam^2*Q.mu) := by + rw [integral_tiltedProduct Q hl₀ hl₁] + have he (m : Fin n → Message) : + normalizer (branchEdges lam m)*(((branchOutput hl₀ hl₁ m).1 0-1)*branchSum lam m) = + branchProduct (branchEdges lam m) 0*branchSum lam m-normalizer (branchEdges lam m)*branchSum lam m := by + change normalizer (branchEdges lam m)*((branchProduct (branchEdges lam m) 0/normalizer (branchEdges lam m)-1)*branchSum lam m) = _ + field_simp [ne_of_gt (normalizer_positive (branchEdges_positive hl₀ hl₁ m))] + simp_rw [he] + rw [integral_sub (f := fun m : Fin n → Message ↦ branchProduct (branchEdges lam m) 0*branchSum lam m) + (g := fun m ↦ normalizer (branchEdges lam m)*branchSum lam m) + (compact_integrable ((continuous_branchProduct lam 0).mul (continuous_branchSum lam n))) + (compact_integrable ((continuous_normalizer n lam).mul (continuous_branchSum lam n))), + integral_branchProduct_sum, integral_normalizer_sum] + simp; ring + +lemma finite_projection_quadratic (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (n : ℕ) (a : ℝ) : + 0 ≤ (2*n*(lam^2*Q.mu)+2*((n:ℝ)^2-n)*(lam^2*Q.mu)^2)*(a*a)+ + (-4*n*(lam^2*Q.mu))*a+2*(finiteLaw Q hl₀ hl₁ n).mu := by + let beta := lam^2*Q.mu + have : IsProbabilityMeasure (tiltedProduct Q lam n) := tiltedProduct_isProbability Q hl₀ hl₁ n + let v : (Fin n → Message) → ℝ := fun m ↦ (branchOutput hl₀ hl₁ m).1 0-1 + have hv : Continuous v := ((continuous_coordinate 0).comp (continuous_branchOutput hl₀ hl₁ n)).sub continuous_const + have hv₂ : (∫ m, v m^2 ∂tiltedProduct Q lam n) = 2*(finiteLaw Q hl₀ hl₁ n).mu := by + have hh := (finiteLaw Q hl₀ hl₁ n).centered_second 0 + change (∫ m, (m.1 0-1)^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at hh + change (∫ m, (m.1 0-1)^2 ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ at hh + rw [integral_map (f := fun m : Message ↦ (m.1 0-1)^2) (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable + (((continuous_coordinate 0).sub continuous_const).pow 2).measurable.aestronglyMeasurable] at hh + exact hh + have hT₂ : (∫ m, branchSum lam m^2 ∂tiltedProduct Q lam n) = + 2*n*beta+2*((n:ℝ)^2-n)*beta^2 := by + rw [integral_tiltedProduct Q hl₀ hl₁] + exact integral_normalizer_sq_sum Q lam n + have hvT : (∫ m, v m*branchSum lam m ∂tiltedProduct Q lam n) = 2*n*beta := + integral_posterior_sum Q hl₀ hl₁ n + show 0 ≤ (2*n*beta+2*((n:ℝ)^2-n)*beta^2)*(a*a)+ + (-4*n*beta)*a+2*(finiteLaw Q hl₀ hl₁ n).mu + have hh := integral_nonneg (μ := tiltedProduct Q lam n) + (f := fun m : Fin n → Message ↦ (v m-a*branchSum lam m)^2) (fun m ↦ sq_nonneg (v m-a*branchSum lam m)) + have he (m : Fin n → Message) : (v m-a*branchSum lam m)^2 = + v m^2-2*a*(v m*branchSum lam m)+a^2*branchSum lam m^2 := by ring + simp_rw [he] at hh + rw [integral_add (f := fun m ↦ v m^2-2*a*(v m*branchSum lam m)) + (g := fun m ↦ a^2*branchSum lam m^2) + ((compact_integrable (hv.pow 2)).sub ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _)) + ((compact_integrable ((continuous_branchSum lam n).pow 2)).const_mul _), + integral_sub (f := fun m ↦ v m^2) (g := fun m ↦ 2*a*(v m*branchSum lam m)) + (compact_integrable (hv.pow 2)) ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _), + integral_const_mul, integral_const_mul, hv₂, hvT, hT₂] at hh + nlinarith [hh] + +theorem finite_projection (Q : Law) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (n : ℕ) (hn : 1 ≤ n) : + (n : ℝ)*(lam^2*Q.mu)/(1+((n:ℝ)-1)*(lam^2*Q.mu)) ≤ (finiteLaw Q hl₀ hl₁ n).mu := by + let beta := lam^2*Q.mu + have hb : 0 ≤ beta := mul_nonneg (sq_nonneg _) Q.mu_nonneg + have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn + have hd : 0 < 1+((n:ℝ)-1)*beta := by nlinarith [mul_nonneg (sub_nonneg.mpr hn') hb] + have : IsProbabilityMeasure (tiltedProduct Q lam n) := tiltedProduct_isProbability Q hl₀ hl₁ n + let v : (Fin n → Message) → ℝ := fun m ↦ (branchOutput hl₀ hl₁ m).1 0-1 + have hv : Continuous v := ((continuous_coordinate 0).comp (continuous_branchOutput hl₀ hl₁ n)).sub continuous_const + have hv₂ : (∫ m, v m^2 ∂tiltedProduct Q lam n) = 2*(finiteLaw Q hl₀ hl₁ n).mu := by + have hh := (finiteLaw Q hl₀ hl₁ n).centered_second 0 + change (∫ m, (m.1 0-1)^2 ∂(finiteProbability Q hl₀ hl₁ n).toMeasure) = _ at hh + change (∫ m, (m.1 0-1)^2 ∂Measure.map (branchOutput hl₀ hl₁) (tiltedProduct Q lam n)) = _ at hh + rw [integral_map (f := fun m : Message ↦ (m.1 0-1)^2) (continuous_branchOutput hl₀ hl₁ n).measurable.aemeasurable + (((continuous_coordinate 0).sub continuous_const).pow 2).measurable.aestronglyMeasurable] at hh + exact hh + have hT₂ : (∫ m, branchSum lam m^2 ∂tiltedProduct Q lam n) = + 2*n*beta+2*((n:ℝ)^2-n)*beta^2 := by + rw [integral_tiltedProduct Q hl₀ hl₁] + exact integral_normalizer_sq_sum Q lam n + have hvT : (∫ m, v m*branchSum lam m ∂tiltedProduct Q lam n) = 2*n*beta := + integral_posterior_sum Q hl₀ hl₁ n + have hquad (a : ℝ) : 0 ≤ (2*n*beta+2*((n:ℝ)^2-n)*beta^2)*(a*a)+ + (-4*n*beta)*a+2*(finiteLaw Q hl₀ hl₁ n).mu := by + have hh := integral_nonneg (μ := tiltedProduct Q lam n) + (f := fun m : Fin n → Message ↦ (v m-a*branchSum lam m)^2) (fun m ↦ sq_nonneg (v m-a*branchSum lam m)) + have he (m : Fin n → Message) : (v m-a*branchSum lam m)^2 = + v m^2-2*a*(v m*branchSum lam m)+a^2*branchSum lam m^2 := by ring + simp_rw [he] at hh + rw [integral_add (f := fun m ↦ v m^2-2*a*(v m*branchSum lam m)) + (g := fun m ↦ a^2*branchSum lam m^2) + ((compact_integrable (hv.pow 2)).sub ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _)) + ((compact_integrable ((continuous_branchSum lam n).pow 2)).const_mul _), + integral_sub (f := fun m ↦ v m^2) (g := fun m ↦ 2*a*(v m*branchSum lam m)) + (compact_integrable (hv.pow 2)) ((compact_integrable (hv.mul (continuous_branchSum lam n))).const_mul _), + integral_const_mul, integral_const_mul, hv₂, hvT, hT₂] at hh + nlinarith [hh] + have hh := discrim_le_zero hquad + dsimp only [discrim] at hh + have hcs : ((n:ℝ)*beta)^2 ≤ (finiteLaw Q hl₀ hl₁ n).mu*((n:ℝ)*beta+((n:ℝ)^2-n)*beta^2) := by nlinarith [hh] + rcases eq_or_lt_of_le hb with hb0 | hbpos + · have hb0' : beta = 0 := hb0.symm + change (n:ℝ)*beta/(1+((n:ℝ)-1)*beta) ≤ _ + simp only [hb0', mul_zero, add_zero, zero_div] + exact (finiteLaw Q hl₀ hl₁ n).mu_nonneg + · have hnb : 0 < (n:ℝ)*beta := mul_pos (lt_of_lt_of_le zero_lt_one hn') hbpos + apply (div_le_iff₀ hd).2 + apply le_of_mul_le_mul_left (a := (n:ℝ)*beta) (b := (n:ℝ)*beta) (c := (finiteLaw Q hl₀ hl₁ n).mu*(1+((n:ℝ)-1)*beta)) _ hnb + calc + (n:ℝ)*beta*((n:ℝ)*beta) = ((n:ℝ)*beta)^2 := by ring + _ ≤ _ := hcs + _ = _ := by ring + +end ThreeState.TreeClauses.Experiment + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RadialAlgebra.lean b/lean/OAI/Probability/ThreeStateClauses/RadialAlgebra.lean index 2d42f24b3e3acd3ff40813487b0b6f3cebcf339b..e22fe422ec56f09921877cc5f6dac80523fa3156 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RadialAlgebra.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RadialAlgebra.lean @@ -1,161 +1,161 @@ -import Mathlib - -namespace OAI - -/-! Radial Algebra. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -namespace ThreeState.TreeClauses.Radial - -abbrev Vec := Fin 3 → ℝ - -def avg (w : Vec) : ℝ := (w 0 + w 1 + w 2) / 3 - -def PositiveMessage (m : Vec) : Prop := (∀ i, 0 < m i) ∧ avg m = 1 - -def centered (m : Vec) : Vec := fun i ↦ m i - 1 - -def momentX (v : Vec) : ℝ := avg (fun i ↦ v i ^ 2) / 2 - -def momentY (v : Vec) : ℝ := avg (fun i ↦ v i ^ 3) / 2 - -def logAverage (m : Vec) : ℝ := avg (fun i ↦ Real.log (m i)) - -def logCentered (m : Vec) : Vec := fun i ↦ Real.log (m i) - logAverage m - -def info (m : Vec) : ℝ := avg (fun i ↦ m i * Real.log (m i)) - -def symEntropy (m : Vec) : ℝ := avg (fun i ↦ (m i - 1) * Real.log (m i)) / 2 - -def correction (m : Vec) : ℝ := avg (fun i ↦ m i * logCentered m i ^ 2) / 2 - -def functional (m : Vec) : ℝ := 3 * info m - 2 * symEntropy m + (4 / 5) * correction m - -def edge (t : ℝ) (m : Vec) : Vec := fun i ↦ 1 + t * (m i - 1) - -def RadialInequality : Prop := ∀ (m : Vec), PositiveMessage m → ∀ (lam : ℝ), - 0 < lam → lam < 1 → - (1 - lam ^ 2) / 2 * momentX (centered m) ^ 2 ≤ - functional m - (lam ^ 2)⁻¹ * functional (edge lam m) - -lemma avg_add (v w : Vec) : avg (fun i ↦ v i + w i) = avg v + avg w := by - simp only [avg]; ring - -lemma avg_sub (v w : Vec) : avg (fun i ↦ v i - w i) = avg v - avg w := by - simp only [avg]; ring - -lemma avg_mul (a : ℝ) (v : Vec) : avg (fun i ↦ a * v i) = a * avg v := by - simp only [avg]; ring - -lemma avg_const (a : ℝ) : avg (fun _ ↦ a) = a := by simp only [avg]; ring - -lemma avg_centered {m : Vec} (hm : PositiveMessage m) : avg (centered m) = 0 := by - have h := hm.2 - dsimp [centered, avg] at * - linarith - -lemma info_eq (m : Vec) : info m = logAverage m + 2 * symEntropy m := by - simp only [info, logAverage, symEntropy, avg]; ring - -lemma functional_eq (m : Vec) : - functional m = 3 * logAverage m + 4 * symEntropy m + (4 / 5) * correction m := by - rw [functional, info_eq]; ring - -lemma third_eq {v : Vec} (hv : avg v = 0) : v 2 = -v 0 - v 1 := by - simp only [avg] at hv; linarith - -lemma momentX_nonneg (v : Vec) : 0 ≤ momentX v := by - unfold momentX avg; positivity - -lemma cubic {v : Vec} (hv : avg v = 0) (i : Fin 3) : - v i ^ 3 = 3 * momentX v * v i + 2 * momentY v := by - have hc := third_eq hv - fin_cases i - · change v 0 ^ 3 = 3 * momentX v * v 0 + 2 * momentY v - simp only [momentX, momentY, avg]; rw [hc]; ring - · change v 1 ^ 3 = 3 * momentX v * v 1 + 2 * momentY v - simp only [momentX, momentY, avg]; rw [hc]; ring - · change v 2 ^ 3 = 3 * momentX v * v 2 + 2 * momentY v - simp only [momentX, momentY, avg]; rw [hc]; ring - -lemma product_eq {v : Vec} (hv : avg v = 0) (t : ℝ) : - (1 + t * v 0) * (1 + t * v 1) * (1 + t * v 2) = - 1 - 3 * t ^ 2 * momentX v + 2 * t ^ 3 * momentY v := by - simp only [momentX, momentY, avg]; rw [third_eq hv]; ring - -lemma discriminant {v : Vec} (hv : avg v = 0) : - (v 0 - v 1) ^ 2 * (v 0 - v 2) ^ 2 * (v 1 - v 2) ^ 2 = - 108 * (momentX v ^ 3 - momentY v ^ 2) := by - simp only [momentX, momentY, avg]; rw [third_eq hv]; ring - -lemma moment_discriminant {v : Vec} (hv : avg v = 0) : - momentY v ^ 2 ≤ momentX v ^ 3 := by - have h : 0 ≤ (v 0 - v 1) ^ 2 * (v 0 - v 2) ^ 2 * (v 1 - v 2) ^ 2 := by positivity - rw [discriminant hv] at h; linarith - -lemma momentX_lt_one {m : Vec} (hm : PositiveMessage m) : momentX (centered m) < 1 := by - have hs : m 0 + m 1 + m 2 = 3 := by simpa only [avg, div_eq_iff (by norm_num : (3:ℝ) ≠ 0), one_mul] using hm.2 - have h01 := mul_pos (hm.1 0) (hm.1 1) - have h02 := mul_pos (hm.1 0) (hm.1 2) - have h12 := mul_pos (hm.1 1) (hm.1 2) - dsimp [momentX, avg, centered] - nlinarith [sq_nonneg (m 0 + m 1 + m 2 - 3)] - -lemma denominator_pos {m : Vec} (hm : PositiveMessage m) (t : ℝ) - (ht : t ∈ Set.Icc (0 : ℝ) 1) : - 0 < 1 - 3 * t ^ 2 * momentX (centered m) + 2 * t ^ 3 * momentY (centered m) := by - rw [← product_eq (avg_centered hm)] - have hi (i : Fin 3) : 0 < 1 + t * centered m i := by - dsimp [centered] - by_cases h : t = 0 - · subst t; norm_num - · have ht0 : 0 < t := lt_of_le_of_ne ht.1 (Ne.symm h) - have := mul_pos ht0 (hm.1 i) - nlinarith [ht.2] - exact mul_pos (mul_pos (hi 0) (hi 1)) (hi 2) - -def hpoly (v : Vec) : Vec := fun i ↦ 1 - v i + v i ^ 2 - 3 * momentX v - -def Hpoly (j : ℕ) (v : Vec) : ℝ := avg (fun i ↦ hpoly v i ^ j) - -lemma Hpoly_one {v : Vec} (hv : avg v = 0) : Hpoly 1 v = 1 - momentX v := by - simp only [Hpoly, hpoly, momentX, avg, pow_one]; rw [third_eq hv]; ring - -lemma Hpoly_two {v : Vec} (hv : avg v = 0) : - Hpoly 2 v = 3 * momentX v ^ 2 - 4 * momentY v + 1 := by - simp only [Hpoly, hpoly, momentX, momentY, avg]; rw [third_eq hv]; ring - -lemma Hpoly_three {v : Vec} (hv : avg v = 0) : - Hpoly 3 v = -9 * momentX v ^ 3 + 9 * momentX v ^ 2 + - 6 * momentX v * momentY v + 3 * momentX v + 4 * momentY v ^ 2 - 14 * momentY v + 1 := by - simp only [Hpoly, hpoly, momentX, momentY, avg]; rw [third_eq hv]; ring - -def polyA (x y : ℝ) : ℝ := - 3*x^4 + 12*x^3 + x^2 + (-6*x^3 - 28*x^2 - 2*x)*y + (26*x - 2)*y^2 - 4*y^3 - -def polyC (x y : ℝ) : ℝ := - 6*x^4 - 2*x^3 + (-13*x^3 - 10*x^2 - x)*y + (10*x^2 + 22*x + 4)*y^2 - 16*y^3 - -def polyN (x y t : ℝ) : ℝ := (24/5) * (polyA x y + t * polyC x y) - -def polyL (x y : ℝ) : ℝ := - 1500*x^5 - 1020*x^4 + 240*x^3 + 168*y^4 + - (-480*x^2 - 756*x - 52)*y^3 + - (2114*x^3 + 710*x^2 + 48*x - 80)*y^2 + - (-3093*x^4 + 736*x^3 - 35*x^2)*y - -lemma polyN_one (x y : ℝ) : - polyN x y 1 = (24/5) * (x-y) * (9*x-10*y+1) * (x^2+x-2*y) := by - simp only [polyN, polyA, polyC]; ring - -lemma polyN_affine (x y t : ℝ) : - polyN x y t = (1-t)*polyN x y 0 + t*polyN x y 1 := by - simp only [polyN]; ring - -end ThreeState.TreeClauses.Radial - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Radial Algebra. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +namespace ThreeState.TreeClauses.Radial + +abbrev Vec := Fin 3 → ℝ + +def avg (w : Vec) : ℝ := (w 0 + w 1 + w 2) / 3 + +def PositiveMessage (m : Vec) : Prop := (∀ i, 0 < m i) ∧ avg m = 1 + +def centered (m : Vec) : Vec := fun i ↦ m i - 1 + +def momentX (v : Vec) : ℝ := avg (fun i ↦ v i ^ 2) / 2 + +def momentY (v : Vec) : ℝ := avg (fun i ↦ v i ^ 3) / 2 + +def logAverage (m : Vec) : ℝ := avg (fun i ↦ Real.log (m i)) + +def logCentered (m : Vec) : Vec := fun i ↦ Real.log (m i) - logAverage m + +def info (m : Vec) : ℝ := avg (fun i ↦ m i * Real.log (m i)) + +def symEntropy (m : Vec) : ℝ := avg (fun i ↦ (m i - 1) * Real.log (m i)) / 2 + +def correction (m : Vec) : ℝ := avg (fun i ↦ m i * logCentered m i ^ 2) / 2 + +def functional (m : Vec) : ℝ := 3 * info m - 2 * symEntropy m + (4 / 5) * correction m + +def edge (t : ℝ) (m : Vec) : Vec := fun i ↦ 1 + t * (m i - 1) + +def RadialInequality : Prop := ∀ (m : Vec), PositiveMessage m → ∀ (lam : ℝ), + 0 < lam → lam < 1 → + (1 - lam ^ 2) / 2 * momentX (centered m) ^ 2 ≤ + functional m - (lam ^ 2)⁻¹ * functional (edge lam m) + +lemma avg_add (v w : Vec) : avg (fun i ↦ v i + w i) = avg v + avg w := by + simp only [avg]; ring + +lemma avg_sub (v w : Vec) : avg (fun i ↦ v i - w i) = avg v - avg w := by + simp only [avg]; ring + +lemma avg_mul (a : ℝ) (v : Vec) : avg (fun i ↦ a * v i) = a * avg v := by + simp only [avg]; ring + +lemma avg_const (a : ℝ) : avg (fun _ ↦ a) = a := by simp only [avg]; ring + +lemma avg_centered {m : Vec} (hm : PositiveMessage m) : avg (centered m) = 0 := by + have h := hm.2 + dsimp [centered, avg] at * + linarith + +lemma info_eq (m : Vec) : info m = logAverage m + 2 * symEntropy m := by + simp only [info, logAverage, symEntropy, avg]; ring + +lemma functional_eq (m : Vec) : + functional m = 3 * logAverage m + 4 * symEntropy m + (4 / 5) * correction m := by + rw [functional, info_eq]; ring + +lemma third_eq {v : Vec} (hv : avg v = 0) : v 2 = -v 0 - v 1 := by + simp only [avg] at hv; linarith + +lemma momentX_nonneg (v : Vec) : 0 ≤ momentX v := by + unfold momentX avg; positivity + +lemma cubic {v : Vec} (hv : avg v = 0) (i : Fin 3) : + v i ^ 3 = 3 * momentX v * v i + 2 * momentY v := by + have hc := third_eq hv + fin_cases i + · change v 0 ^ 3 = 3 * momentX v * v 0 + 2 * momentY v + simp only [momentX, momentY, avg]; rw [hc]; ring + · change v 1 ^ 3 = 3 * momentX v * v 1 + 2 * momentY v + simp only [momentX, momentY, avg]; rw [hc]; ring + · change v 2 ^ 3 = 3 * momentX v * v 2 + 2 * momentY v + simp only [momentX, momentY, avg]; rw [hc]; ring + +lemma product_eq {v : Vec} (hv : avg v = 0) (t : ℝ) : + (1 + t * v 0) * (1 + t * v 1) * (1 + t * v 2) = + 1 - 3 * t ^ 2 * momentX v + 2 * t ^ 3 * momentY v := by + simp only [momentX, momentY, avg]; rw [third_eq hv]; ring + +lemma discriminant {v : Vec} (hv : avg v = 0) : + (v 0 - v 1) ^ 2 * (v 0 - v 2) ^ 2 * (v 1 - v 2) ^ 2 = + 108 * (momentX v ^ 3 - momentY v ^ 2) := by + simp only [momentX, momentY, avg]; rw [third_eq hv]; ring + +lemma moment_discriminant {v : Vec} (hv : avg v = 0) : + momentY v ^ 2 ≤ momentX v ^ 3 := by + have h : 0 ≤ (v 0 - v 1) ^ 2 * (v 0 - v 2) ^ 2 * (v 1 - v 2) ^ 2 := by positivity + rw [discriminant hv] at h; linarith + +lemma momentX_lt_one {m : Vec} (hm : PositiveMessage m) : momentX (centered m) < 1 := by + have hs : m 0 + m 1 + m 2 = 3 := by simpa only [avg, div_eq_iff (by norm_num : (3:ℝ) ≠ 0), one_mul] using hm.2 + have h01 := mul_pos (hm.1 0) (hm.1 1) + have h02 := mul_pos (hm.1 0) (hm.1 2) + have h12 := mul_pos (hm.1 1) (hm.1 2) + dsimp [momentX, avg, centered] + nlinarith [sq_nonneg (m 0 + m 1 + m 2 - 3)] + +lemma denominator_pos {m : Vec} (hm : PositiveMessage m) (t : ℝ) + (ht : t ∈ Set.Icc (0 : ℝ) 1) : + 0 < 1 - 3 * t ^ 2 * momentX (centered m) + 2 * t ^ 3 * momentY (centered m) := by + rw [← product_eq (avg_centered hm)] + have hi (i : Fin 3) : 0 < 1 + t * centered m i := by + dsimp [centered] + by_cases h : t = 0 + · subst t; norm_num + · have ht0 : 0 < t := lt_of_le_of_ne ht.1 (Ne.symm h) + have := mul_pos ht0 (hm.1 i) + nlinarith [ht.2] + exact mul_pos (mul_pos (hi 0) (hi 1)) (hi 2) + +def hpoly (v : Vec) : Vec := fun i ↦ 1 - v i + v i ^ 2 - 3 * momentX v + +def Hpoly (j : ℕ) (v : Vec) : ℝ := avg (fun i ↦ hpoly v i ^ j) + +lemma Hpoly_one {v : Vec} (hv : avg v = 0) : Hpoly 1 v = 1 - momentX v := by + simp only [Hpoly, hpoly, momentX, avg, pow_one]; rw [third_eq hv]; ring + +lemma Hpoly_two {v : Vec} (hv : avg v = 0) : + Hpoly 2 v = 3 * momentX v ^ 2 - 4 * momentY v + 1 := by + simp only [Hpoly, hpoly, momentX, momentY, avg]; rw [third_eq hv]; ring + +lemma Hpoly_three {v : Vec} (hv : avg v = 0) : + Hpoly 3 v = -9 * momentX v ^ 3 + 9 * momentX v ^ 2 + + 6 * momentX v * momentY v + 3 * momentX v + 4 * momentY v ^ 2 - 14 * momentY v + 1 := by + simp only [Hpoly, hpoly, momentX, momentY, avg]; rw [third_eq hv]; ring + +def polyA (x y : ℝ) : ℝ := + 3*x^4 + 12*x^3 + x^2 + (-6*x^3 - 28*x^2 - 2*x)*y + (26*x - 2)*y^2 - 4*y^3 + +def polyC (x y : ℝ) : ℝ := + 6*x^4 - 2*x^3 + (-13*x^3 - 10*x^2 - x)*y + (10*x^2 + 22*x + 4)*y^2 - 16*y^3 + +def polyN (x y t : ℝ) : ℝ := (24/5) * (polyA x y + t * polyC x y) + +def polyL (x y : ℝ) : ℝ := + 1500*x^5 - 1020*x^4 + 240*x^3 + 168*y^4 + + (-480*x^2 - 756*x - 52)*y^3 + + (2114*x^3 + 710*x^2 + 48*x - 80)*y^2 + + (-3093*x^4 + 736*x^3 - 35*x^2)*y + +lemma polyN_one (x y : ℝ) : + polyN x y 1 = (24/5) * (x-y) * (9*x-10*y+1) * (x^2+x-2*y) := by + simp only [polyN, polyA, polyC]; ring + +lemma polyN_affine (x y t : ℝ) : + polyN x y t = (1-t)*polyN x y 0 + t*polyN x y 1 := by + simp only [polyN]; ring + +end ThreeState.TreeClauses.Radial + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RadialBounds.lean b/lean/OAI/Probability/ThreeStateClauses/RadialBounds.lean index 61febc731cf771e987e211d4ce7c5e3e1a4b59b8..d28b74f63401ce748d8da207cfe2f9a1b739040a 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RadialBounds.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RadialBounds.lean @@ -1,466 +1,466 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RadialAlgebra - -namespace OAI - -/-! Radial Bounds. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -namespace ThreeState.TreeClauses.Radial - -def f₀ (r : ℝ) : ℝ := 480*r^4 - 842*r^3 - 117*r^2 + 445*r + 160 - -def f₁ (r : ℝ) : ℝ := - 336*r^6 - 1008*r^5 + 1096*r^4 - 896*r^3 + 63*r^2 + 685*r + 240 - -def f₂ (r : ℝ) : ℝ := 440*r^4 - 1104*r^3 + 368*r^2 + 413*r + 210 - -lemma f₀_certificate (p : ℝ) (hp : 0 ≤ p) : - 4*(1+p)^4 * f₀ ((p-1/2)/(1+p)) = - 504*p^4 + 4386*p^3 + 12267*p^2 - 1161*p + 174 := by - have h : 1+p ≠ 0 := by positivity - dsimp [f₀]; field_simp; ring - -lemma f₁_certificate (p : ℝ) (hp : 0 ≤ p) : - 4*(1+p)^6 * f₁ ((p-1/2)/(1+p)) = - 2064*p^6 + 15486*p^5 + 36669*p^4 + 31368*p^3 + - 20184*p^2 - 2724*p + 522 := by - have h : 1+p ≠ 0 := by positivity - dsimp [f₁]; field_simp; ring - -lemma f₂_certificate (p : ℝ) (hp : 0 ≤ p) : - 4*(1+p)^4 * f₂ ((p-1/2)/(1+p)) = - 1308*p^4 + 7650*p^3 + 12366*p^2 - 1842*p + 1044 := by - have h : 1+p ≠ 0 := by positivity - dsimp [f₂]; field_simp; ring - -lemma f_positive (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : - 0 < f₀ r ∧ 0 < f₁ r ∧ 0 < f₂ r := by - rcases hr₁.eq_or_lt with hr | hr - · subst r; norm_num [f₀, f₁, f₂] - let p := (r+1/2)/(1-r) - have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) - have hp1 : 0 < 1+p := by positivity - have hrp : r = (p-1/2)/(1+p) := by - have heq : p*(1-r) = r+1/2 := div_mul_cancel₀ _ (by linarith : 1-r ≠ 0) - apply (eq_div_iff (ne_of_gt hp1)).2 - nlinarith [heq] - have h₀ : 0 < 12267*p^2 - 1161*p + 174 := by - nlinarith [sq_nonneg (p - (1161 / (2*12267) : ℝ))] - have h₁ : 0 < 20184*p^2 - 2724*p + 522 := by - nlinarith [sq_nonneg (p - (2724 / (2*20184) : ℝ))] - have h₂ : 0 < 12366*p^2 - 1842*p + 1044 := by - nlinarith [sq_nonneg (p - (1842 / (2*12366) : ℝ))] - rw [hrp] - constructor - · have ht : 0 ≤ 504*p^4 + 4386*p^3 := by positivity - have hc := f₀_certificate p hp - exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^4)).1 (by linarith) - constructor - · have ht : 0 ≤ 2064*p^6 + 15486*p^5 + 36669*p^4 + 31368*p^3 := by positivity - have hc := f₁_certificate p hp - exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^6)).1 (by linarith) - · have ht : 0 ≤ 1308*p^4 + 7650*p^3 := by positivity - have hc := f₂_certificate p hp - exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^4)).1 (by linarith) - -def a₀ (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*(10*r^2+r+1) - -def a₁ (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*(9+5*r+20*r^2-4*r^3) - -def a₂ (r : ℝ) : ℝ := 48*(1-r)^3 - -def b₀ (r : ℝ) : ℝ := r^2*(1-r)^3*(3-2*r)^3*f₀ r - -def b₁ (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*f₁ r - -def b₂ (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*f₂ r - -def b₃ (r : ℝ) : ℝ := 24*(1-r)^3*(25-4*r^2-10*r) - -lemma a_nonneg (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : - 0 ≤ a₀ r ∧ 0 ≤ a₁ r ∧ 0 ≤ a₂ r := by - have h1 : 0 ≤ 1-r := by linarith - have h3 : 0 ≤ 3-2*r := by linarith - have hq : 0 ≤ 10*r^2+r+1 := by nlinarith [sq_nonneg (r+1/20)] - have hc : 0 ≤ 9+5*r+20*r^2-4*r^3 := by - have h : 0 ≤ r^2*(20-4*r) := mul_nonneg (sq_nonneg r) (by linarith) - nlinarith - dsimp [a₀, a₁, a₂] - exact ⟨by positivity, by positivity, by positivity⟩ - -lemma b_nonneg (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : - 0 ≤ b₀ r ∧ 0 ≤ b₁ r ∧ 0 ≤ b₂ r ∧ 0 ≤ b₃ r := by - have h1 : 0 ≤ 1-r := by linarith - have h3 : 0 ≤ 3-2*r := by linarith - obtain ⟨hf₀, hf₁, hf₂⟩ := f_positive r hr₀ hr₁ - have hq : 0 ≤ 25-4*r^2-10*r := by - have h : 0 ≤ (1-r)*(r+1/2) := mul_nonneg h1 (by linarith) - nlinarith - dsimp [b₀, b₁, b₂, b₃] - exact ⟨by positivity, by positivity, by positivity, by positivity⟩ - -def normalizedA (x r : ℝ) : ℝ := - (3-6*r)*x^2 + (12-28*r+26*r^2-4*r^3)*x + 1-2*r-2*r^2 - -def normalizedL (x r : ℝ) : ℝ := - (1500-3093*r+2114*r^2-480*r^3)*x^3 + - (168*r^4-756*r^3+710*r^2+736*r-1020)*x^2 + - (240-35*r+48*r^2-52*r^3)*x - 80*r^2 - -lemma normalizeA (x r : ℝ) : polyA x (r*x) = x^2*normalizedA x r := by - dsimp [polyA, normalizedA]; ring - -lemma normalizeL (x r : ℝ) : polyL x (r*x) = x^2*normalizedL x r := by - dsimp [polyL, normalizedL]; ring - -def paramX (r z : ℝ) : ℝ := (r^2+z/(3-2*r))/(1+z) - -lemma a_certificate (r z : ℝ) (hr : r ≤ 1) (hz : 0 ≤ z) : - (1+z)^2*(3-2*r)^2*normalizedA (paramX r z) r = - a₀ r + a₁ r*z + a₂ r*z^2 := by - have h1 : 1+z ≠ 0 := by positivity - have h3 : 3-2*r ≠ 0 := by linarith - dsimp [paramX, normalizedA, a₀, a₁, a₂] - field_simp - ring - -lemma b_certificate (r z : ℝ) (hr : r ≤ 1) (hz : 0 ≤ z) : - (1+z)^3*(3-2*r)^3*normalizedL (paramX r z) r = - b₀ r + b₁ r*z + b₂ r*z^2 + b₃ r*z^3 := by - have h1 : 1+z ≠ 0 := by positivity - have h3 : 3-2*r ≠ 0 := by linarith - dsimp [paramX, normalizedL, b₀, b₁, b₂, b₃, f₀, f₁, f₂] - field_simp - ring - -lemma param_polynomial_nonneg (r z : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) - (hr₁ : r ≤ 1) (hz : 0 ≤ z) : - 0 ≤ polyA (paramX r z) (r*paramX r z) ∧ - 0 ≤ polyL (paramX r z) (r*paramX r z) := by - have h1 : 0 < 1+z := by positivity - have h3 : 0 < 3-2*r := by linarith - obtain ⟨ha₀, ha₁, ha₂⟩ := a_nonneg r hr₀ hr₁ - obtain ⟨hb₀, hb₁, hb₂, hb₃⟩ := b_nonneg r hr₀ hr₁ - constructor - · rw [normalizeA] - apply mul_nonneg (sq_nonneg _) - apply (nonneg_of_mul_nonneg_left _ (by positivity : 0 < (1+z)^2*(3-2*r)^2)) - rw [mul_comm, a_certificate r z hr₁ hz] - positivity - · rw [normalizeL] - apply mul_nonneg (sq_nonneg _) - apply (nonneg_of_mul_nonneg_left _ (by positivity : 0 < (1+z)^3*(3-2*r)^3)) - rw [mul_comm, b_certificate r z hr₁ hz] - positivity - -lemma domain_parametrization {x y : ℝ} (hx₀ : 0 < x) (hx₁ : x < 1) - (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : - ∃ r z : ℝ, -(1/2:ℝ) ≤ r ∧ r < 1 ∧ 0 ≤ z ∧ - x = paramX r z ∧ y = r*x := by - let r := y/x - have hyr : y = r*x := by dsimp [r]; field_simp - have hrx : r^2 ≤ x := by - dsimp [r]; rw [div_pow] - apply (div_le_iff₀ (pow_pos hx₀ 2)).2 - nlinarith - have hr₁ : r < 1 := by nlinarith [sq_nonneg (r-1)] - have h3 : 0 < 3-2*r := by linarith - have hD' : 0 < 1-(3-2*r)*x := by rw [hyr] at hD; nlinarith - have hfactor : 0 < (1-r)^2*(2*r+1) := by - nlinarith [mul_nonneg h3.le (sub_nonneg.mpr hrx)] - have hr₀ : -(1/2:ℝ) ≤ r := by - have hsq : 0 < (1-r)^2 := sq_pos_of_pos (by linarith) - have := (mul_pos_iff_of_pos_left hsq).1 hfactor - linarith - have hden : 0 < 1/(3-2*r)-x := by - apply sub_pos.mpr - apply (lt_div_iff₀ h3).2 - nlinarith - let z := (x-r^2)/(1/(3-2*r)-x) - have hz : 0 ≤ z := div_nonneg (sub_nonneg.mpr hrx) hden.le - have hz1 : 0 < 1+z := by positivity - have hzEq : z*(1/(3-2*r)-x) = x-r^2 := div_mul_cancel₀ _ (ne_of_gt hden) - refine ⟨r, z, hr₀, hr₁, hz, ?_, hyr⟩ - dsimp only [paramX] - apply (eq_div_iff (ne_of_gt hz1)).2 - simp only [div_eq_mul_inv, one_mul] at hzEq ⊢ - nlinarith - -lemma polyN_one_nonneg {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x ≤ 1) - (hxy : y^2 ≤ x^3) : 0 ≤ polyN x y 1 := by - have hx3 : x^3 ≤ x^2 := by - nlinarith [mul_nonneg (sq_nonneg x) (sub_nonneg.mpr hx₁)] - have hyx : y ≤ x := by nlinarith [sq_nonneg (y-x)] - have hlast : 0 ≤ x^2+x-2*y := by - by_contra h - have hminus : 0 < 2*y-(x^2+x) := by linarith - have hplus : 0 < 2*y+(x^2+x) := by nlinarith - have hp := mul_pos hminus hplus - have hsq : 0 ≤ x^2*(x-1)^2 := by positivity - nlinarith - rw [polyN_one] - have hfirst : 0 ≤ x-y := by linarith - have hsecond : 0 ≤ 9*x-10*y+1 := by linarith - positivity - -lemma polynomial_goal {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x < 1) - (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : - 0 ≤ polyN x y 0 ∧ 0 ≤ polyN x y 1 ∧ 0 ≤ polyL x y := by - rcases eq_or_lt_of_le hx₀ with hx | hx - · have hy : y = 0 := by rw [← hx] at hxy; nlinarith [sq_nonneg y] - rw [← hx, hy]; norm_num [polyN, polyA, polyC, polyL] - · obtain ⟨r,z,hr₀,hr₁,hz,hxp,hyr⟩ := domain_parametrization hx hx₁ hxy hD - have hs := param_polynomial_nonneg r z hr₀ hr₁.le hz - rw [← hxp, ← hyr] at hs - refine ⟨?_, polyN_one_nonneg hx₀ hx₁.le hxy, hs.2⟩ - dsimp only [polyN] - nlinarith [hs.1] - -lemma polyN_nonneg {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x < 1) - (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) - {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : 0 ≤ polyN x y t := by - obtain ⟨h0,h1,_⟩ := polynomial_goal hx₀ hx₁ hxy hD - rw [polyN_affine] - exact add_nonneg (mul_nonneg (sub_nonneg.mpr ht.2) h0) (mul_nonneg ht.1 h1) - -end ThreeState.TreeClauses.Radial - -end - -noncomputable section -open MeasureTheory Set -open scoped Interval -namespace ThreeState.TreeClauses.Radial - -def denom (v : Vec) (t : ℝ) : ℝ := 1 - 3*t^2*momentX v + 2*t^3*momentY v - -def kpoly (v : Vec) (t : ℝ) : Vec := fun i ↦ v i - t * (v i^2 - 2*momentX v) - -def invMoment (m : Vec) (j : ℕ) : ℝ := avg (fun i ↦ (m i)⁻¹ ^ j) - -def logInvMoment (m : Vec) (j : ℕ) : ℝ := - avg (fun i ↦ logCentered m i * (m i)⁻¹ ^ j) - -def logMoment (m : Vec) : ℝ := avg (fun i ↦ m i * logCentered m i) - -def radialG (m : Vec) : ℝ := - 6 - 12 * invMoment m 1 + 8 * invMoment m 2 - 2 * invMoment m 3 + - (4/5) * (logInvMoment m 2 - 3*logInvMoment m 1 + - (2*invMoment m 3 - 3*invMoment m 2)*logMoment m + - 3*(invMoment m 1-1)*(invMoment m 2-invMoment m 1)) - -lemma edge_pos {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) - (i : Fin 3) : 0 < 1+t*centered m i := by - by_cases h : t = 0 - · subst t; norm_num - · have ht0 : 0 < t := lt_of_le_of_ne ht.1 (Ne.symm h) - have := mul_pos ht0 (hm.1 i) - dsimp only [centered]; nlinarith [ht.2] - -lemma denom_pos {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : - 0 < denom (centered m) t := denominator_pos hm t ht - -lemma rational_identity {v : Vec} (hv : avg v = 0) (t : ℝ) (i : Fin 3) - (hi : 1+t*v i ≠ 0) (hD : denom v t ≠ 0) : - v i / (1+t*v i) = (v i - t*v i^2 + 2*t^2*momentY v) / denom v t := by - apply (div_eq_div_iff hi hD).2 - dsimp only [denom] - linear_combination t^2 * cubic hv i - -lemma rational_centered {v : Vec} (hv : avg v = 0) (t : ℝ) - (hi : ∀ i, 1+t*v i ≠ 0) (hD : denom v t ≠ 0) (i : Fin 3) : - v i / (1+t*v i) - avg (fun j ↦ v j / (1+t*v j)) = kpoly v t i / denom v t := by - simp_rw [rational_identity hv t _ (hi _) hD] - dsimp only [avg, kpoly, momentX, momentY] - have hs := third_eq hv - field_simp - rw [hs] - ring - -lemma hasDerivAt_log_edge {v : Vec} {t : ℝ} (i : Fin 3) (hi : 1+t*v i ≠ 0) : - HasDerivAt (fun s : ℝ ↦ Real.log (1+s*v i)) (v i/(1+t*v i)) t := by - convert ((hasDerivAt_const t (1:ℝ)).add ((hasDerivAt_id t).mul_const (v i))).log hi using 1 <;> simp - -lemma integral_log_edge {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : - (∫ t in (0:ℝ)..1, centered m i / (1+t*centered m i)) = Real.log (m i) := by - have hc : ContinuousOn (fun t : ℝ ↦ centered m i / (1+t*centered m i)) (Icc 0 1) := by - apply continuousOn_const.div (by fun_prop) - intro t ht; exact ne_of_gt (edge_pos hm ht i) - have hint : IntervalIntegrable (fun t : ℝ ↦ centered m i / (1+t*centered m i)) volume 0 1 := by - apply ContinuousOn.intervalIntegrable - simpa only [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] using hc - have h := intervalIntegral.integral_eq_sub_of_hasDerivAt - (fun t (ht : t ∈ uIcc (0:ℝ) 1) ↦ - hasDerivAt_log_edge i (ne_of_gt (edge_pos hm (by simpa using ht) i))) hint - simpa [centered] using h - -lemma integral_avg {f : ℝ → Vec} - (hf : ∀ i, IntervalIntegrable (fun t ↦ f t i) volume (0:ℝ) 1) : - (∫ t in (0:ℝ)..1, avg (f t)) = avg (fun i ↦ ∫ t in (0:ℝ)..1, f t i) := by - simp only [avg, intervalIntegral.integral_div, - intervalIntegral.integral_add (hf 0) (hf 1), - intervalIntegral.integral_add ((hf 0).add (hf 1)) (hf 2)] - -lemma integral_k {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : - (∫ t in (0:ℝ)..1, kpoly (centered m) t i / denom (centered m) t) = logCentered m i := by - have hint (j : Fin 3) : IntervalIntegrable - (fun t : ℝ ↦ centered m j/(1+t*centered m j)) volume 0 1 := by - apply ContinuousOn.intervalIntegrable - rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] - exact continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht j)) - have havg : IntervalIntegrable - (fun t : ℝ ↦ avg (fun j ↦ centered m j/(1+t*centered m j))) volume 0 1 := by - exact (((hint 0).add (hint 1)).add (hint 2)).div_const 3 - calc - _ = ∫ t in (0:ℝ)..1, centered m i/(1+t*centered m i) - - avg (fun j ↦ centered m j/(1+t*centered m j)) := by - apply intervalIntegral.integral_congr - intro t ht - symm - exact rational_centered (avg_centered hm) t - (fun j ↦ ne_of_gt (edge_pos hm (by simpa using ht) j)) - (ne_of_gt (denom_pos hm (by simpa using ht))) i - _ = _ := by - rw [intervalIntegral.integral_sub (hint i) havg, integral_log_edge hm, - integral_avg hint] - simp only [integral_log_edge hm, logCentered, logAverage] - -lemma avg_div (v : Vec) (a : ℝ) : avg (fun i ↦ v i / a) = avg v / a := by - simp only [avg]; ring - -lemma avg_logCentered (m : Vec) : avg (logCentered m) = 0 := by - simp only [logCentered, logAverage, avg]; ring - -lemma h_inverse {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : - (m i)⁻¹ = hpoly (centered m) i / denom (centered m) 1 := by - have hc := cubic (avg_centered hm) i - have hD := ne_of_gt (denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1)) - apply (eq_div_iff hD).2 - apply (mul_left_cancel₀ (ne_of_gt (hm.1 i))) - rw [← mul_assoc, mul_inv_cancel₀ (ne_of_gt (hm.1 i)), one_mul] - dsimp only [denom, hpoly, centered] at * - norm_num only [one_pow, mul_one, one_mul] - linear_combination -hc - -def polynomialR (v : Vec) : ℝ := - (6-12*momentX v^2)*denom v 1^3 - 12*Hpoly 1 v*denom v 1^2 + - 8*Hpoly 2 v*denom v 1 - 2*Hpoly 3 v + - (12/5)*(Hpoly 1 v-denom v 1)*(Hpoly 2 v-Hpoly 1 v*denom v 1) - -def logWeight (v : Vec) : Vec := fun i ↦ - hpoly v i^2*denom v 1 - 3*hpoly v i*denom v 1^2 + - (2*Hpoly 3 v-3*Hpoly 2 v*denom v 1)*v i - -lemma polynomialN_representation {v : Vec} (hv : avg v = 0) (t : ℝ) : - (4/5)*avg (fun i ↦ kpoly v t i * logWeight v i) = - polyN (momentX v) (momentY v) t := by - simp only [logWeight, Hpoly, kpoly, hpoly, denom, polyN, polyA, polyC, - momentX, momentY, avg] - rw [third_eq hv] - ring - -lemma G_algebra {m : Vec} (hm : PositiveMessage m) : - denom (centered m) 1^3 * (radialG m-12*momentX (centered m)^2) = - polynomialR (centered m) + (4/5)*avg (fun i ↦ logCentered m i * logWeight (centered m) i) := by - have hD := ne_of_gt (denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1)) - simp only [radialG, invMoment, logInvMoment, logMoment] - simp_rw [h_inverse hm] - simp only [polynomialR, logWeight, Hpoly, avg, logCentered, logAverage, centered] - field_simp - ring - -lemma integrable_k {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : - IntervalIntegrable (fun t ↦ kpoly (centered m) t i / denom (centered m) t) volume (0:ℝ) 1 := by - apply ContinuousOn.intervalIntegrable - rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] - apply ContinuousOn.div (by unfold kpoly; fun_prop) (by unfold denom; fun_prop) - intro t ht; exact ne_of_gt (denom_pos hm ht) - -lemma integral_N {m : Vec} (hm : PositiveMessage m) : - (∫ t in (0:ℝ)..1, polyN (momentX (centered m)) (momentY (centered m)) t / - denom (centered m) t) = - (4/5)*avg (fun i ↦ logCentered m i * logWeight (centered m) i) := by - have heq (t : ℝ) : polyN (momentX (centered m)) (momentY (centered m)) t / - denom (centered m) t = (4/5)*avg (fun i ↦ - (kpoly (centered m) t i / denom (centered m) t) * logWeight (centered m) i) := by - rw [← polynomialN_representation (avg_centered hm)] - simp only [avg]; ring - simp_rw [heq] - rw [intervalIntegral.integral_const_mul, - integral_avg (fun i ↦ (integrable_k hm i).mul_const _)] - simp only [intervalIntegral.integral_mul_const, integral_k hm] - -lemma RN_representation {m : Vec} (hm : PositiveMessage m) : - denom (centered m) 1^3 * (radialG m-12*momentX (centered m)^2) = - polynomialR (centered m) + - (∫ t in (0:ℝ)..1, polyN (momentX (centered m)) (momentY (centered m)) t / - denom (centered m) t) := by rw [integral_N hm, G_algebra hm] - -lemma polynomial_integral (x y : ℝ) : - (∫ t in (0:ℝ)..1, polyN x y t * (2-(1-3*t^2*x+2*t^3*y))) = - (24/5)*(polyA x y*(1+x-y/2)+polyC x y*(1/2+3*x/4-2*y/5)) := by - simp only [polyN] - conv_lhs => arg 1; ext t; ring_nf - simp (disch := apply Continuous.intervalIntegrable; fun_prop) only - [intervalIntegral.integral_add, - intervalIntegral.integral_mul_const, intervalIntegral.integral_const_mul, - integral_pow, intervalIntegral.integral_const] - norm_num - ring - -lemma L_representation {v : Vec} (hv : avg v = 0) : - polynomialR v + (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t * (2-denom v t)) = - (6/25)*polyL (momentX v) (momentY v) := by - simp only [denom] - rw [polynomial_integral] - simp only [polynomialR, denom, Hpoly_one hv, Hpoly_two hv, Hpoly_three hv, - polyL, polyA, polyC] - ring - -theorem radialG_bound {m : Vec} (hm : PositiveMessage m) : - 12*momentX (centered m)^2 ≤ radialG m := by - let v := centered m - have hx₀ := momentX_nonneg v - have hx₁ := momentX_lt_one hm - have hxy := moment_discriminant (avg_centered hm) - have hD : 0 < 1-3*momentX v+2*momentY v := by - simpa [v, denom] using denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1) - have hN (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ polyN (momentX v) (momentY v) t := - polyN_nonneg hx₀ hx₁ hxy hD ht - have hL := (polynomial_goal hx₀ hx₁ hxy hD).2.2 - have hcN : Continuous (fun t : ℝ ↦ polyN (momentX v) (momentY v) t) := by - unfold polyN; fun_prop - have hcl : Continuous (fun t : ℝ ↦ polyN (momentX v) (momentY v) t * (2-denom v t)) := by - unfold denom; fun_prop - have hcr : ContinuousOn (fun t : ℝ ↦ polyN (momentX v) (momentY v) t / denom v t) - (Icc 0 1) := by - exact hcN.continuousOn.div (by unfold denom; fun_prop) - (fun t ht ↦ ne_of_gt (denom_pos hm ht)) - have hir : IntervalIntegrable (fun t : ℝ ↦ polyN (momentX v) (momentY v) t / denom v t) volume 0 1 := - hcr.intervalIntegrable_of_Icc (by norm_num : (0:ℝ) ≤ 1) - have hi : (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t * (2-denom v t)) ≤ - (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t / denom v t) := by - apply intervalIntegral.integral_mono_on (by norm_num) (hcl.intervalIntegrable _ _) hir - intro t ht - have hd := denom_pos hm ht - have hh : 2-denom v t ≤ 1/denom v t := by - apply (le_div_iff₀ hd).2 - nlinarith [sq_nonneg (1-denom v t)] - simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hh (hN t ht) - have hp : 0 ≤ denom v 1^3 * (radialG m-12*momentX v^2) := by - rw [RN_representation hm] - have he := L_representation (avg_centered hm) - dsimp only [v] at hi hL ⊢ - linarith - have hd : 0 < denom v 1^3 := pow_pos (denom_pos hm (by norm_num)) 3 - have := (mul_nonneg_iff_of_pos_left hd).1 hp - linarith - -end ThreeState.TreeClauses.Radial - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RadialAlgebra + +namespace OAI + +/-! Radial Bounds. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +namespace ThreeState.TreeClauses.Radial + +def f₀ (r : ℝ) : ℝ := 480*r^4 - 842*r^3 - 117*r^2 + 445*r + 160 + +def f₁ (r : ℝ) : ℝ := + 336*r^6 - 1008*r^5 + 1096*r^4 - 896*r^3 + 63*r^2 + 685*r + 240 + +def f₂ (r : ℝ) : ℝ := 440*r^4 - 1104*r^3 + 368*r^2 + 413*r + 210 + +lemma f₀_certificate (p : ℝ) (hp : 0 ≤ p) : + 4*(1+p)^4 * f₀ ((p-1/2)/(1+p)) = + 504*p^4 + 4386*p^3 + 12267*p^2 - 1161*p + 174 := by + have h : 1+p ≠ 0 := by positivity + dsimp [f₀]; field_simp; ring + +lemma f₁_certificate (p : ℝ) (hp : 0 ≤ p) : + 4*(1+p)^6 * f₁ ((p-1/2)/(1+p)) = + 2064*p^6 + 15486*p^5 + 36669*p^4 + 31368*p^3 + + 20184*p^2 - 2724*p + 522 := by + have h : 1+p ≠ 0 := by positivity + dsimp [f₁]; field_simp; ring + +lemma f₂_certificate (p : ℝ) (hp : 0 ≤ p) : + 4*(1+p)^4 * f₂ ((p-1/2)/(1+p)) = + 1308*p^4 + 7650*p^3 + 12366*p^2 - 1842*p + 1044 := by + have h : 1+p ≠ 0 := by positivity + dsimp [f₂]; field_simp; ring + +lemma f_positive (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : + 0 < f₀ r ∧ 0 < f₁ r ∧ 0 < f₂ r := by + rcases hr₁.eq_or_lt with hr | hr + · subst r; norm_num [f₀, f₁, f₂] + let p := (r+1/2)/(1-r) + have hp : 0 ≤ p := div_nonneg (by linarith) (by linarith) + have hp1 : 0 < 1+p := by positivity + have hrp : r = (p-1/2)/(1+p) := by + have heq : p*(1-r) = r+1/2 := div_mul_cancel₀ _ (by linarith : 1-r ≠ 0) + apply (eq_div_iff (ne_of_gt hp1)).2 + nlinarith [heq] + have h₀ : 0 < 12267*p^2 - 1161*p + 174 := by + nlinarith [sq_nonneg (p - (1161 / (2*12267) : ℝ))] + have h₁ : 0 < 20184*p^2 - 2724*p + 522 := by + nlinarith [sq_nonneg (p - (2724 / (2*20184) : ℝ))] + have h₂ : 0 < 12366*p^2 - 1842*p + 1044 := by + nlinarith [sq_nonneg (p - (1842 / (2*12366) : ℝ))] + rw [hrp] + constructor + · have ht : 0 ≤ 504*p^4 + 4386*p^3 := by positivity + have hc := f₀_certificate p hp + exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^4)).1 (by linarith) + constructor + · have ht : 0 ≤ 2064*p^6 + 15486*p^5 + 36669*p^4 + 31368*p^3 := by positivity + have hc := f₁_certificate p hp + exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^6)).1 (by linarith) + · have ht : 0 ≤ 1308*p^4 + 7650*p^3 := by positivity + have hc := f₂_certificate p hp + exact (mul_pos_iff_of_pos_left (by positivity : 0 < 4*(1+p)^4)).1 (by linarith) + +def a₀ (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*(10*r^2+r+1) + +def a₁ (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*(9+5*r+20*r^2-4*r^3) + +def a₂ (r : ℝ) : ℝ := 48*(1-r)^3 + +def b₀ (r : ℝ) : ℝ := r^2*(1-r)^3*(3-2*r)^3*f₀ r + +def b₁ (r : ℝ) : ℝ := (1-r)^3*(3-2*r)^2*f₁ r + +def b₂ (r : ℝ) : ℝ := 2*(1-r)^3*(3-2*r)*f₂ r + +def b₃ (r : ℝ) : ℝ := 24*(1-r)^3*(25-4*r^2-10*r) + +lemma a_nonneg (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : + 0 ≤ a₀ r ∧ 0 ≤ a₁ r ∧ 0 ≤ a₂ r := by + have h1 : 0 ≤ 1-r := by linarith + have h3 : 0 ≤ 3-2*r := by linarith + have hq : 0 ≤ 10*r^2+r+1 := by nlinarith [sq_nonneg (r+1/20)] + have hc : 0 ≤ 9+5*r+20*r^2-4*r^3 := by + have h : 0 ≤ r^2*(20-4*r) := mul_nonneg (sq_nonneg r) (by linarith) + nlinarith + dsimp [a₀, a₁, a₂] + exact ⟨by positivity, by positivity, by positivity⟩ + +lemma b_nonneg (r : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) (hr₁ : r ≤ 1) : + 0 ≤ b₀ r ∧ 0 ≤ b₁ r ∧ 0 ≤ b₂ r ∧ 0 ≤ b₃ r := by + have h1 : 0 ≤ 1-r := by linarith + have h3 : 0 ≤ 3-2*r := by linarith + obtain ⟨hf₀, hf₁, hf₂⟩ := f_positive r hr₀ hr₁ + have hq : 0 ≤ 25-4*r^2-10*r := by + have h : 0 ≤ (1-r)*(r+1/2) := mul_nonneg h1 (by linarith) + nlinarith + dsimp [b₀, b₁, b₂, b₃] + exact ⟨by positivity, by positivity, by positivity, by positivity⟩ + +def normalizedA (x r : ℝ) : ℝ := + (3-6*r)*x^2 + (12-28*r+26*r^2-4*r^3)*x + 1-2*r-2*r^2 + +def normalizedL (x r : ℝ) : ℝ := + (1500-3093*r+2114*r^2-480*r^3)*x^3 + + (168*r^4-756*r^3+710*r^2+736*r-1020)*x^2 + + (240-35*r+48*r^2-52*r^3)*x - 80*r^2 + +lemma normalizeA (x r : ℝ) : polyA x (r*x) = x^2*normalizedA x r := by + dsimp [polyA, normalizedA]; ring + +lemma normalizeL (x r : ℝ) : polyL x (r*x) = x^2*normalizedL x r := by + dsimp [polyL, normalizedL]; ring + +def paramX (r z : ℝ) : ℝ := (r^2+z/(3-2*r))/(1+z) + +lemma a_certificate (r z : ℝ) (hr : r ≤ 1) (hz : 0 ≤ z) : + (1+z)^2*(3-2*r)^2*normalizedA (paramX r z) r = + a₀ r + a₁ r*z + a₂ r*z^2 := by + have h1 : 1+z ≠ 0 := by positivity + have h3 : 3-2*r ≠ 0 := by linarith + dsimp [paramX, normalizedA, a₀, a₁, a₂] + field_simp + ring + +lemma b_certificate (r z : ℝ) (hr : r ≤ 1) (hz : 0 ≤ z) : + (1+z)^3*(3-2*r)^3*normalizedL (paramX r z) r = + b₀ r + b₁ r*z + b₂ r*z^2 + b₃ r*z^3 := by + have h1 : 1+z ≠ 0 := by positivity + have h3 : 3-2*r ≠ 0 := by linarith + dsimp [paramX, normalizedL, b₀, b₁, b₂, b₃, f₀, f₁, f₂] + field_simp + ring + +lemma param_polynomial_nonneg (r z : ℝ) (hr₀ : -(1/2:ℝ) ≤ r) + (hr₁ : r ≤ 1) (hz : 0 ≤ z) : + 0 ≤ polyA (paramX r z) (r*paramX r z) ∧ + 0 ≤ polyL (paramX r z) (r*paramX r z) := by + have h1 : 0 < 1+z := by positivity + have h3 : 0 < 3-2*r := by linarith + obtain ⟨ha₀, ha₁, ha₂⟩ := a_nonneg r hr₀ hr₁ + obtain ⟨hb₀, hb₁, hb₂, hb₃⟩ := b_nonneg r hr₀ hr₁ + constructor + · rw [normalizeA] + apply mul_nonneg (sq_nonneg _) + apply (nonneg_of_mul_nonneg_left _ (by positivity : 0 < (1+z)^2*(3-2*r)^2)) + rw [mul_comm, a_certificate r z hr₁ hz] + positivity + · rw [normalizeL] + apply mul_nonneg (sq_nonneg _) + apply (nonneg_of_mul_nonneg_left _ (by positivity : 0 < (1+z)^3*(3-2*r)^3)) + rw [mul_comm, b_certificate r z hr₁ hz] + positivity + +lemma domain_parametrization {x y : ℝ} (hx₀ : 0 < x) (hx₁ : x < 1) + (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : + ∃ r z : ℝ, -(1/2:ℝ) ≤ r ∧ r < 1 ∧ 0 ≤ z ∧ + x = paramX r z ∧ y = r*x := by + let r := y/x + have hyr : y = r*x := by dsimp [r]; field_simp + have hrx : r^2 ≤ x := by + dsimp [r]; rw [div_pow] + apply (div_le_iff₀ (pow_pos hx₀ 2)).2 + nlinarith + have hr₁ : r < 1 := by nlinarith [sq_nonneg (r-1)] + have h3 : 0 < 3-2*r := by linarith + have hD' : 0 < 1-(3-2*r)*x := by rw [hyr] at hD; nlinarith + have hfactor : 0 < (1-r)^2*(2*r+1) := by + nlinarith [mul_nonneg h3.le (sub_nonneg.mpr hrx)] + have hr₀ : -(1/2:ℝ) ≤ r := by + have hsq : 0 < (1-r)^2 := sq_pos_of_pos (by linarith) + have := (mul_pos_iff_of_pos_left hsq).1 hfactor + linarith + have hden : 0 < 1/(3-2*r)-x := by + apply sub_pos.mpr + apply (lt_div_iff₀ h3).2 + nlinarith + let z := (x-r^2)/(1/(3-2*r)-x) + have hz : 0 ≤ z := div_nonneg (sub_nonneg.mpr hrx) hden.le + have hz1 : 0 < 1+z := by positivity + have hzEq : z*(1/(3-2*r)-x) = x-r^2 := div_mul_cancel₀ _ (ne_of_gt hden) + refine ⟨r, z, hr₀, hr₁, hz, ?_, hyr⟩ + dsimp only [paramX] + apply (eq_div_iff (ne_of_gt hz1)).2 + simp only [div_eq_mul_inv, one_mul] at hzEq ⊢ + nlinarith + +lemma polyN_one_nonneg {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x ≤ 1) + (hxy : y^2 ≤ x^3) : 0 ≤ polyN x y 1 := by + have hx3 : x^3 ≤ x^2 := by + nlinarith [mul_nonneg (sq_nonneg x) (sub_nonneg.mpr hx₁)] + have hyx : y ≤ x := by nlinarith [sq_nonneg (y-x)] + have hlast : 0 ≤ x^2+x-2*y := by + by_contra h + have hminus : 0 < 2*y-(x^2+x) := by linarith + have hplus : 0 < 2*y+(x^2+x) := by nlinarith + have hp := mul_pos hminus hplus + have hsq : 0 ≤ x^2*(x-1)^2 := by positivity + nlinarith + rw [polyN_one] + have hfirst : 0 ≤ x-y := by linarith + have hsecond : 0 ≤ 9*x-10*y+1 := by linarith + positivity + +lemma polynomial_goal {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x < 1) + (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) : + 0 ≤ polyN x y 0 ∧ 0 ≤ polyN x y 1 ∧ 0 ≤ polyL x y := by + rcases eq_or_lt_of_le hx₀ with hx | hx + · have hy : y = 0 := by rw [← hx] at hxy; nlinarith [sq_nonneg y] + rw [← hx, hy]; norm_num [polyN, polyA, polyC, polyL] + · obtain ⟨r,z,hr₀,hr₁,hz,hxp,hyr⟩ := domain_parametrization hx hx₁ hxy hD + have hs := param_polynomial_nonneg r z hr₀ hr₁.le hz + rw [← hxp, ← hyr] at hs + refine ⟨?_, polyN_one_nonneg hx₀ hx₁.le hxy, hs.2⟩ + dsimp only [polyN] + nlinarith [hs.1] + +lemma polyN_nonneg {x y : ℝ} (hx₀ : 0 ≤ x) (hx₁ : x < 1) + (hxy : y^2 ≤ x^3) (hD : 0 < 1-3*x+2*y) + {t : ℝ} (ht : t ∈ Set.Icc (0:ℝ) 1) : 0 ≤ polyN x y t := by + obtain ⟨h0,h1,_⟩ := polynomial_goal hx₀ hx₁ hxy hD + rw [polyN_affine] + exact add_nonneg (mul_nonneg (sub_nonneg.mpr ht.2) h0) (mul_nonneg ht.1 h1) + +end ThreeState.TreeClauses.Radial + +end + +noncomputable section +open MeasureTheory Set +open scoped Interval +namespace ThreeState.TreeClauses.Radial + +def denom (v : Vec) (t : ℝ) : ℝ := 1 - 3*t^2*momentX v + 2*t^3*momentY v + +def kpoly (v : Vec) (t : ℝ) : Vec := fun i ↦ v i - t * (v i^2 - 2*momentX v) + +def invMoment (m : Vec) (j : ℕ) : ℝ := avg (fun i ↦ (m i)⁻¹ ^ j) + +def logInvMoment (m : Vec) (j : ℕ) : ℝ := + avg (fun i ↦ logCentered m i * (m i)⁻¹ ^ j) + +def logMoment (m : Vec) : ℝ := avg (fun i ↦ m i * logCentered m i) + +def radialG (m : Vec) : ℝ := + 6 - 12 * invMoment m 1 + 8 * invMoment m 2 - 2 * invMoment m 3 + + (4/5) * (logInvMoment m 2 - 3*logInvMoment m 1 + + (2*invMoment m 3 - 3*invMoment m 2)*logMoment m + + 3*(invMoment m 1-1)*(invMoment m 2-invMoment m 1)) + +lemma edge_pos {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) + (i : Fin 3) : 0 < 1+t*centered m i := by + by_cases h : t = 0 + · subst t; norm_num + · have ht0 : 0 < t := lt_of_le_of_ne ht.1 (Ne.symm h) + have := mul_pos ht0 (hm.1 i) + dsimp only [centered]; nlinarith [ht.2] + +lemma denom_pos {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + 0 < denom (centered m) t := denominator_pos hm t ht + +lemma rational_identity {v : Vec} (hv : avg v = 0) (t : ℝ) (i : Fin 3) + (hi : 1+t*v i ≠ 0) (hD : denom v t ≠ 0) : + v i / (1+t*v i) = (v i - t*v i^2 + 2*t^2*momentY v) / denom v t := by + apply (div_eq_div_iff hi hD).2 + dsimp only [denom] + linear_combination t^2 * cubic hv i + +lemma rational_centered {v : Vec} (hv : avg v = 0) (t : ℝ) + (hi : ∀ i, 1+t*v i ≠ 0) (hD : denom v t ≠ 0) (i : Fin 3) : + v i / (1+t*v i) - avg (fun j ↦ v j / (1+t*v j)) = kpoly v t i / denom v t := by + simp_rw [rational_identity hv t _ (hi _) hD] + dsimp only [avg, kpoly, momentX, momentY] + have hs := third_eq hv + field_simp + rw [hs] + ring + +lemma hasDerivAt_log_edge {v : Vec} {t : ℝ} (i : Fin 3) (hi : 1+t*v i ≠ 0) : + HasDerivAt (fun s : ℝ ↦ Real.log (1+s*v i)) (v i/(1+t*v i)) t := by + convert ((hasDerivAt_const t (1:ℝ)).add ((hasDerivAt_id t).mul_const (v i))).log hi using 1 <;> simp + +lemma integral_log_edge {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : + (∫ t in (0:ℝ)..1, centered m i / (1+t*centered m i)) = Real.log (m i) := by + have hc : ContinuousOn (fun t : ℝ ↦ centered m i / (1+t*centered m i)) (Icc 0 1) := by + apply continuousOn_const.div (by fun_prop) + intro t ht; exact ne_of_gt (edge_pos hm ht i) + have hint : IntervalIntegrable (fun t : ℝ ↦ centered m i / (1+t*centered m i)) volume 0 1 := by + apply ContinuousOn.intervalIntegrable + simpa only [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] using hc + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t (ht : t ∈ uIcc (0:ℝ) 1) ↦ + hasDerivAt_log_edge i (ne_of_gt (edge_pos hm (by simpa using ht) i))) hint + simpa [centered] using h + +lemma integral_avg {f : ℝ → Vec} + (hf : ∀ i, IntervalIntegrable (fun t ↦ f t i) volume (0:ℝ) 1) : + (∫ t in (0:ℝ)..1, avg (f t)) = avg (fun i ↦ ∫ t in (0:ℝ)..1, f t i) := by + simp only [avg, intervalIntegral.integral_div, + intervalIntegral.integral_add (hf 0) (hf 1), + intervalIntegral.integral_add ((hf 0).add (hf 1)) (hf 2)] + +lemma integral_k {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : + (∫ t in (0:ℝ)..1, kpoly (centered m) t i / denom (centered m) t) = logCentered m i := by + have hint (j : Fin 3) : IntervalIntegrable + (fun t : ℝ ↦ centered m j/(1+t*centered m j)) volume 0 1 := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] + exact continuousOn_const.div (by fun_prop) (fun t ht ↦ ne_of_gt (edge_pos hm ht j)) + have havg : IntervalIntegrable + (fun t : ℝ ↦ avg (fun j ↦ centered m j/(1+t*centered m j))) volume 0 1 := by + exact (((hint 0).add (hint 1)).add (hint 2)).div_const 3 + calc + _ = ∫ t in (0:ℝ)..1, centered m i/(1+t*centered m i) - + avg (fun j ↦ centered m j/(1+t*centered m j)) := by + apply intervalIntegral.integral_congr + intro t ht + symm + exact rational_centered (avg_centered hm) t + (fun j ↦ ne_of_gt (edge_pos hm (by simpa using ht) j)) + (ne_of_gt (denom_pos hm (by simpa using ht))) i + _ = _ := by + rw [intervalIntegral.integral_sub (hint i) havg, integral_log_edge hm, + integral_avg hint] + simp only [integral_log_edge hm, logCentered, logAverage] + +lemma avg_div (v : Vec) (a : ℝ) : avg (fun i ↦ v i / a) = avg v / a := by + simp only [avg]; ring + +lemma avg_logCentered (m : Vec) : avg (logCentered m) = 0 := by + simp only [logCentered, logAverage, avg]; ring + +lemma h_inverse {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : + (m i)⁻¹ = hpoly (centered m) i / denom (centered m) 1 := by + have hc := cubic (avg_centered hm) i + have hD := ne_of_gt (denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1)) + apply (eq_div_iff hD).2 + apply (mul_left_cancel₀ (ne_of_gt (hm.1 i))) + rw [← mul_assoc, mul_inv_cancel₀ (ne_of_gt (hm.1 i)), one_mul] + dsimp only [denom, hpoly, centered] at * + norm_num only [one_pow, mul_one, one_mul] + linear_combination -hc + +def polynomialR (v : Vec) : ℝ := + (6-12*momentX v^2)*denom v 1^3 - 12*Hpoly 1 v*denom v 1^2 + + 8*Hpoly 2 v*denom v 1 - 2*Hpoly 3 v + + (12/5)*(Hpoly 1 v-denom v 1)*(Hpoly 2 v-Hpoly 1 v*denom v 1) + +def logWeight (v : Vec) : Vec := fun i ↦ + hpoly v i^2*denom v 1 - 3*hpoly v i*denom v 1^2 + + (2*Hpoly 3 v-3*Hpoly 2 v*denom v 1)*v i + +lemma polynomialN_representation {v : Vec} (hv : avg v = 0) (t : ℝ) : + (4/5)*avg (fun i ↦ kpoly v t i * logWeight v i) = + polyN (momentX v) (momentY v) t := by + simp only [logWeight, Hpoly, kpoly, hpoly, denom, polyN, polyA, polyC, + momentX, momentY, avg] + rw [third_eq hv] + ring + +lemma G_algebra {m : Vec} (hm : PositiveMessage m) : + denom (centered m) 1^3 * (radialG m-12*momentX (centered m)^2) = + polynomialR (centered m) + (4/5)*avg (fun i ↦ logCentered m i * logWeight (centered m) i) := by + have hD := ne_of_gt (denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1)) + simp only [radialG, invMoment, logInvMoment, logMoment] + simp_rw [h_inverse hm] + simp only [polynomialR, logWeight, Hpoly, avg, logCentered, logAverage, centered] + field_simp + ring + +lemma integrable_k {m : Vec} (hm : PositiveMessage m) (i : Fin 3) : + IntervalIntegrable (fun t ↦ kpoly (centered m) t i / denom (centered m) t) volume (0:ℝ) 1 := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] + apply ContinuousOn.div (by unfold kpoly; fun_prop) (by unfold denom; fun_prop) + intro t ht; exact ne_of_gt (denom_pos hm ht) + +lemma integral_N {m : Vec} (hm : PositiveMessage m) : + (∫ t in (0:ℝ)..1, polyN (momentX (centered m)) (momentY (centered m)) t / + denom (centered m) t) = + (4/5)*avg (fun i ↦ logCentered m i * logWeight (centered m) i) := by + have heq (t : ℝ) : polyN (momentX (centered m)) (momentY (centered m)) t / + denom (centered m) t = (4/5)*avg (fun i ↦ + (kpoly (centered m) t i / denom (centered m) t) * logWeight (centered m) i) := by + rw [← polynomialN_representation (avg_centered hm)] + simp only [avg]; ring + simp_rw [heq] + rw [intervalIntegral.integral_const_mul, + integral_avg (fun i ↦ (integrable_k hm i).mul_const _)] + simp only [intervalIntegral.integral_mul_const, integral_k hm] + +lemma RN_representation {m : Vec} (hm : PositiveMessage m) : + denom (centered m) 1^3 * (radialG m-12*momentX (centered m)^2) = + polynomialR (centered m) + + (∫ t in (0:ℝ)..1, polyN (momentX (centered m)) (momentY (centered m)) t / + denom (centered m) t) := by rw [integral_N hm, G_algebra hm] + +lemma polynomial_integral (x y : ℝ) : + (∫ t in (0:ℝ)..1, polyN x y t * (2-(1-3*t^2*x+2*t^3*y))) = + (24/5)*(polyA x y*(1+x-y/2)+polyC x y*(1/2+3*x/4-2*y/5)) := by + simp only [polyN] + conv_lhs => arg 1; ext t; ring_nf + simp (disch := apply Continuous.intervalIntegrable; fun_prop) only + [intervalIntegral.integral_add, + intervalIntegral.integral_mul_const, intervalIntegral.integral_const_mul, + integral_pow, intervalIntegral.integral_const] + norm_num + ring + +lemma L_representation {v : Vec} (hv : avg v = 0) : + polynomialR v + (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t * (2-denom v t)) = + (6/25)*polyL (momentX v) (momentY v) := by + simp only [denom] + rw [polynomial_integral] + simp only [polynomialR, denom, Hpoly_one hv, Hpoly_two hv, Hpoly_three hv, + polyL, polyA, polyC] + ring + +theorem radialG_bound {m : Vec} (hm : PositiveMessage m) : + 12*momentX (centered m)^2 ≤ radialG m := by + let v := centered m + have hx₀ := momentX_nonneg v + have hx₁ := momentX_lt_one hm + have hxy := moment_discriminant (avg_centered hm) + have hD : 0 < 1-3*momentX v+2*momentY v := by + simpa [v, denom] using denom_pos hm (by norm_num : (1:ℝ) ∈ Icc 0 1) + have hN (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ polyN (momentX v) (momentY v) t := + polyN_nonneg hx₀ hx₁ hxy hD ht + have hL := (polynomial_goal hx₀ hx₁ hxy hD).2.2 + have hcN : Continuous (fun t : ℝ ↦ polyN (momentX v) (momentY v) t) := by + unfold polyN; fun_prop + have hcl : Continuous (fun t : ℝ ↦ polyN (momentX v) (momentY v) t * (2-denom v t)) := by + unfold denom; fun_prop + have hcr : ContinuousOn (fun t : ℝ ↦ polyN (momentX v) (momentY v) t / denom v t) + (Icc 0 1) := by + exact hcN.continuousOn.div (by unfold denom; fun_prop) + (fun t ht ↦ ne_of_gt (denom_pos hm ht)) + have hir : IntervalIntegrable (fun t : ℝ ↦ polyN (momentX v) (momentY v) t / denom v t) volume 0 1 := + hcr.intervalIntegrable_of_Icc (by norm_num : (0:ℝ) ≤ 1) + have hi : (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t * (2-denom v t)) ≤ + (∫ t in (0:ℝ)..1, polyN (momentX v) (momentY v) t / denom v t) := by + apply intervalIntegral.integral_mono_on (by norm_num) (hcl.intervalIntegrable _ _) hir + intro t ht + have hd := denom_pos hm ht + have hh : 2-denom v t ≤ 1/denom v t := by + apply (le_div_iff₀ hd).2 + nlinarith [sq_nonneg (1-denom v t)] + simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hh (hN t ht) + have hp : 0 ≤ denom v 1^3 * (radialG m-12*momentX v^2) := by + rw [RN_representation hm] + have he := L_representation (avg_centered hm) + dsimp only [v] at hi hL ⊢ + linarith + have hd : 0 < denom v 1^3 := pow_pos (denom_pos hm (by norm_num)) 3 + have := (mul_nonneg_iff_of_pos_left hd).1 hp + linarith + +end ThreeState.TreeClauses.Radial + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RadialCalculus.lean b/lean/OAI/Probability/ThreeStateClauses/RadialCalculus.lean index 62485675debf17db854a8bdbb5b62b11a8f50cc3..e052ece837d0bf5f998ead7fa973add02a561724 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RadialCalculus.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RadialCalculus.lean @@ -1,378 +1,378 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RadialBounds - -namespace OAI - -/-! Radial Calculus. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set -namespace ThreeState.TreeClauses.Radial - -def rayG₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ Real.log (1+t*v i)) -def rayG₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i/(1+t*v i)) -def rayG₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -v i^2/(1+t*v i)^2) -def rayG₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ 2*v i^3/(1+t*v i)^3) - -def rayI₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (1+t*v i)*Real.log (1+t*v i)) -def rayI₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i*Real.log (1+t*v i)) -def rayI₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i^2/(1+t*v i)) -def rayI₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -v i^3/(1+t*v i)^2) - -def rayH₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (1+t*v i)*Real.log (1+t*v i)^2) -def rayH₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i*(Real.log (1+t*v i)^2+2*Real.log (1+t*v i))) -def rayH₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (2*v i^2/(1+t*v i))*(Real.log (1+t*v i)+1)) -def rayH₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -2*v i^3*Real.log (1+t*v i)/(1+t*v i)^2) - -lemma hasDerivAt_avg {f : ℝ → Vec} {df : Vec} {t : ℝ} - (hf : ∀ i, HasDerivAt (fun s ↦ f s i) (df i) t) : - HasDerivAt (fun s ↦ avg (f s)) (avg df) t := - (((hf 0).add (hf 1)).add (hf 2)).div_const 3 - -lemma hasDerivAt_ray_coord (v : Vec) (t : ℝ) (i : Fin 3) : - HasDerivAt (fun s : ℝ ↦ 1+s*v i) (v i) t := by - simpa using (hasDerivAt_mul_const (v i)).const_add (1:ℝ) - -lemma hasDerivAt_rayG₀ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayG₀ v) (rayG₁ v t) t := - hasDerivAt_avg (fun i ↦ hasDerivAt_log_edge i (hp i)) - -lemma hasDerivAt_rayG₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayG₁ v) (rayG₂ v t) t := by - apply hasDerivAt_avg - intro i - apply ((hasDerivAt_const t (v i)).div (hasDerivAt_ray_coord v t i) (hp i)).congr_deriv - simp only [zero_mul, zero_sub]; ring - -lemma hasDerivAt_rayG₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayG₂ v) (rayG₃ v t) t := by - apply hasDerivAt_avg - intro i - apply ((hasDerivAt_const t (-v i^2)).div ((hasDerivAt_ray_coord v t i).pow 2) (pow_ne_zero 2 (hp i))).congr_deriv - dsimp - field_simp [hp i]; ring - -lemma hasDerivAt_rayI₀ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayI₀ v) (rayI₁ v t) t := by - have hd := hasDerivAt_avg (fun i ↦ - (hasDerivAt_ray_coord v t i).mul (hasDerivAt_log_edge i (hp i))) - apply hd.congr_deriv - simp only [rayI₁, avg] at * - have he (i : Fin 3) : (1+t*v i)*(v i/(1+t*v i)) = v i := by field_simp [hp i] - simp_rw [he] - linarith - -lemma hasDerivAt_rayI₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayI₁ v) (rayI₂ v t) t := by - apply hasDerivAt_avg - intro i - apply ((hasDerivAt_log_edge i (hp i)).const_mul (v i)).congr_deriv - ring - -lemma hasDerivAt_rayI₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayI₂ v) (rayI₃ v t) t := by - apply hasDerivAt_avg - intro i - apply ((hasDerivAt_const t (v i^2)).div (hasDerivAt_ray_coord v t i) (hp i)).congr_deriv - simp only [zero_mul, zero_sub]; ring - -lemma hasDerivAt_rayH₀ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayH₀ v) (rayH₁ v t) t := by - apply hasDerivAt_avg - intro i - apply ((hasDerivAt_ray_coord v t i).mul ((hasDerivAt_log_edge i (hp i)).pow 2)).congr_deriv - dsimp - have he : (1+t*v i)*(v i/(1+t*v i)) = v i := by field_simp [hp i] - calc - _ = v i*Real.log (1+t*v i)^2 + 2*Real.log (1+t*v i)*((1+t*v i)*(v i/(1+t*v i))) := by ring - _ = _ := by rw [he]; ring - -lemma hasDerivAt_rayH₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayH₁ v) (rayH₂ v t) t := by - apply hasDerivAt_avg - intro i - have hl := hasDerivAt_log_edge i (hp i) - apply (((hl.pow 2).add (hl.const_mul 2)).const_mul (v i)).congr_deriv - norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one]; ring - -lemma hasDerivAt_rayH₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayH₂ v) (rayH₃ v t) t := by - apply hasDerivAt_avg - intro i - have hl := hasDerivAt_log_edge i (hp i) - have ha := hasDerivAt_ray_coord v t i - apply (((hasDerivAt_const t (2*v i^2)).div ha (hp i)).mul (hl.add_const 1)).congr_deriv - simp only [Pi.div_apply] - field_simp [hp i]; ring - -def rayF₀ (v : Vec) (t : ℝ) : ℝ := - rayG₀ v t + 2*rayI₀ v t + (2/5)*rayH₀ v t - (4/5)*rayG₀ v t*rayI₀ v t + (2/5)*rayG₀ v t^2 - -def rayF₁ (v : Vec) (t : ℝ) : ℝ := - rayG₁ v t + 2*rayI₁ v t + (2/5)*rayH₁ v t - - (4/5)*(rayG₁ v t*rayI₀ v t+rayG₀ v t*rayI₁ v t) + (4/5)*rayG₀ v t*rayG₁ v t - -def rayF₂ (v : Vec) (t : ℝ) : ℝ := - rayG₂ v t + 2*rayI₂ v t + (2/5)*rayH₂ v t - - (4/5)*(rayG₂ v t*rayI₀ v t+2*rayG₁ v t*rayI₁ v t+rayG₀ v t*rayI₂ v t) + - (4/5)*(rayG₁ v t^2+rayG₀ v t*rayG₂ v t) - -def rayF₃ (v : Vec) (t : ℝ) : ℝ := - rayG₃ v t + 2*rayI₃ v t + (2/5)*rayH₃ v t - - (4/5)*(rayG₃ v t*rayI₀ v t+3*rayG₂ v t*rayI₁ v t+ - 3*rayG₁ v t*rayI₂ v t+rayG₀ v t*rayI₃ v t) + - (4/5)*(3*rayG₁ v t*rayG₂ v t+rayG₀ v t*rayG₃ v t) - -lemma hasDerivAt_rayF₀ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayF₀ v) (rayF₁ v t) t := by - have hg := hasDerivAt_rayG₀ hp - have hi := hasDerivAt_rayI₀ hv hp - have hh := hasDerivAt_rayH₀ hp - apply (((hg.add (hi.const_mul 2)).add (hh.const_mul (2/5))).sub - ((hg.const_mul (4/5)).mul hi) |>.add ((hg.pow 2).const_mul (2/5))).congr_deriv - dsimp only [rayF₁, Pi.pow_apply] - norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] - ring - -lemma hasDerivAt_rayF₁ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayF₁ v) (rayF₂ v t) t := by - have hg₀ := hasDerivAt_rayG₀ hp - have hg₁ := hasDerivAt_rayG₁ hp - have hi₀ := hasDerivAt_rayI₀ hv hp - have hi₁ := hasDerivAt_rayI₁ hp - have hh₁ := hasDerivAt_rayH₁ hp - apply (((hg₁.add (hi₁.const_mul 2)).add (hh₁.const_mul (2/5))).sub - (((hg₁.mul hi₀).add (hg₀.mul hi₁)).const_mul (4/5)) |>.add - ((hg₀.const_mul (4/5)).mul hg₁)).congr_deriv - dsimp only [rayF₂, Pi.add_apply] - ring - -lemma hasDerivAt_rayF₂ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - HasDerivAt (rayF₂ v) (rayF₃ v t) t := by - have hg₀ := hasDerivAt_rayG₀ hp - have hg₁ := hasDerivAt_rayG₁ hp - have hg₂ := hasDerivAt_rayG₂ hp - have hi₀ := hasDerivAt_rayI₀ hv hp - have hi₁ := hasDerivAt_rayI₁ hp - have hi₂ := hasDerivAt_rayI₂ hp - have hh₂ := hasDerivAt_rayH₂ hp - apply (((hg₂.add (hi₂.const_mul 2)).add (hh₂.const_mul (2/5))).sub - ((((hg₂.mul hi₀).add ((hg₁.const_mul 2).mul hi₁)).add (hg₀.mul hi₂)).const_mul (4/5)) |>.add - (((hg₁.pow 2).add (hg₀.mul hg₂)).const_mul (4/5))).congr_deriv - dsimp only [rayF₃, Pi.add_apply] - norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] - ring - -lemma rayF₀_eq_functional {v : Vec} (hv : avg v = 0) (t : ℝ) : - rayF₀ v t = functional (fun i ↦ 1+t*v i) := by - rw [functional_eq] - simp only [rayF₀, rayG₀, rayI₀, rayH₀, logAverage, symEntropy, correction, logCentered, avg] - rw [third_eq hv] - ring - -lemma rayF₀_zero (v : Vec) : rayF₀ v 0 = 0 := by - norm_num [rayF₀, rayG₀, rayI₀, rayH₀, avg] - -lemma rayF₁_zero {v : Vec} (hv : avg v = 0) : rayF₁ v 0 = 0 := by - simpa [rayF₁, rayG₀, rayG₁, rayI₀, rayI₁, rayH₁, avg] using hv - -lemma rayG₁_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t*rayG₁ v t = 1-invMoment (fun i ↦ 1+t*v i) 1 := by - have he (i : Fin 3) : t*(v i/(1+t*v i)) = 1-(1+t*v i)⁻¹ := by - field_simp [hp i]; ring - rw [rayG₁, ← avg_mul] - simp_rw [he] - simp only [avg, invMoment, pow_one]; ring - -lemma rayG₂_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^2*rayG₂ v t = -1+2*invMoment (fun i ↦ 1+t*v i) 1-invMoment (fun i ↦ 1+t*v i) 2 := by - have he (i : Fin 3) : t^2*(-v i^2/(1+t*v i)^2) = -1+2*(1+t*v i)⁻¹-(1+t*v i)⁻¹^2 := by - field_simp [hp i]; ring - rw [rayG₂, ← avg_mul] - simp_rw [he] - simp only [avg, invMoment, pow_one]; ring - -lemma rayG₃_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^3*rayG₃ v t = 2-6*invMoment (fun i ↦ 1+t*v i) 1+ - 6*invMoment (fun i ↦ 1+t*v i) 2-2*invMoment (fun i ↦ 1+t*v i) 3 := by - have he (i : Fin 3) : t^3*(2*v i^3/(1+t*v i)^3) = - 2-6*(1+t*v i)⁻¹+6*(1+t*v i)⁻¹^2-2*(1+t*v i)⁻¹^3 := by - field_simp [hp i]; ring - rw [rayG₃, ← avg_mul] - simp_rw [he] - simp only [avg, invMoment, pow_one]; ring - -lemma rayI₁_scaled (v : Vec) (t : ℝ) : t*rayI₁ v t = rayI₀ v t-rayG₀ v t := by - simp only [rayI₁, rayI₀, rayG₀, avg]; ring - -lemma rayI₂_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^2*rayI₂ v t = invMoment (fun i ↦ 1+t*v i) 1-1 := by - have he (i : Fin 3) : t^2*(v i^2/(1+t*v i)) = (1+t*v i)-2+(1+t*v i)⁻¹ := by - field_simp [hp i]; ring - rw [rayI₂, ← avg_mul] - simp_rw [he] - simp only [avg, invMoment, pow_one] - rw [third_eq hv]; ring - -lemma rayI₃_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^3*rayI₃ v t = 2-3*invMoment (fun i ↦ 1+t*v i) 1+invMoment (fun i ↦ 1+t*v i) 2 := by - have he (i : Fin 3) : t^3*(-v i^3/(1+t*v i)^2) = - -(1+t*v i)+3-3*(1+t*v i)⁻¹+(1+t*v i)⁻¹^2 := by - field_simp [hp i]; ring - rw [rayI₃, ← avg_mul] - simp_rw [he] - simp only [avg, invMoment, pow_one] - rw [third_eq hv]; ring - -lemma rayH₃_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^3*rayH₃ v t = -2*(rayI₀ v t-3*rayG₀ v t+ - 3*(logInvMoment (fun i ↦ 1+t*v i) 1+rayG₀ v t*invMoment (fun i ↦ 1+t*v i) 1)- - (logInvMoment (fun i ↦ 1+t*v i) 2+rayG₀ v t*invMoment (fun i ↦ 1+t*v i) 2)) := by - have he (i : Fin 3) : t^3*(-2*v i^3*Real.log (1+t*v i)/(1+t*v i)^2) = - -2*((1+t*v i)*Real.log (1+t*v i)-3*Real.log (1+t*v i)+ - 3*Real.log (1+t*v i)*(1+t*v i)⁻¹-Real.log (1+t*v i)*(1+t*v i)⁻¹^2) := by - field_simp [hp i]; ring - rw [rayH₃, ← avg_mul] - simp_rw [he] - simp only [avg, rayI₀, rayG₀, logInvMoment, logCentered, logAverage, invMoment, pow_one] - ring - -lemma logMoment_ray {v : Vec} (hv : avg v = 0) (t : ℝ) : - logMoment (fun i ↦ 1+t*v i) = rayI₀ v t-rayG₀ v t := by - simp only [logMoment, rayI₀, rayG₀, logCentered, logAverage, avg] - rw [third_eq hv]; ring - -lemma rayF₃_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : - t^3*rayF₃ v t = radialG (fun i ↦ 1+t*v i) := by - calc - _ = t^3*rayG₃ v t + 2*(t^3*rayI₃ v t) + (2/5)*(t^3*rayH₃ v t) - - (4/5)*((t^3*rayG₃ v t)*rayI₀ v t+3*(t^2*rayG₂ v t)*(t*rayI₁ v t)+ - 3*(t*rayG₁ v t)*(t^2*rayI₂ v t)+rayG₀ v t*(t^3*rayI₃ v t)) + - (4/5)*(3*(t*rayG₁ v t)*(t^2*rayG₂ v t)+rayG₀ v t*(t^3*rayG₃ v t)) := by - unfold rayF₃; ring - _ = _ := by - rw [rayG₁_scaled hp, rayG₂_scaled hp, rayG₃_scaled hp, - rayI₁_scaled, rayI₂_scaled hv hp, rayI₃_scaled hv hp, rayH₃_scaled hp] - rw [radialG, logMoment_ray hv] - ring - -end ThreeState.TreeClauses.Radial - -end - -noncomputable section -open Set -namespace ThreeState.TreeClauses.Radial - -lemma monotoneOn_Icc_of_hasDerivAt_nonneg {a b : ℝ} {f f' : ℝ → ℝ} - (hf : ∀ t ∈ Icc a b, HasDerivAt f (f' t) t) - (hn : ∀ t ∈ Ioo a b, 0 ≤ f' t) : MonotoneOn f (Icc a b) := by - apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc a b) - (fun t ht ↦ (hf t ht).continuousAt.continuousWithinAt) - · intro t ht - rw [interior_Icc] at ht - exact (hf t ⟨ht.1.le, ht.2.le⟩).hasDerivWithinAt - · simpa only [interior_Icc] using hn - -lemma radial_calculus {f f₁ f₂ f₃ : ℝ → ℝ} {x : ℝ} - (h₀ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f (f₁ t) t) - (h₁ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f₁ (f₂ t) t) - (h₂ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f₂ (f₃ t) t) - (hf0 : f 0 = 0) (hf1 : f₁ 0 = 0) - (hb : ∀ t ∈ Ioo (0:ℝ) 1, 12*t*x^2 ≤ f₃ t) - {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) : - (1-lam^2)/2*x^2 ≤ f 1-(lam^2)⁻¹*f lam := by - let Y : ℝ → ℝ := fun t ↦ t*f₁ t-2*f t-t^4*x^2 - let Y₁ : ℝ → ℝ := fun t ↦ t*f₂ t-f₁ t-4*t^3*x^2 - let Y₂ : ℝ → ℝ := fun t ↦ t*f₃ t-12*t^2*x^2 - have dY (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : HasDerivAt Y (Y₁ t) t := by - apply ((((hasDerivAt_id t).mul (h₁ t ht)).sub ((h₀ t ht).const_mul 2)).sub - (((hasDerivAt_id t).pow 4).mul_const (x^2))).congr_deriv - dsimp [Y₁]; ring - have dY₁ (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : HasDerivAt Y₁ (Y₂ t) t := by - apply ((((hasDerivAt_id t).mul (h₂ t ht)).sub (h₁ t ht)).sub - ((((hasDerivAt_id t).pow 3).const_mul 4).mul_const (x^2))).congr_deriv - dsimp [Y₂]; ring - have hm₁ : MonotoneOn Y₁ (Icc (0:ℝ) 1) := by - apply monotoneOn_Icc_of_hasDerivAt_nonneg dY₁ - intro t ht - have h := mul_le_mul_of_nonneg_left (hb t ht) ht.1.le - dsimp only [Y₂]; nlinarith - have hn₁ (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ Y₁ t := by - have h := hm₁ (by norm_num : (0:ℝ) ∈ Icc 0 1) ht ht.1 - simpa [Y₁, hf1] using h - have hm : MonotoneOn Y (Icc (0:ℝ) 1) := - monotoneOn_Icc_of_hasDerivAt_nonneg dY (fun t ht ↦ hn₁ t ⟨ht.1.le, ht.2.le⟩) - have hn (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ Y t := by - have h := hm (by norm_num : (0:ℝ) ∈ Icc 0 1) ht ht.1 - simpa [Y, hf0] using h - let q : ℝ → ℝ := fun t ↦ (f t-(1/2)*t^4*x^2)/t^2 - have dq (t : ℝ) (ht : t ∈ Icc lam 1) : HasDerivAt q (Y t/t^3) t := by - have ht0 : 0 < t := lt_of_lt_of_le hl₀ ht.1 - have hti : t ∈ Icc (0:ℝ) 1 := ⟨ht0.le, ht.2⟩ - apply (((h₀ t hti).sub ((((hasDerivAt_id t).pow 4).const_mul (1/2)).mul_const (x^2))).div - ((hasDerivAt_id t).pow 2) (pow_ne_zero 2 (ne_of_gt ht0))).congr_deriv - dsimp [Y] - norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] - field_simp [ne_of_gt ht0]; ring - have hmq : MonotoneOn q (Icc lam 1) := by - apply monotoneOn_Icc_of_hasDerivAt_nonneg dq - intro t ht - exact div_nonneg (hn t ⟨(lt_trans hl₀ ht.1).le, ht.2.le⟩) - (pow_nonneg (lt_trans hl₀ ht.1).le 3) - have hr := hmq (by exact ⟨le_rfl, hl₁.le⟩ : lam ∈ Icc lam 1) - (by exact ⟨hl₁.le, le_rfl⟩ : (1:ℝ) ∈ Icc lam 1) hl₁.le - have hr' : f lam/lam^2-lam^2/2*x^2 ≤ f 1-(1/2)*x^2 := by - calc - f lam/lam^2-lam^2/2*x^2 = q lam := by - dsimp [q]; field_simp [ne_of_gt hl₀] - _ ≤ q 1 := hr - _ = _ := by norm_num [q] - rw [inv_mul_eq_div] - linarith - -lemma positive_edge {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : - PositiveMessage (edge t m) := by - refine ⟨fun i ↦ edge_pos hm ht i, ?_⟩ - change avg (fun i ↦ 1+t*centered m i) = 1 - rw [avg_add, avg_const, avg_mul, avg_centered hm] - ring - -lemma momentX_edge (m : Vec) (t : ℝ) : - momentX (centered (edge t m)) = t^2*momentX (centered m) := by - simp only [momentX, centered, edge, avg]; ring - -lemma rayF₃_lower {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Ioo (0:ℝ) 1) : - 12*t*momentX (centered m)^2 ≤ rayF₃ (centered m) t := by - have h := radialG_bound (positive_edge hm ⟨ht.1.le, ht.2.le⟩) - have hp (i : Fin 3) : 1+t*centered m i ≠ 0 := - ne_of_gt (edge_pos hm ⟨ht.1.le, ht.2.le⟩ i) - rw [momentX_edge] at h - have he : t^3*rayF₃ (centered m) t = radialG (edge t m) := - rayF₃_scaled (avg_centered hm) hp - rw [← he] at h - have h' : 0 ≤ t^3*(rayF₃ (centered m) t-12*t*momentX (centered m)^2) := by nlinarith - exact sub_nonneg.mp ((mul_nonneg_iff_of_pos_left (pow_pos ht.1 3)).mp h') - -theorem radial_inequality : RadialInequality := by - intro m hm lam hl₀ hl₁ - have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) (i : Fin 3) : 1+t*centered m i ≠ 0 := - ne_of_gt (edge_pos hm ht i) - have h := radial_calculus - (fun t ht ↦ hasDerivAt_rayF₀ (avg_centered hm) (hp t ht)) - (fun t ht ↦ hasDerivAt_rayF₁ (avg_centered hm) (hp t ht)) - (fun t ht ↦ hasDerivAt_rayF₂ (avg_centered hm) (hp t ht)) - (rayF₀_zero (centered m)) (rayF₁_zero (avg_centered hm)) - (fun _ ht ↦ rayF₃_lower hm ht) hl₀ hl₁ - rw [rayF₀_eq_functional (avg_centered hm), rayF₀_eq_functional (avg_centered hm)] at h - have he1 : (fun i ↦ 1+(1:ℝ)*centered m i) = m := by funext i; simp [centered] - rw [he1] at h - exact h - -end ThreeState.TreeClauses.Radial - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RadialBounds + +namespace OAI + +/-! Radial Calculus. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set +namespace ThreeState.TreeClauses.Radial + +def rayG₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ Real.log (1+t*v i)) +def rayG₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i/(1+t*v i)) +def rayG₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -v i^2/(1+t*v i)^2) +def rayG₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ 2*v i^3/(1+t*v i)^3) + +def rayI₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (1+t*v i)*Real.log (1+t*v i)) +def rayI₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i*Real.log (1+t*v i)) +def rayI₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i^2/(1+t*v i)) +def rayI₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -v i^3/(1+t*v i)^2) + +def rayH₀ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (1+t*v i)*Real.log (1+t*v i)^2) +def rayH₁ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ v i*(Real.log (1+t*v i)^2+2*Real.log (1+t*v i))) +def rayH₂ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ (2*v i^2/(1+t*v i))*(Real.log (1+t*v i)+1)) +def rayH₃ (v : Vec) (t : ℝ) : ℝ := avg (fun i ↦ -2*v i^3*Real.log (1+t*v i)/(1+t*v i)^2) + +lemma hasDerivAt_avg {f : ℝ → Vec} {df : Vec} {t : ℝ} + (hf : ∀ i, HasDerivAt (fun s ↦ f s i) (df i) t) : + HasDerivAt (fun s ↦ avg (f s)) (avg df) t := + (((hf 0).add (hf 1)).add (hf 2)).div_const 3 + +lemma hasDerivAt_ray_coord (v : Vec) (t : ℝ) (i : Fin 3) : + HasDerivAt (fun s : ℝ ↦ 1+s*v i) (v i) t := by + simpa using (hasDerivAt_mul_const (v i)).const_add (1:ℝ) + +lemma hasDerivAt_rayG₀ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayG₀ v) (rayG₁ v t) t := + hasDerivAt_avg (fun i ↦ hasDerivAt_log_edge i (hp i)) + +lemma hasDerivAt_rayG₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayG₁ v) (rayG₂ v t) t := by + apply hasDerivAt_avg + intro i + apply ((hasDerivAt_const t (v i)).div (hasDerivAt_ray_coord v t i) (hp i)).congr_deriv + simp only [zero_mul, zero_sub]; ring + +lemma hasDerivAt_rayG₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayG₂ v) (rayG₃ v t) t := by + apply hasDerivAt_avg + intro i + apply ((hasDerivAt_const t (-v i^2)).div ((hasDerivAt_ray_coord v t i).pow 2) (pow_ne_zero 2 (hp i))).congr_deriv + dsimp + field_simp [hp i]; ring + +lemma hasDerivAt_rayI₀ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayI₀ v) (rayI₁ v t) t := by + have hd := hasDerivAt_avg (fun i ↦ + (hasDerivAt_ray_coord v t i).mul (hasDerivAt_log_edge i (hp i))) + apply hd.congr_deriv + simp only [rayI₁, avg] at * + have he (i : Fin 3) : (1+t*v i)*(v i/(1+t*v i)) = v i := by field_simp [hp i] + simp_rw [he] + linarith + +lemma hasDerivAt_rayI₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayI₁ v) (rayI₂ v t) t := by + apply hasDerivAt_avg + intro i + apply ((hasDerivAt_log_edge i (hp i)).const_mul (v i)).congr_deriv + ring + +lemma hasDerivAt_rayI₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayI₂ v) (rayI₃ v t) t := by + apply hasDerivAt_avg + intro i + apply ((hasDerivAt_const t (v i^2)).div (hasDerivAt_ray_coord v t i) (hp i)).congr_deriv + simp only [zero_mul, zero_sub]; ring + +lemma hasDerivAt_rayH₀ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayH₀ v) (rayH₁ v t) t := by + apply hasDerivAt_avg + intro i + apply ((hasDerivAt_ray_coord v t i).mul ((hasDerivAt_log_edge i (hp i)).pow 2)).congr_deriv + dsimp + have he : (1+t*v i)*(v i/(1+t*v i)) = v i := by field_simp [hp i] + calc + _ = v i*Real.log (1+t*v i)^2 + 2*Real.log (1+t*v i)*((1+t*v i)*(v i/(1+t*v i))) := by ring + _ = _ := by rw [he]; ring + +lemma hasDerivAt_rayH₁ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayH₁ v) (rayH₂ v t) t := by + apply hasDerivAt_avg + intro i + have hl := hasDerivAt_log_edge i (hp i) + apply (((hl.pow 2).add (hl.const_mul 2)).const_mul (v i)).congr_deriv + norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one]; ring + +lemma hasDerivAt_rayH₂ {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayH₂ v) (rayH₃ v t) t := by + apply hasDerivAt_avg + intro i + have hl := hasDerivAt_log_edge i (hp i) + have ha := hasDerivAt_ray_coord v t i + apply (((hasDerivAt_const t (2*v i^2)).div ha (hp i)).mul (hl.add_const 1)).congr_deriv + simp only [Pi.div_apply] + field_simp [hp i]; ring + +def rayF₀ (v : Vec) (t : ℝ) : ℝ := + rayG₀ v t + 2*rayI₀ v t + (2/5)*rayH₀ v t - (4/5)*rayG₀ v t*rayI₀ v t + (2/5)*rayG₀ v t^2 + +def rayF₁ (v : Vec) (t : ℝ) : ℝ := + rayG₁ v t + 2*rayI₁ v t + (2/5)*rayH₁ v t - + (4/5)*(rayG₁ v t*rayI₀ v t+rayG₀ v t*rayI₁ v t) + (4/5)*rayG₀ v t*rayG₁ v t + +def rayF₂ (v : Vec) (t : ℝ) : ℝ := + rayG₂ v t + 2*rayI₂ v t + (2/5)*rayH₂ v t - + (4/5)*(rayG₂ v t*rayI₀ v t+2*rayG₁ v t*rayI₁ v t+rayG₀ v t*rayI₂ v t) + + (4/5)*(rayG₁ v t^2+rayG₀ v t*rayG₂ v t) + +def rayF₃ (v : Vec) (t : ℝ) : ℝ := + rayG₃ v t + 2*rayI₃ v t + (2/5)*rayH₃ v t - + (4/5)*(rayG₃ v t*rayI₀ v t+3*rayG₂ v t*rayI₁ v t+ + 3*rayG₁ v t*rayI₂ v t+rayG₀ v t*rayI₃ v t) + + (4/5)*(3*rayG₁ v t*rayG₂ v t+rayG₀ v t*rayG₃ v t) + +lemma hasDerivAt_rayF₀ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayF₀ v) (rayF₁ v t) t := by + have hg := hasDerivAt_rayG₀ hp + have hi := hasDerivAt_rayI₀ hv hp + have hh := hasDerivAt_rayH₀ hp + apply (((hg.add (hi.const_mul 2)).add (hh.const_mul (2/5))).sub + ((hg.const_mul (4/5)).mul hi) |>.add ((hg.pow 2).const_mul (2/5))).congr_deriv + dsimp only [rayF₁, Pi.pow_apply] + norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] + ring + +lemma hasDerivAt_rayF₁ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayF₁ v) (rayF₂ v t) t := by + have hg₀ := hasDerivAt_rayG₀ hp + have hg₁ := hasDerivAt_rayG₁ hp + have hi₀ := hasDerivAt_rayI₀ hv hp + have hi₁ := hasDerivAt_rayI₁ hp + have hh₁ := hasDerivAt_rayH₁ hp + apply (((hg₁.add (hi₁.const_mul 2)).add (hh₁.const_mul (2/5))).sub + (((hg₁.mul hi₀).add (hg₀.mul hi₁)).const_mul (4/5)) |>.add + ((hg₀.const_mul (4/5)).mul hg₁)).congr_deriv + dsimp only [rayF₂, Pi.add_apply] + ring + +lemma hasDerivAt_rayF₂ {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + HasDerivAt (rayF₂ v) (rayF₃ v t) t := by + have hg₀ := hasDerivAt_rayG₀ hp + have hg₁ := hasDerivAt_rayG₁ hp + have hg₂ := hasDerivAt_rayG₂ hp + have hi₀ := hasDerivAt_rayI₀ hv hp + have hi₁ := hasDerivAt_rayI₁ hp + have hi₂ := hasDerivAt_rayI₂ hp + have hh₂ := hasDerivAt_rayH₂ hp + apply (((hg₂.add (hi₂.const_mul 2)).add (hh₂.const_mul (2/5))).sub + ((((hg₂.mul hi₀).add ((hg₁.const_mul 2).mul hi₁)).add (hg₀.mul hi₂)).const_mul (4/5)) |>.add + (((hg₁.pow 2).add (hg₀.mul hg₂)).const_mul (4/5))).congr_deriv + dsimp only [rayF₃, Pi.add_apply] + norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] + ring + +lemma rayF₀_eq_functional {v : Vec} (hv : avg v = 0) (t : ℝ) : + rayF₀ v t = functional (fun i ↦ 1+t*v i) := by + rw [functional_eq] + simp only [rayF₀, rayG₀, rayI₀, rayH₀, logAverage, symEntropy, correction, logCentered, avg] + rw [third_eq hv] + ring + +lemma rayF₀_zero (v : Vec) : rayF₀ v 0 = 0 := by + norm_num [rayF₀, rayG₀, rayI₀, rayH₀, avg] + +lemma rayF₁_zero {v : Vec} (hv : avg v = 0) : rayF₁ v 0 = 0 := by + simpa [rayF₁, rayG₀, rayG₁, rayI₀, rayI₁, rayH₁, avg] using hv + +lemma rayG₁_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t*rayG₁ v t = 1-invMoment (fun i ↦ 1+t*v i) 1 := by + have he (i : Fin 3) : t*(v i/(1+t*v i)) = 1-(1+t*v i)⁻¹ := by + field_simp [hp i]; ring + rw [rayG₁, ← avg_mul] + simp_rw [he] + simp only [avg, invMoment, pow_one]; ring + +lemma rayG₂_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^2*rayG₂ v t = -1+2*invMoment (fun i ↦ 1+t*v i) 1-invMoment (fun i ↦ 1+t*v i) 2 := by + have he (i : Fin 3) : t^2*(-v i^2/(1+t*v i)^2) = -1+2*(1+t*v i)⁻¹-(1+t*v i)⁻¹^2 := by + field_simp [hp i]; ring + rw [rayG₂, ← avg_mul] + simp_rw [he] + simp only [avg, invMoment, pow_one]; ring + +lemma rayG₃_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^3*rayG₃ v t = 2-6*invMoment (fun i ↦ 1+t*v i) 1+ + 6*invMoment (fun i ↦ 1+t*v i) 2-2*invMoment (fun i ↦ 1+t*v i) 3 := by + have he (i : Fin 3) : t^3*(2*v i^3/(1+t*v i)^3) = + 2-6*(1+t*v i)⁻¹+6*(1+t*v i)⁻¹^2-2*(1+t*v i)⁻¹^3 := by + field_simp [hp i]; ring + rw [rayG₃, ← avg_mul] + simp_rw [he] + simp only [avg, invMoment, pow_one]; ring + +lemma rayI₁_scaled (v : Vec) (t : ℝ) : t*rayI₁ v t = rayI₀ v t-rayG₀ v t := by + simp only [rayI₁, rayI₀, rayG₀, avg]; ring + +lemma rayI₂_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^2*rayI₂ v t = invMoment (fun i ↦ 1+t*v i) 1-1 := by + have he (i : Fin 3) : t^2*(v i^2/(1+t*v i)) = (1+t*v i)-2+(1+t*v i)⁻¹ := by + field_simp [hp i]; ring + rw [rayI₂, ← avg_mul] + simp_rw [he] + simp only [avg, invMoment, pow_one] + rw [third_eq hv]; ring + +lemma rayI₃_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^3*rayI₃ v t = 2-3*invMoment (fun i ↦ 1+t*v i) 1+invMoment (fun i ↦ 1+t*v i) 2 := by + have he (i : Fin 3) : t^3*(-v i^3/(1+t*v i)^2) = + -(1+t*v i)+3-3*(1+t*v i)⁻¹+(1+t*v i)⁻¹^2 := by + field_simp [hp i]; ring + rw [rayI₃, ← avg_mul] + simp_rw [he] + simp only [avg, invMoment, pow_one] + rw [third_eq hv]; ring + +lemma rayH₃_scaled {v : Vec} {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^3*rayH₃ v t = -2*(rayI₀ v t-3*rayG₀ v t+ + 3*(logInvMoment (fun i ↦ 1+t*v i) 1+rayG₀ v t*invMoment (fun i ↦ 1+t*v i) 1)- + (logInvMoment (fun i ↦ 1+t*v i) 2+rayG₀ v t*invMoment (fun i ↦ 1+t*v i) 2)) := by + have he (i : Fin 3) : t^3*(-2*v i^3*Real.log (1+t*v i)/(1+t*v i)^2) = + -2*((1+t*v i)*Real.log (1+t*v i)-3*Real.log (1+t*v i)+ + 3*Real.log (1+t*v i)*(1+t*v i)⁻¹-Real.log (1+t*v i)*(1+t*v i)⁻¹^2) := by + field_simp [hp i]; ring + rw [rayH₃, ← avg_mul] + simp_rw [he] + simp only [avg, rayI₀, rayG₀, logInvMoment, logCentered, logAverage, invMoment, pow_one] + ring + +lemma logMoment_ray {v : Vec} (hv : avg v = 0) (t : ℝ) : + logMoment (fun i ↦ 1+t*v i) = rayI₀ v t-rayG₀ v t := by + simp only [logMoment, rayI₀, rayG₀, logCentered, logAverage, avg] + rw [third_eq hv]; ring + +lemma rayF₃_scaled {v : Vec} (hv : avg v = 0) {t : ℝ} (hp : ∀ i, 1+t*v i ≠ 0) : + t^3*rayF₃ v t = radialG (fun i ↦ 1+t*v i) := by + calc + _ = t^3*rayG₃ v t + 2*(t^3*rayI₃ v t) + (2/5)*(t^3*rayH₃ v t) - + (4/5)*((t^3*rayG₃ v t)*rayI₀ v t+3*(t^2*rayG₂ v t)*(t*rayI₁ v t)+ + 3*(t*rayG₁ v t)*(t^2*rayI₂ v t)+rayG₀ v t*(t^3*rayI₃ v t)) + + (4/5)*(3*(t*rayG₁ v t)*(t^2*rayG₂ v t)+rayG₀ v t*(t^3*rayG₃ v t)) := by + unfold rayF₃; ring + _ = _ := by + rw [rayG₁_scaled hp, rayG₂_scaled hp, rayG₃_scaled hp, + rayI₁_scaled, rayI₂_scaled hv hp, rayI₃_scaled hv hp, rayH₃_scaled hp] + rw [radialG, logMoment_ray hv] + ring + +end ThreeState.TreeClauses.Radial + +end + +noncomputable section +open Set +namespace ThreeState.TreeClauses.Radial + +lemma monotoneOn_Icc_of_hasDerivAt_nonneg {a b : ℝ} {f f' : ℝ → ℝ} + (hf : ∀ t ∈ Icc a b, HasDerivAt f (f' t) t) + (hn : ∀ t ∈ Ioo a b, 0 ≤ f' t) : MonotoneOn f (Icc a b) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc a b) + (fun t ht ↦ (hf t ht).continuousAt.continuousWithinAt) + · intro t ht + rw [interior_Icc] at ht + exact (hf t ⟨ht.1.le, ht.2.le⟩).hasDerivWithinAt + · simpa only [interior_Icc] using hn + +lemma radial_calculus {f f₁ f₂ f₃ : ℝ → ℝ} {x : ℝ} + (h₀ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f (f₁ t) t) + (h₁ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f₁ (f₂ t) t) + (h₂ : ∀ t ∈ Icc (0:ℝ) 1, HasDerivAt f₂ (f₃ t) t) + (hf0 : f 0 = 0) (hf1 : f₁ 0 = 0) + (hb : ∀ t ∈ Ioo (0:ℝ) 1, 12*t*x^2 ≤ f₃ t) + {lam : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) : + (1-lam^2)/2*x^2 ≤ f 1-(lam^2)⁻¹*f lam := by + let Y : ℝ → ℝ := fun t ↦ t*f₁ t-2*f t-t^4*x^2 + let Y₁ : ℝ → ℝ := fun t ↦ t*f₂ t-f₁ t-4*t^3*x^2 + let Y₂ : ℝ → ℝ := fun t ↦ t*f₃ t-12*t^2*x^2 + have dY (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : HasDerivAt Y (Y₁ t) t := by + apply ((((hasDerivAt_id t).mul (h₁ t ht)).sub ((h₀ t ht).const_mul 2)).sub + (((hasDerivAt_id t).pow 4).mul_const (x^2))).congr_deriv + dsimp [Y₁]; ring + have dY₁ (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : HasDerivAt Y₁ (Y₂ t) t := by + apply ((((hasDerivAt_id t).mul (h₂ t ht)).sub (h₁ t ht)).sub + ((((hasDerivAt_id t).pow 3).const_mul 4).mul_const (x^2))).congr_deriv + dsimp [Y₂]; ring + have hm₁ : MonotoneOn Y₁ (Icc (0:ℝ) 1) := by + apply monotoneOn_Icc_of_hasDerivAt_nonneg dY₁ + intro t ht + have h := mul_le_mul_of_nonneg_left (hb t ht) ht.1.le + dsimp only [Y₂]; nlinarith + have hn₁ (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ Y₁ t := by + have h := hm₁ (by norm_num : (0:ℝ) ∈ Icc 0 1) ht ht.1 + simpa [Y₁, hf1] using h + have hm : MonotoneOn Y (Icc (0:ℝ) 1) := + monotoneOn_Icc_of_hasDerivAt_nonneg dY (fun t ht ↦ hn₁ t ⟨ht.1.le, ht.2.le⟩) + have hn (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : 0 ≤ Y t := by + have h := hm (by norm_num : (0:ℝ) ∈ Icc 0 1) ht ht.1 + simpa [Y, hf0] using h + let q : ℝ → ℝ := fun t ↦ (f t-(1/2)*t^4*x^2)/t^2 + have dq (t : ℝ) (ht : t ∈ Icc lam 1) : HasDerivAt q (Y t/t^3) t := by + have ht0 : 0 < t := lt_of_lt_of_le hl₀ ht.1 + have hti : t ∈ Icc (0:ℝ) 1 := ⟨ht0.le, ht.2⟩ + apply (((h₀ t hti).sub ((((hasDerivAt_id t).pow 4).const_mul (1/2)).mul_const (x^2))).div + ((hasDerivAt_id t).pow 2) (pow_ne_zero 2 (ne_of_gt ht0))).congr_deriv + dsimp [Y] + norm_num only [Nat.cast_ofNat, Nat.reduceSub, pow_one] + field_simp [ne_of_gt ht0]; ring + have hmq : MonotoneOn q (Icc lam 1) := by + apply monotoneOn_Icc_of_hasDerivAt_nonneg dq + intro t ht + exact div_nonneg (hn t ⟨(lt_trans hl₀ ht.1).le, ht.2.le⟩) + (pow_nonneg (lt_trans hl₀ ht.1).le 3) + have hr := hmq (by exact ⟨le_rfl, hl₁.le⟩ : lam ∈ Icc lam 1) + (by exact ⟨hl₁.le, le_rfl⟩ : (1:ℝ) ∈ Icc lam 1) hl₁.le + have hr' : f lam/lam^2-lam^2/2*x^2 ≤ f 1-(1/2)*x^2 := by + calc + f lam/lam^2-lam^2/2*x^2 = q lam := by + dsimp [q]; field_simp [ne_of_gt hl₀] + _ ≤ q 1 := hr + _ = _ := by norm_num [q] + rw [inv_mul_eq_div] + linarith + +lemma positive_edge {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + PositiveMessage (edge t m) := by + refine ⟨fun i ↦ edge_pos hm ht i, ?_⟩ + change avg (fun i ↦ 1+t*centered m i) = 1 + rw [avg_add, avg_const, avg_mul, avg_centered hm] + ring + +lemma momentX_edge (m : Vec) (t : ℝ) : + momentX (centered (edge t m)) = t^2*momentX (centered m) := by + simp only [momentX, centered, edge, avg]; ring + +lemma rayF₃_lower {m : Vec} (hm : PositiveMessage m) {t : ℝ} (ht : t ∈ Ioo (0:ℝ) 1) : + 12*t*momentX (centered m)^2 ≤ rayF₃ (centered m) t := by + have h := radialG_bound (positive_edge hm ⟨ht.1.le, ht.2.le⟩) + have hp (i : Fin 3) : 1+t*centered m i ≠ 0 := + ne_of_gt (edge_pos hm ⟨ht.1.le, ht.2.le⟩ i) + rw [momentX_edge] at h + have he : t^3*rayF₃ (centered m) t = radialG (edge t m) := + rayF₃_scaled (avg_centered hm) hp + rw [← he] at h + have h' : 0 ≤ t^3*(rayF₃ (centered m) t-12*t*momentX (centered m)^2) := by nlinarith + exact sub_nonneg.mp ((mul_nonneg_iff_of_pos_left (pow_pos ht.1 3)).mp h') + +theorem radial_inequality : RadialInequality := by + intro m hm lam hl₀ hl₁ + have hp (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) (i : Fin 3) : 1+t*centered m i ≠ 0 := + ne_of_gt (edge_pos hm ht i) + have h := radial_calculus + (fun t ht ↦ hasDerivAt_rayF₀ (avg_centered hm) (hp t ht)) + (fun t ht ↦ hasDerivAt_rayF₁ (avg_centered hm) (hp t ht)) + (fun t ht ↦ hasDerivAt_rayF₂ (avg_centered hm) (hp t ht)) + (rayF₀_zero (centered m)) (rayF₁_zero (avg_centered hm)) + (fun _ ht ↦ rayF₃_lower hm ht) hl₀ hl₁ + rw [rayF₀_eq_functional (avg_centered hm), rayF₀_eq_functional (avg_centered hm)] at h + have he1 : (fun i ↦ 1+(1:ℝ)*centered m i) = m := by funext i; simp [centered] + rw [he1] at h + exact h + +end ThreeState.TreeClauses.Radial + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RegularCritical.lean b/lean/OAI/Probability/ThreeStateClauses/RegularCritical.lean index 7a5ca724758dc6f123cb4389cf3e9ef37969cd8c..4f9ea571d61432794323550b192de015bcb0ebec 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RegularCritical.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RegularCritical.lean @@ -1,249 +1,249 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.CompactLimits -import OAI.Probability.ThreeStateClauses.PositiveFixed - -namespace OAI - -/-! Regular Critical. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory Filter -open scoped Topology -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma regular_positive_critical_mu (b : ℕ) (hb : 2 ≤ b) {lam : ℝ} - (hl₀ : 0 < lam) (hl₁ : lam < 1) (hlam : Admissible lam) (hcrit : (b:ℝ)*lam^2 = 1) : - Tendsto (fun ℓ ↦ (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by - let Q := regularPosteriorLaw b hl₀.le hl₁ - let C := fun ℓ ↦ degradationCoupling (regularLaw b lam hlam ℓ) (regularExpansion b lam hlam ℓ) - have hf (ℓ : ℕ) : (C ℓ).map Prod.fst = (Q ℓ).probability := by - rw [degradationCoupling_fst, regularPosteriorLaw_probability b hl₀.le hl₁ hlam ℓ] - have hs (ℓ : ℕ) : (C ℓ).map Prod.snd = (Q (ℓ+1)).probability := by - rw [degradationCoupling_snd] - simp only [regularLaw_degrades] - exact (regularPosteriorLaw_probability b hl₀.le hl₁ hlam (ℓ+1)).symm - have hl (ℓ : ℕ) : (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu := by - rw [degradationCoupling_loss] - simp only [regularLaw_degrades] - simp only [Q, Law.mu, regularPosteriorLaw_probability b hl₀.le hl₁ hlam] - obtain ⟨R,hR,hlim⟩ := degrading_finite_fixed_point Q C hf hs hl hl₀.le hl₁ b (fun _ ↦ rfl) - rw [regular_fixed_mu_zero R hl₀ hl₁ b hb hcrit hR] at hlim - exact hlim - -lemma regular_advantage_sq_bound (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) - (hlam : Admissible lam) (ℓ : ℕ) : - (advantage lam hlam (PMF.pure b) ℓ)^2 ≤ (regularPosteriorLaw b hl₀ hl₁ ℓ).mu/2 := by - have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (fun v ↦ PMF.pure (forgetRegular b ℓ v)) - change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ))).toMeasure) ≤ _ at h - simp only [regularLaw_forget] at h - have ha := advantage_sq_bound lam hlam (PMF.pure b) ℓ - unfold Law.mu - rw [regularPosteriorLaw_probability b hl₀ hl₁ hlam ℓ] - linarith - -theorem regular_positive_critical_nonreconstruction (b : ℕ) (hb : 2 ≤ b) - (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 < lam) (hcrit : (b:ℝ)*lam^2 = 1) : - Tendsto (advantage lam hlam (PMF.pure b)) atTop (𝓝 0) := by - have hb' : (2:ℝ) ≤ b := by exact_mod_cast hb - have hl₁ : lam < 1 := by - have h := mul_le_mul_of_nonneg_right hb' (sq_nonneg lam) - nlinarith - have hm := regular_positive_critical_mu b hb hl₀ hl₁ hlam hcrit - have hu : Tendsto (fun ℓ ↦ Real.sqrt (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by - simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm - apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam (PMF.pure b) ℓ) _ hu - intro ℓ - apply (sq_le_sq₀ (advantage_nonneg lam hlam (PMF.pure b) ℓ) (Real.sqrt_nonneg _)).mp - rw [Real.sq_sqrt (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu_nonneg] - have h := regular_advantage_sq_bound b hl₀.le hl₁ hlam ℓ - linarith [(regularPosteriorLaw b hl₀.le hl₁ ℓ).mu_nonneg] - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment - -lemma channelWeight_alt (lam : ℝ) (i j : Spin) : - channelWeight lam i j = lam*(if i = j then 1 else 0)+(1-lam)/3 := by - unfold channelWeight - split_ifs <;> ring - -lemma channelWeight_compose (lam c : ℝ) (i j : Spin) : - (∑ k : Spin, channelWeight lam i k*channelWeight c k j) = channelWeight (lam*c) i j := by - classical - simp only [channelWeight_alt, add_mul, mul_add, Finset.sum_add_distrib, - ← Finset.mul_sum, mul_assoc] - by_cases h : i = j - · subst j - simp - ring - · simp [h] - ring - -lemma channel_compose {lam c : ℝ} (hlam : Admissible lam) (hc : Admissible c) - (hprod : Admissible (lam*c)) (i : Spin) : - (channel lam hlam i).bind (channel c hc) = channel (lam*c) hprod i := by - apply PMF.ext - intro j - apply (ENNReal.toReal_eq_toReal_iff' ((channel lam hlam i).bind (channel c hc) |>.apply_ne_top j) - ((channel (lam*c) hprod i).apply_ne_top j)).mp - rw [PMF.bind_apply, tsum_fintype, - ENNReal.toReal_sum (fun k _ ↦ ENNReal.mul_ne_top ((channel lam hlam i).apply_ne_top k) - ((channel c hc k).apply_ne_top j))] - simp only [ENNReal.toReal_mul, channel_real] - exact channelWeight_compose lam c i j - -lemma channel_permute {lam : ℝ} (hlam : Admissible lam) (σ : Equiv.Perm Spin) (i : Spin) : - (channel lam hlam i).map σ = channel lam hlam (σ i) := by - classical - apply PMF.ext - intro j - rw [PMF.map_apply, tsum_eq_single (σ.symm j)] - · simp only [σ.apply_symm_apply, ↓reduceIte] - change ENNReal.ofReal (channelWeight lam i (σ.symm j)) = - ENNReal.ofReal (channelWeight lam (σ i) j) - congr 1 - unfold channelWeight - simp only [Equiv.eq_symm_apply] - · intro a ha - have hne : j ≠ σ a := by - intro h - exact ha (σ.injective (h.symm.trans (σ.apply_symm_apply j).symm)) - simp only [hne, ↓reduceIte] - -def relabelRegular (b : ℕ) (σ : Equiv.Perm Spin) : (ℓ : ℕ) → RegularObservation b ℓ → RegularObservation b ℓ - | 0, i => σ i - | ℓ+1, v => fun j ↦ relabelRegular b σ ℓ (v j) - -lemma regularLaw_permute (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (σ : Equiv.Perm Spin) - (ℓ : ℕ) (i : Spin) : - (regularLaw b lam hlam ℓ i).map (relabelRegular b σ ℓ) = regularLaw b lam hlam ℓ (σ i) := by - induction ℓ generalizing i with - | zero => exact PMF.pure_bind _ _ - | succ ℓ ih => - change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).map - (fun v j ↦ relabelRegular b σ ℓ (v j)) = _ - rw [productPMF_map] - simp_rw [PMF.map_bind, ih] - have he : (channel lam hlam i).bind (fun j ↦ regularLaw b lam hlam ℓ (σ j)) = - (channel lam hlam (σ i)).bind (regularLaw b lam hlam ℓ) := by - rw [← channel_permute hlam σ i, PMF.bind_map] - rfl - simp_rw [he] - rfl - -def channelNoise (b : ℕ) (c : ℝ) (hc : Admissible c) : - (ℓ : ℕ) → RegularObservation b ℓ → PMF (RegularObservation b ℓ) - | 0, i => PMF.pure i - | ℓ+1, v => productPMF (fun j ↦ - (channel c hc 0).bind (fun s ↦ (channelNoise b c hc ℓ (v j)).map - (relabelRegular b (Equiv.addRight s) ℓ))) - -lemma regularLaw_noise (b : ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) - (hprod : Admissible (lam*c)) (ℓ : ℕ) (i : Spin) : - (regularLaw b lam hlam ℓ i).bind (channelNoise b c hc ℓ) = - regularLaw b (lam*c) hprod ℓ i := by - induction ℓ generalizing i with - | zero => exact PMF.pure_bind _ _ - | succ ℓ ih => - change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).bind - (fun v ↦ productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ - (channelNoise b c hc ℓ (v j)).map (relabelRegular b (Equiv.addRight s) ℓ)))) = - productPMF (fun _ : Fin b ↦ (channel (lam*c) hprod i).bind (regularLaw b (lam*c) hprod ℓ)) - rw [productPMF_bind (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ)) - (fun _ a ↦ (channel c hc 0).bind (fun s ↦ - (channelNoise b c hc ℓ a).map (relabelRegular b (Equiv.addRight s) ℓ)))] - congr 1 - funext j - rw [PMF.bind_bind] - have he (k : Spin) : (regularLaw b lam hlam ℓ k).bind (fun a ↦ (channel c hc 0).bind - (fun s ↦ (channelNoise b c hc ℓ a).map (relabelRegular b (Equiv.addRight s) ℓ))) = - (channel c hc k).bind (regularLaw b (lam*c) hprod ℓ) := by - rw [PMF.bind_comm] - simp_rw [← PMF.map_bind, ih, regularLaw_permute] - change (channel c hc 0).bind (fun s ↦ regularLaw b (lam*c) hprod ℓ (k+s)) = _ - have hm := channel_permute hc (Equiv.addLeft k) 0 - simp only [Equiv.coe_addLeft, add_zero] at hm - rw [← hm, PMF.bind_map] - rfl - simp_rw [he, ← PMF.bind_bind, channel_compose hlam hc hprod] - -end ThreeState.TreeClauses.Tree - -end - -noncomputable section -open Set MeasureTheory Filter -open scoped Topology -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive - -lemma regular_advantage_sq_moment (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) : - (advantage lam hlam (PMF.pure b) ℓ)^2 ≤ - (∫ m, xMoment m ∂(discreteProbability (regularLaw b lam hlam ℓ)).toMeasure)/2 := by - have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (fun v ↦ PMF.pure (forgetRegular b ℓ v)) - change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ - (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ))).toMeasure) ≤ _ at h - simp only [regularLaw_forget] at h - have ha := advantage_sq_bound lam hlam (PMF.pure b) ℓ - linarith - -lemma regular_channel_mu_le (b : ℕ) (lam c : ℝ) (hlam : Admissible lam) - (hc : Admissible c) (hprod : Admissible (lam*c)) (ℓ : ℕ) : - (∫ m, xMoment m ∂(discreteProbability (regularLaw b (lam*c) hprod ℓ)).toMeasure) ≤ - ∫ m, xMoment m ∂(discreteProbability (regularLaw b lam hlam ℓ)).toMeasure := by - have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (channelNoise b c hc ℓ) - simpa only [regularLaw_noise b lam c hlam hc hprod] using h - -theorem regular_positive_nonreconstruction (b : ℕ) (hb : 2 ≤ b) - (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 ≤ lam) (hKS : (b:ℝ)*lam^2 ≤ 1) : - Tendsto (advantage lam hlam (PMF.pure b)) atTop (𝓝 0) := by - have hb' : (2:ℝ) ≤ b := by exact_mod_cast hb - have hbpos : (0:ℝ) < b := by linarith - let t : ℝ := 1/Real.sqrt b - have ht : 0 < t := by dsimp [t]; exact div_pos (by norm_num) (Real.sqrt_pos.mpr hbpos) - have htsq : (b:ℝ)*t^2 = 1 := by - dsimp [t] - rw [div_pow, one_pow, Real.sq_sqrt hbpos.le, mul_one_div_cancel (ne_of_gt hbpos)] - have htone : t < 1 := by - have h := mul_le_mul_of_nonneg_right hb' (sq_nonneg t) - nlinarith - have htadm : Admissible t := ⟨by linarith, htone.le⟩ - have hlt : lam ≤ t := by - have hs : lam^2 ≤ t^2 := (mul_le_mul_iff_right₀ hbpos).mp (by nlinarith [hKS, htsq]) - nlinarith - let c := lam/t - have hcpos : 0 ≤ c := div_nonneg hl₀ ht.le - have hcone : c ≤ 1 := (div_le_one ht).2 hlt - have hcadm : Admissible c := ⟨by linarith, hcone⟩ - have he : t*c = lam := by dsimp [c]; field_simp - have hprod : Admissible (t*c) := he.symm ▸ hlam - have hm := regular_positive_critical_mu b hb ht htone htadm htsq - have hu : Tendsto (fun ℓ ↦ Real.sqrt (regularPosteriorLaw b ht.le htone ℓ).mu) atTop (𝓝 0) := by - simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm - apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam (PMF.pure b) ℓ) _ hu - intro ℓ - apply (sq_le_sq₀ (advantage_nonneg lam hlam (PMF.pure b) ℓ) (Real.sqrt_nonneg _)).mp - rw [Real.sq_sqrt (regularPosteriorLaw b ht.le htone ℓ).mu_nonneg] - have h := regular_channel_mu_le b t c htadm hcadm hprod ℓ - have hw := regular_advantage_sq_moment b lam hlam ℓ - have heq : regularLaw b (t*c) hprod ℓ = regularLaw b lam hlam ℓ := by - congr 1 - rw [heq] at h - rw [← regularPosteriorLaw_probability b ht.le htone htadm ℓ] at h - change _ ≤ (regularPosteriorLaw b ht.le htone ℓ).mu at h - linarith [(regularPosteriorLaw b ht.le htone ℓ).mu_nonneg] - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.CompactLimits +import OAI.Probability.ThreeStateClauses.PositiveFixed + +namespace OAI + +/-! Regular Critical. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory Filter +open scoped Topology +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma regular_positive_critical_mu (b : ℕ) (hb : 2 ≤ b) {lam : ℝ} + (hl₀ : 0 < lam) (hl₁ : lam < 1) (hlam : Admissible lam) (hcrit : (b:ℝ)*lam^2 = 1) : + Tendsto (fun ℓ ↦ (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by + let Q := regularPosteriorLaw b hl₀.le hl₁ + let C := fun ℓ ↦ degradationCoupling (regularLaw b lam hlam ℓ) (regularExpansion b lam hlam ℓ) + have hf (ℓ : ℕ) : (C ℓ).map Prod.fst = (Q ℓ).probability := by + rw [degradationCoupling_fst, regularPosteriorLaw_probability b hl₀.le hl₁ hlam ℓ] + have hs (ℓ : ℕ) : (C ℓ).map Prod.snd = (Q (ℓ+1)).probability := by + rw [degradationCoupling_snd] + simp only [regularLaw_degrades] + exact (regularPosteriorLaw_probability b hl₀.le hl₁ hlam (ℓ+1)).symm + have hl (ℓ : ℕ) : (∫ z, quadraticGap z ∂(C ℓ).toMeasure) = (Q ℓ).mu-(Q (ℓ+1)).mu := by + rw [degradationCoupling_loss] + simp only [regularLaw_degrades] + simp only [Q, Law.mu, regularPosteriorLaw_probability b hl₀.le hl₁ hlam] + obtain ⟨R,hR,hlim⟩ := degrading_finite_fixed_point Q C hf hs hl hl₀.le hl₁ b (fun _ ↦ rfl) + rw [regular_fixed_mu_zero R hl₀ hl₁ b hb hcrit hR] at hlim + exact hlim + +lemma regular_advantage_sq_bound (b : ℕ) {lam : ℝ} (hl₀ : 0 ≤ lam) (hl₁ : lam < 1) + (hlam : Admissible lam) (ℓ : ℕ) : + (advantage lam hlam (PMF.pure b) ℓ)^2 ≤ (regularPosteriorLaw b hl₀ hl₁ ℓ).mu/2 := by + have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (fun v ↦ PMF.pure (forgetRegular b ℓ v)) + change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ))).toMeasure) ≤ _ at h + simp only [regularLaw_forget] at h + have ha := advantage_sq_bound lam hlam (PMF.pure b) ℓ + unfold Law.mu + rw [regularPosteriorLaw_probability b hl₀ hl₁ hlam ℓ] + linarith + +theorem regular_positive_critical_nonreconstruction (b : ℕ) (hb : 2 ≤ b) + (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 < lam) (hcrit : (b:ℝ)*lam^2 = 1) : + Tendsto (advantage lam hlam (PMF.pure b)) atTop (𝓝 0) := by + have hb' : (2:ℝ) ≤ b := by exact_mod_cast hb + have hl₁ : lam < 1 := by + have h := mul_le_mul_of_nonneg_right hb' (sq_nonneg lam) + nlinarith + have hm := regular_positive_critical_mu b hb hl₀ hl₁ hlam hcrit + have hu : Tendsto (fun ℓ ↦ Real.sqrt (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu) atTop (𝓝 0) := by + simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm + apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam (PMF.pure b) ℓ) _ hu + intro ℓ + apply (sq_le_sq₀ (advantage_nonneg lam hlam (PMF.pure b) ℓ) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt (regularPosteriorLaw b hl₀.le hl₁ ℓ).mu_nonneg] + have h := regular_advantage_sq_bound b hl₀.le hl₁ hlam ℓ + linarith [(regularPosteriorLaw b hl₀.le hl₁ ℓ).mu_nonneg] + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment + +lemma channelWeight_alt (lam : ℝ) (i j : Spin) : + channelWeight lam i j = lam*(if i = j then 1 else 0)+(1-lam)/3 := by + unfold channelWeight + split_ifs <;> ring + +lemma channelWeight_compose (lam c : ℝ) (i j : Spin) : + (∑ k : Spin, channelWeight lam i k*channelWeight c k j) = channelWeight (lam*c) i j := by + classical + simp only [channelWeight_alt, add_mul, mul_add, Finset.sum_add_distrib, + ← Finset.mul_sum, mul_assoc] + by_cases h : i = j + · subst j + simp + ring + · simp [h] + ring + +lemma channel_compose {lam c : ℝ} (hlam : Admissible lam) (hc : Admissible c) + (hprod : Admissible (lam*c)) (i : Spin) : + (channel lam hlam i).bind (channel c hc) = channel (lam*c) hprod i := by + apply PMF.ext + intro j + apply (ENNReal.toReal_eq_toReal_iff' ((channel lam hlam i).bind (channel c hc) |>.apply_ne_top j) + ((channel (lam*c) hprod i).apply_ne_top j)).mp + rw [PMF.bind_apply, tsum_fintype, + ENNReal.toReal_sum (fun k _ ↦ ENNReal.mul_ne_top ((channel lam hlam i).apply_ne_top k) + ((channel c hc k).apply_ne_top j))] + simp only [ENNReal.toReal_mul, channel_real] + exact channelWeight_compose lam c i j + +lemma channel_permute {lam : ℝ} (hlam : Admissible lam) (σ : Equiv.Perm Spin) (i : Spin) : + (channel lam hlam i).map σ = channel lam hlam (σ i) := by + classical + apply PMF.ext + intro j + rw [PMF.map_apply, tsum_eq_single (σ.symm j)] + · simp only [σ.apply_symm_apply, ↓reduceIte] + change ENNReal.ofReal (channelWeight lam i (σ.symm j)) = + ENNReal.ofReal (channelWeight lam (σ i) j) + congr 1 + unfold channelWeight + simp only [Equiv.eq_symm_apply] + · intro a ha + have hne : j ≠ σ a := by + intro h + exact ha (σ.injective (h.symm.trans (σ.apply_symm_apply j).symm)) + simp only [hne, ↓reduceIte] + +def relabelRegular (b : ℕ) (σ : Equiv.Perm Spin) : (ℓ : ℕ) → RegularObservation b ℓ → RegularObservation b ℓ + | 0, i => σ i + | ℓ+1, v => fun j ↦ relabelRegular b σ ℓ (v j) + +lemma regularLaw_permute (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (σ : Equiv.Perm Spin) + (ℓ : ℕ) (i : Spin) : + (regularLaw b lam hlam ℓ i).map (relabelRegular b σ ℓ) = regularLaw b lam hlam ℓ (σ i) := by + induction ℓ generalizing i with + | zero => exact PMF.pure_bind _ _ + | succ ℓ ih => + change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).map + (fun v j ↦ relabelRegular b σ ℓ (v j)) = _ + rw [productPMF_map] + simp_rw [PMF.map_bind, ih] + have he : (channel lam hlam i).bind (fun j ↦ regularLaw b lam hlam ℓ (σ j)) = + (channel lam hlam (σ i)).bind (regularLaw b lam hlam ℓ) := by + rw [← channel_permute hlam σ i, PMF.bind_map] + rfl + simp_rw [he] + rfl + +def channelNoise (b : ℕ) (c : ℝ) (hc : Admissible c) : + (ℓ : ℕ) → RegularObservation b ℓ → PMF (RegularObservation b ℓ) + | 0, i => PMF.pure i + | ℓ+1, v => productPMF (fun j ↦ + (channel c hc 0).bind (fun s ↦ (channelNoise b c hc ℓ (v j)).map + (relabelRegular b (Equiv.addRight s) ℓ))) + +lemma regularLaw_noise (b : ℕ) (lam c : ℝ) (hlam : Admissible lam) (hc : Admissible c) + (hprod : Admissible (lam*c)) (ℓ : ℕ) (i : Spin) : + (regularLaw b lam hlam ℓ i).bind (channelNoise b c hc ℓ) = + regularLaw b (lam*c) hprod ℓ i := by + induction ℓ generalizing i with + | zero => exact PMF.pure_bind _ _ + | succ ℓ ih => + change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).bind + (fun v ↦ productPMF (fun j ↦ (channel c hc 0).bind (fun s ↦ + (channelNoise b c hc ℓ (v j)).map (relabelRegular b (Equiv.addRight s) ℓ)))) = + productPMF (fun _ : Fin b ↦ (channel (lam*c) hprod i).bind (regularLaw b (lam*c) hprod ℓ)) + rw [productPMF_bind (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ)) + (fun _ a ↦ (channel c hc 0).bind (fun s ↦ + (channelNoise b c hc ℓ a).map (relabelRegular b (Equiv.addRight s) ℓ)))] + congr 1 + funext j + rw [PMF.bind_bind] + have he (k : Spin) : (regularLaw b lam hlam ℓ k).bind (fun a ↦ (channel c hc 0).bind + (fun s ↦ (channelNoise b c hc ℓ a).map (relabelRegular b (Equiv.addRight s) ℓ))) = + (channel c hc k).bind (regularLaw b (lam*c) hprod ℓ) := by + rw [PMF.bind_comm] + simp_rw [← PMF.map_bind, ih, regularLaw_permute] + change (channel c hc 0).bind (fun s ↦ regularLaw b (lam*c) hprod ℓ (k+s)) = _ + have hm := channel_permute hc (Equiv.addLeft k) 0 + simp only [Equiv.coe_addLeft, add_zero] at hm + rw [← hm, PMF.bind_map] + rfl + simp_rw [he, ← PMF.bind_bind, channel_compose hlam hc hprod] + +end ThreeState.TreeClauses.Tree + +end + +noncomputable section +open Set MeasureTheory Filter +open scoped Topology +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment ThreeState.TreeClauses.Radial ThreeState.TreeClauses.Positive + +lemma regular_advantage_sq_moment (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) : + (advantage lam hlam (PMF.pure b) ℓ)^2 ≤ + (∫ m, xMoment m ∂(discreteProbability (regularLaw b lam hlam ℓ)).toMeasure)/2 := by + have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (fun v ↦ PMF.pure (forgetRegular b ℓ v)) + change (∫ m, xMoment m ∂(discreteProbability (fun i ↦ + (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ))).toMeasure) ≤ _ at h + simp only [regularLaw_forget] at h + have ha := advantage_sq_bound lam hlam (PMF.pure b) ℓ + linarith + +lemma regular_channel_mu_le (b : ℕ) (lam c : ℝ) (hlam : Admissible lam) + (hc : Admissible c) (hprod : Admissible (lam*c)) (ℓ : ℕ) : + (∫ m, xMoment m ∂(discreteProbability (regularLaw b (lam*c) hprod ℓ)).toMeasure) ≤ + ∫ m, xMoment m ∂(discreteProbability (regularLaw b lam hlam ℓ)).toMeasure := by + have h := discrete_degradation_mu (regularLaw b lam hlam ℓ) (channelNoise b c hc ℓ) + simpa only [regularLaw_noise b lam c hlam hc hprod] using h + +theorem regular_positive_nonreconstruction (b : ℕ) (hb : 2 ≤ b) + (lam : ℝ) (hlam : Admissible lam) (hl₀ : 0 ≤ lam) (hKS : (b:ℝ)*lam^2 ≤ 1) : + Tendsto (advantage lam hlam (PMF.pure b)) atTop (𝓝 0) := by + have hb' : (2:ℝ) ≤ b := by exact_mod_cast hb + have hbpos : (0:ℝ) < b := by linarith + let t : ℝ := 1/Real.sqrt b + have ht : 0 < t := by dsimp [t]; exact div_pos (by norm_num) (Real.sqrt_pos.mpr hbpos) + have htsq : (b:ℝ)*t^2 = 1 := by + dsimp [t] + rw [div_pow, one_pow, Real.sq_sqrt hbpos.le, mul_one_div_cancel (ne_of_gt hbpos)] + have htone : t < 1 := by + have h := mul_le_mul_of_nonneg_right hb' (sq_nonneg t) + nlinarith + have htadm : Admissible t := ⟨by linarith, htone.le⟩ + have hlt : lam ≤ t := by + have hs : lam^2 ≤ t^2 := (mul_le_mul_iff_right₀ hbpos).mp (by nlinarith [hKS, htsq]) + nlinarith + let c := lam/t + have hcpos : 0 ≤ c := div_nonneg hl₀ ht.le + have hcone : c ≤ 1 := (div_le_one ht).2 hlt + have hcadm : Admissible c := ⟨by linarith, hcone⟩ + have he : t*c = lam := by dsimp [c]; field_simp + have hprod : Admissible (t*c) := he.symm ▸ hlam + have hm := regular_positive_critical_mu b hb ht htone htadm htsq + have hu : Tendsto (fun ℓ ↦ Real.sqrt (regularPosteriorLaw b ht.le htone ℓ).mu) atTop (𝓝 0) := by + simpa only [Real.sqrt_zero, Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hm + apply squeeze_zero (fun ℓ ↦ advantage_nonneg lam hlam (PMF.pure b) ℓ) _ hu + intro ℓ + apply (sq_le_sq₀ (advantage_nonneg lam hlam (PMF.pure b) ℓ) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt (regularPosteriorLaw b ht.le htone ℓ).mu_nonneg] + have h := regular_channel_mu_le b t c htadm hcadm hprod ℓ + have hw := regular_advantage_sq_moment b lam hlam ℓ + have heq : regularLaw b (t*c) hprod ℓ = regularLaw b lam hlam ℓ := by + congr 1 + rw [heq] at h + rw [← regularPosteriorLaw_probability b ht.le htone htadm ℓ] at h + change _ ≤ (regularPosteriorLaw b ht.le htone ℓ).mu at h + linarith [(regularPosteriorLaw b ht.le htone ℓ).mu_nonneg] + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RegularLaw.lean b/lean/OAI/Probability/ThreeStateClauses/RegularLaw.lean index d280d02a48b2bc6498192277fbdf1889193fcf40..abfa01af07382a31f70668a216d208f179d8486f 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RegularLaw.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RegularLaw.lean @@ -1,114 +1,114 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.Basic -import OAI.Probability.ThreeStateClauses.PosteriorLaw -import OAI.Probability.ThreeStateClauses.Products - -namespace OAI - -/-! Regular Law. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators ENNReal -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment - -def RegularObservation (b : ℕ) : ℕ → Type - | 0 => Spin - | n+1 => Fin b → RegularObservation b n - -instance regularObservationFintype (b ℓ : ℕ) : Fintype (RegularObservation b ℓ) := by - induction ℓ with - | zero => exact inferInstanceAs (Fintype Spin) - | succ ℓ ih => letI := ih; exact inferInstanceAs (Fintype (Fin b → RegularObservation b ℓ)) - -instance regularObservationMeasurable (b : ℕ) : (ℓ : ℕ) → MeasurableSpace (RegularObservation b ℓ) - | 0 => inferInstanceAs (MeasurableSpace Spin) - | ℓ+1 => letI := regularObservationMeasurable b ℓ - inferInstanceAs (MeasurableSpace (Fin b → RegularObservation b ℓ)) -instance regularObservationSingleton (b : ℕ) : (ℓ : ℕ) → MeasurableSingletonClass (RegularObservation b ℓ) - | 0 => inferInstanceAs (MeasurableSingletonClass Spin) - | ℓ+1 => letI := regularObservationSingleton b ℓ - inferInstanceAs (MeasurableSingletonClass (Fin b → RegularObservation b ℓ)) - -instance observationCountable (ℓ : ℕ) : Countable (Observation ℓ) := by - induction ℓ with - | zero => exact inferInstanceAs (Countable Spin) - | succ ℓ ih => let := ih; exact inferInstanceAs (Countable (Multiset (Observation ℓ))) - -instance observationMeasurable (ℓ : ℕ) : MeasurableSpace (Observation ℓ) := ⊤ -instance observationSingleton (ℓ : ℕ) : MeasurableSingletonClass (Observation ℓ) := - ⟨fun _ ↦ MeasurableSpace.measurableSet_top⟩ - -def regularLaw (b : ℕ) (lam : ℝ) (hlam : Admissible lam) : - (ℓ : ℕ) → Spin → PMF (RegularObservation b ℓ) - | 0, i => PMF.pure i - | ℓ+1, i => productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ)) - -def forgetRegular (b : ℕ) : (ℓ : ℕ) → RegularObservation b ℓ → Observation ℓ - | 0, i => i - | ℓ+1, v => (List.ofFn (fun j ↦ forgetRegular b ℓ (v j)) : Multiset (Observation ℓ)) - -lemma productPMF_list {α : Type} (p : PMF α) (n : ℕ) : - (productPMF (fun _ : Fin n ↦ p)).map List.ofFn = iidList p n := by - induction n with - | zero => - have h : productPMF (fun _ : Fin 0 ↦ p) = PMF.pure (fun i : Fin 0 ↦ i.elim0) := by - apply PMF.ext - intro v - simp [PMF.pure_apply, Subsingleton.elim v (fun i : Fin 0 ↦ i.elim0)] - rw [h, PMF.pure_map] - rfl - | succ n ih => - rw [productPMF_cons, PMF.map_bind] - change (p.bind (fun a ↦ _)) = p.bind (fun a ↦ _) - congr 1 - funext a - rw [PMF.map_comp] - have he : (List.ofFn ∘ Fin.cons (n := n) (α := fun _ ↦ α) a : (Fin n → α) → List α) = List.cons a ∘ List.ofFn := by - funext v; exact List.ofFn_cons a v - rw [he, ← PMF.map_comp, ih] - -lemma regularLaw_forget (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : - (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ) = - observationLaw lam hlam (PMF.pure b) ℓ i := by - induction ℓ generalizing i with - | zero => exact PMF.map_id _ - | succ ℓ ih => - simp only [observationLaw, PMF.pure_bind] - change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).map - ((fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))) ∘ - List.ofFn ∘ (fun v j ↦ forgetRegular b ℓ (v j))) = _ - rw [← PMF.map_comp, ← PMF.map_comp, productPMF_map] - simp_rw [PMF.map_bind, ih] - rw [productPMF_list] - exact (PMF.map_id _).symm - -def regularExpansion (b : ℕ) (lam : ℝ) (hlam : Admissible lam) : - (ℓ : ℕ) → RegularObservation b ℓ → PMF (RegularObservation b (ℓ+1)) - | 0, i => productPMF (fun _ : Fin b ↦ channel lam hlam i) - | ℓ+1, v => productPMF (fun j : Fin b ↦ regularExpansion b lam hlam ℓ (v j)) - -lemma regularLaw_degrades (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : - (regularLaw b lam hlam ℓ i).bind (regularExpansion b lam hlam ℓ) = - regularLaw b lam hlam (ℓ+1) i := by - induction ℓ generalizing i with - | zero => - change (PMF.pure i).bind (fun j ↦ productPMF (fun _ : Fin b ↦ channel lam hlam j)) = - productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind PMF.pure) - rw [PMF.pure_bind, PMF.bind_pure] - | succ ℓ ih => - change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).bind - (fun v ↦ productPMF (fun j ↦ regularExpansion b lam hlam ℓ (v j))) = _ - rw [productPMF_bind] - simp only [PMF.bind_bind] - simp_rw [ih] - rfl - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.Basic +import OAI.Probability.ThreeStateClauses.PosteriorLaw +import OAI.Probability.ThreeStateClauses.Products + +namespace OAI + +/-! Regular Law. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators ENNReal +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment + +def RegularObservation (b : ℕ) : ℕ → Type + | 0 => Spin + | n+1 => Fin b → RegularObservation b n + +instance regularObservationFintype (b ℓ : ℕ) : Fintype (RegularObservation b ℓ) := by + induction ℓ with + | zero => exact inferInstanceAs (Fintype Spin) + | succ ℓ ih => letI := ih; exact inferInstanceAs (Fintype (Fin b → RegularObservation b ℓ)) + +instance regularObservationMeasurable (b : ℕ) : (ℓ : ℕ) → MeasurableSpace (RegularObservation b ℓ) + | 0 => inferInstanceAs (MeasurableSpace Spin) + | ℓ+1 => letI := regularObservationMeasurable b ℓ + inferInstanceAs (MeasurableSpace (Fin b → RegularObservation b ℓ)) +instance regularObservationSingleton (b : ℕ) : (ℓ : ℕ) → MeasurableSingletonClass (RegularObservation b ℓ) + | 0 => inferInstanceAs (MeasurableSingletonClass Spin) + | ℓ+1 => letI := regularObservationSingleton b ℓ + inferInstanceAs (MeasurableSingletonClass (Fin b → RegularObservation b ℓ)) + +instance observationCountable (ℓ : ℕ) : Countable (Observation ℓ) := by + induction ℓ with + | zero => exact inferInstanceAs (Countable Spin) + | succ ℓ ih => let := ih; exact inferInstanceAs (Countable (Multiset (Observation ℓ))) + +instance observationMeasurable (ℓ : ℕ) : MeasurableSpace (Observation ℓ) := ⊤ +instance observationSingleton (ℓ : ℕ) : MeasurableSingletonClass (Observation ℓ) := + ⟨fun _ ↦ MeasurableSpace.measurableSet_top⟩ + +def regularLaw (b : ℕ) (lam : ℝ) (hlam : Admissible lam) : + (ℓ : ℕ) → Spin → PMF (RegularObservation b ℓ) + | 0, i => PMF.pure i + | ℓ+1, i => productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ)) + +def forgetRegular (b : ℕ) : (ℓ : ℕ) → RegularObservation b ℓ → Observation ℓ + | 0, i => i + | ℓ+1, v => (List.ofFn (fun j ↦ forgetRegular b ℓ (v j)) : Multiset (Observation ℓ)) + +lemma productPMF_list {α : Type} (p : PMF α) (n : ℕ) : + (productPMF (fun _ : Fin n ↦ p)).map List.ofFn = iidList p n := by + induction n with + | zero => + have h : productPMF (fun _ : Fin 0 ↦ p) = PMF.pure (fun i : Fin 0 ↦ i.elim0) := by + apply PMF.ext + intro v + simp [PMF.pure_apply, Subsingleton.elim v (fun i : Fin 0 ↦ i.elim0)] + rw [h, PMF.pure_map] + rfl + | succ n ih => + rw [productPMF_cons, PMF.map_bind] + change (p.bind (fun a ↦ _)) = p.bind (fun a ↦ _) + congr 1 + funext a + rw [PMF.map_comp] + have he : (List.ofFn ∘ Fin.cons (n := n) (α := fun _ ↦ α) a : (Fin n → α) → List α) = List.cons a ∘ List.ofFn := by + funext v; exact List.ofFn_cons a v + rw [he, ← PMF.map_comp, ih] + +lemma regularLaw_forget (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : + (regularLaw b lam hlam ℓ i).map (forgetRegular b ℓ) = + observationLaw lam hlam (PMF.pure b) ℓ i := by + induction ℓ generalizing i with + | zero => exact PMF.map_id _ + | succ ℓ ih => + simp only [observationLaw, PMF.pure_bind] + change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).map + ((fun xs : List (Observation ℓ) ↦ (xs : Multiset (Observation ℓ))) ∘ + List.ofFn ∘ (fun v j ↦ forgetRegular b ℓ (v j))) = _ + rw [← PMF.map_comp, ← PMF.map_comp, productPMF_map] + simp_rw [PMF.map_bind, ih] + rw [productPMF_list] + exact (PMF.map_id _).symm + +def regularExpansion (b : ℕ) (lam : ℝ) (hlam : Admissible lam) : + (ℓ : ℕ) → RegularObservation b ℓ → PMF (RegularObservation b (ℓ+1)) + | 0, i => productPMF (fun _ : Fin b ↦ channel lam hlam i) + | ℓ+1, v => productPMF (fun j : Fin b ↦ regularExpansion b lam hlam ℓ (v j)) + +lemma regularLaw_degrades (b : ℕ) (lam : ℝ) (hlam : Admissible lam) (ℓ : ℕ) (i : Spin) : + (regularLaw b lam hlam ℓ i).bind (regularExpansion b lam hlam ℓ) = + regularLaw b lam hlam (ℓ+1) i := by + induction ℓ generalizing i with + | zero => + change (PMF.pure i).bind (fun j ↦ productPMF (fun _ : Fin b ↦ channel lam hlam j)) = + productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind PMF.pure) + rw [PMF.pure_bind, PMF.bind_pure] + | succ ℓ ih => + change (productPMF (fun _ : Fin b ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).bind + (fun v ↦ productPMF (fun j ↦ regularExpansion b lam hlam ℓ (v j))) = _ + rw [productPMF_bind] + simp only [PMF.bind_bind] + simp_rw [ih] + rfl + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RegularReconstruction.lean b/lean/OAI/Probability/ThreeStateClauses/RegularReconstruction.lean index c73846b4cb98c84bec6e75dd79f1fc2430249575..7105569e95c30848214c890091bce4a7f23782cc 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RegularReconstruction.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RegularReconstruction.lean @@ -1,114 +1,114 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RegularStatistics -import OAI.Probability.ThreeStateClauses.InformationLoss - -namespace OAI - -/-! Regular Reconstruction. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory Filter -open scoped BigOperators Topology -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment - -def ksConstant (b : ℕ) (lam : ℝ) : ℝ := 4*((b:ℝ)*lam^2)/((b:ℝ)*lam^2-1) - -lemma ksConstant_pos {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : 0 < ksConstant b lam := by - unfold ksConstant; positivity - -lemma ksConstant_ge_four {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : 4 ≤ ksConstant b lam := by - rw [ksConstant, le_div_iff₀ (by linarith)] - linarith - -lemma ksConstant_identity {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : - ksConstant b lam*((b:ℝ)*lam^2-1) = 4*((b:ℝ)*lam^2) := by - rw [ksConstant, div_mul_cancel₀ _ (by linarith)] - -lemma regularStatistic_second (b : ℕ) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (b:ℝ)*lam^2) (ℓ : ℕ) (i : Spin) : - (∫ v, regularStatistic b lam ℓ v^2 ∂(regularLaw b lam hlam ℓ i).toMeasure) ≤ ksConstant b lam := by - have hb : 0 < b := by - by_contra h - have hb0 : b = 0 := by omega - norm_num [hb0] at hKS - have hb' : (0:ℝ) < b := Nat.cast_pos.mpr hb - have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS - have hden : 0 < ((b:ℝ)*lam)^2 := sq_pos_of_ne_zero (mul_ne_zero (ne_of_gt hb') hl) - have hC := ksConstant_pos hKS - induction ℓ generalizing i with - | zero => - change (∫ v : Spin, spinScore v^2 ∂(PMF.pure i).toMeasure) ≤ _ - rw [PMF.toMeasure_pure, integral_dirac] - exact (spinScore_square i).trans (ksConstant_ge_four hKS) - | succ ℓ ih => - have hmean : (∫ v, regularStatistic b lam ℓ v - ∂((channel lam hlam i).bind (regularLaw b lam hlam ℓ)).toMeasure) = lam*spinScore i := by - rw [integral_pmf_bind_finite] - simp_rw [regularStatistic_mean b hb lam hlam hl ℓ] - exact channel_spinScore lam hlam i - have hsecond : (∫ v, regularStatistic b lam ℓ v^2 - ∂((channel lam hlam i).bind (regularLaw b lam hlam ℓ)).toMeasure) ≤ ksConstant b lam := by - rw [integral_pmf_bind_finite] - exact (integral_mono Integrable.of_finite (integrable_const _) (ih)).trans_eq (by simp) - change (∫ v : Fin b → RegularObservation b ℓ, - ((∑ j, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam))^2 - ∂(productPMF (fun _ ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).toMeasure) ≤ _ - simp_rw [div_pow] - rw [integral_div, integral_product_sq_sum, hmean] - apply (div_le_iff₀ hden).2 - have hb1 : (1:ℝ) ≤ b := by exact_mod_cast hb - have hn : 0 ≤ (b:ℝ)^2-b := by nlinarith - have hs := mul_le_mul_of_nonneg_left (spinScore_square i) (sq_nonneg lam) - have hp := mul_le_mul_of_nonneg_left hs hn - have hi := congrArg (fun x : ℝ ↦ x*(b:ℝ)) (ksConstant_identity hKS) - have hm := mul_le_mul_of_nonneg_left hsecond hb'.le - nlinarith [mul_nonneg hb'.le (sq_nonneg lam)] - -lemma regular_estimator_advantage (b : ℕ) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (b:ℝ)*lam^2) (ℓ : ℕ) : - 1/(3*ksConstant b lam) ≤ advantage lam hlam (PMF.pure b) ℓ := by - have hb : 0 < b := by - by_contra h - have hb0 : b = 0 := by omega - norm_num [hb0] at hKS - have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS - let p := observationLaw lam hlam (PMF.pure b) ℓ - let f := observedRegularStatistic b lam ℓ - obtain ⟨B,hB0,hB⟩ := observedRegularStatistic_bound b lam ℓ - have hmean (i : Spin) : (∫ o, f o ∂(p i).toMeasure) = spinScore i := by - dsimp [p, f] - rw [← regularLaw_forget b lam hlam ℓ i, integral_pmf_map] - simp_rw [observedRegularStatistic_forget] - exact regularStatistic_mean b hb lam hlam hl ℓ i - have hsecond (i : Spin) : (∫ o, f o^2 ∂(p i).toMeasure) ≤ ksConstant b lam := by - dsimp [p, f] - rw [← regularLaw_forget b lam hlam ℓ i, integral_pmf_map] - simp_rw [observedRegularStatistic_forget] - exact regularStatistic_second b lam hlam hKS ℓ i - rw [advantage_eq_integral] - apply estimator_tv_lower (p := p) hB (ksConstant_pos hKS) - · rw [integral_discreteMarginal p hB, hmean 0, hmean 1, hmean 2] - norm_num [spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] - · exact hmean 0 - · have hB₂ (o : Observation ℓ) : |f o^2| ≤ B^2 := by - rw [abs_of_nonneg (sq_nonneg _)] - have hh : |f o| ≤ B := hB o - nlinarith [hh, sq_abs (f o), abs_nonneg (f o)] - rw [integral_discreteMarginal p hB₂] - linarith [hsecond 0, hsecond 1, hsecond 2] - -theorem regular_reconstructs_above_KS (b : ℕ) (lam : ℝ) (hlam : Admissible lam) - (hKS : 1 < (b:ℝ)*lam^2) : Reconstructs lam hlam (PMF.pure b) := by - refine ⟨⨅ ℓ, advantage lam hlam (PMF.pure b) ℓ, ?_, advantage_tendsto _ _ _⟩ - have he : 1/(3*ksConstant b lam) ≤ ⨅ ℓ, advantage lam hlam (PMF.pure b) ℓ := by - exact le_ciInf (fun ℓ ↦ regular_estimator_advantage b lam hlam hKS ℓ) - exact (div_pos (by norm_num) (mul_pos (by norm_num) (ksConstant_pos hKS))).trans_le he - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RegularStatistics +import OAI.Probability.ThreeStateClauses.InformationLoss + +namespace OAI + +/-! Regular Reconstruction. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory Filter +open scoped BigOperators Topology +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment + +def ksConstant (b : ℕ) (lam : ℝ) : ℝ := 4*((b:ℝ)*lam^2)/((b:ℝ)*lam^2-1) + +lemma ksConstant_pos {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : 0 < ksConstant b lam := by + unfold ksConstant; positivity + +lemma ksConstant_ge_four {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : 4 ≤ ksConstant b lam := by + rw [ksConstant, le_div_iff₀ (by linarith)] + linarith + +lemma ksConstant_identity {b : ℕ} {lam : ℝ} (hKS : 1 < (b:ℝ)*lam^2) : + ksConstant b lam*((b:ℝ)*lam^2-1) = 4*((b:ℝ)*lam^2) := by + rw [ksConstant, div_mul_cancel₀ _ (by linarith)] + +lemma regularStatistic_second (b : ℕ) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (b:ℝ)*lam^2) (ℓ : ℕ) (i : Spin) : + (∫ v, regularStatistic b lam ℓ v^2 ∂(regularLaw b lam hlam ℓ i).toMeasure) ≤ ksConstant b lam := by + have hb : 0 < b := by + by_contra h + have hb0 : b = 0 := by omega + norm_num [hb0] at hKS + have hb' : (0:ℝ) < b := Nat.cast_pos.mpr hb + have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS + have hden : 0 < ((b:ℝ)*lam)^2 := sq_pos_of_ne_zero (mul_ne_zero (ne_of_gt hb') hl) + have hC := ksConstant_pos hKS + induction ℓ generalizing i with + | zero => + change (∫ v : Spin, spinScore v^2 ∂(PMF.pure i).toMeasure) ≤ _ + rw [PMF.toMeasure_pure, integral_dirac] + exact (spinScore_square i).trans (ksConstant_ge_four hKS) + | succ ℓ ih => + have hmean : (∫ v, regularStatistic b lam ℓ v + ∂((channel lam hlam i).bind (regularLaw b lam hlam ℓ)).toMeasure) = lam*spinScore i := by + rw [integral_pmf_bind_finite] + simp_rw [regularStatistic_mean b hb lam hlam hl ℓ] + exact channel_spinScore lam hlam i + have hsecond : (∫ v, regularStatistic b lam ℓ v^2 + ∂((channel lam hlam i).bind (regularLaw b lam hlam ℓ)).toMeasure) ≤ ksConstant b lam := by + rw [integral_pmf_bind_finite] + exact (integral_mono Integrable.of_finite (integrable_const _) (ih)).trans_eq (by simp) + change (∫ v : Fin b → RegularObservation b ℓ, + ((∑ j, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam))^2 + ∂(productPMF (fun _ ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).toMeasure) ≤ _ + simp_rw [div_pow] + rw [integral_div, integral_product_sq_sum, hmean] + apply (div_le_iff₀ hden).2 + have hb1 : (1:ℝ) ≤ b := by exact_mod_cast hb + have hn : 0 ≤ (b:ℝ)^2-b := by nlinarith + have hs := mul_le_mul_of_nonneg_left (spinScore_square i) (sq_nonneg lam) + have hp := mul_le_mul_of_nonneg_left hs hn + have hi := congrArg (fun x : ℝ ↦ x*(b:ℝ)) (ksConstant_identity hKS) + have hm := mul_le_mul_of_nonneg_left hsecond hb'.le + nlinarith [mul_nonneg hb'.le (sq_nonneg lam)] + +lemma regular_estimator_advantage (b : ℕ) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (b:ℝ)*lam^2) (ℓ : ℕ) : + 1/(3*ksConstant b lam) ≤ advantage lam hlam (PMF.pure b) ℓ := by + have hb : 0 < b := by + by_contra h + have hb0 : b = 0 := by omega + norm_num [hb0] at hKS + have hl : lam ≠ 0 := by intro h; norm_num [h] at hKS + let p := observationLaw lam hlam (PMF.pure b) ℓ + let f := observedRegularStatistic b lam ℓ + obtain ⟨B,hB0,hB⟩ := observedRegularStatistic_bound b lam ℓ + have hmean (i : Spin) : (∫ o, f o ∂(p i).toMeasure) = spinScore i := by + dsimp [p, f] + rw [← regularLaw_forget b lam hlam ℓ i, integral_pmf_map] + simp_rw [observedRegularStatistic_forget] + exact regularStatistic_mean b hb lam hlam hl ℓ i + have hsecond (i : Spin) : (∫ o, f o^2 ∂(p i).toMeasure) ≤ ksConstant b lam := by + dsimp [p, f] + rw [← regularLaw_forget b lam hlam ℓ i, integral_pmf_map] + simp_rw [observedRegularStatistic_forget] + exact regularStatistic_second b lam hlam hKS ℓ i + rw [advantage_eq_integral] + apply estimator_tv_lower (p := p) hB (ksConstant_pos hKS) + · rw [integral_discreteMarginal p hB, hmean 0, hmean 1, hmean 2] + norm_num [spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] + · exact hmean 0 + · have hB₂ (o : Observation ℓ) : |f o^2| ≤ B^2 := by + rw [abs_of_nonneg (sq_nonneg _)] + have hh : |f o| ≤ B := hB o + nlinarith [hh, sq_abs (f o), abs_nonneg (f o)] + rw [integral_discreteMarginal p hB₂] + linarith [hsecond 0, hsecond 1, hsecond 2] + +theorem regular_reconstructs_above_KS (b : ℕ) (lam : ℝ) (hlam : Admissible lam) + (hKS : 1 < (b:ℝ)*lam^2) : Reconstructs lam hlam (PMF.pure b) := by + refine ⟨⨅ ℓ, advantage lam hlam (PMF.pure b) ℓ, ?_, advantage_tendsto _ _ _⟩ + have he : 1/(3*ksConstant b lam) ≤ ⨅ ℓ, advantage lam hlam (PMF.pure b) ℓ := by + exact le_ciInf (fun ℓ ↦ regular_estimator_advantage b lam hlam hKS ℓ) + exact (div_pos (by norm_num) (mul_pos (by norm_num) (ksConstant_pos hKS))).trans_le he + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/RegularStatistics.lean b/lean/OAI/Probability/ThreeStateClauses/RegularStatistics.lean index 3175a4b149578ef99d802ffa0c57d21cc727e490..0603ffa833ff4ea6c270984c5efd433ae1681f12 100644 --- a/lean/OAI/Probability/ThreeStateClauses/RegularStatistics.lean +++ b/lean/OAI/Probability/ThreeStateClauses/RegularStatistics.lean @@ -1,132 +1,132 @@ -import Mathlib -import OAI.Probability.ThreeStateClauses.RegularCritical - -namespace OAI - -/-! Regular Statistics. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Experiment - -variable {α β : Type*} [Fintype α] [MeasurableSpace α] [MeasurableSingletonClass α] - [Fintype β] [MeasurableSpace β] [MeasurableSingletonClass β] - -omit [MeasurableSpace α] [MeasurableSingletonClass α] in -lemma finite_abs_bound (f : α → ℝ) : ∃ C : ℝ, ∀ a, |f a| ≤ C := by - obtain ⟨C,hC⟩ := (Set.finite_range (fun a ↦ |f a|)).bddAbove - exact ⟨C, fun a ↦ hC ⟨a,rfl⟩⟩ - -lemma integral_pmf_bind_finite (p : PMF α) (K : α → PMF β) (f : β → ℝ) : - (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by - obtain ⟨C,hC⟩ := finite_abs_bound f - exact integral_pmf_bind p K hC - -lemma integral_product_sum (p : PMF α) (f : α → ℝ) (n : ℕ) : - (∫ v : Fin n → α, (∑ j, f (v j)) ∂(productPMF (fun _ ↦ p)).toMeasure) = - (n:ℝ)*(∫ a, f a ∂p.toMeasure) := by - rw [productPMF_measure] - simpa [weightProduct] using integral_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) Integrable.of_finite (by simp) - -lemma integral_product_sq_sum (p : PMF α) (f : α → ℝ) (n : ℕ) : - (∫ v : Fin n → α, (∑ j, f (v j))^2 ∂(productPMF (fun _ ↦ p)).toMeasure) = - (n:ℝ)*(∫ a, f a^2 ∂p.toMeasure)+((n:ℝ)^2-n)*(∫ a, f a ∂p.toMeasure)^2 := by - rw [productPMF_measure] - simpa [weightProduct] using integral_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) - (u := f) (integrable_const 1) Integrable.of_finite Integrable.of_finite (by simp) - -end ThreeState.TreeClauses.Experiment - -end - -noncomputable section -open Set MeasureTheory -open scoped BigOperators -namespace ThreeState.TreeClauses.Tree -open ThreeState.TreeClauses.Experiment - -def spinScore (i : Spin) : ℝ := if i=0 then 2 else -1 - -lemma spinScore_abs (i : Spin) : |spinScore i| ≤ 2 := by - unfold spinScore; split_ifs <;> norm_num - -lemma spinScore_square (i : Spin) : spinScore i^2 ≤ 4 := by - unfold spinScore; split_ifs <;> norm_num - -lemma channel_spinScore (lam : ℝ) (hlam : Admissible lam) (i : Spin) : - (∫ j, spinScore j ∂(channel lam hlam i).toMeasure) = lam*spinScore i := by - rw [PMF.integral_eq_sum] - have he (j : Spin) : (channel lam hlam i j).toReal = channelWeight lam i j := - ENNReal.toReal_ofReal (channelWeight_nonneg hlam i j) - simp only [smul_eq_mul, he] - simp_rw [channelWeight_alt, add_mul, Finset.sum_add_distrib] - have hs : ∑ j : Spin, spinScore j = 0 := by - norm_num [Fin.sum_univ_three, spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] - simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul, Finset.sum_ite_eq, - Finset.mem_univ, ite_true, ← Finset.mul_sum, hs, mul_zero, add_zero] - -def regularStatistic (b : ℕ) (lam : ℝ) : (ℓ : ℕ) → RegularObservation b ℓ → ℝ - | 0, i => spinScore i - | ℓ+1, v => (∑ j : Fin b, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam) - -def observedRegularStatistic (b : ℕ) (lam : ℝ) : (ℓ : ℕ) → Observation ℓ → ℝ - | 0, i => spinScore i - | ℓ+1, s => if s.card = b then (s.map (observedRegularStatistic b lam ℓ)).sum/((b:ℝ)*lam) else 0 - -lemma abs_multiset_sum_bound {α : Type*} (f : α → ℝ) (C : ℝ) (hf : ∀ a, |f a| ≤ C) - (s : Multiset α) : |(s.map f).sum| ≤ (s.card:ℝ)*C := by - induction s using Multiset.induction_on with - | empty => simp - | @cons a s ih => - simp only [Multiset.map_cons, Multiset.sum_cons, Multiset.card_cons, Nat.cast_add, Nat.cast_one] - exact (abs_add_le _ _).trans (by linarith [hf a]) - -lemma observedRegularStatistic_bound (b : ℕ) (lam : ℝ) (ℓ : ℕ) : - ∃ C : ℝ, 0 ≤ C ∧ ∀ o, |observedRegularStatistic b lam ℓ o| ≤ C := by - induction ℓ with - | zero => exact ⟨2, by norm_num, spinScore_abs⟩ - | succ ℓ ih => - obtain ⟨C,hC,hbound⟩ := ih - refine ⟨(b:ℝ)*C/|((b:ℝ)*lam)|, by positivity, ?_⟩ - intro s - change |if s.card=b then _ else 0| ≤ _ - split_ifs with h - · rw [abs_div] - exact div_le_div_of_nonneg_right (by simpa only [h] using abs_multiset_sum_bound _ C hbound s) (abs_nonneg _) - · simp only [abs_zero]; positivity - -lemma observedRegularStatistic_forget (b : ℕ) (lam : ℝ) (ℓ : ℕ) - (v : RegularObservation b ℓ) : - observedRegularStatistic b lam ℓ (forgetRegular b ℓ v) = regularStatistic b lam ℓ v := by - induction ℓ with - | zero => rfl - | succ ℓ ih => - simp only [forgetRegular, observedRegularStatistic, Multiset.coe_card, List.length_ofFn, ite_true, regularStatistic] - congr 1 - simp only [Multiset.map_coe, Multiset.sum_coe, List.map_ofFn, Function.comp_def, ih, List.sum_ofFn] - -lemma regularStatistic_mean (b : ℕ) (hb : 0 < b) (lam : ℝ) (hlam : Admissible lam) - (hl : lam ≠ 0) (ℓ : ℕ) (i : Spin) : - (∫ v, regularStatistic b lam ℓ v ∂(regularLaw b lam hlam ℓ i).toMeasure) = spinScore i := by - have hb' : (b:ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hb) - induction ℓ generalizing i with - | zero => - change (∫ v : Spin, spinScore v ∂(PMF.pure i).toMeasure) = spinScore i - rw [PMF.toMeasure_pure, integral_dirac] - | succ ℓ ih => - change (∫ v, (∑ j : Fin b, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam) - ∂(productPMF (fun _ ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).toMeasure) = _ - rw [integral_div, integral_product_sum, integral_pmf_bind_finite] - simp_rw [ih] - rw [channel_spinScore] - field_simp - -end ThreeState.TreeClauses.Tree - -end - -end OAI +import Mathlib +import OAI.Probability.ThreeStateClauses.RegularCritical + +namespace OAI + +/-! Regular Statistics. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Experiment + +variable {α β : Type*} [Fintype α] [MeasurableSpace α] [MeasurableSingletonClass α] + [Fintype β] [MeasurableSpace β] [MeasurableSingletonClass β] + +omit [MeasurableSpace α] [MeasurableSingletonClass α] in +lemma finite_abs_bound (f : α → ℝ) : ∃ C : ℝ, ∀ a, |f a| ≤ C := by + obtain ⟨C,hC⟩ := (Set.finite_range (fun a ↦ |f a|)).bddAbove + exact ⟨C, fun a ↦ hC ⟨a,rfl⟩⟩ + +lemma integral_pmf_bind_finite (p : PMF α) (K : α → PMF β) (f : β → ℝ) : + (∫ b, f b ∂(p.bind K).toMeasure) = ∫ a, (∫ b, f b ∂(K a).toMeasure) ∂p.toMeasure := by + obtain ⟨C,hC⟩ := finite_abs_bound f + exact integral_pmf_bind p K hC + +lemma integral_product_sum (p : PMF α) (f : α → ℝ) (n : ℕ) : + (∫ v : Fin n → α, (∑ j, f (v j)) ∂(productPMF (fun _ ↦ p)).toMeasure) = + (n:ℝ)*(∫ a, f a ∂p.toMeasure) := by + rw [productPMF_measure] + simpa [weightProduct] using integral_weighted_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) Integrable.of_finite (by simp) + +lemma integral_product_sq_sum (p : PMF α) (f : α → ℝ) (n : ℕ) : + (∫ v : Fin n → α, (∑ j, f (v j))^2 ∂(productPMF (fun _ ↦ p)).toMeasure) = + (n:ℝ)*(∫ a, f a^2 ∂p.toMeasure)+((n:ℝ)^2-n)*(∫ a, f a ∂p.toMeasure)^2 := by + rw [productPMF_measure] + simpa [weightProduct] using integral_weighted_sq_sum (ι := Fin n) (a := fun _ : α ↦ (1:ℝ)) + (u := f) (integrable_const 1) Integrable.of_finite Integrable.of_finite (by simp) + +end ThreeState.TreeClauses.Experiment + +end + +noncomputable section +open Set MeasureTheory +open scoped BigOperators +namespace ThreeState.TreeClauses.Tree +open ThreeState.TreeClauses.Experiment + +def spinScore (i : Spin) : ℝ := if i=0 then 2 else -1 + +lemma spinScore_abs (i : Spin) : |spinScore i| ≤ 2 := by + unfold spinScore; split_ifs <;> norm_num + +lemma spinScore_square (i : Spin) : spinScore i^2 ≤ 4 := by + unfold spinScore; split_ifs <;> norm_num + +lemma channel_spinScore (lam : ℝ) (hlam : Admissible lam) (i : Spin) : + (∫ j, spinScore j ∂(channel lam hlam i).toMeasure) = lam*spinScore i := by + rw [PMF.integral_eq_sum] + have he (j : Spin) : (channel lam hlam i j).toReal = channelWeight lam i j := + ENNReal.toReal_ofReal (channelWeight_nonneg hlam i j) + simp only [smul_eq_mul, he] + simp_rw [channelWeight_alt, add_mul, Finset.sum_add_distrib] + have hs : ∑ j : Spin, spinScore j = 0 := by + norm_num [Fin.sum_univ_three, spinScore, show (1:Spin) ≠ 0 by decide, show (2:Spin) ≠ 0 by decide] + simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul, Finset.sum_ite_eq, + Finset.mem_univ, ite_true, ← Finset.mul_sum, hs, mul_zero, add_zero] + +def regularStatistic (b : ℕ) (lam : ℝ) : (ℓ : ℕ) → RegularObservation b ℓ → ℝ + | 0, i => spinScore i + | ℓ+1, v => (∑ j : Fin b, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam) + +def observedRegularStatistic (b : ℕ) (lam : ℝ) : (ℓ : ℕ) → Observation ℓ → ℝ + | 0, i => spinScore i + | ℓ+1, s => if s.card = b then (s.map (observedRegularStatistic b lam ℓ)).sum/((b:ℝ)*lam) else 0 + +lemma abs_multiset_sum_bound {α : Type*} (f : α → ℝ) (C : ℝ) (hf : ∀ a, |f a| ≤ C) + (s : Multiset α) : |(s.map f).sum| ≤ (s.card:ℝ)*C := by + induction s using Multiset.induction_on with + | empty => simp + | @cons a s ih => + simp only [Multiset.map_cons, Multiset.sum_cons, Multiset.card_cons, Nat.cast_add, Nat.cast_one] + exact (abs_add_le _ _).trans (by linarith [hf a]) + +lemma observedRegularStatistic_bound (b : ℕ) (lam : ℝ) (ℓ : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ o, |observedRegularStatistic b lam ℓ o| ≤ C := by + induction ℓ with + | zero => exact ⟨2, by norm_num, spinScore_abs⟩ + | succ ℓ ih => + obtain ⟨C,hC,hbound⟩ := ih + refine ⟨(b:ℝ)*C/|((b:ℝ)*lam)|, by positivity, ?_⟩ + intro s + change |if s.card=b then _ else 0| ≤ _ + split_ifs with h + · rw [abs_div] + exact div_le_div_of_nonneg_right (by simpa only [h] using abs_multiset_sum_bound _ C hbound s) (abs_nonneg _) + · simp only [abs_zero]; positivity + +lemma observedRegularStatistic_forget (b : ℕ) (lam : ℝ) (ℓ : ℕ) + (v : RegularObservation b ℓ) : + observedRegularStatistic b lam ℓ (forgetRegular b ℓ v) = regularStatistic b lam ℓ v := by + induction ℓ with + | zero => rfl + | succ ℓ ih => + simp only [forgetRegular, observedRegularStatistic, Multiset.coe_card, List.length_ofFn, ite_true, regularStatistic] + congr 1 + simp only [Multiset.map_coe, Multiset.sum_coe, List.map_ofFn, Function.comp_def, ih, List.sum_ofFn] + +lemma regularStatistic_mean (b : ℕ) (hb : 0 < b) (lam : ℝ) (hlam : Admissible lam) + (hl : lam ≠ 0) (ℓ : ℕ) (i : Spin) : + (∫ v, regularStatistic b lam ℓ v ∂(regularLaw b lam hlam ℓ i).toMeasure) = spinScore i := by + have hb' : (b:ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hb) + induction ℓ generalizing i with + | zero => + change (∫ v : Spin, spinScore v ∂(PMF.pure i).toMeasure) = spinScore i + rw [PMF.toMeasure_pure, integral_dirac] + | succ ℓ ih => + change (∫ v, (∑ j : Fin b, regularStatistic b lam ℓ (v j))/((b:ℝ)*lam) + ∂(productPMF (fun _ ↦ (channel lam hlam i).bind (regularLaw b lam hlam ℓ))).toMeasure) = _ + rw [integral_div, integral_product_sum, integral_pmf_bind_finite] + simp_rw [ih] + rw [channel_spinScore] + field_simp + +end ThreeState.TreeClauses.Tree + +end + +end OAI diff --git a/lean/OAI/Probability/ThreeStateClauses/ScalarBounds.lean b/lean/OAI/Probability/ThreeStateClauses/ScalarBounds.lean index 0bb2d75eeb42cadaead99fb26dea345f2831931b..13d53e3b413e9181d3a5ca411e402814ae1bae65 100644 --- a/lean/OAI/Probability/ThreeStateClauses/ScalarBounds.lean +++ b/lean/OAI/Probability/ThreeStateClauses/ScalarBounds.lean @@ -1,115 +1,115 @@ -import Mathlib - -namespace OAI - -/-! Scalar Bounds. -/ - -open scoped BigOperators ENNReal NNReal Topology -open Filter -noncomputable section -namespace ThreeState.TreeClauses.Positive - -def cLower (lam : ℝ) : ℝ := (37/27)*(1+2*lam/3) -def scalarT (lam mu s : ℝ) : ℝ := - (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+(17*lam*mu)/(25*s) - -lemma cLower_pos {lam : ℝ} (hl : 0 ≤ lam) : 0 < cLower lam := by - dsimp [cLower]; positivity - -lemma small_polynomial {lam : ℝ} (h₀ : 0 ≤ lam) (h₁ : lam ≤ 3/10) : - (2/5-lam^2/2)*cLower lam^2 > (2/3)*(11/10+lam^2/2) := by - let u := (10/3)*lam - have hu₀ : 0 ≤ u := by dsimp [u]; positivity - have hu₁ : u ≤ 1 := by dsimp [u]; linarith - have heq : (2/5-lam^2/2)*cLower lam^2-(2/3)*(11/10+lam^2/2) = - (65000*(1-u)^4+1355200*u*(1-u)^3+3367745*u^2*(1-u)^2+ - 2806680*u^3*(1-u)+716814*u^4)/3645000 := by dsimp [u, cLower]; ring - have hp : 0 < (2/5-lam^2/2)*cLower lam^2-(2/3)*(11/10+lam^2/2) := by - rw [heq] - rcases lt_or_eq_of_le hu₁ with h | h - · have : 0 < 1-u := sub_pos.mpr h - positivity - · rw [h]; norm_num - linarith - -lemma middle_polynomial {lam : ℝ} (h₀ : 3/10 ≤ lam) (h₁ : lam ≤ 71/100) : - (2/5-lam^2/2)*cLower lam^2 > 1-17*lam/25 := by - let u := (100/41)*(lam-3/10) - have hu₀ : 0 ≤ u := by dsimp [u]; positivity - have hu₁ : u ≤ 1 := by dsimp [u]; linarith - have heq : (2/5-lam^2/2)*cLower lam^2-(1-17*lam/25) = - (53796960000*(1-u)^4+340999128000*u*(1-u)^3+592285169900*u^2*(1-u)^2+ - 337132599220*u^3*(1-u)+28181130511*u^4)/328050000000 := by dsimp [u, cLower]; ring - have hp : 0 < (2/5-lam^2/2)*cLower lam^2-(1-17*lam/25) := by - rw [heq] - rcases lt_or_eq_of_le hu₁ with h | h - · have : 0 < 1-u := sub_pos.mpr h - positivity - · rw [h]; norm_num - linarith - -lemma large_polynomial {lam : ℝ} (h : 7/10 ≤ lam) : - (3/20)*cLower lam^2 > 1-17*lam/25 := by - have heq : (3/20)*cLower lam^2-(1-17*lam/25) = - 44801/546750+(67297/54675)*(lam-7/10)+(1369/10935)*(lam-7/10)^2 := by - dsimp [cLower]; ring - have hpos : 0 < (3/20)*cLower lam^2-(1-17*lam/25) := by - rw [heq]; positivity - linarith - -lemma substitute_moment_region {C B D mu : ℝ} (hC : 0 < C) (hD : 0 ≤ D) - (hmu : mu*C^2 ≤ 1) (hBD : D < B*C^2) : D*mu < B := by - have h := mul_le_mul_of_nonneg_left hmu hD - have hprod : (D*mu)*C^2 < B*C^2 := by nlinarith - exact (mul_lt_mul_iff_left₀ (sq_pos_of_pos hC)).mp hprod - -lemma reciprocal_lower {mu : ℝ} (hmu : 0 ≤ mu) : - 3/2-mu ≤ 3/(2*(1+2*mu/3)) := by - apply (le_div_iff₀ (by positivity : 0 < 2*(1+2*mu/3))).2 - nlinarith [sq_nonneg mu] - -theorem scalar_strict {lam mu s : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) - (hmu : 0 ≤ mu) (hs₀ : 0 < s) (hs₁ : s ≤ 1) (hregion : mu*cLower lam^2 ≤ s) - (hmodel : lam^2 ≤ 1/2 ∨ s ≤ 2*(1-lam^2)) : 8/5 < scalarT lam mu s := by - have hC := cLower_pos hl₀.le - have hmuC : mu*cLower lam^2 ≤ 1 := hregion.trans hs₁ - have hlam : 0 < 1-lam^2 := by nlinarith [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] - have hfirst : (1-lam^2)/2 ≤ (1-lam^2)/(2*s) := - div_le_div_of_nonneg_left hlam.le (by positivity) (by nlinarith) - have hlast : 17*lam*mu/25 ≤ 17*lam*mu/(25*s) := - div_le_div_of_nonneg_left (by positivity) (by positivity) (by nlinarith) - have hrecip := reciprocal_lower hmu - by_cases hsmall : lam ≤ 3/10 - · have hp := small_polynomial hl₀.le hsmall - have hD : 0 ≤ (2/3)*(11/10+lam^2/2) := by positivity - have hsub := substitute_moment_region hC hD hmuC hp - have hden : 0 < 2*(1+2*mu/3) := by positivity - have hfrac : 11/10+lam^2/2 < 3/(2*(1+2*mu/3)) := by - apply (lt_div_iff₀ hden).2 - nlinarith - dsimp [scalarT] - have : 0 ≤ 17*lam*mu/25 := by positivity - linarith - · have hlow : 3/10 ≤ lam := le_of_not_ge hsmall - have hD : 0 ≤ 1-17*lam/25 := by linarith - rcases le_or_gt (lam^2) (1/2) with hmid | hbig - · have hhigh : lam ≤ 71/100 := by nlinarith - have hp := middle_polynomial hlow hhigh - have hsub := substitute_moment_region hC hD hmuC hp - dsimp [scalarT] - nlinarith - · have hsurvive : s ≤ 2*(1-lam^2) := hmodel.resolve_left (not_le.mpr hbig) - have hquarter : 1/4 ≤ (1-lam^2)/(2*s) := by - apply (le_div_iff₀ (by positivity : 0 < 2*s)).2 - linarith - have hlarge : 7/10 ≤ lam := by nlinarith - have hp := large_polynomial hlarge - have hsub := substitute_moment_region hC hD hmuC hp - dsimp [scalarT] - nlinarith - -end ThreeState.TreeClauses.Positive - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Scalar Bounds. -/ + +open scoped BigOperators ENNReal NNReal Topology +open Filter +noncomputable section +namespace ThreeState.TreeClauses.Positive + +def cLower (lam : ℝ) : ℝ := (37/27)*(1+2*lam/3) +def scalarT (lam mu s : ℝ) : ℝ := + (1-lam^2)/(2*s)+3/(2*(1+2*mu/3))+(17*lam*mu)/(25*s) + +lemma cLower_pos {lam : ℝ} (hl : 0 ≤ lam) : 0 < cLower lam := by + dsimp [cLower]; positivity + +lemma small_polynomial {lam : ℝ} (h₀ : 0 ≤ lam) (h₁ : lam ≤ 3/10) : + (2/5-lam^2/2)*cLower lam^2 > (2/3)*(11/10+lam^2/2) := by + let u := (10/3)*lam + have hu₀ : 0 ≤ u := by dsimp [u]; positivity + have hu₁ : u ≤ 1 := by dsimp [u]; linarith + have heq : (2/5-lam^2/2)*cLower lam^2-(2/3)*(11/10+lam^2/2) = + (65000*(1-u)^4+1355200*u*(1-u)^3+3367745*u^2*(1-u)^2+ + 2806680*u^3*(1-u)+716814*u^4)/3645000 := by dsimp [u, cLower]; ring + have hp : 0 < (2/5-lam^2/2)*cLower lam^2-(2/3)*(11/10+lam^2/2) := by + rw [heq] + rcases lt_or_eq_of_le hu₁ with h | h + · have : 0 < 1-u := sub_pos.mpr h + positivity + · rw [h]; norm_num + linarith + +lemma middle_polynomial {lam : ℝ} (h₀ : 3/10 ≤ lam) (h₁ : lam ≤ 71/100) : + (2/5-lam^2/2)*cLower lam^2 > 1-17*lam/25 := by + let u := (100/41)*(lam-3/10) + have hu₀ : 0 ≤ u := by dsimp [u]; positivity + have hu₁ : u ≤ 1 := by dsimp [u]; linarith + have heq : (2/5-lam^2/2)*cLower lam^2-(1-17*lam/25) = + (53796960000*(1-u)^4+340999128000*u*(1-u)^3+592285169900*u^2*(1-u)^2+ + 337132599220*u^3*(1-u)+28181130511*u^4)/328050000000 := by dsimp [u, cLower]; ring + have hp : 0 < (2/5-lam^2/2)*cLower lam^2-(1-17*lam/25) := by + rw [heq] + rcases lt_or_eq_of_le hu₁ with h | h + · have : 0 < 1-u := sub_pos.mpr h + positivity + · rw [h]; norm_num + linarith + +lemma large_polynomial {lam : ℝ} (h : 7/10 ≤ lam) : + (3/20)*cLower lam^2 > 1-17*lam/25 := by + have heq : (3/20)*cLower lam^2-(1-17*lam/25) = + 44801/546750+(67297/54675)*(lam-7/10)+(1369/10935)*(lam-7/10)^2 := by + dsimp [cLower]; ring + have hpos : 0 < (3/20)*cLower lam^2-(1-17*lam/25) := by + rw [heq]; positivity + linarith + +lemma substitute_moment_region {C B D mu : ℝ} (hC : 0 < C) (hD : 0 ≤ D) + (hmu : mu*C^2 ≤ 1) (hBD : D < B*C^2) : D*mu < B := by + have h := mul_le_mul_of_nonneg_left hmu hD + have hprod : (D*mu)*C^2 < B*C^2 := by nlinarith + exact (mul_lt_mul_iff_left₀ (sq_pos_of_pos hC)).mp hprod + +lemma reciprocal_lower {mu : ℝ} (hmu : 0 ≤ mu) : + 3/2-mu ≤ 3/(2*(1+2*mu/3)) := by + apply (le_div_iff₀ (by positivity : 0 < 2*(1+2*mu/3))).2 + nlinarith [sq_nonneg mu] + +theorem scalar_strict {lam mu s : ℝ} (hl₀ : 0 < lam) (hl₁ : lam < 1) + (hmu : 0 ≤ mu) (hs₀ : 0 < s) (hs₁ : s ≤ 1) (hregion : mu*cLower lam^2 ≤ s) + (hmodel : lam^2 ≤ 1/2 ∨ s ≤ 2*(1-lam^2)) : 8/5 < scalarT lam mu s := by + have hC := cLower_pos hl₀.le + have hmuC : mu*cLower lam^2 ≤ 1 := hregion.trans hs₁ + have hlam : 0 < 1-lam^2 := by nlinarith [mul_pos (sub_pos.mpr hl₁) (by linarith : 0 < 1+lam)] + have hfirst : (1-lam^2)/2 ≤ (1-lam^2)/(2*s) := + div_le_div_of_nonneg_left hlam.le (by positivity) (by nlinarith) + have hlast : 17*lam*mu/25 ≤ 17*lam*mu/(25*s) := + div_le_div_of_nonneg_left (by positivity) (by positivity) (by nlinarith) + have hrecip := reciprocal_lower hmu + by_cases hsmall : lam ≤ 3/10 + · have hp := small_polynomial hl₀.le hsmall + have hD : 0 ≤ (2/3)*(11/10+lam^2/2) := by positivity + have hsub := substitute_moment_region hC hD hmuC hp + have hden : 0 < 2*(1+2*mu/3) := by positivity + have hfrac : 11/10+lam^2/2 < 3/(2*(1+2*mu/3)) := by + apply (lt_div_iff₀ hden).2 + nlinarith + dsimp [scalarT] + have : 0 ≤ 17*lam*mu/25 := by positivity + linarith + · have hlow : 3/10 ≤ lam := le_of_not_ge hsmall + have hD : 0 ≤ 1-17*lam/25 := by linarith + rcases le_or_gt (lam^2) (1/2) with hmid | hbig + · have hhigh : lam ≤ 71/100 := by nlinarith + have hp := middle_polynomial hlow hhigh + have hsub := substitute_moment_region hC hD hmuC hp + dsimp [scalarT] + nlinarith + · have hsurvive : s ≤ 2*(1-lam^2) := hmodel.resolve_left (not_le.mpr hbig) + have hquarter : 1/4 ≤ (1-lam^2)/(2*s) := by + apply (le_div_iff₀ (by positivity : 0 < 2*s)).2 + linarith + have hlarge : 7/10 ≤ lam := by nlinarith + have hp := large_polynomial hlarge + have hsub := substitute_moment_region hC hD hmuC hp + dsimp [scalarT] + nlinarith + +end ThreeState.TreeClauses.Positive + +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction.lean b/lean/OAI/Probability/TraceReconstruction.lean index c4667feec965913829a9d2e7c66ce34a63035699..a4f3f0f32540d93a4267678de4330fdacb8e6978 100644 --- a/lean/OAI/Probability/TraceReconstruction.lean +++ b/lean/OAI/Probability/TraceReconstruction.lean @@ -1,427 +1,427 @@ -import OAI.Probability.TraceReconstruction.Induction -import OAI.Probability.TraceReconstruction.Testing - -namespace OAI - -/-! -# Bounds - -Restored construction and final scales; quantitative sample lower bound and both fixed-channel superpolynomial endpoints. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- The exact source error is negligible compared to the squared score energy. -/ -theorem source_final_error_eventually (B : ℕ) (ζ : ℝ) (hB : 2≤B) (hζ : ζ∈Set.Ioo 0 1) - {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) - (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀ (U : ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ (n t) - ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) - (totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) - (initialOverlapLower (q t)) - ((sourceOverlapConstant (q t))^(2*B*sourceDepth B ζ ((q t)^3*Real.log (n t))+2)) - (sourceDepth B ζ ((q t)^3*Real.log (n t))) - (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) - (sourceDepth B ζ ((q t)^3*Real.log (n t))))), - U.error≤(n t)^(-2*totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by - have ht := SourceExpUpper.uniform (fun D _=>(D:ℝ)+1) SourcePolyUpper.depth.expUpper - B ζ 1 hB hζ zero_lt_one hn hq hH - filter_upwards [ht,hn.eventually_ge_atTop 2] with t ht hn2 U - let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) - let d := totalScoreExponent B D - have hn0 : 0(B:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop - have hn1 : Tendsto (fun B : ℕ=>(B:ℝ)+1) atTop atTop := - tendsto_atTop_mono (fun B=>by linarith) hn - have h1 := hn1.const_div_atTop (1:ℝ) - have h2 := hn.const_div_atTop (3/10:ℝ) - have hlim := ((tendsto_const_nhds (x:=(1:ℝ))).sub h1).mul - ((tendsto_const_nhds (x:=(1/4:ℝ))).sub h2) |>.div_const (Real.log 2) - have hlim' : Tendsto (fun B : ℕ=>(1-1/((B:ℝ)+1))*((1/4:ℝ)-(3/10:ℝ)/(B:ℝ))/Real.log 2) - atTop (𝓝 (1/(4*Real.log 2))) := by - convert hlim using 1 - ring_nf - obtain ⟨B,hB,hβ⟩ := ((eventually_ge_atTop 2).and (hlim'.eventually_const_lt hc)).exists - refine ⟨B,hB,1/((B:ℝ)+1),⟨by positivity,?_⟩,?_⟩ - · have hBr : (2:ℝ)≤B := by exact_mod_cast hB - exact (div_lt_one (by positivity)).mpr (by linarith) - · have hBr : (B:ℝ)≠0 := by exact_mod_cast (show B≠0 by omega) - have he : finalSlope B (1/((B:ℝ)+1))= - (1-1/((B:ℝ)+1))*((1/4:ℝ)-(3/10:ℝ)/(B:ℝ))/Real.log 2 := by - unfold finalSlope blockGain - field_simp - ring - rw [he] - exact hβ - -/-- Constant-size subdivision and larger deletion preserve the joint regime. - The factor 16 includes the factor eight of the working deletion cube. -/ -theorem subdivided_working_scale {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) - (hq : ∀t,q t∈Set.Ioo 0 1) - (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) - {G : ℝ} (hG : 0n t/G) atTop atTop ∧ - Tendsto (fun t=>(workingDeletion (q t))^3*Real.log (n t/G)) atTop atTop ∧ - ∀ᶠt in atTop,(q t)^3*Real.log (n t)/16 ≤ - (workingDeletion (q t))^3*Real.log (n t/G) := by - have hN := hn.atTop_div_const hG - have hl := Real.tendsto_log_atTop.comp hn - have hh : ∀ᶠt in atTop,(q t)^3*Real.log (n t)/16 ≤ - (workingDeletion (q t))^3*Real.log (n t/G) := by - filter_upwards [hn.eventually_ge_atTop 1,hl.eventually_ge_atTop (max 0 (2*Real.log G))] with t hn1 hl - have hn0 : 0(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,(n t)^(c*Real.log ((q t)^3*Real.log (n t))) ≤ - a*(n t/G)^(totalScoreExponent B - (sourceDepth B ζ ((workingDeletion (q t))^3*Real.log (n t/G)))) := by - let α := finalSlope B ζ - have hα0 : 0<α := hc.trans hα - obtain ⟨ρ,hρc,hρ1⟩ := exists_between ((div_lt_one hα0).mpr hα) - have hρ0 : 0<ρ := (div_pos hc hα0).trans hρc - have hρc' : c<ρ*α := (div_lt_iff₀ hα0).mp hρc - let H := fun t=>(q t)^3*Real.log (n t) - let J := fun t=>(workingDeletion (q t))^3*Real.log (n t/G) - let d := fun t=>totalScoreExponent B (sourceDepth B ζ (J t)) - let K := blockGain B+(warmupBlocks B:ℝ)*blockGain B+α*Real.log 16 - have hsc := subdivided_working_scale hn hq hH hG - have hdepth := sourceDepth_tendsto B ζ hB hζ.2 hsc.2.1 - have hd : ∀ᶠt in atTop,(ρ*α)*Real.log (H t)-ρ*K≤ρ*d t := by - filter_upwards [hsc.2.2,hH.eventually_gt_atTop 0, - hdepth.eventually_ge_atTop (warmupBlocks B)] with t hj hp hD - have hJ : 0 (q k) ^ 3 * Real.log (n k)) atTop atTop) : - ∀ᶠ k in atTop, - ENNReal.ofReal ((n k : ℝ) ^ (c * Real.log ((q k) ^ 3 * Real.log (n k)))) ≤ - sampleComplexity (n k) (q k) s := by - obtain ⟨B,hB,ζ,hζ,hα⟩ := exists_source_slope hc.2 - obtain ⟨g,hg⟩ := exists_nat_gt (max 1 (2/s)) - have hg1 : 1<(g:ℝ) := (le_max_left _ _).trans_lt hg - have hg0 : 0<(g:ℝ) := by linarith only [hg1] - have hgs : 1/(2:ℝ)^g norm_num - | succ g ih => - push_cast - rw [pow_succ] - have hg : (0:ℝ) ≤ g := Nat.cast_nonneg g - have hp : (1:ℝ) ≤ 2^g := one_le_pow₀ (by norm_num) - nlinarith only [ih,hg,hp] - have hbig : 2/s<(2:ℝ)^g := ((le_max_right _ _).trans_lt hg).trans hp - have hh := (div_lt_iff₀ hs.1).mp hbig - apply (div_lt_iff₀ (by positivity : (0:ℝ)<2^g)).mpr - nlinarith only [hh] - have hnr : Tendsto (fun t=>(n t:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp hn - let N := fun t=>(n t:ℝ)/(g:ℝ) - let r := fun t=>workingDeletion (q t) - have hr (t) : r t∈Set.Ioc 0 (1/2:ℝ) := workingDeletion_Ioc (hq t) - have hsc := subdivided_working_scale hnr hq hscale hg0 - have hpair := source_final_pair_eventually B ζ hB hζ hsc.1 hr hsc.2.1 - have herr := source_final_error_eventually B ζ hB hζ hsc.1 hr hsc.2.1 - have hmargin := source_restored_exponent_margin B ζ c (g:ℝ) (s^2/(64*g)) - hB hζ hc.1 hα hg0 (div_pos (sq_pos_of_pos hs.1) (mul_pos (by norm_num) hg0)) hnr hq hscale - filter_upwards [hpair,herr,hmargin,hsc.1.eventually_ge_atTop 2] with t hp he hm hn2 - obtain ⟨U⟩ := hp - have hN1 : 1 ≤ N t := by dsimp [N]; linarith only [hn2] - have hN2 : 1(n:ℝ)^C*minTraceTV n q) atTop (𝓝 0) := by - let r := workingDeletion q - have hr : r∈Set.Ioc 0 (1/2:ℝ) := workingDeletion_Ioc hq - have hn : Tendsto (fun n : ℕ=>(n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop - have hJ : Tendsto (fun n : ℕ=>r^3*Real.log (n:ℝ)) atTop atTop := - (Real.tendsto_log_atTop.comp hn).const_mul_atTop (pow_pos hr.1 3) - have hpair := source_final_pair_eventually 2 (1/2) (by omega) (by norm_num) hn (fun _=>hr) hJ - have herr := source_final_error_eventually 2 (1/2) (by omega) (by norm_num) hn (fun _=>hr) hJ - obtain ⟨D0,hD0⟩ := exists_nat_ge (5*(2*(C+1))) - have hdepth := (sourceDepth_tendsto 2 (1/2) (by omega) (by norm_num) hJ).eventually_ge_atTop D0 - have hb : ∀ᶠ n : ℕ in atTop,0 ≤ (n:ℝ)^C*minTraceTV n q ∧ - (n:ℝ)^C*minTraceTV n q ≤ 3/(n:ℝ) := by - filter_upwards [hpair,herr,hdepth,hn.eventually_ge_atTop 2] with n hp he hD hn2 - obtain ⟨U⟩ := hp - have hn1 : 1<(n:ℝ) := by linarith only [hn2] - have hk := (sourceHalfMoment_bounds 2 - (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) - (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) (by omega) hn1).1 - obtain ⟨x,y,hxy,hTV⟩ := U.restored_words (by linarith only [hr.2]) - ⟨hq.1.le,hq.2.le⟩ (workingDeletion_bounds hq).2.2 hk n le_rfl - have ht := hTV 1 - rw [FiniteLaw.tv_product_one] at ht - rw [completeTraceLaw_tv q ⟨hq.1.le,hq.2.le⟩ x y] at ht - norm_num only [Nat.cast_one,one_mul,mul_one] at ht - have hd : 2*(C+1) ≤ totalScoreExponent 2 (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) := by - rw [totalScoreExponent_two] - have hDD : (D0:ℝ) ≤ (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ)):ℝ) := by exact_mod_cast hD - linarith only [hD0,hDD] - refine ⟨mul_nonneg (Real.rpow_nonneg (Nat.cast_nonneg n) _) (minTraceTV_nonneg_of_pair q x y hxy),?_⟩ - apply (mul_le_mul_of_nonneg_left (minTraceTV_le_pair q x y hxy) - (Real.rpow_nonneg (Nat.cast_nonneg n) C)).trans - apply one_trace_power_bound hn1.le hC hd - linarith only [ht,he U] - exact squeeze_zero' (hb.mono fun _ h=>h.1) (hb.mono fun _ h=>h.2) (hn.const_div_atTop 3) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical ENNReal - -/-- Source Theorem 2's sample conclusion at the same fixed deletion channel. -/ -theorem superpolynomial_sample_complexity - (q : ℝ) (hq : q ∈ Set.Ioo 0 1) (s : ℝ) (hs : s ∈ Set.Ioc 0 1) - (C : ℝ) (hC : 0 < C) : - Tendsto - (fun n : ℕ => sampleComplexity n q s / ENNReal.ofReal ((n : ℝ) ^ C)) - atTop (𝓝 ⊤) := by - let c : ℝ := 1/(8*Real.log 2) - have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) - have hc0 : 0 < c := by dsimp [c]; positivity - have hc : c ∈ Set.Ioo 0 (1/(4*Real.log 2)) := by - refine ⟨hc0,?_⟩ - dsimp [c] - apply one_div_lt_one_div_of_lt - · positivity - · nlinarith only [hl] - have hn : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop - have hH : Tendsto (fun n : ℕ => q^3*Real.log (n:ℝ)) atTop atTop := - (Real.tendsto_log_atTop.comp hn).const_mul_atTop (pow_pos hq.1 3) - have hb := quantitative_sample_lower_bound s c hs hc id (fun _ => q) tendsto_id (fun _ => hq) hH - have he := ((Real.tendsto_log_atTop.comp hH).const_mul_atTop hc0).eventually_ge_atTop (2*C+1) - have hbound : ∀ᶠ n : ℕ in atTop,(n:ℝ≥0∞) ≤ - sampleComplexity n q s / ENNReal.ofReal ((n:ℝ)^C) := by - filter_upwards [hb,he,hn.eventually_gt_atTop 1] with n hb he hn1 - dsimp only [Function.comp_apply] at he - have hn0 : 0 < (n:ℝ) := zero_lt_one.trans hn1 - have hpow : (n:ℝ)^(C+1) ≤ (n:ℝ)^(c*Real.log (q^3*Real.log (n:ℝ))) := - Real.rpow_le_rpow_of_exponent_le hn1.le (by linarith only [he,hC]) - have hnC : 0 < (n:ℝ)^C := Real.rpow_pos_of_pos hn0 C - have hdiv : ENNReal.ofReal ((n:ℝ)^(C+1)) / - ENNReal.ofReal ((n:ℝ)^C) = (n:ℝ≥0∞) := by - rw [← ENNReal.ofReal_div_of_pos hnC,Real.rpow_add hn0,Real.rpow_one] - rw [mul_div_cancel_left₀ _ hnC.ne',ENNReal.ofReal_natCast] - rw [← hdiv] - exact ENNReal.div_le_div_right ((ENNReal.ofReal_le_ofReal hpow).trans hb) _ - apply ENNReal.tendsto_nhds_top - intro k - filter_upwards [hbound,eventually_gt_atTop k] with n hn hk - exact (show (k:ℝ≥0∞) < (n:ℝ≥0∞) by exact_mod_cast hk).trans_le hn - -end TraceReconstruction - -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Induction +import OAI.Probability.TraceReconstruction.Testing + +namespace OAI + +/-! +# Bounds + +Restored construction and final scales; quantitative sample lower bound and both fixed-channel superpolynomial endpoints. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- The exact source error is negligible compared to the squared score energy. -/ +theorem source_final_error_eventually (B : ℕ) (ζ : ℝ) (hB : 2≤B) (hζ : ζ∈Set.Ioo 0 1) + {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) + (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀ (U : ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ (n t) + ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) + (totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) + (initialOverlapLower (q t)) + ((sourceOverlapConstant (q t))^(2*B*sourceDepth B ζ ((q t)^3*Real.log (n t))+2)) + (sourceDepth B ζ ((q t)^3*Real.log (n t))) + (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) + (sourceDepth B ζ ((q t)^3*Real.log (n t))))), + U.error≤(n t)^(-2*totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by + have ht := SourceExpUpper.uniform (fun D _=>(D:ℝ)+1) SourcePolyUpper.depth.expUpper + B ζ 1 hB hζ zero_lt_one hn hq hH + filter_upwards [ht,hn.eventually_ge_atTop 2] with t ht hn2 U + let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) + let d := totalScoreExponent B D + have hn0 : 0(B:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hn1 : Tendsto (fun B : ℕ=>(B:ℝ)+1) atTop atTop := + tendsto_atTop_mono (fun B=>by linarith) hn + have h1 := hn1.const_div_atTop (1:ℝ) + have h2 := hn.const_div_atTop (3/10:ℝ) + have hlim := ((tendsto_const_nhds (x:=(1:ℝ))).sub h1).mul + ((tendsto_const_nhds (x:=(1/4:ℝ))).sub h2) |>.div_const (Real.log 2) + have hlim' : Tendsto (fun B : ℕ=>(1-1/((B:ℝ)+1))*((1/4:ℝ)-(3/10:ℝ)/(B:ℝ))/Real.log 2) + atTop (𝓝 (1/(4*Real.log 2))) := by + convert hlim using 1 + ring_nf + obtain ⟨B,hB,hβ⟩ := ((eventually_ge_atTop 2).and (hlim'.eventually_const_lt hc)).exists + refine ⟨B,hB,1/((B:ℝ)+1),⟨by positivity,?_⟩,?_⟩ + · have hBr : (2:ℝ)≤B := by exact_mod_cast hB + exact (div_lt_one (by positivity)).mpr (by linarith) + · have hBr : (B:ℝ)≠0 := by exact_mod_cast (show B≠0 by omega) + have he : finalSlope B (1/((B:ℝ)+1))= + (1-1/((B:ℝ)+1))*((1/4:ℝ)-(3/10:ℝ)/(B:ℝ))/Real.log 2 := by + unfold finalSlope blockGain + field_simp + ring + rw [he] + exact hβ + +/-- Constant-size subdivision and larger deletion preserve the joint regime. + The factor 16 includes the factor eight of the working deletion cube. -/ +theorem subdivided_working_scale {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) + (hq : ∀t,q t∈Set.Ioo 0 1) + (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) + {G : ℝ} (hG : 0n t/G) atTop atTop ∧ + Tendsto (fun t=>(workingDeletion (q t))^3*Real.log (n t/G)) atTop atTop ∧ + ∀ᶠt in atTop,(q t)^3*Real.log (n t)/16 ≤ + (workingDeletion (q t))^3*Real.log (n t/G) := by + have hN := hn.atTop_div_const hG + have hl := Real.tendsto_log_atTop.comp hn + have hh : ∀ᶠt in atTop,(q t)^3*Real.log (n t)/16 ≤ + (workingDeletion (q t))^3*Real.log (n t/G) := by + filter_upwards [hn.eventually_ge_atTop 1,hl.eventually_ge_atTop (max 0 (2*Real.log G))] with t hn1 hl + have hn0 : 0(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,(n t)^(c*Real.log ((q t)^3*Real.log (n t))) ≤ + a*(n t/G)^(totalScoreExponent B + (sourceDepth B ζ ((workingDeletion (q t))^3*Real.log (n t/G)))) := by + let α := finalSlope B ζ + have hα0 : 0<α := hc.trans hα + obtain ⟨ρ,hρc,hρ1⟩ := exists_between ((div_lt_one hα0).mpr hα) + have hρ0 : 0<ρ := (div_pos hc hα0).trans hρc + have hρc' : c<ρ*α := (div_lt_iff₀ hα0).mp hρc + let H := fun t=>(q t)^3*Real.log (n t) + let J := fun t=>(workingDeletion (q t))^3*Real.log (n t/G) + let d := fun t=>totalScoreExponent B (sourceDepth B ζ (J t)) + let K := blockGain B+(warmupBlocks B:ℝ)*blockGain B+α*Real.log 16 + have hsc := subdivided_working_scale hn hq hH hG + have hdepth := sourceDepth_tendsto B ζ hB hζ.2 hsc.2.1 + have hd : ∀ᶠt in atTop,(ρ*α)*Real.log (H t)-ρ*K≤ρ*d t := by + filter_upwards [hsc.2.2,hH.eventually_gt_atTop 0, + hdepth.eventually_ge_atTop (warmupBlocks B)] with t hj hp hD + have hJ : 0 (q k) ^ 3 * Real.log (n k)) atTop atTop) : + ∀ᶠ k in atTop, + ENNReal.ofReal ((n k : ℝ) ^ (c * Real.log ((q k) ^ 3 * Real.log (n k)))) ≤ + sampleComplexity (n k) (q k) s := by + obtain ⟨B,hB,ζ,hζ,hα⟩ := exists_source_slope hc.2 + obtain ⟨g,hg⟩ := exists_nat_gt (max 1 (2/s)) + have hg1 : 1<(g:ℝ) := (le_max_left _ _).trans_lt hg + have hg0 : 0<(g:ℝ) := by linarith only [hg1] + have hgs : 1/(2:ℝ)^g norm_num + | succ g ih => + push_cast + rw [pow_succ] + have hg : (0:ℝ) ≤ g := Nat.cast_nonneg g + have hp : (1:ℝ) ≤ 2^g := one_le_pow₀ (by norm_num) + nlinarith only [ih,hg,hp] + have hbig : 2/s<(2:ℝ)^g := ((le_max_right _ _).trans_lt hg).trans hp + have hh := (div_lt_iff₀ hs.1).mp hbig + apply (div_lt_iff₀ (by positivity : (0:ℝ)<2^g)).mpr + nlinarith only [hh] + have hnr : Tendsto (fun t=>(n t:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp hn + let N := fun t=>(n t:ℝ)/(g:ℝ) + let r := fun t=>workingDeletion (q t) + have hr (t) : r t∈Set.Ioc 0 (1/2:ℝ) := workingDeletion_Ioc (hq t) + have hsc := subdivided_working_scale hnr hq hscale hg0 + have hpair := source_final_pair_eventually B ζ hB hζ hsc.1 hr hsc.2.1 + have herr := source_final_error_eventually B ζ hB hζ hsc.1 hr hsc.2.1 + have hmargin := source_restored_exponent_margin B ζ c (g:ℝ) (s^2/(64*g)) + hB hζ hc.1 hα hg0 (div_pos (sq_pos_of_pos hs.1) (mul_pos (by norm_num) hg0)) hnr hq hscale + filter_upwards [hpair,herr,hmargin,hsc.1.eventually_ge_atTop 2] with t hp he hm hn2 + obtain ⟨U⟩ := hp + have hN1 : 1 ≤ N t := by dsimp [N]; linarith only [hn2] + have hN2 : 1(n:ℝ)^C*minTraceTV n q) atTop (𝓝 0) := by + let r := workingDeletion q + have hr : r∈Set.Ioc 0 (1/2:ℝ) := workingDeletion_Ioc hq + have hn : Tendsto (fun n : ℕ=>(n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hJ : Tendsto (fun n : ℕ=>r^3*Real.log (n:ℝ)) atTop atTop := + (Real.tendsto_log_atTop.comp hn).const_mul_atTop (pow_pos hr.1 3) + have hpair := source_final_pair_eventually 2 (1/2) (by omega) (by norm_num) hn (fun _=>hr) hJ + have herr := source_final_error_eventually 2 (1/2) (by omega) (by norm_num) hn (fun _=>hr) hJ + obtain ⟨D0,hD0⟩ := exists_nat_ge (5*(2*(C+1))) + have hdepth := (sourceDepth_tendsto 2 (1/2) (by omega) (by norm_num) hJ).eventually_ge_atTop D0 + have hb : ∀ᶠ n : ℕ in atTop,0 ≤ (n:ℝ)^C*minTraceTV n q ∧ + (n:ℝ)^C*minTraceTV n q ≤ 3/(n:ℝ) := by + filter_upwards [hpair,herr,hdepth,hn.eventually_ge_atTop 2] with n hp he hD hn2 + obtain ⟨U⟩ := hp + have hn1 : 1<(n:ℝ) := by linarith only [hn2] + have hk := (sourceHalfMoment_bounds 2 + (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) + (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) (by omega) hn1).1 + obtain ⟨x,y,hxy,hTV⟩ := U.restored_words (by linarith only [hr.2]) + ⟨hq.1.le,hq.2.le⟩ (workingDeletion_bounds hq).2.2 hk n le_rfl + have ht := hTV 1 + rw [FiniteLaw.tv_product_one] at ht + rw [completeTraceLaw_tv q ⟨hq.1.le,hq.2.le⟩ x y] at ht + norm_num only [Nat.cast_one,one_mul,mul_one] at ht + have hd : 2*(C+1) ≤ totalScoreExponent 2 (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ))) := by + rw [totalScoreExponent_two] + have hDD : (D0:ℝ) ≤ (sourceDepth 2 (1/2) (r^3*Real.log (n:ℝ)):ℝ) := by exact_mod_cast hD + linarith only [hD0,hDD] + refine ⟨mul_nonneg (Real.rpow_nonneg (Nat.cast_nonneg n) _) (minTraceTV_nonneg_of_pair q x y hxy),?_⟩ + apply (mul_le_mul_of_nonneg_left (minTraceTV_le_pair q x y hxy) + (Real.rpow_nonneg (Nat.cast_nonneg n) C)).trans + apply one_trace_power_bound hn1.le hC hd + linarith only [ht,he U] + exact squeeze_zero' (hb.mono fun _ h=>h.1) (hb.mono fun _ h=>h.2) (hn.const_div_atTop 3) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical ENNReal + +/-- Source Theorem 2's sample conclusion at the same fixed deletion channel. -/ +theorem superpolynomial_sample_complexity + (q : ℝ) (hq : q ∈ Set.Ioo 0 1) (s : ℝ) (hs : s ∈ Set.Ioc 0 1) + (C : ℝ) (hC : 0 < C) : + Tendsto + (fun n : ℕ => sampleComplexity n q s / ENNReal.ofReal ((n : ℝ) ^ C)) + atTop (𝓝 ⊤) := by + let c : ℝ := 1/(8*Real.log 2) + have hl : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hc0 : 0 < c := by dsimp [c]; positivity + have hc : c ∈ Set.Ioo 0 (1/(4*Real.log 2)) := by + refine ⟨hc0,?_⟩ + dsimp [c] + apply one_div_lt_one_div_of_lt + · positivity + · nlinarith only [hl] + have hn : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hH : Tendsto (fun n : ℕ => q^3*Real.log (n:ℝ)) atTop atTop := + (Real.tendsto_log_atTop.comp hn).const_mul_atTop (pow_pos hq.1 3) + have hb := quantitative_sample_lower_bound s c hs hc id (fun _ => q) tendsto_id (fun _ => hq) hH + have he := ((Real.tendsto_log_atTop.comp hH).const_mul_atTop hc0).eventually_ge_atTop (2*C+1) + have hbound : ∀ᶠ n : ℕ in atTop,(n:ℝ≥0∞) ≤ + sampleComplexity n q s / ENNReal.ofReal ((n:ℝ)^C) := by + filter_upwards [hb,he,hn.eventually_gt_atTop 1] with n hb he hn1 + dsimp only [Function.comp_apply] at he + have hn0 : 0 < (n:ℝ) := zero_lt_one.trans hn1 + have hpow : (n:ℝ)^(C+1) ≤ (n:ℝ)^(c*Real.log (q^3*Real.log (n:ℝ))) := + Real.rpow_le_rpow_of_exponent_le hn1.le (by linarith only [he,hC]) + have hnC : 0 < (n:ℝ)^C := Real.rpow_pos_of_pos hn0 C + have hdiv : ENNReal.ofReal ((n:ℝ)^(C+1)) / + ENNReal.ofReal ((n:ℝ)^C) = (n:ℝ≥0∞) := by + rw [← ENNReal.ofReal_div_of_pos hnC,Real.rpow_add hn0,Real.rpow_one] + rw [mul_div_cancel_left₀ _ hnC.ne',ENNReal.ofReal_natCast] + rw [← hdiv] + exact ENNReal.div_le_div_right ((ENNReal.ofReal_le_ofReal hpow).trans hb) _ + apply ENNReal.tendsto_nhds_top + intro k + filter_upwards [hbound,eventually_gt_atTop k] with n hn hk + exact (show (k:ℝ≥0∞) < (n:ℝ≥0∞) by exact_mod_cast hk).trans_le hn + +end TraceReconstruction + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Amplification.lean b/lean/OAI/Probability/TraceReconstruction/Amplification.lean index 2ba8dc8e8c98d0c8dc6734b7f40b112cad2c178b..a85f2d14c9b837bbc4dc5bb74a0683db18f61c6e 100644 --- a/lean/OAI/Probability/TraceReconstruction/Amplification.lean +++ b/lean/OAI/Probability/TraceReconstruction/Amplification.lean @@ -1,828 +1,828 @@ -import OAI.Probability.TraceReconstruction.SourceOracle - -namespace OAI - -/-! -# Amplification - -Oracle products, mixed powers, padding, warmup and nested template Hellinger estimates, overlap, and block assembly. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The literal product/concatenation decoder charges only coordinates at - which the two deterministic input templates differ. -/ -theorem OracleTracePair.mixed_tv {q E V : ℝ} {x y : List Bool} {k n : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1≤k) - (τ σ : Fin n → Bool) (M : ℕ) - (hτ : (coordinateWord (fun i => if τ i then y else x)).length≤M) - (hσ : (coordinateWord (fun i => if σ i then y else x)).length≤M) : - (listTraceLaw q hq (coordinateWord (fun i => if τ i then y else x)) M hτ).tv - (listTraceLaw q hq (coordinateWord (fun i => if σ i then y else x)) M hσ) ≤ - Real.sqrt ((∑i,if τ i=σ i then (0:ℝ) else 1)*V)+2*(n:ℝ)*E := by - let := C.finiteOutcome - have ha (ρ : Fin n → Bool) : ApproximatesTrace q - (FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first)) - (fun z => coordinateWord (fun i => C.decode (z i))) - (coordinateWord (fun i => if ρ i then y else x)) ((n:ℝ)*E) := by - have H := coordinateProduct_approximates hq - (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) - (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) - · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H - · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] - · exact C.first_simulation - · exact C.second_simulation - have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hτ hσ (ha τ) (ha σ) - have htv := FiniteLaw.tv_mixedProduct_le C.first C.second C.score C.density k hk C.moment τ σ - linarith only [H,htv] - -theorem coordinateWord_constant (w : List Bool) (n : ℕ) : - coordinateWord (fun _ : Fin n => w)=pureAtomRun w n := by - induction n with - | zero => simp [coordinateWord,pureAtomRun] - | succ n ih => - rw [coordinateWord_succ,ih] - simp only [pureAtomRun,List.replicate_succ,List.flatten_cons] - -/-- Tensorization of a genuine approximate oracle, on actual word powers. -/ -theorem OracleTracePair.power_tv {q E V : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1≤k) - (n M : ℕ) (hx : (pureAtomRun x n).length≤M) (hy : (pureAtomRun y n).length≤M) : - (listTraceLaw q hq (pureAtomRun x n) M hx).tv - (listTraceLaw q hq (pureAtomRun y n) M hy) ≤ - Real.sqrt ((n:ℝ)*V)+2*(n:ℝ)*E := by - have H := C.mixed_tv hq hk (fun _ : Fin n => false) (fun _ => true) M - (by simpa only [Bool.false_eq_true,ite_false,coordinateWord_constant] using hx) - (by simpa only [ite_true,coordinateWord_constant] using hy) - simpa only [Bool.false_eq_true,ite_false,ite_true,coordinateWord_constant, - Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] using H - -/-- Genuine lifting for complete traces, with no auxiliary overlap hypothesis. -/ -theorem listTraceOverlap_lift {F k R : ℕ} {C p q : ℝ} - (hk : 1≤k) (hR : 1≤R) (hp : p∈Set.Ioc 0 (1/8)) (hq : q∈Set.Icc 0 1) - (hC : 1073741824≤p*C) (hF : C*k*R≤F) (w : List Bool) - (hov : p≤listTraceOverlap q hq (pureAtomRun w k) (pureAtomRun w (k+1))) : - (2/3:ℝ)≤listTraceOverlap q hq (pureAtomRun w (F*R)) (pureAtomRun w (F*R+R)) := by - let M := max (pureAtomRun w k).length (pureAtomRun w (k+1)).length - have H := adjacent_power_lift hk hR hp hq hC hF - (listTraceLaw q hq (pureAtomRun w k) M (le_max_left _ _)) - (listTraceLaw q hq (pureAtomRun w (k+1)) M (le_max_right _ _)) Subtype.val w - (listTraceLaw_simulates q hq _ M _) (listTraceLaw_simulates q hq _ M _) hov - obtain ⟨β,fin,P,Q,g,hP,hQ,hO⟩ := H - let := fin - exact hO.trans (simulations_overlap_le hq P Q g _ _ hP hQ) - -theorem pureAtomRun_mul (w : List Bool) (n m : ℕ) : - pureAtomRun (pureAtomRun w n) m=pureAtomRun w (m*n) := by - induction m with - | zero => simp [pureAtomRun] - | succ m ih => - have H : pureAtomRun (pureAtomRun w n) (m+1)= - pureAtomRun w n++pureAtomRun (pureAtomRun w n) m := by - simp [pureAtomRun,List.replicate_succ] - rw [H,ih,←pureAtomRun_add] - congr 1 - ring - -/-- Quantitative overlap transfer used for the initial pure comparison and - the small-dimensional warmup refinement. All three laws are ordinary traces. -/ -theorem OracleTracePair.lifted_power_overlap {q E V p C₀ : ℝ} {w z : List Bool} - {k h P F : ℕ} (O : OracleTracePair q (pureAtomRun w P) z k E V) - (hq : q∈Set.Icc 0 1) (hk : 1≤k) (hh : 1≤h) (hP : 1≤P) - (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824≤p*C₀) (hF : C₀*h*P≤F) - (hov : p≤listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) : - (2/3:ℝ)-(Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E)- - (Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E) ≤ - listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by - let a := pureAtomRun (pureAtomRun w P) F - let b := pureAtomRun (pureAtomRun w P) (F+1) - let x := pureAtomRun z F - let y := pureAtomRun z (F+1) - let M := max (max a.length b.length) (max x.length y.length) - have ha : a.length≤M := (le_max_left _ _).trans (le_max_left _ _) - have hb : b.length≤M := (le_max_right _ _).trans (le_max_left _ _) - have hx : x.length≤M := (le_max_left _ _).trans (le_max_right _ _) - have hy : y.length≤M := (le_max_right _ _).trans (le_max_right _ _) - have ht1 := O.power_tv hq hk F M ha hx - have ht2 := O.power_tv hq hk (F+1) M hb hy - have hol := listTraceOverlap_lift hh hP hp hq hC hF w hov - have he : F*P+P=(F+1)*P := by ring - have heA : pureAtomRun w (F*P)=a := (pureAtomRun_mul w P F).symm - have heB : pureAtomRun w (F*P+P)=b := by - rw [he]; exact (pureAtomRun_mul w P (F+1)).symm - rw [heA,heB] at hol - rw [listTraceOverlap_ambient hq _ _ M ha hb,FiniteLaw.overlap_eq_one_sub_tv] at hol - rw [listTraceOverlap_ambient hq _ _ M hx hy,FiniteLaw.overlap_eq_one_sub_tv] - have H := (FiniteLaw.tv_triangle (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha) - (listTraceLaw q hq y M hy)).trans - (add_le_add le_rfl (FiniteLaw.tv_triangle (listTraceLaw q hq a M ha) - (listTraceLaw q hq b M hb) (listTraceLaw q hq y M hy))) - rw [FiniteLaw.tv_symm (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha)] at H - linarith only [H,ht1,ht2,hol] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -theorem hellingerSq_mixedProduct_le {n : ℕ} (P Q : FiniteLaw α) {V : ℝ} - (hH : P.hellingerSq Q ≤ V) (τ σ : Fin n → Bool) : - (coordinateProduct (fun i => if τ i then Q else P)).hellingerSq - (coordinateProduct (fun i => if σ i then Q else P)) ≤ - (∑i,if τ i=σ i then (0:ℝ) else 1)*V := by - apply (hellingerSq_coordinateProduct_le _ _).trans - rw [Finset.sum_mul] - apply Finset.sum_le_sum - intro i _ - cases τ i <;> cases σ i <;> simp only [Bool.false_eq_true,Bool.true_eq_false, - ite_false,ite_true,zero_mul,one_mul,hellingerSq_self,le_refl] - · exact hH - · rw [hellingerSq_symm]; exact hH - -end FiniteLaw - -theorem ApproximatesTrace.power {α : Type*} [Fintype α] {q E : ℝ} {P : FiniteLaw α} - {g : α → List Bool} {w : List Bool} (H : ApproximatesTrace q P g w E) - (hq : q∈Set.Icc 0 1) (F : ℕ) : - ApproximatesTrace q (P.product F) (fun z => coordinateWord (fun i => g (z i))) - (pureAtomRun w F) ((F:ℝ)*E) := by - have h := coordinateProduct_approximates hq (fun _ : Fin F => P) (fun _ => g) - (fun _ => w) (fun _ => E) (fun _ => H) - have he : FiniteLaw.coordinateProduct (fun _ : Fin F => P)=P.product F := rfl - rw [he,coordinateWord_constant] at h - simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using h - -/-- Repeated mixed templates pay only for the differing leaves in squared - Hellinger, while approximate leaf simulation is charged linearly. -/ -theorem OracleTracePair.mixed_power_tv {q E V : ℝ} {x y : List Bool} {k n : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1 ≤ k) - (τ σ : Fin n → Bool) (F M : ℕ) - (hτ : (pureAtomRun (coordinateWord (fun i => if τ i then y else x)) F).length ≤ M) - (hσ : (pureAtomRun (coordinateWord (fun i => if σ i then y else x)) F).length ≤ M) : - (listTraceLaw q hq (pureAtomRun (coordinateWord (fun i => if τ i then y else x)) F) M hτ).tv - (listTraceLaw q hq (pureAtomRun (coordinateWord (fun i => if σ i then y else x)) F) M hσ) ≤ - Real.sqrt ((F:ℝ)*(∑i,if τ i=σ i then (0:ℝ) else 1)*V)+2*(F:ℝ)*(n:ℝ)*E := by - let := C.finiteOutcome - let A (ρ : Fin n → Bool) := FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first) - let g (z : Fin n → C.Outcome) := coordinateWord (fun i => C.decode (z i)) - have ha (ρ : Fin n → Bool) : ApproximatesTrace q (A ρ) g - (coordinateWord (fun i => if ρ i then y else x)) ((n:ℝ)*E) := by - have H := coordinateProduct_approximates hq - (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) - (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) - · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H - · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] - · exact C.first_simulation - · exact C.second_simulation - have hH : C.first.hellingerSq C.second ≤ V := - (C.first.hellingerSq_le_score C.second C.score C.density).trans - ((C.first.secondMoment_le_evenMomentSq C.score k hk).trans C.moment) - have hm := FiniteLaw.hellingerSq_mixedProduct_le C.first C.second hH τ σ - have hp := (FiniteLaw.hellingerSq_product_le (A τ) (A σ) F).trans - (mul_le_mul_of_nonneg_left hm (Nat.cast_nonneg F)) - have htv := (FiniteLaw.tv_le_sqrt_hellingerSq ((A τ).product F) ((A σ).product F)).trans - (Real.sqrt_le_sqrt hp) - have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hτ hσ - ((ha τ).power hq F) ((ha σ).power hq F) - rw [←mul_assoc] at htv - linarith only [H,htv] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- An exact common prefix and suffix are observed as ordinary independent - complete traces. They neither change the score moment nor cost simulation - error. This is the source's deterministic residual convention. -/ -def OracleTracePair.pad {q E V : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (u v : List Bool) : - OracleTracePair q (u++x++v) (u++y++v) k E V := by - let := C.finiteOutcome - let P := listTraceLaw q hq u u.length le_rfl - let Q := listTraceLaw q hq v v.length le_rfl - refine { - Outcome := (BoundedTrace u.length × C.Outcome) × BoundedTrace v.length - finiteOutcome := inferInstance - first := (P.prod C.first).prod Q - second := (P.prod C.second).prod Q - decode := fun z => z.1.1.val++C.decode z.1.2++z.2.val - score := fun z => C.score z.1.2 - density := by - intro z - change (P.mass z.1.1*C.second.mass z.1.2)*Q.mass z.2=_ - rw [C.density] - change _=(P.mass z.1.1*C.first.mass z.1.2)*Q.mass z.2*(1+C.score z.1.2) - ring - likelihood_nonneg := fun z => C.likelihood_nonneg z.1.2 - centered := by - simp only [FiniteLaw.expect_prod,FiniteLaw.expect_const,C.centered] - moment := by - simpa only [FiniteLaw.evenMomentSq,FiniteLaw.expect_prod,FiniteLaw.expect_const] using C.moment - first_simulation := by - have H := ((listTraceLaw_simulates q hq u u.length le_rfl).approximate.append hq - C.first_simulation).append hq (listTraceLaw_simulates q hq v v.length le_rfl).approximate - simpa only [zero_add,add_zero] using H - second_simulation := by - have H := ((listTraceLaw_simulates q hq u u.length le_rfl).approximate.append hq - C.second_simulation).append hq (listTraceLaw_simulates q hq v v.length le_rfl).approximate - simpa only [zero_add,add_zero] using H } - -/-- Literal template equality under deterministic pure residual padding. -/ -theorem complementaryWords_pad (L P R a len : ℕ) (sign : Fin len → Bool) - (w : Bool → List Bool) (τ : Bool) (hfit : a+len ≤ P) : - complementaryWords (L+P+R) (L+a) len sign w τ = - pureAtomRun (w false) L++complementaryWords P a len sign w τ++pureAtomRun (w false) R := by - unfold complementaryWords - rw [atomString_three] - have hp (i : Fin L) : templateType (L+P+R) (L+a) len sign τ ⟨i.val,by omega⟩=false := by - have hi := i.isLt - simp only [templateType,dite_eq_right (by omega : ¬(L+a ≤ i.val ∧ i.val < L+a+len))] - have hm (i : Fin P) : templateType (L+P+R) (L+a) len sign τ ⟨L+i.val,by omega⟩= - templateType P a len sign τ i := by - unfold templateType - split_ifs with h h' h' - · congr 2 - apply Fin.ext - simp only - omega - · simp only at h - omega - · simp only at h - omega - · rfl - have hr (i : Fin R) : templateType (L+P+R) (L+a) len sign τ ⟨L+P+i.val,by omega⟩=false := by - simp only [templateType,dite_eq_right (by omega : ¬(L+a ≤ L+P+i.val ∧ L+P+i.val < L+a+len))] - simp_rw [hp,hm,hr] - change coordinateWord (fun _ : Fin L => w false)++_++coordinateWord (fun _ : Fin R => w false)=_ - rw [coordinateWord_constant,coordinateWord_constant] - -def centeredLeftResidual (N P : ℕ) : ℕ := N/2-1-(P/2-1) -def centeredRightResidual (N P : ℕ) : ℕ := N-(centeredLeftResidual N P+P) - -theorem centeredResidual_geometry {N P : ℕ} (hP : 2 ≤ P) (hN : P ≤ N) : - centeredLeftResidual N P+P+centeredRightResidual N P=N ∧ - centeredLeftResidual N P+(P/2-1)=N/2-1 := by - simp only [centeredRightResidual,centeredLeftResidual] - omega - -/-- The auxiliary one-window oracle is centered at the same actual source - motif after appending pure residuals, also for odd ambient atom counts. -/ -theorem centeredComplementaryWords_pad (N P s : ℕ) (w : Bool → List Bool) (τ : Bool) - (hP : 2 ≤ P) (hN : P ≤ N) (hfit : P/2-1+2^s ≤ P) : - complementaryWords N (N/2-1) (2^s) (prouhetBool s) w τ = - pureAtomRun (w false) (centeredLeftResidual N P)++ - complementaryWords P (P/2-1) (2^s) (prouhetBool s) w τ++ - pureAtomRun (w false) (centeredRightResidual N P) := by - have h := complementaryWords_pad (centeredLeftResidual N P) P (centeredRightResidual N P) - (P/2-1) (2^s) (prouhetBool s) w τ hfit - rw [(centeredResidual_geometry hP hN).1,(centeredResidual_geometry hP hN).2] at h - exact h - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The source's special one-window warmup observation. The ambient word - need not have the root's arithmetic divisibility: exact pure residuals - restore its literal center, at no additional statistical error. -/ -theorem actual_one_window_oracle {q E V : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hE : 0 ≤ E) - (s N T t h R : ℕ) (hT : 24 ≤ T) (he : Even T) - (hMotif : 24*2^s ≤ T) (hroot : 4*(t+1) ≤ T) - (hfit : t*(2*h+1)+T ≤ N) - (ω a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hω : ω∈Set.Ioo 0 1) - (hov : ω ≤ listTraceOverlap q hq (pureAtomRun x h) (pureAtomRun x (h+1))) - (hk : 1 ≤ k) (hV : V ≤ L^2) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount (fun _ => T) s 0 ≤ 1/2) - (hη : hiddenSmoothingBound t s ω ≤ η) - (herror : sourceClippingCost (fun _ => T) (fun _ => t) s 0 k ω a L ≤ 1/2) : - Nonempty (OracleTracePair q - (complementaryWords N (N/2-1) (2^s) (prouhetBool s) (fun τ => if τ then y else x) false) - (complementaryWords N (N/2-1) (2^s) (prouhetBool s) (fun τ => if τ then y else x) true) k - (sourceClippingCost (fun _ => T) (fun _ => t) s 0 k ω a L+(T:ℝ)*E) - (64*sourceSharpEnergyBudget (fun _ => T) (fun _ => t) s 0 R ω η a ((6*(2*k:ℕ):ℝ)*L))) := by - let := C.finiteOutcome - let p := t*(2*h+1)+T - let atom : Bool → List Bool := fun τ => if τ then y else x - have H : SourceLayoutMargins s (fun _ => p) (fun _ => T) (fun _ => t) (fun _ => h) 0 := by - constructor <;> intro j hj <;> omega - have hm : C.first.expect (fun z => |C.score z|^(2*k)) ≤ L^(2*k) := by - have hv := C.first.expect_even_pow_le_of_moment C.score k hk (C.moment.trans hV) - simpa only [pow_mul] using hv - obtain ⟨W⟩ := actual_source_oracle hq hE s (fun _ => p) (fun _ => T) (fun _ => t) - (fun _ => h) atom 0 R k H (fun _ => by omega) rfl - (fun j hj => by omega) (fun _ _ => hT) (fun _ _ => he) (fun _ _ => hMotif) hroot - C.first C.second C.decode C.score C.density C.likelihood_nonneg - C.first_simulation C.second_simulation ω a η L ha hL hω - (fun j hj => by - have hj' : j=0 := by omega - subst j - exact hov) - hk hm hscale (fun _ _ => hη) herror - have hp : 2 ≤ p := by dsimp [p]; omega - have hmp : p/2-1+2^s ≤ p := by dsimp [p] at *; omega - let U := pureAtomRun x (centeredLeftResidual N p) - let B := pureAtomRun x (centeredRightResidual N p) - have heq (τ : Bool) := centeredComplementaryWords_pad N p s atom τ hp hfit hmp - have HH := W.pad hq U B - simp only [sourceBlockWord,sourceFitTail,add_zero] at HH - change OracleTracePair q - (U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom false++B) - (U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom true++B) k _ _ at HH - have hleft : U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom false++B = - complementaryWords N (N/2-1) (2^s) (prouhetBool s) atom false := (heq false).symm - have hright : U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom true++B = - complementaryWords N (N/2-1) (2^s) (prouhetBool s) atom true := (heq true).symm - rw [hleft,hright] at HH - have hc : SourceLeafCount (fun _ => T) 1=T := by - calc - _ = Fintype.card (Fin (T*1)) := Fintype.card_congr finProdFinEquiv - _ = T := by simp - simp only [hc] at HH - exact ⟨HH⟩ - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem sourceLeafCount_one (T : ℕ → ℕ) : SourceLeafCount T 1=T 0 := by - calc - _ = Fintype.card (Fin (T 0*1)) := Fintype.card_congr finProdFinEquiv - _ = T 0 := by simp - -/-- Exact two-degree cutoff for the one-window warmup refinement. In - particular the remaining geometric term is quadratic in the old energy. -/ -theorem sourceSharpEnergyBudget_one_window (T n : ℕ → ℕ) (s : ℕ) (ω η a w : ℝ) : - sourceSharpEnergyBudget T n s 0 2 ω η a w = - 36*(T 0:ℝ)*w^2*(η^2+a^2)+4*(w^2*2^s)^2/(1-w^2*2^s) := by - simp only [sourceSharpEnergyBudget,Finset.sum_range_succ,Finset.sum_range_zero] - norm_num [sourceSharpDegreeBudget,sourceSparseCount,sourceLeafCount_one,Nat.choose_one_right] - ring - -theorem sourceSharpEnergyBudget_warmup (T n : ℕ → ℕ) (s : ℕ) (ω η w : ℝ) - (h : w^2*2^s ≤ 1/2) : - sourceSharpEnergyBudget T n s 0 2 ω η η w ≤ - 72*(T 0:ℝ)*w^2*η^2+8*(w^2*2^s)^2 := by - rw [sourceSharpEnergyBudget_one_window] - have hd : 0 < 1-w^2*2^s := by linarith - have hb : 4*(w^2*2^s)^2/(1-w^2*2^s) ≤ 8*(w^2*2^s)^2 := by - apply (div_le_iff₀ hd).mpr - have hh := mul_le_mul_of_nonneg_left h (sq_nonneg (w^2*2^s)) - nlinarith only [hh] - nlinarith only [hb] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The number of differing labels of complementary templates is bounded - by the actual motif length, without any assumption that it fills the word. -/ -theorem templateType_difference_count (N a L : ℕ) (sign : Fin L → Bool) (τ σ : Bool) : - (∑i : Fin N,if templateType N a L sign τ i=templateType N a L sign σ i then (0:ℝ) else 1) ≤ L := by - let S : Finset (Fin N) := Finset.univ.filter (fun i => a ≤ i.val ∧ i.val < a+L) - have hi (i : S) : a ≤ i.val.val ∧ i.val.val < a+L := (Finset.mem_filter.mp i.property).2 - let f : S → Fin L := fun i => ⟨i.val.val-a,by have h := hi i; omega⟩ - have hf : Function.Injective f := by - intro i j hij - have h := congrArg Fin.val hij - have h₁ := hi i - have h₂ := hi j - dsimp [f] at h - apply Subtype.ext - apply Fin.ext - omega - have hc : S.card ≤ L := by - simpa only [Fintype.card_coe,Fintype.card_fin] using Fintype.card_le_of_injective f hf - calc - _ ≤ ∑i : Fin N,if i∈S then (1:ℝ) else 0 := by - apply Finset.sum_le_sum - intro i _ - by_cases h : i∈S - · rw [ite_eq_left h]; split_ifs <;> norm_num - · have h' : ¬(a ≤ i.val ∧ i.val < a+L) := by simpa only [S,Finset.mem_filter,Finset.mem_univ,true_and] using h - simp [templateType,h',h] - _ = (S.card:ℝ) := by simp - _ ≤ L := by exact_mod_cast hc - -/-- Actual paired finite observations with a common complete-trace decoder - and a squared Hellinger bound. This auxiliary structure is constructed from - the source score oracle and closed under literal template substitution. -/ -structure HellingerTracePair (q : ℝ) (x y : List Bool) (E V : ℝ) where - Outcome : Type - finiteOutcome : Fintype Outcome - first : @FiniteLaw Outcome finiteOutcome - second : @FiniteLaw Outcome finiteOutcome - decode : Outcome → List Bool - first_simulation : @ApproximatesTrace Outcome finiteOutcome q first decode x E - second_simulation : @ApproximatesTrace Outcome finiteOutcome q second decode y E - bound : @FiniteLaw.hellingerSq Outcome finiteOutcome first second ≤ V - -def OracleTracePair.hellinger {q E V : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) (hk : 1 ≤ k) : HellingerTracePair q x y E V := by - let := C.finiteOutcome - exact { - Outcome := C.Outcome - finiteOutcome := C.finiteOutcome - first := C.first - second := C.second - decode := C.decode - first_simulation := C.first_simulation - second_simulation := C.second_simulation - bound := (C.first.hellingerSq_le_score C.second C.score C.density).trans - ((C.first.secondMoment_le_evenMomentSq C.score k hk).trans C.moment) } - -def HellingerTracePair.mix {q E V : ℝ} {x y : List Bool} (C : HellingerTracePair q x y E V) - (hq : q∈Set.Icc 0 1) {N : ℕ} (τ σ : Fin N → Bool) : - HellingerTracePair q (coordinateWord (fun i => if τ i then y else x)) - (coordinateWord (fun i => if σ i then y else x)) ((N:ℝ)*E) - ((∑i,if τ i=σ i then (0:ℝ) else 1)*V) := by - let := C.finiteOutcome - have ha (ρ : Fin N → Bool) : ApproximatesTrace q - (FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first)) - (fun z => coordinateWord (fun i => C.decode (z i))) - (coordinateWord (fun i => if ρ i then y else x)) ((N:ℝ)*E) := by - have H := coordinateProduct_approximates hq - (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) - (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) - · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H - · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] - · exact C.first_simulation - · exact C.second_simulation - exact { - Outcome := Fin N → C.Outcome - finiteOutcome := inferInstance - first := FiniteLaw.coordinateProduct (fun i => if τ i then C.second else C.first) - second := FiniteLaw.coordinateProduct (fun i => if σ i then C.second else C.first) - decode := fun z => coordinateWord (fun i => C.decode (z i)) - first_simulation := ha τ - second_simulation := ha σ - bound := FiniteLaw.hellingerSq_mixedProduct_le C.first C.second C.bound τ σ } - -def HellingerTracePair.weaken {q E V W : ℝ} {x y : List Bool} - (C : HellingerTracePair q x y E V) (h : V ≤ W) : HellingerTracePair q x y E W := - { C with bound := C.bound.trans h } - -def HellingerTracePair.template {q E V : ℝ} {x y : List Bool} (C : HellingerTracePair q x y E V) - (hq : q∈Set.Icc 0 1) (N a L : ℕ) (sign : Fin L → Bool) : - HellingerTracePair q - (complementaryWords N a L sign (fun τ => if τ then y else x) false) - (complementaryWords N a L sign (fun τ => if τ then y else x) true) ((N:ℝ)*E) ((L:ℝ)*V) := by - let := C.finiteOutcome - let D := C.mix hq (templateType N a L sign false) (templateType N a L sign true) - have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans C.bound - exact D.weaken (mul_le_mul_of_nonneg_right (templateType_difference_count N a L sign false true) hV) - -theorem HellingerTracePair.power_tv {q E V : ℝ} {x y : List Bool} - (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) - (F M : ℕ) (hx : (pureAtomRun x F).length ≤ M) (hy : (pureAtomRun y F).length ≤ M) : - (listTraceLaw q hq (pureAtomRun x F) M hx).tv - (listTraceLaw q hq (pureAtomRun y F) M hy) ≤ Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E := by - let := C.finiteOutcome - have htv := (FiniteLaw.tv_le_sqrt_hellingerSq (C.first.product F) (C.second.product F)).trans - (Real.sqrt_le_sqrt ((FiniteLaw.hellingerSq_product_le C.first C.second F).trans - (mul_le_mul_of_nonneg_left C.bound (Nat.cast_nonneg F)))) - have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hx hy - (C.first_simulation.power hq F) (C.second_simulation.power hq F) - linarith only [H,htv] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem templateType_one_count (N a L : ℕ) (sign : Fin L → Bool) (τ : Bool) : - (∑i : Fin N,if false=templateType N a L sign τ i then (0:ℝ) else 1) ≤ L := by - apply le_trans _ (templateType_difference_count N a L sign false true) - apply Finset.sum_le_sum - intro i _ - by_cases h : a ≤ i.val ∧ i.val < a+L - · simp only [templateType,dite_eq_left h] - cases hs : sign ⟨i.val-a,by omega⟩ <;> cases τ <;> norm_num - · simp [templateType,h] - -def HellingerTracePair.pure_template {q E V : ℝ} {x y : List Bool} - (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) - (N a L : ℕ) (sign : Fin L → Bool) (τ : Bool) : - HellingerTracePair q (pureAtomRun x N) - (complementaryWords N a L sign (fun υ => if υ then y else x) τ) ((N:ℝ)*E) ((L:ℝ)*V) := by - let := C.finiteOutcome - let D := C.mix hq (fun _ : Fin N => false) (templateType N a L sign τ) - have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans C.bound - have W := D.weaken (mul_le_mul_of_nonneg_right (templateType_one_count N a L sign τ) hV) - simp only [Bool.false_eq_true,ite_false,coordinateWord_constant] at W - exact W - -theorem bool_word_eta (w : Bool → List Bool) : (fun τ => if τ then w true else w false)=w := by - funext τ - cases τ <;> rfl - -/-- Literal dense substitution of the old auxiliary laws, used only for - overlap comparison. Statistical cost is paid only for differing motif - leaves, not the filler atoms. -/ -def sourceDensePair {q E V : ℝ} (hq : q∈Set.Icc 0 1) (s : ℕ) (P : ℕ → ℕ) - (atom : Bool → List Bool) (C : HellingerTracePair q (atom false) (atom true) E V) : - (j : ℕ) → HellingerTracePair q (sourceBlockWord s P atom j false) - (sourceBlockWord s P atom j true) ((sourceBlockLength P 1 j:ℝ)*E) (((2^s:ℕ):ℝ)^j*V) - | 0 => by simpa only [sourceBlockWord,sourceBlockLength,Nat.cast_one,pow_zero,one_mul] using C - | j+1 => by - have D := (sourceDensePair hq s P atom C j).template hq (P j) (P j/2-1) (2^s) (prouhetBool s) - rw [bool_word_eta] at D - simpa only [sourceBlockWord,sourceBlockLength,Nat.cast_mul,pow_succ, - mul_assoc,mul_left_comm,mul_comm] using D - -theorem HellingerTracePair.lifted_power_overlap {q E V p C₀ : ℝ} {w z : List Bool} - {h P F : ℕ} (O : HellingerTracePair q (pureAtomRun w P) z E V) - (hq : q∈Set.Icc 0 1) (hh : 1 ≤ h) (hP : 1 ≤ P) - (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) (hF : C₀*h*P ≤ F) - (hov : p ≤ listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) : - (2/3:ℝ)-(Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E)- - (Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E) ≤ - listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by - let a := pureAtomRun (pureAtomRun w P) F - let b := pureAtomRun (pureAtomRun w P) (F+1) - let x := pureAtomRun z F - let y := pureAtomRun z (F+1) - let M := max (max a.length b.length) (max x.length y.length) - have ha : a.length ≤ M := (le_max_left _ _).trans (le_max_left _ _) - have hb : b.length ≤ M := (le_max_right _ _).trans (le_max_left _ _) - have hx : x.length ≤ M := (le_max_left _ _).trans (le_max_right _ _) - have hy : y.length ≤ M := (le_max_right _ _).trans (le_max_right _ _) - have ht1 := O.power_tv hq F M ha hx - have ht2 := O.power_tv hq (F+1) M hb hy - have hol := listTraceOverlap_lift hh hP hp hq hC hF w hov - have he : F*P+P=(F+1)*P := by ring - have heA : pureAtomRun w (F*P)=a := (pureAtomRun_mul w P F).symm - have heB : pureAtomRun w (F*P+P)=b := by - rw [he]; exact (pureAtomRun_mul w P (F+1)).symm - rw [heA,heB] at hol - rw [listTraceOverlap_ambient hq _ _ M ha hb,FiniteLaw.overlap_eq_one_sub_tv] at hol - rw [listTraceOverlap_ambient hq _ _ M hx hy,FiniteLaw.overlap_eq_one_sub_tv] - have H := (FiniteLaw.tv_triangle (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha) - (listTraceLaw q hq y M hy)).trans - (add_le_add le_rfl (FiniteLaw.tv_triangle (listTraceLaw q hq a M ha) - (listTraceLaw q hq b M hb) (listTraceLaw q hq y M hy))) - rw [FiniteLaw.tv_symm (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha)] at H - linarith only [H,ht1,ht2,hol] - -theorem HellingerTracePair.lifted_overlap_quarter {q E V p C₀ : ℝ} {w z : List Bool} - {h P F : ℕ} (O : HellingerTracePair q (pureAtomRun w P) z E V) - (hq : q∈Set.Icc 0 1) (hE : 0 ≤ E) (hh : 1 ≤ h) (hP : 1 ≤ P) - (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) (hF : C₀*h*P ≤ F) - (hov : p ≤ listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) - (hsmall : Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E ≤ 1/4) : - p ≤ listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by - let := O.finiteOutcome - have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans O.bound - have ht := O.lifted_power_overlap hq hh hP hp hC hF hov - have hm : Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E ≤ - Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E := by - apply add_le_add - · apply Real.sqrt_le_sqrt - exact mul_le_mul_of_nonneg_right (by norm_num) hV - · exact mul_le_mul_of_nonneg_right (by norm_num) hE - linarith only [hm,hsmall,ht,hp.2] - -/-- Finite nested overlap induction at the main (post-warmup) dimensions. - Every closeness premise is an explicit scalar estimate on the old oracle; - the repeated-word overlaps themselves are proved, not assumed. -/ -theorem source_nested_overlap {q E V p C₀ : ℝ} (hq : q∈Set.Icc 0 1) - (hE : 0 ≤ E) (s : ℕ) (P h : ℕ → ℕ) (atom : Bool → List Bool) - (C : HellingerTracePair q (atom false) (atom true) E V) (b : ℕ) - (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) - (hcount : ∀j ≤ b,1 ≤ h j) (hP : ∀j < b,1 ≤ P j) - (hlift : ∀j < b,C₀*h j*P j ≤ h (j+1)) - (hsmall : ∀j < b, - Real.sqrt (((h (j+1)+1:ℕ):ℝ)*(((2^s:ℕ):ℝ)^(j+1)*V))+ - 2*((h (j+1)+1:ℕ):ℝ)*((sourceBlockLength P 1 (j+1):ℝ)*E) ≤ 1/4) - (hbase : p ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) - (pureAtomRun (atom false) (h 0+1))) : - ∀j ≤ b,p ≤ listTraceOverlap q hq (pureAtomRun (sourceBlockWord s P atom j false) (h j)) - (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by - intro j hj - induction j with - | zero => exact hbase - | succ j ih => - have hjb : j < b := by omega - have D := (sourceDensePair hq s P atom C j).pure_template hq (P j) (P j/2-1) (2^s) (prouhetBool s) false - rw [bool_word_eta] at D - have H := D.lifted_overlap_quarter hq (by positivity) (hcount j (by omega)) (hP j hjb) - hp hC (hlift j hjb) (ih (by omega)) ?_ - · exact H - · simpa only [sourceBlockLength,Nat.cast_mul,pow_succ,mul_assoc,mul_left_comm,mul_comm] - using hsmall j hjb - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - - -theorem sourceFitTail_nonneg (T n : ℕ → ℕ) (b : ℕ) : 0 ≤ sourceFitTail T n b := by - induction b with - | zero => rfl - | succ b ih => - cases b with - | zero => rfl - | succ b => exact mul_nonneg (Nat.cast_nonneg _) (add_nonneg (by positivity) ih) - -theorem sourceEffectiveHiddenTail_nonneg (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : - 0 ≤ sourceEffectiveHiddenTail T n b ω := by - apply Finset.sum_nonneg - intro v _ - split_ifs <;> positivity - -theorem sourceClippingCost_nonneg (T n : ℕ → ℕ) (s b k : ℕ) (ω a L : ℝ) (ha : 0 ≤ a) : - 0 ≤ sourceClippingCost T n s b k ω a L := by - exact add_nonneg (add_nonneg (sourceEffectiveHiddenTail_nonneg _ _ _ _) - (div_nonneg (sourceFitTail_nonneg _ _ _) ha)) (Real.sqrt_nonneg _) - -/-- The two-dimensional warmup uses the actual one-window cancellation - oracle at its second nested overlap step. No unproved side overlap is - inserted into the recursive source observation. -/ -theorem source_warmup_nested_overlap {q E V p C₀ : ℝ} (hq : q∈Set.Icc 0 1) - (hE : 0 ≤ E) (s k : ℕ) (P h : ℕ → ℕ) (atom : Bool → List Bool) - (C : OracleTracePair q (atom false) (atom true) k E V) - (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) - (hcount : ∀j ≤ 1,1 ≤ h j) (hP : ∀j < 2,1 ≤ P j) - (hlift : ∀j < 2,C₀*h j*P j ≤ h (j+1)) - (hfirst : Real.sqrt (((h 1+1:ℕ):ℝ)*((2^s:ℕ):ℝ)*V)+ - 2*((h 1+1:ℕ):ℝ)*((P 0:ℝ)*E) ≤ 1/4) - (hbase : p ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) - (pureAtomRun (atom false) (h 0+1))) - (T t : ℕ) (hT : 24 ≤ T) (he : Even T) (hMotif : 24*2^s ≤ T) - (hroot : 4*(t+1) ≤ T) (hfit : t*(2*h 0+1)+T ≤ P 0) - (a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hk : 1 ≤ k) (hV : V ≤ L^2) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount (fun _ => T) s 0 ≤ 1/2) - (hη : hiddenSmoothingBound t s p ≤ η) - (herror : sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L ≤ 1/2) - (hsecond : - Real.sqrt (((h 2+1:ℕ):ℝ)*((2^s:ℕ):ℝ)* - (64*sourceSharpEnergyBudget (fun _ => T) (fun _ => t) s 0 2 p η a ((6*(2*k:ℕ):ℝ)*L)))+ - 2*((h 2+1:ℕ):ℝ)*((P 1:ℝ)* - (sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L+(T:ℝ)*E)) ≤ 1/4) : - ∀j ≤ 2,p ≤ listTraceOverlap q hq (pureAtomRun (sourceBlockWord s P atom j false) (h j)) - (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by - have hp' : p∈Set.Ioo 0 1 := ⟨hp.1,lt_of_le_of_lt hp.2 (by norm_num)⟩ - have D := (C.hellinger hk).pure_template hq (P 0) (P 0/2-1) (2^s) (prouhetBool s) false - rw [bool_word_eta] at D - have h1 := D.lifted_overlap_quarter hq (by positivity) (hcount 0 (by omega)) - (hP 0 (by omega)) hp hC (hlift 0 (by omega)) hbase ?_ - · obtain ⟨W⟩ := actual_one_window_oracle C hq hE s (P 0) T t (h 0) 2 hT he hMotif - hroot hfit p a η L ha hL hp' hbase hk hV hscale hη herror - rw [bool_word_eta] at W - have W' := (W.hellinger hk).pure_template hq (P 1) (P 1/2-1) (2^s) (prouhetBool s) false - have heword : (fun τ => if τ then - complementaryWords (P 0) (P 0/2-1) (2^s) (prouhetBool s) atom true else - complementaryWords (P 0) (P 0/2-1) (2^s) (prouhetBool s) atom false) = - sourceBlockWord s P atom 1 := bool_word_eta _ - rw [heword] at W' - have hE' : 0 ≤ sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L+(T:ℝ)*E := by - exact add_nonneg (sourceClippingCost_nonneg _ _ _ _ _ _ _ _ ha.le) (by positivity) - have h2 := W'.lifted_overlap_quarter hq (mul_nonneg (Nat.cast_nonneg _) hE') - (hcount 1 le_rfl) (hP 1 (by omega)) hp hC (hlift 1 (by omega)) h1 ?_ - · intro j hj - interval_cases j - · exact hbase - · exact h1 - · exact h2 - · simpa only [mul_assoc] using hsecond - · simpa only [mul_assoc] using hfirst - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem OracleTracePair.error_nonneg {q E V : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) : 0 ≤ E := by - let := C.finiteOutcome - have h := C.first_simulation (fun _ => 0) (fun _ => ⟨le_rfl,zero_le_one⟩) - exact (abs_nonneg _).trans h - -/-- Finite main-block production: actual oracle, complete trace projection, - and all side overlaps follow from arithmetic budgets and the OLD invariant. - In particular none of the new side laws or their overlap are hypotheses. -/ -theorem actual_main_block {q E V ω C₀ : ℝ} (hq : q∈Set.Icc 0 1) - (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b R k : ℕ) - (C : OracleTracePair q (atom false) (atom true) k E V) - (H : SourceLayoutMargins s P T n h b) - (hTpos : ∀j,0 < T j) (hP : P b=n b*(2*h b+1)+T b) - (hn : ∀j < b,0 < n j) (hT : ∀j ≤ b,24 ≤ T j) (he : ∀j ≤ b,Even (T j)) - (hMotif : ∀j ≤ b,24*2^s ≤ T j) (hroot : 4*(n b+1) ≤ T b) - (a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hω : ω∈Set.Ioc 0 (1/8)) - (hk : 1 ≤ k) (hV : V ≤ L^2) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) - (hη : ∀j < b+1,hiddenSmoothingBound (n j) s ω ≤ η) - (herror : sourceClippingCost T n s b k ω a L ≤ 1/2) - (hC : 1073741824 ≤ ω*C₀) (hcount : ∀j ≤ b+1,1 ≤ h j) - (hpos : ∀j < b+1,1 ≤ P j) - (hlift : ∀j < b+1,C₀*h j*P j ≤ h (j+1)) - (hsmall : ∀j < b+1, - Real.sqrt (((h (j+1)+1:ℕ):ℝ)*(((2^s:ℕ):ℝ)^(j+1)*V))+ - 2*((h (j+1)+1:ℕ):ℝ)*((sourceBlockLength P 1 (j+1):ℝ)*E) ≤ 1/4) - (hbase : ω ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) - (pureAtomRun (atom false) (h 0+1))) : - Nonempty (OracleTracePair q (sourceBlockWord s P atom (b+1) false) - (sourceBlockWord s P atom (b+1) true) k - (sourceClippingCost T n s b k ω a L+(SourceLeafCount T (b+1):ℝ)*E+sourceFitTail T n (b+1)) - (64*sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))) ∧ - (∀j ≤ b+1,ω ≤ listTraceOverlap q hq - (pureAtomRun (sourceBlockWord s P atom j false) (h j)) - (pureAtomRun (sourceBlockWord s P atom j false) (h j+1))) := by - let := C.finiteOutcome - have hov := source_nested_overlap hq C.error_nonneg s P h atom (C.hellinger hk) (b+1) - hω hC hcount hpos hlift hsmall hbase - refine ⟨?_,hov⟩ - have hm : C.first.expect (fun z => |C.score z|^(2*k)) ≤ L^(2*k) := by - have H := C.first.expect_even_pow_le_of_moment C.score k hk (C.moment.trans hV) - simpa only [pow_mul] using H - exact actual_source_oracle hq C.error_nonneg s P T n h atom b R k H hTpos hP hn hT he hMotif hroot - C.first C.second C.decode C.score C.density C.likelihood_nonneg C.first_simulation C.second_simulation - ω a η L ha hL ⟨hω.1,lt_of_le_of_lt hω.2 (by norm_num)⟩ - (fun j hj => hov j (by omega)) hk hm hscale hη herror - -/-- Conversion of a produced genuine oracle into the manuscript invariant. - The scalar bounds here are exactly those to be discharged by scale margins. -/ -def OracleTracePair.toConcrete {q E V N Δ d ω F : ℝ} {x y : List Bool} {k i h : ℕ} - (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) - (hlen : x.length=y.length) (hne : x≠y) (hlo : N/2 ≤ (x.length:ℝ)) - (hhi : (x.length:ℝ) ≤ N) (herror : E/(x.length:ℝ) ≤ ((i:ℝ)+1)*Δ) - (hV : V ≤ N^(-d)) (hhlo : x.length ≤ h) (hhhi : (h:ℝ) ≤ F*(x.length:ℝ)) - (hov : ω ≤ listTraceOverlap q hq (pureAtomRun x h) (pureAtomRun x (h+1))) : - ConcreteLevelPair q hq N Δ d ω F i k := { - left := x - right := y - equalLength := hlen - different := hne - length_lower := hlo - length_upper := hhi - Outcome := C.Outcome - finiteOutcome := C.finiteOutcome - firstLaw := C.first - secondLaw := C.second - decode := C.decode - error := E - error_nonneg := C.error_nonneg - normalized_error := herror - first_simulation := C.first_simulation - second_simulation := C.second_simulation - score := C.score - density := C.density - score_bound := C.moment.trans hV - overlapCount := h - overlapCount_lower := hhlo - overlapCount_upper := hhhi - power_overlap := hov } - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.SourceOracle + +namespace OAI + +/-! +# Amplification + +Oracle products, mixed powers, padding, warmup and nested template Hellinger estimates, overlap, and block assembly. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The literal product/concatenation decoder charges only coordinates at + which the two deterministic input templates differ. -/ +theorem OracleTracePair.mixed_tv {q E V : ℝ} {x y : List Bool} {k n : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1≤k) + (τ σ : Fin n → Bool) (M : ℕ) + (hτ : (coordinateWord (fun i => if τ i then y else x)).length≤M) + (hσ : (coordinateWord (fun i => if σ i then y else x)).length≤M) : + (listTraceLaw q hq (coordinateWord (fun i => if τ i then y else x)) M hτ).tv + (listTraceLaw q hq (coordinateWord (fun i => if σ i then y else x)) M hσ) ≤ + Real.sqrt ((∑i,if τ i=σ i then (0:ℝ) else 1)*V)+2*(n:ℝ)*E := by + let := C.finiteOutcome + have ha (ρ : Fin n → Bool) : ApproximatesTrace q + (FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first)) + (fun z => coordinateWord (fun i => C.decode (z i))) + (coordinateWord (fun i => if ρ i then y else x)) ((n:ℝ)*E) := by + have H := coordinateProduct_approximates hq + (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) + (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) + · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H + · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] + · exact C.first_simulation + · exact C.second_simulation + have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hτ hσ (ha τ) (ha σ) + have htv := FiniteLaw.tv_mixedProduct_le C.first C.second C.score C.density k hk C.moment τ σ + linarith only [H,htv] + +theorem coordinateWord_constant (w : List Bool) (n : ℕ) : + coordinateWord (fun _ : Fin n => w)=pureAtomRun w n := by + induction n with + | zero => simp [coordinateWord,pureAtomRun] + | succ n ih => + rw [coordinateWord_succ,ih] + simp only [pureAtomRun,List.replicate_succ,List.flatten_cons] + +/-- Tensorization of a genuine approximate oracle, on actual word powers. -/ +theorem OracleTracePair.power_tv {q E V : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1≤k) + (n M : ℕ) (hx : (pureAtomRun x n).length≤M) (hy : (pureAtomRun y n).length≤M) : + (listTraceLaw q hq (pureAtomRun x n) M hx).tv + (listTraceLaw q hq (pureAtomRun y n) M hy) ≤ + Real.sqrt ((n:ℝ)*V)+2*(n:ℝ)*E := by + have H := C.mixed_tv hq hk (fun _ : Fin n => false) (fun _ => true) M + (by simpa only [Bool.false_eq_true,ite_false,coordinateWord_constant] using hx) + (by simpa only [ite_true,coordinateWord_constant] using hy) + simpa only [Bool.false_eq_true,ite_false,ite_true,coordinateWord_constant, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] using H + +/-- Genuine lifting for complete traces, with no auxiliary overlap hypothesis. -/ +theorem listTraceOverlap_lift {F k R : ℕ} {C p q : ℝ} + (hk : 1≤k) (hR : 1≤R) (hp : p∈Set.Ioc 0 (1/8)) (hq : q∈Set.Icc 0 1) + (hC : 1073741824≤p*C) (hF : C*k*R≤F) (w : List Bool) + (hov : p≤listTraceOverlap q hq (pureAtomRun w k) (pureAtomRun w (k+1))) : + (2/3:ℝ)≤listTraceOverlap q hq (pureAtomRun w (F*R)) (pureAtomRun w (F*R+R)) := by + let M := max (pureAtomRun w k).length (pureAtomRun w (k+1)).length + have H := adjacent_power_lift hk hR hp hq hC hF + (listTraceLaw q hq (pureAtomRun w k) M (le_max_left _ _)) + (listTraceLaw q hq (pureAtomRun w (k+1)) M (le_max_right _ _)) Subtype.val w + (listTraceLaw_simulates q hq _ M _) (listTraceLaw_simulates q hq _ M _) hov + obtain ⟨β,fin,P,Q,g,hP,hQ,hO⟩ := H + let := fin + exact hO.trans (simulations_overlap_le hq P Q g _ _ hP hQ) + +theorem pureAtomRun_mul (w : List Bool) (n m : ℕ) : + pureAtomRun (pureAtomRun w n) m=pureAtomRun w (m*n) := by + induction m with + | zero => simp [pureAtomRun] + | succ m ih => + have H : pureAtomRun (pureAtomRun w n) (m+1)= + pureAtomRun w n++pureAtomRun (pureAtomRun w n) m := by + simp [pureAtomRun,List.replicate_succ] + rw [H,ih,←pureAtomRun_add] + congr 1 + ring + +/-- Quantitative overlap transfer used for the initial pure comparison and + the small-dimensional warmup refinement. All three laws are ordinary traces. -/ +theorem OracleTracePair.lifted_power_overlap {q E V p C₀ : ℝ} {w z : List Bool} + {k h P F : ℕ} (O : OracleTracePair q (pureAtomRun w P) z k E V) + (hq : q∈Set.Icc 0 1) (hk : 1≤k) (hh : 1≤h) (hP : 1≤P) + (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824≤p*C₀) (hF : C₀*h*P≤F) + (hov : p≤listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) : + (2/3:ℝ)-(Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E)- + (Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E) ≤ + listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by + let a := pureAtomRun (pureAtomRun w P) F + let b := pureAtomRun (pureAtomRun w P) (F+1) + let x := pureAtomRun z F + let y := pureAtomRun z (F+1) + let M := max (max a.length b.length) (max x.length y.length) + have ha : a.length≤M := (le_max_left _ _).trans (le_max_left _ _) + have hb : b.length≤M := (le_max_right _ _).trans (le_max_left _ _) + have hx : x.length≤M := (le_max_left _ _).trans (le_max_right _ _) + have hy : y.length≤M := (le_max_right _ _).trans (le_max_right _ _) + have ht1 := O.power_tv hq hk F M ha hx + have ht2 := O.power_tv hq hk (F+1) M hb hy + have hol := listTraceOverlap_lift hh hP hp hq hC hF w hov + have he : F*P+P=(F+1)*P := by ring + have heA : pureAtomRun w (F*P)=a := (pureAtomRun_mul w P F).symm + have heB : pureAtomRun w (F*P+P)=b := by + rw [he]; exact (pureAtomRun_mul w P (F+1)).symm + rw [heA,heB] at hol + rw [listTraceOverlap_ambient hq _ _ M ha hb,FiniteLaw.overlap_eq_one_sub_tv] at hol + rw [listTraceOverlap_ambient hq _ _ M hx hy,FiniteLaw.overlap_eq_one_sub_tv] + have H := (FiniteLaw.tv_triangle (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha) + (listTraceLaw q hq y M hy)).trans + (add_le_add le_rfl (FiniteLaw.tv_triangle (listTraceLaw q hq a M ha) + (listTraceLaw q hq b M hb) (listTraceLaw q hq y M hy))) + rw [FiniteLaw.tv_symm (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha)] at H + linarith only [H,ht1,ht2,hol] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +theorem hellingerSq_mixedProduct_le {n : ℕ} (P Q : FiniteLaw α) {V : ℝ} + (hH : P.hellingerSq Q ≤ V) (τ σ : Fin n → Bool) : + (coordinateProduct (fun i => if τ i then Q else P)).hellingerSq + (coordinateProduct (fun i => if σ i then Q else P)) ≤ + (∑i,if τ i=σ i then (0:ℝ) else 1)*V := by + apply (hellingerSq_coordinateProduct_le _ _).trans + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro i _ + cases τ i <;> cases σ i <;> simp only [Bool.false_eq_true,Bool.true_eq_false, + ite_false,ite_true,zero_mul,one_mul,hellingerSq_self,le_refl] + · exact hH + · rw [hellingerSq_symm]; exact hH + +end FiniteLaw + +theorem ApproximatesTrace.power {α : Type*} [Fintype α] {q E : ℝ} {P : FiniteLaw α} + {g : α → List Bool} {w : List Bool} (H : ApproximatesTrace q P g w E) + (hq : q∈Set.Icc 0 1) (F : ℕ) : + ApproximatesTrace q (P.product F) (fun z => coordinateWord (fun i => g (z i))) + (pureAtomRun w F) ((F:ℝ)*E) := by + have h := coordinateProduct_approximates hq (fun _ : Fin F => P) (fun _ => g) + (fun _ => w) (fun _ => E) (fun _ => H) + have he : FiniteLaw.coordinateProduct (fun _ : Fin F => P)=P.product F := rfl + rw [he,coordinateWord_constant] at h + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using h + +/-- Repeated mixed templates pay only for the differing leaves in squared + Hellinger, while approximate leaf simulation is charged linearly. -/ +theorem OracleTracePair.mixed_power_tv {q E V : ℝ} {x y : List Bool} {k n : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hk : 1 ≤ k) + (τ σ : Fin n → Bool) (F M : ℕ) + (hτ : (pureAtomRun (coordinateWord (fun i => if τ i then y else x)) F).length ≤ M) + (hσ : (pureAtomRun (coordinateWord (fun i => if σ i then y else x)) F).length ≤ M) : + (listTraceLaw q hq (pureAtomRun (coordinateWord (fun i => if τ i then y else x)) F) M hτ).tv + (listTraceLaw q hq (pureAtomRun (coordinateWord (fun i => if σ i then y else x)) F) M hσ) ≤ + Real.sqrt ((F:ℝ)*(∑i,if τ i=σ i then (0:ℝ) else 1)*V)+2*(F:ℝ)*(n:ℝ)*E := by + let := C.finiteOutcome + let A (ρ : Fin n → Bool) := FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first) + let g (z : Fin n → C.Outcome) := coordinateWord (fun i => C.decode (z i)) + have ha (ρ : Fin n → Bool) : ApproximatesTrace q (A ρ) g + (coordinateWord (fun i => if ρ i then y else x)) ((n:ℝ)*E) := by + have H := coordinateProduct_approximates hq + (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) + (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) + · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H + · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] + · exact C.first_simulation + · exact C.second_simulation + have hH : C.first.hellingerSq C.second ≤ V := + (C.first.hellingerSq_le_score C.second C.score C.density).trans + ((C.first.secondMoment_le_evenMomentSq C.score k hk).trans C.moment) + have hm := FiniteLaw.hellingerSq_mixedProduct_le C.first C.second hH τ σ + have hp := (FiniteLaw.hellingerSq_product_le (A τ) (A σ) F).trans + (mul_le_mul_of_nonneg_left hm (Nat.cast_nonneg F)) + have htv := (FiniteLaw.tv_le_sqrt_hellingerSq ((A τ).product F) ((A σ).product F)).trans + (Real.sqrt_le_sqrt hp) + have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hτ hσ + ((ha τ).power hq F) ((ha σ).power hq F) + rw [←mul_assoc] at htv + linarith only [H,htv] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- An exact common prefix and suffix are observed as ordinary independent + complete traces. They neither change the score moment nor cost simulation + error. This is the source's deterministic residual convention. -/ +def OracleTracePair.pad {q E V : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (u v : List Bool) : + OracleTracePair q (u++x++v) (u++y++v) k E V := by + let := C.finiteOutcome + let P := listTraceLaw q hq u u.length le_rfl + let Q := listTraceLaw q hq v v.length le_rfl + refine { + Outcome := (BoundedTrace u.length × C.Outcome) × BoundedTrace v.length + finiteOutcome := inferInstance + first := (P.prod C.first).prod Q + second := (P.prod C.second).prod Q + decode := fun z => z.1.1.val++C.decode z.1.2++z.2.val + score := fun z => C.score z.1.2 + density := by + intro z + change (P.mass z.1.1*C.second.mass z.1.2)*Q.mass z.2=_ + rw [C.density] + change _=(P.mass z.1.1*C.first.mass z.1.2)*Q.mass z.2*(1+C.score z.1.2) + ring + likelihood_nonneg := fun z => C.likelihood_nonneg z.1.2 + centered := by + simp only [FiniteLaw.expect_prod,FiniteLaw.expect_const,C.centered] + moment := by + simpa only [FiniteLaw.evenMomentSq,FiniteLaw.expect_prod,FiniteLaw.expect_const] using C.moment + first_simulation := by + have H := ((listTraceLaw_simulates q hq u u.length le_rfl).approximate.append hq + C.first_simulation).append hq (listTraceLaw_simulates q hq v v.length le_rfl).approximate + simpa only [zero_add,add_zero] using H + second_simulation := by + have H := ((listTraceLaw_simulates q hq u u.length le_rfl).approximate.append hq + C.second_simulation).append hq (listTraceLaw_simulates q hq v v.length le_rfl).approximate + simpa only [zero_add,add_zero] using H } + +/-- Literal template equality under deterministic pure residual padding. -/ +theorem complementaryWords_pad (L P R a len : ℕ) (sign : Fin len → Bool) + (w : Bool → List Bool) (τ : Bool) (hfit : a+len ≤ P) : + complementaryWords (L+P+R) (L+a) len sign w τ = + pureAtomRun (w false) L++complementaryWords P a len sign w τ++pureAtomRun (w false) R := by + unfold complementaryWords + rw [atomString_three] + have hp (i : Fin L) : templateType (L+P+R) (L+a) len sign τ ⟨i.val,by omega⟩=false := by + have hi := i.isLt + simp only [templateType,dite_eq_right (by omega : ¬(L+a ≤ i.val ∧ i.val < L+a+len))] + have hm (i : Fin P) : templateType (L+P+R) (L+a) len sign τ ⟨L+i.val,by omega⟩= + templateType P a len sign τ i := by + unfold templateType + split_ifs with h h' h' + · congr 2 + apply Fin.ext + simp only + omega + · simp only at h + omega + · simp only at h + omega + · rfl + have hr (i : Fin R) : templateType (L+P+R) (L+a) len sign τ ⟨L+P+i.val,by omega⟩=false := by + simp only [templateType,dite_eq_right (by omega : ¬(L+a ≤ L+P+i.val ∧ L+P+i.val < L+a+len))] + simp_rw [hp,hm,hr] + change coordinateWord (fun _ : Fin L => w false)++_++coordinateWord (fun _ : Fin R => w false)=_ + rw [coordinateWord_constant,coordinateWord_constant] + +def centeredLeftResidual (N P : ℕ) : ℕ := N/2-1-(P/2-1) +def centeredRightResidual (N P : ℕ) : ℕ := N-(centeredLeftResidual N P+P) + +theorem centeredResidual_geometry {N P : ℕ} (hP : 2 ≤ P) (hN : P ≤ N) : + centeredLeftResidual N P+P+centeredRightResidual N P=N ∧ + centeredLeftResidual N P+(P/2-1)=N/2-1 := by + simp only [centeredRightResidual,centeredLeftResidual] + omega + +/-- The auxiliary one-window oracle is centered at the same actual source + motif after appending pure residuals, also for odd ambient atom counts. -/ +theorem centeredComplementaryWords_pad (N P s : ℕ) (w : Bool → List Bool) (τ : Bool) + (hP : 2 ≤ P) (hN : P ≤ N) (hfit : P/2-1+2^s ≤ P) : + complementaryWords N (N/2-1) (2^s) (prouhetBool s) w τ = + pureAtomRun (w false) (centeredLeftResidual N P)++ + complementaryWords P (P/2-1) (2^s) (prouhetBool s) w τ++ + pureAtomRun (w false) (centeredRightResidual N P) := by + have h := complementaryWords_pad (centeredLeftResidual N P) P (centeredRightResidual N P) + (P/2-1) (2^s) (prouhetBool s) w τ hfit + rw [(centeredResidual_geometry hP hN).1,(centeredResidual_geometry hP hN).2] at h + exact h + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The source's special one-window warmup observation. The ambient word + need not have the root's arithmetic divisibility: exact pure residuals + restore its literal center, at no additional statistical error. -/ +theorem actual_one_window_oracle {q E V : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) (hE : 0 ≤ E) + (s N T t h R : ℕ) (hT : 24 ≤ T) (he : Even T) + (hMotif : 24*2^s ≤ T) (hroot : 4*(t+1) ≤ T) + (hfit : t*(2*h+1)+T ≤ N) + (ω a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hω : ω∈Set.Ioo 0 1) + (hov : ω ≤ listTraceOverlap q hq (pureAtomRun x h) (pureAtomRun x (h+1))) + (hk : 1 ≤ k) (hV : V ≤ L^2) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount (fun _ => T) s 0 ≤ 1/2) + (hη : hiddenSmoothingBound t s ω ≤ η) + (herror : sourceClippingCost (fun _ => T) (fun _ => t) s 0 k ω a L ≤ 1/2) : + Nonempty (OracleTracePair q + (complementaryWords N (N/2-1) (2^s) (prouhetBool s) (fun τ => if τ then y else x) false) + (complementaryWords N (N/2-1) (2^s) (prouhetBool s) (fun τ => if τ then y else x) true) k + (sourceClippingCost (fun _ => T) (fun _ => t) s 0 k ω a L+(T:ℝ)*E) + (64*sourceSharpEnergyBudget (fun _ => T) (fun _ => t) s 0 R ω η a ((6*(2*k:ℕ):ℝ)*L))) := by + let := C.finiteOutcome + let p := t*(2*h+1)+T + let atom : Bool → List Bool := fun τ => if τ then y else x + have H : SourceLayoutMargins s (fun _ => p) (fun _ => T) (fun _ => t) (fun _ => h) 0 := by + constructor <;> intro j hj <;> omega + have hm : C.first.expect (fun z => |C.score z|^(2*k)) ≤ L^(2*k) := by + have hv := C.first.expect_even_pow_le_of_moment C.score k hk (C.moment.trans hV) + simpa only [pow_mul] using hv + obtain ⟨W⟩ := actual_source_oracle hq hE s (fun _ => p) (fun _ => T) (fun _ => t) + (fun _ => h) atom 0 R k H (fun _ => by omega) rfl + (fun j hj => by omega) (fun _ _ => hT) (fun _ _ => he) (fun _ _ => hMotif) hroot + C.first C.second C.decode C.score C.density C.likelihood_nonneg + C.first_simulation C.second_simulation ω a η L ha hL hω + (fun j hj => by + have hj' : j=0 := by omega + subst j + exact hov) + hk hm hscale (fun _ _ => hη) herror + have hp : 2 ≤ p := by dsimp [p]; omega + have hmp : p/2-1+2^s ≤ p := by dsimp [p] at *; omega + let U := pureAtomRun x (centeredLeftResidual N p) + let B := pureAtomRun x (centeredRightResidual N p) + have heq (τ : Bool) := centeredComplementaryWords_pad N p s atom τ hp hfit hmp + have HH := W.pad hq U B + simp only [sourceBlockWord,sourceFitTail,add_zero] at HH + change OracleTracePair q + (U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom false++B) + (U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom true++B) k _ _ at HH + have hleft : U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom false++B = + complementaryWords N (N/2-1) (2^s) (prouhetBool s) atom false := (heq false).symm + have hright : U++complementaryWords p (p/2-1) (2^s) (prouhetBool s) atom true++B = + complementaryWords N (N/2-1) (2^s) (prouhetBool s) atom true := (heq true).symm + rw [hleft,hright] at HH + have hc : SourceLeafCount (fun _ => T) 1=T := by + calc + _ = Fintype.card (Fin (T*1)) := Fintype.card_congr finProdFinEquiv + _ = T := by simp + simp only [hc] at HH + exact ⟨HH⟩ + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem sourceLeafCount_one (T : ℕ → ℕ) : SourceLeafCount T 1=T 0 := by + calc + _ = Fintype.card (Fin (T 0*1)) := Fintype.card_congr finProdFinEquiv + _ = T 0 := by simp + +/-- Exact two-degree cutoff for the one-window warmup refinement. In + particular the remaining geometric term is quadratic in the old energy. -/ +theorem sourceSharpEnergyBudget_one_window (T n : ℕ → ℕ) (s : ℕ) (ω η a w : ℝ) : + sourceSharpEnergyBudget T n s 0 2 ω η a w = + 36*(T 0:ℝ)*w^2*(η^2+a^2)+4*(w^2*2^s)^2/(1-w^2*2^s) := by + simp only [sourceSharpEnergyBudget,Finset.sum_range_succ,Finset.sum_range_zero] + norm_num [sourceSharpDegreeBudget,sourceSparseCount,sourceLeafCount_one,Nat.choose_one_right] + ring + +theorem sourceSharpEnergyBudget_warmup (T n : ℕ → ℕ) (s : ℕ) (ω η w : ℝ) + (h : w^2*2^s ≤ 1/2) : + sourceSharpEnergyBudget T n s 0 2 ω η η w ≤ + 72*(T 0:ℝ)*w^2*η^2+8*(w^2*2^s)^2 := by + rw [sourceSharpEnergyBudget_one_window] + have hd : 0 < 1-w^2*2^s := by linarith + have hb : 4*(w^2*2^s)^2/(1-w^2*2^s) ≤ 8*(w^2*2^s)^2 := by + apply (div_le_iff₀ hd).mpr + have hh := mul_le_mul_of_nonneg_left h (sq_nonneg (w^2*2^s)) + nlinarith only [hh] + nlinarith only [hb] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The number of differing labels of complementary templates is bounded + by the actual motif length, without any assumption that it fills the word. -/ +theorem templateType_difference_count (N a L : ℕ) (sign : Fin L → Bool) (τ σ : Bool) : + (∑i : Fin N,if templateType N a L sign τ i=templateType N a L sign σ i then (0:ℝ) else 1) ≤ L := by + let S : Finset (Fin N) := Finset.univ.filter (fun i => a ≤ i.val ∧ i.val < a+L) + have hi (i : S) : a ≤ i.val.val ∧ i.val.val < a+L := (Finset.mem_filter.mp i.property).2 + let f : S → Fin L := fun i => ⟨i.val.val-a,by have h := hi i; omega⟩ + have hf : Function.Injective f := by + intro i j hij + have h := congrArg Fin.val hij + have h₁ := hi i + have h₂ := hi j + dsimp [f] at h + apply Subtype.ext + apply Fin.ext + omega + have hc : S.card ≤ L := by + simpa only [Fintype.card_coe,Fintype.card_fin] using Fintype.card_le_of_injective f hf + calc + _ ≤ ∑i : Fin N,if i∈S then (1:ℝ) else 0 := by + apply Finset.sum_le_sum + intro i _ + by_cases h : i∈S + · rw [ite_eq_left h]; split_ifs <;> norm_num + · have h' : ¬(a ≤ i.val ∧ i.val < a+L) := by simpa only [S,Finset.mem_filter,Finset.mem_univ,true_and] using h + simp [templateType,h',h] + _ = (S.card:ℝ) := by simp + _ ≤ L := by exact_mod_cast hc + +/-- Actual paired finite observations with a common complete-trace decoder + and a squared Hellinger bound. This auxiliary structure is constructed from + the source score oracle and closed under literal template substitution. -/ +structure HellingerTracePair (q : ℝ) (x y : List Bool) (E V : ℝ) where + Outcome : Type + finiteOutcome : Fintype Outcome + first : @FiniteLaw Outcome finiteOutcome + second : @FiniteLaw Outcome finiteOutcome + decode : Outcome → List Bool + first_simulation : @ApproximatesTrace Outcome finiteOutcome q first decode x E + second_simulation : @ApproximatesTrace Outcome finiteOutcome q second decode y E + bound : @FiniteLaw.hellingerSq Outcome finiteOutcome first second ≤ V + +def OracleTracePair.hellinger {q E V : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) (hk : 1 ≤ k) : HellingerTracePair q x y E V := by + let := C.finiteOutcome + exact { + Outcome := C.Outcome + finiteOutcome := C.finiteOutcome + first := C.first + second := C.second + decode := C.decode + first_simulation := C.first_simulation + second_simulation := C.second_simulation + bound := (C.first.hellingerSq_le_score C.second C.score C.density).trans + ((C.first.secondMoment_le_evenMomentSq C.score k hk).trans C.moment) } + +def HellingerTracePair.mix {q E V : ℝ} {x y : List Bool} (C : HellingerTracePair q x y E V) + (hq : q∈Set.Icc 0 1) {N : ℕ} (τ σ : Fin N → Bool) : + HellingerTracePair q (coordinateWord (fun i => if τ i then y else x)) + (coordinateWord (fun i => if σ i then y else x)) ((N:ℝ)*E) + ((∑i,if τ i=σ i then (0:ℝ) else 1)*V) := by + let := C.finiteOutcome + have ha (ρ : Fin N → Bool) : ApproximatesTrace q + (FiniteLaw.coordinateProduct (fun i => if ρ i then C.second else C.first)) + (fun z => coordinateWord (fun i => C.decode (z i))) + (coordinateWord (fun i => if ρ i then y else x)) ((N:ℝ)*E) := by + have H := coordinateProduct_approximates hq + (fun i => if ρ i then C.second else C.first) (fun _ => C.decode) + (fun i => if ρ i then y else x) (fun _ => E) (fun i => ?_) + · simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using H + · cases ρ i <;> simp only [Bool.false_eq_true,ite_false,ite_true] + · exact C.first_simulation + · exact C.second_simulation + exact { + Outcome := Fin N → C.Outcome + finiteOutcome := inferInstance + first := FiniteLaw.coordinateProduct (fun i => if τ i then C.second else C.first) + second := FiniteLaw.coordinateProduct (fun i => if σ i then C.second else C.first) + decode := fun z => coordinateWord (fun i => C.decode (z i)) + first_simulation := ha τ + second_simulation := ha σ + bound := FiniteLaw.hellingerSq_mixedProduct_le C.first C.second C.bound τ σ } + +def HellingerTracePair.weaken {q E V W : ℝ} {x y : List Bool} + (C : HellingerTracePair q x y E V) (h : V ≤ W) : HellingerTracePair q x y E W := + { C with bound := C.bound.trans h } + +def HellingerTracePair.template {q E V : ℝ} {x y : List Bool} (C : HellingerTracePair q x y E V) + (hq : q∈Set.Icc 0 1) (N a L : ℕ) (sign : Fin L → Bool) : + HellingerTracePair q + (complementaryWords N a L sign (fun τ => if τ then y else x) false) + (complementaryWords N a L sign (fun τ => if τ then y else x) true) ((N:ℝ)*E) ((L:ℝ)*V) := by + let := C.finiteOutcome + let D := C.mix hq (templateType N a L sign false) (templateType N a L sign true) + have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans C.bound + exact D.weaken (mul_le_mul_of_nonneg_right (templateType_difference_count N a L sign false true) hV) + +theorem HellingerTracePair.power_tv {q E V : ℝ} {x y : List Bool} + (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) + (F M : ℕ) (hx : (pureAtomRun x F).length ≤ M) (hy : (pureAtomRun y F).length ≤ M) : + (listTraceLaw q hq (pureAtomRun x F) M hx).tv + (listTraceLaw q hq (pureAtomRun y F) M hy) ≤ Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E := by + let := C.finiteOutcome + have htv := (FiniteLaw.tv_le_sqrt_hellingerSq (C.first.product F) (C.second.product F)).trans + (Real.sqrt_le_sqrt ((FiniteLaw.hellingerSq_product_le C.first C.second F).trans + (mul_le_mul_of_nonneg_left C.bound (Nat.cast_nonneg F)))) + have H := approximations_trace_tv hq _ _ _ _ _ _ _ M hx hy + (C.first_simulation.power hq F) (C.second_simulation.power hq F) + linarith only [H,htv] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem templateType_one_count (N a L : ℕ) (sign : Fin L → Bool) (τ : Bool) : + (∑i : Fin N,if false=templateType N a L sign τ i then (0:ℝ) else 1) ≤ L := by + apply le_trans _ (templateType_difference_count N a L sign false true) + apply Finset.sum_le_sum + intro i _ + by_cases h : a ≤ i.val ∧ i.val < a+L + · simp only [templateType,dite_eq_left h] + cases hs : sign ⟨i.val-a,by omega⟩ <;> cases τ <;> norm_num + · simp [templateType,h] + +def HellingerTracePair.pure_template {q E V : ℝ} {x y : List Bool} + (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) + (N a L : ℕ) (sign : Fin L → Bool) (τ : Bool) : + HellingerTracePair q (pureAtomRun x N) + (complementaryWords N a L sign (fun υ => if υ then y else x) τ) ((N:ℝ)*E) ((L:ℝ)*V) := by + let := C.finiteOutcome + let D := C.mix hq (fun _ : Fin N => false) (templateType N a L sign τ) + have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans C.bound + have W := D.weaken (mul_le_mul_of_nonneg_right (templateType_one_count N a L sign τ) hV) + simp only [Bool.false_eq_true,ite_false,coordinateWord_constant] at W + exact W + +theorem bool_word_eta (w : Bool → List Bool) : (fun τ => if τ then w true else w false)=w := by + funext τ + cases τ <;> rfl + +/-- Literal dense substitution of the old auxiliary laws, used only for + overlap comparison. Statistical cost is paid only for differing motif + leaves, not the filler atoms. -/ +def sourceDensePair {q E V : ℝ} (hq : q∈Set.Icc 0 1) (s : ℕ) (P : ℕ → ℕ) + (atom : Bool → List Bool) (C : HellingerTracePair q (atom false) (atom true) E V) : + (j : ℕ) → HellingerTracePair q (sourceBlockWord s P atom j false) + (sourceBlockWord s P atom j true) ((sourceBlockLength P 1 j:ℝ)*E) (((2^s:ℕ):ℝ)^j*V) + | 0 => by simpa only [sourceBlockWord,sourceBlockLength,Nat.cast_one,pow_zero,one_mul] using C + | j+1 => by + have D := (sourceDensePair hq s P atom C j).template hq (P j) (P j/2-1) (2^s) (prouhetBool s) + rw [bool_word_eta] at D + simpa only [sourceBlockWord,sourceBlockLength,Nat.cast_mul,pow_succ, + mul_assoc,mul_left_comm,mul_comm] using D + +theorem HellingerTracePair.lifted_power_overlap {q E V p C₀ : ℝ} {w z : List Bool} + {h P F : ℕ} (O : HellingerTracePair q (pureAtomRun w P) z E V) + (hq : q∈Set.Icc 0 1) (hh : 1 ≤ h) (hP : 1 ≤ P) + (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) (hF : C₀*h*P ≤ F) + (hov : p ≤ listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) : + (2/3:ℝ)-(Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E)- + (Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E) ≤ + listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by + let a := pureAtomRun (pureAtomRun w P) F + let b := pureAtomRun (pureAtomRun w P) (F+1) + let x := pureAtomRun z F + let y := pureAtomRun z (F+1) + let M := max (max a.length b.length) (max x.length y.length) + have ha : a.length ≤ M := (le_max_left _ _).trans (le_max_left _ _) + have hb : b.length ≤ M := (le_max_right _ _).trans (le_max_left _ _) + have hx : x.length ≤ M := (le_max_left _ _).trans (le_max_right _ _) + have hy : y.length ≤ M := (le_max_right _ _).trans (le_max_right _ _) + have ht1 := O.power_tv hq F M ha hx + have ht2 := O.power_tv hq (F+1) M hb hy + have hol := listTraceOverlap_lift hh hP hp hq hC hF w hov + have he : F*P+P=(F+1)*P := by ring + have heA : pureAtomRun w (F*P)=a := (pureAtomRun_mul w P F).symm + have heB : pureAtomRun w (F*P+P)=b := by + rw [he]; exact (pureAtomRun_mul w P (F+1)).symm + rw [heA,heB] at hol + rw [listTraceOverlap_ambient hq _ _ M ha hb,FiniteLaw.overlap_eq_one_sub_tv] at hol + rw [listTraceOverlap_ambient hq _ _ M hx hy,FiniteLaw.overlap_eq_one_sub_tv] + have H := (FiniteLaw.tv_triangle (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha) + (listTraceLaw q hq y M hy)).trans + (add_le_add le_rfl (FiniteLaw.tv_triangle (listTraceLaw q hq a M ha) + (listTraceLaw q hq b M hb) (listTraceLaw q hq y M hy))) + rw [FiniteLaw.tv_symm (listTraceLaw q hq x M hx) (listTraceLaw q hq a M ha)] at H + linarith only [H,ht1,ht2,hol] + +theorem HellingerTracePair.lifted_overlap_quarter {q E V p C₀ : ℝ} {w z : List Bool} + {h P F : ℕ} (O : HellingerTracePair q (pureAtomRun w P) z E V) + (hq : q∈Set.Icc 0 1) (hE : 0 ≤ E) (hh : 1 ≤ h) (hP : 1 ≤ P) + (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) (hF : C₀*h*P ≤ F) + (hov : p ≤ listTraceOverlap q hq (pureAtomRun w h) (pureAtomRun w (h+1))) + (hsmall : Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E ≤ 1/4) : + p ≤ listTraceOverlap q hq (pureAtomRun z F) (pureAtomRun z (F+1)) := by + let := O.finiteOutcome + have hV : 0 ≤ V := (FiniteLaw.hellingerSq_nonneg _ _).trans O.bound + have ht := O.lifted_power_overlap hq hh hP hp hC hF hov + have hm : Real.sqrt ((F:ℝ)*V)+2*(F:ℝ)*E ≤ + Real.sqrt (((F+1:ℕ):ℝ)*V)+2*((F+1:ℕ):ℝ)*E := by + apply add_le_add + · apply Real.sqrt_le_sqrt + exact mul_le_mul_of_nonneg_right (by norm_num) hV + · exact mul_le_mul_of_nonneg_right (by norm_num) hE + linarith only [hm,hsmall,ht,hp.2] + +/-- Finite nested overlap induction at the main (post-warmup) dimensions. + Every closeness premise is an explicit scalar estimate on the old oracle; + the repeated-word overlaps themselves are proved, not assumed. -/ +theorem source_nested_overlap {q E V p C₀ : ℝ} (hq : q∈Set.Icc 0 1) + (hE : 0 ≤ E) (s : ℕ) (P h : ℕ → ℕ) (atom : Bool → List Bool) + (C : HellingerTracePair q (atom false) (atom true) E V) (b : ℕ) + (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) + (hcount : ∀j ≤ b,1 ≤ h j) (hP : ∀j < b,1 ≤ P j) + (hlift : ∀j < b,C₀*h j*P j ≤ h (j+1)) + (hsmall : ∀j < b, + Real.sqrt (((h (j+1)+1:ℕ):ℝ)*(((2^s:ℕ):ℝ)^(j+1)*V))+ + 2*((h (j+1)+1:ℕ):ℝ)*((sourceBlockLength P 1 (j+1):ℝ)*E) ≤ 1/4) + (hbase : p ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) + (pureAtomRun (atom false) (h 0+1))) : + ∀j ≤ b,p ≤ listTraceOverlap q hq (pureAtomRun (sourceBlockWord s P atom j false) (h j)) + (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by + intro j hj + induction j with + | zero => exact hbase + | succ j ih => + have hjb : j < b := by omega + have D := (sourceDensePair hq s P atom C j).pure_template hq (P j) (P j/2-1) (2^s) (prouhetBool s) false + rw [bool_word_eta] at D + have H := D.lifted_overlap_quarter hq (by positivity) (hcount j (by omega)) (hP j hjb) + hp hC (hlift j hjb) (ih (by omega)) ?_ + · exact H + · simpa only [sourceBlockLength,Nat.cast_mul,pow_succ,mul_assoc,mul_left_comm,mul_comm] + using hsmall j hjb + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + + +theorem sourceFitTail_nonneg (T n : ℕ → ℕ) (b : ℕ) : 0 ≤ sourceFitTail T n b := by + induction b with + | zero => rfl + | succ b ih => + cases b with + | zero => rfl + | succ b => exact mul_nonneg (Nat.cast_nonneg _) (add_nonneg (by positivity) ih) + +theorem sourceEffectiveHiddenTail_nonneg (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : + 0 ≤ sourceEffectiveHiddenTail T n b ω := by + apply Finset.sum_nonneg + intro v _ + split_ifs <;> positivity + +theorem sourceClippingCost_nonneg (T n : ℕ → ℕ) (s b k : ℕ) (ω a L : ℝ) (ha : 0 ≤ a) : + 0 ≤ sourceClippingCost T n s b k ω a L := by + exact add_nonneg (add_nonneg (sourceEffectiveHiddenTail_nonneg _ _ _ _) + (div_nonneg (sourceFitTail_nonneg _ _ _) ha)) (Real.sqrt_nonneg _) + +/-- The two-dimensional warmup uses the actual one-window cancellation + oracle at its second nested overlap step. No unproved side overlap is + inserted into the recursive source observation. -/ +theorem source_warmup_nested_overlap {q E V p C₀ : ℝ} (hq : q∈Set.Icc 0 1) + (hE : 0 ≤ E) (s k : ℕ) (P h : ℕ → ℕ) (atom : Bool → List Bool) + (C : OracleTracePair q (atom false) (atom true) k E V) + (hp : p∈Set.Ioc 0 (1/8)) (hC : 1073741824 ≤ p*C₀) + (hcount : ∀j ≤ 1,1 ≤ h j) (hP : ∀j < 2,1 ≤ P j) + (hlift : ∀j < 2,C₀*h j*P j ≤ h (j+1)) + (hfirst : Real.sqrt (((h 1+1:ℕ):ℝ)*((2^s:ℕ):ℝ)*V)+ + 2*((h 1+1:ℕ):ℝ)*((P 0:ℝ)*E) ≤ 1/4) + (hbase : p ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) + (pureAtomRun (atom false) (h 0+1))) + (T t : ℕ) (hT : 24 ≤ T) (he : Even T) (hMotif : 24*2^s ≤ T) + (hroot : 4*(t+1) ≤ T) (hfit : t*(2*h 0+1)+T ≤ P 0) + (a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hk : 1 ≤ k) (hV : V ≤ L^2) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount (fun _ => T) s 0 ≤ 1/2) + (hη : hiddenSmoothingBound t s p ≤ η) + (herror : sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L ≤ 1/2) + (hsecond : + Real.sqrt (((h 2+1:ℕ):ℝ)*((2^s:ℕ):ℝ)* + (64*sourceSharpEnergyBudget (fun _ => T) (fun _ => t) s 0 2 p η a ((6*(2*k:ℕ):ℝ)*L)))+ + 2*((h 2+1:ℕ):ℝ)*((P 1:ℝ)* + (sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L+(T:ℝ)*E)) ≤ 1/4) : + ∀j ≤ 2,p ≤ listTraceOverlap q hq (pureAtomRun (sourceBlockWord s P atom j false) (h j)) + (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by + have hp' : p∈Set.Ioo 0 1 := ⟨hp.1,lt_of_le_of_lt hp.2 (by norm_num)⟩ + have D := (C.hellinger hk).pure_template hq (P 0) (P 0/2-1) (2^s) (prouhetBool s) false + rw [bool_word_eta] at D + have h1 := D.lifted_overlap_quarter hq (by positivity) (hcount 0 (by omega)) + (hP 0 (by omega)) hp hC (hlift 0 (by omega)) hbase ?_ + · obtain ⟨W⟩ := actual_one_window_oracle C hq hE s (P 0) T t (h 0) 2 hT he hMotif + hroot hfit p a η L ha hL hp' hbase hk hV hscale hη herror + rw [bool_word_eta] at W + have W' := (W.hellinger hk).pure_template hq (P 1) (P 1/2-1) (2^s) (prouhetBool s) false + have heword : (fun τ => if τ then + complementaryWords (P 0) (P 0/2-1) (2^s) (prouhetBool s) atom true else + complementaryWords (P 0) (P 0/2-1) (2^s) (prouhetBool s) atom false) = + sourceBlockWord s P atom 1 := bool_word_eta _ + rw [heword] at W' + have hE' : 0 ≤ sourceClippingCost (fun _ => T) (fun _ => t) s 0 k p a L+(T:ℝ)*E := by + exact add_nonneg (sourceClippingCost_nonneg _ _ _ _ _ _ _ _ ha.le) (by positivity) + have h2 := W'.lifted_overlap_quarter hq (mul_nonneg (Nat.cast_nonneg _) hE') + (hcount 1 le_rfl) (hP 1 (by omega)) hp hC (hlift 1 (by omega)) h1 ?_ + · intro j hj + interval_cases j + · exact hbase + · exact h1 + · exact h2 + · simpa only [mul_assoc] using hsecond + · simpa only [mul_assoc] using hfirst + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem OracleTracePair.error_nonneg {q E V : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) : 0 ≤ E := by + let := C.finiteOutcome + have h := C.first_simulation (fun _ => 0) (fun _ => ⟨le_rfl,zero_le_one⟩) + exact (abs_nonneg _).trans h + +/-- Finite main-block production: actual oracle, complete trace projection, + and all side overlaps follow from arithmetic budgets and the OLD invariant. + In particular none of the new side laws or their overlap are hypotheses. -/ +theorem actual_main_block {q E V ω C₀ : ℝ} (hq : q∈Set.Icc 0 1) + (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b R k : ℕ) + (C : OracleTracePair q (atom false) (atom true) k E V) + (H : SourceLayoutMargins s P T n h b) + (hTpos : ∀j,0 < T j) (hP : P b=n b*(2*h b+1)+T b) + (hn : ∀j < b,0 < n j) (hT : ∀j ≤ b,24 ≤ T j) (he : ∀j ≤ b,Even (T j)) + (hMotif : ∀j ≤ b,24*2^s ≤ T j) (hroot : 4*(n b+1) ≤ T b) + (a η L : ℝ) (ha : 0 < a) (hL : 0 < L) (hω : ω∈Set.Ioc 0 (1/8)) + (hk : 1 ≤ k) (hV : V ≤ L^2) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) + (hη : ∀j < b+1,hiddenSmoothingBound (n j) s ω ≤ η) + (herror : sourceClippingCost T n s b k ω a L ≤ 1/2) + (hC : 1073741824 ≤ ω*C₀) (hcount : ∀j ≤ b+1,1 ≤ h j) + (hpos : ∀j < b+1,1 ≤ P j) + (hlift : ∀j < b+1,C₀*h j*P j ≤ h (j+1)) + (hsmall : ∀j < b+1, + Real.sqrt (((h (j+1)+1:ℕ):ℝ)*(((2^s:ℕ):ℝ)^(j+1)*V))+ + 2*((h (j+1)+1:ℕ):ℝ)*((sourceBlockLength P 1 (j+1):ℝ)*E) ≤ 1/4) + (hbase : ω ≤ listTraceOverlap q hq (pureAtomRun (atom false) (h 0)) + (pureAtomRun (atom false) (h 0+1))) : + Nonempty (OracleTracePair q (sourceBlockWord s P atom (b+1) false) + (sourceBlockWord s P atom (b+1) true) k + (sourceClippingCost T n s b k ω a L+(SourceLeafCount T (b+1):ℝ)*E+sourceFitTail T n (b+1)) + (64*sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))) ∧ + (∀j ≤ b+1,ω ≤ listTraceOverlap q hq + (pureAtomRun (sourceBlockWord s P atom j false) (h j)) + (pureAtomRun (sourceBlockWord s P atom j false) (h j+1))) := by + let := C.finiteOutcome + have hov := source_nested_overlap hq C.error_nonneg s P h atom (C.hellinger hk) (b+1) + hω hC hcount hpos hlift hsmall hbase + refine ⟨?_,hov⟩ + have hm : C.first.expect (fun z => |C.score z|^(2*k)) ≤ L^(2*k) := by + have H := C.first.expect_even_pow_le_of_moment C.score k hk (C.moment.trans hV) + simpa only [pow_mul] using H + exact actual_source_oracle hq C.error_nonneg s P T n h atom b R k H hTpos hP hn hT he hMotif hroot + C.first C.second C.decode C.score C.density C.likelihood_nonneg C.first_simulation C.second_simulation + ω a η L ha hL ⟨hω.1,lt_of_le_of_lt hω.2 (by norm_num)⟩ + (fun j hj => hov j (by omega)) hk hm hscale hη herror + +/-- Conversion of a produced genuine oracle into the manuscript invariant. + The scalar bounds here are exactly those to be discharged by scale margins. -/ +def OracleTracePair.toConcrete {q E V N Δ d ω F : ℝ} {x y : List Bool} {k i h : ℕ} + (C : OracleTracePair q x y k E V) (hq : q∈Set.Icc 0 1) + (hlen : x.length=y.length) (hne : x≠y) (hlo : N/2 ≤ (x.length:ℝ)) + (hhi : (x.length:ℝ) ≤ N) (herror : E/(x.length:ℝ) ≤ ((i:ℝ)+1)*Δ) + (hV : V ≤ N^(-d)) (hhlo : x.length ≤ h) (hhhi : (h:ℝ) ≤ F*(x.length:ℝ)) + (hov : ω ≤ listTraceOverlap q hq (pureAtomRun x h) (pureAtomRun x (h+1))) : + ConcreteLevelPair q hq N Δ d ω F i k := { + left := x + right := y + equalLength := hlen + different := hne + length_lower := hlo + length_upper := hhi + Outcome := C.Outcome + finiteOutcome := C.finiteOutcome + firstLaw := C.first + secondLaw := C.second + decode := C.decode + error := E + error_nonneg := C.error_nonneg + normalized_error := herror + first_simulation := C.first_simulation + second_simulation := C.second_simulation + score := C.score + density := C.density + score_bound := C.moment.trans hV + overlapCount := h + overlapCount_lower := hhlo + overlapCount_upper := hhhi + power_overlap := hov } + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Anchors.lean b/lean/OAI/Probability/TraceReconstruction/Anchors.lean index 3a21e1c9468c37a72d19bfea35f25cad358fd47a..0dd20dc0b673d40694df52a8ec2f642dca04d522 100644 --- a/lean/OAI/Probability/TraceReconstruction/Anchors.lean +++ b/lean/OAI/Probability/TraceReconstruction/Anchors.lean @@ -1,1229 +1,1229 @@ -import OAI.Probability.TraceReconstruction.LeafOracle - -namespace OAI - -/-! -# Anchors - -Forced anchors, extra-leaf closeness, and correlated group square-sum estimates. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -namespace FiniteLaw -/-- Two distinct actual child coordinates are independent. This does not -assert independence of their shared parent-global jitter. -/ -theorem coordinateProduct_expect_two {α : Type*} [Fintype α] {n : ℕ} - (P : Fin n → FiniteLaw α) (a c : Fin n) (hne : a≠c) (f h : α → ℝ) : - (coordinateProduct P).expect (fun x => f (x a)*h (x c)) = (P a).expect f*(P c).expect h := by - let F : Fin n → α → ℝ := fun j x => if j=a then f x else if j=c then h x else 1 - have hp : ∀x : Fin n → α, (∏j,F j (x j)) = f (x a)*h (x c) := by - intro x - rw [Finset.prod_eq_mul a c hne] - · simp [F,hne.symm] - · intro j hj hjs - simp [F,hjs.1,hjs.2] - · simp - · simp - rw [show (fun x : Fin n → α => f (x a)*h (x c)) = (fun x => ∏j,F j (x j)) by - funext x; exact (hp x).symm,coordinateProduct_expect_product] - rw [Finset.prod_eq_mul a c hne] - · simp [F,hne.symm] - · intro j hj hjs - simp [F,hjs.1,hjs.2,expect_const] - · simp - · simp - -/-- Exact local/global/children factorization with the parent-global draw -outside the product of child expectations. -/ -theorem expect_prod_two {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - {n : ℕ} (P : FiniteLaw α) (Q : FiniteLaw β) (R : Fin n → FiniteLaw γ) - (a c : Fin n) (hne : a≠c) (f : α → ℝ) (h k : β → γ → ℝ) : - (P.prod (Q.prod (coordinateProduct R))).expect (fun x => - f x.1 * (h x.2.1 (x.2.2 a)*k x.2.1 (x.2.2 c))) = - P.expect f * Q.expect (fun z => (R a).expect (h z)*(R c).expect (k z)) := by - simp_rw [expect_prod,expect_const_mul,coordinateProduct_expect_two R a c hne] - rw [expect_mul_const] -end FiniteLaw - -/-- A concrete binary selection of labels in the complete index tree. -Unlike a free abstract shape this retains every actual column label. -/ -def BinaryWindowLabels (T : ℕ → ℕ) : ℕ → Type - | 0 => PUnit - | b+1 => Fin (T b) × Fin (T b) × BinaryWindowLabels T b × BinaryWindowLabels T b - -noncomputable instance binaryWindowLabelsFintype (T : ℕ → ℕ) : - (b : ℕ) → Fintype (BinaryWindowLabels T b) - | 0 => inferInstanceAs (Fintype PUnit) - | b+1 => by - letI := binaryWindowLabelsFintype T b - exact inferInstanceAs (Fintype (Fin (T b) × Fin (T b) × BinaryWindowLabels T b × BinaryWindowLabels T b)) - -/-- The forced children are distinct at every split. Central restrictions -are separate deterministic predicates, not conditioning events. -/ -def BinaryWindowLabels.distinct (T : ℕ → ℕ) : (b : ℕ) → BinaryWindowLabels T b → Prop - | 0, _ => True - | b+1, p => p.1≠p.2.1 ∧ distinct T b p.2.2.1 ∧ distinct T b p.2.2.2 - -/-- Product of the first-child unsigned anchor at every forced nonleaf, -evaluated using the literal complete-tree orientation assignment. -/ -def binaryAnchorKernel (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : - (b : ℕ) → BinaryWindowLabels T b → WindowAssignments T n g Bool b → ℤ → ℝ - | 0, _, _, _ => 1 - | b+1, p, bits, incoming => - motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (bits.1 i):ℤ))+incoming) * - (binaryAnchorKernel T n g s center globalShift b p.2.2.1 (bits.2.2 p.1) - (globalShift b bits.2.1 p.1) * - binaryAnchorKernel T n g s center globalShift b p.2.2.2 (bits.2.2 p.2.1) - (globalShift b bits.2.1 p.2.1)) - -def binaryAnchorAverage (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (p : BinaryWindowLabels T b) (d : WindowAssignments T n g (Option Bool) b) - (incoming : ℤ) : ℝ := - (windowPosteriorLaw T n g b d).expect (fun bits => - binaryAnchorKernel T n g s center globalShift b p bits incoming) - -theorem binaryAnchorAverage_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (p : BinaryWindowLabels T 0) (d : WindowAssignments T n g (Option Bool) 0) (incoming : ℤ) : - binaryAnchorAverage T n g s center globalShift 0 p d incoming = 1 := by - apply expect_const - -theorem binaryAnchorAverage_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (p : BinaryWindowLabels T (b+1)) (d : WindowAssignments T n g (Option Bool) (b+1)) - (incoming : ℤ) (hd : p.1≠p.2.1) : - binaryAnchorAverage T n g s center globalShift (b+1) p d incoming = - (posteriorArray d.1).expect (fun loc => - motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (loc i):ℤ))+incoming)) * - (posteriorArray d.2.1).expect (fun glob => - binaryAnchorAverage T n g s center globalShift b p.2.2.1 (d.2.2 p.1) - (globalShift b glob p.1) * - binaryAnchorAverage T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1) - (globalShift b glob p.2.1)) := by - exact FiniteLaw.expect_prod_two (posteriorArray d.1) (posteriorArray d.2.1) - (fun i => windowPosteriorLaw T n g b (d.2.2 i)) p.1 p.2.1 hd - (fun loc => motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (loc i):ℤ))+incoming)) - (fun glob bits => binaryAnchorKernel T n g s center globalShift b p.2.2.1 bits - (globalShift b glob p.1)) - (fun glob bits => binaryAnchorKernel T n g s center globalShift b p.2.2.2 bits - (globalShift b glob p.2.1)) - -/-- Local unsigned anchor averaged against its actual known/hidden flags. -/ -def localAnchorAverage {m : ℕ} (d : Fin m → Option Bool) (s : ℕ) (z : ℤ) : ℝ := - (posteriorArray d).expect (fun bits => motifIndicator s (z+∑i,(bitIndex (bits i):ℤ))) - -theorem localAnchorAverage_kernel {m : ℕ} (d : Fin m → Option Bool) (s : ℕ) (z : ℤ) : - localAnchorAverage d s z = windowKernel (∑i,hiddenTrial (d i)) (2^s) - (z+∑i,(visibleOnes (d i):ℤ)) := by - have h := posterior_unsigned_motif d s z - unfold localAnchorAverage posteriorArray coordinateProduct expect - convert h using 1 - congr 2 - exact Subsingleton.elim _ _ - -/-- Product of all lower sibling-group factors. Each group still averages -its own single common global draw, not two independent global draws. -/ -def binaryAnchorBelow (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : - (b : ℕ) → BinaryWindowLabels T (b+1) → WindowAssignments T n g (Option Bool) (b+1) → ℝ - | 0, _, _ => 1 - | b+1, p, d => - (posteriorArray d.2.1).expect (fun glob => - localAnchorAverage (d.2.2 p.1).1 s - ((p.2.2.1.1.val:ℤ)-center b+globalShift (b+1) glob p.1) * - localAnchorAverage (d.2.2 p.2.1).1 s - ((p.2.2.2.1.val:ℤ)-center b+globalShift (b+1) glob p.2.1)) * - (binaryAnchorBelow T n g s center globalShift b p.2.2.1 (d.2.2 p.1) * - binaryAnchorBelow T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1)) - -/-- Exact factorization of the forced anchor expectation into its root -kernel and all correlated sibling groups, at the real metadata/labels. -/ -theorem binaryAnchorAverage_factor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (p : BinaryWindowLabels T (b+1)) (d : WindowAssignments T n g (Option Bool) (b+1)) - (incoming : ℤ) (hd : BinaryWindowLabels.distinct T (b+1) p) : - binaryAnchorAverage T n g s center globalShift (b+1) p d incoming = - localAnchorAverage d.1 s ((p.1.val:ℤ)-center b+incoming) * - binaryAnchorBelow T n g s center globalShift b p d := by - induction b generalizing incoming with - | zero => - rw [binaryAnchorAverage_succ T n g s center globalShift _ p d incoming hd.1] - simp only [binaryAnchorAverage_zero,expect_const,binaryAnchorBelow,mul_one] - unfold localAnchorAverage - congr 1 - funext loc - congr 1 - omega - | succ b ih => - have hl := fun incoming => ih p.2.2.1 (d.2.2 p.1) incoming hd.2.1 - have hr := fun incoming => ih p.2.2.2 (d.2.2 p.2.1) incoming hd.2.2 - have hroot : (posteriorArray d.1).expect (fun loc => - motifIndicator s ((p.1.val:ℤ)-center (b+1)+(∑i,(bitIndex (loc i):ℤ))+incoming)) = - localAnchorAverage d.1 s ((p.1.val:ℤ)-center (b+1)+incoming) := by - apply congrArg (FiniteLaw.expect (posteriorArray d.1)) - funext loc - congr 1 - omega - have hh : (posteriorArray d.2.1).expect (fun glob => - binaryAnchorAverage T n g s center globalShift (b+1) p.2.2.1 (d.2.2 p.1) - (globalShift (b+1) glob p.1) * - binaryAnchorAverage T n g s center globalShift (b+1) p.2.2.2 (d.2.2 p.2.1) - (globalShift (b+1) glob p.2.1)) = - binaryAnchorBelow T n g s center globalShift (b+1) p d := by - calc - _ = (posteriorArray d.2.1).expect (fun glob => - (localAnchorAverage (d.2.2 p.1).1 s - ((p.2.2.1.1.val:ℤ)-center b+globalShift (b+1) glob p.1) * - localAnchorAverage (d.2.2 p.2.1).1 s - ((p.2.2.2.1.val:ℤ)-center b+globalShift (b+1) glob p.2.1)) * - (binaryAnchorBelow T n g s center globalShift b p.2.2.1 (d.2.2 p.1) * - binaryAnchorBelow T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1))) := by - apply congrArg (FiniteLaw.expect (posteriorArray d.2.1)) - funext glob - exact (congrArg₂ (·*·) (hl _) (hr _)).trans (by ring) - _ = _ := expect_mul_const _ _ _ - exact (binaryAnchorAverage_succ T n g s center globalShift _ p d incoming hd.1).trans - (congrArg₂ (·*·) hroot hh) - -/-- One plateau group's local means are the genuine shared-global joint -anchor, with exactly the affine shift appearing in the layout. -/ -theorem localAnchor_pair_plateau {mg m₁ m₂ : ℕ} - (dg : Fin mg → Option Bool) (d₁ : Fin m₁ → Option Bool) (d₂ : Fin m₂ → Option Bool) - (s : ℕ) (z₁ z₂ shift : ℤ) : - (posteriorArray dg).expect (fun glob => - localAnchorAverage d₁ s (z₁+(∑i,(bitIndex (glob i):ℤ))-shift) * - localAnchorAverage d₂ s (z₂+(∑i,(bitIndex (glob i):ℤ))-shift)) = - posteriorJointAnchors dg d₁ d₂ s (z₁-shift) (z₂-shift) := by - unfold localAnchorAverage posteriorArray coordinateProduct expect posteriorJointAnchors - have he : ∀a b c d : ℤ,(a+b-c)+d = (a-c)+b+d := by intros; omega - simp_rw [he,mul_assoc] - congr 2 - · exact Subsingleton.elim _ _ - · funext bg - congr 1 - congr 1 - · congr 2 ; exact Subsingleton.elim _ _ - · congr 2 ; exact Subsingleton.elim _ _ - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- A role-selected forced subtree remembers the actual complete-tree labels, -not merely its abstract binary shape. -/ -def forcedWindowLabels (T : ℕ → ℕ) : (b : ℕ) → - (S : Finset (WindowLeaf T (b+1))) → (a : OccupiedWindowChoice T b S) → - (occupiedWindowTerm T b S a).Forced → BinaryWindowLabels T (b+1) - | 0, S, _, .node i j _ _ _ _ _ => - ((S.equivFin.symm i).val.1,(S.equivFin.symm j).val.1,PUnit.unit,PUnit.unit) - | b+1, S, a, .node i j _ _ _ left right => - (((selectedChildren S).equivFin.symm i).val, - ((selectedChildren S).equivFin.symm j).val, - forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) - (a.1 i) left, - forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) - (a.1 j) right) - -theorem forcedWindowLabels_distinct (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - BinaryWindowLabels.distinct T (b+1) (forcedWindowLabels T b S a F) := by - induction b with - | zero => - cases F with - | node i j hne hi hj left right => - refine ⟨?_,trivial,trivial⟩ - intro he - apply hne - apply S.equivFin.symm.injective - apply Subtype.ext - exact Prod.ext he (Subsingleton.elim (α := Fin 1) _ _) - | succ b ih => - cases F with - | node i j hne hi hj left right => - refine ⟨?_,ih _ _ left,ih _ _ right⟩ - intro he - exact hne ((selectedChildren S).equivFin.symm.injective (Subtype.ext he)) - -theorem motifIndicator_nonneg (s : ℕ) (z : ℤ) : 0 ≤ motifIndicator s z := by - unfold motifIndicator - split_ifs <;> norm_num - -theorem motifIndicator_le_one (s : ℕ) (z : ℤ) : motifIndicator s z≤1 := by - unfold motifIndicator - split_ifs <;> norm_num - -theorem binaryAnchorKernel_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (p : BinaryWindowLabels T b) (bits : WindowAssignments T n g Bool b) - (incoming : ℤ) : 0≤binaryAnchorKernel T n g s center globalShift b p bits incoming := by - induction b generalizing incoming with - | zero => exact zero_le_one - | succ b ih => - exact mul_nonneg (motifIndicator_nonneg _ _) (mul_nonneg (ih _ _ _) (ih _ _ _)) - -theorem bottomRoleWeight_abs_le_indicator (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : - |bottomRoleWeight χ σ a|≤χ := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> - fin_cases a <;> norm_num [bottomRoleWeight] - -theorem internalRoleWeight_active_abs_le_indicator (odd : Prop) [Decidable odd] - (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) (ha : a≠0) : - |internalRoleWeight odd χ σ a|≤χ := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> - fin_cases a <;> by_cases ho : odd <;> norm_num [internalRoleWeight,roleWeight,ho] at * - -theorem occupiedRootWeight_bottom_anchor (T : ℕ → ℕ) (s : ℕ) - (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) (X : ℤ) (i : Fin S.card) : - |occupiedRootWeight T s 0 S a X|≤ - motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X) := by - exact (abs_prod_le_coordinate _ i (fun j _ => - bottomRoleWeight_abs_le_one _ _ (prouhet_motif_value _ _) _)).trans - (bottomRoleWeight_abs_le_indicator _ _ (prouhet_motif_value _ _) _) - -theorem occupiedRootWeight_internal_anchor (T : ℕ → ℕ) (s b : ℕ) - (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) (X : ℤ) - (i : Fin (selectedChildren S).card) (hi : a.2 i≠0) : - |occupiedRootWeight T s (b+1) S a X|≤ - motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X) := by - exact (abs_prod_le_coordinate _ i (fun j _ => - internalRoleWeight_abs_le_one _ _ _ (prouhet_motif_value _ _) _)).trans - (internalRoleWeight_active_abs_le_indicator _ _ _ (prouhet_motif_value _ _) _ hi) - -theorem abs_prod_le_two {ι : Type*} [Fintype ι] (f : ι → ℝ) (a c : ι) (hne : a≠c) - (h : ∀j,j≠a → j≠c → |f j|≤1) : |∏j,f j|≤|f a| * |f c| := by - rw [Finset.abs_prod] - calc - _ ≤ ∏j, if j=a then |f a| else if j=c then |f c| else 1 := by - apply Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) - intro j hj - by_cases hja : j=a - · simp [hja] - · by_cases hjc : j=c - · simp [hjc,hne.symm] - · simpa only [ite_eq_right hja,ite_eq_right hjc] using h j hja hjc - _ = _ := by - rw [Finset.prod_eq_mul a c hne] - · simp [hne.symm] - · intro j hj hjs - simp [hjs.1,hjs.2] - · simp - · simp - -/-- The real role term is pointwise dominated by its selected unsigned -anchors. No independence assumption is used in this domination. -/ -theorem sourceRoleTerm_forced_anchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ - binaryAnchorKernel T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) bits incoming := by - induction b generalizing incoming with - | zero => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_zero] - change _ ≤ motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-center 0+ - (∑i,(bitIndex (bits.1 i):ℤ))+incoming)*(1*1) - rw [mul_one,mul_one] - convert occupiedRootWeight_bottom_anchor T s S a - (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) i using 1 ; congr 1 ; omega - | succ b ih => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_succ,abs_mul] - have hroot := occupiedRootWeight_internal_anchor T s b S a - (center (b+1)-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) i hi - have hprod := abs_prod_le_two (fun k : Fin (selectedChildren S).card => - sourceRoleTerm T n g s center globalShift b - (bits.2.2 ((selectedChildren S).equivFin.symm k).val) - (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm k).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm k).val) (a.1 k)) i j hne - (fun k _ _ => occupiedWindowWeight_abs_le_one T s _ b [] _ _) - have hl := ih (bits.2.2 ((selectedChildren S).equivFin.symm i).val) - (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) _ _ left - have hr := ih (bits.2.2 ((selectedChildren S).equivFin.symm j).val) - (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm j).val) _ _ right - have hp := mul_le_mul hl hr (abs_nonneg _) (binaryAnchorKernel_nonneg T n g s center globalShift _ _ _ _) - have hh := mul_le_mul hroot (hprod.trans hp) (abs_nonneg _) (motifIndicator_nonneg _ _) - apply hh.trans_eq - change motifIndicator s _ * _ = motifIndicator s - ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-center (b+1)+ - (∑k,(bitIndex (bits.1 k):ℤ))+incoming) * _ - congr 2 - omega - -/-- Therefore the coefficient average is bounded by the actual forced -anchor average, with the true posterior law and shared jitter retained. -/ -theorem sourceRoleAverage_forced_anchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ - binaryAnchorAverage T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) d incoming := by - exact ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans - ((windowPosteriorLaw T n g (b+1) d).expect_mono (fun bits => - sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F)) - -theorem sourceRoleTerm_valid (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (h : sourceRoleTerm T n g s center globalShift b bits incoming S a ≠ 0) : - (occupiedWindowTerm T b S a).valid := by - have hh := (occupiedWindowShape T s - (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) b [] S).term_valid - (occupiedWindowChoiceEquiv T s - (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) b [] S a) h - simpa only [occupiedWindowTerm_eq] using hh - -theorem sourceRoleAverage_valid (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (h : sourceRoleAverage T n g s center globalShift b d incoming S a ≠ 0) : - (occupiedWindowTerm T b S a).valid := by - by_contra hn - have hh : ∀bits, sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by - intro bits - by_contra hz - exact hn (sourceRoleTerm_valid T n g s center globalShift b bits incoming S a hz) - apply h - change (windowPosteriorLaw T n g (b+1) d).expect _ = 0 - rw [show (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) = - (fun _ => 0) from funext hh,expect_const] - -/-- The source's two alternatives now apply to actual posterior coefficient -terms: signed singleton smoothing, or domination by a genuine forced tree. -/ -theorem sourceRoleAverage_alternative (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (η : ℝ) (hη : 0≤η) (hcap : MetadataSmoothingCap T n g s η (b+1) d) - (ho : (occupiedWindowTerm T b S a).isOdd) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤η ∨ - ∃F : (occupiedWindowTerm T b S a).Forced, - BinaryWindowLabels.distinct T (b+1) (forcedWindowLabels T b S a F) ∧ - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ - binaryAnchorAverage T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) d incoming := by - by_cases hz : sourceRoleAverage T n g s center globalShift b d incoming S a=0 - · exact Or.inl (by simpa only [hz,abs_zero] using hη) - by_cases hn : (occupiedWindowTerm T b S a).noSingleton - · obtain ⟨F⟩ := OccupiedParityTree.forced_nonempty (occupiedWindowTerm T b S a) - (sourceRoleAverage_valid T n g s center globalShift b d incoming S a hz) hn ho - exact Or.inr ⟨F,forcedWindowLabels_distinct T b S a F, - sourceRoleAverage_forced_anchor T n g s center globalShift b d incoming S a F⟩ - · exact Or.inl (sourceRoleAverage_singleton T n g s center globalShift b d incoming S a η hcap hn) - -end TraceReconstruction - - -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- The unsigned bottom constraint at one literal complete-tree leaf. -/ -def sourceBottomIndicator (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : - (b : ℕ) → WindowAssignments T n g Bool (b+1) → ℤ → WindowLeaf T (b+1) → ℝ - | 0, bits, incoming, v => - motifIndicator s ((v.1.val:ℤ)-center 0+(∑i,(bitIndex (bits.1 i):ℤ))+incoming) - | b+1, bits, _, v => sourceBottomIndicator T n g s center globalShift b - (bits.2.2 v.1) (globalShift (b+1) bits.2.1 v.1) v.2 - -def sourceLeafProduct (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) : ℝ := - ∏v∈S, sourceBottomIndicator T n g s center globalShift b bits incoming v - -theorem sourceBottomIndicator_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (v : WindowLeaf T (b+1)) : - sourceBottomIndicator T n g s center globalShift b bits incoming v=0 ∨ - sourceBottomIndicator T n g s center globalShift b bits incoming v=1 := by - induction b generalizing incoming with - | zero => unfold sourceBottomIndicator motifIndicator; split_ifs <;> simp - | succ b ih => exact ih _ _ _ - -theorem prod_zero_one {ι : Type*} (S : Finset ι) (f : ι → ℝ) - (h : ∀i∈S,f i=0 ∨ f i=1) : (∏i∈S,f i)=0 ∨ (∏i∈S,f i)=1 := by - by_cases hz : ∃i∈S,f i=0 - · obtain ⟨i,hi,hz⟩ := hz - exact Or.inl (Finset.prod_eq_zero hi hz) - · right - apply Finset.prod_eq_one - intro i hi - exact (h i hi).resolve_left (fun he => hz ⟨i,hi,he⟩) - -theorem sourceLeafProduct_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) : - sourceLeafProduct T n g s center globalShift b bits incoming S=0 ∨ - sourceLeafProduct T n g s center globalShift b bits incoming S=1 := - prod_zero_one S _ (fun v _ => sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v) - -theorem binaryAnchorKernel_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (p : BinaryWindowLabels T b) (bits : WindowAssignments T n g Bool b) - (incoming : ℤ) : - binaryAnchorKernel T n g s center globalShift b p bits incoming=0 ∨ - binaryAnchorKernel T n g s center globalShift b p bits incoming=1 := by - induction b generalizing incoming with - | zero => exact Or.inr rfl - | succ b ih => - have hl := ih p.2.2.1 (bits.2.2 p.1) (globalShift b bits.2.1 p.1) - have hr := ih p.2.2.2 (bits.2.2 p.2.1) (globalShift b bits.2.1 p.2.1) - change (_*(_*_)=0) ∨ (_*(_*_)=1) - rcases hl with hl|hl <;> rcases hr with hr|hr <;> rw [hl,hr] <;> - unfold motifIndicator <;> split_ifs <;> norm_num - -theorem sourceLeafProduct_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1+1))) : - sourceLeafProduct T n g s center globalShift (b+1) bits incoming S = - ∏i : Fin (selectedChildren S).card, - sourceLeafProduct T n g s center globalShift b - (bits.2.2 ((selectedChildren S).equivFin.symm i).val) - (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) := by - symm - exact (selected_prod_index (selectedChildren S) (fun h => - ∏v∈selectedChildLeaves S h, - sourceBottomIndicator T n g s center globalShift b (bits.2.2 h) - (globalShift (b+1) bits.2.1 h) v)).trans - (selected_prod_children S (fun v => - sourceBottomIndicator T n g s center globalShift (b+1) bits incoming v)) - -/-- Every selected leaf is active in the bottom expansion, including those -outside the forced tree. Their absolute constraints are not lost. -/ -theorem sourceRoleTerm_all_leaf_constraints (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : - |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ - sourceLeafProduct T n g s center globalShift b bits incoming S := by - induction b generalizing incoming with - | zero => - rw [sourceRoleTerm_zero] - change |∏i : Fin S.card, _|≤_ - rw [Finset.abs_prod] - calc - _ ≤ ∏i : Fin S.card, motifIndicator s - (((S.equivFin.symm i).val.1.val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) := - Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) - (fun i _ => bottomRoleWeight_abs_le_indicator _ _ (prouhet_motif_value _ _) _) - _ = ∏v∈S, motifIndicator s ((v.1.val:ℤ)- - (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) := - selected_prod_index S (fun v : WindowLeaf T 1 => motifIndicator s - ((v.1.val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming))) - _ = _ := by - apply Finset.prod_congr rfl - intro v hv - change motifIndicator s _ = motifIndicator s _ - congr 1 - omega - | succ b ih => - rw [sourceRoleTerm_succ,abs_mul,sourceLeafProduct_succ] - apply (mul_le_mul_of_nonneg_right - (occupiedRootWeight_abs_le_one T s (b+1) S a _) (abs_nonneg _)).trans - rw [one_mul,Finset.abs_prod] - apply Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) - intro i hi - exact ih _ _ _ _ - -theorem sourceLeafProduct_antitone (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (E S : Finset (WindowLeaf T (b+1))) (hES : E⊆S) : - sourceLeafProduct T n g s center globalShift b bits incoming S≤ - sourceLeafProduct T n g s center globalShift b bits incoming E := by - apply Finset.prod_le_prod_of_subset_of_le_one₀ hES - · intro v hv - rcases sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v with h|h <;> norm_num [h] - · intro v hv he - rcases sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v with h|h <;> norm_num [h] - -theorem le_mul_of_zero_one {x a b : ℝ} (ha : a=0 ∨ a=1) (hb : b=0 ∨ b=1) - (hxa : x≤a) (hxb : x≤b) : x≤a*b := by - rcases ha with rfl|rfl <;> rcases hb with rfl|rfl <;> norm_num at * <;> assumption - -/-- Actual forced anchor AND extra-leaf constraints in one bit expectation. -In particular E can be precisely the nonforced leaves; keeping it arbitrary -here permits the later label summation without any conditioning gates. -/ -theorem sourceRoleAverage_forced_extra (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S E : Finset (WindowLeaf T (b+1))) (hES : E⊆S) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ - (windowPosteriorLaw T n g (b+1) d).expect (fun bits => - binaryAnchorKernel T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) bits incoming * - sourceLeafProduct T n g s center globalShift b bits incoming E) := by - apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans - apply FiniteLaw.expect_mono - intro bits - exact le_mul_of_zero_one - (binaryAnchorKernel_zero_one T n g s center globalShift _ _ bits incoming) - (sourceLeafProduct_zero_one T n g s center globalShift b bits incoming E) - (sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F) - ((sourceRoleTerm_all_leaf_constraints T n g s center globalShift b bits incoming S a).trans - (sourceLeafProduct_antitone T n g s center globalShift b bits incoming E S hES)) - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Deterministic closeness of each forced split; it is a restriction on -labels, never an additional conditioning event for the random bits. -/ -def BinaryWindowLabels.close (T : ℕ → ℕ) (s : ℕ) : (b : ℕ) → BinaryWindowLabels T b → Prop - | 0, _ => True - | b+1, p => |(p.1.val:ℤ)-p.2.1.val|<(2^s:ℕ) ∧ close T s b p.2.2.1 ∧ close T s b p.2.2.2 - -theorem motifIndicator_pair_close (s : ℕ) (a c X : ℤ) - (ha : motifIndicator s (a-X)≠0) (hc : motifIndicator s (c-X)≠0) : - |a-c|<(2^s:ℕ) := by - have hsa : 0≤a-X ∧ a-X<(2^s:ℕ) := by - by_contra h - exact ha (by simp only [motifIndicator,ite_eq_right h]) - have hsc : 0≤c-X ∧ c-X<(2^s:ℕ) := by - by_contra h - exact hc (by simp only [motifIndicator,ite_eq_right h]) - exact abs_lt.mpr ⟨by omega,by omega⟩ - -theorem nonzero_of_abs_le {x y : ℝ} (h : x≠0) (hle : |x|≤y) : y≠0 := by - intro hy - rw [hy] at hle - exact h (abs_eq_zero.mp (le_antisymm hle (abs_nonneg x))) - -/-- A nonzero literal role multiplier enforces all close-child restrictions -of every forced subtree chosen from its fixed role pattern. -/ -theorem sourceRoleTerm_forced_close (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) - (h : sourceRoleTerm T n g s center globalShift b bits incoming S a≠0) : - BinaryWindowLabels.close T s (b+1) (forcedWindowLabels T b S a F) := by - induction b generalizing incoming with - | zero => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_zero] at h - change |((S.equivFin.symm i).val.1.val:ℤ)-(S.equivFin.symm j).val.1.val|<(2^s:ℕ) ∧ True ∧ True - refine ⟨?_,trivial,trivial⟩ - exact motifIndicator_pair_close s _ _ _ - (nonzero_of_abs_le h (occupiedRootWeight_bottom_anchor T s S a _ i)) - (nonzero_of_abs_le h (occupiedRootWeight_bottom_anchor T s S a _ j)) - | succ b ih => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_succ] at h - have hm := mul_ne_zero_iff.mp h - have hc := Finset.prod_ne_zero_iff.mp hm.2 - change |(((selectedChildren S).equivFin.symm i).val.val:ℤ)- - ((selectedChildren S).equivFin.symm j).val.val|<(2^s:ℕ) ∧ - BinaryWindowLabels.close T s (b+1) - (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) - (a.1 i) left) ∧ - BinaryWindowLabels.close T s (b+1) - (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) - (a.1 j) right) - refine ⟨?_,ih _ _ _ _ left (hc i (Finset.mem_univ i)), - ih _ _ _ _ right (hc j (Finset.mem_univ j))⟩ - exact motifIndicator_pair_close s _ _ _ - (nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ i hi)) - (nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ j hj)) - -/-- Closeness remains a pure label condition after averaging, without -conditioning on it. -/ -theorem sourceRoleAverage_forced_close (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) - (h : sourceRoleAverage T n g s center globalShift b d incoming S a≠0) : - BinaryWindowLabels.close T s (b+1) (forcedWindowLabels T b S a F) := by - by_contra hn - have hh : ∀bits, sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by - intro bits - by_contra hz - exact hn (sourceRoleTerm_forced_close T n g s center globalShift b bits incoming S a F hz) - apply h - change (windowPosteriorLaw T n g (b+1) d).expect _ = 0 - rw [show (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) = - (fun _ => 0) from funext hh,expect_const] - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- The literal finite child labels embedded in the integer line. -/ -def finIntegerLabels (N : ℕ) : Finset ℤ := Finset.univ.image (fun i : Fin N => (i.val:ℤ)) - -theorem sum_finIntegerLabels (N : ℕ) (f : ℤ → ℝ) : - (∑a∈finIntegerLabels N,f a)=∑i : Fin N,f i.val := by - rw [finIntegerLabels,Finset.sum_image] - intro a ha b hb he - apply Fin.ext - change (a.val:ℤ)=(b.val:ℤ) at he - exact_mod_cast he - -theorem sum_close_finIntegerLabels (N L : ℕ) (a : ℤ) (f : ℤ → ℝ) : - (∑c∈closeLabels (finIntegerLabels N) L a,f c) = - ∑i : Fin N, if |(i.val:ℤ)-a|<(L:ℤ) then f i.val else 0 := by - rw [closeLabels,Finset.sum_filter,sum_finIntegerLabels] - -/-- Any deterministic plateau/distinctness restriction can be retained in -child-pair summation. Only closeness is used to upper bound its cost. -/ -theorem localAnchor_finite_energy {m N : ℕ} (d : Fin m → Option Bool) (s : ℕ) - (c : ℤ) (R : Fin N → Fin N → Prop) [DecidableRel R] - (hR : ∀a b,R a b → |(b.val:ℤ)-a.val|<(2^s:ℕ)) : - (∑a : Fin N, ∑b : Fin N, if R a b then localAnchorAverage d s ((a.val:ℤ)-c)^2 else 0) ≤ - 2*((2^s:ℕ):ℝ)^3*binomialBound (∑i,hiddenTrial (d i)) := by - have H := root_anchor_energy (∑i,hiddenTrial (d i)) (2^s) - (finIntegerLabels N) (finIntegerLabels N) (c-(∑i,(visibleOnes (d i):ℤ))) - rw [sum_finIntegerLabels] at H - simp_rw [sum_close_finIntegerLabels] at H - calc - _ ≤ ∑a : Fin N, ∑b : Fin N, - if |(b.val:ℤ)-a.val|<(2^s:ℕ) then - windowKernel (∑i,hiddenTrial (d i)) (2^s) - ((a.val:ℤ)-(c-∑i,(visibleOnes (d i):ℤ)))^2 else 0 := by - apply Finset.sum_le_sum - intro a ha - apply Finset.sum_le_sum - intro b hb - by_cases h : R a b - · rw [ite_eq_left h,ite_eq_left (hR a b h),localAnchorAverage_kernel] - convert le_refl _ using 1 ; congr 2 ; omega - · rw [ite_eq_right h] - split_ifs <;> positivity - _ ≤ _ := H - -/-- Actual shared-jitter energy over two finite sibling pairs. Parent-label -plateau restrictions are discharged before applying this lemma; arbitrary -restrictions on these child pairs are kept, not conditioned on. -/ -theorem posteriorJoint_finite_energy {mg m₁ m₂ N : ℕ} - (dg : Fin mg → Option Bool) (d₁ : Fin m₁ → Option Bool) (d₂ : Fin m₂ → Option Bool) - (s : ℕ) (c₁ c₂ : ℤ) (R : Fin N → Fin N → Prop) [DecidableRel R] - (hR : ∀a b,R a b → |(b.val:ℤ)-a.val|<(2^s:ℕ)) : - (∑a : Fin N, ∑c : Fin N, ∑b : Fin N, ∑d : Fin N, - if R a c ∧ R b d then - posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0) ≤ - 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (dg i))*binomialBound (∑i,hiddenTrial (d₂ i)) := by - have H := posterior_sibling_anchor_energy dg d₁ d₂ s - (finIntegerLabels N) (finIntegerLabels N) (finIntegerLabels N) (finIntegerLabels N) c₁ c₂ - simp_rw [sum_finIntegerLabels,sum_close_finIntegerLabels] at H - calc - _ = ∑a : Fin N, ∑b : Fin N, ∑c : Fin N, ∑d : Fin N, - if R a c ∧ R b d then - posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0 := by - apply Finset.sum_congr rfl - intro a ha - rw [Finset.sum_comm] - _ ≤ ∑a : Fin N, ∑b : Fin N, ∑c : Fin N, - if |(c.val:ℤ)-a.val|<(2^s:ℕ) then - ∑d : Fin N, if |(d.val:ℤ)-b.val|<(2^s:ℕ) then - posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0 - else 0 := by - apply Finset.sum_le_sum - intro a ha - apply Finset.sum_le_sum - intro b hb - apply Finset.sum_le_sum - intro c hc - by_cases h : |(c.val:ℤ)-a.val|<(2^s:ℕ) - · rw [ite_eq_left h] - apply Finset.sum_le_sum - intro d hd - by_cases hr : R a c ∧ R b d - · rw [ite_eq_left hr,ite_eq_left (hR b d hr.2)] - · rw [ite_eq_right hr] - split_ifs <;> positivity - · rw [ite_eq_right h] - apply le_of_eq - apply Finset.sum_eq_zero - intro d hd - exact ite_eq_right (fun hr => h (hR a c hr.1)) - _ ≤ _ := H - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- The actual finite central domain, distinctness and close-label restriction. -It is purely deterministic and is never added to the orientation posterior. -/ -def anchorPairAllowed (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (s b : ℕ) - (a c : Fin (T b)) : Prop := a∈A b ∧ c∈A b ∧ a≠c ∧ |(c.val:ℤ)-a.val|<(2^s:ℕ) - -/-- The source global plateau identity is required pointwise for bits, not -just in distribution and not after conditioning on successful layout. -/ -def HasGlobalPlateau (T g : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : Prop := - ∀b glob u, u∈A b → globalShift b glob u=(∑i,(bitIndex (glob i):ℤ))-shift b - -/-- Numerical binomial caps extracted from the literal known/hidden metadata. -In applications these are proved using the source hidden-trial lower bounds. -/ -def MetadataBinomialCaps (T n g : ℕ → ℕ) (B C : ℕ → ℝ) : - (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop - | 0, _ => True - | b+1, d => binomialBound (∑i, hiddenTrial (d.1 i)) ≤ B b ∧ - binomialBound (∑i, hiddenTrial (d.2.1 i)) ≤ C b ∧ - ∀u, MetadataBinomialCaps T n g B C b (d.2.2 u) - -/-- One correlated sibling-group anchor, using the actual child metadata -and their parent's one shared global orientation collection. -/ -def binarySiblingAnchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) - (u v : Fin (T (b+1))) (a c : Fin (T b)) : ℝ := - (posteriorArray d.2.1).expect (fun glob => - localAnchorAverage (d.2.2 u).1 s ((a.val:ℤ)-center b+globalShift (b+1) glob u) * - localAnchorAverage (d.2.2 v).1 s ((c.val:ℤ)-center b+globalShift (b+1) glob v)) - -theorem binarySiblingAnchor_plateau (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) - (hplat : HasGlobalPlateau T g A shift globalShift) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) - (u v : Fin (T (b+1))) (hu : u∈A (b+1)) (hv : v∈A (b+1)) (a c : Fin (T b)) : - binarySiblingAnchor T n g s center globalShift b d u v a c = - posteriorJointAnchors d.2.1 (d.2.2 u).1 (d.2.2 v).1 s - ((a.val:ℤ)-(center b+shift (b+1))) ((c.val:ℤ)-(center b+shift (b+1))) := by - calc - _ = (posteriorArray d.2.1).expect (fun glob => - localAnchorAverage (d.2.2 u).1 s ((a.val:ℤ)-center b+(∑i,(bitIndex (glob i):ℤ))-shift (b+1)) * - localAnchorAverage (d.2.2 v).1 s ((c.val:ℤ)-center b+(∑i,(bitIndex (glob i):ℤ))-shift (b+1))) := by - apply congrArg (FiniteLaw.expect (posteriorArray d.2.1)) - funext glob - have hu' := hplat (b+1) glob u hu - have hv' := hplat (b+1) glob v hv - rw [hu',hv'] - congr 2 <;> omega - _ = _ := by - rw [localAnchor_pair_plateau] - congr 1 <;> omega - -/-- Exact dynamic sum of squared group anchors over the allowed finite -labels below a fixed forced split. Distinct groups retain their own metadata. -/ -def binaryDescendantEnergy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) : - (b : ℕ) → WindowAssignments T n g (Option Bool) (b+1) → Fin (T b) → Fin (T b) → ℝ - | 0, _, _, _ => 1 - | b+1, d, u, v => - ∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), - if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then - binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 * - binaryDescendantEnergy T n g s center globalShift A b (d.2.2 u) a c * - binaryDescendantEnergy T n g s center globalShift A b (d.2.2 v) e f - else 0 - -theorem binaryDescendantEnergy_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (u v : Fin (T b)) : - 0≤binaryDescendantEnergy T n g s center globalShift A b d u v := by - induction b with - | zero => exact zero_le_one - | succ b ih => - apply Finset.sum_nonneg - intro a ha - apply Finset.sum_nonneg - intro c hc - apply Finset.sum_nonneg - intro e he - apply Finset.sum_nonneg - intro f hf - split_ifs - · exact mul_nonneg (mul_nonneg (sq_nonneg _) (ih _ _ _)) (ih _ _ _) - · exact le_refl _ - -/-- True common-jitter energy at one group, with its exact finite domains. -/ -theorem binarySiblingAnchor_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) - (hplat : HasGlobalPlateau T g A shift globalShift) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) - (u v : Fin (T (b+1))) (hu : u∈A (b+1)) (hv : v∈A (b+1)) : - (∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), - if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then - binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 else 0) ≤ - 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (d.2.1 i))* - binomialBound (∑i,hiddenTrial ((d.2.2 v).1 i)) := by - simp_rw [binarySiblingAnchor_plateau T n g s center globalShift A shift hplat b d u v hu hv] - exact posteriorJoint_finite_energy d.2.1 (d.2.2 u).1 (d.2.2 v).1 s - (center b+shift (b+1)) (center b+shift (b+1)) (anchorPairAllowed T A s b) - (fun a c h => h.2.2.2) - -/-- The complete bottom-up forced-label energy estimate. Its only numerical -inputs are actual metadata hidden-count binomial caps. The group bound -keeps one shared global kernel until AFTER squaring. -/ -theorem binaryDescendantEnergy_le (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) - (hplat : HasGlobalPlateau T g A shift globalShift) - (B C : ℕ → ℝ) (hB : ∀b,0≤B b) (hC : ∀b,0≤C b) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) - (hcap : MetadataBinomialCaps T n g B C (b+1) d) - (u v : Fin (T b)) (hu : u∈A b) (hv : v∈A b) : - binaryDescendantEnergy T n g s center globalShift A b d u v ≤ - binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by - let K : ℕ → ℝ := fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j - have hK : ∀j,0≤K j := fun j => mul_nonneg (mul_nonneg (by positivity) (hC _)) (hB _) - induction b with - | zero => exact le_refl _ - | succ b ih => - have hbudget := binaryTreeBudget_nonneg K hK b - have hgroup := binarySiblingAnchor_energy T n g s center globalShift A shift hplat b d u v hu hv - have hnum : 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (d.2.1 i))* - binomialBound (∑i,hiddenTrial ((d.2.2 v).1 i)) ≤ K b := by - exact mul_le_mul - (mul_le_mul_of_nonneg_left hcap.2.1 (by positivity)) - (hcap.2.2 v).1 (by unfold binomialBound; positivity) - (mul_nonneg (by positivity) (hC _)) - calc - _ ≤ (∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), - if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then - binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 else 0) * - (binaryTreeBudget K b)^2 := by - simp only [binaryDescendantEnergy,Finset.sum_mul] - apply Finset.sum_le_sum - intro a ha - apply Finset.sum_le_sum - intro c hc - apply Finset.sum_le_sum - intro e he - apply Finset.sum_le_sum - intro f hf - split_ifs with hr - · have hl := ih (d.2.2 u) (hcap.2.2 u) a c hr.1.1 hr.1.2.1 - have hh := ih (d.2.2 v) (hcap.2.2 v) e f hr.2.1 hr.2.2.1 - have hm := mul_le_mul hl hh - (binaryDescendantEnergy_nonneg T n g s center globalShift A b (d.2.2 v) e f) hbudget - have hf := mul_le_mul_of_nonneg_left hm - (sq_nonneg (binarySiblingAnchor T n g s center globalShift b d u v a e)) - simpa only [K,pow_two,mul_assoc] using hf - · simp only [zero_mul,le_refl] - _ ≤ K b*(binaryTreeBudget K b)^2 := - mul_le_mul_of_nonneg_right (hgroup.trans hnum) (sq_nonneg _) - _ = _ := rfl - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -def BinaryWindowLabels.allowed (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (s : ℕ) : - (b : ℕ) → BinaryWindowLabels T b → Prop - | 0, _ => True - | b+1, p => anchorPairAllowed T A s b p.1 p.2.1 ∧ - allowed T A s b p.2.2.1 ∧ allowed T A s b p.2.2.2 - -theorem BinaryWindowLabels.allowed_distinct (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) - (s b : ℕ) (p : BinaryWindowLabels T b) (hp : allowed T A s b p) : distinct T b p := by - induction b with - | zero => trivial - | succ b ih => exact ⟨hp.1.2.2.1,ih _ hp.2.1,ih _ hp.2.2⟩ - -/-- Regroup the two real top child labels, without changing the actual -finite label type or declaration order. -/ -def joinBinaryLabels {T : ℕ → ℕ} {b : ℕ} (a : Fin (T b) × Fin (T b)) - (p : BinaryWindowLabels T b × BinaryWindowLabels T b) : BinaryWindowLabels T (b+1) := - (a.1,a.2,p.1,p.2) - -theorem sum_binary_labels (T : ℕ → ℕ) (b : ℕ) (f : BinaryWindowLabels T (b+1) → ℝ) : - (∑p, f p) = ∑a : Fin (T b) × Fin (T b), - ∑p : BinaryWindowLabels T b × BinaryWindowLabels T b, f (joinBinaryLabels a p) := by - let e : BinaryWindowLabels T (b+1) ≃ - (Fin (T b) × Fin (T b)) × (BinaryWindowLabels T b × BinaryWindowLabels T b) := - { toFun := fun p => ((p.1,p.2.1),(p.2.2.1,p.2.2.2)) - invFun := fun z => joinBinaryLabels z.1 z.2 - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - exact (Fintype.sum_equiv e f (fun z => f (joinBinaryLabels z.1 z.2)) (fun _ => rfl)).trans - (Fintype.sum_prod_type _) - -/-- Exact finite tensor summation after preserving both deterministically -allowed label domains. No probabilistic independence is asserted here. -/ -theorem sum_pair_tensor {α β σ τ : Type*} [Fintype α] [Fintype β] [Fintype σ] [Fintype τ] - (R : α → Prop) (S : β → Prop) (P : σ → Prop) (Q : τ → Prop) - [DecidablePred R] [DecidablePred S] [DecidablePred P] [DecidablePred Q] - (K : α → β → ℝ) (f : α → σ → ℝ) (h : β → τ → ℝ) : - (∑a,∑x,∑b,∑y, if R a ∧ P x ∧ S b ∧ Q y then K a b*f a x*h b y else 0) = - ∑a,∑b,if R a ∧ S b then K a b*(∑x,if P x then f a x else 0)* - (∑y,if Q y then h b y else 0) else 0 := by - apply Finset.sum_congr rfl - intro a ha - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b hb - by_cases hr : R a - · by_cases hs : S b - · rw [ite_eq_left ⟨hr,hs⟩] - simp only [Finset.sum_mul,Finset.mul_sum] - conv_rhs => rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x hx - apply Finset.sum_congr rfl - intro y hy - by_cases hp : P x <;> by_cases hq : Q y <;> simp only [hr,hs,hp,hq,and_self, - false_and,and_false,ite_true,ite_false,mul_zero,zero_mul] - · simp only [hs,and_false,false_and,ite_false,Finset.sum_const_zero] - · simp only [hr,false_and,ite_false,Finset.sum_const_zero] - -/-- Literal sum over all descendant labels is the recursively compiled -sibling-group energy. This is the bridge from the actual anchor average to -bottom-up summation; no coefficient estimate is supplied as a hypothesis. -/ -theorem binaryAnchorBelow_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (u v : Fin (T b)) : - (∑p : BinaryWindowLabels T b × BinaryWindowLabels T b, - if BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2 then - binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels (u,v) p) d ^ 2 else 0) = - binaryDescendantEnergy T n g s center globalShift A b d u v := by - induction b with - | zero => - have hcard : Fintype.card (BinaryWindowLabels T 0) = 1 := rfl - simp only [BinaryWindowLabels.allowed,binaryAnchorBelow,binaryDescendantEnergy, - and_self,ite_true,one_pow,Finset.sum_const,Finset.card_univ,Fintype.card_prod,hcard,nsmul_eq_mul, - mul_one,Nat.cast_one] - | succ b ih => - rw [Fintype.sum_prod_type,sum_binary_labels] - simp_rw [sum_binary_labels] - have hpoint (a c : Fin (T b) × Fin (T b)) - (p q : BinaryWindowLabels T b × BinaryWindowLabels T b) : - (if BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels a p) ∧ - BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels c q) then - binaryAnchorBelow T n g s center globalShift (b+1) - (joinBinaryLabels (u,v) (joinBinaryLabels a p,joinBinaryLabels c q)) d ^ 2 else 0) = - (if anchorPairAllowed T A s b a.1 a.2 ∧ - (BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2) ∧ - anchorPairAllowed T A s b c.1 c.2 ∧ - (BinaryWindowLabels.allowed T A s b q.1 ∧ BinaryWindowLabels.allowed T A s b q.2) then - binarySiblingAnchor T n g s center globalShift b d u v a.1 c.1 ^ 2 * - binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels a p) (d.2.2 u) ^ 2 * - binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels c q) (d.2.2 v) ^ 2 else 0) := by - simp only [BinaryWindowLabels.allowed,joinBinaryLabels,and_assoc,binaryAnchorBelow,binarySiblingAnchor] - split_ifs <;> ring - simp_rw [hpoint] - rw [sum_pair_tensor] - simp_rw [ih] - change _ = ∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), _ - simp only [Fintype.sum_prod_type] - -/-- The square-sum of actual anchor averages over all admissible forced -indices, including the root local smoothing cost exactly once. -/ -theorem binaryAnchorAverage_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : - (∑p : BinaryWindowLabels T (b+1), if BinaryWindowLabels.allowed T A s (b+1) p then - binaryAnchorAverage T n g s center globalShift (b+1) p d incoming ^ 2 else 0) = - ∑u : Fin (T b),∑v : Fin (T b), if anchorPairAllowed T A s b u v then - localAnchorAverage d.1 s ((u.val:ℤ)-center b+incoming)^2 * - binaryDescendantEnergy T n g s center globalShift A b d u v else 0 := by - rw [sum_binary_labels,Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro u hu - apply Finset.sum_congr rfl - intro v hv - by_cases hr : anchorPairAllowed T A s b u v - · rw [ite_eq_left hr,←binaryAnchorBelow_sum,Finset.mul_sum] - apply Finset.sum_congr rfl - intro p hp - by_cases hsub : BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2 - · have ha : BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels (u,v) p) := ⟨hr,hsub⟩ - rw [ite_eq_left ha,ite_eq_left hsub,binaryAnchorAverage_factor T n g s center globalShift _ _ _ _ - (BinaryWindowLabels.allowed_distinct T A s _ _ ha),mul_pow] - rfl - · have ha : ¬BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels (u,v) p) := fun h => hsub h.2 - rw [ite_eq_right ha,ite_eq_right hsub,mul_zero] - · rw [ite_eq_right hr] - apply Finset.sum_eq_zero - intro p hp - exact ite_eq_right (fun h => hr h.1) - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Full finite forced-anchor squared coefficient budget, with the source -power of one local root cost and one correlated global/local cost per group. -This conclusion is about literal posterior averages and actual labels. -/ -theorem binaryAnchorAverage_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) - (hplat : HasGlobalPlateau T g A shift globalShift) - (B C : ℕ → ℝ) (hB : ∀b,0≤B b) (hC : ∀b,0≤C b) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) - (hcap : MetadataBinomialCaps T n g B C (b+1) d) (incoming : ℤ) : - (∑p : BinaryWindowLabels T (b+1), if BinaryWindowLabels.allowed T A s (b+1) p then - binaryAnchorAverage T n g s center globalShift (b+1) p d incoming ^ 2 else 0) ≤ - (2*((2^s:ℕ):ℝ)^3*B b) * - binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by - let K : ℕ → ℝ := fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j - have hK : ∀j,0≤K j := fun j => mul_nonneg (mul_nonneg (by positivity) (hC _)) (hB _) - have hbudget := binaryTreeBudget_nonneg K hK b - have hroot := localAnchor_finite_energy d.1 s (center b-incoming) - (anchorPairAllowed T A s b) (fun a c h => h.2.2.2) - have he (u : Fin (T b)) : (u.val:ℤ)-(center b-incoming)=(u.val:ℤ)-center b+incoming := by omega - simp_rw [he] at hroot - rw [binaryAnchorAverage_sum] - calc - _ ≤ (∑u : Fin (T b),∑v : Fin (T b),if anchorPairAllowed T A s b u v then - localAnchorAverage d.1 s ((u.val:ℤ)-center b+incoming)^2 else 0) * binaryTreeBudget K b := by - simp only [Finset.sum_mul] - apply Finset.sum_le_sum - intro u hu - apply Finset.sum_le_sum - intro v hv - split_ifs with hr - · exact mul_le_mul_of_nonneg_left - (binaryDescendantEnergy_le T n g s center globalShift A shift hplat B C hB hC b d hcap - u v hr.1 hr.2.1) (sq_nonneg _) - · simp only [zero_mul,le_refl] - _ ≤ (2*((2^s:ℕ):ℝ)^3*B b)*binaryTreeBudget K b := by - apply mul_le_mul_of_nonneg_right _ hbudget - exact hroot.trans (mul_le_mul_of_nonneg_left hcap.1 (by positivity)) - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- A literal unsigned length-L translated motif admits at most L child -labels in any finite window, even when the intended motif does not fit. -/ -theorem motifIndicator_finite_sum (s N : ℕ) (X : ℤ) : - (∑h : Fin N,motifIndicator s ((h.val:ℤ)-X)) ≤ (2^s:ℕ) := by - let A := Finset.univ.filter (fun h : Fin N => 0≤(h.val:ℤ)-X ∧ (h.val:ℤ)-X<(2^s:ℕ)) - have hc : A.card≤2^s := by - have H := Finset.card_le_card_of_injOn (s:=A) (t:=Finset.range (2^s)) - (fun h : Fin N => ((h.val:ℤ)-X).toNat) ?_ ?_ - · simpa only [Finset.card_range] using H - · intro h hh - have h' := (Finset.mem_filter.mp hh).2 - apply Finset.mem_range.mpr - dsimp only - omega - · intro h hh j hj he - have h' := (Finset.mem_filter.mp hh).2 - have j' := (Finset.mem_filter.mp hj).2 - apply Fin.ext - dsimp only at he - omega - have he : (∑h : Fin N,motifIndicator s ((h.val:ℤ)-X)) = (A.card:ℝ) := by - simp only [motifIndicator,A,Finset.sum_ite,Finset.sum_const_zero,add_zero, - Finset.sum_const,nsmul_eq_mul,mul_one] - rw [he] - exact_mod_cast hc - -/-- The complete bits law is arbitrary. All extra-leaf offsets may be -mutually correlated and correlated with the retained forced-anchor kernel. -Only the extra leaf label variables themselves are summed here. -/ -def extraLabelAverage {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) - (s N e : ℕ) (f : Ω → ℝ) (X : Ω → Fin e → ℤ) (h : Fin e → Fin N) : ℝ := - P.expect (fun ω => f ω*∏j,motifIndicator s (((h j).val:ℤ)-X ω j)) - -theorem extraLabelAverage_nonneg {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) - (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) - (h : Fin e → Fin N) : 0≤extraLabelAverage P s N e f X h := by - apply Finset.sum_nonneg - intro ω hω - apply mul_nonneg (P.nonneg ω) - exact mul_nonneg (hf ω) (Finset.prod_nonneg (fun j _ => motifIndicator_nonneg _ _)) - -/-- Source the correlated-anchor estimate, extra leaf l1 cost before squaring. No free -T_1 cost and no invalid decoupling of global displacements enter. -/ -theorem extraLabelAverage_sum {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) - (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) : - (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h) ≤ - ((2^s:ℕ):ℝ)^e*P.expect f := by - unfold extraLabelAverage expect - rw [Finset.sum_comm] - simp_rw [←mul_assoc,←Finset.mul_sum] - calc - _ ≤ ∑ω,P.mass ω*f ω*(((2^s:ℕ):ℝ)^e) := by - apply Finset.sum_le_sum - intro ω hω - apply mul_le_mul_of_nonneg_left _ (mul_nonneg (P.nonneg _) (hf ω)) - have he := Fintype.prod_sum (fun (j : Fin e) (h : Fin N) => motifIndicator s ((h.val:ℤ)-X ω j)) - rw [←he] - calc - _ ≤ ∏_j : Fin e,((2^s:ℕ):ℝ) := by - apply Finset.prod_le_prod₀ - · intro j hj - exact Finset.sum_nonneg (fun h hh => motifIndicator_nonneg _ _) - · intro j hj - exact motifIndicator_finite_sum s N (X ω j) - _ = _ := by simp - _ = _ := by rw [←Finset.sum_mul]; ring - -/-- The squared extra-leaf cost follows from nonnegativity AFTER the whole -shared-bit average, exactly as in the source (not from independence). -/ -theorem extraLabelAverage_energy {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) - (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) : - (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h ^ 2) ≤ - ((2^s:ℕ):ℝ)^(2*e)*(P.expect f)^2 := by - have hn (h : Fin e → Fin N) := extraLabelAverage_nonneg P s N e f hf X h - calc - _ ≤ (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h)^2 := - Finset.sum_sq_le_sq_sum_of_nonneg (fun h _ => hn h) - _ ≤ (((2^s:ℕ):ℝ)^e*P.expect f)^2 := by - apply pow_le_pow_left₀ (Finset.sum_nonneg (fun h _ => hn h)) - exact extraLabelAverage_sum P s N e f hf X - _ = _ := by rw [mul_pow,←pow_mul]; congr 2; omega -end TraceReconstruction - -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.LeafOracle + +namespace OAI + +/-! +# Anchors + +Forced anchors, extra-leaf closeness, and correlated group square-sum estimates. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +namespace FiniteLaw +/-- Two distinct actual child coordinates are independent. This does not +assert independence of their shared parent-global jitter. -/ +theorem coordinateProduct_expect_two {α : Type*} [Fintype α] {n : ℕ} + (P : Fin n → FiniteLaw α) (a c : Fin n) (hne : a≠c) (f h : α → ℝ) : + (coordinateProduct P).expect (fun x => f (x a)*h (x c)) = (P a).expect f*(P c).expect h := by + let F : Fin n → α → ℝ := fun j x => if j=a then f x else if j=c then h x else 1 + have hp : ∀x : Fin n → α, (∏j,F j (x j)) = f (x a)*h (x c) := by + intro x + rw [Finset.prod_eq_mul a c hne] + · simp [F,hne.symm] + · intro j hj hjs + simp [F,hjs.1,hjs.2] + · simp + · simp + rw [show (fun x : Fin n → α => f (x a)*h (x c)) = (fun x => ∏j,F j (x j)) by + funext x; exact (hp x).symm,coordinateProduct_expect_product] + rw [Finset.prod_eq_mul a c hne] + · simp [F,hne.symm] + · intro j hj hjs + simp [F,hjs.1,hjs.2,expect_const] + · simp + · simp + +/-- Exact local/global/children factorization with the parent-global draw +outside the product of child expectations. -/ +theorem expect_prod_two {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + {n : ℕ} (P : FiniteLaw α) (Q : FiniteLaw β) (R : Fin n → FiniteLaw γ) + (a c : Fin n) (hne : a≠c) (f : α → ℝ) (h k : β → γ → ℝ) : + (P.prod (Q.prod (coordinateProduct R))).expect (fun x => + f x.1 * (h x.2.1 (x.2.2 a)*k x.2.1 (x.2.2 c))) = + P.expect f * Q.expect (fun z => (R a).expect (h z)*(R c).expect (k z)) := by + simp_rw [expect_prod,expect_const_mul,coordinateProduct_expect_two R a c hne] + rw [expect_mul_const] +end FiniteLaw + +/-- A concrete binary selection of labels in the complete index tree. +Unlike a free abstract shape this retains every actual column label. -/ +def BinaryWindowLabels (T : ℕ → ℕ) : ℕ → Type + | 0 => PUnit + | b+1 => Fin (T b) × Fin (T b) × BinaryWindowLabels T b × BinaryWindowLabels T b + +noncomputable instance binaryWindowLabelsFintype (T : ℕ → ℕ) : + (b : ℕ) → Fintype (BinaryWindowLabels T b) + | 0 => inferInstanceAs (Fintype PUnit) + | b+1 => by + letI := binaryWindowLabelsFintype T b + exact inferInstanceAs (Fintype (Fin (T b) × Fin (T b) × BinaryWindowLabels T b × BinaryWindowLabels T b)) + +/-- The forced children are distinct at every split. Central restrictions +are separate deterministic predicates, not conditioning events. -/ +def BinaryWindowLabels.distinct (T : ℕ → ℕ) : (b : ℕ) → BinaryWindowLabels T b → Prop + | 0, _ => True + | b+1, p => p.1≠p.2.1 ∧ distinct T b p.2.2.1 ∧ distinct T b p.2.2.2 + +/-- Product of the first-child unsigned anchor at every forced nonleaf, +evaluated using the literal complete-tree orientation assignment. -/ +def binaryAnchorKernel (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : + (b : ℕ) → BinaryWindowLabels T b → WindowAssignments T n g Bool b → ℤ → ℝ + | 0, _, _, _ => 1 + | b+1, p, bits, incoming => + motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (bits.1 i):ℤ))+incoming) * + (binaryAnchorKernel T n g s center globalShift b p.2.2.1 (bits.2.2 p.1) + (globalShift b bits.2.1 p.1) * + binaryAnchorKernel T n g s center globalShift b p.2.2.2 (bits.2.2 p.2.1) + (globalShift b bits.2.1 p.2.1)) + +def binaryAnchorAverage (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (p : BinaryWindowLabels T b) (d : WindowAssignments T n g (Option Bool) b) + (incoming : ℤ) : ℝ := + (windowPosteriorLaw T n g b d).expect (fun bits => + binaryAnchorKernel T n g s center globalShift b p bits incoming) + +theorem binaryAnchorAverage_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (p : BinaryWindowLabels T 0) (d : WindowAssignments T n g (Option Bool) 0) (incoming : ℤ) : + binaryAnchorAverage T n g s center globalShift 0 p d incoming = 1 := by + apply expect_const + +theorem binaryAnchorAverage_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (p : BinaryWindowLabels T (b+1)) (d : WindowAssignments T n g (Option Bool) (b+1)) + (incoming : ℤ) (hd : p.1≠p.2.1) : + binaryAnchorAverage T n g s center globalShift (b+1) p d incoming = + (posteriorArray d.1).expect (fun loc => + motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (loc i):ℤ))+incoming)) * + (posteriorArray d.2.1).expect (fun glob => + binaryAnchorAverage T n g s center globalShift b p.2.2.1 (d.2.2 p.1) + (globalShift b glob p.1) * + binaryAnchorAverage T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1) + (globalShift b glob p.2.1)) := by + exact FiniteLaw.expect_prod_two (posteriorArray d.1) (posteriorArray d.2.1) + (fun i => windowPosteriorLaw T n g b (d.2.2 i)) p.1 p.2.1 hd + (fun loc => motifIndicator s ((p.1.val:ℤ)-center b+(∑i,(bitIndex (loc i):ℤ))+incoming)) + (fun glob bits => binaryAnchorKernel T n g s center globalShift b p.2.2.1 bits + (globalShift b glob p.1)) + (fun glob bits => binaryAnchorKernel T n g s center globalShift b p.2.2.2 bits + (globalShift b glob p.2.1)) + +/-- Local unsigned anchor averaged against its actual known/hidden flags. -/ +def localAnchorAverage {m : ℕ} (d : Fin m → Option Bool) (s : ℕ) (z : ℤ) : ℝ := + (posteriorArray d).expect (fun bits => motifIndicator s (z+∑i,(bitIndex (bits i):ℤ))) + +theorem localAnchorAverage_kernel {m : ℕ} (d : Fin m → Option Bool) (s : ℕ) (z : ℤ) : + localAnchorAverage d s z = windowKernel (∑i,hiddenTrial (d i)) (2^s) + (z+∑i,(visibleOnes (d i):ℤ)) := by + have h := posterior_unsigned_motif d s z + unfold localAnchorAverage posteriorArray coordinateProduct expect + convert h using 1 + congr 2 + exact Subsingleton.elim _ _ + +/-- Product of all lower sibling-group factors. Each group still averages +its own single common global draw, not two independent global draws. -/ +def binaryAnchorBelow (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : + (b : ℕ) → BinaryWindowLabels T (b+1) → WindowAssignments T n g (Option Bool) (b+1) → ℝ + | 0, _, _ => 1 + | b+1, p, d => + (posteriorArray d.2.1).expect (fun glob => + localAnchorAverage (d.2.2 p.1).1 s + ((p.2.2.1.1.val:ℤ)-center b+globalShift (b+1) glob p.1) * + localAnchorAverage (d.2.2 p.2.1).1 s + ((p.2.2.2.1.val:ℤ)-center b+globalShift (b+1) glob p.2.1)) * + (binaryAnchorBelow T n g s center globalShift b p.2.2.1 (d.2.2 p.1) * + binaryAnchorBelow T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1)) + +/-- Exact factorization of the forced anchor expectation into its root +kernel and all correlated sibling groups, at the real metadata/labels. -/ +theorem binaryAnchorAverage_factor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (p : BinaryWindowLabels T (b+1)) (d : WindowAssignments T n g (Option Bool) (b+1)) + (incoming : ℤ) (hd : BinaryWindowLabels.distinct T (b+1) p) : + binaryAnchorAverage T n g s center globalShift (b+1) p d incoming = + localAnchorAverage d.1 s ((p.1.val:ℤ)-center b+incoming) * + binaryAnchorBelow T n g s center globalShift b p d := by + induction b generalizing incoming with + | zero => + rw [binaryAnchorAverage_succ T n g s center globalShift _ p d incoming hd.1] + simp only [binaryAnchorAverage_zero,expect_const,binaryAnchorBelow,mul_one] + unfold localAnchorAverage + congr 1 + funext loc + congr 1 + omega + | succ b ih => + have hl := fun incoming => ih p.2.2.1 (d.2.2 p.1) incoming hd.2.1 + have hr := fun incoming => ih p.2.2.2 (d.2.2 p.2.1) incoming hd.2.2 + have hroot : (posteriorArray d.1).expect (fun loc => + motifIndicator s ((p.1.val:ℤ)-center (b+1)+(∑i,(bitIndex (loc i):ℤ))+incoming)) = + localAnchorAverage d.1 s ((p.1.val:ℤ)-center (b+1)+incoming) := by + apply congrArg (FiniteLaw.expect (posteriorArray d.1)) + funext loc + congr 1 + omega + have hh : (posteriorArray d.2.1).expect (fun glob => + binaryAnchorAverage T n g s center globalShift (b+1) p.2.2.1 (d.2.2 p.1) + (globalShift (b+1) glob p.1) * + binaryAnchorAverage T n g s center globalShift (b+1) p.2.2.2 (d.2.2 p.2.1) + (globalShift (b+1) glob p.2.1)) = + binaryAnchorBelow T n g s center globalShift (b+1) p d := by + calc + _ = (posteriorArray d.2.1).expect (fun glob => + (localAnchorAverage (d.2.2 p.1).1 s + ((p.2.2.1.1.val:ℤ)-center b+globalShift (b+1) glob p.1) * + localAnchorAverage (d.2.2 p.2.1).1 s + ((p.2.2.2.1.val:ℤ)-center b+globalShift (b+1) glob p.2.1)) * + (binaryAnchorBelow T n g s center globalShift b p.2.2.1 (d.2.2 p.1) * + binaryAnchorBelow T n g s center globalShift b p.2.2.2 (d.2.2 p.2.1))) := by + apply congrArg (FiniteLaw.expect (posteriorArray d.2.1)) + funext glob + exact (congrArg₂ (·*·) (hl _) (hr _)).trans (by ring) + _ = _ := expect_mul_const _ _ _ + exact (binaryAnchorAverage_succ T n g s center globalShift _ p d incoming hd.1).trans + (congrArg₂ (·*·) hroot hh) + +/-- One plateau group's local means are the genuine shared-global joint +anchor, with exactly the affine shift appearing in the layout. -/ +theorem localAnchor_pair_plateau {mg m₁ m₂ : ℕ} + (dg : Fin mg → Option Bool) (d₁ : Fin m₁ → Option Bool) (d₂ : Fin m₂ → Option Bool) + (s : ℕ) (z₁ z₂ shift : ℤ) : + (posteriorArray dg).expect (fun glob => + localAnchorAverage d₁ s (z₁+(∑i,(bitIndex (glob i):ℤ))-shift) * + localAnchorAverage d₂ s (z₂+(∑i,(bitIndex (glob i):ℤ))-shift)) = + posteriorJointAnchors dg d₁ d₂ s (z₁-shift) (z₂-shift) := by + unfold localAnchorAverage posteriorArray coordinateProduct expect posteriorJointAnchors + have he : ∀a b c d : ℤ,(a+b-c)+d = (a-c)+b+d := by intros; omega + simp_rw [he,mul_assoc] + congr 2 + · exact Subsingleton.elim _ _ + · funext bg + congr 1 + congr 1 + · congr 2 ; exact Subsingleton.elim _ _ + · congr 2 ; exact Subsingleton.elim _ _ + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- A role-selected forced subtree remembers the actual complete-tree labels, +not merely its abstract binary shape. -/ +def forcedWindowLabels (T : ℕ → ℕ) : (b : ℕ) → + (S : Finset (WindowLeaf T (b+1))) → (a : OccupiedWindowChoice T b S) → + (occupiedWindowTerm T b S a).Forced → BinaryWindowLabels T (b+1) + | 0, S, _, .node i j _ _ _ _ _ => + ((S.equivFin.symm i).val.1,(S.equivFin.symm j).val.1,PUnit.unit,PUnit.unit) + | b+1, S, a, .node i j _ _ _ left right => + (((selectedChildren S).equivFin.symm i).val, + ((selectedChildren S).equivFin.symm j).val, + forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) + (a.1 i) left, + forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) + (a.1 j) right) + +theorem forcedWindowLabels_distinct (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + BinaryWindowLabels.distinct T (b+1) (forcedWindowLabels T b S a F) := by + induction b with + | zero => + cases F with + | node i j hne hi hj left right => + refine ⟨?_,trivial,trivial⟩ + intro he + apply hne + apply S.equivFin.symm.injective + apply Subtype.ext + exact Prod.ext he (Subsingleton.elim (α := Fin 1) _ _) + | succ b ih => + cases F with + | node i j hne hi hj left right => + refine ⟨?_,ih _ _ left,ih _ _ right⟩ + intro he + exact hne ((selectedChildren S).equivFin.symm.injective (Subtype.ext he)) + +theorem motifIndicator_nonneg (s : ℕ) (z : ℤ) : 0 ≤ motifIndicator s z := by + unfold motifIndicator + split_ifs <;> norm_num + +theorem motifIndicator_le_one (s : ℕ) (z : ℤ) : motifIndicator s z≤1 := by + unfold motifIndicator + split_ifs <;> norm_num + +theorem binaryAnchorKernel_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (p : BinaryWindowLabels T b) (bits : WindowAssignments T n g Bool b) + (incoming : ℤ) : 0≤binaryAnchorKernel T n g s center globalShift b p bits incoming := by + induction b generalizing incoming with + | zero => exact zero_le_one + | succ b ih => + exact mul_nonneg (motifIndicator_nonneg _ _) (mul_nonneg (ih _ _ _) (ih _ _ _)) + +theorem bottomRoleWeight_abs_le_indicator (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : + |bottomRoleWeight χ σ a|≤χ := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> + fin_cases a <;> norm_num [bottomRoleWeight] + +theorem internalRoleWeight_active_abs_le_indicator (odd : Prop) [Decidable odd] + (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) (ha : a≠0) : + |internalRoleWeight odd χ σ a|≤χ := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> + fin_cases a <;> by_cases ho : odd <;> norm_num [internalRoleWeight,roleWeight,ho] at * + +theorem occupiedRootWeight_bottom_anchor (T : ℕ → ℕ) (s : ℕ) + (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) (X : ℤ) (i : Fin S.card) : + |occupiedRootWeight T s 0 S a X|≤ + motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X) := by + exact (abs_prod_le_coordinate _ i (fun j _ => + bottomRoleWeight_abs_le_one _ _ (prouhet_motif_value _ _) _)).trans + (bottomRoleWeight_abs_le_indicator _ _ (prouhet_motif_value _ _) _) + +theorem occupiedRootWeight_internal_anchor (T : ℕ → ℕ) (s b : ℕ) + (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) (X : ℤ) + (i : Fin (selectedChildren S).card) (hi : a.2 i≠0) : + |occupiedRootWeight T s (b+1) S a X|≤ + motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X) := by + exact (abs_prod_le_coordinate _ i (fun j _ => + internalRoleWeight_abs_le_one _ _ _ (prouhet_motif_value _ _) _)).trans + (internalRoleWeight_active_abs_le_indicator _ _ _ (prouhet_motif_value _ _) _ hi) + +theorem abs_prod_le_two {ι : Type*} [Fintype ι] (f : ι → ℝ) (a c : ι) (hne : a≠c) + (h : ∀j,j≠a → j≠c → |f j|≤1) : |∏j,f j|≤|f a| * |f c| := by + rw [Finset.abs_prod] + calc + _ ≤ ∏j, if j=a then |f a| else if j=c then |f c| else 1 := by + apply Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) + intro j hj + by_cases hja : j=a + · simp [hja] + · by_cases hjc : j=c + · simp [hjc,hne.symm] + · simpa only [ite_eq_right hja,ite_eq_right hjc] using h j hja hjc + _ = _ := by + rw [Finset.prod_eq_mul a c hne] + · simp [hne.symm] + · intro j hj hjs + simp [hjs.1,hjs.2] + · simp + · simp + +/-- The real role term is pointwise dominated by its selected unsigned +anchors. No independence assumption is used in this domination. -/ +theorem sourceRoleTerm_forced_anchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ + binaryAnchorKernel T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) bits incoming := by + induction b generalizing incoming with + | zero => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_zero] + change _ ≤ motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-center 0+ + (∑i,(bitIndex (bits.1 i):ℤ))+incoming)*(1*1) + rw [mul_one,mul_one] + convert occupiedRootWeight_bottom_anchor T s S a + (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) i using 1 ; congr 1 ; omega + | succ b ih => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_succ,abs_mul] + have hroot := occupiedRootWeight_internal_anchor T s b S a + (center (b+1)-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) i hi + have hprod := abs_prod_le_two (fun k : Fin (selectedChildren S).card => + sourceRoleTerm T n g s center globalShift b + (bits.2.2 ((selectedChildren S).equivFin.symm k).val) + (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm k).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm k).val) (a.1 k)) i j hne + (fun k _ _ => occupiedWindowWeight_abs_le_one T s _ b [] _ _) + have hl := ih (bits.2.2 ((selectedChildren S).equivFin.symm i).val) + (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) _ _ left + have hr := ih (bits.2.2 ((selectedChildren S).equivFin.symm j).val) + (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm j).val) _ _ right + have hp := mul_le_mul hl hr (abs_nonneg _) (binaryAnchorKernel_nonneg T n g s center globalShift _ _ _ _) + have hh := mul_le_mul hroot (hprod.trans hp) (abs_nonneg _) (motifIndicator_nonneg _ _) + apply hh.trans_eq + change motifIndicator s _ * _ = motifIndicator s + ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-center (b+1)+ + (∑k,(bitIndex (bits.1 k):ℤ))+incoming) * _ + congr 2 + omega + +/-- Therefore the coefficient average is bounded by the actual forced +anchor average, with the true posterior law and shared jitter retained. -/ +theorem sourceRoleAverage_forced_anchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ + binaryAnchorAverage T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) d incoming := by + exact ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans + ((windowPosteriorLaw T n g (b+1) d).expect_mono (fun bits => + sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F)) + +theorem sourceRoleTerm_valid (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (h : sourceRoleTerm T n g s center globalShift b bits incoming S a ≠ 0) : + (occupiedWindowTerm T b S a).valid := by + have hh := (occupiedWindowShape T s + (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) b [] S).term_valid + (occupiedWindowChoiceEquiv T s + (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) b [] S a) h + simpa only [occupiedWindowTerm_eq] using hh + +theorem sourceRoleAverage_valid (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (h : sourceRoleAverage T n g s center globalShift b d incoming S a ≠ 0) : + (occupiedWindowTerm T b S a).valid := by + by_contra hn + have hh : ∀bits, sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by + intro bits + by_contra hz + exact hn (sourceRoleTerm_valid T n g s center globalShift b bits incoming S a hz) + apply h + change (windowPosteriorLaw T n g (b+1) d).expect _ = 0 + rw [show (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) = + (fun _ => 0) from funext hh,expect_const] + +/-- The source's two alternatives now apply to actual posterior coefficient +terms: signed singleton smoothing, or domination by a genuine forced tree. -/ +theorem sourceRoleAverage_alternative (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (η : ℝ) (hη : 0≤η) (hcap : MetadataSmoothingCap T n g s η (b+1) d) + (ho : (occupiedWindowTerm T b S a).isOdd) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤η ∨ + ∃F : (occupiedWindowTerm T b S a).Forced, + BinaryWindowLabels.distinct T (b+1) (forcedWindowLabels T b S a F) ∧ + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ + binaryAnchorAverage T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) d incoming := by + by_cases hz : sourceRoleAverage T n g s center globalShift b d incoming S a=0 + · exact Or.inl (by simpa only [hz,abs_zero] using hη) + by_cases hn : (occupiedWindowTerm T b S a).noSingleton + · obtain ⟨F⟩ := OccupiedParityTree.forced_nonempty (occupiedWindowTerm T b S a) + (sourceRoleAverage_valid T n g s center globalShift b d incoming S a hz) hn ho + exact Or.inr ⟨F,forcedWindowLabels_distinct T b S a F, + sourceRoleAverage_forced_anchor T n g s center globalShift b d incoming S a F⟩ + · exact Or.inl (sourceRoleAverage_singleton T n g s center globalShift b d incoming S a η hcap hn) + +end TraceReconstruction + + +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- The unsigned bottom constraint at one literal complete-tree leaf. -/ +def sourceBottomIndicator (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : + (b : ℕ) → WindowAssignments T n g Bool (b+1) → ℤ → WindowLeaf T (b+1) → ℝ + | 0, bits, incoming, v => + motifIndicator s ((v.1.val:ℤ)-center 0+(∑i,(bitIndex (bits.1 i):ℤ))+incoming) + | b+1, bits, _, v => sourceBottomIndicator T n g s center globalShift b + (bits.2.2 v.1) (globalShift (b+1) bits.2.1 v.1) v.2 + +def sourceLeafProduct (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) : ℝ := + ∏v∈S, sourceBottomIndicator T n g s center globalShift b bits incoming v + +theorem sourceBottomIndicator_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (v : WindowLeaf T (b+1)) : + sourceBottomIndicator T n g s center globalShift b bits incoming v=0 ∨ + sourceBottomIndicator T n g s center globalShift b bits incoming v=1 := by + induction b generalizing incoming with + | zero => unfold sourceBottomIndicator motifIndicator; split_ifs <;> simp + | succ b ih => exact ih _ _ _ + +theorem prod_zero_one {ι : Type*} (S : Finset ι) (f : ι → ℝ) + (h : ∀i∈S,f i=0 ∨ f i=1) : (∏i∈S,f i)=0 ∨ (∏i∈S,f i)=1 := by + by_cases hz : ∃i∈S,f i=0 + · obtain ⟨i,hi,hz⟩ := hz + exact Or.inl (Finset.prod_eq_zero hi hz) + · right + apply Finset.prod_eq_one + intro i hi + exact (h i hi).resolve_left (fun he => hz ⟨i,hi,he⟩) + +theorem sourceLeafProduct_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) : + sourceLeafProduct T n g s center globalShift b bits incoming S=0 ∨ + sourceLeafProduct T n g s center globalShift b bits incoming S=1 := + prod_zero_one S _ (fun v _ => sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v) + +theorem binaryAnchorKernel_zero_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (p : BinaryWindowLabels T b) (bits : WindowAssignments T n g Bool b) + (incoming : ℤ) : + binaryAnchorKernel T n g s center globalShift b p bits incoming=0 ∨ + binaryAnchorKernel T n g s center globalShift b p bits incoming=1 := by + induction b generalizing incoming with + | zero => exact Or.inr rfl + | succ b ih => + have hl := ih p.2.2.1 (bits.2.2 p.1) (globalShift b bits.2.1 p.1) + have hr := ih p.2.2.2 (bits.2.2 p.2.1) (globalShift b bits.2.1 p.2.1) + change (_*(_*_)=0) ∨ (_*(_*_)=1) + rcases hl with hl|hl <;> rcases hr with hr|hr <;> rw [hl,hr] <;> + unfold motifIndicator <;> split_ifs <;> norm_num + +theorem sourceLeafProduct_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1+1))) : + sourceLeafProduct T n g s center globalShift (b+1) bits incoming S = + ∏i : Fin (selectedChildren S).card, + sourceLeafProduct T n g s center globalShift b + (bits.2.2 ((selectedChildren S).equivFin.symm i).val) + (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) := by + symm + exact (selected_prod_index (selectedChildren S) (fun h => + ∏v∈selectedChildLeaves S h, + sourceBottomIndicator T n g s center globalShift b (bits.2.2 h) + (globalShift (b+1) bits.2.1 h) v)).trans + (selected_prod_children S (fun v => + sourceBottomIndicator T n g s center globalShift (b+1) bits incoming v)) + +/-- Every selected leaf is active in the bottom expansion, including those +outside the forced tree. Their absolute constraints are not lost. -/ +theorem sourceRoleTerm_all_leaf_constraints (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : + |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ + sourceLeafProduct T n g s center globalShift b bits incoming S := by + induction b generalizing incoming with + | zero => + rw [sourceRoleTerm_zero] + change |∏i : Fin S.card, _|≤_ + rw [Finset.abs_prod] + calc + _ ≤ ∏i : Fin S.card, motifIndicator s + (((S.equivFin.symm i).val.1.val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) := + Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) + (fun i _ => bottomRoleWeight_abs_le_indicator _ _ (prouhet_motif_value _ _) _) + _ = ∏v∈S, motifIndicator s ((v.1.val:ℤ)- + (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) := + selected_prod_index S (fun v : WindowLeaf T 1 => motifIndicator s + ((v.1.val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming))) + _ = _ := by + apply Finset.prod_congr rfl + intro v hv + change motifIndicator s _ = motifIndicator s _ + congr 1 + omega + | succ b ih => + rw [sourceRoleTerm_succ,abs_mul,sourceLeafProduct_succ] + apply (mul_le_mul_of_nonneg_right + (occupiedRootWeight_abs_le_one T s (b+1) S a _) (abs_nonneg _)).trans + rw [one_mul,Finset.abs_prod] + apply Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) + intro i hi + exact ih _ _ _ _ + +theorem sourceLeafProduct_antitone (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (E S : Finset (WindowLeaf T (b+1))) (hES : E⊆S) : + sourceLeafProduct T n g s center globalShift b bits incoming S≤ + sourceLeafProduct T n g s center globalShift b bits incoming E := by + apply Finset.prod_le_prod_of_subset_of_le_one₀ hES + · intro v hv + rcases sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v with h|h <;> norm_num [h] + · intro v hv he + rcases sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v with h|h <;> norm_num [h] + +theorem le_mul_of_zero_one {x a b : ℝ} (ha : a=0 ∨ a=1) (hb : b=0 ∨ b=1) + (hxa : x≤a) (hxb : x≤b) : x≤a*b := by + rcases ha with rfl|rfl <;> rcases hb with rfl|rfl <;> norm_num at * <;> assumption + +/-- Actual forced anchor AND extra-leaf constraints in one bit expectation. +In particular E can be precisely the nonforced leaves; keeping it arbitrary +here permits the later label summation without any conditioning gates. -/ +theorem sourceRoleAverage_forced_extra (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S E : Finset (WindowLeaf T (b+1))) (hES : E⊆S) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ + (windowPosteriorLaw T n g (b+1) d).expect (fun bits => + binaryAnchorKernel T n g s center globalShift (b+1) (forcedWindowLabels T b S a F) bits incoming * + sourceLeafProduct T n g s center globalShift b bits incoming E) := by + apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans + apply FiniteLaw.expect_mono + intro bits + exact le_mul_of_zero_one + (binaryAnchorKernel_zero_one T n g s center globalShift _ _ bits incoming) + (sourceLeafProduct_zero_one T n g s center globalShift b bits incoming E) + (sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F) + ((sourceRoleTerm_all_leaf_constraints T n g s center globalShift b bits incoming S a).trans + (sourceLeafProduct_antitone T n g s center globalShift b bits incoming E S hES)) + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Deterministic closeness of each forced split; it is a restriction on +labels, never an additional conditioning event for the random bits. -/ +def BinaryWindowLabels.close (T : ℕ → ℕ) (s : ℕ) : (b : ℕ) → BinaryWindowLabels T b → Prop + | 0, _ => True + | b+1, p => |(p.1.val:ℤ)-p.2.1.val|<(2^s:ℕ) ∧ close T s b p.2.2.1 ∧ close T s b p.2.2.2 + +theorem motifIndicator_pair_close (s : ℕ) (a c X : ℤ) + (ha : motifIndicator s (a-X)≠0) (hc : motifIndicator s (c-X)≠0) : + |a-c|<(2^s:ℕ) := by + have hsa : 0≤a-X ∧ a-X<(2^s:ℕ) := by + by_contra h + exact ha (by simp only [motifIndicator,ite_eq_right h]) + have hsc : 0≤c-X ∧ c-X<(2^s:ℕ) := by + by_contra h + exact hc (by simp only [motifIndicator,ite_eq_right h]) + exact abs_lt.mpr ⟨by omega,by omega⟩ + +theorem nonzero_of_abs_le {x y : ℝ} (h : x≠0) (hle : |x|≤y) : y≠0 := by + intro hy + rw [hy] at hle + exact h (abs_eq_zero.mp (le_antisymm hle (abs_nonneg x))) + +/-- A nonzero literal role multiplier enforces all close-child restrictions +of every forced subtree chosen from its fixed role pattern. -/ +theorem sourceRoleTerm_forced_close (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) + (h : sourceRoleTerm T n g s center globalShift b bits incoming S a≠0) : + BinaryWindowLabels.close T s (b+1) (forcedWindowLabels T b S a F) := by + induction b generalizing incoming with + | zero => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_zero] at h + change |((S.equivFin.symm i).val.1.val:ℤ)-(S.equivFin.symm j).val.1.val|<(2^s:ℕ) ∧ True ∧ True + refine ⟨?_,trivial,trivial⟩ + exact motifIndicator_pair_close s _ _ _ + (nonzero_of_abs_le h (occupiedRootWeight_bottom_anchor T s S a _ i)) + (nonzero_of_abs_le h (occupiedRootWeight_bottom_anchor T s S a _ j)) + | succ b ih => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_succ] at h + have hm := mul_ne_zero_iff.mp h + have hc := Finset.prod_ne_zero_iff.mp hm.2 + change |(((selectedChildren S).equivFin.symm i).val.val:ℤ)- + ((selectedChildren S).equivFin.symm j).val.val|<(2^s:ℕ) ∧ + BinaryWindowLabels.close T s (b+1) + (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) + (a.1 i) left) ∧ + BinaryWindowLabels.close T s (b+1) + (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) + (a.1 j) right) + refine ⟨?_,ih _ _ _ _ left (hc i (Finset.mem_univ i)), + ih _ _ _ _ right (hc j (Finset.mem_univ j))⟩ + exact motifIndicator_pair_close s _ _ _ + (nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ i hi)) + (nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ j hj)) + +/-- Closeness remains a pure label condition after averaging, without +conditioning on it. -/ +theorem sourceRoleAverage_forced_close (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) + (h : sourceRoleAverage T n g s center globalShift b d incoming S a≠0) : + BinaryWindowLabels.close T s (b+1) (forcedWindowLabels T b S a F) := by + by_contra hn + have hh : ∀bits, sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by + intro bits + by_contra hz + exact hn (sourceRoleTerm_forced_close T n g s center globalShift b bits incoming S a F hz) + apply h + change (windowPosteriorLaw T n g (b+1) d).expect _ = 0 + rw [show (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) = + (fun _ => 0) from funext hh,expect_const] + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- The literal finite child labels embedded in the integer line. -/ +def finIntegerLabels (N : ℕ) : Finset ℤ := Finset.univ.image (fun i : Fin N => (i.val:ℤ)) + +theorem sum_finIntegerLabels (N : ℕ) (f : ℤ → ℝ) : + (∑a∈finIntegerLabels N,f a)=∑i : Fin N,f i.val := by + rw [finIntegerLabels,Finset.sum_image] + intro a ha b hb he + apply Fin.ext + change (a.val:ℤ)=(b.val:ℤ) at he + exact_mod_cast he + +theorem sum_close_finIntegerLabels (N L : ℕ) (a : ℤ) (f : ℤ → ℝ) : + (∑c∈closeLabels (finIntegerLabels N) L a,f c) = + ∑i : Fin N, if |(i.val:ℤ)-a|<(L:ℤ) then f i.val else 0 := by + rw [closeLabels,Finset.sum_filter,sum_finIntegerLabels] + +/-- Any deterministic plateau/distinctness restriction can be retained in +child-pair summation. Only closeness is used to upper bound its cost. -/ +theorem localAnchor_finite_energy {m N : ℕ} (d : Fin m → Option Bool) (s : ℕ) + (c : ℤ) (R : Fin N → Fin N → Prop) [DecidableRel R] + (hR : ∀a b,R a b → |(b.val:ℤ)-a.val|<(2^s:ℕ)) : + (∑a : Fin N, ∑b : Fin N, if R a b then localAnchorAverage d s ((a.val:ℤ)-c)^2 else 0) ≤ + 2*((2^s:ℕ):ℝ)^3*binomialBound (∑i,hiddenTrial (d i)) := by + have H := root_anchor_energy (∑i,hiddenTrial (d i)) (2^s) + (finIntegerLabels N) (finIntegerLabels N) (c-(∑i,(visibleOnes (d i):ℤ))) + rw [sum_finIntegerLabels] at H + simp_rw [sum_close_finIntegerLabels] at H + calc + _ ≤ ∑a : Fin N, ∑b : Fin N, + if |(b.val:ℤ)-a.val|<(2^s:ℕ) then + windowKernel (∑i,hiddenTrial (d i)) (2^s) + ((a.val:ℤ)-(c-∑i,(visibleOnes (d i):ℤ)))^2 else 0 := by + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro b hb + by_cases h : R a b + · rw [ite_eq_left h,ite_eq_left (hR a b h),localAnchorAverage_kernel] + convert le_refl _ using 1 ; congr 2 ; omega + · rw [ite_eq_right h] + split_ifs <;> positivity + _ ≤ _ := H + +/-- Actual shared-jitter energy over two finite sibling pairs. Parent-label +plateau restrictions are discharged before applying this lemma; arbitrary +restrictions on these child pairs are kept, not conditioned on. -/ +theorem posteriorJoint_finite_energy {mg m₁ m₂ N : ℕ} + (dg : Fin mg → Option Bool) (d₁ : Fin m₁ → Option Bool) (d₂ : Fin m₂ → Option Bool) + (s : ℕ) (c₁ c₂ : ℤ) (R : Fin N → Fin N → Prop) [DecidableRel R] + (hR : ∀a b,R a b → |(b.val:ℤ)-a.val|<(2^s:ℕ)) : + (∑a : Fin N, ∑c : Fin N, ∑b : Fin N, ∑d : Fin N, + if R a c ∧ R b d then + posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0) ≤ + 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (dg i))*binomialBound (∑i,hiddenTrial (d₂ i)) := by + have H := posterior_sibling_anchor_energy dg d₁ d₂ s + (finIntegerLabels N) (finIntegerLabels N) (finIntegerLabels N) (finIntegerLabels N) c₁ c₂ + simp_rw [sum_finIntegerLabels,sum_close_finIntegerLabels] at H + calc + _ = ∑a : Fin N, ∑b : Fin N, ∑c : Fin N, ∑d : Fin N, + if R a c ∧ R b d then + posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0 := by + apply Finset.sum_congr rfl + intro a ha + rw [Finset.sum_comm] + _ ≤ ∑a : Fin N, ∑b : Fin N, ∑c : Fin N, + if |(c.val:ℤ)-a.val|<(2^s:ℕ) then + ∑d : Fin N, if |(d.val:ℤ)-b.val|<(2^s:ℕ) then + posteriorJointAnchors dg d₁ d₂ s ((a.val:ℤ)-c₁) ((b.val:ℤ)-c₂)^2 else 0 + else 0 := by + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro b hb + apply Finset.sum_le_sum + intro c hc + by_cases h : |(c.val:ℤ)-a.val|<(2^s:ℕ) + · rw [ite_eq_left h] + apply Finset.sum_le_sum + intro d hd + by_cases hr : R a c ∧ R b d + · rw [ite_eq_left hr,ite_eq_left (hR b d hr.2)] + · rw [ite_eq_right hr] + split_ifs <;> positivity + · rw [ite_eq_right h] + apply le_of_eq + apply Finset.sum_eq_zero + intro d hd + exact ite_eq_right (fun hr => h (hR a c hr.1)) + _ ≤ _ := H + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- The actual finite central domain, distinctness and close-label restriction. +It is purely deterministic and is never added to the orientation posterior. -/ +def anchorPairAllowed (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (s b : ℕ) + (a c : Fin (T b)) : Prop := a∈A b ∧ c∈A b ∧ a≠c ∧ |(c.val:ℤ)-a.val|<(2^s:ℕ) + +/-- The source global plateau identity is required pointwise for bits, not +just in distribution and not after conditioning on successful layout. -/ +def HasGlobalPlateau (T g : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : Prop := + ∀b glob u, u∈A b → globalShift b glob u=(∑i,(bitIndex (glob i):ℤ))-shift b + +/-- Numerical binomial caps extracted from the literal known/hidden metadata. +In applications these are proved using the source hidden-trial lower bounds. -/ +def MetadataBinomialCaps (T n g : ℕ → ℕ) (B C : ℕ → ℝ) : + (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop + | 0, _ => True + | b+1, d => binomialBound (∑i, hiddenTrial (d.1 i)) ≤ B b ∧ + binomialBound (∑i, hiddenTrial (d.2.1 i)) ≤ C b ∧ + ∀u, MetadataBinomialCaps T n g B C b (d.2.2 u) + +/-- One correlated sibling-group anchor, using the actual child metadata +and their parent's one shared global orientation collection. -/ +def binarySiblingAnchor (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) + (u v : Fin (T (b+1))) (a c : Fin (T b)) : ℝ := + (posteriorArray d.2.1).expect (fun glob => + localAnchorAverage (d.2.2 u).1 s ((a.val:ℤ)-center b+globalShift (b+1) glob u) * + localAnchorAverage (d.2.2 v).1 s ((c.val:ℤ)-center b+globalShift (b+1) glob v)) + +theorem binarySiblingAnchor_plateau (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) + (hplat : HasGlobalPlateau T g A shift globalShift) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) + (u v : Fin (T (b+1))) (hu : u∈A (b+1)) (hv : v∈A (b+1)) (a c : Fin (T b)) : + binarySiblingAnchor T n g s center globalShift b d u v a c = + posteriorJointAnchors d.2.1 (d.2.2 u).1 (d.2.2 v).1 s + ((a.val:ℤ)-(center b+shift (b+1))) ((c.val:ℤ)-(center b+shift (b+1))) := by + calc + _ = (posteriorArray d.2.1).expect (fun glob => + localAnchorAverage (d.2.2 u).1 s ((a.val:ℤ)-center b+(∑i,(bitIndex (glob i):ℤ))-shift (b+1)) * + localAnchorAverage (d.2.2 v).1 s ((c.val:ℤ)-center b+(∑i,(bitIndex (glob i):ℤ))-shift (b+1))) := by + apply congrArg (FiniteLaw.expect (posteriorArray d.2.1)) + funext glob + have hu' := hplat (b+1) glob u hu + have hv' := hplat (b+1) glob v hv + rw [hu',hv'] + congr 2 <;> omega + _ = _ := by + rw [localAnchor_pair_plateau] + congr 1 <;> omega + +/-- Exact dynamic sum of squared group anchors over the allowed finite +labels below a fixed forced split. Distinct groups retain their own metadata. -/ +def binaryDescendantEnergy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) : + (b : ℕ) → WindowAssignments T n g (Option Bool) (b+1) → Fin (T b) → Fin (T b) → ℝ + | 0, _, _, _ => 1 + | b+1, d, u, v => + ∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), + if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then + binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 * + binaryDescendantEnergy T n g s center globalShift A b (d.2.2 u) a c * + binaryDescendantEnergy T n g s center globalShift A b (d.2.2 v) e f + else 0 + +theorem binaryDescendantEnergy_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (u v : Fin (T b)) : + 0≤binaryDescendantEnergy T n g s center globalShift A b d u v := by + induction b with + | zero => exact zero_le_one + | succ b ih => + apply Finset.sum_nonneg + intro a ha + apply Finset.sum_nonneg + intro c hc + apply Finset.sum_nonneg + intro e he + apply Finset.sum_nonneg + intro f hf + split_ifs + · exact mul_nonneg (mul_nonneg (sq_nonneg _) (ih _ _ _)) (ih _ _ _) + · exact le_refl _ + +/-- True common-jitter energy at one group, with its exact finite domains. -/ +theorem binarySiblingAnchor_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) + (hplat : HasGlobalPlateau T g A shift globalShift) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) + (u v : Fin (T (b+1))) (hu : u∈A (b+1)) (hv : v∈A (b+1)) : + (∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), + if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then + binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 else 0) ≤ + 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (d.2.1 i))* + binomialBound (∑i,hiddenTrial ((d.2.2 v).1 i)) := by + simp_rw [binarySiblingAnchor_plateau T n g s center globalShift A shift hplat b d u v hu hv] + exact posteriorJoint_finite_energy d.2.1 (d.2.2 u).1 (d.2.2 v).1 s + (center b+shift (b+1)) (center b+shift (b+1)) (anchorPairAllowed T A s b) + (fun a c h => h.2.2.2) + +/-- The complete bottom-up forced-label energy estimate. Its only numerical +inputs are actual metadata hidden-count binomial caps. The group bound +keeps one shared global kernel until AFTER squaring. -/ +theorem binaryDescendantEnergy_le (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) + (hplat : HasGlobalPlateau T g A shift globalShift) + (B C : ℕ → ℝ) (hB : ∀b,0≤B b) (hC : ∀b,0≤C b) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) + (hcap : MetadataBinomialCaps T n g B C (b+1) d) + (u v : Fin (T b)) (hu : u∈A b) (hv : v∈A b) : + binaryDescendantEnergy T n g s center globalShift A b d u v ≤ + binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by + let K : ℕ → ℝ := fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j + have hK : ∀j,0≤K j := fun j => mul_nonneg (mul_nonneg (by positivity) (hC _)) (hB _) + induction b with + | zero => exact le_refl _ + | succ b ih => + have hbudget := binaryTreeBudget_nonneg K hK b + have hgroup := binarySiblingAnchor_energy T n g s center globalShift A shift hplat b d u v hu hv + have hnum : 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (d.2.1 i))* + binomialBound (∑i,hiddenTrial ((d.2.2 v).1 i)) ≤ K b := by + exact mul_le_mul + (mul_le_mul_of_nonneg_left hcap.2.1 (by positivity)) + (hcap.2.2 v).1 (by unfold binomialBound; positivity) + (mul_nonneg (by positivity) (hC _)) + calc + _ ≤ (∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), + if anchorPairAllowed T A s b a c ∧ anchorPairAllowed T A s b e f then + binarySiblingAnchor T n g s center globalShift b d u v a e ^ 2 else 0) * + (binaryTreeBudget K b)^2 := by + simp only [binaryDescendantEnergy,Finset.sum_mul] + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro c hc + apply Finset.sum_le_sum + intro e he + apply Finset.sum_le_sum + intro f hf + split_ifs with hr + · have hl := ih (d.2.2 u) (hcap.2.2 u) a c hr.1.1 hr.1.2.1 + have hh := ih (d.2.2 v) (hcap.2.2 v) e f hr.2.1 hr.2.2.1 + have hm := mul_le_mul hl hh + (binaryDescendantEnergy_nonneg T n g s center globalShift A b (d.2.2 v) e f) hbudget + have hf := mul_le_mul_of_nonneg_left hm + (sq_nonneg (binarySiblingAnchor T n g s center globalShift b d u v a e)) + simpa only [K,pow_two,mul_assoc] using hf + · simp only [zero_mul,le_refl] + _ ≤ K b*(binaryTreeBudget K b)^2 := + mul_le_mul_of_nonneg_right (hgroup.trans hnum) (sq_nonneg _) + _ = _ := rfl + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +def BinaryWindowLabels.allowed (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) (s : ℕ) : + (b : ℕ) → BinaryWindowLabels T b → Prop + | 0, _ => True + | b+1, p => anchorPairAllowed T A s b p.1 p.2.1 ∧ + allowed T A s b p.2.2.1 ∧ allowed T A s b p.2.2.2 + +theorem BinaryWindowLabels.allowed_distinct (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) + (s b : ℕ) (p : BinaryWindowLabels T b) (hp : allowed T A s b p) : distinct T b p := by + induction b with + | zero => trivial + | succ b ih => exact ⟨hp.1.2.2.1,ih _ hp.2.1,ih _ hp.2.2⟩ + +/-- Regroup the two real top child labels, without changing the actual +finite label type or declaration order. -/ +def joinBinaryLabels {T : ℕ → ℕ} {b : ℕ} (a : Fin (T b) × Fin (T b)) + (p : BinaryWindowLabels T b × BinaryWindowLabels T b) : BinaryWindowLabels T (b+1) := + (a.1,a.2,p.1,p.2) + +theorem sum_binary_labels (T : ℕ → ℕ) (b : ℕ) (f : BinaryWindowLabels T (b+1) → ℝ) : + (∑p, f p) = ∑a : Fin (T b) × Fin (T b), + ∑p : BinaryWindowLabels T b × BinaryWindowLabels T b, f (joinBinaryLabels a p) := by + let e : BinaryWindowLabels T (b+1) ≃ + (Fin (T b) × Fin (T b)) × (BinaryWindowLabels T b × BinaryWindowLabels T b) := + { toFun := fun p => ((p.1,p.2.1),(p.2.2.1,p.2.2.2)) + invFun := fun z => joinBinaryLabels z.1 z.2 + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + exact (Fintype.sum_equiv e f (fun z => f (joinBinaryLabels z.1 z.2)) (fun _ => rfl)).trans + (Fintype.sum_prod_type _) + +/-- Exact finite tensor summation after preserving both deterministically +allowed label domains. No probabilistic independence is asserted here. -/ +theorem sum_pair_tensor {α β σ τ : Type*} [Fintype α] [Fintype β] [Fintype σ] [Fintype τ] + (R : α → Prop) (S : β → Prop) (P : σ → Prop) (Q : τ → Prop) + [DecidablePred R] [DecidablePred S] [DecidablePred P] [DecidablePred Q] + (K : α → β → ℝ) (f : α → σ → ℝ) (h : β → τ → ℝ) : + (∑a,∑x,∑b,∑y, if R a ∧ P x ∧ S b ∧ Q y then K a b*f a x*h b y else 0) = + ∑a,∑b,if R a ∧ S b then K a b*(∑x,if P x then f a x else 0)* + (∑y,if Q y then h b y else 0) else 0 := by + apply Finset.sum_congr rfl + intro a ha + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b hb + by_cases hr : R a + · by_cases hs : S b + · rw [ite_eq_left ⟨hr,hs⟩] + simp only [Finset.sum_mul,Finset.mul_sum] + conv_rhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x hx + apply Finset.sum_congr rfl + intro y hy + by_cases hp : P x <;> by_cases hq : Q y <;> simp only [hr,hs,hp,hq,and_self, + false_and,and_false,ite_true,ite_false,mul_zero,zero_mul] + · simp only [hs,and_false,false_and,ite_false,Finset.sum_const_zero] + · simp only [hr,false_and,ite_false,Finset.sum_const_zero] + +/-- Literal sum over all descendant labels is the recursively compiled +sibling-group energy. This is the bridge from the actual anchor average to +bottom-up summation; no coefficient estimate is supplied as a hypothesis. -/ +theorem binaryAnchorBelow_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (u v : Fin (T b)) : + (∑p : BinaryWindowLabels T b × BinaryWindowLabels T b, + if BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2 then + binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels (u,v) p) d ^ 2 else 0) = + binaryDescendantEnergy T n g s center globalShift A b d u v := by + induction b with + | zero => + have hcard : Fintype.card (BinaryWindowLabels T 0) = 1 := rfl + simp only [BinaryWindowLabels.allowed,binaryAnchorBelow,binaryDescendantEnergy, + and_self,ite_true,one_pow,Finset.sum_const,Finset.card_univ,Fintype.card_prod,hcard,nsmul_eq_mul, + mul_one,Nat.cast_one] + | succ b ih => + rw [Fintype.sum_prod_type,sum_binary_labels] + simp_rw [sum_binary_labels] + have hpoint (a c : Fin (T b) × Fin (T b)) + (p q : BinaryWindowLabels T b × BinaryWindowLabels T b) : + (if BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels a p) ∧ + BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels c q) then + binaryAnchorBelow T n g s center globalShift (b+1) + (joinBinaryLabels (u,v) (joinBinaryLabels a p,joinBinaryLabels c q)) d ^ 2 else 0) = + (if anchorPairAllowed T A s b a.1 a.2 ∧ + (BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2) ∧ + anchorPairAllowed T A s b c.1 c.2 ∧ + (BinaryWindowLabels.allowed T A s b q.1 ∧ BinaryWindowLabels.allowed T A s b q.2) then + binarySiblingAnchor T n g s center globalShift b d u v a.1 c.1 ^ 2 * + binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels a p) (d.2.2 u) ^ 2 * + binaryAnchorBelow T n g s center globalShift b (joinBinaryLabels c q) (d.2.2 v) ^ 2 else 0) := by + simp only [BinaryWindowLabels.allowed,joinBinaryLabels,and_assoc,binaryAnchorBelow,binarySiblingAnchor] + split_ifs <;> ring + simp_rw [hpoint] + rw [sum_pair_tensor] + simp_rw [ih] + change _ = ∑a : Fin (T b),∑c : Fin (T b),∑e : Fin (T b),∑f : Fin (T b), _ + simp only [Fintype.sum_prod_type] + +/-- The square-sum of actual anchor averages over all admissible forced +indices, including the root local smoothing cost exactly once. -/ +theorem binaryAnchorAverage_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : + (∑p : BinaryWindowLabels T (b+1), if BinaryWindowLabels.allowed T A s (b+1) p then + binaryAnchorAverage T n g s center globalShift (b+1) p d incoming ^ 2 else 0) = + ∑u : Fin (T b),∑v : Fin (T b), if anchorPairAllowed T A s b u v then + localAnchorAverage d.1 s ((u.val:ℤ)-center b+incoming)^2 * + binaryDescendantEnergy T n g s center globalShift A b d u v else 0 := by + rw [sum_binary_labels,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro u hu + apply Finset.sum_congr rfl + intro v hv + by_cases hr : anchorPairAllowed T A s b u v + · rw [ite_eq_left hr,←binaryAnchorBelow_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro p hp + by_cases hsub : BinaryWindowLabels.allowed T A s b p.1 ∧ BinaryWindowLabels.allowed T A s b p.2 + · have ha : BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels (u,v) p) := ⟨hr,hsub⟩ + rw [ite_eq_left ha,ite_eq_left hsub,binaryAnchorAverage_factor T n g s center globalShift _ _ _ _ + (BinaryWindowLabels.allowed_distinct T A s _ _ ha),mul_pow] + rfl + · have ha : ¬BinaryWindowLabels.allowed T A s (b+1) (joinBinaryLabels (u,v) p) := fun h => hsub h.2 + rw [ite_eq_right ha,ite_eq_right hsub,mul_zero] + · rw [ite_eq_right hr] + apply Finset.sum_eq_zero + intro p hp + exact ite_eq_right (fun h => hr h.1) + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Full finite forced-anchor squared coefficient budget, with the source +power of one local root cost and one correlated global/local cost per group. +This conclusion is about literal posterior averages and actual labels. -/ +theorem binaryAnchorAverage_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (shift : ℕ → ℤ) + (hplat : HasGlobalPlateau T g A shift globalShift) + (B C : ℕ → ℝ) (hB : ∀b,0≤B b) (hC : ∀b,0≤C b) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) + (hcap : MetadataBinomialCaps T n g B C (b+1) d) (incoming : ℤ) : + (∑p : BinaryWindowLabels T (b+1), if BinaryWindowLabels.allowed T A s (b+1) p then + binaryAnchorAverage T n g s center globalShift (b+1) p d incoming ^ 2 else 0) ≤ + (2*((2^s:ℕ):ℝ)^3*B b) * + binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by + let K : ℕ → ℝ := fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j + have hK : ∀j,0≤K j := fun j => mul_nonneg (mul_nonneg (by positivity) (hC _)) (hB _) + have hbudget := binaryTreeBudget_nonneg K hK b + have hroot := localAnchor_finite_energy d.1 s (center b-incoming) + (anchorPairAllowed T A s b) (fun a c h => h.2.2.2) + have he (u : Fin (T b)) : (u.val:ℤ)-(center b-incoming)=(u.val:ℤ)-center b+incoming := by omega + simp_rw [he] at hroot + rw [binaryAnchorAverage_sum] + calc + _ ≤ (∑u : Fin (T b),∑v : Fin (T b),if anchorPairAllowed T A s b u v then + localAnchorAverage d.1 s ((u.val:ℤ)-center b+incoming)^2 else 0) * binaryTreeBudget K b := by + simp only [Finset.sum_mul] + apply Finset.sum_le_sum + intro u hu + apply Finset.sum_le_sum + intro v hv + split_ifs with hr + · exact mul_le_mul_of_nonneg_left + (binaryDescendantEnergy_le T n g s center globalShift A shift hplat B C hB hC b d hcap + u v hr.1 hr.2.1) (sq_nonneg _) + · simp only [zero_mul,le_refl] + _ ≤ (2*((2^s:ℕ):ℝ)^3*B b)*binaryTreeBudget K b := by + apply mul_le_mul_of_nonneg_right _ hbudget + exact hroot.trans (mul_le_mul_of_nonneg_left hcap.1 (by positivity)) + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- A literal unsigned length-L translated motif admits at most L child +labels in any finite window, even when the intended motif does not fit. -/ +theorem motifIndicator_finite_sum (s N : ℕ) (X : ℤ) : + (∑h : Fin N,motifIndicator s ((h.val:ℤ)-X)) ≤ (2^s:ℕ) := by + let A := Finset.univ.filter (fun h : Fin N => 0≤(h.val:ℤ)-X ∧ (h.val:ℤ)-X<(2^s:ℕ)) + have hc : A.card≤2^s := by + have H := Finset.card_le_card_of_injOn (s:=A) (t:=Finset.range (2^s)) + (fun h : Fin N => ((h.val:ℤ)-X).toNat) ?_ ?_ + · simpa only [Finset.card_range] using H + · intro h hh + have h' := (Finset.mem_filter.mp hh).2 + apply Finset.mem_range.mpr + dsimp only + omega + · intro h hh j hj he + have h' := (Finset.mem_filter.mp hh).2 + have j' := (Finset.mem_filter.mp hj).2 + apply Fin.ext + dsimp only at he + omega + have he : (∑h : Fin N,motifIndicator s ((h.val:ℤ)-X)) = (A.card:ℝ) := by + simp only [motifIndicator,A,Finset.sum_ite,Finset.sum_const_zero,add_zero, + Finset.sum_const,nsmul_eq_mul,mul_one] + rw [he] + exact_mod_cast hc + +/-- The complete bits law is arbitrary. All extra-leaf offsets may be +mutually correlated and correlated with the retained forced-anchor kernel. +Only the extra leaf label variables themselves are summed here. -/ +def extraLabelAverage {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + (s N e : ℕ) (f : Ω → ℝ) (X : Ω → Fin e → ℤ) (h : Fin e → Fin N) : ℝ := + P.expect (fun ω => f ω*∏j,motifIndicator s (((h j).val:ℤ)-X ω j)) + +theorem extraLabelAverage_nonneg {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) + (h : Fin e → Fin N) : 0≤extraLabelAverage P s N e f X h := by + apply Finset.sum_nonneg + intro ω hω + apply mul_nonneg (P.nonneg ω) + exact mul_nonneg (hf ω) (Finset.prod_nonneg (fun j _ => motifIndicator_nonneg _ _)) + +/-- Source the correlated-anchor estimate, extra leaf l1 cost before squaring. No free +T_1 cost and no invalid decoupling of global displacements enter. -/ +theorem extraLabelAverage_sum {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) : + (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h) ≤ + ((2^s:ℕ):ℝ)^e*P.expect f := by + unfold extraLabelAverage expect + rw [Finset.sum_comm] + simp_rw [←mul_assoc,←Finset.mul_sum] + calc + _ ≤ ∑ω,P.mass ω*f ω*(((2^s:ℕ):ℝ)^e) := by + apply Finset.sum_le_sum + intro ω hω + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (P.nonneg _) (hf ω)) + have he := Fintype.prod_sum (fun (j : Fin e) (h : Fin N) => motifIndicator s ((h.val:ℤ)-X ω j)) + rw [←he] + calc + _ ≤ ∏_j : Fin e,((2^s:ℕ):ℝ) := by + apply Finset.prod_le_prod₀ + · intro j hj + exact Finset.sum_nonneg (fun h hh => motifIndicator_nonneg _ _) + · intro j hj + exact motifIndicator_finite_sum s N (X ω j) + _ = _ := by simp + _ = _ := by rw [←Finset.sum_mul]; ring + +/-- The squared extra-leaf cost follows from nonnegativity AFTER the whole +shared-bit average, exactly as in the source (not from independence). -/ +theorem extraLabelAverage_energy {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + (s N e : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → Fin e → ℤ) : + (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h ^ 2) ≤ + ((2^s:ℕ):ℝ)^(2*e)*(P.expect f)^2 := by + have hn (h : Fin e → Fin N) := extraLabelAverage_nonneg P s N e f hf X h + calc + _ ≤ (∑h : Fin e → Fin N,extraLabelAverage P s N e f X h)^2 := + Finset.sum_sq_le_sq_sum_of_nonneg (fun h _ => hn h) + _ ≤ (((2^s:ℕ):ℝ)^e*P.expect f)^2 := by + apply pow_le_pow_left₀ (Finset.sum_nonneg (fun h _ => hn h)) + exact extraLabelAverage_sum P s N e f hf X + _ = _ := by rw [mul_pow,←pow_mul]; congr 2; omega +end TraceReconstruction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Binomial.lean b/lean/OAI/Probability/TraceReconstruction/Binomial.lean index c193be4ffb18064330940b5badbe89dcd1149ac8..3ef5f8270e8d705982e78fdcd87a883251b74e1a 100644 --- a/lean/OAI/Probability/TraceReconstruction/Binomial.lean +++ b/lean/OAI/Probability/TraceReconstruction/Binomial.lean @@ -1,2111 +1,2111 @@ -import Mathlib - -namespace OAI - -/-! -# Binomial - -Fair and biased binomial laws, generating series, differences, concentration, Gaussian overlap, hidden counts, and local lower bounds. --/ - -open scoped ENNReal -noncomputable section - -namespace TraceReconstruction - -/-! ## Quantitative fair-binomial anti-concentration - -A direct inductive bound, avoiding an unformalized appeal to Stirling. -It is one of the estimates needed for signed binomial smoothing and -for the local/global anchor kernels. --/ - -/-- Fair-binomial mass, extended by zero beyond its natural support. -/ -def fairBinomial (n k : ℕ) : ℝ := (n.choose k : ℝ) / 2 ^ n - -theorem fairBinomial_nonneg (n k : ℕ) : 0 ≤ fairBinomial n k := by - unfold fairBinomial - positivity - -theorem centralBinom_square_bound (n : ℕ) : - ((n : ℝ) + 1) * (n.centralBinom : ℝ) ^ 2 ≤ (16 : ℝ) ^ n := by - induction n with - | zero => norm_num - | succ n ih => - have hn : (0 : ℝ) < n + 1 := by positivity - have hr : ((n : ℝ) + 1) * ((n + 1).centralBinom : ℝ) = - 2 * (2 * n + 1) * (n.centralBinom : ℝ) := by - exact_mod_cast Nat.succ_mul_centralBinom_succ n - have hc : 4 * (2 * (n : ℝ) + 1) ^ 2 * (n + 2) ≤ - 16 * (n + 1) ^ 3 := by nlinarith [sq_nonneg (n : ℝ)] - have hh : ((n : ℝ) + 1) ^ 2 * - ((n + 2) * ((n + 1).centralBinom : ℝ) ^ 2) ≤ - ((n : ℝ) + 1) ^ 2 * (16 * 16 ^ n) := by - calc - _ = (n + 2) * (((n : ℝ) + 1) * ((n + 1).centralBinom : ℝ)) ^ 2 := by ring - _ = (4 * (2 * (n : ℝ) + 1) ^ 2 * (n + 2)) * - (n.centralBinom : ℝ) ^ 2 := by rw [hr]; ring - _ ≤ (16 * ((n : ℝ) + 1) ^ 3) * (n.centralBinom : ℝ) ^ 2 := - mul_le_mul_of_nonneg_right hc (sq_nonneg _) - _ = (16 * ((n : ℝ) + 1) ^ 2) * - (((n : ℝ) + 1) * (n.centralBinom : ℝ) ^ 2) := by ring - _ ≤ (16 * ((n : ℝ) + 1) ^ 2) * 16 ^ n := - mul_le_mul_of_nonneg_left ih (by positivity) - _ = _ := by ring - have := (mul_le_mul_iff_right₀ (sq_pos_of_pos hn)).mp hh - rw [pow_succ (16 : ℝ) n] - convert this using 1 <;> push_cast <;> first | rfl | ring - -theorem choose_odd_le_twice_central (n k : ℕ) : - (2 * n + 1).choose k ≤ 2 * n.centralBinom := by - cases k with - | zero => simp only [Nat.choose_zero_right]; have := Nat.centralBinom_pos n; omega - | succ k => - rw [Nat.choose_succ_succ] - have h₁ := Nat.choose_le_centralBinom k n - have h₂ := Nat.choose_le_centralBinom (k + 1) n - simpa [Nat.succ_eq_add_one, two_mul] using Nat.add_le_add h₁ h₂ - -theorem fairBinomial_square_bound (n k : ℕ) : - ((n : ℝ) + 1) * fairBinomial n k ^ 2 ≤ 2 := by - have hcases : n % 2 = 0 ∨ n % 2 = 1 := Nat.mod_two_eq_zero_or_one n - rcases hcases with he | ho - · obtain ⟨m, rfl⟩ : ∃ m, n = 2 * m := ⟨n / 2, by omega⟩ - have hc : ((2 * m).choose k : ℝ) ≤ (m.centralBinom : ℝ) := - by exact_mod_cast Nat.choose_le_centralBinom k m - have hcs : ((2 * m).choose k : ℝ) ^ 2 ≤ (m.centralBinom : ℝ) ^ 2 := - pow_le_pow_left₀ (by positivity) hc 2 - have ht := centralBinom_square_bound m - have hp : ((2 : ℝ) ^ (2 * m)) ^ 2 = 16 ^ m := by - rw [← pow_mul, show 2 * m * 2 = 4 * m by omega, pow_mul] - norm_num - unfold fairBinomial - rw [div_pow, ← mul_div_assoc, div_le_iff₀ (by positivity : (0 : ℝ) < (2 ^ (2 * m)) ^ 2)] - rw [hp] - push_cast - nlinarith [mul_le_mul_of_nonneg_left hcs (show (0 : ℝ) ≤ m + 1 by positivity), - sq_nonneg ((2 * m).choose k : ℝ)] - · obtain ⟨m, rfl⟩ : ∃ m, n = 2 * m + 1 := ⟨n / 2, by omega⟩ - have hc : ((2 * m + 1).choose k : ℝ) ≤ 2 * (m.centralBinom : ℝ) := - by exact_mod_cast choose_odd_le_twice_central m k - have hcs : ((2 * m + 1).choose k : ℝ) ^ 2 ≤ 4 * (m.centralBinom : ℝ) ^ 2 := by - have := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ ((2 * m + 1).choose k : ℝ)) hc 2 - nlinarith - have ht := centralBinom_square_bound m - have hp : ((2 : ℝ) ^ (2 * m + 1)) ^ 2 = 4 * 16 ^ m := by - rw [pow_add, mul_pow, ← pow_mul, show 2 * m * 2 = 4 * m by omega, pow_mul] - norm_num - ring - unfold fairBinomial - rw [div_pow, ← mul_div_assoc, div_le_iff₀ (by positivity : (0 : ℝ) < (2 ^ (2 * m + 1)) ^ 2)] - rw [hp] - push_cast - nlinarith [mul_le_mul_of_nonneg_left hcs (show (0 : ℝ) ≤ m + 1 by positivity)] - - -/-! ## Discrete convolution estimates for the hidden displacement kernels -/ - -abbrev IntSeries := AddMonoidAlgebra ℝ ℤ - -def seriesL1 (f : IntSeries) : ℝ := ∑' z : ℤ, |f.coeff z| -def seriesL2Sq (f : IntSeries) : ℝ := ∑' z : ℤ, f.coeff z ^ 2 - -theorem series_summable (f : IntSeries) (φ : ℝ → ℝ) (hφ : φ 0 = 0) : - Summable (fun z : ℤ => φ (f.coeff z)) := - summable_of_hasFiniteSupport (f.coeff.hasFiniteSupport.fun_comp hφ) - -theorem seriesL1_nonneg (f : IntSeries) : 0 ≤ seriesL1 f := - tsum_nonneg fun _ => abs_nonneg _ - -theorem seriesL2Sq_nonneg (f : IntSeries) : 0 ≤ seriesL2Sq f := - tsum_nonneg fun _ => sq_nonneg _ - -theorem seriesL1_eq_sum (f : IntSeries) : - seriesL1 f = ∑ z ∈ f.coeff.support, |f.coeff z| := by - apply tsum_eq_sum - intro z hz - simp [Finsupp.notMem_support_iff.mp hz] - -theorem seriesL2Sq_eq_sum (f : IntSeries) : - seriesL2Sq f = ∑ z ∈ f.coeff.support, f.coeff z ^ 2 := by - apply tsum_eq_sum - intro z hz - simp [Finsupp.notMem_support_iff.mp hz] - -theorem series_summable_shift (f : IntSeries) (φ : ℝ → ℝ) - (hφ : φ 0 = 0) (a : ℤ) : - Summable (fun z : ℤ => φ (f.coeff (a + z))) := by - exact (Equiv.addLeft a).summable_iff.mpr (series_summable f φ hφ) - -theorem series_sum_shift (f : IntSeries) (φ : ℝ → ℝ) (a : ℤ) : - (∑' z : ℤ, φ (f.coeff (a + z))) = ∑' z : ℤ, φ (f.coeff z) := - (Equiv.addLeft a).tsum_eq (fun z => φ (f.coeff z)) - -theorem series_coeff_mul_abs_le (f g : IntSeries) (z : ℤ) : - |(f * g).coeff z| ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * |g.coeff (-a + z)| := by - rw [AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum] - simpa only [abs_mul] using Finset.abs_sum_le_sum_abs - (fun a => f.coeff a * g.coeff (-a + z)) f.coeff.support - -theorem seriesL1_mul_le (f g : IntSeries) : - seriesL1 (f * g) ≤ seriesL1 f * seriesL1 g := by - have hh (a : ℤ) : Summable (fun z : ℤ => |f.coeff a| * |g.coeff (-a + z)|) := - (series_summable_shift g abs (by simp) (-a)).mul_left _ - calc - seriesL1 (f * g) ≤ ∑' z : ℤ, ∑ a ∈ f.coeff.support, - |f.coeff a| * |g.coeff (-a + z)| := - Summable.tsum_le_tsum (series_coeff_mul_abs_le f g) (series_summable (f * g) abs (by simp)) - (summable_sum fun a _ => hh a) - _ = ∑ a ∈ f.coeff.support, ∑' z : ℤ, |f.coeff a| * |g.coeff (-a + z)| := - Summable.tsum_finsetSum fun a _ => hh a - _ = (∑ a ∈ f.coeff.support, |f.coeff a|) * seriesL1 g := by - simp_rw [tsum_mul_left, series_sum_shift] - exact (Finset.sum_mul _ _ _).symm - _ = seriesL1 f * seriesL1 g := by rw [seriesL1_eq_sum f] - -theorem series_coeff_mul_sq_le (f g : IntSeries) (z : ℤ) : - (f * g).coeff z ^ 2 ≤ seriesL1 f * - ∑ a ∈ f.coeff.support, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := by - rw [AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum, seriesL1_eq_sum] - apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul - · intro a _; exact abs_nonneg _ - · intro a _; positivity - · intro a _ - rw [mul_pow, ← mul_assoc, ← sq, sq_abs] - -theorem seriesL2Sq_mul_le (f g : IntSeries) : - seriesL2Sq (f * g) ≤ seriesL1 f ^ 2 * seriesL2Sq g := by - have hh (a : ℤ) : Summable (fun z : ℤ => |f.coeff a| * (g.coeff (-a + z)) ^ 2) := - (series_summable_shift g (fun x => x ^ 2) (by simp) (-a)).mul_left _ - calc - seriesL2Sq (f * g) ≤ ∑' z : ℤ, seriesL1 f * - ∑ a ∈ f.coeff.support, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := - Summable.tsum_le_tsum (series_coeff_mul_sq_le f g) - (series_summable (f * g) (fun x => x ^ 2) (by simp)) - ((summable_sum fun a _ => hh a).mul_left _) - _ = seriesL1 f * ∑ a ∈ f.coeff.support, - ∑' z : ℤ, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := by - rw [tsum_mul_left, Summable.tsum_finsetSum fun a _ => hh a] - _ = seriesL1 f ^ 2 * seriesL2Sq g := by - simp_rw [tsum_mul_left, series_sum_shift g (fun x => x ^ 2)] - rw [← Finset.sum_mul, ← seriesL1_eq_sum] - unfold seriesL2Sq - ring - -theorem series_coeff_mul_bound (f g : IntSeries) (M : ℝ) - (hg : ∀ z, |g.coeff z| ≤ M) (z : ℤ) : - |(f * g).coeff z| ≤ seriesL1 f * M := by - calc - _ ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * |g.coeff (-a + z)| := - series_coeff_mul_abs_le f g z - _ ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * M := - Finset.sum_le_sum fun a _ => mul_le_mul_of_nonneg_left (hg _) (abs_nonneg _) - _ = seriesL1 f * M := by rw [← Finset.sum_mul, ← seriesL1_eq_sum] - -/-! The probability generating series of the fair binomial kernel. -/ -def fairSeries (n : ℕ) : IntSeries := - (AddMonoidAlgebra.single 1 (1 / 2) + AddMonoidAlgebra.single 0 (1 / 2)) ^ n - -theorem fairSeries_add (m n : ℕ) : fairSeries (m + n) = fairSeries m * fairSeries n := - pow_add _ m n - -theorem fairSeries_sum (n : ℕ) : - fairSeries n = ∑ k ∈ Finset.range (n + 1), - AddMonoidAlgebra.single (k : ℤ) (fairBinomial n k) := by - unfold fairSeries - rw [add_pow] - apply Finset.sum_congr rfl - intro k hk - have hkn : k ≤ n := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hk - rw [AddMonoidAlgebra.single_pow, AddMonoidAlgebra.single_pow, - AddMonoidAlgebra.natCast_def, AddMonoidAlgebra.single_mul_single, - AddMonoidAlgebra.single_mul_single] - simp only [nsmul_eq_mul, mul_one, mul_zero, add_zero] - congr 1 - rw [← pow_add, Nat.add_sub_of_le hkn] - unfold fairBinomial - rw [div_pow] - simp [div_eq_mul_inv, mul_comm] - -theorem fairSeries_coeff_nat (n k : ℕ) : - (fairSeries n).coeff (k : ℤ) = fairBinomial n k := by - rw [fairSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - by_cases hk : k ≤ n - · rw [Finset.sum_eq_single k] - · simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_true] - · intro b _ hb - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hb] - · intro h - exact (h (Finset.mem_range.mpr (by omega))).elim - · rw [Finset.sum_eq_zero] - · simp [fairBinomial, Nat.choose_eq_zero_of_lt (by omega : n < k)] - · intro b hb - have hbk : b ≠ k := by simp only [Finset.mem_range] at hb; omega - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hbk] - -theorem fairSeries_coeff_neg (n : ℕ) (z : ℤ) (hz : z < 0) : - (fairSeries n).coeff z = 0 := by - rw [fairSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - apply Finset.sum_eq_zero - intro b _ - have h : (b : ℤ) ≠ z := by omega - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] - -theorem seriesL1_eq_sum_range (f : IntSeries) (n : ℕ) - (hneg : ∀ z < 0, f.coeff z = 0) - (hhigh : ∀ k : ℕ, n < k → f.coeff k = 0) : - seriesL1 f = ∑ k ∈ Finset.range (n + 1), |f.coeff (k : ℤ)| := by - let e : ℕ ↪ ℤ := ⟨Nat.cast, Nat.cast_injective⟩ - calc - seriesL1 f = ∑ z ∈ (Finset.range (n + 1)).map e, |f.coeff z| := by - apply tsum_eq_sum - intro z hz - by_cases h : 0 ≤ z - · have heq : ((z.toNat : ℕ) : ℤ) = z := Int.toNat_of_nonneg h - have hh : n < z.toNat := by - by_contra hn - apply hz - exact Finset.mem_map.mpr ⟨z.toNat, Finset.mem_range.mpr (by omega), heq⟩ - rw [← heq, hhigh _ hh, abs_zero] - · rw [hneg z (by omega), abs_zero] - _ = _ := Finset.sum_map _ e _ - -def firstDifference : IntSeries := - AddMonoidAlgebra.single 0 1 - AddMonoidAlgebra.single 1 1 - -theorem firstDifference_coeff (f : IntSeries) (z : ℤ) : - (firstDifference * f).coeff z = f.coeff z - f.coeff (z - 1) := by - rw [firstDifference, sub_mul, AddMonoidAlgebra.coeff_sub, Finsupp.sub_apply, - mul_comm _ f, AddMonoidAlgebra.coeff_mul_single_apply, - mul_comm _ f, AddMonoidAlgebra.coeff_mul_single_apply] - simp only [neg_zero, add_zero, mul_one, sub_eq_add_neg] - -theorem fairSeries_difference_coeff_zero (n : ℕ) : - (firstDifference * fairSeries n).coeff 0 = fairBinomial n 0 := by - rw [firstDifference_coeff] - norm_num only [zero_sub] - rw [fairSeries_coeff_neg n (-1) (by norm_num), sub_zero] - exact fairSeries_coeff_nat n 0 - -theorem fairSeries_difference_coeff_succ (n k : ℕ) : - (firstDifference * fairSeries n).coeff (↑(k + 1) : ℤ) = - fairBinomial n (k + 1) - fairBinomial n k := by - rw [firstDifference_coeff, fairSeries_coeff_nat] - simp only [Nat.cast_add, Nat.cast_one, add_sub_cancel_right, fairSeries_coeff_nat] - -theorem fairBinomial_unimodal_left (n k : ℕ) (hk : k < n / 2) : - fairBinomial n k ≤ fairBinomial n (k + 1) := by - apply div_le_div_of_nonneg_right _ (by positivity) - exact_mod_cast Nat.choose_le_succ_of_lt_half_left hk - -theorem fairBinomial_unimodal_right (n k : ℕ) (hk : n / 2 ≤ k) : - fairBinomial n (k + 1) ≤ fairBinomial n k := by - apply div_le_div_of_nonneg_right _ (by positivity) - have hnk : n - k ≤ k + 1 := by omega - have hmul := Nat.mul_le_mul_left (n.choose k) hnk - rw [← Nat.choose_succ_right_eq] at hmul - exact_mod_cast Nat.le_of_mul_le_mul_right hmul (by omega : 0 < k + 1) - -theorem fairBinomial_variation (n : ℕ) : - (∑ k ∈ Finset.range (n + 1), |fairBinomial n (k + 1) - fairBinomial n k|) = - 2 * fairBinomial n (n / 2) - fairBinomial n 0 := by - have hmid : n / 2 ≤ n + 1 := by omega - rw [← Finset.sum_range_add_sum_Ico _ hmid] - have hl : (∑ k ∈ Finset.range (n / 2), - |fairBinomial n (k + 1) - fairBinomial n k|) = - fairBinomial n (n / 2) - fairBinomial n 0 := by - rw [← Finset.sum_range_sub (fairBinomial n) (n / 2)] - apply Finset.sum_congr rfl - intro k hk - exact abs_of_nonneg (sub_nonneg.mpr - (fairBinomial_unimodal_left n k (Finset.mem_range.mp hk))) - have hr : (∑ k ∈ Finset.Ico (n / 2) (n + 1), - |fairBinomial n (k + 1) - fairBinomial n k|) = - fairBinomial n (n / 2) - fairBinomial n (n + 1) := by - calc - _ = ∑ k ∈ Finset.Ico (n / 2) (n + 1), - -(fairBinomial n (k + 1) - fairBinomial n k) := by - apply Finset.sum_congr rfl - intro k hk - exact abs_of_nonpos (sub_nonpos.mpr - (fairBinomial_unimodal_right n k (Finset.mem_Ico.mp hk).1)) - _ = _ := by rw [Finset.sum_neg_distrib, Finset.sum_Ico_sub _ hmid]; ring - rw [hl, hr] - have hzero : fairBinomial n (n + 1) = 0 := by simp [fairBinomial] - rw [hzero] - ring - -theorem fairSeries_difference_L1 (n : ℕ) : - seriesL1 (firstDifference * fairSeries n) = 2 * fairBinomial n (n / 2) := by - rw [seriesL1_eq_sum_range _ (n + 1)] - · rw [Finset.sum_range_succ', Nat.cast_zero, fairSeries_difference_coeff_zero, - abs_of_nonneg (fairBinomial_nonneg n 0)] - simp_rw [fairSeries_difference_coeff_succ] - rw [fairBinomial_variation] - ring - · intro z hz - rw [firstDifference_coeff, fairSeries_coeff_neg n z hz, - fairSeries_coeff_neg n (z - 1) (by omega), sub_zero] - · intro k hk - have hkpos : 0 < k := by omega - obtain ⟨v, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hkpos) - rw [fairSeries_difference_coeff_succ] - simp [fairBinomial, Nat.choose_eq_zero_of_lt (by omega : n < v), - Nat.choose_eq_zero_of_lt (by omega : n < v + 1)] - -def binomialBound (n : ℕ) : ℝ := Real.sqrt (2 / ((n : ℝ) + 1)) - -theorem binomialBound_nonneg (n : ℕ) : 0 ≤ binomialBound n := Real.sqrt_nonneg _ - -theorem fairBinomial_le_bound (n k : ℕ) : fairBinomial n k ≤ binomialBound n := by - apply Real.le_sqrt_of_sq_le - apply (le_div_iff₀ (by positivity : (0 : ℝ) < n + 1)).mpr - simpa only [mul_comm] using fairBinomial_square_bound n k - -theorem fairSeries_nonneg (n : ℕ) (z : ℤ) : 0 ≤ (fairSeries n).coeff z := by - by_cases hz : 0 ≤ z - · rw [← Int.toNat_of_nonneg hz, fairSeries_coeff_nat] - exact fairBinomial_nonneg _ _ - · rw [fairSeries_coeff_neg n z (by omega)] - -theorem fairSeries_coeff_bound (n : ℕ) (z : ℤ) : - |(fairSeries n).coeff z| ≤ binomialBound n := by - by_cases hz : 0 ≤ z - · rw [← Int.toNat_of_nonneg hz, fairSeries_coeff_nat, - abs_of_nonneg (fairBinomial_nonneg _ _)] - exact fairBinomial_le_bound _ _ - · rw [fairSeries_coeff_neg n z (by omega), abs_zero] - exact binomialBound_nonneg n - -theorem fairSeries_L1 (n : ℕ) : seriesL1 (fairSeries n) = 1 := by - rw [seriesL1_eq_sum_range _ n (fairSeries_coeff_neg n)] - · simp_rw [fairSeries_coeff_nat, abs_of_nonneg (fairBinomial_nonneg _ _)] - unfold fairBinomial - rw [← Finset.sum_div] - have hsum : (∑ k ∈ Finset.range (n + 1), (n.choose k : ℝ)) = (2 : ℝ) ^ n := by - exact_mod_cast Nat.sum_range_choose n - rw [hsum, div_self (by positivity)] - · intro k hk - rw [fairSeries_coeff_nat] - simp [fairBinomial, Nat.choose_eq_zero_of_lt hk] - -theorem seriesL2Sq_le_L1_mul_bound (f : IntSeries) (M : ℝ) - (hf : ∀ z, |f.coeff z| ≤ M) : seriesL2Sq f ≤ seriesL1 f * M := by - calc - _ ≤ ∑' z : ℤ, |f.coeff z| * M := by - apply Summable.tsum_le_tsum - · intro z - calc - f.coeff z ^ 2 = |f.coeff z| * |f.coeff z| := by rw [← sq, sq_abs] - _ ≤ _ := mul_le_mul_of_nonneg_left (hf z) (abs_nonneg _) - · exact series_summable f (fun x => x ^ 2) (by simp) - · exact (series_summable f abs (by simp)).mul_right M - _ = _ := tsum_mul_right - -theorem fairSeries_L2Sq_bound (n : ℕ) : seriesL2Sq (fairSeries n) ≤ binomialBound n := by - simpa only [fairSeries_L1, one_mul] using - seriesL2Sq_le_L1_mul_bound (fairSeries n) (binomialBound n) (fairSeries_coeff_bound n) - -theorem fairSeries_difference_L1_bound (n : ℕ) : - seriesL1 (firstDifference * fairSeries n) ≤ 2 * binomialBound n := by - rw [fairSeries_difference_L1] - exact mul_le_mul_of_nonneg_left (fairBinomial_le_bound n (n / 2)) (by norm_num) - -theorem seriesL1_single (z : ℤ) (r : ℝ) : - seriesL1 (AddMonoidAlgebra.single z r) = |r| := by - unfold seriesL1 - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply] - simp only [apply_ite abs, abs_zero] - exact tsum_ite_eq' z (fun _ : ℤ => |r|) - -theorem seriesL1_one : seriesL1 (1 : IntSeries) = 1 := by - change seriesL1 (AddMonoidAlgebra.single 0 1) = 1 - rw [seriesL1_single, abs_one] - -theorem seriesL1_pow_le (f : IntSeries) (s : ℕ) : seriesL1 (f ^ s) ≤ seriesL1 f ^ s := by - induction s with - | zero => simp only [pow_zero, seriesL1_one, le_refl] - | succ s ih => - rw [pow_succ, pow_succ] - exact (seriesL1_mul_le _ _).trans - (mul_le_mul_of_nonneg_right ih (seriesL1_nonneg f)) - -theorem fairSeries_mul_power (n s : ℕ) : - firstDifference ^ s * fairSeries ((s + 1) * n) = - (firstDifference * fairSeries n) ^ s * fairSeries n := by - simp only [fairSeries, add_mul, one_mul, pow_add, pow_mul, mul_pow] - ring - -/-- Quantitative higher-order smoothing, with n trials assigned to each - difference and one further group reserved for anti-concentration. -/ -theorem binomial_difference_coeff_bound (n s : ℕ) (z : ℤ) : - |(firstDifference ^ s * fairSeries ((s + 1) * n)).coeff z| ≤ - (2 * binomialBound n) ^ s * binomialBound n := by - rw [fairSeries_mul_power] - apply (series_coeff_mul_bound _ _ _ (fairSeries_coeff_bound n) z).trans - apply mul_le_mul_of_nonneg_right _ (binomialBound_nonneg n) - exact (seriesL1_pow_le _ _).trans - (pow_le_pow_left₀ (seriesL1_nonneg _) (fairSeries_difference_L1_bound n) s) - -theorem binomial_difference_L2Sq_bound (n s : ℕ) : - seriesL2Sq (firstDifference ^ s * fairSeries ((s + 1) * n)) ≤ - ((2 * binomialBound n) ^ s) ^ 2 * binomialBound n := by - rw [fairSeries_mul_power] - apply (seriesL2Sq_mul_le _ _).trans - apply mul_le_mul - · apply pow_le_pow_left₀ (seriesL1_nonneg _) - exact (seriesL1_pow_le _ _).trans - (pow_le_pow_left₀ (seriesL1_nonneg _) (fairSeries_difference_L1_bound n) s) - · exact fairSeries_L2Sq_bound n - · exact seriesL2Sq_nonneg _ - · positivity - -theorem seriesL1_add_le (f g : IntSeries) : - seriesL1 (f + g) ≤ seriesL1 f + seriesL1 g := by - calc - _ ≤ ∑' z : ℤ, (|f.coeff z| + |g.coeff z|) := by - apply Summable.tsum_le_tsum - · intro z - simpa only [AddMonoidAlgebra.coeff_add, Finsupp.add_apply] using - abs_add_le (f.coeff z) (g.coeff z) - · exact series_summable (f + g) abs (by simp) - · exact (series_summable f abs (by simp)).add (series_summable g abs (by simp)) - _ = _ := (series_summable f abs (by simp)).tsum_add (series_summable g abs (by simp)) - -theorem seriesL1_zero : seriesL1 (0 : IntSeries) = 0 := by - simp [seriesL1] - -theorem seriesL1_sum_le {ι : Type*} (A : Finset ι) (f : ι → IntSeries) : - seriesL1 (∑ i ∈ A, f i) ≤ ∑ i ∈ A, seriesL1 (f i) := by - classical - induction A using Finset.induction_on with - | empty => simp only [Finset.sum_empty, seriesL1_zero, le_refl] - | @insert a A ha ih => - rw [Finset.sum_insert ha, Finset.sum_insert ha] - exact (seriesL1_add_le _ _).trans (add_le_add le_rfl ih) - -theorem seriesL1_prod_le {ι : Type*} (A : Finset ι) (f : ι → IntSeries) : - seriesL1 (∏ i ∈ A, f i) ≤ ∏ i ∈ A, seriesL1 (f i) := by - classical - induction A using Finset.induction_on with - | empty => simp only [Finset.prod_empty, seriesL1_one, le_refl] - | @insert a A ha ih => - rw [Finset.prod_insert ha, Finset.prod_insert ha] - exact (seriesL1_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (seriesL1_nonneg _)) - -def geomSeries (k : ℕ) : IntSeries := ∑ a ∈ Finset.range k, (AddMonoidAlgebra.single 1 1) ^ a - -def prouhetSeries (s : ℕ) : IntSeries := - ∏ v ∈ Finset.range s, (1 - (AddMonoidAlgebra.single 1 1) ^ (2 ^ v)) - -def prouhetQuotient (s : ℕ) : IntSeries := - ∏ v ∈ Finset.range s, geomSeries (2 ^ v) - -theorem geomSeries_difference (k : ℕ) : - geomSeries k * firstDifference = 1 - (AddMonoidAlgebra.single 1 1 : IntSeries) ^ k := by - exact geom_sum_mul_neg _ _ - -theorem geomSeries_L1_le (k : ℕ) : seriesL1 (geomSeries k) ≤ k := by - apply (seriesL1_sum_le _ _).trans - simp only [AddMonoidAlgebra.single_pow, one_pow, seriesL1_single, abs_one, - Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one, le_refl] - -theorem prouhetSeries_factor (s : ℕ) : - prouhetSeries s = prouhetQuotient s * firstDifference ^ s := by - unfold prouhetSeries prouhetQuotient - simp_rw [← geomSeries_difference] - rw [Finset.prod_mul_distrib] - simp only [Finset.prod_const, Finset.card_range] - -theorem prouhetQuotient_L1_le (s : ℕ) : - seriesL1 (prouhetQuotient s) ≤ (2 : ℝ) ^ (s * s) := by - calc - _ ≤ ∏ v ∈ Finset.range s, seriesL1 (geomSeries (2 ^ v)) := seriesL1_prod_le _ _ - _ ≤ ∏ _v ∈ Finset.range s, ((2 : ℝ) ^ s) := by - apply Finset.prod_le_prod₀ - · intro v _; exact seriesL1_nonneg _ - · intro v hv - apply (geomSeries_L1_le _).trans - push_cast - apply pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) - exact (Finset.mem_range.mp hv).le - _ = _ := by simp only [Finset.prod_const, Finset.card_range, ← pow_mul] - -/-- Prouhet smoothing in an explicit finite-trial form. The constants - 2^(s*s) and (2 sqrt(2/(n+1)))^s are exp(O(s^2)) after assigning - n = floor(g/(s+1)) trials to each group. No Fourier theorem or - probabilistic estimate is assumed. -/ -theorem prouhet_binomial_coeff_bound (n s : ℕ) (z : ℤ) : - |(prouhetSeries s * fairSeries ((s + 1) * n)).coeff z| ≤ - (2 : ℝ) ^ (s * s) * ((2 * binomialBound n) ^ s * binomialBound n) := by - rw [prouhetSeries_factor, mul_assoc] - apply (series_coeff_mul_bound _ _ _ (binomial_difference_coeff_bound n s) z).trans - exact mul_le_mul_of_nonneg_right (prouhetQuotient_L1_le s) - (by positivity [binomialBound_nonneg n]) - -theorem prouhet_binomial_L2Sq_bound (n s : ℕ) : - seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n)) ≤ - ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound n) ^ s) ^ 2 * binomialBound n) := by - rw [prouhetSeries_factor, mul_assoc] - apply (seriesL2Sq_mul_le _ _).trans - apply mul_le_mul - · exact pow_le_pow_left₀ (seriesL1_nonneg _) (prouhetQuotient_L1_le s) 2 - · exact binomial_difference_L2Sq_bound n s - · exact seriesL2Sq_nonneg _ - · positivity - -/-- Arbitrary trial counts are obtained by convolving with the independent - unused trials; this cannot enlarge the coefficient or squared-L2 bounds. -/ -theorem prouhet_binomial_coeff_bound_remainder (n s r : ℕ) (z : ℤ) : - |(prouhetSeries s * fairSeries ((s + 1) * n + r)).coeff z| ≤ - (2 : ℝ) ^ (s * s) * ((2 * binomialBound n) ^ s * binomialBound n) := by - rw [fairSeries_add, ← mul_assoc, mul_comm (prouhetSeries s * _)] - simpa only [fairSeries_L1, one_mul] using - series_coeff_mul_bound (fairSeries r) (prouhetSeries s * fairSeries ((s + 1) * n)) - _ (prouhet_binomial_coeff_bound n s) z - -theorem prouhet_binomial_L2Sq_bound_remainder (n s r : ℕ) : - seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n + r)) ≤ - ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound n) ^ s) ^ 2 * binomialBound n) := by - rw [fairSeries_add, ← mul_assoc, mul_comm (prouhetSeries s * _)] - calc - _ ≤ seriesL1 (fairSeries r) ^ 2 * - seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n)) := seriesL2Sq_mul_le _ _ - _ ≤ _ := by simpa only [fairSeries_L1, one_pow, one_mul] using - prouhet_binomial_L2Sq_bound n s - -theorem signed_binomial_smoothing (g s : ℕ) : - (∀ z : ℤ, |(prouhetSeries s * fairSeries g).coeff z| ≤ - (2 : ℝ) ^ (s * s) * ((2 * binomialBound (g / (s + 1))) ^ s * - binomialBound (g / (s + 1)))) ∧ - (seriesL2Sq (prouhetSeries s * fairSeries g) ≤ - ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound (g / (s + 1))) ^ s) ^ 2 * - binomialBound (g / (s + 1)))) := by - have hg : (s + 1) * (g / (s + 1)) + g % (s + 1) = g := Nat.div_add_mod g (s + 1) - constructor - · intro z - simpa only [hg] using prouhet_binomial_coeff_bound_remainder (g / (s + 1)) s - (g % (s + 1)) z - · simpa only [hg] using prouhet_binomial_L2Sq_bound_remainder (g / (s + 1)) s - (g % (s + 1)) - -theorem binomialBound_quotient_le (g s : ℕ) : - binomialBound (g / (s + 1)) ≤ - Real.sqrt (2 * ((s : ℝ) + 1) / ((g : ℝ) + 1)) := by - apply Real.sqrt_le_sqrt - have hn : g + 1 ≤ (g / (s + 1) + 1) * (s + 1) := by - have hmod := Nat.mod_lt g (by omega : 0 < s + 1) - have hdiv := Nat.div_add_mod g (s + 1) - nlinarith - have hnr : (g : ℝ) + 1 ≤ ((g / (s + 1) : ℕ) + (1 : ℝ)) * ((s : ℝ) + 1) := by - exact_mod_cast hn - apply (div_le_div_iff₀ (by positivity : (0 : ℝ) < (g / (s + 1) : ℕ) + 1) - (by positivity : (0 : ℝ) < g + 1)).mpr - nlinarith - -theorem prouhetSeries_succ_coeff (s : ℕ) (z : ℤ) : - (prouhetSeries (s + 1)).coeff z = - (prouhetSeries s).coeff z - (prouhetSeries s).coeff (z - (2 ^ s : ℕ)) := by - rw [prouhetSeries, Finset.prod_range_succ, mul_sub, mul_one] - change (prouhetSeries s - prouhetSeries s * - (AddMonoidAlgebra.single 1 1 : IntSeries) ^ (2 ^ s)).coeff z = _ - rw [AddMonoidAlgebra.coeff_sub, Finsupp.sub_apply] - simp only [AddMonoidAlgebra.single_pow, one_pow, nsmul_eq_mul, mul_one, - AddMonoidAlgebra.coeff_mul_single_apply, sub_eq_add_neg] - -/-- The exact generating polynomial from the manuscript has unit signed - coefficients at every index 0,...,2^s-1, and no other coefficients. -/ -theorem prouhetSeries_coeff_spec (s : ℕ) : - (∀ z : ℤ, (z < 0 ∨ (2 ^ s : ℕ) ≤ z) → (prouhetSeries s).coeff z = 0) ∧ - (∀ z : ℤ, 0 ≤ z → z < (2 ^ s : ℕ) → |(prouhetSeries s).coeff z| = 1) := by - induction s with - | zero => - have hcoeff (z : ℤ) : (prouhetSeries 0).coeff z = if 0 = z then 1 else 0 := by - change (AddMonoidAlgebra.single 0 (1 : ℝ)).coeff z = _ - exact Finsupp.single_apply - constructor - · intro z hz - rw [hcoeff, ite_eq_right] - norm_num only [pow_zero, Nat.cast_one] at hz - omega - · intro z h0 h1 - have hz : z = 0 := by norm_num only [pow_zero, Nat.cast_one] at h1; omega - subst hz - rw [hcoeff, ite_eq_left rfl, abs_one] - | succ s ih => - have hp : (0 : ℤ) < (2 ^ s : ℕ) := by positivity - have hd : ((2 ^ (s + 1) : ℕ) : ℤ) = 2 * (2 ^ s : ℕ) := by push_cast; ring - constructor - · intro z hz - rw [prouhetSeries_succ_coeff] - rcases hz with hz | hz - · rw [ih.1 z (Or.inl hz), ih.1 _ (Or.inl (by omega)), sub_zero] - · rw [hd] at hz - rw [ih.1 z (Or.inr (by omega)), ih.1 _ (Or.inr (by omega)), sub_zero] - · intro z h0 h1 - rw [hd] at h1 - rw [prouhetSeries_succ_coeff] - by_cases hz : z < (2 ^ s : ℕ) - · rw [ih.1 (z - (2 ^ s : ℕ)) (Or.inl (by omega)), sub_zero] - exact ih.2 z h0 hz - · rw [ih.1 z (Or.inr (by omega)), zero_sub, abs_neg] - exact ih.2 _ (by omega) (by omega) - - -/-! ## Nonfair anti-concentration without an assumed Stirling estimate -/ - -def binomialMass (n : ℕ) (p : ℝ) (k : ℕ) : ℝ := - (n.choose k : ℝ) * p ^ k * (1 - p) ^ (n - k) - -theorem binomialMass_nonneg (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : - 0 ≤ binomialMass n p k := by - unfold binomialMass - positivity [hp.1, sub_nonneg.mpr hp.2] - -theorem sum_binomialMass (n : ℕ) (p : ℝ) : - ∑ k ∈ Finset.range (n + 1), binomialMass n p k = 1 := by - have h := add_pow p (1 - p) n - rw [show p + (1 - p) = 1 by ring, one_pow] at h - rw [h] - apply Finset.sum_congr rfl - intro k _ - unfold binomialMass - ring - -theorem binomialMass_harmonic_step (n k : ℕ) (p : ℝ) : - ((n : ℝ) + 1) * p * (binomialMass n p k / ((k : ℝ) + 1)) = - binomialMass (n + 1) p (k + 1) := by - have hc : ((n : ℝ) + 1) * (n.choose k : ℝ) = - ((n + 1).choose (k + 1) : ℝ) * ((k : ℝ) + 1) := by - exact_mod_cast Nat.add_one_mul_choose_eq n k - unfold binomialMass - rw [Nat.add_sub_add_right, pow_succ] - field_simp - nlinarith [congrArg (fun x : ℝ => x * p ^ k * (1 - p) ^ (n - k) * p) hc] - -theorem binomialMass_harmonic_identity (n : ℕ) (p : ℝ) : - ((n : ℝ) + 1) * p * - (∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1)) = - 1 - (1 - p) ^ (n + 1) := by - rw [Finset.mul_sum] - simp_rw [binomialMass_harmonic_step] - have h := sum_binomialMass (n + 1) p - rw [Finset.sum_range_succ'] at h - simp only [binomialMass, Nat.choose_zero_right, Nat.cast_one, pow_zero, - mul_one, one_mul, Nat.sub_zero] at h ⊢ - linarith - -theorem binomialMass_harmonic_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : - (∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1)) ≤ - 1 / (((n : ℝ) + 1) * p) := by - apply (le_div_iff₀ (mul_pos (by positivity) hp.1)).mpr - rw [mul_comm, binomialMass_harmonic_identity] - have h := pow_nonneg (sub_nonneg.mpr hp.2) (n + 1) - linarith - -/-- The weighted Cauchy--Schwarz step for mixing the fair estimates. -/ -theorem weighted_sum_sq_le {ι : Type*} (S : Finset ι) (w f : ι → ℝ) - (hw : ∀ i, 0 ≤ w i) : - (∑ i ∈ S, w i * f i) ^ 2 ≤ (∑ i ∈ S, w i) * ∑ i ∈ S, w i * f i ^ 2 := by - have heq (i : ι) : w i * f i = Real.sqrt (w i) * (Real.sqrt (w i) * f i) := by - rw [← mul_assoc, ← sq, Real.sq_sqrt (hw i)] - simp_rw [heq] - apply (Finset.sum_mul_sq_le_sq_mul_sq S (fun i => Real.sqrt (w i)) - (fun i => Real.sqrt (w i) * f i)).trans_eq - simp only [mul_pow, Real.sq_sqrt (hw _)] - -theorem mixed_binomialBound_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : - (∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k) ≤ - Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by - have hw (k : ℕ) := binomialMass_nonneg n k (show p ∈ Set.Icc 0 1 from ⟨hp.1.le, hp.2⟩) - have hs := weighted_sum_sq_le (Finset.range (n + 1)) (binomialMass n p) - binomialBound hw - rw [sum_binomialMass, one_mul] at hs - have hb (k : ℕ) : binomialBound k ^ 2 = 2 / ((k : ℝ) + 1) := - Real.sq_sqrt (by positivity) - simp_rw [hb] at hs - have heq : (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (2 / ((k : ℝ) + 1))) = - 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _ - ring - rw [heq] at hs - have hh := binomialMass_harmonic_le n hp - have hp0 := hp.1 - have hbound : (∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k) ^ 2 ≤ - 2 / (((n : ℝ) + 1) * p) := by - calc - _ ≤ 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1) := hs - _ ≤ 2 * (1 / (((n : ℝ) + 1) * p)) := mul_le_mul_of_nonneg_left hh (by norm_num) - _ = _ := by ring - have hsr := Real.sq_sqrt (show (0 : ℝ) ≤ 2 / (((n : ℝ) + 1) * p) by positivity) - have hpos := Real.sqrt_nonneg (2 / (((n : ℝ) + 1) * p)) - nlinarith only [hbound, hsr, hpos] - - -def mixedFairSeries (n : ℕ) (p : ℝ) : IntSeries := - (p • fairSeries 1 + (1 - p) • (1 : IntSeries)) ^ n - -def biasedSeries (n : ℕ) (p : ℝ) : IntSeries := - (AddMonoidAlgebra.single 1 p + AddMonoidAlgebra.single 0 (1 - p)) ^ n - -theorem mixedFairSeries_expansion (n : ℕ) (p : ℝ) : - mixedFairSeries n p = - ∑ k ∈ Finset.range (n + 1), binomialMass n p k • fairSeries k := by - rw [mixedFairSeries, add_pow] - apply Finset.sum_congr rfl - intro k _ - simp only [smul_pow, one_pow, smul_mul_smul, mul_one, fairSeries, pow_one] - rw [mul_comm, ← nsmul_eq_mul, ← Nat.cast_smul_eq_nsmul ℝ, smul_smul] - congr 1 - unfold binomialMass - ring - -theorem mixedFairSeries_eq_biased (n : ℕ) (p : ℝ) : - mixedFairSeries n p = biasedSeries n (p / 2) := by - unfold mixedFairSeries biasedSeries - congr 1 - ext z - simp only [fairSeries, pow_one, smul_add, AddMonoidAlgebra.one_def, AddMonoidAlgebra.coeff_add, - Finsupp.add_apply, AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, - smul_eq_mul, AddMonoidAlgebra.coeff_single, Finsupp.single_apply] - split_ifs <;> first | omega | ring - -theorem mixedFairSeries_coeff_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) (z : ℤ) : - |(mixedFairSeries n p).coeff z| ≤ Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by - rw [mixedFairSeries_expansion, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - simp only [AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, smul_eq_mul] - calc - _ ≤ ∑ k ∈ Finset.range (n + 1), |binomialMass n p k * (fairSeries k).coeff z| := - Finset.abs_sum_le_sum_abs _ _ - _ ≤ ∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k := by - apply Finset.sum_le_sum - intro k _ - have hw := binomialMass_nonneg n k (show p ∈ Set.Icc 0 1 from ⟨hp.1.le, hp.2⟩) - rw [abs_mul, abs_of_nonneg hw] - exact mul_le_mul_of_nonneg_left (fairSeries_coeff_bound k z) hw - _ ≤ _ := mixed_binomialBound_le n hp - -/-- At success probabilities at most 1/2, this gives the sharp variance - scale up to an absolute constant, using only the fair-coin estimate. -/ -theorem biasedSeries_coeff_bound_low (n : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioc 0 (1 / 2)) (z : ℤ) : - |(biasedSeries n p).coeff z| ≤ Real.sqrt (1 / (((n : ℝ) + 1) * p)) := by - have h2p : 2 * p ∈ Set.Ioc 0 1 := ⟨by linarith [hp.1], by linarith [hp.2]⟩ - have h := mixedFairSeries_coeff_bound n h2p z - rw [mixedFairSeries_eq_biased, show 2 * p / 2 = p by ring] at h - have heq : 2 / (((n : ℝ) + 1) * (2 * p)) = 1 / (((n : ℝ) + 1) * p) := by - field_simp - rwa [heq] at h - - -theorem biasedSeries_sum (n : ℕ) (p : ℝ) : - biasedSeries n p = ∑ k ∈ Finset.range (n + 1), - AddMonoidAlgebra.single (k : ℤ) (binomialMass n p k) := by - rw [biasedSeries, add_pow] - apply Finset.sum_congr rfl - intro k _ - rw [AddMonoidAlgebra.single_pow, AddMonoidAlgebra.single_pow, - AddMonoidAlgebra.natCast_def, AddMonoidAlgebra.single_mul_single, - AddMonoidAlgebra.single_mul_single] - simp only [nsmul_eq_mul, mul_one, mul_zero, add_zero] - congr 1 - unfold binomialMass - ring - -theorem biasedSeries_coeff_nat (n k : ℕ) (p : ℝ) : - (biasedSeries n p).coeff (k : ℤ) = binomialMass n p k := by - rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - by_cases hk : k ≤ n - · rw [Finset.sum_eq_single k] - · simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_true] - · intro b _ hb - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hb] - · intro h - exact (h (Finset.mem_range.mpr (by omega))).elim - · rw [Finset.sum_eq_zero] - · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : n < k)] - · intro b hb - have hbk : b ≠ k := by simp only [Finset.mem_range] at hb; omega - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hbk] - -theorem biasedSeries_coeff_neg (n : ℕ) (p : ℝ) (z : ℤ) (hz : z < 0) : - (biasedSeries n p).coeff z = 0 := by - rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - apply Finset.sum_eq_zero - intro b _ - have h : (b : ℤ) ≠ z := by omega - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] - -theorem biasedSeries_coeff_high (n : ℕ) (p : ℝ) (z : ℤ) (hz : (n : ℤ) < z) : - (biasedSeries n p).coeff z = 0 := by - rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] - apply Finset.sum_eq_zero - intro b hb - have h : (b : ℤ) ≠ z := by simp only [Finset.mem_range] at hb; omega - simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] - -theorem binomialMass_symm (n k : ℕ) (p : ℝ) (hk : k ≤ n) : - binomialMass n (1 - p) (n - k) = binomialMass n p k := by - unfold binomialMass - rw [Nat.choose_symm hk, Nat.sub_sub_self hk, show 1 - (1 - p) = p by ring] - ring - -theorem biasedSeries_coeff_reflect (n : ℕ) (p : ℝ) (z : ℤ) : - (biasedSeries n (1 - p)).coeff ((n : ℤ) - z) = (biasedSeries n p).coeff z := by - by_cases hz : z < 0 - · rw [biasedSeries_coeff_neg n p z hz, - biasedSeries_coeff_high n (1 - p) _ (by omega)] - by_cases hz' : (n : ℤ) < z - · rw [biasedSeries_coeff_high n p z hz', - biasedSeries_coeff_neg n (1 - p) _ (by omega)] - have h0 : 0 ≤ z := by omega - have hk : z.toNat ≤ n := by omega - have hzN : (z.toNat : ℤ) = z := Int.toNat_of_nonneg h0 - have hsub : (n : ℤ) - z = ((n - z.toNat : ℕ) : ℤ) := by omega - rw [hsub, ← hzN, biasedSeries_coeff_nat, biasedSeries_coeff_nat] - exact binomialMass_symm n z.toNat p hk - -/-- Uniform nonfair-binomial anti-concentration. This is the absolute - variance-scale upper bound used in the manuscript's rank kernels. -/ -theorem biasedSeries_coeff_bound (n : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : - |(biasedSeries n p).coeff z| ≤ - Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) := by - by_cases hlow : p ≤ 1 / 2 - · apply (biasedSeries_coeff_bound_low n ⟨hp.1, hlow⟩ z).trans - apply Real.sqrt_le_sqrt - apply one_div_le_one_div_of_le - · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) - · have hn : (0 : ℝ) ≤ n + 1 := by positivity - nlinarith [mul_nonneg hn (sq_nonneg p)] - · have hq : 1 - p ∈ Set.Ioc 0 (1 / 2) := ⟨by linarith [hp.2], by linarith⟩ - rw [← biasedSeries_coeff_reflect n p z] - apply (biasedSeries_coeff_bound_low n hq ((n : ℤ) - z)).trans - apply Real.sqrt_le_sqrt - apply one_div_le_one_div_of_le - · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) - · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) - (mul_nonneg (sub_nonneg.mpr hp.2.le) (sub_nonneg.mpr hp.2.le))] - - -theorem binomialMass_mul_index (n k : ℕ) (p : ℝ) : - binomialMass (n + 1) p (k + 1) * ((k : ℝ) + 1) = - ((n : ℝ) + 1) * p * binomialMass n p k := by - have h := binomialMass_harmonic_step n k p - have hk : ((k : ℝ) + 1) ≠ 0 := by positivity - rw [← h] - field_simp - -theorem binomialMass_index_sum (n : ℕ) (p : ℝ) (F : ℕ → ℝ) : - (∑ k ∈ Finset.range (n + 2), binomialMass (n + 1) p k * (k : ℝ) * F k) = - ((n : ℝ) + 1) * p * - ∑ k ∈ Finset.range (n + 1), binomialMass n p k * F (k + 1) := by - rw [show n + 2 = (n + 1) + 1 by omega, Finset.sum_range_succ'] - simp only [Nat.cast_zero, mul_zero, zero_mul, add_zero, Nat.cast_add, Nat.cast_one] - simp_rw [binomialMass_mul_index] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _ - ring - -theorem binomialMass_mean (n : ℕ) (p : ℝ) : - ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) = (n : ℝ) * p := by - cases n with - | zero => simp - | succ n => - simpa only [mul_one, sum_binomialMass, Nat.cast_add, Nat.cast_one] using - binomialMass_index_sum n p (fun _ => 1) - -theorem binomialMass_second_moment (n : ℕ) (p : ℝ) : - ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) ^ 2 = - (n : ℝ) * ((n : ℝ) - 1) * p ^ 2 + (n : ℝ) * p := by - cases n with - | zero => simp - | succ n => - have h := binomialMass_index_sum n p (fun k => k) - simp only [Nat.cast_add, Nat.cast_one] at h ⊢ - simp_rw [mul_add, mul_one, Finset.sum_add_distrib, binomialMass_mean, - sum_binomialMass] at h - calc - _ = ∑ k ∈ Finset.range (n + 2), binomialMass (n + 1) p k * (k : ℝ) * (k : ℝ) := by - apply Finset.sum_congr rfl - intro k _ - ring - _ = _ := by rw [h]; ring - -theorem binomialMass_variance (n : ℕ) (p : ℝ) : - (∑ k ∈ Finset.range (n + 1), binomialMass n p k * ((k : ℝ) - (n : ℝ) * p) ^ 2) = - (n : ℝ) * p * (1 - p) := by - calc - _ = (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) ^ 2) - - 2 * (n : ℝ) * p * (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ)) + - ((n : ℝ) * p) ^ 2 * (∑ k ∈ Finset.range (n + 1), binomialMass n p k) := by - rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro k _ - ring - _ = _ := by rw [binomialMass_second_moment, binomialMass_mean, sum_binomialMass]; ring - -theorem binomialMass_adjacent (n k : ℕ) (p : ℝ) (hk : k < n) : - ((k : ℝ) + 1) * (1 - p) * binomialMass n p (k + 1) = - ((n : ℝ) - k) * p * binomialMass n p k := by - have hc : (n.choose (k + 1) : ℝ) * ((k : ℝ) + 1) = - (n.choose k : ℝ) * ((n : ℝ) - (k : ℝ)) := by - simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_sub hk.le] using - congrArg (fun t : ℕ => (t : ℝ)) (Nat.choose_succ_right_eq n k) - have hnk : n - k = (n - (k + 1)) + 1 := by omega - unfold binomialMass - rw [hnk, pow_succ, pow_succ] - linear_combination p ^ k * p * (1 - p) ^ (n - (k + 1)) * (1 - p) * hc - -theorem binomialMass_le_mode (n l k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) - (hl : l ≤ n) (hmean : (n : ℝ) * p = l) : - binomialMass n p k ≤ binomialMass n p l := by - have h0 (j : ℕ) := binomialMass_nonneg n j ⟨hp.1.le, hp.2.le⟩ - have hleft (j : ℕ) (hj : j < l) : binomialMass n p j ≤ binomialMass n p (j + 1) := by - have hrec := binomialMass_adjacent n j p (by omega) - have hjr : (j : ℝ) + 1 ≤ l := by exact_mod_cast hj - have hcoef : (0 : ℝ) < ((j : ℝ) + 1) * (1 - p) := by - exact mul_pos (by positivity) (sub_pos.mpr hp.2) - have hdiff : ((j : ℝ) + 1) * (1 - p) ≤ ((n : ℝ) - j) * p := by - nlinarith [hp.1] - have := mul_le_mul_of_nonneg_right hdiff (h0 j) - nlinarith only [hrec, this, hcoef] - have hright (j : ℕ) (hj : l ≤ j) : binomialMass n p (j + 1) ≤ binomialMass n p j := by - by_cases hjn : j < n - · have hrec := binomialMass_adjacent n j p hjn - have hjr : (l : ℝ) ≤ j := by exact_mod_cast hj - have hcoef : (0 : ℝ) < ((j : ℝ) + 1) * (1 - p) := by - exact mul_pos (by positivity) (sub_pos.mpr hp.2) - have hdiff : ((n : ℝ) - j) * p ≤ ((j : ℝ) + 1) * (1 - p) := by - nlinarith [hp.2] - have := mul_le_mul_of_nonneg_right hdiff (h0 j) - nlinarith only [hrec, this, hcoef] - · have hjn' : n < j + 1 := by omega - simp only [binomialMass, Nat.choose_eq_zero_of_lt hjn', Nat.cast_zero, zero_mul] - exact h0 j - rcases le_total k l with hk | hk - · have haux : ∀ b : ℕ, k ≤ b → b ≤ l → binomialMass n p k ≤ binomialMass n p b := by - intro b hkb - induction b, hkb using Nat.le_induction with - | base => intro _; exact le_rfl - | succ b hb ih => - intro hbl - exact (ih (by omega)).trans (hleft b (by omega)) - exact haux l hk le_rfl - · induction k, hk using Nat.le_induction with - | base => exact le_rfl - | succ j hj ih => exact (hright j hj).trans ih - - -/-- A discrete law cannot have a very small maximum when its variance is bounded. -The explicit constant is deliberately loose, avoiding any use of Stirling. -/ -theorem discrete_mode_lower (n l : ℕ) (f : ℕ → ℝ) (M v : ℝ) - (hf : ∀ k, 0 ≤ f k) (hsum : ∑ k ∈ Finset.range (n + 1), f k = 1) - (hmax : ∀ k, f k ≤ M) - (hvar : ∑ k ∈ Finset.range (n + 1), f k * ((k : ℝ) - l) ^ 2 = v) - (hv : 1 ≤ v) : 1 / (12 * Real.sqrt v) ≤ M := by - classical - let r : ℕ := ⌈2 * Real.sqrt v⌉₊ - have hv0 : 0 ≤ v := by linarith - have hs : 1 ≤ Real.sqrt v := Real.one_le_sqrt.mpr hv - have hs2 := Real.sq_sqrt hv0 - have hrlo : 2 * Real.sqrt v ≤ (r : ℝ) := Nat.le_ceil _ - have hrhi : (r : ℝ) < 2 * Real.sqrt v + 1 := Nat.ceil_lt_add_one (by positivity) - have hrpos : (0 : ℝ) < r := by linarith - have hM : 0 ≤ M := (hf 0).trans (hmax 0) - let S := (Finset.range (n + 1)).filter (fun k => l - r ≤ k ∧ k ≤ l + r) - have hcard : S.card ≤ 2 * r + 1 := by - have hsub : S ⊆ Finset.Icc (l - r) (l + r) := by - intro k hk - exact Finset.mem_Icc.mpr (Finset.mem_filter.mp hk).2 - have := Finset.card_le_card hsub - rw [Nat.card_Icc] at this - omega - have hout (k : ℕ) (hk : ¬(l - r ≤ k ∧ k ≤ l + r)) : - (r : ℝ) ^ 2 ≤ ((k : ℝ) - l) ^ 2 := by - by_cases hleft : k < l - r - · have hnat : k + r < l := by omega - have hreal : (k : ℝ) + r < l := by exact_mod_cast hnat - nlinarith [sq_nonneg ((l : ℝ) - k - r)] - · have hnat : l + r < k := by omega - have hreal : (l : ℝ) + r < k := by exact_mod_cast hnat - nlinarith [sq_nonneg ((k : ℝ) - l - r)] - have hpoint (k : ℕ) : (r : ℝ) ^ 2 * f k ≤ - (if l - r ≤ k ∧ k ≤ l + r then (r : ℝ) ^ 2 * M else 0) + - f k * ((k : ℝ) - l) ^ 2 := by - split_ifs with hk - · have := mul_le_mul_of_nonneg_left (hmax k) (sq_nonneg (r : ℝ)) - have := mul_nonneg (hf k) (sq_nonneg ((k : ℝ) - l)) - linarith - · simpa only [zero_add, mul_comm] using mul_le_mul_of_nonneg_left (hout k hk) (hf k) - have htotal := Finset.sum_le_sum (fun k (_ : k ∈ Finset.range (n + 1)) => hpoint k) - rw [← Finset.mul_sum, hsum, mul_one, Finset.sum_add_distrib, hvar, - ← Finset.sum_filter] at htotal - change (r : ℝ) ^ 2 ≤ ∑ k ∈ S, (r : ℝ) ^ 2 * M + v at htotal - rw [Finset.sum_const, nsmul_eq_mul] at htotal - have hcardR : (S.card : ℝ) ≤ 2 * r + 1 := by exact_mod_cast hcard - have hbound := mul_le_mul_of_nonneg_right hcardR (mul_nonneg (sq_nonneg (r : ℝ)) hM) - have htotal' : (r : ℝ) ^ 2 ≤ (2 * r + 1) * ((r : ℝ) ^ 2 * M) + v := by - linarith - have hrv : 4 * v ≤ (r : ℝ) ^ 2 := by nlinarith [sq_nonneg ((r : ℝ) - 2 * Real.sqrt v)] - have hcancel : (3 : ℝ) / 4 ≤ (2 * r + 1) * M := by - have hrr : (0 : ℝ) < (r : ℝ) ^ 2 := sq_pos_of_pos hrpos - nlinarith only [htotal', hrv, hrr] - have hsize : 2 * (r : ℝ) + 1 ≤ 7 * Real.sqrt v := by linarith - have hfinal := mul_le_mul_of_nonneg_right hsize hM - apply (div_le_iff₀ (by positivity : 0 < 12 * Real.sqrt v)).mpr - nlinarith only [hcancel, hfinal] - -theorem binomialMass_mean_lower (n l : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) - (hl : l ≤ n) (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) : - 1 / (12 * Real.sqrt ((n : ℝ) * p * (1 - p))) ≤ binomialMass n p l := by - apply discrete_mode_lower n l (binomialMass n p) - (binomialMass n p l) ((n : ℝ) * p * (1 - p)) - · intro k; exact binomialMass_nonneg n k ⟨hp.1.le, hp.2.le⟩ - · exact sum_binomialMass n p - · intro k; exact binomialMass_le_mode n l k hp hl hmean - · rw [← hmean]; exact binomialMass_variance n p - · exact hv - - -theorem binomialMass_mean_inverse_sq (n l : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) - (hl : l ≤ n) (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) : - (binomialMass n p l)⁻¹ ^ 2 ≤ 144 * ((n : ℝ) * p * (1 - p)) := by - have hs : 0 < Real.sqrt ((n : ℝ) * p * (1 - p)) := - Real.sqrt_pos.mpr (by linarith) - have hlow := binomialMass_mean_lower n l hp hl hmean hv - have hpos : 0 < binomialMass n p l := lt_of_lt_of_le (by positivity) hlow - have hi : (binomialMass n p l)⁻¹ ≤ 12 * Real.sqrt ((n : ℝ) * p * (1 - p)) := by - rw [← one_div] - apply (div_le_iff₀ hpos).mpr - have := (div_le_iff₀ (by positivity)).mp hlow - nlinarith only [this] - have his := sq_le_sq₀ (by positivity) (by positivity) |>.mpr hi - have hs2 := Real.sq_sqrt (show 0 ≤ (n : ℝ) * p * (1 - p) by linarith) - nlinarith only [his, hs2] - -theorem seriesL1_smul (a : ℝ) (f : IntSeries) : - seriesL1 (a • f) = |a| * seriesL1 f := by - unfold seriesL1 - simp only [AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, smul_eq_mul, abs_mul] - exact tsum_mul_left - -theorem mixedFairSeries_difference_L1_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : - seriesL1 (firstDifference * mixedFairSeries n p) ≤ - 2 * Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by - rw [mixedFairSeries_expansion, Finset.mul_sum] - simp_rw [mul_smul_comm] - calc - _ ≤ ∑ k ∈ Finset.range (n + 1), - seriesL1 (binomialMass n p k • (firstDifference * fairSeries k)) := seriesL1_sum_le _ _ - _ ≤ ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (2 * binomialBound k) := by - apply Finset.sum_le_sum - intro k _ - have hw := binomialMass_nonneg n k ⟨hp.1.le, hp.2⟩ - rw [seriesL1_smul, abs_of_nonneg hw] - exact mul_le_mul_of_nonneg_left (fairSeries_difference_L1_bound k) hw - _ = 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _; ring - _ ≤ _ := mul_le_mul_of_nonneg_left (mixed_binomialBound_le n hp) (by norm_num) - -theorem biasedSeries_difference_L1_bound_low (n : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioc 0 (1 / 2)) : - seriesL1 (firstDifference * biasedSeries n p) ≤ - 2 * Real.sqrt (1 / (((n : ℝ) + 1) * p)) := by - have h := mixedFairSeries_difference_L1_bound n - (show 2 * p ∈ Set.Ioc 0 1 from ⟨by linarith [hp.1], by linarith [hp.2]⟩) - rw [mixedFairSeries_eq_biased] at h - have hp2 : 2 * p / 2 = p := by ring - have heq : 2 / (((n : ℝ) + 1) * (2 * p)) = 1 / (((n : ℝ) + 1) * p) := by - have hp0 : p ≠ 0 := ne_of_gt hp.1 - have hn0 : ((n : ℝ) + 1) ≠ 0 := by positivity - field_simp - rwa [hp2, heq] at h - -theorem biasedSeries_difference_reflect (n : ℕ) (p : ℝ) (z : ℤ) : - (firstDifference * biasedSeries n (1 - p)).coeff z = - -(firstDifference * biasedSeries n p).coeff ((n : ℤ) + 1 - z) := by - rw [firstDifference_coeff, firstDifference_coeff] - have h1 := biasedSeries_coeff_reflect n p ((n : ℤ) - z) - have h2 := biasedSeries_coeff_reflect n p ((n : ℤ) - (z - 1)) - have hz1 : (n : ℤ) - ((n : ℤ) - z) = z := by ring - have hz2 : (n : ℤ) - ((n : ℤ) - (z - 1)) = z - 1 := by ring - rw [hz1] at h1 - rw [hz2] at h2 - rw [h1, h2] - have he1 : (n : ℤ) - (z - 1) = n + 1 - z := by ring - have he2 : (n : ℤ) + 1 - z - 1 = n - z := by ring - rw [he1, he2] - ring - -theorem biasedSeries_difference_L1_reflect (n : ℕ) (p : ℝ) : - seriesL1 (firstDifference * biasedSeries n (1 - p)) = - seriesL1 (firstDifference * biasedSeries n p) := by - unfold seriesL1 - simp_rw [biasedSeries_difference_reflect, abs_neg] - exact (Equiv.subLeft ((n : ℤ) + 1)).tsum_eq - (fun z : ℤ => |(firstDifference * biasedSeries n p).coeff z|) - -theorem biasedSeries_difference_L1_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - seriesL1 (firstDifference * biasedSeries n p) ≤ - 2 * Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) := by - by_cases hlow : p ≤ 1 / 2 - · apply (biasedSeries_difference_L1_bound_low n ⟨hp.1, hlow⟩).trans - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.sqrt_le_sqrt - apply one_div_le_one_div_of_le - · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) - · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) (sq_nonneg p)] - · have hq : 1 - p ∈ Set.Ioc 0 (1 / 2) := ⟨by linarith [hp.2], by linarith⟩ - rw [← biasedSeries_difference_L1_reflect n p] - apply (biasedSeries_difference_L1_bound_low n hq).trans - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.sqrt_le_sqrt - apply one_div_le_one_div_of_le - · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) - · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) - (mul_nonneg (sub_nonneg.mpr hp.2.le) (sub_nonneg.mpr hp.2.le))] - - -def biasedBinomialBound (n : ℕ) (p : ℝ) : ℝ := - Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) - -theorem biasedSeries_L1 (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : - seriesL1 (biasedSeries n p) = 1 := by - rw [seriesL1_eq_sum_range _ n (biasedSeries_coeff_neg n p)] - · simp_rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ hp)] - exact sum_binomialMass n p - · intro k hk - exact biasedSeries_coeff_high n p k (by exact_mod_cast hk) - -theorem biasedSeries_L2Sq_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - seriesL2Sq (biasedSeries n p) ≤ biasedBinomialBound n p := by - have := seriesL2Sq_le_L1_mul_bound (biasedSeries n p) _ (biasedSeries_coeff_bound n hp) - simpa only [biasedSeries_L1 n ⟨hp.1.le, hp.2.le⟩, one_mul, biasedBinomialBound] using this - -theorem biasedSeries_add (m n : ℕ) (p : ℝ) : - biasedSeries (m + n) p = biasedSeries m p * biasedSeries n p := by - exact pow_add _ _ _ - -theorem biasedSeries_mul_power (n s : ℕ) (p : ℝ) : - firstDifference ^ s * biasedSeries ((s + 1) * n) p = - (firstDifference * biasedSeries n p) ^ s * biasedSeries n p := by - simp only [biasedSeries, add_mul, one_mul, pow_add, pow_mul, mul_pow] - ring - -theorem biased_difference_coeff_bound (n s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : - |(firstDifference ^ s * biasedSeries ((s + 1) * n) p).coeff z| ≤ - (2 * biasedBinomialBound n p) ^ s * biasedBinomialBound n p := by - rw [biasedSeries_mul_power] - apply (series_coeff_mul_bound _ _ _ (biasedSeries_coeff_bound n hp) z).trans - apply mul_le_mul_of_nonneg_right _ (Real.sqrt_nonneg _) - exact (seriesL1_pow_le _ _).trans - (pow_le_pow_left₀ (seriesL1_nonneg _) (biasedSeries_difference_L1_bound n hp) s) - -theorem biased_difference_L2Sq_bound (n s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n) p) ≤ - ((2 * biasedBinomialBound n p) ^ s) ^ 2 * biasedBinomialBound n p := by - rw [biasedSeries_mul_power] - apply (seriesL2Sq_mul_le _ _).trans - apply mul_le_mul - · apply pow_le_pow_left₀ (seriesL1_nonneg _) - exact (seriesL1_pow_le _ _).trans - (pow_le_pow_left₀ (seriesL1_nonneg _) (biasedSeries_difference_L1_bound n hp) s) - · exact biasedSeries_L2Sq_bound n hp - · exact seriesL2Sq_nonneg _ - · exact sq_nonneg _ - -theorem biased_difference_coeff_bound_remainder (n s r : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : - |(firstDifference ^ s * biasedSeries ((s + 1) * n + r) p).coeff z| ≤ - (2 * biasedBinomialBound n p) ^ s * biasedBinomialBound n p := by - rw [biasedSeries_add, ← mul_assoc, mul_comm (firstDifference ^ s * _)] - simpa only [biasedSeries_L1 r ⟨hp.1.le, hp.2.le⟩, one_mul] using - series_coeff_mul_bound (biasedSeries r p) (firstDifference ^ s * biasedSeries ((s + 1) * n) p) - _ (biased_difference_coeff_bound n s hp) z - -theorem biased_difference_L2Sq_bound_remainder (n s r : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioo 0 1) : - seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n + r) p) ≤ - ((2 * biasedBinomialBound n p) ^ s) ^ 2 * biasedBinomialBound n p := by - rw [biasedSeries_add, ← mul_assoc, mul_comm (firstDifference ^ s * _)] - calc - _ ≤ seriesL1 (biasedSeries r p) ^ 2 * - seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n) p) := seriesL2Sq_mul_le _ _ - _ ≤ _ := by simpa only [biasedSeries_L1 r ⟨hp.1.le, hp.2.le⟩, one_pow, one_mul] using - biased_difference_L2Sq_bound n s hp - -/-- All fixed-order nonfair binomial differences, at the exact variance scale. -This is the analytic estimate needed for the initial conditional rank kernels. -/ -theorem biased_difference_smoothing (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - (∀ z : ℤ, |(firstDifference ^ s * biasedSeries g p).coeff z| ≤ - (2 * biasedBinomialBound (g / (s + 1)) p) ^ s * - biasedBinomialBound (g / (s + 1)) p) ∧ - (seriesL2Sq (firstDifference ^ s * biasedSeries g p) ≤ - ((2 * biasedBinomialBound (g / (s + 1)) p) ^ s) ^ 2 * - biasedBinomialBound (g / (s + 1)) p) := by - have hg : (s + 1) * (g / (s + 1)) + g % (s + 1) = g := Nat.div_add_mod g (s + 1) - constructor - · intro z - simpa only [hg] using biased_difference_coeff_bound_remainder (g / (s + 1)) s - (g % (s + 1)) hp z - · simpa only [hg] using biased_difference_L2Sq_bound_remainder (g / (s + 1)) s - (g % (s + 1)) hp - -theorem biasedBinomialBound_quotient_le (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - biasedBinomialBound (g / (s + 1)) p ≤ - Real.sqrt (((s : ℝ) + 1) / (((g : ℝ) + 1) * p * (1 - p))) := by - unfold biasedBinomialBound - apply Real.sqrt_le_sqrt - have hpq : 0 < p * (1 - p) := mul_pos hp.1 (sub_pos.mpr hp.2) - have hnat : g + 1 ≤ (s + 1) * (g / (s + 1) + 1) := by - have hdiv := Nat.div_add_mod g (s + 1) - have hmod : g % (s + 1) < s + 1 := Nat.mod_lt g (by omega) - calc - g + 1 = (s + 1) * (g / (s + 1)) + g % (s + 1) + 1 := by omega - _ ≤ (s + 1) * (g / (s + 1)) + (s + 1) := by omega - _ = _ := by ring - have hreal : (g : ℝ) + 1 ≤ ((s : ℝ) + 1) * ((g / (s + 1) : ℕ) + 1 : ℝ) := by - exact_mod_cast hnat - have hp0 := hp.1 - have hq0 := sub_pos.mpr hp.2 - apply (div_le_div_iff₀ (by positivity) (by positivity)).mpr - nlinarith only [mul_le_mul_of_nonneg_right hreal hpq.le] - -/-! ## Gaussian overlap by exponential tilting of the exact binomial law -/ - -theorem binomialMass_tilt (n k : ℕ) {p a : ℝ} (hp : p ∈ Set.Ioo 0 1) - (ha : 0 < a) : - binomialMass n p k * a ^ k = - (1 - p + p * a) ^ n * binomialMass n (p * a / (1 - p + p * a)) k := by - by_cases hk : k ≤ n - · have hA : 0 < 1 - p + p * a := by positivity [sub_pos.mpr hp.2, hp.1] - have hsub : 1 - p * a / (1 - p + p * a) = (1 - p) / (1 - p + p * a) := by - field_simp; ring - unfold binomialMass - rw [hsub, div_pow, div_pow, mul_pow] - have hpow : (1 - p + p * a) ^ n = - (1 - p + p * a) ^ k * (1 - p + p * a) ^ (n - k) := by - rw [← pow_add, Nat.add_sub_of_le hk] - rw [hpow] - field_simp - · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : n < k)] - -theorem binomialMass_tilt_product (g h k : ℕ) {p a : ℝ} (hp : p ∈ Set.Ioo 0 1) - (ha : 0 < a) : - binomialMass g p k * binomialMass h p k = - ((1 - p + p * a) ^ g * (1 - p + p / a) ^ h) * - (binomialMass g (p * a / (1 - p + p * a)) k * - binomialMass h ((p / a) / (1 - p + p / a)) k) := by - have h1 := binomialMass_tilt g k hp ha - have h2 := binomialMass_tilt h k hp (inv_pos.mpr ha) - have hid := congrArg₂ (· * ·) h1 h2 - simp only [inv_pow, ← div_eq_mul_inv] at hid - have ha0 : a ^ k ≠ 0 := pow_ne_zero _ ha.ne' - calc - _ = (binomialMass g p k * a ^ k) * (binomialMass h p k / a ^ k) := by field_simp - _ = _ := by convert hid using 1; ring - -/-- Tilting on opposite sides retains an anti-concentration factor as well -as the Gaussian penalty for different numbers of trials. -/ -theorem binomial_overlap_tilt_bound (g h : ℕ) {p a : ℝ} - (hp : p ∈ Set.Ioo 0 1) (ha : 0 < a) : - (∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k) ≤ - ((1 - p + p * a) ^ g * (1 - p + p / a) ^ h) * - biasedBinomialBound g (p * a / (1 - p + p * a)) := by - have hA : 0 < 1 - p + p * a := by positivity [sub_pos.mpr hp.2, hp.1] - have hB : 0 < 1 - p + p / a := by positivity [sub_pos.mpr hp.2, hp.1] - have hpA : p * a / (1 - p + p * a) ∈ Set.Ioo (0 : ℝ) 1 := by - constructor - · positivity [hp.1] - · apply (div_lt_one hA).mpr; linarith [hp.2] - have hpB : (p / a) / (1 - p + p / a) ∈ Set.Ioo (0 : ℝ) 1 := by - constructor - · positivity [hp.1] - · apply (div_lt_one hB).mpr; linarith [hp.2] - simp_rw [binomialMass_tilt_product g h _ hp ha, ← Finset.mul_sum] - apply mul_le_mul_of_nonneg_left _ (by positivity) - calc - _ ≤ ∑ k ∈ Finset.range (h + 1), - biasedBinomialBound g (p * a / (1 - p + p * a)) * - binomialMass h ((p / a) / (1 - p + p / a)) k := by - apply Finset.sum_le_sum - intro k _ - apply mul_le_mul_of_nonneg_right _ (binomialMass_nonneg _ _ ⟨hpB.1.le, hpB.2.le⟩) - have hb := biasedSeries_coeff_bound g hpA (k : ℤ) - rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ ⟨hpA.1.le, hpA.2.le⟩)] at hb - exact hb - _ = _ := by rw [← Finset.mul_sum, sum_binomialMass, mul_one] - - -theorem binomial_tilt_variance {p t : ℝ} (hp : p ∈ Set.Ioo 0 1) - (ht : t ∈ Set.Icc 0 (1 / 4 : ℝ)) : - p * (1 - p) / 2 ≤ - (p * (1 - t) / (1 - p + p * (1 - t))) * - (1 - p * (1 - t) / (1 - p + p * (1 - t))) := by - have hA : 0 < 1 - p + p * (1 - t) := by - have := hp.1; have := hp.2; have := ht.2 - positivity [sub_pos.mpr hp.2, show (0 : ℝ) < 1 - t by linarith] - have hA1 : 1 - p + p * (1 - t) ≤ 1 := by nlinarith [mul_nonneg hp.1.le ht.1] - have hAsq : (1 - p + p * (1 - t)) ^ 2 ≤ 1 := by nlinarith - have hpq : 0 < p * (1 - p) := mul_pos hp.1 (sub_pos.mpr hp.2) - have heq : (p * (1 - t) / (1 - p + p * (1 - t))) * - (1 - p * (1 - t) / (1 - p + p * (1 - t))) = - p * (1 - p) * (1 - t) / (1 - p + p * (1 - t)) ^ 2 := by - field_simp; ring - rw [heq] - apply (le_div_iff₀ (sq_pos_of_pos hA)).mpr - have hh := mul_le_mul_of_nonneg_left hAsq hpq.le - nlinarith [ht.2] - -theorem binomial_tilt_normalizer (g h : ℕ) {p : ℝ} - (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hhg : h ≤ g) (hS : 0 < g + h) : - let t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) - ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ - Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by - dsimp only - set t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) with htdef - have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS - have hgr : (h : ℝ) ≤ g := by exact_mod_cast hhg - have hd : (0 : ℝ) ≤ (g : ℝ) - h := sub_nonneg.mpr hgr - have ht0 : 0 ≤ t := div_nonneg hd (by positivity) - have ht1 : t ≤ 1 / 4 := by - apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr - nlinarith [show (0 : ℝ) ≤ h by positivity] - have htlt : 0 < 1 - t := by linarith - have hp0 : 0 < p := by linarith [hp.1] - have hA : 0 < 1 - p + p * (1 - t) := by positivity [sub_pos.mpr hp.2] - have hB : 0 < 1 - p + p / (1 - t) := by positivity [sub_pos.mpr hp.2] - have hlogA : Real.log (1 - p + p * (1 - t)) ≤ -p * t := by - have := Real.log_le_sub_one_of_pos hA - nlinarith only [this] - have hlogB : Real.log (1 - p + p / (1 - t)) ≤ p * t / (1 - t) := by - have := Real.log_le_sub_one_of_pos hB - have heq : 1 - p + p / (1 - t) - 1 = p * t / (1 - t) := by field_simp; ring - rwa [heq] at this - have hlog : Real.log ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ - -(p * ((g : ℝ) - h) * t) + 2 * p * h * t ^ 2 := by - rw [Real.log_mul (pow_pos hA _).ne' (pow_pos hB _).ne', Real.log_pow, Real.log_pow] - have hb : (h : ℝ) * (p * t / (1 - t)) ≤ (h : ℝ) * (p * t + 2 * p * t ^ 2) := by - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply (div_le_iff₀ htlt).mpr - have hh := mul_nonneg (mul_nonneg hp0.le (sq_nonneg t)) (show 0 ≤ 1 - 2 * t by linarith) - nlinarith only [hh] - have ha := mul_le_mul_of_nonneg_left hlogA (show (0 : ℝ) ≤ g by positivity) - have hb' := mul_le_mul_of_nonneg_left hlogB (show (0 : ℝ) ≤ h by positivity) - linarith - have hht : 4 * (h : ℝ) * t ≤ (g : ℝ) - h := by - rw [htdef, ← mul_div_assoc] - apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr - have hm := mul_nonneg (show (0 : ℝ) ≤ g by positivity) hd - nlinarith only [hm] - have hhalf : -(p * ((g : ℝ) - h) * t) + 2 * p * h * t ^ 2 ≤ - -(p * ((g : ℝ) - h) * t) / 2 := by - have hm := mul_le_mul_of_nonneg_right hht (mul_nonneg hp0.le ht0) - nlinarith only [hm] - have hlast : -(p * ((g : ℝ) - h) * t) / 2 ≤ - -((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h)) := by - rw [htdef] - apply (div_le_div_iff₀ (by norm_num : (0 : ℝ) < 2) (by positivity)).mpr - field_simp - have hm := mul_nonneg (show 0 ≤ 2 * p - 1 by linarith [hp.1]) (sq_nonneg ((g : ℝ) - h)) - nlinarith only [hm] - have hexp := Real.exp_le_exp.mpr (hlog.trans (hhalf.trans hlast)) - rwa [Real.exp_log (mul_pos (pow_pos hA _) (pow_pos hB _))] at hexp - - -/-- The Gaussian cross-overlap estimate used by the conditional rank-kernel -square-sum argument. The constant is absolute, also as p tends to one. -/ -theorem binomial_gaussian_overlap (g h : ℕ) {p : ℝ} - (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hhg : h ≤ g) (hS : 0 < g + h) : - (∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k) ≤ - Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * - Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by - let t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) - have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS - have hgr : (h : ℝ) ≤ g := by exact_mod_cast hhg - have ht0 : 0 ≤ t := div_nonneg (sub_nonneg.mpr hgr) (by positivity) - have ht1 : t ≤ 1 / 4 := by - apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr - nlinarith [show (0 : ℝ) ≤ h by positivity] - have htlt : 0 < 1 - t := by linarith - have hp0 : 0 < p := by linarith [hp.1] - have hp' : p ∈ Set.Ioo (0 : ℝ) 1 := ⟨hp0, hp.2⟩ - have hA : 0 < 1 - p + p * (1 - t) := by positivity [sub_pos.mpr hp.2] - have hB : 0 < 1 - p + p / (1 - t) := by positivity [sub_pos.mpr hp.2] - have hv := binomial_tilt_variance hp' ⟨ht0, ht1⟩ - have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) - have hx : 0 < (p * (1 - t) / (1 - p + p * (1 - t))) * - (1 - p * (1 - t) / (1 - p + p * (1 - t))) := lt_of_lt_of_le (by positivity) hv - have hb : biasedBinomialBound g (p * (1 - t) / (1 - p + p * (1 - t))) ≤ - Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) := by - apply Real.sqrt_le_sqrt - have hg : (0 : ℝ) < (g : ℝ) + 1 := by positivity - apply (div_le_div_iff₀ (by nlinarith only [mul_pos hg hx]) (by nlinarith only [mul_pos hg hpq])).mpr - have hm := mul_le_mul_of_nonneg_left hv hg.le - nlinarith only [hm] - have hn := binomial_tilt_normalizer g h hp hhg hS - change ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ _ at hn - have he := binomial_overlap_tilt_bound g h hp' htlt - apply he.trans - have hbound := mul_le_mul hn hb (Real.sqrt_nonneg _) (Real.exp_nonneg _) - simpa only [mul_comm] using hbound - - -theorem sqrt_times_gaussian_le {x : ℝ} (hx : 0 ≤ x) : - Real.sqrt (x + 1) * Real.exp (-x / 96) ≤ 16 := by - have he : Real.exp (-x / 96) ^ 2 = 1 / Real.exp (x / 48) := by - rw [pow_two, ← Real.exp_add] - rw [show -x / 96 + -x / 96 = -(x / 48) by ring, Real.exp_neg, one_div] - have hs : (Real.sqrt (x + 1) * Real.exp (-x / 96)) ^ 2 ≤ 256 := by - rw [mul_pow, Real.sq_sqrt (by linarith), he, mul_one_div] - apply (div_le_iff₀ (Real.exp_pos _)).mpr - have hh := Real.add_one_le_exp (x / 48) - nlinarith only [hh, hx] - nlinarith only [hs] - -theorem sqrt_recip_product_le {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (hab : a ≤ 2 * b) : - Real.sqrt (1 / a) * Real.sqrt (1 / b) ≤ 2 / a := by - rw [← Real.sqrt_mul (by positivity), Real.sqrt_le_iff] - refine ⟨by positivity, ?_⟩ - rw [div_pow] - apply (le_div_iff₀ (sq_pos_of_pos ha)).mpr - field_simp - nlinarith - -theorem binomialMass_le_bound (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - binomialMass n p k ≤ biasedBinomialBound n p := by - have h := biasedSeries_coeff_bound n hp (k : ℤ) - rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ ⟨hp.1.le, hp.2.le⟩)] at h - exact h - -/-- A uniform product-supremum estimate, including very unequal trial -counts. This justifies eliminating a largest gap in the rank kernel. -/ -theorem binomial_product_sup (g h k : ℕ) {p : ℝ} - (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) : - binomialMass g p k * binomialMass h p k ≤ - 32 / (((g : ℝ) + 1) * p * (1 - p)) := by - have hp0 : 0 < p := by linarith [hp.1] - have hp' : p ∈ Set.Ioo (0 : ℝ) 1 := ⟨hp0, hp.2⟩ - have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) - have hpq1 : p * (1 - p) ≤ 1 := by nlinarith only [sq_nonneg (p - 1 / 2)] - have hden : 0 < ((g : ℝ) + 1) * p * (1 - p) := by nlinarith only [mul_pos (show (0 : ℝ) < (g : ℝ) + 1 by positivity) hpq] - by_cases hnear : g ≤ 2 * h - · have hdenh : 0 < ((h : ℝ) + 1) * p * (1 - p) := by nlinarith only [mul_pos (show (0 : ℝ) < (h : ℝ) + 1 by positivity) hpq] - have hgh : ((g : ℝ) + 1) * p * (1 - p) ≤ 2 * (((h : ℝ) + 1) * p * (1 - p)) := by - have hcast : (g : ℝ) ≤ 2 * h := by exact_mod_cast hnear - have hm := mul_le_mul_of_nonneg_right (show (g : ℝ) + 1 ≤ 2 * ((h : ℝ) + 1) by linarith) hpq.le - nlinarith only [hm] - calc - _ ≤ biasedBinomialBound g p * biasedBinomialBound h p := - mul_le_mul (binomialMass_le_bound g k hp') (binomialMass_le_bound h k hp') - (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) (Real.sqrt_nonneg _) - _ ≤ 2 / (((g : ℝ) + 1) * p * (1 - p)) := sqrt_recip_product_le hden hdenh hgh - _ ≤ _ := div_le_div_of_nonneg_right (by norm_num) hden.le - · by_cases hk : k ≤ h - · have hhg : h ≤ g := by omega - have hS : 0 < g + h := by omega - have hsum : binomialMass g p k * binomialMass h p k ≤ - ∑ j ∈ Finset.range (h + 1), binomialMass g p j * binomialMass h p j := by - exact Finset.single_le_sum (s := Finset.range (h + 1)) (a := k) (fun j _ => mul_nonneg - (binomialMass_nonneg g j ⟨hp0.le, hp.2.le⟩) - (binomialMass_nonneg h j ⟨hp0.le, hp.2.le⟩)) (Finset.mem_range.mpr (by omega)) - have hgauss := binomial_gaussian_overlap g h hp hhg hS - have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS - have hfar : 2 * (h : ℝ) < g := by exact_mod_cast (show 2 * h < g by omega) - have hexp : Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) ≤ Real.exp (-(g : ℝ) / 96) := by - apply Real.exp_le_exp.mpr - apply (div_le_div_iff₀ (by positivity : (0 : ℝ) < 16 * ((g : ℝ) + h)) (by norm_num : (0 : ℝ) < 96)).mpr - have hn := mul_nonneg (show 0 ≤ (g : ℝ) - 2 * h by linarith) (show 0 ≤ 5 * (g : ℝ) - 3 * h by linarith) - nlinarith only [hn, sq_nonneg (h : ℝ)] - have hcoeff : Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) ≤ - (2 / (((g : ℝ) + 1) * p * (1 - p))) * Real.sqrt ((g : ℝ) + 1) := by - rw [Real.sqrt_le_iff] - refine ⟨by positivity, ?_⟩ - rw [mul_pow, Real.sq_sqrt (by positivity), div_pow] - have hgpos : (0 : ℝ) < (g : ℝ) + 1 := by positivity - have hqpos : 0 < 1 - p := sub_pos.mpr hp.2 - field_simp - have hm := mul_le_mul_of_nonneg_left hpq1 (show (0 : ℝ) ≤ (g : ℝ) + 1 by positivity) - nlinarith only [hm, hpq1] - calc - _ ≤ Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * - Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := hsum.trans hgauss - _ ≤ ((2 / (((g : ℝ) + 1) * p * (1 - p))) * Real.sqrt ((g : ℝ) + 1)) * - Real.exp (-(g : ℝ) / 96) := mul_le_mul hcoeff hexp (Real.exp_nonneg _) (by positivity) - _ ≤ (2 / (((g : ℝ) + 1) * p * (1 - p))) * 16 := by - rw [mul_assoc] - exact mul_le_mul_of_nonneg_left (sqrt_times_gaussian_le (by positivity)) (by positivity) - _ = _ := by ring - · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : h < k)] - positivity - -end TraceReconstruction - -namespace TraceReconstruction - -/-- Exact moment generating function, including both endpoint channels. -/ -theorem binomialMass_mgf (n : ℕ) (p t : ℝ) : - (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (t * k)) = - (1 - p + p * Real.exp t) ^ n := by - rw [add_comm (1 - p), add_pow] - apply Finset.sum_congr rfl - intro k _ - rw [show t * (k : ℝ) = (k : ℝ) * t by ring, Real.exp_nat_mul, mul_pow] - unfold binomialMass - ring - -theorem binomialMass_mgf_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) (t : ℝ) : - (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (t * k)) ≤ - Real.exp ((n : ℝ) * p * (Real.exp t - 1)) := by - rw [binomialMass_mgf] - have hn : 0 ≤ 1 - p + p * Real.exp t := by positivity [sub_nonneg.mpr hp.2, hp.1] - have he : 1 - p + p * Real.exp t ≤ Real.exp (p * (Real.exp t - 1)) := by - nlinarith only [Real.add_one_le_exp (p * (Real.exp t - 1))] - calc - _ ≤ Real.exp (p * (Real.exp t - 1)) ^ n := pow_le_pow_left₀ hn he n - _ = _ := by rw [← Real.exp_nat_mul]; congr 1; ring - -/-- Exponential Markov bound for a finite nonnegative measure. -/ -theorem finite_exp_markov {α : Type*} (S : Finset α) (w X : α → ℝ) - (hw : ∀ a ∈ S, 0 ≤ w a) (a t : ℝ) (ht : 0 ≤ t) : - (∑ z ∈ S with a ≤ X z, w z) ≤ - Real.exp (-t * a) * ∑ z ∈ S, w z * Real.exp (t * X z) := by - classical - calc - _ = ∑ z ∈ S with a ≤ X z, Real.exp (-t * a) * (w z * Real.exp (t * a)) := by - apply Finset.sum_congr rfl - intro z _ - rw [mul_left_comm, ← Real.exp_add] - simp - _ ≤ ∑ z ∈ S with a ≤ X z, Real.exp (-t * a) * (w z * Real.exp (t * X z)) := by - apply Finset.sum_le_sum - intro z hz - have h := Finset.mem_filter.mp hz - exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left - (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left h.2 ht)) (hw z h.1)) - (Real.exp_nonneg _) - _ ≤ ∑ z ∈ S, Real.exp (-t * a) * (w z * Real.exp (t * X z)) := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) - intro z hz _ - positivity [hw z hz] - _ = _ := by rw [Finset.mul_sum] - -/-- A uniform multiplicative lower tail, sufficient for hidden-flag counts. -/ -theorem binomialMass_lower_half (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : - (∑ k ∈ (Finset.range (n + 1)).filter (fun k : ℕ => (k : ℝ) ≤ n * p / 2), - binomialMass n p k) ≤ Real.exp (-(n : ℝ) * p / 12) := by - have he : Real.exp (-(1 / 2 : ℝ)) ≤ 2 / 3 := by - rw [Real.exp_neg] - apply (inv_le_iff_one_le_mul₀ (Real.exp_pos _)).mpr - nlinarith only [Real.add_one_le_exp (1 / 2 : ℝ)] - have hmark := finite_exp_markov (Finset.range (n + 1)) (binomialMass n p) - (fun k => -(k : ℝ)) (fun k _ => binomialMass_nonneg n k hp) - (-(n : ℝ) * p / 2) (1 / 2) (by norm_num) - have hf : (Finset.range (n + 1)).filter (fun k : ℕ => -(n : ℝ) * p / 2 ≤ -(k : ℝ)) = - (Finset.range (n + 1)).filter (fun k : ℕ => (k : ℝ) ≤ n * p / 2) := by - ext k - simp only [Finset.mem_filter] - constructor <;> rintro ⟨h, h'⟩ <;> exact ⟨h, by linarith⟩ - rw [hf] at hmark - calc - _ ≤ Real.exp (-(1 / 2 : ℝ) * (-(n : ℝ) * p / 2)) * - (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (-(1 / 2 : ℝ) * k)) := by - convert hmark using 1 - congr 2 - funext k - congr 2 - ring - _ ≤ Real.exp (-(1 / 2 : ℝ) * (-(n : ℝ) * p / 2)) * - Real.exp ((n : ℝ) * p * (Real.exp (-(1 / 2 : ℝ)) - 1)) := by - gcongr - exact binomialMass_mgf_le n hp _ - _ = Real.exp ((n : ℝ) * p * (Real.exp (-(1 / 2 : ℝ)) - 3 / 4)) := by - rw [← Real.exp_add] - congr 1 - ring - _ ≤ _ := by - apply Real.exp_le_exp.mpr - nlinarith [mul_le_mul_of_nonneg_left he (mul_nonneg (Nat.cast_nonneg n) hp.1)] - -end TraceReconstruction - -namespace TraceReconstruction -theorem fairBinomial_centered_mgf (n : ℕ) (t : ℝ) : - (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * - Real.exp (t * ((k : ℝ) - n / 2))) ≤ Real.exp ((n : ℝ) * t ^ 2 / 8) := by - have he : (1 / 2 : ℝ) + Real.exp t / 2 = Real.exp (t / 2) * Real.cosh (t / 2) := by - rw [Real.cosh_eq, ← mul_div_assoc, mul_add, ← Real.exp_add, ← Real.exp_add] - rw [show t / 2 + t / 2 = t by ring, show t / 2 + -(t / 2) = 0 by ring, Real.exp_zero] - ring - have hm : (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * - Real.exp (t * ((k : ℝ) - n / 2))) = - Real.exp (-t * n / 2) * (1 - 1 / 2 + (1 / 2) * Real.exp t) ^ n := by - rw [← binomialMass_mgf, Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _ - rw [mul_left_comm, ← Real.exp_add] - congr 2 - ring - rw [hm, show (1 - 1 / 2 + (1 / 2) * Real.exp t : ℝ) = 1 / 2 + Real.exp t / 2 by ring, he, mul_pow] - have hb : Real.cosh (t / 2) ^ n ≤ Real.exp (t ^ 2 / 8) ^ n := by - apply pow_le_pow_left₀ (le_of_lt (Real.cosh_pos _)) - convert Real.cosh_le_exp_half_sq (t / 2) using 1; congr 1; ring - calc - _ ≤ Real.exp (-t * n / 2) * (Real.exp (t / 2) ^ n * Real.exp (t ^ 2 / 8) ^ n) := by gcongr - _ = _ := by - simp only [← Real.exp_nat_mul, ← Real.exp_add] - congr 1 - ring - -theorem fairBinomial_upper_tail (n : ℕ) (hn : 0 < n) (a : ℝ) (ha : 0 ≤ a) : - (∑ k ∈ (Finset.range (n + 1)).filter (fun k : ℕ => a ≤ (k : ℝ) - n / 2), - binomialMass n (1 / 2) k) ≤ Real.exp (-2 * a ^ 2 / n) := by - have hnR : (0 : ℝ) < n := by exact_mod_cast hn - have h := finite_exp_markov (Finset.range (n + 1)) (binomialMass n (1 / 2)) - (fun k => (k : ℝ) - n / 2) (fun k _ => binomialMass_nonneg n k (by norm_num)) - a (4 * a / n) (by positivity) - calc - _ ≤ Real.exp (-(4 * a / n) * a) * - (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * - Real.exp ((4 * a / n) * ((k : ℝ) - n / 2))) := h - _ ≤ Real.exp (-(4 * a / n) * a) * Real.exp ((n : ℝ) * (4 * a / n) ^ 2 / 8) := by - gcongr - exact fairBinomial_centered_mgf n _ - _ = _ := by - rw [← Real.exp_add] - congr 1 - field_simp [ne_of_gt hnR] - ring -end TraceReconstruction - -namespace TraceReconstruction -def hypergeomMass (V M m v : ℕ) : ℝ := - if v ≤ m then (V.choose v : ℝ) * (M.choose (m-v) : ℝ) / ((V+M).choose m : ℝ) else 0 - -theorem hypergeomMass_nonneg (V M m v : ℕ) : 0 ≤ hypergeomMass V M m v := by - unfold hypergeomMass - split <;> positivity - -theorem hypergeomMass_eq_binomial (V M m v : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioo 0 1) (hm : m ≤ V+M) (hv : v ≤ m) : - hypergeomMass V M m v = binomialMass V p v * binomialMass M p (m-v) / - binomialMass (V+M) p m := by - unfold hypergeomMass - rw [ite_eq_left hv] - by_cases hvV : v ≤ V - · by_cases hkM : m-v ≤ M - · unfold binomialMass - have hc : (0 : ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hm - have hp1 := hp.1 - have hq1 := sub_pos.mpr hp.2 - have he : V-v+(M-(m-v)) = V+M-m := by omega - have he' : v+(m-v) = m := by omega - apply (div_eq_div_iff (ne_of_gt hc) (by positivity)).mpr - calc - _ = ((V.choose v : ℝ) * (M.choose (m-v) : ℝ) * ((V+M).choose m : ℝ)) * - (p^m * (1-p)^(V+M-m)) := by ring - _ = _ := by - rw [show p^m = p^v * p^(m-v) by rw [← pow_add, he'], - show (1-p)^(V+M-m) = (1-p)^(V-v)*(1-p)^(M-(m-v)) by rw [← pow_add, he]] - ring - · rw [Nat.choose_eq_zero_of_lt (by omega : M < m-v)] - simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : M < m-v)] - · rw [Nat.choose_eq_zero_of_lt (by omega : V < v)] - simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : V < v)] - -theorem binomialMass_sq_upper (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - binomialMass n p k ^ 2 ≤ 1 / (((n : ℝ)+1)*p*(1-p)) := by - have hp1 := hp.1 - have hq1 := sub_pos.mpr hp.2 - have h := biasedSeries_coeff_bound n hp (k : ℤ) - rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg n k ⟨hp.1.le,hp.2.le⟩)] at h - have hs := sq_le_sq₀ (binomialMass_nonneg n k ⟨hp.1.le,hp.2.le⟩) - (Real.sqrt_nonneg _) |>.mpr h - rwa [Real.sq_sqrt (by positivity)] at hs - -theorem hypergeomMass_sq_upper (V M m v : ℕ) {p : ℝ} - (hp : p ∈ Set.Ioo 0 1) (hm : m ≤ V+M) (hmean : (m : ℝ) = (V+M : ℕ)*p) - (hvar : 1 ≤ (V+M : ℕ)*p*(1-p)) : - hypergeomMass V M m v ^ 2 ≤ - 144 * (V+M : ℕ) / (((V : ℝ)+1)*((M : ℝ)+1)*p*(1-p)) := by - have hp1 := hp.1 - have hq1 := sub_pos.mpr hp.2 - by_cases hv : v ≤ m - · rw [hypergeomMass_eq_binomial V M m v hp hm hv, div_eq_mul_inv, mul_pow, mul_pow] - have hV := binomialMass_sq_upper V v hp - have hM := binomialMass_sq_upper M (m-v) hp - have hN := binomialMass_mean_inverse_sq (V+M) m hp hm hmean.symm hvar - have hvm := mul_le_mul hV hM (sq_nonneg _) (by positivity) - have h := mul_le_mul hvm hN (sq_nonneg _) (by positivity) - apply h.trans - have hp0 : p ≠ 0 := ne_of_gt hp.1 - have hq0 : 1-p ≠ 0 := ne_of_gt (sub_pos.mpr hp.2) - have hV0 : (V : ℝ)+1 ≠ 0 := by positivity - have hM0 : (M : ℝ)+1 ≠ 0 := by positivity - apply le_of_eq - field_simp - · simp only [hypergeomMass, ite_eq_right hv, zero_pow (by decide : 2 ≠ 0)] - positivity - -theorem sum_hypergeomMass (V M m : ℕ) (hm : m ≤ V+M) : - ∑ v ∈ Finset.range (m+1), hypergeomMass V M m v = 1 := by - have hc : (0 : ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hm - have hv := Nat.add_choose_eq V M m - rw [Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk] at hv - simp only [hypergeomMass] - have he : (∑ v ∈ Finset.range (m+1), - if v ≤ m then (V.choose v : ℝ)*(M.choose (m-v) : ℝ)/((V+M).choose m : ℝ) else 0) = - (∑ v ∈ Finset.range (m+1), (V.choose v : ℝ)*(M.choose (m-v) : ℝ))/((V+M).choose m : ℝ) := by - rw [Finset.sum_div] - apply Finset.sum_congr rfl - intro v hv' - rw [ite_eq_left (by simp only [Finset.mem_range] at hv'; omega)] - rw [he] - have he' : (∑ v ∈ Finset.range (m+1), (V.choose v : ℝ)*(M.choose (m-v) : ℝ)) = - ((V+M).choose m : ℝ) := by exact_mod_cast hv.symm - rw [he', div_self (ne_of_gt hc)] - -theorem hypergeomMass_high (V M m v : ℕ) (hv : V < v) : hypergeomMass V M m v = 0 := by - unfold hypergeomMass - rw [Nat.choose_eq_zero_of_lt hv] - simp - -/-- Adjacent-mass identity for the hidden count. The central regime has full support -on 0,...,M; this is exactly the regime used in adjacent-power lifting. -/ -theorem hypergeom_hidden_adjacent (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) (hk : k < M) : - (((k:ℝ)+1)*((V:ℝ)-m+k+1)) * hypergeomMass M V m (k+1) = - (((M:ℝ)-k)*((m:ℝ)-k)) * hypergeomMass M V m k := by - have hkM : k ≤ M := by omega - have hkm : k ≤ m := by omega - have hkm' : k+1 ≤ m := by omega - have hv : m-(k+1) ≤ V := by omega - have h1 := Nat.choose_succ_right_eq M k - have h2 := Nat.choose_succ_right_eq V (m-(k+1)) - rw [show m-(k+1)+1=m-k by omega] at h2 - have h1' : (M.choose (k+1):ℝ)*((k:ℝ)+1) = (M.choose k:ℝ)*((M:ℝ)-k) := by - exact_mod_cast h1 - have h2' : (V.choose (m-k):ℝ)*((m:ℝ)-k) = - (V.choose (m-(k+1)):ℝ)*((V:ℝ)-m+k+1) := by - have hvsub : V-(m-(k+1)) = V-m+k+1 := by omega - rw [hvsub] at h2 - exact_mod_cast h2 - unfold hypergeomMass - rw [ite_eq_left hkm', ite_eq_left hkm] - have hmul := congrArg (fun z : ℝ => z*(V.choose (m-(k+1)) : ℝ)*((V:ℝ)-m+k+1)) h1' - have hmul' := congrArg (fun z : ℝ => z*(M.choose k : ℝ)*((M:ℝ)-k)) h2' - have he : (((k:ℝ)+1)*((V:ℝ)-m+k+1)) * - ((M.choose (k+1):ℝ)*(V.choose (m-(k+1)):ℝ)) = - (((M:ℝ)-k)*((m:ℝ)-k))*((M.choose k:ℝ)*(V.choose (m-k):ℝ)) := by - nlinarith only [hmul, hmul'] - simpa only [mul_div_assoc] using congrArg (fun z : ℝ => z/((M+V).choose m:ℝ)) he - -def hypergeomHiddenMode (V M m : ℕ) : ℕ := (M+1)*(m+1)/(V+M+2) - -theorem hypergeomHiddenMode_le (V M m : ℕ) (hV : m ≤ V) : - hypergeomHiddenMode V M m ≤ M := by - unfold hypergeomHiddenMode - have h1 : (M+1)*(m+1) < (M+1)*(V+M+2) := Nat.mul_lt_mul_of_pos_left (by omega) (by omega) - have hh : (M+1)*(m+1)/(V+M+2) < M+1 := by - apply (Nat.div_lt_iff_lt_mul (by omega)).mpr - exact h1 - omega - -theorem hypergeom_hidden_unimodal_left (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) - (hk : k < hypergeomHiddenMode V M m) : - hypergeomMass M V m k ≤ hypergeomMass M V m (k+1) := by - have hl := hypergeomHiddenMode_le V M m hV - have hkM : k < M := by omega - have hrec := hypergeom_hidden_adjacent V M m k hM hV hkM - have hc : (k+1)*(V+M+2) ≤ (M+1)*(m+1) := by - have hh : k+1 ≤ (M+1)*(m+1)/(V+M+2) := hk - exact (Nat.le_div_iff_mul_le (by omega)).mp hh - have hc' : ((k:ℝ)+1)*((V:ℝ)+M+2) ≤ ((M:ℝ)+1)*((m:ℝ)+1) := by exact_mod_cast hc - have hh : ((k:ℝ)+1)*((V:ℝ)-m+k+1) ≤ ((M:ℝ)-k)*((m:ℝ)-k) := by nlinarith - have hm := mul_le_mul_of_nonneg_right hh (hypergeomMass_nonneg M V m k) - have hV' : (m:ℝ) ≤ V := by exact_mod_cast hV - have ha : 0 < ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by positivity - exact (mul_le_mul_iff_right₀ ha).mp (by nlinarith only [hm, hrec]) - -theorem hypergeom_hidden_unimodal_right (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) - (hk : hypergeomHiddenMode V M m ≤ k) : - hypergeomMass M V m (k+1) ≤ hypergeomMass M V m k := by - by_cases hkM : k < M - · have hrec := hypergeom_hidden_adjacent V M m k hM hV hkM - have hc : (M+1)*(m+1) < (k+1)*(V+M+2) := by - apply (Nat.div_lt_iff_lt_mul (by omega)).mp - exact Nat.lt_succ_of_le hk - have hc' : ((M:ℝ)+1)*((m:ℝ)+1) < ((k:ℝ)+1)*((V:ℝ)+M+2) := by exact_mod_cast hc - have hh : ((M:ℝ)-k)*((m:ℝ)-k) ≤ ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by nlinarith - have hm := mul_le_mul_of_nonneg_right hh (hypergeomMass_nonneg M V m k) - have hV' : (m:ℝ) ≤ V := by exact_mod_cast hV - have ha : 0 < ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by positivity - exact (mul_le_mul_iff_right₀ ha).mp (by nlinarith only [hm, hrec]) - · rw [hypergeomMass_high M V m (k+1) (by omega)] - exact hypergeomMass_nonneg M V m k - -/-- Exact total variation of a zero-extended unimodal sequence. -/ -theorem unimodal_variation (f : ℕ → ℝ) (n l : ℕ) (hl : l ≤ n+1) - (hleft : ∀ k < l, f k ≤ f (k+1)) - (hright : ∀ k, l ≤ k → f (k+1) ≤ f k) (hz : f (n+1)=0) : - f 0 + ∑ k ∈ Finset.range (n+1), |f (k+1)-f k| = 2*f l := by - rw [← Finset.sum_range_add_sum_Ico _ hl] - have h1 : (∑ k ∈ Finset.range l, |f (k+1)-f k|) = f l-f 0 := by - rw [← Finset.sum_range_sub f l] - apply Finset.sum_congr rfl - intro k hk - exact abs_of_nonneg (sub_nonneg.mpr (hleft k (Finset.mem_range.mp hk))) - have h2 : (∑ k ∈ Finset.Ico l (n+1), |f (k+1)-f k|) = f l-f (n+1) := by - calc - _ = ∑ k ∈ Finset.Ico l (n+1), -(f (k+1)-f k) := by - apply Finset.sum_congr rfl - intro k hk - exact abs_of_nonpos (sub_nonpos.mpr (hright k (Finset.mem_Ico.mp hk).1)) - _ = _ := by rw [Finset.sum_neg_distrib, Finset.sum_Ico_sub _ hl]; ring - rw [h1,h2,hz] - ring - -theorem hypergeom_hidden_variation (V M m : ℕ) (hM : M ≤ m) (hV : m ≤ V) : - hypergeomMass M V m 0 + - ∑ k ∈ Finset.range (M+1), |hypergeomMass M V m (k+1)-hypergeomMass M V m k| = - 2*hypergeomMass M V m (hypergeomHiddenMode V M m) := by - apply unimodal_variation _ M (hypergeomHiddenMode V M m) - ((hypergeomHiddenMode_le V M m hV).trans (by omega)) - (fun k hk => hypergeom_hidden_unimodal_left V M m k hM hV hk) - (fun k hk => hypergeom_hidden_unimodal_right V M m k hM hV hk) - exact hypergeomMass_high M V m (M+1) (by omega) -theorem choose_pred_weight (n r : ℕ) (hn : 0 < n) (hr : r ≤ n) : - (n:ℝ)*((n-1).choose r : ℝ) = ((n:ℝ)-r)*(n.choose r : ℝ) := by - have h := Nat.choose_mul_succ_eq (n-1) r - rw [Nat.sub_add_cancel hn] at h - have h' : ((n-1).choose r : ℝ)*(n:ℝ) = (n.choose r : ℝ)*((n:ℝ)-r) := by - exact_mod_cast h - nlinarith only [h'] - -theorem choose_pred_weight_succ (n r : ℕ) (hn : 0 < n) : - (n:ℝ)*((n-1).choose r : ℝ) = ((r:ℝ)+1)*(n.choose (r+1) : ℝ) := by - have h := Nat.add_one_mul_choose_eq (n-1) r - rw [Nat.sub_add_cancel hn] at h - exact_mod_cast h.trans (Nat.mul_comm _ _) - -def hypergeomHiddenFlux (V M m k : ℕ) : ℝ := - (V:ℝ)/(V+M)*hypergeomMass M (V-1) m k - -theorem hypergeomHiddenFlux_formula (V M m k : ℕ) (hM : M ≤ m) (hV : m < V) (hk : k ≤ M) : - hypergeomHiddenFlux V M m k = - ((V:ℝ)-m+k)/((V:ℝ)+M-m)*hypergeomMass M V m k := by - have hN : 0 < V+M := by omega - have hk' : k ≤ m := by omega - have hr : m-k ≤ V := by omega - have hmN : m ≤ V+M := by omega - have hpred : m ≤ V+M-1 := by omega - have hVN : (0:ℝ) < V+M := by exact_mod_cast hN - have hd : (0:ℝ) < (V:ℝ)+M-m := by - have hr : (m:ℝ) < (V:ℝ)+M := by exact_mod_cast (show m < V+M by omega) - linarith - have hCN : (0:ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hmN - have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos hpred - have hcw := choose_pred_weight (V+M) m hN hmN - have hcv := choose_pred_weight V (m-k) (by omega) hr - push_cast [Nat.cast_sub hk'] at hcv - push_cast at hcw - unfold hypergeomHiddenFlux hypergeomMass - rw [ite_eq_left hk', ite_eq_left hk', show M+(V-1)=V+M-1 by omega] - have hden : ((V:ℝ)+M)*((V+M-1).choose m:ℝ) = - ((V:ℝ)+M-m)*((V+M).choose m:ℝ) := hcw - rw [show M+V=V+M by omega] - calc - _ = (M.choose k:ℝ)*((V:ℝ)*((V-1).choose (m-k):ℝ)) / - (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by field_simp - _ = _ := by rw [hden, hcv]; field_simp; ring - -theorem hypergeomHiddenFlux_high (V M m k : ℕ) (hk : M < k) : - hypergeomHiddenFlux V M m k = 0 := by - simp only [hypergeomHiddenFlux, hypergeomMass_high M (V-1) m k hk, mul_zero] - -theorem hypergeomHiddenFlux_boundary (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : - hypergeomHiddenFlux V M m M = hypergeomMass M V m M := by - rw [hypergeomHiddenFlux_formula V M m M hM hV le_rfl] - have hd : (0:ℝ) < (V:ℝ)+M-m := by - have hr : (m:ℝ) < (V:ℝ)+M := by exact_mod_cast (show m < V+M by omega) - linarith - have he : (V:ℝ)-m+M = (V:ℝ)+M-m := by ring - rw [he, div_self hd.ne', one_mul] - -theorem hypergeom_adjacent_hidden_difference (V M m k : ℕ) - (hM : M ≤ m) (hV : m < V) (hk : k ≤ M) : - hypergeomMass M V (m+1) (k+1) - hypergeomMass M V m k = - hypergeomHiddenFlux V M m (k+1) - hypergeomHiddenFlux V M m k := by - by_cases hkM : k = M - · subst k - rw [hypergeomMass_high M V (m+1) (M+1) (by omega), - hypergeomHiddenFlux_high V M m (M+1) (by omega), hypergeomHiddenFlux_boundary V M m hM hV] - have hklt : k < M := by omega - have hkm : k+1 ≤ m := by omega - have hkm' : k ≤ m := by omega - have hN : 0 < V+M := by omega - have hmN : m ≤ V+M := by omega - have hmN' : m+1 ≤ V+M := by omega - have hpred : m ≤ V+M-1 := by omega - have hN0 : (0:ℝ) < (V:ℝ)+M := by exact_mod_cast hN - have hCN : (0:ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hmN - have hCN' : (0:ℝ) < (V+M).choose (m+1) := by exact_mod_cast Nat.choose_pos hmN' - have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos hpred - have hcw := choose_pred_weight (V+M) m hN hmN - have hcws := choose_pred_weight_succ (V+M) m hN - have hcv := choose_pred_weight V (m-k) (by omega) (by omega) - have hcvs := choose_pred_weight_succ V (m-(k+1)) (by omega) - rw [show m-(k+1)+1=m-k by omega] at hcvs - have hMrec := Nat.choose_succ_right_eq M k - have hMrec' : (M.choose (k+1):ℝ)*((k:ℝ)+1) = (M.choose k:ℝ)*((M:ℝ)-k) := by - exact_mod_cast hMrec - push_cast at hcw hcws - push_cast [Nat.cast_sub hkm'] at hcv - push_cast [Nat.cast_sub hkm] at hcvs - unfold hypergeomHiddenFlux hypergeomMass - rw [ite_eq_left (by omega : k+1 ≤ m+1), ite_eq_left hkm', ite_eq_left hkm, ite_eq_left hkm', - show m+1-(k+1)=m-k by omega, show M+V=V+M by omega, - show M+(V-1)=V+M-1 by omega] - have hpold : (M.choose k:ℝ)*(V.choose (m-k):ℝ)/( (V+M).choose m:ℝ) = - ((V:ℝ)+M-m)*(M.choose k:ℝ)*(V.choose (m-k):ℝ) / - (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by - apply (div_eq_div_iff hCN.ne' (mul_pos hN0 hCP).ne').mpr - rw [hcw]; ring - have hpnew : (M.choose (k+1):ℝ)*(V.choose (m-k):ℝ)/( (V+M).choose (m+1):ℝ) = - ((m:ℝ)+1)*(M.choose (k+1):ℝ)*(V.choose (m-k):ℝ) / - (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by - apply (div_eq_div_iff hCN'.ne' (mul_pos hN0 hCP).ne').mpr - rw [hcws]; ring - rw [hpold,hpnew] - have hF (j : ℕ) : (V:ℝ)/((V:ℝ)+M)*((M.choose j:ℝ)*((V-1).choose (m-j):ℝ)/ - ((V+M-1).choose m:ℝ)) = (M.choose j:ℝ)*((V:ℝ)*((V-1).choose (m-j):ℝ)) / - (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by field_simp - rw [hF, hF, hcv, hcvs] - rw [← sub_div, ← sub_div] - congr 1 - have hh := congrArg (fun z : ℝ => z*(V.choose (m-k):ℝ)) hMrec' - nlinarith only [hh] - - -theorem hypergeom_next_zero (V M m : ℕ) (hV : m < V) : - hypergeomMass M V (m+1) 0 = hypergeomHiddenFlux V M m 0 := by - have hN : 0 < V+M := by omega - have hN0 : (0:ℝ) < (V:ℝ)+M := by exact_mod_cast hN - have hCN : (0:ℝ) < (V+M).choose (m+1) := by exact_mod_cast Nat.choose_pos (show m+1 ≤ V+M by omega) - have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos (show m ≤ V+M-1 by omega) - have hcw := choose_pred_weight_succ (V+M) m hN - have hcv := choose_pred_weight_succ V m (by omega) - push_cast at hcw hcv - unfold hypergeomHiddenFlux hypergeomMass - simp only [Nat.zero_le, ite_true, Nat.choose_zero_right, Nat.sub_zero, Nat.cast_one, one_mul] - rw [show M+V=V+M by omega, show M+(V-1)=V+M-1 by omega] - rw [div_mul_div_comm] - apply (div_eq_div_iff hCN.ne' (mul_pos hN0 hCP).ne').mpr - have hh := congrArg (fun z : ℝ => z*(V.choose (m+1):ℝ)) hcw - have hh' := congrArg (fun z : ℝ => z*((V+M).choose (m+1):ℝ)) hcv - nlinarith only [hh,hh'] - -/-- Exact adjacent visible-count TV, expressed with complementary hidden counts. -The shift by one is essential: the two totals are different. -/ -def adjacentHypergeomTV (V M m : ℕ) : ℝ := - (1/2:ℝ)*(hypergeomMass M V (m+1) 0 + - ∑ k ∈ Finset.range (M+1), |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k|) - -theorem adjacentHypergeomTV_eq_flux (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : - adjacentHypergeomTV V M m = - hypergeomHiddenFlux V M m (hypergeomHiddenMode (V-1) M m) := by - unfold adjacentHypergeomTV - rw [hypergeom_next_zero V M m hV] - have he : (∑ k ∈ Finset.range (M+1), - |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k|) = - ∑ k ∈ Finset.range (M+1), |hypergeomHiddenFlux V M m (k+1)-hypergeomHiddenFlux V M m k| := by - apply Finset.sum_congr rfl - intro k hk - rw [hypergeom_adjacent_hidden_difference V M m k hM hV (by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hk)] - rw [he] - unfold hypergeomHiddenFlux - simp_rw [← mul_sub, abs_mul, abs_of_nonneg (by positivity : (0:ℝ) ≤ (V:ℝ)/(V+M))] - rw [← Finset.mul_sum, ← mul_add, hypergeom_hidden_variation (V-1) M m hM (by omega)] - ring - -theorem adjacentHypergeomTV_le_mass (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : - adjacentHypergeomTV V M m ≤ hypergeomMass M V m (hypergeomHiddenMode (V-1) M m) := by - rw [adjacentHypergeomTV_eq_flux V M m hM hV, - hypergeomHiddenFlux_formula V M m _ hM hV (hypergeomHiddenMode_le (V-1) M m (by omega))] - have hk := hypergeomHiddenMode_le (V-1) M m (by omega : m ≤ V-1) - have hk' : (hypergeomHiddenMode (V-1) M m:ℝ) ≤ M := by exact_mod_cast hk - have hm' : (m:ℝ) < V := by exact_mod_cast hV - have hd : (0:ℝ) < (V:ℝ)+M-m := by linarith [Nat.cast_nonneg (α := ℝ) M] - apply mul_le_of_le_one_left (hypergeomMass_nonneg _ _ _ _) - apply (div_le_one hd).mpr - linarith - -end TraceReconstruction - -namespace TraceReconstruction -def bernoulliRelativeEntropy (θ p : ℝ) : ℝ := - θ*Real.log (θ/p)+(1-θ)*Real.log ((1-θ)/(1-p)) - -theorem bernoulliRelativeEntropy_upper {θ p : ℝ} - (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : - bernoulliRelativeEntropy θ p ≤ (θ-p)^2/(p*(1-p)) := by - have h1 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos (div_pos hθ.1 hp.1)) hθ.1.le - have h2 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos - (div_pos (sub_pos.mpr hθ.2) (sub_pos.mpr hp.2))) (sub_nonneg.mpr hθ.2.le) - have he : θ*(θ/p-1)+(1-θ)*((1-θ)/(1-p)-1) = (θ-p)^2/(p*(1-p)) := by - field_simp [hp.1.ne', (sub_pos.mpr hp.2).ne']; ring - unfold bernoulliRelativeEntropy - rw [← he] - linarith - -theorem binomialMass_change_probability (n k : ℕ) {θ p : ℝ} - (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : - binomialMass n p k = binomialMass n θ k * - Real.exp ((k:ℝ)*Real.log (p/θ)+(n-k:ℕ)*Real.log ((1-p)/(1-θ))) := by - rw [Real.exp_add, Real.exp_nat_mul, Real.exp_nat_mul, - Real.exp_log (div_pos hp.1 hθ.1), - Real.exp_log (div_pos (sub_pos.mpr hp.2) (sub_pos.mpr hθ.2))] - unfold binomialMass - simp only [div_pow] - field_simp [hθ.1.ne', (sub_pos.mpr hθ.2).ne'] - -theorem binomialMass_mean_change_probability (n k : ℕ) {θ p : ℝ} - (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) - (hk : k ≤ n) (hmean : (n:ℝ)*θ = k) : - binomialMass n p k = binomialMass n θ k * Real.exp (-(n:ℝ)*bernoulliRelativeEntropy θ p) := by - rw [binomialMass_change_probability n k hθ hp] - congr 2 - rw [Nat.cast_sub hk, ← hmean] - unfold bernoulliRelativeEntropy - rw [Real.log_div hp.1.ne' hθ.1.ne', Real.log_div (sub_pos.mpr hp.2).ne' (sub_pos.mpr hθ.2).ne', - Real.log_div hθ.1.ne' hp.1.ne', Real.log_div (sub_pos.mpr hθ.2).ne' (sub_pos.mpr hp.2).ne'] - ring - -/-- Uniform local binomial lower bound without Stirling. It applies at a -count `k` by changing to the channel with mean exactly `k`. -/ -theorem binomialMass_local_lower (n k : ℕ) {θ p : ℝ} - (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) - (hk : k ≤ n) (hmean : (n:ℝ)*θ = k) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) : - Real.exp (-(n:ℝ)*(θ-p)^2/(p*(1-p))) / - (12*Real.sqrt ((n:ℝ)*θ*(1-θ))) ≤ binomialMass n p k := by - rw [binomialMass_mean_change_probability n k hθ hp hk hmean] - have hlow := binomialMass_mean_lower n k hθ hk hmean hv - have hexp : Real.exp (-(n:ℝ)*(θ-p)^2/(p*(1-p))) ≤ - Real.exp (-(n:ℝ)*bernoulliRelativeEntropy θ p) := by - apply Real.exp_le_exp.mpr - have := mul_le_mul_of_nonpos_left (bernoulliRelativeEntropy_upper hθ hp) (neg_nonpos.mpr (Nat.cast_nonneg n)) - simpa only [mul_div_assoc] using this - have hh := mul_le_mul hlow hexp (Real.exp_pos _).le - (binomialMass_nonneg n k ⟨hθ.1.le,hθ.2.le⟩) - simpa only [one_div, div_eq_mul_inv, mul_comm, one_mul] using hh - -end TraceReconstruction - -end - -end OAI +import Mathlib + +namespace OAI + +/-! +# Binomial + +Fair and biased binomial laws, generating series, differences, concentration, Gaussian overlap, hidden counts, and local lower bounds. +-/ + +open scoped ENNReal +noncomputable section + +namespace TraceReconstruction + +/-! ## Quantitative fair-binomial anti-concentration + +A direct inductive bound, avoiding an unformalized appeal to Stirling. +It is one of the estimates needed for signed binomial smoothing and +for the local/global anchor kernels. +-/ + +/-- Fair-binomial mass, extended by zero beyond its natural support. -/ +def fairBinomial (n k : ℕ) : ℝ := (n.choose k : ℝ) / 2 ^ n + +theorem fairBinomial_nonneg (n k : ℕ) : 0 ≤ fairBinomial n k := by + unfold fairBinomial + positivity + +theorem centralBinom_square_bound (n : ℕ) : + ((n : ℝ) + 1) * (n.centralBinom : ℝ) ^ 2 ≤ (16 : ℝ) ^ n := by + induction n with + | zero => norm_num + | succ n ih => + have hn : (0 : ℝ) < n + 1 := by positivity + have hr : ((n : ℝ) + 1) * ((n + 1).centralBinom : ℝ) = + 2 * (2 * n + 1) * (n.centralBinom : ℝ) := by + exact_mod_cast Nat.succ_mul_centralBinom_succ n + have hc : 4 * (2 * (n : ℝ) + 1) ^ 2 * (n + 2) ≤ + 16 * (n + 1) ^ 3 := by nlinarith [sq_nonneg (n : ℝ)] + have hh : ((n : ℝ) + 1) ^ 2 * + ((n + 2) * ((n + 1).centralBinom : ℝ) ^ 2) ≤ + ((n : ℝ) + 1) ^ 2 * (16 * 16 ^ n) := by + calc + _ = (n + 2) * (((n : ℝ) + 1) * ((n + 1).centralBinom : ℝ)) ^ 2 := by ring + _ = (4 * (2 * (n : ℝ) + 1) ^ 2 * (n + 2)) * + (n.centralBinom : ℝ) ^ 2 := by rw [hr]; ring + _ ≤ (16 * ((n : ℝ) + 1) ^ 3) * (n.centralBinom : ℝ) ^ 2 := + mul_le_mul_of_nonneg_right hc (sq_nonneg _) + _ = (16 * ((n : ℝ) + 1) ^ 2) * + (((n : ℝ) + 1) * (n.centralBinom : ℝ) ^ 2) := by ring + _ ≤ (16 * ((n : ℝ) + 1) ^ 2) * 16 ^ n := + mul_le_mul_of_nonneg_left ih (by positivity) + _ = _ := by ring + have := (mul_le_mul_iff_right₀ (sq_pos_of_pos hn)).mp hh + rw [pow_succ (16 : ℝ) n] + convert this using 1 <;> push_cast <;> first | rfl | ring + +theorem choose_odd_le_twice_central (n k : ℕ) : + (2 * n + 1).choose k ≤ 2 * n.centralBinom := by + cases k with + | zero => simp only [Nat.choose_zero_right]; have := Nat.centralBinom_pos n; omega + | succ k => + rw [Nat.choose_succ_succ] + have h₁ := Nat.choose_le_centralBinom k n + have h₂ := Nat.choose_le_centralBinom (k + 1) n + simpa [Nat.succ_eq_add_one, two_mul] using Nat.add_le_add h₁ h₂ + +theorem fairBinomial_square_bound (n k : ℕ) : + ((n : ℝ) + 1) * fairBinomial n k ^ 2 ≤ 2 := by + have hcases : n % 2 = 0 ∨ n % 2 = 1 := Nat.mod_two_eq_zero_or_one n + rcases hcases with he | ho + · obtain ⟨m, rfl⟩ : ∃ m, n = 2 * m := ⟨n / 2, by omega⟩ + have hc : ((2 * m).choose k : ℝ) ≤ (m.centralBinom : ℝ) := + by exact_mod_cast Nat.choose_le_centralBinom k m + have hcs : ((2 * m).choose k : ℝ) ^ 2 ≤ (m.centralBinom : ℝ) ^ 2 := + pow_le_pow_left₀ (by positivity) hc 2 + have ht := centralBinom_square_bound m + have hp : ((2 : ℝ) ^ (2 * m)) ^ 2 = 16 ^ m := by + rw [← pow_mul, show 2 * m * 2 = 4 * m by omega, pow_mul] + norm_num + unfold fairBinomial + rw [div_pow, ← mul_div_assoc, div_le_iff₀ (by positivity : (0 : ℝ) < (2 ^ (2 * m)) ^ 2)] + rw [hp] + push_cast + nlinarith [mul_le_mul_of_nonneg_left hcs (show (0 : ℝ) ≤ m + 1 by positivity), + sq_nonneg ((2 * m).choose k : ℝ)] + · obtain ⟨m, rfl⟩ : ∃ m, n = 2 * m + 1 := ⟨n / 2, by omega⟩ + have hc : ((2 * m + 1).choose k : ℝ) ≤ 2 * (m.centralBinom : ℝ) := + by exact_mod_cast choose_odd_le_twice_central m k + have hcs : ((2 * m + 1).choose k : ℝ) ^ 2 ≤ 4 * (m.centralBinom : ℝ) ^ 2 := by + have := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ ((2 * m + 1).choose k : ℝ)) hc 2 + nlinarith + have ht := centralBinom_square_bound m + have hp : ((2 : ℝ) ^ (2 * m + 1)) ^ 2 = 4 * 16 ^ m := by + rw [pow_add, mul_pow, ← pow_mul, show 2 * m * 2 = 4 * m by omega, pow_mul] + norm_num + ring + unfold fairBinomial + rw [div_pow, ← mul_div_assoc, div_le_iff₀ (by positivity : (0 : ℝ) < (2 ^ (2 * m + 1)) ^ 2)] + rw [hp] + push_cast + nlinarith [mul_le_mul_of_nonneg_left hcs (show (0 : ℝ) ≤ m + 1 by positivity)] + + +/-! ## Discrete convolution estimates for the hidden displacement kernels -/ + +abbrev IntSeries := AddMonoidAlgebra ℝ ℤ + +def seriesL1 (f : IntSeries) : ℝ := ∑' z : ℤ, |f.coeff z| +def seriesL2Sq (f : IntSeries) : ℝ := ∑' z : ℤ, f.coeff z ^ 2 + +theorem series_summable (f : IntSeries) (φ : ℝ → ℝ) (hφ : φ 0 = 0) : + Summable (fun z : ℤ => φ (f.coeff z)) := + summable_of_hasFiniteSupport (f.coeff.hasFiniteSupport.fun_comp hφ) + +theorem seriesL1_nonneg (f : IntSeries) : 0 ≤ seriesL1 f := + tsum_nonneg fun _ => abs_nonneg _ + +theorem seriesL2Sq_nonneg (f : IntSeries) : 0 ≤ seriesL2Sq f := + tsum_nonneg fun _ => sq_nonneg _ + +theorem seriesL1_eq_sum (f : IntSeries) : + seriesL1 f = ∑ z ∈ f.coeff.support, |f.coeff z| := by + apply tsum_eq_sum + intro z hz + simp [Finsupp.notMem_support_iff.mp hz] + +theorem seriesL2Sq_eq_sum (f : IntSeries) : + seriesL2Sq f = ∑ z ∈ f.coeff.support, f.coeff z ^ 2 := by + apply tsum_eq_sum + intro z hz + simp [Finsupp.notMem_support_iff.mp hz] + +theorem series_summable_shift (f : IntSeries) (φ : ℝ → ℝ) + (hφ : φ 0 = 0) (a : ℤ) : + Summable (fun z : ℤ => φ (f.coeff (a + z))) := by + exact (Equiv.addLeft a).summable_iff.mpr (series_summable f φ hφ) + +theorem series_sum_shift (f : IntSeries) (φ : ℝ → ℝ) (a : ℤ) : + (∑' z : ℤ, φ (f.coeff (a + z))) = ∑' z : ℤ, φ (f.coeff z) := + (Equiv.addLeft a).tsum_eq (fun z => φ (f.coeff z)) + +theorem series_coeff_mul_abs_le (f g : IntSeries) (z : ℤ) : + |(f * g).coeff z| ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * |g.coeff (-a + z)| := by + rw [AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum] + simpa only [abs_mul] using Finset.abs_sum_le_sum_abs + (fun a => f.coeff a * g.coeff (-a + z)) f.coeff.support + +theorem seriesL1_mul_le (f g : IntSeries) : + seriesL1 (f * g) ≤ seriesL1 f * seriesL1 g := by + have hh (a : ℤ) : Summable (fun z : ℤ => |f.coeff a| * |g.coeff (-a + z)|) := + (series_summable_shift g abs (by simp) (-a)).mul_left _ + calc + seriesL1 (f * g) ≤ ∑' z : ℤ, ∑ a ∈ f.coeff.support, + |f.coeff a| * |g.coeff (-a + z)| := + Summable.tsum_le_tsum (series_coeff_mul_abs_le f g) (series_summable (f * g) abs (by simp)) + (summable_sum fun a _ => hh a) + _ = ∑ a ∈ f.coeff.support, ∑' z : ℤ, |f.coeff a| * |g.coeff (-a + z)| := + Summable.tsum_finsetSum fun a _ => hh a + _ = (∑ a ∈ f.coeff.support, |f.coeff a|) * seriesL1 g := by + simp_rw [tsum_mul_left, series_sum_shift] + exact (Finset.sum_mul _ _ _).symm + _ = seriesL1 f * seriesL1 g := by rw [seriesL1_eq_sum f] + +theorem series_coeff_mul_sq_le (f g : IntSeries) (z : ℤ) : + (f * g).coeff z ^ 2 ≤ seriesL1 f * + ∑ a ∈ f.coeff.support, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := by + rw [AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum, seriesL1_eq_sum] + apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul + · intro a _; exact abs_nonneg _ + · intro a _; positivity + · intro a _ + rw [mul_pow, ← mul_assoc, ← sq, sq_abs] + +theorem seriesL2Sq_mul_le (f g : IntSeries) : + seriesL2Sq (f * g) ≤ seriesL1 f ^ 2 * seriesL2Sq g := by + have hh (a : ℤ) : Summable (fun z : ℤ => |f.coeff a| * (g.coeff (-a + z)) ^ 2) := + (series_summable_shift g (fun x => x ^ 2) (by simp) (-a)).mul_left _ + calc + seriesL2Sq (f * g) ≤ ∑' z : ℤ, seriesL1 f * + ∑ a ∈ f.coeff.support, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := + Summable.tsum_le_tsum (series_coeff_mul_sq_le f g) + (series_summable (f * g) (fun x => x ^ 2) (by simp)) + ((summable_sum fun a _ => hh a).mul_left _) + _ = seriesL1 f * ∑ a ∈ f.coeff.support, + ∑' z : ℤ, |f.coeff a| * (g.coeff (-a + z)) ^ 2 := by + rw [tsum_mul_left, Summable.tsum_finsetSum fun a _ => hh a] + _ = seriesL1 f ^ 2 * seriesL2Sq g := by + simp_rw [tsum_mul_left, series_sum_shift g (fun x => x ^ 2)] + rw [← Finset.sum_mul, ← seriesL1_eq_sum] + unfold seriesL2Sq + ring + +theorem series_coeff_mul_bound (f g : IntSeries) (M : ℝ) + (hg : ∀ z, |g.coeff z| ≤ M) (z : ℤ) : + |(f * g).coeff z| ≤ seriesL1 f * M := by + calc + _ ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * |g.coeff (-a + z)| := + series_coeff_mul_abs_le f g z + _ ≤ ∑ a ∈ f.coeff.support, |f.coeff a| * M := + Finset.sum_le_sum fun a _ => mul_le_mul_of_nonneg_left (hg _) (abs_nonneg _) + _ = seriesL1 f * M := by rw [← Finset.sum_mul, ← seriesL1_eq_sum] + +/-! The probability generating series of the fair binomial kernel. -/ +def fairSeries (n : ℕ) : IntSeries := + (AddMonoidAlgebra.single 1 (1 / 2) + AddMonoidAlgebra.single 0 (1 / 2)) ^ n + +theorem fairSeries_add (m n : ℕ) : fairSeries (m + n) = fairSeries m * fairSeries n := + pow_add _ m n + +theorem fairSeries_sum (n : ℕ) : + fairSeries n = ∑ k ∈ Finset.range (n + 1), + AddMonoidAlgebra.single (k : ℤ) (fairBinomial n k) := by + unfold fairSeries + rw [add_pow] + apply Finset.sum_congr rfl + intro k hk + have hkn : k ≤ n := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hk + rw [AddMonoidAlgebra.single_pow, AddMonoidAlgebra.single_pow, + AddMonoidAlgebra.natCast_def, AddMonoidAlgebra.single_mul_single, + AddMonoidAlgebra.single_mul_single] + simp only [nsmul_eq_mul, mul_one, mul_zero, add_zero] + congr 1 + rw [← pow_add, Nat.add_sub_of_le hkn] + unfold fairBinomial + rw [div_pow] + simp [div_eq_mul_inv, mul_comm] + +theorem fairSeries_coeff_nat (n k : ℕ) : + (fairSeries n).coeff (k : ℤ) = fairBinomial n k := by + rw [fairSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + by_cases hk : k ≤ n + · rw [Finset.sum_eq_single k] + · simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_true] + · intro b _ hb + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hb] + · intro h + exact (h (Finset.mem_range.mpr (by omega))).elim + · rw [Finset.sum_eq_zero] + · simp [fairBinomial, Nat.choose_eq_zero_of_lt (by omega : n < k)] + · intro b hb + have hbk : b ≠ k := by simp only [Finset.mem_range] at hb; omega + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hbk] + +theorem fairSeries_coeff_neg (n : ℕ) (z : ℤ) (hz : z < 0) : + (fairSeries n).coeff z = 0 := by + rw [fairSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + apply Finset.sum_eq_zero + intro b _ + have h : (b : ℤ) ≠ z := by omega + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] + +theorem seriesL1_eq_sum_range (f : IntSeries) (n : ℕ) + (hneg : ∀ z < 0, f.coeff z = 0) + (hhigh : ∀ k : ℕ, n < k → f.coeff k = 0) : + seriesL1 f = ∑ k ∈ Finset.range (n + 1), |f.coeff (k : ℤ)| := by + let e : ℕ ↪ ℤ := ⟨Nat.cast, Nat.cast_injective⟩ + calc + seriesL1 f = ∑ z ∈ (Finset.range (n + 1)).map e, |f.coeff z| := by + apply tsum_eq_sum + intro z hz + by_cases h : 0 ≤ z + · have heq : ((z.toNat : ℕ) : ℤ) = z := Int.toNat_of_nonneg h + have hh : n < z.toNat := by + by_contra hn + apply hz + exact Finset.mem_map.mpr ⟨z.toNat, Finset.mem_range.mpr (by omega), heq⟩ + rw [← heq, hhigh _ hh, abs_zero] + · rw [hneg z (by omega), abs_zero] + _ = _ := Finset.sum_map _ e _ + +def firstDifference : IntSeries := + AddMonoidAlgebra.single 0 1 - AddMonoidAlgebra.single 1 1 + +theorem firstDifference_coeff (f : IntSeries) (z : ℤ) : + (firstDifference * f).coeff z = f.coeff z - f.coeff (z - 1) := by + rw [firstDifference, sub_mul, AddMonoidAlgebra.coeff_sub, Finsupp.sub_apply, + mul_comm _ f, AddMonoidAlgebra.coeff_mul_single_apply, + mul_comm _ f, AddMonoidAlgebra.coeff_mul_single_apply] + simp only [neg_zero, add_zero, mul_one, sub_eq_add_neg] + +theorem fairSeries_difference_coeff_zero (n : ℕ) : + (firstDifference * fairSeries n).coeff 0 = fairBinomial n 0 := by + rw [firstDifference_coeff] + norm_num only [zero_sub] + rw [fairSeries_coeff_neg n (-1) (by norm_num), sub_zero] + exact fairSeries_coeff_nat n 0 + +theorem fairSeries_difference_coeff_succ (n k : ℕ) : + (firstDifference * fairSeries n).coeff (↑(k + 1) : ℤ) = + fairBinomial n (k + 1) - fairBinomial n k := by + rw [firstDifference_coeff, fairSeries_coeff_nat] + simp only [Nat.cast_add, Nat.cast_one, add_sub_cancel_right, fairSeries_coeff_nat] + +theorem fairBinomial_unimodal_left (n k : ℕ) (hk : k < n / 2) : + fairBinomial n k ≤ fairBinomial n (k + 1) := by + apply div_le_div_of_nonneg_right _ (by positivity) + exact_mod_cast Nat.choose_le_succ_of_lt_half_left hk + +theorem fairBinomial_unimodal_right (n k : ℕ) (hk : n / 2 ≤ k) : + fairBinomial n (k + 1) ≤ fairBinomial n k := by + apply div_le_div_of_nonneg_right _ (by positivity) + have hnk : n - k ≤ k + 1 := by omega + have hmul := Nat.mul_le_mul_left (n.choose k) hnk + rw [← Nat.choose_succ_right_eq] at hmul + exact_mod_cast Nat.le_of_mul_le_mul_right hmul (by omega : 0 < k + 1) + +theorem fairBinomial_variation (n : ℕ) : + (∑ k ∈ Finset.range (n + 1), |fairBinomial n (k + 1) - fairBinomial n k|) = + 2 * fairBinomial n (n / 2) - fairBinomial n 0 := by + have hmid : n / 2 ≤ n + 1 := by omega + rw [← Finset.sum_range_add_sum_Ico _ hmid] + have hl : (∑ k ∈ Finset.range (n / 2), + |fairBinomial n (k + 1) - fairBinomial n k|) = + fairBinomial n (n / 2) - fairBinomial n 0 := by + rw [← Finset.sum_range_sub (fairBinomial n) (n / 2)] + apply Finset.sum_congr rfl + intro k hk + exact abs_of_nonneg (sub_nonneg.mpr + (fairBinomial_unimodal_left n k (Finset.mem_range.mp hk))) + have hr : (∑ k ∈ Finset.Ico (n / 2) (n + 1), + |fairBinomial n (k + 1) - fairBinomial n k|) = + fairBinomial n (n / 2) - fairBinomial n (n + 1) := by + calc + _ = ∑ k ∈ Finset.Ico (n / 2) (n + 1), + -(fairBinomial n (k + 1) - fairBinomial n k) := by + apply Finset.sum_congr rfl + intro k hk + exact abs_of_nonpos (sub_nonpos.mpr + (fairBinomial_unimodal_right n k (Finset.mem_Ico.mp hk).1)) + _ = _ := by rw [Finset.sum_neg_distrib, Finset.sum_Ico_sub _ hmid]; ring + rw [hl, hr] + have hzero : fairBinomial n (n + 1) = 0 := by simp [fairBinomial] + rw [hzero] + ring + +theorem fairSeries_difference_L1 (n : ℕ) : + seriesL1 (firstDifference * fairSeries n) = 2 * fairBinomial n (n / 2) := by + rw [seriesL1_eq_sum_range _ (n + 1)] + · rw [Finset.sum_range_succ', Nat.cast_zero, fairSeries_difference_coeff_zero, + abs_of_nonneg (fairBinomial_nonneg n 0)] + simp_rw [fairSeries_difference_coeff_succ] + rw [fairBinomial_variation] + ring + · intro z hz + rw [firstDifference_coeff, fairSeries_coeff_neg n z hz, + fairSeries_coeff_neg n (z - 1) (by omega), sub_zero] + · intro k hk + have hkpos : 0 < k := by omega + obtain ⟨v, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hkpos) + rw [fairSeries_difference_coeff_succ] + simp [fairBinomial, Nat.choose_eq_zero_of_lt (by omega : n < v), + Nat.choose_eq_zero_of_lt (by omega : n < v + 1)] + +def binomialBound (n : ℕ) : ℝ := Real.sqrt (2 / ((n : ℝ) + 1)) + +theorem binomialBound_nonneg (n : ℕ) : 0 ≤ binomialBound n := Real.sqrt_nonneg _ + +theorem fairBinomial_le_bound (n k : ℕ) : fairBinomial n k ≤ binomialBound n := by + apply Real.le_sqrt_of_sq_le + apply (le_div_iff₀ (by positivity : (0 : ℝ) < n + 1)).mpr + simpa only [mul_comm] using fairBinomial_square_bound n k + +theorem fairSeries_nonneg (n : ℕ) (z : ℤ) : 0 ≤ (fairSeries n).coeff z := by + by_cases hz : 0 ≤ z + · rw [← Int.toNat_of_nonneg hz, fairSeries_coeff_nat] + exact fairBinomial_nonneg _ _ + · rw [fairSeries_coeff_neg n z (by omega)] + +theorem fairSeries_coeff_bound (n : ℕ) (z : ℤ) : + |(fairSeries n).coeff z| ≤ binomialBound n := by + by_cases hz : 0 ≤ z + · rw [← Int.toNat_of_nonneg hz, fairSeries_coeff_nat, + abs_of_nonneg (fairBinomial_nonneg _ _)] + exact fairBinomial_le_bound _ _ + · rw [fairSeries_coeff_neg n z (by omega), abs_zero] + exact binomialBound_nonneg n + +theorem fairSeries_L1 (n : ℕ) : seriesL1 (fairSeries n) = 1 := by + rw [seriesL1_eq_sum_range _ n (fairSeries_coeff_neg n)] + · simp_rw [fairSeries_coeff_nat, abs_of_nonneg (fairBinomial_nonneg _ _)] + unfold fairBinomial + rw [← Finset.sum_div] + have hsum : (∑ k ∈ Finset.range (n + 1), (n.choose k : ℝ)) = (2 : ℝ) ^ n := by + exact_mod_cast Nat.sum_range_choose n + rw [hsum, div_self (by positivity)] + · intro k hk + rw [fairSeries_coeff_nat] + simp [fairBinomial, Nat.choose_eq_zero_of_lt hk] + +theorem seriesL2Sq_le_L1_mul_bound (f : IntSeries) (M : ℝ) + (hf : ∀ z, |f.coeff z| ≤ M) : seriesL2Sq f ≤ seriesL1 f * M := by + calc + _ ≤ ∑' z : ℤ, |f.coeff z| * M := by + apply Summable.tsum_le_tsum + · intro z + calc + f.coeff z ^ 2 = |f.coeff z| * |f.coeff z| := by rw [← sq, sq_abs] + _ ≤ _ := mul_le_mul_of_nonneg_left (hf z) (abs_nonneg _) + · exact series_summable f (fun x => x ^ 2) (by simp) + · exact (series_summable f abs (by simp)).mul_right M + _ = _ := tsum_mul_right + +theorem fairSeries_L2Sq_bound (n : ℕ) : seriesL2Sq (fairSeries n) ≤ binomialBound n := by + simpa only [fairSeries_L1, one_mul] using + seriesL2Sq_le_L1_mul_bound (fairSeries n) (binomialBound n) (fairSeries_coeff_bound n) + +theorem fairSeries_difference_L1_bound (n : ℕ) : + seriesL1 (firstDifference * fairSeries n) ≤ 2 * binomialBound n := by + rw [fairSeries_difference_L1] + exact mul_le_mul_of_nonneg_left (fairBinomial_le_bound n (n / 2)) (by norm_num) + +theorem seriesL1_single (z : ℤ) (r : ℝ) : + seriesL1 (AddMonoidAlgebra.single z r) = |r| := by + unfold seriesL1 + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply] + simp only [apply_ite abs, abs_zero] + exact tsum_ite_eq' z (fun _ : ℤ => |r|) + +theorem seriesL1_one : seriesL1 (1 : IntSeries) = 1 := by + change seriesL1 (AddMonoidAlgebra.single 0 1) = 1 + rw [seriesL1_single, abs_one] + +theorem seriesL1_pow_le (f : IntSeries) (s : ℕ) : seriesL1 (f ^ s) ≤ seriesL1 f ^ s := by + induction s with + | zero => simp only [pow_zero, seriesL1_one, le_refl] + | succ s ih => + rw [pow_succ, pow_succ] + exact (seriesL1_mul_le _ _).trans + (mul_le_mul_of_nonneg_right ih (seriesL1_nonneg f)) + +theorem fairSeries_mul_power (n s : ℕ) : + firstDifference ^ s * fairSeries ((s + 1) * n) = + (firstDifference * fairSeries n) ^ s * fairSeries n := by + simp only [fairSeries, add_mul, one_mul, pow_add, pow_mul, mul_pow] + ring + +/-- Quantitative higher-order smoothing, with n trials assigned to each + difference and one further group reserved for anti-concentration. -/ +theorem binomial_difference_coeff_bound (n s : ℕ) (z : ℤ) : + |(firstDifference ^ s * fairSeries ((s + 1) * n)).coeff z| ≤ + (2 * binomialBound n) ^ s * binomialBound n := by + rw [fairSeries_mul_power] + apply (series_coeff_mul_bound _ _ _ (fairSeries_coeff_bound n) z).trans + apply mul_le_mul_of_nonneg_right _ (binomialBound_nonneg n) + exact (seriesL1_pow_le _ _).trans + (pow_le_pow_left₀ (seriesL1_nonneg _) (fairSeries_difference_L1_bound n) s) + +theorem binomial_difference_L2Sq_bound (n s : ℕ) : + seriesL2Sq (firstDifference ^ s * fairSeries ((s + 1) * n)) ≤ + ((2 * binomialBound n) ^ s) ^ 2 * binomialBound n := by + rw [fairSeries_mul_power] + apply (seriesL2Sq_mul_le _ _).trans + apply mul_le_mul + · apply pow_le_pow_left₀ (seriesL1_nonneg _) + exact (seriesL1_pow_le _ _).trans + (pow_le_pow_left₀ (seriesL1_nonneg _) (fairSeries_difference_L1_bound n) s) + · exact fairSeries_L2Sq_bound n + · exact seriesL2Sq_nonneg _ + · positivity + +theorem seriesL1_add_le (f g : IntSeries) : + seriesL1 (f + g) ≤ seriesL1 f + seriesL1 g := by + calc + _ ≤ ∑' z : ℤ, (|f.coeff z| + |g.coeff z|) := by + apply Summable.tsum_le_tsum + · intro z + simpa only [AddMonoidAlgebra.coeff_add, Finsupp.add_apply] using + abs_add_le (f.coeff z) (g.coeff z) + · exact series_summable (f + g) abs (by simp) + · exact (series_summable f abs (by simp)).add (series_summable g abs (by simp)) + _ = _ := (series_summable f abs (by simp)).tsum_add (series_summable g abs (by simp)) + +theorem seriesL1_zero : seriesL1 (0 : IntSeries) = 0 := by + simp [seriesL1] + +theorem seriesL1_sum_le {ι : Type*} (A : Finset ι) (f : ι → IntSeries) : + seriesL1 (∑ i ∈ A, f i) ≤ ∑ i ∈ A, seriesL1 (f i) := by + classical + induction A using Finset.induction_on with + | empty => simp only [Finset.sum_empty, seriesL1_zero, le_refl] + | @insert a A ha ih => + rw [Finset.sum_insert ha, Finset.sum_insert ha] + exact (seriesL1_add_le _ _).trans (add_le_add le_rfl ih) + +theorem seriesL1_prod_le {ι : Type*} (A : Finset ι) (f : ι → IntSeries) : + seriesL1 (∏ i ∈ A, f i) ≤ ∏ i ∈ A, seriesL1 (f i) := by + classical + induction A using Finset.induction_on with + | empty => simp only [Finset.prod_empty, seriesL1_one, le_refl] + | @insert a A ha ih => + rw [Finset.prod_insert ha, Finset.prod_insert ha] + exact (seriesL1_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (seriesL1_nonneg _)) + +def geomSeries (k : ℕ) : IntSeries := ∑ a ∈ Finset.range k, (AddMonoidAlgebra.single 1 1) ^ a + +def prouhetSeries (s : ℕ) : IntSeries := + ∏ v ∈ Finset.range s, (1 - (AddMonoidAlgebra.single 1 1) ^ (2 ^ v)) + +def prouhetQuotient (s : ℕ) : IntSeries := + ∏ v ∈ Finset.range s, geomSeries (2 ^ v) + +theorem geomSeries_difference (k : ℕ) : + geomSeries k * firstDifference = 1 - (AddMonoidAlgebra.single 1 1 : IntSeries) ^ k := by + exact geom_sum_mul_neg _ _ + +theorem geomSeries_L1_le (k : ℕ) : seriesL1 (geomSeries k) ≤ k := by + apply (seriesL1_sum_le _ _).trans + simp only [AddMonoidAlgebra.single_pow, one_pow, seriesL1_single, abs_one, + Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_one, le_refl] + +theorem prouhetSeries_factor (s : ℕ) : + prouhetSeries s = prouhetQuotient s * firstDifference ^ s := by + unfold prouhetSeries prouhetQuotient + simp_rw [← geomSeries_difference] + rw [Finset.prod_mul_distrib] + simp only [Finset.prod_const, Finset.card_range] + +theorem prouhetQuotient_L1_le (s : ℕ) : + seriesL1 (prouhetQuotient s) ≤ (2 : ℝ) ^ (s * s) := by + calc + _ ≤ ∏ v ∈ Finset.range s, seriesL1 (geomSeries (2 ^ v)) := seriesL1_prod_le _ _ + _ ≤ ∏ _v ∈ Finset.range s, ((2 : ℝ) ^ s) := by + apply Finset.prod_le_prod₀ + · intro v _; exact seriesL1_nonneg _ + · intro v hv + apply (geomSeries_L1_le _).trans + push_cast + apply pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) + exact (Finset.mem_range.mp hv).le + _ = _ := by simp only [Finset.prod_const, Finset.card_range, ← pow_mul] + +/-- Prouhet smoothing in an explicit finite-trial form. The constants + 2^(s*s) and (2 sqrt(2/(n+1)))^s are exp(O(s^2)) after assigning + n = floor(g/(s+1)) trials to each group. No Fourier theorem or + probabilistic estimate is assumed. -/ +theorem prouhet_binomial_coeff_bound (n s : ℕ) (z : ℤ) : + |(prouhetSeries s * fairSeries ((s + 1) * n)).coeff z| ≤ + (2 : ℝ) ^ (s * s) * ((2 * binomialBound n) ^ s * binomialBound n) := by + rw [prouhetSeries_factor, mul_assoc] + apply (series_coeff_mul_bound _ _ _ (binomial_difference_coeff_bound n s) z).trans + exact mul_le_mul_of_nonneg_right (prouhetQuotient_L1_le s) + (by positivity [binomialBound_nonneg n]) + +theorem prouhet_binomial_L2Sq_bound (n s : ℕ) : + seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n)) ≤ + ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound n) ^ s) ^ 2 * binomialBound n) := by + rw [prouhetSeries_factor, mul_assoc] + apply (seriesL2Sq_mul_le _ _).trans + apply mul_le_mul + · exact pow_le_pow_left₀ (seriesL1_nonneg _) (prouhetQuotient_L1_le s) 2 + · exact binomial_difference_L2Sq_bound n s + · exact seriesL2Sq_nonneg _ + · positivity + +/-- Arbitrary trial counts are obtained by convolving with the independent + unused trials; this cannot enlarge the coefficient or squared-L2 bounds. -/ +theorem prouhet_binomial_coeff_bound_remainder (n s r : ℕ) (z : ℤ) : + |(prouhetSeries s * fairSeries ((s + 1) * n + r)).coeff z| ≤ + (2 : ℝ) ^ (s * s) * ((2 * binomialBound n) ^ s * binomialBound n) := by + rw [fairSeries_add, ← mul_assoc, mul_comm (prouhetSeries s * _)] + simpa only [fairSeries_L1, one_mul] using + series_coeff_mul_bound (fairSeries r) (prouhetSeries s * fairSeries ((s + 1) * n)) + _ (prouhet_binomial_coeff_bound n s) z + +theorem prouhet_binomial_L2Sq_bound_remainder (n s r : ℕ) : + seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n + r)) ≤ + ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound n) ^ s) ^ 2 * binomialBound n) := by + rw [fairSeries_add, ← mul_assoc, mul_comm (prouhetSeries s * _)] + calc + _ ≤ seriesL1 (fairSeries r) ^ 2 * + seriesL2Sq (prouhetSeries s * fairSeries ((s + 1) * n)) := seriesL2Sq_mul_le _ _ + _ ≤ _ := by simpa only [fairSeries_L1, one_pow, one_mul] using + prouhet_binomial_L2Sq_bound n s + +theorem signed_binomial_smoothing (g s : ℕ) : + (∀ z : ℤ, |(prouhetSeries s * fairSeries g).coeff z| ≤ + (2 : ℝ) ^ (s * s) * ((2 * binomialBound (g / (s + 1))) ^ s * + binomialBound (g / (s + 1)))) ∧ + (seriesL2Sq (prouhetSeries s * fairSeries g) ≤ + ((2 : ℝ) ^ (s * s)) ^ 2 * (((2 * binomialBound (g / (s + 1))) ^ s) ^ 2 * + binomialBound (g / (s + 1)))) := by + have hg : (s + 1) * (g / (s + 1)) + g % (s + 1) = g := Nat.div_add_mod g (s + 1) + constructor + · intro z + simpa only [hg] using prouhet_binomial_coeff_bound_remainder (g / (s + 1)) s + (g % (s + 1)) z + · simpa only [hg] using prouhet_binomial_L2Sq_bound_remainder (g / (s + 1)) s + (g % (s + 1)) + +theorem binomialBound_quotient_le (g s : ℕ) : + binomialBound (g / (s + 1)) ≤ + Real.sqrt (2 * ((s : ℝ) + 1) / ((g : ℝ) + 1)) := by + apply Real.sqrt_le_sqrt + have hn : g + 1 ≤ (g / (s + 1) + 1) * (s + 1) := by + have hmod := Nat.mod_lt g (by omega : 0 < s + 1) + have hdiv := Nat.div_add_mod g (s + 1) + nlinarith + have hnr : (g : ℝ) + 1 ≤ ((g / (s + 1) : ℕ) + (1 : ℝ)) * ((s : ℝ) + 1) := by + exact_mod_cast hn + apply (div_le_div_iff₀ (by positivity : (0 : ℝ) < (g / (s + 1) : ℕ) + 1) + (by positivity : (0 : ℝ) < g + 1)).mpr + nlinarith + +theorem prouhetSeries_succ_coeff (s : ℕ) (z : ℤ) : + (prouhetSeries (s + 1)).coeff z = + (prouhetSeries s).coeff z - (prouhetSeries s).coeff (z - (2 ^ s : ℕ)) := by + rw [prouhetSeries, Finset.prod_range_succ, mul_sub, mul_one] + change (prouhetSeries s - prouhetSeries s * + (AddMonoidAlgebra.single 1 1 : IntSeries) ^ (2 ^ s)).coeff z = _ + rw [AddMonoidAlgebra.coeff_sub, Finsupp.sub_apply] + simp only [AddMonoidAlgebra.single_pow, one_pow, nsmul_eq_mul, mul_one, + AddMonoidAlgebra.coeff_mul_single_apply, sub_eq_add_neg] + +/-- The exact generating polynomial from the manuscript has unit signed + coefficients at every index 0,...,2^s-1, and no other coefficients. -/ +theorem prouhetSeries_coeff_spec (s : ℕ) : + (∀ z : ℤ, (z < 0 ∨ (2 ^ s : ℕ) ≤ z) → (prouhetSeries s).coeff z = 0) ∧ + (∀ z : ℤ, 0 ≤ z → z < (2 ^ s : ℕ) → |(prouhetSeries s).coeff z| = 1) := by + induction s with + | zero => + have hcoeff (z : ℤ) : (prouhetSeries 0).coeff z = if 0 = z then 1 else 0 := by + change (AddMonoidAlgebra.single 0 (1 : ℝ)).coeff z = _ + exact Finsupp.single_apply + constructor + · intro z hz + rw [hcoeff, ite_eq_right] + norm_num only [pow_zero, Nat.cast_one] at hz + omega + · intro z h0 h1 + have hz : z = 0 := by norm_num only [pow_zero, Nat.cast_one] at h1; omega + subst hz + rw [hcoeff, ite_eq_left rfl, abs_one] + | succ s ih => + have hp : (0 : ℤ) < (2 ^ s : ℕ) := by positivity + have hd : ((2 ^ (s + 1) : ℕ) : ℤ) = 2 * (2 ^ s : ℕ) := by push_cast; ring + constructor + · intro z hz + rw [prouhetSeries_succ_coeff] + rcases hz with hz | hz + · rw [ih.1 z (Or.inl hz), ih.1 _ (Or.inl (by omega)), sub_zero] + · rw [hd] at hz + rw [ih.1 z (Or.inr (by omega)), ih.1 _ (Or.inr (by omega)), sub_zero] + · intro z h0 h1 + rw [hd] at h1 + rw [prouhetSeries_succ_coeff] + by_cases hz : z < (2 ^ s : ℕ) + · rw [ih.1 (z - (2 ^ s : ℕ)) (Or.inl (by omega)), sub_zero] + exact ih.2 z h0 hz + · rw [ih.1 z (Or.inr (by omega)), zero_sub, abs_neg] + exact ih.2 _ (by omega) (by omega) + + +/-! ## Nonfair anti-concentration without an assumed Stirling estimate -/ + +def binomialMass (n : ℕ) (p : ℝ) (k : ℕ) : ℝ := + (n.choose k : ℝ) * p ^ k * (1 - p) ^ (n - k) + +theorem binomialMass_nonneg (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : + 0 ≤ binomialMass n p k := by + unfold binomialMass + positivity [hp.1, sub_nonneg.mpr hp.2] + +theorem sum_binomialMass (n : ℕ) (p : ℝ) : + ∑ k ∈ Finset.range (n + 1), binomialMass n p k = 1 := by + have h := add_pow p (1 - p) n + rw [show p + (1 - p) = 1 by ring, one_pow] at h + rw [h] + apply Finset.sum_congr rfl + intro k _ + unfold binomialMass + ring + +theorem binomialMass_harmonic_step (n k : ℕ) (p : ℝ) : + ((n : ℝ) + 1) * p * (binomialMass n p k / ((k : ℝ) + 1)) = + binomialMass (n + 1) p (k + 1) := by + have hc : ((n : ℝ) + 1) * (n.choose k : ℝ) = + ((n + 1).choose (k + 1) : ℝ) * ((k : ℝ) + 1) := by + exact_mod_cast Nat.add_one_mul_choose_eq n k + unfold binomialMass + rw [Nat.add_sub_add_right, pow_succ] + field_simp + nlinarith [congrArg (fun x : ℝ => x * p ^ k * (1 - p) ^ (n - k) * p) hc] + +theorem binomialMass_harmonic_identity (n : ℕ) (p : ℝ) : + ((n : ℝ) + 1) * p * + (∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1)) = + 1 - (1 - p) ^ (n + 1) := by + rw [Finset.mul_sum] + simp_rw [binomialMass_harmonic_step] + have h := sum_binomialMass (n + 1) p + rw [Finset.sum_range_succ'] at h + simp only [binomialMass, Nat.choose_zero_right, Nat.cast_one, pow_zero, + mul_one, one_mul, Nat.sub_zero] at h ⊢ + linarith + +theorem binomialMass_harmonic_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : + (∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1)) ≤ + 1 / (((n : ℝ) + 1) * p) := by + apply (le_div_iff₀ (mul_pos (by positivity) hp.1)).mpr + rw [mul_comm, binomialMass_harmonic_identity] + have h := pow_nonneg (sub_nonneg.mpr hp.2) (n + 1) + linarith + +/-- The weighted Cauchy--Schwarz step for mixing the fair estimates. -/ +theorem weighted_sum_sq_le {ι : Type*} (S : Finset ι) (w f : ι → ℝ) + (hw : ∀ i, 0 ≤ w i) : + (∑ i ∈ S, w i * f i) ^ 2 ≤ (∑ i ∈ S, w i) * ∑ i ∈ S, w i * f i ^ 2 := by + have heq (i : ι) : w i * f i = Real.sqrt (w i) * (Real.sqrt (w i) * f i) := by + rw [← mul_assoc, ← sq, Real.sq_sqrt (hw i)] + simp_rw [heq] + apply (Finset.sum_mul_sq_le_sq_mul_sq S (fun i => Real.sqrt (w i)) + (fun i => Real.sqrt (w i) * f i)).trans_eq + simp only [mul_pow, Real.sq_sqrt (hw _)] + +theorem mixed_binomialBound_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : + (∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k) ≤ + Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by + have hw (k : ℕ) := binomialMass_nonneg n k (show p ∈ Set.Icc 0 1 from ⟨hp.1.le, hp.2⟩) + have hs := weighted_sum_sq_le (Finset.range (n + 1)) (binomialMass n p) + binomialBound hw + rw [sum_binomialMass, one_mul] at hs + have hb (k : ℕ) : binomialBound k ^ 2 = 2 / ((k : ℝ) + 1) := + Real.sq_sqrt (by positivity) + simp_rw [hb] at hs + have heq : (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (2 / ((k : ℝ) + 1))) = + 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [heq] at hs + have hh := binomialMass_harmonic_le n hp + have hp0 := hp.1 + have hbound : (∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k) ^ 2 ≤ + 2 / (((n : ℝ) + 1) * p) := by + calc + _ ≤ 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k / ((k : ℝ) + 1) := hs + _ ≤ 2 * (1 / (((n : ℝ) + 1) * p)) := mul_le_mul_of_nonneg_left hh (by norm_num) + _ = _ := by ring + have hsr := Real.sq_sqrt (show (0 : ℝ) ≤ 2 / (((n : ℝ) + 1) * p) by positivity) + have hpos := Real.sqrt_nonneg (2 / (((n : ℝ) + 1) * p)) + nlinarith only [hbound, hsr, hpos] + + +def mixedFairSeries (n : ℕ) (p : ℝ) : IntSeries := + (p • fairSeries 1 + (1 - p) • (1 : IntSeries)) ^ n + +def biasedSeries (n : ℕ) (p : ℝ) : IntSeries := + (AddMonoidAlgebra.single 1 p + AddMonoidAlgebra.single 0 (1 - p)) ^ n + +theorem mixedFairSeries_expansion (n : ℕ) (p : ℝ) : + mixedFairSeries n p = + ∑ k ∈ Finset.range (n + 1), binomialMass n p k • fairSeries k := by + rw [mixedFairSeries, add_pow] + apply Finset.sum_congr rfl + intro k _ + simp only [smul_pow, one_pow, smul_mul_smul, mul_one, fairSeries, pow_one] + rw [mul_comm, ← nsmul_eq_mul, ← Nat.cast_smul_eq_nsmul ℝ, smul_smul] + congr 1 + unfold binomialMass + ring + +theorem mixedFairSeries_eq_biased (n : ℕ) (p : ℝ) : + mixedFairSeries n p = biasedSeries n (p / 2) := by + unfold mixedFairSeries biasedSeries + congr 1 + ext z + simp only [fairSeries, pow_one, smul_add, AddMonoidAlgebra.one_def, AddMonoidAlgebra.coeff_add, + Finsupp.add_apply, AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, + smul_eq_mul, AddMonoidAlgebra.coeff_single, Finsupp.single_apply] + split_ifs <;> first | omega | ring + +theorem mixedFairSeries_coeff_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) (z : ℤ) : + |(mixedFairSeries n p).coeff z| ≤ Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by + rw [mixedFairSeries_expansion, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + simp only [AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, smul_eq_mul] + calc + _ ≤ ∑ k ∈ Finset.range (n + 1), |binomialMass n p k * (fairSeries k).coeff z| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k := by + apply Finset.sum_le_sum + intro k _ + have hw := binomialMass_nonneg n k (show p ∈ Set.Icc 0 1 from ⟨hp.1.le, hp.2⟩) + rw [abs_mul, abs_of_nonneg hw] + exact mul_le_mul_of_nonneg_left (fairSeries_coeff_bound k z) hw + _ ≤ _ := mixed_binomialBound_le n hp + +/-- At success probabilities at most 1/2, this gives the sharp variance + scale up to an absolute constant, using only the fair-coin estimate. -/ +theorem biasedSeries_coeff_bound_low (n : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioc 0 (1 / 2)) (z : ℤ) : + |(biasedSeries n p).coeff z| ≤ Real.sqrt (1 / (((n : ℝ) + 1) * p)) := by + have h2p : 2 * p ∈ Set.Ioc 0 1 := ⟨by linarith [hp.1], by linarith [hp.2]⟩ + have h := mixedFairSeries_coeff_bound n h2p z + rw [mixedFairSeries_eq_biased, show 2 * p / 2 = p by ring] at h + have heq : 2 / (((n : ℝ) + 1) * (2 * p)) = 1 / (((n : ℝ) + 1) * p) := by + field_simp + rwa [heq] at h + + +theorem biasedSeries_sum (n : ℕ) (p : ℝ) : + biasedSeries n p = ∑ k ∈ Finset.range (n + 1), + AddMonoidAlgebra.single (k : ℤ) (binomialMass n p k) := by + rw [biasedSeries, add_pow] + apply Finset.sum_congr rfl + intro k _ + rw [AddMonoidAlgebra.single_pow, AddMonoidAlgebra.single_pow, + AddMonoidAlgebra.natCast_def, AddMonoidAlgebra.single_mul_single, + AddMonoidAlgebra.single_mul_single] + simp only [nsmul_eq_mul, mul_one, mul_zero, add_zero] + congr 1 + unfold binomialMass + ring + +theorem biasedSeries_coeff_nat (n k : ℕ) (p : ℝ) : + (biasedSeries n p).coeff (k : ℤ) = binomialMass n p k := by + rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + by_cases hk : k ≤ n + · rw [Finset.sum_eq_single k] + · simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_true] + · intro b _ hb + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hb] + · intro h + exact (h (Finset.mem_range.mpr (by omega))).elim + · rw [Finset.sum_eq_zero] + · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : n < k)] + · intro b hb + have hbk : b ≠ k := by simp only [Finset.mem_range] at hb; omega + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, Nat.cast_inj, ite_eq_right hbk] + +theorem biasedSeries_coeff_neg (n : ℕ) (p : ℝ) (z : ℤ) (hz : z < 0) : + (biasedSeries n p).coeff z = 0 := by + rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + apply Finset.sum_eq_zero + intro b _ + have h : (b : ℤ) ≠ z := by omega + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] + +theorem biasedSeries_coeff_high (n : ℕ) (p : ℝ) (z : ℤ) (hz : (n : ℤ) < z) : + (biasedSeries n p).coeff z = 0 := by + rw [biasedSeries_sum, AddMonoidAlgebra.coeff_sum, Finsupp.finsetSum_apply] + apply Finset.sum_eq_zero + intro b hb + have h : (b : ℤ) ≠ z := by simp only [Finset.mem_range] at hb; omega + simp only [AddMonoidAlgebra.coeff_single, Finsupp.single_apply, ite_eq_right h] + +theorem binomialMass_symm (n k : ℕ) (p : ℝ) (hk : k ≤ n) : + binomialMass n (1 - p) (n - k) = binomialMass n p k := by + unfold binomialMass + rw [Nat.choose_symm hk, Nat.sub_sub_self hk, show 1 - (1 - p) = p by ring] + ring + +theorem biasedSeries_coeff_reflect (n : ℕ) (p : ℝ) (z : ℤ) : + (biasedSeries n (1 - p)).coeff ((n : ℤ) - z) = (biasedSeries n p).coeff z := by + by_cases hz : z < 0 + · rw [biasedSeries_coeff_neg n p z hz, + biasedSeries_coeff_high n (1 - p) _ (by omega)] + by_cases hz' : (n : ℤ) < z + · rw [biasedSeries_coeff_high n p z hz', + biasedSeries_coeff_neg n (1 - p) _ (by omega)] + have h0 : 0 ≤ z := by omega + have hk : z.toNat ≤ n := by omega + have hzN : (z.toNat : ℤ) = z := Int.toNat_of_nonneg h0 + have hsub : (n : ℤ) - z = ((n - z.toNat : ℕ) : ℤ) := by omega + rw [hsub, ← hzN, biasedSeries_coeff_nat, biasedSeries_coeff_nat] + exact binomialMass_symm n z.toNat p hk + +/-- Uniform nonfair-binomial anti-concentration. This is the absolute + variance-scale upper bound used in the manuscript's rank kernels. -/ +theorem biasedSeries_coeff_bound (n : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : + |(biasedSeries n p).coeff z| ≤ + Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) := by + by_cases hlow : p ≤ 1 / 2 + · apply (biasedSeries_coeff_bound_low n ⟨hp.1, hlow⟩ z).trans + apply Real.sqrt_le_sqrt + apply one_div_le_one_div_of_le + · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) + · have hn : (0 : ℝ) ≤ n + 1 := by positivity + nlinarith [mul_nonneg hn (sq_nonneg p)] + · have hq : 1 - p ∈ Set.Ioc 0 (1 / 2) := ⟨by linarith [hp.2], by linarith⟩ + rw [← biasedSeries_coeff_reflect n p z] + apply (biasedSeries_coeff_bound_low n hq ((n : ℤ) - z)).trans + apply Real.sqrt_le_sqrt + apply one_div_le_one_div_of_le + · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) + · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) + (mul_nonneg (sub_nonneg.mpr hp.2.le) (sub_nonneg.mpr hp.2.le))] + + +theorem binomialMass_mul_index (n k : ℕ) (p : ℝ) : + binomialMass (n + 1) p (k + 1) * ((k : ℝ) + 1) = + ((n : ℝ) + 1) * p * binomialMass n p k := by + have h := binomialMass_harmonic_step n k p + have hk : ((k : ℝ) + 1) ≠ 0 := by positivity + rw [← h] + field_simp + +theorem binomialMass_index_sum (n : ℕ) (p : ℝ) (F : ℕ → ℝ) : + (∑ k ∈ Finset.range (n + 2), binomialMass (n + 1) p k * (k : ℝ) * F k) = + ((n : ℝ) + 1) * p * + ∑ k ∈ Finset.range (n + 1), binomialMass n p k * F (k + 1) := by + rw [show n + 2 = (n + 1) + 1 by omega, Finset.sum_range_succ'] + simp only [Nat.cast_zero, mul_zero, zero_mul, add_zero, Nat.cast_add, Nat.cast_one] + simp_rw [binomialMass_mul_index] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + +theorem binomialMass_mean (n : ℕ) (p : ℝ) : + ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) = (n : ℝ) * p := by + cases n with + | zero => simp + | succ n => + simpa only [mul_one, sum_binomialMass, Nat.cast_add, Nat.cast_one] using + binomialMass_index_sum n p (fun _ => 1) + +theorem binomialMass_second_moment (n : ℕ) (p : ℝ) : + ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) ^ 2 = + (n : ℝ) * ((n : ℝ) - 1) * p ^ 2 + (n : ℝ) * p := by + cases n with + | zero => simp + | succ n => + have h := binomialMass_index_sum n p (fun k => k) + simp only [Nat.cast_add, Nat.cast_one] at h ⊢ + simp_rw [mul_add, mul_one, Finset.sum_add_distrib, binomialMass_mean, + sum_binomialMass] at h + calc + _ = ∑ k ∈ Finset.range (n + 2), binomialMass (n + 1) p k * (k : ℝ) * (k : ℝ) := by + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by rw [h]; ring + +theorem binomialMass_variance (n : ℕ) (p : ℝ) : + (∑ k ∈ Finset.range (n + 1), binomialMass n p k * ((k : ℝ) - (n : ℝ) * p) ^ 2) = + (n : ℝ) * p * (1 - p) := by + calc + _ = (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ) ^ 2) - + 2 * (n : ℝ) * p * (∑ k ∈ Finset.range (n + 1), binomialMass n p k * (k : ℝ)) + + ((n : ℝ) * p) ^ 2 * (∑ k ∈ Finset.range (n + 1), binomialMass n p k) := by + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by rw [binomialMass_second_moment, binomialMass_mean, sum_binomialMass]; ring + +theorem binomialMass_adjacent (n k : ℕ) (p : ℝ) (hk : k < n) : + ((k : ℝ) + 1) * (1 - p) * binomialMass n p (k + 1) = + ((n : ℝ) - k) * p * binomialMass n p k := by + have hc : (n.choose (k + 1) : ℝ) * ((k : ℝ) + 1) = + (n.choose k : ℝ) * ((n : ℝ) - (k : ℝ)) := by + simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_sub hk.le] using + congrArg (fun t : ℕ => (t : ℝ)) (Nat.choose_succ_right_eq n k) + have hnk : n - k = (n - (k + 1)) + 1 := by omega + unfold binomialMass + rw [hnk, pow_succ, pow_succ] + linear_combination p ^ k * p * (1 - p) ^ (n - (k + 1)) * (1 - p) * hc + +theorem binomialMass_le_mode (n l k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) + (hl : l ≤ n) (hmean : (n : ℝ) * p = l) : + binomialMass n p k ≤ binomialMass n p l := by + have h0 (j : ℕ) := binomialMass_nonneg n j ⟨hp.1.le, hp.2.le⟩ + have hleft (j : ℕ) (hj : j < l) : binomialMass n p j ≤ binomialMass n p (j + 1) := by + have hrec := binomialMass_adjacent n j p (by omega) + have hjr : (j : ℝ) + 1 ≤ l := by exact_mod_cast hj + have hcoef : (0 : ℝ) < ((j : ℝ) + 1) * (1 - p) := by + exact mul_pos (by positivity) (sub_pos.mpr hp.2) + have hdiff : ((j : ℝ) + 1) * (1 - p) ≤ ((n : ℝ) - j) * p := by + nlinarith [hp.1] + have := mul_le_mul_of_nonneg_right hdiff (h0 j) + nlinarith only [hrec, this, hcoef] + have hright (j : ℕ) (hj : l ≤ j) : binomialMass n p (j + 1) ≤ binomialMass n p j := by + by_cases hjn : j < n + · have hrec := binomialMass_adjacent n j p hjn + have hjr : (l : ℝ) ≤ j := by exact_mod_cast hj + have hcoef : (0 : ℝ) < ((j : ℝ) + 1) * (1 - p) := by + exact mul_pos (by positivity) (sub_pos.mpr hp.2) + have hdiff : ((n : ℝ) - j) * p ≤ ((j : ℝ) + 1) * (1 - p) := by + nlinarith [hp.2] + have := mul_le_mul_of_nonneg_right hdiff (h0 j) + nlinarith only [hrec, this, hcoef] + · have hjn' : n < j + 1 := by omega + simp only [binomialMass, Nat.choose_eq_zero_of_lt hjn', Nat.cast_zero, zero_mul] + exact h0 j + rcases le_total k l with hk | hk + · have haux : ∀ b : ℕ, k ≤ b → b ≤ l → binomialMass n p k ≤ binomialMass n p b := by + intro b hkb + induction b, hkb using Nat.le_induction with + | base => intro _; exact le_rfl + | succ b hb ih => + intro hbl + exact (ih (by omega)).trans (hleft b (by omega)) + exact haux l hk le_rfl + · induction k, hk using Nat.le_induction with + | base => exact le_rfl + | succ j hj ih => exact (hright j hj).trans ih + + +/-- A discrete law cannot have a very small maximum when its variance is bounded. +The explicit constant is deliberately loose, avoiding any use of Stirling. -/ +theorem discrete_mode_lower (n l : ℕ) (f : ℕ → ℝ) (M v : ℝ) + (hf : ∀ k, 0 ≤ f k) (hsum : ∑ k ∈ Finset.range (n + 1), f k = 1) + (hmax : ∀ k, f k ≤ M) + (hvar : ∑ k ∈ Finset.range (n + 1), f k * ((k : ℝ) - l) ^ 2 = v) + (hv : 1 ≤ v) : 1 / (12 * Real.sqrt v) ≤ M := by + classical + let r : ℕ := ⌈2 * Real.sqrt v⌉₊ + have hv0 : 0 ≤ v := by linarith + have hs : 1 ≤ Real.sqrt v := Real.one_le_sqrt.mpr hv + have hs2 := Real.sq_sqrt hv0 + have hrlo : 2 * Real.sqrt v ≤ (r : ℝ) := Nat.le_ceil _ + have hrhi : (r : ℝ) < 2 * Real.sqrt v + 1 := Nat.ceil_lt_add_one (by positivity) + have hrpos : (0 : ℝ) < r := by linarith + have hM : 0 ≤ M := (hf 0).trans (hmax 0) + let S := (Finset.range (n + 1)).filter (fun k => l - r ≤ k ∧ k ≤ l + r) + have hcard : S.card ≤ 2 * r + 1 := by + have hsub : S ⊆ Finset.Icc (l - r) (l + r) := by + intro k hk + exact Finset.mem_Icc.mpr (Finset.mem_filter.mp hk).2 + have := Finset.card_le_card hsub + rw [Nat.card_Icc] at this + omega + have hout (k : ℕ) (hk : ¬(l - r ≤ k ∧ k ≤ l + r)) : + (r : ℝ) ^ 2 ≤ ((k : ℝ) - l) ^ 2 := by + by_cases hleft : k < l - r + · have hnat : k + r < l := by omega + have hreal : (k : ℝ) + r < l := by exact_mod_cast hnat + nlinarith [sq_nonneg ((l : ℝ) - k - r)] + · have hnat : l + r < k := by omega + have hreal : (l : ℝ) + r < k := by exact_mod_cast hnat + nlinarith [sq_nonneg ((k : ℝ) - l - r)] + have hpoint (k : ℕ) : (r : ℝ) ^ 2 * f k ≤ + (if l - r ≤ k ∧ k ≤ l + r then (r : ℝ) ^ 2 * M else 0) + + f k * ((k : ℝ) - l) ^ 2 := by + split_ifs with hk + · have := mul_le_mul_of_nonneg_left (hmax k) (sq_nonneg (r : ℝ)) + have := mul_nonneg (hf k) (sq_nonneg ((k : ℝ) - l)) + linarith + · simpa only [zero_add, mul_comm] using mul_le_mul_of_nonneg_left (hout k hk) (hf k) + have htotal := Finset.sum_le_sum (fun k (_ : k ∈ Finset.range (n + 1)) => hpoint k) + rw [← Finset.mul_sum, hsum, mul_one, Finset.sum_add_distrib, hvar, + ← Finset.sum_filter] at htotal + change (r : ℝ) ^ 2 ≤ ∑ k ∈ S, (r : ℝ) ^ 2 * M + v at htotal + rw [Finset.sum_const, nsmul_eq_mul] at htotal + have hcardR : (S.card : ℝ) ≤ 2 * r + 1 := by exact_mod_cast hcard + have hbound := mul_le_mul_of_nonneg_right hcardR (mul_nonneg (sq_nonneg (r : ℝ)) hM) + have htotal' : (r : ℝ) ^ 2 ≤ (2 * r + 1) * ((r : ℝ) ^ 2 * M) + v := by + linarith + have hrv : 4 * v ≤ (r : ℝ) ^ 2 := by nlinarith [sq_nonneg ((r : ℝ) - 2 * Real.sqrt v)] + have hcancel : (3 : ℝ) / 4 ≤ (2 * r + 1) * M := by + have hrr : (0 : ℝ) < (r : ℝ) ^ 2 := sq_pos_of_pos hrpos + nlinarith only [htotal', hrv, hrr] + have hsize : 2 * (r : ℝ) + 1 ≤ 7 * Real.sqrt v := by linarith + have hfinal := mul_le_mul_of_nonneg_right hsize hM + apply (div_le_iff₀ (by positivity : 0 < 12 * Real.sqrt v)).mpr + nlinarith only [hcancel, hfinal] + +theorem binomialMass_mean_lower (n l : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) + (hl : l ≤ n) (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) : + 1 / (12 * Real.sqrt ((n : ℝ) * p * (1 - p))) ≤ binomialMass n p l := by + apply discrete_mode_lower n l (binomialMass n p) + (binomialMass n p l) ((n : ℝ) * p * (1 - p)) + · intro k; exact binomialMass_nonneg n k ⟨hp.1.le, hp.2.le⟩ + · exact sum_binomialMass n p + · intro k; exact binomialMass_le_mode n l k hp hl hmean + · rw [← hmean]; exact binomialMass_variance n p + · exact hv + + +theorem binomialMass_mean_inverse_sq (n l : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) + (hl : l ≤ n) (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) : + (binomialMass n p l)⁻¹ ^ 2 ≤ 144 * ((n : ℝ) * p * (1 - p)) := by + have hs : 0 < Real.sqrt ((n : ℝ) * p * (1 - p)) := + Real.sqrt_pos.mpr (by linarith) + have hlow := binomialMass_mean_lower n l hp hl hmean hv + have hpos : 0 < binomialMass n p l := lt_of_lt_of_le (by positivity) hlow + have hi : (binomialMass n p l)⁻¹ ≤ 12 * Real.sqrt ((n : ℝ) * p * (1 - p)) := by + rw [← one_div] + apply (div_le_iff₀ hpos).mpr + have := (div_le_iff₀ (by positivity)).mp hlow + nlinarith only [this] + have his := sq_le_sq₀ (by positivity) (by positivity) |>.mpr hi + have hs2 := Real.sq_sqrt (show 0 ≤ (n : ℝ) * p * (1 - p) by linarith) + nlinarith only [his, hs2] + +theorem seriesL1_smul (a : ℝ) (f : IntSeries) : + seriesL1 (a • f) = |a| * seriesL1 f := by + unfold seriesL1 + simp only [AddMonoidAlgebra.coeff_smul, Finsupp.smul_apply, smul_eq_mul, abs_mul] + exact tsum_mul_left + +theorem mixedFairSeries_difference_L1_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioc 0 1) : + seriesL1 (firstDifference * mixedFairSeries n p) ≤ + 2 * Real.sqrt (2 / (((n : ℝ) + 1) * p)) := by + rw [mixedFairSeries_expansion, Finset.mul_sum] + simp_rw [mul_smul_comm] + calc + _ ≤ ∑ k ∈ Finset.range (n + 1), + seriesL1 (binomialMass n p k • (firstDifference * fairSeries k)) := seriesL1_sum_le _ _ + _ ≤ ∑ k ∈ Finset.range (n + 1), binomialMass n p k * (2 * binomialBound k) := by + apply Finset.sum_le_sum + intro k _ + have hw := binomialMass_nonneg n k ⟨hp.1.le, hp.2⟩ + rw [seriesL1_smul, abs_of_nonneg hw] + exact mul_le_mul_of_nonneg_left (fairSeries_difference_L1_bound k) hw + _ = 2 * ∑ k ∈ Finset.range (n + 1), binomialMass n p k * binomialBound k := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _; ring + _ ≤ _ := mul_le_mul_of_nonneg_left (mixed_binomialBound_le n hp) (by norm_num) + +theorem biasedSeries_difference_L1_bound_low (n : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioc 0 (1 / 2)) : + seriesL1 (firstDifference * biasedSeries n p) ≤ + 2 * Real.sqrt (1 / (((n : ℝ) + 1) * p)) := by + have h := mixedFairSeries_difference_L1_bound n + (show 2 * p ∈ Set.Ioc 0 1 from ⟨by linarith [hp.1], by linarith [hp.2]⟩) + rw [mixedFairSeries_eq_biased] at h + have hp2 : 2 * p / 2 = p := by ring + have heq : 2 / (((n : ℝ) + 1) * (2 * p)) = 1 / (((n : ℝ) + 1) * p) := by + have hp0 : p ≠ 0 := ne_of_gt hp.1 + have hn0 : ((n : ℝ) + 1) ≠ 0 := by positivity + field_simp + rwa [hp2, heq] at h + +theorem biasedSeries_difference_reflect (n : ℕ) (p : ℝ) (z : ℤ) : + (firstDifference * biasedSeries n (1 - p)).coeff z = + -(firstDifference * biasedSeries n p).coeff ((n : ℤ) + 1 - z) := by + rw [firstDifference_coeff, firstDifference_coeff] + have h1 := biasedSeries_coeff_reflect n p ((n : ℤ) - z) + have h2 := biasedSeries_coeff_reflect n p ((n : ℤ) - (z - 1)) + have hz1 : (n : ℤ) - ((n : ℤ) - z) = z := by ring + have hz2 : (n : ℤ) - ((n : ℤ) - (z - 1)) = z - 1 := by ring + rw [hz1] at h1 + rw [hz2] at h2 + rw [h1, h2] + have he1 : (n : ℤ) - (z - 1) = n + 1 - z := by ring + have he2 : (n : ℤ) + 1 - z - 1 = n - z := by ring + rw [he1, he2] + ring + +theorem biasedSeries_difference_L1_reflect (n : ℕ) (p : ℝ) : + seriesL1 (firstDifference * biasedSeries n (1 - p)) = + seriesL1 (firstDifference * biasedSeries n p) := by + unfold seriesL1 + simp_rw [biasedSeries_difference_reflect, abs_neg] + exact (Equiv.subLeft ((n : ℤ) + 1)).tsum_eq + (fun z : ℤ => |(firstDifference * biasedSeries n p).coeff z|) + +theorem biasedSeries_difference_L1_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + seriesL1 (firstDifference * biasedSeries n p) ≤ + 2 * Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) := by + by_cases hlow : p ≤ 1 / 2 + · apply (biasedSeries_difference_L1_bound_low n ⟨hp.1, hlow⟩).trans + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.sqrt_le_sqrt + apply one_div_le_one_div_of_le + · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) + · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) (sq_nonneg p)] + · have hq : 1 - p ∈ Set.Ioc 0 (1 / 2) := ⟨by linarith [hp.2], by linarith⟩ + rw [← biasedSeries_difference_L1_reflect n p] + apply (biasedSeries_difference_L1_bound_low n hq).trans + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.sqrt_le_sqrt + apply one_div_le_one_div_of_le + · exact mul_pos (mul_pos (by positivity) hp.1) (sub_pos.mpr hp.2) + · nlinarith [mul_nonneg (show (0 : ℝ) ≤ n + 1 by positivity) + (mul_nonneg (sub_nonneg.mpr hp.2.le) (sub_nonneg.mpr hp.2.le))] + + +def biasedBinomialBound (n : ℕ) (p : ℝ) : ℝ := + Real.sqrt (1 / (((n : ℝ) + 1) * p * (1 - p))) + +theorem biasedSeries_L1 (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : + seriesL1 (biasedSeries n p) = 1 := by + rw [seriesL1_eq_sum_range _ n (biasedSeries_coeff_neg n p)] + · simp_rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ hp)] + exact sum_binomialMass n p + · intro k hk + exact biasedSeries_coeff_high n p k (by exact_mod_cast hk) + +theorem biasedSeries_L2Sq_bound (n : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + seriesL2Sq (biasedSeries n p) ≤ biasedBinomialBound n p := by + have := seriesL2Sq_le_L1_mul_bound (biasedSeries n p) _ (biasedSeries_coeff_bound n hp) + simpa only [biasedSeries_L1 n ⟨hp.1.le, hp.2.le⟩, one_mul, biasedBinomialBound] using this + +theorem biasedSeries_add (m n : ℕ) (p : ℝ) : + biasedSeries (m + n) p = biasedSeries m p * biasedSeries n p := by + exact pow_add _ _ _ + +theorem biasedSeries_mul_power (n s : ℕ) (p : ℝ) : + firstDifference ^ s * biasedSeries ((s + 1) * n) p = + (firstDifference * biasedSeries n p) ^ s * biasedSeries n p := by + simp only [biasedSeries, add_mul, one_mul, pow_add, pow_mul, mul_pow] + ring + +theorem biased_difference_coeff_bound (n s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : + |(firstDifference ^ s * biasedSeries ((s + 1) * n) p).coeff z| ≤ + (2 * biasedBinomialBound n p) ^ s * biasedBinomialBound n p := by + rw [biasedSeries_mul_power] + apply (series_coeff_mul_bound _ _ _ (biasedSeries_coeff_bound n hp) z).trans + apply mul_le_mul_of_nonneg_right _ (Real.sqrt_nonneg _) + exact (seriesL1_pow_le _ _).trans + (pow_le_pow_left₀ (seriesL1_nonneg _) (biasedSeries_difference_L1_bound n hp) s) + +theorem biased_difference_L2Sq_bound (n s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n) p) ≤ + ((2 * biasedBinomialBound n p) ^ s) ^ 2 * biasedBinomialBound n p := by + rw [biasedSeries_mul_power] + apply (seriesL2Sq_mul_le _ _).trans + apply mul_le_mul + · apply pow_le_pow_left₀ (seriesL1_nonneg _) + exact (seriesL1_pow_le _ _).trans + (pow_le_pow_left₀ (seriesL1_nonneg _) (biasedSeries_difference_L1_bound n hp) s) + · exact biasedSeries_L2Sq_bound n hp + · exact seriesL2Sq_nonneg _ + · exact sq_nonneg _ + +theorem biased_difference_coeff_bound_remainder (n s r : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioo 0 1) (z : ℤ) : + |(firstDifference ^ s * biasedSeries ((s + 1) * n + r) p).coeff z| ≤ + (2 * biasedBinomialBound n p) ^ s * biasedBinomialBound n p := by + rw [biasedSeries_add, ← mul_assoc, mul_comm (firstDifference ^ s * _)] + simpa only [biasedSeries_L1 r ⟨hp.1.le, hp.2.le⟩, one_mul] using + series_coeff_mul_bound (biasedSeries r p) (firstDifference ^ s * biasedSeries ((s + 1) * n) p) + _ (biased_difference_coeff_bound n s hp) z + +theorem biased_difference_L2Sq_bound_remainder (n s r : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioo 0 1) : + seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n + r) p) ≤ + ((2 * biasedBinomialBound n p) ^ s) ^ 2 * biasedBinomialBound n p := by + rw [biasedSeries_add, ← mul_assoc, mul_comm (firstDifference ^ s * _)] + calc + _ ≤ seriesL1 (biasedSeries r p) ^ 2 * + seriesL2Sq (firstDifference ^ s * biasedSeries ((s + 1) * n) p) := seriesL2Sq_mul_le _ _ + _ ≤ _ := by simpa only [biasedSeries_L1 r ⟨hp.1.le, hp.2.le⟩, one_pow, one_mul] using + biased_difference_L2Sq_bound n s hp + +/-- All fixed-order nonfair binomial differences, at the exact variance scale. +This is the analytic estimate needed for the initial conditional rank kernels. -/ +theorem biased_difference_smoothing (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + (∀ z : ℤ, |(firstDifference ^ s * biasedSeries g p).coeff z| ≤ + (2 * biasedBinomialBound (g / (s + 1)) p) ^ s * + biasedBinomialBound (g / (s + 1)) p) ∧ + (seriesL2Sq (firstDifference ^ s * biasedSeries g p) ≤ + ((2 * biasedBinomialBound (g / (s + 1)) p) ^ s) ^ 2 * + biasedBinomialBound (g / (s + 1)) p) := by + have hg : (s + 1) * (g / (s + 1)) + g % (s + 1) = g := Nat.div_add_mod g (s + 1) + constructor + · intro z + simpa only [hg] using biased_difference_coeff_bound_remainder (g / (s + 1)) s + (g % (s + 1)) hp z + · simpa only [hg] using biased_difference_L2Sq_bound_remainder (g / (s + 1)) s + (g % (s + 1)) hp + +theorem biasedBinomialBound_quotient_le (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + biasedBinomialBound (g / (s + 1)) p ≤ + Real.sqrt (((s : ℝ) + 1) / (((g : ℝ) + 1) * p * (1 - p))) := by + unfold biasedBinomialBound + apply Real.sqrt_le_sqrt + have hpq : 0 < p * (1 - p) := mul_pos hp.1 (sub_pos.mpr hp.2) + have hnat : g + 1 ≤ (s + 1) * (g / (s + 1) + 1) := by + have hdiv := Nat.div_add_mod g (s + 1) + have hmod : g % (s + 1) < s + 1 := Nat.mod_lt g (by omega) + calc + g + 1 = (s + 1) * (g / (s + 1)) + g % (s + 1) + 1 := by omega + _ ≤ (s + 1) * (g / (s + 1)) + (s + 1) := by omega + _ = _ := by ring + have hreal : (g : ℝ) + 1 ≤ ((s : ℝ) + 1) * ((g / (s + 1) : ℕ) + 1 : ℝ) := by + exact_mod_cast hnat + have hp0 := hp.1 + have hq0 := sub_pos.mpr hp.2 + apply (div_le_div_iff₀ (by positivity) (by positivity)).mpr + nlinarith only [mul_le_mul_of_nonneg_right hreal hpq.le] + +/-! ## Gaussian overlap by exponential tilting of the exact binomial law -/ + +theorem binomialMass_tilt (n k : ℕ) {p a : ℝ} (hp : p ∈ Set.Ioo 0 1) + (ha : 0 < a) : + binomialMass n p k * a ^ k = + (1 - p + p * a) ^ n * binomialMass n (p * a / (1 - p + p * a)) k := by + by_cases hk : k ≤ n + · have hA : 0 < 1 - p + p * a := by positivity [sub_pos.mpr hp.2, hp.1] + have hsub : 1 - p * a / (1 - p + p * a) = (1 - p) / (1 - p + p * a) := by + field_simp; ring + unfold binomialMass + rw [hsub, div_pow, div_pow, mul_pow] + have hpow : (1 - p + p * a) ^ n = + (1 - p + p * a) ^ k * (1 - p + p * a) ^ (n - k) := by + rw [← pow_add, Nat.add_sub_of_le hk] + rw [hpow] + field_simp + · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : n < k)] + +theorem binomialMass_tilt_product (g h k : ℕ) {p a : ℝ} (hp : p ∈ Set.Ioo 0 1) + (ha : 0 < a) : + binomialMass g p k * binomialMass h p k = + ((1 - p + p * a) ^ g * (1 - p + p / a) ^ h) * + (binomialMass g (p * a / (1 - p + p * a)) k * + binomialMass h ((p / a) / (1 - p + p / a)) k) := by + have h1 := binomialMass_tilt g k hp ha + have h2 := binomialMass_tilt h k hp (inv_pos.mpr ha) + have hid := congrArg₂ (· * ·) h1 h2 + simp only [inv_pow, ← div_eq_mul_inv] at hid + have ha0 : a ^ k ≠ 0 := pow_ne_zero _ ha.ne' + calc + _ = (binomialMass g p k * a ^ k) * (binomialMass h p k / a ^ k) := by field_simp + _ = _ := by convert hid using 1; ring + +/-- Tilting on opposite sides retains an anti-concentration factor as well +as the Gaussian penalty for different numbers of trials. -/ +theorem binomial_overlap_tilt_bound (g h : ℕ) {p a : ℝ} + (hp : p ∈ Set.Ioo 0 1) (ha : 0 < a) : + (∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k) ≤ + ((1 - p + p * a) ^ g * (1 - p + p / a) ^ h) * + biasedBinomialBound g (p * a / (1 - p + p * a)) := by + have hA : 0 < 1 - p + p * a := by positivity [sub_pos.mpr hp.2, hp.1] + have hB : 0 < 1 - p + p / a := by positivity [sub_pos.mpr hp.2, hp.1] + have hpA : p * a / (1 - p + p * a) ∈ Set.Ioo (0 : ℝ) 1 := by + constructor + · positivity [hp.1] + · apply (div_lt_one hA).mpr; linarith [hp.2] + have hpB : (p / a) / (1 - p + p / a) ∈ Set.Ioo (0 : ℝ) 1 := by + constructor + · positivity [hp.1] + · apply (div_lt_one hB).mpr; linarith [hp.2] + simp_rw [binomialMass_tilt_product g h _ hp ha, ← Finset.mul_sum] + apply mul_le_mul_of_nonneg_left _ (by positivity) + calc + _ ≤ ∑ k ∈ Finset.range (h + 1), + biasedBinomialBound g (p * a / (1 - p + p * a)) * + binomialMass h ((p / a) / (1 - p + p / a)) k := by + apply Finset.sum_le_sum + intro k _ + apply mul_le_mul_of_nonneg_right _ (binomialMass_nonneg _ _ ⟨hpB.1.le, hpB.2.le⟩) + have hb := biasedSeries_coeff_bound g hpA (k : ℤ) + rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ ⟨hpA.1.le, hpA.2.le⟩)] at hb + exact hb + _ = _ := by rw [← Finset.mul_sum, sum_binomialMass, mul_one] + + +theorem binomial_tilt_variance {p t : ℝ} (hp : p ∈ Set.Ioo 0 1) + (ht : t ∈ Set.Icc 0 (1 / 4 : ℝ)) : + p * (1 - p) / 2 ≤ + (p * (1 - t) / (1 - p + p * (1 - t))) * + (1 - p * (1 - t) / (1 - p + p * (1 - t))) := by + have hA : 0 < 1 - p + p * (1 - t) := by + have := hp.1; have := hp.2; have := ht.2 + positivity [sub_pos.mpr hp.2, show (0 : ℝ) < 1 - t by linarith] + have hA1 : 1 - p + p * (1 - t) ≤ 1 := by nlinarith [mul_nonneg hp.1.le ht.1] + have hAsq : (1 - p + p * (1 - t)) ^ 2 ≤ 1 := by nlinarith + have hpq : 0 < p * (1 - p) := mul_pos hp.1 (sub_pos.mpr hp.2) + have heq : (p * (1 - t) / (1 - p + p * (1 - t))) * + (1 - p * (1 - t) / (1 - p + p * (1 - t))) = + p * (1 - p) * (1 - t) / (1 - p + p * (1 - t)) ^ 2 := by + field_simp; ring + rw [heq] + apply (le_div_iff₀ (sq_pos_of_pos hA)).mpr + have hh := mul_le_mul_of_nonneg_left hAsq hpq.le + nlinarith [ht.2] + +theorem binomial_tilt_normalizer (g h : ℕ) {p : ℝ} + (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hhg : h ≤ g) (hS : 0 < g + h) : + let t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) + ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ + Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by + dsimp only + set t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) with htdef + have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS + have hgr : (h : ℝ) ≤ g := by exact_mod_cast hhg + have hd : (0 : ℝ) ≤ (g : ℝ) - h := sub_nonneg.mpr hgr + have ht0 : 0 ≤ t := div_nonneg hd (by positivity) + have ht1 : t ≤ 1 / 4 := by + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr + nlinarith [show (0 : ℝ) ≤ h by positivity] + have htlt : 0 < 1 - t := by linarith + have hp0 : 0 < p := by linarith [hp.1] + have hA : 0 < 1 - p + p * (1 - t) := by positivity [sub_pos.mpr hp.2] + have hB : 0 < 1 - p + p / (1 - t) := by positivity [sub_pos.mpr hp.2] + have hlogA : Real.log (1 - p + p * (1 - t)) ≤ -p * t := by + have := Real.log_le_sub_one_of_pos hA + nlinarith only [this] + have hlogB : Real.log (1 - p + p / (1 - t)) ≤ p * t / (1 - t) := by + have := Real.log_le_sub_one_of_pos hB + have heq : 1 - p + p / (1 - t) - 1 = p * t / (1 - t) := by field_simp; ring + rwa [heq] at this + have hlog : Real.log ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ + -(p * ((g : ℝ) - h) * t) + 2 * p * h * t ^ 2 := by + rw [Real.log_mul (pow_pos hA _).ne' (pow_pos hB _).ne', Real.log_pow, Real.log_pow] + have hb : (h : ℝ) * (p * t / (1 - t)) ≤ (h : ℝ) * (p * t + 2 * p * t ^ 2) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply (div_le_iff₀ htlt).mpr + have hh := mul_nonneg (mul_nonneg hp0.le (sq_nonneg t)) (show 0 ≤ 1 - 2 * t by linarith) + nlinarith only [hh] + have ha := mul_le_mul_of_nonneg_left hlogA (show (0 : ℝ) ≤ g by positivity) + have hb' := mul_le_mul_of_nonneg_left hlogB (show (0 : ℝ) ≤ h by positivity) + linarith + have hht : 4 * (h : ℝ) * t ≤ (g : ℝ) - h := by + rw [htdef, ← mul_div_assoc] + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr + have hm := mul_nonneg (show (0 : ℝ) ≤ g by positivity) hd + nlinarith only [hm] + have hhalf : -(p * ((g : ℝ) - h) * t) + 2 * p * h * t ^ 2 ≤ + -(p * ((g : ℝ) - h) * t) / 2 := by + have hm := mul_le_mul_of_nonneg_right hht (mul_nonneg hp0.le ht0) + nlinarith only [hm] + have hlast : -(p * ((g : ℝ) - h) * t) / 2 ≤ + -((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h)) := by + rw [htdef] + apply (div_le_div_iff₀ (by norm_num : (0 : ℝ) < 2) (by positivity)).mpr + field_simp + have hm := mul_nonneg (show 0 ≤ 2 * p - 1 by linarith [hp.1]) (sq_nonneg ((g : ℝ) - h)) + nlinarith only [hm] + have hexp := Real.exp_le_exp.mpr (hlog.trans (hhalf.trans hlast)) + rwa [Real.exp_log (mul_pos (pow_pos hA _) (pow_pos hB _))] at hexp + + +/-- The Gaussian cross-overlap estimate used by the conditional rank-kernel +square-sum argument. The constant is absolute, also as p tends to one. -/ +theorem binomial_gaussian_overlap (g h : ℕ) {p : ℝ} + (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hhg : h ≤ g) (hS : 0 < g + h) : + (∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k) ≤ + Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * + Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by + let t : ℝ := ((g : ℝ) - h) / (4 * ((g : ℝ) + h)) + have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS + have hgr : (h : ℝ) ≤ g := by exact_mod_cast hhg + have ht0 : 0 ≤ t := div_nonneg (sub_nonneg.mpr hgr) (by positivity) + have ht1 : t ≤ 1 / 4 := by + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 4 * ((g : ℝ) + h))).mpr + nlinarith [show (0 : ℝ) ≤ h by positivity] + have htlt : 0 < 1 - t := by linarith + have hp0 : 0 < p := by linarith [hp.1] + have hp' : p ∈ Set.Ioo (0 : ℝ) 1 := ⟨hp0, hp.2⟩ + have hA : 0 < 1 - p + p * (1 - t) := by positivity [sub_pos.mpr hp.2] + have hB : 0 < 1 - p + p / (1 - t) := by positivity [sub_pos.mpr hp.2] + have hv := binomial_tilt_variance hp' ⟨ht0, ht1⟩ + have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) + have hx : 0 < (p * (1 - t) / (1 - p + p * (1 - t))) * + (1 - p * (1 - t) / (1 - p + p * (1 - t))) := lt_of_lt_of_le (by positivity) hv + have hb : biasedBinomialBound g (p * (1 - t) / (1 - p + p * (1 - t))) ≤ + Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) := by + apply Real.sqrt_le_sqrt + have hg : (0 : ℝ) < (g : ℝ) + 1 := by positivity + apply (div_le_div_iff₀ (by nlinarith only [mul_pos hg hx]) (by nlinarith only [mul_pos hg hpq])).mpr + have hm := mul_le_mul_of_nonneg_left hv hg.le + nlinarith only [hm] + have hn := binomial_tilt_normalizer g h hp hhg hS + change ((1 - p + p * (1 - t)) ^ g * (1 - p + p / (1 - t)) ^ h) ≤ _ at hn + have he := binomial_overlap_tilt_bound g h hp' htlt + apply he.trans + have hbound := mul_le_mul hn hb (Real.sqrt_nonneg _) (Real.exp_nonneg _) + simpa only [mul_comm] using hbound + + +theorem sqrt_times_gaussian_le {x : ℝ} (hx : 0 ≤ x) : + Real.sqrt (x + 1) * Real.exp (-x / 96) ≤ 16 := by + have he : Real.exp (-x / 96) ^ 2 = 1 / Real.exp (x / 48) := by + rw [pow_two, ← Real.exp_add] + rw [show -x / 96 + -x / 96 = -(x / 48) by ring, Real.exp_neg, one_div] + have hs : (Real.sqrt (x + 1) * Real.exp (-x / 96)) ^ 2 ≤ 256 := by + rw [mul_pow, Real.sq_sqrt (by linarith), he, mul_one_div] + apply (div_le_iff₀ (Real.exp_pos _)).mpr + have hh := Real.add_one_le_exp (x / 48) + nlinarith only [hh, hx] + nlinarith only [hs] + +theorem sqrt_recip_product_le {a b : ℝ} (ha : 0 < a) (hb : 0 < b) (hab : a ≤ 2 * b) : + Real.sqrt (1 / a) * Real.sqrt (1 / b) ≤ 2 / a := by + rw [← Real.sqrt_mul (by positivity), Real.sqrt_le_iff] + refine ⟨by positivity, ?_⟩ + rw [div_pow] + apply (le_div_iff₀ (sq_pos_of_pos ha)).mpr + field_simp + nlinarith + +theorem binomialMass_le_bound (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + binomialMass n p k ≤ biasedBinomialBound n p := by + have h := biasedSeries_coeff_bound n hp (k : ℤ) + rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg _ _ ⟨hp.1.le, hp.2.le⟩)] at h + exact h + +/-- A uniform product-supremum estimate, including very unequal trial +counts. This justifies eliminating a largest gap in the rank kernel. -/ +theorem binomial_product_sup (g h k : ℕ) {p : ℝ} + (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) : + binomialMass g p k * binomialMass h p k ≤ + 32 / (((g : ℝ) + 1) * p * (1 - p)) := by + have hp0 : 0 < p := by linarith [hp.1] + have hp' : p ∈ Set.Ioo (0 : ℝ) 1 := ⟨hp0, hp.2⟩ + have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) + have hpq1 : p * (1 - p) ≤ 1 := by nlinarith only [sq_nonneg (p - 1 / 2)] + have hden : 0 < ((g : ℝ) + 1) * p * (1 - p) := by nlinarith only [mul_pos (show (0 : ℝ) < (g : ℝ) + 1 by positivity) hpq] + by_cases hnear : g ≤ 2 * h + · have hdenh : 0 < ((h : ℝ) + 1) * p * (1 - p) := by nlinarith only [mul_pos (show (0 : ℝ) < (h : ℝ) + 1 by positivity) hpq] + have hgh : ((g : ℝ) + 1) * p * (1 - p) ≤ 2 * (((h : ℝ) + 1) * p * (1 - p)) := by + have hcast : (g : ℝ) ≤ 2 * h := by exact_mod_cast hnear + have hm := mul_le_mul_of_nonneg_right (show (g : ℝ) + 1 ≤ 2 * ((h : ℝ) + 1) by linarith) hpq.le + nlinarith only [hm] + calc + _ ≤ biasedBinomialBound g p * biasedBinomialBound h p := + mul_le_mul (binomialMass_le_bound g k hp') (binomialMass_le_bound h k hp') + (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) (Real.sqrt_nonneg _) + _ ≤ 2 / (((g : ℝ) + 1) * p * (1 - p)) := sqrt_recip_product_le hden hdenh hgh + _ ≤ _ := div_le_div_of_nonneg_right (by norm_num) hden.le + · by_cases hk : k ≤ h + · have hhg : h ≤ g := by omega + have hS : 0 < g + h := by omega + have hsum : binomialMass g p k * binomialMass h p k ≤ + ∑ j ∈ Finset.range (h + 1), binomialMass g p j * binomialMass h p j := by + exact Finset.single_le_sum (s := Finset.range (h + 1)) (a := k) (fun j _ => mul_nonneg + (binomialMass_nonneg g j ⟨hp0.le, hp.2.le⟩) + (binomialMass_nonneg h j ⟨hp0.le, hp.2.le⟩)) (Finset.mem_range.mpr (by omega)) + have hgauss := binomial_gaussian_overlap g h hp hhg hS + have hSr : (0 : ℝ) < (g : ℝ) + h := by exact_mod_cast hS + have hfar : 2 * (h : ℝ) < g := by exact_mod_cast (show 2 * h < g by omega) + have hexp : Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) ≤ Real.exp (-(g : ℝ) / 96) := by + apply Real.exp_le_exp.mpr + apply (div_le_div_iff₀ (by positivity : (0 : ℝ) < 16 * ((g : ℝ) + h)) (by norm_num : (0 : ℝ) < 96)).mpr + have hn := mul_nonneg (show 0 ≤ (g : ℝ) - 2 * h by linarith) (show 0 ≤ 5 * (g : ℝ) - 3 * h by linarith) + nlinarith only [hn, sq_nonneg (h : ℝ)] + have hcoeff : Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) ≤ + (2 / (((g : ℝ) + 1) * p * (1 - p))) * Real.sqrt ((g : ℝ) + 1) := by + rw [Real.sqrt_le_iff] + refine ⟨by positivity, ?_⟩ + rw [mul_pow, Real.sq_sqrt (by positivity), div_pow] + have hgpos : (0 : ℝ) < (g : ℝ) + 1 := by positivity + have hqpos : 0 < 1 - p := sub_pos.mpr hp.2 + field_simp + have hm := mul_le_mul_of_nonneg_left hpq1 (show (0 : ℝ) ≤ (g : ℝ) + 1 by positivity) + nlinarith only [hm, hpq1] + calc + _ ≤ Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * + Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := hsum.trans hgauss + _ ≤ ((2 / (((g : ℝ) + 1) * p * (1 - p))) * Real.sqrt ((g : ℝ) + 1)) * + Real.exp (-(g : ℝ) / 96) := mul_le_mul hcoeff hexp (Real.exp_nonneg _) (by positivity) + _ ≤ (2 / (((g : ℝ) + 1) * p * (1 - p))) * 16 := by + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (sqrt_times_gaussian_le (by positivity)) (by positivity) + _ = _ := by ring + · simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : h < k)] + positivity + +end TraceReconstruction + +namespace TraceReconstruction + +/-- Exact moment generating function, including both endpoint channels. -/ +theorem binomialMass_mgf (n : ℕ) (p t : ℝ) : + (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (t * k)) = + (1 - p + p * Real.exp t) ^ n := by + rw [add_comm (1 - p), add_pow] + apply Finset.sum_congr rfl + intro k _ + rw [show t * (k : ℝ) = (k : ℝ) * t by ring, Real.exp_nat_mul, mul_pow] + unfold binomialMass + ring + +theorem binomialMass_mgf_le (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) (t : ℝ) : + (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (t * k)) ≤ + Real.exp ((n : ℝ) * p * (Real.exp t - 1)) := by + rw [binomialMass_mgf] + have hn : 0 ≤ 1 - p + p * Real.exp t := by positivity [sub_nonneg.mpr hp.2, hp.1] + have he : 1 - p + p * Real.exp t ≤ Real.exp (p * (Real.exp t - 1)) := by + nlinarith only [Real.add_one_le_exp (p * (Real.exp t - 1))] + calc + _ ≤ Real.exp (p * (Real.exp t - 1)) ^ n := pow_le_pow_left₀ hn he n + _ = _ := by rw [← Real.exp_nat_mul]; congr 1; ring + +/-- Exponential Markov bound for a finite nonnegative measure. -/ +theorem finite_exp_markov {α : Type*} (S : Finset α) (w X : α → ℝ) + (hw : ∀ a ∈ S, 0 ≤ w a) (a t : ℝ) (ht : 0 ≤ t) : + (∑ z ∈ S with a ≤ X z, w z) ≤ + Real.exp (-t * a) * ∑ z ∈ S, w z * Real.exp (t * X z) := by + classical + calc + _ = ∑ z ∈ S with a ≤ X z, Real.exp (-t * a) * (w z * Real.exp (t * a)) := by + apply Finset.sum_congr rfl + intro z _ + rw [mul_left_comm, ← Real.exp_add] + simp + _ ≤ ∑ z ∈ S with a ≤ X z, Real.exp (-t * a) * (w z * Real.exp (t * X z)) := by + apply Finset.sum_le_sum + intro z hz + have h := Finset.mem_filter.mp hz + exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left h.2 ht)) (hw z h.1)) + (Real.exp_nonneg _) + _ ≤ ∑ z ∈ S, Real.exp (-t * a) * (w z * Real.exp (t * X z)) := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + intro z hz _ + positivity [hw z hz] + _ = _ := by rw [Finset.mul_sum] + +/-- A uniform multiplicative lower tail, sufficient for hidden-flag counts. -/ +theorem binomialMass_lower_half (n : ℕ) {p : ℝ} (hp : p ∈ Set.Icc 0 1) : + (∑ k ∈ (Finset.range (n + 1)).filter (fun k : ℕ => (k : ℝ) ≤ n * p / 2), + binomialMass n p k) ≤ Real.exp (-(n : ℝ) * p / 12) := by + have he : Real.exp (-(1 / 2 : ℝ)) ≤ 2 / 3 := by + rw [Real.exp_neg] + apply (inv_le_iff_one_le_mul₀ (Real.exp_pos _)).mpr + nlinarith only [Real.add_one_le_exp (1 / 2 : ℝ)] + have hmark := finite_exp_markov (Finset.range (n + 1)) (binomialMass n p) + (fun k => -(k : ℝ)) (fun k _ => binomialMass_nonneg n k hp) + (-(n : ℝ) * p / 2) (1 / 2) (by norm_num) + have hf : (Finset.range (n + 1)).filter (fun k : ℕ => -(n : ℝ) * p / 2 ≤ -(k : ℝ)) = + (Finset.range (n + 1)).filter (fun k : ℕ => (k : ℝ) ≤ n * p / 2) := by + ext k + simp only [Finset.mem_filter] + constructor <;> rintro ⟨h, h'⟩ <;> exact ⟨h, by linarith⟩ + rw [hf] at hmark + calc + _ ≤ Real.exp (-(1 / 2 : ℝ) * (-(n : ℝ) * p / 2)) * + (∑ k ∈ Finset.range (n + 1), binomialMass n p k * Real.exp (-(1 / 2 : ℝ) * k)) := by + convert hmark using 1 + congr 2 + funext k + congr 2 + ring + _ ≤ Real.exp (-(1 / 2 : ℝ) * (-(n : ℝ) * p / 2)) * + Real.exp ((n : ℝ) * p * (Real.exp (-(1 / 2 : ℝ)) - 1)) := by + gcongr + exact binomialMass_mgf_le n hp _ + _ = Real.exp ((n : ℝ) * p * (Real.exp (-(1 / 2 : ℝ)) - 3 / 4)) := by + rw [← Real.exp_add] + congr 1 + ring + _ ≤ _ := by + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left he (mul_nonneg (Nat.cast_nonneg n) hp.1)] + +end TraceReconstruction + +namespace TraceReconstruction +theorem fairBinomial_centered_mgf (n : ℕ) (t : ℝ) : + (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * + Real.exp (t * ((k : ℝ) - n / 2))) ≤ Real.exp ((n : ℝ) * t ^ 2 / 8) := by + have he : (1 / 2 : ℝ) + Real.exp t / 2 = Real.exp (t / 2) * Real.cosh (t / 2) := by + rw [Real.cosh_eq, ← mul_div_assoc, mul_add, ← Real.exp_add, ← Real.exp_add] + rw [show t / 2 + t / 2 = t by ring, show t / 2 + -(t / 2) = 0 by ring, Real.exp_zero] + ring + have hm : (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * + Real.exp (t * ((k : ℝ) - n / 2))) = + Real.exp (-t * n / 2) * (1 - 1 / 2 + (1 / 2) * Real.exp t) ^ n := by + rw [← binomialMass_mgf, Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + rw [mul_left_comm, ← Real.exp_add] + congr 2 + ring + rw [hm, show (1 - 1 / 2 + (1 / 2) * Real.exp t : ℝ) = 1 / 2 + Real.exp t / 2 by ring, he, mul_pow] + have hb : Real.cosh (t / 2) ^ n ≤ Real.exp (t ^ 2 / 8) ^ n := by + apply pow_le_pow_left₀ (le_of_lt (Real.cosh_pos _)) + convert Real.cosh_le_exp_half_sq (t / 2) using 1; congr 1; ring + calc + _ ≤ Real.exp (-t * n / 2) * (Real.exp (t / 2) ^ n * Real.exp (t ^ 2 / 8) ^ n) := by gcongr + _ = _ := by + simp only [← Real.exp_nat_mul, ← Real.exp_add] + congr 1 + ring + +theorem fairBinomial_upper_tail (n : ℕ) (hn : 0 < n) (a : ℝ) (ha : 0 ≤ a) : + (∑ k ∈ (Finset.range (n + 1)).filter (fun k : ℕ => a ≤ (k : ℝ) - n / 2), + binomialMass n (1 / 2) k) ≤ Real.exp (-2 * a ^ 2 / n) := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have h := finite_exp_markov (Finset.range (n + 1)) (binomialMass n (1 / 2)) + (fun k => (k : ℝ) - n / 2) (fun k _ => binomialMass_nonneg n k (by norm_num)) + a (4 * a / n) (by positivity) + calc + _ ≤ Real.exp (-(4 * a / n) * a) * + (∑ k ∈ Finset.range (n + 1), binomialMass n (1 / 2) k * + Real.exp ((4 * a / n) * ((k : ℝ) - n / 2))) := h + _ ≤ Real.exp (-(4 * a / n) * a) * Real.exp ((n : ℝ) * (4 * a / n) ^ 2 / 8) := by + gcongr + exact fairBinomial_centered_mgf n _ + _ = _ := by + rw [← Real.exp_add] + congr 1 + field_simp [ne_of_gt hnR] + ring +end TraceReconstruction + +namespace TraceReconstruction +def hypergeomMass (V M m v : ℕ) : ℝ := + if v ≤ m then (V.choose v : ℝ) * (M.choose (m-v) : ℝ) / ((V+M).choose m : ℝ) else 0 + +theorem hypergeomMass_nonneg (V M m v : ℕ) : 0 ≤ hypergeomMass V M m v := by + unfold hypergeomMass + split <;> positivity + +theorem hypergeomMass_eq_binomial (V M m v : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioo 0 1) (hm : m ≤ V+M) (hv : v ≤ m) : + hypergeomMass V M m v = binomialMass V p v * binomialMass M p (m-v) / + binomialMass (V+M) p m := by + unfold hypergeomMass + rw [ite_eq_left hv] + by_cases hvV : v ≤ V + · by_cases hkM : m-v ≤ M + · unfold binomialMass + have hc : (0 : ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hm + have hp1 := hp.1 + have hq1 := sub_pos.mpr hp.2 + have he : V-v+(M-(m-v)) = V+M-m := by omega + have he' : v+(m-v) = m := by omega + apply (div_eq_div_iff (ne_of_gt hc) (by positivity)).mpr + calc + _ = ((V.choose v : ℝ) * (M.choose (m-v) : ℝ) * ((V+M).choose m : ℝ)) * + (p^m * (1-p)^(V+M-m)) := by ring + _ = _ := by + rw [show p^m = p^v * p^(m-v) by rw [← pow_add, he'], + show (1-p)^(V+M-m) = (1-p)^(V-v)*(1-p)^(M-(m-v)) by rw [← pow_add, he]] + ring + · rw [Nat.choose_eq_zero_of_lt (by omega : M < m-v)] + simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : M < m-v)] + · rw [Nat.choose_eq_zero_of_lt (by omega : V < v)] + simp [binomialMass, Nat.choose_eq_zero_of_lt (by omega : V < v)] + +theorem binomialMass_sq_upper (n k : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + binomialMass n p k ^ 2 ≤ 1 / (((n : ℝ)+1)*p*(1-p)) := by + have hp1 := hp.1 + have hq1 := sub_pos.mpr hp.2 + have h := biasedSeries_coeff_bound n hp (k : ℤ) + rw [biasedSeries_coeff_nat, abs_of_nonneg (binomialMass_nonneg n k ⟨hp.1.le,hp.2.le⟩)] at h + have hs := sq_le_sq₀ (binomialMass_nonneg n k ⟨hp.1.le,hp.2.le⟩) + (Real.sqrt_nonneg _) |>.mpr h + rwa [Real.sq_sqrt (by positivity)] at hs + +theorem hypergeomMass_sq_upper (V M m v : ℕ) {p : ℝ} + (hp : p ∈ Set.Ioo 0 1) (hm : m ≤ V+M) (hmean : (m : ℝ) = (V+M : ℕ)*p) + (hvar : 1 ≤ (V+M : ℕ)*p*(1-p)) : + hypergeomMass V M m v ^ 2 ≤ + 144 * (V+M : ℕ) / (((V : ℝ)+1)*((M : ℝ)+1)*p*(1-p)) := by + have hp1 := hp.1 + have hq1 := sub_pos.mpr hp.2 + by_cases hv : v ≤ m + · rw [hypergeomMass_eq_binomial V M m v hp hm hv, div_eq_mul_inv, mul_pow, mul_pow] + have hV := binomialMass_sq_upper V v hp + have hM := binomialMass_sq_upper M (m-v) hp + have hN := binomialMass_mean_inverse_sq (V+M) m hp hm hmean.symm hvar + have hvm := mul_le_mul hV hM (sq_nonneg _) (by positivity) + have h := mul_le_mul hvm hN (sq_nonneg _) (by positivity) + apply h.trans + have hp0 : p ≠ 0 := ne_of_gt hp.1 + have hq0 : 1-p ≠ 0 := ne_of_gt (sub_pos.mpr hp.2) + have hV0 : (V : ℝ)+1 ≠ 0 := by positivity + have hM0 : (M : ℝ)+1 ≠ 0 := by positivity + apply le_of_eq + field_simp + · simp only [hypergeomMass, ite_eq_right hv, zero_pow (by decide : 2 ≠ 0)] + positivity + +theorem sum_hypergeomMass (V M m : ℕ) (hm : m ≤ V+M) : + ∑ v ∈ Finset.range (m+1), hypergeomMass V M m v = 1 := by + have hc : (0 : ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hm + have hv := Nat.add_choose_eq V M m + rw [Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk] at hv + simp only [hypergeomMass] + have he : (∑ v ∈ Finset.range (m+1), + if v ≤ m then (V.choose v : ℝ)*(M.choose (m-v) : ℝ)/((V+M).choose m : ℝ) else 0) = + (∑ v ∈ Finset.range (m+1), (V.choose v : ℝ)*(M.choose (m-v) : ℝ))/((V+M).choose m : ℝ) := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro v hv' + rw [ite_eq_left (by simp only [Finset.mem_range] at hv'; omega)] + rw [he] + have he' : (∑ v ∈ Finset.range (m+1), (V.choose v : ℝ)*(M.choose (m-v) : ℝ)) = + ((V+M).choose m : ℝ) := by exact_mod_cast hv.symm + rw [he', div_self (ne_of_gt hc)] + +theorem hypergeomMass_high (V M m v : ℕ) (hv : V < v) : hypergeomMass V M m v = 0 := by + unfold hypergeomMass + rw [Nat.choose_eq_zero_of_lt hv] + simp + +/-- Adjacent-mass identity for the hidden count. The central regime has full support +on 0,...,M; this is exactly the regime used in adjacent-power lifting. -/ +theorem hypergeom_hidden_adjacent (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) (hk : k < M) : + (((k:ℝ)+1)*((V:ℝ)-m+k+1)) * hypergeomMass M V m (k+1) = + (((M:ℝ)-k)*((m:ℝ)-k)) * hypergeomMass M V m k := by + have hkM : k ≤ M := by omega + have hkm : k ≤ m := by omega + have hkm' : k+1 ≤ m := by omega + have hv : m-(k+1) ≤ V := by omega + have h1 := Nat.choose_succ_right_eq M k + have h2 := Nat.choose_succ_right_eq V (m-(k+1)) + rw [show m-(k+1)+1=m-k by omega] at h2 + have h1' : (M.choose (k+1):ℝ)*((k:ℝ)+1) = (M.choose k:ℝ)*((M:ℝ)-k) := by + exact_mod_cast h1 + have h2' : (V.choose (m-k):ℝ)*((m:ℝ)-k) = + (V.choose (m-(k+1)):ℝ)*((V:ℝ)-m+k+1) := by + have hvsub : V-(m-(k+1)) = V-m+k+1 := by omega + rw [hvsub] at h2 + exact_mod_cast h2 + unfold hypergeomMass + rw [ite_eq_left hkm', ite_eq_left hkm] + have hmul := congrArg (fun z : ℝ => z*(V.choose (m-(k+1)) : ℝ)*((V:ℝ)-m+k+1)) h1' + have hmul' := congrArg (fun z : ℝ => z*(M.choose k : ℝ)*((M:ℝ)-k)) h2' + have he : (((k:ℝ)+1)*((V:ℝ)-m+k+1)) * + ((M.choose (k+1):ℝ)*(V.choose (m-(k+1)):ℝ)) = + (((M:ℝ)-k)*((m:ℝ)-k))*((M.choose k:ℝ)*(V.choose (m-k):ℝ)) := by + nlinarith only [hmul, hmul'] + simpa only [mul_div_assoc] using congrArg (fun z : ℝ => z/((M+V).choose m:ℝ)) he + +def hypergeomHiddenMode (V M m : ℕ) : ℕ := (M+1)*(m+1)/(V+M+2) + +theorem hypergeomHiddenMode_le (V M m : ℕ) (hV : m ≤ V) : + hypergeomHiddenMode V M m ≤ M := by + unfold hypergeomHiddenMode + have h1 : (M+1)*(m+1) < (M+1)*(V+M+2) := Nat.mul_lt_mul_of_pos_left (by omega) (by omega) + have hh : (M+1)*(m+1)/(V+M+2) < M+1 := by + apply (Nat.div_lt_iff_lt_mul (by omega)).mpr + exact h1 + omega + +theorem hypergeom_hidden_unimodal_left (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) + (hk : k < hypergeomHiddenMode V M m) : + hypergeomMass M V m k ≤ hypergeomMass M V m (k+1) := by + have hl := hypergeomHiddenMode_le V M m hV + have hkM : k < M := by omega + have hrec := hypergeom_hidden_adjacent V M m k hM hV hkM + have hc : (k+1)*(V+M+2) ≤ (M+1)*(m+1) := by + have hh : k+1 ≤ (M+1)*(m+1)/(V+M+2) := hk + exact (Nat.le_div_iff_mul_le (by omega)).mp hh + have hc' : ((k:ℝ)+1)*((V:ℝ)+M+2) ≤ ((M:ℝ)+1)*((m:ℝ)+1) := by exact_mod_cast hc + have hh : ((k:ℝ)+1)*((V:ℝ)-m+k+1) ≤ ((M:ℝ)-k)*((m:ℝ)-k) := by nlinarith + have hm := mul_le_mul_of_nonneg_right hh (hypergeomMass_nonneg M V m k) + have hV' : (m:ℝ) ≤ V := by exact_mod_cast hV + have ha : 0 < ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by positivity + exact (mul_le_mul_iff_right₀ ha).mp (by nlinarith only [hm, hrec]) + +theorem hypergeom_hidden_unimodal_right (V M m k : ℕ) (hM : M ≤ m) (hV : m ≤ V) + (hk : hypergeomHiddenMode V M m ≤ k) : + hypergeomMass M V m (k+1) ≤ hypergeomMass M V m k := by + by_cases hkM : k < M + · have hrec := hypergeom_hidden_adjacent V M m k hM hV hkM + have hc : (M+1)*(m+1) < (k+1)*(V+M+2) := by + apply (Nat.div_lt_iff_lt_mul (by omega)).mp + exact Nat.lt_succ_of_le hk + have hc' : ((M:ℝ)+1)*((m:ℝ)+1) < ((k:ℝ)+1)*((V:ℝ)+M+2) := by exact_mod_cast hc + have hh : ((M:ℝ)-k)*((m:ℝ)-k) ≤ ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by nlinarith + have hm := mul_le_mul_of_nonneg_right hh (hypergeomMass_nonneg M V m k) + have hV' : (m:ℝ) ≤ V := by exact_mod_cast hV + have ha : 0 < ((k:ℝ)+1)*((V:ℝ)-m+k+1) := by positivity + exact (mul_le_mul_iff_right₀ ha).mp (by nlinarith only [hm, hrec]) + · rw [hypergeomMass_high M V m (k+1) (by omega)] + exact hypergeomMass_nonneg M V m k + +/-- Exact total variation of a zero-extended unimodal sequence. -/ +theorem unimodal_variation (f : ℕ → ℝ) (n l : ℕ) (hl : l ≤ n+1) + (hleft : ∀ k < l, f k ≤ f (k+1)) + (hright : ∀ k, l ≤ k → f (k+1) ≤ f k) (hz : f (n+1)=0) : + f 0 + ∑ k ∈ Finset.range (n+1), |f (k+1)-f k| = 2*f l := by + rw [← Finset.sum_range_add_sum_Ico _ hl] + have h1 : (∑ k ∈ Finset.range l, |f (k+1)-f k|) = f l-f 0 := by + rw [← Finset.sum_range_sub f l] + apply Finset.sum_congr rfl + intro k hk + exact abs_of_nonneg (sub_nonneg.mpr (hleft k (Finset.mem_range.mp hk))) + have h2 : (∑ k ∈ Finset.Ico l (n+1), |f (k+1)-f k|) = f l-f (n+1) := by + calc + _ = ∑ k ∈ Finset.Ico l (n+1), -(f (k+1)-f k) := by + apply Finset.sum_congr rfl + intro k hk + exact abs_of_nonpos (sub_nonpos.mpr (hright k (Finset.mem_Ico.mp hk).1)) + _ = _ := by rw [Finset.sum_neg_distrib, Finset.sum_Ico_sub _ hl]; ring + rw [h1,h2,hz] + ring + +theorem hypergeom_hidden_variation (V M m : ℕ) (hM : M ≤ m) (hV : m ≤ V) : + hypergeomMass M V m 0 + + ∑ k ∈ Finset.range (M+1), |hypergeomMass M V m (k+1)-hypergeomMass M V m k| = + 2*hypergeomMass M V m (hypergeomHiddenMode V M m) := by + apply unimodal_variation _ M (hypergeomHiddenMode V M m) + ((hypergeomHiddenMode_le V M m hV).trans (by omega)) + (fun k hk => hypergeom_hidden_unimodal_left V M m k hM hV hk) + (fun k hk => hypergeom_hidden_unimodal_right V M m k hM hV hk) + exact hypergeomMass_high M V m (M+1) (by omega) +theorem choose_pred_weight (n r : ℕ) (hn : 0 < n) (hr : r ≤ n) : + (n:ℝ)*((n-1).choose r : ℝ) = ((n:ℝ)-r)*(n.choose r : ℝ) := by + have h := Nat.choose_mul_succ_eq (n-1) r + rw [Nat.sub_add_cancel hn] at h + have h' : ((n-1).choose r : ℝ)*(n:ℝ) = (n.choose r : ℝ)*((n:ℝ)-r) := by + exact_mod_cast h + nlinarith only [h'] + +theorem choose_pred_weight_succ (n r : ℕ) (hn : 0 < n) : + (n:ℝ)*((n-1).choose r : ℝ) = ((r:ℝ)+1)*(n.choose (r+1) : ℝ) := by + have h := Nat.add_one_mul_choose_eq (n-1) r + rw [Nat.sub_add_cancel hn] at h + exact_mod_cast h.trans (Nat.mul_comm _ _) + +def hypergeomHiddenFlux (V M m k : ℕ) : ℝ := + (V:ℝ)/(V+M)*hypergeomMass M (V-1) m k + +theorem hypergeomHiddenFlux_formula (V M m k : ℕ) (hM : M ≤ m) (hV : m < V) (hk : k ≤ M) : + hypergeomHiddenFlux V M m k = + ((V:ℝ)-m+k)/((V:ℝ)+M-m)*hypergeomMass M V m k := by + have hN : 0 < V+M := by omega + have hk' : k ≤ m := by omega + have hr : m-k ≤ V := by omega + have hmN : m ≤ V+M := by omega + have hpred : m ≤ V+M-1 := by omega + have hVN : (0:ℝ) < V+M := by exact_mod_cast hN + have hd : (0:ℝ) < (V:ℝ)+M-m := by + have hr : (m:ℝ) < (V:ℝ)+M := by exact_mod_cast (show m < V+M by omega) + linarith + have hCN : (0:ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hmN + have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos hpred + have hcw := choose_pred_weight (V+M) m hN hmN + have hcv := choose_pred_weight V (m-k) (by omega) hr + push_cast [Nat.cast_sub hk'] at hcv + push_cast at hcw + unfold hypergeomHiddenFlux hypergeomMass + rw [ite_eq_left hk', ite_eq_left hk', show M+(V-1)=V+M-1 by omega] + have hden : ((V:ℝ)+M)*((V+M-1).choose m:ℝ) = + ((V:ℝ)+M-m)*((V+M).choose m:ℝ) := hcw + rw [show M+V=V+M by omega] + calc + _ = (M.choose k:ℝ)*((V:ℝ)*((V-1).choose (m-k):ℝ)) / + (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by field_simp + _ = _ := by rw [hden, hcv]; field_simp; ring + +theorem hypergeomHiddenFlux_high (V M m k : ℕ) (hk : M < k) : + hypergeomHiddenFlux V M m k = 0 := by + simp only [hypergeomHiddenFlux, hypergeomMass_high M (V-1) m k hk, mul_zero] + +theorem hypergeomHiddenFlux_boundary (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : + hypergeomHiddenFlux V M m M = hypergeomMass M V m M := by + rw [hypergeomHiddenFlux_formula V M m M hM hV le_rfl] + have hd : (0:ℝ) < (V:ℝ)+M-m := by + have hr : (m:ℝ) < (V:ℝ)+M := by exact_mod_cast (show m < V+M by omega) + linarith + have he : (V:ℝ)-m+M = (V:ℝ)+M-m := by ring + rw [he, div_self hd.ne', one_mul] + +theorem hypergeom_adjacent_hidden_difference (V M m k : ℕ) + (hM : M ≤ m) (hV : m < V) (hk : k ≤ M) : + hypergeomMass M V (m+1) (k+1) - hypergeomMass M V m k = + hypergeomHiddenFlux V M m (k+1) - hypergeomHiddenFlux V M m k := by + by_cases hkM : k = M + · subst k + rw [hypergeomMass_high M V (m+1) (M+1) (by omega), + hypergeomHiddenFlux_high V M m (M+1) (by omega), hypergeomHiddenFlux_boundary V M m hM hV] + have hklt : k < M := by omega + have hkm : k+1 ≤ m := by omega + have hkm' : k ≤ m := by omega + have hN : 0 < V+M := by omega + have hmN : m ≤ V+M := by omega + have hmN' : m+1 ≤ V+M := by omega + have hpred : m ≤ V+M-1 := by omega + have hN0 : (0:ℝ) < (V:ℝ)+M := by exact_mod_cast hN + have hCN : (0:ℝ) < (V+M).choose m := by exact_mod_cast Nat.choose_pos hmN + have hCN' : (0:ℝ) < (V+M).choose (m+1) := by exact_mod_cast Nat.choose_pos hmN' + have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos hpred + have hcw := choose_pred_weight (V+M) m hN hmN + have hcws := choose_pred_weight_succ (V+M) m hN + have hcv := choose_pred_weight V (m-k) (by omega) (by omega) + have hcvs := choose_pred_weight_succ V (m-(k+1)) (by omega) + rw [show m-(k+1)+1=m-k by omega] at hcvs + have hMrec := Nat.choose_succ_right_eq M k + have hMrec' : (M.choose (k+1):ℝ)*((k:ℝ)+1) = (M.choose k:ℝ)*((M:ℝ)-k) := by + exact_mod_cast hMrec + push_cast at hcw hcws + push_cast [Nat.cast_sub hkm'] at hcv + push_cast [Nat.cast_sub hkm] at hcvs + unfold hypergeomHiddenFlux hypergeomMass + rw [ite_eq_left (by omega : k+1 ≤ m+1), ite_eq_left hkm', ite_eq_left hkm, ite_eq_left hkm', + show m+1-(k+1)=m-k by omega, show M+V=V+M by omega, + show M+(V-1)=V+M-1 by omega] + have hpold : (M.choose k:ℝ)*(V.choose (m-k):ℝ)/( (V+M).choose m:ℝ) = + ((V:ℝ)+M-m)*(M.choose k:ℝ)*(V.choose (m-k):ℝ) / + (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by + apply (div_eq_div_iff hCN.ne' (mul_pos hN0 hCP).ne').mpr + rw [hcw]; ring + have hpnew : (M.choose (k+1):ℝ)*(V.choose (m-k):ℝ)/( (V+M).choose (m+1):ℝ) = + ((m:ℝ)+1)*(M.choose (k+1):ℝ)*(V.choose (m-k):ℝ) / + (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by + apply (div_eq_div_iff hCN'.ne' (mul_pos hN0 hCP).ne').mpr + rw [hcws]; ring + rw [hpold,hpnew] + have hF (j : ℕ) : (V:ℝ)/((V:ℝ)+M)*((M.choose j:ℝ)*((V-1).choose (m-j):ℝ)/ + ((V+M-1).choose m:ℝ)) = (M.choose j:ℝ)*((V:ℝ)*((V-1).choose (m-j):ℝ)) / + (((V:ℝ)+M)*((V+M-1).choose m:ℝ)) := by field_simp + rw [hF, hF, hcv, hcvs] + rw [← sub_div, ← sub_div] + congr 1 + have hh := congrArg (fun z : ℝ => z*(V.choose (m-k):ℝ)) hMrec' + nlinarith only [hh] + + +theorem hypergeom_next_zero (V M m : ℕ) (hV : m < V) : + hypergeomMass M V (m+1) 0 = hypergeomHiddenFlux V M m 0 := by + have hN : 0 < V+M := by omega + have hN0 : (0:ℝ) < (V:ℝ)+M := by exact_mod_cast hN + have hCN : (0:ℝ) < (V+M).choose (m+1) := by exact_mod_cast Nat.choose_pos (show m+1 ≤ V+M by omega) + have hCP : (0:ℝ) < (V+M-1).choose m := by exact_mod_cast Nat.choose_pos (show m ≤ V+M-1 by omega) + have hcw := choose_pred_weight_succ (V+M) m hN + have hcv := choose_pred_weight_succ V m (by omega) + push_cast at hcw hcv + unfold hypergeomHiddenFlux hypergeomMass + simp only [Nat.zero_le, ite_true, Nat.choose_zero_right, Nat.sub_zero, Nat.cast_one, one_mul] + rw [show M+V=V+M by omega, show M+(V-1)=V+M-1 by omega] + rw [div_mul_div_comm] + apply (div_eq_div_iff hCN.ne' (mul_pos hN0 hCP).ne').mpr + have hh := congrArg (fun z : ℝ => z*(V.choose (m+1):ℝ)) hcw + have hh' := congrArg (fun z : ℝ => z*((V+M).choose (m+1):ℝ)) hcv + nlinarith only [hh,hh'] + +/-- Exact adjacent visible-count TV, expressed with complementary hidden counts. +The shift by one is essential: the two totals are different. -/ +def adjacentHypergeomTV (V M m : ℕ) : ℝ := + (1/2:ℝ)*(hypergeomMass M V (m+1) 0 + + ∑ k ∈ Finset.range (M+1), |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k|) + +theorem adjacentHypergeomTV_eq_flux (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : + adjacentHypergeomTV V M m = + hypergeomHiddenFlux V M m (hypergeomHiddenMode (V-1) M m) := by + unfold adjacentHypergeomTV + rw [hypergeom_next_zero V M m hV] + have he : (∑ k ∈ Finset.range (M+1), + |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k|) = + ∑ k ∈ Finset.range (M+1), |hypergeomHiddenFlux V M m (k+1)-hypergeomHiddenFlux V M m k| := by + apply Finset.sum_congr rfl + intro k hk + rw [hypergeom_adjacent_hidden_difference V M m k hM hV (by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hk)] + rw [he] + unfold hypergeomHiddenFlux + simp_rw [← mul_sub, abs_mul, abs_of_nonneg (by positivity : (0:ℝ) ≤ (V:ℝ)/(V+M))] + rw [← Finset.mul_sum, ← mul_add, hypergeom_hidden_variation (V-1) M m hM (by omega)] + ring + +theorem adjacentHypergeomTV_le_mass (V M m : ℕ) (hM : M ≤ m) (hV : m < V) : + adjacentHypergeomTV V M m ≤ hypergeomMass M V m (hypergeomHiddenMode (V-1) M m) := by + rw [adjacentHypergeomTV_eq_flux V M m hM hV, + hypergeomHiddenFlux_formula V M m _ hM hV (hypergeomHiddenMode_le (V-1) M m (by omega))] + have hk := hypergeomHiddenMode_le (V-1) M m (by omega : m ≤ V-1) + have hk' : (hypergeomHiddenMode (V-1) M m:ℝ) ≤ M := by exact_mod_cast hk + have hm' : (m:ℝ) < V := by exact_mod_cast hV + have hd : (0:ℝ) < (V:ℝ)+M-m := by linarith [Nat.cast_nonneg (α := ℝ) M] + apply mul_le_of_le_one_left (hypergeomMass_nonneg _ _ _ _) + apply (div_le_one hd).mpr + linarith + +end TraceReconstruction + +namespace TraceReconstruction +def bernoulliRelativeEntropy (θ p : ℝ) : ℝ := + θ*Real.log (θ/p)+(1-θ)*Real.log ((1-θ)/(1-p)) + +theorem bernoulliRelativeEntropy_upper {θ p : ℝ} + (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : + bernoulliRelativeEntropy θ p ≤ (θ-p)^2/(p*(1-p)) := by + have h1 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos (div_pos hθ.1 hp.1)) hθ.1.le + have h2 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos + (div_pos (sub_pos.mpr hθ.2) (sub_pos.mpr hp.2))) (sub_nonneg.mpr hθ.2.le) + have he : θ*(θ/p-1)+(1-θ)*((1-θ)/(1-p)-1) = (θ-p)^2/(p*(1-p)) := by + field_simp [hp.1.ne', (sub_pos.mpr hp.2).ne']; ring + unfold bernoulliRelativeEntropy + rw [← he] + linarith + +theorem binomialMass_change_probability (n k : ℕ) {θ p : ℝ} + (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : + binomialMass n p k = binomialMass n θ k * + Real.exp ((k:ℝ)*Real.log (p/θ)+(n-k:ℕ)*Real.log ((1-p)/(1-θ))) := by + rw [Real.exp_add, Real.exp_nat_mul, Real.exp_nat_mul, + Real.exp_log (div_pos hp.1 hθ.1), + Real.exp_log (div_pos (sub_pos.mpr hp.2) (sub_pos.mpr hθ.2))] + unfold binomialMass + simp only [div_pow] + field_simp [hθ.1.ne', (sub_pos.mpr hθ.2).ne'] + +theorem binomialMass_mean_change_probability (n k : ℕ) {θ p : ℝ} + (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) + (hk : k ≤ n) (hmean : (n:ℝ)*θ = k) : + binomialMass n p k = binomialMass n θ k * Real.exp (-(n:ℝ)*bernoulliRelativeEntropy θ p) := by + rw [binomialMass_change_probability n k hθ hp] + congr 2 + rw [Nat.cast_sub hk, ← hmean] + unfold bernoulliRelativeEntropy + rw [Real.log_div hp.1.ne' hθ.1.ne', Real.log_div (sub_pos.mpr hp.2).ne' (sub_pos.mpr hθ.2).ne', + Real.log_div hθ.1.ne' hp.1.ne', Real.log_div (sub_pos.mpr hθ.2).ne' (sub_pos.mpr hp.2).ne'] + ring + +/-- Uniform local binomial lower bound without Stirling. It applies at a +count `k` by changing to the channel with mean exactly `k`. -/ +theorem binomialMass_local_lower (n k : ℕ) {θ p : ℝ} + (hθ : θ ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) + (hk : k ≤ n) (hmean : (n:ℝ)*θ = k) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) : + Real.exp (-(n:ℝ)*(θ-p)^2/(p*(1-p))) / + (12*Real.sqrt ((n:ℝ)*θ*(1-θ))) ≤ binomialMass n p k := by + rw [binomialMass_mean_change_probability n k hθ hp hk hmean] + have hlow := binomialMass_mean_lower n k hθ hk hmean hv + have hexp : Real.exp (-(n:ℝ)*(θ-p)^2/(p*(1-p))) ≤ + Real.exp (-(n:ℝ)*bernoulliRelativeEntropy θ p) := by + apply Real.exp_le_exp.mpr + have := mul_le_mul_of_nonpos_left (bernoulliRelativeEntropy_upper hθ hp) (neg_nonpos.mpr (Nat.cast_nonneg n)) + simpa only [mul_div_assoc] using this + have hh := mul_le_mul hlow hexp (Real.exp_pos _).le + (binomialMass_nonneg n k ⟨hθ.1.le,hθ.2.le⟩) + simpa only [one_div, div_eq_mul_inv, mul_comm, one_mul] using hh + +end TraceReconstruction + +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Differences.lean b/lean/OAI/Probability/TraceReconstruction/Differences.lean index ef019921e16e82b37a4a64b1061cf0c315ce9155..f405c02734a7fd98aa9701bbe01582ae8fcbfffb 100644 --- a/lean/OAI/Probability/TraceReconstruction/Differences.lean +++ b/lean/OAI/Probability/TraceReconstruction/Differences.lean @@ -1,2475 +1,2475 @@ -import OAI.Probability.TraceReconstruction.Model -import OAI.Probability.TraceReconstruction.Parity -import OAI.Probability.TraceReconstruction.Ranks - -namespace OAI - -/-! -# Differences - -Tensor gap differences, positional shifts, two-gap elimination, central clipping, disjoint rank regions, and weighted period sums. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - -namespace TraceReconstruction - -/-- Forward length differences of the actual binomial probability -polynomial, before imposing the conditional rank total. -/ -def binomialLengthDifference (g s : ℕ) (p : ℝ) : IntSeries := - (biasedSeries 1 p - 1)^s * biasedSeries g p - -/-- Increasing the number of trials corresponds exactly to multiplying -by the Bernoulli step polynomial. -/ -theorem binomialLengthDifference_succ (g s : ℕ) (p : ℝ) : - binomialLengthDifference g (s+1) p = - binomialLengthDifference (g+1) s p - binomialLengthDifference g s p := by - unfold binomialLengthDifference - rw [biasedSeries_add] - ring - -theorem biasedSeries_step_sub_one (p : ℝ) : - biasedSeries 1 p - 1 = (-p) • firstDifference := by - unfold biasedSeries firstDifference - rw [pow_one,smul_sub,AddMonoidAlgebra.smul_single,AddMonoidAlgebra.smul_single] - simp only [smul_eq_mul,mul_one] - have h1 : (1 : IntSeries) = AddMonoidAlgebra.single 0 1 := rfl - rw [h1] - simp only [AddMonoidAlgebra.single_sub] - ext z - simp only [AddMonoidAlgebra.coeff_sub,AddMonoidAlgebra.coeff_add, - Finsupp.sub_apply,Finsupp.add_apply,AddMonoidAlgebra.coeff_single,Finsupp.single_apply] - split_ifs <;> ring - -theorem binomialLengthDifference_eq (g s : ℕ) (p : ℝ) : - binomialLengthDifference g s p = - (-p)^s • (firstDifference^s * biasedSeries g p) := by - unfold binomialLengthDifference - rw [biasedSeries_step_sub_one,smul_pow,smul_mul_assoc] - -theorem seriesL2Sq_smul (c : ℝ) (f : IntSeries) : - seriesL2Sq (c • f) = c^2 * seriesL2Sq f := by - unfold seriesL2Sq - simp only [AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,mul_pow] - exact tsum_mul_left - -/-- Pointwise and square-sum bounds for every forward length difference. -The quotient form keeps every order and every channel factor explicit. -/ -theorem binomialLengthDifference_bounds (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - (∀ z : ℤ, |(binomialLengthDifference g s p).coeff z| ≤ - (2*biasedBinomialBound (g/(s+1)) p)^s * biasedBinomialBound (g/(s+1)) p) ∧ - (seriesL2Sq (binomialLengthDifference g s p) ≤ - ((2*biasedBinomialBound (g/(s+1)) p)^s)^2 * biasedBinomialBound (g/(s+1)) p) := by - have hpow : |(-p)^s| ≤ 1 := by - rw [abs_pow,abs_neg,abs_of_pos hp.1] - exact pow_le_one₀ hp.1.le hp.2.le - have hs := biased_difference_smoothing g s hp - rw [binomialLengthDifference_eq] - constructor - · intro z - simp only [AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,abs_mul] - exact (mul_le_mul_of_nonneg_right hpow (abs_nonneg _)).trans (by simpa using hs.1 z) - · rw [seriesL2Sq_smul] - have h : ((-p)^s) ^ 2 ≤ 1 := by nlinarith [sq_abs ((-p)^s),abs_nonneg ((-p)^s)] - exact (mul_le_mul_of_nonneg_right h (seriesL2Sq_nonneg _)).trans (by simpa using hs.2) - -/-- Explicit fixed-order smoothing constant; no asymptotic hypothesis is hidden. -/ -def lengthDifferenceConstant (s : ℕ) (p : ℝ) : ℝ := - 2 * Real.sqrt (((s:ℝ)+1)/(p*(1-p))) - -theorem lengthDifferenceConstant_pos (s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - 0 < lengthDifferenceConstant s p := by - unfold lengthDifferenceConstant - positivity [hp.1,sub_pos.mpr hp.2] - -theorem biasedBinomialBound_length_le (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - 2*biasedBinomialBound (g/(s+1)) p ≤ - lengthDifferenceConstant s p / Real.sqrt ((g:ℝ)+1) := by - calc - _ ≤ 2*Real.sqrt (((s:ℝ)+1)/(((g:ℝ)+1)*p*(1-p))) := - mul_le_mul_of_nonneg_left (biasedBinomialBound_quotient_le g s hp) (by norm_num) - _ = _ := by - unfold lengthDifferenceConstant - rw [show ((s:ℝ)+1)/(((g:ℝ)+1)*p*(1-p)) = - (((s:ℝ)+1)/(p*(1-p)))/((g:ℝ)+1) by field_simp] - rw [Real.sqrt_div (by positivity [hp.1,sub_pos.mpr hp.2])] - ring - -/-- Squared supremum and squared L2 smoothing estimates in a form suitable -for exact constrained rank profiles. -/ -theorem binomialLengthDifference_numeric (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - (∀ z : ℤ, (binomialLengthDifference g s p).coeff z ^ 2 ≤ - (lengthDifferenceConstant s p)^(2*s+2) / ((g:ℝ)+1)^(s+1)) ∧ - (seriesL2Sq (binomialLengthDifference g s p) ≤ - (lengthDifferenceConstant s p)^(2*s+1) / - (((g:ℝ)+1)^s * Real.sqrt ((g:ℝ)+1))) := by - have hb := binomialLengthDifference_bounds g s hp - have hc := biasedBinomialBound_length_le g s hp - have hB : 0 ≤ biasedBinomialBound (g/(s+1)) p := Real.sqrt_nonneg _ - have hC : 0 < lengthDifferenceConstant s p := lengthDifferenceConstant_pos s hp - have hg : 0 < Real.sqrt ((g:ℝ)+1) := Real.sqrt_pos.mpr (by positivity) - have hB' : biasedBinomialBound (g/(s+1)) p ≤ - lengthDifferenceConstant s p / Real.sqrt ((g:ℝ)+1) := by linarith - have hs := pow_le_pow_left₀ (by positivity : 0 ≤ 2*biasedBinomialBound (g/(s+1)) p) hc s - constructor - · intro z - have h := (hb.1 z).trans (mul_le_mul hs hB' hB (by positivity)) - rw [← pow_succ] at h - have hsq := pow_le_pow_left₀ (abs_nonneg _) h 2 - rw [sq_abs] at hsq - refine hsq.trans_eq ?_ - rw [← pow_mul,div_pow] - have he : (s+1)*2=2*s+2 := by omega - rw [he] - congr 1 - rw [show 2*s+2=2*(s+1) by omega,pow_mul,Real.sq_sqrt (by positivity)] - · have hsq := pow_le_pow_left₀ (by positivity : - 0 ≤ (2*biasedBinomialBound (g/(s+1)) p)^s) hs 2 - refine hb.2.trans ((mul_le_mul hsq hB' hB (by positivity)).trans_eq ?_) - rw [← pow_mul,← pow_succ,div_pow] - congr 1 - · congr 1; omega - · rw [pow_succ,show s*2=2*s by omega,pow_mul,Real.sq_sqrt (by positivity)] - -end TraceReconstruction - -namespace TraceReconstruction - -theorem series_finite_sum_sq_le {α : Type*} [Fintype α] - (f : IntSeries) (z : α → ℤ) (hz : Function.Injective z) : - (∑ a, f.coeff (z a)^2) ≤ seriesL2Sq f := by - simpa only [tsum_fintype,seriesL2Sq] using - Summable.tsum_le_tsum_of_inj z hz (fun _ _ => sq_nonneg _) - (fun _ => le_rfl) (hasSum_fintype _).summable (series_summable f (fun x => x^2) (by simp)) - -/-- Product coefficients of signed gap series, including an arbitrary -translation of each observed rank gap. -/ -def signedRankProduct {l r : ℕ} (f : Fin (r+1) → IntSeries) - (shift : Fin (r+1) → ℤ) (v : IncreasingTuple l r) : ℝ := - ∏ i, (f i).coeff ((tupleGap v.val i : ℤ)-shift i) - -/-- Largest-gap elimination also holds for signed finite-difference series. -The fixed sum of the observed gaps supplies the missing square-root factor; -translations are unrestricted and the estimate contains no omitted ranks. -/ -theorem signedRankProduct_square_sum_le {l r : ℕ} - (f : Fin (r+1) → IntSeries) (shift : Fin (r+1) → ℤ) - (e : Fin (r+1)) (M : ℝ) (hM : 0 ≤ M) - (hbound : ∀ z : ℤ, (f e).coeff z ^ 2 ≤ M) : - (∑ v : IncreasingTuple l r, signedRankProduct f shift v ^ 2) ≤ - M * ∏ i : Fin r, seriesL2Sq (f (Equiv.swap 0 e i.succ)) := by - classical - let σ : Equiv.Perm (Fin (r+1)) := Equiv.swap 0 e - let F : Fin (r+1) → Fin (l-r+1) → ℝ := - fun i k => (f (σ i)).coeff ((k.val:ℤ)-shift (σ i)) ^ 2 - have hF : ∀ i k, 0 ≤ F i k := fun _ _ => sq_nonneg _ - have hpoint (v : IncreasingTuple l r) : - signedRankProduct f shift v ^ 2 = ∏ i, F i (rankGapProfile σ v i) := by - unfold signedRankProduct - rw [← Finset.prod_pow] - dsimp [F,rankGapProfile] - exact (Equiv.prod_comp σ _).symm - simp_rw [hpoint] - calc - _ ≤ ∑ z : Fin (r+1) → Fin (l-r+1), - if ∑ i, (z i).val = l-r then ∏ i, F i (z i) else 0 := by - exact sum_injective_profile_le (rankGapProfile σ) (rankGapProfile_injective σ) - (fun z => ∑ i, (z i).val = l-r) (rankGapProfile_sum σ) - (fun z => ∏ i, F i (z i)) (fun _ => Finset.prod_nonneg (fun _ _ => hF _ _)) - _ ≤ M * ∏ i : Fin r, ∑ k : Fin (l-r+1), F i.succ k := - constrained_sum_product_le r (l-r) F hF M hM (by - intro k - simpa only [F,σ,Equiv.swap_apply_left] using hbound ((k.val:ℤ)-shift e)) - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left _ hM - apply Finset.prod_le_prod₀ (fun _ _ => Finset.sum_nonneg (fun _ _ => hF _ _)) - intro i _ - dsimp only [F] - apply series_finite_sum_sq_le - intro a b h - exact Fin.ext (Int.ofNat_inj.mp (sub_left_injective h)) - -/-- Finite mixtures of signed rank products can be estimated termwise. -This is the exact Cauchy--Schwarz form used when expanding positional -finite-difference operators into gap derivatives. -/ -theorem rank_mixture_square_sum_le {α V : Type*} [Fintype α] [Fintype V] - (c : α → ℝ) (F : α → V → ℝ) (B : α → ℝ) - (hB : ∀ a, (∑ v, F a v ^ 2) ≤ B a) : - (∑ v, (∑ a, c a * F a v)^2) ≤ (∑ a, |c a|) * ∑ a, |c a| * B a := by - have hp (v : V) : (∑ a, c a*F a v)^2 ≤ - (∑ a, |c a|) * ∑ a, |c a| * F a v^2 := by - apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (fun _ _ => abs_nonneg _) (fun _ _ => mul_nonneg (abs_nonneg _) (sq_nonneg _)) - intro a _ - rw [mul_pow,← mul_assoc,← sq, sq_abs] - calc - _ ≤ ∑ v, (∑ a, |c a|) * ∑ a, |c a| * F a v^2 := - Finset.sum_le_sum (fun v _ => hp v) - _ = (∑ a, |c a|) * ∑ a, |c a| * ∑ v, F a v^2 := by - rw [← Finset.mul_sum,Finset.sum_comm] - simp_rw [← Finset.mul_sum] - _ ≤ _ := by - apply mul_le_mul_of_nonneg_left _ (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_left (hB a) (abs_nonneg _) - -end TraceReconstruction - -namespace TraceReconstruction - -/-- The tensor product of finitely supported one-dimensional coefficient -series, represented on its literal vector-valued exponents. -/ -def tensorSeries {ι : Type*} [Fintype ι] (f : ι → IntSeries) : - AddMonoidAlgebra ℝ (ι → ℤ) := -by - classical - exact AddMonoidAlgebra.ofCoeff (Finsupp.onFinset (Fintype.piFinset (fun i => (f i).coeff.support)) - (fun z => ∏ i, (f i).coeff (z i)) (by - classical - intro z hz - simp only [Fintype.mem_piFinset,Finsupp.mem_support_iff] - exact fun i => (Finset.prod_ne_zero_iff.mp hz) i (Finset.mem_univ i))) - -theorem tensorSeries_coeff {ι : Type*} [Fintype ι] (f : ι → IntSeries) (z : ι → ℤ) : - (tensorSeries f).coeff z = ∏ i, (f i).coeff (z i) := rfl - -theorem tensorSeries_support {ι : Type*} [Fintype ι] [DecidableEq ι] - (f : ι → IntSeries) : - (tensorSeries f).coeff.support = Fintype.piFinset (fun i => (f i).coeff.support) := by - classical - ext z - simp [tensorSeries_coeff,Finset.prod_ne_zero_iff] - -/-- Literal tensor multiplication is coordinatewise convolution. -/ -theorem tensorSeries_mul {ι : Type*} [Fintype ι] (f g : ι → IntSeries) : - tensorSeries (fun i => f i*g i) = tensorSeries f * tensorSeries g := by - classical - ext z - rw [tensorSeries_coeff,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum,tensorSeries_support] - simp_rw [tensorSeries_coeff,← Finset.prod_mul_distrib] - simp only [Pi.add_apply, Pi.neg_apply] - rw [← Finset.prod_univ_sum (fun i => (f i).coeff.support) - (fun i j => (f i).coeff j * (g i).coeff (-j + z i))] - apply Finset.prod_congr rfl - intro i _ - rw [AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] - -theorem tensorSeries_one {ι : Type*} [Fintype ι] : - tensorSeries (fun _ : ι => (1 : IntSeries)) = 1 := by - classical - ext z - rw [tensorSeries_coeff] - change (∏ i, Finsupp.single 0 (1:ℝ) (z i)) = Finsupp.single 0 (1:ℝ) z - simp only [Finsupp.single_apply] - by_cases hz : z = 0 - · subst z; simp - · have he : ∃ i, z i ≠ 0 := by simpa [funext_iff] using hz - obtain ⟨i,hi⟩ := he - rw [ite_eq_right (Ne.symm hz)] - exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [Ne.symm hi]) - - -/-- Embedding one integral exponent into its own gap coordinate. -/ -def coordinateExponent {ι : Type*} [DecidableEq ι] (i : ι) : ℤ →+ (ι → ℤ) where - toFun := fun a => Pi.single (M := fun _ => ℤ) i a - map_zero' := Pi.single_zero i - map_add' := fun a b => by - ext j - by_cases h : j=i - · subst j; simp - · simp [Pi.single_eq_of_ne h] - -def coordinateSeriesHom {ι : Type*} [DecidableEq ι] (i : ι) : - IntSeries →+* AddMonoidAlgebra ℝ (ι → ℤ) := - AddMonoidAlgebra.mapDomainRingHom ℝ (coordinateExponent i) - -theorem coordinateExponent_injective {ι : Type*} [DecidableEq ι] (i : ι) : - Function.Injective (coordinateExponent i) := by - intro a b h - simpa only [coordinateExponent,AddMonoidHom.coe_mk,ZeroHom.coe_mk,Pi.single_eq_same] - using congrFun h i - -theorem tensorSeries_coordinate {ι : Type*} [Fintype ι] [DecidableEq ι] - (i : ι) (f : IntSeries) : - tensorSeries (fun j => if j=i then f else 1) = coordinateSeriesHom i f := by - classical - ext z - rw [tensorSeries_coeff] - change (∏ j, (if j=i then f else (1:IntSeries)).coeff (z j)) = - (Finsupp.mapDomain (coordinateExponent i) f.coeff) z - by_cases hz : ∀ j, j ≠ i → z j = 0 - · have he : coordinateExponent i (z i) = z := by - funext j - by_cases hj : j=i - · subst j; simp [coordinateExponent] - · simp [coordinateExponent,Pi.single_eq_of_ne hj,hz j hj] - rw [← he,Finsupp.mapDomain_apply_of_injective (coordinateExponent_injective i)] - rw [Finset.prod_eq_single i] - · simp [coordinateExponent] - · intro j _ hj - simp [hj,coordinateExponent] - · simp - · push Not at hz - obtain ⟨j,hji,hj⟩ := hz - have hn : z ∉ Set.range (coordinateExponent i) := by - rintro ⟨a,ha⟩ - have h := congrFun ha j - simp [coordinateExponent,Pi.single_eq_of_ne hji] at h - exact hj h.symm - rw [Finsupp.mapDomain_of_notMem_range _ _ hn] - apply Finset.prod_eq_zero (Finset.mem_univ j) - simp only [ite_eq_right hji] - change Finsupp.single 0 (1:ℝ) (z j) = 0 - simp [Ne.symm hj] - -theorem tensorSeries_prod {ι α : Type*} [Fintype ι] - (s : Finset α) (f : α → ι → IntSeries) : - tensorSeries (fun i => ∏ a ∈ s, f a i) = ∏ a ∈ s, tensorSeries (f a) := by - classical - induction s using Finset.induction_on with - | empty => simp [tensorSeries_one] - | @insert a s ha ih => - simp only [Finset.prod_insert ha] - rw [tensorSeries_mul,ih] - -/-- The literal product of the coordinate embeddings has precisely the -independent product coefficients, with no external tensor-product axioms. -/ -theorem tensorSeries_eq_prod {ι : Type*} [Fintype ι] [DecidableEq ι] - (f : ι → IntSeries) : - tensorSeries f = ∏ i, coordinateSeriesHom i (f i) := by - have he : f = fun j => ∏ i, if j=i then f i else 1 := by - funext j - simp - conv_lhs => rw [he,tensorSeries_prod] - apply Finset.prod_congr rfl - intro i _ - exact tensorSeries_coordinate i (f i) - -end TraceReconstruction - -namespace TraceReconstruction - -/-- Explicit fixed-order gap derivative bound, uniformly over translated -rank restrictions and the choice of the eliminated gap. -/ -theorem rank_gap_derivatives_bound {l r : ℕ} - (g s : Fin (r+1) → ℕ) (shift : Fin (r+1) → ℤ) - {p : ℝ} (hp : p ∈ Set.Ioo 0 1) (e : Fin (r+1)) : - (∑ v : IncreasingTuple l r, - signedRankProduct (fun i => binomialLengthDifference (g i) (s i) p) shift v ^ 2) ≤ - (lengthDifferenceConstant (s e) p)^(2*s e+2) / ((g e:ℝ)+1)^(s e+1) * - ∏ i : Fin r, - (lengthDifferenceConstant (s (Equiv.swap 0 e i.succ)) p)^(2*s (Equiv.swap 0 e i.succ)+1) / - (((g (Equiv.swap 0 e i.succ):ℝ)+1)^(s (Equiv.swap 0 e i.succ)) * - Real.sqrt ((g (Equiv.swap 0 e i.succ):ℝ)+1)) := by - have hC := (lengthDifferenceConstant_pos (s e) hp).le - refine (signedRankProduct_square_sum_le _ shift e _ (by positivity) - (binomialLengthDifference_numeric (g e) (s e) hp).1).trans ?_ - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply Finset.prod_le_prod₀ (fun _ _ => seriesL2Sq_nonneg _) - intro i _ - exact (binomialLengthDifference_numeric _ _ hp).2 - -/-- Increasing an order increases only its explicit smoothing constant. -/ -theorem lengthDifferenceConstant_mono {s t : ℕ} (hst : s ≤ t) - {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : - lengthDifferenceConstant s p ≤ lengthDifferenceConstant t p := by - unfold lengthDifferenceConstant - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.sqrt_le_sqrt - exact div_le_div_of_nonneg_right (by exact_mod_cast Nat.succ_le_succ hst) - (mul_pos hp.1 (sub_pos.mpr hp.2)).le - -end TraceReconstruction - -namespace TraceReconstruction - -inductive GapDifference - | unchanged | first | second - deriving DecidableEq - -def GapDifference.order : GapDifference → ℕ - | .unchanged => 0 | .first => 1 | .second => 2 - -def adjacentGap {r : ℕ} (h : Fin r) (b : Bool) : Fin (r+1) := - if b then h.succ else h.castSucc - -def gapTermWeight (k : GapDifference) (a : Bool × Bool) : ℝ := - match k with - | .unchanged => 1/4 - | .first => (if a.1 then -1 else 1)/2 - | .second => (if a.1 then -1 else 1)*(if a.2 then -1 else 1)/2 - -def gapTermOrder {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) - (i : Fin (r+1)) : ℕ := - match k with - | .unchanged => 0 - | .first => if i = adjacentGap h a.1 then 1 else 0 - | .second => (if i = adjacentGap h a.1 then 1 else 0) + - (if i = adjacentGap h a.2 then 1 else 0) - -def gapTermExtra {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) - (i : Fin (r+1)) : ℕ := - match k with - | .unchanged => (if i = h.castSucc then 1 else 0) + (if i = h.succ then 1 else 0) - | .first => if i = adjacentGap h a.2 then 1 else 0 - | .second => 0 - -/-- Polynomial of a centered positional operator after removing from -both incident gaps the one unit needed for either direction of movement. -/ -def gapOperator {r : ℕ} (h : Fin r) (k : GapDifference) (p : ℝ) : - AddMonoidAlgebra ℝ (Fin (r+1) → ℤ) := - let L := coordinateSeriesHom h.castSucc (biasedSeries 1 p) - let R := coordinateSeriesHom h.succ (biasedSeries 1 p) - match k with - | .unchanged => L*R - | .first => (1/2:ℝ) • (L^2-R^2) - | .second => (1/2:ℝ) • (L^2+R^2-2*L*R) - -theorem tensorSeries_two_coordinates {ι : Type*} [Fintype ι] [DecidableEq ι] - (a b : ι) (f g : IntSeries) : - tensorSeries (fun i => f^(if i=a then 1 else 0) * g^(if i=b then 1 else 0)) = - coordinateSeriesHom a f * coordinateSeriesHom b g := by - rw [tensorSeries_mul] - have h (c : ι) (u : IntSeries) : - (fun i => u^(if i=c then 1 else 0)) = (fun i => if i=c then u else 1) := by - funext i - split <;> simp - rw [h,h,tensorSeries_coordinate,tensorSeries_coordinate] - -theorem gapLocalTerm_factor {r : ℕ} (h : Fin r) (k : GapDifference) - (a : Bool × Bool) (p : ℝ) : - tensorSeries (fun i => (biasedSeries 1 p-1)^gapTermOrder h k a i * - (biasedSeries 1 p)^gapTermExtra h k a i) = - match k with - | .unchanged => coordinateSeriesHom h.castSucc (biasedSeries 1 p) * - coordinateSeriesHom h.succ (biasedSeries 1 p) - | .first => (coordinateSeriesHom (adjacentGap h a.1) (biasedSeries 1 p)-1) * - coordinateSeriesHom (adjacentGap h a.2) (biasedSeries 1 p) - | .second => (coordinateSeriesHom (adjacentGap h a.1) (biasedSeries 1 p)-1) * - (coordinateSeriesHom (adjacentGap h a.2) (biasedSeries 1 p)-1) := by - cases k <;> simp only [gapTermOrder,gapTermExtra,pow_zero,pow_add,one_mul,mul_one] - all_goals rw [tensorSeries_two_coordinates] - all_goals simp only [map_sub,map_one] - -/-- Exact four-term assignment of positional differences to the adjacent -binomial gap lengths, including all signs and all bounded shifts. -/ -theorem gapOperator_expansion {r : ℕ} (h : Fin r) (k : GapDifference) (p : ℝ) : - gapOperator h k p = ∑ a : Bool × Bool, gapTermWeight k a • - tensorSeries (fun i => (biasedSeries 1 p-1)^gapTermOrder h k a i * - (biasedSeries 1 p)^gapTermExtra h k a i) := by - simp_rw [gapLocalTerm_factor] - cases k <;> simp only [gapOperator,gapTermWeight,Fintype.sum_prod_type, - Fintype.sum_bool,adjacentGap,Bool.false_eq_true,ite_false,ite_true] - · module - all_goals simp only [Algebra.smul_def] - all_goals norm_num - all_goals ring - -theorem gapTermWeight_l1 (k : GapDifference) : - (∑ a : Bool × Bool, |gapTermWeight k a|) ≤ 2 := by - cases k <;> norm_num [gapTermWeight,Fintype.sum_prod_type,Fintype.sum_bool] - -theorem gapTermOrder_total {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) : - (∑ i, gapTermOrder h k a i) = k.order := by - cases k <;> simp [gapTermOrder,GapDifference.order,Finset.sum_add_distrib] - -/-- Exact global expansion inside the unconstrained vector of gap counts. -/ -theorem gapOperators_expansion {r : ℕ} (g : Fin (r+1) → ℕ) - (k : Fin r → GapDifference) (p : ℝ) : - tensorSeries (fun i => biasedSeries (g i) p) * (∏ h, gapOperator h (k h) p) = - ∑ a : Fin r → Bool × Bool, (∏ h, gapTermWeight (k h) (a h)) • - tensorSeries (fun i => binomialLengthDifference - (g i + ∑ h, gapTermExtra h (k h) (a h) i) - (∑ h, gapTermOrder h (k h) (a h) i) p) := by - classical - simp_rw [gapOperator_expansion] - rw [Finset.prod_univ_sum] - simp only [Fintype.piFinset_univ] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - rw [Finset.prod_smul, mul_smul_comm, ← tensorSeries_prod, ← tensorSeries_mul] - congr 2 - funext i - simp only [binomialLengthDifference,biasedSeries, - Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum] - ring - -theorem gapOperators_weight_l1 {r : ℕ} (k : Fin r → GapDifference) : - (∑ a : Fin r → Bool × Bool, |∏ h, gapTermWeight (k h) (a h)|) ≤ (2:ℝ)^r := by - simp_rw [Finset.abs_prod] - rw [← Fintype.prod_sum (fun h a => |gapTermWeight (k h) a|)] - calc - _ ≤ ∏ _h : Fin r, (2:ℝ) := by - apply Finset.prod_le_prod₀ (fun _ _ => Finset.sum_nonneg fun _ _ => abs_nonneg _) - intro h _ - exact gapTermWeight_l1 (k h) - _ = _ := by simp - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction - -theorem prod_eliminate_fin {α : Type*} [CommMonoid α] {r : ℕ} - (f : Fin (r+1) → α) (e : Fin (r+1)) : - f e * (∏ i : Fin r, f (Equiv.swap 0 e i.succ)) = ∏ i, f i := by - calc - _ = ∏ i : Fin (r+1), f (Equiv.swap 0 e i) := by - rw [Fin.prod_univ_succ,Equiv.swap_apply_left] - _ = _ := Equiv.prod_comp (Equiv.swap 0 e) f - -/-- Uniform smoothing with the individual gap scale retained, and a common -lower gap scale reserved for every derivative order. -/ -theorem lengthDifference_uniform (g b s : ℕ) {p C G : ℝ} - (hp : p ∈ Set.Ioo 0 1) (hC : lengthDifferenceConstant s p ≤ C) - (hG : 0 < G) (hb : b ≤ g) (hGg : G ≤ (g:ℝ)+1) : - (∀ z : ℤ, (binomialLengthDifference g s p).coeff z^2 ≤ - (C/Real.sqrt ((b:ℝ)+1)) * (C^(2*s+1)/(G^s*Real.sqrt ((b:ℝ)+1)))) ∧ - seriesL2Sq (binomialLengthDifference g s p) ≤ - C^(2*s+1)/(G^s*Real.sqrt ((b:ℝ)+1)) := by - have hC0 : 0 < C := (lengthDifferenceConstant_pos s hp).trans_le hC - have hb0 : 0 < (b:ℝ)+1 := by positivity - have hg0 : 0 < (g:ℝ)+1 := by positivity - have hb' : (b:ℝ)+1 ≤ (g:ℝ)+1 := by exact_mod_cast Nat.add_le_add_right hb 1 - have hpow : G^s ≤ ((g:ℝ)+1)^s := pow_le_pow_left₀ hG.le hGg s - have hx := binomialLengthDifference_numeric g s hp - constructor - · intro z - refine (hx.1 z).trans ?_ - have hc := pow_le_pow_left₀ (lengthDifferenceConstant_pos s hp).le hC (2*s+2) - have hd : G^s*((b:ℝ)+1) ≤ ((g:ℝ)+1)^(s+1) := by - rw [pow_succ] - exact mul_le_mul hpow hb' hb0.le (by positivity) - calc - _ ≤ C^(2*s+2)/(G^s*((b:ℝ)+1)) := by - apply div_le_div₀ (by positivity) hc (by positivity) hd - _ = _ := by - have hsq := Real.sq_sqrt hb0.le - have hs : Real.sqrt ((b:ℝ)+1) ≠ 0 := (Real.sqrt_pos.mpr hb0).ne' - rw [show 2*s+2=(2*s+1)+1 by omega,pow_succ] - field_simp - nlinarith only [hsq] - · refine hx.2.trans ?_ - apply div_le_div₀ (by positivity) - (pow_le_pow_left₀ (lengthDifferenceConstant_pos s hp).le hC (2*s+1)) - (by positivity) - exact mul_le_mul hpow (Real.sqrt_le_sqrt hb') (Real.sqrt_nonneg _) (by positivity) - -/-- A single translated signed rank product, with every smoothing scale -and the largest-gap constraint exposed. -/ -theorem rank_derivatives_uniform {l r : ℕ} - (g b s : Fin (r+1) → ℕ) (shift : Fin (r+1) → ℤ) - {p C G : ℝ} (hp : p ∈ Set.Ioo 0 1) - (hC : ∀ i, lengthDifferenceConstant (s i) p ≤ C) (hG : 0 < G) - (hb : ∀ i, b i ≤ g i) (hGg : ∀ i, G ≤ (g i:ℝ)+1) (e : Fin (r+1)) : - (∑ v : IncreasingTuple l r, - signedRankProduct (fun i => binomialLengthDifference (g i) (s i) p) shift v ^ 2) ≤ - C^(2*(∑ i, s i)+r+2) / - (G^(∑ i, s i) * Real.sqrt ((b e:ℝ)+1) * ∏ i, Real.sqrt ((b i:ℝ)+1)) := by - let F (i : Fin (r+1)) : ℝ := C^(2*s i+1)/(G^(s i)*Real.sqrt ((b i:ℝ)+1)) - have hC0 : 0 < C := (lengthDifferenceConstant_pos (s e) hp).trans_le (hC e) - have hF : ∀ i, 0 ≤ F i := fun i => by dsimp [F]; positivity - have hbound (i : Fin (r+1)) := lengthDifference_uniform (g i) (b i) (s i) hp (hC i) hG (hb i) (hGg i) - calc - _ ≤ (C/Real.sqrt ((b e:ℝ)+1)*F e) * - ∏ i : Fin r, seriesL2Sq (binomialLengthDifference (g (Equiv.swap 0 e i.succ)) - (s (Equiv.swap 0 e i.succ)) p) := by - apply signedRankProduct_square_sum_le _ shift e _ (by positivity [hF e]) - exact (hbound e).1 - _ ≤ (C/Real.sqrt ((b e:ℝ)+1)*F e) * ∏ i : Fin r, F (Equiv.swap 0 e i.succ) := by - apply mul_le_mul_of_nonneg_left _ (by positivity [hF e]) - apply Finset.prod_le_prod₀ (fun _ _ => seriesL2Sq_nonneg _) - intro i _ - exact (hbound _).2 - _ = (C/Real.sqrt ((b e:ℝ)+1))*∏ i, F i := by - rw [mul_assoc,prod_eliminate_fin] - _ = _ := by - simp only [F,Finset.prod_div_distrib,Finset.prod_mul_distrib, - Finset.prod_pow_eq_pow_sum,Finset.sum_add_distrib,← Finset.mul_sum, - Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one] - rw [show 2*(∑ i, s i)+r+2=(2*(∑ i, s i)+(r+1))+1 by omega,pow_succ] - ring - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction - -/-- Enough vacant slots for independent one-step displacements of every tag. -/ -def SafeTaggedTuple {n r : ℕ} (p : Fin r → Fin n) : Prop := - (∀ i, 1 ≤ (p i).val ∧ (p i).val+1 < n) ∧ - ∀ i j, i < j → (p i).val+3 ≤ (p j).val - -def shiftedTag {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) - (a : Fin r → Fin 3) (i : Fin r) : Fin n := - ⟨(p i).val+(a i).val-1, by - have h := hp.1 i - have ha := (a i).isLt - omega⟩ - -theorem shiftedTag_strictMono {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) - (a : Fin r → Fin 3) : StrictMono (shiftedTag p hp a) := by - intro i j hij - change (p i).val+(a i).val-1 < (p j).val+(a j).val-1 - have h := hp.2 i j hij - have hi := hp.1 i - have hj := hp.1 j - have hai := (a i).isLt - omega - -def gapIncidence (r : ℕ) (i : Fin (r+1)) : ℕ := - Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i + Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i - -def shiftGapExtra {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : ℕ := - Fin.cons (α := fun _ => ℕ) 0 (fun h => 2-(a h).val) i + Fin.snoc (α := fun _ => ℕ) (fun h => (a h).val) 0 i - -/-- Literal adjacent-gap allocation of the units used by a displacement. -Value zero means translate left, one leave fixed, two translate right. -/ -def localShiftExtra {r : ℕ} (h : Fin r) (a : Fin 3) (i : Fin (r+1)) : ℕ := - (if i=h.castSucc then a.val else 0) + (if i=h.succ then 2-a.val else 0) - -theorem sum_castSucc_indicator {r : ℕ} (f : Fin r → ℕ) (i : Fin (r+1)) : - (∑ h, if i=h.castSucc then f h else 0) = Fin.snoc (α := fun _ => ℕ) f 0 i := by - induction i using Fin.lastCases with - | last => simp [eq_comm] - | cast h => simp - -theorem sum_succ_indicator {r : ℕ} (f : Fin r → ℕ) (i : Fin (r+1)) : - (∑ h, if i=h.succ then f h else 0) = Fin.cons (α := fun _ => ℕ) 0 f i := by - induction i using Fin.cases with - | zero => simp [eq_comm] - | succ h => simp - -theorem shiftGapExtra_eq_sum {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : - shiftGapExtra a i = ∑ h, localShiftExtra h (a h) i := by - simp only [localShiftExtra,Finset.sum_add_distrib,sum_castSucc_indicator, - sum_succ_indicator,shiftGapExtra] - omega - -theorem gapIncidence_le {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) - (i : Fin (r+1)) : gapIncidence r i ≤ tupleGap p i := by - cases r with - | zero => - have hi : i=0 := Fin.eq_zero i - subst i - simp [gapIncidence,Fin.snoc_zero] - | succ r => - induction i using Fin.cases with - | zero => simpa only [gapIncidence,Fin.cons_zero,zero_add,Fin.snoc_apply_zero, - tupleGap_zero] using (hp.1 0).1 - | succ i => - induction i using Fin.lastCases with - | last => - simp only [gapIncidence,Fin.succ_last,Fin.cons_last,Fin.snoc_last,add_zero, - tupleGap_last] - have h := (hp.1 (Fin.last r)).2 - omega - | cast i => - simp only [gapIncidence,Fin.cons_succ] - rw [Fin.succ_castSucc,Fin.snoc_castSucc] - rw [← Fin.succ_castSucc,tupleGap_middle] - have h := hp.2 i.castSucc i.succ (by simp) - omega - -/-- The exact geometric identity relating translated tag positions to -nonnegative binomial-gap lengths. -/ -theorem tupleGap_shifted {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) - (a : Fin r → Fin 3) (i : Fin (r+1)) : - tupleGap (shiftedTag p hp a) i = - tupleGap p i - gapIncidence r i + shiftGapExtra a i := by - cases r with - | zero => - have hi : i=0 := Fin.eq_zero i - subst i - simp [tupleGap,tupleLower,tupleUpper,gapIncidence,shiftGapExtra,Fin.snoc_zero] - | succ r => - induction i using Fin.cases with - | zero => - simp only [tupleGap_zero,gapIncidence,shiftGapExtra,Fin.cons_zero,zero_add, - Fin.snoc_apply_zero,shiftedTag] - have h := (hp.1 0).1 - omega - | succ i => - induction i using Fin.lastCases with - | last => - simp only [gapIncidence,shiftGapExtra,Fin.succ_last,Fin.cons_last, - Fin.snoc_last,add_zero,tupleGap_last,shiftedTag] - have h := hp.1 (Fin.last r) - have ha := (a (Fin.last r)).isLt - omega - | cast i => - simp only [gapIncidence,shiftGapExtra,Fin.cons_succ] - rw [Fin.succ_castSucc,Fin.snoc_castSucc,Fin.snoc_castSucc] - rw [← Fin.succ_castSucc,tupleGap_middle,tupleGap_middle] - change (p i.succ).val+(a i.succ).val-1-((p i.castSucc).val+(a i.castSucc).val-1+1) = _ - have hi := hp.1 i.castSucc - have hj := hp.1 i.succ - have hij := hp.2 i.castSucc i.succ (by simp) - have hai := (a i.castSucc).isLt - have haj := (a i.succ).isLt - omega - - -/-- Coefficients of the unchanged, centered first, and centered second -one-step positional operators. -/ -def positionalWeight (k : GapDifference) (a : Fin 3) : ℝ := - match k with - | .unchanged => if a=1 then 1 else 0 - | .first => if a=0 then -1/2 else if a=2 then 1/2 else 0 - | .second => if a=1 then -1 else 1/2 - -theorem localShift_factor {r : ℕ} (h : Fin r) (a : Fin 3) (p : ℝ) : - tensorSeries (fun i => (biasedSeries 1 p)^localShiftExtra h a i) = - coordinateSeriesHom h.castSucc (biasedSeries 1 p)^a.val * - coordinateSeriesHom h.succ (biasedSeries 1 p)^(2-a.val) := by - have hpow (u : IntSeries) (t : ℕ) (c i : Fin (r+1)) : - u^(if i=c then t else 0) = (u^t)^(if i=c then 1 else 0) := by - split <;> simp - have he : (fun i => (biasedSeries 1 p)^localShiftExtra h a i) = - (fun i => ((biasedSeries 1 p)^a.val)^(if i=h.castSucc then 1 else 0) * - ((biasedSeries 1 p)^(2-a.val))^(if i=h.succ then 1 else 0)) := by - funext i - rw [localShiftExtra,pow_add,hpow _ _ h.castSucc i,hpow _ _ h.succ i] - rw [he,tensorSeries_two_coordinates,map_pow,map_pow] - -theorem gapOperator_positional_expansion {r : ℕ} (h : Fin r) (k : GapDifference) - (p : ℝ) : - gapOperator h k p = ∑ a : Fin 3, positionalWeight k a • - tensorSeries (fun i => (biasedSeries 1 p)^localShiftExtra h a i) := by - simp_rw [localShift_factor] - rw [Fin.sum_univ_three] - cases k <;> norm_num [positionalWeight,gapOperator,Fin.ext_iff] - all_goals try simp only [two_mul,add_mul] - all_goals module - -/-- Literal centered differences of all rank kernels are coefficients of -the adjacent-gap operator product, with no formal negative trial lengths. -/ -theorem shifted_gap_series_expansion {n r : ℕ} (p : Fin r → Fin n) - (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) (θ : ℝ) : - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) • - tensorSeries (fun i => biasedSeries (tupleGap (shiftedTag p hp a) i) θ)) = - tensorSeries (fun i => biasedSeries (tupleGap p i-gapIncidence r i) θ) * - ∏ h, gapOperator h (k h) θ := by - classical - simp_rw [gapOperator_positional_expansion] - rw [Finset.prod_univ_sum] - simp only [Fintype.piFinset_univ] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - rw [Finset.prod_smul,mul_smul_comm,← tensorSeries_prod,← tensorSeries_mul] - congr 2 - funext i - rw [tupleGap_shifted,shiftGapExtra_eq_sum] - simp only [biasedSeries,pow_one,Finset.prod_pow_eq_pow_sum,pow_add] - - -/-- Simultaneous literal positional operators applied to the actual -conditional retained-subset kernel. -/ -def positionalRankDifference {n l r : ℕ} (hl : l ≤ n) (p : Fin r → Fin n) - (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) (v : IncreasingTuple l r) : ℝ := - ∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) * - subsetRankKernel hl (shiftedTag p hp a) v.val - -theorem positionalRankDifference_expansion {n l r : ℕ} (hl : l ≤ n) - (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) - {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (v : IncreasingTuple l r) : - positionalRankDifference hl p hp k v = θ^r / binomialMass n θ l * - ∑ a : Fin r → Bool × Bool, (∏ h, gapTermWeight (k h) (a h)) * - signedRankProduct (fun i => binomialLengthDifference - (tupleGap p i-gapIncidence r i + ∑ h, gapTermExtra h (k h) (a h) i) - (∑ h, gapTermOrder h (k h) (a h) i) θ) (fun _ => 0) v := by - have h := shifted_gap_series_expansion p hp k θ - rw [gapOperators_expansion] at h - have hh := congrArg (fun f : AddMonoidAlgebra ℝ (Fin (r+1) → ℤ) => - f.coeff (fun i => (tupleGap v.val i:ℤ))) h - simp only [AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply, - AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,tensorSeries_coeff, - biasedSeries_coeff_nat] at hh - unfold positionalRankDifference - simp_rw [subsetRankKernel_binomial_formula hl _ (shiftedTag_strictMono p hp _) _ v.property θ hθ] - calc - _ = θ^r / binomialMass n θ l * - ∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) * - ∏ i, binomialMass (tupleGap (shiftedTag p hp a) i) θ (tupleGap v.val i) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - ring - _ = _ := by - exact congrArg (fun t => θ^r / binomialMass n θ l * t) (by - simpa only [signedRankProduct,sub_zero] using hh) - -/-- The total derivative order is the source value |D|+2|V|. -/ -theorem gap_global_order {r : ℕ} (k : Fin r → GapDifference) (a : Fin r → Bool × Bool) : - (∑ i : Fin (r+1), ∑ h, gapTermOrder h (k h) (a h) i) = ∑ h, (k h).order := by - rw [Finset.sum_comm] - simp_rw [gapTermOrder_total] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction - -theorem gapTermOrder_sum_le_global {r : ℕ} (k : Fin r → GapDifference) - (a : Fin r → Bool × Bool) (i : Fin (r+1)) : - (∑ h, gapTermOrder h (k h) (a h) i) ≤ ∑ h, (k h).order := by - rw [← gap_global_order k a] - exact Finset.single_le_sum (f := fun j : Fin (r+1) => ∑ h, gapTermOrder h (k h) (a h) j) - (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) - -/-- Literal mixed centered positional differences of a conditional rank -kernel, with a single explicit constant depending only on the total order -and the Bernoulli parameter. Every gap scale remains available for summing -over the period tuples in the signed initial construction. -/ -theorem positionalRankDifference_square_sum_le {n l r : ℕ} (hl : l ≤ n) - (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) - {θ G : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (hG : 0 < G) - (hgap : ∀ i, G ≤ (tupleGap p i-gapIncidence r i : ℕ)+1) - (e : Fin (r+1)) : - (∑ v : IncreasingTuple l r, positionalRankDifference hl p hp k v ^ 2) ≤ - (θ^r / binomialMass n θ l)^2 * (2:ℝ)^(2*r) * - (lengthDifferenceConstant (∑ h, (k h).order) θ)^(2*(∑ h, (k h).order)+r+2) / - (G^(∑ h, (k h).order) * Real.sqrt ((tupleGap p e-gapIncidence r e:ℕ)+1) * - ∏ i, Real.sqrt ((tupleGap p i-gapIncidence r i:ℕ)+1)) := by - let d := ∑ h, (k h).order - let C := lengthDifferenceConstant d θ - let b (i : Fin (r+1)) := tupleGap p i-gapIncidence r i - let B := C^(2*d+r+2) / (G^d*Real.sqrt ((b e:ℝ)+1)*∏ i,Real.sqrt ((b i:ℝ)+1)) - let c (a : Fin r → Bool × Bool) := ∏ h, gapTermWeight (k h) (a h) - let F (a : Fin r → Bool × Bool) (v : IncreasingTuple l r) := - signedRankProduct (fun i => binomialLengthDifference - (b i+∑ h, gapTermExtra h (k h) (a h) i) - (∑ h, gapTermOrder h (k h) (a h) i) θ) (fun _ => 0) v - have hC : 0 < C := lengthDifferenceConstant_pos d hθ - have hB0 : 0 ≤ B := by dsimp [B]; positivity - have hB (a : Fin r → Bool × Bool) : (∑ v, F a v^2) ≤ B := by - have hd (i : Fin (r+1)) : lengthDifferenceConstant (∑ h, gapTermOrder h (k h) (a h) i) θ ≤ C := - lengthDifferenceConstant_mono (gapTermOrder_sum_le_global k a i) hθ - have h := rank_derivatives_uniform (l := l) - (fun i => b i+∑ h, gapTermExtra h (k h) (a h) i) b - (fun i => ∑ h, gapTermOrder h (k h) (a h) i) (fun _ => 0) - hθ hd hG (fun _ => Nat.le_add_right _ _) (by - intro i - exact (hgap i).trans (by exact_mod_cast Nat.add_le_add_right (Nat.le_add_right (b i) _) 1)) e - simpa only [F,B,d,gap_global_order] using h - have hmix := rank_mixture_square_sum_le c F (fun _ => B) hB - have hM : (∑ a, |c a|) ≤ (2:ℝ)^r := gapOperators_weight_l1 k - have hM0 : 0 ≤ ∑ a, |c a| := Finset.sum_nonneg fun _ _ => abs_nonneg _ - have hmix' : (∑ v, (∑ a, c a*F a v)^2) ≤ (2:ℝ)^(2*r)*B := by - refine hmix.trans ?_ - rw [← Finset.sum_mul,← mul_assoc] - have hs : (∑ a, |c a|)^2 ≤ ((2:ℝ)^r)^2 := (sq_le_sq₀ hM0 (by positivity)).mpr hM - calc - _ = (∑ a, |c a|)^2*B := by ring - _ ≤ ((2:ℝ)^r)^2*B := mul_le_mul_of_nonneg_right hs hB0 - _ = _ := by rw [← pow_mul,Nat.mul_comm r 2] - simp_rw [positionalRankDifference_expansion hl p hp k hθ,mul_pow] - rw [← Finset.mul_sum] - calc - _ ≤ (θ^r / binomialMass n θ l)^2 * ((2:ℝ)^(2*r)*B) := - mul_le_mul_of_nonneg_left hmix' (sq_nonneg _) - _ = _ := by dsimp [B,C,d,b]; ring - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction - -theorem gapIncidence_le_two (r : ℕ) (i : Fin (r+1)) : gapIncidence r i ≤ 2 := by - have h₁ : Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i ≤ 1 := by - induction i using Fin.cases <;> simp - have h₂ : Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i ≤ 1 := by - induction i using Fin.lastCases <;> simp - exact Nat.add_le_add h₁ h₂ - -/-- Constant middle-period tags admit every independent left/unchanged/right -choice without violating slot order or either end boundary. -/ -theorem constant_period_safe {u m r : ℕ} (off : Fin m) - (hoff₁ : 1 ≤ off.val) (hoff₂ : off.val+1 < m) (hm : 3 ≤ m) - (j : Fin r → Fin u) (hj : StrictMono j) : - SafeTaggedTuple (periodSlot (fun _ => off) ∘ j) := by - constructor - · intro i - change 1 ≤ (j i).val*m+off.val ∧ (j i).val*m+off.val+1 < u*m - constructor - · omega - · have h := Nat.mul_le_mul_right m (Nat.succ_le_of_lt (j i).isLt) - rw [Nat.succ_mul] at h - omega - · intro i h hih - change (j i).val*m+off.val+3 ≤ (j h).val*m+off.val - have h := Nat.mul_le_mul_right m (Nat.succ_le_iff.mpr (hj hih)) - rw [Nat.succ_mul] at h - omega - -/-- Removing both incident displacement units still leaves a fixed -fraction of each actual coarse gap. Doubled coarse gaps are used to keep -all combinatorial labels integer-valued. -/ -theorem period_derivative_base_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : Fin r → Fin u) (hj : StrictMono j) - (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (i : Fin (r+1)) : - (m:ℝ)*coarsePeriodGap j i/4 ≤ - ((tupleGap (periodSlot off ∘ j) i-gapIncidence r i:ℕ):ℝ)+1 := by - have he := abs_le.mp (period_gap_rounding hr off hoff hdiff j hj i) - have hs := gapIncidence_le (periodSlot off ∘ j) hsafe i - have hs₂ : (gapIncidence r i:ℝ) ≤ 2 := by exact_mod_cast gapIncidence_le_two r i - have hc : 1 ≤ (coarsePeriodGap j i:ℝ) := by exact_mod_cast coarsePeriodGap_pos j i - have hm' : (32:ℝ) ≤ m := by exact_mod_cast hm - rw [Nat.cast_sub hs] - nlinarith - -theorem period_derivative_common_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : Fin r → Fin u) (hj : StrictMono j) - (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (i : Fin (r+1)) : - (m:ℝ)/4 ≤ ((tupleGap (periodSlot off ∘ j) i-gapIncidence r i:ℕ):ℝ)+1 := by - refine le_trans ?_ (period_derivative_base_lower hm hr off hoff hdiff j hj hsafe i) - have hc : 1 ≤ (coarsePeriodGap j i:ℝ) := by exact_mod_cast coarsePeriodGap_pos j i - nlinarith [show (0:ℝ) ≤ m by positivity] - -/-- A largest coarse gap supplies the additional square-root improvement -coming from the fixed sum of the observed ranks. -/ -theorem period_derivative_largest_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : Fin r → Fin u) (hj : StrictMono j) - (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (e : Fin (r+1)) - (he : 2*u ≤ (r+1)*coarsePeriodGap j e) : - (u:ℝ)*m/(2*(r+1:ℝ)) ≤ - ((tupleGap (periodSlot off ∘ j) e-gapIncidence r e:ℕ):ℝ)+1 := by - refine le_trans ?_ (period_derivative_base_lower hm hr off hoff hdiff j hj hsafe e) - have he' : 2*(u:ℝ) ≤ (r+1:ℝ)*coarsePeriodGap j e := by exact_mod_cast he - apply (div_le_iff₀ (by positivity)).mpr - have hh := mul_le_mul_of_nonneg_right he' (show (0:ℝ) ≤ m by positivity) - nlinarith only [hh] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction - -theorem binomial_rank_normalization {n l r : ℕ} {θ : ℝ} - (hθ : θ ∈ Set.Ioo 0 1) (hl : l ≤ n) - (hmean : (n:ℝ)*θ=l) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) : - (θ^r/binomialMass n θ l)^2 ≤ 144*(n:ℝ) := by - have hpow : (θ^r)^2 ≤ 1 := pow_le_one₀ (pow_nonneg hθ.1.le r) (pow_le_one₀ hθ.1.le hθ.2.le) - calc - _ = (θ^r)^2*(binomialMass n θ l)⁻¹^2 := by rw [div_eq_mul_inv,mul_pow] - _ ≤ (binomialMass n θ l)⁻¹^2 := mul_le_of_le_one_left (sq_nonneg _) hpow - _ ≤ 144*((n:ℝ)*θ*(1-θ)) := binomialMass_mean_inverse_sq n l hθ hl hmean hv - _ ≤ _ := by - have h : θ*(1-θ) ≤ 1 := by nlinarith [sq_nonneg θ] - have hh := mul_le_mul_of_nonneg_left h (show 0 ≤ (n:ℝ) by positivity) - nlinarith only [hh] - -/-- The exact mean-count version, with arbitrary proven positive lower -scales for all gaps; no asymptotic or analytic estimate is assumed. -/ -theorem positionalRankDifference_scale_bound {n l r : ℕ} (hl : l ≤ n) - (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) - {θ G H : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (hG : 0 < G) (hH : 0 < H) - (hmean : (n:ℝ)*θ=l) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) - (B : Fin (r+1) → ℝ) (hB : ∀ i, 0 < B i) - (hgap : ∀ i, G ≤ (tupleGap p i-gapIncidence r i:ℕ)+1) - (hscale : ∀ i, B i ≤ (tupleGap p i-gapIncidence r i:ℕ)+1) - (e : Fin (r+1)) (hlarge : H ≤ Real.sqrt ((tupleGap p e-gapIncidence r e:ℕ)+1)) : - (∑ v : IncreasingTuple l r, positionalRankDifference hl p hp k v ^ 2) ≤ - 144*(n:ℝ)*(2:ℝ)^(2*r)* - (lengthDifferenceConstant (∑ h, (k h).order) θ)^(2*(∑ h, (k h).order)+r+2) / - (G^(∑ h, (k h).order)*H*∏ i, Real.sqrt (B i)) := by - refine (positionalRankDifference_square_sum_le hl p hp k hθ hG hgap e).trans ?_ - have hC := (lengthDifferenceConstant_pos (∑ h, (k h).order) hθ).le - apply div_le_div₀ (by positivity) - · exact mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_right (binomial_rank_normalization hθ hl hmean hv) (by positivity)) - (pow_nonneg hC _) - · exact mul_pos (mul_pos (pow_pos hG _) hH) - (Finset.prod_pos (fun i _ => Real.sqrt_pos.mpr (hB i))) - · apply mul_le_mul - · exact mul_le_mul_of_nonneg_left hlarge (by positivity) - · exact Finset.prod_le_prod₀ (fun i _ => (Real.sqrt_nonneg (B i))) - (fun i _ => Real.sqrt_le_sqrt (hscale i)) - · exact Finset.prod_nonneg (fun _ _ => Real.sqrt_nonneg _) - · positivity - -/-- Explicit source rank-difference prefactor. It depends on the period -count, slot length, derivative order and Bernoulli parameter, not the -selected period tuple. -/ -def periodDifferencePrefactor (u m r d : ℕ) (θ : ℝ) : ℝ := - 144*((u*m:ℕ):ℝ)*(2:ℝ)^(2*r)*(lengthDifferenceConstant d θ)^(2*d+r+2) / - (((m:ℝ)/4)^d*Real.sqrt ((u:ℝ)*m/(2*(r+1:ℝ)))* - (Real.sqrt ((m:ℝ)/4))^(r+1)) - -/-- The finite-difference estimate for actual translated tagged slots in -periodic words. The tuple dependence is exactly the product of inverse -square roots of its doubled coarse gaps. -/ -theorem period_positionalRankDifference_bound {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) - (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : - (∑ v : IncreasingTuple l r, - positionalRankDifference hl (periodSlot off ∘ j.val) hsafe k v ^ 2) ≤ - periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by - have hu : 0 < u := lt_of_le_of_lt (Nat.zero_le (j.val ⟨0,hr⟩).val) (j.val ⟨0,hr⟩).isLt - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hu0 : (0:ℝ) < u := by exact_mod_cast hu - obtain ⟨e,he⟩ := exists_large_period_gap hr j - have hb (i : Fin (r+1)) := period_derivative_base_lower hm hr off hoff hdiff j.val j.property hsafe i - have hg (i : Fin (r+1)) := period_derivative_common_lower hm hr off hoff hdiff j.val j.property hsafe i - have hc (i : Fin (r+1)) : (0:ℝ) < coarsePeriodGap j.val i := by exact_mod_cast coarsePeriodGap_pos j.val i - have h := positionalRankDifference_scale_bound hl (periodSlot off ∘ j.val) hsafe k hθ - (G := (m:ℝ)/4) (H := Real.sqrt ((u:ℝ)*m/(2*(r+1:ℝ)))) (by positivity) (by positivity) - hmean hv (fun i => (m:ℝ)*coarsePeriodGap j.val i/4) (fun i => by positivity [hc i]) hg hb e - (Real.sqrt_le_sqrt (period_derivative_largest_lower hm hr off hoff hdiff j.val j.property hsafe e he)) - refine h.trans_eq ?_ - have hs (i : Fin (r+1)) : Real.sqrt ((m:ℝ)*coarsePeriodGap j.val i/4) = - Real.sqrt ((m:ℝ)/4)*Real.sqrt (coarsePeriodGap j.val i) := by - rw [show (m:ℝ)*coarsePeriodGap j.val i/4=((m:ℝ)/4)*coarsePeriodGap j.val i by ring, - Real.sqrt_mul (by positivity)] - simp_rw [hs] - rw [Finset.prod_mul_distrib] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] - rw [periodDifferencePrefactor,Finset.prod_inv_distrib] - ring - -end TraceReconstruction - -open Filter -open scoped Topology - -noncomputable section -namespace TraceReconstruction - -/-- Two independent exact sum constraints determine a missing coordinate on - each side of a fixed cut. This is the second-gap elimination needed when - a period label has been fixed. -/ -theorem two_sums_determine {ι : Type*} [Fintype ι] [DecidableEq ι] - (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) - (x y : ι → ℕ) (hA : ∑ i∈A, x i = ∑ i∈A, y i) - (ht : ∑ i, x i = ∑ i, y i) - (hxy : ∀ i, i≠e → i≠d → x i=y i) : x=y := by - have hs : (∑ i∈A.erase e, x i) = ∑ i∈A.erase e, y i := by - apply Finset.sum_congr rfl - intro i hi - have hi' := Finset.mem_erase.mp hi - apply hxy i hi'.1 - intro hid - exact hd (hid ▸ hi'.2) - have hxe : x e=y e := by - have hx := Finset.sum_erase_add A x he - have hy := Finset.sum_erase_add A y he - omega - have hs' : (∑ i∈Finset.univ.erase d, x i) = ∑ i∈Finset.univ.erase d, y i := by - apply Finset.sum_congr rfl - intro i hi - by_cases hie : i=e - · simpa only [hie] using hxe - · exact hxy i hie (Finset.mem_erase.mp hi).1 - have hxd : x d=y d := by - have hx := Finset.sum_erase_add Finset.univ x (Finset.mem_univ d) - have hy := Finset.sum_erase_add Finset.univ y (Finset.mem_univ d) - omega - funext i - by_cases hie : i=e - · simpa only [hie] using hxe - by_cases hid : i=d - · simpa only [hid] using hxd - exact hxy i hie hid - -abbrev RemainingCoordinates {ι : Type*} (e d : ι) := {i : ι // i≠e ∧ i≠d} - -/-- Restricting an injective gap profile to all but the two eliminated - coordinates is still injective on two fixed-sum fibers. -/ -theorem two_sums_restrict_injective {α ι : Type*} [Fintype ι] [DecidableEq ι] - {U L V : ℕ} (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) - (p : α → ι → Fin (U+1)) (hp : Function.Injective p) - (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) : - Function.Injective (fun a => fun i : RemainingCoordinates e d => p a i.val) := by - intro a b hab - apply hp - have hv : (fun i => (p a i).val) = (fun i => (p b i).val) := by - apply two_sums_determine A he hd - · rw [hA,hA] - · rw [ht,ht] - · intro i hie hid - exact congrArg Fin.val (congrFun hab ⟨i,hie,hid⟩) - funext i - exact Fin.ext (congrFun hv i) - -/-- Once the two coordinates are eliminated all remaining gap weights sum - independently; any additional constraints may be dropped. -/ -theorem two_sums_product_bound {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] - {U L V : ℕ} (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) - (p : α → ι → Fin (U+1)) (hp : Function.Injective p) - (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) - (w : ι → Fin (U+1) → ℝ) (hw : ∀ i k, 0≤w i k) : - (∑ a, ∏ i : RemainingCoordinates e d, w i.val (p a i.val)) ≤ - ∏ i : RemainingCoordinates e d, ∑ k, w i.val k := by - classical - have hh := sum_injective_profile_le - (fun a => fun i : RemainingCoordinates e d => p a i.val) - (two_sums_restrict_injective A he hd p hp hA ht) - (fun _ => True) (fun _ => trivial) - (fun δ => ∏ i : RemainingCoordinates e d, w i.val (δ i)) - (fun δ => Finset.prod_nonneg (fun i _ => hw i.val (δ i))) - simp only [ite_true] at hh - exact hh.trans_eq (by rw [Finset.prod_univ_sum]; simp only [Fintype.piFinset_univ]) - -/-- The sum of doubled coarse gaps to a specified period label is exact, - including the half endpoint cells in the source convention. -/ -theorem coarsePeriodGap_prefix {u r : ℕ} (j : Fin r → Fin u) (hj : StrictMono j) - (i : Fin r) : (∑ g∈Finset.Iic i.castSucc, coarsePeriodGap j g) = 2*(j i).val+1 := by - classical - have hg := tupleGap_prefix j hj i - have hz : (0 : Fin (r+1)) ∈ Finset.Iic i.castSucc := by simp - have hl : ∀ g∈Finset.Iic i.castSucc, g≠Fin.last r := by - intro g hg he - have hle := Finset.mem_Iic.mp hg - have hval : g.val ≤ i.val := hle - have he' := congrArg Fin.val he - simp only [Fin.val_last] at he' - omega - have hc : (∑ g∈Finset.Iic i.castSucc, - if g=0 ∨ g=Fin.last r then 1 else 2) = 2*i.val+1 := by - have hsub : (∑ g∈(Finset.Iic i.castSucc).erase 0, - if g=0 ∨ g=Fin.last r then 1 else 2) = 2*i.val := by - have hc : ((Finset.Iic i.castSucc).erase 0).card = i.val := by - rw [Finset.card_erase_of_mem hz,Fin.card_Iic] - simp - calc - _ = ∑ _g∈(Finset.Iic i.castSucc).erase 0, 2 := by - apply Finset.sum_congr rfl - intro g hg - rw [ite_eq_right (not_or.mpr ⟨(Finset.mem_erase.mp hg).1, - hl g (Finset.mem_erase.mp hg).2⟩)] - _ = _ := by simp [hc,Nat.mul_comm] - have hsum := Finset.sum_erase_add (Finset.Iic i.castSucc) - (fun g => if g=0 ∨ g=Fin.last r then 1 else 2) hz - rw [hsub] at hsum - simpa using hsum.symm - simp only [coarsePeriodGap,Finset.sum_add_distrib,← Finset.mul_sum] - omega - -/-- The full inverse-square-root sum, including the zero cell (whose - value is zero), has the same elementary integral bound. -/ -theorem fin_sum_inverse_sqrt (U : ℕ) : - (∑ k : Fin (U+1), (Real.sqrt (k.val:ℝ))⁻¹) ≤ 2*Real.sqrt U := by - rw [Fin.sum_univ_succ] - simp only [Fin.val_zero, Nat.cast_zero, Real.sqrt_zero, inv_zero,zero_add,Fin.val_succ] - have h := sum_inverse_sqrt U - rw [Finset.sum_range] at h - simpa only [Nat.cast_add,Nat.cast_one] using h - -theorem prod_two_coordinates {ι : Type*} [Fintype ι] [DecidableEq ι] - {e d : ι} (hed : e≠d) (f : ι → ℝ) : - (∏ i, f i) = f e*f d*∏ i : RemainingCoordinates e d, f i.val := by - have hd : d∈Finset.univ.erase e := by simp [hed.symm] - have h1 := Finset.prod_erase_mul Finset.univ f (Finset.mem_univ e) - have h2 := Finset.prod_erase_mul (Finset.univ.erase e) f hd - have hrem : (∏ i∈(Finset.univ.erase e).erase d, f i) = - ∏ i : RemainingCoordinates e d, f i.val := - Finset.prod_subtype _ (by intro i; simp [and_comm]) f - rw [← h1,← h2,hrem] - ring - -theorem inverse_sqrt_pair {x y R : ℝ} (hR : 0 (Real.sqrt (k.val:ℝ))⁻¹) (fun _ _ => by positivity) - _ ≤ R⁻¹*∏ _i : RemainingCoordinates e d, (2*Real.sqrt U) := by - apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hR.le) - exact Finset.prod_le_prod₀ (fun _ _ => by positivity) (fun _ _ => fin_sum_inverse_sqrt U) - _ = _ := by simp - -/-- The fixed involved label is a genuine geometric fiber, not an extra - analytic hypothesis on the rank kernel. -/ -def FixedPeriodTuple (u r : ℕ) (a : Fin r) (h : Fin u) := - {j : IncreasingTuple u r // j.val a=h} - -noncomputable instance fixedPeriodTupleFintype (u r : ℕ) (a : Fin r) (h : Fin u) : - Fintype (FixedPeriodTuple u r a h) := by - unfold FixedPeriodTuple - exact Fintype.ofFinite _ - -def fixedPeriodProfile {u r : ℕ} (a : Fin r) (h : Fin u) (j : FixedPeriodTuple u r a h) : - Fin (r+1) → Fin (2*u+1) := fun i => - ⟨coarsePeriodGap j.val.val i, Nat.lt_succ_of_le - (coarsePeriodGap_le (Nat.zero_lt_of_lt a.isLt) j.val.val j.val.property i)⟩ - -theorem fixedPeriodProfile_injective {u r : ℕ} (a : Fin r) (h : Fin u) : - Function.Injective (fixedPeriodProfile a h) := by - intro j k hjk - apply Subtype.ext - apply Subtype.ext - apply coarsePeriodGap_injective j.val.property k.val.property - funext i - exact congrArg Fin.val (congrFun hjk i) - -theorem fixedPeriodProfile_prefix {u r : ℕ} (a : Fin r) (h : Fin u) - (j : FixedPeriodTuple u r a h) : - (∑ i∈Finset.Iic a.castSucc, (fixedPeriodProfile a h j i).val)=2*h.val+1 := by - change (∑ i∈Finset.Iic a.castSucc, coarsePeriodGap j.val.val i)=_ - rw [coarsePeriodGap_prefix _ j.val.property,j.property] - -theorem fixedPeriodProfile_total {u r : ℕ} (a : Fin r) (h : Fin u) - (j : FixedPeriodTuple u r a h) : - (∑ i, (fixedPeriodProfile a h j i).val)=2*u := - coarsePeriodGap_sum (Nat.zero_lt_of_lt a.isLt) j.val.val j.val.property - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction - -/-- An elementary centered MGF bound valid on both sides of the mean, - with constants independent of the Bernoulli parameter. -/ -theorem binomialMass_centered_mgf (n : ℕ) {p t : ℝ} - (hp : p∈Set.Icc 0 1) (ht : |t|≤1) : - (∑ k∈Finset.range (n+1), binomialMass n p k*Real.exp (t*((k:ℝ)-n*p))) ≤ - Real.exp ((n:ℝ)*t^2) := by - have he := (abs_le.mp (Real.abs_exp_sub_one_sub_id_le ht)).2 - have hn : 0≤(n:ℝ)*p := mul_nonneg (Nat.cast_nonneg _) hp.1 - have hn' : (n:ℝ)*p≤n := mul_le_of_le_one_right (Nat.cast_nonneg _) hp.2 - calc - _ = Real.exp (-t*(n:ℝ)*p)* - ∑ k∈Finset.range (n+1), binomialMass n p k*Real.exp (t*k) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _ - rw [mul_left_comm,← Real.exp_add] - congr 2 - ring - _ ≤ Real.exp (-t*(n:ℝ)*p)*Real.exp ((n:ℝ)*p*(Real.exp t-1)) := - mul_le_mul_of_nonneg_left (binomialMass_mgf_le n hp t) (Real.exp_nonneg _) - _ ≤ Real.exp ((n:ℝ)*t^2) := by - rw [← Real.exp_add] - apply Real.exp_le_exp.mpr - have he' := mul_le_mul_of_nonneg_left he hn - have hs := mul_le_mul_of_nonneg_right hn' (sq_nonneg t) - nlinarith only [he',hs] - -/-- Either signed deviation has the same Chernoff estimate. -/ -theorem binomialMass_signed_tail (n : ℕ) {p t a ε : ℝ} - (hp : p∈Set.Icc 0 1) (ht : t∈Set.Icc 0 1) (hε : ε=1 ∨ ε= -1) : - (∑ k∈(Finset.range (n+1)).filter (fun k : ℕ => a≤ε*((k:ℝ)-n*p)), binomialMass n p k) ≤ - Real.exp (-t*a+(n:ℝ)*t^2) := by - have heps : |t*ε|≤1 := by rcases hε with rfl | rfl <;> simpa [abs_of_nonneg ht.1] using ht.2 - have hm := finite_exp_markov (Finset.range (n+1)) (binomialMass n p) - (fun k : ℕ => ε*((k:ℝ)-n*p)) (fun k _ => binomialMass_nonneg n k hp) a t ht.1 - calc - _ ≤ Real.exp (-t*a)*∑ k∈Finset.range (n+1), - binomialMass n p k*Real.exp ((t*ε)*((k:ℝ)-n*p)) := by - simpa only [mul_assoc] using hm - _ ≤ Real.exp (-t*a)*Real.exp ((n:ℝ)*(t*ε)^2) := - mul_le_mul_of_nonneg_left (binomialMass_centered_mgf n hp heps) (Real.exp_nonneg _) - _ = _ := by rcases hε with rfl | rfl <;> simp [Real.exp_add] - -/-- A uniform two-sided tail at any finite cutoff. Unlike a quoted - concentration theorem, this follows here from the finite binomial MGF. -/ -theorem binomialMass_abs_tail (n : ℕ) {p t a : ℝ} - (hp : p∈Set.Icc 0 1) (ht : t∈Set.Icc 0 1) : - (∑ k∈(Finset.range (n+1)).filter (fun k : ℕ => a≤|(k:ℝ)-n*p|), binomialMass n p k) ≤ - 2*Real.exp (-t*a+(n:ℝ)*t^2) := by - have hpoint (k : ℕ) : (if a≤|(k:ℝ)-n*p| then binomialMass n p k else 0) ≤ - (if a≤(k:ℝ)-n*p then binomialMass n p k else 0)+ - (if a≤-((k:ℝ)-n*p) then binomialMass n p k else 0) := by - have hn := binomialMass_nonneg n k hp - by_cases h : a≤|(k:ℝ)-n*p| - · rw [ite_eq_left h] - have hh := le_abs.mp h - rcases hh with h1 | h2 - · rw [ite_eq_left h1] - split_ifs <;> linarith - · rw [ite_eq_left h2] - split_ifs <;> linarith - · rw [ite_eq_right h] - split_ifs <;> linarith - have hh := Finset.sum_le_sum (s := Finset.range (n+1)) (fun k _ => hpoint k) - rw [Finset.sum_add_distrib,← Finset.sum_filter,← Finset.sum_filter,← Finset.sum_filter] at hh - have h1 := binomialMass_signed_tail n (a:=a) hp ht (Or.inl rfl : (1:ℝ)=1 ∨ (1:ℝ)= -1) - have h2 := binomialMass_signed_tail n (a:=a) hp ht (Or.inr rfl : (-1:ℝ)=1 ∨ (-1:ℝ)= -1) - simp only [one_mul,neg_one_mul] at h1 h2 - linarith - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction - -/-- Cardinality bookkeeping for the two eliminated gap coordinates. -/ -theorem remainingCoordinates_card {ι : Type*} [Fintype ι] [DecidableEq ι] - {e d : ι} (hed : e≠d) : - Fintype.card (RemainingCoordinates e d)=Fintype.card ι-2 := by - classical - have hset : (Finset.univ.filter (fun i : ι => i≠e ∧ i≠d)) = (Finset.univ.erase e).erase d := by - ext i - simp [and_comm] - rw [Fintype.card_subtype, hset] - rw [Finset.card_erase_of_mem (by simp [hed.symm]), - Finset.card_erase_of_mem (Finset.mem_univ e)] - simp only [Finset.card_univ] - omega - -/-- A finite sum's largest entry on a nonempty set controls its average, - with the full number of coordinates in place of the subset cardinality. -/ -theorem exists_large_in_subset {ι : Type*} [Fintype ι] [DecidableEq ι] - (A : Finset ι) (hA : A.Nonempty) (x : ι → ℝ) (hx : ∀ i, 0≤x i) - {R : ℝ} (hR : R*Fintype.card ι ≤ ∑ i∈A, x i) : - ∃ e∈A, R≤x e := by - obtain ⟨e,he,hm⟩ := A.exists_max_image x hA - refine ⟨e,he,?_⟩ - have hc : (A.card:ℝ)≤Fintype.card ι := by exact_mod_cast Finset.card_le_univ A - have hcard : (0:ℝ) hm i hi) - _ = (A.card:ℝ)*x e := by simp - _ ≤ _ := mul_le_mul_of_nonneg_right hc (hx e) - nlinarith - -/-- Covering the fixed-sum profile by its selected largest coordinates - costs only the square of its (fixed) dimension. -/ -theorem two_sided_large_gaps_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] - {U L V : ℕ} (A : Finset ι) - (p : α → ι → Fin (U+1)) (hp : Function.Injective p) - (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) - {R : ℝ} (hR : 0 p a.val) (hp.comp Subtype.val_injective) - (fun a => hA a.val) (fun a => ht a.val) hR - (fun a => by have h := congrArg Prod.fst a.property; simpa only [f] using h ▸ heR a.val) - (fun a => by have h := congrArg Prod.snd a.property; simpa only [f] using h ▸ hdR a.val) - simpa only [W,remainingCoordinates_card hzd] using hh - · have : IsEmpty {a // f a=z} := not_nonempty_iff.mp hne - simp only [Fintype.sum_empty] - positivity - calc - _ = ∑ z : ι × ι, ∑ a : {a // f a=z}, W a.val := by - exact (Fintype.sum_fiberwise f W).symm - _ ≤ ∑ _z : ι × ι, R⁻¹*(2*Real.sqrt U)^(Fintype.card ι-2) := - Finset.sum_le_sum (fun z _ => hfiber z) - _ = _ := by simp [pow_two,mul_assoc] - -/-- The fixed central label leaves a macroscopic sum on both sides. -/ -theorem fixedPeriodProfile_central_sum {u r : ℕ} (a : Fin r) (h : Fin u) - (hleft : (u:ℝ)/3≤2*h.val+1) - (hright : (u:ℝ)/3≤2*u-(2*h.val+1)) : - (∑ j : FixedPeriodTuple u r a h, - ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹) ≤ - ((r+1:ℕ):ℝ)^2 * ((u:ℝ)/(3*(r+1:ℝ)))⁻¹ * - (2*Real.sqrt (2*u:ℕ))^(r-1) := by - classical - have hu : (0:ℝ) (p j i).val) - (fun _ => Nat.cast_nonneg _) - have hs := fixedPeriodProfile_prefix a h j - have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs - rw [hs'] - simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] - convert hleft using 1; field_simp - have hD (j : FixedPeriodTuple u r a h) : - ∃ d∉A, (u:ℝ)/(3*(r+1:ℝ))≤(p j d).val := by - have ha : a.val ((p j i).val:ℝ)) (fun _ => Nat.cast_nonneg _) (R := (u:ℝ)/(3*(r+1:ℝ))) (by - have hs := fixedPeriodProfile_prefix a h j - have ht := fixedPeriodProfile_total a h j - have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs - have ht' : (∑ i, ((p j i).val:ℝ))=2*u := by exact_mod_cast ht - have hc := Finset.sum_compl_add_sum A (fun i => ((p j i).val:ℝ)) - have hsum : (∑ i∈Aᶜ, ((p j i).val:ℝ))=2*u-(2*h.val+1) := by linarith - rw [hsum] - simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] - convert hright using 1; field_simp) - exact ⟨d,Finset.mem_compl.mp hd,hdR⟩ - have hh := two_sided_large_gaps_sum A p (fixedPeriodProfile_injective a h) - (fixedPeriodProfile_prefix a h) (fixedPeriodProfile_total a h) hR hL hD - simpa only [p,fixedPeriodProfile,Fin.val_mk,Fintype.card_fin,show r+1-2=r-1 by omega] using hh - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction - -/-- Any finite cutoff only removes nonnegative mass from the full binomial - support, even if the cutoff extends beyond that support. -/ -theorem binomialMass_cutoff_filter_le (n U : ℕ) {p : ℝ} (hp : p∈Set.Icc 0 1) - (P : ℕ → Prop) [DecidablePred P] : - (∑ k : Fin (U+1), if P k.val then binomialMass n p k.val else 0) ≤ - ∑ k∈(Finset.range (n+1)).filter P, binomialMass n p k := by - rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => if P k then binomialMass n p k else 0) (U+1),Finset.sum_filter] - by_cases hU : U≤n - · apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono (by omega)) - intro k _ _ - split_ifs - · exact binomialMass_nonneg n k hp - · rfl - · apply le_of_eq - symm - apply Finset.sum_subset (Finset.range_mono (by omega)) - intro k _ hk - have hnk : n True) (fun _ => trivial) - (fun δ => ∏ i, w' i (δ i)) (fun δ => Finset.prod_nonneg (fun i _ => hw' i (δ i))) - simpa only [ite_true] using hh - _ = ∏ i, ∑ k, w' i k := (Fintype.prod_sum _).symm - _ ≤ ∏ i : ι, if i=e then T else 1 := - Finset.prod_le_prod₀ (fun i _ => Finset.sum_nonneg (fun k _ => hw' i k)) (fun i _ => hsum i) - _ = T := by simp - -/-- Exponentially small clipping loss for a single gap of the actual - conditional retained-subset rank kernel. -/ -theorem subsetRankKernel_gap_tail {n l r : ℕ} (hl : l≤n) - (p : Fin r → Fin n) (hp : StrictMono p) (e : Fin (r+1)) - {θ t a : ℝ} (hθ : θ∈Set.Ioo 0 1) (ht : t∈Set.Icc 0 1) : - (∑ v : IncreasingTuple l r, - if a≤|(tupleGap v.val e:ℝ)-(tupleGap p e:ℝ)*θ| - then subsetRankKernel hl p v.val else 0) ≤ - θ^r / binomialMass n θ l * - (2*Real.exp (-t*a+(tupleGap p e:ℝ)*t^2)) := by - classical - have hθ' : θ∈Set.Icc 0 1 := ⟨hθ.1.le,hθ.2.le⟩ - let prof := rankGapProfile (n := l) (r := r) (Equiv.refl _) - let w (i : Fin (r+1)) (k : Fin (l-r+1)) := binomialMass (tupleGap p i) θ k.val - have hw (i k) : 0≤w i k := binomialMass_nonneg _ _ hθ' - have hs (i) : (∑ k, w i k)≤1 := by - have hh := binomialMass_cutoff_filter_le (tupleGap p i) (l-r) hθ' (fun _ => True) - simpa only [ite_true,Finset.filter_true,sum_binomialMass] using hh - have ht' : (∑ k : Fin (l-r+1), - if a≤|(k.val:ℝ)-(tupleGap p e:ℝ)*θ| then w e k else 0) ≤ - 2*Real.exp (-t*a+(tupleGap p e:ℝ)*t^2) := by - exact (binomialMass_cutoff_filter_le (tupleGap p e) (l-r) hθ' - (fun k : ℕ => a≤|(k:ℝ)-(tupleGap p e:ℝ)*θ|)).trans - (binomialMass_abs_tail _ hθ' ht) - have hh := profile_coordinate_event_le prof (rankGapProfile_injective _) w hw hs e - (fun k => a≤|(k.val:ℝ)-(tupleGap p e:ℝ)*θ|) (by positivity) ht' - have hfac : 0≤θ^r / binomialMass n θ l := - div_nonneg (pow_nonneg hθ.1.le _) (binomialMass_nonneg _ _ hθ') - calc - _ = θ^r / binomialMass n θ l * - ∑ v : IncreasingTuple l r, - if a≤|(tupleGap v.val e:ℝ)-(tupleGap p e:ℝ)*θ| - then ∏ i, binomialMass (tupleGap p i) θ (tupleGap v.val i) else 0 := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro v _ - split_ifs - · exact subsetRankKernel_binomial_formula hl p hp v.val v.property θ hθ - · simp - _ ≤ _ := mul_le_mul_of_nonneg_left (by - simpa only [prof,rankGapProfile,Equiv.refl_apply,w] using hh) hfac - -/-- A coordinatewise rank region has a union-bound clipping estimate. -/ -theorem subsetRankKernel_outside_region {n l r : ℕ} (hl : l≤n) - (p : Fin r → Fin n) (hp : StrictMono p) - {θ t a : ℝ} (hθ : θ∈Set.Ioo 0 1) (ht : t∈Set.Icc 0 1) : - (∑ v : IncreasingTuple l r, - if ∃ i, a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0) ≤ - ((r+1:ℕ):ℝ)*θ^r / binomialMass n θ l * - (2*Real.exp (-t*a+(n:ℝ)*t^2)) := by - classical - have hθ' : θ∈Set.Icc 0 1 := ⟨hθ.1.le,hθ.2.le⟩ - have hpoint (v : IncreasingTuple l r) : - (if ∃ i, a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0) ≤ - ∑ i, if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0 := by - have hn (i) : 0≤(if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0) := by - split_ifs - · exact subsetRankKernel_nonneg hl p v.val - · rfl - split_ifs with h - · obtain ⟨e,he⟩ := h - have hh := Finset.single_le_sum (fun i _ => hn i) (Finset.mem_univ e) - simpa only [ite_eq_left he] using hh - · exact Finset.sum_nonneg (fun i _ => hn i) - calc - _ ≤ ∑ v : IncreasingTuple l r, ∑ i, - if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0 := Finset.sum_le_sum (fun v _ => hpoint v) - _ = ∑ i, ∑ v : IncreasingTuple l r, - if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0 := Finset.sum_comm - _ ≤ ∑ _i : Fin (r+1), θ^r / binomialMass n θ l * - (2*Real.exp (-t*a+(n:ℝ)*t^2)) := by - apply Finset.sum_le_sum - intro i _ - apply (subsetRankKernel_gap_tail hl p hp i hθ ht).trans - apply mul_le_mul_of_nonneg_left _ (div_nonneg (pow_nonneg hθ.1.le _) (binomialMass_nonneg _ _ hθ')) - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Real.exp_le_exp.mpr - have hgap : tupleGap p i≤n := (tupleGap_le_remainder ⟨p,hp⟩ i).trans (Nat.sub_le _ _) - have hg : (tupleGap p i:ℝ)≤n := by exact_mod_cast hgap - have hh := mul_le_mul_of_nonneg_right hg (sq_nonneg t) - linarith - _ = _ := by simp; ring - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction - -/-- An inverse square root at an integer, extended by zero at zero, - never exceeds one. -/ -theorem inverse_sqrt_nat_le_one (k : ℕ) : (Real.sqrt (k:ℝ))⁻¹≤1 := by - by_cases hk : k=0 - · simp [hk] - have hk' : (1:ℝ)≤k := by exact_mod_cast (Nat.one_le_iff_ne_zero.mpr hk) - have hs : 1≤Real.sqrt (k:ℝ) := by simpa using Real.sqrt_le_sqrt hk' - exact (inv_le_one₀ (by positivity : 0 k.val≤M)).card:ℝ) := by simp - _ ≤ M+1 := by - have hh : (Finset.univ.filter (fun k : Fin (U+1) => k.val≤M)).card≤M+1 := by - rw [← Finset.card_range (M+1)] - apply Finset.card_le_card_of_injOn Fin.val - (fun k hk => by - have hh := (Finset.mem_filter.mp hk).2 - exact Finset.mem_range.mpr (Nat.lt_succ_of_le hh)) - intro k _ j _ hkj; exact Fin.ext hkj - exact_mod_cast hh - -theorem prod_one_special {ι : Type*} [Fintype ι] [DecidableEq ι] - (e : ι) (A B : ℝ) : - (∏ i : ι, if i=e then A else B)=A*B^(Fintype.card ι-1) := by - rw [← Finset.mul_prod_erase Finset.univ (fun i => if i=e then A else B) (Finset.mem_univ e)] - simp only [ite_true] - have hh : (∏ i∈Finset.univ.erase e, if i=e then A else B)= - ∏ _i∈Finset.univ.erase e, B := by - apply Finset.prod_congr rfl - intro i hi - exact ite_eq_right (Finset.mem_erase.mp hi).1 - rw [hh] - simp - -/-- Refined two-gap elimination when a third gap has bounded size. -/ -theorem two_large_bounded_gap_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] - {U L V M : ℕ} (A : Finset ι) {e d c : ι} (he : e∈A) (hd : d∉A) - (hce : c≠e) (hcd : c≠d) - (p : α → ι → Fin (U+1)) (hp : Function.Injective p) - (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) - {R : ℝ} (hR : 0 positivity - have hwP (a i) : w i (p a i)=(Real.sqrt ((p a i).val:ℝ))⁻¹ := by - by_cases hi : i=c - · subst i; simp only [w,ite_true,ite_eq_left (hcM a)] - · simp only [w,ite_eq_right hi] - have hwS (i : RemainingCoordinates e d) : (∑ k, w i.val k)≤ - if i=c' then (M+1:ℝ) else 2*Real.sqrt U := by - by_cases hi : i=c' - · subst i - simpa only [c',w,ite_true] using fin_bounded_inverse_sqrt U M - · have hic : i.val≠c := by intro h; apply hi; exact Subtype.ext h - simpa only [w,ite_eq_right hi,ite_eq_right hic] using fin_sum_inverse_sqrt U - calc - _ ≤ ∑ a, R⁻¹*∏ i : RemainingCoordinates e d, w i.val (p a i.val) := by - apply Finset.sum_le_sum - intro a _ - simp_rw [hwP] - rw [prod_two_coordinates hed] - exact mul_le_mul_of_nonneg_right (inverse_sqrt_pair hR (heR a) (hdR a)) (by positivity) - _ = R⁻¹*∑ a, ∏ i : RemainingCoordinates e d, w i.val (p a i.val) := by rw [Finset.mul_sum] - _ ≤ R⁻¹*∏ i : RemainingCoordinates e d, ∑ k, w i.val k := - mul_le_mul_of_nonneg_left (two_sums_product_bound A he hd p hp hA ht w hw) (inv_nonneg.mpr hR.le) - _ ≤ R⁻¹*∏ i : RemainingCoordinates e d, if i=c' then (M+1:ℝ) else 2*Real.sqrt U := by - apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hR.le) - exact Finset.prod_le_prod₀ (fun i _ => Finset.sum_nonneg (fun k _ => hw i.val k)) (fun i _ => hwS i) - _ = _ := by - rw [prod_one_special,remainingCoordinates_card hed] - simp only [Nat.sub_sub] - ring - -/-- A small internal gap cannot be either selected macroscopic gap. - The bound retains the extra factor u^(-1/2) needed for nonlinear terms. -/ -theorem two_sided_bounded_gaps_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] - {U L V M : ℕ} (A : Finset ι) (c : ι) - (p : α → ι → Fin (U+1)) (hp : Function.Injective p) - (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) - {R : ℝ} (hR : 0 p a.val) (hp.comp Subtype.val_injective) - (fun a => hA a.val) (fun a => ht a.val) hR - (fun a => by have h := congrArg Prod.fst a.property; simpa only [f] using h ▸ heR a.val) - (fun a => by have h := congrArg Prod.snd a.property; simpa only [f] using h ▸ hdR a.val) - (fun a => hcM a.val) - · have : IsEmpty {a // f a=z} := not_nonempty_iff.mp hne - simp only [Fintype.sum_empty] - positivity - calc - _ = ∑ z : ι × ι, ∑ a : {a // f a=z}, W a.val := (Fintype.sum_fiberwise f W).symm - _ ≤ ∑ _z : ι × ι, R⁻¹*(M+1)*(2*Real.sqrt U)^(Fintype.card ι-3) := - Finset.sum_le_sum (fun z _ => hfiber z) - _ = _ := by simp [pow_two,mul_assoc] - -end TraceReconstruction - - -noncomputable section -open scoped Classical -namespace TraceReconstruction - -/-- The literal rank-clipping rectangles used in the manuscript, with - doubled coarse gaps to avoid half-integer natural indices. Only the - first and internal gaps are needed to determine the period tuple. -/ -def PeriodRankRegion {u l r : ℕ} (m : ℕ) (θ : ℝ) - (j : IncreasingTuple u r) (v : IncreasingTuple l r) : Prop := - ∀ i : Fin r, |(tupleGap v.val i.castSucc:ℝ)- - θ*m*(coarsePeriodGap j.val i.castSucc:ℝ)/2| < (m:ℝ)/8 - -/-- Enough accuracy to distinguish two integer gap lengths. -/ -theorem nearby_gap_centers_equal {x y : ℕ} {z θ m : ℝ} - (hθ : 1 / 2 ≤ θ) (hm : 0 < m) - (hx : |z - θ * m * x / 2| < m / 8) (hy : |z - θ * m * y / 2| < m / 8) : x = y := by - have hx' := abs_lt.mp hx - have hy' := abs_lt.mp hy - have hscale : m / 4 ≤ θ * m / 2 := by nlinarith - by_contra hxy - obtain h | h := lt_or_gt_of_ne hxy - · have h' : (x:ℝ)+1≤y := by exact_mod_cast h - have hh := mul_le_mul_of_nonneg_left h' (by positivity : 0 ≤ θ * m / 2) - nlinarith - · have h' : (y:ℝ)+1≤x := by exact_mod_cast h - have hh := mul_le_mul_of_nonneg_left h' (by positivity : 0 ≤ θ * m / 2) - nlinarith - -/-- Regions for distinct tagged period tuples are genuinely disjoint, - before any coefficient or orientation averaging. -/ -theorem periodRankRegion_unique {u l r m : ℕ} (hm : 0 < m) {θ : ℝ} (hθ : 1 / 2 ≤ θ) - {j k : IncreasingTuple u r} {v : IncreasingTuple l r} - (hj : PeriodRankRegion m θ j v) (hk : PeriodRankRegion m θ k v) : j=k := by - apply Subtype.ext - by_cases hr : r=0 - · subst r; exact Subsingleton.elim _ _ - have hg (i : Fin r) : coarsePeriodGap j.val i.castSucc=coarsePeriodGap k.val i.castSucc := - nearby_gap_centers_equal hθ (by exact_mod_cast hm) (hj i) (hk i) - have hsum := coarsePeriodGap_sum (Nat.pos_of_ne_zero hr) j.val j.property - have hsum' := coarsePeriodGap_sum (Nat.pos_of_ne_zero hr) k.val k.property - have hgSum : (∑ i : Fin r, coarsePeriodGap j.val i.castSucc)= - ∑ i : Fin r, coarsePeriodGap k.val i.castSucc := Finset.sum_congr rfl (fun i _ => hg i) - rw [Fin.sum_univ_castSucc] at hsum hsum' - have hlast : coarsePeriodGap j.val (Fin.last r)=coarsePeriodGap k.val (Fin.last r) := by omega - apply coarsePeriodGap_injective j.property k.property - funext i - refine Fin.lastCases hlast (fun i => hg i) i - -/-- Orthogonality of a finite family with pointwise disjoint supports. -/ -theorem disjoint_support_sum_sq {α β : Type*} [Fintype α] [Fintype β] - (f : α → β → ℝ) (hf : ∀ a b, a≠b → ∀ v, f a v*f b v=0) : - (∑ v, (∑ a, f a v)^2) = ∑ a, ∑ v, f a v^2 := by - classical - have hp (v) : (∑ a, f a v)^2=∑ a, f a v^2 := by - rw [pow_two,Finset.sum_mul] - apply Finset.sum_congr rfl - intro a _ - rw [Finset.mul_sum] - rw [Finset.sum_eq_single a] - · ring - · intro b _ hba - exact hf a b hba.symm v - · intro ha - exact False.elim (ha (Finset.mem_univ a)) - simp_rw [hp] - exact Finset.sum_comm - -/-- Squared norm of the clipped sum is at most the sum of the original - squared norms, with arbitrary signed multipliers on each tuple. -/ -theorem period_clipped_square_sum {u l r m : ℕ} (hm : 0 < m) {θ : ℝ} (hθ : 1 / 2 ≤ θ) - (W : IncreasingTuple u r → IncreasingTuple l r → ℝ) - (a : IncreasingTuple u r → ℝ) : - (∑ v, (∑ j, if PeriodRankRegion m θ j v then a j*W j v else 0)^2) ≤ - ∑ j, a j^2*∑ v, W j v^2 := by - classical - rw [disjoint_support_sum_sq _ (by - intro j k hjk v - by_cases hj : PeriodRankRegion m θ j v - · have hk : ¬PeriodRankRegion m θ k v := fun hk => hjk (periodRankRegion_unique hm hθ hj hk) - simp only [ite_eq_left hj,ite_eq_right hk,mul_zero] - · simp only [ite_eq_right hj,zero_mul])] - apply Finset.sum_le_sum - intro j _ - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro v _ - split_ifs - · exact le_of_eq (mul_pow _ _ _) - · simp only [zero_pow (by norm_num : 2 ≠ 0)] - exact mul_nonneg (sq_nonneg _) (sq_nonneg _) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -instance : Fintype GapDifference := - ⟨{.unchanged,.first,.second}, by intro k; cases k <;> simp⟩ - -theorem sum_gapDifference (f : GapDifference → ℝ) : - (∑ k, f k)=f .unchanged+f .first+f .second := by - change (∑ k ∈ ({.unchanged,.first,.second} : Finset GapDifference), f k)=_ - simp [Finset.sum_insert]; ring - -/-- The sign-dependent displacement in {-1,0,1}, represented by Fin 3. -/ -def motifShift (χ β τ : ℝ) : Fin 3 := - if χ=0 then 1 else if β*τ=1 then 2 else 0 - -/-- Coefficients of 1 + χ V + τ β D. -/ -def motifDifferenceWeight (χ β τ : ℝ) : GapDifference → ℝ - | .unchanged => 1 | .first => τ*β | .second => χ - -/-- The centered operator expansion is an exact displacement, not an - approximation of the trace kernel. -/ -theorem motif_positional_identity {χ β τ : ℝ} (hβ : IsMotifValue χ β) - (hτ : IsTypeSign τ) (a : Fin 3) : - (∑ k, motifDifferenceWeight χ β τ k * positionalWeight k a)= - if a=motifShift χ β τ then 1 else 0 := by - rw [sum_gapDifference] - rcases hβ with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> - rcases hτ with rfl | rfl <;> fin_cases a <;> - norm_num [motifDifferenceWeight,motifShift,positionalWeight,Fin.ext_iff] - -theorem product_function_delta {ι κ : Type*} [Fintype ι] [DecidableEq κ] - (a b : ι → κ) : - (∏ i, if a i=b i then (1:ℝ) else 0)=if a=b then 1 else 0 := by - classical - by_cases h : a=b - · subst a; simp - · rw [ite_eq_right h] - obtain ⟨i,hi⟩ := Function.ne_iff.mp h - exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) - -/-- Tensorization of the exact local shift identity, with an arbitrary - array W (in particular any literal retained-subset rank kernel). -/ -theorem motif_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) (τ : ℝ) - (hβ : ∀ h, IsMotifValue (χ h) (β h)) (hτ : IsTypeSign τ) - (W : (Fin r → Fin 3) → ℝ) : - W (fun h => motifShift (χ h) (β h) τ)= - ∑ k : Fin r → GapDifference, - (∏ h, motifDifferenceWeight (χ h) (β h) τ (k h))* - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by - classical - symm - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - calc - _ = ∑ a, (∑ k : Fin r → GapDifference, - ∏ h, motifDifferenceWeight (χ h) (β h) τ (k h)*positionalWeight (k h) (a h))*W a := by - apply Finset.sum_congr rfl - intro a _ - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro k _ - rw [Finset.prod_mul_distrib] - ring - _ = ∑ a, (∏ h, if a h=motifShift (χ h) (β h) τ then (1:ℝ) else 0)*W a := by - apply Finset.sum_congr rfl - intro a _ - rw [← Fintype.prod_sum (fun h k => motifDifferenceWeight (χ h) (β h) τ k * positionalWeight k (a h))] - simp_rw [motif_positional_identity (hβ _) hτ] - _ = _ := by simp_rw [product_function_delta]; simp - -def firstDifferenceCount {r : ℕ} (k : Fin r → GapDifference) : ℕ := - (Finset.univ.filter fun h => k h = .first).card - -def secondDifferenceCount {r : ℕ} (k : Fin r → GapDifference) : ℕ := - (Finset.univ.filter fun h => k h = .second).card - -/-- Every factor of the hypothesis sign comes precisely from a D operator. -/ -theorem motifDifferenceWeight_product {r : ℕ} (χ β : Fin r → ℝ) (τ : ℝ) - (k : Fin r → GapDifference) : - (∏ h, motifDifferenceWeight (χ h) (β h) τ (k h))= - τ^firstDifferenceCount k *∏ h, motifDifferenceWeight (χ h) (β h) 1 (k h) := by - classical - have hw (h) : motifDifferenceWeight (χ h) (β h) τ (k h)= - (if k h=.first then τ else 1)*motifDifferenceWeight (χ h) (β h) 1 (k h) := by - cases k h <;> simp [motifDifferenceWeight] - simp_rw [hw] - rw [Finset.prod_mul_distrib] - congr 1 - rw [← Finset.prod_filter] - simp [firstDifferenceCount] - -/-- The signed difference retains exactly the patterns having an odd - number of centered first differences, with the source's factor two. -/ -theorem motif_signed_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) - (hβ : ∀ h, IsMotifValue (χ h) (β h)) (W : (Fin r → Fin 3) → ℝ) : - W (fun h => motifShift (χ h) (β h) 1)- - W (fun h => motifShift (χ h) (β h) (-1))= - ∑ k : Fin r → GapDifference, - (if Odd (firstDifferenceCount k) then - 2*∏ h, motifDifferenceWeight (χ h) (β h) 1 (k h) else 0)* - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by - rw [motif_shift_expansion χ β 1 hβ (Or.inl rfl) W, - motif_shift_expansion χ β (-1) hβ (Or.inr rfl) W,← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro k _ - rw [motifDifferenceWeight_product χ β 1 k,motifDifferenceWeight_product χ β (-1) k] - rw [sign_pow_parity (Or.inr rfl : IsTypeSign (-1))] - simp only [one_pow,one_mul] - split_ifs <;> ring - -theorem difference_order_eq_counts {r : ℕ} (k : Fin r → GapDifference) : - (∑ h, (k h).order)=firstDifferenceCount k+2*secondDifferenceCount k := by - classical - have hd (h) : (k h).order=(if k h=.first then 1 else 0)+ - 2*(if k h=.second then 1 else 0) := by cases k h <;> simp [GapDifference.order] - simp_rw [hd] - rw [Finset.sum_add_distrib,← Finset.mul_sum] - simp [firstDifferenceCount,secondDifferenceCount] - -/-- The only signed pattern of order below three is the singleton D term. -/ -theorem odd_pattern_linear_or_order_three {r : ℕ} (k : Fin r → GapDifference) - (hk : Odd (firstDifferenceCount k)) : - (firstDifferenceCount k=1 ∧ secondDifferenceCount k=0) ∨ - 3≤∑ h, (k h).order := by - rw [difference_order_eq_counts] - obtain ⟨n,hn⟩ := hk - omega - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem shiftGapExtra_le {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : - shiftGapExtra a i ≤ 2*gapIncidence r i := by - have hl : Fin.cons (α := fun _ => ℕ) 0 (fun h => 2-(a h).val) i ≤ - 2*Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i := by - induction i using Fin.cases with - | zero => simp - | succ i => simp - have hr : Fin.snoc (α := fun _ => ℕ) (fun h => (a h).val) 0 i ≤ - 2*Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i := by - induction i using Fin.lastCases with - | last => simp - | cast i => simpa using Nat.le_of_lt_succ (a i).isLt - dsimp [shiftGapExtra,gapIncidence] - omega - -/-- A unit positional shift changes each actual rank gap by at most two. -/ -theorem tupleGap_shifted_close {n r : ℕ} (p : Fin r → Fin n) - (hp : SafeTaggedTuple p) (a : Fin r → Fin 3) (i : Fin (r+1)) : - |(tupleGap (shiftedTag p hp a) i:ℝ)-(tupleGap p i:ℝ)| ≤ 2 := by - rw [tupleGap_shifted,Nat.cast_add,Nat.cast_sub (gapIncidence_le p hp i)] - have hi : (gapIncidence r i:ℝ) ≤ 2 := by exact_mod_cast gapIncidence_le_two r i - have he : (shiftGapExtra a i:ℝ) ≤ 2*(gapIncidence r i:ℝ) := by exact_mod_cast shiftGapExtra_le a i - have h0 : (0:ℝ) ≤ shiftGapExtra a i := by positivity - apply abs_le.mpr - constructor <;> linarith - -theorem period_shifted_gap_rounding {u m r : ℕ} (hr : 0 < r) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) - (a : Fin r → Fin 3) (i : Fin (r+1)) : - |(tupleGap (shiftedTag (periodSlot off ∘ j.val) hsafe a) i:ℝ)- - (m:ℝ)*coarsePeriodGap j.val i/2| ≤ 6 := by - have ht := abs_sub_le (tupleGap (shiftedTag (periodSlot off ∘ j.val) hsafe a) i:ℝ) - (tupleGap (periodSlot off ∘ j.val) i:ℝ) ((m:ℝ)*coarsePeriodGap j.val i/2) - have h1 := tupleGap_shifted_close (periodSlot off ∘ j.val) hsafe a i - have h2 := period_gap_rounding hr off hoff hdiff j.val j.property i - linarith - -theorem coarse_outside_implies_gap_tail {z g c θ m : ℝ} - (hθ : θ ∈ Set.Icc 0 1) (hm : 128 ≤ m) (hg : |g-m*c/2| ≤ 6) - (hz : m/8 ≤ |z-θ*m*c/2|) : m/16 ≤ |z-g*θ| := by - have he : |g*θ-θ*m*c/2| ≤ 6 := by - have h := mul_le_mul_of_nonneg_right hg hθ.1 - rw [show g*θ-θ*m*c/2=(g-m*c/2)*θ by ring,abs_mul,abs_of_nonneg hθ.1] - exact h.trans (by nlinarith [hθ.2]) - have ht := abs_sub_le z (g*θ) (θ*m*c/2) - linarith - -/-- The manuscript's rank rectangles lose exponentially little mass for - every bounded shift of a tagged tuple. -/ -theorem period_shifted_outside_region {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) - (a : Fin r → Fin 3) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) : - (∑ v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else - subsetRankKernel hl (shiftedTag (periodSlot off ∘ j.val) hsafe a) v.val) ≤ - ((r+1:ℕ):ℝ)*θ^r /binomialMass (u*m) θ l * - (2*Real.exp (-(m:ℝ)/(1024*u))) := by - let p := shiftedTag (periodSlot off ∘ j.val) hsafe a - have hu' : (0:ℝ) < u := by exact_mod_cast hu - have ht : (1/(32*(u:ℝ))) ∈ Set.Icc 0 1 := by - constructor - · positivity - · apply (div_le_one (by positivity)).mpr - have : (1:ℝ) ≤ u := by exact_mod_cast hu - linarith - have hx : -(1/(32*(u:ℝ)))*((m:ℝ)/16)+((u*m:ℕ):ℝ)*(1/(32*(u:ℝ)))^2 = - -(m:ℝ)/(1024*u) := by push_cast; field_simp; ring - calc - _ ≤ ∑ v : IncreasingTuple l r, - if ∃ i, (m:ℝ)/16 ≤ |(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| - then subsetRankKernel hl p v.val else 0 := by - apply Finset.sum_le_sum - intro v _ - by_cases hv : PeriodRankRegion m θ j v - · simp only [ite_eq_left hv] - split_ifs - · exact subsetRankKernel_nonneg hl p v.val - · rfl - · simp only [PeriodRankRegion,not_forall,not_lt] at hv - obtain ⟨i,hi⟩ := hv - have he : ∃ i', (m:ℝ)/16 ≤ |(tupleGap v.val i':ℝ)-(tupleGap p i':ℝ)*θ| := - ⟨i.castSucc,coarse_outside_implies_gap_tail ⟨hθ.1.le,hθ.2.le⟩ - (by exact_mod_cast hm) (period_shifted_gap_rounding hr off hoff hdiff j hsafe a i.castSucc) hi⟩ - rw [ite_eq_left he] - split_ifs - · exact subsetRankKernel_nonneg hl p v.val - · rfl - _ ≤ _ := by - have hh := subsetRankKernel_outside_region hl p (shiftedTag_strictMono _ hsafe a) hθ ht (a := (m:ℝ)/16) - simpa only [hx] using hh - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The literal support indicator of the length-2^s signed block. -/ -def motifIndicator (s : ℕ) (z : ℤ) : ℝ := - if 0 ≤ z ∧ z < (2^s : ℕ) then 1 else 0 - -theorem prouhet_motif_value (s : ℕ) (z : ℤ) : - IsMotifValue (motifIndicator s z) ((prouhetSeries s).coeff z) := by - by_cases hz : 0 ≤ z ∧ z < (2^s : ℕ) - · right - refine ⟨by simp only [motifIndicator,ite_eq_left hz], ?_⟩ - have hv := (prouhetSeries_coeff_spec s).2 z hz.1 hz.2 - exact (abs_eq (by norm_num : (0:ℝ) ≤ 1)).mp hv - · left - refine ⟨by simp only [motifIndicator,ite_eq_right hz], ?_⟩ - apply (prouhetSeries_coeff_spec s).1 z - omega - -theorem motif_weight_abs_le (χ β : ℝ) (h : IsMotifValue χ β) (k : GapDifference) : - |motifDifferenceWeight χ β 1 k| ≤ 1 := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> cases k <;> - norm_num [motifDifferenceWeight] - -theorem motif_weight_abs_le_indicator (χ β : ℝ) (h : IsMotifValue χ β) - (k : GapDifference) (hk : k ≠ .unchanged) : - |motifDifferenceWeight χ β 1 k| ≤ χ := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> cases k <;> - norm_num [motifDifferenceWeight] at * - -/-- A kernel-pattern multiplier averaged over the actual finitely supported - anchor law. No independence of its involved positions is asserted. -/ -def motifPatternMultiplier {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (k : Fin r → GapDifference) : ℝ := - ∑ X ∈ π.coeff.support, π.coeff X * - ∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) - ((prouhetSeries s).coeff (j h-X)) 1 (k h) - -def linearPattern {r : ℕ} (h : Fin r) (a : Fin r) : GapDifference := - if a=h then .first else .unchanged - -theorem motif_linear_multiplier {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (h : Fin r) : - motifPatternMultiplier π s j (linearPattern h)= - (prouhetSeries s * π).coeff (j h) := by - classical - rw [mul_comm,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] - apply Finset.sum_congr rfl - intro X _ - congr 1 - have hw (a : Fin r) : motifDifferenceWeight (motifIndicator s (j a-X)) - ((prouhetSeries s).coeff (j a-X)) 1 (linearPattern h a)= - if a=h then (prouhetSeries s).coeff (j h-X) else 1 := by - by_cases ha : a=h <;> simp [linearPattern,ha,motifDifferenceWeight] - simp_rw [hw] - simp [sub_eq_neg_add] - -theorem motifPatternMultiplier_abs_le {r : ℕ} (π : IntSeries) - (hπ : ∀ X, 0 ≤ π.coeff X) (s : ℕ) (j : Fin r → ℤ) - (k : Fin r → GapDifference) (h : Fin r) (hk : k h ≠ .unchanged) : - |motifPatternMultiplier π s j k| ≤ - ∑ X ∈ π.coeff.support, π.coeff X*motifIndicator s (j h-X) := by - classical - apply (Finset.abs_sum_le_sum_abs _ _).trans - apply Finset.sum_le_sum - intro X _ - rw [abs_mul,abs_of_nonneg (hπ X),Finset.abs_prod] - apply mul_le_mul_of_nonneg_left _ (hπ X) - have hi (a) := motif_weight_abs_le _ _ (prouhet_motif_value s (j a-X)) (k a) - have hh := motif_weight_abs_le_indicator _ _ (prouhet_motif_value s (j h-X)) (k h) hk - calc - _ ≤ ∏ a : Fin r, if a=h then motifIndicator s (j h-X) else 1 := by - apply Finset.prod_le_prod₀ - · intro a _; positivity - · intro a _ - by_cases ha : a=h - · subst a; simpa using hh - · simpa [ha] using hi a - _ = _ := by simp - -/-- A nonzero averaged pattern requires every involved tagged position to - lie in one common translate of the motif; correlations are retained. -/ -theorem motif_multiplier_nonzero_support {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (k : Fin r → GapDifference) - (hm : motifPatternMultiplier π s j k ≠ 0) : - ∃ X ∈ π.coeff.support, ∀ h, k h ≠ .unchanged → - 0 ≤ j h-X ∧ j h-X < (2^s : ℕ) := by - classical - obtain ⟨X,hX,hv⟩ := Finset.exists_ne_zero_of_sum_ne_zero hm - refine ⟨X,hX,?_⟩ - intro h hk - by_contra hh - apply hv - apply mul_eq_zero_of_right - apply Finset.prod_eq_zero (Finset.mem_univ h) - have hi : motifIndicator s (j h-X)=0 := by simp only [motifIndicator,ite_eq_right hh] - have hw := motif_weight_abs_le_indicator _ _ (prouhet_motif_value s (j h-X)) (k h) hk - exact abs_nonpos_iff.mp (hw.trans_eq hi) - -theorem motif_multiplier_bounded_separation {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (k : Fin r → GapDifference) - (hm : motifPatternMultiplier π s j k ≠ 0) - (a b : Fin r) (ha : k a ≠ .unchanged) (hb : k b ≠ .unchanged) : - |j a-j b| < (2^s : ℕ) := by - obtain ⟨X,_,hX⟩ := motif_multiplier_nonzero_support π s j k hm - have h1 := hX a ha - have h2 := hX b hb - exact abs_lt.mpr ⟨by omega,by omega⟩ - -/-- Mixing commutes with the exact signed positional expansion. -/ -theorem mixed_signed_shift_expansion {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (W : (Fin r → Fin 3) → ℝ) : - (∑ X ∈ π.coeff.support, π.coeff X * - (W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) 1)- - W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) (-1))))= - ∑ k : Fin r → GapDifference, - (if Odd (firstDifferenceCount k) then 2*motifPatternMultiplier π s j k else 0)* - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by - calc - _ = ∑ X ∈ π.coeff.support, ∑ k : Fin r → GapDifference, - π.coeff X*((if Odd (firstDifferenceCount k) then - 2*∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) - ((prouhetSeries s).coeff (j h-X)) 1 (k h) else 0)* - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a)) := by - apply Finset.sum_congr rfl - intro X _ - rw [motif_signed_shift_expansion _ _ (fun h => prouhet_motif_value s (j h-X)) W, - Finset.mul_sum] - _ = _ := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro k _ - by_cases hk : Odd (firstDifferenceCount k) - · simp only [ite_eq_left hk,motifPatternMultiplier] - calc - _ = (∑ X ∈ π.coeff.support, 2*(π.coeff X * - ∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) - ((prouhetSeries s).coeff (j h-X)) 1 (k h))) * - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro X _; ring - _ = _ := by rw [← Finset.mul_sum] - · simp only [ite_eq_right hk,zero_mul,mul_zero,Finset.sum_const_zero] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- A general weighted fiber sum, including multipliers which vanish on - inadmissible anchor labels. -/ -theorem weighted_fiber_sum_le {α β : Type*} [Fintype α] [Fintype β] - (f : α → β) (a : α → ℝ) (w : β → ℝ) (P : α → ℝ) (C : ℝ) - (hP : ∀ x, 0 ≤ P x) (ha : ∀ x, a x^2 ≤ w (f x)^2) - (hC : ∀ y, w y ≠ 0 → (∑ x : {x // f x=y}, P x.val) ≤ C) : - (∑ x, a x^2*P x) ≤ C*∑ y, w y^2 := by - classical - calc - _ ≤ ∑ x, w (f x)^2*P x := - Finset.sum_le_sum fun x _ => mul_le_mul_of_nonneg_right (ha x) (hP x) - _ = ∑ y, w y^2*∑ x : {x // f x=y}, P x.val := by - rw [← Fintype.sum_fiberwise f (fun x => w (f x)^2*P x)] - apply Finset.sum_congr rfl - intro y _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - rw [x.property] - _ ≤ ∑ y, w y^2*C := by - apply Finset.sum_le_sum - intro y _ - by_cases hy : w y=0 - · simp [hy] - · exact mul_le_mul_of_nonneg_left (hC y hy) (sq_nonneg _) - _ = _ := by rw [← Finset.sum_mul]; ring - -/-- Explicit central-anchor summation constant for doubled period gaps. -/ -def periodCentralSumConstant (u r : ℕ) : ℝ := - ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(2*Real.sqrt (2*u:ℕ))^(r-1) - -theorem weighted_period_gap_sum {u r : ℕ} (a : Fin r) - (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) - (hA : ∀ j, A j^2 ≤ w (j.val a)^2) - (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) : - (∑ j : IncreasingTuple u r, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) ≤ - periodCentralSumConstant u r *∑ h, w h^2 := by - apply weighted_fiber_sum_le (fun j : IncreasingTuple u r => j.val a) A w - (fun j => ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) - (periodCentralSumConstant u r) (fun _ => by positivity) hA - intro h hh - calc - _ = ∑ j : FixedPeriodTuple u r a h, - ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ := - by - congr 1 - exact congrArg (fun i : Fintype (FixedPeriodTuple u r a h) => @Finset.univ _ i) - (Subsingleton.elim _ _) - _ ≤ _ := fixedPeriodProfile_central_sum a h (hw h hh).1 (hw h hh).2 - -/-- The two largest gaps exist even after arbitrary restrictions on the - tuple, provided its anchor label is central. -/ -theorem fixedPeriodProfile_large_sides {u r : ℕ} (a : Fin r) (h : Fin u) - (hleft : (u:ℝ)/3 ≤ 2*h.val+1) - (hright : (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) (j : FixedPeriodTuple u r a h) : - (∃ e ∈ Finset.Iic a.castSucc, (u:ℝ)/(3*(r+1:ℝ)) ≤ (fixedPeriodProfile a h j e).val) ∧ - (∃ d ∉ Finset.Iic a.castSucc, (u:ℝ)/(3*(r+1:ℝ)) ≤ (fixedPeriodProfile a h j d).val) := by - classical - let A := Finset.Iic a.castSucc - let p := fixedPeriodProfile a h - have hL : ∃ e∈A, (u:ℝ)/(3*(r+1:ℝ)) ≤ (p j e).val := by - apply exists_large_in_subset A ⟨0, by simp [A]⟩ (fun i => (p j i).val) - (fun _ => Nat.cast_nonneg _) - have hs := fixedPeriodProfile_prefix a h j - have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs - rw [hs'] - simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] - convert hleft using 1; field_simp - have hD : ∃ d∉A, (u:ℝ)/(3*(r+1:ℝ)) ≤ (p j d).val := by - have ha : a.val ((p j i).val:ℝ)) (fun _ => Nat.cast_nonneg _) (R := (u:ℝ)/(3*(r+1:ℝ))) (by - have hs := fixedPeriodProfile_prefix a h j - have ht := fixedPeriodProfile_total a h j - have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs - have ht' : (∑ i, ((p j i).val:ℝ))=2*u := by exact_mod_cast ht - have hc := Finset.sum_compl_add_sum A (fun i => ((p j i).val:ℝ)) - have hsum : (∑ i∈Aᶜ, ((p j i).val:ℝ))=2*u-(2*h.val+1) := by linarith - rw [hsum] - simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] - convert hright using 1; field_simp) - exact ⟨d,Finset.mem_compl.mp hd,hdR⟩ - exact ⟨hL,hD⟩ - -/-- Source's bounded gap refinement at a prescribed central label. -/ -theorem fixedPeriodProfile_bounded_central_sum {u r M : ℕ} (a : Fin r) (h : Fin u) - (c : Fin (r+1)) (hleft : (u:ℝ)/3 ≤ 2*h.val+1) - (hright : (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑ j : FixedPeriodTuple u r a h, - if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0) ≤ - ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(M+1)*(2*Real.sqrt (2*u:ℕ))^(r-2) := by - classical - let α := {j : FixedPeriodTuple u r a h // coarsePeriodGap j.val.val c ≤ M} - let p (j : α) := fixedPeriodProfile a h j.val - have hu : (0:ℝ) < u := by exact_mod_cast (Nat.zero_lt_of_lt h.isLt) - have hR : 0 < (u:ℝ)/(3*(r+1:ℝ)) := by positivity - have hs := two_sided_bounded_gaps_sum (Finset.Iic a.castSucc) c p - ((fixedPeriodProfile_injective a h).comp Subtype.val_injective) - (fun j => fixedPeriodProfile_prefix a h j.val) - (fun j => fixedPeriodProfile_total a h j.val) hR hM - (fun j => (fixedPeriodProfile_large_sides a h hleft hright j.val).1) - (fun j => (fixedPeriodProfile_large_sides a h hleft hright j.val).2) - (fun j => j.property) - have he : (∑ j : FixedPeriodTuple u r a h, - if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0)= - ∑ j : α, ∏ i, (Real.sqrt (coarsePeriodGap j.val.val.val i))⁻¹ := by - rw [← Finset.sum_filter] - exact Finset.sum_subtype _ (by intro j; simp) _ - rw [he] - simpa only [α,p,fixedPeriodProfile,Fin.val_mk,Fintype.card_fin, - show r+1-3=r-2 by omega] using hs - -def periodBoundedSumConstant (u r M : ℕ) : ℝ := - ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(M+1)*(2*Real.sqrt (2*u:ℕ))^(r-2) - -theorem weighted_period_bounded_gap_sum {u r M : ℕ} (a : Fin r) (c : Fin (r+1)) - (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) - (hA : ∀ j, A j^2 ≤ w (j.val a)^2) - (hsupport : ∀ j, A j ≠ 0 → coarsePeriodGap j.val c ≤ M) - (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) - (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑ j : IncreasingTuple u r, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) ≤ - periodBoundedSumConstant u r M *∑ h, w h^2 := by - have hp (j : IncreasingTuple u r) : - A j^2*(∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹)= - A j^2*(if coarsePeriodGap j.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ else 0) := by - by_cases hj : A j=0 - · simp [hj] - · rw [ite_eq_left (hsupport j hj)] - simp_rw [hp] - apply weighted_fiber_sum_le (fun j : IncreasingTuple u r => j.val a) A w - (fun j => if coarsePeriodGap j.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ else 0) - (periodBoundedSumConstant u r M) (fun _ => by split_ifs <;> positivity) hA - intro h hh - calc - _ = ∑ j : FixedPeriodTuple u r a h, - if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0 := - by - congr 1 - exact congrArg (fun i : Fintype (FixedPeriodTuple u r a h) => @Finset.univ _ i) - (Subsingleton.elim _ _) - _ ≤ _ := fixedPeriodProfile_bounded_central_sum a h c (hw h hh).1 (hw h hh).2 hM - -end TraceReconstruction - - -namespace TraceReconstruction - -/-- A displaced child window as an actual interval of the deterministic - parent template. `t` is the realized count of atoms before the window. -/ -def childWindowIndex {P T : ℕ} (t : ℕ) (hfit : t+T ≤ P) (h : Fin T) : Fin P := - ⟨t+h.val, by omega⟩ - -theorem templateType_inside_window {P T a L t : ℕ} - (sign : Fin L → Bool) (τ : Bool) (hfit : t+T ≤ P) - (hleft : t ≤ a) (h : Fin T) : - templateType P a L sign τ (childWindowIndex t hfit h)= - templateType T (a-t) L sign τ h := by - have he : (a ≤ (childWindowIndex t hfit h).val ∧ - (childWindowIndex t hfit h).val < a+L) ↔ - a-t ≤ h.val ∧ h.val < a-t+L := by dsimp [childWindowIndex]; omega - unfold templateType - split_ifs with h1 h2 h2 - · congr 2 - apply Fin.ext - dsimp [childWindowIndex] - omega - · exact False.elim (h2 (he.mp h1)) - · exact False.elim (h1 (he.mpr h2)) - · rfl - -/-- When the motif fits its assigned window, every atom outside that - window has the default pure type, including pieces crossing nominal cuts. -/ -theorem templateType_outside_window {P T a L t : ℕ} - (sign : Fin L → Bool) (τ : Bool) (hleft : t ≤ a) (hright : a+L ≤ t+T) - (i : Fin P) (hi : i.val < t ∨ t+T ≤ i.val) : - templateType P a L sign τ i=false := by - have he : ¬(a ≤ i.val ∧ i.val < a+L) := by omega - simp [templateType,he] - -/-- A literal centered window remains within its own nominal parent unit, - and contains the motif, whenever its jitter has the source fit bound. - This elementary statement is independent of the distribution of the jitter. -/ -theorem centered_window_fit (P T L a A t : ℕ) (Y : ℤ) - (hP : 2*T ≤ P) (hA : 2*A=P-T) (ha : 2*a=P) - (hL : 8*L ≤ T) (hY : |8*Y| ≤ (T:ℤ)) (ht : (t:ℤ)=A+Y) : - t+T ≤ P ∧ t ≤ a ∧ a+L ≤ t+T := by - have hy := abs_le.mp hY - omega - -/-- Flattened deterministic parent type, before any random partition. -/ -def parentGroupType {R P L : ℕ} (a : ℕ) (sign : Fin L → Bool) - (τ : Fin R → Bool) (u : Fin R) (h : Fin P) : Bool := - templateType P a L sign (τ u) h - -theorem parentGroup_window_types {R P T L : ℕ} (a : ℕ) (sign : Fin L → Bool) - (τ : Fin R → Bool) (t : Fin R → ℕ) - (hfit : ∀ u, t u+T ≤ P) (hleft : ∀ u, t u ≤ a) - (u : Fin R) (h : Fin T) : - parentGroupType a sign τ u (childWindowIndex (t u) (hfit u) h)= - templateType T (a-t u) L sign (τ u) h := - templateType_inside_window sign (τ u) (hfit u) (hleft u) h - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Model +import OAI.Probability.TraceReconstruction.Parity +import OAI.Probability.TraceReconstruction.Ranks + +namespace OAI + +/-! +# Differences + +Tensor gap differences, positional shifts, two-gap elimination, central clipping, disjoint rank regions, and weighted period sums. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + +namespace TraceReconstruction + +/-- Forward length differences of the actual binomial probability +polynomial, before imposing the conditional rank total. -/ +def binomialLengthDifference (g s : ℕ) (p : ℝ) : IntSeries := + (biasedSeries 1 p - 1)^s * biasedSeries g p + +/-- Increasing the number of trials corresponds exactly to multiplying +by the Bernoulli step polynomial. -/ +theorem binomialLengthDifference_succ (g s : ℕ) (p : ℝ) : + binomialLengthDifference g (s+1) p = + binomialLengthDifference (g+1) s p - binomialLengthDifference g s p := by + unfold binomialLengthDifference + rw [biasedSeries_add] + ring + +theorem biasedSeries_step_sub_one (p : ℝ) : + biasedSeries 1 p - 1 = (-p) • firstDifference := by + unfold biasedSeries firstDifference + rw [pow_one,smul_sub,AddMonoidAlgebra.smul_single,AddMonoidAlgebra.smul_single] + simp only [smul_eq_mul,mul_one] + have h1 : (1 : IntSeries) = AddMonoidAlgebra.single 0 1 := rfl + rw [h1] + simp only [AddMonoidAlgebra.single_sub] + ext z + simp only [AddMonoidAlgebra.coeff_sub,AddMonoidAlgebra.coeff_add, + Finsupp.sub_apply,Finsupp.add_apply,AddMonoidAlgebra.coeff_single,Finsupp.single_apply] + split_ifs <;> ring + +theorem binomialLengthDifference_eq (g s : ℕ) (p : ℝ) : + binomialLengthDifference g s p = + (-p)^s • (firstDifference^s * biasedSeries g p) := by + unfold binomialLengthDifference + rw [biasedSeries_step_sub_one,smul_pow,smul_mul_assoc] + +theorem seriesL2Sq_smul (c : ℝ) (f : IntSeries) : + seriesL2Sq (c • f) = c^2 * seriesL2Sq f := by + unfold seriesL2Sq + simp only [AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,mul_pow] + exact tsum_mul_left + +/-- Pointwise and square-sum bounds for every forward length difference. +The quotient form keeps every order and every channel factor explicit. -/ +theorem binomialLengthDifference_bounds (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + (∀ z : ℤ, |(binomialLengthDifference g s p).coeff z| ≤ + (2*biasedBinomialBound (g/(s+1)) p)^s * biasedBinomialBound (g/(s+1)) p) ∧ + (seriesL2Sq (binomialLengthDifference g s p) ≤ + ((2*biasedBinomialBound (g/(s+1)) p)^s)^2 * biasedBinomialBound (g/(s+1)) p) := by + have hpow : |(-p)^s| ≤ 1 := by + rw [abs_pow,abs_neg,abs_of_pos hp.1] + exact pow_le_one₀ hp.1.le hp.2.le + have hs := biased_difference_smoothing g s hp + rw [binomialLengthDifference_eq] + constructor + · intro z + simp only [AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,abs_mul] + exact (mul_le_mul_of_nonneg_right hpow (abs_nonneg _)).trans (by simpa using hs.1 z) + · rw [seriesL2Sq_smul] + have h : ((-p)^s) ^ 2 ≤ 1 := by nlinarith [sq_abs ((-p)^s),abs_nonneg ((-p)^s)] + exact (mul_le_mul_of_nonneg_right h (seriesL2Sq_nonneg _)).trans (by simpa using hs.2) + +/-- Explicit fixed-order smoothing constant; no asymptotic hypothesis is hidden. -/ +def lengthDifferenceConstant (s : ℕ) (p : ℝ) : ℝ := + 2 * Real.sqrt (((s:ℝ)+1)/(p*(1-p))) + +theorem lengthDifferenceConstant_pos (s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + 0 < lengthDifferenceConstant s p := by + unfold lengthDifferenceConstant + positivity [hp.1,sub_pos.mpr hp.2] + +theorem biasedBinomialBound_length_le (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + 2*biasedBinomialBound (g/(s+1)) p ≤ + lengthDifferenceConstant s p / Real.sqrt ((g:ℝ)+1) := by + calc + _ ≤ 2*Real.sqrt (((s:ℝ)+1)/(((g:ℝ)+1)*p*(1-p))) := + mul_le_mul_of_nonneg_left (biasedBinomialBound_quotient_le g s hp) (by norm_num) + _ = _ := by + unfold lengthDifferenceConstant + rw [show ((s:ℝ)+1)/(((g:ℝ)+1)*p*(1-p)) = + (((s:ℝ)+1)/(p*(1-p)))/((g:ℝ)+1) by field_simp] + rw [Real.sqrt_div (by positivity [hp.1,sub_pos.mpr hp.2])] + ring + +/-- Squared supremum and squared L2 smoothing estimates in a form suitable +for exact constrained rank profiles. -/ +theorem binomialLengthDifference_numeric (g s : ℕ) {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + (∀ z : ℤ, (binomialLengthDifference g s p).coeff z ^ 2 ≤ + (lengthDifferenceConstant s p)^(2*s+2) / ((g:ℝ)+1)^(s+1)) ∧ + (seriesL2Sq (binomialLengthDifference g s p) ≤ + (lengthDifferenceConstant s p)^(2*s+1) / + (((g:ℝ)+1)^s * Real.sqrt ((g:ℝ)+1))) := by + have hb := binomialLengthDifference_bounds g s hp + have hc := biasedBinomialBound_length_le g s hp + have hB : 0 ≤ biasedBinomialBound (g/(s+1)) p := Real.sqrt_nonneg _ + have hC : 0 < lengthDifferenceConstant s p := lengthDifferenceConstant_pos s hp + have hg : 0 < Real.sqrt ((g:ℝ)+1) := Real.sqrt_pos.mpr (by positivity) + have hB' : biasedBinomialBound (g/(s+1)) p ≤ + lengthDifferenceConstant s p / Real.sqrt ((g:ℝ)+1) := by linarith + have hs := pow_le_pow_left₀ (by positivity : 0 ≤ 2*biasedBinomialBound (g/(s+1)) p) hc s + constructor + · intro z + have h := (hb.1 z).trans (mul_le_mul hs hB' hB (by positivity)) + rw [← pow_succ] at h + have hsq := pow_le_pow_left₀ (abs_nonneg _) h 2 + rw [sq_abs] at hsq + refine hsq.trans_eq ?_ + rw [← pow_mul,div_pow] + have he : (s+1)*2=2*s+2 := by omega + rw [he] + congr 1 + rw [show 2*s+2=2*(s+1) by omega,pow_mul,Real.sq_sqrt (by positivity)] + · have hsq := pow_le_pow_left₀ (by positivity : + 0 ≤ (2*biasedBinomialBound (g/(s+1)) p)^s) hs 2 + refine hb.2.trans ((mul_le_mul hsq hB' hB (by positivity)).trans_eq ?_) + rw [← pow_mul,← pow_succ,div_pow] + congr 1 + · congr 1; omega + · rw [pow_succ,show s*2=2*s by omega,pow_mul,Real.sq_sqrt (by positivity)] + +end TraceReconstruction + +namespace TraceReconstruction + +theorem series_finite_sum_sq_le {α : Type*} [Fintype α] + (f : IntSeries) (z : α → ℤ) (hz : Function.Injective z) : + (∑ a, f.coeff (z a)^2) ≤ seriesL2Sq f := by + simpa only [tsum_fintype,seriesL2Sq] using + Summable.tsum_le_tsum_of_inj z hz (fun _ _ => sq_nonneg _) + (fun _ => le_rfl) (hasSum_fintype _).summable (series_summable f (fun x => x^2) (by simp)) + +/-- Product coefficients of signed gap series, including an arbitrary +translation of each observed rank gap. -/ +def signedRankProduct {l r : ℕ} (f : Fin (r+1) → IntSeries) + (shift : Fin (r+1) → ℤ) (v : IncreasingTuple l r) : ℝ := + ∏ i, (f i).coeff ((tupleGap v.val i : ℤ)-shift i) + +/-- Largest-gap elimination also holds for signed finite-difference series. +The fixed sum of the observed gaps supplies the missing square-root factor; +translations are unrestricted and the estimate contains no omitted ranks. -/ +theorem signedRankProduct_square_sum_le {l r : ℕ} + (f : Fin (r+1) → IntSeries) (shift : Fin (r+1) → ℤ) + (e : Fin (r+1)) (M : ℝ) (hM : 0 ≤ M) + (hbound : ∀ z : ℤ, (f e).coeff z ^ 2 ≤ M) : + (∑ v : IncreasingTuple l r, signedRankProduct f shift v ^ 2) ≤ + M * ∏ i : Fin r, seriesL2Sq (f (Equiv.swap 0 e i.succ)) := by + classical + let σ : Equiv.Perm (Fin (r+1)) := Equiv.swap 0 e + let F : Fin (r+1) → Fin (l-r+1) → ℝ := + fun i k => (f (σ i)).coeff ((k.val:ℤ)-shift (σ i)) ^ 2 + have hF : ∀ i k, 0 ≤ F i k := fun _ _ => sq_nonneg _ + have hpoint (v : IncreasingTuple l r) : + signedRankProduct f shift v ^ 2 = ∏ i, F i (rankGapProfile σ v i) := by + unfold signedRankProduct + rw [← Finset.prod_pow] + dsimp [F,rankGapProfile] + exact (Equiv.prod_comp σ _).symm + simp_rw [hpoint] + calc + _ ≤ ∑ z : Fin (r+1) → Fin (l-r+1), + if ∑ i, (z i).val = l-r then ∏ i, F i (z i) else 0 := by + exact sum_injective_profile_le (rankGapProfile σ) (rankGapProfile_injective σ) + (fun z => ∑ i, (z i).val = l-r) (rankGapProfile_sum σ) + (fun z => ∏ i, F i (z i)) (fun _ => Finset.prod_nonneg (fun _ _ => hF _ _)) + _ ≤ M * ∏ i : Fin r, ∑ k : Fin (l-r+1), F i.succ k := + constrained_sum_product_le r (l-r) F hF M hM (by + intro k + simpa only [F,σ,Equiv.swap_apply_left] using hbound ((k.val:ℤ)-shift e)) + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left _ hM + apply Finset.prod_le_prod₀ (fun _ _ => Finset.sum_nonneg (fun _ _ => hF _ _)) + intro i _ + dsimp only [F] + apply series_finite_sum_sq_le + intro a b h + exact Fin.ext (Int.ofNat_inj.mp (sub_left_injective h)) + +/-- Finite mixtures of signed rank products can be estimated termwise. +This is the exact Cauchy--Schwarz form used when expanding positional +finite-difference operators into gap derivatives. -/ +theorem rank_mixture_square_sum_le {α V : Type*} [Fintype α] [Fintype V] + (c : α → ℝ) (F : α → V → ℝ) (B : α → ℝ) + (hB : ∀ a, (∑ v, F a v ^ 2) ≤ B a) : + (∑ v, (∑ a, c a * F a v)^2) ≤ (∑ a, |c a|) * ∑ a, |c a| * B a := by + have hp (v : V) : (∑ a, c a*F a v)^2 ≤ + (∑ a, |c a|) * ∑ a, |c a| * F a v^2 := by + apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (fun _ _ => abs_nonneg _) (fun _ _ => mul_nonneg (abs_nonneg _) (sq_nonneg _)) + intro a _ + rw [mul_pow,← mul_assoc,← sq, sq_abs] + calc + _ ≤ ∑ v, (∑ a, |c a|) * ∑ a, |c a| * F a v^2 := + Finset.sum_le_sum (fun v _ => hp v) + _ = (∑ a, |c a|) * ∑ a, |c a| * ∑ v, F a v^2 := by + rw [← Finset.mul_sum,Finset.sum_comm] + simp_rw [← Finset.mul_sum] + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left _ (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_left (hB a) (abs_nonneg _) + +end TraceReconstruction + +namespace TraceReconstruction + +/-- The tensor product of finitely supported one-dimensional coefficient +series, represented on its literal vector-valued exponents. -/ +def tensorSeries {ι : Type*} [Fintype ι] (f : ι → IntSeries) : + AddMonoidAlgebra ℝ (ι → ℤ) := +by + classical + exact AddMonoidAlgebra.ofCoeff (Finsupp.onFinset (Fintype.piFinset (fun i => (f i).coeff.support)) + (fun z => ∏ i, (f i).coeff (z i)) (by + classical + intro z hz + simp only [Fintype.mem_piFinset,Finsupp.mem_support_iff] + exact fun i => (Finset.prod_ne_zero_iff.mp hz) i (Finset.mem_univ i))) + +theorem tensorSeries_coeff {ι : Type*} [Fintype ι] (f : ι → IntSeries) (z : ι → ℤ) : + (tensorSeries f).coeff z = ∏ i, (f i).coeff (z i) := rfl + +theorem tensorSeries_support {ι : Type*} [Fintype ι] [DecidableEq ι] + (f : ι → IntSeries) : + (tensorSeries f).coeff.support = Fintype.piFinset (fun i => (f i).coeff.support) := by + classical + ext z + simp [tensorSeries_coeff,Finset.prod_ne_zero_iff] + +/-- Literal tensor multiplication is coordinatewise convolution. -/ +theorem tensorSeries_mul {ι : Type*} [Fintype ι] (f g : ι → IntSeries) : + tensorSeries (fun i => f i*g i) = tensorSeries f * tensorSeries g := by + classical + ext z + rw [tensorSeries_coeff,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum,tensorSeries_support] + simp_rw [tensorSeries_coeff,← Finset.prod_mul_distrib] + simp only [Pi.add_apply, Pi.neg_apply] + rw [← Finset.prod_univ_sum (fun i => (f i).coeff.support) + (fun i j => (f i).coeff j * (g i).coeff (-j + z i))] + apply Finset.prod_congr rfl + intro i _ + rw [AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] + +theorem tensorSeries_one {ι : Type*} [Fintype ι] : + tensorSeries (fun _ : ι => (1 : IntSeries)) = 1 := by + classical + ext z + rw [tensorSeries_coeff] + change (∏ i, Finsupp.single 0 (1:ℝ) (z i)) = Finsupp.single 0 (1:ℝ) z + simp only [Finsupp.single_apply] + by_cases hz : z = 0 + · subst z; simp + · have he : ∃ i, z i ≠ 0 := by simpa [funext_iff] using hz + obtain ⟨i,hi⟩ := he + rw [ite_eq_right (Ne.symm hz)] + exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [Ne.symm hi]) + + +/-- Embedding one integral exponent into its own gap coordinate. -/ +def coordinateExponent {ι : Type*} [DecidableEq ι] (i : ι) : ℤ →+ (ι → ℤ) where + toFun := fun a => Pi.single (M := fun _ => ℤ) i a + map_zero' := Pi.single_zero i + map_add' := fun a b => by + ext j + by_cases h : j=i + · subst j; simp + · simp [Pi.single_eq_of_ne h] + +def coordinateSeriesHom {ι : Type*} [DecidableEq ι] (i : ι) : + IntSeries →+* AddMonoidAlgebra ℝ (ι → ℤ) := + AddMonoidAlgebra.mapDomainRingHom ℝ (coordinateExponent i) + +theorem coordinateExponent_injective {ι : Type*} [DecidableEq ι] (i : ι) : + Function.Injective (coordinateExponent i) := by + intro a b h + simpa only [coordinateExponent,AddMonoidHom.coe_mk,ZeroHom.coe_mk,Pi.single_eq_same] + using congrFun h i + +theorem tensorSeries_coordinate {ι : Type*} [Fintype ι] [DecidableEq ι] + (i : ι) (f : IntSeries) : + tensorSeries (fun j => if j=i then f else 1) = coordinateSeriesHom i f := by + classical + ext z + rw [tensorSeries_coeff] + change (∏ j, (if j=i then f else (1:IntSeries)).coeff (z j)) = + (Finsupp.mapDomain (coordinateExponent i) f.coeff) z + by_cases hz : ∀ j, j ≠ i → z j = 0 + · have he : coordinateExponent i (z i) = z := by + funext j + by_cases hj : j=i + · subst j; simp [coordinateExponent] + · simp [coordinateExponent,Pi.single_eq_of_ne hj,hz j hj] + rw [← he,Finsupp.mapDomain_apply_of_injective (coordinateExponent_injective i)] + rw [Finset.prod_eq_single i] + · simp [coordinateExponent] + · intro j _ hj + simp [hj,coordinateExponent] + · simp + · push Not at hz + obtain ⟨j,hji,hj⟩ := hz + have hn : z ∉ Set.range (coordinateExponent i) := by + rintro ⟨a,ha⟩ + have h := congrFun ha j + simp [coordinateExponent,Pi.single_eq_of_ne hji] at h + exact hj h.symm + rw [Finsupp.mapDomain_of_notMem_range _ _ hn] + apply Finset.prod_eq_zero (Finset.mem_univ j) + simp only [ite_eq_right hji] + change Finsupp.single 0 (1:ℝ) (z j) = 0 + simp [Ne.symm hj] + +theorem tensorSeries_prod {ι α : Type*} [Fintype ι] + (s : Finset α) (f : α → ι → IntSeries) : + tensorSeries (fun i => ∏ a ∈ s, f a i) = ∏ a ∈ s, tensorSeries (f a) := by + classical + induction s using Finset.induction_on with + | empty => simp [tensorSeries_one] + | @insert a s ha ih => + simp only [Finset.prod_insert ha] + rw [tensorSeries_mul,ih] + +/-- The literal product of the coordinate embeddings has precisely the +independent product coefficients, with no external tensor-product axioms. -/ +theorem tensorSeries_eq_prod {ι : Type*} [Fintype ι] [DecidableEq ι] + (f : ι → IntSeries) : + tensorSeries f = ∏ i, coordinateSeriesHom i (f i) := by + have he : f = fun j => ∏ i, if j=i then f i else 1 := by + funext j + simp + conv_lhs => rw [he,tensorSeries_prod] + apply Finset.prod_congr rfl + intro i _ + exact tensorSeries_coordinate i (f i) + +end TraceReconstruction + +namespace TraceReconstruction + +/-- Explicit fixed-order gap derivative bound, uniformly over translated +rank restrictions and the choice of the eliminated gap. -/ +theorem rank_gap_derivatives_bound {l r : ℕ} + (g s : Fin (r+1) → ℕ) (shift : Fin (r+1) → ℤ) + {p : ℝ} (hp : p ∈ Set.Ioo 0 1) (e : Fin (r+1)) : + (∑ v : IncreasingTuple l r, + signedRankProduct (fun i => binomialLengthDifference (g i) (s i) p) shift v ^ 2) ≤ + (lengthDifferenceConstant (s e) p)^(2*s e+2) / ((g e:ℝ)+1)^(s e+1) * + ∏ i : Fin r, + (lengthDifferenceConstant (s (Equiv.swap 0 e i.succ)) p)^(2*s (Equiv.swap 0 e i.succ)+1) / + (((g (Equiv.swap 0 e i.succ):ℝ)+1)^(s (Equiv.swap 0 e i.succ)) * + Real.sqrt ((g (Equiv.swap 0 e i.succ):ℝ)+1)) := by + have hC := (lengthDifferenceConstant_pos (s e) hp).le + refine (signedRankProduct_square_sum_le _ shift e _ (by positivity) + (binomialLengthDifference_numeric (g e) (s e) hp).1).trans ?_ + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.prod_le_prod₀ (fun _ _ => seriesL2Sq_nonneg _) + intro i _ + exact (binomialLengthDifference_numeric _ _ hp).2 + +/-- Increasing an order increases only its explicit smoothing constant. -/ +theorem lengthDifferenceConstant_mono {s t : ℕ} (hst : s ≤ t) + {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + lengthDifferenceConstant s p ≤ lengthDifferenceConstant t p := by + unfold lengthDifferenceConstant + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.sqrt_le_sqrt + exact div_le_div_of_nonneg_right (by exact_mod_cast Nat.succ_le_succ hst) + (mul_pos hp.1 (sub_pos.mpr hp.2)).le + +end TraceReconstruction + +namespace TraceReconstruction + +inductive GapDifference + | unchanged | first | second + deriving DecidableEq + +def GapDifference.order : GapDifference → ℕ + | .unchanged => 0 | .first => 1 | .second => 2 + +def adjacentGap {r : ℕ} (h : Fin r) (b : Bool) : Fin (r+1) := + if b then h.succ else h.castSucc + +def gapTermWeight (k : GapDifference) (a : Bool × Bool) : ℝ := + match k with + | .unchanged => 1/4 + | .first => (if a.1 then -1 else 1)/2 + | .second => (if a.1 then -1 else 1)*(if a.2 then -1 else 1)/2 + +def gapTermOrder {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) + (i : Fin (r+1)) : ℕ := + match k with + | .unchanged => 0 + | .first => if i = adjacentGap h a.1 then 1 else 0 + | .second => (if i = adjacentGap h a.1 then 1 else 0) + + (if i = adjacentGap h a.2 then 1 else 0) + +def gapTermExtra {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) + (i : Fin (r+1)) : ℕ := + match k with + | .unchanged => (if i = h.castSucc then 1 else 0) + (if i = h.succ then 1 else 0) + | .first => if i = adjacentGap h a.2 then 1 else 0 + | .second => 0 + +/-- Polynomial of a centered positional operator after removing from +both incident gaps the one unit needed for either direction of movement. -/ +def gapOperator {r : ℕ} (h : Fin r) (k : GapDifference) (p : ℝ) : + AddMonoidAlgebra ℝ (Fin (r+1) → ℤ) := + let L := coordinateSeriesHom h.castSucc (biasedSeries 1 p) + let R := coordinateSeriesHom h.succ (biasedSeries 1 p) + match k with + | .unchanged => L*R + | .first => (1/2:ℝ) • (L^2-R^2) + | .second => (1/2:ℝ) • (L^2+R^2-2*L*R) + +theorem tensorSeries_two_coordinates {ι : Type*} [Fintype ι] [DecidableEq ι] + (a b : ι) (f g : IntSeries) : + tensorSeries (fun i => f^(if i=a then 1 else 0) * g^(if i=b then 1 else 0)) = + coordinateSeriesHom a f * coordinateSeriesHom b g := by + rw [tensorSeries_mul] + have h (c : ι) (u : IntSeries) : + (fun i => u^(if i=c then 1 else 0)) = (fun i => if i=c then u else 1) := by + funext i + split <;> simp + rw [h,h,tensorSeries_coordinate,tensorSeries_coordinate] + +theorem gapLocalTerm_factor {r : ℕ} (h : Fin r) (k : GapDifference) + (a : Bool × Bool) (p : ℝ) : + tensorSeries (fun i => (biasedSeries 1 p-1)^gapTermOrder h k a i * + (biasedSeries 1 p)^gapTermExtra h k a i) = + match k with + | .unchanged => coordinateSeriesHom h.castSucc (biasedSeries 1 p) * + coordinateSeriesHom h.succ (biasedSeries 1 p) + | .first => (coordinateSeriesHom (adjacentGap h a.1) (biasedSeries 1 p)-1) * + coordinateSeriesHom (adjacentGap h a.2) (biasedSeries 1 p) + | .second => (coordinateSeriesHom (adjacentGap h a.1) (biasedSeries 1 p)-1) * + (coordinateSeriesHom (adjacentGap h a.2) (biasedSeries 1 p)-1) := by + cases k <;> simp only [gapTermOrder,gapTermExtra,pow_zero,pow_add,one_mul,mul_one] + all_goals rw [tensorSeries_two_coordinates] + all_goals simp only [map_sub,map_one] + +/-- Exact four-term assignment of positional differences to the adjacent +binomial gap lengths, including all signs and all bounded shifts. -/ +theorem gapOperator_expansion {r : ℕ} (h : Fin r) (k : GapDifference) (p : ℝ) : + gapOperator h k p = ∑ a : Bool × Bool, gapTermWeight k a • + tensorSeries (fun i => (biasedSeries 1 p-1)^gapTermOrder h k a i * + (biasedSeries 1 p)^gapTermExtra h k a i) := by + simp_rw [gapLocalTerm_factor] + cases k <;> simp only [gapOperator,gapTermWeight,Fintype.sum_prod_type, + Fintype.sum_bool,adjacentGap,Bool.false_eq_true,ite_false,ite_true] + · module + all_goals simp only [Algebra.smul_def] + all_goals norm_num + all_goals ring + +theorem gapTermWeight_l1 (k : GapDifference) : + (∑ a : Bool × Bool, |gapTermWeight k a|) ≤ 2 := by + cases k <;> norm_num [gapTermWeight,Fintype.sum_prod_type,Fintype.sum_bool] + +theorem gapTermOrder_total {r : ℕ} (h : Fin r) (k : GapDifference) (a : Bool × Bool) : + (∑ i, gapTermOrder h k a i) = k.order := by + cases k <;> simp [gapTermOrder,GapDifference.order,Finset.sum_add_distrib] + +/-- Exact global expansion inside the unconstrained vector of gap counts. -/ +theorem gapOperators_expansion {r : ℕ} (g : Fin (r+1) → ℕ) + (k : Fin r → GapDifference) (p : ℝ) : + tensorSeries (fun i => biasedSeries (g i) p) * (∏ h, gapOperator h (k h) p) = + ∑ a : Fin r → Bool × Bool, (∏ h, gapTermWeight (k h) (a h)) • + tensorSeries (fun i => binomialLengthDifference + (g i + ∑ h, gapTermExtra h (k h) (a h) i) + (∑ h, gapTermOrder h (k h) (a h) i) p) := by + classical + simp_rw [gapOperator_expansion] + rw [Finset.prod_univ_sum] + simp only [Fintype.piFinset_univ] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.prod_smul, mul_smul_comm, ← tensorSeries_prod, ← tensorSeries_mul] + congr 2 + funext i + simp only [binomialLengthDifference,biasedSeries, + Finset.prod_mul_distrib,Finset.prod_pow_eq_pow_sum] + ring + +theorem gapOperators_weight_l1 {r : ℕ} (k : Fin r → GapDifference) : + (∑ a : Fin r → Bool × Bool, |∏ h, gapTermWeight (k h) (a h)|) ≤ (2:ℝ)^r := by + simp_rw [Finset.abs_prod] + rw [← Fintype.prod_sum (fun h a => |gapTermWeight (k h) a|)] + calc + _ ≤ ∏ _h : Fin r, (2:ℝ) := by + apply Finset.prod_le_prod₀ (fun _ _ => Finset.sum_nonneg fun _ _ => abs_nonneg _) + intro h _ + exact gapTermWeight_l1 (k h) + _ = _ := by simp + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction + +theorem prod_eliminate_fin {α : Type*} [CommMonoid α] {r : ℕ} + (f : Fin (r+1) → α) (e : Fin (r+1)) : + f e * (∏ i : Fin r, f (Equiv.swap 0 e i.succ)) = ∏ i, f i := by + calc + _ = ∏ i : Fin (r+1), f (Equiv.swap 0 e i) := by + rw [Fin.prod_univ_succ,Equiv.swap_apply_left] + _ = _ := Equiv.prod_comp (Equiv.swap 0 e) f + +/-- Uniform smoothing with the individual gap scale retained, and a common +lower gap scale reserved for every derivative order. -/ +theorem lengthDifference_uniform (g b s : ℕ) {p C G : ℝ} + (hp : p ∈ Set.Ioo 0 1) (hC : lengthDifferenceConstant s p ≤ C) + (hG : 0 < G) (hb : b ≤ g) (hGg : G ≤ (g:ℝ)+1) : + (∀ z : ℤ, (binomialLengthDifference g s p).coeff z^2 ≤ + (C/Real.sqrt ((b:ℝ)+1)) * (C^(2*s+1)/(G^s*Real.sqrt ((b:ℝ)+1)))) ∧ + seriesL2Sq (binomialLengthDifference g s p) ≤ + C^(2*s+1)/(G^s*Real.sqrt ((b:ℝ)+1)) := by + have hC0 : 0 < C := (lengthDifferenceConstant_pos s hp).trans_le hC + have hb0 : 0 < (b:ℝ)+1 := by positivity + have hg0 : 0 < (g:ℝ)+1 := by positivity + have hb' : (b:ℝ)+1 ≤ (g:ℝ)+1 := by exact_mod_cast Nat.add_le_add_right hb 1 + have hpow : G^s ≤ ((g:ℝ)+1)^s := pow_le_pow_left₀ hG.le hGg s + have hx := binomialLengthDifference_numeric g s hp + constructor + · intro z + refine (hx.1 z).trans ?_ + have hc := pow_le_pow_left₀ (lengthDifferenceConstant_pos s hp).le hC (2*s+2) + have hd : G^s*((b:ℝ)+1) ≤ ((g:ℝ)+1)^(s+1) := by + rw [pow_succ] + exact mul_le_mul hpow hb' hb0.le (by positivity) + calc + _ ≤ C^(2*s+2)/(G^s*((b:ℝ)+1)) := by + apply div_le_div₀ (by positivity) hc (by positivity) hd + _ = _ := by + have hsq := Real.sq_sqrt hb0.le + have hs : Real.sqrt ((b:ℝ)+1) ≠ 0 := (Real.sqrt_pos.mpr hb0).ne' + rw [show 2*s+2=(2*s+1)+1 by omega,pow_succ] + field_simp + nlinarith only [hsq] + · refine hx.2.trans ?_ + apply div_le_div₀ (by positivity) + (pow_le_pow_left₀ (lengthDifferenceConstant_pos s hp).le hC (2*s+1)) + (by positivity) + exact mul_le_mul hpow (Real.sqrt_le_sqrt hb') (Real.sqrt_nonneg _) (by positivity) + +/-- A single translated signed rank product, with every smoothing scale +and the largest-gap constraint exposed. -/ +theorem rank_derivatives_uniform {l r : ℕ} + (g b s : Fin (r+1) → ℕ) (shift : Fin (r+1) → ℤ) + {p C G : ℝ} (hp : p ∈ Set.Ioo 0 1) + (hC : ∀ i, lengthDifferenceConstant (s i) p ≤ C) (hG : 0 < G) + (hb : ∀ i, b i ≤ g i) (hGg : ∀ i, G ≤ (g i:ℝ)+1) (e : Fin (r+1)) : + (∑ v : IncreasingTuple l r, + signedRankProduct (fun i => binomialLengthDifference (g i) (s i) p) shift v ^ 2) ≤ + C^(2*(∑ i, s i)+r+2) / + (G^(∑ i, s i) * Real.sqrt ((b e:ℝ)+1) * ∏ i, Real.sqrt ((b i:ℝ)+1)) := by + let F (i : Fin (r+1)) : ℝ := C^(2*s i+1)/(G^(s i)*Real.sqrt ((b i:ℝ)+1)) + have hC0 : 0 < C := (lengthDifferenceConstant_pos (s e) hp).trans_le (hC e) + have hF : ∀ i, 0 ≤ F i := fun i => by dsimp [F]; positivity + have hbound (i : Fin (r+1)) := lengthDifference_uniform (g i) (b i) (s i) hp (hC i) hG (hb i) (hGg i) + calc + _ ≤ (C/Real.sqrt ((b e:ℝ)+1)*F e) * + ∏ i : Fin r, seriesL2Sq (binomialLengthDifference (g (Equiv.swap 0 e i.succ)) + (s (Equiv.swap 0 e i.succ)) p) := by + apply signedRankProduct_square_sum_le _ shift e _ (by positivity [hF e]) + exact (hbound e).1 + _ ≤ (C/Real.sqrt ((b e:ℝ)+1)*F e) * ∏ i : Fin r, F (Equiv.swap 0 e i.succ) := by + apply mul_le_mul_of_nonneg_left _ (by positivity [hF e]) + apply Finset.prod_le_prod₀ (fun _ _ => seriesL2Sq_nonneg _) + intro i _ + exact (hbound _).2 + _ = (C/Real.sqrt ((b e:ℝ)+1))*∏ i, F i := by + rw [mul_assoc,prod_eliminate_fin] + _ = _ := by + simp only [F,Finset.prod_div_distrib,Finset.prod_mul_distrib, + Finset.prod_pow_eq_pow_sum,Finset.sum_add_distrib,← Finset.mul_sum, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one] + rw [show 2*(∑ i, s i)+r+2=(2*(∑ i, s i)+(r+1))+1 by omega,pow_succ] + ring + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction + +/-- Enough vacant slots for independent one-step displacements of every tag. -/ +def SafeTaggedTuple {n r : ℕ} (p : Fin r → Fin n) : Prop := + (∀ i, 1 ≤ (p i).val ∧ (p i).val+1 < n) ∧ + ∀ i j, i < j → (p i).val+3 ≤ (p j).val + +def shiftedTag {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) + (a : Fin r → Fin 3) (i : Fin r) : Fin n := + ⟨(p i).val+(a i).val-1, by + have h := hp.1 i + have ha := (a i).isLt + omega⟩ + +theorem shiftedTag_strictMono {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) + (a : Fin r → Fin 3) : StrictMono (shiftedTag p hp a) := by + intro i j hij + change (p i).val+(a i).val-1 < (p j).val+(a j).val-1 + have h := hp.2 i j hij + have hi := hp.1 i + have hj := hp.1 j + have hai := (a i).isLt + omega + +def gapIncidence (r : ℕ) (i : Fin (r+1)) : ℕ := + Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i + Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i + +def shiftGapExtra {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : ℕ := + Fin.cons (α := fun _ => ℕ) 0 (fun h => 2-(a h).val) i + Fin.snoc (α := fun _ => ℕ) (fun h => (a h).val) 0 i + +/-- Literal adjacent-gap allocation of the units used by a displacement. +Value zero means translate left, one leave fixed, two translate right. -/ +def localShiftExtra {r : ℕ} (h : Fin r) (a : Fin 3) (i : Fin (r+1)) : ℕ := + (if i=h.castSucc then a.val else 0) + (if i=h.succ then 2-a.val else 0) + +theorem sum_castSucc_indicator {r : ℕ} (f : Fin r → ℕ) (i : Fin (r+1)) : + (∑ h, if i=h.castSucc then f h else 0) = Fin.snoc (α := fun _ => ℕ) f 0 i := by + induction i using Fin.lastCases with + | last => simp [eq_comm] + | cast h => simp + +theorem sum_succ_indicator {r : ℕ} (f : Fin r → ℕ) (i : Fin (r+1)) : + (∑ h, if i=h.succ then f h else 0) = Fin.cons (α := fun _ => ℕ) 0 f i := by + induction i using Fin.cases with + | zero => simp [eq_comm] + | succ h => simp + +theorem shiftGapExtra_eq_sum {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : + shiftGapExtra a i = ∑ h, localShiftExtra h (a h) i := by + simp only [localShiftExtra,Finset.sum_add_distrib,sum_castSucc_indicator, + sum_succ_indicator,shiftGapExtra] + omega + +theorem gapIncidence_le {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) + (i : Fin (r+1)) : gapIncidence r i ≤ tupleGap p i := by + cases r with + | zero => + have hi : i=0 := Fin.eq_zero i + subst i + simp [gapIncidence,Fin.snoc_zero] + | succ r => + induction i using Fin.cases with + | zero => simpa only [gapIncidence,Fin.cons_zero,zero_add,Fin.snoc_apply_zero, + tupleGap_zero] using (hp.1 0).1 + | succ i => + induction i using Fin.lastCases with + | last => + simp only [gapIncidence,Fin.succ_last,Fin.cons_last,Fin.snoc_last,add_zero, + tupleGap_last] + have h := (hp.1 (Fin.last r)).2 + omega + | cast i => + simp only [gapIncidence,Fin.cons_succ] + rw [Fin.succ_castSucc,Fin.snoc_castSucc] + rw [← Fin.succ_castSucc,tupleGap_middle] + have h := hp.2 i.castSucc i.succ (by simp) + omega + +/-- The exact geometric identity relating translated tag positions to +nonnegative binomial-gap lengths. -/ +theorem tupleGap_shifted {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) + (a : Fin r → Fin 3) (i : Fin (r+1)) : + tupleGap (shiftedTag p hp a) i = + tupleGap p i - gapIncidence r i + shiftGapExtra a i := by + cases r with + | zero => + have hi : i=0 := Fin.eq_zero i + subst i + simp [tupleGap,tupleLower,tupleUpper,gapIncidence,shiftGapExtra,Fin.snoc_zero] + | succ r => + induction i using Fin.cases with + | zero => + simp only [tupleGap_zero,gapIncidence,shiftGapExtra,Fin.cons_zero,zero_add, + Fin.snoc_apply_zero,shiftedTag] + have h := (hp.1 0).1 + omega + | succ i => + induction i using Fin.lastCases with + | last => + simp only [gapIncidence,shiftGapExtra,Fin.succ_last,Fin.cons_last, + Fin.snoc_last,add_zero,tupleGap_last,shiftedTag] + have h := hp.1 (Fin.last r) + have ha := (a (Fin.last r)).isLt + omega + | cast i => + simp only [gapIncidence,shiftGapExtra,Fin.cons_succ] + rw [Fin.succ_castSucc,Fin.snoc_castSucc,Fin.snoc_castSucc] + rw [← Fin.succ_castSucc,tupleGap_middle,tupleGap_middle] + change (p i.succ).val+(a i.succ).val-1-((p i.castSucc).val+(a i.castSucc).val-1+1) = _ + have hi := hp.1 i.castSucc + have hj := hp.1 i.succ + have hij := hp.2 i.castSucc i.succ (by simp) + have hai := (a i.castSucc).isLt + have haj := (a i.succ).isLt + omega + + +/-- Coefficients of the unchanged, centered first, and centered second +one-step positional operators. -/ +def positionalWeight (k : GapDifference) (a : Fin 3) : ℝ := + match k with + | .unchanged => if a=1 then 1 else 0 + | .first => if a=0 then -1/2 else if a=2 then 1/2 else 0 + | .second => if a=1 then -1 else 1/2 + +theorem localShift_factor {r : ℕ} (h : Fin r) (a : Fin 3) (p : ℝ) : + tensorSeries (fun i => (biasedSeries 1 p)^localShiftExtra h a i) = + coordinateSeriesHom h.castSucc (biasedSeries 1 p)^a.val * + coordinateSeriesHom h.succ (biasedSeries 1 p)^(2-a.val) := by + have hpow (u : IntSeries) (t : ℕ) (c i : Fin (r+1)) : + u^(if i=c then t else 0) = (u^t)^(if i=c then 1 else 0) := by + split <;> simp + have he : (fun i => (biasedSeries 1 p)^localShiftExtra h a i) = + (fun i => ((biasedSeries 1 p)^a.val)^(if i=h.castSucc then 1 else 0) * + ((biasedSeries 1 p)^(2-a.val))^(if i=h.succ then 1 else 0)) := by + funext i + rw [localShiftExtra,pow_add,hpow _ _ h.castSucc i,hpow _ _ h.succ i] + rw [he,tensorSeries_two_coordinates,map_pow,map_pow] + +theorem gapOperator_positional_expansion {r : ℕ} (h : Fin r) (k : GapDifference) + (p : ℝ) : + gapOperator h k p = ∑ a : Fin 3, positionalWeight k a • + tensorSeries (fun i => (biasedSeries 1 p)^localShiftExtra h a i) := by + simp_rw [localShift_factor] + rw [Fin.sum_univ_three] + cases k <;> norm_num [positionalWeight,gapOperator,Fin.ext_iff] + all_goals try simp only [two_mul,add_mul] + all_goals module + +/-- Literal centered differences of all rank kernels are coefficients of +the adjacent-gap operator product, with no formal negative trial lengths. -/ +theorem shifted_gap_series_expansion {n r : ℕ} (p : Fin r → Fin n) + (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) (θ : ℝ) : + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) • + tensorSeries (fun i => biasedSeries (tupleGap (shiftedTag p hp a) i) θ)) = + tensorSeries (fun i => biasedSeries (tupleGap p i-gapIncidence r i) θ) * + ∏ h, gapOperator h (k h) θ := by + classical + simp_rw [gapOperator_positional_expansion] + rw [Finset.prod_univ_sum] + simp only [Fintype.piFinset_univ] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.prod_smul,mul_smul_comm,← tensorSeries_prod,← tensorSeries_mul] + congr 2 + funext i + rw [tupleGap_shifted,shiftGapExtra_eq_sum] + simp only [biasedSeries,pow_one,Finset.prod_pow_eq_pow_sum,pow_add] + + +/-- Simultaneous literal positional operators applied to the actual +conditional retained-subset kernel. -/ +def positionalRankDifference {n l r : ℕ} (hl : l ≤ n) (p : Fin r → Fin n) + (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) (v : IncreasingTuple l r) : ℝ := + ∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) * + subsetRankKernel hl (shiftedTag p hp a) v.val + +theorem positionalRankDifference_expansion {n l r : ℕ} (hl : l ≤ n) + (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) + {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (v : IncreasingTuple l r) : + positionalRankDifference hl p hp k v = θ^r / binomialMass n θ l * + ∑ a : Fin r → Bool × Bool, (∏ h, gapTermWeight (k h) (a h)) * + signedRankProduct (fun i => binomialLengthDifference + (tupleGap p i-gapIncidence r i + ∑ h, gapTermExtra h (k h) (a h) i) + (∑ h, gapTermOrder h (k h) (a h) i) θ) (fun _ => 0) v := by + have h := shifted_gap_series_expansion p hp k θ + rw [gapOperators_expansion] at h + have hh := congrArg (fun f : AddMonoidAlgebra ℝ (Fin (r+1) → ℤ) => + f.coeff (fun i => (tupleGap v.val i:ℤ))) h + simp only [AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply, + AddMonoidAlgebra.coeff_smul,Finsupp.smul_apply,smul_eq_mul,tensorSeries_coeff, + biasedSeries_coeff_nat] at hh + unfold positionalRankDifference + simp_rw [subsetRankKernel_binomial_formula hl _ (shiftedTag_strictMono p hp _) _ v.property θ hθ] + calc + _ = θ^r / binomialMass n θ l * + ∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h)) * + ∏ i, binomialMass (tupleGap (shiftedTag p hp a) i) θ (tupleGap v.val i) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + _ = _ := by + exact congrArg (fun t => θ^r / binomialMass n θ l * t) (by + simpa only [signedRankProduct,sub_zero] using hh) + +/-- The total derivative order is the source value |D|+2|V|. -/ +theorem gap_global_order {r : ℕ} (k : Fin r → GapDifference) (a : Fin r → Bool × Bool) : + (∑ i : Fin (r+1), ∑ h, gapTermOrder h (k h) (a h) i) = ∑ h, (k h).order := by + rw [Finset.sum_comm] + simp_rw [gapTermOrder_total] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction + +theorem gapTermOrder_sum_le_global {r : ℕ} (k : Fin r → GapDifference) + (a : Fin r → Bool × Bool) (i : Fin (r+1)) : + (∑ h, gapTermOrder h (k h) (a h) i) ≤ ∑ h, (k h).order := by + rw [← gap_global_order k a] + exact Finset.single_le_sum (f := fun j : Fin (r+1) => ∑ h, gapTermOrder h (k h) (a h) j) + (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + +/-- Literal mixed centered positional differences of a conditional rank +kernel, with a single explicit constant depending only on the total order +and the Bernoulli parameter. Every gap scale remains available for summing +over the period tuples in the signed initial construction. -/ +theorem positionalRankDifference_square_sum_le {n l r : ℕ} (hl : l ≤ n) + (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) + {θ G : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (hG : 0 < G) + (hgap : ∀ i, G ≤ (tupleGap p i-gapIncidence r i : ℕ)+1) + (e : Fin (r+1)) : + (∑ v : IncreasingTuple l r, positionalRankDifference hl p hp k v ^ 2) ≤ + (θ^r / binomialMass n θ l)^2 * (2:ℝ)^(2*r) * + (lengthDifferenceConstant (∑ h, (k h).order) θ)^(2*(∑ h, (k h).order)+r+2) / + (G^(∑ h, (k h).order) * Real.sqrt ((tupleGap p e-gapIncidence r e:ℕ)+1) * + ∏ i, Real.sqrt ((tupleGap p i-gapIncidence r i:ℕ)+1)) := by + let d := ∑ h, (k h).order + let C := lengthDifferenceConstant d θ + let b (i : Fin (r+1)) := tupleGap p i-gapIncidence r i + let B := C^(2*d+r+2) / (G^d*Real.sqrt ((b e:ℝ)+1)*∏ i,Real.sqrt ((b i:ℝ)+1)) + let c (a : Fin r → Bool × Bool) := ∏ h, gapTermWeight (k h) (a h) + let F (a : Fin r → Bool × Bool) (v : IncreasingTuple l r) := + signedRankProduct (fun i => binomialLengthDifference + (b i+∑ h, gapTermExtra h (k h) (a h) i) + (∑ h, gapTermOrder h (k h) (a h) i) θ) (fun _ => 0) v + have hC : 0 < C := lengthDifferenceConstant_pos d hθ + have hB0 : 0 ≤ B := by dsimp [B]; positivity + have hB (a : Fin r → Bool × Bool) : (∑ v, F a v^2) ≤ B := by + have hd (i : Fin (r+1)) : lengthDifferenceConstant (∑ h, gapTermOrder h (k h) (a h) i) θ ≤ C := + lengthDifferenceConstant_mono (gapTermOrder_sum_le_global k a i) hθ + have h := rank_derivatives_uniform (l := l) + (fun i => b i+∑ h, gapTermExtra h (k h) (a h) i) b + (fun i => ∑ h, gapTermOrder h (k h) (a h) i) (fun _ => 0) + hθ hd hG (fun _ => Nat.le_add_right _ _) (by + intro i + exact (hgap i).trans (by exact_mod_cast Nat.add_le_add_right (Nat.le_add_right (b i) _) 1)) e + simpa only [F,B,d,gap_global_order] using h + have hmix := rank_mixture_square_sum_le c F (fun _ => B) hB + have hM : (∑ a, |c a|) ≤ (2:ℝ)^r := gapOperators_weight_l1 k + have hM0 : 0 ≤ ∑ a, |c a| := Finset.sum_nonneg fun _ _ => abs_nonneg _ + have hmix' : (∑ v, (∑ a, c a*F a v)^2) ≤ (2:ℝ)^(2*r)*B := by + refine hmix.trans ?_ + rw [← Finset.sum_mul,← mul_assoc] + have hs : (∑ a, |c a|)^2 ≤ ((2:ℝ)^r)^2 := (sq_le_sq₀ hM0 (by positivity)).mpr hM + calc + _ = (∑ a, |c a|)^2*B := by ring + _ ≤ ((2:ℝ)^r)^2*B := mul_le_mul_of_nonneg_right hs hB0 + _ = _ := by rw [← pow_mul,Nat.mul_comm r 2] + simp_rw [positionalRankDifference_expansion hl p hp k hθ,mul_pow] + rw [← Finset.mul_sum] + calc + _ ≤ (θ^r / binomialMass n θ l)^2 * ((2:ℝ)^(2*r)*B) := + mul_le_mul_of_nonneg_left hmix' (sq_nonneg _) + _ = _ := by dsimp [B,C,d,b]; ring + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction + +theorem gapIncidence_le_two (r : ℕ) (i : Fin (r+1)) : gapIncidence r i ≤ 2 := by + have h₁ : Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i ≤ 1 := by + induction i using Fin.cases <;> simp + have h₂ : Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i ≤ 1 := by + induction i using Fin.lastCases <;> simp + exact Nat.add_le_add h₁ h₂ + +/-- Constant middle-period tags admit every independent left/unchanged/right +choice without violating slot order or either end boundary. -/ +theorem constant_period_safe {u m r : ℕ} (off : Fin m) + (hoff₁ : 1 ≤ off.val) (hoff₂ : off.val+1 < m) (hm : 3 ≤ m) + (j : Fin r → Fin u) (hj : StrictMono j) : + SafeTaggedTuple (periodSlot (fun _ => off) ∘ j) := by + constructor + · intro i + change 1 ≤ (j i).val*m+off.val ∧ (j i).val*m+off.val+1 < u*m + constructor + · omega + · have h := Nat.mul_le_mul_right m (Nat.succ_le_of_lt (j i).isLt) + rw [Nat.succ_mul] at h + omega + · intro i h hih + change (j i).val*m+off.val+3 ≤ (j h).val*m+off.val + have h := Nat.mul_le_mul_right m (Nat.succ_le_iff.mpr (hj hih)) + rw [Nat.succ_mul] at h + omega + +/-- Removing both incident displacement units still leaves a fixed +fraction of each actual coarse gap. Doubled coarse gaps are used to keep +all combinatorial labels integer-valued. -/ +theorem period_derivative_base_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : Fin r → Fin u) (hj : StrictMono j) + (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (i : Fin (r+1)) : + (m:ℝ)*coarsePeriodGap j i/4 ≤ + ((tupleGap (periodSlot off ∘ j) i-gapIncidence r i:ℕ):ℝ)+1 := by + have he := abs_le.mp (period_gap_rounding hr off hoff hdiff j hj i) + have hs := gapIncidence_le (periodSlot off ∘ j) hsafe i + have hs₂ : (gapIncidence r i:ℝ) ≤ 2 := by exact_mod_cast gapIncidence_le_two r i + have hc : 1 ≤ (coarsePeriodGap j i:ℝ) := by exact_mod_cast coarsePeriodGap_pos j i + have hm' : (32:ℝ) ≤ m := by exact_mod_cast hm + rw [Nat.cast_sub hs] + nlinarith + +theorem period_derivative_common_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : Fin r → Fin u) (hj : StrictMono j) + (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (i : Fin (r+1)) : + (m:ℝ)/4 ≤ ((tupleGap (periodSlot off ∘ j) i-gapIncidence r i:ℕ):ℝ)+1 := by + refine le_trans ?_ (period_derivative_base_lower hm hr off hoff hdiff j hj hsafe i) + have hc : 1 ≤ (coarsePeriodGap j i:ℝ) := by exact_mod_cast coarsePeriodGap_pos j i + nlinarith [show (0:ℝ) ≤ m by positivity] + +/-- A largest coarse gap supplies the additional square-root improvement +coming from the fixed sum of the observed ranks. -/ +theorem period_derivative_largest_lower {u m r : ℕ} (hm : 32 ≤ m) (hr : 0 < r) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : Fin r → Fin u) (hj : StrictMono j) + (hsafe : SafeTaggedTuple (periodSlot off ∘ j)) (e : Fin (r+1)) + (he : 2*u ≤ (r+1)*coarsePeriodGap j e) : + (u:ℝ)*m/(2*(r+1:ℝ)) ≤ + ((tupleGap (periodSlot off ∘ j) e-gapIncidence r e:ℕ):ℝ)+1 := by + refine le_trans ?_ (period_derivative_base_lower hm hr off hoff hdiff j hj hsafe e) + have he' : 2*(u:ℝ) ≤ (r+1:ℝ)*coarsePeriodGap j e := by exact_mod_cast he + apply (div_le_iff₀ (by positivity)).mpr + have hh := mul_le_mul_of_nonneg_right he' (show (0:ℝ) ≤ m by positivity) + nlinarith only [hh] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction + +theorem binomial_rank_normalization {n l r : ℕ} {θ : ℝ} + (hθ : θ ∈ Set.Ioo 0 1) (hl : l ≤ n) + (hmean : (n:ℝ)*θ=l) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) : + (θ^r/binomialMass n θ l)^2 ≤ 144*(n:ℝ) := by + have hpow : (θ^r)^2 ≤ 1 := pow_le_one₀ (pow_nonneg hθ.1.le r) (pow_le_one₀ hθ.1.le hθ.2.le) + calc + _ = (θ^r)^2*(binomialMass n θ l)⁻¹^2 := by rw [div_eq_mul_inv,mul_pow] + _ ≤ (binomialMass n θ l)⁻¹^2 := mul_le_of_le_one_left (sq_nonneg _) hpow + _ ≤ 144*((n:ℝ)*θ*(1-θ)) := binomialMass_mean_inverse_sq n l hθ hl hmean hv + _ ≤ _ := by + have h : θ*(1-θ) ≤ 1 := by nlinarith [sq_nonneg θ] + have hh := mul_le_mul_of_nonneg_left h (show 0 ≤ (n:ℝ) by positivity) + nlinarith only [hh] + +/-- The exact mean-count version, with arbitrary proven positive lower +scales for all gaps; no asymptotic or analytic estimate is assumed. -/ +theorem positionalRankDifference_scale_bound {n l r : ℕ} (hl : l ≤ n) + (p : Fin r → Fin n) (hp : SafeTaggedTuple p) (k : Fin r → GapDifference) + {θ G H : ℝ} (hθ : θ ∈ Set.Ioo 0 1) (hG : 0 < G) (hH : 0 < H) + (hmean : (n:ℝ)*θ=l) (hv : 1 ≤ (n:ℝ)*θ*(1-θ)) + (B : Fin (r+1) → ℝ) (hB : ∀ i, 0 < B i) + (hgap : ∀ i, G ≤ (tupleGap p i-gapIncidence r i:ℕ)+1) + (hscale : ∀ i, B i ≤ (tupleGap p i-gapIncidence r i:ℕ)+1) + (e : Fin (r+1)) (hlarge : H ≤ Real.sqrt ((tupleGap p e-gapIncidence r e:ℕ)+1)) : + (∑ v : IncreasingTuple l r, positionalRankDifference hl p hp k v ^ 2) ≤ + 144*(n:ℝ)*(2:ℝ)^(2*r)* + (lengthDifferenceConstant (∑ h, (k h).order) θ)^(2*(∑ h, (k h).order)+r+2) / + (G^(∑ h, (k h).order)*H*∏ i, Real.sqrt (B i)) := by + refine (positionalRankDifference_square_sum_le hl p hp k hθ hG hgap e).trans ?_ + have hC := (lengthDifferenceConstant_pos (∑ h, (k h).order) hθ).le + apply div_le_div₀ (by positivity) + · exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (binomial_rank_normalization hθ hl hmean hv) (by positivity)) + (pow_nonneg hC _) + · exact mul_pos (mul_pos (pow_pos hG _) hH) + (Finset.prod_pos (fun i _ => Real.sqrt_pos.mpr (hB i))) + · apply mul_le_mul + · exact mul_le_mul_of_nonneg_left hlarge (by positivity) + · exact Finset.prod_le_prod₀ (fun i _ => (Real.sqrt_nonneg (B i))) + (fun i _ => Real.sqrt_le_sqrt (hscale i)) + · exact Finset.prod_nonneg (fun _ _ => Real.sqrt_nonneg _) + · positivity + +/-- Explicit source rank-difference prefactor. It depends on the period +count, slot length, derivative order and Bernoulli parameter, not the +selected period tuple. -/ +def periodDifferencePrefactor (u m r d : ℕ) (θ : ℝ) : ℝ := + 144*((u*m:ℕ):ℝ)*(2:ℝ)^(2*r)*(lengthDifferenceConstant d θ)^(2*d+r+2) / + (((m:ℝ)/4)^d*Real.sqrt ((u:ℝ)*m/(2*(r+1:ℝ)))* + (Real.sqrt ((m:ℝ)/4))^(r+1)) + +/-- The finite-difference estimate for actual translated tagged slots in +periodic words. The tuple dependence is exactly the product of inverse +square roots of its doubled coarse gaps. -/ +theorem period_positionalRankDifference_bound {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) + (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : + (∑ v : IncreasingTuple l r, + positionalRankDifference hl (periodSlot off ∘ j.val) hsafe k v ^ 2) ≤ + periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by + have hu : 0 < u := lt_of_le_of_lt (Nat.zero_le (j.val ⟨0,hr⟩).val) (j.val ⟨0,hr⟩).isLt + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hu0 : (0:ℝ) < u := by exact_mod_cast hu + obtain ⟨e,he⟩ := exists_large_period_gap hr j + have hb (i : Fin (r+1)) := period_derivative_base_lower hm hr off hoff hdiff j.val j.property hsafe i + have hg (i : Fin (r+1)) := period_derivative_common_lower hm hr off hoff hdiff j.val j.property hsafe i + have hc (i : Fin (r+1)) : (0:ℝ) < coarsePeriodGap j.val i := by exact_mod_cast coarsePeriodGap_pos j.val i + have h := positionalRankDifference_scale_bound hl (periodSlot off ∘ j.val) hsafe k hθ + (G := (m:ℝ)/4) (H := Real.sqrt ((u:ℝ)*m/(2*(r+1:ℝ)))) (by positivity) (by positivity) + hmean hv (fun i => (m:ℝ)*coarsePeriodGap j.val i/4) (fun i => by positivity [hc i]) hg hb e + (Real.sqrt_le_sqrt (period_derivative_largest_lower hm hr off hoff hdiff j.val j.property hsafe e he)) + refine h.trans_eq ?_ + have hs (i : Fin (r+1)) : Real.sqrt ((m:ℝ)*coarsePeriodGap j.val i/4) = + Real.sqrt ((m:ℝ)/4)*Real.sqrt (coarsePeriodGap j.val i) := by + rw [show (m:ℝ)*coarsePeriodGap j.val i/4=((m:ℝ)/4)*coarsePeriodGap j.val i by ring, + Real.sqrt_mul (by positivity)] + simp_rw [hs] + rw [Finset.prod_mul_distrib] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + rw [periodDifferencePrefactor,Finset.prod_inv_distrib] + ring + +end TraceReconstruction + +open Filter +open scoped Topology + +noncomputable section +namespace TraceReconstruction + +/-- Two independent exact sum constraints determine a missing coordinate on + each side of a fixed cut. This is the second-gap elimination needed when + a period label has been fixed. -/ +theorem two_sums_determine {ι : Type*} [Fintype ι] [DecidableEq ι] + (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) + (x y : ι → ℕ) (hA : ∑ i∈A, x i = ∑ i∈A, y i) + (ht : ∑ i, x i = ∑ i, y i) + (hxy : ∀ i, i≠e → i≠d → x i=y i) : x=y := by + have hs : (∑ i∈A.erase e, x i) = ∑ i∈A.erase e, y i := by + apply Finset.sum_congr rfl + intro i hi + have hi' := Finset.mem_erase.mp hi + apply hxy i hi'.1 + intro hid + exact hd (hid ▸ hi'.2) + have hxe : x e=y e := by + have hx := Finset.sum_erase_add A x he + have hy := Finset.sum_erase_add A y he + omega + have hs' : (∑ i∈Finset.univ.erase d, x i) = ∑ i∈Finset.univ.erase d, y i := by + apply Finset.sum_congr rfl + intro i hi + by_cases hie : i=e + · simpa only [hie] using hxe + · exact hxy i hie (Finset.mem_erase.mp hi).1 + have hxd : x d=y d := by + have hx := Finset.sum_erase_add Finset.univ x (Finset.mem_univ d) + have hy := Finset.sum_erase_add Finset.univ y (Finset.mem_univ d) + omega + funext i + by_cases hie : i=e + · simpa only [hie] using hxe + by_cases hid : i=d + · simpa only [hid] using hxd + exact hxy i hie hid + +abbrev RemainingCoordinates {ι : Type*} (e d : ι) := {i : ι // i≠e ∧ i≠d} + +/-- Restricting an injective gap profile to all but the two eliminated + coordinates is still injective on two fixed-sum fibers. -/ +theorem two_sums_restrict_injective {α ι : Type*} [Fintype ι] [DecidableEq ι] + {U L V : ℕ} (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) + (p : α → ι → Fin (U+1)) (hp : Function.Injective p) + (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) : + Function.Injective (fun a => fun i : RemainingCoordinates e d => p a i.val) := by + intro a b hab + apply hp + have hv : (fun i => (p a i).val) = (fun i => (p b i).val) := by + apply two_sums_determine A he hd + · rw [hA,hA] + · rw [ht,ht] + · intro i hie hid + exact congrArg Fin.val (congrFun hab ⟨i,hie,hid⟩) + funext i + exact Fin.ext (congrFun hv i) + +/-- Once the two coordinates are eliminated all remaining gap weights sum + independently; any additional constraints may be dropped. -/ +theorem two_sums_product_bound {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] + {U L V : ℕ} (A : Finset ι) {e d : ι} (he : e∈A) (hd : d∉A) + (p : α → ι → Fin (U+1)) (hp : Function.Injective p) + (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) + (w : ι → Fin (U+1) → ℝ) (hw : ∀ i k, 0≤w i k) : + (∑ a, ∏ i : RemainingCoordinates e d, w i.val (p a i.val)) ≤ + ∏ i : RemainingCoordinates e d, ∑ k, w i.val k := by + classical + have hh := sum_injective_profile_le + (fun a => fun i : RemainingCoordinates e d => p a i.val) + (two_sums_restrict_injective A he hd p hp hA ht) + (fun _ => True) (fun _ => trivial) + (fun δ => ∏ i : RemainingCoordinates e d, w i.val (δ i)) + (fun δ => Finset.prod_nonneg (fun i _ => hw i.val (δ i))) + simp only [ite_true] at hh + exact hh.trans_eq (by rw [Finset.prod_univ_sum]; simp only [Fintype.piFinset_univ]) + +/-- The sum of doubled coarse gaps to a specified period label is exact, + including the half endpoint cells in the source convention. -/ +theorem coarsePeriodGap_prefix {u r : ℕ} (j : Fin r → Fin u) (hj : StrictMono j) + (i : Fin r) : (∑ g∈Finset.Iic i.castSucc, coarsePeriodGap j g) = 2*(j i).val+1 := by + classical + have hg := tupleGap_prefix j hj i + have hz : (0 : Fin (r+1)) ∈ Finset.Iic i.castSucc := by simp + have hl : ∀ g∈Finset.Iic i.castSucc, g≠Fin.last r := by + intro g hg he + have hle := Finset.mem_Iic.mp hg + have hval : g.val ≤ i.val := hle + have he' := congrArg Fin.val he + simp only [Fin.val_last] at he' + omega + have hc : (∑ g∈Finset.Iic i.castSucc, + if g=0 ∨ g=Fin.last r then 1 else 2) = 2*i.val+1 := by + have hsub : (∑ g∈(Finset.Iic i.castSucc).erase 0, + if g=0 ∨ g=Fin.last r then 1 else 2) = 2*i.val := by + have hc : ((Finset.Iic i.castSucc).erase 0).card = i.val := by + rw [Finset.card_erase_of_mem hz,Fin.card_Iic] + simp + calc + _ = ∑ _g∈(Finset.Iic i.castSucc).erase 0, 2 := by + apply Finset.sum_congr rfl + intro g hg + rw [ite_eq_right (not_or.mpr ⟨(Finset.mem_erase.mp hg).1, + hl g (Finset.mem_erase.mp hg).2⟩)] + _ = _ := by simp [hc,Nat.mul_comm] + have hsum := Finset.sum_erase_add (Finset.Iic i.castSucc) + (fun g => if g=0 ∨ g=Fin.last r then 1 else 2) hz + rw [hsub] at hsum + simpa using hsum.symm + simp only [coarsePeriodGap,Finset.sum_add_distrib,← Finset.mul_sum] + omega + +/-- The full inverse-square-root sum, including the zero cell (whose + value is zero), has the same elementary integral bound. -/ +theorem fin_sum_inverse_sqrt (U : ℕ) : + (∑ k : Fin (U+1), (Real.sqrt (k.val:ℝ))⁻¹) ≤ 2*Real.sqrt U := by + rw [Fin.sum_univ_succ] + simp only [Fin.val_zero, Nat.cast_zero, Real.sqrt_zero, inv_zero,zero_add,Fin.val_succ] + have h := sum_inverse_sqrt U + rw [Finset.sum_range] at h + simpa only [Nat.cast_add,Nat.cast_one] using h + +theorem prod_two_coordinates {ι : Type*} [Fintype ι] [DecidableEq ι] + {e d : ι} (hed : e≠d) (f : ι → ℝ) : + (∏ i, f i) = f e*f d*∏ i : RemainingCoordinates e d, f i.val := by + have hd : d∈Finset.univ.erase e := by simp [hed.symm] + have h1 := Finset.prod_erase_mul Finset.univ f (Finset.mem_univ e) + have h2 := Finset.prod_erase_mul (Finset.univ.erase e) f hd + have hrem : (∏ i∈(Finset.univ.erase e).erase d, f i) = + ∏ i : RemainingCoordinates e d, f i.val := + Finset.prod_subtype _ (by intro i; simp [and_comm]) f + rw [← h1,← h2,hrem] + ring + +theorem inverse_sqrt_pair {x y R : ℝ} (hR : 0 (Real.sqrt (k.val:ℝ))⁻¹) (fun _ _ => by positivity) + _ ≤ R⁻¹*∏ _i : RemainingCoordinates e d, (2*Real.sqrt U) := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hR.le) + exact Finset.prod_le_prod₀ (fun _ _ => by positivity) (fun _ _ => fin_sum_inverse_sqrt U) + _ = _ := by simp + +/-- The fixed involved label is a genuine geometric fiber, not an extra + analytic hypothesis on the rank kernel. -/ +def FixedPeriodTuple (u r : ℕ) (a : Fin r) (h : Fin u) := + {j : IncreasingTuple u r // j.val a=h} + +noncomputable instance fixedPeriodTupleFintype (u r : ℕ) (a : Fin r) (h : Fin u) : + Fintype (FixedPeriodTuple u r a h) := by + unfold FixedPeriodTuple + exact Fintype.ofFinite _ + +def fixedPeriodProfile {u r : ℕ} (a : Fin r) (h : Fin u) (j : FixedPeriodTuple u r a h) : + Fin (r+1) → Fin (2*u+1) := fun i => + ⟨coarsePeriodGap j.val.val i, Nat.lt_succ_of_le + (coarsePeriodGap_le (Nat.zero_lt_of_lt a.isLt) j.val.val j.val.property i)⟩ + +theorem fixedPeriodProfile_injective {u r : ℕ} (a : Fin r) (h : Fin u) : + Function.Injective (fixedPeriodProfile a h) := by + intro j k hjk + apply Subtype.ext + apply Subtype.ext + apply coarsePeriodGap_injective j.val.property k.val.property + funext i + exact congrArg Fin.val (congrFun hjk i) + +theorem fixedPeriodProfile_prefix {u r : ℕ} (a : Fin r) (h : Fin u) + (j : FixedPeriodTuple u r a h) : + (∑ i∈Finset.Iic a.castSucc, (fixedPeriodProfile a h j i).val)=2*h.val+1 := by + change (∑ i∈Finset.Iic a.castSucc, coarsePeriodGap j.val.val i)=_ + rw [coarsePeriodGap_prefix _ j.val.property,j.property] + +theorem fixedPeriodProfile_total {u r : ℕ} (a : Fin r) (h : Fin u) + (j : FixedPeriodTuple u r a h) : + (∑ i, (fixedPeriodProfile a h j i).val)=2*u := + coarsePeriodGap_sum (Nat.zero_lt_of_lt a.isLt) j.val.val j.val.property + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction + +/-- An elementary centered MGF bound valid on both sides of the mean, + with constants independent of the Bernoulli parameter. -/ +theorem binomialMass_centered_mgf (n : ℕ) {p t : ℝ} + (hp : p∈Set.Icc 0 1) (ht : |t|≤1) : + (∑ k∈Finset.range (n+1), binomialMass n p k*Real.exp (t*((k:ℝ)-n*p))) ≤ + Real.exp ((n:ℝ)*t^2) := by + have he := (abs_le.mp (Real.abs_exp_sub_one_sub_id_le ht)).2 + have hn : 0≤(n:ℝ)*p := mul_nonneg (Nat.cast_nonneg _) hp.1 + have hn' : (n:ℝ)*p≤n := mul_le_of_le_one_right (Nat.cast_nonneg _) hp.2 + calc + _ = Real.exp (-t*(n:ℝ)*p)* + ∑ k∈Finset.range (n+1), binomialMass n p k*Real.exp (t*k) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + rw [mul_left_comm,← Real.exp_add] + congr 2 + ring + _ ≤ Real.exp (-t*(n:ℝ)*p)*Real.exp ((n:ℝ)*p*(Real.exp t-1)) := + mul_le_mul_of_nonneg_left (binomialMass_mgf_le n hp t) (Real.exp_nonneg _) + _ ≤ Real.exp ((n:ℝ)*t^2) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have he' := mul_le_mul_of_nonneg_left he hn + have hs := mul_le_mul_of_nonneg_right hn' (sq_nonneg t) + nlinarith only [he',hs] + +/-- Either signed deviation has the same Chernoff estimate. -/ +theorem binomialMass_signed_tail (n : ℕ) {p t a ε : ℝ} + (hp : p∈Set.Icc 0 1) (ht : t∈Set.Icc 0 1) (hε : ε=1 ∨ ε= -1) : + (∑ k∈(Finset.range (n+1)).filter (fun k : ℕ => a≤ε*((k:ℝ)-n*p)), binomialMass n p k) ≤ + Real.exp (-t*a+(n:ℝ)*t^2) := by + have heps : |t*ε|≤1 := by rcases hε with rfl | rfl <;> simpa [abs_of_nonneg ht.1] using ht.2 + have hm := finite_exp_markov (Finset.range (n+1)) (binomialMass n p) + (fun k : ℕ => ε*((k:ℝ)-n*p)) (fun k _ => binomialMass_nonneg n k hp) a t ht.1 + calc + _ ≤ Real.exp (-t*a)*∑ k∈Finset.range (n+1), + binomialMass n p k*Real.exp ((t*ε)*((k:ℝ)-n*p)) := by + simpa only [mul_assoc] using hm + _ ≤ Real.exp (-t*a)*Real.exp ((n:ℝ)*(t*ε)^2) := + mul_le_mul_of_nonneg_left (binomialMass_centered_mgf n hp heps) (Real.exp_nonneg _) + _ = _ := by rcases hε with rfl | rfl <;> simp [Real.exp_add] + +/-- A uniform two-sided tail at any finite cutoff. Unlike a quoted + concentration theorem, this follows here from the finite binomial MGF. -/ +theorem binomialMass_abs_tail (n : ℕ) {p t a : ℝ} + (hp : p∈Set.Icc 0 1) (ht : t∈Set.Icc 0 1) : + (∑ k∈(Finset.range (n+1)).filter (fun k : ℕ => a≤|(k:ℝ)-n*p|), binomialMass n p k) ≤ + 2*Real.exp (-t*a+(n:ℝ)*t^2) := by + have hpoint (k : ℕ) : (if a≤|(k:ℝ)-n*p| then binomialMass n p k else 0) ≤ + (if a≤(k:ℝ)-n*p then binomialMass n p k else 0)+ + (if a≤-((k:ℝ)-n*p) then binomialMass n p k else 0) := by + have hn := binomialMass_nonneg n k hp + by_cases h : a≤|(k:ℝ)-n*p| + · rw [ite_eq_left h] + have hh := le_abs.mp h + rcases hh with h1 | h2 + · rw [ite_eq_left h1] + split_ifs <;> linarith + · rw [ite_eq_left h2] + split_ifs <;> linarith + · rw [ite_eq_right h] + split_ifs <;> linarith + have hh := Finset.sum_le_sum (s := Finset.range (n+1)) (fun k _ => hpoint k) + rw [Finset.sum_add_distrib,← Finset.sum_filter,← Finset.sum_filter,← Finset.sum_filter] at hh + have h1 := binomialMass_signed_tail n (a:=a) hp ht (Or.inl rfl : (1:ℝ)=1 ∨ (1:ℝ)= -1) + have h2 := binomialMass_signed_tail n (a:=a) hp ht (Or.inr rfl : (-1:ℝ)=1 ∨ (-1:ℝ)= -1) + simp only [one_mul,neg_one_mul] at h1 h2 + linarith + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction + +/-- Cardinality bookkeeping for the two eliminated gap coordinates. -/ +theorem remainingCoordinates_card {ι : Type*} [Fintype ι] [DecidableEq ι] + {e d : ι} (hed : e≠d) : + Fintype.card (RemainingCoordinates e d)=Fintype.card ι-2 := by + classical + have hset : (Finset.univ.filter (fun i : ι => i≠e ∧ i≠d)) = (Finset.univ.erase e).erase d := by + ext i + simp [and_comm] + rw [Fintype.card_subtype, hset] + rw [Finset.card_erase_of_mem (by simp [hed.symm]), + Finset.card_erase_of_mem (Finset.mem_univ e)] + simp only [Finset.card_univ] + omega + +/-- A finite sum's largest entry on a nonempty set controls its average, + with the full number of coordinates in place of the subset cardinality. -/ +theorem exists_large_in_subset {ι : Type*} [Fintype ι] [DecidableEq ι] + (A : Finset ι) (hA : A.Nonempty) (x : ι → ℝ) (hx : ∀ i, 0≤x i) + {R : ℝ} (hR : R*Fintype.card ι ≤ ∑ i∈A, x i) : + ∃ e∈A, R≤x e := by + obtain ⟨e,he,hm⟩ := A.exists_max_image x hA + refine ⟨e,he,?_⟩ + have hc : (A.card:ℝ)≤Fintype.card ι := by exact_mod_cast Finset.card_le_univ A + have hcard : (0:ℝ) hm i hi) + _ = (A.card:ℝ)*x e := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right hc (hx e) + nlinarith + +/-- Covering the fixed-sum profile by its selected largest coordinates + costs only the square of its (fixed) dimension. -/ +theorem two_sided_large_gaps_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] + {U L V : ℕ} (A : Finset ι) + (p : α → ι → Fin (U+1)) (hp : Function.Injective p) + (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) + {R : ℝ} (hR : 0 p a.val) (hp.comp Subtype.val_injective) + (fun a => hA a.val) (fun a => ht a.val) hR + (fun a => by have h := congrArg Prod.fst a.property; simpa only [f] using h ▸ heR a.val) + (fun a => by have h := congrArg Prod.snd a.property; simpa only [f] using h ▸ hdR a.val) + simpa only [W,remainingCoordinates_card hzd] using hh + · have : IsEmpty {a // f a=z} := not_nonempty_iff.mp hne + simp only [Fintype.sum_empty] + positivity + calc + _ = ∑ z : ι × ι, ∑ a : {a // f a=z}, W a.val := by + exact (Fintype.sum_fiberwise f W).symm + _ ≤ ∑ _z : ι × ι, R⁻¹*(2*Real.sqrt U)^(Fintype.card ι-2) := + Finset.sum_le_sum (fun z _ => hfiber z) + _ = _ := by simp [pow_two,mul_assoc] + +/-- The fixed central label leaves a macroscopic sum on both sides. -/ +theorem fixedPeriodProfile_central_sum {u r : ℕ} (a : Fin r) (h : Fin u) + (hleft : (u:ℝ)/3≤2*h.val+1) + (hright : (u:ℝ)/3≤2*u-(2*h.val+1)) : + (∑ j : FixedPeriodTuple u r a h, + ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹) ≤ + ((r+1:ℕ):ℝ)^2 * ((u:ℝ)/(3*(r+1:ℝ)))⁻¹ * + (2*Real.sqrt (2*u:ℕ))^(r-1) := by + classical + have hu : (0:ℝ) (p j i).val) + (fun _ => Nat.cast_nonneg _) + have hs := fixedPeriodProfile_prefix a h j + have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs + rw [hs'] + simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] + convert hleft using 1; field_simp + have hD (j : FixedPeriodTuple u r a h) : + ∃ d∉A, (u:ℝ)/(3*(r+1:ℝ))≤(p j d).val := by + have ha : a.val ((p j i).val:ℝ)) (fun _ => Nat.cast_nonneg _) (R := (u:ℝ)/(3*(r+1:ℝ))) (by + have hs := fixedPeriodProfile_prefix a h j + have ht := fixedPeriodProfile_total a h j + have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs + have ht' : (∑ i, ((p j i).val:ℝ))=2*u := by exact_mod_cast ht + have hc := Finset.sum_compl_add_sum A (fun i => ((p j i).val:ℝ)) + have hsum : (∑ i∈Aᶜ, ((p j i).val:ℝ))=2*u-(2*h.val+1) := by linarith + rw [hsum] + simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] + convert hright using 1; field_simp) + exact ⟨d,Finset.mem_compl.mp hd,hdR⟩ + have hh := two_sided_large_gaps_sum A p (fixedPeriodProfile_injective a h) + (fixedPeriodProfile_prefix a h) (fixedPeriodProfile_total a h) hR hL hD + simpa only [p,fixedPeriodProfile,Fin.val_mk,Fintype.card_fin,show r+1-2=r-1 by omega] using hh + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction + +/-- Any finite cutoff only removes nonnegative mass from the full binomial + support, even if the cutoff extends beyond that support. -/ +theorem binomialMass_cutoff_filter_le (n U : ℕ) {p : ℝ} (hp : p∈Set.Icc 0 1) + (P : ℕ → Prop) [DecidablePred P] : + (∑ k : Fin (U+1), if P k.val then binomialMass n p k.val else 0) ≤ + ∑ k∈(Finset.range (n+1)).filter P, binomialMass n p k := by + rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => if P k then binomialMass n p k else 0) (U+1),Finset.sum_filter] + by_cases hU : U≤n + · apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono (by omega)) + intro k _ _ + split_ifs + · exact binomialMass_nonneg n k hp + · rfl + · apply le_of_eq + symm + apply Finset.sum_subset (Finset.range_mono (by omega)) + intro k _ hk + have hnk : n True) (fun _ => trivial) + (fun δ => ∏ i, w' i (δ i)) (fun δ => Finset.prod_nonneg (fun i _ => hw' i (δ i))) + simpa only [ite_true] using hh + _ = ∏ i, ∑ k, w' i k := (Fintype.prod_sum _).symm + _ ≤ ∏ i : ι, if i=e then T else 1 := + Finset.prod_le_prod₀ (fun i _ => Finset.sum_nonneg (fun k _ => hw' i k)) (fun i _ => hsum i) + _ = T := by simp + +/-- Exponentially small clipping loss for a single gap of the actual + conditional retained-subset rank kernel. -/ +theorem subsetRankKernel_gap_tail {n l r : ℕ} (hl : l≤n) + (p : Fin r → Fin n) (hp : StrictMono p) (e : Fin (r+1)) + {θ t a : ℝ} (hθ : θ∈Set.Ioo 0 1) (ht : t∈Set.Icc 0 1) : + (∑ v : IncreasingTuple l r, + if a≤|(tupleGap v.val e:ℝ)-(tupleGap p e:ℝ)*θ| + then subsetRankKernel hl p v.val else 0) ≤ + θ^r / binomialMass n θ l * + (2*Real.exp (-t*a+(tupleGap p e:ℝ)*t^2)) := by + classical + have hθ' : θ∈Set.Icc 0 1 := ⟨hθ.1.le,hθ.2.le⟩ + let prof := rankGapProfile (n := l) (r := r) (Equiv.refl _) + let w (i : Fin (r+1)) (k : Fin (l-r+1)) := binomialMass (tupleGap p i) θ k.val + have hw (i k) : 0≤w i k := binomialMass_nonneg _ _ hθ' + have hs (i) : (∑ k, w i k)≤1 := by + have hh := binomialMass_cutoff_filter_le (tupleGap p i) (l-r) hθ' (fun _ => True) + simpa only [ite_true,Finset.filter_true,sum_binomialMass] using hh + have ht' : (∑ k : Fin (l-r+1), + if a≤|(k.val:ℝ)-(tupleGap p e:ℝ)*θ| then w e k else 0) ≤ + 2*Real.exp (-t*a+(tupleGap p e:ℝ)*t^2) := by + exact (binomialMass_cutoff_filter_le (tupleGap p e) (l-r) hθ' + (fun k : ℕ => a≤|(k:ℝ)-(tupleGap p e:ℝ)*θ|)).trans + (binomialMass_abs_tail _ hθ' ht) + have hh := profile_coordinate_event_le prof (rankGapProfile_injective _) w hw hs e + (fun k => a≤|(k.val:ℝ)-(tupleGap p e:ℝ)*θ|) (by positivity) ht' + have hfac : 0≤θ^r / binomialMass n θ l := + div_nonneg (pow_nonneg hθ.1.le _) (binomialMass_nonneg _ _ hθ') + calc + _ = θ^r / binomialMass n θ l * + ∑ v : IncreasingTuple l r, + if a≤|(tupleGap v.val e:ℝ)-(tupleGap p e:ℝ)*θ| + then ∏ i, binomialMass (tupleGap p i) θ (tupleGap v.val i) else 0 := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro v _ + split_ifs + · exact subsetRankKernel_binomial_formula hl p hp v.val v.property θ hθ + · simp + _ ≤ _ := mul_le_mul_of_nonneg_left (by + simpa only [prof,rankGapProfile,Equiv.refl_apply,w] using hh) hfac + +/-- A coordinatewise rank region has a union-bound clipping estimate. -/ +theorem subsetRankKernel_outside_region {n l r : ℕ} (hl : l≤n) + (p : Fin r → Fin n) (hp : StrictMono p) + {θ t a : ℝ} (hθ : θ∈Set.Ioo 0 1) (ht : t∈Set.Icc 0 1) : + (∑ v : IncreasingTuple l r, + if ∃ i, a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0) ≤ + ((r+1:ℕ):ℝ)*θ^r / binomialMass n θ l * + (2*Real.exp (-t*a+(n:ℝ)*t^2)) := by + classical + have hθ' : θ∈Set.Icc 0 1 := ⟨hθ.1.le,hθ.2.le⟩ + have hpoint (v : IncreasingTuple l r) : + (if ∃ i, a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0) ≤ + ∑ i, if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0 := by + have hn (i) : 0≤(if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0) := by + split_ifs + · exact subsetRankKernel_nonneg hl p v.val + · rfl + split_ifs with h + · obtain ⟨e,he⟩ := h + have hh := Finset.single_le_sum (fun i _ => hn i) (Finset.mem_univ e) + simpa only [ite_eq_left he] using hh + · exact Finset.sum_nonneg (fun i _ => hn i) + calc + _ ≤ ∑ v : IncreasingTuple l r, ∑ i, + if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0 := Finset.sum_le_sum (fun v _ => hpoint v) + _ = ∑ i, ∑ v : IncreasingTuple l r, + if a≤|(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0 := Finset.sum_comm + _ ≤ ∑ _i : Fin (r+1), θ^r / binomialMass n θ l * + (2*Real.exp (-t*a+(n:ℝ)*t^2)) := by + apply Finset.sum_le_sum + intro i _ + apply (subsetRankKernel_gap_tail hl p hp i hθ ht).trans + apply mul_le_mul_of_nonneg_left _ (div_nonneg (pow_nonneg hθ.1.le _) (binomialMass_nonneg _ _ hθ')) + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + have hgap : tupleGap p i≤n := (tupleGap_le_remainder ⟨p,hp⟩ i).trans (Nat.sub_le _ _) + have hg : (tupleGap p i:ℝ)≤n := by exact_mod_cast hgap + have hh := mul_le_mul_of_nonneg_right hg (sq_nonneg t) + linarith + _ = _ := by simp; ring + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction + +/-- An inverse square root at an integer, extended by zero at zero, + never exceeds one. -/ +theorem inverse_sqrt_nat_le_one (k : ℕ) : (Real.sqrt (k:ℝ))⁻¹≤1 := by + by_cases hk : k=0 + · simp [hk] + have hk' : (1:ℝ)≤k := by exact_mod_cast (Nat.one_le_iff_ne_zero.mpr hk) + have hs : 1≤Real.sqrt (k:ℝ) := by simpa using Real.sqrt_le_sqrt hk' + exact (inv_le_one₀ (by positivity : 0 k.val≤M)).card:ℝ) := by simp + _ ≤ M+1 := by + have hh : (Finset.univ.filter (fun k : Fin (U+1) => k.val≤M)).card≤M+1 := by + rw [← Finset.card_range (M+1)] + apply Finset.card_le_card_of_injOn Fin.val + (fun k hk => by + have hh := (Finset.mem_filter.mp hk).2 + exact Finset.mem_range.mpr (Nat.lt_succ_of_le hh)) + intro k _ j _ hkj; exact Fin.ext hkj + exact_mod_cast hh + +theorem prod_one_special {ι : Type*} [Fintype ι] [DecidableEq ι] + (e : ι) (A B : ℝ) : + (∏ i : ι, if i=e then A else B)=A*B^(Fintype.card ι-1) := by + rw [← Finset.mul_prod_erase Finset.univ (fun i => if i=e then A else B) (Finset.mem_univ e)] + simp only [ite_true] + have hh : (∏ i∈Finset.univ.erase e, if i=e then A else B)= + ∏ _i∈Finset.univ.erase e, B := by + apply Finset.prod_congr rfl + intro i hi + exact ite_eq_right (Finset.mem_erase.mp hi).1 + rw [hh] + simp + +/-- Refined two-gap elimination when a third gap has bounded size. -/ +theorem two_large_bounded_gap_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] + {U L V M : ℕ} (A : Finset ι) {e d c : ι} (he : e∈A) (hd : d∉A) + (hce : c≠e) (hcd : c≠d) + (p : α → ι → Fin (U+1)) (hp : Function.Injective p) + (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) + {R : ℝ} (hR : 0 positivity + have hwP (a i) : w i (p a i)=(Real.sqrt ((p a i).val:ℝ))⁻¹ := by + by_cases hi : i=c + · subst i; simp only [w,ite_true,ite_eq_left (hcM a)] + · simp only [w,ite_eq_right hi] + have hwS (i : RemainingCoordinates e d) : (∑ k, w i.val k)≤ + if i=c' then (M+1:ℝ) else 2*Real.sqrt U := by + by_cases hi : i=c' + · subst i + simpa only [c',w,ite_true] using fin_bounded_inverse_sqrt U M + · have hic : i.val≠c := by intro h; apply hi; exact Subtype.ext h + simpa only [w,ite_eq_right hi,ite_eq_right hic] using fin_sum_inverse_sqrt U + calc + _ ≤ ∑ a, R⁻¹*∏ i : RemainingCoordinates e d, w i.val (p a i.val) := by + apply Finset.sum_le_sum + intro a _ + simp_rw [hwP] + rw [prod_two_coordinates hed] + exact mul_le_mul_of_nonneg_right (inverse_sqrt_pair hR (heR a) (hdR a)) (by positivity) + _ = R⁻¹*∑ a, ∏ i : RemainingCoordinates e d, w i.val (p a i.val) := by rw [Finset.mul_sum] + _ ≤ R⁻¹*∏ i : RemainingCoordinates e d, ∑ k, w i.val k := + mul_le_mul_of_nonneg_left (two_sums_product_bound A he hd p hp hA ht w hw) (inv_nonneg.mpr hR.le) + _ ≤ R⁻¹*∏ i : RemainingCoordinates e d, if i=c' then (M+1:ℝ) else 2*Real.sqrt U := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hR.le) + exact Finset.prod_le_prod₀ (fun i _ => Finset.sum_nonneg (fun k _ => hw i.val k)) (fun i _ => hwS i) + _ = _ := by + rw [prod_one_special,remainingCoordinates_card hed] + simp only [Nat.sub_sub] + ring + +/-- A small internal gap cannot be either selected macroscopic gap. + The bound retains the extra factor u^(-1/2) needed for nonlinear terms. -/ +theorem two_sided_bounded_gaps_sum {α ι : Type*} [Fintype α] [Fintype ι] [DecidableEq ι] + {U L V M : ℕ} (A : Finset ι) (c : ι) + (p : α → ι → Fin (U+1)) (hp : Function.Injective p) + (hA : ∀ a, ∑ i∈A, (p a i).val=L) (ht : ∀ a, ∑ i, (p a i).val=V) + {R : ℝ} (hR : 0 p a.val) (hp.comp Subtype.val_injective) + (fun a => hA a.val) (fun a => ht a.val) hR + (fun a => by have h := congrArg Prod.fst a.property; simpa only [f] using h ▸ heR a.val) + (fun a => by have h := congrArg Prod.snd a.property; simpa only [f] using h ▸ hdR a.val) + (fun a => hcM a.val) + · have : IsEmpty {a // f a=z} := not_nonempty_iff.mp hne + simp only [Fintype.sum_empty] + positivity + calc + _ = ∑ z : ι × ι, ∑ a : {a // f a=z}, W a.val := (Fintype.sum_fiberwise f W).symm + _ ≤ ∑ _z : ι × ι, R⁻¹*(M+1)*(2*Real.sqrt U)^(Fintype.card ι-3) := + Finset.sum_le_sum (fun z _ => hfiber z) + _ = _ := by simp [pow_two,mul_assoc] + +end TraceReconstruction + + +noncomputable section +open scoped Classical +namespace TraceReconstruction + +/-- The literal rank-clipping rectangles used in the manuscript, with + doubled coarse gaps to avoid half-integer natural indices. Only the + first and internal gaps are needed to determine the period tuple. -/ +def PeriodRankRegion {u l r : ℕ} (m : ℕ) (θ : ℝ) + (j : IncreasingTuple u r) (v : IncreasingTuple l r) : Prop := + ∀ i : Fin r, |(tupleGap v.val i.castSucc:ℝ)- + θ*m*(coarsePeriodGap j.val i.castSucc:ℝ)/2| < (m:ℝ)/8 + +/-- Enough accuracy to distinguish two integer gap lengths. -/ +theorem nearby_gap_centers_equal {x y : ℕ} {z θ m : ℝ} + (hθ : 1 / 2 ≤ θ) (hm : 0 < m) + (hx : |z - θ * m * x / 2| < m / 8) (hy : |z - θ * m * y / 2| < m / 8) : x = y := by + have hx' := abs_lt.mp hx + have hy' := abs_lt.mp hy + have hscale : m / 4 ≤ θ * m / 2 := by nlinarith + by_contra hxy + obtain h | h := lt_or_gt_of_ne hxy + · have h' : (x:ℝ)+1≤y := by exact_mod_cast h + have hh := mul_le_mul_of_nonneg_left h' (by positivity : 0 ≤ θ * m / 2) + nlinarith + · have h' : (y:ℝ)+1≤x := by exact_mod_cast h + have hh := mul_le_mul_of_nonneg_left h' (by positivity : 0 ≤ θ * m / 2) + nlinarith + +/-- Regions for distinct tagged period tuples are genuinely disjoint, + before any coefficient or orientation averaging. -/ +theorem periodRankRegion_unique {u l r m : ℕ} (hm : 0 < m) {θ : ℝ} (hθ : 1 / 2 ≤ θ) + {j k : IncreasingTuple u r} {v : IncreasingTuple l r} + (hj : PeriodRankRegion m θ j v) (hk : PeriodRankRegion m θ k v) : j=k := by + apply Subtype.ext + by_cases hr : r=0 + · subst r; exact Subsingleton.elim _ _ + have hg (i : Fin r) : coarsePeriodGap j.val i.castSucc=coarsePeriodGap k.val i.castSucc := + nearby_gap_centers_equal hθ (by exact_mod_cast hm) (hj i) (hk i) + have hsum := coarsePeriodGap_sum (Nat.pos_of_ne_zero hr) j.val j.property + have hsum' := coarsePeriodGap_sum (Nat.pos_of_ne_zero hr) k.val k.property + have hgSum : (∑ i : Fin r, coarsePeriodGap j.val i.castSucc)= + ∑ i : Fin r, coarsePeriodGap k.val i.castSucc := Finset.sum_congr rfl (fun i _ => hg i) + rw [Fin.sum_univ_castSucc] at hsum hsum' + have hlast : coarsePeriodGap j.val (Fin.last r)=coarsePeriodGap k.val (Fin.last r) := by omega + apply coarsePeriodGap_injective j.property k.property + funext i + refine Fin.lastCases hlast (fun i => hg i) i + +/-- Orthogonality of a finite family with pointwise disjoint supports. -/ +theorem disjoint_support_sum_sq {α β : Type*} [Fintype α] [Fintype β] + (f : α → β → ℝ) (hf : ∀ a b, a≠b → ∀ v, f a v*f b v=0) : + (∑ v, (∑ a, f a v)^2) = ∑ a, ∑ v, f a v^2 := by + classical + have hp (v) : (∑ a, f a v)^2=∑ a, f a v^2 := by + rw [pow_two,Finset.sum_mul] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.mul_sum] + rw [Finset.sum_eq_single a] + · ring + · intro b _ hba + exact hf a b hba.symm v + · intro ha + exact False.elim (ha (Finset.mem_univ a)) + simp_rw [hp] + exact Finset.sum_comm + +/-- Squared norm of the clipped sum is at most the sum of the original + squared norms, with arbitrary signed multipliers on each tuple. -/ +theorem period_clipped_square_sum {u l r m : ℕ} (hm : 0 < m) {θ : ℝ} (hθ : 1 / 2 ≤ θ) + (W : IncreasingTuple u r → IncreasingTuple l r → ℝ) + (a : IncreasingTuple u r → ℝ) : + (∑ v, (∑ j, if PeriodRankRegion m θ j v then a j*W j v else 0)^2) ≤ + ∑ j, a j^2*∑ v, W j v^2 := by + classical + rw [disjoint_support_sum_sq _ (by + intro j k hjk v + by_cases hj : PeriodRankRegion m θ j v + · have hk : ¬PeriodRankRegion m θ k v := fun hk => hjk (periodRankRegion_unique hm hθ hj hk) + simp only [ite_eq_left hj,ite_eq_right hk,mul_zero] + · simp only [ite_eq_right hj,zero_mul])] + apply Finset.sum_le_sum + intro j _ + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro v _ + split_ifs + · exact le_of_eq (mul_pow _ _ _) + · simp only [zero_pow (by norm_num : 2 ≠ 0)] + exact mul_nonneg (sq_nonneg _) (sq_nonneg _) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +instance : Fintype GapDifference := + ⟨{.unchanged,.first,.second}, by intro k; cases k <;> simp⟩ + +theorem sum_gapDifference (f : GapDifference → ℝ) : + (∑ k, f k)=f .unchanged+f .first+f .second := by + change (∑ k ∈ ({.unchanged,.first,.second} : Finset GapDifference), f k)=_ + simp [Finset.sum_insert]; ring + +/-- The sign-dependent displacement in {-1,0,1}, represented by Fin 3. -/ +def motifShift (χ β τ : ℝ) : Fin 3 := + if χ=0 then 1 else if β*τ=1 then 2 else 0 + +/-- Coefficients of 1 + χ V + τ β D. -/ +def motifDifferenceWeight (χ β τ : ℝ) : GapDifference → ℝ + | .unchanged => 1 | .first => τ*β | .second => χ + +/-- The centered operator expansion is an exact displacement, not an + approximation of the trace kernel. -/ +theorem motif_positional_identity {χ β τ : ℝ} (hβ : IsMotifValue χ β) + (hτ : IsTypeSign τ) (a : Fin 3) : + (∑ k, motifDifferenceWeight χ β τ k * positionalWeight k a)= + if a=motifShift χ β τ then 1 else 0 := by + rw [sum_gapDifference] + rcases hβ with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> + rcases hτ with rfl | rfl <;> fin_cases a <;> + norm_num [motifDifferenceWeight,motifShift,positionalWeight,Fin.ext_iff] + +theorem product_function_delta {ι κ : Type*} [Fintype ι] [DecidableEq κ] + (a b : ι → κ) : + (∏ i, if a i=b i then (1:ℝ) else 0)=if a=b then 1 else 0 := by + classical + by_cases h : a=b + · subst a; simp + · rw [ite_eq_right h] + obtain ⟨i,hi⟩ := Function.ne_iff.mp h + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +/-- Tensorization of the exact local shift identity, with an arbitrary + array W (in particular any literal retained-subset rank kernel). -/ +theorem motif_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) (τ : ℝ) + (hβ : ∀ h, IsMotifValue (χ h) (β h)) (hτ : IsTypeSign τ) + (W : (Fin r → Fin 3) → ℝ) : + W (fun h => motifShift (χ h) (β h) τ)= + ∑ k : Fin r → GapDifference, + (∏ h, motifDifferenceWeight (χ h) (β h) τ (k h))* + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by + classical + symm + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + calc + _ = ∑ a, (∑ k : Fin r → GapDifference, + ∏ h, motifDifferenceWeight (χ h) (β h) τ (k h)*positionalWeight (k h) (a h))*W a := by + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro k _ + rw [Finset.prod_mul_distrib] + ring + _ = ∑ a, (∏ h, if a h=motifShift (χ h) (β h) τ then (1:ℝ) else 0)*W a := by + apply Finset.sum_congr rfl + intro a _ + rw [← Fintype.prod_sum (fun h k => motifDifferenceWeight (χ h) (β h) τ k * positionalWeight k (a h))] + simp_rw [motif_positional_identity (hβ _) hτ] + _ = _ := by simp_rw [product_function_delta]; simp + +def firstDifferenceCount {r : ℕ} (k : Fin r → GapDifference) : ℕ := + (Finset.univ.filter fun h => k h = .first).card + +def secondDifferenceCount {r : ℕ} (k : Fin r → GapDifference) : ℕ := + (Finset.univ.filter fun h => k h = .second).card + +/-- Every factor of the hypothesis sign comes precisely from a D operator. -/ +theorem motifDifferenceWeight_product {r : ℕ} (χ β : Fin r → ℝ) (τ : ℝ) + (k : Fin r → GapDifference) : + (∏ h, motifDifferenceWeight (χ h) (β h) τ (k h))= + τ^firstDifferenceCount k *∏ h, motifDifferenceWeight (χ h) (β h) 1 (k h) := by + classical + have hw (h) : motifDifferenceWeight (χ h) (β h) τ (k h)= + (if k h=.first then τ else 1)*motifDifferenceWeight (χ h) (β h) 1 (k h) := by + cases k h <;> simp [motifDifferenceWeight] + simp_rw [hw] + rw [Finset.prod_mul_distrib] + congr 1 + rw [← Finset.prod_filter] + simp [firstDifferenceCount] + +/-- The signed difference retains exactly the patterns having an odd + number of centered first differences, with the source's factor two. -/ +theorem motif_signed_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) + (hβ : ∀ h, IsMotifValue (χ h) (β h)) (W : (Fin r → Fin 3) → ℝ) : + W (fun h => motifShift (χ h) (β h) 1)- + W (fun h => motifShift (χ h) (β h) (-1))= + ∑ k : Fin r → GapDifference, + (if Odd (firstDifferenceCount k) then + 2*∏ h, motifDifferenceWeight (χ h) (β h) 1 (k h) else 0)* + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by + rw [motif_shift_expansion χ β 1 hβ (Or.inl rfl) W, + motif_shift_expansion χ β (-1) hβ (Or.inr rfl) W,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + rw [motifDifferenceWeight_product χ β 1 k,motifDifferenceWeight_product χ β (-1) k] + rw [sign_pow_parity (Or.inr rfl : IsTypeSign (-1))] + simp only [one_pow,one_mul] + split_ifs <;> ring + +theorem difference_order_eq_counts {r : ℕ} (k : Fin r → GapDifference) : + (∑ h, (k h).order)=firstDifferenceCount k+2*secondDifferenceCount k := by + classical + have hd (h) : (k h).order=(if k h=.first then 1 else 0)+ + 2*(if k h=.second then 1 else 0) := by cases k h <;> simp [GapDifference.order] + simp_rw [hd] + rw [Finset.sum_add_distrib,← Finset.mul_sum] + simp [firstDifferenceCount,secondDifferenceCount] + +/-- The only signed pattern of order below three is the singleton D term. -/ +theorem odd_pattern_linear_or_order_three {r : ℕ} (k : Fin r → GapDifference) + (hk : Odd (firstDifferenceCount k)) : + (firstDifferenceCount k=1 ∧ secondDifferenceCount k=0) ∨ + 3≤∑ h, (k h).order := by + rw [difference_order_eq_counts] + obtain ⟨n,hn⟩ := hk + omega + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem shiftGapExtra_le {r : ℕ} (a : Fin r → Fin 3) (i : Fin (r+1)) : + shiftGapExtra a i ≤ 2*gapIncidence r i := by + have hl : Fin.cons (α := fun _ => ℕ) 0 (fun h => 2-(a h).val) i ≤ + 2*Fin.cons (α := fun _ => ℕ) 0 (fun _ : Fin r => 1) i := by + induction i using Fin.cases with + | zero => simp + | succ i => simp + have hr : Fin.snoc (α := fun _ => ℕ) (fun h => (a h).val) 0 i ≤ + 2*Fin.snoc (α := fun _ => ℕ) (fun _ : Fin r => 1) 0 i := by + induction i using Fin.lastCases with + | last => simp + | cast i => simpa using Nat.le_of_lt_succ (a i).isLt + dsimp [shiftGapExtra,gapIncidence] + omega + +/-- A unit positional shift changes each actual rank gap by at most two. -/ +theorem tupleGap_shifted_close {n r : ℕ} (p : Fin r → Fin n) + (hp : SafeTaggedTuple p) (a : Fin r → Fin 3) (i : Fin (r+1)) : + |(tupleGap (shiftedTag p hp a) i:ℝ)-(tupleGap p i:ℝ)| ≤ 2 := by + rw [tupleGap_shifted,Nat.cast_add,Nat.cast_sub (gapIncidence_le p hp i)] + have hi : (gapIncidence r i:ℝ) ≤ 2 := by exact_mod_cast gapIncidence_le_two r i + have he : (shiftGapExtra a i:ℝ) ≤ 2*(gapIncidence r i:ℝ) := by exact_mod_cast shiftGapExtra_le a i + have h0 : (0:ℝ) ≤ shiftGapExtra a i := by positivity + apply abs_le.mpr + constructor <;> linarith + +theorem period_shifted_gap_rounding {u m r : ℕ} (hr : 0 < r) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) + (a : Fin r → Fin 3) (i : Fin (r+1)) : + |(tupleGap (shiftedTag (periodSlot off ∘ j.val) hsafe a) i:ℝ)- + (m:ℝ)*coarsePeriodGap j.val i/2| ≤ 6 := by + have ht := abs_sub_le (tupleGap (shiftedTag (periodSlot off ∘ j.val) hsafe a) i:ℝ) + (tupleGap (periodSlot off ∘ j.val) i:ℝ) ((m:ℝ)*coarsePeriodGap j.val i/2) + have h1 := tupleGap_shifted_close (periodSlot off ∘ j.val) hsafe a i + have h2 := period_gap_rounding hr off hoff hdiff j.val j.property i + linarith + +theorem coarse_outside_implies_gap_tail {z g c θ m : ℝ} + (hθ : θ ∈ Set.Icc 0 1) (hm : 128 ≤ m) (hg : |g-m*c/2| ≤ 6) + (hz : m/8 ≤ |z-θ*m*c/2|) : m/16 ≤ |z-g*θ| := by + have he : |g*θ-θ*m*c/2| ≤ 6 := by + have h := mul_le_mul_of_nonneg_right hg hθ.1 + rw [show g*θ-θ*m*c/2=(g-m*c/2)*θ by ring,abs_mul,abs_of_nonneg hθ.1] + exact h.trans (by nlinarith [hθ.2]) + have ht := abs_sub_le z (g*θ) (θ*m*c/2) + linarith + +/-- The manuscript's rank rectangles lose exponentially little mass for + every bounded shift of a tagged tuple. -/ +theorem period_shifted_outside_region {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (j : IncreasingTuple u r) (hsafe : SafeTaggedTuple (periodSlot off ∘ j.val)) + (a : Fin r → Fin 3) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) : + (∑ v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else + subsetRankKernel hl (shiftedTag (periodSlot off ∘ j.val) hsafe a) v.val) ≤ + ((r+1:ℕ):ℝ)*θ^r /binomialMass (u*m) θ l * + (2*Real.exp (-(m:ℝ)/(1024*u))) := by + let p := shiftedTag (periodSlot off ∘ j.val) hsafe a + have hu' : (0:ℝ) < u := by exact_mod_cast hu + have ht : (1/(32*(u:ℝ))) ∈ Set.Icc 0 1 := by + constructor + · positivity + · apply (div_le_one (by positivity)).mpr + have : (1:ℝ) ≤ u := by exact_mod_cast hu + linarith + have hx : -(1/(32*(u:ℝ)))*((m:ℝ)/16)+((u*m:ℕ):ℝ)*(1/(32*(u:ℝ)))^2 = + -(m:ℝ)/(1024*u) := by push_cast; field_simp; ring + calc + _ ≤ ∑ v : IncreasingTuple l r, + if ∃ i, (m:ℝ)/16 ≤ |(tupleGap v.val i:ℝ)-(tupleGap p i:ℝ)*θ| + then subsetRankKernel hl p v.val else 0 := by + apply Finset.sum_le_sum + intro v _ + by_cases hv : PeriodRankRegion m θ j v + · simp only [ite_eq_left hv] + split_ifs + · exact subsetRankKernel_nonneg hl p v.val + · rfl + · simp only [PeriodRankRegion,not_forall,not_lt] at hv + obtain ⟨i,hi⟩ := hv + have he : ∃ i', (m:ℝ)/16 ≤ |(tupleGap v.val i':ℝ)-(tupleGap p i':ℝ)*θ| := + ⟨i.castSucc,coarse_outside_implies_gap_tail ⟨hθ.1.le,hθ.2.le⟩ + (by exact_mod_cast hm) (period_shifted_gap_rounding hr off hoff hdiff j hsafe a i.castSucc) hi⟩ + rw [ite_eq_left he] + split_ifs + · exact subsetRankKernel_nonneg hl p v.val + · rfl + _ ≤ _ := by + have hh := subsetRankKernel_outside_region hl p (shiftedTag_strictMono _ hsafe a) hθ ht (a := (m:ℝ)/16) + simpa only [hx] using hh + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The literal support indicator of the length-2^s signed block. -/ +def motifIndicator (s : ℕ) (z : ℤ) : ℝ := + if 0 ≤ z ∧ z < (2^s : ℕ) then 1 else 0 + +theorem prouhet_motif_value (s : ℕ) (z : ℤ) : + IsMotifValue (motifIndicator s z) ((prouhetSeries s).coeff z) := by + by_cases hz : 0 ≤ z ∧ z < (2^s : ℕ) + · right + refine ⟨by simp only [motifIndicator,ite_eq_left hz], ?_⟩ + have hv := (prouhetSeries_coeff_spec s).2 z hz.1 hz.2 + exact (abs_eq (by norm_num : (0:ℝ) ≤ 1)).mp hv + · left + refine ⟨by simp only [motifIndicator,ite_eq_right hz], ?_⟩ + apply (prouhetSeries_coeff_spec s).1 z + omega + +theorem motif_weight_abs_le (χ β : ℝ) (h : IsMotifValue χ β) (k : GapDifference) : + |motifDifferenceWeight χ β 1 k| ≤ 1 := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> cases k <;> + norm_num [motifDifferenceWeight] + +theorem motif_weight_abs_le_indicator (χ β : ℝ) (h : IsMotifValue χ β) + (k : GapDifference) (hk : k ≠ .unchanged) : + |motifDifferenceWeight χ β 1 k| ≤ χ := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl | rfl⟩ <;> cases k <;> + norm_num [motifDifferenceWeight] at * + +/-- A kernel-pattern multiplier averaged over the actual finitely supported + anchor law. No independence of its involved positions is asserted. -/ +def motifPatternMultiplier {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (k : Fin r → GapDifference) : ℝ := + ∑ X ∈ π.coeff.support, π.coeff X * + ∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) + ((prouhetSeries s).coeff (j h-X)) 1 (k h) + +def linearPattern {r : ℕ} (h : Fin r) (a : Fin r) : GapDifference := + if a=h then .first else .unchanged + +theorem motif_linear_multiplier {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (h : Fin r) : + motifPatternMultiplier π s j (linearPattern h)= + (prouhetSeries s * π).coeff (j h) := by + classical + rw [mul_comm,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] + apply Finset.sum_congr rfl + intro X _ + congr 1 + have hw (a : Fin r) : motifDifferenceWeight (motifIndicator s (j a-X)) + ((prouhetSeries s).coeff (j a-X)) 1 (linearPattern h a)= + if a=h then (prouhetSeries s).coeff (j h-X) else 1 := by + by_cases ha : a=h <;> simp [linearPattern,ha,motifDifferenceWeight] + simp_rw [hw] + simp [sub_eq_neg_add] + +theorem motifPatternMultiplier_abs_le {r : ℕ} (π : IntSeries) + (hπ : ∀ X, 0 ≤ π.coeff X) (s : ℕ) (j : Fin r → ℤ) + (k : Fin r → GapDifference) (h : Fin r) (hk : k h ≠ .unchanged) : + |motifPatternMultiplier π s j k| ≤ + ∑ X ∈ π.coeff.support, π.coeff X*motifIndicator s (j h-X) := by + classical + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro X _ + rw [abs_mul,abs_of_nonneg (hπ X),Finset.abs_prod] + apply mul_le_mul_of_nonneg_left _ (hπ X) + have hi (a) := motif_weight_abs_le _ _ (prouhet_motif_value s (j a-X)) (k a) + have hh := motif_weight_abs_le_indicator _ _ (prouhet_motif_value s (j h-X)) (k h) hk + calc + _ ≤ ∏ a : Fin r, if a=h then motifIndicator s (j h-X) else 1 := by + apply Finset.prod_le_prod₀ + · intro a _; positivity + · intro a _ + by_cases ha : a=h + · subst a; simpa using hh + · simpa [ha] using hi a + _ = _ := by simp + +/-- A nonzero averaged pattern requires every involved tagged position to + lie in one common translate of the motif; correlations are retained. -/ +theorem motif_multiplier_nonzero_support {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (k : Fin r → GapDifference) + (hm : motifPatternMultiplier π s j k ≠ 0) : + ∃ X ∈ π.coeff.support, ∀ h, k h ≠ .unchanged → + 0 ≤ j h-X ∧ j h-X < (2^s : ℕ) := by + classical + obtain ⟨X,hX,hv⟩ := Finset.exists_ne_zero_of_sum_ne_zero hm + refine ⟨X,hX,?_⟩ + intro h hk + by_contra hh + apply hv + apply mul_eq_zero_of_right + apply Finset.prod_eq_zero (Finset.mem_univ h) + have hi : motifIndicator s (j h-X)=0 := by simp only [motifIndicator,ite_eq_right hh] + have hw := motif_weight_abs_le_indicator _ _ (prouhet_motif_value s (j h-X)) (k h) hk + exact abs_nonpos_iff.mp (hw.trans_eq hi) + +theorem motif_multiplier_bounded_separation {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (k : Fin r → GapDifference) + (hm : motifPatternMultiplier π s j k ≠ 0) + (a b : Fin r) (ha : k a ≠ .unchanged) (hb : k b ≠ .unchanged) : + |j a-j b| < (2^s : ℕ) := by + obtain ⟨X,_,hX⟩ := motif_multiplier_nonzero_support π s j k hm + have h1 := hX a ha + have h2 := hX b hb + exact abs_lt.mpr ⟨by omega,by omega⟩ + +/-- Mixing commutes with the exact signed positional expansion. -/ +theorem mixed_signed_shift_expansion {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (W : (Fin r → Fin 3) → ℝ) : + (∑ X ∈ π.coeff.support, π.coeff X * + (W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) 1)- + W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) (-1))))= + ∑ k : Fin r → GapDifference, + (if Odd (firstDifferenceCount k) then 2*motifPatternMultiplier π s j k else 0)* + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by + calc + _ = ∑ X ∈ π.coeff.support, ∑ k : Fin r → GapDifference, + π.coeff X*((if Odd (firstDifferenceCount k) then + 2*∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) + ((prouhetSeries s).coeff (j h-X)) 1 (k h) else 0)* + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a)) := by + apply Finset.sum_congr rfl + intro X _ + rw [motif_signed_shift_expansion _ _ (fun h => prouhet_motif_value s (j h-X)) W, + Finset.mul_sum] + _ = _ := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + by_cases hk : Odd (firstDifferenceCount k) + · simp only [ite_eq_left hk,motifPatternMultiplier] + calc + _ = (∑ X ∈ π.coeff.support, 2*(π.coeff X * + ∏ h, motifDifferenceWeight (motifIndicator s (j h-X)) + ((prouhetSeries s).coeff (j h-X)) 1 (k h))) * + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (k h) (a h))*W a) := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro X _; ring + _ = _ := by rw [← Finset.mul_sum] + · simp only [ite_eq_right hk,zero_mul,mul_zero,Finset.sum_const_zero] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- A general weighted fiber sum, including multipliers which vanish on + inadmissible anchor labels. -/ +theorem weighted_fiber_sum_le {α β : Type*} [Fintype α] [Fintype β] + (f : α → β) (a : α → ℝ) (w : β → ℝ) (P : α → ℝ) (C : ℝ) + (hP : ∀ x, 0 ≤ P x) (ha : ∀ x, a x^2 ≤ w (f x)^2) + (hC : ∀ y, w y ≠ 0 → (∑ x : {x // f x=y}, P x.val) ≤ C) : + (∑ x, a x^2*P x) ≤ C*∑ y, w y^2 := by + classical + calc + _ ≤ ∑ x, w (f x)^2*P x := + Finset.sum_le_sum fun x _ => mul_le_mul_of_nonneg_right (ha x) (hP x) + _ = ∑ y, w y^2*∑ x : {x // f x=y}, P x.val := by + rw [← Fintype.sum_fiberwise f (fun x => w (f x)^2*P x)] + apply Finset.sum_congr rfl + intro y _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + rw [x.property] + _ ≤ ∑ y, w y^2*C := by + apply Finset.sum_le_sum + intro y _ + by_cases hy : w y=0 + · simp [hy] + · exact mul_le_mul_of_nonneg_left (hC y hy) (sq_nonneg _) + _ = _ := by rw [← Finset.sum_mul]; ring + +/-- Explicit central-anchor summation constant for doubled period gaps. -/ +def periodCentralSumConstant (u r : ℕ) : ℝ := + ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(2*Real.sqrt (2*u:ℕ))^(r-1) + +theorem weighted_period_gap_sum {u r : ℕ} (a : Fin r) + (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) + (hA : ∀ j, A j^2 ≤ w (j.val a)^2) + (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) : + (∑ j : IncreasingTuple u r, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) ≤ + periodCentralSumConstant u r *∑ h, w h^2 := by + apply weighted_fiber_sum_le (fun j : IncreasingTuple u r => j.val a) A w + (fun j => ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) + (periodCentralSumConstant u r) (fun _ => by positivity) hA + intro h hh + calc + _ = ∑ j : FixedPeriodTuple u r a h, + ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ := + by + congr 1 + exact congrArg (fun i : Fintype (FixedPeriodTuple u r a h) => @Finset.univ _ i) + (Subsingleton.elim _ _) + _ ≤ _ := fixedPeriodProfile_central_sum a h (hw h hh).1 (hw h hh).2 + +/-- The two largest gaps exist even after arbitrary restrictions on the + tuple, provided its anchor label is central. -/ +theorem fixedPeriodProfile_large_sides {u r : ℕ} (a : Fin r) (h : Fin u) + (hleft : (u:ℝ)/3 ≤ 2*h.val+1) + (hright : (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) (j : FixedPeriodTuple u r a h) : + (∃ e ∈ Finset.Iic a.castSucc, (u:ℝ)/(3*(r+1:ℝ)) ≤ (fixedPeriodProfile a h j e).val) ∧ + (∃ d ∉ Finset.Iic a.castSucc, (u:ℝ)/(3*(r+1:ℝ)) ≤ (fixedPeriodProfile a h j d).val) := by + classical + let A := Finset.Iic a.castSucc + let p := fixedPeriodProfile a h + have hL : ∃ e∈A, (u:ℝ)/(3*(r+1:ℝ)) ≤ (p j e).val := by + apply exists_large_in_subset A ⟨0, by simp [A]⟩ (fun i => (p j i).val) + (fun _ => Nat.cast_nonneg _) + have hs := fixedPeriodProfile_prefix a h j + have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs + rw [hs'] + simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] + convert hleft using 1; field_simp + have hD : ∃ d∉A, (u:ℝ)/(3*(r+1:ℝ)) ≤ (p j d).val := by + have ha : a.val ((p j i).val:ℝ)) (fun _ => Nat.cast_nonneg _) (R := (u:ℝ)/(3*(r+1:ℝ))) (by + have hs := fixedPeriodProfile_prefix a h j + have ht := fixedPeriodProfile_total a h j + have hs' : (∑ i∈A, ((p j i).val:ℝ))=2*h.val+1 := by exact_mod_cast hs + have ht' : (∑ i, ((p j i).val:ℝ))=2*u := by exact_mod_cast ht + have hc := Finset.sum_compl_add_sum A (fun i => ((p j i).val:ℝ)) + have hsum : (∑ i∈Aᶜ, ((p j i).val:ℝ))=2*u-(2*h.val+1) := by linarith + rw [hsum] + simp only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] + convert hright using 1; field_simp) + exact ⟨d,Finset.mem_compl.mp hd,hdR⟩ + exact ⟨hL,hD⟩ + +/-- Source's bounded gap refinement at a prescribed central label. -/ +theorem fixedPeriodProfile_bounded_central_sum {u r M : ℕ} (a : Fin r) (h : Fin u) + (c : Fin (r+1)) (hleft : (u:ℝ)/3 ≤ 2*h.val+1) + (hright : (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑ j : FixedPeriodTuple u r a h, + if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0) ≤ + ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(M+1)*(2*Real.sqrt (2*u:ℕ))^(r-2) := by + classical + let α := {j : FixedPeriodTuple u r a h // coarsePeriodGap j.val.val c ≤ M} + let p (j : α) := fixedPeriodProfile a h j.val + have hu : (0:ℝ) < u := by exact_mod_cast (Nat.zero_lt_of_lt h.isLt) + have hR : 0 < (u:ℝ)/(3*(r+1:ℝ)) := by positivity + have hs := two_sided_bounded_gaps_sum (Finset.Iic a.castSucc) c p + ((fixedPeriodProfile_injective a h).comp Subtype.val_injective) + (fun j => fixedPeriodProfile_prefix a h j.val) + (fun j => fixedPeriodProfile_total a h j.val) hR hM + (fun j => (fixedPeriodProfile_large_sides a h hleft hright j.val).1) + (fun j => (fixedPeriodProfile_large_sides a h hleft hright j.val).2) + (fun j => j.property) + have he : (∑ j : FixedPeriodTuple u r a h, + if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0)= + ∑ j : α, ∏ i, (Real.sqrt (coarsePeriodGap j.val.val.val i))⁻¹ := by + rw [← Finset.sum_filter] + exact Finset.sum_subtype _ (by intro j; simp) _ + rw [he] + simpa only [α,p,fixedPeriodProfile,Fin.val_mk,Fintype.card_fin, + show r+1-3=r-2 by omega] using hs + +def periodBoundedSumConstant (u r M : ℕ) : ℝ := + ((r+1:ℕ):ℝ)^2*((u:ℝ)/(3*(r+1:ℝ)))⁻¹*(M+1)*(2*Real.sqrt (2*u:ℕ))^(r-2) + +theorem weighted_period_bounded_gap_sum {u r M : ℕ} (a : Fin r) (c : Fin (r+1)) + (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) + (hA : ∀ j, A j^2 ≤ w (j.val a)^2) + (hsupport : ∀ j, A j ≠ 0 → coarsePeriodGap j.val c ≤ M) + (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) + (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑ j : IncreasingTuple u r, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) ≤ + periodBoundedSumConstant u r M *∑ h, w h^2 := by + have hp (j : IncreasingTuple u r) : + A j^2*(∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹)= + A j^2*(if coarsePeriodGap j.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ else 0) := by + by_cases hj : A j=0 + · simp [hj] + · rw [ite_eq_left (hsupport j hj)] + simp_rw [hp] + apply weighted_fiber_sum_le (fun j : IncreasingTuple u r => j.val a) A w + (fun j => if coarsePeriodGap j.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ else 0) + (periodBoundedSumConstant u r M) (fun _ => by split_ifs <;> positivity) hA + intro h hh + calc + _ = ∑ j : FixedPeriodTuple u r a h, + if coarsePeriodGap j.val.val c ≤ M then ∏ i, (Real.sqrt (coarsePeriodGap j.val.val i))⁻¹ else 0 := + by + congr 1 + exact congrArg (fun i : Fintype (FixedPeriodTuple u r a h) => @Finset.univ _ i) + (Subsingleton.elim _ _) + _ ≤ _ := fixedPeriodProfile_bounded_central_sum a h c (hw h hh).1 (hw h hh).2 hM + +end TraceReconstruction + + +namespace TraceReconstruction + +/-- A displaced child window as an actual interval of the deterministic + parent template. `t` is the realized count of atoms before the window. -/ +def childWindowIndex {P T : ℕ} (t : ℕ) (hfit : t+T ≤ P) (h : Fin T) : Fin P := + ⟨t+h.val, by omega⟩ + +theorem templateType_inside_window {P T a L t : ℕ} + (sign : Fin L → Bool) (τ : Bool) (hfit : t+T ≤ P) + (hleft : t ≤ a) (h : Fin T) : + templateType P a L sign τ (childWindowIndex t hfit h)= + templateType T (a-t) L sign τ h := by + have he : (a ≤ (childWindowIndex t hfit h).val ∧ + (childWindowIndex t hfit h).val < a+L) ↔ + a-t ≤ h.val ∧ h.val < a-t+L := by dsimp [childWindowIndex]; omega + unfold templateType + split_ifs with h1 h2 h2 + · congr 2 + apply Fin.ext + dsimp [childWindowIndex] + omega + · exact False.elim (h2 (he.mp h1)) + · exact False.elim (h1 (he.mpr h2)) + · rfl + +/-- When the motif fits its assigned window, every atom outside that + window has the default pure type, including pieces crossing nominal cuts. -/ +theorem templateType_outside_window {P T a L t : ℕ} + (sign : Fin L → Bool) (τ : Bool) (hleft : t ≤ a) (hright : a+L ≤ t+T) + (i : Fin P) (hi : i.val < t ∨ t+T ≤ i.val) : + templateType P a L sign τ i=false := by + have he : ¬(a ≤ i.val ∧ i.val < a+L) := by omega + simp [templateType,he] + +/-- A literal centered window remains within its own nominal parent unit, + and contains the motif, whenever its jitter has the source fit bound. + This elementary statement is independent of the distribution of the jitter. -/ +theorem centered_window_fit (P T L a A t : ℕ) (Y : ℤ) + (hP : 2*T ≤ P) (hA : 2*A=P-T) (ha : 2*a=P) + (hL : 8*L ≤ T) (hY : |8*Y| ≤ (T:ℤ)) (ht : (t:ℤ)=A+Y) : + t+T ≤ P ∧ t ≤ a ∧ a+L ≤ t+T := by + have hy := abs_le.mp hY + omega + +/-- Flattened deterministic parent type, before any random partition. -/ +def parentGroupType {R P L : ℕ} (a : ℕ) (sign : Fin L → Bool) + (τ : Fin R → Bool) (u : Fin R) (h : Fin P) : Bool := + templateType P a L sign (τ u) h + +theorem parentGroup_window_types {R P T L : ℕ} (a : ℕ) (sign : Fin L → Bool) + (τ : Fin R → Bool) (t : Fin R → ℕ) + (hfit : ∀ u, t u+T ≤ P) (hleft : ∀ u, t u ≤ a) + (u : Fin R) (h : Fin T) : + parentGroupType a sign τ u (childWindowIndex (t u) (hfit u) h)= + templateType T (a-t u) L sign (τ u) h := + templateType_inside_window sign (τ u) (hfit u) (hleft u) h + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Energy.lean b/lean/OAI/Probability/TraceReconstruction/Energy.lean index b15f1d9c4c63077d2402b8d19c3ef59a860ae50c..d9e5fdc1443974446846b430df0ec47cd311e7f0 100644 --- a/lean/OAI/Probability/TraceReconstruction/Energy.lean +++ b/lean/OAI/Probability/TraceReconstruction/Energy.lean @@ -1,881 +1,881 @@ -import OAI.Probability.TraceReconstruction.Shapes - -namespace OAI - -/-! -# Energy - -Shaped envelopes, actual coefficient aggregation, role counts, central contributions, and full coefficient energy. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw -namespace OccupiedParityTree - -/-- Actual unsigned coefficient envelope on one ordered occupied shape. -No bits are resampled for the additional leaves. -/ -def Forced.envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (x : t.Labels T) - (bits : WindowAssignments T n g Bool b) (incoming : ℤ) : ℝ := - binaryAnchorKernel T n g s center globalShift b (F.labels T x) bits incoming * - ∏e : F.ExtraLeafEdge, motifIndicator s ((x e.val.val).val- - sourceTreeAnchors T n g center globalShift b bits incoming (e.val.val.parentPath T x)) - -def Forced.averagedEnvelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (x : t.Labels T) - (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : ℝ := - (windowPosteriorLaw T n g b d).expect - (fun bits => F.envelope T n g s center globalShift x bits incoming) - -/-- Offsets for all extra leaf constraints, with only their labels replaced -by zero. The location of each constraint is not changed by that replacement. -/ -def Forced.extraOffsets (T n g : ℕ → ℕ) (hT : 0 ⟨0,hT⟩),z))) - -theorem Forced.averagedEnvelope_split (T n g : ℕ → ℕ) (hT : 0 binaryAnchorKernel T n g s center globalShift b p bits incoming) - (fun bits e => F.extraOffsets T n g hT center globalShift p z bits incoming e) h := by - let x := (F.fullLabelsEquiv T).symm (p,h,z) - have hx : F.fullLabelsEquiv T x=(p,h,z) := Equiv.apply_symm_apply _ _ - have hp : F.labels T x=p := by rw [←F.fullLabelsEquiv_fst,hx] - apply congrArg (FiniteLaw.expect (windowPosteriorLaw T n g b d)) - funext bits - change F.envelope T n g s center globalShift x bits incoming = _ - unfold Forced.envelope - rw [hp] - congr 1 - apply Finset.prod_congr rfl - intro e he - have hv := congrArg (fun a => (a.2.1 e).val) hx - simp only [Forced.fullLabelsEquiv_leaf_value] at hv - rw [hv] - unfold Forced.extraOffsets - congr 2 - exact congrArg (sourceTreeAnchors T n g center globalShift b bits incoming) - (F.parentPath_extraLeaf_invariant T p h (fun _ => ⟨0,hT⟩) z e.val.val) - -/-- Summing every actual numeric labeling of a fixed shape costs exactly -one l1-squared factor per extra leaf and one factor per extra interior label. -The forced-anchor energy remains a single genuine correlated posterior. -/ -theorem Forced.envelope_energy (T n g : ℕ → ℕ) (hT : 0 - if R (F.labels T x) then (F.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0) - rw [←hs] - simp only [Fintype.sum_prod_type] - calc - _ ≤ ∑p : BinaryWindowLabels T b, ∑z : F.InteriorLabels T, - if R p then L*(binaryAnchorAverage T n g s center globalShift b p d incoming)^2 else 0 := by - apply Finset.sum_le_sum - intro p hp - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro z hz - have he (h : F.ExtraLeafEdge → Fin (T 0)) : - F.labels T ((F.fullLabelsEquiv T).symm (p,h,z))=p := by - rw [←F.fullLabelsEquiv_fst,Equiv.apply_symm_apply] - simp_rw [he] - by_cases hR : R p - · simp only [ite_eq_left hR] - simp_rw [F.averagedEnvelope_split T n g hT s center globalShift] - exact indexedExtraAverage_energy (windowPosteriorLaw T n g b d) s (T 0) - (fun bits => binaryAnchorKernel T n g s center globalShift b p bits incoming) - (fun bits => binaryAnchorKernel_nonneg T n g s center globalShift b p bits incoming) - (fun bits e => F.extraOffsets T n g hT center globalShift p z bits incoming e) - · simp only [ite_eq_right hR,Finset.sum_const_zero,le_refl] - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro p hp - by_cases hr : R p <;> simp [hr,L,mul_assoc] -/-- Connected forced-shape coefficient-envelope estimate with the true -common-global/local sibling energy, and no independent-sibling substitute. -/ -theorem Forced.envelope_energy_root (T n g : ℕ → ℕ) (hT : 0 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) := by - apply (F.envelope_energy T n g hT s center globalShift - (BinaryWindowLabels.allowed T A s (b+1)) d incoming).trans - exact mul_le_mul_of_nonneg_left - (binaryAnchorAverage_energy T n g s center globalShift A shift hplat B C hB hC b d hcap incoming) - (by positivity) - -end OccupiedParityTree -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -/-- The actual full-tree leaf address of a bottom edge, including the edge's -own numeric label. -/ -def Edge.bottomAddress (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → - (x : t.Labels T) → (e : t.Edge) → e.height=0 → WindowLeaf T b - | _, .leaf, _, e, _ => e.elim - | b+1, .node k children roles, x, Sum.inl i, he => by - change b=0 at he - subst b - exact (x (Sum.inl i),(⟨0,by decide⟩ : Fin 1)) - | b+1, .node k children roles, x, Sum.inr z, he => - (x (Sum.inl z.1), Edge.bottomAddress T (x.child T z.1) z.2 he) - -theorem Edge.bottomAddress_mem (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (x : t.Labels T) (e : t.Edge) (he : e.height=0) : - e.bottomAddress T x he ∈ t.labelledLeaves T x := by - induction t with - | leaf => exact e.elim - | @node b k children roles ih => - cases e with - | inl i => - change b=0 at he - subst b - apply Finset.mem_biUnion.mpr - refine ⟨i,Finset.mem_univ i,?_⟩ - apply Finset.mem_image.mpr - refine ⟨(⟨0,by decide⟩ : Fin 1),?_,rfl⟩ - have hz (u : OccupiedParityTree 0) (y : u.Labels T) : - u.labelledLeaves T y = {(⟨0,by decide⟩ : Fin 1)} := by cases u; rfl - rw [hz] - exact Finset.mem_singleton_self _ - | inr z => - apply Finset.mem_biUnion.mpr - refine ⟨z.1,Finset.mem_univ _,?_⟩ - exact Finset.mem_image.mpr ⟨z.2.bottomAddress T (x.child T z.1) he, ih z.1 _ _ he,rfl⟩ - -/-- Leaf constraints read from the real shape label address are exactly the -ones in the genuine complete-tree latent law. -/ -theorem Edge.bottomIndicator_eq (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (t : OccupiedParityTree (b+1)) (x : t.Labels T) - (e : t.Edge) (he : e.height=0) - (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) : - sourceBottomIndicator T n g s center globalShift b bits incoming (e.bottomAddress T x he) = - motifIndicator s ((x e).val-sourceTreeAnchors T n g center globalShift (b+1) bits incoming - (e.parentPath T x)) := by - induction b generalizing incoming with - | zero => - cases t with - | node k children roles => - cases e with - | inl i => - change motifIndicator s _ = motifIndicator s _ - congr 1 - change ((x (Sum.inl i)).val:ℤ)-center 0+(∑i,(bitIndex (bits.1 i):ℤ))+incoming = - ((x (Sum.inl i)).val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) - omega - | inr z => have hh := z.2.height_lt; omega - | succ b ih => - cases t with - | node k children roles => - cases e with - | inl i => change b+1=0 at he; omega - | inr z => - change sourceBottomIndicator T n g s center globalShift b - (bits.2.2 (x (Sum.inl z.1))) (globalShift (b+1) bits.2.1 (x (Sum.inl z.1))) - (z.2.bottomAddress T (x.child T z.1) he) = motifIndicator s ((x.child T z.1 z.2).val- - sourceTreeAnchors T n g center globalShift (b+1+1) bits incoming - ((x (Sum.inl z.1)).val::z.2.parentPath T (x.child T z.1))) - rw [sourceTreeAnchors_child T n g center globalShift (b+1) bits incoming - (x (Sum.inl z.1)) (z.2.parentPath T (x.child T z.1))] - exact ih _ _ _ he _ _ - -end OccupiedParityTree -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Taking repeated constraints from a zero-one product can only enlarge it. -The map need not be injective. This keeps the real leaf addresses, including -coincident labels in the ambient enlarged summation. -/ -theorem product_zero_one_pull_le {α β : Type*} [Fintype β] - (S : Finset α) (f : α → ℝ) (hf : ∀a∈S,f a=0 ∨ f a=1) - (g : β → α) (hg : ∀b,g b∈S) : (∏a∈S,f a)≤∏b,f (g b) := by - rcases prod_zero_one S f hf with hz | ho - · rw [hz] - exact Finset.prod_nonneg (fun b _ => by rcases hf (g b) (hg b) with h|h <;> simp [h]) - · have h (b : β) : f (g b)=1 := by - rcases hf (g b) (hg b) with h|h - · have hz := Finset.prod_eq_zero (hg b) h - rw [ho] at hz - norm_num at hz - · exact h - rw [ho] - simp only [h,Finset.prod_const_one,le_refl] - -/-- Every actual role coefficient is bounded by its actual forced shape -and extra-leaf envelope before averaging over the single whole latent law. -/ -theorem sourceRoleTerm_envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ - F.envelope T n g s center globalShift (occupiedTermLabels T b S a) bits incoming := by - let x := occupiedTermLabels T b S a - let f := sourceBottomIndicator T n g s center globalShift b bits incoming - let addr : F.ExtraLeafEdge → WindowLeaf T (b+1) := - fun e => e.val.val.bottomAddress T x e.property - have hm (e : F.ExtraLeafEdge) : addr e∈S := by - rw [←occupiedTermLabels_leaves T b S a] - exact e.val.val.bottomAddress_mem T x e.property - have he (e : F.ExtraLeafEdge) : f (addr e)=motifIndicator s ((x e.val.val).val- - sourceTreeAnchors T n g center globalShift (b+1) bits incoming (e.val.val.parentPath T x)) := - e.val.val.bottomIndicator_eq T n g s center globalShift b _ x e.property bits incoming - have hle := product_zero_one_pull_le S f (fun v hv => - sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v) addr hm - simp_rw [he] at hle - apply le_mul_of_zero_one - (binaryAnchorKernel_zero_one T n g s center globalShift _ _ bits incoming) - (prod_zero_one Finset.univ _ (fun e _ => by unfold motifIndicator; split_ifs <;> simp)) - · simpa only [occupiedTermLabels_forced] using - sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F - · exact (sourceRoleTerm_all_leaf_constraints T n g s center globalShift b bits incoming S a).trans hle - -/-- The averaged coefficient uses one exact metadata fiber. No fit event, -plateau event or leaf-emission observation is conditioned on here. -/ -theorem sourceRoleAverage_envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ - F.averagedEnvelope T n g s center globalShift (occupiedTermLabels T b S a) d incoming := by - apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans - exact FiniteLaw.expect_mono _ (fun bits => - sourceRoleTerm_envelope T n g s center globalShift b bits incoming S a F) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw -open OccupiedParityTree - -theorem occupiedWindowTerm_leafCount (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : - (occupiedWindowTerm T b S a).leafCount=S.card := by - rw [←occupiedWindowTerm_eq T 0 (fun _ => 0) b [] S a] - exact occupiedWindowShape_leafCount T 0 (fun _ => 0) b [] S _ - -theorem occupiedWindowTerm_occupied (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) (hS : S.Nonempty) : - (occupiedWindowTerm T b S a).occupied := by - rw [←occupiedWindowTerm_eq T 0 (fun _ => 0) b [] S a] - exact occupiedWindowShape_occupied T 0 (fun _ => 0) b [] S hS _ - -/-- Only the unlabeled ordered role shape is selected here; no child label -or hidden orientation enters the forced choice. -/ -abbrev DegreeForcedShape (b r : ℕ) := - {t : OccupiedParityTree b // t.occupied ∧ t.leafCount=r ∧ Nonempty t.Forced} - -instance degreeForcedShapeFinite (b r : ℕ) : Finite (DegreeForcedShape b r) := by - let := finite_bounded_occupied_shapes b r - exact Finite.of_injective - (fun t : DegreeForcedShape b r => - (⟨t.val,t.property.1,t.property.2.1.le⟩ : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r})) - (fun _ _ h => Subtype.ext (congrArg - (fun q : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} => q.val) h)) - -noncomputable instance degreeForcedShapeFintype (b r : ℕ) : Fintype (DegreeForcedShape b r) := - Fintype.ofFinite _ - -def DegreeForcedShape.forced {b r : ℕ} (t : DegreeForcedShape b r) : t.val.Forced := - Classical.choice t.property.2.2 - -theorem card_degreeForcedShape_le (b r : ℕ) : - Fintype.card (DegreeForcedShape b r) ≤ shapeRoleConstant r b := by - let f : DegreeForcedShape b r → FiniteRoleShape r b := fun t => - Classical.choose (exists_finiteRoleShape t.val r t.property.1 t.property.2.1.le) - apply Fintype.card_le_of_injective f - intro t u he - apply Subtype.ext - have ht := Classical.choose_spec (exists_finiteRoleShape t.val r t.property.1 t.property.2.1.le) - have hu := Classical.choose_spec (exists_finiteRoleShape u.val r u.property.1 u.property.2.1.le) - exact ht.symm.trans ((congrArg (FiniteRoleShape.toTree r b) he).trans hu) - -abbrev SourceRoleIndex (T : ℕ → ℕ) (b : ℕ) := - (S : Finset (WindowLeaf T (b+1))) × OccupiedWindowChoice T b S - -abbrev DegreeForcedRole (T : ℕ → ℕ) (b r : ℕ) := - {w : SourceRoleIndex T b // w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced} - -def DegreeForcedRole.shape (T : ℕ → ℕ) (b r : ℕ) (w : DegreeForcedRole T b r) : - DegreeForcedShape (b+1) r := by - refine ⟨occupiedWindowTerm T b w.val.1 w.val.2,?_,?_,w.property.2⟩ - · apply occupiedWindowTerm_occupied - apply Finset.card_pos.mp - obtain ⟨F⟩ := w.property.2 - have hh := F.leaf_lower - rw [occupiedWindowTerm_leafCount] at hh - exact (Nat.pow_pos (by decide : (0:ℕ)<2)).trans_le hh - · exact (occupiedWindowTerm_leafCount T b w.val.1 w.val.2).trans w.property.1 - -def DegreeForcedRole.encoding (T : ℕ → ℕ) (b r : ℕ) (w : DegreeForcedRole T b r) : - (t : DegreeForcedShape (b+1) r) × t.val.Labels T := - ⟨w.shape T b r,occupiedTermLabels T b w.val.1 w.val.2⟩ - -theorem DegreeForcedRole.encoding_injective (T : ℕ → ℕ) (b r : ℕ) : - Function.Injective (DegreeForcedRole.encoding T b r) := by - intro w v he - apply Subtype.ext - apply occupiedTermEncoding_injective T b - exact congrArg (fun z : (t : DegreeForcedShape (b+1) r) × t.val.Labels T => - (⟨z.1.val,z.2⟩ : (t : OccupiedParityTree (b+1)) × t.Labels T)) he - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw -open OccupiedParityTree - -/-- A degree-r sum over the genuine pairs (selected leaves, roles), -restricted only by deterministic allowed forced labels. -/ -def degreeForcedRoleEnergy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : ℝ := - ∑w : DegreeForcedRole T b r, - if BinaryWindowLabels.allowed T A s (b+1) - ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) then - (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)^2 else 0 - -/-- The actual coefficient indices inject into shape+numeric-labels. Thus -summing the enlarged envelope really bounds the original coefficient sum, -with no identification of different selected monomials. -/ -theorem degreeForcedRoleEnergy_le_envelopes (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : - degreeForcedRoleEnergy T n g s center globalShift A b r d incoming ≤ - ∑t : DegreeForcedShape (b+1) r, ∑x : t.val.Labels T, - if BinaryWindowLabels.allowed T A s (b+1) (t.forced.labels T x) then - (t.forced.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0 := by - let f := fun z : (t : DegreeForcedShape (b+1) r) × t.val.Labels T => - if BinaryWindowLabels.allowed T A s (b+1) (z.1.forced.labels T z.2) then - (z.1.forced.averagedEnvelope T n g s center globalShift z.2 d incoming)^2 else 0 - have hf : ∀z,0≤f z := by intro z; dsimp [f]; split_ifs <;> positivity - calc - _ ≤ ∑w : DegreeForcedRole T b r,f (w.encoding T b r) := by - apply Finset.sum_le_sum - intro w hw - dsimp only [f,DegreeForcedRole.encoding] - by_cases h : BinaryWindowLabels.allowed T A s (b+1) - ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) - · simp only [ite_eq_left h] - have hh := sourceRoleAverage_envelope T n g s center globalShift b d incoming - w.val.1 w.val.2 (w.shape T b r).forced - rw [←sq_abs (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)] - exact (sq_le_sq₀ (abs_nonneg _) ((abs_nonneg _).trans hh)).mpr hh - · simp only [ite_eq_right h,le_refl] - _ ≤ ∑z,f z := by - simpa only [ite_true] using sum_injective_profile_le - (DegreeForcedRole.encoding T b r) (DegreeForcedRole.encoding_injective T b r) - (fun _ => True) (fun _ => trivial) f hf - _ = _ := Fintype.sum_sigma _ - -/-- Uniform arithmetic interior-label budget of a degree-r depth-(b+1) -shape. This includes no factor for a bottom label. -/ -def interiorLabelBudget (T : ℕ → ℕ) (b r : ℕ) : ℝ := - ((∏j : Fin (b+1),if j.val=0 then 1 else T j.val : ℕ):ℝ)^(r-2^(b+1)) - -theorem degreeForcedRoleEnergy_bound (T n g : ℕ → ℕ) (hT : ∀j,0 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) := by - let K := interiorLabelBudget T b r * ((2^s:ℕ):ℝ)^(2*(r-2^(b+1))) * - ((2*((2^s:ℕ):ℝ)^3*B b) * binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) - have hbud : 0≤binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by - exact binaryTreeBudget_nonneg _ (fun j => - mul_nonneg (mul_nonneg (by positivity) (hC (j+1))) (hB j)) b - have hb := hB b - have hK : 0≤K := by dsimp [K,interiorLabelBudget]; positivity - calc - _ ≤ ∑t : DegreeForcedShape (b+1) r, ∑x : t.val.Labels T, - if BinaryWindowLabels.allowed T A s (b+1) (t.forced.labels T x) then - (t.forced.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0 := - degreeForcedRoleEnergy_le_envelopes T n g s center globalShift A b r d incoming - _ ≤ ∑_t : DegreeForcedShape (b+1) r,K := by - apply Finset.sum_le_sum - intro t ht - apply (t.forced.envelope_energy_root T n g (hT 0) s center globalShift A shift hplat - B C hB hC b t.val d hcap incoming).trans - have hi := t.forced.card_interiorLabels_le T hT t.property.1 - rw [t.property.2.1] at hi - have hi' : (Fintype.card (t.forced.InteriorLabels T):ℝ) ≤ interiorLabelBudget T b r := by - dsimp [interiorLabelBudget] - exact_mod_cast hi - rw [t.forced.card_extraLeafEdge,t.property.2.1] - exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hi' (by positivity)) (by positivity) - _ = (Fintype.card (DegreeForcedShape (b+1) r):ℝ)*K := by - rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ ≤ (shapeRoleConstant r (b+1):ℝ)*K := by - apply mul_le_mul_of_nonneg_right _ hK - exact_mod_cast card_degreeForcedShape_le (b+1) r - _ = _ := by dsimp [K]; ring - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Total role multiplicity for one actual selected monomial. Every level -has at most the number of selected leaves; no ambient-label factor occurs. -/ -theorem occupiedWindowChoice_card_le (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) : - Fintype.card (OccupiedWindowChoice T b S) ≤ 3^((b+1)*S.card) := by - induction b with - | zero => - change Fintype.card (Fin S.card → Fin 3) ≤ _ - simp - | succ b ih => - change Fintype.card (((i : Fin (selectedChildren S).card) → - OccupiedWindowChoice T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) × - (Fin (selectedChildren S).card → Fin 3)) ≤ _ - rw [Fintype.card_prod,Fintype.card_pi,Fintype.card_fun,Fintype.card_fin,Fintype.card_fin] - have hprod := Finset.prod_le_prod (s:=Finset.univ) (fun i _ => - ih (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) - have hs : (∑i : Fin (selectedChildren S).card, - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val).card)=S.card := - (selected_sum_index (selectedChildren S) (fun h => (selectedChildLeaves S h).card)).trans - (selected_children_card S) - have hc : (selectedChildren S).card≤S.card := Finset.card_image_le - calc - _ ≤ (∏i : Fin (selectedChildren S).card, - 3^((b+1)*(selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val).card)) * - 3^(selectedChildren S).card := Nat.mul_le_mul_right _ hprod - _ = 3^((b+1)*S.card+(selectedChildren S).card) := by - rw [Finset.prod_pow_eq_pow_sum,←Finset.mul_sum,hs,←pow_add] - _ ≤ _ := Nat.pow_le_pow_right (by decide) (by simp only [Nat.add_mul,Nat.one_mul]; omega) - -abbrev DegreeLeafSubset (T : ℕ → ℕ) (b r : ℕ) := - {S : Finset (WindowLeaf T (b+1)) // S.card=r} - -theorem degreeLeafSubset_card (T : ℕ → ℕ) (b r : ℕ) : - Fintype.card (DegreeLeafSubset T b r)=(Fintype.card (WindowLeaf T (b+1))).choose r := by - have h := Finset.card_powersetCard r (Finset.univ : Finset (WindowLeaf T (b+1))) - have he : (Finset.univ.powersetCard r : Finset (Finset (WindowLeaf T (b+1))))=(Finset.univ.filter (fun S : Finset (WindowLeaf T (b+1)) => S.card=r)) := by - ext S - simp only [Finset.mem_powersetCard,Finset.subset_univ,true_and,Finset.mem_filter,Finset.mem_univ] - rw [he,Finset.card_univ] at h - rw [Fintype.card_subtype] - exact h - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- All actual motif support lies in the chosen central interval at every -vertex of the full window tree. This is a predicate of the complete bits, -not an event on which any posterior law is conditioned. -/ -def SourceCentral (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) : - (b : ℕ) → WindowAssignments T n g Bool b → ℤ → Prop - | 0, _, _ => True - | b+1, bits, incoming => - (∀h : Fin (T b), motifIndicator s ((h.val:ℤ)-center b+ - (∑i,(bitIndex (bits.1 i):ℤ))+incoming)≠0 → h∈A b) ∧ - ∀h, SourceCentral T n g s center globalShift A b (bits.2.2 h) (globalShift b bits.2.1 h) - -def BinaryWindowLabels.central (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) : - (b : ℕ) → BinaryWindowLabels T b → Prop - | 0, _ => True - | b+1, p => p.1∈A b ∧ p.2.1∈A b ∧ central T A b p.2.2.1 ∧ central T A b p.2.2.2 - -theorem BinaryWindowLabels.allowed_of_central (T : ℕ → ℕ) - (A : (b : ℕ) → Finset (Fin (T b))) (s b : ℕ) (p : BinaryWindowLabels T b) - (hc : central T A b p) (hd : distinct T b p) (hs : close T s b p) : - allowed T A s b p := by - induction b with - | zero => trivial - | succ b ih => - exact ⟨⟨hc.1,hc.2.1,hd.1,by simpa only [abs_sub_comm] using hs.1⟩, - ih _ hc.2.2.1 hd.2.1 hs.2.1,ih _ hc.2.2.2 hd.2.2 hs.2.2⟩ - -theorem sourceRoleTerm_forced_central (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) - (hc : SourceCentral T n g s center globalShift A (b+1) bits incoming) - (hz : sourceRoleTerm T n g s center globalShift b bits incoming S a≠0) : - BinaryWindowLabels.central T A (b+1) (forcedWindowLabels T b S a F) := by - induction b generalizing incoming with - | zero => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_zero] at hz - change (S.equivFin.symm i).val.1 ∈ A 0 ∧ (S.equivFin.symm j).val.1 ∈ A 0 ∧ True ∧ True - refine ⟨hc.1 _ ?_,hc.1 _ ?_,trivial,trivial⟩ - · convert nonzero_of_abs_le hz (occupiedRootWeight_bottom_anchor T s S a (center 0-(∑k,(bitIndex (bits.1 k):ℤ))-incoming) i) using 1 - congr 1; ring - · convert nonzero_of_abs_le hz (occupiedRootWeight_bottom_anchor T s S a (center 0-(∑k,(bitIndex (bits.1 k):ℤ))-incoming) j) using 1 - congr 1; ring - | succ b ih => - cases F with - | node i j hne hi hj left right => - rw [sourceRoleTerm_succ] at hz - have hm := mul_ne_zero_iff.mp hz - have hp := Finset.prod_ne_zero_iff.mp hm.2 - change ((selectedChildren S).equivFin.symm i).val ∈ A (b+1) ∧ - ((selectedChildren S).equivFin.symm j).val ∈ A (b+1) ∧ - BinaryWindowLabels.central T A (b+1) - (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) - (a.1 i) left) ∧ - BinaryWindowLabels.central T A (b+1) - (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) - (a.1 j) right) - refine ⟨hc.1 _ ?_,hc.1 _ ?_, - ih _ _ _ _ left (hc.2 _) (hp i (Finset.mem_univ i)), - ih _ _ _ _ right (hc.2 _) (hp j (Finset.mem_univ j))⟩ - · convert nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ i hi) using 1 - congr 1; ring - · convert nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ j hj) using 1 - congr 1; ring - -/-- The discarded noncentral role contributions are bounded by the actual -conditional probability of a failed full-tree layout. Typical metadata may -bound this mass; the averaging distribution itself remains unconditional. -/ -def sourceNoncentralMass (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : ℝ := - (windowPosteriorLaw T n g b d).expect - (fun bits => if SourceCentral T n g s center globalShift A b bits incoming then 0 else 1) - -theorem sourceNoncentralMass_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : - 0 ≤ sourceNoncentralMass T n g s center globalShift A b d incoming := by - exact Finset.sum_nonneg (fun bits _ => mul_nonneg - ((windowPosteriorLaw T n g b d).nonneg bits) (by dsimp only; split_ifs <;> norm_num)) - -theorem sourceRoleAverage_not_allowed (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) - (h : ¬BinaryWindowLabels.allowed T A s (b+1) (forcedWindowLabels T b S a F)) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ - sourceNoncentralMass T n g s center globalShift A (b+1) d incoming := by - apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans - apply FiniteLaw.expect_mono - intro bits - by_cases hc : SourceCentral T n g s center globalShift A (b+1) bits incoming - · rw [ite_eq_left hc] - have hz : sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by - by_contra hn - exact h (BinaryWindowLabels.allowed_of_central T A s (b+1) _ - (sourceRoleTerm_forced_central T n g s center globalShift A b bits incoming S a F hc hn) - (forcedWindowLabels_distinct T b S a F) - (sourceRoleTerm_forced_close T n g s center globalShift b bits incoming S a F hn)) - rw [hz,abs_zero] - · rw [ite_eq_right hc] - exact occupiedWindowWeight_abs_le_one T s _ b [] S a - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Extension by zero commutes with the finite subtype sum, including an -empty subtype and predicates depending on dependent role indices. -/ -theorem sum_subtype_zero_extend {α : Type*} [Fintype α] (p : α → Prop) [DecidablePred p] - (f : {x // p x} → ℝ) : - (∑x, if h : p x then f ⟨x,h⟩ else 0) = ∑x,f x := by - have h := Fintype.sum_subtype_add_sum_subtype p - (fun x => if h : p x then f ⟨x,h⟩ else 0) - calc - _ = (∑x : {x // p x}, if h : p x.val then f ⟨x.val,h⟩ else 0) + - ∑x : {x // ¬p x}, if h : p x.val then f ⟨x.val,h⟩ else 0 := h.symm - _ = (∑x,f x)+0 := congrArg₂ (·+·) - (Finset.sum_congr rfl (fun x _ => dite_eq_left x.property)) - (Finset.sum_eq_zero (fun x _ => dite_eq_right x.property)) - _ = _ := add_zero _ - -/-- The coefficient is defined directly from the two literal leaf-type -patterns under the common complete posterior bit tree. -/ -def sourceCoefficient (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) : ℝ := - (windowPosteriorLaw T n g (b+1) d).expect (fun bits => - ∏v∈S,(1-sourceTreeLeafSign T n g s center globalShift (b+1) bits incoming 1 v)/2) - - (windowPosteriorLaw T n g (b+1) d).expect (fun bits => - ∏v∈S,(1-sourceTreeLeafSign T n g s center globalShift (b+1) bits incoming (-1) v)/2) - -theorem sourceCoefficient_expansion (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) : - sourceCoefficient T n g s center globalShift b d incoming S = - 2*∑a : OccupiedWindowChoice T b S, - if (occupiedWindowTerm T b S a).isOdd then - sourceRoleAverage T n g s center globalShift b d incoming S a else 0 := by - unfold sourceCoefficient - simp_rw [sourceTreeLeafSign_eq] - exact occupiedWindow_averaged_difference _ T s _ b [] S - -def sourceGoodRoleSquare (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (w : SourceRoleIndex T b) : ℝ := - if h : w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced then - let u : DegreeForcedRole T b r := ⟨w,h⟩ - if BinaryWindowLabels.allowed T A s (b+1) - ((u.shape T b r).forced.labels T (occupiedTermLabels T b w.1 w.2)) then - (sourceRoleAverage T n g s center globalShift b d incoming w.1 w.2)^2 else 0 - else 0 - -theorem sourceGoodRoleSquare_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (w : SourceRoleIndex T b) : - 0 ≤ sourceGoodRoleSquare T n g s center globalShift A b r d incoming w := by - unfold sourceGoodRoleSquare - split_ifs <;> positivity - -theorem sourceGoodRoleSquare_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : - (∑w : SourceRoleIndex T b, sourceGoodRoleSquare T n g s center globalShift A b r d incoming w)= - degreeForcedRoleEnergy T n g s center globalShift A b r d incoming := by - unfold sourceGoodRoleSquare degreeForcedRoleEnergy - exact sum_subtype_zero_extend - (fun w : SourceRoleIndex T b => w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced) - (fun w : DegreeForcedRole T b r => if BinaryWindowLabels.allowed T A s (b+1) - ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) then - (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)^2 else 0) - -/-- Every actual odd role term is either smoothed at an actual singleton, -discarded by the literal central-layout failure event, or retained in the -forced-tree sum. There is no unproved coefficient-bound assumption. -/ -theorem sourceRoleSquare_split (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (hS : S.card=r) (a : OccupiedWindowChoice T b S) - (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : - (if (occupiedWindowTerm T b S a).isOdd then - sourceRoleAverage T n g s center globalShift b d incoming S a else 0)^2 ≤ - η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2+ - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ := by - have hg := sourceGoodRoleSquare_nonneg T n g s center globalShift A b r d incoming ⟨S,a⟩ - by_cases ho : (occupiedWindowTerm T b S a).isOdd - swap - · rw [ite_eq_right ho]; nlinarith [sq_nonneg η, sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] - rw [ite_eq_left ho] - by_cases hz : sourceRoleAverage T n g s center globalShift b d incoming S a=0 - · rw [hz]; nlinarith [sq_nonneg η, sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] - by_cases hn : (occupiedWindowTerm T b S a).noSingleton - swap - · have hs := sourceRoleAverage_singleton T n g s center globalShift b d incoming S a η hcap hn - have hs2 := (sq_le_sq₀ (abs_nonneg _) ((abs_nonneg _).trans hs)).mpr hs - rw [sq_abs] at hs2 - nlinarith [sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] - have hf := OccupiedParityTree.forced_nonempty (occupiedWindowTerm T b S a) - (sourceRoleAverage_valid T n g s center globalShift b d incoming S a hz) hn ho - let w : DegreeForcedRole T b r := ⟨⟨S,a⟩,hS,hf⟩ - let F : (occupiedWindowTerm T b S a).Forced := (w.shape T b r).forced - change _ ≤ _+ (if h : S.card=r ∧ Nonempty (occupiedWindowTerm T b S a).Forced then _ else 0) - rw [dite_eq_left ⟨hS,hf⟩] - change _ ≤ _ + (if BinaryWindowLabels.allowed T A s (b+1) - (F.labels T (occupiedTermLabels T b S a)) then _ else 0) - rw [occupiedTermLabels_forced T b S a F] - by_cases ha : BinaryWindowLabels.allowed T A s (b+1) (forcedWindowLabels T b S a F) - · rw [ite_eq_left ha]; nlinarith [sq_nonneg η, - sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] - · rw [ite_eq_right ha] - have hs := sourceRoleAverage_not_allowed T n g s center globalShift A b d incoming S a F ha - have hs2 := (sq_le_sq₀ (abs_nonneg _) (sourceNoncentralMass_nonneg T n g s center globalShift A (b+1) d incoming)).mpr hs - rw [sq_abs] at hs2 - nlinarith [sq_nonneg η] - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -theorem sourceGoodRoleSquare_degree_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : - (∑S : DegreeLeafSubset T b r, ∑a : OccupiedWindowChoice T b S.val, - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩)= - degreeForcedRoleEnergy T n g s center globalShift A b r d incoming := by - rw [←sourceGoodRoleSquare_sum,Fintype.sum_sigma] - symm - calc - _ = ∑S : Finset (WindowLeaf T (b+1)), if h : S.card=r then - ∑a : OccupiedWindowChoice T b S, - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ else 0 := by - apply Finset.sum_congr rfl - intro S _ - by_cases h : S.card=r - · rw [dite_eq_left h] - · simp [sourceGoodRoleSquare,h] - _ = _ := sum_subtype_zero_extend - (fun S : Finset (WindowLeaf T (b+1)) => S.card=r) - (fun S : DegreeLeafSubset T b r => ∑a : OccupiedWindowChoice T b S.val, - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩) - -theorem sourceCoefficient_square_bound (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (hS : S.card=r) - (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : - (sourceCoefficient T n g s center globalShift b d incoming S)^2 ≤ - 4*(3^((b+1)*r):ℕ)* - ((3^((b+1)*r):ℕ)*(η^2+ - (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ - ∑a : OccupiedWindowChoice T b S, - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩) := by - let f : OccupiedWindowChoice T b S → ℝ := fun a => - if (occupiedWindowTerm T b S a).isOdd then - sourceRoleAverage T n g s center globalShift b d incoming S a else 0 - let M : ℝ := (3^((b+1)*r):ℕ) - let E : ℝ := η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2 - let G := fun a => sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ - have hE : 0 ≤ E := add_nonneg (sq_nonneg _) (sq_nonneg _) - have hM : 0 ≤ M := Nat.cast_nonneg _ - have hcard : (Fintype.card (OccupiedWindowChoice T b S):ℝ) ≤ M := by - dsimp only [M] - exact_mod_cast (hS ▸ occupiedWindowChoice_card_le T b S) - have hcs : (∑a,f a)^2 ≤ (Fintype.card (OccupiedWindowChoice T b S):ℝ)*∑a,(f a)^2 := by - simpa using Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ => (1:ℝ)) f - have hs : (∑a,(f a)^2) ≤ M*E+∑a,G a := by - calc - _ ≤ ∑a : OccupiedWindowChoice T b S,(E+G a) := - Finset.sum_le_sum (fun a _ => sourceRoleSquare_split T n g s center globalShift A b r d incoming S hS a η hcap) - _ = (Fintype.card (OccupiedWindowChoice T b S):ℝ)*E+∑a,G a := by simp [Finset.sum_add_distrib] - _ ≤ M*E+∑a,G a := add_le_add (mul_le_mul_of_nonneg_right hcard hE) le_rfl - calc - _ = 4*(∑a,f a)^2 := by rw [sourceCoefficient_expansion]; dsimp only [f]; ring - _ ≤ 4*((Fintype.card (OccupiedWindowChoice T b S):ℝ)*∑a,(f a)^2) := by linarith - _ ≤ 4*(M*∑a,(f a)^2) := mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_right hcard (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) (by norm_num) - _ ≤ 4*(M*(M*E+∑a,G a)) := mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_left hs hM) (by norm_num) - _ = _ := by dsimp only [M,E,G]; ring - -/-- The full degree coefficient sum, including every selected monomial, -singletons, and off-center labels. This is the finite, unabsorbed version -of the manuscript's low-degree coefficient estimate. -/ -theorem sourceCoefficient_degree_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : - (∑S : DegreeLeafSubset T b r, - (sourceCoefficient T n g s center globalShift b d incoming S.val)^2) ≤ - 4*(3^((b+1)*r):ℕ)* - (((Fintype.card (WindowLeaf T (b+1))).choose r:ℕ)*(3^((b+1)*r):ℕ)* - (η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ - degreeForcedRoleEnergy T n g s center globalShift A b r d incoming) := by - calc - _ ≤ ∑S : DegreeLeafSubset T b r, - 4*(3^((b+1)*r):ℕ)* - ((3^((b+1)*r):ℕ)*(η^2+ - (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ - ∑a : OccupiedWindowChoice T b S.val, - sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩) := - Finset.sum_le_sum (fun S _ => sourceCoefficient_square_bound T n g s center globalShift A b r d incoming S.val S.property η hcap) - _ = _ := by - rw [←Finset.mul_sum,Finset.sum_add_distrib,sourceGoodRoleSquare_degree_sum] - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,degreeLeafSubset_card] - ring - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Shapes + +namespace OAI + +/-! +# Energy + +Shaped envelopes, actual coefficient aggregation, role counts, central contributions, and full coefficient energy. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw +namespace OccupiedParityTree + +/-- Actual unsigned coefficient envelope on one ordered occupied shape. +No bits are resampled for the additional leaves. -/ +def Forced.envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (x : t.Labels T) + (bits : WindowAssignments T n g Bool b) (incoming : ℤ) : ℝ := + binaryAnchorKernel T n g s center globalShift b (F.labels T x) bits incoming * + ∏e : F.ExtraLeafEdge, motifIndicator s ((x e.val.val).val- + sourceTreeAnchors T n g center globalShift b bits incoming (e.val.val.parentPath T x)) + +def Forced.averagedEnvelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (x : t.Labels T) + (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : ℝ := + (windowPosteriorLaw T n g b d).expect + (fun bits => F.envelope T n g s center globalShift x bits incoming) + +/-- Offsets for all extra leaf constraints, with only their labels replaced +by zero. The location of each constraint is not changed by that replacement. -/ +def Forced.extraOffsets (T n g : ℕ → ℕ) (hT : 0 ⟨0,hT⟩),z))) + +theorem Forced.averagedEnvelope_split (T n g : ℕ → ℕ) (hT : 0 binaryAnchorKernel T n g s center globalShift b p bits incoming) + (fun bits e => F.extraOffsets T n g hT center globalShift p z bits incoming e) h := by + let x := (F.fullLabelsEquiv T).symm (p,h,z) + have hx : F.fullLabelsEquiv T x=(p,h,z) := Equiv.apply_symm_apply _ _ + have hp : F.labels T x=p := by rw [←F.fullLabelsEquiv_fst,hx] + apply congrArg (FiniteLaw.expect (windowPosteriorLaw T n g b d)) + funext bits + change F.envelope T n g s center globalShift x bits incoming = _ + unfold Forced.envelope + rw [hp] + congr 1 + apply Finset.prod_congr rfl + intro e he + have hv := congrArg (fun a => (a.2.1 e).val) hx + simp only [Forced.fullLabelsEquiv_leaf_value] at hv + rw [hv] + unfold Forced.extraOffsets + congr 2 + exact congrArg (sourceTreeAnchors T n g center globalShift b bits incoming) + (F.parentPath_extraLeaf_invariant T p h (fun _ => ⟨0,hT⟩) z e.val.val) + +/-- Summing every actual numeric labeling of a fixed shape costs exactly +one l1-squared factor per extra leaf and one factor per extra interior label. +The forced-anchor energy remains a single genuine correlated posterior. -/ +theorem Forced.envelope_energy (T n g : ℕ → ℕ) (hT : 0 + if R (F.labels T x) then (F.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0) + rw [←hs] + simp only [Fintype.sum_prod_type] + calc + _ ≤ ∑p : BinaryWindowLabels T b, ∑z : F.InteriorLabels T, + if R p then L*(binaryAnchorAverage T n g s center globalShift b p d incoming)^2 else 0 := by + apply Finset.sum_le_sum + intro p hp + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro z hz + have he (h : F.ExtraLeafEdge → Fin (T 0)) : + F.labels T ((F.fullLabelsEquiv T).symm (p,h,z))=p := by + rw [←F.fullLabelsEquiv_fst,Equiv.apply_symm_apply] + simp_rw [he] + by_cases hR : R p + · simp only [ite_eq_left hR] + simp_rw [F.averagedEnvelope_split T n g hT s center globalShift] + exact indexedExtraAverage_energy (windowPosteriorLaw T n g b d) s (T 0) + (fun bits => binaryAnchorKernel T n g s center globalShift b p bits incoming) + (fun bits => binaryAnchorKernel_nonneg T n g s center globalShift b p bits incoming) + (fun bits e => F.extraOffsets T n g hT center globalShift p z bits incoming e) + · simp only [ite_eq_right hR,Finset.sum_const_zero,le_refl] + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro p hp + by_cases hr : R p <;> simp [hr,L,mul_assoc] +/-- Connected forced-shape coefficient-envelope estimate with the true +common-global/local sibling energy, and no independent-sibling substitute. -/ +theorem Forced.envelope_energy_root (T n g : ℕ → ℕ) (hT : 0 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) := by + apply (F.envelope_energy T n g hT s center globalShift + (BinaryWindowLabels.allowed T A s (b+1)) d incoming).trans + exact mul_le_mul_of_nonneg_left + (binaryAnchorAverage_energy T n g s center globalShift A shift hplat B C hB hC b d hcap incoming) + (by positivity) + +end OccupiedParityTree +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +/-- The actual full-tree leaf address of a bottom edge, including the edge's +own numeric label. -/ +def Edge.bottomAddress (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → + (x : t.Labels T) → (e : t.Edge) → e.height=0 → WindowLeaf T b + | _, .leaf, _, e, _ => e.elim + | b+1, .node k children roles, x, Sum.inl i, he => by + change b=0 at he + subst b + exact (x (Sum.inl i),(⟨0,by decide⟩ : Fin 1)) + | b+1, .node k children roles, x, Sum.inr z, he => + (x (Sum.inl z.1), Edge.bottomAddress T (x.child T z.1) z.2 he) + +theorem Edge.bottomAddress_mem (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (x : t.Labels T) (e : t.Edge) (he : e.height=0) : + e.bottomAddress T x he ∈ t.labelledLeaves T x := by + induction t with + | leaf => exact e.elim + | @node b k children roles ih => + cases e with + | inl i => + change b=0 at he + subst b + apply Finset.mem_biUnion.mpr + refine ⟨i,Finset.mem_univ i,?_⟩ + apply Finset.mem_image.mpr + refine ⟨(⟨0,by decide⟩ : Fin 1),?_,rfl⟩ + have hz (u : OccupiedParityTree 0) (y : u.Labels T) : + u.labelledLeaves T y = {(⟨0,by decide⟩ : Fin 1)} := by cases u; rfl + rw [hz] + exact Finset.mem_singleton_self _ + | inr z => + apply Finset.mem_biUnion.mpr + refine ⟨z.1,Finset.mem_univ _,?_⟩ + exact Finset.mem_image.mpr ⟨z.2.bottomAddress T (x.child T z.1) he, ih z.1 _ _ he,rfl⟩ + +/-- Leaf constraints read from the real shape label address are exactly the +ones in the genuine complete-tree latent law. -/ +theorem Edge.bottomIndicator_eq (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (t : OccupiedParityTree (b+1)) (x : t.Labels T) + (e : t.Edge) (he : e.height=0) + (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) : + sourceBottomIndicator T n g s center globalShift b bits incoming (e.bottomAddress T x he) = + motifIndicator s ((x e).val-sourceTreeAnchors T n g center globalShift (b+1) bits incoming + (e.parentPath T x)) := by + induction b generalizing incoming with + | zero => + cases t with + | node k children roles => + cases e with + | inl i => + change motifIndicator s _ = motifIndicator s _ + congr 1 + change ((x (Sum.inl i)).val:ℤ)-center 0+(∑i,(bitIndex (bits.1 i):ℤ))+incoming = + ((x (Sum.inl i)).val:ℤ)-(center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) + omega + | inr z => have hh := z.2.height_lt; omega + | succ b ih => + cases t with + | node k children roles => + cases e with + | inl i => change b+1=0 at he; omega + | inr z => + change sourceBottomIndicator T n g s center globalShift b + (bits.2.2 (x (Sum.inl z.1))) (globalShift (b+1) bits.2.1 (x (Sum.inl z.1))) + (z.2.bottomAddress T (x.child T z.1) he) = motifIndicator s ((x.child T z.1 z.2).val- + sourceTreeAnchors T n g center globalShift (b+1+1) bits incoming + ((x (Sum.inl z.1)).val::z.2.parentPath T (x.child T z.1))) + rw [sourceTreeAnchors_child T n g center globalShift (b+1) bits incoming + (x (Sum.inl z.1)) (z.2.parentPath T (x.child T z.1))] + exact ih _ _ _ he _ _ + +end OccupiedParityTree +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Taking repeated constraints from a zero-one product can only enlarge it. +The map need not be injective. This keeps the real leaf addresses, including +coincident labels in the ambient enlarged summation. -/ +theorem product_zero_one_pull_le {α β : Type*} [Fintype β] + (S : Finset α) (f : α → ℝ) (hf : ∀a∈S,f a=0 ∨ f a=1) + (g : β → α) (hg : ∀b,g b∈S) : (∏a∈S,f a)≤∏b,f (g b) := by + rcases prod_zero_one S f hf with hz | ho + · rw [hz] + exact Finset.prod_nonneg (fun b _ => by rcases hf (g b) (hg b) with h|h <;> simp [h]) + · have h (b : β) : f (g b)=1 := by + rcases hf (g b) (hg b) with h|h + · have hz := Finset.prod_eq_zero (hg b) h + rw [ho] at hz + norm_num at hz + · exact h + rw [ho] + simp only [h,Finset.prod_const_one,le_refl] + +/-- Every actual role coefficient is bounded by its actual forced shape +and extra-leaf envelope before averaging over the single whole latent law. -/ +theorem sourceRoleTerm_envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + |sourceRoleTerm T n g s center globalShift b bits incoming S a|≤ + F.envelope T n g s center globalShift (occupiedTermLabels T b S a) bits incoming := by + let x := occupiedTermLabels T b S a + let f := sourceBottomIndicator T n g s center globalShift b bits incoming + let addr : F.ExtraLeafEdge → WindowLeaf T (b+1) := + fun e => e.val.val.bottomAddress T x e.property + have hm (e : F.ExtraLeafEdge) : addr e∈S := by + rw [←occupiedTermLabels_leaves T b S a] + exact e.val.val.bottomAddress_mem T x e.property + have he (e : F.ExtraLeafEdge) : f (addr e)=motifIndicator s ((x e.val.val).val- + sourceTreeAnchors T n g center globalShift (b+1) bits incoming (e.val.val.parentPath T x)) := + e.val.val.bottomIndicator_eq T n g s center globalShift b _ x e.property bits incoming + have hle := product_zero_one_pull_le S f (fun v hv => + sourceBottomIndicator_zero_one T n g s center globalShift b bits incoming v) addr hm + simp_rw [he] at hle + apply le_mul_of_zero_one + (binaryAnchorKernel_zero_one T n g s center globalShift _ _ bits incoming) + (prod_zero_one Finset.univ _ (fun e _ => by unfold motifIndicator; split_ifs <;> simp)) + · simpa only [occupiedTermLabels_forced] using + sourceRoleTerm_forced_anchor T n g s center globalShift b bits incoming S a F + · exact (sourceRoleTerm_all_leaf_constraints T n g s center globalShift b bits incoming S a).trans hle + +/-- The averaged coefficient uses one exact metadata fiber. No fit event, +plateau event or leaf-emission observation is conditioned on here. -/ +theorem sourceRoleAverage_envelope (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ + F.averagedEnvelope T n g s center globalShift (occupiedTermLabels T b S a) d incoming := by + apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans + exact FiniteLaw.expect_mono _ (fun bits => + sourceRoleTerm_envelope T n g s center globalShift b bits incoming S a F) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw +open OccupiedParityTree + +theorem occupiedWindowTerm_leafCount (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : + (occupiedWindowTerm T b S a).leafCount=S.card := by + rw [←occupiedWindowTerm_eq T 0 (fun _ => 0) b [] S a] + exact occupiedWindowShape_leafCount T 0 (fun _ => 0) b [] S _ + +theorem occupiedWindowTerm_occupied (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) (hS : S.Nonempty) : + (occupiedWindowTerm T b S a).occupied := by + rw [←occupiedWindowTerm_eq T 0 (fun _ => 0) b [] S a] + exact occupiedWindowShape_occupied T 0 (fun _ => 0) b [] S hS _ + +/-- Only the unlabeled ordered role shape is selected here; no child label +or hidden orientation enters the forced choice. -/ +abbrev DegreeForcedShape (b r : ℕ) := + {t : OccupiedParityTree b // t.occupied ∧ t.leafCount=r ∧ Nonempty t.Forced} + +instance degreeForcedShapeFinite (b r : ℕ) : Finite (DegreeForcedShape b r) := by + let := finite_bounded_occupied_shapes b r + exact Finite.of_injective + (fun t : DegreeForcedShape b r => + (⟨t.val,t.property.1,t.property.2.1.le⟩ : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r})) + (fun _ _ h => Subtype.ext (congrArg + (fun q : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} => q.val) h)) + +noncomputable instance degreeForcedShapeFintype (b r : ℕ) : Fintype (DegreeForcedShape b r) := + Fintype.ofFinite _ + +def DegreeForcedShape.forced {b r : ℕ} (t : DegreeForcedShape b r) : t.val.Forced := + Classical.choice t.property.2.2 + +theorem card_degreeForcedShape_le (b r : ℕ) : + Fintype.card (DegreeForcedShape b r) ≤ shapeRoleConstant r b := by + let f : DegreeForcedShape b r → FiniteRoleShape r b := fun t => + Classical.choose (exists_finiteRoleShape t.val r t.property.1 t.property.2.1.le) + apply Fintype.card_le_of_injective f + intro t u he + apply Subtype.ext + have ht := Classical.choose_spec (exists_finiteRoleShape t.val r t.property.1 t.property.2.1.le) + have hu := Classical.choose_spec (exists_finiteRoleShape u.val r u.property.1 u.property.2.1.le) + exact ht.symm.trans ((congrArg (FiniteRoleShape.toTree r b) he).trans hu) + +abbrev SourceRoleIndex (T : ℕ → ℕ) (b : ℕ) := + (S : Finset (WindowLeaf T (b+1))) × OccupiedWindowChoice T b S + +abbrev DegreeForcedRole (T : ℕ → ℕ) (b r : ℕ) := + {w : SourceRoleIndex T b // w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced} + +def DegreeForcedRole.shape (T : ℕ → ℕ) (b r : ℕ) (w : DegreeForcedRole T b r) : + DegreeForcedShape (b+1) r := by + refine ⟨occupiedWindowTerm T b w.val.1 w.val.2,?_,?_,w.property.2⟩ + · apply occupiedWindowTerm_occupied + apply Finset.card_pos.mp + obtain ⟨F⟩ := w.property.2 + have hh := F.leaf_lower + rw [occupiedWindowTerm_leafCount] at hh + exact (Nat.pow_pos (by decide : (0:ℕ)<2)).trans_le hh + · exact (occupiedWindowTerm_leafCount T b w.val.1 w.val.2).trans w.property.1 + +def DegreeForcedRole.encoding (T : ℕ → ℕ) (b r : ℕ) (w : DegreeForcedRole T b r) : + (t : DegreeForcedShape (b+1) r) × t.val.Labels T := + ⟨w.shape T b r,occupiedTermLabels T b w.val.1 w.val.2⟩ + +theorem DegreeForcedRole.encoding_injective (T : ℕ → ℕ) (b r : ℕ) : + Function.Injective (DegreeForcedRole.encoding T b r) := by + intro w v he + apply Subtype.ext + apply occupiedTermEncoding_injective T b + exact congrArg (fun z : (t : DegreeForcedShape (b+1) r) × t.val.Labels T => + (⟨z.1.val,z.2⟩ : (t : OccupiedParityTree (b+1)) × t.Labels T)) he + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw +open OccupiedParityTree + +/-- A degree-r sum over the genuine pairs (selected leaves, roles), +restricted only by deterministic allowed forced labels. -/ +def degreeForcedRoleEnergy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : ℝ := + ∑w : DegreeForcedRole T b r, + if BinaryWindowLabels.allowed T A s (b+1) + ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) then + (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)^2 else 0 + +/-- The actual coefficient indices inject into shape+numeric-labels. Thus +summing the enlarged envelope really bounds the original coefficient sum, +with no identification of different selected monomials. -/ +theorem degreeForcedRoleEnergy_le_envelopes (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : + degreeForcedRoleEnergy T n g s center globalShift A b r d incoming ≤ + ∑t : DegreeForcedShape (b+1) r, ∑x : t.val.Labels T, + if BinaryWindowLabels.allowed T A s (b+1) (t.forced.labels T x) then + (t.forced.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0 := by + let f := fun z : (t : DegreeForcedShape (b+1) r) × t.val.Labels T => + if BinaryWindowLabels.allowed T A s (b+1) (z.1.forced.labels T z.2) then + (z.1.forced.averagedEnvelope T n g s center globalShift z.2 d incoming)^2 else 0 + have hf : ∀z,0≤f z := by intro z; dsimp [f]; split_ifs <;> positivity + calc + _ ≤ ∑w : DegreeForcedRole T b r,f (w.encoding T b r) := by + apply Finset.sum_le_sum + intro w hw + dsimp only [f,DegreeForcedRole.encoding] + by_cases h : BinaryWindowLabels.allowed T A s (b+1) + ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) + · simp only [ite_eq_left h] + have hh := sourceRoleAverage_envelope T n g s center globalShift b d incoming + w.val.1 w.val.2 (w.shape T b r).forced + rw [←sq_abs (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)] + exact (sq_le_sq₀ (abs_nonneg _) ((abs_nonneg _).trans hh)).mpr hh + · simp only [ite_eq_right h,le_refl] + _ ≤ ∑z,f z := by + simpa only [ite_true] using sum_injective_profile_le + (DegreeForcedRole.encoding T b r) (DegreeForcedRole.encoding_injective T b r) + (fun _ => True) (fun _ => trivial) f hf + _ = _ := Fintype.sum_sigma _ + +/-- Uniform arithmetic interior-label budget of a degree-r depth-(b+1) +shape. This includes no factor for a bottom label. -/ +def interiorLabelBudget (T : ℕ → ℕ) (b r : ℕ) : ℝ := + ((∏j : Fin (b+1),if j.val=0 then 1 else T j.val : ℕ):ℝ)^(r-2^(b+1)) + +theorem degreeForcedRoleEnergy_bound (T n g : ℕ → ℕ) (hT : ∀j,0 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) := by + let K := interiorLabelBudget T b r * ((2^s:ℕ):ℝ)^(2*(r-2^(b+1))) * + ((2*((2^s:ℕ):ℝ)^3*B b) * binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b) + have hbud : 0≤binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6*C (j+1)*B j) b := by + exact binaryTreeBudget_nonneg _ (fun j => + mul_nonneg (mul_nonneg (by positivity) (hC (j+1))) (hB j)) b + have hb := hB b + have hK : 0≤K := by dsimp [K,interiorLabelBudget]; positivity + calc + _ ≤ ∑t : DegreeForcedShape (b+1) r, ∑x : t.val.Labels T, + if BinaryWindowLabels.allowed T A s (b+1) (t.forced.labels T x) then + (t.forced.averagedEnvelope T n g s center globalShift x d incoming)^2 else 0 := + degreeForcedRoleEnergy_le_envelopes T n g s center globalShift A b r d incoming + _ ≤ ∑_t : DegreeForcedShape (b+1) r,K := by + apply Finset.sum_le_sum + intro t ht + apply (t.forced.envelope_energy_root T n g (hT 0) s center globalShift A shift hplat + B C hB hC b t.val d hcap incoming).trans + have hi := t.forced.card_interiorLabels_le T hT t.property.1 + rw [t.property.2.1] at hi + have hi' : (Fintype.card (t.forced.InteriorLabels T):ℝ) ≤ interiorLabelBudget T b r := by + dsimp [interiorLabelBudget] + exact_mod_cast hi + rw [t.forced.card_extraLeafEdge,t.property.2.1] + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hi' (by positivity)) (by positivity) + _ = (Fintype.card (DegreeForcedShape (b+1) r):ℝ)*K := by + rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ ≤ (shapeRoleConstant r (b+1):ℝ)*K := by + apply mul_le_mul_of_nonneg_right _ hK + exact_mod_cast card_degreeForcedShape_le (b+1) r + _ = _ := by dsimp [K]; ring + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Total role multiplicity for one actual selected monomial. Every level +has at most the number of selected leaves; no ambient-label factor occurs. -/ +theorem occupiedWindowChoice_card_le (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) : + Fintype.card (OccupiedWindowChoice T b S) ≤ 3^((b+1)*S.card) := by + induction b with + | zero => + change Fintype.card (Fin S.card → Fin 3) ≤ _ + simp + | succ b ih => + change Fintype.card (((i : Fin (selectedChildren S).card) → + OccupiedWindowChoice T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) × + (Fin (selectedChildren S).card → Fin 3)) ≤ _ + rw [Fintype.card_prod,Fintype.card_pi,Fintype.card_fun,Fintype.card_fin,Fintype.card_fin] + have hprod := Finset.prod_le_prod (s:=Finset.univ) (fun i _ => + ih (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) + have hs : (∑i : Fin (selectedChildren S).card, + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val).card)=S.card := + (selected_sum_index (selectedChildren S) (fun h => (selectedChildLeaves S h).card)).trans + (selected_children_card S) + have hc : (selectedChildren S).card≤S.card := Finset.card_image_le + calc + _ ≤ (∏i : Fin (selectedChildren S).card, + 3^((b+1)*(selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val).card)) * + 3^(selectedChildren S).card := Nat.mul_le_mul_right _ hprod + _ = 3^((b+1)*S.card+(selectedChildren S).card) := by + rw [Finset.prod_pow_eq_pow_sum,←Finset.mul_sum,hs,←pow_add] + _ ≤ _ := Nat.pow_le_pow_right (by decide) (by simp only [Nat.add_mul,Nat.one_mul]; omega) + +abbrev DegreeLeafSubset (T : ℕ → ℕ) (b r : ℕ) := + {S : Finset (WindowLeaf T (b+1)) // S.card=r} + +theorem degreeLeafSubset_card (T : ℕ → ℕ) (b r : ℕ) : + Fintype.card (DegreeLeafSubset T b r)=(Fintype.card (WindowLeaf T (b+1))).choose r := by + have h := Finset.card_powersetCard r (Finset.univ : Finset (WindowLeaf T (b+1))) + have he : (Finset.univ.powersetCard r : Finset (Finset (WindowLeaf T (b+1))))=(Finset.univ.filter (fun S : Finset (WindowLeaf T (b+1)) => S.card=r)) := by + ext S + simp only [Finset.mem_powersetCard,Finset.subset_univ,true_and,Finset.mem_filter,Finset.mem_univ] + rw [he,Finset.card_univ] at h + rw [Fintype.card_subtype] + exact h + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- All actual motif support lies in the chosen central interval at every +vertex of the full window tree. This is a predicate of the complete bits, +not an event on which any posterior law is conditioned. -/ +def SourceCentral (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) : + (b : ℕ) → WindowAssignments T n g Bool b → ℤ → Prop + | 0, _, _ => True + | b+1, bits, incoming => + (∀h : Fin (T b), motifIndicator s ((h.val:ℤ)-center b+ + (∑i,(bitIndex (bits.1 i):ℤ))+incoming)≠0 → h∈A b) ∧ + ∀h, SourceCentral T n g s center globalShift A b (bits.2.2 h) (globalShift b bits.2.1 h) + +def BinaryWindowLabels.central (T : ℕ → ℕ) (A : (b : ℕ) → Finset (Fin (T b))) : + (b : ℕ) → BinaryWindowLabels T b → Prop + | 0, _ => True + | b+1, p => p.1∈A b ∧ p.2.1∈A b ∧ central T A b p.2.2.1 ∧ central T A b p.2.2.2 + +theorem BinaryWindowLabels.allowed_of_central (T : ℕ → ℕ) + (A : (b : ℕ) → Finset (Fin (T b))) (s b : ℕ) (p : BinaryWindowLabels T b) + (hc : central T A b p) (hd : distinct T b p) (hs : close T s b p) : + allowed T A s b p := by + induction b with + | zero => trivial + | succ b ih => + exact ⟨⟨hc.1,hc.2.1,hd.1,by simpa only [abs_sub_comm] using hs.1⟩, + ih _ hc.2.2.1 hd.2.1 hs.2.1,ih _ hc.2.2.2 hd.2.2 hs.2.2⟩ + +theorem sourceRoleTerm_forced_central (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) + (hc : SourceCentral T n g s center globalShift A (b+1) bits incoming) + (hz : sourceRoleTerm T n g s center globalShift b bits incoming S a≠0) : + BinaryWindowLabels.central T A (b+1) (forcedWindowLabels T b S a F) := by + induction b generalizing incoming with + | zero => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_zero] at hz + change (S.equivFin.symm i).val.1 ∈ A 0 ∧ (S.equivFin.symm j).val.1 ∈ A 0 ∧ True ∧ True + refine ⟨hc.1 _ ?_,hc.1 _ ?_,trivial,trivial⟩ + · convert nonzero_of_abs_le hz (occupiedRootWeight_bottom_anchor T s S a (center 0-(∑k,(bitIndex (bits.1 k):ℤ))-incoming) i) using 1 + congr 1; ring + · convert nonzero_of_abs_le hz (occupiedRootWeight_bottom_anchor T s S a (center 0-(∑k,(bitIndex (bits.1 k):ℤ))-incoming) j) using 1 + congr 1; ring + | succ b ih => + cases F with + | node i j hne hi hj left right => + rw [sourceRoleTerm_succ] at hz + have hm := mul_ne_zero_iff.mp hz + have hp := Finset.prod_ne_zero_iff.mp hm.2 + change ((selectedChildren S).equivFin.symm i).val ∈ A (b+1) ∧ + ((selectedChildren S).equivFin.symm j).val ∈ A (b+1) ∧ + BinaryWindowLabels.central T A (b+1) + (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) + (a.1 i) left) ∧ + BinaryWindowLabels.central T A (b+1) + (forcedWindowLabels T b (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) + (a.1 j) right) + refine ⟨hc.1 _ ?_,hc.1 _ ?_, + ih _ _ _ _ left (hc.2 _) (hp i (Finset.mem_univ i)), + ih _ _ _ _ right (hc.2 _) (hp j (Finset.mem_univ j))⟩ + · convert nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ i hi) using 1 + congr 1; ring + · convert nonzero_of_abs_le hm.1 (occupiedRootWeight_internal_anchor T s b S a _ j hj) using 1 + congr 1; ring + +/-- The discarded noncentral role contributions are bounded by the actual +conditional probability of a failed full-tree layout. Typical metadata may +bound this mass; the averaging distribution itself remains unconditional. -/ +def sourceNoncentralMass (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : ℝ := + (windowPosteriorLaw T n g b d).expect + (fun bits => if SourceCentral T n g s center globalShift A b bits incoming then 0 else 1) + +theorem sourceNoncentralMass_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) b) (incoming : ℤ) : + 0 ≤ sourceNoncentralMass T n g s center globalShift A b d incoming := by + exact Finset.sum_nonneg (fun bits _ => mul_nonneg + ((windowPosteriorLaw T n g b d).nonneg bits) (by dsimp only; split_ifs <;> norm_num)) + +theorem sourceRoleAverage_not_allowed (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) + (h : ¬BinaryWindowLabels.allowed T A s (b+1) (forcedWindowLabels T b S a F)) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤ + sourceNoncentralMass T n g s center globalShift A (b+1) d incoming := by + apply ((windowPosteriorLaw T n g (b+1) d).abs_expect_le _).trans + apply FiniteLaw.expect_mono + intro bits + by_cases hc : SourceCentral T n g s center globalShift A (b+1) bits incoming + · rw [ite_eq_left hc] + have hz : sourceRoleTerm T n g s center globalShift b bits incoming S a=0 := by + by_contra hn + exact h (BinaryWindowLabels.allowed_of_central T A s (b+1) _ + (sourceRoleTerm_forced_central T n g s center globalShift A b bits incoming S a F hc hn) + (forcedWindowLabels_distinct T b S a F) + (sourceRoleTerm_forced_close T n g s center globalShift b bits incoming S a F hn)) + rw [hz,abs_zero] + · rw [ite_eq_right hc] + exact occupiedWindowWeight_abs_le_one T s _ b [] S a + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Extension by zero commutes with the finite subtype sum, including an +empty subtype and predicates depending on dependent role indices. -/ +theorem sum_subtype_zero_extend {α : Type*} [Fintype α] (p : α → Prop) [DecidablePred p] + (f : {x // p x} → ℝ) : + (∑x, if h : p x then f ⟨x,h⟩ else 0) = ∑x,f x := by + have h := Fintype.sum_subtype_add_sum_subtype p + (fun x => if h : p x then f ⟨x,h⟩ else 0) + calc + _ = (∑x : {x // p x}, if h : p x.val then f ⟨x.val,h⟩ else 0) + + ∑x : {x // ¬p x}, if h : p x.val then f ⟨x.val,h⟩ else 0 := h.symm + _ = (∑x,f x)+0 := congrArg₂ (·+·) + (Finset.sum_congr rfl (fun x _ => dite_eq_left x.property)) + (Finset.sum_eq_zero (fun x _ => dite_eq_right x.property)) + _ = _ := add_zero _ + +/-- The coefficient is defined directly from the two literal leaf-type +patterns under the common complete posterior bit tree. -/ +def sourceCoefficient (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) : ℝ := + (windowPosteriorLaw T n g (b+1) d).expect (fun bits => + ∏v∈S,(1-sourceTreeLeafSign T n g s center globalShift (b+1) bits incoming 1 v)/2) - + (windowPosteriorLaw T n g (b+1) d).expect (fun bits => + ∏v∈S,(1-sourceTreeLeafSign T n g s center globalShift (b+1) bits incoming (-1) v)/2) + +theorem sourceCoefficient_expansion (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) : + sourceCoefficient T n g s center globalShift b d incoming S = + 2*∑a : OccupiedWindowChoice T b S, + if (occupiedWindowTerm T b S a).isOdd then + sourceRoleAverage T n g s center globalShift b d incoming S a else 0 := by + unfold sourceCoefficient + simp_rw [sourceTreeLeafSign_eq] + exact occupiedWindow_averaged_difference _ T s _ b [] S + +def sourceGoodRoleSquare (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (w : SourceRoleIndex T b) : ℝ := + if h : w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced then + let u : DegreeForcedRole T b r := ⟨w,h⟩ + if BinaryWindowLabels.allowed T A s (b+1) + ((u.shape T b r).forced.labels T (occupiedTermLabels T b w.1 w.2)) then + (sourceRoleAverage T n g s center globalShift b d incoming w.1 w.2)^2 else 0 + else 0 + +theorem sourceGoodRoleSquare_nonneg (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (w : SourceRoleIndex T b) : + 0 ≤ sourceGoodRoleSquare T n g s center globalShift A b r d incoming w := by + unfold sourceGoodRoleSquare + split_ifs <;> positivity + +theorem sourceGoodRoleSquare_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : + (∑w : SourceRoleIndex T b, sourceGoodRoleSquare T n g s center globalShift A b r d incoming w)= + degreeForcedRoleEnergy T n g s center globalShift A b r d incoming := by + unfold sourceGoodRoleSquare degreeForcedRoleEnergy + exact sum_subtype_zero_extend + (fun w : SourceRoleIndex T b => w.1.card=r ∧ Nonempty (occupiedWindowTerm T b w.1 w.2).Forced) + (fun w : DegreeForcedRole T b r => if BinaryWindowLabels.allowed T A s (b+1) + ((w.shape T b r).forced.labels T (occupiedTermLabels T b w.val.1 w.val.2)) then + (sourceRoleAverage T n g s center globalShift b d incoming w.val.1 w.val.2)^2 else 0) + +/-- Every actual odd role term is either smoothed at an actual singleton, +discarded by the literal central-layout failure event, or retained in the +forced-tree sum. There is no unproved coefficient-bound assumption. -/ +theorem sourceRoleSquare_split (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (hS : S.card=r) (a : OccupiedWindowChoice T b S) + (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : + (if (occupiedWindowTerm T b S a).isOdd then + sourceRoleAverage T n g s center globalShift b d incoming S a else 0)^2 ≤ + η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2+ + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ := by + have hg := sourceGoodRoleSquare_nonneg T n g s center globalShift A b r d incoming ⟨S,a⟩ + by_cases ho : (occupiedWindowTerm T b S a).isOdd + swap + · rw [ite_eq_right ho]; nlinarith [sq_nonneg η, sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] + rw [ite_eq_left ho] + by_cases hz : sourceRoleAverage T n g s center globalShift b d incoming S a=0 + · rw [hz]; nlinarith [sq_nonneg η, sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] + by_cases hn : (occupiedWindowTerm T b S a).noSingleton + swap + · have hs := sourceRoleAverage_singleton T n g s center globalShift b d incoming S a η hcap hn + have hs2 := (sq_le_sq₀ (abs_nonneg _) ((abs_nonneg _).trans hs)).mpr hs + rw [sq_abs] at hs2 + nlinarith [sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] + have hf := OccupiedParityTree.forced_nonempty (occupiedWindowTerm T b S a) + (sourceRoleAverage_valid T n g s center globalShift b d incoming S a hz) hn ho + let w : DegreeForcedRole T b r := ⟨⟨S,a⟩,hS,hf⟩ + let F : (occupiedWindowTerm T b S a).Forced := (w.shape T b r).forced + change _ ≤ _+ (if h : S.card=r ∧ Nonempty (occupiedWindowTerm T b S a).Forced then _ else 0) + rw [dite_eq_left ⟨hS,hf⟩] + change _ ≤ _ + (if BinaryWindowLabels.allowed T A s (b+1) + (F.labels T (occupiedTermLabels T b S a)) then _ else 0) + rw [occupiedTermLabels_forced T b S a F] + by_cases ha : BinaryWindowLabels.allowed T A s (b+1) (forcedWindowLabels T b S a F) + · rw [ite_eq_left ha]; nlinarith [sq_nonneg η, + sq_nonneg (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)] + · rw [ite_eq_right ha] + have hs := sourceRoleAverage_not_allowed T n g s center globalShift A b d incoming S a F ha + have hs2 := (sq_le_sq₀ (abs_nonneg _) (sourceNoncentralMass_nonneg T n g s center globalShift A (b+1) d incoming)).mpr hs + rw [sq_abs] at hs2 + nlinarith [sq_nonneg η] + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +theorem sourceGoodRoleSquare_degree_sum (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : + (∑S : DegreeLeafSubset T b r, ∑a : OccupiedWindowChoice T b S.val, + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩)= + degreeForcedRoleEnergy T n g s center globalShift A b r d incoming := by + rw [←sourceGoodRoleSquare_sum,Fintype.sum_sigma] + symm + calc + _ = ∑S : Finset (WindowLeaf T (b+1)), if h : S.card=r then + ∑a : OccupiedWindowChoice T b S, + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ else 0 := by + apply Finset.sum_congr rfl + intro S _ + by_cases h : S.card=r + · rw [dite_eq_left h] + · simp [sourceGoodRoleSquare,h] + _ = _ := sum_subtype_zero_extend + (fun S : Finset (WindowLeaf T (b+1)) => S.card=r) + (fun S : DegreeLeafSubset T b r => ∑a : OccupiedWindowChoice T b S.val, + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩) + +theorem sourceCoefficient_square_bound (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (hS : S.card=r) + (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : + (sourceCoefficient T n g s center globalShift b d incoming S)^2 ≤ + 4*(3^((b+1)*r):ℕ)* + ((3^((b+1)*r):ℕ)*(η^2+ + (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ + ∑a : OccupiedWindowChoice T b S, + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩) := by + let f : OccupiedWindowChoice T b S → ℝ := fun a => + if (occupiedWindowTerm T b S a).isOdd then + sourceRoleAverage T n g s center globalShift b d incoming S a else 0 + let M : ℝ := (3^((b+1)*r):ℕ) + let E : ℝ := η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2 + let G := fun a => sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S,a⟩ + have hE : 0 ≤ E := add_nonneg (sq_nonneg _) (sq_nonneg _) + have hM : 0 ≤ M := Nat.cast_nonneg _ + have hcard : (Fintype.card (OccupiedWindowChoice T b S):ℝ) ≤ M := by + dsimp only [M] + exact_mod_cast (hS ▸ occupiedWindowChoice_card_le T b S) + have hcs : (∑a,f a)^2 ≤ (Fintype.card (OccupiedWindowChoice T b S):ℝ)*∑a,(f a)^2 := by + simpa using Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ => (1:ℝ)) f + have hs : (∑a,(f a)^2) ≤ M*E+∑a,G a := by + calc + _ ≤ ∑a : OccupiedWindowChoice T b S,(E+G a) := + Finset.sum_le_sum (fun a _ => sourceRoleSquare_split T n g s center globalShift A b r d incoming S hS a η hcap) + _ = (Fintype.card (OccupiedWindowChoice T b S):ℝ)*E+∑a,G a := by simp [Finset.sum_add_distrib] + _ ≤ M*E+∑a,G a := add_le_add (mul_le_mul_of_nonneg_right hcard hE) le_rfl + calc + _ = 4*(∑a,f a)^2 := by rw [sourceCoefficient_expansion]; dsimp only [f]; ring + _ ≤ 4*((Fintype.card (OccupiedWindowChoice T b S):ℝ)*∑a,(f a)^2) := by linarith + _ ≤ 4*(M*∑a,(f a)^2) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right hcard (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) (by norm_num) + _ ≤ 4*(M*(M*E+∑a,G a)) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left hs hM) (by norm_num) + _ = _ := by dsimp only [M,E,G]; ring + +/-- The full degree coefficient sum, including every selected monomial, +singletons, and off-center labels. This is the finite, unabsorbed version +of the manuscript's low-degree coefficient estimate. -/ +theorem sourceCoefficient_degree_energy (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) : + (∑S : DegreeLeafSubset T b r, + (sourceCoefficient T n g s center globalShift b d incoming S.val)^2) ≤ + 4*(3^((b+1)*r):ℕ)* + (((Fintype.card (WindowLeaf T (b+1))).choose r:ℕ)*(3^((b+1)*r):ℕ)* + (η^2+(sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ + degreeForcedRoleEnergy T n g s center globalShift A b r d incoming) := by + calc + _ ≤ ∑S : DegreeLeafSubset T b r, + 4*(3^((b+1)*r):ℕ)* + ((3^((b+1)*r):ℕ)*(η^2+ + (sourceNoncentralMass T n g s center globalShift A (b+1) d incoming)^2)+ + ∑a : OccupiedWindowChoice T b S.val, + sourceGoodRoleSquare T n g s center globalShift A b r d incoming ⟨S.val,a⟩) := + Finset.sum_le_sum (fun S _ => sourceCoefficient_square_bound T n g s center globalShift A b r d incoming S.val S.property η hcap) + _ = _ := by + rw [←Finset.mul_sum,Finset.sum_add_distrib,sourceGoodRoleSquare_degree_sum] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,degreeLeafSubset_card] + ring + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/ErrorRates.lean b/lean/OAI/Probability/TraceReconstruction/ErrorRates.lean index f35a9e9f17881044a45750992f5cd965e052f188..fc5a6bb40d3468bb1a2882a6f04f9db4494b81a3 100644 --- a/lean/OAI/Probability/TraceReconstruction/ErrorRates.lean +++ b/lean/OAI/Probability/TraceReconstruction/ErrorRates.lean @@ -1,967 +1,967 @@ -import OAI.Probability.TraceReconstruction.LayoutRates - -namespace OAI - -/-! -# ErrorRates - -Realization of block caps, sparse scales, sharp and smoothing budgets, tree tails, fit errors, and uniform polynomial/exponential bounds. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem sourceWindowSize_le (N : ℝ) (b j : ℕ) (ε : ℝ) (hN : 0 ≤ N) : - (sourceWindowSize N b ε j:ℝ) ≤ N^(scaleKappa b (j+1) ε) := by - have hh := Nat.floor_le (div_nonneg (Real.rpow_nonneg hN (scaleKappa b (j+1) ε)) (by norm_num : (0:ℝ) ≤ 4)) - unfold sourceWindowSize - push_cast - linarith only [hh] - --- We use only positive target scales below. -theorem SourceArithmeticBounds.scheduled_trials {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 < N) (hC : 0 < C) (hF : 0 < F) - (j : ℕ) (hj : j+1 < b) : - N^(scaleKappa b (j+2) ε+ε)/(4800*(C^(2*b)*F)) ≤ - (sourceScheduledTrials (sourceBlockWindows N b ε) (sourceArithmeticTrials C N b ε ell k) (j+1):ℝ) := by - let T := sourceBlockWindows N b ε - let n := sourceArithmeticTrials C N b ε ell k - have htbig := (H.windows (j+1) hj).1 - have hsize : (T (j+1):ℝ) ≤ N^(scaleKappa b (j+2) ε) := by - dsimp [T] - rw [sourceBlockWindows,ite_eq_left hj] - have hh := Nat.floor_le (div_nonneg (Real.rpow_nonneg hN.le (scaleKappa b (j+2) ε)) (by norm_num : (0:ℝ) ≤ 4)) - simp only [sourceWindowSize,Nat.cast_mul,Nat.cast_ofNat] - linarith only [hh] - have hx : 8 ≤ N^(scaleKappa b (j+2) ε) := by - have hh : (24:ℝ) ≤ T (j+1) := by exact_mod_cast htbig - linarith only [hh,hsize] - have hlo := (sourceWindowSize_bounds (b:=b) (j:=j+1) hx).1 - have hn := (H.trials j (by omega)).1 - have hdvd : 4 ∣ T (j+1) := by - dsimp [T] - rw [sourceBlockWindows,ite_eq_left hj,sourceWindowSize] - exact dvd_mul_right _ _ - have htlo : N^(scaleKappa b (j+2) ε)/8 ≤ ((T (j+1)/4:ℕ):ℝ) := by - rw [Nat.cast_div hdvd (by norm_num : (4:ℝ)≠0)] - have hh : (sourceWindowSize N b ε (j+1):ℝ)=(T (j+1):ℝ) := by simp [T,sourceBlockWindows,hj] - rw [hh] at hlo - linarith only [hlo] - rw [sourceScheduledTrials,Nat.cast_mul,Real.rpow_add hN] - calc - _ = (N^(scaleKappa b (j+2) ε)/8)*(N^ε/(600*(C^(2*b)*F))) := by ring - _ ≤ _ := mul_le_mul htlo hn (by positivity) (by positivity) - -theorem SourceArithmeticBounds.binomial_caps {C N F ε ω : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 < N) - (hC : 1 ≤ C) (hF : 1 ≤ F) (hω : 0 < ω) : - (∀j - change Fintype.card (Fin 1) ≤ ell - simpa using hell - | succ b ih => - rw [sourceLeafCount_succ,sourceBlockLength] - exact Nat.mul_le_mul (hPT b (by omega)) (ih (fun j hj=>hPT j (by omega))) - -theorem sourceArithmeticLength_eq_block (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : - sourceArithmeticLength C N b ε ell k j= - sourceBlockLength (sourceArithmeticP C N b ε ell k) ell j := by - induction j with - | zero => rfl - | succ j ih => rw [sourceArithmeticLength_step,sourceBlockLength,ih,mul_comm] - -theorem SourceArithmeticBounds.leaf_bound {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 < N) : - (SourceLeafCount (sourceBlockWindows N b ε) b:ℝ) ≤ N := by - have hell : 1 ≤ ell := by - have hh := (H.lengths 0 (Nat.zero_le _)).1 - rw [show sourceArithmeticLength C N b ε ell k 0=ell by rfl] at hh - have hp : 0 < N^(scaleA b 0 ε)/2 := by positivity - have he : (0:ℝ)Nat.le_trans (by omega : sourceBlockWindows N b ε j ≤ 2*sourceBlockWindows N b ε j) - (H.windows j hj).2.2.1) - have hh' : (SourceLeafCount (sourceBlockWindows N b ε) b:ℝ) ≤ - sourceArithmeticLength C N b ε ell k b := by - rw [sourceArithmeticLength_eq_block] - exact_mod_cast hh - apply hh'.trans - simpa only [scaleA_top,Real.rpow_one] using (H.lengths b le_rfl).2 - -/-- Full sparse degree, with the excluded bottom window and the exact - source gap. This is the high-degree geometric gain, before constants. -/ -theorem source_sparse_weight_bound (N ε d W w : ℝ) (b s : ℕ) (hN : 0 < N) (hW : 0 ≤ W) - (hw : w^2 ≤ W*N^(-scaleA b 0 ε*d)) : - w^2*(sourceSparseCount (sourceBlockWindows N b ε) s (b-1):ℝ) ≤ - W*((2^s:ℕ):ℝ)*N^(-(scaleA b 0 ε*d-sourceInteriorExponent b ε)) := by - have hr : N^(-scaleA b 0 ε*d)*N^(sourceInteriorExponent b ε)= - N^(-(scaleA b 0 ε*d-sourceInteriorExponent b ε)) := by - rw [←Real.rpow_add hN] - congr 1 - ring - calc - _ ≤ (W*N^(-scaleA b 0 ε*d))*(((2^s:ℕ):ℝ)*N^(sourceInteriorExponent b ε)) := - mul_le_mul hw (sourceSparseCount_scale N b s ε hN) (by positivity) (by positivity) - _ = (W*((2^s:ℕ):ℝ))*(N^(-scaleA b 0 ε*d)*N^(sourceInteriorExponent b ε)) := by ring - _ = _ := by rw [hr] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def sourceBadRoleFactor (b R : ℕ) : ℝ := - ∑r∈Finset.range R,4*((3^((b+1)*r):ℕ):ℝ)^2 - -def sourceForcedRoleFactor (b R : ℕ) : ℝ := - ∑r∈Finset.range R,4*((3^((b+1)*r):ℕ):ℝ)*(OccupiedParityTree.shapeRoleConstant r (b+1):ℝ) - -/-- Explicit finite sharp energy bound. The two undesirable pattern classes - are suppressed by eta and a, and the genuine binary forced skeleton pays - its full source exponent. The high tail uses the sparse, not dense count. -/ -theorem source_sharp_numeric (T n : ℕ→ℕ) (s b R : ℕ) (ω η a w N ε d K W Q gap : ℝ) - (hN : 1 ≤ N) (hK : 0 ≤ K) (hW : 0 ≤ W) (_hQ : 0 ≤ Q) - (hleaves : (SourceLeafCount T (b+1):ℝ) ≤ N) (hwone : w^2 ≤ 1) - (hw : w^2 ≤ W*N^(-scaleA (b+1) 0 ε*d)) - (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) - (hhalf : w^2*(sourceSparseCount T s b:ℝ) ≤ 1/2) - (hsparse : w^2*(sourceSparseCount T s b:ℝ) ≤ Q*N^(-gap)) - (hn : ∀j≤b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) - (hg : ∀j change 1 ≤ Fintype.card (Fin 1); simp - | succ b ih => - rw [sourceLeafCount_succ] - exact one_le_mul_of_one_le_of_one_le (hT b (by omega)) (ih (fun j hj=>hT j (by omega))) - -theorem sourceFitTail_simple {T n : ℕ → ℕ} {b : ℕ} {v : ℝ} - (hT : ∀j simp [sourceFitTail] - | one => simp only [sourceFitTail]; positivity - | more b _ ih => - have hi := ih (fun j hj=>hT j (by omega)) (fun j hj=>hv j (by omega)) - have hleaf : (1:ℝ) ≤ SourceLeafCount T (b+1) := by - exact_mod_cast sourceLeafCount_positive (fun j hj=>hT j (show j change Fintype.card PEmpty ≤ _; simp - | succ b ih => - have hi := ih (fun j hj=>hT j (by omega)) - have hp := sourceLeafCount_positive (b:=b) (fun j hj=>hT j (show j exact PEmpty.elim v - | succ b ih => - rcases v with a | ⟨u,v⟩ - · cases a - · exact Or.inr (hn b (by omega)) - · exact hg b (by omega) - · exact ih (fun j hj=>hn j (by omega)) (fun j hj=>hg j (by omega)) v - -theorem sourceEffectiveHiddenTail_simple {T n : ℕ→ℕ} {b : ℕ} {M ω : ℝ} - (hT : ∀jhh v)).trans - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - apply mul_le_mul_of_nonneg_right _ (Real.exp_pos _).le - exact_mod_cast windowCollection_card_bound hT - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The literal centering fluctuation has the source epsilon exponent. - This does not treat nested window starts as independent. -/ -theorem SourceArithmeticBounds.fit_exponent {C N F ε : ℝ} {s b ell k j : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hC : 0c) := by - refine ⟨|c|,abs_nonneg _,0,?_⟩ - intro D - simpa using le_abs_self c - -theorem SourcePolyUpper.depth : SourcePolyUpper (fun D=>(D:ℝ)+1) := by - exact ⟨1,zero_le_one,1,by simp⟩ - -theorem SourcePolyUpper.mono {f g : ℕ→ℝ} (hg : SourcePolyUpper g) (hf : ∀D,f D ≤ g D) : - SourcePolyUpper f := by - obtain ⟨C,hC,h,H⟩ := hg - exact ⟨C,hC,h,fun D=>(hf D).trans (H D)⟩ - -theorem SourcePolyUpper.add {f g : ℕ→ℝ} (hf : SourcePolyUpper f) (hg : SourcePolyUpper g) : - SourcePolyUpper (fun D=>f D+g D) := by - obtain ⟨C,hC,h,H⟩ := hf - obtain ⟨K,hK,k,G⟩ := hg - refine ⟨C+K,add_nonneg hC hK,h+k,?_⟩ - intro D - have hd : 1 ≤ (D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] - have hh := (H D).trans (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h ≤ h+k)) hC) - have hk := (G D).trans (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k ≤ h+k)) hK) - nlinarith only [hh,hk] - -theorem SourcePolyUpper.mul {f g : ℕ→ℝ} (hf : SourcePolyUpper f) (hg : SourcePolyUpper g) - (hf0 : ∀D,0 ≤ f D) (hg0 : ∀D,0 ≤ g D) : SourcePolyUpper (fun D=>f D*g D) := by - obtain ⟨C,hC,h,H⟩ := hf - obtain ⟨K,hK,k,G⟩ := hg - refine ⟨C*K,mul_nonneg hC hK,h+k,?_⟩ - intro D - calc - f D*g D ≤ (C*((D:ℝ)+1)^h)*(K*((D:ℝ)+1)^k) := - mul_le_mul (H D) (G D) (hg0 D) ((hf0 D).trans (H D)) - _ = _ := by rw [pow_add]; ring - -theorem SourcePolyUpper.pow {f : ℕ→ℝ} (hf : SourcePolyUpper f) (hf0 : ∀D,0 ≤ f D) (r : ℕ) : - SourcePolyUpper (fun D=>(f D)^r) := by - obtain ⟨C,hC,h,H⟩ := hf - refine ⟨C^r,pow_nonneg hC _,h*r,?_⟩ - intro D - simpa only [mul_pow,pow_mul] using pow_le_pow_left₀ (hf0 D) (H D) r - -theorem sourceEpsilon_inverse_poly (B : ℕ) : - SourcePolyUpper (fun D=>(sourceEpsilon B D)⁻¹) := by - refine ⟨(2:ℝ)^(4*B+100),by positivity,1,?_⟩ - intro D - simp only [sourceEpsilon,one_div,inv_inv,pow_one] - exact le_rfl - -theorem totalScoreExponent_poly (B : ℕ) (hB : 2 ≤ B) : - SourcePolyUpper (totalScoreExponent B) := by - apply (SourcePolyUpper.const 3 |>.add - (SourcePolyUpper.depth.mul (SourcePolyUpper.const (B:ℝ)) (fun D=>by positivity) (fun _=>by positivity))).mono - intro D - have hh := (totalScoreExponent_bounds B D hB).2 - nlinarith only [hh,Nat.cast_nonneg B (α:=ℝ)] - -theorem SourcePolyUpper.ceil {f : ℕ→ℝ} (hf : SourcePolyUpper f) (hf0 : ∀D,0 ≤ f D) : - SourcePolyUpper (fun D=>(⌈f D⌉₊:ℝ)) := by - apply (hf.add (SourcePolyUpper.const 1)).mono - intro D - exact (Nat.ceil_lt_add_one (hf0 D)).le - -theorem sourceCancellationOrder_poly (B : ℕ) (hB : 2 ≤ B) : - SourcePolyUpper (fun D=>(sourceCancellationOrder B D:ℝ)) := by - let f := fun D=>totalScoreExponent B D+(sourceDegreeCutoff B:ℝ)+B+10 - have hf : SourcePolyUpper f := (((totalScoreExponent_poly B hB).add - (SourcePolyUpper.const (sourceDegreeCutoff B:ℝ))).add (SourcePolyUpper.const (B:ℝ))).add - (SourcePolyUpper.const 10) - have hf0 (D) : 0 ≤ f D := by - have hd := (totalScoreExponent_bounds B D hB).1 - have hr : 0 ≤ (sourceDegreeCutoff B:ℝ) := Nat.cast_nonneg _ - dsimp [f] - linarith only [hd,hr,Nat.cast_nonneg B (α:=ℝ)] - have hh := ((SourcePolyUpper.const 100).mul hf (fun _=>by norm_num) hf0).mul - (sourceEpsilon_inverse_poly B) (fun D=>mul_nonneg (by norm_num) (hf0 D)) - (fun D=>(inv_pos.mpr (sourceEpsilon_pos B D)).le) - have hc := hh.ceil (fun D=>mul_nonneg (mul_nonneg (by norm_num) (hf0 D)) - (inv_pos.mpr (sourceEpsilon_pos B D)).le) - simpa only [sourceCancellationOrder,f,div_eq_mul_inv] using hc - -theorem sourceCancellationOrder_large (B D : ℕ) : - 100*(totalScoreExponent B D+(sourceDegreeCutoff B:ℝ)+B+10) ≤ - (sourceCancellationOrder B D:ℝ)*sourceEpsilon B D := by - exact (div_le_iff₀ (sourceEpsilon_pos B D)).mp (Nat.le_ceil _) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- Literal finite-block factors are subpower uniformly over the joint - deletion regime when their logarithms grow polynomially in the depth. -/ -def SourceExpUpper (f : ℕ→ℝ→ℝ) : Prop := - ∃ C : ℝ,0 ≤ C ∧ ∃ h : ℕ,∀D q,q∈Set.Ioc 0 (1/2:ℝ) → - f D q ≤ Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ)) - -theorem SourcePolyUpper.expUpper {f : ℕ→ℝ} (hf : SourcePolyUpper f) : - SourceExpUpper (fun D _=>f D) := by - obtain ⟨C,hC,h,H⟩ := hf - refine ⟨C,hC,h,?_⟩ - intro D q hq - have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ - have hmul := mul_le_mul_of_nonneg_left hΛ (show 0 ≤ C*((D:ℝ)+1)^h by positivity) - exact (H D).trans ((by linarith only [hmul] : C*((D:ℝ)+1)^h ≤ C*((D:ℝ)+1)^h*q^(-3:ℤ)+1).trans - (Real.add_one_le_exp _)) - -theorem SourceExpUpper.const (c : ℝ) : SourceExpUpper (fun _ _=>c) := - (SourcePolyUpper.const c).expUpper - -theorem SourceExpUpper.mono {f g : ℕ→ℝ→ℝ} (hg : SourceExpUpper g) - (hf : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → f D q ≤ g D q) : SourceExpUpper f := by - obtain ⟨C,hC,h,H⟩ := hg - exact ⟨C,hC,h,fun D q hq=>(hf D q hq).trans (H D q hq)⟩ - -theorem SourceExpUpper.mul {f g : ℕ→ℝ→ℝ} (hf : SourceExpUpper f) (hg : SourceExpUpper g) - (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) - (hg0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ g D q) : - SourceExpUpper (fun D q=>f D q*g D q) := by - obtain ⟨C,hC,h,H⟩ := hf - obtain ⟨K,hK,k,G⟩ := hg - refine ⟨C+K,add_nonneg hC hK,h+k,?_⟩ - intro D q hq - have hΛ : 0 ≤ q^(-3:ℤ) := (zpow_pos hq.1 _).le - have hd : 1 ≤ (D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] - have hh := mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h≤h+k)) hC) hΛ - have hk := mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k≤h+k)) hK) hΛ - calc - _ ≤ Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ))*Real.exp (K*((D:ℝ)+1)^k*q^(-3:ℤ)) := - mul_le_mul (H D q hq) (G D q hq) (hg0 D q hq) ((hf0 D q hq).trans (H D q hq)) - _ ≤ _ := by rw [←Real.exp_add]; apply Real.exp_le_exp.mpr; nlinarith only [hh,hk] - -theorem SourceExpUpper.pow_variably {f : ℕ→ℝ→ℝ} {r : ℕ→ℕ} (hf : SourceExpUpper f) - (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) - (hr : SourcePolyUpper (fun D=>(r D:ℝ))) : SourceExpUpper (fun D q=>(f D q)^(r D)) := by - obtain ⟨C,hC,h,H⟩ := hf - obtain ⟨K,hK,k,G⟩ := hr - refine ⟨C*K,mul_nonneg hC hK,h+k,?_⟩ - intro D q hq - have hΛ : 0≤q^(-3:ℤ) := (zpow_pos hq.1 _).le - have hh := mul_le_mul_of_nonneg_right (G D) (show 0≤C*((D:ℝ)+1)^h*q^(-3:ℤ) by positivity) - calc - _ ≤ (Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ)))^(r D) := pow_le_pow_left₀ (hf0 D q hq) (H D q hq) _ - _ = Real.exp ((r D:ℝ)*(C*((D:ℝ)+1)^h*q^(-3:ℤ))) := (Real.exp_nat_mul _ _).symm - _ ≤ _ := by apply Real.exp_le_exp.mpr; rw [pow_add]; nlinarith only [hh] - -theorem SourceExpUpper.pow {f : ℕ→ℝ→ℝ} (hf : SourceExpUpper f) - (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) (r : ℕ) : - SourceExpUpper (fun D q=>(f D q)^r) := - hf.pow_variably hf0 (SourcePolyUpper.const (r:ℝ)) - -theorem sourceOverlapConstant_expUpper : SourceExpUpper (fun _ q=>sourceOverlapConstant q) := by - refine ⟨sourceChannelLogConstant,sourceChannelLogConstant_pos.le,0,?_⟩ - intro D q hq - simp only [pow_zero,mul_one] - apply (Real.log_le_iff_le_exp (sourceOverlapConstant_pos hq.1)).mp - exact sourceOverlapConstant_log_bound ⟨hq.1,by linarith only [hq.2]⟩ - -theorem initialOverlapLower_inverse_expUpper : SourceExpUpper (fun _ q=>(initialOverlapLower q)⁻¹) := by - refine ⟨1536+(32+3*primitivePeriodConstant),by unfold primitivePeriodConstant; positivity,0,?_⟩ - intro D q hq - have hp := initialOverlapLower_pos q - have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ - rw [←Real.log_le_iff_le_exp (inv_pos.mpr hp),Real.log_inv,initialOverlapLower, - Real.log_div (Real.exp_pos _).ne' (by norm_num),Real.log_exp] - simp only [pow_zero,mul_one,zpow_neg,zpow_ofNat] at hΛ ⊢ - have hh := Real.log_le_self (by norm_num : (0:ℝ)≤1536) - have hmul := mul_le_mul_of_nonneg_left hΛ (by norm_num : (0:ℝ)≤1536) - simp only [div_eq_mul_inv] at * - nlinarith only [hh,hmul] - -/-- All indices are inside the same physical n,q instance. -/ -theorem SourceExpUpper.uniform (f : ℕ→ℝ→ℝ) (hf : SourceExpUpper f) - (B : ℕ) (ζ δ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) (hδ : 0<δ) - {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) - (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀i,f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t) ≤ - (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^( - δ*sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by - obtain ⟨C,hC,h,H⟩ := hf - have hrel (t) : Real.log (n t)=(q t)^(-3:ℤ)*((q t)^3*Real.log (n t)) := by - rw [zpow_neg,zpow_ofNat] - field_simp [(hq t).1.ne'] - filter_upwards [source_uniform_exp_absorption B h ζ C δ hB hζ hC hδ hn hH - (fun t=>zpow_pos (hq t).1 _) hrel] with t ht i - exact (H _ _ (hq t)).trans (ht i) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -def sourceMomentEnvelope (B D : ℕ) : ℝ := - ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1)*((D:ℝ)+1)*2^(B*D) - -def sourceCapEnvelope (B D : ℕ) (q : ℝ) : ℝ := - 200*(sourceOverlapConstant q)^(2*B*(D+1)+2)*(initialOverlapLower q)⁻¹ - -def sourceWeightEnvelope (B D : ℕ) : ℝ := 144*(sourceMomentEnvelope B D)^2 - -theorem sourceMomentEnvelope_pos (B D : ℕ) : 0 < sourceMomentEnvelope B D := by - unfold sourceMomentEnvelope - positivity - -theorem sourceCapEnvelope_pos (B D : ℕ) {q : ℝ} (hq : 0sourceMomentEnvelope B D) := by - have hr : SourcePolyUpper (fun D=>((B*D:ℕ):ℝ)) := by - apply ((SourcePolyUpper.const (B:ℝ)).mul SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).mono - intro D - push_cast - nlinarith only [Nat.cast_nonneg B (α:=ℝ)] - have hpow := (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hr - have hp := ((SourcePolyUpper.const ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1)).mul - SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).expUpper - exact hp.mul hpow (fun _ _ _=>by positivity) (fun _ _ _=>by positivity) - -theorem sourceCapEnvelope_expUpper (B : ℕ) : SourceExpUpper (sourceCapEnvelope B) := by - have hr : SourcePolyUpper (fun D=>((2*B*(D+1)+2:ℕ):ℝ)) := by - have hp := ((SourcePolyUpper.const ((2*B:ℕ):ℝ)).mul SourcePolyUpper.depth - (fun _=>by positivity) (fun _=>by positivity)).add (SourcePolyUpper.const 2) - simpa only [Nat.cast_mul,Nat.cast_add,Nat.cast_one,Nat.cast_ofNat] using hp - have hc := sourceOverlapConstant_expUpper.pow_variably (fun _ q hq=>(sourceOverlapConstant_pos hq.1).le) hr - exact ((SourceExpUpper.const 200).mul hc (fun _ _ _=>by norm_num) - (fun _ q hq=>pow_nonneg (sourceOverlapConstant_pos hq.1).le _)).mul initialOverlapLower_inverse_expUpper - (fun _ q hq=>by positivity [sourceOverlapConstant_pos hq.1]) - (fun _ q _=>(inv_pos.mpr (initialOverlapLower_pos q)).le) - -theorem sourceWeightEnvelope_expUpper (B : ℕ) : SourceExpUpper (fun D _=>sourceWeightEnvelope B D) := by - exact (SourceExpUpper.const 144).mul - ((sourceMomentEnvelope_expUpper B).pow (fun D _ _=>(sourceMomentEnvelope_pos B D).le) 2) - (fun _ _ _=>by norm_num) (fun _ _ _=>sq_nonneg _) - -theorem sourceMotif_expUpper (B : ℕ) (hB : 2 ≤ B) : - SourceExpUpper (fun D _=>(2:ℝ)^(sourceCancellationOrder B D)) := - (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) (sourceCancellationOrder_poly B hB) - -theorem sourceSmoothingPrefactor_expUpper (B : ℕ) (hB : 2 ≤ B) : - SourceExpUpper (fun D q=>sourceSmoothingPrefactor (sourceCancellationOrder B D) (sourceCapEnvelope B D q)) := by - let s := sourceCancellationOrder B - have hs := sourceCancellationOrder_poly B hB - have hs0 (D) : 0 ≤ (s D:ℝ) := Nat.cast_nonneg _ - have hp : SourcePolyUpper (fun D=>((s D*s D+s D:ℕ):ℝ)) := by - simpa only [Nat.cast_add,Nat.cast_mul] using (hs.mul hs hs0 hs0).add hs - have ht : SourcePolyUpper (fun D=>((s D+1:ℕ):ℝ)) := by - simpa only [Nat.cast_add,Nat.cast_one] using hs.add (SourcePolyUpper.const 1) - have hone := (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hp - have htwo := ((ht.expUpper).mul (sourceCapEnvelope_expUpper B) - (fun _ _ _=>Nat.cast_nonneg _) (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le)).pow_variably - (fun D q hq=>mul_nonneg (Nat.cast_nonneg _) (sourceCapEnvelope_pos B D hq.1).le) ht - have H := hone.mul htwo (fun _ _ _=>by positivity) - (fun D q hq=>pow_nonneg (mul_nonneg (Nat.cast_nonneg _) (sourceCapEnvelope_pos B D hq.1).le) _) - simpa only [sourceSmoothingPrefactor,s,Nat.cast_add,Nat.cast_one] using H - -theorem sourceSkeletonPrefactor_expUpper (B b : ℕ) (hB : 2 ≤ B) : - SourceExpUpper (fun D q=>sourceSkeletonPrefactor (sourceCancellationOrder B D) b (sourceCapEnvelope B D q)) := by - have hL := sourceMotif_expUpper B hB - have hK := sourceCapEnvelope_expUpper B - have hA := ((SourceExpUpper.const 2).mul (hL.pow (fun _ _ _=>by positivity) 3) - (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity)).mul hK - (fun _ _ _=>by positivity) (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le) - have hF := ((SourceExpUpper.const 4).mul (hL.pow (fun _ _ _=>by positivity) 6) - (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity)).mul - (hK.pow (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le) 2) - (fun _ _ _=>by positivity) (fun _ _ _=>sq_nonneg _) - have H := hA.mul (hF.pow (fun _ _ _=>by positivity) (2^b-1)) - (fun D q hq=>by positivity [sourceCapEnvelope_pos B D hq.1]) (fun _ _ _=>by positivity) - simpa only [sourceSkeletonPrefactor,binaryTreeBudget_const,Nat.cast_pow,Nat.cast_ofNat] using H - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem SourceArithmeticBounds.fit_tail {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hC : 0(by omega : 1≤24).trans (H.windows j hj).1) - (fun j hj=>H.fit_exponent hC hF hN he hκ hj)).trans - have hh := mul_le_mul_of_nonneg_left (H.leaf_bound hN0) (show 0≤2*(b:ℝ) by positivity) - exact mul_le_mul_of_nonneg_right hh (Real.exp_pos _).le - -theorem SourceArithmeticBounds.metadata_tail {C N F ε ω : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0(by omega : 1≤24).trans (H.windows j hj).1) - (fun j hj=>(H.trials j hj).1) ?_).trans - · exact mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_left (H.leaf_bound hN) (show 0≤2*(b:ℝ) by positivity)) (Real.exp_pos _).le - · intro j hj - cases j with - | zero => exact Or.inl rfl - | succ j => - right - rw [sourceScheduledTrials,Nat.cast_mul] - have ht := (H.windows (j+1) hj).1 - have hd : 1 ≤ sourceBlockWindows N b ε (j+1)/4 := by omega - have hd' : (1:ℝ) ≤ (sourceBlockWindows N b ε (j+1)/4:ℕ) := by exact_mod_cast hd - exact (H.trials j (by omega)).1.trans - (le_mul_of_one_le_left (Nat.cast_nonneg _) hd') - -/-- Quantitative clipping without any default-limit increase or limiting - interchange: the power is the finite even moment actually used by the oracle. -/ -theorem source_clipping_moment_power (T : ℕ→ℕ) (s b k : ℕ) (N gap L : ℝ) - (hN : 0f D q+g D q) := by - obtain ⟨C,hC,h,H⟩ := hf - obtain ⟨K,hK,k,G⟩ := hg - refine ⟨C+K+1,by positivity,h+k,?_⟩ - intro D q hq - have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ - have hd : 1≤(D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] - have hh := mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h≤h+k)) hC) (by linarith only [hΛ] : 0≤q^(-3:ℤ)) - have hk := mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k≤h+k)) hK) (by linarith only [hΛ] : 0≤q^(-3:ℤ)) - have hz : 1≤((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := one_le_mul_of_one_le_of_one_le (one_le_pow₀ hd) hΛ - have hc0 : 0≤C*((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := by positivity - have hk0 : 0≤K*((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := by positivity - have he1 : f D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) := - (H D q hq).trans (Real.exp_le_exp.mpr (by nlinarith only [hh,hk0])) - have he2 : g D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) := - (G D q hq).trans (Real.exp_le_exp.mpr (by nlinarith only [hk,hc0])) - have he := Real.add_one_le_exp (((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) - have he' := mul_le_mul_of_nonneg_left (show 2≤Real.exp (((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) by linarith only [he,hz]) - (Real.exp_pos ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ))).le - rw [←Real.exp_add] at he' - convert (show f D q+g D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)+((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) by linarith only [he1,he2,he']) using 1 - congr 1 - ring - -def sourceScaleInverseEnvelope (B D : ℕ) : ℝ := 2*(2:ℝ)^(B*D) - -theorem sourceScaleInverseEnvelope_expUpper (B : ℕ) : SourceExpUpper (fun D _=>sourceScaleInverseEnvelope B D) := by - have hr : SourcePolyUpper (fun D=>((B*D:ℕ):ℝ)) := by - apply ((SourcePolyUpper.const (B:ℝ)).mul SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).mono - intro D - push_cast - nlinarith only [Nat.cast_nonneg B (α:=ℝ)] - exact (SourceExpUpper.const 2).mul ((SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hr) - (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity) - -theorem source_log_scale_lower (B D i : ℕ) {n : ℝ} (hB : 2≤B) (hn : 1(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀i,f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)*Real.log (n t) ≤ - (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^ - (δ*sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by - let g := fun D q=>f D q*sourceScaleInverseEnvelope B D*(2/δ)*(sourceEpsilon B D)⁻¹ - have hg : SourceExpUpper g := - ((hf.mul (sourceScaleInverseEnvelope_expUpper B) hf0 (fun _ _ _=>by unfold sourceScaleInverseEnvelope; positivity)).mul - (SourceExpUpper.const (2/δ)) (fun D q hq=>by unfold sourceScaleInverseEnvelope; positivity [hf0 D q hq]) (fun _ _ _=>by positivity)).mul - (sourceEpsilon_inverse_poly B).expUpper (fun D q hq=>by unfold sourceScaleInverseEnvelope; positivity [hf0 D q hq]) - (fun D _ _=>(inv_pos.mpr (sourceEpsilon_pos B D)).le) - have hu := SourceExpUpper.uniform g hg B ζ (δ/2) hB hζ (by positivity) hn hq hH - filter_upwards [hu,hn.eventually_gt_atTop 1] with t ht hnt - intro i - let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) - let N := sourceTargetScale B D (n t) i - let ε := sourceEpsilon B D - have he : 0<ε := sourceEpsilon_pos B D - have hN : 0(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀i, - g (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)* - Real.exp (-(sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^ - (sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t))))/ - f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)) ≤ - (n t)^(-(h (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t))) := by - have hfu := SourceExpUpper.uniform f hf B ζ (1/4) hB hζ (by norm_num) hn hq hH - have hgu := SourceExpUpper.uniform g hg B ζ (1/4) hB hζ (by norm_num) hn hq hH - have hhu := hh.uniform_log hh0 B ζ (1/4) hB hζ (by norm_num) hn hq hH - have hcu := SourceExpUpper.uniform _ (SourceExpUpper.const 2) B ζ (1/4) hB hζ (by norm_num) hn hq hH - filter_upwards [hfu,hgu,hhu,hcu,hn.eventually_gt_atTop 1] with t hft hgt hht hct hnt - intro i - let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) - let N := sourceTargetScale B D (n t) i - let ε := sourceEpsilon B D - let X := N^((1/4)*ε) - have hN : 0 + change Fintype.card (Fin 1) ≤ ell + simpa using hell + | succ b ih => + rw [sourceLeafCount_succ,sourceBlockLength] + exact Nat.mul_le_mul (hPT b (by omega)) (ih (fun j hj=>hPT j (by omega))) + +theorem sourceArithmeticLength_eq_block (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : + sourceArithmeticLength C N b ε ell k j= + sourceBlockLength (sourceArithmeticP C N b ε ell k) ell j := by + induction j with + | zero => rfl + | succ j ih => rw [sourceArithmeticLength_step,sourceBlockLength,ih,mul_comm] + +theorem SourceArithmeticBounds.leaf_bound {C N F ε : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 < N) : + (SourceLeafCount (sourceBlockWindows N b ε) b:ℝ) ≤ N := by + have hell : 1 ≤ ell := by + have hh := (H.lengths 0 (Nat.zero_le _)).1 + rw [show sourceArithmeticLength C N b ε ell k 0=ell by rfl] at hh + have hp : 0 < N^(scaleA b 0 ε)/2 := by positivity + have he : (0:ℝ)Nat.le_trans (by omega : sourceBlockWindows N b ε j ≤ 2*sourceBlockWindows N b ε j) + (H.windows j hj).2.2.1) + have hh' : (SourceLeafCount (sourceBlockWindows N b ε) b:ℝ) ≤ + sourceArithmeticLength C N b ε ell k b := by + rw [sourceArithmeticLength_eq_block] + exact_mod_cast hh + apply hh'.trans + simpa only [scaleA_top,Real.rpow_one] using (H.lengths b le_rfl).2 + +/-- Full sparse degree, with the excluded bottom window and the exact + source gap. This is the high-degree geometric gain, before constants. -/ +theorem source_sparse_weight_bound (N ε d W w : ℝ) (b s : ℕ) (hN : 0 < N) (hW : 0 ≤ W) + (hw : w^2 ≤ W*N^(-scaleA b 0 ε*d)) : + w^2*(sourceSparseCount (sourceBlockWindows N b ε) s (b-1):ℝ) ≤ + W*((2^s:ℕ):ℝ)*N^(-(scaleA b 0 ε*d-sourceInteriorExponent b ε)) := by + have hr : N^(-scaleA b 0 ε*d)*N^(sourceInteriorExponent b ε)= + N^(-(scaleA b 0 ε*d-sourceInteriorExponent b ε)) := by + rw [←Real.rpow_add hN] + congr 1 + ring + calc + _ ≤ (W*N^(-scaleA b 0 ε*d))*(((2^s:ℕ):ℝ)*N^(sourceInteriorExponent b ε)) := + mul_le_mul hw (sourceSparseCount_scale N b s ε hN) (by positivity) (by positivity) + _ = (W*((2^s:ℕ):ℝ))*(N^(-scaleA b 0 ε*d)*N^(sourceInteriorExponent b ε)) := by ring + _ = _ := by rw [hr] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def sourceBadRoleFactor (b R : ℕ) : ℝ := + ∑r∈Finset.range R,4*((3^((b+1)*r):ℕ):ℝ)^2 + +def sourceForcedRoleFactor (b R : ℕ) : ℝ := + ∑r∈Finset.range R,4*((3^((b+1)*r):ℕ):ℝ)*(OccupiedParityTree.shapeRoleConstant r (b+1):ℝ) + +/-- Explicit finite sharp energy bound. The two undesirable pattern classes + are suppressed by eta and a, and the genuine binary forced skeleton pays + its full source exponent. The high tail uses the sparse, not dense count. -/ +theorem source_sharp_numeric (T n : ℕ→ℕ) (s b R : ℕ) (ω η a w N ε d K W Q gap : ℝ) + (hN : 1 ≤ N) (hK : 0 ≤ K) (hW : 0 ≤ W) (_hQ : 0 ≤ Q) + (hleaves : (SourceLeafCount T (b+1):ℝ) ≤ N) (hwone : w^2 ≤ 1) + (hw : w^2 ≤ W*N^(-scaleA (b+1) 0 ε*d)) + (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) + (hhalf : w^2*(sourceSparseCount T s b:ℝ) ≤ 1/2) + (hsparse : w^2*(sourceSparseCount T s b:ℝ) ≤ Q*N^(-gap)) + (hn : ∀j≤b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) + (hg : ∀j change 1 ≤ Fintype.card (Fin 1); simp + | succ b ih => + rw [sourceLeafCount_succ] + exact one_le_mul_of_one_le_of_one_le (hT b (by omega)) (ih (fun j hj=>hT j (by omega))) + +theorem sourceFitTail_simple {T n : ℕ → ℕ} {b : ℕ} {v : ℝ} + (hT : ∀j simp [sourceFitTail] + | one => simp only [sourceFitTail]; positivity + | more b _ ih => + have hi := ih (fun j hj=>hT j (by omega)) (fun j hj=>hv j (by omega)) + have hleaf : (1:ℝ) ≤ SourceLeafCount T (b+1) := by + exact_mod_cast sourceLeafCount_positive (fun j hj=>hT j (show j change Fintype.card PEmpty ≤ _; simp + | succ b ih => + have hi := ih (fun j hj=>hT j (by omega)) + have hp := sourceLeafCount_positive (b:=b) (fun j hj=>hT j (show j exact PEmpty.elim v + | succ b ih => + rcases v with a | ⟨u,v⟩ + · cases a + · exact Or.inr (hn b (by omega)) + · exact hg b (by omega) + · exact ih (fun j hj=>hn j (by omega)) (fun j hj=>hg j (by omega)) v + +theorem sourceEffectiveHiddenTail_simple {T n : ℕ→ℕ} {b : ℕ} {M ω : ℝ} + (hT : ∀jhh v)).trans + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + apply mul_le_mul_of_nonneg_right _ (Real.exp_pos _).le + exact_mod_cast windowCollection_card_bound hT + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The literal centering fluctuation has the source epsilon exponent. + This does not treat nested window starts as independent. -/ +theorem SourceArithmeticBounds.fit_exponent {C N F ε : ℝ} {s b ell k j : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (hC : 0c) := by + refine ⟨|c|,abs_nonneg _,0,?_⟩ + intro D + simpa using le_abs_self c + +theorem SourcePolyUpper.depth : SourcePolyUpper (fun D=>(D:ℝ)+1) := by + exact ⟨1,zero_le_one,1,by simp⟩ + +theorem SourcePolyUpper.mono {f g : ℕ→ℝ} (hg : SourcePolyUpper g) (hf : ∀D,f D ≤ g D) : + SourcePolyUpper f := by + obtain ⟨C,hC,h,H⟩ := hg + exact ⟨C,hC,h,fun D=>(hf D).trans (H D)⟩ + +theorem SourcePolyUpper.add {f g : ℕ→ℝ} (hf : SourcePolyUpper f) (hg : SourcePolyUpper g) : + SourcePolyUpper (fun D=>f D+g D) := by + obtain ⟨C,hC,h,H⟩ := hf + obtain ⟨K,hK,k,G⟩ := hg + refine ⟨C+K,add_nonneg hC hK,h+k,?_⟩ + intro D + have hd : 1 ≤ (D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] + have hh := (H D).trans (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h ≤ h+k)) hC) + have hk := (G D).trans (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k ≤ h+k)) hK) + nlinarith only [hh,hk] + +theorem SourcePolyUpper.mul {f g : ℕ→ℝ} (hf : SourcePolyUpper f) (hg : SourcePolyUpper g) + (hf0 : ∀D,0 ≤ f D) (hg0 : ∀D,0 ≤ g D) : SourcePolyUpper (fun D=>f D*g D) := by + obtain ⟨C,hC,h,H⟩ := hf + obtain ⟨K,hK,k,G⟩ := hg + refine ⟨C*K,mul_nonneg hC hK,h+k,?_⟩ + intro D + calc + f D*g D ≤ (C*((D:ℝ)+1)^h)*(K*((D:ℝ)+1)^k) := + mul_le_mul (H D) (G D) (hg0 D) ((hf0 D).trans (H D)) + _ = _ := by rw [pow_add]; ring + +theorem SourcePolyUpper.pow {f : ℕ→ℝ} (hf : SourcePolyUpper f) (hf0 : ∀D,0 ≤ f D) (r : ℕ) : + SourcePolyUpper (fun D=>(f D)^r) := by + obtain ⟨C,hC,h,H⟩ := hf + refine ⟨C^r,pow_nonneg hC _,h*r,?_⟩ + intro D + simpa only [mul_pow,pow_mul] using pow_le_pow_left₀ (hf0 D) (H D) r + +theorem sourceEpsilon_inverse_poly (B : ℕ) : + SourcePolyUpper (fun D=>(sourceEpsilon B D)⁻¹) := by + refine ⟨(2:ℝ)^(4*B+100),by positivity,1,?_⟩ + intro D + simp only [sourceEpsilon,one_div,inv_inv,pow_one] + exact le_rfl + +theorem totalScoreExponent_poly (B : ℕ) (hB : 2 ≤ B) : + SourcePolyUpper (totalScoreExponent B) := by + apply (SourcePolyUpper.const 3 |>.add + (SourcePolyUpper.depth.mul (SourcePolyUpper.const (B:ℝ)) (fun D=>by positivity) (fun _=>by positivity))).mono + intro D + have hh := (totalScoreExponent_bounds B D hB).2 + nlinarith only [hh,Nat.cast_nonneg B (α:=ℝ)] + +theorem SourcePolyUpper.ceil {f : ℕ→ℝ} (hf : SourcePolyUpper f) (hf0 : ∀D,0 ≤ f D) : + SourcePolyUpper (fun D=>(⌈f D⌉₊:ℝ)) := by + apply (hf.add (SourcePolyUpper.const 1)).mono + intro D + exact (Nat.ceil_lt_add_one (hf0 D)).le + +theorem sourceCancellationOrder_poly (B : ℕ) (hB : 2 ≤ B) : + SourcePolyUpper (fun D=>(sourceCancellationOrder B D:ℝ)) := by + let f := fun D=>totalScoreExponent B D+(sourceDegreeCutoff B:ℝ)+B+10 + have hf : SourcePolyUpper f := (((totalScoreExponent_poly B hB).add + (SourcePolyUpper.const (sourceDegreeCutoff B:ℝ))).add (SourcePolyUpper.const (B:ℝ))).add + (SourcePolyUpper.const 10) + have hf0 (D) : 0 ≤ f D := by + have hd := (totalScoreExponent_bounds B D hB).1 + have hr : 0 ≤ (sourceDegreeCutoff B:ℝ) := Nat.cast_nonneg _ + dsimp [f] + linarith only [hd,hr,Nat.cast_nonneg B (α:=ℝ)] + have hh := ((SourcePolyUpper.const 100).mul hf (fun _=>by norm_num) hf0).mul + (sourceEpsilon_inverse_poly B) (fun D=>mul_nonneg (by norm_num) (hf0 D)) + (fun D=>(inv_pos.mpr (sourceEpsilon_pos B D)).le) + have hc := hh.ceil (fun D=>mul_nonneg (mul_nonneg (by norm_num) (hf0 D)) + (inv_pos.mpr (sourceEpsilon_pos B D)).le) + simpa only [sourceCancellationOrder,f,div_eq_mul_inv] using hc + +theorem sourceCancellationOrder_large (B D : ℕ) : + 100*(totalScoreExponent B D+(sourceDegreeCutoff B:ℝ)+B+10) ≤ + (sourceCancellationOrder B D:ℝ)*sourceEpsilon B D := by + exact (div_le_iff₀ (sourceEpsilon_pos B D)).mp (Nat.le_ceil _) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- Literal finite-block factors are subpower uniformly over the joint + deletion regime when their logarithms grow polynomially in the depth. -/ +def SourceExpUpper (f : ℕ→ℝ→ℝ) : Prop := + ∃ C : ℝ,0 ≤ C ∧ ∃ h : ℕ,∀D q,q∈Set.Ioc 0 (1/2:ℝ) → + f D q ≤ Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ)) + +theorem SourcePolyUpper.expUpper {f : ℕ→ℝ} (hf : SourcePolyUpper f) : + SourceExpUpper (fun D _=>f D) := by + obtain ⟨C,hC,h,H⟩ := hf + refine ⟨C,hC,h,?_⟩ + intro D q hq + have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ + have hmul := mul_le_mul_of_nonneg_left hΛ (show 0 ≤ C*((D:ℝ)+1)^h by positivity) + exact (H D).trans ((by linarith only [hmul] : C*((D:ℝ)+1)^h ≤ C*((D:ℝ)+1)^h*q^(-3:ℤ)+1).trans + (Real.add_one_le_exp _)) + +theorem SourceExpUpper.const (c : ℝ) : SourceExpUpper (fun _ _=>c) := + (SourcePolyUpper.const c).expUpper + +theorem SourceExpUpper.mono {f g : ℕ→ℝ→ℝ} (hg : SourceExpUpper g) + (hf : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → f D q ≤ g D q) : SourceExpUpper f := by + obtain ⟨C,hC,h,H⟩ := hg + exact ⟨C,hC,h,fun D q hq=>(hf D q hq).trans (H D q hq)⟩ + +theorem SourceExpUpper.mul {f g : ℕ→ℝ→ℝ} (hf : SourceExpUpper f) (hg : SourceExpUpper g) + (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) + (hg0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ g D q) : + SourceExpUpper (fun D q=>f D q*g D q) := by + obtain ⟨C,hC,h,H⟩ := hf + obtain ⟨K,hK,k,G⟩ := hg + refine ⟨C+K,add_nonneg hC hK,h+k,?_⟩ + intro D q hq + have hΛ : 0 ≤ q^(-3:ℤ) := (zpow_pos hq.1 _).le + have hd : 1 ≤ (D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] + have hh := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h≤h+k)) hC) hΛ + have hk := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k≤h+k)) hK) hΛ + calc + _ ≤ Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ))*Real.exp (K*((D:ℝ)+1)^k*q^(-3:ℤ)) := + mul_le_mul (H D q hq) (G D q hq) (hg0 D q hq) ((hf0 D q hq).trans (H D q hq)) + _ ≤ _ := by rw [←Real.exp_add]; apply Real.exp_le_exp.mpr; nlinarith only [hh,hk] + +theorem SourceExpUpper.pow_variably {f : ℕ→ℝ→ℝ} {r : ℕ→ℕ} (hf : SourceExpUpper f) + (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) + (hr : SourcePolyUpper (fun D=>(r D:ℝ))) : SourceExpUpper (fun D q=>(f D q)^(r D)) := by + obtain ⟨C,hC,h,H⟩ := hf + obtain ⟨K,hK,k,G⟩ := hr + refine ⟨C*K,mul_nonneg hC hK,h+k,?_⟩ + intro D q hq + have hΛ : 0≤q^(-3:ℤ) := (zpow_pos hq.1 _).le + have hh := mul_le_mul_of_nonneg_right (G D) (show 0≤C*((D:ℝ)+1)^h*q^(-3:ℤ) by positivity) + calc + _ ≤ (Real.exp (C*((D:ℝ)+1)^h*q^(-3:ℤ)))^(r D) := pow_le_pow_left₀ (hf0 D q hq) (H D q hq) _ + _ = Real.exp ((r D:ℝ)*(C*((D:ℝ)+1)^h*q^(-3:ℤ))) := (Real.exp_nat_mul _ _).symm + _ ≤ _ := by apply Real.exp_le_exp.mpr; rw [pow_add]; nlinarith only [hh] + +theorem SourceExpUpper.pow {f : ℕ→ℝ→ℝ} (hf : SourceExpUpper f) + (hf0 : ∀D q,q∈Set.Ioc 0 (1/2:ℝ) → 0 ≤ f D q) (r : ℕ) : + SourceExpUpper (fun D q=>(f D q)^r) := + hf.pow_variably hf0 (SourcePolyUpper.const (r:ℝ)) + +theorem sourceOverlapConstant_expUpper : SourceExpUpper (fun _ q=>sourceOverlapConstant q) := by + refine ⟨sourceChannelLogConstant,sourceChannelLogConstant_pos.le,0,?_⟩ + intro D q hq + simp only [pow_zero,mul_one] + apply (Real.log_le_iff_le_exp (sourceOverlapConstant_pos hq.1)).mp + exact sourceOverlapConstant_log_bound ⟨hq.1,by linarith only [hq.2]⟩ + +theorem initialOverlapLower_inverse_expUpper : SourceExpUpper (fun _ q=>(initialOverlapLower q)⁻¹) := by + refine ⟨1536+(32+3*primitivePeriodConstant),by unfold primitivePeriodConstant; positivity,0,?_⟩ + intro D q hq + have hp := initialOverlapLower_pos q + have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ + rw [←Real.log_le_iff_le_exp (inv_pos.mpr hp),Real.log_inv,initialOverlapLower, + Real.log_div (Real.exp_pos _).ne' (by norm_num),Real.log_exp] + simp only [pow_zero,mul_one,zpow_neg,zpow_ofNat] at hΛ ⊢ + have hh := Real.log_le_self (by norm_num : (0:ℝ)≤1536) + have hmul := mul_le_mul_of_nonneg_left hΛ (by norm_num : (0:ℝ)≤1536) + simp only [div_eq_mul_inv] at * + nlinarith only [hh,hmul] + +/-- All indices are inside the same physical n,q instance. -/ +theorem SourceExpUpper.uniform (f : ℕ→ℝ→ℝ) (hf : SourceExpUpper f) + (B : ℕ) (ζ δ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) (hδ : 0<δ) + {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) + (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀i,f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t) ≤ + (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^( + δ*sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by + obtain ⟨C,hC,h,H⟩ := hf + have hrel (t) : Real.log (n t)=(q t)^(-3:ℤ)*((q t)^3*Real.log (n t)) := by + rw [zpow_neg,zpow_ofNat] + field_simp [(hq t).1.ne'] + filter_upwards [source_uniform_exp_absorption B h ζ C δ hB hζ hC hδ hn hH + (fun t=>zpow_pos (hq t).1 _) hrel] with t ht i + exact (H _ _ (hq t)).trans (ht i) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +def sourceMomentEnvelope (B D : ℕ) : ℝ := + ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1)*((D:ℝ)+1)*2^(B*D) + +def sourceCapEnvelope (B D : ℕ) (q : ℝ) : ℝ := + 200*(sourceOverlapConstant q)^(2*B*(D+1)+2)*(initialOverlapLower q)⁻¹ + +def sourceWeightEnvelope (B D : ℕ) : ℝ := 144*(sourceMomentEnvelope B D)^2 + +theorem sourceMomentEnvelope_pos (B D : ℕ) : 0 < sourceMomentEnvelope B D := by + unfold sourceMomentEnvelope + positivity + +theorem sourceCapEnvelope_pos (B D : ℕ) {q : ℝ} (hq : 0sourceMomentEnvelope B D) := by + have hr : SourcePolyUpper (fun D=>((B*D:ℕ):ℝ)) := by + apply ((SourcePolyUpper.const (B:ℝ)).mul SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).mono + intro D + push_cast + nlinarith only [Nat.cast_nonneg B (α:=ℝ)] + have hpow := (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hr + have hp := ((SourcePolyUpper.const ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1)).mul + SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).expUpper + exact hp.mul hpow (fun _ _ _=>by positivity) (fun _ _ _=>by positivity) + +theorem sourceCapEnvelope_expUpper (B : ℕ) : SourceExpUpper (sourceCapEnvelope B) := by + have hr : SourcePolyUpper (fun D=>((2*B*(D+1)+2:ℕ):ℝ)) := by + have hp := ((SourcePolyUpper.const ((2*B:ℕ):ℝ)).mul SourcePolyUpper.depth + (fun _=>by positivity) (fun _=>by positivity)).add (SourcePolyUpper.const 2) + simpa only [Nat.cast_mul,Nat.cast_add,Nat.cast_one,Nat.cast_ofNat] using hp + have hc := sourceOverlapConstant_expUpper.pow_variably (fun _ q hq=>(sourceOverlapConstant_pos hq.1).le) hr + exact ((SourceExpUpper.const 200).mul hc (fun _ _ _=>by norm_num) + (fun _ q hq=>pow_nonneg (sourceOverlapConstant_pos hq.1).le _)).mul initialOverlapLower_inverse_expUpper + (fun _ q hq=>by positivity [sourceOverlapConstant_pos hq.1]) + (fun _ q _=>(inv_pos.mpr (initialOverlapLower_pos q)).le) + +theorem sourceWeightEnvelope_expUpper (B : ℕ) : SourceExpUpper (fun D _=>sourceWeightEnvelope B D) := by + exact (SourceExpUpper.const 144).mul + ((sourceMomentEnvelope_expUpper B).pow (fun D _ _=>(sourceMomentEnvelope_pos B D).le) 2) + (fun _ _ _=>by norm_num) (fun _ _ _=>sq_nonneg _) + +theorem sourceMotif_expUpper (B : ℕ) (hB : 2 ≤ B) : + SourceExpUpper (fun D _=>(2:ℝ)^(sourceCancellationOrder B D)) := + (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) (sourceCancellationOrder_poly B hB) + +theorem sourceSmoothingPrefactor_expUpper (B : ℕ) (hB : 2 ≤ B) : + SourceExpUpper (fun D q=>sourceSmoothingPrefactor (sourceCancellationOrder B D) (sourceCapEnvelope B D q)) := by + let s := sourceCancellationOrder B + have hs := sourceCancellationOrder_poly B hB + have hs0 (D) : 0 ≤ (s D:ℝ) := Nat.cast_nonneg _ + have hp : SourcePolyUpper (fun D=>((s D*s D+s D:ℕ):ℝ)) := by + simpa only [Nat.cast_add,Nat.cast_mul] using (hs.mul hs hs0 hs0).add hs + have ht : SourcePolyUpper (fun D=>((s D+1:ℕ):ℝ)) := by + simpa only [Nat.cast_add,Nat.cast_one] using hs.add (SourcePolyUpper.const 1) + have hone := (SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hp + have htwo := ((ht.expUpper).mul (sourceCapEnvelope_expUpper B) + (fun _ _ _=>Nat.cast_nonneg _) (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le)).pow_variably + (fun D q hq=>mul_nonneg (Nat.cast_nonneg _) (sourceCapEnvelope_pos B D hq.1).le) ht + have H := hone.mul htwo (fun _ _ _=>by positivity) + (fun D q hq=>pow_nonneg (mul_nonneg (Nat.cast_nonneg _) (sourceCapEnvelope_pos B D hq.1).le) _) + simpa only [sourceSmoothingPrefactor,s,Nat.cast_add,Nat.cast_one] using H + +theorem sourceSkeletonPrefactor_expUpper (B b : ℕ) (hB : 2 ≤ B) : + SourceExpUpper (fun D q=>sourceSkeletonPrefactor (sourceCancellationOrder B D) b (sourceCapEnvelope B D q)) := by + have hL := sourceMotif_expUpper B hB + have hK := sourceCapEnvelope_expUpper B + have hA := ((SourceExpUpper.const 2).mul (hL.pow (fun _ _ _=>by positivity) 3) + (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity)).mul hK + (fun _ _ _=>by positivity) (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le) + have hF := ((SourceExpUpper.const 4).mul (hL.pow (fun _ _ _=>by positivity) 6) + (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity)).mul + (hK.pow (fun D _ hq=>(sourceCapEnvelope_pos B D hq.1).le) 2) + (fun _ _ _=>by positivity) (fun _ _ _=>sq_nonneg _) + have H := hA.mul (hF.pow (fun _ _ _=>by positivity) (2^b-1)) + (fun D q hq=>by positivity [sourceCapEnvelope_pos B D hq.1]) (fun _ _ _=>by positivity) + simpa only [sourceSkeletonPrefactor,binaryTreeBudget_const,Nat.cast_pow,Nat.cast_ofNat] using H + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem SourceArithmeticBounds.fit_tail {C N F ε : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (hC : 0(by omega : 1≤24).trans (H.windows j hj).1) + (fun j hj=>H.fit_exponent hC hF hN he hκ hj)).trans + have hh := mul_le_mul_of_nonneg_left (H.leaf_bound hN0) (show 0≤2*(b:ℝ) by positivity) + exact mul_le_mul_of_nonneg_right hh (Real.exp_pos _).le + +theorem SourceArithmeticBounds.metadata_tail {C N F ε ω : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0(by omega : 1≤24).trans (H.windows j hj).1) + (fun j hj=>(H.trials j hj).1) ?_).trans + · exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (H.leaf_bound hN) (show 0≤2*(b:ℝ) by positivity)) (Real.exp_pos _).le + · intro j hj + cases j with + | zero => exact Or.inl rfl + | succ j => + right + rw [sourceScheduledTrials,Nat.cast_mul] + have ht := (H.windows (j+1) hj).1 + have hd : 1 ≤ sourceBlockWindows N b ε (j+1)/4 := by omega + have hd' : (1:ℝ) ≤ (sourceBlockWindows N b ε (j+1)/4:ℕ) := by exact_mod_cast hd + exact (H.trials j (by omega)).1.trans + (le_mul_of_one_le_left (Nat.cast_nonneg _) hd') + +/-- Quantitative clipping without any default-limit increase or limiting + interchange: the power is the finite even moment actually used by the oracle. -/ +theorem source_clipping_moment_power (T : ℕ→ℕ) (s b k : ℕ) (N gap L : ℝ) + (hN : 0f D q+g D q) := by + obtain ⟨C,hC,h,H⟩ := hf + obtain ⟨K,hK,k,G⟩ := hg + refine ⟨C+K+1,by positivity,h+k,?_⟩ + intro D q hq + have hΛ := deletion_inverse_cube_ge_one ⟨hq.1,by linarith only [hq.2]⟩ + have hd : 1≤(D:ℝ)+1 := by linarith [Nat.cast_nonneg D (α:=ℝ)] + have hh := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : h≤h+k)) hC) (by linarith only [hΛ] : 0≤q^(-3:ℤ)) + have hk := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hd (by omega : k≤h+k)) hK) (by linarith only [hΛ] : 0≤q^(-3:ℤ)) + have hz : 1≤((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := one_le_mul_of_one_le_of_one_le (one_le_pow₀ hd) hΛ + have hc0 : 0≤C*((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := by positivity + have hk0 : 0≤K*((D:ℝ)+1)^(h+k)*q^(-3:ℤ) := by positivity + have he1 : f D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) := + (H D q hq).trans (Real.exp_le_exp.mpr (by nlinarith only [hh,hk0])) + have he2 : g D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) := + (G D q hq).trans (Real.exp_le_exp.mpr (by nlinarith only [hk,hc0])) + have he := Real.add_one_le_exp (((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) + have he' := mul_le_mul_of_nonneg_left (show 2≤Real.exp (((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) by linarith only [he,hz]) + (Real.exp_pos ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ))).le + rw [←Real.exp_add] at he' + convert (show f D q+g D q ≤ Real.exp ((C+K)*((D:ℝ)+1)^(h+k)*q^(-3:ℤ)+((D:ℝ)+1)^(h+k)*q^(-3:ℤ)) by linarith only [he1,he2,he']) using 1 + congr 1 + ring + +def sourceScaleInverseEnvelope (B D : ℕ) : ℝ := 2*(2:ℝ)^(B*D) + +theorem sourceScaleInverseEnvelope_expUpper (B : ℕ) : SourceExpUpper (fun D _=>sourceScaleInverseEnvelope B D) := by + have hr : SourcePolyUpper (fun D=>((B*D:ℕ):ℝ)) := by + apply ((SourcePolyUpper.const (B:ℝ)).mul SourcePolyUpper.depth (fun _=>by positivity) (fun _=>by positivity)).mono + intro D + push_cast + nlinarith only [Nat.cast_nonneg B (α:=ℝ)] + exact (SourceExpUpper.const 2).mul ((SourceExpUpper.const 2).pow_variably (fun _ _ _=>by norm_num) hr) + (fun _ _ _=>by norm_num) (fun _ _ _=>by positivity) + +theorem source_log_scale_lower (B D i : ℕ) {n : ℝ} (hB : 2≤B) (hn : 1(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀i,f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)*Real.log (n t) ≤ + (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^ + (δ*sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by + let g := fun D q=>f D q*sourceScaleInverseEnvelope B D*(2/δ)*(sourceEpsilon B D)⁻¹ + have hg : SourceExpUpper g := + ((hf.mul (sourceScaleInverseEnvelope_expUpper B) hf0 (fun _ _ _=>by unfold sourceScaleInverseEnvelope; positivity)).mul + (SourceExpUpper.const (2/δ)) (fun D q hq=>by unfold sourceScaleInverseEnvelope; positivity [hf0 D q hq]) (fun _ _ _=>by positivity)).mul + (sourceEpsilon_inverse_poly B).expUpper (fun D q hq=>by unfold sourceScaleInverseEnvelope; positivity [hf0 D q hq]) + (fun D _ _=>(inv_pos.mpr (sourceEpsilon_pos B D)).le) + have hu := SourceExpUpper.uniform g hg B ζ (δ/2) hB hζ (by positivity) hn hq hH + filter_upwards [hu,hn.eventually_gt_atTop 1] with t ht hnt + intro i + let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) + let N := sourceTargetScale B D (n t) i + let ε := sourceEpsilon B D + have he : 0<ε := sourceEpsilon_pos B D + have hN : 0(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀i, + g (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)* + Real.exp (-(sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) i)^ + (sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t))))/ + f (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t)) ≤ + (n t)^(-(h (sourceDepth B ζ ((q t)^3*Real.log (n t))) (q t))) := by + have hfu := SourceExpUpper.uniform f hf B ζ (1/4) hB hζ (by norm_num) hn hq hH + have hgu := SourceExpUpper.uniform g hg B ζ (1/4) hB hζ (by norm_num) hn hq hH + have hhu := hh.uniform_log hh0 B ζ (1/4) hB hζ (by norm_num) hn hq hH + have hcu := SourceExpUpper.uniform _ (SourceExpUpper.const 2) B ζ (1/4) hB hζ (by norm_num) hn hq hH + filter_upwards [hfu,hgu,hhu,hcu,hn.eventually_gt_atTop 1] with t hft hgt hht hct hnt + intro i + let D := sourceDepth B ζ ((q t)^3*Real.log (n t)) + let N := sourceTargetScale B D (n t) i + let ε := sourceEpsilon B D + let X := N^((1/4)*ε) + have hN : 0 |P.mass a - Q.mass a|) - (f := fun a => (Real.sqrt (P.mass a) - Real.sqrt (Q.mass a)) ^ 2) - (g := fun a => (Real.sqrt (P.mass a) + Real.sqrt (Q.mass a)) ^ 2) - (fun a _ => sq_nonneg _) (fun a _ => sq_nonneg _) (fun a _ => hpoint a) - have hplus : (∑ a, (Real.sqrt (P.mass a) + Real.sqrt (Q.mass a)) ^ 2) = - 2 + 2 * affinity P Q := by - unfold affinity - calc - _ = (∑ a, P.mass a) + (∑ a, Q.mass a) + 2 * ∑ a, - Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) := by - rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro a _ - have hp := Real.sq_sqrt (P.nonneg a) - have hq := Real.sq_sqrt (Q.nonneg a) - nlinarith only [hp, hq] - _ = _ := by rw [P.total, Q.total]; ring - rw [hplus] at h - change (∑ a, |P.mass a - Q.mass a|) ^ 2 ≤ hellingerSq P Q * (2 + 2 * affinity P Q) at h - have hbound := mul_le_mul_of_nonneg_left (affinity_le_one P Q) (hellingerSq_nonneg P Q) - unfold tv - nlinarith only [h, hbound] - -theorem tv_le_sqrt_hellingerSq (P Q : FiniteLaw α) : - tv P Q ≤ Real.sqrt (hellingerSq P Q) := by - have h := tv_sq_le_hellingerSq P Q - have hs := Real.sq_sqrt (hellingerSq_nonneg P Q) - have hn := Real.sqrt_nonneg (hellingerSq P Q) - nlinarith only [h, hs, hn] - -def product (P : FiniteLaw α) (m : ℕ) : FiniteLaw (Fin m → α) where - mass a := ∏ j, P.mass (a j) - nonneg a := Finset.prod_nonneg fun j _ => P.nonneg (a j) - total := by - rw [← Fintype.prod_sum] - simp [P.total] - -theorem affinity_product (P Q : FiniteLaw α) (m : ℕ) : - affinity (P.product m) (Q.product m) = affinity P Q ^ m := by - unfold affinity product - simp only - have hexp (a : Fin m → α) : - Real.sqrt (∏ j, P.mass (a j)) * Real.sqrt (∏ j, Q.mass (a j)) = - ∏ j, (Real.sqrt (P.mass (a j)) * Real.sqrt (Q.mass (a j))) := by - rw [Real.sqrt_prod _ (fun j _ => P.nonneg (a j)), - Real.sqrt_prod _ (fun j _ => Q.nonneg (a j)), Finset.prod_mul_distrib] - simp_rw [hexp] - rw [← Fintype.prod_sum (fun (_ : Fin m) a => Real.sqrt (P.mass a) * Real.sqrt (Q.mass a))] - simp - -theorem hellingerSq_product_le (P Q : FiniteLaw α) (m : ℕ) : - hellingerSq (P.product m) (Q.product m) ≤ (m : ℝ) * hellingerSq P Q := by - rw [hellingerSq_eq, affinity_product, hellingerSq_eq] - have ha := affinity_nonneg P Q - have hb := affinity_le_one P Q - have hpow : 1 - affinity P Q ^ m ≤ (m : ℝ) * (1 - affinity P Q) := by - induction m with - | zero => simp - | succ m ih => - rw [pow_succ, Nat.cast_add, Nat.cast_one] - have hmul := mul_le_mul_of_nonneg_right ih ha - have hm : (0 : ℝ) ≤ (m : ℝ) * (1 - affinity P Q) := by positivity - have hmon := mul_le_mul_of_nonneg_left hb hm - nlinarith only [hmul, hmon] - linarith - - -theorem sqrt_sub_one_sq_le {t : ℝ} (ht : 0 ≤ t) : - (Real.sqrt t - 1) ^ 2 ≤ (t - 1) ^ 2 := by - have hs2 := Real.sq_sqrt ht - have hprod := mul_nonneg (Real.sqrt_nonneg t) - (mul_nonneg (show 0 ≤ Real.sqrt t + 2 by positivity) (sq_nonneg (Real.sqrt t - 1))) - conv_rhs => rw [← hs2] - nlinarith only [hprod] - -theorem hellingerSq_le_score (P Q : FiniteLaw α) (Z : α → ℝ) - (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) : - hellingerSq P Q ≤ ∑ a, P.mass a * Z a ^ 2 := by - apply Finset.sum_le_sum - intro a _ - by_cases hp0 : P.mass a = 0 - · have hq0 : Q.mass a = 0 := by rw [hZ, hp0, zero_mul] - simp [hp0, hq0] - have hp : 0 < P.mass a := lt_of_le_of_ne (P.nonneg a) (Ne.symm hp0) - have ht : 0 ≤ 1 + Z a := by - have hq := Q.nonneg a - rw [hZ] at hq - exact nonneg_of_mul_nonneg_right hq hp - have hs := sqrt_sub_one_sq_le ht - have hmul := mul_le_mul_of_nonneg_left hs (P.nonneg a) - have hp2 := Real.sq_sqrt (P.nonneg a) - rw [hZ, Real.sqrt_mul (P.nonneg a)] - calc - _ = P.mass a * (Real.sqrt (1 + Z a) - 1) ^ 2 := by - calc - _ = Real.sqrt (P.mass a) ^ 2 * (Real.sqrt (1 + Z a) - 1) ^ 2 := by ring - _ = _ := by rw [hp2] - _ ≤ P.mass a * ((1 + Z a) - 1) ^ 2 := hmul - _ = _ := by ring - -theorem tv_product_le_sqrt_score (P Q : FiniteLaw α) (Z : α → ℝ) - (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) (m : ℕ) : - tv (P.product m) (Q.product m) ≤ Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) := by - apply (tv_le_sqrt_hellingerSq _ _).trans - apply Real.sqrt_le_sqrt - exact (hellingerSq_product_le P Q m).trans - (mul_le_mul_of_nonneg_left (hellingerSq_le_score P Q Z hZ) (by positivity)) - -def bind (P : FiniteLaw α) (K : α → FiniteLaw β) : FiniteLaw β where - mass b := ∑ a, P.mass a * (K a).mass b - nonneg b := Finset.sum_nonneg fun a _ => mul_nonneg (P.nonneg a) ((K a).nonneg b) - total := by - rw [Finset.sum_comm] - simp_rw [← Finset.mul_sum, (K _).total, mul_one] - exact P.total - -theorem tv_bind_le (P Q : FiniteLaw α) (K : α → FiniteLaw β) : - tv (P.bind K) (Q.bind K) ≤ tv P Q := by - unfold tv bind - simp only - apply mul_le_mul_of_nonneg_left _ (by norm_num) - calc - _ = ∑ b, |∑ a, (P.mass a - Q.mass a) * (K a).mass b| := by - apply Finset.sum_congr rfl - intro b _ - congr 1 - rw [← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro a _; ring - _ ≤ ∑ b, ∑ a, |(P.mass a - Q.mass a) * (K a).mass b| := - Finset.sum_le_sum fun b _ => Finset.abs_sum_le_sum_abs _ _ - _ = ∑ a, |P.mass a - Q.mass a| := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - simp_rw [abs_mul, abs_of_nonneg ((K a).nonneg _), ← Finset.mul_sum, (K a).total, mul_one] - -theorem tv_triangle (P Q R : FiniteLaw α) : tv P R ≤ tv P Q + tv Q R := by - unfold tv - rw [← mul_add, ← Finset.sum_add_distrib] - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Finset.sum_le_sum - intro a _ - exact abs_sub_le _ _ _ - -theorem tv_symm (P Q : FiniteLaw α) : tv P Q = tv Q P := by - unfold tv - congr 1 - apply Finset.sum_congr rfl - intro a _; exact abs_sub_comm _ _ - -theorem expectation_diff_le_tv (P Q : FiniteLaw α) (f : α → ℝ) - (hf : ∀ a, f a ∈ Set.Icc 0 1) : - (∑ a, P.mass a * f a) - (∑ a, Q.mass a * f a) ≤ tv P Q := by - have hz : (∑ a, (P.mass a - Q.mass a)) = 0 := by - rw [Finset.sum_sub_distrib, P.total, Q.total, sub_self] - have h (a : α) : (P.mass a - Q.mass a) * f a ≤ - (|P.mass a - Q.mass a| + (P.mass a - Q.mass a)) / 2 := by - by_cases hd : 0 ≤ P.mass a - Q.mass a - · rw [abs_of_nonneg hd] - have := mul_le_mul_of_nonneg_left (hf a).2 hd - linarith - · rw [abs_of_neg (lt_of_not_ge hd)] - have := mul_nonpos_of_nonpos_of_nonneg (le_of_not_ge hd) (hf a).1 - linarith - calc - _ = ∑ a, (P.mass a - Q.mass a) * f a := by - rw [← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro a _; ring - _ ≤ ∑ a, (|P.mass a - Q.mass a| + (P.mass a - Q.mass a)) / 2 := - Finset.sum_le_sum fun a _ => h a - _ = tv P Q := by - rw [← Finset.sum_div, Finset.sum_add_distrib, hz, add_zero] - unfold tv - ring - -theorem binary_testing_bound (P Q : FiniteLaw α) (f : α → ℝ) - (hf : ∀ a, f a ∈ Set.Icc 0 1) : - ((∑ a, P.mass a * f a) + (∑ a, Q.mass a * (1 - f a))) / 2 ≤ - (1 + tv P Q) / 2 := by - have h := expectation_diff_le_tv P Q f hf - have heq : (∑ a, Q.mass a * (1 - f a)) = 1 - ∑ a, Q.mass a * f a := by - simp_rw [mul_sub, mul_one, Finset.sum_sub_distrib, Q.total] - rw [heq] - linarith - - -theorem sum_max_eq (P Q : FiniteLaw α) : - (∑ a, max (P.mass a) (Q.mass a)) = 1 + tv P Q := by - have hpoint (a : α) : max (P.mass a) (Q.mass a) = - (P.mass a + Q.mass a + |P.mass a - Q.mass a|) / 2 := by - by_cases h : P.mass a ≤ Q.mass a - · rw [max_eq_right h, abs_of_nonpos (sub_nonpos.mpr h)]; ring - · rw [max_eq_left (le_of_not_ge h), abs_of_nonneg (sub_nonneg.mpr (le_of_not_ge h))]; ring - simp_rw [hpoint] - rw [← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib, P.total, Q.total] - unfold tv - ring - -/-- Joint exact recovery of independent binary choices, allowing arbitrary -randomized estimators. No coordinatewise decision rule is assumed. -/ -theorem independent_binary_testing (P Q : FiniteLaw α) (g : ℕ) - (A : (Fin g → α) → (Fin g → Bool) → ℝ) - (hA0 : ∀ z θ, 0 ≤ A z θ) (hA1 : ∀ z, ∑ θ, A z θ = 1) : - (1 / (2 : ℝ) ^ g) * ∑ θ : Fin g → Bool, ∑ z : Fin g → α, - (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) * A z θ ≤ - ((1 + tv P Q) / 2) ^ g := by - classical - have hpoint (z : Fin g → α) (θ : Fin g → Bool) : - (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) ≤ - ∏ j, max (P.mass (z j)) (Q.mass (z j)) := by - apply Finset.prod_le_prod₀ - · intro j _; split <;> first | exact P.nonneg _ | exact Q.nonneg _ - · intro j _; split <;> first | exact le_max_left _ _ | exact le_max_right _ _ - have hsum (z : Fin g → α) : - (∑ θ : Fin g → Bool, - (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) * A z θ) ≤ - ∏ j, max (P.mass (z j)) (Q.mass (z j)) := by - calc - _ ≤ ∑ θ : Fin g → Bool, - (∏ j, max (P.mass (z j)) (Q.mass (z j))) * A z θ := by - apply Finset.sum_le_sum - intro θ _ - exact mul_le_mul_of_nonneg_right (hpoint z θ) (hA0 z θ) - _ = _ := by rw [← Finset.mul_sum, hA1, mul_one] - rw [Finset.sum_comm] - calc - _ ≤ (1 / (2 : ℝ) ^ g) * ∑ z : Fin g → α, ∏ j, - max (P.mass (z j)) (Q.mass (z j)) := - mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun z _ => hsum z) (by positivity) - _ = (1 / (2 : ℝ) ^ g) * (∑ a, max (P.mass a) (Q.mass a)) ^ g := by - rw [← Fintype.prod_sum (fun (_ : Fin g) a => max (P.mass a) (Q.mass a))] - simp - _ = _ := by rw [sum_max_eq, div_pow]; ring - -def tensor (P : FiniteLaw α) (R : FiniteLaw β) : FiniteLaw (α × β) where - mass z := P.mass z.1 * R.mass z.2 - nonneg z := mul_nonneg (P.nonneg z.1) (R.nonneg z.2) - total := by - rw [Fintype.sum_prod_type] - simp_rw [← Finset.mul_sum, R.total, mul_one] - exact P.total - -theorem tv_tensor_le (P Q : FiniteLaw α) (R S : FiniteLaw β) : - tv (P.tensor R) (Q.tensor S) ≤ tv P Q + tv R S := by - unfold tv tensor - simp only - rw [Fintype.sum_prod_type, ← mul_add] - apply mul_le_mul_of_nonneg_left _ (by norm_num) - have hpoint (a : α) (b : β) : - |P.mass a * R.mass b - Q.mass a * S.mass b| ≤ - |P.mass a - Q.mass a| * R.mass b + Q.mass a * |R.mass b - S.mass b| := by - calc - _ = |(P.mass a - Q.mass a) * R.mass b + Q.mass a * (R.mass b - S.mass b)| := by - congr 1; ring - _ ≤ |(P.mass a - Q.mass a) * R.mass b| + |Q.mass a * (R.mass b - S.mass b)| := - abs_add_le _ _ - _ = _ := by rw [abs_mul, abs_mul, abs_of_nonneg (R.nonneg b), abs_of_nonneg (Q.nonneg a)] - calc - _ ≤ ∑ a, ∑ b, (|P.mass a - Q.mass a| * R.mass b + Q.mass a * |R.mass b - S.mass b|) := by - apply Finset.sum_le_sum - intro a _ - exact Finset.sum_le_sum fun b _ => hpoint a b - _ = _ := by - simp_rw [Finset.sum_add_distrib, ← Finset.mul_sum, R.total, mul_one] - rw [← Finset.sum_mul, Q.total, one_mul] - -theorem tv_product_succ (P Q : FiniteLaw α) (m : ℕ) : - tv (P.product (m + 1)) (Q.product (m + 1)) = - tv (P.tensor (P.product m)) (Q.tensor (Q.product m)) := by - unfold tv product tensor - simp only - congr 1 - rw [← (Fin.consEquiv (fun _ : Fin (m + 1) => α)).sum_comp] - apply Finset.sum_congr rfl - intro a _ - simp only [Fin.prod_univ_succ, Fin.consEquiv_apply, Fin.cons_zero, Fin.cons_succ] - -theorem tv_product_le (P Q : FiniteLaw α) (m : ℕ) : - tv (P.product m) (Q.product m) ≤ (m : ℝ) * tv P Q := by - induction m with - | zero => simp [tv, product] - | succ m ih => - rw [tv_product_succ] - apply (tv_tensor_le P Q (P.product m) (Q.product m)).trans - simpa only [Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm] using - add_le_add_left ih (tv P Q) - - -theorem affinity_bind_ge (P Q : FiniteLaw α) (K : α → FiniteLaw β) : - affinity P Q ≤ affinity (P.bind K) (Q.bind K) := by - have hpoint (b : β) : - (∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) ≤ - Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b) := by - have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul (s := Finset.univ) - (r := fun a => Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) - (f := fun a => P.mass a * (K a).mass b) (g := fun a => Q.mass a * (K a).mass b) - (fun a _ => mul_nonneg (P.nonneg a) ((K a).nonneg b)) - (fun a _ => mul_nonneg (Q.nonneg a) ((K a).nonneg b)) (by - intro a _ - rw [mul_pow, mul_pow, Real.sq_sqrt (P.nonneg a), Real.sq_sqrt (Q.nonneg a)] - nlinarith only [sq_nonneg ((K a).mass b)]) - have hp2 := Real.sq_sqrt ((P.bind K).nonneg b) - have hq2 := Real.sq_sqrt ((Q.bind K).nonneg b) - have hsq : (Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b)) ^ 2 = - (P.bind K).mass b * (Q.bind K).mass b := by rw [mul_pow, hp2, hq2] - change (∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) ^ 2 ≤ - (P.bind K).mass b * (Q.bind K).mass b at hcs - have hn : 0 ≤ Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b) := by positivity - nlinarith only [hcs, hsq, hn] - calc - affinity P Q = ∑ b, ∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b := by - rw [Finset.sum_comm] - simp_rw [← Finset.mul_sum, (K _).total, mul_one] - rfl - _ ≤ _ := Finset.sum_le_sum fun b _ => hpoint b - -theorem hellingerSq_bind_le (P Q : FiniteLaw α) (K : α → FiniteLaw β) : - hellingerSq (P.bind K) (Q.bind K) ≤ hellingerSq P Q := by - rw [hellingerSq_eq, hellingerSq_eq] - linarith [affinity_bind_ge P Q K] - -/-- Restoration of approximate oracle simulations before taking independent -complete observations; the simulation error is charged once per sample. -/ -theorem approximate_score_transfer (P Q : FiniteLaw α) (K : α → FiniteLaw β) - (R S : FiniteLaw β) (Z : α → ℝ) - (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) (E : ℝ) - (hR : tv R (P.bind K) ≤ E) (hS : tv S (Q.bind K) ≤ E) (m : ℕ) : - tv (R.product m) (S.product m) ≤ - Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) + 2 * m * E := by - have hmid : tv ((P.bind K).product m) ((Q.bind K).product m) ≤ - Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) := by - apply (tv_le_sqrt_hellingerSq _ _).trans - apply Real.sqrt_le_sqrt - apply (hellingerSq_product_le _ _ m).trans - exact mul_le_mul_of_nonneg_left - ((hellingerSq_bind_le P Q K).trans (hellingerSq_le_score P Q Z hZ)) (by positivity) - have hr := (tv_product_le R (P.bind K) m).trans - (mul_le_mul_of_nonneg_left hR (by positivity : (0 : ℝ) ≤ m)) - have hs := (tv_product_le S (Q.bind K) m).trans - (mul_le_mul_of_nonneg_left hS (by positivity : (0 : ℝ) ≤ m)) - rw [tv_symm (S.product m)] at hs - have htri1 := tv_triangle (R.product m) ((P.bind K).product m) (S.product m) - have htri2 := tv_triangle ((P.bind K).product m) ((Q.bind K).product m) (S.product m) - linarith - -def overlap (P Q : FiniteLaw α) : ℝ := ∑ a, min (P.mass a) (Q.mass a) - -theorem overlap_eq_one_sub_tv (P Q : FiniteLaw α) : overlap P Q = 1 - tv P Q := by - have hm : overlap P Q + (∑ a, max (P.mass a) (Q.mass a)) = 2 := by - rw [overlap, ← Finset.sum_add_distrib] - simp_rw [min_add_max] - rw [Finset.sum_add_distrib, P.total, Q.total] - norm_num - rw [sum_max_eq] at hm - linarith - -theorem overlap_nonneg (P Q : FiniteLaw α) : 0 ≤ overlap P Q := by - apply Finset.sum_nonneg - intro a _ - exact le_min (P.nonneg a) (Q.nonneg a) - -def commonPart (P Q : FiniteLaw α) (h : 0 < overlap P Q) : FiniteLaw α where - mass a := min (P.mass a) (Q.mass a) / overlap P Q - nonneg a := div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le - total := by rw [← Finset.sum_div]; exact div_self h.ne' - -theorem commonPart_le_left (P Q : FiniteLaw α) (h : 0 < overlap P Q) - {ω : ℝ} (hω : ω ≤ overlap P Q) (a : α) : - ω * (commonPart P Q h).mass a ≤ P.mass a := by - change ω * (min (P.mass a) (Q.mass a) / overlap P Q) ≤ _ - calc - _ ≤ overlap P Q * (min (P.mass a) (Q.mass a) / overlap P Q) := - mul_le_mul_of_nonneg_right hω (div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le) - _ = min (P.mass a) (Q.mass a) := by field_simp - _ ≤ _ := min_le_left _ _ - -def remainderLaw (P H : FiniteLaw α) (ω : ℝ) (hω : ω < 1) - (hdom : ∀ a, ω * H.mass a ≤ P.mass a) : FiniteLaw α where - mass a := (P.mass a - ω * H.mass a) / (1 - ω) - nonneg a := div_nonneg (sub_nonneg.mpr (hdom a)) (sub_pos.mpr hω).le - total := by - rw [← Finset.sum_div, Finset.sum_sub_distrib, ← Finset.mul_sum, P.total, H.total, mul_one] - exact div_self (sub_pos.mpr hω).ne' - -theorem common_part_decomposition (P Q : FiniteLaw α) {ω : ℝ} - (hω : ω ∈ Set.Ioo 0 1) (hov : ω ≤ overlap P Q) : - ∃ H P' Q' : FiniteLaw α, - (∀ a, P.mass a = ω * H.mass a + (1 - ω) * P'.mass a) ∧ - (∀ a, Q.mass a = ω * H.mass a + (1 - ω) * Q'.mass a) := by - have h : 0 < overlap P Q := lt_of_lt_of_le hω.1 hov - let H := commonPart P Q h - have hP : ∀ a, ω * H.mass a ≤ P.mass a := commonPart_le_left P Q h hov - have hQ : ∀ a, ω * H.mass a ≤ Q.mass a := by - intro a - change ω * (min (P.mass a) (Q.mass a) / overlap P Q) ≤ _ - calc - _ ≤ overlap P Q * (min (P.mass a) (Q.mass a) / overlap P Q) := - mul_le_mul_of_nonneg_right hov (div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le) - _ = min (P.mass a) (Q.mass a) := by field_simp - _ ≤ _ := min_le_right _ _ - refine ⟨H, remainderLaw P H ω hω.2 hP, remainderLaw Q H ω hω.2 hQ, ?_, ?_⟩ - · intro a - change P.mass a = ω * H.mass a + (1 - ω) * ((P.mass a - ω * H.mass a) / (1 - ω)) - field_simp [(sub_pos.mpr hω.2).ne'] - ring - · intro a - change Q.mass a = ω * H.mass a + (1 - ω) * ((Q.mass a - ω * H.mass a) / (1 - ω)) - field_simp [(sub_pos.mpr hω.2).ne'] - ring - -end FiniteLaw -end TraceReconstruction - -namespace TraceReconstruction.FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] - -def prod (P : FiniteLaw α) (Q : FiniteLaw β) : FiniteLaw (α × β) where - mass x := P.mass x.1 * Q.mass x.2 - nonneg x := mul_nonneg (P.nonneg _) (Q.nonneg _) - total := by - rw [Fintype.sum_prod_type] - simp_rw [← Finset.mul_sum, Q.total, mul_one] - exact P.total - -def expect (P : FiniteLaw α) (f : α → ℝ) : ℝ := ∑ a, P.mass a * f a - -theorem expect_const (P : FiniteLaw α) (c : ℝ) : P.expect (fun _ => c) = c := by - unfold expect - rw [← Finset.sum_mul, P.total, one_mul] - -theorem expect_mono (P : FiniteLaw α) {f g : α → ℝ} (h : ∀ a, f a ≤ g a) : - P.expect f ≤ P.expect g := Finset.sum_le_sum fun a _ => - mul_le_mul_of_nonneg_left (h a) (P.nonneg a) - -theorem expect_prod (P : FiniteLaw α) (Q : FiniteLaw β) (f : α × β → ℝ) : - (P.prod Q).expect f = P.expect (fun a => Q.expect (fun b => f (a, b))) := by - unfold expect prod - rw [Fintype.sum_prod_type] - simp_rw [Finset.mul_sum, mul_assoc] - -/-- Association is only used for increasing likelihood-threshold events. -/ -def Associated [Preorder α] (P : FiniteLaw α) : Prop := - ∀ f g : α → ℝ, Monotone f → Monotone g → - P.expect f * P.expect g ≤ P.expect (fun a => f a * g a) - -theorem associated_linearOrder [LinearOrder α] (P : FiniteLaw α) : P.Associated := by - intro f g hf hg - have hn (a b : α) : 0 ≤ (f a - f b) * (g a - g b) := by - rcases le_total a b with hab | hba - · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (hf hab)) - (sub_nonpos.mpr (hg hab)) - · exact mul_nonneg (sub_nonneg.mpr (hf hba)) (sub_nonneg.mpr (hg hba)) - have h := Finset.sum_nonneg (s := Finset.univ) (fun a _ => - Finset.sum_nonneg (s := Finset.univ) (fun b _ => mul_nonneg (mul_nonneg (P.nonneg a) - (P.nonneg b)) (hn a b))) - have hid : (∑ a, ∑ b, P.mass a * P.mass b * ((f a - f b) * (g a - g b))) = - 2 * (P.expect (fun a => f a * g a) - P.expect f * P.expect g) := by - have hp (a b : α) : P.mass a * P.mass b * ((f a - f b) * (g a - g b)) = - (P.mass a * (f a * g a)) * P.mass b + P.mass a * (P.mass b * (f b * g b)) - - (P.mass a * f a) * (P.mass b * g b) - (P.mass a * g a) * (P.mass b * f b) := by ring - simp_rw [hp, Finset.sum_sub_distrib, Finset.sum_add_distrib, - ← Finset.mul_sum, ← Finset.sum_mul, P.total, one_mul, mul_one] - unfold expect - ring - rw [hid] at h - linarith - -theorem Associated.prod [Preorder α] [Preorder β] {P : FiniteLaw α} {Q : FiniteLaw β} - (hP : P.Associated) (hQ : Q.Associated) : (P.prod Q).Associated := by - intro f g hf hg - rw [expect_prod, expect_prod, expect_prod] - calc - _ ≤ P.expect (fun a => Q.expect (fun b => f (a, b)) * Q.expect (fun b => g (a, b))) := by - apply hP - · intro a a' ha - exact Q.expect_mono (fun b => hf ⟨ha, le_rfl⟩) - · intro a a' ha - exact Q.expect_mono (fun b => hg ⟨ha, le_rfl⟩) - _ ≤ _ := by - apply P.expect_mono - intro a - apply hQ - · intro b b' hb; exact hf ⟨le_rfl, hb⟩ - · intro b b' hb; exact hg ⟨le_rfl, hb⟩ - -theorem product_succ_expect (P : FiniteLaw α) (n : ℕ) (f : (Fin (n + 1) → α) → ℝ) : - (P.product (n + 1)).expect f = - P.expect (fun a => (P.product n).expect (fun b => f (Fin.cons a b))) := by - unfold expect product - rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => α)).sum_comp, Fintype.sum_prod_type] - simp_rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - change (∏ j, P.mass ((Fin.cons a b : Fin (n + 1) → α) j)) * f (Fin.cons a b) = _ - rw [Fin.prod_univ_succ] - simp only [Fin.cons_zero, Fin.cons_succ] - ring - -theorem associated_product [Preorder α] (P : FiniteLaw α) (hP : P.Associated) (n : ℕ) : - (P.product n).Associated := by - induction n with - | zero => - intro f g _ _ - simp [expect, product] - | succ n ih => - intro f g hf hg - rw [product_succ_expect, product_succ_expect, product_succ_expect] - have hcons {a a' : α} {b b' : Fin n → α} (ha : a ≤ a') (hb : b ≤ b') : - (Fin.cons a b : Fin (n + 1) → α) ≤ (Fin.cons a' b' : Fin (n + 1) → α) := by - intro j - refine Fin.cases ?_ (fun i => ?_) j - · exact ha - · exact hb i - calc - _ ≤ P.expect (fun a => (P.product n).expect (fun b => f (Fin.cons a b)) * - (P.product n).expect (fun b => g (Fin.cons a b))) := by - apply hP - · intro a a' ha - exact (P.product n).expect_mono (fun b => hf (hcons ha le_rfl)) - · intro a a' ha - exact (P.product n).expect_mono (fun b => hg (hcons ha le_rfl)) - _ ≤ _ := by - apply P.expect_mono - intro a - apply ih - · intro b b' hb; exact hf (hcons le_rfl hb) - · intro b b' hb; exact hg (hcons le_rfl hb) - -/-- An elementary Paley--Zygmund bound at threshold 1/2, for a density. -/ -theorem density_threshold_mass (P : FiniteLaw α) (f : α → ℝ) - (hmean : P.expect f = 1) : - (1 : ℝ) / 4 ≤ - (P.expect (fun a => if 1 / 2 ≤ f a then 1 else 0)) * P.expect (fun a => f a ^ 2) := by - classical - let S : Finset α := Finset.univ.filter (fun a => 1 / 2 ≤ f a) - have hsmall : (∑ a ∈ Finset.univ \ S, P.mass a * f a) ≤ 1 / 2 := by - calc - _ ≤ ∑ a ∈ Finset.univ \ S, P.mass a * (1 / 2) := by - apply Finset.sum_le_sum - intro a ha - have hnot : ¬ 1 / 2 ≤ f a := by simpa [S] using (Finset.mem_sdiff.mp ha).2 - exact mul_le_mul_of_nonneg_left (le_of_lt (lt_of_not_ge hnot)) (P.nonneg a) - _ ≤ ∑ a, P.mass a * (1 / 2) := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.sdiff_subset) - intro a _ _; positivity [P.nonneg a] - _ = 1 / 2 := P.expect_const _ - have hlarge : 1 / 2 ≤ ∑ a ∈ S, P.mass a * f a := by - have hsplit := Finset.sum_sdiff (Finset.subset_univ S) (f := fun a => P.mass a * f a) - change (∑ a, P.mass a * f a) = 1 at hmean - rw [hmean] at hsplit - linarith - have hc := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul (s := S) - (r := fun a => P.mass a * f a) (f := P.mass) (g := fun a => P.mass a * f a ^ 2) - (fun a _ => P.nonneg a) (fun a _ => by positivity [P.nonneg a]) - (fun a _ => by nlinarith) - have ht : (∑ a ∈ S, P.mass a * f a ^ 2) ≤ P.expect (fun a => f a ^ 2) := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ S) - intro a _ _; positivity [P.nonneg a] - have hmass : P.expect (fun a => if 1 / 2 ≤ f a then 1 else 0) = ∑ a ∈ S, P.mass a := by - unfold expect S - simp_rw [mul_ite, mul_one, mul_zero] - rw [Finset.sum_filter] - rw [hmass] - have hm := mul_le_mul_of_nonneg_left ht (Finset.sum_nonneg (s := S) (fun a _ => P.nonneg a)) - nlinarith - -/-- The common-density overlap used for consecutive pure primitive runs. -/ -theorem increasing_density_overlap [Preorder α] (P : FiniteLaw α) (hP : P.Associated) - (f g : α → ℝ) (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) - (hfm : Monotone f) (hgm : Monotone g) - (hf1 : P.expect f = 1) (hg1 : P.expect g = 1) : - (1 : ℝ) / 32 ≤ P.expect (fun a => min (f a) (g a)) * - P.expect (fun a => f a ^ 2) * P.expect (fun a => g a ^ 2) := by - let F : α → ℝ := fun a => if 1 / 2 ≤ f a then 1 else 0 - let G : α → ℝ := fun a => if 1 / 2 ≤ g a then 1 else 0 - have hF : Monotone F := by - intro a b hab - dsimp [F] - split_ifs with ha hb hb - · rfl - · exact False.elim (hb (ha.trans (hfm hab))) - · norm_num - · rfl - have hG : Monotone G := by - intro a b hab - dsimp [G] - split_ifs with ha hb hb - · rfl - · exact False.elim (hb (ha.trans (hgm hab))) - · norm_num - · rfl - have hcorr := hP F G hF hG - have hpoint : ∀ a, (1 / 2 : ℝ) * (F a * G a) ≤ min (f a) (g a) := by - intro a - dsimp [F, G] - split_ifs <;> simp only [mul_one, mul_zero] - · exact le_min ‹_› ‹_› - all_goals exact le_min (hf a) (hg a) - have hint := P.expect_mono hpoint - have heq : P.expect (fun a => (1 / 2 : ℝ) * (F a * G a)) = - (1 / 2 : ℝ) * P.expect (fun a => F a * G a) := by - unfold expect - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _; ring - rw [heq] at hint - have hfm2 : 0 ≤ P.expect (fun a => f a ^ 2) := - Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) - have hgm2 : 0 ≤ P.expect (fun a => g a ^ 2) := - Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) - have hff := density_threshold_mass P f hf1 - have hgg := density_threshold_mass P g hg1 - change 1 / 4 ≤ P.expect F * P.expect (fun a => f a ^ 2) at hff - change 1 / 4 ≤ P.expect G * P.expect (fun a => g a ^ 2) at hgg - have hmul := mul_le_mul hff hgg (by norm_num : (0 : ℝ) ≤ 1 / 4) (by linarith : - 0 ≤ P.expect F * P.expect (fun a => f a ^ 2)) - have hcomb : (1 / 2 : ℝ) * (P.expect F * P.expect G) ≤ - P.expect (fun a => min (f a) (g a)) := by linarith - have hmul2 := mul_le_mul_of_nonneg_right hcomb (mul_nonneg hfm2 hgm2) - nlinarith only [hmul, hmul2] - -end TraceReconstruction.FiniteLaw - -namespace TraceReconstruction.FiniteLaw -variable {α : Type*} [Fintype α] -/-- Orientation `false` uses P,Q in chronological order; true reverses them. -/ -def orientedProd (P Q : FiniteLaw α) (b : Bool) : FiniteLaw (α × α) := - if b then Q.prod P else P.prod Q - -def pairedHiddenMass (H : FiniteLaw α) (ω : ℝ) (z : α × α) : ℝ := - ω ^ 2 * H.mass z.1 * H.mass z.2 - -theorem sum_pairedHiddenMass (H : FiniteLaw α) (ω : ℝ) : - (∑ z, pairedHiddenMass H ω z) = ω ^ 2 := by - unfold pairedHiddenMass - rw [Fintype.sum_prod_type] - simp_rw [← Finset.mul_sum, H.total, mul_one] - rw [← Finset.mul_sum, H.total, mul_one] - -theorem pairedHiddenMass_le (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) - (b : Bool) (z : α × α) : pairedHiddenMass H ω z ≤ (orientedProd P Q b).mass z := by - have hm (R S : FiniteLaw α) (hR : ∀ a, ω * H.mass a ≤ R.mass a) - (hS : ∀ a, ω * H.mass a ≤ S.mass a) : - pairedHiddenMass H ω z ≤ R.mass z.1 * S.mass z.2 := by - calc - _ = (ω * H.mass z.1) * (ω * H.mass z.2) := by unfold pairedHiddenMass; ring - _ ≤ _ := mul_le_mul (hR z.1) (hS z.2) - (mul_nonneg hω (H.nonneg _)) (R.nonneg _) - cases b - · exact hm P Q hP hQ - · exact hm Q P hQ hP - -/-- None is the joint hidden flag; a visible flag reports the true orientation. -/ -def pairedFlagMass (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) - (z : Option Bool × (α × α)) : ℝ := - match z.1 with - | none => pairedHiddenMass H ω z.2 - | some c => if c = b then (orientedProd P Q b).mass z.2 - pairedHiddenMass H ω z.2 else 0 - -theorem pairedFlagMass_nonneg (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) - (b : Bool) (z : Option Bool × (α × α)) : 0 ≤ pairedFlagMass P Q H ω b z := by - unfold pairedFlagMass - split - · unfold pairedHiddenMass - positivity [H.nonneg z.2.1, H.nonneg z.2.2] - · split_ifs - · exact sub_nonneg.mpr (pairedHiddenMass_le P Q H hω hP hQ b z.2) - · rfl - -theorem pairedFlagMass_sum (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) : - (∑ z, pairedFlagMass P Q H ω b z) = 1 := by - rw [Fintype.sum_prod_type, Finset.sum_comm] - have hp (z : α × α) : (∑ c : Option Bool, pairedFlagMass P Q H ω b (c, z)) = - (orientedProd P Q b).mass z := by - cases b <;> simp [pairedFlagMass, Fintype.sum_option ] - simp_rw [hp] - exact (orientedProd P Q b).total - -def pairedFlagLaw (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) - (b : Bool) : FiniteLaw (Option Bool × (α × α)) := - ⟨pairedFlagMass P Q H ω b, pairedFlagMass_nonneg P Q H hω hP hQ b, - pairedFlagMass_sum P Q H ω b⟩ - -/-- Forgetting the report recovers conditional independence for each orientation. -/ -theorem pairedFlag_simulation (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) (z : α × α) : - (∑ c : Option Bool, pairedFlagMass P Q H ω b (c, z)) = - (orientedProd P Q b).mass z := by - cases b <;> simp [pairedFlagMass, Fintype.sum_option ] - -/-- Hidden reports carry exactly zero information about the fair orientation, -even after both strings have been observed. -/ -theorem pairedFlag_hidden_joint (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) (z : α × α) : - (1 / 2 : ℝ) * pairedFlagMass P Q H ω b (none, z) = - (1 / 2 : ℝ) * (ω ^ 2 * (H.prod H).mass z) := by - unfold pairedFlagMass pairedHiddenMass prod - ring - -theorem pairedFlag_hidden_probability (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) : - (∑ z, pairedFlagMass P Q H ω b (none, z)) = ω ^ 2 := sum_pairedHiddenMass H ω - -end TraceReconstruction.FiniteLaw - -namespace TraceReconstruction.FiniteLaw -variable {α : Type*} [Fintype α] -theorem small_geometric_sum (n : ℕ) {x : ℝ} (hx : x ∈ Set.Icc 0 (1 / 2)) : - (∑ j ∈ Finset.range n, x ^ j) ≤ 2 := by - have he := geom_sum_mul x n - have hn : 0 ≤ ∑ j ∈ Finset.range n, x ^ j := - Finset.sum_nonneg (fun j _ => pow_nonneg hx.1 j) - have hp := pow_nonneg hx.1 n - nlinarith [mul_le_mul_of_nonneg_left hx.2 hn] - -/-- Elementary tail of a binomial polynomial after cancelling orders zero and one. -/ -theorem small_binomial_tail (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hsmall : (n : ℝ) * x ≤ 1 / 2) : - (∑ j ∈ Finset.range (n - 1), (n.choose (j + 2) : ℝ) * x ^ (j + 2)) ≤ - 2 * ((n : ℝ) * x) ^ 2 := by - calc - _ ≤ ∑ j ∈ Finset.range (n - 1), ((n : ℝ) * x) ^ 2 * ((n : ℝ) * x) ^ j := by - apply Finset.sum_le_sum - intro j _ - have hc : (n.choose (j + 2) : ℝ) ≤ (n : ℝ) ^ (j + 2) := by - exact_mod_cast Nat.choose_le_pow n (j + 2) - calc - _ ≤ (n : ℝ) ^ (j + 2) * x ^ (j + 2) := - mul_le_mul_of_nonneg_right hc (pow_nonneg hx _) - _ = _ := by rw [← mul_pow, pow_add]; ring - _ = ((n : ℝ) * x) ^ 2 * ∑ j ∈ Finset.range (n - 1), ((n : ℝ) * x) ^ j := by - rw [Finset.mul_sum] - _ ≤ _ := by - have h := small_geometric_sum (n - 1) ⟨mul_nonneg (Nat.cast_nonneg n) hx, hsmall⟩ - nlinarith [mul_le_mul_of_nonneg_left h (sq_nonneg ((n : ℝ) * x))] - -theorem expect_pow_expansion (P : FiniteLaw α) (Z : α → ℝ) (u : ℝ) (t : ℕ) : - P.expect (fun a => (1 + u * Z a) ^ t) = - ∑ j ∈ Finset.range (t + 1), (t.choose j : ℝ) * u ^ j * P.expect (fun a => Z a ^ j) := by - unfold expect - simp_rw [add_comm (1 : ℝ), add_pow, one_pow, mul_one, mul_pow, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro j _ - apply Finset.sum_congr rfl - intro a _ - ring - -theorem expect_small_affine_pow (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) (ht : 2 ≤ t) - (hcenter : P.expect Z = 0) - (hmom : ∀ j ≤ t, |P.expect (fun a => Z a ^ j)| ≤ 2) - {u : ℝ} (hu : (t : ℝ) * |u| ≤ 1 / 2) : - P.expect (fun a => (1 + u * Z a) ^ t) ≤ 1 + 4 * ((t : ℝ) * u) ^ 2 := by - rw [expect_pow_expansion] - have ht' : t + 1 = 2 + (t - 1) := by omega - rw [ht', Finset.sum_range_add] - have hz : P.expect (fun _ : α => (1 : ℝ)) = 1 := by simp [expect, P.total] - simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, - Nat.choose_zero_right, Nat.cast_one, pow_zero, mul_one, one_mul, - Nat.choose_one_right, pow_one] - rw [hz, hcenter] - simp only [mul_zero, add_zero] - have hb : (∑ j ∈ Finset.range (t - 1), (t.choose (2 + j) : ℝ) * u ^ (2 + j) * - P.expect (fun a => Z a ^ (2 + j))) ≤ - 2 * ∑ j ∈ Finset.range (t - 1), (t.choose (j + 2) : ℝ) * |u| ^ (j + 2) := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro j hj - have hjt : 2 + j ≤ t := by have := Finset.mem_range.mp hj; omega - have hm := hmom (2 + j) hjt - calc - _ ≤ |(t.choose (2 + j) : ℝ) * u ^ (2 + j) * P.expect (fun a => Z a ^ (2 + j))| := - le_abs_self _ - _ ≤ (t.choose (2 + j) : ℝ) * |u| ^ (2 + j) * 2 := by - rw [abs_mul, abs_mul, abs_of_nonneg (Nat.cast_nonneg _), abs_pow] - exact mul_le_mul_of_nonneg_left hm (by positivity) - _ = _ := by rw [Nat.add_comm 2 j]; ring - have htail := small_binomial_tail t (abs_nonneg u) hu - have he : ((t : ℝ) * |u|) ^ 2 = ((t : ℝ) * u) ^ 2 := by rw [mul_pow, mul_pow, sq_abs] - rw [he] at htail - linarith - -/-- Only the centered first moment must vanish; lower absolute moments -are obtained from the one available source moment, without boundedness. -/ -theorem expect_lower_moment_le_two (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) - (ht : P.expect (fun a => |Z a| ^ t) ≤ 1) (j : ℕ) (hj : j ≤ t) : - |P.expect (fun a => Z a ^ j)| ≤ 2 := by - have hpoint (a : α) : |Z a| ^ j ≤ 1 + |Z a| ^ t := by - by_cases hx : |Z a| ≤ 1 - · have h := pow_le_one₀ (n := j) (abs_nonneg _) hx - nlinarith [pow_nonneg (abs_nonneg (Z a)) t] - · have h := pow_le_pow_right₀ (le_of_lt (lt_of_not_ge hx)) hj - linarith - calc - _ ≤ ∑ a, |P.mass a * Z a ^ j| := Finset.abs_sum_le_sum_abs _ _ - _ = ∑ a, P.mass a * |Z a| ^ j := by - apply Finset.sum_congr rfl - intro a _ - rw [abs_mul, abs_of_nonneg (P.nonneg a), abs_pow] - _ ≤ ∑ a, P.mass a * (1 + |Z a| ^ t) := by - apply Finset.sum_le_sum - intro a _ - exact mul_le_mul_of_nonneg_left (hpoint a) (P.nonneg a) - _ = 1 + P.expect (fun a => |Z a| ^ t) := by - simp_rw [mul_add, mul_one, Finset.sum_add_distrib, P.total] - rfl - _ ≤ 2 := by linarith - -theorem expect_affine_pow_le (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) - (hmom : ∀ j ≤ t, |P.expect (fun a => Z a ^ j)| ≤ 2) (u : ℝ) : - P.expect (fun a => (1 + u * Z a) ^ t) ≤ 2 * (1 + |u|) ^ t := by - rw [expect_pow_expansion, add_comm (1 : ℝ), add_pow, Finset.mul_sum] - apply Finset.sum_le_sum - intro j hj - have h := hmom j (by have := Finset.mem_range.mp hj; omega) - calc - _ ≤ |(t.choose j : ℝ) * u ^ j * P.expect (fun a => Z a ^ j)| := le_abs_self _ - _ ≤ (t.choose j : ℝ) * |u| ^ j * 2 := by - rw [abs_mul, abs_mul, abs_of_nonneg (Nat.cast_nonneg _), abs_pow] - exact mul_le_mul_of_nonneg_left h (by positivity) - _ = _ := by simp only [one_pow, mul_one]; ring - -/-- Scalar two-smoothness at even moment order; its constant is linear -in that order after taking the square root, as required for tensorization. -/ -theorem scalar_even_moment_unit (P : FiniteLaw α) (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) - (hcenter : P.expect Z = 0) (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) (u : ℝ) : - P.expect (fun a => (1 + u * Z a) ^ (2 * k)) ≤ - (1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2) ^ k := by - have hmom := expect_lower_moment_le_two P Z (2 * k) ht - have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk - have htR : (1 : ℝ) ≤ (2 * k : ℕ) := by exact_mod_cast (show 1 ≤ 2 * k by omega) - have hbase : 1 ≤ 1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2 := by nlinarith [mul_nonneg (sq_nonneg (6 * ((2 * k : ℕ) : ℝ))) (sq_nonneg u)] - by_cases hu : ((2 * k : ℕ) : ℝ) * |u| ≤ 1 / 2 - · have hs := expect_small_affine_pow P Z (2 * k) (by omega) hcenter hmom hu - have hb : 1 + 4 * (((2 * k : ℕ) : ℝ) * u) ^ 2 ≤ - 1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2 := by nlinarith [sq_nonneg (((2 * k : ℕ) : ℝ) * u)] - exact hs.trans (hb.trans (le_self_pow₀ hbase (by omega))) - · have hu' : 1 / 2 ≤ ((2 * k : ℕ) : ℝ) * |u| := le_of_lt (lt_of_not_ge hu) - have hsum : 1 + |u| ≤ 3 * ((2 * k : ℕ) : ℝ) * |u| := by - have hh := mul_le_mul_of_nonneg_right htR (abs_nonneg u) - nlinarith - have hc : (2 : ℝ) ≤ (2 : ℝ) ^ (2 * k) := le_self_pow₀ (by norm_num) (by omega) - calc - _ ≤ 2 * (1 + |u|) ^ (2 * k) := expect_affine_pow_le P Z (2 * k) hmom u - _ ≤ 2 * (3 * ((2 * k : ℕ) : ℝ) * |u|) ^ (2 * k) := by gcongr - _ ≤ 2 ^ (2 * k) * (3 * ((2 * k : ℕ) : ℝ) * |u|) ^ (2 * k) := by - exact mul_le_mul_of_nonneg_right hc (by positivity) - _ = ((6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2) ^ k := by - rw [← mul_pow, pow_mul] - congr 1 - simp only [mul_pow, sq_abs] - ring - _ ≤ _ := pow_le_pow_left₀ (by positivity) (by linarith) k - -/-- Homogeneous version of the scalar even-moment inequality. -/ -theorem scalar_even_moment (P : FiniteLaw α) (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) - (hcenter : P.expect Z = 0) (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) (b v : ℝ) : - P.expect (fun a => (b + v * Z a) ^ (2 * k)) ≤ - (b ^ 2 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * v ^ 2) ^ k := by - have heven (a : α) : |Z a| ^ (2 * k) = Z a ^ (2 * k) := by - rw [pow_mul, sq_abs, ← pow_mul] - have hmoment : P.expect (fun a => Z a ^ (2 * k)) ≤ 1 := by - simpa only [heven] using ht - have hc : 1 ≤ (6 * (2 * k : ℕ) : ℝ) ^ 2 := by - have hn : (1 : ℝ) ≤ (2 * k : ℕ) := by exact_mod_cast (show 1 ≤ 2 * k by omega) - nlinarith - by_cases hb : b = 0 - · subst b - simp only [zero_add, zero_pow (by omega : 2 ≠ 0)] - have he : P.expect (fun a => (v * Z a) ^ (2 * k)) = - v ^ (2 * k) * P.expect (fun a => Z a ^ (2 * k)) := by - simp only [expect, mul_pow, Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - ring - rw [he] - calc - _ ≤ v ^ (2 * k) := by - have hv : 0 ≤ v ^ (2 * k) := by rw [pow_mul]; positivity - nlinarith [mul_le_mul_of_nonneg_left hmoment hv] - _ = (v ^ 2) ^ k := pow_mul v 2 k - _ ≤ _ := pow_le_pow_left₀ (sq_nonneg v) (by nlinarith [mul_le_mul_of_nonneg_right hc (sq_nonneg v)]) k - · have hs := scalar_even_moment_unit P Z k hk hcenter ht (v / b) - have hbpow : 0 ≤ b ^ (2 * k) := by rw [pow_mul]; positivity - have he : P.expect (fun a => (b + v * Z a) ^ (2 * k)) = - b ^ (2 * k) * P.expect (fun a => (1 + v / b * Z a) ^ (2 * k)) := by - unfold expect - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - have h : b + v * Z a = b * (1 + v / b * Z a) := by field_simp [hb] - dsimp only - rw [h, mul_pow] - ring - rw [he] - calc - _ ≤ b ^ (2 * k) * (1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * (v / b) ^ 2) ^ k := - mul_le_mul_of_nonneg_left hs hbpow - _ = _ := by - rw [pow_mul, ← mul_pow] - congr 1 - field_simp [hb] - -theorem weighted_minkowski_bound (P : FiniteLaw α) (k : ℕ) (hk : 1 ≤ k) - (f g : α → ℝ) (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) - (A B : ℝ) (hA : 0 ≤ A) (hB : 0 ≤ B) - (hfa : P.expect (fun a => f a ^ k) ≤ A ^ k) - (hgb : P.expect (fun a => g a ^ k) ≤ B ^ k) : - P.expect (fun a => (f a + g a) ^ k) ≤ (A + B) ^ k := by - have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk - have hk0 : (k : ℝ) ≠ 0 := by positivity - let w : α → ℝ := fun a => P.mass a ^ (1 / (k : ℝ)) - have hw (a : α) : 0 ≤ w a := Real.rpow_nonneg (P.nonneg a) _ - have hwk (a : α) : w a ^ k = P.mass a := by - dsimp [w] - rw [← Real.rpow_natCast, ← Real.rpow_mul (P.nonneg a), one_div_mul_cancel hk0, Real.rpow_one] - have hsingle (F : α → ℝ) (hF : ∀ a, 0 ≤ F a) : - (∑ a, |w a * F a| ^ (k : ℝ)) = P.expect (fun a => F a ^ k) := by - apply Finset.sum_congr rfl - intro a _ - rw [abs_of_nonneg (mul_nonneg (hw a) (hF a)), Real.rpow_natCast, mul_pow, hwk] - have hsum : (∑ a, |w a * f a + w a * g a| ^ (k : ℝ)) = - P.expect (fun a => (f a + g a) ^ k) := by - simp_rw [← mul_add] - exact hsingle _ (fun a => add_nonneg (hf a) (hg a)) - have hm := Real.Lp_add_le Finset.univ (fun a => w a * f a) (fun a => w a * g a) hkR - rw [hsum, hsingle f hf, hsingle g hg] at hm - have hroots (F : α → ℝ) (hF : ∀ a, 0 ≤ F a) (C : ℝ) (hC : 0 ≤ C) - (hFC : P.expect (fun a => F a ^ k) ≤ C ^ k) : - (P.expect (fun a => F a ^ k)) ^ (1 / (k : ℝ)) ≤ C := by - calc - _ ≤ (C ^ k) ^ (1 / (k : ℝ)) := - Real.rpow_le_rpow (Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (pow_nonneg (hF a) k))) hFC (by positivity) - _ = C := by - rw [← Real.rpow_natCast, one_div, Real.rpow_rpow_inv hC hk0] - have hroot : (P.expect (fun a => (f a + g a) ^ k)) ^ (1 / (k : ℝ)) ≤ A + B := - hm.trans (add_le_add (hroots f hf A hA hfa) (hroots g hg B hB hgb)) - have hexp : 0 ≤ P.expect (fun a => (f a + g a) ^ k) := - Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (pow_nonneg (add_nonneg (hf a) (hg a)) k)) - have hp := pow_le_pow_left₀ (Real.rpow_nonneg hexp _) hroot k - rw [← Real.rpow_natCast, ← Real.rpow_mul hexp, one_div_mul_cancel hk0, Real.rpow_one] at hp - exact hp -theorem product_succ_expect_tail (P : FiniteLaw α) (n : ℕ) (f : (Fin (n + 1) → α) → ℝ) : - (P.product (n + 1)).expect f = - (P.product n).expect (fun b => P.expect (fun a => f (Fin.cons a b))) := by - rw [product_succ_expect] - unfold expect - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - apply Finset.sum_congr rfl - intro a _ - ring - -end TraceReconstruction.FiniteLaw -namespace TraceReconstruction -variable {α : Type*} -def multilinear {n : ℕ} (A : (Fin n → Bool) → ℝ) (Z : α → ℝ) (x : Fin n → α) : ℝ := - ∑ σ, A σ * ∏ j, if σ j then Z (x j) else 1 - -def multilinearEnergy {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : ℝ := - ∑ σ, A σ ^ 2 * ∏ j, if σ j then R ^ 2 else 1 - -theorem multilinearEnergy_nonneg {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : - 0 ≤ multilinearEnergy A R := by - apply Finset.sum_nonneg - intro σ _ - apply mul_nonneg (sq_nonneg _) - apply Finset.prod_nonneg - intro j _ - split <;> positivity - -theorem multilinear_cons {n : ℕ} (A : (Fin (n + 1) → Bool) → ℝ) (Z : α → ℝ) - (x : Fin n → α) (a : α) : - multilinear A Z (Fin.cons a x) = - multilinear (fun σ => A (Fin.cons false σ)) Z x + - Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x := by - unfold multilinear - rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp, Fintype.sum_prod_type] - simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_bool, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, - Bool.false_eq_true, ↓reduceIte, one_mul] - rw [Finset.mul_sum] - rw [add_comm] - congr 1 - apply Finset.sum_congr rfl - intro σ _ - ring - -theorem multilinearEnergy_cons {n : ℕ} (A : (Fin (n + 1) → Bool) → ℝ) (R : ℝ) : - multilinearEnergy A R = - multilinearEnergy (fun σ => A (Fin.cons false σ)) R + - R ^ 2 * multilinearEnergy (fun σ => A (Fin.cons true σ)) R := by - unfold multilinearEnergy - rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp, Fintype.sum_prod_type] - simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_bool, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, - Bool.false_eq_true, ↓reduceIte, one_mul] - rw [Finset.mul_sum] - rw [add_comm] - congr 1 - apply Finset.sum_congr rfl - intro σ _ - ring - -/-- The finite-product moment inequality used for every score expansion. -The order-cost is linear per degree, and no boundedness assumption is needed. -/ -theorem multilinear_even_moment {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) - (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) - (n : ℕ) (A : (Fin n → Bool) → ℝ) : - (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) ≤ - (multilinearEnergy A (6 * (2 * k : ℕ))) ^ k := by - induction n with - | zero => - simp only [FiniteLaw.expect, FiniteLaw.product, multilinear, multilinearEnergy, - Fintype.prod_empty, mul_one, one_mul] - simp only [Finset.univ_unique, Finset.sum_singleton] - exact le_of_eq (pow_mul _ 2 k) - | succ n ih => - let A0 : (Fin n → Bool) → ℝ := fun σ => A (Fin.cons false σ) - let A1 : (Fin n → Bool) → ℝ := fun σ => A (Fin.cons true σ) - let R : ℝ := 6 * (2 * k : ℕ) - let F0 : (Fin n → α) → ℝ := fun x => multilinear A0 Z x - let F1 : (Fin n → α) → ℝ := fun x => multilinear A1 Z x - have h0 := ih A0 - have h1 := ih A1 - have hA0 := multilinearEnergy_nonneg A0 R - have hA1 := multilinearEnergy_nonneg A1 R - rw [FiniteLaw.product_succ_expect_tail, multilinearEnergy_cons] - calc - _ ≤ (P.product n).expect (fun x => (F0 x ^ 2 + R ^ 2 * F1 x ^ 2) ^ k) := by - apply FiniteLaw.expect_mono - intro x - simp_rw [multilinear_cons] - have hs := FiniteLaw.scalar_even_moment P Z k hk hcenter ht (F0 x) (F1 x) - simpa only [F0, F1, A0, A1, R, mul_comm] using hs - _ ≤ (multilinearEnergy A0 R + R ^ 2 * multilinearEnergy A1 R) ^ k := by - apply FiniteLaw.weighted_minkowski_bound (P.product n) k hk - (fun x => F0 x ^ 2) (fun x => R ^ 2 * F1 x ^ 2) - (fun x => sq_nonneg _) (fun x => mul_nonneg (sq_nonneg _) (sq_nonneg _)) - (multilinearEnergy A0 R) (R ^ 2 * multilinearEnergy A1 R) hA0 - (mul_nonneg (sq_nonneg _) hA1) - · simpa only [← pow_mul] using h0 - · have he : (P.product n).expect (fun x => (R ^ 2 * F1 x ^ 2) ^ k) = - (R ^ 2) ^ k * (P.product n).expect (fun x => F1 x ^ (2 * k)) := by - unfold FiniteLaw.expect - simp only [mul_pow, ← pow_mul, Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - ring - rw [he, mul_pow (R ^ 2) (multilinearEnergy A1 R)] - exact mul_le_mul_of_nonneg_left h1 (pow_nonneg (sq_nonneg R) k) - _ = _ := rfl - -def monomialDegree {n : ℕ} (σ : Fin n → Bool) : ℕ := - (Finset.univ.filter (fun j => σ j = true)).card - -theorem monomial_weight {n : ℕ} (σ : Fin n → Bool) (R : ℝ) : - (∏ j, if σ j then R ^ 2 else 1) = R ^ (2 * monomialDegree σ) := by - rw [← Finset.prod_filter] - simp only [Finset.prod_const, ← pow_mul, monomialDegree] - -theorem multilinearEnergy_homogeneous {n : ℕ} (A : (Fin n → Bool) → ℝ) - (r : ℕ) (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) (R : ℝ) : - multilinearEnergy A R = R ^ (2 * r) * ∑ σ, A σ ^ 2 := by - unfold multilinearEnergy - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro σ _ - rw [monomial_weight] - by_cases hd : monomialDegree σ = r - · rw [hd, mul_comm] - · rw [hA σ hd, zero_pow (by omega : 2 ≠ 0), zero_mul, mul_zero] - -theorem homogeneous_even_moment {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) - (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) - (n r : ℕ) (A : (Fin n → Bool) → ℝ) - (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) : - (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) ≤ - ((6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2) ^ k := by - have h := multilinear_even_moment P Z k hk hcenter ht n A - rw [multilinearEnergy_homogeneous A r hA] at h - exact h - -/-- Squared L^(2k)-norm for a finite law, expressed without measure coercions. -/ -def FiniteLaw.evenMomentSq {α : Type*} [Fintype α] (P : FiniteLaw α) - (f : α → ℝ) (k : ℕ) : ℝ := - (P.expect (fun a => |f a| ^ (2 * k))) ^ (1 / (k : ℝ)) - -theorem homogeneous_moment_sq {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) - (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) - (n r : ℕ) (A : (Fin n → Bool) → ℝ) - (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) : - (P.product n).evenMomentSq (multilinear A Z) k ≤ - (6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2 := by - have h := homogeneous_even_moment P Z k hk hcenter ht n r A hA - have he (x : Fin n → α) : |multilinear A Z x| ^ (2 * k) = - multilinear A Z x ^ (2 * k) := by rw [pow_mul, sq_abs, ← pow_mul] - unfold FiniteLaw.evenMomentSq - simp_rw [he] - have hn : 0 ≤ (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) := by - apply Finset.sum_nonneg - intro x _ - apply mul_nonneg ((P.product n).nonneg _) - change 0 ≤ multilinear A Z x ^ (2 * k) - rw [pow_mul] - positivity - have hb : 0 ≤ (6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2 := by positivity - calc - _ ≤ (((6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2) ^ k) ^ (1 / (k : ℝ)) := - Real.rpow_le_rpow hn h (by positivity) - _ = _ := by rw [← Real.rpow_natCast, one_div, Real.rpow_rpow_inv hb (by positivity)] -end TraceReconstruction - -namespace TraceReconstruction.FiniteLaw -variable {α : Type*} [Fintype α] -def eventMass (P : FiniteLaw α) (A : Finset α) : ℝ := ∑ a ∈ A, P.mass a - -theorem eventMass_nonneg (P : FiniteLaw α) (A : Finset α) : 0 ≤ P.eventMass A := - Finset.sum_nonneg (fun a _ => P.nonneg a) - -theorem eventMass_le_one (P : FiniteLaw α) (A : Finset α) : P.eventMass A ≤ 1 := by - rw [← P.total] - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun a _ _ => P.nonneg a) - -def condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : FiniteLaw α := by - classical - exact { - mass := fun a => if a ∈ A then P.mass a / P.eventMass A else 0 - nonneg := fun a => by split <;> positivity [P.nonneg a] - total := by - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - rw [← Finset.sum_div] - exact div_self (ne_of_gt hA) } - -theorem overlap_condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : - overlap P (condition P A hA) = P.eventMass A := by - classical - have he (a : α) : min (P.mass a) ((condition P A hA).mass a) = - if a ∈ A then P.mass a else 0 := by - by_cases ha : a ∈ A - · simp only [condition, ha, ↓reduceIte] - apply min_eq_left - apply (le_div_iff₀ hA).mpr - have h := mul_le_mul_of_nonneg_left (P.eventMass_le_one A) (P.nonneg a) - simpa only [mul_one] using h - · simp only [condition, ha, ↓reduceIte, min_eq_right (P.nonneg a)] - unfold overlap - simp_rw [he] - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, eventMass] - -theorem tv_condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : - tv P (condition P A hA) = 1 - P.eventMass A := by - have he := P.overlap_condition A hA - rw [overlap_eq_one_sub_tv] at he - linarith - -/-- Densities relative to one finite reference, preserving the exact normalization. -/ -def withDensity (P : FiniteLaw α) (f : α → ℝ) (hf : ∀ a, 0 ≤ f a) - (hmean : P.expect f = 1) : FiniteLaw α where - mass a := P.mass a * f a - nonneg a := mul_nonneg (P.nonneg a) (hf a) - total := hmean - -theorem density_bad_mass_sq (P : FiniteLaw α) (f : α → ℝ) (A : Finset α) : - (∑ a ∈ A, P.mass a * f a) ^ 2 ≤ - (P.eventMass A) * P.expect (fun a => f a ^ 2) := by - have h := Finset.sum_mul_sq_le_sq_mul_sq A (fun a => Real.sqrt (P.mass a)) - (fun a => Real.sqrt (P.mass a) * f a) - simp only [mul_pow, Real.sq_sqrt (P.nonneg _)] at h - have he : (∑ a ∈ A, Real.sqrt (P.mass a) * (Real.sqrt (P.mass a) * f a)) = - ∑ a ∈ A, P.mass a * f a := by - apply Finset.sum_congr rfl - intro a _ - rw [← mul_assoc, ← pow_two, Real.sq_sqrt (P.nonneg a)] - rw [he] at h - apply h.trans - apply mul_le_mul_of_nonneg_left _ (P.eventMass_nonneg A) - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun a _ _ => - mul_nonneg (P.nonneg a) (sq_nonneg _)) - -/-- Loss from the small-reference-density event by the exact available moment. -/ -theorem low_density_reference_mass (P : FiniteLaw α) (f : α → ℝ) (t : ℕ) - (A : Finset α) (hA : ∀ a ∈ A, f a < 1 / 2) : - P.eventMass A ≤ (2 : ℝ) ^ t * P.expect (fun a => |f a - 1| ^ t) := by - have hlocal (a : α) (ha : a ∈ A) : 1 ≤ (2 : ℝ) ^ t * |f a - 1| ^ t := by - rw [← mul_pow] - apply one_le_pow₀ - have hh := neg_le_abs (f a - 1) - linarith [hA a ha] - calc - _ ≤ ∑ a ∈ A, (2 : ℝ) ^ t * (P.mass a * |f a - 1| ^ t) := by - apply Finset.sum_le_sum - intro a ha - nlinarith [mul_le_mul_of_nonneg_left (hlocal a ha) (P.nonneg a)] - _ ≤ ∑ a, (2 : ℝ) ^ t * (P.mass a * |f a - 1| ^ t) := by - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun a _ _ => by positivity [P.nonneg a]) - _ = _ := by rw [← Finset.mul_sum]; rfl - -/-- Exact common-event likelihood ratio: no lower bound is imposed off the event. -/ -theorem conditioned_density_identity (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) - (hfm : R.expect f = 1) (hgm : R.expect g = 1) - (A : Finset α) (hAf : ∀ a ∈ A, 0 < f a) - (hP : 0 < (R.withDensity f hf hfm).eventMass A) - (hQ : 0 < (R.withDensity g hg hgm).eventMass A) (a : α) : - (condition (R.withDensity g hg hgm) A hQ).mass a = - (condition (R.withDensity f hf hfm) A hP).mass a * - ((R.withDensity f hf hfm).eventMass A / - (R.withDensity g hg hgm).eventMass A * (g a / f a)) := by - classical - by_cases ha : a ∈ A - · simp only [condition, ha, ↓reduceIte] - change R.mass a * g a / (R.withDensity g hg hgm).eventMass A = - R.mass a * f a / (R.withDensity f hf hfm).eventMass A * - ((R.withDensity f hf hfm).eventMass A / - (R.withDensity g hg hgm).eventMass A * (g a / f a)) - field_simp [ne_of_gt hP, ne_of_gt hQ, ne_of_gt (hAf a ha)] - · simp only [condition, ha, ↓reduceIte, zero_mul] - -/-- The raw likelihood score on a common clipping event, at every integer moment. -/ -theorem clipped_raw_moment (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀ a, 0 ≤ f a) (hfm : R.expect f = 1) - (A : Finset α) (hAf : ∀ a ∈ A, 1 / 2 ≤ f a) - (hP : 0 < (R.withDensity f hf hfm).eventMass A) (k : ℕ) : - (condition (R.withDensity f hf hfm) A hP).expect - (fun a => |g a / f a - 1| ^ (k + 1)) ≤ - (2 : ℝ) ^ k / (R.withDensity f hf hfm).eventMass A * - R.expect (fun a => |g a - f a| ^ (k + 1)) := by - classical - have hpoint (a : α) (ha : a ∈ A) : - f a * |g a / f a - 1| ^ (k + 1) ≤ - (2 : ℝ) ^ k * |g a - f a| ^ (k + 1) := by - have hp : 0 < f a := lt_of_lt_of_le (by norm_num) (hAf a ha) - rw [div_sub_one (ne_of_gt hp), abs_div, abs_of_pos hp] - have hi : 0 ≤ 1 / f a := by positivity - have hi2 : 1 / f a ≤ 2 := (div_le_iff₀ hp).mpr (by linarith [hAf a ha]) - calc - _ = |g a - f a| ^ (k + 1) * (1 / f a) ^ k := by - rw [div_pow, div_pow, one_pow, pow_succ (f a)] - field_simp [ne_of_gt hp] - _ ≤ _ := by - simpa only [mul_comm] using mul_le_mul_of_nonneg_left - (pow_le_pow_left₀ hi hi2 k) (show 0 ≤ |g a - f a| ^ (k + 1) by positivity) - unfold expect - calc - _ = ∑ a ∈ A, (R.mass a * (f a * |g a / f a - 1| ^ (k + 1))) / - (R.withDensity f hf hfm).eventMass A := by - simp only [condition, withDensity] - simp_rw [ite_mul, zero_mul] - rw [← Finset.sum_filter] - simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] - apply Finset.sum_congr rfl - intro a _ - ring - _ ≤ ∑ a ∈ A, ((2 : ℝ) ^ k * (R.mass a * |g a - f a| ^ (k + 1))) / - (R.withDensity f hf hfm).eventMass A := by - apply Finset.sum_le_sum - intro a ha - apply div_le_div_of_nonneg_right _ hP.le - nlinarith [mul_le_mul_of_nonneg_left (hpoint a ha) (R.nonneg a)] - _ ≤ ∑ a, ((2 : ℝ) ^ k * (R.mass a * |g a - f a| ^ (k + 1))) / - (R.withDensity f hf hfm).eventMass A := by - apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - intro a _ _ - positivity [R.nonneg a] - _ = _ := by rw [← Finset.sum_div, ← Finset.mul_sum]; ring - -/-- Normalizing the second conditioned law costs only its scalar normalization error. -/ -theorem score_rescaling_moment (P : FiniteLaw α) (u : α → ℝ) - (c : ℝ) (hc : 0 ≤ c) (k : ℕ) : - P.expect (fun a => |c * u a - 1| ^ (k + 1)) ≤ - 2 ^ k * (c ^ (k + 1) * P.expect (fun a => |u a - 1| ^ (k + 1)) + - |c - 1| ^ (k + 1)) := by - have hb (a : α) : |c * u a - 1| ^ (k + 1) ≤ - 2 ^ k * (c ^ (k + 1) * |u a - 1| ^ (k + 1) + |c - 1| ^ (k + 1)) := by - have he : c * u a - 1 = c * (u a - 1) + (c - 1) := by ring - rw [he] - calc - _ ≤ (|c * (u a - 1)| + |c - 1|) ^ (k + 1) := - pow_le_pow_left₀ (abs_nonneg _) (abs_add_le _ _) _ - _ ≤ _ := by - have h := add_pow_le (abs_nonneg (c * (u a - 1))) (abs_nonneg (c - 1)) (k + 1) - simpa only [Nat.add_sub_cancel, abs_mul, abs_of_nonneg hc, mul_pow] using h - unfold expect - calc - _ ≤ ∑ a, P.mass a * (2 ^ k * (c ^ (k + 1) * |u a - 1| ^ (k + 1) + - |c - 1| ^ (k + 1))) := Finset.sum_le_sum (fun a _ => - mul_le_mul_of_nonneg_left (hb a) (P.nonneg a)) - _ = 2 ^ k * (c ^ (k + 1) * (∑ a, P.mass a * |u a - 1| ^ (k + 1)) + - |c - 1| ^ (k + 1) * ∑ a, P.mass a) := by - simp only [mul_add, Finset.sum_add_distrib, Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro a _ <;> ring - _ = _ := by rw [P.total, mul_one] -end TraceReconstruction.FiniteLaw - -namespace TraceReconstruction -namespace FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] -def coordinateProduct {n : ℕ} (P : Fin n → FiniteLaw α) : FiniteLaw (Fin n → α) where - mass x := ∏ i, (P i).mass (x i) - nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg (x i)) - total := by rw [← Fintype.prod_sum]; simp only [FiniteLaw.total, Finset.prod_const_one] - -def mixture (R : FiniteLaw β) (P : β → FiniteLaw α) : FiniteLaw α where - mass a := ∑ b, R.mass b * (P b).mass a - nonneg a := Finset.sum_nonneg (fun b _ => mul_nonneg (R.nonneg b) ((P b).nonneg a)) - total := by - rw [Finset.sum_comm] - simp_rw [← Finset.mul_sum, FiniteLaw.total, mul_one] - exact R.total -end FiniteLaw -variable {α Ω : Type*} [Fintype Ω] - -def selectionCoefficient {n : ℕ} (θ σ : Fin n → Bool) : ℝ := - ∏ i, if σ i then (if θ i then 1 else 0) else 1 - -def selectionDensity {n : ℕ} (θ : Fin n → Bool) (Z : α → ℝ) (x : Fin n → α) : ℝ := - ∏ i, if θ i then 1 + Z (x i) else 1 - -def averagedCoefficient {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (σ : Fin n → Bool) : ℝ := R.expect (fun ω => selectionCoefficient (θ ω) σ) - -def averagedDensity {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (Z : α → ℝ) (x : Fin n → α) : ℝ := R.expect (fun ω => selectionDensity (θ ω) Z x) - -theorem selectionDensity_expansion {n : ℕ} (θ : Fin n → Bool) (Z : α → ℝ) - (x : Fin n → α) : selectionDensity θ Z x = multilinear (selectionCoefficient θ) Z x := by - unfold selectionDensity multilinear selectionCoefficient - simp_rw [← Finset.prod_mul_distrib] - rw [← Fintype.prod_sum (fun (i : Fin n) (b : Bool) => - (if b then (if θ i then (1 : ℝ) else 0) else 1) * (if b then Z (x i) else 1))] - apply Finset.prod_congr rfl - intro i _ - cases θ i <;> simp [add_comm] - -theorem averagedDensity_expansion {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (Z : α → ℝ) (x : Fin n → α) : - averagedDensity R θ Z x = multilinear (averagedCoefficient R θ) Z x := by - unfold averagedDensity averagedCoefficient - simp_rw [selectionDensity_expansion] - unfold multilinear FiniteLaw.expect - simp_rw [Finset.mul_sum, Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro σ _ - apply Finset.sum_congr rfl - intro ω _ - ring - -theorem averagedDensity_difference {n : ℕ} (R : FiniteLaw Ω) - (θ φ : Ω → Fin n → Bool) (Z : α → ℝ) (x : Fin n → α) : - averagedDensity R θ Z x - averagedDensity R φ Z x = - multilinear (fun σ => averagedCoefficient R θ σ - averagedCoefficient R φ σ) Z x := by - rw [averagedDensity_expansion, averagedDensity_expansion] - simp only [multilinear, sub_mul, Finset.sum_sub_distrib] - -theorem coefficient_nonneg {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (σ : Fin n → Bool) : 0 ≤ averagedCoefficient R θ σ := by - apply Finset.sum_nonneg - intro ω _ - apply mul_nonneg (R.nonneg ω) - apply Finset.prod_nonneg - intro i _ - cases σ i <;> cases θ ω i <;> norm_num - -theorem coefficient_le_one {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (σ : Fin n → Bool) : averagedCoefficient R θ σ ≤ 1 := by - rw [← R.total] - apply Finset.sum_le_sum - intro ω _ - have h : selectionCoefficient (θ ω) σ ≤ 1 := by - apply Finset.prod_le_one₀ - · intro i _; cases σ i <;> cases θ ω i <;> norm_num - · intro i _; cases σ i <;> cases θ ω i <;> norm_num - simpa only [mul_one] using mul_le_mul_of_nonneg_left h (R.nonneg ω) - -/-- The coefficient for the empty subset is exactly one, before or after averaging. -/ -theorem averagedCoefficient_empty {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) : - averagedCoefficient R θ (fun _ => false) = 1 := by - simp [averagedCoefficient, selectionCoefficient, FiniteLaw.expect, R.total] - -/-- Exact density of the conditionally independent leaf oracle used in the source. -/ -theorem leaf_oracle_density [Fintype α] {n : ℕ} (P Q : FiniteLaw α) (Z : α → ℝ) - (hscore : ∀ a, Q.mass a = P.mass a * (1 + Z a)) - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (x : Fin n → α) : - (R.mixture (fun ω => FiniteLaw.coordinateProduct (fun i => if θ ω i then Q else P))).mass x = - (∏ i, P.mass (x i)) * averagedDensity R θ Z x := by - unfold FiniteLaw.mixture FiniteLaw.coordinateProduct averagedDensity FiniteLaw.expect - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro ω _ - have he : (∏ i, (if θ ω i then Q else P).mass (x i)) = - (∏ i, P.mass (x i)) * selectionDensity (θ ω) Z x := by - rw [selectionDensity, ← Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro i _ - cases θ ω i <;> simp only [Bool.false_eq_true, ↓reduceIte, mul_one, hscore] - change R.mass ω * (∏ i, (if θ ω i then Q else P).mass (x i)) = - (∏ i, P.mass (x i)) * (R.mass ω * selectionDensity (θ ω) Z x) - rw [he] - ring -end TraceReconstruction - -end -end - -end OAI +import Mathlib + +namespace OAI + +/-! +# FiniteLaw + +Finite laws, common-reference total variation, Hellinger affinity, overlap, scalar moments, hypercontractivity, clipping, and leaf densities. +-/ + +open scoped ENNReal +noncomputable section + +noncomputable section +namespace TraceReconstruction + +/-- Finite probability laws used for the exact statistical transfer. -/ +structure FiniteLaw (α : Type*) [Fintype α] where + mass : α → ℝ + nonneg : ∀ a, 0 ≤ mass a + total : ∑ a, mass a = 1 + +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +def tv (P Q : FiniteLaw α) : ℝ := (1 / 2 : ℝ) * ∑ a, |P.mass a - Q.mass a| +def hellingerSq (P Q : FiniteLaw α) : ℝ := + ∑ a, (Real.sqrt (P.mass a) - Real.sqrt (Q.mass a)) ^ 2 +def affinity (P Q : FiniteLaw α) : ℝ := + ∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) + +theorem affinity_nonneg (P Q : FiniteLaw α) : 0 ≤ affinity P Q := by + apply Finset.sum_nonneg + intro a _; positivity + +theorem hellingerSq_nonneg (P Q : FiniteLaw α) : 0 ≤ hellingerSq P Q := by + apply Finset.sum_nonneg + intro a _; positivity + +theorem hellingerSq_eq (P Q : FiniteLaw α) : + hellingerSq P Q = 2 - 2 * affinity P Q := by + unfold hellingerSq affinity + calc + _ = (∑ a, P.mass a) + (∑ a, Q.mass a) - 2 * ∑ a, + Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) := by + rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _ + have hp := Real.sq_sqrt (P.nonneg a) + have hq := Real.sq_sqrt (Q.nonneg a) + nlinarith only [hp, hq] + _ = _ := by rw [P.total, Q.total]; ring + +theorem affinity_le_one (P Q : FiniteLaw α) : affinity P Q ≤ 1 := by + have h := hellingerSq_nonneg P Q + rw [hellingerSq_eq] at h + linarith + +theorem tv_nonneg (P Q : FiniteLaw α) : 0 ≤ tv P Q := by unfold tv; positivity + +theorem tv_sq_le_hellingerSq (P Q : FiniteLaw α) : + tv P Q ^ 2 ≤ hellingerSq P Q := by + have hpoint (a : α) : |P.mass a - Q.mass a| ^ 2 ≤ + (Real.sqrt (P.mass a) - Real.sqrt (Q.mass a)) ^ 2 * + (Real.sqrt (P.mass a) + Real.sqrt (Q.mass a)) ^ 2 := by + rw [sq_abs] + have hp := Real.sq_sqrt (P.nonneg a) + have hq := Real.sq_sqrt (Q.nonneg a) + nlinarith only [hp, hq, sq_nonneg (P.mass a - Q.mass a)] + have h := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul + (s := Finset.univ) + (r := fun a => |P.mass a - Q.mass a|) + (f := fun a => (Real.sqrt (P.mass a) - Real.sqrt (Q.mass a)) ^ 2) + (g := fun a => (Real.sqrt (P.mass a) + Real.sqrt (Q.mass a)) ^ 2) + (fun a _ => sq_nonneg _) (fun a _ => sq_nonneg _) (fun a _ => hpoint a) + have hplus : (∑ a, (Real.sqrt (P.mass a) + Real.sqrt (Q.mass a)) ^ 2) = + 2 + 2 * affinity P Q := by + unfold affinity + calc + _ = (∑ a, P.mass a) + (∑ a, Q.mass a) + 2 * ∑ a, + Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) := by + rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro a _ + have hp := Real.sq_sqrt (P.nonneg a) + have hq := Real.sq_sqrt (Q.nonneg a) + nlinarith only [hp, hq] + _ = _ := by rw [P.total, Q.total]; ring + rw [hplus] at h + change (∑ a, |P.mass a - Q.mass a|) ^ 2 ≤ hellingerSq P Q * (2 + 2 * affinity P Q) at h + have hbound := mul_le_mul_of_nonneg_left (affinity_le_one P Q) (hellingerSq_nonneg P Q) + unfold tv + nlinarith only [h, hbound] + +theorem tv_le_sqrt_hellingerSq (P Q : FiniteLaw α) : + tv P Q ≤ Real.sqrt (hellingerSq P Q) := by + have h := tv_sq_le_hellingerSq P Q + have hs := Real.sq_sqrt (hellingerSq_nonneg P Q) + have hn := Real.sqrt_nonneg (hellingerSq P Q) + nlinarith only [h, hs, hn] + +def product (P : FiniteLaw α) (m : ℕ) : FiniteLaw (Fin m → α) where + mass a := ∏ j, P.mass (a j) + nonneg a := Finset.prod_nonneg fun j _ => P.nonneg (a j) + total := by + rw [← Fintype.prod_sum] + simp [P.total] + +theorem affinity_product (P Q : FiniteLaw α) (m : ℕ) : + affinity (P.product m) (Q.product m) = affinity P Q ^ m := by + unfold affinity product + simp only + have hexp (a : Fin m → α) : + Real.sqrt (∏ j, P.mass (a j)) * Real.sqrt (∏ j, Q.mass (a j)) = + ∏ j, (Real.sqrt (P.mass (a j)) * Real.sqrt (Q.mass (a j))) := by + rw [Real.sqrt_prod _ (fun j _ => P.nonneg (a j)), + Real.sqrt_prod _ (fun j _ => Q.nonneg (a j)), Finset.prod_mul_distrib] + simp_rw [hexp] + rw [← Fintype.prod_sum (fun (_ : Fin m) a => Real.sqrt (P.mass a) * Real.sqrt (Q.mass a))] + simp + +theorem hellingerSq_product_le (P Q : FiniteLaw α) (m : ℕ) : + hellingerSq (P.product m) (Q.product m) ≤ (m : ℝ) * hellingerSq P Q := by + rw [hellingerSq_eq, affinity_product, hellingerSq_eq] + have ha := affinity_nonneg P Q + have hb := affinity_le_one P Q + have hpow : 1 - affinity P Q ^ m ≤ (m : ℝ) * (1 - affinity P Q) := by + induction m with + | zero => simp + | succ m ih => + rw [pow_succ, Nat.cast_add, Nat.cast_one] + have hmul := mul_le_mul_of_nonneg_right ih ha + have hm : (0 : ℝ) ≤ (m : ℝ) * (1 - affinity P Q) := by positivity + have hmon := mul_le_mul_of_nonneg_left hb hm + nlinarith only [hmul, hmon] + linarith + + +theorem sqrt_sub_one_sq_le {t : ℝ} (ht : 0 ≤ t) : + (Real.sqrt t - 1) ^ 2 ≤ (t - 1) ^ 2 := by + have hs2 := Real.sq_sqrt ht + have hprod := mul_nonneg (Real.sqrt_nonneg t) + (mul_nonneg (show 0 ≤ Real.sqrt t + 2 by positivity) (sq_nonneg (Real.sqrt t - 1))) + conv_rhs => rw [← hs2] + nlinarith only [hprod] + +theorem hellingerSq_le_score (P Q : FiniteLaw α) (Z : α → ℝ) + (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) : + hellingerSq P Q ≤ ∑ a, P.mass a * Z a ^ 2 := by + apply Finset.sum_le_sum + intro a _ + by_cases hp0 : P.mass a = 0 + · have hq0 : Q.mass a = 0 := by rw [hZ, hp0, zero_mul] + simp [hp0, hq0] + have hp : 0 < P.mass a := lt_of_le_of_ne (P.nonneg a) (Ne.symm hp0) + have ht : 0 ≤ 1 + Z a := by + have hq := Q.nonneg a + rw [hZ] at hq + exact nonneg_of_mul_nonneg_right hq hp + have hs := sqrt_sub_one_sq_le ht + have hmul := mul_le_mul_of_nonneg_left hs (P.nonneg a) + have hp2 := Real.sq_sqrt (P.nonneg a) + rw [hZ, Real.sqrt_mul (P.nonneg a)] + calc + _ = P.mass a * (Real.sqrt (1 + Z a) - 1) ^ 2 := by + calc + _ = Real.sqrt (P.mass a) ^ 2 * (Real.sqrt (1 + Z a) - 1) ^ 2 := by ring + _ = _ := by rw [hp2] + _ ≤ P.mass a * ((1 + Z a) - 1) ^ 2 := hmul + _ = _ := by ring + +theorem tv_product_le_sqrt_score (P Q : FiniteLaw α) (Z : α → ℝ) + (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) (m : ℕ) : + tv (P.product m) (Q.product m) ≤ Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) := by + apply (tv_le_sqrt_hellingerSq _ _).trans + apply Real.sqrt_le_sqrt + exact (hellingerSq_product_le P Q m).trans + (mul_le_mul_of_nonneg_left (hellingerSq_le_score P Q Z hZ) (by positivity)) + +def bind (P : FiniteLaw α) (K : α → FiniteLaw β) : FiniteLaw β where + mass b := ∑ a, P.mass a * (K a).mass b + nonneg b := Finset.sum_nonneg fun a _ => mul_nonneg (P.nonneg a) ((K a).nonneg b) + total := by + rw [Finset.sum_comm] + simp_rw [← Finset.mul_sum, (K _).total, mul_one] + exact P.total + +theorem tv_bind_le (P Q : FiniteLaw α) (K : α → FiniteLaw β) : + tv (P.bind K) (Q.bind K) ≤ tv P Q := by + unfold tv bind + simp only + apply mul_le_mul_of_nonneg_left _ (by norm_num) + calc + _ = ∑ b, |∑ a, (P.mass a - Q.mass a) * (K a).mass b| := by + apply Finset.sum_congr rfl + intro b _ + congr 1 + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _; ring + _ ≤ ∑ b, ∑ a, |(P.mass a - Q.mass a) * (K a).mass b| := + Finset.sum_le_sum fun b _ => Finset.abs_sum_le_sum_abs _ _ + _ = ∑ a, |P.mass a - Q.mass a| := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp_rw [abs_mul, abs_of_nonneg ((K a).nonneg _), ← Finset.mul_sum, (K a).total, mul_one] + +theorem tv_triangle (P Q R : FiniteLaw α) : tv P R ≤ tv P Q + tv Q R := by + unfold tv + rw [← mul_add, ← Finset.sum_add_distrib] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Finset.sum_le_sum + intro a _ + exact abs_sub_le _ _ _ + +theorem tv_symm (P Q : FiniteLaw α) : tv P Q = tv Q P := by + unfold tv + congr 1 + apply Finset.sum_congr rfl + intro a _; exact abs_sub_comm _ _ + +theorem expectation_diff_le_tv (P Q : FiniteLaw α) (f : α → ℝ) + (hf : ∀ a, f a ∈ Set.Icc 0 1) : + (∑ a, P.mass a * f a) - (∑ a, Q.mass a * f a) ≤ tv P Q := by + have hz : (∑ a, (P.mass a - Q.mass a)) = 0 := by + rw [Finset.sum_sub_distrib, P.total, Q.total, sub_self] + have h (a : α) : (P.mass a - Q.mass a) * f a ≤ + (|P.mass a - Q.mass a| + (P.mass a - Q.mass a)) / 2 := by + by_cases hd : 0 ≤ P.mass a - Q.mass a + · rw [abs_of_nonneg hd] + have := mul_le_mul_of_nonneg_left (hf a).2 hd + linarith + · rw [abs_of_neg (lt_of_not_ge hd)] + have := mul_nonpos_of_nonpos_of_nonneg (le_of_not_ge hd) (hf a).1 + linarith + calc + _ = ∑ a, (P.mass a - Q.mass a) * f a := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _; ring + _ ≤ ∑ a, (|P.mass a - Q.mass a| + (P.mass a - Q.mass a)) / 2 := + Finset.sum_le_sum fun a _ => h a + _ = tv P Q := by + rw [← Finset.sum_div, Finset.sum_add_distrib, hz, add_zero] + unfold tv + ring + +theorem binary_testing_bound (P Q : FiniteLaw α) (f : α → ℝ) + (hf : ∀ a, f a ∈ Set.Icc 0 1) : + ((∑ a, P.mass a * f a) + (∑ a, Q.mass a * (1 - f a))) / 2 ≤ + (1 + tv P Q) / 2 := by + have h := expectation_diff_le_tv P Q f hf + have heq : (∑ a, Q.mass a * (1 - f a)) = 1 - ∑ a, Q.mass a * f a := by + simp_rw [mul_sub, mul_one, Finset.sum_sub_distrib, Q.total] + rw [heq] + linarith + + +theorem sum_max_eq (P Q : FiniteLaw α) : + (∑ a, max (P.mass a) (Q.mass a)) = 1 + tv P Q := by + have hpoint (a : α) : max (P.mass a) (Q.mass a) = + (P.mass a + Q.mass a + |P.mass a - Q.mass a|) / 2 := by + by_cases h : P.mass a ≤ Q.mass a + · rw [max_eq_right h, abs_of_nonpos (sub_nonpos.mpr h)]; ring + · rw [max_eq_left (le_of_not_ge h), abs_of_nonneg (sub_nonneg.mpr (le_of_not_ge h))]; ring + simp_rw [hpoint] + rw [← Finset.sum_div, Finset.sum_add_distrib, Finset.sum_add_distrib, P.total, Q.total] + unfold tv + ring + +/-- Joint exact recovery of independent binary choices, allowing arbitrary +randomized estimators. No coordinatewise decision rule is assumed. -/ +theorem independent_binary_testing (P Q : FiniteLaw α) (g : ℕ) + (A : (Fin g → α) → (Fin g → Bool) → ℝ) + (hA0 : ∀ z θ, 0 ≤ A z θ) (hA1 : ∀ z, ∑ θ, A z θ = 1) : + (1 / (2 : ℝ) ^ g) * ∑ θ : Fin g → Bool, ∑ z : Fin g → α, + (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) * A z θ ≤ + ((1 + tv P Q) / 2) ^ g := by + classical + have hpoint (z : Fin g → α) (θ : Fin g → Bool) : + (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) ≤ + ∏ j, max (P.mass (z j)) (Q.mass (z j)) := by + apply Finset.prod_le_prod₀ + · intro j _; split <;> first | exact P.nonneg _ | exact Q.nonneg _ + · intro j _; split <;> first | exact le_max_left _ _ | exact le_max_right _ _ + have hsum (z : Fin g → α) : + (∑ θ : Fin g → Bool, + (∏ j, (if θ j then P.mass (z j) else Q.mass (z j))) * A z θ) ≤ + ∏ j, max (P.mass (z j)) (Q.mass (z j)) := by + calc + _ ≤ ∑ θ : Fin g → Bool, + (∏ j, max (P.mass (z j)) (Q.mass (z j))) * A z θ := by + apply Finset.sum_le_sum + intro θ _ + exact mul_le_mul_of_nonneg_right (hpoint z θ) (hA0 z θ) + _ = _ := by rw [← Finset.mul_sum, hA1, mul_one] + rw [Finset.sum_comm] + calc + _ ≤ (1 / (2 : ℝ) ^ g) * ∑ z : Fin g → α, ∏ j, + max (P.mass (z j)) (Q.mass (z j)) := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun z _ => hsum z) (by positivity) + _ = (1 / (2 : ℝ) ^ g) * (∑ a, max (P.mass a) (Q.mass a)) ^ g := by + rw [← Fintype.prod_sum (fun (_ : Fin g) a => max (P.mass a) (Q.mass a))] + simp + _ = _ := by rw [sum_max_eq, div_pow]; ring + +def tensor (P : FiniteLaw α) (R : FiniteLaw β) : FiniteLaw (α × β) where + mass z := P.mass z.1 * R.mass z.2 + nonneg z := mul_nonneg (P.nonneg z.1) (R.nonneg z.2) + total := by + rw [Fintype.sum_prod_type] + simp_rw [← Finset.mul_sum, R.total, mul_one] + exact P.total + +theorem tv_tensor_le (P Q : FiniteLaw α) (R S : FiniteLaw β) : + tv (P.tensor R) (Q.tensor S) ≤ tv P Q + tv R S := by + unfold tv tensor + simp only + rw [Fintype.sum_prod_type, ← mul_add] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + have hpoint (a : α) (b : β) : + |P.mass a * R.mass b - Q.mass a * S.mass b| ≤ + |P.mass a - Q.mass a| * R.mass b + Q.mass a * |R.mass b - S.mass b| := by + calc + _ = |(P.mass a - Q.mass a) * R.mass b + Q.mass a * (R.mass b - S.mass b)| := by + congr 1; ring + _ ≤ |(P.mass a - Q.mass a) * R.mass b| + |Q.mass a * (R.mass b - S.mass b)| := + abs_add_le _ _ + _ = _ := by rw [abs_mul, abs_mul, abs_of_nonneg (R.nonneg b), abs_of_nonneg (Q.nonneg a)] + calc + _ ≤ ∑ a, ∑ b, (|P.mass a - Q.mass a| * R.mass b + Q.mass a * |R.mass b - S.mass b|) := by + apply Finset.sum_le_sum + intro a _ + exact Finset.sum_le_sum fun b _ => hpoint a b + _ = _ := by + simp_rw [Finset.sum_add_distrib, ← Finset.mul_sum, R.total, mul_one] + rw [← Finset.sum_mul, Q.total, one_mul] + +theorem tv_product_succ (P Q : FiniteLaw α) (m : ℕ) : + tv (P.product (m + 1)) (Q.product (m + 1)) = + tv (P.tensor (P.product m)) (Q.tensor (Q.product m)) := by + unfold tv product tensor + simp only + congr 1 + rw [← (Fin.consEquiv (fun _ : Fin (m + 1) => α)).sum_comp] + apply Finset.sum_congr rfl + intro a _ + simp only [Fin.prod_univ_succ, Fin.consEquiv_apply, Fin.cons_zero, Fin.cons_succ] + +theorem tv_product_le (P Q : FiniteLaw α) (m : ℕ) : + tv (P.product m) (Q.product m) ≤ (m : ℝ) * tv P Q := by + induction m with + | zero => simp [tv, product] + | succ m ih => + rw [tv_product_succ] + apply (tv_tensor_le P Q (P.product m) (Q.product m)).trans + simpa only [Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm] using + add_le_add_left ih (tv P Q) + + +theorem affinity_bind_ge (P Q : FiniteLaw α) (K : α → FiniteLaw β) : + affinity P Q ≤ affinity (P.bind K) (Q.bind K) := by + have hpoint (b : β) : + (∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) ≤ + Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b) := by + have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul (s := Finset.univ) + (r := fun a => Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) + (f := fun a => P.mass a * (K a).mass b) (g := fun a => Q.mass a * (K a).mass b) + (fun a _ => mul_nonneg (P.nonneg a) ((K a).nonneg b)) + (fun a _ => mul_nonneg (Q.nonneg a) ((K a).nonneg b)) (by + intro a _ + rw [mul_pow, mul_pow, Real.sq_sqrt (P.nonneg a), Real.sq_sqrt (Q.nonneg a)] + nlinarith only [sq_nonneg ((K a).mass b)]) + have hp2 := Real.sq_sqrt ((P.bind K).nonneg b) + have hq2 := Real.sq_sqrt ((Q.bind K).nonneg b) + have hsq : (Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b)) ^ 2 = + (P.bind K).mass b * (Q.bind K).mass b := by rw [mul_pow, hp2, hq2] + change (∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b) ^ 2 ≤ + (P.bind K).mass b * (Q.bind K).mass b at hcs + have hn : 0 ≤ Real.sqrt ((P.bind K).mass b) * Real.sqrt ((Q.bind K).mass b) := by positivity + nlinarith only [hcs, hsq, hn] + calc + affinity P Q = ∑ b, ∑ a, Real.sqrt (P.mass a) * Real.sqrt (Q.mass a) * (K a).mass b := by + rw [Finset.sum_comm] + simp_rw [← Finset.mul_sum, (K _).total, mul_one] + rfl + _ ≤ _ := Finset.sum_le_sum fun b _ => hpoint b + +theorem hellingerSq_bind_le (P Q : FiniteLaw α) (K : α → FiniteLaw β) : + hellingerSq (P.bind K) (Q.bind K) ≤ hellingerSq P Q := by + rw [hellingerSq_eq, hellingerSq_eq] + linarith [affinity_bind_ge P Q K] + +/-- Restoration of approximate oracle simulations before taking independent +complete observations; the simulation error is charged once per sample. -/ +theorem approximate_score_transfer (P Q : FiniteLaw α) (K : α → FiniteLaw β) + (R S : FiniteLaw β) (Z : α → ℝ) + (hZ : ∀ a, Q.mass a = P.mass a * (1 + Z a)) (E : ℝ) + (hR : tv R (P.bind K) ≤ E) (hS : tv S (Q.bind K) ≤ E) (m : ℕ) : + tv (R.product m) (S.product m) ≤ + Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) + 2 * m * E := by + have hmid : tv ((P.bind K).product m) ((Q.bind K).product m) ≤ + Real.sqrt ((m : ℝ) * ∑ a, P.mass a * Z a ^ 2) := by + apply (tv_le_sqrt_hellingerSq _ _).trans + apply Real.sqrt_le_sqrt + apply (hellingerSq_product_le _ _ m).trans + exact mul_le_mul_of_nonneg_left + ((hellingerSq_bind_le P Q K).trans (hellingerSq_le_score P Q Z hZ)) (by positivity) + have hr := (tv_product_le R (P.bind K) m).trans + (mul_le_mul_of_nonneg_left hR (by positivity : (0 : ℝ) ≤ m)) + have hs := (tv_product_le S (Q.bind K) m).trans + (mul_le_mul_of_nonneg_left hS (by positivity : (0 : ℝ) ≤ m)) + rw [tv_symm (S.product m)] at hs + have htri1 := tv_triangle (R.product m) ((P.bind K).product m) (S.product m) + have htri2 := tv_triangle ((P.bind K).product m) ((Q.bind K).product m) (S.product m) + linarith + +def overlap (P Q : FiniteLaw α) : ℝ := ∑ a, min (P.mass a) (Q.mass a) + +theorem overlap_eq_one_sub_tv (P Q : FiniteLaw α) : overlap P Q = 1 - tv P Q := by + have hm : overlap P Q + (∑ a, max (P.mass a) (Q.mass a)) = 2 := by + rw [overlap, ← Finset.sum_add_distrib] + simp_rw [min_add_max] + rw [Finset.sum_add_distrib, P.total, Q.total] + norm_num + rw [sum_max_eq] at hm + linarith + +theorem overlap_nonneg (P Q : FiniteLaw α) : 0 ≤ overlap P Q := by + apply Finset.sum_nonneg + intro a _ + exact le_min (P.nonneg a) (Q.nonneg a) + +def commonPart (P Q : FiniteLaw α) (h : 0 < overlap P Q) : FiniteLaw α where + mass a := min (P.mass a) (Q.mass a) / overlap P Q + nonneg a := div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le + total := by rw [← Finset.sum_div]; exact div_self h.ne' + +theorem commonPart_le_left (P Q : FiniteLaw α) (h : 0 < overlap P Q) + {ω : ℝ} (hω : ω ≤ overlap P Q) (a : α) : + ω * (commonPart P Q h).mass a ≤ P.mass a := by + change ω * (min (P.mass a) (Q.mass a) / overlap P Q) ≤ _ + calc + _ ≤ overlap P Q * (min (P.mass a) (Q.mass a) / overlap P Q) := + mul_le_mul_of_nonneg_right hω (div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le) + _ = min (P.mass a) (Q.mass a) := by field_simp + _ ≤ _ := min_le_left _ _ + +def remainderLaw (P H : FiniteLaw α) (ω : ℝ) (hω : ω < 1) + (hdom : ∀ a, ω * H.mass a ≤ P.mass a) : FiniteLaw α where + mass a := (P.mass a - ω * H.mass a) / (1 - ω) + nonneg a := div_nonneg (sub_nonneg.mpr (hdom a)) (sub_pos.mpr hω).le + total := by + rw [← Finset.sum_div, Finset.sum_sub_distrib, ← Finset.mul_sum, P.total, H.total, mul_one] + exact div_self (sub_pos.mpr hω).ne' + +theorem common_part_decomposition (P Q : FiniteLaw α) {ω : ℝ} + (hω : ω ∈ Set.Ioo 0 1) (hov : ω ≤ overlap P Q) : + ∃ H P' Q' : FiniteLaw α, + (∀ a, P.mass a = ω * H.mass a + (1 - ω) * P'.mass a) ∧ + (∀ a, Q.mass a = ω * H.mass a + (1 - ω) * Q'.mass a) := by + have h : 0 < overlap P Q := lt_of_lt_of_le hω.1 hov + let H := commonPart P Q h + have hP : ∀ a, ω * H.mass a ≤ P.mass a := commonPart_le_left P Q h hov + have hQ : ∀ a, ω * H.mass a ≤ Q.mass a := by + intro a + change ω * (min (P.mass a) (Q.mass a) / overlap P Q) ≤ _ + calc + _ ≤ overlap P Q * (min (P.mass a) (Q.mass a) / overlap P Q) := + mul_le_mul_of_nonneg_right hov (div_nonneg (le_min (P.nonneg a) (Q.nonneg a)) h.le) + _ = min (P.mass a) (Q.mass a) := by field_simp + _ ≤ _ := min_le_right _ _ + refine ⟨H, remainderLaw P H ω hω.2 hP, remainderLaw Q H ω hω.2 hQ, ?_, ?_⟩ + · intro a + change P.mass a = ω * H.mass a + (1 - ω) * ((P.mass a - ω * H.mass a) / (1 - ω)) + field_simp [(sub_pos.mpr hω.2).ne'] + ring + · intro a + change Q.mass a = ω * H.mass a + (1 - ω) * ((Q.mass a - ω * H.mass a) / (1 - ω)) + field_simp [(sub_pos.mpr hω.2).ne'] + ring + +end FiniteLaw +end TraceReconstruction + +namespace TraceReconstruction.FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +def prod (P : FiniteLaw α) (Q : FiniteLaw β) : FiniteLaw (α × β) where + mass x := P.mass x.1 * Q.mass x.2 + nonneg x := mul_nonneg (P.nonneg _) (Q.nonneg _) + total := by + rw [Fintype.sum_prod_type] + simp_rw [← Finset.mul_sum, Q.total, mul_one] + exact P.total + +def expect (P : FiniteLaw α) (f : α → ℝ) : ℝ := ∑ a, P.mass a * f a + +theorem expect_const (P : FiniteLaw α) (c : ℝ) : P.expect (fun _ => c) = c := by + unfold expect + rw [← Finset.sum_mul, P.total, one_mul] + +theorem expect_mono (P : FiniteLaw α) {f g : α → ℝ} (h : ∀ a, f a ≤ g a) : + P.expect f ≤ P.expect g := Finset.sum_le_sum fun a _ => + mul_le_mul_of_nonneg_left (h a) (P.nonneg a) + +theorem expect_prod (P : FiniteLaw α) (Q : FiniteLaw β) (f : α × β → ℝ) : + (P.prod Q).expect f = P.expect (fun a => Q.expect (fun b => f (a, b))) := by + unfold expect prod + rw [Fintype.sum_prod_type] + simp_rw [Finset.mul_sum, mul_assoc] + +/-- Association is only used for increasing likelihood-threshold events. -/ +def Associated [Preorder α] (P : FiniteLaw α) : Prop := + ∀ f g : α → ℝ, Monotone f → Monotone g → + P.expect f * P.expect g ≤ P.expect (fun a => f a * g a) + +theorem associated_linearOrder [LinearOrder α] (P : FiniteLaw α) : P.Associated := by + intro f g hf hg + have hn (a b : α) : 0 ≤ (f a - f b) * (g a - g b) := by + rcases le_total a b with hab | hba + · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (hf hab)) + (sub_nonpos.mpr (hg hab)) + · exact mul_nonneg (sub_nonneg.mpr (hf hba)) (sub_nonneg.mpr (hg hba)) + have h := Finset.sum_nonneg (s := Finset.univ) (fun a _ => + Finset.sum_nonneg (s := Finset.univ) (fun b _ => mul_nonneg (mul_nonneg (P.nonneg a) + (P.nonneg b)) (hn a b))) + have hid : (∑ a, ∑ b, P.mass a * P.mass b * ((f a - f b) * (g a - g b))) = + 2 * (P.expect (fun a => f a * g a) - P.expect f * P.expect g) := by + have hp (a b : α) : P.mass a * P.mass b * ((f a - f b) * (g a - g b)) = + (P.mass a * (f a * g a)) * P.mass b + P.mass a * (P.mass b * (f b * g b)) - + (P.mass a * f a) * (P.mass b * g b) - (P.mass a * g a) * (P.mass b * f b) := by ring + simp_rw [hp, Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.sum_mul, P.total, one_mul, mul_one] + unfold expect + ring + rw [hid] at h + linarith + +theorem Associated.prod [Preorder α] [Preorder β] {P : FiniteLaw α} {Q : FiniteLaw β} + (hP : P.Associated) (hQ : Q.Associated) : (P.prod Q).Associated := by + intro f g hf hg + rw [expect_prod, expect_prod, expect_prod] + calc + _ ≤ P.expect (fun a => Q.expect (fun b => f (a, b)) * Q.expect (fun b => g (a, b))) := by + apply hP + · intro a a' ha + exact Q.expect_mono (fun b => hf ⟨ha, le_rfl⟩) + · intro a a' ha + exact Q.expect_mono (fun b => hg ⟨ha, le_rfl⟩) + _ ≤ _ := by + apply P.expect_mono + intro a + apply hQ + · intro b b' hb; exact hf ⟨le_rfl, hb⟩ + · intro b b' hb; exact hg ⟨le_rfl, hb⟩ + +theorem product_succ_expect (P : FiniteLaw α) (n : ℕ) (f : (Fin (n + 1) → α) → ℝ) : + (P.product (n + 1)).expect f = + P.expect (fun a => (P.product n).expect (fun b => f (Fin.cons a b))) := by + unfold expect product + rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => α)).sum_comp, Fintype.sum_prod_type] + simp_rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + change (∏ j, P.mass ((Fin.cons a b : Fin (n + 1) → α) j)) * f (Fin.cons a b) = _ + rw [Fin.prod_univ_succ] + simp only [Fin.cons_zero, Fin.cons_succ] + ring + +theorem associated_product [Preorder α] (P : FiniteLaw α) (hP : P.Associated) (n : ℕ) : + (P.product n).Associated := by + induction n with + | zero => + intro f g _ _ + simp [expect, product] + | succ n ih => + intro f g hf hg + rw [product_succ_expect, product_succ_expect, product_succ_expect] + have hcons {a a' : α} {b b' : Fin n → α} (ha : a ≤ a') (hb : b ≤ b') : + (Fin.cons a b : Fin (n + 1) → α) ≤ (Fin.cons a' b' : Fin (n + 1) → α) := by + intro j + refine Fin.cases ?_ (fun i => ?_) j + · exact ha + · exact hb i + calc + _ ≤ P.expect (fun a => (P.product n).expect (fun b => f (Fin.cons a b)) * + (P.product n).expect (fun b => g (Fin.cons a b))) := by + apply hP + · intro a a' ha + exact (P.product n).expect_mono (fun b => hf (hcons ha le_rfl)) + · intro a a' ha + exact (P.product n).expect_mono (fun b => hg (hcons ha le_rfl)) + _ ≤ _ := by + apply P.expect_mono + intro a + apply ih + · intro b b' hb; exact hf (hcons le_rfl hb) + · intro b b' hb; exact hg (hcons le_rfl hb) + +/-- An elementary Paley--Zygmund bound at threshold 1/2, for a density. -/ +theorem density_threshold_mass (P : FiniteLaw α) (f : α → ℝ) + (hmean : P.expect f = 1) : + (1 : ℝ) / 4 ≤ + (P.expect (fun a => if 1 / 2 ≤ f a then 1 else 0)) * P.expect (fun a => f a ^ 2) := by + classical + let S : Finset α := Finset.univ.filter (fun a => 1 / 2 ≤ f a) + have hsmall : (∑ a ∈ Finset.univ \ S, P.mass a * f a) ≤ 1 / 2 := by + calc + _ ≤ ∑ a ∈ Finset.univ \ S, P.mass a * (1 / 2) := by + apply Finset.sum_le_sum + intro a ha + have hnot : ¬ 1 / 2 ≤ f a := by simpa [S] using (Finset.mem_sdiff.mp ha).2 + exact mul_le_mul_of_nonneg_left (le_of_lt (lt_of_not_ge hnot)) (P.nonneg a) + _ ≤ ∑ a, P.mass a * (1 / 2) := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.sdiff_subset) + intro a _ _; positivity [P.nonneg a] + _ = 1 / 2 := P.expect_const _ + have hlarge : 1 / 2 ≤ ∑ a ∈ S, P.mass a * f a := by + have hsplit := Finset.sum_sdiff (Finset.subset_univ S) (f := fun a => P.mass a * f a) + change (∑ a, P.mass a * f a) = 1 at hmean + rw [hmean] at hsplit + linarith + have hc := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul (s := S) + (r := fun a => P.mass a * f a) (f := P.mass) (g := fun a => P.mass a * f a ^ 2) + (fun a _ => P.nonneg a) (fun a _ => by positivity [P.nonneg a]) + (fun a _ => by nlinarith) + have ht : (∑ a ∈ S, P.mass a * f a ^ 2) ≤ P.expect (fun a => f a ^ 2) := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ S) + intro a _ _; positivity [P.nonneg a] + have hmass : P.expect (fun a => if 1 / 2 ≤ f a then 1 else 0) = ∑ a ∈ S, P.mass a := by + unfold expect S + simp_rw [mul_ite, mul_one, mul_zero] + rw [Finset.sum_filter] + rw [hmass] + have hm := mul_le_mul_of_nonneg_left ht (Finset.sum_nonneg (s := S) (fun a _ => P.nonneg a)) + nlinarith + +/-- The common-density overlap used for consecutive pure primitive runs. -/ +theorem increasing_density_overlap [Preorder α] (P : FiniteLaw α) (hP : P.Associated) + (f g : α → ℝ) (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) + (hfm : Monotone f) (hgm : Monotone g) + (hf1 : P.expect f = 1) (hg1 : P.expect g = 1) : + (1 : ℝ) / 32 ≤ P.expect (fun a => min (f a) (g a)) * + P.expect (fun a => f a ^ 2) * P.expect (fun a => g a ^ 2) := by + let F : α → ℝ := fun a => if 1 / 2 ≤ f a then 1 else 0 + let G : α → ℝ := fun a => if 1 / 2 ≤ g a then 1 else 0 + have hF : Monotone F := by + intro a b hab + dsimp [F] + split_ifs with ha hb hb + · rfl + · exact False.elim (hb (ha.trans (hfm hab))) + · norm_num + · rfl + have hG : Monotone G := by + intro a b hab + dsimp [G] + split_ifs with ha hb hb + · rfl + · exact False.elim (hb (ha.trans (hgm hab))) + · norm_num + · rfl + have hcorr := hP F G hF hG + have hpoint : ∀ a, (1 / 2 : ℝ) * (F a * G a) ≤ min (f a) (g a) := by + intro a + dsimp [F, G] + split_ifs <;> simp only [mul_one, mul_zero] + · exact le_min ‹_› ‹_› + all_goals exact le_min (hf a) (hg a) + have hint := P.expect_mono hpoint + have heq : P.expect (fun a => (1 / 2 : ℝ) * (F a * G a)) = + (1 / 2 : ℝ) * P.expect (fun a => F a * G a) := by + unfold expect + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _; ring + rw [heq] at hint + have hfm2 : 0 ≤ P.expect (fun a => f a ^ 2) := + Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) + have hgm2 : 0 ≤ P.expect (fun a => g a ^ 2) := + Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) + have hff := density_threshold_mass P f hf1 + have hgg := density_threshold_mass P g hg1 + change 1 / 4 ≤ P.expect F * P.expect (fun a => f a ^ 2) at hff + change 1 / 4 ≤ P.expect G * P.expect (fun a => g a ^ 2) at hgg + have hmul := mul_le_mul hff hgg (by norm_num : (0 : ℝ) ≤ 1 / 4) (by linarith : + 0 ≤ P.expect F * P.expect (fun a => f a ^ 2)) + have hcomb : (1 / 2 : ℝ) * (P.expect F * P.expect G) ≤ + P.expect (fun a => min (f a) (g a)) := by linarith + have hmul2 := mul_le_mul_of_nonneg_right hcomb (mul_nonneg hfm2 hgm2) + nlinarith only [hmul, hmul2] + +end TraceReconstruction.FiniteLaw + +namespace TraceReconstruction.FiniteLaw +variable {α : Type*} [Fintype α] +/-- Orientation `false` uses P,Q in chronological order; true reverses them. -/ +def orientedProd (P Q : FiniteLaw α) (b : Bool) : FiniteLaw (α × α) := + if b then Q.prod P else P.prod Q + +def pairedHiddenMass (H : FiniteLaw α) (ω : ℝ) (z : α × α) : ℝ := + ω ^ 2 * H.mass z.1 * H.mass z.2 + +theorem sum_pairedHiddenMass (H : FiniteLaw α) (ω : ℝ) : + (∑ z, pairedHiddenMass H ω z) = ω ^ 2 := by + unfold pairedHiddenMass + rw [Fintype.sum_prod_type] + simp_rw [← Finset.mul_sum, H.total, mul_one] + rw [← Finset.mul_sum, H.total, mul_one] + +theorem pairedHiddenMass_le (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) + (b : Bool) (z : α × α) : pairedHiddenMass H ω z ≤ (orientedProd P Q b).mass z := by + have hm (R S : FiniteLaw α) (hR : ∀ a, ω * H.mass a ≤ R.mass a) + (hS : ∀ a, ω * H.mass a ≤ S.mass a) : + pairedHiddenMass H ω z ≤ R.mass z.1 * S.mass z.2 := by + calc + _ = (ω * H.mass z.1) * (ω * H.mass z.2) := by unfold pairedHiddenMass; ring + _ ≤ _ := mul_le_mul (hR z.1) (hS z.2) + (mul_nonneg hω (H.nonneg _)) (R.nonneg _) + cases b + · exact hm P Q hP hQ + · exact hm Q P hQ hP + +/-- None is the joint hidden flag; a visible flag reports the true orientation. -/ +def pairedFlagMass (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) + (z : Option Bool × (α × α)) : ℝ := + match z.1 with + | none => pairedHiddenMass H ω z.2 + | some c => if c = b then (orientedProd P Q b).mass z.2 - pairedHiddenMass H ω z.2 else 0 + +theorem pairedFlagMass_nonneg (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) + (b : Bool) (z : Option Bool × (α × α)) : 0 ≤ pairedFlagMass P Q H ω b z := by + unfold pairedFlagMass + split + · unfold pairedHiddenMass + positivity [H.nonneg z.2.1, H.nonneg z.2.2] + · split_ifs + · exact sub_nonneg.mpr (pairedHiddenMass_le P Q H hω hP hQ b z.2) + · rfl + +theorem pairedFlagMass_sum (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) : + (∑ z, pairedFlagMass P Q H ω b z) = 1 := by + rw [Fintype.sum_prod_type, Finset.sum_comm] + have hp (z : α × α) : (∑ c : Option Bool, pairedFlagMass P Q H ω b (c, z)) = + (orientedProd P Q b).mass z := by + cases b <;> simp [pairedFlagMass, Fintype.sum_option ] + simp_rw [hp] + exact (orientedProd P Q b).total + +def pairedFlagLaw (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω * H.mass a ≤ P.mass a) (hQ : ∀ a, ω * H.mass a ≤ Q.mass a) + (b : Bool) : FiniteLaw (Option Bool × (α × α)) := + ⟨pairedFlagMass P Q H ω b, pairedFlagMass_nonneg P Q H hω hP hQ b, + pairedFlagMass_sum P Q H ω b⟩ + +/-- Forgetting the report recovers conditional independence for each orientation. -/ +theorem pairedFlag_simulation (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) (z : α × α) : + (∑ c : Option Bool, pairedFlagMass P Q H ω b (c, z)) = + (orientedProd P Q b).mass z := by + cases b <;> simp [pairedFlagMass, Fintype.sum_option ] + +/-- Hidden reports carry exactly zero information about the fair orientation, +even after both strings have been observed. -/ +theorem pairedFlag_hidden_joint (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) (z : α × α) : + (1 / 2 : ℝ) * pairedFlagMass P Q H ω b (none, z) = + (1 / 2 : ℝ) * (ω ^ 2 * (H.prod H).mass z) := by + unfold pairedFlagMass pairedHiddenMass prod + ring + +theorem pairedFlag_hidden_probability (P Q H : FiniteLaw α) (ω : ℝ) (b : Bool) : + (∑ z, pairedFlagMass P Q H ω b (none, z)) = ω ^ 2 := sum_pairedHiddenMass H ω + +end TraceReconstruction.FiniteLaw + +namespace TraceReconstruction.FiniteLaw +variable {α : Type*} [Fintype α] +theorem small_geometric_sum (n : ℕ) {x : ℝ} (hx : x ∈ Set.Icc 0 (1 / 2)) : + (∑ j ∈ Finset.range n, x ^ j) ≤ 2 := by + have he := geom_sum_mul x n + have hn : 0 ≤ ∑ j ∈ Finset.range n, x ^ j := + Finset.sum_nonneg (fun j _ => pow_nonneg hx.1 j) + have hp := pow_nonneg hx.1 n + nlinarith [mul_le_mul_of_nonneg_left hx.2 hn] + +/-- Elementary tail of a binomial polynomial after cancelling orders zero and one. -/ +theorem small_binomial_tail (n : ℕ) {x : ℝ} (hx : 0 ≤ x) (hsmall : (n : ℝ) * x ≤ 1 / 2) : + (∑ j ∈ Finset.range (n - 1), (n.choose (j + 2) : ℝ) * x ^ (j + 2)) ≤ + 2 * ((n : ℝ) * x) ^ 2 := by + calc + _ ≤ ∑ j ∈ Finset.range (n - 1), ((n : ℝ) * x) ^ 2 * ((n : ℝ) * x) ^ j := by + apply Finset.sum_le_sum + intro j _ + have hc : (n.choose (j + 2) : ℝ) ≤ (n : ℝ) ^ (j + 2) := by + exact_mod_cast Nat.choose_le_pow n (j + 2) + calc + _ ≤ (n : ℝ) ^ (j + 2) * x ^ (j + 2) := + mul_le_mul_of_nonneg_right hc (pow_nonneg hx _) + _ = _ := by rw [← mul_pow, pow_add]; ring + _ = ((n : ℝ) * x) ^ 2 * ∑ j ∈ Finset.range (n - 1), ((n : ℝ) * x) ^ j := by + rw [Finset.mul_sum] + _ ≤ _ := by + have h := small_geometric_sum (n - 1) ⟨mul_nonneg (Nat.cast_nonneg n) hx, hsmall⟩ + nlinarith [mul_le_mul_of_nonneg_left h (sq_nonneg ((n : ℝ) * x))] + +theorem expect_pow_expansion (P : FiniteLaw α) (Z : α → ℝ) (u : ℝ) (t : ℕ) : + P.expect (fun a => (1 + u * Z a) ^ t) = + ∑ j ∈ Finset.range (t + 1), (t.choose j : ℝ) * u ^ j * P.expect (fun a => Z a ^ j) := by + unfold expect + simp_rw [add_comm (1 : ℝ), add_pow, one_pow, mul_one, mul_pow, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro a _ + ring + +theorem expect_small_affine_pow (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) (ht : 2 ≤ t) + (hcenter : P.expect Z = 0) + (hmom : ∀ j ≤ t, |P.expect (fun a => Z a ^ j)| ≤ 2) + {u : ℝ} (hu : (t : ℝ) * |u| ≤ 1 / 2) : + P.expect (fun a => (1 + u * Z a) ^ t) ≤ 1 + 4 * ((t : ℝ) * u) ^ 2 := by + rw [expect_pow_expansion] + have ht' : t + 1 = 2 + (t - 1) := by omega + rw [ht', Finset.sum_range_add] + have hz : P.expect (fun _ : α => (1 : ℝ)) = 1 := by simp [expect, P.total] + simp only [Finset.sum_range_succ, Finset.sum_range_zero, zero_add, + Nat.choose_zero_right, Nat.cast_one, pow_zero, mul_one, one_mul, + Nat.choose_one_right, pow_one] + rw [hz, hcenter] + simp only [mul_zero, add_zero] + have hb : (∑ j ∈ Finset.range (t - 1), (t.choose (2 + j) : ℝ) * u ^ (2 + j) * + P.expect (fun a => Z a ^ (2 + j))) ≤ + 2 * ∑ j ∈ Finset.range (t - 1), (t.choose (j + 2) : ℝ) * |u| ^ (j + 2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro j hj + have hjt : 2 + j ≤ t := by have := Finset.mem_range.mp hj; omega + have hm := hmom (2 + j) hjt + calc + _ ≤ |(t.choose (2 + j) : ℝ) * u ^ (2 + j) * P.expect (fun a => Z a ^ (2 + j))| := + le_abs_self _ + _ ≤ (t.choose (2 + j) : ℝ) * |u| ^ (2 + j) * 2 := by + rw [abs_mul, abs_mul, abs_of_nonneg (Nat.cast_nonneg _), abs_pow] + exact mul_le_mul_of_nonneg_left hm (by positivity) + _ = _ := by rw [Nat.add_comm 2 j]; ring + have htail := small_binomial_tail t (abs_nonneg u) hu + have he : ((t : ℝ) * |u|) ^ 2 = ((t : ℝ) * u) ^ 2 := by rw [mul_pow, mul_pow, sq_abs] + rw [he] at htail + linarith + +/-- Only the centered first moment must vanish; lower absolute moments +are obtained from the one available source moment, without boundedness. -/ +theorem expect_lower_moment_le_two (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) + (ht : P.expect (fun a => |Z a| ^ t) ≤ 1) (j : ℕ) (hj : j ≤ t) : + |P.expect (fun a => Z a ^ j)| ≤ 2 := by + have hpoint (a : α) : |Z a| ^ j ≤ 1 + |Z a| ^ t := by + by_cases hx : |Z a| ≤ 1 + · have h := pow_le_one₀ (n := j) (abs_nonneg _) hx + nlinarith [pow_nonneg (abs_nonneg (Z a)) t] + · have h := pow_le_pow_right₀ (le_of_lt (lt_of_not_ge hx)) hj + linarith + calc + _ ≤ ∑ a, |P.mass a * Z a ^ j| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ a, P.mass a * |Z a| ^ j := by + apply Finset.sum_congr rfl + intro a _ + rw [abs_mul, abs_of_nonneg (P.nonneg a), abs_pow] + _ ≤ ∑ a, P.mass a * (1 + |Z a| ^ t) := by + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_left (hpoint a) (P.nonneg a) + _ = 1 + P.expect (fun a => |Z a| ^ t) := by + simp_rw [mul_add, mul_one, Finset.sum_add_distrib, P.total] + rfl + _ ≤ 2 := by linarith + +theorem expect_affine_pow_le (P : FiniteLaw α) (Z : α → ℝ) (t : ℕ) + (hmom : ∀ j ≤ t, |P.expect (fun a => Z a ^ j)| ≤ 2) (u : ℝ) : + P.expect (fun a => (1 + u * Z a) ^ t) ≤ 2 * (1 + |u|) ^ t := by + rw [expect_pow_expansion, add_comm (1 : ℝ), add_pow, Finset.mul_sum] + apply Finset.sum_le_sum + intro j hj + have h := hmom j (by have := Finset.mem_range.mp hj; omega) + calc + _ ≤ |(t.choose j : ℝ) * u ^ j * P.expect (fun a => Z a ^ j)| := le_abs_self _ + _ ≤ (t.choose j : ℝ) * |u| ^ j * 2 := by + rw [abs_mul, abs_mul, abs_of_nonneg (Nat.cast_nonneg _), abs_pow] + exact mul_le_mul_of_nonneg_left h (by positivity) + _ = _ := by simp only [one_pow, mul_one]; ring + +/-- Scalar two-smoothness at even moment order; its constant is linear +in that order after taking the square root, as required for tensorization. -/ +theorem scalar_even_moment_unit (P : FiniteLaw α) (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) + (hcenter : P.expect Z = 0) (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) (u : ℝ) : + P.expect (fun a => (1 + u * Z a) ^ (2 * k)) ≤ + (1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2) ^ k := by + have hmom := expect_lower_moment_le_two P Z (2 * k) ht + have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk + have htR : (1 : ℝ) ≤ (2 * k : ℕ) := by exact_mod_cast (show 1 ≤ 2 * k by omega) + have hbase : 1 ≤ 1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2 := by nlinarith [mul_nonneg (sq_nonneg (6 * ((2 * k : ℕ) : ℝ))) (sq_nonneg u)] + by_cases hu : ((2 * k : ℕ) : ℝ) * |u| ≤ 1 / 2 + · have hs := expect_small_affine_pow P Z (2 * k) (by omega) hcenter hmom hu + have hb : 1 + 4 * (((2 * k : ℕ) : ℝ) * u) ^ 2 ≤ + 1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2 := by nlinarith [sq_nonneg (((2 * k : ℕ) : ℝ) * u)] + exact hs.trans (hb.trans (le_self_pow₀ hbase (by omega))) + · have hu' : 1 / 2 ≤ ((2 * k : ℕ) : ℝ) * |u| := le_of_lt (lt_of_not_ge hu) + have hsum : 1 + |u| ≤ 3 * ((2 * k : ℕ) : ℝ) * |u| := by + have hh := mul_le_mul_of_nonneg_right htR (abs_nonneg u) + nlinarith + have hc : (2 : ℝ) ≤ (2 : ℝ) ^ (2 * k) := le_self_pow₀ (by norm_num) (by omega) + calc + _ ≤ 2 * (1 + |u|) ^ (2 * k) := expect_affine_pow_le P Z (2 * k) hmom u + _ ≤ 2 * (3 * ((2 * k : ℕ) : ℝ) * |u|) ^ (2 * k) := by gcongr + _ ≤ 2 ^ (2 * k) * (3 * ((2 * k : ℕ) : ℝ) * |u|) ^ (2 * k) := by + exact mul_le_mul_of_nonneg_right hc (by positivity) + _ = ((6 * (2 * k : ℕ) : ℝ) ^ 2 * u ^ 2) ^ k := by + rw [← mul_pow, pow_mul] + congr 1 + simp only [mul_pow, sq_abs] + ring + _ ≤ _ := pow_le_pow_left₀ (by positivity) (by linarith) k + +/-- Homogeneous version of the scalar even-moment inequality. -/ +theorem scalar_even_moment (P : FiniteLaw α) (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) + (hcenter : P.expect Z = 0) (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) (b v : ℝ) : + P.expect (fun a => (b + v * Z a) ^ (2 * k)) ≤ + (b ^ 2 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * v ^ 2) ^ k := by + have heven (a : α) : |Z a| ^ (2 * k) = Z a ^ (2 * k) := by + rw [pow_mul, sq_abs, ← pow_mul] + have hmoment : P.expect (fun a => Z a ^ (2 * k)) ≤ 1 := by + simpa only [heven] using ht + have hc : 1 ≤ (6 * (2 * k : ℕ) : ℝ) ^ 2 := by + have hn : (1 : ℝ) ≤ (2 * k : ℕ) := by exact_mod_cast (show 1 ≤ 2 * k by omega) + nlinarith + by_cases hb : b = 0 + · subst b + simp only [zero_add, zero_pow (by omega : 2 ≠ 0)] + have he : P.expect (fun a => (v * Z a) ^ (2 * k)) = + v ^ (2 * k) * P.expect (fun a => Z a ^ (2 * k)) := by + simp only [expect, mul_pow, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + rw [he] + calc + _ ≤ v ^ (2 * k) := by + have hv : 0 ≤ v ^ (2 * k) := by rw [pow_mul]; positivity + nlinarith [mul_le_mul_of_nonneg_left hmoment hv] + _ = (v ^ 2) ^ k := pow_mul v 2 k + _ ≤ _ := pow_le_pow_left₀ (sq_nonneg v) (by nlinarith [mul_le_mul_of_nonneg_right hc (sq_nonneg v)]) k + · have hs := scalar_even_moment_unit P Z k hk hcenter ht (v / b) + have hbpow : 0 ≤ b ^ (2 * k) := by rw [pow_mul]; positivity + have he : P.expect (fun a => (b + v * Z a) ^ (2 * k)) = + b ^ (2 * k) * P.expect (fun a => (1 + v / b * Z a) ^ (2 * k)) := by + unfold expect + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + have h : b + v * Z a = b * (1 + v / b * Z a) := by field_simp [hb] + dsimp only + rw [h, mul_pow] + ring + rw [he] + calc + _ ≤ b ^ (2 * k) * (1 + (6 * (2 * k : ℕ) : ℝ) ^ 2 * (v / b) ^ 2) ^ k := + mul_le_mul_of_nonneg_left hs hbpow + _ = _ := by + rw [pow_mul, ← mul_pow] + congr 1 + field_simp [hb] + +theorem weighted_minkowski_bound (P : FiniteLaw α) (k : ℕ) (hk : 1 ≤ k) + (f g : α → ℝ) (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) + (A B : ℝ) (hA : 0 ≤ A) (hB : 0 ≤ B) + (hfa : P.expect (fun a => f a ^ k) ≤ A ^ k) + (hgb : P.expect (fun a => g a ^ k) ≤ B ^ k) : + P.expect (fun a => (f a + g a) ^ k) ≤ (A + B) ^ k := by + have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk + have hk0 : (k : ℝ) ≠ 0 := by positivity + let w : α → ℝ := fun a => P.mass a ^ (1 / (k : ℝ)) + have hw (a : α) : 0 ≤ w a := Real.rpow_nonneg (P.nonneg a) _ + have hwk (a : α) : w a ^ k = P.mass a := by + dsimp [w] + rw [← Real.rpow_natCast, ← Real.rpow_mul (P.nonneg a), one_div_mul_cancel hk0, Real.rpow_one] + have hsingle (F : α → ℝ) (hF : ∀ a, 0 ≤ F a) : + (∑ a, |w a * F a| ^ (k : ℝ)) = P.expect (fun a => F a ^ k) := by + apply Finset.sum_congr rfl + intro a _ + rw [abs_of_nonneg (mul_nonneg (hw a) (hF a)), Real.rpow_natCast, mul_pow, hwk] + have hsum : (∑ a, |w a * f a + w a * g a| ^ (k : ℝ)) = + P.expect (fun a => (f a + g a) ^ k) := by + simp_rw [← mul_add] + exact hsingle _ (fun a => add_nonneg (hf a) (hg a)) + have hm := Real.Lp_add_le Finset.univ (fun a => w a * f a) (fun a => w a * g a) hkR + rw [hsum, hsingle f hf, hsingle g hg] at hm + have hroots (F : α → ℝ) (hF : ∀ a, 0 ≤ F a) (C : ℝ) (hC : 0 ≤ C) + (hFC : P.expect (fun a => F a ^ k) ≤ C ^ k) : + (P.expect (fun a => F a ^ k)) ^ (1 / (k : ℝ)) ≤ C := by + calc + _ ≤ (C ^ k) ^ (1 / (k : ℝ)) := + Real.rpow_le_rpow (Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (pow_nonneg (hF a) k))) hFC (by positivity) + _ = C := by + rw [← Real.rpow_natCast, one_div, Real.rpow_rpow_inv hC hk0] + have hroot : (P.expect (fun a => (f a + g a) ^ k)) ^ (1 / (k : ℝ)) ≤ A + B := + hm.trans (add_le_add (hroots f hf A hA hfa) (hroots g hg B hB hgb)) + have hexp : 0 ≤ P.expect (fun a => (f a + g a) ^ k) := + Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (pow_nonneg (add_nonneg (hf a) (hg a)) k)) + have hp := pow_le_pow_left₀ (Real.rpow_nonneg hexp _) hroot k + rw [← Real.rpow_natCast, ← Real.rpow_mul hexp, one_div_mul_cancel hk0, Real.rpow_one] at hp + exact hp +theorem product_succ_expect_tail (P : FiniteLaw α) (n : ℕ) (f : (Fin (n + 1) → α) → ℝ) : + (P.product (n + 1)).expect f = + (P.product n).expect (fun b => P.expect (fun a => f (Fin.cons a b))) := by + rw [product_succ_expect] + unfold expect + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +end TraceReconstruction.FiniteLaw +namespace TraceReconstruction +variable {α : Type*} +def multilinear {n : ℕ} (A : (Fin n → Bool) → ℝ) (Z : α → ℝ) (x : Fin n → α) : ℝ := + ∑ σ, A σ * ∏ j, if σ j then Z (x j) else 1 + +def multilinearEnergy {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : ℝ := + ∑ σ, A σ ^ 2 * ∏ j, if σ j then R ^ 2 else 1 + +theorem multilinearEnergy_nonneg {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : + 0 ≤ multilinearEnergy A R := by + apply Finset.sum_nonneg + intro σ _ + apply mul_nonneg (sq_nonneg _) + apply Finset.prod_nonneg + intro j _ + split <;> positivity + +theorem multilinear_cons {n : ℕ} (A : (Fin (n + 1) → Bool) → ℝ) (Z : α → ℝ) + (x : Fin n → α) (a : α) : + multilinear A Z (Fin.cons a x) = + multilinear (fun σ => A (Fin.cons false σ)) Z x + + Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x := by + unfold multilinear + rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp, Fintype.sum_prod_type] + simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_bool, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, + Bool.false_eq_true, ↓reduceIte, one_mul] + rw [Finset.mul_sum] + rw [add_comm] + congr 1 + apply Finset.sum_congr rfl + intro σ _ + ring + +theorem multilinearEnergy_cons {n : ℕ} (A : (Fin (n + 1) → Bool) → ℝ) (R : ℝ) : + multilinearEnergy A R = + multilinearEnergy (fun σ => A (Fin.cons false σ)) R + + R ^ 2 * multilinearEnergy (fun σ => A (Fin.cons true σ)) R := by + unfold multilinearEnergy + rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp, Fintype.sum_prod_type] + simp only [Fin.consEquiv, Equiv.coe_fn_mk, Fintype.sum_bool, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, + Bool.false_eq_true, ↓reduceIte, one_mul] + rw [Finset.mul_sum] + rw [add_comm] + congr 1 + apply Finset.sum_congr rfl + intro σ _ + ring + +/-- The finite-product moment inequality used for every score expansion. +The order-cost is linear per degree, and no boundedness assumption is needed. -/ +theorem multilinear_even_moment {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) + (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) + (n : ℕ) (A : (Fin n → Bool) → ℝ) : + (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) ≤ + (multilinearEnergy A (6 * (2 * k : ℕ))) ^ k := by + induction n with + | zero => + simp only [FiniteLaw.expect, FiniteLaw.product, multilinear, multilinearEnergy, + Fintype.prod_empty, mul_one, one_mul] + simp only [Finset.univ_unique, Finset.sum_singleton] + exact le_of_eq (pow_mul _ 2 k) + | succ n ih => + let A0 : (Fin n → Bool) → ℝ := fun σ => A (Fin.cons false σ) + let A1 : (Fin n → Bool) → ℝ := fun σ => A (Fin.cons true σ) + let R : ℝ := 6 * (2 * k : ℕ) + let F0 : (Fin n → α) → ℝ := fun x => multilinear A0 Z x + let F1 : (Fin n → α) → ℝ := fun x => multilinear A1 Z x + have h0 := ih A0 + have h1 := ih A1 + have hA0 := multilinearEnergy_nonneg A0 R + have hA1 := multilinearEnergy_nonneg A1 R + rw [FiniteLaw.product_succ_expect_tail, multilinearEnergy_cons] + calc + _ ≤ (P.product n).expect (fun x => (F0 x ^ 2 + R ^ 2 * F1 x ^ 2) ^ k) := by + apply FiniteLaw.expect_mono + intro x + simp_rw [multilinear_cons] + have hs := FiniteLaw.scalar_even_moment P Z k hk hcenter ht (F0 x) (F1 x) + simpa only [F0, F1, A0, A1, R, mul_comm] using hs + _ ≤ (multilinearEnergy A0 R + R ^ 2 * multilinearEnergy A1 R) ^ k := by + apply FiniteLaw.weighted_minkowski_bound (P.product n) k hk + (fun x => F0 x ^ 2) (fun x => R ^ 2 * F1 x ^ 2) + (fun x => sq_nonneg _) (fun x => mul_nonneg (sq_nonneg _) (sq_nonneg _)) + (multilinearEnergy A0 R) (R ^ 2 * multilinearEnergy A1 R) hA0 + (mul_nonneg (sq_nonneg _) hA1) + · simpa only [← pow_mul] using h0 + · have he : (P.product n).expect (fun x => (R ^ 2 * F1 x ^ 2) ^ k) = + (R ^ 2) ^ k * (P.product n).expect (fun x => F1 x ^ (2 * k)) := by + unfold FiniteLaw.expect + simp only [mul_pow, ← pow_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + ring + rw [he, mul_pow (R ^ 2) (multilinearEnergy A1 R)] + exact mul_le_mul_of_nonneg_left h1 (pow_nonneg (sq_nonneg R) k) + _ = _ := rfl + +def monomialDegree {n : ℕ} (σ : Fin n → Bool) : ℕ := + (Finset.univ.filter (fun j => σ j = true)).card + +theorem monomial_weight {n : ℕ} (σ : Fin n → Bool) (R : ℝ) : + (∏ j, if σ j then R ^ 2 else 1) = R ^ (2 * monomialDegree σ) := by + rw [← Finset.prod_filter] + simp only [Finset.prod_const, ← pow_mul, monomialDegree] + +theorem multilinearEnergy_homogeneous {n : ℕ} (A : (Fin n → Bool) → ℝ) + (r : ℕ) (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) (R : ℝ) : + multilinearEnergy A R = R ^ (2 * r) * ∑ σ, A σ ^ 2 := by + unfold multilinearEnergy + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ _ + rw [monomial_weight] + by_cases hd : monomialDegree σ = r + · rw [hd, mul_comm] + · rw [hA σ hd, zero_pow (by omega : 2 ≠ 0), zero_mul, mul_zero] + +theorem homogeneous_even_moment {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) + (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) + (n r : ℕ) (A : (Fin n → Bool) → ℝ) + (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) : + (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) ≤ + ((6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2) ^ k := by + have h := multilinear_even_moment P Z k hk hcenter ht n A + rw [multilinearEnergy_homogeneous A r hA] at h + exact h + +/-- Squared L^(2k)-norm for a finite law, expressed without measure coercions. -/ +def FiniteLaw.evenMomentSq {α : Type*} [Fintype α] (P : FiniteLaw α) + (f : α → ℝ) (k : ℕ) : ℝ := + (P.expect (fun a => |f a| ^ (2 * k))) ^ (1 / (k : ℝ)) + +theorem homogeneous_moment_sq {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z = 0) + (ht : P.expect (fun a => |Z a| ^ (2 * k)) ≤ 1) + (n r : ℕ) (A : (Fin n → Bool) → ℝ) + (hA : ∀ σ, monomialDegree σ ≠ r → A σ = 0) : + (P.product n).evenMomentSq (multilinear A Z) k ≤ + (6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2 := by + have h := homogeneous_even_moment P Z k hk hcenter ht n r A hA + have he (x : Fin n → α) : |multilinear A Z x| ^ (2 * k) = + multilinear A Z x ^ (2 * k) := by rw [pow_mul, sq_abs, ← pow_mul] + unfold FiniteLaw.evenMomentSq + simp_rw [he] + have hn : 0 ≤ (P.product n).expect (fun x => multilinear A Z x ^ (2 * k)) := by + apply Finset.sum_nonneg + intro x _ + apply mul_nonneg ((P.product n).nonneg _) + change 0 ≤ multilinear A Z x ^ (2 * k) + rw [pow_mul] + positivity + have hb : 0 ≤ (6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2 := by positivity + calc + _ ≤ (((6 * (2 * k : ℕ) : ℝ) ^ (2 * r) * ∑ σ, A σ ^ 2) ^ k) ^ (1 / (k : ℝ)) := + Real.rpow_le_rpow hn h (by positivity) + _ = _ := by rw [← Real.rpow_natCast, one_div, Real.rpow_rpow_inv hb (by positivity)] +end TraceReconstruction + +namespace TraceReconstruction.FiniteLaw +variable {α : Type*} [Fintype α] +def eventMass (P : FiniteLaw α) (A : Finset α) : ℝ := ∑ a ∈ A, P.mass a + +theorem eventMass_nonneg (P : FiniteLaw α) (A : Finset α) : 0 ≤ P.eventMass A := + Finset.sum_nonneg (fun a _ => P.nonneg a) + +theorem eventMass_le_one (P : FiniteLaw α) (A : Finset α) : P.eventMass A ≤ 1 := by + rw [← P.total] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun a _ _ => P.nonneg a) + +def condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : FiniteLaw α := by + classical + exact { + mass := fun a => if a ∈ A then P.mass a / P.eventMass A else 0 + nonneg := fun a => by split <;> positivity [P.nonneg a] + total := by + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + rw [← Finset.sum_div] + exact div_self (ne_of_gt hA) } + +theorem overlap_condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : + overlap P (condition P A hA) = P.eventMass A := by + classical + have he (a : α) : min (P.mass a) ((condition P A hA).mass a) = + if a ∈ A then P.mass a else 0 := by + by_cases ha : a ∈ A + · simp only [condition, ha, ↓reduceIte] + apply min_eq_left + apply (le_div_iff₀ hA).mpr + have h := mul_le_mul_of_nonneg_left (P.eventMass_le_one A) (P.nonneg a) + simpa only [mul_one] using h + · simp only [condition, ha, ↓reduceIte, min_eq_right (P.nonneg a)] + unfold overlap + simp_rw [he] + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter, eventMass] + +theorem tv_condition (P : FiniteLaw α) (A : Finset α) (hA : 0 < P.eventMass A) : + tv P (condition P A hA) = 1 - P.eventMass A := by + have he := P.overlap_condition A hA + rw [overlap_eq_one_sub_tv] at he + linarith + +/-- Densities relative to one finite reference, preserving the exact normalization. -/ +def withDensity (P : FiniteLaw α) (f : α → ℝ) (hf : ∀ a, 0 ≤ f a) + (hmean : P.expect f = 1) : FiniteLaw α where + mass a := P.mass a * f a + nonneg a := mul_nonneg (P.nonneg a) (hf a) + total := hmean + +theorem density_bad_mass_sq (P : FiniteLaw α) (f : α → ℝ) (A : Finset α) : + (∑ a ∈ A, P.mass a * f a) ^ 2 ≤ + (P.eventMass A) * P.expect (fun a => f a ^ 2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq A (fun a => Real.sqrt (P.mass a)) + (fun a => Real.sqrt (P.mass a) * f a) + simp only [mul_pow, Real.sq_sqrt (P.nonneg _)] at h + have he : (∑ a ∈ A, Real.sqrt (P.mass a) * (Real.sqrt (P.mass a) * f a)) = + ∑ a ∈ A, P.mass a * f a := by + apply Finset.sum_congr rfl + intro a _ + rw [← mul_assoc, ← pow_two, Real.sq_sqrt (P.nonneg a)] + rw [he] at h + apply h.trans + apply mul_le_mul_of_nonneg_left _ (P.eventMass_nonneg A) + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun a _ _ => + mul_nonneg (P.nonneg a) (sq_nonneg _)) + +/-- Loss from the small-reference-density event by the exact available moment. -/ +theorem low_density_reference_mass (P : FiniteLaw α) (f : α → ℝ) (t : ℕ) + (A : Finset α) (hA : ∀ a ∈ A, f a < 1 / 2) : + P.eventMass A ≤ (2 : ℝ) ^ t * P.expect (fun a => |f a - 1| ^ t) := by + have hlocal (a : α) (ha : a ∈ A) : 1 ≤ (2 : ℝ) ^ t * |f a - 1| ^ t := by + rw [← mul_pow] + apply one_le_pow₀ + have hh := neg_le_abs (f a - 1) + linarith [hA a ha] + calc + _ ≤ ∑ a ∈ A, (2 : ℝ) ^ t * (P.mass a * |f a - 1| ^ t) := by + apply Finset.sum_le_sum + intro a ha + nlinarith [mul_le_mul_of_nonneg_left (hlocal a ha) (P.nonneg a)] + _ ≤ ∑ a, (2 : ℝ) ^ t * (P.mass a * |f a - 1| ^ t) := by + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun a _ _ => by positivity [P.nonneg a]) + _ = _ := by rw [← Finset.mul_sum]; rfl + +/-- Exact common-event likelihood ratio: no lower bound is imposed off the event. -/ +theorem conditioned_density_identity (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀ a, 0 ≤ f a) (hg : ∀ a, 0 ≤ g a) + (hfm : R.expect f = 1) (hgm : R.expect g = 1) + (A : Finset α) (hAf : ∀ a ∈ A, 0 < f a) + (hP : 0 < (R.withDensity f hf hfm).eventMass A) + (hQ : 0 < (R.withDensity g hg hgm).eventMass A) (a : α) : + (condition (R.withDensity g hg hgm) A hQ).mass a = + (condition (R.withDensity f hf hfm) A hP).mass a * + ((R.withDensity f hf hfm).eventMass A / + (R.withDensity g hg hgm).eventMass A * (g a / f a)) := by + classical + by_cases ha : a ∈ A + · simp only [condition, ha, ↓reduceIte] + change R.mass a * g a / (R.withDensity g hg hgm).eventMass A = + R.mass a * f a / (R.withDensity f hf hfm).eventMass A * + ((R.withDensity f hf hfm).eventMass A / + (R.withDensity g hg hgm).eventMass A * (g a / f a)) + field_simp [ne_of_gt hP, ne_of_gt hQ, ne_of_gt (hAf a ha)] + · simp only [condition, ha, ↓reduceIte, zero_mul] + +/-- The raw likelihood score on a common clipping event, at every integer moment. -/ +theorem clipped_raw_moment (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀ a, 0 ≤ f a) (hfm : R.expect f = 1) + (A : Finset α) (hAf : ∀ a ∈ A, 1 / 2 ≤ f a) + (hP : 0 < (R.withDensity f hf hfm).eventMass A) (k : ℕ) : + (condition (R.withDensity f hf hfm) A hP).expect + (fun a => |g a / f a - 1| ^ (k + 1)) ≤ + (2 : ℝ) ^ k / (R.withDensity f hf hfm).eventMass A * + R.expect (fun a => |g a - f a| ^ (k + 1)) := by + classical + have hpoint (a : α) (ha : a ∈ A) : + f a * |g a / f a - 1| ^ (k + 1) ≤ + (2 : ℝ) ^ k * |g a - f a| ^ (k + 1) := by + have hp : 0 < f a := lt_of_lt_of_le (by norm_num) (hAf a ha) + rw [div_sub_one (ne_of_gt hp), abs_div, abs_of_pos hp] + have hi : 0 ≤ 1 / f a := by positivity + have hi2 : 1 / f a ≤ 2 := (div_le_iff₀ hp).mpr (by linarith [hAf a ha]) + calc + _ = |g a - f a| ^ (k + 1) * (1 / f a) ^ k := by + rw [div_pow, div_pow, one_pow, pow_succ (f a)] + field_simp [ne_of_gt hp] + _ ≤ _ := by + simpa only [mul_comm] using mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ hi hi2 k) (show 0 ≤ |g a - f a| ^ (k + 1) by positivity) + unfold expect + calc + _ = ∑ a ∈ A, (R.mass a * (f a * |g a / f a - 1| ^ (k + 1))) / + (R.withDensity f hf hfm).eventMass A := by + simp only [condition, withDensity] + simp_rw [ite_mul, zero_mul] + rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter, Finset.univ_inter] + apply Finset.sum_congr rfl + intro a _ + ring + _ ≤ ∑ a ∈ A, ((2 : ℝ) ^ k * (R.mass a * |g a - f a| ^ (k + 1))) / + (R.withDensity f hf hfm).eventMass A := by + apply Finset.sum_le_sum + intro a ha + apply div_le_div_of_nonneg_right _ hP.le + nlinarith [mul_le_mul_of_nonneg_left (hpoint a ha) (R.nonneg a)] + _ ≤ ∑ a, ((2 : ℝ) ^ k * (R.mass a * |g a - f a| ^ (k + 1))) / + (R.withDensity f hf hfm).eventMass A := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro a _ _ + positivity [R.nonneg a] + _ = _ := by rw [← Finset.sum_div, ← Finset.mul_sum]; ring + +/-- Normalizing the second conditioned law costs only its scalar normalization error. -/ +theorem score_rescaling_moment (P : FiniteLaw α) (u : α → ℝ) + (c : ℝ) (hc : 0 ≤ c) (k : ℕ) : + P.expect (fun a => |c * u a - 1| ^ (k + 1)) ≤ + 2 ^ k * (c ^ (k + 1) * P.expect (fun a => |u a - 1| ^ (k + 1)) + + |c - 1| ^ (k + 1)) := by + have hb (a : α) : |c * u a - 1| ^ (k + 1) ≤ + 2 ^ k * (c ^ (k + 1) * |u a - 1| ^ (k + 1) + |c - 1| ^ (k + 1)) := by + have he : c * u a - 1 = c * (u a - 1) + (c - 1) := by ring + rw [he] + calc + _ ≤ (|c * (u a - 1)| + |c - 1|) ^ (k + 1) := + pow_le_pow_left₀ (abs_nonneg _) (abs_add_le _ _) _ + _ ≤ _ := by + have h := add_pow_le (abs_nonneg (c * (u a - 1))) (abs_nonneg (c - 1)) (k + 1) + simpa only [Nat.add_sub_cancel, abs_mul, abs_of_nonneg hc, mul_pow] using h + unfold expect + calc + _ ≤ ∑ a, P.mass a * (2 ^ k * (c ^ (k + 1) * |u a - 1| ^ (k + 1) + + |c - 1| ^ (k + 1))) := Finset.sum_le_sum (fun a _ => + mul_le_mul_of_nonneg_left (hb a) (P.nonneg a)) + _ = 2 ^ k * (c ^ (k + 1) * (∑ a, P.mass a * |u a - 1| ^ (k + 1)) + + |c - 1| ^ (k + 1) * ∑ a, P.mass a) := by + simp only [mul_add, Finset.sum_add_distrib, Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro a _ <;> ring + _ = _ := by rw [P.total, mul_one] +end TraceReconstruction.FiniteLaw + +namespace TraceReconstruction +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] +def coordinateProduct {n : ℕ} (P : Fin n → FiniteLaw α) : FiniteLaw (Fin n → α) where + mass x := ∏ i, (P i).mass (x i) + nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg (x i)) + total := by rw [← Fintype.prod_sum]; simp only [FiniteLaw.total, Finset.prod_const_one] + +def mixture (R : FiniteLaw β) (P : β → FiniteLaw α) : FiniteLaw α where + mass a := ∑ b, R.mass b * (P b).mass a + nonneg a := Finset.sum_nonneg (fun b _ => mul_nonneg (R.nonneg b) ((P b).nonneg a)) + total := by + rw [Finset.sum_comm] + simp_rw [← Finset.mul_sum, FiniteLaw.total, mul_one] + exact R.total +end FiniteLaw +variable {α Ω : Type*} [Fintype Ω] + +def selectionCoefficient {n : ℕ} (θ σ : Fin n → Bool) : ℝ := + ∏ i, if σ i then (if θ i then 1 else 0) else 1 + +def selectionDensity {n : ℕ} (θ : Fin n → Bool) (Z : α → ℝ) (x : Fin n → α) : ℝ := + ∏ i, if θ i then 1 + Z (x i) else 1 + +def averagedCoefficient {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (σ : Fin n → Bool) : ℝ := R.expect (fun ω => selectionCoefficient (θ ω) σ) + +def averagedDensity {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (Z : α → ℝ) (x : Fin n → α) : ℝ := R.expect (fun ω => selectionDensity (θ ω) Z x) + +theorem selectionDensity_expansion {n : ℕ} (θ : Fin n → Bool) (Z : α → ℝ) + (x : Fin n → α) : selectionDensity θ Z x = multilinear (selectionCoefficient θ) Z x := by + unfold selectionDensity multilinear selectionCoefficient + simp_rw [← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun (i : Fin n) (b : Bool) => + (if b then (if θ i then (1 : ℝ) else 0) else 1) * (if b then Z (x i) else 1))] + apply Finset.prod_congr rfl + intro i _ + cases θ i <;> simp [add_comm] + +theorem averagedDensity_expansion {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (Z : α → ℝ) (x : Fin n → α) : + averagedDensity R θ Z x = multilinear (averagedCoefficient R θ) Z x := by + unfold averagedDensity averagedCoefficient + simp_rw [selectionDensity_expansion] + unfold multilinear FiniteLaw.expect + simp_rw [Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro σ _ + apply Finset.sum_congr rfl + intro ω _ + ring + +theorem averagedDensity_difference {n : ℕ} (R : FiniteLaw Ω) + (θ φ : Ω → Fin n → Bool) (Z : α → ℝ) (x : Fin n → α) : + averagedDensity R θ Z x - averagedDensity R φ Z x = + multilinear (fun σ => averagedCoefficient R θ σ - averagedCoefficient R φ σ) Z x := by + rw [averagedDensity_expansion, averagedDensity_expansion] + simp only [multilinear, sub_mul, Finset.sum_sub_distrib] + +theorem coefficient_nonneg {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (σ : Fin n → Bool) : 0 ≤ averagedCoefficient R θ σ := by + apply Finset.sum_nonneg + intro ω _ + apply mul_nonneg (R.nonneg ω) + apply Finset.prod_nonneg + intro i _ + cases σ i <;> cases θ ω i <;> norm_num + +theorem coefficient_le_one {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (σ : Fin n → Bool) : averagedCoefficient R θ σ ≤ 1 := by + rw [← R.total] + apply Finset.sum_le_sum + intro ω _ + have h : selectionCoefficient (θ ω) σ ≤ 1 := by + apply Finset.prod_le_one₀ + · intro i _; cases σ i <;> cases θ ω i <;> norm_num + · intro i _; cases σ i <;> cases θ ω i <;> norm_num + simpa only [mul_one] using mul_le_mul_of_nonneg_left h (R.nonneg ω) + +/-- The coefficient for the empty subset is exactly one, before or after averaging. -/ +theorem averagedCoefficient_empty {n : ℕ} (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) : + averagedCoefficient R θ (fun _ => false) = 1 := by + simp [averagedCoefficient, selectionCoefficient, FiniteLaw.expect, R.total] + +/-- Exact density of the conditionally independent leaf oracle used in the source. -/ +theorem leaf_oracle_density [Fintype α] {n : ℕ} (P Q : FiniteLaw α) (Z : α → ℝ) + (hscore : ∀ a, Q.mass a = P.mass a * (1 + Z a)) + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (x : Fin n → α) : + (R.mixture (fun ω => FiniteLaw.coordinateProduct (fun i => if θ ω i then Q else P))).mass x = + (∏ i, P.mass (x i)) * averagedDensity R θ Z x := by + unfold FiniteLaw.mixture FiniteLaw.coordinateProduct averagedDensity FiniteLaw.expect + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro ω _ + have he : (∏ i, (if θ ω i then Q else P).mass (x i)) = + (∏ i, P.mass (x i)) * selectionDensity (θ ω) Z x := by + rw [selectionDensity, ← Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro i _ + cases θ ω i <;> simp only [Bool.false_eq_true, ↓reduceIte, mul_one, hscore] + change R.mass ω * (∏ i, (if θ ω i then Q else P).mass (x i)) = + (∏ i, P.mass (x i)) * (R.mass ω * selectionDensity (θ ω) Z x) + rw [he] + ring +end TraceReconstruction + +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Induction.lean b/lean/OAI/Probability/TraceReconstruction/Induction.lean index 06710f824b35d86fa1e0e38d4319e6d23f2aff49..933f46fdee0b606ec611e3c92a631077d7dd1d18 100644 --- a/lean/OAI/Probability/TraceReconstruction/Induction.lean +++ b/lean/OAI/Probability/TraceReconstruction/Induction.lean @@ -1,708 +1,708 @@ -import OAI.Probability.TraceReconstruction.Amplification -import OAI.Probability.TraceReconstruction.Propagation - -namespace OAI - -/-! -# Induction - -Concrete level invariants, metadata prefixes, score/error budgets, overlap, the induction step, and the complete construction. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The literal induction invariant, including the depth-dependent moment, - actual complete-trace simulator, distinct words, length, and power overlap. -/ -abbrev SourceLevelPair (B D : ℕ) (n q : ℝ) (hq : q∈Set.Icc 0 1) (i : ℕ) := - ConcreteLevelPair q hq (sourceTargetScale B D n i) - (n^(-100*(totalScoreExponent B D+B+1))) (totalScoreExponent B i) - (initialOverlapLower q) ((sourceOverlapConstant q)^(2*B*i+2)) i (sourceHalfMoment B D n i) - -theorem source_level_geometry {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} - (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : isourceA_nonneg B D b j hb.2 (by omega)) - (fun j hj=>sourceKappa_three_epsilon B D b (j+1) hb.2 (by omega) (by omega)) - · have hh := mul_le_mul_of_nonneg_left hG (show (0:ℝ) ≤ 1200 by norm_num) - exact (by nlinarith only [hh] : 1200*C^(2*b)*C^(2*B*i+2) ≤ 1200*sourceCapEnvelope B D q).trans H.geometry - · simpa only [Nat.cast_pow,Nat.cast_ofNat] using H.motif - · simpa only [sourceTargetScale_step B D i n (by linarith only [hn]) hi] using U.length_lower - · simpa only [sourceTargetScale_step B D i n (by linarith only [hn]) hi] using U.length_upper - · exact U.overlapCount_lower - · exact U.overlapCount_upper - -theorem SourceArithmeticBounds.copies_positive {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 if v=0 then (0:ℝ) else Real.exp (-(v:ℝ)*ω^4/16) - change (f (sourceScheduledTrials T n b)+f (n b)+(∑ _ : Fin (T b), - ∑ v : WindowCollection T b,f (collectionCount T n (sourceScheduledTrials T n) b v))) = - f (n b)+f (sourceScheduledTrials T n b)+(T b:ℝ)* - (∑ v : WindowCollection T b,f (collectionCount T n (sourceScheduledTrials T n) b v)) - rw [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - ring - -theorem sourceEffectiveHiddenTail_two_ge_one (T n : ℕ→ℕ) (ω : ℝ) (hT : 1 ≤ T 1) : - sourceEffectiveHiddenTail (fun _=>T 0) (fun _=>n 0) 1 ω ≤ sourceEffectiveHiddenTail T n 2 ω := by - rw [sourceEffectiveHiddenTail_step T n 1 ω,sourceEffectiveHiddenTail_one, - sourceEffectiveHiddenTail_one] - have hnonneg (v : ℕ) : 0 ≤ (if v=0 then 0 else Real.exp (-(v:ℝ)*ω^4/16)) := by - split_ifs <;> positivity - have ht : (1:ℝ) ≤ T 1 := by exact_mod_cast hT - have hh := le_mul_of_one_le_left (hnonneg (n 0)) ht - linarith only [hh,hnonneg (n 1),hnonneg (sourceScheduledTrials T n 1)] - -theorem sourceSparseCount_motif_le (T : ℕ→ℕ) (s b : ℕ) (hT : ∀jhT j (Finset.mem_range.mp hj)) - have hh : 2^s ≤ sourceSparseCount T s b := by - unfold sourceSparseCount - exact Nat.le_mul_of_pos_right _ hp - exact_mod_cast hh - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem source_level_tail_budget {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} - (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iT 0) (fun _=>t 0) s 0 k ω a L - (((6*(2*k:ℕ):ℝ)*L)^2*(2:ℝ)^s ≤ 1/2) ∧ cost ≤ 1/2 ∧ - Real.sqrt (((h 2+1:ℕ):ℝ)*((2^s:ℕ):ℝ)* - (64*sourceSharpEnergyBudget (fun _=>T 0) (fun _=>t 0) s 0 2 ω a a ((6*(2*k:ℕ):ℝ)*L)))+ - 2*((h 2+1:ℕ):ℝ)*((P 1:ℝ)*(cost+(T 0:ℝ)*U.error)) ≤ 1/4 := by - let N := sourceTargetScale B D n (i+1) - let ε := sourceEpsilon B D - let s := sourceCancellationOrder B D - let C := sourceOverlapConstant q - let F := C^(2*B*i+2) - let K := sourceCapEnvelope B D q - let W := sourceWeightEnvelope B D - let T := sourceBlockWindows N 2 ε - let t := sourceArithmeticTrials C N 2 ε U.left.length U.overlapCount - let P := sourceArithmeticP C N 2 ε U.left.length U.overlapCount - let h := sourceArithmeticCount C N 2 ε U.left.length U.overlapCount - let k := sourceHalfMoment B D n (i+1) - let e := scaleA 2 0 ε*totalScoreExponent B i - let L := N^(-scaleA 2 0 ε*totalScoreExponent B i/2) - let a := N^(-20*sourceWorkSize B D) - let ω := initialOverlapLower q - let w := (6*(2*k:ℕ):ℝ)*L - let gap := (totalScoreExponent B i+1)*sourceGapFloor B - let Δ := n^(-100*(totalScoreExponent B D+B+1)) - have hb : sourceDimension B i=2 := ite_eq_left hiw - have hn1 : 1 ≤ n := by linarith only [hn] - have hn0 : 0Nat.succ_le_of_lt (H'.window_positive (j+1))) - have hs := mul_le_mul_of_nonneg_left hmot (sq_nonneg w) - have hs1 : w^2*(2:ℝ)^s ≤ 1/2 := hs.trans Hnum.2.1 - have hs2 : w^2*(2:ℝ)^s ≤ N^(-gap/2)/8 := hs.trans Hnum.1 - have hm : sourceEffectiveHiddenTail (fun _=>T 0) (fun _=>t 0) 1 ω ≤ - n^(-200*(totalScoreExponent B D+B+1)) := - (sourceEffectiveHiddenTail_two_ge_one T t ω (Nat.succ_le_of_lt (H'.window_positive 1))).trans ht.1 - have hg : sourceGapFloor B ≤ gap := le_mul_of_one_le_left (sourceGapFloor_pos B).le - (by linarith only [(totalScoreExponent_bounds B i hB).1]) - have hc := source_one_window_clipping B D (i+1) s (T 0) (t 0) n ω a gap L hB hn hg hm hs1 hs2 - have hG : C^4*F ≤ K := by - simpa only [hb,show (2:ℕ)*2=4 by rfl] using - source_local_envelope B D i (sourceDimension B i) hq' (Nat.le_of_lt hi) (sourceDimension_bounds B i hB).2 - have hE : U.error ≤ ((i:ℝ)+1)*Δ*U.left.length := by - apply (div_le_iff₀ ?_).mp U.normalized_error - exact (show 0T 0) (fun _=>t 0) s ω a w hs1) (by norm_num : (0:ℝ) ≤ 64) - have hpref := source_overlap_prefactors hK hW (one_le_pow₀ (by norm_num : (1:ℝ) ≤ 2)) hB (j:=0) (by omega) H.overlap - have hexp := (source_level_exponent_margins B D i hB (Nat.le_of_lt hi)).1 hiw - rw [hb] at hexp - have hM : 1 ≤ sourceWorkSize B D := by - unfold sourceWorkSize - linarith only [(totalScoreExponent_bounds B D hB).1,Nat.cast_nonneg (sourceDegreeCutoff B) (α:=ℝ),Nat.cast_nonneg B (α:=ℝ)] - have hv := source_warmup_variance_budget hN.1 hK hW (show 0 ≤ (2:ℝ)^s by positivity) - (Nat.cast_nonneg (T 0)) (Nat.cast_nonneg (h 2+1)) hcount hwindow hw henergy hpref.2.1 hpref.2.2 - (by change ε+2-e-40*sourceWorkSize B D ≤ 0; have hloe : 27/50 ≤ e := hexp.2.1; linarith only [he1,hloe,hM]) - hexp.2.2.2 - refine ⟨hs1,hc.1,?_⟩ - have hh := overlap_sqrt_budget hv herr - simpa only [N,ε,s,C,F,K,W,T,t,P,h,k,e,L,a,ω,w,Nat.cast_pow,Nat.cast_ofNat,mul_assoc] using hh - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem source_level_overlap {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} - (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iif τ then U.right else U.left - ∀j ≤ b, initialOverlapLower q ≤ listTraceOverlap q hq - (pureAtomRun (sourceBlockWord s P atom j false) (h j)) - (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by - let N := sourceTargetScale B D n (i+1) - let b := sourceDimension B i - let ε := sourceEpsilon B D - let s := sourceCancellationOrder B D - let P := sourceArithmeticP (sourceOverlapConstant q) N b ε U.left.length U.overlapCount - let h := sourceArithmeticCount (sourceOverlapConstant q) N b ε U.left.length U.overlapCount - let T := sourceBlockWindows N b ε - let t := sourceArithmeticTrials (sourceOverlapConstant q) N b ε U.left.length U.overlapCount - let atom := fun (τ : Bool)=>if τ then U.right else U.left - let k := sourceHalfMoment B D n (i+1) - let L := N^(-scaleA b 0 ε*totalScoreExponent B i/2) - let a := N^(-20*sourceWorkSize B D) - have hn1 : 1 ≤ n := by linarith only [hn] - have hn2 : 1 < n := by linarith only [hn] - have hN : 0T 0) s 0 ≤ 1/2 := by - simpa only [L,N,b,ε,k,s,T,t,a,hb2,sourceSparseCount,Finset.range_zero,Finset.prod_empty,Nat.mul_one,Nat.cast_pow,Nat.cast_ofNat] using hw.1 - have hclip : sourceClippingCost (fun _=>T 0) (fun _=>t 0) s 0 k (initialOverlapLower q) a L ≤ 1/2 := by - simpa only [L,N,b,ε,k,s,T,t,a,P,h,hb2] using hw.2.1 - have hv : (sourceTargetScale B D n i)^(-totalScoreExponent B i) ≤ L^2 := by - rw [source_old_variance_square B D i (by linarith only [hn]) hi] - have hh := source_warmup_nested_overlap hq U.error_nonneg s k P h atom O hp hC - (fun j hj=>hc j (by omega)) (fun j hj=>hP j (by omega)) (fun j hj=>hlift j (by omega)) - hfirst' hbase (T 0) (t 0) (H'.windows 0 (by omega)).1 hev (H'.windows 0 (by omega)).2.1 - (H'.windows 0 (by omega)).2.2.2 hfit a a L (by positivity) (by positivity) hk hv hs - (hnum.2.2.2.1 0 (by omega)) hclip (by simpa only [L,N,b,ε,k,s,T,t,a,P,h,hb2] using hw.2.2) - change ∀j : ℕ,j≤b → initialOverlapLower q ≤ listTraceOverlap q hq - (pureAtomRun (sourceBlockWord s P atom j false) (h j)) - (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) - intro j hj - exact hh j (by change j≤b at hj; omega) - · apply source_nested_overlap hq U.error_nonneg s P h atom (O.hellinger hk) b hp hC hc hP hlift _ hbase - intro j hj - exact source_level_dense_overlap U hB hi hn hq' H (by omega) - ((source_level_exponent_margins B D i hB (Nat.le_of_lt hi)).2 (by omega) (j+1) (by omega)) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The exact manuscript block is now a producer: no new level invariant or - overlap is assumed. All hypotheses besides the old actual pair are literal - scalar schedule margins. -/ -theorem source_level_step {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} - (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iif τ then U.right else U.left - let k := sourceHalfMoment B D n (i+1) - let L := N^(-scaleA b 0 ε*totalScoreExponent B i/2) - let a := N^(-20*sourceWorkSize B D) - let ω := initialOverlapLower q - let Δ := n^(-100*(totalScoreExponent B D+B+1)) - have hn1 : 1 ≤ n := by linarith only [hn] - have hn2 : 1 < n := by linarith only [hn] - have hn0 : 0|O.score z|^(2*k)) ≤ L^(2*k) := by - have hh := O.first.expect_even_pow_le_of_moment O.score k hk (O.moment.trans hv) - simpa only [pow_mul] using hh - have he (j : ℕ) (hj : j ≤ b-1) : Even (T j) := by - change Even (sourceBlockWindows N b ε j) - rw [sourceBlockWindows,ite_eq_left (by omega : jH'.trials_positive hN (by linarith only [hC]) (by positivity) (by omega)) - (fun j hj=>(H'.windows j (by omega)).1) he (fun j hj=>(H'.windows j (by omega)).2.1) - (H'.windows (b-1) (by omega)).2.2.2 O.first O.second O.decode O.score O.density O.likelihood_nonneg - O.first_simulation O.second_simulation ω a a L (by positivity) (by positivity) - ⟨initialOverlapLower_pos q,lt_of_lt_of_le (initialOverlapLower_lt_eighth hq'.1) (by norm_num)⟩ - (fun j hj=>hov j (by omega)) hk hm hnum.2.1 - (fun j hj=>hnum.2.2.2.1 j (by omega)) hnum.2.2.2.2.1 - rw [hb1] at W - have hlen (τ : Bool) : (sourceBlockWord s P atom b τ).length=sourceArithmeticLength C N b ε U.left.length U.overlapCount b := by - rw [sourceArithmeticLength_eq_block] - apply sourceBlockWord_length - intro σ - cases σ - · rfl - · exact U.equalLength.symm - have hinj : Function.Injective atom := by - intro τ σ hτσ - cases τ <;> cases σ - · rfl - · exact False.elim (U.different hτσ) - · exact False.elim (U.different hτσ.symm) - · rfl - have hne : sourceBlockWord s P atom b false≠sourceBlockWord s P atom b true := by - intro hh - have hh' := sourceBlockWord_injective s P atom U.left.length (by - intro τ; cases τ; rfl; exact U.equalLength.symm) hinj b - (fun j hj=>Nat.lt_of_lt_of_le (by omega : 0<1) (H'.copies_positive hN hj)) hh - contradiction - have hlength := H'.lengths b le_rfl - change N^(scaleA b b ε)/2 ≤ (sourceArithmeticLength C N b ε U.left.length U.overlapCount b:ℝ) ∧ - (sourceArithmeticLength C N b ε U.left.length U.overlapCount b:ℝ) ≤ N^(scaleA b b ε) at hlength - simp only [scaleA_top,Real.rpow_one] at hlength - have hE : U.error ≤ ((i:ℝ)+1)*Δ*U.left.length := by - apply (div_le_iff₀ ?_).mp U.normalized_error - exact (show 0(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀i ≤ sourceDepth B ζ ((q t)^3*Real.log (n t)), - Nonempty (SourceLevelPair B (sourceDepth B ζ ((q t)^3*Real.log (n t))) - (n t) (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ i) := by - filter_upwards [source_initial_at_smallest_scale B ζ hB hζ hn hq hH, - source_numeric_margins_eventually B ζ hB hζ hn hq hH, - source_tails_eventually B ζ hB hζ hn hq hH,hn.eventually_ge_atTop 4] with t h0 hm ht hn4 - intro i hi - induction i with - | zero => simpa only [SourceLevelPair,totalScoreExponent,Finset.range_zero, - Finset.sum_empty,add_zero,Nat.mul_zero,Nat.zero_add] using h0 - | succ i ih => - obtain ⟨U⟩ := ih (by omega) - exact source_level_step U hB (by omega) hn4 (hq t) (hm (i+1)) (ht (i+1)) - -/-- The final source pair has actual length in [n/2,n], an exact common - complete-trace simulator, prescribed high moment and inductively obtained - power overlap. This is the construction theorem, before statistical transfer. -/ -theorem source_final_pair_eventually (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) - (hζ : ζ∈Set.Ioo 0 1) {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) - (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) - (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ (n t) - ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) - (totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) - (initialOverlapLower (q t)) - ((sourceOverlapConstant (q t))^(2*B*sourceDepth B ζ ((q t)^3*Real.log (n t))+2)) - (sourceDepth B ζ ((q t)^3*Real.log (n t))) - (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) - (sourceDepth B ζ ((q t)^3*Real.log (n t))))) := by - filter_upwards [source_all_levels_eventually B ζ hB hζ hn hq hH] with t ht - simpa only [SourceLevelPair,sourceTargetScale_top] using ht _ le_rfl - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Amplification +import OAI.Probability.TraceReconstruction.Propagation + +namespace OAI + +/-! +# Induction + +Concrete level invariants, metadata prefixes, score/error budgets, overlap, the induction step, and the complete construction. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The literal induction invariant, including the depth-dependent moment, + actual complete-trace simulator, distinct words, length, and power overlap. -/ +abbrev SourceLevelPair (B D : ℕ) (n q : ℝ) (hq : q∈Set.Icc 0 1) (i : ℕ) := + ConcreteLevelPair q hq (sourceTargetScale B D n i) + (n^(-100*(totalScoreExponent B D+B+1))) (totalScoreExponent B i) + (initialOverlapLower q) ((sourceOverlapConstant q)^(2*B*i+2)) i (sourceHalfMoment B D n i) + +theorem source_level_geometry {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} + (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : isourceA_nonneg B D b j hb.2 (by omega)) + (fun j hj=>sourceKappa_three_epsilon B D b (j+1) hb.2 (by omega) (by omega)) + · have hh := mul_le_mul_of_nonneg_left hG (show (0:ℝ) ≤ 1200 by norm_num) + exact (by nlinarith only [hh] : 1200*C^(2*b)*C^(2*B*i+2) ≤ 1200*sourceCapEnvelope B D q).trans H.geometry + · simpa only [Nat.cast_pow,Nat.cast_ofNat] using H.motif + · simpa only [sourceTargetScale_step B D i n (by linarith only [hn]) hi] using U.length_lower + · simpa only [sourceTargetScale_step B D i n (by linarith only [hn]) hi] using U.length_upper + · exact U.overlapCount_lower + · exact U.overlapCount_upper + +theorem SourceArithmeticBounds.copies_positive {C N F ε : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (hN : 0 if v=0 then (0:ℝ) else Real.exp (-(v:ℝ)*ω^4/16) + change (f (sourceScheduledTrials T n b)+f (n b)+(∑ _ : Fin (T b), + ∑ v : WindowCollection T b,f (collectionCount T n (sourceScheduledTrials T n) b v))) = + f (n b)+f (sourceScheduledTrials T n b)+(T b:ℝ)* + (∑ v : WindowCollection T b,f (collectionCount T n (sourceScheduledTrials T n) b v)) + rw [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + ring + +theorem sourceEffectiveHiddenTail_two_ge_one (T n : ℕ→ℕ) (ω : ℝ) (hT : 1 ≤ T 1) : + sourceEffectiveHiddenTail (fun _=>T 0) (fun _=>n 0) 1 ω ≤ sourceEffectiveHiddenTail T n 2 ω := by + rw [sourceEffectiveHiddenTail_step T n 1 ω,sourceEffectiveHiddenTail_one, + sourceEffectiveHiddenTail_one] + have hnonneg (v : ℕ) : 0 ≤ (if v=0 then 0 else Real.exp (-(v:ℝ)*ω^4/16)) := by + split_ifs <;> positivity + have ht : (1:ℝ) ≤ T 1 := by exact_mod_cast hT + have hh := le_mul_of_one_le_left (hnonneg (n 0)) ht + linarith only [hh,hnonneg (n 1),hnonneg (sourceScheduledTrials T n 1)] + +theorem sourceSparseCount_motif_le (T : ℕ→ℕ) (s b : ℕ) (hT : ∀jhT j (Finset.mem_range.mp hj)) + have hh : 2^s ≤ sourceSparseCount T s b := by + unfold sourceSparseCount + exact Nat.le_mul_of_pos_right _ hp + exact_mod_cast hh + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem source_level_tail_budget {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} + (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iT 0) (fun _=>t 0) s 0 k ω a L + (((6*(2*k:ℕ):ℝ)*L)^2*(2:ℝ)^s ≤ 1/2) ∧ cost ≤ 1/2 ∧ + Real.sqrt (((h 2+1:ℕ):ℝ)*((2^s:ℕ):ℝ)* + (64*sourceSharpEnergyBudget (fun _=>T 0) (fun _=>t 0) s 0 2 ω a a ((6*(2*k:ℕ):ℝ)*L)))+ + 2*((h 2+1:ℕ):ℝ)*((P 1:ℝ)*(cost+(T 0:ℝ)*U.error)) ≤ 1/4 := by + let N := sourceTargetScale B D n (i+1) + let ε := sourceEpsilon B D + let s := sourceCancellationOrder B D + let C := sourceOverlapConstant q + let F := C^(2*B*i+2) + let K := sourceCapEnvelope B D q + let W := sourceWeightEnvelope B D + let T := sourceBlockWindows N 2 ε + let t := sourceArithmeticTrials C N 2 ε U.left.length U.overlapCount + let P := sourceArithmeticP C N 2 ε U.left.length U.overlapCount + let h := sourceArithmeticCount C N 2 ε U.left.length U.overlapCount + let k := sourceHalfMoment B D n (i+1) + let e := scaleA 2 0 ε*totalScoreExponent B i + let L := N^(-scaleA 2 0 ε*totalScoreExponent B i/2) + let a := N^(-20*sourceWorkSize B D) + let ω := initialOverlapLower q + let w := (6*(2*k:ℕ):ℝ)*L + let gap := (totalScoreExponent B i+1)*sourceGapFloor B + let Δ := n^(-100*(totalScoreExponent B D+B+1)) + have hb : sourceDimension B i=2 := ite_eq_left hiw + have hn1 : 1 ≤ n := by linarith only [hn] + have hn0 : 0Nat.succ_le_of_lt (H'.window_positive (j+1))) + have hs := mul_le_mul_of_nonneg_left hmot (sq_nonneg w) + have hs1 : w^2*(2:ℝ)^s ≤ 1/2 := hs.trans Hnum.2.1 + have hs2 : w^2*(2:ℝ)^s ≤ N^(-gap/2)/8 := hs.trans Hnum.1 + have hm : sourceEffectiveHiddenTail (fun _=>T 0) (fun _=>t 0) 1 ω ≤ + n^(-200*(totalScoreExponent B D+B+1)) := + (sourceEffectiveHiddenTail_two_ge_one T t ω (Nat.succ_le_of_lt (H'.window_positive 1))).trans ht.1 + have hg : sourceGapFloor B ≤ gap := le_mul_of_one_le_left (sourceGapFloor_pos B).le + (by linarith only [(totalScoreExponent_bounds B i hB).1]) + have hc := source_one_window_clipping B D (i+1) s (T 0) (t 0) n ω a gap L hB hn hg hm hs1 hs2 + have hG : C^4*F ≤ K := by + simpa only [hb,show (2:ℕ)*2=4 by rfl] using + source_local_envelope B D i (sourceDimension B i) hq' (Nat.le_of_lt hi) (sourceDimension_bounds B i hB).2 + have hE : U.error ≤ ((i:ℝ)+1)*Δ*U.left.length := by + apply (div_le_iff₀ ?_).mp U.normalized_error + exact (show 0T 0) (fun _=>t 0) s ω a w hs1) (by norm_num : (0:ℝ) ≤ 64) + have hpref := source_overlap_prefactors hK hW (one_le_pow₀ (by norm_num : (1:ℝ) ≤ 2)) hB (j:=0) (by omega) H.overlap + have hexp := (source_level_exponent_margins B D i hB (Nat.le_of_lt hi)).1 hiw + rw [hb] at hexp + have hM : 1 ≤ sourceWorkSize B D := by + unfold sourceWorkSize + linarith only [(totalScoreExponent_bounds B D hB).1,Nat.cast_nonneg (sourceDegreeCutoff B) (α:=ℝ),Nat.cast_nonneg B (α:=ℝ)] + have hv := source_warmup_variance_budget hN.1 hK hW (show 0 ≤ (2:ℝ)^s by positivity) + (Nat.cast_nonneg (T 0)) (Nat.cast_nonneg (h 2+1)) hcount hwindow hw henergy hpref.2.1 hpref.2.2 + (by change ε+2-e-40*sourceWorkSize B D ≤ 0; have hloe : 27/50 ≤ e := hexp.2.1; linarith only [he1,hloe,hM]) + hexp.2.2.2 + refine ⟨hs1,hc.1,?_⟩ + have hh := overlap_sqrt_budget hv herr + simpa only [N,ε,s,C,F,K,W,T,t,P,h,k,e,L,a,ω,w,Nat.cast_pow,Nat.cast_ofNat,mul_assoc] using hh + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem source_level_overlap {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} + (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iif τ then U.right else U.left + ∀j ≤ b, initialOverlapLower q ≤ listTraceOverlap q hq + (pureAtomRun (sourceBlockWord s P atom j false) (h j)) + (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) := by + let N := sourceTargetScale B D n (i+1) + let b := sourceDimension B i + let ε := sourceEpsilon B D + let s := sourceCancellationOrder B D + let P := sourceArithmeticP (sourceOverlapConstant q) N b ε U.left.length U.overlapCount + let h := sourceArithmeticCount (sourceOverlapConstant q) N b ε U.left.length U.overlapCount + let T := sourceBlockWindows N b ε + let t := sourceArithmeticTrials (sourceOverlapConstant q) N b ε U.left.length U.overlapCount + let atom := fun (τ : Bool)=>if τ then U.right else U.left + let k := sourceHalfMoment B D n (i+1) + let L := N^(-scaleA b 0 ε*totalScoreExponent B i/2) + let a := N^(-20*sourceWorkSize B D) + have hn1 : 1 ≤ n := by linarith only [hn] + have hn2 : 1 < n := by linarith only [hn] + have hN : 0T 0) s 0 ≤ 1/2 := by + simpa only [L,N,b,ε,k,s,T,t,a,hb2,sourceSparseCount,Finset.range_zero,Finset.prod_empty,Nat.mul_one,Nat.cast_pow,Nat.cast_ofNat] using hw.1 + have hclip : sourceClippingCost (fun _=>T 0) (fun _=>t 0) s 0 k (initialOverlapLower q) a L ≤ 1/2 := by + simpa only [L,N,b,ε,k,s,T,t,a,P,h,hb2] using hw.2.1 + have hv : (sourceTargetScale B D n i)^(-totalScoreExponent B i) ≤ L^2 := by + rw [source_old_variance_square B D i (by linarith only [hn]) hi] + have hh := source_warmup_nested_overlap hq U.error_nonneg s k P h atom O hp hC + (fun j hj=>hc j (by omega)) (fun j hj=>hP j (by omega)) (fun j hj=>hlift j (by omega)) + hfirst' hbase (T 0) (t 0) (H'.windows 0 (by omega)).1 hev (H'.windows 0 (by omega)).2.1 + (H'.windows 0 (by omega)).2.2.2 hfit a a L (by positivity) (by positivity) hk hv hs + (hnum.2.2.2.1 0 (by omega)) hclip (by simpa only [L,N,b,ε,k,s,T,t,a,P,h,hb2] using hw.2.2) + change ∀j : ℕ,j≤b → initialOverlapLower q ≤ listTraceOverlap q hq + (pureAtomRun (sourceBlockWord s P atom j false) (h j)) + (pureAtomRun (sourceBlockWord s P atom j false) (h j+1)) + intro j hj + exact hh j (by change j≤b at hj; omega) + · apply source_nested_overlap hq U.error_nonneg s P h atom (O.hellinger hk) b hp hC hc hP hlift _ hbase + intro j hj + exact source_level_dense_overlap U hB hi hn hq' H (by omega) + ((source_level_exponent_margins B D i hB (Nat.le_of_lt hi)).2 (by omega) (j+1) (by omega)) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The exact manuscript block is now a producer: no new level invariant or + overlap is assumed. All hypotheses besides the old actual pair are literal + scalar schedule margins. -/ +theorem source_level_step {B D i : ℕ} {n q : ℝ} {hq : q∈Set.Icc 0 1} + (U : SourceLevelPair B D n q hq i) (hB : 2 ≤ B) (hi : iif τ then U.right else U.left + let k := sourceHalfMoment B D n (i+1) + let L := N^(-scaleA b 0 ε*totalScoreExponent B i/2) + let a := N^(-20*sourceWorkSize B D) + let ω := initialOverlapLower q + let Δ := n^(-100*(totalScoreExponent B D+B+1)) + have hn1 : 1 ≤ n := by linarith only [hn] + have hn2 : 1 < n := by linarith only [hn] + have hn0 : 0|O.score z|^(2*k)) ≤ L^(2*k) := by + have hh := O.first.expect_even_pow_le_of_moment O.score k hk (O.moment.trans hv) + simpa only [pow_mul] using hh + have he (j : ℕ) (hj : j ≤ b-1) : Even (T j) := by + change Even (sourceBlockWindows N b ε j) + rw [sourceBlockWindows,ite_eq_left (by omega : jH'.trials_positive hN (by linarith only [hC]) (by positivity) (by omega)) + (fun j hj=>(H'.windows j (by omega)).1) he (fun j hj=>(H'.windows j (by omega)).2.1) + (H'.windows (b-1) (by omega)).2.2.2 O.first O.second O.decode O.score O.density O.likelihood_nonneg + O.first_simulation O.second_simulation ω a a L (by positivity) (by positivity) + ⟨initialOverlapLower_pos q,lt_of_lt_of_le (initialOverlapLower_lt_eighth hq'.1) (by norm_num)⟩ + (fun j hj=>hov j (by omega)) hk hm hnum.2.1 + (fun j hj=>hnum.2.2.2.1 j (by omega)) hnum.2.2.2.2.1 + rw [hb1] at W + have hlen (τ : Bool) : (sourceBlockWord s P atom b τ).length=sourceArithmeticLength C N b ε U.left.length U.overlapCount b := by + rw [sourceArithmeticLength_eq_block] + apply sourceBlockWord_length + intro σ + cases σ + · rfl + · exact U.equalLength.symm + have hinj : Function.Injective atom := by + intro τ σ hτσ + cases τ <;> cases σ + · rfl + · exact False.elim (U.different hτσ) + · exact False.elim (U.different hτσ.symm) + · rfl + have hne : sourceBlockWord s P atom b false≠sourceBlockWord s P atom b true := by + intro hh + have hh' := sourceBlockWord_injective s P atom U.left.length (by + intro τ; cases τ; rfl; exact U.equalLength.symm) hinj b + (fun j hj=>Nat.lt_of_lt_of_le (by omega : 0<1) (H'.copies_positive hN hj)) hh + contradiction + have hlength := H'.lengths b le_rfl + change N^(scaleA b b ε)/2 ≤ (sourceArithmeticLength C N b ε U.left.length U.overlapCount b:ℝ) ∧ + (sourceArithmeticLength C N b ε U.left.length U.overlapCount b:ℝ) ≤ N^(scaleA b b ε) at hlength + simp only [scaleA_top,Real.rpow_one] at hlength + have hE : U.error ≤ ((i:ℝ)+1)*Δ*U.left.length := by + apply (div_le_iff₀ ?_).mp U.normalized_error + exact (show 0(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀i ≤ sourceDepth B ζ ((q t)^3*Real.log (n t)), + Nonempty (SourceLevelPair B (sourceDepth B ζ ((q t)^3*Real.log (n t))) + (n t) (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ i) := by + filter_upwards [source_initial_at_smallest_scale B ζ hB hζ hn hq hH, + source_numeric_margins_eventually B ζ hB hζ hn hq hH, + source_tails_eventually B ζ hB hζ hn hq hH,hn.eventually_ge_atTop 4] with t h0 hm ht hn4 + intro i hi + induction i with + | zero => simpa only [SourceLevelPair,totalScoreExponent,Finset.range_zero, + Finset.sum_empty,add_zero,Nat.mul_zero,Nat.zero_add] using h0 + | succ i ih => + obtain ⟨U⟩ := ih (by omega) + exact source_level_step U hB (by omega) hn4 (hq t) (hm (i+1)) (ht (i+1)) + +/-- The final source pair has actual length in [n/2,n], an exact common + complete-trace simulator, prescribed high moment and inductively obtained + power overlap. This is the construction theorem, before statistical transfer. -/ +theorem source_final_pair_eventually (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) + (hζ : ζ∈Set.Ioo 0 1) {n q : ℕ→ℝ} (hn : Tendsto n atTop atTop) + (hq : ∀t,q t∈Set.Ioc 0 (1/2:ℝ)) + (hH : Tendsto (fun t=>(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ (n t) + ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) + (totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) + (initialOverlapLower (q t)) + ((sourceOverlapConstant (q t))^(2*B*sourceDepth B ζ ((q t)^3*Real.log (n t))+2)) + (sourceDepth B ζ ((q t)^3*Real.log (n t))) + (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) + (sourceDepth B ζ ((q t)^3*Real.log (n t))))) := by + filter_upwards [source_all_levels_eventually B ζ hB hζ hn hq hH] with t ht + simpa only [SourceLevelPair,sourceTargetScale_top] using ht _ le_rfl + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/InitialDensity.lean b/lean/OAI/Probability/TraceReconstruction/InitialDensity.lean index e4a00fd9bf1cff04b1171f9f860349a8c6033695..d539477dc41182ecab2f550d1cf9000f2f7d091f 100644 --- a/lean/OAI/Probability/TraceReconstruction/InitialDensity.lean +++ b/lean/OAI/Probability/TraceReconstruction/InitialDensity.lean @@ -1,527 +1,527 @@ -import OAI.Probability.TraceReconstruction.Ranks - -namespace OAI - -/-! -# InitialDensity - -Defect monomials, orthogonality, normalized initial densities, and common mass. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - -noncomputable section -namespace TraceReconstruction -open FiniteLaw - -/-- A monotone tuple of defect slots is uniquely identified by the -retained ranks whenever all these ranks carry defects. -/ -theorem exists_unique_defect_tuple {n l u r : ℕ} - (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) - (S : FixedSubset (Fin n) l) - (h : ∀ i, slotAtRank S (v.val i) ∈ Set.range d) : - ∃! j : IncreasingTuple u r, taggedRankEvent (d ∘ j.val) v.val S := by - classical - choose j hj using h - have hm : StrictMono j := by - intro a b hab - apply hd.lt_iff_lt.mp - rw [hj a,hj b] - exact slotAtRank_strictMono S (v.property hab) - refine ⟨⟨j,hm⟩,?_,?_⟩ - · intro i - exact (hj i).symm - · intro k hk - apply Subtype.ext - funext i - apply hd.injective - exact (hk i).symm.trans (hj i).symm - -/-- The degree coefficient is the sum over actual tagged defect tuples, -not a separately postulated kernel array. -/ -theorem defect_tuple_indicator {n l u r : ℕ} - (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) - (S : FixedSubset (Fin n) l) : - (if ∀ i, slotAtRank S (v.val i) ∈ Set.range d then (1:ℝ) else 0) = - ∑ j : IncreasingTuple u r, if taggedRankEvent (d ∘ j.val) v.val S then 1 else 0 := by - classical - by_cases h : ∀ i, slotAtRank S (v.val i) ∈ Set.range d - · obtain ⟨j,hj,hu⟩ := exists_unique_defect_tuple d hd v S h - rw [ite_eq_left h] - symm - rw [Finset.sum_eq_single j] - · exact ite_eq_left hj - · intro k _ hkj - have hk : ¬taggedRankEvent (d ∘ k.val) v.val S := by - intro hk - exact hkj (hu k hk) - exact ite_eq_right hk - · simp - · rw [ite_eq_right h] - symm - apply Finset.sum_eq_zero - intro j _ - apply ite_eq_right - intro hj - apply h - intro i - exact ⟨j.val i,(hj i).symm⟩ - -def rankDefectCoefficient {n l u r : ℕ} (hl : l ≤ n) (d : Fin u → Fin n) - (v : IncreasingTuple l r) : ℝ := by - classical - exact (uniformSubsetLaw l (by simpa using hl)).expect (fun S => - if ∀ i, slotAtRank S (v.val i) ∈ Set.range d then 1 else 0) - -theorem rankDefectCoefficient_eq {n l u r : ℕ} (hl : l ≤ n) - (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) : - rankDefectCoefficient hl d v = - ∑ j : IncreasingTuple u r, subsetRankKernel hl (d ∘ j.val) v.val := by - classical - unfold rankDefectCoefficient FiniteLaw.expect subsetRankKernel - simp_rw [defect_tuple_indicator d hd v, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro j _ - apply Finset.sum_congr rfl - intro S _ - split_ifs <;> simp - -/-- Bool-mask form of the selected-rank coefficient, in the exact -multilinear density expansion. -/ -theorem selected_defect_coefficient {n l : ℕ} (D : Finset (Fin n)) - (S : FixedSubset (Fin n) l) (σ : Fin l → Bool) : - selectionCoefficient (defectAtRank D S) σ = - if ∀ i, σ i = true → slotAtRank S i ∈ D then (1:ℝ) else 0 := by - classical - unfold selectionCoefficient defectAtRank - by_cases h : ∀ i, σ i = true → slotAtRank S i ∈ D - · rw [ite_eq_left h] - apply Finset.prod_eq_one - intro i _ - cases hs : σ i - · simp - · simp [h i hs] - · rw [ite_eq_right h] - push Not at h - obtain ⟨i,hi,hni⟩ := h - apply Finset.prod_eq_zero (Finset.mem_univ i) - simp [hi,hni] - -def rankMask {l r : ℕ} (v : IncreasingTuple l r) : Fin l → Bool := - fun i => decide (i ∈ Set.range v.val) - -theorem averaged_rank_coefficient {n l u r : ℕ} (hl : l ≤ n) - (d : Fin u → Fin n) (v : IncreasingTuple l r) : - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image d)) (rankMask v) = - rankDefectCoefficient hl d v := by - classical - unfold averagedCoefficient rankDefectCoefficient FiniteLaw.expect - apply Finset.sum_congr rfl - intro S _ - congr 1 - dsimp only - rw [selected_defect_coefficient] - congr 1 - simp only [rankMask,decide_eq_true_eq,Finset.mem_image,Finset.mem_univ,true_and, - Set.mem_range] - apply propext - constructor - · intro h i - exact h (v.val i) ⟨i,rfl⟩ - · rintro h i ⟨j,rfl⟩ - exact h j - -end TraceReconstruction - -namespace TraceReconstruction -open FiniteLaw - -/-- Canonical increasing tuple associated with a selected set of ranks. -/ -def tupleOfMask {l r : ℕ} (σ : Fin l → Bool) (hσ : monomialDegree σ = r) : - IncreasingTuple l r := by - classical - let S : Finset (Fin l) := Finset.univ.filter (fun i => σ i = true) - have hS : S.card = r := hσ - exact ⟨fun i => ((S.orderIsoOfFin hS) i).val, (S.orderIsoOfFin hS).strictMono⟩ - -theorem rankMask_tupleOfMask {l r : ℕ} (σ : Fin l → Bool) (hσ : monomialDegree σ = r) : - rankMask (tupleOfMask σ hσ) = σ := by - classical - funext i - have he : i ∈ Set.range (tupleOfMask σ hσ).val ↔ σ i = true := by - constructor - · rintro ⟨j,rfl⟩ - exact (Finset.mem_filter.mp (((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ) j).property).2 - · intro hi - let z : ↥(Finset.univ.filter (fun k => σ k = true)) := ⟨i,by simp [hi]⟩ - refine ⟨((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ).symm z,?_⟩ - exact congrArg Subtype.val (((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ).apply_symm_apply z) - simp only [rankMask,he] - exact Bool.decide_eq_true - -theorem tupleOfMask_injective {l r : ℕ} : Function.Injective - (fun σ : {σ : Fin l → Bool // monomialDegree σ = r} => tupleOfMask σ.val σ.property) := by - intro σ τ h - apply Subtype.ext - have he := congrArg rankMask h - simpa only [rankMask_tupleOfMask] using he - -/-- Changing from Boolean monomial labels to ordered rank tuples loses no -mass; an injection suffices for the upper bounds. -/ -theorem sum_degree_coeff_sq_le {l r : ℕ} (A : (Fin l → Bool) → ℝ) : - (∑ σ : Fin l → Bool, if monomialDegree σ = r then A σ ^ 2 else 0) ≤ - ∑ v : IncreasingTuple l r, A (rankMask v)^2 := by - classical - rw [← Finset.sum_filter] - have he : (∑ σ ∈ Finset.univ.filter (fun σ : Fin l → Bool => monomialDegree σ = r), A σ ^ 2) = - ∑ σ : {σ : Fin l → Bool // monomialDegree σ = r}, A σ.val ^ 2 := by - exact Finset.sum_subtype _ (by intro σ; simp) _ - rw [he] - have h := sum_injective_profile_le - (fun σ : {σ : Fin l → Bool // monomialDegree σ = r} => tupleOfMask σ.val σ.property) - tupleOfMask_injective (fun _ => True) (fun _ => True.intro) - (fun v => A (rankMask v)^2) (fun _ => sq_nonneg _) - simpa only [rankMask_tupleOfMask,ite_true] using h - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open FiniteLaw - -/-- Exact orthogonality of the multilinear expansion; this avoids any -loss in the channel power in consecutive-run overlap. -/ -theorem multilinear_second_moment {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (hcenter : P.expect Z = 0) (R : ℝ) - (hvar : P.expect (fun a => Z a^2) = R^2) (n : ℕ) - (A : (Fin n → Bool) → ℝ) : - (P.product n).expect (fun x => multilinear A Z x ^ 2) = - multilinearEnergy A R := by - induction n with - | zero => simp [FiniteLaw.expect,FiniteLaw.product,multilinear,multilinearEnergy] - | succ n ih => - rw [product_succ_expect_tail] - simp_rw [multilinear_cons] - have he (x : Fin n → α) : - P.expect (fun a => (multilinear (fun σ => A (Fin.cons false σ)) Z x + - Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x)^2) = - multilinear (fun σ => A (Fin.cons false σ)) Z x ^ 2 + - R^2 * multilinear (fun σ => A (Fin.cons true σ)) Z x ^ 2 := by - have hp (a : α) : - P.mass a * (multilinear (fun σ => A (Fin.cons false σ)) Z x + - Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x)^2 = - P.mass a * (multilinear (fun σ => A (Fin.cons false σ)) Z x)^2 + - 2 * multilinear (fun σ => A (Fin.cons false σ)) Z x * - multilinear (fun σ => A (Fin.cons true σ)) Z x * (P.mass a * Z a) + - (multilinear (fun σ => A (Fin.cons true σ)) Z x)^2 * (P.mass a * Z a^2) := by ring - unfold FiniteLaw.expect - simp_rw [hp,Finset.sum_add_distrib,← Finset.sum_mul,← Finset.mul_sum] - simp only [FiniteLaw.expect] at hcenter hvar - rw [P.total,hcenter,hvar] - ring - simp_rw [he] - rw [multilinearEnergy_cons] - have hadd (f g : (Fin n → α) → ℝ) : - (P.product n).expect (fun x => f x + R^2*g x) = - (P.product n).expect f + R^2*(P.product n).expect g := by - unfold FiniteLaw.expect - simp_rw [mul_add,Finset.sum_add_distrib] - rw [Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro x _ - ring - rw [hadd,ih,ih] - -/-- Association requires only a total preorder, allowing tied likelihoods. -/ -theorem FiniteLaw.associated_totalPreorder {α : Type*} [Fintype α] [Preorder α] - (P : FiniteLaw α) (htotal : ∀ a b : α, a ≤ b ∨ b ≤ a) : P.Associated := by - intro f g hf hg - have hn (a b : α) : 0 ≤ (f a - f b) * (g a - g b) := by - rcases htotal a b with hab | hba - · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (hf hab)) - (sub_nonpos.mpr (hg hab)) - · exact mul_nonneg (sub_nonneg.mpr (hf hba)) (sub_nonneg.mpr (hg hba)) - have h := Finset.sum_nonneg (s := Finset.univ) (fun a _ => - Finset.sum_nonneg (s := Finset.univ) (fun b _ => mul_nonneg (mul_nonneg (P.nonneg a) - (P.nonneg b)) (hn a b))) - have hid : (∑ a, ∑ b, P.mass a * P.mass b * ((f a - f b) * (g a - g b))) = - 2 * (P.expect (fun a => f a * g a) - P.expect f * P.expect g) := by - have hp (a b : α) : P.mass a * P.mass b * ((f a - f b) * (g a - g b)) = - (P.mass a * (f a * g a)) * P.mass b + P.mass a * (P.mass b * (f b * g b)) - - (P.mass a * f a) * (P.mass b * g b) - (P.mass a * g a) * (P.mass b * f b) := by ring - simp_rw [hp, Finset.sum_sub_distrib, Finset.sum_add_distrib, - ← Finset.mul_sum, ← Finset.sum_mul, P.total, one_mul, mul_one] - unfold FiniteLaw.expect - ring - rw [hid] at h - linarith - -/-- Conditional average densities are nonnegative when the coordinate -likelihoods are nonnegative. -/ -theorem averagedDensity_nonneg {α Ω : Type*} [Fintype Ω] {n : ℕ} - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (Z : α → ℝ) - (hZ : ∀ a, 0 ≤ 1+Z a) (x : Fin n → α) : - 0 ≤ averagedDensity R θ Z x := by - apply Finset.sum_nonneg - intro ω _ - apply mul_nonneg (R.nonneg ω) - apply Finset.prod_nonneg - intro i _ - split_ifs - · exact hZ _ - · norm_num - -theorem averagedDensity_mono {α Ω : Type*} [Preorder α] [Fintype Ω] {n : ℕ} - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (Z : α → ℝ) - (hZ : ∀ a, 0 ≤ 1+Z a) (hZm : Monotone Z) : - Monotone (averagedDensity R θ Z) := by - intro x y hxy - apply R.expect_mono - intro ω - apply Finset.prod_le_prod₀ - · intro i _ - split_ifs - · exact hZ _ - · norm_num - · intro i _ - split_ifs - · linarith [hZm (hxy i)] - · rfl - -/-- Every independent-score likelihood product is normalized. -/ -theorem selectionDensity_mean {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (hZ : P.expect Z = 0) {n : ℕ} (θ : Fin n → Bool) : - (P.product n).expect (selectionDensity θ Z) = 1 := by - unfold FiniteLaw.expect FiniteLaw.product selectionDensity - simp_rw [← Finset.prod_mul_distrib] - rw [← Fintype.prod_sum (fun (i : Fin n) (a : α) => P.mass a * (if θ i then 1+Z a else 1))] - apply Finset.prod_eq_one - intro i _ - cases θ i - · simp only [Bool.false_eq_true,↓reduceIte,mul_one,P.total] - · simp only [↓reduceIte,mul_add,mul_one,Finset.sum_add_distrib,P.total] - exact add_eq_left.mpr hZ - -theorem averagedDensity_mean {α Ω : Type*} [Fintype α] [Fintype Ω] - (P : FiniteLaw α) (R : FiniteLaw Ω) (Z : α → ℝ) (hZ : P.expect Z = 0) - {n : ℕ} (θ : Ω → Fin n → Bool) : - (P.product n).expect (averagedDensity R θ Z) = 1 := by - unfold averagedDensity FiniteLaw.expect - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - have he (ω : Ω) : (∑ x : Fin n → α, (P.product n).mass x * (R.mass ω * selectionDensity (θ ω) Z x)) = - R.mass ω * (P.product n).expect (selectionDensity (θ ω) Z) := by - rw [FiniteLaw.expect,Finset.mul_sum] - apply Finset.sum_congr rfl - intro x _ - ring - simp_rw [he,selectionDensity_mean P Z hZ,mul_one] - exact R.total - -end TraceReconstruction - -namespace TraceReconstruction -open FiniteLaw - -/-- Exact decomposition of the coefficient energy by its degree. -/ -theorem multilinearEnergy_degrees {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : - multilinearEnergy A R = ∑ r ∈ Finset.range (n+1), - R^(2*r) * ∑ σ : Fin n → Bool, if monomialDegree σ = r then A σ^2 else 0 := by - classical - unfold multilinearEnergy - simp_rw [monomial_weight] - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro σ _ - have hd : monomialDegree σ < n+1 := by - have h := Finset.card_filter_le (s := Finset.univ) (p := fun i : Fin n => σ i = true) - simpa [monomialDegree] using Nat.lt_succ_of_le h - rw [Finset.sum_eq_single (monomialDegree σ)] - · simp [mul_comm] - · intro r _ hr - simp [Ne.symm hr] - · simp [Finset.mem_range,hd] - -/-- A zero-degree selection is precisely the empty selection. -/ -theorem monomialDegree_eq_zero_iff {n : ℕ} (σ : Fin n → Bool) : - monomialDegree σ = 0 ↔ σ = fun _ => false := by - classical - constructor - · intro h - have he : Finset.univ.filter (fun i => σ i = true) = ∅ := Finset.card_eq_zero.mp h - funext i - have hn : σ i ≠ true := by - intro hi - have : i ∈ Finset.univ.filter (fun j => σ j = true) := by simp [hi] - rw [he] at this - exact Finset.notMem_empty i this - exact Bool.eq_false_iff.mpr hn - · rintro rfl - simp [monomialDegree] - -theorem averaged_degree_zero {Ω : Type*} [Fintype Ω] {n : ℕ} - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) : - (∑ σ : Fin n → Bool, if monomialDegree σ = 0 then averagedCoefficient R θ σ ^ 2 else 0) = 1 := by - classical - simp_rw [monomialDegree_eq_zero_iff] - simp [averagedCoefficient_empty] - -/-- There is no increasing selection with more entries than its ambient set. -/ -theorem increasingTuple_isEmpty {n r : ℕ} (h : n < r) : IsEmpty (IncreasingTuple n r) := by - refine ⟨fun v => ?_⟩ - have hc := Fintype.card_le_of_injective v.val v.property.injective - simp only [Fintype.card_fin] at hc - omega - -/-- The finite law of uniformly retained slots has no coefficients beyond -its number of actual defect slots. -/ -theorem defect_degree_bound {n l u r : ℕ} (hl : l ≤ n) - (d : Fin u → Fin n) (hd : StrictMono d) (hru : u < r) : - (∑ σ : Fin l → Bool, if monomialDegree σ = r then - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image d)) σ ^ 2 else 0) = 0 := by - classical - apply le_antisymm - · refine (sum_degree_coeff_sq_le (r:=r) (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image d)))).trans ?_ - simp_rw [averaged_rank_coefficient hl d,rankDefectCoefficient_eq hl d hd] - have := increasingTuple_isEmpty hru - simp - · apply Finset.sum_nonneg - intro σ _ - split_ifs <;> positivity - -/-- Coefficient version of the conditional-rank square-sum estimate. -/ -theorem period_degree_square_sum {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hru : r ≤ u) (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} - (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) - (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : - (∑ σ : Fin l → Bool, if monomialDegree σ = r then - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off))) σ ^ 2 else 0) ≤ - ((3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := by - refine (sum_degree_coeff_sq_le (r:=r) (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off))))).trans ?_ - simp_rw [averaged_rank_coefficient hl (periodSlot off), - rankDefectCoefficient_eq hl (periodSlot off) (periodSlot_strictMono off)] - exact period_rank_square_sum_delta hl hr hru hm hum hδ hθ hmean hv off hoff hdiff - -/-- The full coefficient energy is controlled by the subgaussian degree -series, uniformly in the number of retained coordinates. -/ -theorem period_density_energy {u m l : ℕ} (hl : l ≤ u*m) - (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} - (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) - (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) (R : ℝ) : - multilinearEnergy - (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off)))) R ≤ - ∑ r ∈ Finset.range (l+1), - (R^2*(3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/m))^r / (Real.sqrt (r:ℝ))^r := by - rw [multilinearEnergy_degrees] - apply Finset.sum_le_sum - intro r _ - by_cases hr : r = 0 - · subst r - rw [averaged_degree_zero] - norm_num - · by_cases hru : r ≤ u - · have hr0 : 0 < r := Nat.pos_of_ne_zero hr - have hb := period_degree_square_sum hl hr0 hru hm hum hδ hθ hmean hv off hoff hdiff - calc - _ ≤ R^(2*r)*((3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := - mul_le_mul_of_nonneg_left hb (by rw [pow_mul]; positivity) - _ = _ := by - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hr0 : (0:ℝ) < r := by exact_mod_cast hr0 - rw [show (u:ℝ)/((m:ℝ)*r)=((u:ℝ)/m)/r by field_simp] - rw [Real.sqrt_div (by positivity),pow_mul,← mul_pow,← div_pow] - congr 1 - ring - · rw [defect_degree_bound hl (periodSlot off) (periodSlot_strictMono off) (by omega),mul_zero] - have := hδ.1 - positivity [rankSchurConstant_pos] - -/-- A convenient exponential majorant for the full nonnegative degree series. -/ -theorem degree_series_le_exp (a : ℝ) (N : ℕ) : - (∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r) ≤ 2*Real.exp (a^2) := by - have hb := degree_series_bound a N - have hp := Real.exp_pos (a^2) - have he : Real.exp (2*a^2) = (Real.exp (a^2))^2 := by - rw [show 2*a^2=a^2+a^2 by ring,Real.exp_add] - ring - rw [he] at hb - nlinarith [sq_nonneg ((∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r)+2*Real.exp (a^2))] - -/-- Actual conditional initial-oracle density, with its exact second moment. -/ -theorem period_density_second_moment {α : Type*} [Fintype α] - (P : FiniteLaw α) (Z : α → ℝ) (hZ : P.expect Z = 0) - {u m l : ℕ} (hl : l ≤ u*m) - (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} - (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) - (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : - (P.product l).expect (fun x => - averagedDensity (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off))) Z x ^ 2) ≤ - 2*Real.exp ((P.expect (fun a => Z a^2))^2 * (3*rankSchurConstant/δ)^2 * ((u:ℝ)/m)) := by - have hv0 : 0 ≤ P.expect (fun a => Z a^2) := - Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) - simp_rw [averagedDensity_expansion] - rw [multilinear_second_moment P Z hZ (Real.sqrt (P.expect (fun a => Z a^2))) - (Real.sq_sqrt hv0).symm] - refine (period_density_energy hl hm hum hδ hθ hmean hv off hoff hdiff _).trans ?_ - apply (degree_series_le_exp _ (l+1)).trans - rw [Real.sq_sqrt hv0] - have he : (P.expect (fun a => Z a^2)*(3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/m))^2 = - (P.expect (fun a => Z a^2))^2*(3*rankSchurConstant/δ)^2*((u:ℝ)/m) := by - rw [mul_pow,mul_pow,Real.sq_sqrt (by positivity)] - rw [he] - -/-- The source association argument holds for any two conditional mixture -experiments using the same independent primitive marks, even when their -retained-subset sample spaces have different original sizes. -/ -theorem averagedDensity_overlap {α Ω Ψ : Type*} - [Fintype α] [Fintype Ω] [Fintype Ψ] - (P : FiniteLaw α) (R : FiniteLaw Ω) (S : FiniteLaw Ψ) - (Z : α → ℝ) (hZ : P.expect Z = 0) (hZpos : ∀ a, 0 ≤ 1+Z a) - {l : ℕ} (f : Ω → Fin l → Bool) (g : Ψ → Fin l → Bool) : - (1:ℝ)/32 ≤ - (P.product l).expect (fun x => min (averagedDensity R f Z x) (averagedDensity S g Z x)) * - (P.product l).expect (fun x => averagedDensity R f Z x ^ 2) * - (P.product l).expect (fun x => averagedDensity S g Z x ^ 2) := by - let : Preorder α := Preorder.lift Z - have htotal : ∀ a b : α, a ≤ b ∨ b ≤ a := fun a b => le_total (Z a) (Z b) - have hm : Monotone Z := fun _ _ h => h - exact increasing_density_overlap (P.product l) - (associated_product P (P.associated_totalPreorder htotal) l) - (averagedDensity R f Z) (averagedDensity S g Z) - (averagedDensity_nonneg R f Z hZpos) (averagedDensity_nonneg S g Z hZpos) - (averagedDensity_mono R f Z hZpos hm) (averagedDensity_mono S g Z hZpos hm) - (averagedDensity_mean P R Z hZ f) (averagedDensity_mean P S Z hZ g) - -end TraceReconstruction - -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Ranks + +namespace OAI + +/-! +# InitialDensity + +Defect monomials, orthogonality, normalized initial densities, and common mass. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + +noncomputable section +namespace TraceReconstruction +open FiniteLaw + +/-- A monotone tuple of defect slots is uniquely identified by the +retained ranks whenever all these ranks carry defects. -/ +theorem exists_unique_defect_tuple {n l u r : ℕ} + (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) + (S : FixedSubset (Fin n) l) + (h : ∀ i, slotAtRank S (v.val i) ∈ Set.range d) : + ∃! j : IncreasingTuple u r, taggedRankEvent (d ∘ j.val) v.val S := by + classical + choose j hj using h + have hm : StrictMono j := by + intro a b hab + apply hd.lt_iff_lt.mp + rw [hj a,hj b] + exact slotAtRank_strictMono S (v.property hab) + refine ⟨⟨j,hm⟩,?_,?_⟩ + · intro i + exact (hj i).symm + · intro k hk + apply Subtype.ext + funext i + apply hd.injective + exact (hk i).symm.trans (hj i).symm + +/-- The degree coefficient is the sum over actual tagged defect tuples, +not a separately postulated kernel array. -/ +theorem defect_tuple_indicator {n l u r : ℕ} + (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) + (S : FixedSubset (Fin n) l) : + (if ∀ i, slotAtRank S (v.val i) ∈ Set.range d then (1:ℝ) else 0) = + ∑ j : IncreasingTuple u r, if taggedRankEvent (d ∘ j.val) v.val S then 1 else 0 := by + classical + by_cases h : ∀ i, slotAtRank S (v.val i) ∈ Set.range d + · obtain ⟨j,hj,hu⟩ := exists_unique_defect_tuple d hd v S h + rw [ite_eq_left h] + symm + rw [Finset.sum_eq_single j] + · exact ite_eq_left hj + · intro k _ hkj + have hk : ¬taggedRankEvent (d ∘ k.val) v.val S := by + intro hk + exact hkj (hu k hk) + exact ite_eq_right hk + · simp + · rw [ite_eq_right h] + symm + apply Finset.sum_eq_zero + intro j _ + apply ite_eq_right + intro hj + apply h + intro i + exact ⟨j.val i,(hj i).symm⟩ + +def rankDefectCoefficient {n l u r : ℕ} (hl : l ≤ n) (d : Fin u → Fin n) + (v : IncreasingTuple l r) : ℝ := by + classical + exact (uniformSubsetLaw l (by simpa using hl)).expect (fun S => + if ∀ i, slotAtRank S (v.val i) ∈ Set.range d then 1 else 0) + +theorem rankDefectCoefficient_eq {n l u r : ℕ} (hl : l ≤ n) + (d : Fin u → Fin n) (hd : StrictMono d) (v : IncreasingTuple l r) : + rankDefectCoefficient hl d v = + ∑ j : IncreasingTuple u r, subsetRankKernel hl (d ∘ j.val) v.val := by + classical + unfold rankDefectCoefficient FiniteLaw.expect subsetRankKernel + simp_rw [defect_tuple_indicator d hd v, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro S _ + split_ifs <;> simp + +/-- Bool-mask form of the selected-rank coefficient, in the exact +multilinear density expansion. -/ +theorem selected_defect_coefficient {n l : ℕ} (D : Finset (Fin n)) + (S : FixedSubset (Fin n) l) (σ : Fin l → Bool) : + selectionCoefficient (defectAtRank D S) σ = + if ∀ i, σ i = true → slotAtRank S i ∈ D then (1:ℝ) else 0 := by + classical + unfold selectionCoefficient defectAtRank + by_cases h : ∀ i, σ i = true → slotAtRank S i ∈ D + · rw [ite_eq_left h] + apply Finset.prod_eq_one + intro i _ + cases hs : σ i + · simp + · simp [h i hs] + · rw [ite_eq_right h] + push Not at h + obtain ⟨i,hi,hni⟩ := h + apply Finset.prod_eq_zero (Finset.mem_univ i) + simp [hi,hni] + +def rankMask {l r : ℕ} (v : IncreasingTuple l r) : Fin l → Bool := + fun i => decide (i ∈ Set.range v.val) + +theorem averaged_rank_coefficient {n l u r : ℕ} (hl : l ≤ n) + (d : Fin u → Fin n) (v : IncreasingTuple l r) : + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image d)) (rankMask v) = + rankDefectCoefficient hl d v := by + classical + unfold averagedCoefficient rankDefectCoefficient FiniteLaw.expect + apply Finset.sum_congr rfl + intro S _ + congr 1 + dsimp only + rw [selected_defect_coefficient] + congr 1 + simp only [rankMask,decide_eq_true_eq,Finset.mem_image,Finset.mem_univ,true_and, + Set.mem_range] + apply propext + constructor + · intro h i + exact h (v.val i) ⟨i,rfl⟩ + · rintro h i ⟨j,rfl⟩ + exact h j + +end TraceReconstruction + +namespace TraceReconstruction +open FiniteLaw + +/-- Canonical increasing tuple associated with a selected set of ranks. -/ +def tupleOfMask {l r : ℕ} (σ : Fin l → Bool) (hσ : monomialDegree σ = r) : + IncreasingTuple l r := by + classical + let S : Finset (Fin l) := Finset.univ.filter (fun i => σ i = true) + have hS : S.card = r := hσ + exact ⟨fun i => ((S.orderIsoOfFin hS) i).val, (S.orderIsoOfFin hS).strictMono⟩ + +theorem rankMask_tupleOfMask {l r : ℕ} (σ : Fin l → Bool) (hσ : monomialDegree σ = r) : + rankMask (tupleOfMask σ hσ) = σ := by + classical + funext i + have he : i ∈ Set.range (tupleOfMask σ hσ).val ↔ σ i = true := by + constructor + · rintro ⟨j,rfl⟩ + exact (Finset.mem_filter.mp (((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ) j).property).2 + · intro hi + let z : ↥(Finset.univ.filter (fun k => σ k = true)) := ⟨i,by simp [hi]⟩ + refine ⟨((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ).symm z,?_⟩ + exact congrArg Subtype.val (((Finset.univ.filter (fun k => σ k = true)).orderIsoOfFin hσ).apply_symm_apply z) + simp only [rankMask,he] + exact Bool.decide_eq_true + +theorem tupleOfMask_injective {l r : ℕ} : Function.Injective + (fun σ : {σ : Fin l → Bool // monomialDegree σ = r} => tupleOfMask σ.val σ.property) := by + intro σ τ h + apply Subtype.ext + have he := congrArg rankMask h + simpa only [rankMask_tupleOfMask] using he + +/-- Changing from Boolean monomial labels to ordered rank tuples loses no +mass; an injection suffices for the upper bounds. -/ +theorem sum_degree_coeff_sq_le {l r : ℕ} (A : (Fin l → Bool) → ℝ) : + (∑ σ : Fin l → Bool, if monomialDegree σ = r then A σ ^ 2 else 0) ≤ + ∑ v : IncreasingTuple l r, A (rankMask v)^2 := by + classical + rw [← Finset.sum_filter] + have he : (∑ σ ∈ Finset.univ.filter (fun σ : Fin l → Bool => monomialDegree σ = r), A σ ^ 2) = + ∑ σ : {σ : Fin l → Bool // monomialDegree σ = r}, A σ.val ^ 2 := by + exact Finset.sum_subtype _ (by intro σ; simp) _ + rw [he] + have h := sum_injective_profile_le + (fun σ : {σ : Fin l → Bool // monomialDegree σ = r} => tupleOfMask σ.val σ.property) + tupleOfMask_injective (fun _ => True) (fun _ => True.intro) + (fun v => A (rankMask v)^2) (fun _ => sq_nonneg _) + simpa only [rankMask_tupleOfMask,ite_true] using h + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open FiniteLaw + +/-- Exact orthogonality of the multilinear expansion; this avoids any +loss in the channel power in consecutive-run overlap. -/ +theorem multilinear_second_moment {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (hcenter : P.expect Z = 0) (R : ℝ) + (hvar : P.expect (fun a => Z a^2) = R^2) (n : ℕ) + (A : (Fin n → Bool) → ℝ) : + (P.product n).expect (fun x => multilinear A Z x ^ 2) = + multilinearEnergy A R := by + induction n with + | zero => simp [FiniteLaw.expect,FiniteLaw.product,multilinear,multilinearEnergy] + | succ n ih => + rw [product_succ_expect_tail] + simp_rw [multilinear_cons] + have he (x : Fin n → α) : + P.expect (fun a => (multilinear (fun σ => A (Fin.cons false σ)) Z x + + Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x)^2) = + multilinear (fun σ => A (Fin.cons false σ)) Z x ^ 2 + + R^2 * multilinear (fun σ => A (Fin.cons true σ)) Z x ^ 2 := by + have hp (a : α) : + P.mass a * (multilinear (fun σ => A (Fin.cons false σ)) Z x + + Z a * multilinear (fun σ => A (Fin.cons true σ)) Z x)^2 = + P.mass a * (multilinear (fun σ => A (Fin.cons false σ)) Z x)^2 + + 2 * multilinear (fun σ => A (Fin.cons false σ)) Z x * + multilinear (fun σ => A (Fin.cons true σ)) Z x * (P.mass a * Z a) + + (multilinear (fun σ => A (Fin.cons true σ)) Z x)^2 * (P.mass a * Z a^2) := by ring + unfold FiniteLaw.expect + simp_rw [hp,Finset.sum_add_distrib,← Finset.sum_mul,← Finset.mul_sum] + simp only [FiniteLaw.expect] at hcenter hvar + rw [P.total,hcenter,hvar] + ring + simp_rw [he] + rw [multilinearEnergy_cons] + have hadd (f g : (Fin n → α) → ℝ) : + (P.product n).expect (fun x => f x + R^2*g x) = + (P.product n).expect f + R^2*(P.product n).expect g := by + unfold FiniteLaw.expect + simp_rw [mul_add,Finset.sum_add_distrib] + rw [Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro x _ + ring + rw [hadd,ih,ih] + +/-- Association requires only a total preorder, allowing tied likelihoods. -/ +theorem FiniteLaw.associated_totalPreorder {α : Type*} [Fintype α] [Preorder α] + (P : FiniteLaw α) (htotal : ∀ a b : α, a ≤ b ∨ b ≤ a) : P.Associated := by + intro f g hf hg + have hn (a b : α) : 0 ≤ (f a - f b) * (g a - g b) := by + rcases htotal a b with hab | hba + · exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (hf hab)) + (sub_nonpos.mpr (hg hab)) + · exact mul_nonneg (sub_nonneg.mpr (hf hba)) (sub_nonneg.mpr (hg hba)) + have h := Finset.sum_nonneg (s := Finset.univ) (fun a _ => + Finset.sum_nonneg (s := Finset.univ) (fun b _ => mul_nonneg (mul_nonneg (P.nonneg a) + (P.nonneg b)) (hn a b))) + have hid : (∑ a, ∑ b, P.mass a * P.mass b * ((f a - f b) * (g a - g b))) = + 2 * (P.expect (fun a => f a * g a) - P.expect f * P.expect g) := by + have hp (a b : α) : P.mass a * P.mass b * ((f a - f b) * (g a - g b)) = + (P.mass a * (f a * g a)) * P.mass b + P.mass a * (P.mass b * (f b * g b)) - + (P.mass a * f a) * (P.mass b * g b) - (P.mass a * g a) * (P.mass b * f b) := by ring + simp_rw [hp, Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.sum_mul, P.total, one_mul, mul_one] + unfold FiniteLaw.expect + ring + rw [hid] at h + linarith + +/-- Conditional average densities are nonnegative when the coordinate +likelihoods are nonnegative. -/ +theorem averagedDensity_nonneg {α Ω : Type*} [Fintype Ω] {n : ℕ} + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (Z : α → ℝ) + (hZ : ∀ a, 0 ≤ 1+Z a) (x : Fin n → α) : + 0 ≤ averagedDensity R θ Z x := by + apply Finset.sum_nonneg + intro ω _ + apply mul_nonneg (R.nonneg ω) + apply Finset.prod_nonneg + intro i _ + split_ifs + · exact hZ _ + · norm_num + +theorem averagedDensity_mono {α Ω : Type*} [Preorder α] [Fintype Ω] {n : ℕ} + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) (Z : α → ℝ) + (hZ : ∀ a, 0 ≤ 1+Z a) (hZm : Monotone Z) : + Monotone (averagedDensity R θ Z) := by + intro x y hxy + apply R.expect_mono + intro ω + apply Finset.prod_le_prod₀ + · intro i _ + split_ifs + · exact hZ _ + · norm_num + · intro i _ + split_ifs + · linarith [hZm (hxy i)] + · rfl + +/-- Every independent-score likelihood product is normalized. -/ +theorem selectionDensity_mean {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (hZ : P.expect Z = 0) {n : ℕ} (θ : Fin n → Bool) : + (P.product n).expect (selectionDensity θ Z) = 1 := by + unfold FiniteLaw.expect FiniteLaw.product selectionDensity + simp_rw [← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun (i : Fin n) (a : α) => P.mass a * (if θ i then 1+Z a else 1))] + apply Finset.prod_eq_one + intro i _ + cases θ i + · simp only [Bool.false_eq_true,↓reduceIte,mul_one,P.total] + · simp only [↓reduceIte,mul_add,mul_one,Finset.sum_add_distrib,P.total] + exact add_eq_left.mpr hZ + +theorem averagedDensity_mean {α Ω : Type*} [Fintype α] [Fintype Ω] + (P : FiniteLaw α) (R : FiniteLaw Ω) (Z : α → ℝ) (hZ : P.expect Z = 0) + {n : ℕ} (θ : Ω → Fin n → Bool) : + (P.product n).expect (averagedDensity R θ Z) = 1 := by + unfold averagedDensity FiniteLaw.expect + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + have he (ω : Ω) : (∑ x : Fin n → α, (P.product n).mass x * (R.mass ω * selectionDensity (θ ω) Z x)) = + R.mass ω * (P.product n).expect (selectionDensity (θ ω) Z) := by + rw [FiniteLaw.expect,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + ring + simp_rw [he,selectionDensity_mean P Z hZ,mul_one] + exact R.total + +end TraceReconstruction + +namespace TraceReconstruction +open FiniteLaw + +/-- Exact decomposition of the coefficient energy by its degree. -/ +theorem multilinearEnergy_degrees {n : ℕ} (A : (Fin n → Bool) → ℝ) (R : ℝ) : + multilinearEnergy A R = ∑ r ∈ Finset.range (n+1), + R^(2*r) * ∑ σ : Fin n → Bool, if monomialDegree σ = r then A σ^2 else 0 := by + classical + unfold multilinearEnergy + simp_rw [monomial_weight] + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro σ _ + have hd : monomialDegree σ < n+1 := by + have h := Finset.card_filter_le (s := Finset.univ) (p := fun i : Fin n => σ i = true) + simpa [monomialDegree] using Nat.lt_succ_of_le h + rw [Finset.sum_eq_single (monomialDegree σ)] + · simp [mul_comm] + · intro r _ hr + simp [Ne.symm hr] + · simp [Finset.mem_range,hd] + +/-- A zero-degree selection is precisely the empty selection. -/ +theorem monomialDegree_eq_zero_iff {n : ℕ} (σ : Fin n → Bool) : + monomialDegree σ = 0 ↔ σ = fun _ => false := by + classical + constructor + · intro h + have he : Finset.univ.filter (fun i => σ i = true) = ∅ := Finset.card_eq_zero.mp h + funext i + have hn : σ i ≠ true := by + intro hi + have : i ∈ Finset.univ.filter (fun j => σ j = true) := by simp [hi] + rw [he] at this + exact Finset.notMem_empty i this + exact Bool.eq_false_iff.mpr hn + · rintro rfl + simp [monomialDegree] + +theorem averaged_degree_zero {Ω : Type*} [Fintype Ω] {n : ℕ} + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) : + (∑ σ : Fin n → Bool, if monomialDegree σ = 0 then averagedCoefficient R θ σ ^ 2 else 0) = 1 := by + classical + simp_rw [monomialDegree_eq_zero_iff] + simp [averagedCoefficient_empty] + +/-- There is no increasing selection with more entries than its ambient set. -/ +theorem increasingTuple_isEmpty {n r : ℕ} (h : n < r) : IsEmpty (IncreasingTuple n r) := by + refine ⟨fun v => ?_⟩ + have hc := Fintype.card_le_of_injective v.val v.property.injective + simp only [Fintype.card_fin] at hc + omega + +/-- The finite law of uniformly retained slots has no coefficients beyond +its number of actual defect slots. -/ +theorem defect_degree_bound {n l u r : ℕ} (hl : l ≤ n) + (d : Fin u → Fin n) (hd : StrictMono d) (hru : u < r) : + (∑ σ : Fin l → Bool, if monomialDegree σ = r then + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image d)) σ ^ 2 else 0) = 0 := by + classical + apply le_antisymm + · refine (sum_degree_coeff_sq_le (r:=r) (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image d)))).trans ?_ + simp_rw [averaged_rank_coefficient hl d,rankDefectCoefficient_eq hl d hd] + have := increasingTuple_isEmpty hru + simp + · apply Finset.sum_nonneg + intro σ _ + split_ifs <;> positivity + +/-- Coefficient version of the conditional-rank square-sum estimate. -/ +theorem period_degree_square_sum {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hru : r ≤ u) (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} + (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) + (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : + (∑ σ : Fin l → Bool, if monomialDegree σ = r then + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off))) σ ^ 2 else 0) ≤ + ((3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := by + refine (sum_degree_coeff_sq_le (r:=r) (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off))))).trans ?_ + simp_rw [averaged_rank_coefficient hl (periodSlot off), + rankDefectCoefficient_eq hl (periodSlot off) (periodSlot_strictMono off)] + exact period_rank_square_sum_delta hl hr hru hm hum hδ hθ hmean hv off hoff hdiff + +/-- The full coefficient energy is controlled by the subgaussian degree +series, uniformly in the number of retained coordinates. -/ +theorem period_density_energy {u m l : ℕ} (hl : l ≤ u*m) + (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} + (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) + (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) (R : ℝ) : + multilinearEnergy + (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off)))) R ≤ + ∑ r ∈ Finset.range (l+1), + (R^2*(3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/m))^r / (Real.sqrt (r:ℝ))^r := by + rw [multilinearEnergy_degrees] + apply Finset.sum_le_sum + intro r _ + by_cases hr : r = 0 + · subst r + rw [averaged_degree_zero] + norm_num + · by_cases hru : r ≤ u + · have hr0 : 0 < r := Nat.pos_of_ne_zero hr + have hb := period_degree_square_sum hl hr0 hru hm hum hδ hθ hmean hv off hoff hdiff + calc + _ ≤ R^(2*r)*((3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := + mul_le_mul_of_nonneg_left hb (by rw [pow_mul]; positivity) + _ = _ := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hr0 : (0:ℝ) < r := by exact_mod_cast hr0 + rw [show (u:ℝ)/((m:ℝ)*r)=((u:ℝ)/m)/r by field_simp] + rw [Real.sqrt_div (by positivity),pow_mul,← mul_pow,← div_pow] + congr 1 + ring + · rw [defect_degree_bound hl (periodSlot off) (periodSlot_strictMono off) (by omega),mul_zero] + have := hδ.1 + positivity [rankSchurConstant_pos] + +/-- A convenient exponential majorant for the full nonnegative degree series. -/ +theorem degree_series_le_exp (a : ℝ) (N : ℕ) : + (∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r) ≤ 2*Real.exp (a^2) := by + have hb := degree_series_bound a N + have hp := Real.exp_pos (a^2) + have he : Real.exp (2*a^2) = (Real.exp (a^2))^2 := by + rw [show 2*a^2=a^2+a^2 by ring,Real.exp_add] + ring + rw [he] at hb + nlinarith [sq_nonneg ((∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r)+2*Real.exp (a^2))] + +/-- Actual conditional initial-oracle density, with its exact second moment. -/ +theorem period_density_second_moment {α : Type*} [Fintype α] + (P : FiniteLaw α) (Z : α → ℝ) (hZ : P.expect Z = 0) + {u m l : ℕ} (hl : l ≤ u*m) + (hm : 32 ≤ m) (hum : u ≤ m) {δ θ : ℝ} + (hδ : δ ∈ Set.Ioc 0 (1/2:ℝ)) + (hθ : θ ∈ Set.Icc (1-δ^2) (1-δ^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : + (P.product l).expect (fun x => + averagedDensity (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off))) Z x ^ 2) ≤ + 2*Real.exp ((P.expect (fun a => Z a^2))^2 * (3*rankSchurConstant/δ)^2 * ((u:ℝ)/m)) := by + have hv0 : 0 ≤ P.expect (fun a => Z a^2) := + Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) + simp_rw [averagedDensity_expansion] + rw [multilinear_second_moment P Z hZ (Real.sqrt (P.expect (fun a => Z a^2))) + (Real.sq_sqrt hv0).symm] + refine (period_density_energy hl hm hum hδ hθ hmean hv off hoff hdiff _).trans ?_ + apply (degree_series_le_exp _ (l+1)).trans + rw [Real.sq_sqrt hv0] + have he : (P.expect (fun a => Z a^2)*(3*rankSchurConstant/δ)*Real.sqrt ((u:ℝ)/m))^2 = + (P.expect (fun a => Z a^2))^2*(3*rankSchurConstant/δ)^2*((u:ℝ)/m) := by + rw [mul_pow,mul_pow,Real.sq_sqrt (by positivity)] + rw [he] + +/-- The source association argument holds for any two conditional mixture +experiments using the same independent primitive marks, even when their +retained-subset sample spaces have different original sizes. -/ +theorem averagedDensity_overlap {α Ω Ψ : Type*} + [Fintype α] [Fintype Ω] [Fintype Ψ] + (P : FiniteLaw α) (R : FiniteLaw Ω) (S : FiniteLaw Ψ) + (Z : α → ℝ) (hZ : P.expect Z = 0) (hZpos : ∀ a, 0 ≤ 1+Z a) + {l : ℕ} (f : Ω → Fin l → Bool) (g : Ψ → Fin l → Bool) : + (1:ℝ)/32 ≤ + (P.product l).expect (fun x => min (averagedDensity R f Z x) (averagedDensity S g Z x)) * + (P.product l).expect (fun x => averagedDensity R f Z x ^ 2) * + (P.product l).expect (fun x => averagedDensity S g Z x ^ 2) := by + let : Preorder α := Preorder.lift Z + have htotal : ∀ a b : α, a ≤ b ∨ b ≤ a := fun a b => le_total (Z a) (Z b) + have hm : Monotone Z := fun _ _ h => h + exact increasing_density_overlap (P.product l) + (associated_product P (P.associated_totalPreorder htotal) l) + (averagedDensity R f Z) (averagedDensity S g Z) + (averagedDensity_nonneg R f Z hZpos) (averagedDensity_nonneg S g Z hZpos) + (averagedDensity_mono R f Z hZpos hm) (averagedDensity_mono S g Z hZpos hm) + (averagedDensity_mean P R Z hZ f) (averagedDensity_mean P S Z hZ g) + +end TraceReconstruction + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/InitialMoments.lean b/lean/OAI/Probability/TraceReconstruction/InitialMoments.lean index 4b08127b02ebfd66aca682d325b07fe9048d27fa..2dab9878f760774cdaf4d296c8f75fe00be29bfe 100644 --- a/lean/OAI/Probability/TraceReconstruction/InitialMoments.lean +++ b/lean/OAI/Probability/TraceReconstruction/InitialMoments.lean @@ -1,1215 +1,1215 @@ -import OAI.Probability.TraceReconstruction.Patterns - -namespace OAI - -/-! -# InitialMoments - -Initial coefficient tails, primitive conditioning, mark-list oracle densities, pure norm estimates, and moment energies. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem signedPeriodDefects_comp {u m r : ℕ} (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (s : ℕ) (X : ℤ) (τ : ℝ) (j : IncreasingTuple u r) : - signedPeriodDefects off hsafe s X τ ∘ j.val = - shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) - (fun i => motifShift (motifIndicator s ((j.val i).val-X)) - ((prouhetSeries s).coeff ((j.val i).val-X)) τ) := by - funext i; apply Fin.ext; rfl - -def signedTupleKernel {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (j : IncreasingTuple u r) (v : IncreasingTuple l r) : ℝ := - ∑X∈π.coeff.support, π.coeff X* - (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - - subsetRankKernel hl (signedPeriodDefects off hsafe s X (-1) ∘ j.val) v.val) - -theorem signedRankCoefficient_tuple_sum {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) - (v : IncreasingTuple l r) : - signedRankCoefficient hl off hsafe π s v=∑j, signedTupleKernel hl off hsafe π s j v := by - unfold signedRankCoefficient signedTupleKernel - simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), - ← Finset.sum_sub_distrib,Finset.mul_sum] - exact Finset.sum_comm - -theorem signedTupleKernel_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) - (j : IncreasingTuple u r) (v : IncreasingTuple l r) : - signedTupleKernel hl off hsafe π s j v = ∑k : Fin r → GapDifference, - if Odd (firstDifferenceCount k) then - 2*motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0 := by - unfold signedTupleKernel - simp_rw [signedPeriodDefects_comp] - have H := mixed_signed_shift_expansion π s (fun i => (j.val i).val) - (fun a => subsetRankKernel hl - (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) - simpa only [ite_mul,zero_mul,positionalRankDifference] using H - -def clippedSignedRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : ℝ := - ∑j, if PeriodRankRegion m θ j v then signedTupleKernel hl off hsafe π s j v else 0 - -def clippedPatternCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (θ : ℝ) (k : Fin r → GapDifference) (v : IncreasingTuple l r) : ℝ := - ∑j, if PeriodRankRegion m θ j v then - motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0 - -theorem clippedSignedRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : - clippedSignedRankCoefficient hl off hsafe π s θ v = - 2*∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - clippedPatternCoefficient hl off hsafe π s θ k v else 0 := by - unfold clippedSignedRankCoefficient clippedPatternCoefficient - have he (j : IncreasingTuple u r) : - (if PeriodRankRegion m θ j v then signedTupleKernel hl off hsafe π s j v else 0) = - ∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - (if PeriodRankRegion m θ j v then - 2*motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0) else 0 := by - by_cases hv : PeriodRankRegion m θ j v - · simp only [ite_eq_left hv, signedTupleKernel_expansion] - · simp [hv] - simp_rw [he] - rw [Finset.sum_comm,Finset.mul_sum] - apply Finset.sum_congr rfl - intro k _ - by_cases hk : Odd (firstDifferenceCount k) - · simp only [ite_eq_left hk,Finset.mul_sum] - apply Finset.sum_congr rfl - intro j _ - split_ifs <;> ring - · simp [hk] - -/-- Removing coarse rank rectangles loses an explicitly exponentially - small amount in the actual coefficient, before any finite differences. -/ -theorem signedTupleKernel_tail {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2|≤3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0≤π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) (j : IncreasingTuple u r) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : - (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else - |signedTupleKernel hl off hsafe π s j v|) ≤ - 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := by - let K (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) := - subsetRankKernel hl (signedPeriodDefects off hsafe s X τ ∘ j.val) v.val - let B := ((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))) - have hK (X : ℤ) (τ : ℝ) : (∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else K X τ v)≤B := by - simp_rw [K,signedPeriodDefects_comp] - exact period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) j (hsafe.comp j.val j.property) _ hθ - have hnon (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) : 0≤K X τ v := - subsetRankKernel_nonneg _ _ _ - calc - _ ≤ ∑v : IncreasingTuple l r, ∑X∈π.coeff.support, π.coeff X* - (if PeriodRankRegion m θ j v then 0 else K X 1 v+K X (-1) v) := by - apply Finset.sum_le_sum - intro v _ - by_cases hv : PeriodRankRegion m θ j v - · simp [hv] - · simp only [ite_eq_right hv] - refine (Finset.abs_sum_le_sum_abs _ _).trans ?_ - apply Finset.sum_le_sum - intro X _ - rw [abs_mul,abs_of_nonneg (hπ X)] - apply mul_le_mul_of_nonneg_left _ (hπ X) - exact (abs_sub _ _).trans_eq (by rw [abs_of_nonneg (hnon X 1 v),abs_of_nonneg (hnon X (-1) v)]) - _ = ∑X∈π.coeff.support, π.coeff X*((∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else K X 1 v)+ - (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else K X (-1) v)) := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro X _ - rw [← Finset.mul_sum,← Finset.sum_add_distrib] - congr 1; apply Finset.sum_congr rfl - intro v _; split_ifs <;> ring - _ ≤ ∑X∈π.coeff.support, π.coeff X*(B+B) := by - apply Finset.sum_le_sum - intro X _ - exact mul_le_mul_of_nonneg_left (add_le_add (hK X 1) (hK X (-1))) (hπ X) - _ = _ := by rw [← Finset.sum_mul,hπsum]; dsimp [B]; ring - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem motif_pattern_common_short_gap {r : ℕ} (k : Fin r → GapDifference) - (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : - ∃ a : Fin r, k a≠.unchanged ∧ ∃c : Fin (r+1), ∀ {u s : ℕ} (π : IntSeries) - (j : IncreasingTuple u r), - motifPatternMultiplier π s (fun h => (j.val h).val) k≠0 → - coarsePeriodGap j.val c ≤ 2*(2^s) := by - obtain ⟨a,b,hab,ha,hb⟩ := odd_pattern_pair k hk hnl - cases r with - | zero => exact Fin.elim0 a - | succ r => - have har : a.val < r := by have := b.isLt; exact lt_of_lt_of_le hab (Nat.le_of_lt_succ b.isLt) - let i : Fin r := ⟨a.val,har⟩ - have hi : i.castSucc=a := by ext; rfl - refine ⟨a,ha,i.castSucc.succ,?_⟩ - intro u s π j hj - apply motif_pattern_bounded_gap π s j k i b - · simpa only [hi] using hab - · simpa only [hi] using ha - · exact hb - · exact hj - -theorem clipped_linear_pattern_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (a : Fin r) : - (∑v, (clippedPatternCoefficient hl off hsafe π s θ (linearPattern a) v)^2) ≤ - periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * - seriesL2Sq (prouhetSeries s*π) := by - have hb := period_pattern_norm hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) (linearPattern a) - hθ hhalf hmean hv a - (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) (linearPattern a)) - (fun h => (prouhetSeries s*π).coeff h.val) - (by intro j; rw [motif_linear_multiplier]) - (prouhet_convolution_central π hcentral) - rw [linearPattern_order] at hb - apply hb.trans - apply mul_le_mul_of_nonneg_left - (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) - unfold periodDifferencePrefactor lengthDifferenceConstant periodCentralSumConstant - positivity - -theorem clipped_nonlinear_pattern_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (k : Fin r → GapDifference) (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑v, (clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ - periodDifferencePrefactor u m r (∑h, (k h).order) θ * - periodBoundedSumConstant u r (2*(2^s)) * seriesL2Sq (geomSeries (2^s)*π) := by - obtain ⟨a,ha,c,hc⟩ := motif_pattern_common_short_gap k hk hnl - have hb := period_pattern_bounded_norm hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) k - hθ hhalf hmean hv a c - (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) k) - (fun h => (geomSeries (2^s)*π).coeff h.val) - (fun j => motifPatternMultiplier_sq_le π hπ s _ k a ha) - (fun j hj => hc π j hj) (unsigned_convolution_central π hcentral) hM - apply hb.trans - apply mul_le_mul_of_nonneg_left - (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) - unfold periodDifferencePrefactor lengthDifferenceConstant periodBoundedSumConstant - positivity - -def signedPatternBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) - (k : Fin r → GapDifference) : ℝ := - if ∃a, k=linearPattern a then - periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * seriesL2Sq (prouhetSeries s*π) - else periodDifferencePrefactor u m r (∑h, (k h).order) θ * - periodBoundedSumConstant u r (2*(2^s)) * seriesL2Sq (geomSeries (2^s)*π) - -theorem sum_square_card_bound {α β : Type*} [Fintype α] [Fintype β] (f : α → β → ℝ) : - (∑ b, (∑a, f a b)^2) ≤ (Fintype.card α:ℝ)*∑a, ∑b, f a b^2 := by - calc - _ ≤ ∑b, (Fintype.card α:ℝ)*∑a, f a b^2 := by - apply Finset.sum_le_sum - intro b _ - have h := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ - (r := fun a => f a b) (f := fun _ => (1:ℝ)) (g := fun a => f a b^2) - (by intro _ _; norm_num) (by intro _ _; positivity) (by intro _ _; simp) - simpa using h - _ = _ := by rw [← Finset.mul_sum,Finset.sum_comm] - -theorem clipped_signed_initial_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑v : IncreasingTuple l r, (clippedSignedRankCoefficient hl off hsafe π s θ v)^2) ≤ - 4*(Fintype.card (Fin r → GapDifference):ℝ)* - ∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - signedPatternBound u m r s π θ k else 0 := by - simp_rw [clippedSignedRankCoefficient_expansion,mul_pow,show (2:ℝ)^2=4 by norm_num] - rw [← Finset.mul_sum] - calc - _ ≤ 4*((Fintype.card (Fin r → GapDifference):ℝ)*∑k : Fin r → GapDifference, ∑v : IncreasingTuple l r, - (if Odd (firstDifferenceCount k) then clippedPatternCoefficient hl off hsafe π s θ k v else 0)^2) := by - exact mul_le_mul_of_nonneg_left (sum_square_card_bound (fun (k : Fin r → GapDifference) (v : IncreasingTuple l r) => - if Odd (firstDifferenceCount k) then clippedPatternCoefficient hl off hsafe π s θ k v else 0)) (by norm_num) - _ ≤ _ := by - rw [← mul_assoc] - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply Finset.sum_le_sum - intro k _ - by_cases hk : Odd (firstDifferenceCount k) - · simp only [ite_eq_left hk] - unfold signedPatternBound - split_ifs with hlin - · obtain ⟨a,rfl⟩ := hlin - exact clipped_linear_pattern_norm hm hr hl off hoff hsafe π s hcentral hθ hhalf hmean hv a - · exact clipped_nonlinear_pattern_norm hm hr hl off hoff hsafe π hπ s hcentral - hθ hhalf hmean hv k hk hlin hM - · simp [hk] - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem signedRankCoefficient_tail {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : - (∑v : IncreasingTuple l r, |signedRankCoefficient hl off hsafe π s v- - clippedSignedRankCoefficient hl off hsafe π s θ v|) ≤ - (Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))) := by - simp_rw [signedRankCoefficient_tuple_sum,clippedSignedRankCoefficient,← Finset.sum_sub_distrib] - calc - _ ≤ ∑v : IncreasingTuple l r, ∑j : IncreasingTuple u r, - if PeriodRankRegion m θ j v then 0 else |signedTupleKernel hl off hsafe π s j v| := by - apply Finset.sum_le_sum - intro v _ - refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ - apply Finset.sum_congr rfl - intro j _ - split_ifs <;> simp - _ = ∑j : IncreasingTuple u r, ∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else |signedTupleKernel hl off hsafe π s j v| := Finset.sum_comm - _ ≤ _ := by - calc - _ ≤ ∑j : IncreasingTuple u r, - 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := - Finset.sum_le_sum (fun j _ => signedTupleKernel_tail hu hm hr hl off hoff hsafe π hπ hπsum s j hθ) - _ = _ := by simp - -/-- A globally discarded l1 tail is also negligible in coefficient energy. - This does not assume pointwise cancellation on the discarded ranks. -/ -theorem finite_sum_sq_le_abs_sum_sq {α : Type*} [Fintype α] (f : α → ℝ) : - (∑a, f a^2) ≤ (∑a, |f a|)^2 := by - have h := Finset.sum_sq_le_sq_sum_of_nonneg (s := Finset.univ) (f := fun a => |f a|) - (by intro a _; exact abs_nonneg _) - simpa only [sq_abs] using h - -theorem initial_signed_energy {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑v : IncreasingTuple l r, (signedRankCoefficient hl off hsafe π s v)^2) ≤ - 8*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - signedPatternBound u m r s π θ k else 0) + - 2*((Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by - let A : IncreasingTuple l r → ℝ := signedRankCoefficient hl off hsafe π s - let C : IncreasingTuple l r → ℝ := clippedSignedRankCoefficient hl off hsafe π s θ - have hn := clipped_signed_initial_norm (by omega) hr hl off hoff hsafe π hπ s hcentral hθ hhalf hmean hv hM - have ht := signedRankCoefficient_tail hu hm hr hl off hoff hsafe π hπ hπsum s hθ - have hE := (finite_sum_sq_le_abs_sum_sq (fun v : IncreasingTuple l r => A v-C v)).trans - (pow_le_pow_left₀ (Finset.sum_nonneg (fun v _ => abs_nonneg (A v-C v))) ht 2) - have hsum : (∑v : IncreasingTuple l r, A v^2) ≤ - 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := by - simp only [Finset.mul_sum,← Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro v _ - nlinarith [sq_nonneg (A v-2*C v)] - calc - _ ≤ 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := hsum - _ ≤ _ := by dsimp [C] at *; linarith - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Exact complete-trace expectation, recursively on the actual binary word. -/ -def listDeletionExpectation (q : ℝ) : List Bool → (List Bool → ℝ) → ℝ - | [], F => F [] - | b::w, F => q*listDeletionExpectation q w F + - (1-q)*listDeletionExpectation q w (fun t => F (b::t)) - -theorem traceOfMask_cons {n : ℕ} (x : Word (n+1)) (b : Bool) (a : Mask n) : - traceOfMask x (Fin.cons b a)= - if b then x 0::traceOfMask (fun i => x i.succ) a - else traceOfMask (fun i => x i.succ) a := by - rw [trace_filterMap,List.ofFn_succ,trace_filterMap] - cases b <;> simp - -theorem maskWeight_cons {n : ℕ} (q : ℝ) (b : Bool) (a : Mask n) : - maskWeight q (Fin.cons b a)=(if b then 1-q else q)*maskWeight q a := by - simp [maskWeight,Fin.prod_univ_succ] - -theorem listDeletionExpectation_ofFn {n : ℕ} (q : ℝ) (x : Word n) (F : List Bool → ℝ) : - listDeletionExpectation q (List.ofFn x) F = - ∑a : Mask n, maskWeight q a*F (traceOfMask x a) := by - induction n generalizing F with - | zero => simp [listDeletionExpectation,maskWeight,traceOfMask] - | succ n ih => - rw [List.ofFn_succ,listDeletionExpectation,ih,ih] - symm - rw [← (Fin.consEquiv (fun _ : Fin (n+1) => Bool)).sum_comp,Fintype.sum_prod_type] - change (∑b : Bool, ∑a : Mask n, maskWeight q (Fin.cons b a)*F (traceOfMask x (Fin.cons b a)))=_ - simp_rw [maskWeight_cons,traceOfMask_cons] - simp only [Bool.false_eq_true,ite_false,ite_true,Fintype.sum_bool] - simp only [mul_assoc,← Finset.mul_sum] - ring - -theorem listDeletionExpectation_append (q : ℝ) (x y : List Bool) (F : List Bool → ℝ) : - listDeletionExpectation q (x++y) F = - listDeletionExpectation q x (fun t => listDeletionExpectation q y (fun u => F (t++u))) := by - induction x generalizing F with - | nil => simp [listDeletionExpectation] - | cons b x ih => simp only [List.cons_append,listDeletionExpectation,ih] - -/-- The primitive alphabet consists of the literal strings 01 and 1. -/ -def primitiveBlock (b : Bool) : List Bool := if b then [true] else [false,true] - -theorem primitiveBlock_expectation (q : ℝ) (b : Bool) (F : List Bool → ℝ) : - listDeletionExpectation q (primitiveBlock b) F = - ∑z : PrimitiveMark, (if b then defectPrimitiveMass q z else ordinaryPrimitiveMass q z)*F (primitiveOutput z) := by - cases b <;> simp [primitiveBlock,listDeletionExpectation,primitiveOutput, - defectPrimitiveMass,ordinaryPrimitiveMass,Fin.sum_univ_succ] - ring - -theorem primitiveBlock_erasure_expectation {q : ℝ} (hq : q∈Set.Ioo 0 1) - (b : Bool) (F : List Bool → ℝ) : - listDeletionExpectation q (primitiveBlock b) F = - primitiveErasure q * F []+(1-primitiveErasure q)* - (primitiveMarkLaw q hq b).expect (fun z => F (primitiveOutput z)) := by - rw [primitiveBlock_expectation] - simp_rw [← primitiveMark_simulation hq] - simp only [add_mul,Finset.sum_add_distrib] - simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true, - primitiveOutput,Matrix.cons_val_zero] - simp only [FiniteLaw.expect,primitiveMarkLaw,mul_assoc,← Finset.mul_sum] - -/-- Independent silent block erasures and conditionally emitted primitive marks. - An emitted empty mark is retained in the list and differs from a silent erasure. -/ -def silentMarkExpectation (q : ℝ) : List Bool → (List PrimitiveMark → ℝ) → ℝ - | [], F => F [] - | b::bs, F => primitiveErasure q*silentMarkExpectation q bs F + - (1-primitiveErasure q)*∑z : PrimitiveMark, primitiveMarkMass q b z* - silentMarkExpectation q bs (fun ys => F (z::ys)) - -def joinPrimitiveMarks (ys : List PrimitiveMark) : List Bool := (ys.map primitiveOutput).flatten - -theorem silentMarkExpectation_linear (q : ℝ) (bs : List Bool) - (F G : List PrimitiveMark → ℝ) (a b : ℝ) : - silentMarkExpectation q bs (fun ys => a*F ys+b*G ys)= - a*silentMarkExpectation q bs F+b*silentMarkExpectation q bs G := by - induction bs generalizing F G with - | nil => rfl - | cons x xs ih => - simp only [silentMarkExpectation,ih,mul_add,Finset.sum_add_distrib] - have hf : (∑ z : PrimitiveMark, primitiveMarkMass q x z * - (a*silentMarkExpectation q xs (fun ys => F (z::ys)))) = - a*∑ z : PrimitiveMark, primitiveMarkMass q x z * silentMarkExpectation q xs (fun ys => F (z::ys)) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro z _; ring - have hg : (∑ z : PrimitiveMark, primitiveMarkMass q x z * - (b*silentMarkExpectation q xs (fun ys => G (z::ys)))) = - b*∑ z : PrimitiveMark, primitiveMarkMass q x z * silentMarkExpectation q xs (fun ys => G (z::ys)) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro z _; ring - rw [hf,hg]; ring - -theorem silentMarkExpectation_sum {ι : Type*} [Fintype ι] (q : ℝ) (bs : List Bool) - (F : ι → List PrimitiveMark → ℝ) : - silentMarkExpectation q bs (fun ys => ∑i, F i ys)=∑i, silentMarkExpectation q bs (F i) := by - induction bs generalizing F with - | nil => rfl - | cons x xs ih => - simp only [silentMarkExpectation,ih,Finset.mul_sum,Finset.sum_add_distrib] - congr 1 - rw [Finset.sum_comm] - -theorem silentMarkExpectation_scale (q : ℝ) (bs : List Bool) - (F : List PrimitiveMark → ℝ) (a : ℝ) : - silentMarkExpectation q bs (fun ys => a*F ys)=a*silentMarkExpectation q bs F := by - have h := silentMarkExpectation_linear q bs F F a 0 - simpa using h - -/-- The common deterministic mark-joining simulator is exact for arbitrary - concatenations of primitive blocks; block boundaries are not reported. -/ -theorem primitive_run_simulation {q : ℝ} (hq : q∈Set.Ioo 0 1) - (bs : List Bool) (F : List Bool → ℝ) : - listDeletionExpectation q ((bs.map primitiveBlock).flatten) F = - silentMarkExpectation q bs (fun ys => F (joinPrimitiveMarks ys)) := by - induction bs generalizing F with - | nil => rfl - | cons b bs ih => - simp only [List.map_cons,List.flatten_cons] - rw [listDeletionExpectation_append,primitiveBlock_erasure_expectation hq] - simp only [List.nil_append,ih,FiniteLaw.expect,primitiveMarkLaw] - simp only [silentMarkExpectation] - rfl - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Every emitted mark is counted, including the empty primitive output. -/ -def emittedMarkExpectation (q : ℝ) : List Bool → (List PrimitiveMark → ℝ) → ℝ - | [], F => F [] - | b::bs, F => ∑z : PrimitiveMark, primitiveMarkMass q b z* - emittedMarkExpectation q bs (fun ys => F (z::ys)) - -theorem emittedMarkExpectation_ofFn {n : ℕ} (q : ℝ) (θ : Fin n → Bool) - (F : List PrimitiveMark → ℝ) : - emittedMarkExpectation q (List.ofFn θ) F= - ∑x : Fin n → PrimitiveMark, (∏i, primitiveMarkMass q (θ i) (x i))*F (List.ofFn x) := by - induction n generalizing F with - | zero => simp [emittedMarkExpectation] - | succ n ih => - rw [List.ofFn_succ,emittedMarkExpectation] - simp_rw [ih,Finset.mul_sum] - rw [← (Fin.consEquiv (fun _ : Fin (n+1) => PrimitiveMark)).sum_comp,Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro z _ - apply Finset.sum_congr rfl - intro x _ - simp [Fin.consEquiv,Fin.prod_univ_succ,List.ofFn_succ,mul_assoc] - -/-- Conditioning the independent erasures on the return count chooses - a uniformly random subset of the original block slots. -/ -theorem silentMarkExpectation_mask_mixture {n : ℕ} (q : ℝ) (θ : Fin n → Bool) - (F : List PrimitiveMark → ℝ) : - silentMarkExpectation q (List.ofFn θ) F= - ∑a : Mask n, maskWeight (primitiveErasure q) a* - emittedMarkExpectation q (traceOfMask θ a) F := by - induction n generalizing F with - | zero => simp [silentMarkExpectation,emittedMarkExpectation,maskWeight,traceOfMask] - | succ n ih => - rw [List.ofFn_succ,silentMarkExpectation] - simp_rw [ih] - symm - rw [← (Fin.consEquiv (fun _ : Fin (n+1) => Bool)).sum_comp,Fintype.sum_prod_type] - change (∑b : Bool, ∑a : Mask n, maskWeight (primitiveErasure q) (Fin.cons b a)* - emittedMarkExpectation q (traceOfMask θ (Fin.cons b a)) F)=_ - simp_rw [maskWeight_cons,traceOfMask_cons] - simp only [Fintype.sum_bool,ite_true,Bool.false_eq_true,ite_false,emittedMarkExpectation] - simp_rw [mul_assoc,Finset.mul_sum] - rw [Finset.sum_comm,add_comm] - congr 1 - apply Finset.sum_congr rfl - intro z _ - apply Finset.sum_congr rfl - intro a _ - ring - -def maskSubset {n : ℕ} (a : Mask n) : Finset (Fin n) := Finset.univ.filter fun i => a i - -def maskSubsetEquiv (n : ℕ) : Mask n ≃ Finset (Fin n) where - toFun := maskSubset - invFun S i := decide (i∈S) - left_inv a := by funext i; simp [maskSubset] - right_inv S := by ext i; simp [maskSubset] - -theorem maskWeight_card {n : ℕ} (q : ℝ) (a : Mask n) : - maskWeight q a = (1-q)^(maskSubset a).card*q^(n-(maskSubset a).card) := by - unfold maskWeight maskSubset - rw [Finset.prod_ite] - simp only [Finset.prod_const] - congr 1 - have h := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin n))) (p := fun i => a i) - rw [Finset.card_univ,Fintype.card_fin] at h - rw [show (Finset.univ.filter fun i : Fin n => ¬a i=true).card= - n-(Finset.univ.filter fun i : Fin n => a i=true).card by omega] - -theorem slotAtRank_ofFn {n l : ℕ} (S : FixedSubset (Fin n) l) : - List.ofFn (slotAtRank S)=S.val.sort := by - apply List.ext_getElem - · simp [S.property] - · intro i hi hj - simp only [List.getElem_ofFn] - rfl - -theorem filtered_finRange_eq_sort {n : ℕ} (S : Finset (Fin n)) : - ((List.finRange n).filter fun i => decide (i∈S))=S.sort := by - apply ((List.sortedLT_finRange n).pairwise.filter _).eq_of_mem_iff S.sortedLT_sort.pairwise - intro a - simp - -theorem selected_types_ofFn {n l : ℕ} (θ : Fin n → Bool) (S : FixedSubset (Fin n) l) : - traceOfMask θ (fun i => decide (i∈S.val))=List.ofFn (fun v => θ (slotAtRank S v)) := by - rw [traceOfMask,filtered_finRange_eq_sort,← slotAtRank_ofFn S,List.map_ofFn] - rfl - -theorem silentMarkExpectation_subset_mixture {n : ℕ} (q : ℝ) (θ : Fin n → Bool) - (F : List PrimitiveMark → ℝ) : - silentMarkExpectation q (List.ofFn θ) F= - ∑S : Finset (Fin n), subsetWeight (1-primitiveErasure q) S* - emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S))) F := by - rw [silentMarkExpectation_mask_mixture,← (maskSubsetEquiv n).symm.sum_comp] - apply Finset.sum_congr rfl - intro S _ - rw [maskWeight_card] - change (1-primitiveErasure q)^(maskSubsetEquiv n ((maskSubsetEquiv n).symm S)).card * - (primitiveErasure q)^(n-(maskSubsetEquiv n ((maskSubsetEquiv n).symm S)).card)* - emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S))) F=_ - rw [Equiv.apply_symm_apply] - simp [subsetWeight] - -def cardinalSubsetEquiv (n : ℕ) : Finset (Fin n) ≃ Σl : Fin (n+1), FixedSubset (Fin n) l.val where - toFun S := ⟨⟨S.card, by have := Finset.card_le_univ S; simpa using Nat.lt_succ_of_le this⟩,⟨S,rfl⟩⟩ - invFun x := x.2.val - left_inv _ := rfl - right_inv x := by - rcases x with ⟨⟨l,hl⟩,⟨S,hS⟩⟩ - dsimp - change S.card=l at hS - subst l - rfl - -theorem subsetWeight_count_factor {n l : ℕ} (hl : l ≤ n) (p : ℝ) (S : FixedSubset (Fin n) l) : - subsetWeight p S.val=binomialMass n p l*(uniformSubsetLaw l (by simpa using hl)).mass S := by - have hc : (n.choose l:ℝ)≠0 := by exact_mod_cast (Nat.choose_pos hl).ne' - simp only [subsetWeight,binomialMass,uniformSubsetLaw,S.property,Fintype.card_fin] - field_simp - -/-- The literal conditional-list oracle used by the rank coefficients. -/ -def conditionalPrimitiveLaw {n l : ℕ} (hl : l ≤ n) (q : ℝ) (hq : q∈Set.Ioo 0 1) - (θ : Fin n → Bool) : FiniteLaw (Fin l → PrimitiveMark) := - (uniformSubsetLaw l (by simpa using hl)).mixture fun S => - FiniteLaw.coordinateProduct (fun v => primitiveMarkLaw q hq (θ (slotAtRank S v))) - -theorem silentMarkExpectation_count_mixture {n : ℕ} (q : ℝ) (hq : q∈Set.Ioo 0 1) - (θ : Fin n → Bool) (F : List PrimitiveMark → ℝ) : - silentMarkExpectation q (List.ofFn θ) F= - ∑l : Fin (n+1), binomialMass n (1-primitiveErasure q) l.val* - (conditionalPrimitiveLaw (Nat.le_of_lt_succ l.isLt) q hq θ).expect (fun x => F (List.ofFn x)) := by - rw [silentMarkExpectation_subset_mixture,← (cardinalSubsetEquiv n).symm.sum_comp,Fintype.sum_sigma] - apply Finset.sum_congr rfl - intro l _ - change (∑S : FixedSubset (Fin n) l.val, subsetWeight (1-primitiveErasure q) S.val* - emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S.val))) F)=_ - calc - _ = ∑S : FixedSubset (Fin n) l.val, binomialMass n (1-primitiveErasure q) l.val* - (uniformSubsetLaw l.val (by simpa using Nat.le_of_lt_succ l.isLt)).mass S* - (∑x : Fin l.val → PrimitiveMark, (∏v, primitiveMarkMass q (θ (slotAtRank S v)) (x v))*F (List.ofFn x)) := by - apply Finset.sum_congr rfl - intro S _ - rw [subsetWeight_count_factor (Nat.le_of_lt_succ l.isLt),selected_types_ofFn θ S,emittedMarkExpectation_ofFn] - _ = _ := by - unfold conditionalPrimitiveLaw FiniteLaw.expect FiniteLaw.mixture FiniteLaw.coordinateProduct primitiveMarkLaw - simp_rw [Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro S _ - ring - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Density of the actual uniform-subset primitive oracle, over the ordinary - mark product law. This is exactly the channel defined by silent erasures. -/ -theorem conditionalPrimitiveLaw_density {n l : ℕ} (hl : l ≤ n) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (θ : Fin n → Bool) (x : Fin l → PrimitiveMark) : - (conditionalPrimitiveLaw hl q hq θ).mass x = - ((primitiveMarkLaw q hq false).product l).mass x * - averagedDensity (uniformSubsetLaw l (by simpa using hl)) - (fun S v => θ (slotAtRank S v)) (primitiveScore q) x := by - have he : (fun S : FixedSubset (Fin n) l => - FiniteLaw.coordinateProduct (fun v => primitiveMarkLaw q hq (θ (slotAtRank S v)))) = - (fun S : FixedSubset (Fin n) l => - FiniteLaw.coordinateProduct (fun v => if θ (slotAtRank S v) then - primitiveMarkLaw q hq true else primitiveMarkLaw q hq false)) := by - funext S - congr 1 - funext v - cases θ (slotAtRank S v) <;> rfl - unfold conditionalPrimitiveLaw - rw [he] - exact leaf_oracle_density (primitiveMarkLaw q hq false) (primitiveMarkLaw q hq true) - (primitiveScore q) (primitive_score_identity hq) - (uniformSubsetLaw l (by simpa using hl)) (fun S v => θ (slotAtRank S v)) x - -def defectTypes {n u : ℕ} (d : Fin u → Fin n) (i : Fin n) : Bool := decide (i∈Set.range d) - -theorem defectTypes_atRank {n l u : ℕ} (d : Fin u → Fin n) (S : FixedSubset (Fin n) l) : - (fun v => defectTypes d (slotAtRank S v))=defectAtRank (Finset.univ.image d) S := by - funext v - simp [defectTypes,defectAtRank,Set.mem_range] - -theorem conditionalDefectLaw_density {n l u : ℕ} (hl : l ≤ n) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (d : Fin u → Fin n) (x : Fin l → PrimitiveMark) : - (conditionalPrimitiveLaw hl q hq (defectTypes d)).mass x = - ((primitiveMarkLaw q hq false).product l).mass x * - multilinear (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image d))) (primitiveScore q) x := by - rw [conditionalPrimitiveLaw_density,show (fun S v => defectTypes d (slotAtRank S v))= - defectAtRank (Finset.univ.image d) by funext S; exact defectTypes_atRank d S, - averagedDensity_expansion] - -/-- The finite-support law of the hidden motif anchor, not an additional - distributional assumption or a changed channel parameter. -/ -def seriesProbabilityLaw (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) - (hπsum : ∑X∈π.coeff.support, π.coeff X=1) : FiniteLaw ↥π.coeff.support where - mass X := π.coeff X.val - nonneg X := hπ X.val - total := by simpa only [Finset.univ_eq_attach,Finset.sum_attach] using hπsum - -def mixedMotifCoefficient {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (τ : ℝ) (σ : Fin l → Bool) : ℝ := - ∑X∈π.coeff.support, π.coeff X* - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X τ))) σ - -def conditionalMotifLaw {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) - (hπsum : ∑X∈π.coeff.support, π.coeff X=1) (s : ℕ) (τ : ℝ) : - FiniteLaw (Fin l → PrimitiveMark) := - (seriesProbabilityLaw π hπ hπsum).mixture fun X => - conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X.val τ)) - -theorem conditionalMotifLaw_density {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) - (hπsum : ∑X∈π.coeff.support, π.coeff X=1) (s : ℕ) (τ : ℝ) (x : Fin l → PrimitiveMark) : - (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).mass x= - ((primitiveMarkLaw q hq false).product l).mass x * - multilinear (mixedMotifCoefficient hl off hsafe π s τ) (primitiveScore q) x := by - unfold conditionalMotifLaw FiniteLaw.mixture seriesProbabilityLaw - simp_rw [conditionalDefectLaw_density] - let F : ℤ → ℝ := fun X => π.coeff X * - (((primitiveMarkLaw q hq false).product l).mass x * - multilinear (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X τ)))) - (primitiveScore q) x) - change (∑ X : ↥π.coeff.support, F X.val) = _ - rw [Finset.sum_coe_sort] - dsimp only [F] - unfold mixedMotifCoefficient multilinear - simp_rw [Finset.mul_sum,Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro σ _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro X _ - ring - -theorem mixedMotifCoefficient_rank_difference {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : - mixedMotifCoefficient hl off hsafe π s 1 (rankMask v)- - mixedMotifCoefficient hl off hsafe π s (-1) (rankMask v)= - signedRankCoefficient hl off hsafe π s v := by - unfold mixedMotifCoefficient signedRankCoefficient - simp_rw [averaged_rank_coefficient hl _ v] - rw [← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro X _ - ring - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def unchangedPattern (r : ℕ) : Fin r → GapDifference := fun _ => .unchanged - -theorem unchanged_positional_value {r : ℕ} (W : (Fin r → Fin 3) → ℝ) : - (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (unchangedPattern r h) (a h))*W a)= - W (fun _ => 1) := by - simp only [unchangedPattern,positionalWeight] - simp_rw [product_function_delta] - simp - -/-- Comparing a signed displaced motif with the literal centered pure run - retains every nonconstant positional pattern, not just odd ones. -/ -theorem motif_pure_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) - (hβ : ∀h, IsMotifValue (χ h) (β h)) (W : (Fin r → Fin 3) → ℝ) : - W (fun h => motifShift (χ h) (β h) 1)-W (fun _ => 1)= - ∑ k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - (∏h, motifDifferenceWeight (χ h) (β h) 1 (k h))* - (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) := by - rw [motif_shift_expansion χ β 1 hβ (Or.inl rfl) W] - have he : W (fun _ => 1)=∑k : Fin r → GapDifference, - if k=unchangedPattern r then - (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) else 0 := by - simp [unchanged_positional_value] - rw [he,← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro k _ - by_cases hk : k=unchangedPattern r - · subst k - simp [unchangedPattern,motifDifferenceWeight] - · simp [hk] - -theorem mixed_pure_shift_expansion {r : ℕ} (π : IntSeries) (s : ℕ) - (j : Fin r → ℤ) (W : (Fin r → Fin 3) → ℝ) : - (∑X∈π.coeff.support, π.coeff X * - (W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) 1)- - W (fun _ => 1)))= - ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - motifPatternMultiplier π s j k * - (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) := by - simp_rw [motif_pure_shift_expansion _ _ (fun h => prouhet_motif_value s (j h-_)) W, - Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro k _ - by_cases hk : k=unchangedPattern r - · simp [hk] - · simp only [ite_eq_right hk,motifPatternMultiplier,Finset.sum_mul,mul_assoc] - simp_rw [Finset.mul_sum] - exact Finset.sum_comm - -theorem pattern_order_zero {r : ℕ} (k : Fin r → GapDifference) - (hk : (∑h, (k h).order)=0) : k=unchangedPattern r := by - funext h - have hh := Finset.single_le_sum (fun i (_ : i∈(Finset.univ : Finset (Fin r))) => - Nat.zero_le (k i).order) (Finset.mem_univ h) - rw [hk] at hh - have hz : (k h).order=0 := by omega - cases he : k h <;> simp_all [GapDifference.order,unchangedPattern] - -theorem nonconstant_pattern_linear_or_order_two {r : ℕ} (k : Fin r → GapDifference) - (hk : k≠unchangedPattern r) : (∃h, k=linearPattern h) ∨ 2≤∑h,(k h).order := by - by_cases hlin : ∃h, k=linearPattern h - · exact Or.inl hlin - right - by_contra hsmall - have horder : (∑h,(k h).order)=1 := by - have hn : (∑h,(k h).order)≠0 := fun he => hk (pattern_order_zero k he) - omega - have hc := difference_order_eq_counts k - have hfirst : firstDifferenceCount k=1 := by omega - have hsecond : secondDifferenceCount k=0 := by omega - exact hlin (first_second_counts_linear k hfirst hsecond) - - -/-- A nonconstant motif pattern always has an actual involved position. -/ -theorem nonconstant_pattern_position {r : ℕ} (k : Fin r → GapDifference) - (hk : k≠unchangedPattern r) : ∃a, k a≠.unchanged := by - by_contra h - push Not at h - exact hk (funext h) - -theorem clipped_pure_nonlinear_pattern_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (k : Fin r → GapDifference) (hk : k≠unchangedPattern r) : - (∑v : IncreasingTuple l r, (clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ - periodDifferencePrefactor u m r (∑h, (k h).order) θ * - periodCentralSumConstant u r * seriesL2Sq (geomSeries (2^s)*π) := by - obtain ⟨a,ha⟩ := nonconstant_pattern_position k hk - have hb := period_pattern_norm hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) k - hθ hhalf hmean hv a - (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) k) - (fun h => (geomSeries (2^s)*π).coeff h.val) - (fun j => motifPatternMultiplier_sq_le π hπ s _ k a ha) - (unsigned_convolution_central π hcentral) - apply hb.trans - apply mul_le_mul_of_nonneg_left - (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) - unfold periodDifferencePrefactor lengthDifferenceConstant periodCentralSumConstant - positivity - -def purePatternBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) - (k : Fin r → GapDifference) : ℝ := - if ∃a, k=linearPattern a then - periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * seriesL2Sq (prouhetSeries s*π) - else periodDifferencePrefactor u m r (∑h, (k h).order) θ * - periodCentralSumConstant u r * seriesL2Sq (geomSeries (2^s)*π) - -/-- Complete clipped energy, comparing the signed motif to a pure run. -/ -theorem clipped_pure_initial_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : - (∑v : IncreasingTuple l r, (∑k : Fin r → GapDifference, - if k=unchangedPattern r then 0 else clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ - (Fintype.card (Fin r → GapDifference):ℝ)* - ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - purePatternBound u m r s π θ k := by - apply (sum_square_card_bound (fun (k : Fin r → GapDifference) (v : IncreasingTuple l r) => - if k=unchangedPattern r then 0 else clippedPatternCoefficient hl off hsafe π s θ k v)).trans - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply Finset.sum_le_sum - intro k _ - by_cases hk : k=unchangedPattern r - · simp [hk] - · simp only [ite_eq_right hk] - unfold purePatternBound - split_ifs with hlin - · obtain ⟨a,rfl⟩ := hlin - exact clipped_linear_pattern_norm hm hr hl off hoff hsafe π s hcentral hθ hhalf hmean hv a - · exact clipped_pure_nonlinear_pattern_norm hm hr hl off hoff hsafe π hπ s hcentral - hθ hhalf hmean hv k hk - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem shiftedTag_center {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) : - shiftedTag p hp (fun _ => 1)=p := by - funext i - apply Fin.ext - simp [shiftedTag] - -def pureRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : ℝ := - ∑X∈π.coeff.support, π.coeff X * - (rankDefectCoefficient hl (signedPeriodDefects off hsafe s X 1) v - - rankDefectCoefficient hl (periodSlot (fun _ => off)) v) - -def pureTupleKernel {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (j : IncreasingTuple u r) (v : IncreasingTuple l r) : ℝ := - ∑X∈π.coeff.support, π.coeff X * - (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - - subsetRankKernel hl (periodSlot (fun _ => off) ∘ j.val) v.val) - -theorem pureRankCoefficient_tuple_sum {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) - (v : IncreasingTuple l r) : - pureRankCoefficient hl off hsafe π s v=∑j, pureTupleKernel hl off hsafe π s j v := by - unfold pureRankCoefficient pureTupleKernel - simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), - rankDefectCoefficient_eq _ _ (periodSlot_strictMono _), - ← Finset.sum_sub_distrib,Finset.mul_sum] - exact Finset.sum_comm - -theorem pureTupleKernel_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) - (j : IncreasingTuple u r) (v : IncreasingTuple l r) : - pureTupleKernel hl off hsafe π s j v = ∑k : Fin r → GapDifference, - if k=unchangedPattern r then 0 else - motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v := by - unfold pureTupleKernel - simp_rw [signedPeriodDefects_comp] - have H := mixed_pure_shift_expansion π s (fun i => (j.val i).val) - (fun a => subsetRankKernel hl - (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) - simpa only [shiftedTag_center,positionalRankDifference] using H - -def clippedPureRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : ℝ := - ∑j, if PeriodRankRegion m θ j v then pureTupleKernel hl off hsafe π s j v else 0 - -theorem clippedPureRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : - clippedPureRankCoefficient hl off hsafe π s θ v = - ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - clippedPatternCoefficient hl off hsafe π s θ k v := by - unfold clippedPureRankCoefficient clippedPatternCoefficient - simp_rw [pureTupleKernel_expansion] - have he (j : IncreasingTuple u r) : - (if PeriodRankRegion m θ j v then ∑k : Fin r → GapDifference, - if k=unchangedPattern r then 0 else - motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0)= - ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - (if PeriodRankRegion m θ j v then - motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0) := by - by_cases hv : PeriodRankRegion m θ j v <;> simp [hv] - simp_rw [he] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro k _ - by_cases hk : k=unchangedPattern r <;> simp [hk] - -theorem pureTupleKernel_tail {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2|≤3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0≤π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) (j : IncreasingTuple u r) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : - (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else - |pureTupleKernel hl off hsafe π s j v|) ≤ - 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := by - let K (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) := - subsetRankKernel hl (if τ=1 then signedPeriodDefects off hsafe s X 1 ∘ j.val - else periodSlot (fun _ => off) ∘ j.val) v.val - let B := ((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))) - have hK (X : ℤ) (τ : ℝ) : (∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else K X τ v)≤B := by - dsimp [K] - split_ifs - · rw [signedPeriodDefects_comp] - exact period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) j (hsafe.comp j.val j.property) _ hθ - · have H := period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) - (by intro _ _; simp) j (hsafe.comp j.val j.property) (fun _ => 1) hθ - simpa only [shiftedTag_center] using H - have hnon (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) : 0≤K X τ v := - subsetRankKernel_nonneg _ _ _ - calc - _ ≤ ∑v : IncreasingTuple l r, ∑X∈π.coeff.support, π.coeff X* - (if PeriodRankRegion m θ j v then 0 else K X 1 v+K X (-1) v) := by - apply Finset.sum_le_sum - intro v _ - by_cases hv : PeriodRankRegion m θ j v - · simp [hv] - · simp only [ite_eq_right hv] - have he : pureTupleKernel hl off hsafe π s j v= - ∑X∈π.coeff.support, π.coeff X*(K X 1 v-K X (-1) v) := by - norm_num [pureTupleKernel,K] - rw [he] - refine (Finset.abs_sum_le_sum_abs _ _).trans ?_ - apply Finset.sum_le_sum - intro X _ - rw [abs_mul,abs_of_nonneg (hπ X)] - apply mul_le_mul_of_nonneg_left _ (hπ X) - exact (abs_sub _ _).trans_eq (by rw [abs_of_nonneg (hnon X 1 v),abs_of_nonneg (hnon X (-1) v)]) - _ = ∑X∈π.coeff.support, π.coeff X*((∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else K X 1 v)+ - (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else K X (-1) v)) := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro X _ - rw [← Finset.mul_sum,← Finset.sum_add_distrib] - congr 1; apply Finset.sum_congr rfl - intro v _; split_ifs <;> ring - _ ≤ ∑X∈π.coeff.support, π.coeff X*(B+B) := by - apply Finset.sum_le_sum - intro X _ - exact mul_le_mul_of_nonneg_left (add_le_add (hK X 1) (hK X (-1))) (hπ X) - _ = _ := by rw [← Finset.sum_mul,hπsum]; dsimp [B]; ring - - -theorem pureRankCoefficient_tail {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : - (∑v : IncreasingTuple l r, |pureRankCoefficient hl off hsafe π s v- - clippedPureRankCoefficient hl off hsafe π s θ v|) ≤ - (Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))) := by - simp_rw [pureRankCoefficient_tuple_sum,clippedPureRankCoefficient,← Finset.sum_sub_distrib] - calc - _ ≤ ∑v : IncreasingTuple l r, ∑j : IncreasingTuple u r, - if PeriodRankRegion m θ j v then 0 else |pureTupleKernel hl off hsafe π s j v| := by - apply Finset.sum_le_sum - intro v _ - refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ - apply Finset.sum_congr rfl - intro j _ - split_ifs <;> simp - _ = ∑j : IncreasingTuple u r, ∑v : IncreasingTuple l r, - if PeriodRankRegion m θ j v then 0 else |pureTupleKernel hl off hsafe π s j v| := Finset.sum_comm - _ ≤ _ := by - calc - _ ≤ ∑j : IncreasingTuple u r, - 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := - Finset.sum_le_sum (fun j _ => pureTupleKernel_tail hu hm hr hl off hoff hsafe π hπ hπsum s j hθ) - _ = _ := by simp - -theorem initial_pure_energy {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - : - (∑v : IncreasingTuple l r, (pureRankCoefficient hl off hsafe π s v)^2) ≤ - 2*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else - purePatternBound u m r s π θ k) + - 2*((Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by - let A : IncreasingTuple l r → ℝ := pureRankCoefficient hl off hsafe π s - let C : IncreasingTuple l r → ℝ := clippedPureRankCoefficient hl off hsafe π s θ - have hn := clipped_pure_initial_norm (by omega) hr hl off hoff hsafe π hπ s hcentral hθ hhalf hmean hv - simp_rw [← clippedPureRankCoefficient_expansion] at hn - have ht := pureRankCoefficient_tail hu hm hr hl off hoff hsafe π hπ hπsum s hθ - have hE := (finite_sum_sq_le_abs_sum_sq (fun v : IncreasingTuple l r => A v-C v)).trans - (pow_le_pow_left₀ (Finset.sum_nonneg (fun v _ => abs_nonneg (A v-C v))) ht 2) - have hsum : (∑v : IncreasingTuple l r, A v^2) ≤ - 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := by - simp only [Finset.mul_sum,← Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro v _ - nlinarith [sq_nonneg (A v-2*C v)] - calc - _ ≤ 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := hsum - _ ≤ _ := by dsimp [C] at *; linarith - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def scaleCoefficient {n : ℕ} (A : (Fin n → Bool) → ℝ) (L : ℝ) (σ : Fin n → Bool) : ℝ := - A σ * ∏ i, if σ i then L else 1 - -theorem multilinear_scale {α : Type*} {n : ℕ} (A : (Fin n → Bool) → ℝ) - (Z : α → ℝ) {L : ℝ} (hL : L≠0) (x : Fin n → α) : - multilinear (scaleCoefficient A L) (fun a => Z a/L) x=multilinear A Z x := by - unfold multilinear scaleCoefficient - apply Finset.sum_congr rfl - intro σ _ - rw [mul_assoc,← Finset.prod_mul_distrib] - congr 1 - apply Finset.prod_congr rfl - intro i _ - cases σ i <;> simp - exact mul_div_cancel₀ _ hL - -theorem multilinearEnergy_scale {n : ℕ} (A : (Fin n → Bool) → ℝ) (L R : ℝ) : - multilinearEnergy (scaleCoefficient A L) R=multilinearEnergy A (R*L) := by - unfold multilinearEnergy scaleCoefficient - apply Finset.sum_congr rfl - intro σ _ - rw [mul_pow,← Finset.prod_pow,mul_assoc,← Finset.prod_mul_distrib] - congr 1 - apply Finset.prod_congr rfl - intro i _ - cases σ i <;> simp - ring - -/-- The exact norm-of-input factor in the conditional leaf expansion. -/ -theorem multilinear_moment_scaled {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) - {L : ℝ} (hL : 0 |Z a|^(2*k))≤L^(2*k)) - (n : ℕ) (A : (Fin n → Bool) → ℝ) : - (P.product n).expect (fun x => |multilinear A Z x|^(2*k)) ≤ - (multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L))^k := by - have hcenter' : P.expect (fun a => Z a/L)=0 := by - unfold FiniteLaw.expect - simp_rw [← mul_div_assoc] - rw [← Finset.sum_div] - change P.expect Z / L = 0 - rw [hcenter,zero_div] - have hmoment' : P.expect (fun a => |Z a/L|^(2*k))≤1 := by - simp_rw [abs_div,abs_of_pos hL,div_pow] - unfold FiniteLaw.expect - simp_rw [← mul_div_assoc] - rw [← Finset.sum_div] - apply (div_le_one (by positivity)).mpr hMoment - have H := multilinear_even_moment P (fun a => Z a/L) k hk hcenter' hmoment' n (scaleCoefficient A L) - simp_rw [multilinear_scale A Z hL.ne',multilinearEnergy_scale] at H - simpa only [pow_mul,sq_abs] using H - -theorem multilinear_moment_sq_scaled {α : Type*} [Fintype α] (P : FiniteLaw α) - (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) - {L : ℝ} (hL : 0 |Z a|^(2*k))≤L^(2*k)) - (n : ℕ) (A : (Fin n → Bool) → ℝ) : - (P.product n).evenMomentSq (multilinear A Z) k ≤ - multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L) := by - have H := multilinear_moment_scaled P Z k hk hcenter hL hMoment n A - have hn : 0≤(P.product n).expect (fun x => |multilinear A Z x|^(2*k)) := by - exact Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product n).nonneg x) (by positivity)) - unfold FiniteLaw.evenMomentSq - calc - _ ≤ (multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L)^k)^(1/(k:ℝ)) := - Real.rpow_le_rpow hn H (by positivity) - _ = _ := by - rw [← Real.rpow_natCast,one_div,Real.rpow_rpow_inv (multilinearEnergy_nonneg _ _) (by positivity)] - -theorem multilinearEnergy_mixture_le {Ω : Type*} [Fintype Ω] {n : ℕ} - (P : FiniteLaw Ω) (A : Ω → (Fin n → Bool) → ℝ) (R : ℝ) : - multilinearEnergy (fun σ => P.expect (fun ω => A ω σ)) R ≤ - P.expect (fun ω => multilinearEnergy (A ω) R) := by - unfold multilinearEnergy FiniteLaw.expect - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro σ _ - have H := weighted_sum_sq_le Finset.univ P.mass (fun ω => A ω σ) (fun ω => P.nonneg ω) - rw [P.total,one_mul] at H - calc - _ ≤ (∑ω, P.mass ω*A ω σ^2)*(∏i,if σ i then R^2 else 1) := - mul_le_mul_of_nonneg_right H (Finset.prod_nonneg (fun i _ => by split_ifs <;> positivity)) - _ = _ := by rw [Finset.sum_mul]; apply Finset.sum_congr rfl; intro ω _; ring - -theorem multilinearEnergy_sub_le {n : ℕ} (A B : (Fin n → Bool) → ℝ) (R : ℝ) : - multilinearEnergy (fun σ => A σ-B σ) R ≤ - 2*multilinearEnergy A R+2*multilinearEnergy B R := by - unfold multilinearEnergy - simp_rw [Finset.mul_sum,← Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro σ _ - have h := mul_le_mul_of_nonneg_right (show (A σ-B σ)^2≤2*A σ^2+2*B σ^2 by nlinarith [sq_nonneg (A σ+B σ)]) - (Finset.prod_nonneg (s := Finset.univ) (f := fun i => if σ i then R^2 else 1) (fun i _ => by split_ifs <;> positivity)) - nlinarith only [h] - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Patterns + +namespace OAI + +/-! +# InitialMoments + +Initial coefficient tails, primitive conditioning, mark-list oracle densities, pure norm estimates, and moment energies. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem signedPeriodDefects_comp {u m r : ℕ} (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (s : ℕ) (X : ℤ) (τ : ℝ) (j : IncreasingTuple u r) : + signedPeriodDefects off hsafe s X τ ∘ j.val = + shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) + (fun i => motifShift (motifIndicator s ((j.val i).val-X)) + ((prouhetSeries s).coeff ((j.val i).val-X)) τ) := by + funext i; apply Fin.ext; rfl + +def signedTupleKernel {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (j : IncreasingTuple u r) (v : IncreasingTuple l r) : ℝ := + ∑X∈π.coeff.support, π.coeff X* + (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - + subsetRankKernel hl (signedPeriodDefects off hsafe s X (-1) ∘ j.val) v.val) + +theorem signedRankCoefficient_tuple_sum {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) + (v : IncreasingTuple l r) : + signedRankCoefficient hl off hsafe π s v=∑j, signedTupleKernel hl off hsafe π s j v := by + unfold signedRankCoefficient signedTupleKernel + simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), + ← Finset.sum_sub_distrib,Finset.mul_sum] + exact Finset.sum_comm + +theorem signedTupleKernel_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) + (j : IncreasingTuple u r) (v : IncreasingTuple l r) : + signedTupleKernel hl off hsafe π s j v = ∑k : Fin r → GapDifference, + if Odd (firstDifferenceCount k) then + 2*motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0 := by + unfold signedTupleKernel + simp_rw [signedPeriodDefects_comp] + have H := mixed_signed_shift_expansion π s (fun i => (j.val i).val) + (fun a => subsetRankKernel hl + (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) + simpa only [ite_mul,zero_mul,positionalRankDifference] using H + +def clippedSignedRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : ℝ := + ∑j, if PeriodRankRegion m θ j v then signedTupleKernel hl off hsafe π s j v else 0 + +def clippedPatternCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (θ : ℝ) (k : Fin r → GapDifference) (v : IncreasingTuple l r) : ℝ := + ∑j, if PeriodRankRegion m θ j v then + motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0 + +theorem clippedSignedRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : + clippedSignedRankCoefficient hl off hsafe π s θ v = + 2*∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + clippedPatternCoefficient hl off hsafe π s θ k v else 0 := by + unfold clippedSignedRankCoefficient clippedPatternCoefficient + have he (j : IncreasingTuple u r) : + (if PeriodRankRegion m θ j v then signedTupleKernel hl off hsafe π s j v else 0) = + ∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + (if PeriodRankRegion m θ j v then + 2*motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0) else 0 := by + by_cases hv : PeriodRankRegion m θ j v + · simp only [ite_eq_left hv, signedTupleKernel_expansion] + · simp [hv] + simp_rw [he] + rw [Finset.sum_comm,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + by_cases hk : Odd (firstDifferenceCount k) + · simp only [ite_eq_left hk,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + split_ifs <;> ring + · simp [hk] + +/-- Removing coarse rank rectangles loses an explicitly exponentially + small amount in the actual coefficient, before any finite differences. -/ +theorem signedTupleKernel_tail {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2|≤3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0≤π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) (j : IncreasingTuple u r) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : + (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else + |signedTupleKernel hl off hsafe π s j v|) ≤ + 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := by + let K (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) := + subsetRankKernel hl (signedPeriodDefects off hsafe s X τ ∘ j.val) v.val + let B := ((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))) + have hK (X : ℤ) (τ : ℝ) : (∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else K X τ v)≤B := by + simp_rw [K,signedPeriodDefects_comp] + exact period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) j (hsafe.comp j.val j.property) _ hθ + have hnon (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) : 0≤K X τ v := + subsetRankKernel_nonneg _ _ _ + calc + _ ≤ ∑v : IncreasingTuple l r, ∑X∈π.coeff.support, π.coeff X* + (if PeriodRankRegion m θ j v then 0 else K X 1 v+K X (-1) v) := by + apply Finset.sum_le_sum + intro v _ + by_cases hv : PeriodRankRegion m θ j v + · simp [hv] + · simp only [ite_eq_right hv] + refine (Finset.abs_sum_le_sum_abs _ _).trans ?_ + apply Finset.sum_le_sum + intro X _ + rw [abs_mul,abs_of_nonneg (hπ X)] + apply mul_le_mul_of_nonneg_left _ (hπ X) + exact (abs_sub _ _).trans_eq (by rw [abs_of_nonneg (hnon X 1 v),abs_of_nonneg (hnon X (-1) v)]) + _ = ∑X∈π.coeff.support, π.coeff X*((∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else K X 1 v)+ + (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else K X (-1) v)) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro X _ + rw [← Finset.mul_sum,← Finset.sum_add_distrib] + congr 1; apply Finset.sum_congr rfl + intro v _; split_ifs <;> ring + _ ≤ ∑X∈π.coeff.support, π.coeff X*(B+B) := by + apply Finset.sum_le_sum + intro X _ + exact mul_le_mul_of_nonneg_left (add_le_add (hK X 1) (hK X (-1))) (hπ X) + _ = _ := by rw [← Finset.sum_mul,hπsum]; dsimp [B]; ring + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem motif_pattern_common_short_gap {r : ℕ} (k : Fin r → GapDifference) + (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : + ∃ a : Fin r, k a≠.unchanged ∧ ∃c : Fin (r+1), ∀ {u s : ℕ} (π : IntSeries) + (j : IncreasingTuple u r), + motifPatternMultiplier π s (fun h => (j.val h).val) k≠0 → + coarsePeriodGap j.val c ≤ 2*(2^s) := by + obtain ⟨a,b,hab,ha,hb⟩ := odd_pattern_pair k hk hnl + cases r with + | zero => exact Fin.elim0 a + | succ r => + have har : a.val < r := by have := b.isLt; exact lt_of_lt_of_le hab (Nat.le_of_lt_succ b.isLt) + let i : Fin r := ⟨a.val,har⟩ + have hi : i.castSucc=a := by ext; rfl + refine ⟨a,ha,i.castSucc.succ,?_⟩ + intro u s π j hj + apply motif_pattern_bounded_gap π s j k i b + · simpa only [hi] using hab + · simpa only [hi] using ha + · exact hb + · exact hj + +theorem clipped_linear_pattern_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (a : Fin r) : + (∑v, (clippedPatternCoefficient hl off hsafe π s θ (linearPattern a) v)^2) ≤ + periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * + seriesL2Sq (prouhetSeries s*π) := by + have hb := period_pattern_norm hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) (linearPattern a) + hθ hhalf hmean hv a + (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) (linearPattern a)) + (fun h => (prouhetSeries s*π).coeff h.val) + (by intro j; rw [motif_linear_multiplier]) + (prouhet_convolution_central π hcentral) + rw [linearPattern_order] at hb + apply hb.trans + apply mul_le_mul_of_nonneg_left + (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) + unfold periodDifferencePrefactor lengthDifferenceConstant periodCentralSumConstant + positivity + +theorem clipped_nonlinear_pattern_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (k : Fin r → GapDifference) (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑v, (clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ + periodDifferencePrefactor u m r (∑h, (k h).order) θ * + periodBoundedSumConstant u r (2*(2^s)) * seriesL2Sq (geomSeries (2^s)*π) := by + obtain ⟨a,ha,c,hc⟩ := motif_pattern_common_short_gap k hk hnl + have hb := period_pattern_bounded_norm hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) k + hθ hhalf hmean hv a c + (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) k) + (fun h => (geomSeries (2^s)*π).coeff h.val) + (fun j => motifPatternMultiplier_sq_le π hπ s _ k a ha) + (fun j hj => hc π j hj) (unsigned_convolution_central π hcentral) hM + apply hb.trans + apply mul_le_mul_of_nonneg_left + (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) + unfold periodDifferencePrefactor lengthDifferenceConstant periodBoundedSumConstant + positivity + +def signedPatternBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) + (k : Fin r → GapDifference) : ℝ := + if ∃a, k=linearPattern a then + periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * seriesL2Sq (prouhetSeries s*π) + else periodDifferencePrefactor u m r (∑h, (k h).order) θ * + periodBoundedSumConstant u r (2*(2^s)) * seriesL2Sq (geomSeries (2^s)*π) + +theorem sum_square_card_bound {α β : Type*} [Fintype α] [Fintype β] (f : α → β → ℝ) : + (∑ b, (∑a, f a b)^2) ≤ (Fintype.card α:ℝ)*∑a, ∑b, f a b^2 := by + calc + _ ≤ ∑b, (Fintype.card α:ℝ)*∑a, f a b^2 := by + apply Finset.sum_le_sum + intro b _ + have h := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (r := fun a => f a b) (f := fun _ => (1:ℝ)) (g := fun a => f a b^2) + (by intro _ _; norm_num) (by intro _ _; positivity) (by intro _ _; simp) + simpa using h + _ = _ := by rw [← Finset.mul_sum,Finset.sum_comm] + +theorem clipped_signed_initial_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑v : IncreasingTuple l r, (clippedSignedRankCoefficient hl off hsafe π s θ v)^2) ≤ + 4*(Fintype.card (Fin r → GapDifference):ℝ)* + ∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + signedPatternBound u m r s π θ k else 0 := by + simp_rw [clippedSignedRankCoefficient_expansion,mul_pow,show (2:ℝ)^2=4 by norm_num] + rw [← Finset.mul_sum] + calc + _ ≤ 4*((Fintype.card (Fin r → GapDifference):ℝ)*∑k : Fin r → GapDifference, ∑v : IncreasingTuple l r, + (if Odd (firstDifferenceCount k) then clippedPatternCoefficient hl off hsafe π s θ k v else 0)^2) := by + exact mul_le_mul_of_nonneg_left (sum_square_card_bound (fun (k : Fin r → GapDifference) (v : IncreasingTuple l r) => + if Odd (firstDifferenceCount k) then clippedPatternCoefficient hl off hsafe π s θ k v else 0)) (by norm_num) + _ ≤ _ := by + rw [← mul_assoc] + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro k _ + by_cases hk : Odd (firstDifferenceCount k) + · simp only [ite_eq_left hk] + unfold signedPatternBound + split_ifs with hlin + · obtain ⟨a,rfl⟩ := hlin + exact clipped_linear_pattern_norm hm hr hl off hoff hsafe π s hcentral hθ hhalf hmean hv a + · exact clipped_nonlinear_pattern_norm hm hr hl off hoff hsafe π hπ s hcentral + hθ hhalf hmean hv k hk hlin hM + · simp [hk] + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem signedRankCoefficient_tail {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : + (∑v : IncreasingTuple l r, |signedRankCoefficient hl off hsafe π s v- + clippedSignedRankCoefficient hl off hsafe π s θ v|) ≤ + (Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))) := by + simp_rw [signedRankCoefficient_tuple_sum,clippedSignedRankCoefficient,← Finset.sum_sub_distrib] + calc + _ ≤ ∑v : IncreasingTuple l r, ∑j : IncreasingTuple u r, + if PeriodRankRegion m θ j v then 0 else |signedTupleKernel hl off hsafe π s j v| := by + apply Finset.sum_le_sum + intro v _ + refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ + apply Finset.sum_congr rfl + intro j _ + split_ifs <;> simp + _ = ∑j : IncreasingTuple u r, ∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else |signedTupleKernel hl off hsafe π s j v| := Finset.sum_comm + _ ≤ _ := by + calc + _ ≤ ∑j : IncreasingTuple u r, + 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := + Finset.sum_le_sum (fun j _ => signedTupleKernel_tail hu hm hr hl off hoff hsafe π hπ hπsum s j hθ) + _ = _ := by simp + +/-- A globally discarded l1 tail is also negligible in coefficient energy. + This does not assume pointwise cancellation on the discarded ranks. -/ +theorem finite_sum_sq_le_abs_sum_sq {α : Type*} [Fintype α] (f : α → ℝ) : + (∑a, f a^2) ≤ (∑a, |f a|)^2 := by + have h := Finset.sum_sq_le_sq_sum_of_nonneg (s := Finset.univ) (f := fun a => |f a|) + (by intro a _; exact abs_nonneg _) + simpa only [sq_abs] using h + +theorem initial_signed_energy {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑v : IncreasingTuple l r, (signedRankCoefficient hl off hsafe π s v)^2) ≤ + 8*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + signedPatternBound u m r s π θ k else 0) + + 2*((Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by + let A : IncreasingTuple l r → ℝ := signedRankCoefficient hl off hsafe π s + let C : IncreasingTuple l r → ℝ := clippedSignedRankCoefficient hl off hsafe π s θ + have hn := clipped_signed_initial_norm (by omega) hr hl off hoff hsafe π hπ s hcentral hθ hhalf hmean hv hM + have ht := signedRankCoefficient_tail hu hm hr hl off hoff hsafe π hπ hπsum s hθ + have hE := (finite_sum_sq_le_abs_sum_sq (fun v : IncreasingTuple l r => A v-C v)).trans + (pow_le_pow_left₀ (Finset.sum_nonneg (fun v _ => abs_nonneg (A v-C v))) ht 2) + have hsum : (∑v : IncreasingTuple l r, A v^2) ≤ + 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro v _ + nlinarith [sq_nonneg (A v-2*C v)] + calc + _ ≤ 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := hsum + _ ≤ _ := by dsimp [C] at *; linarith + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Exact complete-trace expectation, recursively on the actual binary word. -/ +def listDeletionExpectation (q : ℝ) : List Bool → (List Bool → ℝ) → ℝ + | [], F => F [] + | b::w, F => q*listDeletionExpectation q w F + + (1-q)*listDeletionExpectation q w (fun t => F (b::t)) + +theorem traceOfMask_cons {n : ℕ} (x : Word (n+1)) (b : Bool) (a : Mask n) : + traceOfMask x (Fin.cons b a)= + if b then x 0::traceOfMask (fun i => x i.succ) a + else traceOfMask (fun i => x i.succ) a := by + rw [trace_filterMap,List.ofFn_succ,trace_filterMap] + cases b <;> simp + +theorem maskWeight_cons {n : ℕ} (q : ℝ) (b : Bool) (a : Mask n) : + maskWeight q (Fin.cons b a)=(if b then 1-q else q)*maskWeight q a := by + simp [maskWeight,Fin.prod_univ_succ] + +theorem listDeletionExpectation_ofFn {n : ℕ} (q : ℝ) (x : Word n) (F : List Bool → ℝ) : + listDeletionExpectation q (List.ofFn x) F = + ∑a : Mask n, maskWeight q a*F (traceOfMask x a) := by + induction n generalizing F with + | zero => simp [listDeletionExpectation,maskWeight,traceOfMask] + | succ n ih => + rw [List.ofFn_succ,listDeletionExpectation,ih,ih] + symm + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => Bool)).sum_comp,Fintype.sum_prod_type] + change (∑b : Bool, ∑a : Mask n, maskWeight q (Fin.cons b a)*F (traceOfMask x (Fin.cons b a)))=_ + simp_rw [maskWeight_cons,traceOfMask_cons] + simp only [Bool.false_eq_true,ite_false,ite_true,Fintype.sum_bool] + simp only [mul_assoc,← Finset.mul_sum] + ring + +theorem listDeletionExpectation_append (q : ℝ) (x y : List Bool) (F : List Bool → ℝ) : + listDeletionExpectation q (x++y) F = + listDeletionExpectation q x (fun t => listDeletionExpectation q y (fun u => F (t++u))) := by + induction x generalizing F with + | nil => simp [listDeletionExpectation] + | cons b x ih => simp only [List.cons_append,listDeletionExpectation,ih] + +/-- The primitive alphabet consists of the literal strings 01 and 1. -/ +def primitiveBlock (b : Bool) : List Bool := if b then [true] else [false,true] + +theorem primitiveBlock_expectation (q : ℝ) (b : Bool) (F : List Bool → ℝ) : + listDeletionExpectation q (primitiveBlock b) F = + ∑z : PrimitiveMark, (if b then defectPrimitiveMass q z else ordinaryPrimitiveMass q z)*F (primitiveOutput z) := by + cases b <;> simp [primitiveBlock,listDeletionExpectation,primitiveOutput, + defectPrimitiveMass,ordinaryPrimitiveMass,Fin.sum_univ_succ] + ring + +theorem primitiveBlock_erasure_expectation {q : ℝ} (hq : q∈Set.Ioo 0 1) + (b : Bool) (F : List Bool → ℝ) : + listDeletionExpectation q (primitiveBlock b) F = + primitiveErasure q * F []+(1-primitiveErasure q)* + (primitiveMarkLaw q hq b).expect (fun z => F (primitiveOutput z)) := by + rw [primitiveBlock_expectation] + simp_rw [← primitiveMark_simulation hq] + simp only [add_mul,Finset.sum_add_distrib] + simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true, + primitiveOutput,Matrix.cons_val_zero] + simp only [FiniteLaw.expect,primitiveMarkLaw,mul_assoc,← Finset.mul_sum] + +/-- Independent silent block erasures and conditionally emitted primitive marks. + An emitted empty mark is retained in the list and differs from a silent erasure. -/ +def silentMarkExpectation (q : ℝ) : List Bool → (List PrimitiveMark → ℝ) → ℝ + | [], F => F [] + | b::bs, F => primitiveErasure q*silentMarkExpectation q bs F + + (1-primitiveErasure q)*∑z : PrimitiveMark, primitiveMarkMass q b z* + silentMarkExpectation q bs (fun ys => F (z::ys)) + +def joinPrimitiveMarks (ys : List PrimitiveMark) : List Bool := (ys.map primitiveOutput).flatten + +theorem silentMarkExpectation_linear (q : ℝ) (bs : List Bool) + (F G : List PrimitiveMark → ℝ) (a b : ℝ) : + silentMarkExpectation q bs (fun ys => a*F ys+b*G ys)= + a*silentMarkExpectation q bs F+b*silentMarkExpectation q bs G := by + induction bs generalizing F G with + | nil => rfl + | cons x xs ih => + simp only [silentMarkExpectation,ih,mul_add,Finset.sum_add_distrib] + have hf : (∑ z : PrimitiveMark, primitiveMarkMass q x z * + (a*silentMarkExpectation q xs (fun ys => F (z::ys)))) = + a*∑ z : PrimitiveMark, primitiveMarkMass q x z * silentMarkExpectation q xs (fun ys => F (z::ys)) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro z _; ring + have hg : (∑ z : PrimitiveMark, primitiveMarkMass q x z * + (b*silentMarkExpectation q xs (fun ys => G (z::ys)))) = + b*∑ z : PrimitiveMark, primitiveMarkMass q x z * silentMarkExpectation q xs (fun ys => G (z::ys)) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro z _; ring + rw [hf,hg]; ring + +theorem silentMarkExpectation_sum {ι : Type*} [Fintype ι] (q : ℝ) (bs : List Bool) + (F : ι → List PrimitiveMark → ℝ) : + silentMarkExpectation q bs (fun ys => ∑i, F i ys)=∑i, silentMarkExpectation q bs (F i) := by + induction bs generalizing F with + | nil => rfl + | cons x xs ih => + simp only [silentMarkExpectation,ih,Finset.mul_sum,Finset.sum_add_distrib] + congr 1 + rw [Finset.sum_comm] + +theorem silentMarkExpectation_scale (q : ℝ) (bs : List Bool) + (F : List PrimitiveMark → ℝ) (a : ℝ) : + silentMarkExpectation q bs (fun ys => a*F ys)=a*silentMarkExpectation q bs F := by + have h := silentMarkExpectation_linear q bs F F a 0 + simpa using h + +/-- The common deterministic mark-joining simulator is exact for arbitrary + concatenations of primitive blocks; block boundaries are not reported. -/ +theorem primitive_run_simulation {q : ℝ} (hq : q∈Set.Ioo 0 1) + (bs : List Bool) (F : List Bool → ℝ) : + listDeletionExpectation q ((bs.map primitiveBlock).flatten) F = + silentMarkExpectation q bs (fun ys => F (joinPrimitiveMarks ys)) := by + induction bs generalizing F with + | nil => rfl + | cons b bs ih => + simp only [List.map_cons,List.flatten_cons] + rw [listDeletionExpectation_append,primitiveBlock_erasure_expectation hq] + simp only [List.nil_append,ih,FiniteLaw.expect,primitiveMarkLaw] + simp only [silentMarkExpectation] + rfl + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Every emitted mark is counted, including the empty primitive output. -/ +def emittedMarkExpectation (q : ℝ) : List Bool → (List PrimitiveMark → ℝ) → ℝ + | [], F => F [] + | b::bs, F => ∑z : PrimitiveMark, primitiveMarkMass q b z* + emittedMarkExpectation q bs (fun ys => F (z::ys)) + +theorem emittedMarkExpectation_ofFn {n : ℕ} (q : ℝ) (θ : Fin n → Bool) + (F : List PrimitiveMark → ℝ) : + emittedMarkExpectation q (List.ofFn θ) F= + ∑x : Fin n → PrimitiveMark, (∏i, primitiveMarkMass q (θ i) (x i))*F (List.ofFn x) := by + induction n generalizing F with + | zero => simp [emittedMarkExpectation] + | succ n ih => + rw [List.ofFn_succ,emittedMarkExpectation] + simp_rw [ih,Finset.mul_sum] + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => PrimitiveMark)).sum_comp,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro z _ + apply Finset.sum_congr rfl + intro x _ + simp [Fin.consEquiv,Fin.prod_univ_succ,List.ofFn_succ,mul_assoc] + +/-- Conditioning the independent erasures on the return count chooses + a uniformly random subset of the original block slots. -/ +theorem silentMarkExpectation_mask_mixture {n : ℕ} (q : ℝ) (θ : Fin n → Bool) + (F : List PrimitiveMark → ℝ) : + silentMarkExpectation q (List.ofFn θ) F= + ∑a : Mask n, maskWeight (primitiveErasure q) a* + emittedMarkExpectation q (traceOfMask θ a) F := by + induction n generalizing F with + | zero => simp [silentMarkExpectation,emittedMarkExpectation,maskWeight,traceOfMask] + | succ n ih => + rw [List.ofFn_succ,silentMarkExpectation] + simp_rw [ih] + symm + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => Bool)).sum_comp,Fintype.sum_prod_type] + change (∑b : Bool, ∑a : Mask n, maskWeight (primitiveErasure q) (Fin.cons b a)* + emittedMarkExpectation q (traceOfMask θ (Fin.cons b a)) F)=_ + simp_rw [maskWeight_cons,traceOfMask_cons] + simp only [Fintype.sum_bool,ite_true,Bool.false_eq_true,ite_false,emittedMarkExpectation] + simp_rw [mul_assoc,Finset.mul_sum] + rw [Finset.sum_comm,add_comm] + congr 1 + apply Finset.sum_congr rfl + intro z _ + apply Finset.sum_congr rfl + intro a _ + ring + +def maskSubset {n : ℕ} (a : Mask n) : Finset (Fin n) := Finset.univ.filter fun i => a i + +def maskSubsetEquiv (n : ℕ) : Mask n ≃ Finset (Fin n) where + toFun := maskSubset + invFun S i := decide (i∈S) + left_inv a := by funext i; simp [maskSubset] + right_inv S := by ext i; simp [maskSubset] + +theorem maskWeight_card {n : ℕ} (q : ℝ) (a : Mask n) : + maskWeight q a = (1-q)^(maskSubset a).card*q^(n-(maskSubset a).card) := by + unfold maskWeight maskSubset + rw [Finset.prod_ite] + simp only [Finset.prod_const] + congr 1 + have h := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset (Fin n))) (p := fun i => a i) + rw [Finset.card_univ,Fintype.card_fin] at h + rw [show (Finset.univ.filter fun i : Fin n => ¬a i=true).card= + n-(Finset.univ.filter fun i : Fin n => a i=true).card by omega] + +theorem slotAtRank_ofFn {n l : ℕ} (S : FixedSubset (Fin n) l) : + List.ofFn (slotAtRank S)=S.val.sort := by + apply List.ext_getElem + · simp [S.property] + · intro i hi hj + simp only [List.getElem_ofFn] + rfl + +theorem filtered_finRange_eq_sort {n : ℕ} (S : Finset (Fin n)) : + ((List.finRange n).filter fun i => decide (i∈S))=S.sort := by + apply ((List.sortedLT_finRange n).pairwise.filter _).eq_of_mem_iff S.sortedLT_sort.pairwise + intro a + simp + +theorem selected_types_ofFn {n l : ℕ} (θ : Fin n → Bool) (S : FixedSubset (Fin n) l) : + traceOfMask θ (fun i => decide (i∈S.val))=List.ofFn (fun v => θ (slotAtRank S v)) := by + rw [traceOfMask,filtered_finRange_eq_sort,← slotAtRank_ofFn S,List.map_ofFn] + rfl + +theorem silentMarkExpectation_subset_mixture {n : ℕ} (q : ℝ) (θ : Fin n → Bool) + (F : List PrimitiveMark → ℝ) : + silentMarkExpectation q (List.ofFn θ) F= + ∑S : Finset (Fin n), subsetWeight (1-primitiveErasure q) S* + emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S))) F := by + rw [silentMarkExpectation_mask_mixture,← (maskSubsetEquiv n).symm.sum_comp] + apply Finset.sum_congr rfl + intro S _ + rw [maskWeight_card] + change (1-primitiveErasure q)^(maskSubsetEquiv n ((maskSubsetEquiv n).symm S)).card * + (primitiveErasure q)^(n-(maskSubsetEquiv n ((maskSubsetEquiv n).symm S)).card)* + emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S))) F=_ + rw [Equiv.apply_symm_apply] + simp [subsetWeight] + +def cardinalSubsetEquiv (n : ℕ) : Finset (Fin n) ≃ Σl : Fin (n+1), FixedSubset (Fin n) l.val where + toFun S := ⟨⟨S.card, by have := Finset.card_le_univ S; simpa using Nat.lt_succ_of_le this⟩,⟨S,rfl⟩⟩ + invFun x := x.2.val + left_inv _ := rfl + right_inv x := by + rcases x with ⟨⟨l,hl⟩,⟨S,hS⟩⟩ + dsimp + change S.card=l at hS + subst l + rfl + +theorem subsetWeight_count_factor {n l : ℕ} (hl : l ≤ n) (p : ℝ) (S : FixedSubset (Fin n) l) : + subsetWeight p S.val=binomialMass n p l*(uniformSubsetLaw l (by simpa using hl)).mass S := by + have hc : (n.choose l:ℝ)≠0 := by exact_mod_cast (Nat.choose_pos hl).ne' + simp only [subsetWeight,binomialMass,uniformSubsetLaw,S.property,Fintype.card_fin] + field_simp + +/-- The literal conditional-list oracle used by the rank coefficients. -/ +def conditionalPrimitiveLaw {n l : ℕ} (hl : l ≤ n) (q : ℝ) (hq : q∈Set.Ioo 0 1) + (θ : Fin n → Bool) : FiniteLaw (Fin l → PrimitiveMark) := + (uniformSubsetLaw l (by simpa using hl)).mixture fun S => + FiniteLaw.coordinateProduct (fun v => primitiveMarkLaw q hq (θ (slotAtRank S v))) + +theorem silentMarkExpectation_count_mixture {n : ℕ} (q : ℝ) (hq : q∈Set.Ioo 0 1) + (θ : Fin n → Bool) (F : List PrimitiveMark → ℝ) : + silentMarkExpectation q (List.ofFn θ) F= + ∑l : Fin (n+1), binomialMass n (1-primitiveErasure q) l.val* + (conditionalPrimitiveLaw (Nat.le_of_lt_succ l.isLt) q hq θ).expect (fun x => F (List.ofFn x)) := by + rw [silentMarkExpectation_subset_mixture,← (cardinalSubsetEquiv n).symm.sum_comp,Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro l _ + change (∑S : FixedSubset (Fin n) l.val, subsetWeight (1-primitiveErasure q) S.val* + emittedMarkExpectation q (traceOfMask θ (fun i => decide (i∈S.val))) F)=_ + calc + _ = ∑S : FixedSubset (Fin n) l.val, binomialMass n (1-primitiveErasure q) l.val* + (uniformSubsetLaw l.val (by simpa using Nat.le_of_lt_succ l.isLt)).mass S* + (∑x : Fin l.val → PrimitiveMark, (∏v, primitiveMarkMass q (θ (slotAtRank S v)) (x v))*F (List.ofFn x)) := by + apply Finset.sum_congr rfl + intro S _ + rw [subsetWeight_count_factor (Nat.le_of_lt_succ l.isLt),selected_types_ofFn θ S,emittedMarkExpectation_ofFn] + _ = _ := by + unfold conditionalPrimitiveLaw FiniteLaw.expect FiniteLaw.mixture FiniteLaw.coordinateProduct primitiveMarkLaw + simp_rw [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro S _ + ring + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Density of the actual uniform-subset primitive oracle, over the ordinary + mark product law. This is exactly the channel defined by silent erasures. -/ +theorem conditionalPrimitiveLaw_density {n l : ℕ} (hl : l ≤ n) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (θ : Fin n → Bool) (x : Fin l → PrimitiveMark) : + (conditionalPrimitiveLaw hl q hq θ).mass x = + ((primitiveMarkLaw q hq false).product l).mass x * + averagedDensity (uniformSubsetLaw l (by simpa using hl)) + (fun S v => θ (slotAtRank S v)) (primitiveScore q) x := by + have he : (fun S : FixedSubset (Fin n) l => + FiniteLaw.coordinateProduct (fun v => primitiveMarkLaw q hq (θ (slotAtRank S v)))) = + (fun S : FixedSubset (Fin n) l => + FiniteLaw.coordinateProduct (fun v => if θ (slotAtRank S v) then + primitiveMarkLaw q hq true else primitiveMarkLaw q hq false)) := by + funext S + congr 1 + funext v + cases θ (slotAtRank S v) <;> rfl + unfold conditionalPrimitiveLaw + rw [he] + exact leaf_oracle_density (primitiveMarkLaw q hq false) (primitiveMarkLaw q hq true) + (primitiveScore q) (primitive_score_identity hq) + (uniformSubsetLaw l (by simpa using hl)) (fun S v => θ (slotAtRank S v)) x + +def defectTypes {n u : ℕ} (d : Fin u → Fin n) (i : Fin n) : Bool := decide (i∈Set.range d) + +theorem defectTypes_atRank {n l u : ℕ} (d : Fin u → Fin n) (S : FixedSubset (Fin n) l) : + (fun v => defectTypes d (slotAtRank S v))=defectAtRank (Finset.univ.image d) S := by + funext v + simp [defectTypes,defectAtRank,Set.mem_range] + +theorem conditionalDefectLaw_density {n l u : ℕ} (hl : l ≤ n) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (d : Fin u → Fin n) (x : Fin l → PrimitiveMark) : + (conditionalPrimitiveLaw hl q hq (defectTypes d)).mass x = + ((primitiveMarkLaw q hq false).product l).mass x * + multilinear (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image d))) (primitiveScore q) x := by + rw [conditionalPrimitiveLaw_density,show (fun S v => defectTypes d (slotAtRank S v))= + defectAtRank (Finset.univ.image d) by funext S; exact defectTypes_atRank d S, + averagedDensity_expansion] + +/-- The finite-support law of the hidden motif anchor, not an additional + distributional assumption or a changed channel parameter. -/ +def seriesProbabilityLaw (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) + (hπsum : ∑X∈π.coeff.support, π.coeff X=1) : FiniteLaw ↥π.coeff.support where + mass X := π.coeff X.val + nonneg X := hπ X.val + total := by simpa only [Finset.univ_eq_attach,Finset.sum_attach] using hπsum + +def mixedMotifCoefficient {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (τ : ℝ) (σ : Fin l → Bool) : ℝ := + ∑X∈π.coeff.support, π.coeff X* + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X τ))) σ + +def conditionalMotifLaw {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) + (hπsum : ∑X∈π.coeff.support, π.coeff X=1) (s : ℕ) (τ : ℝ) : + FiniteLaw (Fin l → PrimitiveMark) := + (seriesProbabilityLaw π hπ hπsum).mixture fun X => + conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X.val τ)) + +theorem conditionalMotifLaw_density {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) + (hπsum : ∑X∈π.coeff.support, π.coeff X=1) (s : ℕ) (τ : ℝ) (x : Fin l → PrimitiveMark) : + (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).mass x= + ((primitiveMarkLaw q hq false).product l).mass x * + multilinear (mixedMotifCoefficient hl off hsafe π s τ) (primitiveScore q) x := by + unfold conditionalMotifLaw FiniteLaw.mixture seriesProbabilityLaw + simp_rw [conditionalDefectLaw_density] + let F : ℤ → ℝ := fun X => π.coeff X * + (((primitiveMarkLaw q hq false).product l).mass x * + multilinear (averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X τ)))) + (primitiveScore q) x) + change (∑ X : ↥π.coeff.support, F X.val) = _ + rw [Finset.sum_coe_sort] + dsimp only [F] + unfold mixedMotifCoefficient multilinear + simp_rw [Finset.mul_sum,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro σ _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro X _ + ring + +theorem mixedMotifCoefficient_rank_difference {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : + mixedMotifCoefficient hl off hsafe π s 1 (rankMask v)- + mixedMotifCoefficient hl off hsafe π s (-1) (rankMask v)= + signedRankCoefficient hl off hsafe π s v := by + unfold mixedMotifCoefficient signedRankCoefficient + simp_rw [averaged_rank_coefficient hl _ v] + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro X _ + ring + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def unchangedPattern (r : ℕ) : Fin r → GapDifference := fun _ => .unchanged + +theorem unchanged_positional_value {r : ℕ} (W : (Fin r → Fin 3) → ℝ) : + (∑ a : Fin r → Fin 3, (∏ h, positionalWeight (unchangedPattern r h) (a h))*W a)= + W (fun _ => 1) := by + simp only [unchangedPattern,positionalWeight] + simp_rw [product_function_delta] + simp + +/-- Comparing a signed displaced motif with the literal centered pure run + retains every nonconstant positional pattern, not just odd ones. -/ +theorem motif_pure_shift_expansion {r : ℕ} (χ β : Fin r → ℝ) + (hβ : ∀h, IsMotifValue (χ h) (β h)) (W : (Fin r → Fin 3) → ℝ) : + W (fun h => motifShift (χ h) (β h) 1)-W (fun _ => 1)= + ∑ k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + (∏h, motifDifferenceWeight (χ h) (β h) 1 (k h))* + (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) := by + rw [motif_shift_expansion χ β 1 hβ (Or.inl rfl) W] + have he : W (fun _ => 1)=∑k : Fin r → GapDifference, + if k=unchangedPattern r then + (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) else 0 := by + simp [unchanged_positional_value] + rw [he,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + by_cases hk : k=unchangedPattern r + · subst k + simp [unchangedPattern,motifDifferenceWeight] + · simp [hk] + +theorem mixed_pure_shift_expansion {r : ℕ} (π : IntSeries) (s : ℕ) + (j : Fin r → ℤ) (W : (Fin r → Fin 3) → ℝ) : + (∑X∈π.coeff.support, π.coeff X * + (W (fun h => motifShift (motifIndicator s (j h-X)) ((prouhetSeries s).coeff (j h-X)) 1)- + W (fun _ => 1)))= + ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + motifPatternMultiplier π s j k * + (∑a : Fin r → Fin 3, (∏h, positionalWeight (k h) (a h))*W a) := by + simp_rw [motif_pure_shift_expansion _ _ (fun h => prouhet_motif_value s (j h-_)) W, + Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + by_cases hk : k=unchangedPattern r + · simp [hk] + · simp only [ite_eq_right hk,motifPatternMultiplier,Finset.sum_mul,mul_assoc] + simp_rw [Finset.mul_sum] + exact Finset.sum_comm + +theorem pattern_order_zero {r : ℕ} (k : Fin r → GapDifference) + (hk : (∑h, (k h).order)=0) : k=unchangedPattern r := by + funext h + have hh := Finset.single_le_sum (fun i (_ : i∈(Finset.univ : Finset (Fin r))) => + Nat.zero_le (k i).order) (Finset.mem_univ h) + rw [hk] at hh + have hz : (k h).order=0 := by omega + cases he : k h <;> simp_all [GapDifference.order,unchangedPattern] + +theorem nonconstant_pattern_linear_or_order_two {r : ℕ} (k : Fin r → GapDifference) + (hk : k≠unchangedPattern r) : (∃h, k=linearPattern h) ∨ 2≤∑h,(k h).order := by + by_cases hlin : ∃h, k=linearPattern h + · exact Or.inl hlin + right + by_contra hsmall + have horder : (∑h,(k h).order)=1 := by + have hn : (∑h,(k h).order)≠0 := fun he => hk (pattern_order_zero k he) + omega + have hc := difference_order_eq_counts k + have hfirst : firstDifferenceCount k=1 := by omega + have hsecond : secondDifferenceCount k=0 := by omega + exact hlin (first_second_counts_linear k hfirst hsecond) + + +/-- A nonconstant motif pattern always has an actual involved position. -/ +theorem nonconstant_pattern_position {r : ℕ} (k : Fin r → GapDifference) + (hk : k≠unchangedPattern r) : ∃a, k a≠.unchanged := by + by_contra h + push Not at h + exact hk (funext h) + +theorem clipped_pure_nonlinear_pattern_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (k : Fin r → GapDifference) (hk : k≠unchangedPattern r) : + (∑v : IncreasingTuple l r, (clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ + periodDifferencePrefactor u m r (∑h, (k h).order) θ * + periodCentralSumConstant u r * seriesL2Sq (geomSeries (2^s)*π) := by + obtain ⟨a,ha⟩ := nonconstant_pattern_position k hk + have hb := period_pattern_norm hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) (fun j => hsafe.comp j.val j.property) k + hθ hhalf hmean hv a + (fun j => motifPatternMultiplier π s (fun i => (j.val i).val) k) + (fun h => (geomSeries (2^s)*π).coeff h.val) + (fun j => motifPatternMultiplier_sq_le π hπ s _ k a ha) + (unsigned_convolution_central π hcentral) + apply hb.trans + apply mul_le_mul_of_nonneg_left + (seriesL2Sq_partial _ (fun h : Fin u => (h.val:ℤ)) (by intro a b h; apply Fin.ext; change (a.val:ℤ)=b.val at h; exact_mod_cast h)) + unfold periodDifferencePrefactor lengthDifferenceConstant periodCentralSumConstant + positivity + +def purePatternBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) + (k : Fin r → GapDifference) : ℝ := + if ∃a, k=linearPattern a then + periodDifferencePrefactor u m r 1 θ * periodCentralSumConstant u r * seriesL2Sq (prouhetSeries s*π) + else periodDifferencePrefactor u m r (∑h, (k h).order) θ * + periodCentralSumConstant u r * seriesL2Sq (geomSeries (2^s)*π) + +/-- Complete clipped energy, comparing the signed motif to a pure run. -/ +theorem clipped_pure_initial_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : + (∑v : IncreasingTuple l r, (∑k : Fin r → GapDifference, + if k=unchangedPattern r then 0 else clippedPatternCoefficient hl off hsafe π s θ k v)^2) ≤ + (Fintype.card (Fin r → GapDifference):ℝ)* + ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + purePatternBound u m r s π θ k := by + apply (sum_square_card_bound (fun (k : Fin r → GapDifference) (v : IncreasingTuple l r) => + if k=unchangedPattern r then 0 else clippedPatternCoefficient hl off hsafe π s θ k v)).trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro k _ + by_cases hk : k=unchangedPattern r + · simp [hk] + · simp only [ite_eq_right hk] + unfold purePatternBound + split_ifs with hlin + · obtain ⟨a,rfl⟩ := hlin + exact clipped_linear_pattern_norm hm hr hl off hoff hsafe π s hcentral hθ hhalf hmean hv a + · exact clipped_pure_nonlinear_pattern_norm hm hr hl off hoff hsafe π hπ s hcentral + hθ hhalf hmean hv k hk + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem shiftedTag_center {n r : ℕ} (p : Fin r → Fin n) (hp : SafeTaggedTuple p) : + shiftedTag p hp (fun _ => 1)=p := by + funext i + apply Fin.ext + simp [shiftedTag] + +def pureRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : ℝ := + ∑X∈π.coeff.support, π.coeff X * + (rankDefectCoefficient hl (signedPeriodDefects off hsafe s X 1) v - + rankDefectCoefficient hl (periodSlot (fun _ => off)) v) + +def pureTupleKernel {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (j : IncreasingTuple u r) (v : IncreasingTuple l r) : ℝ := + ∑X∈π.coeff.support, π.coeff X * + (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - + subsetRankKernel hl (periodSlot (fun _ => off) ∘ j.val) v.val) + +theorem pureRankCoefficient_tuple_sum {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) + (v : IncreasingTuple l r) : + pureRankCoefficient hl off hsafe π s v=∑j, pureTupleKernel hl off hsafe π s j v := by + unfold pureRankCoefficient pureTupleKernel + simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), + rankDefectCoefficient_eq _ _ (periodSlot_strictMono _), + ← Finset.sum_sub_distrib,Finset.mul_sum] + exact Finset.sum_comm + +theorem pureTupleKernel_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) (π : IntSeries) (s : ℕ) + (j : IncreasingTuple u r) (v : IncreasingTuple l r) : + pureTupleKernel hl off hsafe π s j v = ∑k : Fin r → GapDifference, + if k=unchangedPattern r then 0 else + motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v := by + unfold pureTupleKernel + simp_rw [signedPeriodDefects_comp] + have H := mixed_pure_shift_expansion π s (fun i => (j.val i).val) + (fun a => subsetRankKernel hl + (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) + simpa only [shiftedTag_center,positionalRankDifference] using H + +def clippedPureRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : ℝ := + ∑j, if PeriodRankRegion m θ j v then pureTupleKernel hl off hsafe π s j v else 0 + +theorem clippedPureRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (θ : ℝ) (v : IncreasingTuple l r) : + clippedPureRankCoefficient hl off hsafe π s θ v = + ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + clippedPatternCoefficient hl off hsafe π s θ k v := by + unfold clippedPureRankCoefficient clippedPatternCoefficient + simp_rw [pureTupleKernel_expansion] + have he (j : IncreasingTuple u r) : + (if PeriodRankRegion m θ j v then ∑k : Fin r → GapDifference, + if k=unchangedPattern r then 0 else + motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0)= + ∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + (if PeriodRankRegion m θ j v then + motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0) := by + by_cases hv : PeriodRankRegion m θ j v <;> simp [hv] + simp_rw [he] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + by_cases hk : k=unchangedPattern r <;> simp [hk] + +theorem pureTupleKernel_tail {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2|≤3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0≤π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) (j : IncreasingTuple u r) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : + (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else + |pureTupleKernel hl off hsafe π s j v|) ≤ + 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := by + let K (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) := + subsetRankKernel hl (if τ=1 then signedPeriodDefects off hsafe s X 1 ∘ j.val + else periodSlot (fun _ => off) ∘ j.val) v.val + let B := ((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))) + have hK (X : ℤ) (τ : ℝ) : (∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else K X τ v)≤B := by + dsimp [K] + split_ifs + · rw [signedPeriodDefects_comp] + exact period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) j (hsafe.comp j.val j.property) _ hθ + · have H := period_shifted_outside_region hu hm hr hl (fun _ => off) (fun _ => hoff) + (by intro _ _; simp) j (hsafe.comp j.val j.property) (fun _ => 1) hθ + simpa only [shiftedTag_center] using H + have hnon (X : ℤ) (τ : ℝ) (v : IncreasingTuple l r) : 0≤K X τ v := + subsetRankKernel_nonneg _ _ _ + calc + _ ≤ ∑v : IncreasingTuple l r, ∑X∈π.coeff.support, π.coeff X* + (if PeriodRankRegion m θ j v then 0 else K X 1 v+K X (-1) v) := by + apply Finset.sum_le_sum + intro v _ + by_cases hv : PeriodRankRegion m θ j v + · simp [hv] + · simp only [ite_eq_right hv] + have he : pureTupleKernel hl off hsafe π s j v= + ∑X∈π.coeff.support, π.coeff X*(K X 1 v-K X (-1) v) := by + norm_num [pureTupleKernel,K] + rw [he] + refine (Finset.abs_sum_le_sum_abs _ _).trans ?_ + apply Finset.sum_le_sum + intro X _ + rw [abs_mul,abs_of_nonneg (hπ X)] + apply mul_le_mul_of_nonneg_left _ (hπ X) + exact (abs_sub _ _).trans_eq (by rw [abs_of_nonneg (hnon X 1 v),abs_of_nonneg (hnon X (-1) v)]) + _ = ∑X∈π.coeff.support, π.coeff X*((∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else K X 1 v)+ + (∑v : IncreasingTuple l r, if PeriodRankRegion m θ j v then 0 else K X (-1) v)) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro X _ + rw [← Finset.mul_sum,← Finset.sum_add_distrib] + congr 1; apply Finset.sum_congr rfl + intro v _; split_ifs <;> ring + _ ≤ ∑X∈π.coeff.support, π.coeff X*(B+B) := by + apply Finset.sum_le_sum + intro X _ + exact mul_le_mul_of_nonneg_left (add_le_add (hK X 1) (hK X (-1))) (hπ X) + _ = _ := by rw [← Finset.sum_mul,hπsum]; dsimp [B]; ring + + +theorem pureRankCoefficient_tail {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) : + (∑v : IncreasingTuple l r, |pureRankCoefficient hl off hsafe π s v- + clippedPureRankCoefficient hl off hsafe π s θ v|) ≤ + (Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))) := by + simp_rw [pureRankCoefficient_tuple_sum,clippedPureRankCoefficient,← Finset.sum_sub_distrib] + calc + _ ≤ ∑v : IncreasingTuple l r, ∑j : IncreasingTuple u r, + if PeriodRankRegion m θ j v then 0 else |pureTupleKernel hl off hsafe π s j v| := by + apply Finset.sum_le_sum + intro v _ + refine (Finset.abs_sum_le_sum_abs _ _).trans_eq ?_ + apply Finset.sum_congr rfl + intro j _ + split_ifs <;> simp + _ = ∑j : IncreasingTuple u r, ∑v : IncreasingTuple l r, + if PeriodRankRegion m θ j v then 0 else |pureTupleKernel hl off hsafe π s j v| := Finset.sum_comm + _ ≤ _ := by + calc + _ ≤ ∑j : IncreasingTuple u r, + 2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u)))) := + Finset.sum_le_sum (fun j _ => pureTupleKernel_tail hu hm hr hl off hoff hsafe π hπ hπsum s j hθ) + _ = _ := by simp + +theorem initial_pure_energy {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support, π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + : + (∑v : IncreasingTuple l r, (pureRankCoefficient hl off hsafe π s v)^2) ≤ + 2*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else + purePatternBound u m r s π θ k) + + 2*((Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by + let A : IncreasingTuple l r → ℝ := pureRankCoefficient hl off hsafe π s + let C : IncreasingTuple l r → ℝ := clippedPureRankCoefficient hl off hsafe π s θ + have hn := clipped_pure_initial_norm (by omega) hr hl off hoff hsafe π hπ s hcentral hθ hhalf hmean hv + simp_rw [← clippedPureRankCoefficient_expansion] at hn + have ht := pureRankCoefficient_tail hu hm hr hl off hoff hsafe π hπ hπsum s hθ + have hE := (finite_sum_sq_le_abs_sum_sq (fun v : IncreasingTuple l r => A v-C v)).trans + (pow_le_pow_left₀ (Finset.sum_nonneg (fun v _ => abs_nonneg (A v-C v))) ht 2) + have hsum : (∑v : IncreasingTuple l r, A v^2) ≤ + 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro v _ + nlinarith [sq_nonneg (A v-2*C v)] + calc + _ ≤ 2*(∑v : IncreasingTuple l r, C v^2)+2*(∑v : IncreasingTuple l r, (A v-C v)^2) := hsum + _ ≤ _ := by dsimp [C] at *; linarith + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def scaleCoefficient {n : ℕ} (A : (Fin n → Bool) → ℝ) (L : ℝ) (σ : Fin n → Bool) : ℝ := + A σ * ∏ i, if σ i then L else 1 + +theorem multilinear_scale {α : Type*} {n : ℕ} (A : (Fin n → Bool) → ℝ) + (Z : α → ℝ) {L : ℝ} (hL : L≠0) (x : Fin n → α) : + multilinear (scaleCoefficient A L) (fun a => Z a/L) x=multilinear A Z x := by + unfold multilinear scaleCoefficient + apply Finset.sum_congr rfl + intro σ _ + rw [mul_assoc,← Finset.prod_mul_distrib] + congr 1 + apply Finset.prod_congr rfl + intro i _ + cases σ i <;> simp + exact mul_div_cancel₀ _ hL + +theorem multilinearEnergy_scale {n : ℕ} (A : (Fin n → Bool) → ℝ) (L R : ℝ) : + multilinearEnergy (scaleCoefficient A L) R=multilinearEnergy A (R*L) := by + unfold multilinearEnergy scaleCoefficient + apply Finset.sum_congr rfl + intro σ _ + rw [mul_pow,← Finset.prod_pow,mul_assoc,← Finset.prod_mul_distrib] + congr 1 + apply Finset.prod_congr rfl + intro i _ + cases σ i <;> simp + ring + +/-- The exact norm-of-input factor in the conditional leaf expansion. -/ +theorem multilinear_moment_scaled {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) + {L : ℝ} (hL : 0 |Z a|^(2*k))≤L^(2*k)) + (n : ℕ) (A : (Fin n → Bool) → ℝ) : + (P.product n).expect (fun x => |multilinear A Z x|^(2*k)) ≤ + (multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L))^k := by + have hcenter' : P.expect (fun a => Z a/L)=0 := by + unfold FiniteLaw.expect + simp_rw [← mul_div_assoc] + rw [← Finset.sum_div] + change P.expect Z / L = 0 + rw [hcenter,zero_div] + have hmoment' : P.expect (fun a => |Z a/L|^(2*k))≤1 := by + simp_rw [abs_div,abs_of_pos hL,div_pow] + unfold FiniteLaw.expect + simp_rw [← mul_div_assoc] + rw [← Finset.sum_div] + apply (div_le_one (by positivity)).mpr hMoment + have H := multilinear_even_moment P (fun a => Z a/L) k hk hcenter' hmoment' n (scaleCoefficient A L) + simp_rw [multilinear_scale A Z hL.ne',multilinearEnergy_scale] at H + simpa only [pow_mul,sq_abs] using H + +theorem multilinear_moment_sq_scaled {α : Type*} [Fintype α] (P : FiniteLaw α) + (Z : α → ℝ) (k : ℕ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) + {L : ℝ} (hL : 0 |Z a|^(2*k))≤L^(2*k)) + (n : ℕ) (A : (Fin n → Bool) → ℝ) : + (P.product n).evenMomentSq (multilinear A Z) k ≤ + multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L) := by + have H := multilinear_moment_scaled P Z k hk hcenter hL hMoment n A + have hn : 0≤(P.product n).expect (fun x => |multilinear A Z x|^(2*k)) := by + exact Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product n).nonneg x) (by positivity)) + unfold FiniteLaw.evenMomentSq + calc + _ ≤ (multilinearEnergy A ((6*(2*k:ℕ):ℝ)*L)^k)^(1/(k:ℝ)) := + Real.rpow_le_rpow hn H (by positivity) + _ = _ := by + rw [← Real.rpow_natCast,one_div,Real.rpow_rpow_inv (multilinearEnergy_nonneg _ _) (by positivity)] + +theorem multilinearEnergy_mixture_le {Ω : Type*} [Fintype Ω] {n : ℕ} + (P : FiniteLaw Ω) (A : Ω → (Fin n → Bool) → ℝ) (R : ℝ) : + multilinearEnergy (fun σ => P.expect (fun ω => A ω σ)) R ≤ + P.expect (fun ω => multilinearEnergy (A ω) R) := by + unfold multilinearEnergy FiniteLaw.expect + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro σ _ + have H := weighted_sum_sq_le Finset.univ P.mass (fun ω => A ω σ) (fun ω => P.nonneg ω) + rw [P.total,one_mul] at H + calc + _ ≤ (∑ω, P.mass ω*A ω σ^2)*(∏i,if σ i then R^2 else 1) := + mul_le_mul_of_nonneg_right H (Finset.prod_nonneg (fun i _ => by split_ifs <;> positivity)) + _ = _ := by rw [Finset.sum_mul]; apply Finset.sum_congr rfl; intro ω _; ring + +theorem multilinearEnergy_sub_le {n : ℕ} (A B : (Fin n → Bool) → ℝ) (R : ℝ) : + multilinearEnergy (fun σ => A σ-B σ) R ≤ + 2*multilinearEnergy A R+2*multilinearEnergy B R := by + unfold multilinearEnergy + simp_rw [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro σ _ + have h := mul_le_mul_of_nonneg_right (show (A σ-B σ)^2≤2*A σ^2+2*B σ^2 by nlinarith [sq_nonneg (A σ+B σ)]) + (Finset.prod_nonneg (s := Finset.univ) (f := fun i => if σ i then R^2 else 1) (fun i _ => by split_ifs <;> positivity)) + nlinarith only [h] + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/InitialOracle.lean b/lean/OAI/Probability/TraceReconstruction/InitialOracle.lean index f8309fb24a51fb465e6be69109f0a5e681eeb834..53ce412c20a6de6bcebbeae30e74d2e88d5abbb7 100644 --- a/lean/OAI/Probability/TraceReconstruction/InitialOracle.lean +++ b/lean/OAI/Probability/TraceReconstruction/InitialOracle.lean @@ -1,1718 +1,1718 @@ -import OAI.Probability.TraceReconstruction.SourceOracle - -namespace OAI - -/-! -# InitialOracle - -Actual initial scores and anchors, count partitions and typicality, clipped metadata, common decoding, sharp hidden-count energy, tails, and budget caps. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -def initialMomentRatio (u m : ℕ) (q w : ℝ) : ℝ := - w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) - -def initialSignedBudget (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) : ℝ := - (∑r∈Finset.range R,w^(2*r)*signedInitialDegreeBound u m r s π θ l)+ - 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) - -theorem initialSignedBudget_nonneg (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) - (hq : 0 ≤ q) (ha : initialMomentRatio u m q w < 1) : - 0 ≤ initialSignedBudget u m l R s π θ q w := by - apply add_nonneg - · exact Finset.sum_nonneg (fun r _ => mul_nonneg (by rw [pow_mul]; positivity) - (signedInitialDegreeBound_nonneg _ _ _ _ _ _ _)) - · apply div_nonneg _ (sub_nonneg.mpr ha.le) - exact mul_nonneg (by norm_num) (pow_nonneg (by unfold initialMomentRatio; positivity [rankSchurConstant_pos]) _) - -/-- The signed score numerator in the *actual conditional mark-list laws*, - with the entire finite cancellation energy and geometric tail retained. -/ -theorem initial_signed_moment {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : - ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq - (fun x => initialMotifDensity hl off hsafe π s 1 q x-initialMotifDensity hl off hsafe π s (-1) q x) k ≤ - initialSignedBudget u m l R s π θ q w := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - have he : (fun x => initialMotifDensity hl off hsafe π s 1 q x-initialMotifDensity hl off hsafe π s (-1) q x)= - multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-mixedMotifCoefficient hl off hsafe π s (-1) σ) - (primitiveScore q) := by funext x; exact (multilinear_sub _ _ _ _).symm - rw [he] - apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk - (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans - rw [←hw] - exact signed_initial_full_energy hu hm hum hR hl off hi hoff hsafe π hπ hπsum s hcentral hq hθ hmean hv hM - (by rw [hw]; positivity [hq.1]) ha - -/-- Quantitative normalized common clipping of the level-zero conditional - pair. This theorem has only the literal count/geometric inequalities of the - initial construction, not a signed-density or oracle conclusion premise. -/ -theorem initial_conditional_clipped_exists {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (hscale : initialMomentRatio u m q w ≤ 1/2) - (hclip : Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k) ≤ 1/2) : - Nonempty (ClippedOracle - (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s (-1)) - (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s 1) k - (Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k)) - (64*initialSignedBudget u m l R s π θ q w)) := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - let A := (primitiveMarkLaw q hq' false).product l - let f := initialMotifDensity hl off hsafe π s (-1) q - let g := initialMotifDensity hl off hsafe π s 1 q - let U := initialMomentRatio u m q w/(1-initialMomentRatio u m q w) - have ha : initialMomentRatio u m q w < 1 := by linarith - have hz : 0 ≤ initialMomentRatio u m q w := by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1] - have hU : 0 ≤ U := div_nonneg hz (sub_nonneg.mpr ha.le) - have hU1 : U ≤ 1 := (div_le_iff₀ (sub_pos.mpr ha)).mpr (by linarith) - have hmom (τ : ℝ) : A.expect (fun x => |initialMotifDensity hl off hsafe π s τ q x-1|^(2*k)) ≤ U^k := - A.expect_even_pow_le_of_moment _ k hk (initial_centered_moment hl (by omega) hum off hi hoff hsafe π hπ hπsum s k hk τ hq hθ hmean hv hw ha) - have hV := initialSignedBudget_nonneg u m l R s π θ q w hq.1.le ha - have hsig := A.expect_even_pow_le_of_moment _ k hk - (initial_signed_moment hu hm hum hR hl off hi hoff hsafe π hπ hπsum s k hcentral hk hq hθ hmean hv hM hw ha) - rw [initialMotifLaw_withDensity hl off hsafe π hπ hπsum s (-1) hq', - initialMotifLaw_withDensity hl off hsafe π hπ hπsum s 1 hq'] - have H := A.exists_clippedOracle f g - (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s (-1) hq') - (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s 1 hq') - (initialMotifDensity_mean hl off hsafe π hπ hπsum s (-1) hq') - (initialMotifDensity_mean hl off hsafe π hπ hπsum s 1 hq') - Finset.univ 0 (by simp [eventMass]) (by simp [eventMass]) k hk U hU hU1 (hmom (-1)) (hmom 1) - (initialSignedBudget u m l R s π θ q w) hV (by simpa only [Finset.mem_univ,ite_true] using hsig) - (by simpa only [zero_add] using hclip) - simpa only [zero_add] using H - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -theorem evenMomentSq_le_of_expect (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) - {V : ℝ} (hV : 0≤V) (h : P.expect (fun a => |F a|^(2*k))≤V^k) : - P.evenMomentSq F k≤V := by - have H := Real.rpow_le_rpow (P.expect_nonneg _ (fun _ => by positivity)) h (by positivity : 0≤(k:ℝ)⁻¹) - rw [Real.pow_rpow_inv_natCast hV (by omega)] at H - simpa only [FiniteLaw.evenMomentSq,one_div] using H - -theorem tv_sigma_eq {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] - (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) : - (M.sigma P).tv (M.sigma Q)=M.expect (fun i => (P i).tv (Q i)) := by - simp only [tv,sigma,expect,Fintype.sum_sigma,←mul_sub,abs_mul,abs_of_nonneg (M.nonneg _)] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - rw [←Finset.mul_sum] - ring - -end FiniteLaw -namespace ClippedOracle -variable {α : Type*} [Fintype α] {P Q : FiniteLaw α} {k : ℕ} {e V E W : ℝ} - -def weaken (C : ClippedOracle P Q k e V) (he : e≤E) (hV : V≤W) : ClippedOracle P Q k E W where - first := C.first - second := C.second - score := C.score - density := C.density - likelihood_nonneg := C.likelihood_nonneg - centered := C.centered - moment := C.moment.trans hV - first_tv := C.first_tv.trans he - second_tv := C.second_tv.trans he - -def trivial (P Q : FiniteLaw α) (k : ℕ) (hk : 1≤k) : ClippedOracle P Q k 1 0 where - first := P - second := P - score := fun _ => 0 - density := fun _ => by ring - likelihood_nonneg := fun _ => by norm_num - centered := by simp [FiniteLaw.expect] - moment := by - apply P.evenMomentSq_le_of_expect _ k hk (by norm_num) - simp [FiniteLaw.expect,zero_pow (by omega : 2*k≠0)] - first_tv := by simp [FiniteLaw.tv] - second_tv := FiniteLaw.tv_le_one _ _ - -/-- Reported metadata is retained, so the squared moment of a normalized - score assembles without a mixing penalty. No conditioning of the original - latent metadata distribution occurs. -/ -def sigma {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] - (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) (e : ι → ℝ) - (k : ℕ) (hk : 1≤k) (V : ℝ) (hV : 0≤V) - (C : ∀i,ClippedOracle (P i) (Q i) k (e i) V) : - ClippedOracle (M.sigma P) (M.sigma Q) k (M.expect e) V where - first := M.sigma (fun i => (C i).first) - second := M.sigma (fun i => (C i).second) - score := fun a => (C a.1).score a.2 - density := fun a => by dsimp only [FiniteLaw.sigma]; rw [(C a.1).density]; ring - likelihood_nonneg := fun a => (C a.1).likelihood_nonneg a.2 - centered := by - rw [FiniteLaw.expect_sigma] - simp_rw [(C _).centered] - simp [FiniteLaw.expect] - moment := by - apply FiniteLaw.evenMomentSq_le_of_expect _ _ k hk hV - rw [FiniteLaw.expect_sigma] - calc - _ ≤ M.expect (fun _ => V^k) := M.expect_mono (fun i => - (C i).first.expect_even_pow_le_of_moment _ k hk (C i).moment) - _ = _ := M.expect_const _ - first_tv := by - rw [FiniteLaw.tv_sigma_eq] - exact M.expect_mono (fun i => (C i).first_tv) - second_tv := by - rw [FiniteLaw.tv_sigma_eq] - exact M.expect_mono (fun i => (C i).second_tv) - -/-- Replace bad conditional observations by a common law rather than making - the original metadata law conditional on typicality. The exact cost is - the true metadata failure mass plus the good conditional clipping cost. -/ -theorem assemble_good {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] - (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) (Good : ι → Prop) - (k : ℕ) (hk : 1≤k) (e V : ℝ) (he : 0≤e) (hV : 0≤V) - (C : ∀i,Good i → Nonempty (ClippedOracle (P i) (Q i) k e V)) : - Nonempty (ClippedOracle (M.sigma P) (M.sigma Q) k - (e+M.expect (fun i => if Good i then 0 else 1)) V) := by - let err := fun i => if Good i then e else 1 - have hi (i) : Nonempty (ClippedOracle (P i) (Q i) k (err i) V) := by - by_cases h : Good i - · simpa only [err,ite_eq_left h] using C i h - · exact ⟨(trivial (P i) (Q i) k hk).weaken (by simp [err,h]) hV⟩ - let D := sigma M P Q err k hk V hV (fun i => Classical.choice (hi i)) - refine ⟨D.weaken ?_ le_rfl⟩ - calc - M.expect err ≤ M.expect (fun i => e+(if Good i then 0 else 1)) := M.expect_mono (fun i => by - dsimp only [err]; split_ifs <;> linarith) - _ = _ := by rw [M.expect_add,M.expect_const] - -end ClippedOracle -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -theorem translated_fair_eval (g : ℕ) (c : ℤ) (F : ℤ → ℝ) : - (∑X∈(translateSeries c (fairSeries g)).coeff.support, - (translateSeries c (fairSeries g)).coeff X*F X)= - ∑k∈Finset.range (g+1),fairBinomial g k*F (c+k) := by - have H := congrArg (fun p : IntSeries => Finsupp.linearCombination ℝ F p.coeff) - (congrArg (translateSeries c) (fairSeries_sum g)) - simp only [translateSeries,Finset.mul_sum,AddMonoidAlgebra.single_mul_single,one_mul, - AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, - Finsupp.linearCombination_single,smul_eq_mul] at H - exact H - -/-- The literal initial anchor after conditioning the paired side outputs. -/ -def posteriorAnchorSeries {ι : Type*} [Fintype ι] (c : ℤ) (d : ι → Option Bool) : IntSeries := - translateSeries (c-(∑i,(visibleOnes (d i):ℤ))-(∑i,hiddenTrial (d i))) - (fairSeries (∑i,hiddenTrial (d i))) - -theorem posterior_anchor_average {ι : Type*} [Fintype ι] - (c : ℤ) (d : ι → Option Bool) (F : ℤ → ℝ) : - (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i))* - F (c-∑i,(bitIndex (b i):ℤ)))= - ∑X∈(posteriorAnchorSeries c d).coeff.support,(posteriorAnchorSeries c d).coeff X*F X := by - rw [posterior_count_average_reflected d (fun z => F (c-z)),posteriorAnchorSeries,translated_fair_eval] - apply Finset.sum_congr rfl - intro k _ - congr 2 - ring - -theorem posteriorAnchorSeries_nonneg {ι : Type*} [Fintype ι] - (c : ℤ) (d : ι → Option Bool) (X : ℤ) : 0 ≤ (posteriorAnchorSeries c d).coeff X := - translated_binomial_nonneg _ _ _ - -theorem posteriorAnchorSeries_total {ι : Type*} [Fintype ι] - (c : ℤ) (d : ι → Option Bool) : - ∑X∈(posteriorAnchorSeries c d).coeff.support,(posteriorAnchorSeries c d).coeff X=1 := by - have H := posterior_anchor_average c d (fun _ => 1) - simp only [mul_one] at H - rw [←H] - exact (FiniteLaw.indexedProduct (fun i => flagPosterior (d i))).total - -theorem posteriorAnchorSeries_support {ι : Type*} [Fintype ι] - (c : ℤ) (d : ι → Option Bool) (X : ℤ) (hX : X∈(posteriorAnchorSeries c d).coeff.support) : - c-Fintype.card ι ≤ X ∧ X ≤ c := by - have H := translated_binomial_support (∑i,hiddenTrial (d i)) - (c-(∑i,(visibleOnes (d i):ℤ))-(∑i,hiddenTrial (d i))) X - (Finsupp.mem_support_iff.mp hX) - have hz : 0 ≤ ∑i,(visibleOnes (d i):ℤ) := Finset.sum_nonneg (fun _ _ => by positivity) - have hh : (∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i)) ≤ Fintype.card ι := by - rw [Nat.cast_sum,←Finset.sum_add_distrib] - calc - _ ≤ ∑_i : ι,(1:ℤ) := Finset.sum_le_sum (fun i _ => by - cases h:d i with - | none => simp [visibleOnes,hiddenTrial] - | some b => cases b <;> simp [visibleOnes,hiddenTrial]) - _ = _ := by simp - omega - -theorem posteriorAnchorSeries_central {ι : Type*} [Fintype ι] - (u s : ℕ) (c : ℤ) (d : ι → Option Bool) - (hleft : (u:ℝ)/3 ≤ 2*((c:ℝ)-Fintype.card ι)+1) - (hright : (u:ℝ)/3 ≤ 2*u-(2*((c:ℝ)+(2:ℝ)^s)+1)) : - CentralMotifSupport u s (posteriorAnchorSeries c d) := by - intro X hX - have H := posteriorAnchorSeries_support c d X hX - have H₁ : (c:ℝ)-Fintype.card ι ≤ X := by exact_mod_cast H.1 - have H₂ : (X:ℝ) ≤ c := by exact_mod_cast H.2 - constructor <;> linarith - -namespace PairedMechanisms -variable {Side α : Type*} [Fintype Side] [Fintype α] {J : ℕ} - -def emissionOracle (M : PairedMechanisms Side J) (K : (Fin J → Bool) → FiniteLaw α) : - FiniteLaw (Reports Side J × α) := - M.reports.joint (fun z => (orientationsGiven z).mixture K) - -/-- Bayes factorization is valid for arbitrary conditional finite emissions, - including the dependent-length initial primitive-mark list. -/ -theorem emission_factorization (M : PairedMechanisms Side J) (K : (Fin J → Bool) → FiniteLaw α) : - (fairOrientations J).mixture (fun b => (M.reportsGiven b).prod (K b))=M.emissionOracle K := by - apply FiniteLaw.ext - funext zx - rcases zx with ⟨z,x⟩ - change (∑b,(∏i : Fin J,(1/2:ℝ))* - ((∏i,FiniteLaw.pairedFlagMass (M.first i) (M.second i) (M.common i) - (M.hiddenWeight i) (b i) (z i))*(K b).mass x))= - (∏i,FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) - (M.hiddenWeight i) (z i))*(∑b,(∏i,(flagPosterior (z i).1).mass (b i))*(K b).mass x) - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro b _ - rw [←mul_assoc,←Finset.prod_mul_distrib,FiniteLaw.pairedFlags_product_bayes,mul_assoc] - -end PairedMechanisms - -theorem conditionalMotifLaw_posterior {u m l J : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (d : Fin J → Option Bool) (s : ℕ) (τ : ℝ) : - (FiniteLaw.coordinateProduct (fun i => flagPosterior (d i))).mixture - (fun b => conditionalPrimitiveLaw hl q hq - (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= - conditionalMotifLaw hl off hsafe hq (posteriorAnchorSeries c d) - (posteriorAnchorSeries_nonneg c d) (posteriorAnchorSeries_total c d) s τ := by - apply FiniteLaw.ext - funext x - change (∑b : Fin J → Bool,(∏i : Fin J,(flagPosterior (d i)).mass (b i))* - (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s - (c-∑i,(bitIndex (b i):ℤ)) τ))).mass x)=_ - classical - have H := posterior_anchor_average c d (fun X => - (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X τ))).mass x) - calc - _ = ∑X∈(posteriorAnchorSeries c d).coeff.support, - (posteriorAnchorSeries c d).coeff X* - (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X τ))).mass x := by - convert H using 1 - congr 1 - ext b - simp - _ = _ := (Finset.sum_coe_sort _ _).symm - - -/-- Initial observations retain the central count with its original binomial law. -/ -def countedMotifLaw {u m : ℕ} (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) - (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (τ : ℝ) : - FiniteLaw (BoundedMarks (u*m)) := - (boundedCountLaw (le_refl (u*m)) (1-primitiveErasure q) (primitiveRetention_mem hq)).sigma - (fun l => conditionalMotifLaw (by omega) off hsafe hq π hπ hπsum s τ) - -theorem countedMotifLaw_posterior {u m J : ℕ} (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (d : Fin J → Option Bool) (s : ℕ) (τ : ℝ) : - (FiniteLaw.coordinateProduct (fun i => flagPosterior (d i))).mixture - (fun b => countedPrimitiveLaw (le_refl (u*m)) hq - (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= - countedMotifLaw off hsafe hq (posteriorAnchorSeries c d) - (posteriorAnchorSeries_nonneg c d) (posteriorAnchorSeries_total c d) s τ := by - apply FiniteLaw.ext - funext x - rcases x with ⟨l,x⟩ - have hl : l.val ≤ u*m := by omega - have H := congrArg (fun P : FiniteLaw (Fin l.val → PrimitiveMark) => P.mass x) - (conditionalMotifLaw_posterior hl off hsafe hq c d s τ) - change (∑b, _ * ((boundedCountLaw _ _ _).mass l * - (boundedConditionalPrimitiveLaw hq _ l).mass x))=_ - simp only [boundedConditionalPrimitiveLaw,dite_eq_left hl] - change _ = (boundedCountLaw _ _ _).mass l * _ - rw [←H] - simp only [FiniteLaw.mixture,Finset.mul_sum] - apply Finset.sum_congr rfl - intro b _ - ring - - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The actual displaced primitive slot in a period. -/ -def motifOffset {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (s : ℕ) (X : ℤ) (τ : ℝ) (j : ℤ) : Fin m := - ⟨off.val+(motifShift (motifIndicator s (j-X)) ((prouhetSeries s).coeff (j-X)) τ).val-1, by - have H := (motifShift (motifIndicator s (j-X)) ((prouhetSeries s).coeff (j-X)) τ).isLt - omega⟩ - -theorem signedPeriodDefects_periodSlot {u m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (s : ℕ) (X : ℤ) (τ : ℝ) : - signedPeriodDefects off hsafe s X τ = - periodSlot (fun j => motifOffset off hi s X τ j.val) := by - funext j - apply Fin.ext - simp only [signedPeriodDefects,shiftedTag,periodSlot,motifOffset] - omega - -def motifPeriodWord {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (u s : ℕ) (X : ℤ) (τ : ℝ) : List Bool := - periodString m u (fun j => motifOffset off hi s X τ j.val) - -theorem signed_primitive_word {u m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (s : ℕ) (X : ℤ) (τ : ℝ) : - (((List.ofFn (defectTypes (signedPeriodDefects off hsafe s X τ))).map primitiveBlock).flatten)= - motifPeriodWord off hi u s X τ := by - rw [signedPeriodDefects_periodSlot off hi,periodic_primitive_word] - rfl - -theorem motifOffset_outside {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (s : ℕ) (X : ℤ) (τ : ℝ) (j : ℤ) (hj : j off ⟨i.val,by omega⟩) ++ - periodString m k (fun i => off ⟨n+i.val,by omega⟩) ++ - periodString m z (fun i => off ⟨n+k+i.val,by omega⟩) := by - simp only [periodString,List.ofFn_add,List.flatten_append] - rfl - -/-- Every randomized initial partition is a partition of the same literal -period string, with no fit conditioning or change of channel. -/ -theorem motifPeriodWord_window {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (t K z s : ℕ) (a : ℤ) (τ : ℝ) (hleft : (t:ℤ) ≤ a) (hright : a+(2^s:ℕ) ≤ t+K) : - motifPeriodWord off hi (t+K+z) s a τ = - pureAtomRun (initialPeriod m off.val) t ++ motifPeriodWord off hi K s (a-t) τ ++ - pureAtomRun (initialPeriod m off.val) z := by - unfold motifPeriodWord - rw [periodString_three] - congr 2 - · rw [←periodString_constant off] - congr 1 - funext i - exact motifOffset_outside off hi s a τ i.val (Or.inl (by have H:=i.isLt; omega)) - · congr 1 - funext i - rw [Nat.cast_add,motifOffset_translate] - · rw [←periodString_constant off] - congr 1 - funext i - exact motifOffset_outside off hi s a τ (t+K+i.val) (Or.inr (by - have H : (0:ℤ) ≤ i.val := by positivity - omega)) - -theorem motifPeriodWord_length {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (u s : ℕ) (X : ℤ) (τ : ℝ) : - (motifPeriodWord off hi u s X τ).length=u*(2*m-1) := periodString_length _ _ _ - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] - -theorem coordinateProduct_expect_pairs {n : ℕ} (P : Fin n → FiniteLaw α) - (Q : Fin n → FiniteLaw β) (F : (Fin n → α×β) → ℝ) : - (coordinateProduct (fun i => (P i).prod (Q i))).expect F= - (coordinateProduct P).expect (fun a => - (coordinateProduct Q).expect (fun b => F (fun i => (a i,b i)))) := by - induction n with - | zero => - have H (a : Fin 0 → α×β) : a = fun i => Fin.elim0 i := by funext i; exact Fin.elim0 i - have hF : F=fun _ => F (fun i => Fin.elim0 i) := by - funext a - exact congrArg F (H a) - rw [hF] - simp only [expect_const] - | succ n ih => - rw [expect_coordinateProduct_succ,expect_prod,expect_coordinateProduct_succ] - congr 1 - funext a - simp_rw [ih,expect_coordinateProduct_succ Q] - rw [expect_comm] - congr 1 - funext x - congr 1 - funext b - congr 1 - funext y - congr 1 - funext i - refine Fin.cases ?_ (fun j => ?_) i <;> simp - -end FiniteLaw - -/-- Three chronological streams, with side pairs independent across slots. -This forgets flags but does not separate any marks inside the central list. -/ -def decodePairedEmission {Side α : Type*} {J : ℕ} - (side : Side → List Bool) (central : α → List Bool) (z : Reports Side J × α) : List Bool := - coordinateWord (fun i => side (z.1 i).2.1) ++ central z.2 ++ - coordinateWord (fun i => side (z.1 i).2.2) - -namespace PairedMechanisms -variable {Side α : Type*} [Fintype Side] [Fintype α] {J : ℕ} - -theorem reportsGiven_paired_simulates (M : PairedMechanisms Side J) (b : Fin J → Bool) - {q : ℝ} (side : Side → List Bool) (central : α → List Bool) (K : FiniteLaw α) - (U V : Fin J → List Bool) (w : List Bool) - (hfirst : ∀i,SimulatesTrace q (M.first i) side (U i)) - (hsecond : ∀i,SimulatesTrace q (M.second i) side (V i)) - (hK : SimulatesTrace q K central w) : - SimulatesTrace q ((M.reportsGiven b).prod K) (decodePairedEmission side central) - (coordinateWord (fun i => if b i then V i else U i) ++ w ++ - coordinateWord (fun i => if b i then U i else V i)) := by - let P : Fin J → FiniteLaw Side := fun i => if b i then M.second i else M.first i - let Q : Fin J → FiniteLaw Side := fun i => if b i then M.first i else M.second i - have HP : ∀i,SimulatesTrace q (P i) side (if b i then V i else U i) := by - intro i - dsimp [P] - cases h:b i - · exact hfirst i - · exact hsecond i - have HQ : ∀i,SimulatesTrace q (Q i) side (if b i then U i else V i) := by - intro i - dsimp [Q] - cases h:b i - · exact hsecond i - · exact hfirst i - have H := ((coordinateProduct_simulates P side _ HP).append hK).append - (coordinateProduct_simulates Q side _ HQ) - intro F - rw [←H F,FiniteLaw.expect_prod,FiniteLaw.expect_prod] - change (M.reportsGiven b).expect (fun z => K.expect (fun x => - F (coordinateWord (fun i => side (z i).2.1) ++ central x ++ - coordinateWord (fun i => side (z i).2.2))))=_ - have hf := congrArg (fun L : FiniteLaw (Fin J → Side×Side) => L.expect (fun z => - K.expect (fun x => F (coordinateWord (fun i => side (z i).1) ++ central x ++ - coordinateWord (fun i => side (z i).2))))) (M.reportsGiven_forget b) - rw [FiniteLaw.expect_map] at hf - simp only [Function.comp_def] at hf - rw [hf] - have he : (fun i => FiniteLaw.orientedProd (M.first i) (M.second i) (b i))= - fun i => (P i).prod (Q i) := by - funext i - cases h:b i <;> simp [FiniteLaw.orientedProd,P,Q,h] - rw [he,FiniteLaw.coordinateProduct_expect_pairs] - simp only [FiniteLaw.expect_prod] - congr 1 - funext a - rw [FiniteLaw.expect_comm] - -end PairedMechanisms -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Exact initial paired prefix and complementary suffix sizes. -/ -def initialPrefixPeriods {J : ℕ} (k : ℕ) (b : Fin J → Bool) : ℕ := - ∑ i : Fin J, (k+bitIndex (b i)) -def initialSuffixPeriods {J : ℕ} (k : ℕ) (b : Fin J → Bool) : ℕ := - ∑ i : Fin J, (k+(1-bitIndex (b i))) - -theorem initialPrefixPeriods_eval {J : ℕ} (k : ℕ) (b : Fin J → Bool) : - initialPrefixPeriods k b=J*k+∑i,bitIndex (b i) := by - simp [initialPrefixPeriods,Finset.sum_add_distrib] - -theorem initialPairPeriods_total {J : ℕ} (k : ℕ) (b : Fin J → Bool) : - initialPrefixPeriods k b+initialSuffixPeriods k b=J*(2*k+1) := by - unfold initialPrefixPeriods initialSuffixPeriods - rw [←Finset.sum_add_distrib] - have H (i : Fin J) : (k+bitIndex (b i))+(k+(1-bitIndex (b i)))=2*k+1 := by - cases h:b i <;> simp [bitIndex] <;> omega - simp only [H,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Nat.cast_id] - -theorem initialPrefixPeriods_bounds {J : ℕ} (k : ℕ) (b : Fin J → Bool) : - J*k ≤ initialPrefixPeriods k b ∧ initialPrefixPeriods k b ≤ J*k+J := by - rw [initialPrefixPeriods_eval] - have H : (∑i,bitIndex (b i)) ≤ J := by - calc - _ ≤ ∑_i : Fin J,1 := Finset.sum_le_sum (fun i _ => by cases b i <;> simp [bitIndex]) - _ = _ := by simp - omega - -theorem initial_paired_oracle_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (k s : ℕ) (a : ℤ) (τ : ℝ) - (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) - (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) - (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) - (ha : (J*k+J:ℕ) ≤ a) (ha' : a+(2^s:ℕ) ≤ (J*k+K:ℕ)) : - SimulatesTrace q - (M.emissionOracle (fun b => countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (signedPeriodDefects off hsafe s - (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)))) - (decodePairedEmission side decodeBoundedMarks) - (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) := by - rw [←M.emission_factorization] - intro F - rw [FiniteLaw.expect_mixture] - have H (b : Fin J → Bool) : - ((M.reportsGiven b).prod (countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (signedPeriodDefects off hsafe s - (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)))).expect - (fun z => F (decodePairedEmission side decodeBoundedMarks z))= - listDeletionExpectation q (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) F := by - let t := initialPrefixPeriods k b - let z := initialSuffixPeriods k b - have ht := initialPrefixPeriods_bounds k b - have htot : t+K+z=J*(2*k+1)+K := by - have H:=initialPairPeriods_total k b - dsimp [t,z] - omega - have hanchor : a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)=a-t := by - dsimp [t] - rw [initialPrefixPeriods_eval] - push_cast - ring - have hleft : (t:ℤ) ≤ a := by - have H : (t:ℤ) ≤ (J*k+J:ℕ) := by exact_mod_cast ht.2 - omega - have hright : a+(2^s:ℕ) ≤ (t:ℤ)+K := by - have H : ((J*k:ℕ):ℤ) ≤ t := by exact_mod_cast ht.1 - simp only [Nat.cast_add] at ha' - omega - have hp : coordinateWord (fun i => if b i then - pureAtomRun (initialPeriod m off.val) (k+1) else pureAtomRun (initialPeriod m off.val) k)= - pureAtomRun (initialPeriod m off.val) t := by - have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) (k+1) else - pureAtomRun (initialPeriod m off.val) k)=pureAtomRun (initialPeriod m off.val) (k+bitIndex (b i)) := by - cases b i <;> simp [bitIndex] - simp_rw [h] - exact coordinateWord_pureAtomRun _ _ - have hz : coordinateWord (fun i => if b i then - pureAtomRun (initialPeriod m off.val) k else pureAtomRun (initialPeriod m off.val) (k+1))= - pureAtomRun (initialPeriod m off.val) z := by - have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) k else - pureAtomRun (initialPeriod m off.val) (k+1))=pureAtomRun (initialPeriod m off.val) (k+(1-bitIndex (b i))) := by - cases b i <;> simp [bitIndex] - simp_rw [h] - exact coordinateWord_pureAtomRun _ _ - have hc := countedPrimitiveLaw_simulates (le_refl (K*m)) hq - (defectTypes (signedPeriodDefects off hsafe s (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)) - rw [signed_primitive_word off hi] at hc - have hs := M.reportsGiven_paired_simulates b side decodeBoundedMarks _ - (fun _ => pureAtomRun (initialPeriod m off.val) k) - (fun _ => pureAtomRun (initialPeriod m off.val) (k+1)) _ hfirst hsecond hc - have hword : coordinateWord (fun i => if b i then - pureAtomRun (initialPeriod m off.val) (k+1) else pureAtomRun (initialPeriod m off.val) k) ++ - motifPeriodWord off hi K s (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ ++ - coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) k else - pureAtomRun (initialPeriod m off.val) (k+1))= - motifPeriodWord off hi (J*(2*k+1)+K) s a τ := by - rw [hp,hz,hanchor,←motifPeriodWord_window off hi t K z s a τ hleft hright,htot] - rw [hword] at hs - exact hs F - simp only [H,FiniteLaw.expect_const] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -abbrev InitialMetadata (Side : Type*) (J N : ℕ) := Reports Side J × Fin (N+1) -abbrev InitialObservation (Side : Type*) (J N : ℕ) := - Σz : InitialMetadata Side J N, Fin z.2.val → PrimitiveMark - -def initialMetadataLaw {Side : Type*} [Fintype Side] {J : ℕ} - (M : PairedMechanisms Side J) (N : ℕ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : - FiniteLaw (InitialMetadata Side J N) := - M.reports.prod (boundedCountLaw (le_refl N) (1-primitiveErasure q) (primitiveRetention_mem hq)) - -def initialConditionalLaw {Side : Type*} [Fintype Side] {J K m : ℕ} - (off : Fin m) (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) - (z : InitialMetadata Side J (K*m)) : FiniteLaw (Fin z.2.val → PrimitiveMark) := - conditionalMotifLaw (by have H:=z.2.isLt; omega) off hsafe hq - (posteriorAnchorSeries c (fun i => (z.1 i).1)) - (posteriorAnchorSeries_nonneg c _) (posteriorAnchorSeries_total c _) s τ - -def initialSigmaLaw {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) : - FiniteLaw (InitialObservation Side J (K*m)) := - (initialMetadataLaw M (K*m) hq).sigma (initialConditionalLaw off hsafe hq c s τ) - -def decodeInitialObservation {Side : Type*} {J N : ℕ} (side : Side → List Bool) - (z : InitialObservation Side J N) : List Bool := - decodePairedEmission side decodeBoundedMarks (z.1.1,⟨z.1.2,z.2⟩) - -theorem initialSigmaLaw_expect {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) - (F : Reports Side J × BoundedMarks (K*m) → ℝ) : - (initialSigmaLaw M off hsafe hq c s τ).expect (fun z => F (z.1.1,⟨z.1.2,z.2⟩))= - (M.emissionOracle (fun b => countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))).expect F := by - unfold PairedMechanisms.emissionOracle - rw [FiniteLaw.expect_joint] - have H (z : Reports Side J) : (PairedMechanisms.orientationsGiven z).mixture - (fun b => countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= - countedMotifLaw off hsafe hq (posteriorAnchorSeries c (fun i => (z i).1)) - (posteriorAnchorSeries_nonneg c _) (posteriorAnchorSeries_total c _) s τ := - countedMotifLaw_posterior off hsafe hq c (fun i => (z i).1) s τ - simp_rw [H] - simp only [initialSigmaLaw,initialMetadataLaw,FiniteLaw.expect_sigma,FiniteLaw.expect_prod, - countedMotifLaw,initialConditionalLaw] - -theorem initial_sigma_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (k s : ℕ) (a : ℤ) (τ : ℝ) - (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) - (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) - (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) - (ha : (J*k+J:ℕ) ≤ a) (ha' : a+(2^s:ℕ) ≤ (J*k+K:ℕ)) : - SimulatesTrace q (initialSigmaLaw M off hsafe hq (a-(J*k:ℕ)) s τ) - (decodeInitialObservation side) (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) := by - intro F - unfold decodeInitialObservation - rw [initialSigmaLaw_expect M off hsafe hq (a-(J*k:ℕ)) s τ (fun z => F (decodePairedEmission side decodeBoundedMarks z))] - exact initial_paired_oracle_simulates M k s a τ off hi hsafe hq side hfirst hsecond ha ha' F - -/-- This is the literal count-typicality condition; it does not change the - central count's original binomial law. -/ -def initialCountAdmissible (N : ℕ) (q : ℝ) (l : Fin (N+1)) : Prop := - (l.val:ℝ)/(N:ℝ)∈Set.Icc (1-q^2) (1-q^2/4) ∧ - 1 ≤ (N:ℝ)*((l.val:ℝ)/(N:ℝ))*(1-(l.val:ℝ)/(N:ℝ)) - -def initialMetadataGood {Side : Type*} {J N : ℕ} (q ω : ℝ) - (z : InitialMetadata Side J N) : Prop := - initialCountAdmissible N q z.2 ∧ (J:ℝ)*ω^2/2 ≤ ∑i,(hiddenTrial (z.1 i).1:ℝ) - -/-- The genuine initial metadata oracle is clipped by conditioning each - admissible fiber only. Every bad report/count keeps its original mass and - is replaced by a common law, so all discarded mass is charged. -/ -theorem initial_sigma_clipped_exists {Side : Type*} [Fintype Side] {J K m R : ℕ} - (M : PairedMechanisms Side J) (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) - (hR : 0 < R) (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - (c : ℤ) (s k : ℕ) (hk : 1 ≤ k) - (hleft : (K:ℝ)/3 ≤ 2*((c:ℝ)-J)+1) - (hright : (K:ℝ)/3 ≤ 2*K-(2*((c:ℝ)+(2:ℝ)^s)+1)) - {q ω w V : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hM : ((2*(2^s):ℕ):ℝ) < (K:ℝ)/(3*(R+1:ℝ))) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) - (hscale : initialMomentRatio K m q w ≤ 1/2) - (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) - (hV : 0 ≤ V) - (hbudget : ∀z : InitialMetadata Side J (K*m),initialMetadataGood q ω z → - 64*initialSignedBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) - ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V) : - Nonempty (ClippedOracle - (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s (-1)) - (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s 1) k - (Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ - (initialMetadataLaw M (K*m) ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩).expect - (fun z => if initialMetadataGood q ω z then 0 else 1)) V) := by - apply ClippedOracle.assemble_good _ _ _ (initialMetadataGood q ω) k hk _ V (Real.sqrt_nonneg _) hV - intro z hz - have hmean : ((K*m:ℕ):ℝ)*((z.2.val:ℝ)/(K*m:ℕ))=z.2.val := by - exact mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0))) - have H := initial_conditional_clipped_exists hK hm hKm hR (by have H:=z.2.isLt; omega) off hi hoff hsafe - (posteriorAnchorSeries c (fun i => (z.1 i).1)) (posteriorAnchorSeries_nonneg c _) - (posteriorAnchorSeries_total c _) s k - (posteriorAnchorSeries_central K s c _ (by simpa using hleft) hright) hk hq hz.1.1 hmean hz.1.2 hM hw hscale hclip - exact ⟨(Classical.choice H).weaken le_rfl (hbudget z hz)⟩ - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def purePeriodCoefficient {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) : (Fin l → Bool) → ℝ := - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot (u:=u) (fun _ => off)))) - -theorem mixedMotifCoefficient_pure_rank_difference {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (v : IncreasingTuple l r) : - mixedMotifCoefficient hl off hsafe π s 1 (rankMask v)-purePeriodCoefficient hl off (rankMask v)= - pureRankCoefficient hl off hsafe π s v := by - unfold mixedMotifCoefficient purePeriodCoefficient pureRankCoefficient - simp_rw [averaged_rank_coefficient hl _ v,mul_sub,Finset.sum_sub_distrib,←Finset.sum_mul,hπsum,one_mul] - -/-- The pure comparison retains all low-degree cancellation, not just its - total defect density. -/ -def initialPureDegreeBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : ℝ := - if r=0 then 0 else - 2*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else purePatternBound u m r s π θ k)+ - 2*((Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l*(2*Real.exp (-(m:ℝ)/(1024*u))))))^2 - -theorem initialPureDegreeBound_nonneg (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : - 0 ≤ initialPureDegreeBound u m r s π θ l := by - unfold initialPureDegreeBound - split_ifs - · exact le_rfl - · apply add_nonneg _ (by positivity) - apply mul_nonneg (by positivity) - apply Finset.sum_nonneg - intro k _ - split_ifs - · exact le_rfl - · unfold purePatternBound - split_ifs <;> apply mul_nonneg _ (seriesL2Sq_nonneg _) - all_goals dsimp only [periodDifferencePrefactor,lengthDifferenceConstant,periodCentralSumConstant] - all_goals positivity - -theorem pureMotif_degree_zero {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) : - (∑σ : Fin l → Bool,if monomialDegree σ=0 then - (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0)=0 := by - simp_rw [monomialDegree_eq_zero_iff] - simp [mixedMotifCoefficient_empty hl off hsafe π hπsum,purePeriodCoefficient,averagedCoefficient_empty] - -theorem pureMotif_degree_cancellation {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : - (∑σ : Fin l → Bool,if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0) ≤ - initialPureDegreeBound u m r s π θ l := by - refine (sum_degree_coeff_sq_le _).trans ?_ - simp_rw [mixedMotifCoefficient_pure_rank_difference hl off hsafe π hπsum s] - simpa only [initialPureDegreeBound,ite_eq_right (by omega : r ≠ 0)] using - initial_pure_energy hu hm hr hl off hoff hsafe π hπ hπsum s hcentral hθ hhalf hmean hv - -theorem purePeriod_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : - w^(2*r)*(∑σ : Fin l → Bool,if monomialDegree σ=r then (purePeriodCoefficient hl off σ)^2 else 0) ≤ - (initialMomentRatio u m q w)^r := by - have hw0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity - have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] - by_cases hru : r ≤ u - · have hb := period_degree_square_sum hl hr hru hm hum hq hθ hmean hv (fun _ => off) - (fun _ => hoff) (fun _ _ => by simp) - have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by - apply Real.sqrt_le_sqrt - apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) - have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr - nlinarith - calc - _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := - mul_le_mul_of_nonneg_left hb hw0 - _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by gcongr - _ = _ := by unfold initialMomentRatio; rw [pow_mul,mul_pow,mul_pow]; ring - · have H := defect_degree_bound hl (periodSlot (u:=u) (fun _ => off)) (periodSlot_strictMono _) (by omega : u < r) - change _=0 at H - change w^(2*r)*_ ≤ _ - rw [show (∑σ : Fin l → Bool,if monomialDegree σ=r then (purePeriodCoefficient hl off σ)^2 else 0)=0 from H,mul_zero] - exact pow_nonneg (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) _ - -theorem pureMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : - w^(2*r)*(∑σ : Fin l → Bool,if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0) ≤ - 4*(initialMomentRatio u m q w)^r := by - have H := mul_le_mul_of_nonneg_left (degree_square_sub_le - (mixedMotifCoefficient hl off hsafe π s 1) (purePeriodCoefficient hl off) r) - (by rw [pow_mul]; positivity : 0 ≤ w^(2*r)) - have h1 := mixedMotif_degree_geometric hl hr hm hum off hi hoff hsafe π hπ hπsum s 1 hq hθ hmean hv w - have h2 := purePeriod_degree_geometric hl hr hm hum off (hoff.trans (by norm_num)) hq hθ hmean hv w - change _ ≤ initialMomentRatio u m q w ^r at h1 - nlinarith only [H,h1,h2] - -def initialPureBudget (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) : ℝ := - (∑r∈Finset.range R,w^(2*r)*initialPureDegreeBound u m r s π θ l)+ - 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) - -theorem pure_initial_full_energy {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : 0 ≤ w) (ha : initialMomentRatio u m q w < 1) : - multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ) w ≤ - initialPureBudget u m l R s π θ q w := by - have hq2 : q^2 ≤ (1/4:ℝ) := by - calc q^2 ≤ (1/2:ℝ)^2 := pow_le_pow_left₀ hq.1.le hq.2 2 - _ = _ := by norm_num - have hθ0 : θ∈Set.Ioo 0 1 := by constructor <;> nlinarith [hq.1,hθ.1,hθ.2] - have hhalf : 1/2 ≤ θ := by nlinarith [hθ.1] - apply multilinearEnergy_low_high _ w _ 4 hw (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) ha - (by norm_num) (initialPureDegreeBound u m · s π θ l) _ _ - (fun r => initialPureDegreeBound_nonneg _ _ _ _ _ _ _) - · intro r _hr - by_cases hr0 : r=0 - · subst r - rw [pureMotif_degree_zero hl off hsafe π hπsum s] - exact initialPureDegreeBound_nonneg _ _ _ _ _ _ _ - · exact pureMotif_degree_cancellation hu hm (Nat.pos_of_ne_zero hr0) hl off (hoff.trans (by norm_num)) - hsafe π hπ hπsum s hcentral hθ0 hhalf hmean hv - · intro r hr - exact pureMotif_degree_geometric hl (by omega) (by omega) hum off hi hoff hsafe π hπ hπsum s hq hθ hmean hv w - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def purePeriodDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) (q : ℝ) : - (Fin l → PrimitiveMark) → ℝ := multilinear (purePeriodCoefficient hl off) (primitiveScore q) - -theorem purePeriodDensity_nonneg {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (x : Fin l → PrimitiveMark) : - 0 ≤ purePeriodDensity hl off q x := by - have H := (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))).nonneg x - rw [conditionalDefectLaw_density] at H - exact nonneg_of_mul_nonneg_right H (primitive_product_mass_pos hq x) - -theorem purePeriodDensity_total {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - {q : ℝ} (hq : q∈Set.Ioo 0 1) : - ((primitiveMarkLaw q hq false).product l).expect (purePeriodDensity hl off q)=1 := by - have H := (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))).total - simpa only [conditionalDefectLaw_density,FiniteLaw.expect,purePeriodDensity,purePeriodCoefficient] using H - -theorem purePeriodLaw_withDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - {q : ℝ} (hq : q∈Set.Ioo 0 1) : - conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))= - ((primitiveMarkLaw q hq false).product l).withDensity (purePeriodDensity hl off q) - (purePeriodDensity_nonneg hl off hq) (purePeriodDensity_total hl off hq) := by - apply FiniteLaw.ext - funext x - exact conditionalDefectLaw_density hl hq _ x - -theorem purePeriod_centered_energy {u m l : ℕ} (hl : l ≤ u*m) (hm : 32 ≤ m) (hum : u ≤ m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : 0 ≤ w) (ha : initialMomentRatio u m q w < 1) : - multilinearEnergy (nonconstantCoefficient (purePeriodCoefficient hl off)) w ≤ - initialMomentRatio u m q w/(1-initialMomentRatio u m q w) := by - have H := multilinearEnergy_low_high (R:=1) - (nonconstantCoefficient (purePeriodCoefficient hl off)) w _ 1 hw - (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) ha (by norm_num) (fun _ => 0) - (fun r hr => by - have he : r=0 := by omega - subst r - rw [nonconstant_degree_zero]) - (fun r hr => by - rw [nonconstant_degree_pos _ (by omega)] - simpa only [one_mul] using purePeriod_degree_geometric hl (by omega) hm hum off hoff hq hθ hmean hv w) - (fun _ => le_rfl) - simpa using H - -theorem purePeriod_centered_moment {u m l : ℕ} (hl : l ≤ u*m) (hm : 32 ≤ m) (hum : u ≤ m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) (k : ℕ) (hk : 1 ≤ k) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : - ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq - (fun x => purePeriodDensity hl off q x-1) k ≤ - initialMomentRatio u m q w/(1-initialMomentRatio u m q w) := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - have he : (fun x => purePeriodDensity hl off q x-1)= - multilinear (nonconstantCoefficient (purePeriodCoefficient hl off)) (primitiveScore q) := by - funext x - rw [nonconstant_multilinear] - simp only [purePeriodCoefficient,averagedCoefficient_empty,purePeriodDensity] - rw [he] - apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk - (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans - rw [←hw] - exact purePeriod_centered_energy hl hm hum off hoff hq hθ hmean hv (by rw [hw]; positivity [hq.1]) ha - -theorem initial_pure_moment {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : - ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq - (fun x => initialMotifDensity hl off hsafe π s 1 q x-purePeriodDensity hl off q x) k ≤ - initialPureBudget u m l R s π θ q w := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - have he : (fun x => initialMotifDensity hl off hsafe π s 1 q x-purePeriodDensity hl off q x)= - multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ) - (primitiveScore q) := by funext x; exact (multilinear_sub _ _ _ _).symm - rw [he] - apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk - (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans - rw [←hw] - exact pure_initial_full_energy hu hm hum hR hl off hi hoff hsafe π hπ hπsum s hcentral hq hθ hmean hv - (by rw [hw]; positivity [hq.1]) ha - -theorem initial_pure_conditional_clipped_exists {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (hscale : initialMomentRatio u m q w ≤ 1/2) - (hclip : Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k) ≤ 1/2) : - Nonempty (ClippedOracle - (conditionalPrimitiveLaw hl q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - (defectTypes (periodSlot (u:=u) (fun _ => off)))) - (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s 1) k - (Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k)) - (64*initialPureBudget u m l R s π θ q w)) := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - let A := (primitiveMarkLaw q hq' false).product l - let f := purePeriodDensity hl off q - let g := initialMotifDensity hl off hsafe π s 1 q - let U := initialMomentRatio u m q w/(1-initialMomentRatio u m q w) - have ha : initialMomentRatio u m q w < 1 := by linarith - have hz : 0 ≤ initialMomentRatio u m q w := by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1] - have hU : 0 ≤ U := div_nonneg hz (sub_nonneg.mpr ha.le) - have hU1 : U ≤ 1 := (div_le_iff₀ (sub_pos.mpr ha)).mpr (by linarith) - have hf : A.expect (fun x => |f x-1|^(2*k)) ≤ U^k := - A.expect_even_pow_le_of_moment _ k hk (purePeriod_centered_moment hl (by omega) hum off - (hoff.trans (by norm_num)) k hk hq hθ hmean hv hw ha) - have hg : A.expect (fun x => |g x-1|^(2*k)) ≤ U^k := - A.expect_even_pow_le_of_moment _ k hk (initial_centered_moment hl (by omega) hum off hi hoff hsafe π hπ hπsum s k hk 1 hq hθ hmean hv hw ha) - have hsig := initial_pure_moment hu hm hum hR hl off hi hoff hsafe π hπ hπsum s k hcentral hk hq hθ hmean hv hw ha - have hV := (A.evenMomentSq_nonneg (fun x => g x-f x) k).trans hsig - have hsig' := A.expect_even_pow_le_of_moment _ k hk hsig - rw [purePeriodLaw_withDensity hl off hq',initialMotifLaw_withDensity hl off hsafe π hπ hπsum s 1 hq'] - have H := A.exists_clippedOracle f g - (purePeriodDensity_nonneg hl off hq') (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s 1 hq') - (purePeriodDensity_total hl off hq') (initialMotifDensity_mean hl off hsafe π hπ hπsum s 1 hq') - Finset.univ 0 (by simp [FiniteLaw.eventMass]) (by simp [FiniteLaw.eventMass]) k hk U hU hU1 hf hg - (initialPureBudget u m l R s π θ q w) hV (by simpa only [Finset.mem_univ,ite_true] using hsig') - (by simpa only [zero_add] using hclip) - simpa only [zero_add] using H - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- A common finite decoder transfers normalized clipping to actual complete - traces. Neither interface is permitted to assume the main lower bound. -/ -theorem ClippedOracle.tracePair {α : Type} [Fintype α] {P Q : FiniteLaw α} - {q e V : ℝ} {x y : List Bool} {k : ℕ} (f : α → List Bool) - (C : ClippedOracle P Q k e V) (hP : SimulatesTrace q P f x) - (hQ : SimulatesTrace q Q f y) : Nonempty (OracleTracePair q x y k e V) := by - refine ⟨{ - Outcome := α - finiteOutcome := inferInstance - first := C.first - second := C.second - decode := f - score := C.score - density := C.density - likelihood_nonneg := C.likelihood_nonneg - centered := C.centered - moment := C.moment - first_simulation := ?_ - second_simulation := ?_ - }⟩ - · simpa using hP.approximate.of_tv C.first_tv - · simpa using hQ.approximate.of_tv C.second_tv - -def initialPureConditionalLaw {Side : Type*} {J K m : ℕ} (off : Fin m) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (z : InitialMetadata Side J (K*m)) : - FiniteLaw (Fin z.2.val → PrimitiveMark) := - conditionalPrimitiveLaw (by have H:=z.2.isLt; omega) q hq - (defectTypes (periodSlot (u:=K) (fun _ => off))) - -def initialPureSigmaLaw {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (off : Fin m) {q : ℝ} (hq : q∈Set.Ioo 0 1) : - FiniteLaw (InitialObservation Side J (K*m)) := - (initialMetadataLaw M (K*m) hq).sigma (initialPureConditionalLaw off hq) - -theorem initialPureSigmaLaw_expect {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (off : Fin m) {q : ℝ} (hq : q∈Set.Ioo 0 1) - (F : Reports Side J × BoundedMarks (K*m) → ℝ) : - (initialPureSigmaLaw M off hq).expect (fun z => F (z.1.1,⟨z.1.2,z.2⟩))= - (M.emissionOracle (fun _ => countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (periodSlot (u:=K) (fun _ => off))))).expect F := by - simp only [initialPureSigmaLaw,initialMetadataLaw,FiniteLaw.expect_sigma, - FiniteLaw.expect_prod,PairedMechanisms.emissionOracle,FiniteLaw.expect_joint, - FiniteLaw.expect_mixture,FiniteLaw.expect_const,initialPureConditionalLaw, - countedPrimitiveLaw,FiniteLaw.expect_sigma] - have hl (l : Fin (K*m+1)) : l.val ≤ K*m := Nat.le_of_lt_succ l.isLt - simp only [boundedConditionalPrimitiveLaw,hl,dite_eq_left] - -theorem initial_pure_sigma_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} - (M : PairedMechanisms Side J) (k : ℕ) (off : Fin m) - {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) - (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) - (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) : - SimulatesTrace q (initialPureSigmaLaw (K:=K) M off hq) (decodeInitialObservation side) - (pureAtomRun (initialPeriod m off.val) (J*(2*k+1)+K)) := by - intro F - unfold decodeInitialObservation - rw [initialPureSigmaLaw_expect M off hq (fun z => F (decodePairedEmission side decodeBoundedMarks z)), - ←M.emission_factorization,FiniteLaw.expect_mixture] - have H (b : Fin J → Bool) : - ((M.reportsGiven b).prod (countedPrimitiveLaw (le_refl (K*m)) hq - (defectTypes (periodSlot (u:=K) (fun _ => off))))).expect - (fun z => F (decodePairedEmission side decodeBoundedMarks z))= - listDeletionExpectation q (pureAtomRun (initialPeriod m off.val) (J*(2*k+1)+K)) F := by - have hc := countedPrimitiveLaw_simulates (le_refl (K*m)) hq (defectTypes (periodSlot (u:=K) (fun _ => off))) - rw [periodic_primitive_word,periodString_constant] at hc - have hs := M.reportsGiven_paired_simulates b side decodeBoundedMarks _ - (fun _ => pureAtomRun (initialPeriod m off.val) k) - (fun _ => pureAtomRun (initialPeriod m off.val) (k+1)) _ hfirst hsecond hc - have hp : coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) (k+1) - else pureAtomRun (initialPeriod m off.val) k)= - pureAtomRun (initialPeriod m off.val) (initialPrefixPeriods k b) := by - have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) (k+1) else - pureAtomRun (initialPeriod m off.val) k)=pureAtomRun (initialPeriod m off.val) (k+bitIndex (b i)) := by - cases b i <;> simp [bitIndex] - simp_rw [h] - exact coordinateWord_pureAtomRun _ _ - have hz : coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) k - else pureAtomRun (initialPeriod m off.val) (k+1))= - pureAtomRun (initialPeriod m off.val) (initialSuffixPeriods k b) := by - have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) k else - pureAtomRun (initialPeriod m off.val) (k+1))=pureAtomRun (initialPeriod m off.val) (k+(1-bitIndex (b i))) := by - cases b i <;> simp [bitIndex] - simp_rw [h] - exact coordinateWord_pureAtomRun _ _ - rw [hp,hz,←pureAtomRun_add,←pureAtomRun_add] at hs - have ht : initialPrefixPeriods k b+K+initialSuffixPeriods k b=J*(2*k+1)+K := by - have ht:=initialPairPeriods_total k b - omega - rw [ht] at hs - exact hs F - simp only [H,FiniteLaw.expect_const] - -theorem initial_pure_sigma_clipped_exists {Side : Type*} [Fintype Side] {J K m R : ℕ} - (M : PairedMechanisms Side J) (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) - (hR : 0 < R) (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - (c : ℤ) (s k : ℕ) (hk : 1 ≤ k) - (hleft : (K:ℝ)/3 ≤ 2*((c:ℝ)-J)+1) - (hright : (K:ℝ)/3 ≤ 2*K-(2*((c:ℝ)+(2:ℝ)^s)+1)) - {q ω w V : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) - (hscale : initialMomentRatio K m q w ≤ 1/2) - (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) - (hV : 0 ≤ V) - (hbudget : ∀z : InitialMetadata Side J (K*m),initialMetadataGood q ω z → - 64*initialPureBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) - ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V) : - Nonempty (ClippedOracle - (initialPureSigmaLaw M off ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩) - (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s 1) k - (Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ - (initialMetadataLaw M (K*m) ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩).expect - (fun z => if initialMetadataGood q ω z then 0 else 1)) V) := by - apply ClippedOracle.assemble_good _ _ _ (initialMetadataGood q ω) k hk _ V (Real.sqrt_nonneg _) hV - intro z hz - have hmean : ((K*m:ℕ):ℝ)*((z.2.val:ℝ)/(K*m:ℕ))=z.2.val := by - exact mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0))) - have H := initial_pure_conditional_clipped_exists hK hm hKm hR (by have H:=z.2.isLt; omega) off hi hoff hsafe - (posteriorAnchorSeries c (fun i => (z.1 i).1)) (posteriorAnchorSeries_nonneg c _) - (posteriorAnchorSeries_total c _) s k - (posteriorAnchorSeries_central K s c _ (by simpa using hleft) hright) hk hq hz.1.1 hmean hz.1.2 hw hscale hclip - exact ⟨(Classical.choice H).weaken le_rfl (hbudget z hz)⟩ - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The half-mean hidden-count event yields the correct L², not supremum, - exponent J^{-s-1/2} in the initial Prouhet cancellation. -/ -def hiddenSignedL2Bound (J s : ℕ) (ω : ℝ) : ℝ := - ((2:ℝ)^(s*s))^2*((2*Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)))^s)^2* - Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)) - -def hiddenUnsignedL2Bound (J s : ℕ) (ω : ℝ) : ℝ := - ((2:ℝ)^s)^2*hiddenBinomialCap J ω - -theorem hiddenSignedL2Bound_nonneg (J s : ℕ) (ω : ℝ) : 0≤hiddenSignedL2Bound J s ω := by - unfold hiddenSignedL2Bound; positivity - -theorem hiddenUnsignedL2Bound_nonneg (J s : ℕ) (ω : ℝ) : 0≤hiddenUnsignedL2Bound J s ω := by - exact mul_nonneg (sq_nonneg _) (hiddenBinomialCap_nonneg _ _) - -theorem hidden_quotient_bound (J G s : ℕ) (ω : ℝ) (h : (J:ℝ)*ω^2/2≤G) : - binomialBound (G/(s+1))≤Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)) := by - apply (binomialBound_quotient_le G s).trans - apply Real.sqrt_le_sqrt - apply (div_le_div_iff₀ (by positivity : (0:ℝ)<(G:ℝ)+1) - (by positivity : (0:ℝ)<(J:ℝ)*ω^2+2)).mpr - have hh := mul_le_mul_of_nonneg_left h (by positivity : (0:ℝ)≤4*((s:ℝ)+1)) - nlinarith - -theorem posteriorAnchorSeries_signed_L2 {J : ℕ} (d : Fin J→Option Bool) (c : ℤ) (s : ℕ) (ω : ℝ) - (h : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - seriesL2Sq (prouhetSeries s*posteriorAnchorSeries c d)≤hiddenSignedL2Bound J s ω := by - have hn : (J:ℝ)*ω^2/2≤((∑i,hiddenTrial (d i):ℕ):ℝ) := by simpa only [Nat.cast_sum] using h - have hb := hidden_quotient_bound J (∑i,hiddenTrial (d i)) s ω hn - apply (translated_binomial_smoothing (∑i,hiddenTrial (d i)) s _).trans - unfold hiddenSignedL2Bound - rw [mul_assoc] - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply mul_le_mul - · apply pow_le_pow_left₀ (by unfold binomialBound; positivity) - exact pow_le_pow_left₀ (by unfold binomialBound; positivity) (mul_le_mul_of_nonneg_left hb (by norm_num)) _ - · exact hb - · exact Real.sqrt_nonneg _ - · positivity - -theorem posteriorAnchorSeries_unsigned_L2 {J : ℕ} (d : Fin J→Option Bool) (c : ℤ) (s : ℕ) (ω : ℝ) - (h : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - seriesL2Sq (geomSeries (2^s)*posteriorAnchorSeries c d)≤hiddenUnsignedL2Bound J s ω := by - have hn : (J:ℝ)*ω^2/2≤((∑i,hiddenTrial (d i):ℕ):ℝ) := by simpa only [Nat.cast_sum] using h - calc - _ ≤ seriesL1 (geomSeries (2^s))^2*seriesL2Sq (posteriorAnchorSeries c d) := seriesL2Sq_mul_le _ _ - _ ≤ ((2:ℝ)^s)^2*hiddenBinomialCap J ω := by - apply mul_le_mul - · exact pow_le_pow_left₀ (seriesL1_nonneg _) (by exact_mod_cast geomSeries_L1_le (2^s)) _ - · rw [posteriorAnchorSeries,translateSeries_L2Sq] - exact (fairSeries_L2Sq_bound _).trans (hidden_binomial_bound J _ ω hn) - · exact seriesL2Sq_nonneg _ - · positivity - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def initialDifferenceCap (d : ℕ) (q : ℝ) : ℝ := - 2*Real.sqrt (8*((d:ℝ)+1)/q^2) - -theorem initial_theta_variance {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) : - θ∈Set.Ioo 0 1 ∧ 1/2≤θ ∧ q^2/8≤θ*(1-θ) := by - have hq2 : q^2≤1/4 := by nlinarith [hq.1,hq.2] - have hs : 0 if initialCountAdmissible N q l then 0 else 1) ≤ - 2*Real.exp (-(N:ℝ)*q^4/64) := by - let p := 1-primitiveErasure q - have hp : p∈Set.Icc 0 1 := primitiveRetention_mem ⟨hq.1,by linarith [hq.2]⟩ - have ht : q^2/8∈Set.Icc (0:ℝ) 1 := ⟨by positivity,by nlinarith [hq.1,hq.2]⟩ - have H := binomialMass_abs_tail N (a:=(N:ℝ)*q^2/4) hp ht - have he : -(q^2/8)*((N:ℝ)*q^2/4)+(N:ℝ)*(q^2/8)^2= -(N:ℝ)*q^4/64 := by ring - rw [he] at H - apply le_trans _ H - rw [Finset.sum_filter,←Fin.sum_univ_eq_sum_range] - apply Finset.sum_le_sum - intro l _ - change binomialMass N p l.val*(if initialCountAdmissible N q l then 0 else 1)≤_ - have hn := binomialMass_nonneg N l.val hp - by_cases hl : initialCountAdmissible N q l - · rw [ite_eq_left hl,mul_zero] - split_ifs <;> positivity - · rw [ite_eq_right hl,mul_one,ite_eq_left] - exact le_of_not_gt (fun h => hl (initialCountAdmissible_of_near hq hscale l (by simpa [p,primitiveErasure] using h))) - -/-- The true bad metadata mass is charged without changing any conditional - law or requiring an unproved concentration conclusion. -/ -theorem initial_metadata_bad_mass {Side : Type*} [Fintype Side] {J N : ℕ} - (M : PairedMechanisms Side J) {q ω : ℝ} - (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hscale : 8≤(N:ℝ)*q^2) - (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : - (initialMetadataLaw M N ⟨hq.1,by linarith [hq.2]⟩).expect - (fun z => if initialMetadataGood q ω z then 0 else 1) ≤ - 2*Real.exp (-(N:ℝ)*q^4/64)+Real.exp (-(J:ℝ)*ω^4/16) := by - calc - _ ≤ (initialMetadataLaw M N ⟨hq.1,by linarith [hq.2]⟩).expect - (fun z => (if initialCountAdmissible N q z.2 then 0 else 1)+ - (if (PairedMechanisms.hiddenCount z.1:ℝ)<(J:ℝ)*ω^2/2 then 1 else 0)) := by - apply FiniteLaw.expect_mono - intro z - have he : (PairedMechanisms.hiddenCount z.1:ℝ)=∑i,(hiddenTrial (z.1 i).1:ℝ) := by - simp only [PairedMechanisms.hiddenCount,Nat.cast_sum] - unfold initialMetadataGood - rw [←he] - split_ifs <;> simp_all - _ ≤ _ := by - simp only [FiniteLaw.expect_add,initialMetadataLaw,FiniteLaw.expect_prod] - apply add_le_add - · exact (M.reports.expect_mono (fun _ => initial_count_bad_mass hq hscale)).trans (by rw [FiniteLaw.expect_const]) - · convert M.hiddenCount_small hw hp using 1 - congr 1 - funext a - split_ifs <;> simp [FiniteLaw.expect,FiniteLaw.total] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def initialSignedPatternCap (J u m r s : ℕ) (q ω : ℝ) (k : Fin r → GapDifference) : ℝ := - if ∃a,k=linearPattern a then - initialPrefactorCap u m r 1 q*periodCentralSumConstant u r*hiddenSignedL2Bound J s ω - else initialPrefactorCap u m r (∑h,(k h).order) q* - periodBoundedSumConstant u r (2*(2^s))*hiddenUnsignedL2Bound J s ω - -def initialPurePatternCap (J u m r s : ℕ) (q ω : ℝ) (k : Fin r → GapDifference) : ℝ := - if ∃a,k=linearPattern a then - initialPrefactorCap u m r 1 q*periodCentralSumConstant u r*hiddenSignedL2Bound J s ω - else initialPrefactorCap u m r (∑h,(k h).order) q* - periodCentralSumConstant u r*hiddenUnsignedL2Bound J s ω - -theorem initial_signed_pattern_cap {J : ℕ} (d : Fin J → Option Bool) (c : ℤ) - (u m r s : ℕ) (k : Fin r → GapDifference) {q θ ω : ℝ} - (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - signedPatternBound u m r s (posteriorAnchorSeries c d) θ k ≤ - initialSignedPatternCap J u m r s q ω k := by - unfold signedPatternBound initialSignedPatternCap - split_ifs - · apply mul_le_mul - · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r 1 hq hθ) - (by unfold periodCentralSumConstant; positivity) - · exact posteriorAnchorSeries_signed_L2 d c s ω hh - · exact seriesL2Sq_nonneg _ - · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) - · apply mul_le_mul - · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r _ hq hθ) - (by unfold periodBoundedSumConstant; positivity) - · exact posteriorAnchorSeries_unsigned_L2 d c s ω hh - · exact seriesL2Sq_nonneg _ - · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodBoundedSumConstant; positivity) - -theorem initial_pure_pattern_cap {J : ℕ} (d : Fin J → Option Bool) (c : ℤ) - (u m r s : ℕ) (k : Fin r → GapDifference) {q θ ω : ℝ} - (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - purePatternBound u m r s (posteriorAnchorSeries c d) θ k ≤ - initialPurePatternCap J u m r s q ω k := by - unfold purePatternBound initialPurePatternCap - split_ifs - · apply mul_le_mul - · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r 1 hq hθ) - (by unfold periodCentralSumConstant; positivity) - · exact posteriorAnchorSeries_signed_L2 d c s ω hh - · exact seriesL2Sq_nonneg _ - · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) - · apply mul_le_mul - · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r _ hq hθ) - (by unfold periodCentralSumConstant; positivity) - · exact posteriorAnchorSeries_unsigned_L2 d c s ω hh - · exact seriesL2Sq_nonneg _ - · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) - -def initialSignedDegreeCap (J u m r s : ℕ) (q ω : ℝ) : ℝ := - if r=0 then 0 else - 8*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference,if Odd (firstDifferenceCount k) then - initialSignedPatternCap J u m r s q ω k else 0)+initialRankTailCap u m r - -def initialPureDegreeCap (J u m r s : ℕ) (q ω : ℝ) : ℝ := - if r=0 then 0 else - 2*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference,if k=unchangedPattern r then 0 else - initialPurePatternCap J u m r s q ω k)+initialRankTailCap u m r - -theorem initial_signed_degree_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (r s : ℕ) - {q θ ω : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - signedInitialDegreeBound u m r s (posteriorAnchorSeries c d) θ l ≤ - initialSignedDegreeCap J u m r s q ω := by - unfold signedInitialDegreeBound initialSignedDegreeCap - split_ifs - · exact le_rfl - · apply add_le_add - · apply mul_le_mul_of_nonneg_left _ (by positivity) - apply Finset.sum_le_sum - intro k _ - split_ifs - · exact initial_signed_pattern_cap d c u m r s k hq hθ hh - · exact le_rfl - · exact initial_rank_tail_bound r (initial_theta_variance hq hθ).1 hl hmean hv - -theorem initial_pure_degree_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (r s : ℕ) - {q θ ω : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - initialPureDegreeBound u m r s (posteriorAnchorSeries c d) θ l ≤ - initialPureDegreeCap J u m r s q ω := by - unfold initialPureDegreeBound initialPureDegreeCap - split_ifs - · exact le_rfl - · apply add_le_add - · apply mul_le_mul_of_nonneg_left _ (by positivity) - apply Finset.sum_le_sum - intro k _ - split_ifs - · exact le_rfl - · exact initial_pure_pattern_cap d c u m r s k hq hθ hh - · exact initial_rank_tail_bound r (initial_theta_variance hq hθ).1 hl hmean hv - -/-- Scalar budgets independent of every actual report and count. The finite - signed-pattern restriction is retained to preserve its three-difference gain. -/ -def initialSignedCap (J u m R s : ℕ) (q ω w : ℝ) : ℝ := - (∑r∈Finset.range R,w^(2*r)*initialSignedDegreeCap J u m r s q ω)+ - 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) - -def initialPureCap (J u m R s : ℕ) (q ω w : ℝ) : ℝ := - (∑r∈Finset.range R,w^(2*r)*initialPureDegreeCap J u m r s q ω)+ - 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) - -theorem initial_signed_budget_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (R s : ℕ) - {q θ ω w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - initialSignedBudget u m l R s (posteriorAnchorSeries c d) θ q w ≤ - initialSignedCap J u m R s q ω w := by - unfold initialSignedBudget initialSignedCap - apply add_le_add _ le_rfl - apply Finset.sum_le_sum - intro r _ - exact mul_le_mul_of_nonneg_left (initial_signed_degree_cap d c r s hq hθ hl hmean hv hh) - (by rw [pow_mul]; positivity) - -theorem initial_pure_budget_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (R s : ℕ) - {q θ ω w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) - (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : - initialPureBudget u m l R s (posteriorAnchorSeries c d) θ q w ≤ - initialPureCap J u m R s q ω w := by - unfold initialPureBudget initialPureCap - apply add_le_add _ le_rfl - apply Finset.sum_le_sum - intro r _ - exact mul_le_mul_of_nonneg_left (initial_pure_degree_cap d c r s hq hθ hl hmean hv hh) - (by rw [pow_mul]; positivity) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def OracleTracePair.weaken {q E V E' V' : ℝ} {x y : List Bool} {k : ℕ} - (C : OracleTracePair q x y k E V) (hE : E ≤ E') (hV : V ≤ V') : - OracleTracePair q x y k E' V' := - { C with - first_simulation := fun F hF => (C.first_simulation F hF).trans hE - second_simulation := fun F hF => (C.second_simulation F hF).trans hE - moment := C.moment.trans hV } - -def initialErrorCap (J K m k : ℕ) (q ω w : ℝ) : ℝ := - Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ - (2*Real.exp (-((K*m:ℕ):ℝ)*q^4/64)+Real.exp (-(J:ℝ)*ω^4/16)) - -/-- Both required initial comparisons are genuine approximate complete-trace - oracles. The metadata budgets have been eliminated: only explicit finite - scalar bounds and literal period geometry remain to be instantiated. -/ -theorem actual_initial_oracles {J K m R : ℕ} - (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) (hR : 0 < R) - (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) - (a : ℤ) (s k : ℕ) (hk : 1 ≤ k) {q w V W : ℝ} - (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hseed : 16 ≤ q^3*(m:ℝ)) (hcount : 8 ≤ ((K*m:ℕ):ℝ)*q^2) - (ha : (J*initialSideCount q m+J:ℕ) ≤ a) - (ha' : a+(2^s:ℕ) ≤ (J*initialSideCount q m+K:ℕ)) - (hleft : (K:ℝ)/3 ≤ 2*((a-(J*initialSideCount q m:ℕ):ℤ)-J)+1) - (hright : (K:ℝ)/3 ≤ 2*K-(2*((a-(J*initialSideCount q m:ℕ):ℤ)+(2:ℝ)^s)+1)) - (hM : ((2*(2^s):ℕ):ℝ) < (K:ℝ)/(3*(R+1:ℝ))) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) - (hscale : initialMomentRatio K m q w ≤ 1/2) - (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) - (hV : 0 ≤ V) (hW : 0 ≤ W) - (hSV : 64*initialSignedCap J K m R s q (initialOverlapLower q) w ≤ V) - (hPW : 64*initialPureCap J K m R s q (initialOverlapLower q) w ≤ W) : - Nonempty (OracleTracePair q - (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a (-1)) - (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a 1) k - (initialErrorCap J K m k q (initialOverlapLower q) w) V) ∧ - Nonempty (OracleTracePair q - (pureAtomRun (initialPeriod m off.val) (J*(2*initialSideCount q m+1)+K)) - (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a 1) k - (initialErrorCap J K m k q (initialOverlapLower q) w) W) := by - let t := initialSideCount q m - let ω := initialOverlapLower q - let c : ℤ := a-(J*t:ℕ) - have hω : 0 < ω := initialOverlapLower_pos q - have hω1 : ω < 1/8 := initialOverlapLower_lt_eighth hq.1 - have hqi : q∈Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ - have hqc : q∈Set.Icc 0 1 := ⟨hq.1.le,hqi.2.le⟩ - let u := pureAtomRun (initialPeriod m off.val) t - let v := pureAtomRun (initialPeriod m off.val) (t+1) - let N := max u.length v.length - have hu : u.length ≤ N := le_max_left _ _ - have hv : v.length ≤ N := le_max_right _ _ - have hov : ω ≤ listTraceOverlap q hqc u v := initial_pure_trace_overlap hq (by omega) - hseed off (by linarith) - let M : PairedMechanisms (BoundedTrace N) J := tracePairedMechanisms hqc hω - (fun _ => u) (fun _ => v) N (fun _ => hu) (fun _ => hv) (fun _ => hov) - have hfirst (i : Fin J) : SimulatesTrace q (M.first i) Subtype.val u := - listTraceLaw_simulates q hqc u N hu - have hsecond (i : Fin J) : SimulatesTrace q (M.second i) Subtype.val v := - listTraceLaw_simulates q hqc v N hv - have htail := initial_metadata_bad_mass M hq hcount (fun _ => rfl) - (show ω^2∈Set.Icc (0:ℝ) 1 from ⟨sq_nonneg _,by nlinarith⟩) - have hsigned (z : InitialMetadata (BoundedTrace N) J (K*m)) - (hz : initialMetadataGood q ω z) : - 64*initialSignedBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) - ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V := by - apply le_trans _ hSV - apply mul_le_mul_of_nonneg_left _ (by norm_num) - exact initial_signed_budget_cap _ c R s hq hz.1.1 (by have H:=z.2.isLt; omega) - (mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0)))) - hz.1.2 hz.2 - have hpure (z : InitialMetadata (BoundedTrace N) J (K*m)) - (hz : initialMetadataGood q ω z) : - 64*initialPureBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) - ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ W := by - apply le_trans _ hPW - apply mul_le_mul_of_nonneg_left _ (by norm_num) - exact initial_pure_budget_cap _ c R s hq hz.1.1 (by have H:=z.2.isLt; omega) - (mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0)))) - hz.1.2 hz.2 - have hsim (τ : ℝ) := initial_sigma_simulates M t s a τ off hi hsafe hqi - Subtype.val hfirst hsecond ha ha' - have hp := initial_pure_sigma_simulates (K:=K) M t off hqi Subtype.val hfirst hsecond - obtain ⟨S⟩ := initial_sigma_clipped_exists M hK hm hKm hR off hi hoff hsafe c s k hk - hleft hright hq hM hw hscale hclip hV hsigned - obtain ⟨P⟩ := initial_pure_sigma_clipped_exists M hK hm hKm hR off hi hoff hsafe c s k hk - hleft hright hq hw hscale hclip hW hpure - constructor - · obtain ⟨O⟩ := S.tracePair (decodeInitialObservation Subtype.val) (hsim (-1)) (hsim 1) - exact ⟨O.weaken (add_le_add le_rfl htail) le_rfl⟩ - · obtain ⟨O⟩ := P.tracePair (decodeInitialObservation Subtype.val) hp (hsim 1) - exact ⟨O.weaken (add_le_add le_rfl htail) le_rfl⟩ - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.SourceOracle + +namespace OAI + +/-! +# InitialOracle + +Actual initial scores and anchors, count partitions and typicality, clipped metadata, common decoding, sharp hidden-count energy, tails, and budget caps. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +def initialMomentRatio (u m : ℕ) (q w : ℝ) : ℝ := + w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) + +def initialSignedBudget (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) : ℝ := + (∑r∈Finset.range R,w^(2*r)*signedInitialDegreeBound u m r s π θ l)+ + 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) + +theorem initialSignedBudget_nonneg (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) + (hq : 0 ≤ q) (ha : initialMomentRatio u m q w < 1) : + 0 ≤ initialSignedBudget u m l R s π θ q w := by + apply add_nonneg + · exact Finset.sum_nonneg (fun r _ => mul_nonneg (by rw [pow_mul]; positivity) + (signedInitialDegreeBound_nonneg _ _ _ _ _ _ _)) + · apply div_nonneg _ (sub_nonneg.mpr ha.le) + exact mul_nonneg (by norm_num) (pow_nonneg (by unfold initialMomentRatio; positivity [rankSchurConstant_pos]) _) + +/-- The signed score numerator in the *actual conditional mark-list laws*, + with the entire finite cancellation energy and geometric tail retained. -/ +theorem initial_signed_moment {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : + ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq + (fun x => initialMotifDensity hl off hsafe π s 1 q x-initialMotifDensity hl off hsafe π s (-1) q x) k ≤ + initialSignedBudget u m l R s π θ q w := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + have he : (fun x => initialMotifDensity hl off hsafe π s 1 q x-initialMotifDensity hl off hsafe π s (-1) q x)= + multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-mixedMotifCoefficient hl off hsafe π s (-1) σ) + (primitiveScore q) := by funext x; exact (multilinear_sub _ _ _ _).symm + rw [he] + apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk + (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans + rw [←hw] + exact signed_initial_full_energy hu hm hum hR hl off hi hoff hsafe π hπ hπsum s hcentral hq hθ hmean hv hM + (by rw [hw]; positivity [hq.1]) ha + +/-- Quantitative normalized common clipping of the level-zero conditional + pair. This theorem has only the literal count/geometric inequalities of the + initial construction, not a signed-density or oracle conclusion premise. -/ +theorem initial_conditional_clipped_exists {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (hscale : initialMomentRatio u m q w ≤ 1/2) + (hclip : Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k) ≤ 1/2) : + Nonempty (ClippedOracle + (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s (-1)) + (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s 1) k + (Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k)) + (64*initialSignedBudget u m l R s π θ q w)) := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + let A := (primitiveMarkLaw q hq' false).product l + let f := initialMotifDensity hl off hsafe π s (-1) q + let g := initialMotifDensity hl off hsafe π s 1 q + let U := initialMomentRatio u m q w/(1-initialMomentRatio u m q w) + have ha : initialMomentRatio u m q w < 1 := by linarith + have hz : 0 ≤ initialMomentRatio u m q w := by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1] + have hU : 0 ≤ U := div_nonneg hz (sub_nonneg.mpr ha.le) + have hU1 : U ≤ 1 := (div_le_iff₀ (sub_pos.mpr ha)).mpr (by linarith) + have hmom (τ : ℝ) : A.expect (fun x => |initialMotifDensity hl off hsafe π s τ q x-1|^(2*k)) ≤ U^k := + A.expect_even_pow_le_of_moment _ k hk (initial_centered_moment hl (by omega) hum off hi hoff hsafe π hπ hπsum s k hk τ hq hθ hmean hv hw ha) + have hV := initialSignedBudget_nonneg u m l R s π θ q w hq.1.le ha + have hsig := A.expect_even_pow_le_of_moment _ k hk + (initial_signed_moment hu hm hum hR hl off hi hoff hsafe π hπ hπsum s k hcentral hk hq hθ hmean hv hM hw ha) + rw [initialMotifLaw_withDensity hl off hsafe π hπ hπsum s (-1) hq', + initialMotifLaw_withDensity hl off hsafe π hπ hπsum s 1 hq'] + have H := A.exists_clippedOracle f g + (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s (-1) hq') + (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s 1 hq') + (initialMotifDensity_mean hl off hsafe π hπ hπsum s (-1) hq') + (initialMotifDensity_mean hl off hsafe π hπ hπsum s 1 hq') + Finset.univ 0 (by simp [eventMass]) (by simp [eventMass]) k hk U hU hU1 (hmom (-1)) (hmom 1) + (initialSignedBudget u m l R s π θ q w) hV (by simpa only [Finset.mem_univ,ite_true] using hsig) + (by simpa only [zero_add] using hclip) + simpa only [zero_add] using H + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +theorem evenMomentSq_le_of_expect (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) + {V : ℝ} (hV : 0≤V) (h : P.expect (fun a => |F a|^(2*k))≤V^k) : + P.evenMomentSq F k≤V := by + have H := Real.rpow_le_rpow (P.expect_nonneg _ (fun _ => by positivity)) h (by positivity : 0≤(k:ℝ)⁻¹) + rw [Real.pow_rpow_inv_natCast hV (by omega)] at H + simpa only [FiniteLaw.evenMomentSq,one_div] using H + +theorem tv_sigma_eq {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] + (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) : + (M.sigma P).tv (M.sigma Q)=M.expect (fun i => (P i).tv (Q i)) := by + simp only [tv,sigma,expect,Fintype.sum_sigma,←mul_sub,abs_mul,abs_of_nonneg (M.nonneg _)] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [←Finset.mul_sum] + ring + +end FiniteLaw +namespace ClippedOracle +variable {α : Type*} [Fintype α] {P Q : FiniteLaw α} {k : ℕ} {e V E W : ℝ} + +def weaken (C : ClippedOracle P Q k e V) (he : e≤E) (hV : V≤W) : ClippedOracle P Q k E W where + first := C.first + second := C.second + score := C.score + density := C.density + likelihood_nonneg := C.likelihood_nonneg + centered := C.centered + moment := C.moment.trans hV + first_tv := C.first_tv.trans he + second_tv := C.second_tv.trans he + +def trivial (P Q : FiniteLaw α) (k : ℕ) (hk : 1≤k) : ClippedOracle P Q k 1 0 where + first := P + second := P + score := fun _ => 0 + density := fun _ => by ring + likelihood_nonneg := fun _ => by norm_num + centered := by simp [FiniteLaw.expect] + moment := by + apply P.evenMomentSq_le_of_expect _ k hk (by norm_num) + simp [FiniteLaw.expect,zero_pow (by omega : 2*k≠0)] + first_tv := by simp [FiniteLaw.tv] + second_tv := FiniteLaw.tv_le_one _ _ + +/-- Reported metadata is retained, so the squared moment of a normalized + score assembles without a mixing penalty. No conditioning of the original + latent metadata distribution occurs. -/ +def sigma {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] + (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) (e : ι → ℝ) + (k : ℕ) (hk : 1≤k) (V : ℝ) (hV : 0≤V) + (C : ∀i,ClippedOracle (P i) (Q i) k (e i) V) : + ClippedOracle (M.sigma P) (M.sigma Q) k (M.expect e) V where + first := M.sigma (fun i => (C i).first) + second := M.sigma (fun i => (C i).second) + score := fun a => (C a.1).score a.2 + density := fun a => by dsimp only [FiniteLaw.sigma]; rw [(C a.1).density]; ring + likelihood_nonneg := fun a => (C a.1).likelihood_nonneg a.2 + centered := by + rw [FiniteLaw.expect_sigma] + simp_rw [(C _).centered] + simp [FiniteLaw.expect] + moment := by + apply FiniteLaw.evenMomentSq_le_of_expect _ _ k hk hV + rw [FiniteLaw.expect_sigma] + calc + _ ≤ M.expect (fun _ => V^k) := M.expect_mono (fun i => + (C i).first.expect_even_pow_le_of_moment _ k hk (C i).moment) + _ = _ := M.expect_const _ + first_tv := by + rw [FiniteLaw.tv_sigma_eq] + exact M.expect_mono (fun i => (C i).first_tv) + second_tv := by + rw [FiniteLaw.tv_sigma_eq] + exact M.expect_mono (fun i => (C i).second_tv) + +/-- Replace bad conditional observations by a common law rather than making + the original metadata law conditional on typicality. The exact cost is + the true metadata failure mass plus the good conditional clipping cost. -/ +theorem assemble_good {ι : Type*} [Fintype ι] {β : ι → Type*} [∀i,Fintype (β i)] + (M : FiniteLaw ι) (P Q : ∀i,FiniteLaw (β i)) (Good : ι → Prop) + (k : ℕ) (hk : 1≤k) (e V : ℝ) (he : 0≤e) (hV : 0≤V) + (C : ∀i,Good i → Nonempty (ClippedOracle (P i) (Q i) k e V)) : + Nonempty (ClippedOracle (M.sigma P) (M.sigma Q) k + (e+M.expect (fun i => if Good i then 0 else 1)) V) := by + let err := fun i => if Good i then e else 1 + have hi (i) : Nonempty (ClippedOracle (P i) (Q i) k (err i) V) := by + by_cases h : Good i + · simpa only [err,ite_eq_left h] using C i h + · exact ⟨(trivial (P i) (Q i) k hk).weaken (by simp [err,h]) hV⟩ + let D := sigma M P Q err k hk V hV (fun i => Classical.choice (hi i)) + refine ⟨D.weaken ?_ le_rfl⟩ + calc + M.expect err ≤ M.expect (fun i => e+(if Good i then 0 else 1)) := M.expect_mono (fun i => by + dsimp only [err]; split_ifs <;> linarith) + _ = _ := by rw [M.expect_add,M.expect_const] + +end ClippedOracle +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +theorem translated_fair_eval (g : ℕ) (c : ℤ) (F : ℤ → ℝ) : + (∑X∈(translateSeries c (fairSeries g)).coeff.support, + (translateSeries c (fairSeries g)).coeff X*F X)= + ∑k∈Finset.range (g+1),fairBinomial g k*F (c+k) := by + have H := congrArg (fun p : IntSeries => Finsupp.linearCombination ℝ F p.coeff) + (congrArg (translateSeries c) (fairSeries_sum g)) + simp only [translateSeries,Finset.mul_sum,AddMonoidAlgebra.single_mul_single,one_mul, + AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, + Finsupp.linearCombination_single,smul_eq_mul] at H + exact H + +/-- The literal initial anchor after conditioning the paired side outputs. -/ +def posteriorAnchorSeries {ι : Type*} [Fintype ι] (c : ℤ) (d : ι → Option Bool) : IntSeries := + translateSeries (c-(∑i,(visibleOnes (d i):ℤ))-(∑i,hiddenTrial (d i))) + (fairSeries (∑i,hiddenTrial (d i))) + +theorem posterior_anchor_average {ι : Type*} [Fintype ι] + (c : ℤ) (d : ι → Option Bool) (F : ℤ → ℝ) : + (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i))* + F (c-∑i,(bitIndex (b i):ℤ)))= + ∑X∈(posteriorAnchorSeries c d).coeff.support,(posteriorAnchorSeries c d).coeff X*F X := by + rw [posterior_count_average_reflected d (fun z => F (c-z)),posteriorAnchorSeries,translated_fair_eval] + apply Finset.sum_congr rfl + intro k _ + congr 2 + ring + +theorem posteriorAnchorSeries_nonneg {ι : Type*} [Fintype ι] + (c : ℤ) (d : ι → Option Bool) (X : ℤ) : 0 ≤ (posteriorAnchorSeries c d).coeff X := + translated_binomial_nonneg _ _ _ + +theorem posteriorAnchorSeries_total {ι : Type*} [Fintype ι] + (c : ℤ) (d : ι → Option Bool) : + ∑X∈(posteriorAnchorSeries c d).coeff.support,(posteriorAnchorSeries c d).coeff X=1 := by + have H := posterior_anchor_average c d (fun _ => 1) + simp only [mul_one] at H + rw [←H] + exact (FiniteLaw.indexedProduct (fun i => flagPosterior (d i))).total + +theorem posteriorAnchorSeries_support {ι : Type*} [Fintype ι] + (c : ℤ) (d : ι → Option Bool) (X : ℤ) (hX : X∈(posteriorAnchorSeries c d).coeff.support) : + c-Fintype.card ι ≤ X ∧ X ≤ c := by + have H := translated_binomial_support (∑i,hiddenTrial (d i)) + (c-(∑i,(visibleOnes (d i):ℤ))-(∑i,hiddenTrial (d i))) X + (Finsupp.mem_support_iff.mp hX) + have hz : 0 ≤ ∑i,(visibleOnes (d i):ℤ) := Finset.sum_nonneg (fun _ _ => by positivity) + have hh : (∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i)) ≤ Fintype.card ι := by + rw [Nat.cast_sum,←Finset.sum_add_distrib] + calc + _ ≤ ∑_i : ι,(1:ℤ) := Finset.sum_le_sum (fun i _ => by + cases h:d i with + | none => simp [visibleOnes,hiddenTrial] + | some b => cases b <;> simp [visibleOnes,hiddenTrial]) + _ = _ := by simp + omega + +theorem posteriorAnchorSeries_central {ι : Type*} [Fintype ι] + (u s : ℕ) (c : ℤ) (d : ι → Option Bool) + (hleft : (u:ℝ)/3 ≤ 2*((c:ℝ)-Fintype.card ι)+1) + (hright : (u:ℝ)/3 ≤ 2*u-(2*((c:ℝ)+(2:ℝ)^s)+1)) : + CentralMotifSupport u s (posteriorAnchorSeries c d) := by + intro X hX + have H := posteriorAnchorSeries_support c d X hX + have H₁ : (c:ℝ)-Fintype.card ι ≤ X := by exact_mod_cast H.1 + have H₂ : (X:ℝ) ≤ c := by exact_mod_cast H.2 + constructor <;> linarith + +namespace PairedMechanisms +variable {Side α : Type*} [Fintype Side] [Fintype α] {J : ℕ} + +def emissionOracle (M : PairedMechanisms Side J) (K : (Fin J → Bool) → FiniteLaw α) : + FiniteLaw (Reports Side J × α) := + M.reports.joint (fun z => (orientationsGiven z).mixture K) + +/-- Bayes factorization is valid for arbitrary conditional finite emissions, + including the dependent-length initial primitive-mark list. -/ +theorem emission_factorization (M : PairedMechanisms Side J) (K : (Fin J → Bool) → FiniteLaw α) : + (fairOrientations J).mixture (fun b => (M.reportsGiven b).prod (K b))=M.emissionOracle K := by + apply FiniteLaw.ext + funext zx + rcases zx with ⟨z,x⟩ + change (∑b,(∏i : Fin J,(1/2:ℝ))* + ((∏i,FiniteLaw.pairedFlagMass (M.first i) (M.second i) (M.common i) + (M.hiddenWeight i) (b i) (z i))*(K b).mass x))= + (∏i,FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) + (M.hiddenWeight i) (z i))*(∑b,(∏i,(flagPosterior (z i).1).mass (b i))*(K b).mass x) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro b _ + rw [←mul_assoc,←Finset.prod_mul_distrib,FiniteLaw.pairedFlags_product_bayes,mul_assoc] + +end PairedMechanisms + +theorem conditionalMotifLaw_posterior {u m l J : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (d : Fin J → Option Bool) (s : ℕ) (τ : ℝ) : + (FiniteLaw.coordinateProduct (fun i => flagPosterior (d i))).mixture + (fun b => conditionalPrimitiveLaw hl q hq + (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= + conditionalMotifLaw hl off hsafe hq (posteriorAnchorSeries c d) + (posteriorAnchorSeries_nonneg c d) (posteriorAnchorSeries_total c d) s τ := by + apply FiniteLaw.ext + funext x + change (∑b : Fin J → Bool,(∏i : Fin J,(flagPosterior (d i)).mass (b i))* + (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s + (c-∑i,(bitIndex (b i):ℤ)) τ))).mass x)=_ + classical + have H := posterior_anchor_average c d (fun X => + (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X τ))).mass x) + calc + _ = ∑X∈(posteriorAnchorSeries c d).coeff.support, + (posteriorAnchorSeries c d).coeff X* + (conditionalPrimitiveLaw hl q hq (defectTypes (signedPeriodDefects off hsafe s X τ))).mass x := by + convert H using 1 + congr 1 + ext b + simp + _ = _ := (Finset.sum_coe_sort _ _).symm + + +/-- Initial observations retain the central count with its original binomial law. -/ +def countedMotifLaw {u m : ℕ} (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) + (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (τ : ℝ) : + FiniteLaw (BoundedMarks (u*m)) := + (boundedCountLaw (le_refl (u*m)) (1-primitiveErasure q) (primitiveRetention_mem hq)).sigma + (fun l => conditionalMotifLaw (by omega) off hsafe hq π hπ hπsum s τ) + +theorem countedMotifLaw_posterior {u m J : ℕ} (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (d : Fin J → Option Bool) (s : ℕ) (τ : ℝ) : + (FiniteLaw.coordinateProduct (fun i => flagPosterior (d i))).mixture + (fun b => countedPrimitiveLaw (le_refl (u*m)) hq + (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= + countedMotifLaw off hsafe hq (posteriorAnchorSeries c d) + (posteriorAnchorSeries_nonneg c d) (posteriorAnchorSeries_total c d) s τ := by + apply FiniteLaw.ext + funext x + rcases x with ⟨l,x⟩ + have hl : l.val ≤ u*m := by omega + have H := congrArg (fun P : FiniteLaw (Fin l.val → PrimitiveMark) => P.mass x) + (conditionalMotifLaw_posterior hl off hsafe hq c d s τ) + change (∑b, _ * ((boundedCountLaw _ _ _).mass l * + (boundedConditionalPrimitiveLaw hq _ l).mass x))=_ + simp only [boundedConditionalPrimitiveLaw,dite_eq_left hl] + change _ = (boundedCountLaw _ _ _).mass l * _ + rw [←H] + simp only [FiniteLaw.mixture,Finset.mul_sum] + apply Finset.sum_congr rfl + intro b _ + ring + + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The actual displaced primitive slot in a period. -/ +def motifOffset {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (s : ℕ) (X : ℤ) (τ : ℝ) (j : ℤ) : Fin m := + ⟨off.val+(motifShift (motifIndicator s (j-X)) ((prouhetSeries s).coeff (j-X)) τ).val-1, by + have H := (motifShift (motifIndicator s (j-X)) ((prouhetSeries s).coeff (j-X)) τ).isLt + omega⟩ + +theorem signedPeriodDefects_periodSlot {u m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (s : ℕ) (X : ℤ) (τ : ℝ) : + signedPeriodDefects off hsafe s X τ = + periodSlot (fun j => motifOffset off hi s X τ j.val) := by + funext j + apply Fin.ext + simp only [signedPeriodDefects,shiftedTag,periodSlot,motifOffset] + omega + +def motifPeriodWord {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (u s : ℕ) (X : ℤ) (τ : ℝ) : List Bool := + periodString m u (fun j => motifOffset off hi s X τ j.val) + +theorem signed_primitive_word {u m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (s : ℕ) (X : ℤ) (τ : ℝ) : + (((List.ofFn (defectTypes (signedPeriodDefects off hsafe s X τ))).map primitiveBlock).flatten)= + motifPeriodWord off hi u s X τ := by + rw [signedPeriodDefects_periodSlot off hi,periodic_primitive_word] + rfl + +theorem motifOffset_outside {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (s : ℕ) (X : ℤ) (τ : ℝ) (j : ℤ) (hj : j off ⟨i.val,by omega⟩) ++ + periodString m k (fun i => off ⟨n+i.val,by omega⟩) ++ + periodString m z (fun i => off ⟨n+k+i.val,by omega⟩) := by + simp only [periodString,List.ofFn_add,List.flatten_append] + rfl + +/-- Every randomized initial partition is a partition of the same literal +period string, with no fit conditioning or change of channel. -/ +theorem motifPeriodWord_window {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (t K z s : ℕ) (a : ℤ) (τ : ℝ) (hleft : (t:ℤ) ≤ a) (hright : a+(2^s:ℕ) ≤ t+K) : + motifPeriodWord off hi (t+K+z) s a τ = + pureAtomRun (initialPeriod m off.val) t ++ motifPeriodWord off hi K s (a-t) τ ++ + pureAtomRun (initialPeriod m off.val) z := by + unfold motifPeriodWord + rw [periodString_three] + congr 2 + · rw [←periodString_constant off] + congr 1 + funext i + exact motifOffset_outside off hi s a τ i.val (Or.inl (by have H:=i.isLt; omega)) + · congr 1 + funext i + rw [Nat.cast_add,motifOffset_translate] + · rw [←periodString_constant off] + congr 1 + funext i + exact motifOffset_outside off hi s a τ (t+K+i.val) (Or.inr (by + have H : (0:ℤ) ≤ i.val := by positivity + omega)) + +theorem motifPeriodWord_length {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (u s : ℕ) (X : ℤ) (τ : ℝ) : + (motifPeriodWord off hi u s X τ).length=u*(2*m-1) := periodString_length _ _ _ + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +theorem coordinateProduct_expect_pairs {n : ℕ} (P : Fin n → FiniteLaw α) + (Q : Fin n → FiniteLaw β) (F : (Fin n → α×β) → ℝ) : + (coordinateProduct (fun i => (P i).prod (Q i))).expect F= + (coordinateProduct P).expect (fun a => + (coordinateProduct Q).expect (fun b => F (fun i => (a i,b i)))) := by + induction n with + | zero => + have H (a : Fin 0 → α×β) : a = fun i => Fin.elim0 i := by funext i; exact Fin.elim0 i + have hF : F=fun _ => F (fun i => Fin.elim0 i) := by + funext a + exact congrArg F (H a) + rw [hF] + simp only [expect_const] + | succ n ih => + rw [expect_coordinateProduct_succ,expect_prod,expect_coordinateProduct_succ] + congr 1 + funext a + simp_rw [ih,expect_coordinateProduct_succ Q] + rw [expect_comm] + congr 1 + funext x + congr 1 + funext b + congr 1 + funext y + congr 1 + funext i + refine Fin.cases ?_ (fun j => ?_) i <;> simp + +end FiniteLaw + +/-- Three chronological streams, with side pairs independent across slots. +This forgets flags but does not separate any marks inside the central list. -/ +def decodePairedEmission {Side α : Type*} {J : ℕ} + (side : Side → List Bool) (central : α → List Bool) (z : Reports Side J × α) : List Bool := + coordinateWord (fun i => side (z.1 i).2.1) ++ central z.2 ++ + coordinateWord (fun i => side (z.1 i).2.2) + +namespace PairedMechanisms +variable {Side α : Type*} [Fintype Side] [Fintype α] {J : ℕ} + +theorem reportsGiven_paired_simulates (M : PairedMechanisms Side J) (b : Fin J → Bool) + {q : ℝ} (side : Side → List Bool) (central : α → List Bool) (K : FiniteLaw α) + (U V : Fin J → List Bool) (w : List Bool) + (hfirst : ∀i,SimulatesTrace q (M.first i) side (U i)) + (hsecond : ∀i,SimulatesTrace q (M.second i) side (V i)) + (hK : SimulatesTrace q K central w) : + SimulatesTrace q ((M.reportsGiven b).prod K) (decodePairedEmission side central) + (coordinateWord (fun i => if b i then V i else U i) ++ w ++ + coordinateWord (fun i => if b i then U i else V i)) := by + let P : Fin J → FiniteLaw Side := fun i => if b i then M.second i else M.first i + let Q : Fin J → FiniteLaw Side := fun i => if b i then M.first i else M.second i + have HP : ∀i,SimulatesTrace q (P i) side (if b i then V i else U i) := by + intro i + dsimp [P] + cases h:b i + · exact hfirst i + · exact hsecond i + have HQ : ∀i,SimulatesTrace q (Q i) side (if b i then U i else V i) := by + intro i + dsimp [Q] + cases h:b i + · exact hsecond i + · exact hfirst i + have H := ((coordinateProduct_simulates P side _ HP).append hK).append + (coordinateProduct_simulates Q side _ HQ) + intro F + rw [←H F,FiniteLaw.expect_prod,FiniteLaw.expect_prod] + change (M.reportsGiven b).expect (fun z => K.expect (fun x => + F (coordinateWord (fun i => side (z i).2.1) ++ central x ++ + coordinateWord (fun i => side (z i).2.2))))=_ + have hf := congrArg (fun L : FiniteLaw (Fin J → Side×Side) => L.expect (fun z => + K.expect (fun x => F (coordinateWord (fun i => side (z i).1) ++ central x ++ + coordinateWord (fun i => side (z i).2))))) (M.reportsGiven_forget b) + rw [FiniteLaw.expect_map] at hf + simp only [Function.comp_def] at hf + rw [hf] + have he : (fun i => FiniteLaw.orientedProd (M.first i) (M.second i) (b i))= + fun i => (P i).prod (Q i) := by + funext i + cases h:b i <;> simp [FiniteLaw.orientedProd,P,Q,h] + rw [he,FiniteLaw.coordinateProduct_expect_pairs] + simp only [FiniteLaw.expect_prod] + congr 1 + funext a + rw [FiniteLaw.expect_comm] + +end PairedMechanisms +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Exact initial paired prefix and complementary suffix sizes. -/ +def initialPrefixPeriods {J : ℕ} (k : ℕ) (b : Fin J → Bool) : ℕ := + ∑ i : Fin J, (k+bitIndex (b i)) +def initialSuffixPeriods {J : ℕ} (k : ℕ) (b : Fin J → Bool) : ℕ := + ∑ i : Fin J, (k+(1-bitIndex (b i))) + +theorem initialPrefixPeriods_eval {J : ℕ} (k : ℕ) (b : Fin J → Bool) : + initialPrefixPeriods k b=J*k+∑i,bitIndex (b i) := by + simp [initialPrefixPeriods,Finset.sum_add_distrib] + +theorem initialPairPeriods_total {J : ℕ} (k : ℕ) (b : Fin J → Bool) : + initialPrefixPeriods k b+initialSuffixPeriods k b=J*(2*k+1) := by + unfold initialPrefixPeriods initialSuffixPeriods + rw [←Finset.sum_add_distrib] + have H (i : Fin J) : (k+bitIndex (b i))+(k+(1-bitIndex (b i)))=2*k+1 := by + cases h:b i <;> simp [bitIndex] <;> omega + simp only [H,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Nat.cast_id] + +theorem initialPrefixPeriods_bounds {J : ℕ} (k : ℕ) (b : Fin J → Bool) : + J*k ≤ initialPrefixPeriods k b ∧ initialPrefixPeriods k b ≤ J*k+J := by + rw [initialPrefixPeriods_eval] + have H : (∑i,bitIndex (b i)) ≤ J := by + calc + _ ≤ ∑_i : Fin J,1 := Finset.sum_le_sum (fun i _ => by cases b i <;> simp [bitIndex]) + _ = _ := by simp + omega + +theorem initial_paired_oracle_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (k s : ℕ) (a : ℤ) (τ : ℝ) + (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) + (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) + (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) + (ha : (J*k+J:ℕ) ≤ a) (ha' : a+(2^s:ℕ) ≤ (J*k+K:ℕ)) : + SimulatesTrace q + (M.emissionOracle (fun b => countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (signedPeriodDefects off hsafe s + (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)))) + (decodePairedEmission side decodeBoundedMarks) + (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) := by + rw [←M.emission_factorization] + intro F + rw [FiniteLaw.expect_mixture] + have H (b : Fin J → Bool) : + ((M.reportsGiven b).prod (countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (signedPeriodDefects off hsafe s + (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)))).expect + (fun z => F (decodePairedEmission side decodeBoundedMarks z))= + listDeletionExpectation q (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) F := by + let t := initialPrefixPeriods k b + let z := initialSuffixPeriods k b + have ht := initialPrefixPeriods_bounds k b + have htot : t+K+z=J*(2*k+1)+K := by + have H:=initialPairPeriods_total k b + dsimp [t,z] + omega + have hanchor : a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)=a-t := by + dsimp [t] + rw [initialPrefixPeriods_eval] + push_cast + ring + have hleft : (t:ℤ) ≤ a := by + have H : (t:ℤ) ≤ (J*k+J:ℕ) := by exact_mod_cast ht.2 + omega + have hright : a+(2^s:ℕ) ≤ (t:ℤ)+K := by + have H : ((J*k:ℕ):ℤ) ≤ t := by exact_mod_cast ht.1 + simp only [Nat.cast_add] at ha' + omega + have hp : coordinateWord (fun i => if b i then + pureAtomRun (initialPeriod m off.val) (k+1) else pureAtomRun (initialPeriod m off.val) k)= + pureAtomRun (initialPeriod m off.val) t := by + have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) (k+1) else + pureAtomRun (initialPeriod m off.val) k)=pureAtomRun (initialPeriod m off.val) (k+bitIndex (b i)) := by + cases b i <;> simp [bitIndex] + simp_rw [h] + exact coordinateWord_pureAtomRun _ _ + have hz : coordinateWord (fun i => if b i then + pureAtomRun (initialPeriod m off.val) k else pureAtomRun (initialPeriod m off.val) (k+1))= + pureAtomRun (initialPeriod m off.val) z := by + have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) k else + pureAtomRun (initialPeriod m off.val) (k+1))=pureAtomRun (initialPeriod m off.val) (k+(1-bitIndex (b i))) := by + cases b i <;> simp [bitIndex] + simp_rw [h] + exact coordinateWord_pureAtomRun _ _ + have hc := countedPrimitiveLaw_simulates (le_refl (K*m)) hq + (defectTypes (signedPeriodDefects off hsafe s (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ)) + rw [signed_primitive_word off hi] at hc + have hs := M.reportsGiven_paired_simulates b side decodeBoundedMarks _ + (fun _ => pureAtomRun (initialPeriod m off.val) k) + (fun _ => pureAtomRun (initialPeriod m off.val) (k+1)) _ hfirst hsecond hc + have hword : coordinateWord (fun i => if b i then + pureAtomRun (initialPeriod m off.val) (k+1) else pureAtomRun (initialPeriod m off.val) k) ++ + motifPeriodWord off hi K s (a-(J*k:ℕ)-∑i,(bitIndex (b i):ℤ)) τ ++ + coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) k else + pureAtomRun (initialPeriod m off.val) (k+1))= + motifPeriodWord off hi (J*(2*k+1)+K) s a τ := by + rw [hp,hz,hanchor,←motifPeriodWord_window off hi t K z s a τ hleft hright,htot] + rw [hword] at hs + exact hs F + simp only [H,FiniteLaw.expect_const] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +abbrev InitialMetadata (Side : Type*) (J N : ℕ) := Reports Side J × Fin (N+1) +abbrev InitialObservation (Side : Type*) (J N : ℕ) := + Σz : InitialMetadata Side J N, Fin z.2.val → PrimitiveMark + +def initialMetadataLaw {Side : Type*} [Fintype Side] {J : ℕ} + (M : PairedMechanisms Side J) (N : ℕ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : + FiniteLaw (InitialMetadata Side J N) := + M.reports.prod (boundedCountLaw (le_refl N) (1-primitiveErasure q) (primitiveRetention_mem hq)) + +def initialConditionalLaw {Side : Type*} [Fintype Side] {J K m : ℕ} + (off : Fin m) (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) + (z : InitialMetadata Side J (K*m)) : FiniteLaw (Fin z.2.val → PrimitiveMark) := + conditionalMotifLaw (by have H:=z.2.isLt; omega) off hsafe hq + (posteriorAnchorSeries c (fun i => (z.1 i).1)) + (posteriorAnchorSeries_nonneg c _) (posteriorAnchorSeries_total c _) s τ + +def initialSigmaLaw {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) : + FiniteLaw (InitialObservation Side J (K*m)) := + (initialMetadataLaw M (K*m) hq).sigma (initialConditionalLaw off hsafe hq c s τ) + +def decodeInitialObservation {Side : Type*} {J N : ℕ} (side : Side → List Bool) + (z : InitialObservation Side J N) : List Bool := + decodePairedEmission side decodeBoundedMarks (z.1.1,⟨z.1.2,z.2⟩) + +theorem initialSigmaLaw_expect {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (c : ℤ) (s : ℕ) (τ : ℝ) + (F : Reports Side J × BoundedMarks (K*m) → ℝ) : + (initialSigmaLaw M off hsafe hq c s τ).expect (fun z => F (z.1.1,⟨z.1.2,z.2⟩))= + (M.emissionOracle (fun b => countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))).expect F := by + unfold PairedMechanisms.emissionOracle + rw [FiniteLaw.expect_joint] + have H (z : Reports Side J) : (PairedMechanisms.orientationsGiven z).mixture + (fun b => countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (signedPeriodDefects off hsafe s (c-∑i,(bitIndex (b i):ℤ)) τ)))= + countedMotifLaw off hsafe hq (posteriorAnchorSeries c (fun i => (z i).1)) + (posteriorAnchorSeries_nonneg c _) (posteriorAnchorSeries_total c _) s τ := + countedMotifLaw_posterior off hsafe hq c (fun i => (z i).1) s τ + simp_rw [H] + simp only [initialSigmaLaw,initialMetadataLaw,FiniteLaw.expect_sigma,FiniteLaw.expect_prod, + countedMotifLaw,initialConditionalLaw] + +theorem initial_sigma_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (k s : ℕ) (a : ℤ) (τ : ℝ) + (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) + (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) + (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) + (ha : (J*k+J:ℕ) ≤ a) (ha' : a+(2^s:ℕ) ≤ (J*k+K:ℕ)) : + SimulatesTrace q (initialSigmaLaw M off hsafe hq (a-(J*k:ℕ)) s τ) + (decodeInitialObservation side) (motifPeriodWord off hi (J*(2*k+1)+K) s a τ) := by + intro F + unfold decodeInitialObservation + rw [initialSigmaLaw_expect M off hsafe hq (a-(J*k:ℕ)) s τ (fun z => F (decodePairedEmission side decodeBoundedMarks z))] + exact initial_paired_oracle_simulates M k s a τ off hi hsafe hq side hfirst hsecond ha ha' F + +/-- This is the literal count-typicality condition; it does not change the + central count's original binomial law. -/ +def initialCountAdmissible (N : ℕ) (q : ℝ) (l : Fin (N+1)) : Prop := + (l.val:ℝ)/(N:ℝ)∈Set.Icc (1-q^2) (1-q^2/4) ∧ + 1 ≤ (N:ℝ)*((l.val:ℝ)/(N:ℝ))*(1-(l.val:ℝ)/(N:ℝ)) + +def initialMetadataGood {Side : Type*} {J N : ℕ} (q ω : ℝ) + (z : InitialMetadata Side J N) : Prop := + initialCountAdmissible N q z.2 ∧ (J:ℝ)*ω^2/2 ≤ ∑i,(hiddenTrial (z.1 i).1:ℝ) + +/-- The genuine initial metadata oracle is clipped by conditioning each + admissible fiber only. Every bad report/count keeps its original mass and + is replaced by a common law, so all discarded mass is charged. -/ +theorem initial_sigma_clipped_exists {Side : Type*} [Fintype Side] {J K m R : ℕ} + (M : PairedMechanisms Side J) (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) + (hR : 0 < R) (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + (c : ℤ) (s k : ℕ) (hk : 1 ≤ k) + (hleft : (K:ℝ)/3 ≤ 2*((c:ℝ)-J)+1) + (hright : (K:ℝ)/3 ≤ 2*K-(2*((c:ℝ)+(2:ℝ)^s)+1)) + {q ω w V : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hM : ((2*(2^s):ℕ):ℝ) < (K:ℝ)/(3*(R+1:ℝ))) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) + (hscale : initialMomentRatio K m q w ≤ 1/2) + (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) + (hV : 0 ≤ V) + (hbudget : ∀z : InitialMetadata Side J (K*m),initialMetadataGood q ω z → + 64*initialSignedBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) + ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V) : + Nonempty (ClippedOracle + (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s (-1)) + (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s 1) k + (Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ + (initialMetadataLaw M (K*m) ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩).expect + (fun z => if initialMetadataGood q ω z then 0 else 1)) V) := by + apply ClippedOracle.assemble_good _ _ _ (initialMetadataGood q ω) k hk _ V (Real.sqrt_nonneg _) hV + intro z hz + have hmean : ((K*m:ℕ):ℝ)*((z.2.val:ℝ)/(K*m:ℕ))=z.2.val := by + exact mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0))) + have H := initial_conditional_clipped_exists hK hm hKm hR (by have H:=z.2.isLt; omega) off hi hoff hsafe + (posteriorAnchorSeries c (fun i => (z.1 i).1)) (posteriorAnchorSeries_nonneg c _) + (posteriorAnchorSeries_total c _) s k + (posteriorAnchorSeries_central K s c _ (by simpa using hleft) hright) hk hq hz.1.1 hmean hz.1.2 hM hw hscale hclip + exact ⟨(Classical.choice H).weaken le_rfl (hbudget z hz)⟩ + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def purePeriodCoefficient {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) : (Fin l → Bool) → ℝ := + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot (u:=u) (fun _ => off)))) + +theorem mixedMotifCoefficient_pure_rank_difference {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (v : IncreasingTuple l r) : + mixedMotifCoefficient hl off hsafe π s 1 (rankMask v)-purePeriodCoefficient hl off (rankMask v)= + pureRankCoefficient hl off hsafe π s v := by + unfold mixedMotifCoefficient purePeriodCoefficient pureRankCoefficient + simp_rw [averaged_rank_coefficient hl _ v,mul_sub,Finset.sum_sub_distrib,←Finset.sum_mul,hπsum,one_mul] + +/-- The pure comparison retains all low-degree cancellation, not just its + total defect density. -/ +def initialPureDegreeBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : ℝ := + if r=0 then 0 else + 2*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference, if k=unchangedPattern r then 0 else purePatternBound u m r s π θ k)+ + 2*((Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l*(2*Real.exp (-(m:ℝ)/(1024*u))))))^2 + +theorem initialPureDegreeBound_nonneg (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : + 0 ≤ initialPureDegreeBound u m r s π θ l := by + unfold initialPureDegreeBound + split_ifs + · exact le_rfl + · apply add_nonneg _ (by positivity) + apply mul_nonneg (by positivity) + apply Finset.sum_nonneg + intro k _ + split_ifs + · exact le_rfl + · unfold purePatternBound + split_ifs <;> apply mul_nonneg _ (seriesL2Sq_nonneg _) + all_goals dsimp only [periodDifferencePrefactor,lengthDifferenceConstant,periodCentralSumConstant] + all_goals positivity + +theorem pureMotif_degree_zero {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) : + (∑σ : Fin l → Bool,if monomialDegree σ=0 then + (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0)=0 := by + simp_rw [monomialDegree_eq_zero_iff] + simp [mixedMotifCoefficient_empty hl off hsafe π hπsum,purePeriodCoefficient,averagedCoefficient_empty] + +theorem pureMotif_degree_cancellation {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : + (∑σ : Fin l → Bool,if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0) ≤ + initialPureDegreeBound u m r s π θ l := by + refine (sum_degree_coeff_sq_le _).trans ?_ + simp_rw [mixedMotifCoefficient_pure_rank_difference hl off hsafe π hπsum s] + simpa only [initialPureDegreeBound,ite_eq_right (by omega : r ≠ 0)] using + initial_pure_energy hu hm hr hl off hoff hsafe π hπ hπsum s hcentral hθ hhalf hmean hv + +theorem purePeriod_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : + w^(2*r)*(∑σ : Fin l → Bool,if monomialDegree σ=r then (purePeriodCoefficient hl off σ)^2 else 0) ≤ + (initialMomentRatio u m q w)^r := by + have hw0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity + have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] + by_cases hru : r ≤ u + · have hb := period_degree_square_sum hl hr hru hm hum hq hθ hmean hv (fun _ => off) + (fun _ => hoff) (fun _ _ => by simp) + have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by + apply Real.sqrt_le_sqrt + apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) + have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr + nlinarith + calc + _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := + mul_le_mul_of_nonneg_left hb hw0 + _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by gcongr + _ = _ := by unfold initialMomentRatio; rw [pow_mul,mul_pow,mul_pow]; ring + · have H := defect_degree_bound hl (periodSlot (u:=u) (fun _ => off)) (periodSlot_strictMono _) (by omega : u < r) + change _=0 at H + change w^(2*r)*_ ≤ _ + rw [show (∑σ : Fin l → Bool,if monomialDegree σ=r then (purePeriodCoefficient hl off σ)^2 else 0)=0 from H,mul_zero] + exact pow_nonneg (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) _ + +theorem pureMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : + w^(2*r)*(∑σ : Fin l → Bool,if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ)^2 else 0) ≤ + 4*(initialMomentRatio u m q w)^r := by + have H := mul_le_mul_of_nonneg_left (degree_square_sub_le + (mixedMotifCoefficient hl off hsafe π s 1) (purePeriodCoefficient hl off) r) + (by rw [pow_mul]; positivity : 0 ≤ w^(2*r)) + have h1 := mixedMotif_degree_geometric hl hr hm hum off hi hoff hsafe π hπ hπsum s 1 hq hθ hmean hv w + have h2 := purePeriod_degree_geometric hl hr hm hum off (hoff.trans (by norm_num)) hq hθ hmean hv w + change _ ≤ initialMomentRatio u m q w ^r at h1 + nlinarith only [H,h1,h2] + +def initialPureBudget (u m l R s : ℕ) (π : IntSeries) (θ q w : ℝ) : ℝ := + (∑r∈Finset.range R,w^(2*r)*initialPureDegreeBound u m r s π θ l)+ + 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) + +theorem pure_initial_full_energy {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : 0 ≤ w) (ha : initialMomentRatio u m q w < 1) : + multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ) w ≤ + initialPureBudget u m l R s π θ q w := by + have hq2 : q^2 ≤ (1/4:ℝ) := by + calc q^2 ≤ (1/2:ℝ)^2 := pow_le_pow_left₀ hq.1.le hq.2 2 + _ = _ := by norm_num + have hθ0 : θ∈Set.Ioo 0 1 := by constructor <;> nlinarith [hq.1,hθ.1,hθ.2] + have hhalf : 1/2 ≤ θ := by nlinarith [hθ.1] + apply multilinearEnergy_low_high _ w _ 4 hw (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) ha + (by norm_num) (initialPureDegreeBound u m · s π θ l) _ _ + (fun r => initialPureDegreeBound_nonneg _ _ _ _ _ _ _) + · intro r _hr + by_cases hr0 : r=0 + · subst r + rw [pureMotif_degree_zero hl off hsafe π hπsum s] + exact initialPureDegreeBound_nonneg _ _ _ _ _ _ _ + · exact pureMotif_degree_cancellation hu hm (Nat.pos_of_ne_zero hr0) hl off (hoff.trans (by norm_num)) + hsafe π hπ hπsum s hcentral hθ0 hhalf hmean hv + · intro r hr + exact pureMotif_degree_geometric hl (by omega) (by omega) hum off hi hoff hsafe π hπ hπsum s hq hθ hmean hv w + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def purePeriodDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) (q : ℝ) : + (Fin l → PrimitiveMark) → ℝ := multilinear (purePeriodCoefficient hl off) (primitiveScore q) + +theorem purePeriodDensity_nonneg {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (x : Fin l → PrimitiveMark) : + 0 ≤ purePeriodDensity hl off q x := by + have H := (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))).nonneg x + rw [conditionalDefectLaw_density] at H + exact nonneg_of_mul_nonneg_right H (primitive_product_mass_pos hq x) + +theorem purePeriodDensity_total {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + {q : ℝ} (hq : q∈Set.Ioo 0 1) : + ((primitiveMarkLaw q hq false).product l).expect (purePeriodDensity hl off q)=1 := by + have H := (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))).total + simpa only [conditionalDefectLaw_density,FiniteLaw.expect,purePeriodDensity,purePeriodCoefficient] using H + +theorem purePeriodLaw_withDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + {q : ℝ} (hq : q∈Set.Ioo 0 1) : + conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot (u:=u) (fun _ => off)))= + ((primitiveMarkLaw q hq false).product l).withDensity (purePeriodDensity hl off q) + (purePeriodDensity_nonneg hl off hq) (purePeriodDensity_total hl off hq) := by + apply FiniteLaw.ext + funext x + exact conditionalDefectLaw_density hl hq _ x + +theorem purePeriod_centered_energy {u m l : ℕ} (hl : l ≤ u*m) (hm : 32 ≤ m) (hum : u ≤ m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : 0 ≤ w) (ha : initialMomentRatio u m q w < 1) : + multilinearEnergy (nonconstantCoefficient (purePeriodCoefficient hl off)) w ≤ + initialMomentRatio u m q w/(1-initialMomentRatio u m q w) := by + have H := multilinearEnergy_low_high (R:=1) + (nonconstantCoefficient (purePeriodCoefficient hl off)) w _ 1 hw + (by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1]) ha (by norm_num) (fun _ => 0) + (fun r hr => by + have he : r=0 := by omega + subst r + rw [nonconstant_degree_zero]) + (fun r hr => by + rw [nonconstant_degree_pos _ (by omega)] + simpa only [one_mul] using purePeriod_degree_geometric hl (by omega) hm hum off hoff hq hθ hmean hv w) + (fun _ => le_rfl) + simpa using H + +theorem purePeriod_centered_moment {u m l : ℕ} (hl : l ≤ u*m) (hm : 32 ≤ m) (hum : u ≤ m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) (k : ℕ) (hk : 1 ≤ k) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : + ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq + (fun x => purePeriodDensity hl off q x-1) k ≤ + initialMomentRatio u m q w/(1-initialMomentRatio u m q w) := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + have he : (fun x => purePeriodDensity hl off q x-1)= + multilinear (nonconstantCoefficient (purePeriodCoefficient hl off)) (primitiveScore q) := by + funext x + rw [nonconstant_multilinear] + simp only [purePeriodCoefficient,averagedCoefficient_empty,purePeriodDensity] + rw [he] + apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk + (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans + rw [←hw] + exact purePeriod_centered_energy hl hm hum off hoff hq hθ hmean hv (by rw [hw]; positivity [hq.1]) ha + +theorem initial_pure_moment {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (ha : initialMomentRatio u m q w < 1) : + ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq + (fun x => initialMotifDensity hl off hsafe π s 1 q x-purePeriodDensity hl off q x) k ≤ + initialPureBudget u m l R s π θ q w := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + have he : (fun x => initialMotifDensity hl off hsafe π s 1 q x-purePeriodDensity hl off q x)= + multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ-purePeriodCoefficient hl off σ) + (primitiveScore q) := by funext x; exact (multilinear_sub _ _ _ _).symm + rw [he] + apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk + (primitive_score_centered hq') (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans + rw [←hw] + exact pure_initial_full_energy hu hm hum hR hl off hi hoff hsafe π hπ hπsum s hcentral hq hθ hmean hv + (by rw [hw]; positivity [hq.1]) ha + +theorem initial_pure_conditional_clipped_exists {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X,0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s k : ℕ) (hcentral : CentralMotifSupport u s π) (hk : 1 ≤ k) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) (hscale : initialMomentRatio u m q w ≤ 1/2) + (hclip : Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k) ≤ 1/2) : + Nonempty (ClippedOracle + (conditionalPrimitiveLaw hl q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + (defectTypes (periodSlot (u:=u) (fun _ => off)))) + (conditionalMotifLaw hl off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ π hπ hπsum s 1) k + (Real.sqrt (6*(4*(initialMomentRatio u m q w/(1-initialMomentRatio u m q w)))^k)) + (64*initialPureBudget u m l R s π θ q w)) := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + let A := (primitiveMarkLaw q hq' false).product l + let f := purePeriodDensity hl off q + let g := initialMotifDensity hl off hsafe π s 1 q + let U := initialMomentRatio u m q w/(1-initialMomentRatio u m q w) + have ha : initialMomentRatio u m q w < 1 := by linarith + have hz : 0 ≤ initialMomentRatio u m q w := by unfold initialMomentRatio; positivity [rankSchurConstant_pos,hq.1] + have hU : 0 ≤ U := div_nonneg hz (sub_nonneg.mpr ha.le) + have hU1 : U ≤ 1 := (div_le_iff₀ (sub_pos.mpr ha)).mpr (by linarith) + have hf : A.expect (fun x => |f x-1|^(2*k)) ≤ U^k := + A.expect_even_pow_le_of_moment _ k hk (purePeriod_centered_moment hl (by omega) hum off + (hoff.trans (by norm_num)) k hk hq hθ hmean hv hw ha) + have hg : A.expect (fun x => |g x-1|^(2*k)) ≤ U^k := + A.expect_even_pow_le_of_moment _ k hk (initial_centered_moment hl (by omega) hum off hi hoff hsafe π hπ hπsum s k hk 1 hq hθ hmean hv hw ha) + have hsig := initial_pure_moment hu hm hum hR hl off hi hoff hsafe π hπ hπsum s k hcentral hk hq hθ hmean hv hw ha + have hV := (A.evenMomentSq_nonneg (fun x => g x-f x) k).trans hsig + have hsig' := A.expect_even_pow_le_of_moment _ k hk hsig + rw [purePeriodLaw_withDensity hl off hq',initialMotifLaw_withDensity hl off hsafe π hπ hπsum s 1 hq'] + have H := A.exists_clippedOracle f g + (purePeriodDensity_nonneg hl off hq') (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s 1 hq') + (purePeriodDensity_total hl off hq') (initialMotifDensity_mean hl off hsafe π hπ hπsum s 1 hq') + Finset.univ 0 (by simp [FiniteLaw.eventMass]) (by simp [FiniteLaw.eventMass]) k hk U hU hU1 hf hg + (initialPureBudget u m l R s π θ q w) hV (by simpa only [Finset.mem_univ,ite_true] using hsig') + (by simpa only [zero_add] using hclip) + simpa only [zero_add] using H + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- A common finite decoder transfers normalized clipping to actual complete + traces. Neither interface is permitted to assume the main lower bound. -/ +theorem ClippedOracle.tracePair {α : Type} [Fintype α] {P Q : FiniteLaw α} + {q e V : ℝ} {x y : List Bool} {k : ℕ} (f : α → List Bool) + (C : ClippedOracle P Q k e V) (hP : SimulatesTrace q P f x) + (hQ : SimulatesTrace q Q f y) : Nonempty (OracleTracePair q x y k e V) := by + refine ⟨{ + Outcome := α + finiteOutcome := inferInstance + first := C.first + second := C.second + decode := f + score := C.score + density := C.density + likelihood_nonneg := C.likelihood_nonneg + centered := C.centered + moment := C.moment + first_simulation := ?_ + second_simulation := ?_ + }⟩ + · simpa using hP.approximate.of_tv C.first_tv + · simpa using hQ.approximate.of_tv C.second_tv + +def initialPureConditionalLaw {Side : Type*} {J K m : ℕ} (off : Fin m) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (z : InitialMetadata Side J (K*m)) : + FiniteLaw (Fin z.2.val → PrimitiveMark) := + conditionalPrimitiveLaw (by have H:=z.2.isLt; omega) q hq + (defectTypes (periodSlot (u:=K) (fun _ => off))) + +def initialPureSigmaLaw {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (off : Fin m) {q : ℝ} (hq : q∈Set.Ioo 0 1) : + FiniteLaw (InitialObservation Side J (K*m)) := + (initialMetadataLaw M (K*m) hq).sigma (initialPureConditionalLaw off hq) + +theorem initialPureSigmaLaw_expect {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (off : Fin m) {q : ℝ} (hq : q∈Set.Ioo 0 1) + (F : Reports Side J × BoundedMarks (K*m) → ℝ) : + (initialPureSigmaLaw M off hq).expect (fun z => F (z.1.1,⟨z.1.2,z.2⟩))= + (M.emissionOracle (fun _ => countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (periodSlot (u:=K) (fun _ => off))))).expect F := by + simp only [initialPureSigmaLaw,initialMetadataLaw,FiniteLaw.expect_sigma, + FiniteLaw.expect_prod,PairedMechanisms.emissionOracle,FiniteLaw.expect_joint, + FiniteLaw.expect_mixture,FiniteLaw.expect_const,initialPureConditionalLaw, + countedPrimitiveLaw,FiniteLaw.expect_sigma] + have hl (l : Fin (K*m+1)) : l.val ≤ K*m := Nat.le_of_lt_succ l.isLt + simp only [boundedConditionalPrimitiveLaw,hl,dite_eq_left] + +theorem initial_pure_sigma_simulates {Side : Type*} [Fintype Side] {J K m : ℕ} + (M : PairedMechanisms Side J) (k : ℕ) (off : Fin m) + {q : ℝ} (hq : q∈Set.Ioo 0 1) (side : Side → List Bool) + (hfirst : ∀i,SimulatesTrace q (M.first i) side (pureAtomRun (initialPeriod m off.val) k)) + (hsecond : ∀i,SimulatesTrace q (M.second i) side (pureAtomRun (initialPeriod m off.val) (k+1))) : + SimulatesTrace q (initialPureSigmaLaw (K:=K) M off hq) (decodeInitialObservation side) + (pureAtomRun (initialPeriod m off.val) (J*(2*k+1)+K)) := by + intro F + unfold decodeInitialObservation + rw [initialPureSigmaLaw_expect M off hq (fun z => F (decodePairedEmission side decodeBoundedMarks z)), + ←M.emission_factorization,FiniteLaw.expect_mixture] + have H (b : Fin J → Bool) : + ((M.reportsGiven b).prod (countedPrimitiveLaw (le_refl (K*m)) hq + (defectTypes (periodSlot (u:=K) (fun _ => off))))).expect + (fun z => F (decodePairedEmission side decodeBoundedMarks z))= + listDeletionExpectation q (pureAtomRun (initialPeriod m off.val) (J*(2*k+1)+K)) F := by + have hc := countedPrimitiveLaw_simulates (le_refl (K*m)) hq (defectTypes (periodSlot (u:=K) (fun _ => off))) + rw [periodic_primitive_word,periodString_constant] at hc + have hs := M.reportsGiven_paired_simulates b side decodeBoundedMarks _ + (fun _ => pureAtomRun (initialPeriod m off.val) k) + (fun _ => pureAtomRun (initialPeriod m off.val) (k+1)) _ hfirst hsecond hc + have hp : coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) (k+1) + else pureAtomRun (initialPeriod m off.val) k)= + pureAtomRun (initialPeriod m off.val) (initialPrefixPeriods k b) := by + have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) (k+1) else + pureAtomRun (initialPeriod m off.val) k)=pureAtomRun (initialPeriod m off.val) (k+bitIndex (b i)) := by + cases b i <;> simp [bitIndex] + simp_rw [h] + exact coordinateWord_pureAtomRun _ _ + have hz : coordinateWord (fun i => if b i then pureAtomRun (initialPeriod m off.val) k + else pureAtomRun (initialPeriod m off.val) (k+1))= + pureAtomRun (initialPeriod m off.val) (initialSuffixPeriods k b) := by + have h (i : Fin J) : (if b i then pureAtomRun (initialPeriod m off.val) k else + pureAtomRun (initialPeriod m off.val) (k+1))=pureAtomRun (initialPeriod m off.val) (k+(1-bitIndex (b i))) := by + cases b i <;> simp [bitIndex] + simp_rw [h] + exact coordinateWord_pureAtomRun _ _ + rw [hp,hz,←pureAtomRun_add,←pureAtomRun_add] at hs + have ht : initialPrefixPeriods k b+K+initialSuffixPeriods k b=J*(2*k+1)+K := by + have ht:=initialPairPeriods_total k b + omega + rw [ht] at hs + exact hs F + simp only [H,FiniteLaw.expect_const] + +theorem initial_pure_sigma_clipped_exists {Side : Type*} [Fintype Side] {J K m R : ℕ} + (M : PairedMechanisms Side J) (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) + (hR : 0 < R) (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + (c : ℤ) (s k : ℕ) (hk : 1 ≤ k) + (hleft : (K:ℝ)/3 ≤ 2*((c:ℝ)-J)+1) + (hright : (K:ℝ)/3 ≤ 2*K-(2*((c:ℝ)+(2:ℝ)^s)+1)) + {q ω w V : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) + (hscale : initialMomentRatio K m q w ≤ 1/2) + (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) + (hV : 0 ≤ V) + (hbudget : ∀z : InitialMetadata Side J (K*m),initialMetadataGood q ω z → + 64*initialPureBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) + ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V) : + Nonempty (ClippedOracle + (initialPureSigmaLaw M off ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩) + (initialSigmaLaw M off hsafe ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ c s 1) k + (Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ + (initialMetadataLaw M (K*m) ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩).expect + (fun z => if initialMetadataGood q ω z then 0 else 1)) V) := by + apply ClippedOracle.assemble_good _ _ _ (initialMetadataGood q ω) k hk _ V (Real.sqrt_nonneg _) hV + intro z hz + have hmean : ((K*m:ℕ):ℝ)*((z.2.val:ℝ)/(K*m:ℕ))=z.2.val := by + exact mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0))) + have H := initial_pure_conditional_clipped_exists hK hm hKm hR (by have H:=z.2.isLt; omega) off hi hoff hsafe + (posteriorAnchorSeries c (fun i => (z.1 i).1)) (posteriorAnchorSeries_nonneg c _) + (posteriorAnchorSeries_total c _) s k + (posteriorAnchorSeries_central K s c _ (by simpa using hleft) hright) hk hq hz.1.1 hmean hz.1.2 hw hscale hclip + exact ⟨(Classical.choice H).weaken le_rfl (hbudget z hz)⟩ + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The half-mean hidden-count event yields the correct L², not supremum, + exponent J^{-s-1/2} in the initial Prouhet cancellation. -/ +def hiddenSignedL2Bound (J s : ℕ) (ω : ℝ) : ℝ := + ((2:ℝ)^(s*s))^2*((2*Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)))^s)^2* + Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)) + +def hiddenUnsignedL2Bound (J s : ℕ) (ω : ℝ) : ℝ := + ((2:ℝ)^s)^2*hiddenBinomialCap J ω + +theorem hiddenSignedL2Bound_nonneg (J s : ℕ) (ω : ℝ) : 0≤hiddenSignedL2Bound J s ω := by + unfold hiddenSignedL2Bound; positivity + +theorem hiddenUnsignedL2Bound_nonneg (J s : ℕ) (ω : ℝ) : 0≤hiddenUnsignedL2Bound J s ω := by + exact mul_nonneg (sq_nonneg _) (hiddenBinomialCap_nonneg _ _) + +theorem hidden_quotient_bound (J G s : ℕ) (ω : ℝ) (h : (J:ℝ)*ω^2/2≤G) : + binomialBound (G/(s+1))≤Real.sqrt (4*((s:ℝ)+1)/((J:ℝ)*ω^2+2)) := by + apply (binomialBound_quotient_le G s).trans + apply Real.sqrt_le_sqrt + apply (div_le_div_iff₀ (by positivity : (0:ℝ)<(G:ℝ)+1) + (by positivity : (0:ℝ)<(J:ℝ)*ω^2+2)).mpr + have hh := mul_le_mul_of_nonneg_left h (by positivity : (0:ℝ)≤4*((s:ℝ)+1)) + nlinarith + +theorem posteriorAnchorSeries_signed_L2 {J : ℕ} (d : Fin J→Option Bool) (c : ℤ) (s : ℕ) (ω : ℝ) + (h : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + seriesL2Sq (prouhetSeries s*posteriorAnchorSeries c d)≤hiddenSignedL2Bound J s ω := by + have hn : (J:ℝ)*ω^2/2≤((∑i,hiddenTrial (d i):ℕ):ℝ) := by simpa only [Nat.cast_sum] using h + have hb := hidden_quotient_bound J (∑i,hiddenTrial (d i)) s ω hn + apply (translated_binomial_smoothing (∑i,hiddenTrial (d i)) s _).trans + unfold hiddenSignedL2Bound + rw [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply mul_le_mul + · apply pow_le_pow_left₀ (by unfold binomialBound; positivity) + exact pow_le_pow_left₀ (by unfold binomialBound; positivity) (mul_le_mul_of_nonneg_left hb (by norm_num)) _ + · exact hb + · exact Real.sqrt_nonneg _ + · positivity + +theorem posteriorAnchorSeries_unsigned_L2 {J : ℕ} (d : Fin J→Option Bool) (c : ℤ) (s : ℕ) (ω : ℝ) + (h : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + seriesL2Sq (geomSeries (2^s)*posteriorAnchorSeries c d)≤hiddenUnsignedL2Bound J s ω := by + have hn : (J:ℝ)*ω^2/2≤((∑i,hiddenTrial (d i):ℕ):ℝ) := by simpa only [Nat.cast_sum] using h + calc + _ ≤ seriesL1 (geomSeries (2^s))^2*seriesL2Sq (posteriorAnchorSeries c d) := seriesL2Sq_mul_le _ _ + _ ≤ ((2:ℝ)^s)^2*hiddenBinomialCap J ω := by + apply mul_le_mul + · exact pow_le_pow_left₀ (seriesL1_nonneg _) (by exact_mod_cast geomSeries_L1_le (2^s)) _ + · rw [posteriorAnchorSeries,translateSeries_L2Sq] + exact (fairSeries_L2Sq_bound _).trans (hidden_binomial_bound J _ ω hn) + · exact seriesL2Sq_nonneg _ + · positivity + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def initialDifferenceCap (d : ℕ) (q : ℝ) : ℝ := + 2*Real.sqrt (8*((d:ℝ)+1)/q^2) + +theorem initial_theta_variance {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) : + θ∈Set.Ioo 0 1 ∧ 1/2≤θ ∧ q^2/8≤θ*(1-θ) := by + have hq2 : q^2≤1/4 := by nlinarith [hq.1,hq.2] + have hs : 0 if initialCountAdmissible N q l then 0 else 1) ≤ + 2*Real.exp (-(N:ℝ)*q^4/64) := by + let p := 1-primitiveErasure q + have hp : p∈Set.Icc 0 1 := primitiveRetention_mem ⟨hq.1,by linarith [hq.2]⟩ + have ht : q^2/8∈Set.Icc (0:ℝ) 1 := ⟨by positivity,by nlinarith [hq.1,hq.2]⟩ + have H := binomialMass_abs_tail N (a:=(N:ℝ)*q^2/4) hp ht + have he : -(q^2/8)*((N:ℝ)*q^2/4)+(N:ℝ)*(q^2/8)^2= -(N:ℝ)*q^4/64 := by ring + rw [he] at H + apply le_trans _ H + rw [Finset.sum_filter,←Fin.sum_univ_eq_sum_range] + apply Finset.sum_le_sum + intro l _ + change binomialMass N p l.val*(if initialCountAdmissible N q l then 0 else 1)≤_ + have hn := binomialMass_nonneg N l.val hp + by_cases hl : initialCountAdmissible N q l + · rw [ite_eq_left hl,mul_zero] + split_ifs <;> positivity + · rw [ite_eq_right hl,mul_one,ite_eq_left] + exact le_of_not_gt (fun h => hl (initialCountAdmissible_of_near hq hscale l (by simpa [p,primitiveErasure] using h))) + +/-- The true bad metadata mass is charged without changing any conditional + law or requiring an unproved concentration conclusion. -/ +theorem initial_metadata_bad_mass {Side : Type*} [Fintype Side] {J N : ℕ} + (M : PairedMechanisms Side J) {q ω : ℝ} + (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hscale : 8≤(N:ℝ)*q^2) + (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : + (initialMetadataLaw M N ⟨hq.1,by linarith [hq.2]⟩).expect + (fun z => if initialMetadataGood q ω z then 0 else 1) ≤ + 2*Real.exp (-(N:ℝ)*q^4/64)+Real.exp (-(J:ℝ)*ω^4/16) := by + calc + _ ≤ (initialMetadataLaw M N ⟨hq.1,by linarith [hq.2]⟩).expect + (fun z => (if initialCountAdmissible N q z.2 then 0 else 1)+ + (if (PairedMechanisms.hiddenCount z.1:ℝ)<(J:ℝ)*ω^2/2 then 1 else 0)) := by + apply FiniteLaw.expect_mono + intro z + have he : (PairedMechanisms.hiddenCount z.1:ℝ)=∑i,(hiddenTrial (z.1 i).1:ℝ) := by + simp only [PairedMechanisms.hiddenCount,Nat.cast_sum] + unfold initialMetadataGood + rw [←he] + split_ifs <;> simp_all + _ ≤ _ := by + simp only [FiniteLaw.expect_add,initialMetadataLaw,FiniteLaw.expect_prod] + apply add_le_add + · exact (M.reports.expect_mono (fun _ => initial_count_bad_mass hq hscale)).trans (by rw [FiniteLaw.expect_const]) + · convert M.hiddenCount_small hw hp using 1 + congr 1 + funext a + split_ifs <;> simp [FiniteLaw.expect,FiniteLaw.total] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def initialSignedPatternCap (J u m r s : ℕ) (q ω : ℝ) (k : Fin r → GapDifference) : ℝ := + if ∃a,k=linearPattern a then + initialPrefactorCap u m r 1 q*periodCentralSumConstant u r*hiddenSignedL2Bound J s ω + else initialPrefactorCap u m r (∑h,(k h).order) q* + periodBoundedSumConstant u r (2*(2^s))*hiddenUnsignedL2Bound J s ω + +def initialPurePatternCap (J u m r s : ℕ) (q ω : ℝ) (k : Fin r → GapDifference) : ℝ := + if ∃a,k=linearPattern a then + initialPrefactorCap u m r 1 q*periodCentralSumConstant u r*hiddenSignedL2Bound J s ω + else initialPrefactorCap u m r (∑h,(k h).order) q* + periodCentralSumConstant u r*hiddenUnsignedL2Bound J s ω + +theorem initial_signed_pattern_cap {J : ℕ} (d : Fin J → Option Bool) (c : ℤ) + (u m r s : ℕ) (k : Fin r → GapDifference) {q θ ω : ℝ} + (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + signedPatternBound u m r s (posteriorAnchorSeries c d) θ k ≤ + initialSignedPatternCap J u m r s q ω k := by + unfold signedPatternBound initialSignedPatternCap + split_ifs + · apply mul_le_mul + · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r 1 hq hθ) + (by unfold periodCentralSumConstant; positivity) + · exact posteriorAnchorSeries_signed_L2 d c s ω hh + · exact seriesL2Sq_nonneg _ + · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) + · apply mul_le_mul + · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r _ hq hθ) + (by unfold periodBoundedSumConstant; positivity) + · exact posteriorAnchorSeries_unsigned_L2 d c s ω hh + · exact seriesL2Sq_nonneg _ + · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodBoundedSumConstant; positivity) + +theorem initial_pure_pattern_cap {J : ℕ} (d : Fin J → Option Bool) (c : ℤ) + (u m r s : ℕ) (k : Fin r → GapDifference) {q θ ω : ℝ} + (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + purePatternBound u m r s (posteriorAnchorSeries c d) θ k ≤ + initialPurePatternCap J u m r s q ω k := by + unfold purePatternBound initialPurePatternCap + split_ifs + · apply mul_le_mul + · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r 1 hq hθ) + (by unfold periodCentralSumConstant; positivity) + · exact posteriorAnchorSeries_signed_L2 d c s ω hh + · exact seriesL2Sq_nonneg _ + · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) + · apply mul_le_mul + · exact mul_le_mul_of_nonneg_right (initial_prefactor_bound u m r _ hq hθ) + (by unfold periodCentralSumConstant; positivity) + · exact posteriorAnchorSeries_unsigned_L2 d c s ω hh + · exact seriesL2Sq_nonneg _ + · exact mul_nonneg (initialPrefactorCap_nonneg _ _ _ _ _) (by unfold periodCentralSumConstant; positivity) + +def initialSignedDegreeCap (J u m r s : ℕ) (q ω : ℝ) : ℝ := + if r=0 then 0 else + 8*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference,if Odd (firstDifferenceCount k) then + initialSignedPatternCap J u m r s q ω k else 0)+initialRankTailCap u m r + +def initialPureDegreeCap (J u m r s : ℕ) (q ω : ℝ) : ℝ := + if r=0 then 0 else + 2*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference,if k=unchangedPattern r then 0 else + initialPurePatternCap J u m r s q ω k)+initialRankTailCap u m r + +theorem initial_signed_degree_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (r s : ℕ) + {q θ ω : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + signedInitialDegreeBound u m r s (posteriorAnchorSeries c d) θ l ≤ + initialSignedDegreeCap J u m r s q ω := by + unfold signedInitialDegreeBound initialSignedDegreeCap + split_ifs + · exact le_rfl + · apply add_le_add + · apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro k _ + split_ifs + · exact initial_signed_pattern_cap d c u m r s k hq hθ hh + · exact le_rfl + · exact initial_rank_tail_bound r (initial_theta_variance hq hθ).1 hl hmean hv + +theorem initial_pure_degree_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (r s : ℕ) + {q θ ω : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + initialPureDegreeBound u m r s (posteriorAnchorSeries c d) θ l ≤ + initialPureDegreeCap J u m r s q ω := by + unfold initialPureDegreeBound initialPureDegreeCap + split_ifs + · exact le_rfl + · apply add_le_add + · apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Finset.sum_le_sum + intro k _ + split_ifs + · exact le_rfl + · exact initial_pure_pattern_cap d c u m r s k hq hθ hh + · exact initial_rank_tail_bound r (initial_theta_variance hq hθ).1 hl hmean hv + +/-- Scalar budgets independent of every actual report and count. The finite + signed-pattern restriction is retained to preserve its three-difference gain. -/ +def initialSignedCap (J u m R s : ℕ) (q ω w : ℝ) : ℝ := + (∑r∈Finset.range R,w^(2*r)*initialSignedDegreeCap J u m r s q ω)+ + 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) + +def initialPureCap (J u m R s : ℕ) (q ω w : ℝ) : ℝ := + (∑r∈Finset.range R,w^(2*r)*initialPureDegreeCap J u m r s q ω)+ + 4*(initialMomentRatio u m q w)^R/(1-initialMomentRatio u m q w) + +theorem initial_signed_budget_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (R s : ℕ) + {q θ ω w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + initialSignedBudget u m l R s (posteriorAnchorSeries c d) θ q w ≤ + initialSignedCap J u m R s q ω w := by + unfold initialSignedBudget initialSignedCap + apply add_le_add _ le_rfl + apply Finset.sum_le_sum + intro r _ + exact mul_le_mul_of_nonneg_left (initial_signed_degree_cap d c r s hq hθ hl hmean hv hh) + (by rw [pow_mul]; positivity) + +theorem initial_pure_budget_cap {J u m l : ℕ} (d : Fin J → Option Bool) (c : ℤ) (R s : ℕ) + {q θ ω w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hl : l≤u*m) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1≤((u*m:ℕ):ℝ)*θ*(1-θ)) + (hh : (J:ℝ)*ω^2/2≤∑i,(hiddenTrial (d i):ℝ)) : + initialPureBudget u m l R s (posteriorAnchorSeries c d) θ q w ≤ + initialPureCap J u m R s q ω w := by + unfold initialPureBudget initialPureCap + apply add_le_add _ le_rfl + apply Finset.sum_le_sum + intro r _ + exact mul_le_mul_of_nonneg_left (initial_pure_degree_cap d c r s hq hθ hl hmean hv hh) + (by rw [pow_mul]; positivity) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def OracleTracePair.weaken {q E V E' V' : ℝ} {x y : List Bool} {k : ℕ} + (C : OracleTracePair q x y k E V) (hE : E ≤ E') (hV : V ≤ V') : + OracleTracePair q x y k E' V' := + { C with + first_simulation := fun F hF => (C.first_simulation F hF).trans hE + second_simulation := fun F hF => (C.second_simulation F hF).trans hE + moment := C.moment.trans hV } + +def initialErrorCap (J K m k : ℕ) (q ω w : ℝ) : ℝ := + Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k)+ + (2*Real.exp (-((K*m:ℕ):ℝ)*q^4/64)+Real.exp (-(J:ℝ)*ω^4/16)) + +/-- Both required initial comparisons are genuine approximate complete-trace + oracles. The metadata budgets have been eliminated: only explicit finite + scalar bounds and literal period geometry remain to be instantiated. -/ +theorem actual_initial_oracles {J K m R : ℕ} + (hK : 0 < K) (hm : 128 ≤ m) (hKm : K ≤ m) (hR : 0 < R) + (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=K) (fun _ => off))) + (a : ℤ) (s k : ℕ) (hk : 1 ≤ k) {q w V W : ℝ} + (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hseed : 16 ≤ q^3*(m:ℝ)) (hcount : 8 ≤ ((K*m:ℕ):ℝ)*q^2) + (ha : (J*initialSideCount q m+J:ℕ) ≤ a) + (ha' : a+(2^s:ℕ) ≤ (J*initialSideCount q m+K:ℕ)) + (hleft : (K:ℝ)/3 ≤ 2*((a-(J*initialSideCount q m:ℕ):ℤ)-J)+1) + (hright : (K:ℝ)/3 ≤ 2*K-(2*((a-(J*initialSideCount q m:ℕ):ℤ)+(2:ℝ)^s)+1)) + (hM : ((2*(2^s):ℕ):ℝ) < (K:ℝ)/(3*(R+1:ℝ))) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) + (hscale : initialMomentRatio K m q w ≤ 1/2) + (hclip : Real.sqrt (6*(4*(initialMomentRatio K m q w/(1-initialMomentRatio K m q w)))^k) ≤ 1/2) + (hV : 0 ≤ V) (hW : 0 ≤ W) + (hSV : 64*initialSignedCap J K m R s q (initialOverlapLower q) w ≤ V) + (hPW : 64*initialPureCap J K m R s q (initialOverlapLower q) w ≤ W) : + Nonempty (OracleTracePair q + (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a (-1)) + (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a 1) k + (initialErrorCap J K m k q (initialOverlapLower q) w) V) ∧ + Nonempty (OracleTracePair q + (pureAtomRun (initialPeriod m off.val) (J*(2*initialSideCount q m+1)+K)) + (motifPeriodWord off hi (J*(2*initialSideCount q m+1)+K) s a 1) k + (initialErrorCap J K m k q (initialOverlapLower q) w) W) := by + let t := initialSideCount q m + let ω := initialOverlapLower q + let c : ℤ := a-(J*t:ℕ) + have hω : 0 < ω := initialOverlapLower_pos q + have hω1 : ω < 1/8 := initialOverlapLower_lt_eighth hq.1 + have hqi : q∈Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ + have hqc : q∈Set.Icc 0 1 := ⟨hq.1.le,hqi.2.le⟩ + let u := pureAtomRun (initialPeriod m off.val) t + let v := pureAtomRun (initialPeriod m off.val) (t+1) + let N := max u.length v.length + have hu : u.length ≤ N := le_max_left _ _ + have hv : v.length ≤ N := le_max_right _ _ + have hov : ω ≤ listTraceOverlap q hqc u v := initial_pure_trace_overlap hq (by omega) + hseed off (by linarith) + let M : PairedMechanisms (BoundedTrace N) J := tracePairedMechanisms hqc hω + (fun _ => u) (fun _ => v) N (fun _ => hu) (fun _ => hv) (fun _ => hov) + have hfirst (i : Fin J) : SimulatesTrace q (M.first i) Subtype.val u := + listTraceLaw_simulates q hqc u N hu + have hsecond (i : Fin J) : SimulatesTrace q (M.second i) Subtype.val v := + listTraceLaw_simulates q hqc v N hv + have htail := initial_metadata_bad_mass M hq hcount (fun _ => rfl) + (show ω^2∈Set.Icc (0:ℝ) 1 from ⟨sq_nonneg _,by nlinarith⟩) + have hsigned (z : InitialMetadata (BoundedTrace N) J (K*m)) + (hz : initialMetadataGood q ω z) : + 64*initialSignedBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) + ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ V := by + apply le_trans _ hSV + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact initial_signed_budget_cap _ c R s hq hz.1.1 (by have H:=z.2.isLt; omega) + (mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0)))) + hz.1.2 hz.2 + have hpure (z : InitialMetadata (BoundedTrace N) J (K*m)) + (hz : initialMetadataGood q ω z) : + 64*initialPureBudget K m z.2.val R s (posteriorAnchorSeries c (fun i => (z.1 i).1)) + ((z.2.val:ℝ)/(K*m:ℕ)) q w ≤ W := by + apply le_trans _ hPW + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact initial_pure_budget_cap _ c R s hq hz.1.1 (by have H:=z.2.isLt; omega) + (mul_div_cancel₀ _ (by exact_mod_cast (Nat.mul_ne_zero (by omega : K≠0) (by omega : m≠0)))) + hz.1.2 hz.2 + have hsim (τ : ℝ) := initial_sigma_simulates M t s a τ off hi hsafe hqi + Subtype.val hfirst hsecond ha ha' + have hp := initial_pure_sigma_simulates (K:=K) M t off hqi Subtype.val hfirst hsecond + obtain ⟨S⟩ := initial_sigma_clipped_exists M hK hm hKm hR off hi hoff hsafe c s k hk + hleft hright hq hM hw hscale hclip hV hsigned + obtain ⟨P⟩ := initial_pure_sigma_clipped_exists M hK hm hKm hR off hi hoff hsafe c s k hk + hleft hright hq hw hscale hclip hW hpure + constructor + · obtain ⟨O⟩ := S.tracePair (decodeInitialObservation Subtype.val) (hsim (-1)) (hsim 1) + exact ⟨O.weaken (add_le_add le_rfl htail) le_rfl⟩ + · obtain ⟨O⟩ := P.tracePair (decodeInitialObservation Subtype.val) hp (hsim 1) + exact ⟨O.weaken (add_le_add le_rfl htail) le_rfl⟩ + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/InitialOverlap.lean b/lean/OAI/Probability/TraceReconstruction/InitialOverlap.lean index a2ffa863fa275b9cc8e83b324a527127fc5ef3db..ff1ee5a198893e23960fa5261604fbb0bf2cdb4a 100644 --- a/lean/OAI/Probability/TraceReconstruction/InitialOverlap.lean +++ b/lean/OAI/Probability/TraceReconstruction/InitialOverlap.lean @@ -1,1186 +1,1186 @@ -import OAI.Probability.TraceReconstruction.Oracles - -namespace OAI - -/-! -# InitialOverlap - -Literal periods, count overlap, initial low/high energies, genuine densities, and centered moment bounds. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem primitive_one_add_score_nonneg {q : ℝ} (hq : q ∈ Set.Ioo 0 1) - (a : PrimitiveMark) : 0 ≤ 1 + primitiveScore q a := by - have hq1 : 1 ≤ 1/q := (le_div_iff₀ hq.1).mpr (by simpa using hq.2.le) - have hq0 := hq.1 - fin_cases a <;> norm_num [primitiveScore] <;> linarith [show 2/q=2*(1/q) by ring] - -/-- Exact conditional law of the genuine periodic primitive observation. -/ -theorem conditionalPeriodLaw_density {u m l : ℕ} (hl : l ≤ u*m) - {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (off : Fin u → Fin m) (x : Fin l → PrimitiveMark) : - (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot off))).mass x = - ((primitiveMarkLaw q hq false).product l).mass x * - averagedDensity (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off))) (primitiveScore q) x := by - rw [conditionalPrimitiveLaw_density] - congr 2 - funext S - exact defectTypes_atRank (periodSlot off) S - -/-- Absolute constant in the conditional second-moment exponent. -/ -def primitivePeriodConstant : ℝ := 36*rankSchurConstant^2 - -theorem primitivePeriodConstant_nonneg : 0 ≤ primitivePeriodConstant := by - unfold primitivePeriodConstant - positivity - -theorem conditionalPeriod_second_moment {u m l : ℕ} (hl : l ≤ u*m) - (hm : 32 ≤ m) (hum : u ≤ m) {q θ : ℝ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) - (hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : - ((primitiveMarkLaw q ⟨hq.1, by linarith [hq.2]⟩ false).product l).expect (fun x => - averagedDensity (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (periodSlot off))) (primitiveScore q) x ^ 2) ≤ - 2*Real.exp (primitivePeriodConstant/q^4 * ((u:ℝ)/m)) := by - have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1, by linarith [hq.2]⟩ - let P := primitiveMarkLaw q hqi false - have hZ : P.expect (primitiveScore q) = 0 := primitive_score_centered hqi - have h := period_density_second_moment P (primitiveScore q) hZ hl hm hum hq hθ hmean hv off hoff hdiff - refine h.trans (mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ?_) (by norm_num)) - have hv0 : 0 ≤ P.expect (fun a => primitiveScore q a ^ 2) := - Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) - have hv1 : P.expect (fun a => primitiveScore q a ^ 2) ≤ 2/q := - primitive_score_variance_le hqi - have hsq : (P.expect (fun a => primitiveScore q a ^ 2))^2 ≤ (2/q)^2 := - pow_le_pow_left₀ hv0 hv1 2 - calc - _ ≤ (2/q)^2*(3*rankSchurConstant/q)^2*((u:ℝ)/m) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hsq (sq_nonneg _)) (by positivity) - _ = _ := by unfold primitivePeriodConstant; field_simp; ring - -/-- Association converts the two actual conditional period-laws into common -mass. The two original block totals may differ; only the retained count agrees. -/ -theorem conditionalPeriod_overlap {u v m l : ℕ} - (hl : l ≤ u*m) (hl' : l ≤ v*m) (hm : 32 ≤ m) (hum : u ≤ m) (hvm : v ≤ m) - {q θ θ' : ℝ} (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) - (hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4)) - (hθ' : θ' ∈ Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hmean' : ((v*m:ℕ):ℝ)*θ'=l) - (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (hv' : 1 ≤ ((v*m:ℕ):ℝ)*θ'*(1-θ')) - (off : Fin u → Fin m) (off' : Fin v → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hoff' : ∀ j, |((off' j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (hdiff' : ∀ j k, |((off' j).val:ℝ)-(off' k).val| ≤ 2) : - Real.exp (-(primitivePeriodConstant/q^4*((u:ℝ)/m+(v:ℝ)/m)))/128 ≤ - FiniteLaw.overlap - (conditionalPrimitiveLaw hl q ⟨hq.1, by linarith [hq.2]⟩ (defectTypes (periodSlot off))) - (conditionalPrimitiveLaw hl' q ⟨hq.1, by linarith [hq.2]⟩ (defectTypes (periodSlot off'))) := by - have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1, by linarith [hq.2]⟩ - let P := primitiveMarkLaw q hqi false - let R := uniformSubsetLaw l (show l≤Fintype.card (Fin (u*m)) by simpa using hl) - let S := uniformSubsetLaw l (show l≤Fintype.card (Fin (v*m)) by simpa using hl') - let f := defectAtRank (l:=l) (Finset.univ.image (periodSlot off)) - let g := defectAtRank (l:=l) (Finset.univ.image (periodSlot off')) - let G := averagedDensity R f (primitiveScore q) - let H := averagedDensity S g (primitiveScore q) - let A := primitivePeriodConstant/q^4*((u:ℝ)/m) - let B := primitivePeriodConstant/q^4*((v:ℝ)/m) - have h1 := conditionalPeriod_second_moment hl hm hum hq hθ hmean hv off hoff hdiff - have h2 := conditionalPeriod_second_moment hl' hm hvm hq hθ' hmean' hv' off' hoff' hdiff' - change (P.product l).expect (fun x => G x^2) ≤ 2*Real.exp A at h1 - change (P.product l).expect (fun x => H x^2) ≤ 2*Real.exp B at h2 - have ha := averagedDensity_overlap P R S (primitiveScore q) - (primitive_score_centered hqi) (primitive_one_add_score_nonneg hqi) f g - change 1/32 ≤ (P.product l).expect (fun x => min (G x) (H x)) * - (P.product l).expect (fun x => G x^2) * (P.product l).expect (fun x => H x^2) at ha - have hG : ∀x, 0 ≤ G x := averagedDensity_nonneg R f _ (primitive_one_add_score_nonneg hqi) - have hH : ∀x, 0 ≤ H x := averagedDensity_nonneg S g _ (primitive_one_add_score_nonneg hqi) - have ho : 0 ≤ (P.product l).expect (fun x => min (G x) (H x)) := - Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product l).nonneg _) (le_min (hG x) (hH x))) - have hm2 : 0 ≤ (P.product l).expect (fun x => H x^2) := - Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product l).nonneg _) (sq_nonneg _)) - have hb := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left h1 ho) hm2 - have hc := mul_le_mul_of_nonneg_left h2 (mul_nonneg ho (by positivity : 0≤2*Real.exp A)) - have he : (P.product l).expect (fun x => min (G x) (H x)) = - FiniteLaw.overlap - (conditionalPrimitiveLaw hl q hqi (defectTypes (periodSlot off))) - (conditionalPrimitiveLaw hl' q hqi (defectTypes (periodSlot off'))) := by - unfold FiniteLaw.expect FiniteLaw.overlap - apply Finset.sum_congr rfl - intro x _ - rw [conditionalPeriodLaw_density,conditionalPeriodLaw_density] - exact mul_min_of_nonneg _ _ ((P.product l).nonneg x) - rw [← he] - have hd : Real.exp (-(A+B))/128 ≤ (P.product l).expect (fun x => min (G x) (H x)) := by - have hx : (1:ℝ)/32 ≤ (P.product l).expect (fun x => min (G x) (H x)) * (4*Real.exp (A+B)) := by - calc - _ ≤ _ := ha.trans (hb.trans hc) - _ = _ := by rw [Real.exp_add]; ring - have hp : 0 < 4*Real.exp (A+B) := by positivity - calc - _ = ((1:ℝ)/32)/(4*Real.exp (A+B)) := by rw [Real.exp_neg]; ring - _ ≤ _ := (div_le_iff₀ hp).2 hx - convert hd using 1 - congr 2 - dsimp [A,B] - ring - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The common count window is admissible for every genuine period count in -the base case. All hypotheses are elementary size/location inequalities. -/ -theorem primitive_count_window {q θ : ℝ} {m n l : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) - (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) - (hmean : (n:ℝ)*θ=l) - (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : - θ ∈ Set.Icc (1-q^2) (1-q^2/4) ∧ - 1 ≤ (n:ℝ)*θ*(1-θ) ∧ - Real.sqrt ((n:ℝ)*θ*(1-θ)) ≤ (m:ℝ) ∧ - ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / ((n:ℝ)*(1-q^2/2)*(q^2/2)) ≤ 32/q^3 := by - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hq0 := hq.1 - have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.2] - have hq2p : 0 < q^2 := sq_pos_of_pos hq0 - have hq3 : 0 < q^3 := pow_pos hq0 3 - have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by have hq0 := hq.1; positivity) hnlo - have hsize : 8*(m:ℝ) ≤ (n:ℝ)*q^2 := by - have ha := mul_le_mul_of_nonneg_right hnlo hq2p.le - have hb := mul_le_mul_of_nonneg_right hscale hm0.le - nlinarith - have hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4) := by - have hl := (abs_le.mp hdev).1 - have hr := (abs_le.mp hdev).2 - rw [←hmean] at hl hr - constructor - · nlinarith - · nlinarith - have ht0 : 0 < θ := by nlinarith [hθ.1] - have ht1 : θ < 1 := by nlinarith [hθ.2] - have hvlo : (n:ℝ)*q^2/8 ≤ (n:ℝ)*θ*(1-θ) := by - have hlow : (1:ℝ)/2 ≤ θ := by linarith [hθ.1] - have hhigh : q^2/4 ≤ 1-θ := by linarith [hθ.2] - have hp := mul_le_mul hlow hhigh (by positivity : (0:ℝ)≤q^2/4) ht0.le - have hp' := mul_le_mul_of_nonneg_left hp hn0.le - nlinarith - have hv : 1 ≤ (n:ℝ)*θ*(1-θ) := by - have hm32 : (32:ℝ) ≤ m := by exact_mod_cast hm - linarith - have hvhi : (n:ℝ)*θ*(1-θ) ≤ (m:ℝ)^2 := by - have hprod : θ*(1-θ) ≤ 1 := by nlinarith [sq_nonneg θ] - have hh := mul_le_mul_of_nonneg_left hprod hn0.le - nlinarith - have hsqrt : Real.sqrt ((n:ℝ)*θ*(1-θ)) ≤ (m:ℝ) := by - exact (Real.sqrt_le_iff).mpr ⟨hm0.le,hvhi⟩ - have hp0 : 0 < 1-q^2/2 := by linarith - have hden0 : 0 < (n:ℝ)*(1-q^2/2)*(q^2/2) := by positivity - have hden : q^3*(m:ℝ)^2/8 ≤ (n:ℝ)*(1-q^2/2)*(q^2/2) := by - have ha := mul_le_mul_of_nonneg_right hnlo hq2p.le - have hb := mul_le_mul_of_nonneg_right (show (1:ℝ)/2≤1-q^2/2 by linarith) - (mul_nonneg hn0.le (by positivity : (0:ℝ)≤q^2/2)) - nlinarith - have hdev2 : ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 ≤ 4*(m:ℝ)^2 := by - have h := pow_le_pow_left₀ (abs_nonneg _) hdev 2 - rw [sq_abs] at h - nlinarith - have hquot : ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / - ((n:ℝ)*(1-q^2/2)*(q^2/2)) ≤ 32/q^3 := by - apply (div_le_div_iff₀ hden0 hq3).mpr - have hh := mul_le_mul_of_nonneg_right hdev2 hq3.le - nlinarith - exact ⟨hθ,hv,hsqrt,hquot⟩ - -/-- Genuine binomial count mass in the window, uniformly in the vanishing -working deletion rate, with an absolute explicit exponential cost. -/ -theorem primitive_count_mass_lower {q : ℝ} {m n l : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) - (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) - (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : - Real.exp (-32/q^3)/(12*(m:ℝ)) ≤ binomialMass n (1-primitiveErasure q) l := by - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by have hq0 := hq.1; positivity) hnlo - let θ : ℝ := (l:ℝ)/n - have hmean : (n:ℝ)*θ=l := by dsimp [θ]; field_simp - obtain ⟨ht,hv,hsqrt,hquot⟩ := primitive_count_window hq hm hscale hnlo hnhi hmean hdev - have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.1,hq.2] - have hq2p : 0 < q^2 := sq_pos_of_pos hq.1 - have ht' : θ ∈ Set.Ioo 0 1 := ⟨by nlinarith [ht.1], by nlinarith [ht.2]⟩ - have hp : 1-q^2/2 ∈ Set.Ioo 0 1 := ⟨by linarith, by linarith⟩ - have hl : l ≤ n := by - have h := mul_le_mul_of_nonneg_left ht'.2.le hn0.le - rw [hmean,mul_one] at h - exact_mod_cast h - have hmass := binomialMass_near_mean_lower n l ht' hp hl hmean hv - have hden : 0 < 12*Real.sqrt ((n:ℝ)*θ*(1-θ)) := by positivity - have hexp : Real.exp (-32/q^3) ≤ Real.exp (-((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / - ((n:ℝ)*(1-q^2/2)*(1-(1-q^2/2)))) := by - apply Real.exp_le_exp.mpr - have he : 1-(1-q^2/2)=q^2/2 := by ring - rw [he] - simpa only [neg_div] using neg_le_neg hquot - calc - _ ≤ Real.exp (-((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / - ((n:ℝ)*(1-q^2/2)*(1-(1-q^2/2)))) / (12*Real.sqrt ((n:ℝ)*θ*(1-θ))) := by - exact div_le_div₀ (Real.exp_nonneg _) hexp hden (by nlinarith) - _ ≤ _ := by simpa only [primitiveErasure] using hmass - - -/-- The actual base count, with no redefinition of the working channel. -/ -def initialSideCount (q : ℝ) (m : ℕ) : ℕ := ⌊q*(m:ℝ)⌋₊ - -theorem initialSideCount_bounds {q : ℝ} {m : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) : - q*(m:ℝ)/2 ≤ (initialSideCount q m:ℝ) ∧ - (initialSideCount q m:ℝ) ≤ q*(m:ℝ) ∧ initialSideCount q m+1 ≤ m := by - have hm0 : (0:ℝ) ≤ m := Nat.cast_nonneg _ - have hm32 : (32:ℝ) ≤ m := by exact_mod_cast hm - have hq0 := hq.1 - have hq2 : q^2 ≤ 1 := by nlinarith [hq.2] - have hqm : 2 ≤ q*(m:ℝ) := by - have hh := mul_le_mul_of_nonneg_right hq2 (mul_nonneg hq0.le hm0) - nlinarith - have hlow := Nat.lt_floor_add_one (q*(m:ℝ)) - have hhigh := Nat.floor_le (mul_nonneg hq0.le hm0) - change q*(m:ℝ) < (initialSideCount q m:ℝ)+1 at hlow - change (initialSideCount q m:ℝ) ≤ q*(m:ℝ) at hhigh - refine ⟨by linarith,hhigh,?_⟩ - have hh := mul_le_mul_of_nonneg_right hq.2 hm0 - have : (initialSideCount q m:ℝ)+1 ≤ (m:ℝ) := by linarith - exact_mod_cast this - -/-- An injective enumeration of m common integer counts; no asymptotic -cardinality argument is left implicit. -/ -def commonCountIndex {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) (j : Fin m) : - Fin ((k+1)*m+1) := - ⟨⌊p*((k*m:ℕ):ℝ)⌋₊+j.val,by - have ha : (⌊p*((k*m:ℕ):ℝ)⌋₊:ℝ) ≤ ((k*m:ℕ):ℝ) := by - exact (Nat.floor_le (mul_nonneg hp.1 (Nat.cast_nonneg _))).trans - (mul_le_of_le_one_left (Nat.cast_nonneg _) hp.2) - have ha' : ⌊p*((k*m:ℕ):ℝ)⌋₊ ≤ k*m := by exact_mod_cast ha - have hj := j.isLt - rw [Nat.add_mul,one_mul] - omega⟩ - -theorem commonCountIndex_injective {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) : - Function.Injective (commonCountIndex (m:=m) k p hp) := by - intro a b h - have hv := congrArg Fin.val h - simp only [commonCountIndex,Nat.add_left_cancel_iff] at hv - exact Fin.ext hv - -theorem commonCountIndex_deviation {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) - (j : Fin m) : - |((commonCountIndex k p hp j).val:ℝ)-((k*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) ∧ - |((commonCountIndex k p hp j).val:ℝ)-(((k+1)*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) := by - have hm : (1:ℝ) ≤ m := by exact_mod_cast (Nat.succ_le_of_lt (Nat.zero_lt_of_lt j.isLt)) - have hj : (j.val:ℝ) < m := by exact_mod_cast j.isLt - have hj0 : (0:ℝ) ≤ j.val := Nat.cast_nonneg _ - have ha := Nat.floor_le (mul_nonneg hp.1 (Nat.cast_nonneg (k*m))) - have hb := Nat.lt_floor_add_one (p*((k*m:ℕ):ℝ)) - have hp0 := hp.1 - have hp1 := hp.2 - have hmp : 0 ≤ (m:ℝ)*p := mul_nonneg (Nat.cast_nonneg _) hp0 - have hmp' : (m:ℝ)*p ≤ m := mul_le_of_le_one_right (Nat.cast_nonneg _) hp1 - change |((⌊p*((k*m:ℕ):ℝ)⌋₊+j.val:ℕ):ℝ)-((k*m:ℕ):ℝ)*p| ≤ _ ∧ - |((⌊p*((k*m:ℕ):ℝ)⌋₊+j.val:ℕ):ℝ)-(((k+1)*m:ℕ):ℝ)*p| ≤ _ - have hn : (((k+1)*m:ℕ):ℝ)=((k*m:ℕ):ℝ)+(m:ℝ) := by push_cast; ring - rw [hn] - push_cast - constructor <;> apply abs_le.mpr <;> constructor <;> push_cast at ha hb <;> nlinarith - -end TraceReconstruction - - - -namespace TraceReconstruction -open scoped Classical - -theorem ordinaryRun_replicate (n : ℕ) : - (List.replicate n [false,true]).flatten = ordinaryRun n := by - induction n with - | zero => rfl - | succ n ih => simp [List.replicate_succ,ordinaryRun,ih] - -/-- Unique primitive parsing identifies the rank model with the literal -period words in the manuscript, not just a law on unlabeled locations. -/ -theorem primitive_period_word {m : ℕ} (off : Fin m) : - (List.ofFn (fun j : Fin m => primitiveBlock (decide (j=off)))).flatten = - initialPeriod m off.val := by - induction m with - | zero => exact Fin.elim0 off - | succ m ih => - refine Fin.cases ?_ (fun d => ?_) off - · simp [List.ofFn_succ,primitiveBlock,initialPeriod,ordinaryRun,ordinaryRun_replicate] - · rw [List.ofFn_succ,List.flatten_cons] - have hf : primitiveBlock (decide ((0:Fin (m+1))=d.succ))=[false,true] := by - simp [primitiveBlock,Ne.symm (Fin.succ_ne_zero d)] - rw [hf] - simp only [Fin.succ_inj] - rw [ih d] - simp [initialPeriod,ordinaryRun,Nat.sub_sub,Nat.add_comm] - -/-- Membership in the true periodic defect set is exactly the within-period -slot test, uniformly for all deterministic period types. -/ -theorem periodSlot_range_iff {u m : ℕ} (off : Fin u → Fin m) (i : Fin u) (j : Fin m) : - (⟨i.val*m+j.val,by - have hi := Nat.mul_le_mul_right m (Nat.succ_le_of_lt i.isLt) - have hj := j.isLt - nlinarith⟩ : Fin (u*m)) ∈ Set.range (periodSlot off) ↔ j=off i := by - constructor - · rintro ⟨a,ha⟩ - have hval := congrArg Fin.val ha - change a.val*m+(off a).val=i.val*m+j.val at hval - have hm : 0 < m := Nat.zero_lt_of_lt j.isLt - have hdiv := congrArg (fun k : ℕ => k/m) hval - simp only [Nat.mul_comm _ m, Nat.mul_add_div hm, Nat.div_eq_of_lt (off a).isLt, - Nat.div_eq_of_lt j.isLt,add_zero] at hdiv - have hai : a=i := Fin.ext hdiv - subst a - apply Fin.ext - omega - · intro h - refine ⟨i,?_⟩ - apply Fin.ext - simp only [periodSlot] - exact congrArg (fun k:Fin m => i.val*m+k.val) h.symm - -/-- The simulator's actual primitive list is the unpadded source gadget. -/ -theorem periodic_primitive_word {u m : ℕ} (off : Fin u → Fin m) : - (((List.ofFn (defectTypes (periodSlot off))).map primitiveBlock).flatten) = - periodString m u off := by - rw [List.map_ofFn,List.ofFn_mul] - rw [List.flatten_flatten,List.map_ofFn] - unfold periodString - congr 1 - apply congrArg List.ofFn - funext i - simp only [Function.comp_apply] - have he : (fun j:Fin m => primitiveBlock (defectTypes (periodSlot off) - ⟨i.val*m+j.val,by - have hi := Nat.mul_le_mul_right m (Nat.succ_le_of_lt i.isLt) - have hj := j.isLt - nlinarith⟩)) = fun j:Fin m => primitiveBlock (decide (j=off i)) := by - funext j - simp only [defectTypes,periodSlot_range_iff] - rw [he] - exact primitive_period_word (off i) - -theorem periodString_constant {u m : ℕ} (off : Fin m) : - periodString m u (fun _ => off) = pureAtomRun (initialPeriod m off.val) u := by - simp only [periodString,List.ofFn_const,pureAtomRun] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem primitive_count_admissible {q : ℝ} {m n l : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) - (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) - (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : - ∃ θ : ℝ, l ≤ n ∧ θ ∈ Set.Icc (1-q^2) (1-q^2/4) ∧ - (n:ℝ)*θ=l ∧ 1 ≤ (n:ℝ)*θ*(1-θ) := by - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hq0 := hq.1 - have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by positivity) hnlo - let θ : ℝ := (l:ℝ)/n - have hmean : (n:ℝ)*θ=l := by dsimp [θ]; field_simp - obtain ⟨ht,hv,_,_⟩ := primitive_count_window hq hm hscale hnlo hnhi hmean hdev - have hl : l ≤ n := by - have ht1 : θ ≤ 1 := by nlinarith [ht.2,sq_nonneg q] - have hh := mul_le_mul_of_nonneg_left ht1 hn0.le - rw [hmean,mul_one] at hh - exact_mod_cast hh - exact ⟨θ,hl,ht,hmean,hv⟩ - -/-- The common-mass constant depends only on the working deletion rate. -/ -def initialOverlapLower (q : ℝ) : ℝ := - Real.exp (-(32+3*primitivePeriodConstant)/q^3)/1536 - -theorem initialOverlapLower_pos (q : ℝ) : 0 < initialOverlapLower q := by - unfold initialOverlapLower - positivity - -theorem initialOverlapLower_lt_eighth {q : ℝ} (hq : 0 < q) : - initialOverlapLower q < 1/8 := by - have hx : -(32+3*primitivePeriodConstant)/q^3 ≤ 0 := by - have hc := primitivePeriodConstant_nonneg - apply div_nonpos_of_nonpos_of_nonneg <;> nlinarith [pow_pos hq 3] - have he : Real.exp (-(32+3*primitivePeriodConstant)/q^3) ≤ 1 := by - simpa using Real.exp_le_exp.mpr hx - unfold initialOverlapLower - linarith - -/-- Unconditioned common mass of the two genuine count-and-mark simulators. -This includes all retained counts, not a conditioned or changed channel. -/ -theorem initial_counted_overlap {q : ℝ} {m : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) (off : Fin m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) : - let k := initialSideCount q m - initialOverlapLower q ≤ FiniteLaw.overlap - (countedPrimitiveLaw (N:=(k+1)*m) (Nat.mul_le_mul_right m (Nat.le_succ k)) - ⟨hq.1,by linarith [hq.2]⟩ (defectTypes (periodSlot (u:=k) (fun _ => off)))) - (countedPrimitiveLaw (N:=(k+1)*m) le_rfl - ⟨hq.1,by linarith [hq.2]⟩ (defectTypes (periodSlot (u:=k+1) (fun _ => off)))) := by - let k := initialSideCount q m - let N := (k+1)*m - have hq0 := hq.1 - have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ - have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) - have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.2] - let p := 1-primitiveErasure q - have hp : p ∈ Set.Icc 0 1 := primitiveRetention_mem hqi - have hp' : p=1-q^2/2 := rfl - obtain ⟨hklo,hkhi,hk1⟩ := initialSideCount_bounds hq hm hscale - change q*(m:ℝ)/2 ≤ (k:ℝ) at hklo - change (k:ℝ) ≤ q*(m:ℝ) at hkhi - change k+1 ≤ m at hk1 - have hk : k ≤ m := by omega - have hnlo : q*(m:ℝ)^2/2 ≤ ((k*m:ℕ):ℝ) := by - have hh := mul_le_mul_of_nonneg_right hklo hm0.le - push_cast - nlinarith - have hnhi : ((k*m:ℕ):ℝ) ≤ (m:ℝ)^2 := by - exact_mod_cast (show k*m ≤ m^2 by simpa [pow_two] using Nat.mul_le_mul_right m hk) - have hNlo : q*(m:ℝ)^2/2 ≤ (N:ℝ) := by - exact hnlo.trans (by exact_mod_cast Nat.mul_le_mul_right m (Nat.le_succ k)) - have hNhi : (N:ℝ) ≤ (m:ℝ)^2 := by - exact_mod_cast (show N ≤ m^2 by simpa [N,pow_two] using Nat.mul_le_mul_right m hk1) - have hqm : 1 ≤ q*(m:ℝ) := by - have hh := mul_le_mul_of_nonneg_right (show q^2≤1 by linarith) (mul_nonneg hq0.le hm0.le) - nlinarith - have hrate : (k:ℝ)/(m:ℝ)+((k+1:ℕ):ℝ)/(m:ℝ) ≤ 3*q := by - rw [←add_div] - apply (div_le_iff₀ hm0).mpr - push_cast - nlinarith - have harg : primitivePeriodConstant/q^4*((k:ℝ)/m+((k+1:ℕ):ℝ)/m) ≤ - 3*primitivePeriodConstant/q^3 := by - calc - _ ≤ primitivePeriodConstant/q^4*(3*q) := - mul_le_mul_of_nonneg_left hrate (div_nonneg primitivePeriodConstant_nonneg (by positivity)) - _ = _ := by field_simp - let C₁ := boundedCountLaw (N:=N) (Nat.mul_le_mul_right m (Nat.le_succ k)) p hp - let C₂ := boundedCountLaw (N:=N) le_rfl p hp - let K := boundedConditionalPrimitiveLaw hqi (defectTypes (periodSlot (u:=k) (fun _ => off))) (N:=N) - let L := boundedConditionalPrimitiveLaw hqi (defectTypes (periodSlot (u:=k+1) (fun _ => off))) (N:=N) - let f : Fin (N+1) → ℝ := fun l => min (C₁.mass l) (C₂.mass l) * FiniteLaw.overlap (K l) (L l) - let a : ℝ := Real.exp (-32/q^3)/(12*(m:ℝ)) - let b : ℝ := Real.exp (-(3*primitivePeriodConstant)/q^3)/128 - have ha0 : 0 ≤ a := by dsimp [a]; positivity - have hb0 : 0 ≤ b := by dsimp [b]; positivity - have hf0 : ∀l, 0 ≤ f l := fun l => - mul_nonneg (le_min (C₁.nonneg l) (C₂.nonneg l)) (FiniteLaw.overlap_nonneg _ _) - let ix : Fin m → Fin (N+1) := commonCountIndex k p hp - have hterm : ∀j : Fin m, a*b ≤ f (ix j) := by - intro j - let l := (ix j).val - have hd := commonCountIndex_deviation k p hp j - change |(l:ℝ)-((k*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) ∧ |(l:ℝ)-(N:ℝ)*p| ≤ 2*(m:ℝ) at hd - rw [hp'] at hd - obtain ⟨θ,hl,hθ,hmean,hv⟩ := primitive_count_admissible hq hm hscale hnlo hnhi hd.1 - obtain ⟨θ',hl',hθ',hmean',hv'⟩ := primitive_count_admissible hq hm hscale hNlo hNhi hd.2 - have hm1 := primitive_count_mass_lower hq hm hscale hnlo hnhi hd.1 - have hm2 := primitive_count_mass_lower hq hm hscale hNlo hNhi hd.2 - have hmin : a ≤ min (C₁.mass (ix j)) (C₂.mass (ix j)) := le_min hm1 hm2 - have hc := conditionalPeriod_overlap hl hl' hm hk hk1 hq hθ hθ' hmean hmean' hv hv' - (fun _ => off) (fun _ => off) (fun _ => hoff) (fun _ => hoff) - (fun _ _ => by simp) (fun _ _ => by simp) - have hb : b ≤ FiniteLaw.overlap (K (ix j)) (L (ix j)) := by - dsimp only [K,L,boundedConditionalPrimitiveLaw] - rw [dite_eq_left hl,dite_eq_left hl'] - refine le_trans ?_ hc - apply div_le_div_of_nonneg_right _ (by norm_num : (0:ℝ)≤128) - apply Real.exp_le_exp.mpr - simpa only [neg_div] using neg_le_neg harg - exact mul_le_mul hmin hb hb0 (le_min (C₁.nonneg _) (C₂.nonneg _)) - have hsub : (∑j : Fin m, f (ix j)) ≤ ∑l : Fin (N+1), f l := by - have hi := commonCountIndex_injective (m:=m) k p hp - calc - _ = ∑l ∈ Finset.univ.image ix, f l := by - rw [Finset.sum_image] - exact fun a _ b _ hab => hi hab - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun l _ _ => hf0 l) - have hsum : (m:ℝ)*(a*b) ≤ ∑l : Fin (N+1), f l := by - calc - _ = ∑_j : Fin m, a*b := by simp - _ ≤ ∑j : Fin m, f (ix j) := Finset.sum_le_sum (fun j _ => hterm j) - _ ≤ _ := hsub - have he : (m:ℝ)*(a*b)=initialOverlapLower q := by - dsimp [a,b,initialOverlapLower] - rw [div_mul_div_comm,←Real.exp_add] - have hx : -32/q^3 + -(3*primitivePeriodConstant)/q^3 = -(32+3*primitivePeriodConstant)/q^3 := by ring - rw [hx] - field_simp - ring - rw [he] at hsum - exact hsum.trans (FiniteLaw.overlap_sigma_lower C₁ C₂ K L) - -/-- Data processing for common exact simulators, stated as a common-mass -inequality and allowing unequal original lengths. -/ -theorem simulations_overlap_le {α : Type*} [Fintype α] {q : ℝ} - (hq : q ∈ Set.Icc 0 1) (P Q : FiniteLaw α) (decode : α → List Bool) - (x y : List Bool) (hP : SimulatesTrace q P decode x) - (hQ : SimulatesTrace q Q decode y) : - P.overlap Q ≤ listTraceOverlap q hq x y := by - have h := approximations_trace_tv hq P Q decode x y 0 0 - (max x.length y.length) (le_max_left _ _) (le_max_right _ _) - hP.approximate hQ.approximate - simp only [add_zero] at h - unfold listTraceOverlap - rw [FiniteLaw.overlap_eq_one_sub_tv, FiniteLaw.overlap_eq_one_sub_tv] - linarith - -/-- The initial hidden-bit overlap for ordinary complete deletion traces of -consecutive pure runs. This is the unconditioned original channel. -/ -theorem initial_pure_trace_overlap {q : ℝ} {m : ℕ} - (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) - (hscale : 16 ≤ q^3*(m:ℝ)) (off : Fin m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) : - let k := initialSideCount q m - initialOverlapLower q ≤ listTraceOverlap q ⟨hq.1.le, by linarith [hq.2]⟩ - (pureAtomRun (initialPeriod m off.val) k) - (pureAtomRun (initialPeriod m off.val) (k+1)) := by - let k := initialSideCount q m - have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ - have hca := countedPrimitiveLaw_simulates (N:=(k+1)*m) - (Nat.mul_le_mul_right m (Nat.le_succ k)) hqi - (defectTypes (periodSlot (u:=k) (fun _ => off))) - have hcb := countedPrimitiveLaw_simulates (N:=(k+1)*m) le_rfl hqi - (defectTypes (periodSlot (u:=k+1) (fun _ => off))) - rw [periodic_primitive_word,periodString_constant] at hca hcb - exact (initial_counted_overlap hq hm hscale off hoff).trans - (simulations_overlap_le ⟨hq.1.le,by linarith [hq.2]⟩ _ _ _ _ _ hca hcb) - -end TraceReconstruction - - - -/-! From the actual displaced period words to their conditional oracle -moments. The coefficient bounds are the rank kernels, -not assumptions on an abstract pair. -/ -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- An interior period slot admits the three literal shifts. -/ -def oneStepOffset {m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : Fin m := - ⟨off.val+a.val-1,by have ha := a.isLt; omega⟩ - -theorem oneStepOffset_add_one {m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : - (oneStepOffset off hi a).val+1=off.val+a.val := by - dsimp [oneStepOffset] - omega - -theorem oneStepOffset_distance {m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : - |((oneStepOffset off hi a).val:ℝ)-(off.val:ℝ)| ≤ 1 := by - have he := oneStepOffset_add_one off hi a - have ha : (a.val:ℝ) ≤ 2 := by exact_mod_cast (show a.val ≤ 2 by omega) - have ha0 : (0:ℝ) ≤ a.val := Nat.cast_nonneg _ - have he' : ((oneStepOffset off hi a).val:ℝ)+1=(off.val:ℝ)+a.val := by exact_mod_cast he - rw [abs_le] - constructor <;> linarith - -theorem constantPeriod_safe {u m : ℕ} (hm : 3 ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) : - SafeTaggedTuple (periodSlot (u:=u) (fun _ => off)) := by - constructor - · intro i - change 1 ≤ i.val*m+off.val ∧ i.val*m+off.val+1 nlinarith [hi.1,hi.2] - · intro i j hij - change i.val*m+off.val+3 ≤ j.val*m+off.val - have h := Nat.mul_le_mul_right m (Nat.succ_le_of_lt hij) - nlinarith - -theorem shifted_constantPeriod {u m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (a : Fin u → Fin 3) : - shiftedTag (periodSlot (fun _ => off)) hsafe a = - periodSlot (fun i => oneStepOffset off hi (a i)) := by - funext i - apply Fin.ext - change i.val*m+off.val+(a i).val-1=i.val*m+(off.val+(a i).val-1) - omega - -/-- Arbitrary deterministic motif orientations remain genuine one-defect -periods with the exact geometry used in the high-degree rank bound. -/ -theorem signedPeriod_geometry {u m : ℕ} (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val + 1 < m) - (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (s : ℕ) (X : ℤ) (τ : ℝ) : - ∃ off' : Fin u → Fin m, - signedPeriodDefects off hsafe s X τ = periodSlot off' ∧ - (∀j, |((off' j).val:ℝ)-(m:ℝ)/2| ≤ 3) ∧ - (∀j k, |((off' j).val:ℝ)-(off' k).val| ≤ 2) := by - let a : Fin u → Fin 3 := fun j => - motifShift (motifIndicator s ((j.val:ℤ)-X)) ((prouhetSeries s).coeff ((j.val:ℤ)-X)) τ - refine ⟨fun j => oneStepOffset off hi (a j),shifted_constantPeriod off hi hsafe a,?_,?_⟩ - · intro j - have h := oneStepOffset_distance off hi (a j) - have ht := abs_add_le (((oneStepOffset off hi (a j)).val:ℝ)-(off.val:ℝ)) - ((off.val:ℝ)-(m:ℝ)/2) - rw [sub_add_sub_cancel] at ht - linarith - · intro j k - have hj := oneStepOffset_distance off hi (a j) - have hk := oneStepOffset_distance off hi (a k) - rw [abs_le] at hj hk ⊢ - constructor <;> linarith - - -/-- Every moment of the actual primitive score has the source uniform -bound. -/ -theorem primitive_score_evenMoment {q : ℝ} (hq : q∈Set.Ioo 0 1) (k : ℕ) : - (primitiveMarkLaw q hq false).expect (fun z => |primitiveScore q z|^(2*k)) ≤ - (2/q)^(2*k) := by - calc - _ ≤ (primitiveMarkLaw q hq false).expect (fun _ => (2/q)^(2*k)) := by - apply Finset.sum_le_sum - intro z _ - exact mul_le_mul_of_nonneg_left - (pow_le_pow_left₀ (abs_nonneg _) (primitive_score_bound hq z) _) ((primitiveMarkLaw q hq false).nonneg z) - _ = _ := (primitiveMarkLaw q hq false).expect_const _ - -/-- Hypercontractivity now applies directly to the actual signed initial -density difference under its ordinary-mark reference law. -/ -theorem initial_moment_of_energy {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (s k : ℕ) (hk : 1 ≤ k) {q : ℝ} (hq : q∈Set.Ioo 0 1) : - ((primitiveMarkLaw q hq false).product l).evenMomentSq - (multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ) (primitiveScore q)) k ≤ - multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ) ((6*(2*k:ℕ):ℝ)*(2/q)) := by - apply multilinear_moment_sq_scaled _ _ k hk - · exact primitive_score_centered hq - · exact div_pos (by norm_num) hq.1 - · exact primitive_score_evenMoment hq k - - -/-- Jensen's inequality on each homogeneous degree. -/ -theorem degree_square_mixture_le {Ω : Type*} [Fintype Ω] {n : ℕ} - (P : FiniteLaw Ω) (A : Ω → (Fin n → Bool) → ℝ) (r : ℕ) : - (∑σ : Fin n → Bool, if monomialDegree σ=r then - (P.expect (fun ω => A ω σ))^2 else 0) ≤ - P.expect (fun ω => ∑σ : Fin n → Bool, - if monomialDegree σ=r then (A ω σ)^2 else 0) := by - unfold FiniteLaw.expect - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro σ _ - by_cases h : monomialDegree σ=r - · simp only [ite_eq_left h] - have H := weighted_sum_sq_le Finset.univ P.mass (fun ω => A ω σ) (fun ω => P.nonneg ω) - simpa only [P.total,one_mul] using H - · simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero,le_refl] - -theorem degree_square_sub_le {n : ℕ} (A B : (Fin n → Bool) → ℝ) (r : ℕ) : - (∑σ : Fin n → Bool, if monomialDegree σ=r then (A σ-B σ)^2 else 0) ≤ - 2*(∑σ : Fin n → Bool, if monomialDegree σ=r then A σ^2 else 0)+ - 2*(∑σ : Fin n → Bool, if monomialDegree σ=r then B σ^2 else 0) := by - simp only [Finset.mul_sum,←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro σ _ - split_ifs <;> nlinarith [sq_nonneg (A σ+B σ)] - -theorem mixedMotifCoefficient_expect {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) (σ : Fin l → Bool) : - mixedMotifCoefficient hl off hsafe π s τ σ = - (seriesProbabilityLaw π hπ hπsum).expect (fun X => - averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) - (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X.val τ))) σ) := by - unfold mixedMotifCoefficient FiniteLaw.expect seriesProbabilityLaw - exact (Finset.sum_coe_sort _ _).symm - -theorem mixedMotifCoefficient_empty {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (τ : ℝ) : - mixedMotifCoefficient hl off hsafe π s τ (fun _ => false)=1 := by - simp only [mixedMotifCoefficient,averagedCoefficient_empty,mul_one,hπsum] - -/-- Uniform high-degree estimate after the real hidden-anchor mixture. -/ -theorem mixedMotif_degree_le {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hru : r ≤ u) (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : - (∑σ : Fin l → Bool, if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s τ σ)^2 else 0) ≤ - ((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := by - simp_rw [mixedMotifCoefficient_expect hl off hsafe π hπ hπsum] - refine (degree_square_mixture_le _ _ r).trans ?_ - calc - _ ≤ (seriesProbabilityLaw π hπ hπsum).expect (fun _ => - ((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r) := by - apply FiniteLaw.expect_mono - intro X - obtain ⟨d,hd,hnear,hclose⟩ := signedPeriod_geometry off hi hoff hsafe s X.val τ - rw [hd] - exact period_degree_square_sum hl hr hru hm hum hq hθ hmean hv d hnear hclose - _ = _ := FiniteLaw.expect_const _ _ - -/-- There are never more selected ranks than actual defect periods, even -in the hidden-anchor mixture. -/ -theorem mixedMotif_degree_vanish {u m l r : ℕ} (hl : l ≤ u*m) (hru : u < r) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) : - (∑σ : Fin l → Bool, if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s τ σ)^2 else 0)=0 := by - apply le_antisymm - · simp_rw [mixedMotifCoefficient_expect hl off hsafe π hπ hπsum] - refine (degree_square_mixture_le _ _ r).trans ?_ - simp_rw [defect_degree_bound hl _ (signedPeriodDefects_strictMono off hsafe s _ τ) hru] - rw [FiniteLaw.expect_const] - · exact Finset.sum_nonneg (fun σ _ => by split_ifs <;> positivity) - -/-- The signed difference has no constant term. -/ -theorem signedMotif_degree_zero {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) : - (∑σ : Fin l → Bool, if monomialDegree σ=0 then - (mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0)=0 := by - simp_rw [monomialDegree_eq_zero_iff] - simp [mixedMotifCoefficient_empty hl off hsafe π hπsum] - -/-- Low-degree cancellation is for exactly the coefficients of the -conditional motif densities, without a rank surrogate at the boundary. -/ -theorem signedMotif_degree_cancellation {u m l r : ℕ} - (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ)<(u:ℝ)/(3*(r+1:ℝ))) : - (∑σ : Fin l → Bool, if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0) ≤ - 8*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - signedPatternBound u m r s π θ k else 0) + - 2*((Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by - refine (sum_degree_coeff_sq_le _).trans ?_ - simp_rw [mixedMotifCoefficient_rank_difference] - exact initial_signed_energy hu hm hr hl off hoff hsafe π hπ hπsum s hcentral - hθ hhalf hmean hv hM - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- A finite tail is no larger than the full geometric tail. -/ -theorem finite_geometric_tail_le {a : ℝ} (ha : 0 ≤ a) (ha1 : a < 1) (N R : ℕ) : - (∑r ∈ Finset.range N, if R ≤ r then a^r else 0) ≤ a^R/(1-a) := by - have ht : HasSum (fun n : ℕ => a^(n+R)) (a^R/(1-a)) := by - simpa only [pow_add, mul_comm, div_eq_mul_inv] using - (hasSum_geometric_of_lt_one ha ha1).mul_left (a^R) - have hsum : (∑r ∈ Finset.range N, if R ≤ r then a^r else 0) = - ∑r ∈ (Finset.range N).filter (R ≤ ·), a^r := by - rw [Finset.sum_filter] - rw [hsum] - calc - _ = ∑r ∈ ((Finset.range N).filter (R ≤ ·)).image (fun r => r-R), a^(r+R) := by - rw [Finset.sum_image] - · apply Finset.sum_congr rfl - intro r hr - rw [Nat.sub_add_cancel (Finset.mem_filter.mp hr).2] - · intro r hr s hs h - dsimp only at h - have hrR := (Finset.mem_filter.mp hr).2 - have hsR := (Finset.mem_filter.mp hs).2 - omega - _ ≤ _ := by - rw [←ht.tsum_eq] - exact ht.summable.sum_le_tsum _ (fun _ _ => by positivity) - -/-- Splitting the exact homogeneous expansion, not a surrogate polynomial. -/ -theorem multilinearEnergy_low_high {n R : ℕ} (A : (Fin n → Bool) → ℝ) - (w a K : ℝ) (hw : 0 ≤ w) (ha : 0 ≤ a) (ha1 : a < 1) (hK : 0 ≤ K) - (L : ℕ → ℝ) - (hlow : ∀r < R, (∑σ : Fin n → Bool, if monomialDegree σ=r then A σ^2 else 0) ≤ L r) - (hhigh : ∀r, R ≤ r → w^(2*r)*(∑σ : Fin n → Bool, - if monomialDegree σ=r then A σ^2 else 0) ≤ K*a^r) - (hL : ∀r, 0 ≤ L r) : - multilinearEnergy A w ≤ (∑r ∈ Finset.range R, w^(2*r)*L r)+K*a^R/(1-a) := by - rw [multilinearEnergy_degrees] - calc - _ ≤ ∑r ∈ Finset.range (n+1), - ((if r < R then w^(2*r)*L r else 0)+(if R ≤ r then K*a^r else 0)) := by - apply Finset.sum_le_sum - intro r _ - by_cases h : r < R - · simp only [ite_eq_left h,ite_eq_right (show ¬R ≤ r by omega),add_zero] - exact mul_le_mul_of_nonneg_left (hlow r h) (by positivity) - · simp only [ite_eq_right h,ite_eq_left (show R ≤ r by omega),zero_add] - exact hhigh r (by omega) - _ ≤ _ := by - rw [Finset.sum_add_distrib] - apply add_le_add - · rw [←Finset.sum_filter] - exact Finset.sum_le_sum_of_subset_of_nonneg - (by intro r hr; exact Finset.mem_range.mpr (Finset.mem_filter.mp hr).2) - (fun r _ _ => mul_nonneg (by positivity) (hL r)) - · have he : (∑r ∈ Finset.range (n+1), if R ≤ r then K*a^r else 0)= - K*∑r ∈ Finset.range (n+1), if R ≤ r then a^r else 0 := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro r _ - split_ifs <;> ring - rw [he,mul_div_assoc] - exact mul_le_mul_of_nonneg_left (finite_geometric_tail_le ha ha1 _ _) hK - -/-- The signed high-degree bound includes the true anchor mixture. -/ -theorem signedMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : - w^(2*r)*(∑σ : Fin l → Bool, if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0) ≤ - 4*(w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by - have hw0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity - have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] - have hb := degree_square_sub_le (mixedMotifCoefficient hl off hsafe π s 1) - (mixedMotifCoefficient hl off hsafe π s (-1)) r - by_cases hru : r ≤ u - · have hplus := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum - s 1 hq hθ hmean hv - have hminus := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum - s (-1) hq hθ hmean hv - have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by - apply Real.sqrt_le_sqrt - apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) - have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr - nlinarith - calc - _ ≤ w^(2*r)*(4*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r) := - mul_le_mul_of_nonneg_left (by linarith) (by rw [pow_mul]; positivity) - _ ≤ w^(2*r)*(4*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r) := by - gcongr - _ = _ := by rw [pow_mul, mul_pow, mul_pow]; ring - · rw [mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s 1, - mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s (-1)] at hb - have hz : (∑σ : Fin l → Bool, if monomialDegree σ=r then - (mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0)=0 := by - apply le_antisymm (by linarith) - exact Finset.sum_nonneg (fun σ _ => by split_ifs <;> positivity) - rw [hz,mul_zero] - positivity - -/-- Explicit low-degree majorant from the signed finite-difference estimate. -/ -def signedInitialDegreeBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : ℝ := - if r=0 then 0 else - 8*(Fintype.card (Fin r → GapDifference):ℝ)* - (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - signedPatternBound u m r s π θ k else 0) + - 2*((Fintype.card (IncreasingTuple u r):ℝ)* - (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 - -theorem signedInitialDegreeBound_nonneg (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : - 0 ≤ signedInitialDegreeBound u m r s π θ l := by - unfold signedInitialDegreeBound - split_ifs - · exact le_rfl - · apply add_nonneg _ (by positivity) - apply mul_nonneg (by positivity) - apply Finset.sum_nonneg - intro k _ - split_ifs - · unfold signedPatternBound - split_ifs <;> apply mul_nonneg _ (seriesL2Sq_nonneg _) - all_goals dsimp only [periodDifferencePrefactor, lengthDifferenceConstant, periodCentralSumConstant, periodBoundedSumConstant] - all_goals positivity - · exact le_rfl - -/-- A fully finite norm estimate for the actual low and high degree pieces. -Only numerical admissible-count and geometric conditions remain to be chosen. -/ -theorem signed_initial_full_energy {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) - (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (hcentral : CentralMotifSupport u s π) - {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) - (hw : 0 ≤ w) (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : - multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- - mixedMotifCoefficient hl off hsafe π s (-1) σ) w ≤ - (∑r ∈ Finset.range R, w^(2*r)*signedInitialDegreeBound u m r s π θ l)+ - 4*(w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^R / - (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by - have hq2 : q^2 ≤ (1/4:ℝ) := by - calc q^2 ≤ (1/2:ℝ)^2 := pow_le_pow_left₀ hq.1.le hq.2 2 - _ = _ := by norm_num - have hθ0 : θ∈Set.Ioo 0 1 := by constructor <;> nlinarith [hq.1,hθ.1,hθ.2] - have hhalf : 1/2 ≤ θ := by nlinarith [hθ.1] - apply multilinearEnergy_low_high _ w _ 4 hw (by positivity [rankSchurConstant_pos,hq.1]) ha - (by norm_num) (signedInitialDegreeBound u m · s π θ l) _ _ - (fun r => signedInitialDegreeBound_nonneg _ _ _ _ _ _ _) - · intro r hr - by_cases hr0 : r=0 - · subst r - rw [signedMotif_degree_zero hl off hsafe π hπsum s] - exact signedInitialDegreeBound_nonneg _ _ _ _ _ _ _ - · have hMr : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ)) := by - apply hM.trans_le - apply div_le_div_of_nonneg_left (by positivity) (by positivity) - exact mul_le_mul_of_nonneg_left (by exact_mod_cast (show r+1 ≤ R+1 by omega)) (by norm_num) - simpa only [signedInitialDegreeBound,ite_eq_right hr0] using - signedMotif_degree_cancellation hu hm (Nat.pos_of_ne_zero hr0) hl off - (hoff.trans (by norm_num)) hsafe π hπ hπsum s hcentral hθ0 hhalf hmean hv hMr - · intro r hr - exact signedMotif_degree_geometric hl (by omega) (by omega) hum off hi hoff hsafe π hπ - hπsum s hq hθ hmean hv w - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -theorem primitive_reference_mass_pos {q : ℝ} (hq : q∈Set.Ioo 0 1) (z : PrimitiveMark) : - 0 < (primitiveMarkLaw q hq false).mass z := by - change 0 < primitiveMarkMass q false z - apply div_pos _ (primitive_retain_pos hq) - fin_cases z <;> simp [ordinaryPrimitiveMass,primitiveErasure] <;> nlinarith [hq.1,hq.2] - -theorem primitive_product_mass_pos {q : ℝ} (hq : q∈Set.Ioo 0 1) {l : ℕ} - (x : Fin l → PrimitiveMark) : 0 < ((primitiveMarkLaw q hq false).product l).mass x := -by - change 0 < ∏ i, (primitiveMarkLaw q hq false).mass (x i) - exact Finset.prod_pos (fun _ _ => primitive_reference_mass_pos hq _) - -/-- The density in the actual base experiment, not an independent model. -/ -def initialMotifDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (τ q : ℝ) : (Fin l → PrimitiveMark) → ℝ := - multilinear (mixedMotifCoefficient hl off hsafe π s τ) (primitiveScore q) - -theorem initialMotifDensity_nonneg {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) (x : Fin l → PrimitiveMark) : - 0 ≤ initialMotifDensity hl off hsafe π s τ q x := by - have h := (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).nonneg x - rw [conditionalMotifLaw_density] at h - exact nonneg_of_mul_nonneg_right h (primitive_product_mass_pos hq x) - -theorem initialMotifDensity_mean {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : - ((primitiveMarkLaw q hq false).product l).expect (initialMotifDensity hl off hsafe π s τ q)=1 := by - have h := (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).total - simpa only [conditionalMotifLaw_density,FiniteLaw.expect,initialMotifDensity] using h - -theorem initialMotifLaw_withDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : - conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ = - ((primitiveMarkLaw q hq false).product l).withDensity - (initialMotifDensity hl off hsafe π s τ q) - (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s τ hq) - (initialMotifDensity_mean hl off hsafe π hπ hπsum s τ hq) := by - apply FiniteLaw.ext - funext x - exact conditionalMotifLaw_density hl off hsafe hq π hπ hπsum s τ x - -theorem multilinear_sub {α : Type*} {l : ℕ} (A B : (Fin l → Bool) → ℝ) - (Z : α → ℝ) (x : Fin l → α) : - multilinear (fun σ => A σ-B σ) Z x = multilinear A Z x-multilinear B Z x := by - simp only [multilinear,sub_mul,Finset.sum_sub_distrib] - -/-- The constant-term deletion of a polynomial. -/ -def nonconstantCoefficient {l : ℕ} (A : (Fin l → Bool) → ℝ) (σ : Fin l → Bool) : ℝ := - if σ=(fun _ => false) then 0 else A σ - -theorem nonconstant_multilinear {α : Type*} {l : ℕ} (A : (Fin l → Bool) → ℝ) - (Z : α → ℝ) (x : Fin l → α) : - multilinear (nonconstantCoefficient A) Z x=multilinear A Z x-A (fun _ => false) := by - have he : ∀σ, nonconstantCoefficient A σ=A σ-(if σ=(fun _ => false) then A σ else 0) := by - intro σ - by_cases h : σ=(fun _ => false) <;> simp [nonconstantCoefficient,h] - rw [show nonconstantCoefficient A = (fun σ => A σ-(if σ=(fun _ => false) then A σ else 0)) from funext he, multilinear_sub] - congr 1 - simp [multilinear,ite_mul] - -theorem nonconstant_degree_zero {l : ℕ} (A : (Fin l → Bool) → ℝ) : - (∑σ : Fin l → Bool, if monomialDegree σ=0 then (nonconstantCoefficient A σ)^2 else 0)=0 := by - simp [monomialDegree_eq_zero_iff,nonconstantCoefficient] - -theorem nonconstant_degree_pos {l r : ℕ} (A : (Fin l → Bool) → ℝ) (hr : 0 < r) : - (∑σ : Fin l → Bool, if monomialDegree σ=r then (nonconstantCoefficient A σ)^2 else 0)= - ∑σ : Fin l → Bool, if monomialDegree σ=r then (A σ)^2 else 0 := by - apply Finset.sum_congr rfl - intro σ _ - by_cases h : σ=(fun _ => false) - · subst σ - simp [monomialDegree,Ne.symm (Nat.ne_of_gt hr)] - · simp [nonconstantCoefficient,h] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -theorem mixedMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : - w^(2*r)*(∑σ : Fin l → Bool, if monomialDegree σ=r then - mixedMotifCoefficient hl off hsafe π s τ σ^2 else 0) ≤ - (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by - have hw : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity - have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] - by_cases hru : r ≤ u - · have hb := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum - s τ hq hθ hmean hv - have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by - apply Real.sqrt_le_sqrt - apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) - have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr - nlinarith - calc - _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := - mul_le_mul_of_nonneg_left hb hw - _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by gcongr - _ = _ := by rw [pow_mul,mul_pow,mul_pow]; ring - · rw [mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s τ,mul_zero] - positivity - -/-- Clipping input: the actual conditional density is close to one. -/ -theorem initial_centered_energy {u m l : ℕ} (hl : l ≤ u*m) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s : ℕ) (τ : ℝ) {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : 0 ≤ w) (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : - multilinearEnergy (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) w ≤ - (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) / - (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by - have H := multilinearEnergy_low_high (R:=1) - (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) w _ 1 hw - (by positivity [rankSchurConstant_pos,hq.1]) ha (by norm_num) (fun _ => 0) - (fun r hr => by - have he : r=0 := by omega - subst r - rw [nonconstant_degree_zero]) - (fun r hr => by - rw [nonconstant_degree_pos _ (by omega)] - simpa only [one_mul] using mixedMotif_degree_geometric hl (by omega) hm hum off - hi hoff hsafe π hπ hπsum s τ hq hθ hmean hv w) - (fun _ => le_rfl) - simpa using H - -theorem initial_centered_moment {u m l : ℕ} (hl : l ≤ u*m) - (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) - (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) - (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) - (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) - (s k : ℕ) (hk : 1 ≤ k) (τ : ℝ) {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) - (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) - (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) - (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : - ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq - (fun x => initialMotifDensity hl off hsafe π s τ q x-1) k ≤ - (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) / - (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by - have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ - have he : (fun x => initialMotifDensity hl off hsafe π s τ q x-1) = - multilinear (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) - (primitiveScore q) := by - funext x - rw [nonconstant_multilinear,mixedMotifCoefficient_empty hl off hsafe π hπsum] - rfl - rw [he] - apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk (primitive_score_centered hq') - (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans - rw [←hw] - apply initial_centered_energy hl hm hum off hi hoff hsafe π hπ hπsum s τ hq hθ hmean hv _ ha - rw [hw]; positivity [hq.1] - -end TraceReconstruction - -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Oracles + +namespace OAI + +/-! +# InitialOverlap + +Literal periods, count overlap, initial low/high energies, genuine densities, and centered moment bounds. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem primitive_one_add_score_nonneg {q : ℝ} (hq : q ∈ Set.Ioo 0 1) + (a : PrimitiveMark) : 0 ≤ 1 + primitiveScore q a := by + have hq1 : 1 ≤ 1/q := (le_div_iff₀ hq.1).mpr (by simpa using hq.2.le) + have hq0 := hq.1 + fin_cases a <;> norm_num [primitiveScore] <;> linarith [show 2/q=2*(1/q) by ring] + +/-- Exact conditional law of the genuine periodic primitive observation. -/ +theorem conditionalPeriodLaw_density {u m l : ℕ} (hl : l ≤ u*m) + {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (off : Fin u → Fin m) (x : Fin l → PrimitiveMark) : + (conditionalPrimitiveLaw hl q hq (defectTypes (periodSlot off))).mass x = + ((primitiveMarkLaw q hq false).product l).mass x * + averagedDensity (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off))) (primitiveScore q) x := by + rw [conditionalPrimitiveLaw_density] + congr 2 + funext S + exact defectTypes_atRank (periodSlot off) S + +/-- Absolute constant in the conditional second-moment exponent. -/ +def primitivePeriodConstant : ℝ := 36*rankSchurConstant^2 + +theorem primitivePeriodConstant_nonneg : 0 ≤ primitivePeriodConstant := by + unfold primitivePeriodConstant + positivity + +theorem conditionalPeriod_second_moment {u m l : ℕ} (hl : l ≤ u*m) + (hm : 32 ≤ m) (hum : u ≤ m) {q θ : ℝ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) + (hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) : + ((primitiveMarkLaw q ⟨hq.1, by linarith [hq.2]⟩ false).product l).expect (fun x => + averagedDensity (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (periodSlot off))) (primitiveScore q) x ^ 2) ≤ + 2*Real.exp (primitivePeriodConstant/q^4 * ((u:ℝ)/m)) := by + have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1, by linarith [hq.2]⟩ + let P := primitiveMarkLaw q hqi false + have hZ : P.expect (primitiveScore q) = 0 := primitive_score_centered hqi + have h := period_density_second_moment P (primitiveScore q) hZ hl hm hum hq hθ hmean hv off hoff hdiff + refine h.trans (mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ?_) (by norm_num)) + have hv0 : 0 ≤ P.expect (fun a => primitiveScore q a ^ 2) := + Finset.sum_nonneg (fun a _ => mul_nonneg (P.nonneg a) (sq_nonneg _)) + have hv1 : P.expect (fun a => primitiveScore q a ^ 2) ≤ 2/q := + primitive_score_variance_le hqi + have hsq : (P.expect (fun a => primitiveScore q a ^ 2))^2 ≤ (2/q)^2 := + pow_le_pow_left₀ hv0 hv1 2 + calc + _ ≤ (2/q)^2*(3*rankSchurConstant/q)^2*((u:ℝ)/m) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hsq (sq_nonneg _)) (by positivity) + _ = _ := by unfold primitivePeriodConstant; field_simp; ring + +/-- Association converts the two actual conditional period-laws into common +mass. The two original block totals may differ; only the retained count agrees. -/ +theorem conditionalPeriod_overlap {u v m l : ℕ} + (hl : l ≤ u*m) (hl' : l ≤ v*m) (hm : 32 ≤ m) (hum : u ≤ m) (hvm : v ≤ m) + {q θ θ' : ℝ} (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) + (hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4)) + (hθ' : θ' ∈ Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hmean' : ((v*m:ℕ):ℝ)*θ'=l) + (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (hv' : 1 ≤ ((v*m:ℕ):ℝ)*θ'*(1-θ')) + (off : Fin u → Fin m) (off' : Fin v → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hoff' : ∀ j, |((off' j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (hdiff' : ∀ j k, |((off' j).val:ℝ)-(off' k).val| ≤ 2) : + Real.exp (-(primitivePeriodConstant/q^4*((u:ℝ)/m+(v:ℝ)/m)))/128 ≤ + FiniteLaw.overlap + (conditionalPrimitiveLaw hl q ⟨hq.1, by linarith [hq.2]⟩ (defectTypes (periodSlot off))) + (conditionalPrimitiveLaw hl' q ⟨hq.1, by linarith [hq.2]⟩ (defectTypes (periodSlot off'))) := by + have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1, by linarith [hq.2]⟩ + let P := primitiveMarkLaw q hqi false + let R := uniformSubsetLaw l (show l≤Fintype.card (Fin (u*m)) by simpa using hl) + let S := uniformSubsetLaw l (show l≤Fintype.card (Fin (v*m)) by simpa using hl') + let f := defectAtRank (l:=l) (Finset.univ.image (periodSlot off)) + let g := defectAtRank (l:=l) (Finset.univ.image (periodSlot off')) + let G := averagedDensity R f (primitiveScore q) + let H := averagedDensity S g (primitiveScore q) + let A := primitivePeriodConstant/q^4*((u:ℝ)/m) + let B := primitivePeriodConstant/q^4*((v:ℝ)/m) + have h1 := conditionalPeriod_second_moment hl hm hum hq hθ hmean hv off hoff hdiff + have h2 := conditionalPeriod_second_moment hl' hm hvm hq hθ' hmean' hv' off' hoff' hdiff' + change (P.product l).expect (fun x => G x^2) ≤ 2*Real.exp A at h1 + change (P.product l).expect (fun x => H x^2) ≤ 2*Real.exp B at h2 + have ha := averagedDensity_overlap P R S (primitiveScore q) + (primitive_score_centered hqi) (primitive_one_add_score_nonneg hqi) f g + change 1/32 ≤ (P.product l).expect (fun x => min (G x) (H x)) * + (P.product l).expect (fun x => G x^2) * (P.product l).expect (fun x => H x^2) at ha + have hG : ∀x, 0 ≤ G x := averagedDensity_nonneg R f _ (primitive_one_add_score_nonneg hqi) + have hH : ∀x, 0 ≤ H x := averagedDensity_nonneg S g _ (primitive_one_add_score_nonneg hqi) + have ho : 0 ≤ (P.product l).expect (fun x => min (G x) (H x)) := + Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product l).nonneg _) (le_min (hG x) (hH x))) + have hm2 : 0 ≤ (P.product l).expect (fun x => H x^2) := + Finset.sum_nonneg (fun x _ => mul_nonneg ((P.product l).nonneg _) (sq_nonneg _)) + have hb := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left h1 ho) hm2 + have hc := mul_le_mul_of_nonneg_left h2 (mul_nonneg ho (by positivity : 0≤2*Real.exp A)) + have he : (P.product l).expect (fun x => min (G x) (H x)) = + FiniteLaw.overlap + (conditionalPrimitiveLaw hl q hqi (defectTypes (periodSlot off))) + (conditionalPrimitiveLaw hl' q hqi (defectTypes (periodSlot off'))) := by + unfold FiniteLaw.expect FiniteLaw.overlap + apply Finset.sum_congr rfl + intro x _ + rw [conditionalPeriodLaw_density,conditionalPeriodLaw_density] + exact mul_min_of_nonneg _ _ ((P.product l).nonneg x) + rw [← he] + have hd : Real.exp (-(A+B))/128 ≤ (P.product l).expect (fun x => min (G x) (H x)) := by + have hx : (1:ℝ)/32 ≤ (P.product l).expect (fun x => min (G x) (H x)) * (4*Real.exp (A+B)) := by + calc + _ ≤ _ := ha.trans (hb.trans hc) + _ = _ := by rw [Real.exp_add]; ring + have hp : 0 < 4*Real.exp (A+B) := by positivity + calc + _ = ((1:ℝ)/32)/(4*Real.exp (A+B)) := by rw [Real.exp_neg]; ring + _ ≤ _ := (div_le_iff₀ hp).2 hx + convert hd using 1 + congr 2 + dsimp [A,B] + ring + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The common count window is admissible for every genuine period count in +the base case. All hypotheses are elementary size/location inequalities. -/ +theorem primitive_count_window {q θ : ℝ} {m n l : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) + (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) + (hmean : (n:ℝ)*θ=l) + (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : + θ ∈ Set.Icc (1-q^2) (1-q^2/4) ∧ + 1 ≤ (n:ℝ)*θ*(1-θ) ∧ + Real.sqrt ((n:ℝ)*θ*(1-θ)) ≤ (m:ℝ) ∧ + ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / ((n:ℝ)*(1-q^2/2)*(q^2/2)) ≤ 32/q^3 := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hq0 := hq.1 + have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.2] + have hq2p : 0 < q^2 := sq_pos_of_pos hq0 + have hq3 : 0 < q^3 := pow_pos hq0 3 + have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by have hq0 := hq.1; positivity) hnlo + have hsize : 8*(m:ℝ) ≤ (n:ℝ)*q^2 := by + have ha := mul_le_mul_of_nonneg_right hnlo hq2p.le + have hb := mul_le_mul_of_nonneg_right hscale hm0.le + nlinarith + have hθ : θ ∈ Set.Icc (1-q^2) (1-q^2/4) := by + have hl := (abs_le.mp hdev).1 + have hr := (abs_le.mp hdev).2 + rw [←hmean] at hl hr + constructor + · nlinarith + · nlinarith + have ht0 : 0 < θ := by nlinarith [hθ.1] + have ht1 : θ < 1 := by nlinarith [hθ.2] + have hvlo : (n:ℝ)*q^2/8 ≤ (n:ℝ)*θ*(1-θ) := by + have hlow : (1:ℝ)/2 ≤ θ := by linarith [hθ.1] + have hhigh : q^2/4 ≤ 1-θ := by linarith [hθ.2] + have hp := mul_le_mul hlow hhigh (by positivity : (0:ℝ)≤q^2/4) ht0.le + have hp' := mul_le_mul_of_nonneg_left hp hn0.le + nlinarith + have hv : 1 ≤ (n:ℝ)*θ*(1-θ) := by + have hm32 : (32:ℝ) ≤ m := by exact_mod_cast hm + linarith + have hvhi : (n:ℝ)*θ*(1-θ) ≤ (m:ℝ)^2 := by + have hprod : θ*(1-θ) ≤ 1 := by nlinarith [sq_nonneg θ] + have hh := mul_le_mul_of_nonneg_left hprod hn0.le + nlinarith + have hsqrt : Real.sqrt ((n:ℝ)*θ*(1-θ)) ≤ (m:ℝ) := by + exact (Real.sqrt_le_iff).mpr ⟨hm0.le,hvhi⟩ + have hp0 : 0 < 1-q^2/2 := by linarith + have hden0 : 0 < (n:ℝ)*(1-q^2/2)*(q^2/2) := by positivity + have hden : q^3*(m:ℝ)^2/8 ≤ (n:ℝ)*(1-q^2/2)*(q^2/2) := by + have ha := mul_le_mul_of_nonneg_right hnlo hq2p.le + have hb := mul_le_mul_of_nonneg_right (show (1:ℝ)/2≤1-q^2/2 by linarith) + (mul_nonneg hn0.le (by positivity : (0:ℝ)≤q^2/2)) + nlinarith + have hdev2 : ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 ≤ 4*(m:ℝ)^2 := by + have h := pow_le_pow_left₀ (abs_nonneg _) hdev 2 + rw [sq_abs] at h + nlinarith + have hquot : ((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / + ((n:ℝ)*(1-q^2/2)*(q^2/2)) ≤ 32/q^3 := by + apply (div_le_div_iff₀ hden0 hq3).mpr + have hh := mul_le_mul_of_nonneg_right hdev2 hq3.le + nlinarith + exact ⟨hθ,hv,hsqrt,hquot⟩ + +/-- Genuine binomial count mass in the window, uniformly in the vanishing +working deletion rate, with an absolute explicit exponential cost. -/ +theorem primitive_count_mass_lower {q : ℝ} {m n l : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) + (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) + (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : + Real.exp (-32/q^3)/(12*(m:ℝ)) ≤ binomialMass n (1-primitiveErasure q) l := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by have hq0 := hq.1; positivity) hnlo + let θ : ℝ := (l:ℝ)/n + have hmean : (n:ℝ)*θ=l := by dsimp [θ]; field_simp + obtain ⟨ht,hv,hsqrt,hquot⟩ := primitive_count_window hq hm hscale hnlo hnhi hmean hdev + have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.1,hq.2] + have hq2p : 0 < q^2 := sq_pos_of_pos hq.1 + have ht' : θ ∈ Set.Ioo 0 1 := ⟨by nlinarith [ht.1], by nlinarith [ht.2]⟩ + have hp : 1-q^2/2 ∈ Set.Ioo 0 1 := ⟨by linarith, by linarith⟩ + have hl : l ≤ n := by + have h := mul_le_mul_of_nonneg_left ht'.2.le hn0.le + rw [hmean,mul_one] at h + exact_mod_cast h + have hmass := binomialMass_near_mean_lower n l ht' hp hl hmean hv + have hden : 0 < 12*Real.sqrt ((n:ℝ)*θ*(1-θ)) := by positivity + have hexp : Real.exp (-32/q^3) ≤ Real.exp (-((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / + ((n:ℝ)*(1-q^2/2)*(1-(1-q^2/2)))) := by + apply Real.exp_le_exp.mpr + have he : 1-(1-q^2/2)=q^2/2 := by ring + rw [he] + simpa only [neg_div] using neg_le_neg hquot + calc + _ ≤ Real.exp (-((l:ℝ)-(n:ℝ)*(1-q^2/2))^2 / + ((n:ℝ)*(1-q^2/2)*(1-(1-q^2/2)))) / (12*Real.sqrt ((n:ℝ)*θ*(1-θ))) := by + exact div_le_div₀ (Real.exp_nonneg _) hexp hden (by nlinarith) + _ ≤ _ := by simpa only [primitiveErasure] using hmass + + +/-- The actual base count, with no redefinition of the working channel. -/ +def initialSideCount (q : ℝ) (m : ℕ) : ℕ := ⌊q*(m:ℝ)⌋₊ + +theorem initialSideCount_bounds {q : ℝ} {m : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) : + q*(m:ℝ)/2 ≤ (initialSideCount q m:ℝ) ∧ + (initialSideCount q m:ℝ) ≤ q*(m:ℝ) ∧ initialSideCount q m+1 ≤ m := by + have hm0 : (0:ℝ) ≤ m := Nat.cast_nonneg _ + have hm32 : (32:ℝ) ≤ m := by exact_mod_cast hm + have hq0 := hq.1 + have hq2 : q^2 ≤ 1 := by nlinarith [hq.2] + have hqm : 2 ≤ q*(m:ℝ) := by + have hh := mul_le_mul_of_nonneg_right hq2 (mul_nonneg hq0.le hm0) + nlinarith + have hlow := Nat.lt_floor_add_one (q*(m:ℝ)) + have hhigh := Nat.floor_le (mul_nonneg hq0.le hm0) + change q*(m:ℝ) < (initialSideCount q m:ℝ)+1 at hlow + change (initialSideCount q m:ℝ) ≤ q*(m:ℝ) at hhigh + refine ⟨by linarith,hhigh,?_⟩ + have hh := mul_le_mul_of_nonneg_right hq.2 hm0 + have : (initialSideCount q m:ℝ)+1 ≤ (m:ℝ) := by linarith + exact_mod_cast this + +/-- An injective enumeration of m common integer counts; no asymptotic +cardinality argument is left implicit. -/ +def commonCountIndex {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) (j : Fin m) : + Fin ((k+1)*m+1) := + ⟨⌊p*((k*m:ℕ):ℝ)⌋₊+j.val,by + have ha : (⌊p*((k*m:ℕ):ℝ)⌋₊:ℝ) ≤ ((k*m:ℕ):ℝ) := by + exact (Nat.floor_le (mul_nonneg hp.1 (Nat.cast_nonneg _))).trans + (mul_le_of_le_one_left (Nat.cast_nonneg _) hp.2) + have ha' : ⌊p*((k*m:ℕ):ℝ)⌋₊ ≤ k*m := by exact_mod_cast ha + have hj := j.isLt + rw [Nat.add_mul,one_mul] + omega⟩ + +theorem commonCountIndex_injective {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) : + Function.Injective (commonCountIndex (m:=m) k p hp) := by + intro a b h + have hv := congrArg Fin.val h + simp only [commonCountIndex,Nat.add_left_cancel_iff] at hv + exact Fin.ext hv + +theorem commonCountIndex_deviation {m : ℕ} (k : ℕ) (p : ℝ) (hp : p ∈ Set.Icc 0 1) + (j : Fin m) : + |((commonCountIndex k p hp j).val:ℝ)-((k*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) ∧ + |((commonCountIndex k p hp j).val:ℝ)-(((k+1)*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) := by + have hm : (1:ℝ) ≤ m := by exact_mod_cast (Nat.succ_le_of_lt (Nat.zero_lt_of_lt j.isLt)) + have hj : (j.val:ℝ) < m := by exact_mod_cast j.isLt + have hj0 : (0:ℝ) ≤ j.val := Nat.cast_nonneg _ + have ha := Nat.floor_le (mul_nonneg hp.1 (Nat.cast_nonneg (k*m))) + have hb := Nat.lt_floor_add_one (p*((k*m:ℕ):ℝ)) + have hp0 := hp.1 + have hp1 := hp.2 + have hmp : 0 ≤ (m:ℝ)*p := mul_nonneg (Nat.cast_nonneg _) hp0 + have hmp' : (m:ℝ)*p ≤ m := mul_le_of_le_one_right (Nat.cast_nonneg _) hp1 + change |((⌊p*((k*m:ℕ):ℝ)⌋₊+j.val:ℕ):ℝ)-((k*m:ℕ):ℝ)*p| ≤ _ ∧ + |((⌊p*((k*m:ℕ):ℝ)⌋₊+j.val:ℕ):ℝ)-(((k+1)*m:ℕ):ℝ)*p| ≤ _ + have hn : (((k+1)*m:ℕ):ℝ)=((k*m:ℕ):ℝ)+(m:ℝ) := by push_cast; ring + rw [hn] + push_cast + constructor <;> apply abs_le.mpr <;> constructor <;> push_cast at ha hb <;> nlinarith + +end TraceReconstruction + + + +namespace TraceReconstruction +open scoped Classical + +theorem ordinaryRun_replicate (n : ℕ) : + (List.replicate n [false,true]).flatten = ordinaryRun n := by + induction n with + | zero => rfl + | succ n ih => simp [List.replicate_succ,ordinaryRun,ih] + +/-- Unique primitive parsing identifies the rank model with the literal +period words in the manuscript, not just a law on unlabeled locations. -/ +theorem primitive_period_word {m : ℕ} (off : Fin m) : + (List.ofFn (fun j : Fin m => primitiveBlock (decide (j=off)))).flatten = + initialPeriod m off.val := by + induction m with + | zero => exact Fin.elim0 off + | succ m ih => + refine Fin.cases ?_ (fun d => ?_) off + · simp [List.ofFn_succ,primitiveBlock,initialPeriod,ordinaryRun,ordinaryRun_replicate] + · rw [List.ofFn_succ,List.flatten_cons] + have hf : primitiveBlock (decide ((0:Fin (m+1))=d.succ))=[false,true] := by + simp [primitiveBlock,Ne.symm (Fin.succ_ne_zero d)] + rw [hf] + simp only [Fin.succ_inj] + rw [ih d] + simp [initialPeriod,ordinaryRun,Nat.sub_sub,Nat.add_comm] + +/-- Membership in the true periodic defect set is exactly the within-period +slot test, uniformly for all deterministic period types. -/ +theorem periodSlot_range_iff {u m : ℕ} (off : Fin u → Fin m) (i : Fin u) (j : Fin m) : + (⟨i.val*m+j.val,by + have hi := Nat.mul_le_mul_right m (Nat.succ_le_of_lt i.isLt) + have hj := j.isLt + nlinarith⟩ : Fin (u*m)) ∈ Set.range (periodSlot off) ↔ j=off i := by + constructor + · rintro ⟨a,ha⟩ + have hval := congrArg Fin.val ha + change a.val*m+(off a).val=i.val*m+j.val at hval + have hm : 0 < m := Nat.zero_lt_of_lt j.isLt + have hdiv := congrArg (fun k : ℕ => k/m) hval + simp only [Nat.mul_comm _ m, Nat.mul_add_div hm, Nat.div_eq_of_lt (off a).isLt, + Nat.div_eq_of_lt j.isLt,add_zero] at hdiv + have hai : a=i := Fin.ext hdiv + subst a + apply Fin.ext + omega + · intro h + refine ⟨i,?_⟩ + apply Fin.ext + simp only [periodSlot] + exact congrArg (fun k:Fin m => i.val*m+k.val) h.symm + +/-- The simulator's actual primitive list is the unpadded source gadget. -/ +theorem periodic_primitive_word {u m : ℕ} (off : Fin u → Fin m) : + (((List.ofFn (defectTypes (periodSlot off))).map primitiveBlock).flatten) = + periodString m u off := by + rw [List.map_ofFn,List.ofFn_mul] + rw [List.flatten_flatten,List.map_ofFn] + unfold periodString + congr 1 + apply congrArg List.ofFn + funext i + simp only [Function.comp_apply] + have he : (fun j:Fin m => primitiveBlock (defectTypes (periodSlot off) + ⟨i.val*m+j.val,by + have hi := Nat.mul_le_mul_right m (Nat.succ_le_of_lt i.isLt) + have hj := j.isLt + nlinarith⟩)) = fun j:Fin m => primitiveBlock (decide (j=off i)) := by + funext j + simp only [defectTypes,periodSlot_range_iff] + rw [he] + exact primitive_period_word (off i) + +theorem periodString_constant {u m : ℕ} (off : Fin m) : + periodString m u (fun _ => off) = pureAtomRun (initialPeriod m off.val) u := by + simp only [periodString,List.ofFn_const,pureAtomRun] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem primitive_count_admissible {q : ℝ} {m n l : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) + (hnlo : q*(m:ℝ)^2/2 ≤ (n:ℝ)) (hnhi : (n:ℝ) ≤ (m:ℝ)^2) + (hdev : |(l:ℝ)-(n:ℝ)*(1-q^2/2)| ≤ 2*(m:ℝ)) : + ∃ θ : ℝ, l ≤ n ∧ θ ∈ Set.Icc (1-q^2) (1-q^2/4) ∧ + (n:ℝ)*θ=l ∧ 1 ≤ (n:ℝ)*θ*(1-θ) := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hq0 := hq.1 + have hn0 : (0:ℝ) < n := lt_of_lt_of_le (by positivity) hnlo + let θ : ℝ := (l:ℝ)/n + have hmean : (n:ℝ)*θ=l := by dsimp [θ]; field_simp + obtain ⟨ht,hv,_,_⟩ := primitive_count_window hq hm hscale hnlo hnhi hmean hdev + have hl : l ≤ n := by + have ht1 : θ ≤ 1 := by nlinarith [ht.2,sq_nonneg q] + have hh := mul_le_mul_of_nonneg_left ht1 hn0.le + rw [hmean,mul_one] at hh + exact_mod_cast hh + exact ⟨θ,hl,ht,hmean,hv⟩ + +/-- The common-mass constant depends only on the working deletion rate. -/ +def initialOverlapLower (q : ℝ) : ℝ := + Real.exp (-(32+3*primitivePeriodConstant)/q^3)/1536 + +theorem initialOverlapLower_pos (q : ℝ) : 0 < initialOverlapLower q := by + unfold initialOverlapLower + positivity + +theorem initialOverlapLower_lt_eighth {q : ℝ} (hq : 0 < q) : + initialOverlapLower q < 1/8 := by + have hx : -(32+3*primitivePeriodConstant)/q^3 ≤ 0 := by + have hc := primitivePeriodConstant_nonneg + apply div_nonpos_of_nonpos_of_nonneg <;> nlinarith [pow_pos hq 3] + have he : Real.exp (-(32+3*primitivePeriodConstant)/q^3) ≤ 1 := by + simpa using Real.exp_le_exp.mpr hx + unfold initialOverlapLower + linarith + +/-- Unconditioned common mass of the two genuine count-and-mark simulators. +This includes all retained counts, not a conditioned or changed channel. -/ +theorem initial_counted_overlap {q : ℝ} {m : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) (off : Fin m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) : + let k := initialSideCount q m + initialOverlapLower q ≤ FiniteLaw.overlap + (countedPrimitiveLaw (N:=(k+1)*m) (Nat.mul_le_mul_right m (Nat.le_succ k)) + ⟨hq.1,by linarith [hq.2]⟩ (defectTypes (periodSlot (u:=k) (fun _ => off)))) + (countedPrimitiveLaw (N:=(k+1)*m) le_rfl + ⟨hq.1,by linarith [hq.2]⟩ (defectTypes (periodSlot (u:=k+1) (fun _ => off)))) := by + let k := initialSideCount q m + let N := (k+1)*m + have hq0 := hq.1 + have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hq2 : q^2 ≤ 1/4 := by nlinarith [hq.2] + let p := 1-primitiveErasure q + have hp : p ∈ Set.Icc 0 1 := primitiveRetention_mem hqi + have hp' : p=1-q^2/2 := rfl + obtain ⟨hklo,hkhi,hk1⟩ := initialSideCount_bounds hq hm hscale + change q*(m:ℝ)/2 ≤ (k:ℝ) at hklo + change (k:ℝ) ≤ q*(m:ℝ) at hkhi + change k+1 ≤ m at hk1 + have hk : k ≤ m := by omega + have hnlo : q*(m:ℝ)^2/2 ≤ ((k*m:ℕ):ℝ) := by + have hh := mul_le_mul_of_nonneg_right hklo hm0.le + push_cast + nlinarith + have hnhi : ((k*m:ℕ):ℝ) ≤ (m:ℝ)^2 := by + exact_mod_cast (show k*m ≤ m^2 by simpa [pow_two] using Nat.mul_le_mul_right m hk) + have hNlo : q*(m:ℝ)^2/2 ≤ (N:ℝ) := by + exact hnlo.trans (by exact_mod_cast Nat.mul_le_mul_right m (Nat.le_succ k)) + have hNhi : (N:ℝ) ≤ (m:ℝ)^2 := by + exact_mod_cast (show N ≤ m^2 by simpa [N,pow_two] using Nat.mul_le_mul_right m hk1) + have hqm : 1 ≤ q*(m:ℝ) := by + have hh := mul_le_mul_of_nonneg_right (show q^2≤1 by linarith) (mul_nonneg hq0.le hm0.le) + nlinarith + have hrate : (k:ℝ)/(m:ℝ)+((k+1:ℕ):ℝ)/(m:ℝ) ≤ 3*q := by + rw [←add_div] + apply (div_le_iff₀ hm0).mpr + push_cast + nlinarith + have harg : primitivePeriodConstant/q^4*((k:ℝ)/m+((k+1:ℕ):ℝ)/m) ≤ + 3*primitivePeriodConstant/q^3 := by + calc + _ ≤ primitivePeriodConstant/q^4*(3*q) := + mul_le_mul_of_nonneg_left hrate (div_nonneg primitivePeriodConstant_nonneg (by positivity)) + _ = _ := by field_simp + let C₁ := boundedCountLaw (N:=N) (Nat.mul_le_mul_right m (Nat.le_succ k)) p hp + let C₂ := boundedCountLaw (N:=N) le_rfl p hp + let K := boundedConditionalPrimitiveLaw hqi (defectTypes (periodSlot (u:=k) (fun _ => off))) (N:=N) + let L := boundedConditionalPrimitiveLaw hqi (defectTypes (periodSlot (u:=k+1) (fun _ => off))) (N:=N) + let f : Fin (N+1) → ℝ := fun l => min (C₁.mass l) (C₂.mass l) * FiniteLaw.overlap (K l) (L l) + let a : ℝ := Real.exp (-32/q^3)/(12*(m:ℝ)) + let b : ℝ := Real.exp (-(3*primitivePeriodConstant)/q^3)/128 + have ha0 : 0 ≤ a := by dsimp [a]; positivity + have hb0 : 0 ≤ b := by dsimp [b]; positivity + have hf0 : ∀l, 0 ≤ f l := fun l => + mul_nonneg (le_min (C₁.nonneg l) (C₂.nonneg l)) (FiniteLaw.overlap_nonneg _ _) + let ix : Fin m → Fin (N+1) := commonCountIndex k p hp + have hterm : ∀j : Fin m, a*b ≤ f (ix j) := by + intro j + let l := (ix j).val + have hd := commonCountIndex_deviation k p hp j + change |(l:ℝ)-((k*m:ℕ):ℝ)*p| ≤ 2*(m:ℝ) ∧ |(l:ℝ)-(N:ℝ)*p| ≤ 2*(m:ℝ) at hd + rw [hp'] at hd + obtain ⟨θ,hl,hθ,hmean,hv⟩ := primitive_count_admissible hq hm hscale hnlo hnhi hd.1 + obtain ⟨θ',hl',hθ',hmean',hv'⟩ := primitive_count_admissible hq hm hscale hNlo hNhi hd.2 + have hm1 := primitive_count_mass_lower hq hm hscale hnlo hnhi hd.1 + have hm2 := primitive_count_mass_lower hq hm hscale hNlo hNhi hd.2 + have hmin : a ≤ min (C₁.mass (ix j)) (C₂.mass (ix j)) := le_min hm1 hm2 + have hc := conditionalPeriod_overlap hl hl' hm hk hk1 hq hθ hθ' hmean hmean' hv hv' + (fun _ => off) (fun _ => off) (fun _ => hoff) (fun _ => hoff) + (fun _ _ => by simp) (fun _ _ => by simp) + have hb : b ≤ FiniteLaw.overlap (K (ix j)) (L (ix j)) := by + dsimp only [K,L,boundedConditionalPrimitiveLaw] + rw [dite_eq_left hl,dite_eq_left hl'] + refine le_trans ?_ hc + apply div_le_div_of_nonneg_right _ (by norm_num : (0:ℝ)≤128) + apply Real.exp_le_exp.mpr + simpa only [neg_div] using neg_le_neg harg + exact mul_le_mul hmin hb hb0 (le_min (C₁.nonneg _) (C₂.nonneg _)) + have hsub : (∑j : Fin m, f (ix j)) ≤ ∑l : Fin (N+1), f l := by + have hi := commonCountIndex_injective (m:=m) k p hp + calc + _ = ∑l ∈ Finset.univ.image ix, f l := by + rw [Finset.sum_image] + exact fun a _ b _ hab => hi hab + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun l _ _ => hf0 l) + have hsum : (m:ℝ)*(a*b) ≤ ∑l : Fin (N+1), f l := by + calc + _ = ∑_j : Fin m, a*b := by simp + _ ≤ ∑j : Fin m, f (ix j) := Finset.sum_le_sum (fun j _ => hterm j) + _ ≤ _ := hsub + have he : (m:ℝ)*(a*b)=initialOverlapLower q := by + dsimp [a,b,initialOverlapLower] + rw [div_mul_div_comm,←Real.exp_add] + have hx : -32/q^3 + -(3*primitivePeriodConstant)/q^3 = -(32+3*primitivePeriodConstant)/q^3 := by ring + rw [hx] + field_simp + ring + rw [he] at hsum + exact hsum.trans (FiniteLaw.overlap_sigma_lower C₁ C₂ K L) + +/-- Data processing for common exact simulators, stated as a common-mass +inequality and allowing unequal original lengths. -/ +theorem simulations_overlap_le {α : Type*} [Fintype α] {q : ℝ} + (hq : q ∈ Set.Icc 0 1) (P Q : FiniteLaw α) (decode : α → List Bool) + (x y : List Bool) (hP : SimulatesTrace q P decode x) + (hQ : SimulatesTrace q Q decode y) : + P.overlap Q ≤ listTraceOverlap q hq x y := by + have h := approximations_trace_tv hq P Q decode x y 0 0 + (max x.length y.length) (le_max_left _ _) (le_max_right _ _) + hP.approximate hQ.approximate + simp only [add_zero] at h + unfold listTraceOverlap + rw [FiniteLaw.overlap_eq_one_sub_tv, FiniteLaw.overlap_eq_one_sub_tv] + linarith + +/-- The initial hidden-bit overlap for ordinary complete deletion traces of +consecutive pure runs. This is the unconditioned original channel. -/ +theorem initial_pure_trace_overlap {q : ℝ} {m : ℕ} + (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) (hm : 32 ≤ m) + (hscale : 16 ≤ q^3*(m:ℝ)) (off : Fin m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) : + let k := initialSideCount q m + initialOverlapLower q ≤ listTraceOverlap q ⟨hq.1.le, by linarith [hq.2]⟩ + (pureAtomRun (initialPeriod m off.val) k) + (pureAtomRun (initialPeriod m off.val) (k+1)) := by + let k := initialSideCount q m + have hqi : q ∈ Set.Ioo 0 1 := ⟨hq.1,by linarith [hq.2]⟩ + have hca := countedPrimitiveLaw_simulates (N:=(k+1)*m) + (Nat.mul_le_mul_right m (Nat.le_succ k)) hqi + (defectTypes (periodSlot (u:=k) (fun _ => off))) + have hcb := countedPrimitiveLaw_simulates (N:=(k+1)*m) le_rfl hqi + (defectTypes (periodSlot (u:=k+1) (fun _ => off))) + rw [periodic_primitive_word,periodString_constant] at hca hcb + exact (initial_counted_overlap hq hm hscale off hoff).trans + (simulations_overlap_le ⟨hq.1.le,by linarith [hq.2]⟩ _ _ _ _ _ hca hcb) + +end TraceReconstruction + + + +/-! From the actual displaced period words to their conditional oracle +moments. The coefficient bounds are the rank kernels, +not assumptions on an abstract pair. -/ +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- An interior period slot admits the three literal shifts. -/ +def oneStepOffset {m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : Fin m := + ⟨off.val+a.val-1,by have ha := a.isLt; omega⟩ + +theorem oneStepOffset_add_one {m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : + (oneStepOffset off hi a).val+1=off.val+a.val := by + dsimp [oneStepOffset] + omega + +theorem oneStepOffset_distance {m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) (a : Fin 3) : + |((oneStepOffset off hi a).val:ℝ)-(off.val:ℝ)| ≤ 1 := by + have he := oneStepOffset_add_one off hi a + have ha : (a.val:ℝ) ≤ 2 := by exact_mod_cast (show a.val ≤ 2 by omega) + have ha0 : (0:ℝ) ≤ a.val := Nat.cast_nonneg _ + have he' : ((oneStepOffset off hi a).val:ℝ)+1=(off.val:ℝ)+a.val := by exact_mod_cast he + rw [abs_le] + constructor <;> linarith + +theorem constantPeriod_safe {u m : ℕ} (hm : 3 ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) : + SafeTaggedTuple (periodSlot (u:=u) (fun _ => off)) := by + constructor + · intro i + change 1 ≤ i.val*m+off.val ∧ i.val*m+off.val+1 nlinarith [hi.1,hi.2] + · intro i j hij + change i.val*m+off.val+3 ≤ j.val*m+off.val + have h := Nat.mul_le_mul_right m (Nat.succ_le_of_lt hij) + nlinarith + +theorem shifted_constantPeriod {u m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (a : Fin u → Fin 3) : + shiftedTag (periodSlot (fun _ => off)) hsafe a = + periodSlot (fun i => oneStepOffset off hi (a i)) := by + funext i + apply Fin.ext + change i.val*m+off.val+(a i).val-1=i.val*m+(off.val+(a i).val-1) + omega + +/-- Arbitrary deterministic motif orientations remain genuine one-defect +periods with the exact geometry used in the high-degree rank bound. -/ +theorem signedPeriod_geometry {u m : ℕ} (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val + 1 < m) + (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (s : ℕ) (X : ℤ) (τ : ℝ) : + ∃ off' : Fin u → Fin m, + signedPeriodDefects off hsafe s X τ = periodSlot off' ∧ + (∀j, |((off' j).val:ℝ)-(m:ℝ)/2| ≤ 3) ∧ + (∀j k, |((off' j).val:ℝ)-(off' k).val| ≤ 2) := by + let a : Fin u → Fin 3 := fun j => + motifShift (motifIndicator s ((j.val:ℤ)-X)) ((prouhetSeries s).coeff ((j.val:ℤ)-X)) τ + refine ⟨fun j => oneStepOffset off hi (a j),shifted_constantPeriod off hi hsafe a,?_,?_⟩ + · intro j + have h := oneStepOffset_distance off hi (a j) + have ht := abs_add_le (((oneStepOffset off hi (a j)).val:ℝ)-(off.val:ℝ)) + ((off.val:ℝ)-(m:ℝ)/2) + rw [sub_add_sub_cancel] at ht + linarith + · intro j k + have hj := oneStepOffset_distance off hi (a j) + have hk := oneStepOffset_distance off hi (a k) + rw [abs_le] at hj hk ⊢ + constructor <;> linarith + + +/-- Every moment of the actual primitive score has the source uniform +bound. -/ +theorem primitive_score_evenMoment {q : ℝ} (hq : q∈Set.Ioo 0 1) (k : ℕ) : + (primitiveMarkLaw q hq false).expect (fun z => |primitiveScore q z|^(2*k)) ≤ + (2/q)^(2*k) := by + calc + _ ≤ (primitiveMarkLaw q hq false).expect (fun _ => (2/q)^(2*k)) := by + apply Finset.sum_le_sum + intro z _ + exact mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (abs_nonneg _) (primitive_score_bound hq z) _) ((primitiveMarkLaw q hq false).nonneg z) + _ = _ := (primitiveMarkLaw q hq false).expect_const _ + +/-- Hypercontractivity now applies directly to the actual signed initial +density difference under its ordinary-mark reference law. -/ +theorem initial_moment_of_energy {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (s k : ℕ) (hk : 1 ≤ k) {q : ℝ} (hq : q∈Set.Ioo 0 1) : + ((primitiveMarkLaw q hq false).product l).evenMomentSq + (multilinear (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ) (primitiveScore q)) k ≤ + multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ) ((6*(2*k:ℕ):ℝ)*(2/q)) := by + apply multilinear_moment_sq_scaled _ _ k hk + · exact primitive_score_centered hq + · exact div_pos (by norm_num) hq.1 + · exact primitive_score_evenMoment hq k + + +/-- Jensen's inequality on each homogeneous degree. -/ +theorem degree_square_mixture_le {Ω : Type*} [Fintype Ω] {n : ℕ} + (P : FiniteLaw Ω) (A : Ω → (Fin n → Bool) → ℝ) (r : ℕ) : + (∑σ : Fin n → Bool, if monomialDegree σ=r then + (P.expect (fun ω => A ω σ))^2 else 0) ≤ + P.expect (fun ω => ∑σ : Fin n → Bool, + if monomialDegree σ=r then (A ω σ)^2 else 0) := by + unfold FiniteLaw.expect + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro σ _ + by_cases h : monomialDegree σ=r + · simp only [ite_eq_left h] + have H := weighted_sum_sq_le Finset.univ P.mass (fun ω => A ω σ) (fun ω => P.nonneg ω) + simpa only [P.total,one_mul] using H + · simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero,le_refl] + +theorem degree_square_sub_le {n : ℕ} (A B : (Fin n → Bool) → ℝ) (r : ℕ) : + (∑σ : Fin n → Bool, if monomialDegree σ=r then (A σ-B σ)^2 else 0) ≤ + 2*(∑σ : Fin n → Bool, if monomialDegree σ=r then A σ^2 else 0)+ + 2*(∑σ : Fin n → Bool, if monomialDegree σ=r then B σ^2 else 0) := by + simp only [Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro σ _ + split_ifs <;> nlinarith [sq_nonneg (A σ+B σ)] + +theorem mixedMotifCoefficient_expect {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) (σ : Fin l → Bool) : + mixedMotifCoefficient hl off hsafe π s τ σ = + (seriesProbabilityLaw π hπ hπsum).expect (fun X => + averagedCoefficient (uniformSubsetLaw l (by simpa using hl)) + (defectAtRank (Finset.univ.image (signedPeriodDefects off hsafe s X.val τ))) σ) := by + unfold mixedMotifCoefficient FiniteLaw.expect seriesProbabilityLaw + exact (Finset.sum_coe_sort _ _).symm + +theorem mixedMotifCoefficient_empty {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) (τ : ℝ) : + mixedMotifCoefficient hl off hsafe π s τ (fun _ => false)=1 := by + simp only [mixedMotifCoefficient,averagedCoefficient_empty,mul_one,hπsum] + +/-- Uniform high-degree estimate after the real hidden-anchor mixture. -/ +theorem mixedMotif_degree_le {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hru : r ≤ u) (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) : + (∑σ : Fin l → Bool, if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s τ σ)^2 else 0) ≤ + ((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := by + simp_rw [mixedMotifCoefficient_expect hl off hsafe π hπ hπsum] + refine (degree_square_mixture_le _ _ r).trans ?_ + calc + _ ≤ (seriesProbabilityLaw π hπ hπsum).expect (fun _ => + ((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r) := by + apply FiniteLaw.expect_mono + intro X + obtain ⟨d,hd,hnear,hclose⟩ := signedPeriod_geometry off hi hoff hsafe s X.val τ + rw [hd] + exact period_degree_square_sum hl hr hru hm hum hq hθ hmean hv d hnear hclose + _ = _ := FiniteLaw.expect_const _ _ + +/-- There are never more selected ranks than actual defect periods, even +in the hidden-anchor mixture. -/ +theorem mixedMotif_degree_vanish {u m l r : ℕ} (hl : l ≤ u*m) (hru : u < r) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) : + (∑σ : Fin l → Bool, if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s τ σ)^2 else 0)=0 := by + apply le_antisymm + · simp_rw [mixedMotifCoefficient_expect hl off hsafe π hπ hπsum] + refine (degree_square_mixture_le _ _ r).trans ?_ + simp_rw [defect_degree_bound hl _ (signedPeriodDefects_strictMono off hsafe s _ τ) hru] + rw [FiniteLaw.expect_const] + · exact Finset.sum_nonneg (fun σ _ => by split_ifs <;> positivity) + +/-- The signed difference has no constant term. -/ +theorem signedMotif_degree_zero {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) (s : ℕ) : + (∑σ : Fin l → Bool, if monomialDegree σ=0 then + (mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0)=0 := by + simp_rw [monomialDegree_eq_zero_iff] + simp [mixedMotifCoefficient_empty hl off hsafe π hπsum] + +/-- Low-degree cancellation is for exactly the coefficients of the +conditional motif densities, without a rank surrogate at the boundary. -/ +theorem signedMotif_degree_cancellation {u m l r : ℕ} + (hu : 0 < u) (hm : 128 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 3) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {θ : ℝ} (hθ : θ∈Set.Ioo 0 1) (hhalf : 1/2 ≤ θ) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ)<(u:ℝ)/(3*(r+1:ℝ))) : + (∑σ : Fin l → Bool, if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0) ≤ + 8*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + signedPatternBound u m r s π θ k else 0) + + 2*((Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 := by + refine (sum_degree_coeff_sq_le _).trans ?_ + simp_rw [mixedMotifCoefficient_rank_difference] + exact initial_signed_energy hu hm hr hl off hoff hsafe π hπ hπsum s hcentral + hθ hhalf hmean hv hM + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- A finite tail is no larger than the full geometric tail. -/ +theorem finite_geometric_tail_le {a : ℝ} (ha : 0 ≤ a) (ha1 : a < 1) (N R : ℕ) : + (∑r ∈ Finset.range N, if R ≤ r then a^r else 0) ≤ a^R/(1-a) := by + have ht : HasSum (fun n : ℕ => a^(n+R)) (a^R/(1-a)) := by + simpa only [pow_add, mul_comm, div_eq_mul_inv] using + (hasSum_geometric_of_lt_one ha ha1).mul_left (a^R) + have hsum : (∑r ∈ Finset.range N, if R ≤ r then a^r else 0) = + ∑r ∈ (Finset.range N).filter (R ≤ ·), a^r := by + rw [Finset.sum_filter] + rw [hsum] + calc + _ = ∑r ∈ ((Finset.range N).filter (R ≤ ·)).image (fun r => r-R), a^(r+R) := by + rw [Finset.sum_image] + · apply Finset.sum_congr rfl + intro r hr + rw [Nat.sub_add_cancel (Finset.mem_filter.mp hr).2] + · intro r hr s hs h + dsimp only at h + have hrR := (Finset.mem_filter.mp hr).2 + have hsR := (Finset.mem_filter.mp hs).2 + omega + _ ≤ _ := by + rw [←ht.tsum_eq] + exact ht.summable.sum_le_tsum _ (fun _ _ => by positivity) + +/-- Splitting the exact homogeneous expansion, not a surrogate polynomial. -/ +theorem multilinearEnergy_low_high {n R : ℕ} (A : (Fin n → Bool) → ℝ) + (w a K : ℝ) (hw : 0 ≤ w) (ha : 0 ≤ a) (ha1 : a < 1) (hK : 0 ≤ K) + (L : ℕ → ℝ) + (hlow : ∀r < R, (∑σ : Fin n → Bool, if monomialDegree σ=r then A σ^2 else 0) ≤ L r) + (hhigh : ∀r, R ≤ r → w^(2*r)*(∑σ : Fin n → Bool, + if monomialDegree σ=r then A σ^2 else 0) ≤ K*a^r) + (hL : ∀r, 0 ≤ L r) : + multilinearEnergy A w ≤ (∑r ∈ Finset.range R, w^(2*r)*L r)+K*a^R/(1-a) := by + rw [multilinearEnergy_degrees] + calc + _ ≤ ∑r ∈ Finset.range (n+1), + ((if r < R then w^(2*r)*L r else 0)+(if R ≤ r then K*a^r else 0)) := by + apply Finset.sum_le_sum + intro r _ + by_cases h : r < R + · simp only [ite_eq_left h,ite_eq_right (show ¬R ≤ r by omega),add_zero] + exact mul_le_mul_of_nonneg_left (hlow r h) (by positivity) + · simp only [ite_eq_right h,ite_eq_left (show R ≤ r by omega),zero_add] + exact hhigh r (by omega) + _ ≤ _ := by + rw [Finset.sum_add_distrib] + apply add_le_add + · rw [←Finset.sum_filter] + exact Finset.sum_le_sum_of_subset_of_nonneg + (by intro r hr; exact Finset.mem_range.mpr (Finset.mem_filter.mp hr).2) + (fun r _ _ => mul_nonneg (by positivity) (hL r)) + · have he : (∑r ∈ Finset.range (n+1), if R ≤ r then K*a^r else 0)= + K*∑r ∈ Finset.range (n+1), if R ≤ r then a^r else 0 := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro r _ + split_ifs <;> ring + rw [he,mul_div_assoc] + exact mul_le_mul_of_nonneg_left (finite_geometric_tail_le ha ha1 _ _) hK + +/-- The signed high-degree bound includes the true anchor mixture. -/ +theorem signedMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : + w^(2*r)*(∑σ : Fin l → Bool, if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0) ≤ + 4*(w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by + have hw0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity + have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] + have hb := degree_square_sub_le (mixedMotifCoefficient hl off hsafe π s 1) + (mixedMotifCoefficient hl off hsafe π s (-1)) r + by_cases hru : r ≤ u + · have hplus := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum + s 1 hq hθ hmean hv + have hminus := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum + s (-1) hq hθ hmean hv + have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by + apply Real.sqrt_le_sqrt + apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) + have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr + nlinarith + calc + _ ≤ w^(2*r)*(4*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r) := + mul_le_mul_of_nonneg_left (by linarith) (by rw [pow_mul]; positivity) + _ ≤ w^(2*r)*(4*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r) := by + gcongr + _ = _ := by rw [pow_mul, mul_pow, mul_pow]; ring + · rw [mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s 1, + mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s (-1)] at hb + have hz : (∑σ : Fin l → Bool, if monomialDegree σ=r then + (mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ)^2 else 0)=0 := by + apply le_antisymm (by linarith) + exact Finset.sum_nonneg (fun σ _ => by split_ifs <;> positivity) + rw [hz,mul_zero] + positivity + +/-- Explicit low-degree majorant from the signed finite-difference estimate. -/ +def signedInitialDegreeBound (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : ℝ := + if r=0 then 0 else + 8*(Fintype.card (Fin r → GapDifference):ℝ)* + (∑k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + signedPatternBound u m r s π θ k else 0) + + 2*((Fintype.card (IncreasingTuple u r):ℝ)* + (2*(((r+1:ℕ):ℝ)*θ^r/binomialMass (u*m) θ l * (2*Real.exp (-(m:ℝ)/(1024*u))))))^2 + +theorem signedInitialDegreeBound_nonneg (u m r s : ℕ) (π : IntSeries) (θ : ℝ) (l : ℕ) : + 0 ≤ signedInitialDegreeBound u m r s π θ l := by + unfold signedInitialDegreeBound + split_ifs + · exact le_rfl + · apply add_nonneg _ (by positivity) + apply mul_nonneg (by positivity) + apply Finset.sum_nonneg + intro k _ + split_ifs + · unfold signedPatternBound + split_ifs <;> apply mul_nonneg _ (seriesL2Sq_nonneg _) + all_goals dsimp only [periodDifferencePrefactor, lengthDifferenceConstant, periodCentralSumConstant, periodBoundedSumConstant] + all_goals positivity + · exact le_rfl + +/-- A fully finite norm estimate for the actual low and high degree pieces. +Only numerical admissible-count and geometric conditions remain to be chosen. -/ +theorem signed_initial_full_energy {u m l R : ℕ} (hu : 0 < u) (hm : 128 ≤ m) + (hum : u ≤ m) (hR : 0 < R) (hl : l ≤ u*m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (hcentral : CentralMotifSupport u s π) + {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hM : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(R+1:ℝ))) + (hw : 0 ≤ w) (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : + multilinearEnergy (fun σ => mixedMotifCoefficient hl off hsafe π s 1 σ- + mixedMotifCoefficient hl off hsafe π s (-1) σ) w ≤ + (∑r ∈ Finset.range R, w^(2*r)*signedInitialDegreeBound u m r s π θ l)+ + 4*(w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^R / + (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by + have hq2 : q^2 ≤ (1/4:ℝ) := by + calc q^2 ≤ (1/2:ℝ)^2 := pow_le_pow_left₀ hq.1.le hq.2 2 + _ = _ := by norm_num + have hθ0 : θ∈Set.Ioo 0 1 := by constructor <;> nlinarith [hq.1,hθ.1,hθ.2] + have hhalf : 1/2 ≤ θ := by nlinarith [hθ.1] + apply multilinearEnergy_low_high _ w _ 4 hw (by positivity [rankSchurConstant_pos,hq.1]) ha + (by norm_num) (signedInitialDegreeBound u m · s π θ l) _ _ + (fun r => signedInitialDegreeBound_nonneg _ _ _ _ _ _ _) + · intro r hr + by_cases hr0 : r=0 + · subst r + rw [signedMotif_degree_zero hl off hsafe π hπsum s] + exact signedInitialDegreeBound_nonneg _ _ _ _ _ _ _ + · have hMr : ((2*(2^s):ℕ):ℝ) < (u:ℝ)/(3*(r+1:ℝ)) := by + apply hM.trans_le + apply div_le_div_of_nonneg_left (by positivity) (by positivity) + exact mul_le_mul_of_nonneg_left (by exact_mod_cast (show r+1 ≤ R+1 by omega)) (by norm_num) + simpa only [signedInitialDegreeBound,ite_eq_right hr0] using + signedMotif_degree_cancellation hu hm (Nat.pos_of_ne_zero hr0) hl off + (hoff.trans (by norm_num)) hsafe π hπ hπsum s hcentral hθ0 hhalf hmean hv hMr + · intro r hr + exact signedMotif_degree_geometric hl (by omega) (by omega) hum off hi hoff hsafe π hπ + hπsum s hq hθ hmean hv w + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +theorem primitive_reference_mass_pos {q : ℝ} (hq : q∈Set.Ioo 0 1) (z : PrimitiveMark) : + 0 < (primitiveMarkLaw q hq false).mass z := by + change 0 < primitiveMarkMass q false z + apply div_pos _ (primitive_retain_pos hq) + fin_cases z <;> simp [ordinaryPrimitiveMass,primitiveErasure] <;> nlinarith [hq.1,hq.2] + +theorem primitive_product_mass_pos {q : ℝ} (hq : q∈Set.Ioo 0 1) {l : ℕ} + (x : Fin l → PrimitiveMark) : 0 < ((primitiveMarkLaw q hq false).product l).mass x := +by + change 0 < ∏ i, (primitiveMarkLaw q hq false).mass (x i) + exact Finset.prod_pos (fun _ _ => primitive_reference_mass_pos hq _) + +/-- The density in the actual base experiment, not an independent model. -/ +def initialMotifDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (τ q : ℝ) : (Fin l → PrimitiveMark) → ℝ := + multilinear (mixedMotifCoefficient hl off hsafe π s τ) (primitiveScore q) + +theorem initialMotifDensity_nonneg {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) (x : Fin l → PrimitiveMark) : + 0 ≤ initialMotifDensity hl off hsafe π s τ q x := by + have h := (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).nonneg x + rw [conditionalMotifLaw_density] at h + exact nonneg_of_mul_nonneg_right h (primitive_product_mass_pos hq x) + +theorem initialMotifDensity_mean {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : + ((primitiveMarkLaw q hq false).product l).expect (initialMotifDensity hl off hsafe π s τ q)=1 := by + have h := (conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ).total + simpa only [conditionalMotifLaw_density,FiniteLaw.expect,initialMotifDensity] using h + +theorem initialMotifLaw_withDensity {u m l : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q : ℝ} (hq : q∈Set.Ioo 0 1) : + conditionalMotifLaw hl off hsafe hq π hπ hπsum s τ = + ((primitiveMarkLaw q hq false).product l).withDensity + (initialMotifDensity hl off hsafe π s τ q) + (initialMotifDensity_nonneg hl off hsafe π hπ hπsum s τ hq) + (initialMotifDensity_mean hl off hsafe π hπ hπsum s τ hq) := by + apply FiniteLaw.ext + funext x + exact conditionalMotifLaw_density hl off hsafe hq π hπ hπsum s τ x + +theorem multilinear_sub {α : Type*} {l : ℕ} (A B : (Fin l → Bool) → ℝ) + (Z : α → ℝ) (x : Fin l → α) : + multilinear (fun σ => A σ-B σ) Z x = multilinear A Z x-multilinear B Z x := by + simp only [multilinear,sub_mul,Finset.sum_sub_distrib] + +/-- The constant-term deletion of a polynomial. -/ +def nonconstantCoefficient {l : ℕ} (A : (Fin l → Bool) → ℝ) (σ : Fin l → Bool) : ℝ := + if σ=(fun _ => false) then 0 else A σ + +theorem nonconstant_multilinear {α : Type*} {l : ℕ} (A : (Fin l → Bool) → ℝ) + (Z : α → ℝ) (x : Fin l → α) : + multilinear (nonconstantCoefficient A) Z x=multilinear A Z x-A (fun _ => false) := by + have he : ∀σ, nonconstantCoefficient A σ=A σ-(if σ=(fun _ => false) then A σ else 0) := by + intro σ + by_cases h : σ=(fun _ => false) <;> simp [nonconstantCoefficient,h] + rw [show nonconstantCoefficient A = (fun σ => A σ-(if σ=(fun _ => false) then A σ else 0)) from funext he, multilinear_sub] + congr 1 + simp [multilinear,ite_mul] + +theorem nonconstant_degree_zero {l : ℕ} (A : (Fin l → Bool) → ℝ) : + (∑σ : Fin l → Bool, if monomialDegree σ=0 then (nonconstantCoefficient A σ)^2 else 0)=0 := by + simp [monomialDegree_eq_zero_iff,nonconstantCoefficient] + +theorem nonconstant_degree_pos {l r : ℕ} (A : (Fin l → Bool) → ℝ) (hr : 0 < r) : + (∑σ : Fin l → Bool, if monomialDegree σ=r then (nonconstantCoefficient A σ)^2 else 0)= + ∑σ : Fin l → Bool, if monomialDegree σ=r then (A σ)^2 else 0 := by + apply Finset.sum_congr rfl + intro σ _ + by_cases h : σ=(fun _ => false) + · subst σ + simp [monomialDegree,Ne.symm (Nat.ne_of_gt hr)] + · simp [nonconstantCoefficient,h] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +theorem mixedMotif_degree_geometric {u m l r : ℕ} (hl : l ≤ u*m) (hr : 0 < r) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q θ : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) (w : ℝ) : + w^(2*r)*(∑σ : Fin l → Bool, if monomialDegree σ=r then + mixedMotifCoefficient hl off hsafe π s τ σ^2 else 0) ≤ + (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by + have hw : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity + have hp : 0 ≤ 3*rankSchurConstant/q := by positivity [rankSchurConstant_pos,hq.1] + by_cases hru : r ≤ u + · have hb := mixedMotif_degree_le hl hr hru hm hum off hi hoff hsafe π hπ hπsum + s τ hq hθ hmean hv + have hsqrt : Real.sqrt ((u:ℝ)/((m:ℝ)*r)) ≤ Real.sqrt ((u:ℝ)/m) := by + apply Real.sqrt_le_sqrt + apply div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast (show 0 < m by omega)) + have hr1 : (1:ℝ) ≤ r := by exact_mod_cast hr + nlinarith + calc + _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/((m:ℝ)*r)))^r := + mul_le_mul_of_nonneg_left hb hw + _ ≤ w^(2*r)*((3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m))^r := by gcongr + _ = _ := by rw [pow_mul,mul_pow,mul_pow]; ring + · rw [mixedMotif_degree_vanish hl (by omega) off hsafe π hπ hπsum s τ,mul_zero] + positivity + +/-- Clipping input: the actual conditional density is close to one. -/ +theorem initial_centered_energy {u m l : ℕ} (hl : l ≤ u*m) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s : ℕ) (τ : ℝ) {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : 0 ≤ w) (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : + multilinearEnergy (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) w ≤ + (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) / + (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by + have H := multilinearEnergy_low_high (R:=1) + (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) w _ 1 hw + (by positivity [rankSchurConstant_pos,hq.1]) ha (by norm_num) (fun _ => 0) + (fun r hr => by + have he : r=0 := by omega + subst r + rw [nonconstant_degree_zero]) + (fun r hr => by + rw [nonconstant_degree_pos _ (by omega)] + simpa only [one_mul] using mixedMotif_degree_geometric hl (by omega) hm hum off + hi hoff hsafe π hπ hπsum s τ hq hθ hmean hv w) + (fun _ => le_rfl) + simpa using H + +theorem initial_centered_moment {u m l : ℕ} (hl : l ≤ u*m) + (hm : 32 ≤ m) (hum : u ≤ m) (off : Fin m) + (hi : 1 ≤ off.val ∧ off.val+1 < m) (hoff : |(off.val:ℝ)-(m:ℝ)/2| ≤ 2) + (hsafe : SafeTaggedTuple (periodSlot (u:=u) (fun _ => off))) + (π : IntSeries) (hπ : ∀X, 0 ≤ π.coeff X) (hπsum : ∑X∈π.coeff.support,π.coeff X=1) + (s k : ℕ) (hk : 1 ≤ k) (τ : ℝ) {q θ w : ℝ} (hq : q∈Set.Ioc 0 (1/2:ℝ)) + (hθ : θ∈Set.Icc (1-q^2) (1-q^2/4)) + (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (hw : w=((6*(2*k:ℕ):ℝ)*(2/q))) + (ha : w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m) < 1) : + ((primitiveMarkLaw q ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ false).product l).evenMomentSq + (fun x => initialMotifDensity hl off hsafe π s τ q x-1) k ≤ + (w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) / + (1-w^2*(3*rankSchurConstant/q)*Real.sqrt ((u:ℝ)/m)) := by + have hq' : q∈Set.Ioo 0 1 := ⟨hq.1,lt_of_le_of_lt hq.2 (by norm_num)⟩ + have he : (fun x => initialMotifDensity hl off hsafe π s τ q x-1) = + multilinear (nonconstantCoefficient (mixedMotifCoefficient hl off hsafe π s τ)) + (primitiveScore q) := by + funext x + rw [nonconstant_multilinear,mixedMotifCoefficient_empty hl off hsafe π hπsum] + rfl + rw [he] + apply (multilinear_moment_sq_scaled (primitiveMarkLaw q hq' false) (primitiveScore q) k hk (primitive_score_centered hq') + (div_pos (by norm_num) hq.1) (primitive_score_evenMoment hq' k) l _).trans + rw [←hw] + apply initial_centered_energy hl hm hum off hi hoff hsafe π hπ hπsum s τ hq hθ hmean hv _ ha + rw [hw]; positivity [hq.1] + +end TraceReconstruction + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/InitialRates.lean b/lean/OAI/Probability/TraceReconstruction/InitialRates.lean index 06e7935bfd9736336f2b7abe3c43dcf64df9f28f..a9b55b0cbf27702ac1eabc9e94e51db1729eace9 100644 --- a/lean/OAI/Probability/TraceReconstruction/InitialRates.lean +++ b/lean/OAI/Probability/TraceReconstruction/InitialRates.lean @@ -1,1401 +1,1401 @@ -import OAI.Probability.TraceReconstruction.InitialOracle -import OAI.Probability.TraceReconstruction.Amplification - -namespace OAI - -/-! -# InitialRates - -Initial geometric parameters, moment depths, error and overlap rates, and production of the base induction pair. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -variable {N q ω w : ℕ → ℝ} {J u m : ℕ → ℕ} - -/-- Exact power of the sharp initial rank prefactor; all channel losses are - subpower at the source's smallest scale. -/ -theorem initialPrefactor_rate (hN : Tendsto N atTop atTop) - {α β : ℝ} (hu : PowerRate N (fun t=>(u t:ℝ)) α) - (hm : PowerRate N (fun t=>(m t:ℝ)) β) (hq : PowerRate N q 0) (r d : ℕ) : - PowerRate N (fun t=>initialPrefactorCap (u t) (m t) r d (q t)) - (α/2-β*((d:ℝ)+(r:ℝ)/2)) := by - have hd : PowerRate N (fun t=>initialDifferenceCap d (q t)) 0 := by - have H := ((PowerRate.const hN (by positivity : (0:ℝ)<8*((d:ℝ)+1))).div (hq.pow 2)).sqrt.const_mul hN (by norm_num : (0:ℝ)<2) - simpa only [initialDifferenceCap,zero_mul,zero_sub,neg_zero,zero_div] using H - have hnum := (((hu.mul hm).const_mul hN (by norm_num : (0:ℝ)<144)).mul_const hN - (by positivity : (0:ℝ)<(2:ℝ)^(2*r))).mul (hd.pow (2*d+r+2)) - have hden := ((hm.div_const hN (by norm_num : (0:ℝ)<4)).pow d).mul - (((hu.mul hm).div_const hN (by positivity : (0:ℝ)<2*(r+1:ℝ))).sqrt) - have H := hnum.div (hden.mul ((hm.div_const hN (by norm_num : (0:ℝ)<4)).sqrt.pow (r+1))) - convert H using 1 - · ext t; simp only [initialPrefactorCap,Nat.cast_mul] - · push_cast; ring - -theorem periodCentral_rate (hN : Tendsto N atTop atTop) {α : ℝ} - (hu : PowerRate N (fun t=>(u t:ℝ)) α) {r : ℕ} (hr : 0periodCentralSumConstant (u t) r) (α*((r:ℝ)-3)/2) := by - have H := ((hu.div_const hN (by positivity : (0:ℝ)<3*(r+1:ℝ))).inv hN).const_mul hN - (by positivity : (0:ℝ)<((r+1:ℕ):ℝ)^2) - have H' := H.mul (((hu.const_mul hN (by norm_num : (0:ℝ)<2)).sqrt.const_mul hN - (by norm_num : (0:ℝ)<2)).pow (r-1)) - convert H' using 1 - · ext t; simp only [periodCentralSumConstant,Nat.cast_mul,Nat.cast_ofNat] - · rw [Nat.cast_sub (by omega : 1≤r)]; norm_num; ring - -theorem periodBounded_rate (hN : Tendsto N atTop atTop) {α : ℝ} - (hu : PowerRate N (fun t=>(u t:ℝ)) α) {r : ℕ} (hr : 2≤r) (M : ℕ) : - PowerRate N (fun t=>periodBoundedSumConstant (u t) r M) (α*((r:ℝ)-4)/2) := by - have H := (((hu.div_const hN (by positivity : (0:ℝ)<3*(r+1:ℝ))).inv hN).const_mul hN - (by positivity : (0:ℝ)<((r+1:ℕ):ℝ)^2)).mul_const hN (by positivity : (0:ℝ)<(M:ℝ)+1) - have H' := H.mul (((hu.const_mul hN (by norm_num : (0:ℝ)<2)).sqrt.const_mul hN - (by norm_num : (0:ℝ)<2)).pow (r-2)) - convert H' using 1 - · ext t; simp only [periodBoundedSumConstant,Nat.cast_mul,Nat.cast_ofNat] - · rw [Nat.cast_sub hr]; norm_num; ring - -theorem hiddenSigned_rate (hN : Tendsto N atTop atTop) {γ : ℝ} (hγ : 0<γ) - (hJ : PowerRate N (fun t=>(J t:ℝ)) γ) (hω : PowerRate N ω 0) (s : ℕ) : - PowerRate N (fun t=>hiddenSignedL2Bound (J t) s (ω t)) (-γ*((s:ℝ)+1/2)) := by - have hden := (hJ.mul (hω.pow 2)).add_const hN (by simpa using hγ) (by norm_num : (0:ℝ)≤2) - have hroot := ((PowerRate.const hN (by positivity : (0:ℝ)<4*((s:ℝ)+1))).div hden).sqrt - have hp := ((hroot.const_mul hN (by norm_num : (0:ℝ)<2)).pow s).pow 2 - have H := (hp.const_mul hN (by positivity : (0:ℝ)<((2:ℝ)^(s*s))^2)).mul hroot - convert H using 1 - · rfl - · push_cast; ring - -theorem hiddenUnsigned_rate (hN : Tendsto N atTop atTop) {γ : ℝ} (hγ : 0<γ) - (hJ : PowerRate N (fun t=>(J t:ℝ)) γ) (hω : PowerRate N ω 0) (s : ℕ) : - PowerRate N (fun t=>hiddenUnsignedL2Bound (J t) s (ω t)) (-γ/2) := by - have hden := (hJ.mul (hω.pow 2)).add_const hN (by simpa using hγ) (by norm_num : (0:ℝ)≤2) - have H := (((PowerRate.const hN (by norm_num : (0:ℝ)<4)).div hden).sqrt).const_mul hN - (by positivity : (0:ℝ)<((2:ℝ)^s)^2) - convert H using 1 - · rfl - · ring - -/-- The two eliminated large gaps are quantitatively visible in this exponent. -/ -theorem initial_central_rate (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - {r : ℕ} (hr : 0initialPrefactorCap (u t) (m t) r d (q t)*periodCentralSumConstant (u t) r) - (-123/250-(62/125)*(d:ℝ)-(1/500)*(r:ℝ)) := by - convert (initialPrefactor_rate hN hu hm hq r d).mul (periodCentral_rate hN hu hr) using 1; ring - -theorem initial_bounded_rate (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - {r : ℕ} (hr : 2≤r) (d M : ℕ) : - PowerRate N (fun t=>initialPrefactorCap (u t) (m t) r d (q t)*periodBoundedSumConstant (u t) r M) - (-369/500-(62/125)*(d:ℝ)-(1/500)*(r:ℝ)) := by - convert (initialPrefactor_rate hN hu hm hq r d).mul (periodBounded_rate hN hu hr M) using 1; ring - -/-- Fixed low degrees already beat the signed and pure source score exponents. -/ -theorem initial_signed_pattern_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) - {r : ℕ} (hr : 0initialSignedPatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-223/100) := by - by_cases hlin : ∃a,k=linearPattern a - · have H := (initial_central_rate hN hu hm hq hr 1).mul - (hiddenSigned_rate hN (by norm_num) hJ hω 300) - have hb : -123/250-(62/125)*(1:ℝ)-(1/500)*(r:ℝ)+(-(1/125)*((300:ℝ)+1/2)) ≤ -223/100 := by - have hh : (0:ℝ)≤r := Nat.cast_nonneg r - linarith - simpa only [initialSignedPatternCap,ite_eq_left hlin] using (H.upper hN).mono (by simpa using hb) - · have hd : 3≤∑h,(k h).order := odd_nonlinear_order k hk hlin - obtain ⟨a,b,hab,_,_⟩ := odd_pattern_pair k hk hlin - have hr2 : 2≤r := by have := a.isLt; have := b.isLt; have := hab; omega - have H := (initial_bounded_rate hN hu hm hq hr2 (∑h,(k h).order) (2*(2^300))).mul - (hiddenUnsigned_rate hN (by norm_num) hJ hω 300) - have hb : -369/500-(62/125)*(∑h,(k h).order:ℕ)-(1/500)*(r:ℝ)+(-(1/125)/2) ≤ -223/100 := by - have hd' : (3:ℝ)≤(∑h,(k h).order:ℕ) := by exact_mod_cast hd - have hr' : (2:ℝ)≤r := by exact_mod_cast hr2 - linarith - simpa only [initialSignedPatternCap,ite_eq_right hlin] using (H.upper hN).mono (by simpa using hb) - -theorem initial_pure_pattern_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) - {r : ℕ} (hr : 0initialPurePatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-37/25) := by - by_cases hlin : ∃a,k=linearPattern a - · have H := (initial_central_rate hN hu hm hq hr 1).mul - (hiddenSigned_rate hN (by norm_num) hJ hω 300) - have hb : -123/250-(62/125)*(1:ℝ)-(1/500)*(r:ℝ)+(-(1/125)*((300:ℝ)+1/2)) ≤ -37/25 := by - have hh : (0:ℝ)≤r := Nat.cast_nonneg r - linarith - simpa only [initialPurePatternCap,ite_eq_left hlin] using (H.upper hN).mono (by simpa using hb) - · have hd := (nonconstant_pattern_linear_or_order_two k hk).resolve_left hlin - have H := (initial_central_rate hN hu hm hq hr (∑h,(k h).order)).mul - (hiddenUnsigned_rate hN (by norm_num) hJ hω 300) - have hb : -123/250-(62/125)*(∑h,(k h).order:ℕ)-(1/500)*(r:ℝ)+(-(1/125)/2) ≤ -37/25 := by - have hd' : (2:ℝ)≤(∑h,(k h).order:ℕ) := by exact_mod_cast hd - have hr' : (0:ℝ)≤r := Nat.cast_nonneg r - linarith - simpa only [initialPurePatternCap,ite_eq_right hlin] using (H.upper hN).mono (by simpa using hb) - -theorem increasingTuple_card_le (u r : ℕ) : Fintype.card (IncreasingTuple u r) ≤ u^r := by - simpa only [Fintype.card_fun,Fintype.card_fin] using - Fintype.card_subtype_le (fun v : Fin r→Fin u => StrictMono v) - -theorem initialRankTail_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (r : ℕ) (a : ℝ) : - PowerUpper N (fun t=>initialRankTailCap (u t) (m t) r) a := by - have hcard : PowerUpper N (fun t=>(Fintype.card (IncreasingTuple (u t) r):ℝ)) ((123/250)*(r:ℝ)) := by - apply (hu.pow r).upper hN |>.of_abs_le - exact Eventually.of_forall fun t=>by - rw [abs_of_nonneg (Nat.cast_nonneg _),abs_of_nonneg (by positivity)] - exact_mod_cast increasingTuple_card_le (u t) r - have hpoly := hcard.mul hN (((hu.mul hm).sqrt.const_mul hN - (by positivity : (0:ℝ)<48*((r+1:ℕ):ℝ))).upper hN) - have hexpr : PowerRate N (fun t=>(m t:ℝ)/(1024*(u t:ℝ))) (1/250) := by - convert hm.div (hu.const_mul hN (by norm_num : (0:ℝ)<1024)) using 1; norm_num - have hexp := hexpr.exp_neg_upper hN (by norm_num) (a/2-((123/250)*(r:ℝ)+(123/250+62/125)/2)) - have H := ((PowerRate.const hN (by norm_num : (0:ℝ)<2)).upper hN).mul hN - ((hpoly.mul hN hexp).pow hN 2) - convert H using 1 - · ext t - simp only [initialRankTailCap,Nat.cast_mul,neg_div] - ring - · push_cast; ring - -theorem initialMomentRatio_rate (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hw : PowerRate N w 0) : - PowerRate N (fun t=>initialMomentRatio (u t) (m t) (q t) (w t)) (-1/500) := by - have H := ((hw.pow 2).mul ((PowerRate.const hN - (by positivity [rankSchurConstant_pos] : (0:ℝ)<3*rankSchurConstant)).div hq)).mul (hu.div hm).sqrt - convert H using 1 - · rfl - · norm_num - -theorem initial_fixed_high_tail_rate (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hw : PowerRate N w 0) : - PowerRate N (fun t=>4*(initialMomentRatio (u t) (m t) (q t) (w t))^3000/ - (1-initialMomentRatio (u t) (m t) (q t) (w t))) (-6) := by - have hρ := initialMomentRatio_rate hN hu hm hq hw - have hz := (hρ.upper hN).tendsto_zero hN (by norm_num) - have hden : PowerRate N (fun t=>1-initialMomentRatio (u t) (m t) (q t) (w t)) 0 := by - apply PowerRate.of_tendsto hN (by norm_num : (0:ℝ)<1) - simpa using tendsto_const_nhds.sub hz - convert ((hρ.pow 3000).const_mul hN (by norm_num : (0:ℝ)<4)).div hden using 1 - norm_num - -theorem initialSignedDegree_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (r : ℕ) : - PowerUpper N (fun t=>initialSignedDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-223/100) := by - by_cases hr : r=0 - · simpa only [initialSignedDegreeCap,ite_eq_left hr] using PowerUpper.zero hN (-223/100) - have hs : PowerUpper N (fun t=>∑k : Fin r→GapDifference, - if Odd (firstDifferenceCount k) then initialSignedPatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k else 0) (-223/100) := by - apply PowerUpper.sum hN Finset.univ - intro k _ - by_cases hk : Odd (firstDifferenceCount k) - · simpa only [ite_eq_left hk] using initial_signed_pattern_upper hN hu hm hq hJ hω (by omega) k hk - · simpa only [ite_eq_right hk] using PowerUpper.zero hN (-223/100) - have hc : (0:ℝ)<8*(Fintype.card (Fin r→GapDifference):ℝ) := by - have hp : 0.unchanged⟩ - positivity - have H := (((PowerRate.const hN hc).upper hN).mul hN hs) - simp only [zero_add] at H - simpa only [initialSignedDegreeCap,ite_eq_right hr] using H.add hN (initialRankTail_upper hN hu hm r (-223/100)) - -theorem initialPureDegree_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (r : ℕ) : - PowerUpper N (fun t=>initialPureDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-37/25) := by - by_cases hr : r=0 - · simpa only [initialPureDegreeCap,ite_eq_left hr] using PowerUpper.zero hN (-37/25) - have hs : PowerUpper N (fun t=>∑k : Fin r→GapDifference, - if k=unchangedPattern r then 0 else initialPurePatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-37/25) := by - apply PowerUpper.sum hN Finset.univ - intro k _ - by_cases hk : k=unchangedPattern r - · simpa only [ite_eq_left hk] using PowerUpper.zero hN (-37/25) - · simpa only [ite_eq_right hk] using initial_pure_pattern_upper hN hu hm hq hJ hω (by omega) k hk - have hc : (0:ℝ)<2*(Fintype.card (Fin r→GapDifference):ℝ) := by - have hp : 0.unchanged⟩ - positivity - have H := (((PowerRate.const hN hc).upper hN).mul hN hs) - simp only [zero_add] at H - simpa only [initialPureDegreeCap,ite_eq_right hr] using H.add hN (initialRankTail_upper hN hu hm r (-37/25)) - -theorem initialSignedCap_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : - PowerUpper N (fun t=>initialSignedCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t)) (-223/100) := by - have hs : PowerUpper N (fun t=>∑r∈Finset.range 3000,(w t)^(2*r)* - initialSignedDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-223/100) := by - apply PowerUpper.sum hN (Finset.range 3000) - intro r _ - simpa only [zero_mul,zero_add] using ((hw.pow (2*r)).upper hN).mul hN (initialSignedDegree_upper hN hu hm hq hJ hω r) - exact hs.add hN ((initial_fixed_high_tail_rate hN hu hm hq hw).upper hN |>.mono (by norm_num)) - -theorem initialPureCap_upper (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : - PowerUpper N (fun t=>initialPureCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t)) (-37/25) := by - have hs : PowerUpper N (fun t=>∑r∈Finset.range 3000,(w t)^(2*r)* - initialPureDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-37/25) := by - apply PowerUpper.sum hN (Finset.range 3000) - intro r _ - simpa only [zero_mul,zero_add] using ((hw.pow (2*r)).upper hN).mul hN (initialPureDegree_upper hN hu hm hq hJ hω r) - exact hs.add hN ((initial_fixed_high_tail_rate hN hu hm hq hw).upper hN |>.mono (by norm_num)) - -/-- Actual scalar budgets, not assumed coefficient bounds: all report- and - count-independent caps are strictly below the source clipping allowances. -/ -theorem initial_score_caps_eventually (hN : Tendsto N atTop atTop) - (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) - (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) - (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : - ∀ᶠt in atTop, - 64*initialSignedCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t) ≤ (N t)^(-11/5:ℝ) ∧ - 64*initialPureCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t) ≤ (N t)^(-7/5:ℝ) := by - have hc := (PowerRate.const hN (by norm_num : (0:ℝ)<64)).upper hN - have hs := hc.mul hN (initialSignedCap_upper hN hu hm hq hJ hω hw) - have hp := hc.mul hN (initialPureCap_upper hN hu hm hq hJ hω hw) - filter_upwards [hs (-11/5) (by norm_num),hp (-7/5) (by norm_num)] with t hs hp - exact ⟨(le_abs_self _).trans hs,(le_abs_self _).trans hp⟩ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -variable {N f g : ℕ→ℝ} {α β : ℝ} - -theorem PowerRate.sub_lower (hN : Tendsto N atTop atTop) - (hf : PowerRate N f α) (hg : PowerRate N g β) (hβα : β<α) : - PowerRate N (fun t=>f t-g t) α := by - have hz := ((hg.div hf).upper hN).tendsto_zero hN (sub_neg.mpr hβα) - apply hf.of_ratio hN (by norm_num : (0:ℝ)<1) - have H : Tendsto (fun t=>1-g t/f t) atTop (𝓝 1) := by - simpa using tendsto_const_nhds.sub hz - apply H.congr' - filter_upwards [hf.1] with t ht - field_simp [ht.ne'] - -theorem PowerRate.nat_sub_lower (hN : Tendsto N atTop atTop) {f g : ℕ→ℕ} - (hf : PowerRate N (fun t=>(f t:ℝ)) α) - (hg : PowerRate N (fun t=>(g t:ℝ)) β) (hβα : β<α) : - PowerRate N (fun t=>(f t-g t:ℕ)) α := by - have H := hf.sub_lower hN hg hβα - apply H.congr - filter_upwards [H.1] with t ht - have hg : g t≤f t := by exact_mod_cast (sub_pos.mp ht).le - rw [Nat.cast_sub hg] - -/-- Literal integer choices of the initial-pair construction, including the outer floors. -/ -def sourceInitialM (N : ℝ) : ℕ := ⌊N^(62/125:ℝ)⌋₊ -def sourceInitialK (N : ℝ) : ℕ := ⌊N^(123/250:ℝ)⌋₊ -def sourceInitialPeriodSize (N : ℝ) : ℕ := 2*sourceInitialM N-1 -def sourceInitialCapacity (N : ℝ) : ℕ := ⌊N/(sourceInitialPeriodSize N:ℝ)⌋₊ -def sourceInitialJ (q N : ℝ) : ℕ := - ⌊((sourceInitialCapacity N:ℝ)-sourceInitialK N)/ - (2*(initialSideCount q (sourceInitialM N):ℝ)+1)⌋₊ -def sourceInitialP (q N : ℝ) : ℕ := - sourceInitialJ q N*(2*initialSideCount q (sourceInitialM N)+1)+sourceInitialK N -/-- One-based manuscript anchors translated once to zero-based list indices. -/ -def sourceInitialAnchor (q N : ℝ) : ℤ := ((sourceInitialP q N/2:ℕ):ℤ)-1 - -theorem sourceInitialM_rate (hN : Tendsto N atTop atTop) : - PowerRate N (fun t=>(sourceInitialM (N t):ℝ)) (62/125) := by - have H := ((PowerRate.base hN).rpow (62/125)).nat_floor hN (by norm_num) - simpa only [sourceInitialM,one_mul] using H - -theorem sourceInitialK_rate (hN : Tendsto N atTop atTop) : - PowerRate N (fun t=>(sourceInitialK (N t):ℝ)) (123/250) := by - have H := ((PowerRate.base hN).rpow (123/250)).nat_floor hN (by norm_num) - simpa only [sourceInitialK,one_mul] using H - -theorem sourceInitialPeriodSize_rate (hN : Tendsto N atTop atTop) : - PowerRate N (fun t=>(sourceInitialPeriodSize (N t):ℝ)) (62/125) := by - have hh : PowerRate N (fun t=>(2*sourceInitialM (N t):ℕ)) (62/125) := by - simpa only [Nat.cast_mul,Nat.cast_ofNat] using (sourceInitialM_rate hN).const_mul hN (by norm_num : (0:ℝ)<2) - exact hh.nat_sub_lower hN (PowerRate.const hN (by norm_num : (0:ℝ)<(1:ℕ))) (by norm_num) - -theorem sourceInitialCapacity_rate (hN : Tendsto N atTop atTop) : - PowerRate N (fun t=>(sourceInitialCapacity (N t):ℝ)) (63/125) := by - have H := ((PowerRate.base hN).div (sourceInitialPeriodSize_rate hN)).nat_floor hN (by norm_num) - convert H using 1 - · rfl - · norm_num - -theorem sourceInitialSide_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} - (hq : PowerRate N q 0) : - PowerRate N (fun t=>(initialSideCount (q t) (sourceInitialM (N t)):ℝ)) (62/125) := by - have H := (hq.mul (sourceInitialM_rate hN)).nat_floor hN (by norm_num) - simpa only [initialSideCount,zero_add] using H - -theorem sourceInitialJ_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} - (hq : PowerRate N q 0) : - PowerRate N (fun t=>(sourceInitialJ (q t) (N t):ℝ)) (1/125) := by - have hn := (sourceInitialCapacity_rate hN).sub_lower hN (sourceInitialK_rate hN) (by norm_num) - have hd := ((sourceInitialSide_rate hN hq).const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN - (by norm_num) (by norm_num : (0:ℝ)≤1) - have H := (hn.div hd).nat_floor hN (by norm_num) - convert H using 1 - · rfl - · norm_num - -theorem initialOverlap_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} - (_hq : ∀t,0(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : - PowerRate N (fun t=>initialOverlapLower (q t)) 0 := by - refine ⟨Eventually.of_forall (fun t=>initialOverlapLower_pos _),?_⟩ - have H := (hΛ.const_mul (-(32+3*primitivePeriodConstant))).sub - ((Real.tendsto_log_atTop.comp hN).const_div_atTop (Real.log 1536)) - simp only [mul_zero,sub_zero] at H - apply H.congr' - filter_upwards [] with t - rw [initialOverlapLower,Real.log_div (Real.exp_pos _).ne' (by norm_num),Real.log_exp] - simp only [zpow_neg,zpow_ofNat,Function.comp_apply] - ring - -theorem deletion_rate_zero (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} - (hq : ∀t,q t∈Set.Ioc 0 1) - (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : - PowerRate N q 0 := by - refine ⟨Eventually.of_forall (fun t=>(hq t).1),?_⟩ - apply squeeze_zero_norm' _ hΛ - filter_upwards [hN.eventually_gt_atTop 1] with t hNt - have hp := (hq t).1 - have hle := (hq t).2 - have hqinv : 1≤(q t)⁻¹ := (one_le_inv₀ hp).mpr hle - have hlog : |Real.log (q t)| ≤ (q t)^(-3:ℤ) := by - rw [abs_of_nonpos (Real.log_nonpos hp.le hle),←Real.log_inv, zpow_neg,zpow_ofNat] - have hh := Real.log_le_sub_one_of_pos (inv_pos.mpr hp) - have hcube : (q t)⁻¹ ≤ ((q t)⁻¹)^3 := by nlinarith [sq_nonneg ((q t)⁻¹-1)] - rw [←inv_pow] - linarith - rw [Real.norm_eq_abs,abs_div,abs_of_pos (Real.log_pos hNt)] - exact div_le_div_of_nonneg_right hlog (Real.log_pos hNt).le - -/-- Mechanical realization of the base scalar score budgets from the actual - integer choices and the unchanged known channel. -/ -theorem source_initial_score_caps {q w : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hq : ∀t,q t∈Set.Ioc 0 1) - (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) - (hw : PowerRate N w 0) : - ∀ᶠt in atTop, - 64*initialSignedCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) - (sourceInitialM (N t)) 3000 300 (q t) (initialOverlapLower (q t)) (w t) ≤ (N t)^(-11/5:ℝ) ∧ - 64*initialPureCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) - (sourceInitialM (N t)) 3000 300 (q t) (initialOverlapLower (q t)) (w t) ≤ (N t)^(-7/5:ℝ) := by - exact initial_score_caps_eventually hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) - (deletion_rate_zero hN hq hΛ) (sourceInitialJ_rate hN (deletion_rate_zero hN hq hΛ)) - (initialOverlap_rate hN (fun t=>(hq t).1) hΛ) hw - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- The manuscript's one-based middle defect, translated to a list index. -/ -def sourceInitialOffset (m : ℕ) (hm : 4 ≤ m) : Fin m := - ⟨m/2-1,by omega⟩ - -theorem sourceInitialOffset_interior (m : ℕ) (hm : 4 ≤ m) : - 1 ≤ (sourceInitialOffset m hm).val ∧ (sourceInitialOffset m hm).val+1 < m := by - simp only [sourceInitialOffset]; omega - -theorem sourceInitialOffset_middle (m : ℕ) (hm : 4 ≤ m) : - |((sourceInitialOffset m hm).val:ℝ)-(m:ℝ)/2| ≤ 2 := by - have h1 : 2*(m/2) ≤ m := Nat.mul_div_le m 2 - have h2 : m<2*(m/2+1) := by omega - have h3 : 1 ≤ m/2 := by omega - simp only [sourceInitialOffset,Nat.cast_sub h3,Nat.cast_one] - rw [abs_le] - have hh1 : (2:ℝ)*(m/2:ℕ) ≤ m := by exact_mod_cast h1 - have hh2 : (m:ℝ)<2*((m/2:ℕ)+1) := by exact_mod_cast h2 - constructor <;> linarith - -theorem sourceInitialOffset_safe (u m : ℕ) (hm : 4 ≤ m) : - SafeTaggedTuple (periodSlot (u:=u) (fun _=>sourceInitialOffset m hm)) := by - have hi := sourceInitialOffset_interior m hm - exact constant_period_safe _ hi.1 hi.2 (by omega) id strictMono_id - -/-- A literal arithmetic margin implies every base window placement condition. -/ -theorem initial_anchor_geometry (J K t s : ℕ) (hK : 12*(J+2^s+1) ≤ K) : - let a : ℤ := (((J*(2*t+1)+K)/2:ℕ):ℤ)-1 - (J*t+J:ℕ) ≤ a ∧ a+(2^s:ℕ) ≤ (J*t+K:ℕ) ∧ - (K:ℝ)/3 ≤ 2*((a-(J*t:ℕ):ℤ)-J)+1 ∧ - (K:ℝ)/3 ≤ 2*K-(2*((a-(J*t:ℕ):ℤ)+(2:ℝ)^s)+1) := by - have he : (J*(2*t+1)+K)/2=J*t+(J+K)/2 := by - rw [show J*(2*t+1)+K=2*(J*t)+(J+K) by ring,Nat.mul_add_div (by norm_num)] - have hlo : 2*((J+K)/2) ≤ J+K := Nat.mul_div_le _ 2 - have hhi : J+K<2*((J+K)/2+1) := by omega - have hK1 : 12*(J+1) ≤ K := by nlinarith [Nat.zero_le (2^s)] - dsimp only - rw [he] - have hi1 : J+1 ≤ (J+K)/2 := by omega - have hi2 : (J+K)/2+(2^s:ℕ) ≤ K+1 := by omega - constructor - · apply (le_sub_iff_add_le).mpr - exact_mod_cast (show J*t+J+1 ≤ J*t+(J+K)/2 from by omega) - constructor - · push_cast only [Nat.cast_add] - omega - have hl : (2:ℝ)*((J+K)/2:ℕ) ≤ J+K := by exact_mod_cast hlo - have hh : (J:ℝ)+K<2*(((J+K)/2:ℕ)+1) := by exact_mod_cast hhi - have hk : (12:ℝ)*((J:ℝ)+(2:ℝ)^s+1) ≤ K := by exact_mod_cast hK - simp only [Nat.cast_add,Int.cast_sub,Int.cast_add,Int.cast_natCast,Int.cast_one,Int.cast_mul,Nat.cast_mul] - constructor <;> nlinarith [show (0:ℝ) ≤ (2:ℝ)^s by positivity] - -theorem prouhetSeries_coeff_zero (s : ℕ) : (prouhetSeries s).coeff 0=1 := by - induction s with - | zero => simp [prouhetSeries] - | succ s ih => - have hp : (0:ℤ)<(2^s:ℕ) := by positivity - rw [prouhetSeries_succ_coeff,ih,(prouhetSeries_coeff_spec s).1 _ (Or.inl (by omega)),sub_zero] - -/-- Literal source initial words really are different, not only their formal templates. -/ -theorem motifPeriodWord_ne {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) - (u s : ℕ) (a : ℤ) (ha : 0 ≤ a) (hau : a((f ⟨a.toNat,hj⟩):Fin m).val) H - have ha' : (a.toNat:ℤ)=a := Int.toNat_of_nonneg ha - simp only [motifOffset,ha',sub_self,prouhetSeries_coeff_zero] at h - have hpos : (0:ℤ)<(2^s:ℕ) := by positivity - norm_num [motifIndicator,hpos,motifShift] at h - -/-- Floors in the initial construction waste no more than one long slot. -/ -theorem initial_period_count_bounds {N : ℝ} {m K t : ℕ} - (hL : 0<2*m-1) (hN : 0 ≤ N) (hK : (K:ℝ) ≤ ⌊N/(2*m-1:ℕ)⌋₊) : - let F : ℕ := ⌊N/(2*m-1:ℕ)⌋₊ - let J : ℕ := ⌊((F:ℝ)-K)/(2*t+1:ℕ)⌋₊ - let P : ℕ := J*(2*t+1)+K - (P:ℝ)*(2*m-1:ℕ) ≤ N ∧ N<((P:ℝ)+(2*t+1:ℕ)+1)*(2*m-1:ℕ) := by - dsimp only - set F : ℕ := ⌊N/(2*m-1:ℕ)⌋₊ - set J : ℕ := ⌊((F:ℝ)-K)/(2*t+1:ℕ)⌋₊ - have hd : (0:ℝ)<(2*t+1:ℕ) := by positivity - have hl : (0:ℝ)<(2*m-1:ℕ) := by exact_mod_cast hL - have hjlo := Nat.floor_le (div_nonneg (sub_nonneg.mpr hK) hd.le) - have hjhi := Nat.lt_floor_add_one (((F:ℝ)-K)/(2*t+1:ℕ)) - change (J:ℝ) ≤ _ at hjlo - change _<(J:ℝ)+1 at hjhi - have hflo := Nat.floor_le (div_nonneg hN hl.le) - have hfhi := Nat.lt_floor_add_one (N/(2*m-1:ℕ)) - change (F:ℝ) ≤ _ at hflo - change _<(F:ℝ)+1 at hfhi - have hp : (J:ℝ)*(2*t+1:ℕ)+K ≤ F := by - have H := (le_div_iff₀ hd).mp hjlo - linarith - have hp' : (F:ℝ)<(J:ℝ)*(2*t+1:ℕ)+K+(2*t+1:ℕ) := by - have H := (div_lt_iff₀ hd).mp hjhi - nlinarith - constructor - · push_cast - simpa only [Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] using - (mul_le_mul_of_nonneg_right hp hl.le).trans ((le_div_iff₀ hl).mp hflo) - · have H := (div_lt_iff₀ hl).mp hfhi - push_cast at hp' ⊢ - nlinarith - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- Source moment order is twice this integer. -/ -def sourceHalfMoment (B D : ℕ) (n : ℝ) (i : ℕ) : ℕ := - ⌈(10^8:ℝ)*2^(10*B)*(totalScoreExponent B D+B+1)*Real.log n/ - Real.log (sourceTargetScale B D n i)⌉₊ - -theorem sourceEpsilon_le_one (B D : ℕ) : sourceEpsilon B D ≤ 1 := by - unfold sourceEpsilon - apply (div_le_one (by positivity)).mpr - have H : (1:ℝ) ≤ 2^(4*B+100) := one_le_pow₀ (by norm_num) - nlinarith [show (0:ℝ) ≤ D by positivity] - -theorem sourceTargetScale_tendsto (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) - {n Λ H : ℕ→ℝ} (i : ℕ→ℕ) (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) - (hΛ : ∀t,1 ≤ Λ t) (hrel : ∀t,Real.log (n t)=Λ t*H t) : - Tendsto (fun t=>sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t)) atTop atTop := by - have hlog : Tendsto (fun t=>Real.log (sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t))) atTop atTop := by - apply tendsto_atTop_mono' atTop _ (((tendsto_rpow_atTop hζ.1).comp hH).atTop_div_const (by norm_num : (0:ℝ)<2)) - filter_upwards [hH.eventually_ge_atTop 1,hn.eventually_gt_atTop 1] with t ht hnt - have hl := sourceTargetScale_log_lower B ζ (H t) (n t) (i t) hB hζ.2.le ht hnt - have he : Real.log (n t)/(2*(H t)^(1-ζ))=Λ t*(H t)^ζ/2 := by - rw [hrel t,Real.rpow_sub (by linarith : 0((sourceDepth B ζ (H t):ℝ)+1)^h*Λ t/ - Real.log (sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t))) atTop (𝓝 0) := by - have hh := source_uniform_absorption B h ζ hB hζ i hn hH (fun t=>lt_of_lt_of_le (by norm_num) (hΛ t)) hrel - apply squeeze_zero' _ _ hh - · filter_upwards [(sourceTargetScale_tendsto B ζ hB hζ i hn hH hΛ hrel).eventually_gt_atTop 1] with t ht - exact div_nonneg (mul_nonneg (by positivity) (by linarith [hΛ t])) (Real.log_pos ht).le - · filter_upwards [(sourceTargetScale_tendsto B ζ hB hζ i hn hH hΛ hrel).eventually_gt_atTop 1] with t ht - apply div_le_div_of_nonneg_left (by positivity [hΛ t]) - (mul_pos (sourceEpsilon_pos _ _) (Real.log_pos ht)) - exact mul_le_of_le_one_left (Real.log_pos ht).le (sourceEpsilon_le_one _ _) - -theorem totalScoreExponent_bounds (B D : ℕ) (hB : 2 ≤ B) : - 11/5 ≤ totalScoreExponent B D ∧ totalScoreExponent B D ≤ 3+(D:ℝ)*B := by - have hdim (i : ℕ) : (2:ℝ) ≤ (if i norm_cast - have hlo : 0 ≤ ∑i∈Finset.range D,blockGain (if i linarith - -theorem sourceHalfMoment_bounds (B D i : ℕ) {n : ℝ} (hB : 2 ≤ B) (hn : 1Real.log (N t)) 0 := by - refine ⟨(hN.eventually_gt_atTop 1).mono (fun _ ht=>Real.log_pos ht),?_⟩ - convert - (isLittleO_log_rpow_atTop (by norm_num : (0:ℝ)<1)).tendsto_div_nhds_zero.comp - (Real.tendsto_log_atTop.comp hN) using 1 - ext t - simp only [Function.comp_apply,Real.rpow_one] - -/-- Only arithmetic predicates on the literal source integers. -/ -structure SourceInitialGeometry (q N : ℝ) : Prop where - m_large : 128 ≤ sourceInitialM N - K_pos : 0 < sourceInitialK N - K_le_m : sourceInitialK N ≤ sourceInitialM N - seed : 16 ≤ q^3*(sourceInitialM N:ℝ) - count : 8 ≤ ((sourceInitialK N*sourceInitialM N:ℕ):ℝ)*q^2 - anchor_margin : 12*(sourceInitialJ q N+2^300+1) ≤ sourceInitialK N - smoothing_margin : ((2*(2^300):ℕ):ℝ) < (sourceInitialK N:ℝ)/(3*(3000+1:ℝ)) - length_lower : N/2 ≤ (sourceInitialP q N:ℝ)*(sourceInitialPeriodSize N:ℝ) - length_upper : (sourceInitialP q N:ℝ)*(sourceInitialPeriodSize N:ℝ) ≤ N - -/-- All floor, seed, count, placement and length restrictions are automatic - in the actual joint regime; no change of the deletion rate at the base scale. -/ -theorem source_initial_geometry {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hq : ∀t,q t∈Set.Ioc 0 1) - (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : - ∀ᶠt in atTop,SourceInitialGeometry (q t) (N t) := by - have hm := sourceInitialM_rate hN - have hK := sourceInitialK_rate hN - have hqrate := deletion_rate_zero hN hq hΛ - have hJ := sourceInitialJ_rate hN hqrate - have hL := sourceInitialPeriodSize_rate hN - have hF := sourceInitialCapacity_rate hN - have ht := sourceInitialSide_rate hN hqrate - have hm128 := (hm.tendsto_atTop hN (by norm_num)).eventually_ge_atTop 128 - have hKm := hK.eventually_lt hN hm (by norm_num) - have hKF := hK.eventually_lt hN hF (by norm_num) - have hseed := ((hqrate.pow 3).mul hm).tendsto_atTop hN (by norm_num) - have hcount := ((hK.mul hm).mul (hqrate.pow 2)).tendsto_atTop hN (by norm_num) - have hanchor := ((hJ.add_const hN (by norm_num) (by positivity : (0:ℝ)≤2^300+1)).const_mul - hN (by norm_num : (0:ℝ)<12)).eventually_lt hN hK (by norm_num) - have hsm := (hK.tendsto_atTop hN (by norm_num)).eventually_gt_atTop ((2*(2^300):ℝ)*(3*3001)) - have hloss : PowerRate N (fun t=>(2*(initialSideCount (q t) (sourceInitialM (N t)):ℝ)+2)* - (sourceInitialPeriodSize (N t):ℝ)) (124/125) := by - convert ((ht.const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN - (by norm_num) (by norm_num : (0:ℝ)≤2)).mul hL using 1 - norm_num - have hloss' := hloss.eventually_lt hN ((PowerRate.base hN).div_const hN (by norm_num : (0:ℝ)<2)) (by norm_num) - filter_upwards [hN.eventually_gt_atTop 0,hm128,hK.1,hKm,hKF, - hseed.eventually_ge_atTop 16,hcount.eventually_ge_atTop 8,hanchor,hsm,hloss'] with t hNt hm128 hKpos hKm hKF hs hc ha hsm hloss - have hmn : 128 ≤ sourceInitialM (N t) := by exact_mod_cast hm128 - have hKn : 0 < sourceInitialK (N t) := by exact_mod_cast hKpos - have hLpos : 0 < sourceInitialPeriodSize (N t) := by unfold sourceInitialPeriodSize; omega - have hcnt := initial_period_count_bounds (m:=sourceInitialM (N t)) - (K:=sourceInitialK (N t)) (t:=initialSideCount (q t) (sourceInitialM (N t))) - (N:=N t) hLpos hNt.le hKF.le - have hcnt' : (sourceInitialP (q t) (N t):ℝ)*(sourceInitialPeriodSize (N t):ℝ) ≤ N t ∧ - N t<((sourceInitialP (q t) (N t):ℝ)+(2*initialSideCount (q t) (sourceInitialM (N t))+1:ℕ)+1)* - (sourceInitialPeriodSize (N t):ℝ) := by - simpa only [sourceInitialP,sourceInitialJ,sourceInitialCapacity,sourceInitialPeriodSize, - Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] using hcnt - refine ⟨hmn,hKn,?_,hs,?_,?_,?_,?_,hcnt'.1⟩ - · exact_mod_cast hKm.le - · simpa only [Nat.cast_mul] using hc - · apply (Nat.cast_le (α:=ℝ)).mp - simp only [Nat.cast_mul,Nat.cast_add,Nat.cast_pow,Nat.cast_ofNat,Nat.cast_one] - simpa only [add_assoc] using ha.le - · apply (lt_div_iff₀ (by norm_num : (0:ℝ)<3*(3000+1))).mpr - simpa only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,show (3000+1:ℝ)=3001 by norm_num] using hsm - · have H := hcnt'.2 - push_cast at H - nlinarith only [H,hloss] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- The exact varying even moment order is subpower at EVERY working scale. -/ -theorem sourceHalfMoment_rate (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) - {n Λ H : ℕ→ℝ} (i : ℕ→ℕ) (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) - (hΛ : ∀t,1 ≤ Λ t) (hrel : ∀t,Real.log (n t)=Λ t*H t) : - PowerRate (fun t=>sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t)) - (fun t=>(sourceHalfMoment B (sourceDepth B ζ (H t)) (n t) (i t):ℝ)) 0 := by - let C : ℝ := ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1) - let A : ℝ := C+1+(B:ℝ)*Real.log 2 - have hC : 0(k t:ℝ)) 0) : - PowerRate N (fun t=>sourceInitialWeight (q t) (k t)) 0 := by - have H := (hk.const_mul hN (by norm_num : (0:ℝ)<24)).div hq - convert H using 1 - · ext t - simp only [sourceInitialWeight,Nat.cast_mul,Nat.cast_ofNat] - ring - · norm_num - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -variable {N q w : ℕ→ℝ} {k : ℕ→ℕ} - -def initialClipFactor (N q w : ℝ) : ℝ := - 4*(initialMomentRatio (sourceInitialK N) (sourceInitialM N) q w/ - (1-initialMomentRatio (sourceInitialK N) (sourceInitialM N) q w)) - -theorem initialClipFactor_rate (hN : Tendsto N atTop atTop) - (hq : PowerRate N q 0) (hw : PowerRate N w 0) : - PowerRate N (fun t=>initialClipFactor (N t) (q t) (w t)) (-1/500) := by - have hρ := initialMomentRatio_rate hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) hq hw - have hden := (PowerRate.const hN (by norm_num : (0:ℝ)<1)).sub_lower hN hρ (by norm_num) - simpa only [initialClipFactor,sub_zero] using (hρ.div hden).const_mul hN (by norm_num : (0:ℝ)<4) - -/-- The source moment is genuinely used in clipping: the exponent is linear - in that moment, not a fixed negative power of the intermediate length. -/ -theorem initial_clip_exp_bound (hN : Tendsto N atTop atTop) - (hq : PowerRate N q 0) (hw : PowerRate N w 0) (hk : ∀ᶠt in atTop,1 ≤ k t) : - ∀ᶠt in atTop, - Real.sqrt (6*(initialClipFactor (N t) (q t) (w t))^(k t)) ≤ - Real.exp (-(k t:ℝ)*Real.log (N t)/2000) := by - have hfac := initialClipFactor_rate hN hq hw - have hu := hfac.upper hN (-3/2000) (by norm_num) - filter_upwards [hk,hfac.1,hu,hN.eventually_gt_atTop 1, - (Real.tendsto_log_atTop.comp hN).eventually_ge_atTop (2000*Real.log 6)] with t hk hp hu hn hlog - rw [abs_of_pos hp] at hu - have hh := Real.log_le_log hp hu - rw [Real.log_rpow (by linarith : 0initialOverlapLower (q t)) 0) - (hk : PowerRate N (fun t=>(k t:ℝ)) 0) : - ∀ᶠt in atTop, - 2*Real.exp (-((sourceInitialK (N t)*sourceInitialM (N t):ℕ):ℝ)*(q t)^4/64)+ - Real.exp (-(sourceInitialJ (q t) (N t):ℝ)*(initialOverlapLower (q t))^4/16) ≤ - 3*Real.exp (-(k t:ℝ)*Real.log (N t)) := by - have hlow : PowerRate N (fun t=>(k t:ℝ)*Real.log (N t)) 0 := by - simpa using hk.mul (PowerRate.log_base hN) - have hfirst := (((sourceInitialK_rate hN).mul (sourceInitialM_rate hN)).mul - (hq.pow 4)).div_const hN (by norm_num : (0:ℝ)<64) - have hsecond := ((sourceInitialJ_rate hN hq).mul (hω.pow 4)).div_const hN (by norm_num : (0:ℝ)<16) - filter_upwards [hlow.eventually_lt hN hfirst (by norm_num),hlow.eventually_lt hN hsecond (by norm_num)] with t h1 h2 - have he1 := Real.exp_le_exp.mpr (neg_le_neg h1.le) - have he2 := Real.exp_le_exp.mpr (neg_le_neg h2.le) - push_cast - simp only [neg_div,neg_mul] at he1 he2 ⊢ - linarith - -/-- A completely quantitative sufficient moment inequality for the actual - initial error. This is later discharged by the literal ceiling r_0/2. -/ -theorem initial_error_eventually {n A : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hn : Tendsto n atTop atTop) (hA : ∀ᶠt in atTop,1 ≤ A t) - (hq : ∀t,q t∈Set.Ioc 0 1) - (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) - (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) - (hmoment : ∀ᶠt in atTop, 10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) : - ∀ᶠt in atTop, - initialErrorCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) - (sourceInitialM (N t)) (k t) (q t) (initialOverlapLower (q t)) - (sourceInitialWeight (q t) (k t)) ≤ (n t)^(-100*A t) := by - have hqrate := deletion_rate_zero hN hq hΛ - have hω := initialOverlap_rate hN (fun t=>(hq t).1) hΛ - have hw := sourceInitialWeight_rate hN hqrate hk - have hclip := initial_clip_exp_bound hN hqrate hw hk1 - have hmeta := initial_metadata_exp_bound hN hqrate hω hk - filter_upwards [hclip,hmeta,hmoment,hA,hn.eventually_gt_atTop 1, - (Real.tendsto_log_atTop.comp hn).eventually_ge_atTop (Real.log 4)] with t hc hm hmom hA hn hlog - have hAn : 0 ≤ A t*Real.log (n t) := mul_nonneg (by linarith) (Real.log_pos hn).le - have he1 : Real.exp (-(k t:ℝ)*Real.log (N t)/2000) ≤ Real.exp (-500*(A t*Real.log (n t))) := - Real.exp_le_exp.mpr (by nlinarith) - have he2 : Real.exp (-(k t:ℝ)*Real.log (N t)) ≤ Real.exp (-500*(A t*Real.log (n t))) := - Real.exp_le_exp.mpr (by nlinarith) - have herr : initialErrorCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) - (sourceInitialM (N t)) (k t) (q t) (initialOverlapLower (q t)) - (sourceInitialWeight (q t) (k t)) ≤ 4*Real.exp (-500*(A t*Real.log (n t))) := by - unfold initialErrorCap - change Real.sqrt (6*initialClipFactor (N t) (q t) (sourceInitialWeight (q t) (k t))^(k t))+_ ≤ _ - nlinarith only [hc,hm,he1,he2] - apply herr.trans - rw [Real.rpow_def_of_pos (by linarith : 0f t+g t) α := by - have hz := ((hg.div hf).upper hN).tendsto_zero hN (sub_neg.mpr hβα) - apply hf.of_ratio hN (by norm_num : (0:ℝ)<1) - have H : Tendsto (fun t=>1+g t/f t) atTop (𝓝 1) := by - simpa using tendsto_const_nhds.add hz - apply H.congr' - filter_upwards [hf.1] with t ht - field_simp [ht.ne'] - -theorem PowerRate.nat_ceil (hN : Tendsto N atTop atTop) (hf : PowerRate N f α) - (ha : 0<α) : PowerRate N (fun t=>(⌈f t⌉₊:ℝ)) α := by - exact hf.of_ratio hN (by norm_num : (0:ℝ)<1) - (tendsto_nat_ceil_div_atTop.comp (hf.tendsto_atTop hN ha)) - -def sourceOverlapConstant (q : ℝ) : ℝ := (2:ℝ)^40/(q*initialOverlapLower q) -def sourceInitialCount (q N : ℝ) : ℕ := - ⌈sourceOverlapConstant q*(initialSideCount q (sourceInitialM N):ℝ)*(sourceInitialP q N:ℝ)⌉₊ - -theorem sourceInitialP_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hq : PowerRate N q 0) : - PowerRate N (fun t=>(sourceInitialP (q t) (N t):ℝ)) (63/125) := by - have hj := sourceInitialJ_rate hN hq - have ht := ((sourceInitialSide_rate hN hq).const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN - (by norm_num) (by norm_num : (0:ℝ)≤1) - have H := (hj.mul ht).add_lower hN (sourceInitialK_rate hN) (by norm_num) - convert H using 1 - · ext t - simp only [sourceInitialP,Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] - · norm_num - -theorem sourceOverlapConstant_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hq : PowerRate N q 0) (hω : PowerRate N (fun t=>initialOverlapLower (q t)) 0) : - PowerRate N (fun t=>sourceOverlapConstant (q t)) 0 := by - simpa only [sourceOverlapConstant,add_zero,sub_zero] using - (PowerRate.const hN (by positivity : (0:ℝ)<(2:ℝ)^40)).div (hq.mul hω) - -theorem sourceInitialCount_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) - (hq : PowerRate N q 0) (hω : PowerRate N (fun t=>initialOverlapLower (q t)) 0) : - PowerRate N (fun t=>(sourceInitialCount (q t) (N t):ℝ)) 1 := by - have H := (((sourceOverlapConstant_rate hN hq hω).mul (sourceInitialSide_rate hN hq)).mul - (sourceInitialP_rate hN hq)).nat_ceil hN (by norm_num) - convert H using 1 - · rfl - · norm_num - -theorem sourceOverlapConstant_pos {q : ℝ} (hq : 0(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) - (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) - (hmoment : ∀ᶠt in atTop,10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) : - ∀ᶠt in atTop, - SourceInitialGeometry (q t) (N t) ∧ - sourceInitialError (q t) (N t) (k t) ≤ (n t)^(-100*A t) ∧ - Nonempty (OracleTracePair (q t) (sourceInitialWord (q t) (N t) (-1)) - (sourceInitialWord (q t) (N t) 1) (k t) (sourceInitialError (q t) (N t) (k t)) ((N t)^(-11/5:ℝ))) ∧ - Nonempty (OracleTracePair (q t) (sourceInitialPure (q t) (N t)) - (sourceInitialWord (q t) (N t) 1) (k t) (sourceInitialError (q t) (N t) (k t)) ((N t)^(-7/5:ℝ))) := by - have hq' (t) : q t ∈ Set.Ioc 0 1 := ⟨(hq t).1,by linarith [(hq t).2]⟩ - have hqr := deletion_rate_zero hN hq' hΛ - have hw := sourceInitialWeight_rate hN hqr hk - have herr := initial_error_eventually hN hn hA hq' hΛ hk hk1 hmoment - have hgeo := source_initial_geometry hN hq' hΛ - have hcap := source_initial_score_caps hN hq' hΛ hw - have hρ := (initialMomentRatio_rate hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) hqr hw).upper hN |>.tendsto_zero hN (by norm_num) - have hsmall := ((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<100)).comp hn).eventually_le_const (by norm_num : (0:ℝ)<1/2) - filter_upwards [hgeo,hcap,herr,hk1,hA,hn.eventually_gt_atTop 1,hN.eventually_gt_atTop 0, - hρ.eventually_le_const (by norm_num : (0:ℝ)<1/2),hsmall] with t hg hcap he hk1 ha hnt hNt hρ hsmall - have hm : 4 ≤ sourceInitialM (N t) := (by norm_num : 4 ≤ 128).trans hg.m_large - let off := sourceInitialOffset (sourceInitialM (N t)) hm - have hi := sourceInitialOffset_interior _ hm - have hanchor := initial_anchor_geometry (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) - (initialSideCount (q t) (sourceInitialM (N t))) 300 hg.anchor_margin - change _ ≤ sourceInitialAnchor (q t) (N t) ∧ sourceInitialAnchor (q t) (N t)+(2^300:ℕ) ≤ _ ∧ _ at hanchor - have he' : sourceInitialError (q t) (N t) (k t) ≤ 1/2 := by - exact he.trans ((Real.rpow_le_rpow_of_exponent_le hnt.le (by linarith : -100*A t ≤ -100)).trans hsmall) - have hc : Real.sqrt (6*(4*(initialMomentRatio (sourceInitialK (N t)) (sourceInitialM (N t)) (q t) - (sourceInitialWeight (q t) (k t))/(1-initialMomentRatio (sourceInitialK (N t)) - (sourceInitialM (N t)) (q t) (sourceInitialWeight (q t) (k t)))))^(k t)) ≤ 1/2 := by - have ht : 0 ≤ 2*Real.exp (-((sourceInitialK (N t)*sourceInitialM (N t):ℕ):ℝ)*(q t)^4/64)+ - Real.exp (-(sourceInitialJ (q t) (N t):ℝ)*(initialOverlapLower (q t))^4/16) := by positivity - unfold sourceInitialError initialErrorCap at he' - linarith only [he',ht] - have HH := actual_initial_oracles hg.K_pos hg.m_large hg.K_le_m (by norm_num : 0<3000) - off hi (sourceInitialOffset_middle _ hm) (sourceInitialOffset_safe _ _ hm) - (sourceInitialAnchor (q t) (N t)) 300 (k t) hk1 (hq t) hg.seed hg.count - hanchor.1 hanchor.2.1 hanchor.2.2.1 hanchor.2.2.2 hg.smoothing_margin - (rfl : sourceInitialWeight (q t) (k t)=_) hρ hc - (Real.rpow_nonneg hNt.le _) (Real.rpow_nonneg hNt.le _) hcap.1 hcap.2 - refine ⟨hg,he,?_,?_⟩ - · simpa only [sourceInitialWord,dite_eq_left hm,sourceInitialP,sourceInitialError,off] using HH.1 - · simpa only [sourceInitialWord,dite_eq_left hm,sourceInitialP,sourceInitialError,sourceInitialPure, - off,sourceInitialOffset] using HH.2 - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -/-- Literal count instantiation; the harmless ceiling is included. -/ -theorem sourceInitialCount_bounds {q N : ℝ} (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) - (H : SourceInitialGeometry q N) : - sourceInitialP q N*sourceInitialPeriodSize N ≤ sourceInitialCount q N ∧ - (sourceInitialCount q N:ℝ) ≤ (sourceOverlapConstant q)^2* - ((sourceInitialP q N*sourceInitialPeriodSize N:ℕ):ℝ) := by - let C := sourceOverlapConstant q - let m := sourceInitialM N - let t := initialSideCount q m - let P := sourceInitialP q N - let ell := sourceInitialPeriodSize N - have hC : 0initialOverlapLower (q t)) 0) - (hE : ∀ᶠt in atTop,0 ≤ E t ∧ E t ≤ (N t)^(-100:ℝ)) : - ∀ᶠt in atTop,Real.sqrt (((sourceInitialCount (q t) (N t)+1:ℕ):ℝ)*((N t)^(-7/5:ℝ)))+ - 2*((sourceInitialCount (q t) (N t)+1:ℕ):ℝ)*E t ≤ 1/16 := by - have hF := (sourceInitialCount_rate hN hq hω).add_const hN (by norm_num) (by norm_num : (0:ℝ) ≤ 1) - have hw := (PowerRate.base hN).rpow (-7/5:ℝ) - have he := (PowerRate.base hN).rpow (-100:ℝ) - have hs := ((hF.mul hw).sqrt.upper hN).tendsto_zero hN (by norm_num) - have ht := (((hF.mul he).const_mul hN (by norm_num : (0:ℝ)<2)).upper hN).tendsto_zero hN (by norm_num) - have hsum := hs.add ht - rw [zero_add] at hsum - have HH := hsum.eventually_le_const (by norm_num : (0:ℝ)<1/16) - filter_upwards [HH,hE] with t ht he - simp only [Nat.cast_add,Nat.cast_one] - simp only [←mul_assoc] at ht - apply le_trans _ ht - apply add_le_add le_rfl - exact mul_le_mul_of_nonneg_left he.2 (by positivity) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open Filter -open scoped Topology Classical - -theorem source_initial_level_eventually {N q n A : ℕ→ℝ} {k : ℕ→ℕ} - (hN : Tendsto N atTop atTop) (hn : Tendsto n atTop atTop) - (hA : ∀ᶠt in atTop,1 ≤ A t) (hq : ∀t,q t ∈ Set.Ioc 0 (1/2:ℝ)) - (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) - (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) - (hmoment : ∀ᶠt in atTop,10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) - (hscale : ∀ᶠt in atTop,N t ≤ n t) : - ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ - (N t) ((n t)^(-100*A t)) (11/5) (initialOverlapLower (q t)) - ((sourceOverlapConstant (q t))^2) 0 (k t)) := by - have hor := source_initial_oracles_eventually hN hn hA hq hΛ hk hk1 hmoment - have hq' (t) : q t ∈ Set.Ioc 0 1 := ⟨(hq t).1,by linarith [(hq t).2]⟩ - have hqr := deletion_rate_zero hN hq' hΛ - have hωr := initialOverlap_rate hN (fun t=>(hq t).1) hΛ - have he : ∀ᶠt in atTop,0 ≤ sourceInitialError (q t) (N t) (k t) ∧ - sourceInitialError (q t) (N t) (k t) ≤ (N t)^(-100:ℝ) := by - filter_upwards [hor,hA,hscale,hN.eventually_gt_atTop 1] with t ht ha hs hNt - obtain ⟨C⟩ := ht.2.2.1 - refine ⟨C.error_nonneg,ht.2.1.trans ?_⟩ - calc - (n t)^(-100*A t) ≤ (n t)^(-100:ℝ) := Real.rpow_le_rpow_of_exponent_le (hNt.le.trans hs) (by linarith) - _ ≤ (N t)^(-100:ℝ) := Real.rpow_le_rpow_of_nonpos (by linarith) hs (by norm_num) - have hsmall := source_initial_overlap_budget_eventually hN hqr hωr he - filter_upwards [hor,hsmall,hk1,hN.eventually_gt_atTop 2,hn.eventually_gt_atTop 0] with t ht hs hk1 hNt hnt - obtain ⟨H,herr,⟨C⟩,⟨U⟩⟩ := ht - have hm : 4 ≤ sourceInitialM (N t) := (by norm_num : 4 ≤ 128).trans H.m_large - have hlen := sourceInitialWord_length (q:=q t) hm (-1) - have hlen' := sourceInitialWord_length (q:=q t) hm 1 - have hh := sourceInitialCount_bounds (hq t) H - have hlower : N t/2 ≤ ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) := by - rw [hlen,Nat.cast_mul]; exact H.length_lower - have hupper : ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) ≤ N t := by - rw [hlen,Nat.cast_mul]; exact H.length_upper - have hell : (1:ℝ) ≤ (sourceInitialWord (q t) (N t) (-1)).length := by linarith only [hNt,hlower] - have hp : 0 < ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) := by linarith only [hell] - refine ⟨C.toConcrete ⟨(hq t).1.le,by linarith [(hq t).2]⟩ - (hlen.trans hlen'.symm) (sourceInitialWord_different H) hlower hupper ?_ (by norm_num) - (by simpa only [hlen] using hh.1) (by simpa only [hlen] using hh.2) ?_⟩ - · simp only [Nat.cast_zero,zero_add,one_mul] - apply (div_le_iff₀ hp).mpr - exact herr.trans (le_mul_of_one_le_right (Real.rpow_nonneg hnt.le _) hell) - · exact source_initial_power_overlap (hq t) H (by linarith) hk1 C U hs - -/-- All backwards targets are no larger than n, with the source epsilon. -/ -theorem sourceScaleProduct_le_one (B D i : ℕ) (hB : 2 ≤ B) : sourceScaleProduct B D i ≤ 1 := by - apply Finset.prod_le_one₀ - · intro j _ - have hdim : sourceDimension B j ≤ B := by unfold sourceDimension; split_ifs <;> omega - have he := sourceEpsilon_pos B D - have hh := sourceEpsilon_small B D - have hp : (1:ℝ) ≤ 2^B := one_le_pow₀ (by norm_num) - have hd : 0 ≤ (D:ℝ) := Nat.cast_nonneg _ - have hu : (2:ℝ)^B*sourceEpsilon B D ≤ 1/2 := by - nlinarith only [hh,mul_nonneg hd (mul_nonneg (le_trans zero_le_one hp) he.le)] - have hx := scaleA_zero_lower (sourceDimension B j) B (sourceEpsilon B D) hdim he.le - apply le_trans _ hx - exact mul_nonneg (by positivity) (by nlinarith only [hu,he]) - · intro j _ - have he := sourceEpsilon_pos B D - have hp : (1:ℝ) ≤ 2^(sourceDimension B j) := one_le_pow₀ (by norm_num) - unfold scaleA - norm_num only [pow_zero,mul_one] - have hh := (div_le_iff₀ (by positivity : (0:ℝ)<2^(sourceDimension B j))).mpr - (show 1+sourceEpsilon B D ≤ (1+sourceEpsilon B D)*2^(sourceDimension B j) from - le_mul_of_one_le_right (by linarith only [he]) hp) - linarith only [hh] - -theorem sourceTargetScale_le (B D i : ℕ) (n : ℝ) (hB : 2 ≤ B) (hn : 1 ≤ n) : - sourceTargetScale B D n i ≤ n := by - simpa only [sourceTargetScale,Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hn (sourceScaleProduct_le_one B D i hB) - -theorem sourceHalfMoment_sufficient (B D i : ℕ) {n : ℝ} (hB : 2 ≤ B) (hn : 1 < n) : - 10^6*(totalScoreExponent B D+B+1)*Real.log n ≤ - (sourceHalfMoment B D n i:ℝ)*Real.log (sourceTargetScale B D n i) := by - have hlo := sourceScaleProduct_lower B D i hB - have hs : 0 < sourceScaleProduct B D i := lt_of_lt_of_le (by positivity) hlo - have hl : 0 < Real.log (sourceTargetScale B D n i) := by - rw [sourceTargetScale,Real.log_rpow (by linarith : 0(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ - (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) 0) - ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) - (11/5) (initialOverlapLower (q t)) ((sourceOverlapConstant (q t))^2) 0 - (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) 0)) := by - let H := fun t=>(q t)^3*Real.log (n t) - let Λ := fun t=>(q t)^(-3:ℤ) - have hΛ (t) : 1 ≤ Λ t := by - dsimp [Λ] - rw [zpow_neg,zpow_ofNat,one_le_inv₀ (pow_pos (hq t).1 _)] - exact pow_le_one₀ (hq t).1.le (by linarith [(hq t).2]) - have hrel (t) : Real.log (n t)=Λ t*H t := by - dsimp [Λ,H] - rw [zpow_neg,zpow_ofNat] - field_simp [(hq t).1.ne'] - let D := fun t=>sourceDepth B ζ (H t) - let N := fun t=>sourceTargetScale B (D t) (n t) 0 - have hN := sourceTargetScale_tendsto B ζ hB hζ (fun _=>0) hn hH hΛ hrel - have hl := source_uniform_log_absorption B 0 ζ hB hζ (fun _=>0) hn hH hΛ hrel - simp only [pow_zero,one_mul] at hl - have hk := sourceHalfMoment_rate B ζ hB hζ (fun _=>0) hn hH hΛ hrel - apply source_initial_level_eventually hN hn _ hq hl hk - · filter_upwards [hn.eventually_gt_atTop 1] with t ht - exact (sourceHalfMoment_bounds B (D t) 0 hB ht).1 - · filter_upwards [hn.eventually_gt_atTop 1] with t ht - exact sourceHalfMoment_sufficient B (D t) 0 hB ht - · filter_upwards [hn.eventually_ge_atTop 1] with t ht - exact sourceTargetScale_le B (D t) 0 (n t) hB ht - · filter_upwards [] with t - have hd := (totalScoreExponent_bounds B (D t) hB).1 - have hbn : (0:ℝ) ≤ B := Nat.cast_nonneg _ - linarith only [hd,hbn] - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.InitialOracle +import OAI.Probability.TraceReconstruction.Amplification + +namespace OAI + +/-! +# InitialRates + +Initial geometric parameters, moment depths, error and overlap rates, and production of the base induction pair. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +variable {N q ω w : ℕ → ℝ} {J u m : ℕ → ℕ} + +/-- Exact power of the sharp initial rank prefactor; all channel losses are + subpower at the source's smallest scale. -/ +theorem initialPrefactor_rate (hN : Tendsto N atTop atTop) + {α β : ℝ} (hu : PowerRate N (fun t=>(u t:ℝ)) α) + (hm : PowerRate N (fun t=>(m t:ℝ)) β) (hq : PowerRate N q 0) (r d : ℕ) : + PowerRate N (fun t=>initialPrefactorCap (u t) (m t) r d (q t)) + (α/2-β*((d:ℝ)+(r:ℝ)/2)) := by + have hd : PowerRate N (fun t=>initialDifferenceCap d (q t)) 0 := by + have H := ((PowerRate.const hN (by positivity : (0:ℝ)<8*((d:ℝ)+1))).div (hq.pow 2)).sqrt.const_mul hN (by norm_num : (0:ℝ)<2) + simpa only [initialDifferenceCap,zero_mul,zero_sub,neg_zero,zero_div] using H + have hnum := (((hu.mul hm).const_mul hN (by norm_num : (0:ℝ)<144)).mul_const hN + (by positivity : (0:ℝ)<(2:ℝ)^(2*r))).mul (hd.pow (2*d+r+2)) + have hden := ((hm.div_const hN (by norm_num : (0:ℝ)<4)).pow d).mul + (((hu.mul hm).div_const hN (by positivity : (0:ℝ)<2*(r+1:ℝ))).sqrt) + have H := hnum.div (hden.mul ((hm.div_const hN (by norm_num : (0:ℝ)<4)).sqrt.pow (r+1))) + convert H using 1 + · ext t; simp only [initialPrefactorCap,Nat.cast_mul] + · push_cast; ring + +theorem periodCentral_rate (hN : Tendsto N atTop atTop) {α : ℝ} + (hu : PowerRate N (fun t=>(u t:ℝ)) α) {r : ℕ} (hr : 0periodCentralSumConstant (u t) r) (α*((r:ℝ)-3)/2) := by + have H := ((hu.div_const hN (by positivity : (0:ℝ)<3*(r+1:ℝ))).inv hN).const_mul hN + (by positivity : (0:ℝ)<((r+1:ℕ):ℝ)^2) + have H' := H.mul (((hu.const_mul hN (by norm_num : (0:ℝ)<2)).sqrt.const_mul hN + (by norm_num : (0:ℝ)<2)).pow (r-1)) + convert H' using 1 + · ext t; simp only [periodCentralSumConstant,Nat.cast_mul,Nat.cast_ofNat] + · rw [Nat.cast_sub (by omega : 1≤r)]; norm_num; ring + +theorem periodBounded_rate (hN : Tendsto N atTop atTop) {α : ℝ} + (hu : PowerRate N (fun t=>(u t:ℝ)) α) {r : ℕ} (hr : 2≤r) (M : ℕ) : + PowerRate N (fun t=>periodBoundedSumConstant (u t) r M) (α*((r:ℝ)-4)/2) := by + have H := (((hu.div_const hN (by positivity : (0:ℝ)<3*(r+1:ℝ))).inv hN).const_mul hN + (by positivity : (0:ℝ)<((r+1:ℕ):ℝ)^2)).mul_const hN (by positivity : (0:ℝ)<(M:ℝ)+1) + have H' := H.mul (((hu.const_mul hN (by norm_num : (0:ℝ)<2)).sqrt.const_mul hN + (by norm_num : (0:ℝ)<2)).pow (r-2)) + convert H' using 1 + · ext t; simp only [periodBoundedSumConstant,Nat.cast_mul,Nat.cast_ofNat] + · rw [Nat.cast_sub hr]; norm_num; ring + +theorem hiddenSigned_rate (hN : Tendsto N atTop atTop) {γ : ℝ} (hγ : 0<γ) + (hJ : PowerRate N (fun t=>(J t:ℝ)) γ) (hω : PowerRate N ω 0) (s : ℕ) : + PowerRate N (fun t=>hiddenSignedL2Bound (J t) s (ω t)) (-γ*((s:ℝ)+1/2)) := by + have hden := (hJ.mul (hω.pow 2)).add_const hN (by simpa using hγ) (by norm_num : (0:ℝ)≤2) + have hroot := ((PowerRate.const hN (by positivity : (0:ℝ)<4*((s:ℝ)+1))).div hden).sqrt + have hp := ((hroot.const_mul hN (by norm_num : (0:ℝ)<2)).pow s).pow 2 + have H := (hp.const_mul hN (by positivity : (0:ℝ)<((2:ℝ)^(s*s))^2)).mul hroot + convert H using 1 + · rfl + · push_cast; ring + +theorem hiddenUnsigned_rate (hN : Tendsto N atTop atTop) {γ : ℝ} (hγ : 0<γ) + (hJ : PowerRate N (fun t=>(J t:ℝ)) γ) (hω : PowerRate N ω 0) (s : ℕ) : + PowerRate N (fun t=>hiddenUnsignedL2Bound (J t) s (ω t)) (-γ/2) := by + have hden := (hJ.mul (hω.pow 2)).add_const hN (by simpa using hγ) (by norm_num : (0:ℝ)≤2) + have H := (((PowerRate.const hN (by norm_num : (0:ℝ)<4)).div hden).sqrt).const_mul hN + (by positivity : (0:ℝ)<((2:ℝ)^s)^2) + convert H using 1 + · rfl + · ring + +/-- The two eliminated large gaps are quantitatively visible in this exponent. -/ +theorem initial_central_rate (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + {r : ℕ} (hr : 0initialPrefactorCap (u t) (m t) r d (q t)*periodCentralSumConstant (u t) r) + (-123/250-(62/125)*(d:ℝ)-(1/500)*(r:ℝ)) := by + convert (initialPrefactor_rate hN hu hm hq r d).mul (periodCentral_rate hN hu hr) using 1; ring + +theorem initial_bounded_rate (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + {r : ℕ} (hr : 2≤r) (d M : ℕ) : + PowerRate N (fun t=>initialPrefactorCap (u t) (m t) r d (q t)*periodBoundedSumConstant (u t) r M) + (-369/500-(62/125)*(d:ℝ)-(1/500)*(r:ℝ)) := by + convert (initialPrefactor_rate hN hu hm hq r d).mul (periodBounded_rate hN hu hr M) using 1; ring + +/-- Fixed low degrees already beat the signed and pure source score exponents. -/ +theorem initial_signed_pattern_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) + {r : ℕ} (hr : 0initialSignedPatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-223/100) := by + by_cases hlin : ∃a,k=linearPattern a + · have H := (initial_central_rate hN hu hm hq hr 1).mul + (hiddenSigned_rate hN (by norm_num) hJ hω 300) + have hb : -123/250-(62/125)*(1:ℝ)-(1/500)*(r:ℝ)+(-(1/125)*((300:ℝ)+1/2)) ≤ -223/100 := by + have hh : (0:ℝ)≤r := Nat.cast_nonneg r + linarith + simpa only [initialSignedPatternCap,ite_eq_left hlin] using (H.upper hN).mono (by simpa using hb) + · have hd : 3≤∑h,(k h).order := odd_nonlinear_order k hk hlin + obtain ⟨a,b,hab,_,_⟩ := odd_pattern_pair k hk hlin + have hr2 : 2≤r := by have := a.isLt; have := b.isLt; have := hab; omega + have H := (initial_bounded_rate hN hu hm hq hr2 (∑h,(k h).order) (2*(2^300))).mul + (hiddenUnsigned_rate hN (by norm_num) hJ hω 300) + have hb : -369/500-(62/125)*(∑h,(k h).order:ℕ)-(1/500)*(r:ℝ)+(-(1/125)/2) ≤ -223/100 := by + have hd' : (3:ℝ)≤(∑h,(k h).order:ℕ) := by exact_mod_cast hd + have hr' : (2:ℝ)≤r := by exact_mod_cast hr2 + linarith + simpa only [initialSignedPatternCap,ite_eq_right hlin] using (H.upper hN).mono (by simpa using hb) + +theorem initial_pure_pattern_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) + {r : ℕ} (hr : 0initialPurePatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-37/25) := by + by_cases hlin : ∃a,k=linearPattern a + · have H := (initial_central_rate hN hu hm hq hr 1).mul + (hiddenSigned_rate hN (by norm_num) hJ hω 300) + have hb : -123/250-(62/125)*(1:ℝ)-(1/500)*(r:ℝ)+(-(1/125)*((300:ℝ)+1/2)) ≤ -37/25 := by + have hh : (0:ℝ)≤r := Nat.cast_nonneg r + linarith + simpa only [initialPurePatternCap,ite_eq_left hlin] using (H.upper hN).mono (by simpa using hb) + · have hd := (nonconstant_pattern_linear_or_order_two k hk).resolve_left hlin + have H := (initial_central_rate hN hu hm hq hr (∑h,(k h).order)).mul + (hiddenUnsigned_rate hN (by norm_num) hJ hω 300) + have hb : -123/250-(62/125)*(∑h,(k h).order:ℕ)-(1/500)*(r:ℝ)+(-(1/125)/2) ≤ -37/25 := by + have hd' : (2:ℝ)≤(∑h,(k h).order:ℕ) := by exact_mod_cast hd + have hr' : (0:ℝ)≤r := Nat.cast_nonneg r + linarith + simpa only [initialPurePatternCap,ite_eq_right hlin] using (H.upper hN).mono (by simpa using hb) + +theorem increasingTuple_card_le (u r : ℕ) : Fintype.card (IncreasingTuple u r) ≤ u^r := by + simpa only [Fintype.card_fun,Fintype.card_fin] using + Fintype.card_subtype_le (fun v : Fin r→Fin u => StrictMono v) + +theorem initialRankTail_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (r : ℕ) (a : ℝ) : + PowerUpper N (fun t=>initialRankTailCap (u t) (m t) r) a := by + have hcard : PowerUpper N (fun t=>(Fintype.card (IncreasingTuple (u t) r):ℝ)) ((123/250)*(r:ℝ)) := by + apply (hu.pow r).upper hN |>.of_abs_le + exact Eventually.of_forall fun t=>by + rw [abs_of_nonneg (Nat.cast_nonneg _),abs_of_nonneg (by positivity)] + exact_mod_cast increasingTuple_card_le (u t) r + have hpoly := hcard.mul hN (((hu.mul hm).sqrt.const_mul hN + (by positivity : (0:ℝ)<48*((r+1:ℕ):ℝ))).upper hN) + have hexpr : PowerRate N (fun t=>(m t:ℝ)/(1024*(u t:ℝ))) (1/250) := by + convert hm.div (hu.const_mul hN (by norm_num : (0:ℝ)<1024)) using 1; norm_num + have hexp := hexpr.exp_neg_upper hN (by norm_num) (a/2-((123/250)*(r:ℝ)+(123/250+62/125)/2)) + have H := ((PowerRate.const hN (by norm_num : (0:ℝ)<2)).upper hN).mul hN + ((hpoly.mul hN hexp).pow hN 2) + convert H using 1 + · ext t + simp only [initialRankTailCap,Nat.cast_mul,neg_div] + ring + · push_cast; ring + +theorem initialMomentRatio_rate (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hw : PowerRate N w 0) : + PowerRate N (fun t=>initialMomentRatio (u t) (m t) (q t) (w t)) (-1/500) := by + have H := ((hw.pow 2).mul ((PowerRate.const hN + (by positivity [rankSchurConstant_pos] : (0:ℝ)<3*rankSchurConstant)).div hq)).mul (hu.div hm).sqrt + convert H using 1 + · rfl + · norm_num + +theorem initial_fixed_high_tail_rate (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hw : PowerRate N w 0) : + PowerRate N (fun t=>4*(initialMomentRatio (u t) (m t) (q t) (w t))^3000/ + (1-initialMomentRatio (u t) (m t) (q t) (w t))) (-6) := by + have hρ := initialMomentRatio_rate hN hu hm hq hw + have hz := (hρ.upper hN).tendsto_zero hN (by norm_num) + have hden : PowerRate N (fun t=>1-initialMomentRatio (u t) (m t) (q t) (w t)) 0 := by + apply PowerRate.of_tendsto hN (by norm_num : (0:ℝ)<1) + simpa using tendsto_const_nhds.sub hz + convert ((hρ.pow 3000).const_mul hN (by norm_num : (0:ℝ)<4)).div hden using 1 + norm_num + +theorem initialSignedDegree_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (r : ℕ) : + PowerUpper N (fun t=>initialSignedDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-223/100) := by + by_cases hr : r=0 + · simpa only [initialSignedDegreeCap,ite_eq_left hr] using PowerUpper.zero hN (-223/100) + have hs : PowerUpper N (fun t=>∑k : Fin r→GapDifference, + if Odd (firstDifferenceCount k) then initialSignedPatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k else 0) (-223/100) := by + apply PowerUpper.sum hN Finset.univ + intro k _ + by_cases hk : Odd (firstDifferenceCount k) + · simpa only [ite_eq_left hk] using initial_signed_pattern_upper hN hu hm hq hJ hω (by omega) k hk + · simpa only [ite_eq_right hk] using PowerUpper.zero hN (-223/100) + have hc : (0:ℝ)<8*(Fintype.card (Fin r→GapDifference):ℝ) := by + have hp : 0.unchanged⟩ + positivity + have H := (((PowerRate.const hN hc).upper hN).mul hN hs) + simp only [zero_add] at H + simpa only [initialSignedDegreeCap,ite_eq_right hr] using H.add hN (initialRankTail_upper hN hu hm r (-223/100)) + +theorem initialPureDegree_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (r : ℕ) : + PowerUpper N (fun t=>initialPureDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-37/25) := by + by_cases hr : r=0 + · simpa only [initialPureDegreeCap,ite_eq_left hr] using PowerUpper.zero hN (-37/25) + have hs : PowerUpper N (fun t=>∑k : Fin r→GapDifference, + if k=unchangedPattern r then 0 else initialPurePatternCap (J t) (u t) (m t) r 300 (q t) (ω t) k) (-37/25) := by + apply PowerUpper.sum hN Finset.univ + intro k _ + by_cases hk : k=unchangedPattern r + · simpa only [ite_eq_left hk] using PowerUpper.zero hN (-37/25) + · simpa only [ite_eq_right hk] using initial_pure_pattern_upper hN hu hm hq hJ hω (by omega) k hk + have hc : (0:ℝ)<2*(Fintype.card (Fin r→GapDifference):ℝ) := by + have hp : 0.unchanged⟩ + positivity + have H := (((PowerRate.const hN hc).upper hN).mul hN hs) + simp only [zero_add] at H + simpa only [initialPureDegreeCap,ite_eq_right hr] using H.add hN (initialRankTail_upper hN hu hm r (-37/25)) + +theorem initialSignedCap_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : + PowerUpper N (fun t=>initialSignedCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t)) (-223/100) := by + have hs : PowerUpper N (fun t=>∑r∈Finset.range 3000,(w t)^(2*r)* + initialSignedDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-223/100) := by + apply PowerUpper.sum hN (Finset.range 3000) + intro r _ + simpa only [zero_mul,zero_add] using ((hw.pow (2*r)).upper hN).mul hN (initialSignedDegree_upper hN hu hm hq hJ hω r) + exact hs.add hN ((initial_fixed_high_tail_rate hN hu hm hq hw).upper hN |>.mono (by norm_num)) + +theorem initialPureCap_upper (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : + PowerUpper N (fun t=>initialPureCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t)) (-37/25) := by + have hs : PowerUpper N (fun t=>∑r∈Finset.range 3000,(w t)^(2*r)* + initialPureDegreeCap (J t) (u t) (m t) r 300 (q t) (ω t)) (-37/25) := by + apply PowerUpper.sum hN (Finset.range 3000) + intro r _ + simpa only [zero_mul,zero_add] using ((hw.pow (2*r)).upper hN).mul hN (initialPureDegree_upper hN hu hm hq hJ hω r) + exact hs.add hN ((initial_fixed_high_tail_rate hN hu hm hq hw).upper hN |>.mono (by norm_num)) + +/-- Actual scalar budgets, not assumed coefficient bounds: all report- and + count-independent caps are strictly below the source clipping allowances. -/ +theorem initial_score_caps_eventually (hN : Tendsto N atTop atTop) + (hu : PowerRate N (fun t=>(u t:ℝ)) (123/250)) + (hm : PowerRate N (fun t=>(m t:ℝ)) (62/125)) (hq : PowerRate N q 0) + (hJ : PowerRate N (fun t=>(J t:ℝ)) (1/125)) (hω : PowerRate N ω 0) (hw : PowerRate N w 0) : + ∀ᶠt in atTop, + 64*initialSignedCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t) ≤ (N t)^(-11/5:ℝ) ∧ + 64*initialPureCap (J t) (u t) (m t) 3000 300 (q t) (ω t) (w t) ≤ (N t)^(-7/5:ℝ) := by + have hc := (PowerRate.const hN (by norm_num : (0:ℝ)<64)).upper hN + have hs := hc.mul hN (initialSignedCap_upper hN hu hm hq hJ hω hw) + have hp := hc.mul hN (initialPureCap_upper hN hu hm hq hJ hω hw) + filter_upwards [hs (-11/5) (by norm_num),hp (-7/5) (by norm_num)] with t hs hp + exact ⟨(le_abs_self _).trans hs,(le_abs_self _).trans hp⟩ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +variable {N f g : ℕ→ℝ} {α β : ℝ} + +theorem PowerRate.sub_lower (hN : Tendsto N atTop atTop) + (hf : PowerRate N f α) (hg : PowerRate N g β) (hβα : β<α) : + PowerRate N (fun t=>f t-g t) α := by + have hz := ((hg.div hf).upper hN).tendsto_zero hN (sub_neg.mpr hβα) + apply hf.of_ratio hN (by norm_num : (0:ℝ)<1) + have H : Tendsto (fun t=>1-g t/f t) atTop (𝓝 1) := by + simpa using tendsto_const_nhds.sub hz + apply H.congr' + filter_upwards [hf.1] with t ht + field_simp [ht.ne'] + +theorem PowerRate.nat_sub_lower (hN : Tendsto N atTop atTop) {f g : ℕ→ℕ} + (hf : PowerRate N (fun t=>(f t:ℝ)) α) + (hg : PowerRate N (fun t=>(g t:ℝ)) β) (hβα : β<α) : + PowerRate N (fun t=>(f t-g t:ℕ)) α := by + have H := hf.sub_lower hN hg hβα + apply H.congr + filter_upwards [H.1] with t ht + have hg : g t≤f t := by exact_mod_cast (sub_pos.mp ht).le + rw [Nat.cast_sub hg] + +/-- Literal integer choices of the initial-pair construction, including the outer floors. -/ +def sourceInitialM (N : ℝ) : ℕ := ⌊N^(62/125:ℝ)⌋₊ +def sourceInitialK (N : ℝ) : ℕ := ⌊N^(123/250:ℝ)⌋₊ +def sourceInitialPeriodSize (N : ℝ) : ℕ := 2*sourceInitialM N-1 +def sourceInitialCapacity (N : ℝ) : ℕ := ⌊N/(sourceInitialPeriodSize N:ℝ)⌋₊ +def sourceInitialJ (q N : ℝ) : ℕ := + ⌊((sourceInitialCapacity N:ℝ)-sourceInitialK N)/ + (2*(initialSideCount q (sourceInitialM N):ℝ)+1)⌋₊ +def sourceInitialP (q N : ℝ) : ℕ := + sourceInitialJ q N*(2*initialSideCount q (sourceInitialM N)+1)+sourceInitialK N +/-- One-based manuscript anchors translated once to zero-based list indices. -/ +def sourceInitialAnchor (q N : ℝ) : ℤ := ((sourceInitialP q N/2:ℕ):ℤ)-1 + +theorem sourceInitialM_rate (hN : Tendsto N atTop atTop) : + PowerRate N (fun t=>(sourceInitialM (N t):ℝ)) (62/125) := by + have H := ((PowerRate.base hN).rpow (62/125)).nat_floor hN (by norm_num) + simpa only [sourceInitialM,one_mul] using H + +theorem sourceInitialK_rate (hN : Tendsto N atTop atTop) : + PowerRate N (fun t=>(sourceInitialK (N t):ℝ)) (123/250) := by + have H := ((PowerRate.base hN).rpow (123/250)).nat_floor hN (by norm_num) + simpa only [sourceInitialK,one_mul] using H + +theorem sourceInitialPeriodSize_rate (hN : Tendsto N atTop atTop) : + PowerRate N (fun t=>(sourceInitialPeriodSize (N t):ℝ)) (62/125) := by + have hh : PowerRate N (fun t=>(2*sourceInitialM (N t):ℕ)) (62/125) := by + simpa only [Nat.cast_mul,Nat.cast_ofNat] using (sourceInitialM_rate hN).const_mul hN (by norm_num : (0:ℝ)<2) + exact hh.nat_sub_lower hN (PowerRate.const hN (by norm_num : (0:ℝ)<(1:ℕ))) (by norm_num) + +theorem sourceInitialCapacity_rate (hN : Tendsto N atTop atTop) : + PowerRate N (fun t=>(sourceInitialCapacity (N t):ℝ)) (63/125) := by + have H := ((PowerRate.base hN).div (sourceInitialPeriodSize_rate hN)).nat_floor hN (by norm_num) + convert H using 1 + · rfl + · norm_num + +theorem sourceInitialSide_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} + (hq : PowerRate N q 0) : + PowerRate N (fun t=>(initialSideCount (q t) (sourceInitialM (N t)):ℝ)) (62/125) := by + have H := (hq.mul (sourceInitialM_rate hN)).nat_floor hN (by norm_num) + simpa only [initialSideCount,zero_add] using H + +theorem sourceInitialJ_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} + (hq : PowerRate N q 0) : + PowerRate N (fun t=>(sourceInitialJ (q t) (N t):ℝ)) (1/125) := by + have hn := (sourceInitialCapacity_rate hN).sub_lower hN (sourceInitialK_rate hN) (by norm_num) + have hd := ((sourceInitialSide_rate hN hq).const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN + (by norm_num) (by norm_num : (0:ℝ)≤1) + have H := (hn.div hd).nat_floor hN (by norm_num) + convert H using 1 + · rfl + · norm_num + +theorem initialOverlap_rate (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} + (_hq : ∀t,0(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : + PowerRate N (fun t=>initialOverlapLower (q t)) 0 := by + refine ⟨Eventually.of_forall (fun t=>initialOverlapLower_pos _),?_⟩ + have H := (hΛ.const_mul (-(32+3*primitivePeriodConstant))).sub + ((Real.tendsto_log_atTop.comp hN).const_div_atTop (Real.log 1536)) + simp only [mul_zero,sub_zero] at H + apply H.congr' + filter_upwards [] with t + rw [initialOverlapLower,Real.log_div (Real.exp_pos _).ne' (by norm_num),Real.log_exp] + simp only [zpow_neg,zpow_ofNat,Function.comp_apply] + ring + +theorem deletion_rate_zero (hN : Tendsto N atTop atTop) {q : ℕ→ℝ} + (hq : ∀t,q t∈Set.Ioc 0 1) + (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : + PowerRate N q 0 := by + refine ⟨Eventually.of_forall (fun t=>(hq t).1),?_⟩ + apply squeeze_zero_norm' _ hΛ + filter_upwards [hN.eventually_gt_atTop 1] with t hNt + have hp := (hq t).1 + have hle := (hq t).2 + have hqinv : 1≤(q t)⁻¹ := (one_le_inv₀ hp).mpr hle + have hlog : |Real.log (q t)| ≤ (q t)^(-3:ℤ) := by + rw [abs_of_nonpos (Real.log_nonpos hp.le hle),←Real.log_inv, zpow_neg,zpow_ofNat] + have hh := Real.log_le_sub_one_of_pos (inv_pos.mpr hp) + have hcube : (q t)⁻¹ ≤ ((q t)⁻¹)^3 := by nlinarith [sq_nonneg ((q t)⁻¹-1)] + rw [←inv_pow] + linarith + rw [Real.norm_eq_abs,abs_div,abs_of_pos (Real.log_pos hNt)] + exact div_le_div_of_nonneg_right hlog (Real.log_pos hNt).le + +/-- Mechanical realization of the base scalar score budgets from the actual + integer choices and the unchanged known channel. -/ +theorem source_initial_score_caps {q w : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hq : ∀t,q t∈Set.Ioc 0 1) + (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) + (hw : PowerRate N w 0) : + ∀ᶠt in atTop, + 64*initialSignedCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) + (sourceInitialM (N t)) 3000 300 (q t) (initialOverlapLower (q t)) (w t) ≤ (N t)^(-11/5:ℝ) ∧ + 64*initialPureCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) + (sourceInitialM (N t)) 3000 300 (q t) (initialOverlapLower (q t)) (w t) ≤ (N t)^(-7/5:ℝ) := by + exact initial_score_caps_eventually hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) + (deletion_rate_zero hN hq hΛ) (sourceInitialJ_rate hN (deletion_rate_zero hN hq hΛ)) + (initialOverlap_rate hN (fun t=>(hq t).1) hΛ) hw + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- The manuscript's one-based middle defect, translated to a list index. -/ +def sourceInitialOffset (m : ℕ) (hm : 4 ≤ m) : Fin m := + ⟨m/2-1,by omega⟩ + +theorem sourceInitialOffset_interior (m : ℕ) (hm : 4 ≤ m) : + 1 ≤ (sourceInitialOffset m hm).val ∧ (sourceInitialOffset m hm).val+1 < m := by + simp only [sourceInitialOffset]; omega + +theorem sourceInitialOffset_middle (m : ℕ) (hm : 4 ≤ m) : + |((sourceInitialOffset m hm).val:ℝ)-(m:ℝ)/2| ≤ 2 := by + have h1 : 2*(m/2) ≤ m := Nat.mul_div_le m 2 + have h2 : m<2*(m/2+1) := by omega + have h3 : 1 ≤ m/2 := by omega + simp only [sourceInitialOffset,Nat.cast_sub h3,Nat.cast_one] + rw [abs_le] + have hh1 : (2:ℝ)*(m/2:ℕ) ≤ m := by exact_mod_cast h1 + have hh2 : (m:ℝ)<2*((m/2:ℕ)+1) := by exact_mod_cast h2 + constructor <;> linarith + +theorem sourceInitialOffset_safe (u m : ℕ) (hm : 4 ≤ m) : + SafeTaggedTuple (periodSlot (u:=u) (fun _=>sourceInitialOffset m hm)) := by + have hi := sourceInitialOffset_interior m hm + exact constant_period_safe _ hi.1 hi.2 (by omega) id strictMono_id + +/-- A literal arithmetic margin implies every base window placement condition. -/ +theorem initial_anchor_geometry (J K t s : ℕ) (hK : 12*(J+2^s+1) ≤ K) : + let a : ℤ := (((J*(2*t+1)+K)/2:ℕ):ℤ)-1 + (J*t+J:ℕ) ≤ a ∧ a+(2^s:ℕ) ≤ (J*t+K:ℕ) ∧ + (K:ℝ)/3 ≤ 2*((a-(J*t:ℕ):ℤ)-J)+1 ∧ + (K:ℝ)/3 ≤ 2*K-(2*((a-(J*t:ℕ):ℤ)+(2:ℝ)^s)+1) := by + have he : (J*(2*t+1)+K)/2=J*t+(J+K)/2 := by + rw [show J*(2*t+1)+K=2*(J*t)+(J+K) by ring,Nat.mul_add_div (by norm_num)] + have hlo : 2*((J+K)/2) ≤ J+K := Nat.mul_div_le _ 2 + have hhi : J+K<2*((J+K)/2+1) := by omega + have hK1 : 12*(J+1) ≤ K := by nlinarith [Nat.zero_le (2^s)] + dsimp only + rw [he] + have hi1 : J+1 ≤ (J+K)/2 := by omega + have hi2 : (J+K)/2+(2^s:ℕ) ≤ K+1 := by omega + constructor + · apply (le_sub_iff_add_le).mpr + exact_mod_cast (show J*t+J+1 ≤ J*t+(J+K)/2 from by omega) + constructor + · push_cast only [Nat.cast_add] + omega + have hl : (2:ℝ)*((J+K)/2:ℕ) ≤ J+K := by exact_mod_cast hlo + have hh : (J:ℝ)+K<2*(((J+K)/2:ℕ)+1) := by exact_mod_cast hhi + have hk : (12:ℝ)*((J:ℝ)+(2:ℝ)^s+1) ≤ K := by exact_mod_cast hK + simp only [Nat.cast_add,Int.cast_sub,Int.cast_add,Int.cast_natCast,Int.cast_one,Int.cast_mul,Nat.cast_mul] + constructor <;> nlinarith [show (0:ℝ) ≤ (2:ℝ)^s by positivity] + +theorem prouhetSeries_coeff_zero (s : ℕ) : (prouhetSeries s).coeff 0=1 := by + induction s with + | zero => simp [prouhetSeries] + | succ s ih => + have hp : (0:ℤ)<(2^s:ℕ) := by positivity + rw [prouhetSeries_succ_coeff,ih,(prouhetSeries_coeff_spec s).1 _ (Or.inl (by omega)),sub_zero] + +/-- Literal source initial words really are different, not only their formal templates. -/ +theorem motifPeriodWord_ne {m : ℕ} (off : Fin m) (hi : 1 ≤ off.val ∧ off.val+1 < m) + (u s : ℕ) (a : ℤ) (ha : 0 ≤ a) (hau : a((f ⟨a.toNat,hj⟩):Fin m).val) H + have ha' : (a.toNat:ℤ)=a := Int.toNat_of_nonneg ha + simp only [motifOffset,ha',sub_self,prouhetSeries_coeff_zero] at h + have hpos : (0:ℤ)<(2^s:ℕ) := by positivity + norm_num [motifIndicator,hpos,motifShift] at h + +/-- Floors in the initial construction waste no more than one long slot. -/ +theorem initial_period_count_bounds {N : ℝ} {m K t : ℕ} + (hL : 0<2*m-1) (hN : 0 ≤ N) (hK : (K:ℝ) ≤ ⌊N/(2*m-1:ℕ)⌋₊) : + let F : ℕ := ⌊N/(2*m-1:ℕ)⌋₊ + let J : ℕ := ⌊((F:ℝ)-K)/(2*t+1:ℕ)⌋₊ + let P : ℕ := J*(2*t+1)+K + (P:ℝ)*(2*m-1:ℕ) ≤ N ∧ N<((P:ℝ)+(2*t+1:ℕ)+1)*(2*m-1:ℕ) := by + dsimp only + set F : ℕ := ⌊N/(2*m-1:ℕ)⌋₊ + set J : ℕ := ⌊((F:ℝ)-K)/(2*t+1:ℕ)⌋₊ + have hd : (0:ℝ)<(2*t+1:ℕ) := by positivity + have hl : (0:ℝ)<(2*m-1:ℕ) := by exact_mod_cast hL + have hjlo := Nat.floor_le (div_nonneg (sub_nonneg.mpr hK) hd.le) + have hjhi := Nat.lt_floor_add_one (((F:ℝ)-K)/(2*t+1:ℕ)) + change (J:ℝ) ≤ _ at hjlo + change _<(J:ℝ)+1 at hjhi + have hflo := Nat.floor_le (div_nonneg hN hl.le) + have hfhi := Nat.lt_floor_add_one (N/(2*m-1:ℕ)) + change (F:ℝ) ≤ _ at hflo + change _<(F:ℝ)+1 at hfhi + have hp : (J:ℝ)*(2*t+1:ℕ)+K ≤ F := by + have H := (le_div_iff₀ hd).mp hjlo + linarith + have hp' : (F:ℝ)<(J:ℝ)*(2*t+1:ℕ)+K+(2*t+1:ℕ) := by + have H := (div_lt_iff₀ hd).mp hjhi + nlinarith + constructor + · push_cast + simpa only [Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] using + (mul_le_mul_of_nonneg_right hp hl.le).trans ((le_div_iff₀ hl).mp hflo) + · have H := (div_lt_iff₀ hl).mp hfhi + push_cast at hp' ⊢ + nlinarith + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- Source moment order is twice this integer. -/ +def sourceHalfMoment (B D : ℕ) (n : ℝ) (i : ℕ) : ℕ := + ⌈(10^8:ℝ)*2^(10*B)*(totalScoreExponent B D+B+1)*Real.log n/ + Real.log (sourceTargetScale B D n i)⌉₊ + +theorem sourceEpsilon_le_one (B D : ℕ) : sourceEpsilon B D ≤ 1 := by + unfold sourceEpsilon + apply (div_le_one (by positivity)).mpr + have H : (1:ℝ) ≤ 2^(4*B+100) := one_le_pow₀ (by norm_num) + nlinarith [show (0:ℝ) ≤ D by positivity] + +theorem sourceTargetScale_tendsto (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) + {n Λ H : ℕ→ℝ} (i : ℕ→ℕ) (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) + (hΛ : ∀t,1 ≤ Λ t) (hrel : ∀t,Real.log (n t)=Λ t*H t) : + Tendsto (fun t=>sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t)) atTop atTop := by + have hlog : Tendsto (fun t=>Real.log (sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t))) atTop atTop := by + apply tendsto_atTop_mono' atTop _ (((tendsto_rpow_atTop hζ.1).comp hH).atTop_div_const (by norm_num : (0:ℝ)<2)) + filter_upwards [hH.eventually_ge_atTop 1,hn.eventually_gt_atTop 1] with t ht hnt + have hl := sourceTargetScale_log_lower B ζ (H t) (n t) (i t) hB hζ.2.le ht hnt + have he : Real.log (n t)/(2*(H t)^(1-ζ))=Λ t*(H t)^ζ/2 := by + rw [hrel t,Real.rpow_sub (by linarith : 0((sourceDepth B ζ (H t):ℝ)+1)^h*Λ t/ + Real.log (sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t))) atTop (𝓝 0) := by + have hh := source_uniform_absorption B h ζ hB hζ i hn hH (fun t=>lt_of_lt_of_le (by norm_num) (hΛ t)) hrel + apply squeeze_zero' _ _ hh + · filter_upwards [(sourceTargetScale_tendsto B ζ hB hζ i hn hH hΛ hrel).eventually_gt_atTop 1] with t ht + exact div_nonneg (mul_nonneg (by positivity) (by linarith [hΛ t])) (Real.log_pos ht).le + · filter_upwards [(sourceTargetScale_tendsto B ζ hB hζ i hn hH hΛ hrel).eventually_gt_atTop 1] with t ht + apply div_le_div_of_nonneg_left (by positivity [hΛ t]) + (mul_pos (sourceEpsilon_pos _ _) (Real.log_pos ht)) + exact mul_le_of_le_one_left (Real.log_pos ht).le (sourceEpsilon_le_one _ _) + +theorem totalScoreExponent_bounds (B D : ℕ) (hB : 2 ≤ B) : + 11/5 ≤ totalScoreExponent B D ∧ totalScoreExponent B D ≤ 3+(D:ℝ)*B := by + have hdim (i : ℕ) : (2:ℝ) ≤ (if i norm_cast + have hlo : 0 ≤ ∑i∈Finset.range D,blockGain (if i linarith + +theorem sourceHalfMoment_bounds (B D i : ℕ) {n : ℝ} (hB : 2 ≤ B) (hn : 1Real.log (N t)) 0 := by + refine ⟨(hN.eventually_gt_atTop 1).mono (fun _ ht=>Real.log_pos ht),?_⟩ + convert + (isLittleO_log_rpow_atTop (by norm_num : (0:ℝ)<1)).tendsto_div_nhds_zero.comp + (Real.tendsto_log_atTop.comp hN) using 1 + ext t + simp only [Function.comp_apply,Real.rpow_one] + +/-- Only arithmetic predicates on the literal source integers. -/ +structure SourceInitialGeometry (q N : ℝ) : Prop where + m_large : 128 ≤ sourceInitialM N + K_pos : 0 < sourceInitialK N + K_le_m : sourceInitialK N ≤ sourceInitialM N + seed : 16 ≤ q^3*(sourceInitialM N:ℝ) + count : 8 ≤ ((sourceInitialK N*sourceInitialM N:ℕ):ℝ)*q^2 + anchor_margin : 12*(sourceInitialJ q N+2^300+1) ≤ sourceInitialK N + smoothing_margin : ((2*(2^300):ℕ):ℝ) < (sourceInitialK N:ℝ)/(3*(3000+1:ℝ)) + length_lower : N/2 ≤ (sourceInitialP q N:ℝ)*(sourceInitialPeriodSize N:ℝ) + length_upper : (sourceInitialP q N:ℝ)*(sourceInitialPeriodSize N:ℝ) ≤ N + +/-- All floor, seed, count, placement and length restrictions are automatic + in the actual joint regime; no change of the deletion rate at the base scale. -/ +theorem source_initial_geometry {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hq : ∀t,q t∈Set.Ioc 0 1) + (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) : + ∀ᶠt in atTop,SourceInitialGeometry (q t) (N t) := by + have hm := sourceInitialM_rate hN + have hK := sourceInitialK_rate hN + have hqrate := deletion_rate_zero hN hq hΛ + have hJ := sourceInitialJ_rate hN hqrate + have hL := sourceInitialPeriodSize_rate hN + have hF := sourceInitialCapacity_rate hN + have ht := sourceInitialSide_rate hN hqrate + have hm128 := (hm.tendsto_atTop hN (by norm_num)).eventually_ge_atTop 128 + have hKm := hK.eventually_lt hN hm (by norm_num) + have hKF := hK.eventually_lt hN hF (by norm_num) + have hseed := ((hqrate.pow 3).mul hm).tendsto_atTop hN (by norm_num) + have hcount := ((hK.mul hm).mul (hqrate.pow 2)).tendsto_atTop hN (by norm_num) + have hanchor := ((hJ.add_const hN (by norm_num) (by positivity : (0:ℝ)≤2^300+1)).const_mul + hN (by norm_num : (0:ℝ)<12)).eventually_lt hN hK (by norm_num) + have hsm := (hK.tendsto_atTop hN (by norm_num)).eventually_gt_atTop ((2*(2^300):ℝ)*(3*3001)) + have hloss : PowerRate N (fun t=>(2*(initialSideCount (q t) (sourceInitialM (N t)):ℝ)+2)* + (sourceInitialPeriodSize (N t):ℝ)) (124/125) := by + convert ((ht.const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN + (by norm_num) (by norm_num : (0:ℝ)≤2)).mul hL using 1 + norm_num + have hloss' := hloss.eventually_lt hN ((PowerRate.base hN).div_const hN (by norm_num : (0:ℝ)<2)) (by norm_num) + filter_upwards [hN.eventually_gt_atTop 0,hm128,hK.1,hKm,hKF, + hseed.eventually_ge_atTop 16,hcount.eventually_ge_atTop 8,hanchor,hsm,hloss'] with t hNt hm128 hKpos hKm hKF hs hc ha hsm hloss + have hmn : 128 ≤ sourceInitialM (N t) := by exact_mod_cast hm128 + have hKn : 0 < sourceInitialK (N t) := by exact_mod_cast hKpos + have hLpos : 0 < sourceInitialPeriodSize (N t) := by unfold sourceInitialPeriodSize; omega + have hcnt := initial_period_count_bounds (m:=sourceInitialM (N t)) + (K:=sourceInitialK (N t)) (t:=initialSideCount (q t) (sourceInitialM (N t))) + (N:=N t) hLpos hNt.le hKF.le + have hcnt' : (sourceInitialP (q t) (N t):ℝ)*(sourceInitialPeriodSize (N t):ℝ) ≤ N t ∧ + N t<((sourceInitialP (q t) (N t):ℝ)+(2*initialSideCount (q t) (sourceInitialM (N t))+1:ℕ)+1)* + (sourceInitialPeriodSize (N t):ℝ) := by + simpa only [sourceInitialP,sourceInitialJ,sourceInitialCapacity,sourceInitialPeriodSize, + Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] using hcnt + refine ⟨hmn,hKn,?_,hs,?_,?_,?_,?_,hcnt'.1⟩ + · exact_mod_cast hKm.le + · simpa only [Nat.cast_mul] using hc + · apply (Nat.cast_le (α:=ℝ)).mp + simp only [Nat.cast_mul,Nat.cast_add,Nat.cast_pow,Nat.cast_ofNat,Nat.cast_one] + simpa only [add_assoc] using ha.le + · apply (lt_div_iff₀ (by norm_num : (0:ℝ)<3*(3000+1))).mpr + simpa only [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,show (3000+1:ℝ)=3001 by norm_num] using hsm + · have H := hcnt'.2 + push_cast at H + nlinarith only [H,hloss] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- The exact varying even moment order is subpower at EVERY working scale. -/ +theorem sourceHalfMoment_rate (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) + {n Λ H : ℕ→ℝ} (i : ℕ→ℕ) (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) + (hΛ : ∀t,1 ≤ Λ t) (hrel : ∀t,Real.log (n t)=Λ t*H t) : + PowerRate (fun t=>sourceTargetScale B (sourceDepth B ζ (H t)) (n t) (i t)) + (fun t=>(sourceHalfMoment B (sourceDepth B ζ (H t)) (n t) (i t):ℝ)) 0 := by + let C : ℝ := ((10^8:ℝ)*2^(10*B)*((B:ℝ)+4)*2+1) + let A : ℝ := C+1+(B:ℝ)*Real.log 2 + have hC : 0(k t:ℝ)) 0) : + PowerRate N (fun t=>sourceInitialWeight (q t) (k t)) 0 := by + have H := (hk.const_mul hN (by norm_num : (0:ℝ)<24)).div hq + convert H using 1 + · ext t + simp only [sourceInitialWeight,Nat.cast_mul,Nat.cast_ofNat] + ring + · norm_num + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +variable {N q w : ℕ→ℝ} {k : ℕ→ℕ} + +def initialClipFactor (N q w : ℝ) : ℝ := + 4*(initialMomentRatio (sourceInitialK N) (sourceInitialM N) q w/ + (1-initialMomentRatio (sourceInitialK N) (sourceInitialM N) q w)) + +theorem initialClipFactor_rate (hN : Tendsto N atTop atTop) + (hq : PowerRate N q 0) (hw : PowerRate N w 0) : + PowerRate N (fun t=>initialClipFactor (N t) (q t) (w t)) (-1/500) := by + have hρ := initialMomentRatio_rate hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) hq hw + have hden := (PowerRate.const hN (by norm_num : (0:ℝ)<1)).sub_lower hN hρ (by norm_num) + simpa only [initialClipFactor,sub_zero] using (hρ.div hden).const_mul hN (by norm_num : (0:ℝ)<4) + +/-- The source moment is genuinely used in clipping: the exponent is linear + in that moment, not a fixed negative power of the intermediate length. -/ +theorem initial_clip_exp_bound (hN : Tendsto N atTop atTop) + (hq : PowerRate N q 0) (hw : PowerRate N w 0) (hk : ∀ᶠt in atTop,1 ≤ k t) : + ∀ᶠt in atTop, + Real.sqrt (6*(initialClipFactor (N t) (q t) (w t))^(k t)) ≤ + Real.exp (-(k t:ℝ)*Real.log (N t)/2000) := by + have hfac := initialClipFactor_rate hN hq hw + have hu := hfac.upper hN (-3/2000) (by norm_num) + filter_upwards [hk,hfac.1,hu,hN.eventually_gt_atTop 1, + (Real.tendsto_log_atTop.comp hN).eventually_ge_atTop (2000*Real.log 6)] with t hk hp hu hn hlog + rw [abs_of_pos hp] at hu + have hh := Real.log_le_log hp hu + rw [Real.log_rpow (by linarith : 0initialOverlapLower (q t)) 0) + (hk : PowerRate N (fun t=>(k t:ℝ)) 0) : + ∀ᶠt in atTop, + 2*Real.exp (-((sourceInitialK (N t)*sourceInitialM (N t):ℕ):ℝ)*(q t)^4/64)+ + Real.exp (-(sourceInitialJ (q t) (N t):ℝ)*(initialOverlapLower (q t))^4/16) ≤ + 3*Real.exp (-(k t:ℝ)*Real.log (N t)) := by + have hlow : PowerRate N (fun t=>(k t:ℝ)*Real.log (N t)) 0 := by + simpa using hk.mul (PowerRate.log_base hN) + have hfirst := (((sourceInitialK_rate hN).mul (sourceInitialM_rate hN)).mul + (hq.pow 4)).div_const hN (by norm_num : (0:ℝ)<64) + have hsecond := ((sourceInitialJ_rate hN hq).mul (hω.pow 4)).div_const hN (by norm_num : (0:ℝ)<16) + filter_upwards [hlow.eventually_lt hN hfirst (by norm_num),hlow.eventually_lt hN hsecond (by norm_num)] with t h1 h2 + have he1 := Real.exp_le_exp.mpr (neg_le_neg h1.le) + have he2 := Real.exp_le_exp.mpr (neg_le_neg h2.le) + push_cast + simp only [neg_div,neg_mul] at he1 he2 ⊢ + linarith + +/-- A completely quantitative sufficient moment inequality for the actual + initial error. This is later discharged by the literal ceiling r_0/2. -/ +theorem initial_error_eventually {n A : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hn : Tendsto n atTop atTop) (hA : ∀ᶠt in atTop,1 ≤ A t) + (hq : ∀t,q t∈Set.Ioc 0 1) + (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) + (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) + (hmoment : ∀ᶠt in atTop, 10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) : + ∀ᶠt in atTop, + initialErrorCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) + (sourceInitialM (N t)) (k t) (q t) (initialOverlapLower (q t)) + (sourceInitialWeight (q t) (k t)) ≤ (n t)^(-100*A t) := by + have hqrate := deletion_rate_zero hN hq hΛ + have hω := initialOverlap_rate hN (fun t=>(hq t).1) hΛ + have hw := sourceInitialWeight_rate hN hqrate hk + have hclip := initial_clip_exp_bound hN hqrate hw hk1 + have hmeta := initial_metadata_exp_bound hN hqrate hω hk + filter_upwards [hclip,hmeta,hmoment,hA,hn.eventually_gt_atTop 1, + (Real.tendsto_log_atTop.comp hn).eventually_ge_atTop (Real.log 4)] with t hc hm hmom hA hn hlog + have hAn : 0 ≤ A t*Real.log (n t) := mul_nonneg (by linarith) (Real.log_pos hn).le + have he1 : Real.exp (-(k t:ℝ)*Real.log (N t)/2000) ≤ Real.exp (-500*(A t*Real.log (n t))) := + Real.exp_le_exp.mpr (by nlinarith) + have he2 : Real.exp (-(k t:ℝ)*Real.log (N t)) ≤ Real.exp (-500*(A t*Real.log (n t))) := + Real.exp_le_exp.mpr (by nlinarith) + have herr : initialErrorCap (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) + (sourceInitialM (N t)) (k t) (q t) (initialOverlapLower (q t)) + (sourceInitialWeight (q t) (k t)) ≤ 4*Real.exp (-500*(A t*Real.log (n t))) := by + unfold initialErrorCap + change Real.sqrt (6*initialClipFactor (N t) (q t) (sourceInitialWeight (q t) (k t))^(k t))+_ ≤ _ + nlinarith only [hc,hm,he1,he2] + apply herr.trans + rw [Real.rpow_def_of_pos (by linarith : 0f t+g t) α := by + have hz := ((hg.div hf).upper hN).tendsto_zero hN (sub_neg.mpr hβα) + apply hf.of_ratio hN (by norm_num : (0:ℝ)<1) + have H : Tendsto (fun t=>1+g t/f t) atTop (𝓝 1) := by + simpa using tendsto_const_nhds.add hz + apply H.congr' + filter_upwards [hf.1] with t ht + field_simp [ht.ne'] + +theorem PowerRate.nat_ceil (hN : Tendsto N atTop atTop) (hf : PowerRate N f α) + (ha : 0<α) : PowerRate N (fun t=>(⌈f t⌉₊:ℝ)) α := by + exact hf.of_ratio hN (by norm_num : (0:ℝ)<1) + (tendsto_nat_ceil_div_atTop.comp (hf.tendsto_atTop hN ha)) + +def sourceOverlapConstant (q : ℝ) : ℝ := (2:ℝ)^40/(q*initialOverlapLower q) +def sourceInitialCount (q N : ℝ) : ℕ := + ⌈sourceOverlapConstant q*(initialSideCount q (sourceInitialM N):ℝ)*(sourceInitialP q N:ℝ)⌉₊ + +theorem sourceInitialP_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hq : PowerRate N q 0) : + PowerRate N (fun t=>(sourceInitialP (q t) (N t):ℝ)) (63/125) := by + have hj := sourceInitialJ_rate hN hq + have ht := ((sourceInitialSide_rate hN hq).const_mul hN (by norm_num : (0:ℝ)<2)).add_const hN + (by norm_num) (by norm_num : (0:ℝ)≤1) + have H := (hj.mul ht).add_lower hN (sourceInitialK_rate hN) (by norm_num) + convert H using 1 + · ext t + simp only [sourceInitialP,Nat.cast_add,Nat.cast_mul,Nat.cast_ofNat,Nat.cast_one] + · norm_num + +theorem sourceOverlapConstant_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hq : PowerRate N q 0) (hω : PowerRate N (fun t=>initialOverlapLower (q t)) 0) : + PowerRate N (fun t=>sourceOverlapConstant (q t)) 0 := by + simpa only [sourceOverlapConstant,add_zero,sub_zero] using + (PowerRate.const hN (by positivity : (0:ℝ)<(2:ℝ)^40)).div (hq.mul hω) + +theorem sourceInitialCount_rate {q : ℕ→ℝ} (hN : Tendsto N atTop atTop) + (hq : PowerRate N q 0) (hω : PowerRate N (fun t=>initialOverlapLower (q t)) 0) : + PowerRate N (fun t=>(sourceInitialCount (q t) (N t):ℝ)) 1 := by + have H := (((sourceOverlapConstant_rate hN hq hω).mul (sourceInitialSide_rate hN hq)).mul + (sourceInitialP_rate hN hq)).nat_ceil hN (by norm_num) + convert H using 1 + · rfl + · norm_num + +theorem sourceOverlapConstant_pos {q : ℝ} (hq : 0(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) + (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) + (hmoment : ∀ᶠt in atTop,10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) : + ∀ᶠt in atTop, + SourceInitialGeometry (q t) (N t) ∧ + sourceInitialError (q t) (N t) (k t) ≤ (n t)^(-100*A t) ∧ + Nonempty (OracleTracePair (q t) (sourceInitialWord (q t) (N t) (-1)) + (sourceInitialWord (q t) (N t) 1) (k t) (sourceInitialError (q t) (N t) (k t)) ((N t)^(-11/5:ℝ))) ∧ + Nonempty (OracleTracePair (q t) (sourceInitialPure (q t) (N t)) + (sourceInitialWord (q t) (N t) 1) (k t) (sourceInitialError (q t) (N t) (k t)) ((N t)^(-7/5:ℝ))) := by + have hq' (t) : q t ∈ Set.Ioc 0 1 := ⟨(hq t).1,by linarith [(hq t).2]⟩ + have hqr := deletion_rate_zero hN hq' hΛ + have hw := sourceInitialWeight_rate hN hqr hk + have herr := initial_error_eventually hN hn hA hq' hΛ hk hk1 hmoment + have hgeo := source_initial_geometry hN hq' hΛ + have hcap := source_initial_score_caps hN hq' hΛ hw + have hρ := (initialMomentRatio_rate hN (sourceInitialK_rate hN) (sourceInitialM_rate hN) hqr hw).upper hN |>.tendsto_zero hN (by norm_num) + have hsmall := ((tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<100)).comp hn).eventually_le_const (by norm_num : (0:ℝ)<1/2) + filter_upwards [hgeo,hcap,herr,hk1,hA,hn.eventually_gt_atTop 1,hN.eventually_gt_atTop 0, + hρ.eventually_le_const (by norm_num : (0:ℝ)<1/2),hsmall] with t hg hcap he hk1 ha hnt hNt hρ hsmall + have hm : 4 ≤ sourceInitialM (N t) := (by norm_num : 4 ≤ 128).trans hg.m_large + let off := sourceInitialOffset (sourceInitialM (N t)) hm + have hi := sourceInitialOffset_interior _ hm + have hanchor := initial_anchor_geometry (sourceInitialJ (q t) (N t)) (sourceInitialK (N t)) + (initialSideCount (q t) (sourceInitialM (N t))) 300 hg.anchor_margin + change _ ≤ sourceInitialAnchor (q t) (N t) ∧ sourceInitialAnchor (q t) (N t)+(2^300:ℕ) ≤ _ ∧ _ at hanchor + have he' : sourceInitialError (q t) (N t) (k t) ≤ 1/2 := by + exact he.trans ((Real.rpow_le_rpow_of_exponent_le hnt.le (by linarith : -100*A t ≤ -100)).trans hsmall) + have hc : Real.sqrt (6*(4*(initialMomentRatio (sourceInitialK (N t)) (sourceInitialM (N t)) (q t) + (sourceInitialWeight (q t) (k t))/(1-initialMomentRatio (sourceInitialK (N t)) + (sourceInitialM (N t)) (q t) (sourceInitialWeight (q t) (k t)))))^(k t)) ≤ 1/2 := by + have ht : 0 ≤ 2*Real.exp (-((sourceInitialK (N t)*sourceInitialM (N t):ℕ):ℝ)*(q t)^4/64)+ + Real.exp (-(sourceInitialJ (q t) (N t):ℝ)*(initialOverlapLower (q t))^4/16) := by positivity + unfold sourceInitialError initialErrorCap at he' + linarith only [he',ht] + have HH := actual_initial_oracles hg.K_pos hg.m_large hg.K_le_m (by norm_num : 0<3000) + off hi (sourceInitialOffset_middle _ hm) (sourceInitialOffset_safe _ _ hm) + (sourceInitialAnchor (q t) (N t)) 300 (k t) hk1 (hq t) hg.seed hg.count + hanchor.1 hanchor.2.1 hanchor.2.2.1 hanchor.2.2.2 hg.smoothing_margin + (rfl : sourceInitialWeight (q t) (k t)=_) hρ hc + (Real.rpow_nonneg hNt.le _) (Real.rpow_nonneg hNt.le _) hcap.1 hcap.2 + refine ⟨hg,he,?_,?_⟩ + · simpa only [sourceInitialWord,dite_eq_left hm,sourceInitialP,sourceInitialError,off] using HH.1 + · simpa only [sourceInitialWord,dite_eq_left hm,sourceInitialP,sourceInitialError,sourceInitialPure, + off,sourceInitialOffset] using HH.2 + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +/-- Literal count instantiation; the harmless ceiling is included. -/ +theorem sourceInitialCount_bounds {q N : ℝ} (hq : q ∈ Set.Ioc 0 (1/2:ℝ)) + (H : SourceInitialGeometry q N) : + sourceInitialP q N*sourceInitialPeriodSize N ≤ sourceInitialCount q N ∧ + (sourceInitialCount q N:ℝ) ≤ (sourceOverlapConstant q)^2* + ((sourceInitialP q N*sourceInitialPeriodSize N:ℕ):ℝ) := by + let C := sourceOverlapConstant q + let m := sourceInitialM N + let t := initialSideCount q m + let P := sourceInitialP q N + let ell := sourceInitialPeriodSize N + have hC : 0initialOverlapLower (q t)) 0) + (hE : ∀ᶠt in atTop,0 ≤ E t ∧ E t ≤ (N t)^(-100:ℝ)) : + ∀ᶠt in atTop,Real.sqrt (((sourceInitialCount (q t) (N t)+1:ℕ):ℝ)*((N t)^(-7/5:ℝ)))+ + 2*((sourceInitialCount (q t) (N t)+1:ℕ):ℝ)*E t ≤ 1/16 := by + have hF := (sourceInitialCount_rate hN hq hω).add_const hN (by norm_num) (by norm_num : (0:ℝ) ≤ 1) + have hw := (PowerRate.base hN).rpow (-7/5:ℝ) + have he := (PowerRate.base hN).rpow (-100:ℝ) + have hs := ((hF.mul hw).sqrt.upper hN).tendsto_zero hN (by norm_num) + have ht := (((hF.mul he).const_mul hN (by norm_num : (0:ℝ)<2)).upper hN).tendsto_zero hN (by norm_num) + have hsum := hs.add ht + rw [zero_add] at hsum + have HH := hsum.eventually_le_const (by norm_num : (0:ℝ)<1/16) + filter_upwards [HH,hE] with t ht he + simp only [Nat.cast_add,Nat.cast_one] + simp only [←mul_assoc] at ht + apply le_trans _ ht + apply add_le_add le_rfl + exact mul_le_mul_of_nonneg_left he.2 (by positivity) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology Classical + +theorem source_initial_level_eventually {N q n A : ℕ→ℝ} {k : ℕ→ℕ} + (hN : Tendsto N atTop atTop) (hn : Tendsto n atTop atTop) + (hA : ∀ᶠt in atTop,1 ≤ A t) (hq : ∀t,q t ∈ Set.Ioc 0 (1/2:ℝ)) + (hΛ : Tendsto (fun t=>(q t)^(-3:ℤ)/Real.log (N t)) atTop (𝓝 0)) + (hk : PowerRate N (fun t=>(k t:ℝ)) 0) (hk1 : ∀ᶠt in atTop,1 ≤ k t) + (hmoment : ∀ᶠt in atTop,10^6*A t*Real.log (n t) ≤ (k t:ℝ)*Real.log (N t)) + (hscale : ∀ᶠt in atTop,N t ≤ n t) : + ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ + (N t) ((n t)^(-100*A t)) (11/5) (initialOverlapLower (q t)) + ((sourceOverlapConstant (q t))^2) 0 (k t)) := by + have hor := source_initial_oracles_eventually hN hn hA hq hΛ hk hk1 hmoment + have hq' (t) : q t ∈ Set.Ioc 0 1 := ⟨(hq t).1,by linarith [(hq t).2]⟩ + have hqr := deletion_rate_zero hN hq' hΛ + have hωr := initialOverlap_rate hN (fun t=>(hq t).1) hΛ + have he : ∀ᶠt in atTop,0 ≤ sourceInitialError (q t) (N t) (k t) ∧ + sourceInitialError (q t) (N t) (k t) ≤ (N t)^(-100:ℝ) := by + filter_upwards [hor,hA,hscale,hN.eventually_gt_atTop 1] with t ht ha hs hNt + obtain ⟨C⟩ := ht.2.2.1 + refine ⟨C.error_nonneg,ht.2.1.trans ?_⟩ + calc + (n t)^(-100*A t) ≤ (n t)^(-100:ℝ) := Real.rpow_le_rpow_of_exponent_le (hNt.le.trans hs) (by linarith) + _ ≤ (N t)^(-100:ℝ) := Real.rpow_le_rpow_of_nonpos (by linarith) hs (by norm_num) + have hsmall := source_initial_overlap_budget_eventually hN hqr hωr he + filter_upwards [hor,hsmall,hk1,hN.eventually_gt_atTop 2,hn.eventually_gt_atTop 0] with t ht hs hk1 hNt hnt + obtain ⟨H,herr,⟨C⟩,⟨U⟩⟩ := ht + have hm : 4 ≤ sourceInitialM (N t) := (by norm_num : 4 ≤ 128).trans H.m_large + have hlen := sourceInitialWord_length (q:=q t) hm (-1) + have hlen' := sourceInitialWord_length (q:=q t) hm 1 + have hh := sourceInitialCount_bounds (hq t) H + have hlower : N t/2 ≤ ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) := by + rw [hlen,Nat.cast_mul]; exact H.length_lower + have hupper : ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) ≤ N t := by + rw [hlen,Nat.cast_mul]; exact H.length_upper + have hell : (1:ℝ) ≤ (sourceInitialWord (q t) (N t) (-1)).length := by linarith only [hNt,hlower] + have hp : 0 < ((sourceInitialWord (q t) (N t) (-1)).length:ℝ) := by linarith only [hell] + refine ⟨C.toConcrete ⟨(hq t).1.le,by linarith [(hq t).2]⟩ + (hlen.trans hlen'.symm) (sourceInitialWord_different H) hlower hupper ?_ (by norm_num) + (by simpa only [hlen] using hh.1) (by simpa only [hlen] using hh.2) ?_⟩ + · simp only [Nat.cast_zero,zero_add,one_mul] + apply (div_le_iff₀ hp).mpr + exact herr.trans (le_mul_of_one_le_right (Real.rpow_nonneg hnt.le _) hell) + · exact source_initial_power_overlap (hq t) H (by linarith) hk1 C U hs + +/-- All backwards targets are no larger than n, with the source epsilon. -/ +theorem sourceScaleProduct_le_one (B D i : ℕ) (hB : 2 ≤ B) : sourceScaleProduct B D i ≤ 1 := by + apply Finset.prod_le_one₀ + · intro j _ + have hdim : sourceDimension B j ≤ B := by unfold sourceDimension; split_ifs <;> omega + have he := sourceEpsilon_pos B D + have hh := sourceEpsilon_small B D + have hp : (1:ℝ) ≤ 2^B := one_le_pow₀ (by norm_num) + have hd : 0 ≤ (D:ℝ) := Nat.cast_nonneg _ + have hu : (2:ℝ)^B*sourceEpsilon B D ≤ 1/2 := by + nlinarith only [hh,mul_nonneg hd (mul_nonneg (le_trans zero_le_one hp) he.le)] + have hx := scaleA_zero_lower (sourceDimension B j) B (sourceEpsilon B D) hdim he.le + apply le_trans _ hx + exact mul_nonneg (by positivity) (by nlinarith only [hu,he]) + · intro j _ + have he := sourceEpsilon_pos B D + have hp : (1:ℝ) ≤ 2^(sourceDimension B j) := one_le_pow₀ (by norm_num) + unfold scaleA + norm_num only [pow_zero,mul_one] + have hh := (div_le_iff₀ (by positivity : (0:ℝ)<2^(sourceDimension B j))).mpr + (show 1+sourceEpsilon B D ≤ (1+sourceEpsilon B D)*2^(sourceDimension B j) from + le_mul_of_one_le_right (by linarith only [he]) hp) + linarith only [hh] + +theorem sourceTargetScale_le (B D i : ℕ) (n : ℝ) (hB : 2 ≤ B) (hn : 1 ≤ n) : + sourceTargetScale B D n i ≤ n := by + simpa only [sourceTargetScale,Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hn (sourceScaleProduct_le_one B D i hB) + +theorem sourceHalfMoment_sufficient (B D i : ℕ) {n : ℝ} (hB : 2 ≤ B) (hn : 1 < n) : + 10^6*(totalScoreExponent B D+B+1)*Real.log n ≤ + (sourceHalfMoment B D n i:ℝ)*Real.log (sourceTargetScale B D n i) := by + have hlo := sourceScaleProduct_lower B D i hB + have hs : 0 < sourceScaleProduct B D i := lt_of_lt_of_le (by positivity) hlo + have hl : 0 < Real.log (sourceTargetScale B D n i) := by + rw [sourceTargetScale,Real.log_rpow (by linarith : 0(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,Nonempty (ConcreteLevelPair (q t) ⟨(hq t).1.le,by linarith [(hq t).2]⟩ + (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) 0) + ((n t)^(-100*(totalScoreExponent B (sourceDepth B ζ ((q t)^3*Real.log (n t)))+B+1))) + (11/5) (initialOverlapLower (q t)) ((sourceOverlapConstant (q t))^2) 0 + (sourceHalfMoment B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) 0)) := by + let H := fun t=>(q t)^3*Real.log (n t) + let Λ := fun t=>(q t)^(-3:ℤ) + have hΛ (t) : 1 ≤ Λ t := by + dsimp [Λ] + rw [zpow_neg,zpow_ofNat,one_le_inv₀ (pow_pos (hq t).1 _)] + exact pow_le_one₀ (hq t).1.le (by linarith [(hq t).2]) + have hrel (t) : Real.log (n t)=Λ t*H t := by + dsimp [Λ,H] + rw [zpow_neg,zpow_ofNat] + field_simp [(hq t).1.ne'] + let D := fun t=>sourceDepth B ζ (H t) + let N := fun t=>sourceTargetScale B (D t) (n t) 0 + have hN := sourceTargetScale_tendsto B ζ hB hζ (fun _=>0) hn hH hΛ hrel + have hl := source_uniform_log_absorption B 0 ζ hB hζ (fun _=>0) hn hH hΛ hrel + simp only [pow_zero,one_mul] at hl + have hk := sourceHalfMoment_rate B ζ hB hζ (fun _=>0) hn hH hΛ hrel + apply source_initial_level_eventually hN hn _ hq hl hk + · filter_upwards [hn.eventually_gt_atTop 1] with t ht + exact (sourceHalfMoment_bounds B (D t) 0 hB ht).1 + · filter_upwards [hn.eventually_gt_atTop 1] with t ht + exact sourceHalfMoment_sufficient B (D t) 0 hB ht + · filter_upwards [hn.eventually_ge_atTop 1] with t ht + exact sourceTargetScale_le B (D t) 0 (n t) hB ht + · filter_upwards [] with t + have hd := (totalScoreExponent_bounds B (D t) hB).1 + have hbn : (0:ℝ) ≤ B := Nat.cast_nonneg _ + linarith only [hd,hbn] + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Kernels.lean b/lean/OAI/Probability/TraceReconstruction/Kernels.lean index ce904ef39cafd87bce0942b20dc3911f137456a0..cd6d91896749232dd8ff0650db60905059493d3b 100644 --- a/lean/OAI/Probability/TraceReconstruction/Kernels.lean +++ b/lean/OAI/Probability/TraceReconstruction/Kernels.lean @@ -1,649 +1,649 @@ -import OAI.Probability.TraceReconstruction.Binomial - -namespace OAI - -/-! -# Kernels - -Constrained rank-gap sums, correlated anchor kernels, window kernels, lattice Laplace sums, and geometric degree bounds. --/ - -open scoped ENNReal -noncomputable section - -noncomputable section -namespace TraceReconstruction - -/-- Eliminate one output gap by its prescribed total before dropping the -other rank constraints. This is the exact finite summation step used in -the conditional rank-kernel estimate. -/ -theorem constrained_sum_product_le (r L : ℕ) - (f : Fin (r + 1) → Fin (L + 1) → ℝ) - (hf : ∀ i k, 0 ≤ f i k) (M : ℝ) (hM : 0 ≤ M) - (hbound : ∀ k, f 0 k ≤ M) : - (∑ z : Fin (r + 1) → Fin (L + 1), - if ∑ j, (z j).val = L then ∏ j, f j (z j) else 0) ≤ - M * ∏ i : Fin r, ∑ k, f i.succ k := by - classical - rw [← (Fin.consEquiv (fun _ : Fin (r + 1) => Fin (L + 1))).sum_comp] - rw [Fintype.sum_prod_type, Finset.sum_comm] - have hpoint (z : Fin r → Fin (L + 1)) : - (∑ k : Fin (L + 1), - if k.val + ∑ i, (z i).val = L then f 0 k * ∏ i, f i.succ (z i) else 0) ≤ - M * ∏ i, f i.succ (z i) := by - by_cases hz : ∑ i, (z i).val ≤ L - · let k₀ : Fin (L + 1) := ⟨L - ∑ i, (z i).val, by omega⟩ - have heq (k : Fin (L + 1)) : k.val + ∑ i, (z i).val = L ↔ k = k₀ := by - change _ ↔ k = ⟨L - ∑ i, (z i).val, _⟩ - rw [Fin.ext_iff] - simp only - omega - simp_rw [heq] - rw [Fintype.sum_ite_eq'] - exact mul_le_mul_of_nonneg_right (hbound k₀) (Finset.prod_nonneg fun i _ => hf _ _) - · have heq (k : Fin (L + 1)) : ¬ (k.val + ∑ i, (z i).val = L) := by omega - simp_rw [ite_eq_right (heq _), Finset.sum_const_zero] - exact mul_nonneg hM (Finset.prod_nonneg fun i _ => hf _ _) - calc - _ ≤ ∑ z : Fin r → Fin (L + 1), M * ∏ i, f i.succ (z i) := by - apply Finset.sum_le_sum - intro z _ - simpa only [Fin.consEquiv_apply, Fin.sum_univ_succ, Fin.prod_univ_succ, - Fin.cons_zero, Fin.cons_succ] using hpoint z - _ = _ := by - rw [← Finset.mul_sum, ← Fintype.prod_sum (fun (i : Fin r) (k : Fin (L + 1)) => f i.succ k)] - -/-- The product of two rank kernels has one scalar denominator factor, -one uniform gap factor and independent one-dimensional cross-overlaps. -/ -theorem constrained_cross_kernel_le (r L : ℕ) - (f g : Fin (r + 1) → Fin (L + 1) → ℝ) - (hf : ∀ i k, 0 ≤ f i k) (hg : ∀ i k, 0 ≤ g i k) - (M : ℝ) (hM : 0 ≤ M) (hbound : ∀ k, f 0 k * g 0 k ≤ M) : - (∑ z : Fin (r + 1) → Fin (L + 1), - if ∑ j, (z j).val = L then (∏ j, f j (z j)) * (∏ j, g j (z j)) else 0) ≤ - M * ∏ i : Fin r, ∑ k, f i.succ k * g i.succ k := by - simp_rw [← Finset.prod_mul_distrib] - exact constrained_sum_product_le r L (fun i k => f i k * g i k) - (fun i k => mul_nonneg (hf i k) (hg i k)) M hM hbound - -end TraceReconstruction - -namespace TraceReconstruction - -/-! ## Correlated sibling-anchor estimate - -This is the analytic summation step in the correlated-anchor estimate, subsection -“Summing the correlated anchor kernels”. The common latent draw is kept -inside the joint kernel, so independence of the two displaced locations -is NOT assumed. Conditional independence only factors the two local -kernels for each fixed common draw. All arrays here have finite support; -the integer-jitter application uses a finite interval containing that support. --/ - -section CorrelatedAnchors - -variable {Ω I J : Type*} [Fintype Ω] [Fintype I] [Fintype J] - -/-- Mixture of conditional products; `p` is the common displacement law. -/ -def jointKernel (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) - (i : I) (j : J) : ℝ := ∑ w, p w * a w i * b w j - -omit [Fintype I] [Fintype J] in -theorem jointKernel_nonneg - (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) - (hp : ∀ w, 0 ≤ p w) (ha : ∀ w i, 0 ≤ a w i) - (hb : ∀ w j, 0 ≤ b w j) (i : I) (j : J) : - 0 ≤ jointKernel p a b i j := by - exact Finset.sum_nonneg fun w _ => mul_nonneg (mul_nonneg (hp w) (ha w i)) (hb w j) - -theorem sum_jointKernel - (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) (L M : ℝ) - (hp : ∑ w, p w = 1) - (ha : ∀ w, ∑ i, a w i = L) (hb : ∀ w, ∑ j, b w j = M) : - ∑ i, ∑ j, jointKernel p a b i j = L * M := by - simp only [jointKernel] - have hcomm (i : I) : - (∑ j : J, ∑ w : Ω, p w * a w i * b w j) = - ∑ w : Ω, ∑ j : J, p w * a w i * b w j := Finset.sum_comm - simp_rw [hcomm] - simp_rw [← Finset.mul_sum, hb] - rw [Finset.sum_comm] - simp_rw [← Finset.sum_mul, ← Finset.mul_sum, ha] - rw [← Finset.sum_mul, hp, one_mul] - -omit [Fintype I] [Fintype J] in -theorem jointKernel_le - (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) (A B : ℝ) - (hp : ∀ w, 0 ≤ p w) (ha : ∀ w i, 0 ≤ a w i) - (hB : 0 ≤ B) (hb : ∀ w j, b w j ≤ B) - (hA : ∀ i, ∑ w, p w * a w i ≤ A) (i : I) (j : J) : - jointKernel p a b i j ≤ A * B := by - calc - jointKernel p a b i j ≤ ∑ w, (p w * a w i) * B := by - exact Finset.sum_le_sum fun w _ => - mul_le_mul_of_nonneg_left (hb w j) (mul_nonneg (hp w) (ha w i)) - _ = (∑ w, p w * a w i) * B := (Finset.sum_mul _ _ _).symm - _ ≤ A * B := mul_le_mul_of_nonneg_right (hA i) hB - -/-- The joint squared-sum estimate retaining the common jitter. In the - manuscript A=L/(omega*sqrt(T*t)) and B=M/(omega*sqrt(t)), - up to the explicit absolute binomial constants. -/ -theorem correlated_anchor_square_sum - (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) - (L M A B : ℝ) - (hp0 : ∀ w, 0 ≤ p w) (hp1 : ∑ w, p w = 1) - (ha0 : ∀ w i, 0 ≤ a w i) (hb0 : ∀ w j, 0 ≤ b w j) - (ha1 : ∀ w, ∑ i, a w i = L) (hb1 : ∀ w, ∑ j, b w j = M) - (hB : 0 ≤ B) (hb : ∀ w j, b w j ≤ B) - (hA : ∀ i, ∑ w, p w * a w i ≤ A) : - ∑ i, ∑ j, (jointKernel p a b i j) ^ 2 ≤ (A * B) * (L * M) := by - calc - ∑ i, ∑ j, (jointKernel p a b i j) ^ 2 ≤ - ∑ i, ∑ j, (A * B) * jointKernel p a b i j := by - apply Finset.sum_le_sum - intro i _ - apply Finset.sum_le_sum - intro j _ - have h0 := jointKernel_nonneg p a b hp0 ha0 hb0 i j - have h1 := jointKernel_le p a b A B hp0 ha0 hB hb hA i j - nlinarith - _ = (A * B) * (∑ i, ∑ j, jointKernel p a b i j) := by - simp_rw [← Finset.mul_sum] - _ = (A * B) * (L * M) := by rw [sum_jointKernel p a b L M hp1 ha1 hb1] - -end CorrelatedAnchors - - -end TraceReconstruction - -namespace TraceReconstruction - -/-- Truncating output ranks cannot increase a binomial cross-overlap. -/ -theorem binomial_overlap_truncate (g h L : ℕ) {p : ℝ} - (hp : p ∈ Set.Icc 0 1) : - (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ - ∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k := by - rw [Fin.sum_univ_eq_sum_range (fun k => binomialMass g p k * binomialMass h p k) (L + 1)] - by_cases hL : L ≤ h - · apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono (by omega)) - intro k _ _ - exact mul_nonneg (binomialMass_nonneg g k hp) (binomialMass_nonneg h k hp) - · apply le_of_eq - symm - apply Finset.sum_subset (Finset.range_mono (by omega)) - intro k _ hk - have hhk : h < k := by - simp only [Finset.mem_range, not_lt] at hk - omega - simp [binomialMass, Nat.choose_eq_zero_of_lt hhk] - -/-- Gaussian cross-overlap with the prefactor attached to either prescribed -first length, removing the order restriction in the tilting proof. -/ -theorem binomial_gaussian_overlap_general (g h L : ℕ) {p : ℝ} - (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hS : 0 < g + h) : - (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ - Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * - Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by - have hp0 : 0 < p := by linarith [hp.1] - have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) - by_cases hhg : h ≤ g - · exact (binomial_overlap_truncate g h L ⟨hp0.le, hp.2.le⟩).trans - (binomial_gaussian_overlap g h hp hhg hS) - · have hgh : g ≤ h := by omega - have ho := (binomial_overlap_truncate h g L ⟨hp0.le, hp.2.le⟩).trans - (binomial_gaussian_overlap h g hp hgh (by omega)) - have hb : Real.sqrt (2 / (((h : ℝ) + 1) * p * (1 - p))) ≤ - Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) := by - apply Real.sqrt_le_sqrt - apply div_le_div_of_nonneg_left (by norm_num) - (by nlinarith only [mul_pos (show (0 : ℝ) < (g : ℝ) + 1 by positivity) hpq]) - have hcast : (g : ℝ) ≤ h := by exact_mod_cast hgh - have ht := mul_le_mul_of_nonneg_right (show (g : ℝ) + 1 ≤ (h : ℝ) + 1 by linarith) hpq.le - nlinarith only [ht] - have heq : -((h : ℝ) - g) ^ 2 / (16 * ((h : ℝ) + g)) = - -((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h)) := by ring - rw [heq] at ho - exact (by simpa only [mul_comm] using ho : - (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ _).trans - (mul_le_mul_of_nonneg_right hb (Real.exp_nonneg _)) - -/-- The exact conditional rank kernel, including the fixed count -normalization, before any coarse-gap estimates or restrictions. -/ -def rankKernel (r n l : ℕ) (p : ℝ) (g : Fin (r + 1) → ℕ) - (z : Fin (r + 1) → Fin (l + 1)) : ℝ := - if r ≤ l ∧ ∑ j, (z j).val = l - r then - p ^ r / binomialMass n p l * ∏ j, binomialMass (g j) p (z j) else 0 - -/-- Largest-gap elimination for the conditional rank kernel. The displayed -constant is absolute; no asymptotic proposal or Stirling theorem is assumed. -/ -theorem rankKernel_cross_le (r n l : ℕ) {p : ℝ} - (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hl : l ≤ n) - (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) - (g h : Fin (r + 1) → ℕ) : - (∑ z : Fin (r + 1) → Fin (l - r + 1), - if ∑ j, (z j).val = l - r then - (p ^ r / binomialMass n p l) ^ 2 * - (∏ j, binomialMass (g j) p (z j)) * - (∏ j, binomialMass (h j) p (z j)) else 0) ≤ - (4608 * n / ((g 0 : ℝ) + 1)) * - ∏ i : Fin r, ∑ k : Fin (l - r + 1), - binomialMass (g i.succ) p k * binomialMass (h i.succ) p k := by - have hp0 : 0 < p := by linarith [hp.1] - have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) - have hden : 0 < ((g 0 : ℝ) + 1) * p * (1 - p) := by - nlinarith only [mul_pos (show (0 : ℝ) < (g 0 : ℝ) + 1 by positivity) hpq] - have hc : (p ^ r / binomialMass n p l) ^ 2 ≤ 144 * ((n : ℝ) * p * (1 - p)) := by - rw [div_eq_mul_inv, mul_pow] - apply (mul_le_mul_of_nonneg_right - (show (p ^ r) ^ 2 ≤ (1 : ℝ) by - exact pow_le_one₀ (pow_nonneg hp0.le _) (pow_le_one₀ hp0.le hp.2.le)) - (sq_nonneg _)).trans - simpa only [one_mul] using binomialMass_mean_inverse_sq n l ⟨hp0, hp.2⟩ hl hmean hv - have hx := constrained_cross_kernel_le r (l - r) - (fun i k => binomialMass (g i) p k) (fun i k => binomialMass (h i) p k) - (fun i k => binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) - (fun i k => binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) - (32 / (((g 0 : ℝ) + 1) * p * (1 - p))) (by positivity) - (fun k => binomial_product_sup (g 0) (h 0) k hp) - have hprod : 0 ≤ ∏ i : Fin r, ∑ k : Fin (l - r + 1), - binomialMass (g i.succ) p k * binomialMass (h i.succ) p k := by - apply Finset.prod_nonneg - intro i _ - exact Finset.sum_nonneg fun k _ => mul_nonneg - (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) - (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) - calc - _ = (p ^ r / binomialMass n p l) ^ 2 * - (∑ z : Fin (r + 1) → Fin (l - r + 1), - if ∑ j, (z j).val = l - r then - (∏ j, binomialMass (g j) p (z j)) * - (∏ j, binomialMass (h j) p (z j)) else 0) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro z _ - split_ifs <;> ring - _ ≤ (p ^ r / binomialMass n p l) ^ 2 * - ((32 / (((g 0 : ℝ) + 1) * p * (1 - p))) * _) := - mul_le_mul_of_nonneg_left hx (sq_nonneg _) - _ ≤ (144 * ((n : ℝ) * p * (1 - p))) * - ((32 / (((g 0 : ℝ) + 1) * p * (1 - p))) * _) := - mul_le_mul_of_nonneg_right hc (mul_nonneg (by positivity) hprod) - _ = _ := by - have hq : 1 - p ≠ 0 := ne_of_gt (sub_pos.mpr hp.2) - field_simp - ring - -end TraceReconstruction - -namespace TraceReconstruction -theorem fairSeries_total (n : ℕ) : ∑' z : ℤ, (fairSeries n).coeff z = 1 := by - have h := fairSeries_L1 n - unfold seriesL1 at h - simpa only [abs_of_nonneg (fairSeries_nonneg n _)] using h - -theorem fairSeries_sum_finite_le_one (n : ℕ) (A : Finset ℤ) (c : ℤ) : - ∑ z ∈ A, (fairSeries n).coeff (c-z) ≤ 1 := by - have hs : Summable (fun z : ℤ => (fairSeries n).coeff (c-z)) := by - exact (Equiv.subLeft c).summable_iff.mpr (series_summable (fairSeries n) id rfl) - have hh : (∑' z : ℤ, (fairSeries n).coeff (c-z)) = 1 := by - simpa using ((Equiv.subLeft c).tsum_eq (fun z => (fairSeries n).coeff z)).trans - (fairSeries_total n) - rw [← hh] - exact Summable.sum_le_tsum A (fun _ _ => fairSeries_nonneg n _) hs - -def windowKernel (n L : ℕ) (z : ℤ) : ℝ := - ∑ a ∈ Finset.range L, (fairSeries n).coeff ((a:ℤ)-z) - -theorem windowKernel_nonneg (n L : ℕ) (z : ℤ) : 0 ≤ windowKernel n L z := - Finset.sum_nonneg (fun _ _ => fairSeries_nonneg n _) - -theorem windowKernel_sup (n L : ℕ) (z : ℤ) : - windowKernel n L z ≤ L*binomialBound n := by - calc - _ ≤ ∑ _a ∈ Finset.range L, binomialBound n := by - apply Finset.sum_le_sum - intro a _ - exact (le_abs_self _).trans (fairSeries_coeff_bound n _) - _ = _ := by simp - -theorem windowKernel_sum (n L : ℕ) (A : Finset ℤ) (c : ℤ) : - ∑ z ∈ A, windowKernel n L (z-c) ≤ L := by - unfold windowKernel - rw [Finset.sum_comm] - calc - _ ≤ ∑ _a ∈ Finset.range L, (1:ℝ) := by - apply Finset.sum_le_sum - intro a _ - simpa only [show ∀ z : ℤ, (a:ℤ)-(z-c)=(a:ℤ)+c-z from fun z => by omega] - using fairSeries_sum_finite_le_one n A ((a:ℤ)+c) - _ = _ := by simp - -theorem windowKernel_energy (n L : ℕ) (A : Finset ℤ) (c : ℤ) : - ∑ z ∈ A, windowKernel n L (z-c)^2 ≤ L^2*binomialBound n := by - calc - _ ≤ ∑ z ∈ A, windowKernel n L (z-c)*(L*binomialBound n) := by - apply Finset.sum_le_sum - intro z _ - simpa only [pow_two] using mul_le_mul_of_nonneg_left - (windowKernel_sup n L (z-c)) (windowKernel_nonneg n L (z-c)) - _ = (∑ z ∈ A, windowKernel n L (z-c))*(L*binomialBound n) := by rw [Finset.sum_mul] - _ ≤ L*(L*binomialBound n) := mul_le_mul_of_nonneg_right - (windowKernel_sum n L A c) (by positivity [binomialBound_nonneg n]) - _ = _ := by ring - -def jointWindowKernel (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : ℝ := - ∑ v ∈ (fairSeries g).coeff.support, - (fairSeries g).coeff v * windowKernel n₁ L (z₁+v) * windowKernel n₂ L (z₂+v) - -theorem windowKernel_average (g n L : ℕ) (z : ℤ) : - (∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * windowKernel n L (z+v)) = - windowKernel (g+n) L z := by - unfold windowKernel - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - rw [fairSeries_add, AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum] - apply Finset.sum_congr rfl - intro v _ - congr 2 - omega - -theorem jointWindowKernel_nonneg (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : - 0 ≤ jointWindowKernel g n₁ n₂ L z₁ z₂ := by - apply Finset.sum_nonneg - intro v _ - exact mul_nonneg (mul_nonneg (fairSeries_nonneg g v) (windowKernel_nonneg n₁ L _)) - (windowKernel_nonneg n₂ L _) - -theorem jointWindowKernel_sup (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : - jointWindowKernel g n₁ n₂ L z₁ z₂ ≤ L^2*binomialBound g*binomialBound n₂ := by - have hbound : binomialBound (g+n₁) ≤ binomialBound g := by - apply Real.sqrt_le_sqrt - apply div_le_div_of_nonneg_left (by norm_num) (by positivity) - simp only [Nat.cast_add]; linarith [show (0:ℝ) ≤ n₁ by positivity] - calc - _ ≤ ∑ v ∈ (fairSeries g).coeff.support, - (fairSeries g).coeff v * windowKernel n₁ L (z₁+v) * (L*binomialBound n₂) := by - apply Finset.sum_le_sum - intro v _ - exact mul_le_mul_of_nonneg_left (windowKernel_sup n₂ L _) (mul_nonneg - (fairSeries_nonneg g v) (windowKernel_nonneg n₁ L _)) - _ = windowKernel (g+n₁) L z₁ * (L*binomialBound n₂) := by - rw [← Finset.sum_mul, windowKernel_average] - _ ≤ (L*binomialBound g)*(L*binomialBound n₂) := by - apply mul_le_mul_of_nonneg_right _ (mul_nonneg (by positivity) (binomialBound_nonneg n₂)) - exact (windowKernel_sup (g+n₁) L z₁).trans - (mul_le_mul_of_nonneg_left hbound (by positivity)) - _ = _ := by ring - -theorem jointWindowKernel_sum (g n₁ n₂ L : ℕ) (A B : Finset ℤ) (c₁ c₂ : ℤ) : - ∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂) ≤ L^2 := by - unfold jointWindowKernel - simp_rw [Finset.sum_comm (s := B)] - rw [Finset.sum_comm] - calc - _ = ∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * - (∑ z₁ ∈ A, windowKernel n₁ L ((z₁-c₁)+v)) * - (∑ z₂ ∈ B, windowKernel n₂ L ((z₂-c₂)+v)) := by - apply Finset.sum_congr rfl - intro v _ - simp_rw [Finset.mul_sum, Finset.sum_mul] - rw [Finset.sum_comm] - _ ≤ ∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * (L*L) := by - apply Finset.sum_le_sum - intro v _ - have h1 : (∑ z₁ ∈ A, windowKernel n₁ L ((z₁-c₁)+v)) ≤ L := by - simpa only [show ∀ z : ℤ, (z-c₁)+v = z-(c₁-v) from fun z => by omega] - using windowKernel_sum n₁ L A (c₁-v) - have h2 : (∑ z₂ ∈ B, windowKernel n₂ L ((z₂-c₂)+v)) ≤ L := by - simpa only [show ∀ z : ℤ, (z-c₂)+v = z-(c₂-v) from fun z => by omega] - using windowKernel_sum n₂ L B (c₂-v) - rw [mul_assoc] - apply mul_le_mul_of_nonneg_left _ (fairSeries_nonneg g v) - exact mul_le_mul h1 h2 (Finset.sum_nonneg (fun z _ => windowKernel_nonneg n₂ L _)) (by positivity) - _ = L^2 := by - rw [← Finset.sum_mul] - have ht : (∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v) = 1 := by - have h := fairSeries_L1 g - rw [seriesL1_eq_sum] at h - simpa only [abs_of_nonneg (fairSeries_nonneg g _)] using h - rw [ht]; ring - -theorem jointWindowKernel_energy (g n₁ n₂ L : ℕ) (A B : Finset ℤ) (c₁ c₂ : ℤ) : - ∑ z₁ ∈ A, ∑ z₂ ∈ B, (jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂))^2 ≤ - L^4*binomialBound g*binomialBound n₂ := by - calc - _ ≤ ∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂) * - (L^2*binomialBound g*binomialBound n₂) := by - apply Finset.sum_le_sum - intro z₁ _ - apply Finset.sum_le_sum - intro z₂ _ - simpa only [pow_two] using mul_le_mul_of_nonneg_left - (jointWindowKernel_sup g n₁ n₂ L _ _) (jointWindowKernel_nonneg g n₁ n₂ L _ _) - _ = (∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂)) * - (L^2*binomialBound g*binomialBound n₂) := by simp_rw [Finset.sum_mul] - _ ≤ L^2*(L^2*binomialBound g*binomialBound n₂) := mul_le_mul_of_nonneg_right - (jointWindowKernel_sum g n₁ n₂ L A B c₁ c₂) - (mul_nonneg (mul_nonneg (by positivity) (binomialBound_nonneg g)) (binomialBound_nonneg n₂)) - _ = _ := by ring -end TraceReconstruction - -open Filter -open scoped Topology - - -namespace TraceReconstruction - -/-- Elementary discrete integral comparison, including the singular first cell. -/ -theorem sum_inverse_sqrt (N : ℕ) : - (∑ k ∈ Finset.range N, (Real.sqrt (k+1:ℝ))⁻¹) ≤ 2*Real.sqrt N := by - induction N with - | zero => simp - | succ N ih => - rw [Finset.sum_range_succ] - have hn : 0 ≤ (N:ℝ) := by positivity - have hp : 0 < Real.sqrt (N+1:ℝ) := Real.sqrt_pos.2 (by positivity) - have hs : Real.sqrt (N:ℝ) ≤ Real.sqrt (N+1:ℝ) := Real.sqrt_le_sqrt (by linarith) - have h1 := Real.sq_sqrt hn - have h2 := Real.sq_sqrt (show 0 ≤ (N+1:ℝ) by positivity) - have hstep : (Real.sqrt (N+1:ℝ))⁻¹ ≤ 2*(Real.sqrt (N+1:ℝ)-Real.sqrt N) := by - apply (inv_le_iff_one_le_mul₀ hp).2 - nlinarith [sq_nonneg (Real.sqrt (N+1:ℝ)-Real.sqrt N)] - push_cast - linarith - -theorem exp_gap_lower {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) : - h/2 ≤ 1-Real.exp (-h) := by - have he := Real.add_one_le_exp h - have hp : 0 < Real.exp h := Real.exp_pos h - have hp' : 0 < 1+h := by linarith - have hinv : (Real.exp h)⁻¹ ≤ (1+h)⁻¹ := inv_anti₀ hp' (by simpa [add_comm] using he) - rw [Real.exp_neg] - have hi : (1+h)⁻¹*(1+h)=1 := inv_mul_cancel₀ (ne_of_gt hp') - nlinarith [mul_nonneg hh.le (sub_nonneg.mpr h1)] - -theorem sum_exp_decay {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) (M : ℕ) : - (∑ k ∈ Finset.range M, Real.exp (-h*(k:ℝ))) ≤ 2/h := by - have he : 0 ≤ Real.exp (-h) := (Real.exp_pos _).le - have he1 : Real.exp (-h) < 1 := Real.exp_lt_one_iff.mpr (by linarith) - have hf : (∑ k ∈ Finset.range M, (Real.exp (-h))^k) ≤ (1-Real.exp (-h))⁻¹ := by - rw [inv_eq_one_div, le_div_iff₀ (by linarith : 0 < 1-Real.exp (-h)), geom_sum_mul_neg] - exact sub_le_self _ (pow_nonneg he M) - have hi : (1-Real.exp (-h))⁻¹ ≤ 2/h := by - rw [inv_le_iff_one_le_mul₀ (by linarith : 0<1-Real.exp (-h))] - have hb := exp_gap_lower hh h1 - have := mul_le_mul_of_nonneg_right hb (show 0 ≤ 2/h by positivity) - nlinarith [div_mul_cancel₀ (2:ℝ) hh.ne'] - calc - _ = ∑ k ∈ Finset.range M, (Real.exp (-h))^k := by - apply Finset.sum_congr rfl - intro k _ - rw [← Real.exp_nat_mul] - congr 1 - ring - _ ≤ _ := hf.trans hi - -/-- The uniform lattice Laplace estimate used by the initial-pair construction, with an absolute constant. -/ -theorem coarse_laplace_sum {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) (M : ℕ) : - (∑ k ∈ Finset.range M, (Real.sqrt (k+1:ℝ))⁻¹ * - Real.exp (-h*(k+1:ℝ))) ≤ 6/Real.sqrt h := by - let N := ⌈1/h⌉₊ - have hN : 1/h ≤ (N:ℝ) := Nat.le_ceil _ - have hNup : (N:ℝ) < 1/h+1 := Nat.ceil_lt_add_one (by positivity) - have hs : 0 < Real.sqrt h := Real.sqrt_pos.2 hh - have hNsqrt : Real.sqrt N ≤ 2/Real.sqrt h := by - have hn : (N:ℝ)*h ≤ 2 := by - have hx := mul_le_mul_of_nonneg_right hNup.le hh.le - have hc : (1/h)*h=1 := div_mul_cancel₀ _ hh.ne' - nlinarith - have hprod : Real.sqrt N * Real.sqrt h ≤ 2 := by - have hsqh := Real.sq_sqrt hh.le - have hsqN := Real.sq_sqrt (show 0≤(N:ℝ) by positivity) - have hnon : 0≤Real.sqrt N*Real.sqrt h := by positivity - nlinarith [sq_nonneg (Real.sqrt N*Real.sqrt h)] - exact (le_div_iff₀ hs).2 hprod - let low := (Finset.range M).filter (fun k => k ¬k - (Real.sqrt (k.val+1:ℝ))⁻¹ * Real.exp (-h*(k.val+1:ℝ)))] - have hc : (6/Real.sqrt h)^r = ∏ _i : Fin r, (6/Real.sqrt h) := by simp [div_pow] - rw [hc] - apply Finset.prod_le_prod₀ - · intros; positivity - · intro i _ - rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => - (Real.sqrt (k+1:ℝ))⁻¹ * Real.exp (-h*(k+1:ℝ))) M] - exact coarse_laplace_sum hh h1 M - -end TraceReconstruction - - -namespace TraceReconstruction - -/-- The degree-series estimate in the common-mass argument, with no asymptotic notation. -/ -theorem degree_series_bound (a : ℝ) (N : ℕ) : - (∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r)^2 ≤ - 2 * Real.exp (2*a^2) := by - let u (r : ℕ) : ℝ := (Real.sqrt ((1/2:ℝ)^r)) - let v (r : ℕ) : ℝ := (Real.sqrt ((2:ℝ)^r))*a^r/(Real.sqrt (r:ℝ))^r - have huv (r : ℕ) : u r * v r = a^r/(Real.sqrt (r:ℝ))^r := by - unfold u v - have he : Real.sqrt ((1/2:ℝ)^r) * Real.sqrt ((2:ℝ)^r)=1 := by - rw [← Real.sqrt_mul (by positivity), ← mul_pow] - norm_num - calc - _ = (Real.sqrt ((1/2:ℝ)^r) * Real.sqrt ((2:ℝ)^r)) * (a^r/(Real.sqrt (r:ℝ))^r) := by ring - _ = _ := by rw [he, one_mul] - have hu : (∑ r ∈ Finset.range N, (u r)^2) ≤ 2 := by - simp only [u, Real.sq_sqrt (by positivity : 0 ≤ (1/2:ℝ)^_)] - have hg := geom_sum_mul_neg (1/2:ℝ) N - have hp : 0≤(1/2:ℝ)^N := by positivity - linarith - have hv : (∑ r ∈ Finset.range N, (v r)^2) ≤ Real.exp (2*a^2) := by - apply le_trans _ (Real.sum_le_exp_of_nonneg (by positivity) N) - apply Finset.sum_le_sum - intro r _ - have hr : 0 < ((r.factorial):ℝ) := by exact_mod_cast Nat.factorial_pos r - have hrpow : 0 < (r:ℝ)^r := by - cases r with - | zero => norm_num - | succ r => positivity - have hfac : (r.factorial:ℝ) ≤ (r:ℝ)^r := by exact_mod_cast Nat.factorial_le_pow r - have hveq : (v r)^2 = (2*a^2)^r / (r:ℝ)^r := by - unfold v - rw [div_pow, mul_pow, Real.sq_sqrt (by positivity)] - have hd : ((Real.sqrt (r:ℝ))^r)^2=(r:ℝ)^r := by - rw [← pow_mul, mul_comm r 2, pow_mul, Real.sq_sqrt (by positivity)] - rw [hd] - rw [← pow_mul, mul_comm r 2, pow_mul] - ring - rw [hveq] - exact div_le_div_of_nonneg_left (by positivity) hr hfac - have hCS := Finset.sum_mul_sq_le_sq_mul_sq (Finset.range N) u v - simp only [huv] at hCS - exact hCS.trans (mul_le_mul hu hv (by positivity) (by norm_num)) - -end TraceReconstruction - -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Binomial + +namespace OAI + +/-! +# Kernels + +Constrained rank-gap sums, correlated anchor kernels, window kernels, lattice Laplace sums, and geometric degree bounds. +-/ + +open scoped ENNReal +noncomputable section + +noncomputable section +namespace TraceReconstruction + +/-- Eliminate one output gap by its prescribed total before dropping the +other rank constraints. This is the exact finite summation step used in +the conditional rank-kernel estimate. -/ +theorem constrained_sum_product_le (r L : ℕ) + (f : Fin (r + 1) → Fin (L + 1) → ℝ) + (hf : ∀ i k, 0 ≤ f i k) (M : ℝ) (hM : 0 ≤ M) + (hbound : ∀ k, f 0 k ≤ M) : + (∑ z : Fin (r + 1) → Fin (L + 1), + if ∑ j, (z j).val = L then ∏ j, f j (z j) else 0) ≤ + M * ∏ i : Fin r, ∑ k, f i.succ k := by + classical + rw [← (Fin.consEquiv (fun _ : Fin (r + 1) => Fin (L + 1))).sum_comp] + rw [Fintype.sum_prod_type, Finset.sum_comm] + have hpoint (z : Fin r → Fin (L + 1)) : + (∑ k : Fin (L + 1), + if k.val + ∑ i, (z i).val = L then f 0 k * ∏ i, f i.succ (z i) else 0) ≤ + M * ∏ i, f i.succ (z i) := by + by_cases hz : ∑ i, (z i).val ≤ L + · let k₀ : Fin (L + 1) := ⟨L - ∑ i, (z i).val, by omega⟩ + have heq (k : Fin (L + 1)) : k.val + ∑ i, (z i).val = L ↔ k = k₀ := by + change _ ↔ k = ⟨L - ∑ i, (z i).val, _⟩ + rw [Fin.ext_iff] + simp only + omega + simp_rw [heq] + rw [Fintype.sum_ite_eq'] + exact mul_le_mul_of_nonneg_right (hbound k₀) (Finset.prod_nonneg fun i _ => hf _ _) + · have heq (k : Fin (L + 1)) : ¬ (k.val + ∑ i, (z i).val = L) := by omega + simp_rw [ite_eq_right (heq _), Finset.sum_const_zero] + exact mul_nonneg hM (Finset.prod_nonneg fun i _ => hf _ _) + calc + _ ≤ ∑ z : Fin r → Fin (L + 1), M * ∏ i, f i.succ (z i) := by + apply Finset.sum_le_sum + intro z _ + simpa only [Fin.consEquiv_apply, Fin.sum_univ_succ, Fin.prod_univ_succ, + Fin.cons_zero, Fin.cons_succ] using hpoint z + _ = _ := by + rw [← Finset.mul_sum, ← Fintype.prod_sum (fun (i : Fin r) (k : Fin (L + 1)) => f i.succ k)] + +/-- The product of two rank kernels has one scalar denominator factor, +one uniform gap factor and independent one-dimensional cross-overlaps. -/ +theorem constrained_cross_kernel_le (r L : ℕ) + (f g : Fin (r + 1) → Fin (L + 1) → ℝ) + (hf : ∀ i k, 0 ≤ f i k) (hg : ∀ i k, 0 ≤ g i k) + (M : ℝ) (hM : 0 ≤ M) (hbound : ∀ k, f 0 k * g 0 k ≤ M) : + (∑ z : Fin (r + 1) → Fin (L + 1), + if ∑ j, (z j).val = L then (∏ j, f j (z j)) * (∏ j, g j (z j)) else 0) ≤ + M * ∏ i : Fin r, ∑ k, f i.succ k * g i.succ k := by + simp_rw [← Finset.prod_mul_distrib] + exact constrained_sum_product_le r L (fun i k => f i k * g i k) + (fun i k => mul_nonneg (hf i k) (hg i k)) M hM hbound + +end TraceReconstruction + +namespace TraceReconstruction + +/-! ## Correlated sibling-anchor estimate + +This is the analytic summation step in the correlated-anchor estimate, subsection +“Summing the correlated anchor kernels”. The common latent draw is kept +inside the joint kernel, so independence of the two displaced locations +is NOT assumed. Conditional independence only factors the two local +kernels for each fixed common draw. All arrays here have finite support; +the integer-jitter application uses a finite interval containing that support. +-/ + +section CorrelatedAnchors + +variable {Ω I J : Type*} [Fintype Ω] [Fintype I] [Fintype J] + +/-- Mixture of conditional products; `p` is the common displacement law. -/ +def jointKernel (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) + (i : I) (j : J) : ℝ := ∑ w, p w * a w i * b w j + +omit [Fintype I] [Fintype J] in +theorem jointKernel_nonneg + (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) + (hp : ∀ w, 0 ≤ p w) (ha : ∀ w i, 0 ≤ a w i) + (hb : ∀ w j, 0 ≤ b w j) (i : I) (j : J) : + 0 ≤ jointKernel p a b i j := by + exact Finset.sum_nonneg fun w _ => mul_nonneg (mul_nonneg (hp w) (ha w i)) (hb w j) + +theorem sum_jointKernel + (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) (L M : ℝ) + (hp : ∑ w, p w = 1) + (ha : ∀ w, ∑ i, a w i = L) (hb : ∀ w, ∑ j, b w j = M) : + ∑ i, ∑ j, jointKernel p a b i j = L * M := by + simp only [jointKernel] + have hcomm (i : I) : + (∑ j : J, ∑ w : Ω, p w * a w i * b w j) = + ∑ w : Ω, ∑ j : J, p w * a w i * b w j := Finset.sum_comm + simp_rw [hcomm] + simp_rw [← Finset.mul_sum, hb] + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul, ← Finset.mul_sum, ha] + rw [← Finset.sum_mul, hp, one_mul] + +omit [Fintype I] [Fintype J] in +theorem jointKernel_le + (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) (A B : ℝ) + (hp : ∀ w, 0 ≤ p w) (ha : ∀ w i, 0 ≤ a w i) + (hB : 0 ≤ B) (hb : ∀ w j, b w j ≤ B) + (hA : ∀ i, ∑ w, p w * a w i ≤ A) (i : I) (j : J) : + jointKernel p a b i j ≤ A * B := by + calc + jointKernel p a b i j ≤ ∑ w, (p w * a w i) * B := by + exact Finset.sum_le_sum fun w _ => + mul_le_mul_of_nonneg_left (hb w j) (mul_nonneg (hp w) (ha w i)) + _ = (∑ w, p w * a w i) * B := (Finset.sum_mul _ _ _).symm + _ ≤ A * B := mul_le_mul_of_nonneg_right (hA i) hB + +/-- The joint squared-sum estimate retaining the common jitter. In the + manuscript A=L/(omega*sqrt(T*t)) and B=M/(omega*sqrt(t)), + up to the explicit absolute binomial constants. -/ +theorem correlated_anchor_square_sum + (p : Ω → ℝ) (a : Ω → I → ℝ) (b : Ω → J → ℝ) + (L M A B : ℝ) + (hp0 : ∀ w, 0 ≤ p w) (hp1 : ∑ w, p w = 1) + (ha0 : ∀ w i, 0 ≤ a w i) (hb0 : ∀ w j, 0 ≤ b w j) + (ha1 : ∀ w, ∑ i, a w i = L) (hb1 : ∀ w, ∑ j, b w j = M) + (hB : 0 ≤ B) (hb : ∀ w j, b w j ≤ B) + (hA : ∀ i, ∑ w, p w * a w i ≤ A) : + ∑ i, ∑ j, (jointKernel p a b i j) ^ 2 ≤ (A * B) * (L * M) := by + calc + ∑ i, ∑ j, (jointKernel p a b i j) ^ 2 ≤ + ∑ i, ∑ j, (A * B) * jointKernel p a b i j := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + have h0 := jointKernel_nonneg p a b hp0 ha0 hb0 i j + have h1 := jointKernel_le p a b A B hp0 ha0 hB hb hA i j + nlinarith + _ = (A * B) * (∑ i, ∑ j, jointKernel p a b i j) := by + simp_rw [← Finset.mul_sum] + _ = (A * B) * (L * M) := by rw [sum_jointKernel p a b L M hp1 ha1 hb1] + +end CorrelatedAnchors + + +end TraceReconstruction + +namespace TraceReconstruction + +/-- Truncating output ranks cannot increase a binomial cross-overlap. -/ +theorem binomial_overlap_truncate (g h L : ℕ) {p : ℝ} + (hp : p ∈ Set.Icc 0 1) : + (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ + ∑ k ∈ Finset.range (h + 1), binomialMass g p k * binomialMass h p k := by + rw [Fin.sum_univ_eq_sum_range (fun k => binomialMass g p k * binomialMass h p k) (L + 1)] + by_cases hL : L ≤ h + · apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono (by omega)) + intro k _ _ + exact mul_nonneg (binomialMass_nonneg g k hp) (binomialMass_nonneg h k hp) + · apply le_of_eq + symm + apply Finset.sum_subset (Finset.range_mono (by omega)) + intro k _ hk + have hhk : h < k := by + simp only [Finset.mem_range, not_lt] at hk + omega + simp [binomialMass, Nat.choose_eq_zero_of_lt hhk] + +/-- Gaussian cross-overlap with the prefactor attached to either prescribed +first length, removing the order restriction in the tilting proof. -/ +theorem binomial_gaussian_overlap_general (g h L : ℕ) {p : ℝ} + (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hS : 0 < g + h) : + (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ + Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) * + Real.exp (-((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h))) := by + have hp0 : 0 < p := by linarith [hp.1] + have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) + by_cases hhg : h ≤ g + · exact (binomial_overlap_truncate g h L ⟨hp0.le, hp.2.le⟩).trans + (binomial_gaussian_overlap g h hp hhg hS) + · have hgh : g ≤ h := by omega + have ho := (binomial_overlap_truncate h g L ⟨hp0.le, hp.2.le⟩).trans + (binomial_gaussian_overlap h g hp hgh (by omega)) + have hb : Real.sqrt (2 / (((h : ℝ) + 1) * p * (1 - p))) ≤ + Real.sqrt (2 / (((g : ℝ) + 1) * p * (1 - p))) := by + apply Real.sqrt_le_sqrt + apply div_le_div_of_nonneg_left (by norm_num) + (by nlinarith only [mul_pos (show (0 : ℝ) < (g : ℝ) + 1 by positivity) hpq]) + have hcast : (g : ℝ) ≤ h := by exact_mod_cast hgh + have ht := mul_le_mul_of_nonneg_right (show (g : ℝ) + 1 ≤ (h : ℝ) + 1 by linarith) hpq.le + nlinarith only [ht] + have heq : -((h : ℝ) - g) ^ 2 / (16 * ((h : ℝ) + g)) = + -((g : ℝ) - h) ^ 2 / (16 * ((g : ℝ) + h)) := by ring + rw [heq] at ho + exact (by simpa only [mul_comm] using ho : + (∑ k : Fin (L + 1), binomialMass g p k * binomialMass h p k) ≤ _).trans + (mul_le_mul_of_nonneg_right hb (Real.exp_nonneg _)) + +/-- The exact conditional rank kernel, including the fixed count +normalization, before any coarse-gap estimates or restrictions. -/ +def rankKernel (r n l : ℕ) (p : ℝ) (g : Fin (r + 1) → ℕ) + (z : Fin (r + 1) → Fin (l + 1)) : ℝ := + if r ≤ l ∧ ∑ j, (z j).val = l - r then + p ^ r / binomialMass n p l * ∏ j, binomialMass (g j) p (z j) else 0 + +/-- Largest-gap elimination for the conditional rank kernel. The displayed +constant is absolute; no asymptotic proposal or Stirling theorem is assumed. -/ +theorem rankKernel_cross_le (r n l : ℕ) {p : ℝ} + (hp : p ∈ Set.Ico (1 / 2 : ℝ) 1) (hl : l ≤ n) + (hmean : (n : ℝ) * p = l) (hv : 1 ≤ (n : ℝ) * p * (1 - p)) + (g h : Fin (r + 1) → ℕ) : + (∑ z : Fin (r + 1) → Fin (l - r + 1), + if ∑ j, (z j).val = l - r then + (p ^ r / binomialMass n p l) ^ 2 * + (∏ j, binomialMass (g j) p (z j)) * + (∏ j, binomialMass (h j) p (z j)) else 0) ≤ + (4608 * n / ((g 0 : ℝ) + 1)) * + ∏ i : Fin r, ∑ k : Fin (l - r + 1), + binomialMass (g i.succ) p k * binomialMass (h i.succ) p k := by + have hp0 : 0 < p := by linarith [hp.1] + have hpq : 0 < p * (1 - p) := mul_pos hp0 (sub_pos.mpr hp.2) + have hden : 0 < ((g 0 : ℝ) + 1) * p * (1 - p) := by + nlinarith only [mul_pos (show (0 : ℝ) < (g 0 : ℝ) + 1 by positivity) hpq] + have hc : (p ^ r / binomialMass n p l) ^ 2 ≤ 144 * ((n : ℝ) * p * (1 - p)) := by + rw [div_eq_mul_inv, mul_pow] + apply (mul_le_mul_of_nonneg_right + (show (p ^ r) ^ 2 ≤ (1 : ℝ) by + exact pow_le_one₀ (pow_nonneg hp0.le _) (pow_le_one₀ hp0.le hp.2.le)) + (sq_nonneg _)).trans + simpa only [one_mul] using binomialMass_mean_inverse_sq n l ⟨hp0, hp.2⟩ hl hmean hv + have hx := constrained_cross_kernel_le r (l - r) + (fun i k => binomialMass (g i) p k) (fun i k => binomialMass (h i) p k) + (fun i k => binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) + (fun i k => binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) + (32 / (((g 0 : ℝ) + 1) * p * (1 - p))) (by positivity) + (fun k => binomial_product_sup (g 0) (h 0) k hp) + have hprod : 0 ≤ ∏ i : Fin r, ∑ k : Fin (l - r + 1), + binomialMass (g i.succ) p k * binomialMass (h i.succ) p k := by + apply Finset.prod_nonneg + intro i _ + exact Finset.sum_nonneg fun k _ => mul_nonneg + (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) + (binomialMass_nonneg _ _ ⟨hp0.le, hp.2.le⟩) + calc + _ = (p ^ r / binomialMass n p l) ^ 2 * + (∑ z : Fin (r + 1) → Fin (l - r + 1), + if ∑ j, (z j).val = l - r then + (∏ j, binomialMass (g j) p (z j)) * + (∏ j, binomialMass (h j) p (z j)) else 0) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro z _ + split_ifs <;> ring + _ ≤ (p ^ r / binomialMass n p l) ^ 2 * + ((32 / (((g 0 : ℝ) + 1) * p * (1 - p))) * _) := + mul_le_mul_of_nonneg_left hx (sq_nonneg _) + _ ≤ (144 * ((n : ℝ) * p * (1 - p))) * + ((32 / (((g 0 : ℝ) + 1) * p * (1 - p))) * _) := + mul_le_mul_of_nonneg_right hc (mul_nonneg (by positivity) hprod) + _ = _ := by + have hq : 1 - p ≠ 0 := ne_of_gt (sub_pos.mpr hp.2) + field_simp + ring + +end TraceReconstruction + +namespace TraceReconstruction +theorem fairSeries_total (n : ℕ) : ∑' z : ℤ, (fairSeries n).coeff z = 1 := by + have h := fairSeries_L1 n + unfold seriesL1 at h + simpa only [abs_of_nonneg (fairSeries_nonneg n _)] using h + +theorem fairSeries_sum_finite_le_one (n : ℕ) (A : Finset ℤ) (c : ℤ) : + ∑ z ∈ A, (fairSeries n).coeff (c-z) ≤ 1 := by + have hs : Summable (fun z : ℤ => (fairSeries n).coeff (c-z)) := by + exact (Equiv.subLeft c).summable_iff.mpr (series_summable (fairSeries n) id rfl) + have hh : (∑' z : ℤ, (fairSeries n).coeff (c-z)) = 1 := by + simpa using ((Equiv.subLeft c).tsum_eq (fun z => (fairSeries n).coeff z)).trans + (fairSeries_total n) + rw [← hh] + exact Summable.sum_le_tsum A (fun _ _ => fairSeries_nonneg n _) hs + +def windowKernel (n L : ℕ) (z : ℤ) : ℝ := + ∑ a ∈ Finset.range L, (fairSeries n).coeff ((a:ℤ)-z) + +theorem windowKernel_nonneg (n L : ℕ) (z : ℤ) : 0 ≤ windowKernel n L z := + Finset.sum_nonneg (fun _ _ => fairSeries_nonneg n _) + +theorem windowKernel_sup (n L : ℕ) (z : ℤ) : + windowKernel n L z ≤ L*binomialBound n := by + calc + _ ≤ ∑ _a ∈ Finset.range L, binomialBound n := by + apply Finset.sum_le_sum + intro a _ + exact (le_abs_self _).trans (fairSeries_coeff_bound n _) + _ = _ := by simp + +theorem windowKernel_sum (n L : ℕ) (A : Finset ℤ) (c : ℤ) : + ∑ z ∈ A, windowKernel n L (z-c) ≤ L := by + unfold windowKernel + rw [Finset.sum_comm] + calc + _ ≤ ∑ _a ∈ Finset.range L, (1:ℝ) := by + apply Finset.sum_le_sum + intro a _ + simpa only [show ∀ z : ℤ, (a:ℤ)-(z-c)=(a:ℤ)+c-z from fun z => by omega] + using fairSeries_sum_finite_le_one n A ((a:ℤ)+c) + _ = _ := by simp + +theorem windowKernel_energy (n L : ℕ) (A : Finset ℤ) (c : ℤ) : + ∑ z ∈ A, windowKernel n L (z-c)^2 ≤ L^2*binomialBound n := by + calc + _ ≤ ∑ z ∈ A, windowKernel n L (z-c)*(L*binomialBound n) := by + apply Finset.sum_le_sum + intro z _ + simpa only [pow_two] using mul_le_mul_of_nonneg_left + (windowKernel_sup n L (z-c)) (windowKernel_nonneg n L (z-c)) + _ = (∑ z ∈ A, windowKernel n L (z-c))*(L*binomialBound n) := by rw [Finset.sum_mul] + _ ≤ L*(L*binomialBound n) := mul_le_mul_of_nonneg_right + (windowKernel_sum n L A c) (by positivity [binomialBound_nonneg n]) + _ = _ := by ring + +def jointWindowKernel (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : ℝ := + ∑ v ∈ (fairSeries g).coeff.support, + (fairSeries g).coeff v * windowKernel n₁ L (z₁+v) * windowKernel n₂ L (z₂+v) + +theorem windowKernel_average (g n L : ℕ) (z : ℤ) : + (∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * windowKernel n L (z+v)) = + windowKernel (g+n) L z := by + unfold windowKernel + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + rw [fairSeries_add, AddMonoidAlgebra.coeff_mul_apply_left, Finsupp.sum] + apply Finset.sum_congr rfl + intro v _ + congr 2 + omega + +theorem jointWindowKernel_nonneg (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : + 0 ≤ jointWindowKernel g n₁ n₂ L z₁ z₂ := by + apply Finset.sum_nonneg + intro v _ + exact mul_nonneg (mul_nonneg (fairSeries_nonneg g v) (windowKernel_nonneg n₁ L _)) + (windowKernel_nonneg n₂ L _) + +theorem jointWindowKernel_sup (g n₁ n₂ L : ℕ) (z₁ z₂ : ℤ) : + jointWindowKernel g n₁ n₂ L z₁ z₂ ≤ L^2*binomialBound g*binomialBound n₂ := by + have hbound : binomialBound (g+n₁) ≤ binomialBound g := by + apply Real.sqrt_le_sqrt + apply div_le_div_of_nonneg_left (by norm_num) (by positivity) + simp only [Nat.cast_add]; linarith [show (0:ℝ) ≤ n₁ by positivity] + calc + _ ≤ ∑ v ∈ (fairSeries g).coeff.support, + (fairSeries g).coeff v * windowKernel n₁ L (z₁+v) * (L*binomialBound n₂) := by + apply Finset.sum_le_sum + intro v _ + exact mul_le_mul_of_nonneg_left (windowKernel_sup n₂ L _) (mul_nonneg + (fairSeries_nonneg g v) (windowKernel_nonneg n₁ L _)) + _ = windowKernel (g+n₁) L z₁ * (L*binomialBound n₂) := by + rw [← Finset.sum_mul, windowKernel_average] + _ ≤ (L*binomialBound g)*(L*binomialBound n₂) := by + apply mul_le_mul_of_nonneg_right _ (mul_nonneg (by positivity) (binomialBound_nonneg n₂)) + exact (windowKernel_sup (g+n₁) L z₁).trans + (mul_le_mul_of_nonneg_left hbound (by positivity)) + _ = _ := by ring + +theorem jointWindowKernel_sum (g n₁ n₂ L : ℕ) (A B : Finset ℤ) (c₁ c₂ : ℤ) : + ∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂) ≤ L^2 := by + unfold jointWindowKernel + simp_rw [Finset.sum_comm (s := B)] + rw [Finset.sum_comm] + calc + _ = ∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * + (∑ z₁ ∈ A, windowKernel n₁ L ((z₁-c₁)+v)) * + (∑ z₂ ∈ B, windowKernel n₂ L ((z₂-c₂)+v)) := by + apply Finset.sum_congr rfl + intro v _ + simp_rw [Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm] + _ ≤ ∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v * (L*L) := by + apply Finset.sum_le_sum + intro v _ + have h1 : (∑ z₁ ∈ A, windowKernel n₁ L ((z₁-c₁)+v)) ≤ L := by + simpa only [show ∀ z : ℤ, (z-c₁)+v = z-(c₁-v) from fun z => by omega] + using windowKernel_sum n₁ L A (c₁-v) + have h2 : (∑ z₂ ∈ B, windowKernel n₂ L ((z₂-c₂)+v)) ≤ L := by + simpa only [show ∀ z : ℤ, (z-c₂)+v = z-(c₂-v) from fun z => by omega] + using windowKernel_sum n₂ L B (c₂-v) + rw [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (fairSeries_nonneg g v) + exact mul_le_mul h1 h2 (Finset.sum_nonneg (fun z _ => windowKernel_nonneg n₂ L _)) (by positivity) + _ = L^2 := by + rw [← Finset.sum_mul] + have ht : (∑ v ∈ (fairSeries g).coeff.support, (fairSeries g).coeff v) = 1 := by + have h := fairSeries_L1 g + rw [seriesL1_eq_sum] at h + simpa only [abs_of_nonneg (fairSeries_nonneg g _)] using h + rw [ht]; ring + +theorem jointWindowKernel_energy (g n₁ n₂ L : ℕ) (A B : Finset ℤ) (c₁ c₂ : ℤ) : + ∑ z₁ ∈ A, ∑ z₂ ∈ B, (jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂))^2 ≤ + L^4*binomialBound g*binomialBound n₂ := by + calc + _ ≤ ∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂) * + (L^2*binomialBound g*binomialBound n₂) := by + apply Finset.sum_le_sum + intro z₁ _ + apply Finset.sum_le_sum + intro z₂ _ + simpa only [pow_two] using mul_le_mul_of_nonneg_left + (jointWindowKernel_sup g n₁ n₂ L _ _) (jointWindowKernel_nonneg g n₁ n₂ L _ _) + _ = (∑ z₁ ∈ A, ∑ z₂ ∈ B, jointWindowKernel g n₁ n₂ L (z₁-c₁) (z₂-c₂)) * + (L^2*binomialBound g*binomialBound n₂) := by simp_rw [Finset.sum_mul] + _ ≤ L^2*(L^2*binomialBound g*binomialBound n₂) := mul_le_mul_of_nonneg_right + (jointWindowKernel_sum g n₁ n₂ L A B c₁ c₂) + (mul_nonneg (mul_nonneg (by positivity) (binomialBound_nonneg g)) (binomialBound_nonneg n₂)) + _ = _ := by ring +end TraceReconstruction + +open Filter +open scoped Topology + + +namespace TraceReconstruction + +/-- Elementary discrete integral comparison, including the singular first cell. -/ +theorem sum_inverse_sqrt (N : ℕ) : + (∑ k ∈ Finset.range N, (Real.sqrt (k+1:ℝ))⁻¹) ≤ 2*Real.sqrt N := by + induction N with + | zero => simp + | succ N ih => + rw [Finset.sum_range_succ] + have hn : 0 ≤ (N:ℝ) := by positivity + have hp : 0 < Real.sqrt (N+1:ℝ) := Real.sqrt_pos.2 (by positivity) + have hs : Real.sqrt (N:ℝ) ≤ Real.sqrt (N+1:ℝ) := Real.sqrt_le_sqrt (by linarith) + have h1 := Real.sq_sqrt hn + have h2 := Real.sq_sqrt (show 0 ≤ (N+1:ℝ) by positivity) + have hstep : (Real.sqrt (N+1:ℝ))⁻¹ ≤ 2*(Real.sqrt (N+1:ℝ)-Real.sqrt N) := by + apply (inv_le_iff_one_le_mul₀ hp).2 + nlinarith [sq_nonneg (Real.sqrt (N+1:ℝ)-Real.sqrt N)] + push_cast + linarith + +theorem exp_gap_lower {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) : + h/2 ≤ 1-Real.exp (-h) := by + have he := Real.add_one_le_exp h + have hp : 0 < Real.exp h := Real.exp_pos h + have hp' : 0 < 1+h := by linarith + have hinv : (Real.exp h)⁻¹ ≤ (1+h)⁻¹ := inv_anti₀ hp' (by simpa [add_comm] using he) + rw [Real.exp_neg] + have hi : (1+h)⁻¹*(1+h)=1 := inv_mul_cancel₀ (ne_of_gt hp') + nlinarith [mul_nonneg hh.le (sub_nonneg.mpr h1)] + +theorem sum_exp_decay {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) (M : ℕ) : + (∑ k ∈ Finset.range M, Real.exp (-h*(k:ℝ))) ≤ 2/h := by + have he : 0 ≤ Real.exp (-h) := (Real.exp_pos _).le + have he1 : Real.exp (-h) < 1 := Real.exp_lt_one_iff.mpr (by linarith) + have hf : (∑ k ∈ Finset.range M, (Real.exp (-h))^k) ≤ (1-Real.exp (-h))⁻¹ := by + rw [inv_eq_one_div, le_div_iff₀ (by linarith : 0 < 1-Real.exp (-h)), geom_sum_mul_neg] + exact sub_le_self _ (pow_nonneg he M) + have hi : (1-Real.exp (-h))⁻¹ ≤ 2/h := by + rw [inv_le_iff_one_le_mul₀ (by linarith : 0<1-Real.exp (-h))] + have hb := exp_gap_lower hh h1 + have := mul_le_mul_of_nonneg_right hb (show 0 ≤ 2/h by positivity) + nlinarith [div_mul_cancel₀ (2:ℝ) hh.ne'] + calc + _ = ∑ k ∈ Finset.range M, (Real.exp (-h))^k := by + apply Finset.sum_congr rfl + intro k _ + rw [← Real.exp_nat_mul] + congr 1 + ring + _ ≤ _ := hf.trans hi + +/-- The uniform lattice Laplace estimate used by the initial-pair construction, with an absolute constant. -/ +theorem coarse_laplace_sum {h : ℝ} (hh : 0 < h) (h1 : h ≤ 1) (M : ℕ) : + (∑ k ∈ Finset.range M, (Real.sqrt (k+1:ℝ))⁻¹ * + Real.exp (-h*(k+1:ℝ))) ≤ 6/Real.sqrt h := by + let N := ⌈1/h⌉₊ + have hN : 1/h ≤ (N:ℝ) := Nat.le_ceil _ + have hNup : (N:ℝ) < 1/h+1 := Nat.ceil_lt_add_one (by positivity) + have hs : 0 < Real.sqrt h := Real.sqrt_pos.2 hh + have hNsqrt : Real.sqrt N ≤ 2/Real.sqrt h := by + have hn : (N:ℝ)*h ≤ 2 := by + have hx := mul_le_mul_of_nonneg_right hNup.le hh.le + have hc : (1/h)*h=1 := div_mul_cancel₀ _ hh.ne' + nlinarith + have hprod : Real.sqrt N * Real.sqrt h ≤ 2 := by + have hsqh := Real.sq_sqrt hh.le + have hsqN := Real.sq_sqrt (show 0≤(N:ℝ) by positivity) + have hnon : 0≤Real.sqrt N*Real.sqrt h := by positivity + nlinarith [sq_nonneg (Real.sqrt N*Real.sqrt h)] + exact (le_div_iff₀ hs).2 hprod + let low := (Finset.range M).filter (fun k => k ¬k + (Real.sqrt (k.val+1:ℝ))⁻¹ * Real.exp (-h*(k.val+1:ℝ)))] + have hc : (6/Real.sqrt h)^r = ∏ _i : Fin r, (6/Real.sqrt h) := by simp [div_pow] + rw [hc] + apply Finset.prod_le_prod₀ + · intros; positivity + · intro i _ + rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => + (Real.sqrt (k+1:ℝ))⁻¹ * Real.exp (-h*(k+1:ℝ))) M] + exact coarse_laplace_sum hh h1 M + +end TraceReconstruction + + +namespace TraceReconstruction + +/-- The degree-series estimate in the common-mass argument, with no asymptotic notation. -/ +theorem degree_series_bound (a : ℝ) (N : ℕ) : + (∑ r ∈ Finset.range N, a^r / (Real.sqrt (r:ℝ))^r)^2 ≤ + 2 * Real.exp (2*a^2) := by + let u (r : ℕ) : ℝ := (Real.sqrt ((1/2:ℝ)^r)) + let v (r : ℕ) : ℝ := (Real.sqrt ((2:ℝ)^r))*a^r/(Real.sqrt (r:ℝ))^r + have huv (r : ℕ) : u r * v r = a^r/(Real.sqrt (r:ℝ))^r := by + unfold u v + have he : Real.sqrt ((1/2:ℝ)^r) * Real.sqrt ((2:ℝ)^r)=1 := by + rw [← Real.sqrt_mul (by positivity), ← mul_pow] + norm_num + calc + _ = (Real.sqrt ((1/2:ℝ)^r) * Real.sqrt ((2:ℝ)^r)) * (a^r/(Real.sqrt (r:ℝ))^r) := by ring + _ = _ := by rw [he, one_mul] + have hu : (∑ r ∈ Finset.range N, (u r)^2) ≤ 2 := by + simp only [u, Real.sq_sqrt (by positivity : 0 ≤ (1/2:ℝ)^_)] + have hg := geom_sum_mul_neg (1/2:ℝ) N + have hp : 0≤(1/2:ℝ)^N := by positivity + linarith + have hv : (∑ r ∈ Finset.range N, (v r)^2) ≤ Real.exp (2*a^2) := by + apply le_trans _ (Real.sum_le_exp_of_nonneg (by positivity) N) + apply Finset.sum_le_sum + intro r _ + have hr : 0 < ((r.factorial):ℝ) := by exact_mod_cast Nat.factorial_pos r + have hrpow : 0 < (r:ℝ)^r := by + cases r with + | zero => norm_num + | succ r => positivity + have hfac : (r.factorial:ℝ) ≤ (r:ℝ)^r := by exact_mod_cast Nat.factorial_le_pow r + have hveq : (v r)^2 = (2*a^2)^r / (r:ℝ)^r := by + unfold v + rw [div_pow, mul_pow, Real.sq_sqrt (by positivity)] + have hd : ((Real.sqrt (r:ℝ))^r)^2=(r:ℝ)^r := by + rw [← pow_mul, mul_comm r 2, pow_mul, Real.sq_sqrt (by positivity)] + rw [hd] + rw [← pow_mul, mul_comm r 2, pow_mul] + ring + rw [hveq] + exact div_le_div_of_nonneg_left (by positivity) hr hfac + have hCS := Finset.sum_mul_sq_le_sq_mul_sq (Finset.range N) u v + simp only [huv] at hCS + exact hCS.trans (mul_le_mul hu hv (by positivity) (by norm_num)) + +end TraceReconstruction + +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Layout.lean b/lean/OAI/Probability/TraceReconstruction/Layout.lean index 1e18b6dba12df82a37fa7de1bfd62fccccdce9ae..1026e5d69cd3de097079dc6e5e6384a759243f5b 100644 --- a/lean/OAI/Probability/TraceReconstruction/Layout.lean +++ b/lean/OAI/Probability/TraceReconstruction/Layout.lean @@ -1,1033 +1,1033 @@ -import OAI.Probability.TraceReconstruction.Shapes - -namespace OAI - -/-! -# Layout - -Multiwindow and paired layouts, coordinate simulations, and literal source types and trees. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Literal unmarked concatenation of fixed windows with separately reported -pure pre/post regions. Counts are in atoms, not surviving trace symbols. -/ -def framedConcat {α : Type*} (e : α) {k : ℕ} - (pre post : Fin k → ℕ) (W : Fin k → List α) : List α := - (List.ofFn (fun i => List.replicate (pre i) e ++ W i ++ - List.replicate (post i) e)).flatten - -theorem framedConcat_succ {α : Type*} (e : α) {k : ℕ} - (pre post : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) : - framedConcat e pre post W = List.replicate (pre 0) e ++ W 0 ++ - List.replicate (post 0) e ++ - framedConcat e (fun i => pre i.succ) (fun i => post i.succ) (fun i => W i.succ) := by - simp [framedConcat,List.ofFn_succ,List.append_assoc] - -/-- Only the first, last, and intervening pure lengths are observable in an -unmarked word. In particular boundaries may jitter across nominal units. -/ -theorem framedConcat_eq_of_gaps {α : Type*} (e : α) (k : ℕ) - (pre post pre' post' : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) - (u u' : ℕ) (hfirst : u+pre 0=u'+pre' 0) - (hgap : ∀i : Fin k, post i.castSucc+pre i.succ=post' i.castSucc+pre' i.succ) - (hlast : post (Fin.last k)=post' (Fin.last k)) : - List.replicate u e ++ framedConcat e pre post W = - List.replicate u' e ++ framedConcat e pre' post' W := by - induction k generalizing u u' with - | zero => - have hl : post 0=post' 0 := hlast - simp only [framedConcat,List.ofFn_succ,List.ofFn_zero,List.flatten_cons, - List.flatten_nil,List.append_nil] - calc - _ = List.replicate (u+pre 0) e ++ W 0 ++ List.replicate (post 0) e := by - simp only [List.replicate_add,List.append_assoc] - _ = List.replicate (u'+pre' 0) e ++ W 0 ++ List.replicate (post' 0) e := by rw [hfirst,hl] - _ = _ := by simp only [List.replicate_add,List.append_assoc] - | succ k ih => - rw [framedConcat_succ e pre post W,framedConcat_succ e pre' post' W] - have ht := ih (fun i => pre i.succ) (fun i => post i.succ) - (fun i => pre' i.succ) (fun i => post' i.succ) (fun i => W i.succ) - (post 0) (post' 0) (hgap 0) (fun i => hgap i.succ) hlast - calc - _ = List.replicate (u+pre 0) e ++ W 0 ++ - (List.replicate (post 0) e ++ framedConcat e - (fun i => pre i.succ) (fun i => post i.succ) (fun i => W i.succ)) := by - simp only [List.replicate_add,List.append_assoc] - _ = List.replicate (u'+pre' 0) e ++ W 0 ++ - (List.replicate (post' 0) e ++ framedConcat e - (fun i => pre' i.succ) (fun i => post' i.succ) (fun i => W i.succ)) := by rw [hfirst,ht] - _ = _ := by simp only [List.replicate_add,List.append_assoc] - -/-- Number of atoms strictly before the indicated padded unit. -/ -def framePrefix {k : ℕ} (pre post : Fin k → ℕ) (len : Fin k → ℕ) (i : ℕ) : ℕ := - ∑j : Fin k, if j.val < i then pre j+len j+post j else 0 - -theorem framePrefix_zero {k : ℕ} (pre post len : Fin k → ℕ) : - framePrefix pre post len 0=0 := by simp [framePrefix] - -theorem framePrefix_step {k : ℕ} (pre post len : Fin k → ℕ) (i : Fin k) : - framePrefix pre post len (i.val+1)=framePrefix pre post len i.val+pre i+len i+post i := by - have he : (fun j : Fin k => if j.val < i.val+1 then pre j+len j+post j else 0)= - fun j => (if j.val < i.val then pre j+len j+post j else 0)+ - (if j=i then pre i+len i+post i else 0) := by - funext j - by_cases h : j=i - · subst j; simp - · have hn : j.val ≠ i.val := fun h' => h (Fin.ext h') - by_cases hlt : j.val < i.val - · simp [hlt,show j.val < i.val+1 by omega,h] - · simp [hlt,show ¬j.val < i.val+1 by omega,h] - simp only [framePrefix,he,Finset.sum_add_distrib,Finset.sum_ite_eq',Finset.mem_univ,ite_true] - omega - -/-- Equal actual starting positions and equal total counts are enough: -there is no requirement that a part coincide with its nominal unit. -/ -theorem framedConcat_eq_of_starts {α : Type*} (e : α) (k : ℕ) - (pre post pre' post' : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) - (hstart : ∀i : Fin (k+1), - framePrefix pre post (fun j => (W j).length) i.val+pre i= - framePrefix pre' post' (fun j => (W j).length) i.val+pre' i) - (htotal : framePrefix pre post (fun j => (W j).length) (k+1)= - framePrefix pre' post' (fun j => (W j).length) (k+1)) : - framedConcat e pre post W=framedConcat e pre' post' W := by - have H := framedConcat_eq_of_gaps e k pre post pre' post' W 0 0 - simp only [List.replicate_zero,List.nil_append] at H - apply H - · simpa only [Fin.val_zero,framePrefix_zero,zero_add] using hstart 0 - · intro i - have h₁ := hstart i.castSucc - have h₂ := hstart i.succ - have h₃ := framePrefix_step pre post (fun j => (W j).length) i.castSucc - have h₄ := framePrefix_step pre' post' (fun j => (W j).length) i.castSucc - simp only [Fin.val_castSucc,Fin.val_succ] at * - omega - · have h₁ := hstart (Fin.last k) - have h₂ := framePrefix_step pre post (fun j => (W j).length) (Fin.last k) - have h₃ := framePrefix_step pre' post' (fun j => (W j).length) (Fin.last k) - simp only [Fin.val_last] at * - omega - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem framePrefix_constant {k : ℕ} (pre post len : Fin k → ℕ) (P i : ℕ) - (hc : ∀j,pre j+len j+post j=P) (hi : i ≤ k) : - framePrefix pre post len i=i*P := by - induction i with - | zero => simp [framePrefix_zero] - | succ i ih => - have h := framePrefix_step pre post len ⟨i,by omega⟩ - have hh := hc ⟨i,by omega⟩ - rw [h,ih (by omega),Nat.add_mul,Nat.one_mul] - omega - -theorem flatten_framedConcat (w : List Bool) {k : ℕ} - (pre post : Fin k → ℕ) (W : Fin k → List (List Bool)) : - (framedConcat w pre post W).flatten= - (List.ofFn (fun i => pureAtomRun w (pre i) ++ (W i).flatten ++ - pureAtomRun w (post i))).flatten := by - rw [framedConcat,List.flatten_flatten,List.map_ofFn] - apply congrArg List.flatten - apply congrArg List.ofFn - funext i - simp [Function.comp_apply,List.flatten_append,pureAtomRun] - -/-- The deterministic multiwindow identity used by the nested simulator. -Every motif is covered by its own window. Predetermined pure-region lengths -may move the boundaries of nominal units; only their exact cumulative counts -are required. Windows and chunks all remain literal unmarked binary words. -/ -theorem template_group_windows (k P T a L : ℕ) (sign : Fin L → Bool) - (w : Bool → List Bool) (τ : Fin (k+1) → Bool) - (t pre post : Fin (k+1) → ℕ) - (hleft : ∀u,t u ≤ a) (hfit : ∀u,a+L ≤ t u+T) - (hunit : ∀u,t u+T ≤ P) - (hstart : ∀u,framePrefix pre post (fun _ => T) u.val+pre u=u.val*P+t u) - (htotal : framePrefix pre post (fun _ => T) (k+1)=(k+1)*P) : - (List.ofFn (fun u => complementaryWords P a L sign w (τ u))).flatten= - (List.ofFn (fun u => pureAtomRun (w false) (pre u) ++ - complementaryWords T (a-t u) L sign w (τ u) ++ - pureAtomRun (w false) (post u))).flatten := by - let W : Fin (k+1) → List (List Bool) := fun u => - List.ofFn (fun i => w (templateType T (a-t u) L sign (τ u) i)) - let z : Fin (k+1) → ℕ := fun u => P-(t u+T) - have hz : ∀u,t u+T+z u=P := by intro u; dsimp [z]; have hu := hunit u; omega - have hlen : ∀u,(W u).length=T := by intro u; simp [W] - have hp : ∀i,i ≤ k+1 → framePrefix t z (fun u => (W u).length) i=i*P := - fun i hi => framePrefix_constant t z _ P i (fun u => by rw [hlen]; exact hz u) hi - have he := framedConcat_eq_of_starts (w false) k t z pre post W - (fun u => by simp only [hlen] at hp ⊢; rw [hp _ (by omega),hstart]) - (by simp only [hlen] at hp ⊢; rw [hp _ le_rfl,htotal]) - have he' := congrArg List.flatten he - rw [flatten_framedConcat,flatten_framedConcat] at he' - calc - _ = (List.ofFn (fun u => pureAtomRun (w false) (t u) ++ (W u).flatten ++ - pureAtomRun (w false) (z u))).flatten := by - congr 1 - apply congrArg List.ofFn - funext u - have hh := template_word_window (t u) T (z u) a L sign (τ u) w (hleft u) (hfit u) - rw [hz] at hh - simpa only [complementaryWords,atomString_constant,W,atomString,List.ofFn_const,pureAtomRun] using hh - _ = _ := he' - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -variable {K : Type*} [Fintype K] - -/-- Counts of literal side chunks, with one deterministic pure filler in - each region. A bundle can contain any even number of paired chunks. -/ -def pairedPreCount {N : ℕ} (left : K → Fin N) (filler : Fin N → ℕ) - (first : K → ℕ) (u : Fin N) : ℕ := - filler u + ∑v, if left v=u then first v else 0 - -def pairedPostCount {N : ℕ} (right : K → Fin N) (filler : Fin N → ℕ) - (reserve first : K → ℕ) (u : Fin N) : ℕ := - filler u + ∑v, if right v=u then 2*reserve v-first v else 0 - -theorem pairedPreCount_cast {N : ℕ} (left : K → Fin N) (filler : Fin N → ℕ) - (reserve first : K → ℕ) (A : ℕ) - (hfill : ∀u,filler u+(∑v,if left v=u then reserve v else 0)=A) (u : Fin N) : - (pairedPreCount left filler first u : ℤ) = A+ - ∑v, if left v=u then (first v:ℤ)-reserve v else 0 := by - have hf : (filler u:ℤ)+(∑v,if left v=u then (reserve v:ℤ) else 0)=A := by - exact_mod_cast hfill u - have he : (∑v,if left v=u then (first v:ℤ)-reserve v else 0)= - (∑v,if left v=u then (first v:ℤ) else 0)- - (∑v,if left v=u then (reserve v:ℤ) else 0) := by - rw [←Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro v _ - split_ifs <;> ring - simp only [pairedPreCount,Nat.cast_add,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero] - rw [he] - omega - -theorem pairedPostCount_cast {N : ℕ} (right : K → Fin N) (filler : Fin N → ℕ) - (reserve first : K → ℕ) (A : ℕ) (hfirst : ∀v,first v ≤ 2*reserve v) - (hfill : ∀u,filler u+(∑v,if right v=u then reserve v else 0)=A) (u : Fin N) : - (pairedPostCount right filler reserve first u : ℤ) = A- - ∑v, if right v=u then (first v:ℤ)-reserve v else 0 := by - have hf : (filler u:ℤ)+(∑v,if right v=u then (reserve v:ℤ) else 0)=A := by - exact_mod_cast hfill u - have he : (∑v,if right v=u then ((2*reserve v-first v:ℕ):ℤ) else 0)= - (∑v,if right v=u then (reserve v:ℤ) else 0)- - (∑v,if right v=u then (first v:ℤ)-reserve v else 0) := by - rw [←Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro v _ - rw [Nat.cast_sub (hfirst v)] - push_cast - split_ifs <;> ring - simp only [pairedPostCount,Nat.cast_add,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero] - rw [he] - omega - -/-- Prefix sum of a delta at a prescribed label, with no loss from replacing - its real finite support by an interval. -/ -theorem fin_prefix_delta {N : ℕ} (a : Fin N) (i : ℕ) (x : ℤ) : - (∑u : Fin N, if u.val < i then (if a=u then x else 0) else 0)= - if a.val < i then x else 0 := by - have he : (fun u : Fin N => if u.val < i then (if a=u then x else 0) else 0)= - fun u => if u=a then (if a.val < i then x else 0) else 0 := by - funext u - by_cases h : u=a - · subst u; simp - · simp [h,Ne.symm h] - rw [he] - simp - -/-- Exact paired-interval contribution to the position of a window. -/ -theorem pair_activity_identity {N : ℕ} (l r u : Fin N) (hlr : l.val ≤ r.val) (x : ℤ) : - (if l.val < u.val then x else 0)-(if r.val < u.val then x else 0)+ - (if l=u then x else 0) = - if l.val ≤ u.val ∧ u.val ≤ r.val then x else 0 := by - by_cases hlu : l.val < u.val - · by_cases hru : r.val < u.val - · simp [hlu,hru,show l≠u by intro h; subst u; omega,show ¬u.val ≤ r.val by omega] - · simp [hlu,hru,show l≠u by intro h; subst u; omega,show l.val ≤ u.val by omega,show u.val ≤ r.val by omega] - · by_cases hlu' : l=u - · subst u; simp [hlr,show ¬r.val < l.val by omega] - · have hn : l.val≠u.val := fun h => hlu' (Fin.ext h) - simp [hlu,hlu',show ¬r.val < u.val by omega,show ¬l.val ≤ u.val by omega] - -/-- Cumulative pure chunk counts have exactly the source's localBits-plus-active- -globalBits jitter. This identity uses the actual chronological pre/post schedule. -/ -theorem pairedLayout_start {N : ℕ} (left right : K → Fin N) - (horder : ∀v,(left v).val ≤ (right v).val) - (fpre fpost : Fin N → ℕ) (reserve first : K → ℕ) - (hfirst : ∀v,first v ≤ 2*reserve v) (A B T : ℕ) - (hpre : ∀u,fpre u+(∑v,if left v=u then reserve v else 0)=A) - (hpost : ∀u,fpost u+(∑v,if right v=u then reserve v else 0)=B) - (u : Fin N) : - ((framePrefix (pairedPreCount left fpre first) - (pairedPostCount right fpost reserve first) (fun _ => T) u.val+ - pairedPreCount left fpre first u : ℕ):ℤ)= - u.val*(A+T+B)+A+ - ∑v, if (left v).val ≤ u.val ∧ u.val ≤ (right v).val then - (first v:ℤ)-reserve v else 0 := by - let d : K → ℤ := fun v => (first v:ℤ)-reserve v - have hpr := pairedPreCount_cast left fpre reserve first A hpre - have hpo := pairedPostCount_cast right fpost reserve first B hfirst hpost - have hsum : (∑j : Fin N, if j.val < u.val then (1:ℤ) else 0)=(u.val:ℤ) := by - have hc := framePrefix_constant (fun _ : Fin N => 0) (fun _ => 0) (fun _ => 1) 1 u.val - (by simp) (by omega) - simpa [framePrefix] using congrArg (fun n : ℕ => (n:ℤ)) hc - simp only [Nat.cast_add,framePrefix,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero,hpr,hpo] - have hex : (∑j : Fin N,if j.val < u.val then - (A+(∑v,if left v=j then d v else 0))+T+ - (B-(∑v,if right v=j then d v else 0)) else 0)= - (u.val:ℤ)*(A+T+B)+ - ∑v,((if (left v).val < u.val then d v else 0)- - (if (right v).val < u.val then d v else 0)) := by - calc - _ = (∑j : Fin N,(if j.val < u.val then (1:ℤ) else 0)*(A+T+B))+ - ∑j : Fin N,∑v, - ((if j.val < u.val then (if left v=j then d v else 0) else 0)- - (if j.val < u.val then (if right v=j then d v else 0) else 0)) := by - rw [←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro j _ - by_cases hj : j.val < u.val - · simp [hj,Finset.sum_sub_distrib]; ring - · simp [hj] - _ = _ := by - rw [←Finset.sum_mul,hsum,Finset.sum_comm] - simp_rw [Finset.sum_sub_distrib,fin_prefix_delta] - change (∑j : Fin N,if j.val < u.val then - (A+(∑v,if left v=j then d v else 0))+T+ - (B-(∑v,if right v=j then d v else 0)) else 0)+ - (A+∑v,if left v=u then d v else 0)=_ - rw [hex] - have he : (∑v,((if (left v).val < u.val then d v else 0)- - (if (right v).val < u.val then d v else 0)))+ - (∑v,if left v=u then d v else 0)= - ∑v,if (left v).val ≤ u.val ∧ u.val ≤ (right v).val then d v else 0 := by - rw [←Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun v _ => pair_activity_identity (left v) (right v) u (horder v) (d v)) - dsimp only [d] at * - linarith only [he] - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -variable {K : Type*} [Fintype K] - -theorem pairedLayout_total {N : ℕ} (left right : K → Fin N) - (fpre fpost : Fin N → ℕ) (reserve first : K → ℕ) - (hfirst : ∀v,first v ≤ 2*reserve v) (A B T : ℕ) - (hpre : ∀u,fpre u+(∑v,if left v=u then reserve v else 0)=A) - (hpost : ∀u,fpost u+(∑v,if right v=u then reserve v else 0)=B) : - framePrefix (pairedPreCount left fpre first) - (pairedPostCount right fpost reserve first) (fun _ => T) N=N*(A+T+B) := by - have hpr := pairedPreCount_cast left fpre reserve first A hpre - have hpo := pairedPostCount_cast right fpost reserve first B hfirst hpost - have he : ∀f : K → Fin N, - (∑u : Fin N,∑v,if f v=u then (first v:ℤ)-reserve v else 0)= - ∑v,((first v:ℤ)-reserve v) := by - intro f - rw [Finset.sum_comm] - simp - apply Nat.cast_injective (R:=ℤ) - simp only [framePrefix,Fin.isLt,ite_true,Nat.cast_sum,Nat.cast_add,hpr,hpo, - Finset.sum_add_distrib,Finset.sum_sub_distrib,he,Finset.sum_const,Finset.card_univ, - Fintype.card_fin,nsmul_eq_mul,Nat.cast_mul] - push_cast - ring - -/-- One localBits bundle at each child, and one globalBits bundle at each vertex in - the first quarter, paired with the reflected last-quarter post region. -/ -abbrev SourceBundle (N : ℕ) := Fin N ⊕ Fin (N/4) - -def sourceBundleLeft (N : ℕ) : SourceBundle N → Fin N - | .inl u => u - | .inr v => ⟨v.val,by have := v.isLt; omega⟩ - -def sourceBundleRight (N : ℕ) : SourceBundle N → Fin N - | .inl u => u - | .inr v => ⟨N-1-v.val,by have := v.isLt; omega⟩ - -theorem sourceBundle_order (N : ℕ) (v : SourceBundle N) : - (sourceBundleLeft N v).val ≤ (sourceBundleRight N v).val := by - cases v with - | inl u => rfl - | inr v => dsimp [sourceBundleLeft,sourceBundleRight]; have := v.isLt; omega - -theorem sum_injective_delta_le {α β : Type*} [Fintype α] [DecidableEq β] - (f : α → β) (hf : Function.Injective f) (u : β) (R : ℕ) : - (∑v,if f v=u then R else 0) ≤ R := by - by_cases h : ∃v,f v=u - · obtain ⟨v,hv⟩ := h - have he : ∀j,f j=u ↔ j=v := fun j => by rw [←hv]; exact hf.eq_iff - simp [he] - · push Not at h - simp [h] - -theorem sourceBundle_reserve_pre (N R : ℕ) (u : Fin N) : - (∑v : SourceBundle N,if sourceBundleLeft N v=u then R else 0) ≤ 2*R := by - rw [Fintype.sum_sum_type] - change (∑v : Fin N, if v=u then R else 0)+(∑v : Fin (N/4), - if (⟨v.val,by have := v.isLt; omega⟩ : Fin N)=u then R else 0) ≤ 2*R - simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] - have h := sum_injective_delta_le - (fun v : Fin (N/4) => (⟨v.val,by have := v.isLt; omega⟩ : Fin N)) - (fun _ _ he => Fin.ext (congrArg (fun z : Fin N => z.val) he)) u R - omega - -theorem sourceBundle_reserve_post (N R : ℕ) (u : Fin N) : - (∑v : SourceBundle N,if sourceBundleRight N v=u then R else 0) ≤ 2*R := by - rw [Fintype.sum_sum_type] - change (∑v : Fin N, if v=u then R else 0)+(∑v : Fin (N/4), - if (⟨N-1-v.val,by have := v.isLt; omega⟩ : Fin N)=u then R else 0) ≤ 2*R - simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] - have hinj : Function.Injective (fun v : Fin (N/4) => - (⟨N-1-v.val,by have := v.isLt; omega⟩ : Fin N)) := by - intro v w he - have hv := v.isLt - have hw := w.isLt - have h := congrArg Fin.val he - apply Fin.ext - dsimp only at h - omega - have h := sum_injective_delta_le _ hinj u R - omega - -def sourceBundleCount (N t h : ℕ) (localBits : Fin N → Fin t → Bool) - (globalBits : Fin ((N/4)*t) → Bool) : SourceBundle N → ℕ - | .inl u => t*h+∑a,bitIndex (localBits u a) - | .inr v => t*h+∑a : Fin t,bitIndex (globalBits (globalTrialIndex N t v a)) - -theorem sourceBundleCount_le (N t h : ℕ) (ht : Even t) - (localBits : Fin N → Fin t → Bool) (globalBits : Fin ((N/4)*t) → Bool) - (v : SourceBundle N) : sourceBundleCount N t h localBits globalBits v ≤ 2*(t*h+t/2) := by - have hh : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) - have hs (b : Fin t → Bool) : (∑a,bitIndex (b a)) ≤ t := by - calc - _ ≤ ∑_a : Fin t,1 := Finset.sum_le_sum (fun a _ => by cases b a <;> norm_num [bitIndex]) - _ = t := by simp - cases v with - | inl u => dsimp [sourceBundleCount]; have := hs (localBits u); omega - | inr v => dsimp [sourceBundleCount]; have := hs (fun a => globalBits (globalTrialIndex N t v a)); omega - -/-- The actual scheduled bits give precisely the arithmetic source displacement - Y=H+V, including its common-globalBits plateau and outer-quarter behavior. -/ -theorem sourceBundle_activity (N t h : ℕ) - (localBits : Fin N → Fin t → Bool) (globalBits : Fin ((N/4)*t) → Bool) (u : Fin N) : - (∑v : SourceBundle N, if (sourceBundleLeft N v).val ≤ u.val ∧ - u.val ≤ (sourceBundleRight N v).val then - (sourceBundleCount N t h localBits globalBits v:ℤ)-(t*h+t/2:ℕ) else 0)= - ((∑a : Fin t,(bitIndex (localBits u a):ℤ))-(t/2:ℕ))+ - scheduledGlobalShift N t globalBits u := by - rw [Fintype.sum_sum_type] - have he : (∑v : Fin N, if v.val ≤ u.val ∧ u.val ≤ v.val then - (sourceBundleCount N t h localBits globalBits (.inl v):ℤ)-(t*h+t/2:ℕ) else 0)= - (∑a : Fin t,(bitIndex (localBits u a):ℤ))-(t/2:ℕ) := by - have hc : ∀v : Fin N,(v.val ≤ u.val ∧ u.val ≤ v.val) ↔ v=u := by - intro v - constructor - · intro hv; exact Fin.ext (le_antisymm hv.1 hv.2) - · intro hv; subst v; exact ⟨le_rfl,le_rfl⟩ - simp only [hc,Finset.sum_ite_eq',Finset.mem_univ,ite_true,sourceBundleCount, - Nat.cast_add,Nat.cast_mul,Nat.cast_sum] - ring - change (∑v : Fin N, if v.val ≤ u.val ∧ u.val ≤ v.val then - (sourceBundleCount N t h localBits globalBits (.inl v):ℤ)-(t*h+t/2:ℕ) else 0)+_=_ - rw [he] - congr 1 - unfold scheduledGlobalShift - apply Finset.sum_congr rfl - intro v _ - have hv := v.isLt - have hu := u.isLt - have hc : (sourceBundleLeft N (.inr v)).val ≤ u.val ∧ - u.val ≤ (sourceBundleRight N (.inr v)).val ↔ v.val ≤ u.val ∧ u.val+v.val < N := by - dsimp [sourceBundleLeft,sourceBundleRight]; omega - simp only [hc] - split_ifs - · simp only [sourceBundleCount,Nat.cast_add,Nat.cast_mul,Nat.cast_sum]; ring - · rfl - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- One-bundle reserved nominal count is integral because the number of - paired trials is even. The actual filler reserves both local and global - bundles when both are present in a region. -/ -def sourceLayoutReserve (t h : ℕ) : ℕ := t*h+t/2 - -def sourcePreFiller (N A t h : ℕ) (u : Fin N) : ℕ := - A-∑v : SourceBundle N,if sourceBundleLeft N v=u then sourceLayoutReserve t h else 0 - -def sourcePostFiller (N B t h : ℕ) (u : Fin N) : ℕ := - B-∑v : SourceBundle N,if sourceBundleRight N v=u then sourceLayoutReserve t h else 0 - -def sourcePreCount (N A t h : ℕ) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) : Fin N → ℕ := - pairedPreCount (sourceBundleLeft N) (sourcePreFiller N A t h) - (sourceBundleCount N t h loc glob) - -def sourcePostCount (N B t h : ℕ) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) : Fin N → ℕ := - pairedPostCount (sourceBundleRight N) (sourcePostFiller N B t h) - (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) - -def sourceDisplacement (N t : ℕ) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : ℤ := - (∑a : Fin t,(bitIndex (loc u a):ℤ))-(t/2:ℕ)+scheduledGlobalShift N t glob u - -def sourceWindowStart (N A t : ℕ) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : ℕ := - ((A:ℤ)+sourceDisplacement N t loc glob u).toNat - -theorem sourcePreFiller_nominal (N A t h : ℕ) - (hA : 2*sourceLayoutReserve t h ≤ A) (u : Fin N) : - sourcePreFiller N A t h u+ - (∑v : SourceBundle N,if sourceBundleLeft N v=u then sourceLayoutReserve t h else 0)=A := by - exact Nat.sub_add_cancel ((sourceBundle_reserve_pre N _ u).trans hA) - -theorem sourcePostFiller_nominal (N B t h : ℕ) - (hB : 2*sourceLayoutReserve t h ≤ B) (u : Fin N) : - sourcePostFiller N B t h u+ - (∑v : SourceBundle N,if sourceBundleRight N v=u then sourceLayoutReserve t h else 0)=B := by - exact Nat.sub_add_cancel ((sourceBundle_reserve_post N _ u).trans hB) - -theorem sourceLayout_exact_start (N A T B t h : ℕ) (ht : Even t) - (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : - ((framePrefix (sourcePreCount N A t h loc glob) (sourcePostCount N B t h loc glob) - (fun _ => T) u.val+sourcePreCount N A t h loc glob u:ℕ):ℤ)= - u.val*(A+T+B)+A+sourceDisplacement N t loc glob u := by - have H := pairedLayout_start (sourceBundleLeft N) (sourceBundleRight N) - (sourceBundle_order N) (sourcePreFiller N A t h) (sourcePostFiller N B t h) - (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) - (sourceBundleCount_le N t h ht loc glob) A B T - (sourcePreFiller_nominal N A t h hA) (sourcePostFiller_nominal N B t h hB) u - simp only [sourceLayoutReserve] at H - rw [sourceBundle_activity] at H - exact H - -theorem sourceLayout_exact_total (N A T B t h : ℕ) (ht : Even t) - (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) : - framePrefix (sourcePreCount N A t h loc glob) (sourcePostCount N B t h loc glob) - (fun _ => T) N=N*(A+T+B) := by - exact pairedLayout_total (sourceBundleLeft N) (sourceBundleRight N) - (sourcePreFiller N A t h) (sourcePostFiller N B t h) - (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) - (sourceBundleCount_le N t h ht loc glob) A B T - (sourcePreFiller_nominal N A t h hA) (sourcePostFiller_nominal N B t h hB) - -/-- The literal surrogate side chunks, after concatenation, are a correct - partition of the actual parent word whenever the windows fit. This is - an equality of unmarked binary strings, not an assumed channel identity. -/ -theorem sourceLayout_literal_partition (k A T B t h a L : ℕ) (ht : Even t) - (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) - (loc : Fin (k+1) → Fin t → Bool) (glob : Fin (((k+1)/4)*t) → Bool) - (sign : Fin L → Bool) (w : Bool → List Bool) (τ : Fin (k+1) → Bool) - (hzero : ∀u,0 ≤ (A:ℤ)+sourceDisplacement (k+1) t loc glob u) - (hleft : ∀u,sourceWindowStart (k+1) A t loc glob u ≤ a) - (hfit : ∀u,a+L ≤ sourceWindowStart (k+1) A t loc glob u+T) - (hunit : ∀u,sourceWindowStart (k+1) A t loc glob u+T ≤ A+T+B) : - (List.ofFn (fun u => complementaryWords (A+T+B) a L sign w (τ u))).flatten= - (List.ofFn (fun u => pureAtomRun (w false) (sourcePreCount (k+1) A t h loc glob u) ++ - complementaryWords T (a-sourceWindowStart (k+1) A t loc glob u) L sign w (τ u) ++ - pureAtomRun (w false) (sourcePostCount (k+1) B t h loc glob u))).flatten := by - apply template_group_windows k (A+T+B) T a L sign w τ - (sourceWindowStart (k+1) A t loc glob) - (sourcePreCount (k+1) A t h loc glob) (sourcePostCount (k+1) B t h loc glob) - hleft hfit hunit - · intro u - apply Nat.cast_injective (R:=ℤ) - rw [sourceLayout_exact_start (k+1) A T B t h ht hA hB] - simp only [Nat.cast_add,Nat.cast_mul,sourceWindowStart,Int.toNat_of_nonneg (hzero u)] - ring - · exact sourceLayout_exact_total (k+1) A T B t h ht hA hB loc glob - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Independent emissions at all literal slots accumulate their actual - approximation errors. The decoders may depend on the fixed slot ID. -/ -theorem coordinateProduct_approximates {α : Type*} [Fintype α] - {n : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) (P : Fin n → FiniteLaw α) - (f : Fin n → α → List Bool) (w : Fin n → List Bool) (E : Fin n → ℝ) - (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : - ApproximatesTrace q (FiniteLaw.coordinateProduct P) - (fun x => coordinateWord (fun i => f i (x i))) (coordinateWord w) (∑i,E i) := by - induction n with - | zero => - intro F hF - change |(FiniteLaw.coordinateProduct P).expect (fun _ => F [])-F []|≤∑i : Fin 0,E i - simp only [FiniteLaw.expect_const,sub_self,abs_zero,Finset.univ_eq_empty,Finset.sum_empty,le_refl] - | succ n ih => - intro F hF - have ht := ih (fun i => P i.succ) (fun i => f i.succ) - (fun i => w i.succ) (fun i => E i.succ) (fun i => h i.succ) - have hh := ApproximatesTrace.append hq (h 0) ht F hF - rw [FiniteLaw.expect_prod] at hh - rw [FiniteLaw.expect_coordinateProduct_succ,coordinateWord_succ,Fin.sum_univ_succ] - have he (a : α) (x : Fin n → α) : - coordinateWord (fun i => f i ((Fin.cons a x : Fin (n+1) → α) i))= - f 0 a++coordinateWord (fun i => f i.succ (x i)) := by - rw [coordinateWord_succ] - simp only [Fin.cons_zero,Fin.cons_succ] - simp_rw [he] - exact hh - -namespace FiniteLaw -variable {ι κ α : Type*} [Fintype ι] [Fintype κ] [Fintype α] - -/-- Independent emissions indexed by the actual token IDs of the layout. -/ -def indexedProduct (P : ι → FiniteLaw α) : FiniteLaw (ι → α) where - mass x := ∏i,(P i).mass (x i) - nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg _) - total := by - rw [←Fintype.prod_sum] - simp only [(P _).total,Finset.prod_const_one] - -/-- Reorder independent emissions by the literal chronological slot order. -The order is a bijection, so no output is duplicated or silently discarded. -/ -theorem indexedProduct_expect_equiv (P : ι → FiniteLaw α) (e : κ ≃ ι) - (F : (ι → α) → ℝ) : - (indexedProduct P).expect F=(indexedProduct (fun j => P (e j))).expect - (fun x => F (fun i => x (e.symm i))) := by - let E : (κ → α) ≃ (ι → α) := - { toFun := fun x i => x (e.symm i) - invFun := fun x j => x (e j) - left_inv := fun x => by funext j; simp - right_inv := fun x => by funext i; simp } - unfold expect indexedProduct - rw [←E.sum_comp] - apply Finset.sum_congr rfl - intro x _ - change (∏i,(P i).mass (x (e.symm i)))*F (fun i => x (e.symm i))=_ - congr 1 - rw [←e.prod_comp] - simp only [Equiv.symm_apply_apply] - -theorem indexedProduct_map (P : ι → FiniteLaw α) {β : Type*} [Fintype β] - (f : ι → α → β) : - (indexedProduct P).map (fun x i => f i (x i))= - indexedProduct (fun i => (P i).map (f i)) := by - apply FiniteLaw.ext - funext y - rw [map_mass] - change (∑x : ι → α,if (fun i => f i (x i))=y then ∏i,(P i).mass (x i) else 0)=_ - simp only [indexedProduct,map_mass] - rw [Fintype.prod_sum] - apply Finset.sum_congr rfl - intro x _ - by_cases he : (fun i => f i (x i))=y - · rw [ite_eq_left he] - exact Finset.prod_congr rfl (fun i _ => (ite_eq_left (congrFun he i)).symm) - · rw [ite_eq_right he] - symm - have hi : ∃i,f i (x i)≠y i := by - by_contra h - push Not at h - exact he (funext h) - obtain ⟨i,hi⟩ := hi - exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) - -end FiniteLaw - -/-- An arbitrarily indexed actual layout has the same unconditional trace - guarantee after its fixed, public chronological ordering is applied. -/ -theorem indexedProduct_approximates {ι α : Type*} [Fintype ι] [Fintype α] - {n : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) (e : Fin n ≃ ι) - (P : ι → FiniteLaw α) (f : ι → α → List Bool) (w : ι → List Bool) (E : ι → ℝ) - (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : - ApproximatesTrace q (FiniteLaw.indexedProduct P) - (fun x => coordinateWord (fun j => f (e j) (x (e j)))) - (coordinateWord (fun j => w (e j))) (∑i,E i) := by - intro F hF - rw [FiniteLaw.indexedProduct_expect_equiv P e] - simp only [Equiv.symm_apply_apply] - have H := coordinateProduct_approximates hq (fun j => P (e j)) - (fun j => f (e j)) (fun j => w (e j)) (fun j => E (e j)) (fun j => h (e j)) F hF - rw [e.sum_comp] at H - simp only [FiniteLaw.expect,FiniteLaw.indexedProduct,FiniteLaw.coordinateProduct] at H ⊢ - convert H using 1 - congr 3 - ext x - simp - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The Boolean representation of the source Prouhet signs; true denotes - a negative type. No sign convention is changed in passing to literal words. -/ -def boolTypeSign (b : Bool) : ℝ := if b then -1 else 1 - -def prouhetBool (s : ℕ) (i : Fin (2^s)) : Bool := - decide ((prouhetSeries s).coeff (i.val:ℤ)= -1) - -theorem boolTypeSign_injective : Function.Injective boolTypeSign := by - intro a b h - cases a <;> cases b <;> norm_num [boolTypeSign] at * - -theorem boolTypeSign_template (s P a : ℕ) (τ : Bool) (i : Fin P) : - boolTypeSign (templateType P a (2^s) (prouhetBool s) τ i)= - motifChildSign s (a:ℤ) i.val (boolTypeSign τ) := by - by_cases hi : a ≤ i.val ∧ i.val < a+2^s - · have hz : 0 ≤ (i.val:ℤ)-a ∧ (i.val:ℤ)-a < (2^s:ℕ) := by omega - have he : ((i.val-a:ℕ):ℤ)=(i.val:ℤ)-a := by omega - have hc := (abs_eq (by norm_num : (0:ℝ)≤1)).mp - ((prouhetSeries_coeff_spec s).2 _ hz.1 hz.2) - have hχ : motifIndicator s ((i.val:ℤ)-a)=1 := by simp only [motifIndicator,ite_eq_left hz] - rcases hc with hc | hc <;> cases τ <;> - norm_num [templateType,hi,prouhetBool,he,boolTypeSign,motifChildSign,hχ,hc] - · have hz : ¬(0 ≤ (i.val:ℤ)-a ∧ (i.val:ℤ)-a < (2^s:ℕ)) := by omega - have hc : (prouhetSeries s).coeff ((i.val:ℤ)-a)=0 := - (prouhetSeries_coeff_spec s).1 _ (by omega) - have hχ : motifIndicator s ((i.val:ℤ)-a)=0 := by simp only [motifIndicator,ite_eq_right hz] - simp [templateType,hi,boolTypeSign,motifChildSign,hχ,hc] - -theorem sourceWindowStart_cast_of_fit (N P T t : ℕ) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (u : Fin N) - (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : - (sourceWindowStart N ((P-T)/2) t loc glob u:ℤ)= - (((P-T)/2:ℕ):ℤ)+sourceDisplacement N t loc glob u := by - apply Int.toNat_of_nonneg - have hy := abs_le.mp hY - omega - -/-- A zero-based centered version of the floor-fit calculation. -/ -theorem sourceWindowStart_fit (N P T t L : ℕ) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) - (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : - sourceWindowStart N ((P-T)/2) t loc glob u+T ≤ P ∧ - sourceWindowStart N ((P-T)/2) t loc glob u ≤ P/2 ∧ - P/2+L ≤ sourceWindowStart N ((P-T)/2) t loc glob u+T := - centered_window_floor_fit P T L _ _ hP hT heven hL hY - (sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY) - -/-- The zero-based centered translated anchor, including both half-trial corrections. -/ -theorem sourceWindowStart_anchor (N P T t L : ℕ) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) - (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : - ((P/2-sourceWindowStart N ((P-T)/2) t loc glob u:ℕ):ℤ)= - (T/2:ℕ)+(t/2:ℕ)-(∑a : Fin t,(bitIndex (loc u a):ℤ))- - scheduledGlobalShift N t glob u := by - have hfit := sourceWindowStart_fit N P T t L loc glob hP hT heven hL u hY - have hc := sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY - have ha := centered_window_floor_anchor P T (by omega) heven - have hA : (P-T)/2 ≤ P/2 := Nat.div_le_div_right (Nat.sub_le P T) - have ha' : ((P/2:ℕ):ℤ)-((P-T)/2:ℕ)=(T/2:ℕ) := by omega - rw [Nat.cast_sub hfit.2.1,hc] - dsimp only [sourceDisplacement] - linarith only [ha'] - -/-- The manuscript numbers motif slots from one. Thus its actual zero-based - onset is P/2-1, not P/2. The strict margins include this endpoint correction. -/ -theorem sourceWindowStart_oneBased_fit (N P T t L : ℕ) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) - (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : - sourceWindowStart N ((P-T)/2) t loc glob u+T ≤ P ∧ - sourceWindowStart N ((P-T)/2) t loc glob u ≤ P/2-1 ∧ - P/2-1+L ≤ sourceWindowStart N ((P-T)/2) t loc glob u+T := by - have hc := sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY - have ha := centered_window_floor_anchor P T (by omega) heven - have hy := abs_le.mp hY - omega - -/-- The exact source anchor in zero-based coordinates. The minus one is - forced by the one-based motif-label convention. -/ -theorem sourceWindowStart_oneBased_anchor (N P T t L : ℕ) - (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) - (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : - ((P/2-1-sourceWindowStart N ((P-T)/2) t loc glob u:ℕ):ℤ)= - (T/2:ℕ)-1+(t/2:ℕ)-(∑a : Fin t,(bitIndex (loc u a):ℤ))- - scheduledGlobalShift N t glob u := by - have hf := sourceWindowStart_oneBased_fit N P T t L loc glob hP hT heven hL u hY - have ha := sourceWindowStart_anchor N P T t L loc glob hP hT heven hL u hY - omega - -/-- The actual recursively substituted source block words. Indices in P - are shifted down by one, but physical binary strings are unchanged. -/ -def sourceBlockWord (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) : ℕ → Bool → List Bool - | 0 => atom - | j+1 => complementaryWords (P j) (P j/2-1) (2^s) (prouhetBool s) - (sourceBlockWord s P atom j) - -def sourceBlockLength (P : ℕ → ℕ) (S : ℕ) : ℕ → ℕ - | 0 => S - | j+1 => P j*sourceBlockLength P S j - -theorem sourceBlockWord_length (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) (S : ℕ) - (hw : ∀τ,(atom τ).length=S) (j : ℕ) (τ : Bool) : - (sourceBlockWord s P atom j τ).length=sourceBlockLength P S j := by - induction j generalizing τ with - | zero => exact hw τ - | succ j ih => exact complementaryWords_length _ _ _ _ _ _ (fun τ => ih τ) τ - -theorem sourceBlockWord_injective (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) (S : ℕ) - (hw : ∀τ,(atom τ).length=S) (hinj : Function.Injective atom) (j : ℕ) - (hP : ∀k exact hinj - | succ j ih => - apply complementaryWords_injective _ _ _ (sourceBlockLength P S j) - _ _ (sourceBlockWord_length s P atom S hw j) - · exact ih (fun k hk => hP k (by omega)) - · positivity - · have h := hP j (Nat.lt_succ_self j); omega - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Total Boolean type, also on failed layouts; no conditioning is hidden - in the definition. -/ -def integerTemplateType (N s : ℕ) (X : ℤ) (τ : Bool) (u : Fin N) : Bool := - decide (motifChildSign s X u.val (boolTypeSign τ)= -1) - -theorem boolTypeSign_integerTemplate (N s : ℕ) (X : ℤ) (τ : Bool) (u : Fin N) : - boolTypeSign (integerTemplateType N s X τ u)=motifChildSign s X u.val (boolTypeSign τ) := by - have hτ : IsTypeSign (boolTypeSign τ) := by cases τ <;> norm_num [IsTypeSign,boolTypeSign] - rcases motifChildSign_isSign s X u.val hτ with h | h <;> - (simp only [integerTemplateType,h]; norm_num [boolTypeSign]) - -theorem integerTemplateType_nat (N s a : ℕ) (τ : Bool) : - integerTemplateType N s (a:ℤ) τ=templateType N a (2^s) (prouhetBool s) τ := by - funext u - apply boolTypeSign_injective - rw [boolTypeSign_integerTemplate,boolTypeSign_template] - -/-- Global trials at a parent use its children's local-trial count. This - fixes the index shift between source level labels and zero-based arrays. -/ -def sourceScheduledTrials (T n : ℕ → ℕ) : ℕ → ℕ - | 0 => 0 - | b+1 => (T (b+1)/4)*n b - -def sourceScheduledShift (T n : ℕ → ℕ) : - (b : ℕ) → (Fin (sourceScheduledTrials T n b) → Bool) → Fin (T b) → ℤ - | 0, _, _ => 0 - | b+1, glob, u => scheduledGlobalShift (T (b+1)) (n b) glob u - -def sourceLocalCenter (T n : ℕ → ℕ) (b : ℕ) : ℤ := - (T b/2:ℕ)-1+(n b/2:ℕ) - -def sourceNodeAnchor (T n : ℕ → ℕ) (center : ℕ → ℤ) (b : ℕ) - (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (incoming : ℤ) : ℤ := - center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming - -/-- All actual leaf Booleans on the complete deterministic window tree. -/ -def sourceTreeLeafBool (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) : - (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → WindowLeaf T b → Bool - | 0, _, _, τ, _ => τ - | b+1, bits, incoming, τ, v => - sourceTreeLeafBool T n s center b (bits.2.2 v.1) - (sourceScheduledShift T n b bits.2.1 v.1) - (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ v.1) v.2 - -theorem sourceTreeLeafBool_sign (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) - (incoming : ℤ) (τ : Bool) (v : WindowLeaf T b) : - boolTypeSign (sourceTreeLeafBool T n s center b bits incoming τ v)= - sourceTreeLeafSign T n (sourceScheduledTrials T n) s center - (sourceScheduledShift T n) b bits incoming (boolTypeSign τ) v := by - induction b generalizing incoming τ with - | zero => rfl - | succ b ih => - change boolTypeSign (sourceTreeLeafBool T n s center b _ _ _ v.2)=_ - rw [ih,boolTypeSign_integerTemplate] - rfl - -def sourceNominalPre (P T : ℕ → ℕ) (b : ℕ) : ℕ := (P b-T b)/2 -def sourceNominalPost (P T : ℕ → ℕ) (b : ℕ) : ℕ := P b-T b-sourceNominalPre P T b - -theorem sourceNominal_total (P T : ℕ → ℕ) (b : ℕ) (h : T b ≤ P b) : - sourceNominalPre P T b+T b+sourceNominalPost P T b=P b := by - dsimp [sourceNominalPre,sourceNominalPost] - omega - -/-- The actual center before recursively cutting its pure side regions. -/ -def sourceCenterWord (s : ℕ) (P T n : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : - (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool - | 0, _, _, τ => atom τ - | b+1, bits, incoming, τ => atomString (T b) (sourceBlockWord s P atom b) - (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ) - -/-- The unconditional literal surrogate partition: local and common-global - pairs contribute their real selected pure lengths, on every bit assignment. -/ -def sourceTreeWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : - (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool - | 0, _, _, τ => atom τ - | 1, bits, incoming, τ => sourceCenterWord s P T n center atom 1 bits incoming τ - | b+2, bits, incoming, τ => - let loc := fun u => (bits.2.2 u).1 - let glob := bits.2.1 - coordinateWord (fun u : Fin (T (b+1)) => - pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) (sourceNominalPre P T b) (n b) (h b) loc glob u) ++ - sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) - (sourceScheduledShift T n (b+1) glob u) - (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) - (sourcePostCount (T (b+1)) (sourceNominalPost P T b) (n b) (h b) loc glob u)) - -/-- The actual fit event uses a joint test of all displacements. It does not - assert independence and will only be charged probabilistically afterwards. -/ -def SourceTreeFit (T n : ℕ → ℕ) : - (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → Prop - | 0, _ => True - | 1, _ => True - | b+2, bits => - (∀u, |8*sourceDisplacement (T (b+1)) (n b) (fun v => (bits.2.2 v).1) bits.2.1 u| ≤ (T b:ℤ)) ∧ - ∀u, SourceTreeFit T n (b+1) (bits.2.2 u) - -/-- Numerical layout conditions from the source. These contain no word or - statistical conclusions, only the genuine integer margins. -/ -structure SourceLayoutMargins (s : ℕ) (P T n h : ℕ → ℕ) (b : ℕ) : Prop where - positive : ∀j intro j hj - · exact H.positive j (lt_of_lt_of_le hj hc) - · exact H.large j (lt_of_lt_of_le hj hc) - · exact H.even_window j (lt_of_lt_of_le hj hc) - · exact H.ambient j (lt_of_lt_of_le hj hc) - · exact H.motif j (lt_of_lt_of_le hj hc) - · exact H.even_trials j (lt_of_lt_of_le hj hc) - · exact H.pre_reserve j (lt_of_lt_of_le hj hc) - · exact H.post_reserve j (lt_of_lt_of_le hj hc) - -/-- Every recursively cut surrogate center is literally the actual center on - the joint fit event. The source type assignment is retained at all leaves. -/ -theorem sourceTreeWord_eq_center (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) - (atom : Bool → List Bool) (b : ℕ) (H : SourceLayoutMargins s P T n h b) - (hc : ∀j, j+1 rfl - | one => rfl - | more b ih₁ ih₂ => - change (Fin (n (b+1)) → Bool) × (Fin ((T (b+1)/4)*n b) → Bool) × - (Fin (T (b+1)) → WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) at bits - let loc : Fin (T (b+1)) → Fin (n b) → Bool := fun u => (bits.2.2 u).1 - let glob := bits.2.1 - let a := P b/2-1 - let A := sourceNominalPre P T b - let B := sourceNominalPost P T b - let start := sourceWindowStart (T (b+1)) A (n b) loc glob - let θ := integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ - have hb : b hc j (by omega)) _ _ _ (hfit.2 u)] - simp only [sourceCenterWord,hx,integerTemplateType_nat,complementaryWords] - have hstartnonneg (u : Fin (T (b+1))) : 0≤(A:ℤ)+sourceDisplacement (T (b+1)) (n b) loc glob u := by - have he := sourceWindowStart_cast_of_fit (T (b+1)) (P b) (T b) (n b) loc glob - (H.ambient b hb) (H.large b hb) u (hfit.1 u) - have hn : (0:ℤ)≤(start u:ℕ) := Int.natCast_nonneg _ - change (start u:ℤ)=(A:ℤ)+_ at he - omega - have hp := H.positive (b+1) (by omega) - obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : T (b+1)≠0) - have hpart : (List.ofFn (fun u => complementaryWords (P b) a (2^s) (prouhetBool s) - (sourceBlockWord s P atom b) (θ u))).flatten= - coordinateWord (fun u => pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by - have hh := sourceLayout_literal_partition k A (T b) B (n b) (h b) a (2^s) - have hk' : k+1=T (b+1) := hk.symm - rw [hk'] at hh - rw [show A+T b+B=P b from htotal] at hh - exact hh (H.even_trials b hb) (H.pre_reserve b hb) (H.post_reserve b hb) loc glob - (prouhetBool s) (sourceBlockWord s P atom b) θ hstartnonneg - (fun u => (hf u).2.1) (fun u => (hf u).2.2) (fun u => (hf u).1) - change coordinateWord (fun u : Fin (T (b+1)) => - pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) - (sourceScheduledShift T n (b+1) glob u) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u))= - atomString (T (b+1)) (sourceBlockWord s P atom (b+1)) θ - calc - _ = coordinateWord (fun u : Fin (T (b+1)) => - pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by - apply congrArg coordinateWord - funext u - exact congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ w ++ - pureAtomRun (sourceBlockWord s P atom b false) - (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) (hchild u) - _ = _ := hpart.symm - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Shapes + +namespace OAI + +/-! +# Layout + +Multiwindow and paired layouts, coordinate simulations, and literal source types and trees. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Literal unmarked concatenation of fixed windows with separately reported +pure pre/post regions. Counts are in atoms, not surviving trace symbols. -/ +def framedConcat {α : Type*} (e : α) {k : ℕ} + (pre post : Fin k → ℕ) (W : Fin k → List α) : List α := + (List.ofFn (fun i => List.replicate (pre i) e ++ W i ++ + List.replicate (post i) e)).flatten + +theorem framedConcat_succ {α : Type*} (e : α) {k : ℕ} + (pre post : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) : + framedConcat e pre post W = List.replicate (pre 0) e ++ W 0 ++ + List.replicate (post 0) e ++ + framedConcat e (fun i => pre i.succ) (fun i => post i.succ) (fun i => W i.succ) := by + simp [framedConcat,List.ofFn_succ,List.append_assoc] + +/-- Only the first, last, and intervening pure lengths are observable in an +unmarked word. In particular boundaries may jitter across nominal units. -/ +theorem framedConcat_eq_of_gaps {α : Type*} (e : α) (k : ℕ) + (pre post pre' post' : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) + (u u' : ℕ) (hfirst : u+pre 0=u'+pre' 0) + (hgap : ∀i : Fin k, post i.castSucc+pre i.succ=post' i.castSucc+pre' i.succ) + (hlast : post (Fin.last k)=post' (Fin.last k)) : + List.replicate u e ++ framedConcat e pre post W = + List.replicate u' e ++ framedConcat e pre' post' W := by + induction k generalizing u u' with + | zero => + have hl : post 0=post' 0 := hlast + simp only [framedConcat,List.ofFn_succ,List.ofFn_zero,List.flatten_cons, + List.flatten_nil,List.append_nil] + calc + _ = List.replicate (u+pre 0) e ++ W 0 ++ List.replicate (post 0) e := by + simp only [List.replicate_add,List.append_assoc] + _ = List.replicate (u'+pre' 0) e ++ W 0 ++ List.replicate (post' 0) e := by rw [hfirst,hl] + _ = _ := by simp only [List.replicate_add,List.append_assoc] + | succ k ih => + rw [framedConcat_succ e pre post W,framedConcat_succ e pre' post' W] + have ht := ih (fun i => pre i.succ) (fun i => post i.succ) + (fun i => pre' i.succ) (fun i => post' i.succ) (fun i => W i.succ) + (post 0) (post' 0) (hgap 0) (fun i => hgap i.succ) hlast + calc + _ = List.replicate (u+pre 0) e ++ W 0 ++ + (List.replicate (post 0) e ++ framedConcat e + (fun i => pre i.succ) (fun i => post i.succ) (fun i => W i.succ)) := by + simp only [List.replicate_add,List.append_assoc] + _ = List.replicate (u'+pre' 0) e ++ W 0 ++ + (List.replicate (post' 0) e ++ framedConcat e + (fun i => pre' i.succ) (fun i => post' i.succ) (fun i => W i.succ)) := by rw [hfirst,ht] + _ = _ := by simp only [List.replicate_add,List.append_assoc] + +/-- Number of atoms strictly before the indicated padded unit. -/ +def framePrefix {k : ℕ} (pre post : Fin k → ℕ) (len : Fin k → ℕ) (i : ℕ) : ℕ := + ∑j : Fin k, if j.val < i then pre j+len j+post j else 0 + +theorem framePrefix_zero {k : ℕ} (pre post len : Fin k → ℕ) : + framePrefix pre post len 0=0 := by simp [framePrefix] + +theorem framePrefix_step {k : ℕ} (pre post len : Fin k → ℕ) (i : Fin k) : + framePrefix pre post len (i.val+1)=framePrefix pre post len i.val+pre i+len i+post i := by + have he : (fun j : Fin k => if j.val < i.val+1 then pre j+len j+post j else 0)= + fun j => (if j.val < i.val then pre j+len j+post j else 0)+ + (if j=i then pre i+len i+post i else 0) := by + funext j + by_cases h : j=i + · subst j; simp + · have hn : j.val ≠ i.val := fun h' => h (Fin.ext h') + by_cases hlt : j.val < i.val + · simp [hlt,show j.val < i.val+1 by omega,h] + · simp [hlt,show ¬j.val < i.val+1 by omega,h] + simp only [framePrefix,he,Finset.sum_add_distrib,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + omega + +/-- Equal actual starting positions and equal total counts are enough: +there is no requirement that a part coincide with its nominal unit. -/ +theorem framedConcat_eq_of_starts {α : Type*} (e : α) (k : ℕ) + (pre post pre' post' : Fin (k+1) → ℕ) (W : Fin (k+1) → List α) + (hstart : ∀i : Fin (k+1), + framePrefix pre post (fun j => (W j).length) i.val+pre i= + framePrefix pre' post' (fun j => (W j).length) i.val+pre' i) + (htotal : framePrefix pre post (fun j => (W j).length) (k+1)= + framePrefix pre' post' (fun j => (W j).length) (k+1)) : + framedConcat e pre post W=framedConcat e pre' post' W := by + have H := framedConcat_eq_of_gaps e k pre post pre' post' W 0 0 + simp only [List.replicate_zero,List.nil_append] at H + apply H + · simpa only [Fin.val_zero,framePrefix_zero,zero_add] using hstart 0 + · intro i + have h₁ := hstart i.castSucc + have h₂ := hstart i.succ + have h₃ := framePrefix_step pre post (fun j => (W j).length) i.castSucc + have h₄ := framePrefix_step pre' post' (fun j => (W j).length) i.castSucc + simp only [Fin.val_castSucc,Fin.val_succ] at * + omega + · have h₁ := hstart (Fin.last k) + have h₂ := framePrefix_step pre post (fun j => (W j).length) (Fin.last k) + have h₃ := framePrefix_step pre' post' (fun j => (W j).length) (Fin.last k) + simp only [Fin.val_last] at * + omega + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem framePrefix_constant {k : ℕ} (pre post len : Fin k → ℕ) (P i : ℕ) + (hc : ∀j,pre j+len j+post j=P) (hi : i ≤ k) : + framePrefix pre post len i=i*P := by + induction i with + | zero => simp [framePrefix_zero] + | succ i ih => + have h := framePrefix_step pre post len ⟨i,by omega⟩ + have hh := hc ⟨i,by omega⟩ + rw [h,ih (by omega),Nat.add_mul,Nat.one_mul] + omega + +theorem flatten_framedConcat (w : List Bool) {k : ℕ} + (pre post : Fin k → ℕ) (W : Fin k → List (List Bool)) : + (framedConcat w pre post W).flatten= + (List.ofFn (fun i => pureAtomRun w (pre i) ++ (W i).flatten ++ + pureAtomRun w (post i))).flatten := by + rw [framedConcat,List.flatten_flatten,List.map_ofFn] + apply congrArg List.flatten + apply congrArg List.ofFn + funext i + simp [Function.comp_apply,List.flatten_append,pureAtomRun] + +/-- The deterministic multiwindow identity used by the nested simulator. +Every motif is covered by its own window. Predetermined pure-region lengths +may move the boundaries of nominal units; only their exact cumulative counts +are required. Windows and chunks all remain literal unmarked binary words. -/ +theorem template_group_windows (k P T a L : ℕ) (sign : Fin L → Bool) + (w : Bool → List Bool) (τ : Fin (k+1) → Bool) + (t pre post : Fin (k+1) → ℕ) + (hleft : ∀u,t u ≤ a) (hfit : ∀u,a+L ≤ t u+T) + (hunit : ∀u,t u+T ≤ P) + (hstart : ∀u,framePrefix pre post (fun _ => T) u.val+pre u=u.val*P+t u) + (htotal : framePrefix pre post (fun _ => T) (k+1)=(k+1)*P) : + (List.ofFn (fun u => complementaryWords P a L sign w (τ u))).flatten= + (List.ofFn (fun u => pureAtomRun (w false) (pre u) ++ + complementaryWords T (a-t u) L sign w (τ u) ++ + pureAtomRun (w false) (post u))).flatten := by + let W : Fin (k+1) → List (List Bool) := fun u => + List.ofFn (fun i => w (templateType T (a-t u) L sign (τ u) i)) + let z : Fin (k+1) → ℕ := fun u => P-(t u+T) + have hz : ∀u,t u+T+z u=P := by intro u; dsimp [z]; have hu := hunit u; omega + have hlen : ∀u,(W u).length=T := by intro u; simp [W] + have hp : ∀i,i ≤ k+1 → framePrefix t z (fun u => (W u).length) i=i*P := + fun i hi => framePrefix_constant t z _ P i (fun u => by rw [hlen]; exact hz u) hi + have he := framedConcat_eq_of_starts (w false) k t z pre post W + (fun u => by simp only [hlen] at hp ⊢; rw [hp _ (by omega),hstart]) + (by simp only [hlen] at hp ⊢; rw [hp _ le_rfl,htotal]) + have he' := congrArg List.flatten he + rw [flatten_framedConcat,flatten_framedConcat] at he' + calc + _ = (List.ofFn (fun u => pureAtomRun (w false) (t u) ++ (W u).flatten ++ + pureAtomRun (w false) (z u))).flatten := by + congr 1 + apply congrArg List.ofFn + funext u + have hh := template_word_window (t u) T (z u) a L sign (τ u) w (hleft u) (hfit u) + rw [hz] at hh + simpa only [complementaryWords,atomString_constant,W,atomString,List.ofFn_const,pureAtomRun] using hh + _ = _ := he' + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +variable {K : Type*} [Fintype K] + +/-- Counts of literal side chunks, with one deterministic pure filler in + each region. A bundle can contain any even number of paired chunks. -/ +def pairedPreCount {N : ℕ} (left : K → Fin N) (filler : Fin N → ℕ) + (first : K → ℕ) (u : Fin N) : ℕ := + filler u + ∑v, if left v=u then first v else 0 + +def pairedPostCount {N : ℕ} (right : K → Fin N) (filler : Fin N → ℕ) + (reserve first : K → ℕ) (u : Fin N) : ℕ := + filler u + ∑v, if right v=u then 2*reserve v-first v else 0 + +theorem pairedPreCount_cast {N : ℕ} (left : K → Fin N) (filler : Fin N → ℕ) + (reserve first : K → ℕ) (A : ℕ) + (hfill : ∀u,filler u+(∑v,if left v=u then reserve v else 0)=A) (u : Fin N) : + (pairedPreCount left filler first u : ℤ) = A+ + ∑v, if left v=u then (first v:ℤ)-reserve v else 0 := by + have hf : (filler u:ℤ)+(∑v,if left v=u then (reserve v:ℤ) else 0)=A := by + exact_mod_cast hfill u + have he : (∑v,if left v=u then (first v:ℤ)-reserve v else 0)= + (∑v,if left v=u then (first v:ℤ) else 0)- + (∑v,if left v=u then (reserve v:ℤ) else 0) := by + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro v _ + split_ifs <;> ring + simp only [pairedPreCount,Nat.cast_add,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero] + rw [he] + omega + +theorem pairedPostCount_cast {N : ℕ} (right : K → Fin N) (filler : Fin N → ℕ) + (reserve first : K → ℕ) (A : ℕ) (hfirst : ∀v,first v ≤ 2*reserve v) + (hfill : ∀u,filler u+(∑v,if right v=u then reserve v else 0)=A) (u : Fin N) : + (pairedPostCount right filler reserve first u : ℤ) = A- + ∑v, if right v=u then (first v:ℤ)-reserve v else 0 := by + have hf : (filler u:ℤ)+(∑v,if right v=u then (reserve v:ℤ) else 0)=A := by + exact_mod_cast hfill u + have he : (∑v,if right v=u then ((2*reserve v-first v:ℕ):ℤ) else 0)= + (∑v,if right v=u then (reserve v:ℤ) else 0)- + (∑v,if right v=u then (first v:ℤ)-reserve v else 0) := by + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro v _ + rw [Nat.cast_sub (hfirst v)] + push_cast + split_ifs <;> ring + simp only [pairedPostCount,Nat.cast_add,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero] + rw [he] + omega + +/-- Prefix sum of a delta at a prescribed label, with no loss from replacing + its real finite support by an interval. -/ +theorem fin_prefix_delta {N : ℕ} (a : Fin N) (i : ℕ) (x : ℤ) : + (∑u : Fin N, if u.val < i then (if a=u then x else 0) else 0)= + if a.val < i then x else 0 := by + have he : (fun u : Fin N => if u.val < i then (if a=u then x else 0) else 0)= + fun u => if u=a then (if a.val < i then x else 0) else 0 := by + funext u + by_cases h : u=a + · subst u; simp + · simp [h,Ne.symm h] + rw [he] + simp + +/-- Exact paired-interval contribution to the position of a window. -/ +theorem pair_activity_identity {N : ℕ} (l r u : Fin N) (hlr : l.val ≤ r.val) (x : ℤ) : + (if l.val < u.val then x else 0)-(if r.val < u.val then x else 0)+ + (if l=u then x else 0) = + if l.val ≤ u.val ∧ u.val ≤ r.val then x else 0 := by + by_cases hlu : l.val < u.val + · by_cases hru : r.val < u.val + · simp [hlu,hru,show l≠u by intro h; subst u; omega,show ¬u.val ≤ r.val by omega] + · simp [hlu,hru,show l≠u by intro h; subst u; omega,show l.val ≤ u.val by omega,show u.val ≤ r.val by omega] + · by_cases hlu' : l=u + · subst u; simp [hlr,show ¬r.val < l.val by omega] + · have hn : l.val≠u.val := fun h => hlu' (Fin.ext h) + simp [hlu,hlu',show ¬r.val < u.val by omega,show ¬l.val ≤ u.val by omega] + +/-- Cumulative pure chunk counts have exactly the source's localBits-plus-active- +globalBits jitter. This identity uses the actual chronological pre/post schedule. -/ +theorem pairedLayout_start {N : ℕ} (left right : K → Fin N) + (horder : ∀v,(left v).val ≤ (right v).val) + (fpre fpost : Fin N → ℕ) (reserve first : K → ℕ) + (hfirst : ∀v,first v ≤ 2*reserve v) (A B T : ℕ) + (hpre : ∀u,fpre u+(∑v,if left v=u then reserve v else 0)=A) + (hpost : ∀u,fpost u+(∑v,if right v=u then reserve v else 0)=B) + (u : Fin N) : + ((framePrefix (pairedPreCount left fpre first) + (pairedPostCount right fpost reserve first) (fun _ => T) u.val+ + pairedPreCount left fpre first u : ℕ):ℤ)= + u.val*(A+T+B)+A+ + ∑v, if (left v).val ≤ u.val ∧ u.val ≤ (right v).val then + (first v:ℤ)-reserve v else 0 := by + let d : K → ℤ := fun v => (first v:ℤ)-reserve v + have hpr := pairedPreCount_cast left fpre reserve first A hpre + have hpo := pairedPostCount_cast right fpost reserve first B hfirst hpost + have hsum : (∑j : Fin N, if j.val < u.val then (1:ℤ) else 0)=(u.val:ℤ) := by + have hc := framePrefix_constant (fun _ : Fin N => 0) (fun _ => 0) (fun _ => 1) 1 u.val + (by simp) (by omega) + simpa [framePrefix] using congrArg (fun n : ℕ => (n:ℤ)) hc + simp only [Nat.cast_add,framePrefix,Nat.cast_sum,Nat.cast_ite,Nat.cast_zero,hpr,hpo] + have hex : (∑j : Fin N,if j.val < u.val then + (A+(∑v,if left v=j then d v else 0))+T+ + (B-(∑v,if right v=j then d v else 0)) else 0)= + (u.val:ℤ)*(A+T+B)+ + ∑v,((if (left v).val < u.val then d v else 0)- + (if (right v).val < u.val then d v else 0)) := by + calc + _ = (∑j : Fin N,(if j.val < u.val then (1:ℤ) else 0)*(A+T+B))+ + ∑j : Fin N,∑v, + ((if j.val < u.val then (if left v=j then d v else 0) else 0)- + (if j.val < u.val then (if right v=j then d v else 0) else 0)) := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + by_cases hj : j.val < u.val + · simp [hj,Finset.sum_sub_distrib]; ring + · simp [hj] + _ = _ := by + rw [←Finset.sum_mul,hsum,Finset.sum_comm] + simp_rw [Finset.sum_sub_distrib,fin_prefix_delta] + change (∑j : Fin N,if j.val < u.val then + (A+(∑v,if left v=j then d v else 0))+T+ + (B-(∑v,if right v=j then d v else 0)) else 0)+ + (A+∑v,if left v=u then d v else 0)=_ + rw [hex] + have he : (∑v,((if (left v).val < u.val then d v else 0)- + (if (right v).val < u.val then d v else 0)))+ + (∑v,if left v=u then d v else 0)= + ∑v,if (left v).val ≤ u.val ∧ u.val ≤ (right v).val then d v else 0 := by + rw [←Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun v _ => pair_activity_identity (left v) (right v) u (horder v) (d v)) + dsimp only [d] at * + linarith only [he] + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +variable {K : Type*} [Fintype K] + +theorem pairedLayout_total {N : ℕ} (left right : K → Fin N) + (fpre fpost : Fin N → ℕ) (reserve first : K → ℕ) + (hfirst : ∀v,first v ≤ 2*reserve v) (A B T : ℕ) + (hpre : ∀u,fpre u+(∑v,if left v=u then reserve v else 0)=A) + (hpost : ∀u,fpost u+(∑v,if right v=u then reserve v else 0)=B) : + framePrefix (pairedPreCount left fpre first) + (pairedPostCount right fpost reserve first) (fun _ => T) N=N*(A+T+B) := by + have hpr := pairedPreCount_cast left fpre reserve first A hpre + have hpo := pairedPostCount_cast right fpost reserve first B hfirst hpost + have he : ∀f : K → Fin N, + (∑u : Fin N,∑v,if f v=u then (first v:ℤ)-reserve v else 0)= + ∑v,((first v:ℤ)-reserve v) := by + intro f + rw [Finset.sum_comm] + simp + apply Nat.cast_injective (R:=ℤ) + simp only [framePrefix,Fin.isLt,ite_true,Nat.cast_sum,Nat.cast_add,hpr,hpo, + Finset.sum_add_distrib,Finset.sum_sub_distrib,he,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul,Nat.cast_mul] + push_cast + ring + +/-- One localBits bundle at each child, and one globalBits bundle at each vertex in + the first quarter, paired with the reflected last-quarter post region. -/ +abbrev SourceBundle (N : ℕ) := Fin N ⊕ Fin (N/4) + +def sourceBundleLeft (N : ℕ) : SourceBundle N → Fin N + | .inl u => u + | .inr v => ⟨v.val,by have := v.isLt; omega⟩ + +def sourceBundleRight (N : ℕ) : SourceBundle N → Fin N + | .inl u => u + | .inr v => ⟨N-1-v.val,by have := v.isLt; omega⟩ + +theorem sourceBundle_order (N : ℕ) (v : SourceBundle N) : + (sourceBundleLeft N v).val ≤ (sourceBundleRight N v).val := by + cases v with + | inl u => rfl + | inr v => dsimp [sourceBundleLeft,sourceBundleRight]; have := v.isLt; omega + +theorem sum_injective_delta_le {α β : Type*} [Fintype α] [DecidableEq β] + (f : α → β) (hf : Function.Injective f) (u : β) (R : ℕ) : + (∑v,if f v=u then R else 0) ≤ R := by + by_cases h : ∃v,f v=u + · obtain ⟨v,hv⟩ := h + have he : ∀j,f j=u ↔ j=v := fun j => by rw [←hv]; exact hf.eq_iff + simp [he] + · push Not at h + simp [h] + +theorem sourceBundle_reserve_pre (N R : ℕ) (u : Fin N) : + (∑v : SourceBundle N,if sourceBundleLeft N v=u then R else 0) ≤ 2*R := by + rw [Fintype.sum_sum_type] + change (∑v : Fin N, if v=u then R else 0)+(∑v : Fin (N/4), + if (⟨v.val,by have := v.isLt; omega⟩ : Fin N)=u then R else 0) ≤ 2*R + simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] + have h := sum_injective_delta_le + (fun v : Fin (N/4) => (⟨v.val,by have := v.isLt; omega⟩ : Fin N)) + (fun _ _ he => Fin.ext (congrArg (fun z : Fin N => z.val) he)) u R + omega + +theorem sourceBundle_reserve_post (N R : ℕ) (u : Fin N) : + (∑v : SourceBundle N,if sourceBundleRight N v=u then R else 0) ≤ 2*R := by + rw [Fintype.sum_sum_type] + change (∑v : Fin N, if v=u then R else 0)+(∑v : Fin (N/4), + if (⟨N-1-v.val,by have := v.isLt; omega⟩ : Fin N)=u then R else 0) ≤ 2*R + simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] + have hinj : Function.Injective (fun v : Fin (N/4) => + (⟨N-1-v.val,by have := v.isLt; omega⟩ : Fin N)) := by + intro v w he + have hv := v.isLt + have hw := w.isLt + have h := congrArg Fin.val he + apply Fin.ext + dsimp only at h + omega + have h := sum_injective_delta_le _ hinj u R + omega + +def sourceBundleCount (N t h : ℕ) (localBits : Fin N → Fin t → Bool) + (globalBits : Fin ((N/4)*t) → Bool) : SourceBundle N → ℕ + | .inl u => t*h+∑a,bitIndex (localBits u a) + | .inr v => t*h+∑a : Fin t,bitIndex (globalBits (globalTrialIndex N t v a)) + +theorem sourceBundleCount_le (N t h : ℕ) (ht : Even t) + (localBits : Fin N → Fin t → Bool) (globalBits : Fin ((N/4)*t) → Bool) + (v : SourceBundle N) : sourceBundleCount N t h localBits globalBits v ≤ 2*(t*h+t/2) := by + have hh : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) + have hs (b : Fin t → Bool) : (∑a,bitIndex (b a)) ≤ t := by + calc + _ ≤ ∑_a : Fin t,1 := Finset.sum_le_sum (fun a _ => by cases b a <;> norm_num [bitIndex]) + _ = t := by simp + cases v with + | inl u => dsimp [sourceBundleCount]; have := hs (localBits u); omega + | inr v => dsimp [sourceBundleCount]; have := hs (fun a => globalBits (globalTrialIndex N t v a)); omega + +/-- The actual scheduled bits give precisely the arithmetic source displacement + Y=H+V, including its common-globalBits plateau and outer-quarter behavior. -/ +theorem sourceBundle_activity (N t h : ℕ) + (localBits : Fin N → Fin t → Bool) (globalBits : Fin ((N/4)*t) → Bool) (u : Fin N) : + (∑v : SourceBundle N, if (sourceBundleLeft N v).val ≤ u.val ∧ + u.val ≤ (sourceBundleRight N v).val then + (sourceBundleCount N t h localBits globalBits v:ℤ)-(t*h+t/2:ℕ) else 0)= + ((∑a : Fin t,(bitIndex (localBits u a):ℤ))-(t/2:ℕ))+ + scheduledGlobalShift N t globalBits u := by + rw [Fintype.sum_sum_type] + have he : (∑v : Fin N, if v.val ≤ u.val ∧ u.val ≤ v.val then + (sourceBundleCount N t h localBits globalBits (.inl v):ℤ)-(t*h+t/2:ℕ) else 0)= + (∑a : Fin t,(bitIndex (localBits u a):ℤ))-(t/2:ℕ) := by + have hc : ∀v : Fin N,(v.val ≤ u.val ∧ u.val ≤ v.val) ↔ v=u := by + intro v + constructor + · intro hv; exact Fin.ext (le_antisymm hv.1 hv.2) + · intro hv; subst v; exact ⟨le_rfl,le_rfl⟩ + simp only [hc,Finset.sum_ite_eq',Finset.mem_univ,ite_true,sourceBundleCount, + Nat.cast_add,Nat.cast_mul,Nat.cast_sum] + ring + change (∑v : Fin N, if v.val ≤ u.val ∧ u.val ≤ v.val then + (sourceBundleCount N t h localBits globalBits (.inl v):ℤ)-(t*h+t/2:ℕ) else 0)+_=_ + rw [he] + congr 1 + unfold scheduledGlobalShift + apply Finset.sum_congr rfl + intro v _ + have hv := v.isLt + have hu := u.isLt + have hc : (sourceBundleLeft N (.inr v)).val ≤ u.val ∧ + u.val ≤ (sourceBundleRight N (.inr v)).val ↔ v.val ≤ u.val ∧ u.val+v.val < N := by + dsimp [sourceBundleLeft,sourceBundleRight]; omega + simp only [hc] + split_ifs + · simp only [sourceBundleCount,Nat.cast_add,Nat.cast_mul,Nat.cast_sum]; ring + · rfl + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- One-bundle reserved nominal count is integral because the number of + paired trials is even. The actual filler reserves both local and global + bundles when both are present in a region. -/ +def sourceLayoutReserve (t h : ℕ) : ℕ := t*h+t/2 + +def sourcePreFiller (N A t h : ℕ) (u : Fin N) : ℕ := + A-∑v : SourceBundle N,if sourceBundleLeft N v=u then sourceLayoutReserve t h else 0 + +def sourcePostFiller (N B t h : ℕ) (u : Fin N) : ℕ := + B-∑v : SourceBundle N,if sourceBundleRight N v=u then sourceLayoutReserve t h else 0 + +def sourcePreCount (N A t h : ℕ) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) : Fin N → ℕ := + pairedPreCount (sourceBundleLeft N) (sourcePreFiller N A t h) + (sourceBundleCount N t h loc glob) + +def sourcePostCount (N B t h : ℕ) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) : Fin N → ℕ := + pairedPostCount (sourceBundleRight N) (sourcePostFiller N B t h) + (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) + +def sourceDisplacement (N t : ℕ) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : ℤ := + (∑a : Fin t,(bitIndex (loc u a):ℤ))-(t/2:ℕ)+scheduledGlobalShift N t glob u + +def sourceWindowStart (N A t : ℕ) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : ℕ := + ((A:ℤ)+sourceDisplacement N t loc glob u).toNat + +theorem sourcePreFiller_nominal (N A t h : ℕ) + (hA : 2*sourceLayoutReserve t h ≤ A) (u : Fin N) : + sourcePreFiller N A t h u+ + (∑v : SourceBundle N,if sourceBundleLeft N v=u then sourceLayoutReserve t h else 0)=A := by + exact Nat.sub_add_cancel ((sourceBundle_reserve_pre N _ u).trans hA) + +theorem sourcePostFiller_nominal (N B t h : ℕ) + (hB : 2*sourceLayoutReserve t h ≤ B) (u : Fin N) : + sourcePostFiller N B t h u+ + (∑v : SourceBundle N,if sourceBundleRight N v=u then sourceLayoutReserve t h else 0)=B := by + exact Nat.sub_add_cancel ((sourceBundle_reserve_post N _ u).trans hB) + +theorem sourceLayout_exact_start (N A T B t h : ℕ) (ht : Even t) + (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : + ((framePrefix (sourcePreCount N A t h loc glob) (sourcePostCount N B t h loc glob) + (fun _ => T) u.val+sourcePreCount N A t h loc glob u:ℕ):ℤ)= + u.val*(A+T+B)+A+sourceDisplacement N t loc glob u := by + have H := pairedLayout_start (sourceBundleLeft N) (sourceBundleRight N) + (sourceBundle_order N) (sourcePreFiller N A t h) (sourcePostFiller N B t h) + (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) + (sourceBundleCount_le N t h ht loc glob) A B T + (sourcePreFiller_nominal N A t h hA) (sourcePostFiller_nominal N B t h hB) u + simp only [sourceLayoutReserve] at H + rw [sourceBundle_activity] at H + exact H + +theorem sourceLayout_exact_total (N A T B t h : ℕ) (ht : Even t) + (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) : + framePrefix (sourcePreCount N A t h loc glob) (sourcePostCount N B t h loc glob) + (fun _ => T) N=N*(A+T+B) := by + exact pairedLayout_total (sourceBundleLeft N) (sourceBundleRight N) + (sourcePreFiller N A t h) (sourcePostFiller N B t h) + (fun _ => sourceLayoutReserve t h) (sourceBundleCount N t h loc glob) + (sourceBundleCount_le N t h ht loc glob) A B T + (sourcePreFiller_nominal N A t h hA) (sourcePostFiller_nominal N B t h hB) + +/-- The literal surrogate side chunks, after concatenation, are a correct + partition of the actual parent word whenever the windows fit. This is + an equality of unmarked binary strings, not an assumed channel identity. -/ +theorem sourceLayout_literal_partition (k A T B t h a L : ℕ) (ht : Even t) + (hA : 2*sourceLayoutReserve t h ≤ A) (hB : 2*sourceLayoutReserve t h ≤ B) + (loc : Fin (k+1) → Fin t → Bool) (glob : Fin (((k+1)/4)*t) → Bool) + (sign : Fin L → Bool) (w : Bool → List Bool) (τ : Fin (k+1) → Bool) + (hzero : ∀u,0 ≤ (A:ℤ)+sourceDisplacement (k+1) t loc glob u) + (hleft : ∀u,sourceWindowStart (k+1) A t loc glob u ≤ a) + (hfit : ∀u,a+L ≤ sourceWindowStart (k+1) A t loc glob u+T) + (hunit : ∀u,sourceWindowStart (k+1) A t loc glob u+T ≤ A+T+B) : + (List.ofFn (fun u => complementaryWords (A+T+B) a L sign w (τ u))).flatten= + (List.ofFn (fun u => pureAtomRun (w false) (sourcePreCount (k+1) A t h loc glob u) ++ + complementaryWords T (a-sourceWindowStart (k+1) A t loc glob u) L sign w (τ u) ++ + pureAtomRun (w false) (sourcePostCount (k+1) B t h loc glob u))).flatten := by + apply template_group_windows k (A+T+B) T a L sign w τ + (sourceWindowStart (k+1) A t loc glob) + (sourcePreCount (k+1) A t h loc glob) (sourcePostCount (k+1) B t h loc glob) + hleft hfit hunit + · intro u + apply Nat.cast_injective (R:=ℤ) + rw [sourceLayout_exact_start (k+1) A T B t h ht hA hB] + simp only [Nat.cast_add,Nat.cast_mul,sourceWindowStart,Int.toNat_of_nonneg (hzero u)] + ring + · exact sourceLayout_exact_total (k+1) A T B t h ht hA hB loc glob + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Independent emissions at all literal slots accumulate their actual + approximation errors. The decoders may depend on the fixed slot ID. -/ +theorem coordinateProduct_approximates {α : Type*} [Fintype α] + {n : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) (P : Fin n → FiniteLaw α) + (f : Fin n → α → List Bool) (w : Fin n → List Bool) (E : Fin n → ℝ) + (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : + ApproximatesTrace q (FiniteLaw.coordinateProduct P) + (fun x => coordinateWord (fun i => f i (x i))) (coordinateWord w) (∑i,E i) := by + induction n with + | zero => + intro F hF + change |(FiniteLaw.coordinateProduct P).expect (fun _ => F [])-F []|≤∑i : Fin 0,E i + simp only [FiniteLaw.expect_const,sub_self,abs_zero,Finset.univ_eq_empty,Finset.sum_empty,le_refl] + | succ n ih => + intro F hF + have ht := ih (fun i => P i.succ) (fun i => f i.succ) + (fun i => w i.succ) (fun i => E i.succ) (fun i => h i.succ) + have hh := ApproximatesTrace.append hq (h 0) ht F hF + rw [FiniteLaw.expect_prod] at hh + rw [FiniteLaw.expect_coordinateProduct_succ,coordinateWord_succ,Fin.sum_univ_succ] + have he (a : α) (x : Fin n → α) : + coordinateWord (fun i => f i ((Fin.cons a x : Fin (n+1) → α) i))= + f 0 a++coordinateWord (fun i => f i.succ (x i)) := by + rw [coordinateWord_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + simp_rw [he] + exact hh + +namespace FiniteLaw +variable {ι κ α : Type*} [Fintype ι] [Fintype κ] [Fintype α] + +/-- Independent emissions indexed by the actual token IDs of the layout. -/ +def indexedProduct (P : ι → FiniteLaw α) : FiniteLaw (ι → α) where + mass x := ∏i,(P i).mass (x i) + nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg _) + total := by + rw [←Fintype.prod_sum] + simp only [(P _).total,Finset.prod_const_one] + +/-- Reorder independent emissions by the literal chronological slot order. +The order is a bijection, so no output is duplicated or silently discarded. -/ +theorem indexedProduct_expect_equiv (P : ι → FiniteLaw α) (e : κ ≃ ι) + (F : (ι → α) → ℝ) : + (indexedProduct P).expect F=(indexedProduct (fun j => P (e j))).expect + (fun x => F (fun i => x (e.symm i))) := by + let E : (κ → α) ≃ (ι → α) := + { toFun := fun x i => x (e.symm i) + invFun := fun x j => x (e j) + left_inv := fun x => by funext j; simp + right_inv := fun x => by funext i; simp } + unfold expect indexedProduct + rw [←E.sum_comp] + apply Finset.sum_congr rfl + intro x _ + change (∏i,(P i).mass (x (e.symm i)))*F (fun i => x (e.symm i))=_ + congr 1 + rw [←e.prod_comp] + simp only [Equiv.symm_apply_apply] + +theorem indexedProduct_map (P : ι → FiniteLaw α) {β : Type*} [Fintype β] + (f : ι → α → β) : + (indexedProduct P).map (fun x i => f i (x i))= + indexedProduct (fun i => (P i).map (f i)) := by + apply FiniteLaw.ext + funext y + rw [map_mass] + change (∑x : ι → α,if (fun i => f i (x i))=y then ∏i,(P i).mass (x i) else 0)=_ + simp only [indexedProduct,map_mass] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro x _ + by_cases he : (fun i => f i (x i))=y + · rw [ite_eq_left he] + exact Finset.prod_congr rfl (fun i _ => (ite_eq_left (congrFun he i)).symm) + · rw [ite_eq_right he] + symm + have hi : ∃i,f i (x i)≠y i := by + by_contra h + push Not at h + exact he (funext h) + obtain ⟨i,hi⟩ := hi + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +end FiniteLaw + +/-- An arbitrarily indexed actual layout has the same unconditional trace + guarantee after its fixed, public chronological ordering is applied. -/ +theorem indexedProduct_approximates {ι α : Type*} [Fintype ι] [Fintype α] + {n : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) (e : Fin n ≃ ι) + (P : ι → FiniteLaw α) (f : ι → α → List Bool) (w : ι → List Bool) (E : ι → ℝ) + (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : + ApproximatesTrace q (FiniteLaw.indexedProduct P) + (fun x => coordinateWord (fun j => f (e j) (x (e j)))) + (coordinateWord (fun j => w (e j))) (∑i,E i) := by + intro F hF + rw [FiniteLaw.indexedProduct_expect_equiv P e] + simp only [Equiv.symm_apply_apply] + have H := coordinateProduct_approximates hq (fun j => P (e j)) + (fun j => f (e j)) (fun j => w (e j)) (fun j => E (e j)) (fun j => h (e j)) F hF + rw [e.sum_comp] at H + simp only [FiniteLaw.expect,FiniteLaw.indexedProduct,FiniteLaw.coordinateProduct] at H ⊢ + convert H using 1 + congr 3 + ext x + simp + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The Boolean representation of the source Prouhet signs; true denotes + a negative type. No sign convention is changed in passing to literal words. -/ +def boolTypeSign (b : Bool) : ℝ := if b then -1 else 1 + +def prouhetBool (s : ℕ) (i : Fin (2^s)) : Bool := + decide ((prouhetSeries s).coeff (i.val:ℤ)= -1) + +theorem boolTypeSign_injective : Function.Injective boolTypeSign := by + intro a b h + cases a <;> cases b <;> norm_num [boolTypeSign] at * + +theorem boolTypeSign_template (s P a : ℕ) (τ : Bool) (i : Fin P) : + boolTypeSign (templateType P a (2^s) (prouhetBool s) τ i)= + motifChildSign s (a:ℤ) i.val (boolTypeSign τ) := by + by_cases hi : a ≤ i.val ∧ i.val < a+2^s + · have hz : 0 ≤ (i.val:ℤ)-a ∧ (i.val:ℤ)-a < (2^s:ℕ) := by omega + have he : ((i.val-a:ℕ):ℤ)=(i.val:ℤ)-a := by omega + have hc := (abs_eq (by norm_num : (0:ℝ)≤1)).mp + ((prouhetSeries_coeff_spec s).2 _ hz.1 hz.2) + have hχ : motifIndicator s ((i.val:ℤ)-a)=1 := by simp only [motifIndicator,ite_eq_left hz] + rcases hc with hc | hc <;> cases τ <;> + norm_num [templateType,hi,prouhetBool,he,boolTypeSign,motifChildSign,hχ,hc] + · have hz : ¬(0 ≤ (i.val:ℤ)-a ∧ (i.val:ℤ)-a < (2^s:ℕ)) := by omega + have hc : (prouhetSeries s).coeff ((i.val:ℤ)-a)=0 := + (prouhetSeries_coeff_spec s).1 _ (by omega) + have hχ : motifIndicator s ((i.val:ℤ)-a)=0 := by simp only [motifIndicator,ite_eq_right hz] + simp [templateType,hi,boolTypeSign,motifChildSign,hχ,hc] + +theorem sourceWindowStart_cast_of_fit (N P T t : ℕ) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (u : Fin N) + (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : + (sourceWindowStart N ((P-T)/2) t loc glob u:ℤ)= + (((P-T)/2:ℕ):ℤ)+sourceDisplacement N t loc glob u := by + apply Int.toNat_of_nonneg + have hy := abs_le.mp hY + omega + +/-- A zero-based centered version of the floor-fit calculation. -/ +theorem sourceWindowStart_fit (N P T t L : ℕ) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) + (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : + sourceWindowStart N ((P-T)/2) t loc glob u+T ≤ P ∧ + sourceWindowStart N ((P-T)/2) t loc glob u ≤ P/2 ∧ + P/2+L ≤ sourceWindowStart N ((P-T)/2) t loc glob u+T := + centered_window_floor_fit P T L _ _ hP hT heven hL hY + (sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY) + +/-- The zero-based centered translated anchor, including both half-trial corrections. -/ +theorem sourceWindowStart_anchor (N P T t L : ℕ) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) + (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : + ((P/2-sourceWindowStart N ((P-T)/2) t loc glob u:ℕ):ℤ)= + (T/2:ℕ)+(t/2:ℕ)-(∑a : Fin t,(bitIndex (loc u a):ℤ))- + scheduledGlobalShift N t glob u := by + have hfit := sourceWindowStart_fit N P T t L loc glob hP hT heven hL u hY + have hc := sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY + have ha := centered_window_floor_anchor P T (by omega) heven + have hA : (P-T)/2 ≤ P/2 := Nat.div_le_div_right (Nat.sub_le P T) + have ha' : ((P/2:ℕ):ℤ)-((P-T)/2:ℕ)=(T/2:ℕ) := by omega + rw [Nat.cast_sub hfit.2.1,hc] + dsimp only [sourceDisplacement] + linarith only [ha'] + +/-- The manuscript numbers motif slots from one. Thus its actual zero-based + onset is P/2-1, not P/2. The strict margins include this endpoint correction. -/ +theorem sourceWindowStart_oneBased_fit (N P T t L : ℕ) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) + (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : + sourceWindowStart N ((P-T)/2) t loc glob u+T ≤ P ∧ + sourceWindowStart N ((P-T)/2) t loc glob u ≤ P/2-1 ∧ + P/2-1+L ≤ sourceWindowStart N ((P-T)/2) t loc glob u+T := by + have hc := sourceWindowStart_cast_of_fit N P T t loc glob hP hT u hY + have ha := centered_window_floor_anchor P T (by omega) heven + have hy := abs_le.mp hY + omega + +/-- The exact source anchor in zero-based coordinates. The minus one is + forced by the one-based motif-label convention. -/ +theorem sourceWindowStart_oneBased_anchor (N P T t L : ℕ) + (loc : Fin N → Fin t → Bool) (glob : Fin ((N/4)*t) → Bool) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) (hL : 8*L ≤ T) + (u : Fin N) (hY : |8*sourceDisplacement N t loc glob u| ≤ (T:ℤ)) : + ((P/2-1-sourceWindowStart N ((P-T)/2) t loc glob u:ℕ):ℤ)= + (T/2:ℕ)-1+(t/2:ℕ)-(∑a : Fin t,(bitIndex (loc u a):ℤ))- + scheduledGlobalShift N t glob u := by + have hf := sourceWindowStart_oneBased_fit N P T t L loc glob hP hT heven hL u hY + have ha := sourceWindowStart_anchor N P T t L loc glob hP hT heven hL u hY + omega + +/-- The actual recursively substituted source block words. Indices in P + are shifted down by one, but physical binary strings are unchanged. -/ +def sourceBlockWord (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) : ℕ → Bool → List Bool + | 0 => atom + | j+1 => complementaryWords (P j) (P j/2-1) (2^s) (prouhetBool s) + (sourceBlockWord s P atom j) + +def sourceBlockLength (P : ℕ → ℕ) (S : ℕ) : ℕ → ℕ + | 0 => S + | j+1 => P j*sourceBlockLength P S j + +theorem sourceBlockWord_length (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) (S : ℕ) + (hw : ∀τ,(atom τ).length=S) (j : ℕ) (τ : Bool) : + (sourceBlockWord s P atom j τ).length=sourceBlockLength P S j := by + induction j generalizing τ with + | zero => exact hw τ + | succ j ih => exact complementaryWords_length _ _ _ _ _ _ (fun τ => ih τ) τ + +theorem sourceBlockWord_injective (s : ℕ) (P : ℕ → ℕ) (atom : Bool → List Bool) (S : ℕ) + (hw : ∀τ,(atom τ).length=S) (hinj : Function.Injective atom) (j : ℕ) + (hP : ∀k exact hinj + | succ j ih => + apply complementaryWords_injective _ _ _ (sourceBlockLength P S j) + _ _ (sourceBlockWord_length s P atom S hw j) + · exact ih (fun k hk => hP k (by omega)) + · positivity + · have h := hP j (Nat.lt_succ_self j); omega + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Total Boolean type, also on failed layouts; no conditioning is hidden + in the definition. -/ +def integerTemplateType (N s : ℕ) (X : ℤ) (τ : Bool) (u : Fin N) : Bool := + decide (motifChildSign s X u.val (boolTypeSign τ)= -1) + +theorem boolTypeSign_integerTemplate (N s : ℕ) (X : ℤ) (τ : Bool) (u : Fin N) : + boolTypeSign (integerTemplateType N s X τ u)=motifChildSign s X u.val (boolTypeSign τ) := by + have hτ : IsTypeSign (boolTypeSign τ) := by cases τ <;> norm_num [IsTypeSign,boolTypeSign] + rcases motifChildSign_isSign s X u.val hτ with h | h <;> + (simp only [integerTemplateType,h]; norm_num [boolTypeSign]) + +theorem integerTemplateType_nat (N s a : ℕ) (τ : Bool) : + integerTemplateType N s (a:ℤ) τ=templateType N a (2^s) (prouhetBool s) τ := by + funext u + apply boolTypeSign_injective + rw [boolTypeSign_integerTemplate,boolTypeSign_template] + +/-- Global trials at a parent use its children's local-trial count. This + fixes the index shift between source level labels and zero-based arrays. -/ +def sourceScheduledTrials (T n : ℕ → ℕ) : ℕ → ℕ + | 0 => 0 + | b+1 => (T (b+1)/4)*n b + +def sourceScheduledShift (T n : ℕ → ℕ) : + (b : ℕ) → (Fin (sourceScheduledTrials T n b) → Bool) → Fin (T b) → ℤ + | 0, _, _ => 0 + | b+1, glob, u => scheduledGlobalShift (T (b+1)) (n b) glob u + +def sourceLocalCenter (T n : ℕ → ℕ) (b : ℕ) : ℤ := + (T b/2:ℕ)-1+(n b/2:ℕ) + +def sourceNodeAnchor (T n : ℕ → ℕ) (center : ℕ → ℤ) (b : ℕ) + (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (incoming : ℤ) : ℤ := + center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming + +/-- All actual leaf Booleans on the complete deterministic window tree. -/ +def sourceTreeLeafBool (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) : + (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → WindowLeaf T b → Bool + | 0, _, _, τ, _ => τ + | b+1, bits, incoming, τ, v => + sourceTreeLeafBool T n s center b (bits.2.2 v.1) + (sourceScheduledShift T n b bits.2.1 v.1) + (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ v.1) v.2 + +theorem sourceTreeLeafBool_sign (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) + (incoming : ℤ) (τ : Bool) (v : WindowLeaf T b) : + boolTypeSign (sourceTreeLeafBool T n s center b bits incoming τ v)= + sourceTreeLeafSign T n (sourceScheduledTrials T n) s center + (sourceScheduledShift T n) b bits incoming (boolTypeSign τ) v := by + induction b generalizing incoming τ with + | zero => rfl + | succ b ih => + change boolTypeSign (sourceTreeLeafBool T n s center b _ _ _ v.2)=_ + rw [ih,boolTypeSign_integerTemplate] + rfl + +def sourceNominalPre (P T : ℕ → ℕ) (b : ℕ) : ℕ := (P b-T b)/2 +def sourceNominalPost (P T : ℕ → ℕ) (b : ℕ) : ℕ := P b-T b-sourceNominalPre P T b + +theorem sourceNominal_total (P T : ℕ → ℕ) (b : ℕ) (h : T b ≤ P b) : + sourceNominalPre P T b+T b+sourceNominalPost P T b=P b := by + dsimp [sourceNominalPre,sourceNominalPost] + omega + +/-- The actual center before recursively cutting its pure side regions. -/ +def sourceCenterWord (s : ℕ) (P T n : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : + (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool + | 0, _, _, τ => atom τ + | b+1, bits, incoming, τ => atomString (T b) (sourceBlockWord s P atom b) + (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ) + +/-- The unconditional literal surrogate partition: local and common-global + pairs contribute their real selected pure lengths, on every bit assignment. -/ +def sourceTreeWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : + (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool + | 0, _, _, τ => atom τ + | 1, bits, incoming, τ => sourceCenterWord s P T n center atom 1 bits incoming τ + | b+2, bits, incoming, τ => + let loc := fun u => (bits.2.2 u).1 + let glob := bits.2.1 + coordinateWord (fun u : Fin (T (b+1)) => + pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) (sourceNominalPre P T b) (n b) (h b) loc glob u) ++ + sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) + (sourceScheduledShift T n (b+1) glob u) + (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) + (sourcePostCount (T (b+1)) (sourceNominalPost P T b) (n b) (h b) loc glob u)) + +/-- The actual fit event uses a joint test of all displacements. It does not + assert independence and will only be charged probabilistically afterwards. -/ +def SourceTreeFit (T n : ℕ → ℕ) : + (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → Prop + | 0, _ => True + | 1, _ => True + | b+2, bits => + (∀u, |8*sourceDisplacement (T (b+1)) (n b) (fun v => (bits.2.2 v).1) bits.2.1 u| ≤ (T b:ℤ)) ∧ + ∀u, SourceTreeFit T n (b+1) (bits.2.2 u) + +/-- Numerical layout conditions from the source. These contain no word or + statistical conclusions, only the genuine integer margins. -/ +structure SourceLayoutMargins (s : ℕ) (P T n h : ℕ → ℕ) (b : ℕ) : Prop where + positive : ∀j intro j hj + · exact H.positive j (lt_of_lt_of_le hj hc) + · exact H.large j (lt_of_lt_of_le hj hc) + · exact H.even_window j (lt_of_lt_of_le hj hc) + · exact H.ambient j (lt_of_lt_of_le hj hc) + · exact H.motif j (lt_of_lt_of_le hj hc) + · exact H.even_trials j (lt_of_lt_of_le hj hc) + · exact H.pre_reserve j (lt_of_lt_of_le hj hc) + · exact H.post_reserve j (lt_of_lt_of_le hj hc) + +/-- Every recursively cut surrogate center is literally the actual center on + the joint fit event. The source type assignment is retained at all leaves. -/ +theorem sourceTreeWord_eq_center (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) + (atom : Bool → List Bool) (b : ℕ) (H : SourceLayoutMargins s P T n h b) + (hc : ∀j, j+1 rfl + | one => rfl + | more b ih₁ ih₂ => + change (Fin (n (b+1)) → Bool) × (Fin ((T (b+1)/4)*n b) → Bool) × + (Fin (T (b+1)) → WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) at bits + let loc : Fin (T (b+1)) → Fin (n b) → Bool := fun u => (bits.2.2 u).1 + let glob := bits.2.1 + let a := P b/2-1 + let A := sourceNominalPre P T b + let B := sourceNominalPost P T b + let start := sourceWindowStart (T (b+1)) A (n b) loc glob + let θ := integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ + have hb : b hc j (by omega)) _ _ _ (hfit.2 u)] + simp only [sourceCenterWord,hx,integerTemplateType_nat,complementaryWords] + have hstartnonneg (u : Fin (T (b+1))) : 0≤(A:ℤ)+sourceDisplacement (T (b+1)) (n b) loc glob u := by + have he := sourceWindowStart_cast_of_fit (T (b+1)) (P b) (T b) (n b) loc glob + (H.ambient b hb) (H.large b hb) u (hfit.1 u) + have hn : (0:ℤ)≤(start u:ℕ) := Int.natCast_nonneg _ + change (start u:ℤ)=(A:ℤ)+_ at he + omega + have hp := H.positive (b+1) (by omega) + obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : T (b+1)≠0) + have hpart : (List.ofFn (fun u => complementaryWords (P b) a (2^s) (prouhetBool s) + (sourceBlockWord s P atom b) (θ u))).flatten= + coordinateWord (fun u => pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by + have hh := sourceLayout_literal_partition k A (T b) B (n b) (h b) a (2^s) + have hk' : k+1=T (b+1) := hk.symm + rw [hk'] at hh + rw [show A+T b+B=P b from htotal] at hh + exact hh (H.even_trials b hb) (H.pre_reserve b hb) (H.post_reserve b hb) loc glob + (prouhetBool s) (sourceBlockWord s P atom b) θ hstartnonneg + (fun u => (hf u).2.1) (fun u => (hf u).2.2) (fun u => (hf u).1) + change coordinateWord (fun u : Fin (T (b+1)) => + pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) + (sourceScheduledShift T n (b+1) glob u) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u))= + atomString (T (b+1)) (sourceBlockWord s P atom (b+1)) θ + calc + _ = coordinateWord (fun u : Fin (T (b+1)) => + pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by + apply congrArg coordinateWord + funext u + exact congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ w ++ + pureAtomRun (sourceBlockWord s P atom b false) + (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) (hchild u) + _ = _ := hpart.symm + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/LayoutRates.lean b/lean/OAI/Probability/TraceReconstruction/LayoutRates.lean index 0337da5bc6a37fed47fe1be0a6674277ed497110..333929b85252786fc6a6198bdce281eb00b7e29e 100644 --- a/lean/OAI/Probability/TraceReconstruction/LayoutRates.lean +++ b/lean/OAI/Probability/TraceReconstruction/LayoutRates.lean @@ -1,1182 +1,1182 @@ -import OAI.Probability.TraceReconstruction.InitialRates - -namespace OAI - -/-! -# LayoutRates - -Integer block schedules, rounding, length and trial margins, sparse gaps, and forced-anchor decay. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The source integer window size, with zero-based nesting index. -/ -def sourceWindowSize (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : ℕ := - 4*⌊N^(scaleKappa b (j+1) ε)/4⌋₊ - -/-- At a nonroot node the source trial count is an even integer. -/ -def sourceLocalTrials (P h : ℕ) : ℕ := 2*(P/(100*(2*h+1))) - -/-- The root schedule count: the literal floor after subtracting its window. -/ -def sourceRootTrials (N : ℝ) (S T h : ℕ) : ℕ := - (⌊N/(S:ℝ)⌋₊-T)/(2*h+1) - -/-- Literal length and overlap-count state of one nested source block. - `copies` and `trials` refer to the transition into this state. -/ -structure SourceArithmeticStage where - length : ℕ - count : ℕ - copies : ℕ - trials : ℕ - -def sourceArithmeticStages (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) : - ℕ → SourceArithmeticStage - | 0 => ⟨ell,k,1,0⟩ - | j+1 => - let prev := sourceArithmeticStages C N b ε ell k j - let T := sourceWindowSize N b ε j - let J := sourceRootTrials N prev.length T prev.count - let P := if j+1=b then J*(2*prev.count+1)+T - else ⌊N^(scaleA b (j+1) ε)/(prev.length:ℝ)⌋₊ - let m := if j+1=b then J else sourceLocalTrials P prev.count - ⟨prev.length*P,⌈C*prev.count*P⌉₊,P,m⟩ - -def sourceArithmeticP (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := - (sourceArithmeticStages C N b ε ell k (j+1)).copies - -def sourceArithmeticTrials (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := - (sourceArithmeticStages C N b ε ell k (j+1)).trials - -def sourceArithmeticLength (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := - (sourceArithmeticStages C N b ε ell k j).length - -def sourceArithmeticCount (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := - (sourceArithmeticStages C N b ε ell k j).count - -theorem sourceLocalTrials_even (P h : ℕ) : Even (sourceLocalTrials P h) := - even_two_mul _ - -theorem sourceLocalTrials_budget (P h : ℕ) : - 50*sourceLocalTrials P h*(2*h+1) ≤ P := by - have H := Nat.mul_div_le P (100*(2*h+1)) - unfold sourceLocalTrials - nlinarith only [H] - -theorem sourceLocalTrials_reserves (P T h : ℕ) (hT : 2*T ≤ P) : - 2*sourceLayoutReserve (sourceLocalTrials P h) h ≤ (P-T)/2 ∧ - 2*sourceLayoutReserve (sourceLocalTrials P h) h ≤ P-T-(P-T)/2 := by - have H := sourceLocalTrials_budget P h - rw [mul_assoc] at H - have he : sourceLocalTrials P h/2=P/(100*(2*h+1)) := by - unfold sourceLocalTrials - omega - have hr : 2*sourceLayoutReserve (sourceLocalTrials P h) h= - sourceLocalTrials P h*(2*h+1) := by - unfold sourceLayoutReserve - rw [he] - unfold sourceLocalTrials - ring - rw [hr] - have hm : 2*(sourceLocalTrials P h*(2*h+1)) ≤ P-T := by omega - constructor <;> omega - -theorem sourceWindowSize_even (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : - Even (sourceWindowSize N b ε j) := by - unfold sourceWindowSize - exact ⟨2*⌊N^(scaleKappa b (j+1) ε)/4⌋₊,by ring⟩ - -theorem sourceArithmeticLength_step (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : - sourceArithmeticLength C N b ε ell k (j+1)= - sourceArithmeticLength C N b ε ell k j*sourceArithmeticP C N b ε ell k j := rfl - -theorem sourceArithmeticCount_step (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : - sourceArithmeticCount C N b ε ell k (j+1)= - ⌈C*sourceArithmeticCount C N b ε ell k j*sourceArithmeticP C N b ε ell k j⌉₊ := rfl - -theorem sourceArithmetic_inner_trials (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) - (hj : j+1≠b) : sourceArithmeticTrials C N b ε ell k j= - sourceLocalTrials (sourceArithmeticP C N b ε ell k j) (sourceArithmeticCount C N b ε ell k j) := by - simp only [sourceArithmeticTrials,sourceArithmeticP,sourceArithmeticCount,sourceArithmeticStages,ite_eq_right hj] - -theorem sourceArithmetic_root_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (hb : 1 ≤ b) : - sourceArithmeticP C N b ε ell k (b-1)= - sourceArithmeticTrials C N b ε ell k (b-1)*(2*sourceArithmeticCount C N b ε ell k (b-1)+1)+ - sourceWindowSize N b ε (b-1) := by - simp only [sourceArithmeticP,sourceArithmeticTrials,sourceArithmeticCount,sourceArithmeticStages, - Nat.sub_add_cancel hb,ite_true] - -theorem sourceArithmetic_count_lift (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : - C*sourceArithmeticCount C N b ε ell k j*sourceArithmeticP C N b ε ell k j ≤ - sourceArithmeticCount C N b ε ell k (j+1) := Nat.le_ceil _ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Rounding the source windows loses at most a factor two. -/ -theorem sourceWindowSize_bounds {N ε : ℝ} {b j : ℕ} - (h : 8 ≤ N^(scaleKappa b (j+1) ε)) : - N^(scaleKappa b (j+1) ε)/2 ≤ (sourceWindowSize N b ε j:ℝ) ∧ - (sourceWindowSize N b ε j:ℝ) ≤ N^(scaleKappa b (j+1) ε) := by - have hlo := Nat.lt_floor_add_one (N^(scaleKappa b (j+1) ε)/4) - have hhi := Nat.floor_le (show 0 ≤ N^(scaleKappa b (j+1) ε)/4 by linarith) - unfold sourceWindowSize - push_cast - constructor <;> linarith only [h,hlo,hhi] - -/-- The nonroot even trial count is between one and two times its unrounded - quotient once the quotient is at least two. -/ -theorem sourceLocalTrials_bounds (P h : ℕ) (hlarge : (200:ℝ)*(2*h+1) ≤ P) : - (P:ℝ)/(100*(2*h+1)) ≤ (sourceLocalTrials P h:ℝ) ∧ - (sourceLocalTrials P h:ℝ) ≤ (P:ℝ)/(50*(2*h+1)) := by - have hd : 0 < (100:ℝ)*(2*h+1) := by positivity - have hx : (2:ℝ) ≤ (P:ℝ)/(100*(2*h+1)) := (le_div_iff₀ hd).mpr (by linarith only [hlarge]) - have he : (sourceLocalTrials P h:ℝ)=2*(⌊(P:ℝ)/(100*(2*h+1))⌋₊:ℝ) := by - unfold sourceLocalTrials - rw [show (100:ℝ)*(2*h+1)=((100*(2*h+1):ℕ):ℝ) by push_cast; ring,Nat.floor_div_eq_div] - norm_cast - rw [he] - have hlo := Nat.lt_floor_add_one ((P:ℝ)/(100*(2*h+1))) - have hhi := Nat.floor_le (div_nonneg (Nat.cast_nonneg P) hd.le) - constructor - · linarith only [hx,hlo] - · have heq : (P:ℝ)/(50*(2*h+1))=2*((P:ℝ)/(100*(2*h+1))) := by field_simp; ring - rw [heq] - linarith only [hhi] - -theorem source_floor_length_bounds {X : ℝ} {S : ℕ} (hS : 0 < S) (hX : 2*(S:ℝ) ≤ X) : - X/2 ≤ ((S*⌊X/(S:ℝ)⌋₊:ℕ):ℝ) ∧ ((S*⌊X/(S:ℝ)⌋₊:ℕ):ℝ) ≤ X := by - have hs : (0:ℝ) < S := by exact_mod_cast hS - have hlo := Nat.lt_floor_add_one (X/(S:ℝ)) - have hhi := Nat.floor_le (div_nonneg (show 0 ≤ X by linarith only [hX,hs]) hs.le) - have hh := mul_lt_mul_of_pos_left hlo hs - have hh' := mul_le_mul_of_nonneg_left hhi hs.le - rw [mul_add,mul_div_cancel₀ _ hs.ne'] at hh - rw [mul_div_cancel₀ _ hs.ne'] at hh' - push_cast - constructor <;> nlinarith only [hX,hh,hh'] - -/-- The real floor and integer division versions of the root are identical - whenever its remaining ambient count is nonnegative. -/ -theorem sourceRootTrials_floor {N : ℝ} {S T h : ℕ} - (hT : T ≤ ⌊N/(S:ℝ)⌋₊) : - sourceRootTrials N S T h=⌊((⌊N/(S:ℝ)⌋₊:ℝ)-T)/(2*h+1)⌋₊ := by - unfold sourceRootTrials - rw [←Nat.cast_sub hT] - rw [show (2:ℝ)*h+1=((2*h+1:ℕ):ℝ) by push_cast; ring,Nat.floor_div_eq_div] - -theorem source_root_length_bounds {N : ℝ} {S T h : ℕ} (hS : 0 < S) - (hT : T ≤ ⌊N/(S:ℝ)⌋₊) (hN : (2*h+2:ℝ)*S ≤ N/2) : - N/2 ≤ (S:ℝ)*(sourceRootTrials N S T h*(2*h+1)+T) ∧ - (S:ℝ)*(sourceRootTrials N S T h*(2*h+1)+T) ≤ N := by - have hs : (0:ℝ)= 8F. -/ -theorem source_root_margins {N X u F : ℝ} {S h T : ℕ} - (hS : 1 ≤ S) (hX : (S:ℝ) ≤ X) (hF : 1 ≤ F) (hu : 8*F ≤ u) - (hh : (h:ℝ) ≤ F*S) (hT : (T:ℝ) ≤ X) (hrel : X^2*u=N) : - T ≤ ⌊N/(S:ℝ)⌋₊ ∧ (2*(h:ℝ)+2)*S ≤ N/2 := by - have hs : (1:ℝ) ≤ S := by exact_mod_cast hS - have hx : 1 ≤ X := hs.trans hX - have hx0 : 0 ≤ X := by linarith only [hx] - have hs0 : (0:ℝ) < S := by linarith only [hs] - have hfs : 1 ≤ F*S := by nlinarith only [hF,hs] - have hsX : (S:ℝ)^2 ≤ X^2 := sq_le_sq₀ hs0.le hx0 |>.mpr hX - have h8 : 8*F*X^2 ≤ N := by nlinarith only [mul_le_mul_of_nonneg_right hu (sq_nonneg X),hrel] - constructor - · apply Nat.le_floor - apply (le_div_iff₀ hs0).mpr - have htX := mul_le_mul hT hX hs0.le hx0 - nlinarith only [htX,h8,mul_le_mul_of_nonneg_right hF (sq_nonneg X)] - · have hhS := mul_le_mul_of_nonneg_right hh hs0.le - have hS2 := mul_le_mul_of_nonneg_right hfs hs0.le - have hFsq := mul_le_mul_of_nonneg_left hsX (by linarith only [hF] : 0 ≤ F) - nlinarith only [hhS,hS2,hFsq,h8] - -theorem source_arithmetic_inner_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) - (hj : j+1≠b) : sourceArithmeticP C N b ε ell k j= - ⌊N^(scaleA b (j+1) ε)/(sourceArithmeticLength C N b ε ell k j:ℝ)⌋₊ := by - simp only [sourceArithmeticP,sourceArithmeticLength,sourceArithmeticStages,ite_eq_right hj] - -theorem source_arithmetic_root_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) - (hj : j+1=b) : sourceArithmeticP C N b ε ell k j= - sourceRootTrials N (sourceArithmeticLength C N b ε ell k j) (sourceWindowSize N b ε j) - (sourceArithmeticCount C N b ε ell k j)* - (2*sourceArithmeticCount C N b ε ell k j+1)+sourceWindowSize N b ε j := by - simp only [sourceArithmeticP,sourceArithmeticLength,sourceArithmeticCount,sourceArithmeticStages,ite_eq_left hj] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- All nested lengths and overlap counts for the literal floors/ceilings. - Only the scalar subpower margin is needed for every rounding step. -/ -theorem source_arithmetic_lengths {C N F ε : ℝ} {b ell k : ℕ} - (hC : 2 ≤ C) (hN : 1 ≤ N) (hF : 1 ≤ F) (he : 0 ≤ ε) - (ha : ∀j ≤ b,0 ≤ scaleA b j ε) - (hsmall : 8*C^(2*b)*F ≤ N^ε) - (hell : N^(scaleA b 0 ε)/2 ≤ (ell:ℝ)) (hell' : (ell:ℝ) ≤ N^(scaleA b 0 ε)) - (hk : ell ≤ k) (hk' : (k:ℝ) ≤ F*ell) : - ∀j ≤ b, - N^(scaleA b j ε)/2 ≤ (sourceArithmeticLength C N b ε ell k j:ℝ) ∧ - (sourceArithmeticLength C N b ε ell k j:ℝ) ≤ N^(scaleA b j ε) ∧ - sourceArithmeticLength C N b ε ell k j ≤ sourceArithmeticCount C N b ε ell k j ∧ - (sourceArithmeticCount C N b ε ell k j:ℝ) ≤ - C^(2*j)*F*sourceArithmeticLength C N b ε ell k j := by - have hN0 : 0 < N := by linarith only [hN] - have hC1 : 1 ≤ C := by linarith only [hC] - intro j - induction j with - | zero => - intro _ - simpa only [sourceArithmeticLength,sourceArithmeticCount,sourceArithmeticStages, - Nat.mul_zero,pow_zero,one_mul] using And.intro hell (And.intro hell' (And.intro hk hk')) - | succ j ih => - intro hj - obtain ⟨hlo,hhi,hcount,hcount'⟩ := ih (by omega) - let S := sourceArithmeticLength C N b ε ell k j - let H := sourceArithmeticCount C N b ε ell k j - let P := sourceArithmeticP C N b ε ell k j - let Fj := C^(2*j)*F - have hFj : 1 ≤ Fj := one_le_mul_of_one_le_of_one_le (one_le_pow₀ hC1) hF - have hS0 : (0:ℝ) nlinarith only [hX,hlo,hhi,hlo',hhi'] - -theorem source_inner_trials_scale {X u F : ℝ} {S P h : ℕ} - (hX : 1 ≤ X) (hF : 1 ≤ F) (hu : 1200*F ≤ u) - (hSlo : X/2 ≤ S) (hShi : (S:ℝ) ≤ X) (hhlo : S ≤ h) (hhhi : (h:ℝ) ≤ F*S) - (hPlo : X*u/2 ≤ (P:ℝ)) (hPhi : (P:ℝ) ≤ 2*X*u) : - u/(600*F) ≤ (sourceLocalTrials P h:ℝ) ∧ (sourceLocalTrials P h:ℝ) ≤ 2*u := by - have hx : 0(q t)^3*Real.log (n t)) atTop atTop) : - ∀ᶠt in atTop,∀i ≤ sourceDepth B ζ ((q t)^3*Real.log (n t)),∀b ≤ B, - 8*(sourceOverlapConstant (q t))^(2*b)*(sourceOverlapConstant (q t))^(2*B*i+2) ≤ - (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) (i+1))^ - (sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by - let K := 8+sourceChannelLogConstant*(2*B+2) - have hK : 0 ≤ K := by dsimp [K]; positivity [sourceChannelLogConstant_pos] - have hrel (t) : Real.log (n t)=(q t)^(-3:ℤ)*((q t)^3*Real.log (n t)) := by - rw [zpow_neg,zpow_ofNat] - field_simp [(hq t).1.ne'] - have H := source_uniform_exp_absorption B 1 ζ K 1 hB hζ hK (by norm_num) hn hH - (fun t=>zpow_pos (hq t).1 _) hrel - filter_upwards [H] with t ht i hi b hb - have hh := source_count_factor_exp_bound (hq t) B (sourceDepth B ζ ((q t)^3*Real.log (n t))) b i hb hi - exact hh.trans (by simpa only [pow_one,one_mul] using ht (i+1)) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Tiny epsilon estimates are uniform in the varying block depth. -/ -theorem sourceEpsilon_power_small (B D m : ℕ) (hm : m ≤ 4*B+100) : - (2:ℝ)^m*sourceEpsilon B D ≤ 1 := by - have hp : (2:ℝ)^m ≤ 2^(4*B+100) := pow_le_pow_right₀ (by norm_num) hm - have hd : (1:ℝ) ≤ (D:ℝ)+1 := by linarith only [Nat.cast_nonneg D (α:=ℝ)] - have hmul := mul_le_mul_of_nonneg_left hd (show 0 ≤ (2:ℝ)^(4*B+100) by positivity) - unfold sourceEpsilon - rw [mul_one_div] - exact (div_le_one (by positivity)).mpr (hp.trans (by simpa only [mul_one] using hmul)) - -theorem scaleA_mono_index (b j k : ℕ) (ε : ℝ) (he : 0 ≤ ε) (hjk : j ≤ k) : - scaleA b j ε ≤ scaleA b k ε := by - unfold scaleA - exact sub_le_sub_right (div_le_div_of_nonneg_right - (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ (by norm_num) hjk) (by linarith only [he])) - (by positivity)) _ - -theorem scaleA_le_geometric (b j : ℕ) (ε : ℝ) (he : 0 ≤ ε) (hj : j ≤ b) : - scaleA b j ε ≤ (2:ℝ)^j/2^b := by - have hp : (2:ℝ)^j ≤ 2^b := pow_le_pow_right₀ (by norm_num) hj - have hh := mul_le_mul_of_nonneg_left hp he - unfold scaleA - apply (sub_le_iff_le_add).mpr - apply (div_le_iff₀ (by positivity)).mpr - simp only [add_mul] - rw [div_mul_cancel₀ _ (by positivity : (2:ℝ)^b ≠ 0)] - nlinarith only [hh] - -theorem sourceKappa_three_epsilon (B D b j : ℕ) (hb : b ≤ B) (_hj : 1 ≤ j) (hj' : j ≤ b) : - 3*sourceEpsilon B D ≤ scaleKappa b j (sourceEpsilon B D) := by - let ε := sourceEpsilon B D - let X := (2:ℝ)^B - have he : 0 < ε := sourceEpsilon_pos _ _ - have hx : 1 ≤ X := one_le_pow₀ (by norm_num) - have hsmall := sourceEpsilon_power_small B D (2*B+4) (by omega) - have hsmall' : 16*X^2*ε ≤ 1 := by - rw [show 2*B+4=B*2+4 by omega,pow_add,pow_mul] at hsmall - norm_num only [show (2:ℝ)^4=16 by norm_num] at hsmall - dsimp [X,ε] - nlinarith only [hsmall] - have hgeom := scaleA_zero_lower b B ε hb he.le - have hmono := scaleA_mono_index b 0 (j-1) ε he.le (Nat.zero_le _) - have hp : (2:ℝ)^j ≤ X := pow_le_pow_right₀ (by norm_num) (hj'.trans hb) - have hprod : (3*X+4)*X*ε ≤ 1 := by - have hxx : 0 ≤ X*(X-1) := mul_nonneg (by linarith only [hx]) (by linarith only [hx]) - have hcmp : (3*X+4)*X ≤ 16*X^2 := by nlinarith only [hxx,sq_nonneg X] - exact (mul_le_mul_of_nonneg_right hcmp he.le).trans hsmall' - have hq : (3*X+4)*ε ≤ 1/X := (le_div_iff₀ (by linarith only [hx])).mpr (by nlinarith only [hprod]) - have hzero : 1/X-ε ≤ scaleA b 0 ε := by - have hh : (1/X)*(1-(X-1)*ε)=1/X-ε+ε/X := by field_simp; ring - dsimp [X] at hh - rw [hh] at hgeom - exact (le_add_of_nonneg_right (div_nonneg he.le (by positivity))).trans hgeom - have hpk := mul_le_mul_of_nonneg_right hp he.le - unfold scaleKappa - change 3*ε ≤ scaleA b (j-1) ε-3*(2^j-1)*ε - nlinarith only [hzero,hmono,hq,hpk,he] - -theorem sourceA_nonneg (B D b j : ℕ) (hb : b ≤ B) (hb0 : 1 ≤ b) : - 0 ≤ scaleA b j (sourceEpsilon B D) := by - have h := sourceKappa_three_epsilon B D b 1 hb (by omega) hb0 - unfold scaleKappa at h - norm_num only [Nat.sub_self,pow_one] at h - have hm := scaleA_mono_index b 0 j (sourceEpsilon B D) (sourceEpsilon_pos B D).le (Nat.zero_le _) - linarith only [h,hm,sourceEpsilon_pos B D] - -/-- The interior scale mass excludes the bottom window, as required by the - sparse role count rather than the much larger total leaf count. -/ -def sourceInteriorExponent (b : ℕ) (ε : ℝ) : ℝ := - ∑j∈Finset.range (b-1),scaleKappa b (j+2) ε - -theorem two_power_sum_shift (m : ℕ) : - (∑j∈Finset.range m,(2:ℝ)^(j+1))=2^(m+1)-2 := by - induction m with - | zero => norm_num - | succ m ih => rw [Finset.sum_range_succ,ih,pow_succ (2:ℝ) (m+1)]; ring - -theorem sourceInteriorExponent_upper (b : ℕ) (ε : ℝ) (hb : 1 ≤ b) (he : 0 ≤ ε) : - sourceInteriorExponent b ε ≤ 1-2/(2:ℝ)^b := by - have hterm (j : ℕ) (hj : j∈Finset.range (b-1)) : - scaleKappa b (j+2) ε ≤ (2:ℝ)^(j+1)/2^b := by - have hj' := Finset.mem_range.mp hj - have ha := scaleA_le_geometric b (j+1) ε he (by omega) - have hp : (1:ℝ) ≤ 2^(j+2) := one_le_pow₀ (by norm_num) - unfold scaleKappa - simp only [show j+2-1=j+1 by omega] - linarith only [ha,mul_nonneg (sub_nonneg.mpr hp) he] - apply (Finset.sum_le_sum hterm).trans_eq - rw [←Finset.sum_div,two_power_sum_shift,Nat.sub_add_cancel hb] - field_simp - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem scaleA_zero_simple_lower (b : ℕ) (ε : ℝ) (he : 0 ≤ ε) : - 1/(2:ℝ)^b-ε ≤ scaleA b 0 ε := by - unfold scaleA - norm_num only [pow_zero,mul_one] - exact sub_le_sub_right (div_le_div_of_nonneg_right (by linarith only [he]) (by positivity)) _ - -/-- Quantitative sparse gap, keeping its growth in d. Both the two-dimensional - warmup and the post-warmup dimension satisfy this common estimate. -/ -theorem source_sparse_gap (B D b : ℕ) (d : ℝ) (hb1 : 1 ≤ b) (_hb : b ≤ B) - (hd : 11/5 ≤ d) (hcases : b=2 ∨ (b=B ∧ (2:ℝ)^B+2 ≤ d)) : - (d+1)/(128*(2:ℝ)^(2*B)) ≤ - scaleA b 0 (sourceEpsilon B D)*d-sourceInteriorExponent b (sourceEpsilon B D) := by - let X := (2:ℝ)^B - let ε := sourceEpsilon B D - have hx : 1 ≤ X := one_le_pow₀ (by norm_num) - have hx0 : 0 < X := by linarith only [hx] - have hd0 : 0 ≤ d := by linarith only [hd] - have he : 0 < ε := sourceEpsilon_pos B D - have hA := mul_le_mul_of_nonneg_right (scaleA_zero_simple_lower b ε he.le) hd0 - have hI := sourceInteriorExponent_upper b ε hb1 he.le - have hcoeff : (d+1)/(64*X^2) ≤ (d+2)/(2:ℝ)^b-1 := by - rcases hcases with htwo | ⟨hmain,hdmain⟩ - · rw [htwo] - have hstep : (d+1)/(64*X^2) ≤ (d+1)/64 := by - apply div_le_div_of_nonneg_left (by linarith only [hd]) (by norm_num) - nlinarith only [hx,sq_nonneg (X-1)] - apply hstep.trans - norm_num only [show (2:ℝ)^2=4 by norm_num] - linarith only [hd] - · rw [hmain] - change (d+1)/(64*X^2) ≤ (d+2)/X-1 - apply (div_le_iff₀ (by positivity : (0:ℝ)<64*X^2)).mpr - have heq : ((d+2)/X-1)*(64*X^2)=64*X*(d+2-X) := by field_simp - rw [heq] - have hh : 0 ≤ (d-X-2)*(64*X-1) := mul_nonneg (by dsimp [X]; linarith only [hdmain]) - (by linarith only [hx]) - nlinarith only [hh,hx] - have hsmall := sourceEpsilon_power_small B D (2*B+8) (by omega) - have hsmall' : 256*X^2*ε ≤ 1 := by - rw [show 2*B+8=B*2+8 by omega,pow_add,pow_mul] at hsmall - norm_num only [show (2:ℝ)^8=256 by norm_num] at hsmall - dsimp [X,ε] - nlinarith only [hsmall] - have herr : ε*d ≤ (d+1)/(256*X^2) := by - apply (le_div_iff₀ (by positivity : (0:ℝ)<256*X^2)).mpr - have hh := mul_le_mul_of_nonneg_right hsmall' hd0 - nlinarith only [hh] - have hpow : (2:ℝ)^(2*B)=X^2 := by dsimp [X]; rw [Nat.mul_comm,pow_mul] - rw [hpow] - change (d+1)/(128*X^2) ≤ scaleA b 0 ε*d-sourceInteriorExponent b ε - have hp : 0 < (2:ℝ)^b := by positivity - have hc : (1/(2:ℝ)^b-ε)*d-(1-2/(2:ℝ)^b)=((d+2)/(2:ℝ)^b-1)-ε*d := by ring - have hbase := sub_le_sub hA hI - rw [hc] at hbase - have hident : (d+1)/(64*X^2)-(d+1)/(256*X^2)=3*(d+1)/(256*X^2) := by ring - have hlo := (sub_le_sub hcoeff herr).trans hbase - rw [hident] at hlo - have hcompare : (d+1)/(128*X^2) ≤ 3*(d+1)/(256*X^2) := by - have hh : (d+1)/128 ≤ 3*(d+1)/256 := by linarith only [hd] - simpa only [div_div] using div_le_div_of_nonneg_right hh (sq_nonneg X) - exact hcompare.trans hlo - -theorem totalScoreExponent_step (B i : ℕ) : - totalScoreExponent B (i+1)=totalScoreExponent B i+blockGain (sourceDimension B i) := by - unfold totalScoreExponent sourceDimension - rw [Finset.sum_range_succ] - ring - -theorem totalScoreExponent_after_warmup (B i : ℕ) (hB : 2 ≤ B) (hi : warmupBlocks B ≤ i) : - (2:ℝ)^B+11/5 ≤ totalScoreExponent B i := by - rw [totalScoreExponent_exact B i hi] - have hm : (0:ℝ) ≤ ((i:ℝ)-warmupBlocks B)*blockGain B := - mul_nonneg (sub_nonneg.mpr (by exact_mod_cast hi)) (blockGain_pos B hB).le - unfold warmupBlocks at * - push_cast at * - linarith only [hm] - -theorem source_level_sparse_gap (B D i : ℕ) (hB : 2 ≤ B) : - (totalScoreExponent B i+1)/(128*(2:ℝ)^(2*B)) ≤ - scaleA (sourceDimension B i) 0 (sourceEpsilon B D)*totalScoreExponent B i- - sourceInteriorExponent (sourceDimension B i) (sourceEpsilon B D) := by - have hb : 2 ≤ sourceDimension B i ∧ sourceDimension B i ≤ B := by - unfold sourceDimension - split_ifs <;> omega - apply source_sparse_gap B D _ _ (by omega) hb.2 (totalScoreExponent_bounds B i hB).1 - unfold sourceDimension - split_ifs with hi - · exact Or.inl rfl - · exact Or.inr ⟨rfl,by linarith only [totalScoreExponent_after_warmup B i hB (by omega)]⟩ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Levels outside the finite source block are irrelevant. Their harmless - positive extension permits the global-index API of the finite tree lemmas. -/ -def sourceBlockWindows (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : ℕ := - if j ⟨(H j hj).1,(H j hj).2.1⟩,fun j hj => (H j hj).2.2,hcopies,htrials,?_⟩ - intro j hj - rw [sourceBlockWindows,ite_eq_left hj] - have hp := hcopies j hj - have ht := htrials j hj - have hu3 : u^3 ≤ N^(scaleKappa b (j+1) ε) := by - dsimp [u] - rw [←Real.rpow_natCast,←Real.rpow_mul hN0.le] - norm_num only [Nat.cast_ofNat] - apply Real.rpow_le_rpow_of_exponent_le hN - linarith only [hκ j hj] - have hu32 : 64*u ≤ u^3 := by - have hu_sq : 64 ≤ u^2 := by nlinarith only [hu8,sq_nonneg (u-8)] - nlinarith only [mul_le_mul_of_nonneg_right hu_sq (by linarith only [hu8] : 0 ≤ u)] - have hw := sourceWindowSize_bounds (show 8 ≤ N^(scaleKappa b (j+1) ε) by linarith only [hu32,hu8,hu3]) - have hwbig : u^3/2 ≤ (sourceWindowSize N b ε j:ℝ) := le_trans (by linarith only [hu3] : u^3/2 ≤ N^(scaleKappa b (j+1) ε)/2) hw.1 - have hwp := sourceWindowSize_le_previous (b:=b) (j:=j) hN he - have hX : 0 ≤ N^(scaleA b j ε) := (Real.rpow_pos_of_pos hN0 _).le - have hambient : (2:ℝ)*(sourceWindowSize N b ε j:ℝ) ≤ sourceArithmeticP C N b ε ell k j := by - have hh := mul_le_mul_of_nonneg_right hu8 hX - nlinarith only [hp.1,hwp,hh] - have h24 : (24:ℝ) ≤ sourceWindowSize N b ε j := by linarith only [hwbig,hu32,hu8] - have hmot : (24:ℝ)*((2^s:ℕ):ℝ) ≤ sourceWindowSize N b ε j := by - have hu' : 48*((2^s:ℕ):ℝ) ≤ u := hmotif - linarith only [hwbig,hu32,hu'] - have hroot : (4:ℝ)*((sourceArithmeticTrials C N b ε ell k j:ℝ)+1) ≤ sourceWindowSize N b ε j := by - linarith only [hwbig,hu32,hu8,ht.2] - exact ⟨by exact_mod_cast h24,by exact_mod_cast hmot,by exact_mod_cast hambient,by exact_mod_cast hroot⟩ - -theorem SourceArithmeticBounds.layout {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) : - SourceLayoutMargins s (sourceArithmeticP C N b ε ell k) (sourceBlockWindows N b ε) - (sourceArithmeticTrials C N b ε ell k) (sourceArithmeticCount C N b ε ell k) (b-1) := by - constructor - · intro j hj - have hh := (H.windows j (by omega)).1 - omega - · intro j hj - have hh := (H.windows j (by omega)).1 - omega - · intro j hj - rw [sourceBlockWindows,ite_eq_left (by omega)] - exact sourceWindowSize_even N b ε j - · intro j hj - exact (H.windows j (by omega)).2.2.1 - · intro j hj - have hh := (H.windows j (by omega)).2.1 - omega - · intro j hj - rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] - exact sourceLocalTrials_even _ _ - · intro j hj - rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] - exact (sourceLocalTrials_reserves _ _ _ (H.windows j (by omega)).2.2.1).1 - · intro j hj - rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] - exact (sourceLocalTrials_reserves _ _ _ (H.windows j (by omega)).2.2.1).2 - -theorem SourceArithmeticBounds.window_positive {C N F ε : ℝ} {s b ell k : ℕ} - (H : SourceArithmeticBounds C N F ε s b ell k) (j : ℕ) : - 0 < sourceBlockWindows N b ε j := by - by_cases hj : j 0 - | b+1 => e b+2*binaryTreeExponent e b - -theorem binaryTreeExponent_sum (e : ℕ → ℝ) (b : ℕ) : - binaryTreeExponent e b=∑j∈Finset.range b,((2:ℝ)^b/2^(j+1))*e j := by - induction b with - | zero => simp [binaryTreeExponent] - | succ b ih => - rw [binaryTreeExponent,ih,Finset.sum_range_succ,Finset.mul_sum] - have he : (∑j∈Finset.range b,((2:ℝ)^(b+1)/2^(j+1))*e j)= - ∑j∈Finset.range b,2*((2^b/2^(j+1))*e j) := by - apply Finset.sum_congr rfl - intro j _ - rw [pow_succ] - ring - rw [he] - simp only [div_self (by positivity : (2:ℝ)^(b+1)≠0),one_mul] - ring - -theorem binaryTreeBudget_mono {C D : ℕ → ℝ} (b : ℕ) - (hC : ∀j < b,0 ≤ C j) (hCD : ∀j < b,C j ≤ D j) : - binaryTreeBudget C b ≤ binaryTreeBudget D b := by - induction b with - | zero => rfl - | succ b ih => - have hc : 0 ≤ binaryTreeBudget C b := by - cases b with - | zero => norm_num [binaryTreeBudget] - | succ j => exact mul_nonneg (hC j (by omega)) (sq_nonneg _) - have hd := ih (fun j hj=>hC j (by omega)) (fun j hj=>hCD j (by omega)) - rw [binaryTreeBudget,binaryTreeBudget] - exact mul_le_mul (hCD b (by omega)) (pow_le_pow_left₀ hc hd 2) - (sq_nonneg _) ((hC b (by omega)).trans (hCD b (by omega))) - -theorem binaryTreeBudget_scaled (A N : ℝ) (hN : 0 < N) (e : ℕ → ℝ) (b : ℕ) : - binaryTreeBudget (fun j => A*N^(-e j)) b= - binaryTreeBudget (fun _=>A) b*N^(-binaryTreeExponent e b) := by - induction b with - | zero => simp [binaryTreeBudget,binaryTreeExponent] - | succ b ih => - rw [binaryTreeBudget,ih,binaryTreeBudget,binaryTreeExponent,mul_pow] - have hr : N^(-e b)*(N^(-binaryTreeExponent e b))^2= - N^(-(e b+2*binaryTreeExponent e b)) := by - rw [←Real.rpow_natCast,←Real.rpow_mul hN.le,←Real.rpow_add hN] - congr 1 - norm_num only [Nat.cast_ofNat] - ring - calc - _ = (A*(binaryTreeBudget (fun _=>A) b)^2)* - (N^(-e b)*(N^(-binaryTreeExponent e b))^2) := by ring - _ = _ := by rw [hr] - -theorem binaryTreeBudget_const (A : ℝ) (b : ℕ) : - binaryTreeBudget (fun _=>A) b=A^(2^b-1) := by - induction b with - | zero => simp [binaryTreeBudget] - | succ b ih => - rw [binaryTreeBudget,ih,←pow_mul,←pow_succ'] - congr 1 - have hp : 1 ≤ 2^b := Nat.one_le_pow b 2 (by omega) - rw [pow_succ] - omega - -theorem source_interior_product (T : ℕ → ℕ) (b : ℕ) : - (∏j : Fin (b+1),if j.val=0 then 1 else T j.val)=∏j∈Finset.range b,T (j+1) := by - rw [Fin.prod_univ_succ] - simp only [Fin.val_zero,ite_true,Fin.val_succ,Nat.add_eq_zero_iff,one_ne_zero,and_false,ite_false,one_mul] - exact Fin.prod_univ_eq_prod_range (fun j => T (j+1)) b - -/-- Pull all extra selected leaves into the sparse-degree small factor. - Only the mandatory 2^(b+1) bottom leaves pay the old score exponent. -/ -theorem sourceForcedBudget_degree_factor (T n : ℕ → ℕ) (s b r : ℕ) (ω w : ℝ) - (hr : 2^(b+1) ≤ r) : - w^(2*r)*sourceForcedBudget T n s b r ω= - (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)* - (w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ))^(r-2^(b+1))* - (w^2)^(2^(b+1))* - ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* - binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) := by - unfold sourceForcedBudget interiorLabelBudget sourceSparseCount - rw [source_interior_product] - push_cast - have hwr : w^(2*r)=(w^2)^(r-2^(b+1))*(w^2)^(2^(b+1)) := by - rw [←pow_add,Nat.sub_add_cancel hr,pow_mul] - rw [hwr] - simp only [mul_pow,pow_mul] - ring - -/-- The remaining extra-degree factor costs no scale power. -/ -theorem sourceForcedBudget_degree_le (T n : ℕ → ℕ) (s b r : ℕ) (ω w : ℝ) - (hr : 2^(b+1) ≤ r) - (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) : - w^(2*r)*sourceForcedBudget T n s b r ω ≤ - (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*(w^2)^(2^(b+1))* - ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* - binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) := by - rw [sourceForcedBudget_degree_factor T n s b r ω w hr] - have hfac : (w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ))^(r-2^(b+1)) ≤ 1 := - pow_le_one₀ (by positivity) hsmall - have htree := binaryTreeBudget_nonneg - (fun j => 4*((2^s:ℕ):ℝ)^6*hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) - (fun j => mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) - (hiddenBinomialCap_nonneg _ _)) b - have hroot := hiddenBinomialCap_nonneg (n b) ω - have hmul := mul_le_mul_of_nonneg_left hfac - (show 0 ≤ (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ) by positivity) - simp only [mul_one] at hmul - exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hmul (by positivity)) (by positivity) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem hiddenBinomialCap_rpow {N e F K ω : ℝ} {m : ℕ} - (hN : 0 < N) (hF : 0 < F) (hK : 0 ≤ K) - (hm : N^e/F ≤ (m:ℝ)) (hcoef : 4*F ≤ K^2*ω^2) : - hiddenBinomialCap m ω ≤ K*N^(-e/2) := by - have hpow : (N^(-e/2))^2=N^(-e) := by - rw [←Real.rpow_natCast,←Real.rpow_mul hN.le] - norm_num only [Nat.cast_ofNat] - congr 1 - ring - have hprod : N^(-e)*N^e=1 := by rw [←Real.rpow_add hN,neg_add_cancel,Real.rpow_zero] - unfold hiddenBinomialCap - apply (Real.sqrt_le_left (mul_nonneg hK (Real.rpow_nonneg hN.le _))).mpr - rw [mul_pow,hpow] - apply (div_le_iff₀ (by positivity : (0:ℝ)<(m:ℝ)*ω^2+2)).mpr - have hh : 4 ≤ K^2*ω^2/F := (le_div_iff₀ hF).mpr hcoef - calc - 4 ≤ K^2*ω^2/F := hh - _ = K^2*N^(-e)*(N^e/F*ω^2) := by - calc - _ = (K^2*ω^2/F)*(N^(-e)*N^e) := by rw [hprod,mul_one] - _ = _ := by ring - _ ≤ K^2*N^(-e)*((m:ℝ)*ω^2+2) := by - apply mul_le_mul_of_nonneg_left _ (by positivity) - have hh' := mul_le_mul_of_nonneg_right hm (sq_nonneg ω) - linarith only [hh'] - -/-- The exact exponent in the skeleton budget equals the manuscript's - forcedDecay, not an arbitrary favorable surrogate. -/ -theorem forcedDecay_binary (b : ℕ) (ε d : ℝ) (hb : 1 ≤ b) : - forcedDecay b ε d=ε/2+ - binaryTreeExponent (fun j=>scaleKappa b (j+2) ε/2+ε) (b-1)+ - (2:ℝ)^b*scaleA b 0 ε*d := by - rw [forcedDecay,binaryTreeExponent_sum] - congr 2 - apply Finset.sum_congr rfl - intro j _ - have he : (2:ℝ)^b/2^(j+2)=2^(b-1)/2^(j+1) := by - rw [show b=(b-1)+1 by omega,pow_succ] - simp only [Nat.add_sub_cancel] - rw [show j+2=(j+1)+1 by omega,pow_succ] - field_simp - rw [he] - -def sourceSkeletonPrefactor (s b : ℕ) (K : ℝ) : ℝ := - (2*((2^s:ℕ):ℝ)^3*K)*binaryTreeBudget (fun _=>4*((2^s:ℕ):ℝ)^6*K^2) b - -theorem sourceSkeletonPrefactor_nonneg (s b : ℕ) {K : ℝ} (hK : 0 ≤ K) : - 0 ≤ sourceSkeletonPrefactor s b K := by - have h := binaryTreeBudget_nonneg (fun _=>4*((2^s:ℕ):ℝ)^6*K^2) (fun _=>by positivity) b - unfold sourceSkeletonPrefactor - positivity - -theorem source_forced_core_bound (T n : ℕ → ℕ) (s b : ℕ) (ω N ε K : ℝ) - (hN : 0 < N) (hK : 0 ≤ K) - (hn : ∀j ≤ b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) - (hg : ∀j < b,hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω ≤ - K*N^(-(scaleKappa (b+1) (j+2) ε+ε)/2)) : - (2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* - binaryTreeBudget (fun j=>4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b ≤ - sourceSkeletonPrefactor s b K* - N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b)) := by - let A := 4*((2^s:ℕ):ℝ)^6*K^2 - let e := fun j=>scaleKappa (b+1) (j+2) ε/2+ε - have hpoints (j : ℕ) (hj : jmul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) - (hiddenBinomialCap_nonneg _ _)) hpoints - rw [binaryTreeBudget_scaled A N hN e b] at htree - have ht0 := binaryTreeBudget_nonneg (fun j=>4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) - (fun j=>mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) - (hiddenBinomialCap_nonneg _ _)) b - calc - _ ≤ (2*((2^s:ℕ):ℝ)^3*(K*N^(-ε/2)))* - (binaryTreeBudget (fun _=>A) b*N^(-binaryTreeExponent e b)) := - mul_le_mul (mul_le_mul_of_nonneg_left (hn b le_rfl) (by positivity)) htree ht0 (by positivity) - _ = _ := by - have hr : N^(-ε/2)*N^(-binaryTreeExponent e b)=N^(-(ε/2+binaryTreeExponent e b)) := by - rw [←Real.rpow_add hN] - congr 1 - ring - dsimp [sourceSkeletonPrefactor] - calc - _ = (2*((2^s:ℕ):ℝ)^3*K)*binaryTreeBudget (fun _=>A) b* - (N^(-ε/2)*N^(-binaryTreeExponent e b)) := by ring - _ = _ := by rw [hr] - -/-- The sharp forced degree has the full decay gain, after all actual - source caps and the old-score factor have been multiplied. -/ -theorem source_forced_degree_decay (T n : ℕ → ℕ) (s b r : ℕ) (ω N ε d K W w : ℝ) - (hN : 0 < N) (hK : 0 ≤ K) (hW : 0 ≤ W) (hr : 2^(b+1) ≤ r) - (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) - (hw : w^2 ≤ W*N^(-scaleA (b+1) 0 ε*d)) - (hn : ∀j ≤ b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) - (hg : ∀j < b,hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω ≤ - K*N^(-(scaleKappa (b+1) (j+2) ε+ε)/2)) : - w^(2*r)*sourceForcedBudget T n s b r ω ≤ - (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*W^(2^(b+1))* - sourceSkeletonPrefactor s b K*N^(-forcedDecay (b+1) ε d) := by - have hstart := sourceForcedBudget_degree_le T n s b r ω w hr hsmall - have hcore := source_forced_core_bound T n s b ω N ε K hN hK hn hg - have hpow := pow_le_pow_left₀ (sq_nonneg w) hw (2^(b+1)) - have hpref := sourceSkeletonPrefactor_nonneg s b hK - have hcore0 := sourceForcedBudget_nonneg T n s b r ω - have ht := binaryTreeBudget_nonneg (fun j=>4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) - (fun j=>mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) - (hiddenBinomialCap_nonneg _ _)) b - have hroot := hiddenBinomialCap_nonneg (n b) ω - apply hstart.trans - apply le_trans (mul_le_mul - (mul_le_mul_of_nonneg_left hpow (by positivity)) hcore (by positivity) (by positivity)) - apply le_of_eq - rw [mul_pow] - have hrp : (N^(-scaleA (b+1) 0 ε*d))^(2^(b+1))* - N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b))= - N^(-forcedDecay (b+1) ε d) := by - rw [←Real.rpow_natCast,←Real.rpow_mul hN.le,←Real.rpow_add hN, - forcedDecay_binary (b+1) ε d (by omega)] - simp only [Nat.add_sub_cancel,Nat.cast_pow,Nat.cast_ofNat] - congr 1 - ring - calc - _ = (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*W^(2^(b+1))*sourceSkeletonPrefactor s b K* - ((N^(-scaleA (b+1) 0 ε*d))^(2^(b+1))* - N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b))) := by ring - _ = _ := by rw [hrp] - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.InitialRates + +namespace OAI + +/-! +# LayoutRates + +Integer block schedules, rounding, length and trial margins, sparse gaps, and forced-anchor decay. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The source integer window size, with zero-based nesting index. -/ +def sourceWindowSize (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : ℕ := + 4*⌊N^(scaleKappa b (j+1) ε)/4⌋₊ + +/-- At a nonroot node the source trial count is an even integer. -/ +def sourceLocalTrials (P h : ℕ) : ℕ := 2*(P/(100*(2*h+1))) + +/-- The root schedule count: the literal floor after subtracting its window. -/ +def sourceRootTrials (N : ℝ) (S T h : ℕ) : ℕ := + (⌊N/(S:ℝ)⌋₊-T)/(2*h+1) + +/-- Literal length and overlap-count state of one nested source block. + `copies` and `trials` refer to the transition into this state. -/ +structure SourceArithmeticStage where + length : ℕ + count : ℕ + copies : ℕ + trials : ℕ + +def sourceArithmeticStages (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) : + ℕ → SourceArithmeticStage + | 0 => ⟨ell,k,1,0⟩ + | j+1 => + let prev := sourceArithmeticStages C N b ε ell k j + let T := sourceWindowSize N b ε j + let J := sourceRootTrials N prev.length T prev.count + let P := if j+1=b then J*(2*prev.count+1)+T + else ⌊N^(scaleA b (j+1) ε)/(prev.length:ℝ)⌋₊ + let m := if j+1=b then J else sourceLocalTrials P prev.count + ⟨prev.length*P,⌈C*prev.count*P⌉₊,P,m⟩ + +def sourceArithmeticP (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := + (sourceArithmeticStages C N b ε ell k (j+1)).copies + +def sourceArithmeticTrials (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := + (sourceArithmeticStages C N b ε ell k (j+1)).trials + +def sourceArithmeticLength (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := + (sourceArithmeticStages C N b ε ell k j).length + +def sourceArithmeticCount (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (j : ℕ) : ℕ := + (sourceArithmeticStages C N b ε ell k j).count + +theorem sourceLocalTrials_even (P h : ℕ) : Even (sourceLocalTrials P h) := + even_two_mul _ + +theorem sourceLocalTrials_budget (P h : ℕ) : + 50*sourceLocalTrials P h*(2*h+1) ≤ P := by + have H := Nat.mul_div_le P (100*(2*h+1)) + unfold sourceLocalTrials + nlinarith only [H] + +theorem sourceLocalTrials_reserves (P T h : ℕ) (hT : 2*T ≤ P) : + 2*sourceLayoutReserve (sourceLocalTrials P h) h ≤ (P-T)/2 ∧ + 2*sourceLayoutReserve (sourceLocalTrials P h) h ≤ P-T-(P-T)/2 := by + have H := sourceLocalTrials_budget P h + rw [mul_assoc] at H + have he : sourceLocalTrials P h/2=P/(100*(2*h+1)) := by + unfold sourceLocalTrials + omega + have hr : 2*sourceLayoutReserve (sourceLocalTrials P h) h= + sourceLocalTrials P h*(2*h+1) := by + unfold sourceLayoutReserve + rw [he] + unfold sourceLocalTrials + ring + rw [hr] + have hm : 2*(sourceLocalTrials P h*(2*h+1)) ≤ P-T := by omega + constructor <;> omega + +theorem sourceWindowSize_even (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : + Even (sourceWindowSize N b ε j) := by + unfold sourceWindowSize + exact ⟨2*⌊N^(scaleKappa b (j+1) ε)/4⌋₊,by ring⟩ + +theorem sourceArithmeticLength_step (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : + sourceArithmeticLength C N b ε ell k (j+1)= + sourceArithmeticLength C N b ε ell k j*sourceArithmeticP C N b ε ell k j := rfl + +theorem sourceArithmeticCount_step (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : + sourceArithmeticCount C N b ε ell k (j+1)= + ⌈C*sourceArithmeticCount C N b ε ell k j*sourceArithmeticP C N b ε ell k j⌉₊ := rfl + +theorem sourceArithmetic_inner_trials (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) + (hj : j+1≠b) : sourceArithmeticTrials C N b ε ell k j= + sourceLocalTrials (sourceArithmeticP C N b ε ell k j) (sourceArithmeticCount C N b ε ell k j) := by + simp only [sourceArithmeticTrials,sourceArithmeticP,sourceArithmeticCount,sourceArithmeticStages,ite_eq_right hj] + +theorem sourceArithmetic_root_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k : ℕ) (hb : 1 ≤ b) : + sourceArithmeticP C N b ε ell k (b-1)= + sourceArithmeticTrials C N b ε ell k (b-1)*(2*sourceArithmeticCount C N b ε ell k (b-1)+1)+ + sourceWindowSize N b ε (b-1) := by + simp only [sourceArithmeticP,sourceArithmeticTrials,sourceArithmeticCount,sourceArithmeticStages, + Nat.sub_add_cancel hb,ite_true] + +theorem sourceArithmetic_count_lift (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) : + C*sourceArithmeticCount C N b ε ell k j*sourceArithmeticP C N b ε ell k j ≤ + sourceArithmeticCount C N b ε ell k (j+1) := Nat.le_ceil _ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Rounding the source windows loses at most a factor two. -/ +theorem sourceWindowSize_bounds {N ε : ℝ} {b j : ℕ} + (h : 8 ≤ N^(scaleKappa b (j+1) ε)) : + N^(scaleKappa b (j+1) ε)/2 ≤ (sourceWindowSize N b ε j:ℝ) ∧ + (sourceWindowSize N b ε j:ℝ) ≤ N^(scaleKappa b (j+1) ε) := by + have hlo := Nat.lt_floor_add_one (N^(scaleKappa b (j+1) ε)/4) + have hhi := Nat.floor_le (show 0 ≤ N^(scaleKappa b (j+1) ε)/4 by linarith) + unfold sourceWindowSize + push_cast + constructor <;> linarith only [h,hlo,hhi] + +/-- The nonroot even trial count is between one and two times its unrounded + quotient once the quotient is at least two. -/ +theorem sourceLocalTrials_bounds (P h : ℕ) (hlarge : (200:ℝ)*(2*h+1) ≤ P) : + (P:ℝ)/(100*(2*h+1)) ≤ (sourceLocalTrials P h:ℝ) ∧ + (sourceLocalTrials P h:ℝ) ≤ (P:ℝ)/(50*(2*h+1)) := by + have hd : 0 < (100:ℝ)*(2*h+1) := by positivity + have hx : (2:ℝ) ≤ (P:ℝ)/(100*(2*h+1)) := (le_div_iff₀ hd).mpr (by linarith only [hlarge]) + have he : (sourceLocalTrials P h:ℝ)=2*(⌊(P:ℝ)/(100*(2*h+1))⌋₊:ℝ) := by + unfold sourceLocalTrials + rw [show (100:ℝ)*(2*h+1)=((100*(2*h+1):ℕ):ℝ) by push_cast; ring,Nat.floor_div_eq_div] + norm_cast + rw [he] + have hlo := Nat.lt_floor_add_one ((P:ℝ)/(100*(2*h+1))) + have hhi := Nat.floor_le (div_nonneg (Nat.cast_nonneg P) hd.le) + constructor + · linarith only [hx,hlo] + · have heq : (P:ℝ)/(50*(2*h+1))=2*((P:ℝ)/(100*(2*h+1))) := by field_simp; ring + rw [heq] + linarith only [hhi] + +theorem source_floor_length_bounds {X : ℝ} {S : ℕ} (hS : 0 < S) (hX : 2*(S:ℝ) ≤ X) : + X/2 ≤ ((S*⌊X/(S:ℝ)⌋₊:ℕ):ℝ) ∧ ((S*⌊X/(S:ℝ)⌋₊:ℕ):ℝ) ≤ X := by + have hs : (0:ℝ) < S := by exact_mod_cast hS + have hlo := Nat.lt_floor_add_one (X/(S:ℝ)) + have hhi := Nat.floor_le (div_nonneg (show 0 ≤ X by linarith only [hX,hs]) hs.le) + have hh := mul_lt_mul_of_pos_left hlo hs + have hh' := mul_le_mul_of_nonneg_left hhi hs.le + rw [mul_add,mul_div_cancel₀ _ hs.ne'] at hh + rw [mul_div_cancel₀ _ hs.ne'] at hh' + push_cast + constructor <;> nlinarith only [hX,hh,hh'] + +/-- The real floor and integer division versions of the root are identical + whenever its remaining ambient count is nonnegative. -/ +theorem sourceRootTrials_floor {N : ℝ} {S T h : ℕ} + (hT : T ≤ ⌊N/(S:ℝ)⌋₊) : + sourceRootTrials N S T h=⌊((⌊N/(S:ℝ)⌋₊:ℝ)-T)/(2*h+1)⌋₊ := by + unfold sourceRootTrials + rw [←Nat.cast_sub hT] + rw [show (2:ℝ)*h+1=((2*h+1:ℕ):ℝ) by push_cast; ring,Nat.floor_div_eq_div] + +theorem source_root_length_bounds {N : ℝ} {S T h : ℕ} (hS : 0 < S) + (hT : T ≤ ⌊N/(S:ℝ)⌋₊) (hN : (2*h+2:ℝ)*S ≤ N/2) : + N/2 ≤ (S:ℝ)*(sourceRootTrials N S T h*(2*h+1)+T) ∧ + (S:ℝ)*(sourceRootTrials N S T h*(2*h+1)+T) ≤ N := by + have hs : (0:ℝ)= 8F. -/ +theorem source_root_margins {N X u F : ℝ} {S h T : ℕ} + (hS : 1 ≤ S) (hX : (S:ℝ) ≤ X) (hF : 1 ≤ F) (hu : 8*F ≤ u) + (hh : (h:ℝ) ≤ F*S) (hT : (T:ℝ) ≤ X) (hrel : X^2*u=N) : + T ≤ ⌊N/(S:ℝ)⌋₊ ∧ (2*(h:ℝ)+2)*S ≤ N/2 := by + have hs : (1:ℝ) ≤ S := by exact_mod_cast hS + have hx : 1 ≤ X := hs.trans hX + have hx0 : 0 ≤ X := by linarith only [hx] + have hs0 : (0:ℝ) < S := by linarith only [hs] + have hfs : 1 ≤ F*S := by nlinarith only [hF,hs] + have hsX : (S:ℝ)^2 ≤ X^2 := sq_le_sq₀ hs0.le hx0 |>.mpr hX + have h8 : 8*F*X^2 ≤ N := by nlinarith only [mul_le_mul_of_nonneg_right hu (sq_nonneg X),hrel] + constructor + · apply Nat.le_floor + apply (le_div_iff₀ hs0).mpr + have htX := mul_le_mul hT hX hs0.le hx0 + nlinarith only [htX,h8,mul_le_mul_of_nonneg_right hF (sq_nonneg X)] + · have hhS := mul_le_mul_of_nonneg_right hh hs0.le + have hS2 := mul_le_mul_of_nonneg_right hfs hs0.le + have hFsq := mul_le_mul_of_nonneg_left hsX (by linarith only [hF] : 0 ≤ F) + nlinarith only [hhS,hS2,hFsq,h8] + +theorem source_arithmetic_inner_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) + (hj : j+1≠b) : sourceArithmeticP C N b ε ell k j= + ⌊N^(scaleA b (j+1) ε)/(sourceArithmeticLength C N b ε ell k j:ℝ)⌋₊ := by + simp only [sourceArithmeticP,sourceArithmeticLength,sourceArithmeticStages,ite_eq_right hj] + +theorem source_arithmetic_root_copies (C N : ℝ) (b : ℕ) (ε : ℝ) (ell k j : ℕ) + (hj : j+1=b) : sourceArithmeticP C N b ε ell k j= + sourceRootTrials N (sourceArithmeticLength C N b ε ell k j) (sourceWindowSize N b ε j) + (sourceArithmeticCount C N b ε ell k j)* + (2*sourceArithmeticCount C N b ε ell k j+1)+sourceWindowSize N b ε j := by + simp only [sourceArithmeticP,sourceArithmeticLength,sourceArithmeticCount,sourceArithmeticStages,ite_eq_left hj] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- All nested lengths and overlap counts for the literal floors/ceilings. + Only the scalar subpower margin is needed for every rounding step. -/ +theorem source_arithmetic_lengths {C N F ε : ℝ} {b ell k : ℕ} + (hC : 2 ≤ C) (hN : 1 ≤ N) (hF : 1 ≤ F) (he : 0 ≤ ε) + (ha : ∀j ≤ b,0 ≤ scaleA b j ε) + (hsmall : 8*C^(2*b)*F ≤ N^ε) + (hell : N^(scaleA b 0 ε)/2 ≤ (ell:ℝ)) (hell' : (ell:ℝ) ≤ N^(scaleA b 0 ε)) + (hk : ell ≤ k) (hk' : (k:ℝ) ≤ F*ell) : + ∀j ≤ b, + N^(scaleA b j ε)/2 ≤ (sourceArithmeticLength C N b ε ell k j:ℝ) ∧ + (sourceArithmeticLength C N b ε ell k j:ℝ) ≤ N^(scaleA b j ε) ∧ + sourceArithmeticLength C N b ε ell k j ≤ sourceArithmeticCount C N b ε ell k j ∧ + (sourceArithmeticCount C N b ε ell k j:ℝ) ≤ + C^(2*j)*F*sourceArithmeticLength C N b ε ell k j := by + have hN0 : 0 < N := by linarith only [hN] + have hC1 : 1 ≤ C := by linarith only [hC] + intro j + induction j with + | zero => + intro _ + simpa only [sourceArithmeticLength,sourceArithmeticCount,sourceArithmeticStages, + Nat.mul_zero,pow_zero,one_mul] using And.intro hell (And.intro hell' (And.intro hk hk')) + | succ j ih => + intro hj + obtain ⟨hlo,hhi,hcount,hcount'⟩ := ih (by omega) + let S := sourceArithmeticLength C N b ε ell k j + let H := sourceArithmeticCount C N b ε ell k j + let P := sourceArithmeticP C N b ε ell k j + let Fj := C^(2*j)*F + have hFj : 1 ≤ Fj := one_le_mul_of_one_le_of_one_le (one_le_pow₀ hC1) hF + have hS0 : (0:ℝ) nlinarith only [hX,hlo,hhi,hlo',hhi'] + +theorem source_inner_trials_scale {X u F : ℝ} {S P h : ℕ} + (hX : 1 ≤ X) (hF : 1 ≤ F) (hu : 1200*F ≤ u) + (hSlo : X/2 ≤ S) (hShi : (S:ℝ) ≤ X) (hhlo : S ≤ h) (hhhi : (h:ℝ) ≤ F*S) + (hPlo : X*u/2 ≤ (P:ℝ)) (hPhi : (P:ℝ) ≤ 2*X*u) : + u/(600*F) ≤ (sourceLocalTrials P h:ℝ) ∧ (sourceLocalTrials P h:ℝ) ≤ 2*u := by + have hx : 0(q t)^3*Real.log (n t)) atTop atTop) : + ∀ᶠt in atTop,∀i ≤ sourceDepth B ζ ((q t)^3*Real.log (n t)),∀b ≤ B, + 8*(sourceOverlapConstant (q t))^(2*b)*(sourceOverlapConstant (q t))^(2*B*i+2) ≤ + (sourceTargetScale B (sourceDepth B ζ ((q t)^3*Real.log (n t))) (n t) (i+1))^ + (sourceEpsilon B (sourceDepth B ζ ((q t)^3*Real.log (n t)))) := by + let K := 8+sourceChannelLogConstant*(2*B+2) + have hK : 0 ≤ K := by dsimp [K]; positivity [sourceChannelLogConstant_pos] + have hrel (t) : Real.log (n t)=(q t)^(-3:ℤ)*((q t)^3*Real.log (n t)) := by + rw [zpow_neg,zpow_ofNat] + field_simp [(hq t).1.ne'] + have H := source_uniform_exp_absorption B 1 ζ K 1 hB hζ hK (by norm_num) hn hH + (fun t=>zpow_pos (hq t).1 _) hrel + filter_upwards [H] with t ht i hi b hb + have hh := source_count_factor_exp_bound (hq t) B (sourceDepth B ζ ((q t)^3*Real.log (n t))) b i hb hi + exact hh.trans (by simpa only [pow_one,one_mul] using ht (i+1)) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Tiny epsilon estimates are uniform in the varying block depth. -/ +theorem sourceEpsilon_power_small (B D m : ℕ) (hm : m ≤ 4*B+100) : + (2:ℝ)^m*sourceEpsilon B D ≤ 1 := by + have hp : (2:ℝ)^m ≤ 2^(4*B+100) := pow_le_pow_right₀ (by norm_num) hm + have hd : (1:ℝ) ≤ (D:ℝ)+1 := by linarith only [Nat.cast_nonneg D (α:=ℝ)] + have hmul := mul_le_mul_of_nonneg_left hd (show 0 ≤ (2:ℝ)^(4*B+100) by positivity) + unfold sourceEpsilon + rw [mul_one_div] + exact (div_le_one (by positivity)).mpr (hp.trans (by simpa only [mul_one] using hmul)) + +theorem scaleA_mono_index (b j k : ℕ) (ε : ℝ) (he : 0 ≤ ε) (hjk : j ≤ k) : + scaleA b j ε ≤ scaleA b k ε := by + unfold scaleA + exact sub_le_sub_right (div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ (by norm_num) hjk) (by linarith only [he])) + (by positivity)) _ + +theorem scaleA_le_geometric (b j : ℕ) (ε : ℝ) (he : 0 ≤ ε) (hj : j ≤ b) : + scaleA b j ε ≤ (2:ℝ)^j/2^b := by + have hp : (2:ℝ)^j ≤ 2^b := pow_le_pow_right₀ (by norm_num) hj + have hh := mul_le_mul_of_nonneg_left hp he + unfold scaleA + apply (sub_le_iff_le_add).mpr + apply (div_le_iff₀ (by positivity)).mpr + simp only [add_mul] + rw [div_mul_cancel₀ _ (by positivity : (2:ℝ)^b ≠ 0)] + nlinarith only [hh] + +theorem sourceKappa_three_epsilon (B D b j : ℕ) (hb : b ≤ B) (_hj : 1 ≤ j) (hj' : j ≤ b) : + 3*sourceEpsilon B D ≤ scaleKappa b j (sourceEpsilon B D) := by + let ε := sourceEpsilon B D + let X := (2:ℝ)^B + have he : 0 < ε := sourceEpsilon_pos _ _ + have hx : 1 ≤ X := one_le_pow₀ (by norm_num) + have hsmall := sourceEpsilon_power_small B D (2*B+4) (by omega) + have hsmall' : 16*X^2*ε ≤ 1 := by + rw [show 2*B+4=B*2+4 by omega,pow_add,pow_mul] at hsmall + norm_num only [show (2:ℝ)^4=16 by norm_num] at hsmall + dsimp [X,ε] + nlinarith only [hsmall] + have hgeom := scaleA_zero_lower b B ε hb he.le + have hmono := scaleA_mono_index b 0 (j-1) ε he.le (Nat.zero_le _) + have hp : (2:ℝ)^j ≤ X := pow_le_pow_right₀ (by norm_num) (hj'.trans hb) + have hprod : (3*X+4)*X*ε ≤ 1 := by + have hxx : 0 ≤ X*(X-1) := mul_nonneg (by linarith only [hx]) (by linarith only [hx]) + have hcmp : (3*X+4)*X ≤ 16*X^2 := by nlinarith only [hxx,sq_nonneg X] + exact (mul_le_mul_of_nonneg_right hcmp he.le).trans hsmall' + have hq : (3*X+4)*ε ≤ 1/X := (le_div_iff₀ (by linarith only [hx])).mpr (by nlinarith only [hprod]) + have hzero : 1/X-ε ≤ scaleA b 0 ε := by + have hh : (1/X)*(1-(X-1)*ε)=1/X-ε+ε/X := by field_simp; ring + dsimp [X] at hh + rw [hh] at hgeom + exact (le_add_of_nonneg_right (div_nonneg he.le (by positivity))).trans hgeom + have hpk := mul_le_mul_of_nonneg_right hp he.le + unfold scaleKappa + change 3*ε ≤ scaleA b (j-1) ε-3*(2^j-1)*ε + nlinarith only [hzero,hmono,hq,hpk,he] + +theorem sourceA_nonneg (B D b j : ℕ) (hb : b ≤ B) (hb0 : 1 ≤ b) : + 0 ≤ scaleA b j (sourceEpsilon B D) := by + have h := sourceKappa_three_epsilon B D b 1 hb (by omega) hb0 + unfold scaleKappa at h + norm_num only [Nat.sub_self,pow_one] at h + have hm := scaleA_mono_index b 0 j (sourceEpsilon B D) (sourceEpsilon_pos B D).le (Nat.zero_le _) + linarith only [h,hm,sourceEpsilon_pos B D] + +/-- The interior scale mass excludes the bottom window, as required by the + sparse role count rather than the much larger total leaf count. -/ +def sourceInteriorExponent (b : ℕ) (ε : ℝ) : ℝ := + ∑j∈Finset.range (b-1),scaleKappa b (j+2) ε + +theorem two_power_sum_shift (m : ℕ) : + (∑j∈Finset.range m,(2:ℝ)^(j+1))=2^(m+1)-2 := by + induction m with + | zero => norm_num + | succ m ih => rw [Finset.sum_range_succ,ih,pow_succ (2:ℝ) (m+1)]; ring + +theorem sourceInteriorExponent_upper (b : ℕ) (ε : ℝ) (hb : 1 ≤ b) (he : 0 ≤ ε) : + sourceInteriorExponent b ε ≤ 1-2/(2:ℝ)^b := by + have hterm (j : ℕ) (hj : j∈Finset.range (b-1)) : + scaleKappa b (j+2) ε ≤ (2:ℝ)^(j+1)/2^b := by + have hj' := Finset.mem_range.mp hj + have ha := scaleA_le_geometric b (j+1) ε he (by omega) + have hp : (1:ℝ) ≤ 2^(j+2) := one_le_pow₀ (by norm_num) + unfold scaleKappa + simp only [show j+2-1=j+1 by omega] + linarith only [ha,mul_nonneg (sub_nonneg.mpr hp) he] + apply (Finset.sum_le_sum hterm).trans_eq + rw [←Finset.sum_div,two_power_sum_shift,Nat.sub_add_cancel hb] + field_simp + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem scaleA_zero_simple_lower (b : ℕ) (ε : ℝ) (he : 0 ≤ ε) : + 1/(2:ℝ)^b-ε ≤ scaleA b 0 ε := by + unfold scaleA + norm_num only [pow_zero,mul_one] + exact sub_le_sub_right (div_le_div_of_nonneg_right (by linarith only [he]) (by positivity)) _ + +/-- Quantitative sparse gap, keeping its growth in d. Both the two-dimensional + warmup and the post-warmup dimension satisfy this common estimate. -/ +theorem source_sparse_gap (B D b : ℕ) (d : ℝ) (hb1 : 1 ≤ b) (_hb : b ≤ B) + (hd : 11/5 ≤ d) (hcases : b=2 ∨ (b=B ∧ (2:ℝ)^B+2 ≤ d)) : + (d+1)/(128*(2:ℝ)^(2*B)) ≤ + scaleA b 0 (sourceEpsilon B D)*d-sourceInteriorExponent b (sourceEpsilon B D) := by + let X := (2:ℝ)^B + let ε := sourceEpsilon B D + have hx : 1 ≤ X := one_le_pow₀ (by norm_num) + have hx0 : 0 < X := by linarith only [hx] + have hd0 : 0 ≤ d := by linarith only [hd] + have he : 0 < ε := sourceEpsilon_pos B D + have hA := mul_le_mul_of_nonneg_right (scaleA_zero_simple_lower b ε he.le) hd0 + have hI := sourceInteriorExponent_upper b ε hb1 he.le + have hcoeff : (d+1)/(64*X^2) ≤ (d+2)/(2:ℝ)^b-1 := by + rcases hcases with htwo | ⟨hmain,hdmain⟩ + · rw [htwo] + have hstep : (d+1)/(64*X^2) ≤ (d+1)/64 := by + apply div_le_div_of_nonneg_left (by linarith only [hd]) (by norm_num) + nlinarith only [hx,sq_nonneg (X-1)] + apply hstep.trans + norm_num only [show (2:ℝ)^2=4 by norm_num] + linarith only [hd] + · rw [hmain] + change (d+1)/(64*X^2) ≤ (d+2)/X-1 + apply (div_le_iff₀ (by positivity : (0:ℝ)<64*X^2)).mpr + have heq : ((d+2)/X-1)*(64*X^2)=64*X*(d+2-X) := by field_simp + rw [heq] + have hh : 0 ≤ (d-X-2)*(64*X-1) := mul_nonneg (by dsimp [X]; linarith only [hdmain]) + (by linarith only [hx]) + nlinarith only [hh,hx] + have hsmall := sourceEpsilon_power_small B D (2*B+8) (by omega) + have hsmall' : 256*X^2*ε ≤ 1 := by + rw [show 2*B+8=B*2+8 by omega,pow_add,pow_mul] at hsmall + norm_num only [show (2:ℝ)^8=256 by norm_num] at hsmall + dsimp [X,ε] + nlinarith only [hsmall] + have herr : ε*d ≤ (d+1)/(256*X^2) := by + apply (le_div_iff₀ (by positivity : (0:ℝ)<256*X^2)).mpr + have hh := mul_le_mul_of_nonneg_right hsmall' hd0 + nlinarith only [hh] + have hpow : (2:ℝ)^(2*B)=X^2 := by dsimp [X]; rw [Nat.mul_comm,pow_mul] + rw [hpow] + change (d+1)/(128*X^2) ≤ scaleA b 0 ε*d-sourceInteriorExponent b ε + have hp : 0 < (2:ℝ)^b := by positivity + have hc : (1/(2:ℝ)^b-ε)*d-(1-2/(2:ℝ)^b)=((d+2)/(2:ℝ)^b-1)-ε*d := by ring + have hbase := sub_le_sub hA hI + rw [hc] at hbase + have hident : (d+1)/(64*X^2)-(d+1)/(256*X^2)=3*(d+1)/(256*X^2) := by ring + have hlo := (sub_le_sub hcoeff herr).trans hbase + rw [hident] at hlo + have hcompare : (d+1)/(128*X^2) ≤ 3*(d+1)/(256*X^2) := by + have hh : (d+1)/128 ≤ 3*(d+1)/256 := by linarith only [hd] + simpa only [div_div] using div_le_div_of_nonneg_right hh (sq_nonneg X) + exact hcompare.trans hlo + +theorem totalScoreExponent_step (B i : ℕ) : + totalScoreExponent B (i+1)=totalScoreExponent B i+blockGain (sourceDimension B i) := by + unfold totalScoreExponent sourceDimension + rw [Finset.sum_range_succ] + ring + +theorem totalScoreExponent_after_warmup (B i : ℕ) (hB : 2 ≤ B) (hi : warmupBlocks B ≤ i) : + (2:ℝ)^B+11/5 ≤ totalScoreExponent B i := by + rw [totalScoreExponent_exact B i hi] + have hm : (0:ℝ) ≤ ((i:ℝ)-warmupBlocks B)*blockGain B := + mul_nonneg (sub_nonneg.mpr (by exact_mod_cast hi)) (blockGain_pos B hB).le + unfold warmupBlocks at * + push_cast at * + linarith only [hm] + +theorem source_level_sparse_gap (B D i : ℕ) (hB : 2 ≤ B) : + (totalScoreExponent B i+1)/(128*(2:ℝ)^(2*B)) ≤ + scaleA (sourceDimension B i) 0 (sourceEpsilon B D)*totalScoreExponent B i- + sourceInteriorExponent (sourceDimension B i) (sourceEpsilon B D) := by + have hb : 2 ≤ sourceDimension B i ∧ sourceDimension B i ≤ B := by + unfold sourceDimension + split_ifs <;> omega + apply source_sparse_gap B D _ _ (by omega) hb.2 (totalScoreExponent_bounds B i hB).1 + unfold sourceDimension + split_ifs with hi + · exact Or.inl rfl + · exact Or.inr ⟨rfl,by linarith only [totalScoreExponent_after_warmup B i hB (by omega)]⟩ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Levels outside the finite source block are irrelevant. Their harmless + positive extension permits the global-index API of the finite tree lemmas. -/ +def sourceBlockWindows (N : ℝ) (b : ℕ) (ε : ℝ) (j : ℕ) : ℕ := + if j ⟨(H j hj).1,(H j hj).2.1⟩,fun j hj => (H j hj).2.2,hcopies,htrials,?_⟩ + intro j hj + rw [sourceBlockWindows,ite_eq_left hj] + have hp := hcopies j hj + have ht := htrials j hj + have hu3 : u^3 ≤ N^(scaleKappa b (j+1) ε) := by + dsimp [u] + rw [←Real.rpow_natCast,←Real.rpow_mul hN0.le] + norm_num only [Nat.cast_ofNat] + apply Real.rpow_le_rpow_of_exponent_le hN + linarith only [hκ j hj] + have hu32 : 64*u ≤ u^3 := by + have hu_sq : 64 ≤ u^2 := by nlinarith only [hu8,sq_nonneg (u-8)] + nlinarith only [mul_le_mul_of_nonneg_right hu_sq (by linarith only [hu8] : 0 ≤ u)] + have hw := sourceWindowSize_bounds (show 8 ≤ N^(scaleKappa b (j+1) ε) by linarith only [hu32,hu8,hu3]) + have hwbig : u^3/2 ≤ (sourceWindowSize N b ε j:ℝ) := le_trans (by linarith only [hu3] : u^3/2 ≤ N^(scaleKappa b (j+1) ε)/2) hw.1 + have hwp := sourceWindowSize_le_previous (b:=b) (j:=j) hN he + have hX : 0 ≤ N^(scaleA b j ε) := (Real.rpow_pos_of_pos hN0 _).le + have hambient : (2:ℝ)*(sourceWindowSize N b ε j:ℝ) ≤ sourceArithmeticP C N b ε ell k j := by + have hh := mul_le_mul_of_nonneg_right hu8 hX + nlinarith only [hp.1,hwp,hh] + have h24 : (24:ℝ) ≤ sourceWindowSize N b ε j := by linarith only [hwbig,hu32,hu8] + have hmot : (24:ℝ)*((2^s:ℕ):ℝ) ≤ sourceWindowSize N b ε j := by + have hu' : 48*((2^s:ℕ):ℝ) ≤ u := hmotif + linarith only [hwbig,hu32,hu'] + have hroot : (4:ℝ)*((sourceArithmeticTrials C N b ε ell k j:ℝ)+1) ≤ sourceWindowSize N b ε j := by + linarith only [hwbig,hu32,hu8,ht.2] + exact ⟨by exact_mod_cast h24,by exact_mod_cast hmot,by exact_mod_cast hambient,by exact_mod_cast hroot⟩ + +theorem SourceArithmeticBounds.layout {C N F ε : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) : + SourceLayoutMargins s (sourceArithmeticP C N b ε ell k) (sourceBlockWindows N b ε) + (sourceArithmeticTrials C N b ε ell k) (sourceArithmeticCount C N b ε ell k) (b-1) := by + constructor + · intro j hj + have hh := (H.windows j (by omega)).1 + omega + · intro j hj + have hh := (H.windows j (by omega)).1 + omega + · intro j hj + rw [sourceBlockWindows,ite_eq_left (by omega)] + exact sourceWindowSize_even N b ε j + · intro j hj + exact (H.windows j (by omega)).2.2.1 + · intro j hj + have hh := (H.windows j (by omega)).2.1 + omega + · intro j hj + rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] + exact sourceLocalTrials_even _ _ + · intro j hj + rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] + exact (sourceLocalTrials_reserves _ _ _ (H.windows j (by omega)).2.2.1).1 + · intro j hj + rw [sourceArithmetic_inner_trials C N b ε ell k j (by omega)] + exact (sourceLocalTrials_reserves _ _ _ (H.windows j (by omega)).2.2.1).2 + +theorem SourceArithmeticBounds.window_positive {C N F ε : ℝ} {s b ell k : ℕ} + (H : SourceArithmeticBounds C N F ε s b ell k) (j : ℕ) : + 0 < sourceBlockWindows N b ε j := by + by_cases hj : j 0 + | b+1 => e b+2*binaryTreeExponent e b + +theorem binaryTreeExponent_sum (e : ℕ → ℝ) (b : ℕ) : + binaryTreeExponent e b=∑j∈Finset.range b,((2:ℝ)^b/2^(j+1))*e j := by + induction b with + | zero => simp [binaryTreeExponent] + | succ b ih => + rw [binaryTreeExponent,ih,Finset.sum_range_succ,Finset.mul_sum] + have he : (∑j∈Finset.range b,((2:ℝ)^(b+1)/2^(j+1))*e j)= + ∑j∈Finset.range b,2*((2^b/2^(j+1))*e j) := by + apply Finset.sum_congr rfl + intro j _ + rw [pow_succ] + ring + rw [he] + simp only [div_self (by positivity : (2:ℝ)^(b+1)≠0),one_mul] + ring + +theorem binaryTreeBudget_mono {C D : ℕ → ℝ} (b : ℕ) + (hC : ∀j < b,0 ≤ C j) (hCD : ∀j < b,C j ≤ D j) : + binaryTreeBudget C b ≤ binaryTreeBudget D b := by + induction b with + | zero => rfl + | succ b ih => + have hc : 0 ≤ binaryTreeBudget C b := by + cases b with + | zero => norm_num [binaryTreeBudget] + | succ j => exact mul_nonneg (hC j (by omega)) (sq_nonneg _) + have hd := ih (fun j hj=>hC j (by omega)) (fun j hj=>hCD j (by omega)) + rw [binaryTreeBudget,binaryTreeBudget] + exact mul_le_mul (hCD b (by omega)) (pow_le_pow_left₀ hc hd 2) + (sq_nonneg _) ((hC b (by omega)).trans (hCD b (by omega))) + +theorem binaryTreeBudget_scaled (A N : ℝ) (hN : 0 < N) (e : ℕ → ℝ) (b : ℕ) : + binaryTreeBudget (fun j => A*N^(-e j)) b= + binaryTreeBudget (fun _=>A) b*N^(-binaryTreeExponent e b) := by + induction b with + | zero => simp [binaryTreeBudget,binaryTreeExponent] + | succ b ih => + rw [binaryTreeBudget,ih,binaryTreeBudget,binaryTreeExponent,mul_pow] + have hr : N^(-e b)*(N^(-binaryTreeExponent e b))^2= + N^(-(e b+2*binaryTreeExponent e b)) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hN.le,←Real.rpow_add hN] + congr 1 + norm_num only [Nat.cast_ofNat] + ring + calc + _ = (A*(binaryTreeBudget (fun _=>A) b)^2)* + (N^(-e b)*(N^(-binaryTreeExponent e b))^2) := by ring + _ = _ := by rw [hr] + +theorem binaryTreeBudget_const (A : ℝ) (b : ℕ) : + binaryTreeBudget (fun _=>A) b=A^(2^b-1) := by + induction b with + | zero => simp [binaryTreeBudget] + | succ b ih => + rw [binaryTreeBudget,ih,←pow_mul,←pow_succ'] + congr 1 + have hp : 1 ≤ 2^b := Nat.one_le_pow b 2 (by omega) + rw [pow_succ] + omega + +theorem source_interior_product (T : ℕ → ℕ) (b : ℕ) : + (∏j : Fin (b+1),if j.val=0 then 1 else T j.val)=∏j∈Finset.range b,T (j+1) := by + rw [Fin.prod_univ_succ] + simp only [Fin.val_zero,ite_true,Fin.val_succ,Nat.add_eq_zero_iff,one_ne_zero,and_false,ite_false,one_mul] + exact Fin.prod_univ_eq_prod_range (fun j => T (j+1)) b + +/-- Pull all extra selected leaves into the sparse-degree small factor. + Only the mandatory 2^(b+1) bottom leaves pay the old score exponent. -/ +theorem sourceForcedBudget_degree_factor (T n : ℕ → ℕ) (s b r : ℕ) (ω w : ℝ) + (hr : 2^(b+1) ≤ r) : + w^(2*r)*sourceForcedBudget T n s b r ω= + (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)* + (w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ))^(r-2^(b+1))* + (w^2)^(2^(b+1))* + ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* + binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) := by + unfold sourceForcedBudget interiorLabelBudget sourceSparseCount + rw [source_interior_product] + push_cast + have hwr : w^(2*r)=(w^2)^(r-2^(b+1))*(w^2)^(2^(b+1)) := by + rw [←pow_add,Nat.sub_add_cancel hr,pow_mul] + rw [hwr] + simp only [mul_pow,pow_mul] + ring + +/-- The remaining extra-degree factor costs no scale power. -/ +theorem sourceForcedBudget_degree_le (T n : ℕ → ℕ) (s b r : ℕ) (ω w : ℝ) + (hr : 2^(b+1) ≤ r) + (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) : + w^(2*r)*sourceForcedBudget T n s b r ω ≤ + (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*(w^2)^(2^(b+1))* + ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* + binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) := by + rw [sourceForcedBudget_degree_factor T n s b r ω w hr] + have hfac : (w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ))^(r-2^(b+1)) ≤ 1 := + pow_le_one₀ (by positivity) hsmall + have htree := binaryTreeBudget_nonneg + (fun j => 4*((2^s:ℕ):ℝ)^6*hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) + (fun j => mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) + (hiddenBinomialCap_nonneg _ _)) b + have hroot := hiddenBinomialCap_nonneg (n b) ω + have hmul := mul_le_mul_of_nonneg_left hfac + (show 0 ≤ (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ) by positivity) + simp only [mul_one] at hmul + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hmul (by positivity)) (by positivity) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem hiddenBinomialCap_rpow {N e F K ω : ℝ} {m : ℕ} + (hN : 0 < N) (hF : 0 < F) (hK : 0 ≤ K) + (hm : N^e/F ≤ (m:ℝ)) (hcoef : 4*F ≤ K^2*ω^2) : + hiddenBinomialCap m ω ≤ K*N^(-e/2) := by + have hpow : (N^(-e/2))^2=N^(-e) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hN.le] + norm_num only [Nat.cast_ofNat] + congr 1 + ring + have hprod : N^(-e)*N^e=1 := by rw [←Real.rpow_add hN,neg_add_cancel,Real.rpow_zero] + unfold hiddenBinomialCap + apply (Real.sqrt_le_left (mul_nonneg hK (Real.rpow_nonneg hN.le _))).mpr + rw [mul_pow,hpow] + apply (div_le_iff₀ (by positivity : (0:ℝ)<(m:ℝ)*ω^2+2)).mpr + have hh : 4 ≤ K^2*ω^2/F := (le_div_iff₀ hF).mpr hcoef + calc + 4 ≤ K^2*ω^2/F := hh + _ = K^2*N^(-e)*(N^e/F*ω^2) := by + calc + _ = (K^2*ω^2/F)*(N^(-e)*N^e) := by rw [hprod,mul_one] + _ = _ := by ring + _ ≤ K^2*N^(-e)*((m:ℝ)*ω^2+2) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + have hh' := mul_le_mul_of_nonneg_right hm (sq_nonneg ω) + linarith only [hh'] + +/-- The exact exponent in the skeleton budget equals the manuscript's + forcedDecay, not an arbitrary favorable surrogate. -/ +theorem forcedDecay_binary (b : ℕ) (ε d : ℝ) (hb : 1 ≤ b) : + forcedDecay b ε d=ε/2+ + binaryTreeExponent (fun j=>scaleKappa b (j+2) ε/2+ε) (b-1)+ + (2:ℝ)^b*scaleA b 0 ε*d := by + rw [forcedDecay,binaryTreeExponent_sum] + congr 2 + apply Finset.sum_congr rfl + intro j _ + have he : (2:ℝ)^b/2^(j+2)=2^(b-1)/2^(j+1) := by + rw [show b=(b-1)+1 by omega,pow_succ] + simp only [Nat.add_sub_cancel] + rw [show j+2=(j+1)+1 by omega,pow_succ] + field_simp + rw [he] + +def sourceSkeletonPrefactor (s b : ℕ) (K : ℝ) : ℝ := + (2*((2^s:ℕ):ℝ)^3*K)*binaryTreeBudget (fun _=>4*((2^s:ℕ):ℝ)^6*K^2) b + +theorem sourceSkeletonPrefactor_nonneg (s b : ℕ) {K : ℝ} (hK : 0 ≤ K) : + 0 ≤ sourceSkeletonPrefactor s b K := by + have h := binaryTreeBudget_nonneg (fun _=>4*((2^s:ℕ):ℝ)^6*K^2) (fun _=>by positivity) b + unfold sourceSkeletonPrefactor + positivity + +theorem source_forced_core_bound (T n : ℕ → ℕ) (s b : ℕ) (ω N ε K : ℝ) + (hN : 0 < N) (hK : 0 ≤ K) + (hn : ∀j ≤ b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) + (hg : ∀j < b,hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω ≤ + K*N^(-(scaleKappa (b+1) (j+2) ε+ε)/2)) : + (2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* + binaryTreeBudget (fun j=>4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b ≤ + sourceSkeletonPrefactor s b K* + N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b)) := by + let A := 4*((2^s:ℕ):ℝ)^6*K^2 + let e := fun j=>scaleKappa (b+1) (j+2) ε/2+ε + have hpoints (j : ℕ) (hj : jmul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) + (hiddenBinomialCap_nonneg _ _)) hpoints + rw [binaryTreeBudget_scaled A N hN e b] at htree + have ht0 := binaryTreeBudget_nonneg (fun j=>4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) + (fun j=>mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) + (hiddenBinomialCap_nonneg _ _)) b + calc + _ ≤ (2*((2^s:ℕ):ℝ)^3*(K*N^(-ε/2)))* + (binaryTreeBudget (fun _=>A) b*N^(-binaryTreeExponent e b)) := + mul_le_mul (mul_le_mul_of_nonneg_left (hn b le_rfl) (by positivity)) htree ht0 (by positivity) + _ = _ := by + have hr : N^(-ε/2)*N^(-binaryTreeExponent e b)=N^(-(ε/2+binaryTreeExponent e b)) := by + rw [←Real.rpow_add hN] + congr 1 + ring + dsimp [sourceSkeletonPrefactor] + calc + _ = (2*((2^s:ℕ):ℝ)^3*K)*binaryTreeBudget (fun _=>A) b* + (N^(-ε/2)*N^(-binaryTreeExponent e b)) := by ring + _ = _ := by rw [hr] + +/-- The sharp forced degree has the full decay gain, after all actual + source caps and the old-score factor have been multiplied. -/ +theorem source_forced_degree_decay (T n : ℕ → ℕ) (s b r : ℕ) (ω N ε d K W w : ℝ) + (hN : 0 < N) (hK : 0 ≤ K) (hW : 0 ≤ W) (hr : 2^(b+1) ≤ r) + (hsmall : w^2*((2^s:ℕ):ℝ)*(sourceSparseCount T s b:ℝ) ≤ 1) + (hw : w^2 ≤ W*N^(-scaleA (b+1) 0 ε*d)) + (hn : ∀j ≤ b,hiddenBinomialCap (n j) ω ≤ K*N^(-ε/2)) + (hg : ∀j < b,hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω ≤ + K*N^(-(scaleKappa (b+1) (j+2) ε+ε)/2)) : + w^(2*r)*sourceForcedBudget T n s b r ω ≤ + (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*W^(2^(b+1))* + sourceSkeletonPrefactor s b K*N^(-forcedDecay (b+1) ε d) := by + have hstart := sourceForcedBudget_degree_le T n s b r ω w hr hsmall + have hcore := source_forced_core_bound T n s b ω N ε K hN hK hn hg + have hpow := pow_le_pow_left₀ (sq_nonneg w) hw (2^(b+1)) + have hpref := sourceSkeletonPrefactor_nonneg s b hK + have hcore0 := sourceForcedBudget_nonneg T n s b r ω + have ht := binaryTreeBudget_nonneg (fun j=>4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) + (fun j=>mul_nonneg (mul_nonneg (by positivity) (hiddenBinomialCap_nonneg _ _)) + (hiddenBinomialCap_nonneg _ _)) b + have hroot := hiddenBinomialCap_nonneg (n b) ω + apply hstart.trans + apply le_trans (mul_le_mul + (mul_le_mul_of_nonneg_left hpow (by positivity)) hcore (by positivity) (by positivity)) + apply le_of_eq + rw [mul_pow] + have hrp : (N^(-scaleA (b+1) 0 ε*d))^(2^(b+1))* + N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b))= + N^(-forcedDecay (b+1) ε d) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hN.le,←Real.rpow_add hN, + forcedDecay_binary (b+1) ε d (by omega)] + simp only [Nat.add_sub_cancel,Nat.cast_pow,Nat.cast_ofNat] + congr 1 + ring + calc + _ = (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*W^(2^(b+1))*sourceSkeletonPrefactor s b K* + ((N^(-scaleA (b+1) 0 ε*d))^(2^(b+1))* + N^(-(ε/2+binaryTreeExponent (fun j=>scaleKappa (b+1) (j+2) ε/2+ε) b))) := by ring + _ = _ := by rw [hrp] + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/LeafOracle.lean b/lean/OAI/Probability/TraceReconstruction/LeafOracle.lean index 2b6ef00d1fcd31eefe15e360e3a2c6b84861cedd..578f82b24f9c7faa75cdc7cc869506acd24d2573 100644 --- a/lean/OAI/Probability/TraceReconstruction/LeafOracle.lean +++ b/lean/OAI/Probability/TraceReconstruction/LeafOracle.lean @@ -1,1320 +1,1320 @@ -import OAI.Probability.TraceReconstruction.InitialOverlap - -namespace OAI - -/-! -# LeafOracle - -Recursive leaf oracles, sparse high tails, occupied shapes, posterior smoothing, source bit trees, and singleton cancellation. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Complete window-tree leaf indices, with counts numbered from the bottom. -The tree is fixed before any occupied subset or orientation is selected. -/ -def WindowLeaf (T : ℕ → ℕ) : ℕ → Type - | 0 => Fin 1 - | b+1 => Fin (T b) × WindowLeaf T b - -noncomputable instance windowLeafFintype (T : ℕ → ℕ) : (b : ℕ) → Fintype (WindowLeaf T b) - | 0 => inferInstanceAs (Fintype (Fin 1)) - | b+1 => by - letI := windowLeafFintype T b - exact inferInstanceAs (Fintype (Fin (T b) × WindowLeaf T b)) - -/-- A motif's actual outgoing type, allowing every integer displacement. -/ -def motifChildSign (s : ℕ) (X : ℤ) (h : ℕ) (τ : ℝ) : ℝ := - 1-motifIndicator s ((h:ℤ)-X)+(prouhetSeries s).coeff ((h:ℤ)-X)*τ - -theorem motifChildSign_isSign (s : ℕ) (X : ℤ) (h : ℕ) {τ : ℝ} (hτ : IsTypeSign τ) : - IsTypeSign (motifChildSign s X h τ) := - motif_child_sign (prouhet_motif_value s ((h:ℤ)-X)) hτ - -theorem motifChildSign_negative_active (s : ℕ) (X : ℤ) (h : ℕ) (τ : ℝ) - (ht : motifChildSign s X h τ= -1) : 0 ≤ (h:ℤ)-X ∧ (h:ℤ)-X<(2^s:ℕ) := by - by_contra hn - have hz := (prouhetSeries_coeff_spec s).1 ((h:ℤ)-X) (by omega) - simp only [motifChildSign,motifIndicator,ite_eq_right hn,hz,zero_mul,sub_zero,add_zero] at ht - norm_num at ht - -/-- Literal top-down type recursion in the source's unconditioned surrogate. -`X path` is the root anchor or `w_j-Y_path`. Dependence of different paths -through the same global jitter is retained by this single full-tree map. -/ -def windowLeafSign (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : - (b : ℕ) → List ℕ → ℝ → WindowLeaf T b → ℝ - | 0, _, τ, _ => τ - | b+1, path, τ, v => windowLeafSign T s X b (path++[v.1.val]) - (motifChildSign s (X path) v.1.val τ) v.2 - -theorem windowLeafSign_isSign (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) {τ : ℝ} (hτ : IsTypeSign τ) (v : WindowLeaf T b) : - IsTypeSign (windowLeafSign T s X b path τ v) := by - induction b generalizing path τ with - | zero => exact hτ - | succ b ih => exact ih _ (motifChildSign_isSign s _ _ hτ) v.2 - -def windowLeafType (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (τ : ℝ) (v : WindowLeaf T b) : Bool := - decide (windowLeafSign T s X b path τ v= -1) - -theorem windowLeafType_weight (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) {τ : ℝ} (hτ : IsTypeSign τ) (v : WindowLeaf T b) : - (if windowLeafType T s X b path τ v then (1:ℝ) else 0)= - (1-windowLeafSign T s X b path τ v)/2 := by - rcases windowLeafSign_isSign T s X b path hτ v with hp | hm - · norm_num [windowLeafType,hp] - · norm_num [windowLeafType,hm] - -/-- A finite indexing of all leaves, not just the active or fitted leaves. -/ -def windowFinType (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (τ : ℝ) (i : Fin (Fintype.card (WindowLeaf T b))) : Bool := - windowLeafType T s X b [] τ ((Fintype.equivFin (WindowLeaf T b)).symm i) - -/-- The actual mixed leaf oracle at arbitrary exact metadata. The one latent -law governs the whole map X; no independent-anchor law is substituted. -/ -def recursiveLeafLaw {Ω α : Type*} [Fintype Ω] [Fintype α] - (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) - (P Q : FiniteLaw α) (τ : ℝ) : - FiniteLaw (Fin (Fintype.card (WindowLeaf T b)) → α) := - R.mixture (fun ω => coordinateProduct (fun i => if windowFinType T s (X ω) b τ i then Q else P)) - -theorem recursiveLeafLaw_density {Ω α : Type*} [Fintype Ω] [Fintype α] - (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) - (P Q : FiniteLaw α) (Z : α → ℝ) (hZ : ∀a,Q.mass a=P.mass a*(1+Z a)) - (τ : ℝ) (x : Fin (Fintype.card (WindowLeaf T b)) → α) : - (recursiveLeafLaw R X T s b P Q τ).mass x = - (P.product (Fintype.card (WindowLeaf T b))).mass x * - multilinear (averagedCoefficient R (fun ω => windowFinType T s (X ω) b τ)) Z x := by - rw [recursiveLeafLaw,leaf_oracle_density P Q Z hZ,averagedDensity_expansion] - rfl - -/-- Pointwise recursive coefficient before averaging over the actual bits. -/ -theorem recursive_selectionCoefficient {Ω : Type*} [Fintype Ω] - (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) (ω : Ω) - {τ : ℝ} (hτ : IsTypeSign τ) (σ : Fin (Fintype.card (WindowLeaf T b)) → Bool) : - selectionCoefficient (windowFinType T s (X ω) b τ) σ = - ∏i, if σ i then - (1-windowLeafSign T s (X ω) b [] τ ((Fintype.equivFin (WindowLeaf T b)).symm i))/2 else 1 := by - unfold selectionCoefficient - apply Finset.prod_congr rfl - intro i _ - cases σ i - · rfl - · exact windowLeafType_weight T s (X ω) b [] hτ _ - -theorem motif_negative_count (s N : ℕ) (X : ℤ) (τ : ℝ) : - (Finset.univ.filter (fun i : Fin N => motifChildSign s X i.val τ= -1)).card ≤ 2^s := by - have H := Finset.card_le_card_of_injOn - (s:=Finset.univ.filter (fun i : Fin N => motifChildSign s X i.val τ= -1)) - (t:=Finset.range (2^s)) (fun i : Fin N => ((i.val:ℤ)-X).toNat) ?_ ?_ - · simpa using H - · intro i hi - have h := motifChildSign_negative_active s X i.val τ (Finset.mem_filter.mp hi).2 - apply Finset.mem_range.mpr - dsimp only - omega - · intro i hi j hj he - have h := motifChildSign_negative_active s X i.val τ (Finset.mem_filter.mp hi).2 - have h' := motifChildSign_negative_active s X j.val τ (Finset.mem_filter.mp hj).2 - apply Fin.ext - dsimp only at he - omega - -/-- Exact number of minus leaves in a fixed realization, without a fit condition. -/ -def windowMinusCount (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (τ : ℝ) : ℕ := - ∑v : WindowLeaf T b, if windowLeafSign T s X b path τ v= -1 then 1 else 0 - -theorem windowMinusCount_succ (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (τ : ℝ) : - windowMinusCount T s X (b+1) path τ = - ∑i : Fin (T b), windowMinusCount T s X b (path++[i.val]) - (motifChildSign s (X path) i.val τ) := by - unfold windowMinusCount - change (∑v : Fin (T b) × WindowLeaf T b, _) = _ - rw [Fintype.sum_prod_type] - rfl - -/-- Source the block layout high-degree budget, bottom motif length times all -upper window counts. It holds for every latent realization, typical or not. -/ -theorem windowMinusCount_bound (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (τ : ℝ) : - windowMinusCount T s X (b+1) path τ ≤ - 2^s * ∏j∈Finset.range b, T (j+1) := by - induction b generalizing path τ with - | zero => - rw [windowMinusCount_succ] - change (∑i : Fin (T 0), ∑v : Fin 1, - if motifChildSign s (X path) i.val τ= -1 then (1:ℕ) else 0) ≤ _ - simp only [Fin.sum_univ_one,Finset.range_zero,Finset.prod_empty,mul_one] - simpa only [Finset.card_filter] using motif_negative_count s (T 0) (X path) τ - | succ b ih => - rw [windowMinusCount_succ] - calc - _ ≤ ∑i : Fin (T (b+1)), 2^s*∏j∈Finset.range b,T (j+1) := - Finset.sum_le_sum (fun _ _ => ih _ _) - _ = _ := by simp [Finset.prod_range_succ]; ring - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -def boolSupport {n : ℕ} (θ : Fin n → Bool) : Finset (Fin n) := - Finset.univ.filter (fun i => θ i=true) - -theorem boolSupport_injective {n : ℕ} : Function.Injective (boolSupport (n:=n)) := by - intro θ φ h - funext i - have hi : (θ i=true) ↔ (φ i=true) := by - simpa [boolSupport] using Finset.ext_iff.mp h i - cases hθ : θ i <;> cases hφ : φ i <;> simp_all - -theorem selectionCoefficient_eq_support {n : ℕ} (θ σ : Fin n → Bool) : - selectionCoefficient θ σ = if boolSupport σ ⊆ boolSupport θ then 1 else 0 := by - by_cases h : boolSupport σ ⊆ boolSupport θ - · rw [ite_eq_left h] - apply Finset.prod_eq_one - intro i _ - cases hs : σ i - · simp - · have ht : θ i=true := by simpa [boolSupport] using h (by simp [boolSupport,hs]) - simp [ht] - · rw [ite_eq_right h] - obtain ⟨i,hi,hni⟩ := Finset.not_subset.mp h - have hs : σ i=true := by simpa [boolSupport] using hi - have ht : θ i=false := by simpa [boolSupport] using hni - apply Finset.prod_eq_zero (Finset.mem_univ i) - simp [hs,ht] - -/-- Uniform cardinality bound for the actual selected monomials of a sparse -0/1 coefficient vector; mixing does not add a squared-cardinality loss. -/ -theorem selection_degree_sum_le {n : ℕ} (θ : Fin n → Bool) (r : ℕ) : - (∑σ : Fin n → Bool, if monomialDegree σ=r then selectionCoefficient θ σ else 0) ≤ - ((monomialDegree θ).choose r:ℝ) := by - have hc : (Finset.univ.filter (fun σ : Fin n → Bool => - monomialDegree σ=r ∧ boolSupport σ ⊆ boolSupport θ)).card ≤ - ((boolSupport θ).powersetCard r).card := by - apply Finset.card_le_card_of_injOn boolSupport - · intro σ hσ - rcases (Finset.mem_filter.mp hσ).2 with ⟨hd,hs⟩ - exact Finset.mem_powersetCard.mpr ⟨hs,hd⟩ - · exact boolSupport_injective.injOn - rw [Finset.card_powersetCard] at hc - have he : (∑σ : Fin n → Bool, if monomialDegree σ=r then selectionCoefficient θ σ else 0) = - ((Finset.univ.filter (fun σ : Fin n → Bool => - monomialDegree σ=r ∧ boolSupport σ ⊆ boolSupport θ)).card:ℝ) := by - simp_rw [selectionCoefficient_eq_support,←ite_and] - exact Finset.sum_boole _ _ - rw [he] - exact_mod_cast hc - -theorem averaged_sparse_degree {Ω : Type*} [Fintype Ω] {n A : ℕ} - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (hA : ∀ω, monomialDegree (θ ω) ≤ A) (r : ℕ) : - (∑σ : Fin n → Bool, if monomialDegree σ=r then averagedCoefficient R θ σ^2 else 0) ≤ - (A.choose r:ℝ) := by - calc - _ ≤ ∑σ : Fin n → Bool, if monomialDegree σ=r then averagedCoefficient R θ σ else 0 := by - apply Finset.sum_le_sum - intro σ _ - split_ifs - · have hc := coefficient_nonneg R θ σ - have h1 := coefficient_le_one R θ σ - nlinarith [mul_nonneg hc (sub_nonneg.mpr h1)] - · rfl - _ = ∑ω, R.mass ω * ∑σ : Fin n → Bool, - if monomialDegree σ=r then selectionCoefficient (θ ω) σ else 0 := by - unfold averagedCoefficient FiniteLaw.expect - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro σ _ - by_cases h : monomialDegree σ=r <;> simp [h] - _ ≤ ∑ω, R.mass ω * (A.choose r:ℝ) := by - apply Finset.sum_le_sum - intro ω _ - apply mul_le_mul_of_nonneg_left _ (R.nonneg ω) - exact (selection_degree_sum_le (θ ω) r).trans (by - exact_mod_cast Nat.choose_le_choose r (hA ω)) - _ = _ := by rw [←Finset.sum_mul,R.total,one_mul] - -/-- Genuine sparse complete-tree leaf count in the exact Fin indexing used -by the independent-product reference law. -/ -theorem windowFinType_degree (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (τ : ℝ) : - monomialDegree (windowFinType T s X b τ) = windowMinusCount T s X b [] τ := by - have h := Equiv.sum_comp (Fintype.equivFin (WindowLeaf T b)).symm - (fun v => if windowLeafSign T s X b [] τ v= -1 then (1:ℕ) else 0) - simpa only [monomialDegree,Finset.card_filter,windowFinType,windowLeafType, - decide_eq_true_eq,windowMinusCount] using h - -theorem recursive_degree_bound {Ω : Type*} [Fintype Ω] - (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b r : ℕ) (τ : ℝ) : - (∑σ, if monomialDegree σ=r then - averagedCoefficient R (fun ω => windowFinType T s (X ω) (b+1) τ) σ^2 else 0) ≤ - ((2^s*∏j∈Finset.range b,T (j+1)).choose r:ℝ) := by - apply averaged_sparse_degree - intro ω - rw [windowFinType_degree] - exact windowMinusCount_bound T s (X ω) b [] τ - -def degreeTail {n : ℕ} (A : (Fin n → Bool) → ℝ) (k : ℕ) (σ : Fin n → Bool) : ℝ := - if k ≤ monomialDegree σ then A σ else 0 - -theorem degreeTail_degree {n r k : ℕ} (A : (Fin n → Bool) → ℝ) : - (∑σ, if monomialDegree σ=r then degreeTail A k σ^2 else 0) = - if k ≤ r then ∑σ, if monomialDegree σ=r then A σ^2 else 0 else 0 := by - by_cases h : k ≤ r - · rw [ite_eq_left h] - apply Finset.sum_congr rfl - intro σ _ - by_cases he : monomialDegree σ=r <;> simp [degreeTail,he,h] - · rw [ite_eq_right h] - apply Finset.sum_eq_zero - intro σ _ - by_cases he : monomialDegree σ=r <;> simp [degreeTail,he,h] - -/-- Geometric high-degree energy of an actual mixed sparse leaf law. -/ -theorem averaged_sparse_tail_energy {Ω : Type*} [Fintype Ω] {n A₀ : ℕ} - (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) - (hA : ∀ω, monomialDegree (θ ω) ≤ A₀) (k : ℕ) {w : ℝ} - (hw : 0 ≤ w) (ha : w^2*A₀ < 1) : - multilinearEnergy (degreeTail (averagedCoefficient R θ) k) w ≤ - (w^2*A₀)^k/(1-w^2*A₀) := by - have H := multilinearEnergy_low_high (R:=k) - (degreeTail (averagedCoefficient R θ) k) w (w^2*A₀) 1 hw (by positivity) ha - (by norm_num) (fun _ => 0) ?_ ?_ (fun _ => le_rfl) - · simpa using H - · intro r hr - rw [degreeTail_degree,ite_eq_right (by omega)] - · intro r hr - rw [degreeTail_degree,ite_eq_left hr,one_mul] - have hc : (A₀.choose r:ℝ) ≤ (A₀:ℝ)^r := by exact_mod_cast Nat.choose_le_pow A₀ r - calc - _ ≤ w^(2*r)*(A₀:ℝ)^r := mul_le_mul_of_nonneg_left - ((averaged_sparse_degree R θ hA r).trans hc) (by positivity) - _ = _ := by rw [pow_mul,mul_pow] - -/-- Actual recursive-oracle high tail, including arbitrary correlated latent -bits and displacements. This supplies the block layout's unconditioned high-degree -input; low degrees still require the signed occupied-tree cancellation. -/ -theorem recursive_high_moment {Ω α : Type*} [Fintype Ω] [Fintype α] - (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b r₀ k : ℕ) (τ : ℝ) - (P : FiniteLaw α) (Z : α → ℝ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) - {L : ℝ} (hL : 0 < L) (hMoment : P.expect (fun a => |Z a|^(2*k)) ≤ L^(2*k)) - (ha : ((6*(2*k:ℕ):ℝ)*L)^2 * (2^s*∏j∈Finset.range b,T (j+1):ℕ) < 1) : - (P.product (Fintype.card (WindowLeaf T (b+1)))).evenMomentSq - (multilinear (degreeTail (averagedCoefficient R - (fun ω => windowFinType T s (X ω) (b+1) τ)) r₀) Z) k ≤ - (((6*(2*k:ℕ):ℝ)*L)^2*(2^s*∏j∈Finset.range b,T (j+1):ℕ))^r₀/ - (1-((6*(2*k:ℕ):ℝ)*L)^2*(2^s*∏j∈Finset.range b,T (j+1):ℕ)) := by - apply (multilinear_moment_sq_scaled P Z k hk hcenter hL hMoment _ _).trans - apply averaged_sparse_tail_energy R _ _ r₀ (by positivity) ha - intro ω - rw [windowFinType_degree] - exact windowMinusCount_bound T s (X ω) b [] τ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -def selectedChildren {α β : Type*} [DecidableEq α] (S : Finset (α × β)) : Finset α := - S.image Prod.fst - -def selectedChildLeaves {α β : Type*} [DecidableEq α] [DecidableEq β] - (S : Finset (α × β)) (h : α) : Finset β := - (S.filter (fun v => v.1=h)).image Prod.snd - -@[to_additive] -theorem selected_prod_children {α β M : Type*} [DecidableEq α] [DecidableEq β] - [CommMonoid M] (S : Finset (α × β)) (f : α × β → M) : - (∏h∈selectedChildren S, ∏v∈selectedChildLeaves S h, f (h,v)) = ∏v∈S, f v := by - have he (h : α) : (∏v∈selectedChildLeaves S h, f (h,v)) = - ∏v∈S.filter (fun v => v.1=h), f v := by - unfold selectedChildLeaves - rw [Finset.prod_image] - · apply Finset.prod_congr rfl - intro v hv - rw [←(Finset.mem_filter.mp hv).2] - · intro v hv w hw h - apply Prod.ext - · exact (Finset.mem_filter.mp hv).2.trans (Finset.mem_filter.mp hw).2.symm - · exact h - simp_rw [he] - exact Finset.prod_fiberwise_of_maps_to (fun v hv => Finset.mem_image.mpr ⟨v,hv,rfl⟩) f - -@[to_additive] -theorem selected_prod_index {α M : Type*} [DecidableEq α] [CommMonoid M] - (S : Finset α) (f : α → M) : - (∏i : Fin S.card, f (S.equivFin.symm i).val) = ∏v∈S, f v := by - have h := Equiv.prod_comp S.equivFin.symm (fun v : S => f v.val) - simpa only [Finset.prod_coe_sort] using h - -/-- Occupied shape of an actual subset of a complete window tree. Only -occupied children are enumerated, so its leaves are exactly the selected -monomial variables, not the other complete-tree leaves. -/ -def occupiedWindowShape (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : - (b : ℕ) → (path : List ℕ) → Finset (WindowLeaf T (b+1)) → CoefficientShape b - | 0, path, S => .bottom S.card - (fun i => motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X path)) - (fun i => (prouhetSeries s).coeff (((S.equivFin.symm i).val.1.val:ℤ)-X path)) - | b+1, path, S => .node (selectedChildren S).card - (fun i => motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X path)) - (fun i => (prouhetSeries s).coeff ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X path)) - (fun i => occupiedWindowShape T s X b - (path++[((selectedChildren S).equivFin.symm i).val.val]) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) - -theorem occupiedWindowShape_admissible (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : - (occupiedWindowShape T s X b path S).Admissible := by - induction b generalizing path with - | zero => exact fun _ => prouhet_motif_value s _ - | succ b ih => exact ⟨fun _ => prouhet_motif_value s _, fun _ => ih _ _⟩ - -/-- The literal coefficient product equals the evaluation of its occupied -shape; this is before any averaging or parity cancellation. -/ -theorem occupiedWindowShape_eval (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) (τ : ℝ) : - (occupiedWindowShape T s X b path S).eval τ = - ∏v∈S, (1-windowLeafSign T s X (b+1) path τ v)/2 := by - induction b generalizing path τ with - | zero => - change (∏i : Fin S.card, _) = _ - refine (selected_prod_index S (fun v : Fin (T 0) × Fin 1 => - (motifIndicator s ((v.1.val:ℤ)-X path) - - (prouhetSeries s).coeff ((v.1.val:ℤ)-X path)*τ)/2)).trans ?_ - apply Finset.prod_congr rfl - intro v hv - simp only [windowLeafSign,motifChildSign] - ring - | succ b ih => - change (∏i : Fin (selectedChildren S).card, _) = _ - simp_rw [ih] - refine (selected_prod_index (selectedChildren S) (fun h : Fin (T (b+1)) => - ∏v∈selectedChildLeaves S h, - (1-windowLeafSign T s X (b+1) (path++[h.val]) - (motifChildSign s (X path) h.val τ) v)/2)).trans ?_ - exact selected_prod_children S (fun v => - (1-windowLeafSign T s X (b+1+1) path τ v)/2) - -theorem selected_children_card {α β : Type*} [DecidableEq α] [DecidableEq β] - (S : Finset (α × β)) : - (∑h∈selectedChildren S, (selectedChildLeaves S h).card) = S.card := by - simpa only [Finset.sum_const,smul_eq_mul,mul_one] using - selected_sum_children S (fun _ => (1:ℕ)) - -theorem selectedChildLeaves_nonempty {α β : Type*} [DecidableEq α] [DecidableEq β] - (S : Finset (α × β)) (h : α) (hh : h∈selectedChildren S) : - (selectedChildLeaves S h).Nonempty := by - obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hh - exact ⟨v.2,Finset.mem_image.mpr ⟨v,Finset.mem_filter.mpr ⟨hv,rfl⟩,rfl⟩⟩ - -theorem occupiedWindowShape_leafCount (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : (occupiedWindowShape T s X b path S).Choice) : - ((occupiedWindowShape T s X b path S).termTree a).leafCount = S.card := by - induction b generalizing path with - | zero => simp [occupiedWindowShape,CoefficientShape.termTree,OccupiedParityTree.leafCount] - | succ b ih => - change (∑i : Fin (selectedChildren S).card, _) = _ - simp_rw [ih] - exact (selected_sum_index (selectedChildren S) (fun h => - (selectedChildLeaves S h).card)).trans (selected_children_card S) - -theorem occupiedWindowShape_occupied (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) (hS : S.Nonempty) - (a : (occupiedWindowShape T s X b path S).Choice) : - ((occupiedWindowShape T s X b path S).termTree a).occupied := by - induction b generalizing path with - | zero => exact ⟨hS.card_pos,fun _ => trivial⟩ - | succ b ih => - refine ⟨(Finset.image_nonempty.mpr hS).card_pos,fun i => ?_⟩ - exact ih _ _ (selectedChildLeaves_nonempty S _ - ((selectedChildren S).equivFin.symm i).property) (a.1 i) - -/-- Forced-leaf count for a term of an actual selected monomial. -/ -theorem occupiedWindowShape_forced_count (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : (occupiedWindowShape T s X b path S).Choice) - (hw : (occupiedWindowShape T s X b path S).weight a ≠ 0) - (ho : ((occupiedWindowShape T s X b path S).termTree a).isOdd) - (hn : ((occupiedWindowShape T s X b path S).termTree a).noSingleton) : - 2^(b+1) ≤ S.card := by - simpa only [occupiedWindowShape_leafCount] using - (occupiedWindowShape T s X b path S).surviving_leaves a hw ho hn - -/-- The role choices depend only on the selected subset, not on any hidden -orientation. This common index type permits averaging before norm estimates. -/ -def OccupiedWindowChoice (T : ℕ → ℕ) : - (b : ℕ) → Finset (WindowLeaf T (b+1)) → Type - | 0, S => Fin S.card → Fin 3 - | b+1, S => - ((i : Fin (selectedChildren S).card) → OccupiedWindowChoice T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) × - (Fin (selectedChildren S).card → Fin 3) - -noncomputable instance occupiedWindowChoiceFintype (T : ℕ → ℕ) : - (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → Fintype (OccupiedWindowChoice T b S) - | 0, S => by unfold OccupiedWindowChoice; infer_instance - | b+1, S => by - letI := fun i : Fin (selectedChildren S).card => - occupiedWindowChoiceFintype T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) - unfold OccupiedWindowChoice - infer_instance - -noncomputable def occupiedWindowChoiceEquiv (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : - (b : ℕ) → (path : List ℕ) → (S : Finset (WindowLeaf T (b+1))) → - OccupiedWindowChoice T b S ≃ (occupiedWindowShape T s X b path S).Choice - | 0, _, _ => Equiv.refl _ - | b+1, path, S => Equiv.prodCongr - (Equiv.piCongrRight fun i => occupiedWindowChoiceEquiv T s X b - (path++[((selectedChildren S).equivFin.symm i).val.val]) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) - (Equiv.refl _) - -/-- The parity tree of a role choice is independent of all displacement bits. -/ -noncomputable def occupiedWindowTerm (T : ℕ → ℕ) : - (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → - OccupiedWindowChoice T b S → OccupiedParityTree (b+1) - | 0, S, a => .node S.card (fun _ => .leaf) a - | b+1, S, a => .node (selectedChildren S).card - (fun i => occupiedWindowTerm T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) a.2 - - theorem occupiedWindowTerm_eq (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : OccupiedWindowChoice T b S) : - (occupiedWindowShape T s X b path S).termTree - (occupiedWindowChoiceEquiv T s X b path S a) = occupiedWindowTerm T b S a := by - induction b generalizing path with - | zero => rfl - | succ b ih => - change OccupiedParityTree.node _ (fun i => _) _ = OccupiedParityTree.node _ _ _ - congr 1 - funext i - exact ih _ _ _ - -noncomputable def occupiedWindowWeight (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : OccupiedWindowChoice T b S) : ℝ := - (occupiedWindowShape T s X b path S).weight - (occupiedWindowChoiceEquiv T s X b path S a) - -/-- Exact source parity formula for the actual selected leaves, using a -single role index independent of the latent map. No fit conditioning. -/ -theorem occupiedWindow_difference (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : - (∏v∈S, (1-windowLeafSign T s X (b+1) path 1 v)/2) - - (∏v∈S, (1-windowLeafSign T s X (b+1) path (-1) v)/2) = - 2*∑a : OccupiedWindowChoice T b S, - if (occupiedWindowTerm T b S a).isOdd then occupiedWindowWeight T s X b path S a else 0 := by - rw [←occupiedWindowShape_eval,←occupiedWindowShape_eval, - CoefficientShape.difference_expansion _ (occupiedWindowShape_admissible T s X b path S)] - congr 1 - rw [←(occupiedWindowChoiceEquiv T s X b path S).sum_comp] - apply Finset.sum_congr rfl - intro a _ - rw [occupiedWindowTerm_eq] - rfl - -/-- Averaging the complete exact expansion keeps all correlations of the -common hidden map. The indicator of an odd root is deterministic. -/ -theorem occupiedWindow_averaged_difference {Ω : Type*} [Fintype Ω] - (R : FiniteLaw Ω) (T : ℕ → ℕ) (s : ℕ) (X : Ω → List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : - R.expect (fun ω => ∏v∈S, (1-windowLeafSign T s (X ω) (b+1) path 1 v)/2) - - R.expect (fun ω => ∏v∈S, (1-windowLeafSign T s (X ω) (b+1) path (-1) v)/2) = - 2*∑a : OccupiedWindowChoice T b S, - if (occupiedWindowTerm T b S a).isOdd then - R.expect (fun ω => occupiedWindowWeight T s (X ω) b path S a) else 0 := by - unfold expect - rw [←Finset.sum_sub_distrib] - simp_rw [←mul_sub,occupiedWindow_difference,mul_left_comm (R.mass _) 2, - Finset.mul_sum] - rw [Finset.sum_comm] - simp_rw [←Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro a _ - by_cases h : (occupiedWindowTerm T b S a).isOdd <;> simp [h] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Arbitrary functions of the actual posterior count have the translated -fair-binomial law, not only its generating polynomial. -/ -theorem posterior_count_average {ι : Type*} [Fintype ι] - (d : ι → Option Bool) (F : ℤ → ℝ) : - (∑ b : ι → Bool, (∏i, (flagPosterior (d i)).mass (b i)) * - F (∑i, (bitIndex (b i):ℤ))) = - ∑k∈Finset.range ((∑i, hiddenTrial (d i))+1), - fairBinomial (∑i, hiddenTrial (d i)) k * F ((∑i,(visibleOnes (d i):ℤ))+k) := by - have H := congrArg (fun p : IntSeries => Finsupp.linearCombination ℝ F p.coeff) - (posterior_count_series d) - rw [fairSeries_sum,Finset.mul_sum] at H - simp only [AddMonoidAlgebra.single_mul_single,one_mul, - AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, - Finsupp.linearCombination_single,smul_eq_mul] at H - exact H - -theorem fairBinomial_reflect (n k : ℕ) (hk : k ≤ n) : - fairBinomial n (n-k) = fairBinomial n k := by - simp only [fairBinomial,Nat.choose_symm hk] - -/-- Reflection of the remaining hidden count. The known visible contribution -is kept, and no positivity assumption on the metadata mass is needed. -/ -theorem posterior_count_average_reflected {ι : Type*} [Fintype ι] - (d : ι → Option Bool) (F : ℤ → ℝ) : - (∑ b : ι → Bool, (∏i, (flagPosterior (d i)).mass (b i)) * - F (∑i, (bitIndex (b i):ℤ))) = - ∑k∈Finset.range ((∑i, hiddenTrial (d i))+1), - fairBinomial (∑i, hiddenTrial (d i)) k * - F ((∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i))-k) := by - rw [posterior_count_average] - rw [←Finset.sum_range_reflect] - apply Finset.sum_congr rfl - intro k hk - have hk' : k ≤ ∑i,hiddenTrial (d i) := by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hk - simp only [Nat.add_sub_cancel,fairBinomial_reflect _ _ hk',Nat.cast_sub hk'] - congr 2 - ring - -/-- The actual local signed motif averaged over posterior orientations is -exactly a translated smoothed Prouhet polynomial. -/ -theorem posterior_signed_motif {ι : Type*} [Fintype ι] - (d : ι → Option Bool) (s : ℕ) (z : ℤ) : - (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i)) * - (prouhetSeries s).coeff (z+∑i,(bitIndex (b i):ℤ))) = - (prouhetSeries s * fairSeries (∑i,hiddenTrial (d i))).coeff - (z+(∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i))) := by - rw [posterior_count_average_reflected d (fun a => (prouhetSeries s).coeff (z+a)), - fairSeries_sum,Finset.mul_sum, - AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply] - apply Finset.sum_congr rfl - intro k hk - rw [AddMonoidAlgebra.coeff_mul_single_apply] - simp only [mul_comm] - congr 2 - omega - -/-- Singleton smoothing for literal hidden orientation bits. Other mechanisms -can now be conditioned on without changing this bound. -/ -theorem posterior_signed_motif_bound {ι : Type*} [Fintype ι] - (d : ι → Option Bool) (s : ℕ) (z : ℤ) : - |∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i)) * - (prouhetSeries s).coeff (z+∑i,(bitIndex (b i):ℤ))| ≤ - (2:ℝ)^(s*s)*((2*binomialBound ((∑i,hiddenTrial (d i))/(s+1)))^s * - binomialBound ((∑i,hiddenTrial (d i))/(s+1))) := by - rw [posterior_signed_motif] - exact (signed_binomial_smoothing _ s).1 _ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- The literal unsigned window evaluated at an affine fair-binomial shift. -/ -theorem windowKernel_binomial (n L : ℕ) (z : ℤ) : - windowKernel n L z = - ∑k∈Finset.range (n+1), fairBinomial n k * - (if 0 ≤ z+(k:ℤ) ∧ z+(k:ℤ) motifIndicator s (z+a)),windowKernel_binomial] - apply Finset.sum_congr rfl - intro k hk - simp only [motifIndicator,add_assoc] - -/-- The finite-series functional form of the posterior count identity. -/ -theorem posterior_count_support {ι : Type*} [Fintype ι] - (d : ι → Option Bool) (F : ℤ → ℝ) : - (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i))*F (∑i,(bitIndex (b i):ℤ))) = - ∑v∈(fairSeries (∑i,hiddenTrial (d i))).coeff.support, - (fairSeries (∑i,hiddenTrial (d i))).coeff v * F ((∑i,(visibleOnes (d i):ℤ))+v) := by - rw [posterior_count_average] - have H := congrArg (fun p : IntSeries => - Finsupp.linearCombination ℝ (fun v => F ((∑i,(visibleOnes (d i):ℤ))+v)) p.coeff) - (fairSeries_sum (∑i,hiddenTrial (d i))) - simp only [AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, - Finsupp.linearCombination_single,smul_eq_mul] at H - exact H.symm - -/-- The actual two-sibling anchor multiplier. Global bits are shared by the -two siblings until AFTER averaging; their local bits are independent. -/ -def posteriorJointAnchors {ιg ι₁ ι₂ : Type*} [Fintype ιg] [Fintype ι₁] [Fintype ι₂] - (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) - (s : ℕ) (z₁ z₂ : ℤ) : ℝ := - ∑bg : ιg → Bool, (∏i,(flagPosterior (dg i)).mass (bg i)) * - (∑b₁ : ι₁ → Bool, (∏i,(flagPosterior (d₁ i)).mass (b₁ i)) * - motifIndicator s (z₁+(∑i,(bitIndex (bg i):ℤ))+(∑i,(bitIndex (b₁ i):ℤ)))) * - (∑b₂ : ι₂ → Bool, (∏i,(flagPosterior (d₂ i)).mass (b₂ i)) * - motifIndicator s (z₂+(∑i,(bitIndex (bg i):ℤ))+(∑i,(bitIndex (b₂ i):ℤ)))) - -theorem posteriorJointAnchors_eq {ιg ι₁ ι₂ : Type*} [Fintype ιg] [Fintype ι₁] [Fintype ι₂] - (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) - (s : ℕ) (z₁ z₂ : ℤ) : - posteriorJointAnchors dg d₁ d₂ s z₁ z₂ = - jointWindowKernel (∑i,hiddenTrial (dg i)) (∑i,hiddenTrial (d₁ i)) - (∑i,hiddenTrial (d₂ i)) (2^s) - (z₁+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₁ i):ℤ))) - (z₂+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₂ i):ℤ))) := by - unfold posteriorJointAnchors - simp_rw [posterior_unsigned_motif,mul_assoc] - rw [posterior_count_support dg (fun v => - windowKernel (∑i,hiddenTrial (d₁ i)) (2^s) (z₁+v+∑i,(visibleOnes (d₁ i):ℤ)) * - windowKernel (∑i,hiddenTrial (d₂ i)) (2^s) (z₂+v+∑i,(visibleOnes (d₂ i):ℤ)))] - unfold jointWindowKernel - apply Finset.sum_congr rfl - intro v hv - have h₁ : z₁+((∑i,(visibleOnes (dg i):ℤ))+v)+(∑i,(visibleOnes (d₁ i):ℤ)) = - z₁+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₁ i):ℤ))+v := by ring - have h₂ : z₂+((∑i,(visibleOnes (dg i):ℤ))+v)+(∑i,(visibleOnes (d₂ i):ℤ)) = - z₂+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₂ i):ℤ))+v := by ring - rw [h₁,h₂,mul_assoc] - -/-- Quantitative sibling summation now directly bounds genuine posterior -bits, not an independent-anchor surrogate. -/ -theorem posterior_sibling_anchor_energy {ιg ι₁ ι₂ : Type*} - [Fintype ιg] [Fintype ι₁] [Fintype ι₂] - (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) - (s : ℕ) (A B C D : Finset ℤ) (c₁ c₂ : ℤ) : - (∑a∈A, ∑b∈B, ∑_c∈closeLabels C (2^s) a, ∑_d∈closeLabels D (2^s) b, - (posteriorJointAnchors dg d₁ d₂ s (a-c₁) (b-c₂))^2) ≤ - 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (dg i))* - binomialBound (∑i,hiddenTrial (d₂ i)) := by - simp_rw [posteriorJointAnchors_eq] - have he : ∀a c u v : ℤ, a-c+u+v = a-(c-u-v) := by intros; omega - simp_rw [he] - exact sibling_anchor_energy (∑i,hiddenTrial (dg i)) (∑i,hiddenTrial (d₁ i)) - (∑i,hiddenTrial (d₂ i)) (2^s) A B C D - (c₁-(∑i,(visibleOnes (dg i):ℤ))-(∑i,(visibleOnes (d₁ i):ℤ))) - (c₂-(∑i,(visibleOnes (dg i):ℤ))-(∑i,(visibleOnes (d₂ i):ℤ))) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -namespace FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] - -theorem expect_mul_const (P : FiniteLaw α) (f : α → ℝ) (c : ℝ) : - P.expect (fun a => f a*c) = P.expect f*c := by - unfold expect - simp only [←mul_assoc,Finset.sum_mul] - -theorem expect_const_mul (P : FiniteLaw α) (f : α → ℝ) (c : ℝ) : - P.expect (fun a => c*f a) = c*P.expect f := by - unfold expect - simp only [mul_left_comm (P.mass _) c,Finset.mul_sum] - -theorem coordinateProduct_expect_product {n : ℕ} (P : Fin n → FiniteLaw α) - (f : Fin n → α → ℝ) : - (coordinateProduct P).expect (fun x => ∏i,f i (x i)) = ∏i,(P i).expect (f i) := by - unfold expect coordinateProduct - simp only [←Finset.prod_mul_distrib] - exact (Fintype.prod_sum (fun (i : Fin n) (a : α) => (P i).mass a*f i a)).symm - -theorem expect_prod_split (P : FiniteLaw α) (Q : FiniteLaw β) - (f : α → ℝ) (g : β → ℝ) : - (P.prod Q).expect (fun x => f x.1*g x.2) = P.expect f * Q.expect g := by - rw [expect_prod] - simp_rw [expect_const_mul] - exact expect_mul_const P f _ - -end FiniteLaw - -/-- All local and global orientation collections on the complete index tree, -including unoccupied vertices and paths which do not fit. The type is fixed -before any selected monomial or role choices. `n` is the local trial count, -`g` the number of global paired trials, and T the full window counts. -/ -def WindowAssignments (T n g : ℕ → ℕ) (A : Type) : ℕ → Type - | 0 => PUnit - | b+1 => (Fin (n b) → A) × (Fin (g b) → A) × - (Fin (T b) → WindowAssignments T n g A b) - -noncomputable instance windowAssignmentsFintype (T n g : ℕ → ℕ) (A : Type) [Fintype A] : - (b : ℕ) → Fintype (WindowAssignments T n g A b) - | 0 => inferInstanceAs (Fintype PUnit) - | b+1 => by - letI := windowAssignmentsFintype T n g A b - exact inferInstanceAs (Fintype ((Fin (n b) → A) × (Fin (g b) → A) × - (Fin (T b) → WindowAssignments T n g A b))) - -def posteriorArray {n : ℕ} (d : Fin n → Option Bool) : FiniteLaw (Fin n → Bool) := - coordinateProduct (fun i => flagPosterior (d i)) - -/-- Actual independent posterior orientations at exact non-leaf metadata. -The common global bits in a group are drawn only once. -/ -def windowPosteriorLaw (T n g : ℕ → ℕ) : (b : ℕ) → - WindowAssignments T n g (Option Bool) b → FiniteLaw (WindowAssignments T n g Bool b) - | 0, _ => ⟨fun _ => 1,fun _ => by norm_num,by change (∑_ : PUnit,(1:ℝ))=1; simp⟩ - | b+1, d => (posteriorArray d.1).prod ((posteriorArray d.2.1).prod - (coordinateProduct (fun i => windowPosteriorLaw T n g b (d.2.2 i)))) - -/-- Displacements from the jointly generated bit tree. The ancestor global -map may vary off its plateau. No independent jitter per child is introduced. -The fixed center includes the deterministic half-trial corrections. -/ -def sourceTreeAnchors (T n g : ℕ → ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : - (b : ℕ) → WindowAssignments T n g Bool b → ℤ → List ℕ → ℤ - | 0, _, _, _ => 0 - | b+1, bits, incoming, [] => center b - (∑i,(bitIndex (bits.1 i):ℤ))-incoming - | b+1, bits, _, h::tail => if hh : h X (pre++tail)) b path τ v := by - induction b generalizing path τ with - | zero => rfl - | succ b ih => - change windowLeafSign T s X b _ _ v.2 = _ - rw [List.append_assoc,ih] - rfl - -/-- Exact recursive leaf signs for the complete bit tree, with one joint -parent-global shift supplied to each sibling's local mechanism. -/ -def sourceTreeLeafSign (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : - (b : ℕ) → WindowAssignments T n g Bool b → ℤ → ℝ → WindowLeaf T b → ℝ - | 0, _, _, τ, _ => τ - | b+1, bits, incoming, τ, v => - sourceTreeLeafSign T n g s center globalShift b (bits.2.2 v.1) - (globalShift b bits.2.1 v.1) - (motifChildSign s (center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) v.1.val τ) v.2 - -theorem sourceTreeLeafSign_eq (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool b) (incoming : ℤ) - (τ : ℝ) (v : WindowLeaf T b) : - sourceTreeLeafSign T n g s center globalShift b bits incoming τ v = - windowLeafSign T s (sourceTreeAnchors T n g center globalShift b bits incoming) b [] τ v := by - induction b generalizing incoming τ with - | zero => rfl - | succ b ih => - change sourceTreeLeafSign T n g s center globalShift b _ _ _ v.2 = - windowLeafSign T s _ b [v.1.val] _ v.2 - rw [ih] - have hp := windowLeafSign_prefix T s - (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) - b [v.1.val] [] - (motifChildSign s (center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) v.1.val τ) v.2 - simp only [List.append_nil,List.singleton_append,sourceTreeAnchors_child] at hp - exact hp.symm - -end TraceReconstruction - --- Actual subtree coefficient factorization and singleton cancellation. -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- The factor at the current vertex of a fixed actual occupied role choice. -It only uses that vertex's displacement, never any descendant mechanism. -/ -def occupiedRootWeight (T : ℕ → ℕ) (s : ℕ) : - (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → - OccupiedWindowChoice T b S → ℤ → ℝ - | 0, S, a, X => ∏i : Fin S.card, - bottomRoleWeight (motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X)) - ((prouhetSeries s).coeff (((S.equivFin.symm i).val.1.val:ℤ)-X)) (a i) - | b+1, S, a, X => ∏i : Fin (selectedChildren S).card, - @internalRoleWeight (occupiedWindowTerm T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)).isOdd - (Classical.propDecidable _) - (motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X)) - ((prouhetSeries s).coeff ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X)) (a.2 i) - -theorem occupiedWindowWeight_zero (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (path : List ℕ) (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : - occupiedWindowWeight T s X 0 path S a = occupiedRootWeight T s 0 S a (X path) := rfl - -theorem occupiedWindowWeight_succ (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1+1))) - (a : OccupiedWindowChoice T (b+1) S) : - occupiedWindowWeight T s X (b+1) path S a = - occupiedRootWeight T s (b+1) S a (X path) * - ∏i : Fin (selectedChildren S).card, - occupiedWindowWeight T s X b - (path++[((selectedChildren S).equivFin.symm i).val.val]) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) := by - unfold occupiedWindowWeight - change (∏i, _ * @internalRoleWeight - ((occupiedWindowShape T s X b - (path++[((selectedChildren S).equivFin.symm i).val.val]) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)).termTree - (occupiedWindowChoiceEquiv T s X b - (path++[((selectedChildren S).equivFin.symm i).val.val]) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i))).isOdd - (Classical.propDecidable _) _ _ _) = _ - simp_rw [occupiedWindowTerm_eq] - rw [Finset.prod_mul_distrib,mul_comm] - rfl - -/-- Moving a subtree's path origin does not change any of its role factors. -/ -theorem occupiedWindowWeight_prefix (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) - (b : ℕ) (pre path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : OccupiedWindowChoice T b S) : - occupiedWindowWeight T s X b (pre++path) S a = - occupiedWindowWeight T s (fun tail => X (pre++tail)) b path S a := by - induction b generalizing path with - | zero => rfl - | succ b ih => - rw [occupiedWindowWeight_succ,occupiedWindowWeight_succ] - congr 1 - apply Finset.prod_congr rfl - intro i hi - rw [List.append_assoc,ih] - -theorem bottomRoleWeight_abs_le_one (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : - |bottomRoleWeight χ σ a| ≤ 1 := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> - fin_cases a <;> norm_num [bottomRoleWeight] - -theorem internalRoleWeight_abs_le_one (odd : Prop) [Decidable odd] - (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : - |internalRoleWeight odd χ σ a| ≤ 1 := by - rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> - fin_cases a <;> by_cases ho : odd <;> norm_num [internalRoleWeight,roleWeight,ho] - -theorem occupiedRootWeight_abs_le_one (T : ℕ → ℕ) (s b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) (X : ℤ) : - |occupiedRootWeight T s b S a X| ≤ 1 := by - cases b with - | zero => - rw [occupiedRootWeight,Finset.abs_prod] - exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) - (fun i _ => bottomRoleWeight_abs_le_one _ _ (prouhet_motif_value s _) (a i)) - | succ b => - rw [occupiedRootWeight,Finset.abs_prod] - exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) - (fun i _ => internalRoleWeight_abs_le_one _ _ _ (prouhet_motif_value s _) (a.2 i)) - -theorem occupiedWindowWeight_abs_le_one (T : ℕ → ℕ) (s : ℕ) - (X : List ℕ → ℤ) (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) - (a : OccupiedWindowChoice T b S) : |occupiedWindowWeight T s X b path S a| ≤ 1 := by - induction b generalizing path with - | zero => exact occupiedRootWeight_abs_le_one T s 0 S a _ - | succ b ih => - rw [occupiedWindowWeight_succ,abs_mul,Finset.abs_prod] - exact (mul_le_of_le_one_left (by positivity) - (occupiedRootWeight_abs_le_one T s (b+1) S a _)).trans - (Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) (fun i _ => ih _ _ _)) - -/-- A singleton signed role factors off its signed motif with a scalar -independent of all displacements. Bottom zero-role terms really vanish. -/ -theorem bottom_singleton_factor {n : ℕ} (a : Fin n → Fin 3) (i : Fin n) - (hi : a i=2) (hrest : ∀j,j≠i → a j=0) : - ∃c : ℝ, |c|≤1 ∧ ∀χ σ : Fin n → ℝ, - (∏j,bottomRoleWeight (χ j) (σ j) (a j)) = c*σ i := by - let c : ℝ := -(∏j∈Finset.univ.erase i,(0:ℝ))/2 - refine ⟨c,?_,?_⟩ - · have hp : 0 ≤ ∏j∈Finset.univ.erase i,(0:ℝ) := Finset.prod_nonneg (fun _ _ => le_rfl) - have hp' : (∏j∈Finset.univ.erase i,(0:ℝ)) ≤ 1 := Finset.prod_le_one₀ - (fun _ _ => le_rfl) (fun _ _ => by norm_num) - dsimp [c] - rw [abs_div,abs_neg,abs_of_nonneg hp] - rw [abs_of_pos (by norm_num : (0:ℝ)<2)] - linarith - · intro χ σ - rw [←Finset.prod_erase_mul _ _ (Finset.mem_univ i)] - have he : (∏j∈Finset.univ.erase i,bottomRoleWeight (χ j) (σ j) (a j)) = - ∏j∈Finset.univ.erase i,(0:ℝ) := by - apply Finset.prod_congr rfl - intro j hj - simp only [hrest j (Finset.mem_erase.mp hj).1,bottomRoleWeight,↓reduceIte] - rw [he,hi] - simp only [bottomRoleWeight,show (2:Fin 3)≠0 by decide, - show (2:Fin 3)≠1 by decide,↓reduceIte] - dsimp [c] - ring - -theorem internal_singleton_factor {n : ℕ} (odd : Fin n → Prop) - (a : Fin n → Fin 3) (i : Fin n) (hi : a i=2) (hrest : ∀j,j≠i → a j=0) : - ∃c : ℝ, |c|≤1 ∧ ∀χ σ : Fin n → ℝ, - (∏j,@internalRoleWeight (odd j) (Classical.propDecidable _) (χ j) (σ j) (a j)) = c*σ i := by - refine ⟨if odd i then 1 else 0,?_,?_⟩ - · split_ifs <;> norm_num - · intro χ σ - rw [Finset.prod_eq_single i] - · by_cases ho : odd i <;> simp [internalRoleWeight,roleWeight,hi,ho] - · intro j hj hji - by_cases ho : odd j <;> simp [internalRoleWeight,roleWeight,hrest j hji,ho] - · simp - -namespace FiniteLaw - -/-- Unoccupied independent coordinates integrate to one. -/ -theorem coordinateProduct_expect_subtype {α : Type*} [Fintype α] {n : ℕ} - (P : Fin n → FiniteLaw α) (S : Finset (Fin n)) (f : S → α → ℝ) : - (coordinateProduct P).expect (fun x => ∏i : S, f i (x i.val)) = - ∏i : S, (P i.val).expect (f i) := by - have scalar : ∀f : S → ℝ, - (∏j : Fin n, if hj : j∈S then f ⟨j,hj⟩ else 1) = ∏i : S,f i := by - intro f - calc - _ = ∏j∈S, if hj : j∈S then f ⟨j,hj⟩ else 1 := - (Finset.prod_subset S.subset_univ (fun j _ hj => dite_eq_right hj)).symm - _ = ∏i : S, if hj : i.val∈S then f ⟨i.val,hj⟩ else 1 := - Finset.prod_subtype S (fun _ => Iff.rfl) _ - _ = _ := by simp only [dite_eq_left (Subtype.property _)] - let F : Fin n → α → ℝ := fun j a => if hj : j∈S then f ⟨j,hj⟩ a else 1 - have hp : ∀x : Fin n → α, (∏j,F j (x j)) = ∏i : S,f i (x i.val) := by - intro x - exact scalar (fun i => f i (x i.val)) - rw [show (fun x : Fin n → α => ∏i : S,f i (x i.val)) = (fun x => ∏j,F j (x j)) by - funext x; exact (hp x).symm] - rw [coordinateProduct_expect_product] - have he : ∀j, (P j).expect (F j) = if hj : j∈S then (P j).expect (f ⟨j,hj⟩) else 1 := by - intro j - by_cases hj : j∈S - · simp only [F,dite_eq_left hj] - · simp only [F,dite_eq_right hj,expect_const] - simp_rw [he] - exact scalar (fun i => (P i.val).expect (f i)) - -theorem coordinateProduct_expect_selected {α : Type*} [Fintype α] {n : ℕ} - (P : Fin n → FiniteLaw α) (S : Finset (Fin n)) (f : Fin S.card → α → ℝ) : - (coordinateProduct P).expect (fun x => ∏i : Fin S.card, f i (x (S.equivFin.symm i).val)) = - ∏i : Fin S.card, (P (S.equivFin.symm i).val).expect (f i) := by - have hp : ∀x : Fin n → α, - (∏i : Fin S.card,f i (x (S.equivFin.symm i).val)) = - ∏i : S,f (S.equivFin i) (x i.val) := by - intro x - simpa only [Equiv.apply_symm_apply] using - Equiv.prod_comp S.equivFin.symm (fun i : S => f (S.equivFin i) (x i.val)) - simp_rw [hp,coordinateProduct_expect_subtype] - symm - simpa only [Equiv.apply_symm_apply] using - Equiv.prod_comp S.equivFin.symm (fun i : S => (P i.val).expect (f (S.equivFin i))) - -theorem expect_prod_selected {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - {n : ℕ} (P : FiniteLaw α) (Q : FiniteLaw β) (R : Fin n → FiniteLaw γ) - (S : Finset (Fin n)) (f : α → ℝ) (h : β → Fin S.card → γ → ℝ) : - (P.prod (Q.prod (coordinateProduct R))).expect (fun x => - f x.1 * ∏i : Fin S.card, h x.2.1 i (x.2.2 (S.equivFin.symm i).val)) = - P.expect f * Q.expect (fun z => ∏i : Fin S.card, - (R (S.equivFin.symm i).val).expect (h z i)) := by - simp_rw [expect_prod,expect_const_mul,coordinateProduct_expect_selected] - rw [expect_mul_const] - -theorem abs_expect_le_const {α : Type*} [Fintype α] (P : FiniteLaw α) - (f : α → ℝ) (c : ℝ) (h : ∀a, |f a|≤c) : |P.expect f|≤c := - (P.abs_expect_le f).trans ((P.expect_mono h).trans_eq (P.expect_const c)) - -end FiniteLaw - - -/-- A fixed real coefficient term evaluated on the actual complete bit tree. -The selected role choice is fixed independently of these bits. -/ -def sourceRoleTerm (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : ℝ := - occupiedWindowWeight T s (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) - b [] S a - -def sourceRoleAverage (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : ℝ := - (windowPosteriorLaw T n g (b+1) d).expect - (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) - -theorem sourceRoleTerm_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (bits : WindowAssignments T n g Bool 1) (incoming : ℤ) - (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : - sourceRoleTerm T n g s center globalShift 0 bits incoming S a = - occupiedRootWeight T s 0 S a (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) := rfl - -theorem sourceRoleTerm_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (bits : WindowAssignments T n g Bool (b+1+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) : - sourceRoleTerm T n g s center globalShift (b+1) bits incoming S a = - occupiedRootWeight T s (b+1) S a (center (b+1)-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) * - ∏i : Fin (selectedChildren S).card, - sourceRoleTerm T n g s center globalShift b - (bits.2.2 ((selectedChildren S).equivFin.symm i).val) - (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) := by - unfold sourceRoleTerm - rw [occupiedWindowWeight_succ] - congr 1 - apply Finset.prod_congr rfl - intro i hi - have hp := occupiedWindowWeight_prefix T s - (sourceTreeAnchors T n g center globalShift (b+1+1) bits incoming) b - [((selectedChildren S).equivFin.symm i).val.val] [] - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) - simpa only [List.append_nil,List.nil_append,List.singleton_append,sourceTreeAnchors_child] using hp - -theorem sourceRoleAverage_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (d : WindowAssignments T n g (Option Bool) 1) (incoming : ℤ) - (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : - sourceRoleAverage T n g s center globalShift 0 d incoming S a = - (posteriorArray d.1).expect (fun loc => - occupiedRootWeight T s 0 S a (center 0-(∑i,(bitIndex (loc i):ℤ))-incoming)) := by - rw [sourceRoleAverage] - simp_rw [sourceRoleTerm_zero] - rcases d with ⟨dl,dg,dc⟩ - change ((posteriorArray dl).prod ((posteriorArray dg).prod - (coordinateProduct (fun i => windowPosteriorLaw T n g 0 (dc i))))).expect - (fun bits => occupiedRootWeight T s 0 S a - (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) = _ - rw [expect_prod] - simp only [expect_const] - -theorem sourceRoleAverage_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) : - sourceRoleAverage T n g s center globalShift (b+1) d incoming S a = - (posteriorArray d.1).expect (fun loc => - occupiedRootWeight T s (b+1) S a (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming)) * - (posteriorArray d.2.1).expect (fun glob => - ∏i : Fin (selectedChildren S).card, - sourceRoleAverage T n g s center globalShift b - (d.2.2 ((selectedChildren S).equivFin.symm i).val) - (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) := by - rw [sourceRoleAverage] - simp_rw [sourceRoleTerm_succ] - exact FiniteLaw.expect_prod_selected (posteriorArray d.1) (posteriorArray d.2.1) - (fun i => windowPosteriorLaw T n g (b+1) (d.2.2 i)) (selectedChildren S) - (fun loc => occupiedRootWeight T s (b+1) S a - (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming)) - (fun glob i bits => sourceRoleTerm T n g s center globalShift b bits - (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) - -theorem sourceRoleAverage_abs_le_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤1 := by - apply FiniteLaw.abs_expect_le_const - intro bits - exact occupiedWindowWeight_abs_le_one T s _ b [] S a - -/-- The exact signed smoothing cost read off the visible metadata alone. -/ -def posteriorSmoothingCost {ι : Type*} [Fintype ι] (s : ℕ) (d : ι → Option Bool) : ℝ := - (2:ℝ)^(s*s)*((2*binomialBound ((∑i,hiddenTrial (d i))/(s+1)))^s * - binomialBound ((∑i,hiddenTrial (d i))/(s+1))) - -/-- A purely numerical typical-metadata condition on every local collection. -It includes unoccupied vertices and is fixed before a coefficient is chosen. -/ -def MetadataSmoothingCap (T n g : ℕ → ℕ) (s : ℕ) (η : ℝ) : - (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop - | 0, _ => True - | b+1, d => posteriorSmoothingCost s d.1 ≤ η ∧ - ∀h, MetadataSmoothingCap T n g s η b (d.2.2 h) - -def occupiedRootHasSingleton (T : ℕ → ℕ) : (b : ℕ) → - (S : Finset (WindowLeaf T (b+1))) → OccupiedWindowChoice T b S → Prop - | 0, _, a => ∃i, a i=2 ∧ ∀j,j≠i → a j=0 - | _+1, _, a => ∃i, a.2 i=2 ∧ ∀j,j≠i → a.2 j=0 - -theorem occupiedRoot_singleton_factor (T : ℕ → ℕ) (s b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (h : occupiedRootHasSingleton T b S a) : - ∃c : ℝ, |c|≤1 ∧ ∃label : ℤ, ∀X, - occupiedRootWeight T s b S a X = c*(prouhetSeries s).coeff (label-X) := by - cases b with - | zero => - obtain ⟨i,hi,hr⟩ := h - obtain ⟨c,hc,hfac⟩ := bottom_singleton_factor a i hi hr - refine ⟨c,hc,((S.equivFin.symm i).val.1.val:ℤ),fun X => ?_⟩ - exact hfac _ _ - | succ b => - obtain ⟨i,hi,hr⟩ := h - obtain ⟨c,hc,hfac⟩ := internal_singleton_factor - (fun j => (occupiedWindowTerm T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) (a.1 j)).isOdd) - a.2 i hi hr - refine ⟨c,hc,(((selectedChildren S).equivFin.symm i).val.val:ℤ),fun X => ?_⟩ - exact hfac _ _ - -theorem occupiedRoot_singleton_average (T : ℕ → ℕ) (s b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (h : occupiedRootHasSingleton T b S a) {m : ℕ} (d : Fin m → Option Bool) - (center incoming : ℤ) : - |(posteriorArray d).expect (fun loc => occupiedRootWeight T s b S a - (center-(∑i,(bitIndex (loc i):ℤ))-incoming))| ≤ posteriorSmoothingCost s d := by - obtain ⟨c,hc,label,hfac⟩ := occupiedRoot_singleton_factor T s b S a h - simp_rw [hfac,expect_const_mul,abs_mul] - have he : ∀loc : Fin m → Bool, - label-(center-(∑i,(bitIndex (loc i):ℤ))-incoming) = - (label-center+incoming)+(∑i,(bitIndex (loc i):ℤ)) := by intro loc; omega - simp_rw [he] - have hb : |(posteriorArray d).expect (fun loc => - (prouhetSeries s).coeff ((label-center+incoming)+(∑i,(bitIndex (loc i):ℤ))))| ≤ - posteriorSmoothingCost s d := by - have hb := posterior_signed_motif_bound d s (label-center+incoming) - unfold posteriorArray coordinateProduct expect posteriorSmoothingCost - convert hb using 1 - congr 3 - exact Subsingleton.elim _ _ - calc - _ ≤ 1*|(posteriorArray d).expect (fun loc => - (prouhetSeries s).coeff ((label-center+incoming)+(∑i,(bitIndex (loc i):ℤ))))| := - mul_le_mul_of_nonneg_right hc (abs_nonneg _) - _ ≤ _ := by simpa only [one_mul] using hb - -theorem abs_prod_le_coordinate {ι : Type*} [Fintype ι] (f : ι → ℝ) (i : ι) - (h : ∀j,j≠i → |f j|≤1) : |∏j,f j|≤|f i| := by - rw [Finset.abs_prod,←Finset.prod_erase_mul _ _ (Finset.mem_univ i)] - have he : (∏j∈Finset.univ.erase i,|f j|)≤1 := - Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) (fun j hj => h j (Finset.mem_erase.mp hj).1) - simpa only [one_mul] using mul_le_mul_of_nonneg_right he (abs_nonneg (f i)) - -/-- Literal singleton cancellation for the complete posterior bit tree. -No successful-fit event is conditioned on, and the common parent-global -jitter is retained until after the child factors have averaged. -/ -theorem sourceRoleAverage_singleton (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) - (hsing : ¬(occupiedWindowTerm T b S a).noSingleton) : - |sourceRoleAverage T n g s center globalShift b d incoming S a|≤η := by - induction b generalizing incoming with - | zero => - have hh : Odd (signedRoleCount a) ∧ activeRoleCount a=1 := by - by_contra! h - apply hsing - exact ⟨fun ho he => h ho he,fun _ => trivial⟩ - have hr : occupiedRootHasSingleton T 0 S a := - (odd_roles_singleton_or_branch a hh.1).resolve_right (by omega) - rw [sourceRoleAverage_zero] - exact (occupiedRoot_singleton_average T s 0 S a hr d.1 _ _).trans hcap.1 - | succ b ih => - rw [sourceRoleAverage_succ,abs_mul] - have hroot : |(posteriorArray d.1).expect (fun loc => - occupiedRootWeight T s (b+1) S a - (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming))|≤1 := - FiniteLaw.abs_expect_le_const _ _ 1 (fun _ => occupiedRootWeight_abs_le_one T s (b+1) S a _) - have hglob : |(posteriorArray d.2.1).expect (fun glob => - ∏i : Fin (selectedChildren S).card, - sourceRoleAverage T n g s center globalShift b - (d.2.2 ((selectedChildren S).equivFin.symm i).val) - (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i))|≤1 := by - apply FiniteLaw.abs_expect_le_const - intro glob - rw [Finset.abs_prod] - exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) - (fun i _ => sourceRoleAverage_abs_le_one T n g s center globalShift b _ _ _ _) - by_cases hr : occupiedRootHasSingleton T (b+1) S a - · have hh := (occupiedRoot_singleton_average T s (b+1) S a hr d.1 - (center (b+1)) incoming).trans hcap.1 - exact (mul_le_mul_of_nonneg_left hglob (abs_nonneg _)).trans (by simpa using hh) - · have hex : ∃i, ¬(occupiedWindowTerm T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)).noSingleton := by - by_contra! h - apply hsing - refine ⟨?_,h⟩ - intro ho he - have hh := odd_roles_singleton_or_branch a.2 ho - exact hr (hh.resolve_right (by omega)) - obtain ⟨i,hi⟩ := hex - have hsmall : |(posteriorArray d.2.1).expect (fun glob => - ∏j : Fin (selectedChildren S).card, - sourceRoleAverage T n g s center globalShift b - (d.2.2 ((selectedChildren S).equivFin.symm j).val) - (globalShift (b+1) glob ((selectedChildren S).equivFin.symm j).val) - (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) (a.1 j))|≤η := by - apply FiniteLaw.abs_expect_le_const - intro glob - apply (abs_prod_le_coordinate _ i (fun j _ => - sourceRoleAverage_abs_le_one T n g s center globalShift b _ _ _ _)).trans - exact ih _ _ _ _ (hcap.2 _) hi - exact (mul_le_mul_of_nonneg_right hroot (abs_nonneg _)).trans (by simpa using hsmall) - -end TraceReconstruction - -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.InitialOverlap + +namespace OAI + +/-! +# LeafOracle + +Recursive leaf oracles, sparse high tails, occupied shapes, posterior smoothing, source bit trees, and singleton cancellation. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Complete window-tree leaf indices, with counts numbered from the bottom. +The tree is fixed before any occupied subset or orientation is selected. -/ +def WindowLeaf (T : ℕ → ℕ) : ℕ → Type + | 0 => Fin 1 + | b+1 => Fin (T b) × WindowLeaf T b + +noncomputable instance windowLeafFintype (T : ℕ → ℕ) : (b : ℕ) → Fintype (WindowLeaf T b) + | 0 => inferInstanceAs (Fintype (Fin 1)) + | b+1 => by + letI := windowLeafFintype T b + exact inferInstanceAs (Fintype (Fin (T b) × WindowLeaf T b)) + +/-- A motif's actual outgoing type, allowing every integer displacement. -/ +def motifChildSign (s : ℕ) (X : ℤ) (h : ℕ) (τ : ℝ) : ℝ := + 1-motifIndicator s ((h:ℤ)-X)+(prouhetSeries s).coeff ((h:ℤ)-X)*τ + +theorem motifChildSign_isSign (s : ℕ) (X : ℤ) (h : ℕ) {τ : ℝ} (hτ : IsTypeSign τ) : + IsTypeSign (motifChildSign s X h τ) := + motif_child_sign (prouhet_motif_value s ((h:ℤ)-X)) hτ + +theorem motifChildSign_negative_active (s : ℕ) (X : ℤ) (h : ℕ) (τ : ℝ) + (ht : motifChildSign s X h τ= -1) : 0 ≤ (h:ℤ)-X ∧ (h:ℤ)-X<(2^s:ℕ) := by + by_contra hn + have hz := (prouhetSeries_coeff_spec s).1 ((h:ℤ)-X) (by omega) + simp only [motifChildSign,motifIndicator,ite_eq_right hn,hz,zero_mul,sub_zero,add_zero] at ht + norm_num at ht + +/-- Literal top-down type recursion in the source's unconditioned surrogate. +`X path` is the root anchor or `w_j-Y_path`. Dependence of different paths +through the same global jitter is retained by this single full-tree map. -/ +def windowLeafSign (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : + (b : ℕ) → List ℕ → ℝ → WindowLeaf T b → ℝ + | 0, _, τ, _ => τ + | b+1, path, τ, v => windowLeafSign T s X b (path++[v.1.val]) + (motifChildSign s (X path) v.1.val τ) v.2 + +theorem windowLeafSign_isSign (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) {τ : ℝ} (hτ : IsTypeSign τ) (v : WindowLeaf T b) : + IsTypeSign (windowLeafSign T s X b path τ v) := by + induction b generalizing path τ with + | zero => exact hτ + | succ b ih => exact ih _ (motifChildSign_isSign s _ _ hτ) v.2 + +def windowLeafType (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (τ : ℝ) (v : WindowLeaf T b) : Bool := + decide (windowLeafSign T s X b path τ v= -1) + +theorem windowLeafType_weight (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) {τ : ℝ} (hτ : IsTypeSign τ) (v : WindowLeaf T b) : + (if windowLeafType T s X b path τ v then (1:ℝ) else 0)= + (1-windowLeafSign T s X b path τ v)/2 := by + rcases windowLeafSign_isSign T s X b path hτ v with hp | hm + · norm_num [windowLeafType,hp] + · norm_num [windowLeafType,hm] + +/-- A finite indexing of all leaves, not just the active or fitted leaves. -/ +def windowFinType (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (τ : ℝ) (i : Fin (Fintype.card (WindowLeaf T b))) : Bool := + windowLeafType T s X b [] τ ((Fintype.equivFin (WindowLeaf T b)).symm i) + +/-- The actual mixed leaf oracle at arbitrary exact metadata. The one latent +law governs the whole map X; no independent-anchor law is substituted. -/ +def recursiveLeafLaw {Ω α : Type*} [Fintype Ω] [Fintype α] + (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) + (P Q : FiniteLaw α) (τ : ℝ) : + FiniteLaw (Fin (Fintype.card (WindowLeaf T b)) → α) := + R.mixture (fun ω => coordinateProduct (fun i => if windowFinType T s (X ω) b τ i then Q else P)) + +theorem recursiveLeafLaw_density {Ω α : Type*} [Fintype Ω] [Fintype α] + (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) + (P Q : FiniteLaw α) (Z : α → ℝ) (hZ : ∀a,Q.mass a=P.mass a*(1+Z a)) + (τ : ℝ) (x : Fin (Fintype.card (WindowLeaf T b)) → α) : + (recursiveLeafLaw R X T s b P Q τ).mass x = + (P.product (Fintype.card (WindowLeaf T b))).mass x * + multilinear (averagedCoefficient R (fun ω => windowFinType T s (X ω) b τ)) Z x := by + rw [recursiveLeafLaw,leaf_oracle_density P Q Z hZ,averagedDensity_expansion] + rfl + +/-- Pointwise recursive coefficient before averaging over the actual bits. -/ +theorem recursive_selectionCoefficient {Ω : Type*} [Fintype Ω] + (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b : ℕ) (ω : Ω) + {τ : ℝ} (hτ : IsTypeSign τ) (σ : Fin (Fintype.card (WindowLeaf T b)) → Bool) : + selectionCoefficient (windowFinType T s (X ω) b τ) σ = + ∏i, if σ i then + (1-windowLeafSign T s (X ω) b [] τ ((Fintype.equivFin (WindowLeaf T b)).symm i))/2 else 1 := by + unfold selectionCoefficient + apply Finset.prod_congr rfl + intro i _ + cases σ i + · rfl + · exact windowLeafType_weight T s (X ω) b [] hτ _ + +theorem motif_negative_count (s N : ℕ) (X : ℤ) (τ : ℝ) : + (Finset.univ.filter (fun i : Fin N => motifChildSign s X i.val τ= -1)).card ≤ 2^s := by + have H := Finset.card_le_card_of_injOn + (s:=Finset.univ.filter (fun i : Fin N => motifChildSign s X i.val τ= -1)) + (t:=Finset.range (2^s)) (fun i : Fin N => ((i.val:ℤ)-X).toNat) ?_ ?_ + · simpa using H + · intro i hi + have h := motifChildSign_negative_active s X i.val τ (Finset.mem_filter.mp hi).2 + apply Finset.mem_range.mpr + dsimp only + omega + · intro i hi j hj he + have h := motifChildSign_negative_active s X i.val τ (Finset.mem_filter.mp hi).2 + have h' := motifChildSign_negative_active s X j.val τ (Finset.mem_filter.mp hj).2 + apply Fin.ext + dsimp only at he + omega + +/-- Exact number of minus leaves in a fixed realization, without a fit condition. -/ +def windowMinusCount (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (τ : ℝ) : ℕ := + ∑v : WindowLeaf T b, if windowLeafSign T s X b path τ v= -1 then 1 else 0 + +theorem windowMinusCount_succ (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (τ : ℝ) : + windowMinusCount T s X (b+1) path τ = + ∑i : Fin (T b), windowMinusCount T s X b (path++[i.val]) + (motifChildSign s (X path) i.val τ) := by + unfold windowMinusCount + change (∑v : Fin (T b) × WindowLeaf T b, _) = _ + rw [Fintype.sum_prod_type] + rfl + +/-- Source the block layout high-degree budget, bottom motif length times all +upper window counts. It holds for every latent realization, typical or not. -/ +theorem windowMinusCount_bound (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (τ : ℝ) : + windowMinusCount T s X (b+1) path τ ≤ + 2^s * ∏j∈Finset.range b, T (j+1) := by + induction b generalizing path τ with + | zero => + rw [windowMinusCount_succ] + change (∑i : Fin (T 0), ∑v : Fin 1, + if motifChildSign s (X path) i.val τ= -1 then (1:ℕ) else 0) ≤ _ + simp only [Fin.sum_univ_one,Finset.range_zero,Finset.prod_empty,mul_one] + simpa only [Finset.card_filter] using motif_negative_count s (T 0) (X path) τ + | succ b ih => + rw [windowMinusCount_succ] + calc + _ ≤ ∑i : Fin (T (b+1)), 2^s*∏j∈Finset.range b,T (j+1) := + Finset.sum_le_sum (fun _ _ => ih _ _) + _ = _ := by simp [Finset.prod_range_succ]; ring + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +def boolSupport {n : ℕ} (θ : Fin n → Bool) : Finset (Fin n) := + Finset.univ.filter (fun i => θ i=true) + +theorem boolSupport_injective {n : ℕ} : Function.Injective (boolSupport (n:=n)) := by + intro θ φ h + funext i + have hi : (θ i=true) ↔ (φ i=true) := by + simpa [boolSupport] using Finset.ext_iff.mp h i + cases hθ : θ i <;> cases hφ : φ i <;> simp_all + +theorem selectionCoefficient_eq_support {n : ℕ} (θ σ : Fin n → Bool) : + selectionCoefficient θ σ = if boolSupport σ ⊆ boolSupport θ then 1 else 0 := by + by_cases h : boolSupport σ ⊆ boolSupport θ + · rw [ite_eq_left h] + apply Finset.prod_eq_one + intro i _ + cases hs : σ i + · simp + · have ht : θ i=true := by simpa [boolSupport] using h (by simp [boolSupport,hs]) + simp [ht] + · rw [ite_eq_right h] + obtain ⟨i,hi,hni⟩ := Finset.not_subset.mp h + have hs : σ i=true := by simpa [boolSupport] using hi + have ht : θ i=false := by simpa [boolSupport] using hni + apply Finset.prod_eq_zero (Finset.mem_univ i) + simp [hs,ht] + +/-- Uniform cardinality bound for the actual selected monomials of a sparse +0/1 coefficient vector; mixing does not add a squared-cardinality loss. -/ +theorem selection_degree_sum_le {n : ℕ} (θ : Fin n → Bool) (r : ℕ) : + (∑σ : Fin n → Bool, if monomialDegree σ=r then selectionCoefficient θ σ else 0) ≤ + ((monomialDegree θ).choose r:ℝ) := by + have hc : (Finset.univ.filter (fun σ : Fin n → Bool => + monomialDegree σ=r ∧ boolSupport σ ⊆ boolSupport θ)).card ≤ + ((boolSupport θ).powersetCard r).card := by + apply Finset.card_le_card_of_injOn boolSupport + · intro σ hσ + rcases (Finset.mem_filter.mp hσ).2 with ⟨hd,hs⟩ + exact Finset.mem_powersetCard.mpr ⟨hs,hd⟩ + · exact boolSupport_injective.injOn + rw [Finset.card_powersetCard] at hc + have he : (∑σ : Fin n → Bool, if monomialDegree σ=r then selectionCoefficient θ σ else 0) = + ((Finset.univ.filter (fun σ : Fin n → Bool => + monomialDegree σ=r ∧ boolSupport σ ⊆ boolSupport θ)).card:ℝ) := by + simp_rw [selectionCoefficient_eq_support,←ite_and] + exact Finset.sum_boole _ _ + rw [he] + exact_mod_cast hc + +theorem averaged_sparse_degree {Ω : Type*} [Fintype Ω] {n A : ℕ} + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (hA : ∀ω, monomialDegree (θ ω) ≤ A) (r : ℕ) : + (∑σ : Fin n → Bool, if monomialDegree σ=r then averagedCoefficient R θ σ^2 else 0) ≤ + (A.choose r:ℝ) := by + calc + _ ≤ ∑σ : Fin n → Bool, if monomialDegree σ=r then averagedCoefficient R θ σ else 0 := by + apply Finset.sum_le_sum + intro σ _ + split_ifs + · have hc := coefficient_nonneg R θ σ + have h1 := coefficient_le_one R θ σ + nlinarith [mul_nonneg hc (sub_nonneg.mpr h1)] + · rfl + _ = ∑ω, R.mass ω * ∑σ : Fin n → Bool, + if monomialDegree σ=r then selectionCoefficient (θ ω) σ else 0 := by + unfold averagedCoefficient FiniteLaw.expect + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro σ _ + by_cases h : monomialDegree σ=r <;> simp [h] + _ ≤ ∑ω, R.mass ω * (A.choose r:ℝ) := by + apply Finset.sum_le_sum + intro ω _ + apply mul_le_mul_of_nonneg_left _ (R.nonneg ω) + exact (selection_degree_sum_le (θ ω) r).trans (by + exact_mod_cast Nat.choose_le_choose r (hA ω)) + _ = _ := by rw [←Finset.sum_mul,R.total,one_mul] + +/-- Genuine sparse complete-tree leaf count in the exact Fin indexing used +by the independent-product reference law. -/ +theorem windowFinType_degree (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (τ : ℝ) : + monomialDegree (windowFinType T s X b τ) = windowMinusCount T s X b [] τ := by + have h := Equiv.sum_comp (Fintype.equivFin (WindowLeaf T b)).symm + (fun v => if windowLeafSign T s X b [] τ v= -1 then (1:ℕ) else 0) + simpa only [monomialDegree,Finset.card_filter,windowFinType,windowLeafType, + decide_eq_true_eq,windowMinusCount] using h + +theorem recursive_degree_bound {Ω : Type*} [Fintype Ω] + (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b r : ℕ) (τ : ℝ) : + (∑σ, if monomialDegree σ=r then + averagedCoefficient R (fun ω => windowFinType T s (X ω) (b+1) τ) σ^2 else 0) ≤ + ((2^s*∏j∈Finset.range b,T (j+1)).choose r:ℝ) := by + apply averaged_sparse_degree + intro ω + rw [windowFinType_degree] + exact windowMinusCount_bound T s (X ω) b [] τ + +def degreeTail {n : ℕ} (A : (Fin n → Bool) → ℝ) (k : ℕ) (σ : Fin n → Bool) : ℝ := + if k ≤ monomialDegree σ then A σ else 0 + +theorem degreeTail_degree {n r k : ℕ} (A : (Fin n → Bool) → ℝ) : + (∑σ, if monomialDegree σ=r then degreeTail A k σ^2 else 0) = + if k ≤ r then ∑σ, if monomialDegree σ=r then A σ^2 else 0 else 0 := by + by_cases h : k ≤ r + · rw [ite_eq_left h] + apply Finset.sum_congr rfl + intro σ _ + by_cases he : monomialDegree σ=r <;> simp [degreeTail,he,h] + · rw [ite_eq_right h] + apply Finset.sum_eq_zero + intro σ _ + by_cases he : monomialDegree σ=r <;> simp [degreeTail,he,h] + +/-- Geometric high-degree energy of an actual mixed sparse leaf law. -/ +theorem averaged_sparse_tail_energy {Ω : Type*} [Fintype Ω] {n A₀ : ℕ} + (R : FiniteLaw Ω) (θ : Ω → Fin n → Bool) + (hA : ∀ω, monomialDegree (θ ω) ≤ A₀) (k : ℕ) {w : ℝ} + (hw : 0 ≤ w) (ha : w^2*A₀ < 1) : + multilinearEnergy (degreeTail (averagedCoefficient R θ) k) w ≤ + (w^2*A₀)^k/(1-w^2*A₀) := by + have H := multilinearEnergy_low_high (R:=k) + (degreeTail (averagedCoefficient R θ) k) w (w^2*A₀) 1 hw (by positivity) ha + (by norm_num) (fun _ => 0) ?_ ?_ (fun _ => le_rfl) + · simpa using H + · intro r hr + rw [degreeTail_degree,ite_eq_right (by omega)] + · intro r hr + rw [degreeTail_degree,ite_eq_left hr,one_mul] + have hc : (A₀.choose r:ℝ) ≤ (A₀:ℝ)^r := by exact_mod_cast Nat.choose_le_pow A₀ r + calc + _ ≤ w^(2*r)*(A₀:ℝ)^r := mul_le_mul_of_nonneg_left + ((averaged_sparse_degree R θ hA r).trans hc) (by positivity) + _ = _ := by rw [pow_mul,mul_pow] + +/-- Actual recursive-oracle high tail, including arbitrary correlated latent +bits and displacements. This supplies the block layout's unconditioned high-degree +input; low degrees still require the signed occupied-tree cancellation. -/ +theorem recursive_high_moment {Ω α : Type*} [Fintype Ω] [Fintype α] + (R : FiniteLaw Ω) (X : Ω → List ℕ → ℤ) (T : ℕ → ℕ) (s b r₀ k : ℕ) (τ : ℝ) + (P : FiniteLaw α) (Z : α → ℝ) (hk : 1 ≤ k) (hcenter : P.expect Z=0) + {L : ℝ} (hL : 0 < L) (hMoment : P.expect (fun a => |Z a|^(2*k)) ≤ L^(2*k)) + (ha : ((6*(2*k:ℕ):ℝ)*L)^2 * (2^s*∏j∈Finset.range b,T (j+1):ℕ) < 1) : + (P.product (Fintype.card (WindowLeaf T (b+1)))).evenMomentSq + (multilinear (degreeTail (averagedCoefficient R + (fun ω => windowFinType T s (X ω) (b+1) τ)) r₀) Z) k ≤ + (((6*(2*k:ℕ):ℝ)*L)^2*(2^s*∏j∈Finset.range b,T (j+1):ℕ))^r₀/ + (1-((6*(2*k:ℕ):ℝ)*L)^2*(2^s*∏j∈Finset.range b,T (j+1):ℕ)) := by + apply (multilinear_moment_sq_scaled P Z k hk hcenter hL hMoment _ _).trans + apply averaged_sparse_tail_energy R _ _ r₀ (by positivity) ha + intro ω + rw [windowFinType_degree] + exact windowMinusCount_bound T s (X ω) b [] τ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +def selectedChildren {α β : Type*} [DecidableEq α] (S : Finset (α × β)) : Finset α := + S.image Prod.fst + +def selectedChildLeaves {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset (α × β)) (h : α) : Finset β := + (S.filter (fun v => v.1=h)).image Prod.snd + +@[to_additive] +theorem selected_prod_children {α β M : Type*} [DecidableEq α] [DecidableEq β] + [CommMonoid M] (S : Finset (α × β)) (f : α × β → M) : + (∏h∈selectedChildren S, ∏v∈selectedChildLeaves S h, f (h,v)) = ∏v∈S, f v := by + have he (h : α) : (∏v∈selectedChildLeaves S h, f (h,v)) = + ∏v∈S.filter (fun v => v.1=h), f v := by + unfold selectedChildLeaves + rw [Finset.prod_image] + · apply Finset.prod_congr rfl + intro v hv + rw [←(Finset.mem_filter.mp hv).2] + · intro v hv w hw h + apply Prod.ext + · exact (Finset.mem_filter.mp hv).2.trans (Finset.mem_filter.mp hw).2.symm + · exact h + simp_rw [he] + exact Finset.prod_fiberwise_of_maps_to (fun v hv => Finset.mem_image.mpr ⟨v,hv,rfl⟩) f + +@[to_additive] +theorem selected_prod_index {α M : Type*} [DecidableEq α] [CommMonoid M] + (S : Finset α) (f : α → M) : + (∏i : Fin S.card, f (S.equivFin.symm i).val) = ∏v∈S, f v := by + have h := Equiv.prod_comp S.equivFin.symm (fun v : S => f v.val) + simpa only [Finset.prod_coe_sort] using h + +/-- Occupied shape of an actual subset of a complete window tree. Only +occupied children are enumerated, so its leaves are exactly the selected +monomial variables, not the other complete-tree leaves. -/ +def occupiedWindowShape (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : + (b : ℕ) → (path : List ℕ) → Finset (WindowLeaf T (b+1)) → CoefficientShape b + | 0, path, S => .bottom S.card + (fun i => motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X path)) + (fun i => (prouhetSeries s).coeff (((S.equivFin.symm i).val.1.val:ℤ)-X path)) + | b+1, path, S => .node (selectedChildren S).card + (fun i => motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X path)) + (fun i => (prouhetSeries s).coeff ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X path)) + (fun i => occupiedWindowShape T s X b + (path++[((selectedChildren S).equivFin.symm i).val.val]) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) + +theorem occupiedWindowShape_admissible (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : + (occupiedWindowShape T s X b path S).Admissible := by + induction b generalizing path with + | zero => exact fun _ => prouhet_motif_value s _ + | succ b ih => exact ⟨fun _ => prouhet_motif_value s _, fun _ => ih _ _⟩ + +/-- The literal coefficient product equals the evaluation of its occupied +shape; this is before any averaging or parity cancellation. -/ +theorem occupiedWindowShape_eval (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) (τ : ℝ) : + (occupiedWindowShape T s X b path S).eval τ = + ∏v∈S, (1-windowLeafSign T s X (b+1) path τ v)/2 := by + induction b generalizing path τ with + | zero => + change (∏i : Fin S.card, _) = _ + refine (selected_prod_index S (fun v : Fin (T 0) × Fin 1 => + (motifIndicator s ((v.1.val:ℤ)-X path) - + (prouhetSeries s).coeff ((v.1.val:ℤ)-X path)*τ)/2)).trans ?_ + apply Finset.prod_congr rfl + intro v hv + simp only [windowLeafSign,motifChildSign] + ring + | succ b ih => + change (∏i : Fin (selectedChildren S).card, _) = _ + simp_rw [ih] + refine (selected_prod_index (selectedChildren S) (fun h : Fin (T (b+1)) => + ∏v∈selectedChildLeaves S h, + (1-windowLeafSign T s X (b+1) (path++[h.val]) + (motifChildSign s (X path) h.val τ) v)/2)).trans ?_ + exact selected_prod_children S (fun v => + (1-windowLeafSign T s X (b+1+1) path τ v)/2) + +theorem selected_children_card {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset (α × β)) : + (∑h∈selectedChildren S, (selectedChildLeaves S h).card) = S.card := by + simpa only [Finset.sum_const,smul_eq_mul,mul_one] using + selected_sum_children S (fun _ => (1:ℕ)) + +theorem selectedChildLeaves_nonempty {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset (α × β)) (h : α) (hh : h∈selectedChildren S) : + (selectedChildLeaves S h).Nonempty := by + obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp hh + exact ⟨v.2,Finset.mem_image.mpr ⟨v,Finset.mem_filter.mpr ⟨hv,rfl⟩,rfl⟩⟩ + +theorem occupiedWindowShape_leafCount (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : (occupiedWindowShape T s X b path S).Choice) : + ((occupiedWindowShape T s X b path S).termTree a).leafCount = S.card := by + induction b generalizing path with + | zero => simp [occupiedWindowShape,CoefficientShape.termTree,OccupiedParityTree.leafCount] + | succ b ih => + change (∑i : Fin (selectedChildren S).card, _) = _ + simp_rw [ih] + exact (selected_sum_index (selectedChildren S) (fun h => + (selectedChildLeaves S h).card)).trans (selected_children_card S) + +theorem occupiedWindowShape_occupied (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) (hS : S.Nonempty) + (a : (occupiedWindowShape T s X b path S).Choice) : + ((occupiedWindowShape T s X b path S).termTree a).occupied := by + induction b generalizing path with + | zero => exact ⟨hS.card_pos,fun _ => trivial⟩ + | succ b ih => + refine ⟨(Finset.image_nonempty.mpr hS).card_pos,fun i => ?_⟩ + exact ih _ _ (selectedChildLeaves_nonempty S _ + ((selectedChildren S).equivFin.symm i).property) (a.1 i) + +/-- Forced-leaf count for a term of an actual selected monomial. -/ +theorem occupiedWindowShape_forced_count (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : (occupiedWindowShape T s X b path S).Choice) + (hw : (occupiedWindowShape T s X b path S).weight a ≠ 0) + (ho : ((occupiedWindowShape T s X b path S).termTree a).isOdd) + (hn : ((occupiedWindowShape T s X b path S).termTree a).noSingleton) : + 2^(b+1) ≤ S.card := by + simpa only [occupiedWindowShape_leafCount] using + (occupiedWindowShape T s X b path S).surviving_leaves a hw ho hn + +/-- The role choices depend only on the selected subset, not on any hidden +orientation. This common index type permits averaging before norm estimates. -/ +def OccupiedWindowChoice (T : ℕ → ℕ) : + (b : ℕ) → Finset (WindowLeaf T (b+1)) → Type + | 0, S => Fin S.card → Fin 3 + | b+1, S => + ((i : Fin (selectedChildren S).card) → OccupiedWindowChoice T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) × + (Fin (selectedChildren S).card → Fin 3) + +noncomputable instance occupiedWindowChoiceFintype (T : ℕ → ℕ) : + (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → Fintype (OccupiedWindowChoice T b S) + | 0, S => by unfold OccupiedWindowChoice; infer_instance + | b+1, S => by + letI := fun i : Fin (selectedChildren S).card => + occupiedWindowChoiceFintype T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) + unfold OccupiedWindowChoice + infer_instance + +noncomputable def occupiedWindowChoiceEquiv (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) : + (b : ℕ) → (path : List ℕ) → (S : Finset (WindowLeaf T (b+1))) → + OccupiedWindowChoice T b S ≃ (occupiedWindowShape T s X b path S).Choice + | 0, _, _ => Equiv.refl _ + | b+1, path, S => Equiv.prodCongr + (Equiv.piCongrRight fun i => occupiedWindowChoiceEquiv T s X b + (path++[((selectedChildren S).equivFin.symm i).val.val]) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)) + (Equiv.refl _) + +/-- The parity tree of a role choice is independent of all displacement bits. -/ +noncomputable def occupiedWindowTerm (T : ℕ → ℕ) : + (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → + OccupiedWindowChoice T b S → OccupiedParityTree (b+1) + | 0, S, a => .node S.card (fun _ => .leaf) a + | b+1, S, a => .node (selectedChildren S).card + (fun i => occupiedWindowTerm T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) a.2 + + theorem occupiedWindowTerm_eq (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : OccupiedWindowChoice T b S) : + (occupiedWindowShape T s X b path S).termTree + (occupiedWindowChoiceEquiv T s X b path S a) = occupiedWindowTerm T b S a := by + induction b generalizing path with + | zero => rfl + | succ b ih => + change OccupiedParityTree.node _ (fun i => _) _ = OccupiedParityTree.node _ _ _ + congr 1 + funext i + exact ih _ _ _ + +noncomputable def occupiedWindowWeight (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : OccupiedWindowChoice T b S) : ℝ := + (occupiedWindowShape T s X b path S).weight + (occupiedWindowChoiceEquiv T s X b path S a) + +/-- Exact source parity formula for the actual selected leaves, using a +single role index independent of the latent map. No fit conditioning. -/ +theorem occupiedWindow_difference (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : + (∏v∈S, (1-windowLeafSign T s X (b+1) path 1 v)/2) - + (∏v∈S, (1-windowLeafSign T s X (b+1) path (-1) v)/2) = + 2*∑a : OccupiedWindowChoice T b S, + if (occupiedWindowTerm T b S a).isOdd then occupiedWindowWeight T s X b path S a else 0 := by + rw [←occupiedWindowShape_eval,←occupiedWindowShape_eval, + CoefficientShape.difference_expansion _ (occupiedWindowShape_admissible T s X b path S)] + congr 1 + rw [←(occupiedWindowChoiceEquiv T s X b path S).sum_comp] + apply Finset.sum_congr rfl + intro a _ + rw [occupiedWindowTerm_eq] + rfl + +/-- Averaging the complete exact expansion keeps all correlations of the +common hidden map. The indicator of an odd root is deterministic. -/ +theorem occupiedWindow_averaged_difference {Ω : Type*} [Fintype Ω] + (R : FiniteLaw Ω) (T : ℕ → ℕ) (s : ℕ) (X : Ω → List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) : + R.expect (fun ω => ∏v∈S, (1-windowLeafSign T s (X ω) (b+1) path 1 v)/2) - + R.expect (fun ω => ∏v∈S, (1-windowLeafSign T s (X ω) (b+1) path (-1) v)/2) = + 2*∑a : OccupiedWindowChoice T b S, + if (occupiedWindowTerm T b S a).isOdd then + R.expect (fun ω => occupiedWindowWeight T s (X ω) b path S a) else 0 := by + unfold expect + rw [←Finset.sum_sub_distrib] + simp_rw [←mul_sub,occupiedWindow_difference,mul_left_comm (R.mass _) 2, + Finset.mul_sum] + rw [Finset.sum_comm] + simp_rw [←Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro a _ + by_cases h : (occupiedWindowTerm T b S a).isOdd <;> simp [h] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Arbitrary functions of the actual posterior count have the translated +fair-binomial law, not only its generating polynomial. -/ +theorem posterior_count_average {ι : Type*} [Fintype ι] + (d : ι → Option Bool) (F : ℤ → ℝ) : + (∑ b : ι → Bool, (∏i, (flagPosterior (d i)).mass (b i)) * + F (∑i, (bitIndex (b i):ℤ))) = + ∑k∈Finset.range ((∑i, hiddenTrial (d i))+1), + fairBinomial (∑i, hiddenTrial (d i)) k * F ((∑i,(visibleOnes (d i):ℤ))+k) := by + have H := congrArg (fun p : IntSeries => Finsupp.linearCombination ℝ F p.coeff) + (posterior_count_series d) + rw [fairSeries_sum,Finset.mul_sum] at H + simp only [AddMonoidAlgebra.single_mul_single,one_mul, + AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, + Finsupp.linearCombination_single,smul_eq_mul] at H + exact H + +theorem fairBinomial_reflect (n k : ℕ) (hk : k ≤ n) : + fairBinomial n (n-k) = fairBinomial n k := by + simp only [fairBinomial,Nat.choose_symm hk] + +/-- Reflection of the remaining hidden count. The known visible contribution +is kept, and no positivity assumption on the metadata mass is needed. -/ +theorem posterior_count_average_reflected {ι : Type*} [Fintype ι] + (d : ι → Option Bool) (F : ℤ → ℝ) : + (∑ b : ι → Bool, (∏i, (flagPosterior (d i)).mass (b i)) * + F (∑i, (bitIndex (b i):ℤ))) = + ∑k∈Finset.range ((∑i, hiddenTrial (d i))+1), + fairBinomial (∑i, hiddenTrial (d i)) k * + F ((∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i))-k) := by + rw [posterior_count_average] + rw [←Finset.sum_range_reflect] + apply Finset.sum_congr rfl + intro k hk + have hk' : k ≤ ∑i,hiddenTrial (d i) := by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hk + simp only [Nat.add_sub_cancel,fairBinomial_reflect _ _ hk',Nat.cast_sub hk'] + congr 2 + ring + +/-- The actual local signed motif averaged over posterior orientations is +exactly a translated smoothed Prouhet polynomial. -/ +theorem posterior_signed_motif {ι : Type*} [Fintype ι] + (d : ι → Option Bool) (s : ℕ) (z : ℤ) : + (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i)) * + (prouhetSeries s).coeff (z+∑i,(bitIndex (b i):ℤ))) = + (prouhetSeries s * fairSeries (∑i,hiddenTrial (d i))).coeff + (z+(∑i,(visibleOnes (d i):ℤ))+(∑i,hiddenTrial (d i))) := by + rw [posterior_count_average_reflected d (fun a => (prouhetSeries s).coeff (z+a)), + fairSeries_sum,Finset.mul_sum, + AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply] + apply Finset.sum_congr rfl + intro k hk + rw [AddMonoidAlgebra.coeff_mul_single_apply] + simp only [mul_comm] + congr 2 + omega + +/-- Singleton smoothing for literal hidden orientation bits. Other mechanisms +can now be conditioned on without changing this bound. -/ +theorem posterior_signed_motif_bound {ι : Type*} [Fintype ι] + (d : ι → Option Bool) (s : ℕ) (z : ℤ) : + |∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i)) * + (prouhetSeries s).coeff (z+∑i,(bitIndex (b i):ℤ))| ≤ + (2:ℝ)^(s*s)*((2*binomialBound ((∑i,hiddenTrial (d i))/(s+1)))^s * + binomialBound ((∑i,hiddenTrial (d i))/(s+1))) := by + rw [posterior_signed_motif] + exact (signed_binomial_smoothing _ s).1 _ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- The literal unsigned window evaluated at an affine fair-binomial shift. -/ +theorem windowKernel_binomial (n L : ℕ) (z : ℤ) : + windowKernel n L z = + ∑k∈Finset.range (n+1), fairBinomial n k * + (if 0 ≤ z+(k:ℤ) ∧ z+(k:ℤ) motifIndicator s (z+a)),windowKernel_binomial] + apply Finset.sum_congr rfl + intro k hk + simp only [motifIndicator,add_assoc] + +/-- The finite-series functional form of the posterior count identity. -/ +theorem posterior_count_support {ι : Type*} [Fintype ι] + (d : ι → Option Bool) (F : ℤ → ℝ) : + (∑b : ι → Bool, (∏i,(flagPosterior (d i)).mass (b i))*F (∑i,(bitIndex (b i):ℤ))) = + ∑v∈(fairSeries (∑i,hiddenTrial (d i))).coeff.support, + (fairSeries (∑i,hiddenTrial (d i))).coeff v * F ((∑i,(visibleOnes (d i):ℤ))+v) := by + rw [posterior_count_average] + have H := congrArg (fun p : IntSeries => + Finsupp.linearCombination ℝ (fun v => F ((∑i,(visibleOnes (d i):ℤ))+v)) p.coeff) + (fairSeries_sum (∑i,hiddenTrial (d i))) + simp only [AddMonoidAlgebra.coeff_sum,AddMonoidAlgebra.coeff_single,map_sum, + Finsupp.linearCombination_single,smul_eq_mul] at H + exact H.symm + +/-- The actual two-sibling anchor multiplier. Global bits are shared by the +two siblings until AFTER averaging; their local bits are independent. -/ +def posteriorJointAnchors {ιg ι₁ ι₂ : Type*} [Fintype ιg] [Fintype ι₁] [Fintype ι₂] + (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) + (s : ℕ) (z₁ z₂ : ℤ) : ℝ := + ∑bg : ιg → Bool, (∏i,(flagPosterior (dg i)).mass (bg i)) * + (∑b₁ : ι₁ → Bool, (∏i,(flagPosterior (d₁ i)).mass (b₁ i)) * + motifIndicator s (z₁+(∑i,(bitIndex (bg i):ℤ))+(∑i,(bitIndex (b₁ i):ℤ)))) * + (∑b₂ : ι₂ → Bool, (∏i,(flagPosterior (d₂ i)).mass (b₂ i)) * + motifIndicator s (z₂+(∑i,(bitIndex (bg i):ℤ))+(∑i,(bitIndex (b₂ i):ℤ)))) + +theorem posteriorJointAnchors_eq {ιg ι₁ ι₂ : Type*} [Fintype ιg] [Fintype ι₁] [Fintype ι₂] + (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) + (s : ℕ) (z₁ z₂ : ℤ) : + posteriorJointAnchors dg d₁ d₂ s z₁ z₂ = + jointWindowKernel (∑i,hiddenTrial (dg i)) (∑i,hiddenTrial (d₁ i)) + (∑i,hiddenTrial (d₂ i)) (2^s) + (z₁+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₁ i):ℤ))) + (z₂+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₂ i):ℤ))) := by + unfold posteriorJointAnchors + simp_rw [posterior_unsigned_motif,mul_assoc] + rw [posterior_count_support dg (fun v => + windowKernel (∑i,hiddenTrial (d₁ i)) (2^s) (z₁+v+∑i,(visibleOnes (d₁ i):ℤ)) * + windowKernel (∑i,hiddenTrial (d₂ i)) (2^s) (z₂+v+∑i,(visibleOnes (d₂ i):ℤ)))] + unfold jointWindowKernel + apply Finset.sum_congr rfl + intro v hv + have h₁ : z₁+((∑i,(visibleOnes (dg i):ℤ))+v)+(∑i,(visibleOnes (d₁ i):ℤ)) = + z₁+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₁ i):ℤ))+v := by ring + have h₂ : z₂+((∑i,(visibleOnes (dg i):ℤ))+v)+(∑i,(visibleOnes (d₂ i):ℤ)) = + z₂+(∑i,(visibleOnes (dg i):ℤ))+(∑i,(visibleOnes (d₂ i):ℤ))+v := by ring + rw [h₁,h₂,mul_assoc] + +/-- Quantitative sibling summation now directly bounds genuine posterior +bits, not an independent-anchor surrogate. -/ +theorem posterior_sibling_anchor_energy {ιg ι₁ ι₂ : Type*} + [Fintype ιg] [Fintype ι₁] [Fintype ι₂] + (dg : ιg → Option Bool) (d₁ : ι₁ → Option Bool) (d₂ : ι₂ → Option Bool) + (s : ℕ) (A B C D : Finset ℤ) (c₁ c₂ : ℤ) : + (∑a∈A, ∑b∈B, ∑_c∈closeLabels C (2^s) a, ∑_d∈closeLabels D (2^s) b, + (posteriorJointAnchors dg d₁ d₂ s (a-c₁) (b-c₂))^2) ≤ + 4*((2^s:ℕ):ℝ)^6*binomialBound (∑i,hiddenTrial (dg i))* + binomialBound (∑i,hiddenTrial (d₂ i)) := by + simp_rw [posteriorJointAnchors_eq] + have he : ∀a c u v : ℤ, a-c+u+v = a-(c-u-v) := by intros; omega + simp_rw [he] + exact sibling_anchor_energy (∑i,hiddenTrial (dg i)) (∑i,hiddenTrial (d₁ i)) + (∑i,hiddenTrial (d₂ i)) (2^s) A B C D + (c₁-(∑i,(visibleOnes (dg i):ℤ))-(∑i,(visibleOnes (d₁ i):ℤ))) + (c₂-(∑i,(visibleOnes (dg i):ℤ))-(∑i,(visibleOnes (d₂ i):ℤ))) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +theorem expect_mul_const (P : FiniteLaw α) (f : α → ℝ) (c : ℝ) : + P.expect (fun a => f a*c) = P.expect f*c := by + unfold expect + simp only [←mul_assoc,Finset.sum_mul] + +theorem expect_const_mul (P : FiniteLaw α) (f : α → ℝ) (c : ℝ) : + P.expect (fun a => c*f a) = c*P.expect f := by + unfold expect + simp only [mul_left_comm (P.mass _) c,Finset.mul_sum] + +theorem coordinateProduct_expect_product {n : ℕ} (P : Fin n → FiniteLaw α) + (f : Fin n → α → ℝ) : + (coordinateProduct P).expect (fun x => ∏i,f i (x i)) = ∏i,(P i).expect (f i) := by + unfold expect coordinateProduct + simp only [←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun (i : Fin n) (a : α) => (P i).mass a*f i a)).symm + +theorem expect_prod_split (P : FiniteLaw α) (Q : FiniteLaw β) + (f : α → ℝ) (g : β → ℝ) : + (P.prod Q).expect (fun x => f x.1*g x.2) = P.expect f * Q.expect g := by + rw [expect_prod] + simp_rw [expect_const_mul] + exact expect_mul_const P f _ + +end FiniteLaw + +/-- All local and global orientation collections on the complete index tree, +including unoccupied vertices and paths which do not fit. The type is fixed +before any selected monomial or role choices. `n` is the local trial count, +`g` the number of global paired trials, and T the full window counts. -/ +def WindowAssignments (T n g : ℕ → ℕ) (A : Type) : ℕ → Type + | 0 => PUnit + | b+1 => (Fin (n b) → A) × (Fin (g b) → A) × + (Fin (T b) → WindowAssignments T n g A b) + +noncomputable instance windowAssignmentsFintype (T n g : ℕ → ℕ) (A : Type) [Fintype A] : + (b : ℕ) → Fintype (WindowAssignments T n g A b) + | 0 => inferInstanceAs (Fintype PUnit) + | b+1 => by + letI := windowAssignmentsFintype T n g A b + exact inferInstanceAs (Fintype ((Fin (n b) → A) × (Fin (g b) → A) × + (Fin (T b) → WindowAssignments T n g A b))) + +def posteriorArray {n : ℕ} (d : Fin n → Option Bool) : FiniteLaw (Fin n → Bool) := + coordinateProduct (fun i => flagPosterior (d i)) + +/-- Actual independent posterior orientations at exact non-leaf metadata. +The common global bits in a group are drawn only once. -/ +def windowPosteriorLaw (T n g : ℕ → ℕ) : (b : ℕ) → + WindowAssignments T n g (Option Bool) b → FiniteLaw (WindowAssignments T n g Bool b) + | 0, _ => ⟨fun _ => 1,fun _ => by norm_num,by change (∑_ : PUnit,(1:ℝ))=1; simp⟩ + | b+1, d => (posteriorArray d.1).prod ((posteriorArray d.2.1).prod + (coordinateProduct (fun i => windowPosteriorLaw T n g b (d.2.2 i)))) + +/-- Displacements from the jointly generated bit tree. The ancestor global +map may vary off its plateau. No independent jitter per child is introduced. +The fixed center includes the deterministic half-trial corrections. -/ +def sourceTreeAnchors (T n g : ℕ → ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : + (b : ℕ) → WindowAssignments T n g Bool b → ℤ → List ℕ → ℤ + | 0, _, _, _ => 0 + | b+1, bits, incoming, [] => center b - (∑i,(bitIndex (bits.1 i):ℤ))-incoming + | b+1, bits, _, h::tail => if hh : h X (pre++tail)) b path τ v := by + induction b generalizing path τ with + | zero => rfl + | succ b ih => + change windowLeafSign T s X b _ _ v.2 = _ + rw [List.append_assoc,ih] + rfl + +/-- Exact recursive leaf signs for the complete bit tree, with one joint +parent-global shift supplied to each sibling's local mechanism. -/ +def sourceTreeLeafSign (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) : + (b : ℕ) → WindowAssignments T n g Bool b → ℤ → ℝ → WindowLeaf T b → ℝ + | 0, _, _, τ, _ => τ + | b+1, bits, incoming, τ, v => + sourceTreeLeafSign T n g s center globalShift b (bits.2.2 v.1) + (globalShift b bits.2.1 v.1) + (motifChildSign s (center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) v.1.val τ) v.2 + +theorem sourceTreeLeafSign_eq (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool b) (incoming : ℤ) + (τ : ℝ) (v : WindowLeaf T b) : + sourceTreeLeafSign T n g s center globalShift b bits incoming τ v = + windowLeafSign T s (sourceTreeAnchors T n g center globalShift b bits incoming) b [] τ v := by + induction b generalizing incoming τ with + | zero => rfl + | succ b ih => + change sourceTreeLeafSign T n g s center globalShift b _ _ _ v.2 = + windowLeafSign T s _ b [v.1.val] _ v.2 + rw [ih] + have hp := windowLeafSign_prefix T s + (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) + b [v.1.val] [] + (motifChildSign s (center b-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) v.1.val τ) v.2 + simp only [List.append_nil,List.singleton_append,sourceTreeAnchors_child] at hp + exact hp.symm + +end TraceReconstruction + +-- Actual subtree coefficient factorization and singleton cancellation. +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- The factor at the current vertex of a fixed actual occupied role choice. +It only uses that vertex's displacement, never any descendant mechanism. -/ +def occupiedRootWeight (T : ℕ → ℕ) (s : ℕ) : + (b : ℕ) → (S : Finset (WindowLeaf T (b+1))) → + OccupiedWindowChoice T b S → ℤ → ℝ + | 0, S, a, X => ∏i : Fin S.card, + bottomRoleWeight (motifIndicator s (((S.equivFin.symm i).val.1.val:ℤ)-X)) + ((prouhetSeries s).coeff (((S.equivFin.symm i).val.1.val:ℤ)-X)) (a i) + | b+1, S, a, X => ∏i : Fin (selectedChildren S).card, + @internalRoleWeight (occupiedWindowTerm T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)).isOdd + (Classical.propDecidable _) + (motifIndicator s ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X)) + ((prouhetSeries s).coeff ((((selectedChildren S).equivFin.symm i).val.val:ℤ)-X)) (a.2 i) + +theorem occupiedWindowWeight_zero (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (path : List ℕ) (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : + occupiedWindowWeight T s X 0 path S a = occupiedRootWeight T s 0 S a (X path) := rfl + +theorem occupiedWindowWeight_succ (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1+1))) + (a : OccupiedWindowChoice T (b+1) S) : + occupiedWindowWeight T s X (b+1) path S a = + occupiedRootWeight T s (b+1) S a (X path) * + ∏i : Fin (selectedChildren S).card, + occupiedWindowWeight T s X b + (path++[((selectedChildren S).equivFin.symm i).val.val]) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) := by + unfold occupiedWindowWeight + change (∏i, _ * @internalRoleWeight + ((occupiedWindowShape T s X b + (path++[((selectedChildren S).equivFin.symm i).val.val]) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val)).termTree + (occupiedWindowChoiceEquiv T s X b + (path++[((selectedChildren S).equivFin.symm i).val.val]) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i))).isOdd + (Classical.propDecidable _) _ _ _) = _ + simp_rw [occupiedWindowTerm_eq] + rw [Finset.prod_mul_distrib,mul_comm] + rfl + +/-- Moving a subtree's path origin does not change any of its role factors. -/ +theorem occupiedWindowWeight_prefix (T : ℕ → ℕ) (s : ℕ) (X : List ℕ → ℤ) + (b : ℕ) (pre path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : OccupiedWindowChoice T b S) : + occupiedWindowWeight T s X b (pre++path) S a = + occupiedWindowWeight T s (fun tail => X (pre++tail)) b path S a := by + induction b generalizing path with + | zero => rfl + | succ b ih => + rw [occupiedWindowWeight_succ,occupiedWindowWeight_succ] + congr 1 + apply Finset.prod_congr rfl + intro i hi + rw [List.append_assoc,ih] + +theorem bottomRoleWeight_abs_le_one (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : + |bottomRoleWeight χ σ a| ≤ 1 := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> + fin_cases a <;> norm_num [bottomRoleWeight] + +theorem internalRoleWeight_abs_le_one (odd : Prop) [Decidable odd] + (χ σ : ℝ) (h : IsMotifValue χ σ) (a : Fin 3) : + |internalRoleWeight odd χ σ a| ≤ 1 := by + rcases h with ⟨rfl,rfl⟩ | ⟨rfl,rfl|rfl⟩ <;> + fin_cases a <;> by_cases ho : odd <;> norm_num [internalRoleWeight,roleWeight,ho] + +theorem occupiedRootWeight_abs_le_one (T : ℕ → ℕ) (s b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) (X : ℤ) : + |occupiedRootWeight T s b S a X| ≤ 1 := by + cases b with + | zero => + rw [occupiedRootWeight,Finset.abs_prod] + exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) + (fun i _ => bottomRoleWeight_abs_le_one _ _ (prouhet_motif_value s _) (a i)) + | succ b => + rw [occupiedRootWeight,Finset.abs_prod] + exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) + (fun i _ => internalRoleWeight_abs_le_one _ _ _ (prouhet_motif_value s _) (a.2 i)) + +theorem occupiedWindowWeight_abs_le_one (T : ℕ → ℕ) (s : ℕ) + (X : List ℕ → ℤ) (b : ℕ) (path : List ℕ) (S : Finset (WindowLeaf T (b+1))) + (a : OccupiedWindowChoice T b S) : |occupiedWindowWeight T s X b path S a| ≤ 1 := by + induction b generalizing path with + | zero => exact occupiedRootWeight_abs_le_one T s 0 S a _ + | succ b ih => + rw [occupiedWindowWeight_succ,abs_mul,Finset.abs_prod] + exact (mul_le_of_le_one_left (by positivity) + (occupiedRootWeight_abs_le_one T s (b+1) S a _)).trans + (Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) (fun i _ => ih _ _ _)) + +/-- A singleton signed role factors off its signed motif with a scalar +independent of all displacements. Bottom zero-role terms really vanish. -/ +theorem bottom_singleton_factor {n : ℕ} (a : Fin n → Fin 3) (i : Fin n) + (hi : a i=2) (hrest : ∀j,j≠i → a j=0) : + ∃c : ℝ, |c|≤1 ∧ ∀χ σ : Fin n → ℝ, + (∏j,bottomRoleWeight (χ j) (σ j) (a j)) = c*σ i := by + let c : ℝ := -(∏j∈Finset.univ.erase i,(0:ℝ))/2 + refine ⟨c,?_,?_⟩ + · have hp : 0 ≤ ∏j∈Finset.univ.erase i,(0:ℝ) := Finset.prod_nonneg (fun _ _ => le_rfl) + have hp' : (∏j∈Finset.univ.erase i,(0:ℝ)) ≤ 1 := Finset.prod_le_one₀ + (fun _ _ => le_rfl) (fun _ _ => by norm_num) + dsimp [c] + rw [abs_div,abs_neg,abs_of_nonneg hp] + rw [abs_of_pos (by norm_num : (0:ℝ)<2)] + linarith + · intro χ σ + rw [←Finset.prod_erase_mul _ _ (Finset.mem_univ i)] + have he : (∏j∈Finset.univ.erase i,bottomRoleWeight (χ j) (σ j) (a j)) = + ∏j∈Finset.univ.erase i,(0:ℝ) := by + apply Finset.prod_congr rfl + intro j hj + simp only [hrest j (Finset.mem_erase.mp hj).1,bottomRoleWeight,↓reduceIte] + rw [he,hi] + simp only [bottomRoleWeight,show (2:Fin 3)≠0 by decide, + show (2:Fin 3)≠1 by decide,↓reduceIte] + dsimp [c] + ring + +theorem internal_singleton_factor {n : ℕ} (odd : Fin n → Prop) + (a : Fin n → Fin 3) (i : Fin n) (hi : a i=2) (hrest : ∀j,j≠i → a j=0) : + ∃c : ℝ, |c|≤1 ∧ ∀χ σ : Fin n → ℝ, + (∏j,@internalRoleWeight (odd j) (Classical.propDecidable _) (χ j) (σ j) (a j)) = c*σ i := by + refine ⟨if odd i then 1 else 0,?_,?_⟩ + · split_ifs <;> norm_num + · intro χ σ + rw [Finset.prod_eq_single i] + · by_cases ho : odd i <;> simp [internalRoleWeight,roleWeight,hi,ho] + · intro j hj hji + by_cases ho : odd j <;> simp [internalRoleWeight,roleWeight,hrest j hji,ho] + · simp + +namespace FiniteLaw + +/-- Unoccupied independent coordinates integrate to one. -/ +theorem coordinateProduct_expect_subtype {α : Type*} [Fintype α] {n : ℕ} + (P : Fin n → FiniteLaw α) (S : Finset (Fin n)) (f : S → α → ℝ) : + (coordinateProduct P).expect (fun x => ∏i : S, f i (x i.val)) = + ∏i : S, (P i.val).expect (f i) := by + have scalar : ∀f : S → ℝ, + (∏j : Fin n, if hj : j∈S then f ⟨j,hj⟩ else 1) = ∏i : S,f i := by + intro f + calc + _ = ∏j∈S, if hj : j∈S then f ⟨j,hj⟩ else 1 := + (Finset.prod_subset S.subset_univ (fun j _ hj => dite_eq_right hj)).symm + _ = ∏i : S, if hj : i.val∈S then f ⟨i.val,hj⟩ else 1 := + Finset.prod_subtype S (fun _ => Iff.rfl) _ + _ = _ := by simp only [dite_eq_left (Subtype.property _)] + let F : Fin n → α → ℝ := fun j a => if hj : j∈S then f ⟨j,hj⟩ a else 1 + have hp : ∀x : Fin n → α, (∏j,F j (x j)) = ∏i : S,f i (x i.val) := by + intro x + exact scalar (fun i => f i (x i.val)) + rw [show (fun x : Fin n → α => ∏i : S,f i (x i.val)) = (fun x => ∏j,F j (x j)) by + funext x; exact (hp x).symm] + rw [coordinateProduct_expect_product] + have he : ∀j, (P j).expect (F j) = if hj : j∈S then (P j).expect (f ⟨j,hj⟩) else 1 := by + intro j + by_cases hj : j∈S + · simp only [F,dite_eq_left hj] + · simp only [F,dite_eq_right hj,expect_const] + simp_rw [he] + exact scalar (fun i => (P i.val).expect (f i)) + +theorem coordinateProduct_expect_selected {α : Type*} [Fintype α] {n : ℕ} + (P : Fin n → FiniteLaw α) (S : Finset (Fin n)) (f : Fin S.card → α → ℝ) : + (coordinateProduct P).expect (fun x => ∏i : Fin S.card, f i (x (S.equivFin.symm i).val)) = + ∏i : Fin S.card, (P (S.equivFin.symm i).val).expect (f i) := by + have hp : ∀x : Fin n → α, + (∏i : Fin S.card,f i (x (S.equivFin.symm i).val)) = + ∏i : S,f (S.equivFin i) (x i.val) := by + intro x + simpa only [Equiv.apply_symm_apply] using + Equiv.prod_comp S.equivFin.symm (fun i : S => f (S.equivFin i) (x i.val)) + simp_rw [hp,coordinateProduct_expect_subtype] + symm + simpa only [Equiv.apply_symm_apply] using + Equiv.prod_comp S.equivFin.symm (fun i : S => (P i.val).expect (f (S.equivFin i))) + +theorem expect_prod_selected {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + {n : ℕ} (P : FiniteLaw α) (Q : FiniteLaw β) (R : Fin n → FiniteLaw γ) + (S : Finset (Fin n)) (f : α → ℝ) (h : β → Fin S.card → γ → ℝ) : + (P.prod (Q.prod (coordinateProduct R))).expect (fun x => + f x.1 * ∏i : Fin S.card, h x.2.1 i (x.2.2 (S.equivFin.symm i).val)) = + P.expect f * Q.expect (fun z => ∏i : Fin S.card, + (R (S.equivFin.symm i).val).expect (h z i)) := by + simp_rw [expect_prod,expect_const_mul,coordinateProduct_expect_selected] + rw [expect_mul_const] + +theorem abs_expect_le_const {α : Type*} [Fintype α] (P : FiniteLaw α) + (f : α → ℝ) (c : ℝ) (h : ∀a, |f a|≤c) : |P.expect f|≤c := + (P.abs_expect_le f).trans ((P.expect_mono h).trans_eq (P.expect_const c)) + +end FiniteLaw + + +/-- A fixed real coefficient term evaluated on the actual complete bit tree. +The selected role choice is fixed independently of these bits. -/ +def sourceRoleTerm (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : ℝ := + occupiedWindowWeight T s (sourceTreeAnchors T n g center globalShift (b+1) bits incoming) + b [] S a + +def sourceRoleAverage (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : ℝ := + (windowPosteriorLaw T n g (b+1) d).expect + (fun bits => sourceRoleTerm T n g s center globalShift b bits incoming S a) + +theorem sourceRoleTerm_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (bits : WindowAssignments T n g Bool 1) (incoming : ℤ) + (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : + sourceRoleTerm T n g s center globalShift 0 bits incoming S a = + occupiedRootWeight T s 0 S a (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) := rfl + +theorem sourceRoleTerm_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (bits : WindowAssignments T n g Bool (b+1+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) : + sourceRoleTerm T n g s center globalShift (b+1) bits incoming S a = + occupiedRootWeight T s (b+1) S a (center (b+1)-(∑i,(bitIndex (bits.1 i):ℤ))-incoming) * + ∏i : Fin (selectedChildren S).card, + sourceRoleTerm T n g s center globalShift b + (bits.2.2 ((selectedChildren S).equivFin.symm i).val) + (globalShift (b+1) bits.2.1 ((selectedChildren S).equivFin.symm i).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) := by + unfold sourceRoleTerm + rw [occupiedWindowWeight_succ] + congr 1 + apply Finset.prod_congr rfl + intro i hi + have hp := occupiedWindowWeight_prefix T s + (sourceTreeAnchors T n g center globalShift (b+1+1) bits incoming) b + [((selectedChildren S).equivFin.symm i).val.val] [] + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i) + simpa only [List.append_nil,List.nil_append,List.singleton_append,sourceTreeAnchors_child] using hp + +theorem sourceRoleAverage_zero (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (d : WindowAssignments T n g (Option Bool) 1) (incoming : ℤ) + (S : Finset (WindowLeaf T 1)) (a : OccupiedWindowChoice T 0 S) : + sourceRoleAverage T n g s center globalShift 0 d incoming S a = + (posteriorArray d.1).expect (fun loc => + occupiedRootWeight T s 0 S a (center 0-(∑i,(bitIndex (loc i):ℤ))-incoming)) := by + rw [sourceRoleAverage] + simp_rw [sourceRoleTerm_zero] + rcases d with ⟨dl,dg,dc⟩ + change ((posteriorArray dl).prod ((posteriorArray dg).prod + (coordinateProduct (fun i => windowPosteriorLaw T n g 0 (dc i))))).expect + (fun bits => occupiedRootWeight T s 0 S a + (center 0-(∑i,(bitIndex (bits.1 i):ℤ))-incoming)) = _ + rw [expect_prod] + simp only [expect_const] + +theorem sourceRoleAverage_succ (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1+1))) (a : OccupiedWindowChoice T (b+1) S) : + sourceRoleAverage T n g s center globalShift (b+1) d incoming S a = + (posteriorArray d.1).expect (fun loc => + occupiedRootWeight T s (b+1) S a (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming)) * + (posteriorArray d.2.1).expect (fun glob => + ∏i : Fin (selectedChildren S).card, + sourceRoleAverage T n g s center globalShift b + (d.2.2 ((selectedChildren S).equivFin.symm i).val) + (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) := by + rw [sourceRoleAverage] + simp_rw [sourceRoleTerm_succ] + exact FiniteLaw.expect_prod_selected (posteriorArray d.1) (posteriorArray d.2.1) + (fun i => windowPosteriorLaw T n g (b+1) (d.2.2 i)) (selectedChildren S) + (fun loc => occupiedRootWeight T s (b+1) S a + (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming)) + (fun glob i bits => sourceRoleTerm T n g s center globalShift b bits + (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) + +theorem sourceRoleAverage_abs_le_one (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤1 := by + apply FiniteLaw.abs_expect_le_const + intro bits + exact occupiedWindowWeight_abs_le_one T s _ b [] S a + +/-- The exact signed smoothing cost read off the visible metadata alone. -/ +def posteriorSmoothingCost {ι : Type*} [Fintype ι] (s : ℕ) (d : ι → Option Bool) : ℝ := + (2:ℝ)^(s*s)*((2*binomialBound ((∑i,hiddenTrial (d i))/(s+1)))^s * + binomialBound ((∑i,hiddenTrial (d i))/(s+1))) + +/-- A purely numerical typical-metadata condition on every local collection. +It includes unoccupied vertices and is fixed before a coefficient is chosen. -/ +def MetadataSmoothingCap (T n g : ℕ → ℕ) (s : ℕ) (η : ℝ) : + (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop + | 0, _ => True + | b+1, d => posteriorSmoothingCost s d.1 ≤ η ∧ + ∀h, MetadataSmoothingCap T n g s η b (d.2.2 h) + +def occupiedRootHasSingleton (T : ℕ → ℕ) : (b : ℕ) → + (S : Finset (WindowLeaf T (b+1))) → OccupiedWindowChoice T b S → Prop + | 0, _, a => ∃i, a i=2 ∧ ∀j,j≠i → a j=0 + | _+1, _, a => ∃i, a.2 i=2 ∧ ∀j,j≠i → a.2 j=0 + +theorem occupiedRoot_singleton_factor (T : ℕ → ℕ) (s b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (h : occupiedRootHasSingleton T b S a) : + ∃c : ℝ, |c|≤1 ∧ ∃label : ℤ, ∀X, + occupiedRootWeight T s b S a X = c*(prouhetSeries s).coeff (label-X) := by + cases b with + | zero => + obtain ⟨i,hi,hr⟩ := h + obtain ⟨c,hc,hfac⟩ := bottom_singleton_factor a i hi hr + refine ⟨c,hc,((S.equivFin.symm i).val.1.val:ℤ),fun X => ?_⟩ + exact hfac _ _ + | succ b => + obtain ⟨i,hi,hr⟩ := h + obtain ⟨c,hc,hfac⟩ := internal_singleton_factor + (fun j => (occupiedWindowTerm T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) (a.1 j)).isOdd) + a.2 i hi hr + refine ⟨c,hc,(((selectedChildren S).equivFin.symm i).val.val:ℤ),fun X => ?_⟩ + exact hfac _ _ + +theorem occupiedRoot_singleton_average (T : ℕ → ℕ) (s b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (h : occupiedRootHasSingleton T b S a) {m : ℕ} (d : Fin m → Option Bool) + (center incoming : ℤ) : + |(posteriorArray d).expect (fun loc => occupiedRootWeight T s b S a + (center-(∑i,(bitIndex (loc i):ℤ))-incoming))| ≤ posteriorSmoothingCost s d := by + obtain ⟨c,hc,label,hfac⟩ := occupiedRoot_singleton_factor T s b S a h + simp_rw [hfac,expect_const_mul,abs_mul] + have he : ∀loc : Fin m → Bool, + label-(center-(∑i,(bitIndex (loc i):ℤ))-incoming) = + (label-center+incoming)+(∑i,(bitIndex (loc i):ℤ)) := by intro loc; omega + simp_rw [he] + have hb : |(posteriorArray d).expect (fun loc => + (prouhetSeries s).coeff ((label-center+incoming)+(∑i,(bitIndex (loc i):ℤ))))| ≤ + posteriorSmoothingCost s d := by + have hb := posterior_signed_motif_bound d s (label-center+incoming) + unfold posteriorArray coordinateProduct expect posteriorSmoothingCost + convert hb using 1 + congr 3 + exact Subsingleton.elim _ _ + calc + _ ≤ 1*|(posteriorArray d).expect (fun loc => + (prouhetSeries s).coeff ((label-center+incoming)+(∑i,(bitIndex (loc i):ℤ))))| := + mul_le_mul_of_nonneg_right hc (abs_nonneg _) + _ ≤ _ := by simpa only [one_mul] using hb + +theorem abs_prod_le_coordinate {ι : Type*} [Fintype ι] (f : ι → ℝ) (i : ι) + (h : ∀j,j≠i → |f j|≤1) : |∏j,f j|≤|f i| := by + rw [Finset.abs_prod,←Finset.prod_erase_mul _ _ (Finset.mem_univ i)] + have he : (∏j∈Finset.univ.erase i,|f j|)≤1 := + Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) (fun j hj => h j (Finset.mem_erase.mp hj).1) + simpa only [one_mul] using mul_le_mul_of_nonneg_right he (abs_nonneg (f i)) + +/-- Literal singleton cancellation for the complete posterior bit tree. +No successful-fit event is conditioned on, and the common parent-global +jitter is retained until after the child factors have averaged. -/ +theorem sourceRoleAverage_singleton (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (b : ℕ) (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (η : ℝ) (hcap : MetadataSmoothingCap T n g s η (b+1) d) + (hsing : ¬(occupiedWindowTerm T b S a).noSingleton) : + |sourceRoleAverage T n g s center globalShift b d incoming S a|≤η := by + induction b generalizing incoming with + | zero => + have hh : Odd (signedRoleCount a) ∧ activeRoleCount a=1 := by + by_contra! h + apply hsing + exact ⟨fun ho he => h ho he,fun _ => trivial⟩ + have hr : occupiedRootHasSingleton T 0 S a := + (odd_roles_singleton_or_branch a hh.1).resolve_right (by omega) + rw [sourceRoleAverage_zero] + exact (occupiedRoot_singleton_average T s 0 S a hr d.1 _ _).trans hcap.1 + | succ b ih => + rw [sourceRoleAverage_succ,abs_mul] + have hroot : |(posteriorArray d.1).expect (fun loc => + occupiedRootWeight T s (b+1) S a + (center (b+1)-(∑i,(bitIndex (loc i):ℤ))-incoming))|≤1 := + FiniteLaw.abs_expect_le_const _ _ 1 (fun _ => occupiedRootWeight_abs_le_one T s (b+1) S a _) + have hglob : |(posteriorArray d.2.1).expect (fun glob => + ∏i : Fin (selectedChildren S).card, + sourceRoleAverage T n g s center globalShift b + (d.2.2 ((selectedChildren S).equivFin.symm i).val) + (globalShift (b+1) glob ((selectedChildren S).equivFin.symm i).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i))|≤1 := by + apply FiniteLaw.abs_expect_le_const + intro glob + rw [Finset.abs_prod] + exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) + (fun i _ => sourceRoleAverage_abs_le_one T n g s center globalShift b _ _ _ _) + by_cases hr : occupiedRootHasSingleton T (b+1) S a + · have hh := (occupiedRoot_singleton_average T s (b+1) S a hr d.1 + (center (b+1)) incoming).trans hcap.1 + exact (mul_le_mul_of_nonneg_left hglob (abs_nonneg _)).trans (by simpa using hh) + · have hex : ∃i, ¬(occupiedWindowTerm T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)).noSingleton := by + by_contra! h + apply hsing + refine ⟨?_,h⟩ + intro ho he + have hh := odd_roles_singleton_or_branch a.2 ho + exact hr (hh.resolve_right (by omega)) + obtain ⟨i,hi⟩ := hex + have hsmall : |(posteriorArray d.2.1).expect (fun glob => + ∏j : Fin (selectedChildren S).card, + sourceRoleAverage T n g s center globalShift b + (d.2.2 ((selectedChildren S).equivFin.symm j).val) + (globalShift (b+1) glob ((selectedChildren S).equivFin.symm j).val) + (selectedChildLeaves S ((selectedChildren S).equivFin.symm j).val) (a.1 j))|≤η := by + apply FiniteLaw.abs_expect_le_const + intro glob + apply (abs_prod_le_coordinate _ i (fun j _ => + sourceRoleAverage_abs_le_one T n g s center globalShift b _ _ _ _)).trans + exact ih _ _ _ _ (hcap.2 _) hi + exact (mul_le_mul_of_nonneg_right hroot (abs_nonneg _)).trans (by simpa using hsmall) + +end TraceReconstruction + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Metadata.lean b/lean/OAI/Probability/TraceReconstruction/Metadata.lean index bf1824c051dd0759ac56095cf6723eba93893888..d97dfcfd9de594612e39823b52bfc478b31ebd50 100644 --- a/lean/OAI/Probability/TraceReconstruction/Metadata.lean +++ b/lean/OAI/Probability/TraceReconstruction/Metadata.lean @@ -1,772 +1,772 @@ -import OAI.Probability.TraceReconstruction.Layout - -namespace OAI - -/-! -# Metadata - -Hidden metadata, fair jitter, heterogeneous emissions, independent window trials, concentration, and fit. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -theorem pairedReportMass_none (P Q H : FiniteLaw α) (ω : ℝ) (z : α × α) : - pairedReportMass P Q H ω (none,z)=pairedHiddenMass H ω z := by - simp only [pairedReportMass,Fintype.sum_bool,pairedFlagMass] - ring - -theorem pairedReport_hidden_expect (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0≤ω) - (hP : ∀a,ω*H.mass a≤P.mass a) (hQ : ∀a,ω*H.mass a≤Q.mass a) (F : ℕ → ℝ) : - (pairedReport P Q H hω hP hQ).expect (fun z => F (hiddenTrial z.1))= - ω^2*F 1+(1-ω^2)*F 0 := by - let R := pairedReport P Q H hω hP hQ - have hp : R.expect (fun z => if z.1=none then (1:ℝ) else 0)=ω^2 := by - simp only [expect,R,pairedReport,Fintype.sum_prod_type,Fintype.sum_option] - simp only [reduceCtorEq,ite_false,mul_zero,Finset.sum_const_zero,add_zero] - simpa only [pairedReportMass_none,Fintype.sum_prod_type,ite_true,mul_one] using sum_pairedHiddenMass H ω - have he (z : Option Bool × (α × α)) : F (hiddenTrial z.1)= - F 0+(F 1-F 0)*(if z.1=none then 1 else 0) := by - rcases z with ⟨d,z⟩; cases d <;> simp [hiddenTrial] - simp_rw [he] - have hadd : R.expect (fun z => F 0+(F 1-F 0)*(if z.1=none then 1 else 0))= - R.expect (fun _ => F 0)+R.expect (fun z => (F 1-F 0)*(if z.1=none then 1 else 0)) := by - simp only [expect,mul_add,Finset.sum_add_distrib] - rw [hadd,expect_const,expect_const_mul,hp] - ring - -/-- Centered hidden-flag MGF, derived from the literal paired experiment. -/ -theorem pairedReport_hidden_mgf (P Q H : FiniteLaw α) {ω t : ℝ} (hω : 0≤ω) - (hP : ∀a,ω*H.mass a≤P.mass a) (hQ : ∀a,ω*H.mass a≤Q.mass a) - (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : - (pairedReport P Q H hω hP hQ).expect (fun z => - Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2)))≤Real.exp (t^2) := by - rw [pairedReport_hidden_expect P Q H hω hP hQ (fun k => Real.exp (t*((k:ℝ)-ω^2)))] - have H := binomialMass_centered_mgf 1 hp ht - norm_num [Finset.sum_range_succ,binomialMass] at H ⊢ - convert H using 1 ; ring - -end FiniteLaw - -namespace PairedMechanisms -variable {Side : Type*} [Fintype Side] {m : ℕ} (M : PairedMechanisms Side m) - -def hiddenCount (z : Reports Side m) : ℕ := ∑i,hiddenTrial (z i).1 - -/-- No independence of displacements is presumed: only the flags of the - distinct literal paired mechanisms are independent. -/ -theorem hiddenCount_mgf {ω t : ℝ} (hw : ∀i,M.hiddenWeight i=ω) - (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : - M.reports.expect (fun z => Real.exp (t*((hiddenCount z:ℕ)-(m:ℝ)*ω^2)))≤ - Real.exp ((m:ℝ)*t^2) := by - have he (z : Reports Side m) : - Real.exp (t*((hiddenCount z:ℕ)-(m:ℝ)*ω^2))= - ∏i : Fin m,Real.exp (t*((hiddenTrial (z i).1:ℕ)-ω^2)) := by - rw [←Real.exp_sum] - congr 1 - simp only [mul_sub,Finset.mul_sum,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, - nsmul_eq_mul,hiddenCount,Nat.cast_sum] - ring - simp_rw [he] - rw [reports,FiniteLaw.coordinateProduct_expect_product _ - (fun (_ : Fin m) (z : Option Bool × (Side × Side)) => Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2))) ] - calc - _ ≤ ∏i : Fin m,Real.exp (t^2) := by - apply Finset.prod_le_prod₀ - · intro i _ - exact Finset.sum_nonneg (fun z _ => mul_nonneg - ((FiniteLaw.pairedReport (M.first i) (M.second i) (M.common i) (M.weight_nonneg i) - (M.common_first i) (M.common_second i)).nonneg z) (Real.exp_nonneg _)) - · intro i _ - have h := FiniteLaw.pairedReport_hidden_mgf (M.first i) (M.second i) (M.common i) - (M.weight_nonneg i) (M.common_first i) (M.common_second i) (by simpa [hw i] using hp) ht - simpa only [hw i] using h - _ = _ := by simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin,Real.exp_nat_mul] - -/-- A quantitative unconditional bound for failure of a source hidden-count - condition. The exponent ω⁴m is sufficient for the uniform scale margins. -/ -theorem hiddenCount_small {ω : ℝ} (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : - M.reports.expect (fun z => if (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 then 1 else 0)≤ - Real.exp (-(m:ℝ)*ω^4/16) := by - have ht : 0≤ω^2/4 := by positivity - have ht' : |-(ω^2/4)|≤1 := by rw [abs_neg,abs_of_nonneg ht]; linarith [hp.2] - have H := finite_exp_markov Finset.univ M.reports.mass - (fun z => -((hiddenCount z:ℕ)-(m:ℝ)*ω^2)) (fun z _ => M.reports.nonneg z) - ((m:ℝ)*ω^2/2) (ω^2/4) ht - have hm := M.hiddenCount_mgf hw hp ht' - have hsub : M.reports.expect (fun z => if (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 then 1 else 0)≤ - ∑z∈Finset.univ.filter (fun z => (m:ℝ)*ω^2/2≤-((hiddenCount z:ℕ)-(m:ℝ)*ω^2)),M.reports.mass z := by - rw [Finset.sum_filter] - apply Finset.sum_le_sum - intro z _ - dsimp only - by_cases hz : (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 - · rw [ite_eq_left hz,ite_eq_left (by linarith : (m:ℝ)*ω^2/2≤-((hiddenCount z:ℕ)-(m:ℝ)*ω^2)),mul_one] - · rw [ite_eq_right hz,mul_zero]; split_ifs <;> positivity [M.reports.nonneg z] - calc - _ ≤ _ := hsub.trans H - _ ≤ Real.exp (-(ω^2/4)*((m:ℝ)*ω^2/2))*Real.exp ((m:ℝ)*(-(ω^2/4))^2) := by - apply mul_le_mul_of_nonneg_left _ (Real.exp_nonneg _) - simpa only [FiniteLaw.expect,neg_mul,mul_neg,neg_neg] using hm - _ = _ := by rw [←Real.exp_add]; congr 1; ring - -/-- Exact Bayes averaging under all metadata, including impossible reports. -/ -theorem posterior_average (F : (Fin m → Bool) → ℝ) : - M.reports.expect (fun z => (orientationsGiven z).expect F)= - (fairOrientations m).expect F := by - unfold FiniteLaw.expect - simp only [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - have hb (z : Reports Side m) : M.reports.mass z*(orientationsGiven z).mass b= - (fairOrientations m).mass b*(M.reportsGiven b).mass z := by - change (∏i,FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) (M.hiddenWeight i) (z i))* - (∏i,(FiniteLaw.flagPosterior (z i).1).mass (b i))=_ - rw [←FiniteLaw.pairedFlags_product_bayes] - rw [Finset.prod_mul_distrib] - rfl - simp_rw [←mul_assoc,hb,mul_assoc] - rw [←Finset.mul_sum,←Finset.sum_mul,(M.reportsGiven b).total,one_mul] - -/-- Markov's inequality for the actual conditional failure probability. - This does not condition any orientation averages on fitting paths. -/ -theorem posterior_bad_mass {a : ℝ} (_ha : 0 if a≤(orientationsGiven z).expect (fun b => if bad b then 1 else 0) - then 1 else 0) ≤ (fairOrientations m).expect (fun b => if bad b then 1 else 0) := by - rw [←M.posterior_average,←FiniteLaw.expect_const_mul] - apply FiniteLaw.expect_mono - intro z - split_ifs with hz - · simpa using hz - · simp only [mul_zero] - exact Finset.sum_nonneg (fun b _ => mul_nonneg ((orientationsGiven z).nonneg b) - (by dsimp only; split_ifs <;> norm_num)) - -end PairedMechanisms -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {ι α : Type*} [Fintype ι] [Fintype α] - -theorem indexedProduct_expect_product (P : ι → FiniteLaw α) (F : ι → α → ℝ) : - (indexedProduct P).expect (fun x => ∏i,F i (x i))=∏i,(P i).expect (F i) := by - simp only [expect,indexedProduct,←Finset.prod_mul_distrib] - exact (Fintype.prod_sum (fun i a => (P i).mass a*F i a)).symm - -end FiniteLaw - -/-- The unconditional orientation distribution on any actual finite trial ID set. -/ -def fairField (ι : Type*) [Fintype ι] : FiniteLaw (ι → Bool) := - FiniteLaw.indexedProduct (fun _ => FiniteLaw.flagPosterior none) - -def fairLinearSum {ι : Type*} [Fintype ι] (c : ι → ℝ) (bits : ι → Bool) : ℝ := - ∑i,c i*((bitIndex (bits i):ℝ)-1/2) - -/-- Exact MGF calculation for each paired orientation bit. -/ -theorem fairBit_mgf (t : ℝ) : - (FiniteLaw.flagPosterior none).expect (fun b => Real.exp (t*((bitIndex b:ℝ)-1/2)))= - Real.cosh (t/2) := by - simp only [FiniteLaw.expect,Fintype.sum_bool,FiniteLaw.flagPosterior,bitIndex] - norm_num only [Bool.false_eq_true,↓reduceIte,Nat.cast_zero,Nat.cast_one,decide_true,decide_false] - rw [Real.cosh_eq] - ring_nf - -/-- Hoeffding's exponential estimate for the actual independently fair bits, - allowing deterministic zero coefficients for completed/nonactive global pairs. -/ -theorem fairLinearSum_mgf {ι : Type*} [Fintype ι] (c : ι → ℝ) (t : ℝ) : - (fairField ι).expect (fun bits => Real.exp (t*fairLinearSum c bits))≤ - Real.exp ((∑i,(c i)^2)*t^2/8) := by - have he (bits : ι → Bool) : Real.exp (t*fairLinearSum c bits)= - ∏i,Real.exp ((t*c i)*((bitIndex (bits i):ℝ)-1/2)) := by - rw [←Real.exp_sum] - congr 1 - simp only [fairLinearSum,Finset.mul_sum,mul_assoc] - simp_rw [he] - rw [fairField,FiniteLaw.indexedProduct_expect_product _ - (fun i b => Real.exp ((t*c i)*((bitIndex b:ℝ)-1/2)))] - simp_rw [fairBit_mgf] - calc - _ ≤ ∏i,Real.exp ((t*c i)^2/8) := by - apply Finset.prod_le_prod₀ - · intro i _; exact (Real.cosh_pos _).le - · intro i _ - convert Real.cosh_le_exp_half_sq (t*c i/2) using 1 - congr 1 - ring - _ = _ := by - rw [←Real.exp_sum] - congr 1 - simp only [Finset.sum_mul,Finset.sum_div] - apply Finset.sum_congr rfl - intro i _ - ring - -theorem fairLinearSum_mgf_card {ι : Type*} [Fintype ι] (c : ι → ℝ) - (hc : ∀i,|c i|≤1) (t : ℝ) : - (fairField ι).expect (fun bits => Real.exp (t*fairLinearSum c bits))≤ - Real.exp ((Fintype.card ι:ℝ)*t^2/8) := by - apply (fairLinearSum_mgf c t).trans - apply Real.exp_le_exp.mpr - have hs : (∑i,(c i)^2)≤(Fintype.card ι:ℝ) := by - calc - _ ≤ ∑_i : ι,(1:ℝ) := by - apply Finset.sum_le_sum - intro i _ - have h:=abs_le.mp (hc i) - nlinarith [sq_nonneg (c i)] - _ = _ := by simp - gcongr - -/-- Two-sided finite Hoeffding bound with the source's sharp quadratic scale. -/ -theorem fairLinearSum_tail_variance {ι : Type*} [Fintype ι] (c : ι → ℝ) - {V : ℝ} (hV : 0 if a≤|fairLinearSum c bits| then 1 else 0)≤ - 2*Real.exp (-2*a^2/V) := by - have oneSide (d : ι → ℝ) (hd : (∑i,(d i)^2)≤V) : - (fairField ι).expect (fun bits => if a≤fairLinearSum d bits then 1 else 0)≤ - Real.exp (-2*a^2/V) := by - have H := finite_exp_markov Finset.univ (fairField ι).mass (fairLinearSum d) - (fun bits _ => (fairField ι).nonneg bits) a (4*a/V) (by positivity) - have hm : (fairField ι).expect (fun bits => Real.exp ((4*a/V)*fairLinearSum d bits))≤ - Real.exp (V*(4*a/V)^2/8) := by - apply (fairLinearSum_mgf d (4*a/V)).trans - apply Real.exp_le_exp.mpr - gcongr - have he : (fairField ι).expect (fun bits => if a≤fairLinearSum d bits then 1 else 0)= - ∑bits∈Finset.univ.filter (fun bits => a≤fairLinearSum d bits),(fairField ι).mass bits := by - simp only [FiniteLaw.expect,Finset.sum_filter,mul_ite,mul_one,mul_zero] - rw [he] - calc - _ ≤ _ := H - _ ≤ Real.exp (-(4*a/V)*a)* - Real.exp (V*(4*a/V)^2/8) := by - exact mul_le_mul_of_nonneg_left hm (Real.exp_nonneg _) - _ = _ := by - rw [←Real.exp_add] - congr 1 - field_simp [ne_of_gt hV] - ring - have hneg (bits : ι → Bool) : fairLinearSum (fun i => -c i) bits= -fairLinearSum c bits := by - simp only [fairLinearSum,neg_mul,Finset.sum_neg_distrib] - have hnegc : (∑i,(-c i)^2)≤V := by simpa only [neg_sq] using hc - have Hpos := oneSide c hc - have Hneg := oneSide (fun i => -c i) hnegc - have hb : (fairField ι).expect (fun bits => if a≤|fairLinearSum c bits| then 1 else 0)≤ - (fairField ι).expect (fun bits => if a≤fairLinearSum c bits then 1 else 0)+ - (fairField ι).expect (fun bits => if a≤fairLinearSum (fun i => -c i) bits then 1 else 0) := by - have hpoint (bits : ι → Bool) : - (if a≤|fairLinearSum c bits| then (1:ℝ) else 0)≤ - (if a≤fairLinearSum c bits then 1 else 0)+(if a≤fairLinearSum (fun i => -c i) bits then 1 else 0) := by - rw [hneg] - by_cases h : 0≤fairLinearSum c bits - · rw [abs_of_nonneg h]; split_ifs <;> norm_num - · rw [abs_of_neg (lt_of_not_ge h)]; split_ifs <;> norm_num - unfold FiniteLaw.expect - rw [←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro bits _ - simpa only [mul_add] using mul_le_mul_of_nonneg_left (hpoint bits) ((fairField ι).nonneg bits) - linarith - -/-- Cardinal specialization, without imposing any extra computation limits. -/ -theorem fairLinearSum_tail {ι : Type*} [Fintype ι] (c : ι → ℝ) - (hc : ∀i,|c i|≤1) (hn : 0 if a≤|fairLinearSum c bits| then 1 else 0)≤ - 2*Real.exp (-2*a^2/(Fintype.card ι:ℝ)) := by - apply fairLinearSum_tail_variance c (by exact_mod_cast hn) _ ha - calc - _ ≤ ∑_i : ι,(1:ℝ) := by - apply Finset.sum_le_sum - intro i _ - have h:=abs_le.mp (hc i) - nlinarith [sq_nonneg (c i)] - _ = _ := by simp - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {ι : Type*} [Fintype ι] [DecidableEq ι] {A : ι → Type*} [∀i,Fintype (A i)] - -/-- Independent observations at literal slot IDs, allowing different outcome - types (side traces and old leaf oracles carry genuinely different data). -/ -def dependentProduct (P : ∀i,FiniteLaw (A i)) : FiniteLaw (∀i,A i) where - mass x := ∏i,(P i).mass (x i) - nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg _) - total := by rw [←Fintype.prod_sum]; simp only [(P _).total,Finset.prod_const_one] - -theorem dependentProduct_expect_product (P : ∀i,FiniteLaw (A i)) (F : ∀i,A i → ℝ) : - (dependentProduct P).expect (fun x => ∏i,F i (x i))=∏i,(P i).expect (F i) := by - simp only [expect,dependentProduct,←Finset.prod_mul_distrib] - exact (Fintype.prod_sum (fun i a => (P i).mass a*F i a)).symm - -theorem expect_dependentProduct_succ {n : ℕ} {A : Fin (n+1) → Type*} - [∀i,Fintype (A i)] (P : ∀i,FiniteLaw (A i)) (F : (∀i,A i) → ℝ) : - (dependentProduct P).expect F=(P 0).expect (fun a => - (dependentProduct (fun i : Fin n => P i.succ)).expect (fun x => F (Fin.cons a x))) := by - change (∑x : ∀i,A i,(∏i,(P i).mass (x i))*F x)=_ - rw [←(Fin.consEquiv A).sum_comp] - simp only [Fintype.sum_prod_type,Fin.consEquiv,Equiv.coe_fn_mk, - Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ,expect,dependentProduct,Finset.mul_sum,mul_assoc] - -/-- A genuine dependent Pi-law is invariant under a fixed bijective relabeling - of slots. No observation is duplicated and no random order is transmitted. -/ -theorem dependentProduct_expect_equiv {κ : Type*} [Fintype κ] [DecidableEq κ] (P : ∀i,FiniteLaw (A i)) - (e : κ ≃ ι) (F : (∀i,A i) → ℝ) : - (dependentProduct P).expect F=(dependentProduct (fun j => P (e j))).expect - (fun x => F (fun i => cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i)))) := by - let E : (∀j,A (e j)) ≃ (∀i,A i) := Equiv.piCongrLeft A e - have he (x : ∀j,A (e j)) (i : ι) : E x i= - cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i)) := by - exact Equiv.piCongrLeft_apply_eq_cast x i - unfold expect dependentProduct - rw [←E.sum_comp] - apply Finset.sum_congr rfl - intro x _ - change (∏i,(P i).mass (E x i))*F (E x)= - (∏j,(P (e j)).mass (x j))*F (fun i => cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i))) - apply congrArg₂ (· * ·) - · rw [←e.prod_comp] - apply Finset.prod_congr rfl - intro j _ - congr 1 - exact Equiv.piCongrLeft_apply_apply A e x j - · congr 1 - funext i - exact he x i - -end FiniteLaw - -/-- Independent heterogeneous emissions in a literal finite chronological - order accumulate precisely the sum of their trace approximation costs. -/ -theorem dependentCoordinate_approximates {n : ℕ} {A : Fin n → Type*} - [∀i,Fintype (A i)] {q : ℝ} (hq : q∈Set.Icc 0 1) - (P : ∀i,FiniteLaw (A i)) (f : ∀i,A i → List Bool) - (w : Fin n → List Bool) (E : Fin n → ℝ) - (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : - ApproximatesTrace q (FiniteLaw.dependentProduct P) - (fun x => coordinateWord (fun i => f i (x i))) (coordinateWord w) (∑i,E i) := by - induction n with - | zero => - intro F hF - change |(FiniteLaw.dependentProduct P).expect (fun _ => F [])-F []|≤∑i : Fin 0,E i - simp only [FiniteLaw.expect_const,sub_self,abs_zero,Finset.univ_eq_empty,Finset.sum_empty,le_refl] - | succ n ih => - intro F hF - have ht := ih (fun i => P i.succ) (fun i => f i.succ) - (fun i => w i.succ) (fun i => E i.succ) (fun i => h i.succ) - have hh := ApproximatesTrace.append hq (h 0) ht F hF - rw [FiniteLaw.expect_prod] at hh - rw [FiniteLaw.expect_dependentProduct_succ,coordinateWord_succ,Fin.sum_univ_succ] - have he (a : A 0) (x : ∀i : Fin n,A i.succ) : - coordinateWord (fun i => f i ((Fin.cons a x : ∀i,A i) i))= - f 0 a++coordinateWord (fun i => f i.succ (x i)) := by - rw [coordinateWord_succ] - simp only [Fin.cons_zero,Fin.cons_succ] - simp_rw [he] - exact hh - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Actual IDs of every local or global paired trial on the whole window tree. -/ -def WindowTrial (T n g : ℕ → ℕ) : ℕ → Type - | 0 => PEmpty - | b+1 => Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)) - -noncomputable instance windowTrialFintype (T n g : ℕ → ℕ) : - (b : ℕ) → Fintype (WindowTrial T n g b) - | 0 => inferInstanceAs (Fintype PEmpty) - | b+1 => by - letI := windowTrialFintype T n g b - exact inferInstanceAs (Fintype (Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)))) - -/-- A fixed bijection, independent of every bit, reveal and hypothesis. -/ -def windowAssignmentEquiv (T n g : ℕ → ℕ) (A : Type) : - (b : ℕ) → WindowAssignments T n g A b ≃ (WindowTrial T n g b → A) - | 0 => - { toFun := fun _ i => PEmpty.elim i - invFun := fun _ => PUnit.unit - left_inv := fun x => by cases x; rfl - right_inv := fun x => by funext i; exact PEmpty.elim i } - | b+1 => - { toFun := fun x i => match i with - | .inl k => x.1 k - | .inr (.inl k) => x.2.1 k - | .inr (.inr (u,k)) => windowAssignmentEquiv T n g A b (x.2.2 u) k - invFun := fun x => (fun k => x (.inl k),fun k => x (.inr (.inl k)), - fun u => (windowAssignmentEquiv T n g A b).symm (fun k => x (.inr (.inr (u,k))))) - left_inv := fun x => by - rcases x with ⟨loc,glob,kids⟩ - change (loc,glob,fun u => (windowAssignmentEquiv T n g A b).symm - (windowAssignmentEquiv T n g A b (kids u)))=(loc,glob,kids) - simp only [Equiv.symm_apply_apply] - - right_inv := fun x => by - funext i - rcases i with k | k - · rfl - · rcases k with k | ⟨u,k⟩ - · rfl - · exact congrFun ((windowAssignmentEquiv T n g A b).apply_symm_apply - (fun k => x (.inr (.inr (u,k))))) k } - -theorem windowPosterior_mass_flat (T n g : ℕ → ℕ) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) b) (bits : WindowAssignments T n g Bool b) : - (windowPosteriorLaw T n g b d).mass bits= - ∏i : WindowTrial T n g b,(FiniteLaw.flagPosterior - (windowAssignmentEquiv T n g (Option Bool) b d i)).mass - (windowAssignmentEquiv T n g Bool b bits i) := by - induction b with - | zero => - change (1:ℝ)=∏i : PEmpty,_ - simp - | succ b ih => - change (∏i,(FiniteLaw.flagPosterior (d.1 i)).mass (bits.1 i))* - ((∏i,(FiniteLaw.flagPosterior (d.2.1 i)).mass (bits.2.1 i))* - ∏u,(windowPosteriorLaw T n g b (d.2.2 u)).mass (bits.2.2 u))=_ - simp_rw [ih] - change _=∏i : Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)), - (FiniteLaw.flagPosterior (match i with - | .inl k => d.1 k - | .inr (.inl k) => d.2.1 k - | .inr (.inr (u,k)) => windowAssignmentEquiv T n g (Option Bool) b (d.2.2 u) k)).mass - (match i with - | .inl k => bits.1 k - | .inr (.inl k) => bits.2.1 k - | .inr (.inr (u,k)) => windowAssignmentEquiv T n g Bool b (bits.2.2 u) k) - simp only [Fintype.prod_sum_type,Fintype.prod_prod_type] - -/-- Exact flat posterior distribution, including all paths and zero-mass - metadata. This is the same independent bit law, not a new assumption. -/ -theorem windowPosterior_expect_flat (T n g : ℕ → ℕ) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) b) - (F : WindowAssignments T n g Bool b → ℝ) : - (windowPosteriorLaw T n g b d).expect F= - (FiniteLaw.indexedProduct (fun i : WindowTrial T n g b => FiniteLaw.flagPosterior - (windowAssignmentEquiv T n g (Option Bool) b d i))).expect - (fun bits => F ((windowAssignmentEquiv T n g Bool b).symm bits)) := by - unfold FiniteLaw.expect FiniteLaw.indexedProduct - rw [←(windowAssignmentEquiv T n g Bool b).sum_comp] - apply Finset.sum_congr rfl - intro bits _ - dsimp only - rw [Equiv.symm_apply_apply,windowPosterior_mass_flat] - -def noReveals (T n g : ℕ → ℕ) (b : ℕ) : WindowAssignments T n g (Option Bool) b := - (windowAssignmentEquiv T n g (Option Bool) b).symm (fun _ => none) - -theorem windowPosterior_fair_flat (T n g : ℕ → ℕ) (b : ℕ) - (F : WindowAssignments T n g Bool b → ℝ) : - (windowPosteriorLaw T n g b (noReveals T n g b)).expect F= - (FiniteLaw.indexedProduct (fun _ : WindowTrial T n g b => FiniteLaw.flagPosterior none)).expect - (fun bits => F ((windowAssignmentEquiv T n g Bool b).symm bits)) := by - rw [windowPosterior_expect_flat] - simp only [noReveals,Equiv.apply_symm_apply] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The literal global schedule is indexed by a fixed pair/block bijection. -/ -def globalTrialEquiv (N t : ℕ) : (Fin (N/4) × Fin t) ≃ Fin ((N/4)*t) := - Equiv.ofBijective _ (globalTrialIndex_bijective N t) - -def sourceGlobalCoefficient (N t : ℕ) (u : Fin N) (k : Fin ((N/4)*t)) : ℝ := - let v := ((globalTrialEquiv N t).symm k).1 - if v.val≤u.val ∧ u.val+v.val 0 - | .inr (.inl k) => sourceGlobalCoefficient (T (b+1)) (n b) u k - | .inr (.inr (v,.inl _)) => if v=u then 1 else 0 - | .inr (.inr (_,.inr _)) => 0 - -theorem even_half_cast (t : ℕ) (ht : Even t) : ((t/2:ℕ):ℝ)=(t:ℝ)/2 := by - have h : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) - have hr : (2:ℝ)*(t/2:ℕ)=t := by exact_mod_cast h - linarith - -theorem scheduledGlobalShift_linear (N t : ℕ) (ht : Even t) - (bits : Fin ((N/4)*t) → Bool) (u : Fin N) : - (scheduledGlobalShift N t bits u:ℝ)= - ∑k,sourceGlobalCoefficient N t u k*((bitIndex (bits k):ℝ)-1/2) := by - rw [←(globalTrialEquiv N t).sum_comp] - simp only [Fintype.sum_prod_type,sourceGlobalCoefficient,Equiv.symm_apply_apply] - unfold scheduledGlobalShift - simp only [Int.cast_sum,Int.cast_ite,Int.cast_sub,Int.cast_natCast,Int.cast_zero] - apply Finset.sum_congr rfl - intro v _ - split_ifs with hv - · simp only [one_mul,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ, - Fintype.card_fin,nsmul_eq_mul] - rw [even_half_cast t ht] - simp only [globalTrialEquiv,Equiv.ofBijective_apply] - ring - · simp only [zero_mul,Finset.sum_const_zero] - -theorem sourceDisplacement_linear (T n : ℕ → ℕ) (b : ℕ) (ht : Even (n b)) - (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) (u : Fin (T (b+1))) : - (sourceDisplacement (T (b+1)) (n b) (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)= - fairLinearSum (sourceGroupCoefficient T n b u) - (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool (b+2) bits) := by - rcases bits with ⟨root,global,children⟩ - change Fin ((T (b+1)/4)*n b) → Bool at global - change Fin (T (b+1)) → ((Fin (n b) → Bool) × - (Fin (sourceScheduledTrials T n b) → Bool) × - (Fin (T b) → WindowAssignments T n (sourceScheduledTrials T n) Bool b)) at children - unfold fairLinearSum - change _=∑i : Fin (n (b+1)) ⊕ (Fin ((T (b+1)/4)*n b) ⊕ - (Fin (T (b+1)) × (Fin (n b) ⊕ (Fin (sourceScheduledTrials T n b) ⊕ - (Fin (T b) × WindowTrial T n (sourceScheduledTrials T n) b))))),_ - simp only [Fintype.sum_sum_type,Fintype.sum_prod_type,sourceGroupCoefficient, - zero_mul,Finset.sum_const_zero,zero_add,add_zero] - change _=(∑k,sourceGlobalCoefficient (T (b+1)) (n b) u k* - ((bitIndex (global k):ℝ)-1/2))+ - (∑v : Fin (T (b+1)),∑a : Fin (n b), - (if v=u then (1:ℝ) else 0)*((bitIndex ((children v).1 a):ℝ)-1/2)) - have hl : (∑v : Fin (T (b+1)),∑a : Fin (n b), - (if v=u then (1:ℝ) else 0)*((bitIndex ((children v).1 a):ℝ)-1/2))= - (∑a : Fin (n b),(bitIndex ((children u).1 a):ℝ))-(n b:ℝ)/2 := by - simp only [ite_mul,one_mul,zero_mul] - rw [show (∑v : Fin (T (b+1)),∑a : Fin (n b), - if v=u then ((bitIndex ((children v).1 a):ℝ)-1/2) else 0)= - ∑v : Fin (T (b+1)),if v=u then - (∑a : Fin (n b),((bitIndex ((children v).1 a):ℝ)-1/2)) else 0 from by - apply Finset.sum_congr rfl - intro v _ - split_ifs <;> simp] - rw [Finset.sum_ite_eq',ite_eq_left (Finset.mem_univ u)] - simp only [Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - ring - rw [hl,←scheduledGlobalShift_linear (T (b+1)) (n b) ht global u] - simp only [sourceDisplacement,Int.cast_add,Int.cast_sub,Int.cast_sum,Int.cast_natCast, - even_half_cast _ ht] - ring - -theorem sourceGroupCoefficient_variance (T n : ℕ → ℕ) (b : ℕ) (u : Fin (T (b+1))) : - (∑i,(sourceGroupCoefficient T n b u i)^2)≤((T (b+1):ℝ)+1)*(n b:ℝ) := by - change (∑i : Fin (n (b+1)) ⊕ (Fin ((T (b+1)/4)*n b) ⊕ - (Fin (T (b+1)) × (Fin (n b) ⊕ (Fin (sourceScheduledTrials T n b) ⊕ - (Fin (T b) × WindowTrial T n (sourceScheduledTrials T n) b))))),_)≤_ - simp only [Fintype.sum_sum_type,Fintype.sum_prod_type,sourceGroupCoefficient, - zero_pow (by omega : 2≠0),Finset.sum_const_zero,zero_add,add_zero] - have hg : (∑k : Fin ((T (b+1)/4)*n b),(sourceGlobalCoefficient (T (b+1)) (n b) u k)^2)≤ - ((T (b+1)/4)*n b:ℕ) := by - calc - _ ≤ ∑_k : Fin ((T (b+1)/4)*n b),(1:ℝ) := by - apply Finset.sum_le_sum - intro k _ - dsimp only [sourceGlobalCoefficient] - split_ifs <;> norm_num - _ = _ := by simp - have hl : (∑v : Fin (T (b+1)),∑_a : Fin (n b),(if v=u then (1:ℝ) else 0)^2)=(n b:ℝ) := by - simp only [ite_pow,one_pow,zero_pow (by omega : 2≠0)] - simp - rw [hl] - have hdiv : ((T (b+1)/4:ℕ):ℝ)≤T (b+1) := by exact_mod_cast Nat.div_le_self (T (b+1)) 4 - push_cast at hg - have hm := mul_le_mul_of_nonneg_right hdiv (Nat.cast_nonneg (n b): (0:ℝ)≤n b) - nlinarith only [hg,hm] - -/-- Actual per-window unconditional fit tail under the full tree's fair law. - No independence between different window displacements is asserted. -/ -theorem sourceDisplacement_tail (T n : ℕ → ℕ) (b : ℕ) (ht : Even (n b)) - (hn : 0 if a≤|(sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| then 1 else 0)≤ - 2*Real.exp (-2*a^2/(((T (b+1):ℝ)+1)*(n b:ℝ))) := by - rw [windowPosterior_fair_flat] - simp_rw [sourceDisplacement_linear T n b ht,Equiv.apply_symm_apply] - exact fairLinearSum_tail_variance (sourceGroupCoefficient T n b u) - (by positivity) (sourceGroupCoefficient_variance T n b u) ha - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α ι : Type*} [Fintype α] [Fintype ι] - -theorem expect_fintype_sum (P : FiniteLaw α) (f : ι → α → ℝ) : - P.expect (fun a => ∑i,f i a)=∑i,P.expect (f i) := by - simp only [expect,Finset.mul_sum] - exact Finset.sum_comm - -theorem expect_add (P : FiniteLaw α) (f g : α → ℝ) : - P.expect (fun a => f a+g a)=P.expect f+P.expect g := by - simp only [expect,mul_add,Finset.sum_add_distrib] - -theorem coordinateProduct_expect_eval {n : ℕ} (P : Fin n → FiniteLaw α) - (u : Fin n) (f : α → ℝ) : - (coordinateProduct P).expect (fun x => f (x u))=(P u).expect f := by - let F : Fin n → α → ℝ := fun j a => if j=u then f a else 1 - have hp (x : Fin n → α) : (∏j,F j (x j))=f (x u) := by simp [F] - rw [show (fun x : Fin n → α => f (x u))=(fun x => ∏j,F j (x j)) by - funext x; exact (hp x).symm,coordinateProduct_expect_product] - have hj (j : Fin n) : (P j).expect (F j)=if j=u then (P j).expect f else 1 := by - by_cases h : j=u <;> simp [F,h,expect_const] - simp_rw [hj] - simp - -end FiniteLaw - -theorem noReveals_succ (T n g : ℕ → ℕ) (b : ℕ) : - noReveals T n g (b+1)=(fun _ => none,fun _ => none,fun _ => noReveals T n g b) := rfl - -theorem windowPosterior_child (T n g : ℕ → ℕ) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) (b+1)) (u : Fin (T b)) - (F : WindowAssignments T n g Bool b → ℝ) : - (windowPosteriorLaw T n g (b+1) d).expect (fun bits => F (bits.2.2 u))= - (windowPosteriorLaw T n g b (d.2.2 u)).expect F := by - rcases d with ⟨loc,glob,kids⟩ - change ((posteriorArray loc).prod ((posteriorArray glob).prod - (FiniteLaw.coordinateProduct (fun i => windowPosteriorLaw T n g b (kids i))))).expect - (fun bits => F (bits.2.2 u))=_ - rw [FiniteLaw.expect_prod] - simp_rw [FiniteLaw.expect_prod,FiniteLaw.coordinateProduct_expect_eval,FiniteLaw.expect_const] - -theorem failure_forall_le_sum {ι : Type*} [Fintype ι] (p : ι → Prop) [DecidablePred p] [Decidable (∀i,p i)] : - (if ∀i,p i then (0:ℝ) else 1)≤∑i,if p i then 0 else 1 := by - by_cases hp : ∀i,p i - · simp only [ite_eq_left hp] - exact Finset.sum_nonneg (fun i _ => by split_ifs <;> norm_num) - · simp only [ite_eq_right hp] - push Not at hp - obtain ⟨i,hi⟩ := hp - calc - (1:ℝ) = if p i then 0 else 1 := by simp [hi] - _ ≤ ∑j,if p j then 0 else 1 := by - apply Finset.single_le_sum (f:=fun j => if p j then (0:ℝ) else 1) - · intro j _; split_ifs <;> norm_num - · exact Finset.mem_univ i - -/-- Explicit finite tree union bound. The source's scale estimates will make - this number exponentially small; no independence of sibling shifts is used. -/ -def sourceFitTail (T n : ℕ → ℕ) : ℕ → ℝ - | 0 => 0 - | 1 => 0 - | b+2 => (T (b+1):ℝ)*(2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ)))+ - sourceFitTail T n (b+1)) - -theorem sourceTreeFit_tail (T n : ℕ → ℕ) (b : ℕ) - (hn : ∀j if SourceTreeFit T n b bits then 0 else 1) ≤ sourceFitTail T n b := by - induction b using Nat.twoStepInduction with - | zero => - have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 0) : SourceTreeFit T n 0 bits := trivial - simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] - | one => - have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 1) : SourceTreeFit T n 1 bits := trivial - simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] - | more b ih0 ih => - let P := windowPosteriorLaw T n (sourceScheduledTrials T n) (b+2) - (noReveals T n (sourceScheduledTrials T n) (b+2)) - let badShift : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2) → Fin (T (b+1)) → Prop := - fun bits u => (T b:ℝ)/8≤|(sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| - have hp (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) : - (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ - (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ - (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by - let p := fun u : Fin (T (b+1)) => |8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u|≤(T b:ℤ) - have hh : (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ - (if ∀u,p u then 0 else 1)+(if ∀u,SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by - by_cases H : SourceTreeFit T n (b+2) bits - · rw [ite_eq_left H] - split_ifs <;> norm_num - · rw [ite_eq_right H] - by_cases h1 : ∀u,p u - · have h2 : ¬∀u,SourceTreeFit T n (b+1) (bits.2.2 u) := fun h2 => H ⟨h1,h2⟩ - rw [ite_eq_left h1,ite_eq_right h2] - norm_num - · rw [ite_eq_right h1] - split_ifs <;> norm_num - apply hh.trans - apply add_le_add - · apply (failure_forall_le_sum p).trans - apply Finset.sum_le_sum - intro u _ - by_cases hu : p u - · simp only [ite_eq_left hu] - split_ifs <;> norm_num - · have hr : (T b:ℝ)<8*|(sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| := by - have hi : (T b:ℤ) < |8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u| := lt_of_not_ge hu - have hi' : (T b:ℝ) < |(8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℤ)| := by exact_mod_cast hi - norm_num only [Int.cast_abs,Int.cast_mul,Int.cast_ofNat,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<8)] at hi' - exact hi' - have hb : badShift bits u := by dsimp [badShift]; linarith - simp [hu,hb] - · exact failure_forall_le_sum _ - calc - _ ≤ P.expect (fun bits => (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ - (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := - P.expect_mono hp - _ = (∑u : Fin (T (b+1)),P.expect (fun bits => if badShift bits u then 1 else 0))+ - (∑u : Fin (T (b+1)),P.expect (fun bits => if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := by - rw [FiniteLaw.expect_add,FiniteLaw.expect_fintype_sum,FiniteLaw.expect_fintype_sum] - _ ≤ (∑_u : Fin (T (b+1)),2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ))))+ - ∑_u : Fin (T (b+1)),sourceFitTail T n (b+1) := by - apply add_le_add - · apply Finset.sum_le_sum - intro u _ - exact sourceDisplacement_tail T n b (he b (by omega)) (hn b (by omega)) u (by positivity) - · apply Finset.sum_le_sum - intro u _ - dsimp only [P] - rw [windowPosterior_child T n (sourceScheduledTrials T n) (b+1) - (noReveals T n (sourceScheduledTrials T n) (b+2)) u - (fun x => if SourceTreeFit T n (b+1) x then 0 else 1)] - rw [noReveals_succ] - exact ih (fun j hj => hn j (by omega)) (fun j hj => he j (by omega)) - _ = sourceFitTail T n (b+2) := by simp [sourceFitTail,mul_add] - -end TraceReconstruction - -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Layout + +namespace OAI + +/-! +# Metadata + +Hidden metadata, fair jitter, heterogeneous emissions, independent window trials, concentration, and fit. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +theorem pairedReportMass_none (P Q H : FiniteLaw α) (ω : ℝ) (z : α × α) : + pairedReportMass P Q H ω (none,z)=pairedHiddenMass H ω z := by + simp only [pairedReportMass,Fintype.sum_bool,pairedFlagMass] + ring + +theorem pairedReport_hidden_expect (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0≤ω) + (hP : ∀a,ω*H.mass a≤P.mass a) (hQ : ∀a,ω*H.mass a≤Q.mass a) (F : ℕ → ℝ) : + (pairedReport P Q H hω hP hQ).expect (fun z => F (hiddenTrial z.1))= + ω^2*F 1+(1-ω^2)*F 0 := by + let R := pairedReport P Q H hω hP hQ + have hp : R.expect (fun z => if z.1=none then (1:ℝ) else 0)=ω^2 := by + simp only [expect,R,pairedReport,Fintype.sum_prod_type,Fintype.sum_option] + simp only [reduceCtorEq,ite_false,mul_zero,Finset.sum_const_zero,add_zero] + simpa only [pairedReportMass_none,Fintype.sum_prod_type,ite_true,mul_one] using sum_pairedHiddenMass H ω + have he (z : Option Bool × (α × α)) : F (hiddenTrial z.1)= + F 0+(F 1-F 0)*(if z.1=none then 1 else 0) := by + rcases z with ⟨d,z⟩; cases d <;> simp [hiddenTrial] + simp_rw [he] + have hadd : R.expect (fun z => F 0+(F 1-F 0)*(if z.1=none then 1 else 0))= + R.expect (fun _ => F 0)+R.expect (fun z => (F 1-F 0)*(if z.1=none then 1 else 0)) := by + simp only [expect,mul_add,Finset.sum_add_distrib] + rw [hadd,expect_const,expect_const_mul,hp] + ring + +/-- Centered hidden-flag MGF, derived from the literal paired experiment. -/ +theorem pairedReport_hidden_mgf (P Q H : FiniteLaw α) {ω t : ℝ} (hω : 0≤ω) + (hP : ∀a,ω*H.mass a≤P.mass a) (hQ : ∀a,ω*H.mass a≤Q.mass a) + (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : + (pairedReport P Q H hω hP hQ).expect (fun z => + Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2)))≤Real.exp (t^2) := by + rw [pairedReport_hidden_expect P Q H hω hP hQ (fun k => Real.exp (t*((k:ℝ)-ω^2)))] + have H := binomialMass_centered_mgf 1 hp ht + norm_num [Finset.sum_range_succ,binomialMass] at H ⊢ + convert H using 1 ; ring + +end FiniteLaw + +namespace PairedMechanisms +variable {Side : Type*} [Fintype Side] {m : ℕ} (M : PairedMechanisms Side m) + +def hiddenCount (z : Reports Side m) : ℕ := ∑i,hiddenTrial (z i).1 + +/-- No independence of displacements is presumed: only the flags of the + distinct literal paired mechanisms are independent. -/ +theorem hiddenCount_mgf {ω t : ℝ} (hw : ∀i,M.hiddenWeight i=ω) + (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : + M.reports.expect (fun z => Real.exp (t*((hiddenCount z:ℕ)-(m:ℝ)*ω^2)))≤ + Real.exp ((m:ℝ)*t^2) := by + have he (z : Reports Side m) : + Real.exp (t*((hiddenCount z:ℕ)-(m:ℝ)*ω^2))= + ∏i : Fin m,Real.exp (t*((hiddenTrial (z i).1:ℕ)-ω^2)) := by + rw [←Real.exp_sum] + congr 1 + simp only [mul_sub,Finset.mul_sum,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin, + nsmul_eq_mul,hiddenCount,Nat.cast_sum] + ring + simp_rw [he] + rw [reports,FiniteLaw.coordinateProduct_expect_product _ + (fun (_ : Fin m) (z : Option Bool × (Side × Side)) => Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2))) ] + calc + _ ≤ ∏i : Fin m,Real.exp (t^2) := by + apply Finset.prod_le_prod₀ + · intro i _ + exact Finset.sum_nonneg (fun z _ => mul_nonneg + ((FiniteLaw.pairedReport (M.first i) (M.second i) (M.common i) (M.weight_nonneg i) + (M.common_first i) (M.common_second i)).nonneg z) (Real.exp_nonneg _)) + · intro i _ + have h := FiniteLaw.pairedReport_hidden_mgf (M.first i) (M.second i) (M.common i) + (M.weight_nonneg i) (M.common_first i) (M.common_second i) (by simpa [hw i] using hp) ht + simpa only [hw i] using h + _ = _ := by simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin,Real.exp_nat_mul] + +/-- A quantitative unconditional bound for failure of a source hidden-count + condition. The exponent ω⁴m is sufficient for the uniform scale margins. -/ +theorem hiddenCount_small {ω : ℝ} (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : + M.reports.expect (fun z => if (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 then 1 else 0)≤ + Real.exp (-(m:ℝ)*ω^4/16) := by + have ht : 0≤ω^2/4 := by positivity + have ht' : |-(ω^2/4)|≤1 := by rw [abs_neg,abs_of_nonneg ht]; linarith [hp.2] + have H := finite_exp_markov Finset.univ M.reports.mass + (fun z => -((hiddenCount z:ℕ)-(m:ℝ)*ω^2)) (fun z _ => M.reports.nonneg z) + ((m:ℝ)*ω^2/2) (ω^2/4) ht + have hm := M.hiddenCount_mgf hw hp ht' + have hsub : M.reports.expect (fun z => if (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 then 1 else 0)≤ + ∑z∈Finset.univ.filter (fun z => (m:ℝ)*ω^2/2≤-((hiddenCount z:ℕ)-(m:ℝ)*ω^2)),M.reports.mass z := by + rw [Finset.sum_filter] + apply Finset.sum_le_sum + intro z _ + dsimp only + by_cases hz : (hiddenCount z:ℝ)<(m:ℝ)*ω^2/2 + · rw [ite_eq_left hz,ite_eq_left (by linarith : (m:ℝ)*ω^2/2≤-((hiddenCount z:ℕ)-(m:ℝ)*ω^2)),mul_one] + · rw [ite_eq_right hz,mul_zero]; split_ifs <;> positivity [M.reports.nonneg z] + calc + _ ≤ _ := hsub.trans H + _ ≤ Real.exp (-(ω^2/4)*((m:ℝ)*ω^2/2))*Real.exp ((m:ℝ)*(-(ω^2/4))^2) := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_nonneg _) + simpa only [FiniteLaw.expect,neg_mul,mul_neg,neg_neg] using hm + _ = _ := by rw [←Real.exp_add]; congr 1; ring + +/-- Exact Bayes averaging under all metadata, including impossible reports. -/ +theorem posterior_average (F : (Fin m → Bool) → ℝ) : + M.reports.expect (fun z => (orientationsGiven z).expect F)= + (fairOrientations m).expect F := by + unfold FiniteLaw.expect + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + have hb (z : Reports Side m) : M.reports.mass z*(orientationsGiven z).mass b= + (fairOrientations m).mass b*(M.reportsGiven b).mass z := by + change (∏i,FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) (M.hiddenWeight i) (z i))* + (∏i,(FiniteLaw.flagPosterior (z i).1).mass (b i))=_ + rw [←FiniteLaw.pairedFlags_product_bayes] + rw [Finset.prod_mul_distrib] + rfl + simp_rw [←mul_assoc,hb,mul_assoc] + rw [←Finset.mul_sum,←Finset.sum_mul,(M.reportsGiven b).total,one_mul] + +/-- Markov's inequality for the actual conditional failure probability. + This does not condition any orientation averages on fitting paths. -/ +theorem posterior_bad_mass {a : ℝ} (_ha : 0 if a≤(orientationsGiven z).expect (fun b => if bad b then 1 else 0) + then 1 else 0) ≤ (fairOrientations m).expect (fun b => if bad b then 1 else 0) := by + rw [←M.posterior_average,←FiniteLaw.expect_const_mul] + apply FiniteLaw.expect_mono + intro z + split_ifs with hz + · simpa using hz + · simp only [mul_zero] + exact Finset.sum_nonneg (fun b _ => mul_nonneg ((orientationsGiven z).nonneg b) + (by dsimp only; split_ifs <;> norm_num)) + +end PairedMechanisms +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {ι α : Type*} [Fintype ι] [Fintype α] + +theorem indexedProduct_expect_product (P : ι → FiniteLaw α) (F : ι → α → ℝ) : + (indexedProduct P).expect (fun x => ∏i,F i (x i))=∏i,(P i).expect (F i) := by + simp only [expect,indexedProduct,←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i a => (P i).mass a*F i a)).symm + +end FiniteLaw + +/-- The unconditional orientation distribution on any actual finite trial ID set. -/ +def fairField (ι : Type*) [Fintype ι] : FiniteLaw (ι → Bool) := + FiniteLaw.indexedProduct (fun _ => FiniteLaw.flagPosterior none) + +def fairLinearSum {ι : Type*} [Fintype ι] (c : ι → ℝ) (bits : ι → Bool) : ℝ := + ∑i,c i*((bitIndex (bits i):ℝ)-1/2) + +/-- Exact MGF calculation for each paired orientation bit. -/ +theorem fairBit_mgf (t : ℝ) : + (FiniteLaw.flagPosterior none).expect (fun b => Real.exp (t*((bitIndex b:ℝ)-1/2)))= + Real.cosh (t/2) := by + simp only [FiniteLaw.expect,Fintype.sum_bool,FiniteLaw.flagPosterior,bitIndex] + norm_num only [Bool.false_eq_true,↓reduceIte,Nat.cast_zero,Nat.cast_one,decide_true,decide_false] + rw [Real.cosh_eq] + ring_nf + +/-- Hoeffding's exponential estimate for the actual independently fair bits, + allowing deterministic zero coefficients for completed/nonactive global pairs. -/ +theorem fairLinearSum_mgf {ι : Type*} [Fintype ι] (c : ι → ℝ) (t : ℝ) : + (fairField ι).expect (fun bits => Real.exp (t*fairLinearSum c bits))≤ + Real.exp ((∑i,(c i)^2)*t^2/8) := by + have he (bits : ι → Bool) : Real.exp (t*fairLinearSum c bits)= + ∏i,Real.exp ((t*c i)*((bitIndex (bits i):ℝ)-1/2)) := by + rw [←Real.exp_sum] + congr 1 + simp only [fairLinearSum,Finset.mul_sum,mul_assoc] + simp_rw [he] + rw [fairField,FiniteLaw.indexedProduct_expect_product _ + (fun i b => Real.exp ((t*c i)*((bitIndex b:ℝ)-1/2)))] + simp_rw [fairBit_mgf] + calc + _ ≤ ∏i,Real.exp ((t*c i)^2/8) := by + apply Finset.prod_le_prod₀ + · intro i _; exact (Real.cosh_pos _).le + · intro i _ + convert Real.cosh_le_exp_half_sq (t*c i/2) using 1 + congr 1 + ring + _ = _ := by + rw [←Real.exp_sum] + congr 1 + simp only [Finset.sum_mul,Finset.sum_div] + apply Finset.sum_congr rfl + intro i _ + ring + +theorem fairLinearSum_mgf_card {ι : Type*} [Fintype ι] (c : ι → ℝ) + (hc : ∀i,|c i|≤1) (t : ℝ) : + (fairField ι).expect (fun bits => Real.exp (t*fairLinearSum c bits))≤ + Real.exp ((Fintype.card ι:ℝ)*t^2/8) := by + apply (fairLinearSum_mgf c t).trans + apply Real.exp_le_exp.mpr + have hs : (∑i,(c i)^2)≤(Fintype.card ι:ℝ) := by + calc + _ ≤ ∑_i : ι,(1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + have h:=abs_le.mp (hc i) + nlinarith [sq_nonneg (c i)] + _ = _ := by simp + gcongr + +/-- Two-sided finite Hoeffding bound with the source's sharp quadratic scale. -/ +theorem fairLinearSum_tail_variance {ι : Type*} [Fintype ι] (c : ι → ℝ) + {V : ℝ} (hV : 0 if a≤|fairLinearSum c bits| then 1 else 0)≤ + 2*Real.exp (-2*a^2/V) := by + have oneSide (d : ι → ℝ) (hd : (∑i,(d i)^2)≤V) : + (fairField ι).expect (fun bits => if a≤fairLinearSum d bits then 1 else 0)≤ + Real.exp (-2*a^2/V) := by + have H := finite_exp_markov Finset.univ (fairField ι).mass (fairLinearSum d) + (fun bits _ => (fairField ι).nonneg bits) a (4*a/V) (by positivity) + have hm : (fairField ι).expect (fun bits => Real.exp ((4*a/V)*fairLinearSum d bits))≤ + Real.exp (V*(4*a/V)^2/8) := by + apply (fairLinearSum_mgf d (4*a/V)).trans + apply Real.exp_le_exp.mpr + gcongr + have he : (fairField ι).expect (fun bits => if a≤fairLinearSum d bits then 1 else 0)= + ∑bits∈Finset.univ.filter (fun bits => a≤fairLinearSum d bits),(fairField ι).mass bits := by + simp only [FiniteLaw.expect,Finset.sum_filter,mul_ite,mul_one,mul_zero] + rw [he] + calc + _ ≤ _ := H + _ ≤ Real.exp (-(4*a/V)*a)* + Real.exp (V*(4*a/V)^2/8) := by + exact mul_le_mul_of_nonneg_left hm (Real.exp_nonneg _) + _ = _ := by + rw [←Real.exp_add] + congr 1 + field_simp [ne_of_gt hV] + ring + have hneg (bits : ι → Bool) : fairLinearSum (fun i => -c i) bits= -fairLinearSum c bits := by + simp only [fairLinearSum,neg_mul,Finset.sum_neg_distrib] + have hnegc : (∑i,(-c i)^2)≤V := by simpa only [neg_sq] using hc + have Hpos := oneSide c hc + have Hneg := oneSide (fun i => -c i) hnegc + have hb : (fairField ι).expect (fun bits => if a≤|fairLinearSum c bits| then 1 else 0)≤ + (fairField ι).expect (fun bits => if a≤fairLinearSum c bits then 1 else 0)+ + (fairField ι).expect (fun bits => if a≤fairLinearSum (fun i => -c i) bits then 1 else 0) := by + have hpoint (bits : ι → Bool) : + (if a≤|fairLinearSum c bits| then (1:ℝ) else 0)≤ + (if a≤fairLinearSum c bits then 1 else 0)+(if a≤fairLinearSum (fun i => -c i) bits then 1 else 0) := by + rw [hneg] + by_cases h : 0≤fairLinearSum c bits + · rw [abs_of_nonneg h]; split_ifs <;> norm_num + · rw [abs_of_neg (lt_of_not_ge h)]; split_ifs <;> norm_num + unfold FiniteLaw.expect + rw [←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro bits _ + simpa only [mul_add] using mul_le_mul_of_nonneg_left (hpoint bits) ((fairField ι).nonneg bits) + linarith + +/-- Cardinal specialization, without imposing any extra computation limits. -/ +theorem fairLinearSum_tail {ι : Type*} [Fintype ι] (c : ι → ℝ) + (hc : ∀i,|c i|≤1) (hn : 0 if a≤|fairLinearSum c bits| then 1 else 0)≤ + 2*Real.exp (-2*a^2/(Fintype.card ι:ℝ)) := by + apply fairLinearSum_tail_variance c (by exact_mod_cast hn) _ ha + calc + _ ≤ ∑_i : ι,(1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + have h:=abs_le.mp (hc i) + nlinarith [sq_nonneg (c i)] + _ = _ := by simp + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {A : ι → Type*} [∀i,Fintype (A i)] + +/-- Independent observations at literal slot IDs, allowing different outcome + types (side traces and old leaf oracles carry genuinely different data). -/ +def dependentProduct (P : ∀i,FiniteLaw (A i)) : FiniteLaw (∀i,A i) where + mass x := ∏i,(P i).mass (x i) + nonneg x := Finset.prod_nonneg (fun i _ => (P i).nonneg _) + total := by rw [←Fintype.prod_sum]; simp only [(P _).total,Finset.prod_const_one] + +theorem dependentProduct_expect_product (P : ∀i,FiniteLaw (A i)) (F : ∀i,A i → ℝ) : + (dependentProduct P).expect (fun x => ∏i,F i (x i))=∏i,(P i).expect (F i) := by + simp only [expect,dependentProduct,←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i a => (P i).mass a*F i a)).symm + +theorem expect_dependentProduct_succ {n : ℕ} {A : Fin (n+1) → Type*} + [∀i,Fintype (A i)] (P : ∀i,FiniteLaw (A i)) (F : (∀i,A i) → ℝ) : + (dependentProduct P).expect F=(P 0).expect (fun a => + (dependentProduct (fun i : Fin n => P i.succ)).expect (fun x => F (Fin.cons a x))) := by + change (∑x : ∀i,A i,(∏i,(P i).mass (x i))*F x)=_ + rw [←(Fin.consEquiv A).sum_comp] + simp only [Fintype.sum_prod_type,Fin.consEquiv,Equiv.coe_fn_mk, + Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ,expect,dependentProduct,Finset.mul_sum,mul_assoc] + +/-- A genuine dependent Pi-law is invariant under a fixed bijective relabeling + of slots. No observation is duplicated and no random order is transmitted. -/ +theorem dependentProduct_expect_equiv {κ : Type*} [Fintype κ] [DecidableEq κ] (P : ∀i,FiniteLaw (A i)) + (e : κ ≃ ι) (F : (∀i,A i) → ℝ) : + (dependentProduct P).expect F=(dependentProduct (fun j => P (e j))).expect + (fun x => F (fun i => cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i)))) := by + let E : (∀j,A (e j)) ≃ (∀i,A i) := Equiv.piCongrLeft A e + have he (x : ∀j,A (e j)) (i : ι) : E x i= + cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i)) := by + exact Equiv.piCongrLeft_apply_eq_cast x i + unfold expect dependentProduct + rw [←E.sum_comp] + apply Finset.sum_congr rfl + intro x _ + change (∏i,(P i).mass (E x i))*F (E x)= + (∏j,(P (e j)).mass (x j))*F (fun i => cast (congrArg A (e.apply_symm_apply i)) (x (e.symm i))) + apply congrArg₂ (· * ·) + · rw [←e.prod_comp] + apply Finset.prod_congr rfl + intro j _ + congr 1 + exact Equiv.piCongrLeft_apply_apply A e x j + · congr 1 + funext i + exact he x i + +end FiniteLaw + +/-- Independent heterogeneous emissions in a literal finite chronological + order accumulate precisely the sum of their trace approximation costs. -/ +theorem dependentCoordinate_approximates {n : ℕ} {A : Fin n → Type*} + [∀i,Fintype (A i)] {q : ℝ} (hq : q∈Set.Icc 0 1) + (P : ∀i,FiniteLaw (A i)) (f : ∀i,A i → List Bool) + (w : Fin n → List Bool) (E : Fin n → ℝ) + (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : + ApproximatesTrace q (FiniteLaw.dependentProduct P) + (fun x => coordinateWord (fun i => f i (x i))) (coordinateWord w) (∑i,E i) := by + induction n with + | zero => + intro F hF + change |(FiniteLaw.dependentProduct P).expect (fun _ => F [])-F []|≤∑i : Fin 0,E i + simp only [FiniteLaw.expect_const,sub_self,abs_zero,Finset.univ_eq_empty,Finset.sum_empty,le_refl] + | succ n ih => + intro F hF + have ht := ih (fun i => P i.succ) (fun i => f i.succ) + (fun i => w i.succ) (fun i => E i.succ) (fun i => h i.succ) + have hh := ApproximatesTrace.append hq (h 0) ht F hF + rw [FiniteLaw.expect_prod] at hh + rw [FiniteLaw.expect_dependentProduct_succ,coordinateWord_succ,Fin.sum_univ_succ] + have he (a : A 0) (x : ∀i : Fin n,A i.succ) : + coordinateWord (fun i => f i ((Fin.cons a x : ∀i,A i) i))= + f 0 a++coordinateWord (fun i => f i.succ (x i)) := by + rw [coordinateWord_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + simp_rw [he] + exact hh + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Actual IDs of every local or global paired trial on the whole window tree. -/ +def WindowTrial (T n g : ℕ → ℕ) : ℕ → Type + | 0 => PEmpty + | b+1 => Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)) + +noncomputable instance windowTrialFintype (T n g : ℕ → ℕ) : + (b : ℕ) → Fintype (WindowTrial T n g b) + | 0 => inferInstanceAs (Fintype PEmpty) + | b+1 => by + letI := windowTrialFintype T n g b + exact inferInstanceAs (Fintype (Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)))) + +/-- A fixed bijection, independent of every bit, reveal and hypothesis. -/ +def windowAssignmentEquiv (T n g : ℕ → ℕ) (A : Type) : + (b : ℕ) → WindowAssignments T n g A b ≃ (WindowTrial T n g b → A) + | 0 => + { toFun := fun _ i => PEmpty.elim i + invFun := fun _ => PUnit.unit + left_inv := fun x => by cases x; rfl + right_inv := fun x => by funext i; exact PEmpty.elim i } + | b+1 => + { toFun := fun x i => match i with + | .inl k => x.1 k + | .inr (.inl k) => x.2.1 k + | .inr (.inr (u,k)) => windowAssignmentEquiv T n g A b (x.2.2 u) k + invFun := fun x => (fun k => x (.inl k),fun k => x (.inr (.inl k)), + fun u => (windowAssignmentEquiv T n g A b).symm (fun k => x (.inr (.inr (u,k))))) + left_inv := fun x => by + rcases x with ⟨loc,glob,kids⟩ + change (loc,glob,fun u => (windowAssignmentEquiv T n g A b).symm + (windowAssignmentEquiv T n g A b (kids u)))=(loc,glob,kids) + simp only [Equiv.symm_apply_apply] + + right_inv := fun x => by + funext i + rcases i with k | k + · rfl + · rcases k with k | ⟨u,k⟩ + · rfl + · exact congrFun ((windowAssignmentEquiv T n g A b).apply_symm_apply + (fun k => x (.inr (.inr (u,k))))) k } + +theorem windowPosterior_mass_flat (T n g : ℕ → ℕ) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) b) (bits : WindowAssignments T n g Bool b) : + (windowPosteriorLaw T n g b d).mass bits= + ∏i : WindowTrial T n g b,(FiniteLaw.flagPosterior + (windowAssignmentEquiv T n g (Option Bool) b d i)).mass + (windowAssignmentEquiv T n g Bool b bits i) := by + induction b with + | zero => + change (1:ℝ)=∏i : PEmpty,_ + simp + | succ b ih => + change (∏i,(FiniteLaw.flagPosterior (d.1 i)).mass (bits.1 i))* + ((∏i,(FiniteLaw.flagPosterior (d.2.1 i)).mass (bits.2.1 i))* + ∏u,(windowPosteriorLaw T n g b (d.2.2 u)).mass (bits.2.2 u))=_ + simp_rw [ih] + change _=∏i : Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b)), + (FiniteLaw.flagPosterior (match i with + | .inl k => d.1 k + | .inr (.inl k) => d.2.1 k + | .inr (.inr (u,k)) => windowAssignmentEquiv T n g (Option Bool) b (d.2.2 u) k)).mass + (match i with + | .inl k => bits.1 k + | .inr (.inl k) => bits.2.1 k + | .inr (.inr (u,k)) => windowAssignmentEquiv T n g Bool b (bits.2.2 u) k) + simp only [Fintype.prod_sum_type,Fintype.prod_prod_type] + +/-- Exact flat posterior distribution, including all paths and zero-mass + metadata. This is the same independent bit law, not a new assumption. -/ +theorem windowPosterior_expect_flat (T n g : ℕ → ℕ) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) b) + (F : WindowAssignments T n g Bool b → ℝ) : + (windowPosteriorLaw T n g b d).expect F= + (FiniteLaw.indexedProduct (fun i : WindowTrial T n g b => FiniteLaw.flagPosterior + (windowAssignmentEquiv T n g (Option Bool) b d i))).expect + (fun bits => F ((windowAssignmentEquiv T n g Bool b).symm bits)) := by + unfold FiniteLaw.expect FiniteLaw.indexedProduct + rw [←(windowAssignmentEquiv T n g Bool b).sum_comp] + apply Finset.sum_congr rfl + intro bits _ + dsimp only + rw [Equiv.symm_apply_apply,windowPosterior_mass_flat] + +def noReveals (T n g : ℕ → ℕ) (b : ℕ) : WindowAssignments T n g (Option Bool) b := + (windowAssignmentEquiv T n g (Option Bool) b).symm (fun _ => none) + +theorem windowPosterior_fair_flat (T n g : ℕ → ℕ) (b : ℕ) + (F : WindowAssignments T n g Bool b → ℝ) : + (windowPosteriorLaw T n g b (noReveals T n g b)).expect F= + (FiniteLaw.indexedProduct (fun _ : WindowTrial T n g b => FiniteLaw.flagPosterior none)).expect + (fun bits => F ((windowAssignmentEquiv T n g Bool b).symm bits)) := by + rw [windowPosterior_expect_flat] + simp only [noReveals,Equiv.apply_symm_apply] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The literal global schedule is indexed by a fixed pair/block bijection. -/ +def globalTrialEquiv (N t : ℕ) : (Fin (N/4) × Fin t) ≃ Fin ((N/4)*t) := + Equiv.ofBijective _ (globalTrialIndex_bijective N t) + +def sourceGlobalCoefficient (N t : ℕ) (u : Fin N) (k : Fin ((N/4)*t)) : ℝ := + let v := ((globalTrialEquiv N t).symm k).1 + if v.val≤u.val ∧ u.val+v.val 0 + | .inr (.inl k) => sourceGlobalCoefficient (T (b+1)) (n b) u k + | .inr (.inr (v,.inl _)) => if v=u then 1 else 0 + | .inr (.inr (_,.inr _)) => 0 + +theorem even_half_cast (t : ℕ) (ht : Even t) : ((t/2:ℕ):ℝ)=(t:ℝ)/2 := by + have h : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) + have hr : (2:ℝ)*(t/2:ℕ)=t := by exact_mod_cast h + linarith + +theorem scheduledGlobalShift_linear (N t : ℕ) (ht : Even t) + (bits : Fin ((N/4)*t) → Bool) (u : Fin N) : + (scheduledGlobalShift N t bits u:ℝ)= + ∑k,sourceGlobalCoefficient N t u k*((bitIndex (bits k):ℝ)-1/2) := by + rw [←(globalTrialEquiv N t).sum_comp] + simp only [Fintype.sum_prod_type,sourceGlobalCoefficient,Equiv.symm_apply_apply] + unfold scheduledGlobalShift + simp only [Int.cast_sum,Int.cast_ite,Int.cast_sub,Int.cast_natCast,Int.cast_zero] + apply Finset.sum_congr rfl + intro v _ + split_ifs with hv + · simp only [one_mul,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul] + rw [even_half_cast t ht] + simp only [globalTrialEquiv,Equiv.ofBijective_apply] + ring + · simp only [zero_mul,Finset.sum_const_zero] + +theorem sourceDisplacement_linear (T n : ℕ → ℕ) (b : ℕ) (ht : Even (n b)) + (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) (u : Fin (T (b+1))) : + (sourceDisplacement (T (b+1)) (n b) (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)= + fairLinearSum (sourceGroupCoefficient T n b u) + (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool (b+2) bits) := by + rcases bits with ⟨root,global,children⟩ + change Fin ((T (b+1)/4)*n b) → Bool at global + change Fin (T (b+1)) → ((Fin (n b) → Bool) × + (Fin (sourceScheduledTrials T n b) → Bool) × + (Fin (T b) → WindowAssignments T n (sourceScheduledTrials T n) Bool b)) at children + unfold fairLinearSum + change _=∑i : Fin (n (b+1)) ⊕ (Fin ((T (b+1)/4)*n b) ⊕ + (Fin (T (b+1)) × (Fin (n b) ⊕ (Fin (sourceScheduledTrials T n b) ⊕ + (Fin (T b) × WindowTrial T n (sourceScheduledTrials T n) b))))),_ + simp only [Fintype.sum_sum_type,Fintype.sum_prod_type,sourceGroupCoefficient, + zero_mul,Finset.sum_const_zero,zero_add,add_zero] + change _=(∑k,sourceGlobalCoefficient (T (b+1)) (n b) u k* + ((bitIndex (global k):ℝ)-1/2))+ + (∑v : Fin (T (b+1)),∑a : Fin (n b), + (if v=u then (1:ℝ) else 0)*((bitIndex ((children v).1 a):ℝ)-1/2)) + have hl : (∑v : Fin (T (b+1)),∑a : Fin (n b), + (if v=u then (1:ℝ) else 0)*((bitIndex ((children v).1 a):ℝ)-1/2))= + (∑a : Fin (n b),(bitIndex ((children u).1 a):ℝ))-(n b:ℝ)/2 := by + simp only [ite_mul,one_mul,zero_mul] + rw [show (∑v : Fin (T (b+1)),∑a : Fin (n b), + if v=u then ((bitIndex ((children v).1 a):ℝ)-1/2) else 0)= + ∑v : Fin (T (b+1)),if v=u then + (∑a : Fin (n b),((bitIndex ((children v).1 a):ℝ)-1/2)) else 0 from by + apply Finset.sum_congr rfl + intro v _ + split_ifs <;> simp] + rw [Finset.sum_ite_eq',ite_eq_left (Finset.mem_univ u)] + simp only [Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + ring + rw [hl,←scheduledGlobalShift_linear (T (b+1)) (n b) ht global u] + simp only [sourceDisplacement,Int.cast_add,Int.cast_sub,Int.cast_sum,Int.cast_natCast, + even_half_cast _ ht] + ring + +theorem sourceGroupCoefficient_variance (T n : ℕ → ℕ) (b : ℕ) (u : Fin (T (b+1))) : + (∑i,(sourceGroupCoefficient T n b u i)^2)≤((T (b+1):ℝ)+1)*(n b:ℝ) := by + change (∑i : Fin (n (b+1)) ⊕ (Fin ((T (b+1)/4)*n b) ⊕ + (Fin (T (b+1)) × (Fin (n b) ⊕ (Fin (sourceScheduledTrials T n b) ⊕ + (Fin (T b) × WindowTrial T n (sourceScheduledTrials T n) b))))),_)≤_ + simp only [Fintype.sum_sum_type,Fintype.sum_prod_type,sourceGroupCoefficient, + zero_pow (by omega : 2≠0),Finset.sum_const_zero,zero_add,add_zero] + have hg : (∑k : Fin ((T (b+1)/4)*n b),(sourceGlobalCoefficient (T (b+1)) (n b) u k)^2)≤ + ((T (b+1)/4)*n b:ℕ) := by + calc + _ ≤ ∑_k : Fin ((T (b+1)/4)*n b),(1:ℝ) := by + apply Finset.sum_le_sum + intro k _ + dsimp only [sourceGlobalCoefficient] + split_ifs <;> norm_num + _ = _ := by simp + have hl : (∑v : Fin (T (b+1)),∑_a : Fin (n b),(if v=u then (1:ℝ) else 0)^2)=(n b:ℝ) := by + simp only [ite_pow,one_pow,zero_pow (by omega : 2≠0)] + simp + rw [hl] + have hdiv : ((T (b+1)/4:ℕ):ℝ)≤T (b+1) := by exact_mod_cast Nat.div_le_self (T (b+1)) 4 + push_cast at hg + have hm := mul_le_mul_of_nonneg_right hdiv (Nat.cast_nonneg (n b): (0:ℝ)≤n b) + nlinarith only [hg,hm] + +/-- Actual per-window unconditional fit tail under the full tree's fair law. + No independence between different window displacements is asserted. -/ +theorem sourceDisplacement_tail (T n : ℕ → ℕ) (b : ℕ) (ht : Even (n b)) + (hn : 0 if a≤|(sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| then 1 else 0)≤ + 2*Real.exp (-2*a^2/(((T (b+1):ℝ)+1)*(n b:ℝ))) := by + rw [windowPosterior_fair_flat] + simp_rw [sourceDisplacement_linear T n b ht,Equiv.apply_symm_apply] + exact fairLinearSum_tail_variance (sourceGroupCoefficient T n b u) + (by positivity) (sourceGroupCoefficient_variance T n b u) ha + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α ι : Type*} [Fintype α] [Fintype ι] + +theorem expect_fintype_sum (P : FiniteLaw α) (f : ι → α → ℝ) : + P.expect (fun a => ∑i,f i a)=∑i,P.expect (f i) := by + simp only [expect,Finset.mul_sum] + exact Finset.sum_comm + +theorem expect_add (P : FiniteLaw α) (f g : α → ℝ) : + P.expect (fun a => f a+g a)=P.expect f+P.expect g := by + simp only [expect,mul_add,Finset.sum_add_distrib] + +theorem coordinateProduct_expect_eval {n : ℕ} (P : Fin n → FiniteLaw α) + (u : Fin n) (f : α → ℝ) : + (coordinateProduct P).expect (fun x => f (x u))=(P u).expect f := by + let F : Fin n → α → ℝ := fun j a => if j=u then f a else 1 + have hp (x : Fin n → α) : (∏j,F j (x j))=f (x u) := by simp [F] + rw [show (fun x : Fin n → α => f (x u))=(fun x => ∏j,F j (x j)) by + funext x; exact (hp x).symm,coordinateProduct_expect_product] + have hj (j : Fin n) : (P j).expect (F j)=if j=u then (P j).expect f else 1 := by + by_cases h : j=u <;> simp [F,h,expect_const] + simp_rw [hj] + simp + +end FiniteLaw + +theorem noReveals_succ (T n g : ℕ → ℕ) (b : ℕ) : + noReveals T n g (b+1)=(fun _ => none,fun _ => none,fun _ => noReveals T n g b) := rfl + +theorem windowPosterior_child (T n g : ℕ → ℕ) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) (b+1)) (u : Fin (T b)) + (F : WindowAssignments T n g Bool b → ℝ) : + (windowPosteriorLaw T n g (b+1) d).expect (fun bits => F (bits.2.2 u))= + (windowPosteriorLaw T n g b (d.2.2 u)).expect F := by + rcases d with ⟨loc,glob,kids⟩ + change ((posteriorArray loc).prod ((posteriorArray glob).prod + (FiniteLaw.coordinateProduct (fun i => windowPosteriorLaw T n g b (kids i))))).expect + (fun bits => F (bits.2.2 u))=_ + rw [FiniteLaw.expect_prod] + simp_rw [FiniteLaw.expect_prod,FiniteLaw.coordinateProduct_expect_eval,FiniteLaw.expect_const] + +theorem failure_forall_le_sum {ι : Type*} [Fintype ι] (p : ι → Prop) [DecidablePred p] [Decidable (∀i,p i)] : + (if ∀i,p i then (0:ℝ) else 1)≤∑i,if p i then 0 else 1 := by + by_cases hp : ∀i,p i + · simp only [ite_eq_left hp] + exact Finset.sum_nonneg (fun i _ => by split_ifs <;> norm_num) + · simp only [ite_eq_right hp] + push Not at hp + obtain ⟨i,hi⟩ := hp + calc + (1:ℝ) = if p i then 0 else 1 := by simp [hi] + _ ≤ ∑j,if p j then 0 else 1 := by + apply Finset.single_le_sum (f:=fun j => if p j then (0:ℝ) else 1) + · intro j _; split_ifs <;> norm_num + · exact Finset.mem_univ i + +/-- Explicit finite tree union bound. The source's scale estimates will make + this number exponentially small; no independence of sibling shifts is used. -/ +def sourceFitTail (T n : ℕ → ℕ) : ℕ → ℝ + | 0 => 0 + | 1 => 0 + | b+2 => (T (b+1):ℝ)*(2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ)))+ + sourceFitTail T n (b+1)) + +theorem sourceTreeFit_tail (T n : ℕ → ℕ) (b : ℕ) + (hn : ∀j if SourceTreeFit T n b bits then 0 else 1) ≤ sourceFitTail T n b := by + induction b using Nat.twoStepInduction with + | zero => + have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 0) : SourceTreeFit T n 0 bits := trivial + simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] + | one => + have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 1) : SourceTreeFit T n 1 bits := trivial + simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] + | more b ih0 ih => + let P := windowPosteriorLaw T n (sourceScheduledTrials T n) (b+2) + (noReveals T n (sourceScheduledTrials T n) (b+2)) + let badShift : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2) → Fin (T (b+1)) → Prop := + fun bits u => (T b:ℝ)/8≤|(sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| + have hp (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) : + (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ + (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ + (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by + let p := fun u : Fin (T (b+1)) => |8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u|≤(T b:ℤ) + have hh : (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ + (if ∀u,p u then 0 else 1)+(if ∀u,SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by + by_cases H : SourceTreeFit T n (b+2) bits + · rw [ite_eq_left H] + split_ifs <;> norm_num + · rw [ite_eq_right H] + by_cases h1 : ∀u,p u + · have h2 : ¬∀u,SourceTreeFit T n (b+1) (bits.2.2 u) := fun h2 => H ⟨h1,h2⟩ + rw [ite_eq_left h1,ite_eq_right h2] + norm_num + · rw [ite_eq_right h1] + split_ifs <;> norm_num + apply hh.trans + apply add_le_add + · apply (failure_forall_le_sum p).trans + apply Finset.sum_le_sum + intro u _ + by_cases hu : p u + · simp only [ite_eq_left hu] + split_ifs <;> norm_num + · have hr : (T b:ℝ)<8*|(sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| := by + have hi : (T b:ℤ) < |8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u| := lt_of_not_ge hu + have hi' : (T b:ℝ) < |(8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℤ)| := by exact_mod_cast hi + norm_num only [Int.cast_abs,Int.cast_mul,Int.cast_ofNat,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<8)] at hi' + exact hi' + have hb : badShift bits u := by dsimp [badShift]; linarith + simp [hu,hb] + · exact failure_forall_le_sum _ + calc + _ ≤ P.expect (fun bits => (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ + (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := + P.expect_mono hp + _ = (∑u : Fin (T (b+1)),P.expect (fun bits => if badShift bits u then 1 else 0))+ + (∑u : Fin (T (b+1)),P.expect (fun bits => if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := by + rw [FiniteLaw.expect_add,FiniteLaw.expect_fintype_sum,FiniteLaw.expect_fintype_sum] + _ ≤ (∑_u : Fin (T (b+1)),2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ))))+ + ∑_u : Fin (T (b+1)),sourceFitTail T n (b+1) := by + apply add_le_add + · apply Finset.sum_le_sum + intro u _ + exact sourceDisplacement_tail T n b (he b (by omega)) (hn b (by omega)) u (by positivity) + · apply Finset.sum_le_sum + intro u _ + dsimp only [P] + rw [windowPosterior_child T n (sourceScheduledTrials T n) (b+1) + (noReveals T n (sourceScheduledTrials T n) (b+2)) u + (fun x => if SourceTreeFit T n (b+1) x then 0 else 1)] + rw [noReveals_succ] + exact ih (fun j hj => hn j (by omega)) (fun j hj => he j (by omega)) + _ = sourceFitTail T n (b+2) := by simp [sourceFitTail,mul_add] + +end TraceReconstruction + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Model.lean b/lean/OAI/Probability/TraceReconstruction/Model.lean index b5e91214b2af88dcd12c914b7146fa2a0d4ae392..b662bc6c2de055afe95d8158682b1a43d08cac45 100644 --- a/lean/OAI/Probability/TraceReconstruction/Model.lean +++ b/lean/OAI/Probability/TraceReconstruction/Model.lean @@ -1,548 +1,548 @@ -import OAI.Probability.TraceReconstruction.FiniteLaw - -namespace OAI - -/-! -# Model - -Independent deletion, complete trace observations, randomized estimators, ENNReal fixed-budget complexity, concatenation, and literal input words. --/ - -open scoped ENNReal -noncomputable section - -open scoped ENNReal -noncomputable section - -namespace TraceReconstruction - -abbrev Word (n : ℕ) := Fin n → Bool -abbrev Mask (n : ℕ) := Fin n → Bool -abbrev Trace := List Bool - -/-- `true` retains the bit. The observer gets only the resulting list. -/ -def traceOfMask {n : ℕ} (x : Word n) (a : Mask n) : Trace := - ((List.finRange n).filter fun i => a i).map x - -/-- The deletion-mask probability, with deletion probability `q`. -/ -def maskWeight {n : ℕ} (q : ℝ) (a : Mask n) : ℝ := - ∏ i, if a i then 1 - q else q - -/-- Law of a single complete trace. -/ -def traceMass {n : ℕ} (q : ℝ) (x : Word n) (w : Trace) : ℝ := - ∑ a : Mask n, if traceOfMask x a = w then maskWeight q a else 0 - -/-- All possible complete outputs from length-n inputs, with lengths included. -/ -def traceSpace (n : ℕ) : Finset Trace := - Finset.univ.biUnion fun k : Fin (n + 1) => - Finset.univ.image fun x : Word k.val => List.ofFn x - -/-- 1/2 sum of absolute differences, on the full finite output space. -/ -def traceTV {n : ℕ} (q : ℝ) (x y : Word n) : ℝ := - (1 / 2 : ℝ) * ∑ w ∈ traceSpace n, |traceMass q x w - traceMass q y w| - -/-- The estimator may depend arbitrarily on n, q and every complete sample. - Its value is its conditional probability of reporting the given input. -/ -def IsEstimator {n m : ℕ} (A : (Fin m → Trace) → Word n → ℝ) : Prop := - (∀ z x, 0 ≤ A z x) ∧ (∀ z, ∑ x : Word n, A z x = 1) - -/-- Independent masks generate independent complete traces; no retained - positions, boundaries or other latent variables are revealed to A. -/ -def reconstructionSuccess {n m : ℕ} (q : ℝ) - (A : (Fin m → Trace) → Word n → ℝ) (x : Word n) : ℝ := - ∑ a : Fin m → Mask n, - (∏ j, maskWeight q (a j)) * A (fun j => traceOfMask x (a j)) x - -def SufficientBudget (n : ℕ) (q s : ℝ) (m : ℕ) : Prop := - ∃ A : (Fin m → Trace) → Word n → ℝ, - IsEstimator A ∧ ∀ x, s ≤ reconstructionSuccess q A x - -/-- Natural fixed sample budget; infimum of the empty set is infinity. -/ -noncomputable def sampleComplexity (n : ℕ) (q s : ℝ) : ℝ≥0∞ := - sInf {t | ∃ m : ℕ, SufficientBudget n q s m ∧ t = (m : ℝ≥0∞)} - -/-- The real infimum is a minimum for n>0 (a nonempty finite set). -/ -noncomputable def minTraceTV (n : ℕ) (q : ℝ) : ℝ := - sInf {t | ∃ x y : Word n, x ≠ y ∧ t = traceTV q x y} - -end TraceReconstruction - -noncomputable section - -namespace TraceReconstruction - - - - -/-! ## Exact finite channel laws -/ - -theorem traceOfMask_length_le {n : ℕ} (x : Word n) (a : Mask n) : - (traceOfMask x a).length ≤ n := by - simpa [traceOfMask] using List.length_filter_le (fun i => a i) (List.finRange n) - -theorem mem_traceSpace_of_length_le {n : ℕ} (w : Trace) (h : w.length ≤ n) : - w ∈ traceSpace n := by - apply Finset.mem_biUnion.mpr - refine ⟨⟨w.length, Nat.lt_succ_of_le h⟩, Finset.mem_univ _, ?_⟩ - exact Finset.mem_image.mpr ⟨w.get, Finset.mem_univ _, List.ofFn_get w⟩ - -theorem length_le_of_mem_traceSpace {n : ℕ} {w : Trace} (h : w ∈ traceSpace n) : - w.length ≤ n := by - obtain ⟨k, _, hk⟩ := Finset.mem_biUnion.mp h - obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hk - simpa using Nat.le_of_lt_succ k.isLt - -@[simp] theorem mem_traceSpace {n : ℕ} {w : Trace} : - w ∈ traceSpace n ↔ w.length ≤ n := - ⟨length_le_of_mem_traceSpace, mem_traceSpace_of_length_le w⟩ - -theorem traceOfMask_mem {n : ℕ} (x : Word n) (a : Mask n) : - traceOfMask x a ∈ traceSpace n := - mem_traceSpace_of_length_le _ (traceOfMask_length_le x a) - -theorem maskWeight_nonneg {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) (a : Mask n) : - 0 ≤ maskWeight q a := by - apply Finset.prod_nonneg - intro i _ - split <;> linarith [hq.1, hq.2] - -@[simp] theorem sum_maskWeight {n : ℕ} (q : ℝ) : - ∑ a : Mask n, maskWeight q a = 1 := by - unfold maskWeight - change (∑ a : Fin n → Bool, ∏ i, (fun (_ : Fin n) (b : Bool) => - if b then 1 - q else q) i (a i)) = 1 - rw [← Fintype.prod_sum (fun (_ : Fin n) (b : Bool) => if b then 1 - q else q)] - simp - -theorem traceMass_nonneg {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) - (x : Word n) (w : Trace) : 0 ≤ traceMass q x w := by - apply Finset.sum_nonneg - intro a _ - split - · exact maskWeight_nonneg hq a - · exact le_rfl - -theorem traceMass_eq_zero_of_not_mem {n : ℕ} (q : ℝ) (x : Word n) (w : Trace) - (hw : w ∉ traceSpace n) : traceMass q x w = 0 := by - apply Finset.sum_eq_zero - intro a _ - have hne : traceOfMask x a ≠ w := by - intro h - exact hw (h ▸ traceOfMask_mem x a) - simp [hne] - -@[simp] theorem sum_traceMass {n : ℕ} (q : ℝ) (x : Word n) : - ∑ w ∈ traceSpace n, traceMass q x w = 1 := by - unfold traceMass - rw [Finset.sum_comm] - simp [traceOfMask_length_le] - -theorem traceTV_nonneg {n : ℕ} (q : ℝ) (x y : Word n) : 0 ≤ traceTV q x y := by - unfold traceTV - positivity - -@[simp] theorem traceTV_self {n : ℕ} (q : ℝ) (x : Word n) : traceTV q x x = 0 := by - simp [traceTV] - -theorem traceTV_comm {n : ℕ} (q : ℝ) (x y : Word n) : traceTV q x y = traceTV q y x := by - simp only [traceTV, abs_sub_comm] - -theorem traceTV_le_one {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) (x y : Word n) : - traceTV q x y ≤ 1 := by - have h : ∑ w ∈ traceSpace n, |traceMass q x w - traceMass q y w| ≤ - ∑ w ∈ traceSpace n, (traceMass q x w + traceMass q y w) := by - apply Finset.sum_le_sum - intro w _ - exact abs_sub_le_iff.mpr - ⟨by linarith [traceMass_nonneg hq y w], by linarith [traceMass_nonneg hq x w]⟩ - rw [Finset.sum_add_distrib, sum_traceMass, sum_traceMass] at h - unfold traceTV - linarith - - -end TraceReconstruction - -namespace TraceReconstruction -namespace FiniteLaw -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -@[ext] theorem ext {P Q : FiniteLaw α} (h : P.mass = Q.mass) : P = Q := by - cases P with - | mk pm pn pt => cases Q with - | mk qm qn qt => cases h; rfl - -noncomputable def pure (a : α) : FiniteLaw α := by - classical - exact ⟨(fun b => if a = b then 1 else 0), - (fun b => by split_ifs <;> norm_num), by simp⟩ - -noncomputable def map (P : FiniteLaw α) (f : α → β) : FiniteLaw β := - P.bind (fun a => pure (f a)) - -theorem map_mass [DecidableEq β] (P : FiniteLaw α) (f : α → β) (b : β) : - (P.map f).mass b = ∑ a, if f a = b then P.mass a else 0 := by - classical - unfold map bind pure - simp only - apply Finset.sum_congr rfl - intro a _ - split_ifs <;> simp - -theorem expectation_map (P : FiniteLaw α) (f : α → β) (F : β → ℝ) : - (∑ b, (P.map f).mass b * F b) = ∑ a, P.mass a * F (f a) := by - classical - simp_rw [map_mass, Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - simp - -theorem tv_map_le (P Q : FiniteLaw α) (f : α → β) : - tv (P.map f) (Q.map f) ≤ tv P Q := tv_bind_le P Q _ - -end FiniteLaw - -abbrev BoundedTrace (n : ℕ) := ↥(traceSpace n) - -def maskLaw {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) : FiniteLaw (Mask n) := - ⟨maskWeight q, maskWeight_nonneg hq, sum_maskWeight q⟩ - -def completeTraceLaw {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x : Word n) : - FiniteLaw (BoundedTrace n) where - mass w := traceMass q x w - nonneg w := traceMass_nonneg hq x w - total := by rw [Finset.sum_coe_sort]; exact sum_traceMass q x - -theorem completeTraceLaw_tv {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x y : Word n) : - (completeTraceLaw q hq x).tv (completeTraceLaw q hq y) = traceTV q x y := by - change (1 / 2 : ℝ) * (∑ w : BoundedTrace n, |traceMass q x w - traceMass q y w|) = _ - rw [Finset.sum_coe_sort (traceSpace n) (fun w => |traceMass q x w - traceMass q y w|)] - rfl - -theorem completeTraceLaw_mask {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x : Word n) : - completeTraceLaw q hq x = - (maskLaw q hq).map (fun a : Mask n => ⟨traceOfMask x a, traceOfMask_mem x a⟩) := by - apply FiniteLaw.ext - funext w - rw [FiniteLaw.map_mass] - unfold completeTraceLaw traceMass maskLaw - simp only - apply Finset.sum_congr rfl - intro a _ - rcases w with ⟨w, hw⟩ - simp only [Subtype.mk.injEq] - -theorem trace_expectation {n : ℕ} (q : ℝ) (x : Word n) (F : Trace → ℝ) : - (∑ w ∈ traceSpace n, traceMass q x w * F w) = - ∑ a : Mask n, maskWeight q a * F (traceOfMask x a) := by - classical - unfold traceMass - simp_rw [Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - simp [traceOfMask_length_le] - -/-- Concatenation of exact binary inputs, not an encoded surrogate. -/ -def appendWord {n m : ℕ} (x : Word n) (y : Word m) : Word (n + m) := Fin.append x y - -theorem trace_filterMap {n : ℕ} (x : Word n) (a : Mask n) : - traceOfMask x a = (List.ofFn fun i => if a i then some (x i) else none).filterMap id := by - have hlist (l : List (Fin n)) : - (l.filter fun i => a i).map x = l.filterMap (fun i => if a i then some (x i) else none) := by - induction l with - | nil => rfl - | cons i l ih => cases hai : a i <;> simp [hai, ih] - unfold traceOfMask - rw [hlist] - have heq : (List.ofFn fun i => if a i then some (x i) else none) = - (List.finRange n).map (fun i => if a i then some (x i) else none) := by - rw [← List.ofFn_id, List.map_ofFn] - rfl - rw [heq, List.filterMap_map] - rfl - -theorem traceOfMask_append {n m : ℕ} (x : Word n) (y : Word m) - (a : Mask n) (b : Mask m) : - traceOfMask (appendWord x y) (Fin.append a b) = traceOfMask x a ++ traceOfMask y b := by - rw [trace_filterMap, List.ofFn_add, List.filterMap_append, trace_filterMap, trace_filterMap] - congr 2 <;> apply congrArg List.ofFn <;> funext i - · change (if Fin.append a b (Fin.castAdd m i) then some (Fin.append x y (Fin.castAdd m i)) else none) = _ - simp - · simp [appendWord] - -theorem maskWeight_append {n m : ℕ} (q : ℝ) (a : Mask n) (b : Mask m) : - maskWeight q (Fin.append a b) = maskWeight q a * maskWeight q b := by - unfold maskWeight - rw [Fin.prod_univ_add] - simp - -theorem concatenated_trace_expectation {n m : ℕ} (q : ℝ) (x : Word n) (y : Word m) - (F : Trace → ℝ) : - (∑ a : Mask (n + m), maskWeight q a * F (traceOfMask (appendWord x y) a)) = - ∑ a : Mask n, ∑ b : Mask m, - maskWeight q a * maskWeight q b * F (traceOfMask x a ++ traceOfMask y b) := by - rw [← (Fin.appendEquiv n m).sum_comp] - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - change maskWeight q (Fin.append a b) * F (traceOfMask (appendWord x y) (Fin.append a b)) = _ - rw [maskWeight_append, traceOfMask_append] - -end TraceReconstruction - -namespace TraceReconstruction - -/-- The four complete traces possible from the ordinary primitive `01`. -/ -abbrev PrimitiveMark := Fin 4 - -def primitiveOutput : PrimitiveMark → List Bool := ![[], [false], [true], [false, true]] -def ordinaryPrimitiveMass (q : ℝ) : PrimitiveMark → ℝ := - ![q ^ 2, q * (1 - q), q * (1 - q), (1 - q) ^ 2] -def defectPrimitiveMass (q : ℝ) : PrimitiveMark → ℝ := ![q, 0, 1 - q, 0] -def primitiveErasure (q : ℝ) : ℝ := q ^ 2 / 2 - -def primitiveMarkMass (q : ℝ) (isDefect : Bool) (z : PrimitiveMark) : ℝ := - ((if isDefect then defectPrimitiveMass q z else ordinaryPrimitiveMass q z) - - if z = 0 then primitiveErasure q else 0) / (1 - primitiveErasure q) - -theorem primitive_retain_pos {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : - 0 < 1 - primitiveErasure q := by - unfold primitiveErasure - nlinarith [hq.1, hq.2] - -theorem primitiveMarkMass_nonneg {q : ℝ} (hq : q ∈ Set.Ioo 0 1) - (b : Bool) (z : PrimitiveMark) : 0 ≤ primitiveMarkMass q b z := by - apply div_nonneg _ (primitive_retain_pos hq).le - cases b <;> fin_cases z <;> - simp [ordinaryPrimitiveMass, defectPrimitiveMass, primitiveErasure] <;> - nlinarith [hq.1, hq.2] - -theorem primitiveMarkMass_sum {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (b : Bool) : - ∑ z : PrimitiveMark, primitiveMarkMass q b z = 1 := by - have hd := ne_of_gt (primitive_retain_pos hq) - unfold primitiveMarkMass - rw [← Finset.sum_div] - apply (div_eq_one_iff_eq hd).mpr - cases b <;> simp [ordinaryPrimitiveMass, defectPrimitiveMass, primitiveErasure, Fin.sum_univ_succ] - all_goals ring - -def primitiveMarkLaw (q : ℝ) (hq : q ∈ Set.Ioo 0 1) (b : Bool) : FiniteLaw PrimitiveMark := - ⟨primitiveMarkMass q b, primitiveMarkMass_nonneg hq b, primitiveMarkMass_sum hq b⟩ - -/-- Emitting the conditional mark, or silently erasing the block, gives -exactly the ordinary primitive-output probabilities. Silent erasure and an -emitted empty mark are distinct latent events. -/ -theorem primitiveMark_simulation {q : ℝ} (hq : q ∈ Set.Ioo 0 1) - (b : Bool) (z : PrimitiveMark) : - (if z = 0 then primitiveErasure q else 0) + - (1 - primitiveErasure q) * primitiveMarkMass q b z = - if b then defectPrimitiveMass q z else ordinaryPrimitiveMass q z := by - unfold primitiveMarkMass - rw [mul_div_cancel₀ _ (ne_of_gt (primitive_retain_pos hq))] - ring - -def primitiveScore (q : ℝ) : PrimitiveMark → ℝ := ![2 / q - 2, -1, 1 / q - 1, -1] - -theorem primitive_score_identity {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (z : PrimitiveMark) : - primitiveMarkMass q true z = primitiveMarkMass q false z * (1 + primitiveScore q z) := by - have hq0 := ne_of_gt hq.1 - have hd := ne_of_gt (primitive_retain_pos hq) - fin_cases z <;> - simp [primitiveMarkMass, ordinaryPrimitiveMass, defectPrimitiveMass, primitiveScore, primitiveErasure] <;> - field_simp - all_goals ring - -theorem primitive_score_centered {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : - ∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z = 0 := by - have hi := primitiveMarkMass_sum hq true - simp_rw [primitive_score_identity hq, mul_add, mul_one, Finset.sum_add_distrib, - primitiveMarkMass_sum hq false] at hi - linarith - -theorem primitive_score_bound {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (z : PrimitiveMark) : - |primitiveScore q z| ≤ 2 / q := by - have hi : 1 ≤ 1 / q := (le_div_iff₀ hq.1).mpr (by linarith [hq.2]) - simp only [one_div] at hi - have he : 2 / q = 2 * (1 / q) := by ring - fin_cases z <;> simp [primitiveScore, abs_le, he] <;> (try constructor) <;> linarith - -theorem primitive_score_variance_exact {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : - (∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z ^ 2) = - (1 / q - 2 * q + q ^ 2) / (1 - q ^ 2 / 2) := by - have hq0 := ne_of_gt hq.1 - have hd := ne_of_gt (primitive_retain_pos hq) - simp only [primitiveMarkMass, primitiveScore, ordinaryPrimitiveMass, primitiveErasure, - Bool.false_eq_true, ↓reduceIte] - simp [Fin.sum_univ_succ] - field_simp - ring - -theorem primitive_score_variance_le {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : - (∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z ^ 2) ≤ 2 / q := by - rw [primitive_score_variance_exact hq] - have hd : 0 < 1 - q ^ 2 / 2 := primitive_retain_pos hq - apply (div_le_div_iff₀ hd hq.1).mpr - rw [add_mul, sub_mul, one_div_mul_cancel (ne_of_gt hq.1)] - have hpow : q ^ 3 ≤ q ^ 2 := by - calc - _ = q ^ 2 * q := by ring - _ ≤ q ^ 2 * 1 := mul_le_mul_of_nonneg_left hq.2.le (sq_nonneg _) - _ = _ := mul_one _ - nlinarith only [hpow, sq_nonneg q] - -end TraceReconstruction - -namespace TraceReconstruction -def ordinaryRun : ℕ → List Bool - | 0 => [] - | m + 1 => false :: true :: ordinaryRun m - -@[simp] theorem ordinaryRun_length (m : ℕ) : (ordinaryRun m).length = 2 * m := by - induction m with - | zero => rfl - | succ m ih => simp only [ordinaryRun, List.length_cons, ih]; omega - -theorem ordinaryRun_add (a b : ℕ) : ordinaryRun (a + b) = ordinaryRun a ++ ordinaryRun b := by - induction a with - | zero => simp [ordinaryRun] - | succ a ih => simp [Nat.succ_add, ordinaryRun, ih] - -/-- A period of m primitives with its unique `1` defect at zero-based slot d. -/ -def initialPeriod (m d : ℕ) : List Bool := - ordinaryRun d ++ [true] ++ ordinaryRun (m - 1 - d) - -theorem initialPeriod_length {m d : ℕ} (hd : d < m) : - (initialPeriod m d).length = 2 * m - 1 := by - simp only [initialPeriod, List.length_append, ordinaryRun_length, List.length_singleton] - omega - -/-- Distinct defect slots differ before either period ends, independently of future text. -/ -theorem initialPeriod_tail_ne {m d e : ℕ} (hde : d < e) (he : e < m) - (u v : List Bool) : initialPeriod m d ++ u ≠ initialPeriod m e ++ v := by - obtain ⟨a, ha⟩ := Nat.exists_eq_add_of_le (show d + 1 ≤ e by omega) - subst e - unfold initialPeriod - rw [Nat.add_assoc d 1 a, ordinaryRun_add d (1 + a)] - simp only [Nat.add_assoc] at * - simp only [Nat.one_add, ordinaryRun, List.append_assoc, List.cons_append, List.nil_append] - intro h - have hh := List.append_cancel_left h - have hf := congrArg List.head? hh - simp only [List.head?_cons, Option.some.injEq] at hf - cases hf - -theorem initialPeriod_injective (m : ℕ) : - Function.Injective (fun d : Fin m => initialPeriod m d) := by - intro d e h - by_contra hne - have hv : d.val ≠ e.val := fun hv => hne (Fin.ext hv) - rcases lt_or_gt_of_ne hv with hlt | hgt - · exact initialPeriod_tail_ne hlt e.isLt [] [] (by simpa using h) - · exact initialPeriod_tail_ne hgt d.isLt [] [] (by simpa using h.symm) - -def periodString (m P : ℕ) (d : Fin P → Fin m) : List Bool := - (List.ofFn (fun i => initialPeriod m (d i))).flatten - -theorem periodString_cons (m P : ℕ) (d : Fin (P + 1) → Fin m) : - periodString m (P + 1) d = initialPeriod m (d 0) ++ - periodString m P (fun i => d i.succ) := by - simp only [periodString, List.ofFn_succ, List.flatten_cons] - -theorem periodString_length (m P : ℕ) (d : Fin P → Fin m) : - (periodString m P d).length = P * (2 * m - 1) := by - induction P with - | zero => simp [periodString] - | succ P ih => - rw [periodString_cons, List.length_append, initialPeriod_length (d 0).isLt, ih] - rw [Nat.add_mul, one_mul, Nat.add_comm] - -theorem periodString_injective (m P : ℕ) : Function.Injective (periodString m P) := by - induction P with - | zero => intro d e _; exact Subsingleton.elim _ _ - | succ P ih => - intro d e h - rw [periodString_cons, periodString_cons] at h - have hz : d 0 = e 0 := by - by_contra hne - have hv : (d 0).val ≠ (e 0).val := fun hv => hne (Fin.ext hv) - rcases lt_or_gt_of_ne hv with hlt | hgt - · exact initialPeriod_tail_ne hlt (e 0).isLt _ _ h - · exact initialPeriod_tail_ne hgt (d 0).isLt _ _ h.symm - rw [hz] at h - have ht := ih (List.append_cancel_left h) - funext i - refine Fin.cases hz (fun j => congrFun ht j) i -end TraceReconstruction - -namespace TraceReconstruction -/-- Uniformly sized binary atoms concatenated without boundary marks. -/ -def atomString (P : ℕ) (w : Bool → List Bool) (θ : Fin P → Bool) : List Bool := - (List.ofFn (fun i => w (θ i))).flatten - -theorem atomString_cons (P : ℕ) (w : Bool → List Bool) (θ : Fin (P + 1) → Bool) : - atomString (P + 1) w θ = w (θ 0) ++ atomString P w (fun i => θ i.succ) := by - simp only [atomString, List.ofFn_succ, List.flatten_cons] - -theorem atomString_length (P S : ℕ) (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) - (θ : Fin P → Bool) : (atomString P w θ).length = P * S := by - induction P with - | zero => simp [atomString] - | succ P ih => rw [atomString_cons, List.length_append, hw, ih, Nat.add_mul, one_mul, Nat.add_comm] - -theorem atomString_injective (P S : ℕ) (w : Bool → List Bool) - (hw : ∀ b, (w b).length = S) (hinj : Function.Injective w) : - Function.Injective (atomString P w) := by - induction P with - | zero => intro θ φ _; exact Subsingleton.elim _ _ - | succ P ih => - intro θ φ h - rw [atomString_cons, atomString_cons] at h - have hh := congrArg (List.take S) h - have hθ (u : List Bool) (b : Bool) : (w b ++ u).take S = w b := by - rw [← hw b, List.take_left] - rw [hθ, hθ] at hh - have hz := hinj hh - rw [hz] at h - have ht := ih (List.append_cancel_left h) - funext i - exact Fin.cases hz (fun j => congrFun ht j) i - -/-- Zero-based notation for the source complementary template; `true` is minus. -The motif itself is fixed independently of the hypothesis. -/ -def templateType (P a L : ℕ) (sign : Fin L → Bool) (τ : Bool) (i : Fin P) : Bool := - if h : a ≤ i.val ∧ i.val < a + L then xor τ (sign ⟨i.val - a, by omega⟩) else false - -theorem templateType_at (P a L : ℕ) (sign : Fin L → Bool) (τ : Bool) - (hL : 0 < L) (ha : a < P) : - templateType P a L sign τ ⟨a, ha⟩ = xor τ (sign ⟨0, hL⟩) := by - simp [templateType, hL] - -theorem templateType_injective (P a L : ℕ) (sign : Fin L → Bool) - (hL : 0 < L) (ha : a < P) : - Function.Injective (templateType P a L sign) := by - intro τ υ h - have he := congrFun h ⟨a, ha⟩ - rw [templateType_at P a L sign τ hL ha, templateType_at P a L sign υ hL ha] at he - cases hs : sign ⟨0, hL⟩ <;> cases τ <;> cases υ <;> simp_all - -def complementaryWords (P a L : ℕ) (sign : Fin L → Bool) (w : Bool → List Bool) - (τ : Bool) : List Bool := atomString P w (templateType P a L sign τ) - -theorem complementaryWords_length (P a L S : ℕ) (sign : Fin L → Bool) - (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) (τ : Bool) : - (complementaryWords P a L sign w τ).length = P * S := atomString_length P S w hw _ - -theorem complementaryWords_injective (P a L S : ℕ) (sign : Fin L → Bool) - (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) (hinj : Function.Injective w) - (hL : 0 < L) (ha : a < P) : Function.Injective (complementaryWords P a L sign w) := - (atomString_injective P S w hw hinj).comp (templateType_injective P a L sign hL ha) -end TraceReconstruction - -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.FiniteLaw + +namespace OAI + +/-! +# Model + +Independent deletion, complete trace observations, randomized estimators, ENNReal fixed-budget complexity, concatenation, and literal input words. +-/ + +open scoped ENNReal +noncomputable section + +open scoped ENNReal +noncomputable section + +namespace TraceReconstruction + +abbrev Word (n : ℕ) := Fin n → Bool +abbrev Mask (n : ℕ) := Fin n → Bool +abbrev Trace := List Bool + +/-- `true` retains the bit. The observer gets only the resulting list. -/ +def traceOfMask {n : ℕ} (x : Word n) (a : Mask n) : Trace := + ((List.finRange n).filter fun i => a i).map x + +/-- The deletion-mask probability, with deletion probability `q`. -/ +def maskWeight {n : ℕ} (q : ℝ) (a : Mask n) : ℝ := + ∏ i, if a i then 1 - q else q + +/-- Law of a single complete trace. -/ +def traceMass {n : ℕ} (q : ℝ) (x : Word n) (w : Trace) : ℝ := + ∑ a : Mask n, if traceOfMask x a = w then maskWeight q a else 0 + +/-- All possible complete outputs from length-n inputs, with lengths included. -/ +def traceSpace (n : ℕ) : Finset Trace := + Finset.univ.biUnion fun k : Fin (n + 1) => + Finset.univ.image fun x : Word k.val => List.ofFn x + +/-- 1/2 sum of absolute differences, on the full finite output space. -/ +def traceTV {n : ℕ} (q : ℝ) (x y : Word n) : ℝ := + (1 / 2 : ℝ) * ∑ w ∈ traceSpace n, |traceMass q x w - traceMass q y w| + +/-- The estimator may depend arbitrarily on n, q and every complete sample. + Its value is its conditional probability of reporting the given input. -/ +def IsEstimator {n m : ℕ} (A : (Fin m → Trace) → Word n → ℝ) : Prop := + (∀ z x, 0 ≤ A z x) ∧ (∀ z, ∑ x : Word n, A z x = 1) + +/-- Independent masks generate independent complete traces; no retained + positions, boundaries or other latent variables are revealed to A. -/ +def reconstructionSuccess {n m : ℕ} (q : ℝ) + (A : (Fin m → Trace) → Word n → ℝ) (x : Word n) : ℝ := + ∑ a : Fin m → Mask n, + (∏ j, maskWeight q (a j)) * A (fun j => traceOfMask x (a j)) x + +def SufficientBudget (n : ℕ) (q s : ℝ) (m : ℕ) : Prop := + ∃ A : (Fin m → Trace) → Word n → ℝ, + IsEstimator A ∧ ∀ x, s ≤ reconstructionSuccess q A x + +/-- Natural fixed sample budget; infimum of the empty set is infinity. -/ +noncomputable def sampleComplexity (n : ℕ) (q s : ℝ) : ℝ≥0∞ := + sInf {t | ∃ m : ℕ, SufficientBudget n q s m ∧ t = (m : ℝ≥0∞)} + +/-- The real infimum is a minimum for n>0 (a nonempty finite set). -/ +noncomputable def minTraceTV (n : ℕ) (q : ℝ) : ℝ := + sInf {t | ∃ x y : Word n, x ≠ y ∧ t = traceTV q x y} + +end TraceReconstruction + +noncomputable section + +namespace TraceReconstruction + + + + +/-! ## Exact finite channel laws -/ + +theorem traceOfMask_length_le {n : ℕ} (x : Word n) (a : Mask n) : + (traceOfMask x a).length ≤ n := by + simpa [traceOfMask] using List.length_filter_le (fun i => a i) (List.finRange n) + +theorem mem_traceSpace_of_length_le {n : ℕ} (w : Trace) (h : w.length ≤ n) : + w ∈ traceSpace n := by + apply Finset.mem_biUnion.mpr + refine ⟨⟨w.length, Nat.lt_succ_of_le h⟩, Finset.mem_univ _, ?_⟩ + exact Finset.mem_image.mpr ⟨w.get, Finset.mem_univ _, List.ofFn_get w⟩ + +theorem length_le_of_mem_traceSpace {n : ℕ} {w : Trace} (h : w ∈ traceSpace n) : + w.length ≤ n := by + obtain ⟨k, _, hk⟩ := Finset.mem_biUnion.mp h + obtain ⟨x, _, rfl⟩ := Finset.mem_image.mp hk + simpa using Nat.le_of_lt_succ k.isLt + +@[simp] theorem mem_traceSpace {n : ℕ} {w : Trace} : + w ∈ traceSpace n ↔ w.length ≤ n := + ⟨length_le_of_mem_traceSpace, mem_traceSpace_of_length_le w⟩ + +theorem traceOfMask_mem {n : ℕ} (x : Word n) (a : Mask n) : + traceOfMask x a ∈ traceSpace n := + mem_traceSpace_of_length_le _ (traceOfMask_length_le x a) + +theorem maskWeight_nonneg {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) (a : Mask n) : + 0 ≤ maskWeight q a := by + apply Finset.prod_nonneg + intro i _ + split <;> linarith [hq.1, hq.2] + +@[simp] theorem sum_maskWeight {n : ℕ} (q : ℝ) : + ∑ a : Mask n, maskWeight q a = 1 := by + unfold maskWeight + change (∑ a : Fin n → Bool, ∏ i, (fun (_ : Fin n) (b : Bool) => + if b then 1 - q else q) i (a i)) = 1 + rw [← Fintype.prod_sum (fun (_ : Fin n) (b : Bool) => if b then 1 - q else q)] + simp + +theorem traceMass_nonneg {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) + (x : Word n) (w : Trace) : 0 ≤ traceMass q x w := by + apply Finset.sum_nonneg + intro a _ + split + · exact maskWeight_nonneg hq a + · exact le_rfl + +theorem traceMass_eq_zero_of_not_mem {n : ℕ} (q : ℝ) (x : Word n) (w : Trace) + (hw : w ∉ traceSpace n) : traceMass q x w = 0 := by + apply Finset.sum_eq_zero + intro a _ + have hne : traceOfMask x a ≠ w := by + intro h + exact hw (h ▸ traceOfMask_mem x a) + simp [hne] + +@[simp] theorem sum_traceMass {n : ℕ} (q : ℝ) (x : Word n) : + ∑ w ∈ traceSpace n, traceMass q x w = 1 := by + unfold traceMass + rw [Finset.sum_comm] + simp [traceOfMask_length_le] + +theorem traceTV_nonneg {n : ℕ} (q : ℝ) (x y : Word n) : 0 ≤ traceTV q x y := by + unfold traceTV + positivity + +@[simp] theorem traceTV_self {n : ℕ} (q : ℝ) (x : Word n) : traceTV q x x = 0 := by + simp [traceTV] + +theorem traceTV_comm {n : ℕ} (q : ℝ) (x y : Word n) : traceTV q x y = traceTV q y x := by + simp only [traceTV, abs_sub_comm] + +theorem traceTV_le_one {n : ℕ} {q : ℝ} (hq : q ∈ Set.Icc 0 1) (x y : Word n) : + traceTV q x y ≤ 1 := by + have h : ∑ w ∈ traceSpace n, |traceMass q x w - traceMass q y w| ≤ + ∑ w ∈ traceSpace n, (traceMass q x w + traceMass q y w) := by + apply Finset.sum_le_sum + intro w _ + exact abs_sub_le_iff.mpr + ⟨by linarith [traceMass_nonneg hq y w], by linarith [traceMass_nonneg hq x w]⟩ + rw [Finset.sum_add_distrib, sum_traceMass, sum_traceMass] at h + unfold traceTV + linarith + + +end TraceReconstruction + +namespace TraceReconstruction +namespace FiniteLaw +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +@[ext] theorem ext {P Q : FiniteLaw α} (h : P.mass = Q.mass) : P = Q := by + cases P with + | mk pm pn pt => cases Q with + | mk qm qn qt => cases h; rfl + +noncomputable def pure (a : α) : FiniteLaw α := by + classical + exact ⟨(fun b => if a = b then 1 else 0), + (fun b => by split_ifs <;> norm_num), by simp⟩ + +noncomputable def map (P : FiniteLaw α) (f : α → β) : FiniteLaw β := + P.bind (fun a => pure (f a)) + +theorem map_mass [DecidableEq β] (P : FiniteLaw α) (f : α → β) (b : β) : + (P.map f).mass b = ∑ a, if f a = b then P.mass a else 0 := by + classical + unfold map bind pure + simp only + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + +theorem expectation_map (P : FiniteLaw α) (f : α → β) (F : β → ℝ) : + (∑ b, (P.map f).mass b * F b) = ∑ a, P.mass a * F (f a) := by + classical + simp_rw [map_mass, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp + +theorem tv_map_le (P Q : FiniteLaw α) (f : α → β) : + tv (P.map f) (Q.map f) ≤ tv P Q := tv_bind_le P Q _ + +end FiniteLaw + +abbrev BoundedTrace (n : ℕ) := ↥(traceSpace n) + +def maskLaw {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) : FiniteLaw (Mask n) := + ⟨maskWeight q, maskWeight_nonneg hq, sum_maskWeight q⟩ + +def completeTraceLaw {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x : Word n) : + FiniteLaw (BoundedTrace n) where + mass w := traceMass q x w + nonneg w := traceMass_nonneg hq x w + total := by rw [Finset.sum_coe_sort]; exact sum_traceMass q x + +theorem completeTraceLaw_tv {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x y : Word n) : + (completeTraceLaw q hq x).tv (completeTraceLaw q hq y) = traceTV q x y := by + change (1 / 2 : ℝ) * (∑ w : BoundedTrace n, |traceMass q x w - traceMass q y w|) = _ + rw [Finset.sum_coe_sort (traceSpace n) (fun w => |traceMass q x w - traceMass q y w|)] + rfl + +theorem completeTraceLaw_mask {n : ℕ} (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x : Word n) : + completeTraceLaw q hq x = + (maskLaw q hq).map (fun a : Mask n => ⟨traceOfMask x a, traceOfMask_mem x a⟩) := by + apply FiniteLaw.ext + funext w + rw [FiniteLaw.map_mass] + unfold completeTraceLaw traceMass maskLaw + simp only + apply Finset.sum_congr rfl + intro a _ + rcases w with ⟨w, hw⟩ + simp only [Subtype.mk.injEq] + +theorem trace_expectation {n : ℕ} (q : ℝ) (x : Word n) (F : Trace → ℝ) : + (∑ w ∈ traceSpace n, traceMass q x w * F w) = + ∑ a : Mask n, maskWeight q a * F (traceOfMask x a) := by + classical + unfold traceMass + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp [traceOfMask_length_le] + +/-- Concatenation of exact binary inputs, not an encoded surrogate. -/ +def appendWord {n m : ℕ} (x : Word n) (y : Word m) : Word (n + m) := Fin.append x y + +theorem trace_filterMap {n : ℕ} (x : Word n) (a : Mask n) : + traceOfMask x a = (List.ofFn fun i => if a i then some (x i) else none).filterMap id := by + have hlist (l : List (Fin n)) : + (l.filter fun i => a i).map x = l.filterMap (fun i => if a i then some (x i) else none) := by + induction l with + | nil => rfl + | cons i l ih => cases hai : a i <;> simp [hai, ih] + unfold traceOfMask + rw [hlist] + have heq : (List.ofFn fun i => if a i then some (x i) else none) = + (List.finRange n).map (fun i => if a i then some (x i) else none) := by + rw [← List.ofFn_id, List.map_ofFn] + rfl + rw [heq, List.filterMap_map] + rfl + +theorem traceOfMask_append {n m : ℕ} (x : Word n) (y : Word m) + (a : Mask n) (b : Mask m) : + traceOfMask (appendWord x y) (Fin.append a b) = traceOfMask x a ++ traceOfMask y b := by + rw [trace_filterMap, List.ofFn_add, List.filterMap_append, trace_filterMap, trace_filterMap] + congr 2 <;> apply congrArg List.ofFn <;> funext i + · change (if Fin.append a b (Fin.castAdd m i) then some (Fin.append x y (Fin.castAdd m i)) else none) = _ + simp + · simp [appendWord] + +theorem maskWeight_append {n m : ℕ} (q : ℝ) (a : Mask n) (b : Mask m) : + maskWeight q (Fin.append a b) = maskWeight q a * maskWeight q b := by + unfold maskWeight + rw [Fin.prod_univ_add] + simp + +theorem concatenated_trace_expectation {n m : ℕ} (q : ℝ) (x : Word n) (y : Word m) + (F : Trace → ℝ) : + (∑ a : Mask (n + m), maskWeight q a * F (traceOfMask (appendWord x y) a)) = + ∑ a : Mask n, ∑ b : Mask m, + maskWeight q a * maskWeight q b * F (traceOfMask x a ++ traceOfMask y b) := by + rw [← (Fin.appendEquiv n m).sum_comp] + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + change maskWeight q (Fin.append a b) * F (traceOfMask (appendWord x y) (Fin.append a b)) = _ + rw [maskWeight_append, traceOfMask_append] + +end TraceReconstruction + +namespace TraceReconstruction + +/-- The four complete traces possible from the ordinary primitive `01`. -/ +abbrev PrimitiveMark := Fin 4 + +def primitiveOutput : PrimitiveMark → List Bool := ![[], [false], [true], [false, true]] +def ordinaryPrimitiveMass (q : ℝ) : PrimitiveMark → ℝ := + ![q ^ 2, q * (1 - q), q * (1 - q), (1 - q) ^ 2] +def defectPrimitiveMass (q : ℝ) : PrimitiveMark → ℝ := ![q, 0, 1 - q, 0] +def primitiveErasure (q : ℝ) : ℝ := q ^ 2 / 2 + +def primitiveMarkMass (q : ℝ) (isDefect : Bool) (z : PrimitiveMark) : ℝ := + ((if isDefect then defectPrimitiveMass q z else ordinaryPrimitiveMass q z) - + if z = 0 then primitiveErasure q else 0) / (1 - primitiveErasure q) + +theorem primitive_retain_pos {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : + 0 < 1 - primitiveErasure q := by + unfold primitiveErasure + nlinarith [hq.1, hq.2] + +theorem primitiveMarkMass_nonneg {q : ℝ} (hq : q ∈ Set.Ioo 0 1) + (b : Bool) (z : PrimitiveMark) : 0 ≤ primitiveMarkMass q b z := by + apply div_nonneg _ (primitive_retain_pos hq).le + cases b <;> fin_cases z <;> + simp [ordinaryPrimitiveMass, defectPrimitiveMass, primitiveErasure] <;> + nlinarith [hq.1, hq.2] + +theorem primitiveMarkMass_sum {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (b : Bool) : + ∑ z : PrimitiveMark, primitiveMarkMass q b z = 1 := by + have hd := ne_of_gt (primitive_retain_pos hq) + unfold primitiveMarkMass + rw [← Finset.sum_div] + apply (div_eq_one_iff_eq hd).mpr + cases b <;> simp [ordinaryPrimitiveMass, defectPrimitiveMass, primitiveErasure, Fin.sum_univ_succ] + all_goals ring + +def primitiveMarkLaw (q : ℝ) (hq : q ∈ Set.Ioo 0 1) (b : Bool) : FiniteLaw PrimitiveMark := + ⟨primitiveMarkMass q b, primitiveMarkMass_nonneg hq b, primitiveMarkMass_sum hq b⟩ + +/-- Emitting the conditional mark, or silently erasing the block, gives +exactly the ordinary primitive-output probabilities. Silent erasure and an +emitted empty mark are distinct latent events. -/ +theorem primitiveMark_simulation {q : ℝ} (hq : q ∈ Set.Ioo 0 1) + (b : Bool) (z : PrimitiveMark) : + (if z = 0 then primitiveErasure q else 0) + + (1 - primitiveErasure q) * primitiveMarkMass q b z = + if b then defectPrimitiveMass q z else ordinaryPrimitiveMass q z := by + unfold primitiveMarkMass + rw [mul_div_cancel₀ _ (ne_of_gt (primitive_retain_pos hq))] + ring + +def primitiveScore (q : ℝ) : PrimitiveMark → ℝ := ![2 / q - 2, -1, 1 / q - 1, -1] + +theorem primitive_score_identity {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (z : PrimitiveMark) : + primitiveMarkMass q true z = primitiveMarkMass q false z * (1 + primitiveScore q z) := by + have hq0 := ne_of_gt hq.1 + have hd := ne_of_gt (primitive_retain_pos hq) + fin_cases z <;> + simp [primitiveMarkMass, ordinaryPrimitiveMass, defectPrimitiveMass, primitiveScore, primitiveErasure] <;> + field_simp + all_goals ring + +theorem primitive_score_centered {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : + ∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z = 0 := by + have hi := primitiveMarkMass_sum hq true + simp_rw [primitive_score_identity hq, mul_add, mul_one, Finset.sum_add_distrib, + primitiveMarkMass_sum hq false] at hi + linarith + +theorem primitive_score_bound {q : ℝ} (hq : q ∈ Set.Ioo 0 1) (z : PrimitiveMark) : + |primitiveScore q z| ≤ 2 / q := by + have hi : 1 ≤ 1 / q := (le_div_iff₀ hq.1).mpr (by linarith [hq.2]) + simp only [one_div] at hi + have he : 2 / q = 2 * (1 / q) := by ring + fin_cases z <;> simp [primitiveScore, abs_le, he] <;> (try constructor) <;> linarith + +theorem primitive_score_variance_exact {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : + (∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z ^ 2) = + (1 / q - 2 * q + q ^ 2) / (1 - q ^ 2 / 2) := by + have hq0 := ne_of_gt hq.1 + have hd := ne_of_gt (primitive_retain_pos hq) + simp only [primitiveMarkMass, primitiveScore, ordinaryPrimitiveMass, primitiveErasure, + Bool.false_eq_true, ↓reduceIte] + simp [Fin.sum_univ_succ] + field_simp + ring + +theorem primitive_score_variance_le {q : ℝ} (hq : q ∈ Set.Ioo 0 1) : + (∑ z : PrimitiveMark, primitiveMarkMass q false z * primitiveScore q z ^ 2) ≤ 2 / q := by + rw [primitive_score_variance_exact hq] + have hd : 0 < 1 - q ^ 2 / 2 := primitive_retain_pos hq + apply (div_le_div_iff₀ hd hq.1).mpr + rw [add_mul, sub_mul, one_div_mul_cancel (ne_of_gt hq.1)] + have hpow : q ^ 3 ≤ q ^ 2 := by + calc + _ = q ^ 2 * q := by ring + _ ≤ q ^ 2 * 1 := mul_le_mul_of_nonneg_left hq.2.le (sq_nonneg _) + _ = _ := mul_one _ + nlinarith only [hpow, sq_nonneg q] + +end TraceReconstruction + +namespace TraceReconstruction +def ordinaryRun : ℕ → List Bool + | 0 => [] + | m + 1 => false :: true :: ordinaryRun m + +@[simp] theorem ordinaryRun_length (m : ℕ) : (ordinaryRun m).length = 2 * m := by + induction m with + | zero => rfl + | succ m ih => simp only [ordinaryRun, List.length_cons, ih]; omega + +theorem ordinaryRun_add (a b : ℕ) : ordinaryRun (a + b) = ordinaryRun a ++ ordinaryRun b := by + induction a with + | zero => simp [ordinaryRun] + | succ a ih => simp [Nat.succ_add, ordinaryRun, ih] + +/-- A period of m primitives with its unique `1` defect at zero-based slot d. -/ +def initialPeriod (m d : ℕ) : List Bool := + ordinaryRun d ++ [true] ++ ordinaryRun (m - 1 - d) + +theorem initialPeriod_length {m d : ℕ} (hd : d < m) : + (initialPeriod m d).length = 2 * m - 1 := by + simp only [initialPeriod, List.length_append, ordinaryRun_length, List.length_singleton] + omega + +/-- Distinct defect slots differ before either period ends, independently of future text. -/ +theorem initialPeriod_tail_ne {m d e : ℕ} (hde : d < e) (he : e < m) + (u v : List Bool) : initialPeriod m d ++ u ≠ initialPeriod m e ++ v := by + obtain ⟨a, ha⟩ := Nat.exists_eq_add_of_le (show d + 1 ≤ e by omega) + subst e + unfold initialPeriod + rw [Nat.add_assoc d 1 a, ordinaryRun_add d (1 + a)] + simp only [Nat.add_assoc] at * + simp only [Nat.one_add, ordinaryRun, List.append_assoc, List.cons_append, List.nil_append] + intro h + have hh := List.append_cancel_left h + have hf := congrArg List.head? hh + simp only [List.head?_cons, Option.some.injEq] at hf + cases hf + +theorem initialPeriod_injective (m : ℕ) : + Function.Injective (fun d : Fin m => initialPeriod m d) := by + intro d e h + by_contra hne + have hv : d.val ≠ e.val := fun hv => hne (Fin.ext hv) + rcases lt_or_gt_of_ne hv with hlt | hgt + · exact initialPeriod_tail_ne hlt e.isLt [] [] (by simpa using h) + · exact initialPeriod_tail_ne hgt d.isLt [] [] (by simpa using h.symm) + +def periodString (m P : ℕ) (d : Fin P → Fin m) : List Bool := + (List.ofFn (fun i => initialPeriod m (d i))).flatten + +theorem periodString_cons (m P : ℕ) (d : Fin (P + 1) → Fin m) : + periodString m (P + 1) d = initialPeriod m (d 0) ++ + periodString m P (fun i => d i.succ) := by + simp only [periodString, List.ofFn_succ, List.flatten_cons] + +theorem periodString_length (m P : ℕ) (d : Fin P → Fin m) : + (periodString m P d).length = P * (2 * m - 1) := by + induction P with + | zero => simp [periodString] + | succ P ih => + rw [periodString_cons, List.length_append, initialPeriod_length (d 0).isLt, ih] + rw [Nat.add_mul, one_mul, Nat.add_comm] + +theorem periodString_injective (m P : ℕ) : Function.Injective (periodString m P) := by + induction P with + | zero => intro d e _; exact Subsingleton.elim _ _ + | succ P ih => + intro d e h + rw [periodString_cons, periodString_cons] at h + have hz : d 0 = e 0 := by + by_contra hne + have hv : (d 0).val ≠ (e 0).val := fun hv => hne (Fin.ext hv) + rcases lt_or_gt_of_ne hv with hlt | hgt + · exact initialPeriod_tail_ne hlt (e 0).isLt _ _ h + · exact initialPeriod_tail_ne hgt (d 0).isLt _ _ h.symm + rw [hz] at h + have ht := ih (List.append_cancel_left h) + funext i + refine Fin.cases hz (fun j => congrFun ht j) i +end TraceReconstruction + +namespace TraceReconstruction +/-- Uniformly sized binary atoms concatenated without boundary marks. -/ +def atomString (P : ℕ) (w : Bool → List Bool) (θ : Fin P → Bool) : List Bool := + (List.ofFn (fun i => w (θ i))).flatten + +theorem atomString_cons (P : ℕ) (w : Bool → List Bool) (θ : Fin (P + 1) → Bool) : + atomString (P + 1) w θ = w (θ 0) ++ atomString P w (fun i => θ i.succ) := by + simp only [atomString, List.ofFn_succ, List.flatten_cons] + +theorem atomString_length (P S : ℕ) (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) + (θ : Fin P → Bool) : (atomString P w θ).length = P * S := by + induction P with + | zero => simp [atomString] + | succ P ih => rw [atomString_cons, List.length_append, hw, ih, Nat.add_mul, one_mul, Nat.add_comm] + +theorem atomString_injective (P S : ℕ) (w : Bool → List Bool) + (hw : ∀ b, (w b).length = S) (hinj : Function.Injective w) : + Function.Injective (atomString P w) := by + induction P with + | zero => intro θ φ _; exact Subsingleton.elim _ _ + | succ P ih => + intro θ φ h + rw [atomString_cons, atomString_cons] at h + have hh := congrArg (List.take S) h + have hθ (u : List Bool) (b : Bool) : (w b ++ u).take S = w b := by + rw [← hw b, List.take_left] + rw [hθ, hθ] at hh + have hz := hinj hh + rw [hz] at h + have ht := ih (List.append_cancel_left h) + funext i + exact Fin.cases hz (fun j => congrFun ht j) i + +/-- Zero-based notation for the source complementary template; `true` is minus. +The motif itself is fixed independently of the hypothesis. -/ +def templateType (P a L : ℕ) (sign : Fin L → Bool) (τ : Bool) (i : Fin P) : Bool := + if h : a ≤ i.val ∧ i.val < a + L then xor τ (sign ⟨i.val - a, by omega⟩) else false + +theorem templateType_at (P a L : ℕ) (sign : Fin L → Bool) (τ : Bool) + (hL : 0 < L) (ha : a < P) : + templateType P a L sign τ ⟨a, ha⟩ = xor τ (sign ⟨0, hL⟩) := by + simp [templateType, hL] + +theorem templateType_injective (P a L : ℕ) (sign : Fin L → Bool) + (hL : 0 < L) (ha : a < P) : + Function.Injective (templateType P a L sign) := by + intro τ υ h + have he := congrFun h ⟨a, ha⟩ + rw [templateType_at P a L sign τ hL ha, templateType_at P a L sign υ hL ha] at he + cases hs : sign ⟨0, hL⟩ <;> cases τ <;> cases υ <;> simp_all + +def complementaryWords (P a L : ℕ) (sign : Fin L → Bool) (w : Bool → List Bool) + (τ : Bool) : List Bool := atomString P w (templateType P a L sign τ) + +theorem complementaryWords_length (P a L S : ℕ) (sign : Fin L → Bool) + (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) (τ : Bool) : + (complementaryWords P a L sign w τ).length = P * S := atomString_length P S w hw _ + +theorem complementaryWords_injective (P a L S : ℕ) (sign : Fin L → Bool) + (w : Bool → List Bool) (hw : ∀ b, (w b).length = S) (hinj : Function.Injective w) + (hL : 0 < L) (ha : a < P) : Function.Injective (complementaryWords P a L sign w) := + (atomString_injective P S w hw hinj).comp (templateType_injective P a L sign hL ha) +end TraceReconstruction + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Oracles.lean b/lean/OAI/Probability/TraceReconstruction/Oracles.lean index 80264348b00a626b676fb44fe8ab7db8cb9d895c..43bbd5da98fde82637d496ac7c7e7abb7374e30e 100644 --- a/lean/OAI/Probability/TraceReconstruction/Oracles.lean +++ b/lean/OAI/Probability/TraceReconstruction/Oracles.lean @@ -1,1697 +1,1697 @@ -import OAI.Probability.TraceReconstruction.InitialMoments - -namespace OAI - -/-! -# Oracles - -TV kernels and trace simulation, anchor costs, counted primitives, common-part lifting, concrete oracle pairs, and paired-flag metadata. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction.FiniteLaw -open scoped Classical -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -@[ext] theorem law_ext {P Q : FiniteLaw α} (h : ∀a,P.mass a=Q.mass a) : P=Q := by - cases P; cases Q; congr; exact funext h - -theorem tv_self (P : FiniteLaw α) : P.tv P=0 := by simp [tv] - -theorem tv_le_one (P Q : FiniteLaw α) : P.tv Q≤1 := by - unfold tv - have h : (∑a,|P.mass a-Q.mass a|)≤2 := by - calc - _ ≤ ∑a, (P.mass a+Q.mass a) := Finset.sum_le_sum (fun a _ => - (abs_sub (P.mass a) (Q.mass a)).trans_eq (by rw [abs_of_nonneg (P.nonneg a),abs_of_nonneg (Q.nonneg a)])) - _ = 2 := by rw [Finset.sum_add_distrib,P.total,Q.total]; norm_num - linarith - -theorem expect_bind (P : FiniteLaw α) (K : α → FiniteLaw β) (f : β → ℝ) : - (P.bind K).expect f=P.expect (fun a => (K a).expect f) := by - unfold expect bind - simp_rw [Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - ring - -theorem bind_assoc (P : FiniteLaw α) (K : α → FiniteLaw β) (L : β → FiniteLaw γ) : - (P.bind K).bind L=P.bind (fun a => (K a).bind L) := by - apply law_ext - intro c - simp only [bind,Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - ring - -theorem tv_bind_kernel_le (P : FiniteLaw α) (K L : α → FiniteLaw β) : - (P.bind K).tv (P.bind L) ≤ P.expect (fun a => (K a).tv (L a)) := by - unfold tv bind expect - simp only - calc - _ = (1/2:ℝ)*∑b, |∑a,P.mass a*((K a).mass b-(L a).mass b)| := by - congr 1 - apply Finset.sum_congr rfl - intro b _ - congr 1 - rw [← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro a _ - ring - _ ≤ (1/2:ℝ)*∑b,∑a,P.mass a*|(K a).mass b-(L a).mass b| := by - apply mul_le_mul_of_nonneg_left _ (by norm_num) - apply Finset.sum_le_sum - intro b _ - simpa only [abs_mul,abs_of_nonneg (P.nonneg _)] using - Finset.abs_sum_le_sum_abs (fun a => P.mass a*((K a).mass b-(L a).mass b)) Finset.univ - _ = _ := by - rw [Finset.sum_comm,Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - rw [← Finset.mul_sum] - ring - -/-- An invalid layout is charged only its unconditional probability. -/ -theorem tv_bind_fit_le (P : FiniteLaw α) (K L : α → FiniteLaw β) - (good : α → Prop) [DecidablePred good] (E : ℝ) - (hfit : ∀a,good a → (K a).tv (L a)≤E) : - (P.bind K).tv (P.bind L) ≤ P.expect (fun a => if good a then E else 1) := by - apply (tv_bind_kernel_le P K L).trans - apply expect_mono - intro a - split_ifs with h - · exact hfit a h - · exact tv_le_one _ _ - -theorem tv_prod_eq_left (P Q : FiniteLaw α) (R : FiniteLaw β) : - (P.prod R).tv (Q.prod R)=P.tv Q := by - unfold tv prod - congr 1 - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro a _ - simp_rw [← sub_mul,abs_mul,abs_of_nonneg (R.nonneg _),← Finset.mul_sum,R.total,mul_one] - -theorem tv_prod_eq_right (P : FiniteLaw α) (Q R : FiniteLaw β) : - (P.prod Q).tv (P.prod R)=Q.tv R := by - unfold tv prod - congr 1 - rw [Fintype.sum_prod_type] - simp_rw [← mul_sub,abs_mul,abs_of_nonneg (P.nonneg _),← Finset.mul_sum] - rw [← Finset.sum_mul,P.total,one_mul] - -theorem tv_prod_le (P Q : FiniteLaw α) (R S : FiniteLaw β) : - (P.prod R).tv (Q.prod S) ≤ P.tv Q+R.tv S := by - have H := tv_triangle (P.prod R) (Q.prod R) (Q.prod S) - rwa [tv_prod_eq_left,tv_prod_eq_right] at H - -end TraceReconstruction.FiniteLaw - - -noncomputable section -namespace TraceReconstruction.FiniteLaw -open scoped Classical -variable {α : Type*} [Fintype α] - -theorem coordinateProduct_succ_tv {n : ℕ} (P Q : Fin (n+1) → FiniteLaw α) : - (coordinateProduct P).tv (coordinateProduct Q) = - ((P 0).prod (coordinateProduct (fun i => P i.succ))).tv - ((Q 0).prod (coordinateProduct (fun i => Q i.succ))) := by - change (1/2:ℝ)*(∑x : Fin (n+1) → α, |(∏i,(P i).mass (x i))-(∏i,(Q i).mass (x i))|)= - (1/2:ℝ)*∑x : α × (Fin n → α), |(P 0).mass x.1*(∏i,(P i.succ).mass (x.2 i))-(Q 0).mass x.1*(∏i,(Q i.succ).mass (x.2 i))| - congr 1 - rw [← (Fin.consEquiv (fun _ : Fin (n+1) => α)).sum_comp] - apply Finset.sum_congr rfl - intro x _ - simp only [Fin.consEquiv,Equiv.coe_fn_mk,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] - -theorem tv_coordinateProduct_le {n : ℕ} (P Q : Fin n → FiniteLaw α) : - (coordinateProduct P).tv (coordinateProduct Q) ≤ ∑i, (P i).tv (Q i) := by - induction n with - | zero => simp [tv,coordinateProduct] - | succ n ih => - rw [coordinateProduct_succ_tv,Fin.sum_univ_succ] - exact (tv_prod_le _ _ _ _).trans (by linarith [ih (fun i => P i.succ) (fun i => Q i.succ)]) - -theorem expect_coordinateProduct_succ {n : ℕ} (P : Fin (n+1) → FiniteLaw α) - (F : (Fin (n+1) → α) → ℝ) : - (coordinateProduct P).expect F = - (P 0).expect (fun a => (coordinateProduct (fun i => P i.succ)).expect - (fun x => F (Fin.cons a x))) := by - change (∑x : Fin (n+1) → α, (∏i,(P i).mass (x i))*F x)= - ∑a : α, (P 0).mass a*(∑x : Fin n → α, (∏i,(P i.succ).mass (x i))*F (Fin.cons a x)) - rw [← (Fin.consEquiv (fun _ : Fin (n+1) => α)).sum_comp,Fintype.sum_prod_type] - simp only [Fin.consEquiv,Equiv.coe_fn_mk,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] - simp_rw [Finset.mul_sum,mul_assoc] - -end TraceReconstruction.FiniteLaw - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem FiniteLaw.expect_sub {α : Type*} [Fintype α] (P : FiniteLaw α) - (F G : α → ℝ) : P.expect (fun a => F a-G a)=P.expect F-P.expect G := by - simp only [FiniteLaw.expect,mul_sub,Finset.sum_sub_distrib] - -theorem FiniteLaw.abs_expect_le {α : Type*} [Fintype α] (P : FiniteLaw α) (F : α → ℝ) : - |P.expect F|≤P.expect (fun a => |F a|) := by - simpa only [FiniteLaw.expect,abs_mul,abs_of_nonneg (P.nonneg _)] using - Finset.abs_sum_le_sum_abs (fun a => P.mass a*F a) Finset.univ - -/-- A finite auxiliary observation, decoded by a fixed function, simulates the -usual deletion channel on a literal binary word. Test functions range over the -observable traces only, never latent boundaries. -/ -def SimulatesTrace {α : Type*} [Fintype α] (q : ℝ) (P : FiniteLaw α) - (decode : α → List Bool) (w : List Bool) : Prop := - ∀ F : List Bool → ℝ, P.expect (fun a => F (decode a))=listDeletionExpectation q w F - -def ApproximatesTrace {α : Type*} [Fintype α] (q : ℝ) (P : FiniteLaw α) - (decode : α → List Bool) (w : List Bool) (E : ℝ) : Prop := - ∀ F : List Bool → ℝ, (∀t,F t∈Set.Icc 0 1) → - |P.expect (fun a => F (decode a))-listDeletionExpectation q w F|≤E - -theorem listDeletionExpectation_const (q c : ℝ) (w : List Bool) : - listDeletionExpectation q w (fun _ => c)=c := by - induction w with - | nil => rfl - | cons b w ih => simp only [listDeletionExpectation,ih]; ring - -theorem listDeletionExpectation_linear (q : ℝ) (w : List Bool) - (a b : ℝ) (F G : List Bool → ℝ) : - listDeletionExpectation q w (fun t => a*F t+b*G t)= - a*listDeletionExpectation q w F+b*listDeletionExpectation q w G := by - induction w generalizing F G with - | nil => rfl - | cons c w ih => simp only [listDeletionExpectation,ih]; ring - -theorem listDeletionExpectation_mono {q : ℝ} (hq : q∈Set.Icc 0 1) - (w : List Bool) {F G : List Bool → ℝ} (h : ∀t,F t≤G t) : - listDeletionExpectation q w F≤listDeletionExpectation q w G := by - induction w generalizing F G with - | nil => exact h [] - | cons b w ih => - exact add_le_add (mul_le_mul_of_nonneg_left (ih h) hq.1) - (mul_le_mul_of_nonneg_left (ih (fun t => h (b::t))) (sub_nonneg.mpr hq.2)) - -theorem listDeletionExpectation_range {q : ℝ} (hq : q∈Set.Icc 0 1) - (w : List Bool) (F : List Bool → ℝ) (hF : ∀t,F t∈Set.Icc 0 1) : - listDeletionExpectation q w F∈Set.Icc 0 1 := by - constructor - · simpa only [listDeletionExpectation_const] using - listDeletionExpectation_mono hq w (fun t => (hF t).1) - · simpa only [listDeletionExpectation_const] using - listDeletionExpectation_mono hq w (fun t => (hF t).2) - -theorem listDeletionExpectation_sum {α : Type*} [Fintype α] (q : ℝ) - (w : List Bool) (F : α → List Bool → ℝ) : - listDeletionExpectation q w (fun t => ∑a,F a t)= - ∑a,listDeletionExpectation q w (F a) := by - induction w generalizing F with - | nil => rfl - | cons b w ih => - simp only [listDeletionExpectation,ih,Finset.mul_sum,Finset.sum_add_distrib] - -theorem FiniteLaw.expect_listDeletionExpectation {α : Type*} [Fintype α] - (P : FiniteLaw α) (q : ℝ) (w : List Bool) (F : α → List Bool → ℝ) : - P.expect (fun a => listDeletionExpectation q w (F a))= - listDeletionExpectation q w (fun t => P.expect (fun a => F a t)) := by - unfold FiniteLaw.expect - rw [listDeletionExpectation_sum] - apply Finset.sum_congr rfl - intro a _ - have H := listDeletionExpectation_linear q w (P.mass a) 0 (F a) (fun _ => 0) - simpa only [zero_mul,add_zero] using H.symm - -theorem SimulatesTrace.append {α β : Type*} [Fintype α] [Fintype β] - {q : ℝ} {P : FiniteLaw α} {Q : FiniteLaw β} {f : α → List Bool} {g : β → List Bool} - {x y : List Bool} (hP : SimulatesTrace q P f x) (hQ : SimulatesTrace q Q g y) : - SimulatesTrace q (P.prod Q) (fun a => f a.1++g a.2) (x++y) := by - intro F - rw [FiniteLaw.expect_prod,listDeletionExpectation_append] - change P.expect (fun a => Q.expect (fun b => F (f a++g b)))=_ - unfold SimulatesTrace at hP hQ - calc - _ = P.expect (fun a => listDeletionExpectation q y (fun t => F (f a++t))) := - congrArg P.expect (funext fun a => hQ (fun t => F (f a++t))) - _ = _ := hP (fun t => listDeletionExpectation q y (fun u => F (t++u))) - -theorem SimulatesTrace.approximate {α : Type*} [Fintype α] - {q : ℝ} {P : FiniteLaw α} {f : α → List Bool} {w : List Bool} - (h : SimulatesTrace q P f w) : ApproximatesTrace q P f w 0 := by - intro F _ - rw [h,sub_self,abs_zero] - -theorem ApproximatesTrace.append {α β : Type*} [Fintype α] [Fintype β] - {q : ℝ} (hq : q∈Set.Icc 0 1) {P : FiniteLaw α} {Q : FiniteLaw β} - {f : α → List Bool} {g : β → List Bool} {x y : List Bool} {E D : ℝ} - (hP : ApproximatesTrace q P f x E) (hQ : ApproximatesTrace q Q g y D) : - ApproximatesTrace q (P.prod Q) (fun a => f a.1++g a.2) (x++y) (E+D) := by - intro F hF - rw [FiniteLaw.expect_prod,listDeletionExpectation_append] - let H : List Bool → ℝ := fun t => listDeletionExpectation q y (fun u => F (t++u)) - have hH : ∀t,H t∈Set.Icc 0 1 := fun t => listDeletionExpectation_range hq y _ (fun u => hF (t++u)) - have h1 := hP H hH - have h2 : |P.expect (fun a => Q.expect (fun b => F (f a++g b)))-P.expect (fun a => H (f a))|≤D := by - rw [← FiniteLaw.expect_sub] - calc - _ ≤ P.expect (fun a => |Q.expect (fun b => F (f a++g b))-H (f a)|) := FiniteLaw.abs_expect_le _ _ - _ ≤ P.expect (fun _ => D) := FiniteLaw.expect_mono _ (fun a => hQ _ (fun t => hF (f a++t))) - _ = D := FiniteLaw.expect_const _ _ - exact (abs_sub_le _ _ _).trans (by linarith only [h1,h2]) - -/-- Any randomized partition into exactly the same literal word gives exactly -its usual trace after boundaries are forgotten. No fit conditioning occurs. -/ -theorem SimulatesTrace.random_partition {α Ω : Type*} [Fintype α] [Fintype Ω] - {q : ℝ} (P : FiniteLaw Ω) (K : Ω → FiniteLaw α) (decode : α → List Bool) - (w : List Bool) (h : ∀ω,SimulatesTrace q (K ω) decode w) : - SimulatesTrace q (P.bind K) decode w := by - intro F - rw [FiniteLaw.expect_bind] - unfold SimulatesTrace at h - simp_rw [h] - exact FiniteLaw.expect_const _ _ - -/-- A failed deterministic layout is charged its unconditional probability; -the conditional law on all metadata, not a fit-conditioned law, is used. -/ -theorem ApproximatesTrace.random_partition {α Ω : Type*} [Fintype α] [Fintype Ω] - {q : ℝ} (hq : q∈Set.Icc 0 1) (P : FiniteLaw Ω) (K : Ω → FiniteLaw α) - (decode : α → List Bool) (w : List Bool) (good : Ω → Prop) [DecidablePred good] - (E : ℝ) (h : ∀ω,good ω → ApproximatesTrace q (K ω) decode w E) : - ApproximatesTrace q (P.bind K) decode w (P.expect (fun ω => if good ω then E else 1)) := by - intro F hF - rw [FiniteLaw.expect_bind,← FiniteLaw.expect_const P (listDeletionExpectation q w F),← FiniteLaw.expect_sub] - apply (FiniteLaw.abs_expect_le _ _).trans - apply FiniteLaw.expect_mono - intro ω - split_ifs with hgood - · exact h ω hgood F hF - · have hc := listDeletionExpectation_range hq w F hF - have hn := FiniteLaw.expect_mono (K ω) (fun a => (hF (decode a)).1) - have hu := FiniteLaw.expect_mono (K ω) (fun a => (hF (decode a)).2) - rw [FiniteLaw.expect_const] at hn hu - exact abs_le.mpr ⟨by linarith [hc.2],by linarith [hc.1]⟩ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Admissible close child labels, without relaxing any plateau restrictions -on the anchor. An arbitrary finite label domain is retained. -/ -def closeLabels (A : Finset ℤ) (L : ℕ) (a : ℤ) : Finset ℤ := - A.filter (fun c => |c-a| < (L:ℤ)) - -theorem closeLabels_card (A : Finset ℤ) (L : ℕ) (a : ℤ) : - (closeLabels A L a).card ≤ 2*L := by - have hsub : closeLabels A L a ⊆ Finset.Ioo (a-(L:ℤ)) (a+(L:ℤ)) := by - intro c hc - have h := abs_lt.mp ((Finset.mem_filter.mp hc).2) - exact Finset.mem_Ioo.mpr ⟨by omega,by omega⟩ - have H := Finset.card_le_card hsub - rw [Int.card_Ioo] at H - omega - -/-- Root anchor and close-child energy. This keeps the actual labels finite, -including any additional source plateau cutoff. -/ -theorem root_anchor_energy (n L : ℕ) (A B : Finset ℤ) (c : ℤ) : - (∑ a∈A, ∑ _d∈closeLabels B L a, windowKernel n L (a-c)^2) ≤ - 2*L^3*binomialBound n := by - calc - _ ≤ ∑a∈A, (2*L:ℝ)*windowKernel n L (a-c)^2 := by - apply Finset.sum_le_sum - intro a _ - simp only [Finset.sum_const,nsmul_eq_mul] - exact mul_le_mul_of_nonneg_right (by exact_mod_cast closeLabels_card B L a) (sq_nonneg _) - _ = (2*L:ℝ)*(∑a∈A,windowKernel n L (a-c)^2) := by rw [Finset.mul_sum] - _ ≤ (2*L:ℝ)*(L^2*binomialBound n) := - mul_le_mul_of_nonneg_left (windowKernel_energy n L A c) (by positivity) - _ = _ := by ring - -/-- The shared global jitter stays in the joint kernel until after squaring. -The two close labels cost only (2L)^2, uniformly in parent labels. -/ -theorem sibling_anchor_energy (g n₁ n₂ L : ℕ) (A B C D : Finset ℤ) (c₁ c₂ : ℤ) : - (∑ a∈A, ∑ b∈B, ∑ _c∈closeLabels C L a, ∑ _d∈closeLabels D L b, - jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2) ≤ - 4*L^6*binomialBound g*binomialBound n₂ := by - calc - _ ≤ ∑a∈A, ∑b∈B, (2*L:ℝ)^2*jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2 := by - apply Finset.sum_le_sum - intro a _ - apply Finset.sum_le_sum - intro b _ - simp only [Finset.sum_const,nsmul_eq_mul] - have hc : ((closeLabels C L a).card:ℝ)≤2*L := by exact_mod_cast closeLabels_card C L a - have hd : ((closeLabels D L b).card:ℝ)≤2*L := by exact_mod_cast closeLabels_card D L b - have hm := mul_le_mul hc hd (by positivity) (by positivity : (0:ℝ)≤2*L) - rw [mul_assoc] at hm - nlinarith [mul_le_mul_of_nonneg_right hm (sq_nonneg (jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)))] - _ = (2*L:ℝ)^2*(∑a∈A,∑b∈B,jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2) := by - simp_rw [Finset.mul_sum] - _ ≤ (2*L:ℝ)^2*(L^4*binomialBound g*binomialBound n₂) := - mul_le_mul_of_nonneg_left (jointWindowKernel_energy g n₁ n₂ L A B c₁ c₂) (by positivity) - _ = _ := by ring - -/-- Exact bottom-up summation of any finite binary anchor model. The state -contains its actual index path, so group-dependent kernels are allowed. -/ -def binaryTreeSum {α : Type*} [Fintype α] (K : ℕ → α → α × α → ℝ) : ℕ → α → ℝ - | 0, _ => 1 - | n+1, a => ∑b, K n a b*binaryTreeSum K n b.1*binaryTreeSum K n b.2 - -def binaryTreeBudget (C : ℕ → ℝ) : ℕ → ℝ - | 0 => 1 - | n+1 => C n*(binaryTreeBudget C n)^2 - -theorem binaryTreeBudget_nonneg (C : ℕ → ℝ) (hC : ∀n,0≤C n) (n : ℕ) : - 0≤binaryTreeBudget C n := by - cases n with - | zero => norm_num [binaryTreeBudget] - | succ n => exact mul_nonneg (hC n) (sq_nonneg _) - -theorem binaryTreeSum_nonneg {α : Type*} [Fintype α] - (K : ℕ → α → α × α → ℝ) (hK : ∀n a b,0≤K n a b) (n : ℕ) (a : α) : - 0≤binaryTreeSum K n a := by - induction n generalizing a with - | zero => norm_num [binaryTreeSum] - | succ n ih => exact Finset.sum_nonneg (fun b _ => mul_nonneg (mul_nonneg (hK n a b) (ih b.1)) (ih b.2)) - -/-- Uniform local anchor square sums multiply without decoupling the two -correlated offsets of a sibling group. Domain/plateau indicators can be -included in K and are never removed by conditioning. -/ -theorem binaryTreeSum_le {α : Type*} [Fintype α] - (K : ℕ → α → α × α → ℝ) (hK : ∀n a b,0≤K n a b) - (C : ℕ → ℝ) (hC : ∀n,0≤C n) (hlocal : ∀n a, (∑b,K n a b)≤C n) - (n : ℕ) (a : α) : binaryTreeSum K n a≤binaryTreeBudget C n := by - induction n generalizing a with - | zero => rfl - | succ n ih => - calc - _ ≤ ∑b, K n a b*(binaryTreeBudget C n)^2 := by - apply Finset.sum_le_sum - intro b _ - rw [mul_assoc,pow_two] - exact mul_le_mul_of_nonneg_left (mul_le_mul (ih b.1) (ih b.2) - (binaryTreeSum_nonneg K hK n b.2) (binaryTreeBudget_nonneg C hC n)) (hK n a b) - _ = (∑b,K n a b)*(binaryTreeBudget C n)^2 := by rw [Finset.sum_mul] - _ ≤ C n*(binaryTreeBudget C n)^2 := mul_le_mul_of_nonneg_right (hlocal n a) (sq_nonneg _) - _ = _ := rfl - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem hypergeomMass_middle_sq (V M m v : ℕ) {p : ℝ} - (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) - (hN : 16≤V+M) (hm : m≤V+M) (hmean : (m:ℝ)=(V+M:ℕ)*p) : - hypergeomMass V M m v^2≤4096/((M:ℝ)+1) := by - have hp' : p∈Set.Ioo (0:ℝ) 1 := by constructor <;> linarith [hp.1,hp.2] - have hpp : (1/8:ℝ)≤p*(1-p) := by nlinarith [sq_nonneg (p-1/2),mul_nonneg (sub_nonneg.mpr hp.1) (sub_nonneg.mpr hp.2)] - have hNr : (16:ℝ)≤(V:ℝ)+M := by exact_mod_cast hN - have hVr : (M:ℝ)≤V := by exact_mod_cast hMV - have hv : 1≤(V+M:ℕ)*p*(1-p) := by - push_cast - nlinarith [Nat.cast_nonneg (α:=ℝ) V,Nat.cast_nonneg (α:=ℝ) M] - have H := hypergeomMass_sq_upper V M m v hp' hm hmean hv - apply H.trans - have hd : 0<((V:ℝ)+1)*((M:ℝ)+1)*p*(1-p) := by positivity [hp'.1,sub_pos.mpr hp'.2] - apply (div_le_iff₀ hd).2 - have hM : 0<(M:ℝ)+1 := by positivity - have he : 4096/((M:ℝ)+1)*(((V:ℝ)+1)*((M:ℝ)+1)*p*(1-p))= - 4096*((V:ℝ)+1)*(p*(1-p)) := by field_simp - rw [he] - push_cast - nlinarith [mul_le_mul_of_nonneg_left hpp (show 0≤(V:ℝ)+1 by positivity)] - -theorem hypergeomMass_middle_le (V M m v : ℕ) {p : ℝ} - (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) - (hN : 16≤V+M) (hm : m≤V+M) (hmean : (m:ℝ)=(V+M:ℕ)*p) : - hypergeomMass V M m v≤64/Real.sqrt ((M:ℝ)+1) := by - have H := hypergeomMass_middle_sq V M m v hp hMV hN hm hmean - have hs : 0 - hypergeomMass_above_total V M m k (by omega))] - exact sum_hypergeomMass V M m hm - -theorem hypergeomMass_complement (V M m v : ℕ) (hv : v≤ m) : - hypergeomMass V M m v=hypergeomMass M V m (m-v) := by - simp only [hypergeomMass,ite_eq_left hv,ite_eq_left (Nat.sub_le _ _),Nat.sub_sub_self hv] - rw [Nat.add_comm M V,mul_comm] - -theorem hypergeomLaw_adjacent_tv (V M m : ℕ) (hM : M≤ m) (hV : m |hypergeomMass V M (m+1) v- - hypergeomMass V M m v|)] - rw [sum_range_extend_zero (show m+2≤V+M+1 by omega) (fun k hk => by - rw [hypergeomMass_above_total V M (m+1) k (by omega), - hypergeomMass_above_total V M m k (by omega),sub_self,abs_zero])] - rw [←Finset.sum_range_reflect (fun v => |hypergeomMass V M (m+1) v- - hypergeomMass V M m v|) (m+2)] - rw [show m+2=(m+1)+1 by omega,Finset.sum_range_succ'] - have hzero : |hypergeomMass V M (m+1) (m+1)-hypergeomMass V M m (m+1)|= - hypergeomMass M V (m+1) 0 := by - rw [hypergeomMass_above_total V M m (m+1) (by omega),sub_zero, - hypergeomMass_complement V M (m+1) (m+1) le_rfl,Nat.sub_self, - abs_of_nonneg (hypergeomMass_nonneg _ _ _ _)] - have he (k : ℕ) (hk : k∈Finset.range (m+1)) : - |hypergeomMass V M (m+1) ((m+1+1)-1-(k+1))- - hypergeomMass V M m ((m+1+1)-1-(k+1))|= - |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k| := by - have hk' : k≤ m := by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hk - rw [show (m+1+1)-1-(k+1)=m-k by omega, - hypergeomMass_complement V M (m+1) (m-k) (by omega), - hypergeomMass_complement V M m (m-k) (by omega)] - rw [show m+1-(m-k)=k+1 by omega,show m-(m-k)=k by omega] - rw [Finset.sum_congr rfl he] - simp only [Nat.add_sub_cancel,Nat.sub_zero,hzero] - rw [sum_range_extend_zero (Nat.add_le_add_right hM 1) (fun k hk => by - rw [hypergeomMass_high M V (m+1) (k+1) (by omega), - hypergeomMass_high M V m k (by omega),sub_self,abs_zero])] - unfold adjacentHypergeomTV - ring - -theorem adjacentHypergeomTV_middle_le (V M m : ℕ) {p : ℝ} - (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) - (hN : 16≤V+M) (hM : M≤ m) (hV : m simp [FiniteLaw.tv_self] - | succ n ih => - rw [Finset.sum_range_succ] - linarith [FiniteLaw.tv_triangle (P 0) (P n) (P (n+1))] - -theorem hypergeomLaw_steps (V M m P : ℕ) (hN : 16≤V+M) - (hM : M≤ m) (hV : m+P - hypergeomLaw V M (m+min j P) (by omega) - have H := FiniteLaw.tv_chain Q P - have hQ0 : Q 0=hypergeomLaw V M m (by omega) := by simp [Q] - have hQP : Q P=hypergeomLaw V M (m+P) (by omega) := by simp [Q] - rw [hQ0,hQP] at H - apply H.trans - calc - _≤∑j∈Finset.range P,64/Real.sqrt ((M:ℝ)+1) := by - apply Finset.sum_le_sum - intro j hj - have hj' : j

T.val.toLeft) - -theorem visibleScheduleLaw_mass (m : ℕ) (hm : m≤Fintype.card α+Fintype.card β) (S : Finset α) : - (visibleScheduleLaw (α:=α) (β:=β) m hm).mass S= - if S.card≤ m then ((Fintype.card β).choose (m-S.card):ℝ)/ - ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0 := by - unfold visibleScheduleLaw - rw [FiniteLaw.map_mass] - by_cases hS : S.card≤ m - · rw [ite_eq_left hS] - simp only [uniformSubsetLaw,Fintype.card_sum] - rw [←Finset.sum_filter] - simp only [Finset.sum_const,nsmul_eq_mul] - have he : (Finset.univ.filter (fun T : FixedSubset (α⊕β) m => T.val.toLeft=S)).card= - (Fintype.card β).choose (m-S.card) := by - rw [←Fintype.card_subtype] - exact (Fintype.card_congr (visibleFiberEquiv (β:=β) m S hS)).trans (card_fixedSubset _) - rw [he] - ring - · rw [ite_eq_right hS] - apply Finset.sum_eq_zero - intro T _ - have hnot : T.val.toLeft≠S := by - intro he - apply hS - simpa only [he,T.property] using (Finset.card_toLeft_le (u:=T.val)) - rw [ite_eq_right hnot] - -theorem sum_finset_card (f : ℕ→ℝ) : - (∑S : Finset α,f S.card)=∑v : Fin (Fintype.card α+1), - ((Fintype.card α).choose v.val:ℝ)*f v.val := by - let g : Finset α→Fin (Fintype.card α+1) := fun S => - ⟨S.card,by have H:=Finset.card_le_univ S; omega⟩ - rw [←Fintype.sum_fiberwise g (fun S => f S.card)] - apply Finset.sum_congr rfl - intro v _ - have hc : Fintype.card {S : Finset α // g S=v}=(Fintype.card α).choose v.val := by - let e : {S : Finset α // g S=v} ≃ FixedSubset α v.val := - { toFun := fun S => ⟨S.val,by have H:=congrArg Fin.val S.property; exact H⟩ - invFun := fun S => ⟨S.val,by apply Fin.ext; exact S.property⟩ - left_inv := fun _ => rfl - right_inv := fun _ => rfl } - exact (Fintype.card_congr e).trans (card_fixedSubset _) - calc - _=∑_S : {S : Finset α // g S=v},f v.val := by - apply Finset.sum_congr rfl - intro S _ - congr 1 - exact congrArg Fin.val S.property - _=_ := by simp [hc] - -end TraceReconstruction - -namespace TraceReconstruction -open scoped Classical -variable {α β : Type*} [Fintype α] [Fintype β] - -theorem visibleScheduleLaw_tv (m m' : ℕ) - (hm : m≤Fintype.card α+Fintype.card β) (hm' : m'≤Fintype.card α+Fintype.card β) : - (visibleScheduleLaw (α:=α) (β:=β) m hm).tv (visibleScheduleLaw m' hm')= - (hypergeomLaw (Fintype.card α) (Fintype.card β) m hm).tv - (hypergeomLaw (Fintype.card α) (Fintype.card β) m' hm') := by - unfold FiniteLaw.tv - simp_rw [visibleScheduleLaw_mass] - rw [sum_finset_card (α:=α) (fun v => - |(if v≤ m then ((Fintype.card β).choose (m-v):ℝ)/ - ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0)- - (if v≤ m' then ((Fintype.card β).choose (m'-v):ℝ)/ - ((Fintype.card α+Fintype.card β).choose m':ℝ) else 0)|)] - have he (v : ℕ) : - ((Fintype.card α).choose v:ℝ)* - |(if v≤ m then ((Fintype.card β).choose (m-v):ℝ)/ - ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0)- - (if v≤ m' then ((Fintype.card β).choose (m'-v):ℝ)/ - ((Fintype.card α+Fintype.card β).choose m':ℝ) else 0)|= - |hypergeomMass (Fintype.card α) (Fintype.card β) m v- - hypergeomMass (Fintype.card α) (Fintype.card β) m' v| := by - rw [←abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) ((Fintype.card α).choose v)),←abs_mul,mul_sub] - simp only [mul_ite,mul_zero,hypergeomMass,mul_div_assoc] - simp_rw [he] - simp only [hypergeomLaw] - rw [Fin.sum_univ_eq_sum_range (fun v => |hypergeomMass (Fintype.card α) (Fintype.card β) m v- - hypergeomMass (Fintype.card α) (Fintype.card β) m' v|)] - rw [Fin.sum_univ_eq_sum_range (n:=Fintype.card α+Fintype.card β+1) - (fun v => |hypergeomMass (Fintype.card α) (Fintype.card β) m v- - hypergeomMass (Fintype.card α) (Fintype.card β) m' v|)] - congr 1 - symm - apply sum_range_extend_zero (by omega) - intro k hk - rw [hypergeomMass_high _ _ _ _ (by omega),hypergeomMass_high _ _ _ _ (by omega),sub_self,abs_zero] - -theorem visibleScheduleLaw_steps (m P : ℕ) - (hN : 16≤Fintype.card α+Fintype.card β) (hM : Fintype.card β≤ m) - (hV : m+P if b=a then 1 else 0) - simpa only [expect,mul_ite,mul_one,mul_zero,Fintype.sum_ite_eq'] using H - -theorem expect_map (P : FiniteLaw α) (f : α→β) (G : β→ℝ) : - (P.map f).expect G=P.expect (G∘f) := expectation_map P f G - -theorem map_map (P : FiniteLaw α) (f : α→β) (g : β→γ) : - (P.map f).map g=P.map (g∘f) := by - apply ext_expect - intro G - rw [expect_map,expect_map,expect_map] - rfl - -theorem map_id (P : FiniteLaw α) : P.map id=P := by - apply ext_expect - intro G - rw [expect_map] - rfl - -theorem map_equiv_mass (P : FiniteLaw α) (e : α≃β) (b : β) : - (P.map e).mass b=P.mass (e.symm b) := by - rw [map_mass] - simp only [←e.eq_symm_apply,Fintype.sum_ite_eq'] - -theorem tv_map_equiv (P Q : FiniteLaw α) (e : α≃β) : - (P.map e).tv (Q.map e)=P.tv Q := by - unfold tv - simp_rw [map_equiv_mass] - rw [e.symm.sum_comp (fun a => |P.mass a-Q.mass a|)] - -end FiniteLaw - -variable {α β : Type*} [Fintype α] [Fintype β] - -def fixedSubsetEquiv (e : α≃β) (m : ℕ) : FixedSubset α m ≃ FixedSubset β m where - toFun S := ⟨S.val.map e.toEmbedding,by simpa only [Finset.card_map] using S.property⟩ - invFun T := ⟨T.val.map e.symm.toEmbedding,by simpa only [Finset.card_map] using T.property⟩ - left_inv S := by apply Subtype.ext; exact e.finsetCongr.left_inv S.val - right_inv T := by apply Subtype.ext; exact e.finsetCongr.right_inv T.val - -theorem uniformSubsetLaw_map (e : α≃β) (m : ℕ) (hm : m≤Fintype.card α) : - (uniformSubsetLaw m hm).map (fixedSubsetEquiv e m)= - uniformSubsetLaw m (by simpa only [←Fintype.card_congr e] using hm) := by - apply FiniteLaw.ext - funext T - rw [FiniteLaw.map_equiv_mass] - simp only [uniformSubsetLaw,Fintype.card_congr e] - -end TraceReconstruction - -namespace TraceReconstruction -open scoped Classical -variable {α : Type*} [Fintype α] - -abbrev HiddenIndex (H : Finset α) := {a : α // a∈H} -abbrev VisibleIndex (H : Finset α) := {a : α // a∉H} - -def splitIndexEquiv (H : Finset α) : VisibleIndex H⊕HiddenIndex H ≃ α := - (Equiv.sumComm _ _).trans (Equiv.sumCompl (fun a => a∈H)) - -theorem card_splitIndex (H : Finset α) : - Fintype.card (VisibleIndex H)+Fintype.card (HiddenIndex H)=Fintype.card α := by - simpa only [Fintype.card_sum] using Fintype.card_congr (splitIndexEquiv H) - -omit [Fintype α] in -theorem card_hiddenIndex (H : Finset α) : Fintype.card (HiddenIndex H)=H.card := by - exact Fintype.card_coe H - -def eraseScheduleLaw (H : Finset α) (m : ℕ) (hm : m≤Fintype.card α) : FiniteLaw (Finset α) := - (uniformSubsetLaw m hm).map (fun S => S.val\H) - -omit [Fintype α] in -theorem erase_splitIndex (H : Finset α) (S : Finset (VisibleIndex H⊕HiddenIndex H)) : - (S.map (splitIndexEquiv H).toEmbedding)\H= - S.toLeft.map ⟨Subtype.val,Subtype.val_injective⟩ := by - ext a - constructor - · intro ha - obtain ⟨ha,hn⟩:=Finset.mem_sdiff.mp ha - obtain ⟨b,hb,rfl⟩:=Finset.mem_map.mp ha - cases b with - | inl b => - apply Finset.mem_map.mpr - exact ⟨b,by simpa using hb,rfl⟩ - | inr b => exact False.elim (hn b.property) - · intro ha - obtain ⟨b,hb,rfl⟩:=Finset.mem_map.mp ha - apply Finset.mem_sdiff.mpr - constructor - · exact Finset.mem_map.mpr ⟨Sum.inl b,by simpa using hb,rfl⟩ - · exact b.property - -end TraceReconstruction - -namespace TraceReconstruction -open scoped Classical -variable {α : Type*} [Fintype α] - -theorem eraseScheduleLaw_eq (H : Finset α) (m : ℕ) (hm : m≤Fintype.card α) : - eraseScheduleLaw H m hm= - (visibleScheduleLaw (α:=VisibleIndex H) (β:=HiddenIndex H) m - (by simpa only [card_splitIndex] using hm)).map - (fun S => S.map ⟨Subtype.val,Subtype.val_injective⟩) := by - have h:=uniformSubsetLaw_map (splitIndexEquiv H) m - (by simpa only [Fintype.card_sum,card_splitIndex] using hm) - unfold eraseScheduleLaw visibleScheduleLaw - rw [←h,FiniteLaw.map_map,FiniteLaw.map_map] - congr 1 - funext S - exact erase_splitIndex H S.val - -theorem eraseScheduleLaw_steps (H : Finset α) (m P : ℕ) - (hN : 16≤Fintype.card α) (hM : H.card≤ m) - (hV : m+P+H.card (K i).expect (fun b => F ⟨i,b⟩)) := by - simp only [expect,sigma,Fintype.sum_sigma,Finset.mul_sum,mul_assoc] - -theorem overlap_sigma_lower (P Q : FiniteLaw ι) (K L : ∀i,FiniteLaw (β i)) : - (∑i,min (P.mass i) (Q.mass i)*overlap (K i) (L i))≤overlap (P.sigma K) (Q.sigma L) := by - simp only [overlap,sigma,Fintype.sum_sigma,Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - apply Finset.sum_le_sum - intro b _ - apply le_min - · exact mul_le_mul (min_le_left _ _) (min_le_left _ _) (le_min ((K i).nonneg b) ((L i).nonneg b)) (P.nonneg i) - · exact mul_le_mul (min_le_right _ _) (min_le_right _ _) (le_min ((K i).nonneg b) ((L i).nonneg b)) (Q.nonneg i) -end FiniteLaw - -theorem sum_binomialMass_cutoff {n N : ℕ} (hn : n≤N) (p : ℝ) : - ∑l : Fin (N+1),binomialMass n p l.val=1 := by - rw [Fin.sum_univ_eq_sum_range (fun k => binomialMass n p k) (N+1)] - rw [←sum_binomialMass n p] - symm - apply Finset.sum_subset (Finset.range_mono (by omega)) - intro k _ hk - have hn' : n F (List.ofFn a.2))= - silentMarkExpectation q (List.ofFn θ) F := by - rw [countedPrimitiveLaw,FiniteLaw.expect_sigma,silentMarkExpectation_count_mixture q hq θ F] - change (∑l : Fin (N+1),binomialMass n (1-primitiveErasure q) l.val* - (boundedConditionalPrimitiveLaw hq θ l).expect (fun x => F (List.ofFn x)))=_ - let f : ℕ→ℝ := fun l => if hl:l≤n then binomialMass n (1-primitiveErasure q) l* - (conditionalPrimitiveLaw hl q hq θ).expect (fun x => F (List.ofFn x)) else 0 - have hleft : (∑l : Fin (N+1),binomialMass n (1-primitiveErasure q) l.val* - (boundedConditionalPrimitiveLaw hq θ l).expect (fun x => F (List.ofFn x)))= - ∑l : Fin (N+1),f l.val := by - apply Finset.sum_congr rfl - intro l _ - by_cases hl:l.val≤n - · simp only [boundedConditionalPrimitiveLaw,hl,dite_eq_left,f] - · simp [boundedConditionalPrimitiveLaw,hl,f,binomialMass,Nat.choose_eq_zero_of_lt (Nat.lt_of_not_ge hl)] - rw [hleft,Fin.sum_univ_eq_sum_range f (N+1)] - have he : (∑l∈Finset.range (n+1),f l)=∑l∈Finset.range (N+1),f l := by - apply Finset.sum_subset (Finset.range_mono (by omega)) - intro l _ hl - simp only [Finset.mem_range] at hl - simp [f,show ¬l≤n by omega] - rw [←he,←Fin.sum_univ_eq_sum_range f (n+1)] - apply Finset.sum_congr rfl - intro l _ - simp only [f,dite_eq_left (Nat.le_of_lt_succ l.isLt)] - -theorem countedPrimitiveLaw_simulates {n N : ℕ} (hn : n≤N) {q : ℝ} (hq : q∈Set.Ioo 0 1) - (θ : Fin n→Bool) : - SimulatesTrace q (countedPrimitiveLaw hn hq θ) decodeBoundedMarks - (((List.ofFn θ).map primitiveBlock).flatten) := by - intro F - rw [primitive_run_simulation hq] - exact countedPrimitiveLaw_expect hn hq θ (fun a => F (joinPrimitiveMarks a)) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -variable {α : Type*} [Fintype α] - -theorem subsetLaw_expect_card (p : ℝ) (hp : p∈Set.Icc 0 1) (f : ℕ→ℝ) : - (subsetLaw (α:=α) p hp).expect (fun S => f S.card)= - ∑k∈Finset.range (Fintype.card α+1),binomialMass (Fintype.card α) p k*f k := by - change (∑S : Finset α,p^S.card*(1-p)^(Fintype.card α-S.card)*f S.card)=_ - rw [sum_finset_card (α:=α) (fun k => p^k*(1-p)^(Fintype.card α-k)*f k), - Fin.sum_univ_eq_sum_range (fun k => ((Fintype.card α).choose k:ℝ)*(p^k*(1-p)^(Fintype.card α-k)*f k))] - apply Finset.sum_congr rfl - intro k _ - unfold binomialMass - ring - -theorem subsetLaw_variance (p : ℝ) (hp : p∈Set.Icc 0 1) : - (subsetLaw (α:=α) p hp).expect (fun S => ((S.card:ℝ)-Fintype.card α*p)^2)= - (Fintype.card α:ℝ)*p*(1-p) := by - rw [subsetLaw_expect_card p hp (fun k => ((k:ℝ)-Fintype.card α*p)^2)] - exact binomialMass_variance _ p - -def hiddenScheduleLaw (p : ℝ) (hp : p∈Set.Icc 0 1) (m : ℕ) (hm : m≤Fintype.card α) : - FiniteLaw (Finset α×Finset α) := - (subsetLaw p hp).bind (fun H => (eraseScheduleLaw H m hm).map (fun S => (H,S))) - -theorem hiddenScheduleLaw_tv (p : ℝ) (hp : p∈Set.Icc 0 1) (m m' : ℕ) - (hm : m≤Fintype.card α) (hm' : m'≤Fintype.card α) : - (hiddenScheduleLaw p hp m hm).tv (hiddenScheduleLaw p hp m' hm') ≤ - (subsetLaw (α:=α) p hp).expect (fun H => - (eraseScheduleLaw H m hm).tv (eraseScheduleLaw H m' hm')) := by - unfold hiddenScheduleLaw - refine (FiniteLaw.tv_bind_kernel_le _ _ _).trans ?_ - apply FiniteLaw.expect_mono - intro H - exact FiniteLaw.tv_map_le _ _ _ - -theorem good_hiddenSchedule_bound {G P : ℕ} {p : ℝ} - (hG : 8≤G) (hP : 4*P≤G) (hp : p∈Set.Ioc 0 (1/8)) - (H : Finset (Fin (2*G))) - (hlo : p*(2*G:ℝ)/2≤H.card) (hhi : (H.card:ℝ)≤2*p*(2*G:ℝ)) : - (eraseScheduleLaw H G (by simp only [Fintype.card_fin]; omega)).tv - (eraseScheduleLaw H (G+P) (by simp only [Fintype.card_fin]; omega))≤ - (P:ℝ)*64/Real.sqrt (p*(2*G:ℝ)/2) := by - have hgr : (0:ℝ) E+4*((H.card:ℝ)-μ)^2/μ^2) (fun H => by - by_cases hg : μ/2≤(H.card:ℝ) ∧ (H.card:ℝ)≤2*μ - · exact (good_hiddenSchedule_bound hG hP hp H hg.1 (by simpa only [μ,mul_assoc] using hg.2)).trans - (le_add_of_nonneg_right (by positivity)) - · exact (FiniteLaw.tv_le_one _ _).trans - ((bad_hiddenSchedule_variance hμ hg).trans (by linarith))) - apply he.trans - have hv:=subsetLaw_variance (α:=Fin (2*G)) p ⟨hp.1.le,by linarith [hp.2]⟩ - simp only [Fintype.card_fin,Nat.cast_mul,Nat.cast_ofNat] at hv - change (∑H,(subsetLaw p _).mass H*(E+4*((H.card:ℝ)-μ)^2/μ^2))≤E+4/μ - simp_rw [mul_add, Finset.sum_add_distrib] - rw [← Finset.sum_mul,FiniteLaw.total,one_mul] - have heq : (∑H : Finset (Fin (2*G)),(subsetLaw p ⟨hp.1.le,by linarith [hp.2]⟩).mass H*(4*((H.card:ℝ)-μ)^2/μ^2))= - 4/μ^2*(2*(G:ℝ)*p*(1-p)) := by - rw [←hv,FiniteLaw.expect,Finset.mul_sum] - apply Finset.sum_congr rfl - intro H _ - dsimp [μ] - ring - rw [heq] - have heq' : 4/μ^2*(2*(G:ℝ)*p*(1-p))=4/μ*(1-p) := by - have h : 2*(G:ℝ)*p=μ := by dsimp [μ]; ring - rw [h] - field_simp - rw [heq'] - have h:=mul_le_mul_of_nonneg_left (show 1-p≤1 by linarith [hp.1]) (show 0≤4/μ by positivity) - linarith - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -theorem expect_comm (P : FiniteLaw α) (Q : FiniteLaw β) (F : α→β→ℝ) : - P.expect (fun a => Q.expect (F a))=Q.expect (fun b => P.expect (fun a => F a b)) := by - simp only [expect,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - apply Finset.sum_congr rfl - intro a _ - ring - -theorem bind_map (P : FiniteLaw α) (f : α→β) (K : β→FiniteLaw γ) : - (P.map f).bind K=P.bind (K∘f) := by - apply ext_expect - intro F - rw [expect_bind,expect_map,expect_bind] - rfl - -theorem map_bind (P : FiniteLaw α) (K : α→FiniteLaw β) (f : β→γ) : - (P.bind K).map f=P.bind (fun a => (K a).map f) := by - apply ext_expect - intro F - simp only [expect_bind,expect_map] - -theorem bind_comm (P : FiniteLaw α) (Q : FiniteLaw β) (K : α→β→FiniteLaw γ) : - P.bind (fun a => Q.bind (K a))=Q.bind (fun b => P.bind (fun a => K a b)) := by - apply ext_expect - intro F - simp only [expect_bind] - exact expect_comm P Q (fun a b => (K a b).expect F) - -end FiniteLaw -variable {α : Type*} [Fintype α] - -theorem subsetWeight_mask {n : ℕ} (p : ℝ) (a : Mask n) : - subsetWeight p (maskSubset a)=maskWeight (1-p) a := by - rw [maskWeight_card] - simp only [subsetWeight,Fintype.card_fin,sub_sub_cancel] - -theorem coordinateProduct_common_flags {n : ℕ} (p : ℝ) (hp : p∈Set.Icc 0 1) - (U : FiniteLaw α) (R P : Fin n→FiniteLaw α) - (hP : ∀ i x,(P i).mass x=p*U.mass x+(1-p)*(R i).mass x) : - (subsetLaw p hp).bind (fun H : Finset (Fin n) => - FiniteLaw.coordinateProduct (fun i => if i∈H then U else R i))= - FiniteLaw.coordinateProduct P := by - apply FiniteLaw.ext - funext x - change (∑H : Finset (Fin n),subsetWeight p H*(∏i,(if i∈H then U else R i).mass (x i)))= - ∏i,(P i).mass (x i) - rw [←(maskSubsetEquiv n).sum_comp] - change (∑a : Mask n,subsetWeight p (maskSubset a)*(∏i,(if i∈maskSubset a then U else R i).mass (x i)))=_ - simp_rw [subsetWeight_mask,maskWeight,←Finset.prod_mul_distrib] - have he (a : Mask n) (i : Fin n) : - (if a i then 1-(1-p) else 1-p)*(if i∈maskSubset a then U else R i).mass (x i)= - if a i then p*U.mass (x i) else (1-p)*(R i).mass (x i) := by - cases ha : a i <;> simp [maskSubset,ha] - simp_rw [he] - rw [←Fintype.prod_sum (fun i (b : Bool) => if b then p*U.mass (x i) else (1-p)*(R i).mass (x i))] - apply Finset.prod_congr rfl - intro i _ - simp only [Fintype.sum_bool,ite_true,Bool.false_eq_true,ite_false] - rw [hP] - -end TraceReconstruction - -namespace TraceReconstruction -open scoped Classical -variable {α : Type*} [Fintype α] - -def schedulePayload {n : ℕ} (U P Q : FiniteLaw α) (z : Finset (Fin n)×Finset (Fin n)) : - FiniteLaw (Fin n→α) := - FiniteLaw.coordinateProduct (fun i => if i∈z.1 then U else if i∈z.2 then Q else P) - -def uniformSchedulePayload {n : ℕ} (P Q : FiniteLaw α) (m : ℕ) (hm : m≤n) : - FiniteLaw (Fin n→α) := - (uniformSubsetLaw (α:=Fin n) m (by simpa using hm)).bind - (fun S => FiniteLaw.coordinateProduct (fun i => if i∈S.val then Q else P)) - -theorem hiddenSchedule_payload_exact {n : ℕ} (p : ℝ) (hp : p∈Set.Icc 0 1) - (U P' Q' P Q : FiniteLaw α) - (hP : ∀ x,P.mass x=p*U.mass x+(1-p)*P'.mass x) - (hQ : ∀ x,Q.mass x=p*U.mass x+(1-p)*Q'.mass x) - (m : ℕ) (hm : m≤n) : - (hiddenScheduleLaw (α:=Fin n) p hp m (by simpa using hm)).bind (schedulePayload U P' Q')= - uniformSchedulePayload P Q m hm := by - unfold hiddenScheduleLaw eraseScheduleLaw - rw [FiniteLaw.bind_assoc] - simp_rw [FiniteLaw.bind_map] - rw [FiniteLaw.bind_comm] - unfold uniformSchedulePayload - congr 1 - funext S - trans (subsetLaw p hp).bind (fun H : Finset (Fin n) => - FiniteLaw.coordinateProduct (fun i => if i∈H then U else if i∈S.val then Q' else P')) - · congr 1 - funext H - dsimp only [Function.comp_def,schedulePayload] - congr 1 - funext i - by_cases h : i∈H <;> by_cases h' : i∈S.val <;> simp [h,h'] - apply coordinateProduct_common_flags - intro i x - by_cases h : i∈S.val - · simpa [h] using hQ x - · simpa [h] using hP x - -theorem uniformSchedulePayload_steps {G R : ℕ} {p : ℝ} - (hG : 8≤G) (hR : 4*R≤G) (hp : p∈Set.Ioc 0 (1/8)) - (P Q : FiniteLaw α) (hov : p≤FiniteLaw.overlap P Q) : - (uniformSchedulePayload (n:=2*G) P Q G (by omega)).tv - (uniformSchedulePayload P Q (G+R) (by omega))≤ - (R:ℝ)*64/Real.sqrt (p*(2*G:ℝ)/2)+4/(p*(2*G:ℝ)) := by - have hp1 : p∈Set.Ioo 0 1 := ⟨hp.1,by linarith [hp.2]⟩ - obtain ⟨U,P',Q',hP,hQ⟩:=FiniteLaw.common_part_decomposition P Q hp1 hov - rw [←hiddenSchedule_payload_exact p ⟨hp.1.le,hp1.2.le⟩ U P' Q' P Q hP hQ, - ←hiddenSchedule_payload_exact p ⟨hp.1.le,hp1.2.le⟩ U P' Q' P Q hP hQ] - exact (FiniteLaw.tv_bind_le _ _ _).trans (hiddenScheduleLaw_steps hG hR hp) - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def coordinateWord {n : ℕ} (w : Fin n→List Bool) : List Bool := (List.ofFn w).flatten - -theorem coordinateWord_succ {n : ℕ} (w : Fin (n+1)→List Bool) : - coordinateWord w=w 0++coordinateWord (fun i => w i.succ) := by - simp only [coordinateWord,List.ofFn_succ,List.flatten_cons] - -theorem coordinateWord_cons {n : ℕ} (w : List Bool) (v : Fin n→List Bool) : - coordinateWord (Fin.cons w v)=w++coordinateWord v := by - rw [coordinateWord_succ] - simp only [Fin.cons_zero,Fin.cons_succ] - -theorem coordinateProduct_simulates {α : Type*} [Fintype α] - {n : ℕ} {q : ℝ} (P : Fin n→FiniteLaw α) (f : α→List Bool) (w : Fin n→List Bool) - (h : ∀i,SimulatesTrace q (P i) f (w i)) : - SimulatesTrace q (FiniteLaw.coordinateProduct P) (fun a => coordinateWord (fun i => f (a i))) - (coordinateWord w) := by - induction n with - | zero => - intro F - change (FiniteLaw.coordinateProduct P).expect (fun _ => F [])=F [] - exact FiniteLaw.expect_const _ _ - | succ n ih => - intro F - rw [FiniteLaw.expect_coordinateProduct_succ,coordinateWord_succ,listDeletionExpectation_append] - have hj (a : α) (x : Fin n→α) : - coordinateWord (fun i => f ((Fin.cons a x : Fin (n+1)→α) i))=f a++coordinateWord (fun i => f (x i)) := by - rw [coordinateWord_succ] - simp only [Fin.cons_zero,Fin.cons_succ] - simp_rw [hj] - have ht:=ih (fun i => P i.succ) (fun i => w i.succ) (fun i => h i.succ) - calc - _=(P 0).expect (fun a => listDeletionExpectation q (coordinateWord (fun i => w i.succ)) - (fun t => F (f a++t))) := by - congr 1 - funext a - exact ht (fun t => F (f a++t)) - _=_ := h 0 (fun t => listDeletionExpectation q (coordinateWord (fun i => w i.succ)) (fun u => F (t++u))) - -theorem sum_subset_choices {n : ℕ} (S : Finset (Fin n)) (k : ℕ) : - (∑i : Fin n,if i∈S then k+1 else k)=n*k+S.card := by - have he (i : Fin n) : (if i∈S then k+1 else k)=k+(if i∈S then 1 else 0) := by - split_ifs <;> omega - simp_rw [he] - simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, - Finset.sum_boole,Finset.filter_mem_eq_inter,Finset.univ_inter,Nat.cast_id] - -theorem coordinateWord_pureAtomRun {n : ℕ} (w : List Bool) (k : Fin n→ℕ) : - coordinateWord (fun i => pureAtomRun w (k i))=pureAtomRun w (∑i,k i) := by - change (List.ofFn (pureAtomRun w ∘ k)).flatten=_ - rw [←List.map_ofFn,pureAtomRun_partition,List.sum_ofFn] - -theorem uniform_schedule_word {n m : ℕ} (S : FixedSubset (Fin n) m) (w : List Bool) (k : ℕ) : - coordinateWord (fun i => if i∈S.val then pureAtomRun w (k+1) else pureAtomRun w k)= - pureAtomRun w (n*k+m) := by - have he (i : Fin n) : (if i∈S.val then pureAtomRun w (k+1) else pureAtomRun w k)= - pureAtomRun w (if i∈S.val then k+1 else k) := by split_ifs <;> rfl - simp_rw [he] - rw [coordinateWord_pureAtomRun,sum_subset_choices,S.property] - -end TraceReconstruction -noncomputable section -namespace TraceReconstruction - -theorem lifting_count_scale {F k P : ℕ} {C p : ℝ} - (hk : 1≤k) (hP : 1≤P) (hp : p∈Set.Ioc 0 (1/8)) - (hC : 1073741824≤p*C) (hF : C*k*P≤F) : - (1048576:ℝ)*(P:ℝ)^2≤p*((F*P/(2*k+1):ℕ):ℝ) := by - let G := F*P/(2*k+1) - have hkr : (1:ℝ)≤k := by exact_mod_cast hk - have hPr : (1:ℝ)≤P := by exact_mod_cast hP - have hGr : (0:ℝ)≤G := Nat.cast_nonneg G - have hnat:=Nat.lt_mul_div_succ (F*P) (show 0<2*k+1 by omega) - have hupper : (F:ℝ)*P<(2*(k:ℝ)+1)*((G:ℝ)+1) := by exact_mod_cast hnat - have hF' := mul_le_mul_of_nonneg_right hF (show (0:ℝ)≤P by positivity) - have hupper' := mul_lt_mul_of_pos_left hupper hp.1 - have hlower:=mul_le_mul_of_nonneg_left hF' hp.1.le - have hC' := mul_le_mul_of_nonneg_right hC (show (0:ℝ)≤(k:ℝ)*(P:ℝ)^2 by positivity) - have hden : (2*(k:ℝ)+1)*(p*((G:ℝ)+1))≤3*(k:ℝ)*(p*((G:ℝ)+1)) := by - apply mul_le_mul_of_nonneg_right (by linarith) - positivity [hp.1.le] - have hmain : (1073741824:ℝ)*(P:ℝ)^2<3*p*((G:ℝ)+1) := by - have h : (k:ℝ)*(1073741824*(P:ℝ)^2)<(k:ℝ)*(3*p*((G:ℝ)+1)) := by - nlinarith only [hlower,hupper',hC',hden] - exact (mul_lt_mul_iff_of_pos_left (by linarith : (0:ℝ) coordinateWord (fun i => f (a i))) (pureAtomRun w (n*k+m)) := by - apply SimulatesTrace.random_partition - intro S - rw [←uniform_schedule_word S w k] - apply coordinateProduct_simulates - intro i - by_cases h : i∈S.val - · simpa only [h,ite_true] using hQ - · simpa only [h,ite_false] using hP - -/-- Explicit source common-part lifting, using finite auxiliary observations -that decode exactly to ordinary complete traces of the adjacent pure powers. -/ -theorem adjacent_power_lift {F k R : ℕ} {C p q : ℝ} - (hk : 1≤k) (hR : 1≤R) (hp : p∈Set.Ioc 0 (1/8)) (hq : q∈Set.Icc 0 1) - (hC : 1073741824≤p*C) (hF : C*k*R≤F) - (P Q : FiniteLaw α) (f : α→List Bool) (w : List Bool) - (hP : SimulatesTrace q P f (pureAtomRun w k)) - (hQ : SimulatesTrace q Q f (pureAtomRun w (k+1))) - (hov : p≤FiniteLaw.overlap P Q) : - ∃ (β : Type u) (_ : Fintype β) (P' Q' : FiniteLaw β) (g : β→List Bool), - SimulatesTrace q P' g (pureAtomRun w (F*R)) ∧ - SimulatesTrace q Q' g (pureAtomRun w (F*R+R)) ∧ - (2/3:ℝ)≤FiniteLaw.overlap P' Q' := by - let G := F*R/(2*k+1) - have hs : (1048576:ℝ)*(R:ℝ)^2≤p*(G:ℝ) := lifting_count_scale hk hR hp hC hF - obtain ⟨hG,hr⟩:=lifting_scale_valid hR hp hs - let A:=uniformSchedulePayload (n:=2*G) P Q G (by omega) - let B:=uniformSchedulePayload (n:=2*G) P Q (G+R) (by omega) - have htv : A.tv B≤1/3 := - (uniformSchedulePayload_steps hG hr hp P Q hov).trans (lifting_numeric_bound hR hp hs) - let tail:=pureAtomRun w (F*R-G*(2*k+1)) - let S:=maskLaw (n:=tail.length) q hq - let g : (Fin (2*G)→α)×Mask tail.length→List Bool := - fun a => coordinateWord (fun i => f (a.1 i))++traceOfMask tail.get a.2 - refine ⟨(Fin (2*G)→α)×Mask tail.length,inferInstance,A.prod S,B.prod S,g,?_,?_,?_⟩ - · have ha:=uniformSchedulePayload_simulates (n:=2*G) (by omega : G≤2*G) P Q f w hP hQ - have ht:=(ha.append (maskLaw_simulates hq tail)) - have hh : G*(2*k+1)≤F*R := Nat.div_mul_le_self _ _ - have he : 2*G*k+G+(F*R-G*(2*k+1))=F*R := by - have he0 : G*(2*k+1)=2*G*k+G := by ring - omega - simpa only [tail,←pureAtomRun_add,he] using ht - · have hb:=uniformSchedulePayload_simulates (n:=2*G) (by omega : G+R≤2*G) P Q f w hP hQ - have ht:=(hb.append (maskLaw_simulates hq tail)) - have hh : G*(2*k+1)≤F*R := Nat.div_mul_le_self _ _ - have he : 2*G*k+(G+R)+(F*R-G*(2*k+1))=F*R+R := by - have he0 : G*(2*k+1)=2*G*k+G := by ring - omega - simpa only [tail,←pureAtomRun_add,he] using ht - · rw [FiniteLaw.overlap_eq_one_sub_tv,FiniteLaw.tv_prod_eq_left] - linarith - -end TraceReconstruction - - - -/-! -Concrete objects for the scale inequalities, Definition 3 (the level invariant). -The observable channel remains the complete deletion trace of a literal word. --/ -noncomputable section -namespace TraceReconstruction -open scoped Classical - -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -/-- The maximizing test for total variation on a finite sample space. -/ -theorem tv_eq_positive_test (P Q : FiniteLaw α) : - P.tv Q = P.expect (fun a => if Q.mass a ≤ P.mass a then 1 else 0) - - Q.expect (fun a => if Q.mass a ≤ P.mass a then 1 else 0) := by - have hz : (∑ a, (P.mass a - Q.mass a)) = 0 := by - rw [Finset.sum_sub_distrib, P.total, Q.total, sub_self] - have he (a : α) : - |P.mass a-Q.mass a|+(P.mass a-Q.mass a) = - 2*((P.mass a-Q.mass a)*(if Q.mass a ≤ P.mass a then 1 else 0)) := by - split_ifs with h - · rw [abs_of_nonneg (sub_nonneg.mpr h)]; ring - · rw [abs_of_neg (sub_neg.mpr (lt_of_not_ge h))]; ring - have hs := congrArg (fun f : α → ℝ => ∑ a, f a) (funext he) - simp only [Finset.sum_add_distrib, hz, add_zero, ← Finset.mul_sum] at hs - simp only [tv, expect] - rw [← Finset.sum_sub_distrib] - simp_rw [← sub_mul] - linarith only [hs] - -/-- Dual characterization, sufficient for simulators with different latent spaces. -/ -theorem tv_le_of_tests (P Q : FiniteLaw α) {E : ℝ} - (h : ∀ f : α → ℝ, (∀ a, f a ∈ Set.Icc 0 1) → - P.expect f-Q.expect f ≤ E) : P.tv Q ≤ E := by - rw [tv_eq_positive_test] - exact h _ (fun a => by split_ifs <;> norm_num) - -theorem abs_expect_sub_le_tv (P Q : FiniteLaw α) (f : α → ℝ) - (hf : ∀ a, f a ∈ Set.Icc 0 1) : |P.expect f-Q.expect f| ≤ P.tv Q := by - apply abs_le.mpr - constructor - · have h := expectation_diff_le_tv Q P f hf - rw [tv_symm Q P] at h - change Q.expect f-P.expect f ≤ P.tv Q at h - linarith - · exact expectation_diff_le_tv P Q f hf -end FiniteLaw - -/-- The genuine complete-trace law embedded in a specified finite trace space. -The extra elements have mass zero, not a cemetery mass. -/ -def listTraceLaw (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) - (M : ℕ) (hw : w.length ≤ M) : FiniteLaw (BoundedTrace M) := - (maskLaw (n:=w.length) q hq).map (fun a => - ⟨traceOfMask w.get a, mem_traceSpace_of_length_le _ - ((traceOfMask_length_le w.get a).trans hw)⟩) - -theorem listTraceLaw_expect (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) - (M : ℕ) (hw : w.length ≤ M) (F : List Bool → ℝ) : - (listTraceLaw q hq w M hw).expect (fun a => F a.val) = - listDeletionExpectation q w F := by - rw [listTraceLaw, FiniteLaw.expect_map] - have h := listDeletionExpectation_ofFn q w.get F - rw [List.ofFn_get] at h - exact h.symm - -theorem listTraceLaw_simulates (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) - (M : ℕ) (hw : w.length ≤ M) : - SimulatesTrace q (listTraceLaw q hq w M hw) Subtype.val w := - listTraceLaw_expect q hq w M hw - -/-- Ordinary overlap of complete traces, including unequal input lengths. -/ -def listTraceOverlap (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x y : List Bool) : ℝ := - let M := max x.length y.length - FiniteLaw.overlap (listTraceLaw q hq x M (le_max_left _ _)) - (listTraceLaw q hq y M (le_max_right _ _)) - -/-- Common approximate simulation transfers distinguishability to genuine -complete traces, without revealing the latent partition. -/ -theorem approximations_trace_tv {α : Type*} [Fintype α] - {q : ℝ} (hq : q ∈ Set.Icc 0 1) (P Q : FiniteLaw α) (decode : α → List Bool) - (x y : List Bool) (Ex Ey : ℝ) (M : ℕ) (hx : x.length ≤ M) (hy : y.length ≤ M) - (hP : ApproximatesTrace q P decode x Ex) - (hQ : ApproximatesTrace q Q decode y Ey) : - (listTraceLaw q hq x M hx).tv (listTraceLaw q hq y M hy) ≤ P.tv Q+Ex+Ey := by - apply FiniteLaw.tv_le_of_tests - intro f hf - let F : List Bool → ℝ := fun t => if h : t ∈ traceSpace M then f ⟨t,h⟩ else 0 - have hF : ∀ t, F t ∈ Set.Icc 0 1 := by - intro t - dsimp [F] - split_ifs with h - · exact hf ⟨t,h⟩ - · norm_num - have hFx : (listTraceLaw q hq x M hx).expect f = listDeletionExpectation q x F := by - rw [← listTraceLaw_expect q hq x M hx F] - congr 1 - funext t - simp only [F, dite_eq_left t.property] - have hFy : (listTraceLaw q hq y M hy).expect f = listDeletionExpectation q y F := by - rw [← listTraceLaw_expect q hq y M hy F] - congr 1 - funext t - simp only [F, dite_eq_left t.property] - rw [hFx,hFy] - have hp := hP F hF - have hq' := hQ F hF - have ht := FiniteLaw.abs_expect_sub_le_tv P Q (fun a => F (decode a)) (fun a => hF _) - linarith [le_abs_self (P.expect (fun a => F (decode a))-Q.expect (fun a => F (decode a))), - (abs_le.mp hp).1, (abs_le.mp hp).2, (abs_le.mp hq').1, (abs_le.mp hq').2] - -/-- A literal witness of the source level invariant. `halfOrder` is half its -positive even moment order. `countFactor` is the prescribed upper multiplier -`C^(2*B*i+O_B(1))`, to be instantiated uniformly in the actual construction. -Finite outcomes suffice for the source's finite latent experiments, and any -randomized common decoder can be included as an additional latent draw. -/ -structure ConcreteLevelPair (q : ℝ) (hq : q ∈ Set.Icc 0 1) - (N Δ d ω countFactor : ℝ) (i halfOrder : ℕ) where - left : List Bool - right : List Bool - equalLength : left.length = right.length - different : left ≠ right - length_lower : N/2 ≤ (left.length : ℝ) - length_upper : (left.length : ℝ) ≤ N - Outcome : Type - finiteOutcome : Fintype Outcome - firstLaw : @FiniteLaw Outcome finiteOutcome - secondLaw : @FiniteLaw Outcome finiteOutcome - decode : Outcome → List Bool - error : ℝ - error_nonneg : 0 ≤ error - normalized_error : error/(left.length : ℝ) ≤ ((i:ℝ)+1)*Δ - first_simulation : @ApproximatesTrace Outcome finiteOutcome q firstLaw decode left error - second_simulation : @ApproximatesTrace Outcome finiteOutcome q secondLaw decode right error - score : Outcome → ℝ - density : ∀ a, secondLaw.mass a = firstLaw.mass a*(1+score a) - score_bound : @FiniteLaw.evenMomentSq Outcome finiteOutcome firstLaw score halfOrder ≤ N ^ (-d) - overlapCount : ℕ - overlapCount_lower : left.length ≤ overlapCount - overlapCount_upper : (overlapCount:ℝ) ≤ countFactor*(left.length:ℝ) - power_overlap : ω ≤ listTraceOverlap q hq (pureAtomRun left overlapCount) - (pureAtomRun left (overlapCount+1)) - -end TraceReconstruction - - - -/-! The actual finite paired-flag experiment. We separate its unconditional -orientation-first generation (used for trace simulation) from its exact -metadata-first Bayes factorization (used for the density estimates). -Neither construction conditions on successful window layout. -/ -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace FiniteLaw -variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] - -/-- A joint law retaining both the latent variable and its conditional draw. -/ -def joint (P : FiniteLaw α) (K : α → FiniteLaw β) : FiniteLaw (α × β) where - mass z := P.mass z.1 * (K z.1).mass z.2 - nonneg z := mul_nonneg (P.nonneg _) ((K _).nonneg _) - total := by - rw [Fintype.sum_prod_type] - simp_rw [← Finset.mul_sum, (K _).total, mul_one] - exact P.total - -theorem expect_joint (P : FiniteLaw α) (K : α → FiniteLaw β) (F : α × β → ℝ) : - (P.joint K).expect F = P.expect (fun a => (K a).expect (fun b => F (a,b))) := by - simp only [expect, joint, Fintype.sum_prod_type, Finset.mul_sum, mul_assoc] - -theorem expect_mixture (P : FiniteLaw α) (K : α → FiniteLaw β) (F : β → ℝ) : - (P.mixture K).expect F = P.expect (fun a => (K a).expect F) := by - simp only [expect, mixture, Finset.sum_mul, Finset.mul_sum, mul_assoc] - exact Finset.sum_comm - -theorem mixture_eq_bind (P : FiniteLaw α) (K : α → FiniteLaw β) : - P.mixture K = P.bind K := rfl - -/-- Independent maps commute with the literal finite product law. -/ -theorem coordinateProduct_map {n : ℕ} (P : Fin n → FiniteLaw α) - (f : Fin n → α → β) : - (coordinateProduct P).map (fun a i => f i (a i)) = - coordinateProduct (fun i => (P i).map (f i)) := by - apply FiniteLaw.ext - funext b - rw [map_mass] - change (∑ a : Fin n → α, if (fun i => f i (a i)) = b then ∏ i, (P i).mass (a i) else 0) = - ∏ i, ((P i).map (f i)).mass (b i) - simp_rw [map_mass] - rw [Fintype.prod_sum] - apply Finset.sum_congr rfl - intro a _ - by_cases hab : (fun i => f i (a i)) = b - · rw [ite_eq_left hab] - apply Finset.prod_congr rfl - intro i _ - rw [ite_eq_left (congrFun hab i)] - · rw [ite_eq_right hab] - symm - have hi : ∃ i, f i (a i) ≠ b i := by - by_contra h - push Not at h - exact hab (funext h) - obtain ⟨i,hi⟩ := hi - exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) - -/-- Forgetting the report recovers the two independent side emissions. -/ -theorem pairedFlagLaw_map (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) - (b : Bool) : - (pairedFlagLaw P Q H hω hP hQ b).map Prod.snd = orientedProd P Q b := by - apply FiniteLaw.ext - funext z - rw [map_mass, Fintype.sum_prod_type] - simp only [pairedFlagLaw] - simp_rw [Finset.sum_ite_eq'] - simp only [Finset.mem_univ, ite_true] - exact pairedFlag_simulation P Q H ω b z - -end FiniteLaw - -variable {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] {m n : ℕ} - -/-- Data of the paired mechanisms, with common submass proved for each side. -All words and their actual trace laws will be substituted in these fields. -/ -structure PairedMechanisms (Side : Type*) [Fintype Side] (m : ℕ) where - first : Fin m → FiniteLaw Side - second : Fin m → FiniteLaw Side - common : Fin m → FiniteLaw Side - hiddenWeight : Fin m → ℝ - weight_nonneg : ∀ i, 0 ≤ hiddenWeight i - common_first : ∀ i a, hiddenWeight i*(common i).mass a ≤ (first i).mass a - common_second : ∀ i a, hiddenWeight i*(common i).mass a ≤ (second i).mass a - -abbrev Reports (Side : Type*) (m : ℕ) := Fin m → Option Bool × (Side × Side) - -namespace PairedMechanisms -variable (M : PairedMechanisms Side m) - -def reports : FiniteLaw (Reports Side m) := - FiniteLaw.coordinateProduct (fun i => FiniteLaw.pairedReport (M.first i) (M.second i) - (M.common i) (M.weight_nonneg i) (M.common_first i) (M.common_second i)) - -def reportsGiven (b : Fin m → Bool) : FiniteLaw (Reports Side m) := - FiniteLaw.coordinateProduct (fun i => FiniteLaw.pairedFlagLaw (M.first i) (M.second i) - (M.common i) (M.weight_nonneg i) (M.common_first i) (M.common_second i) (b i)) - -/-- Bit orientations, prior to generating any emissions. -/ -def fairOrientations (m : ℕ) : FiniteLaw (Fin m → Bool) := - (FiniteLaw.flagPosterior none).product m - -/-- Exact posterior, with zero-mass metadata treated by the same canonical -formula. In particular unseen orientations are independent fair bits. -/ -def orientationsGiven (z : Reports Side m) : FiniteLaw (Fin m → Bool) := - FiniteLaw.coordinateProduct (fun i => FiniteLaw.flagPosterior (z i).1) - -def selectedLeafLaw (P Q : FiniteLaw Leaf) (θ : Fin n → Bool) : - FiniteLaw (Fin n → Leaf) := - FiniteLaw.coordinateProduct (fun i => if θ i then Q else P) - -/-- Actual orientation-first, unconditioned augmented observation. -/ -def orientationOracle (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : - FiniteLaw (Reports Side m × (Fin n → Leaf)) := - (fairOrientations m).mixture (fun b => (M.reportsGiven b).prod (selectedLeafLaw P Q (θ b))) - -/-- Metadata-first factorization of exactly the same law, not a new oracle. -/ -def canonicalOracle (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : - FiniteLaw (Reports Side m × (Fin n → Leaf)) := - M.reports.joint (fun z => (orientationsGiven z).mixture (fun b => selectedLeafLaw P Q (θ b))) - -theorem oracle_factorization (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : - M.orientationOracle P Q θ = M.canonicalOracle P Q θ := by - apply FiniteLaw.ext - funext zx - rcases zx with ⟨z,x⟩ - change (∑ b, (∏ i : Fin m, (1/2:ℝ)) * - ((∏ i, FiniteLaw.pairedFlagMass (M.first i) (M.second i) (M.common i) - (M.hiddenWeight i) (b i) (z i)) * (selectedLeafLaw P Q (θ b)).mass x)) = - (∏ i, FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) - (M.hiddenWeight i) (z i)) * - (∑ b, (∏ i, (FiniteLaw.flagPosterior (z i).1).mass (b i)) * (selectedLeafLaw P Q (θ b)).mass x) - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro b _ - rw [← mul_assoc, ← Finset.prod_mul_distrib, - FiniteLaw.pairedFlags_product_bayes, mul_assoc] - -/-- The reference is independent old-first-law emissions, even after reporting -all side traces. This equality is exact for every metadata value. -/ -theorem canonicalOracle_density (P Q : FiniteLaw Leaf) (Z : Leaf → ℝ) - (hZ : ∀ a, Q.mass a = P.mass a*(1+Z a)) - (θ : (Fin m → Bool) → Fin n → Bool) (z : Reports Side m) (x : Fin n → Leaf) : - (M.canonicalOracle P Q θ).mass (z,x) = - (M.reports.prod (P.product n)).mass (z,x) * - averagedDensity (orientationsGiven z) θ Z x := by - change M.reports.mass z * - ((orientationsGiven z).mixture (fun b => FiniteLaw.coordinateProduct - (fun i => if θ b i then Q else P))).mass x = _ - rw [leaf_oracle_density P Q Z hZ] - exact (mul_assoc _ _ _).symm - -/-- The full side metadata has a common law for both hypotheses. -/ -theorem canonicalOracle_metadata (P Q : FiniteLaw Leaf) - (θ : (Fin m → Bool) → Fin n → Bool) (F : Reports Side m → ℝ) : - (M.canonicalOracle P Q θ).expect (fun z => F z.1) = M.reports.expect F := by - rw [canonicalOracle, FiniteLaw.expect_joint] - simp only [FiniteLaw.expect_const] - -/-- Conditional on every orientation, forgetting flags gives independent side -emissions. This is the unconditional simulation side of the construction. -/ -theorem reportsGiven_forget (b : Fin m → Bool) : - (M.reportsGiven b).map (fun z i => (z i).2) = - FiniteLaw.coordinateProduct (fun i => FiniteLaw.orientedProd (M.first i) (M.second i) (b i)) := by - rw [reportsGiven, FiniteLaw.coordinateProduct_map] - congr 1 - funext i - exact FiniteLaw.pairedFlagLaw_map _ _ _ _ _ _ _ - -end PairedMechanisms -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.InitialMoments + +namespace OAI + +/-! +# Oracles + +TV kernels and trace simulation, anchor costs, counted primitives, common-part lifting, concrete oracle pairs, and paired-flag metadata. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction.FiniteLaw +open scoped Classical +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +@[ext] theorem law_ext {P Q : FiniteLaw α} (h : ∀a,P.mass a=Q.mass a) : P=Q := by + cases P; cases Q; congr; exact funext h + +theorem tv_self (P : FiniteLaw α) : P.tv P=0 := by simp [tv] + +theorem tv_le_one (P Q : FiniteLaw α) : P.tv Q≤1 := by + unfold tv + have h : (∑a,|P.mass a-Q.mass a|)≤2 := by + calc + _ ≤ ∑a, (P.mass a+Q.mass a) := Finset.sum_le_sum (fun a _ => + (abs_sub (P.mass a) (Q.mass a)).trans_eq (by rw [abs_of_nonneg (P.nonneg a),abs_of_nonneg (Q.nonneg a)])) + _ = 2 := by rw [Finset.sum_add_distrib,P.total,Q.total]; norm_num + linarith + +theorem expect_bind (P : FiniteLaw α) (K : α → FiniteLaw β) (f : β → ℝ) : + (P.bind K).expect f=P.expect (fun a => (K a).expect f) := by + unfold expect bind + simp_rw [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + ring + +theorem bind_assoc (P : FiniteLaw α) (K : α → FiniteLaw β) (L : β → FiniteLaw γ) : + (P.bind K).bind L=P.bind (fun a => (K a).bind L) := by + apply law_ext + intro c + simp only [bind,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + ring + +theorem tv_bind_kernel_le (P : FiniteLaw α) (K L : α → FiniteLaw β) : + (P.bind K).tv (P.bind L) ≤ P.expect (fun a => (K a).tv (L a)) := by + unfold tv bind expect + simp only + calc + _ = (1/2:ℝ)*∑b, |∑a,P.mass a*((K a).mass b-(L a).mass b)| := by + congr 1 + apply Finset.sum_congr rfl + intro b _ + congr 1 + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _ + ring + _ ≤ (1/2:ℝ)*∑b,∑a,P.mass a*|(K a).mass b-(L a).mass b| := by + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Finset.sum_le_sum + intro b _ + simpa only [abs_mul,abs_of_nonneg (P.nonneg _)] using + Finset.abs_sum_le_sum_abs (fun a => P.mass a*((K a).mass b-(L a).mass b)) Finset.univ + _ = _ := by + rw [Finset.sum_comm,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [← Finset.mul_sum] + ring + +/-- An invalid layout is charged only its unconditional probability. -/ +theorem tv_bind_fit_le (P : FiniteLaw α) (K L : α → FiniteLaw β) + (good : α → Prop) [DecidablePred good] (E : ℝ) + (hfit : ∀a,good a → (K a).tv (L a)≤E) : + (P.bind K).tv (P.bind L) ≤ P.expect (fun a => if good a then E else 1) := by + apply (tv_bind_kernel_le P K L).trans + apply expect_mono + intro a + split_ifs with h + · exact hfit a h + · exact tv_le_one _ _ + +theorem tv_prod_eq_left (P Q : FiniteLaw α) (R : FiniteLaw β) : + (P.prod R).tv (Q.prod R)=P.tv Q := by + unfold tv prod + congr 1 + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + simp_rw [← sub_mul,abs_mul,abs_of_nonneg (R.nonneg _),← Finset.mul_sum,R.total,mul_one] + +theorem tv_prod_eq_right (P : FiniteLaw α) (Q R : FiniteLaw β) : + (P.prod Q).tv (P.prod R)=Q.tv R := by + unfold tv prod + congr 1 + rw [Fintype.sum_prod_type] + simp_rw [← mul_sub,abs_mul,abs_of_nonneg (P.nonneg _),← Finset.mul_sum] + rw [← Finset.sum_mul,P.total,one_mul] + +theorem tv_prod_le (P Q : FiniteLaw α) (R S : FiniteLaw β) : + (P.prod R).tv (Q.prod S) ≤ P.tv Q+R.tv S := by + have H := tv_triangle (P.prod R) (Q.prod R) (Q.prod S) + rwa [tv_prod_eq_left,tv_prod_eq_right] at H + +end TraceReconstruction.FiniteLaw + + +noncomputable section +namespace TraceReconstruction.FiniteLaw +open scoped Classical +variable {α : Type*} [Fintype α] + +theorem coordinateProduct_succ_tv {n : ℕ} (P Q : Fin (n+1) → FiniteLaw α) : + (coordinateProduct P).tv (coordinateProduct Q) = + ((P 0).prod (coordinateProduct (fun i => P i.succ))).tv + ((Q 0).prod (coordinateProduct (fun i => Q i.succ))) := by + change (1/2:ℝ)*(∑x : Fin (n+1) → α, |(∏i,(P i).mass (x i))-(∏i,(Q i).mass (x i))|)= + (1/2:ℝ)*∑x : α × (Fin n → α), |(P 0).mass x.1*(∏i,(P i.succ).mass (x.2 i))-(Q 0).mass x.1*(∏i,(Q i.succ).mass (x.2 i))| + congr 1 + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => α)).sum_comp] + apply Finset.sum_congr rfl + intro x _ + simp only [Fin.consEquiv,Equiv.coe_fn_mk,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] + +theorem tv_coordinateProduct_le {n : ℕ} (P Q : Fin n → FiniteLaw α) : + (coordinateProduct P).tv (coordinateProduct Q) ≤ ∑i, (P i).tv (Q i) := by + induction n with + | zero => simp [tv,coordinateProduct] + | succ n ih => + rw [coordinateProduct_succ_tv,Fin.sum_univ_succ] + exact (tv_prod_le _ _ _ _).trans (by linarith [ih (fun i => P i.succ) (fun i => Q i.succ)]) + +theorem expect_coordinateProduct_succ {n : ℕ} (P : Fin (n+1) → FiniteLaw α) + (F : (Fin (n+1) → α) → ℝ) : + (coordinateProduct P).expect F = + (P 0).expect (fun a => (coordinateProduct (fun i => P i.succ)).expect + (fun x => F (Fin.cons a x))) := by + change (∑x : Fin (n+1) → α, (∏i,(P i).mass (x i))*F x)= + ∑a : α, (P 0).mass a*(∑x : Fin n → α, (∏i,(P i.succ).mass (x i))*F (Fin.cons a x)) + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => α)).sum_comp,Fintype.sum_prod_type] + simp only [Fin.consEquiv,Equiv.coe_fn_mk,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] + simp_rw [Finset.mul_sum,mul_assoc] + +end TraceReconstruction.FiniteLaw + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem FiniteLaw.expect_sub {α : Type*} [Fintype α] (P : FiniteLaw α) + (F G : α → ℝ) : P.expect (fun a => F a-G a)=P.expect F-P.expect G := by + simp only [FiniteLaw.expect,mul_sub,Finset.sum_sub_distrib] + +theorem FiniteLaw.abs_expect_le {α : Type*} [Fintype α] (P : FiniteLaw α) (F : α → ℝ) : + |P.expect F|≤P.expect (fun a => |F a|) := by + simpa only [FiniteLaw.expect,abs_mul,abs_of_nonneg (P.nonneg _)] using + Finset.abs_sum_le_sum_abs (fun a => P.mass a*F a) Finset.univ + +/-- A finite auxiliary observation, decoded by a fixed function, simulates the +usual deletion channel on a literal binary word. Test functions range over the +observable traces only, never latent boundaries. -/ +def SimulatesTrace {α : Type*} [Fintype α] (q : ℝ) (P : FiniteLaw α) + (decode : α → List Bool) (w : List Bool) : Prop := + ∀ F : List Bool → ℝ, P.expect (fun a => F (decode a))=listDeletionExpectation q w F + +def ApproximatesTrace {α : Type*} [Fintype α] (q : ℝ) (P : FiniteLaw α) + (decode : α → List Bool) (w : List Bool) (E : ℝ) : Prop := + ∀ F : List Bool → ℝ, (∀t,F t∈Set.Icc 0 1) → + |P.expect (fun a => F (decode a))-listDeletionExpectation q w F|≤E + +theorem listDeletionExpectation_const (q c : ℝ) (w : List Bool) : + listDeletionExpectation q w (fun _ => c)=c := by + induction w with + | nil => rfl + | cons b w ih => simp only [listDeletionExpectation,ih]; ring + +theorem listDeletionExpectation_linear (q : ℝ) (w : List Bool) + (a b : ℝ) (F G : List Bool → ℝ) : + listDeletionExpectation q w (fun t => a*F t+b*G t)= + a*listDeletionExpectation q w F+b*listDeletionExpectation q w G := by + induction w generalizing F G with + | nil => rfl + | cons c w ih => simp only [listDeletionExpectation,ih]; ring + +theorem listDeletionExpectation_mono {q : ℝ} (hq : q∈Set.Icc 0 1) + (w : List Bool) {F G : List Bool → ℝ} (h : ∀t,F t≤G t) : + listDeletionExpectation q w F≤listDeletionExpectation q w G := by + induction w generalizing F G with + | nil => exact h [] + | cons b w ih => + exact add_le_add (mul_le_mul_of_nonneg_left (ih h) hq.1) + (mul_le_mul_of_nonneg_left (ih (fun t => h (b::t))) (sub_nonneg.mpr hq.2)) + +theorem listDeletionExpectation_range {q : ℝ} (hq : q∈Set.Icc 0 1) + (w : List Bool) (F : List Bool → ℝ) (hF : ∀t,F t∈Set.Icc 0 1) : + listDeletionExpectation q w F∈Set.Icc 0 1 := by + constructor + · simpa only [listDeletionExpectation_const] using + listDeletionExpectation_mono hq w (fun t => (hF t).1) + · simpa only [listDeletionExpectation_const] using + listDeletionExpectation_mono hq w (fun t => (hF t).2) + +theorem listDeletionExpectation_sum {α : Type*} [Fintype α] (q : ℝ) + (w : List Bool) (F : α → List Bool → ℝ) : + listDeletionExpectation q w (fun t => ∑a,F a t)= + ∑a,listDeletionExpectation q w (F a) := by + induction w generalizing F with + | nil => rfl + | cons b w ih => + simp only [listDeletionExpectation,ih,Finset.mul_sum,Finset.sum_add_distrib] + +theorem FiniteLaw.expect_listDeletionExpectation {α : Type*} [Fintype α] + (P : FiniteLaw α) (q : ℝ) (w : List Bool) (F : α → List Bool → ℝ) : + P.expect (fun a => listDeletionExpectation q w (F a))= + listDeletionExpectation q w (fun t => P.expect (fun a => F a t)) := by + unfold FiniteLaw.expect + rw [listDeletionExpectation_sum] + apply Finset.sum_congr rfl + intro a _ + have H := listDeletionExpectation_linear q w (P.mass a) 0 (F a) (fun _ => 0) + simpa only [zero_mul,add_zero] using H.symm + +theorem SimulatesTrace.append {α β : Type*} [Fintype α] [Fintype β] + {q : ℝ} {P : FiniteLaw α} {Q : FiniteLaw β} {f : α → List Bool} {g : β → List Bool} + {x y : List Bool} (hP : SimulatesTrace q P f x) (hQ : SimulatesTrace q Q g y) : + SimulatesTrace q (P.prod Q) (fun a => f a.1++g a.2) (x++y) := by + intro F + rw [FiniteLaw.expect_prod,listDeletionExpectation_append] + change P.expect (fun a => Q.expect (fun b => F (f a++g b)))=_ + unfold SimulatesTrace at hP hQ + calc + _ = P.expect (fun a => listDeletionExpectation q y (fun t => F (f a++t))) := + congrArg P.expect (funext fun a => hQ (fun t => F (f a++t))) + _ = _ := hP (fun t => listDeletionExpectation q y (fun u => F (t++u))) + +theorem SimulatesTrace.approximate {α : Type*} [Fintype α] + {q : ℝ} {P : FiniteLaw α} {f : α → List Bool} {w : List Bool} + (h : SimulatesTrace q P f w) : ApproximatesTrace q P f w 0 := by + intro F _ + rw [h,sub_self,abs_zero] + +theorem ApproximatesTrace.append {α β : Type*} [Fintype α] [Fintype β] + {q : ℝ} (hq : q∈Set.Icc 0 1) {P : FiniteLaw α} {Q : FiniteLaw β} + {f : α → List Bool} {g : β → List Bool} {x y : List Bool} {E D : ℝ} + (hP : ApproximatesTrace q P f x E) (hQ : ApproximatesTrace q Q g y D) : + ApproximatesTrace q (P.prod Q) (fun a => f a.1++g a.2) (x++y) (E+D) := by + intro F hF + rw [FiniteLaw.expect_prod,listDeletionExpectation_append] + let H : List Bool → ℝ := fun t => listDeletionExpectation q y (fun u => F (t++u)) + have hH : ∀t,H t∈Set.Icc 0 1 := fun t => listDeletionExpectation_range hq y _ (fun u => hF (t++u)) + have h1 := hP H hH + have h2 : |P.expect (fun a => Q.expect (fun b => F (f a++g b)))-P.expect (fun a => H (f a))|≤D := by + rw [← FiniteLaw.expect_sub] + calc + _ ≤ P.expect (fun a => |Q.expect (fun b => F (f a++g b))-H (f a)|) := FiniteLaw.abs_expect_le _ _ + _ ≤ P.expect (fun _ => D) := FiniteLaw.expect_mono _ (fun a => hQ _ (fun t => hF (f a++t))) + _ = D := FiniteLaw.expect_const _ _ + exact (abs_sub_le _ _ _).trans (by linarith only [h1,h2]) + +/-- Any randomized partition into exactly the same literal word gives exactly +its usual trace after boundaries are forgotten. No fit conditioning occurs. -/ +theorem SimulatesTrace.random_partition {α Ω : Type*} [Fintype α] [Fintype Ω] + {q : ℝ} (P : FiniteLaw Ω) (K : Ω → FiniteLaw α) (decode : α → List Bool) + (w : List Bool) (h : ∀ω,SimulatesTrace q (K ω) decode w) : + SimulatesTrace q (P.bind K) decode w := by + intro F + rw [FiniteLaw.expect_bind] + unfold SimulatesTrace at h + simp_rw [h] + exact FiniteLaw.expect_const _ _ + +/-- A failed deterministic layout is charged its unconditional probability; +the conditional law on all metadata, not a fit-conditioned law, is used. -/ +theorem ApproximatesTrace.random_partition {α Ω : Type*} [Fintype α] [Fintype Ω] + {q : ℝ} (hq : q∈Set.Icc 0 1) (P : FiniteLaw Ω) (K : Ω → FiniteLaw α) + (decode : α → List Bool) (w : List Bool) (good : Ω → Prop) [DecidablePred good] + (E : ℝ) (h : ∀ω,good ω → ApproximatesTrace q (K ω) decode w E) : + ApproximatesTrace q (P.bind K) decode w (P.expect (fun ω => if good ω then E else 1)) := by + intro F hF + rw [FiniteLaw.expect_bind,← FiniteLaw.expect_const P (listDeletionExpectation q w F),← FiniteLaw.expect_sub] + apply (FiniteLaw.abs_expect_le _ _).trans + apply FiniteLaw.expect_mono + intro ω + split_ifs with hgood + · exact h ω hgood F hF + · have hc := listDeletionExpectation_range hq w F hF + have hn := FiniteLaw.expect_mono (K ω) (fun a => (hF (decode a)).1) + have hu := FiniteLaw.expect_mono (K ω) (fun a => (hF (decode a)).2) + rw [FiniteLaw.expect_const] at hn hu + exact abs_le.mpr ⟨by linarith [hc.2],by linarith [hc.1]⟩ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Admissible close child labels, without relaxing any plateau restrictions +on the anchor. An arbitrary finite label domain is retained. -/ +def closeLabels (A : Finset ℤ) (L : ℕ) (a : ℤ) : Finset ℤ := + A.filter (fun c => |c-a| < (L:ℤ)) + +theorem closeLabels_card (A : Finset ℤ) (L : ℕ) (a : ℤ) : + (closeLabels A L a).card ≤ 2*L := by + have hsub : closeLabels A L a ⊆ Finset.Ioo (a-(L:ℤ)) (a+(L:ℤ)) := by + intro c hc + have h := abs_lt.mp ((Finset.mem_filter.mp hc).2) + exact Finset.mem_Ioo.mpr ⟨by omega,by omega⟩ + have H := Finset.card_le_card hsub + rw [Int.card_Ioo] at H + omega + +/-- Root anchor and close-child energy. This keeps the actual labels finite, +including any additional source plateau cutoff. -/ +theorem root_anchor_energy (n L : ℕ) (A B : Finset ℤ) (c : ℤ) : + (∑ a∈A, ∑ _d∈closeLabels B L a, windowKernel n L (a-c)^2) ≤ + 2*L^3*binomialBound n := by + calc + _ ≤ ∑a∈A, (2*L:ℝ)*windowKernel n L (a-c)^2 := by + apply Finset.sum_le_sum + intro a _ + simp only [Finset.sum_const,nsmul_eq_mul] + exact mul_le_mul_of_nonneg_right (by exact_mod_cast closeLabels_card B L a) (sq_nonneg _) + _ = (2*L:ℝ)*(∑a∈A,windowKernel n L (a-c)^2) := by rw [Finset.mul_sum] + _ ≤ (2*L:ℝ)*(L^2*binomialBound n) := + mul_le_mul_of_nonneg_left (windowKernel_energy n L A c) (by positivity) + _ = _ := by ring + +/-- The shared global jitter stays in the joint kernel until after squaring. +The two close labels cost only (2L)^2, uniformly in parent labels. -/ +theorem sibling_anchor_energy (g n₁ n₂ L : ℕ) (A B C D : Finset ℤ) (c₁ c₂ : ℤ) : + (∑ a∈A, ∑ b∈B, ∑ _c∈closeLabels C L a, ∑ _d∈closeLabels D L b, + jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2) ≤ + 4*L^6*binomialBound g*binomialBound n₂ := by + calc + _ ≤ ∑a∈A, ∑b∈B, (2*L:ℝ)^2*jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2 := by + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro b _ + simp only [Finset.sum_const,nsmul_eq_mul] + have hc : ((closeLabels C L a).card:ℝ)≤2*L := by exact_mod_cast closeLabels_card C L a + have hd : ((closeLabels D L b).card:ℝ)≤2*L := by exact_mod_cast closeLabels_card D L b + have hm := mul_le_mul hc hd (by positivity) (by positivity : (0:ℝ)≤2*L) + rw [mul_assoc] at hm + nlinarith [mul_le_mul_of_nonneg_right hm (sq_nonneg (jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)))] + _ = (2*L:ℝ)^2*(∑a∈A,∑b∈B,jointWindowKernel g n₁ n₂ L (a-c₁) (b-c₂)^2) := by + simp_rw [Finset.mul_sum] + _ ≤ (2*L:ℝ)^2*(L^4*binomialBound g*binomialBound n₂) := + mul_le_mul_of_nonneg_left (jointWindowKernel_energy g n₁ n₂ L A B c₁ c₂) (by positivity) + _ = _ := by ring + +/-- Exact bottom-up summation of any finite binary anchor model. The state +contains its actual index path, so group-dependent kernels are allowed. -/ +def binaryTreeSum {α : Type*} [Fintype α] (K : ℕ → α → α × α → ℝ) : ℕ → α → ℝ + | 0, _ => 1 + | n+1, a => ∑b, K n a b*binaryTreeSum K n b.1*binaryTreeSum K n b.2 + +def binaryTreeBudget (C : ℕ → ℝ) : ℕ → ℝ + | 0 => 1 + | n+1 => C n*(binaryTreeBudget C n)^2 + +theorem binaryTreeBudget_nonneg (C : ℕ → ℝ) (hC : ∀n,0≤C n) (n : ℕ) : + 0≤binaryTreeBudget C n := by + cases n with + | zero => norm_num [binaryTreeBudget] + | succ n => exact mul_nonneg (hC n) (sq_nonneg _) + +theorem binaryTreeSum_nonneg {α : Type*} [Fintype α] + (K : ℕ → α → α × α → ℝ) (hK : ∀n a b,0≤K n a b) (n : ℕ) (a : α) : + 0≤binaryTreeSum K n a := by + induction n generalizing a with + | zero => norm_num [binaryTreeSum] + | succ n ih => exact Finset.sum_nonneg (fun b _ => mul_nonneg (mul_nonneg (hK n a b) (ih b.1)) (ih b.2)) + +/-- Uniform local anchor square sums multiply without decoupling the two +correlated offsets of a sibling group. Domain/plateau indicators can be +included in K and are never removed by conditioning. -/ +theorem binaryTreeSum_le {α : Type*} [Fintype α] + (K : ℕ → α → α × α → ℝ) (hK : ∀n a b,0≤K n a b) + (C : ℕ → ℝ) (hC : ∀n,0≤C n) (hlocal : ∀n a, (∑b,K n a b)≤C n) + (n : ℕ) (a : α) : binaryTreeSum K n a≤binaryTreeBudget C n := by + induction n generalizing a with + | zero => rfl + | succ n ih => + calc + _ ≤ ∑b, K n a b*(binaryTreeBudget C n)^2 := by + apply Finset.sum_le_sum + intro b _ + rw [mul_assoc,pow_two] + exact mul_le_mul_of_nonneg_left (mul_le_mul (ih b.1) (ih b.2) + (binaryTreeSum_nonneg K hK n b.2) (binaryTreeBudget_nonneg C hC n)) (hK n a b) + _ = (∑b,K n a b)*(binaryTreeBudget C n)^2 := by rw [Finset.sum_mul] + _ ≤ C n*(binaryTreeBudget C n)^2 := mul_le_mul_of_nonneg_right (hlocal n a) (sq_nonneg _) + _ = _ := rfl + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem hypergeomMass_middle_sq (V M m v : ℕ) {p : ℝ} + (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) + (hN : 16≤V+M) (hm : m≤V+M) (hmean : (m:ℝ)=(V+M:ℕ)*p) : + hypergeomMass V M m v^2≤4096/((M:ℝ)+1) := by + have hp' : p∈Set.Ioo (0:ℝ) 1 := by constructor <;> linarith [hp.1,hp.2] + have hpp : (1/8:ℝ)≤p*(1-p) := by nlinarith [sq_nonneg (p-1/2),mul_nonneg (sub_nonneg.mpr hp.1) (sub_nonneg.mpr hp.2)] + have hNr : (16:ℝ)≤(V:ℝ)+M := by exact_mod_cast hN + have hVr : (M:ℝ)≤V := by exact_mod_cast hMV + have hv : 1≤(V+M:ℕ)*p*(1-p) := by + push_cast + nlinarith [Nat.cast_nonneg (α:=ℝ) V,Nat.cast_nonneg (α:=ℝ) M] + have H := hypergeomMass_sq_upper V M m v hp' hm hmean hv + apply H.trans + have hd : 0<((V:ℝ)+1)*((M:ℝ)+1)*p*(1-p) := by positivity [hp'.1,sub_pos.mpr hp'.2] + apply (div_le_iff₀ hd).2 + have hM : 0<(M:ℝ)+1 := by positivity + have he : 4096/((M:ℝ)+1)*(((V:ℝ)+1)*((M:ℝ)+1)*p*(1-p))= + 4096*((V:ℝ)+1)*(p*(1-p)) := by field_simp + rw [he] + push_cast + nlinarith [mul_le_mul_of_nonneg_left hpp (show 0≤(V:ℝ)+1 by positivity)] + +theorem hypergeomMass_middle_le (V M m v : ℕ) {p : ℝ} + (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) + (hN : 16≤V+M) (hm : m≤V+M) (hmean : (m:ℝ)=(V+M:ℕ)*p) : + hypergeomMass V M m v≤64/Real.sqrt ((M:ℝ)+1) := by + have H := hypergeomMass_middle_sq V M m v hp hMV hN hm hmean + have hs : 0 + hypergeomMass_above_total V M m k (by omega))] + exact sum_hypergeomMass V M m hm + +theorem hypergeomMass_complement (V M m v : ℕ) (hv : v≤ m) : + hypergeomMass V M m v=hypergeomMass M V m (m-v) := by + simp only [hypergeomMass,ite_eq_left hv,ite_eq_left (Nat.sub_le _ _),Nat.sub_sub_self hv] + rw [Nat.add_comm M V,mul_comm] + +theorem hypergeomLaw_adjacent_tv (V M m : ℕ) (hM : M≤ m) (hV : m |hypergeomMass V M (m+1) v- + hypergeomMass V M m v|)] + rw [sum_range_extend_zero (show m+2≤V+M+1 by omega) (fun k hk => by + rw [hypergeomMass_above_total V M (m+1) k (by omega), + hypergeomMass_above_total V M m k (by omega),sub_self,abs_zero])] + rw [←Finset.sum_range_reflect (fun v => |hypergeomMass V M (m+1) v- + hypergeomMass V M m v|) (m+2)] + rw [show m+2=(m+1)+1 by omega,Finset.sum_range_succ'] + have hzero : |hypergeomMass V M (m+1) (m+1)-hypergeomMass V M m (m+1)|= + hypergeomMass M V (m+1) 0 := by + rw [hypergeomMass_above_total V M m (m+1) (by omega),sub_zero, + hypergeomMass_complement V M (m+1) (m+1) le_rfl,Nat.sub_self, + abs_of_nonneg (hypergeomMass_nonneg _ _ _ _)] + have he (k : ℕ) (hk : k∈Finset.range (m+1)) : + |hypergeomMass V M (m+1) ((m+1+1)-1-(k+1))- + hypergeomMass V M m ((m+1+1)-1-(k+1))|= + |hypergeomMass M V (m+1) (k+1)-hypergeomMass M V m k| := by + have hk' : k≤ m := by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hk + rw [show (m+1+1)-1-(k+1)=m-k by omega, + hypergeomMass_complement V M (m+1) (m-k) (by omega), + hypergeomMass_complement V M m (m-k) (by omega)] + rw [show m+1-(m-k)=k+1 by omega,show m-(m-k)=k by omega] + rw [Finset.sum_congr rfl he] + simp only [Nat.add_sub_cancel,Nat.sub_zero,hzero] + rw [sum_range_extend_zero (Nat.add_le_add_right hM 1) (fun k hk => by + rw [hypergeomMass_high M V (m+1) (k+1) (by omega), + hypergeomMass_high M V m k (by omega),sub_self,abs_zero])] + unfold adjacentHypergeomTV + ring + +theorem adjacentHypergeomTV_middle_le (V M m : ℕ) {p : ℝ} + (hp : p∈Set.Icc (1/4:ℝ) (3/4:ℝ)) (hMV : M≤V) + (hN : 16≤V+M) (hM : M≤ m) (hV : m simp [FiniteLaw.tv_self] + | succ n ih => + rw [Finset.sum_range_succ] + linarith [FiniteLaw.tv_triangle (P 0) (P n) (P (n+1))] + +theorem hypergeomLaw_steps (V M m P : ℕ) (hN : 16≤V+M) + (hM : M≤ m) (hV : m+P + hypergeomLaw V M (m+min j P) (by omega) + have H := FiniteLaw.tv_chain Q P + have hQ0 : Q 0=hypergeomLaw V M m (by omega) := by simp [Q] + have hQP : Q P=hypergeomLaw V M (m+P) (by omega) := by simp [Q] + rw [hQ0,hQP] at H + apply H.trans + calc + _≤∑j∈Finset.range P,64/Real.sqrt ((M:ℝ)+1) := by + apply Finset.sum_le_sum + intro j hj + have hj' : j

|g a/f a-1|^(2*k)) ≤ - 2^(2*k)*V^k := by - apply hraw.trans - calc - _ ≤ (2^(2*k-1)/p)*V^k := mul_le_mul_of_nonneg_left hM (by positivity) - _ ≤ (2^(2*k-1)*2)*V^k := by - apply mul_le_mul_of_nonneg_right _ (pow_nonneg hV _) - simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hden (by positivity : 0 ≤ (2:ℝ)^(2*k-1)) - _ = _ := by rw [←pow_succ,ht] - have hnorm : |p/q-1|^(2*k) ≤ 2^(2*k)*V^k := by - rw [div_sub_one hq0.ne',abs_div,abs_of_pos hq0,div_pow] - apply (div_le_iff₀ (pow_pos hq0 _)).mpr - have hd := (clipping_mass_difference R f g hf hg hfm hgm A (2*k)).trans hM - have hqpow : 1 ≤ (2*q)^(2*k) := one_le_pow₀ (by linarith) - calc - _ ≤ V^k := hd - _ ≤ (2*q)^(2*k)*V^k := by nlinarith [pow_nonneg hV k] - _ = _ := by rw [mul_pow]; ring - have hs := score_rescaling_moment (condition (R.withDensity f hf hfm) A hp0) - (fun a => g a/f a) (p/q) (div_nonneg hp0.le hq0.le) (2*k-1) - rw [ht] at hs - have hpower : (p/q)^(2*k) ≤ (2:ℝ)^(2*k) := - pow_le_pow_left₀ (div_nonneg hp0.le hq0.le) hratio _ - have hs' : (condition (R.withDensity f hf hfm) A hp0).expect (fun a => |p/q*(g a/f a)-1|^(2*k)) ≤ - (64*V)^k := by - apply hs.trans - calc - _ ≤ 2^(2*k-1)*(2^(2*k)*(2^(2*k)*V^k)+2^(2*k)*V^k) := by - apply mul_le_mul_of_nonneg_left _ (by positivity) - exact add_le_add (mul_le_mul hpower hraw' (by - apply Finset.sum_nonneg; intro a _; positivity [(condition (R.withDensity f hf hfm) A hp0).nonneg a]) (by positivity)) hnorm - _ ≤ 2^(2*k-1)*(2^(2*k)*(2^(2*k)*V^k)+2^(2*k)*(2^(2*k)*V^k)) := by - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply add_le_add_right - have htwo : (1:ℝ) ≤ 2^(2*k) := one_le_pow₀ (by norm_num) - simpa only [one_mul] using mul_le_mul_of_nonneg_right htwo - (by positivity : 0 ≤ (2:ℝ)^(2*k)*V^k) - _ = (64*V)^k := by - have hm : 2^(2*k-1)*2= (2:ℝ)^(2*k) := by rw [←pow_succ,ht] - calc - _ = (2^(2*k-1)*2)*(2:ℝ)^(2*k)*(2:ℝ)^(2*k)*V^k := by ring - _ = _ := by rw [hm,←pow_add,←pow_add,mul_pow]; congr 1; rw [show 2*k+2*k+2*k=6*k by omega,pow_mul]; norm_num - unfold evenMomentSq - calc - _ ≤ ((64*V)^k)^(1/(k:ℝ)) := Real.rpow_le_rpow - (by apply Finset.sum_nonneg; intro a _; positivity [(condition (R.withDensity f hf hfm) A hp0).nonneg a]) hs' (by positivity) - _ = _ := by rw [←Real.rpow_natCast,one_div,Real.rpow_rpow_inv (by positivity) (by positivity)] - -end TraceReconstruction.FiniteLaw - -noncomputable section -namespace TraceReconstruction.FiniteLaw -open scoped Classical -variable {α : Type*} [Fintype α] - -theorem eventMass_indicator (P : FiniteLaw α) (A : Finset α) : - P.eventMass A=P.expect (fun a => if a∈A then 1 else 0) := by - simp only [expect,mul_ite,mul_one,mul_zero,←Finset.sum_filter, - Finset.filter_mem_eq_inter,Finset.univ_inter,eventMass] - -theorem eventMass_compl (P : FiniteLaw α) (A : Finset α) : - P.eventMass Aᶜ=1-P.eventMass A := by - rw [eventMass_indicator,eventMass_indicator] - have he : P.expect (fun a => (if a∈Aᶜ then (1:ℝ) else 0)+(if a∈A then 1 else 0))=1 := by - convert P.expect_const 1 using 1 - congr 1; funext a - by_cases ha : a∈A <;> simp [ha] - rw [expect_add] at he - linarith - -theorem density_second_moment_le_six (R : FiniteLaw α) (f : α → ℝ) (k : ℕ) (hk : 1 ≤ k) - (hM : R.expect (fun a => |f a-1|^(2*k)) ≤ 1) : - R.expect (fun a => f a^2) ≤ 6 := by - have h := R.expect_lower_moment_le_two (fun a => f a-1) (2*k) hM 2 (by omega) - calc - _ ≤ R.expect (fun a => 2*(f a-1)^2+2) := R.expect_mono (fun a => by nlinarith [sq_nonneg (f a-2)]) - _ = 2*R.expect (fun a => (f a-1)^2)+2 := by rw [expect_add,expect_const_mul,expect_const] - _ ≤ _ := by linarith [le_abs_self (R.expect (fun a => (f a-1)^2))] - -/-- Cauchy--Schwarz loss on the actual low-reference-density event, for - either density. The same clipping event is used for both hypotheses. -/ -theorem density_low_event_mass (R : FiniteLaw α) (f g : α → ℝ) - (hg : ∀a,0 ≤ g a) (hgm : R.expect g=1) (k : ℕ) (hk : 1 ≤ k) (U : ℝ) - (hU : 0 ≤ U) (hU1 : U ≤ 1) - (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) - (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) : - (R.withDensity g hg hgm).eventMass (Finset.univ.filter (fun a => f a<1/2)) ≤ - Real.sqrt (6*(4*U)^k) := by - let A := Finset.univ.filter (fun a => f a<1/2) - have hR : R.eventMass A ≤ (4*U)^k := by - calc - _ ≤ 2^(2*k)*R.expect (fun a => |f a-1|^(2*k)) := - R.low_density_reference_mass f (2*k) A (fun a ha => (Finset.mem_filter.mp ha).2) - _ ≤ 2^(2*k)*U^k := mul_le_mul_of_nonneg_left hfM (by positivity) - _ = _ := by rw [pow_mul,mul_pow]; norm_num - have hsecond := R.density_second_moment_le_six g k hk (hgM.trans (pow_le_one₀ hU hU1)) - have hsq : ((R.withDensity g hg hgm).eventMass A)^2 ≤ 6*(4*U)^k := by - apply (R.density_bad_mass_sq g A).trans - calc - _ ≤ R.eventMass A*6 := mul_le_mul_of_nonneg_left hsecond (R.eventMass_nonneg A) - _ ≤ _ := by nlinarith - exact (Real.le_sqrt ((R.withDensity g hg hgm).eventMass_nonneg A) (by positivity)).mpr hsq - -def commonClipEvent (B : Finset α) (f : α → ℝ) : Finset α := - B.filter (fun a => 1/2 ≤ f a) - -theorem commonClipEvent_loss (P : FiniteLaw α) (B : Finset α) (f : α → ℝ) : - 1-P.eventMass (commonClipEvent B f) ≤ - P.eventMass Bᶜ+P.eventMass (Finset.univ.filter (fun a => f a<1/2)) := by - rw [←eventMass_compl,eventMass_indicator,eventMass_indicator,eventMass_indicator,←expect_add] - apply P.expect_mono - intro a - simp only [commonClipEvent,Finset.mem_compl,Finset.mem_filter,Finset.mem_univ,true_and] - split_ifs <;> simp_all - - -/-- Quantitative common clipping on any genuine good event. Both bad-event - costs below are measured under the actual normalized laws, not reference mass. -/ -theorem commonClipEvent_mass (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) - (B : Finset α) (e : ℝ) (hfB : (R.withDensity f hf hfm).eventMass Bᶜ ≤ e) - (hgB : (R.withDensity g hg hgm).eventMass Bᶜ ≤ e) - (k : ℕ) (hk : 1 ≤ k) (U : ℝ) (hU : 0 ≤ U) (hU1 : U ≤ 1) - (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) - (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) : - 1-(R.withDensity f hf hfm).eventMass (commonClipEvent B f) ≤ e+Real.sqrt (6*(4*U)^k) ∧ - 1-(R.withDensity g hg hgm).eventMass (commonClipEvent B f) ≤ e+Real.sqrt (6*(4*U)^k) := by - constructor - · exact (commonClipEvent_loss _ B f).trans (add_le_add hfB - (density_low_event_mass R f f hf hfm k hk U hU hU1 hfM hfM)) - · exact (commonClipEvent_loss _ B f).trans (add_le_add hgB - (density_low_event_mass R f g hg hgm k hk U hU hU1 hfM hgM)) - -end TraceReconstruction.FiniteLaw - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- A pair produced by genuine common-event normalized conditioning. The - outcome space and public decoder remain unchanged. -/ -structure ClippedOracle {α : Type*} [Fintype α] (P Q : FiniteLaw α) (k : ℕ) (e V : ℝ) where - first : FiniteLaw α - second : FiniteLaw α - score : α → ℝ - density : ∀a,second.mass a=first.mass a*(1+score a) - likelihood_nonneg : ∀a,0 ≤ 1+score a - centered : first.expect score=0 - moment : first.evenMomentSq score k ≤ V - first_tv : first.tv P ≤ e - second_tv : second.tv Q ≤ e - -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -theorem exists_clippedOracle (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) - (B : Finset α) (e : ℝ) (hfB : (R.withDensity f hf hfm).eventMass Bᶜ ≤ e) - (hgB : (R.withDensity g hg hgm).eventMass Bᶜ ≤ e) - (k : ℕ) (hk : 1 ≤ k) (U : ℝ) (hU : 0 ≤ U) (hU1 : U ≤ 1) - (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) - (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) - (V : ℝ) (hV : 0 ≤ V) - (hM : R.expect (fun a => |if a∈B then g a-f a else 0|^(2*k)) ≤ V^k) - (hsmall : e+Real.sqrt (6*(4*U)^k) ≤ 1/2) : - Nonempty (ClippedOracle (R.withDensity f hf hfm) (R.withDensity g hg hgm) - k (e+Real.sqrt (6*(4*U)^k)) (64*V)) := by - let A := commonClipEvent B f - let P := R.withDensity f hf hfm - let Q := R.withDensity g hg hgm - have hA (a : α) (ha : a∈A) : 1/2 ≤ f a := (Finset.mem_filter.mp ha).2 - have hloss := commonClipEvent_mass R f g hf hg hfm hgm B e hfB hgB k hk U hU hU1 hfM hgM - have hp : 1/2 ≤ P.eventMass A := by linarith [hloss.1] - have hq : 1/2 ≤ Q.eventMass A := by linarith [hloss.2] - have hp0 : 0 P.eventMass A/Q.eventMass A*(g a/f a)-1 - have hden (a : α) : (Q.condition A hq0).mass a=(P.condition A hp0).mass a*(1+Z a) := by - dsimp only [Z] - rw [show 1+(P.eventMass A/Q.eventMass A*(g a/f a)-1)=P.eventMass A/Q.eventMass A*(g a/f a) by ring] - exact conditioned_density_identity R f g hf hg hfm hgm A - (fun a ha => lt_of_lt_of_le (by norm_num) (hA a ha)) hp0 hq0 a - have hAM : R.expect (fun a => |if a∈A then g a-f a else 0|^(2*k)) ≤ V^k := by - apply le_trans (R.expect_mono _) hM - intro a - by_cases ha : a∈A - · have hb := (Finset.mem_filter.mp ha).1 - simp only [ite_eq_left ha,ite_eq_left hb,le_refl] - · rw [ite_eq_right ha] - simp only [abs_zero,zero_pow (by omega : 2*k≠0)] - exact pow_nonneg (abs_nonneg _) _ - exact ⟨{ - first := P.condition A hp0 - second := Q.condition A hq0 - score := Z - density := hden - likelihood_nonneg := fun a => by - dsimp only [Z] - have hh := mul_nonneg (div_nonneg hp0.le hq0.le) (div_nonneg (hg a) (hf a)) - linarith - centered := density_score_centered _ _ Z hden - moment := clipped_score_moment R f g hf hg hfm hgm A hA hp hq k hk V hV hAM - first_tv := by rw [tv_symm,tv_condition]; exact hloss.1 - second_tv := by rw [tv_symm,tv_condition]; exact hloss.2 - }⟩ - -end FiniteLaw -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Exact finite-union metadata cost; it contains no postulated typical - event and no independence assertion between different collections. -/ -def sourceEffectiveHiddenTail (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : ℝ := - ∑v : WindowCollection T b,if collectionCount T n (sourceScheduledTrials T n) b v=0 then 0 else Real.exp (-(collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^4/16) - -theorem source_hidden_conditions_effective_tail {Side : Type*} [Fintype Side] - (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n b)) - (ω : ℝ) (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : - M.reports.expect (fun z => if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω b - (sourceReportFlags T n b z) then 0 else 1) ≤ sourceEffectiveHiddenTail T n b ω := by - calc - _ ≤ M.reports.expect (fun z => ∑v : WindowCollection T b, - if (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ - ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) - then 0 else 1) := by - apply FiniteLaw.expect_mono - intro z - simp only [hiddenCollectionConditions_iff] - exact failure_forall_le_sum _ - _ = ∑v : WindowCollection T b,M.reports.expect (fun z => - if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< - ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0) := by - rw [FiniteLaw.expect_fintype_sum] - apply Finset.sum_congr rfl - intro v _ - apply congrArg (FiniteLaw.expect M.reports) - funext z - rw [sourceCollectionSet_card,sourceCollection_hidden,Nat.cast_sum] - by_cases h : (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ - ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) - · simp [h,not_lt.mpr h] - · simp [h,lt_of_not_ge h] - _ ≤ _ := by - apply Finset.sum_le_sum - intro v _ - by_cases hc : collectionCount T n (sourceScheduledTrials T n) b v=0 - · rw [ite_eq_left hc] - have hz : M.reports.expect (fun z => - if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< - ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0)=0 := by - have h (z : Reports Side (SourceTrialCount T n b)) : - ¬(PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< - ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 := by - rw [sourceCollectionSet_card,hc] - simp only [Nat.cast_zero,zero_mul,zero_div] - exact not_lt.mpr (Nat.cast_nonneg _) - simp_rw [ite_eq_right (h _)] - exact FiniteLaw.expect_const _ 0 - exact hz.le - · rw [ite_eq_right hc] - simpa only [sourceCollectionSet_card] using M.hiddenSubset_small (sourceCollectionSet T n b v) hw hp - -theorem source_typical_effective_failure {Side : Type*} [Fintype Side] - (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (ω a : ℝ) (ha : 0 if SourceTypical T n s b ω a z then 0 else 1) ≤ - sourceEffectiveHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a := by - let f := fun z : Reports Side (SourceTrialCount T n (b+1)) => - sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) - (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) - (sourceReportFlags T n (b+1) z) 0 - calc - _ ≤ M.reports.expect (fun z => - (if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) - (sourceReportFlags T n (b+1) z) then 0 else 1)+(if a≤f z then 1 else 0)) := by - apply FiniteLaw.expect_mono - intro z - by_cases H : SourceTypical T n s b ω a z - · rw [ite_eq_left H] - split_ifs <;> norm_num - · rw [ite_eq_right H] - by_cases h : HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) - (sourceReportFlags T n (b+1) z) - · have hf : ¬f z H ⟨h,hf⟩ - rw [ite_eq_left h,ite_eq_left (le_of_not_gt hf)] - norm_num - · rw [ite_eq_right h] - split_ifs <;> norm_num - _ ≤ _ := by - rw [FiniteLaw.expect_add] - apply add_le_add (source_hidden_conditions_effective_tail T n (b+1) M ω hw hp) - apply (M.reports.positive_markov f (fun z => sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).trans - exact div_le_div_of_nonneg_right - (source_noncentral_average T n s b M hn hne hT he hL hroot) ha.le - - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Literal density of the source's unconditioned finite canonical oracle. -/ -def sourceOracleDensity {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (Z : Leaf → ℝ) (τ : Bool) - (zx : Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) : ℝ := - averagedDensity (PairedMechanisms.orientationsGiven zx.1) - (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) Z zx.2 - -theorem sourceOracleDensity_expansion {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (Z : Leaf → ℝ) (τ : Bool) - (z : Reports Side (SourceTrialCount T n (b+1))) (x : Fin (SourceLeafCount T (b+1)) → Leaf) : - sourceOracleDensity T n s b Z τ (z,x)=multilinear (sourceOracleCoefficient T n s b z τ) Z x := - averagedDensity_expansion _ _ _ _ - -theorem sourceOracleDensity_nonneg {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (Z : Leaf → ℝ) (hZ : ∀a,0 ≤ 1+Z a) (τ : Bool) - (zx : Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) : - 0 ≤ sourceOracleDensity T n s b Z τ zx := averagedDensity_nonneg _ _ _ hZ _ - -theorem sourceOracleDensity_mean {Side Leaf : Type*} [Fintype Leaf] (T n : ℕ → ℕ) (s b : ℕ) - (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hZ : P.expect Z=0) (τ : Bool) - (z : Reports Side (SourceTrialCount T n (b+1))) : - (P.product (SourceLeafCount T (b+1))).expect (fun x => sourceOracleDensity T n s b Z τ (z,x))=1 := - averagedDensity_mean P (PairedMechanisms.orientationsGiven z) Z hZ - (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) - -theorem source_canonical_centered_moment {Side Leaf : Type*} [Fintype Leaf] - (T n : ℕ → ℕ) (s b k : ℕ) (P : FiniteLaw Leaf) (Z : Leaf → ℝ) - (hk : 1 ≤ k) (hcenter : P.expect Z=0) {L : ℝ} (hL : 0 |Z a|^(2*k)) ≤ L^(2*k)) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) - (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : - (P.product (SourceLeafCount T (b+1))).expect - (fun x => |sourceOracleDensity T n s b Z τ (z,x)-1|^(2*k)) ≤ - ((((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b)/ - (1-((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b))^k := by - have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : - sourceOracleDensity T n s b Z τ (z,x)-1= - multilinear (nonconstantCoefficient (sourceOracleCoefficient T n s b z τ)) Z x := by - rw [nonconstant_multilinear,sourceOracleCoefficient_empty,sourceOracleDensity_expansion] - simp_rw [he] - apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans - exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) - (source_canonical_centered_energy T n s b z τ (by positivity) hsmall) k - -theorem source_canonical_signed_moment {Side Leaf : Type*} [Fintype Leaf] - (T n : ℕ → ℕ) (hT : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) - (z : Reports Side (SourceTrialCount T n (b+1))) (hz : SourceTypical T n s b ω a z) : - (P.product (SourceLeafCount T (b+1))).expect - (fun x => |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|^(2*k)) ≤ - (sourceEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by - have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : - |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|= - |multilinear (sourceSignedCoefficient T n s b z) Z x| := by - unfold sourceSignedCoefficient - rw [multilinear_sub,←sourceOracleDensity_expansion,←sourceOracleDensity_expansion,abs_sub_comm] - simp_rw [he] - apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans - exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) - (source_canonical_energy T n hT s b R ω η a _ ha (by positivity) hsmall hη z hz) k - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem degreeForcedRoleEnergy_zero_of_lt (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) - (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) (hr : r<2^(b+1)) - (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : - degreeForcedRoleEnergy T n g s center globalShift A b r d incoming=0 := by - have hi : IsEmpty (DegreeForcedRole T b r) := ⟨fun w => by - obtain ⟨F⟩ := w.property.2 - have hh := F.leaf_lower - rw [occupiedWindowTerm_leafCount,w.property.1] at hh - omega⟩ - let := hi - exact Finset.sum_eq_zero (fun w _ => isEmptyElim w) - -/-- Below the genuine forced binary leaf threshold there is NO forced - contribution; retaining even its coarse bound would lose the main exponent. -/ -def sourceSharpDegreeBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : ℝ := - 4*(3^((b+1)*r):ℕ)* - (((SourceLeafCount T (b+1)).choose r:ℕ)*(3^((b+1)*r):ℕ)*(η^2+a^2)+ - if 2^(b+1)≤r then sourceForcedBudget T n s b r ω else 0) - -theorem sourceSharpDegreeBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : - 0 ≤ sourceSharpDegreeBudget T n s b r ω η a := by - have h := sourceForcedBudget_nonneg T n s b r ω - unfold sourceSharpDegreeBudget - split_ifs <;> positivity - -theorem source_canonical_sharp_degree_bound {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 centralThird (T j)) b r - (sourceReportFlags T n (b+1) z) 0 η - (hiddenConditions_smoothingCap T n _ ω η s (b+1) hη _ hz.1)).trans - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply add_le_add - · apply mul_le_mul_of_nonneg_left _ (by positivity) - apply add_le_add_right - exact (sq_le_sq₀ (sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).mpr hz.2.le - · by_cases hr : 2^(b+1)≤r - · rw [ite_eq_left hr] - exact degreeForcedRoleEnergy_bound T n _ hT s (sourceLocalCenter T n) _ _ _ (sourceScheduledShift_hasPlateau T n) - (fun j => hiddenBinomialCap (n j) ω) (fun j => hiddenBinomialCap (sourceScheduledTrials T n j) ω) - (fun j => hiddenBinomialCap_nonneg _ _) (fun j => hiddenBinomialCap_nonneg _ _) - b r _ (hiddenConditions_binomialCaps T n _ ω (b+1) _ hz.1) 0 - · rw [ite_eq_right hr,degreeForcedRoleEnergy_zero_of_lt T n _ s _ _ _ b r (lt_of_not_ge hr)] -def sourceSharpEnergyBudget (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) : ℝ := - (∑r∈Finset.range R, w^(2*r)*(if r=0 then 0 else sourceSharpDegreeBudget T n s b r ω η a))+ - 4*(w^2*sourceSparseCount T s b)^R/(1-w^2*sourceSparseCount T s b) - -/-- Complete signed energy, with finite low-degree forced-tree bound and - the geometric high tail. No coefficient estimates remain as hypotheses. -/ -theorem source_canonical_sharp_energy {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 if r=0 then 0 else sourceSharpDegreeBudget T n s b r ω η a) - · intro r _ - by_cases hr : r=0 - · subst r - rw [sourceSignedCoefficient_zero,ite_eq_left rfl] - · rw [ite_eq_right hr] - exact source_canonical_sharp_degree_bound T n hT s b r ω η a ha hη z hz - · intro r _ - exact sourceSignedCoefficient_degree_geometric T n s b r z w - · intro r - split_ifs - · rfl - · exact sourceSharpDegreeBudget_nonneg T n s b r ω η a - -theorem sourceSharpEnergyBudget_nonneg (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) - (hsmall : w^2*sourceSparseCount T s b<1) : - 0 ≤ sourceSharpEnergyBudget T n s b R ω η a w := by - apply add_nonneg - · apply Finset.sum_nonneg - intro r _ - apply mul_nonneg (pow_nonneg (sq_nonneg w) r |>.trans_eq (pow_mul w 2 r).symm) - split_ifs - · rfl - · exact sourceSharpDegreeBudget_nonneg T n s b r ω η a - · exact div_nonneg (by positivity) (sub_nonneg.mpr hsmall.le) - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -local instance (priority := 10000) {α β : Type*} : DecidableEq (α × β) := Classical.decEq _ - -theorem source_canonical_sharp_signed_moment {Side Leaf : Type*} [Fintype Leaf] - (T n : ℕ → ℕ) (hT : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) - (z : Reports Side (SourceTrialCount T n (b+1))) (hz : SourceTypical T n s b ω a z) : - (P.product (SourceLeafCount T (b+1))).expect - (fun x => |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|^(2*k)) ≤ - (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by - have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : - |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|= - |multilinear (sourceSignedCoefficient T n s b z) Z x| := by - unfold sourceSignedCoefficient - rw [multilinear_sub,←sourceOracleDensity_expansion,←sourceOracleDensity_expansion,abs_sub_comm] - simp_rw [he] - apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans - exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) - (source_canonical_sharp_energy T n hT s b R ω η a _ ha (by positivity) hsmall hη z hz) k - - -def sourceReferenceLaw {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (P : FiniteLaw Leaf) : - FiniteLaw (Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) := - M.reports.prod (P.product (SourceLeafCount T (b+1))) - -theorem sourceOracleDensity_total {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hZ : P.expect Z=0) (τ : Bool) : - (sourceReferenceLaw T n b M P).expect (sourceOracleDensity T n s b Z τ)=1 := by - rw [sourceReferenceLaw,FiniteLaw.expect_prod] - simp_rw [sourceOracleDensity_mean T n s b P Z hZ τ] - exact M.reports.expect_const 1 - -theorem sourceOracle_withDensity {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (P Q : FiniteLaw Leaf) (Z : Leaf → ℝ) (hden : ∀a,Q.mass a=P.mass a*(1+Z a)) - (hZ : ∀a,0 ≤ 1+Z a) (hc : P.expect Z=0) (τ : Bool) : - M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)= - (sourceReferenceLaw T n b M P).withDensity (sourceOracleDensity T n s b Z τ) - (sourceOracleDensity_nonneg T n s b Z hZ τ) - (sourceOracleDensity_total T n s b M P Z hc τ) := by - apply FiniteLaw.ext - funext zx - exact M.canonicalOracle_density P Q Z hden _ zx.1 zx.2 - -def sourceTypicalSet {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (s b : ℕ) (ω a : ℝ) : - Finset (Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) := - Finset.univ.filter (fun x => SourceTypical T n s b ω a x.1) - -theorem sourceTypicalSet_mass {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (P Q : FiniteLaw Leaf) (ω a : ℝ) (τ : Bool) : - (M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)).eventMass - (sourceTypicalSet T n s b ω a)ᶜ= - M.reports.expect (fun z => if SourceTypical T n s b ω a z then 0 else 1) := by - rw [FiniteLaw.eventMass_indicator] - calc - _ = (M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)).expect - (fun zx => if SourceTypical T n s b ω a zx.1 then 0 else 1) := by - apply congrArg (FiniteLaw.expect _) - funext zx - simp [sourceTypicalSet] - _ = _ := M.canonicalOracle_metadata P Q - (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) - (fun z => if SourceTypical T n s b ω a z then 0 else 1) - -def sourceCenteredBudget (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) : ℝ := - (((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b)/ - (1-((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b) - -def sourceClippingCost (T n : ℕ → ℕ) (s b k : ℕ) (ω a L : ℝ) : ℝ := - sourceEffectiveHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a+ - Real.sqrt (6*(4*sourceCenteredBudget T s b k L)^k) - -theorem sourceCenteredBudget_nonneg (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) : - 0 ≤ sourceCenteredBudget T s b k L := - div_nonneg (by positivity) (sub_nonneg.mpr hsmall.le) - -theorem sourceCenteredBudget_le_one (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b≤1/2) : - sourceCenteredBudget T s b k L ≤ 1 := by - have hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1 := by linarith - apply (div_le_iff₀ (sub_pos.mpr hsmall)).mpr - linarith - -theorem source_reference_centered_moment {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (s b k : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hk : 1 ≤ k) (hc : P.expect Z=0) - {L : ℝ} (hL : 0 |Z a|^(2*k)) ≤ L^(2*k)) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) (τ : Bool) : - (sourceReferenceLaw T n b M P).expect - (fun zx => |sourceOracleDensity T n s b Z τ zx-1|^(2*k)) ≤ (sourceCenteredBudget T s b k L)^k := by - rw [sourceReferenceLaw,FiniteLaw.expect_prod] - calc - _ ≤ M.reports.expect (fun _ => (sourceCenteredBudget T s b k L)^k) := - M.reports.expect_mono (fun z => source_canonical_centered_moment T n s b k P Z hk hc hL hMoment hsmall z τ) - _ = _ := M.reports.expect_const _ - -theorem source_reference_signed_moment {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (hTpos : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) - (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) - (hη : ∀j - |if zx∈sourceTypicalSet T n s b ω a then sourceOracleDensity T n s b Z true zx- - sourceOracleDensity T n s b Z false zx else 0|^(2*k)) ≤ - (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by - rw [sourceReferenceLaw,FiniteLaw.expect_prod] - have hV := sourceSharpEnergyBudget_nonneg T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L) hsmall - calc - _ ≤ M.reports.expect (fun _ => (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k) := by - apply M.reports.expect_mono - intro z - by_cases hz : SourceTypical T n s b ω a z - · simp only [sourceTypicalSet,Finset.mem_filter,Finset.mem_univ,true_and,hz,ite_true] - exact source_canonical_sharp_signed_moment T n hTpos s b R k ω η a ha hη P Z hk hc hL hMoment hsmall z hz - · simp only [sourceTypicalSet,Finset.mem_filter,Finset.mem_univ,true_and,hz,ite_false, - abs_zero,zero_pow (by omega : 2*k≠0),FiniteLaw.expect_const] - exact pow_nonneg hV k - _ = _ := M.reports.expect_const _ - -theorem source_reference_clipped_exists {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] - (T n : ℕ → ℕ) (hTpos : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) - (hη : ∀j |Z a|^(2*k)) ≤ L^(2*k)) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) - (hη : ∀j C.score x.1 - density x := by - change C.second.mass x.1*R.mass x.2=(C.first.mass x.1*R.mass x.2)*(1+C.score x.1) - rw [C.density]; ring - likelihood_nonneg x := C.likelihood_nonneg x.1 - centered := by - rw [FiniteLaw.expect_prod] - simp_rw [FiniteLaw.expect_const] - exact C.centered - moment := by - unfold FiniteLaw.evenMomentSq - rw [FiniteLaw.expect_prod] - simp_rw [FiniteLaw.expect_const] - exact C.moment - first_tv := by rw [FiniteLaw.tv_prod_eq_left]; exact C.first_tv - second_tv := by rw [FiniteLaw.tv_prod_eq_left]; exact C.second_tv -end ClippedOracle - -theorem ApproximatesTrace.of_tv {α : Type*} [Fintype α] - {q E e : ℝ} {P Q : FiniteLaw α} {f : α → List Bool} {w : List Bool} - (hP : ApproximatesTrace q P f w E) (htv : Q.tv P ≤ e) : - ApproximatesTrace q Q f w (e+E) := by - intro F hF - exact (abs_sub_le (Q.expect (fun a => F (f a))) (P.expect (fun a => F (f a))) - (listDeletionExpectation q w F)).trans (add_le_add - ((FiniteLaw.abs_expect_sub_le_tv Q P _ (fun a => hF _)).trans htv) (hP F hF)) - -/-- A finite genuine approximate oracle pair with a common complete-trace - decoder. It does not include an overlap or any unproved scale conclusion. -/ -structure OracleTracePair (q : ℝ) (x y : List Bool) (k : ℕ) (E V : ℝ) where - Outcome : Type - finiteOutcome : Fintype Outcome - first : @FiniteLaw Outcome finiteOutcome - second : @FiniteLaw Outcome finiteOutcome - decode : Outcome → List Bool - first_simulation : @ApproximatesTrace Outcome finiteOutcome q first decode x E - second_simulation : @ApproximatesTrace Outcome finiteOutcome q second decode y E - score : Outcome → ℝ - density : ∀a,second.mass a=first.mass a*(1+score a) - likelihood_nonneg : ∀a,0≤1+score a - centered : first.expect score=0 - moment : @FiniteLaw.evenMomentSq Outcome finiteOutcome first score k ≤ V - -/-- The clipping and independent filler metadata preserve the source's fixed - public trace decoder. -/ -theorem source_clipped_simulation {Side Leaf : Type} [Fintype Side] [Fintype Leaf] - {q E e V : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) - (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b k : ℕ) - (H : SourceLayoutMargins s P T n h b) - (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) - (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) - (hn : ∀j mul_nonneg (P.nonneg a) (hF a)) - -theorem evenMomentSq_nonneg (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) : - 0≤P.evenMomentSq F k := Real.rpow_nonneg (P.expect_nonneg _ (fun _ => by positivity)) _ - -theorem evenMomentSq_pow (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) : - (P.evenMomentSq F k)^k=P.expect (fun a => |F a|^(2*k)) := by - unfold evenMomentSq - rw [one_div,Real.rpow_inv_natCast_pow (P.expect_nonneg _ (fun _ => by positivity)) (by omega)] - -theorem expect_even_pow_le_of_moment (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) - {V : ℝ} (h : P.evenMomentSq F k≤V) : - P.expect (fun a => |F a|^(2*k))≤V^k := by - rw [←P.evenMomentSq_pow F k hk] - exact pow_le_pow_left₀ (P.evenMomentSq_nonneg F k) h k - -theorem secondMoment_le_evenMomentSq (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) : - P.expect (fun a => F a^2)≤P.evenMomentSq F k := by - have hn : 0≤P.expect (fun a => F a^2) := P.expect_nonneg _ (fun _ => sq_nonneg _) - have hj := P.abs_expect_pow_le (fun a => F a^2) k - simp only [abs_of_nonneg hn,abs_pow,←pow_mul] at hj - have hr := Real.rpow_le_rpow (pow_nonneg hn k) hj (by positivity : 0≤(k:ℝ)⁻¹) - rw [Real.pow_rpow_inv_natCast hn (by omega)] at hr - simpa only [evenMomentSq,one_div] using hr - -theorem affinity_coordinateProduct {n : ℕ} (P Q : Fin n → FiniteLaw α) : - (coordinateProduct P).affinity (coordinateProduct Q)=∏i,(P i).affinity (Q i) := by - unfold affinity coordinateProduct - simp only - have he (a : Fin n → α) : - Real.sqrt (∏i,(P i).mass (a i))*Real.sqrt (∏i,(Q i).mass (a i))= - ∏i,Real.sqrt ((P i).mass (a i))*Real.sqrt ((Q i).mass (a i)) := by - rw [Real.sqrt_prod _ (fun i _ => (P i).nonneg (a i)), - Real.sqrt_prod _ (fun i _ => (Q i).nonneg (a i)),Finset.prod_mul_distrib] - simp_rw [he] - exact (Fintype.prod_sum (fun (i : Fin n) a => Real.sqrt ((P i).mass a)*Real.sqrt ((Q i).mass a))).symm - -theorem one_sub_prod_le_sum {ι : Type*} (S : Finset ι) (f : ι → ℝ) - (h0 : ∀i∈S,0≤f i) (h1 : ∀i∈S,f i≤1) : - 1-∏i∈S,f i≤∑i∈S,(1-f i) := by - induction S using Finset.induction_on with - | empty => simp - | @insert a S ha ih => - rw [Finset.prod_insert ha,Finset.sum_insert ha] - have H := ih (fun i hi => h0 i (Finset.mem_insert_of_mem hi)) - (fun i hi => h1 i (Finset.mem_insert_of_mem hi)) - have hs : 0≤∑i∈S,(1-f i) := Finset.sum_nonneg (fun i hi => sub_nonneg.mpr (h1 i (Finset.mem_insert_of_mem hi))) - have hm := mul_le_mul_of_nonneg_left H (h0 a (Finset.mem_insert_self a S)) - have hm' := mul_le_mul_of_nonneg_right (h1 a (Finset.mem_insert_self a S)) hs - nlinarith - -theorem hellingerSq_coordinateProduct_le {n : ℕ} (P Q : Fin n → FiniteLaw α) : - (coordinateProduct P).hellingerSq (coordinateProduct Q)≤∑i,(P i).hellingerSq (Q i) := by - simp_rw [hellingerSq_eq] - rw [affinity_coordinateProduct] - have h := one_sub_prod_le_sum Finset.univ (fun i => (P i).affinity (Q i)) - (fun i _ => affinity_nonneg _ _) (fun i _ => affinity_le_one _ _) - have he : (∑i,(2-2*(P i).affinity (Q i)))=2*∑i,(1-(P i).affinity (Q i)) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring - rw [he] - linarith - -@[simp] theorem hellingerSq_self (P : FiniteLaw α) : P.hellingerSq P=0 := by - simp [hellingerSq] - -theorem hellingerSq_symm (P Q : FiniteLaw α) : P.hellingerSq Q=Q.hellingerSq P := by - apply Finset.sum_congr rfl; intro a _; ring - -/-- Only differing coordinates cost squared Hellinger distance. This estimate - does not pay for pure filler coordinates, nor assume independence of traces - after their common concatenating decoder. -/ -theorem tv_mixedProduct_le {n : ℕ} (P Q : FiniteLaw α) (Z : α → ℝ) - (hden : ∀a,Q.mass a=P.mass a*(1+Z a)) (k : ℕ) (hk : 1≤k) - {V : ℝ} (hM : P.evenMomentSq Z k≤V) (τ σ : Fin n → Bool) : - (coordinateProduct (fun i => if τ i then Q else P)).tv - (coordinateProduct (fun i => if σ i then Q else P))≤ - Real.sqrt ((∑i,if τ i=σ i then (0:ℝ) else 1)*V) := by - have hH : P.hellingerSq Q≤V := (P.hellingerSq_le_score Q Z hden).trans - ((P.secondMoment_le_evenMomentSq Z k hk).trans hM) - apply (tv_le_sqrt_hellingerSq _ _).trans - apply Real.sqrt_le_sqrt - apply (hellingerSq_coordinateProduct_le _ _).trans - rw [Finset.sum_mul] - apply Finset.sum_le_sum - intro i _ - cases τ i <;> cases σ i <;> simp only [Bool.false_eq_true,Bool.true_eq_false,ite_false,ite_true, - zero_mul,one_mul,hellingerSq_self,le_refl] - · exact hH - · rw [hellingerSq_symm]; exact hH - -end TraceReconstruction.FiniteLaw - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Literal recursive source oracle with actual complete-trace side laws. - All remaining hypotheses here are explicit parameter inequalities, the old - leaf oracle, and its genuine repeated-word overlap invariant. -/ -theorem actual_source_oracle {Leaf : Type} [Fintype Leaf] - {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) - (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b R k : ℕ) - (H : SourceLayoutMargins s P T n h b) - (hTpos : ∀j,0 |Z a|^(2*k))≤L^(2*k)) - (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b≤1/2) - (hη : ∀j listTraceLaw q hq (W j) m (hW j) - have hp : ω^2∈Set.Icc 0 1 := ⟨sq_nonneg ω,by nlinarith [hω.1,hω.2]⟩ - obtain ⟨C⟩ := source_clippedOracle_exists T n hTpos s b R k M A B Z hden hZ ω a η L ha hL - (fun _ => rfl) hp hn H.even_trials hT he hMotif hroot hk hMoment hscale hη herror - apply source_clipped_simulation hq hE s P T n h atom b k H hP (he b le_rfl) hroot - (by nlinarith [hMotif b le_rfl]) hn M F A B Subtype.val g - (fun j => listTraceLaw_simulates q hq (U j) m (hU j)) - (fun j => listTraceLaw_simulates q hq (V j) m (hV j)) - (fun j => listTraceLaw_simulates q hq (W j) m (hW j)) hA hB C - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Simulation + +namespace OAI + +/-! +# SourceOracle + +Actual source mechanisms and posteriors, typical metadata, sparse degrees, common-event clipping, approximate oracles, and mixed Hellinger bounds. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Ambient finite trace-space choice does not lose any of the genuine +complete-trace common mass. The embedding adds only zero-mass points. -/ +theorem listTraceOverlap_le_ambient {q : ℝ} (hq : q∈Set.Icc 0 1) + (x y : List Bool) (M : ℕ) (hx : x.length≤M) (hy : y.length≤M) : + listTraceOverlap q hq x y≤ + (listTraceLaw q hq x M hx).overlap (listTraceLaw q hq y M hy) := by + let M₀ := max x.length y.length + have H := approximations_trace_tv hq + (listTraceLaw q hq x M₀ (le_max_left _ _)) + (listTraceLaw q hq y M₀ (le_max_right _ _)) Subtype.val x y 0 0 M hx hy + (listTraceLaw_simulates q hq x M₀ _).approximate + (listTraceLaw_simulates q hq y M₀ _).approximate + simp only [add_zero] at H + unfold listTraceOverlap + rw [FiniteLaw.overlap_eq_one_sub_tv,FiniteLaw.overlap_eq_one_sub_tv] + linarith + +theorem listTraceOverlap_ambient {q : ℝ} (hq : q∈Set.Icc 0 1) + (x y : List Bool) (M : ℕ) (hx : x.length≤M) (hy : y.length≤M) : + listTraceOverlap q hq x y= + (listTraceLaw q hq x M hx).overlap (listTraceLaw q hq y M hy) := by + apply le_antisymm (listTraceOverlap_le_ambient hq x y M hx hy) + exact simulations_overlap_le hq _ _ Subtype.val x y + (listTraceLaw_simulates q hq x M hx) (listTraceLaw_simulates q hq y M hy) + +namespace FiniteLaw +variable {α : Type*} [Fintype α] +theorem commonPart_le_right (P Q : FiniteLaw α) (h : 0 exact PEmpty.elim i + | succ b ih => + rcases i with i | i | ⟨u,i⟩ + · simpa [sourceTrialWord,bitIndex] using hov b (by omega) + · cases b with + | zero => exact Fin.elim0 i + | succ b => simpa [sourceTrialWord,bitIndex] using hov b (by omega) + · exact ih (fun j hj => hov j (by omega)) i + +/-- A common finite side-trace space exists without changing any word. -/ +theorem finite_word_bound {ι : Type*} [Fintype ι] (w : ι → List Bool) : + ∃M,∀i,(w i).length≤M := by + refine ⟨∑i,(w i).length, fun i => ?_⟩ + exact Finset.single_le_sum (f:=fun i => (w i).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The actual report flags, in the literal nested trial coordinates. -/ +def sourceReportFlags {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) + (z : Reports Side (SourceTrialCount T n b)) : + WindowAssignments T n (sourceScheduledTrials T n) (Option Bool) b := + (sourceAssignmentCode T n (Option Bool) b).symm (fun j => (z j).1) + +/-- Exact change of coordinates for the posterior of all hidden bits, not + just separate local marginals. -/ +theorem source_posterior_code_expect {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) + (z : Reports Side (SourceTrialCount T n b)) + (F : WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℝ) : + (PairedMechanisms.orientationsGiven z).expect + (fun bits => F ((sourceAssignmentCode T n Bool b).symm bits)) = + (windowPosteriorLaw T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z)).expect F := by + rw [windowPosterior_expect_flat,FiniteLaw.indexedProduct_expect_equiv _ (finEnumeration _)] + simp only [sourceReportFlags,sourceAssignmentCode_eval] + simp only [PairedMechanisms.orientationsGiven,FiniteLaw.expect,FiniteLaw.coordinateProduct, + FiniteLaw.indexedProduct,sourceAssignmentCode,Equiv.coe_fn_symm_mk] + apply Finset.sum_congr (by ext; simp) + intro bits _ + rfl + +/-- A monomial is precisely its set of actual leaf addresses. -/ +def sourceSubsetCode (T : ℕ → ℕ) (b : ℕ) : + (Fin (SourceLeafCount T b) → Bool) ≃ Finset (WindowLeaf T b) := + (maskSubsetEquiv _).trans (Equiv.finsetCongr (finEnumeration _)) + +theorem sourceSubsetCode_card (T : ℕ → ℕ) (b : ℕ) + (σ : Fin (SourceLeafCount T b) → Bool) : + (sourceSubsetCode T b σ).card=monomialDegree σ := by + simp only [sourceSubsetCode,Equiv.trans_apply,Equiv.finsetCongr_apply,Finset.card_map] + rfl + +theorem selectionCoefficient_sign {k : ℕ} (θ σ : Fin k → Bool) : + selectionCoefficient θ σ=∏j∈maskSubset σ,(1-boolTypeSign (θ j))/2 := by + unfold selectionCoefficient maskSubset + rw [Finset.prod_filter] + apply Finset.prod_congr rfl + intro j _ + cases σ j <;> cases θ j <;> norm_num [boolTypeSign] + +theorem source_leaf_selection (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) + (incoming : ℤ) (τ : Bool) (σ : Fin (SourceLeafCount T b) → Bool) : + selectionCoefficient + (fun j => sourceTreeLeafBool T n s center b bits incoming τ (finEnumeration _ j)) σ = + ∏v∈sourceSubsetCode T b σ, + (1-sourceTreeLeafSign T n (sourceScheduledTrials T n) s center + (sourceScheduledShift T n) b bits incoming (boolTypeSign τ) v)/2 := by + rw [selectionCoefficient_sign] + simp only [sourceSubsetCode,Equiv.trans_apply,Equiv.finsetCongr_apply,Finset.prod_map] + apply Finset.prod_congr rfl + intro j _ + rw [sourceTreeLeafBool_sign] + rfl + +/-- The real canonical-oracle coefficient difference is the exact source + polynomial coefficient whose forced-tree energy has been proved. -/ +theorem source_canonical_coefficient {Side : Type*} (T n : ℕ → ℕ) (s : ℕ) + (center : ℕ → ℤ) (b : ℕ) (incoming : ℤ) + (z : Reports Side (SourceTrialCount T n (b+1))) + (σ : Fin (SourceLeafCount T (b+1)) → Bool) : + averagedCoefficient (PairedMechanisms.orientationsGiven z) + (sourceFlatLeafType T n s center (b+1) incoming false) σ - + averagedCoefficient (PairedMechanisms.orientationsGiven z) + (sourceFlatLeafType T n s center (b+1) incoming true) σ = + sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) + b (sourceReportFlags T n (b+1) z) incoming (sourceSubsetCode T (b+1) σ) := by + unfold averagedCoefficient sourceFlatLeafType + rw [source_posterior_code_expect T n (b+1) z + (fun bits => selectionCoefficient + (fun j => sourceTreeLeafBool T n s center (b+1) bits incoming false (finEnumeration _ j)) σ), + source_posterior_code_expect T n (b+1) z + (fun bits => selectionCoefficient + (fun j => sourceTreeLeafBool T n s center (b+1) bits incoming true (finEnumeration _ j)) σ)] + simp_rw [source_leaf_selection] + rfl + +/-- Reindexing preserves the entire degree-r square sum, including zero + and degrees larger than the number of real leaves. -/ +theorem source_canonical_degree_sum {Side : Type*} (T n : ℕ → ℕ) (s : ℕ) + (center : ℕ → ℤ) (b r : ℕ) (incoming : ℤ) + (z : Reports Side (SourceTrialCount T n (b+1))) : + (∑σ : Fin (SourceLeafCount T (b+1)) → Bool, if monomialDegree σ=r then + (averagedCoefficient (PairedMechanisms.orientationsGiven z) + (sourceFlatLeafType T n s center (b+1) incoming false) σ - + averagedCoefficient (PairedMechanisms.orientationsGiven z) + (sourceFlatLeafType T n s center (b+1) incoming true) σ)^2 else 0) = + ∑S : DegreeLeafSubset T b r, + (sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) + b (sourceReportFlags T n (b+1) z) incoming S.val)^2 := by + simp_rw [source_canonical_coefficient,←sourceSubsetCode_card] + rw [(sourceSubsetCode T (b+1)).sum_comp + (fun S => if S.card=r then (sourceCoefficient T n (sourceScheduledTrials T n) s center + (sourceScheduledShift T n) b (sourceReportFlags T n (b+1) z) incoming S)^2 else 0)] + let f : DegreeLeafSubset T b r → ℝ := fun S => + (sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) + b (sourceReportFlags T n (b+1) z) incoming S.val)^2 + simpa only [f, dite_eq_ite] using + sum_subtype_zero_extend (fun S : Finset (WindowLeaf T (b+1)) => S.card=r) f + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace PairedMechanisms +variable {Side : Type*} [Fintype Side] {m : ℕ} (M : PairedMechanisms Side m) + +def hiddenSubset (S : Finset (Fin m)) (z : Reports Side m) : ℕ := ∑i : S,hiddenTrial (z i.val).1 + +theorem hiddenSubset_mgf (S : Finset (Fin m)) {ω t : ℝ} (hw : ∀i,M.hiddenWeight i=ω) + (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : + M.reports.expect (fun z => Real.exp (t*((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)))≤ + Real.exp ((S.card:ℝ)*t^2) := by + have he (z : Reports Side m) : + Real.exp (t*((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2))= + ∏i : S,Real.exp (t*((hiddenTrial (z i.val).1:ℕ)-ω^2)) := by + rw [←Real.exp_sum] + congr 1 + simp only [mul_sub,Finset.mul_sum,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_coe, + nsmul_eq_mul,hiddenSubset,Nat.cast_sum] + ring + simp_rw [he] + rw [reports,FiniteLaw.coordinateProduct_expect_subtype _ S + (fun (_ : S) (z : Option Bool × (Side × Side)) => Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2)))] + calc + _ ≤ ∏i : S,Real.exp (t^2) := by + apply Finset.prod_le_prod₀ + · intro i _ + exact Finset.sum_nonneg (fun z _ => mul_nonneg + ((FiniteLaw.pairedReport (M.first i.val) (M.second i.val) (M.common i.val) (M.weight_nonneg i.val) + (M.common_first i.val) (M.common_second i.val)).nonneg z) (Real.exp_nonneg _)) + · intro i _ + have h := FiniteLaw.pairedReport_hidden_mgf (M.first i.val) (M.second i.val) (M.common i.val) + (M.weight_nonneg i.val) (M.common_first i.val) (M.common_second i.val) (by simpa [hw i.val] using hp) ht + simpa only [hw i.val] using h + _ = _ := by simp only [Finset.prod_const,Finset.card_univ,Fintype.card_coe,Real.exp_nat_mul] + +/-- A quantitative unconditional bound for failure of a source hidden-count + condition. The exponent ω⁴m is sufficient for the uniform scale margins. -/ +theorem hiddenSubset_small (S : Finset (Fin m)) {ω : ℝ} (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : + M.reports.expect (fun z => if (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 then 1 else 0)≤ + Real.exp (-(S.card:ℝ)*ω^4/16) := by + have ht : 0≤ω^2/4 := by positivity + have ht' : |-(ω^2/4)|≤1 := by rw [abs_neg,abs_of_nonneg ht]; linarith [hp.2] + have H := finite_exp_markov Finset.univ M.reports.mass + (fun z => -((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)) (fun z _ => M.reports.nonneg z) + ((S.card:ℝ)*ω^2/2) (ω^2/4) ht + have hm := M.hiddenSubset_mgf S hw hp ht' + have hsub : M.reports.expect (fun z => if (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 then 1 else 0)≤ + ∑z∈Finset.univ.filter (fun z => (S.card:ℝ)*ω^2/2≤-((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)),M.reports.mass z := by + rw [Finset.sum_filter] + apply Finset.sum_le_sum + intro z _ + dsimp only + by_cases hz : (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 + · rw [ite_eq_left hz,ite_eq_left (by linarith : (S.card:ℝ)*ω^2/2≤-((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)),mul_one] + · rw [ite_eq_right hz,mul_zero]; split_ifs <;> positivity [M.reports.nonneg z] + calc + _ ≤ _ := hsub.trans H + _ ≤ Real.exp (-(ω^2/4)*((S.card:ℝ)*ω^2/2))*Real.exp ((S.card:ℝ)*(-(ω^2/4))^2) := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_nonneg _) + simpa only [FiniteLaw.expect,neg_mul,mul_neg,neg_neg] using hm + _ = _ := by rw [←Real.exp_add]; congr 1; ring + + +end PairedMechanisms +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- IDs for precisely one local and one global collection at every genuine + nonleaf of the complete source window tree. -/ +def WindowCollection (T : ℕ → ℕ) : ℕ → Type + | 0 => PEmpty + | b+1 => Bool ⊕ (Fin (T b) × WindowCollection T b) + +noncomputable instance windowCollectionFintype (T : ℕ → ℕ) : + (b : ℕ) → Fintype (WindowCollection T b) + | 0 => inferInstanceAs (Fintype PEmpty) + | b+1 => by + letI := windowCollectionFintype T b + exact inferInstanceAs (Fintype (Bool ⊕ (Fin (T b) × WindowCollection T b))) + +def collectionCount (T n g : ℕ → ℕ) : (b : ℕ) → WindowCollection T b → ℕ + | b+1, .inl false => n b + | b+1, .inl true => g b + | b+1, .inr (_,v) => collectionCount T n g b v + +def collectionTrial (T n g : ℕ → ℕ) : + (b : ℕ) → (v : WindowCollection T b) → Fin (collectionCount T n g b v) → WindowTrial T n g b + | _+1, .inl false, j => .inl j + | _+1, .inl true, j => .inr (.inl j) + | b+1, .inr (u,v), j => .inr (.inr (u,collectionTrial T n g b v j)) + +theorem collectionTrial_injective (T n g : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : + Function.Injective (collectionTrial T n g b v) := by + induction b with + | zero => exact PEmpty.elim v + | succ b ih => + rcases v with v | ⟨u,v⟩ + · cases v + · intro i j h + exact Sum.inl.inj h + · intro i j h + exact Sum.inl.inj (Sum.inr.inj h) + · intro i j h + apply ih v + exact congrArg Prod.snd (Sum.inr.inj (Sum.inr.inj h)) + +def collectionFlags (T n g : ℕ → ℕ) {A : Type} : + (b : ℕ) → WindowAssignments T n g A b → (v : WindowCollection T b) → + Fin (collectionCount T n g b v) → A + | _+1, d, .inl false => d.1 + | _+1, d, .inl true => d.2.1 + | b+1, d, .inr (u,v) => collectionFlags T n g b (d.2.2 u) v + +theorem collectionFlags_trial (T n g : ℕ → ℕ) {A : Type} (b : ℕ) + (d : WindowAssignments T n g A b) (v : WindowCollection T b) + (j : Fin (collectionCount T n g b v)) : + collectionFlags T n g b d v j= + windowAssignmentEquiv T n g A b d (collectionTrial T n g b v j) := by + induction b with + | zero => exact PEmpty.elim v + | succ b ih => + rcases v with v | ⟨u,v⟩ + · cases v <;> rfl + · exact ih (d.2.2 u) v j + +/-- This is the source hidden-count predicate, before any conditioning on fit. -/ +def HiddenCollectionConditions (T n g : ℕ → ℕ) (ω : ℝ) : + (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop + | 0, _ => True + | b+1, d => + (n b:ℝ)*ω^2/2≤∑i,(hiddenTrial (d.1 i):ℝ) ∧ + (g b:ℝ)*ω^2/2≤∑i,(hiddenTrial (d.2.1 i):ℝ) ∧ + ∀u,HiddenCollectionConditions T n g ω b (d.2.2 u) + +theorem hiddenCollectionConditions_iff (T n g : ℕ → ℕ) (ω : ℝ) (b : ℕ) + (d : WindowAssignments T n g (Option Bool) b) : + HiddenCollectionConditions T n g ω b d ↔ + ∀v : WindowCollection T b,(collectionCount T n g b v:ℝ)*ω^2/2≤ + ∑i,(hiddenTrial (collectionFlags T n g b d v i):ℝ) := by + induction b with + | zero => simp [HiddenCollectionConditions,WindowCollection] + | succ b ih => + constructor + · intro h v + rcases v with v | ⟨u,v⟩ + · cases v + · exact h.1 + · exact h.2.1 + · exact (ih (d.2.2 u)).mp (h.2.2 u) v + · intro h + refine ⟨h (.inl false),h (.inl true),fun u => (ih (d.2.2 u)).mpr ?_⟩ + intro v + exact h (.inr (u,v)) + +def sourceCollectionIndex (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : + Fin (collectionCount T n (sourceScheduledTrials T n) b v) → Fin (SourceTrialCount T n b) := + fun j => (finEnumeration _).symm (collectionTrial T n (sourceScheduledTrials T n) b v j) + +theorem sourceCollectionIndex_injective (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : + Function.Injective (sourceCollectionIndex T n b v) := + (finEnumeration _).symm.injective.comp (collectionTrial_injective T n _ b v) + +def sourceCollectionSet (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : + Finset (Fin (SourceTrialCount T n b)) := Finset.univ.image (sourceCollectionIndex T n b v) + +theorem sourceCollectionSet_card (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : + (sourceCollectionSet T n b v).card=collectionCount T n (sourceScheduledTrials T n) b v := by + rw [sourceCollectionSet,Finset.card_image_of_injective _ (sourceCollectionIndex_injective T n b v)] + simp only [Finset.card_univ,Fintype.card_fin] + +theorem sourceCollection_flags {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) + (z : Reports Side (SourceTrialCount T n b)) (v : WindowCollection T b) + (j : Fin (collectionCount T n (sourceScheduledTrials T n) b v)) : + collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v j= + (z (sourceCollectionIndex T n b v j)).1 := by + rw [collectionFlags_trial] + have h := sourceAssignmentCode_eval T n (Option Bool) b (fun j => (z j).1) + (sourceCollectionIndex T n b v j) + simpa only [sourceCollectionIndex,Equiv.apply_symm_apply,sourceReportFlags] using h + +theorem sourceCollection_hidden {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) + (z : Reports Side (SourceTrialCount T n b)) (v : WindowCollection T b) : + PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z= + ∑i,hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i) := by + unfold PairedMechanisms.hiddenSubset + rw [←Finset.sum_subtype (sourceCollectionSet T n b v) (fun _ => Iff.rfl) + (fun j => hiddenTrial (z j).1)] + rw [sourceCollectionSet,Finset.sum_image] + · simp_rw [sourceCollection_flags] + · exact (sourceCollectionIndex_injective T n b v).injOn + +/-- Exact finite-union metadata cost; it contains no postulated typical + event and no independence assertion between different collections. -/ +def sourceHiddenTail (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : ℝ := + ∑v : WindowCollection T b,Real.exp (-(collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^4/16) + +theorem source_hidden_conditions_tail {Side : Type*} [Fintype Side] + (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n b)) + (ω : ℝ) (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : + M.reports.expect (fun z => if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω b + (sourceReportFlags T n b z) then 0 else 1) ≤ sourceHiddenTail T n b ω := by + calc + _ ≤ M.reports.expect (fun z => ∑v : WindowCollection T b, + if (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ + ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) + then 0 else 1) := by + apply FiniteLaw.expect_mono + intro z + simp only [hiddenCollectionConditions_iff] + exact failure_forall_le_sum _ + _ = ∑v : WindowCollection T b,M.reports.expect (fun z => + if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< + ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0) := by + rw [FiniteLaw.expect_fintype_sum] + apply Finset.sum_congr rfl + intro v _ + apply congrArg (FiniteLaw.expect M.reports) + funext z + rw [sourceCollectionSet_card,sourceCollection_hidden,Nat.cast_sum] + by_cases h : (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ + ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) + · simp [h,not_lt.mpr h] + · simp [h,lt_of_not_ge h] + _ ≤ _ := by + apply Finset.sum_le_sum + intro v _ + simpa only [sourceCollectionSet_card] using M.hiddenSubset_small (sourceCollectionSet T n b v) hw hp + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Numerical cap forced by at least half the mean number of hidden pairs. -/ +def hiddenBinomialCap (m : ℕ) (ω : ℝ) : ℝ := Real.sqrt (4/((m:ℝ)*ω^2+2)) + +theorem hiddenBinomialCap_nonneg (m : ℕ) (ω : ℝ) : 0≤hiddenBinomialCap m ω := + Real.sqrt_nonneg _ + +theorem hidden_binomial_bound (m G : ℕ) (ω : ℝ) + (h : (m:ℝ)*ω^2/2≤G) : binomialBound G≤hiddenBinomialCap m ω := by + apply Real.sqrt_le_sqrt + apply (div_le_div_iff₀ (by positivity : (0:ℝ) hiddenBinomialCap (n j) ω) + (fun j => hiddenBinomialCap (g j) ω) b d := by + induction b with + | zero => trivial + | succ b ih => + refine ⟨hidden_binomial_bound (n b) _ ω ?_,hidden_binomial_bound (g b) _ ω ?_,fun u => ih _ (h.2.2 u)⟩ + · simpa only [Nat.cast_sum] using h.1 + · simpa only [Nat.cast_sum] using h.2.1 + +theorem hiddenConditions_smoothingCap (T n g : ℕ → ℕ) (ω η : ℝ) (s b : ℕ) + (hη : ∀j trivial + | succ b ih => + exact ⟨(hidden_smoothing_bound d.1 s ω h.1).trans (hη b (by omega)), + fun u => ih (fun j hj => hη j (by omega)) _ (h.2.2 u)⟩ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The actual noncentral posterior mass has the unconditional honest + fit-error bound. Impossible reports cause no problem in Bayes averaging. -/ +theorem source_noncentral_average {Side : Type*} [Fintype Side] + (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (hn : ∀j,j sourceNoncentralMass T n (sourceScheduledTrials T n) s + (sourceLocalCenter T n) (sourceScheduledShift T n) (fun j => centralThird (T j)) + (b+1) (sourceReportFlags T n (b+1) z) 0) ≤ sourceFitTail T n (b+1) := by + calc + _ ≤ M.reports.expect (fun z => + (windowPosteriorLaw T n (sourceScheduledTrials T n) (b+1) (sourceReportFlags T n (b+1) z)).expect + (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1)) := by + apply FiniteLaw.expect_mono + intro z + exact sourceNoncentralMass_le_fit T n s b (sourceLocalCenter T n) (fun _ _ => rfl) + hT he hL hroot _ + _ = M.reports.expect (fun z => (PairedMechanisms.orientationsGiven z).expect + (fun bits => if SourceTreeFit T n (b+1) ((sourceAssignmentCode T n Bool (b+1)).symm bits) then 0 else 1)) := by + apply congrArg (FiniteLaw.expect M.reports) + funext z + exact (source_posterior_code_expect T n (b+1) z + (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1)).symm + _ = _ := M.posterior_average _ + _ ≤ _ := source_flat_fit_tail T n (b+1) (fun j hj => hn j (by omega)) (fun j hj => hne j (by omega)) + +/-- Markov for a genuine finite law, stated for the exact failure indicator. -/ +theorem FiniteLaw.positive_markov {α : Type*} [Fintype α] (P : FiniteLaw α) + (f : α → ℝ) (hf : ∀x,0≤f x) {a : ℝ} (ha : 0 if a≤f x then 1 else 0) ≤ P.expect f/a := by + apply (le_div_iff₀ ha).mpr + rw [mul_comm,←FiniteLaw.expect_const_mul] + apply FiniteLaw.expect_mono + intro x + split_ifs with hx + · simpa only [mul_one] using hx + · simpa only [mul_zero] using hf x + +/-- One metadata event, fixed before choosing a coefficient, controls + local and global smoothing and all internal central-third tests. -/ +def SourceTypical {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) (ω a : ℝ) + (z : Reports Side (SourceTrialCount T n (b+1))) : Prop := + HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) + (sourceReportFlags T n (b+1) z) ∧ + sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) + (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) + (sourceReportFlags T n (b+1) z) 0 if SourceTypical T n s b ω a z then 0 else 1) ≤ + sourceHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a := by + let f := fun z : Reports Side (SourceTrialCount T n (b+1)) => + sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) + (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) + (sourceReportFlags T n (b+1) z) 0 + calc + _ ≤ M.reports.expect (fun z => + (if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) + (sourceReportFlags T n (b+1) z) then 0 else 1)+(if a≤f z then 1 else 0)) := by + apply FiniteLaw.expect_mono + intro z + by_cases H : SourceTypical T n s b ω a z + · rw [ite_eq_left H] + split_ifs <;> norm_num + · rw [ite_eq_right H] + by_cases h : HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) + (sourceReportFlags T n (b+1) z) + · have hf : ¬f z H ⟨h,hf⟩ + rw [ite_eq_left h,ite_eq_left (le_of_not_gt hf)] + norm_num + · rw [ite_eq_right h] + split_ifs <;> norm_num + _ ≤ _ := by + rw [FiniteLaw.expect_add] + apply add_le_add (source_hidden_conditions_tail T n (b+1) M ω hw hp) + apply (M.reports.positive_markov f (fun z => sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).trans + exact div_le_div_of_nonneg_right + (source_noncentral_average T n s b M hn hne hT he hL hroot) ha.le + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Exact common plateau with integer half-count centering. Unlike the + simplified g/2 formula, this identity needs no parity assumption. -/ +theorem scheduledGlobalShift_plateau_exact (N t : ℕ) + (bits : Fin ((N/4)*t) → Bool) (u : Fin N) (hu : u∈centralThird N) : + scheduledGlobalShift N t bits u = (∑i,(bitIndex (bits i):ℤ))-(N/4:ℕ)*(t/2:ℕ) := by + calc + _ = ∑v : Fin (N/4), + ((∑a : Fin t, (bitIndex (bits (globalTrialIndex N t v a)):ℤ))-(t/2:ℕ)) := by + apply Finset.sum_congr rfl + intro v _ + exact ite_eq_left (centralThird_active N u hu v) + _ = _ := by + rw [Finset.sum_sub_distrib] + congr 1 + · exact globalTrial_sum N t (fun i => (bitIndex (bits i):ℤ)) + · simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + +def sourcePlateauCenter (T n : ℕ → ℕ) : ℕ → ℤ + | 0 => 0 + | b+1 => (T (b+1)/4:ℕ)*(n b/2:ℕ) + +theorem sourceScheduledShift_hasPlateau (T n : ℕ → ℕ) : + HasGlobalPlateau T (sourceScheduledTrials T n) (fun j => centralThird (T j)) + (sourcePlateauCenter T n) (sourceScheduledShift T n) := by + intro b bits u hu + cases b with + | zero => + change (0:ℤ)=(∑i : Fin 0,(bitIndex (bits i):ℤ))-0 + simp + | succ b => exact scheduledGlobalShift_plateau_exact (T (b+1)) (n b) bits u hu + +def sourceForcedBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω : ℝ) : ℝ := + (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*interiorLabelBudget T b r * + ((2^s:ℕ):ℝ)^(2*(r-2^(b+1))) * + ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* + binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) + +theorem sourceForcedBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω : ℝ) : + 0 ≤ sourceForcedBudget T n s b r ω := by + have hB := fun j => hiddenBinomialCap_nonneg (n j) ω + have hC := fun j => hiddenBinomialCap_nonneg (sourceScheduledTrials T n j) ω + have ht := binaryTreeBudget_nonneg (fun j => 4*((2^s:ℕ):ℝ)^6* + hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) + (fun j => mul_nonneg (mul_nonneg (by positivity) (hC (j+1))) (hB j)) b + have hb := hB b + unfold sourceForcedBudget interiorLabelBudget + positivity + +/-- Full unabsorbed bound, now with no placeholder anchor-energy hypothesis. -/ +def sourceDegreeBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : ℝ := + 4*(3^((b+1)*r):ℕ)* + (((SourceLeafCount T (b+1)).choose r:ℕ)*(3^((b+1)*r):ℕ)*(η^2+a^2)+ + sourceForcedBudget T n s b r ω) + +theorem sourceDegreeBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : + 0 ≤ sourceDegreeBudget T n s b r ω η a := by + have h := sourceForcedBudget_nonneg T n s b r ω + unfold sourceDegreeBudget + positivity + +theorem source_canonical_degree_bound {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 centralThird (T j)) b r + (sourceReportFlags T n (b+1) z) 0 η + (hiddenConditions_smoothingCap T n _ ω η s (b+1) hη _ hz.1)).trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply add_le_add + · apply mul_le_mul_of_nonneg_left _ (by positivity) + apply add_le_add_right + exact (sq_le_sq₀ (sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).mpr hz.2.le + · exact degreeForcedRoleEnergy_bound T n _ hT s (sourceLocalCenter T n) _ _ _ (sourceScheduledShift_hasPlateau T n) + (fun j => hiddenBinomialCap (n j) ω) (fun j => hiddenBinomialCap (sourceScheduledTrials T n j) ω) + (fun j => hiddenBinomialCap_nonneg _ _) (fun j => hiddenBinomialCap_nonneg _ _) + b r _ (hiddenConditions_binomialCaps T n _ ω (b+1) _ hz.1) 0 + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Pointwise equality of the literal source types and the signed tree types. + This holds for every assignment, including overflowing windows. -/ +theorem sourceFlatLeafType_window (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (b : ℕ) (incoming : ℤ) (τ : Bool) (bits : Fin (SourceTrialCount T n b) → Bool) : + sourceFlatLeafType T n s center b incoming τ bits = + windowFinType T s (sourceTreeAnchors T n (sourceScheduledTrials T n) center + (sourceScheduledShift T n) b ((sourceAssignmentCode T n Bool b).symm bits) incoming) + b (boolTypeSign τ) := by + funext j + unfold sourceFlatLeafType windowFinType windowLeafType + rw [←sourceTreeLeafSign_eq,←sourceTreeLeafBool_sign] + change sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j)= + decide (boolTypeSign (sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j))= -1) + cases sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j) <;> norm_num [boolTypeSign] + +def sourceSparseCount (T : ℕ → ℕ) (s b : ℕ) : ℕ := + 2^s*∏j∈Finset.range b,T (j+1) + +theorem sourceFlatLeafType_sparse (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (b : ℕ) (incoming : ℤ) (τ : Bool) (bits : Fin (SourceTrialCount T n (b+1)) → Bool) : + monomialDegree (sourceFlatLeafType T n s center (b+1) incoming τ bits) ≤ sourceSparseCount T s b := by + rw [sourceFlatLeafType_window,windowFinType_degree] + exact windowMinusCount_bound T s _ b [] _ + +def sourceOracleCoefficient {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : + (Fin (SourceLeafCount T (b+1)) → Bool) → ℝ := + averagedCoefficient (PairedMechanisms.orientationsGiven z) + (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) + +theorem sourceOracleCoefficient_empty {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : + sourceOracleCoefficient T n s b z τ (fun _ => false)=1 := averagedCoefficient_empty _ _ + +theorem sourceOracleCoefficient_degree {Side : Type*} (T n : ℕ → ℕ) (s b r : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : + (∑σ, if monomialDegree σ=r then (sourceOracleCoefficient T n s b z τ σ)^2 else 0) ≤ + ((sourceSparseCount T s b).choose r:ℝ) := + averaged_sparse_degree _ _ (sourceFlatLeafType_sparse T n s _ b 0 τ) r + +def sourceSignedCoefficient {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (σ : Fin (SourceLeafCount T (b+1)) → Bool) : ℝ := + sourceOracleCoefficient T n s b z false σ-sourceOracleCoefficient T n s b z true σ + +theorem sourceSignedCoefficient_zero {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) : + (∑σ, if monomialDegree σ=0 then sourceSignedCoefficient T n s b z σ^2 else 0)=0 := by + simp [monomialDegree_eq_zero_iff,sourceSignedCoefficient,sourceOracleCoefficient_empty] + +theorem sourceSignedCoefficient_degree_geometric {Side : Type*} (T n : ℕ → ℕ) (s b r : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (w : ℝ) : + w^(2*r)*(∑σ, if monomialDegree σ=r then sourceSignedCoefficient T n s b z σ^2 else 0) ≤ + 4*(w^2*sourceSparseCount T s b)^r := by + have h0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity + have hp := sourceOracleCoefficient_degree T n s b r z false + have hm := sourceOracleCoefficient_degree T n s b r z true + have hc : ((sourceSparseCount T s b).choose r:ℝ) ≤ (sourceSparseCount T s b:ℝ)^r := by + exact_mod_cast Nat.choose_le_pow (sourceSparseCount T s b) r + have hd := degree_square_sub_le (sourceOracleCoefficient T n s b z false) + (sourceOracleCoefficient T n s b z true) r + calc + _ ≤ w^(2*r)*(4*(sourceSparseCount T s b:ℝ)^r) := + mul_le_mul_of_nonneg_left (by dsimp only [sourceSignedCoefficient]; linarith) h0 + _ = _ := by rw [pow_mul,mul_pow]; ring + +def sourceEnergyBudget (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) : ℝ := + (∑r∈Finset.range R, w^(2*r)*(if r=0 then 0 else sourceDegreeBudget T n s b r ω η a))+ + 4*(w^2*sourceSparseCount T s b)^R/(1-w^2*sourceSparseCount T s b) + +/-- Complete signed energy, with finite low-degree forced-tree bound and + the geometric high tail. No coefficient estimates remain as hypotheses. -/ +theorem source_canonical_energy {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 if r=0 then 0 else sourceDegreeBudget T n s b r ω η a) + · intro r _ + by_cases hr : r=0 + · subst r + rw [sourceSignedCoefficient_zero,ite_eq_left rfl] + · rw [ite_eq_right hr] + exact source_canonical_degree_bound T n hT s b r ω η a ha hη z hz + · intro r _ + exact sourceSignedCoefficient_degree_geometric T n s b r z w + · intro r + split_ifs + · rfl + · exact sourceDegreeBudget_nonneg T n s b r ω η a + +theorem nonconstant_eq_degreeTail {l : ℕ} (A : (Fin l → Bool) → ℝ) : + nonconstantCoefficient A=degreeTail A 1 := by + funext σ + by_cases h : σ=(fun _ => false) + · subst σ; simp [nonconstantCoefficient,degreeTail,monomialDegree] + · have hd : 1 ≤ monomialDegree σ := by + have := (monomialDegree_eq_zero_iff σ).not.mpr h + omega + simp [nonconstantCoefficient,degreeTail,h,hd] + +/-- The individual density is close to the pure reference without any + metadata typicality assumption. -/ +theorem source_canonical_centered_energy {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) {w : ℝ} (hw : 0 ≤ w) + (hsmall : w^2*sourceSparseCount T s b<1) : + multilinearEnergy (nonconstantCoefficient (sourceOracleCoefficient T n s b z τ)) w ≤ + (w^2*sourceSparseCount T s b)/(1-w^2*sourceSparseCount T s b) := by + rw [nonconstant_eq_degreeTail] + simpa only [pow_one,sourceOracleCoefficient] using averaged_sparse_tail_energy _ _ + (sourceFlatLeafType_sparse T n s _ b 0 τ) 1 hw hsmall + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction.FiniteLaw +open scoped Classical +variable {α : Type*} [Fintype α] + +theorem abs_expect_pow_le (P : FiniteLaw α) (F : α → ℝ) (t : ℕ) : + |P.expect F|^t ≤ P.expect (fun a => |F a|^t) := by + have habs : |P.expect F| ≤ P.expect (fun a => |F a|) := by + calc + _ ≤ ∑a, |P.mass a*F a| := Finset.abs_sum_le_sum_abs _ _ + _ = _ := by simp only [abs_mul,abs_of_nonneg (P.nonneg _)]; rfl + apply (pow_le_pow_left₀ (abs_nonneg _) habs t).trans + simpa only [smul_eq_mul,expect] using + (convexOn_pow (𝕜:=ℝ) t).map_sum_le (t:=Finset.univ) + (w:=P.mass) (p:=fun a => |F a|) (fun a _ => P.nonneg a) P.total (fun a _ => (show |F a| ∈ Set.Ici (0:ℝ) from abs_nonneg (F a))) + +theorem density_score_centered (P Q : FiniteLaw α) (Z : α → ℝ) + (hZ : ∀a,Q.mass a=P.mass a*(1+Z a)) : P.expect Z=0 := by + have h := Q.total + simp_rw [hZ,mul_add,mul_one,Finset.sum_add_distrib,P.total] at h + change _+P.expect Z=1 at h + linarith + +/-- Common-event mass difference is controlled by the restricted density + difference at every moment, by finite Jensen rather than a pointwise bound. -/ +theorem clipping_mass_difference (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) + (A : Finset α) (t : ℕ) : + |(R.withDensity f hf hfm).eventMass A-(R.withDensity g hg hgm).eventMass A|^t ≤ + R.expect (fun a => |if a∈A then g a-f a else 0|^t) := by + have he : (R.withDensity f hf hfm).eventMass A-(R.withDensity g hg hgm).eventMass A= + -(R.expect (fun a => if a∈A then g a-f a else 0)) := by + simp only [expect,mul_ite,mul_zero,←Finset.sum_filter, + Finset.filter_mem_eq_inter,Finset.univ_inter,eventMass,withDensity,mul_sub, + Finset.sum_sub_distrib] + ring + rw [he,abs_neg] + exact R.abs_expect_pow_le _ t + +theorem clipped_raw_moment_restricted (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀a,0 ≤ f a) (hfm : R.expect f=1) + (A : Finset α) (hAf : ∀a∈A,1/2 ≤ f a) + (hP : 0<(R.withDensity f hf hfm).eventMass A) (k : ℕ) : + (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g a/f a-1|^(k+1)) ≤ + 2^k/(R.withDensity f hf hfm).eventMass A * + R.expect (fun a => |if a∈A then g a-f a else 0|^(k+1)) := by + let g' : α → ℝ := fun a => if a∈A then g a else f a + have H := clipped_raw_moment R f g' hf hfm A hAf hP k + have he : (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g a/f a-1|^(k+1))= + (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g' a/f a-1|^(k+1)) := by + apply Finset.sum_congr rfl + intro a _ + by_cases ha : a∈A <;> simp [condition,g',ha] + rw [he] + convert H using 1 + congr 2 + funext a + by_cases ha : a∈A <;> simp [g',ha] + +/-- Explicit normalized clipping, at half of any positive even moment. This + constructs the actual conditioned score; no bounded-score hypothesis. -/ +theorem clipped_score_moment (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) + (A : Finset α) (hAf : ∀a∈A,1/2 ≤ f a) + (hp : 1/2 ≤ (R.withDensity f hf hfm).eventMass A) + (hq : 1/2 ≤ (R.withDensity g hg hgm).eventMass A) + (k : ℕ) (hk : 1 ≤ k) (V : ℝ) (hV : 0 ≤ V) + (hM : R.expect (fun a => |if a∈A then g a-f a else 0|^(2*k)) ≤ V^k) : + let p := (R.withDensity f hf hfm).eventMass A + let q := (R.withDensity g hg hgm).eventMass A + let hP : 0 < p := lt_of_lt_of_le (by norm_num) hp + (condition (R.withDensity f hf hfm) A hP).evenMomentSq (fun a => p/q*(g a/f a)-1) k ≤64*V := by + dsimp only + let p := (R.withDensity f hf hfm).eventMass A + let q := (R.withDensity g hg hgm).eventMass A + have hp0 : 0

|g a/f a-1|^(2*k)) ≤ + 2^(2*k)*V^k := by + apply hraw.trans + calc + _ ≤ (2^(2*k-1)/p)*V^k := mul_le_mul_of_nonneg_left hM (by positivity) + _ ≤ (2^(2*k-1)*2)*V^k := by + apply mul_le_mul_of_nonneg_right _ (pow_nonneg hV _) + simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hden (by positivity : 0 ≤ (2:ℝ)^(2*k-1)) + _ = _ := by rw [←pow_succ,ht] + have hnorm : |p/q-1|^(2*k) ≤ 2^(2*k)*V^k := by + rw [div_sub_one hq0.ne',abs_div,abs_of_pos hq0,div_pow] + apply (div_le_iff₀ (pow_pos hq0 _)).mpr + have hd := (clipping_mass_difference R f g hf hg hfm hgm A (2*k)).trans hM + have hqpow : 1 ≤ (2*q)^(2*k) := one_le_pow₀ (by linarith) + calc + _ ≤ V^k := hd + _ ≤ (2*q)^(2*k)*V^k := by nlinarith [pow_nonneg hV k] + _ = _ := by rw [mul_pow]; ring + have hs := score_rescaling_moment (condition (R.withDensity f hf hfm) A hp0) + (fun a => g a/f a) (p/q) (div_nonneg hp0.le hq0.le) (2*k-1) + rw [ht] at hs + have hpower : (p/q)^(2*k) ≤ (2:ℝ)^(2*k) := + pow_le_pow_left₀ (div_nonneg hp0.le hq0.le) hratio _ + have hs' : (condition (R.withDensity f hf hfm) A hp0).expect (fun a => |p/q*(g a/f a)-1|^(2*k)) ≤ + (64*V)^k := by + apply hs.trans + calc + _ ≤ 2^(2*k-1)*(2^(2*k)*(2^(2*k)*V^k)+2^(2*k)*V^k) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact add_le_add (mul_le_mul hpower hraw' (by + apply Finset.sum_nonneg; intro a _; positivity [(condition (R.withDensity f hf hfm) A hp0).nonneg a]) (by positivity)) hnorm + _ ≤ 2^(2*k-1)*(2^(2*k)*(2^(2*k)*V^k)+2^(2*k)*(2^(2*k)*V^k)) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply add_le_add_right + have htwo : (1:ℝ) ≤ 2^(2*k) := one_le_pow₀ (by norm_num) + simpa only [one_mul] using mul_le_mul_of_nonneg_right htwo + (by positivity : 0 ≤ (2:ℝ)^(2*k)*V^k) + _ = (64*V)^k := by + have hm : 2^(2*k-1)*2= (2:ℝ)^(2*k) := by rw [←pow_succ,ht] + calc + _ = (2^(2*k-1)*2)*(2:ℝ)^(2*k)*(2:ℝ)^(2*k)*V^k := by ring + _ = _ := by rw [hm,←pow_add,←pow_add,mul_pow]; congr 1; rw [show 2*k+2*k+2*k=6*k by omega,pow_mul]; norm_num + unfold evenMomentSq + calc + _ ≤ ((64*V)^k)^(1/(k:ℝ)) := Real.rpow_le_rpow + (by apply Finset.sum_nonneg; intro a _; positivity [(condition (R.withDensity f hf hfm) A hp0).nonneg a]) hs' (by positivity) + _ = _ := by rw [←Real.rpow_natCast,one_div,Real.rpow_rpow_inv (by positivity) (by positivity)] + +end TraceReconstruction.FiniteLaw + +noncomputable section +namespace TraceReconstruction.FiniteLaw +open scoped Classical +variable {α : Type*} [Fintype α] + +theorem eventMass_indicator (P : FiniteLaw α) (A : Finset α) : + P.eventMass A=P.expect (fun a => if a∈A then 1 else 0) := by + simp only [expect,mul_ite,mul_one,mul_zero,←Finset.sum_filter, + Finset.filter_mem_eq_inter,Finset.univ_inter,eventMass] + +theorem eventMass_compl (P : FiniteLaw α) (A : Finset α) : + P.eventMass Aᶜ=1-P.eventMass A := by + rw [eventMass_indicator,eventMass_indicator] + have he : P.expect (fun a => (if a∈Aᶜ then (1:ℝ) else 0)+(if a∈A then 1 else 0))=1 := by + convert P.expect_const 1 using 1 + congr 1; funext a + by_cases ha : a∈A <;> simp [ha] + rw [expect_add] at he + linarith + +theorem density_second_moment_le_six (R : FiniteLaw α) (f : α → ℝ) (k : ℕ) (hk : 1 ≤ k) + (hM : R.expect (fun a => |f a-1|^(2*k)) ≤ 1) : + R.expect (fun a => f a^2) ≤ 6 := by + have h := R.expect_lower_moment_le_two (fun a => f a-1) (2*k) hM 2 (by omega) + calc + _ ≤ R.expect (fun a => 2*(f a-1)^2+2) := R.expect_mono (fun a => by nlinarith [sq_nonneg (f a-2)]) + _ = 2*R.expect (fun a => (f a-1)^2)+2 := by rw [expect_add,expect_const_mul,expect_const] + _ ≤ _ := by linarith [le_abs_self (R.expect (fun a => (f a-1)^2))] + +/-- Cauchy--Schwarz loss on the actual low-reference-density event, for + either density. The same clipping event is used for both hypotheses. -/ +theorem density_low_event_mass (R : FiniteLaw α) (f g : α → ℝ) + (hg : ∀a,0 ≤ g a) (hgm : R.expect g=1) (k : ℕ) (hk : 1 ≤ k) (U : ℝ) + (hU : 0 ≤ U) (hU1 : U ≤ 1) + (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) + (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) : + (R.withDensity g hg hgm).eventMass (Finset.univ.filter (fun a => f a<1/2)) ≤ + Real.sqrt (6*(4*U)^k) := by + let A := Finset.univ.filter (fun a => f a<1/2) + have hR : R.eventMass A ≤ (4*U)^k := by + calc + _ ≤ 2^(2*k)*R.expect (fun a => |f a-1|^(2*k)) := + R.low_density_reference_mass f (2*k) A (fun a ha => (Finset.mem_filter.mp ha).2) + _ ≤ 2^(2*k)*U^k := mul_le_mul_of_nonneg_left hfM (by positivity) + _ = _ := by rw [pow_mul,mul_pow]; norm_num + have hsecond := R.density_second_moment_le_six g k hk (hgM.trans (pow_le_one₀ hU hU1)) + have hsq : ((R.withDensity g hg hgm).eventMass A)^2 ≤ 6*(4*U)^k := by + apply (R.density_bad_mass_sq g A).trans + calc + _ ≤ R.eventMass A*6 := mul_le_mul_of_nonneg_left hsecond (R.eventMass_nonneg A) + _ ≤ _ := by nlinarith + exact (Real.le_sqrt ((R.withDensity g hg hgm).eventMass_nonneg A) (by positivity)).mpr hsq + +def commonClipEvent (B : Finset α) (f : α → ℝ) : Finset α := + B.filter (fun a => 1/2 ≤ f a) + +theorem commonClipEvent_loss (P : FiniteLaw α) (B : Finset α) (f : α → ℝ) : + 1-P.eventMass (commonClipEvent B f) ≤ + P.eventMass Bᶜ+P.eventMass (Finset.univ.filter (fun a => f a<1/2)) := by + rw [←eventMass_compl,eventMass_indicator,eventMass_indicator,eventMass_indicator,←expect_add] + apply P.expect_mono + intro a + simp only [commonClipEvent,Finset.mem_compl,Finset.mem_filter,Finset.mem_univ,true_and] + split_ifs <;> simp_all + + +/-- Quantitative common clipping on any genuine good event. Both bad-event + costs below are measured under the actual normalized laws, not reference mass. -/ +theorem commonClipEvent_mass (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) + (B : Finset α) (e : ℝ) (hfB : (R.withDensity f hf hfm).eventMass Bᶜ ≤ e) + (hgB : (R.withDensity g hg hgm).eventMass Bᶜ ≤ e) + (k : ℕ) (hk : 1 ≤ k) (U : ℝ) (hU : 0 ≤ U) (hU1 : U ≤ 1) + (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) + (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) : + 1-(R.withDensity f hf hfm).eventMass (commonClipEvent B f) ≤ e+Real.sqrt (6*(4*U)^k) ∧ + 1-(R.withDensity g hg hgm).eventMass (commonClipEvent B f) ≤ e+Real.sqrt (6*(4*U)^k) := by + constructor + · exact (commonClipEvent_loss _ B f).trans (add_le_add hfB + (density_low_event_mass R f f hf hfm k hk U hU hU1 hfM hfM)) + · exact (commonClipEvent_loss _ B f).trans (add_le_add hgB + (density_low_event_mass R f g hg hgm k hk U hU hU1 hfM hgM)) + +end TraceReconstruction.FiniteLaw + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- A pair produced by genuine common-event normalized conditioning. The + outcome space and public decoder remain unchanged. -/ +structure ClippedOracle {α : Type*} [Fintype α] (P Q : FiniteLaw α) (k : ℕ) (e V : ℝ) where + first : FiniteLaw α + second : FiniteLaw α + score : α → ℝ + density : ∀a,second.mass a=first.mass a*(1+score a) + likelihood_nonneg : ∀a,0 ≤ 1+score a + centered : first.expect score=0 + moment : first.evenMomentSq score k ≤ V + first_tv : first.tv P ≤ e + second_tv : second.tv Q ≤ e + +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +theorem exists_clippedOracle (R : FiniteLaw α) (f g : α → ℝ) + (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) + (B : Finset α) (e : ℝ) (hfB : (R.withDensity f hf hfm).eventMass Bᶜ ≤ e) + (hgB : (R.withDensity g hg hgm).eventMass Bᶜ ≤ e) + (k : ℕ) (hk : 1 ≤ k) (U : ℝ) (hU : 0 ≤ U) (hU1 : U ≤ 1) + (hfM : R.expect (fun a => |f a-1|^(2*k)) ≤ U^k) + (hgM : R.expect (fun a => |g a-1|^(2*k)) ≤ U^k) + (V : ℝ) (hV : 0 ≤ V) + (hM : R.expect (fun a => |if a∈B then g a-f a else 0|^(2*k)) ≤ V^k) + (hsmall : e+Real.sqrt (6*(4*U)^k) ≤ 1/2) : + Nonempty (ClippedOracle (R.withDensity f hf hfm) (R.withDensity g hg hgm) + k (e+Real.sqrt (6*(4*U)^k)) (64*V)) := by + let A := commonClipEvent B f + let P := R.withDensity f hf hfm + let Q := R.withDensity g hg hgm + have hA (a : α) (ha : a∈A) : 1/2 ≤ f a := (Finset.mem_filter.mp ha).2 + have hloss := commonClipEvent_mass R f g hf hg hfm hgm B e hfB hgB k hk U hU hU1 hfM hgM + have hp : 1/2 ≤ P.eventMass A := by linarith [hloss.1] + have hq : 1/2 ≤ Q.eventMass A := by linarith [hloss.2] + have hp0 : 0 P.eventMass A/Q.eventMass A*(g a/f a)-1 + have hden (a : α) : (Q.condition A hq0).mass a=(P.condition A hp0).mass a*(1+Z a) := by + dsimp only [Z] + rw [show 1+(P.eventMass A/Q.eventMass A*(g a/f a)-1)=P.eventMass A/Q.eventMass A*(g a/f a) by ring] + exact conditioned_density_identity R f g hf hg hfm hgm A + (fun a ha => lt_of_lt_of_le (by norm_num) (hA a ha)) hp0 hq0 a + have hAM : R.expect (fun a => |if a∈A then g a-f a else 0|^(2*k)) ≤ V^k := by + apply le_trans (R.expect_mono _) hM + intro a + by_cases ha : a∈A + · have hb := (Finset.mem_filter.mp ha).1 + simp only [ite_eq_left ha,ite_eq_left hb,le_refl] + · rw [ite_eq_right ha] + simp only [abs_zero,zero_pow (by omega : 2*k≠0)] + exact pow_nonneg (abs_nonneg _) _ + exact ⟨{ + first := P.condition A hp0 + second := Q.condition A hq0 + score := Z + density := hden + likelihood_nonneg := fun a => by + dsimp only [Z] + have hh := mul_nonneg (div_nonneg hp0.le hq0.le) (div_nonneg (hg a) (hf a)) + linarith + centered := density_score_centered _ _ Z hden + moment := clipped_score_moment R f g hf hg hfm hgm A hA hp hq k hk V hV hAM + first_tv := by rw [tv_symm,tv_condition]; exact hloss.1 + second_tv := by rw [tv_symm,tv_condition]; exact hloss.2 + }⟩ + +end FiniteLaw +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Exact finite-union metadata cost; it contains no postulated typical + event and no independence assertion between different collections. -/ +def sourceEffectiveHiddenTail (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : ℝ := + ∑v : WindowCollection T b,if collectionCount T n (sourceScheduledTrials T n) b v=0 then 0 else Real.exp (-(collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^4/16) + +theorem source_hidden_conditions_effective_tail {Side : Type*} [Fintype Side] + (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n b)) + (ω : ℝ) (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : + M.reports.expect (fun z => if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω b + (sourceReportFlags T n b z) then 0 else 1) ≤ sourceEffectiveHiddenTail T n b ω := by + calc + _ ≤ M.reports.expect (fun z => ∑v : WindowCollection T b, + if (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ + ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) + then 0 else 1) := by + apply FiniteLaw.expect_mono + intro z + simp only [hiddenCollectionConditions_iff] + exact failure_forall_le_sum _ + _ = ∑v : WindowCollection T b,M.reports.expect (fun z => + if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< + ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0) := by + rw [FiniteLaw.expect_fintype_sum] + apply Finset.sum_congr rfl + intro v _ + apply congrArg (FiniteLaw.expect M.reports) + funext z + rw [sourceCollectionSet_card,sourceCollection_hidden,Nat.cast_sum] + by_cases h : (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ + ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) + · simp [h,not_lt.mpr h] + · simp [h,lt_of_not_ge h] + _ ≤ _ := by + apply Finset.sum_le_sum + intro v _ + by_cases hc : collectionCount T n (sourceScheduledTrials T n) b v=0 + · rw [ite_eq_left hc] + have hz : M.reports.expect (fun z => + if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< + ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0)=0 := by + have h (z : Reports Side (SourceTrialCount T n b)) : + ¬(PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< + ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 := by + rw [sourceCollectionSet_card,hc] + simp only [Nat.cast_zero,zero_mul,zero_div] + exact not_lt.mpr (Nat.cast_nonneg _) + simp_rw [ite_eq_right (h _)] + exact FiniteLaw.expect_const _ 0 + exact hz.le + · rw [ite_eq_right hc] + simpa only [sourceCollectionSet_card] using M.hiddenSubset_small (sourceCollectionSet T n b v) hw hp + +theorem source_typical_effective_failure {Side : Type*} [Fintype Side] + (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (ω a : ℝ) (ha : 0 if SourceTypical T n s b ω a z then 0 else 1) ≤ + sourceEffectiveHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a := by + let f := fun z : Reports Side (SourceTrialCount T n (b+1)) => + sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) + (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) + (sourceReportFlags T n (b+1) z) 0 + calc + _ ≤ M.reports.expect (fun z => + (if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) + (sourceReportFlags T n (b+1) z) then 0 else 1)+(if a≤f z then 1 else 0)) := by + apply FiniteLaw.expect_mono + intro z + by_cases H : SourceTypical T n s b ω a z + · rw [ite_eq_left H] + split_ifs <;> norm_num + · rw [ite_eq_right H] + by_cases h : HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) + (sourceReportFlags T n (b+1) z) + · have hf : ¬f z H ⟨h,hf⟩ + rw [ite_eq_left h,ite_eq_left (le_of_not_gt hf)] + norm_num + · rw [ite_eq_right h] + split_ifs <;> norm_num + _ ≤ _ := by + rw [FiniteLaw.expect_add] + apply add_le_add (source_hidden_conditions_effective_tail T n (b+1) M ω hw hp) + apply (M.reports.positive_markov f (fun z => sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).trans + exact div_le_div_of_nonneg_right + (source_noncentral_average T n s b M hn hne hT he hL hroot) ha.le + + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Literal density of the source's unconditioned finite canonical oracle. -/ +def sourceOracleDensity {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (Z : Leaf → ℝ) (τ : Bool) + (zx : Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) : ℝ := + averagedDensity (PairedMechanisms.orientationsGiven zx.1) + (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) Z zx.2 + +theorem sourceOracleDensity_expansion {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (Z : Leaf → ℝ) (τ : Bool) + (z : Reports Side (SourceTrialCount T n (b+1))) (x : Fin (SourceLeafCount T (b+1)) → Leaf) : + sourceOracleDensity T n s b Z τ (z,x)=multilinear (sourceOracleCoefficient T n s b z τ) Z x := + averagedDensity_expansion _ _ _ _ + +theorem sourceOracleDensity_nonneg {Side Leaf : Type*} (T n : ℕ → ℕ) (s b : ℕ) + (Z : Leaf → ℝ) (hZ : ∀a,0 ≤ 1+Z a) (τ : Bool) + (zx : Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) : + 0 ≤ sourceOracleDensity T n s b Z τ zx := averagedDensity_nonneg _ _ _ hZ _ + +theorem sourceOracleDensity_mean {Side Leaf : Type*} [Fintype Leaf] (T n : ℕ → ℕ) (s b : ℕ) + (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hZ : P.expect Z=0) (τ : Bool) + (z : Reports Side (SourceTrialCount T n (b+1))) : + (P.product (SourceLeafCount T (b+1))).expect (fun x => sourceOracleDensity T n s b Z τ (z,x))=1 := + averagedDensity_mean P (PairedMechanisms.orientationsGiven z) Z hZ + (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) + +theorem source_canonical_centered_moment {Side Leaf : Type*} [Fintype Leaf] + (T n : ℕ → ℕ) (s b k : ℕ) (P : FiniteLaw Leaf) (Z : Leaf → ℝ) + (hk : 1 ≤ k) (hcenter : P.expect Z=0) {L : ℝ} (hL : 0 |Z a|^(2*k)) ≤ L^(2*k)) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) + (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : + (P.product (SourceLeafCount T (b+1))).expect + (fun x => |sourceOracleDensity T n s b Z τ (z,x)-1|^(2*k)) ≤ + ((((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b)/ + (1-((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b))^k := by + have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : + sourceOracleDensity T n s b Z τ (z,x)-1= + multilinear (nonconstantCoefficient (sourceOracleCoefficient T n s b z τ)) Z x := by + rw [nonconstant_multilinear,sourceOracleCoefficient_empty,sourceOracleDensity_expansion] + simp_rw [he] + apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans + exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) + (source_canonical_centered_energy T n s b z τ (by positivity) hsmall) k + +theorem source_canonical_signed_moment {Side Leaf : Type*} [Fintype Leaf] + (T n : ℕ → ℕ) (hT : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) + (z : Reports Side (SourceTrialCount T n (b+1))) (hz : SourceTypical T n s b ω a z) : + (P.product (SourceLeafCount T (b+1))).expect + (fun x => |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|^(2*k)) ≤ + (sourceEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by + have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : + |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|= + |multilinear (sourceSignedCoefficient T n s b z) Z x| := by + unfold sourceSignedCoefficient + rw [multilinear_sub,←sourceOracleDensity_expansion,←sourceOracleDensity_expansion,abs_sub_comm] + simp_rw [he] + apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans + exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) + (source_canonical_energy T n hT s b R ω η a _ ha (by positivity) hsmall hη z hz) k + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem degreeForcedRoleEnergy_zero_of_lt (T n g : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) + (globalShift : (b : ℕ) → (Fin (g b) → Bool) → Fin (T b) → ℤ) + (A : (b : ℕ) → Finset (Fin (T b))) (b r : ℕ) (hr : r<2^(b+1)) + (d : WindowAssignments T n g (Option Bool) (b+1)) (incoming : ℤ) : + degreeForcedRoleEnergy T n g s center globalShift A b r d incoming=0 := by + have hi : IsEmpty (DegreeForcedRole T b r) := ⟨fun w => by + obtain ⟨F⟩ := w.property.2 + have hh := F.leaf_lower + rw [occupiedWindowTerm_leafCount,w.property.1] at hh + omega⟩ + let := hi + exact Finset.sum_eq_zero (fun w _ => isEmptyElim w) + +/-- Below the genuine forced binary leaf threshold there is NO forced + contribution; retaining even its coarse bound would lose the main exponent. -/ +def sourceSharpDegreeBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : ℝ := + 4*(3^((b+1)*r):ℕ)* + (((SourceLeafCount T (b+1)).choose r:ℕ)*(3^((b+1)*r):ℕ)*(η^2+a^2)+ + if 2^(b+1)≤r then sourceForcedBudget T n s b r ω else 0) + +theorem sourceSharpDegreeBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : + 0 ≤ sourceSharpDegreeBudget T n s b r ω η a := by + have h := sourceForcedBudget_nonneg T n s b r ω + unfold sourceSharpDegreeBudget + split_ifs <;> positivity + +theorem source_canonical_sharp_degree_bound {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 centralThird (T j)) b r + (sourceReportFlags T n (b+1) z) 0 η + (hiddenConditions_smoothingCap T n _ ω η s (b+1) hη _ hz.1)).trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply add_le_add + · apply mul_le_mul_of_nonneg_left _ (by positivity) + apply add_le_add_right + exact (sq_le_sq₀ (sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).mpr hz.2.le + · by_cases hr : 2^(b+1)≤r + · rw [ite_eq_left hr] + exact degreeForcedRoleEnergy_bound T n _ hT s (sourceLocalCenter T n) _ _ _ (sourceScheduledShift_hasPlateau T n) + (fun j => hiddenBinomialCap (n j) ω) (fun j => hiddenBinomialCap (sourceScheduledTrials T n j) ω) + (fun j => hiddenBinomialCap_nonneg _ _) (fun j => hiddenBinomialCap_nonneg _ _) + b r _ (hiddenConditions_binomialCaps T n _ ω (b+1) _ hz.1) 0 + · rw [ite_eq_right hr,degreeForcedRoleEnergy_zero_of_lt T n _ s _ _ _ b r (lt_of_not_ge hr)] +def sourceSharpEnergyBudget (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) : ℝ := + (∑r∈Finset.range R, w^(2*r)*(if r=0 then 0 else sourceSharpDegreeBudget T n s b r ω η a))+ + 4*(w^2*sourceSparseCount T s b)^R/(1-w^2*sourceSparseCount T s b) + +/-- Complete signed energy, with finite low-degree forced-tree bound and + the geometric high tail. No coefficient estimates remain as hypotheses. -/ +theorem source_canonical_sharp_energy {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 if r=0 then 0 else sourceSharpDegreeBudget T n s b r ω η a) + · intro r _ + by_cases hr : r=0 + · subst r + rw [sourceSignedCoefficient_zero,ite_eq_left rfl] + · rw [ite_eq_right hr] + exact source_canonical_sharp_degree_bound T n hT s b r ω η a ha hη z hz + · intro r _ + exact sourceSignedCoefficient_degree_geometric T n s b r z w + · intro r + split_ifs + · rfl + · exact sourceSharpDegreeBudget_nonneg T n s b r ω η a + +theorem sourceSharpEnergyBudget_nonneg (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) + (hsmall : w^2*sourceSparseCount T s b<1) : + 0 ≤ sourceSharpEnergyBudget T n s b R ω η a w := by + apply add_nonneg + · apply Finset.sum_nonneg + intro r _ + apply mul_nonneg (pow_nonneg (sq_nonneg w) r |>.trans_eq (pow_mul w 2 r).symm) + split_ifs + · rfl + · exact sourceSharpDegreeBudget_nonneg T n s b r ω η a + · exact div_nonneg (by positivity) (sub_nonneg.mpr hsmall.le) + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +local instance (priority := 10000) {α β : Type*} : DecidableEq (α × β) := Classical.decEq _ + +theorem source_canonical_sharp_signed_moment {Side Leaf : Type*} [Fintype Leaf] + (T n : ℕ → ℕ) (hT : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) + (z : Reports Side (SourceTrialCount T n (b+1))) (hz : SourceTypical T n s b ω a z) : + (P.product (SourceLeafCount T (b+1))).expect + (fun x => |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|^(2*k)) ≤ + (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by + have he (x : Fin (SourceLeafCount T (b+1)) → Leaf) : + |sourceOracleDensity T n s b Z true (z,x)-sourceOracleDensity T n s b Z false (z,x)|= + |multilinear (sourceSignedCoefficient T n s b z) Z x| := by + unfold sourceSignedCoefficient + rw [multilinear_sub,←sourceOracleDensity_expansion,←sourceOracleDensity_expansion,abs_sub_comm] + simp_rw [he] + apply (multilinear_moment_scaled P Z k hk hcenter hL hMoment _ _).trans + exact pow_le_pow_left₀ (multilinearEnergy_nonneg _ _) + (source_canonical_sharp_energy T n hT s b R ω η a _ ha (by positivity) hsmall hη z hz) k + + +def sourceReferenceLaw {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (P : FiniteLaw Leaf) : + FiniteLaw (Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) := + M.reports.prod (P.product (SourceLeafCount T (b+1))) + +theorem sourceOracleDensity_total {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hZ : P.expect Z=0) (τ : Bool) : + (sourceReferenceLaw T n b M P).expect (sourceOracleDensity T n s b Z τ)=1 := by + rw [sourceReferenceLaw,FiniteLaw.expect_prod] + simp_rw [sourceOracleDensity_mean T n s b P Z hZ τ] + exact M.reports.expect_const 1 + +theorem sourceOracle_withDensity {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (P Q : FiniteLaw Leaf) (Z : Leaf → ℝ) (hden : ∀a,Q.mass a=P.mass a*(1+Z a)) + (hZ : ∀a,0 ≤ 1+Z a) (hc : P.expect Z=0) (τ : Bool) : + M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)= + (sourceReferenceLaw T n b M P).withDensity (sourceOracleDensity T n s b Z τ) + (sourceOracleDensity_nonneg T n s b Z hZ τ) + (sourceOracleDensity_total T n s b M P Z hc τ) := by + apply FiniteLaw.ext + funext zx + exact M.canonicalOracle_density P Q Z hden _ zx.1 zx.2 + +def sourceTypicalSet {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (s b : ℕ) (ω a : ℝ) : + Finset (Reports Side (SourceTrialCount T n (b+1)) × (Fin (SourceLeafCount T (b+1)) → Leaf)) := + Finset.univ.filter (fun x => SourceTypical T n s b ω a x.1) + +theorem sourceTypicalSet_mass {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (P Q : FiniteLaw Leaf) (ω a : ℝ) (τ : Bool) : + (M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)).eventMass + (sourceTypicalSet T n s b ω a)ᶜ= + M.reports.expect (fun z => if SourceTypical T n s b ω a z then 0 else 1) := by + rw [FiniteLaw.eventMass_indicator] + calc + _ = (M.canonicalOracle P Q (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ)).expect + (fun zx => if SourceTypical T n s b ω a zx.1 then 0 else 1) := by + apply congrArg (FiniteLaw.expect _) + funext zx + simp [sourceTypicalSet] + _ = _ := M.canonicalOracle_metadata P Q + (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) + (fun z => if SourceTypical T n s b ω a z then 0 else 1) + +def sourceCenteredBudget (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) : ℝ := + (((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b)/ + (1-((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b) + +def sourceClippingCost (T n : ℕ → ℕ) (s b k : ℕ) (ω a L : ℝ) : ℝ := + sourceEffectiveHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a+ + Real.sqrt (6*(4*sourceCenteredBudget T s b k L)^k) + +theorem sourceCenteredBudget_nonneg (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) : + 0 ≤ sourceCenteredBudget T s b k L := + div_nonneg (by positivity) (sub_nonneg.mpr hsmall.le) + +theorem sourceCenteredBudget_le_one (T : ℕ → ℕ) (s b k : ℕ) (L : ℝ) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b≤1/2) : + sourceCenteredBudget T s b k L ≤ 1 := by + have hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1 := by linarith + apply (div_le_iff₀ (sub_pos.mpr hsmall)).mpr + linarith + +theorem source_reference_centered_moment {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (s b k : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) + (P : FiniteLaw Leaf) (Z : Leaf → ℝ) (hk : 1 ≤ k) (hc : P.expect Z=0) + {L : ℝ} (hL : 0 |Z a|^(2*k)) ≤ L^(2*k)) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) (τ : Bool) : + (sourceReferenceLaw T n b M P).expect + (fun zx => |sourceOracleDensity T n s b Z τ zx-1|^(2*k)) ≤ (sourceCenteredBudget T s b k L)^k := by + rw [sourceReferenceLaw,FiniteLaw.expect_prod] + calc + _ ≤ M.reports.expect (fun _ => (sourceCenteredBudget T s b k L)^k) := + M.reports.expect_mono (fun z => source_canonical_centered_moment T n s b k P Z hk hc hL hMoment hsmall z τ) + _ = _ := M.reports.expect_const _ + +theorem source_reference_signed_moment {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (hTpos : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) + (hsmall : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b<1) + (hη : ∀j + |if zx∈sourceTypicalSet T n s b ω a then sourceOracleDensity T n s b Z true zx- + sourceOracleDensity T n s b Z false zx else 0|^(2*k)) ≤ + (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k := by + rw [sourceReferenceLaw,FiniteLaw.expect_prod] + have hV := sourceSharpEnergyBudget_nonneg T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L) hsmall + calc + _ ≤ M.reports.expect (fun _ => (sourceSharpEnergyBudget T n s b R ω η a ((6*(2*k:ℕ):ℝ)*L))^k) := by + apply M.reports.expect_mono + intro z + by_cases hz : SourceTypical T n s b ω a z + · simp only [sourceTypicalSet,Finset.mem_filter,Finset.mem_univ,true_and,hz,ite_true] + exact source_canonical_sharp_signed_moment T n hTpos s b R k ω η a ha hη P Z hk hc hL hMoment hsmall z hz + · simp only [sourceTypicalSet,Finset.mem_filter,Finset.mem_univ,true_and,hz,ite_false, + abs_zero,zero_pow (by omega : 2*k≠0),FiniteLaw.expect_const] + exact pow_nonneg hV k + _ = _ := M.reports.expect_const _ + +theorem source_reference_clipped_exists {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] + (T n : ℕ → ℕ) (hTpos : ∀j,0 |Z a|^(2*k)) ≤ L^(2*k)) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) + (hη : ∀j |Z a|^(2*k)) ≤ L^(2*k)) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b ≤ 1/2) + (hη : ∀j C.score x.1 + density x := by + change C.second.mass x.1*R.mass x.2=(C.first.mass x.1*R.mass x.2)*(1+C.score x.1) + rw [C.density]; ring + likelihood_nonneg x := C.likelihood_nonneg x.1 + centered := by + rw [FiniteLaw.expect_prod] + simp_rw [FiniteLaw.expect_const] + exact C.centered + moment := by + unfold FiniteLaw.evenMomentSq + rw [FiniteLaw.expect_prod] + simp_rw [FiniteLaw.expect_const] + exact C.moment + first_tv := by rw [FiniteLaw.tv_prod_eq_left]; exact C.first_tv + second_tv := by rw [FiniteLaw.tv_prod_eq_left]; exact C.second_tv +end ClippedOracle + +theorem ApproximatesTrace.of_tv {α : Type*} [Fintype α] + {q E e : ℝ} {P Q : FiniteLaw α} {f : α → List Bool} {w : List Bool} + (hP : ApproximatesTrace q P f w E) (htv : Q.tv P ≤ e) : + ApproximatesTrace q Q f w (e+E) := by + intro F hF + exact (abs_sub_le (Q.expect (fun a => F (f a))) (P.expect (fun a => F (f a))) + (listDeletionExpectation q w F)).trans (add_le_add + ((FiniteLaw.abs_expect_sub_le_tv Q P _ (fun a => hF _)).trans htv) (hP F hF)) + +/-- A finite genuine approximate oracle pair with a common complete-trace + decoder. It does not include an overlap or any unproved scale conclusion. -/ +structure OracleTracePair (q : ℝ) (x y : List Bool) (k : ℕ) (E V : ℝ) where + Outcome : Type + finiteOutcome : Fintype Outcome + first : @FiniteLaw Outcome finiteOutcome + second : @FiniteLaw Outcome finiteOutcome + decode : Outcome → List Bool + first_simulation : @ApproximatesTrace Outcome finiteOutcome q first decode x E + second_simulation : @ApproximatesTrace Outcome finiteOutcome q second decode y E + score : Outcome → ℝ + density : ∀a,second.mass a=first.mass a*(1+score a) + likelihood_nonneg : ∀a,0≤1+score a + centered : first.expect score=0 + moment : @FiniteLaw.evenMomentSq Outcome finiteOutcome first score k ≤ V + +/-- The clipping and independent filler metadata preserve the source's fixed + public trace decoder. -/ +theorem source_clipped_simulation {Side Leaf : Type} [Fintype Side] [Fintype Leaf] + {q E e V : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) + (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b k : ℕ) + (H : SourceLayoutMargins s P T n h b) + (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) + (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) + (hn : ∀j mul_nonneg (P.nonneg a) (hF a)) + +theorem evenMomentSq_nonneg (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) : + 0≤P.evenMomentSq F k := Real.rpow_nonneg (P.expect_nonneg _ (fun _ => by positivity)) _ + +theorem evenMomentSq_pow (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) : + (P.evenMomentSq F k)^k=P.expect (fun a => |F a|^(2*k)) := by + unfold evenMomentSq + rw [one_div,Real.rpow_inv_natCast_pow (P.expect_nonneg _ (fun _ => by positivity)) (by omega)] + +theorem expect_even_pow_le_of_moment (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) + {V : ℝ} (h : P.evenMomentSq F k≤V) : + P.expect (fun a => |F a|^(2*k))≤V^k := by + rw [←P.evenMomentSq_pow F k hk] + exact pow_le_pow_left₀ (P.evenMomentSq_nonneg F k) h k + +theorem secondMoment_le_evenMomentSq (P : FiniteLaw α) (F : α → ℝ) (k : ℕ) (hk : 1≤k) : + P.expect (fun a => F a^2)≤P.evenMomentSq F k := by + have hn : 0≤P.expect (fun a => F a^2) := P.expect_nonneg _ (fun _ => sq_nonneg _) + have hj := P.abs_expect_pow_le (fun a => F a^2) k + simp only [abs_of_nonneg hn,abs_pow,←pow_mul] at hj + have hr := Real.rpow_le_rpow (pow_nonneg hn k) hj (by positivity : 0≤(k:ℝ)⁻¹) + rw [Real.pow_rpow_inv_natCast hn (by omega)] at hr + simpa only [evenMomentSq,one_div] using hr + +theorem affinity_coordinateProduct {n : ℕ} (P Q : Fin n → FiniteLaw α) : + (coordinateProduct P).affinity (coordinateProduct Q)=∏i,(P i).affinity (Q i) := by + unfold affinity coordinateProduct + simp only + have he (a : Fin n → α) : + Real.sqrt (∏i,(P i).mass (a i))*Real.sqrt (∏i,(Q i).mass (a i))= + ∏i,Real.sqrt ((P i).mass (a i))*Real.sqrt ((Q i).mass (a i)) := by + rw [Real.sqrt_prod _ (fun i _ => (P i).nonneg (a i)), + Real.sqrt_prod _ (fun i _ => (Q i).nonneg (a i)),Finset.prod_mul_distrib] + simp_rw [he] + exact (Fintype.prod_sum (fun (i : Fin n) a => Real.sqrt ((P i).mass a)*Real.sqrt ((Q i).mass a))).symm + +theorem one_sub_prod_le_sum {ι : Type*} (S : Finset ι) (f : ι → ℝ) + (h0 : ∀i∈S,0≤f i) (h1 : ∀i∈S,f i≤1) : + 1-∏i∈S,f i≤∑i∈S,(1-f i) := by + induction S using Finset.induction_on with + | empty => simp + | @insert a S ha ih => + rw [Finset.prod_insert ha,Finset.sum_insert ha] + have H := ih (fun i hi => h0 i (Finset.mem_insert_of_mem hi)) + (fun i hi => h1 i (Finset.mem_insert_of_mem hi)) + have hs : 0≤∑i∈S,(1-f i) := Finset.sum_nonneg (fun i hi => sub_nonneg.mpr (h1 i (Finset.mem_insert_of_mem hi))) + have hm := mul_le_mul_of_nonneg_left H (h0 a (Finset.mem_insert_self a S)) + have hm' := mul_le_mul_of_nonneg_right (h1 a (Finset.mem_insert_self a S)) hs + nlinarith + +theorem hellingerSq_coordinateProduct_le {n : ℕ} (P Q : Fin n → FiniteLaw α) : + (coordinateProduct P).hellingerSq (coordinateProduct Q)≤∑i,(P i).hellingerSq (Q i) := by + simp_rw [hellingerSq_eq] + rw [affinity_coordinateProduct] + have h := one_sub_prod_le_sum Finset.univ (fun i => (P i).affinity (Q i)) + (fun i _ => affinity_nonneg _ _) (fun i _ => affinity_le_one _ _) + have he : (∑i,(2-2*(P i).affinity (Q i)))=2*∑i,(1-(P i).affinity (Q i)) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [he] + linarith + +@[simp] theorem hellingerSq_self (P : FiniteLaw α) : P.hellingerSq P=0 := by + simp [hellingerSq] + +theorem hellingerSq_symm (P Q : FiniteLaw α) : P.hellingerSq Q=Q.hellingerSq P := by + apply Finset.sum_congr rfl; intro a _; ring + +/-- Only differing coordinates cost squared Hellinger distance. This estimate + does not pay for pure filler coordinates, nor assume independence of traces + after their common concatenating decoder. -/ +theorem tv_mixedProduct_le {n : ℕ} (P Q : FiniteLaw α) (Z : α → ℝ) + (hden : ∀a,Q.mass a=P.mass a*(1+Z a)) (k : ℕ) (hk : 1≤k) + {V : ℝ} (hM : P.evenMomentSq Z k≤V) (τ σ : Fin n → Bool) : + (coordinateProduct (fun i => if τ i then Q else P)).tv + (coordinateProduct (fun i => if σ i then Q else P))≤ + Real.sqrt ((∑i,if τ i=σ i then (0:ℝ) else 1)*V) := by + have hH : P.hellingerSq Q≤V := (P.hellingerSq_le_score Q Z hden).trans + ((P.secondMoment_le_evenMomentSq Z k hk).trans hM) + apply (tv_le_sqrt_hellingerSq _ _).trans + apply Real.sqrt_le_sqrt + apply (hellingerSq_coordinateProduct_le _ _).trans + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro i _ + cases τ i <;> cases σ i <;> simp only [Bool.false_eq_true,Bool.true_eq_false,ite_false,ite_true, + zero_mul,one_mul,hellingerSq_self,le_refl] + · exact hH + · rw [hellingerSq_symm]; exact hH + +end TraceReconstruction.FiniteLaw + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Literal recursive source oracle with actual complete-trace side laws. + All remaining hypotheses here are explicit parameter inequalities, the old + leaf oracle, and its genuine repeated-word overlap invariant. -/ +theorem actual_source_oracle {Leaf : Type} [Fintype Leaf] + {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) + (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b R k : ℕ) + (H : SourceLayoutMargins s P T n h b) + (hTpos : ∀j,0 |Z a|^(2*k))≤L^(2*k)) + (hscale : ((6*(2*k:ℕ):ℝ)*L)^2*sourceSparseCount T s b≤1/2) + (hη : ∀j listTraceLaw q hq (W j) m (hW j) + have hp : ω^2∈Set.Icc 0 1 := ⟨sq_nonneg ω,by nlinarith [hω.1,hω.2]⟩ + obtain ⟨C⟩ := source_clippedOracle_exists T n hTpos s b R k M A B Z hden hZ ω a η L ha hL + (fun _ => rfl) hp hn H.even_trials hT he hMotif hroot hk hMoment hscale hη herror + apply source_clipped_simulation hq hE s P T n h atom b k H hP (he b le_rfl) hroot + (by nlinarith [hMotif b le_rfl]) hn M F A B Subtype.val g + (fun j => listTraceLaw_simulates q hq (U j) m (hU j)) + (fun j => listTraceLaw_simulates q hq (V j) m (hV j)) + (fun j => listTraceLaw_simulates q hq (W j) m (hW j)) hA hB C + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Testing.lean b/lean/OAI/Probability/TraceReconstruction/Testing.lean index dbe74046ebc1299ad7ecc90f1f9d3c4bd7962d4b..5166ccc4f48105ca59d8855a92ba21a176d160cb 100644 --- a/lean/OAI/Probability/TraceReconstruction/Testing.lean +++ b/lean/OAI/Probability/TraceReconstruction/Testing.lean @@ -1,221 +1,221 @@ -import OAI.Probability.TraceReconstruction.Restoration - -namespace OAI - -/-! -# Testing - -Multi-gadget family restoration and common-reference many-hypothesis statistics for every positive success level. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -namespace FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] - -theorem hellingerSq_prod_same_right (P Q : FiniteLaw α) (R : FiniteLaw β) : - (P.prod R).hellingerSq (Q.prod R)=P.hellingerSq Q := by - unfold hellingerSq prod - rw [Fintype.sum_prod_type] - have he (a : α) (b : β) : - (Real.sqrt (P.mass a*R.mass b)-Real.sqrt (Q.mass a*R.mass b))^2= - (Real.sqrt (P.mass a)-Real.sqrt (Q.mass a))^2*R.mass b := by - rw [Real.sqrt_mul (P.nonneg a),Real.sqrt_mul (Q.nonneg a),←sub_mul,mul_pow, - Real.sq_sqrt (R.nonneg b)] - simp_rw [he,←Finset.mul_sum,R.total,mul_one] - -end FiniteLaw - -def HellingerTracePair.suffix {q E V : ℝ} {x y : List Bool} - (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) (w : List Bool) : - HellingerTracePair q (x++w) (y++w) E V := by - let := C.finiteOutcome - let R := listTraceLaw q hq w w.length le_rfl - exact { - Outcome := C.Outcome × BoundedTrace w.length - finiteOutcome := inferInstance - first := C.first.prod R - second := C.second.prod R - decode := fun z=>C.decode z.1++z.2.val - first_simulation := by - simpa only [add_zero] using C.first_simulation.append hq - (listTraceLaw_simulates q hq w w.length le_rfl).approximate - second_simulation := by - simpa only [add_zero] using C.second_simulation.append hq - (listTraceLaw_simulates q hq w w.length le_rfl).approximate - bound := by rw [FiniteLaw.hellingerSq_prod_same_right]; exact C.bound } - -theorem coordinateWord_length_constant {g S : ℕ} (w : Fin g→List Bool) - (hw : ∀j,(w j).length=S) : (coordinateWord w).length=g*S := by - induction g with - | zero => simp [coordinateWord] - | succ g ih => - rw [coordinateWord_succ,List.length_append,hw,ih (fun j=>w j.succ) (fun j=>hw j.succ)] - simp [Nat.add_mul,Nat.add_comm] - -theorem coordinateWord_injective_equal {g S : ℕ} (atom : Bool→List Bool) - (hw : ∀τ,(atom τ).length=S) (ha : Function.Injective atom) : - Function.Injective (fun θ : Fin g→Bool=>coordinateWord (fun j=>atom (θ j))) := by - induction g with - | zero => intro θ σ _; exact Subsingleton.elim _ _ - | succ g ih => - intro θ σ h - change coordinateWord (fun j=>atom (θ j))=coordinateWord (fun j=>atom (σ j)) at h - rw [coordinateWord_succ,coordinateWord_succ] at h - have h0 := List.append_inj_left' h (by rw [coordinateWord_length_constant _ (fun j=>hw (θ j.succ)),coordinateWord_length_constant _ (fun j=>hw (σ j.succ))]) - have h1 := List.append_inj_right' h (by rw [coordinateWord_length_constant _ (fun j=>hw (θ j.succ)),coordinateWord_length_constant _ (fun j=>hw (σ j.succ))]) - have ht := ih h1 - funext j - exact Fin.cases (ha h0) (fun k=>congrFun ht k) j - -/-- A fixed family of all binary gadget choices, at exact requested length. - Its common-zero member is uniformly close in m-sample TV to every member. - This suffices for every fixed positive worst-case success probability. -/ -theorem ConcreteLevelPair.restored_family {r q N Δ d ω F : ℝ} {hr : r∈Set.Icc 0 1} - {i k : ℕ} (U : ConcreteLevelPair r hr N Δ d ω F i k) - (hr1 : r<1) (hq : q∈Set.Icc 0 1) (hrq : r≤q) (hk : 1≤k) - (g n : ℕ) (hN : (g:ℝ)*N≤n) : - ∃W : (Fin g→Bool)→Word n,Function.Injective W ∧ ∀θ (m : ℕ), - ((completeTraceLaw q hq (W θ)).product m).tv - ((completeTraceLaw q hq (W (fun _=>false))).product m) ≤ - Real.sqrt ((m:ℝ)*g*N^(-d))+2*m*g*U.error := by - have hlen : g*U.left.length≤n := by - exact_mod_cast (mul_le_mul_of_nonneg_left U.length_upper (Nat.cast_nonneg g)).trans hN - let atom := fun (τ : Bool)=>if τ then U.right else U.left - have hw (τ : Bool) : (atom τ).length=U.left.length := by cases τ; rfl; exact U.equalLength.symm - have ha : Function.Injective atom := by - intro τ σ hh - cases τ <;> cases σ - · rfl - · exact False.elim (U.different hh) - · exact False.elim (U.different hh.symm) - · rfl - let tail := List.replicate (n-g*U.left.length) false - let w := fun θ : Fin g→Bool=>coordinateWord (fun j=>atom (θ j))++tail - have hl (θ : Fin g→Bool) : (w θ).length=n := by - simp only [w,tail,List.length_append,List.length_replicate,coordinateWord_length_constant _ (fun j=>hw (θ j))] - omega - let W := fun θ=>wordOfLength (w θ) (hl θ) - refine ⟨W,?_,?_⟩ - · intro θ σ hh - have hh' := congrArg List.ofFn hh - simp only [W,ofFn_wordOfLength] at hh' - exact coordinateWord_injective_equal atom hw ha (List.append_cancel_right hh') - · intro θ m - let C := ((U.oracle.hellinger hk).mix hr θ (fun _ : Fin g=>false)).suffix hr tail - have hV : (∑j : Fin g,if θ j=false then (0:ℝ) else 1) ≤ g := by - calc - _ ≤ ∑_j : Fin g,(1:ℝ) := Finset.sum_le_sum (fun j _=>by split_ifs <;> norm_num) - _ = g := by simp - have HH := C.degraded_sample_tv ⟨hr.1,hr1⟩ hq hrq m n (hl θ).le (hl (fun _=>false)).le - change ((listTraceLaw q hq (w θ) n _).product m).tv ((listTraceLaw q hq (w (fun _=>false)) n _).product m) ≤ _ at HH - rw [listTraceLaw_wordOfLength q hq _ (hl θ),listTraceLaw_wordOfLength q hq _ (hl (fun _=>false))] at HH - apply HH.trans - have hN0 : 0≤N := (Nat.cast_nonneg U.left.length).trans U.length_upper - have hmul : (m:ℝ)*((∑j : Fin g,if θ j=false then (0:ℝ) else 1)*N^(-d)) ≤ m*g*N^(-d) := by - simpa only [mul_assoc] using mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_right hV (Real.rpow_nonneg hN0 (-d))) (Nat.cast_nonneg m) - have hs := Real.sqrt_le_sqrt hmul - simpa only [mul_assoc] using add_le_add hs (le_refl (2*(m:ℝ)*(g*U.error))) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -namespace FiniteLaw -variable {α β : Type*} [Fintype α] [Fintype β] - -theorem product_map_expect (P : FiniteLaw α) (f : α→β) (m : ℕ) - (F : (Fin m→β)→ℝ) : - ((P.map f).product m).expect F=(P.product m).expect (fun z=>F (f∘z)) := by - induction m with - | zero => - simp only [expect,product,Fintype.prod_empty,one_mul,Fintype.sum_unique] - congr 1 - exact Subsingleton.elim _ _ - | succ m ih => - rw [product_succ_expect,expect_map,product_succ_expect] - apply congrArg P.expect - funext a - change ((P.map f).product m).expect (fun b=>F (Fin.cons (f a) b))=_ - rw [ih] - congr 1 - funext z - congr 1 - funext j - exact Fin.cases rfl (fun _=>rfl) j - -end FiniteLaw - -theorem reconstructionSuccess_expect {n m : ℕ} (q : ℝ) (hq : q∈Set.Icc 0 1) - (A : (Fin m→Trace)→Word n→ℝ) (x : Word n) : - reconstructionSuccess q A x=((completeTraceLaw q hq x).product m).expect - (fun z=>A (fun j=>(z j).val) x) := by - rw [completeTraceLaw_mask,FiniteLaw.product_map_expect] - rfl - -theorem IsEstimator.le_one {n m : ℕ} {A : (Fin m→Trace)→Word n→ℝ} - (hA : IsEstimator A) (z : Fin m→Trace) (x : Word n) : A z x≤1 := by - rw [←hA.2 z] - exact Finset.single_le_sum (fun y _=>hA.1 z y) (Finset.mem_univ x) - -/-- Many-hypothesis testing using a common reference law. The decoder remains - unrestricted, randomized and sees only complete traces. -/ -theorem family_testing_bound {n m g : ℕ} {q s ε : ℝ} (hq : q∈Set.Icc 0 1) - (W : (Fin g→Bool)→Word n) (hW : Function.Injective W) - (htv : ∀θ,((completeTraceLaw q hq (W θ)).product m).tv - ((completeTraceLaw q hq (W (fun _=>false))).product m)≤ε) - (hm : SufficientBudget n q s m) : s≤1/(2:ℝ)^g+ε := by - obtain ⟨A,hA,hs⟩ := hm - let P := (completeTraceLaw q hq (W (fun _=>false))).product m - have hθ (θ : Fin g→Bool) : s≤P.expect (fun z=>A (fun j=>(z j).val) (W θ))+ε := by - have hb := FiniteLaw.expectation_diff_le_tv - ((completeTraceLaw q hq (W θ)).product m) P - (fun z=>A (fun j=>(z j).val) (W θ)) - (fun z=>⟨hA.1 _ _,hA.le_one _ _⟩) - have hh := hs (W θ) - rw [reconstructionSuccess_expect q hq] at hh - change ((completeTraceLaw q hq (W θ)).product m).expect (fun z=>A (fun j=>(z j).val) (W θ)) - P.expect _ ≤ _ at hb - linarith [htv θ] - have hsum : (∑θ : Fin g→Bool,P.expect (fun z=>A (fun j=>(z j).val) (W θ)))≤1 := by - unfold FiniteLaw.expect - rw [Finset.sum_comm] - calc - _ ≤ ∑z,P.mass z*1 := by - apply Finset.sum_le_sum - intro z _ - rw [←Finset.mul_sum] - apply mul_le_mul_of_nonneg_left _ (P.nonneg z) - calc - _ = ∑x ∈ Finset.univ.image W,A (fun j=>(z j).val) x := by - rw [Finset.sum_image (fun a _ b _ hab=>hW hab)] - _ ≤ ∑x : Word n,A (fun j=>(z j).val) x := Finset.sum_le_sum_of_subset_of_nonneg - (Finset.subset_univ _) (fun x _ _=>hA.1 _ _) - _ = 1 := hA.2 _ - _ = 1 := by simp [P.total] - have hh := Finset.sum_le_sum (s:=Finset.univ) (fun θ _=>hθ θ) - simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ, - Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,nsmul_eq_mul,Nat.cast_pow,Nat.cast_ofNat] at hh - have hp : 0<(2:ℝ)^g := by positivity - have he : (2:ℝ)^g*(1/(2:ℝ)^g)=1 := by field_simp - nlinarith only [hh,hsum,he,hp] - -end TraceReconstruction - -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Restoration + +namespace OAI + +/-! +# Testing + +Multi-gadget family restoration and common-reference many-hypothesis statistics for every positive success level. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +theorem hellingerSq_prod_same_right (P Q : FiniteLaw α) (R : FiniteLaw β) : + (P.prod R).hellingerSq (Q.prod R)=P.hellingerSq Q := by + unfold hellingerSq prod + rw [Fintype.sum_prod_type] + have he (a : α) (b : β) : + (Real.sqrt (P.mass a*R.mass b)-Real.sqrt (Q.mass a*R.mass b))^2= + (Real.sqrt (P.mass a)-Real.sqrt (Q.mass a))^2*R.mass b := by + rw [Real.sqrt_mul (P.nonneg a),Real.sqrt_mul (Q.nonneg a),←sub_mul,mul_pow, + Real.sq_sqrt (R.nonneg b)] + simp_rw [he,←Finset.mul_sum,R.total,mul_one] + +end FiniteLaw + +def HellingerTracePair.suffix {q E V : ℝ} {x y : List Bool} + (C : HellingerTracePair q x y E V) (hq : q∈Set.Icc 0 1) (w : List Bool) : + HellingerTracePair q (x++w) (y++w) E V := by + let := C.finiteOutcome + let R := listTraceLaw q hq w w.length le_rfl + exact { + Outcome := C.Outcome × BoundedTrace w.length + finiteOutcome := inferInstance + first := C.first.prod R + second := C.second.prod R + decode := fun z=>C.decode z.1++z.2.val + first_simulation := by + simpa only [add_zero] using C.first_simulation.append hq + (listTraceLaw_simulates q hq w w.length le_rfl).approximate + second_simulation := by + simpa only [add_zero] using C.second_simulation.append hq + (listTraceLaw_simulates q hq w w.length le_rfl).approximate + bound := by rw [FiniteLaw.hellingerSq_prod_same_right]; exact C.bound } + +theorem coordinateWord_length_constant {g S : ℕ} (w : Fin g→List Bool) + (hw : ∀j,(w j).length=S) : (coordinateWord w).length=g*S := by + induction g with + | zero => simp [coordinateWord] + | succ g ih => + rw [coordinateWord_succ,List.length_append,hw,ih (fun j=>w j.succ) (fun j=>hw j.succ)] + simp [Nat.add_mul,Nat.add_comm] + +theorem coordinateWord_injective_equal {g S : ℕ} (atom : Bool→List Bool) + (hw : ∀τ,(atom τ).length=S) (ha : Function.Injective atom) : + Function.Injective (fun θ : Fin g→Bool=>coordinateWord (fun j=>atom (θ j))) := by + induction g with + | zero => intro θ σ _; exact Subsingleton.elim _ _ + | succ g ih => + intro θ σ h + change coordinateWord (fun j=>atom (θ j))=coordinateWord (fun j=>atom (σ j)) at h + rw [coordinateWord_succ,coordinateWord_succ] at h + have h0 := List.append_inj_left' h (by rw [coordinateWord_length_constant _ (fun j=>hw (θ j.succ)),coordinateWord_length_constant _ (fun j=>hw (σ j.succ))]) + have h1 := List.append_inj_right' h (by rw [coordinateWord_length_constant _ (fun j=>hw (θ j.succ)),coordinateWord_length_constant _ (fun j=>hw (σ j.succ))]) + have ht := ih h1 + funext j + exact Fin.cases (ha h0) (fun k=>congrFun ht k) j + +/-- A fixed family of all binary gadget choices, at exact requested length. + Its common-zero member is uniformly close in m-sample TV to every member. + This suffices for every fixed positive worst-case success probability. -/ +theorem ConcreteLevelPair.restored_family {r q N Δ d ω F : ℝ} {hr : r∈Set.Icc 0 1} + {i k : ℕ} (U : ConcreteLevelPair r hr N Δ d ω F i k) + (hr1 : r<1) (hq : q∈Set.Icc 0 1) (hrq : r≤q) (hk : 1≤k) + (g n : ℕ) (hN : (g:ℝ)*N≤n) : + ∃W : (Fin g→Bool)→Word n,Function.Injective W ∧ ∀θ (m : ℕ), + ((completeTraceLaw q hq (W θ)).product m).tv + ((completeTraceLaw q hq (W (fun _=>false))).product m) ≤ + Real.sqrt ((m:ℝ)*g*N^(-d))+2*m*g*U.error := by + have hlen : g*U.left.length≤n := by + exact_mod_cast (mul_le_mul_of_nonneg_left U.length_upper (Nat.cast_nonneg g)).trans hN + let atom := fun (τ : Bool)=>if τ then U.right else U.left + have hw (τ : Bool) : (atom τ).length=U.left.length := by cases τ; rfl; exact U.equalLength.symm + have ha : Function.Injective atom := by + intro τ σ hh + cases τ <;> cases σ + · rfl + · exact False.elim (U.different hh) + · exact False.elim (U.different hh.symm) + · rfl + let tail := List.replicate (n-g*U.left.length) false + let w := fun θ : Fin g→Bool=>coordinateWord (fun j=>atom (θ j))++tail + have hl (θ : Fin g→Bool) : (w θ).length=n := by + simp only [w,tail,List.length_append,List.length_replicate,coordinateWord_length_constant _ (fun j=>hw (θ j))] + omega + let W := fun θ=>wordOfLength (w θ) (hl θ) + refine ⟨W,?_,?_⟩ + · intro θ σ hh + have hh' := congrArg List.ofFn hh + simp only [W,ofFn_wordOfLength] at hh' + exact coordinateWord_injective_equal atom hw ha (List.append_cancel_right hh') + · intro θ m + let C := ((U.oracle.hellinger hk).mix hr θ (fun _ : Fin g=>false)).suffix hr tail + have hV : (∑j : Fin g,if θ j=false then (0:ℝ) else 1) ≤ g := by + calc + _ ≤ ∑_j : Fin g,(1:ℝ) := Finset.sum_le_sum (fun j _=>by split_ifs <;> norm_num) + _ = g := by simp + have HH := C.degraded_sample_tv ⟨hr.1,hr1⟩ hq hrq m n (hl θ).le (hl (fun _=>false)).le + change ((listTraceLaw q hq (w θ) n _).product m).tv ((listTraceLaw q hq (w (fun _=>false)) n _).product m) ≤ _ at HH + rw [listTraceLaw_wordOfLength q hq _ (hl θ),listTraceLaw_wordOfLength q hq _ (hl (fun _=>false))] at HH + apply HH.trans + have hN0 : 0≤N := (Nat.cast_nonneg U.left.length).trans U.length_upper + have hmul : (m:ℝ)*((∑j : Fin g,if θ j=false then (0:ℝ) else 1)*N^(-d)) ≤ m*g*N^(-d) := by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right hV (Real.rpow_nonneg hN0 (-d))) (Nat.cast_nonneg m) + have hs := Real.sqrt_le_sqrt hmul + simpa only [mul_assoc] using add_le_add hs (le_refl (2*(m:ℝ)*(g*U.error))) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +namespace FiniteLaw +variable {α β : Type*} [Fintype α] [Fintype β] + +theorem product_map_expect (P : FiniteLaw α) (f : α→β) (m : ℕ) + (F : (Fin m→β)→ℝ) : + ((P.map f).product m).expect F=(P.product m).expect (fun z=>F (f∘z)) := by + induction m with + | zero => + simp only [expect,product,Fintype.prod_empty,one_mul,Fintype.sum_unique] + congr 1 + exact Subsingleton.elim _ _ + | succ m ih => + rw [product_succ_expect,expect_map,product_succ_expect] + apply congrArg P.expect + funext a + change ((P.map f).product m).expect (fun b=>F (Fin.cons (f a) b))=_ + rw [ih] + congr 1 + funext z + congr 1 + funext j + exact Fin.cases rfl (fun _=>rfl) j + +end FiniteLaw + +theorem reconstructionSuccess_expect {n m : ℕ} (q : ℝ) (hq : q∈Set.Icc 0 1) + (A : (Fin m→Trace)→Word n→ℝ) (x : Word n) : + reconstructionSuccess q A x=((completeTraceLaw q hq x).product m).expect + (fun z=>A (fun j=>(z j).val) x) := by + rw [completeTraceLaw_mask,FiniteLaw.product_map_expect] + rfl + +theorem IsEstimator.le_one {n m : ℕ} {A : (Fin m→Trace)→Word n→ℝ} + (hA : IsEstimator A) (z : Fin m→Trace) (x : Word n) : A z x≤1 := by + rw [←hA.2 z] + exact Finset.single_le_sum (fun y _=>hA.1 z y) (Finset.mem_univ x) + +/-- Many-hypothesis testing using a common reference law. The decoder remains + unrestricted, randomized and sees only complete traces. -/ +theorem family_testing_bound {n m g : ℕ} {q s ε : ℝ} (hq : q∈Set.Icc 0 1) + (W : (Fin g→Bool)→Word n) (hW : Function.Injective W) + (htv : ∀θ,((completeTraceLaw q hq (W θ)).product m).tv + ((completeTraceLaw q hq (W (fun _=>false))).product m)≤ε) + (hm : SufficientBudget n q s m) : s≤1/(2:ℝ)^g+ε := by + obtain ⟨A,hA,hs⟩ := hm + let P := (completeTraceLaw q hq (W (fun _=>false))).product m + have hθ (θ : Fin g→Bool) : s≤P.expect (fun z=>A (fun j=>(z j).val) (W θ))+ε := by + have hb := FiniteLaw.expectation_diff_le_tv + ((completeTraceLaw q hq (W θ)).product m) P + (fun z=>A (fun j=>(z j).val) (W θ)) + (fun z=>⟨hA.1 _ _,hA.le_one _ _⟩) + have hh := hs (W θ) + rw [reconstructionSuccess_expect q hq] at hh + change ((completeTraceLaw q hq (W θ)).product m).expect (fun z=>A (fun j=>(z j).val) (W θ)) - P.expect _ ≤ _ at hb + linarith [htv θ] + have hsum : (∑θ : Fin g→Bool,P.expect (fun z=>A (fun j=>(z j).val) (W θ)))≤1 := by + unfold FiniteLaw.expect + rw [Finset.sum_comm] + calc + _ ≤ ∑z,P.mass z*1 := by + apply Finset.sum_le_sum + intro z _ + rw [←Finset.mul_sum] + apply mul_le_mul_of_nonneg_left _ (P.nonneg z) + calc + _ = ∑x ∈ Finset.univ.image W,A (fun j=>(z j).val) x := by + rw [Finset.sum_image (fun a _ b _ hab=>hW hab)] + _ ≤ ∑x : Word n,A (fun j=>(z j).val) x := Finset.sum_le_sum_of_subset_of_nonneg + (Finset.subset_univ _) (fun x _ _=>hA.1 _ _) + _ = 1 := hA.2 _ + _ = 1 := by simp [P.total] + have hh := Finset.sum_le_sum (s:=Finset.univ) (fun θ _=>hθ θ) + simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ, + Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,nsmul_eq_mul,Nat.cast_pow,Nat.cast_ofNat] at hh + have hp : 0<(2:ℝ)^g := by positivity + have he : (2:ℝ)^g*(1/(2:ℝ)^g)=1 := by field_simp + nlinarith only [hh,hsum,he,hp] + +end TraceReconstruction + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Cayley/Folner.lean b/lean/OAI/Probability/UnimodularPercolation/Cayley/Folner.lean index 90467876e261471505e9c15308e2c446e00f78d6..4879db9019a96ce72d2e9c28cffb0d5811f64daf 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Cayley/Folner.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Cayley/Folner.lean @@ -1,133 +1,133 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Cayley.Geometry - -namespace OAI - -/-! The group Følner criterion and nonamenable Cayley graphs. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u -section GroupGeometry -variable {Λ : Type u} [Group Λ] -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def rightTranslate (A : Finset Λ) (g : Λ) : Finset Λ := - A.image (fun x => x * g) - -@[simp] lemma card_rightTranslate (A : Finset Λ) (g : Λ) : - (rightTranslate A g).card = A.card := - Finset.card_image_of_injective _ (Equiv.mulRight g).injective - -@[simp] lemma rightTranslate_one (A : Finset Λ) : rightTranslate A 1 = A := by - simp [rightTranslate] - -lemma rightTranslate_mul (A : Finset Λ) (g h : Λ) : - rightTranslate (rightTranslate A g) h = rightTranslate A (g * h) := by - simp only [rightTranslate, Finset.image_image, Function.comp_def, mul_assoc] - -lemma rightTranslate_sdiff (A B : Finset Λ) (g : Λ) : - rightTranslate (A \ B) g = rightTranslate A g \ rightTranslate B g := - Finset.image_sdiff _ _ (Equiv.mulRight g).injective - -noncomputable def rightDefect (A : Finset Λ) (g : Λ) : ℕ := - (rightTranslate A g \ A).card - -omit [Group Λ] in -lemma card_sdiff_triangle (A B C : Finset Λ) : - (A \ C).card ≤ (A \ B).card + (B \ C).card := by - apply (Finset.card_le_card (show A \ C ⊆ (A \ B) ∪ (B \ C) from ?_)).trans - (Finset.card_union_le _ _) - intro x hx - simp only [Finset.mem_sdiff, Finset.mem_union] at hx ⊢ - by_cases hb : x ∈ B <;> tauto - -lemma rightDefect_mul_le (A : Finset Λ) (g h : Λ) : - rightDefect A (g * h) ≤ rightDefect A g + rightDefect A h := by - calc - rightDefect A (g * h) ≤ - (rightTranslate A (g * h) \ rightTranslate A h).card + rightDefect A h := - card_sdiff_triangle _ _ _ - _ = rightDefect A g + rightDefect A h := by - rw [← rightTranslate_mul, ← rightTranslate_sdiff, card_rightTranslate] - rfl - -@[simp] lemma rightDefect_inv (A : Finset Λ) (g : Λ) : - rightDefect A g⁻¹ = rightDefect A g := by - calc - rightDefect A g⁻¹ = (rightTranslate (rightTranslate A g⁻¹ \ A) g).card := - (card_rightTranslate _ _).symm - _ = (A \ rightTranslate A g).card := by - rw [rightTranslate_sdiff, rightTranslate_mul, inv_mul_cancel, rightTranslate_one] - _ = rightDefect A g := Finset.card_sdiff_comm (card_rightTranslate A g).symm - -lemma rightDefect_le_boundary (S : Finset Λ) - (hgen : Subgroup.closure (S : Set Λ) = ⊤) (g : Λ) : - ∃ n : ℕ, ∀ A : Finset Λ, - rightDefect A g ≤ n * (vertexBoundary (cayleyGraph S) A).ncard := by - have hg : g ∈ Subgroup.closure (S : Set Λ) := by rw [hgen]; trivial - induction hg using Subgroup.closure_induction with - | mem g hg => - refine ⟨1, ?_⟩ - intro A - rw [one_mul] - change (rightTranslate A g \ A).card ≤ _ - rw [← Set.ncard_coe_finset] - apply Set.ncard_le_ncard ?_ (finite_vertexBoundary _ (cayley_locallyFinite S) A) - intro y hy - obtain ⟨hy, hnot⟩ := Finset.mem_sdiff.mp hy - obtain ⟨x, hx, rfl⟩ := Finset.mem_image.mp hy - exact ⟨hnot, x, hx, cayley_adj_of_mem S x g hg⟩ - | one => - exact ⟨0, fun A => by simp [rightDefect]⟩ - | mul g h hg hh ig ih => - obtain ⟨n, hn⟩ := ig - obtain ⟨m, hm⟩ := ih - refine ⟨n + m, fun A => ?_⟩ - exact (rightDefect_mul_le A g h).trans (by simpa [add_mul] using Nat.add_le_add (hn A) (hm A)) - | inv g hg ig => - obtain ⟨n, hn⟩ := ig - exact ⟨n, fun A => by simpa only [rightDefect_inv] using hn A⟩ - -lemma cayley_hV_pos (S : Finset Λ) (hgen : Subgroup.closure (S : Set Λ) = ⊤) - (hna : ¬ AmenableGroup Λ) : 0 < hV (cayleyGraph S) := by - by_contra hh - apply hna - intro K ε hε - choose n hn using rightDefect_le_boundary S hgen - let N : ℕ := (∑ g ∈ K, n g) + 1 - have hN : (0 : ℝ) < N := by dsimp [N]; positivity - have hng (g : Λ) (hg : g ∈ K) : n g ≤ N := - (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hg).trans (Nat.le_add_right _ _) - let B : Set ℝ := {r | ∃ A : Finset Λ, A.Nonempty ∧ - r = (vertexBoundary (cayleyGraph S) A).ncard / (A.card : ℝ)} - have hb : BddBelow B := by - refine ⟨0, ?_⟩ - rintro r ⟨A, hA, rfl⟩ - positivity - have hB : B.Nonempty := - ⟨_, {1}, Finset.singleton_nonempty 1, rfl⟩ - have hlt : sInf B < ε / N := - (le_of_not_gt hh).trans_lt (div_pos hε hN) - obtain ⟨r, ⟨A, hA, rfl⟩, hr⟩ := (csInf_lt_iff hb hB).mp hlt - have hAc : (0 : ℝ) < A.card := Nat.cast_pos.mpr hA.card_pos - have hbound : (N : ℝ) * (vertexBoundary (cayleyGraph S) A).ncard < ε * A.card := by - have hh := (div_lt_iff₀ hAc).mp hr - have hh' := mul_lt_mul_of_pos_left hh hN - have heq : (N : ℝ) * (ε / N * A.card) = ε * A.card := by - field_simp - rwa [heq] at hh' - refine ⟨A, hA, ?_⟩ - intro g hg - have hd : (rightDefect A g : ℝ) ≤ (N : ℝ) * - (vertexBoundary (cayleyGraph S) A).ncard := by - exact_mod_cast (hn g A).trans (Nat.mul_le_mul_right _ (hng g hg)) - exact hd.trans_lt hbound - -end GroupGeometry -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Cayley.Geometry + +namespace OAI + +/-! The group Følner criterion and nonamenable Cayley graphs. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u +section GroupGeometry +variable {Λ : Type u} [Group Λ] +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def rightTranslate (A : Finset Λ) (g : Λ) : Finset Λ := + A.image (fun x => x * g) + +@[simp] lemma card_rightTranslate (A : Finset Λ) (g : Λ) : + (rightTranslate A g).card = A.card := + Finset.card_image_of_injective _ (Equiv.mulRight g).injective + +@[simp] lemma rightTranslate_one (A : Finset Λ) : rightTranslate A 1 = A := by + simp [rightTranslate] + +lemma rightTranslate_mul (A : Finset Λ) (g h : Λ) : + rightTranslate (rightTranslate A g) h = rightTranslate A (g * h) := by + simp only [rightTranslate, Finset.image_image, Function.comp_def, mul_assoc] + +lemma rightTranslate_sdiff (A B : Finset Λ) (g : Λ) : + rightTranslate (A \ B) g = rightTranslate A g \ rightTranslate B g := + Finset.image_sdiff _ _ (Equiv.mulRight g).injective + +noncomputable def rightDefect (A : Finset Λ) (g : Λ) : ℕ := + (rightTranslate A g \ A).card + +omit [Group Λ] in +lemma card_sdiff_triangle (A B C : Finset Λ) : + (A \ C).card ≤ (A \ B).card + (B \ C).card := by + apply (Finset.card_le_card (show A \ C ⊆ (A \ B) ∪ (B \ C) from ?_)).trans + (Finset.card_union_le _ _) + intro x hx + simp only [Finset.mem_sdiff, Finset.mem_union] at hx ⊢ + by_cases hb : x ∈ B <;> tauto + +lemma rightDefect_mul_le (A : Finset Λ) (g h : Λ) : + rightDefect A (g * h) ≤ rightDefect A g + rightDefect A h := by + calc + rightDefect A (g * h) ≤ + (rightTranslate A (g * h) \ rightTranslate A h).card + rightDefect A h := + card_sdiff_triangle _ _ _ + _ = rightDefect A g + rightDefect A h := by + rw [← rightTranslate_mul, ← rightTranslate_sdiff, card_rightTranslate] + rfl + +@[simp] lemma rightDefect_inv (A : Finset Λ) (g : Λ) : + rightDefect A g⁻¹ = rightDefect A g := by + calc + rightDefect A g⁻¹ = (rightTranslate (rightTranslate A g⁻¹ \ A) g).card := + (card_rightTranslate _ _).symm + _ = (A \ rightTranslate A g).card := by + rw [rightTranslate_sdiff, rightTranslate_mul, inv_mul_cancel, rightTranslate_one] + _ = rightDefect A g := Finset.card_sdiff_comm (card_rightTranslate A g).symm + +lemma rightDefect_le_boundary (S : Finset Λ) + (hgen : Subgroup.closure (S : Set Λ) = ⊤) (g : Λ) : + ∃ n : ℕ, ∀ A : Finset Λ, + rightDefect A g ≤ n * (vertexBoundary (cayleyGraph S) A).ncard := by + have hg : g ∈ Subgroup.closure (S : Set Λ) := by rw [hgen]; trivial + induction hg using Subgroup.closure_induction with + | mem g hg => + refine ⟨1, ?_⟩ + intro A + rw [one_mul] + change (rightTranslate A g \ A).card ≤ _ + rw [← Set.ncard_coe_finset] + apply Set.ncard_le_ncard ?_ (finite_vertexBoundary _ (cayley_locallyFinite S) A) + intro y hy + obtain ⟨hy, hnot⟩ := Finset.mem_sdiff.mp hy + obtain ⟨x, hx, rfl⟩ := Finset.mem_image.mp hy + exact ⟨hnot, x, hx, cayley_adj_of_mem S x g hg⟩ + | one => + exact ⟨0, fun A => by simp [rightDefect]⟩ + | mul g h hg hh ig ih => + obtain ⟨n, hn⟩ := ig + obtain ⟨m, hm⟩ := ih + refine ⟨n + m, fun A => ?_⟩ + exact (rightDefect_mul_le A g h).trans (by simpa [add_mul] using Nat.add_le_add (hn A) (hm A)) + | inv g hg ig => + obtain ⟨n, hn⟩ := ig + exact ⟨n, fun A => by simpa only [rightDefect_inv] using hn A⟩ + +lemma cayley_hV_pos (S : Finset Λ) (hgen : Subgroup.closure (S : Set Λ) = ⊤) + (hna : ¬ AmenableGroup Λ) : 0 < hV (cayleyGraph S) := by + by_contra hh + apply hna + intro K ε hε + choose n hn using rightDefect_le_boundary S hgen + let N : ℕ := (∑ g ∈ K, n g) + 1 + have hN : (0 : ℝ) < N := by dsimp [N]; positivity + have hng (g : Λ) (hg : g ∈ K) : n g ≤ N := + (Finset.single_le_sum (fun _ _ => Nat.zero_le _) hg).trans (Nat.le_add_right _ _) + let B : Set ℝ := {r | ∃ A : Finset Λ, A.Nonempty ∧ + r = (vertexBoundary (cayleyGraph S) A).ncard / (A.card : ℝ)} + have hb : BddBelow B := by + refine ⟨0, ?_⟩ + rintro r ⟨A, hA, rfl⟩ + positivity + have hB : B.Nonempty := + ⟨_, {1}, Finset.singleton_nonempty 1, rfl⟩ + have hlt : sInf B < ε / N := + (le_of_not_gt hh).trans_lt (div_pos hε hN) + obtain ⟨r, ⟨A, hA, rfl⟩, hr⟩ := (csInf_lt_iff hb hB).mp hlt + have hAc : (0 : ℝ) < A.card := Nat.cast_pos.mpr hA.card_pos + have hbound : (N : ℝ) * (vertexBoundary (cayleyGraph S) A).ncard < ε * A.card := by + have hh := (div_lt_iff₀ hAc).mp hr + have hh' := mul_lt_mul_of_pos_left hh hN + have heq : (N : ℝ) * (ε / N * A.card) = ε * A.card := by + field_simp + rwa [heq] at hh' + refine ⟨A, hA, ?_⟩ + intro g hg + have hd : (rightDefect A g : ℝ) ≤ (N : ℝ) * + (vertexBoundary (cayleyGraph S) A).ncard := by + exact_mod_cast (hn g A).trans (Nat.mul_le_mul_right _ (hng g hg)) + exact hd.trans_lt hbound + +end GroupGeometry +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Cayley/Geometry.lean b/lean/OAI/Probability/UnimodularPercolation/Cayley/Geometry.lean index dad403e96aaef27ac9f5a0de541fa6c0a306e93f..34bc8b091776c9339a99d9caadcd5ed2babf3e23 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Cayley/Geometry.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Cayley/Geometry.lean @@ -1,156 +1,156 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Cayley graphs, translation symmetries and root transport. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v - -noncomputable def AmenableGroup (Λ : Type u) [Group Λ] : Prop := by - classical - exact ∀ K : Finset Λ, ∀ ε : ℝ, 0 < ε → ∃ A : Finset Λ, A.Nonempty ∧ - ∀ g ∈ K, (((A.image (fun x => x * g)) \ A).card : ℝ) < ε * A.card - -def CayleyEdge {Λ : Type u} [Group Λ] (S : Finset Λ) := - {e : Sym2 Λ // ∃ x : Λ, ∃ s ∈ S, e = s(x, x * s)} - -def cayleyGraph {Λ : Type u} [Group Λ] (S : Finset Λ) : - BondGraph Λ (CayleyEdge S) := Subtype.val - -section GroupGeometry -variable {Λ : Type u} [Group Λ] -attribute [local instance] Classical.propDecidable Classical.decEq - -lemma amenableGroup_of_finite [Finite Λ] : AmenableGroup Λ := by - classical - let := Fintype.ofFinite Λ - intro K ε hε - refine ⟨Finset.univ, Finset.univ_nonempty, ?_⟩ - intro g hg - have he : (Finset.univ.image (fun x : Λ => x * g)) \ Finset.univ = ∅ := - Finset.sdiff_eq_empty_iff_subset.mpr (Finset.subset_univ _) - rw [he, Finset.card_empty, Nat.cast_zero, Finset.card_univ] - exact mul_pos hε (Nat.cast_pos.mpr (Fintype.card_pos)) - -lemma infinite_of_nonamenable (h : ¬ AmenableGroup Λ) : Infinite Λ := by - by_contra hi - let : Finite Λ := not_infinite_iff_finite.mp hi - exact h amenableGroup_of_finite - -lemma cayleyGraph_injective (S : Finset Λ) : Function.Injective (cayleyGraph S) := - Subtype.val_injective - -lemma cayley_adj_of_mem (S : Finset Λ) (x s : Λ) (hs : s ∈ S) : - Adj (cayleyGraph S) x (x * s) := - ⟨⟨s(x, x * s), x, s, hs, rfl⟩, rfl⟩ - -lemma cayley_adj_iff (S : Finset Λ) (hS : ∀ s ∈ S, s⁻¹ ∈ S) (x y : Λ) : - Adj (cayleyGraph S) x y ↔ ∃ s ∈ S, x * s = y := by - constructor - · rintro ⟨⟨e, z, s, hs, rfl⟩, he⟩ - change s(z, z * s) = s(x, y) at he - rcases Sym2.eq_iff.mp he with ⟨hz, hy⟩ | ⟨hz, hx⟩ - · - exact ⟨s, hs, hz ▸ hy⟩ - · refine ⟨s⁻¹, hS s hs, ?_⟩ - rw [← hx, mul_inv_cancel_right, hz] - · rintro ⟨s, hs, rfl⟩ - exact cayley_adj_of_mem S x s hs - -lemma cayley_loopless (S : Finset Λ) (hS : ∀ s ∈ S, s⁻¹ ∈ S) (h1 : 1 ∉ S) - (x : Λ) : ¬ Adj (cayleyGraph S) x x := by - rintro hx - obtain ⟨s, hs, he⟩ := (cayley_adj_iff S hS x x).mp hx - have : s = 1 := mul_left_cancel (by simpa using he : x * s = x * 1) - exact h1 (this ▸ hs) - -lemma cayley_locallyFinite (S : Finset Λ) : LocallyFinite (cayleyGraph S) := by - intro x - let F : Set (Sym2 Λ) := - ((fun s => s(x, x * s)) '' (S : Set Λ)) ∪ - ((fun s => s(x * s⁻¹, x)) '' (S : Set Λ)) - have hF : F.Finite := - (S.finite_toSet.image _).union (S.finite_toSet.image _) - apply (hF.preimage (cayleyGraph_injective S).injOn).subset - rintro ⟨e, z, s, hs, rfl⟩ hx - change x ∈ s(z, z * s) at hx - rcases Sym2.mem_iff.mp hx with hx | hx - · left - exact ⟨s, hs, by simp [hx, cayleyGraph]⟩ - · right - refine ⟨s, hs, ?_⟩ - simp [hx, cayleyGraph] - -noncomputable def cayleyEdgeTranslation (S : Finset Λ) (a : Λ) : CayleyEdge S ≃ CayleyEdge S where - toFun e := ⟨e.val.map (fun x => a * x), by - obtain ⟨e, x, s, hs, rfl⟩ := e - exact ⟨a * x, s, hs, by simp [mul_assoc]⟩⟩ - invFun e := ⟨e.val.map (fun x => a⁻¹ * x), by - obtain ⟨e, x, s, hs, rfl⟩ := e - exact ⟨a⁻¹ * x, s, hs, by simp [mul_assoc]⟩⟩ - left_inv e := by - apply Subtype.ext - simp [Sym2.map_map] - right_inv e := by - apply Subtype.ext - simp [Sym2.map_map] - -lemma cayley_translation_isAut (S : Finset Λ) (a : Λ) : - IsAut (cayleyGraph S) (Equiv.mulLeft a) (cayleyEdgeTranslation S a) := by - intro e - rfl - -lemma cayley_translation_mem (S : Finset Λ) (a : Λ) : - Equiv.mulLeft a ∈ vertexAut (cayleyGraph S) := - ⟨cayleyEdgeTranslation S a, cayley_translation_isAut S a⟩ - -lemma cayley_quasiTransitive (S : Finset Λ) : QuasiTransitive (cayleyGraph S) := by - refine ⟨{1}, ?_⟩ - intro x - exact ⟨1, Finset.mem_singleton_self _, Equiv.mulLeft x, cayleyEdgeTranslation S x, - cayley_translation_isAut S x, mul_one x⟩ - -lemma cayley_connected (S : Finset Λ) (hgen : Subgroup.closure (S : Set Λ) = ⊤) : - Connected (cayleyGraph S) := by - have paths (g : Λ) : ∀ x : Λ, - Relation.ReflTransGen (Adj (cayleyGraph S)) x (x * g) := by - have hg : g ∈ Subgroup.closure (S : Set Λ) := by rw [hgen]; trivial - induction hg using Subgroup.closure_induction with - | mem g hg => exact fun x => .single (cayley_adj_of_mem S x g hg) - | one => intro x; simpa using (Relation.ReflTransGen.refl (a := x)) - | mul a b ha hb ia ib => - intro x - simpa [mul_assoc] using (ia x).trans (ib (x * a)) - | inv a ha ia => - intro x - have h := ia (x * a⁻¹) - rw [inv_mul_cancel_right] at h - let : Std.Symm (Adj (cayleyGraph S)) := ⟨fun _ _ => adj_symm (cayleyGraph S)⟩ - exact symm h - intro x y - simpa using paths (x⁻¹ * y) x - -lemma cayley_rootTransport (S : Finset Λ) : - RootTransport (fun _ : Unit => (1 : Λ)) (fun _ => (1 : ℝ)) - (vertexAut (cayleyGraph S)) := by - intro m hm hr hc - simp only [Finset.univ_unique, Finset.sum_singleton, Complex.ofReal_one, one_mul] - calc - (∑' y, m 1 y) = ∑' y, m y⁻¹ 1 := by - apply tsum_congr - intro y - simpa using (hm (Equiv.mulLeft y⁻¹) (cayley_translation_mem S y⁻¹) 1 y).symm - _ = ∑' x, m x 1 := (Equiv.inv Λ).tsum_eq (fun x => m x 1) - -end GroupGeometry -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Cayley graphs, translation symmetries and root transport. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v + +noncomputable def AmenableGroup (Λ : Type u) [Group Λ] : Prop := by + classical + exact ∀ K : Finset Λ, ∀ ε : ℝ, 0 < ε → ∃ A : Finset Λ, A.Nonempty ∧ + ∀ g ∈ K, (((A.image (fun x => x * g)) \ A).card : ℝ) < ε * A.card + +def CayleyEdge {Λ : Type u} [Group Λ] (S : Finset Λ) := + {e : Sym2 Λ // ∃ x : Λ, ∃ s ∈ S, e = s(x, x * s)} + +def cayleyGraph {Λ : Type u} [Group Λ] (S : Finset Λ) : + BondGraph Λ (CayleyEdge S) := Subtype.val + +section GroupGeometry +variable {Λ : Type u} [Group Λ] +attribute [local instance] Classical.propDecidable Classical.decEq + +lemma amenableGroup_of_finite [Finite Λ] : AmenableGroup Λ := by + classical + let := Fintype.ofFinite Λ + intro K ε hε + refine ⟨Finset.univ, Finset.univ_nonempty, ?_⟩ + intro g hg + have he : (Finset.univ.image (fun x : Λ => x * g)) \ Finset.univ = ∅ := + Finset.sdiff_eq_empty_iff_subset.mpr (Finset.subset_univ _) + rw [he, Finset.card_empty, Nat.cast_zero, Finset.card_univ] + exact mul_pos hε (Nat.cast_pos.mpr (Fintype.card_pos)) + +lemma infinite_of_nonamenable (h : ¬ AmenableGroup Λ) : Infinite Λ := by + by_contra hi + let : Finite Λ := not_infinite_iff_finite.mp hi + exact h amenableGroup_of_finite + +lemma cayleyGraph_injective (S : Finset Λ) : Function.Injective (cayleyGraph S) := + Subtype.val_injective + +lemma cayley_adj_of_mem (S : Finset Λ) (x s : Λ) (hs : s ∈ S) : + Adj (cayleyGraph S) x (x * s) := + ⟨⟨s(x, x * s), x, s, hs, rfl⟩, rfl⟩ + +lemma cayley_adj_iff (S : Finset Λ) (hS : ∀ s ∈ S, s⁻¹ ∈ S) (x y : Λ) : + Adj (cayleyGraph S) x y ↔ ∃ s ∈ S, x * s = y := by + constructor + · rintro ⟨⟨e, z, s, hs, rfl⟩, he⟩ + change s(z, z * s) = s(x, y) at he + rcases Sym2.eq_iff.mp he with ⟨hz, hy⟩ | ⟨hz, hx⟩ + · + exact ⟨s, hs, hz ▸ hy⟩ + · refine ⟨s⁻¹, hS s hs, ?_⟩ + rw [← hx, mul_inv_cancel_right, hz] + · rintro ⟨s, hs, rfl⟩ + exact cayley_adj_of_mem S x s hs + +lemma cayley_loopless (S : Finset Λ) (hS : ∀ s ∈ S, s⁻¹ ∈ S) (h1 : 1 ∉ S) + (x : Λ) : ¬ Adj (cayleyGraph S) x x := by + rintro hx + obtain ⟨s, hs, he⟩ := (cayley_adj_iff S hS x x).mp hx + have : s = 1 := mul_left_cancel (by simpa using he : x * s = x * 1) + exact h1 (this ▸ hs) + +lemma cayley_locallyFinite (S : Finset Λ) : LocallyFinite (cayleyGraph S) := by + intro x + let F : Set (Sym2 Λ) := + ((fun s => s(x, x * s)) '' (S : Set Λ)) ∪ + ((fun s => s(x * s⁻¹, x)) '' (S : Set Λ)) + have hF : F.Finite := + (S.finite_toSet.image _).union (S.finite_toSet.image _) + apply (hF.preimage (cayleyGraph_injective S).injOn).subset + rintro ⟨e, z, s, hs, rfl⟩ hx + change x ∈ s(z, z * s) at hx + rcases Sym2.mem_iff.mp hx with hx | hx + · left + exact ⟨s, hs, by simp [hx, cayleyGraph]⟩ + · right + refine ⟨s, hs, ?_⟩ + simp [hx, cayleyGraph] + +noncomputable def cayleyEdgeTranslation (S : Finset Λ) (a : Λ) : CayleyEdge S ≃ CayleyEdge S where + toFun e := ⟨e.val.map (fun x => a * x), by + obtain ⟨e, x, s, hs, rfl⟩ := e + exact ⟨a * x, s, hs, by simp [mul_assoc]⟩⟩ + invFun e := ⟨e.val.map (fun x => a⁻¹ * x), by + obtain ⟨e, x, s, hs, rfl⟩ := e + exact ⟨a⁻¹ * x, s, hs, by simp [mul_assoc]⟩⟩ + left_inv e := by + apply Subtype.ext + simp [Sym2.map_map] + right_inv e := by + apply Subtype.ext + simp [Sym2.map_map] + +lemma cayley_translation_isAut (S : Finset Λ) (a : Λ) : + IsAut (cayleyGraph S) (Equiv.mulLeft a) (cayleyEdgeTranslation S a) := by + intro e + rfl + +lemma cayley_translation_mem (S : Finset Λ) (a : Λ) : + Equiv.mulLeft a ∈ vertexAut (cayleyGraph S) := + ⟨cayleyEdgeTranslation S a, cayley_translation_isAut S a⟩ + +lemma cayley_quasiTransitive (S : Finset Λ) : QuasiTransitive (cayleyGraph S) := by + refine ⟨{1}, ?_⟩ + intro x + exact ⟨1, Finset.mem_singleton_self _, Equiv.mulLeft x, cayleyEdgeTranslation S x, + cayley_translation_isAut S x, mul_one x⟩ + +lemma cayley_connected (S : Finset Λ) (hgen : Subgroup.closure (S : Set Λ) = ⊤) : + Connected (cayleyGraph S) := by + have paths (g : Λ) : ∀ x : Λ, + Relation.ReflTransGen (Adj (cayleyGraph S)) x (x * g) := by + have hg : g ∈ Subgroup.closure (S : Set Λ) := by rw [hgen]; trivial + induction hg using Subgroup.closure_induction with + | mem g hg => exact fun x => .single (cayley_adj_of_mem S x g hg) + | one => intro x; simpa using (Relation.ReflTransGen.refl (a := x)) + | mul a b ha hb ia ib => + intro x + simpa [mul_assoc] using (ia x).trans (ib (x * a)) + | inv a ha ia => + intro x + have h := ia (x * a⁻¹) + rw [inv_mul_cancel_right] at h + let : Std.Symm (Adj (cayleyGraph S)) := ⟨fun _ _ => adj_symm (cayleyGraph S)⟩ + exact symm h + intro x y + simpa using paths (x⁻¹ * y) x + +lemma cayley_rootTransport (S : Finset Λ) : + RootTransport (fun _ : Unit => (1 : Λ)) (fun _ => (1 : ℝ)) + (vertexAut (cayleyGraph S)) := by + intro m hm hr hc + simp only [Finset.univ_unique, Finset.sum_singleton, Complex.ofReal_one, one_mul] + calc + (∑' y, m 1 y) = ∑' y, m y⁻¹ 1 := by + apply tsum_congr + intro y + simpa using (hm (Equiv.mulLeft y⁻¹) (cayley_translation_mem S y⁻¹) 1 y).symm + _ = ∑' x, m x 1 := (Equiv.inv Λ).tsum_eq (fun x => m x 1) + +end GroupGeometry +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Cayley/Nonuniqueness.lean b/lean/OAI/Probability/UnimodularPercolation/Cayley/Nonuniqueness.lean index 1a0c7317e7946f93ffc3a5b58d0a237ed7ec4a98..99c371f779011b7cb479618654a59faa23703416 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Cayley/Nonuniqueness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Cayley/Nonuniqueness.lean @@ -1,64 +1,64 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Criticality.FullFiniteness -import OAI.Probability.UnimodularPercolation.Cayley.Folner -import OAI.Probability.UnimodularPercolation.Criticality.Phase - -namespace OAI - -/-! Nonuniqueness of percolation for arbitrary finite symmetric generating sets. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u - -theorem arbitrary_cayley {Λ : Type u} [Group Λ] [Group.FG Λ] - (hna : ¬ AmenableGroup Λ) (S : Finset Λ) - (hsym : ∀ s ∈ S, s⁻¹ ∈ S) (hgen : Subgroup.closure (S : Set Λ) = ⊤) - (h1 : 1 ∉ S) : - OperatorBounded (cayleyGraph S) (pc (cayleyGraph S)) ∧ - pc (cayleyGraph S) < ptwo (cayleyGraph S) ∧ - ptwo (cayleyGraph S) ≤ pu (cayleyGraph S) ∧ - (∃ p₁ p₂ : unitInterval, pc (cayleyGraph S) < p₁ ∧ p₁ < p₂ ∧ p₂ < 1 ∧ - ∀ᵐ labels ∂(labelLaw : Measure (CayleyEdge S → unitInterval)), - ∀ p ∈ Set.Icc p₁ p₂, (infiniteClusters (cayleyGraph S) (openEdges labels p)).Infinite) ∧ - (∀ p : unitInterval, pc (cayleyGraph S) < p → p < pu (cayleyGraph S) → - ∀ᵐ ω ∂law p, (infiniteClusters (cayleyGraph S) ω).Infinite) := by - classical - let : Infinite Λ := infinite_of_nonamenable hna - let G := cayleyGraph S - have hconn : Connected G := cayley_connected S hgen - have hloc : LocallyFinite G := cayley_locallyFinite S - have hqt : QuasiTransitive G := cayley_quasiTransitive S - have hh : 0 < hV G := cayley_hV_pos S hgen hna - have hsimple : Function.Injective G := cayleyGraph_injective S - have hloop : ∀ x, ¬ Adj G x x := cayley_loopless S hsym h1 - let : Countable Λ := countable_vertices hloc hconn - let : Countable (CayleyEdge S) := countable_edges hloc - let root : Unit → Λ := fun _ => 1 - let weight : Unit → ℝ := fun _ => 1 - have hw : ∀ i, 0 < weight i := fun _ => zero_lt_one - have hw1 : ∑ i, weight i = 1 := by simp [weight] - have htr : RootTransport root weight (vertexAut G) := cayley_rootTransport S - have hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x := by - intro x - exact ⟨(), Equiv.mulLeft x, cayley_translation_mem S x, mul_one x⟩ - have hfinite := critical_finite_ae_of_transport G hconn hloc hqt hh root weight htr hw hw1 hcov - have hb : OperatorBounded G (pc G) := by - apply critical_bounded_of_transport_finiteness G hsimple hconn hloc hqt hh - root weight htr hcov hw hw1 - intro i - filter_upwards [hfinite] with ω hω - exact hω (root i) - have hgap := strict_gap_of_critical_bounded G hloc hqt - (pc_lt_one_of_nonamenable G hconn hloc hqt hh) hb - have hm := mainConclusion_of_strict_gap G hconn hloc hqt hgap - exact ⟨hb, hgap, hm.2.2.2.1, hm.2.2.2.2, - fun p hc hu => infinitely_many_of_pc_lt_lt_pu G hconn hloc hqt p hc hu⟩ - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Criticality.FullFiniteness +import OAI.Probability.UnimodularPercolation.Cayley.Folner +import OAI.Probability.UnimodularPercolation.Criticality.Phase + +namespace OAI + +/-! Nonuniqueness of percolation for arbitrary finite symmetric generating sets. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u + +theorem arbitrary_cayley {Λ : Type u} [Group Λ] [Group.FG Λ] + (hna : ¬ AmenableGroup Λ) (S : Finset Λ) + (hsym : ∀ s ∈ S, s⁻¹ ∈ S) (hgen : Subgroup.closure (S : Set Λ) = ⊤) + (h1 : 1 ∉ S) : + OperatorBounded (cayleyGraph S) (pc (cayleyGraph S)) ∧ + pc (cayleyGraph S) < ptwo (cayleyGraph S) ∧ + ptwo (cayleyGraph S) ≤ pu (cayleyGraph S) ∧ + (∃ p₁ p₂ : unitInterval, pc (cayleyGraph S) < p₁ ∧ p₁ < p₂ ∧ p₂ < 1 ∧ + ∀ᵐ labels ∂(labelLaw : Measure (CayleyEdge S → unitInterval)), + ∀ p ∈ Set.Icc p₁ p₂, (infiniteClusters (cayleyGraph S) (openEdges labels p)).Infinite) ∧ + (∀ p : unitInterval, pc (cayleyGraph S) < p → p < pu (cayleyGraph S) → + ∀ᵐ ω ∂law p, (infiniteClusters (cayleyGraph S) ω).Infinite) := by + classical + let : Infinite Λ := infinite_of_nonamenable hna + let G := cayleyGraph S + have hconn : Connected G := cayley_connected S hgen + have hloc : LocallyFinite G := cayley_locallyFinite S + have hqt : QuasiTransitive G := cayley_quasiTransitive S + have hh : 0 < hV G := cayley_hV_pos S hgen hna + have hsimple : Function.Injective G := cayleyGraph_injective S + have hloop : ∀ x, ¬ Adj G x x := cayley_loopless S hsym h1 + let : Countable Λ := countable_vertices hloc hconn + let : Countable (CayleyEdge S) := countable_edges hloc + let root : Unit → Λ := fun _ => 1 + let weight : Unit → ℝ := fun _ => 1 + have hw : ∀ i, 0 < weight i := fun _ => zero_lt_one + have hw1 : ∑ i, weight i = 1 := by simp [weight] + have htr : RootTransport root weight (vertexAut G) := cayley_rootTransport S + have hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x := by + intro x + exact ⟨(), Equiv.mulLeft x, cayley_translation_mem S x, mul_one x⟩ + have hfinite := critical_finite_ae_of_transport G hconn hloc hqt hh root weight htr hw hw1 hcov + have hb : OperatorBounded G (pc G) := by + apply critical_bounded_of_transport_finiteness G hsimple hconn hloc hqt hh + root weight htr hcov hw hw1 + intro i + filter_upwards [hfinite] with ω hω + exact hω (root i) + have hgap := strict_gap_of_critical_bounded G hloc hqt + (pc_lt_one_of_nonamenable G hconn hloc hqt hh) hb + have hm := mainConclusion_of_strict_gap G hconn hloc hqt hgap + exact ⟨hb, hgap, hm.2.2.2.1, hm.2.2.2.2, + fun p hc hu => infinitely_many_of_pc_lt_lt_pu G hconn hloc hqt p hc hu⟩ + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/CayleyMain.lean b/lean/OAI/Probability/UnimodularPercolation/CayleyMain.lean index 137748b2f13d6a4cd12291a9af5bbe91a6f5b124..34cfe7ea4cb1088aee1a90c9b89f5bcb20663512 100644 --- a/lean/OAI/Probability/UnimodularPercolation/CayleyMain.lean +++ b/lean/OAI/Probability/UnimodularPercolation/CayleyMain.lean @@ -1 +1 @@ -import OAI.Probability.UnimodularPercolation.Cayley.Nonuniqueness +import OAI.Probability.UnimodularPercolation.Cayley.Nonuniqueness diff --git a/lean/OAI/Probability/UnimodularPercolation/Clusters/ExteriorMoments.lean b/lean/OAI/Probability/UnimodularPercolation/Clusters/ExteriorMoments.lean index 271902e59796ca035beb1ba29abb8aec40693766..cf1f2007e7ca4344ca4eefd5e11b813f4bc87ca2 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Clusters/ExteriorMoments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Clusters/ExteriorMoments.lean @@ -1,1207 +1,1207 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.KernelMoments - -namespace OAI - -/-! Exterior Moments for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section BinDiagonalLoss -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binDiagonalKernel (G : BondGraph V E) (p : unitInterval) - (o : V) (n : ℕ) (K : V → V → ℝ) (x y : V) : ℝ := - ∫ ω, binDiagonalMass G o n K ω x y ∂law p - -theorem binDiagonalKernel_covariant (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (hK : ∀ x y, K (a x) (a y) = K x y) (x y : V) : - binDiagonalKernel G p o n K (a x) (a y) = binDiagonalKernel G p o n K x y := by - have hm : Measurable (fun ω => binDiagonalMass G o n K ω x y) := - measurable_finite_local _ _ (fun ω => binDiagonalMass_local G hloc o n K ω x y) - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [binDiagonalKernel,binDiagonalMass_covariant G o n K hab hK] using h.symm - -theorem binDiagonalKernel_row_integral (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x : V) : - (∑' y, binDiagonalKernel G p o n K x y) = - ∫ ω, binSizeMass G n ω x ^ 2 * ∑ z ∈ binOrbitClass G o n ω x, K x z ∂law p := by - rw [←show (∫ ω, ∑' y, binDiagonalMass G o n K ω x y ∂law p) = - ∑' y, binDiagonalKernel G p o n K x y from - integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ - (fun y => binDiagonalMass_integrable G hloc p o n K x y) - (fun ω y hy => binDiagonalMass_outside G o n K ω x y (by simpa only [Set.Finite.mem_toFinset] using hy))] - simp only [binDiagonalMass_row] - -theorem binDiagonalKernel_column_integral (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x : V) : - (∑' y, binDiagonalKernel G p o n K y x) = - ∫ ω, ∑' y, binDiagonalMass G o n K ω y x ∂law p := by - symm - exact integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ - (fun y => binDiagonalMass_integrable G hloc p o n K y x) - (fun ω y hy => binDiagonalMass_outside_column G o n K ω y x (by simpa only [Set.Finite.mem_toFinset] using hy)) - -theorem integral_binDiagonalLoss (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (p : unitInterval) (n : ℕ) (K : V → V → ℝ) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) : - (∫ ω, binSizeMass G n ω (root i₀)^2 * - ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K (root i₀) z ∂law p) = - ∫ ω, binSizeMass G n ω (root i₀)^2 / (binOrbitClass G (root i₀) n ω (root i₀)).card * - ∑ y ∈ binOrbitClass G (root i₀) n ω (root i₀), - ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K y z ∂law p := by - have hr (x : V) : Summable (binDiagonalKernel G p (root i₀) n K x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) - intro y hy - simp only [binDiagonalKernel,binDiagonalMass_outside G (root i₀) n K _ x y - (by simpa only [Set.Finite.mem_toFinset] using hy),integral_zero] - have hc (y : V) : Summable (fun x => binDiagonalKernel G p (root i₀) n K x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y (2*n)).toFinset) - intro x hx - simp only [binDiagonalKernel,binDiagonalMass_outside_column G (root i₀) n K _ x y - (by simpa only [Set.Finite.mem_toFinset] using hx),integral_zero] - have ht := orbit_kernel_column_eq_row G root weight Γ htr hΓ hw i₀ hw₀ - (binDiagonalKernel G p (root i₀) n K) - (fun a b hab x y => binDiagonalKernel_covariant G hloc p (root i₀) n K hab (hcov a b hab) x y) - (fun x y hx => by simp only [binDiagonalKernel,binDiagonalMass_row_zero G _ n K _ x y hx,integral_zero]) - (fun x y hy => by simp only [binDiagonalKernel,binDiagonalMass_column_zero G _ n K _ x y hy,integral_zero]) - hr hc (root i₀) ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ - rw [binDiagonalKernel_row_integral G hloc,binDiagonalKernel_column_integral G hloc] at ht - simpa only [binDiagonalMass_column] using ht.symm - - - -theorem integral_binDiagonalLoss_le (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (p : unitInterval) (n : ℕ) (K : V → V → ℝ) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : - (∫ ω, binSizeMass G n ω (root i₀)^2 * - ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K (root i₀) z ∂law p) ≤ - ‖A‖ * ∫ ω, binSizeMass G n ω (root i₀)^2 ∂law p := by - rw [integral_binDiagonalLoss G hloc root weight Γ htr hΓ hw i₀ hw₀ p n K hcov] - have hi : Integrable (fun ω => ∑' y, binDiagonalMass G (root i₀) n K ω y (root i₀)) (law p) := by - have he (ω : Set E) : (∑' y, binDiagonalMass G (root i₀) n K ω y (root i₀)) = - ∑ y ∈ (finite_reachBall hloc (root i₀) (2*n)).toFinset, binDiagonalMass G (root i₀) n K ω y (root i₀) := by - apply tsum_eq_sum - intro y hy - exact binDiagonalMass_outside_column G (root i₀) n K ω y (root i₀) - (by simpa only [Set.Finite.mem_toFinset] using hy) - simp only [he] - exact integrable_finsetSum _ (fun y _ => binDiagonalMass_integrable G hloc p (root i₀) n K y (root i₀)) - have hs : Integrable (fun ω => binSizeMass G n ω (root i₀)^2) (law p) := - integrable_finite_local _ p _ (fun ω => congrArg (fun t : ℝ => t^2) (binSizeMass_local G hloc n ω (root i₀))) - rw [←integral_const_mul] - exact integral_mono (by simpa only [binDiagonalMass_column] using hi) (hs.const_mul ‖A‖) - (fun ω => by simpa only [binDiagonalMass_column] using binDiagonalMass_column_le G (root i₀) n K A hA ω (root i₀)) - -end BinDiagonalLoss -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DyadicDiagonalStrata -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def fullOrbitClass (G : BondGraph V E) (o : V) (ω : Set E) (x : V) : Finset V := - if h : (cluster G ω x).Finite then h.toFinset.filter (fun y => y ∈ vertexOrbit G o) else ∅ - -noncomputable def diagonalLossMass (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (ω : Set E) (x : V) : ℝ := - ((cluster G ω x).ncard:ℝ)^2 * ∑ z ∈ fullOrbitClass G o ω x, K x z - -theorem binSizeMass_zero (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) - (hw : ¬ ClusterWindow G x n (2*n) ω) : binSizeMass G n ω x = 0 := by - simp only [binSizeMass,binMass_zero_of_not_window G n ω x _ hw,tsum_zero] - -theorem binOrbitClass_eq_full (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) - (hx : x ∈ vertexOrbit G o) (hw : ClusterWindow G x n (2*n) ω) : - binOrbitClass G o n ω x = fullOrbitClass G o ω x := by - simp only [binOrbitClass,ite_eq_left hx,binClusterSlice,dite_eq_left hw,fullOrbitClass,dite_eq_left hw.1] - -theorem dyadic_window_iff (G : BondGraph V E) (ω : Set E) (x : V) (j : ℕ) - (hz : (cluster G ω x).ncard ≠ 0) : - ClusterWindow G x (2^j) (2*(2^j)) ω ↔ Nat.log 2 (cluster G ω x).ncard = j := by - constructor - · intro h - apply Nat.log_eq_of_pow_le_of_lt_pow h.2.1 - simpa only [pow_succ,Nat.mul_comm] using h.2.2 - · intro h - refine ⟨Set.finite_of_ncard_ne_zero hz,?_,?_⟩ - · rw [←h] - exact Nat.pow_log_le_self 2 hz - · rw [←h,show 2*2^(Nat.log 2 (cluster G ω x).ncard) = 2^(Nat.log 2 (cluster G ω x).ncard+1) by simp only [pow_succ,Nat.mul_comm]] - exact Nat.lt_pow_succ_log_self (by norm_num) _ - -theorem dyadic_binSizeMass_sq (G : BondGraph V E) (ω : Set E) (x : V) (j : ℕ) : - binSizeMass G (2^j) ω x ^ 2 = - if Nat.log 2 (cluster G ω x).ncard = j then ((cluster G ω x).ncard:ℝ)^2 else 0 := by - by_cases hz : (cluster G ω x).ncard = 0 - · have hw : ¬ClusterWindow G x (2^j) (2*(2^j)) ω := by - intro h - have hp : 0 < 2^j := pow_pos (by omega) _ - have hl := h.2.1 - omega - simp only [binSizeMass_zero G (2^j) ω x hw,hz,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0),ite_self] - · by_cases hw : ClusterWindow G x (2^j) (2*(2^j)) ω - · rw [binSizeMass_eq G (2^j) ω x hw,ite_eq_left ((dyadic_window_iff G ω x j hz).mp hw)] - · rw [binSizeMass_zero G (2^j) ω x hw,ite_eq_right (fun h => hw ((dyadic_window_iff G ω x j hz).mpr h))] - norm_num - -theorem dyadic_binDiagonalMass (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (ω : Set E) (x : V) (hx : x ∈ vertexOrbit G o) (j : ℕ) : - binSizeMass G (2^j) ω x ^ 2 * ∑ z ∈ binOrbitClass G o (2^j) ω x, K x z = - if Nat.log 2 (cluster G ω x).ncard = j then diagonalLossMass G o K ω x else 0 := by - by_cases hw : ClusterWindow G x (2^j) (2*(2^j)) ω - · have hz : (cluster G ω x).ncard ≠ 0 := by - have hp : 0 < 2^j := pow_pos (by omega) _ - have hl := hw.2.1 - omega - rw [ite_eq_left ((dyadic_window_iff G ω x j hz).mp hw),binOrbitClass_eq_full G o (2^j) ω x hx hw, - binSizeMass_eq G (2^j) ω x hw] - rfl - · rw [binSizeMass_zero G (2^j) ω x hw] - simp only [zero_pow (by omega : 2 ≠ 0),zero_mul] - by_cases hz : (cluster G ω x).ncard = 0 - · simp only [diagonalLossMass,hz,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0),zero_mul,ite_self] - · rw [ite_eq_right (fun h => hw ((dyadic_window_iff G ω x j hz).mpr h))] - -theorem diagonalLossMass_nonneg (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (hK : ∀ x y, 0 ≤ K x y) (ω : Set E) (x : V) : 0 ≤ diagonalLossMass G o K ω x := - mul_nonneg (sq_nonneg _) (Finset.sum_nonneg (fun z _ => hK x z)) - -theorem diagonalLossMass_le (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) (ω : Set E) (x : V) : - diagonalLossMass G o K ω x ≤ L*((cluster G ω x).ncard:ℝ)^2 := by - exact (mul_le_mul_of_nonneg_left (hrow x _) (sq_nonneg _)).trans_eq (mul_comm _ _) - -end DyadicDiagonalStrata -end Percolation - - -namespace Percolation -open MeasureTheory Filter -open scoped Topology -section DiscreteStratumIntegral -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem integral_le_of_discrete_strata {Ω : Type*} [MeasurableSpace Ω] - (μ : Measure Ω) (J : Ω → ℕ) (f g : Ω → ℝ) (C L : ℝ) - (hf0 : ∀ ω, 0 ≤ f ω) (hg0 : ∀ ω, 0 ≤ g ω) - (hfg : ∀ ω, f ω ≤ L*g ω) (hgi : Integrable g μ) - (hfi : ∀ j, Integrable (fun ω => if J ω = j then f ω else 0) μ) - (hgi' : ∀ j, Integrable (fun ω => if J ω = j then g ω else 0) μ) - (h : ∀ j, (∫ ω, (if J ω = j then f ω else 0) ∂μ) ≤ - C*(∫ ω, (if J ω = j then g ω else 0) ∂μ)) : - (∫ ω, f ω ∂μ) ≤ C*(∫ ω, g ω ∂μ) := by - let F : ℕ → Ω → ℝ := fun N ω => ∑ j ∈ Finset.range N, if J ω = j then f ω else 0 - let H : ℕ → Ω → ℝ := fun N ω => ∑ j ∈ Finset.range N, if J ω = j then g ω else 0 - have he (q : Ω → ℝ) (N : ℕ) (ω : Ω) : - (∑ j ∈ Finset.range N, if J ω = j then q ω else 0) = if J ω < N then q ω else 0 := by - simp only [Finset.sum_ite_eq,Finset.mem_range] - have hFi (N : ℕ) : Integrable (F N) μ := integrable_finsetSum _ (fun j _ => hfi j) - have hHi (N : ℕ) : Integrable (H N) μ := integrable_finsetSum _ (fun j _ => hgi' j) - have hFbody (N : ℕ) (ω : Ω) : ‖F N ω‖ ≤ L*g ω := by - dsimp [F] - rw [he] - split_ifs - · simpa only [Real.norm_eq_abs,abs_of_nonneg (hf0 ω)] using hfg ω - · simpa only [norm_zero,abs_zero] using (hf0 ω).trans (hfg ω) - have hHbody (N : ℕ) (ω : Ω) : ‖H N ω‖ ≤ g ω := by - dsimp [H] - rw [he] - split_ifs - · simp only [abs_of_nonneg (hg0 ω),le_refl] - · simpa only [norm_zero,abs_zero] using hg0 ω - have ht (q : Ω → ℝ) (ω : Ω) : Tendsto - (fun N => ∑ j ∈ Finset.range N, if J ω = j then q ω else 0) atTop (𝓝 (q ω)) := by - have he' : (fun N => ∑ j ∈ Finset.range N, if J ω = j then q ω else 0) =ᶠ[atTop] (fun _ => q ω) := by - filter_upwards [eventually_ge_atTop (J ω+1)] with N hN - rw [he,ite_eq_left (by omega)] - exact tendsto_const_nhds.congr' he'.symm - have htF := tendsto_integral_of_dominated_convergence (fun ω => L*g ω) - (fun N => (hFi N).aestronglyMeasurable) (hgi.const_mul L) - (fun N => Eventually.of_forall (hFbody N)) (Eventually.of_forall (ht f)) - have htH := tendsto_integral_of_dominated_convergence g - (fun N => (hHi N).aestronglyMeasurable) hgi - (fun N => Eventually.of_forall (hHbody N)) (Eventually.of_forall (ht g)) - apply le_of_tendsto_of_tendsto htF (tendsto_const_nhds.mul htH) - exact Eventually.of_forall (fun N => by - change (∫ ω, F N ω ∂μ) ≤ C*(∫ ω, H N ω ∂μ) - simp only [F,H,integral_finsetSum _ (fun j _ => hfi j), - integral_finsetSum _ (fun j _ => hgi' j),Finset.mul_sum] - exact Finset.sum_le_sum (fun j _ => h j)) - -end DiscreteStratumIntegral -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DiagonalLoss -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem integral_diagonalLoss_le (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (p : unitInterval) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) - (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) - (hs : Integrable (fun ω => ((cluster G ω (root i₀)).ncard:ℝ)^2) (law p)) : - (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ - ‖A‖*(∫ ω, ((cluster G ω (root i₀)).ncard:ℝ)^2 ∂law p) := by - have hx : root i₀ ∈ vertexOrbit G (root i₀) := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ - have hs' (j : ℕ) : Integrable (fun ω => binSizeMass G (2^j) ω (root i₀)^2) (law p) := - integrable_finite_local _ p _ (fun ω => congrArg (fun t : ℝ => t^2) - (binSizeMass_local G hloc (2^j) ω (root i₀))) - have hf' (j : ℕ) : Integrable (fun ω => binSizeMass G (2^j) ω (root i₀)^2 * - ∑ z ∈ binOrbitClass G (root i₀) (2^j) ω (root i₀), K (root i₀) z) (law p) := by - apply integrable_finite_local _ p _ - intro ω - rw [binOrbitClass_local G hloc (root i₀) (2^j) ω (root i₀),binSizeMass_local G hloc (2^j) ω (root i₀)] - apply integral_le_of_discrete_strata (law p) (fun ω => Nat.log 2 (cluster G ω (root i₀)).ncard) - (fun ω => diagonalLossMass G (root i₀) K ω (root i₀)) - (fun ω => ((cluster G ω (root i₀)).ncard:ℝ)^2) ‖A‖ L - (fun ω => diagonalLossMass_nonneg G (root i₀) K hK ω (root i₀)) - (fun _ => sq_nonneg _) (fun ω => diagonalLossMass_le G (root i₀) K L hrow ω (root i₀)) hs - · intro j - simpa only [dyadic_binDiagonalMass G (root i₀) K _ (root i₀) hx] using hf' j - · intro j - simpa only [dyadic_binSizeMass_sq] using hs' j - · intro j - have h := integral_binDiagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p (2^j) K hcov A hA - simp only [dyadic_binDiagonalMass G (root i₀) K _ (root i₀) hx] at h - simpa only [dyadic_binSizeMass_sq] using h - - - -theorem subcritical_diagonalLoss_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (p : unitInterval) (hp : p < pc G) : - ∃ C : ℝ, 0 ≤ C ∧ ∀ (K : V → V → ℝ), (∀ x y, 0 ≤ K x y) → - (∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) → - ∀ (L : ℝ), (∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) → - ∀ (A : Hilbert V →L[ℂ] Hilbert V), - (∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) → - (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ ‖A‖*C^3 := by - obtain ⟨C,hC,hs⟩ := subcritical_second_moment G hloc hqt p hp - refine ⟨C,hC,fun K hK hcov L hrow A hA => ?_⟩ - exact (integral_diagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p K hK hcov L hrow A hA - (hs (root i₀)).1).trans (mul_le_mul_of_nonneg_left (hs (root i₀)).2 (norm_nonneg _)) - -end DiagonalLoss -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section RootSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem second_moment_le_rootSusceptibility_cube [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (x : V) : - (∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p) ≤ - (c*rootSusceptibility G root weight p)^3 := by - let C := c*rootSusceptibility G root weight p - have hC : 0 ≤ C := mul_nonneg hc (rootSusceptibility_nonneg G root weight hw p) - have hrow (z : V) : (∑' y, law p {ω | Conn G ω z y}) ≤ ENNReal.ofReal C := by - rw [←ennreal_susceptibility G hloc hqt p hp] - exact ENNReal.ofReal_le_ofReal (susceptibility_le_rootSusceptibility G root weight hw hcov c hc hmin p z) - have hm : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^2) := - (measurable_of_countable (fun n : ℕ => (n:ℝ)^2)).comp (measurable_cluster_ncard G hloc x) - have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)^2) := - Filter.Eventually.of_forall (fun _ => sq_nonneg _) - have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2)) =ᵐ[law p] - (fun ω => clusterMass G ω x ^ 2) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_pow (Nat.cast_nonneg _)] - simp only [ENNReal.ofReal_natCast] - have hbound : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2) ∂law p) ≤ ENNReal.ofReal (C^3) := by - rw [lintegral_congr_ae he,ENNReal.ofReal_pow hC] - exact cluster_second_moment_bound G p _ hrow x - rw [integral_eq_lintegral_of_nonneg_ae hn hm.aestronglyMeasurable] - exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hbound).trans_eq (ENNReal.toReal_ofReal (pow_nonneg hC _)) - -theorem diagonalLoss_le_rootSusceptibility_cube [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) - (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : - (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ - ‖A‖*(c*rootSusceptibility G root weight p)^3 := by - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - exact (integral_diagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p K hK hcov L hrow A hA - (hs (root i₀)).1).trans (mul_le_mul_of_nonneg_left - (second_moment_le_rootSusceptibility_cube G hloc hqt root weight hw hcover c hc hmin p hp (root i₀)) - (norm_nonneg _)) - -end RootSecondMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DiagonalSeries -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def diagonalLossTerm (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (x y : V) (ω : Set E) : ℝ := - if y ∈ vertexOrbit G o ∧ Conn G ω x y then K x y*((cluster G ω x).ncard:ℝ)^2 else 0 - -theorem diagonalLossTerm_nonneg (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (hK : ∀ x y, 0 ≤ K x y) (x y : V) (ω : Set E) : - 0 ≤ diagonalLossTerm G o K x y ω := by - unfold diagonalLossTerm - split_ifs - · exact mul_nonneg (hK x y) (sq_nonneg _) - · exact le_rfl - -theorem diagonalLossTerm_le (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (hK : ∀ x y, 0 ≤ K x y) (x y : V) (ω : Set E) : - diagonalLossTerm G o K x y ω ≤ K x y*((cluster G ω x).ncard:ℝ)^2 := by - unfold diagonalLossTerm - split_ifs - · exact le_rfl - · exact mul_nonneg (hK x y) (sq_nonneg _) - -theorem diagonalLossMass_eq_tsum (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (x : V) (ω : Set E) : - diagonalLossMass G o K ω x = ∑' y, diagonalLossTerm G o K x y ω := by - by_cases hf : (cluster G ω x).Finite - · let S := fullOrbitClass G o ω x - have hs (y : V) : y ∈ S ↔ y ∈ vertexOrbit G o ∧ Conn G ω x y := by - dsimp only [S,fullOrbitClass] - rw [dite_eq_left hf] - simp only [Finset.mem_filter,Set.Finite.mem_toFinset,cluster,Set.mem_ofPred_eq] - exact and_comm - rw [tsum_eq_sum (s := S) (fun y hy => by - simp only [diagonalLossTerm,ite_eq_right (fun h => hy ((hs y).mpr h))])] - rw [diagonalLossMass,Finset.mul_sum] - apply Finset.sum_congr rfl - intro y hy - rw [diagonalLossTerm,ite_eq_left ((hs y).mp hy),mul_comm] - · have hn := Set.Infinite.ncard hf - simp only [diagonalLossMass,diagonalLossTerm,hn,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0), - mul_zero,zero_mul,ite_self,tsum_zero] - -theorem integrable_diagonalLossTerm [Countable V] [Countable E] (G : BondGraph V E) (o : V) (K : V → V → ℝ) - (x y : V) (p : unitInterval) - (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : - Integrable (diagonalLossTerm G o K x y) (law p) := by - by_cases hy : y ∈ vertexOrbit G o - · convert (hs.indicator (measurableSet_conn G x y)).const_mul (K x y) using 1 - ext ω - simp only [diagonalLossTerm,hy,true_and,Set.indicator,Set.mem_ofPred_eq] - split_ifs <;> simp only [mul_zero] - · have he : diagonalLossTerm G o K x y = (fun _ : Set E => (0:ℝ)) := by - funext ω - simp only [diagonalLossTerm,hy,false_and,ite_false] - rw [he] - exact integrable_const 0 - - - -theorem integral_diagonalLoss_eq_series [Countable V] [Countable E] - (G : BondGraph V E) (o : V) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) - (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) - (x : V) (p : unitInterval) - (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : - (∫ ω, diagonalLossMass G o K ω x ∂law p) = - ∑' y, if y ∈ vertexOrbit G o then - K x y*(∫ ω, (if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) ∂law p) else 0 := by - have hi (y : V) := integrable_diagonalLossTerm G o K x y p hs - have hzero (y : V) (ω : Set E) := diagonalLossTerm_nonneg G o K hK x y ω - have hn : Summable (fun y => ∫ ω, ‖diagonalLossTerm G o K x y ω‖ ∂law p) := by - simp only [Real.norm_of_nonneg (hzero _ _)] - apply summable_of_sum_le (fun y => integral_nonneg (hzero y)) (c := L*(∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p)) - intro S - rw [←integral_finsetSum _ (fun y _ => hi y),←integral_const_mul] - apply integral_mono (integrable_finsetSum _ (fun y _ => hi y)) (hs.const_mul L) - intro ω - calc - _ ≤ ∑ y ∈ S, K x y*((cluster G ω x).ncard:ℝ)^2 := - Finset.sum_le_sum (fun y _ => diagonalLossTerm_le G o K hK x y ω) - _ = (∑ y ∈ S, K x y)*((cluster G ω x).ncard:ℝ)^2 := (Finset.sum_mul ..).symm - _ ≤ _ := mul_le_mul_of_nonneg_right (hrow x S) (sq_nonneg _) - rw [show (fun ω => diagonalLossMass G o K ω x) = (fun ω => ∑' y, diagonalLossTerm G o K x y ω) from - funext (diagonalLossMass_eq_tsum G o K x)] - rw [←integral_tsum_of_summable_integral_norm hi hn] - apply tsum_congr - intro y - by_cases hy : y ∈ vertexOrbit G o - · simp only [diagonalLossTerm,hy,true_and,ite_true] - rw [←integral_const_mul] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by dsimp only; split_ifs <;> simp only [mul_zero]) - · simp only [diagonalLossTerm,hy,false_and,ite_false,integral_zero] - -end DiagonalSeries -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section RootSusceptibilityLower -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_rootSusceptibility_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (p₀ : ℝ) (hp₀ : 0 < p₀) : - ∃ a : ℝ, 0 < a ∧ ∀ (p : unitInterval), p₀ ≤ (p:ℝ) → p < pc G → ∀ x, - a*rootSusceptibility G root weight p ≤ susceptibility G p x := by - have hex (ij : ι × ι) : ∃ l : List E, Along G (root ij.1) l (root ij.2) := by - obtain ⟨l,hl,_,_⟩ := conn_exists_bond_trail G (conn_univ_of_connected G hconn (root ij.1) (root ij.2)) - exact ⟨l,hl⟩ - choose path hpath using hex - let N := ∑ ij : ι × ι, (path ij).length - have hlen (i j : ι) : (path (i,j)).length ≤ N := - Finset.single_le_sum (f := fun ij : ι × ι => (path ij).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ (i,j)) - refine ⟨p₀^N,pow_pos hp₀ N,fun p hp hpcrit x => ?_⟩ - obtain ⟨j,a,b,hab,hax⟩ := hcover x - have hfin (z : V) : Summable (fun y => (law p).real {ω | Conn G (ω ∩ Set.univ) z y}) := by - simp only [Set.inter_univ] - exact summable_twoPoint_subcritical G hloc hqt p hpcrit z - have heq (z : V) : restrictedSusceptibility G Set.univ p z = susceptibility G p z := by - simp only [restrictedSusceptibility,susceptibility,Set.inter_univ,twoPoint,Measure.real] - have hb (i : ι) : p₀^N*susceptibility G p (root i) ≤ susceptibility G p (root j) := by - have h := restrictedSusceptibility_path_lower G Set.univ p (hpath (j,i)) (fun _ _ => Set.mem_univ _) hfin - rw [heq,heq] at h - have hpow : p₀^N ≤ (p:ℝ)^(path (j,i)).length := - (pow_le_pow_left₀ hp₀.le hp N).trans (pow_le_pow_of_le_one p.2.1 p.2.2 (hlen j i)) - exact (mul_le_mul_of_nonneg_right hpow (susceptibility_nonneg G p _)).trans h - rw [←hax,susceptibility_aut G p hab] - calc - _ = ∑ i, weight i*(p₀^N*susceptibility G p (root i)) := by - simp only [rootSusceptibility,Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - ring - _ ≤ ∑ i, weight i*susceptibility G p (root j) := - Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hb i) (hw i)) - _ = susceptibility G p (root j) := by rw [←Finset.sum_mul,hw1,one_mul] - -end RootSusceptibilityLower -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ClusterAssociation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem association_finiteWitness_ennreal [Countable E] (p : unitInterval) - (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) - (hfA : FiniteWitness A) (hfB : FiniteWitness B) : - law p A * law p B ≤ law p (A ∩ B) := by - apply (ENNReal.toReal_le_toReal - (ENNReal.mul_ne_top (measure_ne_top _ _) (measure_ne_top _ _)) (measure_ne_top _ _)).mp - rw [ENNReal.toReal_mul] - exact association_finiteWitness p A B hA hB hfA hfB - -theorem clusterMass_mul (G : BondGraph V E) (ω : Set E) (x y : V) : - clusterMass G ω x * clusterMass G ω y = - ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b then (1:ℝ≥0∞) else 0 := by - rw [clusterMass,clusterMass,←ENNReal.tsum_mul_right] - apply tsum_congr - intro a - rw [←ENNReal.tsum_mul_left] - apply tsum_congr - intro b - split_ifs <;> simp_all - -theorem lintegral_clusterMass_mul [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y : V) : - (∫⁻ ω, clusterMass G ω x * clusterMass G ω y ∂law p) = - ∑' a, ∑' b, law p {ω | Conn G ω x a ∧ Conn G ω y b} := by - have hm (a b : V) : Measurable (fun ω : Set E => if Conn G ω x a ∧ Conn G ω y b then (1:ℝ≥0∞) else 0) := - Measurable.ite ((measurableSet_conn G x a).inter (measurableSet_conn G y b)) measurable_const measurable_const - simp_rw [clusterMass_mul] - rw [lintegral_tsum (fun a => (Measurable.tsum (fun b => hm a b)).aemeasurable)] - apply tsum_congr - intro a - rw [lintegral_tsum (fun b => (hm a b).aemeasurable)] - apply tsum_congr - intro b - have hs : MeasurableSet {ω : Set E | Conn G ω x a ∧ Conn G ω y b} := - (measurableSet_conn G x a).inter (measurableSet_conn G y b) - simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) hs) - -theorem clusterMass_association [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y : V) : - (∑' a, law p {ω | Conn G ω x a})*(∑' b, law p {ω | Conn G ω y b}) ≤ - ∫⁻ ω, clusterMass G ω x * clusterMass G ω y ∂law p := by - rw [lintegral_clusterMass_mul,←ENNReal.tsum_mul_right] - apply ENNReal.tsum_le_tsum - intro a - rw [←ENNReal.tsum_mul_left] - apply ENNReal.tsum_le_tsum - intro b - exact association_finiteWitness_ennreal p _ _ - (fun _ _ hω hc => conn_mono G hω hc) (fun _ _ hω hc => conn_mono G hω hc) - (finiteWitness_conn G x a) (finiteWitness_conn G y b) - - - -theorem subcritical_cluster_association [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) (law p) ∧ - susceptibility G p x * susceptibility G p y ≤ - ∫ ω, ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) ∂law p := by - have hm (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := - (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) - have hn (ω : Set E) : 0 ≤ ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) := - mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) - obtain ⟨_,_,hsecond⟩ := subcritical_second_moment G hloc hqt p hp - have hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) (law p) := by - apply ((hsecond x).1.add (hsecond y).1).mono' ((hm x).mul (hm y)).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun ω => by - dsimp only [Pi.mul_apply,Pi.add_apply] - rw [Real.norm_of_nonneg (hn ω)] - nlinarith [sq_nonneg (((cluster G ω x).ncard:ℝ)-((cluster G ω y).ncard:ℝ))]) - refine ⟨hi,?_⟩ - have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ))) =ᵐ[law p] - (fun ω => clusterMass G ω x * clusterMass G ω y) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy - rw [clusterMass_eq_ncard G ω x hx,clusterMass_eq_ncard G ω y hy,ENNReal.ofReal_mul (Nat.cast_nonneg _)] - simp only [ENNReal.ofReal_natCast] - have hb : ENNReal.ofReal (susceptibility G p x * susceptibility G p y) ≤ - ∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) ∂law p := by - rw [lintegral_congr_ae he,ENNReal.ofReal_mul (susceptibility_nonneg G p x), - ennreal_susceptibility G hloc hqt p hp,ennreal_susceptibility G hloc hqt p hp] - exact clusterMass_association G p x y - have htop : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) ∂law p) ≠ ⊤ := - ne_of_lt ((hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hn)).mp hi.hasFiniteIntegral) - rw [integral_eq_lintegral_of_nonneg_ae (Filter.Eventually.of_forall hn) hi.aestronglyMeasurable] - simpa only [ENNReal.toReal_ofReal (mul_nonneg (susceptibility_nonneg G p x) (susceptibility_nonneg G p y))] using - ENNReal.toReal_mono htop hb - -end ClusterAssociation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteLocalIndependence -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integral_mul_finite_local (I R : Finset E) (hdis : Disjoint I R) - (p : unitInterval) (f g : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (I:Set E))) - (hg : ∀ ω, g ω = g (ω ∩ (R:Set E))) : - (∫ ω, f ω*g ω ∂law p) = (∫ ω, f ω ∂law p)*(∫ ω, g ω ∂law p) := by - have hf' := finite_local_of_subset I (I∪R) Finset.subset_union_left f hf - have hg' := finite_local_of_subset R (I∪R) Finset.subset_union_right g hg - rw [integral_eq_bernoulliPolynomial (I∪R) p _ (fun ω => by rw [hf' ω,hg' ω]), - integral_eq_bernoulliPolynomial I p f hf,integral_eq_bernoulliPolynomial R p g hg, - bernoulliPolynomial_union I R hdis] - have hi (a b : Finset E) (ha : a ⊆ I) (hb : b ⊆ R) : - ((a ∪ b : Finset E):Set E) ∩ (I:Set E) = a := by - ext e - simp only [Finset.coe_union,Set.mem_inter_iff,Set.mem_union,Finset.mem_coe] - constructor - · rintro ⟨he,hI⟩ - rcases he with he | he - · exact he - · exact ((Finset.disjoint_left.mp hdis) hI (hb he)).elim - · intro he - exact ⟨Or.inl he,ha he⟩ - have hr (a b : Finset E) (ha : a ⊆ I) (hb : b ⊆ R) : - ((a ∪ b : Finset E):Set E) ∩ (R:Set E) = b := by - ext e - simp only [Finset.coe_union,Set.mem_inter_iff,Set.mem_union,Finset.mem_coe] - constructor - · rintro ⟨he,hR⟩ - rcases he with he | he - · exact ((Finset.disjoint_left.mp hdis) (ha he) hR).elim - · exact he - · intro he - exact ⟨Or.inr he,hb he⟩ - trans bernoulliPolynomial I (fun a => f a*bernoulliPolynomial R (fun b => g b) p) p - · apply bernoulliPolynomial_congr - intro a ha - rw [←bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro b hb - rw [hf ((a∪b : Finset E):Set E),hg ((a∪b : Finset E):Set E),hi a b ha hb,hr a b ha hb] - · exact bernoulliPolynomial_mul_const I _ _ p - -theorem complement_incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) : - ((incidentSupport G hloc W:Set E))ᶜ = internalEdges G (W:Set V)ᶜ := by - ext e - simp only [Set.mem_compl_iff,Finset.mem_coe,mem_incidentSupport,internalEdges,Set.mem_ofPred_eq] - push Not - constructor - · intro h x hx hxW - exact h x hxW hx - · intro h x hxW hx - exact h x hx hxW - - - -theorem cluster_restrict_incident_eq_iff (G : BondGraph V E) (hloc : LocallyFinite G) - (W : Finset V) (Q : Finset E) (hQ : incidentSupport G hloc W ⊆ Q) - (ω : Set E) (x : V) : - cluster G (ω ∩ (Q:Set E)) x = (W:Set V) ↔ cluster G ω x = W := by - have ho : ω \ (Q:Set E) ⊆ internalEdges G (W:Set V)ᶜ := by - rw [←complement_incidentSupport G hloc W] - exact fun _ h => fun he => h.2 (hQ he) - have h := cluster_union_external_eq_iff G (ω ∩ (Q:Set E)) (ω \ (Q:Set E)) x W ho - simpa only [Set.inter_union_sdiff] using h.symm - -theorem measurableSet_cluster_eq [Countable V] [Countable E] - (G : BondGraph V E) (x : V) (W : Set V) : MeasurableSet {ω : Set E | cluster G ω x = W} := by - have he : {ω : Set E | cluster G ω x = W} = ⋂ y, {ω : Set E | Conn G ω x y ↔ y ∈ W} := by - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_iInter,Set.ext_iff,cluster] - rw [he] - apply MeasurableSet.iInter - intro y - by_cases hy : y ∈ W - · simpa only [hy,iff_true] using measurableSet_conn G x y - · simpa only [hy,iff_false,Set.compl_ofPred] using (measurableSet_conn G x y).compl - - - -theorem cluster_cell_finite_exterior_independence [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) (x : V) - (R : Finset E) (hR : (R:Set E) ⊆ internalEdges G (W:Set V)ᶜ) - (p : unitInterval) (f : Set E → ℝ) (hf : ∀ ω, f ω = f (ω ∩ (R:Set E))) : - (∫ ω, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)*f ω ∂law p) = - (law p).real {ω | cluster G ω x = (W:Set V)} * (∫ ω, f ω ∂law p) := by - have hdis : Disjoint (incidentSupport G hloc W) R := by - rw [←complement_incidentSupport G hloc W] at hR - exact Finset.disjoint_left.mpr (fun e he h => hR h he) - have hc (ω : Set E) : - (if cluster G ω x = (W:Set V) then (1:ℝ) else 0) = - (if cluster G (ω ∩ (incidentSupport G hloc W:Set E)) x = (W:Set V) then 1 else 0) := by - simp only [cluster_restrict_incident_eq_iff G hloc W _ (by rfl)] - rw [integral_mul_finite_local _ R hdis p _ f hc hf] - congr 1 - have hm : MeasurableSet {ω : Set E | cluster G ω x = (W:Set V)} := measurableSet_cluster_eq G x W - simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using integral_indicator_one hm - -end FiniteLocalIndependence - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped Topology -section ExteriorConnectionIndependence -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurableSet_restrictedConn [Countable E] (G : BondGraph V E) - (S : Set E) (x y : V) : MeasurableSet {ω : Set E | Conn G (ω ∩ S) x y} := - measurableSet_finiteWitness _ - (fun _ _ hω hc => conn_mono G (Set.inter_subset_inter_left _ hω) hc) - (finiteWitness_inter _ (finiteWitness_conn G x y) S) - -theorem integral_event_indicator (p : unitInterval) (A : Set (Set E)) (hA : MeasurableSet A) : - (∫ ω, (if ω ∈ A then (1:ℝ) else 0) ∂law p) = (law p).real A := by - simpa only [Set.indicator,Pi.one_apply] using (integral_indicator_one (μ := law p) hA) - - - -theorem cluster_cell_exterior_connection_independent [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) - (x y z : V) (p : unitInterval) : - (law p).real {ω | cluster G ω x = (W:Set V) ∧ Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} = - (law p).real {ω | cluster G ω x = (W:Set V)} * - (law p).real {ω | Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} := by - let := Encodable.ofCountable E - let S := internalEdges G (W:Set V)ᶜ - let R := restrictedBondExhaustion S ∅ - have hmono : Monotone R := restrictedBondExhaustion_mono S ∅ - have hsub (n : ℕ) : (R n:Set E) ⊆ S := restrictedBondExhaustion_subset S ∅ (by simp) n - have hcover (e : E) (he : e ∈ S) : ∃ n, e ∈ R n := restrictedBondExhaustion_cover S ∅ e he - let A : Set (Set E) := {ω | cluster G ω x = (W:Set V)} - let B (n : ℕ) : Set (Set E) := {ω | Conn G (ω ∩ (R n:Set E)) y z} - let Btop : Set (Set E) := {ω | Conn G (ω ∩ S) y z} - have hB : Monotone B := fun n m h ω hc => - conn_mono G (Set.inter_subset_inter_right _ (show (R n:Set E) ⊆ (R m:Set E) from hmono h)) hc - have hu : (⋃ n, B n) = Btop := by - ext ω - simp only [B,Btop,Set.mem_iUnion,Set.mem_ofPred_eq] - exact ⟨fun ⟨n,hn⟩ => conn_mono G (Set.inter_subset_inter_right _ (hsub n)) hn, - conn_finite_exhaustion G S R hmono hcover⟩ - have huA : (⋃ n, A ∩ B n) = A ∩ Btop := by rw [←Set.inter_iUnion,hu] - have htB := tendsto_measure_iUnion_atTop (μ := law p) hB - have htA := tendsto_measure_iUnion_atTop (μ := law p) - (show Monotone (fun n => A ∩ B n) from fun _ _ h => Set.inter_subset_inter_right _ (hB h)) - rw [hu] at htB - rw [huA] at htA - have htB' := (ENNReal.tendsto_toReal (measure_ne_top (law p) Btop)).comp htB - have htA' := (ENNReal.tendsto_toReal (measure_ne_top (law p) (A∩Btop))).comp htA - have he (n : ℕ) : (law p).real (A ∩ B n) = (law p).real A * (law p).real (B n) := by - have h := cluster_cell_finite_exterior_independence G hloc W x (R n) (hsub n) p - (fun ω => if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) - (fun ω => by rw [Set.inter_assoc,Set.inter_self]) - have hf : (∫ ω, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)* - (if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) ∂law p) = (law p).real (A ∩ B n) := by - rw [←integral_event_indicator p (A∩B n) - ((measurableSet_cluster_eq G x W).inter (measurableSet_restrictedConn G _ y z))] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - dsimp only [A,B,Set.mem_inter_iff,Set.mem_ofPred_eq] - split_ifs <;> simp_all) - rw [hf] at h - rw [show (∫ ω, (if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) ∂law p) = - (law p).real (B n) from integral_event_indicator p (B n) (measurableSet_restrictedConn G _ y z)] at h - exact h - exact tendsto_nhds_unique htA' ((tendsto_const_nhds.mul htB').congr (fun n => (he n).symm)) - -end ExteriorConnectionIndependence -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExposedClusterGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem conn_exterior_of_cluster_eq (G : BondGraph V E) (ω : Set E) - (x y z : V) (W : Set V) (hW : cluster G ω x = W) (hy : y ∉ W) : - Conn G (ω ∩ internalEdges G Wᶜ) y z ↔ Conn G ω y z := by - refine ⟨conn_mono G Set.inter_subset_left,fun h => ?_⟩ - have hout (a : V) (ha : Conn G ω y a) : a ∉ W := by - intro haW - have hxa : Conn G ω x a := by change a ∈ cluster G ω x; rwa [hW] - exact hy (hW ▸ (hxa.trans (conn_symm G _ ha) : y ∈ cluster G ω x)) - induction h with - | refl => exact conn_refl G _ y - | @tail a b hya hab ih => - obtain ⟨e,he,heq⟩ := hab - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G Wᶜ e a b heq).mpr - ⟨hout a hya,hout b (hya.tail ⟨e,he,heq⟩)⟩⟩,heq⟩ - -theorem cluster_size_eq_tsum_real (G : BondGraph V E) (ω : Set E) (y : V) - (hf : (cluster G ω y).Finite) : - ((cluster G ω y).ncard:ℝ) = ∑' z, if Conn G ω y z then (1:ℝ) else 0 := by - rw [tsum_eq_sum (s := hf.toFinset) (fun z hz => by - exact ite_eq_right (fun hc => hz (hf.mem_toFinset.mpr hc)))] - rw [show (∑ z ∈ hf.toFinset, if Conn G ω y z then (1:ℝ) else 0) = - ∑ _z ∈ hf.toFinset, (1:ℝ) from Finset.sum_congr rfl (fun z hz => ite_eq_left (hf.mem_toFinset.mp hz))] - simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] - - - -theorem integral_cluster_size_event [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (y : V) (A : Set (Set E)) (hA : MeasurableSet A) : - (∫ ω, (if ω ∈ A then ((cluster G ω y).ncard:ℝ) else 0) ∂law p) = - ∑' z, (law p).real {ω | ω ∈ A ∧ Conn G ω y z} := by - let f (z : V) (ω : Set E) : ℝ := if ω ∈ A ∧ Conn G ω y z then 1 else 0 - have hm (z : V) : MeasurableSet {ω : Set E | ω ∈ A ∧ Conn G ω y z} := - hA.inter (measurableSet_conn G y z) - have hf (z : V) : f z = {ω : Set E | ω ∈ A ∧ Conn G ω y z}.indicator (fun _ => (1:ℝ)) := by - funext ω - simp only [f,Set.indicator,Set.mem_ofPred_eq] - have hi (z : V) : Integrable (f z) (law p) := by - rw [hf] - exact (integrable_const (1:ℝ)).indicator (hm z) - have hn (z : V) (ω : Set E) : 0 ≤ f z ω := by unfold f; split_ifs <;> norm_num - have he (z : V) : (∫ ω, f z ω ∂law p) = (law p).real {ω | ω ∈ A ∧ Conn G ω y z} := by - rw [hf] - exact integral_indicator_one (hm z) - have hint : Summable (fun z => ∫ ω, ‖f z ω‖ ∂law p) := by - simp_rw [Real.norm_of_nonneg (hn _ _),he] - apply (summable_twoPoint_subcritical G hloc hqt p hp y).of_nonneg_of_le - · exact fun _ => ENNReal.toReal_nonneg - · intro z - exact ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (fun ω h => h.2)) - calc - _ = ∫ ω, ∑' z, f z ω ∂law p := by - apply integral_congr_ae - filter_upwards [subcritical_cluster_finite_ae G p hp y] with ω hω - by_cases hωA : ω ∈ A - · simp only [hωA,ite_true,f,true_and] - exact cluster_size_eq_tsum_real G ω y hω - · simp only [hωA,ite_false,f,false_and,tsum_zero] - _ = ∑' z, ∫ ω, f z ω ∂law p := (integral_tsum_of_summable_integral_norm hi hint).symm - _ = _ := tsum_congr he - -end ExposedClusterGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExteriorCellSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem cluster_cell_exterior_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (W : Finset V) (x y : V) : - (∫ ω, (if cluster G ω x = (W:Set V) ∧ ¬Conn G ω x y - then ((cluster G ω y).ncard:ℝ) else 0) ∂law p) = - (law p).real {ω | cluster G ω x = (W:Set V)} * - inducedSusceptibility G (W:Set V)ᶜ p y := by - by_cases hy : y ∈ (W:Set V) - · rw [inducedSusceptibility,ite_eq_right (fun h => h hy),mul_zero] - calc - _ = ∫ _ω : Set E, (0:ℝ) ∂law p := by - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - dsimp only - split_ifs with h - · have hc : Conn G ω x y := by change y ∈ cluster G ω x; rwa [h.1] - exact (h.2 hc).elim - · rfl) - _ = 0 := integral_zero _ _ - · simp only [inducedSusceptibility,Set.mem_compl_iff,hy,not_false_eq_true,ite_true] - calc - _ = ∫ ω, (if cluster G ω x = (W:Set V) then ((cluster G ω y).ncard:ℝ) else 0) ∂law p := by - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - dsimp only - by_cases hc : cluster G ω x = (W:Set V) - · have hnc : ¬Conn G ω x y := by intro h; exact hy (hc ▸ h) - simp [hc,hnc] - · simp only [hc,false_and,ite_false]) - _ = ∑' z, (law p).real {ω | cluster G ω x = (W:Set V) ∧ Conn G ω y z} := - integral_cluster_size_event G hloc hqt p hp y _ (measurableSet_cluster_eq G x W) - _ = ∑' z, (law p).real {ω | cluster G ω x = (W:Set V)} * - (law p).real {ω | Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} := by - apply tsum_congr - intro z - rw [show {ω : Set E | cluster G ω x = (W:Set V) ∧ Conn G ω y z} = - {ω | cluster G ω x = (W:Set V) ∧ Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} from by - ext ω - exact ⟨fun h => ⟨h.1,(conn_exterior_of_cluster_eq G ω x y z W h.1 hy).mpr h.2⟩, - fun h => ⟨h.1,conn_mono G Set.inter_subset_left h.2⟩⟩] - exact cluster_cell_exterior_connection_independent G hloc W x y z p - _ = _ := tsum_mul_left - -theorem restrictedSusceptibility_le_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (S : Set E) (y : V) : - restrictedSusceptibility G S p y ≤ susceptibility G p y := by - apply Summable.tsum_le_tsum _ (summable_restrictedTwoPoint G hloc hqt p hp S y) - (summable_twoPoint_subcritical G hloc hqt p hp y) - exact fun z => ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (fun ω hc => conn_mono G Set.inter_subset_left hc)) - -theorem inducedSusceptibility_le_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (D : Set V) (y : V) : - inducedSusceptibility G D p y ≤ susceptibility G p y := by - unfold inducedSusceptibility - split_ifs - · exact restrictedSusceptibility_le_susceptibility G hloc hqt p hp _ y - · exact susceptibility_nonneg G p y - -end ExteriorCellSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterPartition -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem tsum_cluster_cells (G : BondGraph V E) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) (a : ℝ) : - (∑' W : Finset V, if cluster G ω x = (W:Set V) then a else 0) = a := by - let W := hf.toFinset - have hW : cluster G ω x = (W:Set V) := hf.coe_toFinset.symm - rw [tsum_eq_single W (fun U hU => ite_eq_right (fun h => hU (Finset.coe_injective (h.symm.trans hW)))),ite_eq_left hW] - - - -theorem integral_cluster_finite_partition [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (x : V) - (f : Set E → ℝ) (hf : Integrable f (law p)) : - (∫ ω, f ω ∂law p) = ∑' W : Finset V, - ∫ ω, (if cluster G ω x = (W:Set V) then f ω else 0) ∂law p := by - let F (W : Finset V) (ω : Set E) := if cluster G ω x = (W:Set V) then f ω else 0 - have hi (W : Finset V) : Integrable (F W) (law p) := by - have he : F W = {ω : Set E | cluster G ω x = (W:Set V)}.indicator f := by - funext ω - simp only [F,Set.indicator,Set.mem_ofPred_eq] - split_ifs <;> rfl - rw [he] - exact hf.indicator (measurableSet_cluster_eq G x W) - have hb (S : Finset (Finset V)) (ω : Set E) : (∑ W ∈ S, ‖F W ω‖) ≤ ‖f ω‖ := by - by_cases hex : ∃ W ∈ S, cluster G ω x = (W:Set V) - · obtain ⟨W,hWS,hW⟩ := hex - rw [Finset.sum_eq_single W] - · simp only [F,hW,ite_true,le_refl] - · intro U _ hU - have hu : cluster G ω x ≠ (U:Set V) := fun h => hU (Finset.coe_injective (h.symm.trans hW)) - simp only [F,ite_eq_right hu,norm_zero] - · exact fun h => (h hWS).elim - · have he (W : Finset V) (hW : W ∈ S) : cluster G ω x ≠ (W:Set V) := fun h => hex ⟨W,hW,h⟩ - calc - _ = 0 := Finset.sum_eq_zero (fun W hW => by simp only [F,ite_eq_right (he W hW),norm_zero]) - _ ≤ _ := norm_nonneg _ - have hn : Summable (fun W => ∫ ω, ‖F W ω‖ ∂law p) := by - apply summable_of_sum_le (fun _ => integral_nonneg (fun _ => norm_nonneg _)) - (c := ∫ ω, ‖f ω‖ ∂law p) - intro S - rw [←integral_finsetSum _ (fun W _ => (hi W).norm)] - exact integral_mono (integrable_finsetSum _ (fun W _ => (hi W).norm)) hf.norm (hb S) - calc - _ = ∫ ω, ∑' W : Finset V, F W ω ∂law p := by - apply integral_congr_ae - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact (tsum_cluster_cells G ω x hω (f ω)).symm - _ = _ := (integral_tsum_of_summable_integral_norm hi hn).symm - -end ClusterPartition -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FreshExteriorMoment -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def freshExteriorMoment (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) : ℝ := - ((cluster G ω x).ncard:ℝ) * inducedSusceptibility G (cluster G ω x)ᶜ p y - -theorem freshExteriorMoment_eq_tsum (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) : - freshExteriorMoment G p x y ω = ∑' W : Finset V, if cluster G ω x = (W:Set V) - then (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y else 0 := by - by_cases hf : (cluster G ω x).Finite - · let W := hf.toFinset - have hW : cluster G ω x = (W:Set V) := hf.coe_toFinset.symm - rw [tsum_eq_single W (fun U hU => ite_eq_right (fun h => hU (Finset.coe_injective (h.symm.trans hW)))),ite_eq_left hW] - simp only [freshExteriorMoment,hW,Set.ncard_coe_finset] - · have he (W : Finset V) : cluster G ω x ≠ (W:Set V) := fun h => hf (h ▸ W.finite_toSet) - simp only [freshExteriorMoment,Set.Infinite.ncard hf,Nat.cast_zero,zero_mul,ite_eq_right (he _),tsum_zero] - -theorem measurable_freshExteriorMoment [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y : V) : Measurable (freshExteriorMoment G p x y) := by - simp_rw [show freshExteriorMoment G p x y = (fun ω => ∑' W : Finset V, if cluster G ω x = (W:Set V) - then (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y else 0) from funext (freshExteriorMoment_eq_tsum G p x y)] - apply Measurable.tsum - intro W - exact Measurable.ite (measurableSet_cluster_eq G x W) measurable_const measurable_const - -theorem freshExteriorMoment_nonneg (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) : 0 ≤ freshExteriorMoment G p x y ω := - mul_nonneg (Nat.cast_nonneg _) (inducedSusceptibility_nonneg G _ p y) - -theorem integrable_freshExteriorMoment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (freshExteriorMoment G p x y) (law p) := by - apply ((susceptibility_eq_integral G hloc hqt p hp x).1.mul_const (susceptibility G p y)).mono' - (measurable_freshExteriorMoment G p x y).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun ω => by - rw [Real.norm_of_nonneg (freshExteriorMoment_nonneg G p x y ω)] - exact mul_le_mul_of_nonneg_left (inducedSusceptibility_le_susceptibility G hloc hqt p hp _ y) (Nat.cast_nonneg _)) - -theorem integrable_distinct_cluster_product [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (fun ω => if ¬Conn G ω x y - then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) (law p) := by - have he : (fun ω : Set E => if ¬Conn G ω x y - then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) = - {ω : Set E | Conn G ω x y}ᶜ.indicator - (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) := by - funext ω - simp only [Set.indicator,Set.mem_compl_iff,Set.mem_ofPred_eq] - rw [he] - exact (subcritical_cluster_association G hloc hqt p hp x y).1.indicator - (measurableSet_conn G x y).compl - - - -theorem integral_freshExteriorMoment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - (∫ ω, freshExteriorMoment G p x y ω ∂law p) = - ∫ ω, (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) ∂law p := by - rw [integral_cluster_finite_partition G p hp x _ (integrable_freshExteriorMoment G hloc hqt p hp x y), - integral_cluster_finite_partition G p hp x _ (integrable_distinct_cluster_product G hloc hqt p hp x y)] - apply tsum_congr - intro W - have hl : (∫ ω, (if cluster G ω x = (W:Set V) then freshExteriorMoment G p x y ω else 0) ∂law p) = - (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y * (law p).real {ω | cluster G ω x = (W:Set V)} := by - rw [←integral_event_indicator p _ (measurableSet_cluster_eq G x W),←integral_const_mul] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - dsimp only [Set.mem_ofPred_eq] - by_cases hc : cluster G ω x = (W:Set V) - · simp only [hc,ite_true,freshExteriorMoment,Set.ncard_coe_finset,mul_one] - · simp only [hc,ite_false,mul_zero]) - have hr : (∫ ω, (if cluster G ω x = (W:Set V) then - (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) else 0) ∂law p) = - (W.card:ℝ)*((law p).real {ω | cluster G ω x = (W:Set V)} * inducedSusceptibility G (W:Set V)ᶜ p y) := by - rw [←cluster_cell_exterior_susceptibility G hloc hqt p hp W x y,←integral_const_mul] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - dsimp only - by_cases hc : cluster G ω x = (W:Set V) - · simp only [hc,true_and,ite_true,Set.ncard_coe_finset] - split_ifs <;> simp only [mul_zero] - · simp only [hc,false_and,ite_false,mul_zero]) - rw [hl,hr] - ring - -end FreshExteriorMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DistinctClusterMoments -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def distinctClusterMoment (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := - ∫ ω, (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) ∂law p - -theorem distinctClusterMoment_nonneg (G : BondGraph V E) (p : unitInterval) (x y : V) : - 0 ≤ distinctClusterMoment G p x y := by - apply integral_nonneg - intro ω - dsimp only [Pi.zero_apply] - split_ifs <;> positivity - -theorem cluster_ncard_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) : - (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by - rw [←cluster_aut G hab,Set.ncard_image_of_injective _ a.injective] - -theorem distinctClusterMoment_covariant [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : - distinctClusterMoment G p (a x) (a y) = distinctClusterMoment G p x y := by - have hs (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := - (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) - have hm : Measurable (fun ω : Set E => if ¬Conn G ω x y - then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) := - Measurable.ite (measurableSet_conn G x y).compl ((hs x).mul (hs y)) measurable_const - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [distinctClusterMoment,conn_aut_iff G hab,cluster_ncard_covariant G hab] using h.symm - -noncomputable def neighborClusterMoment (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x : V) : ℝ := - ∑ y ∈ neighbors G hloc x, distinctClusterMoment G p x y - -theorem neighborClusterMoment_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x : V) : 0 ≤ neighborClusterMoment G hloc p x := - Finset.sum_nonneg (fun y _ => distinctClusterMoment_nonneg G p x y) - -theorem neighbors_covariant (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : - neighbors G hloc (a x) = (neighbors G hloc x).map a.toEmbedding := by - ext y - simp only [mem_neighbors,Finset.mem_map,Equiv.coe_toEmbedding] - constructor - · intro h - refine ⟨a.symm y,?_,by simp⟩ - simpa only [a.symm_apply_apply] using adj_aut G (isAut_symm G hab) h - · rintro ⟨z,hz,rfl⟩ - exact adj_aut G hab hz - -theorem neighborClusterMoment_covariant [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : - neighborClusterMoment G hloc p (a x) = neighborClusterMoment G hloc p x := by - simp only [neighborClusterMoment,neighbors_covariant G hloc hab,Finset.sum_map,Equiv.coe_toEmbedding, - distinctClusterMoment_covariant G hloc p hab] - -noncomputable def rootNeighborMoment (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : ℝ := - ∑ i, weight i * neighborClusterMoment G hloc p (root i) - -theorem neighborMoment_le_rootMoment [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (p : unitInterval) (x : V) : - neighborClusterMoment G hloc p x ≤ c*rootNeighborMoment G hloc root weight p := by - obtain ⟨i,a,b,hab,hax⟩ := hcov x - rw [←hax,neighborClusterMoment_covariant G hloc p hab] - calc - _ ≤ (c*weight i)*neighborClusterMoment G hloc p (root i) := by - simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) (neighborClusterMoment_nonneg G hloc p _) - _ = c*(weight i*neighborClusterMoment G hloc p (root i)) := mul_assoc _ _ _ - _ ≤ _ := mul_le_mul_of_nonneg_left - (Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (neighborClusterMoment_nonneg G hloc p _)) (Finset.mem_univ i)) hc - -end DistinctClusterMoments -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.KernelMoments + +namespace OAI + +/-! Exterior Moments for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section BinDiagonalLoss +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binDiagonalKernel (G : BondGraph V E) (p : unitInterval) + (o : V) (n : ℕ) (K : V → V → ℝ) (x y : V) : ℝ := + ∫ ω, binDiagonalMass G o n K ω x y ∂law p + +theorem binDiagonalKernel_covariant (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (hK : ∀ x y, K (a x) (a y) = K x y) (x y : V) : + binDiagonalKernel G p o n K (a x) (a y) = binDiagonalKernel G p o n K x y := by + have hm : Measurable (fun ω => binDiagonalMass G o n K ω x y) := + measurable_finite_local _ _ (fun ω => binDiagonalMass_local G hloc o n K ω x y) + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [binDiagonalKernel,binDiagonalMass_covariant G o n K hab hK] using h.symm + +theorem binDiagonalKernel_row_integral (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x : V) : + (∑' y, binDiagonalKernel G p o n K x y) = + ∫ ω, binSizeMass G n ω x ^ 2 * ∑ z ∈ binOrbitClass G o n ω x, K x z ∂law p := by + rw [←show (∫ ω, ∑' y, binDiagonalMass G o n K ω x y ∂law p) = + ∑' y, binDiagonalKernel G p o n K x y from + integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ + (fun y => binDiagonalMass_integrable G hloc p o n K x y) + (fun ω y hy => binDiagonalMass_outside G o n K ω x y (by simpa only [Set.Finite.mem_toFinset] using hy))] + simp only [binDiagonalMass_row] + +theorem binDiagonalKernel_column_integral (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x : V) : + (∑' y, binDiagonalKernel G p o n K y x) = + ∫ ω, ∑' y, binDiagonalMass G o n K ω y x ∂law p := by + symm + exact integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ + (fun y => binDiagonalMass_integrable G hloc p o n K y x) + (fun ω y hy => binDiagonalMass_outside_column G o n K ω y x (by simpa only [Set.Finite.mem_toFinset] using hy)) + +theorem integral_binDiagonalLoss (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (p : unitInterval) (n : ℕ) (K : V → V → ℝ) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) : + (∫ ω, binSizeMass G n ω (root i₀)^2 * + ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K (root i₀) z ∂law p) = + ∫ ω, binSizeMass G n ω (root i₀)^2 / (binOrbitClass G (root i₀) n ω (root i₀)).card * + ∑ y ∈ binOrbitClass G (root i₀) n ω (root i₀), + ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K y z ∂law p := by + have hr (x : V) : Summable (binDiagonalKernel G p (root i₀) n K x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) + intro y hy + simp only [binDiagonalKernel,binDiagonalMass_outside G (root i₀) n K _ x y + (by simpa only [Set.Finite.mem_toFinset] using hy),integral_zero] + have hc (y : V) : Summable (fun x => binDiagonalKernel G p (root i₀) n K x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y (2*n)).toFinset) + intro x hx + simp only [binDiagonalKernel,binDiagonalMass_outside_column G (root i₀) n K _ x y + (by simpa only [Set.Finite.mem_toFinset] using hx),integral_zero] + have ht := orbit_kernel_column_eq_row G root weight Γ htr hΓ hw i₀ hw₀ + (binDiagonalKernel G p (root i₀) n K) + (fun a b hab x y => binDiagonalKernel_covariant G hloc p (root i₀) n K hab (hcov a b hab) x y) + (fun x y hx => by simp only [binDiagonalKernel,binDiagonalMass_row_zero G _ n K _ x y hx,integral_zero]) + (fun x y hy => by simp only [binDiagonalKernel,binDiagonalMass_column_zero G _ n K _ x y hy,integral_zero]) + hr hc (root i₀) ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ + rw [binDiagonalKernel_row_integral G hloc,binDiagonalKernel_column_integral G hloc] at ht + simpa only [binDiagonalMass_column] using ht.symm + + + +theorem integral_binDiagonalLoss_le (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (p : unitInterval) (n : ℕ) (K : V → V → ℝ) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : + (∫ ω, binSizeMass G n ω (root i₀)^2 * + ∑ z ∈ binOrbitClass G (root i₀) n ω (root i₀), K (root i₀) z ∂law p) ≤ + ‖A‖ * ∫ ω, binSizeMass G n ω (root i₀)^2 ∂law p := by + rw [integral_binDiagonalLoss G hloc root weight Γ htr hΓ hw i₀ hw₀ p n K hcov] + have hi : Integrable (fun ω => ∑' y, binDiagonalMass G (root i₀) n K ω y (root i₀)) (law p) := by + have he (ω : Set E) : (∑' y, binDiagonalMass G (root i₀) n K ω y (root i₀)) = + ∑ y ∈ (finite_reachBall hloc (root i₀) (2*n)).toFinset, binDiagonalMass G (root i₀) n K ω y (root i₀) := by + apply tsum_eq_sum + intro y hy + exact binDiagonalMass_outside_column G (root i₀) n K ω y (root i₀) + (by simpa only [Set.Finite.mem_toFinset] using hy) + simp only [he] + exact integrable_finsetSum _ (fun y _ => binDiagonalMass_integrable G hloc p (root i₀) n K y (root i₀)) + have hs : Integrable (fun ω => binSizeMass G n ω (root i₀)^2) (law p) := + integrable_finite_local _ p _ (fun ω => congrArg (fun t : ℝ => t^2) (binSizeMass_local G hloc n ω (root i₀))) + rw [←integral_const_mul] + exact integral_mono (by simpa only [binDiagonalMass_column] using hi) (hs.const_mul ‖A‖) + (fun ω => by simpa only [binDiagonalMass_column] using binDiagonalMass_column_le G (root i₀) n K A hA ω (root i₀)) + +end BinDiagonalLoss +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DyadicDiagonalStrata +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def fullOrbitClass (G : BondGraph V E) (o : V) (ω : Set E) (x : V) : Finset V := + if h : (cluster G ω x).Finite then h.toFinset.filter (fun y => y ∈ vertexOrbit G o) else ∅ + +noncomputable def diagonalLossMass (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (ω : Set E) (x : V) : ℝ := + ((cluster G ω x).ncard:ℝ)^2 * ∑ z ∈ fullOrbitClass G o ω x, K x z + +theorem binSizeMass_zero (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) + (hw : ¬ ClusterWindow G x n (2*n) ω) : binSizeMass G n ω x = 0 := by + simp only [binSizeMass,binMass_zero_of_not_window G n ω x _ hw,tsum_zero] + +theorem binOrbitClass_eq_full (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) + (hx : x ∈ vertexOrbit G o) (hw : ClusterWindow G x n (2*n) ω) : + binOrbitClass G o n ω x = fullOrbitClass G o ω x := by + simp only [binOrbitClass,ite_eq_left hx,binClusterSlice,dite_eq_left hw,fullOrbitClass,dite_eq_left hw.1] + +theorem dyadic_window_iff (G : BondGraph V E) (ω : Set E) (x : V) (j : ℕ) + (hz : (cluster G ω x).ncard ≠ 0) : + ClusterWindow G x (2^j) (2*(2^j)) ω ↔ Nat.log 2 (cluster G ω x).ncard = j := by + constructor + · intro h + apply Nat.log_eq_of_pow_le_of_lt_pow h.2.1 + simpa only [pow_succ,Nat.mul_comm] using h.2.2 + · intro h + refine ⟨Set.finite_of_ncard_ne_zero hz,?_,?_⟩ + · rw [←h] + exact Nat.pow_log_le_self 2 hz + · rw [←h,show 2*2^(Nat.log 2 (cluster G ω x).ncard) = 2^(Nat.log 2 (cluster G ω x).ncard+1) by simp only [pow_succ,Nat.mul_comm]] + exact Nat.lt_pow_succ_log_self (by norm_num) _ + +theorem dyadic_binSizeMass_sq (G : BondGraph V E) (ω : Set E) (x : V) (j : ℕ) : + binSizeMass G (2^j) ω x ^ 2 = + if Nat.log 2 (cluster G ω x).ncard = j then ((cluster G ω x).ncard:ℝ)^2 else 0 := by + by_cases hz : (cluster G ω x).ncard = 0 + · have hw : ¬ClusterWindow G x (2^j) (2*(2^j)) ω := by + intro h + have hp : 0 < 2^j := pow_pos (by omega) _ + have hl := h.2.1 + omega + simp only [binSizeMass_zero G (2^j) ω x hw,hz,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0),ite_self] + · by_cases hw : ClusterWindow G x (2^j) (2*(2^j)) ω + · rw [binSizeMass_eq G (2^j) ω x hw,ite_eq_left ((dyadic_window_iff G ω x j hz).mp hw)] + · rw [binSizeMass_zero G (2^j) ω x hw,ite_eq_right (fun h => hw ((dyadic_window_iff G ω x j hz).mpr h))] + norm_num + +theorem dyadic_binDiagonalMass (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (ω : Set E) (x : V) (hx : x ∈ vertexOrbit G o) (j : ℕ) : + binSizeMass G (2^j) ω x ^ 2 * ∑ z ∈ binOrbitClass G o (2^j) ω x, K x z = + if Nat.log 2 (cluster G ω x).ncard = j then diagonalLossMass G o K ω x else 0 := by + by_cases hw : ClusterWindow G x (2^j) (2*(2^j)) ω + · have hz : (cluster G ω x).ncard ≠ 0 := by + have hp : 0 < 2^j := pow_pos (by omega) _ + have hl := hw.2.1 + omega + rw [ite_eq_left ((dyadic_window_iff G ω x j hz).mp hw),binOrbitClass_eq_full G o (2^j) ω x hx hw, + binSizeMass_eq G (2^j) ω x hw] + rfl + · rw [binSizeMass_zero G (2^j) ω x hw] + simp only [zero_pow (by omega : 2 ≠ 0),zero_mul] + by_cases hz : (cluster G ω x).ncard = 0 + · simp only [diagonalLossMass,hz,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0),zero_mul,ite_self] + · rw [ite_eq_right (fun h => hw ((dyadic_window_iff G ω x j hz).mpr h))] + +theorem diagonalLossMass_nonneg (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (hK : ∀ x y, 0 ≤ K x y) (ω : Set E) (x : V) : 0 ≤ diagonalLossMass G o K ω x := + mul_nonneg (sq_nonneg _) (Finset.sum_nonneg (fun z _ => hK x z)) + +theorem diagonalLossMass_le (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) (ω : Set E) (x : V) : + diagonalLossMass G o K ω x ≤ L*((cluster G ω x).ncard:ℝ)^2 := by + exact (mul_le_mul_of_nonneg_left (hrow x _) (sq_nonneg _)).trans_eq (mul_comm _ _) + +end DyadicDiagonalStrata +end Percolation + + +namespace Percolation +open MeasureTheory Filter +open scoped Topology +section DiscreteStratumIntegral +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem integral_le_of_discrete_strata {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (J : Ω → ℕ) (f g : Ω → ℝ) (C L : ℝ) + (hf0 : ∀ ω, 0 ≤ f ω) (hg0 : ∀ ω, 0 ≤ g ω) + (hfg : ∀ ω, f ω ≤ L*g ω) (hgi : Integrable g μ) + (hfi : ∀ j, Integrable (fun ω => if J ω = j then f ω else 0) μ) + (hgi' : ∀ j, Integrable (fun ω => if J ω = j then g ω else 0) μ) + (h : ∀ j, (∫ ω, (if J ω = j then f ω else 0) ∂μ) ≤ + C*(∫ ω, (if J ω = j then g ω else 0) ∂μ)) : + (∫ ω, f ω ∂μ) ≤ C*(∫ ω, g ω ∂μ) := by + let F : ℕ → Ω → ℝ := fun N ω => ∑ j ∈ Finset.range N, if J ω = j then f ω else 0 + let H : ℕ → Ω → ℝ := fun N ω => ∑ j ∈ Finset.range N, if J ω = j then g ω else 0 + have he (q : Ω → ℝ) (N : ℕ) (ω : Ω) : + (∑ j ∈ Finset.range N, if J ω = j then q ω else 0) = if J ω < N then q ω else 0 := by + simp only [Finset.sum_ite_eq,Finset.mem_range] + have hFi (N : ℕ) : Integrable (F N) μ := integrable_finsetSum _ (fun j _ => hfi j) + have hHi (N : ℕ) : Integrable (H N) μ := integrable_finsetSum _ (fun j _ => hgi' j) + have hFbody (N : ℕ) (ω : Ω) : ‖F N ω‖ ≤ L*g ω := by + dsimp [F] + rw [he] + split_ifs + · simpa only [Real.norm_eq_abs,abs_of_nonneg (hf0 ω)] using hfg ω + · simpa only [norm_zero,abs_zero] using (hf0 ω).trans (hfg ω) + have hHbody (N : ℕ) (ω : Ω) : ‖H N ω‖ ≤ g ω := by + dsimp [H] + rw [he] + split_ifs + · simp only [abs_of_nonneg (hg0 ω),le_refl] + · simpa only [norm_zero,abs_zero] using hg0 ω + have ht (q : Ω → ℝ) (ω : Ω) : Tendsto + (fun N => ∑ j ∈ Finset.range N, if J ω = j then q ω else 0) atTop (𝓝 (q ω)) := by + have he' : (fun N => ∑ j ∈ Finset.range N, if J ω = j then q ω else 0) =ᶠ[atTop] (fun _ => q ω) := by + filter_upwards [eventually_ge_atTop (J ω+1)] with N hN + rw [he,ite_eq_left (by omega)] + exact tendsto_const_nhds.congr' he'.symm + have htF := tendsto_integral_of_dominated_convergence (fun ω => L*g ω) + (fun N => (hFi N).aestronglyMeasurable) (hgi.const_mul L) + (fun N => Eventually.of_forall (hFbody N)) (Eventually.of_forall (ht f)) + have htH := tendsto_integral_of_dominated_convergence g + (fun N => (hHi N).aestronglyMeasurable) hgi + (fun N => Eventually.of_forall (hHbody N)) (Eventually.of_forall (ht g)) + apply le_of_tendsto_of_tendsto htF (tendsto_const_nhds.mul htH) + exact Eventually.of_forall (fun N => by + change (∫ ω, F N ω ∂μ) ≤ C*(∫ ω, H N ω ∂μ) + simp only [F,H,integral_finsetSum _ (fun j _ => hfi j), + integral_finsetSum _ (fun j _ => hgi' j),Finset.mul_sum] + exact Finset.sum_le_sum (fun j _ => h j)) + +end DiscreteStratumIntegral +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DiagonalLoss +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem integral_diagonalLoss_le (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (p : unitInterval) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) + (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) + (hs : Integrable (fun ω => ((cluster G ω (root i₀)).ncard:ℝ)^2) (law p)) : + (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ + ‖A‖*(∫ ω, ((cluster G ω (root i₀)).ncard:ℝ)^2 ∂law p) := by + have hx : root i₀ ∈ vertexOrbit G (root i₀) := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ + have hs' (j : ℕ) : Integrable (fun ω => binSizeMass G (2^j) ω (root i₀)^2) (law p) := + integrable_finite_local _ p _ (fun ω => congrArg (fun t : ℝ => t^2) + (binSizeMass_local G hloc (2^j) ω (root i₀))) + have hf' (j : ℕ) : Integrable (fun ω => binSizeMass G (2^j) ω (root i₀)^2 * + ∑ z ∈ binOrbitClass G (root i₀) (2^j) ω (root i₀), K (root i₀) z) (law p) := by + apply integrable_finite_local _ p _ + intro ω + rw [binOrbitClass_local G hloc (root i₀) (2^j) ω (root i₀),binSizeMass_local G hloc (2^j) ω (root i₀)] + apply integral_le_of_discrete_strata (law p) (fun ω => Nat.log 2 (cluster G ω (root i₀)).ncard) + (fun ω => diagonalLossMass G (root i₀) K ω (root i₀)) + (fun ω => ((cluster G ω (root i₀)).ncard:ℝ)^2) ‖A‖ L + (fun ω => diagonalLossMass_nonneg G (root i₀) K hK ω (root i₀)) + (fun _ => sq_nonneg _) (fun ω => diagonalLossMass_le G (root i₀) K L hrow ω (root i₀)) hs + · intro j + simpa only [dyadic_binDiagonalMass G (root i₀) K _ (root i₀) hx] using hf' j + · intro j + simpa only [dyadic_binSizeMass_sq] using hs' j + · intro j + have h := integral_binDiagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p (2^j) K hcov A hA + simp only [dyadic_binDiagonalMass G (root i₀) K _ (root i₀) hx] at h + simpa only [dyadic_binSizeMass_sq] using h + + + +theorem subcritical_diagonalLoss_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (p : unitInterval) (hp : p < pc G) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (K : V → V → ℝ), (∀ x y, 0 ≤ K x y) → + (∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) → + ∀ (L : ℝ), (∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) → + ∀ (A : Hilbert V →L[ℂ] Hilbert V), + (∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) → + (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ ‖A‖*C^3 := by + obtain ⟨C,hC,hs⟩ := subcritical_second_moment G hloc hqt p hp + refine ⟨C,hC,fun K hK hcov L hrow A hA => ?_⟩ + exact (integral_diagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p K hK hcov L hrow A hA + (hs (root i₀)).1).trans (mul_le_mul_of_nonneg_left (hs (root i₀)).2 (norm_nonneg _)) + +end DiagonalLoss +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section RootSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem second_moment_le_rootSusceptibility_cube [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (x : V) : + (∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p) ≤ + (c*rootSusceptibility G root weight p)^3 := by + let C := c*rootSusceptibility G root weight p + have hC : 0 ≤ C := mul_nonneg hc (rootSusceptibility_nonneg G root weight hw p) + have hrow (z : V) : (∑' y, law p {ω | Conn G ω z y}) ≤ ENNReal.ofReal C := by + rw [←ennreal_susceptibility G hloc hqt p hp] + exact ENNReal.ofReal_le_ofReal (susceptibility_le_rootSusceptibility G root weight hw hcov c hc hmin p z) + have hm : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^2) := + (measurable_of_countable (fun n : ℕ => (n:ℝ)^2)).comp (measurable_cluster_ncard G hloc x) + have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)^2) := + Filter.Eventually.of_forall (fun _ => sq_nonneg _) + have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2)) =ᵐ[law p] + (fun ω => clusterMass G ω x ^ 2) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_pow (Nat.cast_nonneg _)] + simp only [ENNReal.ofReal_natCast] + have hbound : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2) ∂law p) ≤ ENNReal.ofReal (C^3) := by + rw [lintegral_congr_ae he,ENNReal.ofReal_pow hC] + exact cluster_second_moment_bound G p _ hrow x + rw [integral_eq_lintegral_of_nonneg_ae hn hm.aestronglyMeasurable] + exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hbound).trans_eq (ENNReal.toReal_ofReal (pow_nonneg hC _)) + +theorem diagonalLoss_le_rootSusceptibility_cube [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) + (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : + (∫ ω, diagonalLossMass G (root i₀) K ω (root i₀) ∂law p) ≤ + ‖A‖*(c*rootSusceptibility G root weight p)^3 := by + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + exact (integral_diagonalLoss_le G hloc root weight Γ htr hΓ hw i₀ hw₀ p K hK hcov L hrow A hA + (hs (root i₀)).1).trans (mul_le_mul_of_nonneg_left + (second_moment_le_rootSusceptibility_cube G hloc hqt root weight hw hcover c hc hmin p hp (root i₀)) + (norm_nonneg _)) + +end RootSecondMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DiagonalSeries +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def diagonalLossTerm (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (x y : V) (ω : Set E) : ℝ := + if y ∈ vertexOrbit G o ∧ Conn G ω x y then K x y*((cluster G ω x).ncard:ℝ)^2 else 0 + +theorem diagonalLossTerm_nonneg (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (hK : ∀ x y, 0 ≤ K x y) (x y : V) (ω : Set E) : + 0 ≤ diagonalLossTerm G o K x y ω := by + unfold diagonalLossTerm + split_ifs + · exact mul_nonneg (hK x y) (sq_nonneg _) + · exact le_rfl + +theorem diagonalLossTerm_le (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (hK : ∀ x y, 0 ≤ K x y) (x y : V) (ω : Set E) : + diagonalLossTerm G o K x y ω ≤ K x y*((cluster G ω x).ncard:ℝ)^2 := by + unfold diagonalLossTerm + split_ifs + · exact le_rfl + · exact mul_nonneg (hK x y) (sq_nonneg _) + +theorem diagonalLossMass_eq_tsum (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (x : V) (ω : Set E) : + diagonalLossMass G o K ω x = ∑' y, diagonalLossTerm G o K x y ω := by + by_cases hf : (cluster G ω x).Finite + · let S := fullOrbitClass G o ω x + have hs (y : V) : y ∈ S ↔ y ∈ vertexOrbit G o ∧ Conn G ω x y := by + dsimp only [S,fullOrbitClass] + rw [dite_eq_left hf] + simp only [Finset.mem_filter,Set.Finite.mem_toFinset,cluster,Set.mem_ofPred_eq] + exact and_comm + rw [tsum_eq_sum (s := S) (fun y hy => by + simp only [diagonalLossTerm,ite_eq_right (fun h => hy ((hs y).mpr h))])] + rw [diagonalLossMass,Finset.mul_sum] + apply Finset.sum_congr rfl + intro y hy + rw [diagonalLossTerm,ite_eq_left ((hs y).mp hy),mul_comm] + · have hn := Set.Infinite.ncard hf + simp only [diagonalLossMass,diagonalLossTerm,hn,Nat.cast_zero,zero_pow (by omega : 2 ≠ 0), + mul_zero,zero_mul,ite_self,tsum_zero] + +theorem integrable_diagonalLossTerm [Countable V] [Countable E] (G : BondGraph V E) (o : V) (K : V → V → ℝ) + (x y : V) (p : unitInterval) + (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : + Integrable (diagonalLossTerm G o K x y) (law p) := by + by_cases hy : y ∈ vertexOrbit G o + · convert (hs.indicator (measurableSet_conn G x y)).const_mul (K x y) using 1 + ext ω + simp only [diagonalLossTerm,hy,true_and,Set.indicator,Set.mem_ofPred_eq] + split_ifs <;> simp only [mul_zero] + · have he : diagonalLossTerm G o K x y = (fun _ : Set E => (0:ℝ)) := by + funext ω + simp only [diagonalLossTerm,hy,false_and,ite_false] + rw [he] + exact integrable_const 0 + + + +theorem integral_diagonalLoss_eq_series [Countable V] [Countable E] + (G : BondGraph V E) (o : V) (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) + (L : ℝ) (hrow : ∀ x (S : Finset V), (∑ z ∈ S, K x z) ≤ L) + (x : V) (p : unitInterval) + (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : + (∫ ω, diagonalLossMass G o K ω x ∂law p) = + ∑' y, if y ∈ vertexOrbit G o then + K x y*(∫ ω, (if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) ∂law p) else 0 := by + have hi (y : V) := integrable_diagonalLossTerm G o K x y p hs + have hzero (y : V) (ω : Set E) := diagonalLossTerm_nonneg G o K hK x y ω + have hn : Summable (fun y => ∫ ω, ‖diagonalLossTerm G o K x y ω‖ ∂law p) := by + simp only [Real.norm_of_nonneg (hzero _ _)] + apply summable_of_sum_le (fun y => integral_nonneg (hzero y)) (c := L*(∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p)) + intro S + rw [←integral_finsetSum _ (fun y _ => hi y),←integral_const_mul] + apply integral_mono (integrable_finsetSum _ (fun y _ => hi y)) (hs.const_mul L) + intro ω + calc + _ ≤ ∑ y ∈ S, K x y*((cluster G ω x).ncard:ℝ)^2 := + Finset.sum_le_sum (fun y _ => diagonalLossTerm_le G o K hK x y ω) + _ = (∑ y ∈ S, K x y)*((cluster G ω x).ncard:ℝ)^2 := (Finset.sum_mul ..).symm + _ ≤ _ := mul_le_mul_of_nonneg_right (hrow x S) (sq_nonneg _) + rw [show (fun ω => diagonalLossMass G o K ω x) = (fun ω => ∑' y, diagonalLossTerm G o K x y ω) from + funext (diagonalLossMass_eq_tsum G o K x)] + rw [←integral_tsum_of_summable_integral_norm hi hn] + apply tsum_congr + intro y + by_cases hy : y ∈ vertexOrbit G o + · simp only [diagonalLossTerm,hy,true_and,ite_true] + rw [←integral_const_mul] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by dsimp only; split_ifs <;> simp only [mul_zero]) + · simp only [diagonalLossTerm,hy,false_and,ite_false,integral_zero] + +end DiagonalSeries +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section RootSusceptibilityLower +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_rootSusceptibility_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (p₀ : ℝ) (hp₀ : 0 < p₀) : + ∃ a : ℝ, 0 < a ∧ ∀ (p : unitInterval), p₀ ≤ (p:ℝ) → p < pc G → ∀ x, + a*rootSusceptibility G root weight p ≤ susceptibility G p x := by + have hex (ij : ι × ι) : ∃ l : List E, Along G (root ij.1) l (root ij.2) := by + obtain ⟨l,hl,_,_⟩ := conn_exists_bond_trail G (conn_univ_of_connected G hconn (root ij.1) (root ij.2)) + exact ⟨l,hl⟩ + choose path hpath using hex + let N := ∑ ij : ι × ι, (path ij).length + have hlen (i j : ι) : (path (i,j)).length ≤ N := + Finset.single_le_sum (f := fun ij : ι × ι => (path ij).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ (i,j)) + refine ⟨p₀^N,pow_pos hp₀ N,fun p hp hpcrit x => ?_⟩ + obtain ⟨j,a,b,hab,hax⟩ := hcover x + have hfin (z : V) : Summable (fun y => (law p).real {ω | Conn G (ω ∩ Set.univ) z y}) := by + simp only [Set.inter_univ] + exact summable_twoPoint_subcritical G hloc hqt p hpcrit z + have heq (z : V) : restrictedSusceptibility G Set.univ p z = susceptibility G p z := by + simp only [restrictedSusceptibility,susceptibility,Set.inter_univ,twoPoint,Measure.real] + have hb (i : ι) : p₀^N*susceptibility G p (root i) ≤ susceptibility G p (root j) := by + have h := restrictedSusceptibility_path_lower G Set.univ p (hpath (j,i)) (fun _ _ => Set.mem_univ _) hfin + rw [heq,heq] at h + have hpow : p₀^N ≤ (p:ℝ)^(path (j,i)).length := + (pow_le_pow_left₀ hp₀.le hp N).trans (pow_le_pow_of_le_one p.2.1 p.2.2 (hlen j i)) + exact (mul_le_mul_of_nonneg_right hpow (susceptibility_nonneg G p _)).trans h + rw [←hax,susceptibility_aut G p hab] + calc + _ = ∑ i, weight i*(p₀^N*susceptibility G p (root i)) := by + simp only [rootSusceptibility,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ ∑ i, weight i*susceptibility G p (root j) := + Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hb i) (hw i)) + _ = susceptibility G p (root j) := by rw [←Finset.sum_mul,hw1,one_mul] + +end RootSusceptibilityLower +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ClusterAssociation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem association_finiteWitness_ennreal [Countable E] (p : unitInterval) + (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) + (hfA : FiniteWitness A) (hfB : FiniteWitness B) : + law p A * law p B ≤ law p (A ∩ B) := by + apply (ENNReal.toReal_le_toReal + (ENNReal.mul_ne_top (measure_ne_top _ _) (measure_ne_top _ _)) (measure_ne_top _ _)).mp + rw [ENNReal.toReal_mul] + exact association_finiteWitness p A B hA hB hfA hfB + +theorem clusterMass_mul (G : BondGraph V E) (ω : Set E) (x y : V) : + clusterMass G ω x * clusterMass G ω y = + ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b then (1:ℝ≥0∞) else 0 := by + rw [clusterMass,clusterMass,←ENNReal.tsum_mul_right] + apply tsum_congr + intro a + rw [←ENNReal.tsum_mul_left] + apply tsum_congr + intro b + split_ifs <;> simp_all + +theorem lintegral_clusterMass_mul [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y : V) : + (∫⁻ ω, clusterMass G ω x * clusterMass G ω y ∂law p) = + ∑' a, ∑' b, law p {ω | Conn G ω x a ∧ Conn G ω y b} := by + have hm (a b : V) : Measurable (fun ω : Set E => if Conn G ω x a ∧ Conn G ω y b then (1:ℝ≥0∞) else 0) := + Measurable.ite ((measurableSet_conn G x a).inter (measurableSet_conn G y b)) measurable_const measurable_const + simp_rw [clusterMass_mul] + rw [lintegral_tsum (fun a => (Measurable.tsum (fun b => hm a b)).aemeasurable)] + apply tsum_congr + intro a + rw [lintegral_tsum (fun b => (hm a b).aemeasurable)] + apply tsum_congr + intro b + have hs : MeasurableSet {ω : Set E | Conn G ω x a ∧ Conn G ω y b} := + (measurableSet_conn G x a).inter (measurableSet_conn G y b) + simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) hs) + +theorem clusterMass_association [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y : V) : + (∑' a, law p {ω | Conn G ω x a})*(∑' b, law p {ω | Conn G ω y b}) ≤ + ∫⁻ ω, clusterMass G ω x * clusterMass G ω y ∂law p := by + rw [lintegral_clusterMass_mul,←ENNReal.tsum_mul_right] + apply ENNReal.tsum_le_tsum + intro a + rw [←ENNReal.tsum_mul_left] + apply ENNReal.tsum_le_tsum + intro b + exact association_finiteWitness_ennreal p _ _ + (fun _ _ hω hc => conn_mono G hω hc) (fun _ _ hω hc => conn_mono G hω hc) + (finiteWitness_conn G x a) (finiteWitness_conn G y b) + + + +theorem subcritical_cluster_association [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) (law p) ∧ + susceptibility G p x * susceptibility G p y ≤ + ∫ ω, ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) ∂law p := by + have hm (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := + (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) + have hn (ω : Set E) : 0 ≤ ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) := + mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + obtain ⟨_,_,hsecond⟩ := subcritical_second_moment G hloc hqt p hp + have hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) (law p) := by + apply ((hsecond x).1.add (hsecond y).1).mono' ((hm x).mul (hm y)).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun ω => by + dsimp only [Pi.mul_apply,Pi.add_apply] + rw [Real.norm_of_nonneg (hn ω)] + nlinarith [sq_nonneg (((cluster G ω x).ncard:ℝ)-((cluster G ω y).ncard:ℝ))]) + refine ⟨hi,?_⟩ + have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ))) =ᵐ[law p] + (fun ω => clusterMass G ω x * clusterMass G ω y) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy + rw [clusterMass_eq_ncard G ω x hx,clusterMass_eq_ncard G ω y hy,ENNReal.ofReal_mul (Nat.cast_nonneg _)] + simp only [ENNReal.ofReal_natCast] + have hb : ENNReal.ofReal (susceptibility G p x * susceptibility G p y) ≤ + ∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) ∂law p := by + rw [lintegral_congr_ae he,ENNReal.ofReal_mul (susceptibility_nonneg G p x), + ennreal_susceptibility G hloc hqt p hp,ennreal_susceptibility G hloc hqt p hp] + exact clusterMass_association G p x y + have htop : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) ∂law p) ≠ ⊤ := + ne_of_lt ((hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hn)).mp hi.hasFiniteIntegral) + rw [integral_eq_lintegral_of_nonneg_ae (Filter.Eventually.of_forall hn) hi.aestronglyMeasurable] + simpa only [ENNReal.toReal_ofReal (mul_nonneg (susceptibility_nonneg G p x) (susceptibility_nonneg G p y))] using + ENNReal.toReal_mono htop hb + +end ClusterAssociation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteLocalIndependence +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integral_mul_finite_local (I R : Finset E) (hdis : Disjoint I R) + (p : unitInterval) (f g : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (I:Set E))) + (hg : ∀ ω, g ω = g (ω ∩ (R:Set E))) : + (∫ ω, f ω*g ω ∂law p) = (∫ ω, f ω ∂law p)*(∫ ω, g ω ∂law p) := by + have hf' := finite_local_of_subset I (I∪R) Finset.subset_union_left f hf + have hg' := finite_local_of_subset R (I∪R) Finset.subset_union_right g hg + rw [integral_eq_bernoulliPolynomial (I∪R) p _ (fun ω => by rw [hf' ω,hg' ω]), + integral_eq_bernoulliPolynomial I p f hf,integral_eq_bernoulliPolynomial R p g hg, + bernoulliPolynomial_union I R hdis] + have hi (a b : Finset E) (ha : a ⊆ I) (hb : b ⊆ R) : + ((a ∪ b : Finset E):Set E) ∩ (I:Set E) = a := by + ext e + simp only [Finset.coe_union,Set.mem_inter_iff,Set.mem_union,Finset.mem_coe] + constructor + · rintro ⟨he,hI⟩ + rcases he with he | he + · exact he + · exact ((Finset.disjoint_left.mp hdis) hI (hb he)).elim + · intro he + exact ⟨Or.inl he,ha he⟩ + have hr (a b : Finset E) (ha : a ⊆ I) (hb : b ⊆ R) : + ((a ∪ b : Finset E):Set E) ∩ (R:Set E) = b := by + ext e + simp only [Finset.coe_union,Set.mem_inter_iff,Set.mem_union,Finset.mem_coe] + constructor + · rintro ⟨he,hR⟩ + rcases he with he | he + · exact ((Finset.disjoint_left.mp hdis) (ha he) hR).elim + · exact he + · intro he + exact ⟨Or.inr he,hb he⟩ + trans bernoulliPolynomial I (fun a => f a*bernoulliPolynomial R (fun b => g b) p) p + · apply bernoulliPolynomial_congr + intro a ha + rw [←bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro b hb + rw [hf ((a∪b : Finset E):Set E),hg ((a∪b : Finset E):Set E),hi a b ha hb,hr a b ha hb] + · exact bernoulliPolynomial_mul_const I _ _ p + +theorem complement_incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) : + ((incidentSupport G hloc W:Set E))ᶜ = internalEdges G (W:Set V)ᶜ := by + ext e + simp only [Set.mem_compl_iff,Finset.mem_coe,mem_incidentSupport,internalEdges,Set.mem_ofPred_eq] + push Not + constructor + · intro h x hx hxW + exact h x hxW hx + · intro h x hxW hx + exact h x hx hxW + + + +theorem cluster_restrict_incident_eq_iff (G : BondGraph V E) (hloc : LocallyFinite G) + (W : Finset V) (Q : Finset E) (hQ : incidentSupport G hloc W ⊆ Q) + (ω : Set E) (x : V) : + cluster G (ω ∩ (Q:Set E)) x = (W:Set V) ↔ cluster G ω x = W := by + have ho : ω \ (Q:Set E) ⊆ internalEdges G (W:Set V)ᶜ := by + rw [←complement_incidentSupport G hloc W] + exact fun _ h => fun he => h.2 (hQ he) + have h := cluster_union_external_eq_iff G (ω ∩ (Q:Set E)) (ω \ (Q:Set E)) x W ho + simpa only [Set.inter_union_sdiff] using h.symm + +theorem measurableSet_cluster_eq [Countable V] [Countable E] + (G : BondGraph V E) (x : V) (W : Set V) : MeasurableSet {ω : Set E | cluster G ω x = W} := by + have he : {ω : Set E | cluster G ω x = W} = ⋂ y, {ω : Set E | Conn G ω x y ↔ y ∈ W} := by + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_iInter,Set.ext_iff,cluster] + rw [he] + apply MeasurableSet.iInter + intro y + by_cases hy : y ∈ W + · simpa only [hy,iff_true] using measurableSet_conn G x y + · simpa only [hy,iff_false,Set.compl_ofPred] using (measurableSet_conn G x y).compl + + + +theorem cluster_cell_finite_exterior_independence [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) (x : V) + (R : Finset E) (hR : (R:Set E) ⊆ internalEdges G (W:Set V)ᶜ) + (p : unitInterval) (f : Set E → ℝ) (hf : ∀ ω, f ω = f (ω ∩ (R:Set E))) : + (∫ ω, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)*f ω ∂law p) = + (law p).real {ω | cluster G ω x = (W:Set V)} * (∫ ω, f ω ∂law p) := by + have hdis : Disjoint (incidentSupport G hloc W) R := by + rw [←complement_incidentSupport G hloc W] at hR + exact Finset.disjoint_left.mpr (fun e he h => hR h he) + have hc (ω : Set E) : + (if cluster G ω x = (W:Set V) then (1:ℝ) else 0) = + (if cluster G (ω ∩ (incidentSupport G hloc W:Set E)) x = (W:Set V) then 1 else 0) := by + simp only [cluster_restrict_incident_eq_iff G hloc W _ (by rfl)] + rw [integral_mul_finite_local _ R hdis p _ f hc hf] + congr 1 + have hm : MeasurableSet {ω : Set E | cluster G ω x = (W:Set V)} := measurableSet_cluster_eq G x W + simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using integral_indicator_one hm + +end FiniteLocalIndependence + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped Topology +section ExteriorConnectionIndependence +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurableSet_restrictedConn [Countable E] (G : BondGraph V E) + (S : Set E) (x y : V) : MeasurableSet {ω : Set E | Conn G (ω ∩ S) x y} := + measurableSet_finiteWitness _ + (fun _ _ hω hc => conn_mono G (Set.inter_subset_inter_left _ hω) hc) + (finiteWitness_inter _ (finiteWitness_conn G x y) S) + +theorem integral_event_indicator (p : unitInterval) (A : Set (Set E)) (hA : MeasurableSet A) : + (∫ ω, (if ω ∈ A then (1:ℝ) else 0) ∂law p) = (law p).real A := by + simpa only [Set.indicator,Pi.one_apply] using (integral_indicator_one (μ := law p) hA) + + + +theorem cluster_cell_exterior_connection_independent [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) + (x y z : V) (p : unitInterval) : + (law p).real {ω | cluster G ω x = (W:Set V) ∧ Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} = + (law p).real {ω | cluster G ω x = (W:Set V)} * + (law p).real {ω | Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} := by + let := Encodable.ofCountable E + let S := internalEdges G (W:Set V)ᶜ + let R := restrictedBondExhaustion S ∅ + have hmono : Monotone R := restrictedBondExhaustion_mono S ∅ + have hsub (n : ℕ) : (R n:Set E) ⊆ S := restrictedBondExhaustion_subset S ∅ (by simp) n + have hcover (e : E) (he : e ∈ S) : ∃ n, e ∈ R n := restrictedBondExhaustion_cover S ∅ e he + let A : Set (Set E) := {ω | cluster G ω x = (W:Set V)} + let B (n : ℕ) : Set (Set E) := {ω | Conn G (ω ∩ (R n:Set E)) y z} + let Btop : Set (Set E) := {ω | Conn G (ω ∩ S) y z} + have hB : Monotone B := fun n m h ω hc => + conn_mono G (Set.inter_subset_inter_right _ (show (R n:Set E) ⊆ (R m:Set E) from hmono h)) hc + have hu : (⋃ n, B n) = Btop := by + ext ω + simp only [B,Btop,Set.mem_iUnion,Set.mem_ofPred_eq] + exact ⟨fun ⟨n,hn⟩ => conn_mono G (Set.inter_subset_inter_right _ (hsub n)) hn, + conn_finite_exhaustion G S R hmono hcover⟩ + have huA : (⋃ n, A ∩ B n) = A ∩ Btop := by rw [←Set.inter_iUnion,hu] + have htB := tendsto_measure_iUnion_atTop (μ := law p) hB + have htA := tendsto_measure_iUnion_atTop (μ := law p) + (show Monotone (fun n => A ∩ B n) from fun _ _ h => Set.inter_subset_inter_right _ (hB h)) + rw [hu] at htB + rw [huA] at htA + have htB' := (ENNReal.tendsto_toReal (measure_ne_top (law p) Btop)).comp htB + have htA' := (ENNReal.tendsto_toReal (measure_ne_top (law p) (A∩Btop))).comp htA + have he (n : ℕ) : (law p).real (A ∩ B n) = (law p).real A * (law p).real (B n) := by + have h := cluster_cell_finite_exterior_independence G hloc W x (R n) (hsub n) p + (fun ω => if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) + (fun ω => by rw [Set.inter_assoc,Set.inter_self]) + have hf : (∫ ω, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)* + (if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) ∂law p) = (law p).real (A ∩ B n) := by + rw [←integral_event_indicator p (A∩B n) + ((measurableSet_cluster_eq G x W).inter (measurableSet_restrictedConn G _ y z))] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + dsimp only [A,B,Set.mem_inter_iff,Set.mem_ofPred_eq] + split_ifs <;> simp_all) + rw [hf] at h + rw [show (∫ ω, (if Conn G (ω ∩ (R n:Set E)) y z then (1:ℝ) else 0) ∂law p) = + (law p).real (B n) from integral_event_indicator p (B n) (measurableSet_restrictedConn G _ y z)] at h + exact h + exact tendsto_nhds_unique htA' ((tendsto_const_nhds.mul htB').congr (fun n => (he n).symm)) + +end ExteriorConnectionIndependence +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExposedClusterGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem conn_exterior_of_cluster_eq (G : BondGraph V E) (ω : Set E) + (x y z : V) (W : Set V) (hW : cluster G ω x = W) (hy : y ∉ W) : + Conn G (ω ∩ internalEdges G Wᶜ) y z ↔ Conn G ω y z := by + refine ⟨conn_mono G Set.inter_subset_left,fun h => ?_⟩ + have hout (a : V) (ha : Conn G ω y a) : a ∉ W := by + intro haW + have hxa : Conn G ω x a := by change a ∈ cluster G ω x; rwa [hW] + exact hy (hW ▸ (hxa.trans (conn_symm G _ ha) : y ∈ cluster G ω x)) + induction h with + | refl => exact conn_refl G _ y + | @tail a b hya hab ih => + obtain ⟨e,he,heq⟩ := hab + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G Wᶜ e a b heq).mpr + ⟨hout a hya,hout b (hya.tail ⟨e,he,heq⟩)⟩⟩,heq⟩ + +theorem cluster_size_eq_tsum_real (G : BondGraph V E) (ω : Set E) (y : V) + (hf : (cluster G ω y).Finite) : + ((cluster G ω y).ncard:ℝ) = ∑' z, if Conn G ω y z then (1:ℝ) else 0 := by + rw [tsum_eq_sum (s := hf.toFinset) (fun z hz => by + exact ite_eq_right (fun hc => hz (hf.mem_toFinset.mpr hc)))] + rw [show (∑ z ∈ hf.toFinset, if Conn G ω y z then (1:ℝ) else 0) = + ∑ _z ∈ hf.toFinset, (1:ℝ) from Finset.sum_congr rfl (fun z hz => ite_eq_left (hf.mem_toFinset.mp hz))] + simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] + + + +theorem integral_cluster_size_event [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (y : V) (A : Set (Set E)) (hA : MeasurableSet A) : + (∫ ω, (if ω ∈ A then ((cluster G ω y).ncard:ℝ) else 0) ∂law p) = + ∑' z, (law p).real {ω | ω ∈ A ∧ Conn G ω y z} := by + let f (z : V) (ω : Set E) : ℝ := if ω ∈ A ∧ Conn G ω y z then 1 else 0 + have hm (z : V) : MeasurableSet {ω : Set E | ω ∈ A ∧ Conn G ω y z} := + hA.inter (measurableSet_conn G y z) + have hf (z : V) : f z = {ω : Set E | ω ∈ A ∧ Conn G ω y z}.indicator (fun _ => (1:ℝ)) := by + funext ω + simp only [f,Set.indicator,Set.mem_ofPred_eq] + have hi (z : V) : Integrable (f z) (law p) := by + rw [hf] + exact (integrable_const (1:ℝ)).indicator (hm z) + have hn (z : V) (ω : Set E) : 0 ≤ f z ω := by unfold f; split_ifs <;> norm_num + have he (z : V) : (∫ ω, f z ω ∂law p) = (law p).real {ω | ω ∈ A ∧ Conn G ω y z} := by + rw [hf] + exact integral_indicator_one (hm z) + have hint : Summable (fun z => ∫ ω, ‖f z ω‖ ∂law p) := by + simp_rw [Real.norm_of_nonneg (hn _ _),he] + apply (summable_twoPoint_subcritical G hloc hqt p hp y).of_nonneg_of_le + · exact fun _ => ENNReal.toReal_nonneg + · intro z + exact ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (fun ω h => h.2)) + calc + _ = ∫ ω, ∑' z, f z ω ∂law p := by + apply integral_congr_ae + filter_upwards [subcritical_cluster_finite_ae G p hp y] with ω hω + by_cases hωA : ω ∈ A + · simp only [hωA,ite_true,f,true_and] + exact cluster_size_eq_tsum_real G ω y hω + · simp only [hωA,ite_false,f,false_and,tsum_zero] + _ = ∑' z, ∫ ω, f z ω ∂law p := (integral_tsum_of_summable_integral_norm hi hint).symm + _ = _ := tsum_congr he + +end ExposedClusterGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExteriorCellSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem cluster_cell_exterior_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (W : Finset V) (x y : V) : + (∫ ω, (if cluster G ω x = (W:Set V) ∧ ¬Conn G ω x y + then ((cluster G ω y).ncard:ℝ) else 0) ∂law p) = + (law p).real {ω | cluster G ω x = (W:Set V)} * + inducedSusceptibility G (W:Set V)ᶜ p y := by + by_cases hy : y ∈ (W:Set V) + · rw [inducedSusceptibility,ite_eq_right (fun h => h hy),mul_zero] + calc + _ = ∫ _ω : Set E, (0:ℝ) ∂law p := by + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + dsimp only + split_ifs with h + · have hc : Conn G ω x y := by change y ∈ cluster G ω x; rwa [h.1] + exact (h.2 hc).elim + · rfl) + _ = 0 := integral_zero _ _ + · simp only [inducedSusceptibility,Set.mem_compl_iff,hy,not_false_eq_true,ite_true] + calc + _ = ∫ ω, (if cluster G ω x = (W:Set V) then ((cluster G ω y).ncard:ℝ) else 0) ∂law p := by + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + dsimp only + by_cases hc : cluster G ω x = (W:Set V) + · have hnc : ¬Conn G ω x y := by intro h; exact hy (hc ▸ h) + simp [hc,hnc] + · simp only [hc,false_and,ite_false]) + _ = ∑' z, (law p).real {ω | cluster G ω x = (W:Set V) ∧ Conn G ω y z} := + integral_cluster_size_event G hloc hqt p hp y _ (measurableSet_cluster_eq G x W) + _ = ∑' z, (law p).real {ω | cluster G ω x = (W:Set V)} * + (law p).real {ω | Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} := by + apply tsum_congr + intro z + rw [show {ω : Set E | cluster G ω x = (W:Set V) ∧ Conn G ω y z} = + {ω | cluster G ω x = (W:Set V) ∧ Conn G (ω ∩ internalEdges G (W:Set V)ᶜ) y z} from by + ext ω + exact ⟨fun h => ⟨h.1,(conn_exterior_of_cluster_eq G ω x y z W h.1 hy).mpr h.2⟩, + fun h => ⟨h.1,conn_mono G Set.inter_subset_left h.2⟩⟩] + exact cluster_cell_exterior_connection_independent G hloc W x y z p + _ = _ := tsum_mul_left + +theorem restrictedSusceptibility_le_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (S : Set E) (y : V) : + restrictedSusceptibility G S p y ≤ susceptibility G p y := by + apply Summable.tsum_le_tsum _ (summable_restrictedTwoPoint G hloc hqt p hp S y) + (summable_twoPoint_subcritical G hloc hqt p hp y) + exact fun z => ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono (fun ω hc => conn_mono G Set.inter_subset_left hc)) + +theorem inducedSusceptibility_le_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (D : Set V) (y : V) : + inducedSusceptibility G D p y ≤ susceptibility G p y := by + unfold inducedSusceptibility + split_ifs + · exact restrictedSusceptibility_le_susceptibility G hloc hqt p hp _ y + · exact susceptibility_nonneg G p y + +end ExteriorCellSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterPartition +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem tsum_cluster_cells (G : BondGraph V E) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) (a : ℝ) : + (∑' W : Finset V, if cluster G ω x = (W:Set V) then a else 0) = a := by + let W := hf.toFinset + have hW : cluster G ω x = (W:Set V) := hf.coe_toFinset.symm + rw [tsum_eq_single W (fun U hU => ite_eq_right (fun h => hU (Finset.coe_injective (h.symm.trans hW)))),ite_eq_left hW] + + + +theorem integral_cluster_finite_partition [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (x : V) + (f : Set E → ℝ) (hf : Integrable f (law p)) : + (∫ ω, f ω ∂law p) = ∑' W : Finset V, + ∫ ω, (if cluster G ω x = (W:Set V) then f ω else 0) ∂law p := by + let F (W : Finset V) (ω : Set E) := if cluster G ω x = (W:Set V) then f ω else 0 + have hi (W : Finset V) : Integrable (F W) (law p) := by + have he : F W = {ω : Set E | cluster G ω x = (W:Set V)}.indicator f := by + funext ω + simp only [F,Set.indicator,Set.mem_ofPred_eq] + split_ifs <;> rfl + rw [he] + exact hf.indicator (measurableSet_cluster_eq G x W) + have hb (S : Finset (Finset V)) (ω : Set E) : (∑ W ∈ S, ‖F W ω‖) ≤ ‖f ω‖ := by + by_cases hex : ∃ W ∈ S, cluster G ω x = (W:Set V) + · obtain ⟨W,hWS,hW⟩ := hex + rw [Finset.sum_eq_single W] + · simp only [F,hW,ite_true,le_refl] + · intro U _ hU + have hu : cluster G ω x ≠ (U:Set V) := fun h => hU (Finset.coe_injective (h.symm.trans hW)) + simp only [F,ite_eq_right hu,norm_zero] + · exact fun h => (h hWS).elim + · have he (W : Finset V) (hW : W ∈ S) : cluster G ω x ≠ (W:Set V) := fun h => hex ⟨W,hW,h⟩ + calc + _ = 0 := Finset.sum_eq_zero (fun W hW => by simp only [F,ite_eq_right (he W hW),norm_zero]) + _ ≤ _ := norm_nonneg _ + have hn : Summable (fun W => ∫ ω, ‖F W ω‖ ∂law p) := by + apply summable_of_sum_le (fun _ => integral_nonneg (fun _ => norm_nonneg _)) + (c := ∫ ω, ‖f ω‖ ∂law p) + intro S + rw [←integral_finsetSum _ (fun W _ => (hi W).norm)] + exact integral_mono (integrable_finsetSum _ (fun W _ => (hi W).norm)) hf.norm (hb S) + calc + _ = ∫ ω, ∑' W : Finset V, F W ω ∂law p := by + apply integral_congr_ae + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact (tsum_cluster_cells G ω x hω (f ω)).symm + _ = _ := (integral_tsum_of_summable_integral_norm hi hn).symm + +end ClusterPartition +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FreshExteriorMoment +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def freshExteriorMoment (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) : ℝ := + ((cluster G ω x).ncard:ℝ) * inducedSusceptibility G (cluster G ω x)ᶜ p y + +theorem freshExteriorMoment_eq_tsum (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) : + freshExteriorMoment G p x y ω = ∑' W : Finset V, if cluster G ω x = (W:Set V) + then (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y else 0 := by + by_cases hf : (cluster G ω x).Finite + · let W := hf.toFinset + have hW : cluster G ω x = (W:Set V) := hf.coe_toFinset.symm + rw [tsum_eq_single W (fun U hU => ite_eq_right (fun h => hU (Finset.coe_injective (h.symm.trans hW)))),ite_eq_left hW] + simp only [freshExteriorMoment,hW,Set.ncard_coe_finset] + · have he (W : Finset V) : cluster G ω x ≠ (W:Set V) := fun h => hf (h ▸ W.finite_toSet) + simp only [freshExteriorMoment,Set.Infinite.ncard hf,Nat.cast_zero,zero_mul,ite_eq_right (he _),tsum_zero] + +theorem measurable_freshExteriorMoment [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y : V) : Measurable (freshExteriorMoment G p x y) := by + simp_rw [show freshExteriorMoment G p x y = (fun ω => ∑' W : Finset V, if cluster G ω x = (W:Set V) + then (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y else 0) from funext (freshExteriorMoment_eq_tsum G p x y)] + apply Measurable.tsum + intro W + exact Measurable.ite (measurableSet_cluster_eq G x W) measurable_const measurable_const + +theorem freshExteriorMoment_nonneg (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) : 0 ≤ freshExteriorMoment G p x y ω := + mul_nonneg (Nat.cast_nonneg _) (inducedSusceptibility_nonneg G _ p y) + +theorem integrable_freshExteriorMoment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (freshExteriorMoment G p x y) (law p) := by + apply ((susceptibility_eq_integral G hloc hqt p hp x).1.mul_const (susceptibility G p y)).mono' + (measurable_freshExteriorMoment G p x y).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun ω => by + rw [Real.norm_of_nonneg (freshExteriorMoment_nonneg G p x y ω)] + exact mul_le_mul_of_nonneg_left (inducedSusceptibility_le_susceptibility G hloc hqt p hp _ y) (Nat.cast_nonneg _)) + +theorem integrable_distinct_cluster_product [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (fun ω => if ¬Conn G ω x y + then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) (law p) := by + have he : (fun ω : Set E => if ¬Conn G ω x y + then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) = + {ω : Set E | Conn G ω x y}ᶜ.indicator + (fun ω => ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ)) := by + funext ω + simp only [Set.indicator,Set.mem_compl_iff,Set.mem_ofPred_eq] + rw [he] + exact (subcritical_cluster_association G hloc hqt p hp x y).1.indicator + (measurableSet_conn G x y).compl + + + +theorem integral_freshExteriorMoment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + (∫ ω, freshExteriorMoment G p x y ω ∂law p) = + ∫ ω, (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) ∂law p := by + rw [integral_cluster_finite_partition G p hp x _ (integrable_freshExteriorMoment G hloc hqt p hp x y), + integral_cluster_finite_partition G p hp x _ (integrable_distinct_cluster_product G hloc hqt p hp x y)] + apply tsum_congr + intro W + have hl : (∫ ω, (if cluster G ω x = (W:Set V) then freshExteriorMoment G p x y ω else 0) ∂law p) = + (W.card:ℝ)*inducedSusceptibility G (W:Set V)ᶜ p y * (law p).real {ω | cluster G ω x = (W:Set V)} := by + rw [←integral_event_indicator p _ (measurableSet_cluster_eq G x W),←integral_const_mul] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + dsimp only [Set.mem_ofPred_eq] + by_cases hc : cluster G ω x = (W:Set V) + · simp only [hc,ite_true,freshExteriorMoment,Set.ncard_coe_finset,mul_one] + · simp only [hc,ite_false,mul_zero]) + have hr : (∫ ω, (if cluster G ω x = (W:Set V) then + (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) else 0) ∂law p) = + (W.card:ℝ)*((law p).real {ω | cluster G ω x = (W:Set V)} * inducedSusceptibility G (W:Set V)ᶜ p y) := by + rw [←cluster_cell_exterior_susceptibility G hloc hqt p hp W x y,←integral_const_mul] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + dsimp only + by_cases hc : cluster G ω x = (W:Set V) + · simp only [hc,true_and,ite_true,Set.ncard_coe_finset] + split_ifs <;> simp only [mul_zero] + · simp only [hc,false_and,ite_false,mul_zero]) + rw [hl,hr] + ring + +end FreshExteriorMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DistinctClusterMoments +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def distinctClusterMoment (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := + ∫ ω, (if ¬Conn G ω x y then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) ∂law p + +theorem distinctClusterMoment_nonneg (G : BondGraph V E) (p : unitInterval) (x y : V) : + 0 ≤ distinctClusterMoment G p x y := by + apply integral_nonneg + intro ω + dsimp only [Pi.zero_apply] + split_ifs <;> positivity + +theorem cluster_ncard_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) : + (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by + rw [←cluster_aut G hab,Set.ncard_image_of_injective _ a.injective] + +theorem distinctClusterMoment_covariant [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : + distinctClusterMoment G p (a x) (a y) = distinctClusterMoment G p x y := by + have hs (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := + (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) + have hm : Measurable (fun ω : Set E => if ¬Conn G ω x y + then ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) else 0) := + Measurable.ite (measurableSet_conn G x y).compl ((hs x).mul (hs y)) measurable_const + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [distinctClusterMoment,conn_aut_iff G hab,cluster_ncard_covariant G hab] using h.symm + +noncomputable def neighborClusterMoment (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x : V) : ℝ := + ∑ y ∈ neighbors G hloc x, distinctClusterMoment G p x y + +theorem neighborClusterMoment_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x : V) : 0 ≤ neighborClusterMoment G hloc p x := + Finset.sum_nonneg (fun y _ => distinctClusterMoment_nonneg G p x y) + +theorem neighbors_covariant (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : + neighbors G hloc (a x) = (neighbors G hloc x).map a.toEmbedding := by + ext y + simp only [mem_neighbors,Finset.mem_map,Equiv.coe_toEmbedding] + constructor + · intro h + refine ⟨a.symm y,?_,by simp⟩ + simpa only [a.symm_apply_apply] using adj_aut G (isAut_symm G hab) h + · rintro ⟨z,hz,rfl⟩ + exact adj_aut G hab hz + +theorem neighborClusterMoment_covariant [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : + neighborClusterMoment G hloc p (a x) = neighborClusterMoment G hloc p x := by + simp only [neighborClusterMoment,neighbors_covariant G hloc hab,Finset.sum_map,Equiv.coe_toEmbedding, + distinctClusterMoment_covariant G hloc p hab] + +noncomputable def rootNeighborMoment (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : ℝ := + ∑ i, weight i * neighborClusterMoment G hloc p (root i) + +theorem neighborMoment_le_rootMoment [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (p : unitInterval) (x : V) : + neighborClusterMoment G hloc p x ≤ c*rootNeighborMoment G hloc root weight p := by + obtain ⟨i,a,b,hab,hax⟩ := hcov x + rw [←hax,neighborClusterMoment_covariant G hloc p hab] + calc + _ ≤ (c*weight i)*neighborClusterMoment G hloc p (root i) := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) (neighborClusterMoment_nonneg G hloc p _) + _ = c*(weight i*neighborClusterMoment G hloc p (root i)) := mul_assoc _ _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left + (Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (neighborClusterMoment_nonneg G hloc p _)) (Finset.mem_univ i)) hc + +end DistinctClusterMoments +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Clusters/KernelMoments.lean b/lean/OAI/Probability/UnimodularPercolation/Clusters/KernelMoments.lean index 53dd6817c280c4af2e701f8ca532d7db754a06e6..5fddfed454aca4033e8f9fa799d19ee5a22298c0 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Clusters/KernelMoments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Clusters/KernelMoments.lean @@ -1,1240 +1,1240 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.Resampling - -namespace OAI - -/-! Kernel Moments for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeletedDomainPotential -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem inducedSusceptibility_nonneg (G : BondGraph V E) (D : Set V) - (p : unitInterval) (x : V) : 0 ≤ inducedSusceptibility G D p x := by - unfold inducedSusceptibility - split_ifs - · exact restrictedSusceptibility_nonneg G _ p x - · rfl - -noncomputable def deletedBoundaryPotential (G : BondGraph V E) (hloc : LocallyFinite G) - (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : ℝ := - ∑ a ∈ ((finite_reachBall hloc x M).toFinset.filter (· ∉ D)), - ∑ b ∈ neighbors G hloc a, inducedSusceptibility G D p b - -theorem deletedBoundaryPotential_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : - 0 ≤ deletedBoundaryPotential G hloc D p x M := by - exact Finset.sum_nonneg (fun a _ => Finset.sum_nonneg (fun b _ => inducedSusceptibility_nonneg G D p b)) - -theorem le_deletedBoundaryPotential (G : BondGraph V E) (hloc : LocallyFinite G) - (D : Set V) (p : unitInterval) (x : V) (M : ℕ) (a b : V) - (ha : a ∈ reachBall G x M) (haD : a ∉ D) (hab : Adj G a b) : - inducedSusceptibility G D p b ≤ deletedBoundaryPotential G hloc D p x M := by - apply le_trans (Finset.single_le_sum (fun z _ => inducedSusceptibility_nonneg G D p z) - ((mem_neighbors G hloc a b).mpr hab)) - apply Finset.single_le_sum (fun z _ => Finset.sum_nonneg (fun y _ => inducedSusceptibility_nonneg G D p y)) - exact Finset.mem_filter.mpr ⟨(finite_reachBall hloc x M).mem_toFinset.mpr ha,haD⟩ - -noncomputable def deletedLocalPotential (G : BondGraph V E) (D : Set V) (p : unitInterval) - (ω : Set E) (x : V) (M : ℕ) : ℝ := - if x ∈ D then intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) else 0 - -theorem deletedLocalPotential_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (D : Set V) (p : unitInterval) (ω : Set E) (x : V) (M : ℕ) : - 0 ≤ deletedLocalPotential G D p ω x M := by - unfold deletedLocalPotential - split_ifs - · rw [intrinsicPotentialMax_eq G hloc] - exact inducedSusceptibility_nonneg G D p _ - · rfl - - - -theorem short_path_deleted_potential_bound [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : Set V) - (p : unitInterval) (hp : 0 < (p:ℝ)) (ω : Set E) (x y : V) (M : ℕ) - (l : List E) (hl : Along G x l y) (hlen : l.length ≤ M) (ho : ∀ e ∈ l, e ∈ ω) - (hfin : ∀ a, Summable (fun z => (law p).real {η | Conn G (η ∩ internalEdges G D) a z})) : - inducedSusceptibility G D p y ≤ deletedLocalPotential G D p ω x M + - (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M := by - have hpM : 0 ≤ (p:ℝ)^(-(M:ℤ)) := zpow_nonneg p.2.1 _ - have hn := deletedLocalPotential_nonneg G hloc D p ω x M - have hb := deletedBoundaryPotential_nonneg G hloc D p x M - by_cases hy : y ∈ D - · rcases hl.last_entrance D hy with ⟨hx,hall⟩ | ⟨a,b,e,l₁,l₂,heq,h₁,he,ha,hbD,h₂,hs⟩ - · have hreach : y ∈ intrinsicBall G (ω ∩ internalEdges G D) x M := - ⟨l,hl,hlen,fun e he => ⟨ho e he,hall e he⟩⟩ - have hh := le_intrinsicPotentialMax G hloc _ x M (inducedSusceptibility G D p) y hreach - change _ ≤ (if x ∈ D then _ else 0) + _ - rw [ite_eq_left hx] - exact hh.trans (le_add_of_nonneg_right (mul_nonneg hpM hb)) - · have hlen₂ : l₂.length ≤ M := by subst l; simp only [List.length_append,List.length_cons] at hlen; omega - have hpath := restrictedSusceptibility_short_path_bound G (internalEdges G D) p hp h₂ hs M hlen₂ hfin - have hχ : inducedSusceptibility G D p y ≤ (p:ℝ)^(-(M:ℤ))*inducedSusceptibility G D p b := by - simpa only [inducedSusceptibility,ite_eq_left hy,ite_eq_left hbD] using hpath - have haBall : a ∈ reachBall G x M := reachBall_mono G x - (show l₁.length ≤ M by subst l; simp only [List.length_append,List.length_cons] at hlen; omega) h₁.mem_reachBall - exact hχ.trans ((mul_le_mul_of_nonneg_left - (le_deletedBoundaryPotential G hloc D p x M a b haBall ha ⟨e,he⟩) hpM).trans - (le_add_of_nonneg_left hn)) - · rw [inducedSusceptibility,ite_eq_right hy] - exact add_nonneg hn (mul_nonneg hpM hb) - -end DeletedDomainPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LocalKernelAction -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -theorem summable_mass_action (q : LocalEndpointRule G hloc O M L) - (ω : Set E) (x : V) (f : V → ℝ) : Summable (fun y => q.mass ω x y * f y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - rw [q.outside_ball_zero ω x y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] - -theorem summable_kernel_action (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (x : V) (f : V → ℝ) : Summable (fun y => q.kernel p x y * f y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - rw [q.kernel_outside_ball_zero p x y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] - -theorem integrable_mass_action (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (x : V) (f : V → ℝ) : - Integrable (fun ω => ∑' y, q.mass ω x y * f y) (law p) := by - apply integrable_finite_local (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset) p - intro ω - exact tsum_congr (fun y => congrArg (· * f y) (q.locality ω x y)) - -theorem kernel_action_integral (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (x : V) (f : V → ℝ) : - (∑' y, q.kernel p x y * f y) = ∫ ω, (∑' y, q.mass ω x y * f y) ∂law p := by - let B := (finite_reachBall hloc x M).toFinset - have h₁ : (∑' y, q.kernel p x y*f y) = ∑ y ∈ B, q.kernel p x y*f y := - tsum_eq_sum fun y hy => by - rw [q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul] - have h₂ (ω : Set E) : (∑' y, q.mass ω x y*f y) = ∑ y ∈ B, q.mass ω x y*f y := - tsum_eq_sum fun y hy => by - rw [q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul] - rw [h₁] - simp_rw [h₂] - rw [integral_finsetSum B (fun y _ => (q.integrable_mass p x y).mul_const (f y))] - apply Finset.sum_congr rfl - intro y _ - exact (integral_mul_const (f y) (fun ω => q.mass ω x y)).symm - -theorem mass_action_le (q : LocalEndpointRule G hloc O M L) - (ω : Set E) (x : V) (f : V → ℝ) (C : ℝ) (hC : 0 ≤ C) - (hf : ∀ y, q.mass ω x y ≠ 0 → f y ≤ C) : - (∑' y, q.mass ω x y * f y) ≤ C := by - calc - _ ≤ ∑' y, q.mass ω x y * C := by - apply (q.summable_mass_action ω x f).tsum_le_tsum _ ((q.summable_mass ω x).mul_right C) - intro y - by_cases h : q.mass ω x y = 0 - · simp only [h,zero_mul,le_refl] - · exact mul_le_mul_of_nonneg_left (hf y h) (q.nonneg ω x y) - _ = (∑' y, q.mass ω x y)*C := tsum_mul_right - _ ≤ C := by simpa only [one_mul] using mul_le_mul_of_nonneg_right (q.row_le_one ω x) hC - -end LocalEndpointRule -end LocalKernelAction -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LocalMapDeletedPotential -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integrable_deletedLocalPotential (G : BondGraph V E) (hloc : LocallyFinite G) - (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : - Integrable (fun ω => deletedLocalPotential G D p ω x M) (law p) := by - by_cases hx : x ∈ D - · simp only [deletedLocalPotential,ite_eq_left hx] - exact integrable_finite_local _ p _ (fun ω => - intrinsicPotentialMax_domain_local G hloc (internalEdges G D) ω x M (inducedSusceptibility G D p)) - · simp only [deletedLocalPotential,ite_eq_right hx] - exact integrable_const 0 - -theorem integral_deletedLocalPotential_le - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (D : Set V) (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x : V) (M : ℕ) : - (∫ ω, deletedLocalPotential G D p ω x M ∂law p) ≤ - (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x := by - by_cases hx : x ∈ D - · simp only [deletedLocalPotential,ite_eq_left hx] - exact maximal_induced_susceptibility_bound G hloc hqt D x hx M p hp hpc - · simp only [deletedLocalPotential,inducedSusceptibility,ite_eq_right hx,integral_zero,mul_zero,le_refl] - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -theorem kernel_deleted_potential_bound - [Countable V] [Countable E] [Nonempty V] - (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) - (D : Set V) (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x : V) : - (∑' y, q.kernel p x y * inducedSusceptibility G D p y) ≤ - (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x + - (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M := by - let f := inducedSusceptibility G D p - let C := (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M - have hC : 0 ≤ C := mul_nonneg (zpow_nonneg p.2.1 _) (deletedBoundaryPotential_nonneg G hloc D p x M) - have hpoint (ω : Set E) : (∑' y, q.mass ω x y * f y) ≤ deletedLocalPotential G D p ω x M + C := by - apply q.mass_action_le ω x f _ (add_nonneg (deletedLocalPotential_nonneg G hloc D p ω x M) hC) - intro y hy - obtain ⟨_,_,hxy,hfin,hcap,_⟩ := q.support ω x y hy - obtain ⟨l,hl,hlen,ho⟩ := conn_short_of_cluster_cap G ω x y hxy hfin M hcap - exact short_path_deleted_potential_bound G hloc D p hp ω x y M l hl hlen ho - (summable_restrictedTwoPoint G hloc hqt p hpc (internalEdges G D)) - rw [q.kernel_action_integral] - have hi := integrable_deletedLocalPotential G hloc D p x M - calc - _ ≤ ∫ ω, deletedLocalPotential G D p ω x M + C ∂law p := - integral_mono (q.integrable_mass_action p x f) (hi.add (integrable_const C)) hpoint - _ = (∫ ω, deletedLocalPotential G D p ω x M ∂law p) + C := by - rw [integral_add hi (integrable_const C)]; simp - _ ≤ _ := by - have hh := integral_deletedLocalPotential_le G hloc hqt D p hp hpc x M - dsimp [C] - linarith - -end LocalEndpointRule -end LocalMapDeletedPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OrbitKernelTransport -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem orbit_kernel_column_eq_row - (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) (K : V → V → ℝ) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) - (hout : ∀ x y, x ∉ vertexOrbit G (root i₀) → K x y = 0) - (hin : ∀ x y, y ∉ vertexOrbit G (root i₀) → K x y = 0) - (hr : ∀ x, Summable (K x)) (hc : ∀ y, Summable (fun x => K x y)) - (y : V) (hy : y ∈ vertexOrbit G (root i₀)) : - (∑' x, K x y) = ∑' z, K (root i₀) z := by - let O := vertexOrbit G (root i₀) - let w : ι → ℝ := fun i => if root i ∈ O then weight i else 0 - have hrow (x : V) (hx : x ∈ O) : (∑' z, K x z) = ∑' z, K (root i₀) z := by - obtain ⟨a,b,ha,rfl⟩ := hx - rw [← a.tsum_eq (fun z => K (a (root i₀)) z)] - exact tsum_congr (hcov a b ha (root i₀)) - have hcol (x : V) (hx : x ∈ O) : (∑' z, K z x) = ∑' z, K z (root i₀) := by - obtain ⟨a,b,ha,rfl⟩ := hx - rw [← a.tsum_eq (fun z => K z (a (root i₀)))] - exact tsum_congr (fun z => hcov a b ha z (root i₀)) - have ho : root i₀ ∈ O := by - refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ - intro e; simp - have hw' (i : ι) : 0 ≤ w i := by - dsimp [w]; split_ifs - · exact hw i - · rfl - have hpos : 0 < ∑ i, w i := by - have hi := Finset.single_le_sum (fun i _ => hw' i) (Finset.mem_univ i₀) - have he : w i₀ = weight i₀ := ite_eq_left ho - rw [he] at hi - exact hw₀.trans_le hi - have ht := htr.real root weight Γ K - (by intro a ha x z; obtain ⟨b,hb⟩ := hΓ a ha; exact hcov a b hb x z) hr hc - have h₁ (i : ι) : weight i * (∑' z, K (root i) z) = w i * (∑' z, K (root i₀) z) := by - by_cases hi : root i ∈ O - · rw [hrow (root i) hi]; simp only [w,ite_eq_left hi] - · simp only [w,ite_eq_right hi,zero_mul] - have he : (∑' z, K (root i) z) = 0 := by simp only [hout _ _ hi,tsum_zero] - rw [he,mul_zero] - have h₂ (i : ι) : weight i * (∑' z, K z (root i)) = w i * (∑' z, K z (root i₀)) := by - by_cases hi : root i ∈ O - · rw [hcol (root i) hi]; simp only [w,ite_eq_left hi] - · simp only [w,ite_eq_right hi,zero_mul] - have he : (∑' z, K z (root i)) = 0 := by simp only [hin _ _ hi,tsum_zero] - rw [he,mul_zero] - simp_rw [h₁,h₂] at ht - rw [← Finset.sum_mul,← Finset.sum_mul] at ht - rw [hcol y hy] - exact (mul_left_cancel₀ (ne_of_gt hpos) ht).symm - - - -theorem operator_norm_le_absolute_sums (K : V → V → ℝ) (D : ℝ) (hD : 0 ≤ D) - (hr : ∀ x (S : Finset V), (∑ y ∈ S, |K x y|) ≤ D) - (hc : ∀ y (S : Finset V), (∑ x ∈ S, |K x y|) ≤ D) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : ‖A‖ ≤ D := by - obtain ⟨B,hBn,hB⟩ := exists_operator_of_row_column_bound (fun x y => |K x y|) D hD - (fun _ _ => abs_nonneg _) hr hc - obtain ⟨A',hAn,hA'⟩ := exists_operator_of_matrix_domination - (fun x y => |K x y|) K (fun _ _ => abs_nonneg _) (fun _ _ => le_rfl) B hB - have he := kernel_extension_unique hA hA' - rw [he] - exact hAn.trans hBn - -end OrbitKernelTransport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EndpointDifference -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} -variable (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - -noncomputable def kernelDifference (p r : unitInterval) (x y : V) : ℝ := - |q.normalizedKernel o p x y - q.normalizedKernel o r x y| -noncomputable def differenceRow (p r : unitInterval) : ℝ := ∑' y, q.kernelDifference o p r o y - -theorem kernelDifference_nonneg (p r : unitInterval) (x y : V) : - 0 ≤ q.kernelDifference o p r x y := abs_nonneg _ - -theorem kernelDifference_covariant (p r : unitInterval) - (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x y : V) : - q.kernelDifference o p r (a x) (a y) = q.kernelDifference o p r x y := by - simp only [kernelDifference,normalizedKernel,q.kernel_covariant p a b ha,q.kernel_covariant r a b ha] - -theorem kernelDifference_outside (p r : unitInterval) (x y : V) (hy : y ∉ reachBall G x M) : - q.kernelDifference o p r x y = 0 := by - simp only [kernelDifference,normalizedKernel,q.kernel_outside_ball_zero p x y hy, - q.kernel_outside_ball_zero r x y hy,mul_zero,sub_self,abs_zero] - -theorem kernelDifference_reverse_outside (p r : unitInterval) (x y : V) (hx : x ∉ reachBall G y M) : - q.kernelDifference o p r x y = 0 := by - simp only [kernelDifference,normalizedKernel,q.kernel_outside_reverse_ball_zero p x y hx, - q.kernel_outside_reverse_ball_zero r x y hx,mul_zero,sub_self,abs_zero] - -theorem kernelDifference_start (p r : unitInterval) (x y : V) (hx : x ∉ vertexOrbit G o) : - q.kernelDifference o p r x y = 0 := by - simp only [kernelDifference,normalizedKernel,q.kernel_zero_of_start_not_mem p x y hx, - q.kernel_zero_of_start_not_mem r x y hx,mul_zero,sub_self,abs_zero] - -theorem kernelDifference_end (p r : unitInterval) (x y : V) (hy : y ∉ vertexOrbit G o) : - q.kernelDifference o p r x y = 0 := by - simp only [kernelDifference,normalizedKernel,q.kernel_zero_of_end_not_mem p x y hy, - q.kernel_zero_of_end_not_mem r x y hy,mul_zero,sub_self,abs_zero] - -theorem summable_kernelDifference (p r : unitInterval) (x : V) : - Summable (q.kernelDifference o p r x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - exact q.kernelDifference_outside o p r x y (by simpa only [Set.Finite.mem_toFinset] using hy) - -theorem summable_kernelDifference_column (p r : unitInterval) (y : V) : - Summable (fun x => q.kernelDifference o p r x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y M).toFinset) - intro x hx - exact q.kernelDifference_reverse_outside o p r x y (by simpa only [Set.Finite.mem_toFinset] using hx) - -theorem differenceRow_nonneg (p r : unitInterval) : 0 ≤ q.differenceRow o p r := - tsum_nonneg (q.kernelDifference_nonneg o p r o) - -theorem differenceRow_finite (p r : unitInterval) : - q.differenceRow o p r = ∑ y ∈ (finite_reachBall hloc o M).toFinset, q.kernelDifference o p r o y := by - apply tsum_eq_sum - intro y hy - exact q.kernelDifference_outside o p r o y (by simpa only [Set.Finite.mem_toFinset] using hy) - -theorem kernelDifference_row_le (p r : unitInterval) (x : V) : - (∑' y, q.kernelDifference o p r x y) ≤ q.differenceRow o p r := by - by_cases hx : x ∈ vertexOrbit G o - · obtain ⟨a,b,ha,rfl⟩ := hx - rw [← a.tsum_eq (fun y => q.kernelDifference o p r (a o) y)] - exact le_of_eq (tsum_congr (q.kernelDifference_covariant o p r a b ha o)) - · simpa only [q.kernelDifference_start o p r x _ hx,tsum_zero] using q.differenceRow_nonneg o p r - - - -theorem norm_sub_le_differenceRow {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) (ho : o = root i₀) - (p r : unitInterval) (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel o p x y : ℂ)) - (hB : ∀ x y, B (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel o r x y : ℂ)) : - ‖A-B‖ ≤ q.differenceRow o p r := by - subst o - have hc (y : V) : (∑' x, q.kernelDifference (root i₀) p r x y) ≤ q.differenceRow (root i₀) p r := by - by_cases hy : y ∈ vertexOrbit G (root i₀) - · exact (orbit_kernel_column_eq_row G root weight Γ htr hΓ hw i₀ hw₀ - (q.kernelDifference (root i₀) p r) (q.kernelDifference_covariant (root i₀) p r) - (q.kernelDifference_start (root i₀) p r) (q.kernelDifference_end (root i₀) p r) - (q.summable_kernelDifference (root i₀) p r) (q.summable_kernelDifference_column (root i₀) p r) y hy).le - · simpa only [q.kernelDifference_end (root i₀) p r _ y hy,tsum_zero] using - q.differenceRow_nonneg (root i₀) p r - apply operator_norm_le_absolute_sums - (fun x y => q.normalizedKernel (root i₀) p x y-q.normalizedKernel (root i₀) r x y) - _ (q.differenceRow_nonneg (root i₀) p r) - · intro x S - exact ((q.summable_kernelDifference (root i₀) p r x).sum_le_tsum S - (fun y _ => q.kernelDifference_nonneg (root i₀) p r x y)).trans (q.kernelDifference_row_le (root i₀) p r x) - · intro y S - exact ((q.summable_kernelDifference_column (root i₀) p r y).sum_le_tsum S - (fun x _ => q.kernelDifference_nonneg (root i₀) p r x y)).trans (hc y) - · intro x y - change A (lp.single 2 y (1:ℂ)) x - B (lp.single 2 y (1:ℂ)) x = _ - rw [hA,hB,Complex.ofReal_sub] - -end LocalEndpointRule -end EndpointDifference -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section EndpointOperatorContinuity -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem exists_normalized_operator_all {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (p : unitInterval) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ 1 ∧ - ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ) := by - by_cases hu : q.successProbability p (root i₀) = 0 - · refine ⟨0,by simp,?_⟩ - intro x y - simp only [normalizedKernel,hu,inv_zero,zero_mul,Complex.ofReal_zero, - zero_apply,lp.coeFn_zero,Pi.zero_apply] - · obtain ⟨A,_,hA,hK⟩ := q.exists_normalized_operator root weight Γ htr hΓ hw i₀ hw₀ p - (lt_of_le_of_ne (q.successProbability_nonneg p (root i₀)) (Ne.symm hu)) - exact ⟨A,hA,hK⟩ - -theorem continuousAt_differenceRow (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p₀ : unitInterval) - (hu : q.successProbability p₀ o ≠ 0) : - ContinuousAt (fun p => q.differenceRow o p p₀) p₀ := by - simp_rw [q.differenceRow_finite o] - apply tendsto_finsetSum - intro y _ - exact ((((q.continuous_successProbability o).continuousAt.inv₀ hu).mul - (q.continuous_kernel o y).continuousAt).sub continuousAt_const).abs - - - -theorem exists_continuous_normalized_operators {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) : - ∃ A : unitInterval → (Hilbert V →L[ℂ] Hilbert V), - (∀ p, ‖A p‖ ≤ 1) ∧ - (∀ p x y, A p (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ)) ∧ - ∀ p, q.successProbability p (root i₀) ≠ 0 → ContinuousAt A p := by - choose A hn hK using q.exists_normalized_operator_all root weight Γ htr hΓ hw i₀ hw₀ - refine ⟨A,hn,hK,?_⟩ - intro p hu - apply tendsto_iff_norm_sub_tendsto_zero.mpr - apply squeeze_zero (fun r => norm_nonneg (A r-A p)) - (fun r => q.norm_sub_le_differenceRow (root i₀) root weight Γ htr hΓ hw i₀ hw₀ rfl r p (A r) (A p) (hK r) (hK p)) - have h := (q.continuousAt_differenceRow (root i₀) p hu).tendsto - have hz : q.differenceRow (root i₀) p p = 0 := by - simp only [differenceRow,kernelDifference,sub_self,abs_zero,tsum_zero] - rwa [hz] at h - -end LocalEndpointRule -end EndpointOperatorContinuity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ThreeArmGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem Along.first_entrance {G : BondGraph V E} {x y : V} {l : List E} - (hl : Along G x l y) (D : Set V) (hy : y ∈ D) : - ∃ z ∈ D, ∃ k : List E, Along G x k z ∧ k ⊆ l ∧ ∀ e ∈ k, e ∉ internalEdges G D := by - induction hl with - | nil => exact ⟨_,hy,[],.nil _,by simp,by simp⟩ - | @cons x z y l e he ht ih => - by_cases hx : x ∈ D - · exact ⟨x,hx,[],.nil _,by simp,by simp⟩ - · obtain ⟨w,hw,k,hk,hsub,hout⟩ := ih hy - refine ⟨w,hw,e::k,.cons e he hk,?_,?_⟩ - · intro d hd - rcases List.mem_cons.mp hd with rfl | hd - · exact List.mem_cons_self - · exact List.mem_cons_of_mem _ (hsub hd) - · intro d hd - rcases List.mem_cons.mp hd with rfl | hd - · intro h - exact hx ((mem_internalEdges_of_ends G D d x z he).mp h).1 - · exact hout d hd - - - -theorem conn_three_disjoint_arms (G : BondGraph V E) (ω : Set E) (x y z : V) - (hxy : Conn G ω x y) (hxz : Conn G ω x z) : - ∃ w, ω ∈ DisjointOccurrence {η | Conn G η x w} - (DisjointOccurrence {η | Conn G η w y} {η | Conn G η w z}) := by - obtain ⟨p⟩ := (conn_iff_reachable G ω x y).mp hxy - let t := p.toPath - let D : Set V := {a | a ∈ t.val.support} - obtain ⟨l,hl,_,ho⟩ := conn_exists_bond_trail G (conn_symm G ω hxz) - obtain ⟨w,hw,k,hk,hsub,hout⟩ := hl.first_entrance D t.val.start_mem_support - obtain ⟨l₁,h₁,he₁,ho₁⟩ := walk_lift_bonds G ω (t.val.takeUntil w hw) - obtain ⟨l₂,h₂,he₂,ho₂⟩ := walk_lift_bonds G ω (t.val.dropUntil w hw) - have h₁in (e : E) (he : e ∈ l₁) : e ∈ internalEdges G D := by - have hh : G e ∈ (t.val.takeUntil w hw).edges := he₁ ▸ List.mem_map_of_mem he - have hh' := t.val.edges_takeUntil_subset_edges hw hh - intro a ha - exact SimpleGraph.Walk.mem_support_of_mem_edges hh' ha - have h₂in (e : E) (he : e ∈ l₂) : e ∈ internalEdges G D := by - have hh : G e ∈ (t.val.dropUntil w hw).edges := he₂ ▸ List.mem_map_of_mem he - have hh' := t.val.edges_dropUntil_subset_edges hw hh - intro a ha - exact SimpleGraph.Walk.mem_support_of_mem_edges hh' ha - have h12 : Disjoint l₁.toFinset l₂.toFinset := by - apply Finset.disjoint_left.mpr - intro e he₁' he₂' - have hp := t.property.isTrail.disjoint_edges_takeUntil_dropUntil hw - exact List.disjoint_left.mp hp (he₁ ▸ List.mem_map_of_mem (List.mem_toFinset.mp he₁')) - (he₂ ▸ List.mem_map_of_mem (List.mem_toFinset.mp he₂')) - have h13 : Disjoint l₁.toFinset k.toFinset := by - apply Finset.disjoint_left.mpr - intro e he hk' - exact hout e (List.mem_toFinset.mp hk') (h₁in e (List.mem_toFinset.mp he)) - have h23 : Disjoint l₂.toFinset k.toFinset := by - apply Finset.disjoint_left.mpr - intro e he hk' - exact hout e (List.mem_toFinset.mp hk') (h₂in e (List.mem_toFinset.mp he)) - have hkopen (e : E) (he : e ∈ k) : e ∈ ω := ho e (hsub he) - refine ⟨w,l₁.toFinset,l₂.toFinset ∪ k.toFinset,?_,?_,Finset.disjoint_union_right.mpr ⟨h12,h13⟩,?_,?_⟩ - · intro e he; exact ho₁ e (List.mem_toFinset.mp he) - · intro e he - rcases Finset.mem_union.mp he with he | he - · exact ho₂ e (List.mem_toFinset.mp he) - · exact hkopen e (List.mem_toFinset.mp he) - · exact h₁.conn (fun e he => List.mem_toFinset.mpr he) - · refine ⟨l₂.toFinset,k.toFinset,?_,?_,h23,?_,?_⟩ - · exact_mod_cast Finset.subset_union_left - · exact_mod_cast Finset.subset_union_right - · exact h₂.conn (fun e he => List.mem_toFinset.mpr he) - · exact conn_symm G _ (hk.conn (fun e he => List.mem_toFinset.mpr he)) - -end ThreeArmGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ThreeArmProbability -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem bk_ennreal [Countable E] (p : unitInterval) (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) (hfA : FiniteWitness A) (hfB : FiniteWitness B) : - law p (DisjointOccurrence A B) ≤ law p A * law p B := by - apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) - (ENNReal.mul_ne_top (measure_ne_top _ _) (measure_ne_top _ _))).mp - rw [ENNReal.toReal_mul] - exact bk p A B hA hB hfA hfB - - - -theorem three_arm_bound [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y z : V) : - law p {ω | Conn G ω x y ∧ Conn G ω x z} ≤ - ∑' w, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := by - let C := fun a b : V => {ω : Set E | Conn G ω a b} - have hup (a b : V) : IsUpperSet (C a b) := fun _ _ h hconn => conn_mono G h hconn - have hf (a b : V) : FiniteWitness (C a b) := finiteWitness_conn G a b - have hb (w : V) : law p (DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) ≤ - law p (C x w) * law p (C w y) * law p (C w z) := by - calc - _ ≤ law p (C x w) * law p (DisjointOccurrence (C w y) (C w z)) := - bk_ennreal p _ _ (hup x w) (disjointOccurrence_upper _ _) (hf x w) (finiteWitness_disjointOccurrence _ _) - _ ≤ law p (C x w) * (law p (C w y)*law p (C w z)) := - mul_le_mul_right (bk_ennreal p _ _ (hup w y) (hup w z) (hf w y) (hf w z)) _ - _ = _ := (mul_assoc _ _ _).symm - calc - _ ≤ law p (⋃ w, DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) := by - apply measure_mono - intro ω h - obtain ⟨w,hw⟩ := conn_three_disjoint_arms G ω x y z h.1 h.2 - exact Set.mem_iUnion.mpr ⟨w,hw⟩ - _ ≤ ∑' w, law p (DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) := measure_iUnion_le _ - _ ≤ _ := ENNReal.tsum_le_tsum hb - - - -theorem three_arm_double_sum_bound [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (C : ℝ≥0∞) - (hC : ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ C) (x : V) : - (∑' y, ∑' z, law p {ω | Conn G ω x y ∧ Conn G ω x z}) ≤ C^3 := by - calc - _ ≤ ∑' y, ∑' z, ∑' w, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := - ENNReal.tsum_le_tsum (fun y => ENNReal.tsum_le_tsum (fun z => three_arm_bound G p x y z)) - _ = ∑' w, law p {ω | Conn G ω x w} * (∑' y, law p {ω | Conn G ω w y}) * - (∑' z, law p {ω | Conn G ω w z}) := by - calc - _ = ∑' y, ∑' w, ∑' z, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := by - apply tsum_congr - intro y - exact ENNReal.tsum_comm - _ = ∑' w, ∑' y, ∑' z, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := ENNReal.tsum_comm - _ = _ := by simp_rw [ENNReal.tsum_mul_left,ENNReal.tsum_mul_right,ENNReal.tsum_mul_left] - _ ≤ ∑' w, law p {ω | Conn G ω x w} * C * C := - ENNReal.tsum_le_tsum (fun w => mul_le_mul' (mul_le_mul_right (hC w) _) (hC w)) - _ = (∑' w, law p {ω | Conn G ω x w}) * C * C := by - rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_right] - _ ≤ C*C*C := mul_le_mul_left (mul_le_mul_left (hC x) C) C - _ = C^3 := by ring - -end ThreeArmProbability -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ClusterMassMoments -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def clusterMass (G : BondGraph V E) (ω : Set E) (x : V) : ℝ≥0∞ := - ∑' y, if Conn G ω x y then 1 else 0 - -theorem measurable_clusterMass [Countable V] [Countable E] - (G : BondGraph V E) (x : V) : Measurable (fun ω => clusterMass G ω x) := by - apply Measurable.tsum - intro y - exact Measurable.ite (measurableSet_conn G x y) measurable_const measurable_const - -theorem clusterMass_eq_ncard (G : BondGraph V E) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : clusterMass G ω x = (cluster G ω x).ncard := by - change (∑' y, if y ∈ cluster G ω x then (1:ℝ≥0∞) else 0) = _ - rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by - simp only [Set.Finite.mem_toFinset] at hy - simp only [ite_eq_right hy])] - have he : (∑ y ∈ hf.toFinset, if y ∈ cluster G ω x then (1:ℝ≥0∞) else 0) = ∑ _y ∈ hf.toFinset, (1:ℝ≥0∞) := by - apply Finset.sum_congr rfl - intro y hy - exact ite_eq_left (hf.mem_toFinset.mp hy) - rw [he] - simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] - -theorem lintegral_clusterMass [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x : V) : - (∫⁻ ω, clusterMass G ω x ∂law p) = ∑' y, law p {ω | Conn G ω x y} := by - unfold clusterMass - rw [lintegral_tsum (fun y => (Measurable.ite (measurableSet_conn G x y) measurable_const measurable_const).aemeasurable)] - apply tsum_congr - intro y - simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) (measurableSet_conn G x y)) - -theorem clusterMass_sq (G : BondGraph V E) (ω : Set E) (x : V) : - clusterMass G ω x ^ 2 = ∑' y, ∑' z, if Conn G ω x y ∧ Conn G ω x z then (1:ℝ≥0∞) else 0 := by - rw [pow_two,clusterMass] - rw [←ENNReal.tsum_mul_right] - apply tsum_congr - intro y - rw [←ENNReal.tsum_mul_left] - apply tsum_congr - intro z - split_ifs <;> simp_all - -theorem lintegral_clusterMass_sq [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (x : V) : - (∫⁻ ω, clusterMass G ω x ^ 2 ∂law p) = - ∑' y, ∑' z, law p {ω | Conn G ω x y ∧ Conn G ω x z} := by - have hm (y z : V) : Measurable (fun ω : Set E => if Conn G ω x y ∧ Conn G ω x z then (1:ℝ≥0∞) else 0) := - Measurable.ite ((measurableSet_conn G x y).inter (measurableSet_conn G x z)) measurable_const measurable_const - simp_rw [clusterMass_sq] - rw [lintegral_tsum (fun y => (Measurable.tsum (fun z => hm y z)).aemeasurable)] - apply tsum_congr - intro y - rw [lintegral_tsum (fun z => (hm y z).aemeasurable)] - apply tsum_congr - intro z - have hs : MeasurableSet {ω : Set E | Conn G ω x y ∧ Conn G ω x z} := - (measurableSet_conn G x y).inter (measurableSet_conn G x z) - simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) hs) - - -theorem cluster_second_moment_bound [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (C : ℝ≥0∞) - (hC : ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ C) (x : V) : - (∫⁻ ω, clusterMass G ω x ^ 2 ∂law p) ≤ C^3 := by - rw [lintegral_clusterMass_sq] - exact three_arm_double_sum_bound G p C hC x - -end ClusterMassMoments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section SubcriticalMoments -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem subcritical_cluster_finite_ae (G : BondGraph V E) - (p : unitInterval) (hp : p < pc G) (x : V) : - ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by - have hz : (law p).real {ω | (cluster G ω x).Infinite} = 0 := by - apply le_antisymm _ measureReal_nonneg - by_contra! h - exact (not_le_of_gt hp) (pc_le_of_infinite_cluster_probability_pos G x p h) - apply ae_iff.mpr - change law p {ω | (cluster G ω x).Infinite} = 0 - exact ((ENNReal.toReal_eq_zero_iff _).mp hz).resolve_right (measure_ne_top _ _) - -theorem subcritical_ennreal_row_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : - ∃ C : ℝ, 0 ≤ C ∧ ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ ENNReal.ofReal C := by - obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp - refine ⟨C,hC,fun x => ?_⟩ - have hs := summable_of_sum_le (twoPoint_nonneg G p x) (hrow x) - have he : (∑' y, law p {ω | Conn G ω x y}) = ENNReal.ofReal (∑' y, twoPoint G p x y) := by - rw [ENNReal.ofReal_tsum_of_nonneg (twoPoint_nonneg G p x) hs] - apply tsum_congr - intro y - exact (ENNReal.ofReal_toReal (measure_ne_top _ _)).symm - rw [he] - exact ENNReal.ofReal_le_ofReal (hs.tsum_le_of_sum_le (hrow x)) - - - -theorem subcritical_second_moment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : - ∃ C : ℝ, 0 ≤ C ∧ ∀ x, - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p) ∧ - (∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p) ≤ C^3 := by - obtain ⟨C,hC,hrow⟩ := subcritical_ennreal_row_bound G hloc hqt p hp - refine ⟨C,hC,fun x => ?_⟩ - have hmeas : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^2) := - (measurable_of_countable (fun n : ℕ => (n:ℝ)^2)).comp (measurable_cluster_ncard G hloc x) - have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)^2) := - Filter.Eventually.of_forall (fun _ => sq_nonneg _) - have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2)) =ᵐ[law p] - (fun ω => clusterMass G ω x ^ 2) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_pow (Nat.cast_nonneg _)] - simp only [ENNReal.ofReal_natCast] - have hbound : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2) ∂law p) ≤ ENNReal.ofReal (C^3) := by - rw [lintegral_congr_ae he,ENNReal.ofReal_pow hC] - exact cluster_second_moment_bound G p _ hrow x - have hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p) := - ⟨hmeas.aestronglyMeasurable,(hasFiniteIntegral_iff_ofReal hn).mpr - (hbound.trans_lt ENNReal.ofReal_lt_top)⟩ - refine ⟨hi,?_⟩ - rw [integral_eq_lintegral_of_nonneg_ae hn hmeas.aestronglyMeasurable] - exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hbound).trans_eq (ENNReal.toReal_ofReal (pow_nonneg hC _)) - -end SubcriticalMoments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section SusceptibilityTypes -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def susceptibility (G : BondGraph V E) (p : unitInterval) (x : V) : ℝ := - ∑' y, twoPoint G p x y - -noncomputable def rootSusceptibility (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : ℝ := - ∑ i, weight i * susceptibility G p (root i) - -theorem susceptibility_nonneg (G : BondGraph V E) (p : unitInterval) (x : V) : - 0 ≤ susceptibility G p x := tsum_nonneg (twoPoint_nonneg G p x) - -theorem summable_twoPoint_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : Summable (twoPoint G p x) := by - obtain ⟨_,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp - exact summable_of_sum_le (twoPoint_nonneg G p x) (hrow x) - -theorem ennreal_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - ENNReal.ofReal (susceptibility G p x) = ∑' y, law p {ω | Conn G ω x y} := by - rw [susceptibility,ENNReal.ofReal_tsum_of_nonneg (twoPoint_nonneg G p x) - (summable_twoPoint_subcritical G hloc hqt p hp x)] - apply tsum_congr - intro y - exact ENNReal.ofReal_toReal (measure_ne_top _ _) - -theorem susceptibility_aut [Countable V] [Countable E] (G : BondGraph V E) - (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : - susceptibility G p (a x) = susceptibility G p x := by - unfold susceptibility - rw [←a.tsum_eq] - simp only [twoPoint_aut G p h] - -theorem susceptibility_one_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : 1 ≤ susceptibility G p x := by - have hd : twoPoint G p x x = 1 := by - have he : {ω : Set E | Conn G ω x x} = Set.univ := Set.eq_univ_of_forall (fun _ => conn_refl G _ x) - simp only [twoPoint,he,measure_univ,ENNReal.toReal_one] - rw [←hd] - exact (summable_twoPoint_subcritical G hloc hqt p hp x).le_tsum x (fun _ _ => twoPoint_nonneg G p _ _) - -theorem rootSusceptibility_nonneg (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) : - 0 ≤ rootSusceptibility G root weight p := - Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (susceptibility_nonneg G p _)) - -theorem susceptibility_le_rootSusceptibility [Countable V] [Countable E] - (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (p : unitInterval) (x : V) : - susceptibility G p x ≤ c*rootSusceptibility G root weight p := by - obtain ⟨i,a,b,hab,hax⟩ := hcov x - rw [←hax,susceptibility_aut G p hab] - calc - _ ≤ (c*weight i)*susceptibility G p (root i) := by - simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) (susceptibility_nonneg G p _) - _ = c*(weight i*susceptibility G p (root i)) := mul_assoc _ _ _ - _ ≤ _ := mul_le_mul_of_nonneg_left - (Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (susceptibility_nonneg G p _)) (Finset.mem_univ i)) hc - - -theorem susceptibility_eq_integral [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)) (law p) ∧ - susceptibility G p x = ∫ ω, ((cluster G ω x).ncard:ℝ) ∂law p := by - have hm : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)) := - (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x) - have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)) := Filter.Eventually.of_forall (fun _ => Nat.cast_nonneg _) - have he : (fun ω => ENNReal.ofReal ((cluster G ω x).ncard:ℝ)) =ᵐ[law p] (fun ω => clusterMass G ω x) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_natCast] - have heq : (∫⁻ ω, ENNReal.ofReal ((cluster G ω x).ncard:ℝ) ∂law p) = ENNReal.ofReal (susceptibility G p x) := by - rw [lintegral_congr_ae he,lintegral_clusterMass,ennreal_susceptibility G hloc hqt p hp] - refine ⟨⟨hm.aestronglyMeasurable,(hasFiniteIntegral_iff_ofReal hn).mpr (by rw [heq]; exact ENNReal.ofReal_lt_top)⟩,?_⟩ - rw [integral_eq_lintegral_of_nonneg_ae hn hm.aestronglyMeasurable,heq,ENNReal.toReal_ofReal (susceptibility_nonneg G p x)] - -end SusceptibilityTypes -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteKernelNorm -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem kernel_sum_le_norm_card (K : V → V → ℝ) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (F : Finset V) : - ∑ x ∈ F, ∑ y ∈ F, K x y ≤ ‖A‖*F.card := by - have he : inner ℂ (deltaSum F) (A (deltaSum F)) = - ((∑ x ∈ F, ∑ y ∈ F, K x y : ℝ) : ℂ) := by - rw [inner_deltaSum] - simp only [deltaSum,map_sum,lp.coeFn_sum,Finset.sum_apply,Complex.ofReal_sum] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - exact hA x y - have h := (Complex.re_le_norm (inner ℂ (deltaSum F) (A (deltaSum F)))).trans - ((norm_inner_le_norm _ _).trans - (mul_le_mul_of_nonneg_left (A.le_opNorm _) (norm_nonneg _))) - rw [he,Complex.ofReal_re] at h - calc - _ ≤ ‖deltaSum F‖*(‖A‖*‖deltaSum F‖) := h - _ = ‖A‖*‖deltaSum F‖^2 := by ring - _ = _ := by rw [norm_deltaSum_sq] - - -theorem kernel_average_le_norm (K : V → V → ℝ) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) - (F : Finset V) (hF : F.Nonempty) : - (∑ x ∈ F, ∑ y ∈ F, K x y)/(F.card:ℝ) ≤ ‖A‖ := by - exact (div_le_iff₀ (Nat.cast_pos.mpr hF.card_pos)).mpr (kernel_sum_le_norm_card K A hA F) - -end FiniteKernelNorm -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BinClusterSlice -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binClusterSlice (G : BondGraph V E) (o : V) (n : ℕ) - (ω : Set E) (x : V) : Finset V := - if h : ClusterWindow G x n (2*n) ω then h.1.toFinset.filter (fun y => y ∈ vertexOrbit G o) else ∅ - -theorem mem_binClusterSlice (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : - y ∈ binClusterSlice G o n ω x ↔ ClusterWindow G x n (2*n) ω ∧ Conn G ω x y ∧ y ∈ vertexOrbit G o := by - unfold binClusterSlice - split_ifs with h - · simp only [Finset.mem_filter,Set.Finite.mem_toFinset,h,true_and,cluster,Set.mem_ofPred_eq] - · simp only [Finset.notMem_empty,h,false_and] - -theorem binClusterSlice_eq_of_conn (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) - {x y : V} (h : Conn G ω x y) : binClusterSlice G o n ω x = binClusterSlice G o n ω y := by - have hc := cluster_eq_of_conn G ω h - have hw : ClusterWindow G x n (2*n) ω ↔ ClusterWindow G y n (2*n) ω := by - unfold ClusterWindow - rw [hc] - ext z - simp only [mem_binClusterSlice,hw] - have hz : Conn G ω x z ↔ Conn G ω y z := by change z ∈ cluster G ω x ↔ z ∈ cluster G ω y; rw [hc] - rw [hz] - -theorem binClusterSlice_nonempty (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) - (hw : ClusterWindow G x n (2*n) ω) (hx : x ∈ vertexOrbit G o) : - (binClusterSlice G o n ω x).Nonempty := - ⟨x,(mem_binClusterSlice G o n ω x x).mpr ⟨hw,conn_refl _ _ _,hx⟩⟩ - -theorem binOrbitRowMass_eq_slice (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) - (hx : x ∈ vertexOrbit G o) : - binOrbitRowMass G n ω x = (binClusterSlice G o n ω x).card := by - by_cases hw : ClusterWindow G x n (2*n) ω - · rw [binOrbitRowMass_eq G n ω x hw,vertexOrbit_eq_of_mem G o x hx] - simp only [binClusterSlice,dite_eq_left hw] - rw [←Finset.sum_filter] - simp - · rw [binOrbitRowMass_zero G n ω x hw] - simp only [binClusterSlice,dite_eq_right hw,Finset.card_empty,Nat.cast_zero] - -theorem binSizeMass_eq_of_conn (G : BondGraph V E) (n : ℕ) (ω : Set E) - {x y : V} (hc : Conn G ω x y) : binSizeMass G n ω x = binSizeMass G n ω y := by - have he := cluster_eq_of_conn G ω hc - have hw : ClusterWindow G x n (2*n) ω ↔ ClusterWindow G y n (2*n) ω := by - unfold ClusterWindow - rw [he] - by_cases hx : ClusterWindow G x n (2*n) ω - · rw [binSizeMass_eq G n ω x hx,binSizeMass_eq G n ω y (hw.mp hx),he] - · have hy := fun h => hx (hw.mpr h) - simp only [binSizeMass,binMass_zero_of_not_window G n ω x _ hx, - binMass_zero_of_not_window G n ω y _ hy,tsum_zero] - -theorem mem_binClusterSlice_iff_mass (G : BondGraph V E) (o : V) (n : ℕ) - (ω : Set E) (x y : V) : - y ∈ binClusterSlice G o n ω x ↔ - binConnectionMass G n ω x y = 1 ∧ y ∈ vertexOrbit G o := by - rw [mem_binClusterSlice] - have he : binConnectionMass G n ω x y = - if ClusterWindow G x n (2*n) ω ∧ Conn G ω x y then 1 else 0 := by - unfold binConnectionMass ClusterWindow - congr 1 - apply propext; tauto - rw [he] - by_cases h : ClusterWindow G x n (2*n) ω ∧ Conn G ω x y - · rw [ite_eq_left h] - simp only [h.1,h.2,true_and] - · rw [ite_eq_right h] - simp only [zero_ne_one,false_and] - tauto - -theorem binClusterSlice_local (G : BondGraph V E) (hloc : LocallyFinite G) - (o : V) (n : ℕ) (ω : Set E) (x : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binClusterSlice G o n ω x = binClusterSlice G o n (ω ∩ (Q : Set E)) x := by - intro Q - ext y - rw [mem_binClusterSlice_iff_mass,mem_binClusterSlice_iff_mass, - binConnectionMass_local G hloc n ω x y] - -end BinClusterSlice -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteClassTransport -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def finiteClassTransport (S : V → Finset V) (t : V → ℝ) - (K : V → V → ℝ) (x y : V) : ℝ := - if y ∈ S x then t x / (S x).card * ∑ z ∈ S x, K x z else 0 - -theorem finiteClassTransport_nonneg (S : V → Finset V) (t : V → ℝ) - (K : V → V → ℝ) (ht : ∀ x, 0 ≤ t x) (hK : ∀ x y, 0 ≤ K x y) (x y : V) : - 0 ≤ finiteClassTransport S t K x y := by - unfold finiteClassTransport - split_ifs - · exact mul_nonneg (div_nonneg (ht x) (Nat.cast_nonneg _)) (Finset.sum_nonneg (fun z _ => hK x z)) - · rfl - -theorem finiteClassTransport_row (S : V → Finset V) (t : V → ℝ) - (K : V → V → ℝ) (x : V) : - (∑' y, finiteClassTransport S t K x y) = t x * ∑ z ∈ S x, K x z := by - rw [tsum_eq_sum (s := S x) (fun y hy => (show finiteClassTransport S t K x y = 0 from ite_eq_right hy))] - have he : (∑ y ∈ S x, finiteClassTransport S t K x y) = - (S x).card * (t x / (S x).card * ∑ z ∈ S x, K x z) := by - simp only [finiteClassTransport] - rw [Finset.sum_ite_mem] - simp only [Finset.inter_self,Finset.sum_const,nsmul_eq_mul] - rw [he] - by_cases h : (S x).Nonempty - · have hc : ((S x).card:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr h.card_pos.ne' - field_simp - · have hs := Finset.not_nonempty_iff_eq_empty.mp h - simp only [hs,Finset.card_empty,Nat.cast_zero,Finset.sum_empty,mul_zero] - -theorem finiteClassTransport_column (S : V → Finset V) (t : V → ℝ) - (K : V → V → ℝ) - (hsym : ∀ x y, y ∈ S x ↔ x ∈ S y) - (heq : ∀ x y, y ∈ S x → S y = S x) - (ht : ∀ x y, y ∈ S x → t y = t x) (x : V) : - (∑' y, finiteClassTransport S t K y x) = - t x / (S x).card * ∑ y ∈ S x, ∑ z ∈ S x, K y z := by - rw [tsum_eq_sum (s := S x) (fun y hy => (show finiteClassTransport S t K y x = 0 from - ite_eq_right (fun h => hy ((hsym x y).mpr h))))] - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y hy - rw [finiteClassTransport,ite_eq_left ((hsym x y).mp hy),heq x y hy,ht x y hy] - - -theorem finiteClassTransport_column_le (S : V → Finset V) (t : V → ℝ) - (K : V → V → ℝ) (ht0 : ∀ x, 0 ≤ t x) - (hsym : ∀ x y, y ∈ S x ↔ x ∈ S y) - (heq : ∀ x y, y ∈ S x → S y = S x) - (ht : ∀ x y, y ∈ S x → t y = t x) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (x : V) : - (∑' y, finiteClassTransport S t K y x) ≤ ‖A‖*t x := by - rw [finiteClassTransport_column S t K hsym heq ht] - by_cases h : (S x).Nonempty - · have hh := mul_le_mul_of_nonneg_left (kernel_average_le_norm K A hA (S x) h) (ht0 x) - simpa only [div_mul_eq_mul_div,mul_div_assoc,mul_comm (t x) ‖A‖] using hh - · have hs := Finset.not_nonempty_iff_eq_empty.mp h - simp only [hs,Finset.card_empty,Nat.cast_zero,div_zero,Finset.sum_empty,mul_zero] - exact mul_nonneg (norm_nonneg _) (ht0 x) - -end FiniteClassTransport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BinDiagonalClass -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binOrbitClass (G : BondGraph V E) (o : V) (n : ℕ) - (ω : Set E) (x : V) : Finset V := - if x ∈ vertexOrbit G o then binClusterSlice G o n ω x else ∅ - -theorem mem_binOrbitClass (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : - y ∈ binOrbitClass G o n ω x ↔ x ∈ vertexOrbit G o ∧ - ClusterWindow G x n (2*n) ω ∧ Conn G ω x y ∧ y ∈ vertexOrbit G o := by - unfold binOrbitClass - split_ifs with h - · simp only [mem_binClusterSlice,h,true_and] - · simp only [Finset.notMem_empty,h,false_and] - -theorem binOrbitClass_symm (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : - y ∈ binOrbitClass G o n ω x ↔ x ∈ binOrbitClass G o n ω y := by - have h (x y : V) (hy : y ∈ binOrbitClass G o n ω x) : x ∈ binOrbitClass G o n ω y := by - obtain ⟨hx,hw,hc,hy⟩ := (mem_binOrbitClass G o n ω x y).mp hy - have hwy : ClusterWindow G y n (2*n) ω := by - unfold ClusterWindow at hw ⊢ - rw [←cluster_eq_of_conn G ω hc] - exact hw - exact (mem_binOrbitClass G o n ω y x).mpr ⟨hy,hwy,conn_symm G ω hc,hx⟩ - exact ⟨h x y,h y x⟩ - -theorem binOrbitClass_eq (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) - (hy : y ∈ binOrbitClass G o n ω x) : binOrbitClass G o n ω y = binOrbitClass G o n ω x := by - obtain ⟨hx,_,hc,hy⟩ := (mem_binOrbitClass G o n ω x y).mp hy - simp only [binOrbitClass,ite_eq_left hx,ite_eq_left hy] - exact (binClusterSlice_eq_of_conn G o n ω hc).symm - -theorem binOrbitClass_mass_eq (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) - (hy : y ∈ binOrbitClass G o n ω x) : binSizeMass G n ω y = binSizeMass G n ω x := - (binSizeMass_eq_of_conn G n ω ((mem_binOrbitClass G o n ω x y).mp hy).2.2.1).symm - -theorem binOrbitClass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (o : V) (n : ℕ) (ω : Set E) (x : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binOrbitClass G o n ω x = binOrbitClass G o n (ω ∩ (Q : Set E)) x := by - intro Q - unfold binOrbitClass - rw [binClusterSlice_local G hloc o n ω x] - -theorem binOrbitClass_mem_covariant (G : BondGraph V E) (o : V) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (n : ℕ) (ω : Set E) (x y : V) : - y ∈ binOrbitClass G o n (b ⁻¹' ω) x ↔ a y ∈ binOrbitClass G o n ω (a x) := by - unfold binOrbitClass - simp only [mem_vertexOrbit_aut_iff G o hab] - split_ifs - · simp only [mem_binClusterSlice_iff_mass,binConnectionMass_covariant G hab, - mem_vertexOrbit_aut_iff G o hab] - · simp only [Finset.notMem_empty] - -theorem binOrbitClass_covariant (G : BondGraph V E) (o : V) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (n : ℕ) (ω : Set E) (x : V) : - (binOrbitClass G o n (b ⁻¹' ω) x).image a = binOrbitClass G o n ω (a x) := by - ext y - constructor - · rintro hy - obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp hy - exact (binOrbitClass_mem_covariant G o hab n ω x z).mp hz - · intro hy - exact Finset.mem_image.mpr ⟨a.symm y,(binOrbitClass_mem_covariant G o hab n ω x (a.symm y)).mpr - (by simpa only [Equiv.apply_symm_apply] using hy),a.apply_symm_apply y⟩ - -theorem binOrbitClass_reach (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) - (hy : y ∈ binOrbitClass G o n ω x) : y ∈ reachBall G x (2*n) := by - obtain ⟨_,hw,hc,_⟩ := (mem_binOrbitClass G o n ω x y).mp hy - exact finite_cluster_subset_reachBall G ω x hw.1 (2*n) hw.2.2.le hc - -end BinDiagonalClass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section BinDiagonalTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binDiagonalMass (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x y : V) : ℝ := - finiteClassTransport (binOrbitClass G o n ω) (fun x => binSizeMass G n ω x ^ 2) K x y - -theorem binDiagonalMass_nonneg (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) (ω : Set E) (x y : V) : - 0 ≤ binDiagonalMass G o n K ω x y := - finiteClassTransport_nonneg _ _ K (fun _ => sq_nonneg _) hK x y - -theorem binDiagonalMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (o : V) (n : ℕ) (K : V → V → ℝ) (ω : Set E) (x y : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binDiagonalMass G o n K ω x y = binDiagonalMass G o n K (ω ∩ (Q : Set E)) x y := by - intro Q - simp only [binDiagonalMass,finiteClassTransport] - rw [binOrbitClass_local G hloc o n ω x,binSizeMass_local G hloc n ω x] - -theorem binDiagonalMass_integrable (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x y : V) : - Integrable (fun ω => binDiagonalMass G o n K ω x y) (law p) := - integrable_finite_local _ p _ (fun ω => binDiagonalMass_local G hloc o n K ω x y) - -theorem binDiagonalMass_outside (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x y : V) (hy : y ∉ reachBall G x (2*n)) : - binDiagonalMass G o n K ω x y = 0 := - ite_eq_right (fun h => hy (binOrbitClass_reach G o n ω x y h)) - -theorem binDiagonalMass_outside_column (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x y : V) (hx : x ∉ reachBall G y (2*n)) : - binDiagonalMass G o n K ω x y = 0 := - ite_eq_right (fun h => hx (binOrbitClass_reach G o n ω y x ((binOrbitClass_symm G o n ω x y).mp h))) - -theorem binDiagonalMass_row_zero (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x y : V) (hx : x ∉ vertexOrbit G o) : - binDiagonalMass G o n K ω x y = 0 := - ite_eq_right (fun h => hx ((mem_binOrbitClass G o n ω x y).mp h).1) - -theorem binDiagonalMass_column_zero (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x y : V) (hy : y ∉ vertexOrbit G o) : - binDiagonalMass G o n K ω x y = 0 := - ite_eq_right (fun h => hy ((mem_binOrbitClass G o n ω x y).mp h).2.2.2) - -theorem binDiagonalMass_covariant (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (hK : ∀ x y, K (a x) (a y) = K x y) (ω : Set E) (x y : V) : - binDiagonalMass G o n K (b ⁻¹' ω) x y = binDiagonalMass G o n K ω (a x) (a y) := by - have hs := binOrbitClass_covariant G o hab n ω x - have hc : (binOrbitClass G o n (b ⁻¹' ω) x).card = (binOrbitClass G o n ω (a x)).card := by - rw [←hs,Finset.card_image_of_injective _ a.injective] - have hsum : (∑ z ∈ binOrbitClass G o n (b ⁻¹' ω) x, K x z) = - ∑ z ∈ binOrbitClass G o n ω (a x), K (a x) z := by - rw [←hs,Finset.sum_image (fun _ _ _ _ h => a.injective h)] - simp only [hK] - simp only [binDiagonalMass,finiteClassTransport,binOrbitClass_mem_covariant G o hab, - binSizeMass_covariant G n ω hab,hc,hsum] - -theorem binDiagonalMass_row (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x : V) : - (∑' y, binDiagonalMass G o n K ω x y) = - binSizeMass G n ω x ^ 2 * ∑ z ∈ binOrbitClass G o n ω x, K x z := - finiteClassTransport_row _ _ K x - -theorem binDiagonalMass_column (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (ω : Set E) (x : V) : - (∑' y, binDiagonalMass G o n K ω y x) = - binSizeMass G n ω x ^ 2 / (binOrbitClass G o n ω x).card * - ∑ y ∈ binOrbitClass G o n ω x, ∑ z ∈ binOrbitClass G o n ω x, K y z := by - apply finiteClassTransport_column _ _ K (binOrbitClass_symm G o n ω) (binOrbitClass_eq G o n ω) - intro x y hy - rw [binOrbitClass_mass_eq G o n ω x y hy] - -theorem binDiagonalMass_column_le (G : BondGraph V E) (o : V) (n : ℕ) - (K : V → V → ℝ) (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (ω : Set E) (x : V) : - (∑' y, binDiagonalMass G o n K ω y x) ≤ ‖A‖ * binSizeMass G n ω x ^ 2 := by - apply finiteClassTransport_column_le _ _ K (fun _ => sq_nonneg _) - (binOrbitClass_symm G o n ω) (binOrbitClass_eq G o n ω) _ A hA - intro x y hy - rw [binOrbitClass_mass_eq G o n ω x y hy] - -end BinDiagonalTransport -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.Resampling + +namespace OAI + +/-! Kernel Moments for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeletedDomainPotential +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem inducedSusceptibility_nonneg (G : BondGraph V E) (D : Set V) + (p : unitInterval) (x : V) : 0 ≤ inducedSusceptibility G D p x := by + unfold inducedSusceptibility + split_ifs + · exact restrictedSusceptibility_nonneg G _ p x + · rfl + +noncomputable def deletedBoundaryPotential (G : BondGraph V E) (hloc : LocallyFinite G) + (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : ℝ := + ∑ a ∈ ((finite_reachBall hloc x M).toFinset.filter (· ∉ D)), + ∑ b ∈ neighbors G hloc a, inducedSusceptibility G D p b + +theorem deletedBoundaryPotential_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : + 0 ≤ deletedBoundaryPotential G hloc D p x M := by + exact Finset.sum_nonneg (fun a _ => Finset.sum_nonneg (fun b _ => inducedSusceptibility_nonneg G D p b)) + +theorem le_deletedBoundaryPotential (G : BondGraph V E) (hloc : LocallyFinite G) + (D : Set V) (p : unitInterval) (x : V) (M : ℕ) (a b : V) + (ha : a ∈ reachBall G x M) (haD : a ∉ D) (hab : Adj G a b) : + inducedSusceptibility G D p b ≤ deletedBoundaryPotential G hloc D p x M := by + apply le_trans (Finset.single_le_sum (fun z _ => inducedSusceptibility_nonneg G D p z) + ((mem_neighbors G hloc a b).mpr hab)) + apply Finset.single_le_sum (fun z _ => Finset.sum_nonneg (fun y _ => inducedSusceptibility_nonneg G D p y)) + exact Finset.mem_filter.mpr ⟨(finite_reachBall hloc x M).mem_toFinset.mpr ha,haD⟩ + +noncomputable def deletedLocalPotential (G : BondGraph V E) (D : Set V) (p : unitInterval) + (ω : Set E) (x : V) (M : ℕ) : ℝ := + if x ∈ D then intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) else 0 + +theorem deletedLocalPotential_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (D : Set V) (p : unitInterval) (ω : Set E) (x : V) (M : ℕ) : + 0 ≤ deletedLocalPotential G D p ω x M := by + unfold deletedLocalPotential + split_ifs + · rw [intrinsicPotentialMax_eq G hloc] + exact inducedSusceptibility_nonneg G D p _ + · rfl + + + +theorem short_path_deleted_potential_bound [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : Set V) + (p : unitInterval) (hp : 0 < (p:ℝ)) (ω : Set E) (x y : V) (M : ℕ) + (l : List E) (hl : Along G x l y) (hlen : l.length ≤ M) (ho : ∀ e ∈ l, e ∈ ω) + (hfin : ∀ a, Summable (fun z => (law p).real {η | Conn G (η ∩ internalEdges G D) a z})) : + inducedSusceptibility G D p y ≤ deletedLocalPotential G D p ω x M + + (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M := by + have hpM : 0 ≤ (p:ℝ)^(-(M:ℤ)) := zpow_nonneg p.2.1 _ + have hn := deletedLocalPotential_nonneg G hloc D p ω x M + have hb := deletedBoundaryPotential_nonneg G hloc D p x M + by_cases hy : y ∈ D + · rcases hl.last_entrance D hy with ⟨hx,hall⟩ | ⟨a,b,e,l₁,l₂,heq,h₁,he,ha,hbD,h₂,hs⟩ + · have hreach : y ∈ intrinsicBall G (ω ∩ internalEdges G D) x M := + ⟨l,hl,hlen,fun e he => ⟨ho e he,hall e he⟩⟩ + have hh := le_intrinsicPotentialMax G hloc _ x M (inducedSusceptibility G D p) y hreach + change _ ≤ (if x ∈ D then _ else 0) + _ + rw [ite_eq_left hx] + exact hh.trans (le_add_of_nonneg_right (mul_nonneg hpM hb)) + · have hlen₂ : l₂.length ≤ M := by subst l; simp only [List.length_append,List.length_cons] at hlen; omega + have hpath := restrictedSusceptibility_short_path_bound G (internalEdges G D) p hp h₂ hs M hlen₂ hfin + have hχ : inducedSusceptibility G D p y ≤ (p:ℝ)^(-(M:ℤ))*inducedSusceptibility G D p b := by + simpa only [inducedSusceptibility,ite_eq_left hy,ite_eq_left hbD] using hpath + have haBall : a ∈ reachBall G x M := reachBall_mono G x + (show l₁.length ≤ M by subst l; simp only [List.length_append,List.length_cons] at hlen; omega) h₁.mem_reachBall + exact hχ.trans ((mul_le_mul_of_nonneg_left + (le_deletedBoundaryPotential G hloc D p x M a b haBall ha ⟨e,he⟩) hpM).trans + (le_add_of_nonneg_left hn)) + · rw [inducedSusceptibility,ite_eq_right hy] + exact add_nonneg hn (mul_nonneg hpM hb) + +end DeletedDomainPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LocalKernelAction +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +theorem summable_mass_action (q : LocalEndpointRule G hloc O M L) + (ω : Set E) (x : V) (f : V → ℝ) : Summable (fun y => q.mass ω x y * f y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + rw [q.outside_ball_zero ω x y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] + +theorem summable_kernel_action (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (x : V) (f : V → ℝ) : Summable (fun y => q.kernel p x y * f y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + rw [q.kernel_outside_ball_zero p x y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] + +theorem integrable_mass_action (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (x : V) (f : V → ℝ) : + Integrable (fun ω => ∑' y, q.mass ω x y * f y) (law p) := by + apply integrable_finite_local (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset) p + intro ω + exact tsum_congr (fun y => congrArg (· * f y) (q.locality ω x y)) + +theorem kernel_action_integral (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (x : V) (f : V → ℝ) : + (∑' y, q.kernel p x y * f y) = ∫ ω, (∑' y, q.mass ω x y * f y) ∂law p := by + let B := (finite_reachBall hloc x M).toFinset + have h₁ : (∑' y, q.kernel p x y*f y) = ∑ y ∈ B, q.kernel p x y*f y := + tsum_eq_sum fun y hy => by + rw [q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul] + have h₂ (ω : Set E) : (∑' y, q.mass ω x y*f y) = ∑ y ∈ B, q.mass ω x y*f y := + tsum_eq_sum fun y hy => by + rw [q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul] + rw [h₁] + simp_rw [h₂] + rw [integral_finsetSum B (fun y _ => (q.integrable_mass p x y).mul_const (f y))] + apply Finset.sum_congr rfl + intro y _ + exact (integral_mul_const (f y) (fun ω => q.mass ω x y)).symm + +theorem mass_action_le (q : LocalEndpointRule G hloc O M L) + (ω : Set E) (x : V) (f : V → ℝ) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ y, q.mass ω x y ≠ 0 → f y ≤ C) : + (∑' y, q.mass ω x y * f y) ≤ C := by + calc + _ ≤ ∑' y, q.mass ω x y * C := by + apply (q.summable_mass_action ω x f).tsum_le_tsum _ ((q.summable_mass ω x).mul_right C) + intro y + by_cases h : q.mass ω x y = 0 + · simp only [h,zero_mul,le_refl] + · exact mul_le_mul_of_nonneg_left (hf y h) (q.nonneg ω x y) + _ = (∑' y, q.mass ω x y)*C := tsum_mul_right + _ ≤ C := by simpa only [one_mul] using mul_le_mul_of_nonneg_right (q.row_le_one ω x) hC + +end LocalEndpointRule +end LocalKernelAction +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LocalMapDeletedPotential +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integrable_deletedLocalPotential (G : BondGraph V E) (hloc : LocallyFinite G) + (D : Set V) (p : unitInterval) (x : V) (M : ℕ) : + Integrable (fun ω => deletedLocalPotential G D p ω x M) (law p) := by + by_cases hx : x ∈ D + · simp only [deletedLocalPotential,ite_eq_left hx] + exact integrable_finite_local _ p _ (fun ω => + intrinsicPotentialMax_domain_local G hloc (internalEdges G D) ω x M (inducedSusceptibility G D p)) + · simp only [deletedLocalPotential,ite_eq_right hx] + exact integrable_const 0 + +theorem integral_deletedLocalPotential_le + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (D : Set V) (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x : V) (M : ℕ) : + (∫ ω, deletedLocalPotential G D p ω x M ∂law p) ≤ + (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x := by + by_cases hx : x ∈ D + · simp only [deletedLocalPotential,ite_eq_left hx] + exact maximal_induced_susceptibility_bound G hloc hqt D x hx M p hp hpc + · simp only [deletedLocalPotential,inducedSusceptibility,ite_eq_right hx,integral_zero,mul_zero,le_refl] + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +theorem kernel_deleted_potential_bound + [Countable V] [Countable E] [Nonempty V] + (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) + (D : Set V) (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x : V) : + (∑' y, q.kernel p x y * inducedSusceptibility G D p y) ≤ + (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x + + (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M := by + let f := inducedSusceptibility G D p + let C := (p:ℝ)^(-(M:ℤ))*deletedBoundaryPotential G hloc D p x M + have hC : 0 ≤ C := mul_nonneg (zpow_nonneg p.2.1 _) (deletedBoundaryPotential_nonneg G hloc D p x M) + have hpoint (ω : Set E) : (∑' y, q.mass ω x y * f y) ≤ deletedLocalPotential G D p ω x M + C := by + apply q.mass_action_le ω x f _ (add_nonneg (deletedLocalPotential_nonneg G hloc D p ω x M) hC) + intro y hy + obtain ⟨_,_,hxy,hfin,hcap,_⟩ := q.support ω x y hy + obtain ⟨l,hl,hlen,ho⟩ := conn_short_of_cluster_cap G ω x y hxy hfin M hcap + exact short_path_deleted_potential_bound G hloc D p hp ω x y M l hl hlen ho + (summable_restrictedTwoPoint G hloc hqt p hpc (internalEdges G D)) + rw [q.kernel_action_integral] + have hi := integrable_deletedLocalPotential G hloc D p x M + calc + _ ≤ ∫ ω, deletedLocalPotential G D p ω x M + C ∂law p := + integral_mono (q.integrable_mass_action p x f) (hi.add (integrable_const C)) hpoint + _ = (∫ ω, deletedLocalPotential G D p ω x M ∂law p) + C := by + rw [integral_add hi (integrable_const C)]; simp + _ ≤ _ := by + have hh := integral_deletedLocalPotential_le G hloc hqt D p hp hpc x M + dsimp [C] + linarith + +end LocalEndpointRule +end LocalMapDeletedPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OrbitKernelTransport +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem orbit_kernel_column_eq_row + (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) (K : V → V → ℝ) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) + (hout : ∀ x y, x ∉ vertexOrbit G (root i₀) → K x y = 0) + (hin : ∀ x y, y ∉ vertexOrbit G (root i₀) → K x y = 0) + (hr : ∀ x, Summable (K x)) (hc : ∀ y, Summable (fun x => K x y)) + (y : V) (hy : y ∈ vertexOrbit G (root i₀)) : + (∑' x, K x y) = ∑' z, K (root i₀) z := by + let O := vertexOrbit G (root i₀) + let w : ι → ℝ := fun i => if root i ∈ O then weight i else 0 + have hrow (x : V) (hx : x ∈ O) : (∑' z, K x z) = ∑' z, K (root i₀) z := by + obtain ⟨a,b,ha,rfl⟩ := hx + rw [← a.tsum_eq (fun z => K (a (root i₀)) z)] + exact tsum_congr (hcov a b ha (root i₀)) + have hcol (x : V) (hx : x ∈ O) : (∑' z, K z x) = ∑' z, K z (root i₀) := by + obtain ⟨a,b,ha,rfl⟩ := hx + rw [← a.tsum_eq (fun z => K z (a (root i₀)))] + exact tsum_congr (fun z => hcov a b ha z (root i₀)) + have ho : root i₀ ∈ O := by + refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ + intro e; simp + have hw' (i : ι) : 0 ≤ w i := by + dsimp [w]; split_ifs + · exact hw i + · rfl + have hpos : 0 < ∑ i, w i := by + have hi := Finset.single_le_sum (fun i _ => hw' i) (Finset.mem_univ i₀) + have he : w i₀ = weight i₀ := ite_eq_left ho + rw [he] at hi + exact hw₀.trans_le hi + have ht := htr.real root weight Γ K + (by intro a ha x z; obtain ⟨b,hb⟩ := hΓ a ha; exact hcov a b hb x z) hr hc + have h₁ (i : ι) : weight i * (∑' z, K (root i) z) = w i * (∑' z, K (root i₀) z) := by + by_cases hi : root i ∈ O + · rw [hrow (root i) hi]; simp only [w,ite_eq_left hi] + · simp only [w,ite_eq_right hi,zero_mul] + have he : (∑' z, K (root i) z) = 0 := by simp only [hout _ _ hi,tsum_zero] + rw [he,mul_zero] + have h₂ (i : ι) : weight i * (∑' z, K z (root i)) = w i * (∑' z, K z (root i₀)) := by + by_cases hi : root i ∈ O + · rw [hcol (root i) hi]; simp only [w,ite_eq_left hi] + · simp only [w,ite_eq_right hi,zero_mul] + have he : (∑' z, K z (root i)) = 0 := by simp only [hin _ _ hi,tsum_zero] + rw [he,mul_zero] + simp_rw [h₁,h₂] at ht + rw [← Finset.sum_mul,← Finset.sum_mul] at ht + rw [hcol y hy] + exact (mul_left_cancel₀ (ne_of_gt hpos) ht).symm + + + +theorem operator_norm_le_absolute_sums (K : V → V → ℝ) (D : ℝ) (hD : 0 ≤ D) + (hr : ∀ x (S : Finset V), (∑ y ∈ S, |K x y|) ≤ D) + (hc : ∀ y (S : Finset V), (∑ x ∈ S, |K x y|) ≤ D) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) : ‖A‖ ≤ D := by + obtain ⟨B,hBn,hB⟩ := exists_operator_of_row_column_bound (fun x y => |K x y|) D hD + (fun _ _ => abs_nonneg _) hr hc + obtain ⟨A',hAn,hA'⟩ := exists_operator_of_matrix_domination + (fun x y => |K x y|) K (fun _ _ => abs_nonneg _) (fun _ _ => le_rfl) B hB + have he := kernel_extension_unique hA hA' + rw [he] + exact hAn.trans hBn + +end OrbitKernelTransport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EndpointDifference +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} +variable (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + +noncomputable def kernelDifference (p r : unitInterval) (x y : V) : ℝ := + |q.normalizedKernel o p x y - q.normalizedKernel o r x y| +noncomputable def differenceRow (p r : unitInterval) : ℝ := ∑' y, q.kernelDifference o p r o y + +theorem kernelDifference_nonneg (p r : unitInterval) (x y : V) : + 0 ≤ q.kernelDifference o p r x y := abs_nonneg _ + +theorem kernelDifference_covariant (p r : unitInterval) + (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x y : V) : + q.kernelDifference o p r (a x) (a y) = q.kernelDifference o p r x y := by + simp only [kernelDifference,normalizedKernel,q.kernel_covariant p a b ha,q.kernel_covariant r a b ha] + +theorem kernelDifference_outside (p r : unitInterval) (x y : V) (hy : y ∉ reachBall G x M) : + q.kernelDifference o p r x y = 0 := by + simp only [kernelDifference,normalizedKernel,q.kernel_outside_ball_zero p x y hy, + q.kernel_outside_ball_zero r x y hy,mul_zero,sub_self,abs_zero] + +theorem kernelDifference_reverse_outside (p r : unitInterval) (x y : V) (hx : x ∉ reachBall G y M) : + q.kernelDifference o p r x y = 0 := by + simp only [kernelDifference,normalizedKernel,q.kernel_outside_reverse_ball_zero p x y hx, + q.kernel_outside_reverse_ball_zero r x y hx,mul_zero,sub_self,abs_zero] + +theorem kernelDifference_start (p r : unitInterval) (x y : V) (hx : x ∉ vertexOrbit G o) : + q.kernelDifference o p r x y = 0 := by + simp only [kernelDifference,normalizedKernel,q.kernel_zero_of_start_not_mem p x y hx, + q.kernel_zero_of_start_not_mem r x y hx,mul_zero,sub_self,abs_zero] + +theorem kernelDifference_end (p r : unitInterval) (x y : V) (hy : y ∉ vertexOrbit G o) : + q.kernelDifference o p r x y = 0 := by + simp only [kernelDifference,normalizedKernel,q.kernel_zero_of_end_not_mem p x y hy, + q.kernel_zero_of_end_not_mem r x y hy,mul_zero,sub_self,abs_zero] + +theorem summable_kernelDifference (p r : unitInterval) (x : V) : + Summable (q.kernelDifference o p r x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + exact q.kernelDifference_outside o p r x y (by simpa only [Set.Finite.mem_toFinset] using hy) + +theorem summable_kernelDifference_column (p r : unitInterval) (y : V) : + Summable (fun x => q.kernelDifference o p r x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y M).toFinset) + intro x hx + exact q.kernelDifference_reverse_outside o p r x y (by simpa only [Set.Finite.mem_toFinset] using hx) + +theorem differenceRow_nonneg (p r : unitInterval) : 0 ≤ q.differenceRow o p r := + tsum_nonneg (q.kernelDifference_nonneg o p r o) + +theorem differenceRow_finite (p r : unitInterval) : + q.differenceRow o p r = ∑ y ∈ (finite_reachBall hloc o M).toFinset, q.kernelDifference o p r o y := by + apply tsum_eq_sum + intro y hy + exact q.kernelDifference_outside o p r o y (by simpa only [Set.Finite.mem_toFinset] using hy) + +theorem kernelDifference_row_le (p r : unitInterval) (x : V) : + (∑' y, q.kernelDifference o p r x y) ≤ q.differenceRow o p r := by + by_cases hx : x ∈ vertexOrbit G o + · obtain ⟨a,b,ha,rfl⟩ := hx + rw [← a.tsum_eq (fun y => q.kernelDifference o p r (a o) y)] + exact le_of_eq (tsum_congr (q.kernelDifference_covariant o p r a b ha o)) + · simpa only [q.kernelDifference_start o p r x _ hx,tsum_zero] using q.differenceRow_nonneg o p r + + + +theorem norm_sub_le_differenceRow {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) (ho : o = root i₀) + (p r : unitInterval) (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel o p x y : ℂ)) + (hB : ∀ x y, B (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel o r x y : ℂ)) : + ‖A-B‖ ≤ q.differenceRow o p r := by + subst o + have hc (y : V) : (∑' x, q.kernelDifference (root i₀) p r x y) ≤ q.differenceRow (root i₀) p r := by + by_cases hy : y ∈ vertexOrbit G (root i₀) + · exact (orbit_kernel_column_eq_row G root weight Γ htr hΓ hw i₀ hw₀ + (q.kernelDifference (root i₀) p r) (q.kernelDifference_covariant (root i₀) p r) + (q.kernelDifference_start (root i₀) p r) (q.kernelDifference_end (root i₀) p r) + (q.summable_kernelDifference (root i₀) p r) (q.summable_kernelDifference_column (root i₀) p r) y hy).le + · simpa only [q.kernelDifference_end (root i₀) p r _ y hy,tsum_zero] using + q.differenceRow_nonneg (root i₀) p r + apply operator_norm_le_absolute_sums + (fun x y => q.normalizedKernel (root i₀) p x y-q.normalizedKernel (root i₀) r x y) + _ (q.differenceRow_nonneg (root i₀) p r) + · intro x S + exact ((q.summable_kernelDifference (root i₀) p r x).sum_le_tsum S + (fun y _ => q.kernelDifference_nonneg (root i₀) p r x y)).trans (q.kernelDifference_row_le (root i₀) p r x) + · intro y S + exact ((q.summable_kernelDifference_column (root i₀) p r y).sum_le_tsum S + (fun x _ => q.kernelDifference_nonneg (root i₀) p r x y)).trans (hc y) + · intro x y + change A (lp.single 2 y (1:ℂ)) x - B (lp.single 2 y (1:ℂ)) x = _ + rw [hA,hB,Complex.ofReal_sub] + +end LocalEndpointRule +end EndpointDifference +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section EndpointOperatorContinuity +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem exists_normalized_operator_all {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (p : unitInterval) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ 1 ∧ + ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ) := by + by_cases hu : q.successProbability p (root i₀) = 0 + · refine ⟨0,by simp,?_⟩ + intro x y + simp only [normalizedKernel,hu,inv_zero,zero_mul,Complex.ofReal_zero, + zero_apply,lp.coeFn_zero,Pi.zero_apply] + · obtain ⟨A,_,hA,hK⟩ := q.exists_normalized_operator root weight Γ htr hΓ hw i₀ hw₀ p + (lt_of_le_of_ne (q.successProbability_nonneg p (root i₀)) (Ne.symm hu)) + exact ⟨A,hA,hK⟩ + +theorem continuousAt_differenceRow (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p₀ : unitInterval) + (hu : q.successProbability p₀ o ≠ 0) : + ContinuousAt (fun p => q.differenceRow o p p₀) p₀ := by + simp_rw [q.differenceRow_finite o] + apply tendsto_finsetSum + intro y _ + exact ((((q.continuous_successProbability o).continuousAt.inv₀ hu).mul + (q.continuous_kernel o y).continuousAt).sub continuousAt_const).abs + + + +theorem exists_continuous_normalized_operators {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) : + ∃ A : unitInterval → (Hilbert V →L[ℂ] Hilbert V), + (∀ p, ‖A p‖ ≤ 1) ∧ + (∀ p x y, A p (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ)) ∧ + ∀ p, q.successProbability p (root i₀) ≠ 0 → ContinuousAt A p := by + choose A hn hK using q.exists_normalized_operator_all root weight Γ htr hΓ hw i₀ hw₀ + refine ⟨A,hn,hK,?_⟩ + intro p hu + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero (fun r => norm_nonneg (A r-A p)) + (fun r => q.norm_sub_le_differenceRow (root i₀) root weight Γ htr hΓ hw i₀ hw₀ rfl r p (A r) (A p) (hK r) (hK p)) + have h := (q.continuousAt_differenceRow (root i₀) p hu).tendsto + have hz : q.differenceRow (root i₀) p p = 0 := by + simp only [differenceRow,kernelDifference,sub_self,abs_zero,tsum_zero] + rwa [hz] at h + +end LocalEndpointRule +end EndpointOperatorContinuity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ThreeArmGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem Along.first_entrance {G : BondGraph V E} {x y : V} {l : List E} + (hl : Along G x l y) (D : Set V) (hy : y ∈ D) : + ∃ z ∈ D, ∃ k : List E, Along G x k z ∧ k ⊆ l ∧ ∀ e ∈ k, e ∉ internalEdges G D := by + induction hl with + | nil => exact ⟨_,hy,[],.nil _,by simp,by simp⟩ + | @cons x z y l e he ht ih => + by_cases hx : x ∈ D + · exact ⟨x,hx,[],.nil _,by simp,by simp⟩ + · obtain ⟨w,hw,k,hk,hsub,hout⟩ := ih hy + refine ⟨w,hw,e::k,.cons e he hk,?_,?_⟩ + · intro d hd + rcases List.mem_cons.mp hd with rfl | hd + · exact List.mem_cons_self + · exact List.mem_cons_of_mem _ (hsub hd) + · intro d hd + rcases List.mem_cons.mp hd with rfl | hd + · intro h + exact hx ((mem_internalEdges_of_ends G D d x z he).mp h).1 + · exact hout d hd + + + +theorem conn_three_disjoint_arms (G : BondGraph V E) (ω : Set E) (x y z : V) + (hxy : Conn G ω x y) (hxz : Conn G ω x z) : + ∃ w, ω ∈ DisjointOccurrence {η | Conn G η x w} + (DisjointOccurrence {η | Conn G η w y} {η | Conn G η w z}) := by + obtain ⟨p⟩ := (conn_iff_reachable G ω x y).mp hxy + let t := p.toPath + let D : Set V := {a | a ∈ t.val.support} + obtain ⟨l,hl,_,ho⟩ := conn_exists_bond_trail G (conn_symm G ω hxz) + obtain ⟨w,hw,k,hk,hsub,hout⟩ := hl.first_entrance D t.val.start_mem_support + obtain ⟨l₁,h₁,he₁,ho₁⟩ := walk_lift_bonds G ω (t.val.takeUntil w hw) + obtain ⟨l₂,h₂,he₂,ho₂⟩ := walk_lift_bonds G ω (t.val.dropUntil w hw) + have h₁in (e : E) (he : e ∈ l₁) : e ∈ internalEdges G D := by + have hh : G e ∈ (t.val.takeUntil w hw).edges := he₁ ▸ List.mem_map_of_mem he + have hh' := t.val.edges_takeUntil_subset_edges hw hh + intro a ha + exact SimpleGraph.Walk.mem_support_of_mem_edges hh' ha + have h₂in (e : E) (he : e ∈ l₂) : e ∈ internalEdges G D := by + have hh : G e ∈ (t.val.dropUntil w hw).edges := he₂ ▸ List.mem_map_of_mem he + have hh' := t.val.edges_dropUntil_subset_edges hw hh + intro a ha + exact SimpleGraph.Walk.mem_support_of_mem_edges hh' ha + have h12 : Disjoint l₁.toFinset l₂.toFinset := by + apply Finset.disjoint_left.mpr + intro e he₁' he₂' + have hp := t.property.isTrail.disjoint_edges_takeUntil_dropUntil hw + exact List.disjoint_left.mp hp (he₁ ▸ List.mem_map_of_mem (List.mem_toFinset.mp he₁')) + (he₂ ▸ List.mem_map_of_mem (List.mem_toFinset.mp he₂')) + have h13 : Disjoint l₁.toFinset k.toFinset := by + apply Finset.disjoint_left.mpr + intro e he hk' + exact hout e (List.mem_toFinset.mp hk') (h₁in e (List.mem_toFinset.mp he)) + have h23 : Disjoint l₂.toFinset k.toFinset := by + apply Finset.disjoint_left.mpr + intro e he hk' + exact hout e (List.mem_toFinset.mp hk') (h₂in e (List.mem_toFinset.mp he)) + have hkopen (e : E) (he : e ∈ k) : e ∈ ω := ho e (hsub he) + refine ⟨w,l₁.toFinset,l₂.toFinset ∪ k.toFinset,?_,?_,Finset.disjoint_union_right.mpr ⟨h12,h13⟩,?_,?_⟩ + · intro e he; exact ho₁ e (List.mem_toFinset.mp he) + · intro e he + rcases Finset.mem_union.mp he with he | he + · exact ho₂ e (List.mem_toFinset.mp he) + · exact hkopen e (List.mem_toFinset.mp he) + · exact h₁.conn (fun e he => List.mem_toFinset.mpr he) + · refine ⟨l₂.toFinset,k.toFinset,?_,?_,h23,?_,?_⟩ + · exact_mod_cast Finset.subset_union_left + · exact_mod_cast Finset.subset_union_right + · exact h₂.conn (fun e he => List.mem_toFinset.mpr he) + · exact conn_symm G _ (hk.conn (fun e he => List.mem_toFinset.mpr he)) + +end ThreeArmGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ThreeArmProbability +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem bk_ennreal [Countable E] (p : unitInterval) (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) (hfA : FiniteWitness A) (hfB : FiniteWitness B) : + law p (DisjointOccurrence A B) ≤ law p A * law p B := by + apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) + (ENNReal.mul_ne_top (measure_ne_top _ _) (measure_ne_top _ _))).mp + rw [ENNReal.toReal_mul] + exact bk p A B hA hB hfA hfB + + + +theorem three_arm_bound [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y z : V) : + law p {ω | Conn G ω x y ∧ Conn G ω x z} ≤ + ∑' w, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := by + let C := fun a b : V => {ω : Set E | Conn G ω a b} + have hup (a b : V) : IsUpperSet (C a b) := fun _ _ h hconn => conn_mono G h hconn + have hf (a b : V) : FiniteWitness (C a b) := finiteWitness_conn G a b + have hb (w : V) : law p (DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) ≤ + law p (C x w) * law p (C w y) * law p (C w z) := by + calc + _ ≤ law p (C x w) * law p (DisjointOccurrence (C w y) (C w z)) := + bk_ennreal p _ _ (hup x w) (disjointOccurrence_upper _ _) (hf x w) (finiteWitness_disjointOccurrence _ _) + _ ≤ law p (C x w) * (law p (C w y)*law p (C w z)) := + mul_le_mul_right (bk_ennreal p _ _ (hup w y) (hup w z) (hf w y) (hf w z)) _ + _ = _ := (mul_assoc _ _ _).symm + calc + _ ≤ law p (⋃ w, DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) := by + apply measure_mono + intro ω h + obtain ⟨w,hw⟩ := conn_three_disjoint_arms G ω x y z h.1 h.2 + exact Set.mem_iUnion.mpr ⟨w,hw⟩ + _ ≤ ∑' w, law p (DisjointOccurrence (C x w) (DisjointOccurrence (C w y) (C w z))) := measure_iUnion_le _ + _ ≤ _ := ENNReal.tsum_le_tsum hb + + + +theorem three_arm_double_sum_bound [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (C : ℝ≥0∞) + (hC : ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ C) (x : V) : + (∑' y, ∑' z, law p {ω | Conn G ω x y ∧ Conn G ω x z}) ≤ C^3 := by + calc + _ ≤ ∑' y, ∑' z, ∑' w, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := + ENNReal.tsum_le_tsum (fun y => ENNReal.tsum_le_tsum (fun z => three_arm_bound G p x y z)) + _ = ∑' w, law p {ω | Conn G ω x w} * (∑' y, law p {ω | Conn G ω w y}) * + (∑' z, law p {ω | Conn G ω w z}) := by + calc + _ = ∑' y, ∑' w, ∑' z, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := by + apply tsum_congr + intro y + exact ENNReal.tsum_comm + _ = ∑' w, ∑' y, ∑' z, law p {ω | Conn G ω x w} * law p {ω | Conn G ω w y} * law p {ω | Conn G ω w z} := ENNReal.tsum_comm + _ = _ := by simp_rw [ENNReal.tsum_mul_left,ENNReal.tsum_mul_right,ENNReal.tsum_mul_left] + _ ≤ ∑' w, law p {ω | Conn G ω x w} * C * C := + ENNReal.tsum_le_tsum (fun w => mul_le_mul' (mul_le_mul_right (hC w) _) (hC w)) + _ = (∑' w, law p {ω | Conn G ω x w}) * C * C := by + rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_right] + _ ≤ C*C*C := mul_le_mul_left (mul_le_mul_left (hC x) C) C + _ = C^3 := by ring + +end ThreeArmProbability +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ClusterMassMoments +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def clusterMass (G : BondGraph V E) (ω : Set E) (x : V) : ℝ≥0∞ := + ∑' y, if Conn G ω x y then 1 else 0 + +theorem measurable_clusterMass [Countable V] [Countable E] + (G : BondGraph V E) (x : V) : Measurable (fun ω => clusterMass G ω x) := by + apply Measurable.tsum + intro y + exact Measurable.ite (measurableSet_conn G x y) measurable_const measurable_const + +theorem clusterMass_eq_ncard (G : BondGraph V E) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : clusterMass G ω x = (cluster G ω x).ncard := by + change (∑' y, if y ∈ cluster G ω x then (1:ℝ≥0∞) else 0) = _ + rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by + simp only [Set.Finite.mem_toFinset] at hy + simp only [ite_eq_right hy])] + have he : (∑ y ∈ hf.toFinset, if y ∈ cluster G ω x then (1:ℝ≥0∞) else 0) = ∑ _y ∈ hf.toFinset, (1:ℝ≥0∞) := by + apply Finset.sum_congr rfl + intro y hy + exact ite_eq_left (hf.mem_toFinset.mp hy) + rw [he] + simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] + +theorem lintegral_clusterMass [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x : V) : + (∫⁻ ω, clusterMass G ω x ∂law p) = ∑' y, law p {ω | Conn G ω x y} := by + unfold clusterMass + rw [lintegral_tsum (fun y => (Measurable.ite (measurableSet_conn G x y) measurable_const measurable_const).aemeasurable)] + apply tsum_congr + intro y + simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) (measurableSet_conn G x y)) + +theorem clusterMass_sq (G : BondGraph V E) (ω : Set E) (x : V) : + clusterMass G ω x ^ 2 = ∑' y, ∑' z, if Conn G ω x y ∧ Conn G ω x z then (1:ℝ≥0∞) else 0 := by + rw [pow_two,clusterMass] + rw [←ENNReal.tsum_mul_right] + apply tsum_congr + intro y + rw [←ENNReal.tsum_mul_left] + apply tsum_congr + intro z + split_ifs <;> simp_all + +theorem lintegral_clusterMass_sq [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (x : V) : + (∫⁻ ω, clusterMass G ω x ^ 2 ∂law p) = + ∑' y, ∑' z, law p {ω | Conn G ω x y ∧ Conn G ω x z} := by + have hm (y z : V) : Measurable (fun ω : Set E => if Conn G ω x y ∧ Conn G ω x z then (1:ℝ≥0∞) else 0) := + Measurable.ite ((measurableSet_conn G x y).inter (measurableSet_conn G x z)) measurable_const measurable_const + simp_rw [clusterMass_sq] + rw [lintegral_tsum (fun y => (Measurable.tsum (fun z => hm y z)).aemeasurable)] + apply tsum_congr + intro y + rw [lintegral_tsum (fun z => (hm y z).aemeasurable)] + apply tsum_congr + intro z + have hs : MeasurableSet {ω : Set E | Conn G ω x y ∧ Conn G ω x z} := + (measurableSet_conn G x y).inter (measurableSet_conn G x z) + simpa only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] using (lintegral_indicator_one (μ := law p) hs) + + +theorem cluster_second_moment_bound [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (C : ℝ≥0∞) + (hC : ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ C) (x : V) : + (∫⁻ ω, clusterMass G ω x ^ 2 ∂law p) ≤ C^3 := by + rw [lintegral_clusterMass_sq] + exact three_arm_double_sum_bound G p C hC x + +end ClusterMassMoments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section SubcriticalMoments +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem subcritical_cluster_finite_ae (G : BondGraph V E) + (p : unitInterval) (hp : p < pc G) (x : V) : + ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by + have hz : (law p).real {ω | (cluster G ω x).Infinite} = 0 := by + apply le_antisymm _ measureReal_nonneg + by_contra! h + exact (not_le_of_gt hp) (pc_le_of_infinite_cluster_probability_pos G x p h) + apply ae_iff.mpr + change law p {ω | (cluster G ω x).Infinite} = 0 + exact ((ENNReal.toReal_eq_zero_iff _).mp hz).resolve_right (measure_ne_top _ _) + +theorem subcritical_ennreal_row_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ x, (∑' y, law p {ω | Conn G ω x y}) ≤ ENNReal.ofReal C := by + obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp + refine ⟨C,hC,fun x => ?_⟩ + have hs := summable_of_sum_le (twoPoint_nonneg G p x) (hrow x) + have he : (∑' y, law p {ω | Conn G ω x y}) = ENNReal.ofReal (∑' y, twoPoint G p x y) := by + rw [ENNReal.ofReal_tsum_of_nonneg (twoPoint_nonneg G p x) hs] + apply tsum_congr + intro y + exact (ENNReal.ofReal_toReal (measure_ne_top _ _)).symm + rw [he] + exact ENNReal.ofReal_le_ofReal (hs.tsum_le_of_sum_le (hrow x)) + + + +theorem subcritical_second_moment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ x, + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p) ∧ + (∫ ω, ((cluster G ω x).ncard:ℝ)^2 ∂law p) ≤ C^3 := by + obtain ⟨C,hC,hrow⟩ := subcritical_ennreal_row_bound G hloc hqt p hp + refine ⟨C,hC,fun x => ?_⟩ + have hmeas : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^2) := + (measurable_of_countable (fun n : ℕ => (n:ℝ)^2)).comp (measurable_cluster_ncard G hloc x) + have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)^2) := + Filter.Eventually.of_forall (fun _ => sq_nonneg _) + have he : (fun ω => ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2)) =ᵐ[law p] + (fun ω => clusterMass G ω x ^ 2) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_pow (Nat.cast_nonneg _)] + simp only [ENNReal.ofReal_natCast] + have hbound : (∫⁻ ω, ENNReal.ofReal (((cluster G ω x).ncard:ℝ)^2) ∂law p) ≤ ENNReal.ofReal (C^3) := by + rw [lintegral_congr_ae he,ENNReal.ofReal_pow hC] + exact cluster_second_moment_bound G p _ hrow x + have hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p) := + ⟨hmeas.aestronglyMeasurable,(hasFiniteIntegral_iff_ofReal hn).mpr + (hbound.trans_lt ENNReal.ofReal_lt_top)⟩ + refine ⟨hi,?_⟩ + rw [integral_eq_lintegral_of_nonneg_ae hn hmeas.aestronglyMeasurable] + exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hbound).trans_eq (ENNReal.toReal_ofReal (pow_nonneg hC _)) + +end SubcriticalMoments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section SusceptibilityTypes +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def susceptibility (G : BondGraph V E) (p : unitInterval) (x : V) : ℝ := + ∑' y, twoPoint G p x y + +noncomputable def rootSusceptibility (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : ℝ := + ∑ i, weight i * susceptibility G p (root i) + +theorem susceptibility_nonneg (G : BondGraph V E) (p : unitInterval) (x : V) : + 0 ≤ susceptibility G p x := tsum_nonneg (twoPoint_nonneg G p x) + +theorem summable_twoPoint_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : Summable (twoPoint G p x) := by + obtain ⟨_,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp + exact summable_of_sum_le (twoPoint_nonneg G p x) (hrow x) + +theorem ennreal_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + ENNReal.ofReal (susceptibility G p x) = ∑' y, law p {ω | Conn G ω x y} := by + rw [susceptibility,ENNReal.ofReal_tsum_of_nonneg (twoPoint_nonneg G p x) + (summable_twoPoint_subcritical G hloc hqt p hp x)] + apply tsum_congr + intro y + exact ENNReal.ofReal_toReal (measure_ne_top _ _) + +theorem susceptibility_aut [Countable V] [Countable E] (G : BondGraph V E) + (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : + susceptibility G p (a x) = susceptibility G p x := by + unfold susceptibility + rw [←a.tsum_eq] + simp only [twoPoint_aut G p h] + +theorem susceptibility_one_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : 1 ≤ susceptibility G p x := by + have hd : twoPoint G p x x = 1 := by + have he : {ω : Set E | Conn G ω x x} = Set.univ := Set.eq_univ_of_forall (fun _ => conn_refl G _ x) + simp only [twoPoint,he,measure_univ,ENNReal.toReal_one] + rw [←hd] + exact (summable_twoPoint_subcritical G hloc hqt p hp x).le_tsum x (fun _ _ => twoPoint_nonneg G p _ _) + +theorem rootSusceptibility_nonneg (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) : + 0 ≤ rootSusceptibility G root weight p := + Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (susceptibility_nonneg G p _)) + +theorem susceptibility_le_rootSusceptibility [Countable V] [Countable E] + (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (hcov : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (p : unitInterval) (x : V) : + susceptibility G p x ≤ c*rootSusceptibility G root weight p := by + obtain ⟨i,a,b,hab,hax⟩ := hcov x + rw [←hax,susceptibility_aut G p hab] + calc + _ ≤ (c*weight i)*susceptibility G p (root i) := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) (susceptibility_nonneg G p _) + _ = c*(weight i*susceptibility G p (root i)) := mul_assoc _ _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left + (Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (susceptibility_nonneg G p _)) (Finset.mem_univ i)) hc + + +theorem susceptibility_eq_integral [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)) (law p) ∧ + susceptibility G p x = ∫ ω, ((cluster G ω x).ncard:ℝ) ∂law p := by + have hm : Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)) := + (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x) + have hn : 0 ≤ᵐ[law p] (fun ω => ((cluster G ω x).ncard:ℝ)) := Filter.Eventually.of_forall (fun _ => Nat.cast_nonneg _) + have he : (fun ω => ENNReal.ofReal ((cluster G ω x).ncard:ℝ)) =ᵐ[law p] (fun ω => clusterMass G ω x) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [clusterMass_eq_ncard G ω x hω,ENNReal.ofReal_natCast] + have heq : (∫⁻ ω, ENNReal.ofReal ((cluster G ω x).ncard:ℝ) ∂law p) = ENNReal.ofReal (susceptibility G p x) := by + rw [lintegral_congr_ae he,lintegral_clusterMass,ennreal_susceptibility G hloc hqt p hp] + refine ⟨⟨hm.aestronglyMeasurable,(hasFiniteIntegral_iff_ofReal hn).mpr (by rw [heq]; exact ENNReal.ofReal_lt_top)⟩,?_⟩ + rw [integral_eq_lintegral_of_nonneg_ae hn hm.aestronglyMeasurable,heq,ENNReal.toReal_ofReal (susceptibility_nonneg G p x)] + +end SusceptibilityTypes +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteKernelNorm +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem kernel_sum_le_norm_card (K : V → V → ℝ) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (F : Finset V) : + ∑ x ∈ F, ∑ y ∈ F, K x y ≤ ‖A‖*F.card := by + have he : inner ℂ (deltaSum F) (A (deltaSum F)) = + ((∑ x ∈ F, ∑ y ∈ F, K x y : ℝ) : ℂ) := by + rw [inner_deltaSum] + simp only [deltaSum,map_sum,lp.coeFn_sum,Finset.sum_apply,Complex.ofReal_sum] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + exact hA x y + have h := (Complex.re_le_norm (inner ℂ (deltaSum F) (A (deltaSum F)))).trans + ((norm_inner_le_norm _ _).trans + (mul_le_mul_of_nonneg_left (A.le_opNorm _) (norm_nonneg _))) + rw [he,Complex.ofReal_re] at h + calc + _ ≤ ‖deltaSum F‖*(‖A‖*‖deltaSum F‖) := h + _ = ‖A‖*‖deltaSum F‖^2 := by ring + _ = _ := by rw [norm_deltaSum_sq] + + +theorem kernel_average_le_norm (K : V → V → ℝ) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) + (F : Finset V) (hF : F.Nonempty) : + (∑ x ∈ F, ∑ y ∈ F, K x y)/(F.card:ℝ) ≤ ‖A‖ := by + exact (div_le_iff₀ (Nat.cast_pos.mpr hF.card_pos)).mpr (kernel_sum_le_norm_card K A hA F) + +end FiniteKernelNorm +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BinClusterSlice +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binClusterSlice (G : BondGraph V E) (o : V) (n : ℕ) + (ω : Set E) (x : V) : Finset V := + if h : ClusterWindow G x n (2*n) ω then h.1.toFinset.filter (fun y => y ∈ vertexOrbit G o) else ∅ + +theorem mem_binClusterSlice (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : + y ∈ binClusterSlice G o n ω x ↔ ClusterWindow G x n (2*n) ω ∧ Conn G ω x y ∧ y ∈ vertexOrbit G o := by + unfold binClusterSlice + split_ifs with h + · simp only [Finset.mem_filter,Set.Finite.mem_toFinset,h,true_and,cluster,Set.mem_ofPred_eq] + · simp only [Finset.notMem_empty,h,false_and] + +theorem binClusterSlice_eq_of_conn (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) + {x y : V} (h : Conn G ω x y) : binClusterSlice G o n ω x = binClusterSlice G o n ω y := by + have hc := cluster_eq_of_conn G ω h + have hw : ClusterWindow G x n (2*n) ω ↔ ClusterWindow G y n (2*n) ω := by + unfold ClusterWindow + rw [hc] + ext z + simp only [mem_binClusterSlice,hw] + have hz : Conn G ω x z ↔ Conn G ω y z := by change z ∈ cluster G ω x ↔ z ∈ cluster G ω y; rw [hc] + rw [hz] + +theorem binClusterSlice_nonempty (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) + (hw : ClusterWindow G x n (2*n) ω) (hx : x ∈ vertexOrbit G o) : + (binClusterSlice G o n ω x).Nonempty := + ⟨x,(mem_binClusterSlice G o n ω x x).mpr ⟨hw,conn_refl _ _ _,hx⟩⟩ + +theorem binOrbitRowMass_eq_slice (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x : V) + (hx : x ∈ vertexOrbit G o) : + binOrbitRowMass G n ω x = (binClusterSlice G o n ω x).card := by + by_cases hw : ClusterWindow G x n (2*n) ω + · rw [binOrbitRowMass_eq G n ω x hw,vertexOrbit_eq_of_mem G o x hx] + simp only [binClusterSlice,dite_eq_left hw] + rw [←Finset.sum_filter] + simp + · rw [binOrbitRowMass_zero G n ω x hw] + simp only [binClusterSlice,dite_eq_right hw,Finset.card_empty,Nat.cast_zero] + +theorem binSizeMass_eq_of_conn (G : BondGraph V E) (n : ℕ) (ω : Set E) + {x y : V} (hc : Conn G ω x y) : binSizeMass G n ω x = binSizeMass G n ω y := by + have he := cluster_eq_of_conn G ω hc + have hw : ClusterWindow G x n (2*n) ω ↔ ClusterWindow G y n (2*n) ω := by + unfold ClusterWindow + rw [he] + by_cases hx : ClusterWindow G x n (2*n) ω + · rw [binSizeMass_eq G n ω x hx,binSizeMass_eq G n ω y (hw.mp hx),he] + · have hy := fun h => hx (hw.mpr h) + simp only [binSizeMass,binMass_zero_of_not_window G n ω x _ hx, + binMass_zero_of_not_window G n ω y _ hy,tsum_zero] + +theorem mem_binClusterSlice_iff_mass (G : BondGraph V E) (o : V) (n : ℕ) + (ω : Set E) (x y : V) : + y ∈ binClusterSlice G o n ω x ↔ + binConnectionMass G n ω x y = 1 ∧ y ∈ vertexOrbit G o := by + rw [mem_binClusterSlice] + have he : binConnectionMass G n ω x y = + if ClusterWindow G x n (2*n) ω ∧ Conn G ω x y then 1 else 0 := by + unfold binConnectionMass ClusterWindow + congr 1 + apply propext; tauto + rw [he] + by_cases h : ClusterWindow G x n (2*n) ω ∧ Conn G ω x y + · rw [ite_eq_left h] + simp only [h.1,h.2,true_and] + · rw [ite_eq_right h] + simp only [zero_ne_one,false_and] + tauto + +theorem binClusterSlice_local (G : BondGraph V E) (hloc : LocallyFinite G) + (o : V) (n : ℕ) (ω : Set E) (x : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binClusterSlice G o n ω x = binClusterSlice G o n (ω ∩ (Q : Set E)) x := by + intro Q + ext y + rw [mem_binClusterSlice_iff_mass,mem_binClusterSlice_iff_mass, + binConnectionMass_local G hloc n ω x y] + +end BinClusterSlice +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteClassTransport +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def finiteClassTransport (S : V → Finset V) (t : V → ℝ) + (K : V → V → ℝ) (x y : V) : ℝ := + if y ∈ S x then t x / (S x).card * ∑ z ∈ S x, K x z else 0 + +theorem finiteClassTransport_nonneg (S : V → Finset V) (t : V → ℝ) + (K : V → V → ℝ) (ht : ∀ x, 0 ≤ t x) (hK : ∀ x y, 0 ≤ K x y) (x y : V) : + 0 ≤ finiteClassTransport S t K x y := by + unfold finiteClassTransport + split_ifs + · exact mul_nonneg (div_nonneg (ht x) (Nat.cast_nonneg _)) (Finset.sum_nonneg (fun z _ => hK x z)) + · rfl + +theorem finiteClassTransport_row (S : V → Finset V) (t : V → ℝ) + (K : V → V → ℝ) (x : V) : + (∑' y, finiteClassTransport S t K x y) = t x * ∑ z ∈ S x, K x z := by + rw [tsum_eq_sum (s := S x) (fun y hy => (show finiteClassTransport S t K x y = 0 from ite_eq_right hy))] + have he : (∑ y ∈ S x, finiteClassTransport S t K x y) = + (S x).card * (t x / (S x).card * ∑ z ∈ S x, K x z) := by + simp only [finiteClassTransport] + rw [Finset.sum_ite_mem] + simp only [Finset.inter_self,Finset.sum_const,nsmul_eq_mul] + rw [he] + by_cases h : (S x).Nonempty + · have hc : ((S x).card:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr h.card_pos.ne' + field_simp + · have hs := Finset.not_nonempty_iff_eq_empty.mp h + simp only [hs,Finset.card_empty,Nat.cast_zero,Finset.sum_empty,mul_zero] + +theorem finiteClassTransport_column (S : V → Finset V) (t : V → ℝ) + (K : V → V → ℝ) + (hsym : ∀ x y, y ∈ S x ↔ x ∈ S y) + (heq : ∀ x y, y ∈ S x → S y = S x) + (ht : ∀ x y, y ∈ S x → t y = t x) (x : V) : + (∑' y, finiteClassTransport S t K y x) = + t x / (S x).card * ∑ y ∈ S x, ∑ z ∈ S x, K y z := by + rw [tsum_eq_sum (s := S x) (fun y hy => (show finiteClassTransport S t K y x = 0 from + ite_eq_right (fun h => hy ((hsym x y).mpr h))))] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y hy + rw [finiteClassTransport,ite_eq_left ((hsym x y).mp hy),heq x y hy,ht x y hy] + + +theorem finiteClassTransport_column_le (S : V → Finset V) (t : V → ℝ) + (K : V → V → ℝ) (ht0 : ∀ x, 0 ≤ t x) + (hsym : ∀ x y, y ∈ S x ↔ x ∈ S y) + (heq : ∀ x y, y ∈ S x → S y = S x) + (ht : ∀ x y, y ∈ S x → t y = t x) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (x : V) : + (∑' y, finiteClassTransport S t K y x) ≤ ‖A‖*t x := by + rw [finiteClassTransport_column S t K hsym heq ht] + by_cases h : (S x).Nonempty + · have hh := mul_le_mul_of_nonneg_left (kernel_average_le_norm K A hA (S x) h) (ht0 x) + simpa only [div_mul_eq_mul_div,mul_div_assoc,mul_comm (t x) ‖A‖] using hh + · have hs := Finset.not_nonempty_iff_eq_empty.mp h + simp only [hs,Finset.card_empty,Nat.cast_zero,div_zero,Finset.sum_empty,mul_zero] + exact mul_nonneg (norm_nonneg _) (ht0 x) + +end FiniteClassTransport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BinDiagonalClass +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binOrbitClass (G : BondGraph V E) (o : V) (n : ℕ) + (ω : Set E) (x : V) : Finset V := + if x ∈ vertexOrbit G o then binClusterSlice G o n ω x else ∅ + +theorem mem_binOrbitClass (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : + y ∈ binOrbitClass G o n ω x ↔ x ∈ vertexOrbit G o ∧ + ClusterWindow G x n (2*n) ω ∧ Conn G ω x y ∧ y ∈ vertexOrbit G o := by + unfold binOrbitClass + split_ifs with h + · simp only [mem_binClusterSlice,h,true_and] + · simp only [Finset.notMem_empty,h,false_and] + +theorem binOrbitClass_symm (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) : + y ∈ binOrbitClass G o n ω x ↔ x ∈ binOrbitClass G o n ω y := by + have h (x y : V) (hy : y ∈ binOrbitClass G o n ω x) : x ∈ binOrbitClass G o n ω y := by + obtain ⟨hx,hw,hc,hy⟩ := (mem_binOrbitClass G o n ω x y).mp hy + have hwy : ClusterWindow G y n (2*n) ω := by + unfold ClusterWindow at hw ⊢ + rw [←cluster_eq_of_conn G ω hc] + exact hw + exact (mem_binOrbitClass G o n ω y x).mpr ⟨hy,hwy,conn_symm G ω hc,hx⟩ + exact ⟨h x y,h y x⟩ + +theorem binOrbitClass_eq (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) + (hy : y ∈ binOrbitClass G o n ω x) : binOrbitClass G o n ω y = binOrbitClass G o n ω x := by + obtain ⟨hx,_,hc,hy⟩ := (mem_binOrbitClass G o n ω x y).mp hy + simp only [binOrbitClass,ite_eq_left hx,ite_eq_left hy] + exact (binClusterSlice_eq_of_conn G o n ω hc).symm + +theorem binOrbitClass_mass_eq (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) + (hy : y ∈ binOrbitClass G o n ω x) : binSizeMass G n ω y = binSizeMass G n ω x := + (binSizeMass_eq_of_conn G n ω ((mem_binOrbitClass G o n ω x y).mp hy).2.2.1).symm + +theorem binOrbitClass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (o : V) (n : ℕ) (ω : Set E) (x : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binOrbitClass G o n ω x = binOrbitClass G o n (ω ∩ (Q : Set E)) x := by + intro Q + unfold binOrbitClass + rw [binClusterSlice_local G hloc o n ω x] + +theorem binOrbitClass_mem_covariant (G : BondGraph V E) (o : V) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (n : ℕ) (ω : Set E) (x y : V) : + y ∈ binOrbitClass G o n (b ⁻¹' ω) x ↔ a y ∈ binOrbitClass G o n ω (a x) := by + unfold binOrbitClass + simp only [mem_vertexOrbit_aut_iff G o hab] + split_ifs + · simp only [mem_binClusterSlice_iff_mass,binConnectionMass_covariant G hab, + mem_vertexOrbit_aut_iff G o hab] + · simp only [Finset.notMem_empty] + +theorem binOrbitClass_covariant (G : BondGraph V E) (o : V) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (n : ℕ) (ω : Set E) (x : V) : + (binOrbitClass G o n (b ⁻¹' ω) x).image a = binOrbitClass G o n ω (a x) := by + ext y + constructor + · rintro hy + obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp hy + exact (binOrbitClass_mem_covariant G o hab n ω x z).mp hz + · intro hy + exact Finset.mem_image.mpr ⟨a.symm y,(binOrbitClass_mem_covariant G o hab n ω x (a.symm y)).mpr + (by simpa only [Equiv.apply_symm_apply] using hy),a.apply_symm_apply y⟩ + +theorem binOrbitClass_reach (G : BondGraph V E) (o : V) (n : ℕ) (ω : Set E) (x y : V) + (hy : y ∈ binOrbitClass G o n ω x) : y ∈ reachBall G x (2*n) := by + obtain ⟨_,hw,hc,_⟩ := (mem_binOrbitClass G o n ω x y).mp hy + exact finite_cluster_subset_reachBall G ω x hw.1 (2*n) hw.2.2.le hc + +end BinDiagonalClass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section BinDiagonalTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binDiagonalMass (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x y : V) : ℝ := + finiteClassTransport (binOrbitClass G o n ω) (fun x => binSizeMass G n ω x ^ 2) K x y + +theorem binDiagonalMass_nonneg (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (hK : ∀ x y, 0 ≤ K x y) (ω : Set E) (x y : V) : + 0 ≤ binDiagonalMass G o n K ω x y := + finiteClassTransport_nonneg _ _ K (fun _ => sq_nonneg _) hK x y + +theorem binDiagonalMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (o : V) (n : ℕ) (K : V → V → ℝ) (ω : Set E) (x y : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binDiagonalMass G o n K ω x y = binDiagonalMass G o n K (ω ∩ (Q : Set E)) x y := by + intro Q + simp only [binDiagonalMass,finiteClassTransport] + rw [binOrbitClass_local G hloc o n ω x,binSizeMass_local G hloc n ω x] + +theorem binDiagonalMass_integrable (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (K : V → V → ℝ) (x y : V) : + Integrable (fun ω => binDiagonalMass G o n K ω x y) (law p) := + integrable_finite_local _ p _ (fun ω => binDiagonalMass_local G hloc o n K ω x y) + +theorem binDiagonalMass_outside (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x y : V) (hy : y ∉ reachBall G x (2*n)) : + binDiagonalMass G o n K ω x y = 0 := + ite_eq_right (fun h => hy (binOrbitClass_reach G o n ω x y h)) + +theorem binDiagonalMass_outside_column (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x y : V) (hx : x ∉ reachBall G y (2*n)) : + binDiagonalMass G o n K ω x y = 0 := + ite_eq_right (fun h => hx (binOrbitClass_reach G o n ω y x ((binOrbitClass_symm G o n ω x y).mp h))) + +theorem binDiagonalMass_row_zero (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x y : V) (hx : x ∉ vertexOrbit G o) : + binDiagonalMass G o n K ω x y = 0 := + ite_eq_right (fun h => hx ((mem_binOrbitClass G o n ω x y).mp h).1) + +theorem binDiagonalMass_column_zero (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x y : V) (hy : y ∉ vertexOrbit G o) : + binDiagonalMass G o n K ω x y = 0 := + ite_eq_right (fun h => hy ((mem_binOrbitClass G o n ω x y).mp h).2.2.2) + +theorem binDiagonalMass_covariant (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (hK : ∀ x y, K (a x) (a y) = K x y) (ω : Set E) (x y : V) : + binDiagonalMass G o n K (b ⁻¹' ω) x y = binDiagonalMass G o n K ω (a x) (a y) := by + have hs := binOrbitClass_covariant G o hab n ω x + have hc : (binOrbitClass G o n (b ⁻¹' ω) x).card = (binOrbitClass G o n ω (a x)).card := by + rw [←hs,Finset.card_image_of_injective _ a.injective] + have hsum : (∑ z ∈ binOrbitClass G o n (b ⁻¹' ω) x, K x z) = + ∑ z ∈ binOrbitClass G o n ω (a x), K (a x) z := by + rw [←hs,Finset.sum_image (fun _ _ _ _ h => a.injective h)] + simp only [hK] + simp only [binDiagonalMass,finiteClassTransport,binOrbitClass_mem_covariant G o hab, + binSizeMass_covariant G n ω hab,hc,hsum] + +theorem binDiagonalMass_row (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x : V) : + (∑' y, binDiagonalMass G o n K ω x y) = + binSizeMass G n ω x ^ 2 * ∑ z ∈ binOrbitClass G o n ω x, K x z := + finiteClassTransport_row _ _ K x + +theorem binDiagonalMass_column (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (ω : Set E) (x : V) : + (∑' y, binDiagonalMass G o n K ω y x) = + binSizeMass G n ω x ^ 2 / (binOrbitClass G o n ω x).card * + ∑ y ∈ binOrbitClass G o n ω x, ∑ z ∈ binOrbitClass G o n ω x, K y z := by + apply finiteClassTransport_column _ _ K (binOrbitClass_symm G o n ω) (binOrbitClass_eq G o n ω) + intro x y hy + rw [binOrbitClass_mass_eq G o n ω x y hy] + +theorem binDiagonalMass_column_le (G : BondGraph V E) (o : V) (n : ℕ) + (K : V → V → ℝ) (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, A (lp.single 2 y (1:ℂ)) x = (K x y : ℂ)) (ω : Set E) (x : V) : + (∑' y, binDiagonalMass G o n K ω y x) ≤ ‖A‖ * binSizeMass G n ω x ^ 2 := by + apply finiteClassTransport_column_le _ _ K (fun _ => sq_nonneg _) + (binOrbitClass_symm G o n ω) (binOrbitClass_eq G o n ω) _ A hA + intro x y hy + rw [binOrbitClass_mass_eq G o n ω x y hy] + +end BinDiagonalTransport +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Clusters/LargeContacts.lean b/lean/OAI/Probability/UnimodularPercolation/Clusters/LargeContacts.lean index 381b42d123b21b577beb61cc293879955f01be6e..fd6d4dd5e5a11464c0faf68f0e994990cba78bd4 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Clusters/LargeContacts.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Clusters/LargeContacts.lean @@ -1,1229 +1,1229 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.TailBounds - -namespace OAI - -/-! Large Contacts for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UnorderedContactConcentration -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem cluster_contact_tail (G : BondGraph V E) (Q : Finset E) - (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) - (x v : V) (p : unitInterval) (m : ℕ) (hdm : 0 < d*m) (a : ℝ) (ha : 0 < a) : - bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ - min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) - (finiteRootComponent G ω v)).card then 1 else 0) p ≤ - 8*Real.exp (-2*a^2/(d*m:ℕ)) := by - let f (x v : V) (ω : Finset E) : ℝ := - if ¬Conn G (ω:Set E) x v ∧ (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ d*m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) - (finiteRootComponent G ω v)).card then 1 else 0 - calc - _ ≤ bernoulliPolynomial Q (fun ω => f x v ω+f v x ω) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - by_cases h : ¬Conn G (ω:Set E) x v ∧ - min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) - (finiteRootComponent G ω v)).card - · simp only [ite_eq_left h] - rcases le_total (finiteRootComponent G ω v).card (finiteRootComponent G ω x).card with hc | hc - · have hsmall : (finiteRootComponent G ω v).card ≤ m := by simpa only [min_eq_right hc] using h.2.1 - have hh : ¬Conn G (ω:Set E) x v ∧ (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ d*m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := - ⟨h.1,(incidentBonds_card_le G Q _ d hd).trans (Nat.mul_le_mul_left d hsmall),h.2.2⟩ - simp only [f,ite_eq_left hh]; split_ifs <;> norm_num - · have hsmall : (finiteRootComponent G ω x).card ≤ m := by simpa only [min_eq_left hc] using h.2.1 - have hh : ¬Conn G (ω:Set E) v x ∧ (incidentBonds G Q (finiteRootComponent G ω x)).card ≤ d*m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω v) (finiteRootComponent G ω x)).card := by - refine ⟨fun hc' => h.1 (conn_symm G _ hc'), - (incidentBonds_card_le G Q _ d hd).trans (Nat.mul_le_mul_left d hsmall),?_⟩ - rw [contactBonds_comm G Q (finiteRootComponent G ω v)] - exact h.2.2 - simp only [f,ite_eq_left hh]; split_ifs <;> norm_num - · simp only [ite_eq_right h,f]; split_ifs <;> norm_num - _ = bernoulliPolynomial Q (f x v) p+bernoulliPolynomial Q (f v x) p := - bernoulliPolynomial_add .. - _ ≤ 4*Real.exp (-2*a^2/(d*m:ℕ))+4*Real.exp (-2*a^2/(d*m:ℕ)) := - add_le_add (ordered_cluster_contact_tail G Q x v p (d*m) hdm a ha) - (ordered_cluster_contact_tail G Q v x p (d*m) hdm a ha) - _ = _ := by ring - -end UnorderedContactConcentration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TwoLargeFiniteClusters -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cluster_exterior_weighted_bound (G : BondGraph V E) (Q : Finset E) - (x : V) (p : unitInterval) (F : Finset V → ℝ) (hF : ∀ W, 0 ≤ F W) - (f : Finset V → Finset E → ℝ) (K : ℝ) - (hf : ∀ W : Finset V, bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ K) : - bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)*f (finiteRootComponent G ω x) - (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p ≤ - K*bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)) p := by - have hh := cluster_exterior_expectation_bound G Q x p - (fun W η => F W*f W η-K*F W) 0 (fun W => by - rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul,bernoulliPolynomial_const] - exact sub_nonpos.mpr (by simpa only [mul_comm K] using mul_le_mul_of_nonneg_left (hf W) (hF W))) - rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul] at hh - exact sub_nonpos.mp hh - -theorem finiteClusterTail_domain_mono (G : BondGraph V E) {Q R : Finset E} (hRQ : R ⊆ Q) - (x : V) (n : ℕ) (p : unitInterval) : finiteClusterTail G R x n p ≤ finiteClusterTail G Q x n p := by - unfold finiteClusterTail - rw [←bernoulliPolynomial_restrict R Q hRQ] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - exact finiteClusterTailIndicator_mono G x n Finset.inter_subset_left - - - -theorem two_large_clusters_tail (G : BondGraph V E) (Q : Finset E) - (x v : V) (n m : ℕ) (p : unitInterval) : - bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ - n ≤ (finiteRootComponent G ω x).card ∧ m ≤ (finiteRootComponent G ω v).card - then 1 else 0) p ≤ finiteClusterTail G Q v m p*finiteClusterTail G Q x n p := by - let F (W : Finset V) : ℝ := if n ≤ W.card then 1 else 0 - let f (W : Finset V) (η : Finset E) : ℝ := if v ∈ W then 0 else finiteClusterTailIndicator G v m η - have hF : ∀ W, 0 ≤ F W := fun W => by dsimp [F]; split_ifs <;> norm_num - have hf (W : Finset V) : bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ - finiteClusterTail G Q v m p := by - by_cases hv : v ∈ W - · simp only [f,ite_eq_left hv,bernoulliPolynomial_zero] - exact finiteClusterTail_nonneg G Q v m p - · simp only [f,ite_eq_right hv] - exact finiteClusterTail_domain_mono G (Finset.filter_subset _ _) v m p - have hp := cluster_exterior_weighted_bound G Q x p F hF f (finiteClusterTail G Q v m p) hf - have heq : bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)*f (finiteRootComponent G ω x) - (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p = - bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ - n ≤ (finiteRootComponent G ω x).card ∧ m ≤ (finiteRootComponent G ω v).card then 1 else 0) p := by - apply bernoulliPolynomial_congr - intro ω _ - have hv : v ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x v := by - change v ∈ (finiteRootComponent G ω x:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - by_cases hc : Conn G (ω:Set E) x v - · simp only [F,f,ite_eq_left (hv.mpr hc),mul_zero,not_true_eq_false,hc,false_and,ite_false] - · simp only [F,f,ite_eq_right (fun h => hc (hv.mp h)),finiteClusterTailIndicator, - finiteRootComponent_exterior G ω x v hc] - split_ifs <;> norm_num <;> grind - rw [heq] at hp - exact hp - -end TwoLargeFiniteClusters -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section EndpointClusterTails -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteClusterTail_of_endpoint_moment [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (α C : ℝ) - (hα : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) - (Q : Finset E) (x : V) (p : unitInterval) (hpq : p ≤ q) (n : ℕ) (hn : 1 ≤ n) : - finiteClusterTail G Q x n p ≤ 2*C*(n:ℝ)^(-α) := by - have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) - let h : unitInterval := ⟨1/(n:ℝ),⟨by positivity,by apply (div_le_one hn0).mpr; exact_mod_cast hn⟩⟩ - have hh : 0 < (h:ℝ) := by dsimp [h]; positivity - have hhpow : (h:ℝ)^α = (n:ℝ)^(-α) := by - dsimp [h] - rw [one_div,Real.inv_rpow hn0.le,Real.rpow_neg hn0.le] - have hhn : 1 ≤ (h:ℝ)*n := by dsimp [h]; rw [one_div,inv_mul_cancel₀ hn0.ne'] - have hm := cluster_power_mono_integral G hloc x p q hpq α hα (hfin x) (hI x) - have hb := markedConnection_le_cluster_power G Q x h p α hα hα1 - (cluster_finite_ae_mono G x p q hpq (hfin x)) hm.1 - have hM : markedConnectionPolynomial G Q x h p ≤ C*(n:ℝ)^(-α) := by - apply hb.trans - rw [hhpow] - simpa only [mul_comm C] using - mul_le_mul_of_nonneg_left (hm.2.trans (hC x)) (Real.rpow_nonneg (Nat.cast_nonneg n) (-α)) - have hb' := (finiteClusterTail_le_markedConnection G Q x n p h hhn).trans - (mul_le_mul_of_nonneg_left hM (by norm_num : (0:ℝ) ≤ 2)) - simpa only [mul_assoc] using hb' - -theorem two_large_clusters_of_endpoint_moment [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (α C : ℝ) - (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 ≤ C) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) - (Q : Finset E) (x v : V) (p : unitInterval) (hpq : p ≤ q) (n : ℕ) (hn : 1 ≤ n) : - bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ - n ≤ (finiteRootComponent G ω x).card ∧ n ≤ (finiteRootComponent G ω v).card - then 1 else 0) p ≤ 4*C^2*(n:ℝ)^(-2*α) := by - have ht (y : V) := finiteClusterTail_of_endpoint_moment G hloc q α C hα hα1 hfin hI hC Q y p hpq n hn - have hc : 0 ≤ 2*C*(n:ℝ)^(-α) := by positivity - calc - _ ≤ finiteClusterTail G Q v n p*finiteClusterTail G Q x n p := two_large_clusters_tail .. - _ ≤ (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) := - mul_le_mul (ht v) (ht x) (finiteClusterTail_nonneg G Q x n p) hc - _ = 4*C^2*(n:ℝ)^(-2*α) := by - have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) - rw [show (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) = - 4*C^2*((n:ℝ)^(-α)*(n:ℝ)^(-α)) by ring,←Real.rpow_add hn0] - congr 2 - ring - -end EndpointClusterTails -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ContactBinFirstMoment -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem contactBonds_card_le (G : BondGraph V E) (Q : Finset E) - (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) (A B : Finset V) : - (contactBonds G Q A B).card ≤ d*min A.card B.card := by - have hh (A B : Finset V) : (contactBonds G Q A B).card ≤ d*A.card := by - apply (Finset.card_le_card (t := incidentBonds G Q A) _).trans (incidentBonds_card_le G Q A d hd) - intro e he - obtain ⟨he,a,ha,b,_,hab⟩ := Finset.mem_filter.mp he - exact (mem_incidentBonds G Q A e).mpr ⟨he,a,ha,by rw [hab]; simp⟩ - rcases le_total A.card B.card with h | h - · rw [min_eq_left h]; exact hh A B - · rw [min_eq_right h,contactBonds_comm G Q A B]; exact hh B A - -noncomputable def clusterContactBin (G : BondGraph V E) (Q : Finset E) - (x v : V) (n m : ℕ) (ω : Finset E) : ℝ := - if ¬Conn G (ω:Set E) x v ∧ - n ≤ min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ∧ - min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m - then (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card else 0 - - - -theorem clusterContactBin_bound (G : BondGraph V E) (Q : Finset E) - (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) - (x v : V) (p : unitInterval) (hp : 0 < (p:ℝ)) (n m : ℕ) (hdm : 0 < d*m) - (a : ℝ) (ha : 0 < a) : - bernoulliPolynomial Q (clusterContactBin G Q x v n m) p ≤ - (2*a/(p:ℝ))*(finiteClusterTail G Q v n p*finiteClusterTail G Q x n p)+ - (d*m:ℕ)*(8*Real.exp (-2*a^2/(d*m:ℕ))) := by - let D (ω : Finset E) : Prop := ¬Conn G (ω:Set E) x v ∧ - n ≤ (finiteRootComponent G ω x).card ∧ n ≤ (finiteRootComponent G ω v).card - let T (ω : Finset E) : Prop := ¬Conn G (ω:Set E) x v ∧ - min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card - calc - _ ≤ bernoulliPolynomial Q (fun ω => (2*a/(p:ℝ))*(if D ω then 1 else 0)+ - (d*m:ℕ)*(if T ω then 1 else 0)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - unfold clusterContactBin - by_cases h : ¬Conn G (ω:Set E) x v ∧ - n ≤ min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ∧ - min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m - · have hD : D ω := ⟨h.1,(le_min_iff.mp h.2.1).1,(le_min_iff.mp h.2.1).2⟩ - simp only [ite_eq_left h,ite_eq_left hD,mul_one] - by_cases ht : T ω - · rw [ite_eq_left ht,mul_one] - have hk : (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card ≤ d*m := - (contactBonds_card_le G Q d hd _ _).trans (Nat.mul_le_mul_left d h.2.2) - have hk' : ((contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card:ℝ) ≤ (d*m:ℕ) := by exact_mod_cast hk - have hapos : 0 ≤ 2*a/(p:ℝ) := by positivity - linarith - · rw [ite_eq_right ht,mul_zero,add_zero] - apply (le_div_iff₀ hp).mpr - have hn : ¬ 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := - fun hh => ht ⟨h.1,h.2.2,hh⟩ - simpa only [mul_comm] using (not_le.mp hn).le - · simp only [ite_eq_right h] - split_ifs <;> positivity - _ = (2*a/(p:ℝ))*bernoulliPolynomial Q (fun ω => if D ω then 1 else 0) p+ - (d*m:ℕ)*bernoulliPolynomial Q (fun ω => if T ω then 1 else 0) p := by - rw [bernoulliPolynomial_add,bernoulliPolynomial_const_mul,bernoulliPolynomial_const_mul] - _ ≤ _ := add_le_add - (mul_le_mul_of_nonneg_left (two_large_clusters_tail G Q x v n n p) (by positivity)) - (mul_le_mul_of_nonneg_left (cluster_contact_tail G Q d hd x v p m hdm a ha) (Nat.cast_nonneg _)) - -end ContactBinFirstMoment -end Percolation - - -namespace Percolation -section StretchedContactDecay - -theorem exists_stretched_exp_volume_bound (d ε r : ℝ) (hd : 0 < d) (hε : 0 < ε) (hr : r ≤ 1) : - ∃ C : ℝ, 0 < C ∧ ∀ z : ℝ, 0 < z → z*Real.exp (-(z^ε)/d) ≤ C*z^r := by - let s := (1-r)/ε - have hs : 0 ≤ s := by dsimp [s]; positivity - obtain ⟨K,hK,hKb⟩ := exists_exp_neg_le_rpow s hs - refine ⟨K*d^s,by positivity,?_⟩ - intro z hz - have he := mul_le_mul_of_nonneg_left (hKb (z^ε/d) (by positivity)) hz.le - have hex : ε*(-s) = r-1 := by dsimp [s]; field_simp; ring - have hid : (z^ε/d)^(-s) = z^(r-1)*d^s := by - rw [Real.div_rpow (Real.rpow_nonneg hz.le ε) hd.le,←Real.rpow_mul hz.le,hex, - Real.rpow_neg hd.le,div_inv_eq_mul] - have hzpow : z*z^(r-1) = z^r := by - conv_lhs => lhs; rw [←Real.rpow_one z] - rw [←Real.rpow_add hz] - congr 1 - ring - calc - _ ≤ z*(K*(z^ε/d)^(-s)) := by simpa only [neg_div] using he - _ = (K*d^s)*(z*z^(r-1)) := by rw [hid]; ring - _ = _ := by rw [hzpow] - -theorem contact_tail_exponent (d z ε : ℝ) (hd : 0 < d) (hz : 0 < z) : - -2*(z^((1:ℝ)/2+ε))^2/(d*(2*z)) = -(z^(2*ε))/d := by - have hpow : (z^((1:ℝ)/2+ε))^2 = z*z^(2*ε) := by - rw [←Real.rpow_natCast,←Real.rpow_mul hz.le] - norm_num only [Nat.cast_ofNat] - rw [show ((1:ℝ)/2+ε)*2 = 1+2*ε by ring,Real.rpow_add hz,Real.rpow_one] - rw [hpow] - field_simp - -end StretchedContactDecay -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformContactBins -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem clusterContactBin_power_bound [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) - (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) - (d : ℕ) (hd : 0 < d) : - ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E), (∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) → - ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → ∀ n : ℕ, 1 ≤ n → - bernoulliPolynomial Q (clusterContactBin G Q x v n (2*n)) p ≤ - A*(n:ℝ)^((1:ℝ)/2+ε-2*α) := by - let r : ℝ := (1:ℝ)/2+ε-2*α - have hd' : (0:ℝ) < d := Nat.cast_pos.mpr hd - obtain ⟨K,hK,hKb⟩ := exists_stretched_exp_volume_bound (d:ℝ) (2*ε) r hd' (by positivity) (by dsimp [r]; linarith) - refine ⟨8*C^2/p₀+16*(d:ℝ)*K,by positivity,?_⟩ - intro Q hdeg x v p hpp hpq n hn - have hn' : 0 < n := by omega - have hnr : (0:ℝ) < n := Nat.cast_pos.mpr hn' - have hp : 0 < (p:ℝ) := hp₀.trans_le hpp - let a : ℝ := (n:ℝ)^((1:ℝ)/2+ε) - have ha : 0 < a := Real.rpow_pos_of_pos hnr _ - have hb := clusterContactBin_bound G Q d hdeg x v p hp n (2*n) (by positivity) a ha - have ht (y : V) := finiteClusterTail_of_endpoint_moment G hloc q α C hα hα1 hfin hI hC Q y p hpq n hn - have hprod : finiteClusterTail G Q v n p*finiteClusterTail G Q x n p ≤ 4*C^2*(n:ℝ)^(-2*α) := by - calc - _ ≤ (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) := - mul_le_mul (ht v) (ht x) (finiteClusterTail_nonneg G Q x n p) (by positivity) - _ = _ := by - rw [show (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) = 4*C^2*((n:ℝ)^(-α)*(n:ℝ)^(-α)) by ring, - ←Real.rpow_add hnr] - congr 2 - ring - have hfirst : (2*a/(p:ℝ))*(finiteClusterTail G Q v n p*finiteClusterTail G Q x n p) ≤ - (8*C^2/p₀)*(n:ℝ)^r := by - calc - _ ≤ (2*a/p₀)*(4*C^2*(n:ℝ)^(-2*α)) := - mul_le_mul (div_le_div_of_nonneg_left (by positivity) hp₀ hpp) hprod - (mul_nonneg (finiteClusterTail_nonneg G Q v n p) (finiteClusterTail_nonneg G Q x n p)) (by positivity) - _ = (8*C^2/p₀)*((n:ℝ)^((1:ℝ)/2+ε)*(n:ℝ)^(-2*α)) := by dsimp [a]; ring - _ = _ := by rw [←Real.rpow_add hnr]; congr 2; dsimp [r]; ring - have hex : -2*a^2/(d*(2*n):ℕ) = -((n:ℝ)^(2*ε))/(d:ℝ) := by - simp only [Nat.cast_mul,Nat.cast_ofNat] - exact contact_tail_exponent d n ε hd' hnr - have hsecond : (d*(2*n):ℕ)*(8*Real.exp (-2*a^2/(d*(2*n):ℕ))) ≤ - (16*(d:ℝ)*K)*(n:ℝ)^r := by - rw [hex] - calc - _ = (16*(d:ℝ))*((n:ℝ)*Real.exp (-((n:ℝ)^(2*ε))/(d:ℝ))) := by - push_cast - ring - _ ≤ (16*(d:ℝ))*(K*(n:ℝ)^r) := mul_le_mul_of_nonneg_left (hKb n hnr) (by positivity) - _ = _ := by ring - calc - _ ≤ _ := hb - _ ≤ (8*C^2/p₀)*(n:ℝ)^r+(16*(d:ℝ)*K)*(n:ℝ)^r := add_le_add hfirst hsecond - _ = _ := by dsimp [r]; ring - -end UniformContactBins -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section InfiniteContacts -attribute [local instance] Classical.propDecidable Classical.decEq - - -def closedContactSet (G : BondGraph V E) (A B : Set V) : Set E := - {e | ∃ a ∈ A, ∃ b ∈ B, G e = s(a,b)} - -noncomputable def clusterContactCount (G : BondGraph V E) (ω : Set E) (x v : V) : ℕ := - (closedContactSet G (cluster G ω x) (cluster G ω v)).ncard - -noncomputable def fullContactBin (G : BondGraph V E) (x v : V) (n m : ℕ) (ω : Set E) : ℝ := - if ¬Conn G ω x v ∧ n ≤ min (cluster G ω x).ncard (cluster G ω v).ncard ∧ - min (cluster G ω x).ncard (cluster G ω v).ncard ≤ m - then clusterContactCount G ω x v else 0 - -theorem contactSet_subset_incident (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset V) (B : Set V) : closedContactSet G (A:Set V) B ⊆ (incidentSupport G hloc A:Set E) := by - rintro e ⟨a,ha,b,_,hab⟩ - exact (mem_incidentSupport G hloc A e).mpr ⟨a,ha,by rw [hab]; simp⟩ - -theorem coe_contactBonds_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (A B : Finset V) (hQ : incidentSupport G hloc A ⊆ Q) : - (contactBonds G Q A B : Set E) = closedContactSet G A B := by - ext e - constructor - · exact fun h => (Finset.mem_filter.mp h).2 - · intro h - exact Finset.mem_filter.mpr ⟨hQ (contactSet_subset_incident G hloc A B h),h⟩ - -theorem contactSet_ncard_le (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) - (A B : Set V) (hA : A.Finite) (hB : B.Finite) : - (closedContactSet G A B).ncard ≤ d*min A.ncard B.ncard := by - let Q := incidentSupport G hloc (hA.toFinset ∪ hB.toFinset) - have hdeg (z : V) : (Q.filter fun e => z ∈ G e).card ≤ d := by - calc - _ = ((Q.filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm - _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) - _ ≤ d := hd z - have hQ : incidentSupport G hloc hA.toFinset ⊆ Q := - incidentSupport_mono G hloc Finset.subset_union_left - have he := coe_contactBonds_eq G hloc Q hA.toFinset hB.toFinset hQ - simp only [Set.Finite.coe_toFinset] at he - rw [←he,Set.ncard_coe_finset] - simpa only [←Set.ncard_eq_toFinset_card] using contactBonds_card_le G Q d hdeg hA.toFinset hB.toFinset - -theorem fullContactBin_nonneg (G : BondGraph V E) (x v : V) (n m : ℕ) (ω : Set E) : - 0 ≤ fullContactBin G x v n m ω := by unfold fullContactBin; split_ifs <;> positivity - -theorem fullContactBin_le (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (n m : ℕ) (hn : 0 < n) (ω : Set E) : - fullContactBin G x v n m ω ≤ (d*m:ℕ) := by - unfold fullContactBin - split_ifs with h - · have hx : (cluster G ω x).Finite := Set.finite_of_ncard_ne_zero (by omega) - have hv : (cluster G ω v).Finite := Set.finite_of_ncard_ne_zero (by omega) - exact_mod_cast (contactSet_ncard_le G hloc d hd _ _ hx hv).trans (Nat.mul_le_mul_left d h.2.2) - · positivity - -end InfiniteContacts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section ContactMeasurability -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_clusterContactCount [Countable V] [Countable E] - (G : BondGraph V E) (x v : V) : Measurable (fun ω : Set E => clusterContactCount G ω x v) := by - apply measurable_ncard.comp - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - apply measurableSet_setOfPred.mp - change MeasurableSet {ω : Set E | ∃ a, Conn G ω x a ∧ ∃ b, Conn G ω v b ∧ G e = s(a,b)} - simp only [Set.ofPred_exists] - apply MeasurableSet.iUnion - intro a - have he : {ω : Set E | Conn G ω x a ∧ ∃ b, Conn G ω v b ∧ G e = s(a,b)} = - {ω | Conn G ω x a} ∩ ⋃ b, {ω | Conn G ω v b ∧ G e = s(a,b)} := by ext ω; simp - rw [he] - apply (measurableSet_conn G x a).inter - apply MeasurableSet.iUnion - intro b - by_cases h : G e = s(a,b) - · simpa only [h,and_true] using measurableSet_conn G v b - · simp only [h,and_false,Set.ofPred_false]; exact MeasurableSet.empty - -theorem measurable_fullContactBin [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x v : V) (n m : ℕ) : - Measurable (fullContactBin G x v n m) := by - have hs : Measurable (fun ω : Set E => min (cluster G ω x).ncard (cluster G ω v).ncard) := - (measurable_cluster_ncard G hloc x).min (measurable_cluster_ncard G hloc v) - exact ((measurable_of_countable (fun k : ℕ => (k:ℝ))).comp (measurable_clusterContactCount G x v)).ite - (((measurableSet_conn G x v).compl).inter ((measurableSet_le measurable_const hs).inter - (measurableSet_le hs measurable_const))) measurable_const - -theorem coe_domainBits (Q : Finset E) (ω : Set E) : - (domainBits Q ω:Set E) = ω ∩ (Q:Set E) := by ext e; simp only [mem_domainBits,Set.mem_inter_iff,Finset.mem_coe,and_comm] - -theorem domainBits_local (Q : Finset E) (ω : Set E) : - domainBits Q (ω ∩ (Q:Set E)) = domainBits Q ω := by - ext e - simp only [mem_domainBits,Set.mem_inter_iff,Finset.mem_coe] - tauto - -theorem domainBits_of_subset (Q ω : Finset E) (hω : ω ⊆ Q) : domainBits Q (ω:Set E) = ω := by - ext e - simp only [mem_domainBits,Finset.mem_coe] - exact ⟨fun h => h.2,fun h => ⟨hω h,h⟩⟩ - -theorem integral_domainBits (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) : - (∫ ω, f (domainBits Q ω) ∂law p) = bernoulliPolynomial Q f p := by - rw [integral_eq_bernoulliPolynomial Q p _ (fun ω => by rw [domainBits_local])] - apply bernoulliPolynomial_congr - intro ω hω - rw [domainBits_of_subset Q ω hω] - -end ContactMeasurability -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section InfiniteContactLimit -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem fullContactBin_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x v : V) (hx : (cluster G ω x).Finite) (hv : (cluster G ω v).Finite) - (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) - (hQv : incidentSupport G hloc hv.toFinset ⊆ Q) (n m : ℕ) : - clusterContactBin G Q x v n m (domainBits Q ω) = fullContactBin G x v n m ω := by - have hcluster (y : V) (hy : (cluster G ω y).Finite) (hQ : incidentSupport G hloc hy.toFinset ⊆ Q) : - cluster G (domainBits Q ω:Set E) y = cluster G ω y := by - rw [coe_domainBits] - have hh := (cluster_restrict_incident_eq_iff G hloc hy.toFinset Q hQ ω y).mpr - (Set.Finite.coe_toFinset hy).symm - simpa only [Set.Finite.coe_toFinset] using hh - have hcx := hcluster x hx hQx - have hcv := hcluster v hv hQv - have hFx : finiteRootComponent G (domainBits Q ω) x = hx.toFinset := by - apply Finset.coe_injective - rw [coe_finiteRootComponent,hcx,Set.Finite.coe_toFinset] - have hFv : finiteRootComponent G (domainBits Q ω) v = hv.toFinset := by - apply Finset.coe_injective - rw [coe_finiteRootComponent,hcv,Set.Finite.coe_toFinset] - have hconn : Conn G (domainBits Q ω:Set E) x v ↔ Conn G ω x v := by - change v ∈ cluster G (domainBits Q ω:Set E) x ↔ v ∈ cluster G ω x - rw [hcx] - have hc : (contactBonds G Q hx.toFinset hv.toFinset).card = clusterContactCount G ω x v := by - rw [←Set.ncard_coe_finset,coe_contactBonds_eq G hloc Q _ _ hQx] - simp only [Set.Finite.coe_toFinset,clusterContactCount] - simp only [clusterContactBin,fullContactBin,hconn,hFx,hFv,←Set.ncard_eq_toFinset_card,hc] - -theorem clusterContactBin_norm_le (G : BondGraph V E) (Q : Finset E) - (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) - (x v : V) (n m : ℕ) (ω : Finset E) : ‖clusterContactBin G Q x v n m ω‖ ≤ (d*m:ℕ) := by - unfold clusterContactBin - split_ifs with h - · rw [Real.norm_natCast] - exact_mod_cast (contactBonds_card_le G Q d hd _ _).trans (Nat.mul_le_mul_left d h.2.2) - · simp only [norm_zero]; positivity - -theorem fullContactBin_integral_le_of_finite [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) - (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (p : unitInterval) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hv : ∀ᵐ ω ∂law p, (cluster G ω v).Finite) (n m : ℕ) (B : ℝ) - (hB : ∀ Q : Finset E, bernoulliPolynomial Q (clusterContactBin G Q x v n m) p ≤ B) : - (∫ ω, fullContactBin G x v n m ω ∂law p) ≤ B := by - let : Encodable E := Encodable.ofCountable E - let Q := vertexExhaustion (V := E) - let f := fun j ω => clusterContactBin G (Q j) x v n m (domainBits (Q j) ω) - have hfl (j : ℕ) (ω : Set E) : f j ω = f j (ω ∩ (Q j:Set E)) := by - dsimp [f]; rw [domainBits_local] - have hfi (j : ℕ) : Integrable (f j) (law p) := integrable_finite_local (Q j) p (f j) (hfl j) - have hdeg (j : ℕ) (z : V) : ((Q j).filter fun e => z ∈ G e).card ≤ d := by - calc - _ = (((Q j).filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm - _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) - _ ≤ d := hd z - have ht : ∀ᵐ ω ∂law p, Tendsto (fun j => f j ω) atTop (nhds (fullContactBin G x v n m ω)) := by - filter_upwards [hx,hv] with ω hωx hωv - obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hωx.toFinset) - obtain ⟨jv,hjv⟩ := subset_vertexExhaustion (incidentSupport G hloc hωv.toFinset) - have he : (fun j => f j ω) =ᶠ[atTop] (fun _ => fullContactBin G x v n m ω) := by - filter_upwards [eventually_ge_atTop (max jx jv)] with j hj - exact fullContactBin_eq_finite G hloc ω x v hωx hωv (Q j) - (hjx.trans (vertexExhaustion_mono (le_max_left jx jv |>.trans hj))) - (hjv.trans (vertexExhaustion_mono (le_max_right jx jv |>.trans hj))) n m - exact tendsto_const_nhds.congr' he.symm - have hdom := tendsto_integral_of_dominated_convergence (fun _ : Set E => (d*m:ℕ)) - (fun j => (hfi j).aestronglyMeasurable) (integrable_const _) - (fun j => Eventually.of_forall (fun ω => clusterContactBin_norm_le G (Q j) d (hdeg j) x v n m _)) ht - apply le_of_tendsto hdom - exact Eventually.of_forall (fun j => by rw [show (∫ ω, f j ω ∂law p) = - bernoulliPolynomial (Q j) (clusterContactBin G (Q j) x v n m) p from by dsimp [f]; exact integral_domainBits (Q j) p (clusterContactBin G (Q j) x v n m)]; exact hB (Q j)) - -end InfiniteContactLimit -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FullContactPower -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem fullContactBin_power_bound [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) - (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) - (d : ℕ) (hd : 0 < d) (hdeg : ∀ z, {e | z ∈ G e}.ncard ≤ d) : - ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → - ∀ n : ℕ, 1 ≤ n → (∫ ω, fullContactBin G x v n (2*n) ω ∂law p) ≤ - A*(n:ℝ)^((1:ℝ)/2+ε-2*α) := by - obtain ⟨A,hA,hAb⟩ := clusterContactBin_power_bound G hloc q α ε C p₀ hα hα1 hε hr hC0 hp₀ hfin hI hC d hd - refine ⟨A,hA,?_⟩ - intro x v p hpp hpq n hn - apply fullContactBin_integral_le_of_finite G hloc d hdeg x v p - (cluster_finite_ae_mono G x p q hpq (hfin x)) (cluster_finite_ae_mono G v p q hpq (hfin v)) - intro Q - apply hAb Q _ x v p hpp hpq n hn - intro z - calc - _ = ((Q.filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm - _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) - _ ≤ d := hdeg z - -theorem integrable_fullContactBin [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) - (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (n m : ℕ) (hn : 0 < n) (p : unitInterval) : - Integrable (fullContactBin G x v n m) (law p) := by - apply Integrable.mono' (integrable_const ((d*m:ℕ):ℝ)) (measurable_fullContactBin G hloc x v n m).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun ω => by - rw [Real.norm_eq_abs,abs_of_nonneg (fullContactBin_nonneg G x v n m ω)] - exact fullContactBin_le G hloc d hd x v n m hn ω) - -end FullContactPower -end Percolation - - -namespace Percolation -open MeasureTheory -section NonnegativeDyadicIntegration - - - -theorem integral_le_tsum_majorants {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) - (f : Ω → ℝ) (F : ℕ → Ω → ℝ) (hfm : AEStronglyMeasurable f μ) - (hf0 : ∀ ω, 0 ≤ f ω) (hF0 : ∀ j ω, 0 ≤ F j ω) (hFi : ∀ j, Integrable (F j) μ) - (hs : Summable (fun j => ∫ ω, F j ω ∂μ)) - (hb : ∀ ω, ENNReal.ofReal (f ω) ≤ ∑' j, ENNReal.ofReal (F j ω)) : - Integrable f μ ∧ (∫ ω, f ω ∂μ) ≤ ∑' j, ∫ ω, F j ω ∂μ := by - have he : (∫⁻ ω, ∑' j, ENNReal.ofReal (F j ω) ∂μ) = - ENNReal.ofReal (∑' j, ∫ ω, F j ω ∂μ) := by - rw [lintegral_tsum (fun j => (hFi j).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] - simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hF0 _))] - exact (ENNReal.ofReal_tsum_of_nonneg (fun j => integral_nonneg (hF0 j)) hs).symm - have hle := (lintegral_mono hb).trans_eq he - have hi : Integrable f μ := ⟨hfm,(hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hf0)).mpr - (hle.trans_lt ENNReal.ofReal_lt_top)⟩ - refine ⟨hi,?_⟩ - rw [←ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall hf0)] at hle - exact (ENNReal.ofReal_le_ofReal_iff (tsum_nonneg (fun j => integral_nonneg (hF0 j)))).mp hle - -theorem dyadic_rpow_identity (L : ℕ) (hL : 0 < L) (r : ℝ) (j : ℕ) : - ((2^j*L:ℕ):ℝ)^r = (L:ℝ)^r*((2:ℝ)^r)^j := by - rw [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,Real.mul_rpow (by positivity) (by positivity), - ←Real.rpow_natCast,←Real.rpow_mul (by norm_num),mul_comm (j:ℝ) r,Real.rpow_mul (by norm_num),Real.rpow_natCast,mul_comm] - -theorem dyadic_rpow_summable (L : ℕ) (hL : 0 < L) (r : ℝ) (hr : r < 0) : - Summable (fun j : ℕ => ((2^j*L:ℕ):ℝ)^r) := by - simp only [dyadic_rpow_identity L hL r] - exact (summable_geometric_of_lt_one (Real.rpow_nonneg (by norm_num) _) - (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr)).mul_left _ - -theorem dyadic_rpow_sum (L : ℕ) (hL : 0 < L) (r : ℝ) (hr : r < 0) : - (∑' j : ℕ, ((2^j*L:ℕ):ℝ)^r) = (L:ℝ)^r*(1-(2:ℝ)^r)⁻¹ := by - simp only [dyadic_rpow_identity L hL r,tsum_mul_left] - rw [tsum_geometric_of_lt_one (Real.rpow_nonneg (by norm_num) _) (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr)] - -end NonnegativeDyadicIntegration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FullLargeContacts -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def fullLargeContact (G : BondGraph V E) (x v : V) (L : ℕ) (ω : Set E) : ℝ := - if ¬Conn G ω x v ∧ L ≤ min (cluster G ω x).ncard (cluster G ω v).ncard - then clusterContactCount G ω x v else 0 - -theorem fullLargeContact_nonneg (G : BondGraph V E) (x v : V) (L : ℕ) (ω : Set E) : - 0 ≤ fullLargeContact G x v L ω := by unfold fullLargeContact; split_ifs <;> positivity - -theorem measurable_fullLargeContact [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x v : V) (L : ℕ) : - Measurable (fullLargeContact G x v L) := by - have hs : Measurable (fun ω : Set E => min (cluster G ω x).ncard (cluster G ω v).ncard) := - (measurable_cluster_ncard G hloc x).min (measurable_cluster_ncard G hloc v) - exact ((measurable_of_countable (fun k : ℕ => (k:ℝ))).comp (measurable_clusterContactCount G x v)).ite - (((measurableSet_conn G x v).compl).inter (measurableSet_le measurable_const hs)) measurable_const - -theorem fullLargeContact_le_dyadic (G : BondGraph V E) (x v : V) (L : ℕ) (hL : 0 < L) (ω : Set E) : - ENNReal.ofReal (fullLargeContact G x v L ω) ≤ - ∑' j : ℕ, ENNReal.ofReal (fullContactBin G x v (2^j*L) (2*(2^j*L)) ω) := by - by_cases h : ¬Conn G ω x v ∧ L ≤ min (cluster G ω x).ncard (cluster G ω v).ncard - · let k := min (cluster G ω x).ncard (cluster G ω v).ncard - let j := Nat.log 2 (k/L) - have hq : k/L ≠ 0 := by - have : 1 ≤ k/L := (Nat.le_div_iff_mul_le hL).mpr (by rw [one_mul]; exact h.2) - omega - have hl := (Nat.le_div_iff_mul_le hL).mp (Nat.pow_log_le_self 2 hq) - have hu := (Nat.div_lt_iff_lt_mul hL).mp (Nat.lt_pow_succ_log_self (by norm_num : 1 < (2:ℕ)) (k/L)) - have hbin : fullContactBin G x v (2^j*L) (2*(2^j*L)) ω = fullLargeContact G x v L ω := by - rw [fullLargeContact,ite_eq_left h,fullContactBin,ite_eq_left] - refine ⟨h.1,hl,?_⟩ - calc - _ = k := rfl - _ ≤ 2^(Nat.log 2 (k/L)+1)*L := hu.le - _ = _ := by dsimp [j]; rw [pow_succ]; ring - exact (le_of_eq (congrArg ENNReal.ofReal hbin.symm)).trans - (ENNReal.le_tsum (f := fun scale => - ENNReal.ofReal (fullContactBin G x v (2^scale*L) (2*(2^scale*L)) ω)) j) - · simp only [fullLargeContact,ite_eq_right h,ENNReal.ofReal_zero]; exact bot_le - - - -theorem fullLargeContact_bound_of_bins [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) - (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (p : unitInterval) - (A r : ℝ) (_hA : 0 ≤ A) (hr : r < 0) - (hB : ∀ n : ℕ, 1 ≤ n → (∫ ω, fullContactBin G x v n (2*n) ω ∂law p) ≤ A*(n:ℝ)^r) - (L : ℕ) (hL : 0 < L) : - Integrable (fullLargeContact G x v L) (law p) ∧ - (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(1-(2:ℝ)^r)⁻¹*(L:ℝ)^r := by - let F := fun j => fullContactBin G x v (2^j*L) (2*(2^j*L)) - have hbp (j : ℕ) : 0 < 2^j*L := Nat.mul_pos (pow_pos (by norm_num) _) hL - have hFi (j : ℕ) : Integrable (F j) (law p) := integrable_fullContactBin G hloc d hd x v _ _ (hbp j) p - have hsumB := (dyadic_rpow_summable L hL r hr).mul_left A - have hsum : Summable (fun j => ∫ ω, F j ω ∂law p) := - hsumB.of_nonneg_of_le (fun j => integral_nonneg (fullContactBin_nonneg G x v _ _)) - (fun j => hB _ (hbp j)) - obtain ⟨hi,hb⟩ := integral_le_tsum_majorants (law p) (fullLargeContact G x v L) F - (measurable_fullLargeContact G hloc x v L).aestronglyMeasurable - (fullLargeContact_nonneg G x v L) (fun j => fullContactBin_nonneg G x v _ _) hFi hsum - (fullLargeContact_le_dyadic G x v L hL) - refine ⟨hi,hb.trans ?_⟩ - calc - _ ≤ ∑' j : ℕ, A*((2^j*L:ℕ):ℝ)^r := hsum.tsum_le_tsum (fun j => hB _ (hbp j)) hsumB - _ = _ := by rw [tsum_mul_left,dyadic_rpow_sum L hL r hr]; ring - -end FullLargeContacts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformLargeContacts -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem incident_ncard_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - {e | x ∈ G e}.ncard ≤ degree G x := by - have he : ((hloc x).toFinset.filter fun e => x ∈ G e) = (hloc x).toFinset := by - ext e - simp only [Finset.mem_filter,Set.Finite.mem_toFinset,Set.mem_ofPred_eq,and_self] - simpa only [he,←Set.ncard_eq_toFinset_card] using incident_filter_card_le_degree G hloc (hloc x).toFinset x - -theorem fullLargeContact_power_bound [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (q : unitInterval) - (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : - ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → - ∀ L : ℕ, 1 ≤ L → Integrable (fullLargeContact G x v L) (law p) ∧ - (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(L:ℝ)^((1:ℝ)/2+ε-2*α) := by - obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt - have hdn (x : V) := (incident_ncard_le_degree G hloc x).trans (hdeg x) - obtain ⟨A,hA,hAb⟩ := fullContactBin_power_bound G hloc q α ε C p₀ hα hα1 hε hr hC0 hp₀ hfin hI hC d hd hdn - refine ⟨A*(1-(2:ℝ)^((1:ℝ)/2+ε-2*α))⁻¹,?_ ,?_⟩ - · exact mul_pos hA (inv_pos.mpr (sub_pos.mpr (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr))) - · intro x v p hpp hpq L hL - exact fullLargeContact_bound_of_bins G hloc d hdn x v p A _ hA.le hr (hAb x v p hpp hpq) L hL - - - -theorem critical_large_contact_bound - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → - ∀ L : ℕ, 1 ≤ L → Integrable (fullLargeContact G x v L) (law p) ∧ - (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(L:ℝ)^((1:ℝ)/2+ε-2*α) := by - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by - intro x - obtain ⟨i,a,b,hab,rfl⟩ := hcover x - exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) - obtain ⟨C,hC,hb⟩ := uniform_cluster_power_of_root G hloc (pc G) root hcover α - (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) - exact fullLargeContact_power_bound G hloc hqt (pc G) α ε C ((pc G:ℝ)/2) hα.le (by linarith) - hε hr hC (by positivity) hfinite (fun x => (hb x).1) (fun x => (hb x).2) - -end UniformLargeContacts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ExtendedTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem enn_sum_iSup_nat {α : Type*} (s : Finset α) (f : ℕ → α → ℝ≥0∞) - (hm : ∀ a, Monotone (fun n => f n a)) : - (∑ a ∈ s, ⨆ n, f n a) = ⨆ n, ∑ a ∈ s, f n a := by - induction s using Finset.induction_on with - | empty => simp - | @insert a s ha ih => - simp only [Finset.sum_insert ha,ih] - exact ENNReal.iSup_add_iSup_of_monotone (hm a) (fun n m h => - Finset.sum_le_sum fun a _ => hm a h) - -theorem enn_tsum_iSup_nat {α : Type*} (f : ℕ → α → ℝ≥0∞) - (hm : ∀ a, Monotone (fun n => f n a)) : - (∑' a, ⨆ n, f n a) = ⨆ n, ∑' a, f n a := by - simp_rw [ENNReal.tsum_eq_iSup_sum,enn_sum_iSup_nat _ f hm] - exact iSup_comm - - - -theorem RootTransport.ennreal (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (m : V → V → ℝ≥0∞) - (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) : - (∑ i, ENNReal.ofReal (weight i) * ∑' y, m (root i) y) = - (∑ i, ENNReal.ofReal (weight i) * ∑' x, m x (root i)) := by - let cut (n : ℕ) (x y : V) : ℝ≥0∞ := - if transportCut G n x y then min (m x y) n else 0 - have hc0 (n : ℕ) (x y : V) : cut n x y ≠ ⊤ := by - dsimp [cut] - split_ifs - · exact ne_top_of_le_ne_top (ENNReal.natCast_ne_top n) (min_le_right _ _) - · exact ENNReal.zero_ne_top - have hcm (x y : V) : Monotone (fun n => cut n x y) := by - intro n k hnk - dsimp [cut] - split_ifs with hn hk - · exact min_le_min_left _ (by exact_mod_cast hnk) - · exact False.elim (hk (transportCut_mono G hnk hn)) - · exact zero_le - · exact le_refl _ - have hcs (x y : V) : (⨆ n, cut n x y) = m x y := by - apply le_antisymm - · refine iSup_le fun n => ?_ - dsimp [cut] - split_ifs - · exact min_le_left _ _ - · exact zero_le - · obtain ⟨N,hN⟩ := exists_transportCut G hconn y {x} - have hxy := hN x (Finset.mem_singleton_self x) - have he : (⨆ k : ℕ, min (m x y) (k:ℝ≥0∞)) = m x y := by - rw [←inf_iSup_eq,ENNReal.iSup_natCast,inf_top_eq] - rw [←he] - refine iSup_le fun k => le_iSup_of_le (max N k) ?_ - dsimp [cut] - rw [ite_eq_left (transportCut_mono G (le_max_left N k) hxy)] - exact min_le_min_left _ (by exact_mod_cast le_max_right N k) - have hrow (n : ℕ) (x : V) : Summable (fun y => (cut n x y).toReal) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x n).toFinset) - intro y hy - have hh : ¬transportCut G n x y := fun h => hy ((Set.Finite.mem_toFinset _).mpr h.1) - simp only [cut,ite_eq_right hh,ENNReal.toReal_zero] - have hcol (n : ℕ) (y : V) : Summable (fun x => (cut n x y).toReal) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) - intro x hx - have hh : ¬transportCut G n x y := fun h => hx ((Set.Finite.mem_toFinset _).mpr h.2) - simp only [cut,ite_eq_right hh,ENNReal.toReal_zero] - have he (n : ℕ) : - (∑ i, ENNReal.ofReal (weight i) * ∑' y, cut n (root i) y) = - (∑ i, ENNReal.ofReal (weight i) * ∑' x, cut n x (root i)) := by - have ht := htr.real root weight Γ (fun x y => (cut n x y).toReal) - (fun a ha x y => by - obtain ⟨b,hb⟩ := hΓ ha - simp only [cut,transportCut_aut G hb,hi a ha]) (hrow n) (hcol n) - apply_fun ENNReal.ofReal at ht - rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) - (tsum_nonneg fun _ => ENNReal.toReal_nonneg)), - ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) - (tsum_nonneg fun _ => ENNReal.toReal_nonneg))] at ht - simp_rw [ENNReal.ofReal_mul (hw _), - ENNReal.ofReal_tsum_of_nonneg (fun _ => ENNReal.toReal_nonneg) (hrow n _), - ENNReal.ofReal_tsum_of_nonneg (fun _ => ENNReal.toReal_nonneg) (hcol n _), - ENNReal.ofReal_toReal (hc0 n _ _)] at ht - exact ht - have hlim (f : ι → V → ℝ≥0∞) (g : ℕ → ι → V → ℝ≥0∞) - (hmono : ∀ i y, Monotone (fun n => g n i y)) (hs : ∀ i y, (⨆ n, g n i y) = f i y) : - (∑ i, ENNReal.ofReal (weight i) * ∑' y, f i y) = - ⨆ n, ∑ i, ENNReal.ofReal (weight i) * ∑' y, g n i y := by - simp_rw [←hs,enn_tsum_iSup_nat _ (hmono _),ENNReal.mul_iSup] - exact enn_sum_iSup_nat _ _ (fun i n k h => mul_le_mul_right (ENNReal.tsum_le_tsum - (fun y => hmono i y h)) _) - rw [hlim (fun i y => m (root i) y) (fun n i y => cut n (root i) y) - (fun i y => hcm (root i) y) (fun i y => hcs (root i) y), - hlim (fun i x => m x (root i)) (fun n i x => cut n x (root i)) - (fun i x => hcm x (root i)) (fun i x => hcs x (root i))] - exact iSup_congr he - -end ExtendedTransport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ClusterAveraging -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def clusterAveragingKernel (G : BondGraph V E) (ω : Set E) (x y : V) : ℝ≥0∞ := - if Conn G ω x y then ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ else 0 - -theorem measurable_clusterAveragingKernel [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : - Measurable (fun ω => clusterAveragingKernel G ω x y) := by - exact (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp - (measurable_cluster_ncard G hloc x)).inv).ite (measurableSet_conn G x y) measurable_const - -theorem clusterAveragingKernel_symm (G : BondGraph V E) (ω : Set E) (x y : V) : - clusterAveragingKernel G ω x y = clusterAveragingKernel G ω y x := by - by_cases h : Conn G ω x y - · simp only [clusterAveragingKernel,ite_eq_left h,ite_eq_left (conn_symm G ω h),cluster_eq_of_conn G ω h] - · have h' : ¬Conn G ω y x := fun hh => h (conn_symm G ω hh) - simp only [clusterAveragingKernel,ite_eq_right h,ite_eq_right h'] - -theorem cluster_ncard_pos (G : BondGraph V E) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : 0 < (cluster G ω x).ncard := - (Set.ncard_pos hf).mpr ⟨x,mem_cluster_self G ω x⟩ - -theorem clusterAveragingKernel_row (G : BondGraph V E) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : (∑' y, clusterAveragingKernel G ω x y) = 1 := by - have he : (fun y => clusterAveragingKernel G ω x y) = - (fun y => (if Conn G ω x y then (1:ℝ≥0∞) else 0)*((cluster G ω x).ncard:ℝ≥0∞)⁻¹) := by - funext y - unfold clusterAveragingKernel - split_ifs <;> simp - rw [he,ENNReal.tsum_mul_right] - change clusterMass G ω x * ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ = 1 - rw [clusterMass_eq_ncard G ω x hf] - exact ENNReal.mul_inv_cancel (by exact_mod_cast (cluster_ncard_pos G ω x hf).ne') (ENNReal.natCast_ne_top _) - -theorem clusterAveragingKernel_column (G : BondGraph V E) (ω : Set E) (y : V) - (hf : (cluster G ω y).Finite) : (∑' x, clusterAveragingKernel G ω x y) = 1 := by - simp_rw [clusterAveragingKernel_symm G ω] - exact clusterAveragingKernel_row G ω y hf - -theorem clusterAveragingKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) : - clusterAveragingKernel G (b ⁻¹' ω) x y = clusterAveragingKernel G ω (a x) (a y) := by - simp only [clusterAveragingKernel,conn_aut_iff G hab,cluster_ncard_covariant G hab] - - - -theorem root_cluster_average [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (f : Set E → V → ℝ≥0∞) (hf : ∀ x, Measurable (fun ω => f ω x)) - (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x, f (b ⁻¹' ω) x = f ω (a x)) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, - clusterAveragingKernel G ω (root i) y * f ω y ∂law p) = - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, f ω (root i) ∂law p) := by - let m (x y : V) : ℝ≥0∞ := ∫⁻ ω, clusterAveragingKernel G ω x y * f ω y ∂law p - have hm (x y : V) : Measurable (fun ω => clusterAveragingKernel G ω x y * f ω y) := - (measurable_clusterAveragingKernel G hloc x y).mul (hf y) - have hinv : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y := by - intro a ha x y - obtain ⟨b,hb⟩ := hΓ ha - have ht := lintegral_map (μ := law p) (hm x y) (measurable_set_preimage b) - rw [law_map_preimage_equiv] at ht - dsimp only [m] - rw [ht] - apply lintegral_congr - intro ω - rw [clusterAveragingKernel_aut G hb,hi a ha b hb] - have ht := htr.ennreal G hconn hloc root weight Γ hΓ hw m hinv - have hr (x : V) : (∑' y, m x y) = ∫⁻ ω, ∑' y, clusterAveragingKernel G ω x y*f ω y ∂law p := by - exact (lintegral_tsum (fun y => (hm x y).aemeasurable)).symm - have hc (y : V) : (∑' x, m x y) = ∫⁻ ω, f ω y ∂law p := by - rw [show (∑' x, m x y) = ∫⁻ ω, ∑' x, clusterAveragingKernel G ω x y*f ω y ∂law p from - (lintegral_tsum (fun x => (hm x y).aemeasurable)).symm] - apply lintegral_congr_ae - filter_upwards [hfin y] with ω hω - rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G ω y hω,one_mul] - simpa only [hr,hc] using ht - -end ClusterAveraging -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PositiveClusterPairs -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def clusterPairKernel (G : BondGraph V E) (ω : Set E) - (J : V → V → ℝ≥0∞) (x y : V) : ℝ≥0∞ := - ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b then J a b else 0 - - - -noncomputable def clusterPairDensity (G : BondGraph V E) (ω : Set E) - (F : V → V → ℝ≥0∞) (x : V) : ℝ≥0∞ := - ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * - ∑' y, ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * (if ¬Conn G ω x y then F x y else 0) - -noncomputable def clusterPairFunctional (G : BondGraph V E) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (F : Set E → V → V → ℝ≥0∞) : ℝ≥0∞ := - ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, clusterPairDensity G ω (F ω) (root i) ∂law p - -theorem cluster_weighted_resum (G : BondGraph V E) (ω : Set E) - (hfin : ∀ x, (cluster G ω x).Finite) (f : V → V → ℝ≥0∞) - (hc : ∀ x y, Conn G ω x y → f x y = f y y) : - (∑' x, ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * - ∑' y, if Conn G ω x y then f x y else 0) = ∑' y, f y y := by - have he (x y : V) : ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * - (if Conn G ω x y then f x y else 0) = clusterAveragingKernel G ω x y*f y y := by - by_cases h : Conn G ω x y - · simp only [ite_eq_left h,clusterAveragingKernel,hc x y h] - · simp only [ite_eq_right h,clusterAveragingKernel,mul_zero,zero_mul] - simp_rw [←ENNReal.tsum_mul_left,he] - rw [ENNReal.tsum_comm] - apply tsum_congr - intro y - rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G ω y (hfin y),one_mul] - -theorem clusterPairDensity_reroot_pointwise (G : BondGraph V E) (ω : Set E) - (hfin : ∀ x, (cluster G ω x).Finite) (J F : V → V → ℝ≥0∞) - (hF : ∀ x y a b, Conn G ω x a → Conn G ω y b → F x y = F a b) (x : V) : - clusterPairDensity G ω (fun a b => clusterPairKernel G ω J a b * F a b) x = - ∑' a, clusterAveragingKernel G ω x a * - ∑' b, J a b * (if ¬Conn G ω a b then F a b else 0) := by - let K (a b : V) : ℝ≥0∞ := if ¬Conn G ω a b then F a b else 0 - have hK (a b c d : V) (hac : Conn G ω a c) (hbd : Conn G ω b d) : K a b = K c d := by - have he : Conn G ω a b ↔ Conn G ω c d := by - constructor - · intro h; exact conn_trans G ω (conn_symm G ω hac) (conn_trans G ω h hbd) - · intro h; exact conn_trans G ω hac (conn_trans G ω h (conn_symm G ω hbd)) - simp only [K,he,hF a b c d hac hbd] - have hterm (y : V) : ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * - (if ¬Conn G ω x y then clusterPairKernel G ω J x y*F x y else 0) = - ∑' a, if Conn G ω x a then ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * - ∑' b, if Conn G ω y b then J a b*K x y else 0 else 0 := by - have hcond : (if ¬Conn G ω x y then clusterPairKernel G ω J x y*F x y else 0) = - clusterPairKernel G ω J x y*K x y := by dsimp [K]; split_ifs <;> simp - rw [hcond,clusterPairKernel,←ENNReal.tsum_mul_right,←ENNReal.tsum_mul_left] - apply tsum_congr - intro a - by_cases hxa : Conn G ω x a - · rw [ite_eq_left hxa,←ENNReal.tsum_mul_right] - congr 1 - apply tsum_congr - intro b - by_cases hyb : Conn G ω y b <;> simp only [hxa,hyb,and_self,and_false, - ite_true,ite_false,zero_mul] - · simp only [hxa,false_and,ite_false,tsum_zero,zero_mul,mul_zero] - unfold clusterPairDensity - simp_rw [hterm] - rw [ENNReal.tsum_comm,←ENNReal.tsum_mul_left] - apply tsum_congr - intro a - by_cases hxa : Conn G ω x a - · simp only [ite_eq_left hxa,clusterAveragingKernel] - congr 1 - rw [cluster_weighted_resum G ω hfin (fun y b => J a b*K x y) - (fun y b hyb => congrArg (fun t => J a b*t) (hK x y x b (conn_refl G ω x) hyb))] - apply tsum_congr - intro b - rw [hK x b a b hxa (conn_refl G ω b)] - · simp only [ite_eq_right hxa,tsum_zero,mul_zero,clusterAveragingKernel,zero_mul] - -end PositiveClusterPairs -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ClusterPairRerooting -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem clusterPairFunctional_reroot [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) - (F : Set E → V → V → ℝ≥0∞) (hm : ∀ x y, Measurable (fun ω => F ω x y)) - (hF : ∀ ω x y a b, Conn G ω x a → Conn G ω y b → F ω x y = F ω a b) - (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x y, F (b ⁻¹' ω) x y = F ω (a x) (a y)) : - clusterPairFunctional G p root weight (fun ω x y => clusterPairKernel G ω J x y * F ω x y) = - ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, - J (root i) y * (if ¬Conn G ω (root i) y then F ω (root i) y else 0) ∂law p := by - let f (ω : Set E) (x : V) : ℝ≥0∞ := - ∑' y, J x y * (if ¬Conn G ω x y then F ω x y else 0) - have hf (x : V) : Measurable (fun ω => f ω x) := by - apply Measurable.tsum - intro y - exact measurable_const.mul ((hm x y).ite (measurableSet_conn G x y).compl measurable_const) - have hfe : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x, f (b ⁻¹' ω) x = f ω (a x) := by - intro a ha b hab ω x - dsimp [f] - rw [←a.tsum_eq (fun y => J (a x) y * (if ¬Conn G ω (a x) y then F ω (a x) y else 0))] - apply tsum_congr - intro y - rw [hJ a ha,conn_aut_iff G hab,hi a ha b hab] - have ht := root_cluster_average G hconn hloc root weight Γ hΓ htr hw p hfin f hf hfe - rw [clusterPairFunctional] - calc - _ = ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, - clusterAveragingKernel G ω (root i) y*f ω y ∂law p := by - apply Finset.sum_congr rfl - intro i _ - congr 1 - apply lintegral_congr_ae - filter_upwards [ae_all_iff.mpr hfin] with ω hω - exact clusterPairDensity_reroot_pointwise G ω hω J (F ω) (hF ω) (root i) - _ = _ := ht - -end ClusterPairRerooting -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PairReversal -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def clusterPairMass (G : BondGraph V E) (ω : Set E) - (F : V → V → ℝ≥0∞) (x y : V) : ℝ≥0∞ := - ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * - (if ¬Conn G ω x y then F x y else 0) - -theorem clusterPairDensity_eq_tsum (G : BondGraph V E) (ω : Set E) - (F : V → V → ℝ≥0∞) (x : V) : - clusterPairDensity G ω F x = ∑' y, clusterPairMass G ω F x y := by - simp only [clusterPairDensity,clusterPairMass,←ENNReal.tsum_mul_left,mul_assoc] - -theorem clusterPairMass_swap (G : BondGraph V E) (ω : Set E) - (F : V → V → ℝ≥0∞) (x y : V) : - clusterPairMass G ω F x y = clusterPairMass G ω (fun a b => F b a) y x := by - have he : Conn G ω x y ↔ Conn G ω y x := ⟨conn_symm G ω,conn_symm G ω⟩ - simp only [clusterPairMass,he,mul_comm] - -theorem measurable_clusterPairMass [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (F : Set E → V → V → ℝ≥0∞) (hf : ∀ x y, Measurable (fun ω => F ω x y)) (x y : V) : - Measurable (fun ω => clusterPairMass G ω (F ω) x y) := by - have hs (x : V) : Measurable (fun ω => ((cluster G ω x).ncard:ℝ≥0∞)⁻¹) := - (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_cluster_ncard G hloc x))).inv - exact ((hs x).mul (hs y)).mul ((hf x y).ite (measurableSet_conn G x y).compl measurable_const) - -theorem clusterPairFunctional_swap [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (F : Set E → V → V → ℝ≥0∞) (hf : ∀ x y, Measurable (fun ω => F ω x y)) - (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x y, F (b ⁻¹' ω) x y = F ω (a x) (a y)) : - clusterPairFunctional G p root weight F = - clusterPairFunctional G p root weight (fun ω x y => F ω y x) := by - let m (x y : V) : ℝ≥0∞ := ∫⁻ ω, clusterPairMass G ω (F ω) x y ∂law p - have hm := measurable_clusterPairMass G hloc F hf - have hinv : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y := by - intro a ha x y - obtain ⟨b,hb⟩ := hΓ ha - have ht := lintegral_map (μ := law p) (hm x y) (measurable_set_preimage b) - rw [law_map_preimage_equiv] at ht - dsimp only [m] - rw [ht] - apply lintegral_congr - intro ω - simp only [clusterPairMass,cluster_ncard_covariant G hb,conn_aut_iff G hb,hi a ha b hb] - have ht := htr.ennreal G hconn hloc root weight Γ hΓ hw m hinv - have hr (x : V) : (∑' y, m x y) = ∫⁻ ω, clusterPairDensity G ω (F ω) x ∂law p := by - simp_rw [clusterPairDensity_eq_tsum] - exact (lintegral_tsum (fun y => (hm x y).aemeasurable)).symm - have hc (y : V) : (∑' x, m x y) = - ∫⁻ ω, clusterPairDensity G ω (fun a b => F ω b a) y ∂law p := by - simp_rw [clusterPairDensity_eq_tsum,←clusterPairMass_swap G _ (F _)] - exact (lintegral_tsum (fun x => (hm x y).aemeasurable)).symm - simpa only [hr,hc,clusterPairFunctional] using ht - -end PairReversal -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.TailBounds + +namespace OAI + +/-! Large Contacts for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UnorderedContactConcentration +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem cluster_contact_tail (G : BondGraph V E) (Q : Finset E) + (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) + (x v : V) (p : unitInterval) (m : ℕ) (hdm : 0 < d*m) (a : ℝ) (ha : 0 < a) : + bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ + min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) + (finiteRootComponent G ω v)).card then 1 else 0) p ≤ + 8*Real.exp (-2*a^2/(d*m:ℕ)) := by + let f (x v : V) (ω : Finset E) : ℝ := + if ¬Conn G (ω:Set E) x v ∧ (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ d*m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) + (finiteRootComponent G ω v)).card then 1 else 0 + calc + _ ≤ bernoulliPolynomial Q (fun ω => f x v ω+f v x ω) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + by_cases h : ¬Conn G (ω:Set E) x v ∧ + min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) + (finiteRootComponent G ω v)).card + · simp only [ite_eq_left h] + rcases le_total (finiteRootComponent G ω v).card (finiteRootComponent G ω x).card with hc | hc + · have hsmall : (finiteRootComponent G ω v).card ≤ m := by simpa only [min_eq_right hc] using h.2.1 + have hh : ¬Conn G (ω:Set E) x v ∧ (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ d*m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := + ⟨h.1,(incidentBonds_card_le G Q _ d hd).trans (Nat.mul_le_mul_left d hsmall),h.2.2⟩ + simp only [f,ite_eq_left hh]; split_ifs <;> norm_num + · have hsmall : (finiteRootComponent G ω x).card ≤ m := by simpa only [min_eq_left hc] using h.2.1 + have hh : ¬Conn G (ω:Set E) v x ∧ (incidentBonds G Q (finiteRootComponent G ω x)).card ≤ d*m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω v) (finiteRootComponent G ω x)).card := by + refine ⟨fun hc' => h.1 (conn_symm G _ hc'), + (incidentBonds_card_le G Q _ d hd).trans (Nat.mul_le_mul_left d hsmall),?_⟩ + rw [contactBonds_comm G Q (finiteRootComponent G ω v)] + exact h.2.2 + simp only [f,ite_eq_left hh]; split_ifs <;> norm_num + · simp only [ite_eq_right h,f]; split_ifs <;> norm_num + _ = bernoulliPolynomial Q (f x v) p+bernoulliPolynomial Q (f v x) p := + bernoulliPolynomial_add .. + _ ≤ 4*Real.exp (-2*a^2/(d*m:ℕ))+4*Real.exp (-2*a^2/(d*m:ℕ)) := + add_le_add (ordered_cluster_contact_tail G Q x v p (d*m) hdm a ha) + (ordered_cluster_contact_tail G Q v x p (d*m) hdm a ha) + _ = _ := by ring + +end UnorderedContactConcentration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TwoLargeFiniteClusters +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cluster_exterior_weighted_bound (G : BondGraph V E) (Q : Finset E) + (x : V) (p : unitInterval) (F : Finset V → ℝ) (hF : ∀ W, 0 ≤ F W) + (f : Finset V → Finset E → ℝ) (K : ℝ) + (hf : ∀ W : Finset V, bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ K) : + bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)*f (finiteRootComponent G ω x) + (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p ≤ + K*bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)) p := by + have hh := cluster_exterior_expectation_bound G Q x p + (fun W η => F W*f W η-K*F W) 0 (fun W => by + rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul,bernoulliPolynomial_const] + exact sub_nonpos.mpr (by simpa only [mul_comm K] using mul_le_mul_of_nonneg_left (hf W) (hF W))) + rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul] at hh + exact sub_nonpos.mp hh + +theorem finiteClusterTail_domain_mono (G : BondGraph V E) {Q R : Finset E} (hRQ : R ⊆ Q) + (x : V) (n : ℕ) (p : unitInterval) : finiteClusterTail G R x n p ≤ finiteClusterTail G Q x n p := by + unfold finiteClusterTail + rw [←bernoulliPolynomial_restrict R Q hRQ] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + exact finiteClusterTailIndicator_mono G x n Finset.inter_subset_left + + + +theorem two_large_clusters_tail (G : BondGraph V E) (Q : Finset E) + (x v : V) (n m : ℕ) (p : unitInterval) : + bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ + n ≤ (finiteRootComponent G ω x).card ∧ m ≤ (finiteRootComponent G ω v).card + then 1 else 0) p ≤ finiteClusterTail G Q v m p*finiteClusterTail G Q x n p := by + let F (W : Finset V) : ℝ := if n ≤ W.card then 1 else 0 + let f (W : Finset V) (η : Finset E) : ℝ := if v ∈ W then 0 else finiteClusterTailIndicator G v m η + have hF : ∀ W, 0 ≤ F W := fun W => by dsimp [F]; split_ifs <;> norm_num + have hf (W : Finset V) : bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ + finiteClusterTail G Q v m p := by + by_cases hv : v ∈ W + · simp only [f,ite_eq_left hv,bernoulliPolynomial_zero] + exact finiteClusterTail_nonneg G Q v m p + · simp only [f,ite_eq_right hv] + exact finiteClusterTail_domain_mono G (Finset.filter_subset _ _) v m p + have hp := cluster_exterior_weighted_bound G Q x p F hF f (finiteClusterTail G Q v m p) hf + have heq : bernoulliPolynomial Q (fun ω => F (finiteRootComponent G ω x)*f (finiteRootComponent G ω x) + (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p = + bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ + n ≤ (finiteRootComponent G ω x).card ∧ m ≤ (finiteRootComponent G ω v).card then 1 else 0) p := by + apply bernoulliPolynomial_congr + intro ω _ + have hv : v ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x v := by + change v ∈ (finiteRootComponent G ω x:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + by_cases hc : Conn G (ω:Set E) x v + · simp only [F,f,ite_eq_left (hv.mpr hc),mul_zero,not_true_eq_false,hc,false_and,ite_false] + · simp only [F,f,ite_eq_right (fun h => hc (hv.mp h)),finiteClusterTailIndicator, + finiteRootComponent_exterior G ω x v hc] + split_ifs <;> norm_num <;> grind + rw [heq] at hp + exact hp + +end TwoLargeFiniteClusters +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section EndpointClusterTails +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteClusterTail_of_endpoint_moment [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (α C : ℝ) + (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) + (Q : Finset E) (x : V) (p : unitInterval) (hpq : p ≤ q) (n : ℕ) (hn : 1 ≤ n) : + finiteClusterTail G Q x n p ≤ 2*C*(n:ℝ)^(-α) := by + have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) + let h : unitInterval := ⟨1/(n:ℝ),⟨by positivity,by apply (div_le_one hn0).mpr; exact_mod_cast hn⟩⟩ + have hh : 0 < (h:ℝ) := by dsimp [h]; positivity + have hhpow : (h:ℝ)^α = (n:ℝ)^(-α) := by + dsimp [h] + rw [one_div,Real.inv_rpow hn0.le,Real.rpow_neg hn0.le] + have hhn : 1 ≤ (h:ℝ)*n := by dsimp [h]; rw [one_div,inv_mul_cancel₀ hn0.ne'] + have hm := cluster_power_mono_integral G hloc x p q hpq α hα (hfin x) (hI x) + have hb := markedConnection_le_cluster_power G Q x h p α hα hα1 + (cluster_finite_ae_mono G x p q hpq (hfin x)) hm.1 + have hM : markedConnectionPolynomial G Q x h p ≤ C*(n:ℝ)^(-α) := by + apply hb.trans + rw [hhpow] + simpa only [mul_comm C] using + mul_le_mul_of_nonneg_left (hm.2.trans (hC x)) (Real.rpow_nonneg (Nat.cast_nonneg n) (-α)) + have hb' := (finiteClusterTail_le_markedConnection G Q x n p h hhn).trans + (mul_le_mul_of_nonneg_left hM (by norm_num : (0:ℝ) ≤ 2)) + simpa only [mul_assoc] using hb' + +theorem two_large_clusters_of_endpoint_moment [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (α C : ℝ) + (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 ≤ C) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) + (Q : Finset E) (x v : V) (p : unitInterval) (hpq : p ≤ q) (n : ℕ) (hn : 1 ≤ n) : + bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ + n ≤ (finiteRootComponent G ω x).card ∧ n ≤ (finiteRootComponent G ω v).card + then 1 else 0) p ≤ 4*C^2*(n:ℝ)^(-2*α) := by + have ht (y : V) := finiteClusterTail_of_endpoint_moment G hloc q α C hα hα1 hfin hI hC Q y p hpq n hn + have hc : 0 ≤ 2*C*(n:ℝ)^(-α) := by positivity + calc + _ ≤ finiteClusterTail G Q v n p*finiteClusterTail G Q x n p := two_large_clusters_tail .. + _ ≤ (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) := + mul_le_mul (ht v) (ht x) (finiteClusterTail_nonneg G Q x n p) hc + _ = 4*C^2*(n:ℝ)^(-2*α) := by + have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) + rw [show (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) = + 4*C^2*((n:ℝ)^(-α)*(n:ℝ)^(-α)) by ring,←Real.rpow_add hn0] + congr 2 + ring + +end EndpointClusterTails +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ContactBinFirstMoment +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem contactBonds_card_le (G : BondGraph V E) (Q : Finset E) + (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) (A B : Finset V) : + (contactBonds G Q A B).card ≤ d*min A.card B.card := by + have hh (A B : Finset V) : (contactBonds G Q A B).card ≤ d*A.card := by + apply (Finset.card_le_card (t := incidentBonds G Q A) _).trans (incidentBonds_card_le G Q A d hd) + intro e he + obtain ⟨he,a,ha,b,_,hab⟩ := Finset.mem_filter.mp he + exact (mem_incidentBonds G Q A e).mpr ⟨he,a,ha,by rw [hab]; simp⟩ + rcases le_total A.card B.card with h | h + · rw [min_eq_left h]; exact hh A B + · rw [min_eq_right h,contactBonds_comm G Q A B]; exact hh B A + +noncomputable def clusterContactBin (G : BondGraph V E) (Q : Finset E) + (x v : V) (n m : ℕ) (ω : Finset E) : ℝ := + if ¬Conn G (ω:Set E) x v ∧ + n ≤ min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ∧ + min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m + then (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card else 0 + + + +theorem clusterContactBin_bound (G : BondGraph V E) (Q : Finset E) + (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) + (x v : V) (p : unitInterval) (hp : 0 < (p:ℝ)) (n m : ℕ) (hdm : 0 < d*m) + (a : ℝ) (ha : 0 < a) : + bernoulliPolynomial Q (clusterContactBin G Q x v n m) p ≤ + (2*a/(p:ℝ))*(finiteClusterTail G Q v n p*finiteClusterTail G Q x n p)+ + (d*m:ℕ)*(8*Real.exp (-2*a^2/(d*m:ℕ))) := by + let D (ω : Finset E) : Prop := ¬Conn G (ω:Set E) x v ∧ + n ≤ (finiteRootComponent G ω x).card ∧ n ≤ (finiteRootComponent G ω v).card + let T (ω : Finset E) : Prop := ¬Conn G (ω:Set E) x v ∧ + min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card + calc + _ ≤ bernoulliPolynomial Q (fun ω => (2*a/(p:ℝ))*(if D ω then 1 else 0)+ + (d*m:ℕ)*(if T ω then 1 else 0)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + unfold clusterContactBin + by_cases h : ¬Conn G (ω:Set E) x v ∧ + n ≤ min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ∧ + min (finiteRootComponent G ω x).card (finiteRootComponent G ω v).card ≤ m + · have hD : D ω := ⟨h.1,(le_min_iff.mp h.2.1).1,(le_min_iff.mp h.2.1).2⟩ + simp only [ite_eq_left h,ite_eq_left hD,mul_one] + by_cases ht : T ω + · rw [ite_eq_left ht,mul_one] + have hk : (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card ≤ d*m := + (contactBonds_card_le G Q d hd _ _).trans (Nat.mul_le_mul_left d h.2.2) + have hk' : ((contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card:ℝ) ≤ (d*m:ℕ) := by exact_mod_cast hk + have hapos : 0 ≤ 2*a/(p:ℝ) := by positivity + linarith + · rw [ite_eq_right ht,mul_zero,add_zero] + apply (le_div_iff₀ hp).mpr + have hn : ¬ 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := + fun hh => ht ⟨h.1,h.2.2,hh⟩ + simpa only [mul_comm] using (not_le.mp hn).le + · simp only [ite_eq_right h] + split_ifs <;> positivity + _ = (2*a/(p:ℝ))*bernoulliPolynomial Q (fun ω => if D ω then 1 else 0) p+ + (d*m:ℕ)*bernoulliPolynomial Q (fun ω => if T ω then 1 else 0) p := by + rw [bernoulliPolynomial_add,bernoulliPolynomial_const_mul,bernoulliPolynomial_const_mul] + _ ≤ _ := add_le_add + (mul_le_mul_of_nonneg_left (two_large_clusters_tail G Q x v n n p) (by positivity)) + (mul_le_mul_of_nonneg_left (cluster_contact_tail G Q d hd x v p m hdm a ha) (Nat.cast_nonneg _)) + +end ContactBinFirstMoment +end Percolation + + +namespace Percolation +section StretchedContactDecay + +theorem exists_stretched_exp_volume_bound (d ε r : ℝ) (hd : 0 < d) (hε : 0 < ε) (hr : r ≤ 1) : + ∃ C : ℝ, 0 < C ∧ ∀ z : ℝ, 0 < z → z*Real.exp (-(z^ε)/d) ≤ C*z^r := by + let s := (1-r)/ε + have hs : 0 ≤ s := by dsimp [s]; positivity + obtain ⟨K,hK,hKb⟩ := exists_exp_neg_le_rpow s hs + refine ⟨K*d^s,by positivity,?_⟩ + intro z hz + have he := mul_le_mul_of_nonneg_left (hKb (z^ε/d) (by positivity)) hz.le + have hex : ε*(-s) = r-1 := by dsimp [s]; field_simp; ring + have hid : (z^ε/d)^(-s) = z^(r-1)*d^s := by + rw [Real.div_rpow (Real.rpow_nonneg hz.le ε) hd.le,←Real.rpow_mul hz.le,hex, + Real.rpow_neg hd.le,div_inv_eq_mul] + have hzpow : z*z^(r-1) = z^r := by + conv_lhs => lhs; rw [←Real.rpow_one z] + rw [←Real.rpow_add hz] + congr 1 + ring + calc + _ ≤ z*(K*(z^ε/d)^(-s)) := by simpa only [neg_div] using he + _ = (K*d^s)*(z*z^(r-1)) := by rw [hid]; ring + _ = _ := by rw [hzpow] + +theorem contact_tail_exponent (d z ε : ℝ) (hd : 0 < d) (hz : 0 < z) : + -2*(z^((1:ℝ)/2+ε))^2/(d*(2*z)) = -(z^(2*ε))/d := by + have hpow : (z^((1:ℝ)/2+ε))^2 = z*z^(2*ε) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hz.le] + norm_num only [Nat.cast_ofNat] + rw [show ((1:ℝ)/2+ε)*2 = 1+2*ε by ring,Real.rpow_add hz,Real.rpow_one] + rw [hpow] + field_simp + +end StretchedContactDecay +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformContactBins +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem clusterContactBin_power_bound [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) + (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) + (d : ℕ) (hd : 0 < d) : + ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E), (∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) → + ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → ∀ n : ℕ, 1 ≤ n → + bernoulliPolynomial Q (clusterContactBin G Q x v n (2*n)) p ≤ + A*(n:ℝ)^((1:ℝ)/2+ε-2*α) := by + let r : ℝ := (1:ℝ)/2+ε-2*α + have hd' : (0:ℝ) < d := Nat.cast_pos.mpr hd + obtain ⟨K,hK,hKb⟩ := exists_stretched_exp_volume_bound (d:ℝ) (2*ε) r hd' (by positivity) (by dsimp [r]; linarith) + refine ⟨8*C^2/p₀+16*(d:ℝ)*K,by positivity,?_⟩ + intro Q hdeg x v p hpp hpq n hn + have hn' : 0 < n := by omega + have hnr : (0:ℝ) < n := Nat.cast_pos.mpr hn' + have hp : 0 < (p:ℝ) := hp₀.trans_le hpp + let a : ℝ := (n:ℝ)^((1:ℝ)/2+ε) + have ha : 0 < a := Real.rpow_pos_of_pos hnr _ + have hb := clusterContactBin_bound G Q d hdeg x v p hp n (2*n) (by positivity) a ha + have ht (y : V) := finiteClusterTail_of_endpoint_moment G hloc q α C hα hα1 hfin hI hC Q y p hpq n hn + have hprod : finiteClusterTail G Q v n p*finiteClusterTail G Q x n p ≤ 4*C^2*(n:ℝ)^(-2*α) := by + calc + _ ≤ (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) := + mul_le_mul (ht v) (ht x) (finiteClusterTail_nonneg G Q x n p) (by positivity) + _ = _ := by + rw [show (2*C*(n:ℝ)^(-α))*(2*C*(n:ℝ)^(-α)) = 4*C^2*((n:ℝ)^(-α)*(n:ℝ)^(-α)) by ring, + ←Real.rpow_add hnr] + congr 2 + ring + have hfirst : (2*a/(p:ℝ))*(finiteClusterTail G Q v n p*finiteClusterTail G Q x n p) ≤ + (8*C^2/p₀)*(n:ℝ)^r := by + calc + _ ≤ (2*a/p₀)*(4*C^2*(n:ℝ)^(-2*α)) := + mul_le_mul (div_le_div_of_nonneg_left (by positivity) hp₀ hpp) hprod + (mul_nonneg (finiteClusterTail_nonneg G Q v n p) (finiteClusterTail_nonneg G Q x n p)) (by positivity) + _ = (8*C^2/p₀)*((n:ℝ)^((1:ℝ)/2+ε)*(n:ℝ)^(-2*α)) := by dsimp [a]; ring + _ = _ := by rw [←Real.rpow_add hnr]; congr 2; dsimp [r]; ring + have hex : -2*a^2/(d*(2*n):ℕ) = -((n:ℝ)^(2*ε))/(d:ℝ) := by + simp only [Nat.cast_mul,Nat.cast_ofNat] + exact contact_tail_exponent d n ε hd' hnr + have hsecond : (d*(2*n):ℕ)*(8*Real.exp (-2*a^2/(d*(2*n):ℕ))) ≤ + (16*(d:ℝ)*K)*(n:ℝ)^r := by + rw [hex] + calc + _ = (16*(d:ℝ))*((n:ℝ)*Real.exp (-((n:ℝ)^(2*ε))/(d:ℝ))) := by + push_cast + ring + _ ≤ (16*(d:ℝ))*(K*(n:ℝ)^r) := mul_le_mul_of_nonneg_left (hKb n hnr) (by positivity) + _ = _ := by ring + calc + _ ≤ _ := hb + _ ≤ (8*C^2/p₀)*(n:ℝ)^r+(16*(d:ℝ)*K)*(n:ℝ)^r := add_le_add hfirst hsecond + _ = _ := by dsimp [r]; ring + +end UniformContactBins +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section InfiniteContacts +attribute [local instance] Classical.propDecidable Classical.decEq + + +def closedContactSet (G : BondGraph V E) (A B : Set V) : Set E := + {e | ∃ a ∈ A, ∃ b ∈ B, G e = s(a,b)} + +noncomputable def clusterContactCount (G : BondGraph V E) (ω : Set E) (x v : V) : ℕ := + (closedContactSet G (cluster G ω x) (cluster G ω v)).ncard + +noncomputable def fullContactBin (G : BondGraph V E) (x v : V) (n m : ℕ) (ω : Set E) : ℝ := + if ¬Conn G ω x v ∧ n ≤ min (cluster G ω x).ncard (cluster G ω v).ncard ∧ + min (cluster G ω x).ncard (cluster G ω v).ncard ≤ m + then clusterContactCount G ω x v else 0 + +theorem contactSet_subset_incident (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset V) (B : Set V) : closedContactSet G (A:Set V) B ⊆ (incidentSupport G hloc A:Set E) := by + rintro e ⟨a,ha,b,_,hab⟩ + exact (mem_incidentSupport G hloc A e).mpr ⟨a,ha,by rw [hab]; simp⟩ + +theorem coe_contactBonds_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (A B : Finset V) (hQ : incidentSupport G hloc A ⊆ Q) : + (contactBonds G Q A B : Set E) = closedContactSet G A B := by + ext e + constructor + · exact fun h => (Finset.mem_filter.mp h).2 + · intro h + exact Finset.mem_filter.mpr ⟨hQ (contactSet_subset_incident G hloc A B h),h⟩ + +theorem contactSet_ncard_le (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) + (A B : Set V) (hA : A.Finite) (hB : B.Finite) : + (closedContactSet G A B).ncard ≤ d*min A.ncard B.ncard := by + let Q := incidentSupport G hloc (hA.toFinset ∪ hB.toFinset) + have hdeg (z : V) : (Q.filter fun e => z ∈ G e).card ≤ d := by + calc + _ = ((Q.filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm + _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) + _ ≤ d := hd z + have hQ : incidentSupport G hloc hA.toFinset ⊆ Q := + incidentSupport_mono G hloc Finset.subset_union_left + have he := coe_contactBonds_eq G hloc Q hA.toFinset hB.toFinset hQ + simp only [Set.Finite.coe_toFinset] at he + rw [←he,Set.ncard_coe_finset] + simpa only [←Set.ncard_eq_toFinset_card] using contactBonds_card_le G Q d hdeg hA.toFinset hB.toFinset + +theorem fullContactBin_nonneg (G : BondGraph V E) (x v : V) (n m : ℕ) (ω : Set E) : + 0 ≤ fullContactBin G x v n m ω := by unfold fullContactBin; split_ifs <;> positivity + +theorem fullContactBin_le (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (n m : ℕ) (hn : 0 < n) (ω : Set E) : + fullContactBin G x v n m ω ≤ (d*m:ℕ) := by + unfold fullContactBin + split_ifs with h + · have hx : (cluster G ω x).Finite := Set.finite_of_ncard_ne_zero (by omega) + have hv : (cluster G ω v).Finite := Set.finite_of_ncard_ne_zero (by omega) + exact_mod_cast (contactSet_ncard_le G hloc d hd _ _ hx hv).trans (Nat.mul_le_mul_left d h.2.2) + · positivity + +end InfiniteContacts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section ContactMeasurability +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_clusterContactCount [Countable V] [Countable E] + (G : BondGraph V E) (x v : V) : Measurable (fun ω : Set E => clusterContactCount G ω x v) := by + apply measurable_ncard.comp + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + apply measurableSet_setOfPred.mp + change MeasurableSet {ω : Set E | ∃ a, Conn G ω x a ∧ ∃ b, Conn G ω v b ∧ G e = s(a,b)} + simp only [Set.ofPred_exists] + apply MeasurableSet.iUnion + intro a + have he : {ω : Set E | Conn G ω x a ∧ ∃ b, Conn G ω v b ∧ G e = s(a,b)} = + {ω | Conn G ω x a} ∩ ⋃ b, {ω | Conn G ω v b ∧ G e = s(a,b)} := by ext ω; simp + rw [he] + apply (measurableSet_conn G x a).inter + apply MeasurableSet.iUnion + intro b + by_cases h : G e = s(a,b) + · simpa only [h,and_true] using measurableSet_conn G v b + · simp only [h,and_false,Set.ofPred_false]; exact MeasurableSet.empty + +theorem measurable_fullContactBin [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x v : V) (n m : ℕ) : + Measurable (fullContactBin G x v n m) := by + have hs : Measurable (fun ω : Set E => min (cluster G ω x).ncard (cluster G ω v).ncard) := + (measurable_cluster_ncard G hloc x).min (measurable_cluster_ncard G hloc v) + exact ((measurable_of_countable (fun k : ℕ => (k:ℝ))).comp (measurable_clusterContactCount G x v)).ite + (((measurableSet_conn G x v).compl).inter ((measurableSet_le measurable_const hs).inter + (measurableSet_le hs measurable_const))) measurable_const + +theorem coe_domainBits (Q : Finset E) (ω : Set E) : + (domainBits Q ω:Set E) = ω ∩ (Q:Set E) := by ext e; simp only [mem_domainBits,Set.mem_inter_iff,Finset.mem_coe,and_comm] + +theorem domainBits_local (Q : Finset E) (ω : Set E) : + domainBits Q (ω ∩ (Q:Set E)) = domainBits Q ω := by + ext e + simp only [mem_domainBits,Set.mem_inter_iff,Finset.mem_coe] + tauto + +theorem domainBits_of_subset (Q ω : Finset E) (hω : ω ⊆ Q) : domainBits Q (ω:Set E) = ω := by + ext e + simp only [mem_domainBits,Finset.mem_coe] + exact ⟨fun h => h.2,fun h => ⟨hω h,h⟩⟩ + +theorem integral_domainBits (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) : + (∫ ω, f (domainBits Q ω) ∂law p) = bernoulliPolynomial Q f p := by + rw [integral_eq_bernoulliPolynomial Q p _ (fun ω => by rw [domainBits_local])] + apply bernoulliPolynomial_congr + intro ω hω + rw [domainBits_of_subset Q ω hω] + +end ContactMeasurability +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section InfiniteContactLimit +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem fullContactBin_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x v : V) (hx : (cluster G ω x).Finite) (hv : (cluster G ω v).Finite) + (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) + (hQv : incidentSupport G hloc hv.toFinset ⊆ Q) (n m : ℕ) : + clusterContactBin G Q x v n m (domainBits Q ω) = fullContactBin G x v n m ω := by + have hcluster (y : V) (hy : (cluster G ω y).Finite) (hQ : incidentSupport G hloc hy.toFinset ⊆ Q) : + cluster G (domainBits Q ω:Set E) y = cluster G ω y := by + rw [coe_domainBits] + have hh := (cluster_restrict_incident_eq_iff G hloc hy.toFinset Q hQ ω y).mpr + (Set.Finite.coe_toFinset hy).symm + simpa only [Set.Finite.coe_toFinset] using hh + have hcx := hcluster x hx hQx + have hcv := hcluster v hv hQv + have hFx : finiteRootComponent G (domainBits Q ω) x = hx.toFinset := by + apply Finset.coe_injective + rw [coe_finiteRootComponent,hcx,Set.Finite.coe_toFinset] + have hFv : finiteRootComponent G (domainBits Q ω) v = hv.toFinset := by + apply Finset.coe_injective + rw [coe_finiteRootComponent,hcv,Set.Finite.coe_toFinset] + have hconn : Conn G (domainBits Q ω:Set E) x v ↔ Conn G ω x v := by + change v ∈ cluster G (domainBits Q ω:Set E) x ↔ v ∈ cluster G ω x + rw [hcx] + have hc : (contactBonds G Q hx.toFinset hv.toFinset).card = clusterContactCount G ω x v := by + rw [←Set.ncard_coe_finset,coe_contactBonds_eq G hloc Q _ _ hQx] + simp only [Set.Finite.coe_toFinset,clusterContactCount] + simp only [clusterContactBin,fullContactBin,hconn,hFx,hFv,←Set.ncard_eq_toFinset_card,hc] + +theorem clusterContactBin_norm_le (G : BondGraph V E) (Q : Finset E) + (d : ℕ) (hd : ∀ z, (Q.filter fun e => z ∈ G e).card ≤ d) + (x v : V) (n m : ℕ) (ω : Finset E) : ‖clusterContactBin G Q x v n m ω‖ ≤ (d*m:ℕ) := by + unfold clusterContactBin + split_ifs with h + · rw [Real.norm_natCast] + exact_mod_cast (contactBonds_card_le G Q d hd _ _).trans (Nat.mul_le_mul_left d h.2.2) + · simp only [norm_zero]; positivity + +theorem fullContactBin_integral_le_of_finite [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) + (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (p : unitInterval) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hv : ∀ᵐ ω ∂law p, (cluster G ω v).Finite) (n m : ℕ) (B : ℝ) + (hB : ∀ Q : Finset E, bernoulliPolynomial Q (clusterContactBin G Q x v n m) p ≤ B) : + (∫ ω, fullContactBin G x v n m ω ∂law p) ≤ B := by + let : Encodable E := Encodable.ofCountable E + let Q := vertexExhaustion (V := E) + let f := fun j ω => clusterContactBin G (Q j) x v n m (domainBits (Q j) ω) + have hfl (j : ℕ) (ω : Set E) : f j ω = f j (ω ∩ (Q j:Set E)) := by + dsimp [f]; rw [domainBits_local] + have hfi (j : ℕ) : Integrable (f j) (law p) := integrable_finite_local (Q j) p (f j) (hfl j) + have hdeg (j : ℕ) (z : V) : ((Q j).filter fun e => z ∈ G e).card ≤ d := by + calc + _ = (((Q j).filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm + _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) + _ ≤ d := hd z + have ht : ∀ᵐ ω ∂law p, Tendsto (fun j => f j ω) atTop (nhds (fullContactBin G x v n m ω)) := by + filter_upwards [hx,hv] with ω hωx hωv + obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hωx.toFinset) + obtain ⟨jv,hjv⟩ := subset_vertexExhaustion (incidentSupport G hloc hωv.toFinset) + have he : (fun j => f j ω) =ᶠ[atTop] (fun _ => fullContactBin G x v n m ω) := by + filter_upwards [eventually_ge_atTop (max jx jv)] with j hj + exact fullContactBin_eq_finite G hloc ω x v hωx hωv (Q j) + (hjx.trans (vertexExhaustion_mono (le_max_left jx jv |>.trans hj))) + (hjv.trans (vertexExhaustion_mono (le_max_right jx jv |>.trans hj))) n m + exact tendsto_const_nhds.congr' he.symm + have hdom := tendsto_integral_of_dominated_convergence (fun _ : Set E => (d*m:ℕ)) + (fun j => (hfi j).aestronglyMeasurable) (integrable_const _) + (fun j => Eventually.of_forall (fun ω => clusterContactBin_norm_le G (Q j) d (hdeg j) x v n m _)) ht + apply le_of_tendsto hdom + exact Eventually.of_forall (fun j => by rw [show (∫ ω, f j ω ∂law p) = + bernoulliPolynomial (Q j) (clusterContactBin G (Q j) x v n m) p from by dsimp [f]; exact integral_domainBits (Q j) p (clusterContactBin G (Q j) x v n m)]; exact hB (Q j)) + +end InfiniteContactLimit +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FullContactPower +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem fullContactBin_power_bound [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) + (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) + (d : ℕ) (hd : 0 < d) (hdeg : ∀ z, {e | z ∈ G e}.ncard ≤ d) : + ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → + ∀ n : ℕ, 1 ≤ n → (∫ ω, fullContactBin G x v n (2*n) ω ∂law p) ≤ + A*(n:ℝ)^((1:ℝ)/2+ε-2*α) := by + obtain ⟨A,hA,hAb⟩ := clusterContactBin_power_bound G hloc q α ε C p₀ hα hα1 hε hr hC0 hp₀ hfin hI hC d hd + refine ⟨A,hA,?_⟩ + intro x v p hpp hpq n hn + apply fullContactBin_integral_le_of_finite G hloc d hdeg x v p + (cluster_finite_ae_mono G x p q hpq (hfin x)) (cluster_finite_ae_mono G v p q hpq (hfin v)) + intro Q + apply hAb Q _ x v p hpp hpq n hn + intro z + calc + _ = ((Q.filter fun e => z ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm + _ ≤ {e | z ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc z) + _ ≤ d := hdeg z + +theorem integrable_fullContactBin [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) + (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (n m : ℕ) (hn : 0 < n) (p : unitInterval) : + Integrable (fullContactBin G x v n m) (law p) := by + apply Integrable.mono' (integrable_const ((d*m:ℕ):ℝ)) (measurable_fullContactBin G hloc x v n m).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun ω => by + rw [Real.norm_eq_abs,abs_of_nonneg (fullContactBin_nonneg G x v n m ω)] + exact fullContactBin_le G hloc d hd x v n m hn ω) + +end FullContactPower +end Percolation + + +namespace Percolation +open MeasureTheory +section NonnegativeDyadicIntegration + + + +theorem integral_le_tsum_majorants {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (f : Ω → ℝ) (F : ℕ → Ω → ℝ) (hfm : AEStronglyMeasurable f μ) + (hf0 : ∀ ω, 0 ≤ f ω) (hF0 : ∀ j ω, 0 ≤ F j ω) (hFi : ∀ j, Integrable (F j) μ) + (hs : Summable (fun j => ∫ ω, F j ω ∂μ)) + (hb : ∀ ω, ENNReal.ofReal (f ω) ≤ ∑' j, ENNReal.ofReal (F j ω)) : + Integrable f μ ∧ (∫ ω, f ω ∂μ) ≤ ∑' j, ∫ ω, F j ω ∂μ := by + have he : (∫⁻ ω, ∑' j, ENNReal.ofReal (F j ω) ∂μ) = + ENNReal.ofReal (∑' j, ∫ ω, F j ω ∂μ) := by + rw [lintegral_tsum (fun j => (hFi j).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] + simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hF0 _))] + exact (ENNReal.ofReal_tsum_of_nonneg (fun j => integral_nonneg (hF0 j)) hs).symm + have hle := (lintegral_mono hb).trans_eq he + have hi : Integrable f μ := ⟨hfm,(hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hf0)).mpr + (hle.trans_lt ENNReal.ofReal_lt_top)⟩ + refine ⟨hi,?_⟩ + rw [←ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall hf0)] at hle + exact (ENNReal.ofReal_le_ofReal_iff (tsum_nonneg (fun j => integral_nonneg (hF0 j)))).mp hle + +theorem dyadic_rpow_identity (L : ℕ) (hL : 0 < L) (r : ℝ) (j : ℕ) : + ((2^j*L:ℕ):ℝ)^r = (L:ℝ)^r*((2:ℝ)^r)^j := by + rw [Nat.cast_mul,Nat.cast_pow,Nat.cast_ofNat,Real.mul_rpow (by positivity) (by positivity), + ←Real.rpow_natCast,←Real.rpow_mul (by norm_num),mul_comm (j:ℝ) r,Real.rpow_mul (by norm_num),Real.rpow_natCast,mul_comm] + +theorem dyadic_rpow_summable (L : ℕ) (hL : 0 < L) (r : ℝ) (hr : r < 0) : + Summable (fun j : ℕ => ((2^j*L:ℕ):ℝ)^r) := by + simp only [dyadic_rpow_identity L hL r] + exact (summable_geometric_of_lt_one (Real.rpow_nonneg (by norm_num) _) + (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr)).mul_left _ + +theorem dyadic_rpow_sum (L : ℕ) (hL : 0 < L) (r : ℝ) (hr : r < 0) : + (∑' j : ℕ, ((2^j*L:ℕ):ℝ)^r) = (L:ℝ)^r*(1-(2:ℝ)^r)⁻¹ := by + simp only [dyadic_rpow_identity L hL r,tsum_mul_left] + rw [tsum_geometric_of_lt_one (Real.rpow_nonneg (by norm_num) _) (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr)] + +end NonnegativeDyadicIntegration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FullLargeContacts +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def fullLargeContact (G : BondGraph V E) (x v : V) (L : ℕ) (ω : Set E) : ℝ := + if ¬Conn G ω x v ∧ L ≤ min (cluster G ω x).ncard (cluster G ω v).ncard + then clusterContactCount G ω x v else 0 + +theorem fullLargeContact_nonneg (G : BondGraph V E) (x v : V) (L : ℕ) (ω : Set E) : + 0 ≤ fullLargeContact G x v L ω := by unfold fullLargeContact; split_ifs <;> positivity + +theorem measurable_fullLargeContact [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x v : V) (L : ℕ) : + Measurable (fullLargeContact G x v L) := by + have hs : Measurable (fun ω : Set E => min (cluster G ω x).ncard (cluster G ω v).ncard) := + (measurable_cluster_ncard G hloc x).min (measurable_cluster_ncard G hloc v) + exact ((measurable_of_countable (fun k : ℕ => (k:ℝ))).comp (measurable_clusterContactCount G x v)).ite + (((measurableSet_conn G x v).compl).inter (measurableSet_le measurable_const hs)) measurable_const + +theorem fullLargeContact_le_dyadic (G : BondGraph V E) (x v : V) (L : ℕ) (hL : 0 < L) (ω : Set E) : + ENNReal.ofReal (fullLargeContact G x v L ω) ≤ + ∑' j : ℕ, ENNReal.ofReal (fullContactBin G x v (2^j*L) (2*(2^j*L)) ω) := by + by_cases h : ¬Conn G ω x v ∧ L ≤ min (cluster G ω x).ncard (cluster G ω v).ncard + · let k := min (cluster G ω x).ncard (cluster G ω v).ncard + let j := Nat.log 2 (k/L) + have hq : k/L ≠ 0 := by + have : 1 ≤ k/L := (Nat.le_div_iff_mul_le hL).mpr (by rw [one_mul]; exact h.2) + omega + have hl := (Nat.le_div_iff_mul_le hL).mp (Nat.pow_log_le_self 2 hq) + have hu := (Nat.div_lt_iff_lt_mul hL).mp (Nat.lt_pow_succ_log_self (by norm_num : 1 < (2:ℕ)) (k/L)) + have hbin : fullContactBin G x v (2^j*L) (2*(2^j*L)) ω = fullLargeContact G x v L ω := by + rw [fullLargeContact,ite_eq_left h,fullContactBin,ite_eq_left] + refine ⟨h.1,hl,?_⟩ + calc + _ = k := rfl + _ ≤ 2^(Nat.log 2 (k/L)+1)*L := hu.le + _ = _ := by dsimp [j]; rw [pow_succ]; ring + exact (le_of_eq (congrArg ENNReal.ofReal hbin.symm)).trans + (ENNReal.le_tsum (f := fun scale => + ENNReal.ofReal (fullContactBin G x v (2^scale*L) (2*(2^scale*L)) ω)) j) + · simp only [fullLargeContact,ite_eq_right h,ENNReal.ofReal_zero]; exact bot_le + + + +theorem fullLargeContact_bound_of_bins [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) + (hd : ∀ z, {e | z ∈ G e}.ncard ≤ d) (x v : V) (p : unitInterval) + (A r : ℝ) (_hA : 0 ≤ A) (hr : r < 0) + (hB : ∀ n : ℕ, 1 ≤ n → (∫ ω, fullContactBin G x v n (2*n) ω ∂law p) ≤ A*(n:ℝ)^r) + (L : ℕ) (hL : 0 < L) : + Integrable (fullLargeContact G x v L) (law p) ∧ + (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(1-(2:ℝ)^r)⁻¹*(L:ℝ)^r := by + let F := fun j => fullContactBin G x v (2^j*L) (2*(2^j*L)) + have hbp (j : ℕ) : 0 < 2^j*L := Nat.mul_pos (pow_pos (by norm_num) _) hL + have hFi (j : ℕ) : Integrable (F j) (law p) := integrable_fullContactBin G hloc d hd x v _ _ (hbp j) p + have hsumB := (dyadic_rpow_summable L hL r hr).mul_left A + have hsum : Summable (fun j => ∫ ω, F j ω ∂law p) := + hsumB.of_nonneg_of_le (fun j => integral_nonneg (fullContactBin_nonneg G x v _ _)) + (fun j => hB _ (hbp j)) + obtain ⟨hi,hb⟩ := integral_le_tsum_majorants (law p) (fullLargeContact G x v L) F + (measurable_fullLargeContact G hloc x v L).aestronglyMeasurable + (fullLargeContact_nonneg G x v L) (fun j => fullContactBin_nonneg G x v _ _) hFi hsum + (fullLargeContact_le_dyadic G x v L hL) + refine ⟨hi,hb.trans ?_⟩ + calc + _ ≤ ∑' j : ℕ, A*((2^j*L:ℕ):ℝ)^r := hsum.tsum_le_tsum (fun j => hB _ (hbp j)) hsumB + _ = _ := by rw [tsum_mul_left,dyadic_rpow_sum L hL r hr]; ring + +end FullLargeContacts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformLargeContacts +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem incident_ncard_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + {e | x ∈ G e}.ncard ≤ degree G x := by + have he : ((hloc x).toFinset.filter fun e => x ∈ G e) = (hloc x).toFinset := by + ext e + simp only [Finset.mem_filter,Set.Finite.mem_toFinset,Set.mem_ofPred_eq,and_self] + simpa only [he,←Set.ncard_eq_toFinset_card] using incident_filter_card_le_degree G hloc (hloc x).toFinset x + +theorem fullLargeContact_power_bound [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (q : unitInterval) + (α ε C p₀ : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) (hC0 : 0 < C) (hp₀ : 0 < p₀) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : + ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), p₀ ≤ (p:ℝ) → p ≤ q → + ∀ L : ℕ, 1 ≤ L → Integrable (fullLargeContact G x v L) (law p) ∧ + (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(L:ℝ)^((1:ℝ)/2+ε-2*α) := by + obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt + have hdn (x : V) := (incident_ncard_le_degree G hloc x).trans (hdeg x) + obtain ⟨A,hA,hAb⟩ := fullContactBin_power_bound G hloc q α ε C p₀ hα hα1 hε hr hC0 hp₀ hfin hI hC d hd hdn + refine ⟨A*(1-(2:ℝ)^((1:ℝ)/2+ε-2*α))⁻¹,?_ ,?_⟩ + · exact mul_pos hA (inv_pos.mpr (sub_pos.mpr (Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) hr))) + · intro x v p hpp hpq L hL + exact fullLargeContact_bound_of_bins G hloc d hdn x v p A _ hA.le hr (hAb x v p hpp hpq) L hL + + + +theorem critical_large_contact_bound + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ A : ℝ, 0 < A ∧ ∀ (x v : V) (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → + ∀ L : ℕ, 1 ≤ L → Integrable (fullLargeContact G x v L) (law p) ∧ + (∫ ω, fullLargeContact G x v L ω ∂law p) ≤ A*(L:ℝ)^((1:ℝ)/2+ε-2*α) := by + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by + intro x + obtain ⟨i,a,b,hab,rfl⟩ := hcover x + exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) + obtain ⟨C,hC,hb⟩ := uniform_cluster_power_of_root G hloc (pc G) root hcover α + (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) + exact fullLargeContact_power_bound G hloc hqt (pc G) α ε C ((pc G:ℝ)/2) hα.le (by linarith) + hε hr hC (by positivity) hfinite (fun x => (hb x).1) (fun x => (hb x).2) + +end UniformLargeContacts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ExtendedTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem enn_sum_iSup_nat {α : Type*} (s : Finset α) (f : ℕ → α → ℝ≥0∞) + (hm : ∀ a, Monotone (fun n => f n a)) : + (∑ a ∈ s, ⨆ n, f n a) = ⨆ n, ∑ a ∈ s, f n a := by + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + simp only [Finset.sum_insert ha,ih] + exact ENNReal.iSup_add_iSup_of_monotone (hm a) (fun n m h => + Finset.sum_le_sum fun a _ => hm a h) + +theorem enn_tsum_iSup_nat {α : Type*} (f : ℕ → α → ℝ≥0∞) + (hm : ∀ a, Monotone (fun n => f n a)) : + (∑' a, ⨆ n, f n a) = ⨆ n, ∑' a, f n a := by + simp_rw [ENNReal.tsum_eq_iSup_sum,enn_sum_iSup_nat _ f hm] + exact iSup_comm + + + +theorem RootTransport.ennreal (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (m : V → V → ℝ≥0∞) + (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) : + (∑ i, ENNReal.ofReal (weight i) * ∑' y, m (root i) y) = + (∑ i, ENNReal.ofReal (weight i) * ∑' x, m x (root i)) := by + let cut (n : ℕ) (x y : V) : ℝ≥0∞ := + if transportCut G n x y then min (m x y) n else 0 + have hc0 (n : ℕ) (x y : V) : cut n x y ≠ ⊤ := by + dsimp [cut] + split_ifs + · exact ne_top_of_le_ne_top (ENNReal.natCast_ne_top n) (min_le_right _ _) + · exact ENNReal.zero_ne_top + have hcm (x y : V) : Monotone (fun n => cut n x y) := by + intro n k hnk + dsimp [cut] + split_ifs with hn hk + · exact min_le_min_left _ (by exact_mod_cast hnk) + · exact False.elim (hk (transportCut_mono G hnk hn)) + · exact zero_le + · exact le_refl _ + have hcs (x y : V) : (⨆ n, cut n x y) = m x y := by + apply le_antisymm + · refine iSup_le fun n => ?_ + dsimp [cut] + split_ifs + · exact min_le_left _ _ + · exact zero_le + · obtain ⟨N,hN⟩ := exists_transportCut G hconn y {x} + have hxy := hN x (Finset.mem_singleton_self x) + have he : (⨆ k : ℕ, min (m x y) (k:ℝ≥0∞)) = m x y := by + rw [←inf_iSup_eq,ENNReal.iSup_natCast,inf_top_eq] + rw [←he] + refine iSup_le fun k => le_iSup_of_le (max N k) ?_ + dsimp [cut] + rw [ite_eq_left (transportCut_mono G (le_max_left N k) hxy)] + exact min_le_min_left _ (by exact_mod_cast le_max_right N k) + have hrow (n : ℕ) (x : V) : Summable (fun y => (cut n x y).toReal) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x n).toFinset) + intro y hy + have hh : ¬transportCut G n x y := fun h => hy ((Set.Finite.mem_toFinset _).mpr h.1) + simp only [cut,ite_eq_right hh,ENNReal.toReal_zero] + have hcol (n : ℕ) (y : V) : Summable (fun x => (cut n x y).toReal) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) + intro x hx + have hh : ¬transportCut G n x y := fun h => hx ((Set.Finite.mem_toFinset _).mpr h.2) + simp only [cut,ite_eq_right hh,ENNReal.toReal_zero] + have he (n : ℕ) : + (∑ i, ENNReal.ofReal (weight i) * ∑' y, cut n (root i) y) = + (∑ i, ENNReal.ofReal (weight i) * ∑' x, cut n x (root i)) := by + have ht := htr.real root weight Γ (fun x y => (cut n x y).toReal) + (fun a ha x y => by + obtain ⟨b,hb⟩ := hΓ ha + simp only [cut,transportCut_aut G hb,hi a ha]) (hrow n) (hcol n) + apply_fun ENNReal.ofReal at ht + rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) + (tsum_nonneg fun _ => ENNReal.toReal_nonneg)), + ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) + (tsum_nonneg fun _ => ENNReal.toReal_nonneg))] at ht + simp_rw [ENNReal.ofReal_mul (hw _), + ENNReal.ofReal_tsum_of_nonneg (fun _ => ENNReal.toReal_nonneg) (hrow n _), + ENNReal.ofReal_tsum_of_nonneg (fun _ => ENNReal.toReal_nonneg) (hcol n _), + ENNReal.ofReal_toReal (hc0 n _ _)] at ht + exact ht + have hlim (f : ι → V → ℝ≥0∞) (g : ℕ → ι → V → ℝ≥0∞) + (hmono : ∀ i y, Monotone (fun n => g n i y)) (hs : ∀ i y, (⨆ n, g n i y) = f i y) : + (∑ i, ENNReal.ofReal (weight i) * ∑' y, f i y) = + ⨆ n, ∑ i, ENNReal.ofReal (weight i) * ∑' y, g n i y := by + simp_rw [←hs,enn_tsum_iSup_nat _ (hmono _),ENNReal.mul_iSup] + exact enn_sum_iSup_nat _ _ (fun i n k h => mul_le_mul_right (ENNReal.tsum_le_tsum + (fun y => hmono i y h)) _) + rw [hlim (fun i y => m (root i) y) (fun n i y => cut n (root i) y) + (fun i y => hcm (root i) y) (fun i y => hcs (root i) y), + hlim (fun i x => m x (root i)) (fun n i x => cut n x (root i)) + (fun i x => hcm x (root i)) (fun i x => hcs x (root i))] + exact iSup_congr he + +end ExtendedTransport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ClusterAveraging +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def clusterAveragingKernel (G : BondGraph V E) (ω : Set E) (x y : V) : ℝ≥0∞ := + if Conn G ω x y then ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ else 0 + +theorem measurable_clusterAveragingKernel [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : + Measurable (fun ω => clusterAveragingKernel G ω x y) := by + exact (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp + (measurable_cluster_ncard G hloc x)).inv).ite (measurableSet_conn G x y) measurable_const + +theorem clusterAveragingKernel_symm (G : BondGraph V E) (ω : Set E) (x y : V) : + clusterAveragingKernel G ω x y = clusterAveragingKernel G ω y x := by + by_cases h : Conn G ω x y + · simp only [clusterAveragingKernel,ite_eq_left h,ite_eq_left (conn_symm G ω h),cluster_eq_of_conn G ω h] + · have h' : ¬Conn G ω y x := fun hh => h (conn_symm G ω hh) + simp only [clusterAveragingKernel,ite_eq_right h,ite_eq_right h'] + +theorem cluster_ncard_pos (G : BondGraph V E) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : 0 < (cluster G ω x).ncard := + (Set.ncard_pos hf).mpr ⟨x,mem_cluster_self G ω x⟩ + +theorem clusterAveragingKernel_row (G : BondGraph V E) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : (∑' y, clusterAveragingKernel G ω x y) = 1 := by + have he : (fun y => clusterAveragingKernel G ω x y) = + (fun y => (if Conn G ω x y then (1:ℝ≥0∞) else 0)*((cluster G ω x).ncard:ℝ≥0∞)⁻¹) := by + funext y + unfold clusterAveragingKernel + split_ifs <;> simp + rw [he,ENNReal.tsum_mul_right] + change clusterMass G ω x * ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ = 1 + rw [clusterMass_eq_ncard G ω x hf] + exact ENNReal.mul_inv_cancel (by exact_mod_cast (cluster_ncard_pos G ω x hf).ne') (ENNReal.natCast_ne_top _) + +theorem clusterAveragingKernel_column (G : BondGraph V E) (ω : Set E) (y : V) + (hf : (cluster G ω y).Finite) : (∑' x, clusterAveragingKernel G ω x y) = 1 := by + simp_rw [clusterAveragingKernel_symm G ω] + exact clusterAveragingKernel_row G ω y hf + +theorem clusterAveragingKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) : + clusterAveragingKernel G (b ⁻¹' ω) x y = clusterAveragingKernel G ω (a x) (a y) := by + simp only [clusterAveragingKernel,conn_aut_iff G hab,cluster_ncard_covariant G hab] + + + +theorem root_cluster_average [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (f : Set E → V → ℝ≥0∞) (hf : ∀ x, Measurable (fun ω => f ω x)) + (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x, f (b ⁻¹' ω) x = f ω (a x)) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, + clusterAveragingKernel G ω (root i) y * f ω y ∂law p) = + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, f ω (root i) ∂law p) := by + let m (x y : V) : ℝ≥0∞ := ∫⁻ ω, clusterAveragingKernel G ω x y * f ω y ∂law p + have hm (x y : V) : Measurable (fun ω => clusterAveragingKernel G ω x y * f ω y) := + (measurable_clusterAveragingKernel G hloc x y).mul (hf y) + have hinv : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y := by + intro a ha x y + obtain ⟨b,hb⟩ := hΓ ha + have ht := lintegral_map (μ := law p) (hm x y) (measurable_set_preimage b) + rw [law_map_preimage_equiv] at ht + dsimp only [m] + rw [ht] + apply lintegral_congr + intro ω + rw [clusterAveragingKernel_aut G hb,hi a ha b hb] + have ht := htr.ennreal G hconn hloc root weight Γ hΓ hw m hinv + have hr (x : V) : (∑' y, m x y) = ∫⁻ ω, ∑' y, clusterAveragingKernel G ω x y*f ω y ∂law p := by + exact (lintegral_tsum (fun y => (hm x y).aemeasurable)).symm + have hc (y : V) : (∑' x, m x y) = ∫⁻ ω, f ω y ∂law p := by + rw [show (∑' x, m x y) = ∫⁻ ω, ∑' x, clusterAveragingKernel G ω x y*f ω y ∂law p from + (lintegral_tsum (fun x => (hm x y).aemeasurable)).symm] + apply lintegral_congr_ae + filter_upwards [hfin y] with ω hω + rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G ω y hω,one_mul] + simpa only [hr,hc] using ht + +end ClusterAveraging +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PositiveClusterPairs +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def clusterPairKernel (G : BondGraph V E) (ω : Set E) + (J : V → V → ℝ≥0∞) (x y : V) : ℝ≥0∞ := + ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b then J a b else 0 + + + +noncomputable def clusterPairDensity (G : BondGraph V E) (ω : Set E) + (F : V → V → ℝ≥0∞) (x : V) : ℝ≥0∞ := + ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * + ∑' y, ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * (if ¬Conn G ω x y then F x y else 0) + +noncomputable def clusterPairFunctional (G : BondGraph V E) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (F : Set E → V → V → ℝ≥0∞) : ℝ≥0∞ := + ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, clusterPairDensity G ω (F ω) (root i) ∂law p + +theorem cluster_weighted_resum (G : BondGraph V E) (ω : Set E) + (hfin : ∀ x, (cluster G ω x).Finite) (f : V → V → ℝ≥0∞) + (hc : ∀ x y, Conn G ω x y → f x y = f y y) : + (∑' x, ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * + ∑' y, if Conn G ω x y then f x y else 0) = ∑' y, f y y := by + have he (x y : V) : ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * + (if Conn G ω x y then f x y else 0) = clusterAveragingKernel G ω x y*f y y := by + by_cases h : Conn G ω x y + · simp only [ite_eq_left h,clusterAveragingKernel,hc x y h] + · simp only [ite_eq_right h,clusterAveragingKernel,mul_zero,zero_mul] + simp_rw [←ENNReal.tsum_mul_left,he] + rw [ENNReal.tsum_comm] + apply tsum_congr + intro y + rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G ω y (hfin y),one_mul] + +theorem clusterPairDensity_reroot_pointwise (G : BondGraph V E) (ω : Set E) + (hfin : ∀ x, (cluster G ω x).Finite) (J F : V → V → ℝ≥0∞) + (hF : ∀ x y a b, Conn G ω x a → Conn G ω y b → F x y = F a b) (x : V) : + clusterPairDensity G ω (fun a b => clusterPairKernel G ω J a b * F a b) x = + ∑' a, clusterAveragingKernel G ω x a * + ∑' b, J a b * (if ¬Conn G ω a b then F a b else 0) := by + let K (a b : V) : ℝ≥0∞ := if ¬Conn G ω a b then F a b else 0 + have hK (a b c d : V) (hac : Conn G ω a c) (hbd : Conn G ω b d) : K a b = K c d := by + have he : Conn G ω a b ↔ Conn G ω c d := by + constructor + · intro h; exact conn_trans G ω (conn_symm G ω hac) (conn_trans G ω h hbd) + · intro h; exact conn_trans G ω hac (conn_trans G ω h (conn_symm G ω hbd)) + simp only [K,he,hF a b c d hac hbd] + have hterm (y : V) : ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * + (if ¬Conn G ω x y then clusterPairKernel G ω J x y*F x y else 0) = + ∑' a, if Conn G ω x a then ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * + ∑' b, if Conn G ω y b then J a b*K x y else 0 else 0 := by + have hcond : (if ¬Conn G ω x y then clusterPairKernel G ω J x y*F x y else 0) = + clusterPairKernel G ω J x y*K x y := by dsimp [K]; split_ifs <;> simp + rw [hcond,clusterPairKernel,←ENNReal.tsum_mul_right,←ENNReal.tsum_mul_left] + apply tsum_congr + intro a + by_cases hxa : Conn G ω x a + · rw [ite_eq_left hxa,←ENNReal.tsum_mul_right] + congr 1 + apply tsum_congr + intro b + by_cases hyb : Conn G ω y b <;> simp only [hxa,hyb,and_self,and_false, + ite_true,ite_false,zero_mul] + · simp only [hxa,false_and,ite_false,tsum_zero,zero_mul,mul_zero] + unfold clusterPairDensity + simp_rw [hterm] + rw [ENNReal.tsum_comm,←ENNReal.tsum_mul_left] + apply tsum_congr + intro a + by_cases hxa : Conn G ω x a + · simp only [ite_eq_left hxa,clusterAveragingKernel] + congr 1 + rw [cluster_weighted_resum G ω hfin (fun y b => J a b*K x y) + (fun y b hyb => congrArg (fun t => J a b*t) (hK x y x b (conn_refl G ω x) hyb))] + apply tsum_congr + intro b + rw [hK x b a b hxa (conn_refl G ω b)] + · simp only [ite_eq_right hxa,tsum_zero,mul_zero,clusterAveragingKernel,zero_mul] + +end PositiveClusterPairs +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ClusterPairRerooting +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem clusterPairFunctional_reroot [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) + (F : Set E → V → V → ℝ≥0∞) (hm : ∀ x y, Measurable (fun ω => F ω x y)) + (hF : ∀ ω x y a b, Conn G ω x a → Conn G ω y b → F ω x y = F ω a b) + (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x y, F (b ⁻¹' ω) x y = F ω (a x) (a y)) : + clusterPairFunctional G p root weight (fun ω x y => clusterPairKernel G ω J x y * F ω x y) = + ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, + J (root i) y * (if ¬Conn G ω (root i) y then F ω (root i) y else 0) ∂law p := by + let f (ω : Set E) (x : V) : ℝ≥0∞ := + ∑' y, J x y * (if ¬Conn G ω x y then F ω x y else 0) + have hf (x : V) : Measurable (fun ω => f ω x) := by + apply Measurable.tsum + intro y + exact measurable_const.mul ((hm x y).ite (measurableSet_conn G x y).compl measurable_const) + have hfe : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x, f (b ⁻¹' ω) x = f ω (a x) := by + intro a ha b hab ω x + dsimp [f] + rw [←a.tsum_eq (fun y => J (a x) y * (if ¬Conn G ω (a x) y then F ω (a x) y else 0))] + apply tsum_congr + intro y + rw [hJ a ha,conn_aut_iff G hab,hi a ha b hab] + have ht := root_cluster_average G hconn hloc root weight Γ hΓ htr hw p hfin f hf hfe + rw [clusterPairFunctional] + calc + _ = ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, + clusterAveragingKernel G ω (root i) y*f ω y ∂law p := by + apply Finset.sum_congr rfl + intro i _ + congr 1 + apply lintegral_congr_ae + filter_upwards [ae_all_iff.mpr hfin] with ω hω + exact clusterPairDensity_reroot_pointwise G ω hω J (F ω) (hF ω) (root i) + _ = _ := ht + +end ClusterPairRerooting +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PairReversal +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def clusterPairMass (G : BondGraph V E) (ω : Set E) + (F : V → V → ℝ≥0∞) (x y : V) : ℝ≥0∞ := + ((cluster G ω x).ncard:ℝ≥0∞)⁻¹ * ((cluster G ω y).ncard:ℝ≥0∞)⁻¹ * + (if ¬Conn G ω x y then F x y else 0) + +theorem clusterPairDensity_eq_tsum (G : BondGraph V E) (ω : Set E) + (F : V → V → ℝ≥0∞) (x : V) : + clusterPairDensity G ω F x = ∑' y, clusterPairMass G ω F x y := by + simp only [clusterPairDensity,clusterPairMass,←ENNReal.tsum_mul_left,mul_assoc] + +theorem clusterPairMass_swap (G : BondGraph V E) (ω : Set E) + (F : V → V → ℝ≥0∞) (x y : V) : + clusterPairMass G ω F x y = clusterPairMass G ω (fun a b => F b a) y x := by + have he : Conn G ω x y ↔ Conn G ω y x := ⟨conn_symm G ω,conn_symm G ω⟩ + simp only [clusterPairMass,he,mul_comm] + +theorem measurable_clusterPairMass [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (F : Set E → V → V → ℝ≥0∞) (hf : ∀ x y, Measurable (fun ω => F ω x y)) (x y : V) : + Measurable (fun ω => clusterPairMass G ω (F ω) x y) := by + have hs (x : V) : Measurable (fun ω => ((cluster G ω x).ncard:ℝ≥0∞)⁻¹) := + (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_cluster_ncard G hloc x))).inv + exact ((hs x).mul (hs y)).mul ((hf x y).ite (measurableSet_conn G x y).compl measurable_const) + +theorem clusterPairFunctional_swap [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (F : Set E → V → V → ℝ≥0∞) (hf : ∀ x y, Measurable (fun ω => F ω x y)) + (hi : ∀ a ∈ Γ, ∀ b, IsAut G a b → ∀ ω x y, F (b ⁻¹' ω) x y = F ω (a x) (a y)) : + clusterPairFunctional G p root weight F = + clusterPairFunctional G p root weight (fun ω x y => F ω y x) := by + let m (x y : V) : ℝ≥0∞ := ∫⁻ ω, clusterPairMass G ω (F ω) x y ∂law p + have hm := measurable_clusterPairMass G hloc F hf + have hinv : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y := by + intro a ha x y + obtain ⟨b,hb⟩ := hΓ ha + have ht := lintegral_map (μ := law p) (hm x y) (measurable_set_preimage b) + rw [law_map_preimage_equiv] at ht + dsimp only [m] + rw [ht] + apply lintegral_congr + intro ω + simp only [clusterPairMass,cluster_ncard_covariant G hb,conn_aut_iff G hb,hi a ha b hb] + have ht := htr.ennreal G hconn hloc root weight Γ hΓ hw m hinv + have hr (x : V) : (∑' y, m x y) = ∫⁻ ω, clusterPairDensity G ω (F ω) x ∂law p := by + simp_rw [clusterPairDensity_eq_tsum] + exact (lintegral_tsum (fun y => (hm x y).aemeasurable)).symm + have hc (y : V) : (∑' x, m x y) = + ∫⁻ ω, clusterPairDensity G ω (fun a b => F ω b a) y ∂law p := by + simp_rw [clusterPairDensity_eq_tsum,←clusterPairMass_swap G _ (F _)] + exact (lintegral_tsum (fun x => (hm x y).aemeasurable)).symm + simpa only [hr,hc,clusterPairFunctional] using ht + +end PairReversal +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Clusters/Resampling.lean b/lean/OAI/Probability/UnimodularPercolation/Clusters/Resampling.lean index cb4e21f0e335a69195c85b3900fe22f9bd88cb96..22ededeb09b11a79bb7c7e7d6e138bb668aa0bd9 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Clusters/Resampling.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Clusters/Resampling.lean @@ -1,1227 +1,1227 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.ScaleBudget - -namespace OAI - -/-! Resampling for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section ContractingIteration - - - -theorem exists_efficient_of_contracting_successor {S : Type*} - (g H : S → ℝ) (C : ℝ) (hC : 0 ≤ C) (hC1 : C < 1) - (hstep : ∀ x, ∃ y, g y ≤ C*g x ∧ 2*H x ≤ H y) - (x₀ : S) (hH₀ : 0 < H x₀) (η R : ℝ) (hη : 0 < η) : - ∃ x, g x < η ∧ R < H x := by - classical - choose f hf using hstep - let x : ℕ → S := fun n => f^[n] x₀ - have hx (n : ℕ) : x (n+1) = f (x n) := Function.iterate_succ_apply' f n x₀ - have hbounds (n : ℕ) : g (x n) ≤ C^n*g x₀ ∧ (2:ℝ)^n*H x₀ ≤ H (x n) := by - induction n with - | zero => simp only [x,Function.iterate_zero,id_eq,pow_zero,one_mul,le_refl,and_self] - | succ n ih => - rw [hx] - obtain ⟨hg,hH⟩ := hf (x n) - constructor - · calc - _ ≤ C*g (x n) := hg - _ ≤ C*(C^n*g x₀) := mul_le_mul_of_nonneg_left ih.1 hC - _ = _ := by rw [pow_succ]; ring - · calc - _ = 2*((2:ℝ)^n*H x₀) := by rw [pow_succ]; ring - _ ≤ 2*H (x n) := mul_le_mul_of_nonneg_left ih.2 (by norm_num) - _ ≤ _ := hH - have hg : Tendsto (fun n : ℕ => C^n*g x₀) atTop (nhds 0) := by - simpa only [zero_mul] using (tendsto_pow_atTop_nhds_zero_of_lt_one hC hC1).mul_const (g x₀) - have hH : Tendsto (fun n : ℕ => (2:ℝ)^n*H x₀) atTop atTop := - (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1:ℝ) < 2)).atTop_mul_const hH₀ - obtain ⟨n,hg',hH'⟩ := ((tendsto_order.mp hg).2 η hη |>.and - (hH.eventually (eventually_gt_atTop R))).exists - exact ⟨x n,(hbounds n).1.trans_lt hg',hH'.trans_le (hbounds n).2⟩ - -end ContractingIteration - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section EfficientEndpointProfiles -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem efficient_endpoint_profiles_of_divergent_moment - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law p, (cluster G ω (root i)).Finite) - (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) - (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) - (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : - ∃ i, ∀ η : ℝ, 0 < η → ∀ R : ℝ, - ∃ q : EndpointProfile G hloc p (root i) (1/2+ε), - 2 ≤ q.cap ∧ 1 < q.H ∧ R < q.H ∧ q.U+q.m < η*q.H := by - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,e,he,hx⟩ := hcov x - obtain ⟨b,hb⟩ := hΓ he - exact ⟨i,e,b,hb,hx⟩ - obtain ⟨i,hscales⟩ := orbit_scales_of_divergent_moment G hloc root weight Γ hΓ htr hw hw1 hcover p α β hα hαβ hdiv - obtain ⟨ξ,hξ,hξ1,hC,hC1⟩ := exists_amplification_contraction β (1/2+ε) (by linarith) (by linarith) hsmall - have hsξ : 0 < 1/2+ε+ξ := by linarith - obtain ⟨M₀,hM₀⟩ := eventually_atTop.1 (eventually_inverseCodeMass_budget (1/2+ε) ξ (by linarith) hξ) - obtain ⟨q₀,hq₀,hH₀⟩ := starting_endpoint_profile G hloc hqt hh p hp hp1 root weight Γ hΓ htr - (fun i => (hw i).le) hw1 i (hw i) (hfin i) ε hε hε1 M₀ - obtain ⟨d,_,hdeg⟩ := exists_degree_bound G hqt - let c : ℝ := ∑ j, 1/weight j - have hc : 0 ≤ c := Finset.sum_nonneg (fun j _ => (one_div_pos.mpr (hw j)).le) - have hmin (j : ι) : 1 ≤ c*weight j := by - apply (div_le_iff₀ (hw j)).mp - exact Finset.single_le_sum (fun l _ => (one_div_pos.mpr (hw l)).le) (Finset.mem_univ j) - let S := {q : EndpointProfile G hloc p (root i) (1/2+ε) // M₀ ≤ q.cap ∧ 1 < q.H} - let g : S → ℝ := fun q => q.val.cost ξ/q.val.H - let H : S → ℝ := fun q => q.val.H - have hstep : ∀ q : S, ∃ q' : S, g q' ≤ amplificationContraction β (1/2+ε) ξ*g q ∧ 2*H q ≤ H q' := by - intro q - have hcap := hM₀ q.val.cap q.property.1 - have hH : 0 < q.val.H := lt_trans zero_lt_one q.property.2 - obtain ⟨r,k,hr,hk,hU,hm,hH',hH''⟩ := q.val.amplify_at_scales hconn hqt root weight Γ hΓ htr hcov hw hw1 - c hc hmin i p hp1 d hdeg ε ξ β hε hε1 hξ hξ1 hscales hcap.1 hcap.2.1 hcap.2.2 hH M₀ - have hrH : 1 < r.H := by linarith [q.property.2] - refine ⟨⟨r,hr,hrH⟩,?_,hH''⟩ - exact q.val.cost_contraction r β ξ k hcap.1 hsξ hH hξ1 hk hC hU hm hH' - refine ⟨i,?_⟩ - intro η hη R - let D : ℝ := 1+1/(1/2+ε+ξ) - have hD : 0 < D := by dsimp [D]; positivity - obtain ⟨q,hg,hR⟩ := exists_efficient_of_contracting_successor g H (amplificationContraction β (1/2+ε) ξ) - hC hC1 hstep ⟨q₀,hq₀,hH₀⟩ (lt_trans zero_lt_one hH₀) (η/D) R (div_pos hη hD) - have hcap := (hM₀ q.val.cap q.property.1).1 - refine ⟨q.val,hcap,q.property.2,hR,?_⟩ - have hH : 0 < q.val.H := lt_trans zero_lt_one q.property.2 - have hcost := q.val.total_cost_le hcap ξ hsξ - have hratio : (q.val.U+q.val.m)/q.val.H ≤ D*g q := by - have h := div_le_div_of_nonneg_right hcost hH.le - simpa only [D,g,mul_div_assoc] using h - apply (div_lt_iff₀ hH).mp - apply hratio.trans_lt - have hg' := (lt_div_iff₀ hD).mp hg - simpa only [mul_comm] using hg' - -end EfficientEndpointProfiles - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ShortBoundaryPivotal -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def ShortClosedBoundary (G : BondGraph V E) (ω : Set E) (x z : V) (M : ℕ) (e : E) : Prop := - e ∉ ω ∧ ¬Conn G ω x z ∧ ∃ a b : V, ∃ l : List E, - G e = s(a,b) ∧ Along G x l a ∧ (∀ f ∈ l, f ∈ ω) ∧ l.length < M ∧ Conn G ω b z - -theorem bridgeIndex_le_short_trail (G : BondGraph V E) (ω : Set E) (x z : V) - (hC : (cluster G ω x).Finite) (e : E) (he : OpenMarkedPivotal G ω {z} x e) - (a b : V) (hab : G e = s(a,b)) (l : List E) (hl : Along G x l a) - (ho : ∀ f ∈ l, f ∈ ω) : bridgeIndex G ω x z e ≤ l.length+1 := by - unfold bridgeIndex - have hsub : (separatingBonds G ω x z).filter (fun f => pivotalRank G ω x f ≤ pivotalRank G ω x e) ⊆ - (e::l).toFinset := by - intro f hf - obtain ⟨hf,hfe⟩ := Finset.mem_filter.mp hf - have hfp := (mem_separatingBonds G ω x z f).mp hf - by_cases h : f = e - · subst f; simp - by_contra hnot - have hn : f ∉ l := fun hfl => hnot (List.mem_toFinset.mpr (List.mem_cons_of_mem _ hfl)) - have hlt : pivotalRank G ω x f < pivotalRank G ω x e := by - apply lt_of_le_of_ne hfe - intro heq - exact h (pivotalRank_injective_of_cluster_finite G ω {z} x hC hfp he heq) - have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC hfp he).mp hlt - have hb : ¬ Conn G (ω \ {f}) x b := ((mem_internalEdges_of_ends G _ e a b hab).mp hout).2 - apply hb - have hxa : Conn G (ω \ {f}) x a := hl.conn (fun g hg => ⟨ho g hg,fun hgf => hn ((Set.mem_singleton_iff.mp hgf) ▸ hg)⟩) - exact hxa.tail ⟨e,⟨he.1,fun hEq => h hEq.symm⟩,hab⟩ - exact (Finset.card_le_card hsub).trans (by simpa only [List.length_cons] using List.toFinset_card_le (e::l)) - -theorem ShortClosedBoundary.open_pivotal (G : BondGraph V E) (ω : Set E) (x z : V) - (M : ℕ) (e : E) (h : ShortClosedBoundary G ω x z M e) : - OpenMarkedPivotal G (insert e ω) {z} x e := by - obtain ⟨he,hxz,a,b,l,hab,hl,ho,_,hbz⟩ := h - refine ⟨Set.mem_insert e ω,⟨z,rfl,?_⟩,?_⟩ - · have hxa := hl.conn ho - exact (conn_mono G (Set.subset_insert e ω) hxa).trans - ((Relation.ReflTransGen.single ⟨e,Set.mem_insert e ω,hab⟩).trans - (conn_mono G (Set.subset_insert e ω) hbz)) - · rintro ⟨y,hy,hxy⟩ - have hy' : y = z := Set.mem_singleton_iff.mp hy - subst y - apply hxz - apply conn_mono G _ hxy - intro f hf - rcases hf.1 with hfe | hfω - · exact (hf.2 (Set.mem_singleton_iff.mpr hfe)).elim - · exact hfω - -theorem ShortClosedBoundary.bridgeIndex_le (G : BondGraph V E) (ω : Set E) (x z : V) - (hω : ω.Finite) (M : ℕ) (e : E) (h : ShortClosedBoundary G ω x z M e) : - bridgeIndex G (insert e ω) x z e ≤ M := by - have hpiv := ShortClosedBoundary.open_pivotal G ω x z M e h - obtain ⟨_,_,a,b,l,hab,hl,ho,hlen,_⟩ := h - have hc := cluster_finite_of_finite_edges G (hω.insert e) x - have hb := bridgeIndex_le_short_trail G (insert e ω) x z hc e hpiv - a b hab l hl (fun f hf => Set.mem_insert_of_mem e (ho f hf)) - exact hb.trans (by omega) - -end ShortBoundaryPivotal - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ShortBoundaryCounting -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def firstOpenBridgeCount (G : BondGraph V E) (Q : Finset E) - (x z : V) (M : ℕ) (ω : Finset E) : ℕ := - (Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M)).card - -noncomputable def shortClosedBoundaryCount (G : BondGraph V E) (Q : Finset E) - (x z : V) (M : ℕ) (ω : Finset E) : ℕ := - (Q.filter (ShortClosedBoundary G ω x z M)).card - -theorem firstOpenBridgeCount_le (G : BondGraph V E) (Q : Finset E) - (x z : V) (M : ℕ) (ω : Finset E) : - firstOpenBridgeCount G Q x z M ω ≤ if Conn G ω x z then M else 0 := by - by_cases hc : Conn G ω x z - · rw [ite_eq_left hc] - unfold firstOpenBridgeCount - let S := Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M) - have hm : Set.MapsTo (bridgeIndex G ω x z) (S : Set E) (Finset.Icc 1 M) := by - intro e he - have he' := (Finset.mem_filter.mp he).2 - exact Finset.mem_Icc.mpr ⟨bridgeIndex_pos G ω x z he'.1,he'.2⟩ - have hi : Set.InjOn (bridgeIndex G ω x z) (S : Set E) := by - intro e he f hf h - exact bridgeIndex_injective G ω x z (cluster_finite_of_finite_edges G ω.finite_toSet x) - (Finset.mem_filter.mp he).2.1 (Finset.mem_filter.mp hf).2.1 h - simpa only [Nat.card_Icc,Nat.add_sub_cancel] using - (Finset.card_le_card_of_injOn (bridgeIndex G ω x z) hm hi) - · rw [ite_eq_right hc] - unfold firstOpenBridgeCount - have he : Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M) = ∅ := by - apply Finset.eq_empty_iff_forall_notMem.mpr - intro e he - obtain ⟨y,hy,hxy⟩ := (Finset.mem_filter.mp he).2.1.2.1 - exact hc ((Set.mem_singleton_iff.mp hy) ▸ hxy) - rw [he,Finset.card_empty] - -theorem bernoulliPolynomial_bit_balance (Q : Finset E) (e : E) (he : e ∈ Q) - (f : Finset E → ℝ) (p : ℝ) : - p*bernoulliPolynomial Q (fun ω => if e ∉ ω then f ω else 0) p = - (1-p)*bernoulliPolynomial Q (fun ω => if e ∈ ω then f (ω.erase e) else 0) p := by - conv_lhs => rw [←Finset.insert_erase he] - conv_rhs => rw [←Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q), - bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] - have hc : bernoulliPolynomial (Q.erase e) (fun ω => if e ∉ ω then f ω else 0) p = - bernoulliPolynomial (Q.erase e) f p := by - apply bernoulliPolynomial_congr - intro ω hω - simp only [show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),not_false_eq_true,ite_true] - have hco : bernoulliPolynomial (Q.erase e) (fun ω => if e ∉ insert e ω then f (insert e ω) else 0) p = 0 := by - simp only [Finset.mem_insert_self,not_true_eq_false,ite_false,bernoulliPolynomial_zero] - have ho : bernoulliPolynomial (Q.erase e) (fun ω => if e ∈ ω then f (ω.erase e) else 0) p = 0 := by - calc - _ = bernoulliPolynomial (Q.erase e) (fun _ => 0) p := by - apply bernoulliPolynomial_congr - intro ω hω - simp only [show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),ite_false] - _ = 0 := bernoulliPolynomial_zero _ _ - have hoo : bernoulliPolynomial (Q.erase e) - (fun ω => if e ∈ insert e ω then f ((insert e ω).erase e) else 0) p = - bernoulliPolynomial (Q.erase e) f p := by - apply bernoulliPolynomial_congr - intro ω hω - simp only [Finset.mem_insert_self,ite_true,Finset.erase_insert - (show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h))] - rw [hc,hco,ho,hoo] - ring - -end ShortBoundaryCounting - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ShortBoundaryExpectation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem bernoulliPolynomial_closed_count_balance (Q : Finset E) - (P : Finset E → E → Prop) (hP : ∀ ω e, P ω e → e ∉ ω) (p : ℝ) : - p*bernoulliPolynomial Q (fun ω => ((Q.filter (P ω)).card:ℝ)) p = - (1-p)*bernoulliPolynomial Q - (fun ω => ((Q.filter (fun e => e ∈ ω ∧ P (ω.erase e) e)).card:ℝ)) p := by - have hbal (e : E) (he : e ∈ Q) : - p*bernoulliPolynomial Q (fun ω => if P ω e then 1 else 0) p = - (1-p)*bernoulliPolynomial Q (fun ω => if e ∈ ω ∧ P (ω.erase e) e then 1 else 0) p := by - have h := bernoulliPolynomial_bit_balance Q e he (fun ω => if P ω e then 1 else 0) p - have hL : bernoulliPolynomial Q (fun ω => if e ∉ ω then (if P ω e then 1 else 0) else 0) p = - bernoulliPolynomial Q (fun ω => if P ω e then 1 else 0) p := by - apply bernoulliPolynomial_congr - intro ω _ - by_cases hp : P ω e - · simp only [hp,hP ω e hp,not_false_eq_true,ite_true] - · simp only [hp,ite_false,ite_self] - have hR : bernoulliPolynomial Q (fun ω => if e ∈ ω then (if P (ω.erase e) e then 1 else 0) else 0) p = - bernoulliPolynomial Q (fun ω => if e ∈ ω ∧ P (ω.erase e) e then 1 else 0) p := by - apply bernoulliPolynomial_congr - intro ω _ - by_cases hm : e ∈ ω <;> simp only [hm,true_and,false_and,ite_true,ite_false] - rw [hL,hR] at h - exact h - simp only [Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero, - bernoulliPolynomial_sum,Finset.mul_sum] - exact Finset.sum_congr rfl (fun e he => hbal e he) - -theorem shortClosedBoundary_erase_first (G : BondGraph V E) (ω : Finset E) - (x z : V) (M : ℕ) (e : E) (he : e ∈ ω) - (h : ShortClosedBoundary G (ω.erase e) x z M e) : - OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M := by - have h₁ := ShortClosedBoundary.open_pivotal G (ω.erase e) x z M e h - have h₂ := ShortClosedBoundary.bridgeIndex_le G (ω.erase e) x z (ω.erase e).finite_toSet M e h - rw [←Finset.coe_insert,Finset.insert_erase he] at h₁ h₂ - exact ⟨h₁,h₂⟩ - -theorem shortRecoveredBoundaryCount_le (G : BondGraph V E) (Q ω : Finset E) - (x z : V) (M : ℕ) : - (Q.filter (fun e => e ∈ ω ∧ ShortClosedBoundary G (ω.erase e) x z M e)).card ≤ - if Conn G ω x z then M else 0 := by - apply le_trans _ (firstOpenBridgeCount_le G Q x z M ω) - apply Finset.card_le_card - intro e he - obtain ⟨heQ,heω,hb⟩ := Finset.mem_filter.mp he - exact Finset.mem_filter.mpr ⟨heQ,shortClosedBoundary_erase_first G ω x z M e heω hb⟩ - - - -theorem finite_short_boundary_expectation (G : BondGraph V E) (Q : Finset E) - (x z : V) (M : ℕ) (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : - bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p ≤ - ((1-p)/p)*M*bernoulliPolynomial Q (fun ω => if Conn G ω x z then 1 else 0) p := by - have hbal := bernoulliPolynomial_closed_count_balance Q - (fun ω e => ShortClosedBoundary G ω x z M e) (fun ω e h => h.1) p - have hmono := bernoulliPolynomial_mono Q - (fun ω => ((Q.filter (fun e => e ∈ ω ∧ ShortClosedBoundary G (ω.erase e) x z M e)).card:ℝ)) - (fun ω => (M:ℝ)*(if Conn G ω x z then 1 else 0)) p ⟨hp.le,hp1⟩ (by - intro ω _ - have h := shortRecoveredBoundaryCount_le G Q ω x z M - by_cases hc : Conn G ω x z - · simp only [hc,ite_true,mul_one] at * - exact_mod_cast h - · simp only [hc,ite_false,mul_zero] at * - exact_mod_cast h) - rw [bernoulliPolynomial_const_mul] at hmono - have hbound := mul_le_mul_of_nonneg_left hmono (sub_nonneg.mpr hp1) - rw [←hbal] at hbound - change p*bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p ≤ _ at hbound - have hdiv := (le_div_iff₀ hp).mpr (show - bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p*p ≤ _ by - simpa only [mul_comm p] using hbound) - simpa only [div_eq_mul_inv,mul_assoc,mul_left_comm,mul_comm] using hdiv - -end ShortBoundaryExpectation - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ClusterResampling -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem bernoulliPolynomial_commute {F : Type*} (Q : Finset E) (R : Finset F) - (f : Finset E → Finset F → ℝ) (p q : ℝ) : - bernoulliPolynomial Q (fun a => bernoulliPolynomial R (f a) q) p = - bernoulliPolynomial R (fun b => bernoulliPolynomial Q (fun a => f a b) p) q := by - simp only [bernoulliPolynomial,Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - apply Finset.sum_congr rfl - intro a _ - ring - -theorem exteriorBonds_union_blocks (G : BondGraph V E) (Q : Finset E) - (W : Set V) (a b : Finset E) (ha : a ⊆ Q \ exteriorBonds G Q W) - (hb : b ⊆ exteriorBonds G Q W) : exteriorBonds G (a ∪ b) W = b := by - ext e - simp only [exteriorBonds,Finset.mem_filter,Finset.mem_union] - constructor - · rintro ⟨he,heW⟩ - rcases he with he | he - · obtain ⟨heQ,heR⟩ := Finset.mem_sdiff.mp (ha he) - exact (heR (Finset.mem_filter.mpr ⟨heQ,heW⟩)).elim - · exact he - · intro he - exact ⟨Or.inr he,(Finset.mem_filter.mp (hb he)).2⟩ - - -theorem cluster_cell_exterior_factor (G : BondGraph V E) (Q : Finset E) - (x : V) (W : Set V) (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial Q (fun ω => - (if cluster G ω x = W then (1:ℝ) else 0)*f (exteriorBonds G ω W)) p = - bernoulliPolynomial (Q \ exteriorBonds G Q W) - (fun a => if cluster G a x = W then (1:ℝ) else 0) p * - bernoulliPolynomial (exteriorBonds G Q W) f p := by - let R := exteriorBonds G Q W - let A := Q \ R - have hQ : A ∪ R = Q := Finset.sdiff_union_of_subset (Finset.filter_subset _ _) - conv_lhs => rw [←hQ,bernoulliPolynomial_union A R Finset.sdiff_disjoint] - trans bernoulliPolynomial A (fun a => - (if cluster G a x = W then (1:ℝ) else 0)*bernoulliPolynomial R f p) p - · apply bernoulliPolynomial_congr - intro a ha - rw [←bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro b hb - have hc := cluster_union_external_eq_iff G (a:Set E) b x W - (fun e he => (Finset.mem_filter.mp (hb he)).2) - rw [exteriorBonds_union_blocks G Q W a b ha hb] - simp only [Finset.coe_union,hc] - · exact bernoulliPolynomial_mul_const A _ _ p - -theorem cluster_cell_incident_probability (G : BondGraph V E) (Q : Finset E) - (x : V) (W : Set V) (p : ℝ) : - bernoulliPolynomial Q (fun ω => if cluster G ω x = W then (1:ℝ) else 0) p = - bernoulliPolynomial (Q \ exteriorBonds G Q W) - (fun a => if cluster G a x = W then (1:ℝ) else 0) p := by - have h := cluster_cell_exterior_factor G Q x W (fun _ => 1) p - simpa only [mul_one,bernoulliPolynomial_const] using h - -noncomputable def resampleClusterAt (G : BondGraph V E) (Q : Finset E) - (W : Set V) (ω η : Finset E) : Finset E := - exteriorBonds G ω W ∪ (η ∩ (Q \ exteriorBonds G Q W)) - - - -theorem cluster_resample_cell_independent (G : BondGraph V E) (Q : Finset E) - (x : V) (W : Set V) (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => - (if cluster G ω x = W then (1:ℝ) else 0)*f (resampleClusterAt G Q W ω η)) p) p = - bernoulliPolynomial Q (fun ω => if cluster G ω x = W then (1:ℝ) else 0) p * - bernoulliPolynomial Q f p := by - let R := exteriorBonds G Q W - let A := Q \ R - let c := bernoulliPolynomial A (fun a => if cluster G a x = W then (1:ℝ) else 0) p - rw [bernoulliPolynomial_commute] - trans bernoulliPolynomial Q (fun η => c * bernoulliPolynomial R - (fun b => f (b ∪ (η ∩ A))) p) p - · apply bernoulliPolynomial_congr - intro η _ - exact cluster_cell_exterior_factor G Q x W (fun b => f (b ∪ (η ∩ A))) p - · rw [bernoulliPolynomial_const_mul,bernoulliPolynomial_restrict A Q Finset.sdiff_subset - (fun a => bernoulliPolynomial R (fun b => f (b ∪ a)) p) p, - bernoulliPolynomial_commute] - have hQ : R ∪ A = Q := Finset.union_sdiff_of_subset (Finset.filter_subset _ _) - rw [←bernoulliPolynomial_union R A Finset.disjoint_sdiff,hQ, - cluster_cell_incident_probability G Q x W p] - -end ClusterResampling -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ResampledBoundary -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem resampleClusterAt_subset (G : BondGraph V E) (Q : Finset E) - (W : Set V) (ω η : Finset E) (hω : ω ⊆ Q) : - resampleClusterAt G Q W ω η ⊆ Q := by - intro e he - rcases Finset.mem_union.mp he with he | he - · exact hω (Finset.mem_filter.mp he).1 - · exact (Finset.mem_sdiff.mp (Finset.mem_inter.mp he).2).1 - -theorem resampleClusterAt_external (G : BondGraph V E) (Q : Finset E) - (W : Set V) (ω η : Finset E) {e : E} (he : e ∈ resampleClusterAt G Q W ω η) - (heW : e ∈ internalEdges G Wᶜ) : e ∈ ω := by - rcases Finset.mem_union.mp he with he | he - · exact (Finset.mem_filter.mp he).1 - · obtain ⟨_,heA⟩ := Finset.mem_inter.mp he - obtain ⟨heQ,heR⟩ := Finset.mem_sdiff.mp heA - exact (heR (Finset.mem_filter.mpr ⟨heQ,heW⟩)).elim - - - -theorem resampled_path_boundary (G : BondGraph V E) (Q ω η : Finset E) - (hω : ω ⊆ Q) (x z y : V) (M : ℕ) - (hy : Conn G ω z y) (hx : ¬Conn G ω x z) - (l : List E) (hl : Along G x l y) (hlen : l.length ≤ M) - (ho : ∀ e ∈ l, e ∈ resampleClusterAt G Q (cluster G ω z) ω η) : - ∃ e ∈ Q, ShortClosedBoundary G ω x z M e := by - let W := cluster G ω z - have hxW : x ∉ W := fun h => hx (conn_symm G ω h) - rcases hl.first_outside (internalEdges G Wᶜ) with hall | ⟨a,b,e,l₁,l₂,heq,h₁,hab,_,hfirst,hen⟩ - · have hc : Conn G ((Set.univ:Set E) ∩ internalEdges G Wᶜ) x y := - hl.conn (fun e he => ⟨Set.mem_univ e,hall e he⟩) - exact ((conn_internal_endpoint G Wᶜ hxW hc) hy).elim - · subst l - have heopen := ho e (List.mem_append_right _ (by simp)) - have heQ := resampleClusterAt_subset G Q W ω η hω heopen - have hprefix : ∀ f ∈ l₁, f ∈ ω := by - intro f hf - exact resampleClusterAt_external G Q W ω η - (ho f (List.mem_append_left _ hf)) (hfirst f hf) - have hxa : Conn G ((ω:Set E) ∩ internalEdges G Wᶜ) x a := - h₁.conn (fun f hf => ⟨hprefix f hf,hfirst f hf⟩) - have haW : a ∉ W := conn_internal_endpoint G Wᶜ hxW hxa - have hbW : b ∈ W := by - by_contra hbW - exact hen ((mem_internalEdges_of_ends G Wᶜ e a b hab).mpr ⟨haW,hbW⟩) - have heclosed : e ∉ ω := by - intro heω - apply haW - exact (show Conn G ω z b from hbW).tail ⟨e,heω,hab.trans (Sym2.eq_swap ..)⟩ - refine ⟨e,heQ,heclosed,hx,a,b,l₁,hab,h₁,hprefix,?_,conn_symm G ω hbW⟩ - simp only [List.length_append,List.length_cons] at hlen - omega - -noncomputable def resampleRootCluster (G : BondGraph V E) (Q : Finset E) - (z : V) (ω η : Finset E) : Finset E := - resampleClusterAt G Q (cluster G ω z) ω η - - -theorem resampled_hit_le_boundaryCount (G : BondGraph V E) (Q ω η : Finset E) - (hω : ω ⊆ Q) (x z y : V) (M : ℕ) - (hpath : ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ - ∀ e ∈ l, e ∈ resampleRootCluster G Q z ω η) : - (if Conn G ω z y then (1:ℝ) else 0) ≤ - (if Conn G ω x z then (1:ℝ) else 0) + shortClosedBoundaryCount G Q x z M ω := by - by_cases hy : Conn G ω z y - · rw [ite_eq_left hy] - by_cases hx : Conn G ω x z - · rw [ite_eq_left hx] - exact le_add_of_nonneg_right (Nat.cast_nonneg _) - · rw [ite_eq_right hx,zero_add] - obtain ⟨l,hl,hlen,ho⟩ := hpath - obtain ⟨e,heQ,he⟩ := resampled_path_boundary G Q ω η hω x z y M hy hx l hl hlen ho - have hpos : 0 < shortClosedBoundaryCount G Q x z M ω := - Finset.card_pos.mpr ⟨e,Finset.mem_filter.mpr ⟨heQ,he⟩⟩ - exact_mod_cast hpos - · rw [ite_eq_right hy] - positivity - -end ResampledBoundary -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RootResamplingLaw -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem rootCluster_resampling_law (G : BondGraph V E) (Q : Finset E) - (x : V) (f : Finset V → Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q - (fun η => f (finiteRootComponent G ω x) (resampleRootCluster G Q x ω η)) p) p = - bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q - (f (finiteRootComponent G ω x)) p) p := by - let F := insert x (searchVertices G Q) - let c := fun (W : Finset V) (ω : Finset E) => if cluster G ω x = (W:Set V) then (1:ℝ) else 0 - have hpart (ω η : Finset E) (hω : ω ⊆ Q) : - f (finiteRootComponent G ω x) (resampleRootCluster G Q x ω η) = - ∑ W ∈ F.powerset, c W ω * f W (resampleClusterAt G Q W ω η) := by - have h := sum_component_partition G Q F x ω hω (by rfl) - (fun W => f W (resampleClusterAt G Q W ω η)) - simpa only [c,ite_mul,one_mul,zero_mul,coe_finiteRootComponent, - resampleRootCluster] using h.symm - trans ∑ W ∈ F.powerset, - bernoulliPolynomial Q (c W) p * bernoulliPolynomial Q (f W) p - · trans bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => - ∑ W ∈ F.powerset, c W ω * f W (resampleClusterAt G Q W ω η)) p) p - · apply bernoulliPolynomial_congr - intro ω hω - apply bernoulliPolynomial_congr - intro η _ - exact hpart ω η hω - · simp only [bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro W _ - exact cluster_resample_cell_independent G Q x W (f W) p - · trans bernoulliPolynomial Q (fun ω => ∑ W ∈ F.powerset, - c W ω * bernoulliPolynomial Q (f W) p) p - · rw [bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro W _ - exact (bernoulliPolynomial_mul_const Q (c W) _ p).symm - · apply bernoulliPolynomial_congr - intro ω hω - have h := sum_component_partition G Q F x ω hω (by rfl) - (fun W => bernoulliPolynomial Q (f W) p) - simpa only [c,ite_mul,one_mul,zero_mul] using h - -end RootResamplingLaw -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteMaximalSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteSusceptibility (G : BondGraph V E) (Q : Finset E) - (F : Finset V) (p : ℝ) (x : V) : ℝ := - ∑ z ∈ F, bernoulliPolynomial Q (fun ω => if Conn G ω x z then (1:ℝ) else 0) p - -theorem finiteSusceptibility_nonneg (G : BondGraph V E) (Q : Finset E) - (F : Finset V) (p : ℝ) (x : V) (hp : p ∈ Set.Icc (0:ℝ) 1) : - 0 ≤ finiteSusceptibility G Q F p x := by - apply Finset.sum_nonneg - intro z _ - exact bernoulliPolynomial_nonneg Q _ p hp (fun _ _ => by positivity) - -theorem rootCluster_resampled_selector (G : BondGraph V E) (Q : Finset E) - (w : V) (Z : Finset E → V) (p : ℝ) : - bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => - if Conn G ω w (Z (resampleRootCluster G Q w ω η)) then (1:ℝ) else 0) p) p = - bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => - if Conn G ω w (Z η) then (1:ℝ) else 0) p) p := by - have hm (ω : Finset E) (y : V) : - y ∈ finiteRootComponent G ω w ↔ Conn G ω w y := by - change y ∈ (finiteRootComponent G ω w : Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - have h := rootCluster_resampling_law G Q w (fun W η => if Z η ∈ W then (1:ℝ) else 0) p - simp only [hm] at h - exact h.trans (bernoulliPolynomial_commute Q Q _ p p) - -theorem finite_selector_connection_bound (G : BondGraph V E) (Q : Finset E) - (x w : V) (M : ℕ) (Z : Finset E → V) - (hZ : ∀ η ⊆ Q, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) - (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : - bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => - if Conn G ω w (Z η) then (1:ℝ) else 0) p) p ≤ - (1+(1-p)/p*M)*bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p := by - rw [←rootCluster_resampled_selector G Q w Z p] - have hmono := bernoulliPolynomial_mono Q - (fun ω => bernoulliPolynomial Q (fun η => - if Conn G ω w (Z (resampleRootCluster G Q w ω η)) then (1:ℝ) else 0) p) - (fun ω => (if Conn G ω x w then (1:ℝ) else 0)+shortClosedBoundaryCount G Q x w M ω) - p ⟨hp.le,hp1⟩ (by - intro ω hω - calc - _ ≤ bernoulliPolynomial Q (fun _ => - (if Conn G ω x w then (1:ℝ) else 0)+shortClosedBoundaryCount G Q x w M ω) p := by - apply bernoulliPolynomial_mono Q _ _ p ⟨hp.le,hp1⟩ - intro η _ - exact resampled_hit_le_boundaryCount G Q ω η hω x w _ M - (hZ _ (resampleClusterAt_subset G Q _ ω η hω)) - _ = _ := bernoulliPolynomial_const Q _ p) - rw [bernoulliPolynomial_add] at hmono - have hb := finite_short_boundary_expectation G Q x w M p hp hp1 - calc - _ ≤ _ := hmono - _ ≤ bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p + - ((1-p)/p)*M*bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p := - add_le_add le_rfl hb - _ = _ := by ring - - - -theorem finite_selected_susceptibility_bound (G : BondGraph V E) (Q : Finset E) - (F : Finset V) (x : V) (M : ℕ) (Z : Finset E → V) - (hZ : ∀ η ⊆ Q, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) - (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : - bernoulliPolynomial Q (fun η => finiteSusceptibility G Q F p (Z η)) p ≤ - (1+(1-p)/p*M)*finiteSusceptibility G Q F p x := by - unfold finiteSusceptibility - rw [bernoulliPolynomial_sum,Finset.mul_sum] - apply Finset.sum_le_sum - intro w _ - have h := finite_selector_connection_bound G Q x w M Z hZ p hp hp1 - calc - _ = bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => - if Conn G ω w (Z η) then (1:ℝ) else 0) p) p := by - apply bernoulliPolynomial_congr - intro η _ - apply bernoulliPolynomial_congr - intro ω _ - apply if_congr _ rfl rfl - exact ⟨conn_symm G ω,conn_symm G ω⟩ - _ ≤ _ := h - -end FiniteMaximalSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section RestrictedConnectionLimit -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem tendsto_bernoulliPolynomial {ι : Type*} {l : Filter ι} - (Q : Finset E) (f : ι → Finset E → ℝ) (g : Finset E → ℝ) (p : ℝ) - (h : ∀ a ⊆ Q, Tendsto (fun i => f i a) l (𝓝 (g a))) : - Tendsto (fun i => bernoulliPolynomial Q (f i) p) l - (𝓝 (bernoulliPolynomial Q g p)) := by - unfold bernoulliPolynomial - exact tendsto_finsetSum _ (fun a ha => - ((h a (Finset.mem_powerset.mp ha)).mul_const _).mul_const _) - -theorem conn_finite_exhaustion (G : BondGraph V E) (S : Set E) - (Q : ℕ → Finset E) (hQ : Monotone Q) (hcover : ∀ e ∈ S, ∃ n, e ∈ Q n) - {ω : Set E} {x y : V} (h : Conn G (ω ∩ S) x y) : - ∃ n, Conn G (ω ∩ (Q n : Set E)) x y := by - induction h with - | refl => exact ⟨0,conn_refl _ _ _⟩ - | @tail a b hxa hab ih => - obtain ⟨n,hn⟩ := ih - obtain ⟨e,he,hab⟩ := hab - obtain ⟨m,hm⟩ := hcover e he.2 - refine ⟨max n m,?_⟩ - exact (conn_mono G (Set.inter_subset_inter_right _ - (show (Q n:Set E) ⊆ (Q (max n m):Set E) from hQ (le_max_left n m))) hn).tail - ⟨e,⟨he.1,hQ (le_max_right n m) hm⟩,hab⟩ - -theorem finite_connection_polynomial_tendsto (G : BondGraph V E) (S : Set E) - (Q : ℕ → Finset E) (hQ : Monotone Q) (hsub : ∀ n, (Q n:Set E) ⊆ S) - (hcover : ∀ e ∈ S, ∃ n, e ∈ Q n) (p : unitInterval) (x y : V) : - Tendsto (fun n => bernoulliPolynomial (Q n) (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) - atTop (𝓝 ((law p).real {ω | Conn G (ω ∩ S) x y})) := by - have he (n : ℕ) : bernoulliPolynomial (Q n) (fun ω => if Conn G ω x y then (1:ℝ) else 0) p = - (law p).real {ω | Conn G (ω ∩ (Q n:Set E)) x y} := - finiteEventPolynomial_restrict (Q n) {ω | Conn G ω x y} p - simp_rw [he] - have hm : Monotone (fun n => {ω : Set E | Conn G (ω ∩ (Q n:Set E)) x y}) := by - intro m n h ω hc - exact conn_mono G (Set.inter_subset_inter_right _ (show (Q m:Set E) ⊆ (Q n:Set E) from hQ h)) hc - have hu : (⋃ n, {ω : Set E | Conn G (ω ∩ (Q n:Set E)) x y}) = - {ω : Set E | Conn G (ω ∩ S) x y} := by - ext ω - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] - exact ⟨fun ⟨n,hn⟩ => conn_mono G (Set.inter_subset_inter_right _ (hsub n)) hn, - conn_finite_exhaustion G S Q hQ hcover⟩ - have ht := tendsto_measure_iUnion_atTop (μ := law p) hm - rw [hu] at ht - exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht - -noncomputable def restrictedBondExhaustion [Encodable E] (S : Set E) (K : Finset E) - (n : ℕ) : Finset E := K ∪ (vertexExhaustion (V := E) n).filter (· ∈ S) - -theorem restrictedBondExhaustion_mono [Encodable E] (S : Set E) (K : Finset E) : - Monotone (restrictedBondExhaustion S K) := by - intro m n h - exact Finset.union_subset_union (by rfl) (Finset.filter_subset_filter _ (vertexExhaustion_mono h)) - -theorem restrictedBondExhaustion_cover [Encodable E] (S : Set E) (K : Finset E) - (e : E) (he : e ∈ S) : ∃ n, e ∈ restrictedBondExhaustion S K n := by - obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e}:Finset E) - exact ⟨n,Finset.mem_union_right _ (Finset.mem_filter.mpr ⟨hn (by simp),he⟩)⟩ - -theorem restrictedBondExhaustion_subset [Encodable E] (S : Set E) (K : Finset E) - (hK : (K:Set E) ⊆ S) (n : ℕ) : (restrictedBondExhaustion S K n:Set E) ⊆ S := by - intro e he - rcases Finset.mem_union.mp he with he | he - · exact hK he - · exact (Finset.mem_filter.mp he).2 - -end RestrictedConnectionLimit -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section RestrictedSelectorBound -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem restricted_selector_connection_bound [Countable E] (G : BondGraph V E) - (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) - (x w : V) (M : ℕ) (Z : Finset E → V) - (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) - (p : unitInterval) (hp : 0 < (p:ℝ)) : - bernoulliPolynomial K (fun η => (law p).real {ω | Conn G (ω ∩ S) w (Z η)}) p ≤ - (1+(1-(p:ℝ))/p*M)*(law p).real {ω | Conn G (ω ∩ S) x w} := by - let := Encodable.ofCountable E - let Q := restrictedBondExhaustion S K - have hlim (a b : V) := finite_connection_polynomial_tendsto G S Q - (restrictedBondExhaustion_mono S K) (restrictedBondExhaustion_subset S K hK) - (restrictedBondExhaustion_cover S K) p a b - have hleft := tendsto_bernoulliPolynomial K - (fun n η => bernoulliPolynomial (Q n) (fun ω => if Conn G ω w (Z η) then (1:ℝ) else 0) p) - (fun η => (law p).real {ω | Conn G (ω ∩ S) w (Z η)}) p (fun η _ => hlim w (Z η)) - have hright := (hlim x w).const_mul (1+(1-(p:ℝ))/p*M) - apply le_of_tendsto_of_tendsto hleft hright - apply Eventually.of_forall - intro n - have hZQ : ∀ η ⊆ Q n, ∃ l : List E, Along G x l (Z (η ∩ K)) ∧ - l.length ≤ M ∧ ∀ e ∈ l, e ∈ η := by - intro η _ - obtain ⟨l,hl,hlen,ho⟩ := hZ (η ∩ K) Finset.inter_subset_right - exact ⟨l,hl,hlen,fun e he => (Finset.mem_inter.mp (ho e he)).1⟩ - have h := finite_selector_connection_bound G (Q n) x w M (fun η => Z (η ∩ K)) hZQ p hp p.2.2 - rw [bernoulliPolynomial_restrict K (Q n) Finset.subset_union_left - (fun η => bernoulliPolynomial (Q n) (fun ω => if Conn G ω w (Z η) then (1:ℝ) else 0) p) p] at h - exact h - -noncomputable def restrictedSusceptibility (G : BondGraph V E) (S : Set E) - (p : unitInterval) (x : V) : ℝ := - ∑' y, (law p).real {ω | Conn G (ω ∩ S) x y} - -theorem restrictedTwoPoint_le (G : BondGraph V E) (S : Set E) - (p : unitInterval) (x y : V) : - (law p).real {ω | Conn G (ω ∩ S) x y} ≤ twoPoint G p x y := by - exact measureReal_mono (fun _ h => conn_mono G Set.inter_subset_left h) - -theorem summable_restrictedTwoPoint [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (S : Set E) (x : V) : - Summable (fun y => (law p).real {ω | Conn G (ω ∩ S) x y}) := by - obtain ⟨C,_,hC⟩ := subcritical_row_bound G hloc hqt p hp - apply summable_of_sum_le (fun _ => measureReal_nonneg) - intro F - exact (Finset.sum_le_sum (fun y _ => restrictedTwoPoint_le G S p x y)).trans (hC x F) - -end RestrictedSelectorBound -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section SelectorSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem summable_bernoulliPolynomial {A : Type*} (K : Finset E) - (f : Finset E → A → ℝ) (p : ℝ) (hf : ∀ η ⊆ K, Summable (f η)) : - Summable (fun y => bernoulliPolynomial K (fun η => f η y) p) := by - unfold bernoulliPolynomial - apply summable_sum - intro η hη - exact ((hf η (Finset.mem_powerset.mp hη)).mul_right _).mul_right _ - -theorem bernoulliPolynomial_tsum {A : Type*} (K : Finset E) - (f : Finset E → A → ℝ) (p : ℝ) (hf : ∀ η ⊆ K, Summable (f η)) : - bernoulliPolynomial K (fun η => ∑' y, f η y) p = - ∑' y, bernoulliPolynomial K (fun η => f η y) p := by - unfold bernoulliPolynomial - rw [Summable.tsum_finsetSum (fun η hη => - ((hf η (Finset.mem_powerset.mp hη)).mul_right _).mul_right _)] - apply Finset.sum_congr rfl - intro η _ - rw [tsum_mul_right,tsum_mul_right] - -theorem restrictedTwoPoint_symm (G : BondGraph V E) (S : Set E) - (p : unitInterval) (x y : V) : - (law p).real {ω | Conn G (ω ∩ S) x y} = - (law p).real {ω | Conn G (ω ∩ S) y x} := by - congr 1 - ext ω - exact ⟨conn_symm G _,conn_symm G _⟩ - - - -theorem restricted_selected_susceptibility_bound [Countable E] (G : BondGraph V E) - (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) - (x : V) (M : ℕ) (Z : Finset E → V) - (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) - (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) y z})) : - bernoulliPolynomial K (fun η => restrictedSusceptibility G S p (Z η)) p ≤ - (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := by - unfold restrictedSusceptibility - rw [bernoulliPolynomial_tsum K _ p (fun η _ => hfin (Z η)),←tsum_mul_left] - apply Summable.tsum_le_tsum _ (summable_bernoulliPolynomial K _ p (fun η _ => hfin (Z η))) - ((hfin x).mul_left _) - intro w - have h := restricted_selector_connection_bound G S K hK x w M Z hZ p hp - simpa only [restrictedTwoPoint_symm G S p (Z _) w] using h - - - -theorem subcritical_selected_susceptibility_bound - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) - (x : V) (M : ℕ) (Z : Finset E → V) - (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) : - bernoulliPolynomial K (fun η => restrictedSusceptibility G S p (Z η)) p ≤ - (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := - restricted_selected_susceptibility_bound G S K hK x M Z hZ p hp - (summable_restrictedTwoPoint G hloc hqt p hpc S) - -end SelectorSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section IntrinsicBall -attribute [local instance] Classical.propDecidable Classical.decEq - - -def intrinsicBall (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : Set V := - {y | ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ ω} - -theorem mem_intrinsicBall_self (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : - x ∈ intrinsicBall G ω x M := ⟨[],.nil x,Nat.zero_le _,by simp⟩ - -theorem intrinsicBall_subset_reachBall (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : - intrinsicBall G ω x M ⊆ reachBall G x M := by - rintro y ⟨l,hl,hlen,_⟩ - exact reachBall_mono G x hlen hl.mem_reachBall - -theorem intrinsicBall_mono (G : BondGraph V E) {ω η : Set E} (h : ω ⊆ η) (x : V) (M : ℕ) : - intrinsicBall G ω x M ⊆ intrinsicBall G η x M := by - rintro y ⟨l,hl,hlen,ho⟩ - exact ⟨l,hl,hlen,fun e he => h (ho e he)⟩ - -theorem Along.bonds_in_incidentBall {G : BondGraph V E} (hloc : LocallyFinite G) - {x y : V} {l : List E} (h : Along G x l y) (M : ℕ) (hlen : l.length ≤ M) : - ∀ e ∈ l, e ∈ incidentSupport G hloc (finite_reachBall hloc x M).toFinset := by - rcases h.first_outside (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) - with h | ⟨a,b,e,l₁,l₂,heq,h₁,he,_,_,hnot⟩ - · exact h - · exfalso - apply hnot - apply (mem_incidentSupport G hloc _ e).mpr - refine ⟨a,?_,by simp [he]⟩ - apply (finite_reachBall hloc x M).mem_toFinset.mpr - apply reachBall_mono G x (show l₁.length ≤ M by subst l; simp only [List.length_append,List.length_cons] at hlen; omega) - exact h₁.mem_reachBall - -theorem intrinsicBall_restrict (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) : - intrinsicBall G (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E)) x M = - intrinsicBall G ω x M := by - apply Set.Subset.antisymm (intrinsicBall_mono G Set.inter_subset_left x M) - rintro y ⟨l,hl,hlen,ho⟩ - exact ⟨l,hl,hlen,fun e he => ⟨ho e he,hl.bonds_in_incidentBall hloc M hlen e he⟩⟩ - -theorem integral_eq_bernoulliPolynomial (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (Q:Set E))) : - (∫ ω, f ω ∂law p) = bernoulliPolynomial Q (fun η => f η) p := by - rw [integral_finite_local Q p f hf] - simp only [finiteFieldWeight,finiteFieldSet] - rw [Finset.sum_coe_sort Q.powerset (fun η => bernoulliWeight Q η p * f η)] - unfold bernoulliPolynomial - apply Finset.sum_congr rfl - intro η _ - unfold bernoulliWeight - ring - -end IntrinsicBall -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section IntrinsicMaximum -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem intrinsicBall_exists_max (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : - ∃ z ∈ intrinsicBall G ω x M, ∀ y ∈ intrinsicBall G ω x M, f y ≤ f z := - Set.exists_max_image _ f ((finite_reachBall hloc x M).subset - (intrinsicBall_subset_reachBall G ω x M)) ⟨x,mem_intrinsicBall_self G ω x M⟩ - -noncomputable def intrinsicMaximizer (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : V := - Classical.choose (intrinsicBall_exists_max G hloc ω x M f) - -theorem intrinsicMaximizer_spec (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : - intrinsicMaximizer G hloc ω x M f ∈ intrinsicBall G ω x M ∧ - ∀ y ∈ intrinsicBall G ω x M, f y ≤ f (intrinsicMaximizer G hloc ω x M f) := - Classical.choose_spec (intrinsicBall_exists_max G hloc ω x M f) - -noncomputable def intrinsicPotentialMax (G : BondGraph V E) (ω : Set E) - (x : V) (M : ℕ) (f : V → ℝ) : ℝ := sSup (f '' intrinsicBall G ω x M) - -theorem intrinsicPotentialMax_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : - intrinsicPotentialMax G ω x M f = f (intrinsicMaximizer G hloc ω x M f) := by - have h := intrinsicMaximizer_spec G hloc ω x M f - apply IsGreatest.csSup_eq - exact ⟨⟨_,h.1,rfl⟩,fun _ ⟨y,hy,he⟩ => he ▸ h.2 y hy⟩ - -theorem le_intrinsicPotentialMax (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) (y : V) (hy : y ∈ intrinsicBall G ω x M) : - f y ≤ intrinsicPotentialMax G ω x M f := by - rw [intrinsicPotentialMax_eq G hloc] - exact (intrinsicMaximizer_spec G hloc ω x M f).2 y hy - -noncomputable def intrinsicBondSupport (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Set E) (x : V) (M : ℕ) : Finset E := - (incidentSupport G hloc (finite_reachBall hloc x M).toFinset).filter (· ∈ S) - -theorem intrinsicBondSupport_coe (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Set E) (x : V) (M : ℕ) : - (intrinsicBondSupport G hloc S x M : Set E) = - (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) ∩ S := by - ext e - simp [intrinsicBondSupport] - -theorem intrinsicBall_domain_restrict (G : BondGraph V E) (hloc : LocallyFinite G) - (S ω : Set E) (x : V) (M : ℕ) : - intrinsicBall G (ω ∩ (intrinsicBondSupport G hloc S x M : Set E)) x M = - intrinsicBall G (ω ∩ S) x M := by - rw [intrinsicBondSupport_coe] - have he : ω ∩ ((incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) ∩ S) = - (ω ∩ S) ∩ (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) := by - ext e; simp [and_left_comm,and_comm,and_assoc] - rw [he,intrinsicBall_restrict G hloc] - -theorem intrinsicPotentialMax_domain_local (G : BondGraph V E) (hloc : LocallyFinite G) - (S ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : - intrinsicPotentialMax G (ω ∩ S) x M f = - intrinsicPotentialMax G ((ω ∩ (intrinsicBondSupport G hloc S x M : Set E)) ∩ S) x M f := by - have hsub : (intrinsicBondSupport G hloc S x M : Set E) ⊆ S := by - rw [intrinsicBondSupport_coe]; exact Set.inter_subset_right - rw [Set.inter_assoc,Set.inter_eq_left.mpr hsub] - unfold intrinsicPotentialMax - rw [intrinsicBall_domain_restrict G hloc] - -end IntrinsicMaximum -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section MaximalSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem maximal_restricted_susceptibility_bound - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (S : Set E) (x : V) (M : ℕ) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hpc : p < pc G) : - (∫ ω, intrinsicPotentialMax G (ω ∩ S) x M (restrictedSusceptibility G S p) ∂law p) ≤ - (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := by - let K := intrinsicBondSupport G hloc S x M - let f := restrictedSusceptibility G S p - let Z : Finset E → V := fun η => intrinsicMaximizer G hloc η x M f - have hK : (K:Set E) ⊆ S := by - rw [intrinsicBondSupport_coe]; exact Set.inter_subset_right - rw [integral_eq_bernoulliPolynomial K p _ (fun ω => - intrinsicPotentialMax_domain_local G hloc S ω x M f)] - have he : bernoulliPolynomial K (fun η => intrinsicPotentialMax G ((η:Set E) ∩ S) x M f) p = - bernoulliPolynomial K (fun η => f (Z η)) p := by - apply bernoulliPolynomial_congr K _ p - intro η hη - rw [Set.inter_eq_left.mpr (fun e he => hK (hη he))] - exact intrinsicPotentialMax_eq G hloc η x M f - rw [he] - apply subcritical_selected_susceptibility_bound G hloc hqt S K hK x M Z _ p hp hpc - intro η _ - exact (intrinsicMaximizer_spec G hloc η x M f).1 - - - -noncomputable def inducedSusceptibility (G : BondGraph V E) (D : Set V) - (p : unitInterval) (x : V) : ℝ := - if x ∈ D then restrictedSusceptibility G (internalEdges G D) p x else 0 - -theorem intrinsicBall_internal_subset (G : BondGraph V E) (D : Set V) - (ω : Set E) (x : V) (hx : x ∈ D) (M : ℕ) : - intrinsicBall G (ω ∩ internalEdges G D) x M ⊆ D := by - rintro y ⟨l,hl,_,ho⟩ - exact conn_internal_endpoint G D hx (hl.conn ho) - -theorem inducedSusceptibility_max_eq (G : BondGraph V E) (D : Set V) - (ω : Set E) (p : unitInterval) (x : V) (hx : x ∈ D) (M : ℕ) : - intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) = - intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (restrictedSusceptibility G (internalEdges G D) p) := by - unfold intrinsicPotentialMax - congr 1 - apply Set.image_congr - intro y hy - exact ite_eq_left (intrinsicBall_internal_subset G D ω x hx M hy) - - - -theorem maximal_induced_susceptibility_bound - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (D : Set V) (x : V) (hx : x ∈ D) (M : ℕ) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hpc : p < pc G) : - (∫ ω, intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) ∂law p) ≤ - (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x := by - simp_rw [inducedSusceptibility_max_eq G D _ p x hx M] - rw [inducedSusceptibility,ite_eq_left hx] - exact maximal_restricted_susceptibility_bound G hloc hqt (internalEdges G D) x M p hp hpc - -end MaximalSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section RestrictedPathPotential -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem restrictedTwoPoint_adj_lower [Countable E] (G : BondGraph V E) - (S : Set E) (p : unitInterval) (x y z : V) (e : E) - (he : G e = s(x,y)) (heS : e ∈ S) : - (p:ℝ)*(law p).real {ω | Conn G (ω ∩ S) y z} ≤ - (law p).real {ω | Conn G (ω ∩ S) x z} := by - have h := association_finiteWitness p {ω : Set E | e ∈ ω} {ω | Conn G (ω ∩ S) y z} - (fun _ _ hω h => hω h) - (fun _ _ hω h => conn_mono G (Set.inter_subset_inter_left _ hω) h) - (finiteWitness_edge e) (finiteWitness_inter _ (finiteWitness_conn G y z) S) - have hp : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by - simpa using finite_open_probability p {e} - rw [hp] at h - exact h.trans (measureReal_mono (fun ω hω => - conn_trans G _ (Relation.ReflTransGen.single ⟨e,⟨hω.1,heS⟩,he⟩) hω.2)) - -theorem restrictedTwoPoint_path_lower [Countable E] (G : BondGraph V E) - (S : Set E) (p : unitInterval) {x y : V} {l : List E} - (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) (z : V) : - (p:ℝ)^l.length*(law p).real {ω | Conn G (ω ∩ S) y z} ≤ - (law p).real {ω | Conn G (ω ∩ S) x z} := by - induction hl with - | nil => simp - | @cons x a y l e he ht ih => - have hh := mul_le_mul_of_nonneg_left (ih (fun d hd => hS d (List.mem_cons_of_mem _ hd))) p.2.1 - have ha := restrictedTwoPoint_adj_lower G S p x a z e he (hS e (by simp)) - simpa only [List.length_cons,pow_succ',mul_assoc] using hh.trans ha - -theorem restrictedSusceptibility_nonneg (G : BondGraph V E) (S : Set E) - (p : unitInterval) (x : V) : 0 ≤ restrictedSusceptibility G S p x := - tsum_nonneg (fun _ => measureReal_nonneg) - -theorem restrictedSusceptibility_path_lower [Countable E] (G : BondGraph V E) - (S : Set E) (p : unitInterval) {x y : V} {l : List E} - (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) - (hfin : ∀ a, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) a z})) : - (p:ℝ)^l.length*restrictedSusceptibility G S p y ≤ restrictedSusceptibility G S p x := by - unfold restrictedSusceptibility - rw [←tsum_mul_left] - exact ((hfin y).mul_left _).tsum_le_tsum (restrictedTwoPoint_path_lower G S p hl hS) (hfin x) - - - -theorem restrictedSusceptibility_short_path_bound [Countable E] (G : BondGraph V E) - (S : Set E) (p : unitInterval) (hp : 0 < (p:ℝ)) {x y : V} {l : List E} - (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) (M : ℕ) (hlen : l.length ≤ M) - (hfin : ∀ a, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) a z})) : - restrictedSusceptibility G S p y ≤ (p:ℝ)^(-(M:ℤ))*restrictedSusceptibility G S p x := by - have hh := restrictedSusceptibility_path_lower G S p hl hS hfin - have hpow : (p:ℝ)^M ≤ (p:ℝ)^l.length := - pow_le_pow_of_le_one p.2.1 p.2.2 hlen - have hbound := (mul_le_mul_of_nonneg_right hpow (restrictedSusceptibility_nonneg G S p y)).trans hh - rw [zpow_neg,zpow_natCast,←div_eq_inv_mul] - exact (le_div_iff₀ (pow_pos hp M)).mpr (by simpa only [mul_comm] using hbound) - -end RestrictedPathPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ShortPathsDeletedDomain -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem conn_short_of_cluster_cap (G : BondGraph V E) (ω : Set E) (x y : V) - (hxy : Conn G ω x y) (hfin : (cluster G ω x).Finite) - (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) : - ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ ω := by - obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp hxy - let q := w.toPath - have hs : q.val.support.toFinset ⊆ hfin.toFinset := by - intro z hz - have hz' : z ∈ q.val.support := List.mem_toFinset.mp hz - exact hfin.mem_toFinset.mpr ((conn_iff_reachable G ω x z).mpr ⟨q.val.takeUntil z hz'⟩) - have hc : q.val.length+1 ≤ (cluster G ω x).ncard := by - have hc := Finset.card_le_card hs - rwa [List.toFinset_card_of_nodup q.property.support_nodup, - SimpleGraph.Walk.length_support,←Set.ncard_eq_toFinset_card _ hfin] at hc - obtain ⟨l,hl,he,ho⟩ := walk_lift_bonds G ω q.val - have hlen : l.length = q.val.length := by - have hh := congrArg List.length he - simpa only [List.length_map,SimpleGraph.Walk.length_edges] using hh - exact ⟨l,hl,by omega,ho⟩ - - - -theorem Along.last_entrance {G : BondGraph V E} {x y : V} {l : List E} - (hl : Along G x l y) (D : Set V) (hy : y ∈ D) : - (x ∈ D ∧ ∀ e ∈ l, e ∈ internalEdges G D) ∨ - ∃ a b e l₁ l₂, l = l₁ ++ e::l₂ ∧ Along G x l₁ a ∧ G e = s(a,b) ∧ - a ∉ D ∧ b ∈ D ∧ Along G b l₂ y ∧ ∀ d ∈ l₂, d ∈ internalEdges G D := by - induction hl with - | nil => exact Or.inl ⟨hy,by simp⟩ - | @cons x z y l e he ht ih => - rcases ih hy with ⟨hz,hall⟩ | ⟨a,b,d,l₁,l₂,heq,h₁,hd,ha,hb,h₂,hs⟩ - · by_cases hx : x ∈ D - · left - refine ⟨hx,?_⟩ - intro d hd - rcases List.mem_cons.mp hd with rfl | hd - · exact (mem_internalEdges_of_ends G D d x z he).mpr ⟨hx,hz⟩ - · exact hall d hd - · right - exact ⟨x,z,e,[],l,rfl,.nil x,he,hx,hz,ht,hall⟩ - · right - exact ⟨a,b,d,e::l₁,l₂,by simp [heq],.cons e he h₁,hd,ha,hb,h₂,hs⟩ - -end ShortPathsDeletedDomain -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.ScaleBudget + +namespace OAI + +/-! Resampling for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section ContractingIteration + + + +theorem exists_efficient_of_contracting_successor {S : Type*} + (g H : S → ℝ) (C : ℝ) (hC : 0 ≤ C) (hC1 : C < 1) + (hstep : ∀ x, ∃ y, g y ≤ C*g x ∧ 2*H x ≤ H y) + (x₀ : S) (hH₀ : 0 < H x₀) (η R : ℝ) (hη : 0 < η) : + ∃ x, g x < η ∧ R < H x := by + classical + choose f hf using hstep + let x : ℕ → S := fun n => f^[n] x₀ + have hx (n : ℕ) : x (n+1) = f (x n) := Function.iterate_succ_apply' f n x₀ + have hbounds (n : ℕ) : g (x n) ≤ C^n*g x₀ ∧ (2:ℝ)^n*H x₀ ≤ H (x n) := by + induction n with + | zero => simp only [x,Function.iterate_zero,id_eq,pow_zero,one_mul,le_refl,and_self] + | succ n ih => + rw [hx] + obtain ⟨hg,hH⟩ := hf (x n) + constructor + · calc + _ ≤ C*g (x n) := hg + _ ≤ C*(C^n*g x₀) := mul_le_mul_of_nonneg_left ih.1 hC + _ = _ := by rw [pow_succ]; ring + · calc + _ = 2*((2:ℝ)^n*H x₀) := by rw [pow_succ]; ring + _ ≤ 2*H (x n) := mul_le_mul_of_nonneg_left ih.2 (by norm_num) + _ ≤ _ := hH + have hg : Tendsto (fun n : ℕ => C^n*g x₀) atTop (nhds 0) := by + simpa only [zero_mul] using (tendsto_pow_atTop_nhds_zero_of_lt_one hC hC1).mul_const (g x₀) + have hH : Tendsto (fun n : ℕ => (2:ℝ)^n*H x₀) atTop atTop := + (tendsto_pow_atTop_atTop_of_one_lt (by norm_num : (1:ℝ) < 2)).atTop_mul_const hH₀ + obtain ⟨n,hg',hH'⟩ := ((tendsto_order.mp hg).2 η hη |>.and + (hH.eventually (eventually_gt_atTop R))).exists + exact ⟨x n,(hbounds n).1.trans_lt hg',hH'.trans_le (hbounds n).2⟩ + +end ContractingIteration + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section EfficientEndpointProfiles +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem efficient_endpoint_profiles_of_divergent_moment + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law p, (cluster G ω (root i)).Finite) + (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) + (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) + (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : + ∃ i, ∀ η : ℝ, 0 < η → ∀ R : ℝ, + ∃ q : EndpointProfile G hloc p (root i) (1/2+ε), + 2 ≤ q.cap ∧ 1 < q.H ∧ R < q.H ∧ q.U+q.m < η*q.H := by + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,e,he,hx⟩ := hcov x + obtain ⟨b,hb⟩ := hΓ he + exact ⟨i,e,b,hb,hx⟩ + obtain ⟨i,hscales⟩ := orbit_scales_of_divergent_moment G hloc root weight Γ hΓ htr hw hw1 hcover p α β hα hαβ hdiv + obtain ⟨ξ,hξ,hξ1,hC,hC1⟩ := exists_amplification_contraction β (1/2+ε) (by linarith) (by linarith) hsmall + have hsξ : 0 < 1/2+ε+ξ := by linarith + obtain ⟨M₀,hM₀⟩ := eventually_atTop.1 (eventually_inverseCodeMass_budget (1/2+ε) ξ (by linarith) hξ) + obtain ⟨q₀,hq₀,hH₀⟩ := starting_endpoint_profile G hloc hqt hh p hp hp1 root weight Γ hΓ htr + (fun i => (hw i).le) hw1 i (hw i) (hfin i) ε hε hε1 M₀ + obtain ⟨d,_,hdeg⟩ := exists_degree_bound G hqt + let c : ℝ := ∑ j, 1/weight j + have hc : 0 ≤ c := Finset.sum_nonneg (fun j _ => (one_div_pos.mpr (hw j)).le) + have hmin (j : ι) : 1 ≤ c*weight j := by + apply (div_le_iff₀ (hw j)).mp + exact Finset.single_le_sum (fun l _ => (one_div_pos.mpr (hw l)).le) (Finset.mem_univ j) + let S := {q : EndpointProfile G hloc p (root i) (1/2+ε) // M₀ ≤ q.cap ∧ 1 < q.H} + let g : S → ℝ := fun q => q.val.cost ξ/q.val.H + let H : S → ℝ := fun q => q.val.H + have hstep : ∀ q : S, ∃ q' : S, g q' ≤ amplificationContraction β (1/2+ε) ξ*g q ∧ 2*H q ≤ H q' := by + intro q + have hcap := hM₀ q.val.cap q.property.1 + have hH : 0 < q.val.H := lt_trans zero_lt_one q.property.2 + obtain ⟨r,k,hr,hk,hU,hm,hH',hH''⟩ := q.val.amplify_at_scales hconn hqt root weight Γ hΓ htr hcov hw hw1 + c hc hmin i p hp1 d hdeg ε ξ β hε hε1 hξ hξ1 hscales hcap.1 hcap.2.1 hcap.2.2 hH M₀ + have hrH : 1 < r.H := by linarith [q.property.2] + refine ⟨⟨r,hr,hrH⟩,?_,hH''⟩ + exact q.val.cost_contraction r β ξ k hcap.1 hsξ hH hξ1 hk hC hU hm hH' + refine ⟨i,?_⟩ + intro η hη R + let D : ℝ := 1+1/(1/2+ε+ξ) + have hD : 0 < D := by dsimp [D]; positivity + obtain ⟨q,hg,hR⟩ := exists_efficient_of_contracting_successor g H (amplificationContraction β (1/2+ε) ξ) + hC hC1 hstep ⟨q₀,hq₀,hH₀⟩ (lt_trans zero_lt_one hH₀) (η/D) R (div_pos hη hD) + have hcap := (hM₀ q.val.cap q.property.1).1 + refine ⟨q.val,hcap,q.property.2,hR,?_⟩ + have hH : 0 < q.val.H := lt_trans zero_lt_one q.property.2 + have hcost := q.val.total_cost_le hcap ξ hsξ + have hratio : (q.val.U+q.val.m)/q.val.H ≤ D*g q := by + have h := div_le_div_of_nonneg_right hcost hH.le + simpa only [D,g,mul_div_assoc] using h + apply (div_lt_iff₀ hH).mp + apply hratio.trans_lt + have hg' := (lt_div_iff₀ hD).mp hg + simpa only [mul_comm] using hg' + +end EfficientEndpointProfiles + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ShortBoundaryPivotal +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def ShortClosedBoundary (G : BondGraph V E) (ω : Set E) (x z : V) (M : ℕ) (e : E) : Prop := + e ∉ ω ∧ ¬Conn G ω x z ∧ ∃ a b : V, ∃ l : List E, + G e = s(a,b) ∧ Along G x l a ∧ (∀ f ∈ l, f ∈ ω) ∧ l.length < M ∧ Conn G ω b z + +theorem bridgeIndex_le_short_trail (G : BondGraph V E) (ω : Set E) (x z : V) + (hC : (cluster G ω x).Finite) (e : E) (he : OpenMarkedPivotal G ω {z} x e) + (a b : V) (hab : G e = s(a,b)) (l : List E) (hl : Along G x l a) + (ho : ∀ f ∈ l, f ∈ ω) : bridgeIndex G ω x z e ≤ l.length+1 := by + unfold bridgeIndex + have hsub : (separatingBonds G ω x z).filter (fun f => pivotalRank G ω x f ≤ pivotalRank G ω x e) ⊆ + (e::l).toFinset := by + intro f hf + obtain ⟨hf,hfe⟩ := Finset.mem_filter.mp hf + have hfp := (mem_separatingBonds G ω x z f).mp hf + by_cases h : f = e + · subst f; simp + by_contra hnot + have hn : f ∉ l := fun hfl => hnot (List.mem_toFinset.mpr (List.mem_cons_of_mem _ hfl)) + have hlt : pivotalRank G ω x f < pivotalRank G ω x e := by + apply lt_of_le_of_ne hfe + intro heq + exact h (pivotalRank_injective_of_cluster_finite G ω {z} x hC hfp he heq) + have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC hfp he).mp hlt + have hb : ¬ Conn G (ω \ {f}) x b := ((mem_internalEdges_of_ends G _ e a b hab).mp hout).2 + apply hb + have hxa : Conn G (ω \ {f}) x a := hl.conn (fun g hg => ⟨ho g hg,fun hgf => hn ((Set.mem_singleton_iff.mp hgf) ▸ hg)⟩) + exact hxa.tail ⟨e,⟨he.1,fun hEq => h hEq.symm⟩,hab⟩ + exact (Finset.card_le_card hsub).trans (by simpa only [List.length_cons] using List.toFinset_card_le (e::l)) + +theorem ShortClosedBoundary.open_pivotal (G : BondGraph V E) (ω : Set E) (x z : V) + (M : ℕ) (e : E) (h : ShortClosedBoundary G ω x z M e) : + OpenMarkedPivotal G (insert e ω) {z} x e := by + obtain ⟨he,hxz,a,b,l,hab,hl,ho,_,hbz⟩ := h + refine ⟨Set.mem_insert e ω,⟨z,rfl,?_⟩,?_⟩ + · have hxa := hl.conn ho + exact (conn_mono G (Set.subset_insert e ω) hxa).trans + ((Relation.ReflTransGen.single ⟨e,Set.mem_insert e ω,hab⟩).trans + (conn_mono G (Set.subset_insert e ω) hbz)) + · rintro ⟨y,hy,hxy⟩ + have hy' : y = z := Set.mem_singleton_iff.mp hy + subst y + apply hxz + apply conn_mono G _ hxy + intro f hf + rcases hf.1 with hfe | hfω + · exact (hf.2 (Set.mem_singleton_iff.mpr hfe)).elim + · exact hfω + +theorem ShortClosedBoundary.bridgeIndex_le (G : BondGraph V E) (ω : Set E) (x z : V) + (hω : ω.Finite) (M : ℕ) (e : E) (h : ShortClosedBoundary G ω x z M e) : + bridgeIndex G (insert e ω) x z e ≤ M := by + have hpiv := ShortClosedBoundary.open_pivotal G ω x z M e h + obtain ⟨_,_,a,b,l,hab,hl,ho,hlen,_⟩ := h + have hc := cluster_finite_of_finite_edges G (hω.insert e) x + have hb := bridgeIndex_le_short_trail G (insert e ω) x z hc e hpiv + a b hab l hl (fun f hf => Set.mem_insert_of_mem e (ho f hf)) + exact hb.trans (by omega) + +end ShortBoundaryPivotal + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ShortBoundaryCounting +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def firstOpenBridgeCount (G : BondGraph V E) (Q : Finset E) + (x z : V) (M : ℕ) (ω : Finset E) : ℕ := + (Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M)).card + +noncomputable def shortClosedBoundaryCount (G : BondGraph V E) (Q : Finset E) + (x z : V) (M : ℕ) (ω : Finset E) : ℕ := + (Q.filter (ShortClosedBoundary G ω x z M)).card + +theorem firstOpenBridgeCount_le (G : BondGraph V E) (Q : Finset E) + (x z : V) (M : ℕ) (ω : Finset E) : + firstOpenBridgeCount G Q x z M ω ≤ if Conn G ω x z then M else 0 := by + by_cases hc : Conn G ω x z + · rw [ite_eq_left hc] + unfold firstOpenBridgeCount + let S := Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M) + have hm : Set.MapsTo (bridgeIndex G ω x z) (S : Set E) (Finset.Icc 1 M) := by + intro e he + have he' := (Finset.mem_filter.mp he).2 + exact Finset.mem_Icc.mpr ⟨bridgeIndex_pos G ω x z he'.1,he'.2⟩ + have hi : Set.InjOn (bridgeIndex G ω x z) (S : Set E) := by + intro e he f hf h + exact bridgeIndex_injective G ω x z (cluster_finite_of_finite_edges G ω.finite_toSet x) + (Finset.mem_filter.mp he).2.1 (Finset.mem_filter.mp hf).2.1 h + simpa only [Nat.card_Icc,Nat.add_sub_cancel] using + (Finset.card_le_card_of_injOn (bridgeIndex G ω x z) hm hi) + · rw [ite_eq_right hc] + unfold firstOpenBridgeCount + have he : Q.filter (fun e => OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M) = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro e he + obtain ⟨y,hy,hxy⟩ := (Finset.mem_filter.mp he).2.1.2.1 + exact hc ((Set.mem_singleton_iff.mp hy) ▸ hxy) + rw [he,Finset.card_empty] + +theorem bernoulliPolynomial_bit_balance (Q : Finset E) (e : E) (he : e ∈ Q) + (f : Finset E → ℝ) (p : ℝ) : + p*bernoulliPolynomial Q (fun ω => if e ∉ ω then f ω else 0) p = + (1-p)*bernoulliPolynomial Q (fun ω => if e ∈ ω then f (ω.erase e) else 0) p := by + conv_lhs => rw [←Finset.insert_erase he] + conv_rhs => rw [←Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q), + bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] + have hc : bernoulliPolynomial (Q.erase e) (fun ω => if e ∉ ω then f ω else 0) p = + bernoulliPolynomial (Q.erase e) f p := by + apply bernoulliPolynomial_congr + intro ω hω + simp only [show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),not_false_eq_true,ite_true] + have hco : bernoulliPolynomial (Q.erase e) (fun ω => if e ∉ insert e ω then f (insert e ω) else 0) p = 0 := by + simp only [Finset.mem_insert_self,not_true_eq_false,ite_false,bernoulliPolynomial_zero] + have ho : bernoulliPolynomial (Q.erase e) (fun ω => if e ∈ ω then f (ω.erase e) else 0) p = 0 := by + calc + _ = bernoulliPolynomial (Q.erase e) (fun _ => 0) p := by + apply bernoulliPolynomial_congr + intro ω hω + simp only [show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),ite_false] + _ = 0 := bernoulliPolynomial_zero _ _ + have hoo : bernoulliPolynomial (Q.erase e) + (fun ω => if e ∈ insert e ω then f ((insert e ω).erase e) else 0) p = + bernoulliPolynomial (Q.erase e) f p := by + apply bernoulliPolynomial_congr + intro ω hω + simp only [Finset.mem_insert_self,ite_true,Finset.erase_insert + (show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h))] + rw [hc,hco,ho,hoo] + ring + +end ShortBoundaryCounting + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ShortBoundaryExpectation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem bernoulliPolynomial_closed_count_balance (Q : Finset E) + (P : Finset E → E → Prop) (hP : ∀ ω e, P ω e → e ∉ ω) (p : ℝ) : + p*bernoulliPolynomial Q (fun ω => ((Q.filter (P ω)).card:ℝ)) p = + (1-p)*bernoulliPolynomial Q + (fun ω => ((Q.filter (fun e => e ∈ ω ∧ P (ω.erase e) e)).card:ℝ)) p := by + have hbal (e : E) (he : e ∈ Q) : + p*bernoulliPolynomial Q (fun ω => if P ω e then 1 else 0) p = + (1-p)*bernoulliPolynomial Q (fun ω => if e ∈ ω ∧ P (ω.erase e) e then 1 else 0) p := by + have h := bernoulliPolynomial_bit_balance Q e he (fun ω => if P ω e then 1 else 0) p + have hL : bernoulliPolynomial Q (fun ω => if e ∉ ω then (if P ω e then 1 else 0) else 0) p = + bernoulliPolynomial Q (fun ω => if P ω e then 1 else 0) p := by + apply bernoulliPolynomial_congr + intro ω _ + by_cases hp : P ω e + · simp only [hp,hP ω e hp,not_false_eq_true,ite_true] + · simp only [hp,ite_false,ite_self] + have hR : bernoulliPolynomial Q (fun ω => if e ∈ ω then (if P (ω.erase e) e then 1 else 0) else 0) p = + bernoulliPolynomial Q (fun ω => if e ∈ ω ∧ P (ω.erase e) e then 1 else 0) p := by + apply bernoulliPolynomial_congr + intro ω _ + by_cases hm : e ∈ ω <;> simp only [hm,true_and,false_and,ite_true,ite_false] + rw [hL,hR] at h + exact h + simp only [Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero, + bernoulliPolynomial_sum,Finset.mul_sum] + exact Finset.sum_congr rfl (fun e he => hbal e he) + +theorem shortClosedBoundary_erase_first (G : BondGraph V E) (ω : Finset E) + (x z : V) (M : ℕ) (e : E) (he : e ∈ ω) + (h : ShortClosedBoundary G (ω.erase e) x z M e) : + OpenMarkedPivotal G ω {z} x e ∧ bridgeIndex G ω x z e ≤ M := by + have h₁ := ShortClosedBoundary.open_pivotal G (ω.erase e) x z M e h + have h₂ := ShortClosedBoundary.bridgeIndex_le G (ω.erase e) x z (ω.erase e).finite_toSet M e h + rw [←Finset.coe_insert,Finset.insert_erase he] at h₁ h₂ + exact ⟨h₁,h₂⟩ + +theorem shortRecoveredBoundaryCount_le (G : BondGraph V E) (Q ω : Finset E) + (x z : V) (M : ℕ) : + (Q.filter (fun e => e ∈ ω ∧ ShortClosedBoundary G (ω.erase e) x z M e)).card ≤ + if Conn G ω x z then M else 0 := by + apply le_trans _ (firstOpenBridgeCount_le G Q x z M ω) + apply Finset.card_le_card + intro e he + obtain ⟨heQ,heω,hb⟩ := Finset.mem_filter.mp he + exact Finset.mem_filter.mpr ⟨heQ,shortClosedBoundary_erase_first G ω x z M e heω hb⟩ + + + +theorem finite_short_boundary_expectation (G : BondGraph V E) (Q : Finset E) + (x z : V) (M : ℕ) (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : + bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p ≤ + ((1-p)/p)*M*bernoulliPolynomial Q (fun ω => if Conn G ω x z then 1 else 0) p := by + have hbal := bernoulliPolynomial_closed_count_balance Q + (fun ω e => ShortClosedBoundary G ω x z M e) (fun ω e h => h.1) p + have hmono := bernoulliPolynomial_mono Q + (fun ω => ((Q.filter (fun e => e ∈ ω ∧ ShortClosedBoundary G (ω.erase e) x z M e)).card:ℝ)) + (fun ω => (M:ℝ)*(if Conn G ω x z then 1 else 0)) p ⟨hp.le,hp1⟩ (by + intro ω _ + have h := shortRecoveredBoundaryCount_le G Q ω x z M + by_cases hc : Conn G ω x z + · simp only [hc,ite_true,mul_one] at * + exact_mod_cast h + · simp only [hc,ite_false,mul_zero] at * + exact_mod_cast h) + rw [bernoulliPolynomial_const_mul] at hmono + have hbound := mul_le_mul_of_nonneg_left hmono (sub_nonneg.mpr hp1) + rw [←hbal] at hbound + change p*bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p ≤ _ at hbound + have hdiv := (le_div_iff₀ hp).mpr (show + bernoulliPolynomial Q (fun ω => (shortClosedBoundaryCount G Q x z M ω:ℝ)) p*p ≤ _ by + simpa only [mul_comm p] using hbound) + simpa only [div_eq_mul_inv,mul_assoc,mul_left_comm,mul_comm] using hdiv + +end ShortBoundaryExpectation + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ClusterResampling +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem bernoulliPolynomial_commute {F : Type*} (Q : Finset E) (R : Finset F) + (f : Finset E → Finset F → ℝ) (p q : ℝ) : + bernoulliPolynomial Q (fun a => bernoulliPolynomial R (f a) q) p = + bernoulliPolynomial R (fun b => bernoulliPolynomial Q (fun a => f a b) p) q := by + simp only [bernoulliPolynomial,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +theorem exteriorBonds_union_blocks (G : BondGraph V E) (Q : Finset E) + (W : Set V) (a b : Finset E) (ha : a ⊆ Q \ exteriorBonds G Q W) + (hb : b ⊆ exteriorBonds G Q W) : exteriorBonds G (a ∪ b) W = b := by + ext e + simp only [exteriorBonds,Finset.mem_filter,Finset.mem_union] + constructor + · rintro ⟨he,heW⟩ + rcases he with he | he + · obtain ⟨heQ,heR⟩ := Finset.mem_sdiff.mp (ha he) + exact (heR (Finset.mem_filter.mpr ⟨heQ,heW⟩)).elim + · exact he + · intro he + exact ⟨Or.inr he,(Finset.mem_filter.mp (hb he)).2⟩ + + +theorem cluster_cell_exterior_factor (G : BondGraph V E) (Q : Finset E) + (x : V) (W : Set V) (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial Q (fun ω => + (if cluster G ω x = W then (1:ℝ) else 0)*f (exteriorBonds G ω W)) p = + bernoulliPolynomial (Q \ exteriorBonds G Q W) + (fun a => if cluster G a x = W then (1:ℝ) else 0) p * + bernoulliPolynomial (exteriorBonds G Q W) f p := by + let R := exteriorBonds G Q W + let A := Q \ R + have hQ : A ∪ R = Q := Finset.sdiff_union_of_subset (Finset.filter_subset _ _) + conv_lhs => rw [←hQ,bernoulliPolynomial_union A R Finset.sdiff_disjoint] + trans bernoulliPolynomial A (fun a => + (if cluster G a x = W then (1:ℝ) else 0)*bernoulliPolynomial R f p) p + · apply bernoulliPolynomial_congr + intro a ha + rw [←bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro b hb + have hc := cluster_union_external_eq_iff G (a:Set E) b x W + (fun e he => (Finset.mem_filter.mp (hb he)).2) + rw [exteriorBonds_union_blocks G Q W a b ha hb] + simp only [Finset.coe_union,hc] + · exact bernoulliPolynomial_mul_const A _ _ p + +theorem cluster_cell_incident_probability (G : BondGraph V E) (Q : Finset E) + (x : V) (W : Set V) (p : ℝ) : + bernoulliPolynomial Q (fun ω => if cluster G ω x = W then (1:ℝ) else 0) p = + bernoulliPolynomial (Q \ exteriorBonds G Q W) + (fun a => if cluster G a x = W then (1:ℝ) else 0) p := by + have h := cluster_cell_exterior_factor G Q x W (fun _ => 1) p + simpa only [mul_one,bernoulliPolynomial_const] using h + +noncomputable def resampleClusterAt (G : BondGraph V E) (Q : Finset E) + (W : Set V) (ω η : Finset E) : Finset E := + exteriorBonds G ω W ∪ (η ∩ (Q \ exteriorBonds G Q W)) + + + +theorem cluster_resample_cell_independent (G : BondGraph V E) (Q : Finset E) + (x : V) (W : Set V) (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => + (if cluster G ω x = W then (1:ℝ) else 0)*f (resampleClusterAt G Q W ω η)) p) p = + bernoulliPolynomial Q (fun ω => if cluster G ω x = W then (1:ℝ) else 0) p * + bernoulliPolynomial Q f p := by + let R := exteriorBonds G Q W + let A := Q \ R + let c := bernoulliPolynomial A (fun a => if cluster G a x = W then (1:ℝ) else 0) p + rw [bernoulliPolynomial_commute] + trans bernoulliPolynomial Q (fun η => c * bernoulliPolynomial R + (fun b => f (b ∪ (η ∩ A))) p) p + · apply bernoulliPolynomial_congr + intro η _ + exact cluster_cell_exterior_factor G Q x W (fun b => f (b ∪ (η ∩ A))) p + · rw [bernoulliPolynomial_const_mul,bernoulliPolynomial_restrict A Q Finset.sdiff_subset + (fun a => bernoulliPolynomial R (fun b => f (b ∪ a)) p) p, + bernoulliPolynomial_commute] + have hQ : R ∪ A = Q := Finset.union_sdiff_of_subset (Finset.filter_subset _ _) + rw [←bernoulliPolynomial_union R A Finset.disjoint_sdiff,hQ, + cluster_cell_incident_probability G Q x W p] + +end ClusterResampling +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ResampledBoundary +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem resampleClusterAt_subset (G : BondGraph V E) (Q : Finset E) + (W : Set V) (ω η : Finset E) (hω : ω ⊆ Q) : + resampleClusterAt G Q W ω η ⊆ Q := by + intro e he + rcases Finset.mem_union.mp he with he | he + · exact hω (Finset.mem_filter.mp he).1 + · exact (Finset.mem_sdiff.mp (Finset.mem_inter.mp he).2).1 + +theorem resampleClusterAt_external (G : BondGraph V E) (Q : Finset E) + (W : Set V) (ω η : Finset E) {e : E} (he : e ∈ resampleClusterAt G Q W ω η) + (heW : e ∈ internalEdges G Wᶜ) : e ∈ ω := by + rcases Finset.mem_union.mp he with he | he + · exact (Finset.mem_filter.mp he).1 + · obtain ⟨_,heA⟩ := Finset.mem_inter.mp he + obtain ⟨heQ,heR⟩ := Finset.mem_sdiff.mp heA + exact (heR (Finset.mem_filter.mpr ⟨heQ,heW⟩)).elim + + + +theorem resampled_path_boundary (G : BondGraph V E) (Q ω η : Finset E) + (hω : ω ⊆ Q) (x z y : V) (M : ℕ) + (hy : Conn G ω z y) (hx : ¬Conn G ω x z) + (l : List E) (hl : Along G x l y) (hlen : l.length ≤ M) + (ho : ∀ e ∈ l, e ∈ resampleClusterAt G Q (cluster G ω z) ω η) : + ∃ e ∈ Q, ShortClosedBoundary G ω x z M e := by + let W := cluster G ω z + have hxW : x ∉ W := fun h => hx (conn_symm G ω h) + rcases hl.first_outside (internalEdges G Wᶜ) with hall | ⟨a,b,e,l₁,l₂,heq,h₁,hab,_,hfirst,hen⟩ + · have hc : Conn G ((Set.univ:Set E) ∩ internalEdges G Wᶜ) x y := + hl.conn (fun e he => ⟨Set.mem_univ e,hall e he⟩) + exact ((conn_internal_endpoint G Wᶜ hxW hc) hy).elim + · subst l + have heopen := ho e (List.mem_append_right _ (by simp)) + have heQ := resampleClusterAt_subset G Q W ω η hω heopen + have hprefix : ∀ f ∈ l₁, f ∈ ω := by + intro f hf + exact resampleClusterAt_external G Q W ω η + (ho f (List.mem_append_left _ hf)) (hfirst f hf) + have hxa : Conn G ((ω:Set E) ∩ internalEdges G Wᶜ) x a := + h₁.conn (fun f hf => ⟨hprefix f hf,hfirst f hf⟩) + have haW : a ∉ W := conn_internal_endpoint G Wᶜ hxW hxa + have hbW : b ∈ W := by + by_contra hbW + exact hen ((mem_internalEdges_of_ends G Wᶜ e a b hab).mpr ⟨haW,hbW⟩) + have heclosed : e ∉ ω := by + intro heω + apply haW + exact (show Conn G ω z b from hbW).tail ⟨e,heω,hab.trans (Sym2.eq_swap ..)⟩ + refine ⟨e,heQ,heclosed,hx,a,b,l₁,hab,h₁,hprefix,?_,conn_symm G ω hbW⟩ + simp only [List.length_append,List.length_cons] at hlen + omega + +noncomputable def resampleRootCluster (G : BondGraph V E) (Q : Finset E) + (z : V) (ω η : Finset E) : Finset E := + resampleClusterAt G Q (cluster G ω z) ω η + + +theorem resampled_hit_le_boundaryCount (G : BondGraph V E) (Q ω η : Finset E) + (hω : ω ⊆ Q) (x z y : V) (M : ℕ) + (hpath : ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ + ∀ e ∈ l, e ∈ resampleRootCluster G Q z ω η) : + (if Conn G ω z y then (1:ℝ) else 0) ≤ + (if Conn G ω x z then (1:ℝ) else 0) + shortClosedBoundaryCount G Q x z M ω := by + by_cases hy : Conn G ω z y + · rw [ite_eq_left hy] + by_cases hx : Conn G ω x z + · rw [ite_eq_left hx] + exact le_add_of_nonneg_right (Nat.cast_nonneg _) + · rw [ite_eq_right hx,zero_add] + obtain ⟨l,hl,hlen,ho⟩ := hpath + obtain ⟨e,heQ,he⟩ := resampled_path_boundary G Q ω η hω x z y M hy hx l hl hlen ho + have hpos : 0 < shortClosedBoundaryCount G Q x z M ω := + Finset.card_pos.mpr ⟨e,Finset.mem_filter.mpr ⟨heQ,he⟩⟩ + exact_mod_cast hpos + · rw [ite_eq_right hy] + positivity + +end ResampledBoundary +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RootResamplingLaw +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem rootCluster_resampling_law (G : BondGraph V E) (Q : Finset E) + (x : V) (f : Finset V → Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q + (fun η => f (finiteRootComponent G ω x) (resampleRootCluster G Q x ω η)) p) p = + bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q + (f (finiteRootComponent G ω x)) p) p := by + let F := insert x (searchVertices G Q) + let c := fun (W : Finset V) (ω : Finset E) => if cluster G ω x = (W:Set V) then (1:ℝ) else 0 + have hpart (ω η : Finset E) (hω : ω ⊆ Q) : + f (finiteRootComponent G ω x) (resampleRootCluster G Q x ω η) = + ∑ W ∈ F.powerset, c W ω * f W (resampleClusterAt G Q W ω η) := by + have h := sum_component_partition G Q F x ω hω (by rfl) + (fun W => f W (resampleClusterAt G Q W ω η)) + simpa only [c,ite_mul,one_mul,zero_mul,coe_finiteRootComponent, + resampleRootCluster] using h.symm + trans ∑ W ∈ F.powerset, + bernoulliPolynomial Q (c W) p * bernoulliPolynomial Q (f W) p + · trans bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => + ∑ W ∈ F.powerset, c W ω * f W (resampleClusterAt G Q W ω η)) p) p + · apply bernoulliPolynomial_congr + intro ω hω + apply bernoulliPolynomial_congr + intro η _ + exact hpart ω η hω + · simp only [bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro W _ + exact cluster_resample_cell_independent G Q x W (f W) p + · trans bernoulliPolynomial Q (fun ω => ∑ W ∈ F.powerset, + c W ω * bernoulliPolynomial Q (f W) p) p + · rw [bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro W _ + exact (bernoulliPolynomial_mul_const Q (c W) _ p).symm + · apply bernoulliPolynomial_congr + intro ω hω + have h := sum_component_partition G Q F x ω hω (by rfl) + (fun W => bernoulliPolynomial Q (f W) p) + simpa only [c,ite_mul,one_mul,zero_mul] using h + +end RootResamplingLaw +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteMaximalSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteSusceptibility (G : BondGraph V E) (Q : Finset E) + (F : Finset V) (p : ℝ) (x : V) : ℝ := + ∑ z ∈ F, bernoulliPolynomial Q (fun ω => if Conn G ω x z then (1:ℝ) else 0) p + +theorem finiteSusceptibility_nonneg (G : BondGraph V E) (Q : Finset E) + (F : Finset V) (p : ℝ) (x : V) (hp : p ∈ Set.Icc (0:ℝ) 1) : + 0 ≤ finiteSusceptibility G Q F p x := by + apply Finset.sum_nonneg + intro z _ + exact bernoulliPolynomial_nonneg Q _ p hp (fun _ _ => by positivity) + +theorem rootCluster_resampled_selector (G : BondGraph V E) (Q : Finset E) + (w : V) (Z : Finset E → V) (p : ℝ) : + bernoulliPolynomial Q (fun ω => bernoulliPolynomial Q (fun η => + if Conn G ω w (Z (resampleRootCluster G Q w ω η)) then (1:ℝ) else 0) p) p = + bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => + if Conn G ω w (Z η) then (1:ℝ) else 0) p) p := by + have hm (ω : Finset E) (y : V) : + y ∈ finiteRootComponent G ω w ↔ Conn G ω w y := by + change y ∈ (finiteRootComponent G ω w : Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + have h := rootCluster_resampling_law G Q w (fun W η => if Z η ∈ W then (1:ℝ) else 0) p + simp only [hm] at h + exact h.trans (bernoulliPolynomial_commute Q Q _ p p) + +theorem finite_selector_connection_bound (G : BondGraph V E) (Q : Finset E) + (x w : V) (M : ℕ) (Z : Finset E → V) + (hZ : ∀ η ⊆ Q, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) + (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : + bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => + if Conn G ω w (Z η) then (1:ℝ) else 0) p) p ≤ + (1+(1-p)/p*M)*bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p := by + rw [←rootCluster_resampled_selector G Q w Z p] + have hmono := bernoulliPolynomial_mono Q + (fun ω => bernoulliPolynomial Q (fun η => + if Conn G ω w (Z (resampleRootCluster G Q w ω η)) then (1:ℝ) else 0) p) + (fun ω => (if Conn G ω x w then (1:ℝ) else 0)+shortClosedBoundaryCount G Q x w M ω) + p ⟨hp.le,hp1⟩ (by + intro ω hω + calc + _ ≤ bernoulliPolynomial Q (fun _ => + (if Conn G ω x w then (1:ℝ) else 0)+shortClosedBoundaryCount G Q x w M ω) p := by + apply bernoulliPolynomial_mono Q _ _ p ⟨hp.le,hp1⟩ + intro η _ + exact resampled_hit_le_boundaryCount G Q ω η hω x w _ M + (hZ _ (resampleClusterAt_subset G Q _ ω η hω)) + _ = _ := bernoulliPolynomial_const Q _ p) + rw [bernoulliPolynomial_add] at hmono + have hb := finite_short_boundary_expectation G Q x w M p hp hp1 + calc + _ ≤ _ := hmono + _ ≤ bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p + + ((1-p)/p)*M*bernoulliPolynomial Q (fun ω => if Conn G ω x w then (1:ℝ) else 0) p := + add_le_add le_rfl hb + _ = _ := by ring + + + +theorem finite_selected_susceptibility_bound (G : BondGraph V E) (Q : Finset E) + (F : Finset V) (x : V) (M : ℕ) (Z : Finset E → V) + (hZ : ∀ η ⊆ Q, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) + (p : ℝ) (hp : 0 < p) (hp1 : p ≤ 1) : + bernoulliPolynomial Q (fun η => finiteSusceptibility G Q F p (Z η)) p ≤ + (1+(1-p)/p*M)*finiteSusceptibility G Q F p x := by + unfold finiteSusceptibility + rw [bernoulliPolynomial_sum,Finset.mul_sum] + apply Finset.sum_le_sum + intro w _ + have h := finite_selector_connection_bound G Q x w M Z hZ p hp hp1 + calc + _ = bernoulliPolynomial Q (fun η => bernoulliPolynomial Q (fun ω => + if Conn G ω w (Z η) then (1:ℝ) else 0) p) p := by + apply bernoulliPolynomial_congr + intro η _ + apply bernoulliPolynomial_congr + intro ω _ + apply if_congr _ rfl rfl + exact ⟨conn_symm G ω,conn_symm G ω⟩ + _ ≤ _ := h + +end FiniteMaximalSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section RestrictedConnectionLimit +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem tendsto_bernoulliPolynomial {ι : Type*} {l : Filter ι} + (Q : Finset E) (f : ι → Finset E → ℝ) (g : Finset E → ℝ) (p : ℝ) + (h : ∀ a ⊆ Q, Tendsto (fun i => f i a) l (𝓝 (g a))) : + Tendsto (fun i => bernoulliPolynomial Q (f i) p) l + (𝓝 (bernoulliPolynomial Q g p)) := by + unfold bernoulliPolynomial + exact tendsto_finsetSum _ (fun a ha => + ((h a (Finset.mem_powerset.mp ha)).mul_const _).mul_const _) + +theorem conn_finite_exhaustion (G : BondGraph V E) (S : Set E) + (Q : ℕ → Finset E) (hQ : Monotone Q) (hcover : ∀ e ∈ S, ∃ n, e ∈ Q n) + {ω : Set E} {x y : V} (h : Conn G (ω ∩ S) x y) : + ∃ n, Conn G (ω ∩ (Q n : Set E)) x y := by + induction h with + | refl => exact ⟨0,conn_refl _ _ _⟩ + | @tail a b hxa hab ih => + obtain ⟨n,hn⟩ := ih + obtain ⟨e,he,hab⟩ := hab + obtain ⟨m,hm⟩ := hcover e he.2 + refine ⟨max n m,?_⟩ + exact (conn_mono G (Set.inter_subset_inter_right _ + (show (Q n:Set E) ⊆ (Q (max n m):Set E) from hQ (le_max_left n m))) hn).tail + ⟨e,⟨he.1,hQ (le_max_right n m) hm⟩,hab⟩ + +theorem finite_connection_polynomial_tendsto (G : BondGraph V E) (S : Set E) + (Q : ℕ → Finset E) (hQ : Monotone Q) (hsub : ∀ n, (Q n:Set E) ⊆ S) + (hcover : ∀ e ∈ S, ∃ n, e ∈ Q n) (p : unitInterval) (x y : V) : + Tendsto (fun n => bernoulliPolynomial (Q n) (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) + atTop (𝓝 ((law p).real {ω | Conn G (ω ∩ S) x y})) := by + have he (n : ℕ) : bernoulliPolynomial (Q n) (fun ω => if Conn G ω x y then (1:ℝ) else 0) p = + (law p).real {ω | Conn G (ω ∩ (Q n:Set E)) x y} := + finiteEventPolynomial_restrict (Q n) {ω | Conn G ω x y} p + simp_rw [he] + have hm : Monotone (fun n => {ω : Set E | Conn G (ω ∩ (Q n:Set E)) x y}) := by + intro m n h ω hc + exact conn_mono G (Set.inter_subset_inter_right _ (show (Q m:Set E) ⊆ (Q n:Set E) from hQ h)) hc + have hu : (⋃ n, {ω : Set E | Conn G (ω ∩ (Q n:Set E)) x y}) = + {ω : Set E | Conn G (ω ∩ S) x y} := by + ext ω + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] + exact ⟨fun ⟨n,hn⟩ => conn_mono G (Set.inter_subset_inter_right _ (hsub n)) hn, + conn_finite_exhaustion G S Q hQ hcover⟩ + have ht := tendsto_measure_iUnion_atTop (μ := law p) hm + rw [hu] at ht + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht + +noncomputable def restrictedBondExhaustion [Encodable E] (S : Set E) (K : Finset E) + (n : ℕ) : Finset E := K ∪ (vertexExhaustion (V := E) n).filter (· ∈ S) + +theorem restrictedBondExhaustion_mono [Encodable E] (S : Set E) (K : Finset E) : + Monotone (restrictedBondExhaustion S K) := by + intro m n h + exact Finset.union_subset_union (by rfl) (Finset.filter_subset_filter _ (vertexExhaustion_mono h)) + +theorem restrictedBondExhaustion_cover [Encodable E] (S : Set E) (K : Finset E) + (e : E) (he : e ∈ S) : ∃ n, e ∈ restrictedBondExhaustion S K n := by + obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e}:Finset E) + exact ⟨n,Finset.mem_union_right _ (Finset.mem_filter.mpr ⟨hn (by simp),he⟩)⟩ + +theorem restrictedBondExhaustion_subset [Encodable E] (S : Set E) (K : Finset E) + (hK : (K:Set E) ⊆ S) (n : ℕ) : (restrictedBondExhaustion S K n:Set E) ⊆ S := by + intro e he + rcases Finset.mem_union.mp he with he | he + · exact hK he + · exact (Finset.mem_filter.mp he).2 + +end RestrictedConnectionLimit +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section RestrictedSelectorBound +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem restricted_selector_connection_bound [Countable E] (G : BondGraph V E) + (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) + (x w : V) (M : ℕ) (Z : Finset E → V) + (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) + (p : unitInterval) (hp : 0 < (p:ℝ)) : + bernoulliPolynomial K (fun η => (law p).real {ω | Conn G (ω ∩ S) w (Z η)}) p ≤ + (1+(1-(p:ℝ))/p*M)*(law p).real {ω | Conn G (ω ∩ S) x w} := by + let := Encodable.ofCountable E + let Q := restrictedBondExhaustion S K + have hlim (a b : V) := finite_connection_polynomial_tendsto G S Q + (restrictedBondExhaustion_mono S K) (restrictedBondExhaustion_subset S K hK) + (restrictedBondExhaustion_cover S K) p a b + have hleft := tendsto_bernoulliPolynomial K + (fun n η => bernoulliPolynomial (Q n) (fun ω => if Conn G ω w (Z η) then (1:ℝ) else 0) p) + (fun η => (law p).real {ω | Conn G (ω ∩ S) w (Z η)}) p (fun η _ => hlim w (Z η)) + have hright := (hlim x w).const_mul (1+(1-(p:ℝ))/p*M) + apply le_of_tendsto_of_tendsto hleft hright + apply Eventually.of_forall + intro n + have hZQ : ∀ η ⊆ Q n, ∃ l : List E, Along G x l (Z (η ∩ K)) ∧ + l.length ≤ M ∧ ∀ e ∈ l, e ∈ η := by + intro η _ + obtain ⟨l,hl,hlen,ho⟩ := hZ (η ∩ K) Finset.inter_subset_right + exact ⟨l,hl,hlen,fun e he => (Finset.mem_inter.mp (ho e he)).1⟩ + have h := finite_selector_connection_bound G (Q n) x w M (fun η => Z (η ∩ K)) hZQ p hp p.2.2 + rw [bernoulliPolynomial_restrict K (Q n) Finset.subset_union_left + (fun η => bernoulliPolynomial (Q n) (fun ω => if Conn G ω w (Z η) then (1:ℝ) else 0) p) p] at h + exact h + +noncomputable def restrictedSusceptibility (G : BondGraph V E) (S : Set E) + (p : unitInterval) (x : V) : ℝ := + ∑' y, (law p).real {ω | Conn G (ω ∩ S) x y} + +theorem restrictedTwoPoint_le (G : BondGraph V E) (S : Set E) + (p : unitInterval) (x y : V) : + (law p).real {ω | Conn G (ω ∩ S) x y} ≤ twoPoint G p x y := by + exact measureReal_mono (fun _ h => conn_mono G Set.inter_subset_left h) + +theorem summable_restrictedTwoPoint [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (S : Set E) (x : V) : + Summable (fun y => (law p).real {ω | Conn G (ω ∩ S) x y}) := by + obtain ⟨C,_,hC⟩ := subcritical_row_bound G hloc hqt p hp + apply summable_of_sum_le (fun _ => measureReal_nonneg) + intro F + exact (Finset.sum_le_sum (fun y _ => restrictedTwoPoint_le G S p x y)).trans (hC x F) + +end RestrictedSelectorBound +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section SelectorSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem summable_bernoulliPolynomial {A : Type*} (K : Finset E) + (f : Finset E → A → ℝ) (p : ℝ) (hf : ∀ η ⊆ K, Summable (f η)) : + Summable (fun y => bernoulliPolynomial K (fun η => f η y) p) := by + unfold bernoulliPolynomial + apply summable_sum + intro η hη + exact ((hf η (Finset.mem_powerset.mp hη)).mul_right _).mul_right _ + +theorem bernoulliPolynomial_tsum {A : Type*} (K : Finset E) + (f : Finset E → A → ℝ) (p : ℝ) (hf : ∀ η ⊆ K, Summable (f η)) : + bernoulliPolynomial K (fun η => ∑' y, f η y) p = + ∑' y, bernoulliPolynomial K (fun η => f η y) p := by + unfold bernoulliPolynomial + rw [Summable.tsum_finsetSum (fun η hη => + ((hf η (Finset.mem_powerset.mp hη)).mul_right _).mul_right _)] + apply Finset.sum_congr rfl + intro η _ + rw [tsum_mul_right,tsum_mul_right] + +theorem restrictedTwoPoint_symm (G : BondGraph V E) (S : Set E) + (p : unitInterval) (x y : V) : + (law p).real {ω | Conn G (ω ∩ S) x y} = + (law p).real {ω | Conn G (ω ∩ S) y x} := by + congr 1 + ext ω + exact ⟨conn_symm G _,conn_symm G _⟩ + + + +theorem restricted_selected_susceptibility_bound [Countable E] (G : BondGraph V E) + (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) + (x : V) (M : ℕ) (Z : Finset E → V) + (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) + (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) y z})) : + bernoulliPolynomial K (fun η => restrictedSusceptibility G S p (Z η)) p ≤ + (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := by + unfold restrictedSusceptibility + rw [bernoulliPolynomial_tsum K _ p (fun η _ => hfin (Z η)),←tsum_mul_left] + apply Summable.tsum_le_tsum _ (summable_bernoulliPolynomial K _ p (fun η _ => hfin (Z η))) + ((hfin x).mul_left _) + intro w + have h := restricted_selector_connection_bound G S K hK x w M Z hZ p hp + simpa only [restrictedTwoPoint_symm G S p (Z _) w] using h + + + +theorem subcritical_selected_susceptibility_bound + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (S : Set E) (K : Finset E) (hK : (K:Set E) ⊆ S) + (x : V) (M : ℕ) (Z : Finset E → V) + (hZ : ∀ η ⊆ K, ∃ l : List E, Along G x l (Z η) ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ η) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) : + bernoulliPolynomial K (fun η => restrictedSusceptibility G S p (Z η)) p ≤ + (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := + restricted_selected_susceptibility_bound G S K hK x M Z hZ p hp + (summable_restrictedTwoPoint G hloc hqt p hpc S) + +end SelectorSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section IntrinsicBall +attribute [local instance] Classical.propDecidable Classical.decEq + + +def intrinsicBall (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : Set V := + {y | ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ ω} + +theorem mem_intrinsicBall_self (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : + x ∈ intrinsicBall G ω x M := ⟨[],.nil x,Nat.zero_le _,by simp⟩ + +theorem intrinsicBall_subset_reachBall (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) : + intrinsicBall G ω x M ⊆ reachBall G x M := by + rintro y ⟨l,hl,hlen,_⟩ + exact reachBall_mono G x hlen hl.mem_reachBall + +theorem intrinsicBall_mono (G : BondGraph V E) {ω η : Set E} (h : ω ⊆ η) (x : V) (M : ℕ) : + intrinsicBall G ω x M ⊆ intrinsicBall G η x M := by + rintro y ⟨l,hl,hlen,ho⟩ + exact ⟨l,hl,hlen,fun e he => h (ho e he)⟩ + +theorem Along.bonds_in_incidentBall {G : BondGraph V E} (hloc : LocallyFinite G) + {x y : V} {l : List E} (h : Along G x l y) (M : ℕ) (hlen : l.length ≤ M) : + ∀ e ∈ l, e ∈ incidentSupport G hloc (finite_reachBall hloc x M).toFinset := by + rcases h.first_outside (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) + with h | ⟨a,b,e,l₁,l₂,heq,h₁,he,_,_,hnot⟩ + · exact h + · exfalso + apply hnot + apply (mem_incidentSupport G hloc _ e).mpr + refine ⟨a,?_,by simp [he]⟩ + apply (finite_reachBall hloc x M).mem_toFinset.mpr + apply reachBall_mono G x (show l₁.length ≤ M by subst l; simp only [List.length_append,List.length_cons] at hlen; omega) + exact h₁.mem_reachBall + +theorem intrinsicBall_restrict (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) : + intrinsicBall G (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E)) x M = + intrinsicBall G ω x M := by + apply Set.Subset.antisymm (intrinsicBall_mono G Set.inter_subset_left x M) + rintro y ⟨l,hl,hlen,ho⟩ + exact ⟨l,hl,hlen,fun e he => ⟨ho e he,hl.bonds_in_incidentBall hloc M hlen e he⟩⟩ + +theorem integral_eq_bernoulliPolynomial (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (Q:Set E))) : + (∫ ω, f ω ∂law p) = bernoulliPolynomial Q (fun η => f η) p := by + rw [integral_finite_local Q p f hf] + simp only [finiteFieldWeight,finiteFieldSet] + rw [Finset.sum_coe_sort Q.powerset (fun η => bernoulliWeight Q η p * f η)] + unfold bernoulliPolynomial + apply Finset.sum_congr rfl + intro η _ + unfold bernoulliWeight + ring + +end IntrinsicBall +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section IntrinsicMaximum +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem intrinsicBall_exists_max (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : + ∃ z ∈ intrinsicBall G ω x M, ∀ y ∈ intrinsicBall G ω x M, f y ≤ f z := + Set.exists_max_image _ f ((finite_reachBall hloc x M).subset + (intrinsicBall_subset_reachBall G ω x M)) ⟨x,mem_intrinsicBall_self G ω x M⟩ + +noncomputable def intrinsicMaximizer (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : V := + Classical.choose (intrinsicBall_exists_max G hloc ω x M f) + +theorem intrinsicMaximizer_spec (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : + intrinsicMaximizer G hloc ω x M f ∈ intrinsicBall G ω x M ∧ + ∀ y ∈ intrinsicBall G ω x M, f y ≤ f (intrinsicMaximizer G hloc ω x M f) := + Classical.choose_spec (intrinsicBall_exists_max G hloc ω x M f) + +noncomputable def intrinsicPotentialMax (G : BondGraph V E) (ω : Set E) + (x : V) (M : ℕ) (f : V → ℝ) : ℝ := sSup (f '' intrinsicBall G ω x M) + +theorem intrinsicPotentialMax_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : + intrinsicPotentialMax G ω x M f = f (intrinsicMaximizer G hloc ω x M f) := by + have h := intrinsicMaximizer_spec G hloc ω x M f + apply IsGreatest.csSup_eq + exact ⟨⟨_,h.1,rfl⟩,fun _ ⟨y,hy,he⟩ => he ▸ h.2 y hy⟩ + +theorem le_intrinsicPotentialMax (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) (y : V) (hy : y ∈ intrinsicBall G ω x M) : + f y ≤ intrinsicPotentialMax G ω x M f := by + rw [intrinsicPotentialMax_eq G hloc] + exact (intrinsicMaximizer_spec G hloc ω x M f).2 y hy + +noncomputable def intrinsicBondSupport (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Set E) (x : V) (M : ℕ) : Finset E := + (incidentSupport G hloc (finite_reachBall hloc x M).toFinset).filter (· ∈ S) + +theorem intrinsicBondSupport_coe (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Set E) (x : V) (M : ℕ) : + (intrinsicBondSupport G hloc S x M : Set E) = + (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) ∩ S := by + ext e + simp [intrinsicBondSupport] + +theorem intrinsicBall_domain_restrict (G : BondGraph V E) (hloc : LocallyFinite G) + (S ω : Set E) (x : V) (M : ℕ) : + intrinsicBall G (ω ∩ (intrinsicBondSupport G hloc S x M : Set E)) x M = + intrinsicBall G (ω ∩ S) x M := by + rw [intrinsicBondSupport_coe] + have he : ω ∩ ((incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) ∩ S) = + (ω ∩ S) ∩ (incidentSupport G hloc (finite_reachBall hloc x M).toFinset : Set E) := by + ext e; simp [and_left_comm,and_comm,and_assoc] + rw [he,intrinsicBall_restrict G hloc] + +theorem intrinsicPotentialMax_domain_local (G : BondGraph V E) (hloc : LocallyFinite G) + (S ω : Set E) (x : V) (M : ℕ) (f : V → ℝ) : + intrinsicPotentialMax G (ω ∩ S) x M f = + intrinsicPotentialMax G ((ω ∩ (intrinsicBondSupport G hloc S x M : Set E)) ∩ S) x M f := by + have hsub : (intrinsicBondSupport G hloc S x M : Set E) ⊆ S := by + rw [intrinsicBondSupport_coe]; exact Set.inter_subset_right + rw [Set.inter_assoc,Set.inter_eq_left.mpr hsub] + unfold intrinsicPotentialMax + rw [intrinsicBall_domain_restrict G hloc] + +end IntrinsicMaximum +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section MaximalSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem maximal_restricted_susceptibility_bound + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (S : Set E) (x : V) (M : ℕ) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hpc : p < pc G) : + (∫ ω, intrinsicPotentialMax G (ω ∩ S) x M (restrictedSusceptibility G S p) ∂law p) ≤ + (1+(1-(p:ℝ))/p*M)*restrictedSusceptibility G S p x := by + let K := intrinsicBondSupport G hloc S x M + let f := restrictedSusceptibility G S p + let Z : Finset E → V := fun η => intrinsicMaximizer G hloc η x M f + have hK : (K:Set E) ⊆ S := by + rw [intrinsicBondSupport_coe]; exact Set.inter_subset_right + rw [integral_eq_bernoulliPolynomial K p _ (fun ω => + intrinsicPotentialMax_domain_local G hloc S ω x M f)] + have he : bernoulliPolynomial K (fun η => intrinsicPotentialMax G ((η:Set E) ∩ S) x M f) p = + bernoulliPolynomial K (fun η => f (Z η)) p := by + apply bernoulliPolynomial_congr K _ p + intro η hη + rw [Set.inter_eq_left.mpr (fun e he => hK (hη he))] + exact intrinsicPotentialMax_eq G hloc η x M f + rw [he] + apply subcritical_selected_susceptibility_bound G hloc hqt S K hK x M Z _ p hp hpc + intro η _ + exact (intrinsicMaximizer_spec G hloc η x M f).1 + + + +noncomputable def inducedSusceptibility (G : BondGraph V E) (D : Set V) + (p : unitInterval) (x : V) : ℝ := + if x ∈ D then restrictedSusceptibility G (internalEdges G D) p x else 0 + +theorem intrinsicBall_internal_subset (G : BondGraph V E) (D : Set V) + (ω : Set E) (x : V) (hx : x ∈ D) (M : ℕ) : + intrinsicBall G (ω ∩ internalEdges G D) x M ⊆ D := by + rintro y ⟨l,hl,_,ho⟩ + exact conn_internal_endpoint G D hx (hl.conn ho) + +theorem inducedSusceptibility_max_eq (G : BondGraph V E) (D : Set V) + (ω : Set E) (p : unitInterval) (x : V) (hx : x ∈ D) (M : ℕ) : + intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) = + intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (restrictedSusceptibility G (internalEdges G D) p) := by + unfold intrinsicPotentialMax + congr 1 + apply Set.image_congr + intro y hy + exact ite_eq_left (intrinsicBall_internal_subset G D ω x hx M hy) + + + +theorem maximal_induced_susceptibility_bound + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (D : Set V) (x : V) (hx : x ∈ D) (M : ℕ) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hpc : p < pc G) : + (∫ ω, intrinsicPotentialMax G (ω ∩ internalEdges G D) x M (inducedSusceptibility G D p) ∂law p) ≤ + (1+(1-(p:ℝ))/p*M)*inducedSusceptibility G D p x := by + simp_rw [inducedSusceptibility_max_eq G D _ p x hx M] + rw [inducedSusceptibility,ite_eq_left hx] + exact maximal_restricted_susceptibility_bound G hloc hqt (internalEdges G D) x M p hp hpc + +end MaximalSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section RestrictedPathPotential +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem restrictedTwoPoint_adj_lower [Countable E] (G : BondGraph V E) + (S : Set E) (p : unitInterval) (x y z : V) (e : E) + (he : G e = s(x,y)) (heS : e ∈ S) : + (p:ℝ)*(law p).real {ω | Conn G (ω ∩ S) y z} ≤ + (law p).real {ω | Conn G (ω ∩ S) x z} := by + have h := association_finiteWitness p {ω : Set E | e ∈ ω} {ω | Conn G (ω ∩ S) y z} + (fun _ _ hω h => hω h) + (fun _ _ hω h => conn_mono G (Set.inter_subset_inter_left _ hω) h) + (finiteWitness_edge e) (finiteWitness_inter _ (finiteWitness_conn G y z) S) + have hp : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by + simpa using finite_open_probability p {e} + rw [hp] at h + exact h.trans (measureReal_mono (fun ω hω => + conn_trans G _ (Relation.ReflTransGen.single ⟨e,⟨hω.1,heS⟩,he⟩) hω.2)) + +theorem restrictedTwoPoint_path_lower [Countable E] (G : BondGraph V E) + (S : Set E) (p : unitInterval) {x y : V} {l : List E} + (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) (z : V) : + (p:ℝ)^l.length*(law p).real {ω | Conn G (ω ∩ S) y z} ≤ + (law p).real {ω | Conn G (ω ∩ S) x z} := by + induction hl with + | nil => simp + | @cons x a y l e he ht ih => + have hh := mul_le_mul_of_nonneg_left (ih (fun d hd => hS d (List.mem_cons_of_mem _ hd))) p.2.1 + have ha := restrictedTwoPoint_adj_lower G S p x a z e he (hS e (by simp)) + simpa only [List.length_cons,pow_succ',mul_assoc] using hh.trans ha + +theorem restrictedSusceptibility_nonneg (G : BondGraph V E) (S : Set E) + (p : unitInterval) (x : V) : 0 ≤ restrictedSusceptibility G S p x := + tsum_nonneg (fun _ => measureReal_nonneg) + +theorem restrictedSusceptibility_path_lower [Countable E] (G : BondGraph V E) + (S : Set E) (p : unitInterval) {x y : V} {l : List E} + (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) + (hfin : ∀ a, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) a z})) : + (p:ℝ)^l.length*restrictedSusceptibility G S p y ≤ restrictedSusceptibility G S p x := by + unfold restrictedSusceptibility + rw [←tsum_mul_left] + exact ((hfin y).mul_left _).tsum_le_tsum (restrictedTwoPoint_path_lower G S p hl hS) (hfin x) + + + +theorem restrictedSusceptibility_short_path_bound [Countable E] (G : BondGraph V E) + (S : Set E) (p : unitInterval) (hp : 0 < (p:ℝ)) {x y : V} {l : List E} + (hl : Along G x l y) (hS : ∀ e ∈ l, e ∈ S) (M : ℕ) (hlen : l.length ≤ M) + (hfin : ∀ a, Summable (fun z => (law p).real {ω | Conn G (ω ∩ S) a z})) : + restrictedSusceptibility G S p y ≤ (p:ℝ)^(-(M:ℤ))*restrictedSusceptibility G S p x := by + have hh := restrictedSusceptibility_path_lower G S p hl hS hfin + have hpow : (p:ℝ)^M ≤ (p:ℝ)^l.length := + pow_le_pow_of_le_one p.2.1 p.2.2 hlen + have hbound := (mul_le_mul_of_nonneg_right hpow (restrictedSusceptibility_nonneg G S p y)).trans hh + rw [zpow_neg,zpow_natCast,←div_eq_inv_mul] + exact (le_div_iff₀ (pow_pos hp M)).mpr (by simpa only [mul_comm] using hbound) + +end RestrictedPathPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ShortPathsDeletedDomain +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem conn_short_of_cluster_cap (G : BondGraph V E) (ω : Set E) (x y : V) + (hxy : Conn G ω x y) (hfin : (cluster G ω x).Finite) + (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) : + ∃ l : List E, Along G x l y ∧ l.length ≤ M ∧ ∀ e ∈ l, e ∈ ω := by + obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp hxy + let q := w.toPath + have hs : q.val.support.toFinset ⊆ hfin.toFinset := by + intro z hz + have hz' : z ∈ q.val.support := List.mem_toFinset.mp hz + exact hfin.mem_toFinset.mpr ((conn_iff_reachable G ω x z).mpr ⟨q.val.takeUntil z hz'⟩) + have hc : q.val.length+1 ≤ (cluster G ω x).ncard := by + have hc := Finset.card_le_card hs + rwa [List.toFinset_card_of_nodup q.property.support_nodup, + SimpleGraph.Walk.length_support,←Set.ncard_eq_toFinset_card _ hfin] at hc + obtain ⟨l,hl,he,ho⟩ := walk_lift_bonds G ω q.val + have hlen : l.length = q.val.length := by + have hh := congrArg List.length he + simpa only [List.length_map,SimpleGraph.Walk.length_edges] using hh + exact ⟨l,hl,by omega,ho⟩ + + + +theorem Along.last_entrance {G : BondGraph V E} {x y : V} {l : List E} + (hl : Along G x l y) (D : Set V) (hy : y ∈ D) : + (x ∈ D ∧ ∀ e ∈ l, e ∈ internalEdges G D) ∨ + ∃ a b e l₁ l₂, l = l₁ ++ e::l₂ ∧ Along G x l₁ a ∧ G e = s(a,b) ∧ + a ∉ D ∧ b ∈ D ∧ Along G b l₂ y ∧ ∀ d ∈ l₂, d ∈ internalEdges G D := by + induction hl with + | nil => exact Or.inl ⟨hy,by simp⟩ + | @cons x z y l e he ht ih => + rcases ih hy with ⟨hz,hall⟩ | ⟨a,b,d,l₁,l₂,heq,h₁,hd,ha,hb,h₂,hs⟩ + · by_cases hx : x ∈ D + · left + refine ⟨hx,?_⟩ + intro d hd + rcases List.mem_cons.mp hd with rfl | hd + · exact (mem_internalEdges_of_ends G D d x z he).mpr ⟨hx,hz⟩ + · exact hall d hd + · right + exact ⟨x,z,e,[],l,rfl,.nil x,he,hx,hz,ht,hall⟩ + · right + exact ⟨a,b,d,e::l₁,l₂,by simp [heq],.cons e he h₁,hd,ha,hb,h₂,hs⟩ + +end ShortPathsDeletedDomain +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Clusters/Uniqueness.lean b/lean/OAI/Probability/UnimodularPercolation/Clusters/Uniqueness.lean index 457f6bbaefb2f68ec33a29b86f643b1972b408b3..3be618f5a70de961ca03f504567a9edc8b3966e3 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Clusters/Uniqueness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Clusters/Uniqueness.lean @@ -1,599 +1,599 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.ProductMeasure.Association - -namespace OAI - -/-! Cluster events, invariant covers and uniqueness thresholds. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section InfiniteOrbits -attribute [local instance] Classical.propDecidable - -def vertexOrbit (G : BondGraph V E) (x : V) : Set V := - {y | ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ a x = y} - -theorem adj_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) {x y : V} (hxy : Adj G x y) : Adj G (a x) (a y) := by - obtain ⟨e, he⟩ := hxy - exact ⟨b e, by rw [h e, he, Sym2.map_mk]⟩ - -theorem mem_reachBall_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) {x y : V} {n : ℕ} (hy : y ∈ reachBall G x n) : - a y ∈ reachBall G (a x) n := by - induction n generalizing y with - | zero => simpa only [reachBall, Set.mem_singleton_iff, Equiv.apply_eq_iff_eq] using hy - | succ n ih => - rcases hy with hy | hy - · exact Or.inl (ih hy) - · change a y ∈ reachBall G (a x) n ∪ ⋃ z ∈ reachBall G (a x) n, {w | Adj G z w} - apply Or.inr - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] at hy ⊢ - obtain ⟨z, hz, hzy⟩ := hy - exact ⟨a z, ih hz, adj_aut G h hzy⟩ - - - -theorem vertexOrbit_infinite [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (x : V) : - (vertexOrbit G x).Infinite := by - intro hfin - obtain ⟨R, hR⟩ := hqt - choose n hn using (fun y => exists_mem_reachBall (hconn x y)) - have hS : (⋃ o ∈ (R : Set V), ⋃ z ∈ vertexOrbit G x, reachBall G z (n o)).Finite := - R.finite_toSet.biUnion fun o _ => hfin.biUnion fun z _ => finite_reachBall hloc z (n o) - have he : Set.univ ⊆ ⋃ o ∈ (R : Set V), ⋃ z ∈ vertexOrbit G x, reachBall G z (n o) := by - intro y _ - obtain ⟨o, ho, a, b, hab, hay⟩ := hR y - simp only [Set.mem_iUnion] - exact ⟨o, ho, a x, ⟨a, b, hab, rfl⟩, hay ▸ mem_reachBall_aut G hab (hn o)⟩ - exact Set.infinite_univ (hS.subset he) - -end InfiniteOrbits - -section FinitePairBound -attribute [local instance] Classical.propDecidable -open scoped ComplexConjugate - -noncomputable def deltaSum (F : Finset V) : Hilbert V := ∑ x ∈ F, lp.single 2 x (1 : ℂ) - -@[simp] theorem deltaSum_apply (F : Finset V) (x : V) : - deltaSum F x = if x ∈ F then 1 else 0 := by - simp only [deltaSum, lp.coeFn_sum, Finset.sum_apply, lp.single_apply] - simp - -@[simp] theorem inner_deltaSum (F : Finset V) (f : Hilbert V) : - inner ℂ (deltaSum F) f = ∑ x ∈ F, f x := by - simp [deltaSum, lp.inner_single_left] - -theorem norm_deltaSum_sq (F : Finset V) : ‖deltaSum F‖ ^ 2 = (F.card : ℝ) := by - rw [← inner_self_eq_norm_sq (𝕜 := ℂ), inner_deltaSum] - simp only [map_sum, deltaSum_apply] - trans ∑ _x ∈ F, (1 : ℝ) - · apply Finset.sum_congr rfl - intro x hx - simp [hx] - · simp - - -theorem sum_twoPoint_le_norm_card (G : BondGraph V E) (p : unitInterval) - {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) (F : Finset V) : - ∑ x ∈ F, ∑ y ∈ F, twoPoint G p x y ≤ ‖A‖ * F.card := by - have he : inner ℂ (deltaSum F) (A (deltaSum F)) = - ((∑ x ∈ F, ∑ y ∈ F, twoPoint G p x y : ℝ) : ℂ) := by - rw [inner_deltaSum] - simp only [deltaSum, map_sum] - simp only [lp.coeFn_sum, Finset.sum_apply, Complex.ofReal_sum] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - exact hA x y - have h := (Complex.re_le_norm (inner ℂ (deltaSum F) (A (deltaSum F)))).trans - ((norm_inner_le_norm _ _).trans - (mul_le_mul_of_nonneg_left (A.le_opNorm _) (norm_nonneg _))) - rw [he, Complex.ofReal_re] at h - calc - _ ≤ ‖deltaSum F‖ * (‖A‖ * ‖deltaSum F‖) := h - _ = ‖A‖ * ‖deltaSum F‖ ^ 2 := by ring - _ = _ := by rw [norm_deltaSum_sq] - -end FinitePairBound - -section PairCounting -attribute [local instance] Classical.propDecidable - - -theorem card_sq_le_image_card_mul_pairs {W : Type*} (S : Finset V) (c : V → W) : - (S.card : ℝ) ^ 2 ≤ ((S.image c).card : ℝ) * - ∑ x ∈ S, ∑ y ∈ S, if c x = c y then (1 : ℝ) else 0 := by - let t := S.image c - let f := fun w => ((S.filter (fun x => c x = w)).card : ℝ) - have hsum : ∑ w ∈ t, f w = (S.card : ℝ) := by - have h := Finset.sum_fiberwise_of_maps_to - (fun x (hx : x ∈ S) => Finset.mem_image_of_mem c hx) (fun _ => (1 : ℝ)) - simpa only [Finset.sum_const, nsmul_eq_mul, mul_one, t, f] using h - have hsq : ∑ w ∈ t, f w ^ 2 = - ∑ x ∈ S, ∑ y ∈ S, if c x = c y then (1 : ℝ) else 0 := by - calc - ∑ w ∈ t, f w ^ 2 = ∑ w ∈ t, ∑ x ∈ S with c x = w, f (c x) := by - apply Finset.sum_congr rfl - intro w hw - rw [show ∑ x ∈ S with c x = w, f (c x) = - ∑ _x ∈ S with c _x = w, f w from - Finset.sum_congr rfl (fun x hx => by rw [(Finset.mem_filter.mp hx).2])] - simp only [Finset.sum_const, nsmul_eq_mul, f] - ring - _ = ∑ x ∈ S, f (c x) := Finset.sum_fiberwise_of_maps_to - (fun x hx => Finset.mem_image_of_mem c hx) _ - _ = _ := by - apply Finset.sum_congr rfl - intro x hx - rw [← Finset.sum_filter] - simp only [Finset.sum_const, nsmul_eq_mul, mul_one, f] - congr 2 - ext y - simp [eq_comm] - have h := Finset.sum_mul_sq_le_sq_mul_sq t (fun _ => (1 : ℝ)) f - simpa only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, hsum, hsq, t] using h - -end PairCounting - -section PairIntegral -attribute [local instance] Classical.propDecidable -variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] - - -theorem square_sum_probability_le (F : Finset V) (S : V → Set Ω) - (C : V → V → Set Ω) (hS : ∀ x, MeasurableSet (S x)) - (hC : ∀ x y, MeasurableSet (C x y)) (n : ℝ) - (hpoint : ∀ ω, (∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) ω) ^ 2 ≤ - n * ∑ x ∈ F, ∑ y ∈ F, (C x y).indicator (fun _ => (1 : ℝ)) ω) : - (∑ x ∈ F, μ.real (S x)) ^ 2 ≤ n * ∑ x ∈ F, ∑ y ∈ F, μ.real (C x y) := by - let X := fun ω => ∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) ω - have hX : MemLp X 2 μ := memLp_finsetSum F - (fun x _ => (memLp_const (1 : ℝ)).indicator (hS x)) - have hCi (x y) : Integrable ((C x y).indicator (fun _ => (1 : ℝ))) μ := - (integrable_const (1 : ℝ)).indicator (hC x y) - have hY : Integrable (fun ω => ∑ x ∈ F, ∑ y ∈ F, - (C x y).indicator (fun _ => (1 : ℝ)) ω) μ := - integrable_finsetSum F (fun x _ => integrable_finsetSum F (fun y _ => hCi x y)) - have hv := variance_nonneg X μ - rw [variance_eq_sub hX] at hv - have hi := integral_mono hX.integrable_sq (hY.const_mul n) hpoint - have hx : (∫ ω, X ω ∂μ) = ∑ x ∈ F, μ.real (S x) := by - dsimp only [X] - rw [integral_finsetSum F (fun x _ => (integrable_const (1 : ℝ)).indicator (hS x))] - simp only [integral_indicator_const _ (hS _), smul_eq_mul, mul_one] - have hy : (∫ ω, n * ∑ x ∈ F, ∑ y ∈ F, - (C x y).indicator (fun _ => (1 : ℝ)) ω ∂μ) = - n * ∑ x ∈ F, ∑ y ∈ F, μ.real (C x y) := by - rw [integral_const_mul, integral_finsetSum F - (fun x _ => integrable_finsetSum F (fun y _ => hCi x y))] - congr 1 - apply Finset.sum_congr rfl - intro x _ - rw [integral_finsetSum F (fun y _ => hCi x y)] - simp only [integral_indicator_const _ (hC x _), smul_eq_mul, mul_one] - rw [hx] at hv - rw [hy] at hi - exact (sub_nonneg.mp hv).trans hi - -end PairIntegral - -section CoupledCovers -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] - -omit [Countable V] [Countable E] in -theorem cluster_eq_iff_conn (G : BondGraph V E) (ω : Set E) (x y : V) : - cluster G ω x = cluster G ω y ↔ Conn G ω x y := by - constructor - · intro h - have hh := mem_cluster_self G ω y - rwa [← h] at hh - · exact cluster_eq_of_conn G ω - - -def TouchedCover (G : BondGraph V E) (p q : unitInterval) (n : ℕ) - (labels : E → unitInterval) : Prop := - ∃ f : Fin n → V, ∀ x, (cluster G (openEdges labels p) x).Infinite → - ∃ i, Conn G (openEdges labels q) x (f i) - -theorem measurableSet_touchedCover (G : BondGraph V E) (p q : unitInterval) (n : ℕ) : - MeasurableSet {labels | TouchedCover G p q n labels} := by - have he : {labels | TouchedCover G p q n labels} = - ⋃ f : Fin n → V, ⋂ x : V, ({labels | (cluster G (openEdges labels p) x).Infinite}ᶜ ∪ - ⋃ i : Fin n, {labels | Conn G (openEdges labels q) x (f i)}) := by - ext labels - simp only [TouchedCover, Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_iInter, - Set.mem_union, Set.mem_compl_iff] - simp only [← imp_iff_not_or] - rw [he] - apply MeasurableSet.iUnion - intro f - apply MeasurableSet.iInter - intro x - exact ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)).compl.union - (MeasurableSet.iUnion fun i => (measurableSet_conn G x (f i)).preimage (measurable_openEdges q)) - -omit [Countable V] [Countable E] in - -theorem survivor_count_sq_le (G : BondGraph V E) (p q : unitInterval) (n : ℕ) - (F : Finset V) (labels : E → unitInterval) (h : TouchedCover G p q n labels) : - ((F.filter fun x => (cluster G (openEdges labels p) x).Infinite).card : ℝ) ^ 2 ≤ - n * ∑ x ∈ F, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by - obtain ⟨f, hf⟩ := h - let S := F.filter fun x => (cluster G (openEdges labels p) x).Infinite - let c := cluster G (openEdges labels q) - have hsub : S.image c ⊆ Finset.univ.image (fun i : Fin n => c (f i)) := by - intro C hC - obtain ⟨x, hx, rfl⟩ := Finset.mem_image.mp hC - obtain ⟨i, hi⟩ := hf x (Finset.mem_filter.mp hx).2 - exact Finset.mem_image.mpr ⟨i, Finset.mem_univ _, (cluster_eq_of_conn G _ hi).symm⟩ - have hcard : (S.image c).card ≤ n := - (Finset.card_le_card hsub).trans (by simpa using (Finset.card_image_le (s := (Finset.univ : Finset (Fin n))) - (f := fun i : Fin n => c (f i)))) - have hpair := card_sq_le_image_card_mul_pairs S c - have hpairs : ∑ x ∈ S, ∑ y ∈ S, (if c x = c y then (1 : ℝ) else 0) ≤ - ∑ x ∈ F, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by - simp only [c, cluster_eq_iff_conn] - calc - _ ≤ ∑ x ∈ S, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by - apply Finset.sum_le_sum - intro x _ - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) - (fun _ _ _ => by split_ifs <;> positivity) - _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) - (fun _ _ _ => Finset.sum_nonneg fun _ _ => by split_ifs <;> positivity) - exact hpair.trans ((mul_le_mul_of_nonneg_left hpairs (Nat.cast_nonneg _)).trans - (mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) - (Finset.sum_nonneg fun _ _ => Finset.sum_nonneg fun _ _ => by split_ifs <;> positivity))) - -end CoupledCovers - -section CoverInvariance -attribute [local instance] Classical.propDecidable - - -theorem labelLaw_map_precomp (b : E ≃ E) : - (labelLaw : Measure (E → unitInterval)).map (fun labels => labels ∘ b) = labelLaw := by - have he : (fun labels : E → unitInterval => labels ∘ b) = - MeasurableEquiv.piCongrLeft (fun _ : E => unitInterval) b.symm := by - funext labels e - have h := MeasurableEquiv.piCongrLeft_apply_apply (β := fun _ : E => unitInterval) - b.symm labels (b e) - simpa only [Equiv.symm_apply_apply, Function.comp_apply] using h.symm - unfold labelLaw - rw [he] - exact Measure.infinitePi_map_piCongrLeft (fun _ : E => (volume : Measure unitInterval)) b.symm - -theorem infinite_cluster_precomp (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (labels : E → unitInterval) (p : unitInterval) (x : V) : - (cluster G (openEdges (labels ∘ b) p) x).Infinite ↔ - (cluster G (openEdges labels p) (a x)).Infinite := by - change (cluster G (b ⁻¹' openEdges labels p) x).Infinite ↔ _ - rw [← cluster_aut G h] - exact (Set.infinite_image_iff (fun _ _ _ _ hab => a.injective hab)).symm - -variable [Countable V] [Countable E] - -omit [Countable V] [Countable E] in -theorem touchedCover_precomp (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (labels : E → unitInterval) (p q : unitInterval) (n : ℕ) : - TouchedCover G p q n (labels ∘ b) ↔ TouchedCover G p q n labels := by - constructor - · rintro ⟨f, hf⟩ - refine ⟨fun i => a (f i), fun x hx => ?_⟩ - have hs : (cluster G (openEdges (labels ∘ b) p) (a.symm x)).Infinite := - (infinite_cluster_precomp G h labels p (a.symm x)).mpr (by simpa using hx) - obtain ⟨i, hi⟩ := hf _ hs - exact ⟨i, by simpa using (conn_aut_iff G h (openEdges labels q) (a.symm x) (f i)).mp hi⟩ - · rintro ⟨f, hf⟩ - refine ⟨fun i => a.symm (f i), fun x hx => ?_⟩ - obtain ⟨i, hi⟩ := hf (a x) ((infinite_cluster_precomp G h labels p x).mp hx) - exact ⟨i, (conn_aut_iff G h (openEdges labels q) x (a.symm (f i))).mpr (by simpa using hi)⟩ - -theorem cover_survival_aut (G : BondGraph V E) (p q : unitInterval) (n : ℕ) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : - (labelLaw : Measure (E → unitInterval)).real - {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) (a x)).Infinite} = - labelLaw.real {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite} := by - have hm : Measurable (fun labels : E → unitInterval => labels ∘ b) := - Measurable.of_eval (fun e => measurable_pi_apply (b e)) - have hs : MeasurableSet {labels | TouchedCover G p q n labels ∧ - (cluster G (openEdges labels p) x).Infinite} := - (measurableSet_touchedCover G p q n).inter - ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)) - have he : {labels | TouchedCover G p q n labels ∧ - (cluster G (openEdges labels p) (a x)).Infinite} = - (fun labels : E → unitInterval => labels ∘ b) ⁻¹' - {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite} := by - ext labels - simp only [Set.mem_ofPred_eq, Set.mem_preimage, touchedCover_precomp G h, - infinite_cluster_precomp G h] - simp only [Measure.real] - rw [he, ← Measure.map_apply hm hs, labelLaw_map_precomp] - -end CoverInvariance - -section CoverObstruction -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] - -theorem cover_survival_square_sum_le (G : BondGraph V E) (p q : unitInterval) (n : ℕ) - {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G q A) (F : Finset V) : - (∑ x ∈ F, (labelLaw : Measure (E → unitInterval)).real {labels | - TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite}) ^ 2 ≤ - n * ‖A‖ * F.card := by - let S := fun x => {labels | TouchedCover G p q n labels ∧ - (cluster G (openEdges labels p) x).Infinite} - let C := fun x y => {labels | Conn G (openEdges labels q) x y} - have hS (x) : MeasurableSet (S x) := - (measurableSet_touchedCover G p q n).inter - ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)) - have hC (x y) : MeasurableSet (C x y) := - (measurableSet_conn G x y).preimage (measurable_openEdges q) - have hpoint (labels : E → unitInterval) : - (∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) labels) ^ 2 ≤ - (n : ℝ) * ∑ x ∈ F, ∑ y ∈ F, (C x y).indicator (fun _ => (1 : ℝ)) labels := by - by_cases hc : TouchedCover G p q n labels - · have he : ∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) labels = - ((F.filter fun x => (cluster G (openEdges labels p) x).Infinite).card : ℝ) := by - simp only [S, Set.indicator, Set.mem_ofPred_eq, hc, true_and] - rw [← Finset.sum_filter] - simp - rw [he] - simpa only [C, Set.indicator, Set.mem_ofPred_eq] using - survivor_count_sq_le G p q n F labels hc - · simp only [S, Set.indicator, Set.mem_ofPred_eq, hc, false_and, ite_false, - Finset.sum_const_zero, zero_pow (by decide : 2 ≠ 0)] - exact mul_nonneg (Nat.cast_nonneg _) (Finset.sum_nonneg fun _ _ => - Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _) - have h := square_sum_probability_le (labelLaw : Measure (E → unitInterval)) F S C hS hC - (n : ℝ) hpoint - have he (x y) : labelLaw.real (C x y) = twoPoint G q x y := - (twoPoint_eq_labelLaw G q x y).symm - simp only [he] at h - exact h.trans (by simpa only [mul_assoc] using - mul_le_mul_of_nonneg_left (sum_twoPoint_le_norm_card G q hA F) (Nat.cast_nonneg n)) - - - -theorem measure_cover_survival_eq_zero [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p q : unitInterval) (hq : OperatorBounded G q) (n : ℕ) (x : V) : - (labelLaw : Measure (E → unitInterval)) {labels | TouchedCover G p q n labels ∧ - (cluster G (openEdges labels p) x).Infinite} = 0 := by - apply (measureReal_eq_zero_iff).mp - by_contra hnz - let θ := (labelLaw : Measure (E → unitInterval)).real {labels | TouchedCover G p q n labels ∧ - (cluster G (openEdges labels p) x).Infinite} - have hθ : 0 < θ := lt_of_le_of_ne measureReal_nonneg (Ne.symm hnz) - obtain ⟨A, hA⟩ := hq - obtain ⟨m, hm⟩ := exists_nat_gt ((n : ℝ) * ‖A‖ / θ ^ 2 + 1) - obtain ⟨F, hF, hcard⟩ := (vertexOrbit_infinite G hconn hloc hqt x).exists_subset_card_eq m - have he (y : V) (hy : y ∈ F) : (labelLaw : Measure (E → unitInterval)).real - {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) y).Infinite} = θ := by - obtain ⟨a, b, hab, hay⟩ := hF hy - rw [← hay] - exact cover_survival_aut G p q n hab x - have hh := cover_survival_square_sum_le G p q n hA F - rw [Finset.sum_congr rfl he] at hh - simp only [Finset.sum_const, nsmul_eq_mul, hcard] at hh - have hθsq : 0 < θ ^ 2 := sq_pos_of_pos hθ - have hm0 : (0 : ℝ) < m := lt_trans (by positivity : (0 : ℝ) < (n : ℝ) * ‖A‖ / θ ^ 2 + 1) hm - have hlt : (n : ℝ) * ‖A‖ < (m : ℝ) * θ ^ 2 := by - apply (div_lt_iff₀ hθsq).mp - linarith - nlinarith - -end CoverObstruction - -section FiniteChanges -attribute [local instance] Classical.propDecidable - - -theorem cluster_union_subset (G : BondGraph V E) (ω : Set E) (F : Set E) (x : V) : - cluster G (ω ∪ F) x ⊆ cluster G ω x ∪ ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G ω z := by - intro y hy - induction hy with - | refl => exact Or.inl (mem_cluster_self G ω x) - | @tail y z hy hed ih => - obtain ⟨e, he, heq⟩ := hed - rcases he with he | he - · have hyz : Conn G ω y z := (conn_refl G ω y).tail ⟨e, he, heq⟩ - rcases ih with ih | ih - · exact Or.inl (conn_trans G ω ih hyz) - · right - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] at ih ⊢ - obtain ⟨e', he', w, hw, hwy⟩ := ih - exact ⟨e', he', w, hw, conn_trans G ω hwy hyz⟩ - · right - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] - exact ⟨e, he, z, heq ▸ by simp, conn_refl G ω z⟩ - -theorem exists_infinite_cluster_mono (G : BondGraph V E) {ω ω' : Set E} (h : ω ⊆ ω') : - (∃ x, (cluster G ω x).Infinite) → ∃ x, (cluster G ω' x).Infinite := by - rintro ⟨x, hx⟩ - exact ⟨x, hx.mono (fun _ hy => conn_mono G h hy)⟩ - - -theorem exists_infinite_cluster_sdiff (G : BondGraph V E) (ω : Set E) - {F : Set E} (hF : F.Finite) : - (∃ x, (cluster G (ω \ F) x).Infinite) ↔ ∃ x, (cluster G ω x).Infinite := by - constructor - · exact exists_infinite_cluster_mono G Set.sdiff_subset - · contrapose! - intro h x - have hs : (cluster G (ω \ F) x ∪ - ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G (ω \ F) z).Finite := by - apply (h x).union - apply hF.biUnion - intro e _ - have he : {z | z ∈ G e}.Finite := by - exact (G e).toFinset.finite_toSet.subset (fun z hz => by simpa using hz) - exact he.biUnion (fun z _ => h z) - apply hs.subset - apply Set.Subset.trans (fun y hy => conn_mono G (Set.subset_sdiff_union _ _) hy) - exact cluster_union_subset G (ω \ F) F x - -end FiniteChanges - -section PercolationZeroOne -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] - -omit [Countable V] [Countable E] in -theorem infiniteClusters_nonempty_iff (G : BondGraph V E) (ω : Set E) : - (infiniteClusters G ω).Nonempty ↔ ∃ x, (cluster G ω x).Infinite := by - constructor - · rintro ⟨C, hC, x, rfl⟩ - exact ⟨x, hC⟩ - · rintro ⟨x, hx⟩ - exact ⟨cluster G ω x, hx, x, rfl⟩ - - theorem measurableSet_exists_infinite_cluster (G : BondGraph V E) : - MeasurableSet {ω : Set E | ∃ x, (cluster G ω x).Infinite} := by - simpa only [Set.ofPred_exists] using MeasurableSet.iUnion (fun x => measurableSet_infinite_cluster G x) - - theorem infinite_cluster_zero_one (G : BondGraph V E) (p : unitInterval) : - (labelLaw : Measure (E → unitInterval)) - {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} = 0 ∨ - (labelLaw : Measure (E → unitInterval)) - {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} = 1 := by - let σ : E → MeasurableSpace (E → unitInterval) := fun e => - MeasurableSpace.comap (fun labels : E → unitInterval => labels e) inferInstance - have hle (e) : σ e ≤ (inferInstance : MeasurableSpace (E → unitInterval)) := (measurable_pi_apply e).comap_le - have hi : iIndep σ (labelLaw : Measure (E → unitInterval)) := - iIndepFun_infinitePi (X := fun (_ : E) (x : unitInterval) => x) (fun _ => measurable_id) - have htail : MeasurableSet[Filter.limsup σ Filter.cofinite] - {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} := by - rw [Filter.limsup_eq_iInf_iSup] - apply MeasurableSpace.measurableSet_iInf.mpr - intro s - apply MeasurableSpace.measurableSet_iInf.mpr - intro hs - have hfin : sᶜ.Finite := Filter.mem_cofinite.mp hs - let m := ⨆ e ∈ s, σ e - have hm : @Measurable (E → unitInterval) (Set E) m inferInstance - (fun labels => openEdges labels p ∩ s) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - change @Measurable (E → unitInterval) Prop m inferInstance (fun labels => labels e ≤ p ∧ e ∈ s) - by_cases he : e ∈ s - · have hev : @Measurable (E → unitInterval) unitInterval m inferInstance - (fun labels => labels e) := - Measurable.of_comap_le (le_iSup_of_le e (le_iSup_of_le he le_rfl)) - simpa only [he, and_true, Function.comp_def] - using (measurable_threshold p).comp hev - · simpa only [he, and_false] - using (measurable_const : @Measurable (E → unitInterval) Prop m inferInstance - (fun _ => False)) - have heq : {labels : E → unitInterval | ∃ x, (cluster G (openEdges labels p) x).Infinite} = - {labels | ∃ x, (cluster G (openEdges labels p ∩ s) x).Infinite} := by - ext labels - simpa only [Set.sdiff_compl, Set.mem_ofPred_eq] using - (exists_infinite_cluster_sdiff G (openEdges labels p) hfin).symm - rw [heq] - exact (measurableSet_exists_infinite_cluster G).preimage hm - exact measure_zero_or_one_of_measurableSet_limsup - (s := σ) (f := Filter.cofinite) (p := Set.Finite) - (ns := fun F : Finset E => (F : Set E)) hle hi - (fun t ht => by simpa using ht) - (fun F H => ⟨F ∪ H, Finset.coe_subset.mpr Finset.subset_union_left, - Finset.coe_subset.mpr Finset.subset_union_right⟩) - (fun F => F.finite_toSet) (fun e => ⟨{e}, by simp⟩) htail - -end PercolationZeroOne - -section CoupledInterval -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] - - theorem exists_infinite_cluster_probability_mono (G : BondGraph V E) {p q : unitInterval} - (hpq : p ≤ q) : - law p {ω | (infiniteClusters G ω).Nonempty} ≤ - law q {ω | (infiniteClusters G ω).Nonempty} := by - have hm : MeasurableSet {ω : Set E | (infiniteClusters G ω).Nonempty} := by - simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G - rw [← map_openEdges p, ← map_openEdges q, - Measure.map_apply (measurable_openEdges p) hm, - Measure.map_apply (measurable_openEdges q) hm] - apply measure_mono - intro labels h - simp only [Set.mem_preimage, Set.mem_ofPred_eq, infiniteClusters_nonempty_iff] at h ⊢ - exact exists_infinite_cluster_mono G (openEdges_mono labels hpq) h - - theorem ae_exists_infinite_cluster_of_pc_lt (G : BondGraph V E) (p : unitInterval) - (hp : pc G < p) : - ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), - ∃ x, (cluster G (openEdges labels p) x).Infinite := by - obtain ⟨q, hq, hqp⟩ := sInf_lt_iff.mp hp - have hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty} := - lt_of_lt_of_le hq (exists_infinite_cluster_probability_mono G hqp.le) - have hm : MeasurableSet {ω : Set E | (infiniteClusters G ω).Nonempty} := by - simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G - rw [← map_openEdges p, Measure.map_apply (measurable_openEdges p) hm] at hpos - simp only [Set.preimage_ofPred_eq, infiniteClusters_nonempty_iff] at hpos - have hpone := (infinite_cluster_zero_one G p).resolve_left (ne_of_gt hpos) - exact (mem_ae_iff_prob_eq_one - ((measurableSet_exists_infinite_cluster G).preimage (measurable_openEdges p))).mpr hpone - -omit [Countable V] [Countable E] in - theorem touchedCover_of_finite_infiniteClusters (G : BondGraph V E) - (labels : E → unitInterval) {p r q : unitInterval} (hpr : p ≤ r) (hrq : r ≤ q) - (hfinite : (infiniteClusters G (openEdges labels r)).Finite) : - ∃ n, TouchedCover G p q n labels := by - let C := infiniteClusters G (openEdges labels r) - let : Fintype C := hfinite.fintype - let f : C → V := fun c => Classical.choose c.property.2 - have hf (c : C) : c.val = cluster G (openEdges labels r) (f c) := - Classical.choose_spec c.property.2 - refine ⟨Fintype.card C, fun i => f ((Fintype.equivFin C).symm i), ?_⟩ - intro x hx - have hx' : (cluster G (openEdges labels r) x).Infinite := - hx.mono (fun _ hy => conn_mono G (openEdges_mono labels hpr) hy) - let c : C := ⟨cluster G (openEdges labels r) x, hx', x, rfl⟩ - refine ⟨Fintype.equivFin C c, ?_⟩ - simp only [Equiv.symm_apply_apply] - apply conn_mono G (openEdges_mono labels hrq) - change f c ∈ cluster G (openEdges labels r) x - change f c ∈ c.val - rw [hf c] - exact mem_cluster_self G _ _ - - - - theorem coupled_interval [Infinite V] (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p q : unitInterval) (hp : pc G < p) (hq : OperatorBounded G q) : - ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), - ∀ r ∈ Set.Icc p q, (infiniteClusters G (openEdges labels r)).Infinite := by - have hall : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), ∀ n x, - ¬(TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite) := by - rw [ae_all_iff] - intro n - rw [ae_all_iff] - intro x - apply ae_iff.mpr - simpa only [not_not] using measure_cover_survival_eq_zero G hconn hloc hqt p q hq n x - filter_upwards [hall, ae_exists_infinite_cluster_of_pc_lt G p hp] with labels hlabels hex - intro r hr - by_contra hfinite - obtain ⟨n, hn⟩ := touchedCover_of_finite_infiniteClusters G labels hr.1 hr.2 - (Set.not_infinite.mp hfinite) - obtain ⟨x, hx⟩ := hex - exact hlabels n x ⟨hn, hx⟩ - -end CoupledInterval - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.ProductMeasure.Association + +namespace OAI + +/-! Cluster events, invariant covers and uniqueness thresholds. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section InfiniteOrbits +attribute [local instance] Classical.propDecidable + +def vertexOrbit (G : BondGraph V E) (x : V) : Set V := + {y | ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ a x = y} + +theorem adj_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) {x y : V} (hxy : Adj G x y) : Adj G (a x) (a y) := by + obtain ⟨e, he⟩ := hxy + exact ⟨b e, by rw [h e, he, Sym2.map_mk]⟩ + +theorem mem_reachBall_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) {x y : V} {n : ℕ} (hy : y ∈ reachBall G x n) : + a y ∈ reachBall G (a x) n := by + induction n generalizing y with + | zero => simpa only [reachBall, Set.mem_singleton_iff, Equiv.apply_eq_iff_eq] using hy + | succ n ih => + rcases hy with hy | hy + · exact Or.inl (ih hy) + · change a y ∈ reachBall G (a x) n ∪ ⋃ z ∈ reachBall G (a x) n, {w | Adj G z w} + apply Or.inr + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] at hy ⊢ + obtain ⟨z, hz, hzy⟩ := hy + exact ⟨a z, ih hz, adj_aut G h hzy⟩ + + + +theorem vertexOrbit_infinite [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (x : V) : + (vertexOrbit G x).Infinite := by + intro hfin + obtain ⟨R, hR⟩ := hqt + choose n hn using (fun y => exists_mem_reachBall (hconn x y)) + have hS : (⋃ o ∈ (R : Set V), ⋃ z ∈ vertexOrbit G x, reachBall G z (n o)).Finite := + R.finite_toSet.biUnion fun o _ => hfin.biUnion fun z _ => finite_reachBall hloc z (n o) + have he : Set.univ ⊆ ⋃ o ∈ (R : Set V), ⋃ z ∈ vertexOrbit G x, reachBall G z (n o) := by + intro y _ + obtain ⟨o, ho, a, b, hab, hay⟩ := hR y + simp only [Set.mem_iUnion] + exact ⟨o, ho, a x, ⟨a, b, hab, rfl⟩, hay ▸ mem_reachBall_aut G hab (hn o)⟩ + exact Set.infinite_univ (hS.subset he) + +end InfiniteOrbits + +section FinitePairBound +attribute [local instance] Classical.propDecidable +open scoped ComplexConjugate + +noncomputable def deltaSum (F : Finset V) : Hilbert V := ∑ x ∈ F, lp.single 2 x (1 : ℂ) + +@[simp] theorem deltaSum_apply (F : Finset V) (x : V) : + deltaSum F x = if x ∈ F then 1 else 0 := by + simp only [deltaSum, lp.coeFn_sum, Finset.sum_apply, lp.single_apply] + simp + +@[simp] theorem inner_deltaSum (F : Finset V) (f : Hilbert V) : + inner ℂ (deltaSum F) f = ∑ x ∈ F, f x := by + simp [deltaSum, lp.inner_single_left] + +theorem norm_deltaSum_sq (F : Finset V) : ‖deltaSum F‖ ^ 2 = (F.card : ℝ) := by + rw [← inner_self_eq_norm_sq (𝕜 := ℂ), inner_deltaSum] + simp only [map_sum, deltaSum_apply] + trans ∑ _x ∈ F, (1 : ℝ) + · apply Finset.sum_congr rfl + intro x hx + simp [hx] + · simp + + +theorem sum_twoPoint_le_norm_card (G : BondGraph V E) (p : unitInterval) + {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) (F : Finset V) : + ∑ x ∈ F, ∑ y ∈ F, twoPoint G p x y ≤ ‖A‖ * F.card := by + have he : inner ℂ (deltaSum F) (A (deltaSum F)) = + ((∑ x ∈ F, ∑ y ∈ F, twoPoint G p x y : ℝ) : ℂ) := by + rw [inner_deltaSum] + simp only [deltaSum, map_sum] + simp only [lp.coeFn_sum, Finset.sum_apply, Complex.ofReal_sum] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + exact hA x y + have h := (Complex.re_le_norm (inner ℂ (deltaSum F) (A (deltaSum F)))).trans + ((norm_inner_le_norm _ _).trans + (mul_le_mul_of_nonneg_left (A.le_opNorm _) (norm_nonneg _))) + rw [he, Complex.ofReal_re] at h + calc + _ ≤ ‖deltaSum F‖ * (‖A‖ * ‖deltaSum F‖) := h + _ = ‖A‖ * ‖deltaSum F‖ ^ 2 := by ring + _ = _ := by rw [norm_deltaSum_sq] + +end FinitePairBound + +section PairCounting +attribute [local instance] Classical.propDecidable + + +theorem card_sq_le_image_card_mul_pairs {W : Type*} (S : Finset V) (c : V → W) : + (S.card : ℝ) ^ 2 ≤ ((S.image c).card : ℝ) * + ∑ x ∈ S, ∑ y ∈ S, if c x = c y then (1 : ℝ) else 0 := by + let t := S.image c + let f := fun w => ((S.filter (fun x => c x = w)).card : ℝ) + have hsum : ∑ w ∈ t, f w = (S.card : ℝ) := by + have h := Finset.sum_fiberwise_of_maps_to + (fun x (hx : x ∈ S) => Finset.mem_image_of_mem c hx) (fun _ => (1 : ℝ)) + simpa only [Finset.sum_const, nsmul_eq_mul, mul_one, t, f] using h + have hsq : ∑ w ∈ t, f w ^ 2 = + ∑ x ∈ S, ∑ y ∈ S, if c x = c y then (1 : ℝ) else 0 := by + calc + ∑ w ∈ t, f w ^ 2 = ∑ w ∈ t, ∑ x ∈ S with c x = w, f (c x) := by + apply Finset.sum_congr rfl + intro w hw + rw [show ∑ x ∈ S with c x = w, f (c x) = + ∑ _x ∈ S with c _x = w, f w from + Finset.sum_congr rfl (fun x hx => by rw [(Finset.mem_filter.mp hx).2])] + simp only [Finset.sum_const, nsmul_eq_mul, f] + ring + _ = ∑ x ∈ S, f (c x) := Finset.sum_fiberwise_of_maps_to + (fun x hx => Finset.mem_image_of_mem c hx) _ + _ = _ := by + apply Finset.sum_congr rfl + intro x hx + rw [← Finset.sum_filter] + simp only [Finset.sum_const, nsmul_eq_mul, mul_one, f] + congr 2 + ext y + simp [eq_comm] + have h := Finset.sum_mul_sq_le_sq_mul_sq t (fun _ => (1 : ℝ)) f + simpa only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one, hsum, hsq, t] using h + +end PairCounting + +section PairIntegral +attribute [local instance] Classical.propDecidable +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + + +theorem square_sum_probability_le (F : Finset V) (S : V → Set Ω) + (C : V → V → Set Ω) (hS : ∀ x, MeasurableSet (S x)) + (hC : ∀ x y, MeasurableSet (C x y)) (n : ℝ) + (hpoint : ∀ ω, (∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) ω) ^ 2 ≤ + n * ∑ x ∈ F, ∑ y ∈ F, (C x y).indicator (fun _ => (1 : ℝ)) ω) : + (∑ x ∈ F, μ.real (S x)) ^ 2 ≤ n * ∑ x ∈ F, ∑ y ∈ F, μ.real (C x y) := by + let X := fun ω => ∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) ω + have hX : MemLp X 2 μ := memLp_finsetSum F + (fun x _ => (memLp_const (1 : ℝ)).indicator (hS x)) + have hCi (x y) : Integrable ((C x y).indicator (fun _ => (1 : ℝ))) μ := + (integrable_const (1 : ℝ)).indicator (hC x y) + have hY : Integrable (fun ω => ∑ x ∈ F, ∑ y ∈ F, + (C x y).indicator (fun _ => (1 : ℝ)) ω) μ := + integrable_finsetSum F (fun x _ => integrable_finsetSum F (fun y _ => hCi x y)) + have hv := variance_nonneg X μ + rw [variance_eq_sub hX] at hv + have hi := integral_mono hX.integrable_sq (hY.const_mul n) hpoint + have hx : (∫ ω, X ω ∂μ) = ∑ x ∈ F, μ.real (S x) := by + dsimp only [X] + rw [integral_finsetSum F (fun x _ => (integrable_const (1 : ℝ)).indicator (hS x))] + simp only [integral_indicator_const _ (hS _), smul_eq_mul, mul_one] + have hy : (∫ ω, n * ∑ x ∈ F, ∑ y ∈ F, + (C x y).indicator (fun _ => (1 : ℝ)) ω ∂μ) = + n * ∑ x ∈ F, ∑ y ∈ F, μ.real (C x y) := by + rw [integral_const_mul, integral_finsetSum F + (fun x _ => integrable_finsetSum F (fun y _ => hCi x y))] + congr 1 + apply Finset.sum_congr rfl + intro x _ + rw [integral_finsetSum F (fun y _ => hCi x y)] + simp only [integral_indicator_const _ (hC x _), smul_eq_mul, mul_one] + rw [hx] at hv + rw [hy] at hi + exact (sub_nonneg.mp hv).trans hi + +end PairIntegral + +section CoupledCovers +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] + +omit [Countable V] [Countable E] in +theorem cluster_eq_iff_conn (G : BondGraph V E) (ω : Set E) (x y : V) : + cluster G ω x = cluster G ω y ↔ Conn G ω x y := by + constructor + · intro h + have hh := mem_cluster_self G ω y + rwa [← h] at hh + · exact cluster_eq_of_conn G ω + + +def TouchedCover (G : BondGraph V E) (p q : unitInterval) (n : ℕ) + (labels : E → unitInterval) : Prop := + ∃ f : Fin n → V, ∀ x, (cluster G (openEdges labels p) x).Infinite → + ∃ i, Conn G (openEdges labels q) x (f i) + +theorem measurableSet_touchedCover (G : BondGraph V E) (p q : unitInterval) (n : ℕ) : + MeasurableSet {labels | TouchedCover G p q n labels} := by + have he : {labels | TouchedCover G p q n labels} = + ⋃ f : Fin n → V, ⋂ x : V, ({labels | (cluster G (openEdges labels p) x).Infinite}ᶜ ∪ + ⋃ i : Fin n, {labels | Conn G (openEdges labels q) x (f i)}) := by + ext labels + simp only [TouchedCover, Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_iInter, + Set.mem_union, Set.mem_compl_iff] + simp only [← imp_iff_not_or] + rw [he] + apply MeasurableSet.iUnion + intro f + apply MeasurableSet.iInter + intro x + exact ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)).compl.union + (MeasurableSet.iUnion fun i => (measurableSet_conn G x (f i)).preimage (measurable_openEdges q)) + +omit [Countable V] [Countable E] in + +theorem survivor_count_sq_le (G : BondGraph V E) (p q : unitInterval) (n : ℕ) + (F : Finset V) (labels : E → unitInterval) (h : TouchedCover G p q n labels) : + ((F.filter fun x => (cluster G (openEdges labels p) x).Infinite).card : ℝ) ^ 2 ≤ + n * ∑ x ∈ F, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by + obtain ⟨f, hf⟩ := h + let S := F.filter fun x => (cluster G (openEdges labels p) x).Infinite + let c := cluster G (openEdges labels q) + have hsub : S.image c ⊆ Finset.univ.image (fun i : Fin n => c (f i)) := by + intro C hC + obtain ⟨x, hx, rfl⟩ := Finset.mem_image.mp hC + obtain ⟨i, hi⟩ := hf x (Finset.mem_filter.mp hx).2 + exact Finset.mem_image.mpr ⟨i, Finset.mem_univ _, (cluster_eq_of_conn G _ hi).symm⟩ + have hcard : (S.image c).card ≤ n := + (Finset.card_le_card hsub).trans (by simpa using (Finset.card_image_le (s := (Finset.univ : Finset (Fin n))) + (f := fun i : Fin n => c (f i)))) + have hpair := card_sq_le_image_card_mul_pairs S c + have hpairs : ∑ x ∈ S, ∑ y ∈ S, (if c x = c y then (1 : ℝ) else 0) ≤ + ∑ x ∈ F, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by + simp only [c, cluster_eq_iff_conn] + calc + _ ≤ ∑ x ∈ S, ∑ y ∈ F, if Conn G (openEdges labels q) x y then (1 : ℝ) else 0 := by + apply Finset.sum_le_sum + intro x _ + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun _ _ _ => by split_ifs <;> positivity) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun _ _ _ => Finset.sum_nonneg fun _ _ => by split_ifs <;> positivity) + exact hpair.trans ((mul_le_mul_of_nonneg_left hpairs (Nat.cast_nonneg _)).trans + (mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) + (Finset.sum_nonneg fun _ _ => Finset.sum_nonneg fun _ _ => by split_ifs <;> positivity))) + +end CoupledCovers + +section CoverInvariance +attribute [local instance] Classical.propDecidable + + +theorem labelLaw_map_precomp (b : E ≃ E) : + (labelLaw : Measure (E → unitInterval)).map (fun labels => labels ∘ b) = labelLaw := by + have he : (fun labels : E → unitInterval => labels ∘ b) = + MeasurableEquiv.piCongrLeft (fun _ : E => unitInterval) b.symm := by + funext labels e + have h := MeasurableEquiv.piCongrLeft_apply_apply (β := fun _ : E => unitInterval) + b.symm labels (b e) + simpa only [Equiv.symm_apply_apply, Function.comp_apply] using h.symm + unfold labelLaw + rw [he] + exact Measure.infinitePi_map_piCongrLeft (fun _ : E => (volume : Measure unitInterval)) b.symm + +theorem infinite_cluster_precomp (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (labels : E → unitInterval) (p : unitInterval) (x : V) : + (cluster G (openEdges (labels ∘ b) p) x).Infinite ↔ + (cluster G (openEdges labels p) (a x)).Infinite := by + change (cluster G (b ⁻¹' openEdges labels p) x).Infinite ↔ _ + rw [← cluster_aut G h] + exact (Set.infinite_image_iff (fun _ _ _ _ hab => a.injective hab)).symm + +variable [Countable V] [Countable E] + +omit [Countable V] [Countable E] in +theorem touchedCover_precomp (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (labels : E → unitInterval) (p q : unitInterval) (n : ℕ) : + TouchedCover G p q n (labels ∘ b) ↔ TouchedCover G p q n labels := by + constructor + · rintro ⟨f, hf⟩ + refine ⟨fun i => a (f i), fun x hx => ?_⟩ + have hs : (cluster G (openEdges (labels ∘ b) p) (a.symm x)).Infinite := + (infinite_cluster_precomp G h labels p (a.symm x)).mpr (by simpa using hx) + obtain ⟨i, hi⟩ := hf _ hs + exact ⟨i, by simpa using (conn_aut_iff G h (openEdges labels q) (a.symm x) (f i)).mp hi⟩ + · rintro ⟨f, hf⟩ + refine ⟨fun i => a.symm (f i), fun x hx => ?_⟩ + obtain ⟨i, hi⟩ := hf (a x) ((infinite_cluster_precomp G h labels p x).mp hx) + exact ⟨i, (conn_aut_iff G h (openEdges labels q) x (a.symm (f i))).mpr (by simpa using hi)⟩ + +theorem cover_survival_aut (G : BondGraph V E) (p q : unitInterval) (n : ℕ) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : + (labelLaw : Measure (E → unitInterval)).real + {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) (a x)).Infinite} = + labelLaw.real {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite} := by + have hm : Measurable (fun labels : E → unitInterval => labels ∘ b) := + Measurable.of_eval (fun e => measurable_pi_apply (b e)) + have hs : MeasurableSet {labels | TouchedCover G p q n labels ∧ + (cluster G (openEdges labels p) x).Infinite} := + (measurableSet_touchedCover G p q n).inter + ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)) + have he : {labels | TouchedCover G p q n labels ∧ + (cluster G (openEdges labels p) (a x)).Infinite} = + (fun labels : E → unitInterval => labels ∘ b) ⁻¹' + {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite} := by + ext labels + simp only [Set.mem_ofPred_eq, Set.mem_preimage, touchedCover_precomp G h, + infinite_cluster_precomp G h] + simp only [Measure.real] + rw [he, ← Measure.map_apply hm hs, labelLaw_map_precomp] + +end CoverInvariance + +section CoverObstruction +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] + +theorem cover_survival_square_sum_le (G : BondGraph V E) (p q : unitInterval) (n : ℕ) + {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G q A) (F : Finset V) : + (∑ x ∈ F, (labelLaw : Measure (E → unitInterval)).real {labels | + TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite}) ^ 2 ≤ + n * ‖A‖ * F.card := by + let S := fun x => {labels | TouchedCover G p q n labels ∧ + (cluster G (openEdges labels p) x).Infinite} + let C := fun x y => {labels | Conn G (openEdges labels q) x y} + have hS (x) : MeasurableSet (S x) := + (measurableSet_touchedCover G p q n).inter + ((measurableSet_infinite_cluster G x).preimage (measurable_openEdges p)) + have hC (x y) : MeasurableSet (C x y) := + (measurableSet_conn G x y).preimage (measurable_openEdges q) + have hpoint (labels : E → unitInterval) : + (∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) labels) ^ 2 ≤ + (n : ℝ) * ∑ x ∈ F, ∑ y ∈ F, (C x y).indicator (fun _ => (1 : ℝ)) labels := by + by_cases hc : TouchedCover G p q n labels + · have he : ∑ x ∈ F, (S x).indicator (fun _ => (1 : ℝ)) labels = + ((F.filter fun x => (cluster G (openEdges labels p) x).Infinite).card : ℝ) := by + simp only [S, Set.indicator, Set.mem_ofPred_eq, hc, true_and] + rw [← Finset.sum_filter] + simp + rw [he] + simpa only [C, Set.indicator, Set.mem_ofPred_eq] using + survivor_count_sq_le G p q n F labels hc + · simp only [S, Set.indicator, Set.mem_ofPred_eq, hc, false_and, ite_false, + Finset.sum_const_zero, zero_pow (by decide : 2 ≠ 0)] + exact mul_nonneg (Nat.cast_nonneg _) (Finset.sum_nonneg fun _ _ => + Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _) + have h := square_sum_probability_le (labelLaw : Measure (E → unitInterval)) F S C hS hC + (n : ℝ) hpoint + have he (x y) : labelLaw.real (C x y) = twoPoint G q x y := + (twoPoint_eq_labelLaw G q x y).symm + simp only [he] at h + exact h.trans (by simpa only [mul_assoc] using + mul_le_mul_of_nonneg_left (sum_twoPoint_le_norm_card G q hA F) (Nat.cast_nonneg n)) + + + +theorem measure_cover_survival_eq_zero [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p q : unitInterval) (hq : OperatorBounded G q) (n : ℕ) (x : V) : + (labelLaw : Measure (E → unitInterval)) {labels | TouchedCover G p q n labels ∧ + (cluster G (openEdges labels p) x).Infinite} = 0 := by + apply (measureReal_eq_zero_iff).mp + by_contra hnz + let θ := (labelLaw : Measure (E → unitInterval)).real {labels | TouchedCover G p q n labels ∧ + (cluster G (openEdges labels p) x).Infinite} + have hθ : 0 < θ := lt_of_le_of_ne measureReal_nonneg (Ne.symm hnz) + obtain ⟨A, hA⟩ := hq + obtain ⟨m, hm⟩ := exists_nat_gt ((n : ℝ) * ‖A‖ / θ ^ 2 + 1) + obtain ⟨F, hF, hcard⟩ := (vertexOrbit_infinite G hconn hloc hqt x).exists_subset_card_eq m + have he (y : V) (hy : y ∈ F) : (labelLaw : Measure (E → unitInterval)).real + {labels | TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) y).Infinite} = θ := by + obtain ⟨a, b, hab, hay⟩ := hF hy + rw [← hay] + exact cover_survival_aut G p q n hab x + have hh := cover_survival_square_sum_le G p q n hA F + rw [Finset.sum_congr rfl he] at hh + simp only [Finset.sum_const, nsmul_eq_mul, hcard] at hh + have hθsq : 0 < θ ^ 2 := sq_pos_of_pos hθ + have hm0 : (0 : ℝ) < m := lt_trans (by positivity : (0 : ℝ) < (n : ℝ) * ‖A‖ / θ ^ 2 + 1) hm + have hlt : (n : ℝ) * ‖A‖ < (m : ℝ) * θ ^ 2 := by + apply (div_lt_iff₀ hθsq).mp + linarith + nlinarith + +end CoverObstruction + +section FiniteChanges +attribute [local instance] Classical.propDecidable + + +theorem cluster_union_subset (G : BondGraph V E) (ω : Set E) (F : Set E) (x : V) : + cluster G (ω ∪ F) x ⊆ cluster G ω x ∪ ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G ω z := by + intro y hy + induction hy with + | refl => exact Or.inl (mem_cluster_self G ω x) + | @tail y z hy hed ih => + obtain ⟨e, he, heq⟩ := hed + rcases he with he | he + · have hyz : Conn G ω y z := (conn_refl G ω y).tail ⟨e, he, heq⟩ + rcases ih with ih | ih + · exact Or.inl (conn_trans G ω ih hyz) + · right + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] at ih ⊢ + obtain ⟨e', he', w, hw, hwy⟩ := ih + exact ⟨e', he', w, hw, conn_trans G ω hwy hyz⟩ + · right + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] + exact ⟨e, he, z, heq ▸ by simp, conn_refl G ω z⟩ + +theorem exists_infinite_cluster_mono (G : BondGraph V E) {ω ω' : Set E} (h : ω ⊆ ω') : + (∃ x, (cluster G ω x).Infinite) → ∃ x, (cluster G ω' x).Infinite := by + rintro ⟨x, hx⟩ + exact ⟨x, hx.mono (fun _ hy => conn_mono G h hy)⟩ + + +theorem exists_infinite_cluster_sdiff (G : BondGraph V E) (ω : Set E) + {F : Set E} (hF : F.Finite) : + (∃ x, (cluster G (ω \ F) x).Infinite) ↔ ∃ x, (cluster G ω x).Infinite := by + constructor + · exact exists_infinite_cluster_mono G Set.sdiff_subset + · contrapose! + intro h x + have hs : (cluster G (ω \ F) x ∪ + ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G (ω \ F) z).Finite := by + apply (h x).union + apply hF.biUnion + intro e _ + have he : {z | z ∈ G e}.Finite := by + exact (G e).toFinset.finite_toSet.subset (fun z hz => by simpa using hz) + exact he.biUnion (fun z _ => h z) + apply hs.subset + apply Set.Subset.trans (fun y hy => conn_mono G (Set.subset_sdiff_union _ _) hy) + exact cluster_union_subset G (ω \ F) F x + +end FiniteChanges + +section PercolationZeroOne +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] + +omit [Countable V] [Countable E] in +theorem infiniteClusters_nonempty_iff (G : BondGraph V E) (ω : Set E) : + (infiniteClusters G ω).Nonempty ↔ ∃ x, (cluster G ω x).Infinite := by + constructor + · rintro ⟨C, hC, x, rfl⟩ + exact ⟨x, hC⟩ + · rintro ⟨x, hx⟩ + exact ⟨cluster G ω x, hx, x, rfl⟩ + + theorem measurableSet_exists_infinite_cluster (G : BondGraph V E) : + MeasurableSet {ω : Set E | ∃ x, (cluster G ω x).Infinite} := by + simpa only [Set.ofPred_exists] using MeasurableSet.iUnion (fun x => measurableSet_infinite_cluster G x) + + theorem infinite_cluster_zero_one (G : BondGraph V E) (p : unitInterval) : + (labelLaw : Measure (E → unitInterval)) + {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} = 0 ∨ + (labelLaw : Measure (E → unitInterval)) + {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} = 1 := by + let σ : E → MeasurableSpace (E → unitInterval) := fun e => + MeasurableSpace.comap (fun labels : E → unitInterval => labels e) inferInstance + have hle (e) : σ e ≤ (inferInstance : MeasurableSpace (E → unitInterval)) := (measurable_pi_apply e).comap_le + have hi : iIndep σ (labelLaw : Measure (E → unitInterval)) := + iIndepFun_infinitePi (X := fun (_ : E) (x : unitInterval) => x) (fun _ => measurable_id) + have htail : MeasurableSet[Filter.limsup σ Filter.cofinite] + {labels | ∃ x, (cluster G (openEdges labels p) x).Infinite} := by + rw [Filter.limsup_eq_iInf_iSup] + apply MeasurableSpace.measurableSet_iInf.mpr + intro s + apply MeasurableSpace.measurableSet_iInf.mpr + intro hs + have hfin : sᶜ.Finite := Filter.mem_cofinite.mp hs + let m := ⨆ e ∈ s, σ e + have hm : @Measurable (E → unitInterval) (Set E) m inferInstance + (fun labels => openEdges labels p ∩ s) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + change @Measurable (E → unitInterval) Prop m inferInstance (fun labels => labels e ≤ p ∧ e ∈ s) + by_cases he : e ∈ s + · have hev : @Measurable (E → unitInterval) unitInterval m inferInstance + (fun labels => labels e) := + Measurable.of_comap_le (le_iSup_of_le e (le_iSup_of_le he le_rfl)) + simpa only [he, and_true, Function.comp_def] + using (measurable_threshold p).comp hev + · simpa only [he, and_false] + using (measurable_const : @Measurable (E → unitInterval) Prop m inferInstance + (fun _ => False)) + have heq : {labels : E → unitInterval | ∃ x, (cluster G (openEdges labels p) x).Infinite} = + {labels | ∃ x, (cluster G (openEdges labels p ∩ s) x).Infinite} := by + ext labels + simpa only [Set.sdiff_compl, Set.mem_ofPred_eq] using + (exists_infinite_cluster_sdiff G (openEdges labels p) hfin).symm + rw [heq] + exact (measurableSet_exists_infinite_cluster G).preimage hm + exact measure_zero_or_one_of_measurableSet_limsup + (s := σ) (f := Filter.cofinite) (p := Set.Finite) + (ns := fun F : Finset E => (F : Set E)) hle hi + (fun t ht => by simpa using ht) + (fun F H => ⟨F ∪ H, Finset.coe_subset.mpr Finset.subset_union_left, + Finset.coe_subset.mpr Finset.subset_union_right⟩) + (fun F => F.finite_toSet) (fun e => ⟨{e}, by simp⟩) htail + +end PercolationZeroOne + +section CoupledInterval +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] + + theorem exists_infinite_cluster_probability_mono (G : BondGraph V E) {p q : unitInterval} + (hpq : p ≤ q) : + law p {ω | (infiniteClusters G ω).Nonempty} ≤ + law q {ω | (infiniteClusters G ω).Nonempty} := by + have hm : MeasurableSet {ω : Set E | (infiniteClusters G ω).Nonempty} := by + simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G + rw [← map_openEdges p, ← map_openEdges q, + Measure.map_apply (measurable_openEdges p) hm, + Measure.map_apply (measurable_openEdges q) hm] + apply measure_mono + intro labels h + simp only [Set.mem_preimage, Set.mem_ofPred_eq, infiniteClusters_nonempty_iff] at h ⊢ + exact exists_infinite_cluster_mono G (openEdges_mono labels hpq) h + + theorem ae_exists_infinite_cluster_of_pc_lt (G : BondGraph V E) (p : unitInterval) + (hp : pc G < p) : + ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), + ∃ x, (cluster G (openEdges labels p) x).Infinite := by + obtain ⟨q, hq, hqp⟩ := sInf_lt_iff.mp hp + have hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty} := + lt_of_lt_of_le hq (exists_infinite_cluster_probability_mono G hqp.le) + have hm : MeasurableSet {ω : Set E | (infiniteClusters G ω).Nonempty} := by + simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G + rw [← map_openEdges p, Measure.map_apply (measurable_openEdges p) hm] at hpos + simp only [Set.preimage_ofPred_eq, infiniteClusters_nonempty_iff] at hpos + have hpone := (infinite_cluster_zero_one G p).resolve_left (ne_of_gt hpos) + exact (mem_ae_iff_prob_eq_one + ((measurableSet_exists_infinite_cluster G).preimage (measurable_openEdges p))).mpr hpone + +omit [Countable V] [Countable E] in + theorem touchedCover_of_finite_infiniteClusters (G : BondGraph V E) + (labels : E → unitInterval) {p r q : unitInterval} (hpr : p ≤ r) (hrq : r ≤ q) + (hfinite : (infiniteClusters G (openEdges labels r)).Finite) : + ∃ n, TouchedCover G p q n labels := by + let C := infiniteClusters G (openEdges labels r) + let : Fintype C := hfinite.fintype + let f : C → V := fun c => Classical.choose c.property.2 + have hf (c : C) : c.val = cluster G (openEdges labels r) (f c) := + Classical.choose_spec c.property.2 + refine ⟨Fintype.card C, fun i => f ((Fintype.equivFin C).symm i), ?_⟩ + intro x hx + have hx' : (cluster G (openEdges labels r) x).Infinite := + hx.mono (fun _ hy => conn_mono G (openEdges_mono labels hpr) hy) + let c : C := ⟨cluster G (openEdges labels r) x, hx', x, rfl⟩ + refine ⟨Fintype.equivFin C c, ?_⟩ + simp only [Equiv.symm_apply_apply] + apply conn_mono G (openEdges_mono labels hrq) + change f c ∈ cluster G (openEdges labels r) x + change f c ∈ c.val + rw [hf c] + exact mem_cluster_self G _ _ + + + + theorem coupled_interval [Infinite V] (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p q : unitInterval) (hp : pc G < p) (hq : OperatorBounded G q) : + ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), + ∀ r ∈ Set.Icc p q, (infiniteClusters G (openEdges labels r)).Infinite := by + have hall : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), ∀ n x, + ¬(TouchedCover G p q n labels ∧ (cluster G (openEdges labels p) x).Infinite) := by + rw [ae_all_iff] + intro n + rw [ae_all_iff] + intro x + apply ae_iff.mpr + simpa only [not_not] using measure_cover_survival_eq_zero G hconn hloc hqt p q hq n x + filter_upwards [hall, ae_exists_infinite_cluster_of_pc_lt G p hp] with labels hlabels hex + intro r hr + by_contra hfinite + obtain ⟨n, hn⟩ := touchedCover_of_finite_infiniteClusters G labels hr.1 hr.2 + (Set.not_infinite.mp hfinite) + obtain ⟨x, hx⟩ := hex + exact hlabels n x ⟨hn, hx⟩ + +end CoupledInterval + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/ClusterCount.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/ClusterCount.lean index 62e8bcb2be82526f62b9c49336868708b9c3ce28..ace38eca82a6b05945c19cd027473e9fbeacf713 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/ClusterCount.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/ClusterCount.lean @@ -1,147 +1,147 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Criticality.Connectivity -import OAI.Probability.UnimodularPercolation.Criticality.Ergodicity -import OAI.Probability.UnimodularPercolation.Criticality.FiniteChanges - -namespace OAI - -/-! Exclusion of positive finite critical cluster counts. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory ProbabilityTheory -open scoped ENNReal -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem law_invariant_zero_one [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (A : Set (Set E)) (hA : MeasurableSet A) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → - (fun ω : Set E => b ⁻¹' ω) ⁻¹' A = A) : law p A = 0 ∨ law p A = 1 := by - have hm : law p A = labelLaw ((fun l => openEdges l p) ⁻¹' A) := by - rw [←map_openEdges p,Measure.map_apply (measurable_openEdges p) hA] - rw [hm] - apply label_invariant_zero_one G hconn hloc hqt _ (hA.preimage (measurable_openEdges p)) - intro a b hab - ext l - have h := Set.ext_iff.mp (hinv a b hab) (openEdges l p) - exact h - -theorem unique_infinite_cluster_aut_iff (G : BondGraph V E) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (ω : Set E) : - (∃! C, C ∈ infiniteClusters G (b ⁻¹' ω)) ↔ ∃! C, C ∈ infiniteClusters G ω := by - have hInf (x : V) : (cluster G (b ⁻¹' ω) x).Infinite ↔ (cluster G ω (a x)).Infinite := by - rw [←cluster_aut G hab ω x] - exact (Set.infinite_image_iff a.injective.injOn).symm - rw [unique_infinite_cluster_iff,unique_infinite_cluster_iff] - constructor - · rintro ⟨x,hx,h⟩ - refine ⟨a x,(hInf x).mp hx,?_⟩ - intro y hy - have hh : (cluster G (b ⁻¹' ω) (a.symm y)).Infinite := (hInf _).mpr (by simpa using hy) - simpa only [Equiv.apply_symm_apply] using (conn_aut_iff G hab ω x (a.symm y)).mp (h _ hh) - · rintro ⟨x,hx,h⟩ - refine ⟨a.symm x,(hInf _).mpr (by simpa using hx),?_⟩ - intro y hy - apply (conn_aut_iff G hab ω (a.symm x) y).mpr - simpa only [Equiv.apply_symm_apply] using h (a y) ((hInf y).mp hy) - -theorem critical_unique_probability_zero [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) : law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} = 0 := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - refine (law_invariant_zero_one G hconn hloc hqt (pc G) _ - (measurableSet_unique_infinite_cluster G) ?_).resolve_right - (critical_not_ae_unique G hconn hloc hqt hh) - intro a b hab - ext ω - exact unique_infinite_cluster_aut_iff G hab ω - -def InfiniteCover (G : BondGraph V E) (R : Finset V) (ω : Set E) : Prop := - ∀ y, (cluster G ω y).Infinite → ∃ z ∈ R, Conn G ω y z - -theorem measurableSet_infiniteCover [Countable V] [Countable E] - (G : BondGraph V E) (R : Finset V) : MeasurableSet {ω | InfiniteCover G R ω} := by - have he : {ω | InfiniteCover G R ω} = - ⋂ y, ({ω | (cluster G ω y).Infinite}ᶜ ∪ ⋃ z ∈ R, {ω | Conn G ω y z}) := by - ext ω - simp only [InfiniteCover,Set.mem_iInter,Set.mem_union,Set.mem_compl_iff, - Set.mem_iUnion,Set.mem_ofPred_eq,imp_iff_not_or] - simp only [exists_prop] - rw [he] - exact MeasurableSet.iInter fun y => (measurableSet_infinite_cluster G y).compl.union - (R.measurableSet_biUnion fun z _ => measurableSet_conn G y z) - -theorem unique_pos_of_cover_pos [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (p : unitInterval) (hp : 0 < p) - (hp1 : p < 1) (x : V) (R : Finset V) - (hpos : 0 < law p {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω}) : - 0 < law p {ω | ∃! C, C ∈ infiniteClusters G ω} := by - obtain ⟨F,hF⟩ := finite_connecting_edges G hconn x R - apply finiteOverwrite_pos p hp hp1 F F (Finset.Subset.refl _) - {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} _ - (measurableSet_unique_infinite_cluster G) hpos - rintro ω ⟨hx,hcover⟩ - have how : finiteOverwrite F F ω = ω ∪ (F:Set E) := by - ext e - simp only [finiteOverwrite,Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] - tauto - rw [how] - apply finite_opening_unique G ω F x hx - intro y hy - obtain ⟨z,hz,hyz⟩ := hcover y hy - exact conn_trans G _ (conn_mono G Set.subset_union_right (hF z hz)) - (conn_mono G Set.subset_union_left (conn_symm G _ hyz)) - -theorem critical_infiniteCover_survival_zero [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (x : V) (R : Finset V) : - law (pc G) {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} = 0 := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - by_contra h - have hp := unique_pos_of_cover_pos G hconn (pc G) (pc_pos G hloc hqt) - (pc_lt_one_of_nonamenable G hconn hloc hqt hh) x R (pos_iff_ne_zero.mpr h) - rw [critical_unique_probability_zero G hconn hloc hqt hh] at hp - exact lt_irrefl _ hp - -theorem critical_finite_count_empty_ae [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) : - ∀ᵐ ω ∂law (pc G), (infiniteClusters G ω).Finite → infiniteClusters G ω = ∅ := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - have ha (x : V) (R : Finset V) : - ∀ᵐ ω ∂law (pc G), ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by - apply ae_iff.mpr - simpa only [not_not] using critical_infiniteCover_survival_zero G hconn hloc hqt hh x R - have hall : ∀ᵐ ω ∂law (pc G), ∀ x : V, ∀ R : Finset V, - ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by - exact ae_all_iff.mpr fun x => ae_all_iff.mpr (ha x) - filter_upwards [hall] with ω hω - intro hfin - by_contra hn - obtain ⟨C,hC⟩ := Set.nonempty_iff_ne_empty.mpr hn - obtain ⟨hx,x,rfl⟩ := hC - let f : Set V → V := fun C => if hc : C ∈ infiniteClusters G ω then - Classical.choose hc.2 else x - have hf (C : Set V) (hC : C ∈ infiniteClusters G ω) : C = cluster G ω (f C) := by - simp only [f,dite_eq_left hC] - exact Classical.choose_spec hC.2 - let R : Finset V := hfin.toFinset.image f - apply hω x R ⟨hx,?_⟩ - intro y hy - have hc : cluster G ω y ∈ infiniteClusters G ω := ⟨hy,y,rfl⟩ - refine ⟨f (cluster G ω y),Finset.mem_image.mpr ⟨_,hfin.mem_toFinset.mpr hc,rfl⟩,?_⟩ - have he := hf _ hc - exact (Set.ext_iff.mp he _).mpr (mem_cluster_self G ω (f (cluster G ω y))) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Criticality.Connectivity +import OAI.Probability.UnimodularPercolation.Criticality.Ergodicity +import OAI.Probability.UnimodularPercolation.Criticality.FiniteChanges + +namespace OAI + +/-! Exclusion of positive finite critical cluster counts. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory ProbabilityTheory +open scoped ENNReal +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem law_invariant_zero_one [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (A : Set (Set E)) (hA : MeasurableSet A) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → + (fun ω : Set E => b ⁻¹' ω) ⁻¹' A = A) : law p A = 0 ∨ law p A = 1 := by + have hm : law p A = labelLaw ((fun l => openEdges l p) ⁻¹' A) := by + rw [←map_openEdges p,Measure.map_apply (measurable_openEdges p) hA] + rw [hm] + apply label_invariant_zero_one G hconn hloc hqt _ (hA.preimage (measurable_openEdges p)) + intro a b hab + ext l + have h := Set.ext_iff.mp (hinv a b hab) (openEdges l p) + exact h + +theorem unique_infinite_cluster_aut_iff (G : BondGraph V E) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (ω : Set E) : + (∃! C, C ∈ infiniteClusters G (b ⁻¹' ω)) ↔ ∃! C, C ∈ infiniteClusters G ω := by + have hInf (x : V) : (cluster G (b ⁻¹' ω) x).Infinite ↔ (cluster G ω (a x)).Infinite := by + rw [←cluster_aut G hab ω x] + exact (Set.infinite_image_iff a.injective.injOn).symm + rw [unique_infinite_cluster_iff,unique_infinite_cluster_iff] + constructor + · rintro ⟨x,hx,h⟩ + refine ⟨a x,(hInf x).mp hx,?_⟩ + intro y hy + have hh : (cluster G (b ⁻¹' ω) (a.symm y)).Infinite := (hInf _).mpr (by simpa using hy) + simpa only [Equiv.apply_symm_apply] using (conn_aut_iff G hab ω x (a.symm y)).mp (h _ hh) + · rintro ⟨x,hx,h⟩ + refine ⟨a.symm x,(hInf _).mpr (by simpa using hx),?_⟩ + intro y hy + apply (conn_aut_iff G hab ω (a.symm x) y).mpr + simpa only [Equiv.apply_symm_apply] using h (a y) ((hInf y).mp hy) + +theorem critical_unique_probability_zero [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) : law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} = 0 := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + refine (law_invariant_zero_one G hconn hloc hqt (pc G) _ + (measurableSet_unique_infinite_cluster G) ?_).resolve_right + (critical_not_ae_unique G hconn hloc hqt hh) + intro a b hab + ext ω + exact unique_infinite_cluster_aut_iff G hab ω + +def InfiniteCover (G : BondGraph V E) (R : Finset V) (ω : Set E) : Prop := + ∀ y, (cluster G ω y).Infinite → ∃ z ∈ R, Conn G ω y z + +theorem measurableSet_infiniteCover [Countable V] [Countable E] + (G : BondGraph V E) (R : Finset V) : MeasurableSet {ω | InfiniteCover G R ω} := by + have he : {ω | InfiniteCover G R ω} = + ⋂ y, ({ω | (cluster G ω y).Infinite}ᶜ ∪ ⋃ z ∈ R, {ω | Conn G ω y z}) := by + ext ω + simp only [InfiniteCover,Set.mem_iInter,Set.mem_union,Set.mem_compl_iff, + Set.mem_iUnion,Set.mem_ofPred_eq,imp_iff_not_or] + simp only [exists_prop] + rw [he] + exact MeasurableSet.iInter fun y => (measurableSet_infinite_cluster G y).compl.union + (R.measurableSet_biUnion fun z _ => measurableSet_conn G y z) + +theorem unique_pos_of_cover_pos [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (p : unitInterval) (hp : 0 < p) + (hp1 : p < 1) (x : V) (R : Finset V) + (hpos : 0 < law p {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω}) : + 0 < law p {ω | ∃! C, C ∈ infiniteClusters G ω} := by + obtain ⟨F,hF⟩ := finite_connecting_edges G hconn x R + apply finiteOverwrite_pos p hp hp1 F F (Finset.Subset.refl _) + {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} _ + (measurableSet_unique_infinite_cluster G) hpos + rintro ω ⟨hx,hcover⟩ + have how : finiteOverwrite F F ω = ω ∪ (F:Set E) := by + ext e + simp only [finiteOverwrite,Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] + tauto + rw [how] + apply finite_opening_unique G ω F x hx + intro y hy + obtain ⟨z,hz,hyz⟩ := hcover y hy + exact conn_trans G _ (conn_mono G Set.subset_union_right (hF z hz)) + (conn_mono G Set.subset_union_left (conn_symm G _ hyz)) + +theorem critical_infiniteCover_survival_zero [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (x : V) (R : Finset V) : + law (pc G) {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} = 0 := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + by_contra h + have hp := unique_pos_of_cover_pos G hconn (pc G) (pc_pos G hloc hqt) + (pc_lt_one_of_nonamenable G hconn hloc hqt hh) x R (pos_iff_ne_zero.mpr h) + rw [critical_unique_probability_zero G hconn hloc hqt hh] at hp + exact lt_irrefl _ hp + +theorem critical_finite_count_empty_ae [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) : + ∀ᵐ ω ∂law (pc G), (infiniteClusters G ω).Finite → infiniteClusters G ω = ∅ := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + have ha (x : V) (R : Finset V) : + ∀ᵐ ω ∂law (pc G), ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by + apply ae_iff.mpr + simpa only [not_not] using critical_infiniteCover_survival_zero G hconn hloc hqt hh x R + have hall : ∀ᵐ ω ∂law (pc G), ∀ x : V, ∀ R : Finset V, + ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by + exact ae_all_iff.mpr fun x => ae_all_iff.mpr (ha x) + filter_upwards [hall] with ω hω + intro hfin + by_contra hn + obtain ⟨C,hC⟩ := Set.nonempty_iff_ne_empty.mpr hn + obtain ⟨hx,x,rfl⟩ := hC + let f : Set V → V := fun C => if hc : C ∈ infiniteClusters G ω then + Classical.choose hc.2 else x + have hf (C : Set V) (hC : C ∈ infiniteClusters G ω) : C = cluster G ω (f C) := by + simp only [f,dite_eq_left hC] + exact Classical.choose_spec hC.2 + let R : Finset V := hfin.toFinset.image f + apply hω x R ⟨hx,?_⟩ + intro y hy + have hc : cluster G ω y ∈ infiniteClusters G ω := ⟨hy,y,rfl⟩ + refine ⟨f (cluster G ω y),Finset.mem_image.mpr ⟨_,hfin.mem_toFinset.mpr hc,rfl⟩,?_⟩ + have he := hf _ hc + exact (Set.ext_iff.mp he _).mpr (mem_cluster_self G ω (f (cluster G ω y))) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Connectivity.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Connectivity.lean index 1a7ec958391826b65dccda83750d0b559a722b93..e10744b4a3dda81c2627da4cd17d028f6280c32f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Connectivity.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Connectivity.lean @@ -1,194 +1,194 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Critical connection probabilities and nonamenable growth. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory Filter -open scoped Topology -universe u v -variable {V : Type u} {E : Type v} - -theorem connectivity_twoPoint_mul_le [Countable E] (G : BondGraph V E) (p : unitInterval) - (x y z : V) : twoPoint G p x y * twoPoint G p y z ≤ twoPoint G p x z := by - have h := association_finiteWitness p {ω | Conn G ω x y} {ω | Conn G ω y z} - (fun _ _ hst hxy => conn_mono G hst hxy) - (fun _ _ hst hyz => conn_mono G hst hyz) - (finiteWitness_conn G x y) (finiteWitness_conn G y z) - refine h.trans (measureReal_mono ?_) - intro ω hω - exact conn_trans G ω hω.1 hω.2 - -theorem reachBall_split (G : BondGraph V E) (x z : V) (n m : ℕ) - (hz : z ∈ reachBall G x (n+m)) : - ∃ y ∈ reachBall G x n, z ∈ reachBall G y m := by - induction m generalizing z with - | zero => - exact ⟨z,by simpa using hz,by simp [reachBall]⟩ - | succ m ih => - change z ∈ reachBall G x (n+m) ∪ _ at hz - rcases hz with hz | hz - · obtain ⟨y,hy,hyz⟩ := ih z hz - exact ⟨y,hy,Or.inl hyz⟩ - · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hz - obtain ⟨z',hz',hzz⟩ := hz - obtain ⟨y,hy,hyz⟩ := ih z' hz' - refine ⟨y,hy,Or.inr ?_⟩ - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] - exact ⟨z',hyz,hzz⟩ - -theorem twoPoint_block_lower [Countable E] (G : BondGraph V E) (p : unitInterval) - (n : ℕ) (c : ℝ) (hc : 0 ≤ c) - (h : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) - (m : ℕ) (x y : V) (hy : y ∈ reachBall G x (n*m)) : - c^m ≤ twoPoint G p x y := by - induction m generalizing x y with - | zero => - simp only [mul_zero,reachBall,Set.mem_singleton_iff] at hy - subst y - simp [twoPoint_self] - | succ m ih => - rw [Nat.mul_succ] at hy - obtain ⟨z,hz,hzy⟩ := reachBall_split G x y (n*m) n hy - calc - c^(m+1) = c^m*c := pow_succ _ _ - _ ≤ twoPoint G p x z * twoPoint G p z y := - mul_le_mul (ih x z hz) (h z y hzy) hc (twoPoint_nonneg G p x z) - _ ≤ twoPoint G p x y := connectivity_twoPoint_mul_le G p x z y - -theorem isoperimetric_ball_growth (G : BondGraph V E) (hloc : LocallyFinite G) - (hh : 0 < hV G) (x : V) (n : ℕ) : - (1+hV G)^n ≤ ((reachBall G x n).ncard : ℝ) := by - classical - induction n with - | zero => simp [reachBall] - | succ n ih => - let B := (finite_reachBall hloc x n).toFinset - have heq : reachBall G x (n+1) = reachBall G x n ∪ vertexBoundary G B := by - ext y - simp only [reachBall,Set.mem_union,Set.mem_iUnion,Set.mem_ofPred_eq,vertexBoundary] - constructor - · rintro (hy | ⟨z,hz,hzy⟩) - · exact Or.inl hy - · by_cases hy : y ∈ reachBall G x n - · exact Or.inl hy - · exact Or.inr ⟨by simpa [B] using hy,z,by simpa [B] using hz,hzy⟩ - · rintro (hy | ⟨_,z,hz,hzy⟩) - · exact Or.inl hy - · exact Or.inr ⟨z,by simpa [B] using hz,hzy⟩ - have hd : Disjoint (reachBall G x n) (vertexBoundary G B) := by - apply Set.disjoint_left.mpr - intro y hy hb - exact hb.1 (by simpa [B] using hy) - have hb := hV_mul_card_le G B - have hcard : B.card = (reachBall G x n).ncard := - (Set.ncard_eq_toFinset_card _ _).symm - rw [hcard] at hb - rw [heq,Set.ncard_union_eq hd (finite_reachBall hloc x n) - (finite_vertexBoundary G hloc B),Nat.cast_add,pow_succ] - have hh0 : 0 ≤ 1+hV G := by linarith - nlinarith [mul_le_mul_of_nonneg_right ih hh0] - -theorem subcritical_block_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (p : unitInterval) (hp : p < pc G) - (n : ℕ) (c : ℝ) (hc : 0 ≤ c) - (h : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) : - (1+hV G)^n*c ≤ 1 := by - classical - by_contra hbad - have hgt : 1 < (1+hV G)^n*c := lt_of_not_ge hbad - let x : V := Classical.arbitrary V - have hbound (m : ℕ) : ((1+hV G)^n*c)^m ≤ susceptibility G p x := by - let B := (finite_reachBall hloc x (n*m)).toFinset - calc - ((1+hV G)^n*c)^m = (1+hV G)^(n*m)*c^m := by rw [mul_pow,pow_mul] - _ ≤ (B.card:ℝ)*c^m := by - simpa only [B, ← Set.ncard_eq_toFinset_card] using mul_le_mul_of_nonneg_right - (isoperimetric_ball_growth G hloc hh x (n*m)) (pow_nonneg hc m) - _ = ∑ y ∈ B, c^m := by simp - _ ≤ ∑ y ∈ B, twoPoint G p x y := by - apply Finset.sum_le_sum - intro y hy - exact twoPoint_block_lower G p n c hc h m x y (by simpa [B] using hy) - _ ≤ susceptibility G p x := - (summable_twoPoint_subcritical G hloc hqt p hp x).sum_le_tsum B - (fun y _ => twoPoint_nonneg G p x y) - obtain ⟨m,hm⟩ := pow_unbounded_of_one_lt (susceptibility G p x) hgt - exact (not_lt_of_ge (hbound m)) hm - -theorem uniform_ball_lower_below [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (q : unitInterval) (hq : 0 < q) (n : ℕ) (a c : ℝ) (hac : a < c) - (h : ∀ x y, c ≤ twoPoint G q x y) : - ∃ p : unitInterval, p < q ∧ ∀ x y, y ∈ reachBall G x n → a < twoPoint G p x y := by - classical - obtain ⟨R,hR⟩ := hqt - obtain ⟨ps,hps,hpsq,ht⟩ := exists_seq_strictMono_tendsto' hq - have hev : ∀ᶠ k in atTop, ∀ o ∈ R, ∀ y ∈ reachBall G o n, - a < twoPoint G (ps k) o y := by - apply (eventually_all_finset R).mpr - intro o _ - apply (eventually_all_finite (finite_reachBall hloc o n)).mpr - intro y _ - exact (twoPoint_tendsto_of_monotone G ps hps.monotone q - (fun k => (hpsq k).2.le) ht o y).eventually (eventually_gt_nhds (hac.trans_le (h o y))) - obtain ⟨k,hk⟩ := hev.exists - refine ⟨ps k,(hpsq k).2,?_⟩ - intro x y hy - obtain ⟨o,ho,g,b,hg,hgx⟩ := hR x - have hy' : g.symm y ∈ reachBall G o n := by - apply (mem_reachBall_aut_iff G hg o (g.symm y) n).mp - simpa only [g.apply_symm_apply,hgx] using hy - have hb := hk o ho (g.symm y) hy' - have he := twoPoint_aut G (ps k) hg o (g.symm y) - rw [g.apply_symm_apply,hgx] at he - rwa [he] - -theorem critical_twoPoint_no_uniform_positive [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (c : ℝ) (hc : 0 < c) : - ¬ (∀ x y, c ≤ twoPoint G (pc G) x y) := by - intro h - have ha : 0 < c/2 := by positivity - obtain ⟨n,hn⟩ := pow_unbounded_of_one_lt (1/(c/2)) (show 1 < 1+hV G by linarith) - obtain ⟨p,hp,hball⟩ := uniform_ball_lower_below G hloc hqt (pc G) - (pc_pos G hloc hqt) n (c/2) c (by linarith) h - have hb := subcritical_block_bound G hloc hqt hh p hp n (c/2) ha.le - (fun x y hy => (hball x y hy).le) - exact (not_lt_of_ge hb) ((div_lt_iff₀ ha).mp hn) - -theorem critical_not_ae_unique [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) : - law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} ≠ 1 := by - classical - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - intro hu - have hpos : 0 < law (pc G) {ω | (infiniteClusters G ω).Nonempty} := by - exact lt_of_lt_of_le (show 0 < law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} by - rw [hu]; exact zero_lt_one) - (measure_mono fun ω hω => ⟨hω.choose,hω.choose_spec.1⟩) - obtain ⟨θ,hθ,hroot⟩ := uniform_survival_pos G hconn hqt (pc G) (pc_pos G hloc hqt) hpos - have hue : ∀ᵐ ω ∂law (pc G), ∃! C, C ∈ infiniteClusters G ω := - (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu - apply critical_twoPoint_no_uniform_positive G hloc hqt hh (θ*θ) (mul_pos hθ hθ) - intro x y - refine (mul_le_mul (hroot x) (hroot y) hθ.le measureReal_nonneg).trans - ((association_infinite_cluster G (pc G) x y).trans ?_) - apply ENNReal.toReal_mono (measure_ne_top _ _) - apply measure_mono_ae - filter_upwards [hue] with ω hω - intro hi - obtain ⟨r,_,hr⟩ := (unique_infinite_cluster_iff G ω).mp hω - exact conn_trans G ω (conn_symm G ω (hr x hi.1)) (hr y hi.2) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Critical connection probabilities and nonamenable growth. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory Filter +open scoped Topology +universe u v +variable {V : Type u} {E : Type v} + +theorem connectivity_twoPoint_mul_le [Countable E] (G : BondGraph V E) (p : unitInterval) + (x y z : V) : twoPoint G p x y * twoPoint G p y z ≤ twoPoint G p x z := by + have h := association_finiteWitness p {ω | Conn G ω x y} {ω | Conn G ω y z} + (fun _ _ hst hxy => conn_mono G hst hxy) + (fun _ _ hst hyz => conn_mono G hst hyz) + (finiteWitness_conn G x y) (finiteWitness_conn G y z) + refine h.trans (measureReal_mono ?_) + intro ω hω + exact conn_trans G ω hω.1 hω.2 + +theorem reachBall_split (G : BondGraph V E) (x z : V) (n m : ℕ) + (hz : z ∈ reachBall G x (n+m)) : + ∃ y ∈ reachBall G x n, z ∈ reachBall G y m := by + induction m generalizing z with + | zero => + exact ⟨z,by simpa using hz,by simp [reachBall]⟩ + | succ m ih => + change z ∈ reachBall G x (n+m) ∪ _ at hz + rcases hz with hz | hz + · obtain ⟨y,hy,hyz⟩ := ih z hz + exact ⟨y,hy,Or.inl hyz⟩ + · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hz + obtain ⟨z',hz',hzz⟩ := hz + obtain ⟨y,hy,hyz⟩ := ih z' hz' + refine ⟨y,hy,Or.inr ?_⟩ + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] + exact ⟨z',hyz,hzz⟩ + +theorem twoPoint_block_lower [Countable E] (G : BondGraph V E) (p : unitInterval) + (n : ℕ) (c : ℝ) (hc : 0 ≤ c) + (h : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) + (m : ℕ) (x y : V) (hy : y ∈ reachBall G x (n*m)) : + c^m ≤ twoPoint G p x y := by + induction m generalizing x y with + | zero => + simp only [mul_zero,reachBall,Set.mem_singleton_iff] at hy + subst y + simp [twoPoint_self] + | succ m ih => + rw [Nat.mul_succ] at hy + obtain ⟨z,hz,hzy⟩ := reachBall_split G x y (n*m) n hy + calc + c^(m+1) = c^m*c := pow_succ _ _ + _ ≤ twoPoint G p x z * twoPoint G p z y := + mul_le_mul (ih x z hz) (h z y hzy) hc (twoPoint_nonneg G p x z) + _ ≤ twoPoint G p x y := connectivity_twoPoint_mul_le G p x z y + +theorem isoperimetric_ball_growth (G : BondGraph V E) (hloc : LocallyFinite G) + (hh : 0 < hV G) (x : V) (n : ℕ) : + (1+hV G)^n ≤ ((reachBall G x n).ncard : ℝ) := by + classical + induction n with + | zero => simp [reachBall] + | succ n ih => + let B := (finite_reachBall hloc x n).toFinset + have heq : reachBall G x (n+1) = reachBall G x n ∪ vertexBoundary G B := by + ext y + simp only [reachBall,Set.mem_union,Set.mem_iUnion,Set.mem_ofPred_eq,vertexBoundary] + constructor + · rintro (hy | ⟨z,hz,hzy⟩) + · exact Or.inl hy + · by_cases hy : y ∈ reachBall G x n + · exact Or.inl hy + · exact Or.inr ⟨by simpa [B] using hy,z,by simpa [B] using hz,hzy⟩ + · rintro (hy | ⟨_,z,hz,hzy⟩) + · exact Or.inl hy + · exact Or.inr ⟨z,by simpa [B] using hz,hzy⟩ + have hd : Disjoint (reachBall G x n) (vertexBoundary G B) := by + apply Set.disjoint_left.mpr + intro y hy hb + exact hb.1 (by simpa [B] using hy) + have hb := hV_mul_card_le G B + have hcard : B.card = (reachBall G x n).ncard := + (Set.ncard_eq_toFinset_card _ _).symm + rw [hcard] at hb + rw [heq,Set.ncard_union_eq hd (finite_reachBall hloc x n) + (finite_vertexBoundary G hloc B),Nat.cast_add,pow_succ] + have hh0 : 0 ≤ 1+hV G := by linarith + nlinarith [mul_le_mul_of_nonneg_right ih hh0] + +theorem subcritical_block_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (p : unitInterval) (hp : p < pc G) + (n : ℕ) (c : ℝ) (hc : 0 ≤ c) + (h : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) : + (1+hV G)^n*c ≤ 1 := by + classical + by_contra hbad + have hgt : 1 < (1+hV G)^n*c := lt_of_not_ge hbad + let x : V := Classical.arbitrary V + have hbound (m : ℕ) : ((1+hV G)^n*c)^m ≤ susceptibility G p x := by + let B := (finite_reachBall hloc x (n*m)).toFinset + calc + ((1+hV G)^n*c)^m = (1+hV G)^(n*m)*c^m := by rw [mul_pow,pow_mul] + _ ≤ (B.card:ℝ)*c^m := by + simpa only [B, ← Set.ncard_eq_toFinset_card] using mul_le_mul_of_nonneg_right + (isoperimetric_ball_growth G hloc hh x (n*m)) (pow_nonneg hc m) + _ = ∑ y ∈ B, c^m := by simp + _ ≤ ∑ y ∈ B, twoPoint G p x y := by + apply Finset.sum_le_sum + intro y hy + exact twoPoint_block_lower G p n c hc h m x y (by simpa [B] using hy) + _ ≤ susceptibility G p x := + (summable_twoPoint_subcritical G hloc hqt p hp x).sum_le_tsum B + (fun y _ => twoPoint_nonneg G p x y) + obtain ⟨m,hm⟩ := pow_unbounded_of_one_lt (susceptibility G p x) hgt + exact (not_lt_of_ge (hbound m)) hm + +theorem uniform_ball_lower_below [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (q : unitInterval) (hq : 0 < q) (n : ℕ) (a c : ℝ) (hac : a < c) + (h : ∀ x y, c ≤ twoPoint G q x y) : + ∃ p : unitInterval, p < q ∧ ∀ x y, y ∈ reachBall G x n → a < twoPoint G p x y := by + classical + obtain ⟨R,hR⟩ := hqt + obtain ⟨ps,hps,hpsq,ht⟩ := exists_seq_strictMono_tendsto' hq + have hev : ∀ᶠ k in atTop, ∀ o ∈ R, ∀ y ∈ reachBall G o n, + a < twoPoint G (ps k) o y := by + apply (eventually_all_finset R).mpr + intro o _ + apply (eventually_all_finite (finite_reachBall hloc o n)).mpr + intro y _ + exact (twoPoint_tendsto_of_monotone G ps hps.monotone q + (fun k => (hpsq k).2.le) ht o y).eventually (eventually_gt_nhds (hac.trans_le (h o y))) + obtain ⟨k,hk⟩ := hev.exists + refine ⟨ps k,(hpsq k).2,?_⟩ + intro x y hy + obtain ⟨o,ho,g,b,hg,hgx⟩ := hR x + have hy' : g.symm y ∈ reachBall G o n := by + apply (mem_reachBall_aut_iff G hg o (g.symm y) n).mp + simpa only [g.apply_symm_apply,hgx] using hy + have hb := hk o ho (g.symm y) hy' + have he := twoPoint_aut G (ps k) hg o (g.symm y) + rw [g.apply_symm_apply,hgx] at he + rwa [he] + +theorem critical_twoPoint_no_uniform_positive [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (c : ℝ) (hc : 0 < c) : + ¬ (∀ x y, c ≤ twoPoint G (pc G) x y) := by + intro h + have ha : 0 < c/2 := by positivity + obtain ⟨n,hn⟩ := pow_unbounded_of_one_lt (1/(c/2)) (show 1 < 1+hV G by linarith) + obtain ⟨p,hp,hball⟩ := uniform_ball_lower_below G hloc hqt (pc G) + (pc_pos G hloc hqt) n (c/2) c (by linarith) h + have hb := subcritical_block_bound G hloc hqt hh p hp n (c/2) ha.le + (fun x y hy => (hball x y hy).le) + exact (not_lt_of_ge hb) ((div_lt_iff₀ ha).mp hn) + +theorem critical_not_ae_unique [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) : + law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} ≠ 1 := by + classical + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + intro hu + have hpos : 0 < law (pc G) {ω | (infiniteClusters G ω).Nonempty} := by + exact lt_of_lt_of_le (show 0 < law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} by + rw [hu]; exact zero_lt_one) + (measure_mono fun ω hω => ⟨hω.choose,hω.choose_spec.1⟩) + obtain ⟨θ,hθ,hroot⟩ := uniform_survival_pos G hconn hqt (pc G) (pc_pos G hloc hqt) hpos + have hue : ∀ᵐ ω ∂law (pc G), ∃! C, C ∈ infiniteClusters G ω := + (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu + apply critical_twoPoint_no_uniform_positive G hloc hqt hh (θ*θ) (mul_pos hθ hθ) + intro x y + refine (mul_le_mul (hroot x) (hroot y) hθ.le measureReal_nonneg).trans + ((association_infinite_cluster G (pc G) x y).trans ?_) + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono_ae + filter_upwards [hue] with ω hω + intro hi + obtain ⟨r,_,hr⟩ := (unique_infinite_cluster_iff G ω).mp hω + exact conn_trans G ω (conn_symm G ω (hr x hi.1)) (hr y hi.2) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Ergodicity.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Ergodicity.lean index 2a0209dfc3c486093d3006b209fa2c513c024068..833e56c3b568211c5bf24fb94a4541d82bf33484 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Ergodicity.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Ergodicity.lean @@ -1,146 +1,146 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Zero-one laws for invariant Bernoulli events. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory ProbabilityTheory -open scoped ENNReal symmDiff -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem exists_aut_disjoint_edges [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (F : Finset E) : ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ Disjoint F (F.image b) := by - classical - let B : Finset V := F.biUnion (fun e => (G e).toFinset) - let x : V := Classical.arbitrary V - obtain ⟨n,hn⟩ := exists_transportCut G hconn x B - have hfin : (⋃ z ∈ (B : Set V), reachBall G z n).Finite := - B.finite_toSet.biUnion (fun z _ => finite_reachBall hloc z n) - obtain ⟨y,⟨a,b,hab,hax⟩,hy⟩ := - (vertexOrbit_infinite G hconn hloc hqt x).exists_notMem_finite hfin - refine ⟨a,b,hab,Finset.disjoint_left.mpr ?_⟩ - intro e he heb - obtain ⟨e',he',rfl⟩ := Finset.mem_image.mp heb - have hm : ∃ z, z ∈ G e' := Sym2.inductionOn (G e') (fun z w => ⟨z,by simp⟩) - obtain ⟨z,hz⟩ := hm - have hzB : z ∈ B := Finset.mem_biUnion.mpr ⟨e',he',by simpa using hz⟩ - have hazB : a z ∈ B := by - apply Finset.mem_biUnion.mpr - refine ⟨b e',he,?_⟩ - rw [Sym2.mem_toFinset,hab] - exact Sym2.mem_map.mpr ⟨z,hz,rfl⟩ - apply hy - simp only [Set.mem_iUnion] - refine ⟨a z,hazB,?_⟩ - rw [←hax] - exact mem_reachBall_aut G hab (hn z hzB).1 - -theorem label_cylinder_independent (F : Finset E) (b : E ≃ E) - (hd : Disjoint F (F.image b)) (S : Set (F → unitInterval)) (hS : MeasurableSet S) : - (labelLaw : Measure (E → unitInterval)) - (cylinder F S ∩ (fun l : E → unitInterval => l ∘ b) ⁻¹' cylinder F S) = - labelLaw (cylinder F S) * labelLaw (cylinder F S) := by - classical - have hi : iIndepFun (fun e (l : E → unitInterval) => l e) labelLaw := - iIndepFun_infinitePi (X := fun (_ : E) (x : unitInterval) => x) (fun _ => measurable_id) - have h := hi.indepFun_finset F (F.image b) hd (fun e => measurable_pi_apply e) - let r : ((F.image b) → unitInterval) → (F → unitInterval) := - fun l e => l ⟨b e,Finset.mem_image.mpr ⟨e,e.property,rfl⟩⟩ - have hr : Measurable r := Measurable.of_eval (fun _ => measurable_pi_apply _) - have h' := h.comp measurable_id hr - have he := h'.meas_inter (s := cylinder F S) - (t := (fun l : E → unitInterval => l ∘ b) ⁻¹' cylinder F S) - ⟨S,hS,rfl⟩ ⟨S,hS,rfl⟩ - have hm : Measurable (fun l : E → unitInterval => l ∘ b) := - Measurable.of_eval fun e => measurable_pi_apply (b e) - rw [←Measure.map_apply hm hS.cylinder,labelLaw_map_precomp] at he - exact he - -theorem label_invariant_zero_one [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (A : Set (E → unitInterval)) (hA : MeasurableSet A) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → - (fun l : E → unitInterval => l ∘ b) ⁻¹' A = A) : - labelLaw A = 0 ∨ labelLaw A = 1 := by - classical - let μ : Measure (E → unitInterval) := labelLaw - have hd := Measure.MeasureDense.of_generateFrom_isSetAlgebra_finite μ - (isSetAlgebra_measurableCylinders (α := fun _ : E => unitInterval)) - generateFrom_measurableCylinders.symm - have heq : μ.real A ≤ (μ.real A)^2 := by - apply le_of_forall_pos_le_add - intro ε hε - obtain ⟨B,hB,hAB⟩ := hd.approx A hA (measure_ne_top _ _) (ε/4) (by positivity) - obtain ⟨F,S,hS,rfl⟩ := (mem_measurableCylinders B).mp hB - let B : Set (E → unitInterval) := cylinder F S - have hBm : MeasurableSet B := hS.cylinder - have hABr : μ.real (A ∆ B) < ε/4 := by - exact (ENNReal.toReal_lt_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mpr hAB |>.trans_le - (by rw [ENNReal.toReal_ofReal (by positivity)]) - obtain ⟨a,b,hab,habF⟩ := exists_aut_disjoint_edges G hconn hloc hqt F - let φ : (E → unitInterval) → (E → unitInterval) := fun l => l ∘ b - have hφ : Measurable φ := Measurable.of_eval fun e => measurable_pi_apply (b e) - have hφμ : μ.map φ = μ := labelLaw_map_precomp b - have hφA : φ ⁻¹' A = A := hinv a b hab - have hφAB : μ.real (A ∆ (φ ⁻¹' B)) = μ.real (A ∆ B) := by - conv_lhs => rw [←hφA,←Set.preimage_symmDiff] - change (μ (φ ⁻¹' (A ∆ B))).toReal = _ - rw [←Measure.map_apply hφ (hA.symmDiff hBm),hφμ] - rfl - have hC : MeasurableSet (B ∩ φ ⁻¹' B) := hBm.inter (hBm.preimage hφ) - have hsub : A ∆ (B ∩ φ ⁻¹' B) ⊆ (A ∆ B) ∪ (A ∆ (φ ⁻¹' B)) := by - intro l hl - simp only [Set.mem_symmDiff,Set.mem_inter_iff,Set.mem_union] at hl ⊢ - tauto - have hAC : μ.real (A ∆ (B ∩ φ ⁻¹' B)) < ε/2 := by - calc - _ ≤ μ.real ((A ∆ B) ∪ (A ∆ (φ ⁻¹' B))) := measureReal_mono hsub - _ ≤ μ.real (A ∆ B) + μ.real (A ∆ (φ ⁻¹' B)) := measureReal_union_le _ _ - _ < ε/2 := by rw [hφAB]; linarith - have hprod : μ.real (B ∩ φ ⁻¹' B) = (μ.real B)^2 := by - change (labelLaw (B ∩ φ ⁻¹' B)).toReal = _ - rw [label_cylinder_independent F b habF S hS,ENNReal.toReal_mul,pow_two] - rfl - have h1 := abs_measureReal_sub_le_measureReal_symmDiff (μ := μ) hA.nullMeasurableSet hC.nullMeasurableSet - have h2 := abs_measureReal_sub_le_measureReal_symmDiff (μ := μ) hA.nullMeasurableSet hBm.nullMeasurableSet - have h1' : μ.real A - (μ.real B)^2 < ε/2 := by - rw [hprod] at h1 - exact lt_of_le_of_lt (le_trans (le_abs_self (μ.real A - (μ.real B)^2)) h1) hAC - have h2' : μ.real B - μ.real A < ε/4 := by - have hh := (neg_le_abs (μ.real A - μ.real B)).trans h2 |>.trans_lt hABr - linarith - have hA0 : 0 ≤ μ.real A := measureReal_nonneg - have hB0 : 0 ≤ μ.real B := measureReal_nonneg - have hA1 : μ.real A ≤ 1 := measureReal_le_one - have hB1 : μ.real B ≤ 1 := measureReal_le_one - have hsq : (μ.real B)^2 ≤ (μ.real A)^2 + ε/2 := by - by_cases hle : μ.real B ≤ μ.real A - · nlinarith [sq_nonneg (μ.real A-μ.real B)] - · have hp := mul_le_mul (le_of_lt h2') (show μ.real B+μ.real A ≤ 2 by linarith) - (show 0 ≤ μ.real B+μ.real A by positivity) (show 0 ≤ ε/4 by positivity) - nlinarith - linarith - have hA0 : 0 ≤ μ.real A := measureReal_nonneg - have hA1 : μ.real A ≤ 1 := measureReal_le_one - have he : μ.real A = 0 ∨ μ.real A = 1 := by - have : μ.real A * (μ.real A-1) = 0 := by nlinarith - rcases mul_eq_zero.mp this with h | h - · exact Or.inl h - · exact Or.inr (by linarith) - rcases he with h | h - · left - exact (ENNReal.toReal_eq_zero_iff _).mp h |>.resolve_right (measure_ne_top _ _) - · right - exact (ENNReal.toReal_eq_one_iff _).mp h - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Zero-one laws for invariant Bernoulli events. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory ProbabilityTheory +open scoped ENNReal symmDiff +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem exists_aut_disjoint_edges [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (F : Finset E) : ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ Disjoint F (F.image b) := by + classical + let B : Finset V := F.biUnion (fun e => (G e).toFinset) + let x : V := Classical.arbitrary V + obtain ⟨n,hn⟩ := exists_transportCut G hconn x B + have hfin : (⋃ z ∈ (B : Set V), reachBall G z n).Finite := + B.finite_toSet.biUnion (fun z _ => finite_reachBall hloc z n) + obtain ⟨y,⟨a,b,hab,hax⟩,hy⟩ := + (vertexOrbit_infinite G hconn hloc hqt x).exists_notMem_finite hfin + refine ⟨a,b,hab,Finset.disjoint_left.mpr ?_⟩ + intro e he heb + obtain ⟨e',he',rfl⟩ := Finset.mem_image.mp heb + have hm : ∃ z, z ∈ G e' := Sym2.inductionOn (G e') (fun z w => ⟨z,by simp⟩) + obtain ⟨z,hz⟩ := hm + have hzB : z ∈ B := Finset.mem_biUnion.mpr ⟨e',he',by simpa using hz⟩ + have hazB : a z ∈ B := by + apply Finset.mem_biUnion.mpr + refine ⟨b e',he,?_⟩ + rw [Sym2.mem_toFinset,hab] + exact Sym2.mem_map.mpr ⟨z,hz,rfl⟩ + apply hy + simp only [Set.mem_iUnion] + refine ⟨a z,hazB,?_⟩ + rw [←hax] + exact mem_reachBall_aut G hab (hn z hzB).1 + +theorem label_cylinder_independent (F : Finset E) (b : E ≃ E) + (hd : Disjoint F (F.image b)) (S : Set (F → unitInterval)) (hS : MeasurableSet S) : + (labelLaw : Measure (E → unitInterval)) + (cylinder F S ∩ (fun l : E → unitInterval => l ∘ b) ⁻¹' cylinder F S) = + labelLaw (cylinder F S) * labelLaw (cylinder F S) := by + classical + have hi : iIndepFun (fun e (l : E → unitInterval) => l e) labelLaw := + iIndepFun_infinitePi (X := fun (_ : E) (x : unitInterval) => x) (fun _ => measurable_id) + have h := hi.indepFun_finset F (F.image b) hd (fun e => measurable_pi_apply e) + let r : ((F.image b) → unitInterval) → (F → unitInterval) := + fun l e => l ⟨b e,Finset.mem_image.mpr ⟨e,e.property,rfl⟩⟩ + have hr : Measurable r := Measurable.of_eval (fun _ => measurable_pi_apply _) + have h' := h.comp measurable_id hr + have he := h'.meas_inter (s := cylinder F S) + (t := (fun l : E → unitInterval => l ∘ b) ⁻¹' cylinder F S) + ⟨S,hS,rfl⟩ ⟨S,hS,rfl⟩ + have hm : Measurable (fun l : E → unitInterval => l ∘ b) := + Measurable.of_eval fun e => measurable_pi_apply (b e) + rw [←Measure.map_apply hm hS.cylinder,labelLaw_map_precomp] at he + exact he + +theorem label_invariant_zero_one [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (A : Set (E → unitInterval)) (hA : MeasurableSet A) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → + (fun l : E → unitInterval => l ∘ b) ⁻¹' A = A) : + labelLaw A = 0 ∨ labelLaw A = 1 := by + classical + let μ : Measure (E → unitInterval) := labelLaw + have hd := Measure.MeasureDense.of_generateFrom_isSetAlgebra_finite μ + (isSetAlgebra_measurableCylinders (α := fun _ : E => unitInterval)) + generateFrom_measurableCylinders.symm + have heq : μ.real A ≤ (μ.real A)^2 := by + apply le_of_forall_pos_le_add + intro ε hε + obtain ⟨B,hB,hAB⟩ := hd.approx A hA (measure_ne_top _ _) (ε/4) (by positivity) + obtain ⟨F,S,hS,rfl⟩ := (mem_measurableCylinders B).mp hB + let B : Set (E → unitInterval) := cylinder F S + have hBm : MeasurableSet B := hS.cylinder + have hABr : μ.real (A ∆ B) < ε/4 := by + exact (ENNReal.toReal_lt_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mpr hAB |>.trans_le + (by rw [ENNReal.toReal_ofReal (by positivity)]) + obtain ⟨a,b,hab,habF⟩ := exists_aut_disjoint_edges G hconn hloc hqt F + let φ : (E → unitInterval) → (E → unitInterval) := fun l => l ∘ b + have hφ : Measurable φ := Measurable.of_eval fun e => measurable_pi_apply (b e) + have hφμ : μ.map φ = μ := labelLaw_map_precomp b + have hφA : φ ⁻¹' A = A := hinv a b hab + have hφAB : μ.real (A ∆ (φ ⁻¹' B)) = μ.real (A ∆ B) := by + conv_lhs => rw [←hφA,←Set.preimage_symmDiff] + change (μ (φ ⁻¹' (A ∆ B))).toReal = _ + rw [←Measure.map_apply hφ (hA.symmDiff hBm),hφμ] + rfl + have hC : MeasurableSet (B ∩ φ ⁻¹' B) := hBm.inter (hBm.preimage hφ) + have hsub : A ∆ (B ∩ φ ⁻¹' B) ⊆ (A ∆ B) ∪ (A ∆ (φ ⁻¹' B)) := by + intro l hl + simp only [Set.mem_symmDiff,Set.mem_inter_iff,Set.mem_union] at hl ⊢ + tauto + have hAC : μ.real (A ∆ (B ∩ φ ⁻¹' B)) < ε/2 := by + calc + _ ≤ μ.real ((A ∆ B) ∪ (A ∆ (φ ⁻¹' B))) := measureReal_mono hsub + _ ≤ μ.real (A ∆ B) + μ.real (A ∆ (φ ⁻¹' B)) := measureReal_union_le _ _ + _ < ε/2 := by rw [hφAB]; linarith + have hprod : μ.real (B ∩ φ ⁻¹' B) = (μ.real B)^2 := by + change (labelLaw (B ∩ φ ⁻¹' B)).toReal = _ + rw [label_cylinder_independent F b habF S hS,ENNReal.toReal_mul,pow_two] + rfl + have h1 := abs_measureReal_sub_le_measureReal_symmDiff (μ := μ) hA.nullMeasurableSet hC.nullMeasurableSet + have h2 := abs_measureReal_sub_le_measureReal_symmDiff (μ := μ) hA.nullMeasurableSet hBm.nullMeasurableSet + have h1' : μ.real A - (μ.real B)^2 < ε/2 := by + rw [hprod] at h1 + exact lt_of_le_of_lt (le_trans (le_abs_self (μ.real A - (μ.real B)^2)) h1) hAC + have h2' : μ.real B - μ.real A < ε/4 := by + have hh := (neg_le_abs (μ.real A - μ.real B)).trans h2 |>.trans_lt hABr + linarith + have hA0 : 0 ≤ μ.real A := measureReal_nonneg + have hB0 : 0 ≤ μ.real B := measureReal_nonneg + have hA1 : μ.real A ≤ 1 := measureReal_le_one + have hB1 : μ.real B ≤ 1 := measureReal_le_one + have hsq : (μ.real B)^2 ≤ (μ.real A)^2 + ε/2 := by + by_cases hle : μ.real B ≤ μ.real A + · nlinarith [sq_nonneg (μ.real A-μ.real B)] + · have hp := mul_le_mul (le_of_lt h2') (show μ.real B+μ.real A ≤ 2 by linarith) + (show 0 ≤ μ.real B+μ.real A by positivity) (show 0 ≤ ε/4 by positivity) + nlinarith + linarith + have hA0 : 0 ≤ μ.real A := measureReal_nonneg + have hA1 : μ.real A ≤ 1 := measureReal_le_one + have he : μ.real A = 0 ∨ μ.real A = 1 := by + have : μ.real A * (μ.real A-1) = 0 := by nlinarith + rcases mul_eq_zero.mp this with h | h + · exact Or.inl h + · exact Or.inr (by linarith) + rcases he with h | h + · left + exact (ENNReal.toReal_eq_zero_iff _).mp h |>.resolve_right (measure_ne_top _ _) + · right + exact (ENNReal.toReal_eq_one_iff _).mp h + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/FiniteChanges.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/FiniteChanges.lean index 5839868c4685d20d0df1a72b5da0572aa7646d60..0ea2cbc7a8be2f858439fba33a294eddf7e72075 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/FiniteChanges.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/FiniteChanges.lean @@ -1,139 +1,139 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Finite changes of bond configurations and their positive probabilities. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory ProbabilityTheory -open scoped ENNReal -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -def finiteOverwrite (F P : Finset E) (ω : Set E) : Set E := - (ω ∩ (F:Set E)ᶜ) ∪ (P:Set E) - -theorem measurable_finiteOverwrite (F P : Finset E) : Measurable (finiteOverwrite F P) := - (measurable_union_const (P:Set E)).comp (measurable_inter_const (F:Set E)ᶜ) - -theorem finite_pattern_pos [Countable E] (p : unitInterval) (hp : 0 < p) (hp1 : p < 1) - (F P : Finset E) (hPF : P ⊆ F) : - 0 < (law p : Measure (Set E)) {ω | ω ∩ (F:Set E) = (P:Set E)} := by - let R : Set (F:Set E) := Subtype.val ⁻¹' (P:Set E) - have he : {ω : Set E | ω ∩ (F:Set E) = (P:Set E)} = - (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (F:Set E))) ⁻¹' {R} := by - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_preimage,Set.mem_singleton_iff] - constructor - · intro h - ext e - change e.val ∈ ω ↔ e.val ∈ (P:Set E) - have := Set.ext_iff.mp h e.val - simpa only [Set.mem_inter_iff,e.property,and_true] using this - · intro h - ext e - simp only [Set.mem_inter_iff,Finset.mem_coe] - constructor - · rintro ⟨he,hF⟩ - exact (Set.ext_iff.mp h ⟨e,hF⟩).mp he - · intro he - have hF := hPF he - exact ⟨(Set.ext_iff.mp h ⟨e,hF⟩).mpr he,hF⟩ - rw [he,←Measure.map_apply (measurable_set_restrict _) (measurableSet_singleton _),law_map_restrict] - have hh : 0 < (law p : Measure (Set (F:Set E))).real {R} := by - rw [law,setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ] - exact mul_pos (pow_pos (show (0:ℝ) < p from hp) _) - (pow_pos (sub_pos.mpr (show (p:ℝ) < 1 from hp1)) _) - exact (ENNReal.toReal_pos_iff.mp hh).1 - -theorem finiteOverwrite_pos [Countable E] (p : unitInterval) (hp : 0 < p) (hp1 : p < 1) - (F P : Finset E) (hPF : P ⊆ F) (A B : Set (Set E)) - (hB : MeasurableSet B) (hA : 0 < (law p : Measure (Set E)) A) - (hAB : ∀ ω ∈ A, finiteOverwrite F P ω ∈ B) : 0 < (law p : Measure (Set E)) B := by - let D := (finiteOverwrite F P) ⁻¹' B - let C : Set (Set E) := {ω | ω ∩ (F:Set E) = (P:Set E)} - have hD : MeasurableSet D := hB.preimage (measurable_finiteOverwrite F P) - have hDfix : (fun ω : Set E => ω ∩ (F:Set E)ᶜ) ⁻¹' D = D := by - ext ω - simp only [D,finiteOverwrite,Set.mem_preimage,Set.inter_assoc,Set.inter_self] - have hind := restriction_events_independent p (F:Set E) (F:Set E)ᶜ disjoint_compl_right - {(P:Set E)} D (measurableSet_singleton _) hD - rw [hDfix] at hind - change (law p : Measure (Set E)) (C ∩ D) = law p C * law p D at hind - have hposC : 0 < (law p : Measure (Set E)) C := finite_pattern_pos p hp hp1 F P hPF - have hposD : 0 < (law p : Measure (Set E)) D := hA.trans_le (measure_mono hAB) - have hsub : C ∩ D ⊆ B := by - rintro ω ⟨hC,hD⟩ - have he : finiteOverwrite F P ω = ω := by - change ω ∩ (F:Set E) = (P:Set E) at hC - rw [finiteOverwrite,←hC] - ext e - simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] - tauto - simpa only [D,Set.mem_preimage,he] using hD - apply lt_of_lt_of_le _ (measure_mono hsub) - rw [hind] - exact ENNReal.mul_pos hposC.ne' hposD.ne' - -theorem infinite_cluster_union_contains (G : BondGraph V E) (ω : Set E) - (F : Set E) (hF : F.Finite) (x : V) (hx : (cluster G (ω ∪ F) x).Infinite) : - ∃ z, Conn G (ω ∪ F) x z ∧ (cluster G ω z).Infinite := by - by_contra hn - have hfin (z : V) : (cluster G ω z ∩ cluster G (ω ∪ F) x).Finite := by - by_cases hz : Conn G (ω ∪ F) x z - · have hf : (cluster G ω z).Finite := by - by_contra hh - exact hn ⟨z,hz,hh⟩ - exact hf.inter_of_left _ - · have he : cluster G ω z ∩ cluster G (ω ∪ F) x = ∅ := by - apply Set.eq_empty_iff_forall_notMem.mpr - rintro y ⟨hzy,hxy⟩ - apply hz - exact conn_trans G _ hxy (conn_symm G _ (conn_mono G Set.subset_union_left hzy)) - rw [he] - exact Set.finite_empty - have hupper : (cluster G ω x ∩ cluster G (ω ∪ F) x ∪ - ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G ω z ∩ cluster G (ω ∪ F) x).Finite := by - apply (hfin x).union - apply hF.biUnion - intro e _ - have he : {z | z ∈ G e}.Finite := - (G e).toFinset.finite_toSet.subset (fun z hz => by simpa using hz) - exact he.biUnion (fun z _ => hfin z) - apply hx (hupper.subset ?_) - intro y hy - rcases cluster_union_subset G ω F x hy with hy' | hy' - · exact Or.inl ⟨hy',hy⟩ - · right - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy' ⊢ - obtain ⟨e,he,z,hz,hzy⟩ := hy' - exact ⟨e,he,z,hz,hzy,hy⟩ - -theorem finite_opening_unique (G : BondGraph V E) (ω : Set E) (F : Finset E) (x : V) - (hx : (cluster G ω x).Infinite) - (hjoin : ∀ y, (cluster G ω y).Infinite → Conn G (ω ∪ (F:Set E)) x y) : - ∃! C, C ∈ infiniteClusters G (ω ∪ (F:Set E)) := by - rw [unique_infinite_cluster_iff] - refine ⟨x,hx.mono (fun _ h => conn_mono G Set.subset_union_left h),?_⟩ - intro y hy - obtain ⟨z,hyz,hz⟩ := infinite_cluster_union_contains G ω (F:Set E) F.finite_toSet y hy - exact conn_trans G _ (hjoin z hz) (conn_symm G _ hyz) - -theorem finite_connecting_edges (G : BondGraph V E) (hconn : Connected G) - (x : V) (R : Finset V) : ∃ F : Finset E, ∀ y ∈ R, Conn G (F:Set E) x y := by - have hall (y : V) : ∃ F : Finset E, Conn G (F:Set E) x y := by - obtain ⟨s,_,hs⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hconn x y) - exact ⟨s,hs⟩ - choose F hF using hall - refine ⟨R.biUnion F,?_⟩ - intro y hy - exact conn_mono G (fun e he => Finset.mem_biUnion.mpr ⟨y,hy,he⟩) (hF y) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Finite changes of bond configurations and their positive probabilities. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory ProbabilityTheory +open scoped ENNReal +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +def finiteOverwrite (F P : Finset E) (ω : Set E) : Set E := + (ω ∩ (F:Set E)ᶜ) ∪ (P:Set E) + +theorem measurable_finiteOverwrite (F P : Finset E) : Measurable (finiteOverwrite F P) := + (measurable_union_const (P:Set E)).comp (measurable_inter_const (F:Set E)ᶜ) + +theorem finite_pattern_pos [Countable E] (p : unitInterval) (hp : 0 < p) (hp1 : p < 1) + (F P : Finset E) (hPF : P ⊆ F) : + 0 < (law p : Measure (Set E)) {ω | ω ∩ (F:Set E) = (P:Set E)} := by + let R : Set (F:Set E) := Subtype.val ⁻¹' (P:Set E) + have he : {ω : Set E | ω ∩ (F:Set E) = (P:Set E)} = + (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (F:Set E))) ⁻¹' {R} := by + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_preimage,Set.mem_singleton_iff] + constructor + · intro h + ext e + change e.val ∈ ω ↔ e.val ∈ (P:Set E) + have := Set.ext_iff.mp h e.val + simpa only [Set.mem_inter_iff,e.property,and_true] using this + · intro h + ext e + simp only [Set.mem_inter_iff,Finset.mem_coe] + constructor + · rintro ⟨he,hF⟩ + exact (Set.ext_iff.mp h ⟨e,hF⟩).mp he + · intro he + have hF := hPF he + exact ⟨(Set.ext_iff.mp h ⟨e,hF⟩).mpr he,hF⟩ + rw [he,←Measure.map_apply (measurable_set_restrict _) (measurableSet_singleton _),law_map_restrict] + have hh : 0 < (law p : Measure (Set (F:Set E))).real {R} := by + rw [law,setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ] + exact mul_pos (pow_pos (show (0:ℝ) < p from hp) _) + (pow_pos (sub_pos.mpr (show (p:ℝ) < 1 from hp1)) _) + exact (ENNReal.toReal_pos_iff.mp hh).1 + +theorem finiteOverwrite_pos [Countable E] (p : unitInterval) (hp : 0 < p) (hp1 : p < 1) + (F P : Finset E) (hPF : P ⊆ F) (A B : Set (Set E)) + (hB : MeasurableSet B) (hA : 0 < (law p : Measure (Set E)) A) + (hAB : ∀ ω ∈ A, finiteOverwrite F P ω ∈ B) : 0 < (law p : Measure (Set E)) B := by + let D := (finiteOverwrite F P) ⁻¹' B + let C : Set (Set E) := {ω | ω ∩ (F:Set E) = (P:Set E)} + have hD : MeasurableSet D := hB.preimage (measurable_finiteOverwrite F P) + have hDfix : (fun ω : Set E => ω ∩ (F:Set E)ᶜ) ⁻¹' D = D := by + ext ω + simp only [D,finiteOverwrite,Set.mem_preimage,Set.inter_assoc,Set.inter_self] + have hind := restriction_events_independent p (F:Set E) (F:Set E)ᶜ disjoint_compl_right + {(P:Set E)} D (measurableSet_singleton _) hD + rw [hDfix] at hind + change (law p : Measure (Set E)) (C ∩ D) = law p C * law p D at hind + have hposC : 0 < (law p : Measure (Set E)) C := finite_pattern_pos p hp hp1 F P hPF + have hposD : 0 < (law p : Measure (Set E)) D := hA.trans_le (measure_mono hAB) + have hsub : C ∩ D ⊆ B := by + rintro ω ⟨hC,hD⟩ + have he : finiteOverwrite F P ω = ω := by + change ω ∩ (F:Set E) = (P:Set E) at hC + rw [finiteOverwrite,←hC] + ext e + simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] + tauto + simpa only [D,Set.mem_preimage,he] using hD + apply lt_of_lt_of_le _ (measure_mono hsub) + rw [hind] + exact ENNReal.mul_pos hposC.ne' hposD.ne' + +theorem infinite_cluster_union_contains (G : BondGraph V E) (ω : Set E) + (F : Set E) (hF : F.Finite) (x : V) (hx : (cluster G (ω ∪ F) x).Infinite) : + ∃ z, Conn G (ω ∪ F) x z ∧ (cluster G ω z).Infinite := by + by_contra hn + have hfin (z : V) : (cluster G ω z ∩ cluster G (ω ∪ F) x).Finite := by + by_cases hz : Conn G (ω ∪ F) x z + · have hf : (cluster G ω z).Finite := by + by_contra hh + exact hn ⟨z,hz,hh⟩ + exact hf.inter_of_left _ + · have he : cluster G ω z ∩ cluster G (ω ∪ F) x = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + rintro y ⟨hzy,hxy⟩ + apply hz + exact conn_trans G _ hxy (conn_symm G _ (conn_mono G Set.subset_union_left hzy)) + rw [he] + exact Set.finite_empty + have hupper : (cluster G ω x ∩ cluster G (ω ∪ F) x ∪ + ⋃ e ∈ F, ⋃ z ∈ {z | z ∈ G e}, cluster G ω z ∩ cluster G (ω ∪ F) x).Finite := by + apply (hfin x).union + apply hF.biUnion + intro e _ + have he : {z | z ∈ G e}.Finite := + (G e).toFinset.finite_toSet.subset (fun z hz => by simpa using hz) + exact he.biUnion (fun z _ => hfin z) + apply hx (hupper.subset ?_) + intro y hy + rcases cluster_union_subset G ω F x hy with hy' | hy' + · exact Or.inl ⟨hy',hy⟩ + · right + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy' ⊢ + obtain ⟨e,he,z,hz,hzy⟩ := hy' + exact ⟨e,he,z,hz,hzy,hy⟩ + +theorem finite_opening_unique (G : BondGraph V E) (ω : Set E) (F : Finset E) (x : V) + (hx : (cluster G ω x).Infinite) + (hjoin : ∀ y, (cluster G ω y).Infinite → Conn G (ω ∪ (F:Set E)) x y) : + ∃! C, C ∈ infiniteClusters G (ω ∪ (F:Set E)) := by + rw [unique_infinite_cluster_iff] + refine ⟨x,hx.mono (fun _ h => conn_mono G Set.subset_union_left h),?_⟩ + intro y hy + obtain ⟨z,hyz,hz⟩ := infinite_cluster_union_contains G ω (F:Set E) F.finite_toSet y hy + exact conn_trans G _ (hjoin z hz) (conn_symm G _ hyz) + +theorem finite_connecting_edges (G : BondGraph V E) (hconn : Connected G) + (x : V) (R : Finset V) : ∃ F : Finset E, ∀ y ∈ R, Conn G (F:Set E) x y := by + have hall (y : V) : ∃ F : Finset E, Conn G (F:Set E) x y := by + obtain ⟨s,_,hs⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hconn x y) + exact ⟨s,hs⟩ + choose F hF using hall + refine ⟨R.biUnion F,?_⟩ + intro y hy + exact conn_mono G (fun e he => Finset.mem_biUnion.mpr ⟨y,hy,he⟩) (hF y) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Finiteness.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Finiteness.lean index 1eca0fcd1f649b7f1e8809e01b4ccab059211658..cc9e444eb03293d92f4ea8edf4359b877ec18db0 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Finiteness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Finiteness.lean @@ -1,466 +1,466 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.Corridors -import OAI.Probability.UnimodularPercolation.TwoCluster.Bounds - -namespace OAI - -/-! Critical two-cluster estimates, finite opening and almost-sure finite clusters. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory Filter Topology -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -section RootData -variable [Countable V] [Countable E] [Nonempty V] -variable (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) - -include hconn hloc hqt hΓ htr hcov hw hw1 hc hmin hd - - - -omit [Nonempty V] in -theorem critical_twoLarge_probability_bound - (n : ℕ) (hn : 0 < n) (e : E) (a b : V) (he : G e = s(a,b)) : - (pc G:ℝ) * ((n:ℝ) * (law (pc G)).real (twoLargeEvent G a b n)) ≤ - 20*c*Real.sqrt (d*n:ℕ) := by - obtain ⟨p,hp,hpc,hlim⟩ := exists_seq_strictMono_tendsto' (pc_pos G hloc hqt) - have ht := (continuous_subtype_val.tendsto (pc G) |>.comp hlim).mul - ((tendsto_const_nhds (x := (n:ℝ))).mul (twoLarge_probability_tendsto G p hp.monotone (pc G) - (fun j => (hpc j).2.le) hlim a b n)) - apply le_of_tendsto ht - apply Eventually.of_forall - intro j - have hb := twoLarge_probability_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 - c hc hmin d hd n hn (p j) (hpc j).1 - (subcritical_cluster_finite_ae G (p j) (hpc j).2) e a b he - change (p j:ℝ) * ((n:ℝ) * (law (p j)).real (twoLargeEvent G a b n)) ≤ _ - rw [mul_comm (p j:ℝ)] - exact (le_div_iff₀ (hpc j).1).mp hb - - - -omit [Nonempty V] in -theorem critical_adjacent_infinite_connected (e : E) (a b : V) (he : G e = s(a,b)) : - ∀ᵐ ω ∂law (pc G), (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b := by - let A : Set (Set E) := {ω | ¬Conn G ω a b ∧ - (cluster G ω a).Infinite ∧ (cluster G ω b).Infinite} - have hA : MeasurableSet A := (measurableSet_conn G a b).compl.inter - ((measurableSet_infinite_cluster G a).inter (measurableSet_infinite_cluster G b)) - have hp : 0 < (pc G:ℝ) := pc_pos G hloc hqt - have hzero : (law (pc G)).real A = 0 := by - by_contra hne - have hθ : 0 < (law (pc G)).real A := lt_of_le_of_ne measureReal_nonneg (Ne.symm hne) - have hb (n : ℕ) (hn : 0 < n) : - (pc G:ℝ)*((n:ℝ)*(law (pc G)).real A) ≤ 20*c*Real.sqrt (d*n:ℕ) := by - have hs : A ⊆ twoLargeEvent G a b n := by - intro ω h - refine ⟨h.1,?_,?_⟩ - · have hx : ω ∈ {ω | (cluster G ω a).Infinite} := h.2.1 - rw [infinite_cluster_eq_iInter G a] at hx - exact Set.mem_iInter.mp hx n - · have hx : ω ∈ {ω | (cluster G ω b).Infinite} := h.2.2 - rw [infinite_cluster_eq_iInter G b] at hx - exact Set.mem_iInter.mp hx n - exact (mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_left (measureReal_mono hs) (Nat.cast_nonneg n)) hp.le).trans - (critical_twoLarge_probability_bound G hconn hloc hqt root weight Γ hΓ htr hcov - hw hw1 c hc hmin d hd n hn e a b he) - let B := 20*c*Real.sqrt (d:ℝ) - obtain ⟨m,hm⟩ := exists_nat_gt (B / ((pc G:ℝ)*(law (pc G)).real A) + 1) - have hmpos : 0 < (m:ℝ) := lt_trans (by dsimp [B]; positivity) hm - have hmn : 0 < m := by exact_mod_cast hmpos - have hb' := hb (m^2) (pow_pos hmn _) - have hsqrt : Real.sqrt (d*(m^2):ℕ) = Real.sqrt (d:ℝ)*(m:ℝ) := by - rw [Nat.cast_mul,Nat.cast_pow,Real.sqrt_mul (Nat.cast_nonneg d),Real.sqrt_sq (Nat.cast_nonneg m)] - rw [hsqrt,Nat.cast_pow] at hb' - have hcancel : (pc G:ℝ)*(law (pc G)).real A*(m:ℝ) ≤ B := by - apply (mul_le_mul_iff_left₀ hmpos).mp - change ((pc G:ℝ)*(law (pc G)).real A*(m:ℝ))*(m:ℝ) ≤ B*(m:ℝ) - dsimp only [B] - nlinarith only [hb'] - have hlt : B < (pc G:ℝ)*(law (pc G)).real A*(m:ℝ) := by - have hdiv : B / ((pc G:ℝ)*(law (pc G)).real A) < (m:ℝ) := by linarith - have hh := (div_lt_iff₀ (mul_pos hp hθ)).mp hdiv - nlinarith - exact (not_lt_of_ge hcancel) hlt - have hn : law (pc G) A = 0 := (measureReal_eq_zero_iff).mp hzero - have hae : ∀ᵐ ω ∂law (pc G), ω ∉ A := by - rw [ae_iff]; simpa using hn - filter_upwards [hae] with ω hω ha hb - by_contra hc - exact hω ⟨hc,ha,hb⟩ - -end RootData -end Percolation - - - -open MeasureTheory ProbabilityTheory Filter -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem measure_union_finset_null [Countable E] (p : unitInterval) (hp : 0 < (p:ℝ)) - (A : Set (Set E)) (hA : MeasurableSet A) (hzero : law p A = 0) (F : Finset E) : - law p {ω | ω ∪ (F:Set E) ∈ A} = 0 := by - let B : Set (Set E) := {ω | ω ∪ (F:Set E) ∈ A} - let C : Set (Set E) := {ω | (F:Set E) ⊆ ω} - have hB : MeasurableSet B := hA.preimage - (measurable_set_union_pair.comp (measurable_id.prodMk measurable_const)) - have hC : MeasurableSet C := by - change MeasurableSet {ω | ∀ e ∈ F, e ∈ ω} - simp only [Set.ofPred_forall] - exact MeasurableSet.iInter fun e => MeasurableSet.iInter fun _ => measurableSet_mem e - have heB : (fun ω : Set E => ω ∩ (F:Set E)ᶜ) ⁻¹' B = B := by - ext ω - have he : (ω ∩ (F:Set E)ᶜ) ∪ (F:Set E) = ω ∪ (F:Set E) := by - ext t - simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] - tauto - simp only [Set.mem_preimage,B,Set.mem_ofPred_eq,he] - have heC : (fun ω : Set E => ω ∩ (F:Set E)) ⁻¹' C = C := by - ext ω - simp [C] - have hi := restriction_events_independent p (F:Set E)ᶜ (F:Set E) - (Set.disjoint_left.mpr (fun _ hx hy => hx hy)) B C hB hC - rw [heB,heC] at hi - have hBC : law p (B ∩ C) = 0 := measure_mono_null (by - intro ω h - have he : ω ∪ (F:Set E) = ω := Set.union_eq_left.mpr h.2 - simpa only [B,Set.mem_ofPred_eq,he] using h.1) hzero - have hCp : 0 < (law p).real C := by - rw [show C = {ω | (F:Set E) ⊆ ω} from rfl,finite_open_probability] - exact pow_pos hp _ - exact (mul_eq_zero.mp (hi.symm.trans hBC)).resolve_right - (fun h => by simp [Measure.real,h] at hCp) - -theorem ae_union_finset [Countable E] (p : unitInterval) (hp : 0 < (p:ℝ)) - (A : Set (Set E)) (hA : MeasurableSet A) (hae : ∀ᵐ ω ∂law p, ω ∈ A) (F : Finset E) : - ∀ᵐ ω ∂law p, ω ∪ (F:Set E) ∈ A := by - rw [ae_iff] at hae ⊢ - exact measure_union_finset_null p hp Aᶜ hA.compl hae F - - - -theorem atMostOne_of_finite_openings (G : BondGraph V E) (hconn : Connected G) (ω : Set E) - (h : ∀ F : Finset E, ∀ a b, Adj G a b → - (cluster G (ω ∪ (F:Set E)) a).Infinite → - (cluster G (ω ∪ (F:Set E)) b).Infinite → Conn G (ω ∪ (F:Set E)) a b) : - ∀ x y, (cluster G ω x).Infinite → (cluster G ω y).Infinite → Conn G ω x y := by - intro x y hx hy - by_contra hxy - have hF : ∀ F : Finset E, ¬Conn G (ω ∪ (F:Set E)) x y := by - intro F - induction F using Finset.induction_on with - | empty => simpa only [Finset.coe_empty,Set.union_empty] using hxy - | @insert e F he ih => - have heq : ω ∪ ((insert e F : Finset E):Set E) = insert e (ω ∪ (F:Set E)) := by - ext t; simp only [Finset.coe_insert,Set.mem_union,Set.mem_insert_iff]; tauto - rw [heq] - obtain ⟨⟨a,b⟩,hab'⟩ := Sym2.mk_surjective (G e) - have hab : G e = s(a,b) := hab'.symm - rw [conn_insert_iff G _ e a b x y hab] - rintro (hc | ⟨hxa,hby⟩ | ⟨hxb,hay⟩) - · exact ih hc - · have ha : (cluster G (ω ∪ (F:Set E)) a).Infinite := by - rw [←cluster_eq_of_conn G _ hxa] - exact hx.mono (fun z hz => conn_mono G Set.subset_union_left hz) - have hb : (cluster G (ω ∪ (F:Set E)) b).Infinite := by - rw [cluster_eq_of_conn G _ hby] - exact hy.mono (fun z hz => conn_mono G Set.subset_union_left hz) - exact ih (conn_trans G _ hxa (conn_trans G _ (h F a b ⟨e,hab⟩ ha hb) hby)) - · have hb : (cluster G (ω ∪ (F:Set E)) b).Infinite := by - rw [←cluster_eq_of_conn G _ hxb] - exact hx.mono (fun z hz => conn_mono G Set.subset_union_left hz) - have ha : (cluster G (ω ∪ (F:Set E)) a).Infinite := by - rw [cluster_eq_of_conn G _ hay] - exact hy.mono (fun z hz => conn_mono G Set.subset_union_left hz) - exact ih (conn_trans G _ hxb (conn_trans G _ - (conn_symm G _ (h F a b ⟨e,hab⟩ ha hb)) hay)) - obtain ⟨F,_,hFc⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hconn x y) - exact hF F (conn_mono G Set.subset_union_right hFc) - -end Percolation - - - - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -open scoped ENNReal - - -theorem twoPoint_mul_le [Countable E] (G : BondGraph V E) (p : unitInterval) - (x y z : V) : twoPoint G p x y * twoPoint G p y z ≤ twoPoint G p x z := by - have h := association_finiteWitness p {ω : Set E | Conn G ω x y} - {ω : Set E | Conn G ω y z} - (fun _ _ hω h => conn_mono G hω h) (fun _ _ hω h => conn_mono G hω h) - (finiteWitness_conn G x y) (finiteWitness_conn G y z) - exact h.trans (measureReal_mono (fun ω hω => conn_trans G ω hω.1 hω.2)) - - -theorem reachBall_add_split (G : BondGraph V E) (x : V) (n m : ℕ) {y : V} - (hy : y ∈ reachBall G x (n+m)) : - ∃ z ∈ reachBall G x n, y ∈ reachBall G z m := by - induction m generalizing y with - | zero => exact ⟨y,hy,Set.mem_singleton y⟩ - | succ m ih => - rcases hy with hy | hy - · obtain ⟨z,hz,hyz⟩ := ih hy - exact ⟨z,hz,Or.inl hyz⟩ - · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy - obtain ⟨w,hw,hwy⟩ := hy - obtain ⟨z,hz,hwz⟩ := ih hw - refine ⟨z,hz,Or.inr ?_⟩ - exact Set.mem_iUnion.mpr ⟨w,Set.mem_iUnion.mpr ⟨hwz,hwy⟩⟩ - - -theorem twoPoint_lower_on_multiples [Countable E] (G : BondGraph V E) - (p : unitInterval) (n : ℕ) (c : ℝ) (hc : 0 ≤ c) - (hball : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) - (k : ℕ) (x y : V) (hy : y ∈ reachBall G x (n*k)) : - c^k ≤ twoPoint G p x y := by - induction k generalizing x y with - | zero => - have he : y = x := by simpa [reachBall] using hy - subst y - simp [twoPoint_self] - | succ k ih => - rw [Nat.mul_succ] at hy - obtain ⟨z,hz,hyz⟩ := reachBall_add_split G x (n*k) n hy - calc - c^(k+1) = c^k*c := pow_succ _ _ - _ ≤ twoPoint G p x z * twoPoint G p z y := - mul_le_mul (ih x z hz) (hball z y hyz) hc (twoPoint_nonneg G p x z) - _ ≤ twoPoint G p x y := twoPoint_mul_le G p x z y - - -theorem reachBall_exponential_growth (G : BondGraph V E) (hloc : LocallyFinite G) - (hh : 0 ≤ hV G) (x : V) (n : ℕ) : - (1+hV G)^n ≤ ((reachBall G x n).ncard : ℝ) := by - classical - induction n with - | zero => simp [reachBall] - | succ n ih => - let A := (finite_reachBall hloc x n).toFinset - have he : reachBall G x (n+1) = (A : Set V) ∪ vertexBoundary G A := by - ext y - simp only [reachBall,Set.mem_union,Finset.mem_coe, - vertexBoundary,Set.mem_ofPred_eq,Set.mem_iUnion] - simp only [A,Set.Finite.mem_toFinset] - constructor - · rintro (hy | ⟨z,hz,hzy⟩) - · exact Or.inl hy - · by_cases hy : y ∈ reachBall G x n - · exact Or.inl hy - · exact Or.inr ⟨hy,z,hz,hzy⟩ - · rintro (hy | ⟨_,z,hz,hzy⟩) - · exact Or.inl hy - · exact Or.inr ⟨z,hz,hzy⟩ - have hd : Disjoint (A : Set V) (vertexBoundary G A) := by - exact Set.disjoint_left.mpr (fun y hy hb => hb.1 hy) - have hc : (reachBall G x (n+1)).ncard = A.card + (vertexBoundary G A).ncard := by - rw [he,Set.ncard_union_eq hd A.finite_toSet (finite_vertexBoundary G hloc A),Set.ncard_coe_finset] - have hcard : A.card = (reachBall G x n).ncard := - (Set.ncard_eq_toFinset_card _ (finite_reachBall hloc x n)).symm - have hs := hV_mul_card_le G A - rw [hcard] at hs - rw [hc,hcard,Nat.cast_add,pow_succ] - nlinarith [mul_le_mul_of_nonneg_right ih (show 0 ≤ 1+hV G by linarith)] - - - -theorem exists_subcritical_ball_lower [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (c : ℝ) (hc : 0 < c) (hcrit : ∀ x y, c ≤ twoPoint G (pc G) x y) - (n : ℕ) : ∃ p : unitInterval, p < pc G ∧ - ∀ x y, y ∈ reachBall G x n → c/2 ≤ twoPoint G p x y := by - classical - obtain ⟨p,hp,hpc,hlim⟩ := exists_seq_strictMono_tendsto' (pc_pos G hloc hqt) - obtain ⟨s,hs⟩ := hqt - have hev : ∀ᶠ k in atTop, ∀ x ∈ s, ∀ y ∈ reachBall G x n, - c/2 ≤ twoPoint G (p k) x y := by - apply (eventually_all_finset s).mpr - intro x hx - apply (finite_reachBall hloc x n).eventually_all.mpr - intro y hy - have ht := twoPoint_tendsto_of_monotone G p hp.monotone (pc G) - (fun k => (hpc k).2.le) hlim x y - have hlt : c/2 < twoPoint G (pc G) x y := lt_of_lt_of_le (by linarith) (hcrit x y) - exact (ht.eventually (eventually_gt_nhds hlt)).mono (fun k hk => hk.le) - obtain ⟨k,hk⟩ := hev.exists - refine ⟨p k,(hpc k).2,?_⟩ - intro x y hy - obtain ⟨o,ho,a,b,ha,hax⟩ := hs x - have hy' : a.symm y ∈ reachBall G o n := by - have hi := mem_reachBall_aut G (isAut_symm G ha) hy - simpa [←hax] using hi - have he := twoPoint_aut G (p k) ha o (a.symm y) - rw [hax,a.apply_symm_apply] at he - rw [he] - exact hk o ho (a.symm y) hy' - - - -theorem no_uniform_positive_twoPoint_critical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) : - ¬ ∃ c : ℝ, 0 < c ∧ ∀ x y, c ≤ twoPoint G (pc G) x y := by - rintro ⟨c,hc,hcrit⟩ - obtain ⟨n,hn⟩ := pow_unbounded_of_one_lt (2/c) (show 1 < 1+hV G by linarith) - have hn' : 1 < (c/2)*(1+hV G)^n := by - have := (div_lt_iff₀ hc).mp hn - nlinarith - obtain ⟨p,hp,hball⟩ := exists_subcritical_ball_lower G hloc hqt c hc hcrit n - obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp - obtain ⟨k,hk⟩ := pow_unbounded_of_one_lt C hn' - let x : V := Classical.arbitrary V - let A := (finite_reachBall hloc x (n*k)).toFinset - have hcard : (reachBall G x (n*k)).ncard = A.card := Set.ncard_eq_toFinset_card _ _ - have hsum : (A.card:ℝ)*(c/2)^k ≤ ∑ y ∈ A, twoPoint G p x y := by - calc - _ = ∑ y ∈ A, (c/2)^k := by simp - _ ≤ _ := Finset.sum_le_sum fun y hy => - twoPoint_lower_on_multiples G p n (c/2) (by linarith) hball k x y - (by simpa [A] using hy) - have hg := reachBall_exponential_growth G hloc hh.le x (n*k) - rw [hcard] at hg - have hpow : ((c/2)*(1+hV G)^n)^k ≤ (A.card:ℝ)*(c/2)^k := by - calc - _ = (1+hV G)^(n*k)*(c/2)^k := by rw [mul_pow,pow_mul]; ring - _ ≤ _ := mul_le_mul_of_nonneg_right hg (pow_nonneg (half_pos hc).le k) - exact (not_lt_of_ge (hpow.trans (hsum.trans (hrow x A)))) hk - - - -theorem not_unique_infinite_cluster_critical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) : - law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} ≠ 1 := by - intro hu - have hp := pc_pos G hloc hqt - have hpos : 0 < law (pc G) {ω | (infiniteClusters G ω).Nonempty} := - lt_of_lt_of_le (show 0 < law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} by - rw [hu]; exact zero_lt_one) - (measure_mono fun ω hω => ⟨hω.choose,hω.choose_spec.1⟩) - obtain ⟨θ,hθ,hroot⟩ := uniform_survival_pos G hconn hqt (pc G) hp hpos - have hue : ∀ᵐ ω ∂law (pc G), ∃! C, C ∈ infiniteClusters G ω := - (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu - apply no_uniform_positive_twoPoint_critical G hloc hqt hh - refine ⟨θ*θ,mul_pos hθ hθ,fun x y => ?_⟩ - refine (mul_le_mul (hroot x) (hroot y) hθ.le measureReal_nonneg).trans - ((association_infinite_cluster G (pc G) x y).trans ?_) - apply ENNReal.toReal_mono (measure_ne_top _ _) - apply measure_mono_ae - filter_upwards [hue] with ω hω - intro hi - obtain ⟨r,_,hconnr⟩ := (unique_infinite_cluster_iff G ω).mp hω - exact conn_trans G ω (conn_symm G ω (hconnr x hi.1)) (hconnr y hi.2) - -end Percolation - - - -open MeasureTheory ProbabilityTheory Filter Topology -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_finite_of_transport [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) : - ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by - let c : ℝ := ∑ i, 1/weight i - have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) - have hmin (i : ι) : 1 ≤ c*weight i := by - apply (div_le_iff₀ (hw i)).mp - exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - have hdn (x : V) := (incident_ncard_le_degree G hloc x).trans (hd x) - let A : Set (Set E) := {ω | ∀ a b, Adj G a b → - (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b} - have hA : MeasurableSet A := by - simp only [A,Set.ofPred_forall] - apply MeasurableSet.iInter - intro a - apply MeasurableSet.iInter - intro b - apply MeasurableSet.iInter - intro _ - simp only [imp_iff_not_or,Set.ofPred_or] - exact (measurableSet_infinite_cluster G a).compl.union - ((measurableSet_infinite_cluster G b).compl.union (measurableSet_conn G a b)) - have hae : ∀ᵐ ω ∂law (pc G), ω ∈ A := by - change ∀ᵐ ω ∂law (pc G), ∀ a b, Adj G a b → - (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b - rw [ae_all_iff] - intro a - rw [ae_all_iff] - intro b - rw [ae_all_iff] - rintro ⟨e,he⟩ - exact critical_adjacent_infinite_connected G hconn hloc hqt root weight Γ hΓ htr hcov - (fun i => (hw i).le) hw1 c hc hmin d hdn e a b he - have haeF : ∀ᵐ ω ∂law (pc G), ∀ F : Finset E, ω ∪ (F:Set E) ∈ A := by - rw [ae_all_iff] - intro F - exact ae_union_finset (pc G) (pc_pos G hloc hqt) A hA hae F - have hat : ∀ᵐ ω ∂law (pc G), ∀ x y, - (cluster G ω x).Infinite → (cluster G ω y).Infinite → Conn G ω x y := by - filter_upwards [haeF] with ω hω - exact atMostOne_of_finite_openings G hconn ω hω - have hex := infinite_cluster_zero_one G (pc G) - have he : (labelLaw : Measure (E → unitInterval)) - {labels | ∃ x, (cluster G (openEdges labels (pc G)) x).Infinite} = - law (pc G) {ω | ∃ x, (cluster G ω x).Infinite} := by - rw [←map_openEdges (pc G),Measure.map_apply (measurable_openEdges (pc G)) - (measurableSet_exists_infinite_cluster G)] - rfl - rw [he] at hex - have hz : law (pc G) {ω | ∃ x, (cluster G ω x).Infinite} = 0 := by - rcases hex with hzero | hone - · exact hzero - · exfalso - apply not_unique_infinite_cluster_critical G hconn hloc hqt hh - apply (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mp - have haex : ∀ᵐ ω ∂law (pc G), ∃ x, (cluster G ω x).Infinite := - (mem_ae_iff_prob_eq_one (measurableSet_exists_infinite_cluster G)).mpr hone - filter_upwards [hat,haex] with ω hω hex - obtain ⟨x,hx⟩ := hex - exact (unique_infinite_cluster_iff G ω).mpr ⟨x,hx,fun y hy => hω x y hx hy⟩ - intro x - rw [ae_iff] - apply measure_mono_null (t := {ω | ∃ y, (cluster G ω y).Infinite}) ?_ hz - intro ω hω - exact ⟨x,hω⟩ - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.Corridors +import OAI.Probability.UnimodularPercolation.TwoCluster.Bounds + +namespace OAI + +/-! Critical two-cluster estimates, finite opening and almost-sure finite clusters. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +section RootData +variable [Countable V] [Countable E] [Nonempty V] +variable (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) + +include hconn hloc hqt hΓ htr hcov hw hw1 hc hmin hd + + + +omit [Nonempty V] in +theorem critical_twoLarge_probability_bound + (n : ℕ) (hn : 0 < n) (e : E) (a b : V) (he : G e = s(a,b)) : + (pc G:ℝ) * ((n:ℝ) * (law (pc G)).real (twoLargeEvent G a b n)) ≤ + 20*c*Real.sqrt (d*n:ℕ) := by + obtain ⟨p,hp,hpc,hlim⟩ := exists_seq_strictMono_tendsto' (pc_pos G hloc hqt) + have ht := (continuous_subtype_val.tendsto (pc G) |>.comp hlim).mul + ((tendsto_const_nhds (x := (n:ℝ))).mul (twoLarge_probability_tendsto G p hp.monotone (pc G) + (fun j => (hpc j).2.le) hlim a b n)) + apply le_of_tendsto ht + apply Eventually.of_forall + intro j + have hb := twoLarge_probability_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 + c hc hmin d hd n hn (p j) (hpc j).1 + (subcritical_cluster_finite_ae G (p j) (hpc j).2) e a b he + change (p j:ℝ) * ((n:ℝ) * (law (p j)).real (twoLargeEvent G a b n)) ≤ _ + rw [mul_comm (p j:ℝ)] + exact (le_div_iff₀ (hpc j).1).mp hb + + + +omit [Nonempty V] in +theorem critical_adjacent_infinite_connected (e : E) (a b : V) (he : G e = s(a,b)) : + ∀ᵐ ω ∂law (pc G), (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b := by + let A : Set (Set E) := {ω | ¬Conn G ω a b ∧ + (cluster G ω a).Infinite ∧ (cluster G ω b).Infinite} + have hA : MeasurableSet A := (measurableSet_conn G a b).compl.inter + ((measurableSet_infinite_cluster G a).inter (measurableSet_infinite_cluster G b)) + have hp : 0 < (pc G:ℝ) := pc_pos G hloc hqt + have hzero : (law (pc G)).real A = 0 := by + by_contra hne + have hθ : 0 < (law (pc G)).real A := lt_of_le_of_ne measureReal_nonneg (Ne.symm hne) + have hb (n : ℕ) (hn : 0 < n) : + (pc G:ℝ)*((n:ℝ)*(law (pc G)).real A) ≤ 20*c*Real.sqrt (d*n:ℕ) := by + have hs : A ⊆ twoLargeEvent G a b n := by + intro ω h + refine ⟨h.1,?_,?_⟩ + · have hx : ω ∈ {ω | (cluster G ω a).Infinite} := h.2.1 + rw [infinite_cluster_eq_iInter G a] at hx + exact Set.mem_iInter.mp hx n + · have hx : ω ∈ {ω | (cluster G ω b).Infinite} := h.2.2 + rw [infinite_cluster_eq_iInter G b] at hx + exact Set.mem_iInter.mp hx n + exact (mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (measureReal_mono hs) (Nat.cast_nonneg n)) hp.le).trans + (critical_twoLarge_probability_bound G hconn hloc hqt root weight Γ hΓ htr hcov + hw hw1 c hc hmin d hd n hn e a b he) + let B := 20*c*Real.sqrt (d:ℝ) + obtain ⟨m,hm⟩ := exists_nat_gt (B / ((pc G:ℝ)*(law (pc G)).real A) + 1) + have hmpos : 0 < (m:ℝ) := lt_trans (by dsimp [B]; positivity) hm + have hmn : 0 < m := by exact_mod_cast hmpos + have hb' := hb (m^2) (pow_pos hmn _) + have hsqrt : Real.sqrt (d*(m^2):ℕ) = Real.sqrt (d:ℝ)*(m:ℝ) := by + rw [Nat.cast_mul,Nat.cast_pow,Real.sqrt_mul (Nat.cast_nonneg d),Real.sqrt_sq (Nat.cast_nonneg m)] + rw [hsqrt,Nat.cast_pow] at hb' + have hcancel : (pc G:ℝ)*(law (pc G)).real A*(m:ℝ) ≤ B := by + apply (mul_le_mul_iff_left₀ hmpos).mp + change ((pc G:ℝ)*(law (pc G)).real A*(m:ℝ))*(m:ℝ) ≤ B*(m:ℝ) + dsimp only [B] + nlinarith only [hb'] + have hlt : B < (pc G:ℝ)*(law (pc G)).real A*(m:ℝ) := by + have hdiv : B / ((pc G:ℝ)*(law (pc G)).real A) < (m:ℝ) := by linarith + have hh := (div_lt_iff₀ (mul_pos hp hθ)).mp hdiv + nlinarith + exact (not_lt_of_ge hcancel) hlt + have hn : law (pc G) A = 0 := (measureReal_eq_zero_iff).mp hzero + have hae : ∀ᵐ ω ∂law (pc G), ω ∉ A := by + rw [ae_iff]; simpa using hn + filter_upwards [hae] with ω hω ha hb + by_contra hc + exact hω ⟨hc,ha,hb⟩ + +end RootData +end Percolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem measure_union_finset_null [Countable E] (p : unitInterval) (hp : 0 < (p:ℝ)) + (A : Set (Set E)) (hA : MeasurableSet A) (hzero : law p A = 0) (F : Finset E) : + law p {ω | ω ∪ (F:Set E) ∈ A} = 0 := by + let B : Set (Set E) := {ω | ω ∪ (F:Set E) ∈ A} + let C : Set (Set E) := {ω | (F:Set E) ⊆ ω} + have hB : MeasurableSet B := hA.preimage + (measurable_set_union_pair.comp (measurable_id.prodMk measurable_const)) + have hC : MeasurableSet C := by + change MeasurableSet {ω | ∀ e ∈ F, e ∈ ω} + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun e => MeasurableSet.iInter fun _ => measurableSet_mem e + have heB : (fun ω : Set E => ω ∩ (F:Set E)ᶜ) ⁻¹' B = B := by + ext ω + have he : (ω ∩ (F:Set E)ᶜ) ∪ (F:Set E) = ω ∪ (F:Set E) := by + ext t + simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] + tauto + simp only [Set.mem_preimage,B,Set.mem_ofPred_eq,he] + have heC : (fun ω : Set E => ω ∩ (F:Set E)) ⁻¹' C = C := by + ext ω + simp [C] + have hi := restriction_events_independent p (F:Set E)ᶜ (F:Set E) + (Set.disjoint_left.mpr (fun _ hx hy => hx hy)) B C hB hC + rw [heB,heC] at hi + have hBC : law p (B ∩ C) = 0 := measure_mono_null (by + intro ω h + have he : ω ∪ (F:Set E) = ω := Set.union_eq_left.mpr h.2 + simpa only [B,Set.mem_ofPred_eq,he] using h.1) hzero + have hCp : 0 < (law p).real C := by + rw [show C = {ω | (F:Set E) ⊆ ω} from rfl,finite_open_probability] + exact pow_pos hp _ + exact (mul_eq_zero.mp (hi.symm.trans hBC)).resolve_right + (fun h => by simp [Measure.real,h] at hCp) + +theorem ae_union_finset [Countable E] (p : unitInterval) (hp : 0 < (p:ℝ)) + (A : Set (Set E)) (hA : MeasurableSet A) (hae : ∀ᵐ ω ∂law p, ω ∈ A) (F : Finset E) : + ∀ᵐ ω ∂law p, ω ∪ (F:Set E) ∈ A := by + rw [ae_iff] at hae ⊢ + exact measure_union_finset_null p hp Aᶜ hA.compl hae F + + + +theorem atMostOne_of_finite_openings (G : BondGraph V E) (hconn : Connected G) (ω : Set E) + (h : ∀ F : Finset E, ∀ a b, Adj G a b → + (cluster G (ω ∪ (F:Set E)) a).Infinite → + (cluster G (ω ∪ (F:Set E)) b).Infinite → Conn G (ω ∪ (F:Set E)) a b) : + ∀ x y, (cluster G ω x).Infinite → (cluster G ω y).Infinite → Conn G ω x y := by + intro x y hx hy + by_contra hxy + have hF : ∀ F : Finset E, ¬Conn G (ω ∪ (F:Set E)) x y := by + intro F + induction F using Finset.induction_on with + | empty => simpa only [Finset.coe_empty,Set.union_empty] using hxy + | @insert e F he ih => + have heq : ω ∪ ((insert e F : Finset E):Set E) = insert e (ω ∪ (F:Set E)) := by + ext t; simp only [Finset.coe_insert,Set.mem_union,Set.mem_insert_iff]; tauto + rw [heq] + obtain ⟨⟨a,b⟩,hab'⟩ := Sym2.mk_surjective (G e) + have hab : G e = s(a,b) := hab'.symm + rw [conn_insert_iff G _ e a b x y hab] + rintro (hc | ⟨hxa,hby⟩ | ⟨hxb,hay⟩) + · exact ih hc + · have ha : (cluster G (ω ∪ (F:Set E)) a).Infinite := by + rw [←cluster_eq_of_conn G _ hxa] + exact hx.mono (fun z hz => conn_mono G Set.subset_union_left hz) + have hb : (cluster G (ω ∪ (F:Set E)) b).Infinite := by + rw [cluster_eq_of_conn G _ hby] + exact hy.mono (fun z hz => conn_mono G Set.subset_union_left hz) + exact ih (conn_trans G _ hxa (conn_trans G _ (h F a b ⟨e,hab⟩ ha hb) hby)) + · have hb : (cluster G (ω ∪ (F:Set E)) b).Infinite := by + rw [←cluster_eq_of_conn G _ hxb] + exact hx.mono (fun z hz => conn_mono G Set.subset_union_left hz) + have ha : (cluster G (ω ∪ (F:Set E)) a).Infinite := by + rw [cluster_eq_of_conn G _ hay] + exact hy.mono (fun z hz => conn_mono G Set.subset_union_left hz) + exact ih (conn_trans G _ hxb (conn_trans G _ + (conn_symm G _ (h F a b ⟨e,hab⟩ ha hb)) hay)) + obtain ⟨F,_,hFc⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hconn x y) + exact hF F (conn_mono G Set.subset_union_right hFc) + +end Percolation + + + + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +open scoped ENNReal + + +theorem twoPoint_mul_le [Countable E] (G : BondGraph V E) (p : unitInterval) + (x y z : V) : twoPoint G p x y * twoPoint G p y z ≤ twoPoint G p x z := by + have h := association_finiteWitness p {ω : Set E | Conn G ω x y} + {ω : Set E | Conn G ω y z} + (fun _ _ hω h => conn_mono G hω h) (fun _ _ hω h => conn_mono G hω h) + (finiteWitness_conn G x y) (finiteWitness_conn G y z) + exact h.trans (measureReal_mono (fun ω hω => conn_trans G ω hω.1 hω.2)) + + +theorem reachBall_add_split (G : BondGraph V E) (x : V) (n m : ℕ) {y : V} + (hy : y ∈ reachBall G x (n+m)) : + ∃ z ∈ reachBall G x n, y ∈ reachBall G z m := by + induction m generalizing y with + | zero => exact ⟨y,hy,Set.mem_singleton y⟩ + | succ m ih => + rcases hy with hy | hy + · obtain ⟨z,hz,hyz⟩ := ih hy + exact ⟨z,hz,Or.inl hyz⟩ + · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy + obtain ⟨w,hw,hwy⟩ := hy + obtain ⟨z,hz,hwz⟩ := ih hw + refine ⟨z,hz,Or.inr ?_⟩ + exact Set.mem_iUnion.mpr ⟨w,Set.mem_iUnion.mpr ⟨hwz,hwy⟩⟩ + + +theorem twoPoint_lower_on_multiples [Countable E] (G : BondGraph V E) + (p : unitInterval) (n : ℕ) (c : ℝ) (hc : 0 ≤ c) + (hball : ∀ x y, y ∈ reachBall G x n → c ≤ twoPoint G p x y) + (k : ℕ) (x y : V) (hy : y ∈ reachBall G x (n*k)) : + c^k ≤ twoPoint G p x y := by + induction k generalizing x y with + | zero => + have he : y = x := by simpa [reachBall] using hy + subst y + simp [twoPoint_self] + | succ k ih => + rw [Nat.mul_succ] at hy + obtain ⟨z,hz,hyz⟩ := reachBall_add_split G x (n*k) n hy + calc + c^(k+1) = c^k*c := pow_succ _ _ + _ ≤ twoPoint G p x z * twoPoint G p z y := + mul_le_mul (ih x z hz) (hball z y hyz) hc (twoPoint_nonneg G p x z) + _ ≤ twoPoint G p x y := twoPoint_mul_le G p x z y + + +theorem reachBall_exponential_growth (G : BondGraph V E) (hloc : LocallyFinite G) + (hh : 0 ≤ hV G) (x : V) (n : ℕ) : + (1+hV G)^n ≤ ((reachBall G x n).ncard : ℝ) := by + classical + induction n with + | zero => simp [reachBall] + | succ n ih => + let A := (finite_reachBall hloc x n).toFinset + have he : reachBall G x (n+1) = (A : Set V) ∪ vertexBoundary G A := by + ext y + simp only [reachBall,Set.mem_union,Finset.mem_coe, + vertexBoundary,Set.mem_ofPred_eq,Set.mem_iUnion] + simp only [A,Set.Finite.mem_toFinset] + constructor + · rintro (hy | ⟨z,hz,hzy⟩) + · exact Or.inl hy + · by_cases hy : y ∈ reachBall G x n + · exact Or.inl hy + · exact Or.inr ⟨hy,z,hz,hzy⟩ + · rintro (hy | ⟨_,z,hz,hzy⟩) + · exact Or.inl hy + · exact Or.inr ⟨z,hz,hzy⟩ + have hd : Disjoint (A : Set V) (vertexBoundary G A) := by + exact Set.disjoint_left.mpr (fun y hy hb => hb.1 hy) + have hc : (reachBall G x (n+1)).ncard = A.card + (vertexBoundary G A).ncard := by + rw [he,Set.ncard_union_eq hd A.finite_toSet (finite_vertexBoundary G hloc A),Set.ncard_coe_finset] + have hcard : A.card = (reachBall G x n).ncard := + (Set.ncard_eq_toFinset_card _ (finite_reachBall hloc x n)).symm + have hs := hV_mul_card_le G A + rw [hcard] at hs + rw [hc,hcard,Nat.cast_add,pow_succ] + nlinarith [mul_le_mul_of_nonneg_right ih (show 0 ≤ 1+hV G by linarith)] + + + +theorem exists_subcritical_ball_lower [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (c : ℝ) (hc : 0 < c) (hcrit : ∀ x y, c ≤ twoPoint G (pc G) x y) + (n : ℕ) : ∃ p : unitInterval, p < pc G ∧ + ∀ x y, y ∈ reachBall G x n → c/2 ≤ twoPoint G p x y := by + classical + obtain ⟨p,hp,hpc,hlim⟩ := exists_seq_strictMono_tendsto' (pc_pos G hloc hqt) + obtain ⟨s,hs⟩ := hqt + have hev : ∀ᶠ k in atTop, ∀ x ∈ s, ∀ y ∈ reachBall G x n, + c/2 ≤ twoPoint G (p k) x y := by + apply (eventually_all_finset s).mpr + intro x hx + apply (finite_reachBall hloc x n).eventually_all.mpr + intro y hy + have ht := twoPoint_tendsto_of_monotone G p hp.monotone (pc G) + (fun k => (hpc k).2.le) hlim x y + have hlt : c/2 < twoPoint G (pc G) x y := lt_of_lt_of_le (by linarith) (hcrit x y) + exact (ht.eventually (eventually_gt_nhds hlt)).mono (fun k hk => hk.le) + obtain ⟨k,hk⟩ := hev.exists + refine ⟨p k,(hpc k).2,?_⟩ + intro x y hy + obtain ⟨o,ho,a,b,ha,hax⟩ := hs x + have hy' : a.symm y ∈ reachBall G o n := by + have hi := mem_reachBall_aut G (isAut_symm G ha) hy + simpa [←hax] using hi + have he := twoPoint_aut G (p k) ha o (a.symm y) + rw [hax,a.apply_symm_apply] at he + rw [he] + exact hk o ho (a.symm y) hy' + + + +theorem no_uniform_positive_twoPoint_critical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) : + ¬ ∃ c : ℝ, 0 < c ∧ ∀ x y, c ≤ twoPoint G (pc G) x y := by + rintro ⟨c,hc,hcrit⟩ + obtain ⟨n,hn⟩ := pow_unbounded_of_one_lt (2/c) (show 1 < 1+hV G by linarith) + have hn' : 1 < (c/2)*(1+hV G)^n := by + have := (div_lt_iff₀ hc).mp hn + nlinarith + obtain ⟨p,hp,hball⟩ := exists_subcritical_ball_lower G hloc hqt c hc hcrit n + obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp + obtain ⟨k,hk⟩ := pow_unbounded_of_one_lt C hn' + let x : V := Classical.arbitrary V + let A := (finite_reachBall hloc x (n*k)).toFinset + have hcard : (reachBall G x (n*k)).ncard = A.card := Set.ncard_eq_toFinset_card _ _ + have hsum : (A.card:ℝ)*(c/2)^k ≤ ∑ y ∈ A, twoPoint G p x y := by + calc + _ = ∑ y ∈ A, (c/2)^k := by simp + _ ≤ _ := Finset.sum_le_sum fun y hy => + twoPoint_lower_on_multiples G p n (c/2) (by linarith) hball k x y + (by simpa [A] using hy) + have hg := reachBall_exponential_growth G hloc hh.le x (n*k) + rw [hcard] at hg + have hpow : ((c/2)*(1+hV G)^n)^k ≤ (A.card:ℝ)*(c/2)^k := by + calc + _ = (1+hV G)^(n*k)*(c/2)^k := by rw [mul_pow,pow_mul]; ring + _ ≤ _ := mul_le_mul_of_nonneg_right hg (pow_nonneg (half_pos hc).le k) + exact (not_lt_of_ge (hpow.trans (hsum.trans (hrow x A)))) hk + + + +theorem not_unique_infinite_cluster_critical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) : + law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} ≠ 1 := by + intro hu + have hp := pc_pos G hloc hqt + have hpos : 0 < law (pc G) {ω | (infiniteClusters G ω).Nonempty} := + lt_of_lt_of_le (show 0 < law (pc G) {ω | ∃! C, C ∈ infiniteClusters G ω} by + rw [hu]; exact zero_lt_one) + (measure_mono fun ω hω => ⟨hω.choose,hω.choose_spec.1⟩) + obtain ⟨θ,hθ,hroot⟩ := uniform_survival_pos G hconn hqt (pc G) hp hpos + have hue : ∀ᵐ ω ∂law (pc G), ∃! C, C ∈ infiniteClusters G ω := + (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu + apply no_uniform_positive_twoPoint_critical G hloc hqt hh + refine ⟨θ*θ,mul_pos hθ hθ,fun x y => ?_⟩ + refine (mul_le_mul (hroot x) (hroot y) hθ.le measureReal_nonneg).trans + ((association_infinite_cluster G (pc G) x y).trans ?_) + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono_ae + filter_upwards [hue] with ω hω + intro hi + obtain ⟨r,_,hconnr⟩ := (unique_infinite_cluster_iff G ω).mp hω + exact conn_trans G ω (conn_symm G ω (hconnr x hi.1)) (hconnr y hi.2) + +end Percolation + + + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_finite_of_transport [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) : + ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by + let c : ℝ := ∑ i, 1/weight i + have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) + have hmin (i : ι) : 1 ≤ c*weight i := by + apply (div_le_iff₀ (hw i)).mp + exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + have hdn (x : V) := (incident_ncard_le_degree G hloc x).trans (hd x) + let A : Set (Set E) := {ω | ∀ a b, Adj G a b → + (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b} + have hA : MeasurableSet A := by + simp only [A,Set.ofPred_forall] + apply MeasurableSet.iInter + intro a + apply MeasurableSet.iInter + intro b + apply MeasurableSet.iInter + intro _ + simp only [imp_iff_not_or,Set.ofPred_or] + exact (measurableSet_infinite_cluster G a).compl.union + ((measurableSet_infinite_cluster G b).compl.union (measurableSet_conn G a b)) + have hae : ∀ᵐ ω ∂law (pc G), ω ∈ A := by + change ∀ᵐ ω ∂law (pc G), ∀ a b, Adj G a b → + (cluster G ω a).Infinite → (cluster G ω b).Infinite → Conn G ω a b + rw [ae_all_iff] + intro a + rw [ae_all_iff] + intro b + rw [ae_all_iff] + rintro ⟨e,he⟩ + exact critical_adjacent_infinite_connected G hconn hloc hqt root weight Γ hΓ htr hcov + (fun i => (hw i).le) hw1 c hc hmin d hdn e a b he + have haeF : ∀ᵐ ω ∂law (pc G), ∀ F : Finset E, ω ∪ (F:Set E) ∈ A := by + rw [ae_all_iff] + intro F + exact ae_union_finset (pc G) (pc_pos G hloc hqt) A hA hae F + have hat : ∀ᵐ ω ∂law (pc G), ∀ x y, + (cluster G ω x).Infinite → (cluster G ω y).Infinite → Conn G ω x y := by + filter_upwards [haeF] with ω hω + exact atMostOne_of_finite_openings G hconn ω hω + have hex := infinite_cluster_zero_one G (pc G) + have he : (labelLaw : Measure (E → unitInterval)) + {labels | ∃ x, (cluster G (openEdges labels (pc G)) x).Infinite} = + law (pc G) {ω | ∃ x, (cluster G ω x).Infinite} := by + rw [←map_openEdges (pc G),Measure.map_apply (measurable_openEdges (pc G)) + (measurableSet_exists_infinite_cluster G)] + rfl + rw [he] at hex + have hz : law (pc G) {ω | ∃ x, (cluster G ω x).Infinite} = 0 := by + rcases hex with hzero | hone + · exact hzero + · exfalso + apply not_unique_infinite_cluster_critical G hconn hloc hqt hh + apply (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mp + have haex : ∀ᵐ ω ∂law (pc G), ∃ x, (cluster G ω x).Infinite := + (mem_ae_iff_prob_eq_one (measurableSet_exists_infinite_cluster G)).mpr hone + filter_upwards [hat,haex] with ω hω hex + obtain ⟨x,hx⟩ := hex + exact (unique_infinite_cluster_iff G ω).mpr ⟨x,hx,fun y hy => hω x y hx hy⟩ + intro x + rw [ae_iff] + apply measure_mono_null (t := {ω | ∃ y, (cluster G ω y).Infinite}) ?_ hz + intro ω hω + exact ⟨x,hω⟩ + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/FullFiniteness.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/FullFiniteness.lean index 5306cba0ddc12d3e9d7b617d33162fb079922d07..afb266c8732f18df90dcbcf4076bdefc97fcd6d6 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/FullFiniteness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/FullFiniteness.lean @@ -1,80 +1,80 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Criticality.ClusterCount -import OAI.Probability.UnimodularPercolation.Encounter.Surgery -import OAI.Probability.UnimodularPercolation.Encounter.ZeroIntensity - -namespace OAI - -/-! Almost-sure critical cluster finiteness from the full root transport. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteOverwrite_preimage_zero [Countable E] (p : unitInterval) - (hp : 0 < p) (hp1 : p < 1) (F P : Finset E) (hPF : P ⊆ F) - (B : Set (Set E)) (hB : MeasurableSet B) (hz : law p B = 0) : - law p ((finiteOverwrite F P) ⁻¹' B) = 0 := by - by_contra hn - have hpos := finiteOverwrite_pos p hp hp1 F P hPF - ((finiteOverwrite F P) ⁻¹' B) B hB (pos_iff_ne_zero.mpr hn) (fun _ h => h) - rw [hz] at hpos - exact lt_irrefl _ hpos - -theorem critical_finite_count_ae_of_transport [Infinite V] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : - ∀ᵐ ω ∂law (pc G), (infiniteClusters G ω).Finite := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - have hp := pc_pos G hloc hqt - have hp1 := pc_lt_one_of_nonamenable G hconn hloc hqt hh - have he (F P : Finset E) (x : V) : - ∀ᵐ ω ∂law (pc G), P ⊆ F → ¬ IsEncounter G (finiteOverwrite F P ω) x := by - by_cases hPF : P ⊆ F - · have hz := finiteOverwrite_preimage_zero (pc G) hp hp1 F P hPF - {ω | IsEncounter G ω x} (measurableSet_isEncounter G x) - (critical_encounter_zero G hconn hloc hp root weight htr hw hw1 hcov x) - apply ae_iff.mpr - simpa only [hPF,true_implies,not_not,Set.preimage_ofPred_eq] using hz - · filter_upwards [] with ω - exact fun h => False.elim (hPF h) - have hall : ∀ᵐ ω ∂law (pc G), ∀ F P : Finset E, ∀ x : V, - P ⊆ F → ¬ IsEncounter G (finiteOverwrite F P ω) x := - ae_all_iff.mpr fun F => ae_all_iff.mpr fun P => ae_all_iff.mpr (he F P) - filter_upwards [hall] with ω hω - by_contra hinf - obtain ⟨z,hz,hsep⟩ := three_of_infinite_count G ω hinf - obtain ⟨F,P,hPF,x,hx⟩ := encounter_surgery_of_three G hconn hloc ω z hz hsep - exact hω F P x hPF hx - -theorem critical_finite_ae_of_transport [Infinite V] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : - ∀ᵐ ω ∂law (pc G), ∀ x, (cluster G ω x).Finite := by - filter_upwards [critical_finite_count_ae_of_transport G hconn hloc hqt hh - root weight htr hw hw1 hcov,critical_finite_count_empty_ae G hconn hloc hqt hh] with ω hf he - have hempty := he hf - intro x - by_contra hx - have hc : cluster G ω x ∈ infiniteClusters G ω := ⟨hx,x,rfl⟩ - rw [hempty] at hc - exact hc - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Criticality.ClusterCount +import OAI.Probability.UnimodularPercolation.Encounter.Surgery +import OAI.Probability.UnimodularPercolation.Encounter.ZeroIntensity + +namespace OAI + +/-! Almost-sure critical cluster finiteness from the full root transport. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteOverwrite_preimage_zero [Countable E] (p : unitInterval) + (hp : 0 < p) (hp1 : p < 1) (F P : Finset E) (hPF : P ⊆ F) + (B : Set (Set E)) (hB : MeasurableSet B) (hz : law p B = 0) : + law p ((finiteOverwrite F P) ⁻¹' B) = 0 := by + by_contra hn + have hpos := finiteOverwrite_pos p hp hp1 F P hPF + ((finiteOverwrite F P) ⁻¹' B) B hB (pos_iff_ne_zero.mpr hn) (fun _ h => h) + rw [hz] at hpos + exact lt_irrefl _ hpos + +theorem critical_finite_count_ae_of_transport [Infinite V] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : + ∀ᵐ ω ∂law (pc G), (infiniteClusters G ω).Finite := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + have hp := pc_pos G hloc hqt + have hp1 := pc_lt_one_of_nonamenable G hconn hloc hqt hh + have he (F P : Finset E) (x : V) : + ∀ᵐ ω ∂law (pc G), P ⊆ F → ¬ IsEncounter G (finiteOverwrite F P ω) x := by + by_cases hPF : P ⊆ F + · have hz := finiteOverwrite_preimage_zero (pc G) hp hp1 F P hPF + {ω | IsEncounter G ω x} (measurableSet_isEncounter G x) + (critical_encounter_zero G hconn hloc hp root weight htr hw hw1 hcov x) + apply ae_iff.mpr + simpa only [hPF,true_implies,not_not,Set.preimage_ofPred_eq] using hz + · filter_upwards [] with ω + exact fun h => False.elim (hPF h) + have hall : ∀ᵐ ω ∂law (pc G), ∀ F P : Finset E, ∀ x : V, + P ⊆ F → ¬ IsEncounter G (finiteOverwrite F P ω) x := + ae_all_iff.mpr fun F => ae_all_iff.mpr fun P => ae_all_iff.mpr (he F P) + filter_upwards [hall] with ω hω + by_contra hinf + obtain ⟨z,hz,hsep⟩ := three_of_infinite_count G ω hinf + obtain ⟨F,P,hPF,x,hx⟩ := encounter_surgery_of_three G hconn hloc ω z hz hsep + exact hω F P x hPF hx + +theorem critical_finite_ae_of_transport [Infinite V] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : + ∀ᵐ ω ∂law (pc G), ∀ x, (cluster G ω x).Finite := by + filter_upwards [critical_finite_count_ae_of_transport G hconn hloc hqt hh + root weight htr hw hw1 hcov,critical_finite_count_empty_ae G hconn hloc hqt hh] with ω hf he + have hempty := he hf + intro x + by_contra hx + have hc : cluster G ω x ∈ infiniteClusters G ω := ⟨hx,x,rfl⟩ + rw [hempty] at hc + exact hc + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/FullOperator.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/FullOperator.lean index 2975a04307d0ef1751cdcdc2b972b9b02ce8ee04..db1dac7436ea315b8b411aa7841990a19072dd52 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/FullOperator.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/FullOperator.lean @@ -1,59 +1,59 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Criticality.FullFiniteness -import OAI.Probability.UnimodularPercolation.Transport.InvariantRoot - -namespace OAI - -/-! Critical operator boundedness for the full unimodular automorphism group. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory -universe u v -variable {V : Type u} {E : Type v} -variable [TopologicalSpace V] [DiscreteTopology V] - -theorem critical_bounded_of_graphUnimodular [Infinite V] (G : BondGraph V E) - (hinj : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) (x₀ : V) - (hu : GraphUnimodular G hinj hloc hconn x₀) : OperatorBounded G (pc G) := by - obtain ⟨n,root,weight,_,hw,hw1,htr,hcov⟩ := - exists_rootTransport_of_unimodular G hinj hloc hconn hqt x₀ hu - have hf := critical_finite_ae_of_transport G hconn hloc hqt hh - root weight htr hw hw1 hcov - apply critical_bounded_of_transport_finiteness G hinj hconn hloc hqt hh - root weight htr hcov hw hw1 - intro i - filter_upwards [hf] with ω hω - exact hω (root i) - -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -noncomputable def FullAutUnimodular (G : BondGraph V E) - (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) - (x₀ : V) : Prop := by - letI : TopologicalSpace V := ⊥ - letI : DiscreteTopology V := ⟨rfl⟩ - exact GraphUnimodular G hinj hloc hconn x₀ - -theorem critical_operator_fullAut [Infinite V] (G : BondGraph V E) - (hinj : Function.Injective G) (_hloop : ∀ x, ¬Adj G x x) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (x₀ : V) - (hu : FullAutUnimodular G hinj hloc hconn x₀) : - operatorNorm G (pc G) < ⊤ := by - let : TopologicalSpace V := ⊥ - let : DiscreteTopology V := ⟨rfl⟩ - apply (operatorNorm_lt_top_iff G (pc G)).mpr - exact critical_bounded_of_graphUnimodular G hinj hconn hloc hqt hh x₀ hu - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Criticality.FullFiniteness +import OAI.Probability.UnimodularPercolation.Transport.InvariantRoot + +namespace OAI + +/-! Critical operator boundedness for the full unimodular automorphism group. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory +universe u v +variable {V : Type u} {E : Type v} +variable [TopologicalSpace V] [DiscreteTopology V] + +theorem critical_bounded_of_graphUnimodular [Infinite V] (G : BondGraph V E) + (hinj : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) (x₀ : V) + (hu : GraphUnimodular G hinj hloc hconn x₀) : OperatorBounded G (pc G) := by + obtain ⟨n,root,weight,_,hw,hw1,htr,hcov⟩ := + exists_rootTransport_of_unimodular G hinj hloc hconn hqt x₀ hu + have hf := critical_finite_ae_of_transport G hconn hloc hqt hh + root weight htr hw hw1 hcov + apply critical_bounded_of_transport_finiteness G hinj hconn hloc hqt hh + root weight htr hcov hw hw1 + intro i + filter_upwards [hf] with ω hω + exact hω (root i) + +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +noncomputable def FullAutUnimodular (G : BondGraph V E) + (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) + (x₀ : V) : Prop := by + letI : TopologicalSpace V := ⊥ + letI : DiscreteTopology V := ⟨rfl⟩ + exact GraphUnimodular G hinj hloc hconn x₀ + +theorem critical_operator_fullAut [Infinite V] (G : BondGraph V E) + (hinj : Function.Injective G) (_hloop : ∀ x, ¬Adj G x x) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (x₀ : V) + (hu : FullAutUnimodular G hinj hloc hconn x₀) : + operatorNorm G (pc G) < ⊤ := by + let : TopologicalSpace V := ⊥ + let : DiscreteTopology V := ⟨rfl⟩ + apply (operatorNorm_lt_top_iff G (pc G)).mpr + exact critical_bounded_of_graphUnimodular G hinj hconn hloc hqt hh x₀ hu + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Operator.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Operator.lean index 7050da574eb4dd7ab9a53c8d7572b46ade2889aa..f31d5ea3d15f271bcfc8639f196ef5d6de727886 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Operator.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Operator.lean @@ -1,274 +1,274 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Criticality.Finiteness -import OAI.Probability.UnimodularPercolation.Criticality.ScaleLimits -import OAI.Probability.UnimodularPercolation.Deformation.FiniteScale -import OAI.Probability.UnimodularPercolation.Graph.Automorphisms - -namespace OAI - -/-! Critical boundedness of the percolation operator under unimodularity and simple edge indexing. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory Filter -open scoped Topology - - -noncomputable def criticalApproach (q : unitInterval) (n : ℕ) : unitInterval := - ⟨(q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)),by - have he : Real.exp (-(n:ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Nat.cast_nonneg n)) - have hq := q.2 - have hp := Real.exp_pos (-(n:ℝ)) - constructor <;> nlinarith only [he,hq.1,hq.2,hp]⟩ - -theorem criticalApproach_half (q : unitInterval) (n : ℕ) : - (q:ℝ)/2 ≤ (criticalApproach q n : ℝ) := by - have he : Real.exp (-(n:ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Nat.cast_nonneg n)) - change _ ≤ (q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)) - nlinarith only [he,q.2.1] - -theorem criticalApproach_lt (q : unitInterval) (hq : 0 < (q:ℝ)) (n : ℕ) : - criticalApproach q n < q := by - change (q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)) < q - exact sub_lt_self _ (mul_pos (half_pos hq) (Real.exp_pos _)) - -theorem criticalApproach_gap (q : unitInterval) (n : ℕ) : - (q:ℝ)-(criticalApproach q n:ℝ) = (q:ℝ)/2*Real.exp (-(n:ℝ)) := by - change (q:ℝ)-((q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ))) = _ - ring - - - -theorem log_sublinear_of_geometric_gap (f : ℕ → ℝ) (p₀ : ℝ) (hp₀ : 0 < p₀) - (hf : ∀ n, 1 ≤ f n) - (hb : ∀ η : ℝ, 0 < η → ∃ K : ℝ, 0 < K ∧ - ∀ n : ℕ, f n ≤ K*(p₀*Real.exp (-(n:ℝ)))^(-η)) : - Tendsto (fun n => Real.log (f n)/(n:ℝ)) atTop (𝓝 0) := by - apply log_sublinear_of_subexp f hf - intro η hη - obtain ⟨K,hK,hbK⟩ := hb η hη - refine ⟨K*p₀^(-η),mul_pos hK (Real.rpow_pos_of_pos hp₀ _),fun n => ?_⟩ - have he : (p₀*Real.exp (-(n:ℝ)))^(-η) = p₀^(-η)*Real.exp (η*(n:ℝ)) := by - rw [Real.mul_rpow hp₀.le (Real.exp_pos _).le,←Real.exp_mul] - congr 2 - ring - simpa only [he,mul_assoc] using hbK n - -universe u v -variable {V : Type u} {E : Type v} -section AnalyticCritical -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Infinite V] [Nonempty E] -variable {ι : Type*} [Fintype ι] [Nonempty ι] - - - -theorem critical_bounded_of_fixed_data - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (hh : 0 < hV G) - (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) : - OperatorBounded G (pc G) := by - by_contra hu - obtain ⟨C,hC,J,hJ,C₁,hC₁,k₀,hk₀,ε,M,hε,_,hbad⟩ := - exists_finite_scale_obstruction G hG hconn hloc hqt a ha root weight htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag hρ d hd hpcrit hpcrit₁ - let p := criticalApproach (pc G) - have hpnear (n) : (pc G:ℝ)/2 ≤ (p n:ℝ) := criticalApproach_half (pc G) n - have hp (n) : p n < pc G := criticalApproach_lt (pc G) hpcrit n - have hpzero (n) : 0 < (p n:ℝ) := (half_pos hpcrit).trans_le (hpnear n) - let A := fun n => Classical.choose (operatorBounded_of_lt_pc G hloc hqt (p n) (hp n)) - have hA (n) : HasKernel G (p n) (A n) := Classical.choose_spec (operatorBounded_of_lt_pc G hloc hqt (p n) (hp n)) - let m := fun n => ‖A n‖ - let R := fun n => maxSusceptibility G (p n)/m n - let Q := fun n => rootTriangle G root weight (p n:ℝ) - have hR (n) : 1 ≤ R n := (one_le_div (zero_lt_one.trans_le ((hA n).norm_one_le G (p n) (A n)))).mpr - ((hA n).norm_le_maxSusceptibility G hloc hqt (p n) (hp n) (A n)) - have hQ (n) : 1 ≤ Q n := rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 (p n) (hp n) - have hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0) := by - apply log_sublinear_of_geometric_gap R ((pc G:ℝ)/2) (half_pos hpcrit) hR - intro η hη - obtain ⟨K,hK,hRK⟩ := critical_normRatio_subpower G hloc hconn hqt hh root weight (vertexAut G) - (Set.Subset.refl _) htr hcov hw hw1 hpcrit hpcrit₁ hfin hu η hη - refine ⟨K,hK,fun n => ?_⟩ - simpa only [p,criticalApproach_gap] using (hRK (p n) (hpnear n) (hp n) (A n) (hA n)).2 - have hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0) := by - apply log_sublinear_of_geometric_gap Q ((pc G:ℝ)/2) (half_pos hpcrit) hQ - intro η hη - obtain ⟨K,hK,hQK⟩ := critical_rootTriangle_subpower G hloc hconn hqt hh root weight (vertexAut G) - (Set.Subset.refl _) htr hcov hw hw1 hpcrit hpcrit₁ hfin η hη - refine ⟨K,hK,fun n => ?_⟩ - simpa only [p,criticalApproach_gap] using hQK (p n) (hpnear n) (hp n) - obtain ⟨cm,hcm,hm⟩ := critical_norm_inverse_lower G hloc hqt hpcrit₁ hu - have hmlower (n : ℕ) : (cm/((pc G:ℝ)/2))*Real.exp (n:ℝ) ≤ m n := by - have hh := hm (p n) (hpzero n) (hp n) (A n) (hA n) - rw [show (pc G:ℝ)-(p n:ℝ) = (pc G:ℝ)/2*Real.exp (-(n:ℝ)) from criticalApproach_gap (pc G) n, - Real.exp_neg,div_mul_eq_div_div,div_inv_eq_mul] at hh - exact hh - have hρpos : 0 < ‖P‖ := by - let x : V := Classical.arbitrary V - have hh := (hdiag x).trans ((Complex.re_le_norm _).trans (matrixCoeff_norm_le P x x)) - linarith only [hh] - obtain ⟨n,k,B,hk,hB,hsmall,htime,herror,hlarge⟩ := exists_corridor_scales - ‖P‖ ((pc G:ℝ)/2) C C₁ ε M (cm/((pc G:ℝ)/2)) J k₀ hρpos hρ (half_pos hpcrit) hC hC₁ hε - (div_pos hcm (half_pos hpcrit)) hJ m R Q hR hQ hmlower hlogR hlogQ - exact hbad (p n) (hpnear n) (hp n) (A n) (hA n) k hk B hB hsmall htime herror hlarge - -end AnalyticCritical - - - -theorem nonempty_bonds_of_connected [Infinite V] (G : BondGraph V E) (hconn : Connected G) : Nonempty E := by - classical - by_contra he - let : IsEmpty E := not_nonempty_iff.mp he - obtain ⟨x,y,hxy⟩ := exists_pair_ne V - have hh := conn_univ_of_connected G hconn x y - have heq : (Set.univ : Set E) = ∅ := Set.eq_empty_of_isEmpty _ - rw [heq,conn_empty_iff] at hh - exact hxy hh - - - -theorem critical_bounded_of_transport_finiteness [Infinite V] - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) : - OperatorBounded G (pc G) := by - classical - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - let : Nonempty E := nonempty_bonds_of_connected G hconn - let : Nonempty ι := ⟨(hcov (Classical.arbitrary V)).choose⟩ - let c := ∑ i, (weight i)⁻¹ - have hc : 0 < c := Finset.sum_pos (fun i _ => inv_pos.mpr (hw i)) Finset.univ_nonempty - have hmin (i) : 1 ≤ c*weight i := by - have hi : (weight i)⁻¹ ≤ c := Finset.single_le_sum - (fun j _ => (inv_pos.mpr (hw j)).le) (Finset.mem_univ i) - simpa only [inv_mul_cancel₀ (hw i).ne'] using mul_le_mul_of_nonneg_right hi (hw i).le - obtain ⟨d,P,hdpos,hd,hρ,hPs,hP⟩ := exists_strict_walk_operator G hloc hqt hh - let a := (1:ℝ)/(2*d) - have hdr : (0:ℝ) < d := Nat.cast_pos.mpr hdpos - have ha : 0 < a := by dsimp [a]; positivity - have had : a*d = 1/2 := by dsimp [a]; field_simp - have hPe : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ) := hP - have hPpos : PositiveRealMatrix P := by - intro x y - rw [hPe] - refine ⟨rfl,?_⟩ - exact walkKernel_nonneg G hloc d hd a ha.le (by rw [had]; norm_num) x y - have hdiag (x) : 1/2 ≤ (matrixCoeff P x x).re := by - rw [hPe,Complex.ofReal_re] - exact walkKernel_lazy G hloc d hd a ha.le had.le x - exact critical_bounded_of_fixed_data G hG hconn hloc hqt hh a ha root weight htr hcov hw hw1 c hc hmin - P hPpos hPs.isSelfAdjoint hPe hdiag hρ d hd (pc_pos G hloc hqt) - (pc_lt_one_of_nonamenable G hconn hloc hqt hh) hfin - -end Percolation - - - - - -namespace Percolation -open MeasureTheory -universe u v -variable {V : Type u} {E : Type v} - - - -noncomputable def AutUnimodular [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : Prop := - letI : TopologicalSpace V := ⊥ - letI : DiscreteTopology V := ⟨rfl⟩ - (graphHaar G hG hconn hloc).IsMulRightInvariant - - - -theorem critical_bounded_of_unimodular_finiteness [Infinite V] - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) - (hfin : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite) : - OperatorBounded G (pc G) := by - classical - let : TopologicalSpace V := ⊥ - let : DiscreteTopology V := ⟨rfl⟩ - let : Countable V := countable_vertices hloc hconn - let : MeasurableSpace V := borel V - let : BorelSpace V := ⟨rfl⟩ - obtain ⟨ι,hι,hn,root,weight,htr,hcov,hw,hw1⟩ := - exists_rootData_of_unimodular G hG hconn hloc hqt huni - let : Fintype ι := hι - exact critical_bounded_of_transport_finiteness G hG hconn hloc hqt hh - root weight htr hcov hw hw1 (fun i => hfin (root i)) - - - -theorem critical_finite_of_unimodular [Infinite V] - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : - ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by - classical - let : TopologicalSpace V := ⊥ - let : DiscreteTopology V := ⟨rfl⟩ - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - let : MeasurableSpace V := borel V - let : BorelSpace V := ⟨rfl⟩ - obtain ⟨ι,hι,hn,root,weight,htr,hcov,hw,hw1⟩ := - exists_rootData_of_unimodular G hG hconn hloc hqt huni - let : Fintype ι := hι - exact critical_finite_of_transport G hconn hloc hqt hh root weight - (vertexAut G) (Set.Subset.refl _) htr hcov hw hw1 - - - -theorem critical_bounded_of_unimodular [Infinite V] - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : - OperatorBounded G (pc G) := by - exact critical_bounded_of_unimodular_finiteness G hG hconn hloc hqt hh huni - (critical_finite_of_unimodular G hG hconn hloc hqt hh huni) - -end Percolation - - - -namespace Percolation -open MeasureTheory -universe u v -variable {V : Type u} {E : Type v} - - - -theorem critical_operator [Infinite V] - (G : BondGraph V E) (hG : Function.Injective G) - (_hloop : ∀ e x, G e ≠ s(x,x)) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : - operatorNorm G (pc G) < ⊤ - := by - exact (operatorNorm_lt_top_iff G (pc G)).mpr - (critical_bounded_of_unimodular G hG hconn hloc hqt hh huni) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Criticality.Finiteness +import OAI.Probability.UnimodularPercolation.Criticality.ScaleLimits +import OAI.Probability.UnimodularPercolation.Deformation.FiniteScale +import OAI.Probability.UnimodularPercolation.Graph.Automorphisms + +namespace OAI + +/-! Critical boundedness of the percolation operator under unimodularity and simple edge indexing. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory Filter +open scoped Topology + + +noncomputable def criticalApproach (q : unitInterval) (n : ℕ) : unitInterval := + ⟨(q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)),by + have he : Real.exp (-(n:ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Nat.cast_nonneg n)) + have hq := q.2 + have hp := Real.exp_pos (-(n:ℝ)) + constructor <;> nlinarith only [he,hq.1,hq.2,hp]⟩ + +theorem criticalApproach_half (q : unitInterval) (n : ℕ) : + (q:ℝ)/2 ≤ (criticalApproach q n : ℝ) := by + have he : Real.exp (-(n:ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Nat.cast_nonneg n)) + change _ ≤ (q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)) + nlinarith only [he,q.2.1] + +theorem criticalApproach_lt (q : unitInterval) (hq : 0 < (q:ℝ)) (n : ℕ) : + criticalApproach q n < q := by + change (q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ)) < q + exact sub_lt_self _ (mul_pos (half_pos hq) (Real.exp_pos _)) + +theorem criticalApproach_gap (q : unitInterval) (n : ℕ) : + (q:ℝ)-(criticalApproach q n:ℝ) = (q:ℝ)/2*Real.exp (-(n:ℝ)) := by + change (q:ℝ)-((q:ℝ)-(q:ℝ)/2*Real.exp (-(n:ℝ))) = _ + ring + + + +theorem log_sublinear_of_geometric_gap (f : ℕ → ℝ) (p₀ : ℝ) (hp₀ : 0 < p₀) + (hf : ∀ n, 1 ≤ f n) + (hb : ∀ η : ℝ, 0 < η → ∃ K : ℝ, 0 < K ∧ + ∀ n : ℕ, f n ≤ K*(p₀*Real.exp (-(n:ℝ)))^(-η)) : + Tendsto (fun n => Real.log (f n)/(n:ℝ)) atTop (𝓝 0) := by + apply log_sublinear_of_subexp f hf + intro η hη + obtain ⟨K,hK,hbK⟩ := hb η hη + refine ⟨K*p₀^(-η),mul_pos hK (Real.rpow_pos_of_pos hp₀ _),fun n => ?_⟩ + have he : (p₀*Real.exp (-(n:ℝ)))^(-η) = p₀^(-η)*Real.exp (η*(n:ℝ)) := by + rw [Real.mul_rpow hp₀.le (Real.exp_pos _).le,←Real.exp_mul] + congr 2 + ring + simpa only [he,mul_assoc] using hbK n + +universe u v +variable {V : Type u} {E : Type v} +section AnalyticCritical +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Infinite V] [Nonempty E] +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + + +theorem critical_bounded_of_fixed_data + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (hh : 0 < hV G) + (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) : + OperatorBounded G (pc G) := by + by_contra hu + obtain ⟨C,hC,J,hJ,C₁,hC₁,k₀,hk₀,ε,M,hε,_,hbad⟩ := + exists_finite_scale_obstruction G hG hconn hloc hqt a ha root weight htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag hρ d hd hpcrit hpcrit₁ + let p := criticalApproach (pc G) + have hpnear (n) : (pc G:ℝ)/2 ≤ (p n:ℝ) := criticalApproach_half (pc G) n + have hp (n) : p n < pc G := criticalApproach_lt (pc G) hpcrit n + have hpzero (n) : 0 < (p n:ℝ) := (half_pos hpcrit).trans_le (hpnear n) + let A := fun n => Classical.choose (operatorBounded_of_lt_pc G hloc hqt (p n) (hp n)) + have hA (n) : HasKernel G (p n) (A n) := Classical.choose_spec (operatorBounded_of_lt_pc G hloc hqt (p n) (hp n)) + let m := fun n => ‖A n‖ + let R := fun n => maxSusceptibility G (p n)/m n + let Q := fun n => rootTriangle G root weight (p n:ℝ) + have hR (n) : 1 ≤ R n := (one_le_div (zero_lt_one.trans_le ((hA n).norm_one_le G (p n) (A n)))).mpr + ((hA n).norm_le_maxSusceptibility G hloc hqt (p n) (hp n) (A n)) + have hQ (n) : 1 ≤ Q n := rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 (p n) (hp n) + have hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0) := by + apply log_sublinear_of_geometric_gap R ((pc G:ℝ)/2) (half_pos hpcrit) hR + intro η hη + obtain ⟨K,hK,hRK⟩ := critical_normRatio_subpower G hloc hconn hqt hh root weight (vertexAut G) + (Set.Subset.refl _) htr hcov hw hw1 hpcrit hpcrit₁ hfin hu η hη + refine ⟨K,hK,fun n => ?_⟩ + simpa only [p,criticalApproach_gap] using (hRK (p n) (hpnear n) (hp n) (A n) (hA n)).2 + have hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0) := by + apply log_sublinear_of_geometric_gap Q ((pc G:ℝ)/2) (half_pos hpcrit) hQ + intro η hη + obtain ⟨K,hK,hQK⟩ := critical_rootTriangle_subpower G hloc hconn hqt hh root weight (vertexAut G) + (Set.Subset.refl _) htr hcov hw hw1 hpcrit hpcrit₁ hfin η hη + refine ⟨K,hK,fun n => ?_⟩ + simpa only [p,criticalApproach_gap] using hQK (p n) (hpnear n) (hp n) + obtain ⟨cm,hcm,hm⟩ := critical_norm_inverse_lower G hloc hqt hpcrit₁ hu + have hmlower (n : ℕ) : (cm/((pc G:ℝ)/2))*Real.exp (n:ℝ) ≤ m n := by + have hh := hm (p n) (hpzero n) (hp n) (A n) (hA n) + rw [show (pc G:ℝ)-(p n:ℝ) = (pc G:ℝ)/2*Real.exp (-(n:ℝ)) from criticalApproach_gap (pc G) n, + Real.exp_neg,div_mul_eq_div_div,div_inv_eq_mul] at hh + exact hh + have hρpos : 0 < ‖P‖ := by + let x : V := Classical.arbitrary V + have hh := (hdiag x).trans ((Complex.re_le_norm _).trans (matrixCoeff_norm_le P x x)) + linarith only [hh] + obtain ⟨n,k,B,hk,hB,hsmall,htime,herror,hlarge⟩ := exists_corridor_scales + ‖P‖ ((pc G:ℝ)/2) C C₁ ε M (cm/((pc G:ℝ)/2)) J k₀ hρpos hρ (half_pos hpcrit) hC hC₁ hε + (div_pos hcm (half_pos hpcrit)) hJ m R Q hR hQ hmlower hlogR hlogQ + exact hbad (p n) (hpnear n) (hp n) (A n) (hA n) k hk B hB hsmall htime herror hlarge + +end AnalyticCritical + + + +theorem nonempty_bonds_of_connected [Infinite V] (G : BondGraph V E) (hconn : Connected G) : Nonempty E := by + classical + by_contra he + let : IsEmpty E := not_nonempty_iff.mp he + obtain ⟨x,y,hxy⟩ := exists_pair_ne V + have hh := conn_univ_of_connected G hconn x y + have heq : (Set.univ : Set E) = ∅ := Set.eq_empty_of_isEmpty _ + rw [heq,conn_empty_iff] at hh + exact hxy hh + + + +theorem critical_bounded_of_transport_finiteness [Infinite V] + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) : + OperatorBounded G (pc G) := by + classical + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + let : Nonempty E := nonempty_bonds_of_connected G hconn + let : Nonempty ι := ⟨(hcov (Classical.arbitrary V)).choose⟩ + let c := ∑ i, (weight i)⁻¹ + have hc : 0 < c := Finset.sum_pos (fun i _ => inv_pos.mpr (hw i)) Finset.univ_nonempty + have hmin (i) : 1 ≤ c*weight i := by + have hi : (weight i)⁻¹ ≤ c := Finset.single_le_sum + (fun j _ => (inv_pos.mpr (hw j)).le) (Finset.mem_univ i) + simpa only [inv_mul_cancel₀ (hw i).ne'] using mul_le_mul_of_nonneg_right hi (hw i).le + obtain ⟨d,P,hdpos,hd,hρ,hPs,hP⟩ := exists_strict_walk_operator G hloc hqt hh + let a := (1:ℝ)/(2*d) + have hdr : (0:ℝ) < d := Nat.cast_pos.mpr hdpos + have ha : 0 < a := by dsimp [a]; positivity + have had : a*d = 1/2 := by dsimp [a]; field_simp + have hPe : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ) := hP + have hPpos : PositiveRealMatrix P := by + intro x y + rw [hPe] + refine ⟨rfl,?_⟩ + exact walkKernel_nonneg G hloc d hd a ha.le (by rw [had]; norm_num) x y + have hdiag (x) : 1/2 ≤ (matrixCoeff P x x).re := by + rw [hPe,Complex.ofReal_re] + exact walkKernel_lazy G hloc d hd a ha.le had.le x + exact critical_bounded_of_fixed_data G hG hconn hloc hqt hh a ha root weight htr hcov hw hw1 c hc hmin + P hPpos hPs.isSelfAdjoint hPe hdiag hρ d hd (pc_pos G hloc hqt) + (pc_lt_one_of_nonamenable G hconn hloc hqt hh) hfin + +end Percolation + + + + + +namespace Percolation +open MeasureTheory +universe u v +variable {V : Type u} {E : Type v} + + + +noncomputable def AutUnimodular [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : Prop := + letI : TopologicalSpace V := ⊥ + letI : DiscreteTopology V := ⟨rfl⟩ + (graphHaar G hG hconn hloc).IsMulRightInvariant + + + +theorem critical_bounded_of_unimodular_finiteness [Infinite V] + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) + (hfin : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite) : + OperatorBounded G (pc G) := by + classical + let : TopologicalSpace V := ⊥ + let : DiscreteTopology V := ⟨rfl⟩ + let : Countable V := countable_vertices hloc hconn + let : MeasurableSpace V := borel V + let : BorelSpace V := ⟨rfl⟩ + obtain ⟨ι,hι,hn,root,weight,htr,hcov,hw,hw1⟩ := + exists_rootData_of_unimodular G hG hconn hloc hqt huni + let : Fintype ι := hι + exact critical_bounded_of_transport_finiteness G hG hconn hloc hqt hh + root weight htr hcov hw hw1 (fun i => hfin (root i)) + + + +theorem critical_finite_of_unimodular [Infinite V] + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : + ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by + classical + let : TopologicalSpace V := ⊥ + let : DiscreteTopology V := ⟨rfl⟩ + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + let : MeasurableSpace V := borel V + let : BorelSpace V := ⟨rfl⟩ + obtain ⟨ι,hι,hn,root,weight,htr,hcov,hw,hw1⟩ := + exists_rootData_of_unimodular G hG hconn hloc hqt huni + let : Fintype ι := hι + exact critical_finite_of_transport G hconn hloc hqt hh root weight + (vertexAut G) (Set.Subset.refl _) htr hcov hw hw1 + + + +theorem critical_bounded_of_unimodular [Infinite V] + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : + OperatorBounded G (pc G) := by + exact critical_bounded_of_unimodular_finiteness G hG hconn hloc hqt hh huni + (critical_finite_of_unimodular G hG hconn hloc hqt hh huni) + +end Percolation + + + +namespace Percolation +open MeasureTheory +universe u v +variable {V : Type u} {E : Type v} + + + +theorem critical_operator [Infinite V] + (G : BondGraph V E) (hG : Function.Injective G) + (_hloop : ∀ e x, G e ≠ s(x,x)) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (huni : AutUnimodular G hG hconn hloc) : + operatorNorm G (pc G) < ⊤ + := by + exact (operatorNorm_lt_top_iff G (pc G)).mpr + (critical_bounded_of_unimodular G hG hconn hloc hqt hh huni) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Phase.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Phase.lean index cb7db30acdec530b0157e5ae3a2809dad1c87104..00e146c6696c296463df9a98929c036b43ea5fad 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Phase.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Phase.lean @@ -1,111 +1,111 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Criticality.ClusterCount - -namespace OAI - -/-! Strict operator-threshold gaps and infinite-cluster phase classification. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem strict_gap_of_critical_bounded [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hp1 : pc G < 1) (hb : OperatorBounded G (pc G)) : pc G < ptwo G := by - obtain ⟨D, hDpos, hD⟩ := exists_degree_bound G hqt - obtain ⟨A, hA⟩ := hb - let c : ℝ := (4 * D) * ‖A‖ - have hc : 0 ≤ c := by dsimp [c]; positivity - let ε : ℝ := (1 - (pc G : ℝ)) / (2 * (c + 1)) - have hε : 0 < ε := div_pos (sub_pos.mpr hp1) (by positivity) - have heq : ε * (2 * (c + 1)) = 1 - (pc G : ℝ) := - div_mul_cancel₀ _ (ne_of_gt (by positivity : (0 : ℝ) < 2 * (c + 1))) - have hr1 : (pc G : ℝ) + ε < 1 := by nlinarith - let r : unitInterval := ⟨(pc G : ℝ) + ε, add_nonneg (pc G).2.1 hε.le, hr1.le⟩ - have hpr : pc G < r := by change (pc G : ℝ) < (pc G : ℝ) + ε; linarith - have hrb : OperatorBounded G r := by - apply operatorBounded_of_quantitative_gap G hloc D hD (pc G) r - (pc_pos G hloc hqt) hpr hr1 A hA - change (((pc G : ℝ) + ε) - (pc G : ℝ)) * (4 * D) * ‖A‖ < 1 - ((pc G : ℝ) + ε) - have he : (((pc G : ℝ) + ε) - (pc G : ℝ)) * (4 * D) * ‖A‖ = ε * c := by - dsimp [c] - ring - rw [he] - nlinarith - exact hpr.trans_le (le_sSup hrb) - -theorem unique_probability_zero_of_lt_pu [Infinite V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pu G) : - law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 0 := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - refine (law_invariant_zero_one G hconn hloc hqt p _ - (measurableSet_unique_infinite_cluster G) ?_).resolve_right ?_ - · intro a b hab - ext ω - exact unique_infinite_cluster_aut_iff G hab ω - · intro he - exact (not_le_of_gt hp) (sInf_le he) - -theorem finite_count_empty_ae_of_lt_pu [Infinite V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp0 : 0 < p) (hp : p < pu G) : - ∀ᵐ ω ∂law p, (infiniteClusters G ω).Finite → infiniteClusters G ω = ∅ := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - have hp1 : p < 1 := hp.trans_le (pu G).2.2 - have ha (x : V) (R : Finset V) : - ∀ᵐ ω ∂law p, ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by - have hz : law p {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} = 0 := by - by_contra h - have ht := unique_pos_of_cover_pos G hconn p hp0 hp1 x R (pos_iff_ne_zero.mpr h) - rw [unique_probability_zero_of_lt_pu G hconn hloc hqt p hp] at ht - exact lt_irrefl _ ht - apply ae_iff.mpr - simpa only [not_not] using hz - have hall : ∀ᵐ ω ∂law p, ∀ x : V, ∀ R : Finset V, - ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := - ae_all_iff.mpr fun x => ae_all_iff.mpr (ha x) - filter_upwards [hall] with ω hω - intro hfin - by_contra hn - obtain ⟨C, hC⟩ := Set.nonempty_iff_ne_empty.mpr hn - obtain ⟨hx, x, rfl⟩ := hC - let f : Set V → V := fun C => if hc : C ∈ infiniteClusters G ω then - Classical.choose hc.2 else x - have hf (C : Set V) (hC : C ∈ infiniteClusters G ω) : C = cluster G ω (f C) := by - simp only [f, dite_eq_left hC] - exact Classical.choose_spec hC.2 - let R : Finset V := hfin.toFinset.image f - apply hω x R ⟨hx, ?_⟩ - intro y hy - have hc : cluster G ω y ∈ infiniteClusters G ω := ⟨hy, y, rfl⟩ - refine ⟨f (cluster G ω y), Finset.mem_image.mpr ⟨_, hfin.mem_toFinset.mpr hc, rfl⟩, ?_⟩ - have he := hf _ hc - exact (Set.ext_iff.mp he _).mpr (mem_cluster_self G ω (f (cluster G ω y))) - -theorem infinitely_many_of_pc_lt_lt_pu [Infinite V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hc : pc G < p) (hu : p < pu G) : - ∀ᵐ ω ∂law p, (infiniteClusters G ω).Infinite := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - have he : ∀ᵐ ω ∂law p, (infiniteClusters G ω).Nonempty := by - rw [← map_openEdges p] - apply (ae_map_iff (measurable_openEdges p).aemeasurable ?_).mpr - · simpa only [infiniteClusters_nonempty_iff] using ae_exists_infinite_cluster_of_pc_lt G p hc - · simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G - filter_upwards [he, finite_count_empty_ae_of_lt_pu G hconn hloc hqt p - ((pc_pos G hloc hqt).trans hc) hu] with ω hne hf - intro hfin - exact hne.ne_empty (hf hfin) -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Criticality.ClusterCount + +namespace OAI + +/-! Strict operator-threshold gaps and infinite-cluster phase classification. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem strict_gap_of_critical_bounded [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hp1 : pc G < 1) (hb : OperatorBounded G (pc G)) : pc G < ptwo G := by + obtain ⟨D, hDpos, hD⟩ := exists_degree_bound G hqt + obtain ⟨A, hA⟩ := hb + let c : ℝ := (4 * D) * ‖A‖ + have hc : 0 ≤ c := by dsimp [c]; positivity + let ε : ℝ := (1 - (pc G : ℝ)) / (2 * (c + 1)) + have hε : 0 < ε := div_pos (sub_pos.mpr hp1) (by positivity) + have heq : ε * (2 * (c + 1)) = 1 - (pc G : ℝ) := + div_mul_cancel₀ _ (ne_of_gt (by positivity : (0 : ℝ) < 2 * (c + 1))) + have hr1 : (pc G : ℝ) + ε < 1 := by nlinarith + let r : unitInterval := ⟨(pc G : ℝ) + ε, add_nonneg (pc G).2.1 hε.le, hr1.le⟩ + have hpr : pc G < r := by change (pc G : ℝ) < (pc G : ℝ) + ε; linarith + have hrb : OperatorBounded G r := by + apply operatorBounded_of_quantitative_gap G hloc D hD (pc G) r + (pc_pos G hloc hqt) hpr hr1 A hA + change (((pc G : ℝ) + ε) - (pc G : ℝ)) * (4 * D) * ‖A‖ < 1 - ((pc G : ℝ) + ε) + have he : (((pc G : ℝ) + ε) - (pc G : ℝ)) * (4 * D) * ‖A‖ = ε * c := by + dsimp [c] + ring + rw [he] + nlinarith + exact hpr.trans_le (le_sSup hrb) + +theorem unique_probability_zero_of_lt_pu [Infinite V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pu G) : + law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 0 := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + refine (law_invariant_zero_one G hconn hloc hqt p _ + (measurableSet_unique_infinite_cluster G) ?_).resolve_right ?_ + · intro a b hab + ext ω + exact unique_infinite_cluster_aut_iff G hab ω + · intro he + exact (not_le_of_gt hp) (sInf_le he) + +theorem finite_count_empty_ae_of_lt_pu [Infinite V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp0 : 0 < p) (hp : p < pu G) : + ∀ᵐ ω ∂law p, (infiniteClusters G ω).Finite → infiniteClusters G ω = ∅ := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + have hp1 : p < 1 := hp.trans_le (pu G).2.2 + have ha (x : V) (R : Finset V) : + ∀ᵐ ω ∂law p, ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := by + have hz : law p {ω | (cluster G ω x).Infinite ∧ InfiniteCover G R ω} = 0 := by + by_contra h + have ht := unique_pos_of_cover_pos G hconn p hp0 hp1 x R (pos_iff_ne_zero.mpr h) + rw [unique_probability_zero_of_lt_pu G hconn hloc hqt p hp] at ht + exact lt_irrefl _ ht + apply ae_iff.mpr + simpa only [not_not] using hz + have hall : ∀ᵐ ω ∂law p, ∀ x : V, ∀ R : Finset V, + ¬((cluster G ω x).Infinite ∧ InfiniteCover G R ω) := + ae_all_iff.mpr fun x => ae_all_iff.mpr (ha x) + filter_upwards [hall] with ω hω + intro hfin + by_contra hn + obtain ⟨C, hC⟩ := Set.nonempty_iff_ne_empty.mpr hn + obtain ⟨hx, x, rfl⟩ := hC + let f : Set V → V := fun C => if hc : C ∈ infiniteClusters G ω then + Classical.choose hc.2 else x + have hf (C : Set V) (hC : C ∈ infiniteClusters G ω) : C = cluster G ω (f C) := by + simp only [f, dite_eq_left hC] + exact Classical.choose_spec hC.2 + let R : Finset V := hfin.toFinset.image f + apply hω x R ⟨hx, ?_⟩ + intro y hy + have hc : cluster G ω y ∈ infiniteClusters G ω := ⟨hy, y, rfl⟩ + refine ⟨f (cluster G ω y), Finset.mem_image.mpr ⟨_, hfin.mem_toFinset.mpr hc, rfl⟩, ?_⟩ + have he := hf _ hc + exact (Set.ext_iff.mp he _).mpr (mem_cluster_self G ω (f (cluster G ω y))) + +theorem infinitely_many_of_pc_lt_lt_pu [Infinite V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hc : pc G < p) (hu : p < pu G) : + ∀ᵐ ω ∂law p, (infiniteClusters G ω).Infinite := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + have he : ∀ᵐ ω ∂law p, (infiniteClusters G ω).Nonempty := by + rw [← map_openEdges p] + apply (ae_map_iff (measurable_openEdges p).aemeasurable ?_).mpr + · simpa only [infiniteClusters_nonempty_iff] using ae_exists_infinite_cluster_of_pc_lt G p hc + · simpa only [infiniteClusters_nonempty_iff] using measurableSet_exists_infinite_cluster G + filter_upwards [he, finite_count_empty_ae_of_lt_pu G hconn hloc hqt p + ((pc_pos G hloc hqt).trans hc) hu] with ω hne hf + intro hfin + exact hne.ne_empty (hf hfin) +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/ScaleLimits.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/ScaleLimits.lean index 73f24142dd104fd87e3b93085ec4b20c21daa53d..bd5f5cce549a35dbf1f18202b581fbe0d02c8939 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/ScaleLimits.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/ScaleLimits.lean @@ -1,206 +1,206 @@ -import Mathlib - -namespace OAI - -/-! Analytic scale limits and quantitative parameter estimates. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open Filter -open scoped Topology - - - -theorem log_sublinear_of_subexp (f : ℕ → ℝ) (hf : ∀ n, 1 ≤ f n) - (hb : ∀ η : ℝ, 0 < η → ∃ K : ℝ, 0 < K ∧ ∀ n, f n ≤ K*Real.exp (η*(n:ℝ))) : - Tendsto (fun n => Real.log (f n)/(n:ℝ)) atTop (𝓝 0) := by - apply Metric.tendsto_nhds.mpr - intro ε hε - obtain ⟨K,hK,hbK⟩ := hb (ε/2) (half_pos hε) - have hlim := tendsto_const_div_atTop_nhds_zero_nat (Real.log K) - filter_upwards [hlim.eventually (gt_mem_nhds (half_pos hε)), eventually_ge_atTop (1:ℕ)] with n hn hn1 - have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) - have hlog := Real.log_le_log (zero_lt_one.trans_le (hf n)) (hbK n) - rw [Real.log_mul hK.ne' (Real.exp_pos _).ne',Real.log_exp] at hlog - have hdiv := (div_le_div_of_nonneg_right hlog hnpos.le) - rw [add_div,mul_div_cancel_right₀ _ hnpos.ne'] at hdiv - rw [Real.dist_eq,sub_zero,abs_of_nonneg (div_nonneg (Real.log_nonneg (hf n)) hnpos.le)] - linarith only [hdiv,hn] - - -theorem tendsto_atTop_of_div_nat_pos (f : ℕ → ℝ) (L : ℝ) (hL : 0 < L) - (hf : Tendsto (fun n => f n/(n:ℝ)) atTop (𝓝 L)) : Tendsto f atTop atTop := by - have ht := (tendsto_natCast_atTop_atTop (R := ℝ)).atTop_mul_pos hL hf - apply ht.congr' - filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn - exact mul_div_cancel₀ (f n) (by exact_mod_cast (show n ≠ 0 by omega)) - - -theorem tendsto_exp_of_div_nat_neg (f : ℕ → ℝ) (L : ℝ) (hL : L < 0) - (hf : Tendsto (fun n => f n/(n:ℝ)) atTop (𝓝 L)) : - Tendsto (fun n => Real.exp (f n)) atTop (𝓝 0) := by - have hn : Tendsto (fun n => -f n/(n:ℝ)) atTop (𝓝 (-L)) := by - simpa only [neg_div] using hf.neg - have ht := tendsto_atTop_of_div_nat_pos (fun n => -f n) (-L) (neg_pos.mpr hL) hn - simpa only [Function.comp_def,neg_neg] using Real.tendsto_exp_neg_atTop_nhds_zero.comp ht - - - -theorem corridor_scale_limits (r C₁ : ℝ) (J : ℕ) (hr : 0 < r) (hC₁ : 0 < C₁) (hJ : 0 < J) - (R : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) - (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) : - let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ - let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ - Tendsto k atTop atTop ∧ - Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) ∧ - Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) ∧ - Tendsto (fun n => Real.log (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) := by - dsimp only - let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ - let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ - have hkt : Tendsto k atTop atTop := - tendsto_nat_ceil_atTop.comp ((tendsto_natCast_atTop_atTop (R := ℝ)).const_mul_atTop hr) - have hk : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) := - (tendsto_nat_ceil_mul_div_atTop hr.le).comp tendsto_natCast_atTop_atTop - have hkplus : Tendsto (fun n => ((k n:ℝ)+1)/(n:ℝ)) atTop (𝓝 r) := by - simpa only [add_div,add_zero] using hk.add (tendsto_const_div_atTop_nhds_zero_nat (1:ℝ)) - have hkTop : Tendsto (fun n => (k n:ℝ)+1) atTop atTop := - tendsto_atTop_mono (fun n => le_add_of_nonneg_right (show (0:ℝ) ≤ 1 by norm_num)) - (tendsto_natCast_atTop_atTop.comp hkt) - have hlogk : Tendsto (fun n => Real.log ((k n:ℝ)+1)/(n:ℝ)) atTop (𝓝 0) := by - have hl : Tendsto (fun n => Real.log ((k n:ℝ)+1)/((k n:ℝ)+1)) atTop (𝓝 0) := by - simpa only [Function.comp_def,pow_one,one_mul,add_zero] using - (Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 (by norm_num)).comp hkTop - have hh := hl.mul hkplus - rw [zero_mul] at hh - apply hh.congr - intro n - have hn : (k n:ℝ)+1 ≠ 0 := by positivity - field_simp - have hupper : Tendsto (fun n : ℕ => ((J:ℝ)+1)/(n:ℝ) + C₁*(Real.log ((k n:ℝ)+1)/(n:ℝ) + Real.log (R n)/(n:ℝ))) atTop (𝓝 0) := by - simpa only [add_zero,mul_zero] using - (tendsto_const_div_atTop_nhds_zero_nat ((J:ℝ)+1)).add ((hlogk.add hlogR).const_mul C₁) - have hjlim : Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) := by - apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper - · exact Eventually.of_forall (fun n => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) - filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn - have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) - have hprod : 1 ≤ ((k n:ℝ)+1)*R n := by nlinarith only [hR n,(Nat.cast_nonneg (k n) : (0:ℝ) ≤ _)] - have harg : 0 ≤ C₁*Real.log (((k n:ℝ)+1)*R n) := mul_nonneg hC₁.le (Real.log_nonneg hprod) - have hceil := (Nat.ceil_lt_add_one harg).le - have he : Real.log (((k n:ℝ)+1)*R n) = Real.log ((k n:ℝ)+1)+Real.log (R n) := - Real.log_mul (by positivity) (zero_lt_one.trans_le (hR n)).ne' - dsimp only [j] - push_cast - rw [←add_div,←mul_div_assoc,←add_div,←he] - exact (div_le_div_of_nonneg_right (by linarith only [hceil]) hnpos.le) - refine ⟨hkt,hk,hjlim,?_⟩ - apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hjlim - · exact Eventually.of_forall (fun n => div_nonneg (Real.log_nonneg (Nat.one_le_cast.mpr (show 1 ≤ j n by dsimp [j]; omega))) (Nat.cast_nonneg n)) - · exact Eventually.of_forall (fun n => div_le_div_of_nonneg_right (Real.log_le_self (Nat.cast_nonneg (j n))) (Nat.cast_nonneg n)) - - - -theorem exists_corridor_scales_of_slopes - (ρ p₀ C C₁ ε M cm r z : ℝ) (J k₀ : ℕ) - (hρ : 0 < ρ) (hp₀ : 0 < p₀) (hC₁ : 0 < C₁) (hε : 0 < ε) (hcm : 0 < cm) - (hJ : 0 < J) (hr : 0 < r) (hz : 0 < z) - (hzρ : z+r*Real.log ρ < 0) (hzC : z+C*r < 1) - (m R Q : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) (hQ : ∀ n, 1 ≤ Q n) - (hm : ∀ n : ℕ, cm*Real.exp (n:ℝ) ≤ m n) - (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) - (hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0)) : - ∃ (n k : ℕ) (B : ℝ), k₀ ≤ k ∧ 0 < B ∧ - let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R n)⌉₊ - B*ρ^k ≤ 1/4 ∧ B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m n ∧ - (R n)^2*Q n*ρ^k ≤ ε*p₀^(2*j) ∧ M < B*p₀^(2*j) := by - let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ - let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ - let B := fun n : ℕ => Real.exp (z*(n:ℝ)) - obtain ⟨hkt,hk,hj,hlogj⟩ := corridor_scale_limits r C₁ J hr hC₁ hJ R hR hlogR - change Tendsto k atTop atTop at hkt - change Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) at hk - change Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) at hj - change Tendsto (fun n => Real.log (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) at hlogj - have hn : Tendsto (fun n : ℕ => (n:ℝ)/(n:ℝ)) atTop (𝓝 1) := by - simpa only [add_zero] using tendsto_natCast_div_add_atTop (0:ℝ) - have hβ (n) : Real.exp ((j n:ℝ)*(2*Real.log p₀)) = p₀^(2*j n) := by - rw [show (j n:ℝ)*(2*Real.log p₀) = ((2*j n:ℕ):ℝ)*Real.log p₀ by push_cast; ring, - Real.exp_nat_mul,Real.exp_log hp₀] - have hjpos (n) : (0:ℝ) < j n := Nat.cast_pos.mpr (by dsimp [j]; omega) - have hlim₁ : Tendsto (fun n : ℕ => (z*(n:ℝ)+(k n:ℝ)*Real.log ρ)/(n:ℝ)) atTop (𝓝 (z+r*Real.log ρ)) := by - simpa only [mul_one,div_mul_eq_mul_div,←mul_div_assoc,←add_div] using - (hn.const_mul z).add (hk.mul_const (Real.log ρ)) - have hdec₁ := tendsto_exp_of_div_nat_neg _ _ hzρ hlim₁ - have hlim₂ : Tendsto (fun n : ℕ => - (2*Real.log (R n)+Real.log (Q n)+(k n:ℝ)*Real.log ρ-(j n:ℝ)*(2*Real.log p₀))/(n:ℝ)) - atTop (𝓝 (r*Real.log ρ)) := by - simpa only [mul_zero,zero_add,zero_mul,sub_zero,div_mul_eq_mul_div,←mul_div_assoc,←add_div,←sub_div] using - (((hlogR.const_mul 2).add hlogQ).add (hk.mul_const (Real.log ρ))).sub (hj.mul_const (2*Real.log p₀)) - have hsl₂ : r*Real.log ρ < 0 := by linarith only [hz,hzρ] - have hdec₂ := tendsto_exp_of_div_nat_neg _ _ hsl₂ hlim₂ - have hlim₃ : Tendsto (fun n : ℕ => - (z*(n:ℝ)+Real.log (j n:ℝ)+C*(k n:ℝ)-(n:ℝ))/(n:ℝ)) atTop (𝓝 (z+C*r-1)) := by - simpa only [mul_one,add_zero,←mul_div_assoc,←add_div,←sub_div] using - (((hn.const_mul z).add hlogj).add (hk.const_mul C)).sub hn - have hdec₃ := tendsto_exp_of_div_nat_neg _ _ (sub_neg.mpr hzC) hlim₃ - have hlim₄ : Tendsto (fun n : ℕ => - (z*(n:ℝ)+(j n:ℝ)*(2*Real.log p₀))/(n:ℝ)) atTop (𝓝 z) := by - simpa only [mul_one,zero_mul,add_zero,div_mul_eq_mul_div,←mul_div_assoc,←add_div] using - (hn.const_mul z).add (hj.mul_const (2*Real.log p₀)) - have hgrow := Real.tendsto_exp_atTop.comp (tendsto_atTop_of_div_nat_pos _ _ hz hlim₄) - have hfinal : ∀ᶠ n : ℕ in atTop, - k₀ ≤ k n ∧ B n*ρ^(k n) ≤ 1/4 ∧ - B n*(j n:ℝ)*Real.exp (C*(k n:ℝ)) ≤ m n ∧ - (R n)^2*Q n*ρ^(k n) ≤ ε*p₀^(2*j n) ∧ M < B n*p₀^(2*j n) := by - filter_upwards [hkt.eventually_ge_atTop k₀, - hdec₁.eventually_lt_const (show (0:ℝ) < 1/4 by norm_num), - hdec₂.eventually_lt_const hε,hdec₃.eventually_lt_const hcm, - hgrow.eventually_gt_atTop M] with n hk₀ h₁ h₂ h₃ h₄ - have heρ : Real.exp ((k n:ℝ)*Real.log ρ) = ρ^(k n) := by rw [Real.exp_nat_mul,Real.exp_log hρ] - have heR : Real.exp (2*Real.log (R n)) = (R n)^2 := by - simpa only [Nat.cast_ofNat,Real.exp_log (zero_lt_one.trans_le (hR n))] using Real.exp_nat_mul (Real.log (R n)) 2 - simp only [Real.exp_add,heρ] at h₁ - simp only [Real.exp_sub,Real.exp_add,heR,Real.exp_log (zero_lt_one.trans_le (hQ n)),heρ,hβ n] at h₂ - simp only [Real.exp_sub,Real.exp_add,Real.exp_log (hjpos n)] at h₃ - change M < Real.exp (z*(n:ℝ)+(j n:ℝ)*(2*Real.log p₀)) at h₄ - rw [Real.exp_add,hβ n] at h₄ - refine ⟨hk₀,h₁.le,?_,(div_le_iff₀ (pow_pos hp₀ _)).mp h₂.le,h₄⟩ - exact ((div_le_iff₀ (Real.exp_pos _)).mp h₃.le).trans (hm n) - obtain ⟨n,hn⟩ := hfinal.exists - exact ⟨n,k n,B n,hn.1,Real.exp_pos _,hn.2⟩ - - - -theorem exists_corridor_scales - (ρ p₀ C C₁ ε M cm : ℝ) (J k₀ : ℕ) - (hρ : 0 < ρ) (hρ₁ : ρ < 1) (hp₀ : 0 < p₀) (hC : 0 < C) - (hC₁ : 0 < C₁) (hε : 0 < ε) (hcm : 0 < cm) (hJ : 0 < J) - (m R Q : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) (hQ : ∀ n, 1 ≤ Q n) - (hm : ∀ n : ℕ, cm*Real.exp (n:ℝ) ≤ m n) - (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) - (hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0)) : - ∃ (n k : ℕ) (B : ℝ), k₀ ≤ k ∧ 0 < B ∧ - let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R n)⌉₊ - B*ρ^k ≤ 1/4 ∧ B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m n ∧ - (R n)^2*Q n*ρ^k ≤ ε*p₀^(2*j) ∧ M < B*p₀^(2*j) := by - let r := 1/(4*(C+1)) - let z := min (1/4) (-(r*Real.log ρ)/2) - have hr : 0 < r := by dsimp [r]; positivity - have hlog : Real.log ρ < 0 := by simpa only [Real.log_one] using Real.log_lt_log hρ hρ₁ - have hz : 0 < z := lt_min (by norm_num) (half_pos (neg_pos.mpr (mul_neg_of_pos_of_neg hr hlog))) - have hzr : z+r*Real.log ρ < 0 := by - have hh : z ≤ -(r*Real.log ρ)/2 := min_le_right _ _ - linarith only [hh,mul_neg_of_pos_of_neg hr hlog] - have hzc : z+C*r < 1 := by - have hz' : z ≤ 1/4 := min_le_left _ _ - have hr' : r*(4*(C+1)) = 1 := div_mul_cancel₀ 1 (by positivity) - nlinarith only [hz',hr',hr] - exact exists_corridor_scales_of_slopes ρ p₀ C C₁ ε M cm r z J k₀ - hρ hp₀ hC₁ hε hcm hJ hr hz hzr hzc m R Q hR hQ hm hlogR hlogQ - -end Percolation - -end OAI +import Mathlib + +namespace OAI + +/-! Analytic scale limits and quantitative parameter estimates. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open Filter +open scoped Topology + + + +theorem log_sublinear_of_subexp (f : ℕ → ℝ) (hf : ∀ n, 1 ≤ f n) + (hb : ∀ η : ℝ, 0 < η → ∃ K : ℝ, 0 < K ∧ ∀ n, f n ≤ K*Real.exp (η*(n:ℝ))) : + Tendsto (fun n => Real.log (f n)/(n:ℝ)) atTop (𝓝 0) := by + apply Metric.tendsto_nhds.mpr + intro ε hε + obtain ⟨K,hK,hbK⟩ := hb (ε/2) (half_pos hε) + have hlim := tendsto_const_div_atTop_nhds_zero_nat (Real.log K) + filter_upwards [hlim.eventually (gt_mem_nhds (half_pos hε)), eventually_ge_atTop (1:ℕ)] with n hn hn1 + have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) + have hlog := Real.log_le_log (zero_lt_one.trans_le (hf n)) (hbK n) + rw [Real.log_mul hK.ne' (Real.exp_pos _).ne',Real.log_exp] at hlog + have hdiv := (div_le_div_of_nonneg_right hlog hnpos.le) + rw [add_div,mul_div_cancel_right₀ _ hnpos.ne'] at hdiv + rw [Real.dist_eq,sub_zero,abs_of_nonneg (div_nonneg (Real.log_nonneg (hf n)) hnpos.le)] + linarith only [hdiv,hn] + + +theorem tendsto_atTop_of_div_nat_pos (f : ℕ → ℝ) (L : ℝ) (hL : 0 < L) + (hf : Tendsto (fun n => f n/(n:ℝ)) atTop (𝓝 L)) : Tendsto f atTop atTop := by + have ht := (tendsto_natCast_atTop_atTop (R := ℝ)).atTop_mul_pos hL hf + apply ht.congr' + filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn + exact mul_div_cancel₀ (f n) (by exact_mod_cast (show n ≠ 0 by omega)) + + +theorem tendsto_exp_of_div_nat_neg (f : ℕ → ℝ) (L : ℝ) (hL : L < 0) + (hf : Tendsto (fun n => f n/(n:ℝ)) atTop (𝓝 L)) : + Tendsto (fun n => Real.exp (f n)) atTop (𝓝 0) := by + have hn : Tendsto (fun n => -f n/(n:ℝ)) atTop (𝓝 (-L)) := by + simpa only [neg_div] using hf.neg + have ht := tendsto_atTop_of_div_nat_pos (fun n => -f n) (-L) (neg_pos.mpr hL) hn + simpa only [Function.comp_def,neg_neg] using Real.tendsto_exp_neg_atTop_nhds_zero.comp ht + + + +theorem corridor_scale_limits (r C₁ : ℝ) (J : ℕ) (hr : 0 < r) (hC₁ : 0 < C₁) (hJ : 0 < J) + (R : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) + (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) : + let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ + let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ + Tendsto k atTop atTop ∧ + Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) ∧ + Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) ∧ + Tendsto (fun n => Real.log (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) := by + dsimp only + let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ + let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ + have hkt : Tendsto k atTop atTop := + tendsto_nat_ceil_atTop.comp ((tendsto_natCast_atTop_atTop (R := ℝ)).const_mul_atTop hr) + have hk : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) := + (tendsto_nat_ceil_mul_div_atTop hr.le).comp tendsto_natCast_atTop_atTop + have hkplus : Tendsto (fun n => ((k n:ℝ)+1)/(n:ℝ)) atTop (𝓝 r) := by + simpa only [add_div,add_zero] using hk.add (tendsto_const_div_atTop_nhds_zero_nat (1:ℝ)) + have hkTop : Tendsto (fun n => (k n:ℝ)+1) atTop atTop := + tendsto_atTop_mono (fun n => le_add_of_nonneg_right (show (0:ℝ) ≤ 1 by norm_num)) + (tendsto_natCast_atTop_atTop.comp hkt) + have hlogk : Tendsto (fun n => Real.log ((k n:ℝ)+1)/(n:ℝ)) atTop (𝓝 0) := by + have hl : Tendsto (fun n => Real.log ((k n:ℝ)+1)/((k n:ℝ)+1)) atTop (𝓝 0) := by + simpa only [Function.comp_def,pow_one,one_mul,add_zero] using + (Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 (by norm_num)).comp hkTop + have hh := hl.mul hkplus + rw [zero_mul] at hh + apply hh.congr + intro n + have hn : (k n:ℝ)+1 ≠ 0 := by positivity + field_simp + have hupper : Tendsto (fun n : ℕ => ((J:ℝ)+1)/(n:ℝ) + C₁*(Real.log ((k n:ℝ)+1)/(n:ℝ) + Real.log (R n)/(n:ℝ))) atTop (𝓝 0) := by + simpa only [add_zero,mul_zero] using + (tendsto_const_div_atTop_nhds_zero_nat ((J:ℝ)+1)).add ((hlogk.add hlogR).const_mul C₁) + have hjlim : Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper + · exact Eventually.of_forall (fun n => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) + filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn + have hnpos : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) + have hprod : 1 ≤ ((k n:ℝ)+1)*R n := by nlinarith only [hR n,(Nat.cast_nonneg (k n) : (0:ℝ) ≤ _)] + have harg : 0 ≤ C₁*Real.log (((k n:ℝ)+1)*R n) := mul_nonneg hC₁.le (Real.log_nonneg hprod) + have hceil := (Nat.ceil_lt_add_one harg).le + have he : Real.log (((k n:ℝ)+1)*R n) = Real.log ((k n:ℝ)+1)+Real.log (R n) := + Real.log_mul (by positivity) (zero_lt_one.trans_le (hR n)).ne' + dsimp only [j] + push_cast + rw [←add_div,←mul_div_assoc,←add_div,←he] + exact (div_le_div_of_nonneg_right (by linarith only [hceil]) hnpos.le) + refine ⟨hkt,hk,hjlim,?_⟩ + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hjlim + · exact Eventually.of_forall (fun n => div_nonneg (Real.log_nonneg (Nat.one_le_cast.mpr (show 1 ≤ j n by dsimp [j]; omega))) (Nat.cast_nonneg n)) + · exact Eventually.of_forall (fun n => div_le_div_of_nonneg_right (Real.log_le_self (Nat.cast_nonneg (j n))) (Nat.cast_nonneg n)) + + + +theorem exists_corridor_scales_of_slopes + (ρ p₀ C C₁ ε M cm r z : ℝ) (J k₀ : ℕ) + (hρ : 0 < ρ) (hp₀ : 0 < p₀) (hC₁ : 0 < C₁) (hε : 0 < ε) (hcm : 0 < cm) + (hJ : 0 < J) (hr : 0 < r) (hz : 0 < z) + (hzρ : z+r*Real.log ρ < 0) (hzC : z+C*r < 1) + (m R Q : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) (hQ : ∀ n, 1 ≤ Q n) + (hm : ∀ n : ℕ, cm*Real.exp (n:ℝ) ≤ m n) + (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) + (hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0)) : + ∃ (n k : ℕ) (B : ℝ), k₀ ≤ k ∧ 0 < B ∧ + let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R n)⌉₊ + B*ρ^k ≤ 1/4 ∧ B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m n ∧ + (R n)^2*Q n*ρ^k ≤ ε*p₀^(2*j) ∧ M < B*p₀^(2*j) := by + let k := fun n : ℕ => ⌈r*(n:ℝ)⌉₊ + let j := fun n : ℕ => J+⌈C₁*Real.log (((k n:ℝ)+1)*R n)⌉₊ + let B := fun n : ℕ => Real.exp (z*(n:ℝ)) + obtain ⟨hkt,hk,hj,hlogj⟩ := corridor_scale_limits r C₁ J hr hC₁ hJ R hR hlogR + change Tendsto k atTop atTop at hkt + change Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 r) at hk + change Tendsto (fun n => (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) at hj + change Tendsto (fun n => Real.log (j n:ℝ)/(n:ℝ)) atTop (𝓝 0) at hlogj + have hn : Tendsto (fun n : ℕ => (n:ℝ)/(n:ℝ)) atTop (𝓝 1) := by + simpa only [add_zero] using tendsto_natCast_div_add_atTop (0:ℝ) + have hβ (n) : Real.exp ((j n:ℝ)*(2*Real.log p₀)) = p₀^(2*j n) := by + rw [show (j n:ℝ)*(2*Real.log p₀) = ((2*j n:ℕ):ℝ)*Real.log p₀ by push_cast; ring, + Real.exp_nat_mul,Real.exp_log hp₀] + have hjpos (n) : (0:ℝ) < j n := Nat.cast_pos.mpr (by dsimp [j]; omega) + have hlim₁ : Tendsto (fun n : ℕ => (z*(n:ℝ)+(k n:ℝ)*Real.log ρ)/(n:ℝ)) atTop (𝓝 (z+r*Real.log ρ)) := by + simpa only [mul_one,div_mul_eq_mul_div,←mul_div_assoc,←add_div] using + (hn.const_mul z).add (hk.mul_const (Real.log ρ)) + have hdec₁ := tendsto_exp_of_div_nat_neg _ _ hzρ hlim₁ + have hlim₂ : Tendsto (fun n : ℕ => + (2*Real.log (R n)+Real.log (Q n)+(k n:ℝ)*Real.log ρ-(j n:ℝ)*(2*Real.log p₀))/(n:ℝ)) + atTop (𝓝 (r*Real.log ρ)) := by + simpa only [mul_zero,zero_add,zero_mul,sub_zero,div_mul_eq_mul_div,←mul_div_assoc,←add_div,←sub_div] using + (((hlogR.const_mul 2).add hlogQ).add (hk.mul_const (Real.log ρ))).sub (hj.mul_const (2*Real.log p₀)) + have hsl₂ : r*Real.log ρ < 0 := by linarith only [hz,hzρ] + have hdec₂ := tendsto_exp_of_div_nat_neg _ _ hsl₂ hlim₂ + have hlim₃ : Tendsto (fun n : ℕ => + (z*(n:ℝ)+Real.log (j n:ℝ)+C*(k n:ℝ)-(n:ℝ))/(n:ℝ)) atTop (𝓝 (z+C*r-1)) := by + simpa only [mul_one,add_zero,←mul_div_assoc,←add_div,←sub_div] using + (((hn.const_mul z).add hlogj).add (hk.const_mul C)).sub hn + have hdec₃ := tendsto_exp_of_div_nat_neg _ _ (sub_neg.mpr hzC) hlim₃ + have hlim₄ : Tendsto (fun n : ℕ => + (z*(n:ℝ)+(j n:ℝ)*(2*Real.log p₀))/(n:ℝ)) atTop (𝓝 z) := by + simpa only [mul_one,zero_mul,add_zero,div_mul_eq_mul_div,←mul_div_assoc,←add_div] using + (hn.const_mul z).add (hj.mul_const (2*Real.log p₀)) + have hgrow := Real.tendsto_exp_atTop.comp (tendsto_atTop_of_div_nat_pos _ _ hz hlim₄) + have hfinal : ∀ᶠ n : ℕ in atTop, + k₀ ≤ k n ∧ B n*ρ^(k n) ≤ 1/4 ∧ + B n*(j n:ℝ)*Real.exp (C*(k n:ℝ)) ≤ m n ∧ + (R n)^2*Q n*ρ^(k n) ≤ ε*p₀^(2*j n) ∧ M < B n*p₀^(2*j n) := by + filter_upwards [hkt.eventually_ge_atTop k₀, + hdec₁.eventually_lt_const (show (0:ℝ) < 1/4 by norm_num), + hdec₂.eventually_lt_const hε,hdec₃.eventually_lt_const hcm, + hgrow.eventually_gt_atTop M] with n hk₀ h₁ h₂ h₃ h₄ + have heρ : Real.exp ((k n:ℝ)*Real.log ρ) = ρ^(k n) := by rw [Real.exp_nat_mul,Real.exp_log hρ] + have heR : Real.exp (2*Real.log (R n)) = (R n)^2 := by + simpa only [Nat.cast_ofNat,Real.exp_log (zero_lt_one.trans_le (hR n))] using Real.exp_nat_mul (Real.log (R n)) 2 + simp only [Real.exp_add,heρ] at h₁ + simp only [Real.exp_sub,Real.exp_add,heR,Real.exp_log (zero_lt_one.trans_le (hQ n)),heρ,hβ n] at h₂ + simp only [Real.exp_sub,Real.exp_add,Real.exp_log (hjpos n)] at h₃ + change M < Real.exp (z*(n:ℝ)+(j n:ℝ)*(2*Real.log p₀)) at h₄ + rw [Real.exp_add,hβ n] at h₄ + refine ⟨hk₀,h₁.le,?_,(div_le_iff₀ (pow_pos hp₀ _)).mp h₂.le,h₄⟩ + exact ((div_le_iff₀ (Real.exp_pos _)).mp h₃.le).trans (hm n) + obtain ⟨n,hn⟩ := hfinal.exists + exact ⟨n,k n,B n,hn.1,Real.exp_pos _,hn.2⟩ + + + +theorem exists_corridor_scales + (ρ p₀ C C₁ ε M cm : ℝ) (J k₀ : ℕ) + (hρ : 0 < ρ) (hρ₁ : ρ < 1) (hp₀ : 0 < p₀) (hC : 0 < C) + (hC₁ : 0 < C₁) (hε : 0 < ε) (hcm : 0 < cm) (hJ : 0 < J) + (m R Q : ℕ → ℝ) (hR : ∀ n, 1 ≤ R n) (hQ : ∀ n, 1 ≤ Q n) + (hm : ∀ n : ℕ, cm*Real.exp (n:ℝ) ≤ m n) + (hlogR : Tendsto (fun n => Real.log (R n)/(n:ℝ)) atTop (𝓝 0)) + (hlogQ : Tendsto (fun n => Real.log (Q n)/(n:ℝ)) atTop (𝓝 0)) : + ∃ (n k : ℕ) (B : ℝ), k₀ ≤ k ∧ 0 < B ∧ + let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R n)⌉₊ + B*ρ^k ≤ 1/4 ∧ B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m n ∧ + (R n)^2*Q n*ρ^k ≤ ε*p₀^(2*j) ∧ M < B*p₀^(2*j) := by + let r := 1/(4*(C+1)) + let z := min (1/4) (-(r*Real.log ρ)/2) + have hr : 0 < r := by dsimp [r]; positivity + have hlog : Real.log ρ < 0 := by simpa only [Real.log_one] using Real.log_lt_log hρ hρ₁ + have hz : 0 < z := lt_min (by norm_num) (half_pos (neg_pos.mpr (mul_neg_of_pos_of_neg hr hlog))) + have hzr : z+r*Real.log ρ < 0 := by + have hh : z ≤ -(r*Real.log ρ)/2 := min_le_right _ _ + linarith only [hh,mul_neg_of_pos_of_neg hr hlog] + have hzc : z+C*r < 1 := by + have hz' : z ≤ 1/4 := min_le_left _ _ + have hr' : r*(4*(C+1)) = 1 := div_mul_cancel₀ 1 (by positivity) + nlinarith only [hz',hr',hr] + exact exists_corridor_scales_of_slopes ρ p₀ C C₁ ε M cm r z J k₀ + hρ hp₀ hC₁ hε hcm hJ hr hz hzr hzc m R Q hR hQ hm hlogR hlogQ + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Sharpness.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Sharpness.lean index d2f6607d126df3a004ca2a7178b50e9c191a01ee..8485bd1992d673afa6619c60aef98def9f0a0345 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Sharpness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Sharpness.lean @@ -1,1542 +1,1542 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Sprinkling - -namespace OAI - -/-! Finite Russo formulae, exterior exposure and subcritical sharpness. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteRusso -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - - -noncomputable def bernoulliPolynomial (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : ℝ := - ∑ t ∈ s.powerset, f t * p ^ t.card * (1-p) ^ (s.card-t.card) - -@[simp] theorem bernoulliPolynomial_empty (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial ∅ f p = f ∅ := by simp [bernoulliPolynomial] - -theorem bernoulliPolynomial_congr (s : Finset E) {f g : Finset E → ℝ} - (h : ∀ t ⊆ s, f t = g t) (p : ℝ) : - bernoulliPolynomial s f p = bernoulliPolynomial s g p := by - apply Finset.sum_congr rfl - intro t ht - rw [h t (Finset.mem_powerset.mp ht)] - -theorem bernoulliPolynomial_sub (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial s (fun t => f t-g t) p = - bernoulliPolynomial s f p - bernoulliPolynomial s g p := by - simp only [bernoulliPolynomial, sub_mul, Finset.sum_sub_distrib] - -theorem bernoulliPolynomial_insert (s : Finset E) (e : E) (he : e ∉ s) - (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial (insert e s) f p = - (1-p)*bernoulliPolynomial s f p + p*bernoulliPolynomial s (fun t => f (insert e t)) p := by - have hd : Disjoint s.powerset (s.powerset.image (insert e)) := by - apply Finset.disjoint_left.mpr - intro t ht himg - obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp himg - exact he ((Finset.mem_powerset.mp ht) (by simp)) - have hinj : Set.InjOn (insert e) (↑s.powerset : Set (Finset E)) := by - intro t ht r hr h - have ht' : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) - have hr' : e ∉ r := fun h => he (Finset.mem_powerset.mp hr h) - have hh := congrArg (fun t : Finset E => t.erase e) h - simpa [ht', hr'] using hh - simp only [bernoulliPolynomial, Finset.powerset_insert, Finset.sum_union hd, - Finset.sum_image hinj, Finset.mul_sum, Finset.card_insert_of_notMem he] - congr 1 - · apply Finset.sum_congr rfl - intro t ht - have hcard := Finset.card_le_card (Finset.mem_powerset.mp ht) - have hexp : s.card+1-t.card = (s.card-t.card)+1 := by omega - rw [hexp, pow_succ] - ring - · apply Finset.sum_congr rfl - intro t ht - have het : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) - simp only [Finset.card_insert_of_notMem het, Nat.add_sub_add_right, pow_succ] - ring - - -theorem hasDerivAt_bernoulliPolynomial (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : - HasDerivAt (bernoulliPolynomial s f) - (∑ e ∈ s, bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p) p := by - induction s using Finset.induction_on generalizing f with - | empty => - convert hasDerivAt_const p (f ∅) using 1 <;> try rfl - · funext q - exact bernoulliPolynomial_empty f q - | @insert e s he ih => - have hd := (((hasDerivAt_const p 1).sub (hasDerivAt_id p)).mul (ih f)).add - ((hasDerivAt_id p).mul (ih (fun t => f (insert e t)))) - have hf : bernoulliPolynomial (insert e s) f = - fun q => (1-q)*bernoulliPolynomial s f q + - q*bernoulliPolynomial s (fun t => f (insert e t)) q := - funext fun q => bernoulliPolynomial_insert s e he f q - rw [hf] - convert hd using 1 <;> try rfl - have hs : ∑ a ∈ s, bernoulliPolynomial ((insert e s).erase a) - (fun t => f (insert a t)-f t) p = - (1-p)*(∑ a ∈ s, bernoulliPolynomial (s.erase a) (fun t => f (insert a t)-f t) p) + - p*(∑ a ∈ s, bernoulliPolynomial (s.erase a) - (fun t => f (insert e (insert a t))-f (insert e t)) p) := by - simp only [Finset.mul_sum, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro a ha - have hae : e ≠ a := (ne_of_mem_of_not_mem ha he).symm - rw [Finset.erase_insert_of_ne hae, bernoulliPolynomial_insert _ e - (fun hh => he (Finset.mem_of_mem_erase hh))] - congr 2 - apply bernoulliPolynomial_congr - intro t _ - rw [Finset.insert_comm e a] - simp only [Finset.sum_insert he, Finset.erase_insert he, zero_sub, neg_one_mul, - one_mul, Pi.sub_apply, id_eq] - rw [hs, bernoulliPolynomial_sub] - ring - -@[simp] theorem bernoulliPolynomial_zero (s : Finset E) (p : ℝ) : - bernoulliPolynomial s (fun _ => 0) p = 0 := by simp [bernoulliPolynomial] - -theorem bernoulliPolynomial_const (s : Finset E) (c p : ℝ) : - bernoulliPolynomial s (fun _ => c) p = c := by - induction s using Finset.induction_on with - | empty => simp - | @insert e s he ih => rw [bernoulliPolynomial_insert s e he]; simp only [ih]; ring - -theorem bernoulliPolynomial_nonneg (s : Finset E) (f : Finset E → ℝ) (p : ℝ) - (hp : p ∈ Set.Icc (0:ℝ) 1) (hf : ∀ t ⊆ s, 0 ≤ f t) : - 0 ≤ bernoulliPolynomial s f p := by - apply Finset.sum_nonneg - intro t ht - exact mul_nonneg (mul_nonneg (hf t (Finset.mem_powerset.mp ht)) - (pow_nonneg hp.1 _)) (pow_nonneg (sub_nonneg.mpr hp.2) _) - -theorem bernoulliPolynomial_mono (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) - (hp : p ∈ Set.Icc (0:ℝ) 1) (hfg : ∀ t ⊆ s, f t ≤ g t) : - bernoulliPolynomial s f p ≤ bernoulliPolynomial s g p := by - apply Finset.sum_le_sum - intro t ht - exact mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_right (hfg t (Finset.mem_powerset.mp ht)) (pow_nonneg hp.1 _)) - (pow_nonneg (sub_nonneg.mpr hp.2) _) - - -theorem bernoulliPolynomial_union (s t : Finset E) (hdis : Disjoint s t) - (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial (s ∪ t) f p = - bernoulliPolynomial s (fun a => bernoulliPolynomial t (fun b => f (a ∪ b)) p) p := by - induction s using Finset.induction_on generalizing f with - | empty => simp - | @insert e s he ih => - have hed : e ∉ t := (Finset.disjoint_insert_left.mp hdis).1 - have hst : Disjoint s t := (Finset.disjoint_insert_left.mp hdis).2 - rw [Finset.insert_union, bernoulliPolynomial_insert _ e (by simp [he, hed]), - bernoulliPolynomial_insert s e he, ih hst, ih hst] - congr 2 - apply bernoulliPolynomial_congr - intro a _ - apply bernoulliPolynomial_congr - intro b _ - rw [Finset.insert_union] - - - -theorem bernoulliPolynomial_closed_difference (s : Finset E) (e : E) (he : e ∈ s) - (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial s (fun t => if e ∈ t then 0 else f (insert e t)-f t) p = - (1-p)*bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by - have hes : e ∉ s.erase e := Finset.notMem_erase e s - conv_lhs => rw [← Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e hes] - have hc : bernoulliPolynomial (s.erase e) - (fun t => if e ∈ t then 0 else f (insert e t)-f t) p = - bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by - apply bernoulliPolynomial_congr - intro t ht - simp [show e ∉ t from fun h => hes (ht h)] - rw [hc] - simp - -theorem closed_difference_russo (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : - (1-p)*deriv (bernoulliPolynomial s f) p = - ∑ e ∈ s, bernoulliPolynomial s - (fun t => if e ∈ t then 0 else f (insert e t)-f t) p := by - rw [(hasDerivAt_bernoulliPolynomial s f p).deriv, Finset.mul_sum] - apply Finset.sum_congr rfl - intro e he - exact (bernoulliPolynomial_closed_difference s e he f p).symm - - -noncomputable def finiteEventPolynomial (s : Finset E) (A : Set (Set E)) (p : ℝ) : ℝ := - bernoulliPolynomial s (fun t => if (t : Set E) ∈ A then 1 else 0) p - -theorem finiteEventPolynomial_eq (s : Finset E) (A : Set (Set E)) (p : unitInterval) : - finiteEventPolynomial s A (p : ℝ) = finiteProbability p s A := by - unfold finiteEventPolynomial bernoulliPolynomial finiteProbability - apply Finset.sum_congr rfl - intro t _ - by_cases ht : (t : Set E) ∈ A <;> simp [ht] - - -def closedPivotal (A : Set (Set E)) (e : E) : Set (Set E) := - {ω | e ∉ ω ∧ ω ∉ A ∧ insert e ω ∈ A} - -theorem closedPivotal_difference (A : Set (Set E)) (hA : IsUpperSet A) (e : E) - (t : Finset E) : - (if (t : Set E) ∈ closedPivotal A e then (1:ℝ) else 0) = - (if e ∈ t then 0 else - (if ((insert e t : Finset E) : Set E) ∈ A then (1:ℝ) else 0) - - (if (t : Set E) ∈ A then 1 else 0)) := by - by_cases he : e ∈ t - · simp [closedPivotal, he] - · by_cases ha : (t : Set E) ∈ A - · have hi : insert e (t : Set E) ∈ A := hA (Set.subset_insert e _) ha - simp [closedPivotal, he, ha, hi] - · by_cases hi : insert e (t : Set E) ∈ A <;> simp [closedPivotal, he, ha, hi] - - -theorem finite_russo_closed (s : Finset E) (A : Set (Set E)) (hA : IsUpperSet A) - (p : unitInterval) : - (1-(p:ℝ))*deriv (finiteEventPolynomial s A) (p:ℝ) = - ∑ e ∈ s, finiteProbability p s (closedPivotal A e) := by - rw [show finiteEventPolynomial s A = - bernoulliPolynomial s (fun t => if (t : Set E) ∈ A then 1 else 0) from rfl, - closed_difference_russo] - apply Finset.sum_congr rfl - intro e _ - rw [← finiteEventPolynomial_eq] - apply bernoulliPolynomial_congr - intro t _ - exact (closedPivotal_difference A hA e t).symm - - - -theorem finite_russo_closed_law [Fintype E] (A : Set (Set E)) (hA : IsUpperSet A) - (p : unitInterval) : - (1-(p:ℝ))*deriv (finiteEventPolynomial Finset.univ A) (p:ℝ) = - ∑ e : E, (law p).real (closedPivotal A e) := by - simpa only [finiteProbability_univ] using finite_russo_closed Finset.univ A hA p - -end FiniteRusso - -section ExteriorExposure -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - - -theorem conn_insert_iff (G : BondGraph V E) (ω : Set E) (e : E) (a b x y : V) - (he : G e = s(a,b)) : - Conn G (insert e ω) x y ↔ Conn G ω x y ∨ - (Conn G ω x a ∧ Conn G ω b y) ∨ (Conn G ω x b ∧ Conn G ω a y) := by - constructor - · intro hh - induction hh with - | refl => exact Or.inl (conn_refl G ω x) - | @tail u v huv huv' ih => - obtain ⟨f,hf,hfuv⟩ := huv' - rcases Set.mem_insert_iff.mp hf with rfl | hf - · have hp : s(a,b) = s(u,v) := he.symm.trans hfuv - rcases Sym2.eq_iff.mp hp with ⟨rfl,rfl⟩ | ⟨rfl,rfl⟩ - · rcases ih with h | ⟨hxa,hba⟩ | ⟨hxb,haa⟩ - · exact Or.inr (Or.inl ⟨h,conn_refl G ω b⟩) - · exact Or.inr (Or.inl ⟨hxa,conn_refl G ω b⟩) - · exact Or.inl hxb - · rcases ih with h | ⟨hxa,hbb⟩ | ⟨hxb,hab⟩ - · exact Or.inr (Or.inr ⟨h,conn_refl G ω a⟩) - · exact Or.inl hxa - · exact Or.inr (Or.inr ⟨hxb,conn_refl G ω a⟩) - · have huvω : Conn G ω u v := .single ⟨f,hf,hfuv⟩ - rcases ih with h | ⟨hxa,hbu⟩ | ⟨hxb,hau⟩ - · exact Or.inl (h.trans huvω) - · exact Or.inr (Or.inl ⟨hxa,hbu.trans huvω⟩) - · exact Or.inr (Or.inr ⟨hxb,hau.trans huvω⟩) - · intro hh - have hm : ω ⊆ insert e ω := Set.subset_insert e ω - have hab : Conn G (insert e ω) a b := .single ⟨e,Set.mem_insert e ω,he⟩ - rcases hh with h | ⟨hxa,hby⟩ | ⟨hxb,hay⟩ - · exact conn_mono G hm h - · exact (conn_mono G hm hxa).trans (hab.trans (conn_mono G hm hby)) - · exact (conn_mono G hm hxb).trans ((conn_symm G _ hab).trans (conn_mono G hm hay)) - - -def internalEdges (G : BondGraph V E) (S : Set V) : Set E := - {e | ∀ x ∈ G e, x ∈ S} - -@[simp] theorem mem_internalEdges_of_ends (G : BondGraph V E) (S : Set V) - (e : E) (a b : V) (he : G e = s(a,b)) : - e ∈ internalEdges G S ↔ a ∈ S ∧ b ∈ S := by - simp [internalEdges, he] - - -def unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) : Set V := - {x | ∀ y, Conn G ω x y → y ∈ Λ} - -theorem unexposed_subset (G : BondGraph V E) (Λ : Set V) (ω : Set E) : - unexposed G Λ ω ⊆ Λ := fun x hx => hx x (conn_refl G ω x) - -theorem mem_unexposed_of_conn (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {x y : V} (hx : x ∈ unexposed G Λ ω) (hxy : Conn G ω x y) : - y ∈ unexposed G Λ ω := by - intro z hyz - exact hx z (hxy.trans hyz) - - -theorem conn_restrict_unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {x y : V} (hx : x ∈ unexposed G Λ ω) (hxy : Conn G ω x y) : - Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x y := by - induction hxy with - | refl => exact conn_refl _ _ _ - | @tail y z hxy hyz ih => - obtain ⟨e,he,hends⟩ := hyz - have hy : y ∈ unexposed G Λ ω := mem_unexposed_of_conn G Λ ω hx hxy - have hz : z ∈ unexposed G Λ ω := mem_unexposed_of_conn G Λ ω hy (.single ⟨e,he,hends⟩) - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e y z hends).mpr ⟨hy,hz⟩⟩,hends⟩ - - -theorem unexposed_boundary_closed (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {e : E} {a b : V} (he : G e = s(a,b)) - (ha : a ∈ unexposed G Λ ω) (hb : b ∉ unexposed G Λ ω) : e ∉ ω := by - intro ho - exact hb (mem_unexposed_of_conn G Λ ω ha (.single ⟨e,ho,he⟩)) - - - -theorem unexposed_insert_crossing (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {e : E} {a b x : V} (he : G e = s(a,b)) - (hx : x ∈ unexposed G Λ ω) (_ha : a ∈ unexposed G Λ ω) - (hb : b ∉ unexposed G Λ ω) : - x ∉ unexposed G Λ (insert e ω) ↔ - Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x a := by - classical - constructor - · intro hn - obtain ⟨y,hxy,hy⟩ := by simpa [unexposed, not_forall, Classical.not_imp] using hn - rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | h | h - · exact (hy (hx y h)).elim - · exact conn_restrict_unexposed G Λ ω hx h.1 - · exact (hb (mem_unexposed_of_conn G Λ ω hx h.1)).elim - · intro hxa hn - have hxa' : Conn G ω x a := conn_mono G Set.inter_subset_left hxa - apply hb - intro y hby - exact hn y ((conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨hxa',hby⟩))) - - -theorem not_mem_unexposed_of_conn (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {x y : V} (hx : x ∉ unexposed G Λ ω) (hxy : Conn G ω x y) : - y ∉ unexposed G Λ ω := by - intro hy - exact hx (mem_unexposed_of_conn G Λ ω hy (conn_symm G ω hxy)) - - -theorem conn_sdiff_internal_unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) - {x y : V} (hx : x ∉ unexposed G Λ ω) (hxy : Conn G ω x y) : - Conn G (ω \ internalEdges G (unexposed G Λ ω)) x y := by - induction hxy with - | refl => exact conn_refl _ _ _ - | @tail y z hxy hyz ih => - obtain ⟨e,he,hends⟩ := hyz - have hy : y ∉ unexposed G Λ ω := not_mem_unexposed_of_conn G Λ ω hx hxy - exact ih.tail ⟨e,⟨he,fun hi => hy ((mem_internalEdges_of_ends G _ e y z hends).mp hi).1⟩,hends⟩ - - -theorem unexposed_sdiff_internal (G : BondGraph V E) (Λ : Set V) (ω : Set E) : - unexposed G Λ (ω \ internalEdges G (unexposed G Λ ω)) = unexposed G Λ ω := by - ext x - constructor - · intro hx - by_contra hn - apply hn - intro y hxy - exact hx y (conn_sdiff_internal_unexposed G Λ ω hn hxy) - · intro hx y hxy - exact hx y (conn_mono G Set.sdiff_subset hxy) - - -theorem unexposed_union_internal (G : BondGraph V E) (Λ : Set V) (ω η : Set E) - (hη : η ⊆ internalEdges G (unexposed G Λ ω)) : - unexposed G Λ (ω ∪ η) = unexposed G Λ ω := by - ext x - constructor - · intro hx y hxy - exact hx y (conn_mono G Set.subset_union_left hxy) - · intro hx y hxy - suffices hy : y ∈ unexposed G Λ ω from unexposed_subset G Λ ω hy - induction hxy with - | refl => exact hx - | @tail y z hxy hyz ih => - obtain ⟨e,hωe,he⟩ := hyz - rcases hωe with ho | hηe - · exact mem_unexposed_of_conn G Λ ω ih (.single ⟨e,ho,he⟩) - · exact ((mem_internalEdges_of_ends G _ e y z he).mp (hη hηe)).2 - - -theorem unexposed_union_eq_iff (G : BondGraph V E) (Λ S : Set V) (a b : Set E) - (ha : a ⊆ internalEdges G S) (hb : Disjoint b (internalEdges G S)) : - unexposed G Λ (a ∪ b) = S ↔ unexposed G Λ b = S := by - constructor - · intro h - have he : (a ∪ b) \ internalEdges G S = b := by - ext e - constructor - · rintro ⟨he,hn⟩ - exact he.resolve_left (fun he => hn (ha he)) - · intro he - exact ⟨Or.inr he,fun hi => Set.disjoint_left.mp hb he hi⟩ - simpa only [h, he] using unexposed_sdiff_internal G Λ (a ∪ b) - · intro h - have he := unexposed_union_internal G Λ b a (h ▸ ha) - simpa only [Set.union_comm b a,h] using he - - -def escapeEvent (G : BondGraph V E) (Λ : Set V) (x : V) : Set (Set E) := - {ω | x ∉ unexposed G Λ ω} - -theorem escapeEvent_isUpperSet (G : BondGraph V E) (Λ : Set V) (x : V) : - IsUpperSet (escapeEvent G Λ x) := by - intro ω η hωη hx hη - apply hx - intro y hxy - exact hη y (conn_mono G hωη hxy) - - -theorem escape_closed_pivotal_iff (G : BondGraph V E) (Λ : Set V) - (ω : Set E) (x : V) (e : E) : - (e ∉ ω ∧ ω ∉ escapeEvent G Λ x ∧ insert e ω ∈ escapeEvent G Λ x) ↔ - x ∈ unexposed G Λ ω ∧ ∃ a b, - G e = s(a,b) ∧ a ∈ unexposed G Λ ω ∧ b ∉ unexposed G Λ ω ∧ - Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x a := by - classical - constructor - · rintro ⟨_,hx,hn⟩ - have hx' : x ∈ unexposed G Λ ω := by simpa [escapeEvent] using hx - refine ⟨hx',?_⟩ - obtain ⟨⟨a,b⟩,he'⟩ := Sym2.mk_surjective (G e) - have he : G e = s(a,b) := he'.symm - obtain ⟨y,hxy,hy⟩ := by simpa [escapeEvent,unexposed,not_forall,Classical.not_imp] using hn - rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | h | h - · exact (hy (hx' y h)).elim - · exact ⟨a,b,he,mem_unexposed_of_conn G Λ ω hx' h.1, - fun hb => hy (hb y h.2),conn_restrict_unexposed G Λ ω hx' h.1⟩ - · exact ⟨b,a,he.trans (Sym2.eq_swap ..),mem_unexposed_of_conn G Λ ω hx' h.1, - fun ha => hy (ha y h.2),conn_restrict_unexposed G Λ ω hx' h.1⟩ - · rintro ⟨hx,a,b,he,ha,hb,hxa⟩ - exact ⟨unexposed_boundary_closed G Λ ω he ha hb,by simpa [escapeEvent] using hx, - (unexposed_insert_crossing G Λ ω he hx ha hb).mpr hxa⟩ - -attribute [local instance] Classical.decEq - - theorem bernoulliPolynomial_add (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial s (fun t => f t+g t) p = - bernoulliPolynomial s f p + bernoulliPolynomial s g p := by - simp only [bernoulliPolynomial, add_mul, Finset.sum_add_distrib] - - theorem bernoulliPolynomial_mul_const (s : Finset E) (f : Finset E → ℝ) (c p : ℝ) : - bernoulliPolynomial s (fun t => f t*c) p = bernoulliPolynomial s f p*c := by - simp only [bernoulliPolynomial, Finset.sum_mul] - apply Finset.sum_congr rfl - intro t _ - ring - - theorem bernoulliPolynomial_const_mul (s : Finset E) (f : Finset E → ℝ) (c p : ℝ) : - bernoulliPolynomial s (fun t => c*f t) p = c*bernoulliPolynomial s f p := by - simpa only [mul_comm c] using bernoulliPolynomial_mul_const s f c p - - theorem bernoulliPolynomial_sum {ι : Type*} (s : Finset E) (I : Finset ι) - (f : ι → Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial s (fun t => ∑ i ∈ I, f i t) p = - ∑ i ∈ I, bernoulliPolynomial s (f i) p := by - classical - simp only [bernoulliPolynomial, Finset.sum_mul] - exact Finset.sum_comm - - -theorem bernoulliPolynomial_blocks (s t : Finset E) (hdis : Disjoint s t) - (f g : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial (s ∪ t) (fun a => f (a ∩ s)*g (a ∩ t)) p = - bernoulliPolynomial s f p * bernoulliPolynomial t g p := by - rw [bernoulliPolynomial_union s t hdis] - trans bernoulliPolynomial s (fun a => f a*bernoulliPolynomial t g p) p - · apply bernoulliPolynomial_congr - intro a ha - rw [← bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro b hb - have has : a ∩ s = a := Finset.inter_eq_left.mpr ha - have hbt : b ∩ t = b := Finset.inter_eq_left.mpr hb - have hbs : b ∩ s = ∅ := Finset.disjoint_iff_inter_eq_empty.mp - (hdis.symm.mono_left hb) - have hat : a ∩ t = ∅ := Finset.disjoint_iff_inter_eq_empty.mp - (hdis.mono_left ha) - simp [Finset.union_inter_distrib_right,has,hbt,hbs,hat] - · exact bernoulliPolynomial_mul_const s f _ p - - - -theorem bernoulliPolynomial_exposure (G : BondGraph V E) (Λ S : Set V) - (s t : Finset E) (hs : (s : Set E) ⊆ internalEdges G S) - (ht : Disjoint (t : Set E) (internalEdges G S)) (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial (s ∪ t) - (fun a => (if unexposed G Λ (a : Set E) = S then (1:ℝ) else 0) * f (a ∩ s)) p = - bernoulliPolynomial t (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p * - bernoulliPolynomial s f p := by - have hdis : Disjoint s t := by - apply Finset.disjoint_left.mpr - intro e he hf - exact Set.disjoint_left.mp ht hf (hs he) - rw [bernoulliPolynomial_union s t hdis] - trans bernoulliPolynomial s (fun a => - bernoulliPolynomial t (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p * f a) p - · apply bernoulliPolynomial_congr - intro a ha - rw [← bernoulliPolynomial_mul_const] - apply bernoulliPolynomial_congr - intro b hb - have hab : unexposed G Λ ((a ∪ b : Finset E) : Set E) = S ↔ - unexposed G Λ (b : Set E) = S := by - rw [Finset.coe_union] - exact unexposed_union_eq_iff G Λ S _ _ (fun _ he => hs (ha he)) - (ht.mono_left (by exact_mod_cast hb)) - have hbs : b ∩ s = ∅ := - Finset.disjoint_iff_inter_eq_empty.mp (hdis.symm.mono_left hb) - rw [Finset.union_inter_distrib_right,Finset.inter_eq_left.mpr ha,hbs,Finset.union_empty] - simp only [hab] - · exact bernoulliPolynomial_const_mul s f _ p - - -noncomputable def unexposedRegion (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : Finset V := - ((Set.toFinite (Λ : Set V)).subset (unexposed_subset G (Λ : Set V) ω)).toFinset - -@[simp] theorem coe_unexposedRegion (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : - (unexposedRegion G Λ ω : Set V) = unexposed G (Λ : Set V) ω := by - simp [unexposedRegion] - -theorem unexposedRegion_subset (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : - unexposedRegion G Λ ω ⊆ Λ := by - intro x hx - apply unexposed_subset G (Λ : Set V) ω - simpa only [← coe_unexposedRegion,Finset.mem_coe] using hx - - -theorem bernoulliPolynomial_partition_region (G : BondGraph V E) (Λ : Finset V) - (F : Finset E) (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial F f p = ∑ S ∈ Λ.powerset, - bernoulliPolynomial F - (fun t => if unexposed G (Λ : Set V) (t : Set E) = (S : Set V) then f t else 0) p := by - rw [← bernoulliPolynomial_sum] - apply bernoulliPolynomial_congr - intro t _ - symm - rw [Finset.sum_eq_single (unexposedRegion G Λ (t : Set E))] - · simp - · intro S _ hne - have hh : unexposed G (Λ : Set V) (t : Set E) ≠ (S : Set V) := by - intro he - apply hne - apply Finset.coe_injective - exact he.symm.trans (coe_unexposedRegion G Λ (t : Set E)).symm - simp [hh] - · intro hn - exact (hn (Finset.mem_powerset.mpr (unexposedRegion_subset G Λ (t : Set E)))).elim - - -noncomputable def internalSupport (G : BondGraph V E) (S : Set V) (F : Finset E) : Finset E := - F.filter (fun e => e ∈ internalEdges G S) - - theorem internalSupport_subset (G : BondGraph V E) (S : Set V) (F : Finset E) : - internalSupport G S F ⊆ F := Finset.filter_subset _ _ - - theorem internalSupport_union_sdiff (G : BondGraph V E) (S : Set V) (F : Finset E) : - internalSupport G S F ∪ (F \ internalSupport G S F) = F := - Finset.union_sdiff_of_subset (internalSupport_subset G S F) - - theorem coe_inter_internalSupport (G : BondGraph V E) (S : Set V) (F t : Finset E) - (ht : t ⊆ F) : ((t ∩ internalSupport G S F : Finset E) : Set E) = - (t : Set E) ∩ internalEdges G S := by - ext e - simp only [Finset.mem_coe,Finset.mem_inter,internalSupport,Finset.mem_filter,Set.mem_inter_iff] - exact ⟨fun h => ⟨h.1,h.2.2⟩,fun h => ⟨h.1,ht h.1,h.2⟩⟩ - - -noncomputable def regionProbability (G : BondGraph V E) (Λ S : Set V) - (F : Finset E) (p : ℝ) : ℝ := - bernoulliPolynomial F (fun t => if unexposed G Λ (t : Set E) = S then 1 else 0) p - - theorem regionProbability_nonneg (G : BondGraph V E) (Λ S : Set V) - (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : - 0 ≤ regionProbability G Λ S F p := by - apply bernoulliPolynomial_nonneg _ _ _ hp - intro t _ - split_ifs <;> norm_num - - -theorem bernoulliPolynomial_exposure_factor (G : BondGraph V E) (Λ S : Set V) - (F : Finset E) (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial F - (fun t => (if unexposed G Λ (t : Set E) = S then (1:ℝ) else 0) * - f (t ∩ internalSupport G S F)) p = - regionProbability G Λ S F p * bernoulliPolynomial (internalSupport G S F) f p := by - let s := internalSupport G S F - let t := F \ s - have hs : (s : Set E) ⊆ internalEdges G S := by - intro e he - exact (Finset.mem_filter.mp he).2 - have ht : Disjoint (t : Set E) (internalEdges G S) := by - apply Set.disjoint_left.mpr - intro e he hi - have he' := Finset.mem_sdiff.mp he - exact he'.2 (Finset.mem_filter.mpr ⟨he'.1,hi⟩) - have he : s ∪ t = F := internalSupport_union_sdiff G S F - have hq : bernoulliPolynomial t - (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p = - regionProbability G Λ S F p := by - simpa only [he,mul_one,bernoulliPolynomial_const,regionProbability] using - (bernoulliPolynomial_exposure G Λ S s t hs ht (fun _ => 1) p).symm - simpa only [he,hq] using bernoulliPolynomial_exposure G Λ S s t hs ht f p - - -def crossingReach (G : BondGraph V E) (S : Set V) (x : V) (ω : Set E) (e : E) : Prop := - ∃ a b, G e = s(a,b) ∧ a ∈ S ∧ b ∉ S ∧ Conn G ω x a - -noncomputable def crossingCount (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) (ω : Set E) : ℝ := - ∑ e ∈ F, if crossingReach G S x ω e then (1:ℝ) else 0 - - -noncomputable def boundaryExpectation (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) (p : ℝ) : ℝ := - bernoulliPolynomial (internalSupport G S F) - (fun t => crossingCount G S x F (t : Set E)) p - -noncomputable def closedEscapeCount (G : BondGraph V E) (Λ : Set V) (x : V) - (F : Finset E) (ω : Set E) : ℝ := - ∑ e ∈ F, if ω ∈ closedPivotal (escapeEvent G Λ x) e then (1:ℝ) else 0 - -theorem finite_escape_russo (G : BondGraph V E) (Λ : Set V) (x : V) - (F : Finset E) (p : ℝ) : - (1-p)*deriv (finiteEventPolynomial F (escapeEvent G Λ x)) p = - bernoulliPolynomial F (fun t => closedEscapeCount G Λ x F (t : Set E)) p := by - unfold finiteEventPolynomial - rw [closed_difference_russo] - unfold closedEscapeCount - rw [bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro e _ - apply bernoulliPolynomial_congr - intro t _ - exact (closedPivotal_difference _ (escapeEvent_isUpperSet G Λ x) e t).symm - - -theorem closedEscapeCount_expectation (G : BondGraph V E) (Λ : Finset V) (x : V) - (F : Finset E) (p : ℝ) : - bernoulliPolynomial F (fun t => closedEscapeCount G Λ x F (t : Set E)) p = - ∑ S ∈ Λ.powerset, if x ∈ S then - regionProbability G Λ S F p * boundaryExpectation G S x F p else 0 := by - rw [bernoulliPolynomial_partition_region G Λ F] - apply Finset.sum_congr rfl - intro S _ - by_cases hx : x ∈ S - · rw [ite_eq_left hx] - unfold boundaryExpectation - rw [← bernoulliPolynomial_exposure_factor G Λ S F - (fun t => crossingCount G S x F (t : Set E)) p] - apply bernoulliPolynomial_congr - intro t ht - by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) - · simp only [hreg,ite_true,one_mul] - apply Finset.sum_congr rfl - intro e _ - have hc : (t : Set E) ∈ closedPivotal (escapeEvent G Λ x) e ↔ - crossingReach G S x ((t ∩ internalSupport G S F : Finset E) : Set E) e := by - simpa only [closedPivotal,Set.mem_ofPred_eq,hreg,Finset.mem_coe,hx,true_and, - coe_inter_internalSupport G S F t ht,crossingReach] using - escape_closed_pivotal_iff G Λ (t : Set E) x e - exact if_congr hc rfl rfl - · simp [hreg] - · rw [ite_eq_right hx,← bernoulliPolynomial_zero F p] - apply bernoulliPolynomial_congr - intro t _ - by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) - · simp only [hreg,ite_true] - apply Finset.sum_eq_zero - intro e _ - have hn : (t : Set E) ∉ closedPivotal (escapeEvent G Λ x) e := by - intro he - have hh := ((escape_closed_pivotal_iff G Λ (t : Set E) x e).mp he).1 - apply hx - simpa only [hreg,Finset.mem_coe] using hh - simp [hn] - · simp [hreg] - - -theorem finite_escape_complement (G : BondGraph V E) (Λ : Finset V) (x : V) - (F : Finset E) (p : ℝ) : - 1-finiteEventPolynomial F (escapeEvent G Λ x) p = - ∑ S ∈ Λ.powerset, if x ∈ S then regionProbability G Λ S F p else 0 := by - have he : 1-finiteEventPolynomial F (escapeEvent G Λ x) p = - bernoulliPolynomial F - (fun t => if x ∈ unexposed G (Λ : Set V) (t : Set E) then (1:ℝ) else 0) p := by - change 1-bernoulliPolynomial F (fun t => if (t : Set E) ∈ escapeEvent G Λ x then 1 else 0) p = _ - rw [show (1:ℝ) = bernoulliPolynomial F (fun _ => 1) p from (bernoulliPolynomial_const F 1 p).symm] - rw [← bernoulliPolynomial_sub] - apply bernoulliPolynomial_congr - intro t _ - by_cases hx : x ∈ unexposed G (Λ : Set V) (t : Set E) <;> simp [escapeEvent,hx,bernoulliPolynomial_const] - rw [he,bernoulliPolynomial_partition_region G Λ F] - apply Finset.sum_congr rfl - intro S _ - by_cases hx : x ∈ S - · rw [ite_eq_left hx] - apply bernoulliPolynomial_congr - intro t _ - by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) <;> simp [hreg,hx] - · rw [ite_eq_right hx,← bernoulliPolynomial_zero F p] - apply bernoulliPolynomial_congr - intro t _ - by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) <;> simp [hreg,hx] - - - -theorem finite_escape_differential_lower (G : BondGraph V E) (Λ : Finset V) (x : V) - (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) - (hcost : ∀ S ⊆ Λ, x ∈ S → 1 ≤ p*boundaryExpectation G (S : Set V) x F p) : - 1-finiteEventPolynomial F (escapeEvent G Λ x) p ≤ - p*(1-p)*deriv (finiteEventPolynomial F (escapeEvent G Λ x)) p := by - rw [mul_assoc,finite_escape_russo,closedEscapeCount_expectation,finite_escape_complement, - Finset.mul_sum] - apply Finset.sum_le_sum - intro S hS - by_cases hx : x ∈ S - · simp only [ite_eq_left hx] - have hq := regionProbability_nonneg G Λ S F p hp - calc - regionProbability G Λ S F p ≤ - regionProbability G Λ S F p * (p*boundaryExpectation G S x F p) := - le_mul_of_one_le_right hq (hcost S (Finset.mem_powerset.mp hS) hx) - _ = p*(regionProbability G Λ S F p * boundaryExpectation G S x F p) := by ring - · simp [hx] - - theorem bernoulliPolynomial_monotoneOn (F : Finset E) (f : Finset E → ℝ) - (hf : ∀ a b, a ⊆ b → f a ≤ f b) : - MonotoneOn (bernoulliPolynomial F f) (Set.Icc (0:ℝ) 1) := by - have hd : Differentiable ℝ (bernoulliPolynomial F f) := - fun q => (hasDerivAt_bernoulliPolynomial F f q).differentiableAt - apply monotoneOn_of_deriv_nonneg (convex_Icc 0 1) hd.continuous.continuousOn hd.differentiableOn - intro q hq - have hq' : q ∈ Set.Icc (0:ℝ) 1 := interior_subset hq - rw [(hasDerivAt_bernoulliPolynomial F f q).deriv] - apply Finset.sum_nonneg - intro e _ - apply bernoulliPolynomial_nonneg _ _ _ hq' - intro t _ - exact sub_nonneg.mpr (hf t (insert e t) (Finset.subset_insert e t)) - - theorem crossingCount_mono (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) {ω η : Set E} (h : ω ⊆ η) : - crossingCount G S x F ω ≤ crossingCount G S x F η := by - apply Finset.sum_le_sum - intro e _ - have hh : crossingReach G S x ω e → crossingReach G S x η e := by - rintro ⟨a,b,he,ha,hb,hc⟩ - exact ⟨a,b,he,ha,hb,conn_mono G h hc⟩ - by_cases hω : crossingReach G S x ω e - · simp [hω,hh hω] - · simp only [ite_eq_right hω] - split_ifs <;> norm_num - - theorem boundaryExpectation_nonneg (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : - 0 ≤ boundaryExpectation G S x F p := by - apply bernoulliPolynomial_nonneg _ _ _ hp - intro t _ - apply Finset.sum_nonneg - intro e _ - split_ifs <;> norm_num - - theorem boundaryExpectation_monotoneOn (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) : MonotoneOn (boundaryExpectation G S x F) (Set.Icc (0:ℝ) 1) := by - apply bernoulliPolynomial_monotoneOn - intro a b hab - exact crossingCount_mono G S x F (by exact_mod_cast hab) - - theorem boundaryCost_monotoneOn (G : BondGraph V E) (S : Set V) (x : V) - (F : Finset E) : MonotoneOn (fun p => p*boundaryExpectation G S x F p) - (Set.Icc (0:ℝ) 1) := by - intro p hp q hq hpq - exact mul_le_mul hpq (boundaryExpectation_monotoneOn G S x F hp hq hpq) - (boundaryExpectation_nonneg G S x F p hp) hq.1 - - theorem finiteEventPolynomial_mem_Icc (F : Finset E) (A : Set (Set E)) - (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : - finiteEventPolynomial F A p ∈ Set.Icc (0:ℝ) 1 := by - constructor - · apply bernoulliPolynomial_nonneg _ _ _ hp - intro t _ - split_ifs <;> norm_num - · calc - finiteEventPolynomial F A p ≤ bernoulliPolynomial F (fun _ => 1) p := by - apply bernoulliPolynomial_mono _ _ _ _ hp - intro t _ - split_ifs <;> norm_num - _ = 1 := bernoulliPolynomial_const F 1 p - - - -theorem differential_escape_growth {f : ℝ → ℝ} {r p : ℝ} - (hr : 0 < r) (hrp : r ≤ p) (hp : p < 1) - (hf : Differentiable ℝ f) (hbound : ∀ q ∈ Set.Icc r p, f q ∈ Set.Icc (0:ℝ) 1) - (hineq : ∀ q ∈ Set.Icc r p, 1-f q ≤ q*(1-q)*deriv f q) : - 1-Real.exp (r-p) ≤ f p := by - have hd (q : ℝ) : HasDerivAt (fun u => Real.exp u*(1-f u)) - (Real.exp q*(1-f q)+Real.exp q*(0-deriv f q)) q := - (Real.hasDerivAt_exp q).mul ((hasDerivAt_const q 1).sub (hf q).hasDerivAt) - have hanti : AntitoneOn (fun q => Real.exp q*(1-f q)) (Set.Icc r p) := by - apply antitoneOn_of_hasDerivWithinAt_nonpos (convex_Icc r p) - (Real.continuous_exp.mul (continuous_const.sub hf.continuous)).continuousOn - (fun q _ => (hd q).hasDerivWithinAt) - intro q hq - have hqi : q ∈ Set.Icc r p := interior_subset hq - have hq0 : 0 < q := hr.trans_le hqi.1 - have hq1 : q < 1 := hqi.2.trans_lt hp - have hcoef : 0 < q*(1-q) := mul_pos hq0 (sub_pos.mpr hq1) - have hder : 0 ≤ deriv f q := nonneg_of_mul_nonneg_right - ((sub_nonneg.mpr (hbound q hqi).2).trans (hineq q hqi)) hcoef - have hc : q*(1-q) ≤ 1 := by nlinarith [sq_nonneg q] - have hsmall : 1-f q ≤ deriv f q := (hineq q hqi).trans - (mul_le_of_le_one_left hder hc) - have hn := mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos q).le - (show 1-f q-deriv f q ≤ 0 by linarith) - nlinarith only [hn] - have hle := hanti (show r ∈ Set.Icc r p from ⟨le_rfl,hrp⟩) - (show p ∈ Set.Icc r p from ⟨hrp,le_rfl⟩) hrp - have he : Real.exp p*(1-f p) ≤ Real.exp r := by - calc - Real.exp p*(1-f p) ≤ Real.exp r*(1-f r) := hle - _ ≤ Real.exp r := mul_le_of_le_one_right (Real.exp_pos r).le - (by linarith [(hbound r ⟨le_rfl,hrp⟩).1]) - have hfin : 1-f p ≤ Real.exp (r-p) := by - rw [Real.exp_sub] - apply (le_div_iff₀ (Real.exp_pos p)).mpr - simpa only [mul_comm] using he - linarith - - - -theorem finite_escape_probability_lower (G : BondGraph V E) (Λ : Finset V) (x : V) - (F : Finset E) (r p : ℝ) (hr : 0 < r) (hrp : r < p) (hp : p < 1) - (hcost : ∀ S ⊆ Λ, x ∈ S → 1 ≤ r*boundaryExpectation G (S : Set V) x F r) : - 0 < 1-Real.exp (r-p) ∧ - 1-Real.exp (r-p) ≤ finiteEventPolynomial F (escapeEvent G Λ x) p := by - have hrI : r ∈ Set.Icc (0:ℝ) 1 := ⟨hr.le,(hrp.trans hp).le⟩ - have hqI (q : ℝ) (hq : q ∈ Set.Icc r p) : q ∈ Set.Icc (0:ℝ) 1 := - ⟨hr.le.trans hq.1,hq.2.trans hp.le⟩ - refine ⟨sub_pos.mpr (Real.exp_lt_one_iff.mpr (sub_neg.mpr hrp)),?_⟩ - apply differential_escape_growth hr hrp.le hp - · intro q - exact (hasDerivAt_bernoulliPolynomial F _ q).differentiableAt - · intro q hq - exact finiteEventPolynomial_mem_Icc F _ q (hqI q hq) - · intro q hq - apply finite_escape_differential_lower G Λ x F q (hqI q hq) - intro S hS hx - exact (hcost S hS hx).trans (boundaryCost_monotoneOn G S x F hrI (hqI q hq) hq.1) - -end ExteriorExposure - -section SharpnessBridge -attribute [local instance] Classical.propDecidable Classical.decEq -open Filter Topology - -theorem bernoulliPolynomial_map {F : Type*} (f : E ↪ F) (s : Finset E) - (h : Finset F → ℝ) (p : ℝ) : - bernoulliPolynomial (s.map f) h p = - bernoulliPolynomial s (fun t => h (t.map f)) p := by - induction s using Finset.induction_on generalizing h with - | empty => simp - | @insert e s he ih => - rw [Finset.map_insert,bernoulliPolynomial_insert _ (f e) (by simpa using he), - bernoulliPolynomial_insert s e he,ih,ih] - simp only [Finset.map_insert] - -theorem finiteEventPolynomial_restrict (F : Finset E) (A : Set (Set E)) (p : unitInterval) : - finiteEventPolynomial F A (p : ℝ) = (law p).real {ω | ω ∩ (F : Set E) ∈ A} := by - let f : (F : Set E) ↪ E := ⟨Subtype.val,Subtype.val_injective⟩ - have hm : (Finset.univ : Finset (F : Set E)).map f = F := by - ext e - simp [f] - have he : finiteEventPolynomial F A (p : ℝ) = - finiteEventPolynomial (Finset.univ : Finset (F : Set E)) - {η | f '' η ∈ A} (p : ℝ) := by - unfold finiteEventPolynomial - calc - bernoulliPolynomial F (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ) = - bernoulliPolynomial (Finset.univ.map f) (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ) := - congrArg (fun H => bernoulliPolynomial H (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ)) hm.symm - _ = _ := by - rw [bernoulliPolynomial_map] - apply bernoulliPolynomial_congr - intro t _ - simp only [Finset.coe_map] - rfl - rw [he,finiteEventPolynomial_eq,finiteProbability_univ,← law_map_restrict p (F : Set E), - measureReal_def,Measure.map_apply (measurable_set_restrict _) .of_discrete] - congr 2 - ext ω - have hh : f '' (Subtype.val ⁻¹' ω : Set (F : Set E)) = ω ∩ (F : Set E) := by - ext e - simp [f,and_comm] - simp only [Set.mem_preimage,Set.mem_ofPred_eq,hh] - -theorem bernoulliPolynomial_restrict (F H : Finset E) (hFH : F ⊆ H) - (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial H (fun t => f (t ∩ F)) p = bernoulliPolynomial F f p := by - rw [← Finset.union_sdiff_of_subset hFH,bernoulliPolynomial_union _ _ Finset.disjoint_sdiff] - trans bernoulliPolynomial F (fun a => f a) p - · apply bernoulliPolynomial_congr - intro a ha - trans bernoulliPolynomial (H \ F) (fun _ => f a) p - · apply bernoulliPolynomial_congr - intro b hb - have hdis : Disjoint b F := (Finset.disjoint_sdiff.symm).mono_left hb - rw [Finset.union_inter_distrib_right,Finset.inter_eq_left.mpr ha, - Finset.disjoint_iff_inter_eq_empty.mp hdis,Finset.union_empty] - · exact bernoulliPolynomial_const _ _ _ - · rfl - - -noncomputable def incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) : Finset E := Λ.biUnion (fun x => (hloc x).toFinset) - -@[simp] theorem mem_incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (e : E) : e ∈ incidentSupport G hloc Λ ↔ ∃ x ∈ Λ, x ∈ G e := by - simp [incidentSupport] - -theorem incidentSupport_mono (G : BondGraph V E) (hloc : LocallyFinite G) - {S Λ : Finset V} (hS : S ⊆ Λ) : incidentSupport G hloc S ⊆ incidentSupport G hloc Λ := by - intro e he - obtain ⟨x,hx,hxe⟩ := (mem_incidentSupport G hloc S e).mp he - exact (mem_incidentSupport G hloc Λ e).mpr ⟨x,hS hx,hxe⟩ - - -theorem escapeEvent_restrict_incident (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (x : V) (ω : Set E) : - ω ∩ (incidentSupport G hloc Λ : Set E) ∈ escapeEvent G Λ x ↔ - ω ∈ escapeEvent G Λ x := by - constructor - · exact escapeEvent_isUpperSet G Λ x Set.inter_subset_left - · intro hx - by_contra hn - have hx' : x ∈ unexposed G Λ (ω ∩ (incidentSupport G hloc Λ : Set E)) := by - simpa only [escapeEvent,Set.mem_ofPred_eq,not_not] using hn - apply hx - intro y hxy - have hc : Conn G (ω ∩ (incidentSupport G hloc Λ : Set E)) x y := by - induction hxy with - | refl => exact conn_refl _ _ _ - | @tail a b hxa hab ih => - obtain ⟨e,he,heab⟩ := hab - have ha : a ∈ Λ := hx' a ih - have hF : e ∈ incidentSupport G hloc Λ := - (mem_incidentSupport G hloc Λ e).mpr ⟨a,ha,by simp [heab]⟩ - exact ih.tail ⟨e,⟨he,hF⟩,heab⟩ - exact hx' y hc - -theorem finite_escape_eq_law (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (x : V) (p : unitInterval) : - finiteEventPolynomial (incidentSupport G hloc Λ) (escapeEvent G Λ x) (p : ℝ) = - (law p).real (escapeEvent G Λ x) := by - rw [finiteEventPolynomial_restrict] - congr 1 - ext ω - exact escapeEvent_restrict_incident G hloc Λ x ω - -theorem internal_edge_mem_incident (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) {e : E} (he : e ∈ internalEdges G (S : Set V)) : - e ∈ incidentSupport G hloc S := by - obtain ⟨⟨a,b⟩,hab⟩ := Sym2.mk_surjective (G e) - have ha : a ∈ G e := by rw [← hab]; simp - exact (mem_incidentSupport G hloc S e).mpr ⟨a,he a ha,ha⟩ - -theorem internalSupport_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) : - internalSupport G S F = internalSupport G S (incidentSupport G hloc S) := by - ext e - simp only [internalSupport,Finset.mem_filter] - exact ⟨fun h => ⟨internal_edge_mem_incident G hloc S h.2,h.2⟩, - fun h => ⟨hF h.1,h.2⟩⟩ - -theorem crossingCount_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (x : V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) (ω : Set E) : - crossingCount G S x F ω = crossingCount G S x (incidentSupport G hloc S) ω := by - symm - apply Finset.sum_subset hF - intro e _ he - have hn : ¬ crossingReach G S x ω e := by - rintro ⟨a,b,hab,ha,_,_⟩ - exact he ((mem_incidentSupport G hloc S e).mpr ⟨a,ha,by simp [hab]⟩) - simp [hn] - -theorem boundaryExpectation_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (x : V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) (p : ℝ) : - boundaryExpectation G S x F p = - boundaryExpectation G S x (incidentSupport G hloc S) p := by - unfold boundaryExpectation - rw [internalSupport_eq_of_incident_subset G hloc S F hF] - apply bernoulliPolynomial_congr - intro t _ - exact crossingCount_eq_of_incident_subset G hloc S x F hF t - - -noncomputable def boundaryCost (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (x : V) (p : ℝ) : ℝ := - p*boundaryExpectation G S x (incidentSupport G hloc S) p - -theorem measurableSet_escapeEvent (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (x : V) : MeasurableSet (escapeEvent G Λ x) := by - let F := incidentSupport G hloc Λ - have he : escapeEvent G Λ x = - (fun ω => (Subtype.val ⁻¹' ω : Set (F : Set E))) ⁻¹' - {η | Subtype.val '' η ∈ escapeEvent G Λ x} := by - ext ω - have hh : Subtype.val '' (Subtype.val ⁻¹' ω : Set (F : Set E)) = ω ∩ (F : Set E) := by - ext e - simp [and_comm] - simp only [Set.mem_preimage,Set.mem_ofPred_eq,hh] - exact (escapeEvent_restrict_incident G hloc Λ x ω).symm - rw [he] - exact MeasurableSet.preimage .of_discrete (measurable_set_restrict _) - -theorem escapeEvent_antitone_domain (G : BondGraph V E) {S Λ : Set V} (hS : S ⊆ Λ) - (x : V) : escapeEvent G Λ x ⊆ escapeEvent G S x := by - intro ω hω hn - apply hω - intro y hxy - exact hS (hn y hxy) - -noncomputable def vertexExhaustion [Encodable V] (n : ℕ) : Finset V := - (Finset.range n).preimage Encodable.encode Encodable.encode_injective.injOn - -theorem vertexExhaustion_mono [Encodable V] : - Monotone (vertexExhaustion : ℕ → Finset V) := by - intro m n h x hx - simp only [vertexExhaustion,Finset.mem_preimage,Finset.mem_range] at hx ⊢ - exact hx.trans_le h - -theorem subset_vertexExhaustion [Encodable V] (S : Finset V) : - ∃ n, S ⊆ vertexExhaustion n := by - refine ⟨S.sup Encodable.encode+1,?_⟩ - intro x hx - simp only [vertexExhaustion,Finset.mem_preimage,Finset.mem_range] - exact Nat.lt_succ_of_le (Finset.le_sup hx) - -theorem infinite_cluster_eq_iInter_escape [Encodable V] (G : BondGraph V E) (x : V) : - {ω | (cluster G ω x).Infinite} = ⋂ n, escapeEvent G (vertexExhaustion (V := V) n : Set V) x := by - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_iInter] - constructor - · intro hi n hn - exact hi ((vertexExhaustion n).finite_toSet.subset (by - intro y hy; exact hn y hy)) - · intro he hf - obtain ⟨n,hn⟩ := subset_vertexExhaustion hf.toFinset - apply he n - intro y hy - exact hn (hf.mem_toFinset.mpr hy) - - -theorem infinite_cluster_probability_ge_of_escape [Countable V] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (p : unitInterval) (c : ℝ) - (hc : ∀ Λ : Finset V, c ≤ (law p).real (escapeEvent G Λ x)) : - c ≤ (law p).real {ω | (cluster G ω x).Infinite} := by - let := Encodable.ofCountable V - rw [infinite_cluster_eq_iInter_escape] - have hm : Antitone (fun n => escapeEvent G (vertexExhaustion (V := V) n : Set V) x) := by - intro m n h - exact escapeEvent_antitone_domain G (by exact_mod_cast vertexExhaustion_mono h) x - have ht := tendsto_measure_iInter_atTop (μ := law p) - (fun n => (measurableSet_escapeEvent G hloc (vertexExhaustion n) x).nullMeasurableSet) - hm ⟨0,measure_ne_top _ _⟩ - have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht - exact ge_of_tendsto hr (Eventually.of_forall (fun n => hc (vertexExhaustion n))) - - - -theorem infinite_cluster_probability_pos_of_bad_cost [Countable V] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (r p : unitInterval) - (hr : 0 < r) (hrp : r < p) (hp : p < 1) - (hcost : ∀ S : Finset V, x ∈ S → 1 ≤ boundaryCost G hloc S x (r : ℝ)) : - 0 < (law p).real {ω | (cluster G ω x).Infinite} := by - have hc : 0 < 1-Real.exp ((r:ℝ)-(p:ℝ)) := - sub_pos.mpr (Real.exp_lt_one_iff.mpr (sub_neg.mpr hrp)) - apply hc.trans_le - apply infinite_cluster_probability_ge_of_escape G hloc x p - intro Λ - rw [← finite_escape_eq_law G hloc Λ x p] - apply (finite_escape_probability_lower G Λ x (incidentSupport G hloc Λ) - (r:ℝ) (p:ℝ) hr hrp hp ?_).2 - intro S hS hx - rw [boundaryExpectation_eq_of_incident_subset G hloc S x _ (incidentSupport_mono G hloc hS)] - exact hcost S hx - -theorem pc_le_of_infinite_cluster_probability_pos (G : BondGraph V E) - (x : V) (p : unitInterval) (hp : 0 < (law p).real {ω | (cluster G ω x).Infinite}) : - pc G ≤ p := by - apply sInf_le - have hh : 0 < law p {ω | (cluster G ω x).Infinite} := (ENNReal.toReal_pos_iff.mp hp).1 - apply hh.trans_le - apply measure_mono - intro ω hω - exact ⟨cluster G ω x,hω,x,rfl⟩ - - -theorem exists_subcritical_testSet [Countable V] (G : BondGraph V E) - (hloc : LocallyFinite G) (p : unitInterval) (hp : p < pc G) (x : V) : - ∃ S : Finset V, x ∈ S ∧ boundaryCost G hloc S x (p:ℝ) < 1 := by - by_cases hz : p = 0 - · exact ⟨{x},by simp,by simp [hz,boundaryCost]⟩ - · have hp0 : 0 < p := bot_lt_iff_ne_bot.mpr hz - by_contra! hn - obtain ⟨q,hpq,hqc⟩ := exists_between hp - have hq1 : q < 1 := hqc.trans_le (show pc G ≤ 1 from (pc G).2.2) - have hs := infinite_cluster_probability_pos_of_bad_cost G hloc x p q hp0 hpq hq1 hn - exact (not_le_of_gt hqc) (pc_le_of_infinite_cluster_probability_pos G x q hs) - -theorem internalEdges_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (S : Set V) (e : E) : - b e ∈ internalEdges G (a '' S) ↔ e ∈ internalEdges G S := by - constructor - · intro he x hx - have hh := he (a x) (by rw [h e]; exact Sym2.mem_map.mpr ⟨x,hx,rfl⟩) - simpa using hh - · intro he y hy - rw [h e,Sym2.mem_map] at hy - obtain ⟨x,hx,rfl⟩ := hy - exact Set.mem_image_of_mem a (he x hx) - -theorem crossingReach_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (S : Set V) (x : V) (ω : Set E) (e : E) : - crossingReach G (a '' S) (a x) (b '' ω) (b e) ↔ crossingReach G S x ω e := by - constructor - · rintro ⟨c,d,he,hc,hd,hconn⟩ - have he' : G e = s(a.symm c,a.symm d) := by - have hh := congrArg (Sym2.map a.symm) he - rw [h e,Sym2.map_map,Equiv.symm_comp_self,Sym2.map_id,Sym2.map_mk] at hh - exact hh - refine ⟨a.symm c,a.symm d,he',?_,?_,?_⟩ - · simpa using hc - · simpa using hd - · have hh := (conn_aut_iff G h (b '' ω) x (a.symm c)).mpr (by simpa using hconn) - simpa only [Set.preimage_image_eq _ b.injective] using hh - · rintro ⟨c,d,he,hc,hd,hconn⟩ - refine ⟨a c,a d,?_,by simpa using hc,by simpa using hd,conn_aut G h hconn⟩ - rw [h e,he,Sym2.map_mk] - -theorem internalSupport_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (S : Set V) (F : Finset E) : - internalSupport G (a '' S) (F.map b.toEmbedding) = - (internalSupport G S F).map b.toEmbedding := by - ext e - obtain ⟨d,rfl⟩ := b.surjective e - simp [internalSupport,internalEdges_aut_iff G h] - -theorem crossingCount_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (S : Set V) (x : V) (F : Finset E) (ω : Set E) : - crossingCount G (a '' S) (a x) (F.map b.toEmbedding) (b '' ω) = - crossingCount G S x F ω := by - simp only [crossingCount,Finset.sum_map,Equiv.toEmbedding_apply,crossingReach_aut_iff G h] - -theorem boundaryExpectation_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (S : Set V) (x : V) (F : Finset E) (p : ℝ) : - boundaryExpectation G (a '' S) (a x) (F.map b.toEmbedding) p = - boundaryExpectation G S x F p := by - unfold boundaryExpectation - rw [internalSupport_aut G h,bernoulliPolynomial_map] - apply bernoulliPolynomial_congr - intro t _ - simp only [Finset.coe_map,Equiv.coe_toEmbedding] - exact crossingCount_aut G h S x F t - -theorem incidentSupport_aut (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (S : Finset V) : - incidentSupport G hloc (S.map a.toEmbedding) = - (incidentSupport G hloc S).map b.toEmbedding := by - ext e - obtain ⟨d,rfl⟩ := b.surjective e - simp only [mem_incidentSupport,Finset.mem_map,Equiv.toEmbedding_apply, - b.injective.eq_iff,exists_eq_right] - constructor - · rintro ⟨x,⟨y,hy,rfl⟩,hx⟩ - rw [h d,Sym2.mem_map] at hx - obtain ⟨z,hz,hzy⟩ := hx - have hz' : z = y := a.injective hzy - exact ⟨y,hy,hz' ▸ hz⟩ - · rintro ⟨x,hx,he⟩ - exact ⟨a x,⟨x,hx,rfl⟩,by rw [h d]; exact Sym2.mem_map.mpr ⟨x,he,rfl⟩⟩ - -theorem boundaryCost_aut (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (S : Finset V) (x : V) (p : ℝ) : - boundaryCost G hloc (S.map a.toEmbedding) (a x) p = boundaryCost G hloc S x p := by - unfold boundaryCost - rw [incidentSupport_aut G hloc h,Finset.coe_map] - exact congrArg (p*·) (boundaryExpectation_aut G h S x (incidentSupport G hloc S) p) - - - -theorem exists_uniform_subcritical_testSets [Countable V] [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) : - ∃ (L : ℕ) (a : ℝ), 0 ≤ a ∧ a < 1 ∧ ∀ x, ∃ S : Finset V, - x ∈ S ∧ S.card ≤ L ∧ boundaryCost G hloc S x (p:ℝ) ≤ a := by - obtain ⟨O,hO⟩ := hqt - choose S hmem hcost using exists_subcritical_testSet G hloc p hp - have hOn : O.Nonempty := by - obtain ⟨o,ho,_⟩ := hO (Classical.arbitrary V) - exact ⟨o,ho⟩ - let L := O.sup (fun x => (S x).card) - let a := max 0 (O.sup' hOn (fun x => boundaryCost G hloc (S x) x (p:ℝ))) - refine ⟨L,a,le_max_left _ _,?_,?_⟩ - · apply max_lt zero_lt_one - exact (Finset.sup'_lt_iff hOn).mpr (fun x _ => hcost x) - · intro x - obtain ⟨o,ho,α,β,hαβ,rfl⟩ := hO x - refine ⟨(S o).map α.toEmbedding,?_,?_,?_⟩ - · simp only [Finset.mem_map,Equiv.toEmbedding_apply] - exact ⟨o,hmem o,rfl⟩ - · simpa only [Finset.card_map] using Finset.le_sup (f := fun x => (S x).card) ho - · rw [boundaryCost_aut G hloc hαβ] - exact (Finset.le_sup' (f := fun x => boundaryCost G hloc (S x) x (p:ℝ)) ho).trans - (le_max_right _ _) - -end SharpnessBridge - -section SharpnessSusceptibility -open Filter Topology -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def domainTwoPoint (G : BondGraph V E) (S : Set V) (p : unitInterval) - (x y : V) : ℝ := (law p).real {ω | Conn G (ω ∩ internalEdges G S) x y} - -theorem conn_internal_endpoint (G : BondGraph V E) (S : Set V) {ω : Set E} {x y : V} - (hx : x ∈ S) (h : Conn G (ω ∩ internalEdges G S) x y) : y ∈ S := by - induction h with - | refl => exact hx - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - exact ((mem_internalEdges_of_ends G S e a b heq).mp he.2).2 - -def CutExists (G : BondGraph V E) (S : Set V) (e : E) : Prop := - ∃ a b, G e = s(a,b) ∧ a ∈ S ∧ b ∉ S - -noncomputable def cutInside [Nonempty V] (G : BondGraph V E) (S : Set V) (e : E) : V := - if h : CutExists G S e then h.choose else Classical.arbitrary V - -noncomputable def cutOutside [Nonempty V] (G : BondGraph V E) (S : Set V) (e : E) : V := - if h : CutExists G S e then h.choose_spec.choose else Classical.arbitrary V - -theorem cut_spec [Nonempty V] (G : BondGraph V E) (S : Set V) {e : E} - (he : CutExists G S e) : - G e = s(cutInside G S e,cutOutside G S e) ∧ - cutInside G S e ∈ S ∧ cutOutside G S e ∉ S := by - simpa only [cutInside,cutOutside,dite_eq_left he] using he.choose_spec.choose_spec - -theorem cut_unique [Nonempty V] (G : BondGraph V E) (S : Set V) {e : E} {a b : V} - (he : G e = s(a,b)) (ha : a ∈ S) (hb : b ∉ S) : - a = cutInside G S e ∧ b = cutOutside G S e := by - have hc := cut_spec G S (e := e) ⟨a,b,he,ha,hb⟩ - have hh := Sym2.eq_iff.mp (he.symm.trans hc.1) - rcases hh with ⟨h₁,h₂⟩ | ⟨h₁,h₂⟩ - · exact ⟨h₁,h₂⟩ - · exact (hc.2.2 (h₁ ▸ ha)).elim - -theorem crossingReach_cut [Nonempty V] (G : BondGraph V E) (S : Set V) - (x : V) (ω : Set E) (e : E) : - crossingReach G S x ω e ↔ CutExists G S e ∧ Conn G ω x (cutInside G S e) := by - constructor - · rintro ⟨a,b,he,ha,hb,h⟩ - exact ⟨⟨a,b,he,ha,hb⟩,(cut_unique G S he ha hb).1 ▸ h⟩ - · rintro ⟨he,h⟩ - have hs := cut_spec G S he - exact ⟨_,_,hs.1,hs.2.1,hs.2.2,h⟩ - -theorem crossingReach_upper (G : BondGraph V E) (S : Set V) (x : V) (e : E) : - IsUpperSet {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by - rintro ω η h ⟨a,b,he,ha,hb,hconn⟩ - exact ⟨a,b,he,ha,hb,conn_mono G (Set.inter_subset_inter_left _ h) hconn⟩ - -theorem finiteWitness_crossingReach (G : BondGraph V E) (S : Set V) (x : V) (e : E) : - FiniteWitness {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by - rintro ω ⟨a,b,he,ha,hb,hconn⟩ - obtain ⟨t,ht,hc⟩ := finiteWitness_inter {η | Conn G η x a} (finiteWitness_conn G x a) - (internalEdges G S) ω hconn - exact ⟨t,ht,a,b,he,ha,hb,hc⟩ - - -theorem conn_first_exit [Nonempty V] (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (U : Set E) {ω : Set E} {x y : V} (hx : x ∈ S) - (hxy : Conn G (ω ∩ U) x y) : - y ∈ S ∨ ∃ e ∈ incidentSupport G hloc S, - ω ∈ DisjointOccurrence {η | crossingReach G S x (η ∩ internalEdges G S) e} - (DisjointOccurrence {η | e ∈ η} {η | Conn G (η ∩ U) (cutOutside G S e) y}) := by - obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G hxy - rcases hl.first_outside (internalEdges G S) with hall | - ⟨a,b,e,l₁,l₂,heq,h₁,he,h₂,hfirst,hnot⟩ - · exact Or.inl (conn_internal_endpoint G S hx (hl.conn fun e he => ⟨(ho e he).1,hall e he⟩)) - · subst l - have hnod := List.nodup_append.mp hn - have hen : e ∉ l₂ := (List.nodup_cons.mp hnod.2.1).1 - have ha : a ∈ S := conn_internal_endpoint G S hx - (h₁.conn (ω := ω ∩ internalEdges G S) fun d hd => - ⟨(ho d (List.mem_append_left _ hd)).1,hfirst d hd⟩) - have hb : b ∉ S := fun hb => hnot ((mem_internalEdges_of_ends G S e a b he).mpr ⟨ha,hb⟩) - have hbe := (cut_unique G S he ha hb).2 - refine Or.inr ⟨e,(mem_incidentSupport G hloc S e).mpr ⟨a,ha,by simp [he]⟩, - l₁.toFinset,(e::l₂).toFinset,?_,?_,?_,?_,?_⟩ - · intro d hd - exact (ho d (List.mem_append_left _ (List.mem_toFinset.mp hd))).1 - · intro d hd - exact (ho d (List.mem_append_right _ (List.mem_toFinset.mp hd))).1 - · apply Finset.disjoint_left.mpr - intro d hd hd' - exact hnod.2.2 d (List.mem_toFinset.mp hd) d (List.mem_toFinset.mp hd') rfl - · exact ⟨a,b,he,ha,hb,h₁.conn (fun d hd => ⟨by simpa using hd,hfirst d hd⟩)⟩ - · refine ⟨{e},l₂.toFinset,by simp,by simp,by simpa using hen,by simp,?_⟩ - rw [← hbe] - exact h₂.conn fun d hd => ⟨by simpa using hd, - (ho d (List.mem_append_right _ (List.mem_cons_of_mem e hd))).2⟩ - - -theorem boundaryExpectation_eq_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (x : V) (p : unitInterval) : - boundaryExpectation G S x (incidentSupport G hloc S) (p:ℝ) = - ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by - have hI : (internalSupport G S (incidentSupport G hloc S) : Set E) = internalEdges G S := by - ext e - simp only [Finset.mem_coe,internalSupport,Finset.mem_filter] - exact ⟨And.right,fun he => ⟨internal_edge_mem_incident G hloc S he,he⟩⟩ - unfold boundaryExpectation crossingCount bernoulliPolynomial - simp only [Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro e _ - change finiteEventPolynomial (internalSupport G S (incidentSupport G hloc S)) - {ω | crossingReach G S x ω e} (p:ℝ) = _ - rw [finiteEventPolynomial_restrict,hI] - rfl - - -theorem domainTwoPoint_first_exit [Countable E] [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (S : Finset V) (Λ : Set V) (p : unitInterval) - (x y : V) (hx : x ∈ S) : - domainTwoPoint G Λ p x y ≤ (if y ∈ S then (1:ℝ) else 0) + - ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * - (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y := by - by_cases hy : y ∈ S - · have hnon : 0 ≤ ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * - (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y := by - apply Finset.sum_nonneg - intro e _ - exact mul_nonneg (mul_nonneg (measureReal_nonneg) p.2.1) measureReal_nonneg - simpa only [ite_eq_left hy,domainTwoPoint] using (measureReal_le_one (μ := law p) - (s := {ω | Conn G (ω ∩ internalEdges G Λ) x y})).trans (le_add_of_nonneg_right hnon) - · simp only [ite_eq_right hy,zero_add] - let A := fun e => {ω | crossingReach G S x (ω ∩ internalEdges G S) e} - let B := fun e => {ω | Conn G (ω ∩ internalEdges G Λ) (cutOutside G S e) y} - let F := incidentSupport G hloc S - let C := fun e => DisjointOccurrence (A e) (DisjointOccurrence {ω | e ∈ ω} (B e)) - have hsub : {ω | Conn G (ω ∩ internalEdges G Λ) x y} ⊆ ⋃ e ∈ F, C e := by - intro ω hω - rcases conn_first_exit G hloc S (internalEdges G Λ) hx hω with h | ⟨e,he,h⟩ - · exact (hy h).elim - · exact Set.mem_iUnion.mpr ⟨e,Set.mem_iUnion.mpr ⟨he,h⟩⟩ - calc - domainTwoPoint G Λ p x y ≤ (law p).real (⋃ e ∈ F, C e) := measureReal_mono (μ := law p) hsub (measure_ne_top _ _) - _ ≤ ∑ e ∈ F, (law p).real (C e) := measureReal_biUnion_finset_le _ _ - _ ≤ _ := by - apply Finset.sum_le_sum - intro e _ - have hB : IsUpperSet (B e) := fun _ _ h hc => - conn_mono G (Set.inter_subset_inter_left _ h) hc - have hfB : FiniteWitness (B e) := finiteWitness_inter _ - (finiteWitness_conn G _ _) (internalEdges G Λ) - have hb := bk p (A e) (DisjointOccurrence {ω | e ∈ ω} (B e)) - (crossingReach_upper G S x e) (disjointOccurrence_upper _ _) - (finiteWitness_crossingReach G S x e) (finiteWitness_disjointOccurrence _ _) - have hb' := bk p {ω | e ∈ ω} (B e) (fun _ _ h he => h he) hB (finiteWitness_edge e) hfB - have heq : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by - simpa using finite_open_probability p {e} - rw [heq] at hb' - calc - (law p).real (C e) ≤ (law p).real (A e) * (law p).real - (DisjointOccurrence {ω | e ∈ ω} (B e)) := hb - _ ≤ (law p).real (A e) * ((p:ℝ) * (law p).real (B e)) := - mul_le_mul_of_nonneg_left hb' measureReal_nonneg - _ = _ := (mul_assoc _ _ _).symm - -theorem conn_internal_eq_or_mem (G : BondGraph V E) (S : Set V) {ω : Set E} {x y : V} - (h : Conn G (ω ∩ internalEdges G S) x y) : x = y ∨ x ∈ S ∧ y ∈ S := by - induction h with - | refl => exact Or.inl rfl - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - have he' := (mem_internalEdges_of_ends G S e a b heq).mp he.2 - right - exact ⟨ih.elim (fun h => h.symm ▸ he'.1) And.left,he'.2⟩ - -theorem domainTwoPoint_zero_of_outside (G : BondGraph V E) (S : Set V) (p : unitInterval) - {x y : V} (hx : x ∉ S) (hy : y ∈ S) : domainTwoPoint G S p x y = 0 := by - have he : {ω | Conn G (ω ∩ internalEdges G S) x y} = ∅ := by - apply Set.eq_empty_iff_forall_notMem.mpr - intro ω h - rcases conn_internal_eq_or_mem G S h with rfl | h - · exact hx hy - · exact hx h.1 - simp only [domainTwoPoint,he,measureReal_empty] - -theorem domainRow_le_boundaryCost [Countable E] [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (S Λ : Finset V) (p : unitInterval) (x : V) (hx : x ∈ S) - (H : ℝ) (hH : ∀ z, ∑ y ∈ Λ, domainTwoPoint G Λ p z y ≤ H) : - (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ S.card + boundaryCost G hloc S x (p:ℝ) * H := by - have hind : (∑ y ∈ Λ, if y ∈ S then (1:ℝ) else 0) ≤ (S.card:ℝ) := by - simp only [← Finset.sum_filter] - simpa using (Nat.cast_le (α := ℝ)).mpr (Finset.card_le_card - (show Λ.filter (fun y => y ∈ S) ⊆ S from fun y hy => (Finset.mem_filter.mp hy).2)) - calc - (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ - ∑ y ∈ Λ, ((if y ∈ S then (1:ℝ) else 0) + - ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * - (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y) := - Finset.sum_le_sum fun y _ => domainTwoPoint_first_exit G hloc S Λ p x y hx - _ = (∑ y ∈ Λ, if y ∈ S then (1:ℝ) else 0) + - ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * - (p:ℝ) * ∑ y ∈ Λ, domainTwoPoint G Λ p (cutOutside G S e) y := by - rw [Finset.sum_add_distrib,Finset.sum_comm] - simp only [← Finset.mul_sum] - _ ≤ S.card + ∑ e ∈ incidentSupport G hloc S, - (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * (p:ℝ) * H := by - apply add_le_add hind - apply Finset.sum_le_sum - intro e _ - exact mul_le_mul_of_nonneg_left (hH _) (mul_nonneg measureReal_nonneg p.2.1) - _ = S.card + boundaryCost G hloc S x (p:ℝ) * H := by - unfold boundaryCost - rw [boundaryExpectation_eq_sum] - simp only [← Finset.sum_mul] - ring - -theorem domainRow_uniform_bound [Countable E] [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (p : unitInterval) (L : ℕ) (a : ℝ) (ha : a < 1) - (htest : ∀ x, ∃ S : Finset V, x ∈ S ∧ S.card ≤ L ∧ boundaryCost G hloc S x (p:ℝ) ≤ a) - (Λ : Finset V) (x : V) : - (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ (L:ℝ)/(1-a) := by - by_cases hΛ : Λ.Nonempty - · let row := fun z => ∑ y ∈ Λ, domainTwoPoint G Λ p z y - obtain ⟨z,hz,hmax⟩ := Λ.exists_max_image row hΛ - have hnon : 0 ≤ row z := Finset.sum_nonneg (fun _ _ => measureReal_nonneg) - have hH : ∀ w, row w ≤ row z := by - intro w - by_cases hw : w ∈ Λ - · exact hmax w hw - · have he : row w = 0 := by - apply Finset.sum_eq_zero - intro y hy - exact domainTwoPoint_zero_of_outside G Λ p hw hy - rwa [he] - obtain ⟨S,hS,hcard,hcost⟩ := htest z - have h := domainRow_le_boundaryCost G hloc S Λ p z hS (row z) hH - have hL : (S.card:ℝ) ≤ (L:ℝ) := Nat.cast_le.mpr hcard - have hc := mul_le_mul_of_nonneg_right hcost hnon - have hrow : row z ≤ (L:ℝ)/(1-a) := (le_div_iff₀ (sub_pos.mpr ha)).mpr (by nlinarith) - exact (hH x).trans hrow - · simp only [Finset.not_nonempty_iff_eq_empty.mp hΛ,Finset.sum_empty] - exact div_nonneg (Nat.cast_nonneg _) (sub_pos.mpr ha).le - -theorem internalEdges_mono (G : BondGraph V E) {S T : Set V} (h : S ⊆ T) : - internalEdges G S ⊆ internalEdges G T := fun _ he x hx => h (he x hx) - -theorem exists_internal_vertexExhaustion [Encodable V] (G : BondGraph V E) (e : E) : - ∃ n, e ∈ internalEdges G (vertexExhaustion (V := V) n : Set V) := by - obtain ⟨⟨a,b⟩,hab⟩ := Sym2.mk_surjective (G e) - obtain ⟨n,hn⟩ := subset_vertexExhaustion ({a,b} : Finset V) - refine ⟨n,?_⟩ - rw [mem_internalEdges_of_ends G _ e a b hab.symm] - exact ⟨hn (by simp),hn (by simp)⟩ - -theorem conn_domain_exhaustion [Encodable V] (G : BondGraph V E) {ω : Set E} {x y : V} - (h : Conn G ω x y) : - ∃ n, Conn G (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y := by - induction h with - | refl => exact ⟨0,conn_refl _ _ _⟩ - | @tail a b hxa hab ih => - obtain ⟨n,hn⟩ := ih - obtain ⟨e,he,heq⟩ := hab - obtain ⟨m,hm⟩ := exists_internal_vertexExhaustion G e - refine ⟨max n m,?_⟩ - have hnm := internalEdges_mono G (show (vertexExhaustion (V := V) n : Set V) ⊆ - (vertexExhaustion (V := V) (max n m) : Set V) from vertexExhaustion_mono (le_max_left n m)) - have hmm := internalEdges_mono G (show (vertexExhaustion (V := V) m : Set V) ⊆ - (vertexExhaustion (V := V) (max n m) : Set V) from vertexExhaustion_mono (le_max_right n m)) - exact (conn_mono G (Set.inter_subset_inter_right _ hnm) hn).tail ⟨e,⟨he,hmm hm⟩,heq⟩ - -theorem tendsto_domainTwoPoint [Encodable V] (G : BondGraph V E) (p : unitInterval) (x y : V) : - Tendsto (fun n => domainTwoPoint G (vertexExhaustion (V := V) n : Set V) p x y) - atTop (𝓝 (twoPoint G p x y)) := by - have hm : Monotone (fun n => {ω | Conn G - (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y}) := by - intro m n h ω hc - exact conn_mono G (Set.inter_subset_inter_right _ (internalEdges_mono G - (show (vertexExhaustion (V := V) m : Set V) ⊆ (vertexExhaustion (V := V) n : Set V) from - vertexExhaustion_mono h))) hc - have he : (⋃ n, {ω | Conn G (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y}) = - {ω | Conn G ω x y} := by - ext ω - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] - exact ⟨fun ⟨n,h⟩ => conn_mono G Set.inter_subset_left h,conn_domain_exhaustion G⟩ - have h := tendsto_measure_iUnion_atTop (μ := law p) hm - rw [he] at h - exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h - - -theorem subcritical_row_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : - ∃ C : ℝ, 0 ≤ C ∧ ∀ x (F : Finset V), ∑ y ∈ F, twoPoint G p x y ≤ C := by - let : Encodable V := Encodable.ofCountable V - obtain ⟨L,a,_,ha,htest⟩ := exists_uniform_subcritical_testSets G hloc hqt p hp - refine ⟨(L:ℝ)/(1-a),div_nonneg (Nat.cast_nonneg _) (sub_pos.mpr ha).le,?_⟩ - intro x F - apply le_of_tendsto (tendsto_finsetSum F (fun y _ => tendsto_domainTwoPoint G p x y)) - obtain ⟨N,hN⟩ := subset_vertexExhaustion F - filter_upwards [eventually_ge_atTop N] with n hn - have hFn : F ⊆ vertexExhaustion n := hN.trans (vertexExhaustion_mono hn) - exact (Finset.sum_le_sum_of_subset_of_nonneg hFn (fun _ _ _ => measureReal_nonneg)).trans - (domainRow_uniform_bound G hloc p L a ha htest (vertexExhaustion n) x) - - -theorem operatorBounded_of_lt_pc [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : OperatorBounded G p := by - obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp - obtain ⟨A,_,hA⟩ := exists_operator_of_row_column_bound (twoPoint G p) C hC - (twoPoint_nonneg G p) hrow (fun y F => by - simpa only [twoPoint_symm G p] using hrow y F) - exact ⟨A,hA⟩ - -end SharpnessSusceptibility - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Sprinkling + +namespace OAI + +/-! Finite Russo formulae, exterior exposure and subcritical sharpness. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteRusso +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + + +noncomputable def bernoulliPolynomial (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : ℝ := + ∑ t ∈ s.powerset, f t * p ^ t.card * (1-p) ^ (s.card-t.card) + +@[simp] theorem bernoulliPolynomial_empty (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial ∅ f p = f ∅ := by simp [bernoulliPolynomial] + +theorem bernoulliPolynomial_congr (s : Finset E) {f g : Finset E → ℝ} + (h : ∀ t ⊆ s, f t = g t) (p : ℝ) : + bernoulliPolynomial s f p = bernoulliPolynomial s g p := by + apply Finset.sum_congr rfl + intro t ht + rw [h t (Finset.mem_powerset.mp ht)] + +theorem bernoulliPolynomial_sub (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial s (fun t => f t-g t) p = + bernoulliPolynomial s f p - bernoulliPolynomial s g p := by + simp only [bernoulliPolynomial, sub_mul, Finset.sum_sub_distrib] + +theorem bernoulliPolynomial_insert (s : Finset E) (e : E) (he : e ∉ s) + (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial (insert e s) f p = + (1-p)*bernoulliPolynomial s f p + p*bernoulliPolynomial s (fun t => f (insert e t)) p := by + have hd : Disjoint s.powerset (s.powerset.image (insert e)) := by + apply Finset.disjoint_left.mpr + intro t ht himg + obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp himg + exact he ((Finset.mem_powerset.mp ht) (by simp)) + have hinj : Set.InjOn (insert e) (↑s.powerset : Set (Finset E)) := by + intro t ht r hr h + have ht' : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) + have hr' : e ∉ r := fun h => he (Finset.mem_powerset.mp hr h) + have hh := congrArg (fun t : Finset E => t.erase e) h + simpa [ht', hr'] using hh + simp only [bernoulliPolynomial, Finset.powerset_insert, Finset.sum_union hd, + Finset.sum_image hinj, Finset.mul_sum, Finset.card_insert_of_notMem he] + congr 1 + · apply Finset.sum_congr rfl + intro t ht + have hcard := Finset.card_le_card (Finset.mem_powerset.mp ht) + have hexp : s.card+1-t.card = (s.card-t.card)+1 := by omega + rw [hexp, pow_succ] + ring + · apply Finset.sum_congr rfl + intro t ht + have het : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) + simp only [Finset.card_insert_of_notMem het, Nat.add_sub_add_right, pow_succ] + ring + + +theorem hasDerivAt_bernoulliPolynomial (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : + HasDerivAt (bernoulliPolynomial s f) + (∑ e ∈ s, bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p) p := by + induction s using Finset.induction_on generalizing f with + | empty => + convert hasDerivAt_const p (f ∅) using 1 <;> try rfl + · funext q + exact bernoulliPolynomial_empty f q + | @insert e s he ih => + have hd := (((hasDerivAt_const p 1).sub (hasDerivAt_id p)).mul (ih f)).add + ((hasDerivAt_id p).mul (ih (fun t => f (insert e t)))) + have hf : bernoulliPolynomial (insert e s) f = + fun q => (1-q)*bernoulliPolynomial s f q + + q*bernoulliPolynomial s (fun t => f (insert e t)) q := + funext fun q => bernoulliPolynomial_insert s e he f q + rw [hf] + convert hd using 1 <;> try rfl + have hs : ∑ a ∈ s, bernoulliPolynomial ((insert e s).erase a) + (fun t => f (insert a t)-f t) p = + (1-p)*(∑ a ∈ s, bernoulliPolynomial (s.erase a) (fun t => f (insert a t)-f t) p) + + p*(∑ a ∈ s, bernoulliPolynomial (s.erase a) + (fun t => f (insert e (insert a t))-f (insert e t)) p) := by + simp only [Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro a ha + have hae : e ≠ a := (ne_of_mem_of_not_mem ha he).symm + rw [Finset.erase_insert_of_ne hae, bernoulliPolynomial_insert _ e + (fun hh => he (Finset.mem_of_mem_erase hh))] + congr 2 + apply bernoulliPolynomial_congr + intro t _ + rw [Finset.insert_comm e a] + simp only [Finset.sum_insert he, Finset.erase_insert he, zero_sub, neg_one_mul, + one_mul, Pi.sub_apply, id_eq] + rw [hs, bernoulliPolynomial_sub] + ring + +@[simp] theorem bernoulliPolynomial_zero (s : Finset E) (p : ℝ) : + bernoulliPolynomial s (fun _ => 0) p = 0 := by simp [bernoulliPolynomial] + +theorem bernoulliPolynomial_const (s : Finset E) (c p : ℝ) : + bernoulliPolynomial s (fun _ => c) p = c := by + induction s using Finset.induction_on with + | empty => simp + | @insert e s he ih => rw [bernoulliPolynomial_insert s e he]; simp only [ih]; ring + +theorem bernoulliPolynomial_nonneg (s : Finset E) (f : Finset E → ℝ) (p : ℝ) + (hp : p ∈ Set.Icc (0:ℝ) 1) (hf : ∀ t ⊆ s, 0 ≤ f t) : + 0 ≤ bernoulliPolynomial s f p := by + apply Finset.sum_nonneg + intro t ht + exact mul_nonneg (mul_nonneg (hf t (Finset.mem_powerset.mp ht)) + (pow_nonneg hp.1 _)) (pow_nonneg (sub_nonneg.mpr hp.2) _) + +theorem bernoulliPolynomial_mono (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) + (hp : p ∈ Set.Icc (0:ℝ) 1) (hfg : ∀ t ⊆ s, f t ≤ g t) : + bernoulliPolynomial s f p ≤ bernoulliPolynomial s g p := by + apply Finset.sum_le_sum + intro t ht + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (hfg t (Finset.mem_powerset.mp ht)) (pow_nonneg hp.1 _)) + (pow_nonneg (sub_nonneg.mpr hp.2) _) + + +theorem bernoulliPolynomial_union (s t : Finset E) (hdis : Disjoint s t) + (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial (s ∪ t) f p = + bernoulliPolynomial s (fun a => bernoulliPolynomial t (fun b => f (a ∪ b)) p) p := by + induction s using Finset.induction_on generalizing f with + | empty => simp + | @insert e s he ih => + have hed : e ∉ t := (Finset.disjoint_insert_left.mp hdis).1 + have hst : Disjoint s t := (Finset.disjoint_insert_left.mp hdis).2 + rw [Finset.insert_union, bernoulliPolynomial_insert _ e (by simp [he, hed]), + bernoulliPolynomial_insert s e he, ih hst, ih hst] + congr 2 + apply bernoulliPolynomial_congr + intro a _ + apply bernoulliPolynomial_congr + intro b _ + rw [Finset.insert_union] + + + +theorem bernoulliPolynomial_closed_difference (s : Finset E) (e : E) (he : e ∈ s) + (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial s (fun t => if e ∈ t then 0 else f (insert e t)-f t) p = + (1-p)*bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by + have hes : e ∉ s.erase e := Finset.notMem_erase e s + conv_lhs => rw [← Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e hes] + have hc : bernoulliPolynomial (s.erase e) + (fun t => if e ∈ t then 0 else f (insert e t)-f t) p = + bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by + apply bernoulliPolynomial_congr + intro t ht + simp [show e ∉ t from fun h => hes (ht h)] + rw [hc] + simp + +theorem closed_difference_russo (s : Finset E) (f : Finset E → ℝ) (p : ℝ) : + (1-p)*deriv (bernoulliPolynomial s f) p = + ∑ e ∈ s, bernoulliPolynomial s + (fun t => if e ∈ t then 0 else f (insert e t)-f t) p := by + rw [(hasDerivAt_bernoulliPolynomial s f p).deriv, Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + exact (bernoulliPolynomial_closed_difference s e he f p).symm + + +noncomputable def finiteEventPolynomial (s : Finset E) (A : Set (Set E)) (p : ℝ) : ℝ := + bernoulliPolynomial s (fun t => if (t : Set E) ∈ A then 1 else 0) p + +theorem finiteEventPolynomial_eq (s : Finset E) (A : Set (Set E)) (p : unitInterval) : + finiteEventPolynomial s A (p : ℝ) = finiteProbability p s A := by + unfold finiteEventPolynomial bernoulliPolynomial finiteProbability + apply Finset.sum_congr rfl + intro t _ + by_cases ht : (t : Set E) ∈ A <;> simp [ht] + + +def closedPivotal (A : Set (Set E)) (e : E) : Set (Set E) := + {ω | e ∉ ω ∧ ω ∉ A ∧ insert e ω ∈ A} + +theorem closedPivotal_difference (A : Set (Set E)) (hA : IsUpperSet A) (e : E) + (t : Finset E) : + (if (t : Set E) ∈ closedPivotal A e then (1:ℝ) else 0) = + (if e ∈ t then 0 else + (if ((insert e t : Finset E) : Set E) ∈ A then (1:ℝ) else 0) - + (if (t : Set E) ∈ A then 1 else 0)) := by + by_cases he : e ∈ t + · simp [closedPivotal, he] + · by_cases ha : (t : Set E) ∈ A + · have hi : insert e (t : Set E) ∈ A := hA (Set.subset_insert e _) ha + simp [closedPivotal, he, ha, hi] + · by_cases hi : insert e (t : Set E) ∈ A <;> simp [closedPivotal, he, ha, hi] + + +theorem finite_russo_closed (s : Finset E) (A : Set (Set E)) (hA : IsUpperSet A) + (p : unitInterval) : + (1-(p:ℝ))*deriv (finiteEventPolynomial s A) (p:ℝ) = + ∑ e ∈ s, finiteProbability p s (closedPivotal A e) := by + rw [show finiteEventPolynomial s A = + bernoulliPolynomial s (fun t => if (t : Set E) ∈ A then 1 else 0) from rfl, + closed_difference_russo] + apply Finset.sum_congr rfl + intro e _ + rw [← finiteEventPolynomial_eq] + apply bernoulliPolynomial_congr + intro t _ + exact (closedPivotal_difference A hA e t).symm + + + +theorem finite_russo_closed_law [Fintype E] (A : Set (Set E)) (hA : IsUpperSet A) + (p : unitInterval) : + (1-(p:ℝ))*deriv (finiteEventPolynomial Finset.univ A) (p:ℝ) = + ∑ e : E, (law p).real (closedPivotal A e) := by + simpa only [finiteProbability_univ] using finite_russo_closed Finset.univ A hA p + +end FiniteRusso + +section ExteriorExposure +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + + +theorem conn_insert_iff (G : BondGraph V E) (ω : Set E) (e : E) (a b x y : V) + (he : G e = s(a,b)) : + Conn G (insert e ω) x y ↔ Conn G ω x y ∨ + (Conn G ω x a ∧ Conn G ω b y) ∨ (Conn G ω x b ∧ Conn G ω a y) := by + constructor + · intro hh + induction hh with + | refl => exact Or.inl (conn_refl G ω x) + | @tail u v huv huv' ih => + obtain ⟨f,hf,hfuv⟩ := huv' + rcases Set.mem_insert_iff.mp hf with rfl | hf + · have hp : s(a,b) = s(u,v) := he.symm.trans hfuv + rcases Sym2.eq_iff.mp hp with ⟨rfl,rfl⟩ | ⟨rfl,rfl⟩ + · rcases ih with h | ⟨hxa,hba⟩ | ⟨hxb,haa⟩ + · exact Or.inr (Or.inl ⟨h,conn_refl G ω b⟩) + · exact Or.inr (Or.inl ⟨hxa,conn_refl G ω b⟩) + · exact Or.inl hxb + · rcases ih with h | ⟨hxa,hbb⟩ | ⟨hxb,hab⟩ + · exact Or.inr (Or.inr ⟨h,conn_refl G ω a⟩) + · exact Or.inl hxa + · exact Or.inr (Or.inr ⟨hxb,conn_refl G ω a⟩) + · have huvω : Conn G ω u v := .single ⟨f,hf,hfuv⟩ + rcases ih with h | ⟨hxa,hbu⟩ | ⟨hxb,hau⟩ + · exact Or.inl (h.trans huvω) + · exact Or.inr (Or.inl ⟨hxa,hbu.trans huvω⟩) + · exact Or.inr (Or.inr ⟨hxb,hau.trans huvω⟩) + · intro hh + have hm : ω ⊆ insert e ω := Set.subset_insert e ω + have hab : Conn G (insert e ω) a b := .single ⟨e,Set.mem_insert e ω,he⟩ + rcases hh with h | ⟨hxa,hby⟩ | ⟨hxb,hay⟩ + · exact conn_mono G hm h + · exact (conn_mono G hm hxa).trans (hab.trans (conn_mono G hm hby)) + · exact (conn_mono G hm hxb).trans ((conn_symm G _ hab).trans (conn_mono G hm hay)) + + +def internalEdges (G : BondGraph V E) (S : Set V) : Set E := + {e | ∀ x ∈ G e, x ∈ S} + +@[simp] theorem mem_internalEdges_of_ends (G : BondGraph V E) (S : Set V) + (e : E) (a b : V) (he : G e = s(a,b)) : + e ∈ internalEdges G S ↔ a ∈ S ∧ b ∈ S := by + simp [internalEdges, he] + + +def unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) : Set V := + {x | ∀ y, Conn G ω x y → y ∈ Λ} + +theorem unexposed_subset (G : BondGraph V E) (Λ : Set V) (ω : Set E) : + unexposed G Λ ω ⊆ Λ := fun x hx => hx x (conn_refl G ω x) + +theorem mem_unexposed_of_conn (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {x y : V} (hx : x ∈ unexposed G Λ ω) (hxy : Conn G ω x y) : + y ∈ unexposed G Λ ω := by + intro z hyz + exact hx z (hxy.trans hyz) + + +theorem conn_restrict_unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {x y : V} (hx : x ∈ unexposed G Λ ω) (hxy : Conn G ω x y) : + Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x y := by + induction hxy with + | refl => exact conn_refl _ _ _ + | @tail y z hxy hyz ih => + obtain ⟨e,he,hends⟩ := hyz + have hy : y ∈ unexposed G Λ ω := mem_unexposed_of_conn G Λ ω hx hxy + have hz : z ∈ unexposed G Λ ω := mem_unexposed_of_conn G Λ ω hy (.single ⟨e,he,hends⟩) + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e y z hends).mpr ⟨hy,hz⟩⟩,hends⟩ + + +theorem unexposed_boundary_closed (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {e : E} {a b : V} (he : G e = s(a,b)) + (ha : a ∈ unexposed G Λ ω) (hb : b ∉ unexposed G Λ ω) : e ∉ ω := by + intro ho + exact hb (mem_unexposed_of_conn G Λ ω ha (.single ⟨e,ho,he⟩)) + + + +theorem unexposed_insert_crossing (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {e : E} {a b x : V} (he : G e = s(a,b)) + (hx : x ∈ unexposed G Λ ω) (_ha : a ∈ unexposed G Λ ω) + (hb : b ∉ unexposed G Λ ω) : + x ∉ unexposed G Λ (insert e ω) ↔ + Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x a := by + classical + constructor + · intro hn + obtain ⟨y,hxy,hy⟩ := by simpa [unexposed, not_forall, Classical.not_imp] using hn + rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | h | h + · exact (hy (hx y h)).elim + · exact conn_restrict_unexposed G Λ ω hx h.1 + · exact (hb (mem_unexposed_of_conn G Λ ω hx h.1)).elim + · intro hxa hn + have hxa' : Conn G ω x a := conn_mono G Set.inter_subset_left hxa + apply hb + intro y hby + exact hn y ((conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨hxa',hby⟩))) + + +theorem not_mem_unexposed_of_conn (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {x y : V} (hx : x ∉ unexposed G Λ ω) (hxy : Conn G ω x y) : + y ∉ unexposed G Λ ω := by + intro hy + exact hx (mem_unexposed_of_conn G Λ ω hy (conn_symm G ω hxy)) + + +theorem conn_sdiff_internal_unexposed (G : BondGraph V E) (Λ : Set V) (ω : Set E) + {x y : V} (hx : x ∉ unexposed G Λ ω) (hxy : Conn G ω x y) : + Conn G (ω \ internalEdges G (unexposed G Λ ω)) x y := by + induction hxy with + | refl => exact conn_refl _ _ _ + | @tail y z hxy hyz ih => + obtain ⟨e,he,hends⟩ := hyz + have hy : y ∉ unexposed G Λ ω := not_mem_unexposed_of_conn G Λ ω hx hxy + exact ih.tail ⟨e,⟨he,fun hi => hy ((mem_internalEdges_of_ends G _ e y z hends).mp hi).1⟩,hends⟩ + + +theorem unexposed_sdiff_internal (G : BondGraph V E) (Λ : Set V) (ω : Set E) : + unexposed G Λ (ω \ internalEdges G (unexposed G Λ ω)) = unexposed G Λ ω := by + ext x + constructor + · intro hx + by_contra hn + apply hn + intro y hxy + exact hx y (conn_sdiff_internal_unexposed G Λ ω hn hxy) + · intro hx y hxy + exact hx y (conn_mono G Set.sdiff_subset hxy) + + +theorem unexposed_union_internal (G : BondGraph V E) (Λ : Set V) (ω η : Set E) + (hη : η ⊆ internalEdges G (unexposed G Λ ω)) : + unexposed G Λ (ω ∪ η) = unexposed G Λ ω := by + ext x + constructor + · intro hx y hxy + exact hx y (conn_mono G Set.subset_union_left hxy) + · intro hx y hxy + suffices hy : y ∈ unexposed G Λ ω from unexposed_subset G Λ ω hy + induction hxy with + | refl => exact hx + | @tail y z hxy hyz ih => + obtain ⟨e,hωe,he⟩ := hyz + rcases hωe with ho | hηe + · exact mem_unexposed_of_conn G Λ ω ih (.single ⟨e,ho,he⟩) + · exact ((mem_internalEdges_of_ends G _ e y z he).mp (hη hηe)).2 + + +theorem unexposed_union_eq_iff (G : BondGraph V E) (Λ S : Set V) (a b : Set E) + (ha : a ⊆ internalEdges G S) (hb : Disjoint b (internalEdges G S)) : + unexposed G Λ (a ∪ b) = S ↔ unexposed G Λ b = S := by + constructor + · intro h + have he : (a ∪ b) \ internalEdges G S = b := by + ext e + constructor + · rintro ⟨he,hn⟩ + exact he.resolve_left (fun he => hn (ha he)) + · intro he + exact ⟨Or.inr he,fun hi => Set.disjoint_left.mp hb he hi⟩ + simpa only [h, he] using unexposed_sdiff_internal G Λ (a ∪ b) + · intro h + have he := unexposed_union_internal G Λ b a (h ▸ ha) + simpa only [Set.union_comm b a,h] using he + + +def escapeEvent (G : BondGraph V E) (Λ : Set V) (x : V) : Set (Set E) := + {ω | x ∉ unexposed G Λ ω} + +theorem escapeEvent_isUpperSet (G : BondGraph V E) (Λ : Set V) (x : V) : + IsUpperSet (escapeEvent G Λ x) := by + intro ω η hωη hx hη + apply hx + intro y hxy + exact hη y (conn_mono G hωη hxy) + + +theorem escape_closed_pivotal_iff (G : BondGraph V E) (Λ : Set V) + (ω : Set E) (x : V) (e : E) : + (e ∉ ω ∧ ω ∉ escapeEvent G Λ x ∧ insert e ω ∈ escapeEvent G Λ x) ↔ + x ∈ unexposed G Λ ω ∧ ∃ a b, + G e = s(a,b) ∧ a ∈ unexposed G Λ ω ∧ b ∉ unexposed G Λ ω ∧ + Conn G (ω ∩ internalEdges G (unexposed G Λ ω)) x a := by + classical + constructor + · rintro ⟨_,hx,hn⟩ + have hx' : x ∈ unexposed G Λ ω := by simpa [escapeEvent] using hx + refine ⟨hx',?_⟩ + obtain ⟨⟨a,b⟩,he'⟩ := Sym2.mk_surjective (G e) + have he : G e = s(a,b) := he'.symm + obtain ⟨y,hxy,hy⟩ := by simpa [escapeEvent,unexposed,not_forall,Classical.not_imp] using hn + rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | h | h + · exact (hy (hx' y h)).elim + · exact ⟨a,b,he,mem_unexposed_of_conn G Λ ω hx' h.1, + fun hb => hy (hb y h.2),conn_restrict_unexposed G Λ ω hx' h.1⟩ + · exact ⟨b,a,he.trans (Sym2.eq_swap ..),mem_unexposed_of_conn G Λ ω hx' h.1, + fun ha => hy (ha y h.2),conn_restrict_unexposed G Λ ω hx' h.1⟩ + · rintro ⟨hx,a,b,he,ha,hb,hxa⟩ + exact ⟨unexposed_boundary_closed G Λ ω he ha hb,by simpa [escapeEvent] using hx, + (unexposed_insert_crossing G Λ ω he hx ha hb).mpr hxa⟩ + +attribute [local instance] Classical.decEq + + theorem bernoulliPolynomial_add (s : Finset E) (f g : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial s (fun t => f t+g t) p = + bernoulliPolynomial s f p + bernoulliPolynomial s g p := by + simp only [bernoulliPolynomial, add_mul, Finset.sum_add_distrib] + + theorem bernoulliPolynomial_mul_const (s : Finset E) (f : Finset E → ℝ) (c p : ℝ) : + bernoulliPolynomial s (fun t => f t*c) p = bernoulliPolynomial s f p*c := by + simp only [bernoulliPolynomial, Finset.sum_mul] + apply Finset.sum_congr rfl + intro t _ + ring + + theorem bernoulliPolynomial_const_mul (s : Finset E) (f : Finset E → ℝ) (c p : ℝ) : + bernoulliPolynomial s (fun t => c*f t) p = c*bernoulliPolynomial s f p := by + simpa only [mul_comm c] using bernoulliPolynomial_mul_const s f c p + + theorem bernoulliPolynomial_sum {ι : Type*} (s : Finset E) (I : Finset ι) + (f : ι → Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial s (fun t => ∑ i ∈ I, f i t) p = + ∑ i ∈ I, bernoulliPolynomial s (f i) p := by + classical + simp only [bernoulliPolynomial, Finset.sum_mul] + exact Finset.sum_comm + + +theorem bernoulliPolynomial_blocks (s t : Finset E) (hdis : Disjoint s t) + (f g : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial (s ∪ t) (fun a => f (a ∩ s)*g (a ∩ t)) p = + bernoulliPolynomial s f p * bernoulliPolynomial t g p := by + rw [bernoulliPolynomial_union s t hdis] + trans bernoulliPolynomial s (fun a => f a*bernoulliPolynomial t g p) p + · apply bernoulliPolynomial_congr + intro a ha + rw [← bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro b hb + have has : a ∩ s = a := Finset.inter_eq_left.mpr ha + have hbt : b ∩ t = b := Finset.inter_eq_left.mpr hb + have hbs : b ∩ s = ∅ := Finset.disjoint_iff_inter_eq_empty.mp + (hdis.symm.mono_left hb) + have hat : a ∩ t = ∅ := Finset.disjoint_iff_inter_eq_empty.mp + (hdis.mono_left ha) + simp [Finset.union_inter_distrib_right,has,hbt,hbs,hat] + · exact bernoulliPolynomial_mul_const s f _ p + + + +theorem bernoulliPolynomial_exposure (G : BondGraph V E) (Λ S : Set V) + (s t : Finset E) (hs : (s : Set E) ⊆ internalEdges G S) + (ht : Disjoint (t : Set E) (internalEdges G S)) (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial (s ∪ t) + (fun a => (if unexposed G Λ (a : Set E) = S then (1:ℝ) else 0) * f (a ∩ s)) p = + bernoulliPolynomial t (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p * + bernoulliPolynomial s f p := by + have hdis : Disjoint s t := by + apply Finset.disjoint_left.mpr + intro e he hf + exact Set.disjoint_left.mp ht hf (hs he) + rw [bernoulliPolynomial_union s t hdis] + trans bernoulliPolynomial s (fun a => + bernoulliPolynomial t (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p * f a) p + · apply bernoulliPolynomial_congr + intro a ha + rw [← bernoulliPolynomial_mul_const] + apply bernoulliPolynomial_congr + intro b hb + have hab : unexposed G Λ ((a ∪ b : Finset E) : Set E) = S ↔ + unexposed G Λ (b : Set E) = S := by + rw [Finset.coe_union] + exact unexposed_union_eq_iff G Λ S _ _ (fun _ he => hs (ha he)) + (ht.mono_left (by exact_mod_cast hb)) + have hbs : b ∩ s = ∅ := + Finset.disjoint_iff_inter_eq_empty.mp (hdis.symm.mono_left hb) + rw [Finset.union_inter_distrib_right,Finset.inter_eq_left.mpr ha,hbs,Finset.union_empty] + simp only [hab] + · exact bernoulliPolynomial_const_mul s f _ p + + +noncomputable def unexposedRegion (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : Finset V := + ((Set.toFinite (Λ : Set V)).subset (unexposed_subset G (Λ : Set V) ω)).toFinset + +@[simp] theorem coe_unexposedRegion (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : + (unexposedRegion G Λ ω : Set V) = unexposed G (Λ : Set V) ω := by + simp [unexposedRegion] + +theorem unexposedRegion_subset (G : BondGraph V E) (Λ : Finset V) (ω : Set E) : + unexposedRegion G Λ ω ⊆ Λ := by + intro x hx + apply unexposed_subset G (Λ : Set V) ω + simpa only [← coe_unexposedRegion,Finset.mem_coe] using hx + + +theorem bernoulliPolynomial_partition_region (G : BondGraph V E) (Λ : Finset V) + (F : Finset E) (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial F f p = ∑ S ∈ Λ.powerset, + bernoulliPolynomial F + (fun t => if unexposed G (Λ : Set V) (t : Set E) = (S : Set V) then f t else 0) p := by + rw [← bernoulliPolynomial_sum] + apply bernoulliPolynomial_congr + intro t _ + symm + rw [Finset.sum_eq_single (unexposedRegion G Λ (t : Set E))] + · simp + · intro S _ hne + have hh : unexposed G (Λ : Set V) (t : Set E) ≠ (S : Set V) := by + intro he + apply hne + apply Finset.coe_injective + exact he.symm.trans (coe_unexposedRegion G Λ (t : Set E)).symm + simp [hh] + · intro hn + exact (hn (Finset.mem_powerset.mpr (unexposedRegion_subset G Λ (t : Set E)))).elim + + +noncomputable def internalSupport (G : BondGraph V E) (S : Set V) (F : Finset E) : Finset E := + F.filter (fun e => e ∈ internalEdges G S) + + theorem internalSupport_subset (G : BondGraph V E) (S : Set V) (F : Finset E) : + internalSupport G S F ⊆ F := Finset.filter_subset _ _ + + theorem internalSupport_union_sdiff (G : BondGraph V E) (S : Set V) (F : Finset E) : + internalSupport G S F ∪ (F \ internalSupport G S F) = F := + Finset.union_sdiff_of_subset (internalSupport_subset G S F) + + theorem coe_inter_internalSupport (G : BondGraph V E) (S : Set V) (F t : Finset E) + (ht : t ⊆ F) : ((t ∩ internalSupport G S F : Finset E) : Set E) = + (t : Set E) ∩ internalEdges G S := by + ext e + simp only [Finset.mem_coe,Finset.mem_inter,internalSupport,Finset.mem_filter,Set.mem_inter_iff] + exact ⟨fun h => ⟨h.1,h.2.2⟩,fun h => ⟨h.1,ht h.1,h.2⟩⟩ + + +noncomputable def regionProbability (G : BondGraph V E) (Λ S : Set V) + (F : Finset E) (p : ℝ) : ℝ := + bernoulliPolynomial F (fun t => if unexposed G Λ (t : Set E) = S then 1 else 0) p + + theorem regionProbability_nonneg (G : BondGraph V E) (Λ S : Set V) + (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : + 0 ≤ regionProbability G Λ S F p := by + apply bernoulliPolynomial_nonneg _ _ _ hp + intro t _ + split_ifs <;> norm_num + + +theorem bernoulliPolynomial_exposure_factor (G : BondGraph V E) (Λ S : Set V) + (F : Finset E) (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial F + (fun t => (if unexposed G Λ (t : Set E) = S then (1:ℝ) else 0) * + f (t ∩ internalSupport G S F)) p = + regionProbability G Λ S F p * bernoulliPolynomial (internalSupport G S F) f p := by + let s := internalSupport G S F + let t := F \ s + have hs : (s : Set E) ⊆ internalEdges G S := by + intro e he + exact (Finset.mem_filter.mp he).2 + have ht : Disjoint (t : Set E) (internalEdges G S) := by + apply Set.disjoint_left.mpr + intro e he hi + have he' := Finset.mem_sdiff.mp he + exact he'.2 (Finset.mem_filter.mpr ⟨he'.1,hi⟩) + have he : s ∪ t = F := internalSupport_union_sdiff G S F + have hq : bernoulliPolynomial t + (fun b => if unexposed G Λ (b : Set E) = S then (1:ℝ) else 0) p = + regionProbability G Λ S F p := by + simpa only [he,mul_one,bernoulliPolynomial_const,regionProbability] using + (bernoulliPolynomial_exposure G Λ S s t hs ht (fun _ => 1) p).symm + simpa only [he,hq] using bernoulliPolynomial_exposure G Λ S s t hs ht f p + + +def crossingReach (G : BondGraph V E) (S : Set V) (x : V) (ω : Set E) (e : E) : Prop := + ∃ a b, G e = s(a,b) ∧ a ∈ S ∧ b ∉ S ∧ Conn G ω x a + +noncomputable def crossingCount (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) (ω : Set E) : ℝ := + ∑ e ∈ F, if crossingReach G S x ω e then (1:ℝ) else 0 + + +noncomputable def boundaryExpectation (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) (p : ℝ) : ℝ := + bernoulliPolynomial (internalSupport G S F) + (fun t => crossingCount G S x F (t : Set E)) p + +noncomputable def closedEscapeCount (G : BondGraph V E) (Λ : Set V) (x : V) + (F : Finset E) (ω : Set E) : ℝ := + ∑ e ∈ F, if ω ∈ closedPivotal (escapeEvent G Λ x) e then (1:ℝ) else 0 + +theorem finite_escape_russo (G : BondGraph V E) (Λ : Set V) (x : V) + (F : Finset E) (p : ℝ) : + (1-p)*deriv (finiteEventPolynomial F (escapeEvent G Λ x)) p = + bernoulliPolynomial F (fun t => closedEscapeCount G Λ x F (t : Set E)) p := by + unfold finiteEventPolynomial + rw [closed_difference_russo] + unfold closedEscapeCount + rw [bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro e _ + apply bernoulliPolynomial_congr + intro t _ + exact (closedPivotal_difference _ (escapeEvent_isUpperSet G Λ x) e t).symm + + +theorem closedEscapeCount_expectation (G : BondGraph V E) (Λ : Finset V) (x : V) + (F : Finset E) (p : ℝ) : + bernoulliPolynomial F (fun t => closedEscapeCount G Λ x F (t : Set E)) p = + ∑ S ∈ Λ.powerset, if x ∈ S then + regionProbability G Λ S F p * boundaryExpectation G S x F p else 0 := by + rw [bernoulliPolynomial_partition_region G Λ F] + apply Finset.sum_congr rfl + intro S _ + by_cases hx : x ∈ S + · rw [ite_eq_left hx] + unfold boundaryExpectation + rw [← bernoulliPolynomial_exposure_factor G Λ S F + (fun t => crossingCount G S x F (t : Set E)) p] + apply bernoulliPolynomial_congr + intro t ht + by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) + · simp only [hreg,ite_true,one_mul] + apply Finset.sum_congr rfl + intro e _ + have hc : (t : Set E) ∈ closedPivotal (escapeEvent G Λ x) e ↔ + crossingReach G S x ((t ∩ internalSupport G S F : Finset E) : Set E) e := by + simpa only [closedPivotal,Set.mem_ofPred_eq,hreg,Finset.mem_coe,hx,true_and, + coe_inter_internalSupport G S F t ht,crossingReach] using + escape_closed_pivotal_iff G Λ (t : Set E) x e + exact if_congr hc rfl rfl + · simp [hreg] + · rw [ite_eq_right hx,← bernoulliPolynomial_zero F p] + apply bernoulliPolynomial_congr + intro t _ + by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) + · simp only [hreg,ite_true] + apply Finset.sum_eq_zero + intro e _ + have hn : (t : Set E) ∉ closedPivotal (escapeEvent G Λ x) e := by + intro he + have hh := ((escape_closed_pivotal_iff G Λ (t : Set E) x e).mp he).1 + apply hx + simpa only [hreg,Finset.mem_coe] using hh + simp [hn] + · simp [hreg] + + +theorem finite_escape_complement (G : BondGraph V E) (Λ : Finset V) (x : V) + (F : Finset E) (p : ℝ) : + 1-finiteEventPolynomial F (escapeEvent G Λ x) p = + ∑ S ∈ Λ.powerset, if x ∈ S then regionProbability G Λ S F p else 0 := by + have he : 1-finiteEventPolynomial F (escapeEvent G Λ x) p = + bernoulliPolynomial F + (fun t => if x ∈ unexposed G (Λ : Set V) (t : Set E) then (1:ℝ) else 0) p := by + change 1-bernoulliPolynomial F (fun t => if (t : Set E) ∈ escapeEvent G Λ x then 1 else 0) p = _ + rw [show (1:ℝ) = bernoulliPolynomial F (fun _ => 1) p from (bernoulliPolynomial_const F 1 p).symm] + rw [← bernoulliPolynomial_sub] + apply bernoulliPolynomial_congr + intro t _ + by_cases hx : x ∈ unexposed G (Λ : Set V) (t : Set E) <;> simp [escapeEvent,hx,bernoulliPolynomial_const] + rw [he,bernoulliPolynomial_partition_region G Λ F] + apply Finset.sum_congr rfl + intro S _ + by_cases hx : x ∈ S + · rw [ite_eq_left hx] + apply bernoulliPolynomial_congr + intro t _ + by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) <;> simp [hreg,hx] + · rw [ite_eq_right hx,← bernoulliPolynomial_zero F p] + apply bernoulliPolynomial_congr + intro t _ + by_cases hreg : unexposed G (Λ : Set V) (t : Set E) = (S : Set V) <;> simp [hreg,hx] + + + +theorem finite_escape_differential_lower (G : BondGraph V E) (Λ : Finset V) (x : V) + (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) + (hcost : ∀ S ⊆ Λ, x ∈ S → 1 ≤ p*boundaryExpectation G (S : Set V) x F p) : + 1-finiteEventPolynomial F (escapeEvent G Λ x) p ≤ + p*(1-p)*deriv (finiteEventPolynomial F (escapeEvent G Λ x)) p := by + rw [mul_assoc,finite_escape_russo,closedEscapeCount_expectation,finite_escape_complement, + Finset.mul_sum] + apply Finset.sum_le_sum + intro S hS + by_cases hx : x ∈ S + · simp only [ite_eq_left hx] + have hq := regionProbability_nonneg G Λ S F p hp + calc + regionProbability G Λ S F p ≤ + regionProbability G Λ S F p * (p*boundaryExpectation G S x F p) := + le_mul_of_one_le_right hq (hcost S (Finset.mem_powerset.mp hS) hx) + _ = p*(regionProbability G Λ S F p * boundaryExpectation G S x F p) := by ring + · simp [hx] + + theorem bernoulliPolynomial_monotoneOn (F : Finset E) (f : Finset E → ℝ) + (hf : ∀ a b, a ⊆ b → f a ≤ f b) : + MonotoneOn (bernoulliPolynomial F f) (Set.Icc (0:ℝ) 1) := by + have hd : Differentiable ℝ (bernoulliPolynomial F f) := + fun q => (hasDerivAt_bernoulliPolynomial F f q).differentiableAt + apply monotoneOn_of_deriv_nonneg (convex_Icc 0 1) hd.continuous.continuousOn hd.differentiableOn + intro q hq + have hq' : q ∈ Set.Icc (0:ℝ) 1 := interior_subset hq + rw [(hasDerivAt_bernoulliPolynomial F f q).deriv] + apply Finset.sum_nonneg + intro e _ + apply bernoulliPolynomial_nonneg _ _ _ hq' + intro t _ + exact sub_nonneg.mpr (hf t (insert e t) (Finset.subset_insert e t)) + + theorem crossingCount_mono (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) {ω η : Set E} (h : ω ⊆ η) : + crossingCount G S x F ω ≤ crossingCount G S x F η := by + apply Finset.sum_le_sum + intro e _ + have hh : crossingReach G S x ω e → crossingReach G S x η e := by + rintro ⟨a,b,he,ha,hb,hc⟩ + exact ⟨a,b,he,ha,hb,conn_mono G h hc⟩ + by_cases hω : crossingReach G S x ω e + · simp [hω,hh hω] + · simp only [ite_eq_right hω] + split_ifs <;> norm_num + + theorem boundaryExpectation_nonneg (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : + 0 ≤ boundaryExpectation G S x F p := by + apply bernoulliPolynomial_nonneg _ _ _ hp + intro t _ + apply Finset.sum_nonneg + intro e _ + split_ifs <;> norm_num + + theorem boundaryExpectation_monotoneOn (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) : MonotoneOn (boundaryExpectation G S x F) (Set.Icc (0:ℝ) 1) := by + apply bernoulliPolynomial_monotoneOn + intro a b hab + exact crossingCount_mono G S x F (by exact_mod_cast hab) + + theorem boundaryCost_monotoneOn (G : BondGraph V E) (S : Set V) (x : V) + (F : Finset E) : MonotoneOn (fun p => p*boundaryExpectation G S x F p) + (Set.Icc (0:ℝ) 1) := by + intro p hp q hq hpq + exact mul_le_mul hpq (boundaryExpectation_monotoneOn G S x F hp hq hpq) + (boundaryExpectation_nonneg G S x F p hp) hq.1 + + theorem finiteEventPolynomial_mem_Icc (F : Finset E) (A : Set (Set E)) + (p : ℝ) (hp : p ∈ Set.Icc (0:ℝ) 1) : + finiteEventPolynomial F A p ∈ Set.Icc (0:ℝ) 1 := by + constructor + · apply bernoulliPolynomial_nonneg _ _ _ hp + intro t _ + split_ifs <;> norm_num + · calc + finiteEventPolynomial F A p ≤ bernoulliPolynomial F (fun _ => 1) p := by + apply bernoulliPolynomial_mono _ _ _ _ hp + intro t _ + split_ifs <;> norm_num + _ = 1 := bernoulliPolynomial_const F 1 p + + + +theorem differential_escape_growth {f : ℝ → ℝ} {r p : ℝ} + (hr : 0 < r) (hrp : r ≤ p) (hp : p < 1) + (hf : Differentiable ℝ f) (hbound : ∀ q ∈ Set.Icc r p, f q ∈ Set.Icc (0:ℝ) 1) + (hineq : ∀ q ∈ Set.Icc r p, 1-f q ≤ q*(1-q)*deriv f q) : + 1-Real.exp (r-p) ≤ f p := by + have hd (q : ℝ) : HasDerivAt (fun u => Real.exp u*(1-f u)) + (Real.exp q*(1-f q)+Real.exp q*(0-deriv f q)) q := + (Real.hasDerivAt_exp q).mul ((hasDerivAt_const q 1).sub (hf q).hasDerivAt) + have hanti : AntitoneOn (fun q => Real.exp q*(1-f q)) (Set.Icc r p) := by + apply antitoneOn_of_hasDerivWithinAt_nonpos (convex_Icc r p) + (Real.continuous_exp.mul (continuous_const.sub hf.continuous)).continuousOn + (fun q _ => (hd q).hasDerivWithinAt) + intro q hq + have hqi : q ∈ Set.Icc r p := interior_subset hq + have hq0 : 0 < q := hr.trans_le hqi.1 + have hq1 : q < 1 := hqi.2.trans_lt hp + have hcoef : 0 < q*(1-q) := mul_pos hq0 (sub_pos.mpr hq1) + have hder : 0 ≤ deriv f q := nonneg_of_mul_nonneg_right + ((sub_nonneg.mpr (hbound q hqi).2).trans (hineq q hqi)) hcoef + have hc : q*(1-q) ≤ 1 := by nlinarith [sq_nonneg q] + have hsmall : 1-f q ≤ deriv f q := (hineq q hqi).trans + (mul_le_of_le_one_left hder hc) + have hn := mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos q).le + (show 1-f q-deriv f q ≤ 0 by linarith) + nlinarith only [hn] + have hle := hanti (show r ∈ Set.Icc r p from ⟨le_rfl,hrp⟩) + (show p ∈ Set.Icc r p from ⟨hrp,le_rfl⟩) hrp + have he : Real.exp p*(1-f p) ≤ Real.exp r := by + calc + Real.exp p*(1-f p) ≤ Real.exp r*(1-f r) := hle + _ ≤ Real.exp r := mul_le_of_le_one_right (Real.exp_pos r).le + (by linarith [(hbound r ⟨le_rfl,hrp⟩).1]) + have hfin : 1-f p ≤ Real.exp (r-p) := by + rw [Real.exp_sub] + apply (le_div_iff₀ (Real.exp_pos p)).mpr + simpa only [mul_comm] using he + linarith + + + +theorem finite_escape_probability_lower (G : BondGraph V E) (Λ : Finset V) (x : V) + (F : Finset E) (r p : ℝ) (hr : 0 < r) (hrp : r < p) (hp : p < 1) + (hcost : ∀ S ⊆ Λ, x ∈ S → 1 ≤ r*boundaryExpectation G (S : Set V) x F r) : + 0 < 1-Real.exp (r-p) ∧ + 1-Real.exp (r-p) ≤ finiteEventPolynomial F (escapeEvent G Λ x) p := by + have hrI : r ∈ Set.Icc (0:ℝ) 1 := ⟨hr.le,(hrp.trans hp).le⟩ + have hqI (q : ℝ) (hq : q ∈ Set.Icc r p) : q ∈ Set.Icc (0:ℝ) 1 := + ⟨hr.le.trans hq.1,hq.2.trans hp.le⟩ + refine ⟨sub_pos.mpr (Real.exp_lt_one_iff.mpr (sub_neg.mpr hrp)),?_⟩ + apply differential_escape_growth hr hrp.le hp + · intro q + exact (hasDerivAt_bernoulliPolynomial F _ q).differentiableAt + · intro q hq + exact finiteEventPolynomial_mem_Icc F _ q (hqI q hq) + · intro q hq + apply finite_escape_differential_lower G Λ x F q (hqI q hq) + intro S hS hx + exact (hcost S hS hx).trans (boundaryCost_monotoneOn G S x F hrI (hqI q hq) hq.1) + +end ExteriorExposure + +section SharpnessBridge +attribute [local instance] Classical.propDecidable Classical.decEq +open Filter Topology + +theorem bernoulliPolynomial_map {F : Type*} (f : E ↪ F) (s : Finset E) + (h : Finset F → ℝ) (p : ℝ) : + bernoulliPolynomial (s.map f) h p = + bernoulliPolynomial s (fun t => h (t.map f)) p := by + induction s using Finset.induction_on generalizing h with + | empty => simp + | @insert e s he ih => + rw [Finset.map_insert,bernoulliPolynomial_insert _ (f e) (by simpa using he), + bernoulliPolynomial_insert s e he,ih,ih] + simp only [Finset.map_insert] + +theorem finiteEventPolynomial_restrict (F : Finset E) (A : Set (Set E)) (p : unitInterval) : + finiteEventPolynomial F A (p : ℝ) = (law p).real {ω | ω ∩ (F : Set E) ∈ A} := by + let f : (F : Set E) ↪ E := ⟨Subtype.val,Subtype.val_injective⟩ + have hm : (Finset.univ : Finset (F : Set E)).map f = F := by + ext e + simp [f] + have he : finiteEventPolynomial F A (p : ℝ) = + finiteEventPolynomial (Finset.univ : Finset (F : Set E)) + {η | f '' η ∈ A} (p : ℝ) := by + unfold finiteEventPolynomial + calc + bernoulliPolynomial F (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ) = + bernoulliPolynomial (Finset.univ.map f) (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ) := + congrArg (fun H => bernoulliPolynomial H (fun t => if (t : Set E) ∈ A then 1 else 0) (p : ℝ)) hm.symm + _ = _ := by + rw [bernoulliPolynomial_map] + apply bernoulliPolynomial_congr + intro t _ + simp only [Finset.coe_map] + rfl + rw [he,finiteEventPolynomial_eq,finiteProbability_univ,← law_map_restrict p (F : Set E), + measureReal_def,Measure.map_apply (measurable_set_restrict _) .of_discrete] + congr 2 + ext ω + have hh : f '' (Subtype.val ⁻¹' ω : Set (F : Set E)) = ω ∩ (F : Set E) := by + ext e + simp [f,and_comm] + simp only [Set.mem_preimage,Set.mem_ofPred_eq,hh] + +theorem bernoulliPolynomial_restrict (F H : Finset E) (hFH : F ⊆ H) + (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial H (fun t => f (t ∩ F)) p = bernoulliPolynomial F f p := by + rw [← Finset.union_sdiff_of_subset hFH,bernoulliPolynomial_union _ _ Finset.disjoint_sdiff] + trans bernoulliPolynomial F (fun a => f a) p + · apply bernoulliPolynomial_congr + intro a ha + trans bernoulliPolynomial (H \ F) (fun _ => f a) p + · apply bernoulliPolynomial_congr + intro b hb + have hdis : Disjoint b F := (Finset.disjoint_sdiff.symm).mono_left hb + rw [Finset.union_inter_distrib_right,Finset.inter_eq_left.mpr ha, + Finset.disjoint_iff_inter_eq_empty.mp hdis,Finset.union_empty] + · exact bernoulliPolynomial_const _ _ _ + · rfl + + +noncomputable def incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) : Finset E := Λ.biUnion (fun x => (hloc x).toFinset) + +@[simp] theorem mem_incidentSupport (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (e : E) : e ∈ incidentSupport G hloc Λ ↔ ∃ x ∈ Λ, x ∈ G e := by + simp [incidentSupport] + +theorem incidentSupport_mono (G : BondGraph V E) (hloc : LocallyFinite G) + {S Λ : Finset V} (hS : S ⊆ Λ) : incidentSupport G hloc S ⊆ incidentSupport G hloc Λ := by + intro e he + obtain ⟨x,hx,hxe⟩ := (mem_incidentSupport G hloc S e).mp he + exact (mem_incidentSupport G hloc Λ e).mpr ⟨x,hS hx,hxe⟩ + + +theorem escapeEvent_restrict_incident (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (x : V) (ω : Set E) : + ω ∩ (incidentSupport G hloc Λ : Set E) ∈ escapeEvent G Λ x ↔ + ω ∈ escapeEvent G Λ x := by + constructor + · exact escapeEvent_isUpperSet G Λ x Set.inter_subset_left + · intro hx + by_contra hn + have hx' : x ∈ unexposed G Λ (ω ∩ (incidentSupport G hloc Λ : Set E)) := by + simpa only [escapeEvent,Set.mem_ofPred_eq,not_not] using hn + apply hx + intro y hxy + have hc : Conn G (ω ∩ (incidentSupport G hloc Λ : Set E)) x y := by + induction hxy with + | refl => exact conn_refl _ _ _ + | @tail a b hxa hab ih => + obtain ⟨e,he,heab⟩ := hab + have ha : a ∈ Λ := hx' a ih + have hF : e ∈ incidentSupport G hloc Λ := + (mem_incidentSupport G hloc Λ e).mpr ⟨a,ha,by simp [heab]⟩ + exact ih.tail ⟨e,⟨he,hF⟩,heab⟩ + exact hx' y hc + +theorem finite_escape_eq_law (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (x : V) (p : unitInterval) : + finiteEventPolynomial (incidentSupport G hloc Λ) (escapeEvent G Λ x) (p : ℝ) = + (law p).real (escapeEvent G Λ x) := by + rw [finiteEventPolynomial_restrict] + congr 1 + ext ω + exact escapeEvent_restrict_incident G hloc Λ x ω + +theorem internal_edge_mem_incident (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) {e : E} (he : e ∈ internalEdges G (S : Set V)) : + e ∈ incidentSupport G hloc S := by + obtain ⟨⟨a,b⟩,hab⟩ := Sym2.mk_surjective (G e) + have ha : a ∈ G e := by rw [← hab]; simp + exact (mem_incidentSupport G hloc S e).mpr ⟨a,he a ha,ha⟩ + +theorem internalSupport_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) : + internalSupport G S F = internalSupport G S (incidentSupport G hloc S) := by + ext e + simp only [internalSupport,Finset.mem_filter] + exact ⟨fun h => ⟨internal_edge_mem_incident G hloc S h.2,h.2⟩, + fun h => ⟨hF h.1,h.2⟩⟩ + +theorem crossingCount_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (x : V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) (ω : Set E) : + crossingCount G S x F ω = crossingCount G S x (incidentSupport G hloc S) ω := by + symm + apply Finset.sum_subset hF + intro e _ he + have hn : ¬ crossingReach G S x ω e := by + rintro ⟨a,b,hab,ha,_,_⟩ + exact he ((mem_incidentSupport G hloc S e).mpr ⟨a,ha,by simp [hab]⟩) + simp [hn] + +theorem boundaryExpectation_eq_of_incident_subset (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (x : V) (F : Finset E) (hF : incidentSupport G hloc S ⊆ F) (p : ℝ) : + boundaryExpectation G S x F p = + boundaryExpectation G S x (incidentSupport G hloc S) p := by + unfold boundaryExpectation + rw [internalSupport_eq_of_incident_subset G hloc S F hF] + apply bernoulliPolynomial_congr + intro t _ + exact crossingCount_eq_of_incident_subset G hloc S x F hF t + + +noncomputable def boundaryCost (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (x : V) (p : ℝ) : ℝ := + p*boundaryExpectation G S x (incidentSupport G hloc S) p + +theorem measurableSet_escapeEvent (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (x : V) : MeasurableSet (escapeEvent G Λ x) := by + let F := incidentSupport G hloc Λ + have he : escapeEvent G Λ x = + (fun ω => (Subtype.val ⁻¹' ω : Set (F : Set E))) ⁻¹' + {η | Subtype.val '' η ∈ escapeEvent G Λ x} := by + ext ω + have hh : Subtype.val '' (Subtype.val ⁻¹' ω : Set (F : Set E)) = ω ∩ (F : Set E) := by + ext e + simp [and_comm] + simp only [Set.mem_preimage,Set.mem_ofPred_eq,hh] + exact (escapeEvent_restrict_incident G hloc Λ x ω).symm + rw [he] + exact MeasurableSet.preimage .of_discrete (measurable_set_restrict _) + +theorem escapeEvent_antitone_domain (G : BondGraph V E) {S Λ : Set V} (hS : S ⊆ Λ) + (x : V) : escapeEvent G Λ x ⊆ escapeEvent G S x := by + intro ω hω hn + apply hω + intro y hxy + exact hS (hn y hxy) + +noncomputable def vertexExhaustion [Encodable V] (n : ℕ) : Finset V := + (Finset.range n).preimage Encodable.encode Encodable.encode_injective.injOn + +theorem vertexExhaustion_mono [Encodable V] : + Monotone (vertexExhaustion : ℕ → Finset V) := by + intro m n h x hx + simp only [vertexExhaustion,Finset.mem_preimage,Finset.mem_range] at hx ⊢ + exact hx.trans_le h + +theorem subset_vertexExhaustion [Encodable V] (S : Finset V) : + ∃ n, S ⊆ vertexExhaustion n := by + refine ⟨S.sup Encodable.encode+1,?_⟩ + intro x hx + simp only [vertexExhaustion,Finset.mem_preimage,Finset.mem_range] + exact Nat.lt_succ_of_le (Finset.le_sup hx) + +theorem infinite_cluster_eq_iInter_escape [Encodable V] (G : BondGraph V E) (x : V) : + {ω | (cluster G ω x).Infinite} = ⋂ n, escapeEvent G (vertexExhaustion (V := V) n : Set V) x := by + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_iInter] + constructor + · intro hi n hn + exact hi ((vertexExhaustion n).finite_toSet.subset (by + intro y hy; exact hn y hy)) + · intro he hf + obtain ⟨n,hn⟩ := subset_vertexExhaustion hf.toFinset + apply he n + intro y hy + exact hn (hf.mem_toFinset.mpr hy) + + +theorem infinite_cluster_probability_ge_of_escape [Countable V] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (p : unitInterval) (c : ℝ) + (hc : ∀ Λ : Finset V, c ≤ (law p).real (escapeEvent G Λ x)) : + c ≤ (law p).real {ω | (cluster G ω x).Infinite} := by + let := Encodable.ofCountable V + rw [infinite_cluster_eq_iInter_escape] + have hm : Antitone (fun n => escapeEvent G (vertexExhaustion (V := V) n : Set V) x) := by + intro m n h + exact escapeEvent_antitone_domain G (by exact_mod_cast vertexExhaustion_mono h) x + have ht := tendsto_measure_iInter_atTop (μ := law p) + (fun n => (measurableSet_escapeEvent G hloc (vertexExhaustion n) x).nullMeasurableSet) + hm ⟨0,measure_ne_top _ _⟩ + have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht + exact ge_of_tendsto hr (Eventually.of_forall (fun n => hc (vertexExhaustion n))) + + + +theorem infinite_cluster_probability_pos_of_bad_cost [Countable V] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (r p : unitInterval) + (hr : 0 < r) (hrp : r < p) (hp : p < 1) + (hcost : ∀ S : Finset V, x ∈ S → 1 ≤ boundaryCost G hloc S x (r : ℝ)) : + 0 < (law p).real {ω | (cluster G ω x).Infinite} := by + have hc : 0 < 1-Real.exp ((r:ℝ)-(p:ℝ)) := + sub_pos.mpr (Real.exp_lt_one_iff.mpr (sub_neg.mpr hrp)) + apply hc.trans_le + apply infinite_cluster_probability_ge_of_escape G hloc x p + intro Λ + rw [← finite_escape_eq_law G hloc Λ x p] + apply (finite_escape_probability_lower G Λ x (incidentSupport G hloc Λ) + (r:ℝ) (p:ℝ) hr hrp hp ?_).2 + intro S hS hx + rw [boundaryExpectation_eq_of_incident_subset G hloc S x _ (incidentSupport_mono G hloc hS)] + exact hcost S hx + +theorem pc_le_of_infinite_cluster_probability_pos (G : BondGraph V E) + (x : V) (p : unitInterval) (hp : 0 < (law p).real {ω | (cluster G ω x).Infinite}) : + pc G ≤ p := by + apply sInf_le + have hh : 0 < law p {ω | (cluster G ω x).Infinite} := (ENNReal.toReal_pos_iff.mp hp).1 + apply hh.trans_le + apply measure_mono + intro ω hω + exact ⟨cluster G ω x,hω,x,rfl⟩ + + +theorem exists_subcritical_testSet [Countable V] (G : BondGraph V E) + (hloc : LocallyFinite G) (p : unitInterval) (hp : p < pc G) (x : V) : + ∃ S : Finset V, x ∈ S ∧ boundaryCost G hloc S x (p:ℝ) < 1 := by + by_cases hz : p = 0 + · exact ⟨{x},by simp,by simp [hz,boundaryCost]⟩ + · have hp0 : 0 < p := bot_lt_iff_ne_bot.mpr hz + by_contra! hn + obtain ⟨q,hpq,hqc⟩ := exists_between hp + have hq1 : q < 1 := hqc.trans_le (show pc G ≤ 1 from (pc G).2.2) + have hs := infinite_cluster_probability_pos_of_bad_cost G hloc x p q hp0 hpq hq1 hn + exact (not_le_of_gt hqc) (pc_le_of_infinite_cluster_probability_pos G x q hs) + +theorem internalEdges_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (S : Set V) (e : E) : + b e ∈ internalEdges G (a '' S) ↔ e ∈ internalEdges G S := by + constructor + · intro he x hx + have hh := he (a x) (by rw [h e]; exact Sym2.mem_map.mpr ⟨x,hx,rfl⟩) + simpa using hh + · intro he y hy + rw [h e,Sym2.mem_map] at hy + obtain ⟨x,hx,rfl⟩ := hy + exact Set.mem_image_of_mem a (he x hx) + +theorem crossingReach_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (S : Set V) (x : V) (ω : Set E) (e : E) : + crossingReach G (a '' S) (a x) (b '' ω) (b e) ↔ crossingReach G S x ω e := by + constructor + · rintro ⟨c,d,he,hc,hd,hconn⟩ + have he' : G e = s(a.symm c,a.symm d) := by + have hh := congrArg (Sym2.map a.symm) he + rw [h e,Sym2.map_map,Equiv.symm_comp_self,Sym2.map_id,Sym2.map_mk] at hh + exact hh + refine ⟨a.symm c,a.symm d,he',?_,?_,?_⟩ + · simpa using hc + · simpa using hd + · have hh := (conn_aut_iff G h (b '' ω) x (a.symm c)).mpr (by simpa using hconn) + simpa only [Set.preimage_image_eq _ b.injective] using hh + · rintro ⟨c,d,he,hc,hd,hconn⟩ + refine ⟨a c,a d,?_,by simpa using hc,by simpa using hd,conn_aut G h hconn⟩ + rw [h e,he,Sym2.map_mk] + +theorem internalSupport_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (S : Set V) (F : Finset E) : + internalSupport G (a '' S) (F.map b.toEmbedding) = + (internalSupport G S F).map b.toEmbedding := by + ext e + obtain ⟨d,rfl⟩ := b.surjective e + simp [internalSupport,internalEdges_aut_iff G h] + +theorem crossingCount_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (S : Set V) (x : V) (F : Finset E) (ω : Set E) : + crossingCount G (a '' S) (a x) (F.map b.toEmbedding) (b '' ω) = + crossingCount G S x F ω := by + simp only [crossingCount,Finset.sum_map,Equiv.toEmbedding_apply,crossingReach_aut_iff G h] + +theorem boundaryExpectation_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (S : Set V) (x : V) (F : Finset E) (p : ℝ) : + boundaryExpectation G (a '' S) (a x) (F.map b.toEmbedding) p = + boundaryExpectation G S x F p := by + unfold boundaryExpectation + rw [internalSupport_aut G h,bernoulliPolynomial_map] + apply bernoulliPolynomial_congr + intro t _ + simp only [Finset.coe_map,Equiv.coe_toEmbedding] + exact crossingCount_aut G h S x F t + +theorem incidentSupport_aut (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (S : Finset V) : + incidentSupport G hloc (S.map a.toEmbedding) = + (incidentSupport G hloc S).map b.toEmbedding := by + ext e + obtain ⟨d,rfl⟩ := b.surjective e + simp only [mem_incidentSupport,Finset.mem_map,Equiv.toEmbedding_apply, + b.injective.eq_iff,exists_eq_right] + constructor + · rintro ⟨x,⟨y,hy,rfl⟩,hx⟩ + rw [h d,Sym2.mem_map] at hx + obtain ⟨z,hz,hzy⟩ := hx + have hz' : z = y := a.injective hzy + exact ⟨y,hy,hz' ▸ hz⟩ + · rintro ⟨x,hx,he⟩ + exact ⟨a x,⟨x,hx,rfl⟩,by rw [h d]; exact Sym2.mem_map.mpr ⟨x,he,rfl⟩⟩ + +theorem boundaryCost_aut (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (S : Finset V) (x : V) (p : ℝ) : + boundaryCost G hloc (S.map a.toEmbedding) (a x) p = boundaryCost G hloc S x p := by + unfold boundaryCost + rw [incidentSupport_aut G hloc h,Finset.coe_map] + exact congrArg (p*·) (boundaryExpectation_aut G h S x (incidentSupport G hloc S) p) + + + +theorem exists_uniform_subcritical_testSets [Countable V] [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) : + ∃ (L : ℕ) (a : ℝ), 0 ≤ a ∧ a < 1 ∧ ∀ x, ∃ S : Finset V, + x ∈ S ∧ S.card ≤ L ∧ boundaryCost G hloc S x (p:ℝ) ≤ a := by + obtain ⟨O,hO⟩ := hqt + choose S hmem hcost using exists_subcritical_testSet G hloc p hp + have hOn : O.Nonempty := by + obtain ⟨o,ho,_⟩ := hO (Classical.arbitrary V) + exact ⟨o,ho⟩ + let L := O.sup (fun x => (S x).card) + let a := max 0 (O.sup' hOn (fun x => boundaryCost G hloc (S x) x (p:ℝ))) + refine ⟨L,a,le_max_left _ _,?_,?_⟩ + · apply max_lt zero_lt_one + exact (Finset.sup'_lt_iff hOn).mpr (fun x _ => hcost x) + · intro x + obtain ⟨o,ho,α,β,hαβ,rfl⟩ := hO x + refine ⟨(S o).map α.toEmbedding,?_,?_,?_⟩ + · simp only [Finset.mem_map,Equiv.toEmbedding_apply] + exact ⟨o,hmem o,rfl⟩ + · simpa only [Finset.card_map] using Finset.le_sup (f := fun x => (S x).card) ho + · rw [boundaryCost_aut G hloc hαβ] + exact (Finset.le_sup' (f := fun x => boundaryCost G hloc (S x) x (p:ℝ)) ho).trans + (le_max_right _ _) + +end SharpnessBridge + +section SharpnessSusceptibility +open Filter Topology +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def domainTwoPoint (G : BondGraph V E) (S : Set V) (p : unitInterval) + (x y : V) : ℝ := (law p).real {ω | Conn G (ω ∩ internalEdges G S) x y} + +theorem conn_internal_endpoint (G : BondGraph V E) (S : Set V) {ω : Set E} {x y : V} + (hx : x ∈ S) (h : Conn G (ω ∩ internalEdges G S) x y) : y ∈ S := by + induction h with + | refl => exact hx + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + exact ((mem_internalEdges_of_ends G S e a b heq).mp he.2).2 + +def CutExists (G : BondGraph V E) (S : Set V) (e : E) : Prop := + ∃ a b, G e = s(a,b) ∧ a ∈ S ∧ b ∉ S + +noncomputable def cutInside [Nonempty V] (G : BondGraph V E) (S : Set V) (e : E) : V := + if h : CutExists G S e then h.choose else Classical.arbitrary V + +noncomputable def cutOutside [Nonempty V] (G : BondGraph V E) (S : Set V) (e : E) : V := + if h : CutExists G S e then h.choose_spec.choose else Classical.arbitrary V + +theorem cut_spec [Nonempty V] (G : BondGraph V E) (S : Set V) {e : E} + (he : CutExists G S e) : + G e = s(cutInside G S e,cutOutside G S e) ∧ + cutInside G S e ∈ S ∧ cutOutside G S e ∉ S := by + simpa only [cutInside,cutOutside,dite_eq_left he] using he.choose_spec.choose_spec + +theorem cut_unique [Nonempty V] (G : BondGraph V E) (S : Set V) {e : E} {a b : V} + (he : G e = s(a,b)) (ha : a ∈ S) (hb : b ∉ S) : + a = cutInside G S e ∧ b = cutOutside G S e := by + have hc := cut_spec G S (e := e) ⟨a,b,he,ha,hb⟩ + have hh := Sym2.eq_iff.mp (he.symm.trans hc.1) + rcases hh with ⟨h₁,h₂⟩ | ⟨h₁,h₂⟩ + · exact ⟨h₁,h₂⟩ + · exact (hc.2.2 (h₁ ▸ ha)).elim + +theorem crossingReach_cut [Nonempty V] (G : BondGraph V E) (S : Set V) + (x : V) (ω : Set E) (e : E) : + crossingReach G S x ω e ↔ CutExists G S e ∧ Conn G ω x (cutInside G S e) := by + constructor + · rintro ⟨a,b,he,ha,hb,h⟩ + exact ⟨⟨a,b,he,ha,hb⟩,(cut_unique G S he ha hb).1 ▸ h⟩ + · rintro ⟨he,h⟩ + have hs := cut_spec G S he + exact ⟨_,_,hs.1,hs.2.1,hs.2.2,h⟩ + +theorem crossingReach_upper (G : BondGraph V E) (S : Set V) (x : V) (e : E) : + IsUpperSet {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by + rintro ω η h ⟨a,b,he,ha,hb,hconn⟩ + exact ⟨a,b,he,ha,hb,conn_mono G (Set.inter_subset_inter_left _ h) hconn⟩ + +theorem finiteWitness_crossingReach (G : BondGraph V E) (S : Set V) (x : V) (e : E) : + FiniteWitness {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by + rintro ω ⟨a,b,he,ha,hb,hconn⟩ + obtain ⟨t,ht,hc⟩ := finiteWitness_inter {η | Conn G η x a} (finiteWitness_conn G x a) + (internalEdges G S) ω hconn + exact ⟨t,ht,a,b,he,ha,hb,hc⟩ + + +theorem conn_first_exit [Nonempty V] (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (U : Set E) {ω : Set E} {x y : V} (hx : x ∈ S) + (hxy : Conn G (ω ∩ U) x y) : + y ∈ S ∨ ∃ e ∈ incidentSupport G hloc S, + ω ∈ DisjointOccurrence {η | crossingReach G S x (η ∩ internalEdges G S) e} + (DisjointOccurrence {η | e ∈ η} {η | Conn G (η ∩ U) (cutOutside G S e) y}) := by + obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G hxy + rcases hl.first_outside (internalEdges G S) with hall | + ⟨a,b,e,l₁,l₂,heq,h₁,he,h₂,hfirst,hnot⟩ + · exact Or.inl (conn_internal_endpoint G S hx (hl.conn fun e he => ⟨(ho e he).1,hall e he⟩)) + · subst l + have hnod := List.nodup_append.mp hn + have hen : e ∉ l₂ := (List.nodup_cons.mp hnod.2.1).1 + have ha : a ∈ S := conn_internal_endpoint G S hx + (h₁.conn (ω := ω ∩ internalEdges G S) fun d hd => + ⟨(ho d (List.mem_append_left _ hd)).1,hfirst d hd⟩) + have hb : b ∉ S := fun hb => hnot ((mem_internalEdges_of_ends G S e a b he).mpr ⟨ha,hb⟩) + have hbe := (cut_unique G S he ha hb).2 + refine Or.inr ⟨e,(mem_incidentSupport G hloc S e).mpr ⟨a,ha,by simp [he]⟩, + l₁.toFinset,(e::l₂).toFinset,?_,?_,?_,?_,?_⟩ + · intro d hd + exact (ho d (List.mem_append_left _ (List.mem_toFinset.mp hd))).1 + · intro d hd + exact (ho d (List.mem_append_right _ (List.mem_toFinset.mp hd))).1 + · apply Finset.disjoint_left.mpr + intro d hd hd' + exact hnod.2.2 d (List.mem_toFinset.mp hd) d (List.mem_toFinset.mp hd') rfl + · exact ⟨a,b,he,ha,hb,h₁.conn (fun d hd => ⟨by simpa using hd,hfirst d hd⟩)⟩ + · refine ⟨{e},l₂.toFinset,by simp,by simp,by simpa using hen,by simp,?_⟩ + rw [← hbe] + exact h₂.conn fun d hd => ⟨by simpa using hd, + (ho d (List.mem_append_right _ (List.mem_cons_of_mem e hd))).2⟩ + + +theorem boundaryExpectation_eq_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (x : V) (p : unitInterval) : + boundaryExpectation G S x (incidentSupport G hloc S) (p:ℝ) = + ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} := by + have hI : (internalSupport G S (incidentSupport G hloc S) : Set E) = internalEdges G S := by + ext e + simp only [Finset.mem_coe,internalSupport,Finset.mem_filter] + exact ⟨And.right,fun he => ⟨internal_edge_mem_incident G hloc S he,he⟩⟩ + unfold boundaryExpectation crossingCount bernoulliPolynomial + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro e _ + change finiteEventPolynomial (internalSupport G S (incidentSupport G hloc S)) + {ω | crossingReach G S x ω e} (p:ℝ) = _ + rw [finiteEventPolynomial_restrict,hI] + rfl + + +theorem domainTwoPoint_first_exit [Countable E] [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (S : Finset V) (Λ : Set V) (p : unitInterval) + (x y : V) (hx : x ∈ S) : + domainTwoPoint G Λ p x y ≤ (if y ∈ S then (1:ℝ) else 0) + + ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * + (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y := by + by_cases hy : y ∈ S + · have hnon : 0 ≤ ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * + (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y := by + apply Finset.sum_nonneg + intro e _ + exact mul_nonneg (mul_nonneg (measureReal_nonneg) p.2.1) measureReal_nonneg + simpa only [ite_eq_left hy,domainTwoPoint] using (measureReal_le_one (μ := law p) + (s := {ω | Conn G (ω ∩ internalEdges G Λ) x y})).trans (le_add_of_nonneg_right hnon) + · simp only [ite_eq_right hy,zero_add] + let A := fun e => {ω | crossingReach G S x (ω ∩ internalEdges G S) e} + let B := fun e => {ω | Conn G (ω ∩ internalEdges G Λ) (cutOutside G S e) y} + let F := incidentSupport G hloc S + let C := fun e => DisjointOccurrence (A e) (DisjointOccurrence {ω | e ∈ ω} (B e)) + have hsub : {ω | Conn G (ω ∩ internalEdges G Λ) x y} ⊆ ⋃ e ∈ F, C e := by + intro ω hω + rcases conn_first_exit G hloc S (internalEdges G Λ) hx hω with h | ⟨e,he,h⟩ + · exact (hy h).elim + · exact Set.mem_iUnion.mpr ⟨e,Set.mem_iUnion.mpr ⟨he,h⟩⟩ + calc + domainTwoPoint G Λ p x y ≤ (law p).real (⋃ e ∈ F, C e) := measureReal_mono (μ := law p) hsub (measure_ne_top _ _) + _ ≤ ∑ e ∈ F, (law p).real (C e) := measureReal_biUnion_finset_le _ _ + _ ≤ _ := by + apply Finset.sum_le_sum + intro e _ + have hB : IsUpperSet (B e) := fun _ _ h hc => + conn_mono G (Set.inter_subset_inter_left _ h) hc + have hfB : FiniteWitness (B e) := finiteWitness_inter _ + (finiteWitness_conn G _ _) (internalEdges G Λ) + have hb := bk p (A e) (DisjointOccurrence {ω | e ∈ ω} (B e)) + (crossingReach_upper G S x e) (disjointOccurrence_upper _ _) + (finiteWitness_crossingReach G S x e) (finiteWitness_disjointOccurrence _ _) + have hb' := bk p {ω | e ∈ ω} (B e) (fun _ _ h he => h he) hB (finiteWitness_edge e) hfB + have heq : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by + simpa using finite_open_probability p {e} + rw [heq] at hb' + calc + (law p).real (C e) ≤ (law p).real (A e) * (law p).real + (DisjointOccurrence {ω | e ∈ ω} (B e)) := hb + _ ≤ (law p).real (A e) * ((p:ℝ) * (law p).real (B e)) := + mul_le_mul_of_nonneg_left hb' measureReal_nonneg + _ = _ := (mul_assoc _ _ _).symm + +theorem conn_internal_eq_or_mem (G : BondGraph V E) (S : Set V) {ω : Set E} {x y : V} + (h : Conn G (ω ∩ internalEdges G S) x y) : x = y ∨ x ∈ S ∧ y ∈ S := by + induction h with + | refl => exact Or.inl rfl + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + have he' := (mem_internalEdges_of_ends G S e a b heq).mp he.2 + right + exact ⟨ih.elim (fun h => h.symm ▸ he'.1) And.left,he'.2⟩ + +theorem domainTwoPoint_zero_of_outside (G : BondGraph V E) (S : Set V) (p : unitInterval) + {x y : V} (hx : x ∉ S) (hy : y ∈ S) : domainTwoPoint G S p x y = 0 := by + have he : {ω | Conn G (ω ∩ internalEdges G S) x y} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro ω h + rcases conn_internal_eq_or_mem G S h with rfl | h + · exact hx hy + · exact hx h.1 + simp only [domainTwoPoint,he,measureReal_empty] + +theorem domainRow_le_boundaryCost [Countable E] [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (S Λ : Finset V) (p : unitInterval) (x : V) (hx : x ∈ S) + (H : ℝ) (hH : ∀ z, ∑ y ∈ Λ, domainTwoPoint G Λ p z y ≤ H) : + (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ S.card + boundaryCost G hloc S x (p:ℝ) * H := by + have hind : (∑ y ∈ Λ, if y ∈ S then (1:ℝ) else 0) ≤ (S.card:ℝ) := by + simp only [← Finset.sum_filter] + simpa using (Nat.cast_le (α := ℝ)).mpr (Finset.card_le_card + (show Λ.filter (fun y => y ∈ S) ⊆ S from fun y hy => (Finset.mem_filter.mp hy).2)) + calc + (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ + ∑ y ∈ Λ, ((if y ∈ S then (1:ℝ) else 0) + + ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * + (p:ℝ) * domainTwoPoint G Λ p (cutOutside G S e) y) := + Finset.sum_le_sum fun y _ => domainTwoPoint_first_exit G hloc S Λ p x y hx + _ = (∑ y ∈ Λ, if y ∈ S then (1:ℝ) else 0) + + ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * + (p:ℝ) * ∑ y ∈ Λ, domainTwoPoint G Λ p (cutOutside G S e) y := by + rw [Finset.sum_add_distrib,Finset.sum_comm] + simp only [← Finset.mul_sum] + _ ≤ S.card + ∑ e ∈ incidentSupport G hloc S, + (law p).real {ω | crossingReach G S x (ω ∩ internalEdges G S) e} * (p:ℝ) * H := by + apply add_le_add hind + apply Finset.sum_le_sum + intro e _ + exact mul_le_mul_of_nonneg_left (hH _) (mul_nonneg measureReal_nonneg p.2.1) + _ = S.card + boundaryCost G hloc S x (p:ℝ) * H := by + unfold boundaryCost + rw [boundaryExpectation_eq_sum] + simp only [← Finset.sum_mul] + ring + +theorem domainRow_uniform_bound [Countable E] [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (p : unitInterval) (L : ℕ) (a : ℝ) (ha : a < 1) + (htest : ∀ x, ∃ S : Finset V, x ∈ S ∧ S.card ≤ L ∧ boundaryCost G hloc S x (p:ℝ) ≤ a) + (Λ : Finset V) (x : V) : + (∑ y ∈ Λ, domainTwoPoint G Λ p x y) ≤ (L:ℝ)/(1-a) := by + by_cases hΛ : Λ.Nonempty + · let row := fun z => ∑ y ∈ Λ, domainTwoPoint G Λ p z y + obtain ⟨z,hz,hmax⟩ := Λ.exists_max_image row hΛ + have hnon : 0 ≤ row z := Finset.sum_nonneg (fun _ _ => measureReal_nonneg) + have hH : ∀ w, row w ≤ row z := by + intro w + by_cases hw : w ∈ Λ + · exact hmax w hw + · have he : row w = 0 := by + apply Finset.sum_eq_zero + intro y hy + exact domainTwoPoint_zero_of_outside G Λ p hw hy + rwa [he] + obtain ⟨S,hS,hcard,hcost⟩ := htest z + have h := domainRow_le_boundaryCost G hloc S Λ p z hS (row z) hH + have hL : (S.card:ℝ) ≤ (L:ℝ) := Nat.cast_le.mpr hcard + have hc := mul_le_mul_of_nonneg_right hcost hnon + have hrow : row z ≤ (L:ℝ)/(1-a) := (le_div_iff₀ (sub_pos.mpr ha)).mpr (by nlinarith) + exact (hH x).trans hrow + · simp only [Finset.not_nonempty_iff_eq_empty.mp hΛ,Finset.sum_empty] + exact div_nonneg (Nat.cast_nonneg _) (sub_pos.mpr ha).le + +theorem internalEdges_mono (G : BondGraph V E) {S T : Set V} (h : S ⊆ T) : + internalEdges G S ⊆ internalEdges G T := fun _ he x hx => h (he x hx) + +theorem exists_internal_vertexExhaustion [Encodable V] (G : BondGraph V E) (e : E) : + ∃ n, e ∈ internalEdges G (vertexExhaustion (V := V) n : Set V) := by + obtain ⟨⟨a,b⟩,hab⟩ := Sym2.mk_surjective (G e) + obtain ⟨n,hn⟩ := subset_vertexExhaustion ({a,b} : Finset V) + refine ⟨n,?_⟩ + rw [mem_internalEdges_of_ends G _ e a b hab.symm] + exact ⟨hn (by simp),hn (by simp)⟩ + +theorem conn_domain_exhaustion [Encodable V] (G : BondGraph V E) {ω : Set E} {x y : V} + (h : Conn G ω x y) : + ∃ n, Conn G (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y := by + induction h with + | refl => exact ⟨0,conn_refl _ _ _⟩ + | @tail a b hxa hab ih => + obtain ⟨n,hn⟩ := ih + obtain ⟨e,he,heq⟩ := hab + obtain ⟨m,hm⟩ := exists_internal_vertexExhaustion G e + refine ⟨max n m,?_⟩ + have hnm := internalEdges_mono G (show (vertexExhaustion (V := V) n : Set V) ⊆ + (vertexExhaustion (V := V) (max n m) : Set V) from vertexExhaustion_mono (le_max_left n m)) + have hmm := internalEdges_mono G (show (vertexExhaustion (V := V) m : Set V) ⊆ + (vertexExhaustion (V := V) (max n m) : Set V) from vertexExhaustion_mono (le_max_right n m)) + exact (conn_mono G (Set.inter_subset_inter_right _ hnm) hn).tail ⟨e,⟨he,hmm hm⟩,heq⟩ + +theorem tendsto_domainTwoPoint [Encodable V] (G : BondGraph V E) (p : unitInterval) (x y : V) : + Tendsto (fun n => domainTwoPoint G (vertexExhaustion (V := V) n : Set V) p x y) + atTop (𝓝 (twoPoint G p x y)) := by + have hm : Monotone (fun n => {ω | Conn G + (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y}) := by + intro m n h ω hc + exact conn_mono G (Set.inter_subset_inter_right _ (internalEdges_mono G + (show (vertexExhaustion (V := V) m : Set V) ⊆ (vertexExhaustion (V := V) n : Set V) from + vertexExhaustion_mono h))) hc + have he : (⋃ n, {ω | Conn G (ω ∩ internalEdges G (vertexExhaustion (V := V) n : Set V)) x y}) = + {ω | Conn G ω x y} := by + ext ω + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] + exact ⟨fun ⟨n,h⟩ => conn_mono G Set.inter_subset_left h,conn_domain_exhaustion G⟩ + have h := tendsto_measure_iUnion_atTop (μ := law p) hm + rw [he] at h + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h + + +theorem subcritical_row_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ x (F : Finset V), ∑ y ∈ F, twoPoint G p x y ≤ C := by + let : Encodable V := Encodable.ofCountable V + obtain ⟨L,a,_,ha,htest⟩ := exists_uniform_subcritical_testSets G hloc hqt p hp + refine ⟨(L:ℝ)/(1-a),div_nonneg (Nat.cast_nonneg _) (sub_pos.mpr ha).le,?_⟩ + intro x F + apply le_of_tendsto (tendsto_finsetSum F (fun y _ => tendsto_domainTwoPoint G p x y)) + obtain ⟨N,hN⟩ := subset_vertexExhaustion F + filter_upwards [eventually_ge_atTop N] with n hn + have hFn : F ⊆ vertexExhaustion n := hN.trans (vertexExhaustion_mono hn) + exact (Finset.sum_le_sum_of_subset_of_nonneg hFn (fun _ _ _ => measureReal_nonneg)).trans + (domainRow_uniform_bound G hloc p L a ha htest (vertexExhaustion n) x) + + +theorem operatorBounded_of_lt_pc [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : OperatorBounded G p := by + obtain ⟨C,hC,hrow⟩ := subcritical_row_bound G hloc hqt p hp + obtain ⟨A,_,hA⟩ := exists_operator_of_row_column_bound (twoPoint G p) C hC + (twoPoint_nonneg G p) hrow (fun y F => by + simpa only [twoPoint_symm G p] using hrow y F) + exact ⟨A,hA⟩ + +end SharpnessSusceptibility + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/Susceptibility.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/Susceptibility.lean index 35ae2cb0f581ceaecaca768a231dfea655cd9601..969977d20946e81f1160c6536b6aa29b07ebd2f6 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/Susceptibility.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/Susceptibility.lean @@ -1,1196 +1,1196 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.DistinctMoments - -namespace OAI - -/-! Susceptibility for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SusceptibilityPivotalGain -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem sprinkleParameter_ge_left (p a : unitInterval) : p ≤ sprinkleParameter p a := by - change (p:ℝ) ≤ (p:ℝ)+(1-(p:ℝ))*(a:ℝ) - exact le_add_of_nonneg_right (mul_nonneg (sub_nonneg.mpr p.2.2) a.2.1) - - - -theorem susceptibility_sprinkling_gain [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p a : unitInterval) (hq : sprinkleParameter p a < pc G) (x : V) - (Q : Finset E) (F : Finset V) : - (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * - (∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω x y} e)) ≤ - susceptibility G (sprinkleParameter p a) x - susceptibility G p x := by - have hpa := sprinkleParameter_ge_left p a - have hp : p < pc G := lt_of_le_of_lt hpa hq - have hsum := (summable_twoPoint_subcritical G hloc hqt (sprinkleParameter p a) hq x).sub - (summable_twoPoint_subcritical G hloc hqt p hp x) - calc - _ = ∑ y ∈ F, (a:ℝ)*(1-(a:ℝ))^(Q.card-1)* - (∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω x y} e)) := Finset.mul_sum _ _ _ - _ ≤ ∑ y ∈ F, (twoPoint G (sprinkleParameter p a) x y - twoPoint G p x y) := by - apply Finset.sum_le_sum - intro y _ - exact event_sprinkling_gain p a Q {ω | Conn G ω x y} (measurableSet_conn G x y) - (fun _ _ h hc => conn_mono G h hc) - _ ≤ ∑' y, (twoPoint G (sprinkleParameter p a) x y - twoPoint G p x y) := - hsum.sum_le_tsum F (fun y _ => sub_nonneg.mpr (twoPoint_mono G x y hpa)) - _ = _ := (summable_twoPoint_subcritical G hloc hqt (sprinkleParameter p a) hq x).tsum_sub - (summable_twoPoint_subcritical G hloc hqt p hp x) - - -theorem rootSusceptibility_sprinkling_gain [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (p a : unitInterval) (hq : sprinkleParameter p a < pc G) - (Q : Finset E) (F : Finset V) : - (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * - (∑ i, weight i*(∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω (root i) y} e))) ≤ - rootSusceptibility G root weight (sprinkleParameter p a) - rootSusceptibility G root weight p := by - rw [rootSusceptibility,rootSusceptibility,←Finset.sum_sub_distrib,Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - have h := mul_le_mul_of_nonneg_left - (susceptibility_sprinkling_gain G hloc hqt p a hq (root i) Q F) (hw i) - convert h using 1 <;> ring - -end SusceptibilityPivotalGain -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section OrientedPivotalConnections -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def orientedPivotalEvent (G : BondGraph V E) (x y a b : V) : Set (Set E) := - {ω | Conn G ω x a ∧ Conn G ω b y ∧ ¬ Conn G ω a b} - -theorem measurableSet_orientedPivotalEvent [Countable V] [Countable E] - (G : BondGraph V E) (x y a b : V) : MeasurableSet (orientedPivotalEvent G x y a b) := - (measurableSet_conn G x a).inter ((measurableSet_conn G b y).inter (measurableSet_conn G a b).compl) - -theorem orientedPivotalEvent_disjoint (G : BondGraph V E) (x y a b : V) : - Disjoint (orientedPivotalEvent G x y a b) (orientedPivotalEvent G x y b a) := by - apply Set.disjoint_left.mpr - intro ω h h' - exact h.2.2 ((conn_symm G ω h.1).trans h'.1) - -theorem closedPivotal_conn (G : BondGraph V E) (e : E) (a b x y : V) - (he : G e = s(a,b)) : - closedPivotal {ω | Conn G ω x y} e = - orientedPivotalEvent G x y a b ∪ orientedPivotalEvent G x y b a := by - ext ω - constructor - · rintro ⟨_,hn,hc⟩ - rcases (conn_insert_iff G ω e a b x y he).mp hc with h | h | h - · exact (hn h).elim - · exact Or.inl ⟨h.1,h.2,fun hab => hn (h.1.trans (hab.trans h.2))⟩ - · exact Or.inr ⟨h.1,h.2,fun hba => hn (h.1.trans (hba.trans h.2))⟩ - · intro h - have hi : ∀ a b : V, G e = s(a,b) → ω ∈ orientedPivotalEvent G x y a b → - ω ∈ closedPivotal {ω | Conn G ω x y} e := by - intro a b he h - refine ⟨?_,?_,?_⟩ - · intro heω - exact h.2.2 (.single ⟨e,heω,he⟩) - · intro hxy - exact h.2.2 ((conn_symm G ω h.1).trans (hxy.trans (conn_symm G ω h.2.1))) - · exact (conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨h.1,h.2.1⟩)) - exact h.elim (hi a b he) (hi b a (he.trans (Sym2.eq_swap ..))) - -theorem closedPivotal_conn_probability [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (e : E) (a b x y : V) (he : G e = s(a,b)) : - (law p).real (closedPivotal {ω | Conn G ω x y} e) = - (law p).real (orientedPivotalEvent G x y a b) + - (law p).real (orientedPivotalEvent G x y b a) := by - rw [closedPivotal_conn G e a b x y he] - exact measureReal_union (orientedPivotalEvent_disjoint G x y a b) - (measurableSet_orientedPivotalEvent G x y b a) - - -theorem orientedPivotalEvent_subset_disjoint (G : BondGraph V E) (x y a b : V) : - orientedPivotalEvent G x y a b ⊆ - DisjointOccurrence {ω | Conn G ω x a} {ω | Conn G ω b y} := by - intro ω hω - have hx : x ∈ cluster G ω a := conn_symm G ω hω.1 - have hb : b ∉ cluster G ω a := hω.2.2 - obtain ⟨Q,hQ,hQa⟩ := finiteWitness_conn G x a _ (conn_restrict_cluster G ω a hx hω.1) - obtain ⟨R,hR,hRb⟩ := finiteWitness_conn G b y _ (conn_restrict_cluster_compl G ω a hb hω.2.1) - refine ⟨Q,R,fun e he => (hQ he).1,fun e he => (hR he).1,?_,hQa,hRb⟩ - apply Finset.disjoint_left.mpr - intro e heQ heR - obtain ⟨⟨z,w⟩,he⟩ := Quot.exists_rep (G e) - have hz : z ∈ G e := by rw [←he]; exact Sym2.mem_mk_left z w - exact (hR heR).2 z hz ((hQ heQ).2 z hz) - -end OrientedPivotalConnections -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PivotalMomentIdentity -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem distinctClusterMass_eq_pivotal (G : BondGraph V E) (ω : Set E) (a b : V) : - (if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) = - ∑' x, ∑' y, if ω ∈ orientedPivotalEvent G x y a b then (1:ℝ≥0∞) else 0 := by - by_cases hab : Conn G ω a b - · simp only [hab,not_true_eq_false,ite_false,orientedPivotalEvent,Set.mem_ofPred_eq, - and_false,ite_false,tsum_zero] - · rw [ite_eq_left hab,clusterMass_mul] - apply tsum_congr - intro x - apply tsum_congr - intro y - apply if_congr _ rfl rfl - simp only [orientedPivotalEvent,Set.mem_ofPred_eq,hab,not_false_eq_true,and_true] - exact and_congr (show Conn G ω a x ↔ Conn G ω x a from ⟨conn_symm G ω,conn_symm G ω⟩) Iff.rfl - -theorem lintegral_distinctClusterMass [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (a b : V) : - (∫⁻ ω, (if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) ∂law p) = - ∑' x, ∑' y, law p (orientedPivotalEvent G x y a b) := by - have hm (x y : V) : Measurable (fun ω : Set E => - if ω ∈ orientedPivotalEvent G x y a b then (1:ℝ≥0∞) else 0) := - Measurable.ite (measurableSet_orientedPivotalEvent G x y a b) measurable_const measurable_const - simp_rw [distinctClusterMass_eq_pivotal] - rw [lintegral_tsum (fun x => (Measurable.tsum (fun y => hm x y)).aemeasurable)] - apply tsum_congr - intro x - rw [lintegral_tsum (fun y => (hm x y).aemeasurable)] - apply tsum_congr - intro y - simpa only [Set.indicator,Pi.one_apply] using - (lintegral_indicator_one (μ := law p) (measurableSet_orientedPivotalEvent G x y a b)) - -theorem ennreal_distinctClusterMoment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (a b : V) : - ENNReal.ofReal (distinctClusterMoment G p a b) = - ∑' x, ∑' y, law p (orientedPivotalEvent G x y a b) := by - have hi := integrable_distinct_cluster_product G hloc hqt p hp a b - have hn : 0 ≤ᵐ[law p] (fun ω => if ¬Conn G ω a b - then ((cluster G ω a).ncard:ℝ)*((cluster G ω b).ncard:ℝ) else 0) := by - exact Filter.Eventually.of_forall (fun ω => by dsimp only; split_ifs <;> positivity) - have he : (fun ω => ENNReal.ofReal (if ¬Conn G ω a b - then ((cluster G ω a).ncard:ℝ)*((cluster G ω b).ncard:ℝ) else 0)) =ᵐ[law p] - (fun ω => if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) := by - filter_upwards [subcritical_cluster_finite_ae G p hp a, - subcritical_cluster_finite_ae G p hp b] with ω ha hb - by_cases hab : Conn G ω a b - · simp only [hab,not_true_eq_false,ite_false,ENNReal.ofReal_zero] - · simp only [hab,not_false_eq_true,ite_true] - rw [clusterMass_eq_ncard G ω a ha,clusterMass_eq_ncard G ω b hb, - ENNReal.ofReal_mul (Nat.cast_nonneg _)] - simp only [ENNReal.ofReal_natCast] - rw [←lintegral_distinctClusterMass,←lintegral_congr_ae he] - exact ofReal_integral_eq_lintegral_ofReal hi hn - -theorem summable_orientedPivotal_pairs [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (a b : V) : - Summable (fun xy : V × V => (law p).real (orientedPivotalEvent G xy.1 xy.2 a b)) := by - apply ENNReal.summable_toReal - rw [ENNReal.tsum_prod',←ennreal_distinctClusterMoment G hloc hqt p hp a b] - exact ENNReal.ofReal_ne_top - -theorem distinctClusterMoment_eq_pivotal [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (a b : V) : - distinctClusterMoment G p a b = - ∑' x, ∑' y, (law p).real (orientedPivotalEvent G x y a b) := by - rw [←(summable_orientedPivotal_pairs G hloc hqt p hp a b).tsum_prod] - change distinctClusterMoment G p a b = - ∑' xy : V × V, (law p (orientedPivotalEvent G xy.1 xy.2 a b)).toReal - rw [←ENNReal.tsum_toReal_eq (f := fun xy : V × V => law p (orientedPivotalEvent G xy.1 xy.2 a b)) - (fun _ => measure_ne_top _ _), ENNReal.tsum_prod', - ←ennreal_distinctClusterMoment G hloc hqt p hp a b, - ENNReal.toReal_ofReal (distinctClusterMoment_nonneg G p a b)] - -end PivotalMomentIdentity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section PivotalTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem orientedPivotal_probability_covariant [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x y z w : V) : - (law p).real (orientedPivotalEvent G (a x) (a y) (a z) (a w)) = - (law p).real (orientedPivotalEvent G x y z w) := by - have he : orientedPivotalEvent G (a x) (a y) (a z) (a w) = - (fun ω => b ⁻¹' ω) ⁻¹' orientedPivotalEvent G x y z w := by - ext ω - simp only [orientedPivotalEvent,Set.mem_ofPred_eq,Set.mem_preimage,conn_aut_iff G hab] - unfold Measure.real - rw [he,←Measure.map_apply (measurable_set_preimage b) - (measurableSet_orientedPivotalEvent G x y z w),law_map_preimage_equiv] - -noncomputable def pivotalTransportMass (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x a : V) : ℝ := - ∑ b ∈ neighbors G hloc a, ∑' y, (law p).real (orientedPivotalEvent G x y a b) - -theorem pivotalTransportMass_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x a : V) : 0 ≤ pivotalTransportMass G hloc p x a := - Finset.sum_nonneg (fun _ _ => tsum_nonneg (fun _ => measureReal_nonneg)) - -theorem pivotalTransportMass_covariant [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x z : V) : - pivotalTransportMass G hloc p (a x) (a z) = pivotalTransportMass G hloc p x z := by - simp only [pivotalTransportMass,neighbors_covariant G hloc hab,Finset.sum_map,Equiv.coe_toEmbedding] - apply Finset.sum_congr rfl - intro w _ - rw [←a.tsum_eq (fun y => (law p).real (orientedPivotalEvent G (a x) y (a z) (a w)))] - exact tsum_congr (fun y => orientedPivotal_probability_covariant G p hab x y z w) - -theorem pivotalTransportMass_incoming_summable [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (a : V) : - Summable (fun x => pivotalTransportMass G hloc p x a) := by - apply summable_sum - intro b _ - exact (summable_orientedPivotal_pairs G hloc hqt p hp a b).prod - -theorem pivotalTransportMass_incoming [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (a : V) : - (∑' x, pivotalTransportMass G hloc p x a) = neighborClusterMoment G hloc p a := by - unfold pivotalTransportMass neighborClusterMoment - rw [Summable.tsum_finsetSum (fun b _ => - (summable_orientedPivotal_pairs G hloc hqt p hp a b).prod)] - exact Finset.sum_congr rfl (fun b _ => (distinctClusterMoment_eq_pivotal G hloc hqt p hp a b).symm) - -end PivotalTransport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section PivotalTransportTotal -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem pivotalTransportMass_outgoing_summable - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (x : V) : - Summable (pivotalTransportMass G hloc p x) := by - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - exact (transported_column_of_row_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin - (fun a x => pivotalTransportMass G hloc p x a) - (fun a x => pivotalTransportMass_nonneg G hloc p x a) - (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact pivotalTransportMass_covariant G hloc p hab y x) - (pivotalTransportMass_incoming_summable G hloc hqt p hp) - (c*rootNeighborMoment G hloc root weight p) - (fun a => by - rw [pivotalTransportMass_incoming G hloc hqt p hp] - exact neighborMoment_le_rootMoment G hloc root weight hw hcover c hc hmin p a) x).1 - - - -theorem rootPivotalMass_eq_neighborMoment - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) : - (∑ i, weight i * ∑' a, pivotalTransportMass G hloc p (root i) a) = - rootNeighborMoment G hloc root weight p := by - rw [htr.real root weight Γ (pivotalTransportMass G hloc p) - (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact pivotalTransportMass_covariant G hloc p hab x y) - (pivotalTransportMass_outgoing_summable G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp) - (pivotalTransportMass_incoming_summable G hloc hqt p hp)] - exact Finset.sum_congr rfl (fun i _ => congrArg (fun t => weight i*t) - (pivotalTransportMass_incoming G hloc hqt p hp (root i))) - -end PivotalTransportTotal -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FinitePivotalComparison -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem orientedPivotal_probability_le_closed [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (e : E) (x y a b : V) (he : G e = s(a,b)) : - (law p).real (orientedPivotalEvent G x y a b) ≤ - (law p).real (closedPivotal {ω | Conn G ω x y} e) := by - rw [closedPivotal_conn_probability G p e a b x y he] - exact le_add_of_nonneg_right measureReal_nonneg - - - -theorem finite_neighbor_pivotal_le_incident [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y a : V) : - (∑ b ∈ neighbors G hloc a, (law p).real (orientedPivotalEvent G x y a b)) ≤ - ∑ e ∈ (hloc a).toFinset, (law p).real (closedPivotal {ω | Conn G ω x y} e) := by - let B := neighbors G hloc a - have he (b : B) : ∃ e, G e = s(a,(b:V)) := (mem_neighbors G hloc a b).mp b.property - choose edge hedge using he - have hinj : Function.Injective edge := by - intro b c h - apply Subtype.ext - have hh := (hedge b).symm.trans ((congrArg G h).trans (hedge c)) - rcases Sym2.eq_iff.mp hh with h | h - · exact h.2 - · exact h.2.trans h.1 - calc - _ = ∑ b : B, (law p).real (orientedPivotalEvent G x y a b) := (Finset.sum_coe_sort B _).symm - _ ≤ ∑ b : B, (law p).real (closedPivotal {ω | Conn G ω x y} (edge b)) := - Finset.sum_le_sum (fun b _ => orientedPivotal_probability_le_closed G p (edge b) x y a b (hedge b)) - _ = ∑ e ∈ Finset.univ.image edge, (law p).real (closedPivotal {ω | Conn G ω x y} e) := - (Finset.sum_image (f := fun e => (law p).real (closedPivotal {ω | Conn G ω x y} e)) - (s := Finset.univ) (fun _ _ _ _ h => hinj h)).symm - _ ≤ _ := by - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro e he - obtain ⟨b,_,rfl⟩ := Finset.mem_image.mp he - rw [Set.Finite.mem_toFinset] - change a ∈ G (edge b) - rw [hedge b] - exact Sym2.mem_mk_left _ _ - · intro _ _ _ - exact measureReal_nonneg - -theorem finite_incident_sum_le_twice (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset V) (f : E → ℝ) (hf : ∀ e, 0 ≤ f e) : - (∑ a ∈ A, ∑ e ∈ (hloc a).toFinset, f e) ≤ 2*∑ e ∈ incidentSupport G hloc A, f e := by - let Q := incidentSupport G hloc A - have heq (a : V) (ha : a ∈ A) : - (∑ e ∈ (hloc a).toFinset, f e) = ∑ e ∈ Q, if a ∈ G e then f e else 0 := by - rw [←Finset.sum_filter] - apply Finset.sum_congr _ (fun _ _ => rfl) - ext e - simp only [Set.Finite.mem_toFinset,Finset.mem_filter] - exact ⟨fun he => ⟨(mem_incidentSupport G hloc A e).mpr ⟨a,ha,he⟩,he⟩,fun h => h.2⟩ - calc - _ = ∑ a ∈ A, ∑ e ∈ Q, if a ∈ G e then f e else 0 := Finset.sum_congr rfl heq - _ = ∑ e ∈ Q, ∑ a ∈ A, if a ∈ G e then f e else 0 := Finset.sum_comm - _ ≤ ∑ e ∈ Q, 2*f e := by - apply Finset.sum_le_sum - intro e _ - have hsub : A.filter (fun a => a ∈ G e) ⊆ (G e).toFinset := by - intro a ha - exact Sym2.mem_toFinset.mpr (Finset.mem_filter.mp ha).2 - rw [←Finset.sum_filter,Finset.sum_const, nsmul_eq_mul] - have hc : (A.filter (fun a => a ∈ G e)).card ≤ 2 := (Finset.card_le_card hsub).trans (by - rw [Sym2.card_toFinset]; split_ifs <;> omega) - exact mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (hf e) - _ = _ := (Finset.mul_sum _ _ _).symm - -theorem finite_oriented_pivotal_sum_le [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) (A : Finset V) : - (∑ a ∈ A, ∑ b ∈ neighbors G hloc a, (law p).real (orientedPivotalEvent G x y a b)) ≤ - 2*∑ e ∈ incidentSupport G hloc A, (law p).real (closedPivotal {ω | Conn G ω x y} e) := by - exact (Finset.sum_le_sum (fun a _ => finite_neighbor_pivotal_le_incident G hloc p x y a)).trans - (finite_incident_sum_le_twice G hloc A _ (fun _ => measureReal_nonneg)) - -end FinitePivotalComparison -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section SubcriticalSusceptibilityContinuity -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem eventually_cluster_eq_at_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (labels : E → unitInterval) (p : unitInterval) (x : V) - (hneq : ∀ e, labels e ≠ p) (hfin : (cluster G (openEdges labels p) x).Finite) : - ∀ᶠ q in nhds p, cluster G (openEdges labels q) x = cluster G (openEdges labels p) x := by - let Q := incidentSupport G hloc hfin.toFinset - have he (e : E) : ∀ᶠ q in nhds p, (e ∈ openEdges labels q ↔ e ∈ openEdges labels p) := by - change ∀ᶠ q in nhds p, (labels e ≤ q ↔ labels e ≤ p) - by_cases hp : labels e ≤ p - · have hlt : labels e < p := lt_of_le_of_ne hp (hneq e) - filter_upwards [eventually_gt_nhds hlt] with q hq - exact iff_of_true hq.le hp - · have hlt : p < labels e := lt_of_not_ge hp - filter_upwards [eventually_lt_nhds hlt] with q hq - exact iff_of_false (not_le.mpr hq) hp - filter_upwards [(eventually_all_finset Q).mpr (fun e _ => he e)] with q hq - apply cluster_eq_of_incident_agreement G - intro e he - apply (hq e _).symm - obtain ⟨v,hv,hve⟩ := he - exact (mem_incidentSupport G hloc hfin.toFinset e).mpr ⟨v,hfin.mem_toFinset.mpr hv,hve⟩ - -theorem label_cluster_finite_ae_subcritical [Countable E] - (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (x : V) : - ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), (cluster G (openEdges labels p) x).Finite := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges p).aemeasurable - rw [map_openEdges] - exact subcritical_cluster_finite_ae G p hp x - -theorem susceptibility_eq_label_integral [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Integrable (fun labels : E → unitInterval => ((cluster G (openEdges labels p) x).ncard:ℝ)) labelLaw ∧ - susceptibility G p x = ∫ labels : E → unitInterval, ((cluster G (openEdges labels p) x).ncard:ℝ) ∂labelLaw := by - obtain ⟨hi,he⟩ := susceptibility_eq_integral G hloc hqt p hp x - have hi' : Integrable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)) - ((labelLaw : Measure (E → unitInterval)).map (fun labels => openEdges labels p)) := by - rwa [map_openEdges] - refine ⟨hi'.comp_measurable (measurable_openEdges p),?_⟩ - rw [he,←integral_map (measurable_openEdges p).aemeasurable hi'.aestronglyMeasurable,map_openEdges] - - - -theorem continuousAt_susceptibility_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : ContinuousAt (fun q => susceptibility G q x) p := by - obtain ⟨r,hpr,hr⟩ := exists_between hp - let F (q : unitInterval) (labels : E → unitInterval) : ℝ := ((cluster G (openEdges labels q) x).ncard:ℝ) - have hm (q : unitInterval) : Measurable (F q) := - (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp - ((measurable_cluster_ncard G hloc x).comp (measurable_openEdges q)) - have hcont : ContinuousAt (fun q => ∫ labels, F q labels ∂labelLaw) p := by - apply continuousAt_of_dominated - (bound := F r) (Filter.Eventually.of_forall (fun q => (hm q).aestronglyMeasurable)) - · filter_upwards [eventually_lt_nhds hpr] with q hqr - filter_upwards [label_cluster_finite_ae_subcritical G r hr x] with labels hfin - rw [Real.norm_of_nonneg (Nat.cast_nonneg _)] - dsimp only [F] - exact_mod_cast Set.ncard_le_ncard (show cluster G (openEdges labels q) x ⊆ cluster G (openEdges labels r) x from - fun y hy => conn_mono G (openEdges_mono labels hqr.le) hy) hfin - · exact (susceptibility_eq_label_integral G hloc hqt r hr x).1 - · filter_upwards [ae_labels_ne (E := E) p,label_cluster_finite_ae_subcritical G p hp x] with labels hneq hfin - apply Filter.EventuallyEq.continuousAt - filter_upwards [eventually_cluster_eq_at_finite G hloc labels p x hneq hfin] with q hq - exact congrArg (fun S : Set V => (S.ncard:ℝ)) hq - apply (continuousAt_congr _).mpr hcont - filter_upwards [eventually_lt_nhds hp] with q hq - exact (susceptibility_eq_label_integral G hloc hqt q hq x).2 - -theorem continuousAt_rootSusceptibility_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (p : unitInterval) (hp : p < pc G) : - ContinuousAt (rootSusceptibility G root weight) p := by - exact tendsto_finsetSum Finset.univ (fun i _ => continuousAt_const.mul - (continuousAt_susceptibility_subcritical G hloc hqt p hp (root i))) - -end SubcriticalSusceptibilityContinuity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section FiniteRootPivotalApproximation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem summable_orientedPivotal_targets [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x a b : V) : - Summable (fun y => (law p).real (orientedPivotalEvent G x y a b)) := by - apply (summable_twoPoint_subcritical G hloc hqt p hp b).of_nonneg_of_le - · exact fun _ => measureReal_nonneg - · intro y - exact measureReal_mono (fun _ h => h.2.1) - -noncomputable def finiteRootPivotalMass (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (p : unitInterval) (Q : Finset E) (F : Finset V) : ℝ := - ∑ i, weight i*(∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω (root i) y} e)) - -theorem finiteRootPivotalMass_nonneg (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (p : unitInterval) (Q : Finset E) (F : Finset V) : - 0 ≤ finiteRootPivotalMass G root weight p Q F := - Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) - (Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => measureReal_nonneg)))) - - - -theorem exists_finiteRootPivotalMass_gt - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (B : ℝ) - (hB : B < rootNeighborMoment G hloc root weight p / 2) : - ∃ Q : Finset E, ∃ F : Finset V, B < finiteRootPivotalMass G root weight p Q F := by - have hs (x : V) := pivotalTransportMass_outgoing_summable G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp x - let f (a : V) := ∑ i, weight i*pivotalTransportMass G hloc p (root i) a - have hsf : Summable f := summable_sum (fun i _ => (hs (root i)).mul_left (weight i)) - have htf : (∑' a, f a) = rootNeighborMoment G hloc root weight p := by - rw [Summable.tsum_finsetSum (fun i _ => (hs (root i)).mul_left (weight i))] - simp_rw [tsum_mul_left] - exact rootPivotalMass_eq_neighborMoment G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp - have hB' : 2*B < ∑' a, f a := by rw [htf]; linarith - obtain ⟨A,hA⟩ := ((tendsto_order.mp hsf.hasSum).1 (2*B) hB').exists - let g (y : V) := ∑ i, weight i*(∑ a ∈ A, ∑ b ∈ neighbors G hloc a, - (law p).real (orientedPivotalEvent G (root i) y a b)) - have hst (i : ι) (a b : V) := summable_orientedPivotal_targets G hloc hqt p hp (root i) a b - have hsg : Summable g := summable_sum (fun i _ => - (summable_sum (fun a _ => summable_sum (fun b _ => hst i a b))).mul_left (weight i)) - have htg : (∑' y, g y) = ∑ a ∈ A, f a := by - rw [Summable.tsum_finsetSum (fun i _ => - (summable_sum (fun a _ => summable_sum (fun b _ => hst i a b))).mul_left (weight i))] - simp_rw [tsum_mul_left] - simp_rw [Summable.tsum_finsetSum (fun a _ => summable_sum (fun b _ => hst _ a b))] - simp_rw [Summable.tsum_finsetSum (fun b _ => hst _ _ b)] - simp only [f,Finset.mul_sum,pivotalTransportMass] - rw [Finset.sum_comm] - obtain ⟨F,hF⟩ := ((tendsto_order.mp hsg.hasSum).1 (2*B) (by rwa [htg])).exists - refine ⟨incidentSupport G hloc A,F,?_⟩ - have hb : (∑ y ∈ F, g y) ≤ 2*finiteRootPivotalMass G root weight p (incidentSupport G hloc A) F := by - unfold g finiteRootPivotalMass - rw [Finset.sum_comm, Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - rw [← Finset.mul_sum, mul_left_comm] - apply mul_le_mul_of_nonneg_left _ (hw i) - rw [Finset.mul_sum] - exact Finset.sum_le_sum (fun y _ => finite_oriented_pivotal_sum_le G hloc p (root i) y A) - linarith - -end FiniteRootPivotalApproximation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section VanishingSprinkles -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def vanishingSprinkle (n : ℕ) : unitInterval := - ⟨1/((n:ℝ)+1), by - constructor - · positivity - · apply (div_le_one (by positivity : 0 < (n:ℝ)+1)).mpr - linarith [show (0:ℝ) ≤ (n:ℝ) by positivity] - ⟩ - -theorem vanishingSprinkle_pos (n : ℕ) : 0 < (vanishingSprinkle n : ℝ) := by - dsimp [vanishingSprinkle] - positivity - -theorem tendsto_vanishingSprinkle : - Tendsto (fun n => (vanishingSprinkle n:ℝ)) atTop (nhds 0) := - tendsto_one_div_add_atTop_nhds_zero_nat - -theorem sprinkle_sequence_gt (p : unitInterval) (hp : (p:ℝ) < 1) (n : ℕ) : - p < sprinkleParameter p (vanishingSprinkle n) := by - change (p:ℝ) < (p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ) - exact lt_add_of_pos_right _ (mul_pos (sub_pos.mpr hp) (vanishingSprinkle_pos n)) - -theorem tendsto_sprinkle_sequence (p : unitInterval) : - Tendsto (fun n => sprinkleParameter p (vanishingSprinkle n)) atTop (nhds p) := by - apply tendsto_subtype_rng.mpr - change Tendsto (fun n => (p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ)) atTop (nhds (p:ℝ)) - convert tendsto_const_nhds.add (tendsto_const_nhds.mul tendsto_vanishingSprinkle) using 1; simp - -theorem tendsto_sprinkle_sequence_right (p : unitInterval) (hp : (p:ℝ) < 1) : - Tendsto (fun n => (sprinkleParameter p (vanishingSprinkle n):ℝ)) atTop (nhdsWithin (p:ℝ) (Set.Ioi (p:ℝ))) := by - apply tendsto_nhdsWithin_iff.mpr - exact ⟨continuous_subtype_val.continuousAt.tendsto.comp (tendsto_sprinkle_sequence p), - Eventually.of_forall (sprinkle_sequence_gt p hp)⟩ - - - -theorem rootSusceptibility_sequence_slope_lower - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (p : unitInterval) (hp : p < pc G) (Q : Finset E) (F : Finset V) (d : ℝ) - (hd : d < finiteRootPivotalMass G root weight p Q F) : - ∀ᶠ n in atTop, - ((sprinkleParameter p (vanishingSprinkle n):ℝ)-(p:ℝ))*d ≤ - rootSusceptibility G root weight (sprinkleParameter p (vanishingSprinkle n)) - - rootSusceptibility G root weight p := by - have ht : Tendsto (fun n => (1-(vanishingSprinkle n:ℝ))^(Q.card-1) * - finiteRootPivotalMass G root weight p Q F) atTop - (nhds (finiteRootPivotalMass G root weight p Q F)) := by - convert ((tendsto_const_nhds.sub tendsto_vanishingSprinkle).pow (Q.card-1)).mul tendsto_const_nhds using 1; simp - have hnn := finiteRootPivotalMass_nonneg G root weight hw p Q F - filter_upwards [(tendsto_sprinkle_sequence p).eventually (eventually_lt_nhds hp), - ht.eventually (eventually_gt_nhds hd)] with n hn hdn - have hgain := rootSusceptibility_sprinkling_gain G hloc hqt root weight hw - p (vanishingSprinkle n) hn Q F - change (vanishingSprinkle n:ℝ)*(1-(vanishingSprinkle n:ℝ))^(Q.card-1)* - finiteRootPivotalMass G root weight p Q F ≤ _ at hgain - by_cases hd0 : 0 ≤ d - · have hdp : (1-(p:ℝ))*d ≤ (1-(vanishingSprinkle n:ℝ))^(Q.card-1)* - finiteRootPivotalMass G root weight p Q F := by - calc - _ ≤ d := by nlinarith [p.2.1] - _ ≤ _ := hdn.le - have hm := mul_le_mul_of_nonneg_left hdp (vanishingSprinkle n).2.1 - calc - _ = (vanishingSprinkle n:ℝ)*((1-(p:ℝ))*d) := by - change ((p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ)-(p:ℝ))*d = _ - ring - _ ≤ (vanishingSprinkle n:ℝ)*((1-(vanishingSprinkle n:ℝ))^(Q.card-1)* - finiteRootPivotalMass G root weight p Q F) := hm - _ ≤ _ := by simpa only [mul_assoc] using hgain - · have hmono : 0 ≤ rootSusceptibility G root weight (sprinkleParameter p (vanishingSprinkle n)) - rootSusceptibility G root weight p := - (mul_nonneg (mul_nonneg (vanishingSprinkle n).2.1 (pow_nonneg (sub_nonneg.mpr (vanishingSprinkle n).2.2) _)) hnn).trans hgain - have hdp : ((sprinkleParameter p (vanishingSprinkle n):ℝ)-(p:ℝ))*d ≤ 0 := - mul_nonpos_of_nonneg_of_nonpos (sub_nonneg.mpr (sprinkleParameter_ge_left _ _)) (le_of_not_ge hd0) - linarith - -end VanishingSprinkles -end Percolation - - -namespace Percolation -open Filter -section NegativePowerRightSlopes - - - -theorem frequently_rpow_slope_le_of_sequence - (f : ℝ → ℝ) (x d e : ℝ) (hx : 0 < f x) (hd : 0 < d) (he : e < 0) - (z : ℕ → ℝ) (hz : Tendsto z atTop (nhdsWithin x (Set.Ioi x))) - (hgain : ∀ᶠ n in atTop, (z n-x)*d ≤ f (z n)-f x) : - ∀ r, e*(f x)^(e-1)*d < r → - ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope (fun t => (f t)^e) x y < r := by - let A (t : ℝ) := f x+(t-x)*d - have hA : HasDerivAt A d x := by - simpa only [zero_add, one_mul] using! (hasDerivAt_const x (f x)).add (((hasDerivAt_id x).sub_const x).mul_const d) - have hAx : A x = f x := by simp [A] - have hR : HasDerivAt (fun t => (A t)^e) (e*(f x)^(e-1)*d) x := by - simpa only [hAx] using! (Real.hasDerivAt_rpow_const (p := e) (Or.inl (show A x ≠ 0 by rw [hAx]; exact hx.ne'))).comp x hA - intro r hr - have hlim := hR.tendsto_slope.comp (hz.mono_right (nhdsWithin_mono x (show Set.Ioi x ⊆ {x}ᶜ from fun y hy => by simpa using ne_of_gt hy))) - have hright : ∀ᶠ n in atTop, x < z n := (tendsto_nhdsWithin_iff.mp hz).2 - apply hz.frequently - apply Filter.Eventually.frequently - filter_upwards [hgain, hright, hlim.eventually (eventually_lt_nhds hr)] with n hn hzn hnr - have hApos : 0 < A (z n) := by dsimp [A]; positivity - have hAr : A (z n) ≤ f (z n) := by dsimp [A]; linarith - have hp := Real.rpow_le_rpow_of_nonpos hApos hAr he.le - apply lt_of_le_of_lt _ hnr - simp only [Function.comp_apply, slope_def_field, hAx] - exact div_le_div_of_nonneg_right (sub_le_sub_right hp _) (sub_pos.mpr hzn).le - -end NegativePowerRightSlopes -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section ActualSusceptibilityRightSlope -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def realRootSusceptibility (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := - rootSusceptibility G root weight (Set.projIcc 0 1 zero_le_one t) - -@[simp] theorem realRootSusceptibility_coe (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : - realRootSusceptibility G root weight (p:ℝ) = rootSusceptibility G root weight p := by - simp only [realRootSusceptibility, Set.projIcc_val] - -theorem rootSusceptibility_one_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (p : unitInterval) (hp : p < pc G) : 1 ≤ rootSusceptibility G root weight p := by - calc - 1 = ∑ i, weight i*1 := by simp only [mul_one, hw1] - _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left - (susceptibility_one_le G hloc hqt p hp (root i)) (hw i)) - -theorem continuousAt_realRootSusceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (p : unitInterval) (hp : p < pc G) : - ContinuousAt (realRootSusceptibility G root weight) (p:ℝ) := by - apply ContinuousAt.comp (f := Set.projIcc 0 1 zero_le_one) - · simpa only [Set.projIcc_val] using continuousAt_rootSusceptibility_subcritical G hloc hqt root weight p hp - · exact continuous_projIcc.continuousAt - - - -theorem rootSusceptibility_power_right_slope - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (b γ : ℝ) (hb : 0 < b) (hγ : γ < 1) - (hD : b*(rootSusceptibility G root weight p)^(2-γ) ≤ rootNeighborMoment G hloc root weight p) : - ∀ r, -(1-γ)*b/4 < r → ∃ᶠ y in nhdsWithin (p:ℝ) (Set.Ioi (p:ℝ)), - slope (fun t => (realRootSusceptibility G root weight t)^(γ-1)) (p:ℝ) y < r := by - let χ := rootSusceptibility G root weight p - have hχ : 0 < χ := lt_of_lt_of_le zero_lt_one (rootSusceptibility_one_le G hloc hqt root weight hw hw1 p hp) - let d := (b/4)*χ^(2-γ) - have hd : 0 < d := mul_pos (by positivity) (Real.rpow_pos_of_pos hχ _) - have hBd : d < rootNeighborMoment G hloc root weight p/2 := by - dsimp [d, χ] at * - nlinarith [Real.rpow_pos_of_pos hχ (2-γ)] - obtain ⟨Q,F,hQ⟩ := exists_finiteRootPivotalMass_gt G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp d hBd - have hg := rootSusceptibility_sequence_slope_lower G hloc hqt root weight hw p hp Q F d hQ - have hp1 : (p:ℝ) < 1 := lt_of_lt_of_le hp (pc G).2.2 - have hsl := frequently_rpow_slope_le_of_sequence (realRootSusceptibility G root weight) - (p:ℝ) d (γ-1) (by simpa only [realRootSusceptibility_coe] using hχ) hd (by linarith) - (fun n => (sprinkleParameter p (vanishingSprinkle n):ℝ)) (tendsto_sprinkle_sequence_right p hp1) - (by simpa only [realRootSusceptibility_coe] using hg) - have heq : (γ-1)*(realRootSusceptibility G root weight (p:ℝ))^(γ-1-1)*d = -(1-γ)*b/4 := by - rw [realRootSusceptibility_coe] - change (γ-1)*χ^(γ-1-1)*((b/4)*χ^(2-γ)) = _ - rw [show γ-1-1 = γ-2 by ring] - calc - _ = ((γ-1)*b/4)*(χ^(γ-2)*χ^(2-γ)) := by ring - _ = _ := by rw [←Real.rpow_add hχ, sub_add_sub_cancel, sub_self, Real.rpow_zero]; ring - rwa [heq] at hsl - -end ActualSusceptibilityRightSlope -end Percolation - - -namespace Percolation -open Filter -section IntegratedRightSlopes - - - -theorem interval_decrease_of_right_slope (f : ℝ → ℝ) (a b k : ℝ) - (hab : a ≤ b) (hf : ContinuousOn f (Set.Icc a b)) - (hs : ∀ x ∈ Set.Ico a b, ∀ r, -k < r → - ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope f x y < r) : - k*(b-a) ≤ f a-f b := by - let B (t : ℝ) := f a-k*(t-a) - have hB : ContinuousOn B (Set.Icc a b) := by fun_prop - have hB' (x : ℝ) : HasDerivAt B (-k) x := by - simpa only [one_mul, sub_zero, mul_one, zero_sub] using! - (hasDerivAt_const x (f a)).sub (((hasDerivAt_id x).sub_const a).const_mul k) - have h := image_le_of_liminf_slope_right_le_deriv_boundary hf - (show f a ≤ B a by simp [B]) hB (fun x _ => (hB' x).hasDerivWithinAt) hs ⟨hab,le_rfl⟩ - dsimp [B] at h - linarith - - - -theorem right_slope_distance_bound (f : ℝ → ℝ) (a b k : ℝ) - (hab : a < b) (hk : 0 < k) - (hpos : ∀ x ∈ Set.Ico a b, 0 ≤ f x) - (hc : ContinuousOn f (Set.Ico a b)) - (hs : ∀ x ∈ Set.Ico a b, ∀ r, -k < r → - ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope f x y < r) : - k*(b-a) ≤ f a := by - have hbound (r : ℝ) (hr : r ∈ Set.Ico a b) : k*(r-a) ≤ f a := by - have hsub : Set.Icc a r ⊆ Set.Ico a b := fun t ht => ⟨ht.1,lt_of_le_of_lt ht.2 hr.2⟩ - have h := interval_decrease_of_right_slope f a r k hr.1 (hc.mono hsub) - (fun x hx => hs x ⟨hx.1,lt_trans hx.2 hr.2⟩) - linarith [hpos r hr] - by_contra h - have hd : a+f a/k < b := by - have hh : f a < k*(b-a) := lt_of_not_ge h - have hv : f a/k < b-a := (div_lt_iff₀ hk).mpr (by nlinarith) - linarith - obtain ⟨r,hr1,hr2⟩ := exists_between hd - have ha : a ≤ r := by - have hf := hpos a ⟨le_rfl,hab⟩ - have hd0 := div_nonneg hf hk.le - linarith - have hb := hbound r ⟨ha,hr2⟩ - have hr : f a < (r-a)*k := (div_lt_iff₀ hk).mp (by linarith : f a/k < r-a) - nlinarith - -end IntegratedRightSlopes -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section ActualIntegratedSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem susceptibility_bound_of_neighborMoment - [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (b γ : ℝ) (hb : 0 < b) (hγ : γ < 1) - (hD : ∀ q, p ≤ q → q < pc G → b*(rootSusceptibility G root weight q)^(2-γ) ≤ - rootNeighborMoment G hloc root weight q) : - rootSusceptibility G root weight p ≤ - (((1-γ)*b/4)*((pc G:ℝ)-(p:ℝ)))^(-1/(1-γ)) := by - let k := (1-γ)*b/4 - have hk : 0 < k := by dsimp [k]; positivity - let f (t : ℝ) := (realRootSusceptibility G root weight t)^(γ-1) - have hparam (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : t ∈ Set.Icc (0:ℝ) 1 := - ⟨le_trans p.2.1 ht.1, le_trans ht.2.le (pc G).2.2⟩ - have hcp (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : - ContinuousAt (realRootSusceptibility G root weight) t := - continuousAt_realRootSusceptibility G hloc hqt root weight ⟨t,hparam t ht⟩ ht.2 - have hpos (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : - 0 < realRootSusceptibility G root weight t := by - have hh := rootSusceptibility_one_le G hloc hqt root weight hw hw1 ⟨t,hparam t ht⟩ ht.2 - rw [←realRootSusceptibility_coe] at hh - exact lt_of_lt_of_le zero_lt_one hh - have hcont : ContinuousOn f (Set.Ico (p:ℝ) (pc G:ℝ)) := by - intro t ht - exact ((hcp t ht).rpow_const (Or.inl (hpos t ht).ne')).continuousWithinAt - have hs (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) := - rootSusceptibility_power_right_slope G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin - ⟨t,hparam t ht⟩ ht.2 b γ hb hγ (hD ⟨t,hparam t ht⟩ ht.1 ht.2) - have hdist : k*((pc G:ℝ)-(p:ℝ)) ≤ f (p:ℝ) := by - apply right_slope_distance_bound f (p:ℝ) (pc G:ℝ) k hp hk - (fun t ht => (Real.rpow_pos_of_pos (hpos t ht) _).le) hcont - intro t ht r hr - apply hs t ht r - dsimp [k] at hr - linarith - have hχ := lt_of_lt_of_le zero_lt_one (rootSusceptibility_one_le G hloc hqt root weight hw hw1 p hp) - have hd : 0 < k*((pc G:ℝ)-(p:ℝ)) := mul_pos hk (sub_pos.mpr hp) - have he : -1/(1-γ) = 1/(γ-1) := by rw [show γ-1=-(1-γ) by ring, div_neg, neg_div] - have he0 : 1/(γ-1) < 0 := one_div_neg.mpr (by linarith) - have hinv := Real.rpow_le_rpow_of_nonpos hd hdist he0.le - rw [he] - apply le_trans _ hinv - change rootSusceptibility G root weight p ≤ - ((realRootSusceptibility G root weight (p:ℝ))^(γ-1))^(1/(γ-1)) - rw [realRootSusceptibility_coe,←Real.rpow_mul hχ.le] - rw [mul_one_div_cancel (by linarith : γ-1 ≠ 0),Real.rpow_one] - -end ActualIntegratedSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section SusceptibilityGrowthConsequence -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem eventually_upper_interval_unit (p₀ : unitInterval) (P : unitInterval → Prop) - (h : ∀ᶠ p in nhds p₀, P p) : - ∀ᶠ p in nhds p₀, p < p₀ → ∀ q, p ≤ q → q < p₀ → P q := by - obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp h - apply Metric.eventually_nhds_iff.mpr - refine ⟨ε,hε,?_⟩ - intro p hp hpp q hpq hq - apply hball - have hd : dist q p₀ ≤ dist p p₀ := by - change |(q:ℝ)-(p₀:ℝ)| ≤ |(p:ℝ)-(p₀:ℝ)| - rw [abs_of_nonpos (sub_nonpos.mpr (show (q:ℝ) ≤ (p₀:ℝ) from hq.le)),abs_of_nonpos (sub_nonpos.mpr (show (p:ℝ) ≤ (p₀:ℝ) from hpp.le))] - have hpqR : (p:ℝ) ≤ (q:ℝ) := hpq - linarith - exact lt_of_le_of_lt hd hp - - - -theorem susceptibility_growth_of_divergent_moment - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) - (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) - (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G))) : - ∀ γ : ℝ, 0 < γ → γ < 1 → ∃ C : ℝ, 0 < C ∧ ∀ᶠ p in nhds (pc G), p < pc G → - rootSusceptibility G root weight p ≤ C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ)) := by - intro γ hγ hγ1 - obtain ⟨b,hb,hnear⟩ := neighborMoment_growth_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr - hcov hw hw1 (pc G) hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv γ hγ - let c : ℝ := ∑ i, 1/weight i - have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) - have hmin (i : ι) : 1 ≤ c*weight i := by - apply (div_le_iff₀ (hw i)).mp - exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) - let k := (1-γ)*b/4 - have hk : 0 < k := by dsimp [k]; positivity - refine ⟨k^(-1/(1-γ)),Real.rpow_pos_of_pos hk _,?_⟩ - filter_upwards [eventually_upper_interval_unit (pc G) _ hnear] with p hp - intro hpc - have hD (q : unitInterval) (hpq : p ≤ q) (hq : q < pc G) := hp hpc q hpq hq hq - have hs := susceptibility_bound_of_neighborMoment G hconn hloc hqt root weight Γ hΓ htr hcov - (fun i => (hw i).le) hw1 c hc hmin p hpc b γ hb hγ1 hD - rwa [Real.mul_rpow hk.le (sub_pos.mpr (show (p:ℝ) < (pc G:ℝ) from hpc)).le] at hs - -end SusceptibilityGrowthConsequence -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section MarkedSearchTransfer -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem exponential_transfer_of_deriv_bound (H : ℝ → ℝ) (a b K : ℝ) - (hH : Differentiable ℝ H) (hab : a ≤ b) - (hb : ∀ t ∈ Set.Icc a b, deriv H t ≤ K*H t) : - H b ≤ Real.exp (K*(b-a))*H a := by - let F (t : ℝ) := Real.exp (-K*(t-a))*H t - have hF (t : ℝ) : HasDerivAt F (Real.exp (-K*(t-a))*(deriv H t-K*H t)) t := by - have he := (((hasDerivAt_id t).sub_const a).const_mul (-K)).exp - convert! he.mul (hH t).hasDerivAt using 1 - simp only [id_eq] - ring - have hanti : AntitoneOn F (Set.Icc a b) := by - apply antitoneOn_of_deriv_nonpos (convex_Icc a b) - (fun t _ => (hF t).continuousAt.continuousWithinAt) - (fun t _ => (hF t).differentiableAt.differentiableWithinAt) - intro t ht - rw [(hF t).deriv] - exact mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos _).le (sub_nonpos.mpr (hb t (interior_subset ht))) - have h := hanti ⟨le_rfl,hab⟩ ⟨hab,le_rfl⟩ hab - have hm := mul_le_mul_of_nonneg_left h (Real.exp_pos (K*(b-a))).le - simpa only [F, sub_self,mul_zero,Real.exp_zero,one_mul,←mul_assoc,←Real.exp_add, - neg_mul,add_neg_cancel,Real.exp_zero,one_mul,neg_zero,add_zero] using hm - - - -theorem markedConnection_transfer (G : BondGraph V E) (Q : Finset E) (x : V) - (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (p q h : unitInterval) (hp : 0 < (p:ℝ)) (hpq : p ≤ q) (hq : (q:ℝ) < 1) - (hh : 0 < (h:ℝ)) : - markedConnectionPolynomial G Q x h q ≤ - Real.exp ((Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ)))) * - Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*((q:ℝ)-(p:ℝ))) * - markedConnectionPolynomial G Q x h p := by - let H := markedConnectionPolynomial G Q x h - have hdiff : Differentiable ℝ H := fun t => (hasDerivAt_bernoulliPolynomial Q _ t).differentiableAt - apply exponential_transfer_of_deriv_bound H p q _ hdiff hpq - intro t ht - let r : unitInterval := ⟨t,⟨le_trans p.2.1 ht.1,le_trans ht.2 q.2.2⟩⟩ - have hr0 : 0 < t := lt_of_lt_of_le hp ht.1 - have hr1 : t < 1 := lt_of_le_of_lt ht.2 hq - have HB := markedConnection_derivative_bound G Q x r h hr1 hh d hd hdeg - have hH : 0 ≤ H t := by - change 0 ≤ markedConnectionPolynomial G Q x h r - rw [markedConnectionPolynomial_eq_tree] - exact ProbeTree.successMass_nonneg r h _ - have hs : 0 ≤ Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ)) := Real.sqrt_nonneg _ - have hden : (p:ℝ)*(1-(q:ℝ)) ≤ t*(1-t) := by - exact mul_le_mul ht.1 (by linarith [ht.2]) (sub_pos.mpr hq).le (by positivity) - have hratio : Real.sqrt ((d:ℝ)/2)/(t*(1-t)) ≤ - Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ))) := - div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (mul_pos hp (sub_pos.mpr hq)) hden - have hle : deriv H t ≤ (Real.sqrt ((d:ℝ)/2)/(t*(1-t)))* - Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*H t := by - have HBr : deriv H t ≤ ((Real.sqrt ((d:ℝ)/2)/(1-t))* - Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*H t)/t := by - apply (le_div_iff₀ hr0).mpr - simpa only [mul_comm (deriv H t) t] using HB - convert HBr using 1 - field_simp - exact hle.trans (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hratio hs) hH) - -end MarkedSearchTransfer -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section MarkedComponentIdentity -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem markedConnection_component_polynomial (G : BondGraph V E) - (Q : Finset E) (x : V) (h p : ℝ) : - markedConnectionPolynomial G Q x h p = - bernoulliPolynomial Q (fun ω => 1-(1-h)^(finiteRootComponent G ω x).card) p := by - apply bernoulliPolynomial_congr - intro ω hω - let C := finiteRootComponent G ω x - let F := insert x (searchVertices G Q) - have hCF : C ⊆ F := finiteRootComponent_subset G Q F x ω hω le_rfl - have he (m : Finset V) : (∃ y ∈ m, Conn G (ω:Set E) x y) ↔ m ∩ C ≠ ∅ := by - rw [Finset.nonempty_iff_ne_empty.symm] - constructor - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,Finset.mem_inter.mpr ⟨hy,by change y ∈ (C:Set V); simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hxy⟩⟩ - · rintro ⟨y,hy⟩ - refine ⟨y,(Finset.mem_inter.mp hy).1,?_⟩ - have hm : y ∈ (C:Set V) := (Finset.mem_inter.mp hy).2 - simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hm - have hid : bernoulliPolynomial F (fun m => if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0) h = - 1-bernoulliPolynomial F (fun m => if m ∩ C = ∅ then 1 else 0) h := by - calc - _ = bernoulliPolynomial F (fun m => 1-(if m ∩ C = ∅ then 1 else 0)) h := by - apply bernoulliPolynomial_congr - intro m _ - by_cases hm : m ∩ C = ∅ - · have hn : ¬∃ y ∈ m, Conn G (ω:Set E) x y := fun hc => (he m).mp hc hm - simp only [hm,hn,ite_false,ite_true,sub_self] - · have hy := (he m).mpr hm - simp only [hm,hy,ite_false,ite_true,sub_zero] - _ = _ := by rw [bernoulliPolynomial_sub,bernoulliPolynomial_const] - rw [hid,bernoulliPolynomial_restrict C F hCF (fun m => if m = ∅ then 1 else 0) h, - bernoulliPolynomial_empty_indicator] - -theorem one_sub_pow_one_sub_le (h : unitInterval) (n : ℕ) : - 1-(1-(h:ℝ))^n ≤ (h:ℝ)*n := by - induction n with - | zero => simp - | succ n ih => - rw [pow_succ,Nat.cast_succ] - have hm := mul_le_mul_of_nonneg_right ih (sub_nonneg.mpr h.2.2) - have hn : 0 ≤ (h:ℝ)^2*n := by positivity - nlinarith - -end MarkedComponentIdentity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section MarkedConnectionLaw -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem markedConnection_integral (G : BondGraph V E) (Q : Finset E) (x : V) - (h p : unitInterval) : - markedConnectionPolynomial G Q x h p = - ∫ ω, (1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard) ∂law p := by - rw [integral_eq_bernoulliPolynomial Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]), - markedConnection_component_polynomial] - apply bernoulliPolynomial_congr - intro ω hω - rw [Set.inter_eq_left.mpr (show (ω:Set E) ⊆ Q from hω)] - congr 2 - rw [←coe_finiteRootComponent,Set.ncard_coe_finset] - -theorem markedConnection_le_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (Q : Finset E) (x : V) (h p : unitInterval) (hp : p < pc G) : - markedConnectionPolynomial G Q x h p ≤ (h:ℝ)*susceptibility G p x := by - obtain ⟨hi,he⟩ := susceptibility_eq_integral G hloc hqt p hp x - rw [markedConnection_integral,he,←integral_const_mul] - apply integral_mono_ae - · exact integrable_finite_local Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]) - · exact hi.const_mul _ - · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - apply (one_sub_pow_one_sub_le h _).trans - apply mul_le_mul_of_nonneg_left _ h.2.1 - exact_mod_cast Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω - - - -theorem one_sub_pow_one_sub_ge_half (h : unitInterval) (n : ℕ) - (hn : 1 ≤ (h:ℝ)*n) : (1:ℝ)/2 ≤ 1-(1-(h:ℝ))^n := by - have hb (m : ℕ) : (1+(h:ℝ)*m)*(1-(h:ℝ))^m ≤ 1 := by - induction m with - | zero => simp - | succ m ih => - have hp : 0 ≤ (1-(h:ℝ))^m := pow_nonneg (sub_nonneg.mpr h.2.2) _ - have ha : (1+(h:ℝ)*(m+1))*(1-(h:ℝ)) ≤ 1+(h:ℝ)*m := by - have hh : 0 ≤ (h:ℝ)^2*((m:ℝ)+1) := by positivity - nlinarith - have hm := mul_le_mul_of_nonneg_right ha hp - rw [Nat.cast_succ,pow_succ] - nlinarith - have hp : 0 ≤ (1-(h:ℝ))^n := pow_nonneg (sub_nonneg.mpr h.2.2) _ - have hm := mul_le_mul_of_nonneg_right hn hp - have hb' := hb n - nlinarith - - - -theorem clusterWindow_le_markedConnection (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (lo hi : ℕ) (p h : unitInterval) (hh : 1 ≤ (h:ℝ)*lo) : - clusterWindowProbability G p x lo hi ≤ 2*markedConnectionPolynomial G - (incidentSupport G hloc (finite_reachBall hloc x hi).toFinset) x h p := by - let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset - let f (ω : Set E) := 1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard - let A := {ω | ClusterWindow G x lo hi ω} - have hA : MeasurableSet A := measurableSet_clusterWindow G hloc x lo hi - have hf : Integrable f (law p) := integrable_finite_local Q p _ - (by intro ω; simp only [f,Set.inter_assoc,Set.inter_self]) - have hnon (ω : Set E) : 0 ≤ f ω := by - apply sub_nonneg.mpr - exact pow_le_one₀ (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) - have hbound (ω : Set E) : A.indicator (fun _ => (1:ℝ)/2) ω ≤ f ω := by - by_cases hω : ω ∈ A - · rw [Set.indicator_of_mem hω] - have hs : cluster G ω x ⊆ (finite_reachBall hloc x hi).toFinset := by - simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hω.1 hi hω.2.2.le - have he := cluster_restrict_incident_of_full G hloc _ ω x hs - change 1/2 ≤ 1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard - rw [he] - apply one_sub_pow_one_sub_ge_half - exact hh.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hω.2.1) h.2.1) - · rw [Set.indicator_of_notMem hω] - exact hnon ω - have hib := integral_mono ((integrable_const _).indicator hA) hf hbound - rw [integral_indicator_const _ hA] at hib - have he := markedConnection_integral G Q x h p - change markedConnectionPolynomial G Q x h p = ∫ ω, f ω ∂law p at he - rw [←he] at hib - change (law p).real A ≤ 2*markedConnectionPolynomial G Q x h p - simp only [smul_eq_mul] at hib - linarith - -end MarkedConnectionLaw -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.DistinctMoments + +namespace OAI + +/-! Susceptibility for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SusceptibilityPivotalGain +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem sprinkleParameter_ge_left (p a : unitInterval) : p ≤ sprinkleParameter p a := by + change (p:ℝ) ≤ (p:ℝ)+(1-(p:ℝ))*(a:ℝ) + exact le_add_of_nonneg_right (mul_nonneg (sub_nonneg.mpr p.2.2) a.2.1) + + + +theorem susceptibility_sprinkling_gain [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p a : unitInterval) (hq : sprinkleParameter p a < pc G) (x : V) + (Q : Finset E) (F : Finset V) : + (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * + (∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω x y} e)) ≤ + susceptibility G (sprinkleParameter p a) x - susceptibility G p x := by + have hpa := sprinkleParameter_ge_left p a + have hp : p < pc G := lt_of_le_of_lt hpa hq + have hsum := (summable_twoPoint_subcritical G hloc hqt (sprinkleParameter p a) hq x).sub + (summable_twoPoint_subcritical G hloc hqt p hp x) + calc + _ = ∑ y ∈ F, (a:ℝ)*(1-(a:ℝ))^(Q.card-1)* + (∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω x y} e)) := Finset.mul_sum _ _ _ + _ ≤ ∑ y ∈ F, (twoPoint G (sprinkleParameter p a) x y - twoPoint G p x y) := by + apply Finset.sum_le_sum + intro y _ + exact event_sprinkling_gain p a Q {ω | Conn G ω x y} (measurableSet_conn G x y) + (fun _ _ h hc => conn_mono G h hc) + _ ≤ ∑' y, (twoPoint G (sprinkleParameter p a) x y - twoPoint G p x y) := + hsum.sum_le_tsum F (fun y _ => sub_nonneg.mpr (twoPoint_mono G x y hpa)) + _ = _ := (summable_twoPoint_subcritical G hloc hqt (sprinkleParameter p a) hq x).tsum_sub + (summable_twoPoint_subcritical G hloc hqt p hp x) + + +theorem rootSusceptibility_sprinkling_gain [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (p a : unitInterval) (hq : sprinkleParameter p a < pc G) + (Q : Finset E) (F : Finset V) : + (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * + (∑ i, weight i*(∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω (root i) y} e))) ≤ + rootSusceptibility G root weight (sprinkleParameter p a) - rootSusceptibility G root weight p := by + rw [rootSusceptibility,rootSusceptibility,←Finset.sum_sub_distrib,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have h := mul_le_mul_of_nonneg_left + (susceptibility_sprinkling_gain G hloc hqt p a hq (root i) Q F) (hw i) + convert h using 1 <;> ring + +end SusceptibilityPivotalGain +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section OrientedPivotalConnections +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def orientedPivotalEvent (G : BondGraph V E) (x y a b : V) : Set (Set E) := + {ω | Conn G ω x a ∧ Conn G ω b y ∧ ¬ Conn G ω a b} + +theorem measurableSet_orientedPivotalEvent [Countable V] [Countable E] + (G : BondGraph V E) (x y a b : V) : MeasurableSet (orientedPivotalEvent G x y a b) := + (measurableSet_conn G x a).inter ((measurableSet_conn G b y).inter (measurableSet_conn G a b).compl) + +theorem orientedPivotalEvent_disjoint (G : BondGraph V E) (x y a b : V) : + Disjoint (orientedPivotalEvent G x y a b) (orientedPivotalEvent G x y b a) := by + apply Set.disjoint_left.mpr + intro ω h h' + exact h.2.2 ((conn_symm G ω h.1).trans h'.1) + +theorem closedPivotal_conn (G : BondGraph V E) (e : E) (a b x y : V) + (he : G e = s(a,b)) : + closedPivotal {ω | Conn G ω x y} e = + orientedPivotalEvent G x y a b ∪ orientedPivotalEvent G x y b a := by + ext ω + constructor + · rintro ⟨_,hn,hc⟩ + rcases (conn_insert_iff G ω e a b x y he).mp hc with h | h | h + · exact (hn h).elim + · exact Or.inl ⟨h.1,h.2,fun hab => hn (h.1.trans (hab.trans h.2))⟩ + · exact Or.inr ⟨h.1,h.2,fun hba => hn (h.1.trans (hba.trans h.2))⟩ + · intro h + have hi : ∀ a b : V, G e = s(a,b) → ω ∈ orientedPivotalEvent G x y a b → + ω ∈ closedPivotal {ω | Conn G ω x y} e := by + intro a b he h + refine ⟨?_,?_,?_⟩ + · intro heω + exact h.2.2 (.single ⟨e,heω,he⟩) + · intro hxy + exact h.2.2 ((conn_symm G ω h.1).trans (hxy.trans (conn_symm G ω h.2.1))) + · exact (conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨h.1,h.2.1⟩)) + exact h.elim (hi a b he) (hi b a (he.trans (Sym2.eq_swap ..))) + +theorem closedPivotal_conn_probability [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (e : E) (a b x y : V) (he : G e = s(a,b)) : + (law p).real (closedPivotal {ω | Conn G ω x y} e) = + (law p).real (orientedPivotalEvent G x y a b) + + (law p).real (orientedPivotalEvent G x y b a) := by + rw [closedPivotal_conn G e a b x y he] + exact measureReal_union (orientedPivotalEvent_disjoint G x y a b) + (measurableSet_orientedPivotalEvent G x y b a) + + +theorem orientedPivotalEvent_subset_disjoint (G : BondGraph V E) (x y a b : V) : + orientedPivotalEvent G x y a b ⊆ + DisjointOccurrence {ω | Conn G ω x a} {ω | Conn G ω b y} := by + intro ω hω + have hx : x ∈ cluster G ω a := conn_symm G ω hω.1 + have hb : b ∉ cluster G ω a := hω.2.2 + obtain ⟨Q,hQ,hQa⟩ := finiteWitness_conn G x a _ (conn_restrict_cluster G ω a hx hω.1) + obtain ⟨R,hR,hRb⟩ := finiteWitness_conn G b y _ (conn_restrict_cluster_compl G ω a hb hω.2.1) + refine ⟨Q,R,fun e he => (hQ he).1,fun e he => (hR he).1,?_,hQa,hRb⟩ + apply Finset.disjoint_left.mpr + intro e heQ heR + obtain ⟨⟨z,w⟩,he⟩ := Quot.exists_rep (G e) + have hz : z ∈ G e := by rw [←he]; exact Sym2.mem_mk_left z w + exact (hR heR).2 z hz ((hQ heQ).2 z hz) + +end OrientedPivotalConnections +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PivotalMomentIdentity +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem distinctClusterMass_eq_pivotal (G : BondGraph V E) (ω : Set E) (a b : V) : + (if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) = + ∑' x, ∑' y, if ω ∈ orientedPivotalEvent G x y a b then (1:ℝ≥0∞) else 0 := by + by_cases hab : Conn G ω a b + · simp only [hab,not_true_eq_false,ite_false,orientedPivotalEvent,Set.mem_ofPred_eq, + and_false,ite_false,tsum_zero] + · rw [ite_eq_left hab,clusterMass_mul] + apply tsum_congr + intro x + apply tsum_congr + intro y + apply if_congr _ rfl rfl + simp only [orientedPivotalEvent,Set.mem_ofPred_eq,hab,not_false_eq_true,and_true] + exact and_congr (show Conn G ω a x ↔ Conn G ω x a from ⟨conn_symm G ω,conn_symm G ω⟩) Iff.rfl + +theorem lintegral_distinctClusterMass [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (a b : V) : + (∫⁻ ω, (if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) ∂law p) = + ∑' x, ∑' y, law p (orientedPivotalEvent G x y a b) := by + have hm (x y : V) : Measurable (fun ω : Set E => + if ω ∈ orientedPivotalEvent G x y a b then (1:ℝ≥0∞) else 0) := + Measurable.ite (measurableSet_orientedPivotalEvent G x y a b) measurable_const measurable_const + simp_rw [distinctClusterMass_eq_pivotal] + rw [lintegral_tsum (fun x => (Measurable.tsum (fun y => hm x y)).aemeasurable)] + apply tsum_congr + intro x + rw [lintegral_tsum (fun y => (hm x y).aemeasurable)] + apply tsum_congr + intro y + simpa only [Set.indicator,Pi.one_apply] using + (lintegral_indicator_one (μ := law p) (measurableSet_orientedPivotalEvent G x y a b)) + +theorem ennreal_distinctClusterMoment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (a b : V) : + ENNReal.ofReal (distinctClusterMoment G p a b) = + ∑' x, ∑' y, law p (orientedPivotalEvent G x y a b) := by + have hi := integrable_distinct_cluster_product G hloc hqt p hp a b + have hn : 0 ≤ᵐ[law p] (fun ω => if ¬Conn G ω a b + then ((cluster G ω a).ncard:ℝ)*((cluster G ω b).ncard:ℝ) else 0) := by + exact Filter.Eventually.of_forall (fun ω => by dsimp only; split_ifs <;> positivity) + have he : (fun ω => ENNReal.ofReal (if ¬Conn G ω a b + then ((cluster G ω a).ncard:ℝ)*((cluster G ω b).ncard:ℝ) else 0)) =ᵐ[law p] + (fun ω => if ¬Conn G ω a b then clusterMass G ω a * clusterMass G ω b else 0) := by + filter_upwards [subcritical_cluster_finite_ae G p hp a, + subcritical_cluster_finite_ae G p hp b] with ω ha hb + by_cases hab : Conn G ω a b + · simp only [hab,not_true_eq_false,ite_false,ENNReal.ofReal_zero] + · simp only [hab,not_false_eq_true,ite_true] + rw [clusterMass_eq_ncard G ω a ha,clusterMass_eq_ncard G ω b hb, + ENNReal.ofReal_mul (Nat.cast_nonneg _)] + simp only [ENNReal.ofReal_natCast] + rw [←lintegral_distinctClusterMass,←lintegral_congr_ae he] + exact ofReal_integral_eq_lintegral_ofReal hi hn + +theorem summable_orientedPivotal_pairs [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (a b : V) : + Summable (fun xy : V × V => (law p).real (orientedPivotalEvent G xy.1 xy.2 a b)) := by + apply ENNReal.summable_toReal + rw [ENNReal.tsum_prod',←ennreal_distinctClusterMoment G hloc hqt p hp a b] + exact ENNReal.ofReal_ne_top + +theorem distinctClusterMoment_eq_pivotal [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (a b : V) : + distinctClusterMoment G p a b = + ∑' x, ∑' y, (law p).real (orientedPivotalEvent G x y a b) := by + rw [←(summable_orientedPivotal_pairs G hloc hqt p hp a b).tsum_prod] + change distinctClusterMoment G p a b = + ∑' xy : V × V, (law p (orientedPivotalEvent G xy.1 xy.2 a b)).toReal + rw [←ENNReal.tsum_toReal_eq (f := fun xy : V × V => law p (orientedPivotalEvent G xy.1 xy.2 a b)) + (fun _ => measure_ne_top _ _), ENNReal.tsum_prod', + ←ennreal_distinctClusterMoment G hloc hqt p hp a b, + ENNReal.toReal_ofReal (distinctClusterMoment_nonneg G p a b)] + +end PivotalMomentIdentity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section PivotalTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem orientedPivotal_probability_covariant [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x y z w : V) : + (law p).real (orientedPivotalEvent G (a x) (a y) (a z) (a w)) = + (law p).real (orientedPivotalEvent G x y z w) := by + have he : orientedPivotalEvent G (a x) (a y) (a z) (a w) = + (fun ω => b ⁻¹' ω) ⁻¹' orientedPivotalEvent G x y z w := by + ext ω + simp only [orientedPivotalEvent,Set.mem_ofPred_eq,Set.mem_preimage,conn_aut_iff G hab] + unfold Measure.real + rw [he,←Measure.map_apply (measurable_set_preimage b) + (measurableSet_orientedPivotalEvent G x y z w),law_map_preimage_equiv] + +noncomputable def pivotalTransportMass (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x a : V) : ℝ := + ∑ b ∈ neighbors G hloc a, ∑' y, (law p).real (orientedPivotalEvent G x y a b) + +theorem pivotalTransportMass_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x a : V) : 0 ≤ pivotalTransportMass G hloc p x a := + Finset.sum_nonneg (fun _ _ => tsum_nonneg (fun _ => measureReal_nonneg)) + +theorem pivotalTransportMass_covariant [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x z : V) : + pivotalTransportMass G hloc p (a x) (a z) = pivotalTransportMass G hloc p x z := by + simp only [pivotalTransportMass,neighbors_covariant G hloc hab,Finset.sum_map,Equiv.coe_toEmbedding] + apply Finset.sum_congr rfl + intro w _ + rw [←a.tsum_eq (fun y => (law p).real (orientedPivotalEvent G (a x) y (a z) (a w)))] + exact tsum_congr (fun y => orientedPivotal_probability_covariant G p hab x y z w) + +theorem pivotalTransportMass_incoming_summable [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (a : V) : + Summable (fun x => pivotalTransportMass G hloc p x a) := by + apply summable_sum + intro b _ + exact (summable_orientedPivotal_pairs G hloc hqt p hp a b).prod + +theorem pivotalTransportMass_incoming [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (a : V) : + (∑' x, pivotalTransportMass G hloc p x a) = neighborClusterMoment G hloc p a := by + unfold pivotalTransportMass neighborClusterMoment + rw [Summable.tsum_finsetSum (fun b _ => + (summable_orientedPivotal_pairs G hloc hqt p hp a b).prod)] + exact Finset.sum_congr rfl (fun b _ => (distinctClusterMoment_eq_pivotal G hloc hqt p hp a b).symm) + +end PivotalTransport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section PivotalTransportTotal +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem pivotalTransportMass_outgoing_summable + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (x : V) : + Summable (pivotalTransportMass G hloc p x) := by + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + exact (transported_column_of_row_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin + (fun a x => pivotalTransportMass G hloc p x a) + (fun a x => pivotalTransportMass_nonneg G hloc p x a) + (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact pivotalTransportMass_covariant G hloc p hab y x) + (pivotalTransportMass_incoming_summable G hloc hqt p hp) + (c*rootNeighborMoment G hloc root weight p) + (fun a => by + rw [pivotalTransportMass_incoming G hloc hqt p hp] + exact neighborMoment_le_rootMoment G hloc root weight hw hcover c hc hmin p a) x).1 + + + +theorem rootPivotalMass_eq_neighborMoment + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) : + (∑ i, weight i * ∑' a, pivotalTransportMass G hloc p (root i) a) = + rootNeighborMoment G hloc root weight p := by + rw [htr.real root weight Γ (pivotalTransportMass G hloc p) + (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact pivotalTransportMass_covariant G hloc p hab x y) + (pivotalTransportMass_outgoing_summable G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp) + (pivotalTransportMass_incoming_summable G hloc hqt p hp)] + exact Finset.sum_congr rfl (fun i _ => congrArg (fun t => weight i*t) + (pivotalTransportMass_incoming G hloc hqt p hp (root i))) + +end PivotalTransportTotal +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FinitePivotalComparison +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem orientedPivotal_probability_le_closed [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (e : E) (x y a b : V) (he : G e = s(a,b)) : + (law p).real (orientedPivotalEvent G x y a b) ≤ + (law p).real (closedPivotal {ω | Conn G ω x y} e) := by + rw [closedPivotal_conn_probability G p e a b x y he] + exact le_add_of_nonneg_right measureReal_nonneg + + + +theorem finite_neighbor_pivotal_le_incident [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y a : V) : + (∑ b ∈ neighbors G hloc a, (law p).real (orientedPivotalEvent G x y a b)) ≤ + ∑ e ∈ (hloc a).toFinset, (law p).real (closedPivotal {ω | Conn G ω x y} e) := by + let B := neighbors G hloc a + have he (b : B) : ∃ e, G e = s(a,(b:V)) := (mem_neighbors G hloc a b).mp b.property + choose edge hedge using he + have hinj : Function.Injective edge := by + intro b c h + apply Subtype.ext + have hh := (hedge b).symm.trans ((congrArg G h).trans (hedge c)) + rcases Sym2.eq_iff.mp hh with h | h + · exact h.2 + · exact h.2.trans h.1 + calc + _ = ∑ b : B, (law p).real (orientedPivotalEvent G x y a b) := (Finset.sum_coe_sort B _).symm + _ ≤ ∑ b : B, (law p).real (closedPivotal {ω | Conn G ω x y} (edge b)) := + Finset.sum_le_sum (fun b _ => orientedPivotal_probability_le_closed G p (edge b) x y a b (hedge b)) + _ = ∑ e ∈ Finset.univ.image edge, (law p).real (closedPivotal {ω | Conn G ω x y} e) := + (Finset.sum_image (f := fun e => (law p).real (closedPivotal {ω | Conn G ω x y} e)) + (s := Finset.univ) (fun _ _ _ _ h => hinj h)).symm + _ ≤ _ := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro e he + obtain ⟨b,_,rfl⟩ := Finset.mem_image.mp he + rw [Set.Finite.mem_toFinset] + change a ∈ G (edge b) + rw [hedge b] + exact Sym2.mem_mk_left _ _ + · intro _ _ _ + exact measureReal_nonneg + +theorem finite_incident_sum_le_twice (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset V) (f : E → ℝ) (hf : ∀ e, 0 ≤ f e) : + (∑ a ∈ A, ∑ e ∈ (hloc a).toFinset, f e) ≤ 2*∑ e ∈ incidentSupport G hloc A, f e := by + let Q := incidentSupport G hloc A + have heq (a : V) (ha : a ∈ A) : + (∑ e ∈ (hloc a).toFinset, f e) = ∑ e ∈ Q, if a ∈ G e then f e else 0 := by + rw [←Finset.sum_filter] + apply Finset.sum_congr _ (fun _ _ => rfl) + ext e + simp only [Set.Finite.mem_toFinset,Finset.mem_filter] + exact ⟨fun he => ⟨(mem_incidentSupport G hloc A e).mpr ⟨a,ha,he⟩,he⟩,fun h => h.2⟩ + calc + _ = ∑ a ∈ A, ∑ e ∈ Q, if a ∈ G e then f e else 0 := Finset.sum_congr rfl heq + _ = ∑ e ∈ Q, ∑ a ∈ A, if a ∈ G e then f e else 0 := Finset.sum_comm + _ ≤ ∑ e ∈ Q, 2*f e := by + apply Finset.sum_le_sum + intro e _ + have hsub : A.filter (fun a => a ∈ G e) ⊆ (G e).toFinset := by + intro a ha + exact Sym2.mem_toFinset.mpr (Finset.mem_filter.mp ha).2 + rw [←Finset.sum_filter,Finset.sum_const, nsmul_eq_mul] + have hc : (A.filter (fun a => a ∈ G e)).card ≤ 2 := (Finset.card_le_card hsub).trans (by + rw [Sym2.card_toFinset]; split_ifs <;> omega) + exact mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (hf e) + _ = _ := (Finset.mul_sum _ _ _).symm + +theorem finite_oriented_pivotal_sum_le [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) (A : Finset V) : + (∑ a ∈ A, ∑ b ∈ neighbors G hloc a, (law p).real (orientedPivotalEvent G x y a b)) ≤ + 2*∑ e ∈ incidentSupport G hloc A, (law p).real (closedPivotal {ω | Conn G ω x y} e) := by + exact (Finset.sum_le_sum (fun a _ => finite_neighbor_pivotal_le_incident G hloc p x y a)).trans + (finite_incident_sum_le_twice G hloc A _ (fun _ => measureReal_nonneg)) + +end FinitePivotalComparison +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section SubcriticalSusceptibilityContinuity +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem eventually_cluster_eq_at_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (labels : E → unitInterval) (p : unitInterval) (x : V) + (hneq : ∀ e, labels e ≠ p) (hfin : (cluster G (openEdges labels p) x).Finite) : + ∀ᶠ q in nhds p, cluster G (openEdges labels q) x = cluster G (openEdges labels p) x := by + let Q := incidentSupport G hloc hfin.toFinset + have he (e : E) : ∀ᶠ q in nhds p, (e ∈ openEdges labels q ↔ e ∈ openEdges labels p) := by + change ∀ᶠ q in nhds p, (labels e ≤ q ↔ labels e ≤ p) + by_cases hp : labels e ≤ p + · have hlt : labels e < p := lt_of_le_of_ne hp (hneq e) + filter_upwards [eventually_gt_nhds hlt] with q hq + exact iff_of_true hq.le hp + · have hlt : p < labels e := lt_of_not_ge hp + filter_upwards [eventually_lt_nhds hlt] with q hq + exact iff_of_false (not_le.mpr hq) hp + filter_upwards [(eventually_all_finset Q).mpr (fun e _ => he e)] with q hq + apply cluster_eq_of_incident_agreement G + intro e he + apply (hq e _).symm + obtain ⟨v,hv,hve⟩ := he + exact (mem_incidentSupport G hloc hfin.toFinset e).mpr ⟨v,hfin.mem_toFinset.mpr hv,hve⟩ + +theorem label_cluster_finite_ae_subcritical [Countable E] + (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (x : V) : + ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), (cluster G (openEdges labels p) x).Finite := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges p).aemeasurable + rw [map_openEdges] + exact subcritical_cluster_finite_ae G p hp x + +theorem susceptibility_eq_label_integral [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Integrable (fun labels : E → unitInterval => ((cluster G (openEdges labels p) x).ncard:ℝ)) labelLaw ∧ + susceptibility G p x = ∫ labels : E → unitInterval, ((cluster G (openEdges labels p) x).ncard:ℝ) ∂labelLaw := by + obtain ⟨hi,he⟩ := susceptibility_eq_integral G hloc hqt p hp x + have hi' : Integrable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)) + ((labelLaw : Measure (E → unitInterval)).map (fun labels => openEdges labels p)) := by + rwa [map_openEdges] + refine ⟨hi'.comp_measurable (measurable_openEdges p),?_⟩ + rw [he,←integral_map (measurable_openEdges p).aemeasurable hi'.aestronglyMeasurable,map_openEdges] + + + +theorem continuousAt_susceptibility_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : ContinuousAt (fun q => susceptibility G q x) p := by + obtain ⟨r,hpr,hr⟩ := exists_between hp + let F (q : unitInterval) (labels : E → unitInterval) : ℝ := ((cluster G (openEdges labels q) x).ncard:ℝ) + have hm (q : unitInterval) : Measurable (F q) := + (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp + ((measurable_cluster_ncard G hloc x).comp (measurable_openEdges q)) + have hcont : ContinuousAt (fun q => ∫ labels, F q labels ∂labelLaw) p := by + apply continuousAt_of_dominated + (bound := F r) (Filter.Eventually.of_forall (fun q => (hm q).aestronglyMeasurable)) + · filter_upwards [eventually_lt_nhds hpr] with q hqr + filter_upwards [label_cluster_finite_ae_subcritical G r hr x] with labels hfin + rw [Real.norm_of_nonneg (Nat.cast_nonneg _)] + dsimp only [F] + exact_mod_cast Set.ncard_le_ncard (show cluster G (openEdges labels q) x ⊆ cluster G (openEdges labels r) x from + fun y hy => conn_mono G (openEdges_mono labels hqr.le) hy) hfin + · exact (susceptibility_eq_label_integral G hloc hqt r hr x).1 + · filter_upwards [ae_labels_ne (E := E) p,label_cluster_finite_ae_subcritical G p hp x] with labels hneq hfin + apply Filter.EventuallyEq.continuousAt + filter_upwards [eventually_cluster_eq_at_finite G hloc labels p x hneq hfin] with q hq + exact congrArg (fun S : Set V => (S.ncard:ℝ)) hq + apply (continuousAt_congr _).mpr hcont + filter_upwards [eventually_lt_nhds hp] with q hq + exact (susceptibility_eq_label_integral G hloc hqt q hq x).2 + +theorem continuousAt_rootSusceptibility_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (p : unitInterval) (hp : p < pc G) : + ContinuousAt (rootSusceptibility G root weight) p := by + exact tendsto_finsetSum Finset.univ (fun i _ => continuousAt_const.mul + (continuousAt_susceptibility_subcritical G hloc hqt p hp (root i))) + +end SubcriticalSusceptibilityContinuity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section FiniteRootPivotalApproximation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem summable_orientedPivotal_targets [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x a b : V) : + Summable (fun y => (law p).real (orientedPivotalEvent G x y a b)) := by + apply (summable_twoPoint_subcritical G hloc hqt p hp b).of_nonneg_of_le + · exact fun _ => measureReal_nonneg + · intro y + exact measureReal_mono (fun _ h => h.2.1) + +noncomputable def finiteRootPivotalMass (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (p : unitInterval) (Q : Finset E) (F : Finset V) : ℝ := + ∑ i, weight i*(∑ y ∈ F, ∑ e ∈ Q, (law p).real (closedPivotal {ω | Conn G ω (root i) y} e)) + +theorem finiteRootPivotalMass_nonneg (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (p : unitInterval) (Q : Finset E) (F : Finset V) : + 0 ≤ finiteRootPivotalMass G root weight p Q F := + Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) + (Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => measureReal_nonneg)))) + + + +theorem exists_finiteRootPivotalMass_gt + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (B : ℝ) + (hB : B < rootNeighborMoment G hloc root weight p / 2) : + ∃ Q : Finset E, ∃ F : Finset V, B < finiteRootPivotalMass G root weight p Q F := by + have hs (x : V) := pivotalTransportMass_outgoing_summable G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp x + let f (a : V) := ∑ i, weight i*pivotalTransportMass G hloc p (root i) a + have hsf : Summable f := summable_sum (fun i _ => (hs (root i)).mul_left (weight i)) + have htf : (∑' a, f a) = rootNeighborMoment G hloc root weight p := by + rw [Summable.tsum_finsetSum (fun i _ => (hs (root i)).mul_left (weight i))] + simp_rw [tsum_mul_left] + exact rootPivotalMass_eq_neighborMoment G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp + have hB' : 2*B < ∑' a, f a := by rw [htf]; linarith + obtain ⟨A,hA⟩ := ((tendsto_order.mp hsf.hasSum).1 (2*B) hB').exists + let g (y : V) := ∑ i, weight i*(∑ a ∈ A, ∑ b ∈ neighbors G hloc a, + (law p).real (orientedPivotalEvent G (root i) y a b)) + have hst (i : ι) (a b : V) := summable_orientedPivotal_targets G hloc hqt p hp (root i) a b + have hsg : Summable g := summable_sum (fun i _ => + (summable_sum (fun a _ => summable_sum (fun b _ => hst i a b))).mul_left (weight i)) + have htg : (∑' y, g y) = ∑ a ∈ A, f a := by + rw [Summable.tsum_finsetSum (fun i _ => + (summable_sum (fun a _ => summable_sum (fun b _ => hst i a b))).mul_left (weight i))] + simp_rw [tsum_mul_left] + simp_rw [Summable.tsum_finsetSum (fun a _ => summable_sum (fun b _ => hst _ a b))] + simp_rw [Summable.tsum_finsetSum (fun b _ => hst _ _ b)] + simp only [f,Finset.mul_sum,pivotalTransportMass] + rw [Finset.sum_comm] + obtain ⟨F,hF⟩ := ((tendsto_order.mp hsg.hasSum).1 (2*B) (by rwa [htg])).exists + refine ⟨incidentSupport G hloc A,F,?_⟩ + have hb : (∑ y ∈ F, g y) ≤ 2*finiteRootPivotalMass G root weight p (incidentSupport G hloc A) F := by + unfold g finiteRootPivotalMass + rw [Finset.sum_comm, Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.mul_sum, mul_left_comm] + apply mul_le_mul_of_nonneg_left _ (hw i) + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun y _ => finite_oriented_pivotal_sum_le G hloc p (root i) y A) + linarith + +end FiniteRootPivotalApproximation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section VanishingSprinkles +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def vanishingSprinkle (n : ℕ) : unitInterval := + ⟨1/((n:ℝ)+1), by + constructor + · positivity + · apply (div_le_one (by positivity : 0 < (n:ℝ)+1)).mpr + linarith [show (0:ℝ) ≤ (n:ℝ) by positivity] + ⟩ + +theorem vanishingSprinkle_pos (n : ℕ) : 0 < (vanishingSprinkle n : ℝ) := by + dsimp [vanishingSprinkle] + positivity + +theorem tendsto_vanishingSprinkle : + Tendsto (fun n => (vanishingSprinkle n:ℝ)) atTop (nhds 0) := + tendsto_one_div_add_atTop_nhds_zero_nat + +theorem sprinkle_sequence_gt (p : unitInterval) (hp : (p:ℝ) < 1) (n : ℕ) : + p < sprinkleParameter p (vanishingSprinkle n) := by + change (p:ℝ) < (p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ) + exact lt_add_of_pos_right _ (mul_pos (sub_pos.mpr hp) (vanishingSprinkle_pos n)) + +theorem tendsto_sprinkle_sequence (p : unitInterval) : + Tendsto (fun n => sprinkleParameter p (vanishingSprinkle n)) atTop (nhds p) := by + apply tendsto_subtype_rng.mpr + change Tendsto (fun n => (p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ)) atTop (nhds (p:ℝ)) + convert tendsto_const_nhds.add (tendsto_const_nhds.mul tendsto_vanishingSprinkle) using 1; simp + +theorem tendsto_sprinkle_sequence_right (p : unitInterval) (hp : (p:ℝ) < 1) : + Tendsto (fun n => (sprinkleParameter p (vanishingSprinkle n):ℝ)) atTop (nhdsWithin (p:ℝ) (Set.Ioi (p:ℝ))) := by + apply tendsto_nhdsWithin_iff.mpr + exact ⟨continuous_subtype_val.continuousAt.tendsto.comp (tendsto_sprinkle_sequence p), + Eventually.of_forall (sprinkle_sequence_gt p hp)⟩ + + + +theorem rootSusceptibility_sequence_slope_lower + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (p : unitInterval) (hp : p < pc G) (Q : Finset E) (F : Finset V) (d : ℝ) + (hd : d < finiteRootPivotalMass G root weight p Q F) : + ∀ᶠ n in atTop, + ((sprinkleParameter p (vanishingSprinkle n):ℝ)-(p:ℝ))*d ≤ + rootSusceptibility G root weight (sprinkleParameter p (vanishingSprinkle n)) - + rootSusceptibility G root weight p := by + have ht : Tendsto (fun n => (1-(vanishingSprinkle n:ℝ))^(Q.card-1) * + finiteRootPivotalMass G root weight p Q F) atTop + (nhds (finiteRootPivotalMass G root weight p Q F)) := by + convert ((tendsto_const_nhds.sub tendsto_vanishingSprinkle).pow (Q.card-1)).mul tendsto_const_nhds using 1; simp + have hnn := finiteRootPivotalMass_nonneg G root weight hw p Q F + filter_upwards [(tendsto_sprinkle_sequence p).eventually (eventually_lt_nhds hp), + ht.eventually (eventually_gt_nhds hd)] with n hn hdn + have hgain := rootSusceptibility_sprinkling_gain G hloc hqt root weight hw + p (vanishingSprinkle n) hn Q F + change (vanishingSprinkle n:ℝ)*(1-(vanishingSprinkle n:ℝ))^(Q.card-1)* + finiteRootPivotalMass G root weight p Q F ≤ _ at hgain + by_cases hd0 : 0 ≤ d + · have hdp : (1-(p:ℝ))*d ≤ (1-(vanishingSprinkle n:ℝ))^(Q.card-1)* + finiteRootPivotalMass G root weight p Q F := by + calc + _ ≤ d := by nlinarith [p.2.1] + _ ≤ _ := hdn.le + have hm := mul_le_mul_of_nonneg_left hdp (vanishingSprinkle n).2.1 + calc + _ = (vanishingSprinkle n:ℝ)*((1-(p:ℝ))*d) := by + change ((p:ℝ)+(1-(p:ℝ))*(vanishingSprinkle n:ℝ)-(p:ℝ))*d = _ + ring + _ ≤ (vanishingSprinkle n:ℝ)*((1-(vanishingSprinkle n:ℝ))^(Q.card-1)* + finiteRootPivotalMass G root weight p Q F) := hm + _ ≤ _ := by simpa only [mul_assoc] using hgain + · have hmono : 0 ≤ rootSusceptibility G root weight (sprinkleParameter p (vanishingSprinkle n)) - rootSusceptibility G root weight p := + (mul_nonneg (mul_nonneg (vanishingSprinkle n).2.1 (pow_nonneg (sub_nonneg.mpr (vanishingSprinkle n).2.2) _)) hnn).trans hgain + have hdp : ((sprinkleParameter p (vanishingSprinkle n):ℝ)-(p:ℝ))*d ≤ 0 := + mul_nonpos_of_nonneg_of_nonpos (sub_nonneg.mpr (sprinkleParameter_ge_left _ _)) (le_of_not_ge hd0) + linarith + +end VanishingSprinkles +end Percolation + + +namespace Percolation +open Filter +section NegativePowerRightSlopes + + + +theorem frequently_rpow_slope_le_of_sequence + (f : ℝ → ℝ) (x d e : ℝ) (hx : 0 < f x) (hd : 0 < d) (he : e < 0) + (z : ℕ → ℝ) (hz : Tendsto z atTop (nhdsWithin x (Set.Ioi x))) + (hgain : ∀ᶠ n in atTop, (z n-x)*d ≤ f (z n)-f x) : + ∀ r, e*(f x)^(e-1)*d < r → + ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope (fun t => (f t)^e) x y < r := by + let A (t : ℝ) := f x+(t-x)*d + have hA : HasDerivAt A d x := by + simpa only [zero_add, one_mul] using! (hasDerivAt_const x (f x)).add (((hasDerivAt_id x).sub_const x).mul_const d) + have hAx : A x = f x := by simp [A] + have hR : HasDerivAt (fun t => (A t)^e) (e*(f x)^(e-1)*d) x := by + simpa only [hAx] using! (Real.hasDerivAt_rpow_const (p := e) (Or.inl (show A x ≠ 0 by rw [hAx]; exact hx.ne'))).comp x hA + intro r hr + have hlim := hR.tendsto_slope.comp (hz.mono_right (nhdsWithin_mono x (show Set.Ioi x ⊆ {x}ᶜ from fun y hy => by simpa using ne_of_gt hy))) + have hright : ∀ᶠ n in atTop, x < z n := (tendsto_nhdsWithin_iff.mp hz).2 + apply hz.frequently + apply Filter.Eventually.frequently + filter_upwards [hgain, hright, hlim.eventually (eventually_lt_nhds hr)] with n hn hzn hnr + have hApos : 0 < A (z n) := by dsimp [A]; positivity + have hAr : A (z n) ≤ f (z n) := by dsimp [A]; linarith + have hp := Real.rpow_le_rpow_of_nonpos hApos hAr he.le + apply lt_of_le_of_lt _ hnr + simp only [Function.comp_apply, slope_def_field, hAx] + exact div_le_div_of_nonneg_right (sub_le_sub_right hp _) (sub_pos.mpr hzn).le + +end NegativePowerRightSlopes +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section ActualSusceptibilityRightSlope +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def realRootSusceptibility (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := + rootSusceptibility G root weight (Set.projIcc 0 1 zero_le_one t) + +@[simp] theorem realRootSusceptibility_coe (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (p : unitInterval) : + realRootSusceptibility G root weight (p:ℝ) = rootSusceptibility G root weight p := by + simp only [realRootSusceptibility, Set.projIcc_val] + +theorem rootSusceptibility_one_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (p : unitInterval) (hp : p < pc G) : 1 ≤ rootSusceptibility G root weight p := by + calc + 1 = ∑ i, weight i*1 := by simp only [mul_one, hw1] + _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left + (susceptibility_one_le G hloc hqt p hp (root i)) (hw i)) + +theorem continuousAt_realRootSusceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (p : unitInterval) (hp : p < pc G) : + ContinuousAt (realRootSusceptibility G root weight) (p:ℝ) := by + apply ContinuousAt.comp (f := Set.projIcc 0 1 zero_le_one) + · simpa only [Set.projIcc_val] using continuousAt_rootSusceptibility_subcritical G hloc hqt root weight p hp + · exact continuous_projIcc.continuousAt + + + +theorem rootSusceptibility_power_right_slope + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (b γ : ℝ) (hb : 0 < b) (hγ : γ < 1) + (hD : b*(rootSusceptibility G root weight p)^(2-γ) ≤ rootNeighborMoment G hloc root weight p) : + ∀ r, -(1-γ)*b/4 < r → ∃ᶠ y in nhdsWithin (p:ℝ) (Set.Ioi (p:ℝ)), + slope (fun t => (realRootSusceptibility G root weight t)^(γ-1)) (p:ℝ) y < r := by + let χ := rootSusceptibility G root weight p + have hχ : 0 < χ := lt_of_lt_of_le zero_lt_one (rootSusceptibility_one_le G hloc hqt root weight hw hw1 p hp) + let d := (b/4)*χ^(2-γ) + have hd : 0 < d := mul_pos (by positivity) (Real.rpow_pos_of_pos hχ _) + have hBd : d < rootNeighborMoment G hloc root weight p/2 := by + dsimp [d, χ] at * + nlinarith [Real.rpow_pos_of_pos hχ (2-γ)] + obtain ⟨Q,F,hQ⟩ := exists_finiteRootPivotalMass_gt G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin p hp d hBd + have hg := rootSusceptibility_sequence_slope_lower G hloc hqt root weight hw p hp Q F d hQ + have hp1 : (p:ℝ) < 1 := lt_of_lt_of_le hp (pc G).2.2 + have hsl := frequently_rpow_slope_le_of_sequence (realRootSusceptibility G root weight) + (p:ℝ) d (γ-1) (by simpa only [realRootSusceptibility_coe] using hχ) hd (by linarith) + (fun n => (sprinkleParameter p (vanishingSprinkle n):ℝ)) (tendsto_sprinkle_sequence_right p hp1) + (by simpa only [realRootSusceptibility_coe] using hg) + have heq : (γ-1)*(realRootSusceptibility G root weight (p:ℝ))^(γ-1-1)*d = -(1-γ)*b/4 := by + rw [realRootSusceptibility_coe] + change (γ-1)*χ^(γ-1-1)*((b/4)*χ^(2-γ)) = _ + rw [show γ-1-1 = γ-2 by ring] + calc + _ = ((γ-1)*b/4)*(χ^(γ-2)*χ^(2-γ)) := by ring + _ = _ := by rw [←Real.rpow_add hχ, sub_add_sub_cancel, sub_self, Real.rpow_zero]; ring + rwa [heq] at hsl + +end ActualSusceptibilityRightSlope +end Percolation + + +namespace Percolation +open Filter +section IntegratedRightSlopes + + + +theorem interval_decrease_of_right_slope (f : ℝ → ℝ) (a b k : ℝ) + (hab : a ≤ b) (hf : ContinuousOn f (Set.Icc a b)) + (hs : ∀ x ∈ Set.Ico a b, ∀ r, -k < r → + ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope f x y < r) : + k*(b-a) ≤ f a-f b := by + let B (t : ℝ) := f a-k*(t-a) + have hB : ContinuousOn B (Set.Icc a b) := by fun_prop + have hB' (x : ℝ) : HasDerivAt B (-k) x := by + simpa only [one_mul, sub_zero, mul_one, zero_sub] using! + (hasDerivAt_const x (f a)).sub (((hasDerivAt_id x).sub_const a).const_mul k) + have h := image_le_of_liminf_slope_right_le_deriv_boundary hf + (show f a ≤ B a by simp [B]) hB (fun x _ => (hB' x).hasDerivWithinAt) hs ⟨hab,le_rfl⟩ + dsimp [B] at h + linarith + + + +theorem right_slope_distance_bound (f : ℝ → ℝ) (a b k : ℝ) + (hab : a < b) (hk : 0 < k) + (hpos : ∀ x ∈ Set.Ico a b, 0 ≤ f x) + (hc : ContinuousOn f (Set.Ico a b)) + (hs : ∀ x ∈ Set.Ico a b, ∀ r, -k < r → + ∃ᶠ y in nhdsWithin x (Set.Ioi x), slope f x y < r) : + k*(b-a) ≤ f a := by + have hbound (r : ℝ) (hr : r ∈ Set.Ico a b) : k*(r-a) ≤ f a := by + have hsub : Set.Icc a r ⊆ Set.Ico a b := fun t ht => ⟨ht.1,lt_of_le_of_lt ht.2 hr.2⟩ + have h := interval_decrease_of_right_slope f a r k hr.1 (hc.mono hsub) + (fun x hx => hs x ⟨hx.1,lt_trans hx.2 hr.2⟩) + linarith [hpos r hr] + by_contra h + have hd : a+f a/k < b := by + have hh : f a < k*(b-a) := lt_of_not_ge h + have hv : f a/k < b-a := (div_lt_iff₀ hk).mpr (by nlinarith) + linarith + obtain ⟨r,hr1,hr2⟩ := exists_between hd + have ha : a ≤ r := by + have hf := hpos a ⟨le_rfl,hab⟩ + have hd0 := div_nonneg hf hk.le + linarith + have hb := hbound r ⟨ha,hr2⟩ + have hr : f a < (r-a)*k := (div_lt_iff₀ hk).mp (by linarith : f a/k < r-a) + nlinarith + +end IntegratedRightSlopes +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section ActualIntegratedSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem susceptibility_bound_of_neighborMoment + [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (b γ : ℝ) (hb : 0 < b) (hγ : γ < 1) + (hD : ∀ q, p ≤ q → q < pc G → b*(rootSusceptibility G root weight q)^(2-γ) ≤ + rootNeighborMoment G hloc root weight q) : + rootSusceptibility G root weight p ≤ + (((1-γ)*b/4)*((pc G:ℝ)-(p:ℝ)))^(-1/(1-γ)) := by + let k := (1-γ)*b/4 + have hk : 0 < k := by dsimp [k]; positivity + let f (t : ℝ) := (realRootSusceptibility G root weight t)^(γ-1) + have hparam (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : t ∈ Set.Icc (0:ℝ) 1 := + ⟨le_trans p.2.1 ht.1, le_trans ht.2.le (pc G).2.2⟩ + have hcp (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : + ContinuousAt (realRootSusceptibility G root weight) t := + continuousAt_realRootSusceptibility G hloc hqt root weight ⟨t,hparam t ht⟩ ht.2 + have hpos (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) : + 0 < realRootSusceptibility G root weight t := by + have hh := rootSusceptibility_one_le G hloc hqt root weight hw hw1 ⟨t,hparam t ht⟩ ht.2 + rw [←realRootSusceptibility_coe] at hh + exact lt_of_lt_of_le zero_lt_one hh + have hcont : ContinuousOn f (Set.Ico (p:ℝ) (pc G:ℝ)) := by + intro t ht + exact ((hcp t ht).rpow_const (Or.inl (hpos t ht).ne')).continuousWithinAt + have hs (t : ℝ) (ht : t ∈ Set.Ico (p:ℝ) (pc G:ℝ)) := + rootSusceptibility_power_right_slope G hconn hloc hqt root weight Γ hΓ htr hcov hw hw1 c hc hmin + ⟨t,hparam t ht⟩ ht.2 b γ hb hγ (hD ⟨t,hparam t ht⟩ ht.1 ht.2) + have hdist : k*((pc G:ℝ)-(p:ℝ)) ≤ f (p:ℝ) := by + apply right_slope_distance_bound f (p:ℝ) (pc G:ℝ) k hp hk + (fun t ht => (Real.rpow_pos_of_pos (hpos t ht) _).le) hcont + intro t ht r hr + apply hs t ht r + dsimp [k] at hr + linarith + have hχ := lt_of_lt_of_le zero_lt_one (rootSusceptibility_one_le G hloc hqt root weight hw hw1 p hp) + have hd : 0 < k*((pc G:ℝ)-(p:ℝ)) := mul_pos hk (sub_pos.mpr hp) + have he : -1/(1-γ) = 1/(γ-1) := by rw [show γ-1=-(1-γ) by ring, div_neg, neg_div] + have he0 : 1/(γ-1) < 0 := one_div_neg.mpr (by linarith) + have hinv := Real.rpow_le_rpow_of_nonpos hd hdist he0.le + rw [he] + apply le_trans _ hinv + change rootSusceptibility G root weight p ≤ + ((realRootSusceptibility G root weight (p:ℝ))^(γ-1))^(1/(γ-1)) + rw [realRootSusceptibility_coe,←Real.rpow_mul hχ.le] + rw [mul_one_div_cancel (by linarith : γ-1 ≠ 0),Real.rpow_one] + +end ActualIntegratedSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section SusceptibilityGrowthConsequence +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem eventually_upper_interval_unit (p₀ : unitInterval) (P : unitInterval → Prop) + (h : ∀ᶠ p in nhds p₀, P p) : + ∀ᶠ p in nhds p₀, p < p₀ → ∀ q, p ≤ q → q < p₀ → P q := by + obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp h + apply Metric.eventually_nhds_iff.mpr + refine ⟨ε,hε,?_⟩ + intro p hp hpp q hpq hq + apply hball + have hd : dist q p₀ ≤ dist p p₀ := by + change |(q:ℝ)-(p₀:ℝ)| ≤ |(p:ℝ)-(p₀:ℝ)| + rw [abs_of_nonpos (sub_nonpos.mpr (show (q:ℝ) ≤ (p₀:ℝ) from hq.le)),abs_of_nonpos (sub_nonpos.mpr (show (p:ℝ) ≤ (p₀:ℝ) from hpp.le))] + have hpqR : (p:ℝ) ≤ (q:ℝ) := hpq + linarith + exact lt_of_le_of_lt hd hp + + + +theorem susceptibility_growth_of_divergent_moment + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) + (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) + (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G))) : + ∀ γ : ℝ, 0 < γ → γ < 1 → ∃ C : ℝ, 0 < C ∧ ∀ᶠ p in nhds (pc G), p < pc G → + rootSusceptibility G root weight p ≤ C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ)) := by + intro γ hγ hγ1 + obtain ⟨b,hb,hnear⟩ := neighborMoment_growth_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr + hcov hw hw1 (pc G) hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv γ hγ + let c : ℝ := ∑ i, 1/weight i + have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) + have hmin (i : ι) : 1 ≤ c*weight i := by + apply (div_le_iff₀ (hw i)).mp + exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) + let k := (1-γ)*b/4 + have hk : 0 < k := by dsimp [k]; positivity + refine ⟨k^(-1/(1-γ)),Real.rpow_pos_of_pos hk _,?_⟩ + filter_upwards [eventually_upper_interval_unit (pc G) _ hnear] with p hp + intro hpc + have hD (q : unitInterval) (hpq : p ≤ q) (hq : q < pc G) := hp hpc q hpq hq hq + have hs := susceptibility_bound_of_neighborMoment G hconn hloc hqt root weight Γ hΓ htr hcov + (fun i => (hw i).le) hw1 c hc hmin p hpc b γ hb hγ1 hD + rwa [Real.mul_rpow hk.le (sub_pos.mpr (show (p:ℝ) < (pc G:ℝ) from hpc)).le] at hs + +end SusceptibilityGrowthConsequence +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section MarkedSearchTransfer +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem exponential_transfer_of_deriv_bound (H : ℝ → ℝ) (a b K : ℝ) + (hH : Differentiable ℝ H) (hab : a ≤ b) + (hb : ∀ t ∈ Set.Icc a b, deriv H t ≤ K*H t) : + H b ≤ Real.exp (K*(b-a))*H a := by + let F (t : ℝ) := Real.exp (-K*(t-a))*H t + have hF (t : ℝ) : HasDerivAt F (Real.exp (-K*(t-a))*(deriv H t-K*H t)) t := by + have he := (((hasDerivAt_id t).sub_const a).const_mul (-K)).exp + convert! he.mul (hH t).hasDerivAt using 1 + simp only [id_eq] + ring + have hanti : AntitoneOn F (Set.Icc a b) := by + apply antitoneOn_of_deriv_nonpos (convex_Icc a b) + (fun t _ => (hF t).continuousAt.continuousWithinAt) + (fun t _ => (hF t).differentiableAt.differentiableWithinAt) + intro t ht + rw [(hF t).deriv] + exact mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos _).le (sub_nonpos.mpr (hb t (interior_subset ht))) + have h := hanti ⟨le_rfl,hab⟩ ⟨hab,le_rfl⟩ hab + have hm := mul_le_mul_of_nonneg_left h (Real.exp_pos (K*(b-a))).le + simpa only [F, sub_self,mul_zero,Real.exp_zero,one_mul,←mul_assoc,←Real.exp_add, + neg_mul,add_neg_cancel,Real.exp_zero,one_mul,neg_zero,add_zero] using hm + + + +theorem markedConnection_transfer (G : BondGraph V E) (Q : Finset E) (x : V) + (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (p q h : unitInterval) (hp : 0 < (p:ℝ)) (hpq : p ≤ q) (hq : (q:ℝ) < 1) + (hh : 0 < (h:ℝ)) : + markedConnectionPolynomial G Q x h q ≤ + Real.exp ((Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ)))) * + Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*((q:ℝ)-(p:ℝ))) * + markedConnectionPolynomial G Q x h p := by + let H := markedConnectionPolynomial G Q x h + have hdiff : Differentiable ℝ H := fun t => (hasDerivAt_bernoulliPolynomial Q _ t).differentiableAt + apply exponential_transfer_of_deriv_bound H p q _ hdiff hpq + intro t ht + let r : unitInterval := ⟨t,⟨le_trans p.2.1 ht.1,le_trans ht.2 q.2.2⟩⟩ + have hr0 : 0 < t := lt_of_lt_of_le hp ht.1 + have hr1 : t < 1 := lt_of_le_of_lt ht.2 hq + have HB := markedConnection_derivative_bound G Q x r h hr1 hh d hd hdeg + have hH : 0 ≤ H t := by + change 0 ≤ markedConnectionPolynomial G Q x h r + rw [markedConnectionPolynomial_eq_tree] + exact ProbeTree.successMass_nonneg r h _ + have hs : 0 ≤ Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ)) := Real.sqrt_nonneg _ + have hden : (p:ℝ)*(1-(q:ℝ)) ≤ t*(1-t) := by + exact mul_le_mul ht.1 (by linarith [ht.2]) (sub_pos.mpr hq).le (by positivity) + have hratio : Real.sqrt ((d:ℝ)/2)/(t*(1-t)) ≤ + Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ))) := + div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (mul_pos hp (sub_pos.mpr hq)) hden + have hle : deriv H t ≤ (Real.sqrt ((d:ℝ)/2)/(t*(1-t)))* + Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*H t := by + have HBr : deriv H t ≤ ((Real.sqrt ((d:ℝ)/2)/(1-t))* + Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*H t)/t := by + apply (le_div_iff₀ hr0).mpr + simpa only [mul_comm (deriv H t) t] using HB + convert HBr using 1 + field_simp + exact hle.trans (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hratio hs) hH) + +end MarkedSearchTransfer +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section MarkedComponentIdentity +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem markedConnection_component_polynomial (G : BondGraph V E) + (Q : Finset E) (x : V) (h p : ℝ) : + markedConnectionPolynomial G Q x h p = + bernoulliPolynomial Q (fun ω => 1-(1-h)^(finiteRootComponent G ω x).card) p := by + apply bernoulliPolynomial_congr + intro ω hω + let C := finiteRootComponent G ω x + let F := insert x (searchVertices G Q) + have hCF : C ⊆ F := finiteRootComponent_subset G Q F x ω hω le_rfl + have he (m : Finset V) : (∃ y ∈ m, Conn G (ω:Set E) x y) ↔ m ∩ C ≠ ∅ := by + rw [Finset.nonempty_iff_ne_empty.symm] + constructor + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,Finset.mem_inter.mpr ⟨hy,by change y ∈ (C:Set V); simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hxy⟩⟩ + · rintro ⟨y,hy⟩ + refine ⟨y,(Finset.mem_inter.mp hy).1,?_⟩ + have hm : y ∈ (C:Set V) := (Finset.mem_inter.mp hy).2 + simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hm + have hid : bernoulliPolynomial F (fun m => if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0) h = + 1-bernoulliPolynomial F (fun m => if m ∩ C = ∅ then 1 else 0) h := by + calc + _ = bernoulliPolynomial F (fun m => 1-(if m ∩ C = ∅ then 1 else 0)) h := by + apply bernoulliPolynomial_congr + intro m _ + by_cases hm : m ∩ C = ∅ + · have hn : ¬∃ y ∈ m, Conn G (ω:Set E) x y := fun hc => (he m).mp hc hm + simp only [hm,hn,ite_false,ite_true,sub_self] + · have hy := (he m).mpr hm + simp only [hm,hy,ite_false,ite_true,sub_zero] + _ = _ := by rw [bernoulliPolynomial_sub,bernoulliPolynomial_const] + rw [hid,bernoulliPolynomial_restrict C F hCF (fun m => if m = ∅ then 1 else 0) h, + bernoulliPolynomial_empty_indicator] + +theorem one_sub_pow_one_sub_le (h : unitInterval) (n : ℕ) : + 1-(1-(h:ℝ))^n ≤ (h:ℝ)*n := by + induction n with + | zero => simp + | succ n ih => + rw [pow_succ,Nat.cast_succ] + have hm := mul_le_mul_of_nonneg_right ih (sub_nonneg.mpr h.2.2) + have hn : 0 ≤ (h:ℝ)^2*n := by positivity + nlinarith + +end MarkedComponentIdentity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section MarkedConnectionLaw +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem markedConnection_integral (G : BondGraph V E) (Q : Finset E) (x : V) + (h p : unitInterval) : + markedConnectionPolynomial G Q x h p = + ∫ ω, (1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard) ∂law p := by + rw [integral_eq_bernoulliPolynomial Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]), + markedConnection_component_polynomial] + apply bernoulliPolynomial_congr + intro ω hω + rw [Set.inter_eq_left.mpr (show (ω:Set E) ⊆ Q from hω)] + congr 2 + rw [←coe_finiteRootComponent,Set.ncard_coe_finset] + +theorem markedConnection_le_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (Q : Finset E) (x : V) (h p : unitInterval) (hp : p < pc G) : + markedConnectionPolynomial G Q x h p ≤ (h:ℝ)*susceptibility G p x := by + obtain ⟨hi,he⟩ := susceptibility_eq_integral G hloc hqt p hp x + rw [markedConnection_integral,he,←integral_const_mul] + apply integral_mono_ae + · exact integrable_finite_local Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]) + · exact hi.const_mul _ + · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + apply (one_sub_pow_one_sub_le h _).trans + apply mul_le_mul_of_nonneg_left _ h.2.1 + exact_mod_cast Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω + + + +theorem one_sub_pow_one_sub_ge_half (h : unitInterval) (n : ℕ) + (hn : 1 ≤ (h:ℝ)*n) : (1:ℝ)/2 ≤ 1-(1-(h:ℝ))^n := by + have hb (m : ℕ) : (1+(h:ℝ)*m)*(1-(h:ℝ))^m ≤ 1 := by + induction m with + | zero => simp + | succ m ih => + have hp : 0 ≤ (1-(h:ℝ))^m := pow_nonneg (sub_nonneg.mpr h.2.2) _ + have ha : (1+(h:ℝ)*(m+1))*(1-(h:ℝ)) ≤ 1+(h:ℝ)*m := by + have hh : 0 ≤ (h:ℝ)^2*((m:ℝ)+1) := by positivity + nlinarith + have hm := mul_le_mul_of_nonneg_right ha hp + rw [Nat.cast_succ,pow_succ] + nlinarith + have hp : 0 ≤ (1-(h:ℝ))^n := pow_nonneg (sub_nonneg.mpr h.2.2) _ + have hm := mul_le_mul_of_nonneg_right hn hp + have hb' := hb n + nlinarith + + + +theorem clusterWindow_le_markedConnection (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (lo hi : ℕ) (p h : unitInterval) (hh : 1 ≤ (h:ℝ)*lo) : + clusterWindowProbability G p x lo hi ≤ 2*markedConnectionPolynomial G + (incidentSupport G hloc (finite_reachBall hloc x hi).toFinset) x h p := by + let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset + let f (ω : Set E) := 1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard + let A := {ω | ClusterWindow G x lo hi ω} + have hA : MeasurableSet A := measurableSet_clusterWindow G hloc x lo hi + have hf : Integrable f (law p) := integrable_finite_local Q p _ + (by intro ω; simp only [f,Set.inter_assoc,Set.inter_self]) + have hnon (ω : Set E) : 0 ≤ f ω := by + apply sub_nonneg.mpr + exact pow_le_one₀ (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) + have hbound (ω : Set E) : A.indicator (fun _ => (1:ℝ)/2) ω ≤ f ω := by + by_cases hω : ω ∈ A + · rw [Set.indicator_of_mem hω] + have hs : cluster G ω x ⊆ (finite_reachBall hloc x hi).toFinset := by + simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hω.1 hi hω.2.2.le + have he := cluster_restrict_incident_of_full G hloc _ ω x hs + change 1/2 ≤ 1-(1-(h:ℝ))^(cluster G (ω ∩ (Q:Set E)) x).ncard + rw [he] + apply one_sub_pow_one_sub_ge_half + exact hh.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hω.2.1) h.2.1) + · rw [Set.indicator_of_notMem hω] + exact hnon ω + have hib := integral_mono ((integrable_const _).indicator hA) hf hbound + rw [integral_indicator_const _ hA] at hib + have he := markedConnection_integral G Q x h p + change markedConnectionPolynomial G Q x h p = ∫ ω, f ω ∂law p at he + rw [←he] at hib + change (law p).real A ≤ 2*markedConnectionPolynomial G Q x h p + simp only [smul_eq_mul] at hib + linarith + +end MarkedConnectionLaw +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Criticality/UnimodularMain.lean b/lean/OAI/Probability/UnimodularPercolation/Criticality/UnimodularMain.lean index 84463baeb074b4e398f1361ac190a4df93269df2..d33df847fabae53139c31d4d053d341231bac16b 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Criticality/UnimodularMain.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Criticality/UnimodularMain.lean @@ -1,28 +1,28 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Criticality.FullOperator - -namespace OAI - -/-! Threshold separation and simultaneous nonuniqueness under unimodularity. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -theorem main_unimodular [Infinite V] (G : BondGraph V E) - (hinj : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) (x₀ : V) - (hu : FullAutUnimodular G hinj hloc hconn x₀) : MainConclusion G := by - let : TopologicalSpace V := ⊥ - let : DiscreteTopology V := ⟨rfl⟩ - apply mainConclusion_of_critical_bounded G hconn hloc hqt - exact critical_bounded_of_graphUnimodular G hinj hconn hloc hqt hh x₀ hu - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Criticality.FullOperator + +namespace OAI + +/-! Threshold separation and simultaneous nonuniqueness under unimodularity. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +theorem main_unimodular [Infinite V] (G : BondGraph V E) + (hinj : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) (x₀ : V) + (hu : FullAutUnimodular G hinj hloc hconn x₀) : MainConclusion G := by + let : TopologicalSpace V := ⊥ + let : DiscreteTopology V := ⟨rfl⟩ + apply mainConclusion_of_critical_bounded G hconn hloc hqt + exact critical_bounded_of_graphUnimodular G hinj hconn hloc hqt hh x₀ hu + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/AveragedDecrease.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/AveragedDecrease.lean index 8e0cd6756c4f11024d84dbb4d0e0a4dee52fd5ee..196c89bea2201062e6000c89fc5bd8a2edf98a27 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/AveragedDecrease.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/AveragedDecrease.lean @@ -1,1209 +1,1209 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.Calibration - -namespace OAI - -/-! Averaged Decrease for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CountedCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem preimage_diff_singleton (b : E ≃ E) (ω : Set E) (e : E) : - (b ⁻¹' ω) \ {e} = b ⁻¹' (ω \ {b e}) := by - ext f - simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] - -theorem corridorCounted_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (S B : Set E) (D : Set V) (ω : Set E) (x y : V) : - corridorCounted G (b ⁻¹' S) (b ⁻¹' B) (a ⁻¹' D) (b ⁻¹' ω) x y ↔ - corridorCounted G S B D ω (a x) (a y) := by - have he : (b ⁻¹' ω) ∩ internalEdges G (a ⁻¹' D) = b ⁻¹' (ω ∩ internalEdges G D) := by - rw [internalEdges_aut_preimage G hab,Set.preimage_inter] - simp only [corridorCounted,he,conn_aut_iff G hab,preimage_diff_singleton, - Set.mem_preimage] - apply and_congr_right - intro _ - constructor - · rintro ⟨hp,hB⟩ - constructor - · intro e he - obtain ⟨f,rfl⟩ := b.surjective e - exact hp f he - · apply Set.disjoint_left.mpr - intro e he hw - obtain ⟨f,rfl⟩ := b.surjective e - exact Set.disjoint_left.mp hB he hw - · rintro ⟨hp,hB⟩ - exact ⟨fun e he => hp (b e) he,Set.disjoint_left.mpr (fun e he hw => Set.disjoint_left.mp hB he hw)⟩ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem aut_counted {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : - w.counted (a ⁻¹' D) (b ⁻¹' ω) x y ↔ (autEquiv hab w).counted D ω (a x) (a y) := by - have hr : w.retained = b ⁻¹' (autEquiv hab w).retained := by - ext e - exact (aut_retained hab w e).symm - have hb : w.blockers = b ⁻¹' (autEquiv hab w).blockers := by - ext e - exact (aut_blockers hab w e).symm - rw [counted_iff,counted_iff,aut_path_length,hr,hb,corridorCounted_aut G hab] - -end RawCorridor - -theorem corridorPenaltyTerm_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : ℝ) {k : ℕ} (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : - corridorPenaltyTerm G P p (a ⁻¹' D) (b ⁻¹' ω) x y w = - corridorPenaltyTerm G P p D ω (a x) (a y) (RawCorridor.autEquiv hab w) := by - simp only [corridorPenaltyTerm,w.aut_counted hab D ω x y,RawCorridor.aut_weight hab P hP] - -theorem corridorPenalty_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - corridorPenalty G P p k (a ⁻¹' D) (b ⁻¹' ω) x y = - corridorPenalty G P p k D ω (a x) (a y) := by - unfold corridorPenalty - rw [←(RawCorridor.autEquiv hab).tsum_eq (corridorPenaltyTerm G P p D ω (a x) (a y))] - exact tsum_congr (fun w => corridorPenaltyTerm_aut G hab P hP p w D ω x y) - -end CountedCovariance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeformationCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedConnection_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - deformedConnection G P p k t (a ⁻¹' D) (b ⁻¹' ω) x y = - deformedConnection G P p k t D ω (a x) (a y) := by - simp only [deformedConnection,corridorPenalty_aut G hab P hP,Set.mem_preimage, - internalEdges_aut_preimage G hab,←Set.preimage_inter,conn_aut_iff G hab] - -theorem deformedKernel_aut [Countable V] [Countable E] - (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : - deformedKernel G P p k t D (a x) (a y) = deformedKernel G P p k t (a ⁻¹' D) x y := by - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable - (measurable_deformedConnection G P p k t (a ⁻¹' D) x y).aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [deformedKernel,deformedConnection_aut G hab P hP] using h.symm - -theorem deformedSusceptibility_aut [Countable V] [Countable E] - (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : - deformedSusceptibility G P p k t D (a x) = deformedSusceptibility G P p k t (a ⁻¹' D) x := by - unfold deformedSusceptibility - rw [←a.tsum_eq (deformedKernel G P p k t D (a x))] - exact tsum_congr (fun y => deformedKernel_aut G hab P hP p k t D x y) - - - -noncomputable def corridorDerivativeContribution (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : ℝ := - ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * - deformedConnection G P p k t Set.univ ω x y ∂law p - -theorem corridorDerivativeContribution_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : - 0 ≤ corridorDerivativeContribution G P p t w x y := - integral_corridorDerivativeTerm_nonneg G P hP p k t w x y - -theorem corridorDerivativeContribution_aut [Countable V] [Countable E] - (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : - corridorDerivativeContribution G P p t (RawCorridor.autEquiv hab w) (a x) (a y) = - corridorDerivativeContribution G P p t w x y := by - have hm := ((measurable_corridorPenaltyTerm G P p (a ⁻¹' Set.univ) x y w).mul - (measurable_deformedConnection G P p k t (a ⁻¹' Set.univ) x y)) - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - have hc (ω : Set E) := corridorPenaltyTerm_aut G hab P hP p w Set.univ ω x y - have hd (ω : Set E) := deformedConnection_aut G hab P hP p k t Set.univ ω x y - simp only [Set.preimage_univ] at hc hd - simpa only [Pi.mul_apply,corridorDerivativeContribution,Set.preimage_univ,hc,hd] using h.symm - -end DeformationCovariance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DerivativeTonelli -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem derivative_field_summable (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - Summable (fun yw : V × RawCorridor G k => corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * - deformedConnection G P p k t Set.univ ω x yw.1) := by - have hs (y : V) : Summable (fun w : RawCorridor G k => - corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y) := - (corridorPenalty_summable G hloc P p k Set.univ ω x y).mul_right - (deformedConnection G P p k t Set.univ ω x y) - have hr : Summable (fun y => corridorPenalty G P p k Set.univ ω x y * - deformedConnection G P p k t Set.univ ω x y) := by - apply summable_of_hasFiniteSupport - apply hf.subset - intro y hy - by_contra hn - apply hy - change corridorPenalty G P p k Set.univ ω x y * deformedConnection G P p k t Set.univ ω x y = 0 - rw [deformedConnection_eq_zero_of_not_conn G P p k t Set.univ ω x y hn,mul_zero] - have hn : 0 ≤ (fun yw : V × RawCorridor G k => - corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * deformedConnection G P p k t Set.univ ω x yw.1) := - fun yw => mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x yw.1 yw.2) - (deformedConnection_nonneg G P p k t Set.univ ω x yw.1) - apply (summable_prod_of_nonneg hn).mpr - refine ⟨hs,?_⟩ - simpa only [tsum_mul_right,corridorPenalty] using hr - -theorem derivative_field_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - (∑' yw : V × RawCorridor G k, corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * - deformedConnection G P p k t Set.univ ω x yw.1) = - deformedDerivativeMass G P p k t Set.univ ω x := by - rw [(derivative_field_summable G hloc P hP p k t ω x hf).tsum_prod] - simp only [tsum_mul_right,corridorPenalty,deformedDerivativeMass] - - - -theorem derivative_contribution_sum [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x : V) : - Summable (fun yw : V × RawCorridor G k => corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1) ∧ - (∑' yw : V × RawCorridor G k, corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1) = - ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x ∂law p := by - let F := fun yw : V × RawCorridor G k => fun ω => - corridorPenaltyTerm G (walkKernel G hloc a) p Set.univ ω x yw.1 yw.2 * - deformedConnection G (walkKernel G hloc a) p k t Set.univ ω x yw.1 - have hs : ∀ᵐ ω ∂law p, Summable (fun yw => F yw ω) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact derivative_field_summable G hloc _ hP p k t ω x hω - have he : (fun ω => ∑' yw, F yw ω) =ᵐ[law p] - fun ω => deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x := by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact derivative_field_sum G hloc _ hP p k t ω x hω - have hh := real_tonelli_of_integrable_sum (law p) F - (fun yw => integrable_corridorDerivativeTerm G _ hP p k t ht Set.univ x yw.1 yw.2) - (fun yw ω => mul_nonneg (corridorPenaltyTerm_nonneg G _ hP p Set.univ ω x yw.1 yw.2) - (deformedConnection_nonneg G _ p k t Set.univ ω x yw.1)) hs - ((integrable_deformedDerivativeMass G hloc hqt d hd a hP p hp0 hp k t ht Set.univ x).congr he.symm) - exact ⟨hh.1,hh.2.trans (integral_congr_ae he)⟩ - -end DerivativeTonelli -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DerivativeTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem raw_from_sum_eq_masked (G : BondGraph V E) (hloc : LocallyFinite G) - (k : ℕ) (u : V) (f : RawCorridor G k → ℝ) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, f ⟨u,w⟩) = - ∑' w : RawCorridor G k, if w.base = u then f w else 0 := by - have hs := summable_raw_selection G hloc k {u} (Set.finite_singleton u) - (fun w : RawCorridor G k => w.base = u) (fun _ h => h) f - rw [hs.tsum_sigma] - have he (x : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, - if (RawCorridor.base ⟨x,w⟩) = u then f ⟨x,w⟩ else 0) = - if x = u then (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, f ⟨u,w⟩) else 0 := by - by_cases hx : x = u - · subst x; simp only [RawCorridor.base,ite_true] - · simp only [RawCorridor.base,hx,ite_false,tsum_zero] - simp only [he,tsum_ite_eq] - -noncomputable def derivativeTransportMass (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : ℝ := - ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, - ∑' y, corridorDerivativeContribution G P p t ⟨u,w⟩ x y - -theorem derivativeTransportMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : - 0 ≤ derivativeTransportMass G P p k t x u := - tsum_nonneg (fun w => tsum_nonneg (fun y => corridorDerivativeContribution_nonneg G P hP p t ⟨u,w⟩ x y)) - -theorem derivativeTransportMass_aut [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) - (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : - derivativeTransportMass G P p k t (a x) (a u) = derivativeTransportMass G P p k t x u := by - unfold derivativeTransportMass - rw [raw_from_sum_eq_masked G hloc k (a u) (fun w => ∑' y, corridorDerivativeContribution G P p t w (a x) y), - raw_from_sum_eq_masked G hloc k u (fun w => ∑' y, corridorDerivativeContribution G P p t w x y)] - rw [←(RawCorridor.autEquiv hab).tsum_eq] - apply tsum_congr - intro w - simp only [RawCorridor.aut_base,a.injective.eq_iff] - by_cases hw : w.base = u - · simp only [hw,ite_true] - rw [←a.tsum_eq] - exact tsum_congr (fun y => corridorDerivativeContribution_aut G hab P hP p t w x y) - · simp only [hw,ite_false] - -end DerivativeTransport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DerivativeTransportSums -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -theorem summable_swapped_real {α β : Type*} (f : α → β → ℝ) - (hs : Summable (fun ab : α × β => f ab.1 ab.2)) : - Summable (fun ba : β × α => f ba.2 ba.1) := by - exact hs.comp_injective (Equiv.prodComm β α).injective - -theorem derivativeTransportMass_row (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x : V) : - Summable (derivativeTransportMass G (walkKernel G hloc a) p k t x) ∧ - (∑' u, derivativeTransportMass G (walkKernel G hloc a) p k t x u) = - ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x ∂law p := by - obtain ⟨hs,he⟩ := derivative_contribution_sum G hloc hqt d hd a hP p hp0 hp k t ht x - have hs' : Summable (fun wy : RawCorridor G k × V => - corridorDerivativeContribution G (walkKernel G hloc a) p t wy.1 x wy.2) := by - exact summable_swapped_real (fun y w => corridorDerivativeContribution G (walkKernel G hloc a) p t w x y) hs - have hr := hs'.prod.sigma - refine ⟨hr,?_⟩ - change (∑' u, ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, ∑' y, - corridorDerivativeContribution G (walkKernel G hloc a) p t ⟨u,w⟩ x y) = _ - rw [←hs'.prod.tsum_sigma,←hs'.tsum_prod] - exact ((Equiv.prodComm (RawCorridor G k) V).tsum_eq - (fun yw : V × RawCorridor G k => corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1)).trans he - -theorem derivativeTransportMass_column (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (u : V) : - Summable (fun x => derivativeTransportMass G P p k t x u) ∧ - (∑' x, derivativeTransportMass G P p k t x u) = - ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, - ∑' xy : V × V, corridorDerivativeContribution G P p t ⟨u,w⟩ xy.1 xy.2 := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k u) - have hs (w : RawFrom (openSimpleGraph G Set.univ) k u) : - Summable (fun xy : V × V => corridorDerivativeContribution G P p t ⟨u,w⟩ xy.1 xy.2) := - summable_corridorDerivativeTerm_pairs G hG hloc hqt P hP p hp0 hp t ht ⟨u,w⟩ - have hh : Summable (fun x => ∑ w : RawFrom (openSimpleGraph G Set.univ) k u, - ∑' y, corridorDerivativeContribution G P p t ⟨u,w⟩ x y) := - summable_sum (fun w _ => (hs w).prod) - refine ⟨by simpa only [derivativeTransportMass,tsum_fintype] using hh,?_⟩ - simp only [derivativeTransportMass,tsum_fintype] - rw [Summable.tsum_finsetSum (fun w _ => (hs w).prod)] - exact Finset.sum_congr rfl (fun w _ => (hs w).tsum_prod.symm) - -end DerivativeTransportSums -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AveragedDerivative -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] - - - -theorem averaged_derivative_transport (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) : - (∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p) = - ∑ i, weight i * ∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), - ∑' xy : V × V, corridorDerivativeContribution G (walkKernel G hloc a) p t ⟨root i,w⟩ xy.1 xy.2 := by - have hh := htr.real root weight Γ (derivativeTransportMass G (walkKernel G hloc a) p k t) - (fun g hg x u => by - obtain ⟨b,hb⟩ := hΓ hg - exact derivativeTransportMass_aut G hloc hb _ (walkKernel_covariant G hloc a hb) p k t x u) - (fun x => (derivativeTransportMass_row G hloc hqt d hd a hP p hp0 hp k t ht x).1) - (fun u => (derivativeTransportMass_column G hG hloc hqt _ hP p hp0 hp k t ht u).1) - simpa only [(derivativeTransportMass_row G hloc hqt d hd a hP p hp0 hp k t ht _).2, - (derivativeTransportMass_column G hG hloc hqt _ hP p hp0 hp k t ht _).2] using hh - -noncomputable def averagedDeformedSusceptibility (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := - ∑ i, weight i * deformedSusceptibility G P p k t Set.univ (root i) - -theorem hasDerivAt_averagedDeformedSusceptibility (G : BondGraph V E) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (root : ι → V) (weight : ι → ℝ) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 < t) : - HasDerivAt (averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight) - (-(∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p)) t := by - have he : -(∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p) = - ∑ i, weight i * (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p)) := by - simp only [mul_neg,Finset.sum_neg_distrib] - rw [he] - exact HasDerivAt.fun_sum (u := Finset.univ) (fun i _ => - (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht Set.univ (root i)).const_mul (weight i)) - -end AveragedDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PathAverage -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - -noncomputable def rawPathAverage (G : BondGraph V E) (P : V → V → ℝ) (k : ℕ) - (root : ι → V) (weight : ι → ℝ) (f : RawCorridor G k → ℝ) : ℝ := - ∑ i, weight i * ∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), - w.2.mass P * f ⟨root i,w⟩ - -theorem rawPathAverage_mono (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (k : ℕ) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (f g : RawCorridor G k → ℝ) (hfg : ∀ w, f w ≤ g w) : - rawPathAverage G P k root weight f ≤ rawPathAverage G P k root weight g := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - unfold rawPathAverage - apply Finset.sum_le_sum - intro i _ - apply mul_le_mul_of_nonneg_left _ (hw i) - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) - simp only [tsum_fintype] - exact Finset.sum_le_sum (fun w _ => mul_le_mul_of_nonneg_left (hfg _) (w.2.mass_nonneg P hP)) - -theorem rawPathAverage_sub (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (k : ℕ) (root : ι → V) (weight : ι → ℝ) - (f g : RawCorridor G k → ℝ) : - rawPathAverage G P k root weight (fun w => f w-g w) = - rawPathAverage G P k root weight f - rawPathAverage G P k root weight g := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - have he (i : ι) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), - w.2.mass P * (f ⟨root i,w⟩-g ⟨root i,w⟩)) = - (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), w.2.mass P*f ⟨root i,w⟩) - - (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), w.2.mass P*g ⟨root i,w⟩) := by - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) - simp only [tsum_fintype,mul_sub,Finset.sum_sub_distrib] - simp only [rawPathAverage] - simp only [he] - simp only [mul_sub,Finset.sum_sub_distrib] - -theorem rawPathAverage_const_mul (G : BondGraph V E) (P : V → V → ℝ) (k : ℕ) - (root : ι → V) (weight : ι → ℝ) (c : ℝ) (f : RawCorridor G k → ℝ) : - rawPathAverage G P k root weight (fun w => c*f w) = c*rawPathAverage G P k root weight f := by - unfold rawPathAverage - simp only [←mul_left_comm c,tsum_mul_left,Finset.mul_sum] - -noncomputable def retainedSusceptibilityProduct (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) : ℝ := - if 3 ≤ w.path.length then - deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.base * - deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.endpoint - else 0 - -end PathAverage -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AveragedCalibratedDecrease -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] - -theorem raw_derivative_template_row_lower (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) - (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (k : ℕ) (w : RawCorridor G k) - (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) : - Real.exp (-t*c) * (w.probability P * - (retainedSusceptibilityProduct G P p t w - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2*(matrixCoeff (T^3) w.base w.endpoint).re)) ≤ - ∑' xy : V × V, corridorDerivativeContribution G P p t w xy.1 xy.2 := by - by_cases hlen : 3 ≤ w.path.length - · have hh := calibrated_derivative_template_row_lower G hG hloc hqt d - (fun x => (neighbors_card_le_degree G hloc x).trans (hd x)) P hP hpcrit p hp hpnear T hT k w hlen c hc t ht - simpa only [retainedSusceptibilityProduct,hlen,ite_true,corridorDerivativeContribution, - mul_assoc,mul_left_comm (Real.exp (-t*c))] using hh - · have hC : 0 ≤ 1+2*(d:ℝ)/(pc G:ℝ) := by positivity - have hA := (((hT.positiveRealMatrix G p T).pow 3) w.base w.endpoint).2 - have hpr := w.2.2.mass_nonneg P hP - have hr : 0 ≤ ∑' xy : V × V, corridorDerivativeContribution G P p t w xy.1 xy.2 := - tsum_nonneg (fun xy => corridorDerivativeContribution_nonneg G P hP p t w xy.1 xy.2) - apply le_trans _ hr - simp only [retainedSusceptibilityProduct,hlen,ite_false,zero_sub,mul_neg] - exact neg_nonpos.mpr (mul_nonneg (Real.exp_pos _).le (mul_nonneg hpr - (mul_nonneg (mul_nonneg hC (sq_nonneg _)) hA))) - - -theorem averaged_derivative_raw_lower (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (hpcrit : 0 < (pc G:ℝ)) - (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (k : ℕ) (c : ℝ) (hc : ∀ w : RawCorridor G k, - (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight (walkKernel G hloc a) p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) : - Real.exp (-t*c) * - (rawPathAverage G (walkKernel G hloc a) k root weight (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * - rawPathAverage G (walkKernel G hloc a) k root weight (fun w => (matrixCoeff (T^3) w.base w.endpoint).re)) ≤ - ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p := by - rw [averaged_derivative_transport G hG hloc hqt root weight Γ hΓ htr d hd a hP p - ((half_pos hpcrit).trans_le hpnear) hp k t ht] - rw [←rawPathAverage_const_mul G _ k root weight _ (fun w => (matrixCoeff (T^3) w.base w.endpoint).re), - ←rawPathAverage_sub G hloc] - unfold rawPathAverage - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - rw [mul_left_comm] - apply mul_le_mul_of_nonneg_left _ (hw i) - rw [←tsum_mul_left] - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) - simp only [tsum_fintype] - exact Finset.sum_le_sum (fun w _ => raw_derivative_template_row_lower G hG hloc hqt d hd _ hP - hpcrit p hp hpnear T hT k ⟨root i,w⟩ c (hc _) t ht) - -end AveragedCalibratedDecrease -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PathErrorTrace -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - -theorem rawPathAverage_operator_trace (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (A : Hilbert V →L[ℂ] Hilbert V) (hAs : IsSelfAdjoint A) - (k : ℕ) (root : ι → V) (weight : ι → ℝ) : - rawPathAverage G (walkKernel G hloc a) k root weight - (fun w => (matrixCoeff A w.base w.endpoint).re) = (rootTrace root weight (P^k*A)).re := by - have he (u : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, - w.2.mass (walkKernel G hloc a) * (matrixCoeff A u w.1).re) = (matrixCoeff (P^k*A) u u).re := by - change RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k u - (fun v => (matrixCoeff A u v).re) = _ - rw [raw_integral_operator G hloc a P hpos hP] - simp only [matrixCoeff_real_symm A hAs u] - exact ((hpos.pow k).mul_hasSum A u u).tsum_eq - simp only [rawPathAverage,RawCorridor.base,RawCorridor.endpoint,he,rootTrace, - Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] - -open scoped ComplexOrder -attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass -local instance averagedDecreasePathNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -local instance averagedDecreasePathContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) - - - -theorem rawPathAverage_operator_le_norm (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (Γ : Set (V ≃ V)) (htr : RootTransport root weight Γ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hPi : KernelInvariant Γ P) (hPs : IsSelfAdjoint P) - (A : Hilbert V →L[ℂ] Hilbert V) (hAi : KernelInvariant Γ A) (hA : 0 ≤ A) (k : ℕ) : - rawPathAverage G (walkKernel G hloc a) k root weight - (fun w => (matrixCoeff A w.base w.endpoint).re) ≤ - ‖P‖^k * (rootTrace root weight A).re := by - rw [rawPathAverage_operator_trace G hloc a P hpos hP A (IsSelfAdjoint.of_nonneg hA)] - have hh := rootTrace_positive_mul_le root weight htr hw A (P^k) hAi (hPi.pow k) hA (hPs.pow k) - have hr := (Complex.le_def.mp hh).1 - simp only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] at hr - have hn : ‖P^k‖ ≤ ‖P‖^k := by - cases k with - | zero => - simp only [pow_zero] - have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext f; rfl - rw [he] - exact ContinuousLinearMap.norm_id_le - | succ j => exact norm_pow_le' P (Nat.succ_pos j) - exact hr.trans (mul_le_mul_of_nonneg_right hn - (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw A hA)).1) - -end PathErrorTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ComplexOrder -section UniformAveragedDecrease -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] -attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass -local instance averagedDecreaseUniformNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -local instance averagedDecreaseUniformContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) - - - -theorem exists_uniform_averaged_decrease (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hPs : IsSelfAdjoint P) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → ∀ (k : ℕ), 3 ≤ k → - ∀ (t : ℝ), 0 ≤ t → - Real.exp (-t*Real.exp (C*(k:ℝ))) * - (rawPathAverage G (walkKernel G hloc a) k root weight - (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * - (‖P‖^k * (rootTrace root weight (T^3)).re)) ≤ - ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p := by - obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_leg_cost G hG hloc d hd a hK hpcrit hpcrit₁ - refine ⟨C,hC,?_⟩ - intro p hpnear hp T hT k hk t ht - have hpositive : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) - have hTi : KernelInvariant Γ T := fun g hg => hT.invariant G p T g (hΓ hg) - have hPi : KernelInvariant Γ P := by - intro g hg x y - obtain ⟨b,hb⟩ := hΓ hg - simp only [hP,walkKernel_covariant G hloc a hb] - have herr := rawPathAverage_operator_le_norm G hloc a root weight hw Γ htr P hpos hP hPi hPs - (T^3) (hTi.pow 3) (CStarAlgebra.pow_nonneg T 3 hpositive) k - have hCnonneg : 0 ≤ (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 := by positivity - apply le_trans _ (averaged_derivative_raw_lower G hG hloc hqt root weight hw Γ hΓ htr - d hd a hK hpcrit p hp hpnear T hT k (Real.exp (C*(k:ℝ))) (hcost p hpnear hp k hk) t ht) - exact mul_le_mul_of_nonneg_left (sub_le_sub_left (mul_le_mul_of_nonneg_left herr hCnonneg) _) - (Real.exp_pos _).le - -end UniformAveragedDecrease -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeformedRowComparison -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] - - - -theorem exists_uniform_deformed_row_comparison (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : - ∃ C cf : ℝ, 0 < C ∧ 0 < cf ∧ ∀ (p : unitInterval), - (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → ∀ (k : ℕ), 3 ≤ k → ∀ (t : ℝ), - 0 ≤ t → t*Real.exp (C*(k:ℝ)) ≤ 1 → ∀ x, - cf*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x := by - obtain ⟨C,hC,hmove⟩ := exists_uniform_deformed_endpoint_comparison G hloc hqt d hd a hP hpcrit hpcrit₁ - have hex (ij : ι × ι) : ∃ l : List E, Along G (root ij.1) l (root ij.2) := by - obtain ⟨l,hl,_,_⟩ := conn_exists_bond_trail G (conn_univ_of_connected G hconn (root ij.1) (root ij.2)) - exact ⟨l,hl⟩ - choose path hpath using hex - let N := ∑ ij : ι × ι, (path ij).length - have hlen (i j : ι) : (path (i,j)).length ≤ N := - Finset.single_le_sum (f := fun ij : ι × ι => (path ij).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ (i,j)) - refine ⟨C,Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N,hC,mul_pos (Real.exp_pos _) (pow_pos (half_pos hpcrit) N),?_⟩ - intro p hpnear hp k hk t ht htc x - obtain ⟨j,g,b,hgb,hgx⟩ := hcover x - have hb (i : ι) : (Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N)* - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root i) ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root j) := by - have hh := hmove p hpnear hp k hk t ht Set.univ (root j) (root i) (path (j,i)) - (Set.mem_univ _) (hpath (j,i)) (fun _ _ _ _ => Set.mem_univ _) - have hpow : ((pc G:ℝ)/2)^N ≤ (p:ℝ)^(path (j,i)).length := - (pow_le_pow_left₀ (half_pos hpcrit).le hpnear N).trans - (pow_le_pow_of_le_one p.2.1 p.2.2 (hlen j i)) - have he : Real.exp (-(N:ℝ)) ≤ Real.exp (-t*((path (j,i)).length*Real.exp (C*(k:ℝ)))) := by - apply Real.exp_le_exp.mpr - have hh := mul_le_mul_of_nonneg_right htc (Nat.cast_nonneg (path (j,i)).length : (0:ℝ) ≤ _) - have hn : ((path (j,i)).length:ℝ) ≤ (N:ℝ) := Nat.cast_le.mpr (hlen j i) - nlinarith - exact (mul_le_mul_of_nonneg_right (mul_le_mul he hpow (pow_nonneg (half_pos hpcrit).le _) (Real.exp_pos _).le) - (deformedSusceptibility_nonneg G _ p k t Set.univ (root i))).trans hh - rw [←hgx,deformedSusceptibility_aut G hgb _ (walkKernel_covariant G hloc a hgb)] - simp only [Set.preimage_univ] - calc - _ = ∑ i, weight i*((Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N)* - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root i)) := by - simp only [averagedDeformedSusceptibility,Finset.mul_sum] - exact Finset.sum_congr rfl (fun _ _ => by ring) - _ ≤ ∑ i, weight i*deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root j) := - Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hb i) (hw i)) - _ = _ := by rw [←Finset.sum_mul,hw1,one_mul] - -end DeformedRowComparison -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AnchoredSegments -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - -def segmentOrbit (G : BondGraph V E) (γ : I → V) : Set (I → V) := - {s | ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ s = a ∘ γ} - -omit [Fintype I] in -theorem segmentOrbit_aut_iff (G : BondGraph V E) (γ s : I → V) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : - a ∘ s ∈ segmentOrbit G γ ↔ s ∈ segmentOrbit G γ := by - constructor - · rintro ⟨c,d,hcd,he⟩ - refine ⟨c.trans a.symm,d.trans b.symm,isAut_trans G hcd (isAut_symm G h),?_⟩ - funext i - have hh := congrFun he i - simpa only [Function.comp_apply,Equiv.trans_apply,Equiv.symm_apply_apply] using congrArg a.symm hh - · rintro ⟨c,d,hcd,rfl⟩ - exact ⟨c.trans a,d.trans b,isAut_trans G hcd h,rfl⟩ - -theorem finite_segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : - {s ∈ segmentOrbit G γ | s i = x}.Finite := by - apply (Set.Finite.pi' (fun _ : I => finite_reachBall hloc x n)).subset - rintro s ⟨⟨a,b,hab,rfl⟩,hx⟩ j - have hh := mem_reachBall_aut G hab (hdiam i j) - change a (γ i) = x at hx - simpa only [hx,Function.comp_apply] using hh - -noncomputable def segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : Finset (I → V) := - (finite_segmentAnchors G hloc γ n hdiam i x).toFinset - -theorem mem_segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) (s : I → V) : - s ∈ segmentAnchors G hloc γ n hdiam i x ↔ s ∈ segmentOrbit G γ ∧ s i = x := by - exact Set.Finite.mem_toFinset _ - -theorem segmentAnchors_nonempty_iff (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : - (segmentAnchors G hloc γ n hdiam i x).Nonempty ↔ x ∈ vertexOrbit G (γ i) := by - constructor - · rintro ⟨s,hs⟩ - obtain ⟨⟨a,b,h,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs - exact ⟨a,b,h,hx⟩ - · rintro ⟨a,b,h,hx⟩ - exact ⟨a ∘ γ,(mem_segmentAnchors G hloc γ n hdiam i x _).mpr ⟨⟨a,b,h,rfl⟩,hx⟩⟩ - -end AnchoredSegments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AnchoredPositionKernels -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - -def segmentAut (a : V ≃ V) : (I → V) ≃ (I → V) where - toFun s := a ∘ s - invFun s := a.symm ∘ s - left_inv s := by funext i; exact a.symm_apply_apply (s i) - right_inv s := by funext i; exact a.apply_symm_apply (s i) - -theorem segmentAnchors_map (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : - segmentAnchors G hloc γ n hdiam i (a x) = - (segmentAnchors G hloc γ n hdiam i x).map (segmentAut a).toEmbedding := by - ext s - rw [Finset.mem_map,mem_segmentAnchors] - constructor - · rintro ⟨hs,hx⟩ - refine ⟨a.symm ∘ s,(mem_segmentAnchors G hloc γ n hdiam i x _).mpr ⟨?_,?_⟩,?_⟩ - · exact (segmentOrbit_aut_iff G γ s (isAut_symm G h)).mpr hs - · simp only [Function.comp_apply,hx,Equiv.symm_apply_apply] - · funext j; exact a.apply_symm_apply (s j) - · rintro ⟨t,ht,rfl⟩ - obtain ⟨ht,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x t).mp ht - exact ⟨(segmentOrbit_aut_iff G γ t h).mpr ht,congrArg a hx⟩ - -theorem segmentAnchors_card_aut (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : - (segmentAnchors G hloc γ n hdiam i (a x)).card = (segmentAnchors G hloc γ n hdiam i x).card := by - rw [segmentAnchors_map G hloc γ n hdiam i x h,Finset.card_map] - - - -noncomputable def anchoredPositionKernel (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : ℝ := - ∑ s ∈ segmentAnchors G hloc γ n hdiam i x, - if y = s j then ((segmentAnchors G hloc γ n hdiam i x).card : ℝ)⁻¹ else 0 - -theorem anchoredPositionKernel_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : - 0 ≤ anchoredPositionKernel G hloc γ n hdiam i j x y := by - apply Finset.sum_nonneg - intro s _ - split_ifs <;> positivity - -theorem anchoredPositionKernel_aut (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : - anchoredPositionKernel G hloc γ n hdiam i j (a x) (a y) = - anchoredPositionKernel G hloc γ n hdiam i j x y := by - simp only [anchoredPositionKernel,segmentAnchors_map G hloc γ n hdiam i x h, - Finset.card_map,Finset.sum_map,Equiv.toEmbedding_apply, - segmentAut,Equiv.coe_fn_mk,Function.comp_apply,Equiv.apply_eq_iff_eq] - -end AnchoredPositionKernels -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AnchoredPositionRows -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - -theorem anchoredPositionKernel_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x : V) : - HasSum (anchoredPositionKernel G hloc γ n hdiam i j x) - (if x ∈ vertexOrbit G (γ i) then (1:ℝ) else 0) := by - have hh := hasSum_sum (s := segmentAnchors G hloc γ n hdiam i x) - (fun s _ => hasSum_ite_eq (s j) (((segmentAnchors G hloc γ n hdiam i x).card:ℝ)⁻¹)) - have he : (∑ s ∈ segmentAnchors G hloc γ n hdiam i x, - ((segmentAnchors G hloc γ n hdiam i x).card:ℝ)⁻¹) = - if x ∈ vertexOrbit G (γ i) then (1:ℝ) else 0 := by - simp only [Finset.sum_const,nsmul_eq_mul] - by_cases hx : x ∈ vertexOrbit G (γ i) - · have hn := Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i x).mpr hx) - rw [ite_eq_left hx,mul_inv_cancel₀ (Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn))] - · have he : segmentAnchors G hloc γ n hdiam i x = ∅ := Finset.not_nonempty_iff_eq_empty.mp - (fun h => hx ((segmentAnchors_nonempty_iff G hloc γ n hdiam i x).mp h)) - simp only [he,Finset.card_empty,Nat.cast_zero,zero_mul,ite_eq_right hx] - rw [he] at hh - exact hh - -theorem anchoredPositionKernel_eq_zero_off_ball (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) - (hxy : y ∉ reachBall G x n) : anchoredPositionKernel G hloc γ n hdiam i j x y = 0 := by - apply Finset.sum_eq_zero - intro s hs - apply ite_eq_right - intro hy - obtain ⟨⟨a,b,hab,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs - change a (γ i) = x at hx - change y = a (γ j) at hy - exact hxy (by simpa only [hx,←hy] using mem_reachBall_aut G hab (hdiam i j)) - -theorem anchoredPositionKernel_eq_zero_off_orbits (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : - x ∉ vertexOrbit G (γ i) ∨ y ∉ vertexOrbit G (γ j) → - anchoredPositionKernel G hloc γ n hdiam i j x y = 0 := by - intro h - apply Finset.sum_eq_zero - intro s hs - apply ite_eq_right - intro hy - obtain ⟨⟨a,b,hab,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs - rcases h with h | h - · exact h ⟨a,b,hab,hx⟩ - · exact h ⟨a,b,hab,hy.symm⟩ - -end AnchoredPositionRows -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AnchoredPositionColumns -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - -theorem anchoredPositionKernel_columnSummable (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (y : V) : - Summable (fun x => anchoredPositionKernel G hloc γ n hdiam i j x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) - intro x hx - simp only [Set.Finite.mem_toFinset] at hx - apply Finset.sum_eq_zero - intro s hs - apply ite_eq_right - intro hy - obtain ⟨⟨a,b,hab,rfl⟩,he⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs - change a (γ i) = x at he - change y = a (γ j) at hy - exact hx (by simpa only [he,←hy] using mem_reachBall_aut G hab (hdiam j i)) - -theorem anchoredPositionKernel_column_orbit (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (y : V) : - (∑' x, anchoredPositionKernel G hloc γ n hdiam i j x y) = - if y ∈ vertexOrbit G (γ j) then - ∑' x, anchoredPositionKernel G hloc γ n hdiam i j x (γ j) else 0 := by - by_cases hy : y ∈ vertexOrbit G (γ j) - · rw [ite_eq_left hy] - obtain ⟨a,b,hab,rfl⟩ := hy - rw [←a.tsum_eq] - exact tsum_congr (fun x => anchoredPositionKernel_aut G hloc γ n hdiam i j x (γ j) hab) - · rw [ite_eq_right hy] - calc - _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun x => - anchoredPositionKernel_eq_zero_off_orbits G hloc γ n hdiam i j x y (Or.inr hy)) - _ = 0 := tsum_zero - - - -theorem anchoredPositionKernel_column_mass {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) : - (∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) = - (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) * - ∑' x, anchoredPositionKernel G hloc γ n hdiam i j x (γ j) := by - have ht := htr.real root weight Γ (anchoredPositionKernel G hloc γ n hdiam i j) - (fun a ha x y => by - obtain ⟨b,hb⟩ := hΓ ha - exact anchoredPositionKernel_aut G hloc γ n hdiam i j x y hb) - (fun x => (anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable) - (anchoredPositionKernel_columnSummable G hloc γ n hdiam i j) - calc - _ = ∑ r, weight r * ∑' y, anchoredPositionKernel G hloc γ n hdiam i j (root r) y := by - apply Finset.sum_congr rfl - intro r _ - rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j (root r)).tsum_eq] - split_ifs <;> simp only [mul_one,mul_zero] - _ = _ := ht - _ = _ := by - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro r _ - rw [anchoredPositionKernel_column_orbit] - split_ifs <;> simp only [mul_zero,zero_mul] - -theorem anchoredPositionKernel_column_ratio {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) - (hj : 0 < ∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) (y : V) : - (∑' x, anchoredPositionKernel G hloc γ n hdiam i j x y) = - if y ∈ vertexOrbit G (γ j) then - (∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) / - (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) else 0 := by - have he := anchoredPositionKernel_column_mass G hloc root weight Γ hΓ htr γ n hdiam i j - rw [anchoredPositionKernel_column_orbit] - congr 1 - exact (eq_div_iff (ne_of_gt hj)).mpr (by simpa only [mul_comm] using he.symm) - -end AnchoredPositionColumns -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -section AsymmetricSchur -open scoped ENNReal -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_operator_of_unit_row_column_bound (U : V → V → ℝ) (D : ℝ) - (hD : 0 ≤ D) (hU : ∀ x y, 0 ≤ U x y) - (hrow : ∀ x (s : Finset V), ∑ y ∈ s, U x y ≤ 1) - (hcol : ∀ y (s : Finset V), ∑ x ∈ s, U x y ≤ D) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ Real.sqrt D ∧ - ∀ x y, matrixCoeff A x y = (U x y : ℂ) := by - have hentry (x y : V) : U x y ≤ 1 := by simpa only [Finset.sum_singleton] using hrow x {y} - have hcm (y : V) : Memℓp (fun x => (U x y : ℂ)) 2 := by - apply (memℓp_gen_iff'' (by norm_num : 0 < (2 : ℝ≥0∞).toReal)).mpr - refine ⟨D,hD,fun s => ?_⟩ - simp only [ENNReal.toReal_ofNat,Real.rpow_two,Complex.norm_real,Real.norm_eq_abs,sq_abs] - exact (Finset.sum_le_sum (fun x _ => by nlinarith [hentry x y,hU x y])).trans (hcol y s) - let col (y : V) : Hilbert V := ⟨fun x => (U x y : ℂ),hcm y⟩ - let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col - have hn (f : V →₀ ℂ) : ‖L f‖ ≤ Real.sqrt D * ‖finiteEmbedding f‖ := by - apply lp.norm_le_of_forall_sum_le (by norm_num) - (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _)) - intro s - simp only [ENNReal.toReal_ofNat,Real.rpow_two] - have hpoint (x : V) : ‖L f x‖^2 ≤ ∑ y ∈ f.support, ‖f y‖^2 * U x y := by - have hn0 : 0 ≤ ∑ y ∈ f.support, ‖f y‖*U x y := - Finset.sum_nonneg (fun y _ => mul_nonneg (norm_nonneg _) (hU x y)) - have hn1 : ‖L f x‖ ≤ ∑ y ∈ f.support, ‖f y‖*U x y := by - simp only [L,Finsupp.linearCombination_apply,Finsupp.sum,lp.coeFn_sum, - Finset.sum_apply,lp.coeFn_smul,Pi.smul_apply,smul_eq_mul] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - simp [col,abs_of_nonneg (hU x y)] - have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul f.support - (f := fun y => U x y) (g := fun y => ‖f y‖^2*U x y) - (r := fun y => ‖f y‖*U x y) - (fun y _ => hU x y) - (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) (fun y _ => by nlinarith) - have hn2 : 0 ≤ ∑ y ∈ f.support, ‖f y‖^2*U x y := - Finset.sum_nonneg (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) - have hr := mul_le_mul_of_nonneg_right (hrow x f.support) hn2 - rw [one_mul] at hr - exact (sq_le_sq₀ (norm_nonneg _) hn0 |>.mpr hn1).trans (hcs.trans hr) - calc - ∑ x ∈ s, ‖L f x‖^2 ≤ ∑ x ∈ s, ∑ y ∈ f.support, ‖f y‖^2*U x y := - Finset.sum_le_sum (fun x _ => hpoint x) - _ = ∑ y ∈ f.support, ‖f y‖^2*∑ x ∈ s, U x y := by - rw [Finset.sum_comm] - simp_rw [Finset.mul_sum] - _ ≤ ∑ y ∈ f.support, ‖f y‖^2*D := - Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_left (hcol y s) (sq_nonneg _)) - _ = D*∑ y ∈ f.support, ‖finiteEmbedding f y‖^2 := by - simp only [finiteEmbedding_apply] - rw [←Finset.sum_mul,mul_comm] - _ ≤ D*‖finiteEmbedding f‖^2 := by - apply mul_le_mul_of_nonneg_left _ hD - simpa only [ENNReal.toReal_ofNat,Real.rpow_two] using - lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2:ℝ≥0∞).toReal) (finiteEmbedding f) f.support - _ = (Real.sqrt D*‖finiteEmbedding f‖)^2 := by rw [mul_pow,Real.sq_sqrt hD] - refine ⟨L.extendOfNorm finiteEmbedding, - LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense (Real.sqrt_nonneg _) hn,?_⟩ - intro x y - have he := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨Real.sqrt D,hn⟩ - (Finsupp.single y (1:ℂ)) - simp only [finiteEmbedding_single] at he - change (L.extendOfNorm finiteEmbedding) (lp.single 2 y (1:ℂ)) x = _ - rw [he] - simp [L,col] - -end AsymmetricSchur -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AnchoredPositionOperators -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι : Type*} [Fintype I] [Fintype ι] - - - -theorem exists_anchoredPositionOperator (G : BondGraph V E) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) - (hj : 0 < ∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) : - ∃ H : Hilbert V →L[ℂ] Hilbert V, - (∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam i j x y : ℂ)) ∧ - ‖H‖ ≤ Real.sqrt ((∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) / - (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0)) := by - have hnum : 0 ≤ ∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0 := - Finset.sum_nonneg (fun r _ => by split_ifs; exact hw r; exact le_refl 0) - have hratio := div_nonneg hnum hj.le - obtain ⟨H,hn,hH⟩ := exists_operator_of_unit_row_column_bound - (anchoredPositionKernel G hloc γ n hdiam i j) _ hratio - (anchoredPositionKernel_nonneg G hloc γ n hdiam i j) - (fun x s => ((anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable.sum_le_tsum s - (fun y _ => anchoredPositionKernel_nonneg G hloc γ n hdiam i j x y)).trans (by - rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).tsum_eq] - split_ifs <;> norm_num)) - (fun y s => ((anchoredPositionKernel_columnSummable G hloc γ n hdiam i j y).sum_le_tsum s - (fun x _ => anchoredPositionKernel_nonneg G hloc γ n hdiam i j x y)).trans (by - rw [anchoredPositionKernel_column_ratio G hloc root weight Γ hΓ htr γ n hdiam i j hj y] - split_ifs; exact le_refl _; exact hratio)) - exact ⟨H,hH,hn⟩ - - -theorem exists_anchoredPositionOperator_uniform (G : BondGraph V E) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ a ∈ Γ, a (root r) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) : - ∃ H : Hilbert V →L[ℂ] Hilbert V, - (∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam i j x y : ℂ)) ∧ - ‖H‖ ≤ Real.sqrt c := by - let U := anchoredPositionKernel G hloc γ n hdiam i j - have hn : ∀ x y, 0 ≤ U x y := anchoredPositionKernel_nonneg G hloc γ n hdiam i j - have hr : ∀ x, Summable (U x) := fun x => (anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable - have hcol := anchoredPositionKernel_columnSummable G hloc γ n hdiam i j - have hb (x : V) : (∑' y, U x y) ≤ 1 := by - rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).tsum_eq] - split_ifs <;> norm_num - have hi : ∀ a ∈ Γ, ∀ x y, U (a x) (a y) = U x y := by - intro a ha x y - obtain ⟨b,hb⟩ := hΓ ha - exact anchoredPositionKernel_aut G hloc γ n hdiam i j x y hb - have hbcol (y : V) : (∑' x, U x y) ≤ c := by - simpa only [mul_one] using transported_column_le root weight Γ htr hcov hw hw1 c hc hmin U hn hi hr hcol 1 hb y - obtain ⟨H,hHn,hH⟩ := exists_operator_of_unit_row_column_bound U c hc hn - (fun x s => ((hr x).sum_le_tsum s (fun y _ => hn x y)).trans (hb x)) - (fun y s => ((hcol y).sum_le_tsum s (fun x _ => hn x y)).trans (hbcol y)) - exact ⟨H,hH,hHn⟩ - -end AnchoredPositionOperators -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -section RawReversal -namespace HoldingWalk -variable {H : SimpleGraph V} - - -def snocHold : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H (k+1) x y - | _,_,_,.nil x => .hold (.nil x) - | _,_,_,.hold w => .hold (snocHold w) - | _,_,_,.step h w => .step h (snocHold w) - - -def snocStep : {k : ℕ} → {x y z : V} → HoldingWalk H k x y → H.Adj y z → HoldingWalk H (k+1) x z - | _,_,_,z,.nil _,h => .step h (.nil z) - | _,_,_,_,.hold w,h => .hold (snocStep w h) - | _,_,_,_,.step h' w,h => .step h' (snocStep w h) - - - -def reverse : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H k y x - | _,_,_,.nil x => .nil x - | _,_,_,.hold w => snocHold (reverse w) - | _,_,_,.step h w => snocStep (reverse w) h.symm - -theorem reverse_snocHold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - w.snocHold.reverse = w.reverse.hold := by - induction w with - | nil => rfl - | hold w ih => simp only [snocHold,reverse,ih] - | step h w ih => simp only [snocHold,reverse,ih,snocStep] - -theorem reverse_snocStep {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : - (w.snocStep h).reverse = .step h.symm w.reverse := by - induction w with - | nil => rfl - | hold w ih => simp only [snocStep,reverse,ih,snocHold] - | step h' w ih => simp only [snocStep,reverse,ih] - -theorem reverse_reverse {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.reverse.reverse = w := by - induction w with - | nil => rfl - | hold w ih => simp only [reverse,reverse_snocHold,ih] - | step h w ih => simp only [reverse,reverse_snocStep,ih] - -def reverseEquiv (k : ℕ) (x y : V) : HoldingWalk H k x y ≃ HoldingWalk H k y x where - toFun := reverse - invFun := reverse - left_inv := reverse_reverse - right_inv := reverse_reverse - -theorem mass_snocHold (P : V → V → ℝ) {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - w.snocHold.mass P = w.mass P * P y y := by - induction w with - | nil => simp only [snocHold,mass,mul_one,one_mul] - | hold w ih => simp only [snocHold,mass,ih,mul_assoc] - | step h w ih => simp only [snocHold,mass,ih,mul_assoc] - -theorem mass_snocStep (P : V → V → ℝ) {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : - (w.snocStep h).mass P = w.mass P * P y z := by - induction w with - | nil => simp only [snocStep,mass,mul_one,one_mul] - | hold w ih => simp only [snocStep,mass,ih,mul_assoc] - | step h' w ih => simp only [snocStep,mass,ih,mul_assoc] - -theorem mass_reverse (P : V → V → ℝ) (hP : ∀ x y, P x y = P y x) - {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.reverse.mass P = w.mass P := by - induction w with - | nil => rfl - | hold w ih => simp only [reverse,mass_snocHold,mass,ih,mul_comm] - | step h w ih => simp only [reverse,mass_snocStep,mass,ih,hP,mul_comm] - -theorem vertices_snocHold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - w.snocHold.vertices = w.vertices ++ [y] := by - induction w with - | nil => rfl - | hold w ih => simp only [snocHold,vertices,ih,List.cons_append] - | step h w ih => simp only [snocHold,vertices,ih,List.cons_append] - -theorem vertices_snocStep {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : - (w.snocStep h).vertices = w.vertices ++ [z] := by - induction w with - | nil => rfl - | hold w ih => simp only [snocStep,vertices,ih,List.cons_append] - | step h' w ih => simp only [snocStep,vertices,ih,List.cons_append] - -theorem vertices_reverse {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - w.reverse.vertices = w.vertices.reverse := by - induction w with - | nil => rfl - | hold w ih => simp only [reverse,vertices_snocHold,vertices,ih,List.reverse_cons] - | step h w ih => simp only [reverse,vertices_snocStep,vertices,ih,List.reverse_cons] - -end HoldingWalk -end RawReversal -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.Calibration + +namespace OAI + +/-! Averaged Decrease for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CountedCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem preimage_diff_singleton (b : E ≃ E) (ω : Set E) (e : E) : + (b ⁻¹' ω) \ {e} = b ⁻¹' (ω \ {b e}) := by + ext f + simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] + +theorem corridorCounted_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (S B : Set E) (D : Set V) (ω : Set E) (x y : V) : + corridorCounted G (b ⁻¹' S) (b ⁻¹' B) (a ⁻¹' D) (b ⁻¹' ω) x y ↔ + corridorCounted G S B D ω (a x) (a y) := by + have he : (b ⁻¹' ω) ∩ internalEdges G (a ⁻¹' D) = b ⁻¹' (ω ∩ internalEdges G D) := by + rw [internalEdges_aut_preimage G hab,Set.preimage_inter] + simp only [corridorCounted,he,conn_aut_iff G hab,preimage_diff_singleton, + Set.mem_preimage] + apply and_congr_right + intro _ + constructor + · rintro ⟨hp,hB⟩ + constructor + · intro e he + obtain ⟨f,rfl⟩ := b.surjective e + exact hp f he + · apply Set.disjoint_left.mpr + intro e he hw + obtain ⟨f,rfl⟩ := b.surjective e + exact Set.disjoint_left.mp hB he hw + · rintro ⟨hp,hB⟩ + exact ⟨fun e he => hp (b e) he,Set.disjoint_left.mpr (fun e he hw => Set.disjoint_left.mp hB he hw)⟩ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem aut_counted {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : + w.counted (a ⁻¹' D) (b ⁻¹' ω) x y ↔ (autEquiv hab w).counted D ω (a x) (a y) := by + have hr : w.retained = b ⁻¹' (autEquiv hab w).retained := by + ext e + exact (aut_retained hab w e).symm + have hb : w.blockers = b ⁻¹' (autEquiv hab w).blockers := by + ext e + exact (aut_blockers hab w e).symm + rw [counted_iff,counted_iff,aut_path_length,hr,hb,corridorCounted_aut G hab] + +end RawCorridor + +theorem corridorPenaltyTerm_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : ℝ) {k : ℕ} (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : + corridorPenaltyTerm G P p (a ⁻¹' D) (b ⁻¹' ω) x y w = + corridorPenaltyTerm G P p D ω (a x) (a y) (RawCorridor.autEquiv hab w) := by + simp only [corridorPenaltyTerm,w.aut_counted hab D ω x y,RawCorridor.aut_weight hab P hP] + +theorem corridorPenalty_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + corridorPenalty G P p k (a ⁻¹' D) (b ⁻¹' ω) x y = + corridorPenalty G P p k D ω (a x) (a y) := by + unfold corridorPenalty + rw [←(RawCorridor.autEquiv hab).tsum_eq (corridorPenaltyTerm G P p D ω (a x) (a y))] + exact tsum_congr (fun w => corridorPenaltyTerm_aut G hab P hP p w D ω x y) + +end CountedCovariance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeformationCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedConnection_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + deformedConnection G P p k t (a ⁻¹' D) (b ⁻¹' ω) x y = + deformedConnection G P p k t D ω (a x) (a y) := by + simp only [deformedConnection,corridorPenalty_aut G hab P hP,Set.mem_preimage, + internalEdges_aut_preimage G hab,←Set.preimage_inter,conn_aut_iff G hab] + +theorem deformedKernel_aut [Countable V] [Countable E] + (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : + deformedKernel G P p k t D (a x) (a y) = deformedKernel G P p k t (a ⁻¹' D) x y := by + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable + (measurable_deformedConnection G P p k t (a ⁻¹' D) x y).aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [deformedKernel,deformedConnection_aut G hab P hP] using h.symm + +theorem deformedSusceptibility_aut [Countable V] [Countable E] + (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : + deformedSusceptibility G P p k t D (a x) = deformedSusceptibility G P p k t (a ⁻¹' D) x := by + unfold deformedSusceptibility + rw [←a.tsum_eq (deformedKernel G P p k t D (a x))] + exact tsum_congr (fun y => deformedKernel_aut G hab P hP p k t D x y) + + + +noncomputable def corridorDerivativeContribution (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : ℝ := + ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * + deformedConnection G P p k t Set.univ ω x y ∂law p + +theorem corridorDerivativeContribution_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : + 0 ≤ corridorDerivativeContribution G P p t w x y := + integral_corridorDerivativeTerm_nonneg G P hP p k t w x y + +theorem corridorDerivativeContribution_aut [Countable V] [Countable E] + (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (x y : V) : + corridorDerivativeContribution G P p t (RawCorridor.autEquiv hab w) (a x) (a y) = + corridorDerivativeContribution G P p t w x y := by + have hm := ((measurable_corridorPenaltyTerm G P p (a ⁻¹' Set.univ) x y w).mul + (measurable_deformedConnection G P p k t (a ⁻¹' Set.univ) x y)) + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + have hc (ω : Set E) := corridorPenaltyTerm_aut G hab P hP p w Set.univ ω x y + have hd (ω : Set E) := deformedConnection_aut G hab P hP p k t Set.univ ω x y + simp only [Set.preimage_univ] at hc hd + simpa only [Pi.mul_apply,corridorDerivativeContribution,Set.preimage_univ,hc,hd] using h.symm + +end DeformationCovariance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DerivativeTonelli +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem derivative_field_summable (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + Summable (fun yw : V × RawCorridor G k => corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * + deformedConnection G P p k t Set.univ ω x yw.1) := by + have hs (y : V) : Summable (fun w : RawCorridor G k => + corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y) := + (corridorPenalty_summable G hloc P p k Set.univ ω x y).mul_right + (deformedConnection G P p k t Set.univ ω x y) + have hr : Summable (fun y => corridorPenalty G P p k Set.univ ω x y * + deformedConnection G P p k t Set.univ ω x y) := by + apply summable_of_hasFiniteSupport + apply hf.subset + intro y hy + by_contra hn + apply hy + change corridorPenalty G P p k Set.univ ω x y * deformedConnection G P p k t Set.univ ω x y = 0 + rw [deformedConnection_eq_zero_of_not_conn G P p k t Set.univ ω x y hn,mul_zero] + have hn : 0 ≤ (fun yw : V × RawCorridor G k => + corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * deformedConnection G P p k t Set.univ ω x yw.1) := + fun yw => mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x yw.1 yw.2) + (deformedConnection_nonneg G P p k t Set.univ ω x yw.1) + apply (summable_prod_of_nonneg hn).mpr + refine ⟨hs,?_⟩ + simpa only [tsum_mul_right,corridorPenalty] using hr + +theorem derivative_field_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + (∑' yw : V × RawCorridor G k, corridorPenaltyTerm G P p Set.univ ω x yw.1 yw.2 * + deformedConnection G P p k t Set.univ ω x yw.1) = + deformedDerivativeMass G P p k t Set.univ ω x := by + rw [(derivative_field_summable G hloc P hP p k t ω x hf).tsum_prod] + simp only [tsum_mul_right,corridorPenalty,deformedDerivativeMass] + + + +theorem derivative_contribution_sum [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x : V) : + Summable (fun yw : V × RawCorridor G k => corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1) ∧ + (∑' yw : V × RawCorridor G k, corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1) = + ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x ∂law p := by + let F := fun yw : V × RawCorridor G k => fun ω => + corridorPenaltyTerm G (walkKernel G hloc a) p Set.univ ω x yw.1 yw.2 * + deformedConnection G (walkKernel G hloc a) p k t Set.univ ω x yw.1 + have hs : ∀ᵐ ω ∂law p, Summable (fun yw => F yw ω) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact derivative_field_summable G hloc _ hP p k t ω x hω + have he : (fun ω => ∑' yw, F yw ω) =ᵐ[law p] + fun ω => deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x := by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact derivative_field_sum G hloc _ hP p k t ω x hω + have hh := real_tonelli_of_integrable_sum (law p) F + (fun yw => integrable_corridorDerivativeTerm G _ hP p k t ht Set.univ x yw.1 yw.2) + (fun yw ω => mul_nonneg (corridorPenaltyTerm_nonneg G _ hP p Set.univ ω x yw.1 yw.2) + (deformedConnection_nonneg G _ p k t Set.univ ω x yw.1)) hs + ((integrable_deformedDerivativeMass G hloc hqt d hd a hP p hp0 hp k t ht Set.univ x).congr he.symm) + exact ⟨hh.1,hh.2.trans (integral_congr_ae he)⟩ + +end DerivativeTonelli +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DerivativeTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem raw_from_sum_eq_masked (G : BondGraph V E) (hloc : LocallyFinite G) + (k : ℕ) (u : V) (f : RawCorridor G k → ℝ) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, f ⟨u,w⟩) = + ∑' w : RawCorridor G k, if w.base = u then f w else 0 := by + have hs := summable_raw_selection G hloc k {u} (Set.finite_singleton u) + (fun w : RawCorridor G k => w.base = u) (fun _ h => h) f + rw [hs.tsum_sigma] + have he (x : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, + if (RawCorridor.base ⟨x,w⟩) = u then f ⟨x,w⟩ else 0) = + if x = u then (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, f ⟨u,w⟩) else 0 := by + by_cases hx : x = u + · subst x; simp only [RawCorridor.base,ite_true] + · simp only [RawCorridor.base,hx,ite_false,tsum_zero] + simp only [he,tsum_ite_eq] + +noncomputable def derivativeTransportMass (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : ℝ := + ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, + ∑' y, corridorDerivativeContribution G P p t ⟨u,w⟩ x y + +theorem derivativeTransportMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : + 0 ≤ derivativeTransportMass G P p k t x u := + tsum_nonneg (fun w => tsum_nonneg (fun y => corridorDerivativeContribution_nonneg G P hP p t ⟨u,w⟩ x y)) + +theorem derivativeTransportMass_aut [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) + (p : unitInterval) (k : ℕ) (t : ℝ) (x u : V) : + derivativeTransportMass G P p k t (a x) (a u) = derivativeTransportMass G P p k t x u := by + unfold derivativeTransportMass + rw [raw_from_sum_eq_masked G hloc k (a u) (fun w => ∑' y, corridorDerivativeContribution G P p t w (a x) y), + raw_from_sum_eq_masked G hloc k u (fun w => ∑' y, corridorDerivativeContribution G P p t w x y)] + rw [←(RawCorridor.autEquiv hab).tsum_eq] + apply tsum_congr + intro w + simp only [RawCorridor.aut_base,a.injective.eq_iff] + by_cases hw : w.base = u + · simp only [hw,ite_true] + rw [←a.tsum_eq] + exact tsum_congr (fun y => corridorDerivativeContribution_aut G hab P hP p t w x y) + · simp only [hw,ite_false] + +end DerivativeTransport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DerivativeTransportSums +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +theorem summable_swapped_real {α β : Type*} (f : α → β → ℝ) + (hs : Summable (fun ab : α × β => f ab.1 ab.2)) : + Summable (fun ba : β × α => f ba.2 ba.1) := by + exact hs.comp_injective (Equiv.prodComm β α).injective + +theorem derivativeTransportMass_row (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x : V) : + Summable (derivativeTransportMass G (walkKernel G hloc a) p k t x) ∧ + (∑' u, derivativeTransportMass G (walkKernel G hloc a) p k t x u) = + ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω x ∂law p := by + obtain ⟨hs,he⟩ := derivative_contribution_sum G hloc hqt d hd a hP p hp0 hp k t ht x + have hs' : Summable (fun wy : RawCorridor G k × V => + corridorDerivativeContribution G (walkKernel G hloc a) p t wy.1 x wy.2) := by + exact summable_swapped_real (fun y w => corridorDerivativeContribution G (walkKernel G hloc a) p t w x y) hs + have hr := hs'.prod.sigma + refine ⟨hr,?_⟩ + change (∑' u, ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, ∑' y, + corridorDerivativeContribution G (walkKernel G hloc a) p t ⟨u,w⟩ x y) = _ + rw [←hs'.prod.tsum_sigma,←hs'.tsum_prod] + exact ((Equiv.prodComm (RawCorridor G k) V).tsum_eq + (fun yw : V × RawCorridor G k => corridorDerivativeContribution G (walkKernel G hloc a) p t yw.2 x yw.1)).trans he + +theorem derivativeTransportMass_column (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (u : V) : + Summable (fun x => derivativeTransportMass G P p k t x u) ∧ + (∑' x, derivativeTransportMass G P p k t x u) = + ∑' w : RawFrom (openSimpleGraph G Set.univ) k u, + ∑' xy : V × V, corridorDerivativeContribution G P p t ⟨u,w⟩ xy.1 xy.2 := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k u) + have hs (w : RawFrom (openSimpleGraph G Set.univ) k u) : + Summable (fun xy : V × V => corridorDerivativeContribution G P p t ⟨u,w⟩ xy.1 xy.2) := + summable_corridorDerivativeTerm_pairs G hG hloc hqt P hP p hp0 hp t ht ⟨u,w⟩ + have hh : Summable (fun x => ∑ w : RawFrom (openSimpleGraph G Set.univ) k u, + ∑' y, corridorDerivativeContribution G P p t ⟨u,w⟩ x y) := + summable_sum (fun w _ => (hs w).prod) + refine ⟨by simpa only [derivativeTransportMass,tsum_fintype] using hh,?_⟩ + simp only [derivativeTransportMass,tsum_fintype] + rw [Summable.tsum_finsetSum (fun w _ => (hs w).prod)] + exact Finset.sum_congr rfl (fun w _ => (hs w).tsum_prod.symm) + +end DerivativeTransportSums +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AveragedDerivative +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] + + + +theorem averaged_derivative_transport (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) : + (∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p) = + ∑ i, weight i * ∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), + ∑' xy : V × V, corridorDerivativeContribution G (walkKernel G hloc a) p t ⟨root i,w⟩ xy.1 xy.2 := by + have hh := htr.real root weight Γ (derivativeTransportMass G (walkKernel G hloc a) p k t) + (fun g hg x u => by + obtain ⟨b,hb⟩ := hΓ hg + exact derivativeTransportMass_aut G hloc hb _ (walkKernel_covariant G hloc a hb) p k t x u) + (fun x => (derivativeTransportMass_row G hloc hqt d hd a hP p hp0 hp k t ht x).1) + (fun u => (derivativeTransportMass_column G hG hloc hqt _ hP p hp0 hp k t ht u).1) + simpa only [(derivativeTransportMass_row G hloc hqt d hd a hP p hp0 hp k t ht _).2, + (derivativeTransportMass_column G hG hloc hqt _ hP p hp0 hp k t ht _).2] using hh + +noncomputable def averagedDeformedSusceptibility (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := + ∑ i, weight i * deformedSusceptibility G P p k t Set.univ (root i) + +theorem hasDerivAt_averagedDeformedSusceptibility (G : BondGraph V E) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (root : ι → V) (weight : ι → ℝ) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 < t) : + HasDerivAt (averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight) + (-(∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p)) t := by + have he : -(∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p) = + ∑ i, weight i * (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p)) := by + simp only [mul_neg,Finset.sum_neg_distrib] + rw [he] + exact HasDerivAt.fun_sum (u := Finset.univ) (fun i _ => + (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht Set.univ (root i)).const_mul (weight i)) + +end AveragedDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PathAverage +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + +noncomputable def rawPathAverage (G : BondGraph V E) (P : V → V → ℝ) (k : ℕ) + (root : ι → V) (weight : ι → ℝ) (f : RawCorridor G k → ℝ) : ℝ := + ∑ i, weight i * ∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), + w.2.mass P * f ⟨root i,w⟩ + +theorem rawPathAverage_mono (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (k : ℕ) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (f g : RawCorridor G k → ℝ) (hfg : ∀ w, f w ≤ g w) : + rawPathAverage G P k root weight f ≤ rawPathAverage G P k root weight g := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + unfold rawPathAverage + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_of_nonneg_left _ (hw i) + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) + simp only [tsum_fintype] + exact Finset.sum_le_sum (fun w _ => mul_le_mul_of_nonneg_left (hfg _) (w.2.mass_nonneg P hP)) + +theorem rawPathAverage_sub (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (k : ℕ) (root : ι → V) (weight : ι → ℝ) + (f g : RawCorridor G k → ℝ) : + rawPathAverage G P k root weight (fun w => f w-g w) = + rawPathAverage G P k root weight f - rawPathAverage G P k root weight g := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + have he (i : ι) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), + w.2.mass P * (f ⟨root i,w⟩-g ⟨root i,w⟩)) = + (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), w.2.mass P*f ⟨root i,w⟩) - + (∑' w : RawFrom (openSimpleGraph G Set.univ) k (root i), w.2.mass P*g ⟨root i,w⟩) := by + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) + simp only [tsum_fintype,mul_sub,Finset.sum_sub_distrib] + simp only [rawPathAverage] + simp only [he] + simp only [mul_sub,Finset.sum_sub_distrib] + +theorem rawPathAverage_const_mul (G : BondGraph V E) (P : V → V → ℝ) (k : ℕ) + (root : ι → V) (weight : ι → ℝ) (c : ℝ) (f : RawCorridor G k → ℝ) : + rawPathAverage G P k root weight (fun w => c*f w) = c*rawPathAverage G P k root weight f := by + unfold rawPathAverage + simp only [←mul_left_comm c,tsum_mul_left,Finset.mul_sum] + +noncomputable def retainedSusceptibilityProduct (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) {k : ℕ} (t : ℝ) (w : RawCorridor G k) : ℝ := + if 3 ≤ w.path.length then + deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.base * + deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.endpoint + else 0 + +end PathAverage +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AveragedCalibratedDecrease +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] + +theorem raw_derivative_template_row_lower (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) + (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (k : ℕ) (w : RawCorridor G k) + (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) : + Real.exp (-t*c) * (w.probability P * + (retainedSusceptibilityProduct G P p t w - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2*(matrixCoeff (T^3) w.base w.endpoint).re)) ≤ + ∑' xy : V × V, corridorDerivativeContribution G P p t w xy.1 xy.2 := by + by_cases hlen : 3 ≤ w.path.length + · have hh := calibrated_derivative_template_row_lower G hG hloc hqt d + (fun x => (neighbors_card_le_degree G hloc x).trans (hd x)) P hP hpcrit p hp hpnear T hT k w hlen c hc t ht + simpa only [retainedSusceptibilityProduct,hlen,ite_true,corridorDerivativeContribution, + mul_assoc,mul_left_comm (Real.exp (-t*c))] using hh + · have hC : 0 ≤ 1+2*(d:ℝ)/(pc G:ℝ) := by positivity + have hA := (((hT.positiveRealMatrix G p T).pow 3) w.base w.endpoint).2 + have hpr := w.2.2.mass_nonneg P hP + have hr : 0 ≤ ∑' xy : V × V, corridorDerivativeContribution G P p t w xy.1 xy.2 := + tsum_nonneg (fun xy => corridorDerivativeContribution_nonneg G P hP p t w xy.1 xy.2) + apply le_trans _ hr + simp only [retainedSusceptibilityProduct,hlen,ite_false,zero_sub,mul_neg] + exact neg_nonpos.mpr (mul_nonneg (Real.exp_pos _).le (mul_nonneg hpr + (mul_nonneg (mul_nonneg hC (sq_nonneg _)) hA))) + + +theorem averaged_derivative_raw_lower (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (hpcrit : 0 < (pc G:ℝ)) + (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (k : ℕ) (c : ℝ) (hc : ∀ w : RawCorridor G k, + (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight (walkKernel G hloc a) p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) : + Real.exp (-t*c) * + (rawPathAverage G (walkKernel G hloc a) k root weight (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * + rawPathAverage G (walkKernel G hloc a) k root weight (fun w => (matrixCoeff (T^3) w.base w.endpoint).re)) ≤ + ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p := by + rw [averaged_derivative_transport G hG hloc hqt root weight Γ hΓ htr d hd a hP p + ((half_pos hpcrit).trans_le hpnear) hp k t ht] + rw [←rawPathAverage_const_mul G _ k root weight _ (fun w => (matrixCoeff (T^3) w.base w.endpoint).re), + ←rawPathAverage_sub G hloc] + unfold rawPathAverage + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [mul_left_comm] + apply mul_le_mul_of_nonneg_left _ (hw i) + rw [←tsum_mul_left] + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k (root i)) + simp only [tsum_fintype] + exact Finset.sum_le_sum (fun w _ => raw_derivative_template_row_lower G hG hloc hqt d hd _ hP + hpcrit p hp hpnear T hT k ⟨root i,w⟩ c (hc _) t ht) + +end AveragedCalibratedDecrease +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PathErrorTrace +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + +theorem rawPathAverage_operator_trace (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (A : Hilbert V →L[ℂ] Hilbert V) (hAs : IsSelfAdjoint A) + (k : ℕ) (root : ι → V) (weight : ι → ℝ) : + rawPathAverage G (walkKernel G hloc a) k root weight + (fun w => (matrixCoeff A w.base w.endpoint).re) = (rootTrace root weight (P^k*A)).re := by + have he (u : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k u, + w.2.mass (walkKernel G hloc a) * (matrixCoeff A u w.1).re) = (matrixCoeff (P^k*A) u u).re := by + change RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k u + (fun v => (matrixCoeff A u v).re) = _ + rw [raw_integral_operator G hloc a P hpos hP] + simp only [matrixCoeff_real_symm A hAs u] + exact ((hpos.pow k).mul_hasSum A u u).tsum_eq + simp only [rawPathAverage,RawCorridor.base,RawCorridor.endpoint,he,rootTrace, + Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] + +open scoped ComplexOrder +attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass +local instance averagedDecreasePathNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +local instance averagedDecreasePathContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) + + + +theorem rawPathAverage_operator_le_norm (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (Γ : Set (V ≃ V)) (htr : RootTransport root weight Γ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hPi : KernelInvariant Γ P) (hPs : IsSelfAdjoint P) + (A : Hilbert V →L[ℂ] Hilbert V) (hAi : KernelInvariant Γ A) (hA : 0 ≤ A) (k : ℕ) : + rawPathAverage G (walkKernel G hloc a) k root weight + (fun w => (matrixCoeff A w.base w.endpoint).re) ≤ + ‖P‖^k * (rootTrace root weight A).re := by + rw [rawPathAverage_operator_trace G hloc a P hpos hP A (IsSelfAdjoint.of_nonneg hA)] + have hh := rootTrace_positive_mul_le root weight htr hw A (P^k) hAi (hPi.pow k) hA (hPs.pow k) + have hr := (Complex.le_def.mp hh).1 + simp only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] at hr + have hn : ‖P^k‖ ≤ ‖P‖^k := by + cases k with + | zero => + simp only [pow_zero] + have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext f; rfl + rw [he] + exact ContinuousLinearMap.norm_id_le + | succ j => exact norm_pow_le' P (Nat.succ_pos j) + exact hr.trans (mul_le_mul_of_nonneg_right hn + (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw A hA)).1) + +end PathErrorTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ComplexOrder +section UniformAveragedDecrease +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] +attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass +local instance averagedDecreaseUniformNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +local instance averagedDecreaseUniformContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) + + + +theorem exists_uniform_averaged_decrease (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hPs : IsSelfAdjoint P) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → ∀ (k : ℕ), 3 ≤ k → + ∀ (t : ℝ), 0 ≤ t → + Real.exp (-t*Real.exp (C*(k:ℝ))) * + (rawPathAverage G (walkKernel G hloc a) k root weight + (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * + (‖P‖^k * (rootTrace root weight (T^3)).re)) ≤ + ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p := by + obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_leg_cost G hG hloc d hd a hK hpcrit hpcrit₁ + refine ⟨C,hC,?_⟩ + intro p hpnear hp T hT k hk t ht + have hpositive : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) + have hTi : KernelInvariant Γ T := fun g hg => hT.invariant G p T g (hΓ hg) + have hPi : KernelInvariant Γ P := by + intro g hg x y + obtain ⟨b,hb⟩ := hΓ hg + simp only [hP,walkKernel_covariant G hloc a hb] + have herr := rawPathAverage_operator_le_norm G hloc a root weight hw Γ htr P hpos hP hPi hPs + (T^3) (hTi.pow 3) (CStarAlgebra.pow_nonneg T 3 hpositive) k + have hCnonneg : 0 ≤ (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 := by positivity + apply le_trans _ (averaged_derivative_raw_lower G hG hloc hqt root weight hw Γ hΓ htr + d hd a hK hpcrit p hp hpnear T hT k (Real.exp (C*(k:ℝ))) (hcost p hpnear hp k hk) t ht) + exact mul_le_mul_of_nonneg_left (sub_le_sub_left (mul_le_mul_of_nonneg_left herr hCnonneg) _) + (Real.exp_pos _).le + +end UniformAveragedDecrease +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeformedRowComparison +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] + + + +theorem exists_uniform_deformed_row_comparison (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : + ∃ C cf : ℝ, 0 < C ∧ 0 < cf ∧ ∀ (p : unitInterval), + (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → ∀ (k : ℕ), 3 ≤ k → ∀ (t : ℝ), + 0 ≤ t → t*Real.exp (C*(k:ℝ)) ≤ 1 → ∀ x, + cf*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x := by + obtain ⟨C,hC,hmove⟩ := exists_uniform_deformed_endpoint_comparison G hloc hqt d hd a hP hpcrit hpcrit₁ + have hex (ij : ι × ι) : ∃ l : List E, Along G (root ij.1) l (root ij.2) := by + obtain ⟨l,hl,_,_⟩ := conn_exists_bond_trail G (conn_univ_of_connected G hconn (root ij.1) (root ij.2)) + exact ⟨l,hl⟩ + choose path hpath using hex + let N := ∑ ij : ι × ι, (path ij).length + have hlen (i j : ι) : (path (i,j)).length ≤ N := + Finset.single_le_sum (f := fun ij : ι × ι => (path ij).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ (i,j)) + refine ⟨C,Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N,hC,mul_pos (Real.exp_pos _) (pow_pos (half_pos hpcrit) N),?_⟩ + intro p hpnear hp k hk t ht htc x + obtain ⟨j,g,b,hgb,hgx⟩ := hcover x + have hb (i : ι) : (Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N)* + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root i) ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root j) := by + have hh := hmove p hpnear hp k hk t ht Set.univ (root j) (root i) (path (j,i)) + (Set.mem_univ _) (hpath (j,i)) (fun _ _ _ _ => Set.mem_univ _) + have hpow : ((pc G:ℝ)/2)^N ≤ (p:ℝ)^(path (j,i)).length := + (pow_le_pow_left₀ (half_pos hpcrit).le hpnear N).trans + (pow_le_pow_of_le_one p.2.1 p.2.2 (hlen j i)) + have he : Real.exp (-(N:ℝ)) ≤ Real.exp (-t*((path (j,i)).length*Real.exp (C*(k:ℝ)))) := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right htc (Nat.cast_nonneg (path (j,i)).length : (0:ℝ) ≤ _) + have hn : ((path (j,i)).length:ℝ) ≤ (N:ℝ) := Nat.cast_le.mpr (hlen j i) + nlinarith + exact (mul_le_mul_of_nonneg_right (mul_le_mul he hpow (pow_nonneg (half_pos hpcrit).le _) (Real.exp_pos _).le) + (deformedSusceptibility_nonneg G _ p k t Set.univ (root i))).trans hh + rw [←hgx,deformedSusceptibility_aut G hgb _ (walkKernel_covariant G hloc a hgb)] + simp only [Set.preimage_univ] + calc + _ = ∑ i, weight i*((Real.exp (-(N:ℝ))*((pc G:ℝ)/2)^N)* + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root i)) := by + simp only [averagedDeformedSusceptibility,Finset.mul_sum] + exact Finset.sum_congr rfl (fun _ _ => by ring) + _ ≤ ∑ i, weight i*deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root j) := + Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hb i) (hw i)) + _ = _ := by rw [←Finset.sum_mul,hw1,one_mul] + +end DeformedRowComparison +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AnchoredSegments +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + +def segmentOrbit (G : BondGraph V E) (γ : I → V) : Set (I → V) := + {s | ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ s = a ∘ γ} + +omit [Fintype I] in +theorem segmentOrbit_aut_iff (G : BondGraph V E) (γ s : I → V) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : + a ∘ s ∈ segmentOrbit G γ ↔ s ∈ segmentOrbit G γ := by + constructor + · rintro ⟨c,d,hcd,he⟩ + refine ⟨c.trans a.symm,d.trans b.symm,isAut_trans G hcd (isAut_symm G h),?_⟩ + funext i + have hh := congrFun he i + simpa only [Function.comp_apply,Equiv.trans_apply,Equiv.symm_apply_apply] using congrArg a.symm hh + · rintro ⟨c,d,hcd,rfl⟩ + exact ⟨c.trans a,d.trans b,isAut_trans G hcd h,rfl⟩ + +theorem finite_segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : + {s ∈ segmentOrbit G γ | s i = x}.Finite := by + apply (Set.Finite.pi' (fun _ : I => finite_reachBall hloc x n)).subset + rintro s ⟨⟨a,b,hab,rfl⟩,hx⟩ j + have hh := mem_reachBall_aut G hab (hdiam i j) + change a (γ i) = x at hx + simpa only [hx,Function.comp_apply] using hh + +noncomputable def segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : Finset (I → V) := + (finite_segmentAnchors G hloc γ n hdiam i x).toFinset + +theorem mem_segmentAnchors (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) (s : I → V) : + s ∈ segmentAnchors G hloc γ n hdiam i x ↔ s ∈ segmentOrbit G γ ∧ s i = x := by + exact Set.Finite.mem_toFinset _ + +theorem segmentAnchors_nonempty_iff (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : + (segmentAnchors G hloc γ n hdiam i x).Nonempty ↔ x ∈ vertexOrbit G (γ i) := by + constructor + · rintro ⟨s,hs⟩ + obtain ⟨⟨a,b,h,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs + exact ⟨a,b,h,hx⟩ + · rintro ⟨a,b,h,hx⟩ + exact ⟨a ∘ γ,(mem_segmentAnchors G hloc γ n hdiam i x _).mpr ⟨⟨a,b,h,rfl⟩,hx⟩⟩ + +end AnchoredSegments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AnchoredPositionKernels +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + +def segmentAut (a : V ≃ V) : (I → V) ≃ (I → V) where + toFun s := a ∘ s + invFun s := a.symm ∘ s + left_inv s := by funext i; exact a.symm_apply_apply (s i) + right_inv s := by funext i; exact a.apply_symm_apply (s i) + +theorem segmentAnchors_map (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : + segmentAnchors G hloc γ n hdiam i (a x) = + (segmentAnchors G hloc γ n hdiam i x).map (segmentAut a).toEmbedding := by + ext s + rw [Finset.mem_map,mem_segmentAnchors] + constructor + · rintro ⟨hs,hx⟩ + refine ⟨a.symm ∘ s,(mem_segmentAnchors G hloc γ n hdiam i x _).mpr ⟨?_,?_⟩,?_⟩ + · exact (segmentOrbit_aut_iff G γ s (isAut_symm G h)).mpr hs + · simp only [Function.comp_apply,hx,Equiv.symm_apply_apply] + · funext j; exact a.apply_symm_apply (s j) + · rintro ⟨t,ht,rfl⟩ + obtain ⟨ht,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x t).mp ht + exact ⟨(segmentOrbit_aut_iff G γ t h).mpr ht,congrArg a hx⟩ + +theorem segmentAnchors_card_aut (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : + (segmentAnchors G hloc γ n hdiam i (a x)).card = (segmentAnchors G hloc γ n hdiam i x).card := by + rw [segmentAnchors_map G hloc γ n hdiam i x h,Finset.card_map] + + + +noncomputable def anchoredPositionKernel (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : ℝ := + ∑ s ∈ segmentAnchors G hloc γ n hdiam i x, + if y = s j then ((segmentAnchors G hloc γ n hdiam i x).card : ℝ)⁻¹ else 0 + +theorem anchoredPositionKernel_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : + 0 ≤ anchoredPositionKernel G hloc γ n hdiam i j x y := by + apply Finset.sum_nonneg + intro s _ + split_ifs <;> positivity + +theorem anchoredPositionKernel_aut (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) : + anchoredPositionKernel G hloc γ n hdiam i j (a x) (a y) = + anchoredPositionKernel G hloc γ n hdiam i j x y := by + simp only [anchoredPositionKernel,segmentAnchors_map G hloc γ n hdiam i x h, + Finset.card_map,Finset.sum_map,Equiv.toEmbedding_apply, + segmentAut,Equiv.coe_fn_mk,Function.comp_apply,Equiv.apply_eq_iff_eq] + +end AnchoredPositionKernels +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AnchoredPositionRows +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + +theorem anchoredPositionKernel_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x : V) : + HasSum (anchoredPositionKernel G hloc γ n hdiam i j x) + (if x ∈ vertexOrbit G (γ i) then (1:ℝ) else 0) := by + have hh := hasSum_sum (s := segmentAnchors G hloc γ n hdiam i x) + (fun s _ => hasSum_ite_eq (s j) (((segmentAnchors G hloc γ n hdiam i x).card:ℝ)⁻¹)) + have he : (∑ s ∈ segmentAnchors G hloc γ n hdiam i x, + ((segmentAnchors G hloc γ n hdiam i x).card:ℝ)⁻¹) = + if x ∈ vertexOrbit G (γ i) then (1:ℝ) else 0 := by + simp only [Finset.sum_const,nsmul_eq_mul] + by_cases hx : x ∈ vertexOrbit G (γ i) + · have hn := Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i x).mpr hx) + rw [ite_eq_left hx,mul_inv_cancel₀ (Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn))] + · have he : segmentAnchors G hloc γ n hdiam i x = ∅ := Finset.not_nonempty_iff_eq_empty.mp + (fun h => hx ((segmentAnchors_nonempty_iff G hloc γ n hdiam i x).mp h)) + simp only [he,Finset.card_empty,Nat.cast_zero,zero_mul,ite_eq_right hx] + rw [he] at hh + exact hh + +theorem anchoredPositionKernel_eq_zero_off_ball (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) + (hxy : y ∉ reachBall G x n) : anchoredPositionKernel G hloc γ n hdiam i j x y = 0 := by + apply Finset.sum_eq_zero + intro s hs + apply ite_eq_right + intro hy + obtain ⟨⟨a,b,hab,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs + change a (γ i) = x at hx + change y = a (γ j) at hy + exact hxy (by simpa only [hx,←hy] using mem_reachBall_aut G hab (hdiam i j)) + +theorem anchoredPositionKernel_eq_zero_off_orbits (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (x y : V) : + x ∉ vertexOrbit G (γ i) ∨ y ∉ vertexOrbit G (γ j) → + anchoredPositionKernel G hloc γ n hdiam i j x y = 0 := by + intro h + apply Finset.sum_eq_zero + intro s hs + apply ite_eq_right + intro hy + obtain ⟨⟨a,b,hab,rfl⟩,hx⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs + rcases h with h | h + · exact h ⟨a,b,hab,hx⟩ + · exact h ⟨a,b,hab,hy.symm⟩ + +end AnchoredPositionRows +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AnchoredPositionColumns +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + +theorem anchoredPositionKernel_columnSummable (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (y : V) : + Summable (fun x => anchoredPositionKernel G hloc γ n hdiam i j x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) + intro x hx + simp only [Set.Finite.mem_toFinset] at hx + apply Finset.sum_eq_zero + intro s hs + apply ite_eq_right + intro hy + obtain ⟨⟨a,b,hab,rfl⟩,he⟩ := (mem_segmentAnchors G hloc γ n hdiam i x s).mp hs + change a (γ i) = x at he + change y = a (γ j) at hy + exact hx (by simpa only [he,←hy] using mem_reachBall_aut G hab (hdiam j i)) + +theorem anchoredPositionKernel_column_orbit (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) (y : V) : + (∑' x, anchoredPositionKernel G hloc γ n hdiam i j x y) = + if y ∈ vertexOrbit G (γ j) then + ∑' x, anchoredPositionKernel G hloc γ n hdiam i j x (γ j) else 0 := by + by_cases hy : y ∈ vertexOrbit G (γ j) + · rw [ite_eq_left hy] + obtain ⟨a,b,hab,rfl⟩ := hy + rw [←a.tsum_eq] + exact tsum_congr (fun x => anchoredPositionKernel_aut G hloc γ n hdiam i j x (γ j) hab) + · rw [ite_eq_right hy] + calc + _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun x => + anchoredPositionKernel_eq_zero_off_orbits G hloc γ n hdiam i j x y (Or.inr hy)) + _ = 0 := tsum_zero + + + +theorem anchoredPositionKernel_column_mass {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) : + (∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) = + (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) * + ∑' x, anchoredPositionKernel G hloc γ n hdiam i j x (γ j) := by + have ht := htr.real root weight Γ (anchoredPositionKernel G hloc γ n hdiam i j) + (fun a ha x y => by + obtain ⟨b,hb⟩ := hΓ ha + exact anchoredPositionKernel_aut G hloc γ n hdiam i j x y hb) + (fun x => (anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable) + (anchoredPositionKernel_columnSummable G hloc γ n hdiam i j) + calc + _ = ∑ r, weight r * ∑' y, anchoredPositionKernel G hloc γ n hdiam i j (root r) y := by + apply Finset.sum_congr rfl + intro r _ + rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j (root r)).tsum_eq] + split_ifs <;> simp only [mul_one,mul_zero] + _ = _ := ht + _ = _ := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro r _ + rw [anchoredPositionKernel_column_orbit] + split_ifs <;> simp only [mul_zero,zero_mul] + +theorem anchoredPositionKernel_column_ratio {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) + (hj : 0 < ∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) (y : V) : + (∑' x, anchoredPositionKernel G hloc γ n hdiam i j x y) = + if y ∈ vertexOrbit G (γ j) then + (∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) / + (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) else 0 := by + have he := anchoredPositionKernel_column_mass G hloc root weight Γ hΓ htr γ n hdiam i j + rw [anchoredPositionKernel_column_orbit] + congr 1 + exact (eq_div_iff (ne_of_gt hj)).mpr (by simpa only [mul_comm] using he.symm) + +end AnchoredPositionColumns +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +section AsymmetricSchur +open scoped ENNReal +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_operator_of_unit_row_column_bound (U : V → V → ℝ) (D : ℝ) + (hD : 0 ≤ D) (hU : ∀ x y, 0 ≤ U x y) + (hrow : ∀ x (s : Finset V), ∑ y ∈ s, U x y ≤ 1) + (hcol : ∀ y (s : Finset V), ∑ x ∈ s, U x y ≤ D) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ Real.sqrt D ∧ + ∀ x y, matrixCoeff A x y = (U x y : ℂ) := by + have hentry (x y : V) : U x y ≤ 1 := by simpa only [Finset.sum_singleton] using hrow x {y} + have hcm (y : V) : Memℓp (fun x => (U x y : ℂ)) 2 := by + apply (memℓp_gen_iff'' (by norm_num : 0 < (2 : ℝ≥0∞).toReal)).mpr + refine ⟨D,hD,fun s => ?_⟩ + simp only [ENNReal.toReal_ofNat,Real.rpow_two,Complex.norm_real,Real.norm_eq_abs,sq_abs] + exact (Finset.sum_le_sum (fun x _ => by nlinarith [hentry x y,hU x y])).trans (hcol y s) + let col (y : V) : Hilbert V := ⟨fun x => (U x y : ℂ),hcm y⟩ + let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col + have hn (f : V →₀ ℂ) : ‖L f‖ ≤ Real.sqrt D * ‖finiteEmbedding f‖ := by + apply lp.norm_le_of_forall_sum_le (by norm_num) + (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _)) + intro s + simp only [ENNReal.toReal_ofNat,Real.rpow_two] + have hpoint (x : V) : ‖L f x‖^2 ≤ ∑ y ∈ f.support, ‖f y‖^2 * U x y := by + have hn0 : 0 ≤ ∑ y ∈ f.support, ‖f y‖*U x y := + Finset.sum_nonneg (fun y _ => mul_nonneg (norm_nonneg _) (hU x y)) + have hn1 : ‖L f x‖ ≤ ∑ y ∈ f.support, ‖f y‖*U x y := by + simp only [L,Finsupp.linearCombination_apply,Finsupp.sum,lp.coeFn_sum, + Finset.sum_apply,lp.coeFn_smul,Pi.smul_apply,smul_eq_mul] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + simp [col,abs_of_nonneg (hU x y)] + have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul f.support + (f := fun y => U x y) (g := fun y => ‖f y‖^2*U x y) + (r := fun y => ‖f y‖*U x y) + (fun y _ => hU x y) + (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) (fun y _ => by nlinarith) + have hn2 : 0 ≤ ∑ y ∈ f.support, ‖f y‖^2*U x y := + Finset.sum_nonneg (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) + have hr := mul_le_mul_of_nonneg_right (hrow x f.support) hn2 + rw [one_mul] at hr + exact (sq_le_sq₀ (norm_nonneg _) hn0 |>.mpr hn1).trans (hcs.trans hr) + calc + ∑ x ∈ s, ‖L f x‖^2 ≤ ∑ x ∈ s, ∑ y ∈ f.support, ‖f y‖^2*U x y := + Finset.sum_le_sum (fun x _ => hpoint x) + _ = ∑ y ∈ f.support, ‖f y‖^2*∑ x ∈ s, U x y := by + rw [Finset.sum_comm] + simp_rw [Finset.mul_sum] + _ ≤ ∑ y ∈ f.support, ‖f y‖^2*D := + Finset.sum_le_sum (fun y _ => mul_le_mul_of_nonneg_left (hcol y s) (sq_nonneg _)) + _ = D*∑ y ∈ f.support, ‖finiteEmbedding f y‖^2 := by + simp only [finiteEmbedding_apply] + rw [←Finset.sum_mul,mul_comm] + _ ≤ D*‖finiteEmbedding f‖^2 := by + apply mul_le_mul_of_nonneg_left _ hD + simpa only [ENNReal.toReal_ofNat,Real.rpow_two] using + lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2:ℝ≥0∞).toReal) (finiteEmbedding f) f.support + _ = (Real.sqrt D*‖finiteEmbedding f‖)^2 := by rw [mul_pow,Real.sq_sqrt hD] + refine ⟨L.extendOfNorm finiteEmbedding, + LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense (Real.sqrt_nonneg _) hn,?_⟩ + intro x y + have he := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨Real.sqrt D,hn⟩ + (Finsupp.single y (1:ℂ)) + simp only [finiteEmbedding_single] at he + change (L.extendOfNorm finiteEmbedding) (lp.single 2 y (1:ℂ)) x = _ + rw [he] + simp [L,col] + +end AsymmetricSchur +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AnchoredPositionOperators +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι : Type*} [Fintype I] [Fintype ι] + + + +theorem exists_anchoredPositionOperator (G : BondGraph V E) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) + (hj : 0 < ∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0) : + ∃ H : Hilbert V →L[ℂ] Hilbert V, + (∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam i j x y : ℂ)) ∧ + ‖H‖ ≤ Real.sqrt ((∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0) / + (∑ r, if root r ∈ vertexOrbit G (γ j) then weight r else 0)) := by + have hnum : 0 ≤ ∑ r, if root r ∈ vertexOrbit G (γ i) then weight r else 0 := + Finset.sum_nonneg (fun r _ => by split_ifs; exact hw r; exact le_refl 0) + have hratio := div_nonneg hnum hj.le + obtain ⟨H,hn,hH⟩ := exists_operator_of_unit_row_column_bound + (anchoredPositionKernel G hloc γ n hdiam i j) _ hratio + (anchoredPositionKernel_nonneg G hloc γ n hdiam i j) + (fun x s => ((anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable.sum_le_tsum s + (fun y _ => anchoredPositionKernel_nonneg G hloc γ n hdiam i j x y)).trans (by + rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).tsum_eq] + split_ifs <;> norm_num)) + (fun y s => ((anchoredPositionKernel_columnSummable G hloc γ n hdiam i j y).sum_le_tsum s + (fun x _ => anchoredPositionKernel_nonneg G hloc γ n hdiam i j x y)).trans (by + rw [anchoredPositionKernel_column_ratio G hloc root weight Γ hΓ htr γ n hdiam i j hj y] + split_ifs; exact le_refl _; exact hratio)) + exact ⟨H,hH,hn⟩ + + +theorem exists_anchoredPositionOperator_uniform (G : BondGraph V E) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ a ∈ Γ, a (root r) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i j : I) : + ∃ H : Hilbert V →L[ℂ] Hilbert V, + (∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam i j x y : ℂ)) ∧ + ‖H‖ ≤ Real.sqrt c := by + let U := anchoredPositionKernel G hloc γ n hdiam i j + have hn : ∀ x y, 0 ≤ U x y := anchoredPositionKernel_nonneg G hloc γ n hdiam i j + have hr : ∀ x, Summable (U x) := fun x => (anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).summable + have hcol := anchoredPositionKernel_columnSummable G hloc γ n hdiam i j + have hb (x : V) : (∑' y, U x y) ≤ 1 := by + rw [(anchoredPositionKernel_hasSum G hloc γ n hdiam i j x).tsum_eq] + split_ifs <;> norm_num + have hi : ∀ a ∈ Γ, ∀ x y, U (a x) (a y) = U x y := by + intro a ha x y + obtain ⟨b,hb⟩ := hΓ ha + exact anchoredPositionKernel_aut G hloc γ n hdiam i j x y hb + have hbcol (y : V) : (∑' x, U x y) ≤ c := by + simpa only [mul_one] using transported_column_le root weight Γ htr hcov hw hw1 c hc hmin U hn hi hr hcol 1 hb y + obtain ⟨H,hHn,hH⟩ := exists_operator_of_unit_row_column_bound U c hc hn + (fun x s => ((hr x).sum_le_tsum s (fun y _ => hn x y)).trans (hb x)) + (fun y s => ((hcol y).sum_le_tsum s (fun x _ => hn x y)).trans (hbcol y)) + exact ⟨H,hH,hHn⟩ + +end AnchoredPositionOperators +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +section RawReversal +namespace HoldingWalk +variable {H : SimpleGraph V} + + +def snocHold : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H (k+1) x y + | _,_,_,.nil x => .hold (.nil x) + | _,_,_,.hold w => .hold (snocHold w) + | _,_,_,.step h w => .step h (snocHold w) + + +def snocStep : {k : ℕ} → {x y z : V} → HoldingWalk H k x y → H.Adj y z → HoldingWalk H (k+1) x z + | _,_,_,z,.nil _,h => .step h (.nil z) + | _,_,_,_,.hold w,h => .hold (snocStep w h) + | _,_,_,_,.step h' w,h => .step h' (snocStep w h) + + + +def reverse : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H k y x + | _,_,_,.nil x => .nil x + | _,_,_,.hold w => snocHold (reverse w) + | _,_,_,.step h w => snocStep (reverse w) h.symm + +theorem reverse_snocHold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + w.snocHold.reverse = w.reverse.hold := by + induction w with + | nil => rfl + | hold w ih => simp only [snocHold,reverse,ih] + | step h w ih => simp only [snocHold,reverse,ih,snocStep] + +theorem reverse_snocStep {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : + (w.snocStep h).reverse = .step h.symm w.reverse := by + induction w with + | nil => rfl + | hold w ih => simp only [snocStep,reverse,ih,snocHold] + | step h' w ih => simp only [snocStep,reverse,ih] + +theorem reverse_reverse {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.reverse.reverse = w := by + induction w with + | nil => rfl + | hold w ih => simp only [reverse,reverse_snocHold,ih] + | step h w ih => simp only [reverse,reverse_snocStep,ih] + +def reverseEquiv (k : ℕ) (x y : V) : HoldingWalk H k x y ≃ HoldingWalk H k y x where + toFun := reverse + invFun := reverse + left_inv := reverse_reverse + right_inv := reverse_reverse + +theorem mass_snocHold (P : V → V → ℝ) {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + w.snocHold.mass P = w.mass P * P y y := by + induction w with + | nil => simp only [snocHold,mass,mul_one,one_mul] + | hold w ih => simp only [snocHold,mass,ih,mul_assoc] + | step h w ih => simp only [snocHold,mass,ih,mul_assoc] + +theorem mass_snocStep (P : V → V → ℝ) {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : + (w.snocStep h).mass P = w.mass P * P y z := by + induction w with + | nil => simp only [snocStep,mass,mul_one,one_mul] + | hold w ih => simp only [snocStep,mass,ih,mul_assoc] + | step h' w ih => simp only [snocStep,mass,ih,mul_assoc] + +theorem mass_reverse (P : V → V → ℝ) (hP : ∀ x y, P x y = P y x) + {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.reverse.mass P = w.mass P := by + induction w with + | nil => rfl + | hold w ih => simp only [reverse,mass_snocHold,mass,ih,mul_comm] + | step h w ih => simp only [reverse,mass_snocStep,mass,ih,hP,mul_comm] + +theorem vertices_snocHold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + w.snocHold.vertices = w.vertices ++ [y] := by + induction w with + | nil => rfl + | hold w ih => simp only [snocHold,vertices,ih,List.cons_append] + | step h w ih => simp only [snocHold,vertices,ih,List.cons_append] + +theorem vertices_snocStep {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) (h : H.Adj y z) : + (w.snocStep h).vertices = w.vertices ++ [z] := by + induction w with + | nil => rfl + | hold w ih => simp only [snocStep,vertices,ih,List.cons_append] + | step h' w ih => simp only [snocStep,vertices,ih,List.cons_append] + +theorem vertices_reverse {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + w.reverse.vertices = w.vertices.reverse := by + induction w with + | nil => rfl + | hold w ih => simp only [reverse,vertices_snocHold,vertices,ih,List.reverse_cons] + | step h w ih => simp only [reverse,vertices_snocStep,vertices,ih,List.reverse_cons] + +end HoldingWalk +end RawReversal +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/Calibration.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/Calibration.lean index 7b7983e0d30f3958b244ec88db58bdd86f7b03c7..791e378349d3f3b35d103a756138f070c6b71480 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/Calibration.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/Calibration.lean @@ -1,1247 +1,1247 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.Derivatives - -namespace OAI - -/-! Calibration for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformDeformedEndpoint -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_uniform_deformed_endpoint_comparison [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (k : ℕ), 3 ≤ k → ∀ (t : ℝ), 0 ≤ t → ∀ (D : Set V) (b z : V) (l : List E), - b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → - Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * - deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t D b := by - obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_edge_cost G hloc d hd a hP hpcrit hpcrit₁ - refine ⟨C,hC,?_⟩ - intro p hpnear hp k hk t ht D b z l hb hl hD - have hc : ∀ e, (∑' w : RawCorridor G k, - if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ Real.exp (C*(k:ℝ)) := by - intro e - exact (hcost p hpnear hp k hk e).trans (div_le_self (Real.exp_pos _).le (by exact_mod_cast (show 1 ≤ k by omega))) - have hh := deformedSusceptibility_move_lower G hloc hqt (walkKernel G hloc a) hP p hp k t ht D - l.toFinset (fun e he => hD e (List.mem_toFinset.mp he)) b z hb - (hl.conn (fun e he => List.mem_toFinset.mpr he)) (Real.exp (C*(k:ℝ))) hc - have hcard : (l.toFinset.card:ℝ) ≤ (l.length:ℝ) := Nat.cast_le.mpr l.toFinset_card_le - have he : Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) ≤ - Real.exp (-t*((l.toFinset.card:ℝ)*Real.exp (C*(k:ℝ)))) := by - apply Real.exp_le_exp.mpr - exact mul_le_mul_of_nonpos_left (mul_le_mul_of_nonneg_right hcard (Real.exp_pos _).le) (neg_nonpos.mpr ht) - have hpw : (p:ℝ)^l.length ≤ (p:ℝ)^l.toFinset.card := - pow_le_pow_of_le_one p.2.1 p.2.2 l.toFinset_card_le - exact (mul_le_mul_of_nonneg_right (mul_le_mul he hpw (pow_nonneg p.2.1 _) (Real.exp_pos _).le) - (tsum_nonneg (deformedKernel_nonneg G (walkKernel G hloc a) p k t D z))).trans hh - -end UniformDeformedEndpoint -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PivotalLegGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem pivotal_endpoint_connected (G : BondGraph V E) (S : Set E) (x y : V) - (hc : Conn G S x y) (e : E) (hp : ¬Conn G (S \ {e}) x y) (z : V) (hz : z ∈ G e) : - Conn G S x z := by - obtain ⟨q⟩ := (conn_iff_reachable G S x y).mp hc - have hzs : z ∈ q.support := SimpleGraph.Walk.mem_support_of_mem_edges - (pivotal_image_mem_edges G S q e hp) hz - exact (conn_iff_reachable G S x z).mpr ⟨q.takeUntil z hzs⟩ - -theorem conn_delete_of_unconnected_endpoint (G : BondGraph V E) (S : Set E) (x y z : V) - (hc : Conn G S x y) (e : E) (hz : z ∈ G e) (hn : ¬Conn G S x z) : - Conn G (S \ {e}) x y := by - by_contra hh - exact hn (pivotal_endpoint_connected G S x y hc e hh z hz) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem retained_conn_base (w : RawCorridor G k) (z : V) (hz : z ∈ w.path.support) : - Conn G w.retained w.base z := by - obtain ⟨l,hl,hm,_⟩ := walk_lift_bonds G Set.univ (w.path.takeUntil z hz) - apply hl.conn - intro e he - exact w.path.edges_takeUntil_subset_edges hz (hm ▸ List.mem_map_of_mem he) - -theorem retained_conn (w : RawCorridor G k) : Conn G w.retained w.base w.endpoint := - w.retained_conn_base w.endpoint w.path.end_mem_support - -theorem retained_connects_support (w : RawCorridor G k) (x y : V) - (hx : x ∈ w.path.support) (hy : y ∈ w.path.support) : Conn G w.retained x y := - conn_trans G _ (conn_symm G _ (w.retained_conn_base x hx)) (w.retained_conn_base y hy) - -theorem retained_nonempty (w : RawCorridor G k) (hl : 0 < w.path.length) : w.retained.Nonempty := by - have hp : w.path.edges ≠ [] := by - intro he - have hh := congrArg List.length he - simp only [SimpleGraph.Walk.length_edges,List.length_nil] at hh - omega - obtain ⟨s,hs⟩ := List.exists_mem_of_ne_nil _ hp - obtain ⟨e,he,_⟩ := w.edge_has_label s hs - exact ⟨e,he⟩ - -end RawCorridor -end PivotalLegGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OneLegGeometry -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem counted_one_leg (r : RawCorridor G k) (D : Set V) (ω B : Set E) - (x y u v : V) (hc : r.counted Set.univ ω x y) - (hr : r.retained ⊆ ω ∩ internalEdges G D) (hB : B ⊆ ω) - (hd : Disjoint B r.retained) (huv : Conn G B u v) - (hxu : Conn G (ω ∩ internalEdges G D) x u) - (hvy : Conn G (ω ∩ internalEdges G D) v y) - (hne : ¬Conn G (ω ∩ internalEdges G D) u v) - (e : E) (he : e ∈ r.retained) - (hep : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x u) : r.counted D ω x u := by - let S := ω ∩ internalEdges G D - have huniv : ω ∩ internalEdges G Set.univ = ω := by - apply Set.Subset.antisymm Set.inter_subset_left - exact fun _ he => ⟨he,fun _ _ => trivial⟩ - obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by - obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) - exact ⟨z,z',hh.symm⟩ - have hz : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' - have hxz : Conn G S x z := pivotal_endpoint_connected G S x u hxu e hep z hz - have hzsupport : z ∈ r.path.support := SimpleGraph.Walk.mem_support_of_mem_edges he hz - apply (r.counted_iff D ω x u).mpr - refine ⟨hc.1,hxu,?_,hc.2.2.2.2.mono_right ?_⟩ - · intro f hf - refine ⟨hr hf,?_⟩ - intro hxf - obtain ⟨a,b,hab⟩ : ∃ a b, G f = s(a,b) := by - obtain ⟨⟨a,b⟩,hh⟩ := Quot.exists_rep (G f) - exact ⟨a,b,hh.symm⟩ - have ha : a ∈ G f := hab.symm ▸ Sym2.mem_mk_left a b - have haz : Conn G S z a := conn_mono G hr (r.retained_connects_support z a hzsupport - (SimpleGraph.Walk.mem_support_of_mem_edges hf ha)) - have hua : Conn G S u a := conn_trans G S (conn_symm G S hxu) (conn_trans G S hxz haz) - have hvf : Conn G (S \ {f}) v y := conn_delete_of_unconnected_endpoint G S v y a hvy f ha - (fun hva => hne (conn_trans G S hua (conn_symm G S hva))) - have hBf : Conn G (ω \ {f}) u v := conn_mono G (show B ⊆ ω \ {f} from fun g hg => ⟨hB hg,fun hgf => - Set.disjoint_left.mp hd hg ((Set.mem_singleton_iff.mp hgf).symm ▸ hf)⟩) huv - apply (hc.2.2.2.1 f hf).2 - rw [huniv] - exact conn_trans G _ (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hxf) - (conn_trans G _ hBf (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hvf)) - · rw [huniv] - exact Set.inter_subset_left - -end RawCorridor -end OneLegGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TwoLegGeometry -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem counted_split_legs (r : RawCorridor G k) (D : Set V) (ω B : Set E) - (x y u v : V) (hc : r.counted Set.univ ω x y) - (hr : r.retained ⊆ ω ∩ internalEdges G D) (hB : B ⊆ ω) - (hd : Disjoint B r.retained) (huv : Conn G B u v) - (hxu : Conn G (ω ∩ internalEdges G D) x u) - (hvy : Conn G (ω ∩ internalEdges G D) v y) - (hne : ¬Conn G (ω ∩ internalEdges G D) u v) : - r.counted D ω x u ∨ r.counted D ω v y := by - obtain ⟨e,he⟩ := r.retained_nonempty (by have := hc.1; omega) - by_cases hp : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x u - · exact Or.inl (r.counted_one_leg D ω B x y u v hc hr hB hd huv hxu hvy hne e he hp) - · have hxu' : Conn G ((ω ∩ internalEdges G D) \ {e}) x u := not_not.mp hp - have hp' : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) y v := by - intro hyv - apply (hc.2.2.2.1 e he).2 - have huniv : ω ∩ internalEdges G Set.univ = ω := by - apply Set.Subset.antisymm Set.inter_subset_left - exact fun _ he => ⟨he,fun _ _ => trivial⟩ - rw [huniv] - have hB' : Conn G (ω \ {e}) u v := conn_mono G (show B ⊆ ω \ {e} from fun f hf => ⟨hB hf,fun hfe => - Set.disjoint_left.mp hd hf ((Set.mem_singleton_iff.mp hfe).symm ▸ he)⟩) huv - exact conn_trans G _ (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hxu') - (conn_trans G _ hB' (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) (conn_symm G _ hyv))) - exact Or.inr ((r.counted_symm D ω y v).mp (r.counted_one_leg D ω B y x v u - ((r.counted_symm Set.univ ω x y).mp hc) hr hB hd (conn_symm G B huv) - (conn_symm G _ hvy) (conn_symm G _ hxu) (fun h => hne (conn_symm G _ h)) e he hp')) - - -theorem counted_legs_of_disjoint (w r : RawCorridor G k) (ω : Set E) - (hq : ω ∈ w.calibrationEvent) (x y : V) - (hxu : Conn G (w.exterior ω) x w.base) - (hvy : Conn G (w.exterior ω) w.endpoint y) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) - (hc : r.counted Set.univ ω x y) (hd : Disjoint w.retained r.retained) : - r.counted (w.interior : Set V)ᶜ ω x w.base ∨ r.counted (w.interior : Set V)ᶜ ω w.endpoint y := by - apply r.counted_split_legs (w.interior : Set V)ᶜ ω w.retained x y w.base w.endpoint - hc ?_ hq.1 hd w.retained_conn hxu hvy hne - intro e he - have heω := (hc.2.2.2.1 e he).1.1 - exact (w.open_subset_exterior_retained ω hq heω).resolve_right - (fun hw => Set.disjoint_left.mp hd hw he) - -end RawCorridor -end TwoLegGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TwoLegPenaltyTerms -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem corridorPenaltyTerm_legs (G : BondGraph V E) (hG : Function.Injective G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) - (w r : RawCorridor G k) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) - (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : - corridorPenaltyTerm G P p Set.univ ω x y r ≤ - (∑ e ∈ (w.retained_finite hG).toFinset, if e ∈ r.retained then r.weight P p else 0) + - corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω x w.base r + - corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω w.endpoint y r := by - have hr := r.weight_nonneg P hP p - have hs : 0 ≤ ∑ e ∈ (w.retained_finite hG).toFinset, if e ∈ r.retained then r.weight P p else 0 := - Finset.sum_nonneg (fun _ _ => ite_nonneg hr (le_refl _)) - have hl := corridorPenaltyTerm_nonneg G P hP p (w.interior : Set V)ᶜ ω x w.base r - have ht := corridorPenaltyTerm_nonneg G P hP p (w.interior : Set V)ᶜ ω w.endpoint y r - by_cases hc : r.counted Set.univ ω x y - · rw [corridorPenaltyTerm,ite_eq_left hc] - by_cases hd : Disjoint w.retained r.retained - · rcases w.counted_legs_of_disjoint r ω hq x y hxu hvy hne hc hd with hh | hh - · have he : corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω x w.base r = r.weight P p := ite_eq_left hh - linarith - · have he : corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω w.endpoint y r = r.weight P p := ite_eq_left hh - linarith - · obtain ⟨e,hew,her⟩ := Set.not_disjoint_iff.mp hd - have he := Finset.single_le_sum (f := fun e => if e ∈ r.retained then r.weight P p else 0) - (s := (w.retained_finite hG).toFinset) (fun _ _ => ite_nonneg hr (le_refl _)) - ((w.retained_finite hG).mem_toFinset.mpr hew) - rw [ite_eq_left her] at he - linarith - · rw [corridorPenaltyTerm,ite_eq_right hc] - linarith - - - -theorem corridorPenalty_legs (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (ω : Set E) - (hq : ω ∈ w.calibrationEvent) (x y : V) - (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : - corridorPenalty G P p k Set.univ ω x y ≤ - (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) + - corridorPenalty G P p k (w.interior : Set V)ᶜ ω x w.base + - corridorPenalty G P p k (w.interior : Set V)ᶜ ω w.endpoint y := by - have hs : Summable (fun r : RawCorridor G k => ∑ e ∈ (w.retained_finite hG).toFinset, - if e ∈ r.retained then r.weight P p else 0) := - (hasSum_sum (fun e (_ : e ∈ (w.retained_finite hG).toFinset) => - (summable_raw_edge_weights G hloc P p k e).hasSum)).summable - have hl := corridorPenalty_summable G hloc P p k (w.interior : Set V)ᶜ ω x w.base - have hr := corridorPenalty_summable G hloc P p k (w.interior : Set V)ᶜ ω w.endpoint y - have hh := (corridorPenalty_summable G hloc P p k Set.univ ω x y).tsum_le_tsum - (fun r => corridorPenaltyTerm_legs G hG P hP p k w r ω hq x y hxu hvy hne) ((hs.add hl).add hr) - rw [(hs.add hl).tsum_add hr,hs.tsum_add hl, - Summable.tsum_finsetSum (fun e _ => summable_raw_edge_weights G hloc P p k e)] at hh - exact hh - -end TwoLegPenaltyTerms -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WeightedLegComparison -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} -theorem base_not_interior (w : RawCorridor G k) : w.base ∉ w.interior := by - simp only [interior,Finset.mem_sdiff,Finset.mem_insert,true_or,not_true_eq_false,and_false,not_false_eq_true] -theorem endpoint_not_interior (w : RawCorridor G k) : w.endpoint ∉ w.interior := by - simp only [interior,Finset.mem_sdiff,Finset.mem_insert,Finset.mem_singleton,or_true,not_true_eq_false,and_false,not_false_eq_true] -end RawCorridor - - -theorem deformedConnection_legs_lower (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (ω : Set E) - (hq : ω ∈ w.calibrationEvent) (x y : V) - (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) (c : ℝ) - (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) (t : ℝ) (ht : 0 ≤ t) : - Real.exp (-t*c) * deformedConnection G P p k t (w.interior : Set V)ᶜ ω x w.base * - deformedConnection G P p k t (w.interior : Set V)ᶜ ω w.endpoint y ≤ - deformedConnection G P p k t Set.univ ω x y := by - have hx : x ∈ (w.interior : Set V)ᶜ := by - rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hxu with h | h - · rw [h]; exact w.base_not_interior - · exact h.1 - have hy : y ∈ (w.interior : Set V)ᶜ := by - rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hvy with h | h - · rw [←h]; exact w.endpoint_not_interior - · exact h.2 - have hxy : Conn G (ω ∩ internalEdges G Set.univ) x y := by - apply conn_mono G (show ω ⊆ ω ∩ internalEdges G Set.univ from fun _ h => ⟨h,fun _ _ => trivial⟩) - exact conn_trans G ω (conn_mono G Set.inter_subset_left hxu) - (conn_trans G ω (conn_mono G hq.1 w.retained_conn) (conn_mono G Set.inter_subset_left hvy)) - have hleft : x ∈ (w.interior : Set V)ᶜ ∧ w.base ∈ (w.interior : Set V)ᶜ ∧ - Conn G (ω ∩ internalEdges G (w.interior : Set V)ᶜ) x w.base := ⟨hx,w.base_not_interior,hxu⟩ - have hright : w.endpoint ∈ (w.interior : Set V)ᶜ ∧ y ∈ (w.interior : Set V)ᶜ ∧ - Conn G (ω ∩ internalEdges G (w.interior : Set V)ᶜ) w.endpoint y := ⟨w.endpoint_not_interior,hy,hvy⟩ - simp only [deformedConnection,ite_eq_left hleft,ite_eq_left hright,Set.mem_univ,hxy,and_self,ite_true] - rw [←Real.exp_add,←Real.exp_add] - apply Real.exp_le_exp.mpr - have hh := (corridorPenalty_legs G hG hloc P hP p k w ω hq x y hxu hvy hne).trans - (add_le_add (add_le_add hc le_rfl) le_rfl) - simpa only [mul_add] using mul_le_mul_of_nonpos_left hh (neg_nonpos.mpr ht) - -end WeightedLegComparison -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformLegCost -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem exists_uniform_corridor_leg_cost (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (k : ℕ), 3 ≤ k → ∀ w : RawCorridor G k, - (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight (walkKernel G hloc a) p else 0) ≤ Real.exp (C*(k:ℝ)) := by - obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_edge_cost G hloc d hd a hP hpcrit hpcrit₁ - refine ⟨C,hC,?_⟩ - intro p hpnear hp k hk w - have hh := Finset.sum_le_sum (s := (w.retained_finite hG).toFinset) - (fun e _ => hcost p hpnear hp k hk e) - have hcard : ((w.retained_finite hG).toFinset.card:ℝ) ≤ (k:ℝ) := by - rw [←Set.ncard_eq_toFinset_card w.retained (w.retained_finite hG),w.retained_ncard hG] - exact Nat.cast_le.mpr w.path_length - have hk0 : (0:ℝ) < k := Nat.cast_pos.mpr (by omega) - calc - _ ≤ ((w.retained_finite hG).toFinset.card:ℝ)*(Real.exp (C*(k:ℝ))/(k:ℝ)) := by - simpa only [Finset.sum_const,nsmul_eq_mul] using hh - _ ≤ (k:ℝ)*(Real.exp (C*(k:ℝ))/(k:ℝ)) := mul_le_mul_of_nonneg_right hcard (div_nonneg (Real.exp_pos _).le hk0.le) - _ = _ := by field_simp - -end UniformLegCost -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SimplePathCuts -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem simplePath_edge_cut {H : SimpleGraph V} {u v : V} (q : H.Walk u v) - (hq : q.IsPath) (e : Sym2 V) (he : e ∈ q.edges) : - ∃ A : Set V, u ∈ A ∧ v ∉ A ∧ (∀ z ∈ A, z ∈ q.support) ∧ - ∀ f ∈ q.edges, f ≠ e → ∀ a ∈ f, ∀ b ∈ f, a ∈ A ↔ b ∈ A := by - induction q with - | nil => simp only [SimpleGraph.Walk.edges_nil,List.not_mem_nil] at he - | @cons u a v h q ih => - have hu : u ∉ q.support := ((SimpleGraph.Walk.cons_isPath_iff _ _).mp hq).2 - have huv : v ≠ u := fun hvu => hu (hvu ▸ q.end_mem_support) - by_cases hh : e = s(u,a) - · refine ⟨{u},rfl,huv,?_,?_⟩ - · intro z hz; rw [Set.mem_singleton_iff] at hz; subst z; simp - · intro f hf hfe x hx y hy - have hfq : f ∈ q.edges := (List.mem_cons.mp hf).resolve_left (fun h' => hfe (h'.trans hh.symm)) - have hxu : x ≠ u := fun hxu => hu (hxu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hfq hx) - have hyu : y ≠ u := fun hyu => hu (hyu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hfq hy) - simp only [Set.mem_singleton_iff,hxu,hyu] - · have heq : e ∈ q.edges := (List.mem_cons.mp he).resolve_left hh - obtain ⟨A,ha,hv,hA,hcut⟩ := ih hq.of_cons heq - refine ⟨insert u A,Set.mem_insert u A,?_,?_,?_⟩ - · intro hvA - rcases hvA with h' | h' - · exact huv h' - · exact hv h' - · intro z hz - rcases hz with rfl | hz - · simp - · exact List.mem_cons_of_mem u (hA z hz) - · intro f hf hfe x hx y hy - rcases List.mem_cons.mp hf with rfl | hf - · have hx' : x = u ∨ x = a := by simpa only [SimpleGraph.Dart.edge,Sym2.mem_iff] using hx - have hy' : y = u ∨ y = a := by simpa only [SimpleGraph.Dart.edge,Sym2.mem_iff] using hy - have hxm : x ∈ insert u A := hx'.elim (fun h' => h' ▸ Set.mem_insert u A) - (fun h' => h' ▸ Set.mem_insert_of_mem u ha) - have hym : y ∈ insert u A := hy'.elim (fun h' => h' ▸ Set.mem_insert u A) - (fun h' => h' ▸ Set.mem_insert_of_mem u ha) - exact iff_of_true hxm hym - · have hxu : x ≠ u := fun hxu => hu (hxu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hf hx) - have hyu : y ≠ u := fun hyu => hu (hyu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hf hy) - simpa only [Set.mem_insert_iff,hxu,hyu,false_or] using hcut f hf hfe x hx y hy - -theorem conn_closed_vertex_set (G : BondGraph V E) (S : Set E) (A : Set V) - (hA : ∀ e ∈ S, ∀ a ∈ G e, ∀ b ∈ G e, a ∈ A → b ∈ A) - {x y : V} (hc : Conn G S x y) (hx : x ∈ A) : y ∈ A := by - induction hc with - | refl => exact hx - | @tail a b _ hab ih => - obtain ⟨e,he,heq⟩ := hab - exact hA e he a (heq.symm ▸ Sym2.mem_mk_left a b) b (heq.symm ▸ Sym2.mem_mk_right a b) ih - -end SimplePathCuts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CalibratedCut -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem conn_edge_members (G : BondGraph V E) (S : Set E) (e : E) (he : e ∈ S) - (a b : V) (ha : a ∈ G e) (hb : b ∈ G e) : Conn G S a b := by - obtain ⟨x,y,hxy⟩ : ∃ x y, G e = s(x,y) := by - obtain ⟨⟨x,y⟩,hh⟩ := Quot.exists_rep (G e) - exact ⟨x,y,hh.symm⟩ - rw [hxy,Sym2.mem_iff] at ha hb - rcases ha with rfl | rfl <;> rcases hb with rfl | rfl - · exact conn_refl G S _ - · exact Relation.ReflTransGen.single ⟨e,he,hxy⟩ - · exact conn_symm G S (Relation.ReflTransGen.single ⟨e,he,hxy⟩) - · exact conn_refl G S _ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem calibration_pivotal_ports (hG : Function.Injective G) (w : RawCorridor G k) - (ω : Set E) (hq : ω ∈ w.calibrationEvent) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) - (e : E) (he : e ∈ w.retained) : ¬Conn G (ω \ {e}) w.base w.endpoint := by - obtain ⟨A,hu,hv,hA,hcut⟩ := simplePath_edge_cut w.path w.path_isPath (G e) he - let B := A ∪ {z | Conn G (w.exterior ω) w.base z} - have hAport (z : V) (hz : z ∈ A) (ho : z ∉ w.interior) : z = w.base := by - rcases w.support_exterior_ports (hA z hz) ho with h | h - · exact h - · exact (hv (h ▸ hz)).elim - have hConnOut (z : V) (hz : Conn G (w.exterior ω) w.base z) : z ∉ w.interior := by - rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hz with h | h - · rw [←h]; exact w.base_not_interior - · exact h.2 - have hBclosed : ∀ f ∈ ω \ {e}, ∀ a ∈ G f, ∀ b ∈ G f, a ∈ B → b ∈ B := by - intro f hf a ha b hb hba - rcases w.open_subset_exterior_retained ω hq hf.1 with hfs | hfr - · have hab := conn_edge_members G (w.exterior ω) f hfs a b ha hb - rcases hba with haa | hua - · have hau : a = w.base := hAport a haa (hfs.2 a ha) - exact Or.inr (hau ▸ hab) - · exact Or.inr (conn_trans G _ hua hab) - · have hfe : G f ≠ G e := fun h => hf.2 (hG h) - have haa : a ∈ A := by - rcases hba with h | h - · exact h - · rcases w.support_exterior_ports (SimpleGraph.Walk.mem_support_of_mem_edges hfr ha) - (hConnOut a h) with hau | hav - · exact hau ▸ hu - · exact (hne (hav ▸ h)).elim - exact Or.inl ((hcut (G f) hfr hfe a ha b hb).mp haa) - intro hc - have hh := conn_closed_vertex_set G (ω \ {e}) B hBclosed hc (Or.inl hu) - exact hh.elim hv hne - -end RawCorridor -end CalibratedCut -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ReverseCalibration -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem calibration_counted_of_orientation (hG : Function.Injective G) (w : RawCorridor G k) - (hlen : 3 ≤ w.path.length) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) - (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) - (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : w.counted Set.univ ω x y := by - have huniv : ω ∩ internalEdges G Set.univ = ω := by - apply Set.Subset.antisymm Set.inter_subset_left - exact fun _ he => ⟨he,fun _ _ => trivial⟩ - apply (w.counted_iff Set.univ ω x y).mpr - refine ⟨hlen,?_⟩ - unfold corridorCounted - rw [huniv] - refine ⟨conn_trans G ω (conn_mono G Set.inter_subset_left hxu) - (conn_trans G ω (conn_mono G hq.1 w.retained_conn) (conn_mono G Set.inter_subset_left hvy)),?_,hq.2⟩ - intro e he - refine ⟨hq.1 he,?_⟩ - intro hxy - have hS : w.exterior ω ⊆ ω \ {e} := by - intro f hf - refine ⟨hf.1,?_⟩ - intro hfe - have hfe' : f = e := hfe - subst f - exact Set.disjoint_left.mp (w.specified_disjoint_exterior hlen) (Or.inl he) hf.2 - exact w.calibration_pivotal_ports hG ω hq hne e he - (conn_trans G _ (conn_mono G hS (conn_symm G _ hxu)) - (conn_trans G _ hxy (conn_mono G hS (conn_symm G _ hvy)))) - - - -theorem calibration_counted_iff (hG : Function.Injective G) (w : RawCorridor G k) - (hlen : 3 ≤ w.path.length) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) : - w.counted Set.univ ω x y ↔ ¬Conn G (w.exterior ω) w.base w.endpoint ∧ - ((Conn G (w.exterior ω) w.base x ∧ Conn G (w.exterior ω) w.endpoint y) ∨ - (Conn G (w.exterior ω) w.endpoint x ∧ Conn G (w.exterior ω) w.base y)) := by - constructor - · intro hc - exact w.counted_exterior_orientation hlen ω hq x y hc.2.2 - · rintro ⟨hne,ho⟩ - rcases ho with ⟨hx,hy⟩ | ⟨hx,hy⟩ - · exact w.calibration_counted_of_orientation hG hlen ω hq x y (conn_symm G _ hx) hy hne - · exact (w.counted_symm Set.univ ω y x).mp - (w.calibration_counted_of_orientation hG hlen ω hq y x (conn_symm G _ hy) hx hne) - -end RawCorridor -end ReverseCalibration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExteriorLegObservable -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedConnection_restrict_config (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - deformedConnection G P p k t D (ω ∩ internalEdges G D) x y = - deformedConnection G P p k t D ω x y := by - have he : (ω ∩ internalEdges G D) ∩ internalEdges G D = ω ∩ internalEdges G D := - Set.inter_assoc _ _ _ |>.trans (congrArg (ω ∩ ·) (Set.inter_self _)) - have hc (w : RawCorridor G k) : w.counted D (ω ∩ internalEdges G D) x y ↔ w.counted D ω x y := by - simp only [RawCorridor.counted,corridorCounted,he] - simp only [deformedConnection,corridorPenalty,corridorPenaltyTerm,hc,he] - -noncomputable def exteriorLegProduct (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : ℝ := - if ¬Conn G (w.exterior ω) w.base w.endpoint then - deformedConnection G P p k t (w.interior : Set V)ᶜ ω x w.base * - deformedConnection G P p k t (w.interior : Set V)ᶜ ω w.endpoint y else 0 - -theorem exteriorLegProduct_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : - 0 ≤ exteriorLegProduct G P p t w ω x y := by - unfold exteriorLegProduct - by_cases h : ¬Conn G (w.exterior ω) w.base w.endpoint - · rw [ite_eq_left h] - exact mul_nonneg (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) - (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) - · rw [ite_eq_right h] - -theorem exteriorLegProduct_le_one (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (t : ℝ) (ht : 0 ≤ t) - (w : RawCorridor G k) (ω : Set E) (x y : V) : - exteriorLegProduct G P p t w ω x y ≤ 1 := by - unfold exteriorLegProduct - by_cases h : ¬Conn G (w.exterior ω) w.base w.endpoint - · rw [ite_eq_left h] - exact (mul_le_of_le_one_left (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) - (deformedConnection_le_one G P hP p k t ht _ _ _ _)).trans - (deformedConnection_le_one G P hP p k t ht _ _ _ _) - · rw [ite_eq_right h] - exact zero_le_one - -theorem measurable_exteriorLegProduct [Countable V] [Countable E] - (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) {k : ℕ} (t : ℝ) - (w : RawCorridor G k) (x y : V) : - Measurable (fun ω => exteriorLegProduct G P p t w ω x y) := by - apply Measurable.ite - ((measurableSet_restrictedConn G (internalEdges G (w.interior:Set V)ᶜ) w.base w.endpoint).compl) - · exact (measurable_deformedConnection G P p k t _ x w.base).mul - (measurable_deformedConnection G P p k t _ w.endpoint y) - · exact measurable_const - -theorem exteriorLegProduct_restrict (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : - exteriorLegProduct G P p t w ω x y = - exteriorLegProduct G P p t w (ω ∩ internalEdges G (w.interior:Set V)ᶜ) x y := by - simp only [exteriorLegProduct,RawCorridor.exterior,Set.inter_assoc,Set.inter_self, - deformedConnection_restrict_config] - rfl - -end ExteriorLegObservable -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CalibrationFactor -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem measurableSet_calibration (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) : MeasurableSet w.calibrationEvent := by - rw [w.calibrationEvent_eq hG hloc] - apply measurableSet_edgePattern - apply Finset.disjoint_left.mpr - intro e he hb - exact Set.disjoint_left.mp w.retained_disjoint_blockers - ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) - - - -theorem calibration_integral (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (p : unitInterval) - (f : Set E → ℝ) (hf : Measurable f) - (hfr : ∀ ω, f ω = f (ω ∩ internalEdges G (w.interior:Set V)ᶜ)) : - (∫ ω, if ω ∈ w.calibrationEvent then f ω else 0 ∂law p) = - (law p).real w.calibrationEvent * ∫ ω, f ω ∂law p := by - have hh := integral_mul_disjoint_coordinates p _ _ (w.specified_disjoint_exterior hlen) - (fun ω => if ω ∈ w.calibrationEvent then (1:ℝ) else 0) f - (Measurable.ite (w.measurableSet_calibration hG hloc) measurable_const measurable_const) hf - (fun ω => by rw [w.calibration_restriction ω]) hfr - simpa only [ite_mul,one_mul,zero_mul,integral_event_indicator p _ (w.measurableSet_calibration hG hloc)] using hh - -theorem calibration_weighted_integral (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (P : V → V → ℝ) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) - (f : Set E → ℝ) (hf : Measurable f) - (hfr : ∀ ω, f ω = f (ω ∩ internalEdges G (w.interior:Set V)ᶜ)) : - (∫ ω, if ω ∈ w.calibrationEvent then w.weight P p * f ω else 0 ∂law p) = - w.probability P * ∫ ω, f ω ∂law p := by - have he : (fun ω => if ω ∈ w.calibrationEvent then w.weight P p * f ω else 0) = - (fun ω => w.weight P p * (if ω ∈ w.calibrationEvent then f ω else 0)) := by - funext ω - by_cases h : ω ∈ w.calibrationEvent <;> simp only [h,ite_true,ite_false,mul_zero] - rw [he,integral_const_mul,w.calibration_integral hG hloc hlen p f hf hfr, - ←mul_assoc,w.calibration_identity hG hloc P p hp hp₁] - -end RawCorridor -end CalibrationFactor -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CalibratedDerivativeTerm -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem calibrated_leg_product_le_term (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) (ω : Set E) (x y : V) : - (if ω ∈ w.calibrationEvent then w.weight P p * (Real.exp (-t*c) * - exteriorLegProduct G P p t w ω x y) else 0) ≤ - corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y := by - have hr : 0 ≤ corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y := - mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) - (deformedConnection_nonneg G P p k t Set.univ ω x y) - by_cases hq : ω ∈ w.calibrationEvent - · rw [ite_eq_left hq] - by_cases hn : ¬Conn G (w.exterior ω) w.base w.endpoint - · rw [exteriorLegProduct,ite_eq_left hn] - by_cases hx : Conn G (w.exterior ω) x w.base - · by_cases hy : Conn G (w.exterior ω) w.endpoint y - · have hj := w.calibration_counted_of_orientation hG hlen ω hq x y hx hy hn - rw [corridorPenaltyTerm,ite_eq_left hj] - have hh := mul_le_mul_of_nonneg_left - (deformedConnection_legs_lower G hG hloc P hP p k w ω hq x y hx hy hn c hc t ht) - (w.weight_nonneg P hP p) - simpa only [mul_assoc] using hh - · have hz : deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.endpoint y = 0 := by - simp only [deformedConnection,show ¬Conn G (ω ∩ internalEdges G (w.interior:Set V)ᶜ) w.endpoint y from hy,and_false,ite_false] - simpa only [hz,mul_zero] using hr - · have hz : deformedConnection G P p k t (w.interior:Set V)ᶜ ω x w.base = 0 := by - simp only [deformedConnection,show ¬Conn G (ω ∩ internalEdges G (w.interior:Set V)ᶜ) x w.base from hx,and_false,ite_false] - simpa only [hz,zero_mul,mul_zero] using hr - · simpa only [exteriorLegProduct,ite_eq_right hn,mul_zero] using hr - · simpa only [ite_eq_right hq] using hr - -theorem integrable_corridorDerivativeTerm [Countable V] [Countable E] - (G : BondGraph V E) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) - (w : RawCorridor G k) : - Integrable (fun ω => corridorPenaltyTerm G P p D ω x y w * - deformedConnection G P p k t D ω x y) (law p) := by - have hh := ((integrable_deformedConnection G P hP p k t ht D x y).const_mul - (w.weight P p)).indicator (w.measurableSet_counted D x y) - have he : (fun ω => corridorPenaltyTerm G P p D ω x y w * - deformedConnection G P p k t D ω x y) = - {ω | w.counted D ω x y}.indicator (fun ω => w.weight P p * deformedConnection G P p k t D ω x y) := by - funext ω - simp only [Set.indicator,Set.mem_ofPred_eq,corridorPenaltyTerm,ite_mul,zero_mul] - rw [he] - exact hh - -end CalibratedDerivativeTerm -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CalibratedDecreaseKernel -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integrable_exteriorLegProduct [Countable V] [Countable E] - (G : BondGraph V E) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) (x y : V) : - Integrable (fun ω => exteriorLegProduct G P p t w ω x y) (law p) := by - apply Integrable.mono' (integrable_const (1:ℝ)) - (measurable_exteriorLegProduct G P p t w x y).aestronglyMeasurable - filter_upwards [] with ω - rw [Real.norm_of_nonneg (exteriorLegProduct_nonneg G P p t w ω x y)] - exact exteriorLegProduct_le_one G P hP p t ht w ω x y - - - -theorem calibrated_derivative_kernel_lower [Countable V] [Countable E] - (G : BondGraph V E) (hG : Function.Injective G) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) - (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) (x y : V) : - w.probability P * Real.exp (-t*c) * (∫ ω, exteriorLegProduct G P p t w ω x y ∂law p) ≤ - ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * - deformedConnection G P p k t Set.univ ω x y ∂law p := by - have hf := integrable_exteriorLegProduct G P hP p t ht w x y - have hi : Integrable (fun ω => if ω ∈ w.calibrationEvent then w.weight P p * - (Real.exp (-t*c) * exteriorLegProduct G P p t w ω x y) else 0) (law p) := - ((hf.const_mul (Real.exp (-t*c))).const_mul (w.weight P p)).indicator - (w.measurableSet_calibration hG hloc) - have hh := integral_mono hi (integrable_corridorDerivativeTerm G P hP p k t ht Set.univ x y w) - (fun ω => calibrated_leg_product_le_term G hG hloc P hP p k w hlen c hc t ht ω x y) - rw [w.calibration_weighted_integral hG hloc hlen P p hp hp₁ - (fun ω => Real.exp (-t*c)*exteriorLegProduct G P p t w ω x y) - ((measurable_exteriorLegProduct G P p t w x y).const_mul _) - (fun ω => congrArg (Real.exp (-t*c)*·) (exteriorLegProduct_restrict G P p t w ω x y)), - integral_const_mul] at hh - simpa only [mul_assoc] using hh - -end CalibratedDecreaseKernel -end Percolation - - -namespace Percolation -open MeasureTheory -section NonnegativeRealTonelli -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem real_tonelli_of_integrable_sum {Ω I : Type*} [MeasurableSpace Ω] [Countable I] - (μ : Measure Ω) (F : I → Ω → ℝ) (hF : ∀ i, Integrable (F i) μ) - (hn : ∀ i ω, 0 ≤ F i ω) (hs : ∀ᵐ ω ∂μ, Summable (fun i => F i ω)) - (hi : Integrable (fun ω => ∑' i, F i ω) μ) : - Summable (fun i => ∫ ω, F i ω ∂μ) ∧ - (∑' i, ∫ ω, F i ω ∂μ) = ∫ ω, ∑' i, F i ω ∂μ := by - have he : (∑' i, ENNReal.ofReal (∫ ω, F i ω ∂μ)) = - ∫⁻ ω, ENNReal.ofReal (∑' i, F i ω) ∂μ := by - simp_rw [ofReal_integral_eq_lintegral_ofReal (hF _) (Filter.Eventually.of_forall (hn _))] - rw [←lintegral_tsum (fun i => (hF i).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] - apply lintegral_congr_ae - filter_upwards [hs] with ω hω - exact (ENNReal.ofReal_tsum_of_nonneg (fun i => hn i ω) hω).symm - have ht : (∑' i, ENNReal.ofReal (∫ ω, F i ω ∂μ)) ≠ ⊤ := by - rw [he,←ofReal_integral_eq_lintegral_ofReal hi - (Filter.Eventually.of_forall (fun ω => tsum_nonneg (fun i => hn i ω)))] - exact ENNReal.ofReal_ne_top - have hh : Summable (fun i => ∫ ω, F i ω ∂μ) := by - simpa only [ENNReal.toReal_ofReal (integral_nonneg (hn _))] using ENNReal.summable_toReal ht - refine ⟨hh,?_⟩ - apply integral_tsum_of_summable_integral_norm hF - simpa only [Real.norm_of_nonneg (hn _ _)] using hh - -end NonnegativeRealTonelli -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section TotalExteriorLegs -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem exteriorLegProduct_sum (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) - (hu : (cluster G ω w.base).Finite) (hv : (cluster G ω w.endpoint).Finite) : - Summable (fun xy : V × V => exteriorLegProduct G P p t w ω xy.1 xy.2) ∧ - (∑' xy : V × V, exteriorLegProduct G P p t w ω xy.1 xy.2) = - if ¬Conn G (w.exterior ω) w.base w.endpoint then - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0 := by - by_cases hn : ¬Conn G (w.exterior ω) w.base w.endpoint - · have hsu : Summable (deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.base) := - summable_of_hasFiniteSupport (deformedConnection_finite_support G P p k t (w.interior:Set V)ᶜ ω w.base hu) - have hsv : Summable (deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.endpoint) := - summable_of_hasFiniteSupport (deformedConnection_finite_support G P p k t (w.interior:Set V)ᶜ ω w.endpoint hv) - have hsx : Summable (fun x => deformedConnection G P p k t (w.interior:Set V)ᶜ ω x w.base) := by - simpa only [deformedConnection_symm G P p k t (w.interior:Set V)ᶜ ω _ w.base] using hsu - have hs := hsx.mul_of_nonneg hsv - (fun x => deformedConnection_nonneg G P p k t _ ω x w.base) - (fun y => deformedConnection_nonneg G P p k t _ ω w.endpoint y) - simp only [exteriorLegProduct,ite_eq_left hn] - refine ⟨hs,?_⟩ - rw [←hsx.tsum_mul_tsum hsv hs] - simp only [deformedClusterMass,deformedConnection_symm G P p k t (w.interior:Set V)ᶜ ω _ w.base] - · simp only [exteriorLegProduct,ite_eq_right hn,summable_zero,tsum_zero,and_self] - - - -theorem exteriorLegProduct_integral_sum [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) : - Summable (fun xy : V × V => ∫ ω, exteriorLegProduct G P p t w ω xy.1 xy.2 ∂law p) ∧ - (∑' xy : V × V, ∫ ω, exteriorLegProduct G P p t w ω xy.1 xy.2 ∂law p) = - ∫ ω, (if ¬Conn G (w.exterior ω) w.base w.endpoint then - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0) ∂law p := by - have hae : ∀ᵐ ω ∂law p, Summable (fun xy : V × V => exteriorLegProduct G P p t w ω xy.1 xy.2) ∧ - (∑' xy : V × V, exteriorLegProduct G P p t w ω xy.1 xy.2) = - if ¬Conn G (w.exterior ω) w.base w.endpoint then - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0 := by - filter_upwards [subcritical_cluster_finite_ae G p hp w.base, - subcritical_cluster_finite_ae G p hp w.endpoint] with ω hu hv - exact exteriorLegProduct_sum G P p t w ω hu hv - have hi := (integrable_distinct_deformed_product G hloc hqt P hP p hp k t ht - (w.interior:Set V)ᶜ w.base w.endpoint).congr (hae.mono (fun _ h => h.2.symm)) - obtain ⟨hs,he⟩ := real_tonelli_of_integrable_sum (law p) - (fun xy : V × V => fun ω => exteriorLegProduct G P p t w ω xy.1 xy.2) - (fun xy => integrable_exteriorLegProduct G P hP p t ht w xy.1 xy.2) - (fun xy ω => exteriorLegProduct_nonneg G P p t w ω xy.1 xy.2) - (hae.mono (fun _ h => h.1)) hi - exact ⟨hs,he.trans (integral_congr_ae (hae.mono (fun _ h => h.2)))⟩ - -end TotalExteriorLegs -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SummableDerivativeTerm -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -omit [Nonempty V] in -theorem integral_corridorDerivativeTerm_le (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) - {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) (x y : V) : - (∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * - deformedConnection G P p k t Set.univ ω x y ∂law p) ≤ - w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + - twoPoint G p x w.endpoint * twoPoint G p w.base y) := by - apply le_trans (integral_mono (integrable_corridorDerivativeTerm G P hP p k t ht Set.univ x y w) - (integrable_corridorPenaltyTerm G P p Set.univ x y w) (fun ω => - mul_le_of_le_one_right (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) - (deformedConnection_le_one G P hP p k t ht Set.univ ω x y))) - exact integral_corridorPenaltyTerm_le G hG hloc P hP p hp0 hp1 x y w - -theorem summable_twoPoint_pairs (G : BondGraph V E) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (p : unitInterval) - (hp : p < pc G) (u v : V) : - Summable (fun xy : V × V => twoPoint G p xy.1 u * twoPoint G p v xy.2) := by - have hs : Summable (fun x => twoPoint G p x u) := by - simpa only [twoPoint_symm G p _ u] using summable_twoPoint_subcritical G hloc hqt p hp u - exact hs.mul_of_nonneg (summable_twoPoint_subcritical G hloc hqt p hp v) - (fun x => twoPoint_nonneg G p x u) (fun y => twoPoint_nonneg G p v y) - -omit [Nonempty V] [Countable V] [Countable E] in - theorem integral_corridorDerivativeTerm_nonneg (G : BondGraph V E) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) - (t : ℝ) (w : RawCorridor G k) (x y : V) : - 0 ≤ ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * - deformedConnection G P p k t Set.univ ω x y ∂law p := - integral_nonneg (fun ω => mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) - (deformedConnection_nonneg G P p k t Set.univ ω x y)) - -theorem summable_corridorDerivativeTerm_pairs (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) : - Summable (fun xy : V × V => ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * - deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p) := by - have hs : Summable (fun xy : V × V => w.probability P * - (twoPoint G p xy.1 w.base * twoPoint G p w.endpoint xy.2 + - twoPoint G p xy.1 w.endpoint * twoPoint G p w.base xy.2)) := - ((summable_twoPoint_pairs G hloc hqt p hp w.base w.endpoint).add - (summable_twoPoint_pairs G hloc hqt p hp w.endpoint w.base)).mul_left (w.probability P) - exact Summable.of_nonneg_of_le - (fun (xy : V × V) => integral_corridorDerivativeTerm_nonneg G P hP p k t w xy.1 xy.2) - (fun (xy : V × V) => integral_corridorDerivativeTerm_le G hG hloc P hP p hp0 - ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) t ht w xy.1 xy.2) hs - -end SummableDerivativeTerm -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SingleTemplateDecrease -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem calibrated_derivative_template_lower (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) : - w.probability P * Real.exp (-t*c) * - (∫ ω, (if ¬Conn G (w.exterior ω) w.base w.endpoint then - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * - deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0) ∂law p) ≤ - ∑' xy : V × V, ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * - deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p := by - obtain ⟨hs,he⟩ := exteriorLegProduct_integral_sum G hloc hqt P hP p hp t ht w - have hh := (hs.mul_left (w.probability P * Real.exp (-t*c))).tsum_le_tsum - (fun (xy : V × V) => calibrated_derivative_kernel_lower G hG hloc P hP p hp0 - ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) k w hlen c hc t ht xy.1 xy.2) - (summable_corridorDerivativeTerm_pairs G hG hloc hqt P hP p hp0 hp t ht w) - rwa [tsum_mul_left,he] at hh - - - -theorem calibrated_derivative_template_row_lower (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) - (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, - if e ∈ r.retained then r.weight P p else 0) ≤ c) - (t : ℝ) (ht : 0 ≤ t) : - w.probability P * Real.exp (-t*c) * - (deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.base * - deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.endpoint - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2*(matrixCoeff (T^3) w.base w.endpoint).re) ≤ - ∑' xy : V × V, ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * - deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p := by - have hm := deformed_distinct_correlation_uniform G hloc hqt d hd P hP hpcrit p hp hpnear T hT - k t ht (w.interior:Set V)ᶜ w.base w.endpoint - exact (mul_le_mul_of_nonneg_left hm (mul_nonneg (w.2.2.mass_nonneg P hP) (Real.exp_pos _).le)).trans - (calibrated_derivative_template_lower G hG hloc hqt P hP p ((half_pos hpcrit).trans_le hpnear) - hp k w hlen c hc t ht) - -end SingleTemplateDecrease -end Percolation - - -namespace Percolation -universe u u' v -section ErasureNaturality -attribute [local instance] Classical.propDecidable Classical.decEq -variable {V : Type u} {V' : Type u'} {H : SimpleGraph V} {H' : SimpleGraph V'} - -theorem walk_map_dropUntil (f : H →g H') (hf : Function.Injective f) - {x y : V} (w : H.Walk x y) (z : V) (hz : z ∈ w.support) : - (w.dropUntil z hz).map f = (w.map f).dropUntil (f z) - (by simpa only [SimpleGraph.Walk.support_map] using List.mem_map_of_mem hz) := by - induction w with - | @nil x => - have he : z = x := by simpa using hz - subst z - rfl - | @cons x a y h w ih => - by_cases he : x = z - · subst z - simp only [SimpleGraph.Walk.dropUntil_first] - · have hfe : f x ≠ f z := fun h => he (hf h) - simp only [SimpleGraph.Walk.dropUntil,he,hfe,SimpleGraph.Walk.map_cons] - exact ih _ - - - -theorem walk_map_bypass (f : H →g H') (hf : Function.Injective f) - {x y : V} (w : H.Walk x y) : w.bypass.map f = (w.map f).bypass := by - induction w with - | nil => rfl - | @cons x a y h w ih => - have hm : f x ∈ (w.map f).bypass.support ↔ x ∈ w.bypass.support := by - rw [←ih,SimpleGraph.Walk.support_map] - exact List.mem_map_of_injective hf - by_cases hx : x ∈ w.bypass.support - · have hfx := hm.mpr hx - simp only [SimpleGraph.Walk.bypass,SimpleGraph.Walk.map_cons,dite_eq_left hx,dite_eq_left hfx] - simp only [walk_map_dropUntil f hf,ih] - · have hfx := mt hm.mp hx - simp only [SimpleGraph.Walk.bypass,SimpleGraph.Walk.map_cons,dite_eq_right hx,dite_eq_right hfx,ih] - -namespace HoldingWalk - -def map (f : H →g H') : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H' k (f x) (f y) - | _,_,_,.nil _ => .nil _ - | _,_,_,.hold w => .hold (w.map f) - | _,_,_,.step h w => .step (f.map_rel h) (w.map f) - -theorem map_vertices (f : H →g H') {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - (w.map f).vertices = w.vertices.map f := by - induction w with - | nil => rfl - | hold w ih => simp only [map,vertices,List.map_cons,ih] - | step h w ih => simp only [map,vertices,List.map_cons,ih] - -theorem map_withoutHolds (f : H →g H') {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - (w.map f).withoutHolds = w.withoutHolds.map f := by - induction w with - | nil => rfl - | hold w ih => exact ih - | step h w ih => simp only [map,withoutHolds,SimpleGraph.Walk.map_cons,ih] - -theorem map_erase (f : H →g H') (hf : Function.Injective f) - {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : - (w.map f).erase = w.erase.map f := by - simp only [erase,map_withoutHolds,SimpleGraph.Walk.reverse_map, - ←walk_map_bypass f hf] - -end HoldingWalk -end ErasureNaturality -end Percolation - - -namespace Percolation -universe u u' u'' v -section RawWalkMaps -attribute [local instance] Classical.propDecidable Classical.decEq -variable {V : Type u} {V' : Type u'} {V'' : Type u''} - {H : SimpleGraph V} {H' : SimpleGraph V'} {H'' : SimpleGraph V''} -namespace HoldingWalk - -theorem map_map (f : H →g H') (g : H' →g H'') - {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : (w.map f).map g = w.map (g.comp f) := by - induction w with - | nil => rfl - | hold w ih => exact congrArg hold ih - | step h w ih => exact congrArg (step _) ih - -theorem map_id {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.map ((SimpleGraph.Hom.id : H →g H)) = w := by - induction w with - | nil => rfl - | hold w ih => exact congrArg hold ih - | step h w ih => exact congrArg (step _) ih - -theorem mass_map (f : H →g H') (P : V → V → ℝ) (Q : V' → V' → ℝ) - (hPQ : ∀ x y, Q (f x) (f y) = P x y) - {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : (w.map f).mass Q = w.mass P := by - induction w with - | nil => rfl - | hold w ih => simp only [map,mass,hPQ,ih] - | step h w ih => simp only [map,mass,hPQ,ih] -end HoldingWalk - -def rawWalkMap (f : H →g H') (k : ℕ) (w : Σ x y, HoldingWalk H k x y) : - Σ x y, HoldingWalk H' k x y := ⟨f w.1,f w.2.1,w.2.2.map f⟩ - -theorem rawWalkMap_comp (f : H →g H') (g : H' →g H'') (k : ℕ) - (w : Σ x y, HoldingWalk H k x y) : rawWalkMap g k (rawWalkMap f k w) = rawWalkMap (g.comp f) k w := by - cases w with - | mk x w => - cases w with - | mk y w => - simp only [rawWalkMap,HoldingWalk.map_map] - rfl - -theorem rawWalkMap_id (k : ℕ) (w : Σ x y, HoldingWalk H k x y) : - rawWalkMap ((SimpleGraph.Hom.id : H →g H)) k w = w := by - cases w with - | mk x w => - cases w with - | mk y w => - simp only [rawWalkMap,HoldingWalk.map_id] - rfl - -def rawWalkEquiv (f : H ≃g H') (k : ℕ) : - (Σ x y, HoldingWalk H k x y) ≃ (Σ x y, HoldingWalk H' k x y) where - toFun := rawWalkMap f.toHom k - invFun := rawWalkMap f.symm.toHom k - left_inv w := by - rw [rawWalkMap_comp] - have he : f.symm.toHom.comp f.toHom = (SimpleGraph.Hom.id : H →g H) := by - ext x - exact f.symm_apply_apply x - rw [he,rawWalkMap_id] - right_inv w := by - rw [rawWalkMap_comp] - have he : f.toHom.comp f.symm.toHom = (SimpleGraph.Hom.id : H' →g H') := by - ext x - exact f.apply_symm_apply x - rw [he,rawWalkMap_id] - -end RawWalkMaps -section GraphAutWalks -attribute [local instance] Classical.propDecidable Classical.decEq -variable {V : Type u} {E : Type v} - -theorem openSimpleGraph_univ_adj (G : BondGraph V E) (x y : V) : - (openSimpleGraph G Set.univ).Adj x y ↔ x ≠ y ∧ Adj G x y := by - simp only [openSimpleGraph,Adj,Set.mem_univ,true_and] - -def autSimpleGraph (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : - openSimpleGraph G Set.univ ≃g openSimpleGraph G Set.univ where - toEquiv := a - map_rel_iff' := by - intro x y - simp only [openSimpleGraph_univ_adj,a.injective.ne_iff] - exact and_congr_right (fun _ => ⟨fun h => by simpa using adj_aut G (isAut_symm G hab) h, - adj_aut G hab⟩) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} -def autEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : RawCorridor G k ≃ RawCorridor G k := - rawWalkEquiv (autSimpleGraph G hab) k - -theorem aut_path {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).path = w.path.map (autSimpleGraph G hab).toHom := - w.2.2.map_erase _ a.injective - -theorem aut_path_length {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).path.length = w.path.length := by - have hh := congrArg (fun q => q.length) (aut_path hab w) - exact hh.trans (SimpleGraph.Walk.length_map _ _) - -end RawCorridor -end GraphAutWalks -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TemplateCovariance -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem aut_base {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).base = a w.base := rfl - -theorem aut_endpoint {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).endpoint = a w.endpoint := rfl - -theorem aut_support {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).path.support = w.path.support.map a := by - exact (congrArg (fun q => q.support) (aut_path hab w)).trans - (SimpleGraph.Walk.support_map _ _) - -theorem aut_edges {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).path.edges = w.path.edges.map (Sym2.map a) := by - exact (congrArg (fun q => q.edges) (aut_path hab w)).trans - (SimpleGraph.Walk.edges_map _ _) - -theorem aut_interior {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (z : V) : - a z ∈ (autEquiv hab w).interior ↔ z ∈ w.interior := by - simp only [interior,Finset.mem_sdiff,List.mem_toFinset] - rw [aut_support hab w] - simp only [aut_base,aut_endpoint,Finset.mem_insert,Finset.mem_singleton, - List.mem_map_of_injective a.injective,a.injective.eq_iff] - -theorem aut_retained {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (e : E) : - b e ∈ (autEquiv hab w).retained ↔ e ∈ w.retained := by - simp only [retained,Set.mem_ofPred_eq,aut_edges hab w,hab e] - exact List.mem_map_of_injective (Sym2.map.injective a.injective) - -theorem aut_blockers {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (e : E) : - b e ∈ (autEquiv hab w).blockers ↔ e ∈ w.blockers := by - simp only [blockers,Set.mem_sdiff,Set.mem_ofPred_eq,aut_retained] - apply and_congr_left - intro _ - constructor - · rintro ⟨z,hz,he⟩ - rw [hab e] at he - obtain ⟨y,hy,rfl⟩ := Sym2.mem_map.mp he - exact ⟨y,(aut_interior hab w y).mp hz,hy⟩ - · rintro ⟨z,hz,he⟩ - refine ⟨a z,(aut_interior hab w z).mpr hz,?_⟩ - rw [hab e] - exact Sym2.mem_map.mpr ⟨z,he,rfl⟩ - -theorem aut_blockers_ncard {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : - (autEquiv hab w).blockers.ncard = w.blockers.ncard := by - have he : w.blockers = b ⁻¹' (autEquiv hab w).blockers := by - ext e - exact (aut_blockers hab w e).symm - rw [he,Set.ncard_preimage_of_injective_subset_range b.injective] - exact fun e _ => b.surjective e - -theorem aut_probability {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) (w : RawCorridor G k) : - (autEquiv hab w).probability P = w.probability P := - w.2.2.mass_map (autSimpleGraph G hab).toHom P P hP - -theorem aut_weight {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) (p : ℝ) (w : RawCorridor G k) : - (autEquiv hab w).weight P p = w.weight P p := by - simp only [weight,aut_probability hab P hP,aut_path_length,aut_blockers_ncard] - -end RawCorridor -end TemplateCovariance -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.Derivatives + +namespace OAI + +/-! Calibration for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformDeformedEndpoint +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_uniform_deformed_endpoint_comparison [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (k : ℕ), 3 ≤ k → ∀ (t : ℝ), 0 ≤ t → ∀ (D : Set V) (b z : V) (l : List E), + b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → + Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * + deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t D b := by + obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_edge_cost G hloc d hd a hP hpcrit hpcrit₁ + refine ⟨C,hC,?_⟩ + intro p hpnear hp k hk t ht D b z l hb hl hD + have hc : ∀ e, (∑' w : RawCorridor G k, + if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ Real.exp (C*(k:ℝ)) := by + intro e + exact (hcost p hpnear hp k hk e).trans (div_le_self (Real.exp_pos _).le (by exact_mod_cast (show 1 ≤ k by omega))) + have hh := deformedSusceptibility_move_lower G hloc hqt (walkKernel G hloc a) hP p hp k t ht D + l.toFinset (fun e he => hD e (List.mem_toFinset.mp he)) b z hb + (hl.conn (fun e he => List.mem_toFinset.mpr he)) (Real.exp (C*(k:ℝ))) hc + have hcard : (l.toFinset.card:ℝ) ≤ (l.length:ℝ) := Nat.cast_le.mpr l.toFinset_card_le + have he : Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) ≤ + Real.exp (-t*((l.toFinset.card:ℝ)*Real.exp (C*(k:ℝ)))) := by + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (mul_le_mul_of_nonneg_right hcard (Real.exp_pos _).le) (neg_nonpos.mpr ht) + have hpw : (p:ℝ)^l.length ≤ (p:ℝ)^l.toFinset.card := + pow_le_pow_of_le_one p.2.1 p.2.2 l.toFinset_card_le + exact (mul_le_mul_of_nonneg_right (mul_le_mul he hpw (pow_nonneg p.2.1 _) (Real.exp_pos _).le) + (tsum_nonneg (deformedKernel_nonneg G (walkKernel G hloc a) p k t D z))).trans hh + +end UniformDeformedEndpoint +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PivotalLegGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem pivotal_endpoint_connected (G : BondGraph V E) (S : Set E) (x y : V) + (hc : Conn G S x y) (e : E) (hp : ¬Conn G (S \ {e}) x y) (z : V) (hz : z ∈ G e) : + Conn G S x z := by + obtain ⟨q⟩ := (conn_iff_reachable G S x y).mp hc + have hzs : z ∈ q.support := SimpleGraph.Walk.mem_support_of_mem_edges + (pivotal_image_mem_edges G S q e hp) hz + exact (conn_iff_reachable G S x z).mpr ⟨q.takeUntil z hzs⟩ + +theorem conn_delete_of_unconnected_endpoint (G : BondGraph V E) (S : Set E) (x y z : V) + (hc : Conn G S x y) (e : E) (hz : z ∈ G e) (hn : ¬Conn G S x z) : + Conn G (S \ {e}) x y := by + by_contra hh + exact hn (pivotal_endpoint_connected G S x y hc e hh z hz) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem retained_conn_base (w : RawCorridor G k) (z : V) (hz : z ∈ w.path.support) : + Conn G w.retained w.base z := by + obtain ⟨l,hl,hm,_⟩ := walk_lift_bonds G Set.univ (w.path.takeUntil z hz) + apply hl.conn + intro e he + exact w.path.edges_takeUntil_subset_edges hz (hm ▸ List.mem_map_of_mem he) + +theorem retained_conn (w : RawCorridor G k) : Conn G w.retained w.base w.endpoint := + w.retained_conn_base w.endpoint w.path.end_mem_support + +theorem retained_connects_support (w : RawCorridor G k) (x y : V) + (hx : x ∈ w.path.support) (hy : y ∈ w.path.support) : Conn G w.retained x y := + conn_trans G _ (conn_symm G _ (w.retained_conn_base x hx)) (w.retained_conn_base y hy) + +theorem retained_nonempty (w : RawCorridor G k) (hl : 0 < w.path.length) : w.retained.Nonempty := by + have hp : w.path.edges ≠ [] := by + intro he + have hh := congrArg List.length he + simp only [SimpleGraph.Walk.length_edges,List.length_nil] at hh + omega + obtain ⟨s,hs⟩ := List.exists_mem_of_ne_nil _ hp + obtain ⟨e,he,_⟩ := w.edge_has_label s hs + exact ⟨e,he⟩ + +end RawCorridor +end PivotalLegGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OneLegGeometry +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem counted_one_leg (r : RawCorridor G k) (D : Set V) (ω B : Set E) + (x y u v : V) (hc : r.counted Set.univ ω x y) + (hr : r.retained ⊆ ω ∩ internalEdges G D) (hB : B ⊆ ω) + (hd : Disjoint B r.retained) (huv : Conn G B u v) + (hxu : Conn G (ω ∩ internalEdges G D) x u) + (hvy : Conn G (ω ∩ internalEdges G D) v y) + (hne : ¬Conn G (ω ∩ internalEdges G D) u v) + (e : E) (he : e ∈ r.retained) + (hep : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x u) : r.counted D ω x u := by + let S := ω ∩ internalEdges G D + have huniv : ω ∩ internalEdges G Set.univ = ω := by + apply Set.Subset.antisymm Set.inter_subset_left + exact fun _ he => ⟨he,fun _ _ => trivial⟩ + obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by + obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) + exact ⟨z,z',hh.symm⟩ + have hz : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' + have hxz : Conn G S x z := pivotal_endpoint_connected G S x u hxu e hep z hz + have hzsupport : z ∈ r.path.support := SimpleGraph.Walk.mem_support_of_mem_edges he hz + apply (r.counted_iff D ω x u).mpr + refine ⟨hc.1,hxu,?_,hc.2.2.2.2.mono_right ?_⟩ + · intro f hf + refine ⟨hr hf,?_⟩ + intro hxf + obtain ⟨a,b,hab⟩ : ∃ a b, G f = s(a,b) := by + obtain ⟨⟨a,b⟩,hh⟩ := Quot.exists_rep (G f) + exact ⟨a,b,hh.symm⟩ + have ha : a ∈ G f := hab.symm ▸ Sym2.mem_mk_left a b + have haz : Conn G S z a := conn_mono G hr (r.retained_connects_support z a hzsupport + (SimpleGraph.Walk.mem_support_of_mem_edges hf ha)) + have hua : Conn G S u a := conn_trans G S (conn_symm G S hxu) (conn_trans G S hxz haz) + have hvf : Conn G (S \ {f}) v y := conn_delete_of_unconnected_endpoint G S v y a hvy f ha + (fun hva => hne (conn_trans G S hua (conn_symm G S hva))) + have hBf : Conn G (ω \ {f}) u v := conn_mono G (show B ⊆ ω \ {f} from fun g hg => ⟨hB hg,fun hgf => + Set.disjoint_left.mp hd hg ((Set.mem_singleton_iff.mp hgf).symm ▸ hf)⟩) huv + apply (hc.2.2.2.1 f hf).2 + rw [huniv] + exact conn_trans G _ (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hxf) + (conn_trans G _ hBf (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hvf)) + · rw [huniv] + exact Set.inter_subset_left + +end RawCorridor +end OneLegGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TwoLegGeometry +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem counted_split_legs (r : RawCorridor G k) (D : Set V) (ω B : Set E) + (x y u v : V) (hc : r.counted Set.univ ω x y) + (hr : r.retained ⊆ ω ∩ internalEdges G D) (hB : B ⊆ ω) + (hd : Disjoint B r.retained) (huv : Conn G B u v) + (hxu : Conn G (ω ∩ internalEdges G D) x u) + (hvy : Conn G (ω ∩ internalEdges G D) v y) + (hne : ¬Conn G (ω ∩ internalEdges G D) u v) : + r.counted D ω x u ∨ r.counted D ω v y := by + obtain ⟨e,he⟩ := r.retained_nonempty (by have := hc.1; omega) + by_cases hp : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x u + · exact Or.inl (r.counted_one_leg D ω B x y u v hc hr hB hd huv hxu hvy hne e he hp) + · have hxu' : Conn G ((ω ∩ internalEdges G D) \ {e}) x u := not_not.mp hp + have hp' : ¬Conn G ((ω ∩ internalEdges G D) \ {e}) y v := by + intro hyv + apply (hc.2.2.2.1 e he).2 + have huniv : ω ∩ internalEdges G Set.univ = ω := by + apply Set.Subset.antisymm Set.inter_subset_left + exact fun _ he => ⟨he,fun _ _ => trivial⟩ + rw [huniv] + have hB' : Conn G (ω \ {e}) u v := conn_mono G (show B ⊆ ω \ {e} from fun f hf => ⟨hB hf,fun hfe => + Set.disjoint_left.mp hd hf ((Set.mem_singleton_iff.mp hfe).symm ▸ he)⟩) huv + exact conn_trans G _ (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) hxu') + (conn_trans G _ hB' (conn_mono G (Set.sdiff_subset_sdiff_left Set.inter_subset_left) (conn_symm G _ hyv))) + exact Or.inr ((r.counted_symm D ω y v).mp (r.counted_one_leg D ω B y x v u + ((r.counted_symm Set.univ ω x y).mp hc) hr hB hd (conn_symm G B huv) + (conn_symm G _ hvy) (conn_symm G _ hxu) (fun h => hne (conn_symm G _ h)) e he hp')) + + +theorem counted_legs_of_disjoint (w r : RawCorridor G k) (ω : Set E) + (hq : ω ∈ w.calibrationEvent) (x y : V) + (hxu : Conn G (w.exterior ω) x w.base) + (hvy : Conn G (w.exterior ω) w.endpoint y) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) + (hc : r.counted Set.univ ω x y) (hd : Disjoint w.retained r.retained) : + r.counted (w.interior : Set V)ᶜ ω x w.base ∨ r.counted (w.interior : Set V)ᶜ ω w.endpoint y := by + apply r.counted_split_legs (w.interior : Set V)ᶜ ω w.retained x y w.base w.endpoint + hc ?_ hq.1 hd w.retained_conn hxu hvy hne + intro e he + have heω := (hc.2.2.2.1 e he).1.1 + exact (w.open_subset_exterior_retained ω hq heω).resolve_right + (fun hw => Set.disjoint_left.mp hd hw he) + +end RawCorridor +end TwoLegGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TwoLegPenaltyTerms +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem corridorPenaltyTerm_legs (G : BondGraph V E) (hG : Function.Injective G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) + (w r : RawCorridor G k) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) + (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : + corridorPenaltyTerm G P p Set.univ ω x y r ≤ + (∑ e ∈ (w.retained_finite hG).toFinset, if e ∈ r.retained then r.weight P p else 0) + + corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω x w.base r + + corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω w.endpoint y r := by + have hr := r.weight_nonneg P hP p + have hs : 0 ≤ ∑ e ∈ (w.retained_finite hG).toFinset, if e ∈ r.retained then r.weight P p else 0 := + Finset.sum_nonneg (fun _ _ => ite_nonneg hr (le_refl _)) + have hl := corridorPenaltyTerm_nonneg G P hP p (w.interior : Set V)ᶜ ω x w.base r + have ht := corridorPenaltyTerm_nonneg G P hP p (w.interior : Set V)ᶜ ω w.endpoint y r + by_cases hc : r.counted Set.univ ω x y + · rw [corridorPenaltyTerm,ite_eq_left hc] + by_cases hd : Disjoint w.retained r.retained + · rcases w.counted_legs_of_disjoint r ω hq x y hxu hvy hne hc hd with hh | hh + · have he : corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω x w.base r = r.weight P p := ite_eq_left hh + linarith + · have he : corridorPenaltyTerm G P p (w.interior : Set V)ᶜ ω w.endpoint y r = r.weight P p := ite_eq_left hh + linarith + · obtain ⟨e,hew,her⟩ := Set.not_disjoint_iff.mp hd + have he := Finset.single_le_sum (f := fun e => if e ∈ r.retained then r.weight P p else 0) + (s := (w.retained_finite hG).toFinset) (fun _ _ => ite_nonneg hr (le_refl _)) + ((w.retained_finite hG).mem_toFinset.mpr hew) + rw [ite_eq_left her] at he + linarith + · rw [corridorPenaltyTerm,ite_eq_right hc] + linarith + + + +theorem corridorPenalty_legs (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (ω : Set E) + (hq : ω ∈ w.calibrationEvent) (x y : V) + (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : + corridorPenalty G P p k Set.univ ω x y ≤ + (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) + + corridorPenalty G P p k (w.interior : Set V)ᶜ ω x w.base + + corridorPenalty G P p k (w.interior : Set V)ᶜ ω w.endpoint y := by + have hs : Summable (fun r : RawCorridor G k => ∑ e ∈ (w.retained_finite hG).toFinset, + if e ∈ r.retained then r.weight P p else 0) := + (hasSum_sum (fun e (_ : e ∈ (w.retained_finite hG).toFinset) => + (summable_raw_edge_weights G hloc P p k e).hasSum)).summable + have hl := corridorPenalty_summable G hloc P p k (w.interior : Set V)ᶜ ω x w.base + have hr := corridorPenalty_summable G hloc P p k (w.interior : Set V)ᶜ ω w.endpoint y + have hh := (corridorPenalty_summable G hloc P p k Set.univ ω x y).tsum_le_tsum + (fun r => corridorPenaltyTerm_legs G hG P hP p k w r ω hq x y hxu hvy hne) ((hs.add hl).add hr) + rw [(hs.add hl).tsum_add hr,hs.tsum_add hl, + Summable.tsum_finsetSum (fun e _ => summable_raw_edge_weights G hloc P p k e)] at hh + exact hh + +end TwoLegPenaltyTerms +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WeightedLegComparison +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} +theorem base_not_interior (w : RawCorridor G k) : w.base ∉ w.interior := by + simp only [interior,Finset.mem_sdiff,Finset.mem_insert,true_or,not_true_eq_false,and_false,not_false_eq_true] +theorem endpoint_not_interior (w : RawCorridor G k) : w.endpoint ∉ w.interior := by + simp only [interior,Finset.mem_sdiff,Finset.mem_insert,Finset.mem_singleton,or_true,not_true_eq_false,and_false,not_false_eq_true] +end RawCorridor + + +theorem deformedConnection_legs_lower (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (ω : Set E) + (hq : ω ∈ w.calibrationEvent) (x y : V) + (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) (c : ℝ) + (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) (t : ℝ) (ht : 0 ≤ t) : + Real.exp (-t*c) * deformedConnection G P p k t (w.interior : Set V)ᶜ ω x w.base * + deformedConnection G P p k t (w.interior : Set V)ᶜ ω w.endpoint y ≤ + deformedConnection G P p k t Set.univ ω x y := by + have hx : x ∈ (w.interior : Set V)ᶜ := by + rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hxu with h | h + · rw [h]; exact w.base_not_interior + · exact h.1 + have hy : y ∈ (w.interior : Set V)ᶜ := by + rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hvy with h | h + · rw [←h]; exact w.endpoint_not_interior + · exact h.2 + have hxy : Conn G (ω ∩ internalEdges G Set.univ) x y := by + apply conn_mono G (show ω ⊆ ω ∩ internalEdges G Set.univ from fun _ h => ⟨h,fun _ _ => trivial⟩) + exact conn_trans G ω (conn_mono G Set.inter_subset_left hxu) + (conn_trans G ω (conn_mono G hq.1 w.retained_conn) (conn_mono G Set.inter_subset_left hvy)) + have hleft : x ∈ (w.interior : Set V)ᶜ ∧ w.base ∈ (w.interior : Set V)ᶜ ∧ + Conn G (ω ∩ internalEdges G (w.interior : Set V)ᶜ) x w.base := ⟨hx,w.base_not_interior,hxu⟩ + have hright : w.endpoint ∈ (w.interior : Set V)ᶜ ∧ y ∈ (w.interior : Set V)ᶜ ∧ + Conn G (ω ∩ internalEdges G (w.interior : Set V)ᶜ) w.endpoint y := ⟨w.endpoint_not_interior,hy,hvy⟩ + simp only [deformedConnection,ite_eq_left hleft,ite_eq_left hright,Set.mem_univ,hxy,and_self,ite_true] + rw [←Real.exp_add,←Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := (corridorPenalty_legs G hG hloc P hP p k w ω hq x y hxu hvy hne).trans + (add_le_add (add_le_add hc le_rfl) le_rfl) + simpa only [mul_add] using mul_le_mul_of_nonpos_left hh (neg_nonpos.mpr ht) + +end WeightedLegComparison +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformLegCost +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem exists_uniform_corridor_leg_cost (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (k : ℕ), 3 ≤ k → ∀ w : RawCorridor G k, + (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight (walkKernel G hloc a) p else 0) ≤ Real.exp (C*(k:ℝ)) := by + obtain ⟨C,hC,hcost⟩ := exists_uniform_corridor_edge_cost G hloc d hd a hP hpcrit hpcrit₁ + refine ⟨C,hC,?_⟩ + intro p hpnear hp k hk w + have hh := Finset.sum_le_sum (s := (w.retained_finite hG).toFinset) + (fun e _ => hcost p hpnear hp k hk e) + have hcard : ((w.retained_finite hG).toFinset.card:ℝ) ≤ (k:ℝ) := by + rw [←Set.ncard_eq_toFinset_card w.retained (w.retained_finite hG),w.retained_ncard hG] + exact Nat.cast_le.mpr w.path_length + have hk0 : (0:ℝ) < k := Nat.cast_pos.mpr (by omega) + calc + _ ≤ ((w.retained_finite hG).toFinset.card:ℝ)*(Real.exp (C*(k:ℝ))/(k:ℝ)) := by + simpa only [Finset.sum_const,nsmul_eq_mul] using hh + _ ≤ (k:ℝ)*(Real.exp (C*(k:ℝ))/(k:ℝ)) := mul_le_mul_of_nonneg_right hcard (div_nonneg (Real.exp_pos _).le hk0.le) + _ = _ := by field_simp + +end UniformLegCost +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SimplePathCuts +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem simplePath_edge_cut {H : SimpleGraph V} {u v : V} (q : H.Walk u v) + (hq : q.IsPath) (e : Sym2 V) (he : e ∈ q.edges) : + ∃ A : Set V, u ∈ A ∧ v ∉ A ∧ (∀ z ∈ A, z ∈ q.support) ∧ + ∀ f ∈ q.edges, f ≠ e → ∀ a ∈ f, ∀ b ∈ f, a ∈ A ↔ b ∈ A := by + induction q with + | nil => simp only [SimpleGraph.Walk.edges_nil,List.not_mem_nil] at he + | @cons u a v h q ih => + have hu : u ∉ q.support := ((SimpleGraph.Walk.cons_isPath_iff _ _).mp hq).2 + have huv : v ≠ u := fun hvu => hu (hvu ▸ q.end_mem_support) + by_cases hh : e = s(u,a) + · refine ⟨{u},rfl,huv,?_,?_⟩ + · intro z hz; rw [Set.mem_singleton_iff] at hz; subst z; simp + · intro f hf hfe x hx y hy + have hfq : f ∈ q.edges := (List.mem_cons.mp hf).resolve_left (fun h' => hfe (h'.trans hh.symm)) + have hxu : x ≠ u := fun hxu => hu (hxu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hfq hx) + have hyu : y ≠ u := fun hyu => hu (hyu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hfq hy) + simp only [Set.mem_singleton_iff,hxu,hyu] + · have heq : e ∈ q.edges := (List.mem_cons.mp he).resolve_left hh + obtain ⟨A,ha,hv,hA,hcut⟩ := ih hq.of_cons heq + refine ⟨insert u A,Set.mem_insert u A,?_,?_,?_⟩ + · intro hvA + rcases hvA with h' | h' + · exact huv h' + · exact hv h' + · intro z hz + rcases hz with rfl | hz + · simp + · exact List.mem_cons_of_mem u (hA z hz) + · intro f hf hfe x hx y hy + rcases List.mem_cons.mp hf with rfl | hf + · have hx' : x = u ∨ x = a := by simpa only [SimpleGraph.Dart.edge,Sym2.mem_iff] using hx + have hy' : y = u ∨ y = a := by simpa only [SimpleGraph.Dart.edge,Sym2.mem_iff] using hy + have hxm : x ∈ insert u A := hx'.elim (fun h' => h' ▸ Set.mem_insert u A) + (fun h' => h' ▸ Set.mem_insert_of_mem u ha) + have hym : y ∈ insert u A := hy'.elim (fun h' => h' ▸ Set.mem_insert u A) + (fun h' => h' ▸ Set.mem_insert_of_mem u ha) + exact iff_of_true hxm hym + · have hxu : x ≠ u := fun hxu => hu (hxu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hf hx) + have hyu : y ≠ u := fun hyu => hu (hyu ▸ SimpleGraph.Walk.mem_support_of_mem_edges hf hy) + simpa only [Set.mem_insert_iff,hxu,hyu,false_or] using hcut f hf hfe x hx y hy + +theorem conn_closed_vertex_set (G : BondGraph V E) (S : Set E) (A : Set V) + (hA : ∀ e ∈ S, ∀ a ∈ G e, ∀ b ∈ G e, a ∈ A → b ∈ A) + {x y : V} (hc : Conn G S x y) (hx : x ∈ A) : y ∈ A := by + induction hc with + | refl => exact hx + | @tail a b _ hab ih => + obtain ⟨e,he,heq⟩ := hab + exact hA e he a (heq.symm ▸ Sym2.mem_mk_left a b) b (heq.symm ▸ Sym2.mem_mk_right a b) ih + +end SimplePathCuts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CalibratedCut +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem conn_edge_members (G : BondGraph V E) (S : Set E) (e : E) (he : e ∈ S) + (a b : V) (ha : a ∈ G e) (hb : b ∈ G e) : Conn G S a b := by + obtain ⟨x,y,hxy⟩ : ∃ x y, G e = s(x,y) := by + obtain ⟨⟨x,y⟩,hh⟩ := Quot.exists_rep (G e) + exact ⟨x,y,hh.symm⟩ + rw [hxy,Sym2.mem_iff] at ha hb + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact conn_refl G S _ + · exact Relation.ReflTransGen.single ⟨e,he,hxy⟩ + · exact conn_symm G S (Relation.ReflTransGen.single ⟨e,he,hxy⟩) + · exact conn_refl G S _ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem calibration_pivotal_ports (hG : Function.Injective G) (w : RawCorridor G k) + (ω : Set E) (hq : ω ∈ w.calibrationEvent) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) + (e : E) (he : e ∈ w.retained) : ¬Conn G (ω \ {e}) w.base w.endpoint := by + obtain ⟨A,hu,hv,hA,hcut⟩ := simplePath_edge_cut w.path w.path_isPath (G e) he + let B := A ∪ {z | Conn G (w.exterior ω) w.base z} + have hAport (z : V) (hz : z ∈ A) (ho : z ∉ w.interior) : z = w.base := by + rcases w.support_exterior_ports (hA z hz) ho with h | h + · exact h + · exact (hv (h ▸ hz)).elim + have hConnOut (z : V) (hz : Conn G (w.exterior ω) w.base z) : z ∉ w.interior := by + rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hz with h | h + · rw [←h]; exact w.base_not_interior + · exact h.2 + have hBclosed : ∀ f ∈ ω \ {e}, ∀ a ∈ G f, ∀ b ∈ G f, a ∈ B → b ∈ B := by + intro f hf a ha b hb hba + rcases w.open_subset_exterior_retained ω hq hf.1 with hfs | hfr + · have hab := conn_edge_members G (w.exterior ω) f hfs a b ha hb + rcases hba with haa | hua + · have hau : a = w.base := hAport a haa (hfs.2 a ha) + exact Or.inr (hau ▸ hab) + · exact Or.inr (conn_trans G _ hua hab) + · have hfe : G f ≠ G e := fun h => hf.2 (hG h) + have haa : a ∈ A := by + rcases hba with h | h + · exact h + · rcases w.support_exterior_ports (SimpleGraph.Walk.mem_support_of_mem_edges hfr ha) + (hConnOut a h) with hau | hav + · exact hau ▸ hu + · exact (hne (hav ▸ h)).elim + exact Or.inl ((hcut (G f) hfr hfe a ha b hb).mp haa) + intro hc + have hh := conn_closed_vertex_set G (ω \ {e}) B hBclosed hc (Or.inl hu) + exact hh.elim hv hne + +end RawCorridor +end CalibratedCut +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ReverseCalibration +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem calibration_counted_of_orientation (hG : Function.Injective G) (w : RawCorridor G k) + (hlen : 3 ≤ w.path.length) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) + (hxu : Conn G (w.exterior ω) x w.base) (hvy : Conn G (w.exterior ω) w.endpoint y) + (hne : ¬Conn G (w.exterior ω) w.base w.endpoint) : w.counted Set.univ ω x y := by + have huniv : ω ∩ internalEdges G Set.univ = ω := by + apply Set.Subset.antisymm Set.inter_subset_left + exact fun _ he => ⟨he,fun _ _ => trivial⟩ + apply (w.counted_iff Set.univ ω x y).mpr + refine ⟨hlen,?_⟩ + unfold corridorCounted + rw [huniv] + refine ⟨conn_trans G ω (conn_mono G Set.inter_subset_left hxu) + (conn_trans G ω (conn_mono G hq.1 w.retained_conn) (conn_mono G Set.inter_subset_left hvy)),?_,hq.2⟩ + intro e he + refine ⟨hq.1 he,?_⟩ + intro hxy + have hS : w.exterior ω ⊆ ω \ {e} := by + intro f hf + refine ⟨hf.1,?_⟩ + intro hfe + have hfe' : f = e := hfe + subst f + exact Set.disjoint_left.mp (w.specified_disjoint_exterior hlen) (Or.inl he) hf.2 + exact w.calibration_pivotal_ports hG ω hq hne e he + (conn_trans G _ (conn_mono G hS (conn_symm G _ hxu)) + (conn_trans G _ hxy (conn_mono G hS (conn_symm G _ hvy)))) + + + +theorem calibration_counted_iff (hG : Function.Injective G) (w : RawCorridor G k) + (hlen : 3 ≤ w.path.length) (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) : + w.counted Set.univ ω x y ↔ ¬Conn G (w.exterior ω) w.base w.endpoint ∧ + ((Conn G (w.exterior ω) w.base x ∧ Conn G (w.exterior ω) w.endpoint y) ∨ + (Conn G (w.exterior ω) w.endpoint x ∧ Conn G (w.exterior ω) w.base y)) := by + constructor + · intro hc + exact w.counted_exterior_orientation hlen ω hq x y hc.2.2 + · rintro ⟨hne,ho⟩ + rcases ho with ⟨hx,hy⟩ | ⟨hx,hy⟩ + · exact w.calibration_counted_of_orientation hG hlen ω hq x y (conn_symm G _ hx) hy hne + · exact (w.counted_symm Set.univ ω y x).mp + (w.calibration_counted_of_orientation hG hlen ω hq y x (conn_symm G _ hy) hx hne) + +end RawCorridor +end ReverseCalibration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExteriorLegObservable +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedConnection_restrict_config (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + deformedConnection G P p k t D (ω ∩ internalEdges G D) x y = + deformedConnection G P p k t D ω x y := by + have he : (ω ∩ internalEdges G D) ∩ internalEdges G D = ω ∩ internalEdges G D := + Set.inter_assoc _ _ _ |>.trans (congrArg (ω ∩ ·) (Set.inter_self _)) + have hc (w : RawCorridor G k) : w.counted D (ω ∩ internalEdges G D) x y ↔ w.counted D ω x y := by + simp only [RawCorridor.counted,corridorCounted,he] + simp only [deformedConnection,corridorPenalty,corridorPenaltyTerm,hc,he] + +noncomputable def exteriorLegProduct (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : ℝ := + if ¬Conn G (w.exterior ω) w.base w.endpoint then + deformedConnection G P p k t (w.interior : Set V)ᶜ ω x w.base * + deformedConnection G P p k t (w.interior : Set V)ᶜ ω w.endpoint y else 0 + +theorem exteriorLegProduct_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : + 0 ≤ exteriorLegProduct G P p t w ω x y := by + unfold exteriorLegProduct + by_cases h : ¬Conn G (w.exterior ω) w.base w.endpoint + · rw [ite_eq_left h] + exact mul_nonneg (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) + (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) + · rw [ite_eq_right h] + +theorem exteriorLegProduct_le_one (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (t : ℝ) (ht : 0 ≤ t) + (w : RawCorridor G k) (ω : Set E) (x y : V) : + exteriorLegProduct G P p t w ω x y ≤ 1 := by + unfold exteriorLegProduct + by_cases h : ¬Conn G (w.exterior ω) w.base w.endpoint + · rw [ite_eq_left h] + exact (mul_le_of_le_one_left (deformedConnection_nonneg _ _ _ _ _ _ _ _ _) + (deformedConnection_le_one G P hP p k t ht _ _ _ _)).trans + (deformedConnection_le_one G P hP p k t ht _ _ _ _) + · rw [ite_eq_right h] + exact zero_le_one + +theorem measurable_exteriorLegProduct [Countable V] [Countable E] + (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) {k : ℕ} (t : ℝ) + (w : RawCorridor G k) (x y : V) : + Measurable (fun ω => exteriorLegProduct G P p t w ω x y) := by + apply Measurable.ite + ((measurableSet_restrictedConn G (internalEdges G (w.interior:Set V)ᶜ) w.base w.endpoint).compl) + · exact (measurable_deformedConnection G P p k t _ x w.base).mul + (measurable_deformedConnection G P p k t _ w.endpoint y) + · exact measurable_const + +theorem exteriorLegProduct_restrict (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) (x y : V) : + exteriorLegProduct G P p t w ω x y = + exteriorLegProduct G P p t w (ω ∩ internalEdges G (w.interior:Set V)ᶜ) x y := by + simp only [exteriorLegProduct,RawCorridor.exterior,Set.inter_assoc,Set.inter_self, + deformedConnection_restrict_config] + rfl + +end ExteriorLegObservable +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CalibrationFactor +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem measurableSet_calibration (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) : MeasurableSet w.calibrationEvent := by + rw [w.calibrationEvent_eq hG hloc] + apply measurableSet_edgePattern + apply Finset.disjoint_left.mpr + intro e he hb + exact Set.disjoint_left.mp w.retained_disjoint_blockers + ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) + + + +theorem calibration_integral (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (p : unitInterval) + (f : Set E → ℝ) (hf : Measurable f) + (hfr : ∀ ω, f ω = f (ω ∩ internalEdges G (w.interior:Set V)ᶜ)) : + (∫ ω, if ω ∈ w.calibrationEvent then f ω else 0 ∂law p) = + (law p).real w.calibrationEvent * ∫ ω, f ω ∂law p := by + have hh := integral_mul_disjoint_coordinates p _ _ (w.specified_disjoint_exterior hlen) + (fun ω => if ω ∈ w.calibrationEvent then (1:ℝ) else 0) f + (Measurable.ite (w.measurableSet_calibration hG hloc) measurable_const measurable_const) hf + (fun ω => by rw [w.calibration_restriction ω]) hfr + simpa only [ite_mul,one_mul,zero_mul,integral_event_indicator p _ (w.measurableSet_calibration hG hloc)] using hh + +theorem calibration_weighted_integral (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (P : V → V → ℝ) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) + (f : Set E → ℝ) (hf : Measurable f) + (hfr : ∀ ω, f ω = f (ω ∩ internalEdges G (w.interior:Set V)ᶜ)) : + (∫ ω, if ω ∈ w.calibrationEvent then w.weight P p * f ω else 0 ∂law p) = + w.probability P * ∫ ω, f ω ∂law p := by + have he : (fun ω => if ω ∈ w.calibrationEvent then w.weight P p * f ω else 0) = + (fun ω => w.weight P p * (if ω ∈ w.calibrationEvent then f ω else 0)) := by + funext ω + by_cases h : ω ∈ w.calibrationEvent <;> simp only [h,ite_true,ite_false,mul_zero] + rw [he,integral_const_mul,w.calibration_integral hG hloc hlen p f hf hfr, + ←mul_assoc,w.calibration_identity hG hloc P p hp hp₁] + +end RawCorridor +end CalibrationFactor +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CalibratedDerivativeTerm +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem calibrated_leg_product_le_term (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) (ω : Set E) (x y : V) : + (if ω ∈ w.calibrationEvent then w.weight P p * (Real.exp (-t*c) * + exteriorLegProduct G P p t w ω x y) else 0) ≤ + corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y := by + have hr : 0 ≤ corridorPenaltyTerm G P p Set.univ ω x y w * deformedConnection G P p k t Set.univ ω x y := + mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) + (deformedConnection_nonneg G P p k t Set.univ ω x y) + by_cases hq : ω ∈ w.calibrationEvent + · rw [ite_eq_left hq] + by_cases hn : ¬Conn G (w.exterior ω) w.base w.endpoint + · rw [exteriorLegProduct,ite_eq_left hn] + by_cases hx : Conn G (w.exterior ω) x w.base + · by_cases hy : Conn G (w.exterior ω) w.endpoint y + · have hj := w.calibration_counted_of_orientation hG hlen ω hq x y hx hy hn + rw [corridorPenaltyTerm,ite_eq_left hj] + have hh := mul_le_mul_of_nonneg_left + (deformedConnection_legs_lower G hG hloc P hP p k w ω hq x y hx hy hn c hc t ht) + (w.weight_nonneg P hP p) + simpa only [mul_assoc] using hh + · have hz : deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.endpoint y = 0 := by + simp only [deformedConnection,show ¬Conn G (ω ∩ internalEdges G (w.interior:Set V)ᶜ) w.endpoint y from hy,and_false,ite_false] + simpa only [hz,mul_zero] using hr + · have hz : deformedConnection G P p k t (w.interior:Set V)ᶜ ω x w.base = 0 := by + simp only [deformedConnection,show ¬Conn G (ω ∩ internalEdges G (w.interior:Set V)ᶜ) x w.base from hx,and_false,ite_false] + simpa only [hz,zero_mul,mul_zero] using hr + · simpa only [exteriorLegProduct,ite_eq_right hn,mul_zero] using hr + · simpa only [ite_eq_right hq] using hr + +theorem integrable_corridorDerivativeTerm [Countable V] [Countable E] + (G : BondGraph V E) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) + (w : RawCorridor G k) : + Integrable (fun ω => corridorPenaltyTerm G P p D ω x y w * + deformedConnection G P p k t D ω x y) (law p) := by + have hh := ((integrable_deformedConnection G P hP p k t ht D x y).const_mul + (w.weight P p)).indicator (w.measurableSet_counted D x y) + have he : (fun ω => corridorPenaltyTerm G P p D ω x y w * + deformedConnection G P p k t D ω x y) = + {ω | w.counted D ω x y}.indicator (fun ω => w.weight P p * deformedConnection G P p k t D ω x y) := by + funext ω + simp only [Set.indicator,Set.mem_ofPred_eq,corridorPenaltyTerm,ite_mul,zero_mul] + rw [he] + exact hh + +end CalibratedDerivativeTerm +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CalibratedDecreaseKernel +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integrable_exteriorLegProduct [Countable V] [Countable E] + (G : BondGraph V E) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) (x y : V) : + Integrable (fun ω => exteriorLegProduct G P p t w ω x y) (law p) := by + apply Integrable.mono' (integrable_const (1:ℝ)) + (measurable_exteriorLegProduct G P p t w x y).aestronglyMeasurable + filter_upwards [] with ω + rw [Real.norm_of_nonneg (exteriorLegProduct_nonneg G P p t w ω x y)] + exact exteriorLegProduct_le_one G P hP p t ht w ω x y + + + +theorem calibrated_derivative_kernel_lower [Countable V] [Countable E] + (G : BondGraph V E) (hG : Function.Injective G) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) + (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) (x y : V) : + w.probability P * Real.exp (-t*c) * (∫ ω, exteriorLegProduct G P p t w ω x y ∂law p) ≤ + ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * + deformedConnection G P p k t Set.univ ω x y ∂law p := by + have hf := integrable_exteriorLegProduct G P hP p t ht w x y + have hi : Integrable (fun ω => if ω ∈ w.calibrationEvent then w.weight P p * + (Real.exp (-t*c) * exteriorLegProduct G P p t w ω x y) else 0) (law p) := + ((hf.const_mul (Real.exp (-t*c))).const_mul (w.weight P p)).indicator + (w.measurableSet_calibration hG hloc) + have hh := integral_mono hi (integrable_corridorDerivativeTerm G P hP p k t ht Set.univ x y w) + (fun ω => calibrated_leg_product_le_term G hG hloc P hP p k w hlen c hc t ht ω x y) + rw [w.calibration_weighted_integral hG hloc hlen P p hp hp₁ + (fun ω => Real.exp (-t*c)*exteriorLegProduct G P p t w ω x y) + ((measurable_exteriorLegProduct G P p t w x y).const_mul _) + (fun ω => congrArg (Real.exp (-t*c)*·) (exteriorLegProduct_restrict G P p t w ω x y)), + integral_const_mul] at hh + simpa only [mul_assoc] using hh + +end CalibratedDecreaseKernel +end Percolation + + +namespace Percolation +open MeasureTheory +section NonnegativeRealTonelli +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem real_tonelli_of_integrable_sum {Ω I : Type*} [MeasurableSpace Ω] [Countable I] + (μ : Measure Ω) (F : I → Ω → ℝ) (hF : ∀ i, Integrable (F i) μ) + (hn : ∀ i ω, 0 ≤ F i ω) (hs : ∀ᵐ ω ∂μ, Summable (fun i => F i ω)) + (hi : Integrable (fun ω => ∑' i, F i ω) μ) : + Summable (fun i => ∫ ω, F i ω ∂μ) ∧ + (∑' i, ∫ ω, F i ω ∂μ) = ∫ ω, ∑' i, F i ω ∂μ := by + have he : (∑' i, ENNReal.ofReal (∫ ω, F i ω ∂μ)) = + ∫⁻ ω, ENNReal.ofReal (∑' i, F i ω) ∂μ := by + simp_rw [ofReal_integral_eq_lintegral_ofReal (hF _) (Filter.Eventually.of_forall (hn _))] + rw [←lintegral_tsum (fun i => (hF i).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] + apply lintegral_congr_ae + filter_upwards [hs] with ω hω + exact (ENNReal.ofReal_tsum_of_nonneg (fun i => hn i ω) hω).symm + have ht : (∑' i, ENNReal.ofReal (∫ ω, F i ω ∂μ)) ≠ ⊤ := by + rw [he,←ofReal_integral_eq_lintegral_ofReal hi + (Filter.Eventually.of_forall (fun ω => tsum_nonneg (fun i => hn i ω)))] + exact ENNReal.ofReal_ne_top + have hh : Summable (fun i => ∫ ω, F i ω ∂μ) := by + simpa only [ENNReal.toReal_ofReal (integral_nonneg (hn _))] using ENNReal.summable_toReal ht + refine ⟨hh,?_⟩ + apply integral_tsum_of_summable_integral_norm hF + simpa only [Real.norm_of_nonneg (hn _ _)] using hh + +end NonnegativeRealTonelli +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section TotalExteriorLegs +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem exteriorLegProduct_sum (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) {k : ℕ} (t : ℝ) (w : RawCorridor G k) (ω : Set E) + (hu : (cluster G ω w.base).Finite) (hv : (cluster G ω w.endpoint).Finite) : + Summable (fun xy : V × V => exteriorLegProduct G P p t w ω xy.1 xy.2) ∧ + (∑' xy : V × V, exteriorLegProduct G P p t w ω xy.1 xy.2) = + if ¬Conn G (w.exterior ω) w.base w.endpoint then + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0 := by + by_cases hn : ¬Conn G (w.exterior ω) w.base w.endpoint + · have hsu : Summable (deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.base) := + summable_of_hasFiniteSupport (deformedConnection_finite_support G P p k t (w.interior:Set V)ᶜ ω w.base hu) + have hsv : Summable (deformedConnection G P p k t (w.interior:Set V)ᶜ ω w.endpoint) := + summable_of_hasFiniteSupport (deformedConnection_finite_support G P p k t (w.interior:Set V)ᶜ ω w.endpoint hv) + have hsx : Summable (fun x => deformedConnection G P p k t (w.interior:Set V)ᶜ ω x w.base) := by + simpa only [deformedConnection_symm G P p k t (w.interior:Set V)ᶜ ω _ w.base] using hsu + have hs := hsx.mul_of_nonneg hsv + (fun x => deformedConnection_nonneg G P p k t _ ω x w.base) + (fun y => deformedConnection_nonneg G P p k t _ ω w.endpoint y) + simp only [exteriorLegProduct,ite_eq_left hn] + refine ⟨hs,?_⟩ + rw [←hsx.tsum_mul_tsum hsv hs] + simp only [deformedClusterMass,deformedConnection_symm G P p k t (w.interior:Set V)ᶜ ω _ w.base] + · simp only [exteriorLegProduct,ite_eq_right hn,summable_zero,tsum_zero,and_self] + + + +theorem exteriorLegProduct_integral_sum [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) : + Summable (fun xy : V × V => ∫ ω, exteriorLegProduct G P p t w ω xy.1 xy.2 ∂law p) ∧ + (∑' xy : V × V, ∫ ω, exteriorLegProduct G P p t w ω xy.1 xy.2 ∂law p) = + ∫ ω, (if ¬Conn G (w.exterior ω) w.base w.endpoint then + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0) ∂law p := by + have hae : ∀ᵐ ω ∂law p, Summable (fun xy : V × V => exteriorLegProduct G P p t w ω xy.1 xy.2) ∧ + (∑' xy : V × V, exteriorLegProduct G P p t w ω xy.1 xy.2) = + if ¬Conn G (w.exterior ω) w.base w.endpoint then + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0 := by + filter_upwards [subcritical_cluster_finite_ae G p hp w.base, + subcritical_cluster_finite_ae G p hp w.endpoint] with ω hu hv + exact exteriorLegProduct_sum G P p t w ω hu hv + have hi := (integrable_distinct_deformed_product G hloc hqt P hP p hp k t ht + (w.interior:Set V)ᶜ w.base w.endpoint).congr (hae.mono (fun _ h => h.2.symm)) + obtain ⟨hs,he⟩ := real_tonelli_of_integrable_sum (law p) + (fun xy : V × V => fun ω => exteriorLegProduct G P p t w ω xy.1 xy.2) + (fun xy => integrable_exteriorLegProduct G P hP p t ht w xy.1 xy.2) + (fun xy ω => exteriorLegProduct_nonneg G P p t w ω xy.1 xy.2) + (hae.mono (fun _ h => h.1)) hi + exact ⟨hs,he.trans (integral_congr_ae (hae.mono (fun _ h => h.2)))⟩ + +end TotalExteriorLegs +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SummableDerivativeTerm +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +omit [Nonempty V] in +theorem integral_corridorDerivativeTerm_le (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) + {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) (x y : V) : + (∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * + deformedConnection G P p k t Set.univ ω x y ∂law p) ≤ + w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + + twoPoint G p x w.endpoint * twoPoint G p w.base y) := by + apply le_trans (integral_mono (integrable_corridorDerivativeTerm G P hP p k t ht Set.univ x y w) + (integrable_corridorPenaltyTerm G P p Set.univ x y w) (fun ω => + mul_le_of_le_one_right (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) + (deformedConnection_le_one G P hP p k t ht Set.univ ω x y))) + exact integral_corridorPenaltyTerm_le G hG hloc P hP p hp0 hp1 x y w + +theorem summable_twoPoint_pairs (G : BondGraph V E) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) (p : unitInterval) + (hp : p < pc G) (u v : V) : + Summable (fun xy : V × V => twoPoint G p xy.1 u * twoPoint G p v xy.2) := by + have hs : Summable (fun x => twoPoint G p x u) := by + simpa only [twoPoint_symm G p _ u] using summable_twoPoint_subcritical G hloc hqt p hp u + exact hs.mul_of_nonneg (summable_twoPoint_subcritical G hloc hqt p hp v) + (fun x => twoPoint_nonneg G p x u) (fun y => twoPoint_nonneg G p v y) + +omit [Nonempty V] [Countable V] [Countable E] in + theorem integral_corridorDerivativeTerm_nonneg (G : BondGraph V E) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) + (t : ℝ) (w : RawCorridor G k) (x y : V) : + 0 ≤ ∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w * + deformedConnection G P p k t Set.univ ω x y ∂law p := + integral_nonneg (fun ω => mul_nonneg (corridorPenaltyTerm_nonneg G P hP p Set.univ ω x y w) + (deformedConnection_nonneg G P p k t Set.univ ω x y)) + +theorem summable_corridorDerivativeTerm_pairs (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + {k : ℕ} (t : ℝ) (ht : 0 ≤ t) (w : RawCorridor G k) : + Summable (fun xy : V × V => ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * + deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p) := by + have hs : Summable (fun xy : V × V => w.probability P * + (twoPoint G p xy.1 w.base * twoPoint G p w.endpoint xy.2 + + twoPoint G p xy.1 w.endpoint * twoPoint G p w.base xy.2)) := + ((summable_twoPoint_pairs G hloc hqt p hp w.base w.endpoint).add + (summable_twoPoint_pairs G hloc hqt p hp w.endpoint w.base)).mul_left (w.probability P) + exact Summable.of_nonneg_of_le + (fun (xy : V × V) => integral_corridorDerivativeTerm_nonneg G P hP p k t w xy.1 xy.2) + (fun (xy : V × V) => integral_corridorDerivativeTerm_le G hG hloc P hP p hp0 + ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) t ht w xy.1 xy.2) hs + +end SummableDerivativeTerm +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SingleTemplateDecrease +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem calibrated_derivative_template_lower (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) : + w.probability P * Real.exp (-t*c) * + (∫ ω, (if ¬Conn G (w.exterior ω) w.base w.endpoint then + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.base * + deformedClusterMass G P p k t (w.interior:Set V)ᶜ ω w.endpoint else 0) ∂law p) ≤ + ∑' xy : V × V, ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * + deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p := by + obtain ⟨hs,he⟩ := exteriorLegProduct_integral_sum G hloc hqt P hP p hp t ht w + have hh := (hs.mul_left (w.probability P * Real.exp (-t*c))).tsum_le_tsum + (fun (xy : V × V) => calibrated_derivative_kernel_lower G hG hloc P hP p hp0 + ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) k w hlen c hc t ht xy.1 xy.2) + (summable_corridorDerivativeTerm_pairs G hG hloc hqt P hP p hp0 hp t ht w) + rwa [tsum_mul_left,he] at hh + + + +theorem calibrated_derivative_template_row_lower (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) + (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (k : ℕ) (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (c : ℝ) (hc : (∑ e ∈ (w.retained_finite hG).toFinset, ∑' r : RawCorridor G k, + if e ∈ r.retained then r.weight P p else 0) ≤ c) + (t : ℝ) (ht : 0 ≤ t) : + w.probability P * Real.exp (-t*c) * + (deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.base * + deformedSusceptibility G P p k t (w.interior:Set V)ᶜ w.endpoint - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2*(matrixCoeff (T^3) w.base w.endpoint).re) ≤ + ∑' xy : V × V, ∫ ω, corridorPenaltyTerm G P p Set.univ ω xy.1 xy.2 w * + deformedConnection G P p k t Set.univ ω xy.1 xy.2 ∂law p := by + have hm := deformed_distinct_correlation_uniform G hloc hqt d hd P hP hpcrit p hp hpnear T hT + k t ht (w.interior:Set V)ᶜ w.base w.endpoint + exact (mul_le_mul_of_nonneg_left hm (mul_nonneg (w.2.2.mass_nonneg P hP) (Real.exp_pos _).le)).trans + (calibrated_derivative_template_lower G hG hloc hqt P hP p ((half_pos hpcrit).trans_le hpnear) + hp k w hlen c hc t ht) + +end SingleTemplateDecrease +end Percolation + + +namespace Percolation +universe u u' v +section ErasureNaturality +attribute [local instance] Classical.propDecidable Classical.decEq +variable {V : Type u} {V' : Type u'} {H : SimpleGraph V} {H' : SimpleGraph V'} + +theorem walk_map_dropUntil (f : H →g H') (hf : Function.Injective f) + {x y : V} (w : H.Walk x y) (z : V) (hz : z ∈ w.support) : + (w.dropUntil z hz).map f = (w.map f).dropUntil (f z) + (by simpa only [SimpleGraph.Walk.support_map] using List.mem_map_of_mem hz) := by + induction w with + | @nil x => + have he : z = x := by simpa using hz + subst z + rfl + | @cons x a y h w ih => + by_cases he : x = z + · subst z + simp only [SimpleGraph.Walk.dropUntil_first] + · have hfe : f x ≠ f z := fun h => he (hf h) + simp only [SimpleGraph.Walk.dropUntil,he,hfe,SimpleGraph.Walk.map_cons] + exact ih _ + + + +theorem walk_map_bypass (f : H →g H') (hf : Function.Injective f) + {x y : V} (w : H.Walk x y) : w.bypass.map f = (w.map f).bypass := by + induction w with + | nil => rfl + | @cons x a y h w ih => + have hm : f x ∈ (w.map f).bypass.support ↔ x ∈ w.bypass.support := by + rw [←ih,SimpleGraph.Walk.support_map] + exact List.mem_map_of_injective hf + by_cases hx : x ∈ w.bypass.support + · have hfx := hm.mpr hx + simp only [SimpleGraph.Walk.bypass,SimpleGraph.Walk.map_cons,dite_eq_left hx,dite_eq_left hfx] + simp only [walk_map_dropUntil f hf,ih] + · have hfx := mt hm.mp hx + simp only [SimpleGraph.Walk.bypass,SimpleGraph.Walk.map_cons,dite_eq_right hx,dite_eq_right hfx,ih] + +namespace HoldingWalk + +def map (f : H →g H') : {k : ℕ} → {x y : V} → HoldingWalk H k x y → HoldingWalk H' k (f x) (f y) + | _,_,_,.nil _ => .nil _ + | _,_,_,.hold w => .hold (w.map f) + | _,_,_,.step h w => .step (f.map_rel h) (w.map f) + +theorem map_vertices (f : H →g H') {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + (w.map f).vertices = w.vertices.map f := by + induction w with + | nil => rfl + | hold w ih => simp only [map,vertices,List.map_cons,ih] + | step h w ih => simp only [map,vertices,List.map_cons,ih] + +theorem map_withoutHolds (f : H →g H') {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + (w.map f).withoutHolds = w.withoutHolds.map f := by + induction w with + | nil => rfl + | hold w ih => exact ih + | step h w ih => simp only [map,withoutHolds,SimpleGraph.Walk.map_cons,ih] + +theorem map_erase (f : H →g H') (hf : Function.Injective f) + {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : + (w.map f).erase = w.erase.map f := by + simp only [erase,map_withoutHolds,SimpleGraph.Walk.reverse_map, + ←walk_map_bypass f hf] + +end HoldingWalk +end ErasureNaturality +end Percolation + + +namespace Percolation +universe u u' u'' v +section RawWalkMaps +attribute [local instance] Classical.propDecidable Classical.decEq +variable {V : Type u} {V' : Type u'} {V'' : Type u''} + {H : SimpleGraph V} {H' : SimpleGraph V'} {H'' : SimpleGraph V''} +namespace HoldingWalk + +theorem map_map (f : H →g H') (g : H' →g H'') + {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : (w.map f).map g = w.map (g.comp f) := by + induction w with + | nil => rfl + | hold w ih => exact congrArg hold ih + | step h w ih => exact congrArg (step _) ih + +theorem map_id {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.map ((SimpleGraph.Hom.id : H →g H)) = w := by + induction w with + | nil => rfl + | hold w ih => exact congrArg hold ih + | step h w ih => exact congrArg (step _) ih + +theorem mass_map (f : H →g H') (P : V → V → ℝ) (Q : V' → V' → ℝ) + (hPQ : ∀ x y, Q (f x) (f y) = P x y) + {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : (w.map f).mass Q = w.mass P := by + induction w with + | nil => rfl + | hold w ih => simp only [map,mass,hPQ,ih] + | step h w ih => simp only [map,mass,hPQ,ih] +end HoldingWalk + +def rawWalkMap (f : H →g H') (k : ℕ) (w : Σ x y, HoldingWalk H k x y) : + Σ x y, HoldingWalk H' k x y := ⟨f w.1,f w.2.1,w.2.2.map f⟩ + +theorem rawWalkMap_comp (f : H →g H') (g : H' →g H'') (k : ℕ) + (w : Σ x y, HoldingWalk H k x y) : rawWalkMap g k (rawWalkMap f k w) = rawWalkMap (g.comp f) k w := by + cases w with + | mk x w => + cases w with + | mk y w => + simp only [rawWalkMap,HoldingWalk.map_map] + rfl + +theorem rawWalkMap_id (k : ℕ) (w : Σ x y, HoldingWalk H k x y) : + rawWalkMap ((SimpleGraph.Hom.id : H →g H)) k w = w := by + cases w with + | mk x w => + cases w with + | mk y w => + simp only [rawWalkMap,HoldingWalk.map_id] + rfl + +def rawWalkEquiv (f : H ≃g H') (k : ℕ) : + (Σ x y, HoldingWalk H k x y) ≃ (Σ x y, HoldingWalk H' k x y) where + toFun := rawWalkMap f.toHom k + invFun := rawWalkMap f.symm.toHom k + left_inv w := by + rw [rawWalkMap_comp] + have he : f.symm.toHom.comp f.toHom = (SimpleGraph.Hom.id : H →g H) := by + ext x + exact f.symm_apply_apply x + rw [he,rawWalkMap_id] + right_inv w := by + rw [rawWalkMap_comp] + have he : f.toHom.comp f.symm.toHom = (SimpleGraph.Hom.id : H' →g H') := by + ext x + exact f.apply_symm_apply x + rw [he,rawWalkMap_id] + +end RawWalkMaps +section GraphAutWalks +attribute [local instance] Classical.propDecidable Classical.decEq +variable {V : Type u} {E : Type v} + +theorem openSimpleGraph_univ_adj (G : BondGraph V E) (x y : V) : + (openSimpleGraph G Set.univ).Adj x y ↔ x ≠ y ∧ Adj G x y := by + simp only [openSimpleGraph,Adj,Set.mem_univ,true_and] + +def autSimpleGraph (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : + openSimpleGraph G Set.univ ≃g openSimpleGraph G Set.univ where + toEquiv := a + map_rel_iff' := by + intro x y + simp only [openSimpleGraph_univ_adj,a.injective.ne_iff] + exact and_congr_right (fun _ => ⟨fun h => by simpa using adj_aut G (isAut_symm G hab) h, + adj_aut G hab⟩) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} +def autEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : RawCorridor G k ≃ RawCorridor G k := + rawWalkEquiv (autSimpleGraph G hab) k + +theorem aut_path {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).path = w.path.map (autSimpleGraph G hab).toHom := + w.2.2.map_erase _ a.injective + +theorem aut_path_length {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).path.length = w.path.length := by + have hh := congrArg (fun q => q.length) (aut_path hab w) + exact hh.trans (SimpleGraph.Walk.length_map _ _) + +end RawCorridor +end GraphAutWalks +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TemplateCovariance +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem aut_base {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).base = a w.base := rfl + +theorem aut_endpoint {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).endpoint = a w.endpoint := rfl + +theorem aut_support {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).path.support = w.path.support.map a := by + exact (congrArg (fun q => q.support) (aut_path hab w)).trans + (SimpleGraph.Walk.support_map _ _) + +theorem aut_edges {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).path.edges = w.path.edges.map (Sym2.map a) := by + exact (congrArg (fun q => q.edges) (aut_path hab w)).trans + (SimpleGraph.Walk.edges_map _ _) + +theorem aut_interior {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (z : V) : + a z ∈ (autEquiv hab w).interior ↔ z ∈ w.interior := by + simp only [interior,Finset.mem_sdiff,List.mem_toFinset] + rw [aut_support hab w] + simp only [aut_base,aut_endpoint,Finset.mem_insert,Finset.mem_singleton, + List.mem_map_of_injective a.injective,a.injective.eq_iff] + +theorem aut_retained {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (e : E) : + b e ∈ (autEquiv hab w).retained ↔ e ∈ w.retained := by + simp only [retained,Set.mem_ofPred_eq,aut_edges hab w,hab e] + exact List.mem_map_of_injective (Sym2.map.injective a.injective) + +theorem aut_blockers {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) (e : E) : + b e ∈ (autEquiv hab w).blockers ↔ e ∈ w.blockers := by + simp only [blockers,Set.mem_sdiff,Set.mem_ofPred_eq,aut_retained] + apply and_congr_left + intro _ + constructor + · rintro ⟨z,hz,he⟩ + rw [hab e] at he + obtain ⟨y,hy,rfl⟩ := Sym2.mem_map.mp he + exact ⟨y,(aut_interior hab w y).mp hz,hy⟩ + · rintro ⟨z,hz,he⟩ + refine ⟨a z,(aut_interior hab w z).mpr hz,?_⟩ + rw [hab e] + exact Sym2.mem_map.mpr ⟨z,he,rfl⟩ + +theorem aut_blockers_ncard {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (w : RawCorridor G k) : + (autEquiv hab w).blockers.ncard = w.blockers.ncard := by + have he : w.blockers = b ⁻¹' (autEquiv hab w).blockers := by + ext e + exact (aut_blockers hab w e).symm + rw [he,Set.ncard_preimage_of_injective_subset_range b.injective] + exact fun e _ => b.surjective e + +theorem aut_probability {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) (w : RawCorridor G k) : + (autEquiv hab w).probability P = w.probability P := + w.2.2.mass_map (autSimpleGraph G hab).toHom P P hP + +theorem aut_weight {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (P : V → V → ℝ) (hP : ∀ x y, P (a x) (a y) = P x y) (p : ℝ) (w : RawCorridor G k) : + (autEquiv hab w).weight P p = w.weight P p := by + simp only [weight,aut_probability hab P hP,aut_path_length,aut_blockers_ncard] + +end RawCorridor +end TemplateCovariance +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/ClusterProducts.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/ClusterProducts.lean index bc040b5b14e2bf92200a63bed18acc26315d1082..349943265271290de2186f851e473dc90229510c 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/ClusterProducts.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/ClusterProducts.lean @@ -1,1223 +1,1223 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.Corridors - -namespace OAI - -/-! Cluster Products for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SmallDeformationOperators -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - - - -theorem exists_deformedOperator_small_change (G : BondGraph V E) - (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) - (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) : - ∃ B : Hilbert V →L[ℂ] Hilbert V, - (∀ x y, matrixCoeff B x y = (deformedKernel G (walkKernel G hloc a) p k t Set.univ x y : ℂ)) ∧ - ‖B‖ ≤ ‖A‖ ∧ ‖A-B‖ ≤ 2*t*‖P‖^k*‖A‖^2 ∧ ‖A‖-2*t*‖P‖^k*‖A‖^2 ≤ ‖B‖ := by - let K := deformedKernel G (walkKernel G hloc a) p k t Set.univ - have hKn (x y : V) : 0 ≤ K x y := deformedKernel_nonneg G _ p k t _ x y - have hb (x y : V) := deformedKernel_change_bound G hG hloc p hp hp₁ a P hpos hPs hP A hA hAs hAT k t ht x y - obtain ⟨B,hBn,hBK⟩ := exists_operator_of_matrix_domination (twoPoint G p) K (twoPoint_nonneg G p) - (fun x y => by rw [abs_of_nonneg (hKn x y)]; exact sub_nonneg.mp (hb x y).1) A hAT - have hBK' (x y : V) : matrixCoeff B x y = (K x y : ℂ) := hBK x y - let C := A*(P^k*A) - have hCn : PositiveRealMatrix C := hA.mul ((hpos.pow k).mul hA) - have hscale (x y : V) : matrixCoeff (((2*t:ℝ):ℂ) • C) x y = - (2*t*(matrixCoeff C x y).re : ℝ) := by - change ((2*t:ℝ):ℂ)*matrixCoeff C x y = _ - rw [hCn.real] - simp only [Complex.ofReal_re,Complex.ofReal_mul] - obtain ⟨D,hDn,hDK⟩ := exists_operator_of_matrix_domination - (fun x y => 2*t*(matrixCoeff C x y).re) (fun x y => twoPoint G p x y - K x y) - (fun x y => mul_nonneg (mul_nonneg (by norm_num) ht) (hCn x y).2) - (fun x y => by rw [abs_of_nonneg (hb x y).1]; exact (hb x y).2) - (((2*t:ℝ):ℂ) • C) hscale - have he : D = A-B := kernel_extension_unique hDK (by - intro x y - change matrixCoeff A x y - matrixCoeff B x y = _ - rw [hAT,hBK',Complex.ofReal_sub]) - rw [he] at hDn - have hCnorm : ‖C‖ ≤ ‖A‖*‖P‖^k*‖A‖ := by - calc - _ ≤ ‖A‖*‖P^k*A‖ := norm_mul_le _ _ - _ ≤ ‖A‖*(‖P^k‖*‖A‖) := mul_le_mul_of_nonneg_left (norm_mul_le _ _) (norm_nonneg _) - _ ≤ ‖A‖*(‖P‖^k*‖A‖) := by - gcongr - cases k with - | zero => - simp only [pow_zero] - have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext f; rfl - rw [he] - exact ContinuousLinearMap.norm_id_le - | succ j => exact norm_pow_le' P (Nat.succ_pos j) - _ = _ := by ring - have hd : ‖A-B‖ ≤ 2*t*‖P‖^k*‖A‖^2 := by - calc - _ ≤ ‖((2*t:ℝ):ℂ) • C‖ := hDn - _ = 2*t*‖C‖ := by rw [norm_smul,Complex.norm_of_nonneg (mul_nonneg (by norm_num) ht)] - _ ≤ 2*t*(‖A‖*‖P‖^k*‖A‖) := mul_le_mul_of_nonneg_left hCnorm (mul_nonneg (by norm_num) ht) - _ = _ := by ring - refine ⟨B,hBK,hBn,hd,?_⟩ - have hh : ‖A‖ ≤ ‖A-B‖+‖B‖ := by simpa only [sub_add_cancel] using norm_add_le (A-B) B - linarith - -end SmallDeformationOperators -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeletionGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -def closedBondNeighborhood (G : BondGraph V E) (A : Set V) : Set V := - {z | z ∈ A ∨ ∃ e, z ∈ G e ∧ ∃ a ∈ G e, a ∈ A} - -def SimpleVisit (G : BondGraph V E) (S : Set E) (A : Set V) (x y : V) : Prop := - ∃ q : (openSimpleGraph G S).Walk x y, q.IsPath ∧ ∃ z ∈ q.support, z ∈ A - -theorem SimpleVisit.mono (G : BondGraph V E) {S T : Set E} {A B : Set V} - (hST : S ⊆ T) (hAB : A ⊆ B) {x y : V} (h : SimpleVisit G S A x y) : - SimpleVisit G T B x y := by - obtain ⟨q,hq,z,hz,ha⟩ := h - have hg : openSimpleGraph G S ≤ openSimpleGraph G T := by - rintro a b ⟨hne,e,he,hGe⟩ - exact ⟨hne,e,hST he,hGe⟩ - exact ⟨q.mapLe hg,hq.mapLe hg,z,by simpa only [SimpleGraph.Walk.support_mapLe_eq_support] using hz,hAB ha⟩ - -theorem walk_conn_restrict_vertices (G : BondGraph V E) (S : Set E) {x y : V} - (q : (openSimpleGraph G S).Walk x y) (D : Set V) - (hD : ∀ z ∈ q.support, z ∈ D) : Conn G (S ∩ internalEdges G D) x y := by - obtain ⟨l,hl,hm,ho⟩ := walk_lift_bonds G S q - apply hl.conn - intro e he - refine ⟨ho e he,?_⟩ - intro z hz - exact hD z (SimpleGraph.Walk.mem_support_of_mem_edges (hm ▸ List.mem_map_of_mem he) hz) - -theorem conn_restrict_of_no_simpleVisit (G : BondGraph V E) (S : Set E) - (A : Set V) (x y : V) (hc : Conn G S x y) (hn : ¬SimpleVisit G S A x y) : - Conn G (S ∩ internalEdges G Aᶜ) x y := by - obtain ⟨q⟩ := (conn_iff_reachable G S x y).mp hc - exact walk_conn_restrict_vertices G S q.bypass Aᶜ - (fun z hz ha => hn ⟨q.bypass,q.bypass_isPath,z,hz,ha⟩) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem counted_support_subset_walk (w : RawCorridor G k) (D : Set V) (ω : Set E) - (x y : V) (hc : w.counted D ω x y) - (q : (openSimpleGraph G (ω ∩ internalEdges G D)).Walk x y) : - ∀ z ∈ w.path.support, z ∈ q.support := by - intro z hz - have hl : 0 < w.path.length := by have := hc.1; omega - obtain ⟨s,hs,hzs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil - (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp hz - obtain ⟨e,he,hGe⟩ := w.edge_has_label s hs - exact SimpleGraph.Walk.mem_support_of_mem_edges - (pivotal_image_mem_edges G _ q e (hc.2.2.2.1 e he).2) (hGe.symm ▸ hzs) - -end RawCorridor - - - -theorem simplePath_disjoint_at (G : BondGraph V E) (S : Set E) {x y z : V} - (q : (openSimpleGraph G S).Walk x y) (hq : q.IsPath) (hz : z ∈ q.support) : - S ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} := by - obtain ⟨a,ha,hea,hoa⟩ := walk_lift_bonds G S (q.takeUntil z hz) - obtain ⟨b,hb,heb,hob⟩ := walk_lift_bonds G S (q.dropUntil z hz) - refine ⟨a.toFinset,b.toFinset,?_,?_,?_,?_,?_⟩ - · intro e he; exact hoa e (List.mem_toFinset.mp he) - · intro e he; exact hob e (List.mem_toFinset.mp he) - · apply Finset.disjoint_left.mpr - intro e hae hbe - exact List.disjoint_left.mp (hq.isTrail.disjoint_edges_takeUntil_dropUntil hz) - (hea ▸ List.mem_map_of_mem (List.mem_toFinset.mp hae)) - (heb ▸ List.mem_map_of_mem (List.mem_toFinset.mp hbe)) - · exact ha.conn (fun e he => List.mem_toFinset.mpr he) - · exact hb.conn (fun e he => List.mem_toFinset.mpr he) - -end DeletionGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeletionCounted -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem conn_delete_of_no_visit (G : BondGraph V E) (ω : Set E) (D A : Set V) - (x y : V) (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) - (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : - Conn G (S ∩ internalEdges G (D \ A)) x y := by - have hno : ¬SimpleVisit G S A x y := fun h => hn (h.mono G hS (fun _ => Or.inl)) - have h := conn_restrict_of_no_simpleVisit G S A x y hc hno - apply conn_mono G ?_ h - rintro e ⟨he,ha⟩ - exact ⟨he,fun z hz => ⟨(hS he).2 z hz,ha z hz⟩⟩ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem counted_before_deletion_of_no_visit (w : RawCorridor G k) - (D A : Set V) (ω : Set E) (x y : V) - (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) - (hc : w.counted (D \ A) ω x y) : w.counted D ω x y := by - have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := - Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) - apply (w.counted_iff D ω x y).mpr - refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ - · intro e he - refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ - intro hbad - have hd := conn_delete_of_no_visit G ω D A x y hn - ((ω ∩ internalEdges G D) \ {e}) Set.sdiff_subset hbad - apply (hc.2.2.2.1 e he).2 - apply conn_mono G ?_ hd - rintro f ⟨⟨⟨hfω,hfD⟩,hfne⟩,hfnew⟩ - exact ⟨⟨hfω,hfnew⟩,hfne⟩ - · apply Set.disjoint_left.mpr - intro e he ho - have henew : e ∉ internalEdges G (D \ A) := fun he' => - Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,he'⟩ - obtain ⟨a,ha,hna⟩ : ∃ a ∈ G e, a ∉ D \ A := by - change ¬(∀ a ∈ G e, a ∈ D \ A) at henew - push Not at henew - exact henew - have haA : a ∈ A := by - by_contra ha' - exact hna ⟨ho.2 a ha,ha'⟩ - obtain ⟨z,hzi,hze⟩ := he.1 - obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 - have hz : z ∈ q.bypass.support := w.counted_support_subset_walk (D \ A) ω x y hc q.bypass z - (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1) - have hv : SimpleVisit G (ω ∩ internalEdges G (D \ A)) (closedBondNeighborhood G A) x y := - ⟨q.bypass,q.bypass_isPath,z,hz,Or.inr ⟨e,hze,a,ha,haA⟩⟩ - exact hn (hv.mono G hs (Set.Subset.refl _)) - -end RawCorridor -end DeletionCounted -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeletionWeightedLoss -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem deformedConnection_no_visit (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (ω : Set E) (x y : V) - (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) : - deformedConnection G P p k t D ω x y ≤ deformedConnection G P p k t (D \ A) ω x y := by - by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y - · obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2 - have hx : x ∉ A := fun ha => hn ⟨q.bypass,q.bypass_isPath,x,q.bypass.start_mem_support,Or.inl ha⟩ - have hy : y ∉ A := fun ha => hn ⟨q.bypass,q.bypass_isPath,y,q.bypass.end_mem_support,Or.inl ha⟩ - have hc' : x ∈ D \ A ∧ y ∈ D \ A ∧ Conn G (ω ∩ internalEdges G (D \ A)) x y := by - refine ⟨⟨hc.1,hx⟩,⟨hc.2.1,hy⟩,?_⟩ - apply conn_mono G ?_ (conn_delete_of_no_visit G ω D A x y hn _ (Set.Subset.refl _) hc.2.2) - rintro e ⟨⟨heω,heD⟩,henew⟩ - exact ⟨heω,henew⟩ - simp only [deformedConnection,hc,hc'] - apply Real.exp_le_exp.mpr - apply mul_le_mul_of_nonpos_left ?_ (neg_nonpos.mpr ht) - apply (corridorPenalty_summable G hloc P p k (D \ A) ω x y).tsum_le_tsum ?_ - (corridorPenalty_summable G hloc P p k D ω x y) - intro w - by_cases hw : w.counted (D \ A) ω x y - · have hw' := w.counted_before_deletion_of_no_visit D A ω x y hn hw - simp only [corridorPenaltyTerm,hw,hw',ite_true,le_refl] - · simpa only [corridorPenaltyTerm,hw,ite_false] using corridorPenaltyTerm_nonneg G P hP p D ω x y w - · simpa only [deformedConnection,hc,ite_false] using deformedConnection_nonneg G P p k t (D \ A) ω x y - - - -theorem deformedConnection_deletion_pointwise (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (ω : Set E) (x y : V) : - deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ≤ - if ∃ z ∈ closedBondNeighborhood G A, - ω ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} then 1 else 0 := by - split_ifs with h - · linarith [deformedConnection_le_one G P hP p k t ht D ω x y, - deformedConnection_nonneg G P p k t (D \ A) ω x y] - · apply sub_nonpos.mpr - apply deformedConnection_no_visit G hloc P hP p k t ht D A ω x y - rintro ⟨q,hq,z,hz,hza⟩ - apply h - exact ⟨z,hza,disjointOccurrence_upper _ _ Set.inter_subset_left (simplePath_disjoint_at G _ q hq hz)⟩ - -end DeletionWeightedLoss -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeletionKernelBound -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - - - -theorem deformedKernel_deletion_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (x y : V) - (hs : Summable (fun z : closedBondNeighborhood G A => twoPoint G p x z * twoPoint G p z y)) : - deformedKernel G P p k t D x y - deformedKernel G P p k t (D \ A) x y ≤ - ∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y := by - let B := fun z : closedBondNeighborhood G A => - DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} - let U := ⋃ z, B z - have hBm (z : closedBondNeighborhood G A) : MeasurableSet (B z) := - measurableSet_finiteWitness _ (disjointOccurrence_upper _ _) (finiteWitness_disjointOccurrence _ _) - have hUm : MeasurableSet U := MeasurableSet.iUnion hBm - have hBn (z : closedBondNeighborhood G A) : 0 ≤ twoPoint G p x z * twoPoint G p z y := - mul_nonneg (twoPoint_nonneg G p x z) (twoPoint_nonneg G p z y) - have hBK (z : closedBondNeighborhood G A) : law p (B z) ≤ ENNReal.ofReal (twoPoint G p x z * twoPoint G p z y) := by - rw [←ENNReal.ofReal_toReal (measure_ne_top (law p) (B z))] - exact ENNReal.ofReal_le_ofReal (bk p _ _ (fun _ _ h hc => conn_mono G h hc) - (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x z) (finiteWitness_conn G z y)) - have hU : (law p).real U ≤ ∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y := by - have hh : law p U ≤ ENNReal.ofReal (∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y) := by - calc - _ ≤ ∑' z, law p (B z) := measure_iUnion_le B - _ ≤ ∑' z : closedBondNeighborhood G A, ENNReal.ofReal (twoPoint G p x z * twoPoint G p z y) := ENNReal.tsum_le_tsum hBK - _ = _ := (ENNReal.ofReal_tsum_of_nonneg hBn hs).symm - exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hh).trans_eq (ENNReal.toReal_ofReal (tsum_nonneg hBn)) - have hUi : Integrable (U.indicator (fun _ : Set E => (1:ℝ))) (law p) := (integrable_const _).indicator hUm - have hpoint (ω : Set E) : deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ≤ - U.indicator (fun _ : Set E => (1:ℝ)) ω := by - have he : ω ∈ U ↔ ∃ z ∈ closedBondNeighborhood G A, ω ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} := by - simp [U,B] - simpa only [Set.indicator_apply,he] using deformedConnection_deletion_pointwise G hloc P hP p k t ht D A ω x y - have hi := integrable_deformedConnection G P hP p k t ht D x y - have hi' := integrable_deformedConnection G P hP p k t ht (D \ A) x y - calc - _ = ∫ ω, deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ∂law p := (integral_sub hi hi').symm - _ ≤ ∫ ω, U.indicator (fun _ : Set E => (1:ℝ)) ω ∂law p := integral_mono (hi.sub hi') hUi hpoint - _ = (law p).real U := integral_indicator_one hUm - _ ≤ _ := hU - -end DeletionKernelBound -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeformedSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def deformedSusceptibility (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : ℝ := - ∑' y, deformedKernel G P p k t D x y - -theorem deformedKernel_le_twoPoint [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - deformedKernel G P p k t D x y ≤ twoPoint G p x y := by - rw [←deformedKernel_zero G P p k x y] - apply integral_mono (integrable_deformedConnection G P hP p k t ht D x y) - (integrable_deformedConnection G P hP p k 0 (le_refl _) Set.univ x y) - intro ω - exact (deformedConnection_mono G hloc P hP p k t ht (Set.subset_univ D) - (Set.Subset.refl _) x y).trans (sub_nonneg.mp (deformedConnection_change G P hP p k t ht Set.univ ω x y).1) - -theorem summable_deformedKernel [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : - Summable (deformedKernel G P p k t D x) := - Summable.of_nonneg_of_le (deformedKernel_nonneg G P p k t D x) - (deformedKernel_le_twoPoint G hloc P hP p k t ht D x) - (summable_twoPoint_subcritical G hloc hqt p hp x) - -theorem deformedSusceptibility_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : - deformedSusceptibility G P p k t D x ≤ susceptibility G p x := - (summable_deformedKernel G hloc hqt P hP p hp k t ht D x).tsum_le_tsum - (deformedKernel_le_twoPoint G hloc P hP p k t ht D x) - (summable_twoPoint_subcritical G hloc hqt p hp x) - -end DeformedSusceptibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeletionSusceptibilityEstimate -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -theorem summable_twoPoint_restricted_pair (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x : V) (N : Set V) : - Summable (fun zy : N×V => twoPoint G p x zy.1 * twoPoint G p zy.1 zy.2) := by - apply (summable_twoPoint_pair G hloc hqt p hp x).comp_injective (i := fun zy : N×V => (zy.1.val,zy.2)) - intro a b hab - exact Prod.ext (Subtype.ext (congrArg Prod.fst hab)) (congrArg (fun z : V×V => z.2) hab) - -theorem twoPoint_double_restricted_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x : V) (N : Set V) : - (∑' y : V, ∑' z : N, twoPoint G p x z * twoPoint G p z y) ≤ - maxSusceptibility G p * (∑' z : N, twoPoint G p x z) := by - have hpairs := summable_twoPoint_restricted_pair G hloc hqt p hp x N - have hcomm : (∑' y : V, ∑' z : N, twoPoint G p x z * twoPoint G p z y) = - ∑' z : N, twoPoint G p x z * susceptibility G p z := by - calc - _ = ∑' z : N, ∑' y : V, twoPoint G p x z * twoPoint G p z y := hpairs.tsum_comm - _ = _ := by simp only [tsum_mul_left, susceptibility] - have hprod : Summable (fun z : N => twoPoint G p x z * susceptibility G p z) := by - simpa only [tsum_mul_left, susceptibility] using hpairs.prod - rw [hcomm] - calc - _ ≤ ∑' z : N, twoPoint G p x z * maxSusceptibility G p := - hprod.tsum_le_tsum - (fun z => mul_le_mul_of_nonneg_left (susceptibility_le_max G hloc hqt p hp z) (twoPoint_nonneg G p x z)) - ((summable_twoPoint_subcritical G hloc hqt p hp x).subtype N |>.mul_right _) - _ = _ := by rw [tsum_mul_right,mul_comm] - - - -theorem deformedSusceptibility_deletion (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D A : Set V) (x : V) : - deformedSusceptibility G P p k t D x - - maxSusceptibility G p * (∑' z : closedBondNeighborhood G A, twoPoint G p x z) ≤ - deformedSusceptibility G P p k t (D \ A) x := by - let N := closedBondNeighborhood G A - have hpairs := summable_twoPoint_restricted_pair G hloc hqt p hp x N - have hdiag (y : V) := hpairs.prod_symm.prod_factor y - have hi := summable_deformedKernel G hloc hqt P hP p hp k t ht D x - have hi' := summable_deformedKernel G hloc hqt P hP p hp k t ht (D \ A) x - have hb := (hi.sub hi').tsum_le_tsum - (fun y => deformedKernel_deletion_bound G hloc P hP p k t ht D A x y (hdiag y)) hpairs.prod_symm.prod - rw [hi.tsum_sub hi'] at hb - change deformedSusceptibility G P p k t D x - deformedSusceptibility G P p k t (D \ A) x ≤ _ at hb - have herr := twoPoint_double_restricted_bound G hloc hqt p hp x N - linarith - -end DeletionSusceptibilityEstimate -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExteriorCorridorGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem conn_of_open_incident (G : BondGraph V E) (ω : Set E) (e : E) - (he : e ∈ ω) (a b : V) (ha : a ∈ G e) (hb : b ∈ G e) : Conn G ω a b := by - obtain ⟨c,d,hcd⟩ : ∃ c d, G e = s(c,d) := by - obtain ⟨⟨c,d⟩,hh⟩ := Quot.exists_rep (G e) - exact ⟨c,d,hh.symm⟩ - rw [hcd,Sym2.mem_iff] at ha hb - rcases ha with rfl | rfl <;> rcases hb with rfl | rfl - · exact conn_refl G ω _ - · exact .single ⟨e,he,hcd⟩ - · exact conn_symm G ω (.single ⟨e,he,hcd⟩) - · exact conn_refl G ω _ - - - -theorem conn_restrict_away_from_cluster (G : BondGraph V E) (ω S : Set E) - (hS : S ⊆ ω) (u x y : V) (hx : x ∉ cluster G ω u) (hc : Conn G S x y) : - Conn G (S ∩ internalEdges G (cluster G ω u)ᶜ) x y := by - apply conn_restrict_of_no_simpleVisit G S (cluster G ω u) x y hc - rintro ⟨q,_,z,hz,hzu⟩ - have hxz : Conn G ω x z := conn_mono G hS - ((conn_iff_reachable G S x z).mpr ⟨q.takeUntil z hz⟩) - exact hx (hzu.trans (conn_symm G ω hxz)) - -theorem conn_delete_cluster (G : BondGraph V E) (D : Set V) (ω : Set E) - (u x y : V) (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) - (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : - Conn G (S ∩ internalEdges G (D \ cluster G (ω ∩ internalEdges G D) u)) x y := by - apply conn_mono G ?_ (conn_restrict_away_from_cluster G _ S hS u x y hx hc) - rintro e ⟨he,heA⟩ - exact ⟨he,fun z hz => ⟨(hS he).2 z hz,heA z hz⟩⟩ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem counted_delete_other_cluster (w : RawCorridor G k) (D : Set V) (ω : Set E) - (u x y : V) (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : - w.counted (D \ cluster G (ω ∩ internalEdges G D) u) ω x y ↔ w.counted D ω x y := by - let A := cluster G (ω ∩ internalEdges G D) u - have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := - Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) - constructor - · intro hc - apply (w.counted_iff D ω x y).mpr - refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ - · intro e he - refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ - intro hbad - have hd := conn_delete_cluster G D ω u x y hx - ((ω ∩ internalEdges G D) \ {e}) Set.sdiff_subset hbad - apply (hc.2.2.2.1 e he).2 - apply conn_mono G ?_ hd - rintro f ⟨⟨⟨hfω,hfD⟩,hfne⟩,hfnew⟩ - exact ⟨⟨hfω,hfnew⟩,hfne⟩ - · apply Set.disjoint_left.mpr - intro e he ho - obtain ⟨z,hzi,hze⟩ := he.1 - obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 - have hz : z ∈ q.support := w.counted_support_subset_walk (D \ A) ω x y hc q z - (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1) - have hxz : Conn G (ω ∩ internalEdges G D) x z := conn_mono G hs - ((conn_iff_reachable G _ x z).mpr ⟨q.takeUntil z hz⟩) - have heA : e ∈ internalEdges G (D \ A) := by - intro a ha - refine ⟨ho.2 a ha,?_⟩ - intro hau - have hza := conn_of_open_incident G _ e ho z a hze ha - exact hx (hau.trans (conn_symm G _ (hxz.trans hza))) - exact Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,heA⟩ - · intro hc - have hnew := conn_delete_cluster G D ω u x y hx _ (Set.Subset.refl _) hc.2.2.1 - have hc' : Conn G (ω ∩ internalEdges G (D \ A)) x y := by - apply conn_mono G ?_ hnew - rintro e ⟨⟨heω,_⟩,heA⟩ - exact ⟨heω,heA⟩ - exact (w.counted_iff _ ω x y).mpr ⟨hc.1, - corridorCounted_restrict G _ _ Set.sdiff_subset (Set.Subset.refl _) x y hc' hc.2.2⟩ - -end RawCorridor -end ExteriorCorridorGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExteriorWeightedConnections -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem corridorPenalty_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (u x y : V) - (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : - corridorPenalty G P p k (D \ cluster G (ω ∩ internalEdges G D) u) ω x y = - corridorPenalty G P p k D ω x y := by - unfold corridorPenalty - apply tsum_congr - intro w - simp only [corridorPenaltyTerm,w.counted_delete_other_cluster D ω u x y hx] - - - -theorem deformedConnection_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (u x y : V) - (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : - deformedConnection G P p k t (D \ cluster G (ω ∩ internalEdges G D) u) ω x y = - deformedConnection G P p k t D ω x y := by - let A := cluster G (ω ∩ internalEdges G D) u - have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := - Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) - have hg : (x ∈ D \ A ∧ y ∈ D \ A ∧ Conn G (ω ∩ internalEdges G (D \ A)) x y) ↔ - (x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y) := by - constructor - · exact fun h => ⟨h.1.1,h.2.1.1,conn_mono G hs h.2.2⟩ - · rintro ⟨hxD,hyD,hc⟩ - have hy : y ∉ A := fun hy => hx (hy.trans (conn_symm G _ hc)) - refine ⟨⟨hxD,hx⟩,⟨hyD,hy⟩,?_⟩ - apply conn_mono G ?_ (conn_delete_cluster G D ω u x y hx _ (Set.Subset.refl _) hc) - rintro e ⟨⟨heω,_⟩,heA⟩ - exact ⟨heω,heA⟩ - dsimp only [A] at hg - simp only [deformedConnection,hg,corridorPenalty_delete_other_cluster G P p k D ω u x y hx] - -noncomputable def deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : ℝ := - ∑' y, deformedConnection G P p k t D ω x y - -theorem deformedClusterMass_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (u x : V) - (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : - deformedClusterMass G P p k t (D \ cluster G (ω ∩ internalEdges G D) u) ω x = - deformedClusterMass G P p k t D ω x := by - exact tsum_congr (fun y => deformedConnection_delete_other_cluster G P p k t D ω u x y hx) - -theorem deformedConnection_le_conn (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (ω : Set E) (x y : V) : deformedConnection G P p k t D ω x y ≤ - if Conn G ω x y then 1 else 0 := by - by_cases hc : Conn G ω x y - · simpa only [hc,ite_true] using deformedConnection_le_one G P hP p k t ht D ω x y - · have hn : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hc (conn_mono G Set.inter_subset_left h) - simp only [deformedConnection,hn,hc,and_false,ite_false,le_refl] - -theorem measurable_deformedClusterMass [Countable V] [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : - Measurable (fun ω => deformedClusterMass G P p k t D ω x) := - Measurable.tsum (fun y => measurable_deformedConnection G P p k t D x y) - -end ExteriorWeightedConnections -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeformedMassIntegrals -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedConnection_finite_support (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : - (deformedConnection G P p k t D ω x).HasFiniteSupport := by - apply hf.subset - intro y hy - by_contra hn - have hnc : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hn (conn_mono G Set.inter_subset_left h) - exact hy (by simp only [deformedConnection,hnc,and_false,ite_false]) - -theorem deformedClusterMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : - 0 ≤ deformedClusterMass G P p k t D ω x := - tsum_nonneg (deformedConnection_nonneg G P p k t D ω x) - -theorem deformedClusterMass_le_ncard (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - deformedClusterMass G P p k t D ω x ≤ ((cluster G ω x).ncard:ℝ) := by - unfold deformedClusterMass - rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by - have hn : ¬Conn G ω x y := fun hc => hy (hf.mem_toFinset.mpr hc) - have hn' : ¬Conn G (ω ∩ internalEdges G D) x y := fun hc => hn (conn_mono G Set.inter_subset_left hc) - simp only [deformedConnection,hn',and_false,ite_false])] - calc - _ ≤ ∑ _y ∈ hf.toFinset, (1:ℝ) := Finset.sum_le_sum (fun y _ => deformedConnection_le_one G P hP p k t ht D ω x y) - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] - -theorem integrable_deformedClusterMass [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : - Integrable (fun ω => deformedClusterMass G P p k t D ω x) (law p) := by - apply Integrable.mono' (susceptibility_eq_integral G hloc hqt p hp x).1 - (measurable_deformedClusterMass G P p k t D x).aestronglyMeasurable - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [Real.norm_of_nonneg (deformedClusterMass_nonneg G P p k t D ω x)] - exact deformedClusterMass_le_ncard G P hP p k t ht D ω x hω - - - -theorem deformedSusceptibility_eq_integral [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : - deformedSusceptibility G P p k t D x = ∫ ω, deformedClusterMass G P p k t D ω x ∂law p := by - have hi := integrable_deformedConnection G P hP p k t ht D x - have hs : Summable (fun y => ∫ ω, ‖deformedConnection G P p k t D ω x y‖ ∂law p) := by - simp only [Real.norm_of_nonneg (deformedConnection_nonneg G P p k t D _ x _)] - exact summable_deformedKernel G hloc hqt P hP p hp k t ht D x - exact integral_tsum_of_summable_integral_norm hi hs - -end DeformedMassIntegrals -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExactComponentRestriction -attribute [local instance] Classical.propDecidable Classical.decEq - - -def OpenClosed (G : BondGraph V E) (ω : Set E) (A : Set V) : Prop := - ∀ e ∈ ω, ∀ z ∈ G e, z ∈ A → ∀ a ∈ G e, a ∈ A - -theorem openClosed_cluster (G : BondGraph V E) (ω : Set E) (x : V) : - OpenClosed G ω (cluster G ω x) := by - intro e he z hz hx a ha - exact hx.trans (conn_of_open_incident G ω e he z a hz ha) - -theorem conn_restrict_openClosed (G : BondGraph V E) (ω S : Set E) (hS : S ⊆ ω) - (A : Set V) (hA : OpenClosed G ω A) (x y : V) (hx : x ∈ A) (hc : Conn G S x y) : - y ∈ A ∧ Conn G (S ∩ internalEdges G A) x y := by - induction hc with - | refl => exact ⟨hx,conn_refl G _ x⟩ - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - have ha : a ∈ G e := by simp [heq] - have hb : b ∈ G e := by simp [heq] - have hei : e ∈ internalEdges G A := hA e (hS he) a ha ih.1 - exact ⟨hei b hb,ih.2.tail ⟨e,⟨he,hei⟩,heq⟩⟩ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem counted_restrict_openClosed (w : RawCorridor G k) (D A : Set V) (ω : Set E) - (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : - w.counted (D ∩ A) ω x y ↔ w.counted D ω x y := by - have hs : ω ∩ internalEdges G (D ∩ A) ⊆ ω ∩ internalEdges G D := - Set.inter_subset_inter_right _ (internalEdges_mono G Set.inter_subset_left) - have hrest (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : - Conn G (S ∩ internalEdges G (D ∩ A)) x y := by - apply conn_mono G ?_ (conn_restrict_openClosed G _ S hS A hA x y hx hc).2 - rintro e ⟨he,heA⟩ - exact ⟨he,fun z hz => ⟨(hS he).2 z hz,heA z hz⟩⟩ - constructor - · intro hc - apply (w.counted_iff D ω x y).mpr - refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ - · intro e he - refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ - intro hbad - apply (hc.2.2.2.1 e he).2 - apply conn_mono G ?_ (hrest _ Set.sdiff_subset hbad) - rintro f ⟨⟨⟨hfω,_⟩,hfne⟩,hfnew⟩ - exact ⟨⟨hfω,hfnew⟩,hfne⟩ - · apply Set.disjoint_left.mpr - intro e he ho - obtain ⟨z,hzi,hze⟩ := he.1 - have hz : z ∈ A := (hc.2.1 z (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1)).2 - have heA : e ∈ internalEdges G (D ∩ A) := fun a ha => ⟨ho.2 a ha,hA e ho z hze hz a ha⟩ - exact Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,heA⟩ - · intro hc - have hc' : Conn G (ω ∩ internalEdges G (D ∩ A)) x y := by - apply conn_mono G ?_ (hrest _ (Set.Subset.refl _) hc.2.2.1) - rintro e ⟨⟨heω,_⟩,heA⟩ - exact ⟨heω,heA⟩ - exact (w.counted_iff _ ω x y).mpr ⟨hc.1, - corridorCounted_restrict G _ _ Set.inter_subset_left (Set.Subset.refl _) x y hc' hc.2.2⟩ - -end RawCorridor -end ExactComponentRestriction -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section InternalWeightedRestriction -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem corridorPenalty_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (D A : Set V) (ω : Set E) - (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : - corridorPenalty G P p k (D ∩ A) ω x y = corridorPenalty G P p k D ω x y := by - unfold corridorPenalty - apply tsum_congr - intro w - simp only [corridorPenaltyTerm,w.counted_restrict_openClosed D A ω hA x y hx] - -theorem deformedConnection_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D A : Set V) (ω : Set E) - (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : - deformedConnection G P p k t (D ∩ A) ω x y = deformedConnection G P p k t D ω x y := by - have hg : (x ∈ D ∩ A ∧ y ∈ D ∩ A ∧ Conn G (ω ∩ internalEdges G (D ∩ A)) x y) ↔ - (x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y) := by - constructor - · exact fun h => ⟨h.1.1,h.2.1.1,conn_mono G - (Set.inter_subset_inter_right _ (internalEdges_mono G Set.inter_subset_left)) h.2.2⟩ - · rintro ⟨hxD,hyD,hc⟩ - have hh := conn_restrict_openClosed G _ _ (Set.Subset.refl _) A hA x y hx hc - refine ⟨⟨hxD,hx⟩,⟨hyD,hh.1⟩,conn_mono G ?_ hh.2⟩ - rintro e ⟨⟨heω,heD⟩,heA⟩ - exact ⟨heω,fun z hz => ⟨heD z hz,heA z hz⟩⟩ - simp only [deformedConnection,hg,corridorPenalty_restrict_openClosed G P p k D A ω hA x y hx] - -theorem deformedClusterMass_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D A : Set V) (ω : Set E) - (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x : V) (hx : x ∈ A) : - deformedClusterMass G P p k t (D ∩ A) ω x = deformedClusterMass G P p k t D ω x := - tsum_congr (fun y => deformedConnection_restrict_openClosed G P p k t D A ω hA x y hx) - - -theorem deformedClusterMass_restrict_config (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (S : Set E) - (hS : internalEdges G D ⊆ S) : - deformedClusterMass G P p k t D (ω ∩ S) x = deformedClusterMass G P p k t D ω x := by - have he : (ω ∩ S) ∩ internalEdges G D = ω ∩ internalEdges G D := by - ext e - exact ⟨fun h => ⟨h.1.1,h.2⟩,fun h => ⟨⟨h.1,hS h.2⟩,h.2⟩⟩ - apply tsum_congr - intro y - have hc (w : RawCorridor G k) : w.counted D (ω ∩ S) x y ↔ w.counted D ω x y := by - simp only [RawCorridor.counted,corridorCounted,he] - simp only [deformedConnection,corridorPenalty,corridorPenaltyTerm,hc,he] - -end InternalWeightedRestriction -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory ProbabilityTheory -section DisjointCoordinateObservables -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem restriction_functions_independent (p : unitInterval) (S T : Set E) - (hST : Disjoint S T) (f g : Set E → ℝ) (hf : Measurable f) (hg : Measurable g) - (hfS : ∀ ω, f ω = f (ω ∩ S)) (hgT : ∀ ω, g ω = g (ω ∩ T)) : - IndepFun f g (law p) := by - rw [indepFun_iff_measure_inter_preimage_eq_mul] - intro A B hA hB - have he (h : Set E → ℝ) (U : Set E) (hU : ∀ ω, h ω = h (ω ∩ U)) (C : Set ℝ) : - (fun ω => ω ∩ U) ⁻¹' (h ⁻¹' C) = h ⁻¹' C := by - ext ω - simp only [Set.mem_preimage,←hU ω] - simpa only [he f S hfS A,he g T hgT B] using - restriction_events_independent p S T hST (f ⁻¹' A) (g ⁻¹' B) - (hA.preimage hf) (hB.preimage hg) - -theorem integral_mul_disjoint_coordinates (p : unitInterval) (S T : Set E) - (hST : Disjoint S T) (f g : Set E → ℝ) (hf : Measurable f) (hg : Measurable g) - (hfS : ∀ ω, f ω = f (ω ∩ S)) (hgT : ∀ ω, g ω = g (ω ∩ T)) : - (∫ ω, f ω*g ω ∂law p) = (∫ ω, f ω ∂law p)*(∫ ω, g ω ∂law p) := - (restriction_functions_independent p S T hST f g hf hg hfS hgT).integral_mul_eq_mul_integral - hf.aestronglyMeasurable hg.aestronglyMeasurable - -end DisjointCoordinateObservables -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExactWeightedClusterCell -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem induced_cluster_restrict_incident_iff (G : BondGraph V E) (hloc : LocallyFinite G) - (W : Finset V) (D : Set V) (ω : Set E) (x : V) : - cluster G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) x = (W:Set V) ↔ - cluster G (ω ∩ internalEdges G D) x = (W:Set V) := by - rw [Set.inter_right_comm] - exact cluster_restrict_incident_eq_iff G hloc W _ (Finset.Subset.refl _) _ x - -theorem weighted_cluster_cell_local (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (W : Finset V) (x : V) - (ω : Set E) : - (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) - then deformedClusterMass G P p k t D ω x else 0) = - (if cluster G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) x = (W:Set V) - then deformedClusterMass G P p k t D (ω ∩ (incidentSupport G hloc W:Set E)) x else 0) := by - simp only [induced_cluster_restrict_incident_iff] - split_ifs with hW - · have hx : x ∈ (W:Set V) := hW ▸ conn_refl G _ x - have hA : OpenClosed G (ω ∩ internalEdges G D) (W:Set V) := hW ▸ openClosed_cluster G _ x - have hW' := (induced_cluster_restrict_incident_iff G hloc W D ω x).mpr hW - have hA' : OpenClosed G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) (W:Set V) := - hW' ▸ openClosed_cluster G _ x - rw [←deformedClusterMass_restrict_openClosed G P p k t D W ω hA x hx, - ←deformedClusterMass_restrict_openClosed G P p k t D W _ hA' x hx] - symm - apply deformedClusterMass_restrict_config - intro e he - exact (mem_incidentSupport G hloc W e).mpr - ⟨(G e).out.1,(he _ (Sym2.out_fst_mem _)).2,Sym2.out_fst_mem _⟩ - · rfl - - - -theorem weighted_cluster_cell_exposure [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (W : Finset V) (x y : V) : - (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) - then deformedClusterMass G P p k t D ω x else 0) * - deformedClusterMass G P p k t (D \ (W:Set V)) ω y ∂law p) = - (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) - then deformedClusterMass G P p k t D ω x else 0) ∂law p) * - deformedSusceptibility G P p k t (D \ (W:Set V)) y := by - rw [deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht] - apply integral_mul_disjoint_coordinates p (incidentSupport G hloc W:Set E) - (incidentSupport G hloc W:Set E)ᶜ disjoint_compl_right - · exact Measurable.ite ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) - (measurable_deformedClusterMass G P p k t D x) measurable_const - · exact measurable_deformedClusterMass G P p k t _ y - · exact weighted_cluster_cell_local G hloc P p k t D W x - · intro ω - symm - apply deformedClusterMass_restrict_config - rw [complement_incidentSupport] - exact fun e he z hz => (he z hz).2 - -end ExactWeightedClusterCell -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section InducedClusterPartition -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem integral_induced_cluster_finite_partition [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (D : Set V) (x : V) - (f : Set E → ℝ) (hf : Integrable f (law p)) : - (∫ ω, f ω ∂law p) = ∑' W : Finset V, - ∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then f ω else 0) ∂law p := by - let F (W : Finset V) (ω : Set E) := if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then f ω else 0 - have hi (W : Finset V) : Integrable (F W) (law p) := by - have he : F W = {ω : Set E | cluster G (ω ∩ internalEdges G D) x = (W:Set V)}.indicator f := by - funext ω - simp only [F,Set.indicator,Set.mem_ofPred_eq] - split_ifs <;> rfl - rw [he] - exact hf.indicator ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) - have hb (S : Finset (Finset V)) (ω : Set E) : (∑ W ∈ S, ‖F W ω‖) ≤ ‖f ω‖ := by - by_cases hex : ∃ W ∈ S, cluster G (ω ∩ internalEdges G D) x = (W:Set V) - · obtain ⟨W,hWS,hW⟩ := hex - rw [Finset.sum_eq_single W] - · simp only [F,hW,ite_true,le_refl] - · intro U _ hU - have hu : cluster G (ω ∩ internalEdges G D) x ≠ (U:Set V) := fun h => hU (Finset.coe_injective (h.symm.trans hW)) - simp only [F,ite_eq_right hu,norm_zero] - · exact fun h => (h hWS).elim - · have he (W : Finset V) (hW : W ∈ S) : cluster G (ω ∩ internalEdges G D) x ≠ (W:Set V) := fun h => hex ⟨W,hW,h⟩ - calc - _ = 0 := Finset.sum_eq_zero (fun W hW => by simp only [F,ite_eq_right (he W hW),norm_zero]) - _ ≤ _ := norm_nonneg _ - have hn : Summable (fun W => ∫ ω, ‖F W ω‖ ∂law p) := by - apply summable_of_sum_le (fun _ => integral_nonneg (fun _ => norm_nonneg _)) - (c := ∫ ω, ‖f ω‖ ∂law p) - intro S - rw [←integral_finsetSum _ (fun W _ => (hi W).norm)] - exact integral_mono (integrable_finsetSum _ (fun W _ => (hi W).norm)) hf.norm (hb S) - calc - _ = ∫ ω, ∑' W : Finset V, F W ω ∂law p := by - apply integral_congr_ae - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact (tsum_cluster_cells G (ω ∩ internalEdges G D) x - (hω.subset (fun _ h => conn_mono G Set.inter_subset_left h)) (f ω)).symm - _ = _ := (integral_tsum_of_summable_integral_norm hi hn).symm - -end InducedClusterPartition -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeformedClusterProducts -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedClusterMass_eq_zero_of_not_mem (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (hx : x ∉ D) : - deformedClusterMass G P p k t D ω x = 0 := by - simp only [deformedClusterMass,deformedConnection,hx,false_and,ite_false,tsum_zero] - -theorem deformed_distinct_product_eq_exterior (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - (if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) = - deformedClusterMass G P p k t D ω x * - deformedClusterMass G P p k t (D \ cluster G (ω ∩ internalEdges G D) x) ω y := by - by_cases hc : Conn G (ω ∩ internalEdges G D) x y - · rw [ite_eq_right (not_not_intro hc),deformedClusterMass_eq_zero_of_not_mem G P p k t _ ω y - (fun h => h.2 hc),mul_zero] - · rw [ite_eq_left hc,deformedClusterMass_delete_other_cluster G P p k t D ω x y hc] - -theorem integrable_deformed_product [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - Integrable (fun ω => deformedClusterMass G P p k t D ω x * - deformedClusterMass G P p k t D ω y) (law p) := by - apply Integrable.mono' (subcritical_cluster_association G hloc hqt p hp x y).1 - ((measurable_deformedClusterMass G P p k t D x).mul - (measurable_deformedClusterMass G P p k t D y)).aestronglyMeasurable - filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy - dsimp only [Pi.mul_apply] - rw [Real.norm_of_nonneg (mul_nonneg (deformedClusterMass_nonneg G P p k t D ω x) - (deformedClusterMass_nonneg G P p k t D ω y))] - exact mul_le_mul (deformedClusterMass_le_ncard G P hP p k t ht D ω x hx) - (deformedClusterMass_le_ncard G P hP p k t ht D ω y hy) - (deformedClusterMass_nonneg G P p k t D ω y) (Nat.cast_nonneg _) - -theorem integrable_distinct_deformed_product [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - Integrable (fun ω => if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) (law p) := by - have he : (fun ω => if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) = - {ω | Conn G (ω ∩ internalEdges G D) x y}ᶜ.indicator - (fun ω => deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y) := by - funext ω - simp only [Set.indicator,Set.mem_compl_iff,Set.mem_ofPred_eq] - rw [he] - exact (integrable_deformed_product G hloc hqt P hP p hp k t ht D x y).indicator - (((measurableSet_conn G x y).preimage (measurable_inter_const (internalEdges G D))).compl) - -end DeformedClusterProducts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FreshWeightedMass -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def deformedFreshExteriorMoment (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) (ω : Set E) : ℝ := - deformedClusterMass G P p k t D ω x * - deformedSusceptibility G P p k t (D \ cluster G (ω ∩ internalEdges G D) x) y - -theorem deformedSusceptibility_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : - 0 ≤ deformedSusceptibility G P p k t D x := - tsum_nonneg (deformedKernel_nonneg G P p k t D x) - -theorem deformedFreshExteriorMoment_eq_tsum (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) (ω : Set E) - (hf : (cluster G (ω ∩ internalEdges G D) x).Finite) : - deformedFreshExteriorMoment G P p k t D x y ω = ∑' W : Finset V, - if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then - deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t (D \ (W:Set V)) y else 0 := by - rw [←tsum_cluster_cells G (ω ∩ internalEdges G D) x hf (deformedFreshExteriorMoment G P p k t D x y ω)] - apply tsum_congr - intro W - split_ifs with hW - · simp only [deformedFreshExteriorMoment,hW] - · rfl - -theorem integrable_deformedFreshExteriorMoment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - Integrable (deformedFreshExteriorMoment G P p k t D x y) (law p) := by - have hm : AEStronglyMeasurable (deformedFreshExteriorMoment G P p k t D x y) (law p) := by - have hh : Measurable (fun ω => ∑' W : Finset V, - if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then - deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t (D \ (W:Set V)) y else 0) := by - apply Measurable.tsum - intro W - exact Measurable.ite ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) - ((measurable_deformedClusterMass G P p k t D x).mul_const _) measurable_const - apply hh.aestronglyMeasurable.congr - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact (deformedFreshExteriorMoment_eq_tsum G P p k t D x y ω - (hω.subset (fun _ h => conn_mono G Set.inter_subset_left h))).symm - apply Integrable.mono' ((integrable_deformedClusterMass G hloc hqt P hP p hp k t ht D x).mul_const - (susceptibility G p y)) hm - exact Filter.Eventually.of_forall (fun ω => by - dsimp only [deformedFreshExteriorMoment] - rw [Real.norm_of_nonneg (mul_nonneg (deformedClusterMass_nonneg G P p k t D ω x) - (deformedSusceptibility_nonneg G P p k t _ y))] - exact mul_le_mul_of_nonneg_left (deformedSusceptibility_le G hloc hqt P hP p hp k t ht _ y) - (deformedClusterMass_nonneg G P p k t D ω x)) - -end FreshWeightedMass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedExposureIdentity -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem integral_deformedFreshExteriorMoment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - (∫ ω, deformedFreshExteriorMoment G P p k t D x y ω ∂law p) = - ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by - rw [integral_induced_cluster_finite_partition G p hp D x _ - (integrable_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y), - integral_induced_cluster_finite_partition G p hp D x _ - (integrable_distinct_deformed_product G hloc hqt P hP p hp k t ht D x y)] - apply tsum_congr - intro W - have hl : (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then - deformedFreshExteriorMoment G P p k t D x y ω else 0) ∂law p) = - (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then - deformedClusterMass G P p k t D ω x else 0) ∂law p) * - deformedSusceptibility G P p k t (D \ (W:Set V)) y := by - rw [←integral_mul_const] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - by_cases hW : cluster G (ω ∩ internalEdges G D) x = (W:Set V) - · simp only [hW,ite_true,deformedFreshExteriorMoment] - · simp only [hW,ite_false,zero_mul]) - rw [hl,←weighted_cluster_cell_exposure G hloc hqt P hP p hp k t ht D W x y] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - by_cases hW : cluster G (ω ∩ internalEdges G D) x = (W:Set V) - · simp only [hW,ite_true] - rw [deformed_distinct_product_eq_exterior,hW] - · simp only [hW,ite_false,zero_mul]) - -end WeightedExposureIdentity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedThreeArmEstimate -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -theorem summable_three_arm_pair (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a : V) : - Summable (fun bz : V×V => twoPoint G p x bz.1 * twoPoint G p bz.1 a * twoPoint G p bz.1 bz.2) := by - apply (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le - · exact fun bz => mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) - (twoPoint_nonneg G p _ _) - · intro bz - exact mul_le_mul_of_nonneg_right (mul_le_of_le_one_right (twoPoint_nonneg G p _ _) (twoPoint_le_one G p _ _)) - (twoPoint_nonneg G p _ _) - -theorem three_arm_real_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a z : V) : - (law p).real {ω | Conn G ω x a ∧ Conn G ω x z} ≤ - ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := by - have hs := (summable_three_arm_pair G hloc hqt p hp x a).prod_symm.prod_factor z - have hn (b : V) : 0 ≤ twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := - mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _) - have he : (∑' b, law p {ω | Conn G ω x b} * law p {ω | Conn G ω b a} * law p {ω | Conn G ω b z}) = - ENNReal.ofReal (∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z) := by - rw [ENNReal.ofReal_tsum_of_nonneg hn hs] - apply tsum_congr - intro b - rw [ENNReal.ofReal_mul (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)), - ENNReal.ofReal_mul (twoPoint_nonneg G p _ _)] - simp only [twoPoint,ENNReal.ofReal_toReal (measure_ne_top _ _)] - have hh := (three_arm_bound G p x a z).trans_eq he - exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hh).trans_eq (ENNReal.toReal_ofReal (tsum_nonneg hn)) - - - -theorem integral_size_membership_le (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a : V) : - (∫ ω, (if Conn G ω x a then ((cluster G ω x).ncard:ℝ) else 0) ∂law p) ≤ - maxSusceptibility G p * (∑' b, twoPoint G p x b * twoPoint G p b a) := by - have he := integral_cluster_size_event G hloc hqt p hp x _ (measurableSet_conn G x a) - simp only [Set.mem_ofPred_eq] at he - rw [he] - have hs := summable_three_arm_pair G hloc hqt p hp x a - have hl : Summable (fun z => (law p).real {ω | Conn G ω x a ∧ Conn G ω x z}) := - (summable_twoPoint_subcritical G hloc hqt p hp x).of_nonneg_of_le (fun _ => measureReal_nonneg) - (fun _ => measureReal_mono (fun _ h => h.2)) - have hb : Summable (fun b => twoPoint G p x b * twoPoint G p b a) := - (summable_twoPoint_subcritical G hloc hqt p hp x).of_nonneg_of_le - (fun b => mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) - (fun b => mul_le_of_le_one_right (twoPoint_nonneg G p _ _) (twoPoint_le_one G p _ _)) - have hj : Summable (fun b => twoPoint G p x b * twoPoint G p b a * susceptibility G p b) := by - simpa only [tsum_mul_left,susceptibility] using hs.prod - calc - _ ≤ ∑' z, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := - hl.tsum_le_tsum (three_arm_real_bound G hloc hqt p hp x a) hs.prod_symm.prod - _ = ∑' b, ∑' z, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := hs.tsum_comm - _ = ∑' b, twoPoint G p x b * twoPoint G p b a * susceptibility G p b := by - simp only [tsum_mul_left,susceptibility] - _ ≤ ∑' b, twoPoint G p x b * twoPoint G p b a * maxSusceptibility G p := by - apply hj.tsum_le_tsum - (fun b => mul_le_mul_of_nonneg_left (susceptibility_le_max G hloc hqt p hp b) - (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _))) (hb.mul_right _) - _ = _ := by rw [tsum_mul_right,mul_comm] - -end WeightedThreeArmEstimate -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteNeighborhoodMass -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finset_sum_union_le (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) (S T : Finset V) : - (∑ x ∈ S ∪ T, f x) ≤ (∑ x ∈ S, f x) + ∑ x ∈ T, f x := by - have he := Finset.sum_union_inter (f := f) (s₁ := S) (s₂ := T) - have hn := Finset.sum_nonneg (s := S ∩ T) (fun x _ => hf x) - linarith - -theorem finset_sum_biUnion_le (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) - (W : Finset V) (N : V → Finset V) : - (∑ z ∈ W.biUnion N, f z) ≤ ∑ a ∈ W, ∑ z ∈ N a, f z := by - induction W using Finset.induction_on with - | empty => simp - | @insert a W ha ih => - rw [Finset.biUnion_insert,Finset.sum_insert ha] - exact (finset_sum_union_le f hf _ _).trans (add_le_add (le_refl _) ih) - -theorem closedBondNeighborhood_finset (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) : - closedBondNeighborhood G (W:Set V) = (W ∪ W.biUnion (neighbors G hloc) : Finset V) := by - ext z - simp only [closedBondNeighborhood,Set.mem_ofPred_eq,Finset.mem_coe,Finset.mem_union,Finset.mem_biUnion] - constructor - · rintro (hz | ⟨e,hz,a,ha,haW⟩) - · exact Or.inl hz - · by_cases hza : a = z - · exact Or.inl (hza ▸ haW) - · exact Or.inr ⟨a,haW,(mem_neighbors G hloc a z).mpr - ⟨e,(Sym2.mem_and_mem_iff hza).mp ⟨ha,hz⟩⟩⟩ - · rintro (hz | ⟨a,ha,haz⟩) - · exact Or.inl hz - · obtain ⟨e,he⟩ := (mem_neighbors G hloc a z).mp haz - exact Or.inr ⟨e,he.symm ▸ Sym2.mem_mk_right a z,a,he.symm ▸ Sym2.mem_mk_left a z,ha⟩ - -theorem neighborhood_mass_le (G : BondGraph V E) (hloc : LocallyFinite G) - (W : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) : - (∑' z : closedBondNeighborhood G (W:Set V), f z) ≤ - ∑ a ∈ W, (f a + ∑ z ∈ neighbors G hloc a, f z) := by - rw [closedBondNeighborhood_finset G hloc W,Finset.tsum_subtype'] - exact (finset_sum_union_le f hf _ _).trans - ((add_le_add (le_refl _) (finset_sum_biUnion_le f hf W (neighbors G hloc))).trans_eq - (Finset.sum_add_distrib).symm) - -end FiniteNeighborhoodMass -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.Corridors + +namespace OAI + +/-! Cluster Products for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SmallDeformationOperators +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + + + +theorem exists_deformedOperator_small_change (G : BondGraph V E) + (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) + (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) : + ∃ B : Hilbert V →L[ℂ] Hilbert V, + (∀ x y, matrixCoeff B x y = (deformedKernel G (walkKernel G hloc a) p k t Set.univ x y : ℂ)) ∧ + ‖B‖ ≤ ‖A‖ ∧ ‖A-B‖ ≤ 2*t*‖P‖^k*‖A‖^2 ∧ ‖A‖-2*t*‖P‖^k*‖A‖^2 ≤ ‖B‖ := by + let K := deformedKernel G (walkKernel G hloc a) p k t Set.univ + have hKn (x y : V) : 0 ≤ K x y := deformedKernel_nonneg G _ p k t _ x y + have hb (x y : V) := deformedKernel_change_bound G hG hloc p hp hp₁ a P hpos hPs hP A hA hAs hAT k t ht x y + obtain ⟨B,hBn,hBK⟩ := exists_operator_of_matrix_domination (twoPoint G p) K (twoPoint_nonneg G p) + (fun x y => by rw [abs_of_nonneg (hKn x y)]; exact sub_nonneg.mp (hb x y).1) A hAT + have hBK' (x y : V) : matrixCoeff B x y = (K x y : ℂ) := hBK x y + let C := A*(P^k*A) + have hCn : PositiveRealMatrix C := hA.mul ((hpos.pow k).mul hA) + have hscale (x y : V) : matrixCoeff (((2*t:ℝ):ℂ) • C) x y = + (2*t*(matrixCoeff C x y).re : ℝ) := by + change ((2*t:ℝ):ℂ)*matrixCoeff C x y = _ + rw [hCn.real] + simp only [Complex.ofReal_re,Complex.ofReal_mul] + obtain ⟨D,hDn,hDK⟩ := exists_operator_of_matrix_domination + (fun x y => 2*t*(matrixCoeff C x y).re) (fun x y => twoPoint G p x y - K x y) + (fun x y => mul_nonneg (mul_nonneg (by norm_num) ht) (hCn x y).2) + (fun x y => by rw [abs_of_nonneg (hb x y).1]; exact (hb x y).2) + (((2*t:ℝ):ℂ) • C) hscale + have he : D = A-B := kernel_extension_unique hDK (by + intro x y + change matrixCoeff A x y - matrixCoeff B x y = _ + rw [hAT,hBK',Complex.ofReal_sub]) + rw [he] at hDn + have hCnorm : ‖C‖ ≤ ‖A‖*‖P‖^k*‖A‖ := by + calc + _ ≤ ‖A‖*‖P^k*A‖ := norm_mul_le _ _ + _ ≤ ‖A‖*(‖P^k‖*‖A‖) := mul_le_mul_of_nonneg_left (norm_mul_le _ _) (norm_nonneg _) + _ ≤ ‖A‖*(‖P‖^k*‖A‖) := by + gcongr + cases k with + | zero => + simp only [pow_zero] + have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext f; rfl + rw [he] + exact ContinuousLinearMap.norm_id_le + | succ j => exact norm_pow_le' P (Nat.succ_pos j) + _ = _ := by ring + have hd : ‖A-B‖ ≤ 2*t*‖P‖^k*‖A‖^2 := by + calc + _ ≤ ‖((2*t:ℝ):ℂ) • C‖ := hDn + _ = 2*t*‖C‖ := by rw [norm_smul,Complex.norm_of_nonneg (mul_nonneg (by norm_num) ht)] + _ ≤ 2*t*(‖A‖*‖P‖^k*‖A‖) := mul_le_mul_of_nonneg_left hCnorm (mul_nonneg (by norm_num) ht) + _ = _ := by ring + refine ⟨B,hBK,hBn,hd,?_⟩ + have hh : ‖A‖ ≤ ‖A-B‖+‖B‖ := by simpa only [sub_add_cancel] using norm_add_le (A-B) B + linarith + +end SmallDeformationOperators +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeletionGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +def closedBondNeighborhood (G : BondGraph V E) (A : Set V) : Set V := + {z | z ∈ A ∨ ∃ e, z ∈ G e ∧ ∃ a ∈ G e, a ∈ A} + +def SimpleVisit (G : BondGraph V E) (S : Set E) (A : Set V) (x y : V) : Prop := + ∃ q : (openSimpleGraph G S).Walk x y, q.IsPath ∧ ∃ z ∈ q.support, z ∈ A + +theorem SimpleVisit.mono (G : BondGraph V E) {S T : Set E} {A B : Set V} + (hST : S ⊆ T) (hAB : A ⊆ B) {x y : V} (h : SimpleVisit G S A x y) : + SimpleVisit G T B x y := by + obtain ⟨q,hq,z,hz,ha⟩ := h + have hg : openSimpleGraph G S ≤ openSimpleGraph G T := by + rintro a b ⟨hne,e,he,hGe⟩ + exact ⟨hne,e,hST he,hGe⟩ + exact ⟨q.mapLe hg,hq.mapLe hg,z,by simpa only [SimpleGraph.Walk.support_mapLe_eq_support] using hz,hAB ha⟩ + +theorem walk_conn_restrict_vertices (G : BondGraph V E) (S : Set E) {x y : V} + (q : (openSimpleGraph G S).Walk x y) (D : Set V) + (hD : ∀ z ∈ q.support, z ∈ D) : Conn G (S ∩ internalEdges G D) x y := by + obtain ⟨l,hl,hm,ho⟩ := walk_lift_bonds G S q + apply hl.conn + intro e he + refine ⟨ho e he,?_⟩ + intro z hz + exact hD z (SimpleGraph.Walk.mem_support_of_mem_edges (hm ▸ List.mem_map_of_mem he) hz) + +theorem conn_restrict_of_no_simpleVisit (G : BondGraph V E) (S : Set E) + (A : Set V) (x y : V) (hc : Conn G S x y) (hn : ¬SimpleVisit G S A x y) : + Conn G (S ∩ internalEdges G Aᶜ) x y := by + obtain ⟨q⟩ := (conn_iff_reachable G S x y).mp hc + exact walk_conn_restrict_vertices G S q.bypass Aᶜ + (fun z hz ha => hn ⟨q.bypass,q.bypass_isPath,z,hz,ha⟩) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem counted_support_subset_walk (w : RawCorridor G k) (D : Set V) (ω : Set E) + (x y : V) (hc : w.counted D ω x y) + (q : (openSimpleGraph G (ω ∩ internalEdges G D)).Walk x y) : + ∀ z ∈ w.path.support, z ∈ q.support := by + intro z hz + have hl : 0 < w.path.length := by have := hc.1; omega + obtain ⟨s,hs,hzs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil + (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp hz + obtain ⟨e,he,hGe⟩ := w.edge_has_label s hs + exact SimpleGraph.Walk.mem_support_of_mem_edges + (pivotal_image_mem_edges G _ q e (hc.2.2.2.1 e he).2) (hGe.symm ▸ hzs) + +end RawCorridor + + + +theorem simplePath_disjoint_at (G : BondGraph V E) (S : Set E) {x y z : V} + (q : (openSimpleGraph G S).Walk x y) (hq : q.IsPath) (hz : z ∈ q.support) : + S ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} := by + obtain ⟨a,ha,hea,hoa⟩ := walk_lift_bonds G S (q.takeUntil z hz) + obtain ⟨b,hb,heb,hob⟩ := walk_lift_bonds G S (q.dropUntil z hz) + refine ⟨a.toFinset,b.toFinset,?_,?_,?_,?_,?_⟩ + · intro e he; exact hoa e (List.mem_toFinset.mp he) + · intro e he; exact hob e (List.mem_toFinset.mp he) + · apply Finset.disjoint_left.mpr + intro e hae hbe + exact List.disjoint_left.mp (hq.isTrail.disjoint_edges_takeUntil_dropUntil hz) + (hea ▸ List.mem_map_of_mem (List.mem_toFinset.mp hae)) + (heb ▸ List.mem_map_of_mem (List.mem_toFinset.mp hbe)) + · exact ha.conn (fun e he => List.mem_toFinset.mpr he) + · exact hb.conn (fun e he => List.mem_toFinset.mpr he) + +end DeletionGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeletionCounted +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem conn_delete_of_no_visit (G : BondGraph V E) (ω : Set E) (D A : Set V) + (x y : V) (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) + (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : + Conn G (S ∩ internalEdges G (D \ A)) x y := by + have hno : ¬SimpleVisit G S A x y := fun h => hn (h.mono G hS (fun _ => Or.inl)) + have h := conn_restrict_of_no_simpleVisit G S A x y hc hno + apply conn_mono G ?_ h + rintro e ⟨he,ha⟩ + exact ⟨he,fun z hz => ⟨(hS he).2 z hz,ha z hz⟩⟩ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem counted_before_deletion_of_no_visit (w : RawCorridor G k) + (D A : Set V) (ω : Set E) (x y : V) + (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) + (hc : w.counted (D \ A) ω x y) : w.counted D ω x y := by + have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := + Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) + apply (w.counted_iff D ω x y).mpr + refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ + · intro e he + refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ + intro hbad + have hd := conn_delete_of_no_visit G ω D A x y hn + ((ω ∩ internalEdges G D) \ {e}) Set.sdiff_subset hbad + apply (hc.2.2.2.1 e he).2 + apply conn_mono G ?_ hd + rintro f ⟨⟨⟨hfω,hfD⟩,hfne⟩,hfnew⟩ + exact ⟨⟨hfω,hfnew⟩,hfne⟩ + · apply Set.disjoint_left.mpr + intro e he ho + have henew : e ∉ internalEdges G (D \ A) := fun he' => + Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,he'⟩ + obtain ⟨a,ha,hna⟩ : ∃ a ∈ G e, a ∉ D \ A := by + change ¬(∀ a ∈ G e, a ∈ D \ A) at henew + push Not at henew + exact henew + have haA : a ∈ A := by + by_contra ha' + exact hna ⟨ho.2 a ha,ha'⟩ + obtain ⟨z,hzi,hze⟩ := he.1 + obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 + have hz : z ∈ q.bypass.support := w.counted_support_subset_walk (D \ A) ω x y hc q.bypass z + (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1) + have hv : SimpleVisit G (ω ∩ internalEdges G (D \ A)) (closedBondNeighborhood G A) x y := + ⟨q.bypass,q.bypass_isPath,z,hz,Or.inr ⟨e,hze,a,ha,haA⟩⟩ + exact hn (hv.mono G hs (Set.Subset.refl _)) + +end RawCorridor +end DeletionCounted +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeletionWeightedLoss +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem deformedConnection_no_visit (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (ω : Set E) (x y : V) + (hn : ¬SimpleVisit G (ω ∩ internalEdges G D) (closedBondNeighborhood G A) x y) : + deformedConnection G P p k t D ω x y ≤ deformedConnection G P p k t (D \ A) ω x y := by + by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y + · obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2 + have hx : x ∉ A := fun ha => hn ⟨q.bypass,q.bypass_isPath,x,q.bypass.start_mem_support,Or.inl ha⟩ + have hy : y ∉ A := fun ha => hn ⟨q.bypass,q.bypass_isPath,y,q.bypass.end_mem_support,Or.inl ha⟩ + have hc' : x ∈ D \ A ∧ y ∈ D \ A ∧ Conn G (ω ∩ internalEdges G (D \ A)) x y := by + refine ⟨⟨hc.1,hx⟩,⟨hc.2.1,hy⟩,?_⟩ + apply conn_mono G ?_ (conn_delete_of_no_visit G ω D A x y hn _ (Set.Subset.refl _) hc.2.2) + rintro e ⟨⟨heω,heD⟩,henew⟩ + exact ⟨heω,henew⟩ + simp only [deformedConnection,hc,hc'] + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonpos_left ?_ (neg_nonpos.mpr ht) + apply (corridorPenalty_summable G hloc P p k (D \ A) ω x y).tsum_le_tsum ?_ + (corridorPenalty_summable G hloc P p k D ω x y) + intro w + by_cases hw : w.counted (D \ A) ω x y + · have hw' := w.counted_before_deletion_of_no_visit D A ω x y hn hw + simp only [corridorPenaltyTerm,hw,hw',ite_true,le_refl] + · simpa only [corridorPenaltyTerm,hw,ite_false] using corridorPenaltyTerm_nonneg G P hP p D ω x y w + · simpa only [deformedConnection,hc,ite_false] using deformedConnection_nonneg G P p k t (D \ A) ω x y + + + +theorem deformedConnection_deletion_pointwise (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (ω : Set E) (x y : V) : + deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ≤ + if ∃ z ∈ closedBondNeighborhood G A, + ω ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} then 1 else 0 := by + split_ifs with h + · linarith [deformedConnection_le_one G P hP p k t ht D ω x y, + deformedConnection_nonneg G P p k t (D \ A) ω x y] + · apply sub_nonpos.mpr + apply deformedConnection_no_visit G hloc P hP p k t ht D A ω x y + rintro ⟨q,hq,z,hz,hza⟩ + apply h + exact ⟨z,hza,disjointOccurrence_upper _ _ Set.inter_subset_left (simplePath_disjoint_at G _ q hq hz)⟩ + +end DeletionWeightedLoss +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeletionKernelBound +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + + + +theorem deformedKernel_deletion_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D A : Set V) (x y : V) + (hs : Summable (fun z : closedBondNeighborhood G A => twoPoint G p x z * twoPoint G p z y)) : + deformedKernel G P p k t D x y - deformedKernel G P p k t (D \ A) x y ≤ + ∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y := by + let B := fun z : closedBondNeighborhood G A => + DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} + let U := ⋃ z, B z + have hBm (z : closedBondNeighborhood G A) : MeasurableSet (B z) := + measurableSet_finiteWitness _ (disjointOccurrence_upper _ _) (finiteWitness_disjointOccurrence _ _) + have hUm : MeasurableSet U := MeasurableSet.iUnion hBm + have hBn (z : closedBondNeighborhood G A) : 0 ≤ twoPoint G p x z * twoPoint G p z y := + mul_nonneg (twoPoint_nonneg G p x z) (twoPoint_nonneg G p z y) + have hBK (z : closedBondNeighborhood G A) : law p (B z) ≤ ENNReal.ofReal (twoPoint G p x z * twoPoint G p z y) := by + rw [←ENNReal.ofReal_toReal (measure_ne_top (law p) (B z))] + exact ENNReal.ofReal_le_ofReal (bk p _ _ (fun _ _ h hc => conn_mono G h hc) + (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x z) (finiteWitness_conn G z y)) + have hU : (law p).real U ≤ ∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y := by + have hh : law p U ≤ ENNReal.ofReal (∑' z : closedBondNeighborhood G A, twoPoint G p x z * twoPoint G p z y) := by + calc + _ ≤ ∑' z, law p (B z) := measure_iUnion_le B + _ ≤ ∑' z : closedBondNeighborhood G A, ENNReal.ofReal (twoPoint G p x z * twoPoint G p z y) := ENNReal.tsum_le_tsum hBK + _ = _ := (ENNReal.ofReal_tsum_of_nonneg hBn hs).symm + exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hh).trans_eq (ENNReal.toReal_ofReal (tsum_nonneg hBn)) + have hUi : Integrable (U.indicator (fun _ : Set E => (1:ℝ))) (law p) := (integrable_const _).indicator hUm + have hpoint (ω : Set E) : deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ≤ + U.indicator (fun _ : Set E => (1:ℝ)) ω := by + have he : ω ∈ U ↔ ∃ z ∈ closedBondNeighborhood G A, ω ∈ DisjointOccurrence {η | Conn G η x z} {η | Conn G η z y} := by + simp [U,B] + simpa only [Set.indicator_apply,he] using deformedConnection_deletion_pointwise G hloc P hP p k t ht D A ω x y + have hi := integrable_deformedConnection G P hP p k t ht D x y + have hi' := integrable_deformedConnection G P hP p k t ht (D \ A) x y + calc + _ = ∫ ω, deformedConnection G P p k t D ω x y - deformedConnection G P p k t (D \ A) ω x y ∂law p := (integral_sub hi hi').symm + _ ≤ ∫ ω, U.indicator (fun _ : Set E => (1:ℝ)) ω ∂law p := integral_mono (hi.sub hi') hUi hpoint + _ = (law p).real U := integral_indicator_one hUm + _ ≤ _ := hU + +end DeletionKernelBound +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeformedSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def deformedSusceptibility (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : ℝ := + ∑' y, deformedKernel G P p k t D x y + +theorem deformedKernel_le_twoPoint [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + deformedKernel G P p k t D x y ≤ twoPoint G p x y := by + rw [←deformedKernel_zero G P p k x y] + apply integral_mono (integrable_deformedConnection G P hP p k t ht D x y) + (integrable_deformedConnection G P hP p k 0 (le_refl _) Set.univ x y) + intro ω + exact (deformedConnection_mono G hloc P hP p k t ht (Set.subset_univ D) + (Set.Subset.refl _) x y).trans (sub_nonneg.mp (deformedConnection_change G P hP p k t ht Set.univ ω x y).1) + +theorem summable_deformedKernel [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : + Summable (deformedKernel G P p k t D x) := + Summable.of_nonneg_of_le (deformedKernel_nonneg G P p k t D x) + (deformedKernel_le_twoPoint G hloc P hP p k t ht D x) + (summable_twoPoint_subcritical G hloc hqt p hp x) + +theorem deformedSusceptibility_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : + deformedSusceptibility G P p k t D x ≤ susceptibility G p x := + (summable_deformedKernel G hloc hqt P hP p hp k t ht D x).tsum_le_tsum + (deformedKernel_le_twoPoint G hloc P hP p k t ht D x) + (summable_twoPoint_subcritical G hloc hqt p hp x) + +end DeformedSusceptibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeletionSusceptibilityEstimate +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +theorem summable_twoPoint_restricted_pair (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x : V) (N : Set V) : + Summable (fun zy : N×V => twoPoint G p x zy.1 * twoPoint G p zy.1 zy.2) := by + apply (summable_twoPoint_pair G hloc hqt p hp x).comp_injective (i := fun zy : N×V => (zy.1.val,zy.2)) + intro a b hab + exact Prod.ext (Subtype.ext (congrArg Prod.fst hab)) (congrArg (fun z : V×V => z.2) hab) + +theorem twoPoint_double_restricted_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x : V) (N : Set V) : + (∑' y : V, ∑' z : N, twoPoint G p x z * twoPoint G p z y) ≤ + maxSusceptibility G p * (∑' z : N, twoPoint G p x z) := by + have hpairs := summable_twoPoint_restricted_pair G hloc hqt p hp x N + have hcomm : (∑' y : V, ∑' z : N, twoPoint G p x z * twoPoint G p z y) = + ∑' z : N, twoPoint G p x z * susceptibility G p z := by + calc + _ = ∑' z : N, ∑' y : V, twoPoint G p x z * twoPoint G p z y := hpairs.tsum_comm + _ = _ := by simp only [tsum_mul_left, susceptibility] + have hprod : Summable (fun z : N => twoPoint G p x z * susceptibility G p z) := by + simpa only [tsum_mul_left, susceptibility] using hpairs.prod + rw [hcomm] + calc + _ ≤ ∑' z : N, twoPoint G p x z * maxSusceptibility G p := + hprod.tsum_le_tsum + (fun z => mul_le_mul_of_nonneg_left (susceptibility_le_max G hloc hqt p hp z) (twoPoint_nonneg G p x z)) + ((summable_twoPoint_subcritical G hloc hqt p hp x).subtype N |>.mul_right _) + _ = _ := by rw [tsum_mul_right,mul_comm] + + + +theorem deformedSusceptibility_deletion (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D A : Set V) (x : V) : + deformedSusceptibility G P p k t D x - + maxSusceptibility G p * (∑' z : closedBondNeighborhood G A, twoPoint G p x z) ≤ + deformedSusceptibility G P p k t (D \ A) x := by + let N := closedBondNeighborhood G A + have hpairs := summable_twoPoint_restricted_pair G hloc hqt p hp x N + have hdiag (y : V) := hpairs.prod_symm.prod_factor y + have hi := summable_deformedKernel G hloc hqt P hP p hp k t ht D x + have hi' := summable_deformedKernel G hloc hqt P hP p hp k t ht (D \ A) x + have hb := (hi.sub hi').tsum_le_tsum + (fun y => deformedKernel_deletion_bound G hloc P hP p k t ht D A x y (hdiag y)) hpairs.prod_symm.prod + rw [hi.tsum_sub hi'] at hb + change deformedSusceptibility G P p k t D x - deformedSusceptibility G P p k t (D \ A) x ≤ _ at hb + have herr := twoPoint_double_restricted_bound G hloc hqt p hp x N + linarith + +end DeletionSusceptibilityEstimate +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExteriorCorridorGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem conn_of_open_incident (G : BondGraph V E) (ω : Set E) (e : E) + (he : e ∈ ω) (a b : V) (ha : a ∈ G e) (hb : b ∈ G e) : Conn G ω a b := by + obtain ⟨c,d,hcd⟩ : ∃ c d, G e = s(c,d) := by + obtain ⟨⟨c,d⟩,hh⟩ := Quot.exists_rep (G e) + exact ⟨c,d,hh.symm⟩ + rw [hcd,Sym2.mem_iff] at ha hb + rcases ha with rfl | rfl <;> rcases hb with rfl | rfl + · exact conn_refl G ω _ + · exact .single ⟨e,he,hcd⟩ + · exact conn_symm G ω (.single ⟨e,he,hcd⟩) + · exact conn_refl G ω _ + + + +theorem conn_restrict_away_from_cluster (G : BondGraph V E) (ω S : Set E) + (hS : S ⊆ ω) (u x y : V) (hx : x ∉ cluster G ω u) (hc : Conn G S x y) : + Conn G (S ∩ internalEdges G (cluster G ω u)ᶜ) x y := by + apply conn_restrict_of_no_simpleVisit G S (cluster G ω u) x y hc + rintro ⟨q,_,z,hz,hzu⟩ + have hxz : Conn G ω x z := conn_mono G hS + ((conn_iff_reachable G S x z).mpr ⟨q.takeUntil z hz⟩) + exact hx (hzu.trans (conn_symm G ω hxz)) + +theorem conn_delete_cluster (G : BondGraph V E) (D : Set V) (ω : Set E) + (u x y : V) (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) + (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : + Conn G (S ∩ internalEdges G (D \ cluster G (ω ∩ internalEdges G D) u)) x y := by + apply conn_mono G ?_ (conn_restrict_away_from_cluster G _ S hS u x y hx hc) + rintro e ⟨he,heA⟩ + exact ⟨he,fun z hz => ⟨(hS he).2 z hz,heA z hz⟩⟩ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem counted_delete_other_cluster (w : RawCorridor G k) (D : Set V) (ω : Set E) + (u x y : V) (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : + w.counted (D \ cluster G (ω ∩ internalEdges G D) u) ω x y ↔ w.counted D ω x y := by + let A := cluster G (ω ∩ internalEdges G D) u + have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := + Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) + constructor + · intro hc + apply (w.counted_iff D ω x y).mpr + refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ + · intro e he + refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ + intro hbad + have hd := conn_delete_cluster G D ω u x y hx + ((ω ∩ internalEdges G D) \ {e}) Set.sdiff_subset hbad + apply (hc.2.2.2.1 e he).2 + apply conn_mono G ?_ hd + rintro f ⟨⟨⟨hfω,hfD⟩,hfne⟩,hfnew⟩ + exact ⟨⟨hfω,hfnew⟩,hfne⟩ + · apply Set.disjoint_left.mpr + intro e he ho + obtain ⟨z,hzi,hze⟩ := he.1 + obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 + have hz : z ∈ q.support := w.counted_support_subset_walk (D \ A) ω x y hc q z + (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1) + have hxz : Conn G (ω ∩ internalEdges G D) x z := conn_mono G hs + ((conn_iff_reachable G _ x z).mpr ⟨q.takeUntil z hz⟩) + have heA : e ∈ internalEdges G (D \ A) := by + intro a ha + refine ⟨ho.2 a ha,?_⟩ + intro hau + have hza := conn_of_open_incident G _ e ho z a hze ha + exact hx (hau.trans (conn_symm G _ (hxz.trans hza))) + exact Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,heA⟩ + · intro hc + have hnew := conn_delete_cluster G D ω u x y hx _ (Set.Subset.refl _) hc.2.2.1 + have hc' : Conn G (ω ∩ internalEdges G (D \ A)) x y := by + apply conn_mono G ?_ hnew + rintro e ⟨⟨heω,_⟩,heA⟩ + exact ⟨heω,heA⟩ + exact (w.counted_iff _ ω x y).mpr ⟨hc.1, + corridorCounted_restrict G _ _ Set.sdiff_subset (Set.Subset.refl _) x y hc' hc.2.2⟩ + +end RawCorridor +end ExteriorCorridorGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExteriorWeightedConnections +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem corridorPenalty_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (u x y : V) + (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : + corridorPenalty G P p k (D \ cluster G (ω ∩ internalEdges G D) u) ω x y = + corridorPenalty G P p k D ω x y := by + unfold corridorPenalty + apply tsum_congr + intro w + simp only [corridorPenaltyTerm,w.counted_delete_other_cluster D ω u x y hx] + + + +theorem deformedConnection_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (u x y : V) + (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : + deformedConnection G P p k t (D \ cluster G (ω ∩ internalEdges G D) u) ω x y = + deformedConnection G P p k t D ω x y := by + let A := cluster G (ω ∩ internalEdges G D) u + have hs : ω ∩ internalEdges G (D \ A) ⊆ ω ∩ internalEdges G D := + Set.inter_subset_inter_right _ (internalEdges_mono G Set.sdiff_subset) + have hg : (x ∈ D \ A ∧ y ∈ D \ A ∧ Conn G (ω ∩ internalEdges G (D \ A)) x y) ↔ + (x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y) := by + constructor + · exact fun h => ⟨h.1.1,h.2.1.1,conn_mono G hs h.2.2⟩ + · rintro ⟨hxD,hyD,hc⟩ + have hy : y ∉ A := fun hy => hx (hy.trans (conn_symm G _ hc)) + refine ⟨⟨hxD,hx⟩,⟨hyD,hy⟩,?_⟩ + apply conn_mono G ?_ (conn_delete_cluster G D ω u x y hx _ (Set.Subset.refl _) hc) + rintro e ⟨⟨heω,_⟩,heA⟩ + exact ⟨heω,heA⟩ + dsimp only [A] at hg + simp only [deformedConnection,hg,corridorPenalty_delete_other_cluster G P p k D ω u x y hx] + +noncomputable def deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : ℝ := + ∑' y, deformedConnection G P p k t D ω x y + +theorem deformedClusterMass_delete_other_cluster (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (u x : V) + (hx : x ∉ cluster G (ω ∩ internalEdges G D) u) : + deformedClusterMass G P p k t (D \ cluster G (ω ∩ internalEdges G D) u) ω x = + deformedClusterMass G P p k t D ω x := by + exact tsum_congr (fun y => deformedConnection_delete_other_cluster G P p k t D ω u x y hx) + +theorem deformedConnection_le_conn (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (ω : Set E) (x y : V) : deformedConnection G P p k t D ω x y ≤ + if Conn G ω x y then 1 else 0 := by + by_cases hc : Conn G ω x y + · simpa only [hc,ite_true] using deformedConnection_le_one G P hP p k t ht D ω x y + · have hn : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hc (conn_mono G Set.inter_subset_left h) + simp only [deformedConnection,hn,hc,and_false,ite_false,le_refl] + +theorem measurable_deformedClusterMass [Countable V] [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : + Measurable (fun ω => deformedClusterMass G P p k t D ω x) := + Measurable.tsum (fun y => measurable_deformedConnection G P p k t D x y) + +end ExteriorWeightedConnections +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeformedMassIntegrals +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedConnection_finite_support (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : + (deformedConnection G P p k t D ω x).HasFiniteSupport := by + apply hf.subset + intro y hy + by_contra hn + have hnc : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hn (conn_mono G Set.inter_subset_left h) + exact hy (by simp only [deformedConnection,hnc,and_false,ite_false]) + +theorem deformedClusterMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : + 0 ≤ deformedClusterMass G P p k t D ω x := + tsum_nonneg (deformedConnection_nonneg G P p k t D ω x) + +theorem deformedClusterMass_le_ncard (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + deformedClusterMass G P p k t D ω x ≤ ((cluster G ω x).ncard:ℝ) := by + unfold deformedClusterMass + rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by + have hn : ¬Conn G ω x y := fun hc => hy (hf.mem_toFinset.mpr hc) + have hn' : ¬Conn G (ω ∩ internalEdges G D) x y := fun hc => hn (conn_mono G Set.inter_subset_left hc) + simp only [deformedConnection,hn',and_false,ite_false])] + calc + _ ≤ ∑ _y ∈ hf.toFinset, (1:ℝ) := Finset.sum_le_sum (fun y _ => deformedConnection_le_one G P hP p k t ht D ω x y) + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hf] + +theorem integrable_deformedClusterMass [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : + Integrable (fun ω => deformedClusterMass G P p k t D ω x) (law p) := by + apply Integrable.mono' (susceptibility_eq_integral G hloc hqt p hp x).1 + (measurable_deformedClusterMass G P p k t D x).aestronglyMeasurable + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [Real.norm_of_nonneg (deformedClusterMass_nonneg G P p k t D ω x)] + exact deformedClusterMass_le_ncard G P hP p k t ht D ω x hω + + + +theorem deformedSusceptibility_eq_integral [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x : V) : + deformedSusceptibility G P p k t D x = ∫ ω, deformedClusterMass G P p k t D ω x ∂law p := by + have hi := integrable_deformedConnection G P hP p k t ht D x + have hs : Summable (fun y => ∫ ω, ‖deformedConnection G P p k t D ω x y‖ ∂law p) := by + simp only [Real.norm_of_nonneg (deformedConnection_nonneg G P p k t D _ x _)] + exact summable_deformedKernel G hloc hqt P hP p hp k t ht D x + exact integral_tsum_of_summable_integral_norm hi hs + +end DeformedMassIntegrals +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExactComponentRestriction +attribute [local instance] Classical.propDecidable Classical.decEq + + +def OpenClosed (G : BondGraph V E) (ω : Set E) (A : Set V) : Prop := + ∀ e ∈ ω, ∀ z ∈ G e, z ∈ A → ∀ a ∈ G e, a ∈ A + +theorem openClosed_cluster (G : BondGraph V E) (ω : Set E) (x : V) : + OpenClosed G ω (cluster G ω x) := by + intro e he z hz hx a ha + exact hx.trans (conn_of_open_incident G ω e he z a hz ha) + +theorem conn_restrict_openClosed (G : BondGraph V E) (ω S : Set E) (hS : S ⊆ ω) + (A : Set V) (hA : OpenClosed G ω A) (x y : V) (hx : x ∈ A) (hc : Conn G S x y) : + y ∈ A ∧ Conn G (S ∩ internalEdges G A) x y := by + induction hc with + | refl => exact ⟨hx,conn_refl G _ x⟩ + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + have ha : a ∈ G e := by simp [heq] + have hb : b ∈ G e := by simp [heq] + have hei : e ∈ internalEdges G A := hA e (hS he) a ha ih.1 + exact ⟨hei b hb,ih.2.tail ⟨e,⟨he,hei⟩,heq⟩⟩ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem counted_restrict_openClosed (w : RawCorridor G k) (D A : Set V) (ω : Set E) + (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : + w.counted (D ∩ A) ω x y ↔ w.counted D ω x y := by + have hs : ω ∩ internalEdges G (D ∩ A) ⊆ ω ∩ internalEdges G D := + Set.inter_subset_inter_right _ (internalEdges_mono G Set.inter_subset_left) + have hrest (S : Set E) (hS : S ⊆ ω ∩ internalEdges G D) (hc : Conn G S x y) : + Conn G (S ∩ internalEdges G (D ∩ A)) x y := by + apply conn_mono G ?_ (conn_restrict_openClosed G _ S hS A hA x y hx hc).2 + rintro e ⟨he,heA⟩ + exact ⟨he,fun z hz => ⟨(hS he).2 z hz,heA z hz⟩⟩ + constructor + · intro hc + apply (w.counted_iff D ω x y).mpr + refine ⟨hc.1,conn_mono G hs hc.2.2.1,?_,?_⟩ + · intro e he + refine ⟨hs (hc.2.2.2.1 e he).1,?_⟩ + intro hbad + apply (hc.2.2.2.1 e he).2 + apply conn_mono G ?_ (hrest _ Set.sdiff_subset hbad) + rintro f ⟨⟨⟨hfω,_⟩,hfne⟩,hfnew⟩ + exact ⟨⟨hfω,hfnew⟩,hfne⟩ + · apply Set.disjoint_left.mpr + intro e he ho + obtain ⟨z,hzi,hze⟩ := he.1 + have hz : z ∈ A := (hc.2.1 z (List.mem_toFinset.mp (Finset.mem_sdiff.mp hzi).1)).2 + have heA : e ∈ internalEdges G (D ∩ A) := fun a ha => ⟨ho.2 a ha,hA e ho z hze hz a ha⟩ + exact Set.disjoint_left.mp hc.2.2.2.2 he ⟨ho.1,heA⟩ + · intro hc + have hc' : Conn G (ω ∩ internalEdges G (D ∩ A)) x y := by + apply conn_mono G ?_ (hrest _ (Set.Subset.refl _) hc.2.2.1) + rintro e ⟨⟨heω,_⟩,heA⟩ + exact ⟨heω,heA⟩ + exact (w.counted_iff _ ω x y).mpr ⟨hc.1, + corridorCounted_restrict G _ _ Set.inter_subset_left (Set.Subset.refl _) x y hc' hc.2.2⟩ + +end RawCorridor +end ExactComponentRestriction +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section InternalWeightedRestriction +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem corridorPenalty_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (D A : Set V) (ω : Set E) + (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : + corridorPenalty G P p k (D ∩ A) ω x y = corridorPenalty G P p k D ω x y := by + unfold corridorPenalty + apply tsum_congr + intro w + simp only [corridorPenaltyTerm,w.counted_restrict_openClosed D A ω hA x y hx] + +theorem deformedConnection_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D A : Set V) (ω : Set E) + (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x y : V) (hx : x ∈ A) : + deformedConnection G P p k t (D ∩ A) ω x y = deformedConnection G P p k t D ω x y := by + have hg : (x ∈ D ∩ A ∧ y ∈ D ∩ A ∧ Conn G (ω ∩ internalEdges G (D ∩ A)) x y) ↔ + (x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y) := by + constructor + · exact fun h => ⟨h.1.1,h.2.1.1,conn_mono G + (Set.inter_subset_inter_right _ (internalEdges_mono G Set.inter_subset_left)) h.2.2⟩ + · rintro ⟨hxD,hyD,hc⟩ + have hh := conn_restrict_openClosed G _ _ (Set.Subset.refl _) A hA x y hx hc + refine ⟨⟨hxD,hx⟩,⟨hyD,hh.1⟩,conn_mono G ?_ hh.2⟩ + rintro e ⟨⟨heω,heD⟩,heA⟩ + exact ⟨heω,fun z hz => ⟨heD z hz,heA z hz⟩⟩ + simp only [deformedConnection,hg,corridorPenalty_restrict_openClosed G P p k D A ω hA x y hx] + +theorem deformedClusterMass_restrict_openClosed (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D A : Set V) (ω : Set E) + (hA : OpenClosed G (ω ∩ internalEdges G D) A) (x : V) (hx : x ∈ A) : + deformedClusterMass G P p k t (D ∩ A) ω x = deformedClusterMass G P p k t D ω x := + tsum_congr (fun y => deformedConnection_restrict_openClosed G P p k t D A ω hA x y hx) + + +theorem deformedClusterMass_restrict_config (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (S : Set E) + (hS : internalEdges G D ⊆ S) : + deformedClusterMass G P p k t D (ω ∩ S) x = deformedClusterMass G P p k t D ω x := by + have he : (ω ∩ S) ∩ internalEdges G D = ω ∩ internalEdges G D := by + ext e + exact ⟨fun h => ⟨h.1.1,h.2⟩,fun h => ⟨⟨h.1,hS h.2⟩,h.2⟩⟩ + apply tsum_congr + intro y + have hc (w : RawCorridor G k) : w.counted D (ω ∩ S) x y ↔ w.counted D ω x y := by + simp only [RawCorridor.counted,corridorCounted,he] + simp only [deformedConnection,corridorPenalty,corridorPenaltyTerm,hc,he] + +end InternalWeightedRestriction +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory ProbabilityTheory +section DisjointCoordinateObservables +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem restriction_functions_independent (p : unitInterval) (S T : Set E) + (hST : Disjoint S T) (f g : Set E → ℝ) (hf : Measurable f) (hg : Measurable g) + (hfS : ∀ ω, f ω = f (ω ∩ S)) (hgT : ∀ ω, g ω = g (ω ∩ T)) : + IndepFun f g (law p) := by + rw [indepFun_iff_measure_inter_preimage_eq_mul] + intro A B hA hB + have he (h : Set E → ℝ) (U : Set E) (hU : ∀ ω, h ω = h (ω ∩ U)) (C : Set ℝ) : + (fun ω => ω ∩ U) ⁻¹' (h ⁻¹' C) = h ⁻¹' C := by + ext ω + simp only [Set.mem_preimage,←hU ω] + simpa only [he f S hfS A,he g T hgT B] using + restriction_events_independent p S T hST (f ⁻¹' A) (g ⁻¹' B) + (hA.preimage hf) (hB.preimage hg) + +theorem integral_mul_disjoint_coordinates (p : unitInterval) (S T : Set E) + (hST : Disjoint S T) (f g : Set E → ℝ) (hf : Measurable f) (hg : Measurable g) + (hfS : ∀ ω, f ω = f (ω ∩ S)) (hgT : ∀ ω, g ω = g (ω ∩ T)) : + (∫ ω, f ω*g ω ∂law p) = (∫ ω, f ω ∂law p)*(∫ ω, g ω ∂law p) := + (restriction_functions_independent p S T hST f g hf hg hfS hgT).integral_mul_eq_mul_integral + hf.aestronglyMeasurable hg.aestronglyMeasurable + +end DisjointCoordinateObservables +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExactWeightedClusterCell +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem induced_cluster_restrict_incident_iff (G : BondGraph V E) (hloc : LocallyFinite G) + (W : Finset V) (D : Set V) (ω : Set E) (x : V) : + cluster G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) x = (W:Set V) ↔ + cluster G (ω ∩ internalEdges G D) x = (W:Set V) := by + rw [Set.inter_right_comm] + exact cluster_restrict_incident_eq_iff G hloc W _ (Finset.Subset.refl _) _ x + +theorem weighted_cluster_cell_local (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (W : Finset V) (x : V) + (ω : Set E) : + (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) + then deformedClusterMass G P p k t D ω x else 0) = + (if cluster G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) x = (W:Set V) + then deformedClusterMass G P p k t D (ω ∩ (incidentSupport G hloc W:Set E)) x else 0) := by + simp only [induced_cluster_restrict_incident_iff] + split_ifs with hW + · have hx : x ∈ (W:Set V) := hW ▸ conn_refl G _ x + have hA : OpenClosed G (ω ∩ internalEdges G D) (W:Set V) := hW ▸ openClosed_cluster G _ x + have hW' := (induced_cluster_restrict_incident_iff G hloc W D ω x).mpr hW + have hA' : OpenClosed G ((ω ∩ (incidentSupport G hloc W:Set E)) ∩ internalEdges G D) (W:Set V) := + hW' ▸ openClosed_cluster G _ x + rw [←deformedClusterMass_restrict_openClosed G P p k t D W ω hA x hx, + ←deformedClusterMass_restrict_openClosed G P p k t D W _ hA' x hx] + symm + apply deformedClusterMass_restrict_config + intro e he + exact (mem_incidentSupport G hloc W e).mpr + ⟨(G e).out.1,(he _ (Sym2.out_fst_mem _)).2,Sym2.out_fst_mem _⟩ + · rfl + + + +theorem weighted_cluster_cell_exposure [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (W : Finset V) (x y : V) : + (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) + then deformedClusterMass G P p k t D ω x else 0) * + deformedClusterMass G P p k t (D \ (W:Set V)) ω y ∂law p) = + (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) + then deformedClusterMass G P p k t D ω x else 0) ∂law p) * + deformedSusceptibility G P p k t (D \ (W:Set V)) y := by + rw [deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht] + apply integral_mul_disjoint_coordinates p (incidentSupport G hloc W:Set E) + (incidentSupport G hloc W:Set E)ᶜ disjoint_compl_right + · exact Measurable.ite ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) + (measurable_deformedClusterMass G P p k t D x) measurable_const + · exact measurable_deformedClusterMass G P p k t _ y + · exact weighted_cluster_cell_local G hloc P p k t D W x + · intro ω + symm + apply deformedClusterMass_restrict_config + rw [complement_incidentSupport] + exact fun e he z hz => (he z hz).2 + +end ExactWeightedClusterCell +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section InducedClusterPartition +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem integral_induced_cluster_finite_partition [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (hp : p < pc G) (D : Set V) (x : V) + (f : Set E → ℝ) (hf : Integrable f (law p)) : + (∫ ω, f ω ∂law p) = ∑' W : Finset V, + ∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then f ω else 0) ∂law p := by + let F (W : Finset V) (ω : Set E) := if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then f ω else 0 + have hi (W : Finset V) : Integrable (F W) (law p) := by + have he : F W = {ω : Set E | cluster G (ω ∩ internalEdges G D) x = (W:Set V)}.indicator f := by + funext ω + simp only [F,Set.indicator,Set.mem_ofPred_eq] + split_ifs <;> rfl + rw [he] + exact hf.indicator ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) + have hb (S : Finset (Finset V)) (ω : Set E) : (∑ W ∈ S, ‖F W ω‖) ≤ ‖f ω‖ := by + by_cases hex : ∃ W ∈ S, cluster G (ω ∩ internalEdges G D) x = (W:Set V) + · obtain ⟨W,hWS,hW⟩ := hex + rw [Finset.sum_eq_single W] + · simp only [F,hW,ite_true,le_refl] + · intro U _ hU + have hu : cluster G (ω ∩ internalEdges G D) x ≠ (U:Set V) := fun h => hU (Finset.coe_injective (h.symm.trans hW)) + simp only [F,ite_eq_right hu,norm_zero] + · exact fun h => (h hWS).elim + · have he (W : Finset V) (hW : W ∈ S) : cluster G (ω ∩ internalEdges G D) x ≠ (W:Set V) := fun h => hex ⟨W,hW,h⟩ + calc + _ = 0 := Finset.sum_eq_zero (fun W hW => by simp only [F,ite_eq_right (he W hW),norm_zero]) + _ ≤ _ := norm_nonneg _ + have hn : Summable (fun W => ∫ ω, ‖F W ω‖ ∂law p) := by + apply summable_of_sum_le (fun _ => integral_nonneg (fun _ => norm_nonneg _)) + (c := ∫ ω, ‖f ω‖ ∂law p) + intro S + rw [←integral_finsetSum _ (fun W _ => (hi W).norm)] + exact integral_mono (integrable_finsetSum _ (fun W _ => (hi W).norm)) hf.norm (hb S) + calc + _ = ∫ ω, ∑' W : Finset V, F W ω ∂law p := by + apply integral_congr_ae + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact (tsum_cluster_cells G (ω ∩ internalEdges G D) x + (hω.subset (fun _ h => conn_mono G Set.inter_subset_left h)) (f ω)).symm + _ = _ := (integral_tsum_of_summable_integral_norm hi hn).symm + +end InducedClusterPartition +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeformedClusterProducts +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedClusterMass_eq_zero_of_not_mem (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (hx : x ∉ D) : + deformedClusterMass G P p k t D ω x = 0 := by + simp only [deformedClusterMass,deformedConnection,hx,false_and,ite_false,tsum_zero] + +theorem deformed_distinct_product_eq_exterior (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + (if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) = + deformedClusterMass G P p k t D ω x * + deformedClusterMass G P p k t (D \ cluster G (ω ∩ internalEdges G D) x) ω y := by + by_cases hc : Conn G (ω ∩ internalEdges G D) x y + · rw [ite_eq_right (not_not_intro hc),deformedClusterMass_eq_zero_of_not_mem G P p k t _ ω y + (fun h => h.2 hc),mul_zero] + · rw [ite_eq_left hc,deformedClusterMass_delete_other_cluster G P p k t D ω x y hc] + +theorem integrable_deformed_product [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + Integrable (fun ω => deformedClusterMass G P p k t D ω x * + deformedClusterMass G P p k t D ω y) (law p) := by + apply Integrable.mono' (subcritical_cluster_association G hloc hqt p hp x y).1 + ((measurable_deformedClusterMass G P p k t D x).mul + (measurable_deformedClusterMass G P p k t D y)).aestronglyMeasurable + filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy + dsimp only [Pi.mul_apply] + rw [Real.norm_of_nonneg (mul_nonneg (deformedClusterMass_nonneg G P p k t D ω x) + (deformedClusterMass_nonneg G P p k t D ω y))] + exact mul_le_mul (deformedClusterMass_le_ncard G P hP p k t ht D ω x hx) + (deformedClusterMass_le_ncard G P hP p k t ht D ω y hy) + (deformedClusterMass_nonneg G P p k t D ω y) (Nat.cast_nonneg _) + +theorem integrable_distinct_deformed_product [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + Integrable (fun ω => if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) (law p) := by + have he : (fun ω => if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) = + {ω | Conn G (ω ∩ internalEdges G D) x y}ᶜ.indicator + (fun ω => deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y) := by + funext ω + simp only [Set.indicator,Set.mem_compl_iff,Set.mem_ofPred_eq] + rw [he] + exact (integrable_deformed_product G hloc hqt P hP p hp k t ht D x y).indicator + (((measurableSet_conn G x y).preimage (measurable_inter_const (internalEdges G D))).compl) + +end DeformedClusterProducts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FreshWeightedMass +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def deformedFreshExteriorMoment (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) (ω : Set E) : ℝ := + deformedClusterMass G P p k t D ω x * + deformedSusceptibility G P p k t (D \ cluster G (ω ∩ internalEdges G D) x) y + +theorem deformedSusceptibility_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : + 0 ≤ deformedSusceptibility G P p k t D x := + tsum_nonneg (deformedKernel_nonneg G P p k t D x) + +theorem deformedFreshExteriorMoment_eq_tsum (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) (ω : Set E) + (hf : (cluster G (ω ∩ internalEdges G D) x).Finite) : + deformedFreshExteriorMoment G P p k t D x y ω = ∑' W : Finset V, + if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then + deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t (D \ (W:Set V)) y else 0 := by + rw [←tsum_cluster_cells G (ω ∩ internalEdges G D) x hf (deformedFreshExteriorMoment G P p k t D x y ω)] + apply tsum_congr + intro W + split_ifs with hW + · simp only [deformedFreshExteriorMoment,hW] + · rfl + +theorem integrable_deformedFreshExteriorMoment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + Integrable (deformedFreshExteriorMoment G P p k t D x y) (law p) := by + have hm : AEStronglyMeasurable (deformedFreshExteriorMoment G P p k t D x y) (law p) := by + have hh : Measurable (fun ω => ∑' W : Finset V, + if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then + deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t (D \ (W:Set V)) y else 0) := by + apply Measurable.tsum + intro W + exact Measurable.ite ((measurableSet_cluster_eq G x W).preimage (measurable_inter_const _)) + ((measurable_deformedClusterMass G P p k t D x).mul_const _) measurable_const + apply hh.aestronglyMeasurable.congr + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact (deformedFreshExteriorMoment_eq_tsum G P p k t D x y ω + (hω.subset (fun _ h => conn_mono G Set.inter_subset_left h))).symm + apply Integrable.mono' ((integrable_deformedClusterMass G hloc hqt P hP p hp k t ht D x).mul_const + (susceptibility G p y)) hm + exact Filter.Eventually.of_forall (fun ω => by + dsimp only [deformedFreshExteriorMoment] + rw [Real.norm_of_nonneg (mul_nonneg (deformedClusterMass_nonneg G P p k t D ω x) + (deformedSusceptibility_nonneg G P p k t _ y))] + exact mul_le_mul_of_nonneg_left (deformedSusceptibility_le G hloc hqt P hP p hp k t ht _ y) + (deformedClusterMass_nonneg G P p k t D ω x)) + +end FreshWeightedMass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedExposureIdentity +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem integral_deformedFreshExteriorMoment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + (∫ ω, deformedFreshExteriorMoment G P p k t D x y ω ∂law p) = + ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by + rw [integral_induced_cluster_finite_partition G p hp D x _ + (integrable_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y), + integral_induced_cluster_finite_partition G p hp D x _ + (integrable_distinct_deformed_product G hloc hqt P hP p hp k t ht D x y)] + apply tsum_congr + intro W + have hl : (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then + deformedFreshExteriorMoment G P p k t D x y ω else 0) ∂law p) = + (∫ ω, (if cluster G (ω ∩ internalEdges G D) x = (W:Set V) then + deformedClusterMass G P p k t D ω x else 0) ∂law p) * + deformedSusceptibility G P p k t (D \ (W:Set V)) y := by + rw [←integral_mul_const] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + by_cases hW : cluster G (ω ∩ internalEdges G D) x = (W:Set V) + · simp only [hW,ite_true,deformedFreshExteriorMoment] + · simp only [hW,ite_false,zero_mul]) + rw [hl,←weighted_cluster_cell_exposure G hloc hqt P hP p hp k t ht D W x y] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + by_cases hW : cluster G (ω ∩ internalEdges G D) x = (W:Set V) + · simp only [hW,ite_true] + rw [deformed_distinct_product_eq_exterior,hW] + · simp only [hW,ite_false,zero_mul]) + +end WeightedExposureIdentity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedThreeArmEstimate +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +theorem summable_three_arm_pair (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a : V) : + Summable (fun bz : V×V => twoPoint G p x bz.1 * twoPoint G p bz.1 a * twoPoint G p bz.1 bz.2) := by + apply (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le + · exact fun bz => mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) + (twoPoint_nonneg G p _ _) + · intro bz + exact mul_le_mul_of_nonneg_right (mul_le_of_le_one_right (twoPoint_nonneg G p _ _) (twoPoint_le_one G p _ _)) + (twoPoint_nonneg G p _ _) + +theorem three_arm_real_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a z : V) : + (law p).real {ω | Conn G ω x a ∧ Conn G ω x z} ≤ + ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := by + have hs := (summable_three_arm_pair G hloc hqt p hp x a).prod_symm.prod_factor z + have hn (b : V) : 0 ≤ twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := + mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _) + have he : (∑' b, law p {ω | Conn G ω x b} * law p {ω | Conn G ω b a} * law p {ω | Conn G ω b z}) = + ENNReal.ofReal (∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z) := by + rw [ENNReal.ofReal_tsum_of_nonneg hn hs] + apply tsum_congr + intro b + rw [ENNReal.ofReal_mul (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)), + ENNReal.ofReal_mul (twoPoint_nonneg G p _ _)] + simp only [twoPoint,ENNReal.ofReal_toReal (measure_ne_top _ _)] + have hh := (three_arm_bound G p x a z).trans_eq he + exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hh).trans_eq (ENNReal.toReal_ofReal (tsum_nonneg hn)) + + + +theorem integral_size_membership_le (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x a : V) : + (∫ ω, (if Conn G ω x a then ((cluster G ω x).ncard:ℝ) else 0) ∂law p) ≤ + maxSusceptibility G p * (∑' b, twoPoint G p x b * twoPoint G p b a) := by + have he := integral_cluster_size_event G hloc hqt p hp x _ (measurableSet_conn G x a) + simp only [Set.mem_ofPred_eq] at he + rw [he] + have hs := summable_three_arm_pair G hloc hqt p hp x a + have hl : Summable (fun z => (law p).real {ω | Conn G ω x a ∧ Conn G ω x z}) := + (summable_twoPoint_subcritical G hloc hqt p hp x).of_nonneg_of_le (fun _ => measureReal_nonneg) + (fun _ => measureReal_mono (fun _ h => h.2)) + have hb : Summable (fun b => twoPoint G p x b * twoPoint G p b a) := + (summable_twoPoint_subcritical G hloc hqt p hp x).of_nonneg_of_le + (fun b => mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) + (fun b => mul_le_of_le_one_right (twoPoint_nonneg G p _ _) (twoPoint_le_one G p _ _)) + have hj : Summable (fun b => twoPoint G p x b * twoPoint G p b a * susceptibility G p b) := by + simpa only [tsum_mul_left,susceptibility] using hs.prod + calc + _ ≤ ∑' z, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := + hl.tsum_le_tsum (three_arm_real_bound G hloc hqt p hp x a) hs.prod_symm.prod + _ = ∑' b, ∑' z, twoPoint G p x b * twoPoint G p b a * twoPoint G p b z := hs.tsum_comm + _ = ∑' b, twoPoint G p x b * twoPoint G p b a * susceptibility G p b := by + simp only [tsum_mul_left,susceptibility] + _ ≤ ∑' b, twoPoint G p x b * twoPoint G p b a * maxSusceptibility G p := by + apply hj.tsum_le_tsum + (fun b => mul_le_mul_of_nonneg_left (susceptibility_le_max G hloc hqt p hp b) + (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _))) (hb.mul_right _) + _ = _ := by rw [tsum_mul_right,mul_comm] + +end WeightedThreeArmEstimate +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteNeighborhoodMass +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finset_sum_union_le (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) (S T : Finset V) : + (∑ x ∈ S ∪ T, f x) ≤ (∑ x ∈ S, f x) + ∑ x ∈ T, f x := by + have he := Finset.sum_union_inter (f := f) (s₁ := S) (s₂ := T) + have hn := Finset.sum_nonneg (s := S ∩ T) (fun x _ => hf x) + linarith + +theorem finset_sum_biUnion_le (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) + (W : Finset V) (N : V → Finset V) : + (∑ z ∈ W.biUnion N, f z) ≤ ∑ a ∈ W, ∑ z ∈ N a, f z := by + induction W using Finset.induction_on with + | empty => simp + | @insert a W ha ih => + rw [Finset.biUnion_insert,Finset.sum_insert ha] + exact (finset_sum_union_le f hf _ _).trans (add_le_add (le_refl _) ih) + +theorem closedBondNeighborhood_finset (G : BondGraph V E) (hloc : LocallyFinite G) (W : Finset V) : + closedBondNeighborhood G (W:Set V) = (W ∪ W.biUnion (neighbors G hloc) : Finset V) := by + ext z + simp only [closedBondNeighborhood,Set.mem_ofPred_eq,Finset.mem_coe,Finset.mem_union,Finset.mem_biUnion] + constructor + · rintro (hz | ⟨e,hz,a,ha,haW⟩) + · exact Or.inl hz + · by_cases hza : a = z + · exact Or.inl (hza ▸ haW) + · exact Or.inr ⟨a,haW,(mem_neighbors G hloc a z).mpr + ⟨e,(Sym2.mem_and_mem_iff hza).mp ⟨ha,hz⟩⟩⟩ + · rintro (hz | ⟨a,ha,haz⟩) + · exact Or.inl hz + · obtain ⟨e,he⟩ := (mem_neighbors G hloc a z).mp haz + exact Or.inr ⟨e,he.symm ▸ Sym2.mem_mk_right a z,a,he.symm ▸ Sym2.mem_mk_left a z,ha⟩ + +theorem neighborhood_mass_le (G : BondGraph V E) (hloc : LocallyFinite G) + (W : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) : + (∑' z : closedBondNeighborhood G (W:Set V), f z) ≤ + ∑ a ∈ W, (f a + ∑ z ∈ neighbors G hloc a, f z) := by + rw [closedBondNeighborhood_finset G hloc W,Finset.tsum_subtype'] + exact (finset_sum_union_le f hf _ _).trans + ((add_le_add (le_refl _) (finset_sum_biUnion_le f hf W (neighbors G hloc))).trans_eq + (Finset.sum_add_distrib).symm) + +end FiniteNeighborhoodMass +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/Corridors.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/Corridors.lean index e8d78b96cccd5eb9f6ab9ba39ace4e57b572aa6a..3c72c97786a2a8b0a8104cd9affb96af933a3c53 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/Corridors.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/Corridors.lean @@ -1,1230 +1,1230 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.TraceBounds - -namespace OAI - -/-! Corridors for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorEligibility -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem edge_has_label (w : RawCorridor G k) (s : Sym2 V) (hs : s ∈ w.path.edges) : - ∃ e ∈ w.retained, G e = s := by - induction s using Sym2.inductionOn with - | _ x y => - obtain ⟨_,e,_,he⟩ := w.path.adj_of_mem_edges hs - exact ⟨e,by simpa only [retained,Set.mem_ofPred_eq,he] using hs,he⟩ - -theorem image_retained (w : RawCorridor G k) : G '' w.retained = {s | s ∈ w.path.edges} := by - ext s - constructor - · rintro ⟨e,he,rfl⟩; exact he - · exact w.edge_has_label s - -theorem retained_ncard (hG : Function.Injective G) (w : RawCorridor G k) : - w.retained.ncard = w.path.length := by - rw [←hG.injOn.ncard_image (s := w.retained),w.image_retained] - have hh := List.toFinset_card_of_nodup w.path_isPath.isTrail.edges_nodup - simpa only [←List.coe_toFinset,Set.ncard_coe_finset,SimpleGraph.Walk.length_edges] using hh - - - -theorem support_subset_of_retained (w : RawCorridor G k) (hlen : 0 < w.path.length) - (D : Set V) (he : w.retained ⊆ internalEdges G D) : - ∀ z ∈ w.path.support, z ∈ D := by - intro z hz - obtain ⟨s,hs,hzs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil - (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hlen)).mp hz - obtain ⟨e,he',hGe⟩ := w.edge_has_label s hs - exact he he' z (hGe.symm ▸ hzs) - -theorem retained_subset_of_support (w : RawCorridor G k) (D : Set V) - (hs : ∀ z ∈ w.path.support, z ∈ D) : w.retained ⊆ internalEdges G D := by - intro e he z hz - exact hs z (SimpleGraph.Walk.mem_support_of_mem_edges he hz) - -theorem support_iff_retained (w : RawCorridor G k) (hlen : 0 < w.path.length) (D : Set V) : - (∀ z ∈ w.path.support, z ∈ D) ↔ w.retained ⊆ internalEdges G D := - ⟨w.retained_subset_of_support D,w.support_subset_of_retained hlen D⟩ - -theorem retained_incident_interior (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (e : E) (he : e ∈ w.retained) : ∃ z ∈ w.interior, z ∈ G e := by - change G e ∈ w.path.edges at he - generalize hab : G e = s at he - induction s using Sym2.inductionOn with - | _ a b => - have hedge : s(a,b) ∈ w.path.edges := he - have ha := w.path.fst_mem_support_of_mem_edges hedge - have hb := w.path.snd_mem_support_of_mem_edges hedge - have habne : a ≠ b := (w.path.adj_of_mem_edges hedge).1 - by_contra hn - have hna : a ∉ w.interior := fun hi => hn ⟨a,hi,by simp⟩ - have hnb : b ∉ w.interior := fun hi => hn ⟨b,hi,by simp⟩ - have hax : a = w.base ∨ a = w.endpoint := by simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,ha,true_and,Finset.mem_insert,Finset.mem_singleton,not_not] using hna - have hbx : b = w.base ∨ b = w.endpoint := by simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,hb,true_and,Finset.mem_insert,Finset.mem_singleton,not_not] using hnb - have hedge' : s(w.base,w.endpoint) ∈ w.path.edges := by - rcases hax with rfl | rfl <;> rcases hbx with rfl | rfl - · exact (habne rfl).elim - · exact hedge - · simpa only [Sym2.eq_swap] using hedge - · exact (habne rfl).elim - have hh := w.path_isPath.length_eq_one_of_mem_edges hedge' - omega - -theorem specified_disjoint_exterior (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) : - Disjoint (w.retained ∪ w.blockers) (internalEdges G (w.interior : Set V)ᶜ) := by - apply Set.disjoint_left.mpr - intro e he hx - obtain ⟨z,hz,he⟩ := he.elim (w.retained_incident_interior hlen e) (fun hb => hb.1) - exact hx z he hz - -end RawCorridor -end CorridorEligibility -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExactCorridorPattern -attribute [local instance] Classical.propDecidable Classical.decEq - -def edgePattern (A B : Finset E) : Set (Set E) := - {ω | (A : Set E) ⊆ ω ∧ Disjoint (B : Set E) ω} - -theorem edgePattern_eq_restriction (A B : Finset E) (hAB : Disjoint A B) : - edgePattern A B = {ω | ω ∩ ((A ∪ B : Finset E) : Set E) = (A : Set E)} := by - ext ω - constructor - · rintro ⟨ha,hb⟩ - apply Set.Subset.antisymm - · rintro e ⟨he,heQ⟩ - rcases Finset.mem_union.mp heQ with h | h - · exact h - · exact (Set.disjoint_left.mp hb h he).elim - · intro e he - exact ⟨ha he,Finset.mem_union_left _ he⟩ - · intro h - constructor - · intro e he - exact ((Set.ext_iff.mp h e).mpr he).1 - · apply Set.disjoint_left.mpr - intro e he hw - have ha : e ∈ A := (Set.ext_iff.mp h e).mp ⟨hw,Finset.mem_union_right _ he⟩ - exact Finset.disjoint_left.mp hAB ha he - -theorem measurableSet_edgePattern (A B : Finset E) (hAB : Disjoint A B) : - MeasurableSet (edgePattern A B) := by - rw [edgePattern_eq_restriction A B hAB] - exact measurableSet_finite_restriction (A∪B) {(A:Set E)} - - -theorem edgePattern_probability (A B : Finset E) (hAB : Disjoint A B) (p : unitInterval) : - (law p).real (edgePattern A B) = (p:ℝ)^A.card*(1-(p:ℝ))^B.card := by - let f : Set E → ℝ := fun ω => if ω ∈ edgePattern A B then 1 else 0 - have hf (ω : Set E) : f ω = f (ω ∩ ((A∪B:Finset E):Set E)) := by - simp only [f,edgePattern_eq_restriction A B hAB,Set.mem_ofPred_eq,Set.inter_assoc,Set.inter_self] - rw [←integral_event_indicator p _ (measurableSet_edgePattern A B hAB)] - change (∫ ω, f ω ∂law p) = _ - rw [integral_eq_bernoulliPolynomial (A∪B) p f hf] - trans bernoulliPolynomial (A∪B) (fun η => if η=A then 1 else 0) p - · apply bernoulliPolynomial_congr - intro η hη - have he : (η:Set E) ∩ ((A∪B:Finset E):Set E) = (η:Set E) := - Set.inter_eq_left.mpr hη - simp only [f,edgePattern_eq_restriction A B hAB,Set.mem_ofPred_eq,he,Finset.coe_inj] - · simp only [bernoulliPolynomial,ite_mul,zero_mul,one_mul] - rw [Finset.sum_ite_eq'] - simp only [Finset.mem_powerset,Finset.subset_union_left,ite_true,Finset.card_union_of_disjoint hAB, - Nat.add_sub_cancel_left] - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -def calibrationEvent (w : RawCorridor G k) : Set (Set E) := - {ω | w.retained ⊆ ω ∧ Disjoint w.blockers ω} - -theorem calibrationEvent_eq (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) : w.calibrationEvent = - edgePattern (w.retained_finite hG).toFinset (w.blockers_finite hloc).toFinset := by - simp only [calibrationEvent,edgePattern,Set.Finite.coe_toFinset] - -theorem calibration_probability (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (p : unitInterval) : - (law p).real w.calibrationEvent = (p:ℝ)^w.path.length*(1-(p:ℝ))^w.blockers.ncard := by - rw [w.calibrationEvent_eq hG hloc,edgePattern_probability] - · rw [←Set.ncard_eq_toFinset_card w.retained (w.retained_finite hG),←Set.ncard_eq_toFinset_card w.blockers (w.blockers_finite hloc),w.retained_ncard hG] - · apply Finset.disjoint_left.mpr - intro e he hb - exact Set.disjoint_left.mp w.retained_disjoint_blockers - ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) - - - -theorem calibration_identity (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (P : V → V → ℝ) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) : - w.weight P p * (law p).real w.calibrationEvent = w.probability P := by - rw [w.calibration_probability hG hloc p] - unfold weight - have h₁ := pow_ne_zero w.path.length hp.ne' - have h₂ := pow_ne_zero w.blockers.ncard (sub_pos.mpr hp₁).ne' - field_simp - -end RawCorridor -end ExactCorridorPattern -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorTerminalGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem path_internal_two_neighbors {H : SimpleGraph V} {u v z : V} - (q : H.Walk u v) (hq : q.IsPath) (hz : z ∈ q.support) (hzu : z ≠ u) (hzv : z ≠ v) : - ∃ a b : V, a ≠ b ∧ s(z,a) ∈ q.edges ∧ s(z,b) ∈ q.edges := by - induction q with - | nil => simp only [SimpleGraph.Walk.support_nil,List.mem_singleton] at hz; exact (hzu hz).elim - | @cons u a v h q ih => - have htail : q.IsPath := hq.of_cons - have huz : u ∉ q.support := ((SimpleGraph.Walk.cons_isPath_iff _ _).mp hq).2 - have hzq : z ∈ q.support := (List.mem_cons.mp hz).resolve_left hzu - by_cases hza : z = a - · subst z - cases q with - | nil => exact (hzv rfl).elim - | @cons a b v h' q => - refine ⟨u,b,?_,?_,?_⟩ - · intro hub - apply huz - subst b - simp - · simp only [SimpleGraph.Walk.edges_cons,List.mem_cons,Sym2.eq_swap]; exact Or.inl trivial - · simp only [SimpleGraph.Walk.edges_cons,List.mem_cons]; exact Or.inr (Or.inl trivial) - · obtain ⟨b,c,hbc,hb,hc⟩ := ih htail hzq hza hzv - exact ⟨b,c,hbc,List.mem_cons_of_mem _ hb,List.mem_cons_of_mem _ hc⟩ - - - -theorem pivotal_image_mem_edges (G : BondGraph V E) (ω : Set E) {x y : V} - (q : (openSimpleGraph G ω).Walk x y) (e : E) - (hp : ¬Conn G (ω \ {e}) x y) : G e ∈ q.edges := by - obtain ⟨l,hl,hmap,ho⟩ := walk_lift_bonds G ω q - by_contra he - apply hp - apply hl.conn - intro f hf - refine ⟨ho f hf,?_⟩ - intro hfe - have hfe' : f = e := Set.mem_singleton_iff.mp hfe - subst f - apply he - rw [←hmap] - exact List.mem_map_of_mem hf - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem counted_terminal_outside (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) - (hc : corridorCounted G w.retained w.blockers D ω x y) : x ∉ w.interior ∧ y ∉ w.interior := by - have hleft (x y : V) (hc : corridorCounted G w.retained w.blockers D ω x y) : x ∉ w.interior := by - intro hx - have hx' := Finset.mem_sdiff.mp hx - have hxs : x ∈ w.path.support := List.mem_toFinset.mp hx'.1 - have hxne : x ≠ w.base ∧ x ≠ w.endpoint := by - simpa only [Finset.mem_insert,Finset.mem_singleton,not_or] using hx'.2 - have hxu := hxne.1 - have hxv := hxne.2 - obtain ⟨a,b,hab,ha,hb⟩ := path_internal_two_neighbors w.path w.path_isPath hxs hxu hxv - obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.1 - let qp := q.bypass - have hqp : qp.IsPath := q.bypass_isPath - obtain ⟨e,he,hGe⟩ := w.edge_has_label _ ha - obtain ⟨f,hf,hGf⟩ := w.edge_has_label _ hb - have hea := pivotal_image_mem_edges G _ qp e (hc.2.1 e he).2 - have heb := pivotal_image_mem_edges G _ qp f (hc.2.1 f hf).2 - rw [hGe] at hea - rw [hGf] at heb - exact hab ((hqp.eq_snd_of_mem_edges hea).trans (hqp.eq_snd_of_mem_edges heb).symm) - exact ⟨hleft x y hc,hleft y x ((corridorCounted_symm G _ _ D ω x y).mp hc)⟩ - -end RawCorridor -end CorridorTerminalGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory ProbabilityTheory -section CorridorIndependence -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_inter_const (S : Set E) : Measurable (fun ω : Set E => ω ∩ S) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).and measurable_const - - -theorem restriction_events_independent (p : unitInterval) (S T : Set E) - (hST : Disjoint S T) (A B : Set (Set E)) (hA : MeasurableSet A) (hB : MeasurableSet B) : - (law p) ((fun ω => ω ∩ S) ⁻¹' A ∩ (fun ω => ω ∩ T) ⁻¹' B) = - (law p) ((fun ω => ω ∩ S) ⁻¹' A) * (law p) ((fun ω => ω ∩ T) ⁻¹' B) := by - let μ : Measure (E → Prop) := Measure.infinitePi (fun _ => bitLaw p) - let σ : E → MeasurableSpace (E → Prop) := fun e => - MeasurableSpace.comap (fun f : E → Prop => f e) inferInstance - have hi : iIndep σ μ := iIndepFun_infinitePi (X := fun (_ : E) (b : Prop) => b) - (fun _ => measurable_id) - have hle (e : E) : σ e ≤ (inferInstance : MeasurableSpace (E → Prop)) := - (measurable_pi_apply e).comap_le - have hr (S : Set E) : @Measurable (E → Prop) (Set E) (⨆ e ∈ S, σ e) inferInstance - (fun f => {e | f e} ∩ S) := by - let : MeasurableSpace (E → Prop) := ⨆ e ∈ S, σ e - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - change @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun f => f e ∧ e ∈ S) - by_cases he : e ∈ S - · have hm : @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun f => f e) := - Measurable.of_comap_le (le_iSup_of_le e (le_iSup_of_le he le_rfl)) - simpa only [Set.mem_inter_iff,Set.mem_ofPred_eq,he,and_true] using hm - · simpa only [Set.mem_inter_iff,Set.mem_ofPred_eq,he,and_false] using - (measurable_const : @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun _ => False)) - have hm : (law p : Measure (Set E)) = μ.map (fun f => {e | f e}) := by - simp only [law,setBernoulli_eq_map,Set.mem_univ,μ,bitLaw,bernoulliMeasure_def] - rw [hm,Measure.map_apply measurable_setOfPred ((hA.preimage (measurable_inter_const S)).inter - (hB.preimage (measurable_inter_const T))), - Measure.map_apply measurable_setOfPred (hA.preimage (measurable_inter_const S)), - Measure.map_apply measurable_setOfPred (hB.preimage (measurable_inter_const T))] - exact (Indep_iff _ _ _).mp (indep_iSup_of_disjoint hle hi hST) _ _ - (hA.preimage (hr S)) (hB.preimage (hr T)) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem calibration_restriction (w : RawCorridor G k) (ω : Set E) : - ω ∈ w.calibrationEvent ↔ ω ∩ (w.retained ∪ w.blockers) ∈ w.calibrationEvent := by - constructor - · rintro ⟨ha,hb⟩ - exact ⟨fun e he => ⟨ha he,Or.inl he⟩,hb.mono_right Set.inter_subset_left⟩ - · rintro ⟨ha,hb⟩ - refine ⟨fun e he => (ha he).1,Set.disjoint_left.mpr ?_⟩ - intro e he hw - exact Set.disjoint_left.mp hb he ⟨hw,Or.inr he⟩ - - - -theorem calibration_independent (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (p : unitInterval) - (A : Set (Set E)) (hA : MeasurableSet A) : - (law p) (w.calibrationEvent ∩ (fun ω => ω ∩ internalEdges G (w.interior : Set V)ᶜ) ⁻¹' A) = - (law p) w.calibrationEvent * - (law p) ((fun ω => ω ∩ internalEdges G (w.interior : Set V)ᶜ) ⁻¹' A) := by - have hQ : MeasurableSet w.calibrationEvent := by - rw [w.calibrationEvent_eq hG hloc] - apply measurableSet_edgePattern - apply Finset.disjoint_left.mpr - intro e he hb - exact Set.disjoint_left.mp w.retained_disjoint_blockers - ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) - have heq : (fun ω => ω ∩ (w.retained ∪ w.blockers)) ⁻¹' w.calibrationEvent = w.calibrationEvent := by - ext ω; exact (w.calibration_restriction ω).symm - have hh := restriction_events_independent p _ _ (w.specified_disjoint_exterior hlen) - w.calibrationEvent A hQ hA - simpa only [heq] using hh - -end RawCorridor -end CorridorIndependence -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorContraction -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem conn_union_attachment (G : BondGraph V E) (S T : Set E) (A : Set V) - (hclosed : ∀ a b, a ∈ A → Conn G S a b → b ∈ A) - (hT : ∀ e ∈ T, ∀ z ∈ G e, z ∈ A) {x y : V} (hc : Conn G (S ∪ T) x y) : - Conn G S x y ∨ x ∈ A ∧ y ∈ A := by - induction hc with - | refl => exact Or.inl (conn_refl G S x) - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - rcases he with he | he - · have hab : Conn G S a b := Relation.ReflTransGen.single ⟨e,he,heq⟩ - exact ih.elim (fun h => Or.inl (conn_trans G S h hab)) - (fun h => Or.inr ⟨h.1,hclosed a b h.2 hab⟩) - · have ha := hT e he a (heq.symm ▸ (by simp : a ∈ s(a,b))) - have hb := hT e he b (heq.symm ▸ (by simp : b ∈ s(a,b))) - exact Or.inr ⟨ih.elim (fun h => hclosed a x ha (conn_symm G S h)) And.left,hb⟩ - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -def exterior (w : RawCorridor G k) (ω : Set E) : Set E := - ω ∩ internalEdges G (w.interior : Set V)ᶜ - -def attachment (w : RawCorridor G k) (ω : Set E) : Set V := - {z | z ∈ w.path.support ∨ Conn G (w.exterior ω) w.base z ∨ Conn G (w.exterior ω) w.endpoint z} - -theorem support_exterior_ports (w : RawCorridor G k) {z : V} - (hz : z ∈ w.path.support) (ho : z ∉ w.interior) : z = w.base ∨ z = w.endpoint := by - simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,hz,true_and, - Finset.mem_insert,Finset.mem_singleton,not_not] using ho - -theorem attachment_closed (w : RawCorridor G k) (ω : Set E) (a b : V) - (ha : a ∈ w.attachment ω) (hc : Conn G (w.exterior ω) a b) : b ∈ w.attachment ω := by - rcases ha with ha | ha | ha - · rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hc with rfl | ho - · exact Or.inl ha - · rcases w.support_exterior_ports ha ho.1 with rfl | rfl - · exact Or.inr (Or.inl hc) - · exact Or.inr (Or.inr hc) - · exact Or.inr (Or.inl (conn_trans G _ ha hc)) - · exact Or.inr (Or.inr (conn_trans G _ ha hc)) - -theorem open_subset_exterior_retained (w : RawCorridor G k) (ω : Set E) - (hq : ω ∈ w.calibrationEvent) : ω ⊆ w.exterior ω ∪ w.retained := by - intro e he - by_cases hr : e ∈ w.retained - · exact Or.inr hr - · left - refine ⟨he,?_⟩ - intro z hz hi - exact Set.disjoint_left.mp hq.2 ⟨⟨z,hi,hz⟩,hr⟩ he - -theorem connection_exterior_or_attachment (w : RawCorridor G k) (ω : Set E) - (hq : ω ∈ w.calibrationEvent) {x y : V} (hc : Conn G ω x y) : - Conn G (w.exterior ω) x y ∨ x ∈ w.attachment ω ∧ y ∈ w.attachment ω := by - apply conn_union_attachment G _ w.retained (w.attachment ω) (w.attachment_closed ω) - (fun e he z hz => Or.inl (SimpleGraph.Walk.mem_support_of_mem_edges he hz)) - exact conn_mono G (w.open_subset_exterior_retained ω hq) hc - -theorem attachment_outside (w : RawCorridor G k) (ω : Set E) {z : V} - (ha : z ∈ w.attachment ω) (hz : z ∉ w.interior) : - Conn G (w.exterior ω) w.base z ∨ Conn G (w.exterior ω) w.endpoint z := by - rcases ha with ha | ha | ha - · rcases w.support_exterior_ports ha hz with rfl | rfl - · exact Or.inl (conn_refl G _ _) - · exact Or.inr (conn_refl G _ _) - · exact Or.inl ha - · exact Or.inr ha - - -theorem counted_exterior_orientation (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) - (hc : corridorCounted G w.retained w.blockers Set.univ ω x y) : - ¬Conn G (w.exterior ω) w.base w.endpoint ∧ - ((Conn G (w.exterior ω) w.base x ∧ Conn G (w.exterior ω) w.endpoint y) ∨ - (Conn G (w.exterior ω) w.endpoint x ∧ Conn G (w.exterior ω) w.base y)) := by - have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) - have hc' : Conn G ω x y := by simpa only [hi,Set.inter_univ] using hc.1 - have hs : w.retained.Nonempty := by - have hp : w.path.edges ≠ [] := by - intro he - have hh := congrArg List.length he - simp only [SimpleGraph.Walk.length_edges,List.length_nil] at hh - omega - obtain ⟨s,hs⟩ := List.exists_mem_of_ne_nil _ hp - obtain ⟨e,he,_⟩ := w.edge_has_label s hs - exact ⟨e,he⟩ - have hnot : ¬Conn G (w.exterior ω) x y := by - intro h - obtain ⟨e,he⟩ := hs - apply (hc.2.1 e he).2 - apply conn_mono G ?_ h - intro f hf - refine ⟨?_,?_⟩ - · simpa only [hi,Set.inter_univ] using hf.1 - · intro hfe - have hfe' := Set.mem_singleton_iff.mp hfe - subst f - exact Set.disjoint_left.mp (w.specified_disjoint_exterior hlen) (Or.inl he) hf.2 - have hatt := (w.connection_exterior_or_attachment ω hq hc').resolve_left hnot - have hout := w.counted_terminal_outside Set.univ ω x y hc - have hx := w.attachment_outside ω hatt.1 hout.1 - have hy := w.attachment_outside ω hatt.2 hout.2 - have hne : ¬Conn G (w.exterior ω) w.base w.endpoint := by - intro h - apply hnot - have hx' : Conn G (w.exterior ω) w.base x := hx.elim id (conn_trans G _ h) - have hy' : Conn G (w.exterior ω) w.base y := hy.elim id (conn_trans G _ h) - exact conn_trans G _ (conn_symm G _ hx') hy' - refine ⟨hne,?_⟩ - rcases hx with hx | hx <;> rcases hy with hy | hy - · exact (hnot (conn_trans G _ (conn_symm G _ hx) hy)).elim - · exact Or.inl ⟨hx,hy⟩ - · exact Or.inr ⟨hx,hy⟩ - · exact (hnot (conn_trans G _ (conn_symm G _ hx) hy)).elim - -end RawCorridor -end CorridorContraction -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CorridorBKCalibration -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -def exteriorOrientations (w : RawCorridor G k) (x y : V) : Set (Set E) := - orientedPivotalEvent G x y w.base w.endpoint ∪ orientedPivotalEvent G x y w.endpoint w.base - -theorem measurableSet_exteriorOrientations (w : RawCorridor G k) (x y : V) : - MeasurableSet (w.exteriorOrientations x y) := - (measurableSet_orientedPivotalEvent G x y w.base w.endpoint).union - (measurableSet_orientedPivotalEvent G x y w.endpoint w.base) - -omit [Countable V] [Countable E] in -theorem counted_subset_calibration_exterior (w : RawCorridor G k) - (hlen : 3 ≤ w.path.length) (x y : V) : - {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} ⊆ - w.calibrationEvent ∩ (w.exterior ⁻¹' w.exteriorOrientations x y) := by - intro ω hc - have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) - have hq : ω ∈ w.calibrationEvent := by - refine ⟨fun e he => ?_,?_⟩ - · simpa only [hi,Set.inter_univ] using (hc.2.1 e he).1 - · simpa only [hi,Set.inter_univ] using hc.2.2 - refine ⟨hq,?_⟩ - obtain ⟨hne,ho⟩ := w.counted_exterior_orientation hlen ω hq x y hc - rcases ho with ho | ho - · exact Or.inl ⟨conn_symm G _ ho.1,ho.2,hne⟩ - · exact Or.inr ⟨conn_symm G _ ho.1,ho.2,fun h => hne (conn_symm G _ h)⟩ - -omit [Countable V] in -theorem exterior_orientation_BK (w : RawCorridor G k) (p : unitInterval) (x y a b : V) : - (law p).real (w.exterior ⁻¹' orientedPivotalEvent G x y a b) ≤ - twoPoint G p x a * twoPoint G p b y := by - apply le_trans (measureReal_mono ?_) (bk p {ω | Conn G ω x a} {ω | Conn G ω b y} - (fun _ _ h hc => conn_mono G h hc) (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x a) (finiteWitness_conn G b y)) - intro ω h - exact disjointOccurrence_upper _ _ Set.inter_subset_left - (orientedPivotalEvent_subset_disjoint G x y a b h) - - - -theorem counted_weight_bound (hG : Function.Injective G) (hloc : LocallyFinite G) - (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (x y : V) : - w.weight P p * (law p).real {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} ≤ - w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + - twoPoint G p x w.endpoint * twoPoint G p w.base y) := by - have hi := w.calibration_independent hG hloc hlen p (w.exteriorOrientations x y) - (w.measurableSet_exteriorOrientations x y) - have hir : (law p).real (w.calibrationEvent ∩ w.exterior ⁻¹' w.exteriorOrientations x y) = - (law p).real w.calibrationEvent * (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) := by - exact congrArg ENNReal.toReal hi |>.trans ENNReal.toReal_mul - have hb : (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) ≤ - twoPoint G p x w.base * twoPoint G p w.endpoint y + - twoPoint G p x w.endpoint * twoPoint G p w.base y := by - apply le_trans (measureReal_union_le _ _) - exact add_le_add (w.exterior_orientation_BK p x y w.base w.endpoint) - (w.exterior_orientation_BK p x y w.endpoint w.base) - calc - _ ≤ w.weight P p * (law p).real (w.calibrationEvent ∩ w.exterior ⁻¹' w.exteriorOrientations x y) := - mul_le_mul_of_nonneg_left (measureReal_mono (w.counted_subset_calibration_exterior hlen x y)) - (w.weight_nonneg P hP p) - _ = w.probability P * (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) := by - rw [hir,←mul_assoc,w.calibration_identity hG hloc P p hp hp₁] - _ ≤ _ := mul_le_mul_of_nonneg_left hb (w.2.2.mass_nonneg P hP) - -end RawCorridor -end CorridorBKCalibration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawPathIntegration -attribute [local instance] Classical.propDecidable Classical.decEq - -abbrev RawFrom (H : SimpleGraph V) (k : ℕ) (x : V) := Σ y : V, HoldingWalk H k x y - -namespace RawFrom -variable {H : SimpleGraph V} - -def zeroEquiv (x : V) : RawFrom H 0 x ≃ Unit where - toFun _ := () - invFun _ := ⟨x,.nil x⟩ - left_inv w := by rcases w with ⟨y,w⟩; cases w; rfl - right_inv _ := rfl - -def succEquiv (k : ℕ) (x : V) : RawFrom H (k+1) x ≃ - RawFrom H k x ⊕ (Σ z : H.neighborSet x, RawFrom H k z.val) where - toFun - | ⟨y,.hold w⟩ => .inl ⟨y,w⟩ - | ⟨y,.step (z := z) h w⟩ => .inr ⟨⟨z,h⟩,y,w⟩ - invFun - | .inl ⟨y,w⟩ => ⟨y,.hold w⟩ - | .inr ⟨⟨z,h⟩,y,w⟩ => ⟨y,.step h w⟩ - left_inv w := by rcases w with ⟨y,w⟩; cases w <;> rfl - right_inv w := by rcases w with ⟨y,w⟩ | ⟨⟨z,h⟩,y,w⟩ <;> rfl - -instance finite [∀ x, Finite (H.neighborSet x)] (k : ℕ) (x : V) : Finite (RawFrom H k x) := by - induction k generalizing x with - | zero => exact Finite.of_equiv Unit (zeroEquiv x).symm - | succ k ih => - let (z : V) : Finite (RawFrom H k z) := ih z - exact Finite.of_equiv _ (succEquiv k x).symm - -noncomputable def integral (P : V → V → ℝ) (k : ℕ) (x : V) (f : V → ℝ) : ℝ := - ∑' w : RawFrom H k x, w.2.mass P * f w.1 - -theorem integral_zero (P : V → V → ℝ) (x : V) (f : V → ℝ) : - integral (H := H) P 0 x f = f x := by - unfold integral - rw [←(zeroEquiv x).symm.tsum_eq] - simp only [zeroEquiv,Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,one_mul,tsum_fintype,Fintype.sum_unique] - -theorem integral_succ [∀ x, Finite (H.neighborSet x)] (P : V → V → ℝ) - (k : ℕ) (x : V) (f : V → ℝ) : - integral (H := H) P (k+1) x f = - P x x * integral (H := H) P k x f + - ∑' z : H.neighborSet x, P x z * integral (H := H) P k z f := by - unfold integral - rw [←(succEquiv k x).symm.tsum_eq] - let := Fintype.ofFinite (RawFrom H k x) - let := Fintype.ofFinite (H.neighborSet x) - let (z : H.neighborSet x) := Fintype.ofFinite (RawFrom H k z) - simp only [tsum_fintype,Fintype.sum_sum_type,Fintype.sum_sigma,succEquiv, - Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,mul_assoc,Finset.mul_sum] - -end RawFrom - -theorem finite_openSimpleGraph_neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - Finite ((openSimpleGraph G Set.univ).neighborSet x) := by - apply Set.Finite.to_subtype - apply (finite_neighbors hloc x).subset - intro y hy - obtain ⟨_,e,_,he⟩ := hy - exact ⟨e,he⟩ - -end RawPathIntegration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawPathOperator -attribute [local instance] Classical.propDecidable Classical.decEq - - theorem sum_step_decomposition (H : SimpleGraph V) (P : V → V → ℝ) - (hs : ∀ x, (Function.support (P x)).Finite) - (hstep : ∀ x y, x ≠ y → ¬H.Adj x y → P x y = 0) (x : V) (f : V → ℝ) : - (∑' y, P x y * f y) = P x x * f x + ∑' y : H.neighborSet x, P x y * f y := by - rw [(finiteKernel_summable_mul P hs x f).tsum_eq_add_tsum_ite x] - congr 1 - have he : (∑' y : H.neighborSet x, if (y:V) = x then (0:ℝ) else P x y * f y) = - ∑' y, if y = x then (0:ℝ) else P x y * f y := by - apply tsum_subtype_eq_of_support_subset (f := fun y : V => if y = x then (0:ℝ) else P x y * f y) - intro y hy - by_contra hn - apply hy - by_cases h : y = x - · simp only [h,ite_true] - · simp only [ite_eq_right h,hstep x y (Ne.symm h) hn,zero_mul] - rw [←he] - apply tsum_congr - intro y - have hn : (y:V) ≠ x := by - intro h - have hy : H.Adj x y := y.property - rw [h] at hy - exact H.loopless.irrefl x hy - rw [ite_eq_right hn] - - theorem raw_integral_operator (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (k : ℕ) (x : V) (f : V → ℝ) : - RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k x f = - ∑' y, (matrixCoeff (P^k) x y).re * f y := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := - finite_openSimpleGraph_neighbors G hloc z - have hs (x : V) : (Function.support (walkKernel G hloc a x)).Finite := by - simpa only [pow_one,hP,Complex.ofReal_re] using walkPower_finite_support G hloc a P hpos hP 1 x - have hsP (x : V) : (Function.support (fun y => (matrixCoeff P x y).re)).Finite := by - simpa only [hP,Complex.ofReal_re] using hs x - induction k generalizing x with - | zero => rw [RawFrom.integral_zero,pow_zero,positive_identity_action] - | succ k ih => - rw [RawFrom.integral_succ,pow_succ',finite_positive_product_action P (P^k) hpos hsP - (finite_positive_pow_support P hpos hsP k)] - simp only [hP,Complex.ofReal_re] - rw [sum_step_decomposition (openSimpleGraph G Set.univ) (walkKernel G hloc a) hs] - · simp only [ih] - · intro u v huv hn - apply walkKernel_zero_of_not_step G hloc a u v huv - intro ha - apply hn - obtain ⟨e,he⟩ := ha - exact ⟨huv,e,Set.mem_univ e,he⟩ - -end RawPathOperator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorSum -attribute [local instance] Classical.propDecidable Classical.decEq -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -def counted (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : Prop := - 3 ≤ w.path.length ∧ (∀ z ∈ w.path.support, z ∈ D) ∧ - corridorCounted G w.retained w.blockers D ω x y - -theorem counted_iff (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : - w.counted D ω x y ↔ 3 ≤ w.path.length ∧ corridorCounted G w.retained w.blockers D ω x y := by - constructor - · exact fun h => ⟨h.1,h.2.2⟩ - · rintro ⟨hlen,hc⟩ - exact ⟨hlen,w.support_subset_of_retained (by omega) D (fun e he => (hc.2.1 e he).1.2),hc⟩ - -theorem counted_base_mem_walk (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) - (hc : w.counted D ω x y) (q : (openSimpleGraph G (ω ∩ internalEdges G D)).Walk x y) : - w.base ∈ q.support := by - have hl : 0 < w.path.length := by have := hc.1; omega - obtain ⟨s,hs,hbs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil - (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp w.path.start_mem_support - obtain ⟨e,he,hGe⟩ := w.edge_has_label s hs - have heq := pivotal_image_mem_edges G _ q e (hc.2.2.2.1 e he).2 - exact SimpleGraph.Walk.mem_support_of_mem_edges heq (hGe.symm ▸ hbs) - -theorem counted_symm (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : - w.counted D ω x y ↔ w.counted D ω y x := by - rw [counted_iff,counted_iff,corridorCounted_symm] - -theorem measurableSet_counted [Countable E] (w : RawCorridor G k) (D : Set V) (x y : V) : - MeasurableSet {ω | w.counted D ω x y} := by - simp_rw [w.counted_iff] - by_cases h : 3 ≤ w.path.length - · simpa only [h,true_and] using measurableSet_corridorCounted G w.retained w.blockers D x y - · simp only [h,false_and,Set.ofPred_false]; exact MeasurableSet.empty - -end RawCorridor - - theorem finite_corridors_on_bases (G : BondGraph V E) (hloc : LocallyFinite G) (k : ℕ) - (S : Set V) (hS : S.Finite) : {w : RawCorridor G k | w.base ∈ S}.Finite := by - let (x : V) : Finite ((openSimpleGraph G Set.univ).neighborSet x) := - finite_openSimpleGraph_neighbors G hloc x - let : Finite S := hS.to_subtype - let f : (Σ x : S, RawFrom (openSimpleGraph G Set.univ) k x.val) → RawCorridor G k := - fun w => ⟨w.1.val,w.2⟩ - have hr : {w : RawCorridor G k | w.base ∈ S} = Set.range f := by - ext w - constructor - · intro hw - exact ⟨⟨⟨w.base,hw⟩,w.2⟩,rfl⟩ - · rintro ⟨w,rfl⟩ - exact w.1.property - rw [hr] - exact Set.finite_range f - - - -theorem finite_counted_corridors (G : BondGraph V E) (hloc : LocallyFinite G) (k : ℕ) - (D : Set V) (ω : Set E) (x y : V) : {w : RawCorridor G k | w.counted D ω x y}.Finite := by - by_cases hc : Conn G (ω ∩ internalEdges G D) x y - · obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc - apply (finite_corridors_on_bases G hloc k {z | z ∈ q.support} (List.finite_toSet _)).subset - exact fun w hw => w.counted_base_mem_walk D ω x y hw q - · have he : {w : RawCorridor G k | w.counted D ω x y} = ∅ := by - ext w - exact ⟨fun h => hc h.2.2.1,False.elim⟩ - rw [he] - exact Set.finite_empty - -end CorridorSum -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ActualCorridorPenalty -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def corridorPenaltyTerm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - {k : ℕ} (D : Set V) (ω : Set E) (x y : V) (w : RawCorridor G k) : ℝ := - if w.counted D ω x y then w.weight P p else 0 - -noncomputable def corridorPenalty (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : ℝ := - ∑' w : RawCorridor G k, corridorPenaltyTerm G P p D ω x y w - -theorem corridorPenaltyTerm_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (D : Set V) - (ω : Set E) (x y : V) (w : RawCorridor G k) : - 0 ≤ corridorPenaltyTerm G P p D ω x y w := by - unfold corridorPenaltyTerm - split_ifs - · exact w.weight_nonneg P hP p - · exact le_rfl - -theorem corridorPenalty_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - (Function.support (corridorPenaltyTerm G P p (k := k) D ω x y)).Finite := by - apply (finite_counted_corridors G hloc k D ω x y).subset - intro w hw - by_contra hn - exact hw (ite_eq_right hn) - -theorem corridorPenalty_summable (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - Summable (corridorPenaltyTerm G P p (k := k) D ω x y) := - summable_of_hasFiniteSupport (corridorPenalty_finite_support G hloc P p k D ω x y) - -theorem corridorPenalty_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (D : Set V) - (ω : Set E) (x y : V) : 0 ≤ corridorPenalty G P p k D ω x y := - tsum_nonneg (corridorPenaltyTerm_nonneg G P hP p D ω x y) - -theorem corridorPenalty_symm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - corridorPenalty G P p k D ω x y = corridorPenalty G P p k D ω y x := by - unfold corridorPenalty - apply tsum_congr - intro w - simp only [corridorPenaltyTerm,w.counted_symm D ω x y] - -theorem corridorPenalty_restrict (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) - {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') - (x y : V) (hc : Conn G (ω ∩ internalEdges G D) x y) : - corridorPenalty G P p k D' ω' x y ≤ corridorPenalty G P p k D ω x y := by - apply (corridorPenalty_summable G hloc P p k D' ω' x y).tsum_le_tsum ?_ - (corridorPenalty_summable G hloc P p k D ω x y) - intro w - by_cases hn : w.counted D' ω' x y - · have ho : w.counted D ω x y := (w.counted_iff D ω x y).mpr - ⟨hn.1,corridorCounted_restrict G _ _ hD hω x y hc hn.2.2⟩ - simp only [corridorPenaltyTerm,hn,ho,ite_true,le_refl] - · simpa only [corridorPenaltyTerm,hn,ite_false] using corridorPenaltyTerm_nonneg G P hP p D ω x y w - -theorem measurable_corridorPenaltyTerm [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : ℝ) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : - Measurable (fun ω => corridorPenaltyTerm G P p D ω x y w) := by - exact Measurable.ite (w.measurableSet_counted D x y) measurable_const measurable_const - -theorem measurable_corridorPenalty [Countable V] [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (x y : V) : - Measurable (fun ω => corridorPenalty G P p k D ω x y) := by - exact Measurable.tsum (fun w => measurable_corridorPenaltyTerm G P p D x y w) - -end ActualCorridorPenalty -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ActualWeightedConnections -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def deformedConnection (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : ℝ := - if x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y then - Real.exp (-t * corridorPenalty G P p k D ω x y) else 0 - -noncomputable def deformedKernel (G : BondGraph V E) (P : V → V → ℝ) (p : unitInterval) - (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : ℝ := - ∫ ω, deformedConnection G P p k t D ω x y ∂law p - -theorem deformedConnection_nonneg (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - 0 ≤ deformedConnection G P p k t D ω x y := by - unfold deformedConnection - split_ifs - · exact (Real.exp_pos _).le - · exact le_rfl - -theorem deformedConnection_le_one (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (ω : Set E) (x y : V) : deformedConnection G P p k t D ω x y ≤ 1 := by - unfold deformedConnection - split_ifs - · apply Real.exp_le_one_iff.mpr - exact mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr ht) (corridorPenalty_nonneg G P hP p k D ω x y) - · exact zero_le_one - -theorem deformedConnection_symm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - deformedConnection G P p k t D ω x y = deformedConnection G P p k t D ω y x := by - have hc : Conn G (ω ∩ internalEdges G D) x y ↔ Conn G (ω ∩ internalEdges G D) y x := - ⟨conn_symm G _,conn_symm G _⟩ - simp only [deformedConnection,corridorPenalty_symm G P p k D ω x y,hc] - congr 1 - apply propext; tauto - -theorem deformedConnection_mono (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) - (t : ℝ) (ht : 0 ≤ t) {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') - (x y : V) : deformedConnection G P p k t D ω x y ≤ deformedConnection G P p k t D' ω' x y := by - by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y - · have hc' : x ∈ D' ∧ y ∈ D' ∧ Conn G (ω' ∩ internalEdges G D') x y := - ⟨hD hc.1,hD hc.2.1,conn_mono G (Set.inter_subset_inter hω (internalEdges_mono G hD)) hc.2.2⟩ - simp only [deformedConnection,hc,hc'] - apply Real.exp_le_exp.mpr - exact mul_le_mul_of_nonpos_left (corridorPenalty_restrict G hloc P hP p k hD hω x y hc.2.2) - (neg_nonpos.mpr ht) - · simpa only [deformedConnection,hc,ite_false] using deformedConnection_nonneg G P p k t D' ω' x y - -theorem measurable_deformedConnection [Countable V] [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) - (D : Set V) (x y : V) : Measurable (fun ω => deformedConnection G P p k t D ω x y) := by - have hs : MeasurableSet {ω : Set E | x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y} := by - by_cases hx : x ∈ D <;> by_cases hy : y ∈ D - · simpa only [hx,hy,true_and] using measurableSet_restrictedConn G (internalEdges G D) x y - all_goals simp only [hx,hy,false_and,and_false,Set.ofPred_false]; exact MeasurableSet.empty - exact Measurable.ite hs ((measurable_corridorPenalty G P p k D x y).const_mul (-t)).exp measurable_const - -theorem integrable_deformedConnection [Countable V] [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - Integrable (fun ω => deformedConnection G P p k t D ω x y) (law p) := by - apply Integrable.mono' (integrable_const (1:ℝ)) (measurable_deformedConnection G P p k t D x y).aestronglyMeasurable - filter_upwards [] with ω - rw [Real.norm_eq_abs,abs_of_nonneg (deformedConnection_nonneg G P p k t D ω x y)] - exact deformedConnection_le_one G P hP p k t ht D ω x y - -end ActualWeightedConnections -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedConnectionEndpoints -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem corridorPenalty_diag (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (D : Set V) (ω : Set E) (x : V) : corridorPenalty G P p k D ω x x = 0 := by - unfold corridorPenalty - rw [←tsum_zero] - apply tsum_congr - intro w - have hn : ¬w.counted D ω x x := by - intro hc - have hl : 0 < w.path.length := by have := hc.1; omega - obtain ⟨s,hs,_⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil - (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp w.path.start_mem_support - obtain ⟨e,he,_⟩ := w.edge_has_label s hs - exact (hc.2.2.2.1 e he).2 (conn_refl G _ x) - exact ite_eq_right hn - -theorem deformedConnection_diag (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (hx : x ∈ D) : - deformedConnection G P p k t D ω x x = 1 := by - simp only [deformedConnection,hx,conn_refl G _ x,and_self,ite_true, - corridorPenalty_diag,mul_zero,Real.exp_zero] - -theorem deformedConnection_zero (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - deformedConnection G P p k 0 D ω x y = - if x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y then 1 else 0 := by - simp only [deformedConnection,neg_zero,zero_mul,Real.exp_zero] - -theorem deformedConnection_full_zero (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) - (k : ℕ) (ω : Set E) (x y : V) : deformedConnection G P p k 0 Set.univ ω x y = - if Conn G ω x y then 1 else 0 := by - have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) - simp only [deformedConnection_zero,Set.mem_univ,true_and,hi,Set.inter_univ] - -theorem deformedConnection_change (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (ω : Set E) (x y : V) : - 0 ≤ deformedConnection G P p k 0 D ω x y - deformedConnection G P p k t D ω x y ∧ - deformedConnection G P p k 0 D ω x y - deformedConnection G P p k t D ω x y ≤ - t*corridorPenalty G P p k D ω x y := by - have hN := corridorPenalty_nonneg G P hP p k D ω x y - by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y - · simp only [deformedConnection,hc,ite_true,neg_zero,zero_mul,Real.exp_zero,and_self] - constructor - · exact sub_nonneg.mpr ((Real.exp_le_one_iff).mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr ht) hN)) - · have h := Real.one_sub_le_exp_neg (t*corridorPenalty G P p k D ω x y) - rw [←neg_mul] at h - linarith - · simp only [deformedConnection,hc,ite_false,sub_self] - exact ⟨le_rfl,mul_nonneg ht hN⟩ - -theorem deformedKernel_zero [Countable V] [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : unitInterval) (k : ℕ) (x y : V) : - deformedKernel G P p k 0 Set.univ x y = twoPoint G p x y := by - unfold deformedKernel - simp_rw [deformedConnection_full_zero] - have hi := integral_indicator_const (μ := law p) (1:ℝ) (measurableSet_conn G x y) - simpa only [Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_one,Measure.real,twoPoint] using hi - -end WeightedConnectionEndpoints -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawWalkDiagrams -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_diagram_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (k : ℕ) (x y : V) : - HasSum (fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * - ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re)) - (matrixCoeff (A*(P^k*A)) x y).re := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := - finite_openSimpleGraph_neighbors G hloc z - let F := fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * - ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re) - have hFn (w : RawCorridor G k) : 0 ≤ F w := - mul_nonneg (w.2.2.mass_nonneg _ hK) (mul_nonneg (hA _ _).2 (hA _ _).2) - have hr (z : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k z, F ⟨z,w⟩) = - (matrixCoeff A x z).re * (matrixCoeff (P^k*A) z y).re := by - have h := raw_integral_operator G hloc a P hpos hP k z (fun u => (matrixCoeff A u y).re) - have he : (∑' w : RawFrom (openSimpleGraph G Set.univ) k z, F ⟨z,w⟩) = - (matrixCoeff A x z).re * RawFrom.integral (H := openSimpleGraph G Set.univ) - (walkKernel G hloc a) k z (fun u => (matrixCoeff A u y).re) := by - rw [RawFrom.integral,←tsum_mul_left] - apply tsum_congr - intro w - dsimp only [F,RawCorridor.probability,RawCorridor.base,RawCorridor.endpoint] - change w.2.mass _ * (_ * _) = _ * (w.2.mass _ * _) - ring - rw [he,h,((hpos.pow k).mul_hasSum A z y).tsum_eq] - have ho := hA.mul_hasSum (P^k*A) x y - have hs : Summable F := (summable_sigma_of_nonneg hFn).mpr ⟨fun z => by - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k z) - exact (hasSum_fintype _).summable,by simpa only [hr] using ho.summable⟩ - have he : (∑' w, F w) = (matrixCoeff (A*(P^k*A)) x y).re := by - rw [hs.tsum_sigma] - simpa only [hr] using ho.tsum_eq - exact he ▸ hs.hasSum - - theorem sandwich_selfAdjoint (A P : Hilbert V →L[ℂ] Hilbert V) - (hA : IsSelfAdjoint A) (hP : IsSelfAdjoint P) (k : ℕ) : IsSelfAdjoint (A*(P^k*A)) := by - change star (A*(P^k*A)) = A*(P^k*A) - simp only [star_mul,hA.star_eq,(hP.pow k).star_eq,mul_assoc] - -end RawWalkDiagrams -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawWalkSymmetricDiagrams -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem raw_two_diagrams_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) - (k : ℕ) (x y : V) : - HasSum (fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * - ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re + - (matrixCoeff A x w.endpoint).re * (matrixCoeff A w.base y).re)) - (2*(matrixCoeff (A*(P^k*A)) x y).re) := by - have h₁ := raw_diagram_hasSum G hloc a P hpos hP hK A hA k x y - have h₂ := raw_diagram_hasSum G hloc a P hpos hP hK A hA k y x - have hh := h₁.add h₂ - have hC := matrixCoeff_real_symm (A*(P^k*A)) (sandwich_selfAdjoint A P hAs hPs k) y x - rw [hC,←two_mul] at hh - convert hh using 1 - ext w - rw [matrixCoeff_real_symm A hAs y w.base,matrixCoeff_real_symm A hAs w.endpoint x] - ring - -end RawWalkSymmetricDiagrams -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section PenaltyTermExpectation -attribute [local instance] Classical.propDecidable Classical.decEq - - theorem integrable_corridorPenaltyTerm [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : unitInterval) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : - Integrable (fun ω => corridorPenaltyTerm G P p D ω x y w) (law p) := by - exact (integrable_const (w.weight P p)).indicator (w.measurableSet_counted D x y) - -theorem integral_corridorPenaltyTerm [Countable E] (G : BondGraph V E) - (P : V → V → ℝ) (p : unitInterval) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : - (∫ ω, corridorPenaltyTerm G P p D ω x y w ∂law p) = - w.weight P p * (law p).real {ω | w.counted D ω x y} := by - have h := integral_indicator_const (μ := law p) (w.weight P p) (w.measurableSet_counted D x y) - simpa only [corridorPenaltyTerm,Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_comm] using h - - -theorem integral_corridorPenaltyTerm_le [Countable V] [Countable E] - (G : BondGraph V E) (hG : Function.Injective G) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) {k : ℕ} (x y : V) (w : RawCorridor G k) : - (∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w ∂law p) ≤ - w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + - twoPoint G p x w.endpoint * twoPoint G p w.base y) := by - rw [integral_corridorPenaltyTerm] - by_cases hl : 3 ≤ w.path.length - · have he : {ω | w.counted Set.univ ω x y} = - {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} := by - ext ω - simp only [Set.mem_ofPred_eq,w.counted_iff,hl,true_and] - rw [he] - exact w.counted_weight_bound hG hloc hl P hP p hp hp₁ x y - · have he : {ω | w.counted Set.univ ω x y} = ∅ := by - ext ω - simp only [Set.mem_ofPred_eq,w.counted_iff,hl,false_and,Set.mem_empty_iff_false] - rw [he,measureReal_empty,mul_zero] - exact mul_nonneg (w.2.2.mass_nonneg P hP) (add_nonneg - (mul_nonneg (twoPoint_nonneg G p x w.base) (twoPoint_nonneg G p w.endpoint y)) - (mul_nonneg (twoPoint_nonneg G p x w.endpoint) (twoPoint_nonneg G p w.base y))) - -end PenaltyTermExpectation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FullCorridorPenaltyExpectation -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - -theorem corridorPenalty_integrable_bound (G : BondGraph V E) - (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) - (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) (k : ℕ) (x y : V) : - Integrable (fun ω => corridorPenalty G (walkKernel G hloc a) p k Set.univ ω x y) (law p) ∧ - (∫ ω, corridorPenalty G (walkKernel G hloc a) p k Set.univ ω x y ∂law p) ≤ - 2*(matrixCoeff (A*(P^k*A)) x y).re := by - let K := walkKernel G hloc a - have hK (u v : V) : 0 ≤ K u v := by simpa only [hP,Complex.ofReal_re] using (hpos u v).2 - let F := fun w : RawCorridor G k => fun ω : Set E => corridorPenaltyTerm G K p Set.univ ω x y w - have hFi (w : RawCorridor G k) : Integrable (F w) (law p) := integrable_corridorPenaltyTerm G K p Set.univ x y w - have hFn (w : RawCorridor G k) (ω : Set E) : 0 ≤ F w ω := corridorPenaltyTerm_nonneg G K hK p _ ω x y w - have hd := raw_two_diagrams_hasSum G hloc a P hpos hPs hP hK A hA hAs k x y - simp only [hAT,Complex.ofReal_re] at hd - have hb (w : RawCorridor G k) := integral_corridorPenaltyTerm_le G hG hloc K hK p hp hp₁ x y w - have hs : Summable (fun w => ∫ ω, F w ω ∂law p) := Summable.of_nonneg_of_le - (fun w => integral_nonneg (hFn w)) hb hd.summable - have hsN (ω : Set E) := corridorPenalty_summable G hloc K p k Set.univ ω x y - have hlin : (∫⁻ ω, ENNReal.ofReal (corridorPenalty G K p k Set.univ ω x y) ∂law p) = - ENNReal.ofReal (∑' w, ∫ ω, F w ω ∂law p) := by - have he (ω : Set E) : ENNReal.ofReal (corridorPenalty G K p k Set.univ ω x y) = - ∑' w, ENNReal.ofReal (F w ω) := ENNReal.ofReal_tsum_of_nonneg (fun w => hFn w ω) (hsN ω) - simp_rw [he] - rw [lintegral_tsum (fun w => (hFi w).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] - simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hFn _))] - exact (ENNReal.ofReal_tsum_of_nonneg (fun w => integral_nonneg (hFn w)) hs).symm - have hNn (ω : Set E) := corridorPenalty_nonneg G K hK p k Set.univ ω x y - have hi : Integrable (fun ω => corridorPenalty G K p k Set.univ ω x y) (law p) := - ⟨(measurable_corridorPenalty G K p k Set.univ x y).aestronglyMeasurable, - (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hNn)).mpr (by rw [hlin]; exact ENNReal.ofReal_lt_top)⟩ - refine ⟨hi,?_⟩ - have hn : Summable (fun w => ∫ ω, ‖F w ω‖ ∂law p) := by - simpa only [Real.norm_of_nonneg (hFn _ _)] using hs - change (∫ ω, ∑' w, F w ω ∂law p) ≤ _ - rw [←integral_tsum_of_summable_integral_norm hFi hn] - exact (hs.tsum_le_tsum hb hd.summable).trans_eq hd.tsum_eq - -end FullCorridorPenaltyExpectation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SmallDeformationEntrywise -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - - - -theorem deformedKernel_change_bound (G : BondGraph V E) - (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) - (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) - (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x y : V) : - 0 ≤ twoPoint G p x y - deformedKernel G (walkKernel G hloc a) p k t Set.univ x y ∧ - twoPoint G p x y - deformedKernel G (walkKernel G hloc a) p k t Set.univ x y ≤ - 2*t*(matrixCoeff (A*(P^k*A)) x y).re := by - let K := walkKernel G hloc a - have hK (u v : V) : 0 ≤ K u v := by simpa only [hP,Complex.ofReal_re] using (hpos u v).2 - have hi₀ := integrable_deformedConnection G K hK p k 0 (le_refl _) Set.univ x y - have hi := integrable_deformedConnection G K hK p k t ht Set.univ x y - have he : twoPoint G p x y - deformedKernel G K p k t Set.univ x y = - ∫ ω, deformedConnection G K p k 0 Set.univ ω x y - deformedConnection G K p k t Set.univ ω x y ∂law p := by - rw [integral_sub hi₀ hi] - change _ = deformedKernel G K p k 0 Set.univ x y - _ - rw [deformedKernel_zero] - rfl - rw [he] - refine ⟨integral_nonneg (fun ω => (deformedConnection_change G K hK p k t ht Set.univ ω x y).1),?_⟩ - obtain ⟨hNi,hNb⟩ := corridorPenalty_integrable_bound G hG hloc p hp hp₁ a P hpos hPs hP A hA hAs hAT k x y - calc - _ ≤ ∫ ω, t*corridorPenalty G K p k Set.univ ω x y ∂law p := - integral_mono (hi₀.sub hi) (hNi.const_mul t) - (fun ω => (deformedConnection_change G K hK p k t ht Set.univ ω x y).2) - _ = t*∫ ω, corridorPenalty G K p k Set.univ ω x y ∂law p := integral_const_mul _ _ - _ ≤ t*(2*(matrixCoeff (A*(P^k*A)) x y).re) := mul_le_mul_of_nonneg_left hNb ht - _ = _ := by ring - -omit [Countable V] [Countable E] in -theorem deformedKernel_nonneg (G : BondGraph V E) (P : V → V → ℝ) (p : unitInterval) - (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : 0 ≤ deformedKernel G P p k t D x y := - integral_nonneg (fun ω => deformedConnection_nonneg G P p k t D ω x y) - -end SmallDeformationEntrywise -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.TraceBounds + +namespace OAI + +/-! Corridors for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorEligibility +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem edge_has_label (w : RawCorridor G k) (s : Sym2 V) (hs : s ∈ w.path.edges) : + ∃ e ∈ w.retained, G e = s := by + induction s using Sym2.inductionOn with + | _ x y => + obtain ⟨_,e,_,he⟩ := w.path.adj_of_mem_edges hs + exact ⟨e,by simpa only [retained,Set.mem_ofPred_eq,he] using hs,he⟩ + +theorem image_retained (w : RawCorridor G k) : G '' w.retained = {s | s ∈ w.path.edges} := by + ext s + constructor + · rintro ⟨e,he,rfl⟩; exact he + · exact w.edge_has_label s + +theorem retained_ncard (hG : Function.Injective G) (w : RawCorridor G k) : + w.retained.ncard = w.path.length := by + rw [←hG.injOn.ncard_image (s := w.retained),w.image_retained] + have hh := List.toFinset_card_of_nodup w.path_isPath.isTrail.edges_nodup + simpa only [←List.coe_toFinset,Set.ncard_coe_finset,SimpleGraph.Walk.length_edges] using hh + + + +theorem support_subset_of_retained (w : RawCorridor G k) (hlen : 0 < w.path.length) + (D : Set V) (he : w.retained ⊆ internalEdges G D) : + ∀ z ∈ w.path.support, z ∈ D := by + intro z hz + obtain ⟨s,hs,hzs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil + (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hlen)).mp hz + obtain ⟨e,he',hGe⟩ := w.edge_has_label s hs + exact he he' z (hGe.symm ▸ hzs) + +theorem retained_subset_of_support (w : RawCorridor G k) (D : Set V) + (hs : ∀ z ∈ w.path.support, z ∈ D) : w.retained ⊆ internalEdges G D := by + intro e he z hz + exact hs z (SimpleGraph.Walk.mem_support_of_mem_edges he hz) + +theorem support_iff_retained (w : RawCorridor G k) (hlen : 0 < w.path.length) (D : Set V) : + (∀ z ∈ w.path.support, z ∈ D) ↔ w.retained ⊆ internalEdges G D := + ⟨w.retained_subset_of_support D,w.support_subset_of_retained hlen D⟩ + +theorem retained_incident_interior (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (e : E) (he : e ∈ w.retained) : ∃ z ∈ w.interior, z ∈ G e := by + change G e ∈ w.path.edges at he + generalize hab : G e = s at he + induction s using Sym2.inductionOn with + | _ a b => + have hedge : s(a,b) ∈ w.path.edges := he + have ha := w.path.fst_mem_support_of_mem_edges hedge + have hb := w.path.snd_mem_support_of_mem_edges hedge + have habne : a ≠ b := (w.path.adj_of_mem_edges hedge).1 + by_contra hn + have hna : a ∉ w.interior := fun hi => hn ⟨a,hi,by simp⟩ + have hnb : b ∉ w.interior := fun hi => hn ⟨b,hi,by simp⟩ + have hax : a = w.base ∨ a = w.endpoint := by simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,ha,true_and,Finset.mem_insert,Finset.mem_singleton,not_not] using hna + have hbx : b = w.base ∨ b = w.endpoint := by simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,hb,true_and,Finset.mem_insert,Finset.mem_singleton,not_not] using hnb + have hedge' : s(w.base,w.endpoint) ∈ w.path.edges := by + rcases hax with rfl | rfl <;> rcases hbx with rfl | rfl + · exact (habne rfl).elim + · exact hedge + · simpa only [Sym2.eq_swap] using hedge + · exact (habne rfl).elim + have hh := w.path_isPath.length_eq_one_of_mem_edges hedge' + omega + +theorem specified_disjoint_exterior (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) : + Disjoint (w.retained ∪ w.blockers) (internalEdges G (w.interior : Set V)ᶜ) := by + apply Set.disjoint_left.mpr + intro e he hx + obtain ⟨z,hz,he⟩ := he.elim (w.retained_incident_interior hlen e) (fun hb => hb.1) + exact hx z he hz + +end RawCorridor +end CorridorEligibility +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExactCorridorPattern +attribute [local instance] Classical.propDecidable Classical.decEq + +def edgePattern (A B : Finset E) : Set (Set E) := + {ω | (A : Set E) ⊆ ω ∧ Disjoint (B : Set E) ω} + +theorem edgePattern_eq_restriction (A B : Finset E) (hAB : Disjoint A B) : + edgePattern A B = {ω | ω ∩ ((A ∪ B : Finset E) : Set E) = (A : Set E)} := by + ext ω + constructor + · rintro ⟨ha,hb⟩ + apply Set.Subset.antisymm + · rintro e ⟨he,heQ⟩ + rcases Finset.mem_union.mp heQ with h | h + · exact h + · exact (Set.disjoint_left.mp hb h he).elim + · intro e he + exact ⟨ha he,Finset.mem_union_left _ he⟩ + · intro h + constructor + · intro e he + exact ((Set.ext_iff.mp h e).mpr he).1 + · apply Set.disjoint_left.mpr + intro e he hw + have ha : e ∈ A := (Set.ext_iff.mp h e).mp ⟨hw,Finset.mem_union_right _ he⟩ + exact Finset.disjoint_left.mp hAB ha he + +theorem measurableSet_edgePattern (A B : Finset E) (hAB : Disjoint A B) : + MeasurableSet (edgePattern A B) := by + rw [edgePattern_eq_restriction A B hAB] + exact measurableSet_finite_restriction (A∪B) {(A:Set E)} + + +theorem edgePattern_probability (A B : Finset E) (hAB : Disjoint A B) (p : unitInterval) : + (law p).real (edgePattern A B) = (p:ℝ)^A.card*(1-(p:ℝ))^B.card := by + let f : Set E → ℝ := fun ω => if ω ∈ edgePattern A B then 1 else 0 + have hf (ω : Set E) : f ω = f (ω ∩ ((A∪B:Finset E):Set E)) := by + simp only [f,edgePattern_eq_restriction A B hAB,Set.mem_ofPred_eq,Set.inter_assoc,Set.inter_self] + rw [←integral_event_indicator p _ (measurableSet_edgePattern A B hAB)] + change (∫ ω, f ω ∂law p) = _ + rw [integral_eq_bernoulliPolynomial (A∪B) p f hf] + trans bernoulliPolynomial (A∪B) (fun η => if η=A then 1 else 0) p + · apply bernoulliPolynomial_congr + intro η hη + have he : (η:Set E) ∩ ((A∪B:Finset E):Set E) = (η:Set E) := + Set.inter_eq_left.mpr hη + simp only [f,edgePattern_eq_restriction A B hAB,Set.mem_ofPred_eq,he,Finset.coe_inj] + · simp only [bernoulliPolynomial,ite_mul,zero_mul,one_mul] + rw [Finset.sum_ite_eq'] + simp only [Finset.mem_powerset,Finset.subset_union_left,ite_true,Finset.card_union_of_disjoint hAB, + Nat.add_sub_cancel_left] + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +def calibrationEvent (w : RawCorridor G k) : Set (Set E) := + {ω | w.retained ⊆ ω ∧ Disjoint w.blockers ω} + +theorem calibrationEvent_eq (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) : w.calibrationEvent = + edgePattern (w.retained_finite hG).toFinset (w.blockers_finite hloc).toFinset := by + simp only [calibrationEvent,edgePattern,Set.Finite.coe_toFinset] + +theorem calibration_probability (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (p : unitInterval) : + (law p).real w.calibrationEvent = (p:ℝ)^w.path.length*(1-(p:ℝ))^w.blockers.ncard := by + rw [w.calibrationEvent_eq hG hloc,edgePattern_probability] + · rw [←Set.ncard_eq_toFinset_card w.retained (w.retained_finite hG),←Set.ncard_eq_toFinset_card w.blockers (w.blockers_finite hloc),w.retained_ncard hG] + · apply Finset.disjoint_left.mpr + intro e he hb + exact Set.disjoint_left.mp w.retained_disjoint_blockers + ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) + + + +theorem calibration_identity (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (P : V → V → ℝ) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) : + w.weight P p * (law p).real w.calibrationEvent = w.probability P := by + rw [w.calibration_probability hG hloc p] + unfold weight + have h₁ := pow_ne_zero w.path.length hp.ne' + have h₂ := pow_ne_zero w.blockers.ncard (sub_pos.mpr hp₁).ne' + field_simp + +end RawCorridor +end ExactCorridorPattern +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorTerminalGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem path_internal_two_neighbors {H : SimpleGraph V} {u v z : V} + (q : H.Walk u v) (hq : q.IsPath) (hz : z ∈ q.support) (hzu : z ≠ u) (hzv : z ≠ v) : + ∃ a b : V, a ≠ b ∧ s(z,a) ∈ q.edges ∧ s(z,b) ∈ q.edges := by + induction q with + | nil => simp only [SimpleGraph.Walk.support_nil,List.mem_singleton] at hz; exact (hzu hz).elim + | @cons u a v h q ih => + have htail : q.IsPath := hq.of_cons + have huz : u ∉ q.support := ((SimpleGraph.Walk.cons_isPath_iff _ _).mp hq).2 + have hzq : z ∈ q.support := (List.mem_cons.mp hz).resolve_left hzu + by_cases hza : z = a + · subst z + cases q with + | nil => exact (hzv rfl).elim + | @cons a b v h' q => + refine ⟨u,b,?_,?_,?_⟩ + · intro hub + apply huz + subst b + simp + · simp only [SimpleGraph.Walk.edges_cons,List.mem_cons,Sym2.eq_swap]; exact Or.inl trivial + · simp only [SimpleGraph.Walk.edges_cons,List.mem_cons]; exact Or.inr (Or.inl trivial) + · obtain ⟨b,c,hbc,hb,hc⟩ := ih htail hzq hza hzv + exact ⟨b,c,hbc,List.mem_cons_of_mem _ hb,List.mem_cons_of_mem _ hc⟩ + + + +theorem pivotal_image_mem_edges (G : BondGraph V E) (ω : Set E) {x y : V} + (q : (openSimpleGraph G ω).Walk x y) (e : E) + (hp : ¬Conn G (ω \ {e}) x y) : G e ∈ q.edges := by + obtain ⟨l,hl,hmap,ho⟩ := walk_lift_bonds G ω q + by_contra he + apply hp + apply hl.conn + intro f hf + refine ⟨ho f hf,?_⟩ + intro hfe + have hfe' : f = e := Set.mem_singleton_iff.mp hfe + subst f + apply he + rw [←hmap] + exact List.mem_map_of_mem hf + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem counted_terminal_outside (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) + (hc : corridorCounted G w.retained w.blockers D ω x y) : x ∉ w.interior ∧ y ∉ w.interior := by + have hleft (x y : V) (hc : corridorCounted G w.retained w.blockers D ω x y) : x ∉ w.interior := by + intro hx + have hx' := Finset.mem_sdiff.mp hx + have hxs : x ∈ w.path.support := List.mem_toFinset.mp hx'.1 + have hxne : x ≠ w.base ∧ x ≠ w.endpoint := by + simpa only [Finset.mem_insert,Finset.mem_singleton,not_or] using hx'.2 + have hxu := hxne.1 + have hxv := hxne.2 + obtain ⟨a,b,hab,ha,hb⟩ := path_internal_two_neighbors w.path w.path_isPath hxs hxu hxv + obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.1 + let qp := q.bypass + have hqp : qp.IsPath := q.bypass_isPath + obtain ⟨e,he,hGe⟩ := w.edge_has_label _ ha + obtain ⟨f,hf,hGf⟩ := w.edge_has_label _ hb + have hea := pivotal_image_mem_edges G _ qp e (hc.2.1 e he).2 + have heb := pivotal_image_mem_edges G _ qp f (hc.2.1 f hf).2 + rw [hGe] at hea + rw [hGf] at heb + exact hab ((hqp.eq_snd_of_mem_edges hea).trans (hqp.eq_snd_of_mem_edges heb).symm) + exact ⟨hleft x y hc,hleft y x ((corridorCounted_symm G _ _ D ω x y).mp hc)⟩ + +end RawCorridor +end CorridorTerminalGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory ProbabilityTheory +section CorridorIndependence +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_inter_const (S : Set E) : Measurable (fun ω : Set E => ω ∩ S) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).and measurable_const + + +theorem restriction_events_independent (p : unitInterval) (S T : Set E) + (hST : Disjoint S T) (A B : Set (Set E)) (hA : MeasurableSet A) (hB : MeasurableSet B) : + (law p) ((fun ω => ω ∩ S) ⁻¹' A ∩ (fun ω => ω ∩ T) ⁻¹' B) = + (law p) ((fun ω => ω ∩ S) ⁻¹' A) * (law p) ((fun ω => ω ∩ T) ⁻¹' B) := by + let μ : Measure (E → Prop) := Measure.infinitePi (fun _ => bitLaw p) + let σ : E → MeasurableSpace (E → Prop) := fun e => + MeasurableSpace.comap (fun f : E → Prop => f e) inferInstance + have hi : iIndep σ μ := iIndepFun_infinitePi (X := fun (_ : E) (b : Prop) => b) + (fun _ => measurable_id) + have hle (e : E) : σ e ≤ (inferInstance : MeasurableSpace (E → Prop)) := + (measurable_pi_apply e).comap_le + have hr (S : Set E) : @Measurable (E → Prop) (Set E) (⨆ e ∈ S, σ e) inferInstance + (fun f => {e | f e} ∩ S) := by + let : MeasurableSpace (E → Prop) := ⨆ e ∈ S, σ e + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + change @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun f => f e ∧ e ∈ S) + by_cases he : e ∈ S + · have hm : @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun f => f e) := + Measurable.of_comap_le (le_iSup_of_le e (le_iSup_of_le he le_rfl)) + simpa only [Set.mem_inter_iff,Set.mem_ofPred_eq,he,and_true] using hm + · simpa only [Set.mem_inter_iff,Set.mem_ofPred_eq,he,and_false] using + (measurable_const : @Measurable (E → Prop) Prop (⨆ e ∈ S, σ e) inferInstance (fun _ => False)) + have hm : (law p : Measure (Set E)) = μ.map (fun f => {e | f e}) := by + simp only [law,setBernoulli_eq_map,Set.mem_univ,μ,bitLaw,bernoulliMeasure_def] + rw [hm,Measure.map_apply measurable_setOfPred ((hA.preimage (measurable_inter_const S)).inter + (hB.preimage (measurable_inter_const T))), + Measure.map_apply measurable_setOfPred (hA.preimage (measurable_inter_const S)), + Measure.map_apply measurable_setOfPred (hB.preimage (measurable_inter_const T))] + exact (Indep_iff _ _ _).mp (indep_iSup_of_disjoint hle hi hST) _ _ + (hA.preimage (hr S)) (hB.preimage (hr T)) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem calibration_restriction (w : RawCorridor G k) (ω : Set E) : + ω ∈ w.calibrationEvent ↔ ω ∩ (w.retained ∪ w.blockers) ∈ w.calibrationEvent := by + constructor + · rintro ⟨ha,hb⟩ + exact ⟨fun e he => ⟨ha he,Or.inl he⟩,hb.mono_right Set.inter_subset_left⟩ + · rintro ⟨ha,hb⟩ + refine ⟨fun e he => (ha he).1,Set.disjoint_left.mpr ?_⟩ + intro e he hw + exact Set.disjoint_left.mp hb he ⟨hw,Or.inr he⟩ + + + +theorem calibration_independent (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) (p : unitInterval) + (A : Set (Set E)) (hA : MeasurableSet A) : + (law p) (w.calibrationEvent ∩ (fun ω => ω ∩ internalEdges G (w.interior : Set V)ᶜ) ⁻¹' A) = + (law p) w.calibrationEvent * + (law p) ((fun ω => ω ∩ internalEdges G (w.interior : Set V)ᶜ) ⁻¹' A) := by + have hQ : MeasurableSet w.calibrationEvent := by + rw [w.calibrationEvent_eq hG hloc] + apply measurableSet_edgePattern + apply Finset.disjoint_left.mpr + intro e he hb + exact Set.disjoint_left.mp w.retained_disjoint_blockers + ((w.retained_finite hG).mem_toFinset.mp he) ((w.blockers_finite hloc).mem_toFinset.mp hb) + have heq : (fun ω => ω ∩ (w.retained ∪ w.blockers)) ⁻¹' w.calibrationEvent = w.calibrationEvent := by + ext ω; exact (w.calibration_restriction ω).symm + have hh := restriction_events_independent p _ _ (w.specified_disjoint_exterior hlen) + w.calibrationEvent A hQ hA + simpa only [heq] using hh + +end RawCorridor +end CorridorIndependence +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorContraction +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem conn_union_attachment (G : BondGraph V E) (S T : Set E) (A : Set V) + (hclosed : ∀ a b, a ∈ A → Conn G S a b → b ∈ A) + (hT : ∀ e ∈ T, ∀ z ∈ G e, z ∈ A) {x y : V} (hc : Conn G (S ∪ T) x y) : + Conn G S x y ∨ x ∈ A ∧ y ∈ A := by + induction hc with + | refl => exact Or.inl (conn_refl G S x) + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + rcases he with he | he + · have hab : Conn G S a b := Relation.ReflTransGen.single ⟨e,he,heq⟩ + exact ih.elim (fun h => Or.inl (conn_trans G S h hab)) + (fun h => Or.inr ⟨h.1,hclosed a b h.2 hab⟩) + · have ha := hT e he a (heq.symm ▸ (by simp : a ∈ s(a,b))) + have hb := hT e he b (heq.symm ▸ (by simp : b ∈ s(a,b))) + exact Or.inr ⟨ih.elim (fun h => hclosed a x ha (conn_symm G S h)) And.left,hb⟩ + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +def exterior (w : RawCorridor G k) (ω : Set E) : Set E := + ω ∩ internalEdges G (w.interior : Set V)ᶜ + +def attachment (w : RawCorridor G k) (ω : Set E) : Set V := + {z | z ∈ w.path.support ∨ Conn G (w.exterior ω) w.base z ∨ Conn G (w.exterior ω) w.endpoint z} + +theorem support_exterior_ports (w : RawCorridor G k) {z : V} + (hz : z ∈ w.path.support) (ho : z ∉ w.interior) : z = w.base ∨ z = w.endpoint := by + simpa only [interior,Finset.mem_sdiff,List.mem_toFinset,hz,true_and, + Finset.mem_insert,Finset.mem_singleton,not_not] using ho + +theorem attachment_closed (w : RawCorridor G k) (ω : Set E) (a b : V) + (ha : a ∈ w.attachment ω) (hc : Conn G (w.exterior ω) a b) : b ∈ w.attachment ω := by + rcases ha with ha | ha | ha + · rcases conn_internal_eq_or_mem G (w.interior : Set V)ᶜ hc with rfl | ho + · exact Or.inl ha + · rcases w.support_exterior_ports ha ho.1 with rfl | rfl + · exact Or.inr (Or.inl hc) + · exact Or.inr (Or.inr hc) + · exact Or.inr (Or.inl (conn_trans G _ ha hc)) + · exact Or.inr (Or.inr (conn_trans G _ ha hc)) + +theorem open_subset_exterior_retained (w : RawCorridor G k) (ω : Set E) + (hq : ω ∈ w.calibrationEvent) : ω ⊆ w.exterior ω ∪ w.retained := by + intro e he + by_cases hr : e ∈ w.retained + · exact Or.inr hr + · left + refine ⟨he,?_⟩ + intro z hz hi + exact Set.disjoint_left.mp hq.2 ⟨⟨z,hi,hz⟩,hr⟩ he + +theorem connection_exterior_or_attachment (w : RawCorridor G k) (ω : Set E) + (hq : ω ∈ w.calibrationEvent) {x y : V} (hc : Conn G ω x y) : + Conn G (w.exterior ω) x y ∨ x ∈ w.attachment ω ∧ y ∈ w.attachment ω := by + apply conn_union_attachment G _ w.retained (w.attachment ω) (w.attachment_closed ω) + (fun e he z hz => Or.inl (SimpleGraph.Walk.mem_support_of_mem_edges he hz)) + exact conn_mono G (w.open_subset_exterior_retained ω hq) hc + +theorem attachment_outside (w : RawCorridor G k) (ω : Set E) {z : V} + (ha : z ∈ w.attachment ω) (hz : z ∉ w.interior) : + Conn G (w.exterior ω) w.base z ∨ Conn G (w.exterior ω) w.endpoint z := by + rcases ha with ha | ha | ha + · rcases w.support_exterior_ports ha hz with rfl | rfl + · exact Or.inl (conn_refl G _ _) + · exact Or.inr (conn_refl G _ _) + · exact Or.inl ha + · exact Or.inr ha + + +theorem counted_exterior_orientation (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (ω : Set E) (hq : ω ∈ w.calibrationEvent) (x y : V) + (hc : corridorCounted G w.retained w.blockers Set.univ ω x y) : + ¬Conn G (w.exterior ω) w.base w.endpoint ∧ + ((Conn G (w.exterior ω) w.base x ∧ Conn G (w.exterior ω) w.endpoint y) ∨ + (Conn G (w.exterior ω) w.endpoint x ∧ Conn G (w.exterior ω) w.base y)) := by + have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) + have hc' : Conn G ω x y := by simpa only [hi,Set.inter_univ] using hc.1 + have hs : w.retained.Nonempty := by + have hp : w.path.edges ≠ [] := by + intro he + have hh := congrArg List.length he + simp only [SimpleGraph.Walk.length_edges,List.length_nil] at hh + omega + obtain ⟨s,hs⟩ := List.exists_mem_of_ne_nil _ hp + obtain ⟨e,he,_⟩ := w.edge_has_label s hs + exact ⟨e,he⟩ + have hnot : ¬Conn G (w.exterior ω) x y := by + intro h + obtain ⟨e,he⟩ := hs + apply (hc.2.1 e he).2 + apply conn_mono G ?_ h + intro f hf + refine ⟨?_,?_⟩ + · simpa only [hi,Set.inter_univ] using hf.1 + · intro hfe + have hfe' := Set.mem_singleton_iff.mp hfe + subst f + exact Set.disjoint_left.mp (w.specified_disjoint_exterior hlen) (Or.inl he) hf.2 + have hatt := (w.connection_exterior_or_attachment ω hq hc').resolve_left hnot + have hout := w.counted_terminal_outside Set.univ ω x y hc + have hx := w.attachment_outside ω hatt.1 hout.1 + have hy := w.attachment_outside ω hatt.2 hout.2 + have hne : ¬Conn G (w.exterior ω) w.base w.endpoint := by + intro h + apply hnot + have hx' : Conn G (w.exterior ω) w.base x := hx.elim id (conn_trans G _ h) + have hy' : Conn G (w.exterior ω) w.base y := hy.elim id (conn_trans G _ h) + exact conn_trans G _ (conn_symm G _ hx') hy' + refine ⟨hne,?_⟩ + rcases hx with hx | hx <;> rcases hy with hy | hy + · exact (hnot (conn_trans G _ (conn_symm G _ hx) hy)).elim + · exact Or.inl ⟨hx,hy⟩ + · exact Or.inr ⟨hx,hy⟩ + · exact (hnot (conn_trans G _ (conn_symm G _ hx) hy)).elim + +end RawCorridor +end CorridorContraction +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CorridorBKCalibration +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +def exteriorOrientations (w : RawCorridor G k) (x y : V) : Set (Set E) := + orientedPivotalEvent G x y w.base w.endpoint ∪ orientedPivotalEvent G x y w.endpoint w.base + +theorem measurableSet_exteriorOrientations (w : RawCorridor G k) (x y : V) : + MeasurableSet (w.exteriorOrientations x y) := + (measurableSet_orientedPivotalEvent G x y w.base w.endpoint).union + (measurableSet_orientedPivotalEvent G x y w.endpoint w.base) + +omit [Countable V] [Countable E] in +theorem counted_subset_calibration_exterior (w : RawCorridor G k) + (hlen : 3 ≤ w.path.length) (x y : V) : + {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} ⊆ + w.calibrationEvent ∩ (w.exterior ⁻¹' w.exteriorOrientations x y) := by + intro ω hc + have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) + have hq : ω ∈ w.calibrationEvent := by + refine ⟨fun e he => ?_,?_⟩ + · simpa only [hi,Set.inter_univ] using (hc.2.1 e he).1 + · simpa only [hi,Set.inter_univ] using hc.2.2 + refine ⟨hq,?_⟩ + obtain ⟨hne,ho⟩ := w.counted_exterior_orientation hlen ω hq x y hc + rcases ho with ho | ho + · exact Or.inl ⟨conn_symm G _ ho.1,ho.2,hne⟩ + · exact Or.inr ⟨conn_symm G _ ho.1,ho.2,fun h => hne (conn_symm G _ h)⟩ + +omit [Countable V] in +theorem exterior_orientation_BK (w : RawCorridor G k) (p : unitInterval) (x y a b : V) : + (law p).real (w.exterior ⁻¹' orientedPivotalEvent G x y a b) ≤ + twoPoint G p x a * twoPoint G p b y := by + apply le_trans (measureReal_mono ?_) (bk p {ω | Conn G ω x a} {ω | Conn G ω b y} + (fun _ _ h hc => conn_mono G h hc) (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x a) (finiteWitness_conn G b y)) + intro ω h + exact disjointOccurrence_upper _ _ Set.inter_subset_left + (orientedPivotalEvent_subset_disjoint G x y a b h) + + + +theorem counted_weight_bound (hG : Function.Injective G) (hloc : LocallyFinite G) + (w : RawCorridor G k) (hlen : 3 ≤ w.path.length) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (x y : V) : + w.weight P p * (law p).real {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} ≤ + w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + + twoPoint G p x w.endpoint * twoPoint G p w.base y) := by + have hi := w.calibration_independent hG hloc hlen p (w.exteriorOrientations x y) + (w.measurableSet_exteriorOrientations x y) + have hir : (law p).real (w.calibrationEvent ∩ w.exterior ⁻¹' w.exteriorOrientations x y) = + (law p).real w.calibrationEvent * (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) := by + exact congrArg ENNReal.toReal hi |>.trans ENNReal.toReal_mul + have hb : (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) ≤ + twoPoint G p x w.base * twoPoint G p w.endpoint y + + twoPoint G p x w.endpoint * twoPoint G p w.base y := by + apply le_trans (measureReal_union_le _ _) + exact add_le_add (w.exterior_orientation_BK p x y w.base w.endpoint) + (w.exterior_orientation_BK p x y w.endpoint w.base) + calc + _ ≤ w.weight P p * (law p).real (w.calibrationEvent ∩ w.exterior ⁻¹' w.exteriorOrientations x y) := + mul_le_mul_of_nonneg_left (measureReal_mono (w.counted_subset_calibration_exterior hlen x y)) + (w.weight_nonneg P hP p) + _ = w.probability P * (law p).real (w.exterior ⁻¹' w.exteriorOrientations x y) := by + rw [hir,←mul_assoc,w.calibration_identity hG hloc P p hp hp₁] + _ ≤ _ := mul_le_mul_of_nonneg_left hb (w.2.2.mass_nonneg P hP) + +end RawCorridor +end CorridorBKCalibration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawPathIntegration +attribute [local instance] Classical.propDecidable Classical.decEq + +abbrev RawFrom (H : SimpleGraph V) (k : ℕ) (x : V) := Σ y : V, HoldingWalk H k x y + +namespace RawFrom +variable {H : SimpleGraph V} + +def zeroEquiv (x : V) : RawFrom H 0 x ≃ Unit where + toFun _ := () + invFun _ := ⟨x,.nil x⟩ + left_inv w := by rcases w with ⟨y,w⟩; cases w; rfl + right_inv _ := rfl + +def succEquiv (k : ℕ) (x : V) : RawFrom H (k+1) x ≃ + RawFrom H k x ⊕ (Σ z : H.neighborSet x, RawFrom H k z.val) where + toFun + | ⟨y,.hold w⟩ => .inl ⟨y,w⟩ + | ⟨y,.step (z := z) h w⟩ => .inr ⟨⟨z,h⟩,y,w⟩ + invFun + | .inl ⟨y,w⟩ => ⟨y,.hold w⟩ + | .inr ⟨⟨z,h⟩,y,w⟩ => ⟨y,.step h w⟩ + left_inv w := by rcases w with ⟨y,w⟩; cases w <;> rfl + right_inv w := by rcases w with ⟨y,w⟩ | ⟨⟨z,h⟩,y,w⟩ <;> rfl + +instance finite [∀ x, Finite (H.neighborSet x)] (k : ℕ) (x : V) : Finite (RawFrom H k x) := by + induction k generalizing x with + | zero => exact Finite.of_equiv Unit (zeroEquiv x).symm + | succ k ih => + let (z : V) : Finite (RawFrom H k z) := ih z + exact Finite.of_equiv _ (succEquiv k x).symm + +noncomputable def integral (P : V → V → ℝ) (k : ℕ) (x : V) (f : V → ℝ) : ℝ := + ∑' w : RawFrom H k x, w.2.mass P * f w.1 + +theorem integral_zero (P : V → V → ℝ) (x : V) (f : V → ℝ) : + integral (H := H) P 0 x f = f x := by + unfold integral + rw [←(zeroEquiv x).symm.tsum_eq] + simp only [zeroEquiv,Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,one_mul,tsum_fintype,Fintype.sum_unique] + +theorem integral_succ [∀ x, Finite (H.neighborSet x)] (P : V → V → ℝ) + (k : ℕ) (x : V) (f : V → ℝ) : + integral (H := H) P (k+1) x f = + P x x * integral (H := H) P k x f + + ∑' z : H.neighborSet x, P x z * integral (H := H) P k z f := by + unfold integral + rw [←(succEquiv k x).symm.tsum_eq] + let := Fintype.ofFinite (RawFrom H k x) + let := Fintype.ofFinite (H.neighborSet x) + let (z : H.neighborSet x) := Fintype.ofFinite (RawFrom H k z) + simp only [tsum_fintype,Fintype.sum_sum_type,Fintype.sum_sigma,succEquiv, + Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,mul_assoc,Finset.mul_sum] + +end RawFrom + +theorem finite_openSimpleGraph_neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + Finite ((openSimpleGraph G Set.univ).neighborSet x) := by + apply Set.Finite.to_subtype + apply (finite_neighbors hloc x).subset + intro y hy + obtain ⟨_,e,_,he⟩ := hy + exact ⟨e,he⟩ + +end RawPathIntegration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawPathOperator +attribute [local instance] Classical.propDecidable Classical.decEq + + theorem sum_step_decomposition (H : SimpleGraph V) (P : V → V → ℝ) + (hs : ∀ x, (Function.support (P x)).Finite) + (hstep : ∀ x y, x ≠ y → ¬H.Adj x y → P x y = 0) (x : V) (f : V → ℝ) : + (∑' y, P x y * f y) = P x x * f x + ∑' y : H.neighborSet x, P x y * f y := by + rw [(finiteKernel_summable_mul P hs x f).tsum_eq_add_tsum_ite x] + congr 1 + have he : (∑' y : H.neighborSet x, if (y:V) = x then (0:ℝ) else P x y * f y) = + ∑' y, if y = x then (0:ℝ) else P x y * f y := by + apply tsum_subtype_eq_of_support_subset (f := fun y : V => if y = x then (0:ℝ) else P x y * f y) + intro y hy + by_contra hn + apply hy + by_cases h : y = x + · simp only [h,ite_true] + · simp only [ite_eq_right h,hstep x y (Ne.symm h) hn,zero_mul] + rw [←he] + apply tsum_congr + intro y + have hn : (y:V) ≠ x := by + intro h + have hy : H.Adj x y := y.property + rw [h] at hy + exact H.loopless.irrefl x hy + rw [ite_eq_right hn] + + theorem raw_integral_operator (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (k : ℕ) (x : V) (f : V → ℝ) : + RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k x f = + ∑' y, (matrixCoeff (P^k) x y).re * f y := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := + finite_openSimpleGraph_neighbors G hloc z + have hs (x : V) : (Function.support (walkKernel G hloc a x)).Finite := by + simpa only [pow_one,hP,Complex.ofReal_re] using walkPower_finite_support G hloc a P hpos hP 1 x + have hsP (x : V) : (Function.support (fun y => (matrixCoeff P x y).re)).Finite := by + simpa only [hP,Complex.ofReal_re] using hs x + induction k generalizing x with + | zero => rw [RawFrom.integral_zero,pow_zero,positive_identity_action] + | succ k ih => + rw [RawFrom.integral_succ,pow_succ',finite_positive_product_action P (P^k) hpos hsP + (finite_positive_pow_support P hpos hsP k)] + simp only [hP,Complex.ofReal_re] + rw [sum_step_decomposition (openSimpleGraph G Set.univ) (walkKernel G hloc a) hs] + · simp only [ih] + · intro u v huv hn + apply walkKernel_zero_of_not_step G hloc a u v huv + intro ha + apply hn + obtain ⟨e,he⟩ := ha + exact ⟨huv,e,Set.mem_univ e,he⟩ + +end RawPathOperator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorSum +attribute [local instance] Classical.propDecidable Classical.decEq +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +def counted (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : Prop := + 3 ≤ w.path.length ∧ (∀ z ∈ w.path.support, z ∈ D) ∧ + corridorCounted G w.retained w.blockers D ω x y + +theorem counted_iff (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : + w.counted D ω x y ↔ 3 ≤ w.path.length ∧ corridorCounted G w.retained w.blockers D ω x y := by + constructor + · exact fun h => ⟨h.1,h.2.2⟩ + · rintro ⟨hlen,hc⟩ + exact ⟨hlen,w.support_subset_of_retained (by omega) D (fun e he => (hc.2.1 e he).1.2),hc⟩ + +theorem counted_base_mem_walk (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) + (hc : w.counted D ω x y) (q : (openSimpleGraph G (ω ∩ internalEdges G D)).Walk x y) : + w.base ∈ q.support := by + have hl : 0 < w.path.length := by have := hc.1; omega + obtain ⟨s,hs,hbs⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil + (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp w.path.start_mem_support + obtain ⟨e,he,hGe⟩ := w.edge_has_label s hs + have heq := pivotal_image_mem_edges G _ q e (hc.2.2.2.1 e he).2 + exact SimpleGraph.Walk.mem_support_of_mem_edges heq (hGe.symm ▸ hbs) + +theorem counted_symm (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) : + w.counted D ω x y ↔ w.counted D ω y x := by + rw [counted_iff,counted_iff,corridorCounted_symm] + +theorem measurableSet_counted [Countable E] (w : RawCorridor G k) (D : Set V) (x y : V) : + MeasurableSet {ω | w.counted D ω x y} := by + simp_rw [w.counted_iff] + by_cases h : 3 ≤ w.path.length + · simpa only [h,true_and] using measurableSet_corridorCounted G w.retained w.blockers D x y + · simp only [h,false_and,Set.ofPred_false]; exact MeasurableSet.empty + +end RawCorridor + + theorem finite_corridors_on_bases (G : BondGraph V E) (hloc : LocallyFinite G) (k : ℕ) + (S : Set V) (hS : S.Finite) : {w : RawCorridor G k | w.base ∈ S}.Finite := by + let (x : V) : Finite ((openSimpleGraph G Set.univ).neighborSet x) := + finite_openSimpleGraph_neighbors G hloc x + let : Finite S := hS.to_subtype + let f : (Σ x : S, RawFrom (openSimpleGraph G Set.univ) k x.val) → RawCorridor G k := + fun w => ⟨w.1.val,w.2⟩ + have hr : {w : RawCorridor G k | w.base ∈ S} = Set.range f := by + ext w + constructor + · intro hw + exact ⟨⟨⟨w.base,hw⟩,w.2⟩,rfl⟩ + · rintro ⟨w,rfl⟩ + exact w.1.property + rw [hr] + exact Set.finite_range f + + + +theorem finite_counted_corridors (G : BondGraph V E) (hloc : LocallyFinite G) (k : ℕ) + (D : Set V) (ω : Set E) (x y : V) : {w : RawCorridor G k | w.counted D ω x y}.Finite := by + by_cases hc : Conn G (ω ∩ internalEdges G D) x y + · obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc + apply (finite_corridors_on_bases G hloc k {z | z ∈ q.support} (List.finite_toSet _)).subset + exact fun w hw => w.counted_base_mem_walk D ω x y hw q + · have he : {w : RawCorridor G k | w.counted D ω x y} = ∅ := by + ext w + exact ⟨fun h => hc h.2.2.1,False.elim⟩ + rw [he] + exact Set.finite_empty + +end CorridorSum +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ActualCorridorPenalty +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def corridorPenaltyTerm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + {k : ℕ} (D : Set V) (ω : Set E) (x y : V) (w : RawCorridor G k) : ℝ := + if w.counted D ω x y then w.weight P p else 0 + +noncomputable def corridorPenalty (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : ℝ := + ∑' w : RawCorridor G k, corridorPenaltyTerm G P p D ω x y w + +theorem corridorPenaltyTerm_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) {k : ℕ} (D : Set V) + (ω : Set E) (x y : V) (w : RawCorridor G k) : + 0 ≤ corridorPenaltyTerm G P p D ω x y w := by + unfold corridorPenaltyTerm + split_ifs + · exact w.weight_nonneg P hP p + · exact le_rfl + +theorem corridorPenalty_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + (Function.support (corridorPenaltyTerm G P p (k := k) D ω x y)).Finite := by + apply (finite_counted_corridors G hloc k D ω x y).subset + intro w hw + by_contra hn + exact hw (ite_eq_right hn) + +theorem corridorPenalty_summable (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + Summable (corridorPenaltyTerm G P p (k := k) D ω x y) := + summable_of_hasFiniteSupport (corridorPenalty_finite_support G hloc P p k D ω x y) + +theorem corridorPenalty_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (D : Set V) + (ω : Set E) (x y : V) : 0 ≤ corridorPenalty G P p k D ω x y := + tsum_nonneg (corridorPenaltyTerm_nonneg G P hP p D ω x y) + +theorem corridorPenalty_symm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + corridorPenalty G P p k D ω x y = corridorPenalty G P p k D ω y x := by + unfold corridorPenalty + apply tsum_congr + intro w + simp only [corridorPenaltyTerm,w.counted_symm D ω x y] + +theorem corridorPenalty_restrict (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) + {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') + (x y : V) (hc : Conn G (ω ∩ internalEdges G D) x y) : + corridorPenalty G P p k D' ω' x y ≤ corridorPenalty G P p k D ω x y := by + apply (corridorPenalty_summable G hloc P p k D' ω' x y).tsum_le_tsum ?_ + (corridorPenalty_summable G hloc P p k D ω x y) + intro w + by_cases hn : w.counted D' ω' x y + · have ho : w.counted D ω x y := (w.counted_iff D ω x y).mpr + ⟨hn.1,corridorCounted_restrict G _ _ hD hω x y hc hn.2.2⟩ + simp only [corridorPenaltyTerm,hn,ho,ite_true,le_refl] + · simpa only [corridorPenaltyTerm,hn,ite_false] using corridorPenaltyTerm_nonneg G P hP p D ω x y w + +theorem measurable_corridorPenaltyTerm [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : ℝ) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : + Measurable (fun ω => corridorPenaltyTerm G P p D ω x y w) := by + exact Measurable.ite (w.measurableSet_counted D x y) measurable_const measurable_const + +theorem measurable_corridorPenalty [Countable V] [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (D : Set V) (x y : V) : + Measurable (fun ω => corridorPenalty G P p k D ω x y) := by + exact Measurable.tsum (fun w => measurable_corridorPenaltyTerm G P p D x y w) + +end ActualCorridorPenalty +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ActualWeightedConnections +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def deformedConnection (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : ℝ := + if x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y then + Real.exp (-t * corridorPenalty G P p k D ω x y) else 0 + +noncomputable def deformedKernel (G : BondGraph V E) (P : V → V → ℝ) (p : unitInterval) + (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : ℝ := + ∫ ω, deformedConnection G P p k t D ω x y ∂law p + +theorem deformedConnection_nonneg (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + 0 ≤ deformedConnection G P p k t D ω x y := by + unfold deformedConnection + split_ifs + · exact (Real.exp_pos _).le + · exact le_rfl + +theorem deformedConnection_le_one (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (ω : Set E) (x y : V) : deformedConnection G P p k t D ω x y ≤ 1 := by + unfold deformedConnection + split_ifs + · apply Real.exp_le_one_iff.mpr + exact mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr ht) (corridorPenalty_nonneg G P hP p k D ω x y) + · exact zero_le_one + +theorem deformedConnection_symm (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + deformedConnection G P p k t D ω x y = deformedConnection G P p k t D ω y x := by + have hc : Conn G (ω ∩ internalEdges G D) x y ↔ Conn G (ω ∩ internalEdges G D) y x := + ⟨conn_symm G _,conn_symm G _⟩ + simp only [deformedConnection,corridorPenalty_symm G P p k D ω x y,hc] + congr 1 + apply propext; tauto + +theorem deformedConnection_mono (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) + (t : ℝ) (ht : 0 ≤ t) {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') + (x y : V) : deformedConnection G P p k t D ω x y ≤ deformedConnection G P p k t D' ω' x y := by + by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y + · have hc' : x ∈ D' ∧ y ∈ D' ∧ Conn G (ω' ∩ internalEdges G D') x y := + ⟨hD hc.1,hD hc.2.1,conn_mono G (Set.inter_subset_inter hω (internalEdges_mono G hD)) hc.2.2⟩ + simp only [deformedConnection,hc,hc'] + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (corridorPenalty_restrict G hloc P hP p k hD hω x y hc.2.2) + (neg_nonpos.mpr ht) + · simpa only [deformedConnection,hc,ite_false] using deformedConnection_nonneg G P p k t D' ω' x y + +theorem measurable_deformedConnection [Countable V] [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) + (D : Set V) (x y : V) : Measurable (fun ω => deformedConnection G P p k t D ω x y) := by + have hs : MeasurableSet {ω : Set E | x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y} := by + by_cases hx : x ∈ D <;> by_cases hy : y ∈ D + · simpa only [hx,hy,true_and] using measurableSet_restrictedConn G (internalEdges G D) x y + all_goals simp only [hx,hy,false_and,and_false,Set.ofPred_false]; exact MeasurableSet.empty + exact Measurable.ite hs ((measurable_corridorPenalty G P p k D x y).const_mul (-t)).exp measurable_const + +theorem integrable_deformedConnection [Countable V] [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + Integrable (fun ω => deformedConnection G P p k t D ω x y) (law p) := by + apply Integrable.mono' (integrable_const (1:ℝ)) (measurable_deformedConnection G P p k t D x y).aestronglyMeasurable + filter_upwards [] with ω + rw [Real.norm_eq_abs,abs_of_nonneg (deformedConnection_nonneg G P p k t D ω x y)] + exact deformedConnection_le_one G P hP p k t ht D ω x y + +end ActualWeightedConnections +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedConnectionEndpoints +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem corridorPenalty_diag (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (D : Set V) (ω : Set E) (x : V) : corridorPenalty G P p k D ω x x = 0 := by + unfold corridorPenalty + rw [←tsum_zero] + apply tsum_congr + intro w + have hn : ¬w.counted D ω x x := by + intro hc + have hl : 0 < w.path.length := by have := hc.1; omega + obtain ⟨s,hs,_⟩ := (SimpleGraph.Walk.mem_support_iff_exists_mem_edges_of_not_nil + (SimpleGraph.Walk.not_nil_iff_lt_length.mpr hl)).mp w.path.start_mem_support + obtain ⟨e,he,_⟩ := w.edge_has_label s hs + exact (hc.2.2.2.1 e he).2 (conn_refl G _ x) + exact ite_eq_right hn + +theorem deformedConnection_diag (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) (hx : x ∈ D) : + deformedConnection G P p k t D ω x x = 1 := by + simp only [deformedConnection,hx,conn_refl G _ x,and_self,ite_true, + corridorPenalty_diag,mul_zero,Real.exp_zero] + +theorem deformedConnection_zero (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + deformedConnection G P p k 0 D ω x y = + if x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y then 1 else 0 := by + simp only [deformedConnection,neg_zero,zero_mul,Real.exp_zero] + +theorem deformedConnection_full_zero (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) + (k : ℕ) (ω : Set E) (x y : V) : deformedConnection G P p k 0 Set.univ ω x y = + if Conn G ω x y then 1 else 0 := by + have hi : internalEdges G Set.univ = Set.univ := Set.eq_univ_of_forall (fun _ _ _ => trivial) + simp only [deformedConnection_zero,Set.mem_univ,true_and,hi,Set.inter_univ] + +theorem deformedConnection_change (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (ω : Set E) (x y : V) : + 0 ≤ deformedConnection G P p k 0 D ω x y - deformedConnection G P p k t D ω x y ∧ + deformedConnection G P p k 0 D ω x y - deformedConnection G P p k t D ω x y ≤ + t*corridorPenalty G P p k D ω x y := by + have hN := corridorPenalty_nonneg G P hP p k D ω x y + by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y + · simp only [deformedConnection,hc,ite_true,neg_zero,zero_mul,Real.exp_zero,and_self] + constructor + · exact sub_nonneg.mpr ((Real.exp_le_one_iff).mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr ht) hN)) + · have h := Real.one_sub_le_exp_neg (t*corridorPenalty G P p k D ω x y) + rw [←neg_mul] at h + linarith + · simp only [deformedConnection,hc,ite_false,sub_self] + exact ⟨le_rfl,mul_nonneg ht hN⟩ + +theorem deformedKernel_zero [Countable V] [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : unitInterval) (k : ℕ) (x y : V) : + deformedKernel G P p k 0 Set.univ x y = twoPoint G p x y := by + unfold deformedKernel + simp_rw [deformedConnection_full_zero] + have hi := integral_indicator_const (μ := law p) (1:ℝ) (measurableSet_conn G x y) + simpa only [Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_one,Measure.real,twoPoint] using hi + +end WeightedConnectionEndpoints +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawWalkDiagrams +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_diagram_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (k : ℕ) (x y : V) : + HasSum (fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * + ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re)) + (matrixCoeff (A*(P^k*A)) x y).re := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := + finite_openSimpleGraph_neighbors G hloc z + let F := fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * + ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re) + have hFn (w : RawCorridor G k) : 0 ≤ F w := + mul_nonneg (w.2.2.mass_nonneg _ hK) (mul_nonneg (hA _ _).2 (hA _ _).2) + have hr (z : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k z, F ⟨z,w⟩) = + (matrixCoeff A x z).re * (matrixCoeff (P^k*A) z y).re := by + have h := raw_integral_operator G hloc a P hpos hP k z (fun u => (matrixCoeff A u y).re) + have he : (∑' w : RawFrom (openSimpleGraph G Set.univ) k z, F ⟨z,w⟩) = + (matrixCoeff A x z).re * RawFrom.integral (H := openSimpleGraph G Set.univ) + (walkKernel G hloc a) k z (fun u => (matrixCoeff A u y).re) := by + rw [RawFrom.integral,←tsum_mul_left] + apply tsum_congr + intro w + dsimp only [F,RawCorridor.probability,RawCorridor.base,RawCorridor.endpoint] + change w.2.mass _ * (_ * _) = _ * (w.2.mass _ * _) + ring + rw [he,h,((hpos.pow k).mul_hasSum A z y).tsum_eq] + have ho := hA.mul_hasSum (P^k*A) x y + have hs : Summable F := (summable_sigma_of_nonneg hFn).mpr ⟨fun z => by + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) k z) + exact (hasSum_fintype _).summable,by simpa only [hr] using ho.summable⟩ + have he : (∑' w, F w) = (matrixCoeff (A*(P^k*A)) x y).re := by + rw [hs.tsum_sigma] + simpa only [hr] using ho.tsum_eq + exact he ▸ hs.hasSum + + theorem sandwich_selfAdjoint (A P : Hilbert V →L[ℂ] Hilbert V) + (hA : IsSelfAdjoint A) (hP : IsSelfAdjoint P) (k : ℕ) : IsSelfAdjoint (A*(P^k*A)) := by + change star (A*(P^k*A)) = A*(P^k*A) + simp only [star_mul,hA.star_eq,(hP.pow k).star_eq,mul_assoc] + +end RawWalkDiagrams +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawWalkSymmetricDiagrams +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem raw_two_diagrams_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) + (k : ℕ) (x y : V) : + HasSum (fun w : RawCorridor G k => w.probability (walkKernel G hloc a) * + ((matrixCoeff A x w.base).re * (matrixCoeff A w.endpoint y).re + + (matrixCoeff A x w.endpoint).re * (matrixCoeff A w.base y).re)) + (2*(matrixCoeff (A*(P^k*A)) x y).re) := by + have h₁ := raw_diagram_hasSum G hloc a P hpos hP hK A hA k x y + have h₂ := raw_diagram_hasSum G hloc a P hpos hP hK A hA k y x + have hh := h₁.add h₂ + have hC := matrixCoeff_real_symm (A*(P^k*A)) (sandwich_selfAdjoint A P hAs hPs k) y x + rw [hC,←two_mul] at hh + convert hh using 1 + ext w + rw [matrixCoeff_real_symm A hAs y w.base,matrixCoeff_real_symm A hAs w.endpoint x] + ring + +end RawWalkSymmetricDiagrams +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section PenaltyTermExpectation +attribute [local instance] Classical.propDecidable Classical.decEq + + theorem integrable_corridorPenaltyTerm [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : unitInterval) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : + Integrable (fun ω => corridorPenaltyTerm G P p D ω x y w) (law p) := by + exact (integrable_const (w.weight P p)).indicator (w.measurableSet_counted D x y) + +theorem integral_corridorPenaltyTerm [Countable E] (G : BondGraph V E) + (P : V → V → ℝ) (p : unitInterval) {k : ℕ} (D : Set V) (x y : V) (w : RawCorridor G k) : + (∫ ω, corridorPenaltyTerm G P p D ω x y w ∂law p) = + w.weight P p * (law p).real {ω | w.counted D ω x y} := by + have h := integral_indicator_const (μ := law p) (w.weight P p) (w.measurableSet_counted D x y) + simpa only [corridorPenaltyTerm,Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_comm] using h + + +theorem integral_corridorPenaltyTerm_le [Countable V] [Countable E] + (G : BondGraph V E) (hG : Function.Injective G) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) {k : ℕ} (x y : V) (w : RawCorridor G k) : + (∫ ω, corridorPenaltyTerm G P p Set.univ ω x y w ∂law p) ≤ + w.probability P * (twoPoint G p x w.base * twoPoint G p w.endpoint y + + twoPoint G p x w.endpoint * twoPoint G p w.base y) := by + rw [integral_corridorPenaltyTerm] + by_cases hl : 3 ≤ w.path.length + · have he : {ω | w.counted Set.univ ω x y} = + {ω | corridorCounted G w.retained w.blockers Set.univ ω x y} := by + ext ω + simp only [Set.mem_ofPred_eq,w.counted_iff,hl,true_and] + rw [he] + exact w.counted_weight_bound hG hloc hl P hP p hp hp₁ x y + · have he : {ω | w.counted Set.univ ω x y} = ∅ := by + ext ω + simp only [Set.mem_ofPred_eq,w.counted_iff,hl,false_and,Set.mem_empty_iff_false] + rw [he,measureReal_empty,mul_zero] + exact mul_nonneg (w.2.2.mass_nonneg P hP) (add_nonneg + (mul_nonneg (twoPoint_nonneg G p x w.base) (twoPoint_nonneg G p w.endpoint y)) + (mul_nonneg (twoPoint_nonneg G p x w.endpoint) (twoPoint_nonneg G p w.base y))) + +end PenaltyTermExpectation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FullCorridorPenaltyExpectation +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + +theorem corridorPenalty_integrable_bound (G : BondGraph V E) + (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) + (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) (k : ℕ) (x y : V) : + Integrable (fun ω => corridorPenalty G (walkKernel G hloc a) p k Set.univ ω x y) (law p) ∧ + (∫ ω, corridorPenalty G (walkKernel G hloc a) p k Set.univ ω x y ∂law p) ≤ + 2*(matrixCoeff (A*(P^k*A)) x y).re := by + let K := walkKernel G hloc a + have hK (u v : V) : 0 ≤ K u v := by simpa only [hP,Complex.ofReal_re] using (hpos u v).2 + let F := fun w : RawCorridor G k => fun ω : Set E => corridorPenaltyTerm G K p Set.univ ω x y w + have hFi (w : RawCorridor G k) : Integrable (F w) (law p) := integrable_corridorPenaltyTerm G K p Set.univ x y w + have hFn (w : RawCorridor G k) (ω : Set E) : 0 ≤ F w ω := corridorPenaltyTerm_nonneg G K hK p _ ω x y w + have hd := raw_two_diagrams_hasSum G hloc a P hpos hPs hP hK A hA hAs k x y + simp only [hAT,Complex.ofReal_re] at hd + have hb (w : RawCorridor G k) := integral_corridorPenaltyTerm_le G hG hloc K hK p hp hp₁ x y w + have hs : Summable (fun w => ∫ ω, F w ω ∂law p) := Summable.of_nonneg_of_le + (fun w => integral_nonneg (hFn w)) hb hd.summable + have hsN (ω : Set E) := corridorPenalty_summable G hloc K p k Set.univ ω x y + have hlin : (∫⁻ ω, ENNReal.ofReal (corridorPenalty G K p k Set.univ ω x y) ∂law p) = + ENNReal.ofReal (∑' w, ∫ ω, F w ω ∂law p) := by + have he (ω : Set E) : ENNReal.ofReal (corridorPenalty G K p k Set.univ ω x y) = + ∑' w, ENNReal.ofReal (F w ω) := ENNReal.ofReal_tsum_of_nonneg (fun w => hFn w ω) (hsN ω) + simp_rw [he] + rw [lintegral_tsum (fun w => (hFi w).aestronglyMeasurable.aemeasurable.ennreal_ofReal)] + simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hFn _))] + exact (ENNReal.ofReal_tsum_of_nonneg (fun w => integral_nonneg (hFn w)) hs).symm + have hNn (ω : Set E) := corridorPenalty_nonneg G K hK p k Set.univ ω x y + have hi : Integrable (fun ω => corridorPenalty G K p k Set.univ ω x y) (law p) := + ⟨(measurable_corridorPenalty G K p k Set.univ x y).aestronglyMeasurable, + (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hNn)).mpr (by rw [hlin]; exact ENNReal.ofReal_lt_top)⟩ + refine ⟨hi,?_⟩ + have hn : Summable (fun w => ∫ ω, ‖F w ω‖ ∂law p) := by + simpa only [Real.norm_of_nonneg (hFn _ _)] using hs + change (∫ ω, ∑' w, F w ω ∂law p) ≤ _ + rw [←integral_tsum_of_summable_integral_norm hFi hn] + exact (hs.tsum_le_tsum hb hd.summable).trans_eq hd.tsum_eq + +end FullCorridorPenaltyExpectation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SmallDeformationEntrywise +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + + + +theorem deformedKernel_change_bound (G : BondGraph V E) + (hG : Function.Injective G) (hloc : LocallyFinite G) (p : unitInterval) + (hp : 0 < (p:ℝ)) (hp₁ : (p:ℝ) < 1) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) (hAs : IsSelfAdjoint A) + (hAT : ∀ x y, matrixCoeff A x y = (twoPoint G p x y : ℂ)) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (x y : V) : + 0 ≤ twoPoint G p x y - deformedKernel G (walkKernel G hloc a) p k t Set.univ x y ∧ + twoPoint G p x y - deformedKernel G (walkKernel G hloc a) p k t Set.univ x y ≤ + 2*t*(matrixCoeff (A*(P^k*A)) x y).re := by + let K := walkKernel G hloc a + have hK (u v : V) : 0 ≤ K u v := by simpa only [hP,Complex.ofReal_re] using (hpos u v).2 + have hi₀ := integrable_deformedConnection G K hK p k 0 (le_refl _) Set.univ x y + have hi := integrable_deformedConnection G K hK p k t ht Set.univ x y + have he : twoPoint G p x y - deformedKernel G K p k t Set.univ x y = + ∫ ω, deformedConnection G K p k 0 Set.univ ω x y - deformedConnection G K p k t Set.univ ω x y ∂law p := by + rw [integral_sub hi₀ hi] + change _ = deformedKernel G K p k 0 Set.univ x y - _ + rw [deformedKernel_zero] + rfl + rw [he] + refine ⟨integral_nonneg (fun ω => (deformedConnection_change G K hK p k t ht Set.univ ω x y).1),?_⟩ + obtain ⟨hNi,hNb⟩ := corridorPenalty_integrable_bound G hG hloc p hp hp₁ a P hpos hPs hP A hA hAs hAT k x y + calc + _ ≤ ∫ ω, t*corridorPenalty G K p k Set.univ ω x y ∂law p := + integral_mono (hi₀.sub hi) (hNi.const_mul t) + (fun ω => (deformedConnection_change G K hK p k t ht Set.univ ω x y).2) + _ = t*∫ ω, corridorPenalty G K p k Set.univ ω x y ∂law p := integral_const_mul _ _ + _ ≤ t*(2*(matrixCoeff (A*(P^k*A)) x y).re) := mul_le_mul_of_nonneg_left hNb ht + _ = _ := by ring + +omit [Countable V] [Countable E] in +theorem deformedKernel_nonneg (G : BondGraph V E) (P : V → V → ℝ) (p : unitInterval) + (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : 0 ≤ deformedKernel G P p k t D x y := + integral_nonneg (fun ω => deformedConnection_nonneg G P p k t D ω x y) + +end SmallDeformationEntrywise +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/Derivatives.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/Derivatives.lean index 47f1556f17ce5fd710511deefc89bd0ba508a172..278ecf37c0ee3b054c32c42129eebdd6908c6d87 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/Derivatives.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/Derivatives.lean @@ -1,1225 +1,1225 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.ClusterProducts - -namespace OAI - -/-! Derivatives for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedNeighborhoodEstimate -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem twoPoint_neighbor_div_bound [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (hp : 0 < (p:ℝ)) (v a z : V) (hz : z ∈ neighbors G hloc a) : - twoPoint G p v z ≤ twoPoint G p v a / (p:ℝ) := by - obtain ⟨e,he⟩ := (mem_neighbors G hloc a z).mp hz - have hh := restrictedTwoPoint_adj_lower G Set.univ p a z v e he (Set.mem_univ _) - simp only [Set.inter_univ] at hh - change (p:ℝ)*twoPoint G p z v ≤ twoPoint G p a v at hh - rw [twoPoint_symm G p z v,twoPoint_symm G p a v] at hh - exact (le_div_iff₀ hp).mpr (by simpa only [mul_comm] using hh) - - - -theorem neighborhood_twoPoint_bound [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) (p : unitInterval) (hp : 0 < (p:ℝ)) - (W : Finset V) (v : V) : - (∑' z : closedBondNeighborhood G (W:Set V), twoPoint G p v z) ≤ - (1+(d:ℝ)/(p:ℝ)) * (∑ a ∈ W, twoPoint G p v a) := by - apply (neighborhood_mass_le G hloc W (twoPoint G p v) (twoPoint_nonneg G p v)).trans - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro a _ - have hsum : (∑ z ∈ neighbors G hloc a, twoPoint G p v z) ≤ - (d:ℝ)*(twoPoint G p v a/(p:ℝ)) := by - calc - _ ≤ ∑ _z ∈ neighbors G hloc a, twoPoint G p v a/(p:ℝ) := - Finset.sum_le_sum (fun z hz => twoPoint_neighbor_div_bound G hloc p hp v a z hz) - _ = ((neighbors G hloc a).card:ℝ)*(twoPoint G p v a/(p:ℝ)) := by simp only [Finset.sum_const,nsmul_eq_mul] - _ ≤ _ := mul_le_mul_of_nonneg_right (Nat.cast_le.mpr (hd a)) (div_nonneg (twoPoint_nonneg G p _ _) hp.le) - calc - _ ≤ twoPoint G p v a + (d:ℝ)*(twoPoint G p v a/(p:ℝ)) := add_le_add (le_refl _) hsum - _ = _ := by ring - -end WeightedNeighborhoodEstimate -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SizeWeightedPotential -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def sizeMembership (G : BondGraph V E) (x a : V) (ω : Set E) : ℝ := - if Conn G ω x a then ((cluster G ω x).ncard:ℝ) else 0 - -noncomputable def sizeWeightedConnectionPotential (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) : ℝ := ∑' a, sizeMembership G x a ω * twoPoint G p y a - -theorem sizeMembership_nonneg (G : BondGraph V E) (x a : V) (ω : Set E) : - 0 ≤ sizeMembership G x a ω := by - unfold sizeMembership - split_ifs - · exact Nat.cast_nonneg _ - · rfl - -theorem sizeMembership_le (G : BondGraph V E) (x a : V) (ω : Set E) : - sizeMembership G x a ω ≤ ((cluster G ω x).ncard:ℝ) := by - unfold sizeMembership - split_ifs - · rfl - · exact Nat.cast_nonneg _ - -theorem measurable_sizeMembership [Countable V] [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (x a : V) : Measurable (sizeMembership G x a) := by - apply Measurable.ite (measurableSet_conn G x a) - ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x)) measurable_const - -theorem integrable_sizeMembership [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x a : V) : Integrable (sizeMembership G x a) (law p) := by - apply Integrable.mono' (susceptibility_eq_integral G hloc hqt p hp x).1 - (measurable_sizeMembership G hloc x a).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun ω => by - rw [Real.norm_of_nonneg (sizeMembership_nonneg G x a ω)] - exact sizeMembership_le G x a ω) - -theorem integral_sizeMembership_le_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x a : V) : - (∫ ω, sizeMembership G x a ω ∂law p) ≤ susceptibility G p x := by - rw [(susceptibility_eq_integral G hloc hqt p hp x).2] - exact integral_mono (integrable_sizeMembership G hloc hqt p hp x a) - (susceptibility_eq_integral G hloc hqt p hp x).1 (sizeMembership_le G x a) - -theorem sizeWeightedConnectionPotential_eq_finite (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) (hf : (cluster G ω x).Finite) : - sizeWeightedConnectionPotential G p x y ω = - ((cluster G ω x).ncard:ℝ) * ∑ a ∈ hf.toFinset, twoPoint G p y a := by - unfold sizeWeightedConnectionPotential - rw [tsum_eq_sum (s := hf.toFinset)] - · rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a ha - have hc : Conn G ω x a := hf.mem_toFinset.mp ha - simp only [sizeMembership,ite_eq_left hc] - · intro a ha - have hn : ¬Conn G ω x a := fun hc => ha (hf.mem_toFinset.mpr hc) - simp only [sizeMembership,ite_eq_right hn,zero_mul] - -end SizeWeightedPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SizePotentialIntegral -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -theorem summable_sizePotential_integral_norm (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : - Summable (fun a => ∫ ω, ‖sizeMembership G x a ω * twoPoint G p y a‖ ∂law p) := by - apply ((summable_twoPoint_subcritical G hloc hqt p hp y).mul_left (susceptibility G p x)).of_nonneg_of_le - · exact fun a => integral_nonneg (fun _ => norm_nonneg _) - · intro a - simp only [Real.norm_of_nonneg (mul_nonneg (sizeMembership_nonneg G x a _) (twoPoint_nonneg G p y a)), - integral_mul_const] - exact mul_le_mul_of_nonneg_right (integral_sizeMembership_le_susceptibility G hloc hqt p hp x a) - (twoPoint_nonneg G p y a) - -theorem integrable_sizeWeightedConnectionPotential (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (sizeWeightedConnectionPotential G p x y) (law p) := by - apply Integrable.mono' ((susceptibility_eq_integral G hloc hqt p hp x).1.mul_const - (susceptibility G p y)) - (Measurable.tsum (fun a => (measurable_sizeMembership G hloc x a).mul_const (twoPoint G p y a))).aestronglyMeasurable - exact Filter.Eventually.of_forall (fun ω => by - have hb (a : V) : sizeMembership G x a ω * twoPoint G p y a ≤ - ((cluster G ω x).ncard:ℝ)*twoPoint G p y a := - mul_le_mul_of_nonneg_right (sizeMembership_le G x a ω) (twoPoint_nonneg G p y a) - have hn (a : V) : 0 ≤ sizeMembership G x a ω * twoPoint G p y a := - mul_nonneg (sizeMembership_nonneg G x a ω) (twoPoint_nonneg G p y a) - have hs := (summable_twoPoint_subcritical G hloc hqt p hp y).mul_left ((cluster G ω x).ncard:ℝ) - change ‖∑' a, sizeMembership G x a ω * twoPoint G p y a‖ ≤ _ - rw [Real.norm_of_nonneg (tsum_nonneg hn)] - exact ((hs.of_nonneg_of_le hn hb).tsum_le_tsum hb hs).trans_eq (tsum_mul_left)) - -omit [Countable V] [Countable E] [Nonempty V] in -theorem sizeWeightedConnectionPotential_nonneg (G : BondGraph V E) (p : unitInterval) - (x y : V) (ω : Set E) : 0 ≤ sizeWeightedConnectionPotential G p x y ω := - tsum_nonneg (fun a => mul_nonneg (sizeMembership_nonneg G x a ω) (twoPoint_nonneg G p y a)) - -theorem summable_twoPoint_cube_pair (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : - Summable (fun ba : V×V => twoPoint G p x ba.1 * twoPoint G p ba.1 ba.2 * twoPoint G p y ba.2) := by - exact (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le - (fun ba => mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) - (twoPoint_nonneg G p _ _)) - (fun ba => mul_le_of_le_one_right - (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_le_one G p _ _)) - - -theorem integral_sizeWeightedConnectionPotential_le (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : - (∫ ω, sizeWeightedConnectionPotential G p x y ω ∂law p) ≤ - maxSusceptibility G p * (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) := by - have hi (a : V) := (integrable_sizeMembership G hloc hqt p hp x a).mul_const (twoPoint G p y a) - have hs := summable_sizePotential_integral_norm G hloc hqt p hp x y - have hc : Summable (fun a => ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) := - (summable_twoPoint_cube_pair G hloc hqt p hp x y).prod_symm.prod - change (∫ ω, ∑' a, sizeMembership G x a ω * twoPoint G p y a ∂law p) ≤ _ - rw [←integral_tsum_of_summable_integral_norm hi hs,←tsum_mul_left] - have hs' : Summable (fun a => ∫ ω, sizeMembership G x a ω * twoPoint G p y a ∂law p) := by - simpa only [Real.norm_of_nonneg (mul_nonneg (sizeMembership_nonneg G x _ _) (twoPoint_nonneg G p y _))] using hs - apply hs'.tsum_le_tsum (fun a => ?_) (hc.mul_left _) - rw [integral_mul_const,tsum_mul_right] - calc - _ ≤ (maxSusceptibility G p * (∑' b, twoPoint G p x b * twoPoint G p b a)) * twoPoint G p y a := - mul_le_mul_of_nonneg_right (integral_size_membership_le G hloc hqt p hp x a) (twoPoint_nonneg G p y a) - _ = _ := mul_assoc _ _ _ - -end SizePotentialIntegral -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedCorrelationPointwise -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem deformedFreshExteriorMoment_lower (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (hp : p < pc G) (hp₀ : 0 < (p:ℝ)) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (x y : V) (ω : Set E) (hf : (cluster G ω x).Finite) : - deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t D y - - (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p * sizeWeightedConnectionPotential G p x y ω ≤ - deformedFreshExteriorMoment G P p k t D x y ω := by - let A := cluster G (ω ∩ internalEdges G D) x - have hsub : A ⊆ cluster G ω x := fun _ h => conn_mono G Set.inter_subset_left h - have hA : A.Finite := hf.subset hsub - have hn : (∑' z : closedBondNeighborhood G A, twoPoint G p y z) ≤ - (1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a) := by - have hh := neighborhood_twoPoint_bound G hloc d hd p hp₀ hA.toFinset y - rw [hA.coe_toFinset] at hh - exact hh.trans (mul_le_mul_of_nonneg_left - (Finset.sum_le_sum_of_subset_of_nonneg - (fun a ha => hf.mem_toFinset.mpr (hsub (hA.mem_toFinset.mp ha))) - (fun a _ _ => twoPoint_nonneg G p y a)) - (add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le))) - have hm := deformedClusterMass_le_ncard G P hP p k t ht D ω x hf - have hm₀ := deformedClusterMass_nonneg G P p k t D ω x - have hχ : 0 ≤ maxSusceptibility G p := zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp) - have hh := mul_le_mul_of_nonneg_left - (deformedSusceptibility_deletion G hloc hqt P hP p hp k t ht D A y) hm₀ - have hsum : 0 ≤ ∑ a ∈ hf.toFinset, twoPoint G p y a := - Finset.sum_nonneg (fun a _ => twoPoint_nonneg G p y a) - have hC : 0 ≤ 1+(d:ℝ)/(p:ℝ) := add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le) - have herr : deformedClusterMass G P p k t D ω x * - (maxSusceptibility G p * (∑' z : closedBondNeighborhood G A, twoPoint G p y z)) ≤ - (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p * sizeWeightedConnectionPotential G p x y ω := by - calc - _ ≤ deformedClusterMass G P p k t D ω x * - (maxSusceptibility G p * ((1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a))) := - mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hn hχ) hm₀ - _ ≤ ((cluster G ω x).ncard:ℝ)* - (maxSusceptibility G p * ((1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a))) := - mul_le_mul_of_nonneg_right hm (mul_nonneg hχ (mul_nonneg hC hsum)) - _ = _ := by rw [sizeWeightedConnectionPotential_eq_finite G p x y ω hf]; ring - dsimp only [deformedFreshExteriorMoment] - dsimp only [A] at hh - nlinarith - -end WeightedCorrelationPointwise -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedCorrelationIntegral -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem deformed_distinct_correlation (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (hp : p < pc G) (hp₀ : 0 < (p:ℝ)) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (x y : V) : - deformedSusceptibility G P p k t D x * deformedSusceptibility G P p k t D y - - (1+(d:ℝ)/(p:ℝ))*(maxSusceptibility G p)^2 * - (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) ≤ - ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by - rw [←integral_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y] - have hi := integrable_deformedClusterMass G hloc hqt P hP p hp k t ht D x - have hj := integrable_sizeWeightedConnectionPotential G hloc hqt p hp x y - have hb := integral_mono_ae - ((hi.mul_const (deformedSusceptibility G P p k t D y)).sub - (hj.const_mul ((1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p))) - (integrable_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y) - (by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact deformedFreshExteriorMoment_lower G hloc hqt d hd P hP p hp hp₀ k t ht D x y ω hω) - simp only [Pi.sub_apply] at hb - rw [integral_sub (hi.mul_const _) (hj.const_mul _),integral_mul_const,integral_const_mul, - ←deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht D x] at hb - have hC : 0 ≤ (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p := - mul_nonneg (add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le)) - (zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp)) - have herr := mul_le_mul_of_nonneg_left - (integral_sizeWeightedConnectionPotential_le G hloc hqt p hp x y) hC - nlinarith - -end WeightedCorrelationIntegral -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExactCubeKernel -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem HasKernel.square_real_kernel (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : - (∑' b, twoPoint G p x b * twoPoint G p b y) = (matrixCoeff (T^2) x y).re := by - have hh := ((hT.positiveRealMatrix G p T).mul_hasSum T x y).tsum_eq - simpa only [hT.matrixCoeff_re G p T,pow_two] using hh - -theorem HasKernel.cube_real_kernel (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : - (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) = - (matrixCoeff (T^3) x y).re := by - have hh := (((hT.positiveRealMatrix G p T).pow 2).mul_hasSum T x y).tsum_eq - calc - _ = ∑' a, (matrixCoeff (T^2) x a).re * (matrixCoeff T a y).re := by - apply tsum_congr - intro a - rw [tsum_mul_right,hT.square_real_kernel G p T x a,hT.matrixCoeff_re G p T a y,twoPoint_symm G p y a] - _ = _ := by simpa only [show T^2*T = T^3 by rw [←pow_succ]] using hh - -end ExactCubeKernel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformWeightedCorrelation -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem deformed_distinct_correlation_uniform (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) - (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : - deformedSusceptibility G P p k t D x * deformedSusceptibility G P p k t D y - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * (matrixCoeff (T^3) x y).re ≤ - ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then - deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by - have hp₀ : 0 < (p:ℝ) := (half_pos hpcrit).trans_le hpnear - have hb := deformed_distinct_correlation G hloc hqt d hd P hP p hp hp₀ k t ht D x y - rw [hT.cube_real_kernel G p T x y] at hb - have hc : (d:ℝ)/(p:ℝ) ≤ 2*(d:ℝ)/(pc G:ℝ) := by - apply (div_le_div_iff₀ hp₀ hpcrit).mpr - nlinarith [Nat.cast_nonneg (α := ℝ) d] - have he := mul_le_mul_of_nonneg_right (add_le_add (le_refl (1:ℝ)) hc) - (mul_nonneg (sq_nonneg (maxSusceptibility G p)) (((hT.positiveRealMatrix G p T).pow 3) x y).2) - nlinarith - -end UniformWeightedCorrelation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorSizeBounds -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem incidentSupport_card_le (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (W : Finset V) : - (incidentSupport G hloc W).card ≤ W.card*d := by - apply Finset.card_biUnion_le_card_mul - intro x _ - rw [←Set.ncard_eq_toFinset_card _ (hloc x)] - exact (incident_ncard_le_degree G hloc x).trans (hd x) - -theorem reachBall_ncard_le_pow (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (x : V) (k : ℕ) : - (reachBall G x k).ncard ≤ (d+1)^k := by - induction k with - | zero => simp only [reachBall,Set.ncard_singleton,pow_zero,le_refl] - | succ k ih => - let W := (finite_reachBall hloc x k).toFinset - have he : reachBall G x (k+1) = (W ∪ W.biUnion (neighbors G hloc) : Finset V) := by - ext z - simp only [reachBall,Set.mem_union,Set.mem_iUnion,Set.mem_ofPred_eq,Finset.mem_coe, - Finset.mem_union,Finset.mem_biUnion,mem_neighbors,Set.Finite.mem_toFinset,W,Adj,exists_prop] - rw [he,Set.ncard_coe_finset] - have hb : (W.biUnion (neighbors G hloc)).card ≤ W.card*d := - Finset.card_biUnion_le_card_mul _ _ _ (fun a _ => (neighbors_card_le_degree G hloc a).trans (hd a)) - have hi : W.card ≤ (d+1)^k := by simpa only [W,←Set.ncard_eq_toFinset_card] using ih - calc - _ ≤ W.card + (W.biUnion (neighbors G hloc)).card := Finset.card_union_le _ _ - _ ≤ W.card + W.card*d := Nat.add_le_add_left hb _ - _ = W.card*(d+1) := by ring - _ ≤ (d+1)^k*(d+1) := Nat.mul_le_mul_right _ hi - _ = _ := (pow_succ _ _).symm - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem interior_card_le (w : RawCorridor G k) : w.interior.card ≤ w.path.length := by - have hs : w.interior ⊂ w.path.support.toFinset := by - apply Finset.ssubset_iff_subset_ne.mpr - refine ⟨Finset.sdiff_subset,?_⟩ - intro he - have hb : w.base ∈ w.path.support.toFinset := List.mem_toFinset.mpr w.path.start_mem_support - rw [←he] at hb - have hn : w.base ∉ w.interior := by simp only [interior,Finset.mem_sdiff,Finset.mem_insert, - true_or,not_true_eq_false,and_false,not_false_eq_true] - exact hn hb - have hh := Finset.card_lt_card hs - rw [List.toFinset_card_of_nodup w.path_isPath.support_nodup,SimpleGraph.Walk.length_support] at hh - omega - -theorem blockers_ncard_le (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) - (w : RawCorridor G k) : w.blockers.ncard ≤ d*k := by - have hs : w.blockers ⊆ (incidentSupport G hloc w.interior : Set E) := - fun e he => (mem_incidentSupport G hloc w.interior e).mpr he.1 - calc - _ ≤ (incidentSupport G hloc w.interior : Set E).ncard := Set.ncard_le_ncard hs (Finset.finite_toSet _) - _ = (incidentSupport G hloc w.interior).card := Set.ncard_coe_finset _ - _ ≤ w.interior.card*d := incidentSupport_card_le G hloc d hd _ - _ ≤ k*d := Nat.mul_le_mul_right _ (w.interior_card_le.trans w.path_length) - _ = _ := Nat.mul_comm _ _ - -end RawCorridor -end CorridorSizeBounds -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawWalkTotalMass -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem walkKernel_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (x : V) : (Function.support (walkKernel G hloc a x)).Finite := by - apply (Finset.finite_toSet (insert x (neighbors G hloc x))).subset - intro y hy - by_contra hn - have hn' : y ≠ x ∧ ¬Adj G x y := by simpa only [Finset.mem_coe,Finset.mem_insert,mem_neighbors,not_or] using hn - exact hy (by simp only [walkKernel,ite_eq_right hn'.1.symm,ite_eq_right hn'.2,add_zero]) - -theorem walkKernel_tsum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) (x : V) : - (∑' y, walkKernel G hloc a x y) = 1 := by - rw [tsum_eq_sum (s := insert x (neighbors G hloc x))] - · exact walkKernel_row_sum G hloc a x - · intro y hy - have hn : y ≠ x ∧ ¬Adj G x y := by simpa only [Finset.mem_insert,mem_neighbors,not_or] using hy - simp only [walkKernel,ite_eq_right hn.1.symm,ite_eq_right hn.2,add_zero] - -theorem raw_integral_one (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (k : ℕ) (x : V) : - RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k x (fun _ => 1) = 1 := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - induction k generalizing x with - | zero => exact RawFrom.integral_zero _ _ _ - | succ k ih => - rw [RawFrom.integral_succ] - simp only [ih,mul_one] - have he := sum_step_decomposition (openSimpleGraph G Set.univ) (walkKernel G hloc a) - (walkKernel_finite_support G hloc a) (fun x y hxy hn => by - apply walkKernel_zero_of_not_step G hloc a x y hxy - intro h - obtain ⟨e,he⟩ := h - exact hn ⟨hxy,e,Set.mem_univ e,he⟩) x (fun _ => 1) - simpa only [mul_one,walkKernel_tsum G hloc a] using he.symm - - -theorem rawFrom_probability_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (k : ℕ) (x : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, w.2.mass (walkKernel G hloc a)) = 1 := by - simpa only [RawFrom.integral,mul_one] using raw_integral_one G hloc a k x - -end RawWalkTotalMass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawWalkFiniteBases -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem raw_probability_on_bases_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (k : ℕ) (S : Set V) (hS : S.Finite) : - (∑' w : RawCorridor G k, if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) = (S.ncard:ℝ) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - have hs : Summable (fun w : RawCorridor G k => if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) := by - apply summable_of_hasFiniteSupport - apply (finite_corridors_on_bases G hloc k S hS).subset - intro w hw - by_contra hn - exact hw (ite_eq_right hn) - rw [hs.tsum_sigma] - have he (x : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, - if (RawCorridor.base ⟨x,w⟩) ∈ S then (RawCorridor.probability (walkKernel G hloc a) ⟨x,w⟩) else 0) = - if x ∈ S then 1 else 0 := by - by_cases hx : x ∈ S - · simp only [RawCorridor.base,RawCorridor.probability,hx,ite_true,rawFrom_probability_sum G hloc a k x] - · simp only [RawCorridor.base,hx,ite_false,tsum_zero] - simp only [he] - rw [tsum_eq_sum (s := hS.toFinset)] - · rw [Finset.sum_congr rfl (fun x hx => ite_eq_left (hS.mem_toFinset.mp hx))] - simp only [Finset.sum_const,nsmul_eq_mul,mul_one] - rw [←Set.ncard_eq_toFinset_card _ hS] - · intro x hx - exact ite_eq_right (fun h => hx (hS.mem_toFinset.mpr h)) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem base_mem_reachBall_of_retained (w : RawCorridor G k) (e : E) - (he : e ∈ w.retained) (z : V) (hz : z ∈ G e) : w.base ∈ reachBall G z k := by - have hs : z ∈ w.path.support := SimpleGraph.Walk.mem_support_of_mem_edges he hz - let q := (w.path.takeUntil z hs).reverse - have hq : q.length ≤ k := by - change (w.path.takeUntil z hs).reverse.length ≤ k - rw [SimpleGraph.Walk.length_reverse] - exact (w.path.length_takeUntil_le_length hs).trans w.path_length - have hh := walk_mem_reachBall G Set.univ (x := z) q 0 (by simp only [reachBall,Set.mem_singleton_iff]) - simp only [Nat.zero_add] at hh - exact reachBall_mono_local G z hq hh - -theorem counted_base_mem_cluster (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) - (hc : w.counted D ω x y) : w.base ∈ cluster G ω x := by - obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 - have hm := w.counted_base_mem_walk D ω x y hc q - exact conn_mono G Set.inter_subset_left ((conn_iff_reachable G _ x w.base).mpr ⟨q.takeUntil w.base hm⟩) - -end RawCorridor -end RawWalkFiniteBases -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformRawWeight -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def rawWeightBase (r q : ℝ) (d : ℕ) : ℝ := r⁻¹ * (q⁻¹)^d - -theorem rawWeightBase_one_le {r q : ℝ} (hr : 0 < r) (hr₁ : r ≤ 1) - (hq : 0 < q) (hq₁ : q ≤ 1) (d : ℕ) : 1 ≤ rawWeightBase r q d := by - exact one_le_mul_of_one_le_of_one_le ((one_le_inv₀ hr).mpr hr₁) - (one_le_pow₀ ((one_le_inv₀ hq).mpr hq₁)) - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem weight_le_uniform (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) - (w : RawCorridor G k) : w.weight P p ≤ w.probability P * (rawWeightBase r q d)^k := by - have hp₀ : 0 < (p:ℝ) := hr.trans_le hrp - have hp₁ : 0 < 1-(p:ℝ) := hq.trans_le hqp - have hr₁ : r ≤ 1 := hrp.trans p.2.2 - have hq₁ : q ≤ 1 := hqp.trans (sub_le_self _ p.2.1) - have hi : (p:ℝ)⁻¹ ≤ r⁻¹ := inv_anti₀ hr hrp - have hj : (1-(p:ℝ))⁻¹ ≤ q⁻¹ := inv_anti₀ hq hqp - have hL : ((p:ℝ)^w.path.length)⁻¹ ≤ (r⁻¹)^k := by - simp only [←inv_pow] - exact (pow_le_pow_left₀ (inv_nonneg.mpr p.2.1) hi _).trans - (pow_le_pow_right₀ ((one_le_inv₀ hr).mpr hr₁) w.path_length) - have hB : ((1-(p:ℝ))^w.blockers.ncard)⁻¹ ≤ ((q⁻¹)^d)^k := by - simp only [←inv_pow,←pow_mul] - exact (pow_le_pow_left₀ (inv_nonneg.mpr hp₁.le) hj _).trans - (pow_le_pow_right₀ ((one_le_inv₀ hq).mpr hq₁) (w.blockers_ncard_le hloc d hd)) - unfold weight - calc - _ = w.probability P * (((p:ℝ)^w.path.length)⁻¹ * ((1-(p:ℝ))^w.blockers.ncard)⁻¹) := mul_assoc _ _ _ - _ ≤ w.probability P * ((r⁻¹)^k * ((q⁻¹)^d)^k) := - mul_le_mul_of_nonneg_left (mul_le_mul hL hB - (inv_nonneg.mpr (pow_nonneg hp₁.le _)) (pow_nonneg (inv_nonneg.mpr hr.le) _)) - (w.2.2.mass_nonneg P hP) - _ = _ := by rw [rawWeightBase,mul_pow] - -end RawCorridor -end UniformRawWeight -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformPenaltyDomination -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem summable_raw_selection (G : BondGraph V E) (hloc : LocallyFinite G) - (k : ℕ) (S : Set V) (hS : S.Finite) (Q : RawCorridor G k → Prop) - (hQ : ∀ w, Q w → w.base ∈ S) (f : RawCorridor G k → ℝ) : - Summable (fun w => if Q w then f w else 0) := by - apply summable_of_hasFiniteSupport - apply (finite_corridors_on_bases G hloc k S hS).subset - intro w hw - by_contra hn - exact hw (ite_eq_right (fun h => hn (hQ w h))) - -theorem mask_le_mask_mul {U W : Prop} [Decidable U] [Decidable W] (hUW : U → W) - {f g B : ℝ} (hg : 0 ≤ g) (hB : 0 ≤ B) (hfg : f ≤ g*B) : - (if U then f else 0) ≤ (if W then g else 0)*B := by - by_cases hU : U - · simp only [hU,hUW hU,ite_true]; exact hfg - · rw [ite_eq_right hU] - by_cases hW : W - · rw [ite_eq_left hW]; exact mul_nonneg hg hB - · rw [ite_eq_right hW,zero_mul] - -theorem raw_weight_sum_le_on_bases (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) - (k : ℕ) (S : Set V) (hS : S.Finite) (Q : RawCorridor G k → Prop) - (hQ : ∀ w, Q w → w.base ∈ S) : - (∑' w : RawCorridor G k, if Q w then w.weight (walkKernel G hloc a) p else 0) ≤ - (S.ncard:ℝ)*(rawWeightBase r q d)^k := by - have hf := summable_raw_selection G hloc k S hS Q hQ - (fun w => w.weight (walkKernel G hloc a) p) - have hg := summable_raw_selection G hloc k S hS (fun w => w.base ∈ S) - (fun _ h => h) (fun w => w.probability (walkKernel G hloc a)) - have hB : 0 ≤ (rawWeightBase r q d)^k := pow_nonneg - (zero_le_one.trans (rawWeightBase_one_le hr (hrp.trans p.2.2) hq (hqp.trans (sub_le_self _ p.2.1)) d)) _ - have hpoint (w : RawCorridor G k) : - (if Q w then w.weight (walkKernel G hloc a) p else 0) ≤ - (if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) * (rawWeightBase r q d)^k := - mask_le_mask_mul (hQ w) (w.2.2.mass_nonneg _ hP) hB - (w.weight_le_uniform hloc d hd (walkKernel G hloc a) hP p hr hq hrp hqp) - have hb := hf.tsum_le_tsum hpoint (hg.mul_right ((rawWeightBase r q d)^k)) - rw [tsum_mul_right,raw_probability_on_bases_sum G hloc a k S hS] at hb - exact hb - - - -theorem corridorPenalty_le_cluster (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) - (k : ℕ) (D : Set V) (ω : Set E) (x y : V) (hf : (cluster G ω x).Finite) : - corridorPenalty G (walkKernel G hloc a) p k D ω x y ≤ - ((cluster G ω x).ncard:ℝ)*(rawWeightBase r q d)^k := by - exact raw_weight_sum_le_on_bases G hloc d hd a hP p hr hq hrp hqp k _ hf - (fun w => w.counted D ω x y) (fun w hw => w.counted_base_mem_cluster D ω x y hw) - - - -theorem raw_edge_weight_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) - (k : ℕ) (e : E) (z : V) (hz : z ∈ G e) : - (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ - (((d:ℝ)+1)*rawWeightBase r q d)^k := by - have hb := raw_weight_sum_le_on_bases G hloc d hd a hP p hr hq hrp hqp k - (reachBall G z k) (finite_reachBall hloc z k) (fun w => e ∈ w.retained) - (fun w hw => w.base_mem_reachBall_of_retained e hw z hz) - have hcard : ((reachBall G z k).ncard:ℝ) ≤ ((d:ℝ)+1)^k := by - exact_mod_cast reachBall_ncard_le_pow G hloc d hd z k - have hB : 0 ≤ (rawWeightBase r q d)^k := pow_nonneg - (zero_le_one.trans (rawWeightBase_one_le hr (hrp.trans p.2.2) hq (hqp.trans (sub_le_self _ p.2.1)) d)) _ - exact hb.trans ((mul_le_mul_of_nonneg_right hcard hB).trans_eq (mul_pow _ _ _).symm) - -end UniformPenaltyDomination -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExponentialCorridorCost -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem pow_le_exp_div_self {B : ℝ} (hB : 1 ≤ B) {k : ℕ} (hk : 0 < k) : - B^k ≤ Real.exp ((Real.log B + 1)*(k:ℝ))/(k:ℝ) := by - have hB₀ : 0 < B := zero_lt_one.trans_le hB - apply (le_div_iff₀ (Nat.cast_pos.mpr hk)).mpr - have hh : (k:ℝ) ≤ Real.exp (k:ℝ) := by linarith [Real.add_one_le_exp (k:ℝ)] - calc - _ ≤ B^k * Real.exp (k:ℝ) := mul_le_mul_of_nonneg_left hh (pow_nonneg hB₀.le _) - _ = Real.exp ((k:ℝ)*Real.log B) * Real.exp (k:ℝ) := by rw [Real.exp_nat_mul,Real.exp_log hB₀] - _ = _ := by rw [←Real.exp_add]; congr 1; ring - - - -theorem exists_uniform_corridor_edge_cost (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (k : ℕ), 3 ≤ k → ∀ e : E, - (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ - Real.exp (C*(k:ℝ))/(k:ℝ) := by - let B := ((d:ℝ)+1)*rawWeightBase ((pc G:ℝ)/2) (1-(pc G:ℝ)) d - have hB : 1 ≤ B := one_le_mul_of_one_le_of_one_le (by have := Nat.cast_nonneg (α := ℝ) d; linarith) - (rawWeightBase_one_le (half_pos hpcrit) (by have := (pc G).2.2; linarith) - (sub_pos.mpr hpcrit₁) (sub_le_self _ (pc G).2.1) d) - refine ⟨Real.log B + 1,by linarith [Real.log_nonneg hB],?_⟩ - intro p hpnear hp k hk e - obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by - obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) - exact ⟨z,z',hh.symm⟩ - have he : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' - have hq : 1-(pc G:ℝ) ≤ 1-(p:ℝ) := sub_le_sub_left (show (p:ℝ) ≤ (pc G:ℝ) from hp.le) (1:ℝ) - exact (raw_edge_weight_bound G hloc d hd a hP p (half_pos hpcrit) - (sub_pos.mpr hpcrit₁) hpnear hq k e z he).trans (pow_le_exp_div_self hB (by omega)) - -end ExponentialCorridorCost -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LiteralDeformationDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def deformedDerivativeMass (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : ℝ := - ∑' y, corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y - -theorem deformedConnection_eq_zero_of_not_conn (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) (hn : ¬Conn G ω x y) : - deformedConnection G P p k t D ω x y = 0 := by - have hnc : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hn (conn_mono G Set.inter_subset_left h) - simp only [deformedConnection,hnc,and_false,ite_false] - -theorem deformedClusterMass_eq_sum (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : deformedClusterMass G P p k t D ω x = - ∑ y ∈ hf.toFinset, deformedConnection G P p k t D ω x y := by - apply tsum_eq_sum - intro y hy - exact deformedConnection_eq_zero_of_not_conn G P p k t D ω x y (fun h => hy (hf.mem_toFinset.mpr h)) - -theorem deformedDerivativeMass_eq_sum (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : deformedDerivativeMass G P p k t D ω x = - ∑ y ∈ hf.toFinset, corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y := by - apply tsum_eq_sum - intro y hy - rw [deformedConnection_eq_zero_of_not_conn G P p k t D ω x y (fun h => hy (hf.mem_toFinset.mpr h)),mul_zero] - -theorem measurable_deformedDerivativeMass [Countable V] [Countable E] - (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : - Measurable (fun ω => deformedDerivativeMass G P p k t D ω x) := - Measurable.tsum (fun y => (measurable_corridorPenalty G P p k D x y).mul - (measurable_deformedConnection G P p k t D x y)) - -theorem deformedDerivativeMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) - (D : Set V) (ω : Set E) (x : V) : 0 ≤ deformedDerivativeMass G P p k t D ω x := - tsum_nonneg (fun y => mul_nonneg (corridorPenalty_nonneg G P hP p k D ω x y) - (deformedConnection_nonneg G P p k t D ω x y)) - -theorem hasDerivAt_deformedConnection (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : - HasDerivAt (fun s => deformedConnection G P p k s D ω x y) - (-(corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y)) t := by - by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y - · simp only [deformedConnection,hc,and_self,ite_true] - simpa only [Pi.neg_apply,id_eq,neg_mul,one_mul,mul_neg,mul_comm] using - (((hasDerivAt_id t).neg.mul_const (corridorPenalty G P p k D ω x y)).exp) - · simpa only [deformedConnection,hc,ite_false,mul_zero,neg_zero] using hasDerivAt_const t (0:ℝ) - - - -theorem hasDerivAt_deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) - (hf : (cluster G ω x).Finite) : - HasDerivAt (fun s => deformedClusterMass G P p k s D ω x) - (-deformedDerivativeMass G P p k t D ω x) t := by - have hh := HasDerivAt.fun_sum (u := hf.toFinset) (fun y _ => hasDerivAt_deformedConnection G P p k t D ω x y) - simpa only [deformedClusterMass_eq_sum G P p k _ D ω x hf, - deformedDerivativeMass_eq_sum G P p k t D ω x hf,Finset.sum_neg_distrib] using hh - -end LiteralDeformationDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DeformationDerivativeDomination -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedDerivativeMass_le_square (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ≤ - ((cluster G ω x).ncard:ℝ)^2 * (rawWeightBase p (1-(p:ℝ)) d)^k := by - rw [deformedDerivativeMass_eq_sum G (walkKernel G hloc a) p k t D ω x hf] - calc - _ ≤ ∑ _y ∈ hf.toFinset, ((cluster G ω x).ncard:ℝ)*(rawWeightBase p (1-(p:ℝ)) d)^k := by - apply Finset.sum_le_sum - intro y _ - have hn := corridorPenalty_nonneg G (walkKernel G hloc a) hP p k D ω x y - exact (mul_le_of_le_one_right hn (deformedConnection_le_one G (walkKernel G hloc a) hP p k t ht D ω x y)).trans - (corridorPenalty_le_cluster G hloc d hd a hP p hp0 (sub_pos.mpr hp1) le_rfl le_rfl k D ω x y hf) - _ = _ := by - simp only [Finset.sum_const,nsmul_eq_mul,←Set.ncard_eq_toFinset_card _ hf] - ring - -theorem integrable_deformedDerivativeMass [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (D : Set V) (x : V) : - Integrable (fun ω => deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x) (law p) := by - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - apply Integrable.mono' ((hs x).1.mul_const ((rawWeightBase p (1-(p:ℝ)) d)^k)) - (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).aestronglyMeasurable - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k t D ω x)] - exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 - ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2) k t ht D ω x hω - -end DeformationDerivativeDomination -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section DeformationDifferentiation -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem hasDerivAt_deformedSusceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 < t) - (D : Set V) (x : V) : - HasDerivAt (fun s => deformedSusceptibility G (walkKernel G hloc a) p k s D x) - (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ∂law p)) t := by - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - have hp1 : (p:ℝ) < 1 := (show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2 - have hder := hasDerivAt_integral_of_dominated_loc_of_deriv_le - (μ := law p) (s := Set.Ioi 0) (x₀ := t) - (F := fun s ω => deformedClusterMass G (walkKernel G hloc a) p k s D ω x) - (F' := fun s ω => -deformedDerivativeMass G (walkKernel G hloc a) p k s D ω x) - (bound := fun ω => ((cluster G ω x).ncard:ℝ)^2*(rawWeightBase p (1-(p:ℝ)) d)^k) - (Ioi_mem_nhds ht) - (Filter.Eventually.of_forall (fun s => (measurable_deformedClusterMass G (walkKernel G hloc a) p k s D x).aestronglyMeasurable)) - (integrable_deformedClusterMass G hloc hqt (walkKernel G hloc a) hP p hp k t ht.le D x) - (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).neg.aestronglyMeasurable - (by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - intro s hs - rw [norm_neg,Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k s D ω x)] - exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 hp1 k s hs.le D ω x hω) - ((hs x).1.mul_const _) - (by - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - intro s _ - exact hasDerivAt_deformedClusterMass G (walkKernel G hloc a) p k s D ω x hω) - rw [integral_neg] at hder - apply hder.2.congr_of_eventuallyEq - filter_upwards [Ioi_mem_nhds ht] with s hs - exact deformedSusceptibility_eq_integral G hloc hqt (walkKernel G hloc a) hP p hp k s hs.le D x - -end DeformationDifferentiation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section ContinuousDeformationDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem continuous_deformedConnection (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : - Continuous (fun s => deformedConnection G P p k s D ω x y) := - continuous_iff_continuousAt.mpr (fun t => (hasDerivAt_deformedConnection G P p k t D ω x y).continuousAt) - -theorem continuous_deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - Continuous (fun s => deformedClusterMass G P p k s D ω x) := - continuous_iff_continuousAt.mpr (fun t => (hasDerivAt_deformedClusterMass G P p k t D ω x hf).continuousAt) - -theorem continuous_deformedDerivativeMass (G : BondGraph V E) (P : V → V → ℝ) - (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : - Continuous (fun s => deformedDerivativeMass G P p k s D ω x) := by - simp_rw [deformedDerivativeMass_eq_sum G P p k _ D ω x hf] - exact continuous_finsetSum _ (fun y _ => continuous_const.mul (continuous_deformedConnection G P p k D ω x y)) - - - -theorem continuousOn_integral_deformedDerivativeMass [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (D : Set V) (x : V) : - ContinuousOn (fun t => ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ∂law p) (Set.Ici 0) := by - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - apply continuousOn_of_dominated - (bound := fun ω => ((cluster G ω x).ncard:ℝ)^2*(rawWeightBase p (1-(p:ℝ)) d)^k) - · intro t _ - exact (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).aestronglyMeasurable - · intro t ht - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k t D ω x)] - exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 - ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2) k t ht D ω x hω - · exact (hs x).1.mul_const _ - · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact (continuous_deformedDerivativeMass G (walkKernel G hloc a) p k D ω x hω).continuousOn - -end ContinuousDeformationDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Topology -section RightDeformationDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem continuousOn_deformedSusceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (D : Set V) (x : V) : - ContinuousOn (fun t => deformedSusceptibility G P p k t D x) (Set.Ici 0) := by - have hc : ContinuousOn (fun t => ∫ ω, deformedClusterMass G P p k t D ω x ∂law p) (Set.Ici 0) := by - apply continuousOn_of_dominated (bound := fun ω => ((cluster G ω x).ncard:ℝ)) - · intro t _ - exact (measurable_deformedClusterMass G P p k t D x).aestronglyMeasurable - · intro t ht - filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - rw [Real.norm_of_nonneg (deformedClusterMass_nonneg G P p k t D ω x)] - exact deformedClusterMass_le_ncard G P hP p k t ht D ω x hω - · exact (susceptibility_eq_integral G hloc hqt p hp x).1 - · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω - exact (continuous_deformedClusterMass G P p k D ω x hω).continuousOn - exact hc.congr (fun t ht => deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht D x) - - - -theorem hasDerivWithinAt_deformedSusceptibility_zero [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) - (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) - (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (D : Set V) (x : V) : - HasDerivWithinAt (fun t => deformedSusceptibility G (walkKernel G hloc a) p k t D x) - (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k 0 D ω x ∂law p)) (Set.Ici 0) 0 := by - apply hasDerivWithinAt_Ici_of_tendsto_deriv (s := Set.Ioi 0) - · intro t ht - exact (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht D x).differentiableAt.differentiableWithinAt - · exact (continuousOn_deformedSusceptibility G hloc hqt (walkKernel G hloc a) hP p hp k D x 0 (by simp)).mono Set.Ioi_subset_Ici_self - · exact self_mem_nhdsWithin - · have hc := (continuousOn_integral_deformedDerivativeMass G hloc hqt d hd a hP p hp0 hp k D x 0 (by simp)).neg - apply (hc.mono Set.Ioi_subset_Ici_self).congr' - filter_upwards [self_mem_nhdsWithin (s := Set.Ioi (0:ℝ)) (a := 0)] with t ht - exact (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht D x).deriv.symm - -end RightDeformationDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TerminalMoveGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - - - -theorem counted_move_terminal (w : RawCorridor G k) (D : Set V) (ω : Set E) - (F : Set E) (hF : F ⊆ ω ∩ internalEdges G D) (b z y : V) - (hbz : Conn G F b z) (hc : w.counted D ω b y) (hdis : Disjoint F w.retained) : - w.counted D ω z y := by - apply (w.counted_iff D ω z y).mpr - refine ⟨hc.1,conn_trans G _ (conn_symm G _ (conn_mono G hF hbz)) hc.2.2.1,?_,hc.2.2.2.2⟩ - intro e he - refine ⟨(hc.2.2.2.1 e he).1,?_⟩ - intro hzy - apply (hc.2.2.2.1 e he).2 - apply conn_trans G _ (conn_mono G ?_ hbz) hzy - intro f hf - refine ⟨hF hf,?_⟩ - intro hfe - have hh : f = e := Set.mem_singleton_iff.mp hfe - exact Set.disjoint_left.mp hdis hf (hh.symm ▸ he) - -end RawCorridor - - - -theorem corridorPenaltyTerm_move_bound (G : BondGraph V E) (P : V → V → ℝ) - (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (D : Set V) (ω : Set E) - (F : Finset E) (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) - (hbz : Conn G (F:Set E) b z) (w : RawCorridor G k) : - corridorPenaltyTerm G P p D ω b y w ≤ - (∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0) + corridorPenaltyTerm G P p D ω z y w := by - have hn := w.weight_nonneg P hP p - have hs : 0 ≤ ∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0 := - Finset.sum_nonneg (fun e _ => by split_ifs; exact hn; exact le_rfl) - by_cases hc : w.counted D ω b y - · rw [corridorPenaltyTerm,ite_eq_left hc] - by_cases hd : Disjoint (F:Set E) w.retained - · have hc' := w.counted_move_terminal D ω F hF b z y hbz hc hd - simpa only [corridorPenaltyTerm,hc',ite_true] using le_add_of_nonneg_left hs - · obtain ⟨e,he,hew⟩ := Set.not_disjoint_iff.mp hd - have he' : (if e ∈ w.retained then w.weight P p else 0) ≤ - ∑ f ∈ F, if f ∈ w.retained then w.weight P p else 0 := - Finset.single_le_sum (f := fun f => if f ∈ w.retained then w.weight P p else 0) (fun f _ => by split_ifs; exact hn; exact le_rfl) he - rw [ite_eq_left hew] at he' - exact he'.trans (le_add_of_nonneg_right (corridorPenaltyTerm_nonneg G P hP p D ω z y w)) - · rw [corridorPenaltyTerm,ite_eq_right hc] - exact add_nonneg hs (corridorPenaltyTerm_nonneg G P hP p D ω z y w) - -end TerminalMoveGeometry -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TerminalMovePenalty -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem summable_raw_edge_weights (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (p : ℝ) (k : ℕ) (e : E) : - Summable (fun w : RawCorridor G k => if e ∈ w.retained then w.weight P p else 0) := by - obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by - obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) - exact ⟨z,z',hh.symm⟩ - have he : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' - exact summable_raw_selection G hloc k (reachBall G z k) (finite_reachBall hloc z k) - (fun w => e ∈ w.retained) (fun w hw => w.base_mem_reachBall_of_retained e hw z he) - (fun w => w.weight P p) - - - -theorem corridorPenalty_move_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (D : Set V) (ω : Set E) (F : Finset E) - (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) (hbz : Conn G (F:Set E) b z) : - corridorPenalty G P p k D ω b y ≤ - (∑ e ∈ F, ∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) + - corridorPenalty G P p k D ω z y := by - have hs : Summable (fun w : RawCorridor G k => ∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0) := - (hasSum_sum (fun e (_ : e ∈ F) => (summable_raw_edge_weights G hloc P p k e).hasSum)).summable - have hr := corridorPenalty_summable G hloc P p k D ω z y - have hl := (corridorPenalty_summable G hloc P p k D ω b y).tsum_le_tsum - (corridorPenaltyTerm_move_bound G P hP p k D ω F hF b z y hbz) (hs.add hr) - rw [hs.tsum_add hr,Summable.tsum_finsetSum (fun e _ => summable_raw_edge_weights G hloc P p k e)] at hl - exact hl - -end TerminalMovePenalty -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteOpeningAssociation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_union_const (S : Set E) : Measurable (fun ω : Set E => ω ∪ S) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).or measurable_const - -theorem measurableSet_finite_open (F : Finset E) : MeasurableSet {ω : Set E | (F:Set E) ⊆ ω} := by - have he : {ω : Set E | (F:Set E) ⊆ ω} = ⋂ e ∈ F, {ω : Set E | e ∈ ω} := by - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_iInter,Finset.mem_coe,Set.subset_def] - rw [he] - exact F.measurableSet_biInter (fun e _ => measurableSet_setOfPred.mpr ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable)) - - - -theorem finite_open_integral_lower (p : unitInterval) (F : Finset E) (f : Set E → ℝ) - (hf : Measurable f) (hn : ∀ ω, 0 ≤ f ω) (hb : ∀ ω, f ω ≤ 1) - (hm : Monotone f) : - (p:ℝ)^F.card*(∫ ω, f ω ∂law p) ≤ ∫ ω, if (F:Set E) ⊆ ω then f ω else 0 ∂law p := by - let J : Set E → ℝ := fun ω => if (F:Set E) ⊆ ω then 1 else 0 - let g : Set E → ℝ := fun ω => f (ω ∪ (F:Set E)) - have hJ : Measurable J := Measurable.ite (measurableSet_finite_open F) measurable_const measurable_const - have hg : Measurable g := hf.comp (measurable_union_const (F:Set E)) - have hi (f : Set E → ℝ) (hfm : Measurable f) (hfn : ∀ ω, 0 ≤ f ω) (hfb : ∀ ω, f ω ≤ 1) : Integrable f (law p) := by - exact Integrable.mono' (integrable_const (1:ℝ)) hfm.aestronglyMeasurable - (Filter.Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (hfn ω)]; exact hfb ω)) - have hfi := hi f hf hn hb - have hgi := hi g hg (fun ω => hn _) (fun ω => hb _) - have hJint : (∫ ω, J ω ∂law p) = (p:ℝ)^F.card := by - have hh := integral_indicator_const (μ := law p) (1:ℝ) (measurableSet_finite_open F) - simpa only [Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_one,finite_open_probability,J] using hh - have he := integral_mul_disjoint_coordinates p (F:Set E) (F:Set E)ᶜ disjoint_compl_right J g hJ hg - (fun ω => by simp only [J,Set.subset_inter_iff,Set.Subset.refl,and_true]) - (fun ω => by - dsimp only [g] - congr 1 - ext e - simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] - tauto) - calc - _ ≤ (p:ℝ)^F.card*(∫ ω, g ω ∂law p) := mul_le_mul_of_nonneg_left - (integral_mono hfi hgi (fun ω => hm Set.subset_union_left)) (pow_nonneg p.2.1 _) - _ = (∫ ω, J ω ∂law p)*(∫ ω, g ω ∂law p) := by rw [hJint] - _ = ∫ ω, J ω*g ω ∂law p := he.symm - _ = _ := by - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - by_cases hF : (F:Set E) ⊆ ω - · simp only [J,g,hF,ite_true,one_mul,Set.union_eq_left.mpr hF] - · simp only [J,hF,ite_false,zero_mul]) - -end FiniteOpeningAssociation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TerminalConnectionComparison -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem corridorPenalty_move_edge_cost (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (D : Set V) (ω : Set E) (F : Finset E) - (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) (hbz : Conn G (F:Set E) b z) - (c : ℝ) (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : - corridorPenalty G P p k D ω b y ≤ (F.card:ℝ)*c+corridorPenalty G P p k D ω z y := by - apply (corridorPenalty_move_bound G hloc P hP p k D ω F hF b z y hbz).trans - apply add_le_add _ le_rfl - exact (Finset.sum_le_sum (fun e _ => hc e)).trans_eq (by simp only [Finset.sum_const,nsmul_eq_mul]) - - - -theorem deformedConnection_move_lower (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (ω : Set E) (F : Finset E) - (hF : (F:Set E) ⊆ internalEdges G D) (b z y : V) (hb : b ∈ D) - (hbz : Conn G (F:Set E) b z) (c : ℝ) - (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : - Real.exp (-t*((F.card:ℝ)*c)) * (if (F:Set E) ⊆ ω then deformedConnection G P p k t D ω z y else 0) ≤ - deformedConnection G P p k t D ω b y := by - by_cases ho : (F:Set E) ⊆ ω - · rw [ite_eq_left ho] - by_cases hz : z ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) z y - · have hFa : (F:Set E) ⊆ ω ∩ internalEdges G D := fun e he => ⟨ho he,hF he⟩ - have hb' : b ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) b y := - ⟨hb,hz.2.1,conn_trans G _ (conn_mono G hFa hbz) hz.2.2⟩ - simp only [deformedConnection,hz,hb',and_self,ite_true] - rw [←Real.exp_add] - apply Real.exp_le_exp.mpr - have hh := mul_le_mul_of_nonpos_left - (corridorPenalty_move_edge_cost G hloc P hP p k D ω F hFa b z y hbz c hc) (neg_nonpos.mpr ht) - simpa only [mul_add] using hh - · rw [deformedConnection,ite_eq_right hz,mul_zero] - exact deformedConnection_nonneg G P p k t D ω b y - · rw [ite_eq_right ho,mul_zero] - exact deformedConnection_nonneg G P p k t D ω b y - -end TerminalConnectionComparison -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section EndpointSusceptibilityComparison -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deformedKernel_move_lower [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (F : Finset E) - (hF : (F:Set E) ⊆ internalEdges G D) (b z y : V) (hb : b ∈ D) - (hbz : Conn G (F:Set E) b z) (c : ℝ) - (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : - Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card * deformedKernel G P p k t D z y ≤ - deformedKernel G P p k t D b y := by - have hi := integrable_deformedConnection G P hP p k t ht D z y - have hIi := hi.indicator (measurableSet_finite_open F) - have has := finite_open_integral_lower p F (fun ω => deformedConnection G P p k t D ω z y) - (measurable_deformedConnection G P p k t D z y) - (fun ω => deformedConnection_nonneg G P p k t D ω z y) - (fun ω => deformedConnection_le_one G P hP p k t ht D ω z y) - (fun _ _ hω => deformedConnection_mono G hloc P hP p k t ht (Set.Subset.refl _) hω z y) - have hb' := integral_mono (hIi.const_mul (Real.exp (-t*((F.card:ℝ)*c)))) - (integrable_deformedConnection G P hP p k t ht D b y) - (fun ω => deformedConnection_move_lower G hloc P hP p k t ht D ω F hF b z y hb hbz c hc) - simp only [Set.indicator,Set.mem_ofPred_eq,integral_const_mul] at hb' - have hh := mul_le_mul_of_nonneg_left has (Real.exp_pos (-t*((F.card:ℝ)*c))).le - simp only [mul_assoc] at hh ⊢ - exact hh.trans hb' - - -theorem deformedSusceptibility_move_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) - (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (F : Finset E) - (hF : (F:Set E) ⊆ internalEdges G D) (b z : V) (hb : b ∈ D) - (hbz : Conn G (F:Set E) b z) (c : ℝ) - (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : - Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card * deformedSusceptibility G P p k t D z ≤ - deformedSusceptibility G P p k t D b := by - simpa only [deformedSusceptibility,tsum_mul_left] using - ((summable_deformedKernel G hloc hqt P hP p hp k t ht D z).mul_left - (Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card)).tsum_le_tsum - (fun y => deformedKernel_move_lower G hloc P hP p k t ht D F hF b z y hb hbz c hc) - (summable_deformedKernel G hloc hqt P hP p hp k t ht D b) - -end EndpointSusceptibilityComparison -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.ClusterProducts + +namespace OAI + +/-! Derivatives for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedNeighborhoodEstimate +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem twoPoint_neighbor_div_bound [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (hp : 0 < (p:ℝ)) (v a z : V) (hz : z ∈ neighbors G hloc a) : + twoPoint G p v z ≤ twoPoint G p v a / (p:ℝ) := by + obtain ⟨e,he⟩ := (mem_neighbors G hloc a z).mp hz + have hh := restrictedTwoPoint_adj_lower G Set.univ p a z v e he (Set.mem_univ _) + simp only [Set.inter_univ] at hh + change (p:ℝ)*twoPoint G p z v ≤ twoPoint G p a v at hh + rw [twoPoint_symm G p z v,twoPoint_symm G p a v] at hh + exact (le_div_iff₀ hp).mpr (by simpa only [mul_comm] using hh) + + + +theorem neighborhood_twoPoint_bound [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) (p : unitInterval) (hp : 0 < (p:ℝ)) + (W : Finset V) (v : V) : + (∑' z : closedBondNeighborhood G (W:Set V), twoPoint G p v z) ≤ + (1+(d:ℝ)/(p:ℝ)) * (∑ a ∈ W, twoPoint G p v a) := by + apply (neighborhood_mass_le G hloc W (twoPoint G p v) (twoPoint_nonneg G p v)).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro a _ + have hsum : (∑ z ∈ neighbors G hloc a, twoPoint G p v z) ≤ + (d:ℝ)*(twoPoint G p v a/(p:ℝ)) := by + calc + _ ≤ ∑ _z ∈ neighbors G hloc a, twoPoint G p v a/(p:ℝ) := + Finset.sum_le_sum (fun z hz => twoPoint_neighbor_div_bound G hloc p hp v a z hz) + _ = ((neighbors G hloc a).card:ℝ)*(twoPoint G p v a/(p:ℝ)) := by simp only [Finset.sum_const,nsmul_eq_mul] + _ ≤ _ := mul_le_mul_of_nonneg_right (Nat.cast_le.mpr (hd a)) (div_nonneg (twoPoint_nonneg G p _ _) hp.le) + calc + _ ≤ twoPoint G p v a + (d:ℝ)*(twoPoint G p v a/(p:ℝ)) := add_le_add (le_refl _) hsum + _ = _ := by ring + +end WeightedNeighborhoodEstimate +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SizeWeightedPotential +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def sizeMembership (G : BondGraph V E) (x a : V) (ω : Set E) : ℝ := + if Conn G ω x a then ((cluster G ω x).ncard:ℝ) else 0 + +noncomputable def sizeWeightedConnectionPotential (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) : ℝ := ∑' a, sizeMembership G x a ω * twoPoint G p y a + +theorem sizeMembership_nonneg (G : BondGraph V E) (x a : V) (ω : Set E) : + 0 ≤ sizeMembership G x a ω := by + unfold sizeMembership + split_ifs + · exact Nat.cast_nonneg _ + · rfl + +theorem sizeMembership_le (G : BondGraph V E) (x a : V) (ω : Set E) : + sizeMembership G x a ω ≤ ((cluster G ω x).ncard:ℝ) := by + unfold sizeMembership + split_ifs + · rfl + · exact Nat.cast_nonneg _ + +theorem measurable_sizeMembership [Countable V] [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (x a : V) : Measurable (sizeMembership G x a) := by + apply Measurable.ite (measurableSet_conn G x a) + ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x)) measurable_const + +theorem integrable_sizeMembership [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x a : V) : Integrable (sizeMembership G x a) (law p) := by + apply Integrable.mono' (susceptibility_eq_integral G hloc hqt p hp x).1 + (measurable_sizeMembership G hloc x a).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun ω => by + rw [Real.norm_of_nonneg (sizeMembership_nonneg G x a ω)] + exact sizeMembership_le G x a ω) + +theorem integral_sizeMembership_le_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x a : V) : + (∫ ω, sizeMembership G x a ω ∂law p) ≤ susceptibility G p x := by + rw [(susceptibility_eq_integral G hloc hqt p hp x).2] + exact integral_mono (integrable_sizeMembership G hloc hqt p hp x a) + (susceptibility_eq_integral G hloc hqt p hp x).1 (sizeMembership_le G x a) + +theorem sizeWeightedConnectionPotential_eq_finite (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) (hf : (cluster G ω x).Finite) : + sizeWeightedConnectionPotential G p x y ω = + ((cluster G ω x).ncard:ℝ) * ∑ a ∈ hf.toFinset, twoPoint G p y a := by + unfold sizeWeightedConnectionPotential + rw [tsum_eq_sum (s := hf.toFinset)] + · rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + have hc : Conn G ω x a := hf.mem_toFinset.mp ha + simp only [sizeMembership,ite_eq_left hc] + · intro a ha + have hn : ¬Conn G ω x a := fun hc => ha (hf.mem_toFinset.mpr hc) + simp only [sizeMembership,ite_eq_right hn,zero_mul] + +end SizeWeightedPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SizePotentialIntegral +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +theorem summable_sizePotential_integral_norm (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : + Summable (fun a => ∫ ω, ‖sizeMembership G x a ω * twoPoint G p y a‖ ∂law p) := by + apply ((summable_twoPoint_subcritical G hloc hqt p hp y).mul_left (susceptibility G p x)).of_nonneg_of_le + · exact fun a => integral_nonneg (fun _ => norm_nonneg _) + · intro a + simp only [Real.norm_of_nonneg (mul_nonneg (sizeMembership_nonneg G x a _) (twoPoint_nonneg G p y a)), + integral_mul_const] + exact mul_le_mul_of_nonneg_right (integral_sizeMembership_le_susceptibility G hloc hqt p hp x a) + (twoPoint_nonneg G p y a) + +theorem integrable_sizeWeightedConnectionPotential (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (sizeWeightedConnectionPotential G p x y) (law p) := by + apply Integrable.mono' ((susceptibility_eq_integral G hloc hqt p hp x).1.mul_const + (susceptibility G p y)) + (Measurable.tsum (fun a => (measurable_sizeMembership G hloc x a).mul_const (twoPoint G p y a))).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun ω => by + have hb (a : V) : sizeMembership G x a ω * twoPoint G p y a ≤ + ((cluster G ω x).ncard:ℝ)*twoPoint G p y a := + mul_le_mul_of_nonneg_right (sizeMembership_le G x a ω) (twoPoint_nonneg G p y a) + have hn (a : V) : 0 ≤ sizeMembership G x a ω * twoPoint G p y a := + mul_nonneg (sizeMembership_nonneg G x a ω) (twoPoint_nonneg G p y a) + have hs := (summable_twoPoint_subcritical G hloc hqt p hp y).mul_left ((cluster G ω x).ncard:ℝ) + change ‖∑' a, sizeMembership G x a ω * twoPoint G p y a‖ ≤ _ + rw [Real.norm_of_nonneg (tsum_nonneg hn)] + exact ((hs.of_nonneg_of_le hn hb).tsum_le_tsum hb hs).trans_eq (tsum_mul_left)) + +omit [Countable V] [Countable E] [Nonempty V] in +theorem sizeWeightedConnectionPotential_nonneg (G : BondGraph V E) (p : unitInterval) + (x y : V) (ω : Set E) : 0 ≤ sizeWeightedConnectionPotential G p x y ω := + tsum_nonneg (fun a => mul_nonneg (sizeMembership_nonneg G x a ω) (twoPoint_nonneg G p y a)) + +theorem summable_twoPoint_cube_pair (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : + Summable (fun ba : V×V => twoPoint G p x ba.1 * twoPoint G p ba.1 ba.2 * twoPoint G p y ba.2) := by + exact (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le + (fun ba => mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) + (twoPoint_nonneg G p _ _)) + (fun ba => mul_le_of_le_one_right + (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_le_one G p _ _)) + + +theorem integral_sizeWeightedConnectionPotential_le (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : p < pc G) (x y : V) : + (∫ ω, sizeWeightedConnectionPotential G p x y ω ∂law p) ≤ + maxSusceptibility G p * (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) := by + have hi (a : V) := (integrable_sizeMembership G hloc hqt p hp x a).mul_const (twoPoint G p y a) + have hs := summable_sizePotential_integral_norm G hloc hqt p hp x y + have hc : Summable (fun a => ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) := + (summable_twoPoint_cube_pair G hloc hqt p hp x y).prod_symm.prod + change (∫ ω, ∑' a, sizeMembership G x a ω * twoPoint G p y a ∂law p) ≤ _ + rw [←integral_tsum_of_summable_integral_norm hi hs,←tsum_mul_left] + have hs' : Summable (fun a => ∫ ω, sizeMembership G x a ω * twoPoint G p y a ∂law p) := by + simpa only [Real.norm_of_nonneg (mul_nonneg (sizeMembership_nonneg G x _ _) (twoPoint_nonneg G p y _))] using hs + apply hs'.tsum_le_tsum (fun a => ?_) (hc.mul_left _) + rw [integral_mul_const,tsum_mul_right] + calc + _ ≤ (maxSusceptibility G p * (∑' b, twoPoint G p x b * twoPoint G p b a)) * twoPoint G p y a := + mul_le_mul_of_nonneg_right (integral_size_membership_le G hloc hqt p hp x a) (twoPoint_nonneg G p y a) + _ = _ := mul_assoc _ _ _ + +end SizePotentialIntegral +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedCorrelationPointwise +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem deformedFreshExteriorMoment_lower (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (hp : p < pc G) (hp₀ : 0 < (p:ℝ)) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (x y : V) (ω : Set E) (hf : (cluster G ω x).Finite) : + deformedClusterMass G P p k t D ω x * deformedSusceptibility G P p k t D y - + (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p * sizeWeightedConnectionPotential G p x y ω ≤ + deformedFreshExteriorMoment G P p k t D x y ω := by + let A := cluster G (ω ∩ internalEdges G D) x + have hsub : A ⊆ cluster G ω x := fun _ h => conn_mono G Set.inter_subset_left h + have hA : A.Finite := hf.subset hsub + have hn : (∑' z : closedBondNeighborhood G A, twoPoint G p y z) ≤ + (1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a) := by + have hh := neighborhood_twoPoint_bound G hloc d hd p hp₀ hA.toFinset y + rw [hA.coe_toFinset] at hh + exact hh.trans (mul_le_mul_of_nonneg_left + (Finset.sum_le_sum_of_subset_of_nonneg + (fun a ha => hf.mem_toFinset.mpr (hsub (hA.mem_toFinset.mp ha))) + (fun a _ _ => twoPoint_nonneg G p y a)) + (add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le))) + have hm := deformedClusterMass_le_ncard G P hP p k t ht D ω x hf + have hm₀ := deformedClusterMass_nonneg G P p k t D ω x + have hχ : 0 ≤ maxSusceptibility G p := zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp) + have hh := mul_le_mul_of_nonneg_left + (deformedSusceptibility_deletion G hloc hqt P hP p hp k t ht D A y) hm₀ + have hsum : 0 ≤ ∑ a ∈ hf.toFinset, twoPoint G p y a := + Finset.sum_nonneg (fun a _ => twoPoint_nonneg G p y a) + have hC : 0 ≤ 1+(d:ℝ)/(p:ℝ) := add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le) + have herr : deformedClusterMass G P p k t D ω x * + (maxSusceptibility G p * (∑' z : closedBondNeighborhood G A, twoPoint G p y z)) ≤ + (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p * sizeWeightedConnectionPotential G p x y ω := by + calc + _ ≤ deformedClusterMass G P p k t D ω x * + (maxSusceptibility G p * ((1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a))) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hn hχ) hm₀ + _ ≤ ((cluster G ω x).ncard:ℝ)* + (maxSusceptibility G p * ((1+(d:ℝ)/(p:ℝ))*(∑ a ∈ hf.toFinset, twoPoint G p y a))) := + mul_le_mul_of_nonneg_right hm (mul_nonneg hχ (mul_nonneg hC hsum)) + _ = _ := by rw [sizeWeightedConnectionPotential_eq_finite G p x y ω hf]; ring + dsimp only [deformedFreshExteriorMoment] + dsimp only [A] at hh + nlinarith + +end WeightedCorrelationPointwise +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedCorrelationIntegral +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem deformed_distinct_correlation (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (hp : p < pc G) (hp₀ : 0 < (p:ℝ)) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (x y : V) : + deformedSusceptibility G P p k t D x * deformedSusceptibility G P p k t D y - + (1+(d:ℝ)/(p:ℝ))*(maxSusceptibility G p)^2 * + (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) ≤ + ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by + rw [←integral_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y] + have hi := integrable_deformedClusterMass G hloc hqt P hP p hp k t ht D x + have hj := integrable_sizeWeightedConnectionPotential G hloc hqt p hp x y + have hb := integral_mono_ae + ((hi.mul_const (deformedSusceptibility G P p k t D y)).sub + (hj.const_mul ((1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p))) + (integrable_deformedFreshExteriorMoment G hloc hqt P hP p hp k t ht D x y) + (by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact deformedFreshExteriorMoment_lower G hloc hqt d hd P hP p hp hp₀ k t ht D x y ω hω) + simp only [Pi.sub_apply] at hb + rw [integral_sub (hi.mul_const _) (hj.const_mul _),integral_mul_const,integral_const_mul, + ←deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht D x] at hb + have hC : 0 ≤ (1+(d:ℝ)/(p:ℝ))*maxSusceptibility G p := + mul_nonneg (add_nonneg zero_le_one (div_nonneg (Nat.cast_nonneg _) hp₀.le)) + (zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp)) + have herr := mul_le_mul_of_nonneg_left + (integral_sizeWeightedConnectionPotential_le G hloc hqt p hp x y) hC + nlinarith + +end WeightedCorrelationIntegral +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExactCubeKernel +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem HasKernel.square_real_kernel (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : + (∑' b, twoPoint G p x b * twoPoint G p b y) = (matrixCoeff (T^2) x y).re := by + have hh := ((hT.positiveRealMatrix G p T).mul_hasSum T x y).tsum_eq + simpa only [hT.matrixCoeff_re G p T,pow_two] using hh + +theorem HasKernel.cube_real_kernel (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : + (∑' a, ∑' b, twoPoint G p x b * twoPoint G p b a * twoPoint G p y a) = + (matrixCoeff (T^3) x y).re := by + have hh := (((hT.positiveRealMatrix G p T).pow 2).mul_hasSum T x y).tsum_eq + calc + _ = ∑' a, (matrixCoeff (T^2) x a).re * (matrixCoeff T a y).re := by + apply tsum_congr + intro a + rw [tsum_mul_right,hT.square_real_kernel G p T x a,hT.matrixCoeff_re G p T a y,twoPoint_symm G p y a] + _ = _ := by simpa only [show T^2*T = T^3 by rw [←pow_succ]] using hh + +end ExactCubeKernel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformWeightedCorrelation +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem deformed_distinct_correlation_uniform (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (d : ℕ) (hd : ∀ a, (neighbors G hloc a).card ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (hpcrit : 0 < (pc G:ℝ)) + (p : unitInterval) (hp : p < pc G) (hpnear : (pc G:ℝ)/2 ≤ (p:ℝ)) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (x y : V) : + deformedSusceptibility G P p k t D x * deformedSusceptibility G P p k t D y - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * (matrixCoeff (T^3) x y).re ≤ + ∫ ω, (if ¬Conn G (ω ∩ internalEdges G D) x y then + deformedClusterMass G P p k t D ω x * deformedClusterMass G P p k t D ω y else 0) ∂law p := by + have hp₀ : 0 < (p:ℝ) := (half_pos hpcrit).trans_le hpnear + have hb := deformed_distinct_correlation G hloc hqt d hd P hP p hp hp₀ k t ht D x y + rw [hT.cube_real_kernel G p T x y] at hb + have hc : (d:ℝ)/(p:ℝ) ≤ 2*(d:ℝ)/(pc G:ℝ) := by + apply (div_le_div_iff₀ hp₀ hpcrit).mpr + nlinarith [Nat.cast_nonneg (α := ℝ) d] + have he := mul_le_mul_of_nonneg_right (add_le_add (le_refl (1:ℝ)) hc) + (mul_nonneg (sq_nonneg (maxSusceptibility G p)) (((hT.positiveRealMatrix G p T).pow 3) x y).2) + nlinarith + +end UniformWeightedCorrelation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorSizeBounds +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem incidentSupport_card_le (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (W : Finset V) : + (incidentSupport G hloc W).card ≤ W.card*d := by + apply Finset.card_biUnion_le_card_mul + intro x _ + rw [←Set.ncard_eq_toFinset_card _ (hloc x)] + exact (incident_ncard_le_degree G hloc x).trans (hd x) + +theorem reachBall_ncard_le_pow (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (x : V) (k : ℕ) : + (reachBall G x k).ncard ≤ (d+1)^k := by + induction k with + | zero => simp only [reachBall,Set.ncard_singleton,pow_zero,le_refl] + | succ k ih => + let W := (finite_reachBall hloc x k).toFinset + have he : reachBall G x (k+1) = (W ∪ W.biUnion (neighbors G hloc) : Finset V) := by + ext z + simp only [reachBall,Set.mem_union,Set.mem_iUnion,Set.mem_ofPred_eq,Finset.mem_coe, + Finset.mem_union,Finset.mem_biUnion,mem_neighbors,Set.Finite.mem_toFinset,W,Adj,exists_prop] + rw [he,Set.ncard_coe_finset] + have hb : (W.biUnion (neighbors G hloc)).card ≤ W.card*d := + Finset.card_biUnion_le_card_mul _ _ _ (fun a _ => (neighbors_card_le_degree G hloc a).trans (hd a)) + have hi : W.card ≤ (d+1)^k := by simpa only [W,←Set.ncard_eq_toFinset_card] using ih + calc + _ ≤ W.card + (W.biUnion (neighbors G hloc)).card := Finset.card_union_le _ _ + _ ≤ W.card + W.card*d := Nat.add_le_add_left hb _ + _ = W.card*(d+1) := by ring + _ ≤ (d+1)^k*(d+1) := Nat.mul_le_mul_right _ hi + _ = _ := (pow_succ _ _).symm + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem interior_card_le (w : RawCorridor G k) : w.interior.card ≤ w.path.length := by + have hs : w.interior ⊂ w.path.support.toFinset := by + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨Finset.sdiff_subset,?_⟩ + intro he + have hb : w.base ∈ w.path.support.toFinset := List.mem_toFinset.mpr w.path.start_mem_support + rw [←he] at hb + have hn : w.base ∉ w.interior := by simp only [interior,Finset.mem_sdiff,Finset.mem_insert, + true_or,not_true_eq_false,and_false,not_false_eq_true] + exact hn hb + have hh := Finset.card_lt_card hs + rw [List.toFinset_card_of_nodup w.path_isPath.support_nodup,SimpleGraph.Walk.length_support] at hh + omega + +theorem blockers_ncard_le (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) + (w : RawCorridor G k) : w.blockers.ncard ≤ d*k := by + have hs : w.blockers ⊆ (incidentSupport G hloc w.interior : Set E) := + fun e he => (mem_incidentSupport G hloc w.interior e).mpr he.1 + calc + _ ≤ (incidentSupport G hloc w.interior : Set E).ncard := Set.ncard_le_ncard hs (Finset.finite_toSet _) + _ = (incidentSupport G hloc w.interior).card := Set.ncard_coe_finset _ + _ ≤ w.interior.card*d := incidentSupport_card_le G hloc d hd _ + _ ≤ k*d := Nat.mul_le_mul_right _ (w.interior_card_le.trans w.path_length) + _ = _ := Nat.mul_comm _ _ + +end RawCorridor +end CorridorSizeBounds +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawWalkTotalMass +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem walkKernel_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (x : V) : (Function.support (walkKernel G hloc a x)).Finite := by + apply (Finset.finite_toSet (insert x (neighbors G hloc x))).subset + intro y hy + by_contra hn + have hn' : y ≠ x ∧ ¬Adj G x y := by simpa only [Finset.mem_coe,Finset.mem_insert,mem_neighbors,not_or] using hn + exact hy (by simp only [walkKernel,ite_eq_right hn'.1.symm,ite_eq_right hn'.2,add_zero]) + +theorem walkKernel_tsum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) (x : V) : + (∑' y, walkKernel G hloc a x y) = 1 := by + rw [tsum_eq_sum (s := insert x (neighbors G hloc x))] + · exact walkKernel_row_sum G hloc a x + · intro y hy + have hn : y ≠ x ∧ ¬Adj G x y := by simpa only [Finset.mem_insert,mem_neighbors,not_or] using hy + simp only [walkKernel,ite_eq_right hn.1.symm,ite_eq_right hn.2,add_zero] + +theorem raw_integral_one (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (k : ℕ) (x : V) : + RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) k x (fun _ => 1) = 1 := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + induction k generalizing x with + | zero => exact RawFrom.integral_zero _ _ _ + | succ k ih => + rw [RawFrom.integral_succ] + simp only [ih,mul_one] + have he := sum_step_decomposition (openSimpleGraph G Set.univ) (walkKernel G hloc a) + (walkKernel_finite_support G hloc a) (fun x y hxy hn => by + apply walkKernel_zero_of_not_step G hloc a x y hxy + intro h + obtain ⟨e,he⟩ := h + exact hn ⟨hxy,e,Set.mem_univ e,he⟩) x (fun _ => 1) + simpa only [mul_one,walkKernel_tsum G hloc a] using he.symm + + +theorem rawFrom_probability_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (k : ℕ) (x : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, w.2.mass (walkKernel G hloc a)) = 1 := by + simpa only [RawFrom.integral,mul_one] using raw_integral_one G hloc a k x + +end RawWalkTotalMass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawWalkFiniteBases +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem raw_probability_on_bases_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (k : ℕ) (S : Set V) (hS : S.Finite) : + (∑' w : RawCorridor G k, if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) = (S.ncard:ℝ) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + have hs : Summable (fun w : RawCorridor G k => if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) := by + apply summable_of_hasFiniteSupport + apply (finite_corridors_on_bases G hloc k S hS).subset + intro w hw + by_contra hn + exact hw (ite_eq_right hn) + rw [hs.tsum_sigma] + have he (x : V) : (∑' w : RawFrom (openSimpleGraph G Set.univ) k x, + if (RawCorridor.base ⟨x,w⟩) ∈ S then (RawCorridor.probability (walkKernel G hloc a) ⟨x,w⟩) else 0) = + if x ∈ S then 1 else 0 := by + by_cases hx : x ∈ S + · simp only [RawCorridor.base,RawCorridor.probability,hx,ite_true,rawFrom_probability_sum G hloc a k x] + · simp only [RawCorridor.base,hx,ite_false,tsum_zero] + simp only [he] + rw [tsum_eq_sum (s := hS.toFinset)] + · rw [Finset.sum_congr rfl (fun x hx => ite_eq_left (hS.mem_toFinset.mp hx))] + simp only [Finset.sum_const,nsmul_eq_mul,mul_one] + rw [←Set.ncard_eq_toFinset_card _ hS] + · intro x hx + exact ite_eq_right (fun h => hx (hS.mem_toFinset.mpr h)) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem base_mem_reachBall_of_retained (w : RawCorridor G k) (e : E) + (he : e ∈ w.retained) (z : V) (hz : z ∈ G e) : w.base ∈ reachBall G z k := by + have hs : z ∈ w.path.support := SimpleGraph.Walk.mem_support_of_mem_edges he hz + let q := (w.path.takeUntil z hs).reverse + have hq : q.length ≤ k := by + change (w.path.takeUntil z hs).reverse.length ≤ k + rw [SimpleGraph.Walk.length_reverse] + exact (w.path.length_takeUntil_le_length hs).trans w.path_length + have hh := walk_mem_reachBall G Set.univ (x := z) q 0 (by simp only [reachBall,Set.mem_singleton_iff]) + simp only [Nat.zero_add] at hh + exact reachBall_mono_local G z hq hh + +theorem counted_base_mem_cluster (w : RawCorridor G k) (D : Set V) (ω : Set E) (x y : V) + (hc : w.counted D ω x y) : w.base ∈ cluster G ω x := by + obtain ⟨q⟩ := (conn_iff_reachable G _ x y).mp hc.2.2.1 + have hm := w.counted_base_mem_walk D ω x y hc q + exact conn_mono G Set.inter_subset_left ((conn_iff_reachable G _ x w.base).mpr ⟨q.takeUntil w.base hm⟩) + +end RawCorridor +end RawWalkFiniteBases +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformRawWeight +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def rawWeightBase (r q : ℝ) (d : ℕ) : ℝ := r⁻¹ * (q⁻¹)^d + +theorem rawWeightBase_one_le {r q : ℝ} (hr : 0 < r) (hr₁ : r ≤ 1) + (hq : 0 < q) (hq₁ : q ≤ 1) (d : ℕ) : 1 ≤ rawWeightBase r q d := by + exact one_le_mul_of_one_le_of_one_le ((one_le_inv₀ hr).mpr hr₁) + (one_le_pow₀ ((one_le_inv₀ hq).mpr hq₁)) + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem weight_le_uniform (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ x, degree G x ≤ d) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) + (w : RawCorridor G k) : w.weight P p ≤ w.probability P * (rawWeightBase r q d)^k := by + have hp₀ : 0 < (p:ℝ) := hr.trans_le hrp + have hp₁ : 0 < 1-(p:ℝ) := hq.trans_le hqp + have hr₁ : r ≤ 1 := hrp.trans p.2.2 + have hq₁ : q ≤ 1 := hqp.trans (sub_le_self _ p.2.1) + have hi : (p:ℝ)⁻¹ ≤ r⁻¹ := inv_anti₀ hr hrp + have hj : (1-(p:ℝ))⁻¹ ≤ q⁻¹ := inv_anti₀ hq hqp + have hL : ((p:ℝ)^w.path.length)⁻¹ ≤ (r⁻¹)^k := by + simp only [←inv_pow] + exact (pow_le_pow_left₀ (inv_nonneg.mpr p.2.1) hi _).trans + (pow_le_pow_right₀ ((one_le_inv₀ hr).mpr hr₁) w.path_length) + have hB : ((1-(p:ℝ))^w.blockers.ncard)⁻¹ ≤ ((q⁻¹)^d)^k := by + simp only [←inv_pow,←pow_mul] + exact (pow_le_pow_left₀ (inv_nonneg.mpr hp₁.le) hj _).trans + (pow_le_pow_right₀ ((one_le_inv₀ hq).mpr hq₁) (w.blockers_ncard_le hloc d hd)) + unfold weight + calc + _ = w.probability P * (((p:ℝ)^w.path.length)⁻¹ * ((1-(p:ℝ))^w.blockers.ncard)⁻¹) := mul_assoc _ _ _ + _ ≤ w.probability P * ((r⁻¹)^k * ((q⁻¹)^d)^k) := + mul_le_mul_of_nonneg_left (mul_le_mul hL hB + (inv_nonneg.mpr (pow_nonneg hp₁.le _)) (pow_nonneg (inv_nonneg.mpr hr.le) _)) + (w.2.2.mass_nonneg P hP) + _ = _ := by rw [rawWeightBase,mul_pow] + +end RawCorridor +end UniformRawWeight +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformPenaltyDomination +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem summable_raw_selection (G : BondGraph V E) (hloc : LocallyFinite G) + (k : ℕ) (S : Set V) (hS : S.Finite) (Q : RawCorridor G k → Prop) + (hQ : ∀ w, Q w → w.base ∈ S) (f : RawCorridor G k → ℝ) : + Summable (fun w => if Q w then f w else 0) := by + apply summable_of_hasFiniteSupport + apply (finite_corridors_on_bases G hloc k S hS).subset + intro w hw + by_contra hn + exact hw (ite_eq_right (fun h => hn (hQ w h))) + +theorem mask_le_mask_mul {U W : Prop} [Decidable U] [Decidable W] (hUW : U → W) + {f g B : ℝ} (hg : 0 ≤ g) (hB : 0 ≤ B) (hfg : f ≤ g*B) : + (if U then f else 0) ≤ (if W then g else 0)*B := by + by_cases hU : U + · simp only [hU,hUW hU,ite_true]; exact hfg + · rw [ite_eq_right hU] + by_cases hW : W + · rw [ite_eq_left hW]; exact mul_nonneg hg hB + · rw [ite_eq_right hW,zero_mul] + +theorem raw_weight_sum_le_on_bases (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) + (k : ℕ) (S : Set V) (hS : S.Finite) (Q : RawCorridor G k → Prop) + (hQ : ∀ w, Q w → w.base ∈ S) : + (∑' w : RawCorridor G k, if Q w then w.weight (walkKernel G hloc a) p else 0) ≤ + (S.ncard:ℝ)*(rawWeightBase r q d)^k := by + have hf := summable_raw_selection G hloc k S hS Q hQ + (fun w => w.weight (walkKernel G hloc a) p) + have hg := summable_raw_selection G hloc k S hS (fun w => w.base ∈ S) + (fun _ h => h) (fun w => w.probability (walkKernel G hloc a)) + have hB : 0 ≤ (rawWeightBase r q d)^k := pow_nonneg + (zero_le_one.trans (rawWeightBase_one_le hr (hrp.trans p.2.2) hq (hqp.trans (sub_le_self _ p.2.1)) d)) _ + have hpoint (w : RawCorridor G k) : + (if Q w then w.weight (walkKernel G hloc a) p else 0) ≤ + (if w.base ∈ S then w.probability (walkKernel G hloc a) else 0) * (rawWeightBase r q d)^k := + mask_le_mask_mul (hQ w) (w.2.2.mass_nonneg _ hP) hB + (w.weight_le_uniform hloc d hd (walkKernel G hloc a) hP p hr hq hrp hqp) + have hb := hf.tsum_le_tsum hpoint (hg.mul_right ((rawWeightBase r q d)^k)) + rw [tsum_mul_right,raw_probability_on_bases_sum G hloc a k S hS] at hb + exact hb + + + +theorem corridorPenalty_le_cluster (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) + (k : ℕ) (D : Set V) (ω : Set E) (x y : V) (hf : (cluster G ω x).Finite) : + corridorPenalty G (walkKernel G hloc a) p k D ω x y ≤ + ((cluster G ω x).ncard:ℝ)*(rawWeightBase r q d)^k := by + exact raw_weight_sum_le_on_bases G hloc d hd a hP p hr hq hrp hqp k _ hf + (fun w => w.counted D ω x y) (fun w hw => w.counted_base_mem_cluster D ω x y hw) + + + +theorem raw_edge_weight_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + {r q : ℝ} (hr : 0 < r) (hq : 0 < q) (hrp : r ≤ (p:ℝ)) (hqp : q ≤ 1-(p:ℝ)) + (k : ℕ) (e : E) (z : V) (hz : z ∈ G e) : + (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ + (((d:ℝ)+1)*rawWeightBase r q d)^k := by + have hb := raw_weight_sum_le_on_bases G hloc d hd a hP p hr hq hrp hqp k + (reachBall G z k) (finite_reachBall hloc z k) (fun w => e ∈ w.retained) + (fun w hw => w.base_mem_reachBall_of_retained e hw z hz) + have hcard : ((reachBall G z k).ncard:ℝ) ≤ ((d:ℝ)+1)^k := by + exact_mod_cast reachBall_ncard_le_pow G hloc d hd z k + have hB : 0 ≤ (rawWeightBase r q d)^k := pow_nonneg + (zero_le_one.trans (rawWeightBase_one_le hr (hrp.trans p.2.2) hq (hqp.trans (sub_le_self _ p.2.1)) d)) _ + exact hb.trans ((mul_le_mul_of_nonneg_right hcard hB).trans_eq (mul_pow _ _ _).symm) + +end UniformPenaltyDomination +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExponentialCorridorCost +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem pow_le_exp_div_self {B : ℝ} (hB : 1 ≤ B) {k : ℕ} (hk : 0 < k) : + B^k ≤ Real.exp ((Real.log B + 1)*(k:ℝ))/(k:ℝ) := by + have hB₀ : 0 < B := zero_lt_one.trans_le hB + apply (le_div_iff₀ (Nat.cast_pos.mpr hk)).mpr + have hh : (k:ℝ) ≤ Real.exp (k:ℝ) := by linarith [Real.add_one_le_exp (k:ℝ)] + calc + _ ≤ B^k * Real.exp (k:ℝ) := mul_le_mul_of_nonneg_left hh (pow_nonneg hB₀.le _) + _ = Real.exp ((k:ℝ)*Real.log B) * Real.exp (k:ℝ) := by rw [Real.exp_nat_mul,Real.exp_log hB₀] + _ = _ := by rw [←Real.exp_add]; congr 1; ring + + + +theorem exists_uniform_corridor_edge_cost (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (k : ℕ), 3 ≤ k → ∀ e : E, + (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight (walkKernel G hloc a) p else 0) ≤ + Real.exp (C*(k:ℝ))/(k:ℝ) := by + let B := ((d:ℝ)+1)*rawWeightBase ((pc G:ℝ)/2) (1-(pc G:ℝ)) d + have hB : 1 ≤ B := one_le_mul_of_one_le_of_one_le (by have := Nat.cast_nonneg (α := ℝ) d; linarith) + (rawWeightBase_one_le (half_pos hpcrit) (by have := (pc G).2.2; linarith) + (sub_pos.mpr hpcrit₁) (sub_le_self _ (pc G).2.1) d) + refine ⟨Real.log B + 1,by linarith [Real.log_nonneg hB],?_⟩ + intro p hpnear hp k hk e + obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by + obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) + exact ⟨z,z',hh.symm⟩ + have he : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' + have hq : 1-(pc G:ℝ) ≤ 1-(p:ℝ) := sub_le_sub_left (show (p:ℝ) ≤ (pc G:ℝ) from hp.le) (1:ℝ) + exact (raw_edge_weight_bound G hloc d hd a hP p (half_pos hpcrit) + (sub_pos.mpr hpcrit₁) hpnear hq k e z he).trans (pow_le_exp_div_self hB (by omega)) + +end ExponentialCorridorCost +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LiteralDeformationDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def deformedDerivativeMass (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) : ℝ := + ∑' y, corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y + +theorem deformedConnection_eq_zero_of_not_conn (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) (hn : ¬Conn G ω x y) : + deformedConnection G P p k t D ω x y = 0 := by + have hnc : ¬Conn G (ω ∩ internalEdges G D) x y := fun h => hn (conn_mono G Set.inter_subset_left h) + simp only [deformedConnection,hnc,and_false,ite_false] + +theorem deformedClusterMass_eq_sum (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : deformedClusterMass G P p k t D ω x = + ∑ y ∈ hf.toFinset, deformedConnection G P p k t D ω x y := by + apply tsum_eq_sum + intro y hy + exact deformedConnection_eq_zero_of_not_conn G P p k t D ω x y (fun h => hy (hf.mem_toFinset.mpr h)) + +theorem deformedDerivativeMass_eq_sum (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : deformedDerivativeMass G P p k t D ω x = + ∑ y ∈ hf.toFinset, corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y := by + apply tsum_eq_sum + intro y hy + rw [deformedConnection_eq_zero_of_not_conn G P p k t D ω x y (fun h => hy (hf.mem_toFinset.mpr h)),mul_zero] + +theorem measurable_deformedDerivativeMass [Countable V] [Countable E] + (G : BondGraph V E) (P : V → V → ℝ) (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (x : V) : + Measurable (fun ω => deformedDerivativeMass G P p k t D ω x) := + Measurable.tsum (fun y => (measurable_corridorPenalty G P p k D x y).mul + (measurable_deformedConnection G P p k t D x y)) + +theorem deformedDerivativeMass_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) + (D : Set V) (ω : Set E) (x : V) : 0 ≤ deformedDerivativeMass G P p k t D ω x := + tsum_nonneg (fun y => mul_nonneg (corridorPenalty_nonneg G P hP p k D ω x y) + (deformedConnection_nonneg G P p k t D ω x y)) + +theorem hasDerivAt_deformedConnection (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x y : V) : + HasDerivAt (fun s => deformedConnection G P p k s D ω x y) + (-(corridorPenalty G P p k D ω x y * deformedConnection G P p k t D ω x y)) t := by + by_cases hc : x ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) x y + · simp only [deformedConnection,hc,and_self,ite_true] + simpa only [Pi.neg_apply,id_eq,neg_mul,one_mul,mul_neg,mul_comm] using + (((hasDerivAt_id t).neg.mul_const (corridorPenalty G P p k D ω x y)).exp) + · simpa only [deformedConnection,hc,ite_false,mul_zero,neg_zero] using hasDerivAt_const t (0:ℝ) + + + +theorem hasDerivAt_deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (t : ℝ) (D : Set V) (ω : Set E) (x : V) + (hf : (cluster G ω x).Finite) : + HasDerivAt (fun s => deformedClusterMass G P p k s D ω x) + (-deformedDerivativeMass G P p k t D ω x) t := by + have hh := HasDerivAt.fun_sum (u := hf.toFinset) (fun y _ => hasDerivAt_deformedConnection G P p k t D ω x y) + simpa only [deformedClusterMass_eq_sum G P p k _ D ω x hf, + deformedDerivativeMass_eq_sum G P p k t D ω x hf,Finset.sum_neg_distrib] using hh + +end LiteralDeformationDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DeformationDerivativeDomination +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedDerivativeMass_le_square (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ≤ + ((cluster G ω x).ncard:ℝ)^2 * (rawWeightBase p (1-(p:ℝ)) d)^k := by + rw [deformedDerivativeMass_eq_sum G (walkKernel G hloc a) p k t D ω x hf] + calc + _ ≤ ∑ _y ∈ hf.toFinset, ((cluster G ω x).ncard:ℝ)*(rawWeightBase p (1-(p:ℝ)) d)^k := by + apply Finset.sum_le_sum + intro y _ + have hn := corridorPenalty_nonneg G (walkKernel G hloc a) hP p k D ω x y + exact (mul_le_of_le_one_right hn (deformedConnection_le_one G (walkKernel G hloc a) hP p k t ht D ω x y)).trans + (corridorPenalty_le_cluster G hloc d hd a hP p hp0 (sub_pos.mpr hp1) le_rfl le_rfl k D ω x y hf) + _ = _ := by + simp only [Finset.sum_const,nsmul_eq_mul,←Set.ncard_eq_toFinset_card _ hf] + ring + +theorem integrable_deformedDerivativeMass [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (D : Set V) (x : V) : + Integrable (fun ω => deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x) (law p) := by + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + apply Integrable.mono' ((hs x).1.mul_const ((rawWeightBase p (1-(p:ℝ)) d)^k)) + (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).aestronglyMeasurable + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k t D ω x)] + exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 + ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2) k t ht D ω x hω + +end DeformationDerivativeDomination +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section DeformationDifferentiation +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem hasDerivAt_deformedSusceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 < t) + (D : Set V) (x : V) : + HasDerivAt (fun s => deformedSusceptibility G (walkKernel G hloc a) p k s D x) + (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ∂law p)) t := by + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + have hp1 : (p:ℝ) < 1 := (show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2 + have hder := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := law p) (s := Set.Ioi 0) (x₀ := t) + (F := fun s ω => deformedClusterMass G (walkKernel G hloc a) p k s D ω x) + (F' := fun s ω => -deformedDerivativeMass G (walkKernel G hloc a) p k s D ω x) + (bound := fun ω => ((cluster G ω x).ncard:ℝ)^2*(rawWeightBase p (1-(p:ℝ)) d)^k) + (Ioi_mem_nhds ht) + (Filter.Eventually.of_forall (fun s => (measurable_deformedClusterMass G (walkKernel G hloc a) p k s D x).aestronglyMeasurable)) + (integrable_deformedClusterMass G hloc hqt (walkKernel G hloc a) hP p hp k t ht.le D x) + (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).neg.aestronglyMeasurable + (by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + intro s hs + rw [norm_neg,Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k s D ω x)] + exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 hp1 k s hs.le D ω x hω) + ((hs x).1.mul_const _) + (by + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + intro s _ + exact hasDerivAt_deformedClusterMass G (walkKernel G hloc a) p k s D ω x hω) + rw [integral_neg] at hder + apply hder.2.congr_of_eventuallyEq + filter_upwards [Ioi_mem_nhds ht] with s hs + exact deformedSusceptibility_eq_integral G hloc hqt (walkKernel G hloc a) hP p hp k s hs.le D x + +end DeformationDifferentiation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section ContinuousDeformationDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem continuous_deformedConnection (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x y : V) : + Continuous (fun s => deformedConnection G P p k s D ω x y) := + continuous_iff_continuousAt.mpr (fun t => (hasDerivAt_deformedConnection G P p k t D ω x y).continuousAt) + +theorem continuous_deformedClusterMass (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + Continuous (fun s => deformedClusterMass G P p k s D ω x) := + continuous_iff_continuousAt.mpr (fun t => (hasDerivAt_deformedClusterMass G P p k t D ω x hf).continuousAt) + +theorem continuous_deformedDerivativeMass (G : BondGraph V E) (P : V → V → ℝ) + (p : ℝ) (k : ℕ) (D : Set V) (ω : Set E) (x : V) (hf : (cluster G ω x).Finite) : + Continuous (fun s => deformedDerivativeMass G P p k s D ω x) := by + simp_rw [deformedDerivativeMass_eq_sum G P p k _ D ω x hf] + exact continuous_finsetSum _ (fun y _ => continuous_const.mul (continuous_deformedConnection G P p k D ω x y)) + + + +theorem continuousOn_integral_deformedDerivativeMass [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (D : Set V) (x : V) : + ContinuousOn (fun t => ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t D ω x ∂law p) (Set.Ici 0) := by + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + apply continuousOn_of_dominated + (bound := fun ω => ((cluster G ω x).ncard:ℝ)^2*(rawWeightBase p (1-(p:ℝ)) d)^k) + · intro t _ + exact (measurable_deformedDerivativeMass G (walkKernel G hloc a) p k t D x).aestronglyMeasurable + · intro t ht + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [Real.norm_of_nonneg (deformedDerivativeMass_nonneg G (walkKernel G hloc a) hP p k t D ω x)] + exact deformedDerivativeMass_le_square G hloc d hd a hP p hp0 + ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2) k t ht D ω x hω + · exact (hs x).1.mul_const _ + · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact (continuous_deformedDerivativeMass G (walkKernel G hloc a) p k D ω x hω).continuousOn + +end ContinuousDeformationDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Topology +section RightDeformationDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem continuousOn_deformedSusceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (D : Set V) (x : V) : + ContinuousOn (fun t => deformedSusceptibility G P p k t D x) (Set.Ici 0) := by + have hc : ContinuousOn (fun t => ∫ ω, deformedClusterMass G P p k t D ω x ∂law p) (Set.Ici 0) := by + apply continuousOn_of_dominated (bound := fun ω => ((cluster G ω x).ncard:ℝ)) + · intro t _ + exact (measurable_deformedClusterMass G P p k t D x).aestronglyMeasurable + · intro t ht + filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + rw [Real.norm_of_nonneg (deformedClusterMass_nonneg G P p k t D ω x)] + exact deformedClusterMass_le_ncard G P hP p k t ht D ω x hω + · exact (susceptibility_eq_integral G hloc hqt p hp x).1 + · filter_upwards [subcritical_cluster_finite_ae G p hp x] with ω hω + exact (continuous_deformedClusterMass G P p k D ω x hω).continuousOn + exact hc.congr (fun t ht => deformedSusceptibility_eq_integral G hloc hqt P hP p hp k t ht D x) + + + +theorem hasDerivWithinAt_deformedSusceptibility_zero [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (a : ℝ) + (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) (p : unitInterval) + (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (k : ℕ) (D : Set V) (x : V) : + HasDerivWithinAt (fun t => deformedSusceptibility G (walkKernel G hloc a) p k t D x) + (-(∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k 0 D ω x ∂law p)) (Set.Ici 0) 0 := by + apply hasDerivWithinAt_Ici_of_tendsto_deriv (s := Set.Ioi 0) + · intro t ht + exact (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht D x).differentiableAt.differentiableWithinAt + · exact (continuousOn_deformedSusceptibility G hloc hqt (walkKernel G hloc a) hP p hp k D x 0 (by simp)).mono Set.Ioi_subset_Ici_self + · exact self_mem_nhdsWithin + · have hc := (continuousOn_integral_deformedDerivativeMass G hloc hqt d hd a hP p hp0 hp k D x 0 (by simp)).neg + apply (hc.mono Set.Ioi_subset_Ici_self).congr' + filter_upwards [self_mem_nhdsWithin (s := Set.Ioi (0:ℝ)) (a := 0)] with t ht + exact (hasDerivAt_deformedSusceptibility G hloc hqt d hd a hP p hp0 hp k t ht D x).deriv.symm + +end RightDeformationDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TerminalMoveGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + + + +theorem counted_move_terminal (w : RawCorridor G k) (D : Set V) (ω : Set E) + (F : Set E) (hF : F ⊆ ω ∩ internalEdges G D) (b z y : V) + (hbz : Conn G F b z) (hc : w.counted D ω b y) (hdis : Disjoint F w.retained) : + w.counted D ω z y := by + apply (w.counted_iff D ω z y).mpr + refine ⟨hc.1,conn_trans G _ (conn_symm G _ (conn_mono G hF hbz)) hc.2.2.1,?_,hc.2.2.2.2⟩ + intro e he + refine ⟨(hc.2.2.2.1 e he).1,?_⟩ + intro hzy + apply (hc.2.2.2.1 e he).2 + apply conn_trans G _ (conn_mono G ?_ hbz) hzy + intro f hf + refine ⟨hF hf,?_⟩ + intro hfe + have hh : f = e := Set.mem_singleton_iff.mp hfe + exact Set.disjoint_left.mp hdis hf (hh.symm ▸ he) + +end RawCorridor + + + +theorem corridorPenaltyTerm_move_bound (G : BondGraph V E) (P : V → V → ℝ) + (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (D : Set V) (ω : Set E) + (F : Finset E) (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) + (hbz : Conn G (F:Set E) b z) (w : RawCorridor G k) : + corridorPenaltyTerm G P p D ω b y w ≤ + (∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0) + corridorPenaltyTerm G P p D ω z y w := by + have hn := w.weight_nonneg P hP p + have hs : 0 ≤ ∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0 := + Finset.sum_nonneg (fun e _ => by split_ifs; exact hn; exact le_rfl) + by_cases hc : w.counted D ω b y + · rw [corridorPenaltyTerm,ite_eq_left hc] + by_cases hd : Disjoint (F:Set E) w.retained + · have hc' := w.counted_move_terminal D ω F hF b z y hbz hc hd + simpa only [corridorPenaltyTerm,hc',ite_true] using le_add_of_nonneg_left hs + · obtain ⟨e,he,hew⟩ := Set.not_disjoint_iff.mp hd + have he' : (if e ∈ w.retained then w.weight P p else 0) ≤ + ∑ f ∈ F, if f ∈ w.retained then w.weight P p else 0 := + Finset.single_le_sum (f := fun f => if f ∈ w.retained then w.weight P p else 0) (fun f _ => by split_ifs; exact hn; exact le_rfl) he + rw [ite_eq_left hew] at he' + exact he'.trans (le_add_of_nonneg_right (corridorPenaltyTerm_nonneg G P hP p D ω z y w)) + · rw [corridorPenaltyTerm,ite_eq_right hc] + exact add_nonneg hs (corridorPenaltyTerm_nonneg G P hP p D ω z y w) + +end TerminalMoveGeometry +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TerminalMovePenalty +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem summable_raw_edge_weights (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (p : ℝ) (k : ℕ) (e : E) : + Summable (fun w : RawCorridor G k => if e ∈ w.retained then w.weight P p else 0) := by + obtain ⟨z,z',hzz⟩ : ∃ z z', G e = s(z,z') := by + obtain ⟨⟨z,z'⟩,hh⟩ := Quot.exists_rep (G e) + exact ⟨z,z',hh.symm⟩ + have he : z ∈ G e := hzz.symm ▸ Sym2.mem_mk_left z z' + exact summable_raw_selection G hloc k (reachBall G z k) (finite_reachBall hloc z k) + (fun w => e ∈ w.retained) (fun w hw => w.base_mem_reachBall_of_retained e hw z he) + (fun w => w.weight P p) + + + +theorem corridorPenalty_move_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (D : Set V) (ω : Set E) (F : Finset E) + (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) (hbz : Conn G (F:Set E) b z) : + corridorPenalty G P p k D ω b y ≤ + (∑ e ∈ F, ∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) + + corridorPenalty G P p k D ω z y := by + have hs : Summable (fun w : RawCorridor G k => ∑ e ∈ F, if e ∈ w.retained then w.weight P p else 0) := + (hasSum_sum (fun e (_ : e ∈ F) => (summable_raw_edge_weights G hloc P p k e).hasSum)).summable + have hr := corridorPenalty_summable G hloc P p k D ω z y + have hl := (corridorPenalty_summable G hloc P p k D ω b y).tsum_le_tsum + (corridorPenaltyTerm_move_bound G P hP p k D ω F hF b z y hbz) (hs.add hr) + rw [hs.tsum_add hr,Summable.tsum_finsetSum (fun e _ => summable_raw_edge_weights G hloc P p k e)] at hl + exact hl + +end TerminalMovePenalty +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteOpeningAssociation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_union_const (S : Set E) : Measurable (fun ω : Set E => ω ∪ S) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).or measurable_const + +theorem measurableSet_finite_open (F : Finset E) : MeasurableSet {ω : Set E | (F:Set E) ⊆ ω} := by + have he : {ω : Set E | (F:Set E) ⊆ ω} = ⋂ e ∈ F, {ω : Set E | e ∈ ω} := by + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_iInter,Finset.mem_coe,Set.subset_def] + rw [he] + exact F.measurableSet_biInter (fun e _ => measurableSet_setOfPred.mpr ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable)) + + + +theorem finite_open_integral_lower (p : unitInterval) (F : Finset E) (f : Set E → ℝ) + (hf : Measurable f) (hn : ∀ ω, 0 ≤ f ω) (hb : ∀ ω, f ω ≤ 1) + (hm : Monotone f) : + (p:ℝ)^F.card*(∫ ω, f ω ∂law p) ≤ ∫ ω, if (F:Set E) ⊆ ω then f ω else 0 ∂law p := by + let J : Set E → ℝ := fun ω => if (F:Set E) ⊆ ω then 1 else 0 + let g : Set E → ℝ := fun ω => f (ω ∪ (F:Set E)) + have hJ : Measurable J := Measurable.ite (measurableSet_finite_open F) measurable_const measurable_const + have hg : Measurable g := hf.comp (measurable_union_const (F:Set E)) + have hi (f : Set E → ℝ) (hfm : Measurable f) (hfn : ∀ ω, 0 ≤ f ω) (hfb : ∀ ω, f ω ≤ 1) : Integrable f (law p) := by + exact Integrable.mono' (integrable_const (1:ℝ)) hfm.aestronglyMeasurable + (Filter.Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (hfn ω)]; exact hfb ω)) + have hfi := hi f hf hn hb + have hgi := hi g hg (fun ω => hn _) (fun ω => hb _) + have hJint : (∫ ω, J ω ∂law p) = (p:ℝ)^F.card := by + have hh := integral_indicator_const (μ := law p) (1:ℝ) (measurableSet_finite_open F) + simpa only [Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_one,finite_open_probability,J] using hh + have he := integral_mul_disjoint_coordinates p (F:Set E) (F:Set E)ᶜ disjoint_compl_right J g hJ hg + (fun ω => by simp only [J,Set.subset_inter_iff,Set.Subset.refl,and_true]) + (fun ω => by + dsimp only [g] + congr 1 + ext e + simp only [Set.mem_union,Set.mem_inter_iff,Set.mem_compl_iff] + tauto) + calc + _ ≤ (p:ℝ)^F.card*(∫ ω, g ω ∂law p) := mul_le_mul_of_nonneg_left + (integral_mono hfi hgi (fun ω => hm Set.subset_union_left)) (pow_nonneg p.2.1 _) + _ = (∫ ω, J ω ∂law p)*(∫ ω, g ω ∂law p) := by rw [hJint] + _ = ∫ ω, J ω*g ω ∂law p := he.symm + _ = _ := by + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + by_cases hF : (F:Set E) ⊆ ω + · simp only [J,g,hF,ite_true,one_mul,Set.union_eq_left.mpr hF] + · simp only [J,hF,ite_false,zero_mul]) + +end FiniteOpeningAssociation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TerminalConnectionComparison +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem corridorPenalty_move_edge_cost (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (D : Set V) (ω : Set E) (F : Finset E) + (hF : (F:Set E) ⊆ ω ∩ internalEdges G D) (b z y : V) (hbz : Conn G (F:Set E) b z) + (c : ℝ) (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : + corridorPenalty G P p k D ω b y ≤ (F.card:ℝ)*c+corridorPenalty G P p k D ω z y := by + apply (corridorPenalty_move_bound G hloc P hP p k D ω F hF b z y hbz).trans + apply add_le_add _ le_rfl + exact (Finset.sum_le_sum (fun e _ => hc e)).trans_eq (by simp only [Finset.sum_const,nsmul_eq_mul]) + + + +theorem deformedConnection_move_lower (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (ω : Set E) (F : Finset E) + (hF : (F:Set E) ⊆ internalEdges G D) (b z y : V) (hb : b ∈ D) + (hbz : Conn G (F:Set E) b z) (c : ℝ) + (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : + Real.exp (-t*((F.card:ℝ)*c)) * (if (F:Set E) ⊆ ω then deformedConnection G P p k t D ω z y else 0) ≤ + deformedConnection G P p k t D ω b y := by + by_cases ho : (F:Set E) ⊆ ω + · rw [ite_eq_left ho] + by_cases hz : z ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) z y + · have hFa : (F:Set E) ⊆ ω ∩ internalEdges G D := fun e he => ⟨ho he,hF he⟩ + have hb' : b ∈ D ∧ y ∈ D ∧ Conn G (ω ∩ internalEdges G D) b y := + ⟨hb,hz.2.1,conn_trans G _ (conn_mono G hFa hbz) hz.2.2⟩ + simp only [deformedConnection,hz,hb',and_self,ite_true] + rw [←Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonpos_left + (corridorPenalty_move_edge_cost G hloc P hP p k D ω F hFa b z y hbz c hc) (neg_nonpos.mpr ht) + simpa only [mul_add] using hh + · rw [deformedConnection,ite_eq_right hz,mul_zero] + exact deformedConnection_nonneg G P p k t D ω b y + · rw [ite_eq_right ho,mul_zero] + exact deformedConnection_nonneg G P p k t D ω b y + +end TerminalConnectionComparison +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section EndpointSusceptibilityComparison +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deformedKernel_move_lower [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (F : Finset E) + (hF : (F:Set E) ⊆ internalEdges G D) (b z y : V) (hb : b ∈ D) + (hbz : Conn G (F:Set E) b z) (c : ℝ) + (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : + Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card * deformedKernel G P p k t D z y ≤ + deformedKernel G P p k t D b y := by + have hi := integrable_deformedConnection G P hP p k t ht D z y + have hIi := hi.indicator (measurableSet_finite_open F) + have has := finite_open_integral_lower p F (fun ω => deformedConnection G P p k t D ω z y) + (measurable_deformedConnection G P p k t D z y) + (fun ω => deformedConnection_nonneg G P p k t D ω z y) + (fun ω => deformedConnection_le_one G P hP p k t ht D ω z y) + (fun _ _ hω => deformedConnection_mono G hloc P hP p k t ht (Set.Subset.refl _) hω z y) + have hb' := integral_mono (hIi.const_mul (Real.exp (-t*((F.card:ℝ)*c)))) + (integrable_deformedConnection G P hP p k t ht D b y) + (fun ω => deformedConnection_move_lower G hloc P hP p k t ht D ω F hF b z y hb hbz c hc) + simp only [Set.indicator,Set.mem_ofPred_eq,integral_const_mul] at hb' + have hh := mul_le_mul_of_nonneg_left has (Real.exp_pos (-t*((F.card:ℝ)*c))).le + simp only [mul_assoc] at hh ⊢ + exact hh.trans hb' + + +theorem deformedSusceptibility_move_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (hp : p < pc G) + (k : ℕ) (t : ℝ) (ht : 0 ≤ t) (D : Set V) (F : Finset E) + (hF : (F:Set E) ⊆ internalEdges G D) (b z : V) (hb : b ∈ D) + (hbz : Conn G (F:Set E) b z) (c : ℝ) + (hc : ∀ e, (∑' w : RawCorridor G k, if e ∈ w.retained then w.weight P p else 0) ≤ c) : + Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card * deformedSusceptibility G P p k t D z ≤ + deformedSusceptibility G P p k t D b := by + simpa only [deformedSusceptibility,tsum_mul_left] using + ((summable_deformedKernel G hloc hqt P hP p hp k t ht D z).mul_left + (Real.exp (-t*((F.card:ℝ)*c)) * (p:ℝ)^F.card)).tsum_le_tsum + (fun y => deformedKernel_move_lower G hloc P hP p k t ht D F hF b z y hb hbz c hc) + (summable_deformedKernel G hloc hqt P hP p hp k t ht D b) + +end EndpointSusceptibilityComparison +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Deformation/FiniteScale.lean b/lean/OAI/Probability/UnimodularPercolation/Deformation/FiniteScale.lean index 8ec4f8d4a02d423271df06a44e261bf3432b366a..1314fd60a28a734e94936275eb7ab745e4f28fe8 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Deformation/FiniteScale.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Deformation/FiniteScale.lean @@ -1,454 +1,454 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.PathSelection - -namespace OAI - -/-! Deformed susceptibility, finite-scale estimates and the Riccati contradiction. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section EscapeSusceptibility -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - -omit [Countable V] [Countable E] [Nonempty V] in - - -theorem deformed_move_of_walk (G : BondGraph V E) (hloc : LocallyFinite G) - (a C : ℝ) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (hmove : ∀ (D : Set V) (b z : V) (l : List E), - b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → - Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * - deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t D b) - (D : Set V) (b z : V) (q : (openSimpleGraph G Set.univ).Walk b z) - (j : ℕ) (hj : q.length ≤ j) (hD : ∀ x ∈ q.support, x ∈ D) : - Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^j * - deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t D b := by - obtain ⟨l,hl,he,_⟩ := walk_lift_bonds G Set.univ q - have hlen : l.length = q.length := by - have hh := congrArg List.length he - simpa only [List.length_map,SimpleGraph.Walk.length_edges] using hh - have hle : l.length ≤ j := hlen.trans_le hj - have hcomp := hmove D b z l (hD b q.start_mem_support) hl (by - intro e hel x hxe - exact hD x (SimpleGraph.Walk.mem_support_of_mem_edges - (he ▸ List.mem_map_of_mem hel) hxe)) - have he' : Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ)))) ≤ - Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) := by - apply Real.exp_le_exp.mpr - exact mul_le_mul_of_nonpos_left - (mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hle) (Real.exp_pos _).le) (neg_nonpos.mpr ht) - have hpw : (p:ℝ)^j ≤ (p:ℝ)^l.length := pow_le_pow_of_le_one p.2.1 p.2.2 hle - exact (mul_le_mul_of_nonneg_right (mul_le_mul he' hpw (pow_nonneg p.2.1 _) (Real.exp_pos _).le) - (deformedSusceptibility_nonneg G _ p k t D z)).trans hcomp - - -theorem deformedSusceptibility_delete_interior (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (w : RawCorridor G k) (x : V) : - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x - - maxSusceptibility G p * (∑ z ∈ w.neighborhood hloc, twoPoint G p x z) ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ x := by - have hh := deformedSusceptibility_deletion G hloc hqt _ hP p hp k t ht Set.univ (w.interior : Set V) x - rw [←w.coe_neighborhood hloc,Finset.tsum_subtype'] at hh - have he : Set.univ \ (w.interior : Set V) = (w.interior : Set V)ᶜ := by ext z; simp - rw [he] at hh - exact hh - - - -theorem selected_retained_product_lower (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (j : ℕ) (s C cf χ : ℝ) (hcf : 0 ≤ cf) (hχ : 0 ≤ χ) - (hrow : ∀ x, cf*χ ≤ deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x) - (hcost : maxSusceptibility G p*s ≤ (cf/2)*χ) - (hmove : ∀ (D : Set V) (b z : V) (l : List E), - b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → - Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * - deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t D b) - (w : RawCorridor G k) (hw : w.Selected hloc p j s) : - Real.exp (-2*t*(j:ℝ)*Real.exp (C*(k:ℝ))) * (p:ℝ)^(2*j) * ((cf/2)*χ)^2 ≤ - retainedSusceptibilityProduct G (walkKernel G hloc a) p t w := by - have hx (x : V) (he : w.HasEscape hloc p j s x) : - Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ))))*(p:ℝ)^j*((cf/2)*χ) ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ x := by - obtain ⟨z,q,_hq,hj,havoid,hs⟩ := he - have hd := deformedSusceptibility_delete_interior G hloc hqt a hP p hp k t ht w z - have hδ : (cf/2)*χ ≤ - deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ z := by - have hb := mul_le_mul_of_nonneg_left hs (zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp)) - have hr := hrow z - linarith - exact (mul_le_mul_of_nonneg_left hδ - (mul_nonneg (Real.exp_pos _).le (pow_nonneg p.2.1 _))).trans - (deformed_move_of_walk G hloc a C p k t ht hmove (w.interior : Set V)ᶜ x z q j hj havoid) - have h₁ := hx w.base hw.2.1 - have h₂ := hx w.endpoint hw.2.2 - have hfactor : 0 ≤ Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ))))*(p:ℝ)^j*((cf/2)*χ) := - mul_nonneg (mul_nonneg (Real.exp_pos _).le (pow_nonneg p.2.1 _)) - (mul_nonneg (div_nonneg hcf (by norm_num)) hχ) - have hh := mul_le_mul h₁ h₂ hfactor - (deformedSusceptibility_nonneg G _ p k t (w.interior : Set V)ᶜ w.base) - rw [retainedSusceptibilityProduct,ite_eq_left hw.1] - apply le_trans (le_of_eq ?_) hh - have he : -2*t*(j:ℝ)*Real.exp (C*(k:ℝ)) = - -t*((j:ℝ)*Real.exp (C*(k:ℝ))) + -t*((j:ℝ)*Real.exp (C*(k:ℝ))) := by ring - rw [he,Real.exp_add,show 2*j=j+j by omega,pow_add] - ring - -end EscapeSusceptibility -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AveragedRetention -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] - -omit [Countable V] [Countable E] [Nonempty V] in -theorem averagedDeformedSusceptibility_nonneg (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (t : ℝ) : - 0 ≤ averagedDeformedSusceptibility G P p k root weight t := - Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (deformedSusceptibility_nonneg G P p k t Set.univ (root i))) - -omit [Countable V] [Countable E] [Nonempty V] in -theorem deformedKernel_symm (G : BondGraph V E) (P : V → V → ℝ) - (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : - deformedKernel G P p k t D x y = deformedKernel G P p k t D y x := by - simp only [deformedKernel,deformedConnection_symm G P p k t D _ x y] - -omit [Nonempty V] in - - -theorem deformed_row_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (p : unitInterval) (k : ℕ) (t : ℝ) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (x : V) : - deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x ≤ - c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by - obtain ⟨i,g,⟨e,he⟩,rfl⟩ := hcov x - rw [deformedSusceptibility_aut G he _ (walkKernel_covariant G hloc a he)] - simp only [Set.preimage_univ] - have hs := deformedSusceptibility_nonneg G (walkKernel G hloc a) p k t Set.univ - have hi := Finset.single_le_sum - (s := Finset.univ) - (f := fun r => weight r * deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root r)) - (fun r _ => mul_nonneg (hw r) (hs (root r))) (Finset.mem_univ i) - have hi' := mul_le_mul_of_nonneg_left hi hc - have hh := mul_le_mul_of_nonneg_right (hmin i) (hs (root i)) - change _ ≤ c*∑ r, weight r * deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root r) - nlinarith - - - -theorem deformed_norm_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (B : Hilbert V →L[ℂ] Hilbert V) - (hB : ∀ x y, matrixCoeff B x y = (deformedKernel G (walkKernel G hloc a) p k t Set.univ x y : ℂ)) : - ‖B‖ ≤ c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by - have hs (x : V) (F : Finset V) : - (∑ y ∈ F, |deformedKernel G (walkKernel G hloc a) p k t Set.univ x y|) ≤ - c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by - simp only [abs_of_nonneg (deformedKernel_nonneg G _ p k t _ _ _)] - exact ((summable_deformedKernel G hloc hqt _ hP p hp k t ht Set.univ x).sum_le_tsum F - (fun y _ => deformedKernel_nonneg G _ p k t _ x y)).trans - (deformed_row_le_root_sum G hloc a p k t root weight hw hcov c hc hmin x) - exact operator_norm_le_absolute_sums _ _ - (mul_nonneg hc (averagedDeformedSusceptibility_nonneg G _ p k root weight hw t)) hs - (fun y F => by simpa only [deformedKernel_symm G _ p k t Set.univ] using hs y F) B hB - - - -theorem deformed_root_sum_retained (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (a : ℝ) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hA : HasKernel G p A) (k : ℕ) (t B : ℝ) (ht : 0 ≤ t) - (htB : t*‖A‖ ≤ B) (hB : B*‖P‖^k ≤ 1/4) : - ‖A‖/(2*c) ≤ averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - obtain ⟨T,hT,_,_,hret⟩ := exists_deformedOperator_small_change G hG hloc p hp0 - ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) a P hpos hPs hP - A (hA.positiveRealMatrix G p A) (hA.isPositive G p A).isSelfAdjoint hA k t ht - have hn := deformed_norm_le_root_sum G hloc hqt a hK p hp k t ht root weight hw hcov c hc.le hmin T hT - have hsmall := (mul_le_mul_of_nonneg_right htB (pow_nonneg (norm_nonneg P) k)).trans hB - have hh := mul_le_mul_of_nonneg_right hsmall (norm_nonneg A) - apply (div_le_iff₀ (by positivity : 0 < 2*c)).mpr - nlinarith - -end AveragedRetention -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AveragePositiveTerm -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] -variable {ι : Type*} [Fintype ι] - -omit [Countable V] [Countable E] [Nonempty V] in - -theorem selected_average_lower (G : BondGraph V E) (hloc : LocallyFinite G) - (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (j : ℕ) (s b F : ℝ) (hF : 0 ≤ F) - (hm : b ≤ rawPathAverage G P k root weight - (fun w => if w.Selected hloc p j s then 1 else 0)) - (hgood : ∀ w : RawCorridor G k, w.Selected hloc p j s → - F ≤ retainedSusceptibilityProduct G P p t w) : - F*b ≤ rawPathAverage G P k root weight (retainedSusceptibilityProduct G P p t) := by - have hh := rawPathAverage_mono G hloc P hP k root weight hw - (fun w => F*(if w.Selected hloc p j s then 1 else 0)) - (retainedSusceptibilityProduct G P p t) (by - intro w - by_cases hs : w.Selected hloc p j s - · simpa only [hs,ite_true,mul_one] using hgood w hs - · simp only [hs,ite_false,mul_zero,retainedSusceptibilityProduct] - split_ifs - · exact mul_nonneg (deformedSusceptibility_nonneg G P p k t _ w.base) - (deformedSusceptibility_nonneg G P p k t _ w.endpoint) - · exact le_rfl) - rw [rawPathAverage_const_mul] at hh - exact (mul_le_mul_of_nonneg_left hm hF).trans hh -end AveragePositiveTerm - -section RiccatiContradiction - - -theorem riccati_retention_bound (χ D : ℝ → ℝ) (T m c h : ℝ) - (hT : 0 < T) (hm : 0 < m) (hc : 0 < c) (_hh : 0 ≤ h) - (hret : ∀ t ∈ Set.Icc (T/2) T, m/(2*c) ≤ χ t) - (hder : ∀ t ∈ Set.Icc (T/2) T, HasDerivAt χ (-D t) t) - (hdec : ∀ t ∈ Set.Icc (T/2) T, h*(χ t)^2 ≤ D t) : - h*T*m ≤ 4*c := by - have hpos (t) (ht : t ∈ Set.Icc (T/2) T) : 0 < χ t := - (div_pos hm (by positivity)).trans_le (hret t ht) - have hd (t) (ht : t ∈ Set.Icc (T/2) T) : - HasDerivAt (fun s => (χ s)⁻¹) (D t/(χ t)^2) t := by - convert! (hder t ht).inv (hpos t ht).ne' using 1 - simp only [neg_neg] - have hcχ : ContinuousOn (fun s => (χ s)⁻¹) (Set.Icc (T/2) T) := - fun t ht => (hd t ht).continuousAt.continuousWithinAt - have hdiff : DifferentiableOn ℝ (fun s => (χ s)⁻¹) (interior (Set.Icc (T/2) T)) := - fun t ht => (hd t (interior_subset ht)).differentiableAt.differentiableWithinAt - have hdl (t) (ht : t ∈ interior (Set.Icc (T/2) T)) : - h ≤ deriv (fun s => (χ s)⁻¹) t := by - rw [(hd t (interior_subset ht)).deriv] - exact (le_div_iff₀ (sq_pos_of_pos (hpos t (interior_subset ht)))).mpr (hdec t (interior_subset ht)) - have hs := (convex_Icc (T/2) T).mul_sub_le_image_sub_of_le_deriv hcχ hdiff hdl - (T/2) ⟨le_rfl,by linarith⟩ T ⟨by linarith,le_rfl⟩ (by linarith) - have hstart : 0 ≤ (χ (T/2))⁻¹ := (inv_pos.mpr (hpos _ ⟨le_rfl,by linarith⟩)).le - have hend : (χ T)⁻¹ ≤ 2*c/m := by - have hb := one_div_le_one_div_of_le (div_pos hm (by positivity)) (hret T ⟨by linarith,le_rfl⟩) - simpa only [one_div,inv_div] using hb - have hs' : h*(T/2) ≤ 2*c/m := by linarith - have hs'' := (le_div_iff₀ hm).mp hs' - nlinarith -end RiccatiContradiction -end Percolation - - - - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteScale -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Infinite V] -variable {ι : Type*} [Fintype ι] - - - -theorem exists_finite_scale_obstruction - (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) - (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : - ∃ C : ℝ, 0 < C ∧ ∃ J : ℕ, 0 < J ∧ ∃ C₁ : ℝ, 0 < C₁ ∧ - ∃ k₀ : ℕ, 3 ≤ k₀ ∧ ∃ ε M : ℝ, 0 < ε ∧ 0 < M ∧ - ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (A : Hilbert V →L[ℂ] Hilbert V), HasKernel G p A → - ∀ k : ℕ, k₀ ≤ k → ∀ B : ℝ, 0 < B → - let R := maxSusceptibility G p/‖A‖ - let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ - B*‖P‖^k ≤ 1/4 → - B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ ‖A‖ → - R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k ≤ ε*((pc G:ℝ)/2)^(2*j) → - M < B*((pc G:ℝ)/2)^(2*j) → False := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hw₀ (i) := (hw i).le - obtain ⟨Cr,cf,hCr,hcf,hrow⟩ := exists_uniform_deformed_row_comparison G hconn hloc hqt - root weight hw₀ hw1 (fun x => by - obtain ⟨i,g,⟨e,he⟩,hx⟩ := hcov x - exact ⟨i,g,e,he,hx⟩) d hd a hK hpcrit hpcrit₁ - obtain ⟨Cm,hCm,hmove⟩ := exists_uniform_deformed_endpoint_comparison G hloc hqt d hd a hK hpcrit hpcrit₁ - obtain ⟨Cd,hCd,hdecrease⟩ := exists_uniform_averaged_decrease G hG hloc hqt - root weight hw₀ (vertexAut G) (Set.Subset.refl _) htr d hd a hK hpcrit hpcrit₁ P hpos hP hsym - let τ := cf/(8*c) - have hτ : 0 < τ := div_pos hcf (by positivity) - obtain ⟨J,C₁,k₀,b,hJ,hC₁,hk₀,hb,hselected⟩ := exists_selected_path_mass G hconn hloc hqt - a ha root weight htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag hρ d hd τ hτ - let C := Cr+Cm+Cd - let q := b*Real.exp (-2)*(cf/2)^2 - let H := (1+2*(d:ℝ)/(pc G:ℝ))*(2*c)^2 - let ε := q/(2*H) - let h₀ := Real.exp (-1)*q/2 - let M := 4*c/h₀ - have hq : 0 < q := by dsimp [q]; positivity - have hH : 0 < H := by dsimp [H]; positivity - have hε : 0 < ε := div_pos hq (by positivity) - have hh₀ : 0 < h₀ := by dsimp [h₀]; positivity - have hM : 0 < M := div_pos (by positivity) hh₀ - refine ⟨C,by dsimp [C]; positivity,J,hJ,C₁,hC₁,k₀,hk₀,ε,M,hε,hM,?_⟩ - intro p hpnear hp A hA k hk B hB - dsimp only - let m := ‖A‖ - let R := maxSusceptibility G p/m - let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ - let β := ((pc G:ℝ)/2)^(2*j) - let T := B/m - let χ := averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight - let D := fun t => ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p - change B*‖P‖^k ≤ 1/4 → B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m → - R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k ≤ ε*β → M < B*β → False - intro hsmall htime herrscale hlarge - have hm : 0 < m := zero_lt_one.trans_le (hA.norm_one_le G p A) - have hR : 1 ≤ R := (one_le_div hm).mpr (hA.norm_le_maxSusceptibility G hloc hqt p hp A) - have hβ : 0 < β := pow_pos (half_pos hpcrit) _ - have hj : 1 ≤ j := by dsimp [j]; omega - have hjr : (1:ℝ) ≤ (j:ℝ) := Nat.one_le_cast.mpr hj - have hk3 : 3 ≤ k := hk₀.trans hk - have hpzero : 0 < (p:ℝ) := (half_pos hpcrit).trans_le hpnear - have hT : 0 < T := div_pos hB hm - have hTb (t : ℝ) (ht : t ≤ T) : t*m ≤ B := (le_div_iff₀ hm).mp ht - have htim (t : ℝ) (ht : t ≤ T) : t*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ 1 := by - have hm' := mul_le_mul_of_nonneg_right (hTb t ht) - (mul_nonneg (Nat.cast_nonneg j) (Real.exp_pos (C*(k:ℝ))).le) - nlinarith only [hm',htime,hm] - have hCbound (C' : ℝ) (hC' : C' ≤ C) : Real.exp (C'*(k:ℝ)) ≤ Real.exp (C*(k:ℝ)) := - Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hC' (Nat.cast_nonneg k)) - have htim' (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) (C' : ℝ) (hC' : C' ≤ C) : - t*Real.exp (C'*(k:ℝ)) ≤ 1 := by - have he := mul_le_mul_of_nonneg_left (hCbound C' hC') ht - have hj' := mul_le_mul_of_nonneg_left hjr (mul_nonneg ht (Real.exp_pos (C*(k:ℝ))).le) - nlinarith only [he,hj',htim t htT] - have hret (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) : m/(2*c) ≤ χ t := - deformed_root_sum_retained G hG hloc hqt a p hpzero hp root weight hw₀ hcov c hc hmin - P A hpos hsym hP hA k t B ht (hTb t htT) hsmall - have hdec (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) : (h₀*β)*(χ t)^2 ≤ D t := by - have hχ : 0 ≤ χ t := averagedDeformedSusceptibility_nonneg G _ p k root weight hw₀ t - have hret' := (div_le_iff₀ (by positivity : 0 < 2*c)).mp (hret t ht htT) - have hrow' := hrow p hpnear hp k hk3 t ht (htim' t ht htT Cr (by dsimp [C]; linarith only [hCr,hCm,hCd])) - have hcost : maxSusceptibility G p*(τ/R) ≤ (cf/2)*χ t := by - have hmax : maxSusceptibility G p ≠ 0 := - (zero_lt_one.trans_le (maxSusceptibility_one_le G hloc hqt p hp)).ne' - have he : maxSusceptibility G p*(τ/R) = τ*m := by dsimp [R]; field_simp [hmax] - rw [he] - have hh := mul_le_mul_of_nonneg_left hret' hτ.le - have hτcf : τ*(2*c) = cf/4 := by dsimp [τ]; field_simp; ring - rw [mul_left_comm τ (χ t) (2*c),hτcf,mul_comm (χ t)] at hh - nlinarith only [hh,hcf,hχ] - have hprod (w : RawCorridor G k) (hwsel : w.Selected hloc p j (τ/R)) : - Real.exp (-2)*β*((cf/2)*χ t)^2 ≤ retainedSusceptibilityProduct G (walkKernel G hloc a) p t w := by - have hbnd := selected_retained_product_lower G hloc hqt a hK p hp k t ht j (τ/R) Cm cf (χ t) - hcf.le hχ hrow' hcost (hmove p hpnear hp k hk3 t ht) w hwsel - have he : Real.exp (-2) ≤ Real.exp (-2*t*(j:ℝ)*Real.exp (Cm*(k:ℝ))) := by - apply Real.exp_le_exp.mpr - have he' := mul_le_mul_of_nonneg_left (hCbound Cm (by dsimp [C]; linarith only [hCr,hCm,hCd])) - (mul_nonneg ht (Nat.cast_nonneg j)) - linarith only [he',htim t htT] - have hpw : β ≤ (p:ℝ)^(2*j) := pow_le_pow_left₀ (half_pos hpcrit).le hpnear _ - exact (mul_le_mul_of_nonneg_right - (mul_le_mul he hpw hβ.le (Real.exp_pos _).le) (sq_nonneg _)).trans hbnd - have hsel := hselected p hpnear hp k hk R hR - have hpositive := selected_average_lower G hloc _ hK p k t root weight hw₀ j (τ/R) b - (Real.exp (-2)*β*((cf/2)*χ t)^2) (by positivity) hsel hprod - have hpositive' : q*β*(χ t)^2 ≤ rawPathAverage G (walkKernel G hloc a) k root weight - (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) := by - convert hpositive using 1 - dsimp [q] - ring - have ha₃ : 0 ≤ rootTriangle G root weight (p:ℝ) := - zero_le_one.trans (rootTriangle_one_le G hloc hqt root weight hw₀ hw1 p hp) - have herror : (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * - (‖P‖^k*(rootTrace root weight (A^3)).re) ≤ (q/2)*β*(χ t)^2 := by - rw [←rootTriangle_eq_trace G p root weight A hA] - have hx : maxSusceptibility G p = R*m := by dsimp [R]; field_simp - rw [hx] - have hcoeff : 0 ≤ (1+2*(d:ℝ)/(pc G:ℝ)) := by positivity - have hm2 : m^2 ≤ (2*c)^2*(χ t)^2 := by - calc - m^2 ≤ (χ t*(2*c))^2 := pow_le_pow_left₀ hm.le hret' 2 - _ = _ := by ring - have h₁ := mul_le_mul_of_nonneg_left hm2 - (mul_nonneg (mul_nonneg hcoeff (sq_nonneg R)) (mul_nonneg ha₃ (pow_nonneg (norm_nonneg P) k))) - have h₂ := mul_le_mul_of_nonneg_left herrscale (mul_nonneg hH.le (sq_nonneg (χ t))) - have he : H*ε = q/2 := by dsimp [ε]; field_simp - calc - _ ≤ H*(R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k)*(χ t)^2 := by dsimp [H]; nlinarith only [h₁] - _ ≤ H*(ε*β)*(χ t)^2 := by nlinarith only [h₂] - _ = _ := by rw [←mul_assoc H ε β,he] - have hdiff : (q/2)*β*(χ t)^2 ≤ - rawPathAverage G (walkKernel G hloc a) k root weight - (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - - (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * - (‖P‖^k*(rootTrace root weight (A^3)).re) := by linarith only [hpositive',herror] - have hexp : Real.exp (-1) ≤ Real.exp (-t*Real.exp (Cd*(k:ℝ))) := - Real.exp_le_exp.mpr (by linarith only [htim' t ht htT Cd (by dsimp [C]; linarith only [hCr,hCm]) ]) - have hh := mul_le_mul hexp hdiff (by positivity) (Real.exp_pos _).le - have hdecr := hdecrease p hpnear hp A hA k hk3 t ht - apply le_trans _ hdecr - convert hh using 1 - dsimp [h₀] - ring - have hb := riccati_retention_bound χ D T m c (h₀*β) hT hm hc (mul_pos hh₀ hβ).le - (fun t ht => hret t (by linarith only [ht.1,hT]) ht.2) - (fun t ht => hasDerivAt_averagedDeformedSusceptibility G hloc hqt root weight d hd a hK p hpzero hp k t - (by linarith only [ht.1,hT])) - (fun t ht => hdec t (by linarith only [ht.1,hT]) ht.2) - have he : h₀*β*T*m = h₀*(B*β) := by dsimp [T]; field_simp - rw [he] at hb - have hg := (div_lt_iff₀ hh₀).mp hlarge - nlinarith only [hg,hb] - -end FiniteScale -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.PathSelection + +namespace OAI + +/-! Deformed susceptibility, finite-scale estimates and the Riccati contradiction. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section EscapeSusceptibility +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + +omit [Countable V] [Countable E] [Nonempty V] in + + +theorem deformed_move_of_walk (G : BondGraph V E) (hloc : LocallyFinite G) + (a C : ℝ) (p : unitInterval) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (hmove : ∀ (D : Set V) (b z : V) (l : List E), + b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → + Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * + deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t D b) + (D : Set V) (b z : V) (q : (openSimpleGraph G Set.univ).Walk b z) + (j : ℕ) (hj : q.length ≤ j) (hD : ∀ x ∈ q.support, x ∈ D) : + Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^j * + deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t D b := by + obtain ⟨l,hl,he,_⟩ := walk_lift_bonds G Set.univ q + have hlen : l.length = q.length := by + have hh := congrArg List.length he + simpa only [List.length_map,SimpleGraph.Walk.length_edges] using hh + have hle : l.length ≤ j := hlen.trans_le hj + have hcomp := hmove D b z l (hD b q.start_mem_support) hl (by + intro e hel x hxe + exact hD x (SimpleGraph.Walk.mem_support_of_mem_edges + (he ▸ List.mem_map_of_mem hel) hxe)) + have he' : Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ)))) ≤ + Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) := by + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left + (mul_le_mul_of_nonneg_right (Nat.cast_le.mpr hle) (Real.exp_pos _).le) (neg_nonpos.mpr ht) + have hpw : (p:ℝ)^j ≤ (p:ℝ)^l.length := pow_le_pow_of_le_one p.2.1 p.2.2 hle + exact (mul_le_mul_of_nonneg_right (mul_le_mul he' hpw (pow_nonneg p.2.1 _) (Real.exp_pos _).le) + (deformedSusceptibility_nonneg G _ p k t D z)).trans hcomp + + +theorem deformedSusceptibility_delete_interior (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (w : RawCorridor G k) (x : V) : + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x - + maxSusceptibility G p * (∑ z ∈ w.neighborhood hloc, twoPoint G p x z) ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ x := by + have hh := deformedSusceptibility_deletion G hloc hqt _ hP p hp k t ht Set.univ (w.interior : Set V) x + rw [←w.coe_neighborhood hloc,Finset.tsum_subtype'] at hh + have he : Set.univ \ (w.interior : Set V) = (w.interior : Set V)ᶜ := by ext z; simp + rw [he] at hh + exact hh + + + +theorem selected_retained_product_lower (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (j : ℕ) (s C cf χ : ℝ) (hcf : 0 ≤ cf) (hχ : 0 ≤ χ) + (hrow : ∀ x, cf*χ ≤ deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x) + (hcost : maxSusceptibility G p*s ≤ (cf/2)*χ) + (hmove : ∀ (D : Set V) (b z : V) (l : List E), + b ∈ D → Along G b l z → (∀ e ∈ l, e ∈ internalEdges G D) → + Real.exp (-t*((l.length:ℝ)*Real.exp (C*(k:ℝ)))) * (p:ℝ)^l.length * + deformedSusceptibility G (walkKernel G hloc a) p k t D z ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t D b) + (w : RawCorridor G k) (hw : w.Selected hloc p j s) : + Real.exp (-2*t*(j:ℝ)*Real.exp (C*(k:ℝ))) * (p:ℝ)^(2*j) * ((cf/2)*χ)^2 ≤ + retainedSusceptibilityProduct G (walkKernel G hloc a) p t w := by + have hx (x : V) (he : w.HasEscape hloc p j s x) : + Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ))))*(p:ℝ)^j*((cf/2)*χ) ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ x := by + obtain ⟨z,q,_hq,hj,havoid,hs⟩ := he + have hd := deformedSusceptibility_delete_interior G hloc hqt a hP p hp k t ht w z + have hδ : (cf/2)*χ ≤ + deformedSusceptibility G (walkKernel G hloc a) p k t (w.interior : Set V)ᶜ z := by + have hb := mul_le_mul_of_nonneg_left hs (zero_le_one.trans (maxSusceptibility_one_le G hloc hqt p hp)) + have hr := hrow z + linarith + exact (mul_le_mul_of_nonneg_left hδ + (mul_nonneg (Real.exp_pos _).le (pow_nonneg p.2.1 _))).trans + (deformed_move_of_walk G hloc a C p k t ht hmove (w.interior : Set V)ᶜ x z q j hj havoid) + have h₁ := hx w.base hw.2.1 + have h₂ := hx w.endpoint hw.2.2 + have hfactor : 0 ≤ Real.exp (-t*((j:ℝ)*Real.exp (C*(k:ℝ))))*(p:ℝ)^j*((cf/2)*χ) := + mul_nonneg (mul_nonneg (Real.exp_pos _).le (pow_nonneg p.2.1 _)) + (mul_nonneg (div_nonneg hcf (by norm_num)) hχ) + have hh := mul_le_mul h₁ h₂ hfactor + (deformedSusceptibility_nonneg G _ p k t (w.interior : Set V)ᶜ w.base) + rw [retainedSusceptibilityProduct,ite_eq_left hw.1] + apply le_trans (le_of_eq ?_) hh + have he : -2*t*(j:ℝ)*Real.exp (C*(k:ℝ)) = + -t*((j:ℝ)*Real.exp (C*(k:ℝ))) + -t*((j:ℝ)*Real.exp (C*(k:ℝ))) := by ring + rw [he,Real.exp_add,show 2*j=j+j by omega,pow_add] + ring + +end EscapeSusceptibility +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AveragedRetention +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] + +omit [Countable V] [Countable E] [Nonempty V] in +theorem averagedDeformedSusceptibility_nonneg (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (t : ℝ) : + 0 ≤ averagedDeformedSusceptibility G P p k root weight t := + Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (deformedSusceptibility_nonneg G P p k t Set.univ (root i))) + +omit [Countable V] [Countable E] [Nonempty V] in +theorem deformedKernel_symm (G : BondGraph V E) (P : V → V → ℝ) + (p : unitInterval) (k : ℕ) (t : ℝ) (D : Set V) (x y : V) : + deformedKernel G P p k t D x y = deformedKernel G P p k t D y x := by + simp only [deformedKernel,deformedConnection_symm G P p k t D _ x y] + +omit [Nonempty V] in + + +theorem deformed_row_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (p : unitInterval) (k : ℕ) (t : ℝ) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) (x : V) : + deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ x ≤ + c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by + obtain ⟨i,g,⟨e,he⟩,rfl⟩ := hcov x + rw [deformedSusceptibility_aut G he _ (walkKernel_covariant G hloc a he)] + simp only [Set.preimage_univ] + have hs := deformedSusceptibility_nonneg G (walkKernel G hloc a) p k t Set.univ + have hi := Finset.single_le_sum + (s := Finset.univ) + (f := fun r => weight r * deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root r)) + (fun r _ => mul_nonneg (hw r) (hs (root r))) (Finset.mem_univ i) + have hi' := mul_le_mul_of_nonneg_left hi hc + have hh := mul_le_mul_of_nonneg_right (hmin i) (hs (root i)) + change _ ≤ c*∑ r, weight r * deformedSusceptibility G (walkKernel G hloc a) p k t Set.univ (root r) + nlinarith + + + +theorem deformed_norm_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (p : unitInterval) (hp : p < pc G) (k : ℕ) (t : ℝ) (ht : 0 ≤ t) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (B : Hilbert V →L[ℂ] Hilbert V) + (hB : ∀ x y, matrixCoeff B x y = (deformedKernel G (walkKernel G hloc a) p k t Set.univ x y : ℂ)) : + ‖B‖ ≤ c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by + have hs (x : V) (F : Finset V) : + (∑ y ∈ F, |deformedKernel G (walkKernel G hloc a) p k t Set.univ x y|) ≤ + c*averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by + simp only [abs_of_nonneg (deformedKernel_nonneg G _ p k t _ _ _)] + exact ((summable_deformedKernel G hloc hqt _ hP p hp k t ht Set.univ x).sum_le_tsum F + (fun y _ => deformedKernel_nonneg G _ p k t _ x y)).trans + (deformed_row_le_root_sum G hloc a p k t root weight hw hcov c hc hmin x) + exact operator_norm_le_absolute_sums _ _ + (mul_nonneg hc (averagedDeformedSusceptibility_nonneg G _ p k root weight hw t)) hs + (fun y F => by simpa only [deformedKernel_symm G _ p k t Set.univ] using hs y F) B hB + + + +theorem deformed_root_sum_retained (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (a : ℝ) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (hcov : ∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hPs : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hA : HasKernel G p A) (k : ℕ) (t B : ℝ) (ht : 0 ≤ t) + (htB : t*‖A‖ ≤ B) (hB : B*‖P‖^k ≤ 1/4) : + ‖A‖/(2*c) ≤ averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight t := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + obtain ⟨T,hT,_,_,hret⟩ := exists_deformedOperator_small_change G hG hloc p hp0 + ((show (p:ℝ)<(pc G:ℝ) from hp).trans_le (pc G).2.2) a P hpos hPs hP + A (hA.positiveRealMatrix G p A) (hA.isPositive G p A).isSelfAdjoint hA k t ht + have hn := deformed_norm_le_root_sum G hloc hqt a hK p hp k t ht root weight hw hcov c hc.le hmin T hT + have hsmall := (mul_le_mul_of_nonneg_right htB (pow_nonneg (norm_nonneg P) k)).trans hB + have hh := mul_le_mul_of_nonneg_right hsmall (norm_nonneg A) + apply (div_le_iff₀ (by positivity : 0 < 2*c)).mpr + nlinarith + +end AveragedRetention +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AveragePositiveTerm +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] +variable {ι : Type*} [Fintype ι] + +omit [Countable V] [Countable E] [Nonempty V] in + +theorem selected_average_lower (G : BondGraph V E) (hloc : LocallyFinite G) + (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) (p : unitInterval) (k : ℕ) (t : ℝ) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (j : ℕ) (s b F : ℝ) (hF : 0 ≤ F) + (hm : b ≤ rawPathAverage G P k root weight + (fun w => if w.Selected hloc p j s then 1 else 0)) + (hgood : ∀ w : RawCorridor G k, w.Selected hloc p j s → + F ≤ retainedSusceptibilityProduct G P p t w) : + F*b ≤ rawPathAverage G P k root weight (retainedSusceptibilityProduct G P p t) := by + have hh := rawPathAverage_mono G hloc P hP k root weight hw + (fun w => F*(if w.Selected hloc p j s then 1 else 0)) + (retainedSusceptibilityProduct G P p t) (by + intro w + by_cases hs : w.Selected hloc p j s + · simpa only [hs,ite_true,mul_one] using hgood w hs + · simp only [hs,ite_false,mul_zero,retainedSusceptibilityProduct] + split_ifs + · exact mul_nonneg (deformedSusceptibility_nonneg G P p k t _ w.base) + (deformedSusceptibility_nonneg G P p k t _ w.endpoint) + · exact le_rfl) + rw [rawPathAverage_const_mul] at hh + exact (mul_le_mul_of_nonneg_left hm hF).trans hh +end AveragePositiveTerm + +section RiccatiContradiction + + +theorem riccati_retention_bound (χ D : ℝ → ℝ) (T m c h : ℝ) + (hT : 0 < T) (hm : 0 < m) (hc : 0 < c) (_hh : 0 ≤ h) + (hret : ∀ t ∈ Set.Icc (T/2) T, m/(2*c) ≤ χ t) + (hder : ∀ t ∈ Set.Icc (T/2) T, HasDerivAt χ (-D t) t) + (hdec : ∀ t ∈ Set.Icc (T/2) T, h*(χ t)^2 ≤ D t) : + h*T*m ≤ 4*c := by + have hpos (t) (ht : t ∈ Set.Icc (T/2) T) : 0 < χ t := + (div_pos hm (by positivity)).trans_le (hret t ht) + have hd (t) (ht : t ∈ Set.Icc (T/2) T) : + HasDerivAt (fun s => (χ s)⁻¹) (D t/(χ t)^2) t := by + convert! (hder t ht).inv (hpos t ht).ne' using 1 + simp only [neg_neg] + have hcχ : ContinuousOn (fun s => (χ s)⁻¹) (Set.Icc (T/2) T) := + fun t ht => (hd t ht).continuousAt.continuousWithinAt + have hdiff : DifferentiableOn ℝ (fun s => (χ s)⁻¹) (interior (Set.Icc (T/2) T)) := + fun t ht => (hd t (interior_subset ht)).differentiableAt.differentiableWithinAt + have hdl (t) (ht : t ∈ interior (Set.Icc (T/2) T)) : + h ≤ deriv (fun s => (χ s)⁻¹) t := by + rw [(hd t (interior_subset ht)).deriv] + exact (le_div_iff₀ (sq_pos_of_pos (hpos t (interior_subset ht)))).mpr (hdec t (interior_subset ht)) + have hs := (convex_Icc (T/2) T).mul_sub_le_image_sub_of_le_deriv hcχ hdiff hdl + (T/2) ⟨le_rfl,by linarith⟩ T ⟨by linarith,le_rfl⟩ (by linarith) + have hstart : 0 ≤ (χ (T/2))⁻¹ := (inv_pos.mpr (hpos _ ⟨le_rfl,by linarith⟩)).le + have hend : (χ T)⁻¹ ≤ 2*c/m := by + have hb := one_div_le_one_div_of_le (div_pos hm (by positivity)) (hret T ⟨by linarith,le_rfl⟩) + simpa only [one_div,inv_div] using hb + have hs' : h*(T/2) ≤ 2*c/m := by linarith + have hs'' := (le_div_iff₀ hm).mp hs' + nlinarith +end RiccatiContradiction +end Percolation + + + + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteScale +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Infinite V] +variable {ι : Type*} [Fintype ι] + + + +theorem exists_finite_scale_obstruction + (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) + (hpcrit : 0 < (pc G:ℝ)) (hpcrit₁ : (pc G:ℝ) < 1) : + ∃ C : ℝ, 0 < C ∧ ∃ J : ℕ, 0 < J ∧ ∃ C₁ : ℝ, 0 < C₁ ∧ + ∃ k₀ : ℕ, 3 ≤ k₀ ∧ ∃ ε M : ℝ, 0 < ε ∧ 0 < M ∧ + ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (A : Hilbert V →L[ℂ] Hilbert V), HasKernel G p A → + ∀ k : ℕ, k₀ ≤ k → ∀ B : ℝ, 0 < B → + let R := maxSusceptibility G p/‖A‖ + let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ + B*‖P‖^k ≤ 1/4 → + B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ ‖A‖ → + R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k ≤ ε*((pc G:ℝ)/2)^(2*j) → + M < B*((pc G:ℝ)/2)^(2*j) → False := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hw₀ (i) := (hw i).le + obtain ⟨Cr,cf,hCr,hcf,hrow⟩ := exists_uniform_deformed_row_comparison G hconn hloc hqt + root weight hw₀ hw1 (fun x => by + obtain ⟨i,g,⟨e,he⟩,hx⟩ := hcov x + exact ⟨i,g,e,he,hx⟩) d hd a hK hpcrit hpcrit₁ + obtain ⟨Cm,hCm,hmove⟩ := exists_uniform_deformed_endpoint_comparison G hloc hqt d hd a hK hpcrit hpcrit₁ + obtain ⟨Cd,hCd,hdecrease⟩ := exists_uniform_averaged_decrease G hG hloc hqt + root weight hw₀ (vertexAut G) (Set.Subset.refl _) htr d hd a hK hpcrit hpcrit₁ P hpos hP hsym + let τ := cf/(8*c) + have hτ : 0 < τ := div_pos hcf (by positivity) + obtain ⟨J,C₁,k₀,b,hJ,hC₁,hk₀,hb,hselected⟩ := exists_selected_path_mass G hconn hloc hqt + a ha root weight htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag hρ d hd τ hτ + let C := Cr+Cm+Cd + let q := b*Real.exp (-2)*(cf/2)^2 + let H := (1+2*(d:ℝ)/(pc G:ℝ))*(2*c)^2 + let ε := q/(2*H) + let h₀ := Real.exp (-1)*q/2 + let M := 4*c/h₀ + have hq : 0 < q := by dsimp [q]; positivity + have hH : 0 < H := by dsimp [H]; positivity + have hε : 0 < ε := div_pos hq (by positivity) + have hh₀ : 0 < h₀ := by dsimp [h₀]; positivity + have hM : 0 < M := div_pos (by positivity) hh₀ + refine ⟨C,by dsimp [C]; positivity,J,hJ,C₁,hC₁,k₀,hk₀,ε,M,hε,hM,?_⟩ + intro p hpnear hp A hA k hk B hB + dsimp only + let m := ‖A‖ + let R := maxSusceptibility G p/m + let j := J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ + let β := ((pc G:ℝ)/2)^(2*j) + let T := B/m + let χ := averagedDeformedSusceptibility G (walkKernel G hloc a) p k root weight + let D := fun t => ∑ i, weight i * ∫ ω, deformedDerivativeMass G (walkKernel G hloc a) p k t Set.univ ω (root i) ∂law p + change B*‖P‖^k ≤ 1/4 → B*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ m → + R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k ≤ ε*β → M < B*β → False + intro hsmall htime herrscale hlarge + have hm : 0 < m := zero_lt_one.trans_le (hA.norm_one_le G p A) + have hR : 1 ≤ R := (one_le_div hm).mpr (hA.norm_le_maxSusceptibility G hloc hqt p hp A) + have hβ : 0 < β := pow_pos (half_pos hpcrit) _ + have hj : 1 ≤ j := by dsimp [j]; omega + have hjr : (1:ℝ) ≤ (j:ℝ) := Nat.one_le_cast.mpr hj + have hk3 : 3 ≤ k := hk₀.trans hk + have hpzero : 0 < (p:ℝ) := (half_pos hpcrit).trans_le hpnear + have hT : 0 < T := div_pos hB hm + have hTb (t : ℝ) (ht : t ≤ T) : t*m ≤ B := (le_div_iff₀ hm).mp ht + have htim (t : ℝ) (ht : t ≤ T) : t*(j:ℝ)*Real.exp (C*(k:ℝ)) ≤ 1 := by + have hm' := mul_le_mul_of_nonneg_right (hTb t ht) + (mul_nonneg (Nat.cast_nonneg j) (Real.exp_pos (C*(k:ℝ))).le) + nlinarith only [hm',htime,hm] + have hCbound (C' : ℝ) (hC' : C' ≤ C) : Real.exp (C'*(k:ℝ)) ≤ Real.exp (C*(k:ℝ)) := + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hC' (Nat.cast_nonneg k)) + have htim' (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) (C' : ℝ) (hC' : C' ≤ C) : + t*Real.exp (C'*(k:ℝ)) ≤ 1 := by + have he := mul_le_mul_of_nonneg_left (hCbound C' hC') ht + have hj' := mul_le_mul_of_nonneg_left hjr (mul_nonneg ht (Real.exp_pos (C*(k:ℝ))).le) + nlinarith only [he,hj',htim t htT] + have hret (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) : m/(2*c) ≤ χ t := + deformed_root_sum_retained G hG hloc hqt a p hpzero hp root weight hw₀ hcov c hc hmin + P A hpos hsym hP hA k t B ht (hTb t htT) hsmall + have hdec (t : ℝ) (ht : 0 ≤ t) (htT : t ≤ T) : (h₀*β)*(χ t)^2 ≤ D t := by + have hχ : 0 ≤ χ t := averagedDeformedSusceptibility_nonneg G _ p k root weight hw₀ t + have hret' := (div_le_iff₀ (by positivity : 0 < 2*c)).mp (hret t ht htT) + have hrow' := hrow p hpnear hp k hk3 t ht (htim' t ht htT Cr (by dsimp [C]; linarith only [hCr,hCm,hCd])) + have hcost : maxSusceptibility G p*(τ/R) ≤ (cf/2)*χ t := by + have hmax : maxSusceptibility G p ≠ 0 := + (zero_lt_one.trans_le (maxSusceptibility_one_le G hloc hqt p hp)).ne' + have he : maxSusceptibility G p*(τ/R) = τ*m := by dsimp [R]; field_simp [hmax] + rw [he] + have hh := mul_le_mul_of_nonneg_left hret' hτ.le + have hτcf : τ*(2*c) = cf/4 := by dsimp [τ]; field_simp; ring + rw [mul_left_comm τ (χ t) (2*c),hτcf,mul_comm (χ t)] at hh + nlinarith only [hh,hcf,hχ] + have hprod (w : RawCorridor G k) (hwsel : w.Selected hloc p j (τ/R)) : + Real.exp (-2)*β*((cf/2)*χ t)^2 ≤ retainedSusceptibilityProduct G (walkKernel G hloc a) p t w := by + have hbnd := selected_retained_product_lower G hloc hqt a hK p hp k t ht j (τ/R) Cm cf (χ t) + hcf.le hχ hrow' hcost (hmove p hpnear hp k hk3 t ht) w hwsel + have he : Real.exp (-2) ≤ Real.exp (-2*t*(j:ℝ)*Real.exp (Cm*(k:ℝ))) := by + apply Real.exp_le_exp.mpr + have he' := mul_le_mul_of_nonneg_left (hCbound Cm (by dsimp [C]; linarith only [hCr,hCm,hCd])) + (mul_nonneg ht (Nat.cast_nonneg j)) + linarith only [he',htim t htT] + have hpw : β ≤ (p:ℝ)^(2*j) := pow_le_pow_left₀ (half_pos hpcrit).le hpnear _ + exact (mul_le_mul_of_nonneg_right + (mul_le_mul he hpw hβ.le (Real.exp_pos _).le) (sq_nonneg _)).trans hbnd + have hsel := hselected p hpnear hp k hk R hR + have hpositive := selected_average_lower G hloc _ hK p k t root weight hw₀ j (τ/R) b + (Real.exp (-2)*β*((cf/2)*χ t)^2) (by positivity) hsel hprod + have hpositive' : q*β*(χ t)^2 ≤ rawPathAverage G (walkKernel G hloc a) k root weight + (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) := by + convert hpositive using 1 + dsimp [q] + ring + have ha₃ : 0 ≤ rootTriangle G root weight (p:ℝ) := + zero_le_one.trans (rootTriangle_one_le G hloc hqt root weight hw₀ hw1 p hp) + have herror : (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * + (‖P‖^k*(rootTrace root weight (A^3)).re) ≤ (q/2)*β*(χ t)^2 := by + rw [←rootTriangle_eq_trace G p root weight A hA] + have hx : maxSusceptibility G p = R*m := by dsimp [R]; field_simp + rw [hx] + have hcoeff : 0 ≤ (1+2*(d:ℝ)/(pc G:ℝ)) := by positivity + have hm2 : m^2 ≤ (2*c)^2*(χ t)^2 := by + calc + m^2 ≤ (χ t*(2*c))^2 := pow_le_pow_left₀ hm.le hret' 2 + _ = _ := by ring + have h₁ := mul_le_mul_of_nonneg_left hm2 + (mul_nonneg (mul_nonneg hcoeff (sq_nonneg R)) (mul_nonneg ha₃ (pow_nonneg (norm_nonneg P) k))) + have h₂ := mul_le_mul_of_nonneg_left herrscale (mul_nonneg hH.le (sq_nonneg (χ t))) + have he : H*ε = q/2 := by dsimp [ε]; field_simp + calc + _ ≤ H*(R^2*rootTriangle G root weight (p:ℝ)*‖P‖^k)*(χ t)^2 := by dsimp [H]; nlinarith only [h₁] + _ ≤ H*(ε*β)*(χ t)^2 := by nlinarith only [h₂] + _ = _ := by rw [←mul_assoc H ε β,he] + have hdiff : (q/2)*β*(χ t)^2 ≤ + rawPathAverage G (walkKernel G hloc a) k root weight + (retainedSusceptibilityProduct G (walkKernel G hloc a) p t) - + (1+2*(d:ℝ)/(pc G:ℝ))*(maxSusceptibility G p)^2 * + (‖P‖^k*(rootTrace root weight (A^3)).re) := by linarith only [hpositive',herror] + have hexp : Real.exp (-1) ≤ Real.exp (-t*Real.exp (Cd*(k:ℝ))) := + Real.exp_le_exp.mpr (by linarith only [htim' t ht htT Cd (by dsimp [C]; linarith only [hCr,hCm]) ]) + have hh := mul_le_mul hexp hdiff (by positivity) (Real.exp_pos _).le + have hdecr := hdecrease p hpnear hp A hA k hk3 t ht + apply le_trans _ hdecr + convert hh using 1 + dsimp [h₀] + ring + have hb := riccati_retention_bound χ D T m c (h₀*β) hT hm hc (mul_pos hh₀ hβ).le + (fun t ht => hret t (by linarith only [ht.1,hT]) ht.2) + (fun t ht => hasDerivAt_averagedDeformedSusceptibility G hloc hqt root weight d hd a hK p hpzero hp k t + (by linarith only [ht.1,hT])) + (fun t ht => hdec t (by linarith only [ht.1,hT]) ht.2) + have he : h₀*β*T*m = h₀*(B*β) := by dsimp [T]; field_simp + rw [he] at hb + have hg := (div_lt_iff₀ hh₀).mp hlarge + nlinarith only [hg,hb] + +end FiniteScale +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Counts.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Counts.lean index 73f6cc95365d08faf75d3fdb414d7237c876abc1..bbd92e41d53231a21c6175a6b3a3d597372641d0 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Counts.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Counts.lean @@ -1,224 +1,224 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.Measurability - -namespace OAI - -/-! Counting encounter vertices by mass transport. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -open scoped ENNReal -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -def cutIso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} - (f : H ≃g K) (x : V) : cutVertex H x ≃g cutVertex K (f x) where - toEquiv := f.toEquiv - map_rel_iff' := by - intro a b - change (K.Adj (f a) (f b) ∧ f a ≠ f x ∧ f b ≠ f x) ↔ - (H.Adj a b ∧ a ≠ x ∧ b ≠ x) - simp only [f.map_adj_iff,f.injective.ne_iff] - -theorem branchCount_iso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} - (f : H ≃g K) (S : Finset V) (x : V) : - branchCount K (S.image f) (f x) = branchCount H S x := by - unfold branchCount - rw [←Finset.image_erase f.injective,Finset.image_image] - let e := (cutIso f x).connectedComponentEquiv - have he : ((S.erase x).image (fun a => (cutVertex K (f x)).connectedComponentMk (f a))) = - (((S.erase x).image (cutVertex H x).connectedComponentMk).image e) := by - rw [Finset.image_image] - rfl - change ((S.erase x).image (fun a => (cutVertex K (f x)).connectedComponentMk (f a))).card = _ - rw [he] - exact Finset.card_image_iff.mpr e.injective.injOn - -theorem clusterFinset_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω : Set E) (x : V) : - (clusterFinset G (b ⁻¹' ω) x).image a = clusterFinset G ω (a x) := by - have hi : (cluster G (b ⁻¹' ω) x).Infinite ↔ (cluster G ω (a x)).Infinite := by - rw [←cluster_aut G hab] - exact (Set.infinite_image_iff a.injective.injOn).symm - by_cases hf : (cluster G (b ⁻¹' ω) x).Finite - · have hf' : (cluster G ω (a x)).Finite := by - rw [←cluster_aut G hab] - exact hf.image a - apply Finset.coe_injective - simp only [Finset.coe_image,clusterFinset_coe G _ _ hf,clusterFinset_coe G _ _ hf'] - exact cluster_aut G hab ω x - · have hf' : ¬(cluster G ω (a x)).Finite := hi.mp hf - simp only [clusterFinset,dite_eq_right hf,dite_eq_right hf',Finset.image_empty] - -theorem measurable_branchCount_pair [Countable V] [Countable E] - (G : BondGraph V E) (x : V) : - Measurable (fun z : Set E × Finset V => branchCount (openSimpleGraph G z.1) z.2 x) := - measurable_from_prod_countable_left (fun S => measurable_branchCount G S x) - -noncomputable def markedCluster (G : BondGraph V E) (ω η : Set E) (x : V) : Finset V := - (clusterFinset G η x).filter (IsEncounter G ω) - -noncomputable def encounterCount (G : BondGraph V E) (ω η : Set E) (x : V) : ℕ := - if IsEncounter G ω x then branchCount (openSimpleGraph G ω) (markedCluster G ω η x) x else 0 - -theorem markedCluster_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω η : Set E) (x : V) : - (markedCluster G (b ⁻¹' ω) (b ⁻¹' η) x).image a = markedCluster G ω η (a x) := by - unfold markedCluster - rw [←clusterFinset_aut G a b hab η x,Finset.filter_image] - simp only [isEncounter_aut_iff G a b hab] - -theorem encounterCount_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω η : Set E) (x : V) : - encounterCount G (b ⁻¹' ω) (b ⁻¹' η) x = encounterCount G ω η (a x) := by - simp only [encounterCount,isEncounter_aut_iff G a b hab] - congr 1 - rw [←markedCluster_aut G a b hab] - exact (branchCount_iso (openAutIso G a b hab ω) _ x).symm - -theorem measurable_markedCluster [Countable V] [Countable E] - (G : BondGraph V E) (p q : unitInterval) (x : V) : - Measurable (fun l : E → unitInterval => markedCluster G (openEdges l p) (openEdges l q) x) := - measurable_filter_finset _ ((measurable_clusterFinset G x).comp (measurable_openEdges q)) _ - (fun y => (measurableSet_isEncounter G y).preimage (measurable_openEdges p)) - -theorem measurable_encounterCount [Countable V] [Countable E] - (G : BondGraph V E) (p q : unitInterval) (x : V) : - Measurable (fun l : E → unitInterval => encounterCount G (openEdges l p) (openEdges l q) x) := by - apply Measurable.ite ((measurableSet_isEncounter G x).preimage (measurable_openEdges p)) _ measurable_const - exact (measurable_branchCount_pair G x).comp - ((measurable_openEdges p).prodMk (measurable_markedCluster G p q x)) - -theorem cluster_induce_connected (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) (x : V) : - ((openSimpleGraph G ω).induce (cluster G η x)).Connected := by - let H := openSimpleGraph G η - have he : cluster G η x = (H.connectedComponentMk x).supp := by - ext y - simp only [cluster,Set.mem_ofPred_eq,ConnectedComponent.mem_supp_iff,ConnectedComponent.eq] - exact (conn_iff_reachable G η x y).trans SimpleGraph.reachable_comm - rw [he] - apply SimpleGraph.Connected.mono (G := H.induce (H.connectedComponentMk x).supp) - · intro a b hab - exact ⟨hab.1,by obtain ⟨e,he,hGe⟩ := hab.2; exact ⟨e,hsub he,hGe⟩⟩ - · exact (H.connectedComponentMk x).connected_toSimpleGraph - -theorem markedCluster_eq_of_conn (G : BondGraph V E) (ω η : Set E) {x y : V} - (hxy : Conn G η x y) : markedCluster G ω η x = markedCluster G ω η y := by - unfold markedCluster clusterFinset - simp only [cluster_eq_of_conn G η hxy] - -theorem sum_encounterCount_le (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) (x : V) - (hf : (cluster G η x).Finite) : - (∑ y ∈ clusterFinset G η x, encounterCount G ω η y) ≤ - 2*(markedCluster G ω η x).card := by - let D := clusterFinset G η x - let S := markedCluster G ω η x - have hSD : S ⊆ D := Finset.filter_subset _ _ - have hDeq : (D:Set V) = cluster G η x := clusterFinset_coe G η x hf - have hDconn : ((openSimpleGraph G ω).induce (D:Set V)).Connected := - hDeq ▸ cluster_induce_connected G ω η hsub x - have he : (∑ y ∈ D, encounterCount G ω η y) = - ∑ y ∈ S, branchCount (openSimpleGraph G ω) S y := by - calc - _ = ∑ y ∈ D, if IsEncounter G ω y then branchCount (openSimpleGraph G ω) S y else 0 := by - apply Finset.sum_congr rfl - intro y hy - have hxy : Conn G η x y := by - change y ∈ cluster G η x - rw [←hDeq] - exact hy - rw [encounterCount,←markedCluster_eq_of_conn G ω η hxy] - _ = _ := (Finset.sum_filter _ _).symm - rw [he] - by_cases hs : S.Nonempty - · exact (Nat.le_add_right _ 2).trans (sum_branchCount_le (openSimpleGraph G ω) S D hs hSD hDconn) - · rw [Finset.not_nonempty_iff_eq_empty.mp hs] - simp - -end Percolation - -namespace Percolation -open MeasureTheory SimpleGraph -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cluster_average_eq_sum (G : BondGraph V E) (η : Set E) (x : V) - (hf : (cluster G η x).Finite) (f : V → ℝ≥0∞) : - (∑' y, clusterAveragingKernel G η x y * f y) = - ((cluster G η x).ncard : ℝ≥0∞)⁻¹ * ∑ y ∈ clusterFinset G η x, f y := by - rw [tsum_eq_sum (s := clusterFinset G η x)] - · rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y hy - have hc : Conn G η x y := by - change y ∈ cluster G η x - rw [←clusterFinset_coe G η x hf] - exact hy - simp only [clusterAveragingKernel,ite_eq_left hc] - · intro y hy - have hc : ¬Conn G η x y := by - intro h - apply hy - have hm : y ∈ cluster G η x := h - rwa [←clusterFinset_coe G η x hf] at hm - simp only [clusterAveragingKernel,ite_eq_right hc,zero_mul] - -theorem average_encounterCount_le (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) - (x : V) (hf : (cluster G η x).Finite) : - (∑' y, clusterAveragingKernel G η x y * (encounterCount G ω η y : ℝ≥0∞)) ≤ - 2 * ∑' y, clusterAveragingKernel G η x y * (if IsEncounter G ω y then 1 else 0) := by - rw [cluster_average_eq_sum G η x hf,cluster_average_eq_sum G η x hf] - have hc : (∑ y ∈ clusterFinset G η x, (encounterCount G ω η y : ℝ≥0∞)) ≤ - 2 * (markedCluster G ω η x).card := by - exact_mod_cast sum_encounterCount_le G ω η hsub x hf - have he : (∑ y ∈ clusterFinset G η x, (if IsEncounter G ω y then (1:ℝ≥0∞) else 0)) = - (markedCluster G ω η x).card := by - rw [←Finset.sum_filter] - simp only [markedCluster,Finset.sum_const,nsmul_one] - rw [he,←mul_assoc, mul_comm (2:ℝ≥0∞),mul_assoc] - exact mul_le_mul_right hc _ - -theorem expected_encounterCount_le [Countable V] [Countable E] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) - (p q : unitInterval) (hqp : q ≤ p) - (hfin : ∀ x, ∀ᵐ ω ∂law q, (cluster G ω x).Finite) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, - (encounterCount G (openEdges l p) (openEdges l q) (root i) : ℝ≥0∞) ∂labelLaw) ≤ - 2 * (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, - (if IsEncounter G (openEdges l p) (root i) then 1 else 0) ∂labelLaw) := by - have ha := label_root_cluster_average G hconn hloc root weight htr hw q hfin - (fun l x => (encounterCount G (openEdges l p) (openEdges l q) x : ℝ≥0∞)) - (fun x => (measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_encounterCount G p q x)) - (fun a b hab l x => by exact_mod_cast encounterCount_aut G a b hab (openEdges l p) (openEdges l q) x) - have hb := label_root_cluster_average G hconn hloc root weight htr hw q hfin - (fun l x => if IsEncounter G (openEdges l p) x then (1:ℝ≥0∞) else 0) - (fun x => Measurable.ite ((measurableSet_isEncounter G x).preimage (measurable_openEdges p)) - measurable_const measurable_const) - (fun a b hab l x => by simp only [show openEdges (l ∘ b) p = b ⁻¹' openEdges l p from rfl, - isEncounter_aut_iff G a b hab]) - rw [←ha,←hb,Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - rw [←mul_assoc,mul_comm (2:ℝ≥0∞),mul_assoc] - apply mul_le_mul_right - rw [←lintegral_const_mul' _ _ ENNReal.ofNat_ne_top] - apply lintegral_mono_ae - have hfl : ∀ᵐ l ∂labelLaw, (cluster G (openEdges l q) (root i)).Finite := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => (cluster G ω (root i)).Finite) (measurable_openEdges q).aemeasurable - rw [map_openEdges] - exact hfin (root i) - filter_upwards [hfl] with l hl - exact average_encounterCount_le G _ _ (openEdges_mono l hqp) (root i) hl -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.Measurability + +namespace OAI + +/-! Counting encounter vertices by mass transport. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +open scoped ENNReal +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +def cutIso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} + (f : H ≃g K) (x : V) : cutVertex H x ≃g cutVertex K (f x) where + toEquiv := f.toEquiv + map_rel_iff' := by + intro a b + change (K.Adj (f a) (f b) ∧ f a ≠ f x ∧ f b ≠ f x) ↔ + (H.Adj a b ∧ a ≠ x ∧ b ≠ x) + simp only [f.map_adj_iff,f.injective.ne_iff] + +theorem branchCount_iso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} + (f : H ≃g K) (S : Finset V) (x : V) : + branchCount K (S.image f) (f x) = branchCount H S x := by + unfold branchCount + rw [←Finset.image_erase f.injective,Finset.image_image] + let e := (cutIso f x).connectedComponentEquiv + have he : ((S.erase x).image (fun a => (cutVertex K (f x)).connectedComponentMk (f a))) = + (((S.erase x).image (cutVertex H x).connectedComponentMk).image e) := by + rw [Finset.image_image] + rfl + change ((S.erase x).image (fun a => (cutVertex K (f x)).connectedComponentMk (f a))).card = _ + rw [he] + exact Finset.card_image_iff.mpr e.injective.injOn + +theorem clusterFinset_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω : Set E) (x : V) : + (clusterFinset G (b ⁻¹' ω) x).image a = clusterFinset G ω (a x) := by + have hi : (cluster G (b ⁻¹' ω) x).Infinite ↔ (cluster G ω (a x)).Infinite := by + rw [←cluster_aut G hab] + exact (Set.infinite_image_iff a.injective.injOn).symm + by_cases hf : (cluster G (b ⁻¹' ω) x).Finite + · have hf' : (cluster G ω (a x)).Finite := by + rw [←cluster_aut G hab] + exact hf.image a + apply Finset.coe_injective + simp only [Finset.coe_image,clusterFinset_coe G _ _ hf,clusterFinset_coe G _ _ hf'] + exact cluster_aut G hab ω x + · have hf' : ¬(cluster G ω (a x)).Finite := hi.mp hf + simp only [clusterFinset,dite_eq_right hf,dite_eq_right hf',Finset.image_empty] + +theorem measurable_branchCount_pair [Countable V] [Countable E] + (G : BondGraph V E) (x : V) : + Measurable (fun z : Set E × Finset V => branchCount (openSimpleGraph G z.1) z.2 x) := + measurable_from_prod_countable_left (fun S => measurable_branchCount G S x) + +noncomputable def markedCluster (G : BondGraph V E) (ω η : Set E) (x : V) : Finset V := + (clusterFinset G η x).filter (IsEncounter G ω) + +noncomputable def encounterCount (G : BondGraph V E) (ω η : Set E) (x : V) : ℕ := + if IsEncounter G ω x then branchCount (openSimpleGraph G ω) (markedCluster G ω η x) x else 0 + +theorem markedCluster_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω η : Set E) (x : V) : + (markedCluster G (b ⁻¹' ω) (b ⁻¹' η) x).image a = markedCluster G ω η (a x) := by + unfold markedCluster + rw [←clusterFinset_aut G a b hab η x,Finset.filter_image] + simp only [isEncounter_aut_iff G a b hab] + +theorem encounterCount_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω η : Set E) (x : V) : + encounterCount G (b ⁻¹' ω) (b ⁻¹' η) x = encounterCount G ω η (a x) := by + simp only [encounterCount,isEncounter_aut_iff G a b hab] + congr 1 + rw [←markedCluster_aut G a b hab] + exact (branchCount_iso (openAutIso G a b hab ω) _ x).symm + +theorem measurable_markedCluster [Countable V] [Countable E] + (G : BondGraph V E) (p q : unitInterval) (x : V) : + Measurable (fun l : E → unitInterval => markedCluster G (openEdges l p) (openEdges l q) x) := + measurable_filter_finset _ ((measurable_clusterFinset G x).comp (measurable_openEdges q)) _ + (fun y => (measurableSet_isEncounter G y).preimage (measurable_openEdges p)) + +theorem measurable_encounterCount [Countable V] [Countable E] + (G : BondGraph V E) (p q : unitInterval) (x : V) : + Measurable (fun l : E → unitInterval => encounterCount G (openEdges l p) (openEdges l q) x) := by + apply Measurable.ite ((measurableSet_isEncounter G x).preimage (measurable_openEdges p)) _ measurable_const + exact (measurable_branchCount_pair G x).comp + ((measurable_openEdges p).prodMk (measurable_markedCluster G p q x)) + +theorem cluster_induce_connected (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) (x : V) : + ((openSimpleGraph G ω).induce (cluster G η x)).Connected := by + let H := openSimpleGraph G η + have he : cluster G η x = (H.connectedComponentMk x).supp := by + ext y + simp only [cluster,Set.mem_ofPred_eq,ConnectedComponent.mem_supp_iff,ConnectedComponent.eq] + exact (conn_iff_reachable G η x y).trans SimpleGraph.reachable_comm + rw [he] + apply SimpleGraph.Connected.mono (G := H.induce (H.connectedComponentMk x).supp) + · intro a b hab + exact ⟨hab.1,by obtain ⟨e,he,hGe⟩ := hab.2; exact ⟨e,hsub he,hGe⟩⟩ + · exact (H.connectedComponentMk x).connected_toSimpleGraph + +theorem markedCluster_eq_of_conn (G : BondGraph V E) (ω η : Set E) {x y : V} + (hxy : Conn G η x y) : markedCluster G ω η x = markedCluster G ω η y := by + unfold markedCluster clusterFinset + simp only [cluster_eq_of_conn G η hxy] + +theorem sum_encounterCount_le (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) (x : V) + (hf : (cluster G η x).Finite) : + (∑ y ∈ clusterFinset G η x, encounterCount G ω η y) ≤ + 2*(markedCluster G ω η x).card := by + let D := clusterFinset G η x + let S := markedCluster G ω η x + have hSD : S ⊆ D := Finset.filter_subset _ _ + have hDeq : (D:Set V) = cluster G η x := clusterFinset_coe G η x hf + have hDconn : ((openSimpleGraph G ω).induce (D:Set V)).Connected := + hDeq ▸ cluster_induce_connected G ω η hsub x + have he : (∑ y ∈ D, encounterCount G ω η y) = + ∑ y ∈ S, branchCount (openSimpleGraph G ω) S y := by + calc + _ = ∑ y ∈ D, if IsEncounter G ω y then branchCount (openSimpleGraph G ω) S y else 0 := by + apply Finset.sum_congr rfl + intro y hy + have hxy : Conn G η x y := by + change y ∈ cluster G η x + rw [←hDeq] + exact hy + rw [encounterCount,←markedCluster_eq_of_conn G ω η hxy] + _ = _ := (Finset.sum_filter _ _).symm + rw [he] + by_cases hs : S.Nonempty + · exact (Nat.le_add_right _ 2).trans (sum_branchCount_le (openSimpleGraph G ω) S D hs hSD hDconn) + · rw [Finset.not_nonempty_iff_eq_empty.mp hs] + simp + +end Percolation + +namespace Percolation +open MeasureTheory SimpleGraph +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cluster_average_eq_sum (G : BondGraph V E) (η : Set E) (x : V) + (hf : (cluster G η x).Finite) (f : V → ℝ≥0∞) : + (∑' y, clusterAveragingKernel G η x y * f y) = + ((cluster G η x).ncard : ℝ≥0∞)⁻¹ * ∑ y ∈ clusterFinset G η x, f y := by + rw [tsum_eq_sum (s := clusterFinset G η x)] + · rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y hy + have hc : Conn G η x y := by + change y ∈ cluster G η x + rw [←clusterFinset_coe G η x hf] + exact hy + simp only [clusterAveragingKernel,ite_eq_left hc] + · intro y hy + have hc : ¬Conn G η x y := by + intro h + apply hy + have hm : y ∈ cluster G η x := h + rwa [←clusterFinset_coe G η x hf] at hm + simp only [clusterAveragingKernel,ite_eq_right hc,zero_mul] + +theorem average_encounterCount_le (G : BondGraph V E) (ω η : Set E) (hsub : η ⊆ ω) + (x : V) (hf : (cluster G η x).Finite) : + (∑' y, clusterAveragingKernel G η x y * (encounterCount G ω η y : ℝ≥0∞)) ≤ + 2 * ∑' y, clusterAveragingKernel G η x y * (if IsEncounter G ω y then 1 else 0) := by + rw [cluster_average_eq_sum G η x hf,cluster_average_eq_sum G η x hf] + have hc : (∑ y ∈ clusterFinset G η x, (encounterCount G ω η y : ℝ≥0∞)) ≤ + 2 * (markedCluster G ω η x).card := by + exact_mod_cast sum_encounterCount_le G ω η hsub x hf + have he : (∑ y ∈ clusterFinset G η x, (if IsEncounter G ω y then (1:ℝ≥0∞) else 0)) = + (markedCluster G ω η x).card := by + rw [←Finset.sum_filter] + simp only [markedCluster,Finset.sum_const,nsmul_one] + rw [he,←mul_assoc, mul_comm (2:ℝ≥0∞),mul_assoc] + exact mul_le_mul_right hc _ + +theorem expected_encounterCount_le [Countable V] [Countable E] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) + (p q : unitInterval) (hqp : q ≤ p) + (hfin : ∀ x, ∀ᵐ ω ∂law q, (cluster G ω x).Finite) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, + (encounterCount G (openEdges l p) (openEdges l q) (root i) : ℝ≥0∞) ∂labelLaw) ≤ + 2 * (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, + (if IsEncounter G (openEdges l p) (root i) then 1 else 0) ∂labelLaw) := by + have ha := label_root_cluster_average G hconn hloc root weight htr hw q hfin + (fun l x => (encounterCount G (openEdges l p) (openEdges l q) x : ℝ≥0∞)) + (fun x => (measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_encounterCount G p q x)) + (fun a b hab l x => by exact_mod_cast encounterCount_aut G a b hab (openEdges l p) (openEdges l q) x) + have hb := label_root_cluster_average G hconn hloc root weight htr hw q hfin + (fun l x => if IsEncounter G (openEdges l p) x then (1:ℝ≥0∞) else 0) + (fun x => Measurable.ite ((measurableSet_isEncounter G x).preimage (measurable_openEdges p)) + measurable_const measurable_const) + (fun a b hab l x => by simp only [show openEdges (l ∘ b) p = b ⁻¹' openEdges l p from rfl, + isEncounter_aut_iff G a b hab]) + rw [←ha,←hb,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [←mul_assoc,mul_comm (2:ℝ≥0∞),mul_assoc] + apply mul_le_mul_right + rw [←lintegral_const_mul' _ _ ENNReal.ofNat_ne_top] + apply lintegral_mono_ae + have hfl : ∀ᵐ l ∂labelLaw, (cluster G (openEdges l q) (root i)).Finite := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => (cluster G ω (root i)).Finite) (measurable_openEdges q).aemeasurable + rw [map_openEdges] + exact hfin (root i) + filter_upwards [hfl] with l hl + exact average_encounterCount_le G _ _ (openEdges_mono l hqp) (root i) hl +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Geometry.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Geometry.lean index 33685eed8abfdd5587c442b2c43cb50db02689ce..d22680c2aaf764807e9859ee28756270dada826f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Geometry.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Geometry.lean @@ -1,144 +1,144 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Cut vertices and connected branches. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open SimpleGraph -universe u w -variable {V : Type u} {W : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -def cutVertex (H : SimpleGraph V) (x : V) : SimpleGraph V where - Adj a b := H.Adj a b ∧ a ≠ x ∧ b ≠ x - symm := ⟨fun _ _ h => ⟨h.1.symm,h.2.2,h.2.1⟩⟩ - loopless := ⟨fun a h => H.loopless.irrefl a h.1⟩ - -noncomputable def branchCount (H : SimpleGraph V) (S : Finset V) (x : V) : ℕ := - ((S.erase x).image (cutVertex H x).connectedComponentMk).card - -theorem walk_reachable_cut (H : SimpleGraph V) (T : SimpleGraph W) - (f : W → V) (hf : ∀ {a b}, T.Adj a b → H.Adj (f a) (f b)) - (x : V) {a b : W} (p : T.Walk a b) - (hp : ∀ z ∈ p.support, f z ≠ x) : - (cutVertex H x).Reachable (f a) (f b) := by - induction p with - | nil => exact .refl _ - | @cons a b c hab p ih => - apply Reachable.trans (Adj.reachable (G := cutVertex H x) ?_) (ih ?_) - · exact ⟨hf hab,hp a (by simp),hp b (by simp [p.start_mem_support])⟩ - · intro z hz - exact hp z (by simp [hz]) - -theorem branchCount_le_degree [Fintype W] (H : SimpleGraph V) (T : SimpleGraph W) - (f : W ↪ V) (hf : ∀ {a b}, T.Adj a b → H.Adj (f a) (f b)) - (hT : T.Connected) (S : Finset V) (hS : ∀ z ∈ S, ∃ y, f y = z) (x : W) : - branchCount H S (f x) ≤ T.degree x := by - classical - let g : W → (cutVertex H (f x)).ConnectedComponent := - fun y => (cutVertex H (f x)).connectedComponentMk (f y) - have hsub : (S.erase (f x)).image (cutVertex H (f x)).connectedComponentMk ⊆ - (T.neighborFinset x).image g := by - intro c hc - obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp hc - obtain ⟨hyx,hzS⟩ := Finset.mem_erase.mp hz - obtain ⟨y,rfl⟩ := hS z hzS - obtain ⟨p,hp⟩ := hT.exists_isPath x y - cases p with - | nil => exact False.elim (hyx rfl) - | @cons x a y hab p => - refine Finset.mem_image.mpr ⟨a,(T.mem_neighborFinset x a).mpr hab,?_⟩ - apply ConnectedComponent.sound - apply walk_reachable_cut H T f hf (f x) p - intro z hz he - have hzx := f.injective he - subst z - exact (List.nodup_cons.mp hp.support_nodup).1 hz - exact (Finset.card_le_card hsub).trans ((Finset.card_image_le).trans (by simp)) - -theorem connected_erase_leaf (H : SimpleGraph V) (D : Finset V) - (T : SimpleGraph (D:Set V)) (hTH : T ≤ H.induce (D:Set V)) - (hT : T.Connected) (z : (D:Set V)) (hz : T.degree z = 1) : - (H.induce ((D.erase z.val):Set V)).Connected := by - let f : ({z}ᶜ : Set (D:Set V)) → ((D.erase z.val):Set V) := - fun y => ⟨y.val.val,Finset.mem_erase.mpr ⟨by - intro h - apply y.property - exact Subtype.ext h,y.val.property⟩⟩ - have hf : Function.Surjective f := by - intro y - refine ⟨⟨⟨y.val,(Finset.mem_erase.mp y.property).2⟩,?_⟩,rfl⟩ - intro h - exact (Finset.mem_erase.mp y.property).1 (congrArg Subtype.val h) - apply (hT.induce_compl_singleton_of_degree_eq_one hz).map (f := ⟨f,?_⟩) hf - intro a b hab - exact hTH hab - -theorem exists_pruned_connector (H : SimpleGraph V) (S D : Finset V) - (hS : S.Nonempty) (hSD : S ⊆ D) (hD : (H.induce (D:Set V)).Connected) : - ∃ D' : Finset V, D' ⊆ D ∧ S ⊆ D' ∧ - ∃ T : SimpleGraph (D':Set V), T ≤ H.induce (D':Set V) ∧ T.IsTree ∧ - ∀ z : (D':Set V), z.val ∉ S → 2 ≤ T.degree z := by - classical - induction hn : D.card using Nat.strong_induction_on generalizing D with - | h n ih => - obtain ⟨T,hTH,hT⟩ := hD.exists_isTree_le - by_cases hp : ∀ z : (D:Set V), z.val ∉ S → 2 ≤ T.degree z - · exact ⟨D,Finset.Subset.refl _,hSD,T,hTH,hT,hp⟩ - push Not at hp - obtain ⟨z,hzS,hzdeg⟩ := hp - obtain ⟨s,hs⟩ := hS - have hsz : s ≠ z.val := fun h => hzS (h ▸ hs) - have hnon : Nontrivial (D:Set V) := ⟨⟨⟨s,hSD hs⟩,z,fun he => hsz (congrArg Subtype.val he)⟩⟩ - let := hnon - have hdeg : T.degree z = 1 := by - have hh := hT.connected.preconnected.minDegree_pos_of_nontrivial - have hl := T.minDegree_le_degree z - omega - have hDel := connected_erase_leaf H D T hTH hT.connected z hdeg - have hSD' : S ⊆ D.erase z.val := by - intro a ha - exact Finset.mem_erase.mpr ⟨fun he => hzS (he ▸ ha),hSD ha⟩ - obtain ⟨D',hD'D,hSD',T',hT'H,hT',hpr⟩ := - ih (D.erase z.val).card (by rw [←hn]; exact Finset.card_erase_lt_of_mem z.property) - (D.erase z.val) hSD' hDel rfl - exact ⟨D',hD'D.trans (Finset.erase_subset _ _),hSD',T',hT'H,hT',hpr⟩ - -theorem sum_branchCount_le (H : SimpleGraph V) (S D : Finset V) - (hS : S.Nonempty) (hSD : S ⊆ D) (hD : (H.induce (D:Set V)).Connected) : - (∑ x ∈ S, branchCount H S x) + 2 ≤ 2*S.card := by - classical - obtain ⟨D',_,hSD',T,hTH,hT,hpr⟩ := exists_pruned_connector H S D hS hSD hD - let f : (D':Set V) ↪ V := ⟨Subtype.val,Subtype.val_injective⟩ - have hb (z : (D':Set V)) : branchCount H S z.val ≤ T.degree z := - branchCount_le_degree H T f (fun h => hTH h) hT.connected S - (fun y hy => ⟨⟨y,hSD' hy⟩,rfl⟩) z - have hsum : (∑ z : (D':Set V), if z.val ∈ S then branchCount H S z.val else 2) ≤ - ∑ z : (D':Set V), T.degree z := by - apply Finset.sum_le_sum - intro z _ - split_ifs with hz - · exact hb z - · exact hpr z hz - have hsplit : (∑ z : (D':Set V), if z.val ∈ S then branchCount H S z.val else 2) = - (∑ z ∈ S, branchCount H S z) + 2*(D'.card-S.card) := by - rw [Finset.sum_finset_coe (fun z => if z ∈ S then branchCount H S z else 2) D'] - rw [Finset.sum_ite] - simp only [Finset.filter_mem_eq_inter,Finset.inter_eq_right.mpr hSD', - ←Finset.sdiff_eq_filter] - simp only [Finset.sum_const,smul_eq_mul,Finset.card_sdiff_of_subset hSD',mul_comm] - rw [hsplit,T.sum_degrees_eq_twice_card_edges] at hsum - have hcard := hT.card_edgeFinset - have hDcard : Fintype.card (D':Set V) = D'.card := by simp - rw [hDcard] at hcard - have hle := Finset.card_le_card hSD' - omega - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Cut vertices and connected branches. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open SimpleGraph +universe u w +variable {V : Type u} {W : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +def cutVertex (H : SimpleGraph V) (x : V) : SimpleGraph V where + Adj a b := H.Adj a b ∧ a ≠ x ∧ b ≠ x + symm := ⟨fun _ _ h => ⟨h.1.symm,h.2.2,h.2.1⟩⟩ + loopless := ⟨fun a h => H.loopless.irrefl a h.1⟩ + +noncomputable def branchCount (H : SimpleGraph V) (S : Finset V) (x : V) : ℕ := + ((S.erase x).image (cutVertex H x).connectedComponentMk).card + +theorem walk_reachable_cut (H : SimpleGraph V) (T : SimpleGraph W) + (f : W → V) (hf : ∀ {a b}, T.Adj a b → H.Adj (f a) (f b)) + (x : V) {a b : W} (p : T.Walk a b) + (hp : ∀ z ∈ p.support, f z ≠ x) : + (cutVertex H x).Reachable (f a) (f b) := by + induction p with + | nil => exact .refl _ + | @cons a b c hab p ih => + apply Reachable.trans (Adj.reachable (G := cutVertex H x) ?_) (ih ?_) + · exact ⟨hf hab,hp a (by simp),hp b (by simp [p.start_mem_support])⟩ + · intro z hz + exact hp z (by simp [hz]) + +theorem branchCount_le_degree [Fintype W] (H : SimpleGraph V) (T : SimpleGraph W) + (f : W ↪ V) (hf : ∀ {a b}, T.Adj a b → H.Adj (f a) (f b)) + (hT : T.Connected) (S : Finset V) (hS : ∀ z ∈ S, ∃ y, f y = z) (x : W) : + branchCount H S (f x) ≤ T.degree x := by + classical + let g : W → (cutVertex H (f x)).ConnectedComponent := + fun y => (cutVertex H (f x)).connectedComponentMk (f y) + have hsub : (S.erase (f x)).image (cutVertex H (f x)).connectedComponentMk ⊆ + (T.neighborFinset x).image g := by + intro c hc + obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp hc + obtain ⟨hyx,hzS⟩ := Finset.mem_erase.mp hz + obtain ⟨y,rfl⟩ := hS z hzS + obtain ⟨p,hp⟩ := hT.exists_isPath x y + cases p with + | nil => exact False.elim (hyx rfl) + | @cons x a y hab p => + refine Finset.mem_image.mpr ⟨a,(T.mem_neighborFinset x a).mpr hab,?_⟩ + apply ConnectedComponent.sound + apply walk_reachable_cut H T f hf (f x) p + intro z hz he + have hzx := f.injective he + subst z + exact (List.nodup_cons.mp hp.support_nodup).1 hz + exact (Finset.card_le_card hsub).trans ((Finset.card_image_le).trans (by simp)) + +theorem connected_erase_leaf (H : SimpleGraph V) (D : Finset V) + (T : SimpleGraph (D:Set V)) (hTH : T ≤ H.induce (D:Set V)) + (hT : T.Connected) (z : (D:Set V)) (hz : T.degree z = 1) : + (H.induce ((D.erase z.val):Set V)).Connected := by + let f : ({z}ᶜ : Set (D:Set V)) → ((D.erase z.val):Set V) := + fun y => ⟨y.val.val,Finset.mem_erase.mpr ⟨by + intro h + apply y.property + exact Subtype.ext h,y.val.property⟩⟩ + have hf : Function.Surjective f := by + intro y + refine ⟨⟨⟨y.val,(Finset.mem_erase.mp y.property).2⟩,?_⟩,rfl⟩ + intro h + exact (Finset.mem_erase.mp y.property).1 (congrArg Subtype.val h) + apply (hT.induce_compl_singleton_of_degree_eq_one hz).map (f := ⟨f,?_⟩) hf + intro a b hab + exact hTH hab + +theorem exists_pruned_connector (H : SimpleGraph V) (S D : Finset V) + (hS : S.Nonempty) (hSD : S ⊆ D) (hD : (H.induce (D:Set V)).Connected) : + ∃ D' : Finset V, D' ⊆ D ∧ S ⊆ D' ∧ + ∃ T : SimpleGraph (D':Set V), T ≤ H.induce (D':Set V) ∧ T.IsTree ∧ + ∀ z : (D':Set V), z.val ∉ S → 2 ≤ T.degree z := by + classical + induction hn : D.card using Nat.strong_induction_on generalizing D with + | h n ih => + obtain ⟨T,hTH,hT⟩ := hD.exists_isTree_le + by_cases hp : ∀ z : (D:Set V), z.val ∉ S → 2 ≤ T.degree z + · exact ⟨D,Finset.Subset.refl _,hSD,T,hTH,hT,hp⟩ + push Not at hp + obtain ⟨z,hzS,hzdeg⟩ := hp + obtain ⟨s,hs⟩ := hS + have hsz : s ≠ z.val := fun h => hzS (h ▸ hs) + have hnon : Nontrivial (D:Set V) := ⟨⟨⟨s,hSD hs⟩,z,fun he => hsz (congrArg Subtype.val he)⟩⟩ + let := hnon + have hdeg : T.degree z = 1 := by + have hh := hT.connected.preconnected.minDegree_pos_of_nontrivial + have hl := T.minDegree_le_degree z + omega + have hDel := connected_erase_leaf H D T hTH hT.connected z hdeg + have hSD' : S ⊆ D.erase z.val := by + intro a ha + exact Finset.mem_erase.mpr ⟨fun he => hzS (he ▸ ha),hSD ha⟩ + obtain ⟨D',hD'D,hSD',T',hT'H,hT',hpr⟩ := + ih (D.erase z.val).card (by rw [←hn]; exact Finset.card_erase_lt_of_mem z.property) + (D.erase z.val) hSD' hDel rfl + exact ⟨D',hD'D.trans (Finset.erase_subset _ _),hSD',T',hT'H,hT',hpr⟩ + +theorem sum_branchCount_le (H : SimpleGraph V) (S D : Finset V) + (hS : S.Nonempty) (hSD : S ⊆ D) (hD : (H.induce (D:Set V)).Connected) : + (∑ x ∈ S, branchCount H S x) + 2 ≤ 2*S.card := by + classical + obtain ⟨D',_,hSD',T,hTH,hT,hpr⟩ := exists_pruned_connector H S D hS hSD hD + let f : (D':Set V) ↪ V := ⟨Subtype.val,Subtype.val_injective⟩ + have hb (z : (D':Set V)) : branchCount H S z.val ≤ T.degree z := + branchCount_le_degree H T f (fun h => hTH h) hT.connected S + (fun y hy => ⟨⟨y,hSD' hy⟩,rfl⟩) z + have hsum : (∑ z : (D':Set V), if z.val ∈ S then branchCount H S z.val else 2) ≤ + ∑ z : (D':Set V), T.degree z := by + apply Finset.sum_le_sum + intro z _ + split_ifs with hz + · exact hb z + · exact hpr z hz + have hsplit : (∑ z : (D':Set V), if z.val ∈ S then branchCount H S z.val else 2) = + (∑ z ∈ S, branchCount H S z) + 2*(D'.card-S.card) := by + rw [Finset.sum_finset_coe (fun z => if z ∈ S then branchCount H S z else 2) D'] + rw [Finset.sum_ite] + simp only [Finset.filter_mem_eq_inter,Finset.inter_eq_right.mpr hSD', + ←Finset.sdiff_eq_filter] + simp only [Finset.sum_const,smul_eq_mul,Finset.card_sdiff_of_subset hSD',mul_comm] + rw [hsplit,T.sum_degrees_eq_twice_card_edges] at hsum + have hcard := hT.card_edgeFinset + have hDcard : Fintype.card (D':Set V) = D'.card := by simp + rw [hDcard] at hcard + have hle := Finset.card_le_card hSD' + omega + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/IntrinsicDistance.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/IntrinsicDistance.lean index 39bf58926ce9c7df554507f7670dfc9ac30083a8..d99fec8e948a812387db543196443c8ab636b538 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/IntrinsicDistance.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/IntrinsicDistance.lean @@ -1,208 +1,208 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.Geometry - -namespace OAI - -/-! Intrinsic distance and closest vertices in percolation clusters. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem Along.exists_open_walk_length_le {G : BondGraph V E} {ω : Set E} - {x y : V} {l : List E} (h : Along G x l y) (ho : ∀ e ∈ l, e ∈ ω) : - ∃ w : (openSimpleGraph G ω).Walk x y, w.length ≤ l.length := by - induction h with - | nil => exact ⟨.nil,le_rfl⟩ - | @cons x z y l e he ht ih => - obtain ⟨w,hw⟩ := ih (fun a ha => ho a (by simp [ha])) - by_cases hxz : x = z - · subst z - exact ⟨w,hw.trans (by simp)⟩ - · exact ⟨.cons ⟨hxz,e,ho e (by simp),he⟩ w,by change w.length + 1 ≤ l.length + 1; omega⟩ - -theorem mem_intrinsicBall_iff (G : BondGraph V E) (ω : Set E) (x y : V) (n : ℕ) : - y ∈ intrinsicBall G ω x n ↔ Conn G ω x y ∧ (openSimpleGraph G ω).dist x y ≤ n := by - constructor - · rintro ⟨l,hl,hlen,ho⟩ - obtain ⟨w,hw⟩ := hl.exists_open_walk_length_le ho - exact ⟨hl.conn ho,(SimpleGraph.dist_le w).trans (hw.trans hlen)⟩ - · rintro ⟨h,hn⟩ - obtain ⟨w,hw⟩ := ((conn_iff_reachable G ω x y).mp h).exists_walk_length_eq_dist - obtain ⟨l,hl,hm,ho⟩ := walk_lift_bonds G ω w - refine ⟨l,hl,?_,ho⟩ - have he := congrArg List.length hm - have hh : l.length = (openSimpleGraph G ω).dist x y := by - simpa only [List.length_map,Walk.length_edges,hw] using he - exact hh ▸ hn - -theorem measurableSet_mem_intrinsicBall [Countable E] (G : BondGraph V E) - (x y : V) (n : ℕ) : MeasurableSet {ω | y ∈ intrinsicBall G ω x n} := by - have he : {ω | y ∈ intrinsicBall G ω x n} = - ⋃ (l : List E), {ω | Along G x l y ∧ l.length ≤ n ∧ ∀ e ∈ l, e ∈ ω} := by - ext ω; simp [intrinsicBall] - rw [he] - apply MeasurableSet.iUnion - intro l - by_cases hl : Along G x l y ∧ l.length ≤ n - · have hm : MeasurableSet {ω : Set E | ∀ e ∈ l, e ∈ ω} := by - simpa only [Set.ofPred_forall] using MeasurableSet.iInter (fun e => - MeasurableSet.iInter (fun _ : e ∈ l => (measurableSet_setOfPred.mpr (measurable_set_mem e)))) - simpa [hl.1,hl.2] using hm - · have he : {ω : Set E | Along G x l y ∧ l.length ≤ n ∧ ∀ e ∈ l, e ∈ ω} = ∅ := by - ext ω; simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] - intro h; exact hl ⟨h.1,h.2.1⟩ - rw [he]; exact MeasurableSet.empty - -def closest (H : SimpleGraph V) (A : Set V) (x : V) : Set V := - {y | y ∈ A ∧ H.Reachable x y ∧ ∀ z ∈ A, H.Reachable x z → H.dist x y ≤ H.dist x z} - -theorem closest_finite (G : BondGraph V E) (hloc : LocallyFinite G) (ω : Set E) - (A : Set V) (x : V) : (closest (openSimpleGraph G ω) A x).Finite := by - by_cases he : (closest (openSimpleGraph G ω) A x).Nonempty - · obtain ⟨y,hy⟩ := he - apply (finite_reachBall hloc x ((openSimpleGraph G ω).dist x y)).subset - intro z hz - apply intrinsicBall_subset_reachBall G ω x _ - exact (mem_intrinsicBall_iff G ω x z _).mpr - ⟨(conn_iff_reachable G ω x z).mpr hz.2.1,hz.2.2 y hy.1 hy.2.1⟩ - · exact (Set.not_nonempty_iff_eq_empty.mp he) ▸ Set.finite_empty - -theorem closest_nonempty (H : SimpleGraph V) (A : Set V) (x : V) - (he : ∃ y ∈ A, H.Reachable x y) : (closest H A x).Nonempty := by - let P : ℕ → Prop := fun n => ∃ y ∈ A, H.Reachable x y ∧ H.dist x y = n - have hP : ∃ n, P n := by - obtain ⟨y,hy,hr⟩ := he - exact ⟨H.dist x y,y,hy,hr,rfl⟩ - obtain ⟨y,hy,hr,hd⟩ := Nat.find_spec hP - refine ⟨y,hy,hr,?_⟩ - intro z hz hzr - rw [hd] - exact Nat.find_min' hP ⟨z,hz,hzr,rfl⟩ - -theorem mem_closest_iff_balls (G : BondGraph V E) (ω : Set E) (A : Set V) (x y : V) : - y ∈ closest (openSimpleGraph G ω) A x ↔ y ∈ A ∧ Conn G ω x y ∧ - ∀ n z, z ∈ A → z ∈ intrinsicBall G ω x n → y ∈ intrinsicBall G ω x n := by - constructor - · rintro ⟨hy,hr,hmin⟩ - refine ⟨hy,(conn_iff_reachable G ω x y).mpr hr,?_⟩ - intro n z hz hzb - obtain ⟨hzc,hzd⟩ := (mem_intrinsicBall_iff G ω x z n).mp hzb - exact (mem_intrinsicBall_iff G ω x y n).mpr - ⟨(conn_iff_reachable G ω x y).mpr hr, - (hmin z hz ((conn_iff_reachable G ω x z).mp hzc)).trans hzd⟩ - · rintro ⟨hy,hc,hmin⟩ - refine ⟨hy,(conn_iff_reachable G ω x y).mp hc,?_⟩ - intro z hz hzr - have hzb := (mem_intrinsicBall_iff G ω x z ((openSimpleGraph G ω).dist x z)).mpr - ⟨(conn_iff_reachable G ω x z).mpr hzr,le_rfl⟩ - exact ((mem_intrinsicBall_iff G ω x y _).mp (hmin _ z hz hzb)).2 - -theorem measurableSet_mem_closest [Countable V] [Countable E] - (G : BondGraph V E) (A : Set E → Set V) - (hA : ∀ y, MeasurableSet {ω | y ∈ A ω}) (x y : V) : - MeasurableSet {ω | y ∈ closest (openSimpleGraph G ω) (A ω) x} := by - simp only [mem_closest_iff_balls,Set.ofPred_and,Set.ofPred_forall] - apply (hA y).inter - apply (measurableSet_conn G x y).inter - apply MeasurableSet.iInter - intro n - apply MeasurableSet.iInter - intro z - have he : {ω | z ∈ A ω → z ∈ intrinsicBall G ω x n → y ∈ intrinsicBall G ω x n} = - {ω | z ∈ A ω}ᶜ ∪ {ω | z ∈ intrinsicBall G ω x n}ᶜ ∪ - {ω | y ∈ intrinsicBall G ω x n} := by ext ω; simp; tauto - rw [he] - exact ((hA z).compl.union (measurableSet_mem_intrinsicBall G x z n).compl).union - (measurableSet_mem_intrinsicBall G x y n) - -def openAutIso (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (h : IsAut G a b) (ω : Set E) : - openSimpleGraph G (b ⁻¹' ω) ≃g openSimpleGraph G ω where - toEquiv := a - map_rel_iff' := by - intro x y - constructor - · rintro ⟨hxy,e,he,heq⟩ - refine ⟨fun hh => hxy (congrArg a hh),b.symm e,by simpa using he,?_⟩ - have hh := (isAut_symm G h) e - rw [heq,Sym2.map_mk] at hh - simpa only [Equiv.symm_apply_apply] using hh - · rintro ⟨hxy,e,he,heq⟩ - exact ⟨fun hh => hxy (a.injective hh),b e,he,by rw [h,heq,Sym2.map_mk]⟩ - -theorem iso_dist {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} - (f : H ≃g K) (x y : V) : K.dist (f x) (f y) = H.dist x y := by - by_cases hr : H.Reachable x y - · obtain ⟨w,hw⟩ := hr.exists_walk_length_eq_dist - have hr' := hr.map f.toHom - obtain ⟨w',hw'⟩ := hr'.exists_walk_length_eq_dist - apply le_antisymm - · have hh := SimpleGraph.dist_le (w.map f.toHom) - rw [Walk.length_map,hw] at hh - exact hh - · have hh := SimpleGraph.dist_le (w'.map f.symm.toHom) - rw [Walk.length_map,hw'] at hh - simpa using hh - · have hr' : ¬K.Reachable (f x) (f y) := fun hh => hr (Iso.reachable_iff.mp hh) - simp [SimpleGraph.dist_eq_zero_iff_eq_or_not_reachable.mpr (Or.inr hr), - SimpleGraph.dist_eq_zero_iff_eq_or_not_reachable.mpr (Or.inr hr')] - -theorem closest_iso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} - (f : H ≃g K) (A : Set W) (x y : V) : - y ∈ closest H (f ⁻¹' A) x ↔ f y ∈ closest K A (f x) := by - constructor - · rintro ⟨hy,hr,hmin⟩ - refine ⟨hy,hr.map f.toHom,?_⟩ - intro z hz hzr - obtain ⟨z,rfl⟩ := f.surjective z - simpa only [iso_dist] using hmin z hz (Iso.reachable_iff.mp hzr) - · rintro ⟨hy,hr,hmin⟩ - refine ⟨hy,Iso.reachable_iff.mp hr,?_⟩ - intro z hz hzr - simpa only [iso_dist] using hmin (f z) hz (hzr.map f.toHom) - -theorem dist_lt_of_cut_separates (H : SimpleGraph V) {x y z : V} - (hyr : H.Reachable y z) (hcut : ¬ (cutVertex H x).Reachable y z) - (hxz : x ≠ z) : H.dist y x < H.dist y z := by - obtain ⟨w,hw⟩ := hyr.exists_walk_length_eq_dist - have hmem : x ∈ w.support := by - by_contra hnot - apply hcut - exact walk_reachable_cut H H id (fun h => h) x w - (fun a ha he => hnot (he ▸ ha)) - exact (SimpleGraph.dist_le (w.takeUntil x hmem)).trans_lt - (hw ▸ w.length_takeUntil_lt_length hmem hxz) - -theorem closest_eq_singleton_of_branch (H : SimpleGraph V) (A : Set V) - {x y : V} (hx : x ∈ A) (hy : H.Reachable y x) - (hbranch : ∀ z ∈ A, z ≠ x → ¬ (cutVertex H x).Reachable y z) : - closest H A y = {x} := by - have hstrict (z : V) (hz : z ∈ A) (hne : z ≠ x) (hr : H.Reachable y z) : - H.dist y x < H.dist y z := - dist_lt_of_cut_separates H hr (hbranch z hz hne) hne.symm - ext z - constructor - · intro hz - have he : z = x := by - by_contra hn - exact (not_le_of_gt (hstrict z hz.1 hn hz.2.1)) (hz.2.2 x hx hy) - exact he - · intro hz - have he : z = x := hz - subst z - refine ⟨hx,hy,?_⟩ - intro a ha hr - by_cases he : a = x - · subst a; exact le_rfl - · exact (hstrict a ha he hr).le - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.Geometry + +namespace OAI + +/-! Intrinsic distance and closest vertices in percolation clusters. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem Along.exists_open_walk_length_le {G : BondGraph V E} {ω : Set E} + {x y : V} {l : List E} (h : Along G x l y) (ho : ∀ e ∈ l, e ∈ ω) : + ∃ w : (openSimpleGraph G ω).Walk x y, w.length ≤ l.length := by + induction h with + | nil => exact ⟨.nil,le_rfl⟩ + | @cons x z y l e he ht ih => + obtain ⟨w,hw⟩ := ih (fun a ha => ho a (by simp [ha])) + by_cases hxz : x = z + · subst z + exact ⟨w,hw.trans (by simp)⟩ + · exact ⟨.cons ⟨hxz,e,ho e (by simp),he⟩ w,by change w.length + 1 ≤ l.length + 1; omega⟩ + +theorem mem_intrinsicBall_iff (G : BondGraph V E) (ω : Set E) (x y : V) (n : ℕ) : + y ∈ intrinsicBall G ω x n ↔ Conn G ω x y ∧ (openSimpleGraph G ω).dist x y ≤ n := by + constructor + · rintro ⟨l,hl,hlen,ho⟩ + obtain ⟨w,hw⟩ := hl.exists_open_walk_length_le ho + exact ⟨hl.conn ho,(SimpleGraph.dist_le w).trans (hw.trans hlen)⟩ + · rintro ⟨h,hn⟩ + obtain ⟨w,hw⟩ := ((conn_iff_reachable G ω x y).mp h).exists_walk_length_eq_dist + obtain ⟨l,hl,hm,ho⟩ := walk_lift_bonds G ω w + refine ⟨l,hl,?_,ho⟩ + have he := congrArg List.length hm + have hh : l.length = (openSimpleGraph G ω).dist x y := by + simpa only [List.length_map,Walk.length_edges,hw] using he + exact hh ▸ hn + +theorem measurableSet_mem_intrinsicBall [Countable E] (G : BondGraph V E) + (x y : V) (n : ℕ) : MeasurableSet {ω | y ∈ intrinsicBall G ω x n} := by + have he : {ω | y ∈ intrinsicBall G ω x n} = + ⋃ (l : List E), {ω | Along G x l y ∧ l.length ≤ n ∧ ∀ e ∈ l, e ∈ ω} := by + ext ω; simp [intrinsicBall] + rw [he] + apply MeasurableSet.iUnion + intro l + by_cases hl : Along G x l y ∧ l.length ≤ n + · have hm : MeasurableSet {ω : Set E | ∀ e ∈ l, e ∈ ω} := by + simpa only [Set.ofPred_forall] using MeasurableSet.iInter (fun e => + MeasurableSet.iInter (fun _ : e ∈ l => (measurableSet_setOfPred.mpr (measurable_set_mem e)))) + simpa [hl.1,hl.2] using hm + · have he : {ω : Set E | Along G x l y ∧ l.length ≤ n ∧ ∀ e ∈ l, e ∈ ω} = ∅ := by + ext ω; simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + intro h; exact hl ⟨h.1,h.2.1⟩ + rw [he]; exact MeasurableSet.empty + +def closest (H : SimpleGraph V) (A : Set V) (x : V) : Set V := + {y | y ∈ A ∧ H.Reachable x y ∧ ∀ z ∈ A, H.Reachable x z → H.dist x y ≤ H.dist x z} + +theorem closest_finite (G : BondGraph V E) (hloc : LocallyFinite G) (ω : Set E) + (A : Set V) (x : V) : (closest (openSimpleGraph G ω) A x).Finite := by + by_cases he : (closest (openSimpleGraph G ω) A x).Nonempty + · obtain ⟨y,hy⟩ := he + apply (finite_reachBall hloc x ((openSimpleGraph G ω).dist x y)).subset + intro z hz + apply intrinsicBall_subset_reachBall G ω x _ + exact (mem_intrinsicBall_iff G ω x z _).mpr + ⟨(conn_iff_reachable G ω x z).mpr hz.2.1,hz.2.2 y hy.1 hy.2.1⟩ + · exact (Set.not_nonempty_iff_eq_empty.mp he) ▸ Set.finite_empty + +theorem closest_nonempty (H : SimpleGraph V) (A : Set V) (x : V) + (he : ∃ y ∈ A, H.Reachable x y) : (closest H A x).Nonempty := by + let P : ℕ → Prop := fun n => ∃ y ∈ A, H.Reachable x y ∧ H.dist x y = n + have hP : ∃ n, P n := by + obtain ⟨y,hy,hr⟩ := he + exact ⟨H.dist x y,y,hy,hr,rfl⟩ + obtain ⟨y,hy,hr,hd⟩ := Nat.find_spec hP + refine ⟨y,hy,hr,?_⟩ + intro z hz hzr + rw [hd] + exact Nat.find_min' hP ⟨z,hz,hzr,rfl⟩ + +theorem mem_closest_iff_balls (G : BondGraph V E) (ω : Set E) (A : Set V) (x y : V) : + y ∈ closest (openSimpleGraph G ω) A x ↔ y ∈ A ∧ Conn G ω x y ∧ + ∀ n z, z ∈ A → z ∈ intrinsicBall G ω x n → y ∈ intrinsicBall G ω x n := by + constructor + · rintro ⟨hy,hr,hmin⟩ + refine ⟨hy,(conn_iff_reachable G ω x y).mpr hr,?_⟩ + intro n z hz hzb + obtain ⟨hzc,hzd⟩ := (mem_intrinsicBall_iff G ω x z n).mp hzb + exact (mem_intrinsicBall_iff G ω x y n).mpr + ⟨(conn_iff_reachable G ω x y).mpr hr, + (hmin z hz ((conn_iff_reachable G ω x z).mp hzc)).trans hzd⟩ + · rintro ⟨hy,hc,hmin⟩ + refine ⟨hy,(conn_iff_reachable G ω x y).mp hc,?_⟩ + intro z hz hzr + have hzb := (mem_intrinsicBall_iff G ω x z ((openSimpleGraph G ω).dist x z)).mpr + ⟨(conn_iff_reachable G ω x z).mpr hzr,le_rfl⟩ + exact ((mem_intrinsicBall_iff G ω x y _).mp (hmin _ z hz hzb)).2 + +theorem measurableSet_mem_closest [Countable V] [Countable E] + (G : BondGraph V E) (A : Set E → Set V) + (hA : ∀ y, MeasurableSet {ω | y ∈ A ω}) (x y : V) : + MeasurableSet {ω | y ∈ closest (openSimpleGraph G ω) (A ω) x} := by + simp only [mem_closest_iff_balls,Set.ofPred_and,Set.ofPred_forall] + apply (hA y).inter + apply (measurableSet_conn G x y).inter + apply MeasurableSet.iInter + intro n + apply MeasurableSet.iInter + intro z + have he : {ω | z ∈ A ω → z ∈ intrinsicBall G ω x n → y ∈ intrinsicBall G ω x n} = + {ω | z ∈ A ω}ᶜ ∪ {ω | z ∈ intrinsicBall G ω x n}ᶜ ∪ + {ω | y ∈ intrinsicBall G ω x n} := by ext ω; simp; tauto + rw [he] + exact ((hA z).compl.union (measurableSet_mem_intrinsicBall G x z n).compl).union + (measurableSet_mem_intrinsicBall G x y n) + +def openAutIso (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (h : IsAut G a b) (ω : Set E) : + openSimpleGraph G (b ⁻¹' ω) ≃g openSimpleGraph G ω where + toEquiv := a + map_rel_iff' := by + intro x y + constructor + · rintro ⟨hxy,e,he,heq⟩ + refine ⟨fun hh => hxy (congrArg a hh),b.symm e,by simpa using he,?_⟩ + have hh := (isAut_symm G h) e + rw [heq,Sym2.map_mk] at hh + simpa only [Equiv.symm_apply_apply] using hh + · rintro ⟨hxy,e,he,heq⟩ + exact ⟨fun hh => hxy (a.injective hh),b e,he,by rw [h,heq,Sym2.map_mk]⟩ + +theorem iso_dist {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} + (f : H ≃g K) (x y : V) : K.dist (f x) (f y) = H.dist x y := by + by_cases hr : H.Reachable x y + · obtain ⟨w,hw⟩ := hr.exists_walk_length_eq_dist + have hr' := hr.map f.toHom + obtain ⟨w',hw'⟩ := hr'.exists_walk_length_eq_dist + apply le_antisymm + · have hh := SimpleGraph.dist_le (w.map f.toHom) + rw [Walk.length_map,hw] at hh + exact hh + · have hh := SimpleGraph.dist_le (w'.map f.symm.toHom) + rw [Walk.length_map,hw'] at hh + simpa using hh + · have hr' : ¬K.Reachable (f x) (f y) := fun hh => hr (Iso.reachable_iff.mp hh) + simp [SimpleGraph.dist_eq_zero_iff_eq_or_not_reachable.mpr (Or.inr hr), + SimpleGraph.dist_eq_zero_iff_eq_or_not_reachable.mpr (Or.inr hr')] + +theorem closest_iso {W : Type*} {H : SimpleGraph V} {K : SimpleGraph W} + (f : H ≃g K) (A : Set W) (x y : V) : + y ∈ closest H (f ⁻¹' A) x ↔ f y ∈ closest K A (f x) := by + constructor + · rintro ⟨hy,hr,hmin⟩ + refine ⟨hy,hr.map f.toHom,?_⟩ + intro z hz hzr + obtain ⟨z,rfl⟩ := f.surjective z + simpa only [iso_dist] using hmin z hz (Iso.reachable_iff.mp hzr) + · rintro ⟨hy,hr,hmin⟩ + refine ⟨hy,Iso.reachable_iff.mp hr,?_⟩ + intro z hz hzr + simpa only [iso_dist] using hmin (f z) hz (hzr.map f.toHom) + +theorem dist_lt_of_cut_separates (H : SimpleGraph V) {x y z : V} + (hyr : H.Reachable y z) (hcut : ¬ (cutVertex H x).Reachable y z) + (hxz : x ≠ z) : H.dist y x < H.dist y z := by + obtain ⟨w,hw⟩ := hyr.exists_walk_length_eq_dist + have hmem : x ∈ w.support := by + by_contra hnot + apply hcut + exact walk_reachable_cut H H id (fun h => h) x w + (fun a ha he => hnot (he ▸ ha)) + exact (SimpleGraph.dist_le (w.takeUntil x hmem)).trans_lt + (hw ▸ w.length_takeUntil_lt_length hmem hxz) + +theorem closest_eq_singleton_of_branch (H : SimpleGraph V) (A : Set V) + {x y : V} (hx : x ∈ A) (hy : H.Reachable y x) + (hbranch : ∀ z ∈ A, z ≠ x → ¬ (cutVertex H x).Reachable y z) : + closest H A y = {x} := by + have hstrict (z : V) (hz : z ∈ A) (hne : z ≠ x) (hr : H.Reachable y z) : + H.dist y x < H.dist y z := + dist_lt_of_cut_separates H hr (hbranch z hz hne) hne.symm + ext z + constructor + · intro hz + have he : z = x := by + by_contra hn + exact (not_le_of_gt (hstrict z hz.1 hn hz.2.1)) (hz.2.2 x hx hy) + exact he + · intro hz + have he : z = x := hz + subst z + refine ⟨hx,hy,?_⟩ + intro a ha hr + by_cases he : a = x + · subst a; exact le_rfl + · exact (hstrict a ha he hr).le + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Measurability.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Measurability.lean index 87be26baf5b8776900b0079974dd19f376bbf9f5..75c395c24ce89b3273c41ea331a2e71527dd3db9 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Measurability.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Measurability.lean @@ -1,123 +1,123 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.Vertices - -namespace OAI - -/-! Measurability of branches and finite clusters. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem card_image_eq_minima [Encodable V] {W : Type*} (S : Finset V) (f : V → W) : - (S.image f).card = - (S.filter (fun y => ∀ z ∈ S, f z = f y → Encodable.encode y ≤ Encodable.encode z)).card := by - let R := S.filter (fun y => ∀ z ∈ S, f z = f y → Encodable.encode y ≤ Encodable.encode z) - have hRS : R ⊆ S := Finset.filter_subset _ _ - have hinj : Set.InjOn f (R:Set V) := by - intro y hy z hz he - apply Encodable.encode_injective - exact le_antisymm ((Finset.mem_filter.mp hy).2 z (hRS hz) he.symm) - ((Finset.mem_filter.mp hz).2 y (hRS hy) he) - have he : R.image f = S.image f := by - apply Finset.Subset.antisymm (Finset.image_subset_image hRS) - intro c hc - obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hc - obtain ⟨z,hz,hmin⟩ := (S.filter (fun z => f z = f y)).exists_min_image - Encodable.encode ⟨y,Finset.mem_filter.mpr ⟨hy,rfl⟩⟩ - refine Finset.mem_image.mpr ⟨z,Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hz).1,?_⟩, - (Finset.mem_filter.mp hz).2⟩ - intro w hw hwe - exact hmin w (Finset.mem_filter.mpr ⟨hw,hwe.trans (Finset.mem_filter.mp hz).2⟩) - rw [←he] - exact Finset.card_image_iff.mpr hinj - -theorem measurable_branchCount [Countable V] [Countable E] - (G : BondGraph V E) (S : Finset V) (x : V) : - Measurable (fun ω => branchCount (openSimpleGraph G ω) S x) := by - let : Encodable V := Encodable.ofCountable V - have he (ω : Set E) : branchCount (openSimpleGraph G ω) S x = - ∑ y ∈ S.erase x, if (∀ z ∈ S.erase x, Conn G (cutConfig G ω x) z y → - Encodable.encode y ≤ Encodable.encode z) then 1 else 0 := by - rw [branchCount,card_image_eq_minima,Finset.card_filter] - apply Finset.sum_congr rfl - intro y _ - simp only [ConnectedComponent.eq,cutVertex_open,←conn_iff_reachable] - simp_rw [he] - apply Finset.measurable_sum - intro y hy - apply Measurable.ite _ measurable_const measurable_const - have he' : {ω : Set E | ∀ z ∈ S.erase x, Conn G (cutConfig G ω x) z y → - Encodable.encode y ≤ Encodable.encode z} = - ⋂ z ∈ S.erase x, ({ω | Conn G (cutConfig G ω x) z y}ᶜ ∪ - {ω : Set E | Encodable.encode y ≤ Encodable.encode z}) := by ext ω; simp [imp_iff_not_or] - rw [he'] - apply MeasurableSet.iInter - intro z - apply MeasurableSet.iInter - intro _ - exact ((measurableSet_conn G z y).preimage (measurable_cutConfig G x)).compl.union - (by by_cases hh : Encodable.encode y ≤ Encodable.encode z <;> simp [hh]) - -noncomputable def clusterFinset (G : BondGraph V E) (ω : Set E) (x : V) : Finset V := - if h : (cluster G ω x).Finite then h.toFinset else ∅ - -theorem clusterFinset_coe (G : BondGraph V E) (ω : Set E) (x : V) - (h : (cluster G ω x).Finite) : (clusterFinset G ω x : Set V) = cluster G ω x := by - simp [clusterFinset,h] - -theorem measurable_clusterFinset [Countable V] [Countable E] - (G : BondGraph V E) (x : V) : Measurable (fun ω => clusterFinset G ω x) := by - apply measurable_to_countable - intro ω₀ - let S := clusterFinset G ω₀ x - have he : {ω | clusterFinset G ω x = S} = - {ω | cluster G ω x = (S:Set V)} ∪ - ({ω | (cluster G ω x).Infinite} ∩ {ω : Set E | S = ∅}) := by - ext ω - by_cases h : (cluster G ω x).Finite - · simp only [Set.mem_ofPred,Set.mem_union,Set.mem_inter_iff,clusterFinset,dite_eq_left h] - simp only [Set.Infinite,h,not_true_eq_false,false_and,or_false] - constructor - · intro he; rw [←he,h.coe_toFinset] - · intro he; exact Finset.coe_injective (h.coe_toFinset.trans he) - · simp only [Set.mem_ofPred,Set.mem_union,Set.mem_inter_iff,clusterFinset,dite_eq_right h] - have hn : cluster G ω x ≠ (S:Set V) := fun he => h (he ▸ S.finite_toSet) - simp [hn,Set.Infinite,h,eq_comm] - change MeasurableSet {ω | clusterFinset G ω x = S} - rw [he] - exact (measurableSet_cluster_eq G x (S:Set V)).union - ((measurableSet_infinite_cluster G x).inter (by by_cases hs : S = ∅ <;> simp [hs])) - -theorem measurable_filter_finset {Ω : Type*} [MeasurableSpace Ω] [Countable V] - (S : Ω → Finset V) (hS : Measurable S) (P : Ω → V → Prop) - (hP : ∀ x, MeasurableSet {ω | P ω x}) : - Measurable (fun ω => (S ω).filter (P ω)) := by - have hf (D : Finset V) : Measurable (fun ω => D.filter (P ω)) := by - apply measurable_to_countable - intro ω₀ - have he : {ω | D.filter (P ω) = D.filter (P ω₀)} = - ⋂ y, {ω | (y ∈ D ∧ P ω y) ↔ y ∈ D.filter (P ω₀)} := by - ext ω; simp only [Set.mem_ofPred_eq,Set.mem_iInter,Finset.ext_iff,Finset.mem_filter] - change MeasurableSet {ω | D.filter (P ω) = D.filter (P ω₀)} - rw [he] - apply MeasurableSet.iInter - intro y - by_cases hy : y ∈ D - · by_cases hp : P ω₀ y <;> simp only [hy,hp,Finset.mem_filter,true_and,iff_true,iff_false] - · exact hP y - · exact (hP y).compl - · simp [hy] - have hm : Measurable (fun z : Ω × Finset V => z.2.filter (P z.1)) := - measurable_from_prod_countable_left hf - exact hm.comp (measurable_id.prodMk hS) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.Vertices + +namespace OAI + +/-! Measurability of branches and finite clusters. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem card_image_eq_minima [Encodable V] {W : Type*} (S : Finset V) (f : V → W) : + (S.image f).card = + (S.filter (fun y => ∀ z ∈ S, f z = f y → Encodable.encode y ≤ Encodable.encode z)).card := by + let R := S.filter (fun y => ∀ z ∈ S, f z = f y → Encodable.encode y ≤ Encodable.encode z) + have hRS : R ⊆ S := Finset.filter_subset _ _ + have hinj : Set.InjOn f (R:Set V) := by + intro y hy z hz he + apply Encodable.encode_injective + exact le_antisymm ((Finset.mem_filter.mp hy).2 z (hRS hz) he.symm) + ((Finset.mem_filter.mp hz).2 y (hRS hy) he) + have he : R.image f = S.image f := by + apply Finset.Subset.antisymm (Finset.image_subset_image hRS) + intro c hc + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hc + obtain ⟨z,hz,hmin⟩ := (S.filter (fun z => f z = f y)).exists_min_image + Encodable.encode ⟨y,Finset.mem_filter.mpr ⟨hy,rfl⟩⟩ + refine Finset.mem_image.mpr ⟨z,Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hz).1,?_⟩, + (Finset.mem_filter.mp hz).2⟩ + intro w hw hwe + exact hmin w (Finset.mem_filter.mpr ⟨hw,hwe.trans (Finset.mem_filter.mp hz).2⟩) + rw [←he] + exact Finset.card_image_iff.mpr hinj + +theorem measurable_branchCount [Countable V] [Countable E] + (G : BondGraph V E) (S : Finset V) (x : V) : + Measurable (fun ω => branchCount (openSimpleGraph G ω) S x) := by + let : Encodable V := Encodable.ofCountable V + have he (ω : Set E) : branchCount (openSimpleGraph G ω) S x = + ∑ y ∈ S.erase x, if (∀ z ∈ S.erase x, Conn G (cutConfig G ω x) z y → + Encodable.encode y ≤ Encodable.encode z) then 1 else 0 := by + rw [branchCount,card_image_eq_minima,Finset.card_filter] + apply Finset.sum_congr rfl + intro y _ + simp only [ConnectedComponent.eq,cutVertex_open,←conn_iff_reachable] + simp_rw [he] + apply Finset.measurable_sum + intro y hy + apply Measurable.ite _ measurable_const measurable_const + have he' : {ω : Set E | ∀ z ∈ S.erase x, Conn G (cutConfig G ω x) z y → + Encodable.encode y ≤ Encodable.encode z} = + ⋂ z ∈ S.erase x, ({ω | Conn G (cutConfig G ω x) z y}ᶜ ∪ + {ω : Set E | Encodable.encode y ≤ Encodable.encode z}) := by ext ω; simp [imp_iff_not_or] + rw [he'] + apply MeasurableSet.iInter + intro z + apply MeasurableSet.iInter + intro _ + exact ((measurableSet_conn G z y).preimage (measurable_cutConfig G x)).compl.union + (by by_cases hh : Encodable.encode y ≤ Encodable.encode z <;> simp [hh]) + +noncomputable def clusterFinset (G : BondGraph V E) (ω : Set E) (x : V) : Finset V := + if h : (cluster G ω x).Finite then h.toFinset else ∅ + +theorem clusterFinset_coe (G : BondGraph V E) (ω : Set E) (x : V) + (h : (cluster G ω x).Finite) : (clusterFinset G ω x : Set V) = cluster G ω x := by + simp [clusterFinset,h] + +theorem measurable_clusterFinset [Countable V] [Countable E] + (G : BondGraph V E) (x : V) : Measurable (fun ω => clusterFinset G ω x) := by + apply measurable_to_countable + intro ω₀ + let S := clusterFinset G ω₀ x + have he : {ω | clusterFinset G ω x = S} = + {ω | cluster G ω x = (S:Set V)} ∪ + ({ω | (cluster G ω x).Infinite} ∩ {ω : Set E | S = ∅}) := by + ext ω + by_cases h : (cluster G ω x).Finite + · simp only [Set.mem_ofPred,Set.mem_union,Set.mem_inter_iff,clusterFinset,dite_eq_left h] + simp only [Set.Infinite,h,not_true_eq_false,false_and,or_false] + constructor + · intro he; rw [←he,h.coe_toFinset] + · intro he; exact Finset.coe_injective (h.coe_toFinset.trans he) + · simp only [Set.mem_ofPred,Set.mem_union,Set.mem_inter_iff,clusterFinset,dite_eq_right h] + have hn : cluster G ω x ≠ (S:Set V) := fun he => h (he ▸ S.finite_toSet) + simp [hn,Set.Infinite,h,eq_comm] + change MeasurableSet {ω | clusterFinset G ω x = S} + rw [he] + exact (measurableSet_cluster_eq G x (S:Set V)).union + ((measurableSet_infinite_cluster G x).inter (by by_cases hs : S = ∅ <;> simp [hs])) + +theorem measurable_filter_finset {Ω : Type*} [MeasurableSpace Ω] [Countable V] + (S : Ω → Finset V) (hS : Measurable S) (P : Ω → V → Prop) + (hP : ∀ x, MeasurableSet {ω | P ω x}) : + Measurable (fun ω => (S ω).filter (P ω)) := by + have hf (D : Finset V) : Measurable (fun ω => D.filter (P ω)) := by + apply measurable_to_countable + intro ω₀ + have he : {ω | D.filter (P ω) = D.filter (P ω₀)} = + ⋂ y, {ω | (y ∈ D ∧ P ω y) ↔ y ∈ D.filter (P ω₀)} := by + ext ω; simp only [Set.mem_ofPred_eq,Set.mem_iInter,Finset.ext_iff,Finset.mem_filter] + change MeasurableSet {ω | D.filter (P ω) = D.filter (P ω₀)} + rw [he] + apply MeasurableSet.iInter + intro y + by_cases hy : y ∈ D + · by_cases hp : P ω₀ y <;> simp only [hy,hp,Finset.mem_filter,true_and,iff_true,iff_false] + · exact hP y + · exact (hP y).compl + · simp [hy] + have hm : Measurable (fun z : Ω × Finset V => z.2.filter (P z.1)) := + measurable_from_prod_countable_left hf + exact hm.comp (measurable_id.prodMk hS) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/NearestMass.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/NearestMass.lean index 6028555f4369b3dd11c42d0c4f6706095347c744..5c86ae45579c00023d85c4a474bbbe46e5cf61e8 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/NearestMass.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/NearestMass.lean @@ -1,88 +1,88 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.IntrinsicDistance - -namespace OAI - -/-! Nearest-vertex transport and its finite incoming mass. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def nearestMass (G : BondGraph V E) (A : Set E → Set V) - (ω : Set E) (x y : V) : ℝ≥0∞ := - if y ∈ closest (openSimpleGraph G ω) (A ω) x then - ((closest (openSimpleGraph G ω) (A ω) x).ncard : ℝ≥0∞)⁻¹ else 0 - -theorem measurable_nearestMass [Countable V] [Countable E] - (G : BondGraph V E) (A : Set E → Set V) - (hA : ∀ y, MeasurableSet {ω | y ∈ A ω}) (x y : V) : - Measurable (fun ω => nearestMass G A ω x y) := by - have hm : Measurable (fun ω => closest (openSimpleGraph G ω) (A ω) x) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro z - exact measurableSet_setOfPred.mp (measurableSet_mem_closest G A hA x z) - exact Measurable.ite (measurableSet_mem_closest G A hA x y) - (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_ncard.comp hm)).inv) measurable_const - -theorem nearestMass_row_le (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Set E → Set V) (ω : Set E) (x : V) : - ∑' y, nearestMass G A ω x y ≤ 1 := by - let S := closest (openSimpleGraph G ω) (A ω) x - have hf := closest_finite G hloc ω (A ω) x - rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by - simp only [nearestMass,ite_eq_right (fun hh => hy (hf.mem_toFinset.mpr hh))])] - simp only [nearestMass] - have he : (∑ y ∈ hf.toFinset, if y ∈ S then (S.ncard : ℝ≥0∞)⁻¹ else 0) = - (S.ncard : ℝ≥0∞) * (S.ncard : ℝ≥0∞)⁻¹ := by - calc - _ = ∑ _y ∈ hf.toFinset, (S.ncard : ℝ≥0∞)⁻¹ := by - apply Finset.sum_congr rfl - intro y hy - rw [ite_eq_left (hf.mem_toFinset.mp hy)] - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,←Set.ncard_eq_toFinset_card _ hf,S] - change (∑ y ∈ hf.toFinset, if y ∈ S then (S.ncard : ℝ≥0∞)⁻¹ else 0) ≤ 1 - rw [he] - exact ENNReal.mul_inv_le_one _ - -theorem nearestMass_aut (G : BondGraph V E) (A : Set E → Set V) - (hA : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x, - x ∈ A (b ⁻¹' ω) ↔ a x ∈ A ω) - (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x y : V) : - nearestMass G A (b ⁻¹' ω) x y = nearestMass G A ω (a x) (a y) := by - have heA : A (b ⁻¹' ω) = a ⁻¹' A ω := by ext z; exact hA a b hab ω z - have heS : closest (openSimpleGraph G (b ⁻¹' ω)) (A (b ⁻¹' ω)) x = - a ⁻¹' closest (openSimpleGraph G ω) (A ω) (a x) := by - rw [heA] - ext z - exact closest_iso (openAutIso G a b hab ω) (A ω) x z - simp only [nearestMass,heS,Set.mem_preimage] - rw [Set.ncard_preimage_of_injective_subset_range a.injective (by simp)] - -theorem nearestMass_eq_one (G : BondGraph V E) (A : Set E → Set V) - (ω : Set E) (x y : V) - (h : closest (openSimpleGraph G ω) (A ω) x = {y}) : - nearestMass G A ω x y = 1 := by simp [nearestMass,h] - -theorem incoming_top_of_infinite (m : V → ℝ≥0∞) (B : Set V) - (hB : B.Infinite) (hm : ∀ x ∈ B, m x = 1) : ∑' x, m x = ⊤ := by - let : Infinite B := hB.to_subtype - apply top_unique - calc - ⊤ = ∑' x : B, (1:ℝ≥0∞) := (ENNReal.tsum_const_eq_top_of_ne_zero one_ne_zero).symm - _ = ∑' x : B, m x.val := tsum_congr (fun x => (hm x.val x.property).symm) - _ = ∑' x, B.indicator m x := tsum_subtype B m - _ ≤ ∑' x, m x := ENNReal.tsum_le_tsum (fun x => by - by_cases hx : x ∈ B <;> simp [Set.indicator,hx]) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.IntrinsicDistance + +namespace OAI + +/-! Nearest-vertex transport and its finite incoming mass. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def nearestMass (G : BondGraph V E) (A : Set E → Set V) + (ω : Set E) (x y : V) : ℝ≥0∞ := + if y ∈ closest (openSimpleGraph G ω) (A ω) x then + ((closest (openSimpleGraph G ω) (A ω) x).ncard : ℝ≥0∞)⁻¹ else 0 + +theorem measurable_nearestMass [Countable V] [Countable E] + (G : BondGraph V E) (A : Set E → Set V) + (hA : ∀ y, MeasurableSet {ω | y ∈ A ω}) (x y : V) : + Measurable (fun ω => nearestMass G A ω x y) := by + have hm : Measurable (fun ω => closest (openSimpleGraph G ω) (A ω) x) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro z + exact measurableSet_setOfPred.mp (measurableSet_mem_closest G A hA x z) + exact Measurable.ite (measurableSet_mem_closest G A hA x y) + (((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp (measurable_ncard.comp hm)).inv) measurable_const + +theorem nearestMass_row_le (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Set E → Set V) (ω : Set E) (x : V) : + ∑' y, nearestMass G A ω x y ≤ 1 := by + let S := closest (openSimpleGraph G ω) (A ω) x + have hf := closest_finite G hloc ω (A ω) x + rw [tsum_eq_sum (s := hf.toFinset) (fun y hy => by + simp only [nearestMass,ite_eq_right (fun hh => hy (hf.mem_toFinset.mpr hh))])] + simp only [nearestMass] + have he : (∑ y ∈ hf.toFinset, if y ∈ S then (S.ncard : ℝ≥0∞)⁻¹ else 0) = + (S.ncard : ℝ≥0∞) * (S.ncard : ℝ≥0∞)⁻¹ := by + calc + _ = ∑ _y ∈ hf.toFinset, (S.ncard : ℝ≥0∞)⁻¹ := by + apply Finset.sum_congr rfl + intro y hy + rw [ite_eq_left (hf.mem_toFinset.mp hy)] + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,←Set.ncard_eq_toFinset_card _ hf,S] + change (∑ y ∈ hf.toFinset, if y ∈ S then (S.ncard : ℝ≥0∞)⁻¹ else 0) ≤ 1 + rw [he] + exact ENNReal.mul_inv_le_one _ + +theorem nearestMass_aut (G : BondGraph V E) (A : Set E → Set V) + (hA : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x, + x ∈ A (b ⁻¹' ω) ↔ a x ∈ A ω) + (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x y : V) : + nearestMass G A (b ⁻¹' ω) x y = nearestMass G A ω (a x) (a y) := by + have heA : A (b ⁻¹' ω) = a ⁻¹' A ω := by ext z; exact hA a b hab ω z + have heS : closest (openSimpleGraph G (b ⁻¹' ω)) (A (b ⁻¹' ω)) x = + a ⁻¹' closest (openSimpleGraph G ω) (A ω) (a x) := by + rw [heA] + ext z + exact closest_iso (openAutIso G a b hab ω) (A ω) x z + simp only [nearestMass,heS,Set.mem_preimage] + rw [Set.ncard_preimage_of_injective_subset_range a.injective (by simp)] + +theorem nearestMass_eq_one (G : BondGraph V E) (A : Set E → Set V) + (ω : Set E) (x y : V) + (h : closest (openSimpleGraph G ω) (A ω) x = {y}) : + nearestMass G A ω x y = 1 := by simp [nearestMass,h] + +theorem incoming_top_of_infinite (m : V → ℝ≥0∞) (B : Set V) + (hB : B.Infinite) (hm : ∀ x ∈ B, m x = 1) : ∑' x, m x = ⊤ := by + let : Infinite B := hB.to_subtype + apply top_unique + calc + ⊤ = ∑' x : B, (1:ℝ≥0∞) := (ENNReal.tsum_const_eq_top_of_ne_zero one_ne_zero).symm + _ = ∑' x : B, m x.val := tsum_congr (fun x => (hm x.val x.property).symm) + _ = ∑' x, B.indicator m x := tsum_subtype B m + _ ≤ ∑' x, m x := ENNReal.tsum_le_tsum (fun x => by + by_cases hx : x ∈ B <;> simp [Set.indicator,hx]) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Surgery.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Surgery.lean index 07321b98a53989004d6d2a7f6f69f45eefbc50c0..c1871864974a8709b6ce9b59802e5207083ed04f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Surgery.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Surgery.lean @@ -1,231 +1,231 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Criticality.FiniteChanges -import OAI.Probability.UnimodularPercolation.Encounter.Counts -import OAI.Probability.UnimodularPercolation.Encounter.TreeBranches - -namespace OAI - -/-! Exterior branches and finite encounter surgery. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem infinite_cluster_sdiff_contains (G : BondGraph V E) (ω : Set E) - (F : Set E) (hF : F.Finite) (x : V) (hx : (cluster G ω x).Infinite) : - ∃ z, Conn G ω x z ∧ (cluster G (ω \ F) z).Infinite := by - have he : (ω \ F) ∪ (ω ∩ F) = ω := by ext e; simp only [Set.mem_union,Set.mem_sdiff,Set.mem_inter_iff]; tauto - obtain ⟨z,hz,hzi⟩ := infinite_cluster_union_contains G (ω \ F) (ω ∩ F) (hF.inter_of_right ω) x (by rw [he]; exact hx) - exact ⟨z,by simpa only [he] using hz,hzi⟩ - -theorem conn_eq_of_no_incident (G : BondGraph V E) (ω : Set E) (x y : V) - (hx : ∀ e ∈ ω, x ∉ G e) (hxy : Conn G ω x y) : y = x := by - induction hxy with - | refl => rfl - | @tail y z hy hed ih => - obtain ⟨e,he,hGe⟩ := hed - exact False.elim (hx e he (by rw [hGe,ih]; simp)) - -theorem cluster_singleton_of_no_incident (G : BondGraph V E) (ω : Set E) (x : V) - (hx : ∀ e ∈ ω, x ∉ G e) : cluster G ω x = {x} := by - ext y - constructor - · intro h; exact conn_eq_of_no_incident G ω x y hx h - · rintro rfl; exact mem_cluster_self G ω _ - -theorem deleted_cluster_singleton (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) : - cluster G (ω \ (incidentSupport G hloc A:Set E)) x = {x} := by - apply cluster_singleton_of_no_incident - intro e he hxe - exact he.2 ((mem_incidentSupport G hloc A e).mpr ⟨x,hx,hxe⟩) - -theorem conn_exterior_attachment (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) {z : V} (hxz : Conn G ω x z) : - z ∈ A ∨ ∃ v ∈ A, ∃ w, w ∉ A ∧ ∃ e ∈ ω, G e = s(v,w) ∧ - Conn G (ω \ (incidentSupport G hloc A:Set E)) w z := by - induction hxz with - | refl => exact Or.inl hx - | @tail y z hy hed ih => - by_cases hz : z ∈ A - · exact Or.inl hz - right - obtain ⟨e,he,hGe⟩ := hed - rcases ih with hyA | ⟨v,hv,w,hw,f,hf,hGf,hwy⟩ - · exact ⟨y,hyA,z,hz,e,he,hGe,conn_refl G _ z⟩ - · have hyA : y ∉ A := by - intro hya - have hs := deleted_cluster_singleton G hloc ω A y hya - have hyy : w ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) y := conn_symm G _ hwy - rw [hs] at hyy - exact hw (hyy ▸ hya) - refine ⟨v,hv,w,hw,f,hf,hGf,hwy.tail ⟨e,⟨he,?_⟩,hGe⟩⟩ - intro hei - obtain ⟨a,ha,hage⟩ := (mem_incidentSupport G hloc A e).mp hei - rw [hGe,Sym2.mem_iff] at hage - rcases hage with rfl | rfl - · exact hyA ha - · exact hz ha - -theorem infinite_exterior_attachment (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) (hi : (cluster G ω x).Infinite) : - ∃ v ∈ A, ∃ w, w ∉ A ∧ ∃ e ∈ ω, G e = s(v,w) ∧ Conn G ω x w ∧ - (cluster G (ω \ (incidentSupport G hloc A:Set E)) w).Infinite := by - obtain ⟨z,hxz,hz⟩ := infinite_cluster_sdiff_contains G ω _ (incidentSupport G hloc A).finite_toSet x hi - have hn : z ∉ A := by - intro hzA - rw [deleted_cluster_singleton G hloc ω A z hzA] at hz - exact hz (Set.finite_singleton z) - obtain ⟨v,hv,w,hw,e,he,hGe,hwz⟩ := (conn_exterior_attachment G hloc ω A x hx hxz).resolve_left hn - refine ⟨v,hv,w,hw,e,he,hGe,conn_trans G ω hxz (conn_symm G ω (conn_mono G Set.sdiff_subset hwz)),?_⟩ - rwa [cluster_eq_of_conn G _ hwz] - -theorem exists_finite_connected_envelope (G : BondGraph V E) (hconn : Connected G) - (x : V) (R : Finset V) : ∃ A : Finset V, R ⊆ A ∧ - ((openSimpleGraph G Set.univ).induce (A:Set V)).Connected := by - obtain ⟨F,hF⟩ := finite_connecting_edges G hconn x R - have hf := cluster_finite_of_finite_edges G F.finite_toSet x - refine ⟨hf.toFinset,?_,?_⟩ - · intro y hy - exact hf.mem_toFinset.mpr (hF y hy) - · rw [hf.coe_toFinset] - exact cluster_induce_connected G Set.univ (F:Set E) (Set.subset_univ _) x -end Percolation - -namespace Percolation -open SimpleGraph -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem deleted_envelope_separated (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (A : Finset V) (w : Fin 3 → V) - (hsep : ∀ i j, Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j) → i = j) - (a b : V) (ha : a ∈ A ∪ Finset.univ.image w) (hb : b ∈ A ∪ Finset.univ.image w) - (hab : Conn G (ω \ (incidentSupport G hloc A:Set E)) a b) : a = b := by - rcases Finset.mem_union.mp ha with ha | ha - · have hh := deleted_cluster_singleton G hloc ω A a ha - have hm : b ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) a := hab - rw [hh] at hm - exact hm.symm - rcases Finset.mem_union.mp hb with hb | hb - · have hh := deleted_cluster_singleton G hloc ω A b hb - have hm : a ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) b := conn_symm G _ hab - rw [hh] at hm - exact hm - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp ha - obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hb - exact congrArg w (hsep i j hab) - -theorem encounter_surgery_of_attachments (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (A : Finset V) (v w : Fin 3 → V) - (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) - (hadj : ∀ i, (openSimpleGraph G Set.univ).Adj (v i) (w i)) - (hA : ((openSimpleGraph G Set.univ).induce (A:Set V)).Connected) - (hsep : ∀ i j, Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j) → i = j) - (hinf : ∀ i, (cluster G (ω \ (incidentSupport G hloc A:Set E)) (w i)).Infinite) : - ∃ P : Finset E, P ⊆ incidentSupport G hloc A ∧ - ∃ x, IsEncounter G (finiteOverwrite (incidentSupport G hloc A) P ω) x := by - obtain ⟨D,hD,hSD,T,hTK,hT,x,a,b,c,hx,ha,hb,hc,hab,hac,hbc⟩ := - exists_terminal_tree (openSimpleGraph G Set.univ) A v w hv hw hwi hadj hA - let F := incidentSupport G hloc A - let η := ω \ (F:Set E) - let f : (D:Set V) ↪ V := ⟨Subtype.val,Subtype.val_injective⟩ - let P := F.filter (fun e => ∃ a b : (D:Set V), T.Adj a b ∧ G e = s(a.val,b.val)) - have hPF : P ⊆ F := Finset.filter_subset _ _ - have hP (e : E) (he : e ∈ P) : ∃ a b, T.Adj a b ∧ G e = s(f a,f b) := - (Finset.mem_filter.mp he).2 - have hPres (a b : (D:Set V)) (hab : T.Adj a b) : ∃ e ∈ (P:Set E), G e = s(f a,f b) := by - have hk := hTK hab - obtain ⟨e,_,he⟩ := hk.1.2 - refine ⟨e,Finset.mem_filter.mpr ⟨?_,⟨a,b,hab,he⟩⟩,he⟩ - apply (mem_incidentSupport G hloc A e).mpr - rcases terminalGraph_touch _ A v w hv hk with ha | hb - · exact ⟨a.val,ha,by rw [he]; simp⟩ - · exact ⟨b.val,hb,by rw [he]; simp⟩ - have hsepD (a b : (D:Set V)) (h : Conn G η (f a) (f b)) : a = b := by - apply Subtype.ext - exact deleted_envelope_separated G hloc ω A w hsep a.val b.val (hD a.property) (hD b.property) h - obtain ⟨r,hr,hrη⟩ := exists_cluster_retraction G η f hsepD x - have hr' (a : (D:Set V)) : r a.val = a := hr a - have hcut : η ⊆ cutConfig G (η ∪ (P:Set E)) x.val := by - intro e he - refine ⟨Or.inl he,?_⟩ - intro hxe - exact he.2 ((mem_incidentSupport G hloc A e).mpr ⟨x.val,hx,hxe⟩) - have hInf (z : (D:Set V)) (hz : z.val ∈ Finset.univ.image w) : - (cluster G (cutConfig G (η ∪ (P:Set E)) x.val) z.val).Infinite := by - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz - apply (hinf i).mono - intro y hy - rw [hi] at hy - exact conn_mono G hcut hy - have hnew : finiteOverwrite F P ω = η ∪ (P:Set E) := by rfl - refine ⟨P,hPF,x.val,?_⟩ - rw [hnew] - refine ⟨a.val,b.val,c.val,?_,?_,?_,hInf a ha,hInf b hb,hInf c hc,?_,?_,?_⟩ - · exact glued_conn G _ T f hT.connected - (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x a - · exact glued_conn G _ T f hT.connected - (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x b - · exact glued_conn G _ T f hT.connected - (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x c - · intro h - have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h - exact hab (by simpa only [hr'] using hh) - · intro h - have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h - exact hac (by simpa only [hr'] using hh) - · intro h - have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h - exact hbc (by simpa only [hr'] using hh) - -theorem encounter_surgery_of_three (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (ω : Set E) (z : Fin 3 → V) - (hinf : ∀ i, (cluster G ω (z i)).Infinite) - (hsep : ∀ i j, Conn G ω (z i) (z j) → i = j) : - ∃ F P : Finset E, P ⊆ F ∧ ∃ x, IsEncounter G (finiteOverwrite F P ω) x := by - obtain ⟨A,hA,hAc⟩ := exists_finite_connected_envelope G hconn (z 0) (Finset.univ.image z) - have hattach (i : Fin 3) := infinite_exterior_attachment G hloc ω A (z i) - (hA (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩)) (hinf i) - choose v hv w hw e he hGe hzw hInf using hattach - have hext (i j : Fin 3) - (h : Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j)) : i = j := - hsep i j (conn_trans G ω (hzw i) - (conn_trans G ω (conn_mono G Set.sdiff_subset h) (conn_symm G ω (hzw j)))) - have hwi : Function.Injective w := by - intro i j h - apply hext - rw [h] - exact conn_refl G _ _ - have hadj (i : Fin 3) : (openSimpleGraph G Set.univ).Adj (v i) (w i) := by - refine ⟨?_,e i,Set.mem_univ _,hGe i⟩ - intro h - exact hw i (h ▸ hv i) - obtain ⟨P,hPF,x,hx⟩ := encounter_surgery_of_attachments G hloc ω A v w hv hw hwi hadj hAc hext hInf - exact ⟨incidentSupport G hloc A,P,hPF,x,hx⟩ - -theorem three_of_infinite_count (G : BondGraph V E) (ω : Set E) - (h : (infiniteClusters G ω).Infinite) : - ∃ z : Fin 3 → V, (∀ i, (cluster G ω (z i)).Infinite) ∧ - ∀ i j, Conn G ω (z i) (z j) → i = j := by - let e := Set.Infinite.natEmbedding (infiniteClusters G ω) h - let C (i : Fin 3) := e i.val - choose z hz using (fun i : Fin 3 => (C i).property.2) - refine ⟨z,?_,?_⟩ - · intro i; rw [←hz i]; exact (C i).property.1 - · intro i j hij - have hc : C i = C j := by - apply Subtype.ext - rw [hz i,hz j] - exact cluster_eq_of_conn G ω hij - exact Fin.ext (e.injective hc) -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Criticality.FiniteChanges +import OAI.Probability.UnimodularPercolation.Encounter.Counts +import OAI.Probability.UnimodularPercolation.Encounter.TreeBranches + +namespace OAI + +/-! Exterior branches and finite encounter surgery. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem infinite_cluster_sdiff_contains (G : BondGraph V E) (ω : Set E) + (F : Set E) (hF : F.Finite) (x : V) (hx : (cluster G ω x).Infinite) : + ∃ z, Conn G ω x z ∧ (cluster G (ω \ F) z).Infinite := by + have he : (ω \ F) ∪ (ω ∩ F) = ω := by ext e; simp only [Set.mem_union,Set.mem_sdiff,Set.mem_inter_iff]; tauto + obtain ⟨z,hz,hzi⟩ := infinite_cluster_union_contains G (ω \ F) (ω ∩ F) (hF.inter_of_right ω) x (by rw [he]; exact hx) + exact ⟨z,by simpa only [he] using hz,hzi⟩ + +theorem conn_eq_of_no_incident (G : BondGraph V E) (ω : Set E) (x y : V) + (hx : ∀ e ∈ ω, x ∉ G e) (hxy : Conn G ω x y) : y = x := by + induction hxy with + | refl => rfl + | @tail y z hy hed ih => + obtain ⟨e,he,hGe⟩ := hed + exact False.elim (hx e he (by rw [hGe,ih]; simp)) + +theorem cluster_singleton_of_no_incident (G : BondGraph V E) (ω : Set E) (x : V) + (hx : ∀ e ∈ ω, x ∉ G e) : cluster G ω x = {x} := by + ext y + constructor + · intro h; exact conn_eq_of_no_incident G ω x y hx h + · rintro rfl; exact mem_cluster_self G ω _ + +theorem deleted_cluster_singleton (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) : + cluster G (ω \ (incidentSupport G hloc A:Set E)) x = {x} := by + apply cluster_singleton_of_no_incident + intro e he hxe + exact he.2 ((mem_incidentSupport G hloc A e).mpr ⟨x,hx,hxe⟩) + +theorem conn_exterior_attachment (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) {z : V} (hxz : Conn G ω x z) : + z ∈ A ∨ ∃ v ∈ A, ∃ w, w ∉ A ∧ ∃ e ∈ ω, G e = s(v,w) ∧ + Conn G (ω \ (incidentSupport G hloc A:Set E)) w z := by + induction hxz with + | refl => exact Or.inl hx + | @tail y z hy hed ih => + by_cases hz : z ∈ A + · exact Or.inl hz + right + obtain ⟨e,he,hGe⟩ := hed + rcases ih with hyA | ⟨v,hv,w,hw,f,hf,hGf,hwy⟩ + · exact ⟨y,hyA,z,hz,e,he,hGe,conn_refl G _ z⟩ + · have hyA : y ∉ A := by + intro hya + have hs := deleted_cluster_singleton G hloc ω A y hya + have hyy : w ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) y := conn_symm G _ hwy + rw [hs] at hyy + exact hw (hyy ▸ hya) + refine ⟨v,hv,w,hw,f,hf,hGf,hwy.tail ⟨e,⟨he,?_⟩,hGe⟩⟩ + intro hei + obtain ⟨a,ha,hage⟩ := (mem_incidentSupport G hloc A e).mp hei + rw [hGe,Sym2.mem_iff] at hage + rcases hage with rfl | rfl + · exact hyA ha + · exact hz ha + +theorem infinite_exterior_attachment (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (A : Finset V) (x : V) (hx : x ∈ A) (hi : (cluster G ω x).Infinite) : + ∃ v ∈ A, ∃ w, w ∉ A ∧ ∃ e ∈ ω, G e = s(v,w) ∧ Conn G ω x w ∧ + (cluster G (ω \ (incidentSupport G hloc A:Set E)) w).Infinite := by + obtain ⟨z,hxz,hz⟩ := infinite_cluster_sdiff_contains G ω _ (incidentSupport G hloc A).finite_toSet x hi + have hn : z ∉ A := by + intro hzA + rw [deleted_cluster_singleton G hloc ω A z hzA] at hz + exact hz (Set.finite_singleton z) + obtain ⟨v,hv,w,hw,e,he,hGe,hwz⟩ := (conn_exterior_attachment G hloc ω A x hx hxz).resolve_left hn + refine ⟨v,hv,w,hw,e,he,hGe,conn_trans G ω hxz (conn_symm G ω (conn_mono G Set.sdiff_subset hwz)),?_⟩ + rwa [cluster_eq_of_conn G _ hwz] + +theorem exists_finite_connected_envelope (G : BondGraph V E) (hconn : Connected G) + (x : V) (R : Finset V) : ∃ A : Finset V, R ⊆ A ∧ + ((openSimpleGraph G Set.univ).induce (A:Set V)).Connected := by + obtain ⟨F,hF⟩ := finite_connecting_edges G hconn x R + have hf := cluster_finite_of_finite_edges G F.finite_toSet x + refine ⟨hf.toFinset,?_,?_⟩ + · intro y hy + exact hf.mem_toFinset.mpr (hF y hy) + · rw [hf.coe_toFinset] + exact cluster_induce_connected G Set.univ (F:Set E) (Set.subset_univ _) x +end Percolation + +namespace Percolation +open SimpleGraph +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem deleted_envelope_separated (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (A : Finset V) (w : Fin 3 → V) + (hsep : ∀ i j, Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j) → i = j) + (a b : V) (ha : a ∈ A ∪ Finset.univ.image w) (hb : b ∈ A ∪ Finset.univ.image w) + (hab : Conn G (ω \ (incidentSupport G hloc A:Set E)) a b) : a = b := by + rcases Finset.mem_union.mp ha with ha | ha + · have hh := deleted_cluster_singleton G hloc ω A a ha + have hm : b ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) a := hab + rw [hh] at hm + exact hm.symm + rcases Finset.mem_union.mp hb with hb | hb + · have hh := deleted_cluster_singleton G hloc ω A b hb + have hm : a ∈ cluster G (ω \ (incidentSupport G hloc A:Set E)) b := conn_symm G _ hab + rw [hh] at hm + exact hm + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp ha + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hb + exact congrArg w (hsep i j hab) + +theorem encounter_surgery_of_attachments (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (A : Finset V) (v w : Fin 3 → V) + (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) + (hadj : ∀ i, (openSimpleGraph G Set.univ).Adj (v i) (w i)) + (hA : ((openSimpleGraph G Set.univ).induce (A:Set V)).Connected) + (hsep : ∀ i j, Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j) → i = j) + (hinf : ∀ i, (cluster G (ω \ (incidentSupport G hloc A:Set E)) (w i)).Infinite) : + ∃ P : Finset E, P ⊆ incidentSupport G hloc A ∧ + ∃ x, IsEncounter G (finiteOverwrite (incidentSupport G hloc A) P ω) x := by + obtain ⟨D,hD,hSD,T,hTK,hT,x,a,b,c,hx,ha,hb,hc,hab,hac,hbc⟩ := + exists_terminal_tree (openSimpleGraph G Set.univ) A v w hv hw hwi hadj hA + let F := incidentSupport G hloc A + let η := ω \ (F:Set E) + let f : (D:Set V) ↪ V := ⟨Subtype.val,Subtype.val_injective⟩ + let P := F.filter (fun e => ∃ a b : (D:Set V), T.Adj a b ∧ G e = s(a.val,b.val)) + have hPF : P ⊆ F := Finset.filter_subset _ _ + have hP (e : E) (he : e ∈ P) : ∃ a b, T.Adj a b ∧ G e = s(f a,f b) := + (Finset.mem_filter.mp he).2 + have hPres (a b : (D:Set V)) (hab : T.Adj a b) : ∃ e ∈ (P:Set E), G e = s(f a,f b) := by + have hk := hTK hab + obtain ⟨e,_,he⟩ := hk.1.2 + refine ⟨e,Finset.mem_filter.mpr ⟨?_,⟨a,b,hab,he⟩⟩,he⟩ + apply (mem_incidentSupport G hloc A e).mpr + rcases terminalGraph_touch _ A v w hv hk with ha | hb + · exact ⟨a.val,ha,by rw [he]; simp⟩ + · exact ⟨b.val,hb,by rw [he]; simp⟩ + have hsepD (a b : (D:Set V)) (h : Conn G η (f a) (f b)) : a = b := by + apply Subtype.ext + exact deleted_envelope_separated G hloc ω A w hsep a.val b.val (hD a.property) (hD b.property) h + obtain ⟨r,hr,hrη⟩ := exists_cluster_retraction G η f hsepD x + have hr' (a : (D:Set V)) : r a.val = a := hr a + have hcut : η ⊆ cutConfig G (η ∪ (P:Set E)) x.val := by + intro e he + refine ⟨Or.inl he,?_⟩ + intro hxe + exact he.2 ((mem_incidentSupport G hloc A e).mpr ⟨x.val,hx,hxe⟩) + have hInf (z : (D:Set V)) (hz : z.val ∈ Finset.univ.image w) : + (cluster G (cutConfig G (η ∪ (P:Set E)) x.val) z.val).Infinite := by + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hz + apply (hinf i).mono + intro y hy + rw [hi] at hy + exact conn_mono G hcut hy + have hnew : finiteOverwrite F P ω = η ∪ (P:Set E) := by rfl + refine ⟨P,hPF,x.val,?_⟩ + rw [hnew] + refine ⟨a.val,b.val,c.val,?_,?_,?_,hInf a ha,hInf b hb,hInf c hc,?_,?_,?_⟩ + · exact glued_conn G _ T f hT.connected + (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x a + · exact glued_conn G _ T f hT.connected + (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x b + · exact glued_conn G _ T f hT.connected + (fun a b h => let ⟨e,he,hGe⟩ := hPres a b h; ⟨e,Or.inr he,hGe⟩) x c + · intro h + have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h + exact hab (by simpa only [hr'] using hh) + · intro h + have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h + exact hac (by simpa only [hr'] using hh) + · intro h + have hh := glued_cut_conn G η (P:Set E) T f r hr hrη hP x h + exact hbc (by simpa only [hr'] using hh) + +theorem encounter_surgery_of_three (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (ω : Set E) (z : Fin 3 → V) + (hinf : ∀ i, (cluster G ω (z i)).Infinite) + (hsep : ∀ i j, Conn G ω (z i) (z j) → i = j) : + ∃ F P : Finset E, P ⊆ F ∧ ∃ x, IsEncounter G (finiteOverwrite F P ω) x := by + obtain ⟨A,hA,hAc⟩ := exists_finite_connected_envelope G hconn (z 0) (Finset.univ.image z) + have hattach (i : Fin 3) := infinite_exterior_attachment G hloc ω A (z i) + (hA (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩)) (hinf i) + choose v hv w hw e he hGe hzw hInf using hattach + have hext (i j : Fin 3) + (h : Conn G (ω \ (incidentSupport G hloc A:Set E)) (w i) (w j)) : i = j := + hsep i j (conn_trans G ω (hzw i) + (conn_trans G ω (conn_mono G Set.sdiff_subset h) (conn_symm G ω (hzw j)))) + have hwi : Function.Injective w := by + intro i j h + apply hext + rw [h] + exact conn_refl G _ _ + have hadj (i : Fin 3) : (openSimpleGraph G Set.univ).Adj (v i) (w i) := by + refine ⟨?_,e i,Set.mem_univ _,hGe i⟩ + intro h + exact hw i (h ▸ hv i) + obtain ⟨P,hPF,x,hx⟩ := encounter_surgery_of_attachments G hloc ω A v w hv hw hwi hadj hAc hext hInf + exact ⟨incidentSupport G hloc A,P,hPF,x,hx⟩ + +theorem three_of_infinite_count (G : BondGraph V E) (ω : Set E) + (h : (infiniteClusters G ω).Infinite) : + ∃ z : Fin 3 → V, (∀ i, (cluster G ω (z i)).Infinite) ∧ + ∀ i j, Conn G ω (z i) (z j) → i = j := by + let e := Set.Infinite.natEmbedding (infiniteClusters G ω) h + let C (i : Fin 3) := e i.val + choose z hz using (fun i : Fin 3 => (C i).property.2) + refine ⟨z,?_,?_⟩ + · intro i; rw [←hz i]; exact (C i).property.1 + · intro i j hij + have hc : C i = C j := by + apply Subtype.ext + rw [hz i,hz j] + exact cluster_eq_of_conn G ω hij + exact Fin.ext (e.injective hc) +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Transport.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Transport.lean index 683ea80098cf2668dd602c891a86b1508d210ef0..2ffb386c3ef42c910130c7e7ed5861b1375f9f14 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Transport.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Transport.lean @@ -1,163 +1,163 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! Expected mass transport and cluster averaging. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -variable [Countable V] [Countable E] [Fintype ι] - -omit [Countable V] [Countable E] [Fintype ι] in -theorem expected_mass_transport [Countable V] [Countable E] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) - (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) - (hm : ∀ x y, Measurable (fun ω => m ω x y)) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, - m (b ⁻¹' ω) x y = m ω (a x) (a y)) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, m ω (root i) y ∂law p) = - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' x, m ω x (root i) ∂law p) := by - have hInv (a : V ≃ V) (ha : a ∈ vertexAut G) (x y : V) : - (∫⁻ ω, m ω (a x) (a y) ∂law p) = ∫⁻ ω, m ω x y ∂law p := by - obtain ⟨b,hb⟩ := ha - calc - _ = ∫⁻ ω, m (b ⁻¹' ω) x y ∂law p := lintegral_congr (fun ω => (hinv a b hb ω x y).symm) - _ = ∫⁻ ω, m ω x y ∂(law p).map (fun ω => b ⁻¹' ω) := - (lintegral_map (hm x y) (measurable_set_preimage b)).symm - _ = _ := by rw [law_map_preimage_equiv] - have ht := htr.ennreal G hconn hloc root weight (vertexAut G) (Set.Subset.refl _) hw - (fun x y => ∫⁻ ω, m ω x y ∂law p) hInv - have hr (x : V) : (∫⁻ ω, ∑' y, m ω x y ∂law p) = ∑' y, ∫⁻ ω, m ω x y ∂law p := - lintegral_tsum (fun y => (hm x y).aemeasurable) - have hc (y : V) : (∫⁻ ω, ∑' x, m ω x y ∂law p) = ∑' x, ∫⁻ ω, m ω x y ∂law p := - lintegral_tsum (fun x => (hm x y).aemeasurable) - simp_rw [hr,hc] - exact ht - -theorem incoming_finite_ae (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) - (hm : ∀ x y, Measurable (fun ω => m ω x y)) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, - m (b ⁻¹' ω) x y = m ω (a x) (a y)) - (hrow : ∀ ω x, ∑' y, m ω x y ≤ 1) (i : ι) : - ∀ᵐ ω ∂law p, ∑' x, m ω x (root i) < ⊤ := by - have ht := expected_mass_transport G hconn hloc root weight htr (fun i => (hw i).le) - p m hm hinv - have hupper : (∑ j, ENNReal.ofReal (weight j) * ∫⁻ ω, ∑' x, m ω x (root j) ∂law p) ≤ 1 := by - rw [←ht] - calc - _ ≤ ∑ j, ENNReal.ofReal (weight j) * 1 := by - apply Finset.sum_le_sum - intro j _ - gcongr - calc - _ ≤ ∫⁻ ω : Set E, (1:ℝ≥0∞) ∂law p := lintegral_mono (fun ω => hrow ω (root j)) - _ = 1 := by simp - _ = 1 := by - simp only [mul_one,←ENNReal.ofReal_sum_of_nonneg (fun j _ => (hw j).le),hw1,ENNReal.ofReal_one] - have hterm := (Finset.single_le_sum (fun j _ => (show (0:ℝ≥0∞) ≤ ENNReal.ofReal (weight j) * ∫⁻ ω, ∑' x, m ω x (root j) ∂law p from zero_le)) - (Finset.mem_univ i)).trans hupper - have hfinite : (∫⁻ ω, ∑' x, m ω x (root i) ∂law p) ≠ ⊤ := by - intro he - rw [he,ENNReal.mul_top ((ENNReal.ofReal_pos.mpr (hw i)).ne')] at hterm - exact (not_le_of_gt ENNReal.one_lt_top) hterm - exact ae_lt_top (Measurable.tsum (fun x => hm x (root i))) hfinite - -omit [Countable V] [Countable E] [Fintype ι] in -theorem expected_label_mass_transport [Countable V] [Countable E] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) - (m : (E → unitInterval) → V → V → ℝ≥0∞) - (hm : ∀ x y, Measurable (fun l => m l x y)) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ l x y, - m (l ∘ b) x y = m l (a x) (a y)) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' y, m l (root i) y ∂labelLaw) = - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' x, m l x (root i) ∂labelLaw) := by - have hInv (a : V ≃ V) (ha : a ∈ vertexAut G) (x y : V) : - (∫⁻ l, m l (a x) (a y) ∂labelLaw) = ∫⁻ l, m l x y ∂labelLaw := by - obtain ⟨b,hb⟩ := ha - calc - _ = ∫⁻ l, m (l ∘ b) x y ∂labelLaw := lintegral_congr (fun l => (hinv a b hb l x y).symm) - _ = ∫⁻ l, m l x y ∂labelLaw.map (fun l => l ∘ b) := - (lintegral_map (hm x y) (by fun_prop)).symm - _ = _ := by rw [labelLaw_map_precomp] - have ht := htr.ennreal G hconn hloc root weight (vertexAut G) (Set.Subset.refl _) hw - (fun x y => ∫⁻ l, m l x y ∂labelLaw) hInv - have hr x : (∫⁻ l, ∑' y, m l x y ∂labelLaw) = ∑' y, ∫⁻ l, m l x y ∂labelLaw := - lintegral_tsum (fun y => (hm x y).aemeasurable) - have hc y : (∫⁻ l, ∑' x, m l x y ∂labelLaw) = ∑' x, ∫⁻ l, m l x y ∂labelLaw := - lintegral_tsum (fun x => (hm x y).aemeasurable) - simp_rw [hr,hc] - exact ht - -theorem label_root_cluster_average (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) - (q : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law q, (cluster G ω x).Finite) - (f : (E → unitInterval) → V → ℝ≥0∞) (hf : ∀ x, Measurable (fun l => f l x)) - (hi : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ l x, - f (l ∘ b) x = f l (a x)) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' y, - clusterAveragingKernel G (openEdges l q) (root i) y * f l y ∂labelLaw) = - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, f l (root i) ∂labelLaw) := by - have hm x y : Measurable (fun l => clusterAveragingKernel G (openEdges l q) x y * f l y) := - ((measurable_clusterAveragingKernel G hloc x y).comp (measurable_openEdges q)).mul (hf y) - have ht := expected_label_mass_transport G hconn hloc root weight htr hw - (fun l x y => clusterAveragingKernel G (openEdges l q) x y * f l y) hm - (fun a b hab l x y => by - rw [hi a b hab] - exact congrArg (fun t => t * f l (a y)) (clusterAveragingKernel_aut G hab (openEdges l q) x y)) - rw [ht] - apply Finset.sum_congr rfl - intro i _ - congr 1 - apply lintegral_congr_ae - have hfl : ∀ᵐ l ∂labelLaw, (cluster G (openEdges l q) (root i)).Finite := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => (cluster G ω (root i)).Finite) (measurable_openEdges q).aemeasurable - rw [map_openEdges] - exact hfin (root i) - filter_upwards [hfl] with l hl - rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G (openEdges l q) (root i) hl,one_mul] - -theorem incoming_finite_ae_all (G : BondGraph V E) (hconn : Connected G) - (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) - (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) - (hm : ∀ x y, Measurable (fun ω => m ω x y)) - (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, - m (b ⁻¹' ω) x y = m ω (a x) (a y)) - (hrow : ∀ ω x, ∑' y, m ω x y ≤ 1) : - ∀ᵐ ω ∂law p, ∀ y, ∑' x, m ω x y < ⊤ := by - apply ae_all_iff.mpr - intro y - obtain ⟨i,a,⟨b,hab⟩,rfl⟩ := hcov y - have hi := incoming_finite_ae G hconn hloc root weight htr hw hw1 p m hm hinv hrow i - have hi' : ∀ᵐ ω ∂law p, ∑' x, m (b ⁻¹' ω) x (root i) < ⊤ := by - apply ae_of_ae_map (μ := law p) - (p := fun ω : Set E => ∑' x, m ω x (root i) < ⊤) - (measurable_set_preimage b).aemeasurable - rw [law_map_preimage_equiv] - exact hi - filter_upwards [hi'] with ω hω - simpa only [hinv a b hab,a.tsum_eq (fun x => m ω x (a (root i)))] using hω - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! Expected mass transport and cluster averaging. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +variable [Countable V] [Countable E] [Fintype ι] + +omit [Countable V] [Countable E] [Fintype ι] in +theorem expected_mass_transport [Countable V] [Countable E] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) + (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) + (hm : ∀ x y, Measurable (fun ω => m ω x y)) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, + m (b ⁻¹' ω) x y = m ω (a x) (a y)) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, m ω (root i) y ∂law p) = + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' x, m ω x (root i) ∂law p) := by + have hInv (a : V ≃ V) (ha : a ∈ vertexAut G) (x y : V) : + (∫⁻ ω, m ω (a x) (a y) ∂law p) = ∫⁻ ω, m ω x y ∂law p := by + obtain ⟨b,hb⟩ := ha + calc + _ = ∫⁻ ω, m (b ⁻¹' ω) x y ∂law p := lintegral_congr (fun ω => (hinv a b hb ω x y).symm) + _ = ∫⁻ ω, m ω x y ∂(law p).map (fun ω => b ⁻¹' ω) := + (lintegral_map (hm x y) (measurable_set_preimage b)).symm + _ = _ := by rw [law_map_preimage_equiv] + have ht := htr.ennreal G hconn hloc root weight (vertexAut G) (Set.Subset.refl _) hw + (fun x y => ∫⁻ ω, m ω x y ∂law p) hInv + have hr (x : V) : (∫⁻ ω, ∑' y, m ω x y ∂law p) = ∑' y, ∫⁻ ω, m ω x y ∂law p := + lintegral_tsum (fun y => (hm x y).aemeasurable) + have hc (y : V) : (∫⁻ ω, ∑' x, m ω x y ∂law p) = ∑' x, ∫⁻ ω, m ω x y ∂law p := + lintegral_tsum (fun x => (hm x y).aemeasurable) + simp_rw [hr,hc] + exact ht + +theorem incoming_finite_ae (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) + (hm : ∀ x y, Measurable (fun ω => m ω x y)) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, + m (b ⁻¹' ω) x y = m ω (a x) (a y)) + (hrow : ∀ ω x, ∑' y, m ω x y ≤ 1) (i : ι) : + ∀ᵐ ω ∂law p, ∑' x, m ω x (root i) < ⊤ := by + have ht := expected_mass_transport G hconn hloc root weight htr (fun i => (hw i).le) + p m hm hinv + have hupper : (∑ j, ENNReal.ofReal (weight j) * ∫⁻ ω, ∑' x, m ω x (root j) ∂law p) ≤ 1 := by + rw [←ht] + calc + _ ≤ ∑ j, ENNReal.ofReal (weight j) * 1 := by + apply Finset.sum_le_sum + intro j _ + gcongr + calc + _ ≤ ∫⁻ ω : Set E, (1:ℝ≥0∞) ∂law p := lintegral_mono (fun ω => hrow ω (root j)) + _ = 1 := by simp + _ = 1 := by + simp only [mul_one,←ENNReal.ofReal_sum_of_nonneg (fun j _ => (hw j).le),hw1,ENNReal.ofReal_one] + have hterm := (Finset.single_le_sum (fun j _ => (show (0:ℝ≥0∞) ≤ ENNReal.ofReal (weight j) * ∫⁻ ω, ∑' x, m ω x (root j) ∂law p from zero_le)) + (Finset.mem_univ i)).trans hupper + have hfinite : (∫⁻ ω, ∑' x, m ω x (root i) ∂law p) ≠ ⊤ := by + intro he + rw [he,ENNReal.mul_top ((ENNReal.ofReal_pos.mpr (hw i)).ne')] at hterm + exact (not_le_of_gt ENNReal.one_lt_top) hterm + exact ae_lt_top (Measurable.tsum (fun x => hm x (root i))) hfinite + +omit [Countable V] [Countable E] [Fintype ι] in +theorem expected_label_mass_transport [Countable V] [Countable E] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) + (m : (E → unitInterval) → V → V → ℝ≥0∞) + (hm : ∀ x y, Measurable (fun l => m l x y)) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ l x y, + m (l ∘ b) x y = m l (a x) (a y)) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' y, m l (root i) y ∂labelLaw) = + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' x, m l x (root i) ∂labelLaw) := by + have hInv (a : V ≃ V) (ha : a ∈ vertexAut G) (x y : V) : + (∫⁻ l, m l (a x) (a y) ∂labelLaw) = ∫⁻ l, m l x y ∂labelLaw := by + obtain ⟨b,hb⟩ := ha + calc + _ = ∫⁻ l, m (l ∘ b) x y ∂labelLaw := lintegral_congr (fun l => (hinv a b hb l x y).symm) + _ = ∫⁻ l, m l x y ∂labelLaw.map (fun l => l ∘ b) := + (lintegral_map (hm x y) (by fun_prop)).symm + _ = _ := by rw [labelLaw_map_precomp] + have ht := htr.ennreal G hconn hloc root weight (vertexAut G) (Set.Subset.refl _) hw + (fun x y => ∫⁻ l, m l x y ∂labelLaw) hInv + have hr x : (∫⁻ l, ∑' y, m l x y ∂labelLaw) = ∑' y, ∫⁻ l, m l x y ∂labelLaw := + lintegral_tsum (fun y => (hm x y).aemeasurable) + have hc y : (∫⁻ l, ∑' x, m l x y ∂labelLaw) = ∑' x, ∫⁻ l, m l x y ∂labelLaw := + lintegral_tsum (fun x => (hm x y).aemeasurable) + simp_rw [hr,hc] + exact ht + +theorem label_root_cluster_average (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 ≤ weight i) + (q : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law q, (cluster G ω x).Finite) + (f : (E → unitInterval) → V → ℝ≥0∞) (hf : ∀ x, Measurable (fun l => f l x)) + (hi : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ l x, + f (l ∘ b) x = f l (a x)) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, ∑' y, + clusterAveragingKernel G (openEdges l q) (root i) y * f l y ∂labelLaw) = + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, f l (root i) ∂labelLaw) := by + have hm x y : Measurable (fun l => clusterAveragingKernel G (openEdges l q) x y * f l y) := + ((measurable_clusterAveragingKernel G hloc x y).comp (measurable_openEdges q)).mul (hf y) + have ht := expected_label_mass_transport G hconn hloc root weight htr hw + (fun l x y => clusterAveragingKernel G (openEdges l q) x y * f l y) hm + (fun a b hab l x y => by + rw [hi a b hab] + exact congrArg (fun t => t * f l (a y)) (clusterAveragingKernel_aut G hab (openEdges l q) x y)) + rw [ht] + apply Finset.sum_congr rfl + intro i _ + congr 1 + apply lintegral_congr_ae + have hfl : ∀ᵐ l ∂labelLaw, (cluster G (openEdges l q) (root i)).Finite := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => (cluster G ω (root i)).Finite) (measurable_openEdges q).aemeasurable + rw [map_openEdges] + exact hfin (root i) + filter_upwards [hfl] with l hl + rw [ENNReal.tsum_mul_right,clusterAveragingKernel_column G (openEdges l q) (root i) hl,one_mul] + +theorem incoming_finite_ae_all (G : BondGraph V E) (hconn : Connected G) + (hloc : LocallyFinite G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) + (p : unitInterval) (m : Set E → V → V → ℝ≥0∞) + (hm : ∀ x y, Measurable (fun ω => m ω x y)) + (hinv : ∀ a : V ≃ V, ∀ b : E ≃ E, IsAut G a b → ∀ ω x y, + m (b ⁻¹' ω) x y = m ω (a x) (a y)) + (hrow : ∀ ω x, ∑' y, m ω x y ≤ 1) : + ∀ᵐ ω ∂law p, ∀ y, ∑' x, m ω x y < ⊤ := by + apply ae_all_iff.mpr + intro y + obtain ⟨i,a,⟨b,hab⟩,rfl⟩ := hcov y + have hi := incoming_finite_ae G hconn hloc root weight htr hw hw1 p m hm hinv hrow i + have hi' : ∀ᵐ ω ∂law p, ∑' x, m (b ⁻¹' ω) x (root i) < ⊤ := by + apply ae_of_ae_map (μ := law p) + (p := fun ω : Set E => ∑' x, m ω x (root i) < ⊤) + (measurable_set_preimage b).aemeasurable + rw [law_map_preimage_equiv] + exact hi + filter_upwards [hi'] with ω hω + simpa only [hinv a b hab,a.tsum_eq (fun x => m ω x (a (root i)))] using hω + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/TreeBranches.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/TreeBranches.lean index 0fc685c8f8d646cb1dedd89dd1206fd76c37b322..3e02afddf7fa2b0484b042fc12ab271ae03e2a4f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/TreeBranches.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/TreeBranches.lean @@ -1,336 +1,336 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.Vertices - -namespace OAI - -/-! Tree branches, cluster retractions and terminal connecting trees. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open SimpleGraph -universe u -variable {V : Type u} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cutVertex_le_deleteEdge (T : SimpleGraph V) (x y : V) : - cutVertex T x ≤ T.deleteEdges {s(x,y)} := by - intro a b hab - apply deleteEdges_adj.mpr - refine ⟨hab.1,?_⟩ - intro he - have hh : x ∈ s(a,b) := (Set.mem_singleton_iff.mp he) ▸ (by simp : x ∈ s(x,y)) - rcases Sym2.mem_iff.mp hh with hx | hx - · exact hab.2.1 hx.symm - · exact hab.2.2 hx.symm - -theorem tree_cut_neighbors (T : SimpleGraph V) (ht : T.IsAcyclic) (x y z : V) - (hy : T.Adj x y) (hz : T.Adj x z) (hyz : (cutVertex T x).Reachable y z) : y = z := by - by_contra hn - have hb := (isAcyclic_iff_forall_adj_isBridge.mp ht) hy - have hd : (T.deleteEdges {s(x,y)}).Adj x z := by - apply deleteEdges_adj.mpr - refine ⟨hz,?_⟩ - intro he - have hh := Sym2.eq_iff.mp (Set.mem_singleton_iff.mp he) - rcases hh with ⟨_,hzy⟩ | ⟨hxy,hzx⟩ - · exact hn hzy.symm - · exact hy.ne hxy - exact (isBridge_iff.mp hb) (hd.reachable.trans (hyz.mono (cutVertex_le_deleteEdge T x y)).symm) - -theorem cut_reachable_self_eq (T : SimpleGraph V) (x z : V) - (h : (cutVertex T x).Reachable x z) : z = x := by - induction h with - | intro p => - cases p with - | nil => rfl - | cons hadj _ => exact False.elim (hadj.2.1 rfl) - -theorem tree_branch_contains_leaf [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) - (x y : V) (hxy : T.Adj x y) : - ∃ z, z ≠ x ∧ (cutVertex T x).Reachable y z ∧ T.degree z = 1 := by - let C := ((cutVertex T x).connectedComponentMk y).supp - have hyC : y ∈ C := (ConnectedComponent.mem_supp_iff _ _).mpr rfl - have hxC : x ∉ C := by - intro h - have hr : (cutVertex T x).Reachable y x := by - exact (ConnectedComponent.eq.mp ((ConnectedComponent.mem_supp_iff _ _).mp h)).symm - exact hxy.ne (cut_reachable_self_eq T x y hr.symm).symm - have hr (z : V) (hz : z ∈ C) : (cutVertex T x).Reachable y z := - (ConnectedComponent.eq.mp ((ConnectedComponent.mem_supp_iff _ _).mp hz)).symm - have hnbr (z : V) (hz : z ∈ C) (w : V) (hzw : T.Adj z w) : w = x ∨ w ∈ C := by - by_cases hw : w = x - · exact Or.inl hw - · right - apply (ConnectedComponent.mem_supp_iff _ _).mpr - apply ConnectedComponent.sound - exact (hr z hz).trans (Adj.reachable (G := cutVertex T x) - ⟨hzw,fun h => hxC (h ▸ hz),hw⟩) |>.symm - have hnx (z : V) (hz : z ∈ C) (hzx : T.Adj z x) : z = y := - (tree_cut_neighbors T ht.isAcyclic x y z hxy hzx.symm (hr z hz)).symm - have hccon : (T.induce C).Connected := by - apply SimpleGraph.Connected.mono (G := (cutVertex T x).induce C) - · intro a b hab; exact hab.1 - · exact ((cutVertex T x).connectedComponentMk y).connected_toSimpleGraph - have hc : (T.induce C).IsTree := ⟨hccon,ht.isAcyclic.induce C⟩ - by_cases he : ∃ z ∈ C, z ≠ y - · obtain ⟨z,hz,hzy⟩ := he - let : Nontrivial C := ⟨⟨⟨z,hz⟩,⟨y,hyC⟩,fun h => hzy (congrArg Subtype.val h)⟩⟩ - obtain ⟨a,b,hab,ha,hb⟩ := hc.exists_ne_and_degree_eq_one - have hex : ∃ a : C, a.val ≠ y ∧ (T.induce C).degree a = 1 := by - by_cases hay : a.val = y - · refine ⟨b,?_,hb⟩ - intro hby - exact hab (Subtype.ext (hay.trans hby.symm)) - · exact ⟨a,hay,ha⟩ - obtain ⟨a,hay,ha⟩ := hex - refine ⟨a.val,fun h => hxC (h ▸ a.property),hr _ a.property,?_⟩ - have hn : T.neighborSet a.val ⊆ C := by - intro w hw - rcases hnbr a.val a.property w hw with rfl | hwc - · exact False.elim (hay (hnx a.val a.property hw)) - · exact hwc - rwa [T.degree_induce_of_neighborSet_subset hn] at ha - · push Not at he - refine ⟨y,hxy.ne.symm,Reachable.refl y,?_⟩ - apply degree_eq_one_iff_existsUnique_adj.mpr - refine ⟨x,hxy.symm,?_⟩ - intro w hw - rcases hnbr y hyC w hw with hwx | hwC - · exact hwx - · exact False.elim (hw.ne (he w hwC).symm) - -theorem pruned_tree_branch_marked [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) - (S : Finset V) (hpr : ∀ z, z ∉ S → 2 ≤ T.degree z) - (x y : V) (hxy : T.Adj x y) : - ∃ z ∈ S, z ≠ x ∧ (cutVertex T x).Reachable y z := by - obtain ⟨z,hzx,hz,hd⟩ := tree_branch_contains_leaf T ht x y hxy - refine ⟨z,?_,hzx,hz⟩ - by_contra hn - have hh := hpr z hn - omega - -theorem tree_three_leaves_branch [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) - (S : Finset V) (hcard : 3 ≤ S.card) (hleaf : ∀ z ∈ S, T.degree z = 1) : - ∃ x, 3 ≤ T.degree x := by - by_contra hn - have hd (x : V) : T.degree x ≤ 2 := by have := not_exists.mp hn x; omega - have hs : (∑ x : V, (T.degree x + (if x ∈ S then 1 else 0))) ≤ - ∑ x : V, (2:ℕ) := by - apply Finset.sum_le_sum - intro x _ - by_cases hx : x ∈ S - · simp only [hx,ite_true,hleaf x hx]; omega - · simpa only [hx,ite_false,add_zero] using hd x - have hsum : (∑ x : V, if x ∈ S then (1:ℕ) else 0) = S.card := by - simp - rw [Finset.sum_add_distrib,hsum,T.sum_degrees_eq_twice_card_edges] at hs - simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] at hs - have he := ht.card_edgeFinset - have hc : S.card ≤ Fintype.card V := Finset.card_le_univ S - omega - -theorem pruned_tree_three_branches [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) - (S : Finset V) (hcard : 3 ≤ S.card) (hleaf : ∀ z ∈ S, T.degree z = 1) - (hpr : ∀ z, z ∉ S → 2 ≤ T.degree z) : - ∃ x a b c, x ∉ S ∧ a ∈ S ∧ b ∈ S ∧ c ∈ S ∧ - a ≠ x ∧ b ≠ x ∧ c ≠ x ∧ - ¬ (cutVertex T x).Reachable a b ∧ - ¬ (cutVertex T x).Reachable a c ∧ - ¬ (cutVertex T x).Reachable b c := by - obtain ⟨x,hx⟩ := tree_three_leaves_branch T ht S hcard hleaf - have hxS : x ∉ S := by intro h; have := hleaf x h; omega - have hnc : 2 < (T.neighborFinset x).card := by simpa using (show 2 < T.degree x by omega) - obtain ⟨u,v,w,hu,hv,hw,huv,huw,hvw⟩ := Finset.two_lt_card_iff.mp hnc - have hau := (T.mem_neighborFinset x u).mp hu - have hav := (T.mem_neighborFinset x v).mp hv - have haw := (T.mem_neighborFinset x w).mp hw - obtain ⟨a,ha,hax,hua⟩ := pruned_tree_branch_marked T ht S hpr x u hau - obtain ⟨b,hb,hbx,hvb⟩ := pruned_tree_branch_marked T ht S hpr x v hav - obtain ⟨c,hc,hcx,hwc⟩ := pruned_tree_branch_marked T ht S hpr x w haw - refine ⟨x,a,b,c,hxS,ha,hb,hc,hax,hbx,hcx,?_,?_,?_⟩ - · intro h; exact huv (tree_cut_neighbors T ht.isAcyclic x u v hau hav - (hua.trans (h.trans hvb.symm))) - · intro h; exact huw (tree_cut_neighbors T ht.isAcyclic x u w hau haw - (hua.trans (h.trans hwc.symm))) - · intro h; exact hvw (tree_cut_neighbors T ht.isAcyclic x v w hav haw - (hvb.trans (h.trans hwc.symm))) -end Percolation - -namespace Percolation -open SimpleGraph -universe u v w -variable {V : Type u} {E : Type v} {W : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem exists_cluster_retraction (G : BondGraph V E) (η : Set E) (f : W ↪ V) - (hsep : ∀ a b, Conn G η (f a) (f b) → a = b) (x : W) : - ∃ r : V → W, (∀ a, r (f a) = a) ∧ - ∀ a b, Conn G η a b → r a = r b := by - let r : V → W := fun y => if h : ∃ z, Conn G η (f z) y then h.choose else x - have hval (y : V) (z : W) (hz : Conn G η (f z) y) : r y = z := by - have hex : ∃ z, Conn G η (f z) y := ⟨z,hz⟩ - dsimp [r] - rw [dite_eq_left hex] - exact hsep _ _ (conn_trans G η hex.choose_spec (conn_symm G η hz)) - refine ⟨r,fun a => hval _ _ (conn_refl G η _),?_⟩ - intro a b hab - by_cases ha : ∃ z, Conn G η (f z) a - · obtain ⟨z,hz⟩ := ha - rw [hval a z hz,hval b z (conn_trans G η hz hab)] - · have hb : ¬ ∃ z, Conn G η (f z) b := by - rintro ⟨z,hz⟩ - exact ha ⟨z,conn_trans G η hz (conn_symm G η hab)⟩ - simp only [r,dite_eq_right ha,dite_eq_right hb] - -theorem glued_cut_conn (G : BondGraph V E) (η P : Set E) (T : SimpleGraph W) - (f : W ↪ V) (r : V → W) (hr : ∀ a, r (f a) = a) - (hη : ∀ a b, Conn G η a b → r a = r b) - (hP : ∀ e ∈ P, ∃ a b, T.Adj a b ∧ G e = s(f a,f b)) - (x : W) {a b : V} (hab : Conn G (cutConfig G (η ∪ P) (f x)) a b) : - (cutVertex T x).Reachable (r a) (r b) := by - induction hab with - | refl => exact .refl _ - | @tail a b hab hed ih => - obtain ⟨e,⟨he,hx⟩,hGe⟩ := hed - rcases he with he | he - · have hh := hη a b ((conn_refl G η a).tail ⟨e,he,hGe⟩) - rwa [←hh] - · obtain ⟨u,v,huv,heq⟩ := hP e he - have hne : u ≠ x ∧ v ≠ x := by - rw [heq] at hx - simpa [Sym2.mem_iff,f.injective.eq_iff,eq_comm] using hx - have hkv : (cutVertex T x).Adj u v := ⟨huv,hne⟩ - have habuv := Sym2.eq_iff.mp (hGe.symm.trans heq) - rcases habuv with ⟨rfl,rfl⟩ | ⟨rfl,rfl⟩ - · rw [hr] at ih ⊢ - exact ih.trans hkv.reachable - · rw [hr] at ih ⊢ - exact ih.trans hkv.symm.reachable - -theorem glued_conn (G : BondGraph V E) (ω : Set E) (T : SimpleGraph W) - (f : W → V) (hT : T.Connected) - (he : ∀ a b, T.Adj a b → ∃ e ∈ ω, G e = s(f a,f b)) (a b : W) : - Conn G ω (f a) (f b) := by - obtain ⟨p⟩ := hT a b - induction p with - | nil => exact conn_refl G ω _ - | @cons a b c hab p ih => - exact conn_trans G ω ((conn_refl G ω _).tail (he a b hab)) ih - -end Percolation - -namespace Percolation -open SimpleGraph -universe u -variable {V : Type u} -attribute [local instance] Classical.propDecidable Classical.decEq - -def terminalGraph (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) : SimpleGraph V where - Adj a b := H.Adj a b ∧ ((a ∈ A ∧ b ∈ A) ∨ - ∃ i, (a = v i ∧ b = w i) ∨ (a = w i ∧ b = v i)) - symm := ⟨by - intro a b h - refine ⟨h.1.symm,?_⟩ - rcases h.2 with h | ⟨i,h|h⟩ - · exact Or.inl h.symm - · exact Or.inr ⟨i,Or.inr h.symm⟩ - · exact Or.inr ⟨i,Or.inl h.symm⟩⟩ - loopless := ⟨fun a h => H.loopless.irrefl a h.1⟩ - -theorem terminalGraph_touch (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) - (hv : ∀ i, v i ∈ A) {a b : V} (h : (terminalGraph H A v w).Adj a b) : - a ∈ A ∨ b ∈ A := by - rcases h.2 with h | ⟨i,h|h⟩ - · exact Or.inl h.1 - · exact Or.inl (h.1 ▸ hv i) - · exact Or.inr (h.2 ▸ hv i) - -theorem terminalGraph_leaf (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) - (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) - (i : Fin 3) {y : V} (h : (terminalGraph H A v w).Adj (w i) y) : y = v i := by - rcases h.2 with h | ⟨j,h|h⟩ - · exact False.elim (hw i h.1) - · exact False.elim (hw i (h.1 ▸ hv j)) - · have hij := hwi h.1 - simpa only [hij] using h.2 - -theorem terminalGraph_connected (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) - (hv : ∀ i, v i ∈ A) (hadj : ∀ i, H.Adj (v i) (w i)) - (hA : (H.induce (A:Set V)).Connected) : - ((terminalGraph H A v w).induce ((A ∪ Finset.univ.image w : Finset V):Set V)).Connected := by - let D := A ∪ Finset.univ.image w - let K := terminalGraph H A v w - have hAD : A ⊆ D := Finset.subset_union_left - let f : (H.induce (A:Set V)) →g (K.induce (D:Set V)) := - ⟨fun a => ⟨a.val,hAD a.property⟩,fun {a b} hab => ⟨hab,Or.inl ⟨a.property,b.property⟩⟩⟩ - let z : (D:Set V) := ⟨v 0,hAD (hv 0)⟩ - have connA (a : V) (ha : a ∈ A) : (K.induce (D:Set V)).Reachable ⟨a,hAD ha⟩ z := - (hA ⟨a,ha⟩ ⟨v 0,hv 0⟩).map f - have connD (a : (D:Set V)) : (K.induce (D:Set V)).Reachable a z := by - rcases Finset.mem_union.mp a.property with ha | ha - · exact connA a.val ha - · obtain ⟨i,_,hi⟩ := Finset.mem_image.mp ha - have hK : (K.induce (D:Set V)).Adj a ⟨v i,hAD (hv i)⟩ := by - change K.Adj a.val (v i) - rw [←hi] - exact ⟨(hadj i).symm,Or.inr ⟨i,Or.inr ⟨rfl,rfl⟩⟩⟩ - exact hK.reachable.trans (connA _ (hv i)) - let : Nonempty (D:Set V) := ⟨z⟩ - exact ⟨fun a b => (connD a).trans (connD b).symm⟩ - -theorem exists_terminal_tree (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) - (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) - (hadj : ∀ i, H.Adj (v i) (w i)) - (hA : (H.induce (A:Set V)).Connected) : - ∃ D : Finset V, D ⊆ A ∪ Finset.univ.image w ∧ Finset.univ.image w ⊆ D ∧ - ∃ T : SimpleGraph (D:Set V), T ≤ (terminalGraph H A v w).induce (D:Set V) ∧ - T.IsTree ∧ ∃ x a b c : (D:Set V), x.val ∈ A ∧ - a.val ∈ Finset.univ.image w ∧ b.val ∈ Finset.univ.image w ∧ - c.val ∈ Finset.univ.image w ∧ - ¬ (cutVertex T x).Reachable a b ∧ - ¬ (cutVertex T x).Reachable a c ∧ - ¬ (cutVertex T x).Reachable b c := by - let S := Finset.univ.image w - have hS : S.Nonempty := ⟨w 0,Finset.mem_image.mpr ⟨0,Finset.mem_univ _,rfl⟩⟩ - obtain ⟨D,hD,hSD,T,hTK,hT,hpr⟩ := exists_pruned_connector - (terminalGraph H A v w) S (A ∪ S) hS Finset.subset_union_right - (terminalGraph_connected H A v w hv hadj hA) - let s : Fin 3 → (D:Set V) := fun i => ⟨w i,hSD (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩)⟩ - have hsi : Function.Injective s := fun _ _ h => hwi (congrArg Subtype.val h) - let S' := Finset.univ.image s - have hS' (z : (D:Set V)) : z ∈ S' ↔ z.val ∈ S := by - simp only [S',S,Finset.mem_image,Finset.mem_univ,true_and] - constructor - · rintro ⟨i,rfl⟩; exact ⟨i,rfl⟩ - · rintro ⟨i,hi⟩; exact ⟨i,Subtype.ext hi⟩ - have hcard : S'.card = 3 := by - rw [Finset.card_image_of_injective _ hsi] - simp - let : Nontrivial (D:Set V) := ⟨⟨s 0,s 1,fun h => by have := hsi h; norm_num at this⟩⟩ - have hleaf (z : (D:Set V)) (hz : z ∈ S') : T.degree z = 1 := by - obtain ⟨i,_,hi⟩ := Finset.mem_image.mp ((hS' z).mp hz) - have hpos : 0 < T.degree z := lt_of_lt_of_le - hT.connected.preconnected.minDegree_pos_of_nontrivial (T.minDegree_le_degree z) - obtain ⟨a,ha⟩ := (T.degree_pos_iff_exists_adj z).mp hpos - apply degree_eq_one_iff_existsUnique_adj.mpr - refine ⟨a,ha,?_⟩ - intro b hb - apply Subtype.ext - have ha' : a.val = v i := terminalGraph_leaf H A v w hv hw hwi i (by rw [hi]; exact hTK ha) - have hb' : b.val = v i := terminalGraph_leaf H A v w hv hw hwi i (by rw [hi]; exact hTK hb) - exact hb'.trans ha'.symm - obtain ⟨x,a,b,c,hx,ha,hb,hc,_,_,_,hab,hac,hbc⟩ := - pruned_tree_three_branches T hT S' (by omega) hleaf - (fun z hz => hpr z (fun h => hz ((hS' z).mpr h))) - have hxA : x.val ∈ A := by - rcases Finset.mem_union.mp (hD x.property) with h | h - · exact h - · exact False.elim (hx ((hS' x).mpr h)) - exact ⟨D,hD,hSD,T,hTK,hT,x,a,b,c,hxA,(hS' a).mp ha,(hS' b).mp hb, - (hS' c).mp hc,hab,hac,hbc⟩ -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.Vertices + +namespace OAI + +/-! Tree branches, cluster retractions and terminal connecting trees. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open SimpleGraph +universe u +variable {V : Type u} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cutVertex_le_deleteEdge (T : SimpleGraph V) (x y : V) : + cutVertex T x ≤ T.deleteEdges {s(x,y)} := by + intro a b hab + apply deleteEdges_adj.mpr + refine ⟨hab.1,?_⟩ + intro he + have hh : x ∈ s(a,b) := (Set.mem_singleton_iff.mp he) ▸ (by simp : x ∈ s(x,y)) + rcases Sym2.mem_iff.mp hh with hx | hx + · exact hab.2.1 hx.symm + · exact hab.2.2 hx.symm + +theorem tree_cut_neighbors (T : SimpleGraph V) (ht : T.IsAcyclic) (x y z : V) + (hy : T.Adj x y) (hz : T.Adj x z) (hyz : (cutVertex T x).Reachable y z) : y = z := by + by_contra hn + have hb := (isAcyclic_iff_forall_adj_isBridge.mp ht) hy + have hd : (T.deleteEdges {s(x,y)}).Adj x z := by + apply deleteEdges_adj.mpr + refine ⟨hz,?_⟩ + intro he + have hh := Sym2.eq_iff.mp (Set.mem_singleton_iff.mp he) + rcases hh with ⟨_,hzy⟩ | ⟨hxy,hzx⟩ + · exact hn hzy.symm + · exact hy.ne hxy + exact (isBridge_iff.mp hb) (hd.reachable.trans (hyz.mono (cutVertex_le_deleteEdge T x y)).symm) + +theorem cut_reachable_self_eq (T : SimpleGraph V) (x z : V) + (h : (cutVertex T x).Reachable x z) : z = x := by + induction h with + | intro p => + cases p with + | nil => rfl + | cons hadj _ => exact False.elim (hadj.2.1 rfl) + +theorem tree_branch_contains_leaf [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) + (x y : V) (hxy : T.Adj x y) : + ∃ z, z ≠ x ∧ (cutVertex T x).Reachable y z ∧ T.degree z = 1 := by + let C := ((cutVertex T x).connectedComponentMk y).supp + have hyC : y ∈ C := (ConnectedComponent.mem_supp_iff _ _).mpr rfl + have hxC : x ∉ C := by + intro h + have hr : (cutVertex T x).Reachable y x := by + exact (ConnectedComponent.eq.mp ((ConnectedComponent.mem_supp_iff _ _).mp h)).symm + exact hxy.ne (cut_reachable_self_eq T x y hr.symm).symm + have hr (z : V) (hz : z ∈ C) : (cutVertex T x).Reachable y z := + (ConnectedComponent.eq.mp ((ConnectedComponent.mem_supp_iff _ _).mp hz)).symm + have hnbr (z : V) (hz : z ∈ C) (w : V) (hzw : T.Adj z w) : w = x ∨ w ∈ C := by + by_cases hw : w = x + · exact Or.inl hw + · right + apply (ConnectedComponent.mem_supp_iff _ _).mpr + apply ConnectedComponent.sound + exact (hr z hz).trans (Adj.reachable (G := cutVertex T x) + ⟨hzw,fun h => hxC (h ▸ hz),hw⟩) |>.symm + have hnx (z : V) (hz : z ∈ C) (hzx : T.Adj z x) : z = y := + (tree_cut_neighbors T ht.isAcyclic x y z hxy hzx.symm (hr z hz)).symm + have hccon : (T.induce C).Connected := by + apply SimpleGraph.Connected.mono (G := (cutVertex T x).induce C) + · intro a b hab; exact hab.1 + · exact ((cutVertex T x).connectedComponentMk y).connected_toSimpleGraph + have hc : (T.induce C).IsTree := ⟨hccon,ht.isAcyclic.induce C⟩ + by_cases he : ∃ z ∈ C, z ≠ y + · obtain ⟨z,hz,hzy⟩ := he + let : Nontrivial C := ⟨⟨⟨z,hz⟩,⟨y,hyC⟩,fun h => hzy (congrArg Subtype.val h)⟩⟩ + obtain ⟨a,b,hab,ha,hb⟩ := hc.exists_ne_and_degree_eq_one + have hex : ∃ a : C, a.val ≠ y ∧ (T.induce C).degree a = 1 := by + by_cases hay : a.val = y + · refine ⟨b,?_,hb⟩ + intro hby + exact hab (Subtype.ext (hay.trans hby.symm)) + · exact ⟨a,hay,ha⟩ + obtain ⟨a,hay,ha⟩ := hex + refine ⟨a.val,fun h => hxC (h ▸ a.property),hr _ a.property,?_⟩ + have hn : T.neighborSet a.val ⊆ C := by + intro w hw + rcases hnbr a.val a.property w hw with rfl | hwc + · exact False.elim (hay (hnx a.val a.property hw)) + · exact hwc + rwa [T.degree_induce_of_neighborSet_subset hn] at ha + · push Not at he + refine ⟨y,hxy.ne.symm,Reachable.refl y,?_⟩ + apply degree_eq_one_iff_existsUnique_adj.mpr + refine ⟨x,hxy.symm,?_⟩ + intro w hw + rcases hnbr y hyC w hw with hwx | hwC + · exact hwx + · exact False.elim (hw.ne (he w hwC).symm) + +theorem pruned_tree_branch_marked [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) + (S : Finset V) (hpr : ∀ z, z ∉ S → 2 ≤ T.degree z) + (x y : V) (hxy : T.Adj x y) : + ∃ z ∈ S, z ≠ x ∧ (cutVertex T x).Reachable y z := by + obtain ⟨z,hzx,hz,hd⟩ := tree_branch_contains_leaf T ht x y hxy + refine ⟨z,?_,hzx,hz⟩ + by_contra hn + have hh := hpr z hn + omega + +theorem tree_three_leaves_branch [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) + (S : Finset V) (hcard : 3 ≤ S.card) (hleaf : ∀ z ∈ S, T.degree z = 1) : + ∃ x, 3 ≤ T.degree x := by + by_contra hn + have hd (x : V) : T.degree x ≤ 2 := by have := not_exists.mp hn x; omega + have hs : (∑ x : V, (T.degree x + (if x ∈ S then 1 else 0))) ≤ + ∑ x : V, (2:ℕ) := by + apply Finset.sum_le_sum + intro x _ + by_cases hx : x ∈ S + · simp only [hx,ite_true,hleaf x hx]; omega + · simpa only [hx,ite_false,add_zero] using hd x + have hsum : (∑ x : V, if x ∈ S then (1:ℕ) else 0) = S.card := by + simp + rw [Finset.sum_add_distrib,hsum,T.sum_degrees_eq_twice_card_edges] at hs + simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] at hs + have he := ht.card_edgeFinset + have hc : S.card ≤ Fintype.card V := Finset.card_le_univ S + omega + +theorem pruned_tree_three_branches [Fintype V] (T : SimpleGraph V) (ht : T.IsTree) + (S : Finset V) (hcard : 3 ≤ S.card) (hleaf : ∀ z ∈ S, T.degree z = 1) + (hpr : ∀ z, z ∉ S → 2 ≤ T.degree z) : + ∃ x a b c, x ∉ S ∧ a ∈ S ∧ b ∈ S ∧ c ∈ S ∧ + a ≠ x ∧ b ≠ x ∧ c ≠ x ∧ + ¬ (cutVertex T x).Reachable a b ∧ + ¬ (cutVertex T x).Reachable a c ∧ + ¬ (cutVertex T x).Reachable b c := by + obtain ⟨x,hx⟩ := tree_three_leaves_branch T ht S hcard hleaf + have hxS : x ∉ S := by intro h; have := hleaf x h; omega + have hnc : 2 < (T.neighborFinset x).card := by simpa using (show 2 < T.degree x by omega) + obtain ⟨u,v,w,hu,hv,hw,huv,huw,hvw⟩ := Finset.two_lt_card_iff.mp hnc + have hau := (T.mem_neighborFinset x u).mp hu + have hav := (T.mem_neighborFinset x v).mp hv + have haw := (T.mem_neighborFinset x w).mp hw + obtain ⟨a,ha,hax,hua⟩ := pruned_tree_branch_marked T ht S hpr x u hau + obtain ⟨b,hb,hbx,hvb⟩ := pruned_tree_branch_marked T ht S hpr x v hav + obtain ⟨c,hc,hcx,hwc⟩ := pruned_tree_branch_marked T ht S hpr x w haw + refine ⟨x,a,b,c,hxS,ha,hb,hc,hax,hbx,hcx,?_,?_,?_⟩ + · intro h; exact huv (tree_cut_neighbors T ht.isAcyclic x u v hau hav + (hua.trans (h.trans hvb.symm))) + · intro h; exact huw (tree_cut_neighbors T ht.isAcyclic x u w hau haw + (hua.trans (h.trans hwc.symm))) + · intro h; exact hvw (tree_cut_neighbors T ht.isAcyclic x v w hav haw + (hvb.trans (h.trans hwc.symm))) +end Percolation + +namespace Percolation +open SimpleGraph +universe u v w +variable {V : Type u} {E : Type v} {W : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem exists_cluster_retraction (G : BondGraph V E) (η : Set E) (f : W ↪ V) + (hsep : ∀ a b, Conn G η (f a) (f b) → a = b) (x : W) : + ∃ r : V → W, (∀ a, r (f a) = a) ∧ + ∀ a b, Conn G η a b → r a = r b := by + let r : V → W := fun y => if h : ∃ z, Conn G η (f z) y then h.choose else x + have hval (y : V) (z : W) (hz : Conn G η (f z) y) : r y = z := by + have hex : ∃ z, Conn G η (f z) y := ⟨z,hz⟩ + dsimp [r] + rw [dite_eq_left hex] + exact hsep _ _ (conn_trans G η hex.choose_spec (conn_symm G η hz)) + refine ⟨r,fun a => hval _ _ (conn_refl G η _),?_⟩ + intro a b hab + by_cases ha : ∃ z, Conn G η (f z) a + · obtain ⟨z,hz⟩ := ha + rw [hval a z hz,hval b z (conn_trans G η hz hab)] + · have hb : ¬ ∃ z, Conn G η (f z) b := by + rintro ⟨z,hz⟩ + exact ha ⟨z,conn_trans G η hz (conn_symm G η hab)⟩ + simp only [r,dite_eq_right ha,dite_eq_right hb] + +theorem glued_cut_conn (G : BondGraph V E) (η P : Set E) (T : SimpleGraph W) + (f : W ↪ V) (r : V → W) (hr : ∀ a, r (f a) = a) + (hη : ∀ a b, Conn G η a b → r a = r b) + (hP : ∀ e ∈ P, ∃ a b, T.Adj a b ∧ G e = s(f a,f b)) + (x : W) {a b : V} (hab : Conn G (cutConfig G (η ∪ P) (f x)) a b) : + (cutVertex T x).Reachable (r a) (r b) := by + induction hab with + | refl => exact .refl _ + | @tail a b hab hed ih => + obtain ⟨e,⟨he,hx⟩,hGe⟩ := hed + rcases he with he | he + · have hh := hη a b ((conn_refl G η a).tail ⟨e,he,hGe⟩) + rwa [←hh] + · obtain ⟨u,v,huv,heq⟩ := hP e he + have hne : u ≠ x ∧ v ≠ x := by + rw [heq] at hx + simpa [Sym2.mem_iff,f.injective.eq_iff,eq_comm] using hx + have hkv : (cutVertex T x).Adj u v := ⟨huv,hne⟩ + have habuv := Sym2.eq_iff.mp (hGe.symm.trans heq) + rcases habuv with ⟨rfl,rfl⟩ | ⟨rfl,rfl⟩ + · rw [hr] at ih ⊢ + exact ih.trans hkv.reachable + · rw [hr] at ih ⊢ + exact ih.trans hkv.symm.reachable + +theorem glued_conn (G : BondGraph V E) (ω : Set E) (T : SimpleGraph W) + (f : W → V) (hT : T.Connected) + (he : ∀ a b, T.Adj a b → ∃ e ∈ ω, G e = s(f a,f b)) (a b : W) : + Conn G ω (f a) (f b) := by + obtain ⟨p⟩ := hT a b + induction p with + | nil => exact conn_refl G ω _ + | @cons a b c hab p ih => + exact conn_trans G ω ((conn_refl G ω _).tail (he a b hab)) ih + +end Percolation + +namespace Percolation +open SimpleGraph +universe u +variable {V : Type u} +attribute [local instance] Classical.propDecidable Classical.decEq + +def terminalGraph (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) : SimpleGraph V where + Adj a b := H.Adj a b ∧ ((a ∈ A ∧ b ∈ A) ∨ + ∃ i, (a = v i ∧ b = w i) ∨ (a = w i ∧ b = v i)) + symm := ⟨by + intro a b h + refine ⟨h.1.symm,?_⟩ + rcases h.2 with h | ⟨i,h|h⟩ + · exact Or.inl h.symm + · exact Or.inr ⟨i,Or.inr h.symm⟩ + · exact Or.inr ⟨i,Or.inl h.symm⟩⟩ + loopless := ⟨fun a h => H.loopless.irrefl a h.1⟩ + +theorem terminalGraph_touch (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) + (hv : ∀ i, v i ∈ A) {a b : V} (h : (terminalGraph H A v w).Adj a b) : + a ∈ A ∨ b ∈ A := by + rcases h.2 with h | ⟨i,h|h⟩ + · exact Or.inl h.1 + · exact Or.inl (h.1 ▸ hv i) + · exact Or.inr (h.2 ▸ hv i) + +theorem terminalGraph_leaf (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) + (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) + (i : Fin 3) {y : V} (h : (terminalGraph H A v w).Adj (w i) y) : y = v i := by + rcases h.2 with h | ⟨j,h|h⟩ + · exact False.elim (hw i h.1) + · exact False.elim (hw i (h.1 ▸ hv j)) + · have hij := hwi h.1 + simpa only [hij] using h.2 + +theorem terminalGraph_connected (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) + (hv : ∀ i, v i ∈ A) (hadj : ∀ i, H.Adj (v i) (w i)) + (hA : (H.induce (A:Set V)).Connected) : + ((terminalGraph H A v w).induce ((A ∪ Finset.univ.image w : Finset V):Set V)).Connected := by + let D := A ∪ Finset.univ.image w + let K := terminalGraph H A v w + have hAD : A ⊆ D := Finset.subset_union_left + let f : (H.induce (A:Set V)) →g (K.induce (D:Set V)) := + ⟨fun a => ⟨a.val,hAD a.property⟩,fun {a b} hab => ⟨hab,Or.inl ⟨a.property,b.property⟩⟩⟩ + let z : (D:Set V) := ⟨v 0,hAD (hv 0)⟩ + have connA (a : V) (ha : a ∈ A) : (K.induce (D:Set V)).Reachable ⟨a,hAD ha⟩ z := + (hA ⟨a,ha⟩ ⟨v 0,hv 0⟩).map f + have connD (a : (D:Set V)) : (K.induce (D:Set V)).Reachable a z := by + rcases Finset.mem_union.mp a.property with ha | ha + · exact connA a.val ha + · obtain ⟨i,_,hi⟩ := Finset.mem_image.mp ha + have hK : (K.induce (D:Set V)).Adj a ⟨v i,hAD (hv i)⟩ := by + change K.Adj a.val (v i) + rw [←hi] + exact ⟨(hadj i).symm,Or.inr ⟨i,Or.inr ⟨rfl,rfl⟩⟩⟩ + exact hK.reachable.trans (connA _ (hv i)) + let : Nonempty (D:Set V) := ⟨z⟩ + exact ⟨fun a b => (connD a).trans (connD b).symm⟩ + +theorem exists_terminal_tree (H : SimpleGraph V) (A : Finset V) (v w : Fin 3 → V) + (hv : ∀ i, v i ∈ A) (hw : ∀ i, w i ∉ A) (hwi : Function.Injective w) + (hadj : ∀ i, H.Adj (v i) (w i)) + (hA : (H.induce (A:Set V)).Connected) : + ∃ D : Finset V, D ⊆ A ∪ Finset.univ.image w ∧ Finset.univ.image w ⊆ D ∧ + ∃ T : SimpleGraph (D:Set V), T ≤ (terminalGraph H A v w).induce (D:Set V) ∧ + T.IsTree ∧ ∃ x a b c : (D:Set V), x.val ∈ A ∧ + a.val ∈ Finset.univ.image w ∧ b.val ∈ Finset.univ.image w ∧ + c.val ∈ Finset.univ.image w ∧ + ¬ (cutVertex T x).Reachable a b ∧ + ¬ (cutVertex T x).Reachable a c ∧ + ¬ (cutVertex T x).Reachable b c := by + let S := Finset.univ.image w + have hS : S.Nonempty := ⟨w 0,Finset.mem_image.mpr ⟨0,Finset.mem_univ _,rfl⟩⟩ + obtain ⟨D,hD,hSD,T,hTK,hT,hpr⟩ := exists_pruned_connector + (terminalGraph H A v w) S (A ∪ S) hS Finset.subset_union_right + (terminalGraph_connected H A v w hv hadj hA) + let s : Fin 3 → (D:Set V) := fun i => ⟨w i,hSD (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩)⟩ + have hsi : Function.Injective s := fun _ _ h => hwi (congrArg Subtype.val h) + let S' := Finset.univ.image s + have hS' (z : (D:Set V)) : z ∈ S' ↔ z.val ∈ S := by + simp only [S',S,Finset.mem_image,Finset.mem_univ,true_and] + constructor + · rintro ⟨i,rfl⟩; exact ⟨i,rfl⟩ + · rintro ⟨i,hi⟩; exact ⟨i,Subtype.ext hi⟩ + have hcard : S'.card = 3 := by + rw [Finset.card_image_of_injective _ hsi] + simp + let : Nontrivial (D:Set V) := ⟨⟨s 0,s 1,fun h => by have := hsi h; norm_num at this⟩⟩ + have hleaf (z : (D:Set V)) (hz : z ∈ S') : T.degree z = 1 := by + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp ((hS' z).mp hz) + have hpos : 0 < T.degree z := lt_of_lt_of_le + hT.connected.preconnected.minDegree_pos_of_nontrivial (T.minDegree_le_degree z) + obtain ⟨a,ha⟩ := (T.degree_pos_iff_exists_adj z).mp hpos + apply degree_eq_one_iff_existsUnique_adj.mpr + refine ⟨a,ha,?_⟩ + intro b hb + apply Subtype.ext + have ha' : a.val = v i := terminalGraph_leaf H A v w hv hw hwi i (by rw [hi]; exact hTK ha) + have hb' : b.val = v i := terminalGraph_leaf H A v w hv hw hwi i (by rw [hi]; exact hTK hb) + exact hb'.trans ha'.symm + obtain ⟨x,a,b,c,hx,ha,hb,hc,_,_,_,hab,hac,hbc⟩ := + pruned_tree_three_branches T hT S' (by omega) hleaf + (fun z hz => hpr z (fun h => hz ((hS' z).mpr h))) + have hxA : x.val ∈ A := by + rcases Finset.mem_union.mp (hD x.property) with h | h + · exact h + · exact False.elim (hx ((hS' x).mpr h)) + exact ⟨D,hD,hSD,T,hTK,hT,x,a,b,c,hxA,(hS' a).mp ha,(hS' b).mp hb, + (hS' c).mp hc,hab,hac,hbc⟩ +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/Vertices.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/Vertices.lean index b1c507254a603155ce57fdcc0cccdbca81314f2e..0d07a4ec7944eb3bad847d8079bf03ce187be218 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/Vertices.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/Vertices.lean @@ -1,151 +1,151 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.NearestMass -import OAI.Probability.UnimodularPercolation.Encounter.Transport - -namespace OAI - -/-! Encounter vertices and infinite open branches. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -def cutConfig (G : BondGraph V E) (ω : Set E) (x : V) : Set E := - {e | e ∈ ω ∧ x ∉ G e} - -theorem measurable_cutConfig (G : BondGraph V E) (x : V) : - Measurable (fun ω => cutConfig G ω x) := by - apply measurable_setOfPred.comp (Measurable.of_eval ?_) - intro e - exact (measurable_set_mem e).and measurable_const - -theorem cutVertex_open (G : BondGraph V E) (ω : Set E) (x : V) : - cutVertex (openSimpleGraph G ω) x = openSimpleGraph G (cutConfig G ω x) := by - ext a b - change ((a ≠ b ∧ ∃ e ∈ ω, G e = s(a,b)) ∧ a ≠ x ∧ b ≠ x) ↔ - (a ≠ b ∧ ∃ e, (e ∈ ω ∧ x ∉ G e) ∧ G e = s(a,b)) - constructor - · rintro ⟨⟨hab,e,he,hGe⟩,hax,hbx⟩ - exact ⟨hab,e,⟨he,by rw [hGe]; simpa [Sym2.mem_iff,eq_comm] using And.intro hax hbx⟩,hGe⟩ - · rintro ⟨hab,e,⟨he,hx⟩,hGe⟩ - rw [hGe] at hx - have hh : a ≠ x ∧ b ≠ x := by simpa [Sym2.mem_iff,eq_comm] using hx - exact ⟨⟨hab,e,he,hGe⟩,hh⟩ - -theorem cutConfig_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω : Set E) (x : V) : - cutConfig G (b ⁻¹' ω) x = b ⁻¹' cutConfig G ω (a x) := by - ext e - simp only [cutConfig,Set.mem_ofPred_eq,Set.mem_preimage,hab e] - rw [Sym2.mem_map] - simp only [a.injective.eq_iff,exists_eq_right] - -def IsEncounter (G : BondGraph V E) (ω : Set E) (x : V) : Prop := - ∃ a b c : V, - Conn G ω x a ∧ Conn G ω x b ∧ Conn G ω x c ∧ - (cluster G (cutConfig G ω x) a).Infinite ∧ - (cluster G (cutConfig G ω x) b).Infinite ∧ - (cluster G (cutConfig G ω x) c).Infinite ∧ - ¬ Conn G (cutConfig G ω x) a b ∧ - ¬ Conn G (cutConfig G ω x) a c ∧ - ¬ Conn G (cutConfig G ω x) b c - -def encounters (G : BondGraph V E) (ω : Set E) : Set V := {x | IsEncounter G ω x} - -theorem measurableSet_isEncounter [Countable V] [Countable E] - (G : BondGraph V E) (x : V) : MeasurableSet {ω | IsEncounter G ω x} := by - simp only [IsEncounter,Set.ofPred_exists,Set.ofPred_and] - apply MeasurableSet.iUnion - intro a - apply MeasurableSet.iUnion - intro b - apply MeasurableSet.iUnion - intro c - exact (measurableSet_conn G x a).inter ((measurableSet_conn G x b).inter - ((measurableSet_conn G x c).inter - (((measurableSet_infinite_cluster G a).preimage (measurable_cutConfig G x)).inter - (((measurableSet_infinite_cluster G b).preimage (measurable_cutConfig G x)).inter - (((measurableSet_infinite_cluster G c).preimage (measurable_cutConfig G x)).inter - (((measurableSet_conn G a b).preimage (measurable_cutConfig G x)).compl.inter - (((measurableSet_conn G a c).preimage (measurable_cutConfig G x)).compl.inter - ((measurableSet_conn G b c).preimage (measurable_cutConfig G x)).compl))))))) - -theorem isEncounter_aut_iff (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω : Set E) (x : V) : - IsEncounter G (b ⁻¹' ω) x ↔ IsEncounter G ω (a x) := by - have hc y z : Conn G (cutConfig G (b ⁻¹' ω) x) y z ↔ - Conn G (cutConfig G ω (a x)) (a y) (a z) := by - rw [cutConfig_aut G a b hab] - exact conn_aut_iff G hab _ y z - have hi y : (cluster G (cutConfig G (b ⁻¹' ω) x) y).Infinite ↔ - (cluster G (cutConfig G ω (a x)) (a y)).Infinite := by - rw [cutConfig_aut G a b hab,←cluster_aut G hab] - exact (Set.infinite_image_iff a.injective.injOn).symm - constructor - · rintro ⟨u,v,w,hxu,hxv,hxw,hu,hv,hw,huv,huw,hvw⟩ - exact ⟨a u,a v,a w,(conn_aut_iff G hab ω x u).mp hxu, - (conn_aut_iff G hab ω x v).mp hxv,(conn_aut_iff G hab ω x w).mp hxw, - (hi u).mp hu,(hi v).mp hv,(hi w).mp hw, - fun h => huv ((hc u v).mpr h),fun h => huw ((hc u w).mpr h),fun h => hvw ((hc v w).mpr h)⟩ - · rintro ⟨u,v,w,hxu,hxv,hxw,hu,hv,hw,huv,huw,hvw⟩ - refine ⟨a.symm u,a.symm v,a.symm w,?_,?_,?_,?_,?_,?_,?_,?_,?_⟩ - · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxu) - · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxv) - · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxw) - · exact (hi _).mpr (by simpa using hu) - · exact (hi _).mpr (by simpa using hv) - · exact (hi _).mpr (by simpa using hw) - · intro h; exact huv (by simpa using (hc _ _).mp h) - · intro h; exact huw (by simpa using (hc _ _).mp h) - · intro h; exact hvw (by simpa using (hc _ _).mp h) - -theorem encounter_branch_contains_of_finite_incoming (G : BondGraph V E) - (ω : Set E) (x a : V) (hx : IsEncounter G ω x) (hxa : Conn G ω x a) - (hInf : (cluster G (cutConfig G ω x) a).Infinite) - (hin : ∑' y, nearestMass G (encounters G) ω y x < ⊤) : - ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z := by - by_contra hno - have hm (y : V) (hy : y ∈ cluster G (cutConfig G ω x) a) : - nearestMass G (encounters G) ω y x = 1 := by - apply nearestMass_eq_one - apply closest_eq_singleton_of_branch (openSimpleGraph G ω) (encounters G ω) hx - · apply (conn_iff_reachable G ω y x).mp - exact conn_symm G ω (conn_trans G ω hxa (conn_mono G (fun e he => he.1) hy)) - · intro z hz hzx hcut - apply hno - refine ⟨z,?_,hzx,hz⟩ - rw [cutVertex_open] at hcut - exact conn_trans G _ hy ((conn_iff_reachable G _ y z).mpr hcut) - have he := incoming_top_of_infinite (fun y => nearestMass G (encounters G) ω y x) - (cluster G (cutConfig G ω x) a) hInf hm - rw [he] at hin - exact lt_irrefl _ hin - -theorem encounter_branches_ae [Countable V] [Countable E] [Fintype ι] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (p : unitInterval) : - ∀ᵐ ω ∂law p, ∀ x, IsEncounter G ω x → ∀ a, Conn G ω x a → - (cluster G (cutConfig G ω x) a).Infinite → - ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z := by - have hin := incoming_finite_ae_all G hconn hloc root weight htr hw hw1 hcov p - (nearestMass G (encounters G)) - (measurable_nearestMass G (encounters G) (measurableSet_isEncounter G)) - (nearestMass_aut G (encounters G) (isEncounter_aut_iff G)) - (nearestMass_row_le G hloc (encounters G)) - filter_upwards [hin] with ω hω - intro x hx a hxa hi - exact encounter_branch_contains_of_finite_incoming G ω x a hx hxa hi (hω x) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.NearestMass +import OAI.Probability.UnimodularPercolation.Encounter.Transport + +namespace OAI + +/-! Encounter vertices and infinite open branches. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +def cutConfig (G : BondGraph V E) (ω : Set E) (x : V) : Set E := + {e | e ∈ ω ∧ x ∉ G e} + +theorem measurable_cutConfig (G : BondGraph V E) (x : V) : + Measurable (fun ω => cutConfig G ω x) := by + apply measurable_setOfPred.comp (Measurable.of_eval ?_) + intro e + exact (measurable_set_mem e).and measurable_const + +theorem cutVertex_open (G : BondGraph V E) (ω : Set E) (x : V) : + cutVertex (openSimpleGraph G ω) x = openSimpleGraph G (cutConfig G ω x) := by + ext a b + change ((a ≠ b ∧ ∃ e ∈ ω, G e = s(a,b)) ∧ a ≠ x ∧ b ≠ x) ↔ + (a ≠ b ∧ ∃ e, (e ∈ ω ∧ x ∉ G e) ∧ G e = s(a,b)) + constructor + · rintro ⟨⟨hab,e,he,hGe⟩,hax,hbx⟩ + exact ⟨hab,e,⟨he,by rw [hGe]; simpa [Sym2.mem_iff,eq_comm] using And.intro hax hbx⟩,hGe⟩ + · rintro ⟨hab,e,⟨he,hx⟩,hGe⟩ + rw [hGe] at hx + have hh : a ≠ x ∧ b ≠ x := by simpa [Sym2.mem_iff,eq_comm] using hx + exact ⟨⟨hab,e,he,hGe⟩,hh⟩ + +theorem cutConfig_aut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω : Set E) (x : V) : + cutConfig G (b ⁻¹' ω) x = b ⁻¹' cutConfig G ω (a x) := by + ext e + simp only [cutConfig,Set.mem_ofPred_eq,Set.mem_preimage,hab e] + rw [Sym2.mem_map] + simp only [a.injective.eq_iff,exists_eq_right] + +def IsEncounter (G : BondGraph V E) (ω : Set E) (x : V) : Prop := + ∃ a b c : V, + Conn G ω x a ∧ Conn G ω x b ∧ Conn G ω x c ∧ + (cluster G (cutConfig G ω x) a).Infinite ∧ + (cluster G (cutConfig G ω x) b).Infinite ∧ + (cluster G (cutConfig G ω x) c).Infinite ∧ + ¬ Conn G (cutConfig G ω x) a b ∧ + ¬ Conn G (cutConfig G ω x) a c ∧ + ¬ Conn G (cutConfig G ω x) b c + +def encounters (G : BondGraph V E) (ω : Set E) : Set V := {x | IsEncounter G ω x} + +theorem measurableSet_isEncounter [Countable V] [Countable E] + (G : BondGraph V E) (x : V) : MeasurableSet {ω | IsEncounter G ω x} := by + simp only [IsEncounter,Set.ofPred_exists,Set.ofPred_and] + apply MeasurableSet.iUnion + intro a + apply MeasurableSet.iUnion + intro b + apply MeasurableSet.iUnion + intro c + exact (measurableSet_conn G x a).inter ((measurableSet_conn G x b).inter + ((measurableSet_conn G x c).inter + (((measurableSet_infinite_cluster G a).preimage (measurable_cutConfig G x)).inter + (((measurableSet_infinite_cluster G b).preimage (measurable_cutConfig G x)).inter + (((measurableSet_infinite_cluster G c).preimage (measurable_cutConfig G x)).inter + (((measurableSet_conn G a b).preimage (measurable_cutConfig G x)).compl.inter + (((measurableSet_conn G a c).preimage (measurable_cutConfig G x)).compl.inter + ((measurableSet_conn G b c).preimage (measurable_cutConfig G x)).compl))))))) + +theorem isEncounter_aut_iff (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω : Set E) (x : V) : + IsEncounter G (b ⁻¹' ω) x ↔ IsEncounter G ω (a x) := by + have hc y z : Conn G (cutConfig G (b ⁻¹' ω) x) y z ↔ + Conn G (cutConfig G ω (a x)) (a y) (a z) := by + rw [cutConfig_aut G a b hab] + exact conn_aut_iff G hab _ y z + have hi y : (cluster G (cutConfig G (b ⁻¹' ω) x) y).Infinite ↔ + (cluster G (cutConfig G ω (a x)) (a y)).Infinite := by + rw [cutConfig_aut G a b hab,←cluster_aut G hab] + exact (Set.infinite_image_iff a.injective.injOn).symm + constructor + · rintro ⟨u,v,w,hxu,hxv,hxw,hu,hv,hw,huv,huw,hvw⟩ + exact ⟨a u,a v,a w,(conn_aut_iff G hab ω x u).mp hxu, + (conn_aut_iff G hab ω x v).mp hxv,(conn_aut_iff G hab ω x w).mp hxw, + (hi u).mp hu,(hi v).mp hv,(hi w).mp hw, + fun h => huv ((hc u v).mpr h),fun h => huw ((hc u w).mpr h),fun h => hvw ((hc v w).mpr h)⟩ + · rintro ⟨u,v,w,hxu,hxv,hxw,hu,hv,hw,huv,huw,hvw⟩ + refine ⟨a.symm u,a.symm v,a.symm w,?_,?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxu) + · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxv) + · exact (conn_aut_iff G hab ω x _).mpr (by simpa using hxw) + · exact (hi _).mpr (by simpa using hu) + · exact (hi _).mpr (by simpa using hv) + · exact (hi _).mpr (by simpa using hw) + · intro h; exact huv (by simpa using (hc _ _).mp h) + · intro h; exact huw (by simpa using (hc _ _).mp h) + · intro h; exact hvw (by simpa using (hc _ _).mp h) + +theorem encounter_branch_contains_of_finite_incoming (G : BondGraph V E) + (ω : Set E) (x a : V) (hx : IsEncounter G ω x) (hxa : Conn G ω x a) + (hInf : (cluster G (cutConfig G ω x) a).Infinite) + (hin : ∑' y, nearestMass G (encounters G) ω y x < ⊤) : + ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z := by + by_contra hno + have hm (y : V) (hy : y ∈ cluster G (cutConfig G ω x) a) : + nearestMass G (encounters G) ω y x = 1 := by + apply nearestMass_eq_one + apply closest_eq_singleton_of_branch (openSimpleGraph G ω) (encounters G ω) hx + · apply (conn_iff_reachable G ω y x).mp + exact conn_symm G ω (conn_trans G ω hxa (conn_mono G (fun e he => he.1) hy)) + · intro z hz hzx hcut + apply hno + refine ⟨z,?_,hzx,hz⟩ + rw [cutVertex_open] at hcut + exact conn_trans G _ hy ((conn_iff_reachable G _ y z).mpr hcut) + have he := incoming_top_of_infinite (fun y => nearestMass G (encounters G) ω y x) + (cluster G (cutConfig G ω x) a) hInf hm + rw [he] at hin + exact lt_irrefl _ hin + +theorem encounter_branches_ae [Countable V] [Countable E] [Fintype ι] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (p : unitInterval) : + ∀ᵐ ω ∂law p, ∀ x, IsEncounter G ω x → ∀ a, Conn G ω x a → + (cluster G (cutConfig G ω x) a).Infinite → + ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z := by + have hin := incoming_finite_ae_all G hconn hloc root weight htr hw hw1 hcov p + (nearestMass G (encounters G)) + (measurable_nearestMass G (encounters G) (measurableSet_isEncounter G)) + (nearestMass_aut G (encounters G) (isEncounter_aut_iff G)) + (nearestMass_row_le G hloc (encounters G)) + filter_upwards [hin] with ω hω + intro x hx a hxa hi + exact encounter_branch_contains_of_finite_incoming G ω x a hx hxa hi (hω x) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Encounter/ZeroIntensity.lean b/lean/OAI/Probability/UnimodularPercolation/Encounter/ZeroIntensity.lean index bb9e0c10230fa6c080b6e08767f08f70627dc3ca..0231a29486b68fb0c0dc2e2fd6161bdcc15cb7a8 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Encounter/ZeroIntensity.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Encounter/ZeroIntensity.lean @@ -1,234 +1,234 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Encounter.Counts - -namespace OAI - -/-! Critical limits and zero encounter intensity. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory SimpleGraph Filter Topology -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem branchCount_three (H : SimpleGraph V) (S : Finset V) (x a b c : V) - (ha : a ∈ S) (hb : b ∈ S) (hc : c ∈ S) - (hax : a ≠ x) (hbx : b ≠ x) (hcx : c ≠ x) - (hab : ¬(cutVertex H x).Reachable a b) - (hac : ¬(cutVertex H x).Reachable a c) - (hbc : ¬(cutVertex H x).Reachable b c) : 3 ≤ branchCount H S x := by - let f := (cutVertex H x).connectedComponentMk - have hab' : f a ≠ f b := fun h => hab (ConnectedComponent.exact h) - have hac' : f a ≠ f c := fun h => hac (ConnectedComponent.exact h) - have hbc' : f b ≠ f c := fun h => hbc (ConnectedComponent.exact h) - have hs : ({f a,f b,f c}:Finset _) ⊆ (S.erase x).image f := by - intro y hy - simp only [Finset.mem_insert,Finset.mem_singleton] at hy - rcases hy with rfl | rfl | rfl - · exact Finset.mem_image.mpr ⟨a,Finset.mem_erase.mpr ⟨hax,ha⟩,rfl⟩ - · exact Finset.mem_image.mpr ⟨b,Finset.mem_erase.mpr ⟨hbx,hb⟩,rfl⟩ - · exact Finset.mem_image.mpr ⟨c,Finset.mem_erase.mpr ⟨hcx,hc⟩,rfl⟩ - have hh := Finset.card_le_card hs - have hcard : ({f a,f b,f c}:Finset _).card = 3 := by simp [hab',hac',hbc'] - rw [hcard] at hh - exact hh - -theorem eventually_conn_of_limit (G : BondGraph V E) (l : E → unitInterval) - (p : unitInterval) (q : ℕ → unitInterval) (hmono : Monotone q) - (hq : ∀ n, q n ≤ p) (hlim : Tendsto q atTop (𝓝 p)) (hne : ∀ e, l e ≠ p) - {x y : V} (hxy : Conn G (openEdges l p) x y) : - ∀ᶠ n in atTop, Conn G (openEdges l (q n)) x y := by - rw [openEdges_eq_iUnion_of_tendsto l p hne q hq hlim,conn_iUnion_iff G _ - (fun m n hmn => openEdges_mono l (hmono hmn))] at hxy - obtain ⟨n,hn⟩ := hxy - exact eventually_atTop.mpr ⟨n,fun m hm => conn_mono G (openEdges_mono l (hmono hm)) hn⟩ - -theorem eventually_encounterCount_three (G : BondGraph V E) (l : E → unitInterval) - (p : unitInterval) (q : ℕ → unitInterval) (hmono : Monotone q) - (hq : ∀ n, q n ≤ p) (hlim : Tendsto q atTop (𝓝 p)) (hne : ∀ e, l e ≠ p) - (hfin : ∀ n x, (cluster G (openEdges l (q n)) x).Finite) - (hbranch : ∀ x, IsEncounter G (openEdges l p) x → ∀ a, - Conn G (openEdges l p) x a → (cluster G (cutConfig G (openEdges l p) x) a).Infinite → - ∃ z ∈ cluster G (cutConfig G (openEdges l p) x) a, z ≠ x ∧ IsEncounter G (openEdges l p) z) - (x : V) (hx : IsEncounter G (openEdges l p) x) : - ∀ᶠ n in atTop, 3 ≤ encounterCount G (openEdges l p) (openEdges l (q n)) x := by - obtain ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ := hx - obtain ⟨a',haa',hax,ha'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ a hxa ha - obtain ⟨b',hbb',hbx,hb'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ b hxb hb - obtain ⟨c',hcc',hcx,hc'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ c hxc hc - have hx' : IsEncounter G (openEdges l p) x := ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ - have hac' : Conn G (openEdges l p) x a' := conn_trans G _ hxa (conn_mono G (fun _ h => h.1) haa') - have hbc' : Conn G (openEdges l p) x b' := conn_trans G _ hxb (conn_mono G (fun _ h => h.1) hbb') - have hxc' : Conn G (openEdges l p) x c' := conn_trans G _ hxc (conn_mono G (fun _ h => h.1) hcc') - filter_upwards [eventually_conn_of_limit G l p q hmono hq hlim hne hac', - eventually_conn_of_limit G l p q hmono hq hlim hne hbc', - eventually_conn_of_limit G l p q hmono hq hlim hne hxc'] with n han hbn hcn - rw [encounterCount,ite_eq_left hx'] - have hm (z : V) (hz : Conn G (openEdges l (q n)) x z) (he : IsEncounter G (openEdges l p) z) : - z ∈ markedCluster G (openEdges l p) (openEdges l (q n)) x := by - apply Finset.mem_filter.mpr - refine ⟨?_,he⟩ - have ht : z ∈ cluster G (openEdges l (q n)) x := hz - rwa [←clusterFinset_coe G _ x (hfin n x)] at ht - apply branchCount_three _ _ x a' b' c' (hm _ han ha') (hm _ hbn hb') (hm _ hcn hc') hax hbx hcx - · intro ht - rw [cutVertex_open] at ht - exact hab (conn_trans G _ haa' (conn_trans G _ ((conn_iff_reachable G _ a' b').mpr ht) (conn_symm G _ hbb'))) - · intro ht - rw [cutVertex_open] at ht - exact hac (conn_trans G _ haa' (conn_trans G _ ((conn_iff_reachable G _ a' c').mpr ht) (conn_symm G _ hcc'))) - · intro ht - rw [cutVertex_open] at ht - exact hbc (conn_trans G _ hbb' (conn_trans G _ ((conn_iff_reachable G _ b' c').mpr ht) (conn_symm G _ hcc'))) - -end Percolation - -namespace Percolation -open MeasureTheory SimpleGraph Filter Topology -open scoped ENNReal -universe u v w -variable {V : Type u} {E : Type v} {ι : Type w} -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Fintype ι] - -theorem critical_encounter_density_zero - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, - (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ∂labelLaw) = 0 := by - obtain ⟨q,hmono,hq,hlim⟩ := exists_seq_strictMono_tendsto' hp - let d (l : E → unitInterval) : ℝ≥0∞ := ∑ i, ENNReal.ofReal (weight i) * - if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0 - let f (n : ℕ) (l : E → unitInterval) : ℝ≥0∞ := ∑ i, ENNReal.ofReal (weight i) * - (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i) : ℝ≥0∞) - have hd : Measurable d := by - apply Finset.measurable_sum - intro i _ - exact measurable_const.mul (Measurable.ite ((measurableSet_isEncounter G (root i)).preimage - (measurable_openEdges (pc G))) measurable_const measurable_const) - have hf n : Measurable (f n) := by - apply Finset.measurable_sum - intro i _ - exact measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp - (measurable_encounterCount G (pc G) (q n) (root i))) - have hdint : (∫⁻ l, d l ∂labelLaw) = ∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, - (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ∂labelLaw := by - rw [show d = _ from rfl,lintegral_finsetSum] - · apply Finset.sum_congr rfl - intro i _ - exact lintegral_const_mul' _ _ ENNReal.ofReal_ne_top - · intro i _ - exact measurable_const.mul (Measurable.ite ((measurableSet_isEncounter G (root i)).preimage - (measurable_openEdges (pc G))) measurable_const measurable_const) - have hbound n : (∫⁻ l, f n l ∂labelLaw) ≤ 2 * ∫⁻ l, d l ∂labelLaw := by - rw [hdint,show f n = _ from rfl,lintegral_finsetSum] - · simp_rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] - exact expected_encounterCount_le G hconn hloc root weight htr (fun i => (hw i).le) - (pc G) (q n) (hq n).2.le (fun x => subcritical_cluster_finite_ae G (q n) (hq n).2 x) - · intro i _ - exact measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp - (measurable_encounterCount G (pc G) (q n) (root i))) - have hfl : ∀ᵐ l ∂labelLaw, ∀ n x, (cluster G (openEdges l (q n)) x).Finite := - ae_all_iff.mpr fun n => ae_all_iff.mpr fun x => label_cluster_finite_ae_subcritical G (q n) (hq n).2 x - have hbl : ∀ᵐ l ∂labelLaw, ∀ x, IsEncounter G (openEdges l (pc G)) x → ∀ a, - Conn G (openEdges l (pc G)) x a → (cluster G (cutConfig G (openEdges l (pc G)) x) a).Infinite → - ∃ z ∈ cluster G (cutConfig G (openEdges l (pc G)) x) a, z ≠ x ∧ IsEncounter G (openEdges l (pc G)) z := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => ∀ x, IsEncounter G ω x → ∀ a, - Conn G ω x a → (cluster G (cutConfig G ω x) a).Infinite → - ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z) - (measurable_openEdges (pc G)).aemeasurable - rw [map_openEdges] - exact encounter_branches_ae G hconn hloc root weight htr hw hw1 hcov (pc G) - have hlow : ∀ᵐ l ∂labelLaw, 3 * d l ≤ liminf (fun n => f n l) atTop := by - filter_upwards [hfl,hbl,ae_labels_ne (E := E) (pc G)] with l hl hb hn - refine le_liminf_of_le (by isBoundedDefault) ?_ - have he (i : ι) : ∀ᶠ n in atTop, - (3:ℝ≥0∞) * (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ≤ - (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i) : ℝ≥0∞) := by - by_cases hi : IsEncounter G (openEdges l (pc G)) (root i) - · filter_upwards [eventually_encounterCount_three G l (pc G) q hmono.monotone - (fun n => (hq n).2.le) hlim hn hl hb (root i) hi] with n hnc - simpa only [ite_eq_left hi,mul_one] using (show (3:ℝ≥0∞) ≤ (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i):ℝ≥0∞) from by exact_mod_cast hnc) - · filter_upwards [] with n - simp only [ite_eq_right hi,mul_zero,zero_le] - filter_upwards [(eventually_all_finset (Finset.univ : Finset ι)).mpr (fun i _ => he i)] with n hnn - dsimp [d,f] - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro i hi - rw [←mul_assoc,mul_comm (3:ℝ≥0∞),mul_assoc] - exact mul_le_mul_right (hnn i hi) _ - have hineq : 3 * (∫⁻ l, d l ∂labelLaw) ≤ 2 * ∫⁻ l, d l ∂labelLaw := by - calc - _ = ∫⁻ l, 3 * d l ∂labelLaw := (lintegral_const_mul' _ _ ENNReal.ofNat_ne_top).symm - _ ≤ ∫⁻ l, liminf (fun n => f n l) atTop ∂labelLaw := lintegral_mono_ae hlow - _ ≤ liminf (fun n => ∫⁻ l, f n l ∂labelLaw) atTop := lintegral_liminf_le hf - _ ≤ _ := by - refine liminf_le_of_le (by isBoundedDefault) ?_ - intro b hb - obtain ⟨n,hn⟩ := hb.exists - exact hn.trans (hbound n) - have hdle (l : E → unitInterval) : d l ≤ 1 := by - calc - _ ≤ ∑ i, ENNReal.ofReal (weight i) * 1 := by - apply Finset.sum_le_sum - intro i _ - apply mul_le_mul_right - split_ifs <;> simp - _ = 1 := by - simp only [mul_one,←ENNReal.ofReal_sum_of_nonneg (fun i _ => (hw i).le),hw1,ENNReal.ofReal_one] - have hdf : (∫⁻ l, d l ∂labelLaw) ≠ ⊤ := by - have he : (∫⁻ l, d l ∂labelLaw) ≤ 1 := (lintegral_mono hdle).trans_eq (by simp) - exact ne_of_lt (he.trans_lt ENNReal.one_lt_top) - rw [←hdint] - by_contra hne - exact (not_lt_of_ge hineq) (ENNReal.mul_lt_mul_left hne hdf (by norm_num)) - -theorem critical_encounter_root_zero - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (i : ι) : - law (pc G) {ω | IsEncounter G ω (root i)} = 0 := by - have hd := critical_encounter_density_zero G hconn hloc hp root weight htr hw hw1 hcov - have hi : ENNReal.ofReal (weight i) * ∫⁻ l, - (if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) ∂labelLaw = 0 := by - exact (Finset.sum_eq_zero_iff.mp hd) i (Finset.mem_univ i) - have hz : (∫⁻ l, (if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) ∂labelLaw) = 0 := - (mul_eq_zero.mp hi).resolve_left ((ENNReal.ofReal_pos.mpr (hw i)).ne') - rw [←map_openEdges (pc G),Measure.map_apply (measurable_openEdges (pc G)) - (measurableSet_isEncounter G (root i))] - have he : (fun l : E → unitInterval => if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) = - ((fun l : E → unitInterval => openEdges l (pc G)) ⁻¹' {ω | IsEncounter G ω (root i)}).indicator (fun _ => 1) := rfl - rw [he,lintegral_indicator ((measurableSet_isEncounter G (root i)).preimage (measurable_openEdges (pc G)))] at hz - simpa only [lintegral_const,Measure.restrict_apply_univ,one_mul] using hz - -theorem critical_encounter_zero - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) - (hw1 : ∑ i, weight i = 1) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (x : V) : - law (pc G) {ω | IsEncounter G ω x} = 0 := by - obtain ⟨i,a,⟨b,hab⟩,rfl⟩ := hcov x - have he : {ω | IsEncounter G ω (a (root i))} = - (fun ω : Set E => b ⁻¹' ω) ⁻¹' {ω | IsEncounter G ω (root i)} := by - ext ω - exact (isEncounter_aut_iff G a b hab ω (root i)).symm - rw [he,←Measure.map_apply (measurable_set_preimage b) (measurableSet_isEncounter G (root i)), - law_map_preimage_equiv] - exact critical_encounter_root_zero G hconn hloc hp root weight htr hw hw1 hcov i - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Encounter.Counts + +namespace OAI + +/-! Critical limits and zero encounter intensity. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory SimpleGraph Filter Topology +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem branchCount_three (H : SimpleGraph V) (S : Finset V) (x a b c : V) + (ha : a ∈ S) (hb : b ∈ S) (hc : c ∈ S) + (hax : a ≠ x) (hbx : b ≠ x) (hcx : c ≠ x) + (hab : ¬(cutVertex H x).Reachable a b) + (hac : ¬(cutVertex H x).Reachable a c) + (hbc : ¬(cutVertex H x).Reachable b c) : 3 ≤ branchCount H S x := by + let f := (cutVertex H x).connectedComponentMk + have hab' : f a ≠ f b := fun h => hab (ConnectedComponent.exact h) + have hac' : f a ≠ f c := fun h => hac (ConnectedComponent.exact h) + have hbc' : f b ≠ f c := fun h => hbc (ConnectedComponent.exact h) + have hs : ({f a,f b,f c}:Finset _) ⊆ (S.erase x).image f := by + intro y hy + simp only [Finset.mem_insert,Finset.mem_singleton] at hy + rcases hy with rfl | rfl | rfl + · exact Finset.mem_image.mpr ⟨a,Finset.mem_erase.mpr ⟨hax,ha⟩,rfl⟩ + · exact Finset.mem_image.mpr ⟨b,Finset.mem_erase.mpr ⟨hbx,hb⟩,rfl⟩ + · exact Finset.mem_image.mpr ⟨c,Finset.mem_erase.mpr ⟨hcx,hc⟩,rfl⟩ + have hh := Finset.card_le_card hs + have hcard : ({f a,f b,f c}:Finset _).card = 3 := by simp [hab',hac',hbc'] + rw [hcard] at hh + exact hh + +theorem eventually_conn_of_limit (G : BondGraph V E) (l : E → unitInterval) + (p : unitInterval) (q : ℕ → unitInterval) (hmono : Monotone q) + (hq : ∀ n, q n ≤ p) (hlim : Tendsto q atTop (𝓝 p)) (hne : ∀ e, l e ≠ p) + {x y : V} (hxy : Conn G (openEdges l p) x y) : + ∀ᶠ n in atTop, Conn G (openEdges l (q n)) x y := by + rw [openEdges_eq_iUnion_of_tendsto l p hne q hq hlim,conn_iUnion_iff G _ + (fun m n hmn => openEdges_mono l (hmono hmn))] at hxy + obtain ⟨n,hn⟩ := hxy + exact eventually_atTop.mpr ⟨n,fun m hm => conn_mono G (openEdges_mono l (hmono hm)) hn⟩ + +theorem eventually_encounterCount_three (G : BondGraph V E) (l : E → unitInterval) + (p : unitInterval) (q : ℕ → unitInterval) (hmono : Monotone q) + (hq : ∀ n, q n ≤ p) (hlim : Tendsto q atTop (𝓝 p)) (hne : ∀ e, l e ≠ p) + (hfin : ∀ n x, (cluster G (openEdges l (q n)) x).Finite) + (hbranch : ∀ x, IsEncounter G (openEdges l p) x → ∀ a, + Conn G (openEdges l p) x a → (cluster G (cutConfig G (openEdges l p) x) a).Infinite → + ∃ z ∈ cluster G (cutConfig G (openEdges l p) x) a, z ≠ x ∧ IsEncounter G (openEdges l p) z) + (x : V) (hx : IsEncounter G (openEdges l p) x) : + ∀ᶠ n in atTop, 3 ≤ encounterCount G (openEdges l p) (openEdges l (q n)) x := by + obtain ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ := hx + obtain ⟨a',haa',hax,ha'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ a hxa ha + obtain ⟨b',hbb',hbx,hb'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ b hxb hb + obtain ⟨c',hcc',hcx,hc'⟩ := hbranch x ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ c hxc hc + have hx' : IsEncounter G (openEdges l p) x := ⟨a,b,c,hxa,hxb,hxc,ha,hb,hc,hab,hac,hbc⟩ + have hac' : Conn G (openEdges l p) x a' := conn_trans G _ hxa (conn_mono G (fun _ h => h.1) haa') + have hbc' : Conn G (openEdges l p) x b' := conn_trans G _ hxb (conn_mono G (fun _ h => h.1) hbb') + have hxc' : Conn G (openEdges l p) x c' := conn_trans G _ hxc (conn_mono G (fun _ h => h.1) hcc') + filter_upwards [eventually_conn_of_limit G l p q hmono hq hlim hne hac', + eventually_conn_of_limit G l p q hmono hq hlim hne hbc', + eventually_conn_of_limit G l p q hmono hq hlim hne hxc'] with n han hbn hcn + rw [encounterCount,ite_eq_left hx'] + have hm (z : V) (hz : Conn G (openEdges l (q n)) x z) (he : IsEncounter G (openEdges l p) z) : + z ∈ markedCluster G (openEdges l p) (openEdges l (q n)) x := by + apply Finset.mem_filter.mpr + refine ⟨?_,he⟩ + have ht : z ∈ cluster G (openEdges l (q n)) x := hz + rwa [←clusterFinset_coe G _ x (hfin n x)] at ht + apply branchCount_three _ _ x a' b' c' (hm _ han ha') (hm _ hbn hb') (hm _ hcn hc') hax hbx hcx + · intro ht + rw [cutVertex_open] at ht + exact hab (conn_trans G _ haa' (conn_trans G _ ((conn_iff_reachable G _ a' b').mpr ht) (conn_symm G _ hbb'))) + · intro ht + rw [cutVertex_open] at ht + exact hac (conn_trans G _ haa' (conn_trans G _ ((conn_iff_reachable G _ a' c').mpr ht) (conn_symm G _ hcc'))) + · intro ht + rw [cutVertex_open] at ht + exact hbc (conn_trans G _ hbb' (conn_trans G _ ((conn_iff_reachable G _ b' c').mpr ht) (conn_symm G _ hcc'))) + +end Percolation + +namespace Percolation +open MeasureTheory SimpleGraph Filter Topology +open scoped ENNReal +universe u v w +variable {V : Type u} {E : Type v} {ι : Type w} +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Fintype ι] + +theorem critical_encounter_density_zero + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, + (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ∂labelLaw) = 0 := by + obtain ⟨q,hmono,hq,hlim⟩ := exists_seq_strictMono_tendsto' hp + let d (l : E → unitInterval) : ℝ≥0∞ := ∑ i, ENNReal.ofReal (weight i) * + if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0 + let f (n : ℕ) (l : E → unitInterval) : ℝ≥0∞ := ∑ i, ENNReal.ofReal (weight i) * + (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i) : ℝ≥0∞) + have hd : Measurable d := by + apply Finset.measurable_sum + intro i _ + exact measurable_const.mul (Measurable.ite ((measurableSet_isEncounter G (root i)).preimage + (measurable_openEdges (pc G))) measurable_const measurable_const) + have hf n : Measurable (f n) := by + apply Finset.measurable_sum + intro i _ + exact measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp + (measurable_encounterCount G (pc G) (q n) (root i))) + have hdint : (∫⁻ l, d l ∂labelLaw) = ∑ i, ENNReal.ofReal (weight i) * ∫⁻ l, + (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ∂labelLaw := by + rw [show d = _ from rfl,lintegral_finsetSum] + · apply Finset.sum_congr rfl + intro i _ + exact lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + · intro i _ + exact measurable_const.mul (Measurable.ite ((measurableSet_isEncounter G (root i)).preimage + (measurable_openEdges (pc G))) measurable_const measurable_const) + have hbound n : (∫⁻ l, f n l ∂labelLaw) ≤ 2 * ∫⁻ l, d l ∂labelLaw := by + rw [hdint,show f n = _ from rfl,lintegral_finsetSum] + · simp_rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + exact expected_encounterCount_le G hconn hloc root weight htr (fun i => (hw i).le) + (pc G) (q n) (hq n).2.le (fun x => subcritical_cluster_finite_ae G (q n) (hq n).2 x) + · intro i _ + exact measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ≥0∞))).comp + (measurable_encounterCount G (pc G) (q n) (root i))) + have hfl : ∀ᵐ l ∂labelLaw, ∀ n x, (cluster G (openEdges l (q n)) x).Finite := + ae_all_iff.mpr fun n => ae_all_iff.mpr fun x => label_cluster_finite_ae_subcritical G (q n) (hq n).2 x + have hbl : ∀ᵐ l ∂labelLaw, ∀ x, IsEncounter G (openEdges l (pc G)) x → ∀ a, + Conn G (openEdges l (pc G)) x a → (cluster G (cutConfig G (openEdges l (pc G)) x) a).Infinite → + ∃ z ∈ cluster G (cutConfig G (openEdges l (pc G)) x) a, z ≠ x ∧ IsEncounter G (openEdges l (pc G)) z := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => ∀ x, IsEncounter G ω x → ∀ a, + Conn G ω x a → (cluster G (cutConfig G ω x) a).Infinite → + ∃ z ∈ cluster G (cutConfig G ω x) a, z ≠ x ∧ IsEncounter G ω z) + (measurable_openEdges (pc G)).aemeasurable + rw [map_openEdges] + exact encounter_branches_ae G hconn hloc root weight htr hw hw1 hcov (pc G) + have hlow : ∀ᵐ l ∂labelLaw, 3 * d l ≤ liminf (fun n => f n l) atTop := by + filter_upwards [hfl,hbl,ae_labels_ne (E := E) (pc G)] with l hl hb hn + refine le_liminf_of_le (by isBoundedDefault) ?_ + have he (i : ι) : ∀ᶠ n in atTop, + (3:ℝ≥0∞) * (if IsEncounter G (openEdges l (pc G)) (root i) then 1 else 0) ≤ + (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i) : ℝ≥0∞) := by + by_cases hi : IsEncounter G (openEdges l (pc G)) (root i) + · filter_upwards [eventually_encounterCount_three G l (pc G) q hmono.monotone + (fun n => (hq n).2.le) hlim hn hl hb (root i) hi] with n hnc + simpa only [ite_eq_left hi,mul_one] using (show (3:ℝ≥0∞) ≤ (encounterCount G (openEdges l (pc G)) (openEdges l (q n)) (root i):ℝ≥0∞) from by exact_mod_cast hnc) + · filter_upwards [] with n + simp only [ite_eq_right hi,mul_zero,zero_le] + filter_upwards [(eventually_all_finset (Finset.univ : Finset ι)).mpr (fun i _ => he i)] with n hnn + dsimp [d,f] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i hi + rw [←mul_assoc,mul_comm (3:ℝ≥0∞),mul_assoc] + exact mul_le_mul_right (hnn i hi) _ + have hineq : 3 * (∫⁻ l, d l ∂labelLaw) ≤ 2 * ∫⁻ l, d l ∂labelLaw := by + calc + _ = ∫⁻ l, 3 * d l ∂labelLaw := (lintegral_const_mul' _ _ ENNReal.ofNat_ne_top).symm + _ ≤ ∫⁻ l, liminf (fun n => f n l) atTop ∂labelLaw := lintegral_mono_ae hlow + _ ≤ liminf (fun n => ∫⁻ l, f n l ∂labelLaw) atTop := lintegral_liminf_le hf + _ ≤ _ := by + refine liminf_le_of_le (by isBoundedDefault) ?_ + intro b hb + obtain ⟨n,hn⟩ := hb.exists + exact hn.trans (hbound n) + have hdle (l : E → unitInterval) : d l ≤ 1 := by + calc + _ ≤ ∑ i, ENNReal.ofReal (weight i) * 1 := by + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_right + split_ifs <;> simp + _ = 1 := by + simp only [mul_one,←ENNReal.ofReal_sum_of_nonneg (fun i _ => (hw i).le),hw1,ENNReal.ofReal_one] + have hdf : (∫⁻ l, d l ∂labelLaw) ≠ ⊤ := by + have he : (∫⁻ l, d l ∂labelLaw) ≤ 1 := (lintegral_mono hdle).trans_eq (by simp) + exact ne_of_lt (he.trans_lt ENNReal.one_lt_top) + rw [←hdint] + by_contra hne + exact (not_lt_of_ge hineq) (ENNReal.mul_lt_mul_left hne hdf (by norm_num)) + +theorem critical_encounter_root_zero + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (i : ι) : + law (pc G) {ω | IsEncounter G ω (root i)} = 0 := by + have hd := critical_encounter_density_zero G hconn hloc hp root weight htr hw hw1 hcov + have hi : ENNReal.ofReal (weight i) * ∫⁻ l, + (if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) ∂labelLaw = 0 := by + exact (Finset.sum_eq_zero_iff.mp hd) i (Finset.mem_univ i) + have hz : (∫⁻ l, (if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) ∂labelLaw) = 0 := + (mul_eq_zero.mp hi).resolve_left ((ENNReal.ofReal_pos.mpr (hw i)).ne') + rw [←map_openEdges (pc G),Measure.map_apply (measurable_openEdges (pc G)) + (measurableSet_isEncounter G (root i))] + have he : (fun l : E → unitInterval => if IsEncounter G (openEdges l (pc G)) (root i) then (1:ℝ≥0∞) else 0) = + ((fun l : E → unitInterval => openEdges l (pc G)) ⁻¹' {ω | IsEncounter G ω (root i)}).indicator (fun _ => 1) := rfl + rw [he,lintegral_indicator ((measurableSet_isEncounter G (root i)).preimage (measurable_openEdges (pc G)))] at hz + simpa only [lintegral_const,Measure.restrict_apply_univ,one_mul] using hz + +theorem critical_encounter_zero + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + (hp : 0 < pc G) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) (hw : ∀ i, 0 < weight i) + (hw1 : ∑ i, weight i = 1) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) (x : V) : + law (pc G) {ω | IsEncounter G ω x} = 0 := by + obtain ⟨i,a,⟨b,hab⟩,rfl⟩ := hcov x + have he : {ω | IsEncounter G ω (a (root i))} = + (fun ω : Set E => b ⁻¹' ω) ⁻¹' {ω | IsEncounter G ω (root i)} := by + ext ω + exact (isEncounter_aut_iff G a b hab ω (root i)).symm + rw [he,←Measure.map_apply (measurable_set_preimage b) (measurableSet_isEncounter G (root i)), + law_map_preimage_equiv] + exact critical_encounter_root_zero G hconn hloc hp root weight htr hw hw1 hcov i + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Escape/CollisionTails.lean b/lean/OAI/Probability/UnimodularPercolation/Escape/CollisionTails.lean index b7b1220f5548f4325339bbd1952699c2e08fdf19..72f592ce4bbf3c107fdc483c031b817ccda0f13c 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Escape/CollisionTails.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Escape/CollisionTails.lean @@ -1,1204 +1,1204 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.Labels - -namespace OAI - -/-! Collision Tails for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RawTimeMarginals -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_position_integral (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (i m : ℕ) (him : i ≤ m) (x : V) (f : V → ℝ) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - w.2.mass (walkKernel G hloc a) * f (w.2.position i)) = - RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) i x f := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - induction i generalizing m x with - | zero => - simp only [HoldingWalk.position_zero,tsum_mul_right,rawFrom_probability_sum G hloc a,one_mul,RawFrom.integral_zero] - | succ i ih => - cases m with - | zero => omega - | succ m => - rw [←(RawFrom.succEquiv m x).symm.tsum_eq,RawFrom.integral_succ] - let (z : V) := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m z) - let := Fintype.ofFinite ((openSimpleGraph G Set.univ).neighborSet x) - have hh (z : V) := ih m (Nat.le_of_succ_le_succ him) z - simp only [tsum_fintype,Fintype.sum_sum_type,Fintype.sum_sigma,RawFrom.succEquiv, - Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,HoldingWalk.position,mul_assoc] - simp only [tsum_fintype] at hh - simp only [←Finset.mul_sum,hh] - -theorem raw_position_probability (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (i m : ℕ) (him : i ≤ m) (x z : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - if w.2.position i = z then w.2.mass (walkKernel G hloc a) else 0) = - (matrixCoeff (P^i) x z).re := by - have hh := raw_position_integral G hloc a i m him x (fun y => if y = z then (1:ℝ) else 0) - simp only [mul_ite,mul_one,mul_zero] at hh - rw [hh,raw_integral_operator G hloc a P hpos hP] - simp only [mul_ite,mul_one,mul_zero,tsum_ite_eq] - -end RawTimeMarginals -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IndependentRawCollisions -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_two_time_collision (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (i m j n : ℕ) (him : i ≤ m) (hjn : j ≤ n) (x y : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, - if w.1.2.position i = w.2.2.position j then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) = - (matrixCoeff (P^(i+j)) x y).re := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) n y) - have hi (w : RawFrom (openSimpleGraph G Set.univ) m x) : - (∑' v : RawFrom (openSimpleGraph G Set.univ) n y, - if w.2.position i = v.2.position j then w.2.mass (walkKernel G hloc a)*v.2.mass (walkKernel G hloc a) else 0) = - w.2.mass (walkKernel G hloc a)*(matrixCoeff (P^j) y (w.2.position i)).re := by - rw [← raw_position_probability G hloc a P hpos hP j n hjn y (w.2.position i),←tsum_mul_left] - apply tsum_congr - intro v - by_cases hh : w.2.position i = v.2.position j - · simp only [ite_eq_left hh,ite_eq_left hh.symm] - · simp only [ite_eq_right hh,ite_eq_right (Ne.symm hh),mul_zero] - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] - simp only [hi] - rw [raw_position_integral G hloc a i m him x (fun z => (matrixCoeff (P^j) y z).re),raw_integral_operator G hloc a P hpos hP] - simp only [matrixCoeff_real_symm (P^j) (hsym.pow j) y] - rw [((hpos.pow i).mul_hasSum (P^j) x y).tsum_eq,←pow_add] - -theorem matrixCoeff_norm_le (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - ‖matrixCoeff A x y‖ ≤ ‖A‖ := by - apply (lp.norm_apply_le_norm (by norm_num : (2:ENNReal) ≠ 0) (A (lp.single 2 y (1:ℂ))) x).trans - simpa using A.le_opNorm (lp.single 2 y (1:ℂ)) - -theorem matrixCoeff_power_le (P : Hilbert V →L[ℂ] Hilbert V) (k : ℕ) (x y : V) : - (matrixCoeff (P^k) x y).re ≤ ‖P‖^k := by - have hn (k : ℕ) : ‖P^k‖ ≤ ‖P‖^k := by - induction k with - | zero => simpa only [pow_zero,ContinuousLinearMap.one_def] using - (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) - | succ k ih => - rw [pow_succ,pow_succ] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) - exact (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (P^k) x y).trans (hn k)) - -end IndependentRawCollisions -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FinitePropagation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem reachBall_exists_short_walk (G : BondGraph V E) (x : V) (k : ℕ) {y : V} - (hy : y ∈ reachBall G x k) : - ∃ q : (openSimpleGraph G Set.univ).Walk x y, q.length ≤ k := by - induction k generalizing y with - | zero => - have he : y = x := hy - subst y - exact ⟨.nil,by simp⟩ - | succ k ih => - rcases hy with hy | hy - · obtain ⟨q,hq⟩ := ih hy - exact ⟨q,hq.trans (Nat.le_succ _)⟩ - · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy - obtain ⟨z,hz,hzy⟩ := hy - obtain ⟨q,hq⟩ := ih hz - by_cases he : z = y - · subst z - exact ⟨q,hq.trans (Nat.le_succ _)⟩ - · let h : (openSimpleGraph G Set.univ).Adj z y := - (openSimpleGraph_univ_adj G z y).mpr ⟨he,hzy⟩ - refine ⟨q.append (.cons h .nil),?_⟩ - simpa only [SimpleGraph.Walk.length_append,SimpleGraph.Walk.length_cons, - SimpleGraph.Walk.length_nil,zero_add] using Nat.add_le_add_right hq 1 - -theorem dist_le_of_mem_reachBall (G : BondGraph V E) (x y : V) (k : ℕ) - (hy : y ∈ reachBall G x k) : (openSimpleGraph G Set.univ).dist x y ≤ k := by - obtain ⟨q,hq⟩ := reachBall_exists_short_walk G x k hy - exact (SimpleGraph.dist_le q).trans hq - -theorem walkPower_zero_of_lt_dist (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (k : ℕ) (x y : V) (hk : k < (openSimpleGraph G Set.univ).dist x y) : - (matrixCoeff (P^k) x y).re = 0 := by - apply walkPower_support G hloc a P hpos hP - intro hy - exact Nat.not_le_of_gt hk (dist_le_of_mem_reachBall G x y k hy) - - - -theorem raw_two_time_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (i m j n : ℕ) (him : i ≤ m) (hjn : j ≤ n) (x y : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, - if w.1.2.position i = w.2.2.position j then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ - if i+j < (openSimpleGraph G Set.univ).dist x y then 0 else ‖P‖^(i+j) := by - rw [raw_two_time_collision G hloc a P hpos hsym hP i m j n him hjn x y] - split_ifs with hh - · exact (walkPower_zero_of_lt_dist G hloc a P hpos hP (i+j) x y hh).le - · exact matrixCoeff_power_le P (i+j) x y - -end FinitePropagation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualCollisionUnion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_nonnegative_event_union {α β : Type*} [Fintype α] [Fintype β] - (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (B : α → β → Prop) : - (∑ a, if ∃ b, B a b then μ a else 0) ≤ ∑ b, ∑ a, if B a b then μ a else 0 := by - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro a _ - by_cases hh : ∃ b, B a b - · obtain ⟨b,hb⟩ := hh - rw [ite_eq_left ⟨b,hb⟩] - calc - μ a = (if B a b then μ a else 0) := (ite_eq_left hb).symm - _ ≤ ∑ b, if B a b then μ a else 0 := - Finset.single_le_sum (f := fun b => if B a b then μ a else 0) - (fun b _ => by split_ifs; exact hμ a; exact le_rfl) (Finset.mem_univ b) - · rw [ite_eq_right hh] - exact Finset.sum_nonneg (fun b _ => by split_ifs; exact hμ a; exact le_rfl) - - - -theorem raw_intersection_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (m n : ℕ) (x y : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, - if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ - ∑ i : Fin (m+1), ∑ j : Fin (n+1), - if i.val+j.val < (openSimpleGraph G Set.univ).dist x y then 0 else ‖P‖^(i.val+j.val) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) n y) - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have he (w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y) : - (∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) ↔ - ∃ ij : Fin (m+1) × Fin (n+1), w.1.2.position ij.1 = w.2.2.position ij.2 := by - constructor - · rintro ⟨z,hz,hz'⟩ - obtain ⟨i,hi,he⟩ := w.1.2.mem_vertices_iff_position.mp hz - obtain ⟨j,hj,he'⟩ := w.2.2.mem_vertices_iff_position.mp hz' - exact ⟨(⟨i,by omega⟩,⟨j,by omega⟩),he.trans he'.symm⟩ - · rintro ⟨⟨i,j⟩,hij⟩ - exact ⟨w.1.2.position i,w.1.2.position_mem_vertices i,hij ▸ w.2.2.position_mem_vertices j⟩ - simp only [he,tsum_fintype] - have hu := finite_nonnegative_event_union - (fun w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y => - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a)) - (fun w => mul_nonneg (w.1.2.mass_nonneg _ hK) (w.2.2.mass_nonneg _ hK)) - (fun w (ij : Fin (m+1) × Fin (n+1)) => w.1.2.position ij.1 = w.2.2.position ij.2) - apply hu.trans - rw [Fintype.sum_prod_type] - apply Finset.sum_le_sum - intro i _ - apply Finset.sum_le_sum - intro j _ - simpa only [tsum_fintype] using - raw_two_time_collision_bound G hloc a P hpos hsym hP i m j n (by omega) (by omega) x y - -end ActualCollisionUnion -end Percolation - - -namespace Percolation -section UniformCollisionTails -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem geometric_cutoff_summable (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J : ℕ) : - Summable (fun i : ℕ => if J ≤ i then ρ^i else 0) := - Summable.of_nonneg_of_le (fun i => by split_ifs <;> positivity) - (fun i => by split_ifs <;> first | exact le_rfl | exact pow_nonneg hρ i) - (summable_geometric_of_lt_one hρ hρ1) - -theorem geometric_cutoff_tsum (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J : ℕ) : - (∑' i : ℕ, if J ≤ i then ρ^i else 0) = ρ^J/(1-ρ) := by - have hs := geometric_cutoff_summable ρ hρ hρ1 J - rw [←hs.sum_add_tsum_nat_add J] - have hz : (∑ i ∈ Finset.range J, if J ≤ i then ρ^i else 0) = 0 := by - apply Finset.sum_eq_zero - intro i hi - exact ite_eq_right (Nat.not_le_of_gt (Finset.mem_range.mp hi)) - rw [hz,zero_add] - simp only [Nat.le_add_left,ite_true,pow_add,tsum_mul_right, - tsum_geometric_of_lt_one hρ hρ1,div_eq_mul_inv] - exact mul_comm _ _ - -theorem finite_geometric_cutoff_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J M : ℕ) : - (∑ i : Fin M, if J ≤ i.val then ρ^i.val else 0) ≤ ρ^J/(1-ρ) := by - change (∑ i : Fin M, (fun n : ℕ => if J ≤ n then ρ^n else 0) i.val) ≤ _ - rw [Fin.sum_univ_eq_sum_range (fun n : ℕ => if J ≤ n then ρ^n else 0) M,←geometric_cutoff_tsum ρ hρ hρ1 J] - exact Summable.sum_le_tsum (s := Finset.range M) (fun i _ => by split_ifs <;> positivity) - (geometric_cutoff_summable ρ hρ hρ1 J) - - - -theorem finite_double_geometric_cutoff_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) - (J M N D : ℕ) (hD : 2*J ≤ D) : - (∑ i : Fin M, ∑ j : Fin N, if i.val+j.val < D then 0 else ρ^(i.val+j.val)) ≤ - 2*ρ^J/(1-ρ)^2 := by - let q : ℕ → ℝ := fun i => if J ≤ i then ρ^i else 0 - have hq (i : ℕ) : 0 ≤ q i := by dsimp [q]; split_ifs <;> positivity - have hp (i : ℕ) : 0 ≤ ρ^i := pow_nonneg hρ i - have hQ := finite_geometric_cutoff_bound ρ hρ hρ1 J M - have hQ' := finite_geometric_cutoff_bound ρ hρ hρ1 J N - have hS := finite_geometric_cutoff_bound ρ hρ hρ1 0 M - have hS' := finite_geometric_cutoff_bound ρ hρ hρ1 0 N - simp only [Nat.zero_le,ite_true,pow_zero,one_div] at hS hS' - have hd : 0 < 1-ρ := sub_pos.mpr hρ1 - calc - _ ≤ ∑ i : Fin M, ∑ j : Fin N, (q i.val*ρ^j.val + ρ^i.val*q j.val) := by - apply Finset.sum_le_sum - intro i _ - apply Finset.sum_le_sum - intro j _ - by_cases hh : i.val+j.val < D - · rw [ite_eq_left hh] - exact add_nonneg (mul_nonneg (hq _) (hp _)) (mul_nonneg (hp _) (hq _)) - · rw [ite_eq_right hh,pow_add] - have hj : J ≤ i.val ∨ J ≤ j.val := by omega - rcases hj with hi | hj - · simp only [q,ite_eq_left hi] - exact le_add_of_nonneg_right (mul_nonneg (hp _) (by split_ifs <;> positivity)) - · simp only [q,ite_eq_left hj] - exact le_add_of_nonneg_left (mul_nonneg (by split_ifs <;> positivity) (hp _)) - _ = (∑ i : Fin M, q i.val)*(∑ j : Fin N, ρ^j.val) + - (∑ i : Fin M, ρ^i.val)*(∑ j : Fin N, q j.val) := by - simp only [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.sum_mul] - _ ≤ (ρ^J/(1-ρ))*(1-ρ)⁻¹ + (1-ρ)⁻¹*(ρ^J/(1-ρ)) := by - apply add_le_add - · exact mul_le_mul hQ hS' (Finset.sum_nonneg (fun i _ => hp _)) (by positivity) - · exact mul_le_mul hS hQ' (Finset.sum_nonneg (fun i _ => hq _)) (by positivity) - _ = _ := by field_simp; ring - -end UniformCollisionTails -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformRawCollision -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_intersection_uniform_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hcontract : ‖P‖ < 1) - (m n J : ℕ) (x y : V) (hD : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, - if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ - 2*‖P‖^J/(1-‖P‖)^2 := - (raw_intersection_probability_bound G hloc a P hpos hsym hP m n x y).trans - (finite_double_geometric_cutoff_bound ‖P‖ (norm_nonneg _) hcontract J (m+1) (n+1) _ hD) - - -theorem exists_uniform_raw_collision_separation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hcontract : ‖P‖ < 1) - (ε : ℝ) (hε : 0 < ε) : - ∃ J₀ : ℕ, ∀ J : ℕ, J₀ ≤ J → ∀ m n : ℕ, ∀ x y : V, - 2*J ≤ (openSimpleGraph G Set.univ).dist x y → - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, - if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) < ε := by - have ht : Filter.Tendsto (fun J : ℕ => 2*‖P‖^J/(1-‖P‖)^2) Filter.atTop (nhds 0) := by - simpa only [mul_zero,zero_div] using - ((tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg P) hcontract).const_mul 2).div_const ((1-‖P‖)^2) - obtain ⟨J₀,hJ⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds hε)) - refine ⟨J₀,?_⟩ - intro J hJJ m n x y hd - exact (raw_intersection_uniform_bound G hloc a P hpos hsym hP hcontract m n J x y hd).trans_lt (hJ J hJJ) - -end UniformRawCollision -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -namespace HoldingWalk -variable {H : SimpleGraph V} - - - -def fromPositions : (k : ℕ) → (f : Fin (k+1) → V) → - (∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) → - HoldingWalk H k (f 0) (f (Fin.last k)) - | 0,f,_ => .nil (f 0) - | k+1,f,h => .step (h 0) (fromPositions k (fun i => f i.succ) (fun i => h i.succ)) - -theorem mass_fromPositions (P : V → V → ℝ) (a : ℝ) - (hP : ∀ x y, H.Adj x y → P x y = a) - (k : ℕ) (f : Fin (k+1) → V) (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) : - (fromPositions k f h).mass P = a^k := by - induction k with - | zero => rfl - | succ k ih => - change P (f 0) (f 1) * (fromPositions k (fun i => f i.succ) (fun i => h i.succ)).mass P = a^(k+1) - have he : P (f 0) (f 1) = a := by simpa using hP _ _ (h 0) - rw [he,ih,pow_succ'] - -theorem position_fromPositions (k : ℕ) (f : Fin (k+1) → V) - (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) (i : ℕ) (hi : i ≤ k) : - (fromPositions k f h).position i = f ⟨i,by omega⟩ := by - induction k generalizing i with - | zero => - obtain rfl : i = 0 := by omega - rfl - | succ k ih => - cases i with - | zero => rfl - | succ i => - exact ih (fun j => f j.succ) (fun j => h j.succ) i (by omega) - -end HoldingWalk -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -namespace HoldingWalk -variable {H : SimpleGraph V} - -theorem position_append_left {k l : ℕ} {x y z : V} - (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) (i : ℕ) (hi : i ≤ k) : - (w.append v).position i = w.position i := by - induction w generalizing i with - | nil => - obtain rfl : i = 0 := by omega - exact v.position_zero - | hold w ih => cases i with - | zero => rfl - | succ i => exact ih v i (by omega) - | step h w ih => cases i with - | zero => rfl - | succ i => exact ih v i (by omega) - -theorem position_append_right {k l : ℕ} {x y z : V} - (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) (i : ℕ) : - (w.append v).position (k+i) = v.position i := by - induction w with - | nil => simp only [Nat.zero_add,append] - | hold w ih => simpa only [Nat.succ_add,append,position] using ih v - | step h w ih => simpa only [Nat.succ_add,append,position] using ih v - - - -theorem ext_positions {k : ℕ} {x y : V} (w v : HoldingWalk H k x y) - (h : ∀ i : ℕ, i ≤ k → w.position i = v.position i) : w = v := by - induction k generalizing x y with - | zero => cases w; cases v; rfl - | succ k ih => - cases w with - | hold w => - cases v with - | hold v => - congr 1 - exact ih w v (fun i hi => h (i+1) (Nat.succ_le_succ hi)) - | step hv v => - have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) - simp only [position,position_zero] at he - exact (hv.ne he).elim - | step hw w => - cases v with - | hold v => - have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) - simp only [position,position_zero] at he - exact (hw.ne he.symm).elim - | step hv v => - have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) - simp only [position,position_zero] at he - cases he - congr 1 - exact ih w v (fun i hi => h (i+1) (Nat.succ_le_succ hi)) - -end HoldingWalk -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IntrinsicVisibleBlocks -attribute [local instance] Classical.propDecidable Classical.decEq - -def segmentCenter (J : ℕ) : Fin (J+J+1) := ⟨J,by omega⟩ - -def segmentPositivePositions (J : ℕ) (s : Fin (J+J+1) → V) : Fin (J+1) → V := - fun i => s ⟨J+i.val,by omega⟩ - -def positiveStem (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) - (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) : - HoldingWalk H J (s (segmentCenter J)) (s (Fin.last (J+J))) := - HoldingWalk.fromPositions J (segmentPositivePositions J s) (fun i => hs ⟨J+i.val,by omega⟩) - -theorem positiveStem_mass (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) - (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) - (P : V → V → ℝ) (a : ℝ) (hP : ∀ x y, H.Adj x y → P x y = a) : - (positiveStem H J s hs).mass P = a^J := - HoldingWalk.mass_fromPositions P a hP J _ _ - -theorem orbitSegment_consecutive (G : BondGraph V E) (J : ℕ) (γ s : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (hs : s ∈ segmentOrbit G γ) : - ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (s i.castSucc) (s i.succ) := - fun i => segmentOrbit_adj G γ s hs _ _ (hγ i) - - - -def escapeLabelRaw (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : - HoldingWalk (openSimpleGraph G Set.univ) ((J+L)+J) - (ξ.first (segmentCenter J)) (ξ.last (segmentCenter J)) := - (positiveStem _ J ξ.first (orbitSegment_consecutive G J γ ξ.first hγ ξ.first_mem)).append - (ξ.middle.append (positiveStem _ J ξ.last - (orbitSegment_consecutive G J γ ξ.last hγ ξ.last_mem)).reverse) - -theorem escapeLabelRaw_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : - (escapeLabelRaw G J L m γ hγ ξ).mass (walkKernel G hloc a) = - a^(J+J)*ξ.middle.mass (walkKernel G hloc a) := by - simp only [escapeLabelRaw,HoldingWalk.mass_append,HoldingWalk.mass_reverse _ (walkKernel_symmetric G hloc a), - positiveStem_mass _ _ _ _ _ a (fun _ _ h => walkKernel_step G hloc a h),pow_add] - ring - -theorem escapeLabelRaw_middle_position (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (i : ℕ) (hi : i ≤ L) : - (escapeLabelRaw G J L m γ hγ ξ).position (J+i) = ξ.middle.position i := by - rw [escapeLabelRaw,HoldingWalk.position_append_right,HoldingWalk.position_append_left _ _ i hi] - -end IntrinsicVisibleBlocks -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -namespace RawFrom -variable {H : SimpleGraph V} - - -theorem ext_positions {k : ℕ} {x : V} (w v : RawFrom H k x) - (h : ∀ i : ℕ, i ≤ k → w.2.position i = v.2.position i) : w = v := by - rcases w with ⟨y,w⟩ - rcases v with ⟨z,v⟩ - have he : y = z := by simpa only [HoldingWalk.position_length] using h k le_rfl - subst z - exact Sigma.ext rfl (heq_of_eq (HoldingWalk.ext_positions w v h)) - -theorem pairwise_disjoint_position_indicators {k : ℕ} {x : V} (f : ℕ → V) - {w v : RawFrom H k x} - (hw : ∀ i : ℕ, i ≤ k → w.2.position i = f i) - (hv : ∀ i : ℕ, i ≤ k → v.2.position i = f i) : w = v := - ext_positions w v (fun i hi => (hw i hi).trans (hv i hi).symm) - -end RawFrom - - - -theorem finite_single_fiber_weight_bound {α : Type*} [Fintype α] - (μ : α → ℝ) (B : α → Prop) [DecidablePred B] (C : ℝ) (hC : 0 ≤ C) - (hunique : ∀ a b, B a → B b → a = b) (hbound : ∀ a, B a → μ a ≤ C) : - (∑ a, if B a then μ a else 0) ≤ C := by - classical - by_cases hh : ∃ a, B a - · obtain ⟨a,ha⟩ := hh - calc - _ = μ a := by - rw [Finset.sum_eq_single a] - · exact ite_eq_left ha - · intro b _ hba - exact ite_eq_right (fun hb => hba (hunique b a hb ha)) - · simp - _ ≤ C := hbound a ha - · simpa only [not_exists.mp hh,ite_false,Finset.sum_const_zero] using hC - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RootedRawProjection -attribute [local instance] Classical.propDecidable Classical.decEq - -def rootedEscapeLabelRaw (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : - RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x := by - rcases ξ with ⟨ξ,hξ⟩ - subst x - exact ⟨ξ.last (segmentCenter J),escapeLabelRaw G J L m γ hγ ξ⟩ - -theorem rootedEscapeLabelRaw_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : - (rootedEscapeLabelRaw G J L m γ hγ x ξ).2.mass (walkKernel G hloc a) = - a^(J+J)*ξ.1.middle.mass (walkKernel G hloc a) := by - rcases ξ with ⟨ξ,hξ⟩ - subst x - exact escapeLabelRaw_mass G hloc a J L m γ hγ ξ - -theorem rootedEscapeLabelRaw_middle_position (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) - (i : ℕ) (hi : i ≤ L) : - (rootedEscapeLabelRaw G J L m γ hγ x ξ).2.position (J+i) = ξ.1.middle.position i := by - rcases ξ with ⟨ξ,hξ⟩ - subst x - exact escapeLabelRaw_middle_position G J L m γ hγ ξ i hi - -theorem rootedEscapeLabelRaw_fiber_middle_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (ha : 0 < a) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) - (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) - (hw : rootedEscapeLabelRaw G J L m γ hγ x ξ = w) : - ξ.1.middle.mass (walkKernel G hloc a) = w.2.mass (walkKernel G hloc a)/a^(J+J) := by - apply (eq_div_iff (ne_of_gt (pow_pos ha _))).mpr - rw [mul_comm,←rootedEscapeLabelRaw_mass G hloc a J L m γ hγ x ξ,hw] - -theorem rootedEscapeLabelRaw_fiber_middle_positions (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) - (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) - (hw : rootedEscapeLabelRaw G J L m γ hγ x ξ = w) : - ∀ i : ℕ, i ≤ L → ξ.1.middle.position i = w.2.position (J+i) := by - intro i hi - rw [←rootedEscapeLabelRaw_middle_position G J L m γ hγ x ξ i hi,hw] - -end RootedRawProjection -end Percolation - - -namespace Percolation -section FiniteFiberDomination -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_auxiliary_event_bound {α : Type*} [Fintype α] - (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (hs : ∑ a, μ a = 1) - (B : α → Prop) (c : ℝ) (hc : 0 ≤ c) : - (∑ a, if B a then c*μ a else 0) ≤ c := by - calc - _ ≤ ∑ a, c*μ a := Finset.sum_le_sum (fun a _ => by - split_ifs; exact le_rfl; exact mul_nonneg hc (hμ a)) - _ = c := by rw [←Finset.mul_sum,hs,mul_one] - - - -theorem finite_nested_unique_fiber_bound {β : Type*} [Fintype β] - {γ : β → Type*} [∀ b, Fintype (γ b)] - {T : (b : β) → γ b → Type*} [∀ b c, Fintype (T b c)] - (μ : β → ℝ) (hμ : ∀ b, 0 ≤ μ b) - (ν : (b : β) → (c : γ b) → T b c → ℝ) (hν : ∀ b c t, 0 ≤ ν b c t) - (hs : ∀ b c, ∑ t, ν b c t = 1) - (B : (b : β) → (c : γ b) → T b c → Prop) - (N C : ℝ) (hN : 0 ≤ N) (hC : 0 ≤ C) - (hcard : ∀ b, (Fintype.card (γ b) : ℝ) ≤ N) - (hunique : ∀ b c t b' c' t', B b c t → B b' c' t' → b = b') - (hbound : ∀ b c t, B b c t → μ b ≤ C) : - (∑ b, ∑ c, ∑ t, if B b c t then μ b*ν b c t else 0) ≤ N*C := by - by_cases hh : ∃ b c t, B b c t - · obtain ⟨b,c,t,hb⟩ := hh - have he : (∑ b', ∑ c', ∑ t', if B b' c' t' then μ b'*ν b' c' t' else 0) = - ∑ c', ∑ t', if B b c' t' then μ b*ν b c' t' else 0 := by - apply Finset.sum_eq_single b - · intro b' _ hne - apply Finset.sum_eq_zero - intro c' _ - apply Finset.sum_eq_zero - intro t' _ - exact ite_eq_right (fun hb' => hne (hunique b' c' t' b c t hb' hb)) - · simp - rw [he] - calc - _ ≤ ∑ _c : γ b, μ b := Finset.sum_le_sum (fun c' _ => - finite_auxiliary_event_bound (ν b c') (hν b c') (hs b c') (B b c') (μ b) (hμ b)) - _ = (Fintype.card (γ b) : ℝ)*μ b := by simp - _ ≤ N*C := mul_le_mul (hcard b) (hbound b c t hb) (hμ b) hN - · have hz : ∀ b c t, ¬B b c t := by simpa only [not_exists] using hh - simp only [hz,ite_false,Finset.sum_const_zero] - exact mul_nonneg hN hC - -end FiniteFiberDomination -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section CodeMiddleIdentities -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -theorem labelFromCode_middle_position (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) - (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) (i : ℕ) : - (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.middle.position i = - c.2.1.2.position i := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - -theorem labelFromCode_middle_mass (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (P : V → V → ℝ) - (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : - (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.middle.mass P = - c.2.1.2.mass P := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - -end CodeMiddleIdentities -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralFiberEstimate -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem rooted_code_single_anchor_fiber_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) - (s : segmentAnchors G hloc γ n hdiam (segmentCenter J) x) - (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val (Fin.last (J+J))), - ∑' h : segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) mid.1, - ∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val 0) × - RawFrom (openSimpleGraph G Set.univ) m (h.val 0), - if rootedEscapeLabelRaw G J L m γ hγ x - (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x - ⟨s,mid,h,tails⟩) = w then - mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * - tails.2.2.mass (walkKernel G hloc a) else 0) ≤ - ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * - (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - simp only [tsum_fintype,mul_assoc] - convert finite_nested_unique_fiber_bound - (β := RawFrom (openSimpleGraph G Set.univ) L (s.val (Fin.last (J+J)))) - (γ := fun mid => segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) mid.1) - (T := fun _ h => RawFrom (openSimpleGraph G Set.univ) m (s.val 0) × - RawFrom (openSimpleGraph G Set.univ) m (h.val 0)) - (fun mid => mid.2.mass (walkKernel G hloc a)) - (fun mid => mid.2.mass_nonneg _ hK) - (fun _ _ tails => tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a)) - (fun _ _ tails => mul_nonneg (tails.1.2.mass_nonneg _ hK) (tails.2.2.mass_nonneg _ hK)) ?_ - (fun mid h tails => rootedEscapeLabelRaw G J L m γ hγ x - (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) = w) - (((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ)) - (w.2.mass (walkKernel G hloc a)/a^(J+J)) ?_ ?_ ?_ ?_ ?_ using 1 - · apply Finset.sum_congr rfl - intro mid _ - apply Finset.sum_congr rfl - intro h _ - apply Finset.sum_congr rfl - intro tails _ - split_ifs <;> rfl - · intro mid h - rw [Fintype.sum_prod_type] - simp only [←Finset.mul_sum,←Finset.sum_mul] - simpa only [tsum_fintype,mul_one] using congrArg₂ (fun r s : ℝ => r*s) - (rawFrom_probability_sum G hloc a m (s.val 0)) - (rawFrom_probability_sum G hloc a m (h.val 0)) - · positivity - · exact div_nonneg (w.2.mass_nonneg _ hK) (pow_nonneg ha.le _) - · intro mid - rw [Fintype.card_coe,segmentAnchors_card_eq_indicator G hloc γ n hdiam (Fin.last (J+J)) mid.1] - split_ifs - · exact le_rfl - · exact_mod_cast Nat.zero_le _ - · intro mid h tails mid' h' tails' hh hh' - apply RawFrom.ext_positions - intro i hi - have he := rootedEscapeLabelRaw_fiber_middle_positions G J L m γ hγ x - (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) w hh i hi - have he' := rootedEscapeLabelRaw_fiber_middle_positions G J L m γ hγ x - (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid',h',tails'⟩) w hh' i hi - have hm := labelFromCode_middle_position G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩ i - have hm' := labelFromCode_middle_position G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid',h',tails'⟩ i - exact hm.symm.trans (he.trans (he'.symm.trans hm')) - · intro mid h tails hh - have he := rootedEscapeLabelRaw_fiber_middle_mass G hloc a ha J L m γ hγ x - (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) w hh - have hm := labelFromCode_middle_mass G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x (walkKernel G hloc a) ⟨s,mid,h,tails⟩ - exact (hm.symm.trans he).le - -end LiteralFiberEstimate -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralProjectionDomination -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem rooted_label_raw_fiber_mass_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) - (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : - (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, - if rootedEscapeLabelRaw G J L m γ hγ x ξ = w then ξ.1.mass (walkKernel G hloc a) else 0) ≤ - ((segmentAnchors G hloc γ n hdiam (segmentCenter J) x).card : ℝ) * - ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * - (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := finite_rootedEscapeLabels G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x - let R := rootedLabelEquiv G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x - rw [←R.symm.tsum_eq] - simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] - unfold RootedLabelCode at * - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - calc - _ ≤ ∑' _s : segmentAnchors G hloc γ n hdiam (segmentCenter J) x, - ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * - (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by - apply (summable_of_hasFiniteSupport (Set.toFinite _)).tsum_le_tsum _ - (summable_of_hasFiniteSupport (Set.toFinite _)) - intro s - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - conv_lhs => arg 1; ext mid; rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - exact rooted_code_single_anchor_fiber_bound G hloc a ha hK J L m γ hγ n hdiam x s w - _ = _ := by - simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] - ring - -end LiteralProjectionDomination -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NormalizedProjection -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem tsum_indicator_div {α : Type*} (f : α → ℝ) (B : α → Prop) [DecidablePred B] (d : ℝ) : - (∑' a, if B a then f a/d else 0) = (∑' a, if B a then f a else 0)/d := by - rw [←tsum_div_const] - apply tsum_congr - intro a - split_ifs <;> simp - -theorem rooted_label_raw_projection_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) - (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) - (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) - (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : - (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, - if rootedEscapeLabelRaw G J L m γ hγ x ξ = w then - escapeLabelProbability G hloc a γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) ≤ - w.2.mass (walkKernel G hloc a)/(a^(J+J)*q) := by - have hN (i : Fin (J+J+1)) : 0 < ((segmentAnchors G hloc γ n hdiam i (γ i)).card : ℝ) := by - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i (γ i)).mpr - (by exact ⟨Equiv.refl V,Equiv.refl E,(fun e => by simp),rfl⟩)) - have hQ := hq.trans_le hqle - have hA := pow_pos ha (J+J) - have hm := w.2.mass_nonneg (walkKernel G hloc a) hK - simp only [escapeLabelProbability,tsum_indicator_div] - have hb := rooted_label_raw_fiber_mass_bound G hloc a ha hK J L m γ hγ n hdiam x w - rw [segmentAnchors_card_on_orbit G hloc γ n hdiam (segmentCenter J) x hx] at hb - apply (div_le_div_of_nonneg_right hb (mul_nonneg (mul_nonneg (hN (segmentCenter J)).le (hN (Fin.last (J+J))).le) hQ.le)).trans - calc - _ = w.2.mass (walkKernel G hloc a)/ - (a^(J+J)*segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) := by - field_simp [(hN (segmentCenter J)).ne', (hN (Fin.last (J+J))).ne'] - _ ≤ _ := div_le_div_of_nonneg_left hm (mul_pos hA hq) (mul_le_mul_of_nonneg_left hqle hA.le) - -end NormalizedProjection -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -section SuffixCollisionOperator - -theorem operator_pow_norm_le (P : Hilbert V →L[ℂ] Hilbert V) (k : ℕ) : ‖P^k‖ ≤ ‖P‖^k := by - cases k with - | zero => simpa only [pow_zero,ContinuousLinearMap.one_def] using - (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) - | succ k => exact norm_pow_le' P (Nat.succ_pos k) - - - -theorem positive_rows_collision_hasSum (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) (x y : V) : - HasSum (fun z => (matrixCoeff A x z).re*(matrixCoeff B y z).re) - (matrixCoeff (A*star B) x y).re := by - simpa only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_re] using - hA.mul_hasSum (star B) x y - -theorem positive_rows_collision_bound (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) (x y : V) : - (∑' z, (matrixCoeff A x z).re*(matrixCoeff B y z).re) ≤ ‖A‖*‖B‖ := by - rw [(positive_rows_collision_hasSum A B hA x y).tsum_eq] - apply (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (A*star B) x y).trans _) - have hs : ‖star B‖ = ‖B‖ := ContinuousLinearMap.adjoint.norm_map B - simpa only [hs] using norm_mul_le A (star B) - -theorem walk_suffix_collision_operator_bound (P H : Hilbert V →L[ℂ] Hilbert V) - (hP : PositiveRealMatrix P) (C : ℝ) (hH : ‖H‖ ≤ C) (l L : ℕ) (x y : V) : - (∑' z, (matrixCoeff (P^l) x z).re*(matrixCoeff (P^L*H) y z).re) ≤ - C*‖P‖^(l+L) := by - calc - _ ≤ ‖P^l‖*‖P^L*H‖ := positive_rows_collision_bound _ _ (hP.pow l) x y - _ ≤ ‖P‖^l*(‖P‖^L*C) := mul_le_mul (operator_pow_norm_le P l) - ((norm_mul_le _ _).trans (mul_le_mul (operator_pow_norm_le P L) hH (norm_nonneg H) - (pow_nonneg (norm_nonneg P) L))) (norm_nonneg _) (pow_nonneg (norm_nonneg P) l) - _ = _ := by rw [pow_add]; ring - -end SuffixCollisionOperator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualSuffixCollision -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem raw_anchored_position_expectation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) - (L : ℕ) (x z : V) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L x, - mid.2.mass (walkKernel G hloc a)*anchoredPositionKernel G hloc γ n hdiam ep j mid.1 z) = - (matrixCoeff (P^L*H) x z).re := by - change RawFrom.integral (walkKernel G hloc a) L x - (fun y => anchoredPositionKernel G hloc γ n hdiam ep j y z) = _ - rw [raw_integral_operator G hloc a P hpos hP] - simpa only [hH,Complex.ofReal_re] using ((hpos.pow L).mul_hasSum H x z).tsum_eq - - - -theorem raw_tail_anchored_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) - (C : ℝ) (hHC : ‖H‖ ≤ C) (l m L : ℕ) (hlm : l ≤ m) (x y : V) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - tail.2.mass (walkKernel G hloc a) * - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - mid.2.mass (walkKernel G hloc a)* - anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) ≤ - C*‖P‖^(l+L) := by - simp only [raw_anchored_position_expectation G hloc a γ n hdiam ep j P H hpos hP hH] - rw [raw_position_integral G hloc a l m hlm x (fun z => (matrixCoeff (P^L*H) y z).re), - raw_integral_operator G hloc a P hpos hP] - exact walk_suffix_collision_operator_bound P H hpos C hHC l L x y - -end ActualSuffixCollision -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section UniformSuffixCollision -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι : Type*} [Fintype I] [Fintype ι] - - - -theorem raw_tail_anchored_collision_uniform (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (l m L : ℕ) (hlm : l ≤ m) (x y : V) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - tail.2.mass (walkKernel G hloc a) * - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - mid.2.mass (walkKernel G hloc a)* - anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) ≤ - Real.sqrt c*‖P‖^(l+L) := by - obtain ⟨H,hH,hHn⟩ := exists_anchoredPositionOperator_uniform G hloc root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep j - exact raw_tail_anchored_collision_bound G hloc a γ n hdiam ep j P H hpos hP hH - (Real.sqrt c) hHn l m L hlm x y - -end UniformSuffixCollision -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section GlobalAnchorDenominator -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem anchoredPositionKernel_global_denominator (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) (x z : V) : - (∑ h : segmentAnchors G hloc γ n hdiam ep x, - if h.val j = z then ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ)⁻¹ else 0) = - anchoredPositionKernel G hloc γ n hdiam ep j x z := by - rw [Finset.sum_coe_sort _ (fun h : I → V => if h j = z then - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ)⁻¹ else 0)] - by_cases hx : x ∈ vertexOrbit G (γ ep) - · unfold anchoredPositionKernel - rw [segmentAnchors_card_on_orbit G hloc γ n hdiam ep x hx] - apply Finset.sum_congr rfl - intro h _ - simp only [eq_comm] - · have hz := ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep x).not.mpr hx) - have he := Finset.not_nonempty_iff_eq_empty.mp hz - simp only [anchoredPositionKernel,he,Finset.sum_empty] - -theorem finite_geometric_sum_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (M : ℕ) : - (∑ i : Fin M, ρ^i.val) ≤ 1/(1-ρ) := by - simpa only [Nat.zero_le,ite_true,pow_zero] using finite_geometric_cutoff_bound ρ hρ hρ1 0 M - -end GlobalAnchorDenominator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralSuffixExperiment -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem raw_tail_anchor_collision_identity (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (l m L : ℕ) (x y : V) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if tail.2.position l = h.val j then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - tail.2.mass (walkKernel G hloc a) * - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - mid.2.mass (walkKernel G hloc a)* - anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - simp only [tsum_fintype] - apply Finset.sum_congr rfl - intro tail _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro mid _ - rw [←anchoredPositionKernel_global_denominator G hloc γ n hdiam ep j mid.1 (tail.2.position l)] - simp only [Finset.mul_sum] - apply Finset.sum_congr rfl - intro h _ - by_cases hh : tail.2.position l = h.val j - · simp only [ite_eq_left hh,ite_eq_left hh.symm,div_eq_mul_inv,mul_assoc] - · simp only [ite_eq_right hh,ite_eq_right (Ne.symm hh),mul_zero] - -end LiteralSuffixExperiment -end Percolation - - -namespace Percolation -section NestedFiniteUnion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_threefold_event_union {α β δ : Type*} [Fintype α] [Fintype β] [Fintype δ] - {γ : β → Type*} [∀ b, Fintype (γ b)] - (μ : (a : α) → (b : β) → γ b → ℝ) (hμ : ∀ a b c, 0 ≤ μ a b c) - (B : (a : α) → (b : β) → γ b → δ → Prop) : - (∑ a, ∑ b, ∑ c, if ∃ d, B a b c d then μ a b c else 0) ≤ - ∑ d, ∑ a, ∑ b, ∑ c, if B a b c d then μ a b c else 0 := by - have hh := finite_nonnegative_event_union - (fun ξ : α × Sigma γ => μ ξ.1 ξ.2.1 ξ.2.2) - (fun ξ => hμ ξ.1 ξ.2.1 ξ.2.2) - (fun ξ : α × Sigma γ => B ξ.1 ξ.2.1 ξ.2.2) - simpa only [Fintype.sum_prod_type,Fintype.sum_sigma] using hh - -end NestedFiniteUnion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WholeSuffixCollision -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι S : Type*} [Fintype I] [Fintype ι] [Fintype S] - - - -theorem raw_tail_whole_suffix_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) (j : S → I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hρ : ‖P‖ < 1) (m L : ℕ) (x y : V) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if ∃ ij : Fin (m+1) × S, tail.2.position ij.1.val = h.val (j ij.2) then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - (Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L/(1-‖P‖) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - simp only [tsum_fintype] - have hu := finite_threefold_event_union - (α := RawFrom (openSimpleGraph G Set.univ) m x) - (β := RawFrom (openSimpleGraph G Set.univ) L y) - (γ := fun mid => segmentAnchors G hloc γ n hdiam ep mid.1) - (δ := Fin (m+1) × S) - (fun tail mid _ => tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card) - (fun tail mid _ => div_nonneg (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) (Nat.cast_nonneg _)) - (fun tail _ h ij => tail.2.position ij.1.val = h.val (j ij.2)) - apply hu.trans - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ i : Fin (m+1), ∑ _s : S, Real.sqrt c*‖P‖^(i.val+L) := by - apply Finset.sum_le_sum - intro i _ - apply Finset.sum_le_sum - intro s _ - have hh := raw_tail_anchored_collision_uniform G hloc a root weight Γ hΓ htr hw hw1 hcov c hc hmin - γ n hdiam ep (j s) P hpos hP i.val m L (by omega) x y - rw [←raw_tail_anchor_collision_identity G hloc a γ n hdiam ep (j s) i.val m L x y] at hh - simpa only [tsum_fintype] using hh - _ = ((Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L)*(∑ i : Fin (m+1), ‖P‖^i.val) := by - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,pow_add,←Finset.mul_sum,←Finset.sum_mul] - ring - _ ≤ ((Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L)*(1/(1-‖P‖)) := - mul_le_mul_of_nonneg_left (finite_geometric_sum_bound ‖P‖ (norm_nonneg P) hρ (m+1)) (by positivity) - _ = _ := by ring - -end WholeSuffixCollision -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualAnchorPointTest -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - -theorem raw_anchor_position_identity (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (L : ℕ) (y z : V) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if h.val j = z then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - mid.2.mass (walkKernel G hloc a)*anchoredPositionKernel G hloc γ n hdiam ep j mid.1 z) := by - apply tsum_congr - intro mid - rw [←anchoredPositionKernel_global_denominator G hloc γ n hdiam ep j mid.1 z,tsum_fintype,Finset.mul_sum] - apply Finset.sum_congr rfl - intro h _ - split_ifs <;> simp only [div_eq_mul_inv,mul_zero] - -theorem raw_anchor_point_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) - (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) - (C : ℝ) (hC : ‖H‖ ≤ C) (L : ℕ) (y z : V) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if h.val j = z then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ C*‖P‖^L := by - rw [raw_anchor_position_identity G hloc a γ n hdiam ep j L y z, - raw_anchored_position_expectation G hloc a γ n hdiam ep j P H hpos hP hH L y z] - apply (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (P^L*H) y z).trans _) - calc - _ ≤ ‖P^L‖*‖H‖ := norm_mul_le _ _ - _ ≤ ‖P‖^L*C := mul_le_mul (operator_pow_norm_le P L) hC (norm_nonneg _) (pow_nonneg (norm_nonneg P) L) - _ = _ := mul_comm _ _ - -end ActualAnchorPointTest -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.Labels + +namespace OAI + +/-! Collision Tails for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RawTimeMarginals +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_position_integral (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (i m : ℕ) (him : i ≤ m) (x : V) (f : V → ℝ) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + w.2.mass (walkKernel G hloc a) * f (w.2.position i)) = + RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) i x f := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + induction i generalizing m x with + | zero => + simp only [HoldingWalk.position_zero,tsum_mul_right,rawFrom_probability_sum G hloc a,one_mul,RawFrom.integral_zero] + | succ i ih => + cases m with + | zero => omega + | succ m => + rw [←(RawFrom.succEquiv m x).symm.tsum_eq,RawFrom.integral_succ] + let (z : V) := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m z) + let := Fintype.ofFinite ((openSimpleGraph G Set.univ).neighborSet x) + have hh (z : V) := ih m (Nat.le_of_succ_le_succ him) z + simp only [tsum_fintype,Fintype.sum_sum_type,Fintype.sum_sigma,RawFrom.succEquiv, + Equiv.symm_mk,Equiv.coe_fn_mk,HoldingWalk.mass,HoldingWalk.position,mul_assoc] + simp only [tsum_fintype] at hh + simp only [←Finset.mul_sum,hh] + +theorem raw_position_probability (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (i m : ℕ) (him : i ≤ m) (x z : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + if w.2.position i = z then w.2.mass (walkKernel G hloc a) else 0) = + (matrixCoeff (P^i) x z).re := by + have hh := raw_position_integral G hloc a i m him x (fun y => if y = z then (1:ℝ) else 0) + simp only [mul_ite,mul_one,mul_zero] at hh + rw [hh,raw_integral_operator G hloc a P hpos hP] + simp only [mul_ite,mul_one,mul_zero,tsum_ite_eq] + +end RawTimeMarginals +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IndependentRawCollisions +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_two_time_collision (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (i m j n : ℕ) (him : i ≤ m) (hjn : j ≤ n) (x y : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, + if w.1.2.position i = w.2.2.position j then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) = + (matrixCoeff (P^(i+j)) x y).re := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) n y) + have hi (w : RawFrom (openSimpleGraph G Set.univ) m x) : + (∑' v : RawFrom (openSimpleGraph G Set.univ) n y, + if w.2.position i = v.2.position j then w.2.mass (walkKernel G hloc a)*v.2.mass (walkKernel G hloc a) else 0) = + w.2.mass (walkKernel G hloc a)*(matrixCoeff (P^j) y (w.2.position i)).re := by + rw [← raw_position_probability G hloc a P hpos hP j n hjn y (w.2.position i),←tsum_mul_left] + apply tsum_congr + intro v + by_cases hh : w.2.position i = v.2.position j + · simp only [ite_eq_left hh,ite_eq_left hh.symm] + · simp only [ite_eq_right hh,ite_eq_right (Ne.symm hh),mul_zero] + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] + simp only [hi] + rw [raw_position_integral G hloc a i m him x (fun z => (matrixCoeff (P^j) y z).re),raw_integral_operator G hloc a P hpos hP] + simp only [matrixCoeff_real_symm (P^j) (hsym.pow j) y] + rw [((hpos.pow i).mul_hasSum (P^j) x y).tsum_eq,←pow_add] + +theorem matrixCoeff_norm_le (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + ‖matrixCoeff A x y‖ ≤ ‖A‖ := by + apply (lp.norm_apply_le_norm (by norm_num : (2:ENNReal) ≠ 0) (A (lp.single 2 y (1:ℂ))) x).trans + simpa using A.le_opNorm (lp.single 2 y (1:ℂ)) + +theorem matrixCoeff_power_le (P : Hilbert V →L[ℂ] Hilbert V) (k : ℕ) (x y : V) : + (matrixCoeff (P^k) x y).re ≤ ‖P‖^k := by + have hn (k : ℕ) : ‖P^k‖ ≤ ‖P‖^k := by + induction k with + | zero => simpa only [pow_zero,ContinuousLinearMap.one_def] using + (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) + | succ k ih => + rw [pow_succ,pow_succ] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) + exact (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (P^k) x y).trans (hn k)) + +end IndependentRawCollisions +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FinitePropagation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem reachBall_exists_short_walk (G : BondGraph V E) (x : V) (k : ℕ) {y : V} + (hy : y ∈ reachBall G x k) : + ∃ q : (openSimpleGraph G Set.univ).Walk x y, q.length ≤ k := by + induction k generalizing y with + | zero => + have he : y = x := hy + subst y + exact ⟨.nil,by simp⟩ + | succ k ih => + rcases hy with hy | hy + · obtain ⟨q,hq⟩ := ih hy + exact ⟨q,hq.trans (Nat.le_succ _)⟩ + · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy + obtain ⟨z,hz,hzy⟩ := hy + obtain ⟨q,hq⟩ := ih hz + by_cases he : z = y + · subst z + exact ⟨q,hq.trans (Nat.le_succ _)⟩ + · let h : (openSimpleGraph G Set.univ).Adj z y := + (openSimpleGraph_univ_adj G z y).mpr ⟨he,hzy⟩ + refine ⟨q.append (.cons h .nil),?_⟩ + simpa only [SimpleGraph.Walk.length_append,SimpleGraph.Walk.length_cons, + SimpleGraph.Walk.length_nil,zero_add] using Nat.add_le_add_right hq 1 + +theorem dist_le_of_mem_reachBall (G : BondGraph V E) (x y : V) (k : ℕ) + (hy : y ∈ reachBall G x k) : (openSimpleGraph G Set.univ).dist x y ≤ k := by + obtain ⟨q,hq⟩ := reachBall_exists_short_walk G x k hy + exact (SimpleGraph.dist_le q).trans hq + +theorem walkPower_zero_of_lt_dist (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (k : ℕ) (x y : V) (hk : k < (openSimpleGraph G Set.univ).dist x y) : + (matrixCoeff (P^k) x y).re = 0 := by + apply walkPower_support G hloc a P hpos hP + intro hy + exact Nat.not_le_of_gt hk (dist_le_of_mem_reachBall G x y k hy) + + + +theorem raw_two_time_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (i m j n : ℕ) (him : i ≤ m) (hjn : j ≤ n) (x y : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, + if w.1.2.position i = w.2.2.position j then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ + if i+j < (openSimpleGraph G Set.univ).dist x y then 0 else ‖P‖^(i+j) := by + rw [raw_two_time_collision G hloc a P hpos hsym hP i m j n him hjn x y] + split_ifs with hh + · exact (walkPower_zero_of_lt_dist G hloc a P hpos hP (i+j) x y hh).le + · exact matrixCoeff_power_le P (i+j) x y + +end FinitePropagation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualCollisionUnion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_nonnegative_event_union {α β : Type*} [Fintype α] [Fintype β] + (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (B : α → β → Prop) : + (∑ a, if ∃ b, B a b then μ a else 0) ≤ ∑ b, ∑ a, if B a b then μ a else 0 := by + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro a _ + by_cases hh : ∃ b, B a b + · obtain ⟨b,hb⟩ := hh + rw [ite_eq_left ⟨b,hb⟩] + calc + μ a = (if B a b then μ a else 0) := (ite_eq_left hb).symm + _ ≤ ∑ b, if B a b then μ a else 0 := + Finset.single_le_sum (f := fun b => if B a b then μ a else 0) + (fun b _ => by split_ifs; exact hμ a; exact le_rfl) (Finset.mem_univ b) + · rw [ite_eq_right hh] + exact Finset.sum_nonneg (fun b _ => by split_ifs; exact hμ a; exact le_rfl) + + + +theorem raw_intersection_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (m n : ℕ) (x y : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, + if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ + ∑ i : Fin (m+1), ∑ j : Fin (n+1), + if i.val+j.val < (openSimpleGraph G Set.univ).dist x y then 0 else ‖P‖^(i.val+j.val) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) n y) + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have he (w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y) : + (∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) ↔ + ∃ ij : Fin (m+1) × Fin (n+1), w.1.2.position ij.1 = w.2.2.position ij.2 := by + constructor + · rintro ⟨z,hz,hz'⟩ + obtain ⟨i,hi,he⟩ := w.1.2.mem_vertices_iff_position.mp hz + obtain ⟨j,hj,he'⟩ := w.2.2.mem_vertices_iff_position.mp hz' + exact ⟨(⟨i,by omega⟩,⟨j,by omega⟩),he.trans he'.symm⟩ + · rintro ⟨⟨i,j⟩,hij⟩ + exact ⟨w.1.2.position i,w.1.2.position_mem_vertices i,hij ▸ w.2.2.position_mem_vertices j⟩ + simp only [he,tsum_fintype] + have hu := finite_nonnegative_event_union + (fun w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y => + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a)) + (fun w => mul_nonneg (w.1.2.mass_nonneg _ hK) (w.2.2.mass_nonneg _ hK)) + (fun w (ij : Fin (m+1) × Fin (n+1)) => w.1.2.position ij.1 = w.2.2.position ij.2) + apply hu.trans + rw [Fintype.sum_prod_type] + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + simpa only [tsum_fintype] using + raw_two_time_collision_bound G hloc a P hpos hsym hP i m j n (by omega) (by omega) x y + +end ActualCollisionUnion +end Percolation + + +namespace Percolation +section UniformCollisionTails +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem geometric_cutoff_summable (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J : ℕ) : + Summable (fun i : ℕ => if J ≤ i then ρ^i else 0) := + Summable.of_nonneg_of_le (fun i => by split_ifs <;> positivity) + (fun i => by split_ifs <;> first | exact le_rfl | exact pow_nonneg hρ i) + (summable_geometric_of_lt_one hρ hρ1) + +theorem geometric_cutoff_tsum (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J : ℕ) : + (∑' i : ℕ, if J ≤ i then ρ^i else 0) = ρ^J/(1-ρ) := by + have hs := geometric_cutoff_summable ρ hρ hρ1 J + rw [←hs.sum_add_tsum_nat_add J] + have hz : (∑ i ∈ Finset.range J, if J ≤ i then ρ^i else 0) = 0 := by + apply Finset.sum_eq_zero + intro i hi + exact ite_eq_right (Nat.not_le_of_gt (Finset.mem_range.mp hi)) + rw [hz,zero_add] + simp only [Nat.le_add_left,ite_true,pow_add,tsum_mul_right, + tsum_geometric_of_lt_one hρ hρ1,div_eq_mul_inv] + exact mul_comm _ _ + +theorem finite_geometric_cutoff_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (J M : ℕ) : + (∑ i : Fin M, if J ≤ i.val then ρ^i.val else 0) ≤ ρ^J/(1-ρ) := by + change (∑ i : Fin M, (fun n : ℕ => if J ≤ n then ρ^n else 0) i.val) ≤ _ + rw [Fin.sum_univ_eq_sum_range (fun n : ℕ => if J ≤ n then ρ^n else 0) M,←geometric_cutoff_tsum ρ hρ hρ1 J] + exact Summable.sum_le_tsum (s := Finset.range M) (fun i _ => by split_ifs <;> positivity) + (geometric_cutoff_summable ρ hρ hρ1 J) + + + +theorem finite_double_geometric_cutoff_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) + (J M N D : ℕ) (hD : 2*J ≤ D) : + (∑ i : Fin M, ∑ j : Fin N, if i.val+j.val < D then 0 else ρ^(i.val+j.val)) ≤ + 2*ρ^J/(1-ρ)^2 := by + let q : ℕ → ℝ := fun i => if J ≤ i then ρ^i else 0 + have hq (i : ℕ) : 0 ≤ q i := by dsimp [q]; split_ifs <;> positivity + have hp (i : ℕ) : 0 ≤ ρ^i := pow_nonneg hρ i + have hQ := finite_geometric_cutoff_bound ρ hρ hρ1 J M + have hQ' := finite_geometric_cutoff_bound ρ hρ hρ1 J N + have hS := finite_geometric_cutoff_bound ρ hρ hρ1 0 M + have hS' := finite_geometric_cutoff_bound ρ hρ hρ1 0 N + simp only [Nat.zero_le,ite_true,pow_zero,one_div] at hS hS' + have hd : 0 < 1-ρ := sub_pos.mpr hρ1 + calc + _ ≤ ∑ i : Fin M, ∑ j : Fin N, (q i.val*ρ^j.val + ρ^i.val*q j.val) := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + by_cases hh : i.val+j.val < D + · rw [ite_eq_left hh] + exact add_nonneg (mul_nonneg (hq _) (hp _)) (mul_nonneg (hp _) (hq _)) + · rw [ite_eq_right hh,pow_add] + have hj : J ≤ i.val ∨ J ≤ j.val := by omega + rcases hj with hi | hj + · simp only [q,ite_eq_left hi] + exact le_add_of_nonneg_right (mul_nonneg (hp _) (by split_ifs <;> positivity)) + · simp only [q,ite_eq_left hj] + exact le_add_of_nonneg_left (mul_nonneg (by split_ifs <;> positivity) (hp _)) + _ = (∑ i : Fin M, q i.val)*(∑ j : Fin N, ρ^j.val) + + (∑ i : Fin M, ρ^i.val)*(∑ j : Fin N, q j.val) := by + simp only [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.sum_mul] + _ ≤ (ρ^J/(1-ρ))*(1-ρ)⁻¹ + (1-ρ)⁻¹*(ρ^J/(1-ρ)) := by + apply add_le_add + · exact mul_le_mul hQ hS' (Finset.sum_nonneg (fun i _ => hp _)) (by positivity) + · exact mul_le_mul hS hQ' (Finset.sum_nonneg (fun i _ => hq _)) (by positivity) + _ = _ := by field_simp; ring + +end UniformCollisionTails +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformRawCollision +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_intersection_uniform_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hcontract : ‖P‖ < 1) + (m n J : ℕ) (x y : V) (hD : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, + if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ + 2*‖P‖^J/(1-‖P‖)^2 := + (raw_intersection_probability_bound G hloc a P hpos hsym hP m n x y).trans + (finite_double_geometric_cutoff_bound ‖P‖ (norm_nonneg _) hcontract J (m+1) (n+1) _ hD) + + +theorem exists_uniform_raw_collision_separation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hcontract : ‖P‖ < 1) + (ε : ℝ) (hε : 0 < ε) : + ∃ J₀ : ℕ, ∀ J : ℕ, J₀ ≤ J → ∀ m n : ℕ, ∀ x y : V, + 2*J ≤ (openSimpleGraph G Set.univ).dist x y → + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) n y, + if ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) < ε := by + have ht : Filter.Tendsto (fun J : ℕ => 2*‖P‖^J/(1-‖P‖)^2) Filter.atTop (nhds 0) := by + simpa only [mul_zero,zero_div] using + ((tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg P) hcontract).const_mul 2).div_const ((1-‖P‖)^2) + obtain ⟨J₀,hJ⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds hε)) + refine ⟨J₀,?_⟩ + intro J hJJ m n x y hd + exact (raw_intersection_uniform_bound G hloc a P hpos hsym hP hcontract m n J x y hd).trans_lt (hJ J hJJ) + +end UniformRawCollision +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +namespace HoldingWalk +variable {H : SimpleGraph V} + + + +def fromPositions : (k : ℕ) → (f : Fin (k+1) → V) → + (∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) → + HoldingWalk H k (f 0) (f (Fin.last k)) + | 0,f,_ => .nil (f 0) + | k+1,f,h => .step (h 0) (fromPositions k (fun i => f i.succ) (fun i => h i.succ)) + +theorem mass_fromPositions (P : V → V → ℝ) (a : ℝ) + (hP : ∀ x y, H.Adj x y → P x y = a) + (k : ℕ) (f : Fin (k+1) → V) (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) : + (fromPositions k f h).mass P = a^k := by + induction k with + | zero => rfl + | succ k ih => + change P (f 0) (f 1) * (fromPositions k (fun i => f i.succ) (fun i => h i.succ)).mass P = a^(k+1) + have he : P (f 0) (f 1) = a := by simpa using hP _ _ (h 0) + rw [he,ih,pow_succ'] + +theorem position_fromPositions (k : ℕ) (f : Fin (k+1) → V) + (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) (i : ℕ) (hi : i ≤ k) : + (fromPositions k f h).position i = f ⟨i,by omega⟩ := by + induction k generalizing i with + | zero => + obtain rfl : i = 0 := by omega + rfl + | succ k ih => + cases i with + | zero => rfl + | succ i => + exact ih (fun j => f j.succ) (fun j => h j.succ) i (by omega) + +end HoldingWalk +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +namespace HoldingWalk +variable {H : SimpleGraph V} + +theorem position_append_left {k l : ℕ} {x y z : V} + (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) (i : ℕ) (hi : i ≤ k) : + (w.append v).position i = w.position i := by + induction w generalizing i with + | nil => + obtain rfl : i = 0 := by omega + exact v.position_zero + | hold w ih => cases i with + | zero => rfl + | succ i => exact ih v i (by omega) + | step h w ih => cases i with + | zero => rfl + | succ i => exact ih v i (by omega) + +theorem position_append_right {k l : ℕ} {x y z : V} + (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) (i : ℕ) : + (w.append v).position (k+i) = v.position i := by + induction w with + | nil => simp only [Nat.zero_add,append] + | hold w ih => simpa only [Nat.succ_add,append,position] using ih v + | step h w ih => simpa only [Nat.succ_add,append,position] using ih v + + + +theorem ext_positions {k : ℕ} {x y : V} (w v : HoldingWalk H k x y) + (h : ∀ i : ℕ, i ≤ k → w.position i = v.position i) : w = v := by + induction k generalizing x y with + | zero => cases w; cases v; rfl + | succ k ih => + cases w with + | hold w => + cases v with + | hold v => + congr 1 + exact ih w v (fun i hi => h (i+1) (Nat.succ_le_succ hi)) + | step hv v => + have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) + simp only [position,position_zero] at he + exact (hv.ne he).elim + | step hw w => + cases v with + | hold v => + have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) + simp only [position,position_zero] at he + exact (hw.ne he.symm).elim + | step hv v => + have he := h 1 (Nat.succ_le_succ (Nat.zero_le k)) + simp only [position,position_zero] at he + cases he + congr 1 + exact ih w v (fun i hi => h (i+1) (Nat.succ_le_succ hi)) + +end HoldingWalk +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IntrinsicVisibleBlocks +attribute [local instance] Classical.propDecidable Classical.decEq + +def segmentCenter (J : ℕ) : Fin (J+J+1) := ⟨J,by omega⟩ + +def segmentPositivePositions (J : ℕ) (s : Fin (J+J+1) → V) : Fin (J+1) → V := + fun i => s ⟨J+i.val,by omega⟩ + +def positiveStem (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) + (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) : + HoldingWalk H J (s (segmentCenter J)) (s (Fin.last (J+J))) := + HoldingWalk.fromPositions J (segmentPositivePositions J s) (fun i => hs ⟨J+i.val,by omega⟩) + +theorem positiveStem_mass (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) + (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) + (P : V → V → ℝ) (a : ℝ) (hP : ∀ x y, H.Adj x y → P x y = a) : + (positiveStem H J s hs).mass P = a^J := + HoldingWalk.mass_fromPositions P a hP J _ _ + +theorem orbitSegment_consecutive (G : BondGraph V E) (J : ℕ) (γ s : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (hs : s ∈ segmentOrbit G γ) : + ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (s i.castSucc) (s i.succ) := + fun i => segmentOrbit_adj G γ s hs _ _ (hγ i) + + + +def escapeLabelRaw (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : + HoldingWalk (openSimpleGraph G Set.univ) ((J+L)+J) + (ξ.first (segmentCenter J)) (ξ.last (segmentCenter J)) := + (positiveStem _ J ξ.first (orbitSegment_consecutive G J γ ξ.first hγ ξ.first_mem)).append + (ξ.middle.append (positiveStem _ J ξ.last + (orbitSegment_consecutive G J γ ξ.last hγ ξ.last_mem)).reverse) + +theorem escapeLabelRaw_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : + (escapeLabelRaw G J L m γ hγ ξ).mass (walkKernel G hloc a) = + a^(J+J)*ξ.middle.mass (walkKernel G hloc a) := by + simp only [escapeLabelRaw,HoldingWalk.mass_append,HoldingWalk.mass_reverse _ (walkKernel_symmetric G hloc a), + positiveStem_mass _ _ _ _ _ a (fun _ _ h => walkKernel_step G hloc a h),pow_add] + ring + +theorem escapeLabelRaw_middle_position (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (i : ℕ) (hi : i ≤ L) : + (escapeLabelRaw G J L m γ hγ ξ).position (J+i) = ξ.middle.position i := by + rw [escapeLabelRaw,HoldingWalk.position_append_right,HoldingWalk.position_append_left _ _ i hi] + +end IntrinsicVisibleBlocks +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +namespace RawFrom +variable {H : SimpleGraph V} + + +theorem ext_positions {k : ℕ} {x : V} (w v : RawFrom H k x) + (h : ∀ i : ℕ, i ≤ k → w.2.position i = v.2.position i) : w = v := by + rcases w with ⟨y,w⟩ + rcases v with ⟨z,v⟩ + have he : y = z := by simpa only [HoldingWalk.position_length] using h k le_rfl + subst z + exact Sigma.ext rfl (heq_of_eq (HoldingWalk.ext_positions w v h)) + +theorem pairwise_disjoint_position_indicators {k : ℕ} {x : V} (f : ℕ → V) + {w v : RawFrom H k x} + (hw : ∀ i : ℕ, i ≤ k → w.2.position i = f i) + (hv : ∀ i : ℕ, i ≤ k → v.2.position i = f i) : w = v := + ext_positions w v (fun i hi => (hw i hi).trans (hv i hi).symm) + +end RawFrom + + + +theorem finite_single_fiber_weight_bound {α : Type*} [Fintype α] + (μ : α → ℝ) (B : α → Prop) [DecidablePred B] (C : ℝ) (hC : 0 ≤ C) + (hunique : ∀ a b, B a → B b → a = b) (hbound : ∀ a, B a → μ a ≤ C) : + (∑ a, if B a then μ a else 0) ≤ C := by + classical + by_cases hh : ∃ a, B a + · obtain ⟨a,ha⟩ := hh + calc + _ = μ a := by + rw [Finset.sum_eq_single a] + · exact ite_eq_left ha + · intro b _ hba + exact ite_eq_right (fun hb => hba (hunique b a hb ha)) + · simp + _ ≤ C := hbound a ha + · simpa only [not_exists.mp hh,ite_false,Finset.sum_const_zero] using hC + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RootedRawProjection +attribute [local instance] Classical.propDecidable Classical.decEq + +def rootedEscapeLabelRaw (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : + RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x := by + rcases ξ with ⟨ξ,hξ⟩ + subst x + exact ⟨ξ.last (segmentCenter J),escapeLabelRaw G J L m γ hγ ξ⟩ + +theorem rootedEscapeLabelRaw_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : + (rootedEscapeLabelRaw G J L m γ hγ x ξ).2.mass (walkKernel G hloc a) = + a^(J+J)*ξ.1.middle.mass (walkKernel G hloc a) := by + rcases ξ with ⟨ξ,hξ⟩ + subst x + exact escapeLabelRaw_mass G hloc a J L m γ hγ ξ + +theorem rootedEscapeLabelRaw_middle_position (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) + (i : ℕ) (hi : i ≤ L) : + (rootedEscapeLabelRaw G J L m γ hγ x ξ).2.position (J+i) = ξ.1.middle.position i := by + rcases ξ with ⟨ξ,hξ⟩ + subst x + exact escapeLabelRaw_middle_position G J L m γ hγ ξ i hi + +theorem rootedEscapeLabelRaw_fiber_middle_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (ha : 0 < a) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) + (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) + (hw : rootedEscapeLabelRaw G J L m γ hγ x ξ = w) : + ξ.1.middle.mass (walkKernel G hloc a) = w.2.mass (walkKernel G hloc a)/a^(J+J) := by + apply (eq_div_iff (ne_of_gt (pow_pos ha _))).mpr + rw [mul_comm,←rootedEscapeLabelRaw_mass G hloc a J L m γ hγ x ξ,hw] + +theorem rootedEscapeLabelRaw_fiber_middle_positions (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) + (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) + (hw : rootedEscapeLabelRaw G J L m γ hγ x ξ = w) : + ∀ i : ℕ, i ≤ L → ξ.1.middle.position i = w.2.position (J+i) := by + intro i hi + rw [←rootedEscapeLabelRaw_middle_position G J L m γ hγ x ξ i hi,hw] + +end RootedRawProjection +end Percolation + + +namespace Percolation +section FiniteFiberDomination +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_auxiliary_event_bound {α : Type*} [Fintype α] + (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (hs : ∑ a, μ a = 1) + (B : α → Prop) (c : ℝ) (hc : 0 ≤ c) : + (∑ a, if B a then c*μ a else 0) ≤ c := by + calc + _ ≤ ∑ a, c*μ a := Finset.sum_le_sum (fun a _ => by + split_ifs; exact le_rfl; exact mul_nonneg hc (hμ a)) + _ = c := by rw [←Finset.mul_sum,hs,mul_one] + + + +theorem finite_nested_unique_fiber_bound {β : Type*} [Fintype β] + {γ : β → Type*} [∀ b, Fintype (γ b)] + {T : (b : β) → γ b → Type*} [∀ b c, Fintype (T b c)] + (μ : β → ℝ) (hμ : ∀ b, 0 ≤ μ b) + (ν : (b : β) → (c : γ b) → T b c → ℝ) (hν : ∀ b c t, 0 ≤ ν b c t) + (hs : ∀ b c, ∑ t, ν b c t = 1) + (B : (b : β) → (c : γ b) → T b c → Prop) + (N C : ℝ) (hN : 0 ≤ N) (hC : 0 ≤ C) + (hcard : ∀ b, (Fintype.card (γ b) : ℝ) ≤ N) + (hunique : ∀ b c t b' c' t', B b c t → B b' c' t' → b = b') + (hbound : ∀ b c t, B b c t → μ b ≤ C) : + (∑ b, ∑ c, ∑ t, if B b c t then μ b*ν b c t else 0) ≤ N*C := by + by_cases hh : ∃ b c t, B b c t + · obtain ⟨b,c,t,hb⟩ := hh + have he : (∑ b', ∑ c', ∑ t', if B b' c' t' then μ b'*ν b' c' t' else 0) = + ∑ c', ∑ t', if B b c' t' then μ b*ν b c' t' else 0 := by + apply Finset.sum_eq_single b + · intro b' _ hne + apply Finset.sum_eq_zero + intro c' _ + apply Finset.sum_eq_zero + intro t' _ + exact ite_eq_right (fun hb' => hne (hunique b' c' t' b c t hb' hb)) + · simp + rw [he] + calc + _ ≤ ∑ _c : γ b, μ b := Finset.sum_le_sum (fun c' _ => + finite_auxiliary_event_bound (ν b c') (hν b c') (hs b c') (B b c') (μ b) (hμ b)) + _ = (Fintype.card (γ b) : ℝ)*μ b := by simp + _ ≤ N*C := mul_le_mul (hcard b) (hbound b c t hb) (hμ b) hN + · have hz : ∀ b c t, ¬B b c t := by simpa only [not_exists] using hh + simp only [hz,ite_false,Finset.sum_const_zero] + exact mul_nonneg hN hC + +end FiniteFiberDomination +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section CodeMiddleIdentities +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +theorem labelFromCode_middle_position (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) + (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) (i : ℕ) : + (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.middle.position i = + c.2.1.2.position i := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + +theorem labelFromCode_middle_mass (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (P : V → V → ℝ) + (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : + (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.middle.mass P = + c.2.1.2.mass P := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + +end CodeMiddleIdentities +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralFiberEstimate +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem rooted_code_single_anchor_fiber_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) + (s : segmentAnchors G hloc γ n hdiam (segmentCenter J) x) + (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val (Fin.last (J+J))), + ∑' h : segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) mid.1, + ∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val 0) × + RawFrom (openSimpleGraph G Set.univ) m (h.val 0), + if rootedEscapeLabelRaw G J L m γ hγ x + (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x + ⟨s,mid,h,tails⟩) = w then + mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * + tails.2.2.mass (walkKernel G hloc a) else 0) ≤ + ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * + (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + simp only [tsum_fintype,mul_assoc] + convert finite_nested_unique_fiber_bound + (β := RawFrom (openSimpleGraph G Set.univ) L (s.val (Fin.last (J+J)))) + (γ := fun mid => segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) mid.1) + (T := fun _ h => RawFrom (openSimpleGraph G Set.univ) m (s.val 0) × + RawFrom (openSimpleGraph G Set.univ) m (h.val 0)) + (fun mid => mid.2.mass (walkKernel G hloc a)) + (fun mid => mid.2.mass_nonneg _ hK) + (fun _ _ tails => tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a)) + (fun _ _ tails => mul_nonneg (tails.1.2.mass_nonneg _ hK) (tails.2.2.mass_nonneg _ hK)) ?_ + (fun mid h tails => rootedEscapeLabelRaw G J L m γ hγ x + (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) = w) + (((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ)) + (w.2.mass (walkKernel G hloc a)/a^(J+J)) ?_ ?_ ?_ ?_ ?_ using 1 + · apply Finset.sum_congr rfl + intro mid _ + apply Finset.sum_congr rfl + intro h _ + apply Finset.sum_congr rfl + intro tails _ + split_ifs <;> rfl + · intro mid h + rw [Fintype.sum_prod_type] + simp only [←Finset.mul_sum,←Finset.sum_mul] + simpa only [tsum_fintype,mul_one] using congrArg₂ (fun r s : ℝ => r*s) + (rawFrom_probability_sum G hloc a m (s.val 0)) + (rawFrom_probability_sum G hloc a m (h.val 0)) + · positivity + · exact div_nonneg (w.2.mass_nonneg _ hK) (pow_nonneg ha.le _) + · intro mid + rw [Fintype.card_coe,segmentAnchors_card_eq_indicator G hloc γ n hdiam (Fin.last (J+J)) mid.1] + split_ifs + · exact le_rfl + · exact_mod_cast Nat.zero_le _ + · intro mid h tails mid' h' tails' hh hh' + apply RawFrom.ext_positions + intro i hi + have he := rootedEscapeLabelRaw_fiber_middle_positions G J L m γ hγ x + (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) w hh i hi + have he' := rootedEscapeLabelRaw_fiber_middle_positions G J L m γ hγ x + (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid',h',tails'⟩) w hh' i hi + have hm := labelFromCode_middle_position G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩ i + have hm' := labelFromCode_middle_position G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid',h',tails'⟩ i + exact hm.symm.trans (he.trans (he'.symm.trans hm')) + · intro mid h tails hh + have he := rootedEscapeLabelRaw_fiber_middle_mass G hloc a ha J L m γ hγ x + (labelFromCode G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x ⟨s,mid,h,tails⟩) w hh + have hm := labelFromCode_middle_mass G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x (walkKernel G hloc a) ⟨s,mid,h,tails⟩ + exact (hm.symm.trans he).le + +end LiteralFiberEstimate +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralProjectionDomination +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem rooted_label_raw_fiber_mass_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) + (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : + (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, + if rootedEscapeLabelRaw G J L m γ hγ x ξ = w then ξ.1.mass (walkKernel G hloc a) else 0) ≤ + ((segmentAnchors G hloc γ n hdiam (segmentCenter J) x).card : ℝ) * + ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * + (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := finite_rootedEscapeLabels G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x + let R := rootedLabelEquiv G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x + rw [←R.symm.tsum_eq] + simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] + unfold RootedLabelCode at * + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + calc + _ ≤ ∑' _s : segmentAnchors G hloc γ n hdiam (segmentCenter J) x, + ((segmentAnchors G hloc γ n hdiam (Fin.last (J+J)) (γ (Fin.last (J+J)))).card : ℝ) * + (w.2.mass (walkKernel G hloc a)/a^(J+J)) := by + apply (summable_of_hasFiniteSupport (Set.toFinite _)).tsum_le_tsum _ + (summable_of_hasFiniteSupport (Set.toFinite _)) + intro s + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + conv_lhs => arg 1; ext mid; rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + exact rooted_code_single_anchor_fiber_bound G hloc a ha hK J L m γ hγ n hdiam x s w + _ = _ := by + simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + ring + +end LiteralProjectionDomination +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NormalizedProjection +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem tsum_indicator_div {α : Type*} (f : α → ℝ) (B : α → Prop) [DecidablePred B] (d : ℝ) : + (∑' a, if B a then f a/d else 0) = (∑' a, if B a then f a else 0)/d := by + rw [←tsum_div_const] + apply tsum_congr + intro a + split_ifs <;> simp + +theorem rooted_label_raw_projection_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) + (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) + (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) + (w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) : + (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, + if rootedEscapeLabelRaw G J L m γ hγ x ξ = w then + escapeLabelProbability G hloc a γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) ≤ + w.2.mass (walkKernel G hloc a)/(a^(J+J)*q) := by + have hN (i : Fin (J+J+1)) : 0 < ((segmentAnchors G hloc γ n hdiam i (γ i)).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i (γ i)).mpr + (by exact ⟨Equiv.refl V,Equiv.refl E,(fun e => by simp),rfl⟩)) + have hQ := hq.trans_le hqle + have hA := pow_pos ha (J+J) + have hm := w.2.mass_nonneg (walkKernel G hloc a) hK + simp only [escapeLabelProbability,tsum_indicator_div] + have hb := rooted_label_raw_fiber_mass_bound G hloc a ha hK J L m γ hγ n hdiam x w + rw [segmentAnchors_card_on_orbit G hloc γ n hdiam (segmentCenter J) x hx] at hb + apply (div_le_div_of_nonneg_right hb (mul_nonneg (mul_nonneg (hN (segmentCenter J)).le (hN (Fin.last (J+J))).le) hQ.le)).trans + calc + _ = w.2.mass (walkKernel G hloc a)/ + (a^(J+J)*segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) := by + field_simp [(hN (segmentCenter J)).ne', (hN (Fin.last (J+J))).ne'] + _ ≤ _ := div_le_div_of_nonneg_left hm (mul_pos hA hq) (mul_le_mul_of_nonneg_left hqle hA.le) + +end NormalizedProjection +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +section SuffixCollisionOperator + +theorem operator_pow_norm_le (P : Hilbert V →L[ℂ] Hilbert V) (k : ℕ) : ‖P^k‖ ≤ ‖P‖^k := by + cases k with + | zero => simpa only [pow_zero,ContinuousLinearMap.one_def] using + (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) + | succ k => exact norm_pow_le' P (Nat.succ_pos k) + + + +theorem positive_rows_collision_hasSum (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) (x y : V) : + HasSum (fun z => (matrixCoeff A x z).re*(matrixCoeff B y z).re) + (matrixCoeff (A*star B) x y).re := by + simpa only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_re] using + hA.mul_hasSum (star B) x y + +theorem positive_rows_collision_bound (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) (x y : V) : + (∑' z, (matrixCoeff A x z).re*(matrixCoeff B y z).re) ≤ ‖A‖*‖B‖ := by + rw [(positive_rows_collision_hasSum A B hA x y).tsum_eq] + apply (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (A*star B) x y).trans _) + have hs : ‖star B‖ = ‖B‖ := ContinuousLinearMap.adjoint.norm_map B + simpa only [hs] using norm_mul_le A (star B) + +theorem walk_suffix_collision_operator_bound (P H : Hilbert V →L[ℂ] Hilbert V) + (hP : PositiveRealMatrix P) (C : ℝ) (hH : ‖H‖ ≤ C) (l L : ℕ) (x y : V) : + (∑' z, (matrixCoeff (P^l) x z).re*(matrixCoeff (P^L*H) y z).re) ≤ + C*‖P‖^(l+L) := by + calc + _ ≤ ‖P^l‖*‖P^L*H‖ := positive_rows_collision_bound _ _ (hP.pow l) x y + _ ≤ ‖P‖^l*(‖P‖^L*C) := mul_le_mul (operator_pow_norm_le P l) + ((norm_mul_le _ _).trans (mul_le_mul (operator_pow_norm_le P L) hH (norm_nonneg H) + (pow_nonneg (norm_nonneg P) L))) (norm_nonneg _) (pow_nonneg (norm_nonneg P) l) + _ = _ := by rw [pow_add]; ring + +end SuffixCollisionOperator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualSuffixCollision +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem raw_anchored_position_expectation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) + (L : ℕ) (x z : V) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L x, + mid.2.mass (walkKernel G hloc a)*anchoredPositionKernel G hloc γ n hdiam ep j mid.1 z) = + (matrixCoeff (P^L*H) x z).re := by + change RawFrom.integral (walkKernel G hloc a) L x + (fun y => anchoredPositionKernel G hloc γ n hdiam ep j y z) = _ + rw [raw_integral_operator G hloc a P hpos hP] + simpa only [hH,Complex.ofReal_re] using ((hpos.pow L).mul_hasSum H x z).tsum_eq + + + +theorem raw_tail_anchored_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) + (C : ℝ) (hHC : ‖H‖ ≤ C) (l m L : ℕ) (hlm : l ≤ m) (x y : V) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + tail.2.mass (walkKernel G hloc a) * + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + mid.2.mass (walkKernel G hloc a)* + anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) ≤ + C*‖P‖^(l+L) := by + simp only [raw_anchored_position_expectation G hloc a γ n hdiam ep j P H hpos hP hH] + rw [raw_position_integral G hloc a l m hlm x (fun z => (matrixCoeff (P^L*H) y z).re), + raw_integral_operator G hloc a P hpos hP] + exact walk_suffix_collision_operator_bound P H hpos C hHC l L x y + +end ActualSuffixCollision +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section UniformSuffixCollision +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι : Type*} [Fintype I] [Fintype ι] + + + +theorem raw_tail_anchored_collision_uniform (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (l m L : ℕ) (hlm : l ≤ m) (x y : V) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + tail.2.mass (walkKernel G hloc a) * + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + mid.2.mass (walkKernel G hloc a)* + anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) ≤ + Real.sqrt c*‖P‖^(l+L) := by + obtain ⟨H,hH,hHn⟩ := exists_anchoredPositionOperator_uniform G hloc root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep j + exact raw_tail_anchored_collision_bound G hloc a γ n hdiam ep j P H hpos hP hH + (Real.sqrt c) hHn l m L hlm x y + +end UniformSuffixCollision +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section GlobalAnchorDenominator +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem anchoredPositionKernel_global_denominator (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) (x z : V) : + (∑ h : segmentAnchors G hloc γ n hdiam ep x, + if h.val j = z then ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ)⁻¹ else 0) = + anchoredPositionKernel G hloc γ n hdiam ep j x z := by + rw [Finset.sum_coe_sort _ (fun h : I → V => if h j = z then + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ)⁻¹ else 0)] + by_cases hx : x ∈ vertexOrbit G (γ ep) + · unfold anchoredPositionKernel + rw [segmentAnchors_card_on_orbit G hloc γ n hdiam ep x hx] + apply Finset.sum_congr rfl + intro h _ + simp only [eq_comm] + · have hz := ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep x).not.mpr hx) + have he := Finset.not_nonempty_iff_eq_empty.mp hz + simp only [anchoredPositionKernel,he,Finset.sum_empty] + +theorem finite_geometric_sum_bound (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (M : ℕ) : + (∑ i : Fin M, ρ^i.val) ≤ 1/(1-ρ) := by + simpa only [Nat.zero_le,ite_true,pow_zero] using finite_geometric_cutoff_bound ρ hρ hρ1 0 M + +end GlobalAnchorDenominator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralSuffixExperiment +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem raw_tail_anchor_collision_identity (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (l m L : ℕ) (x y : V) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if tail.2.position l = h.val j then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + tail.2.mass (walkKernel G hloc a) * + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + mid.2.mass (walkKernel G hloc a)* + anchoredPositionKernel G hloc γ n hdiam ep j mid.1 (tail.2.position l)) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + simp only [tsum_fintype] + apply Finset.sum_congr rfl + intro tail _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro mid _ + rw [←anchoredPositionKernel_global_denominator G hloc γ n hdiam ep j mid.1 (tail.2.position l)] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro h _ + by_cases hh : tail.2.position l = h.val j + · simp only [ite_eq_left hh,ite_eq_left hh.symm,div_eq_mul_inv,mul_assoc] + · simp only [ite_eq_right hh,ite_eq_right (Ne.symm hh),mul_zero] + +end LiteralSuffixExperiment +end Percolation + + +namespace Percolation +section NestedFiniteUnion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_threefold_event_union {α β δ : Type*} [Fintype α] [Fintype β] [Fintype δ] + {γ : β → Type*} [∀ b, Fintype (γ b)] + (μ : (a : α) → (b : β) → γ b → ℝ) (hμ : ∀ a b c, 0 ≤ μ a b c) + (B : (a : α) → (b : β) → γ b → δ → Prop) : + (∑ a, ∑ b, ∑ c, if ∃ d, B a b c d then μ a b c else 0) ≤ + ∑ d, ∑ a, ∑ b, ∑ c, if B a b c d then μ a b c else 0 := by + have hh := finite_nonnegative_event_union + (fun ξ : α × Sigma γ => μ ξ.1 ξ.2.1 ξ.2.2) + (fun ξ => hμ ξ.1 ξ.2.1 ξ.2.2) + (fun ξ : α × Sigma γ => B ξ.1 ξ.2.1 ξ.2.2) + simpa only [Fintype.sum_prod_type,Fintype.sum_sigma] using hh + +end NestedFiniteUnion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WholeSuffixCollision +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι S : Type*} [Fintype I] [Fintype ι] [Fintype S] + + + +theorem raw_tail_whole_suffix_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) (j : S → I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hρ : ‖P‖ < 1) (m L : ℕ) (x y : V) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if ∃ ij : Fin (m+1) × S, tail.2.position ij.1.val = h.val (j ij.2) then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + (Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L/(1-‖P‖) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + simp only [tsum_fintype] + have hu := finite_threefold_event_union + (α := RawFrom (openSimpleGraph G Set.univ) m x) + (β := RawFrom (openSimpleGraph G Set.univ) L y) + (γ := fun mid => segmentAnchors G hloc γ n hdiam ep mid.1) + (δ := Fin (m+1) × S) + (fun tail mid _ => tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card) + (fun tail mid _ => div_nonneg (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) (Nat.cast_nonneg _)) + (fun tail _ h ij => tail.2.position ij.1.val = h.val (j ij.2)) + apply hu.trans + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ i : Fin (m+1), ∑ _s : S, Real.sqrt c*‖P‖^(i.val+L) := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro s _ + have hh := raw_tail_anchored_collision_uniform G hloc a root weight Γ hΓ htr hw hw1 hcov c hc hmin + γ n hdiam ep (j s) P hpos hP i.val m L (by omega) x y + rw [←raw_tail_anchor_collision_identity G hloc a γ n hdiam ep (j s) i.val m L x y] at hh + simpa only [tsum_fintype] using hh + _ = ((Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L)*(∑ i : Fin (m+1), ‖P‖^i.val) := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,pow_add,←Finset.mul_sum,←Finset.sum_mul] + ring + _ ≤ ((Fintype.card S : ℝ)*Real.sqrt c*‖P‖^L)*(1/(1-‖P‖)) := + mul_le_mul_of_nonneg_left (finite_geometric_sum_bound ‖P‖ (norm_nonneg P) hρ (m+1)) (by positivity) + _ = _ := by ring + +end WholeSuffixCollision +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualAnchorPointTest +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + +theorem raw_anchor_position_identity (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (L : ℕ) (y z : V) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if h.val j = z then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + mid.2.mass (walkKernel G hloc a)*anchoredPositionKernel G hloc γ n hdiam ep j mid.1 z) := by + apply tsum_congr + intro mid + rw [←anchoredPositionKernel_global_denominator G hloc γ n hdiam ep j mid.1 z,tsum_fintype,Finset.mul_sum] + apply Finset.sum_congr rfl + intro h _ + split_ifs <;> simp only [div_eq_mul_inv,mul_zero] + +theorem raw_anchor_point_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep j : I) + (P H : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hH : ∀ x y, matrixCoeff H x y = (anchoredPositionKernel G hloc γ n hdiam ep j x y : ℂ)) + (C : ℝ) (hC : ‖H‖ ≤ C) (L : ℕ) (y z : V) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if h.val j = z then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ C*‖P‖^L := by + rw [raw_anchor_position_identity G hloc a γ n hdiam ep j L y z, + raw_anchored_position_expectation G hloc a γ n hdiam ep j P H hpos hP hH L y z] + apply (Complex.re_le_norm _).trans ((matrixCoeff_norm_le (P^L*H) y z).trans _) + calc + _ ≤ ‖P^L‖*‖H‖ := norm_mul_le _ _ + _ ≤ ‖P‖^L*C := mul_le_mul (operator_pow_norm_le P L) hC (norm_nonneg _) (pow_nonneg (norm_nonneg P) L) + _ = _ := mul_comm _ _ + +end ActualAnchorPointTest +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Escape/Labels.lean b/lean/OAI/Probability/UnimodularPercolation/Escape/Labels.lean index 754c35764ab8bf74561289de683454e85796bb11..d5eb73e2ab00b8ba3b92be5634c7f924e6ca1d58 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Escape/Labels.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Escape/Labels.lean @@ -1,1216 +1,1216 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Deformation.AveragedDecrease - -namespace OAI - -/-! Labels for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section LabeledEscapeExperiment - - - -structure EscapeLabel (G : BondGraph V E) (γ : I → V) (endpoint negative : I) (L m : ℕ) where - first : I → V - first_mem : first ∈ segmentOrbit G γ - last : I → V - last_mem : last ∈ segmentOrbit G γ - middle : HoldingWalk (openSimpleGraph G Set.univ) L (first endpoint) (last endpoint) - leftTail : RawFrom (openSimpleGraph G Set.univ) m (first negative) - rightTail : RawFrom (openSimpleGraph G Set.univ) m (last negative) - -namespace EscapeLabel -variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} - -def reverse (ξ : EscapeLabel G γ ep neg L m) : EscapeLabel G γ ep neg L m where - first := ξ.last - first_mem := ξ.last_mem - last := ξ.first - last_mem := ξ.first_mem - middle := ξ.middle.reverse - leftTail := ξ.rightTail - rightTail := ξ.leftTail - -theorem reverse_reverse (ξ : EscapeLabel G γ ep neg L m) : ξ.reverse.reverse = ξ := by - cases ξ - simp only [reverse,HoldingWalk.reverse_reverse] - -def reverseEquiv : EscapeLabel G γ ep neg L m ≃ EscapeLabel G γ ep neg L m where - toFun := reverse - invFun := reverse - left_inv := reverse_reverse - right_inv := reverse_reverse - -noncomputable def mass (P : V → V → ℝ) (ξ : EscapeLabel G γ ep neg L m) : ℝ := - ξ.middle.mass P * ξ.leftTail.2.mass P * ξ.rightTail.2.mass P - -theorem mass_nonneg (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (ξ : EscapeLabel G γ ep neg L m) : 0 ≤ ξ.mass P := - mul_nonneg (mul_nonneg (ξ.middle.mass_nonneg P hP) (ξ.leftTail.2.mass_nonneg P hP)) - (ξ.rightTail.2.mass_nonneg P hP) - -theorem mass_reverse (P : V → V → ℝ) (hP : ∀ x y, P x y = P y x) - (ξ : EscapeLabel G γ ep neg L m) : ξ.reverse.mass P = ξ.mass P := by - simp only [mass,reverse,HoldingWalk.mass_reverse P hP] - ring - - - -def reverseRootedEquiv (center : I) (x y : V) : - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} ≃ - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = y ∧ ξ.last center = x} where - toFun ξ := ⟨ξ.1.reverse,ξ.2.2,ξ.2.1⟩ - invFun ξ := ⟨ξ.1.reverse,ξ.2.2,ξ.2.1⟩ - left_inv ξ := Subtype.ext (reverse_reverse ξ.1) - right_inv ξ := Subtype.ext (reverse_reverse ξ.1) - -end EscapeLabel -end LabeledEscapeExperiment -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section FiniteRootedLabels -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -noncomputable def RootedLabelCode (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) : Type (max u w) := - Σ s : (segmentAnchors G hloc γ n hdiam center x), - Σ mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - Σ h : (segmentAnchors G hloc γ n hdiam ep mid.1), - RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg) - -instance finite_rootedLabelCode (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) : - Finite (RootedLabelCode G hloc γ n hdiam center ep neg L m x) := by - let (z : V) := finite_openSimpleGraph_neighbors G hloc z - unfold RootedLabelCode - infer_instance - -noncomputable def labelFromCode (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) - (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - have hsm := ((mem_segmentAnchors G hloc γ n hdiam center x s).mp hs).1 - have hsx := ((mem_segmentAnchors G hloc γ n hdiam center x s).mp hs).2 - have hhm := ((mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh).1 - have hhz := ((mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh).2 - subst z - exact ⟨⟨s,hsm,h,hhm,mid,α,β⟩,hsx⟩ - -noncomputable def labelToCode (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) - (ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}) : - RootedLabelCode G hloc γ n hdiam center ep neg L m x := - ⟨⟨ξ.1.first,(mem_segmentAnchors G hloc γ n hdiam center x ξ.1.first).mpr ⟨ξ.1.first_mem,ξ.2⟩⟩, - ⟨ξ.1.last ep,ξ.1.middle⟩, - ⟨ξ.1.last,(mem_segmentAnchors G hloc γ n hdiam ep (ξ.1.last ep) ξ.1.last).mpr ⟨ξ.1.last_mem,rfl⟩⟩, - ξ.1.leftTail,ξ.1.rightTail⟩ - -noncomputable def rootedLabelEquiv (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) : - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} ≃ - RootedLabelCode G hloc γ n hdiam center ep neg L m x where - toFun := labelToCode G hloc γ n hdiam center ep neg L m x - invFun := labelFromCode G hloc γ n hdiam center ep neg L m x - left_inv ξ := by - cases ξ with - | mk ξ hξ => cases ξ; rfl - right_inv c := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - have hh' := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - obtain ⟨hhm,hhz⟩ := hh' - subst z - rfl - -theorem finite_rootedEscapeLabels (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) : - Finite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} := - Finite.of_equiv _ (rootedLabelEquiv G hloc γ n hdiam center ep neg L m x).symm - -end FiniteRootedLabels -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section LabeledMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -theorem segmentAnchors_card_on_orbit (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) - (hx : x ∈ vertexOrbit G (γ i)) : - (segmentAnchors G hloc γ n hdiam i x).card = (segmentAnchors G hloc γ n hdiam i (γ i)).card := by - obtain ⟨a,b,h,rfl⟩ := hx - exact segmentAnchors_card_aut G hloc γ n hdiam i (γ i) h - -theorem segmentAnchors_card_eq_indicator (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : - ((segmentAnchors G hloc γ n hdiam i x).card : ℝ) = - if x ∈ vertexOrbit G (γ i) then (segmentAnchors G hloc γ n hdiam i (γ i)).card else 0 := by - split_ifs with hx - · exact congrArg Nat.cast (segmentAnchors_card_on_orbit G hloc γ n hdiam i x hx) - · have hh := (segmentAnchors_nonempty_iff G hloc γ n hdiam i x).not.mpr hx - rw [Finset.not_nonempty_iff_eq_empty.mp hh] - rfl - -noncomputable def segmentReturnMass (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) : ℝ := - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L x, - if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0 - -theorem labelFromCode_mass (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (P : V → V → ℝ) - (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : - (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.mass P = - c.2.1.2.mass P * c.2.2.2.1.2.mass P * c.2.2.2.2.2.mass P := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - - - -theorem rooted_label_mass_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - ξ.1.mass (walkKernel G hloc a)) = - ∑ s ∈ segmentAnchors G hloc γ n hdiam center x, - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * - segmentReturnMass G hloc a γ ep L (s ep) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x - rw [←R.symm.tsum_eq] - simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] - unfold RootedLabelCode at * - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - change (∑' s : (segmentAnchors G hloc γ n hdiam center x), _) = _ - rw [tsum_fintype] - conv_rhs => rw [←Finset.sum_coe_sort] - apply Finset.sum_congr rfl - intro s _ - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - have he (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) : - (∑' h : (segmentAnchors G hloc γ n hdiam ep mid.1), - ∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * - tails.2.2.mass (walkKernel G hloc a)) = - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * - (if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0) := by - have ht (h : (segmentAnchors G hloc γ n hdiam ep mid.1)) : - (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * - tails.2.2.mass (walkKernel G hloc a)) = mid.2.mass (walkKernel G hloc a) := by - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] - simp only [tsum_mul_left,rawFrom_probability_sum G hloc a,mul_one] - simp only [ht,tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] - rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] - split_ifs <;> ring - calc - _ = ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * - (if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0) := by - apply tsum_congr - intro mid - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - exact he mid - _ = _ := tsum_mul_left - -end LabeledMass -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section LabeledNormalization -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -omit [Fintype I] in -theorem segmentReturnMass_operator (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) : - segmentReturnMass G hloc a γ ep L x = - ∑' y, if y ∈ vertexOrbit G (γ ep) then (matrixCoeff (P^L) x y).re else 0 := by - have hh := raw_integral_operator G hloc a P hpos hP L x - (fun y => if y ∈ vertexOrbit G (γ ep) then 1 else 0) - simpa only [RawFrom.integral,mul_ite,mul_one,mul_zero,segmentReturnMass] using hh - -omit [Fintype I] in -theorem segmentReturnMass_aut (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) : - segmentReturnMass G hloc a γ ep L (g x) = segmentReturnMass G hloc a γ ep L x := by - rw [segmentReturnMass_operator G hloc a γ ep L (g x) P hpos hP, - segmentReturnMass_operator G hloc a γ ep L x P hpos hP,←g.tsum_eq] - apply tsum_congr - intro y - rw [mem_vertexOrbit_aut_iff G (γ ep) hg] - have hh := walkPower_invariant G hloc a P hP L g ⟨b,hg⟩ x y - rw [hh] - -omit [Fintype I] in -theorem segmentReturnMass_on_orbit (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) - (hx : x ∈ vertexOrbit G (γ ep)) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) : - segmentReturnMass G hloc a γ ep L x = segmentReturnMass G hloc a γ ep L (γ ep) := by - obtain ⟨g,b,hg,rfl⟩ := hx - exact segmentReturnMass_aut G hloc a γ ep L (γ ep) P hpos hP hg - - - -noncomputable def escapeLabelProbability (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : ℝ := - ξ.mass (walkKernel G hloc a) / - (((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) * - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * - segmentReturnMass G hloc a γ ep L (γ ep)) - -theorem rooted_label_probability_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hq : segmentReturnMass G hloc a γ ep L (γ ep) ≠ 0) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) = 1 := by - have hN (i : I) : ((segmentAnchors G hloc γ n hdiam i (γ i)).card : ℝ) ≠ 0 := by - apply ne_of_gt - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i (γ i)).mpr - (by exact ⟨Equiv.refl V,Equiv.refl E,(fun e => by simp),rfl⟩)) - simp only [escapeLabelProbability,tsum_div_const] - rw [rooted_label_mass_sum G hloc a γ n hdiam center ep neg L m x] - have he (s : I → V) (hs : s ∈ segmentAnchors G hloc γ n hdiam center x) : - segmentReturnMass G hloc a γ ep L (s ep) = segmentReturnMass G hloc a γ ep L (γ ep) := by - obtain ⟨⟨g,b,hg,rfl⟩,_⟩ := (mem_segmentAnchors G hloc γ n hdiam center x s).mp hs - exact segmentReturnMass_aut G hloc a γ ep L (γ ep) P hpos hP hg - rw [Finset.sum_congr rfl (fun s hs => congrArg (fun q => _ * q) (he s hs))] - simp only [Finset.sum_const,nsmul_eq_mul] - rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx,←mul_assoc] - exact div_self (mul_ne_zero (mul_ne_zero (hN center) (hN ep)) hq) - -theorem escapeLabelProbability_reverse (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.reverse = - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by - simp only [escapeLabelProbability,EscapeLabel.mass_reverse _ (walkKernel_symmetric G hloc a)] - -end LabeledNormalization -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -theorem isAut_refl (G : BondGraph V E) : IsAut G (Equiv.refl V) (Equiv.refl E) := by - intro e - simp - -namespace EscapeLabel -variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} - -def autMap {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (ξ : EscapeLabel G γ ep neg L m) : EscapeLabel G γ ep neg L m where - first := a ∘ ξ.first - first_mem := (segmentOrbit_aut_iff G γ ξ.first hab).mpr ξ.first_mem - last := a ∘ ξ.last - last_mem := (segmentOrbit_aut_iff G γ ξ.last hab).mpr ξ.last_mem - middle := ξ.middle.map (autSimpleGraph G hab).toHom - leftTail := ⟨a ξ.leftTail.1,ξ.leftTail.2.map (autSimpleGraph G hab).toHom⟩ - rightTail := ⟨a ξ.rightTail.1,ξ.rightTail.2.map (autSimpleGraph G hab).toHom⟩ - -theorem autMap_trans {a c : V ≃ V} {b d : E ≃ E} (hab : IsAut G a b) (hcd : IsAut G c d) - (ξ : EscapeLabel G γ ep neg L m) : - autMap hcd (autMap hab ξ) = autMap (isAut_trans G hab hcd) ξ := by - cases ξ - dsimp only [autMap,autSimpleGraph] - simp only [HoldingWalk.map_map] - rfl - -theorem autMap_refl (ξ : EscapeLabel G γ ep neg L m) : - autMap (isAut_refl G) ξ = ξ := by - cases ξ with - | mk f hf l hl mid α β => - change EscapeLabel.mk f hf l hl (mid.map SimpleGraph.Hom.id) - ⟨α.1,α.2.map SimpleGraph.Hom.id⟩ ⟨β.1,β.2.map SimpleGraph.Hom.id⟩ = _ - simp only [HoldingWalk.map_id] - -theorem autMap_symm {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (ξ : EscapeLabel G γ ep neg L m) : - autMap (isAut_symm G hab) (autMap hab ξ) = ξ := by - rw [autMap_trans] - have ha : a.trans a.symm = Equiv.refl V := by ext x; exact a.symm_apply_apply x - have hb : b.trans b.symm = Equiv.refl E := by ext x; exact b.symm_apply_apply x - generalize hp : isAut_trans G hab (isAut_symm G hab) = h - clear hp - revert h - rw [ha,hb] - intro h - exact autMap_refl ξ - -def autEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : - EscapeLabel G γ ep neg L m ≃ EscapeLabel G γ ep neg L m where - toFun := autMap hab - invFun := autMap (isAut_symm G hab) - left_inv := autMap_symm hab - right_inv := autMap_symm (isAut_symm G hab) - -def autRootedEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (center : I) (x : V) : - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} ≃ - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = a x} where - toFun ξ := ⟨autMap hab ξ.1,congrArg a ξ.2⟩ - invFun ξ := ⟨autMap (isAut_symm G hab) ξ.1,by - change a.symm (ξ.1.first center) = x - rw [ξ.2,a.symm_apply_apply]⟩ - left_inv ξ := Subtype.ext (autMap_symm hab ξ.1) - right_inv ξ := Subtype.ext (autMap_symm (isAut_symm G hab) ξ.1) - -theorem mass_autMap (hloc : LocallyFinite G) (a₀ : ℝ) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (ξ : EscapeLabel G γ ep neg L m) : - (autMap hab ξ).mass (walkKernel G hloc a₀) = ξ.mass (walkKernel G hloc a₀) := by - change (ξ.middle.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) * - (ξ.leftTail.2.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) * - (ξ.rightTail.2.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) = _ - simp only [HoldingWalk.mass_map (autSimpleGraph G hab).toHom _ _ (walkKernel_covariant G hloc a₀ hab)] - rfl - -end EscapeLabel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LazyOrbitReturn -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem walkKernel_lazy (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1/2) - (x : V) : 1/2 ≤ walkKernel G hloc a x x := by - have hn : ((neighbors G hloc x).card : ℝ) ≤ D := by - exact_mod_cast (neighbors_card_le_degree G hloc x).trans (hD x) - have hh := mul_le_mul_of_nonneg_left hn ha - simp only [walkKernel,ite_true] - split_ifs <;> linarith - -theorem positive_lazy_power_step (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (k : ℕ) (x y : V) : - (1/2) * (matrixCoeff (P^k) x y).re ≤ (matrixCoeff (P^(k+1)) x y).re := by - have hs := hpos.mul_hasSum (P^k) x y - have hh := hs.summable.sum_le_tsum ({x} : Finset V) - (fun z _ => mul_nonneg (hpos x z).2 ((hpos.pow k) z y).2) - simp only [Finset.sum_singleton,hs.tsum_eq,←pow_succ'] at hh - exact (mul_le_mul_of_nonneg_right (hdiag x) ((hpos.pow k) x y).2).trans hh - - - -theorem walkPower_orbit_return_lower (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (L : ℕ) : - (1/2) * (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ - ∑' y, if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^L) (root i₀) y).re else 0 := by - have hsum (k : ℕ) : Summable (fun y => - if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^k) (root i₀) y).re else 0) := by - simpa only [mul_ite,mul_one,mul_zero] using finiteKernel_summable_mul - (fun x y => (matrixCoeff (P^k) x y).re) (walkPower_finite_support G hloc a P hpos hP k) - (root i₀) (fun y => if y ∈ vertexOrbit G (root i₀) then 1 else 0) - obtain ⟨k,hk | hk⟩ := Nat.even_or_odd' L - · rw [hk] - have hh := walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k - have hn : 0 ≤ ∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0 := - Finset.sum_nonneg (fun i _ => by split_ifs <;> first | exact hw i | rfl) - linarith - · rw [hk] - have hh := mul_le_mul_of_nonneg_left - (walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k) - (show (0:ℝ) ≤ 1/2 by norm_num) - apply hh.trans - rw [←tsum_mul_left] - apply ((hsum (2*k)).mul_left (1/2)).tsum_le_tsum _ (hsum (2*k+1)) - intro y - split_ifs - · exact positive_lazy_power_step P hpos hdiag (2*k) (root i₀) y - · simp only [mul_zero,le_refl] - -end LazyOrbitReturn -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section UniformLabeledLaw -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -omit [Fintype I] in - - -theorem segmentReturnMass_uniform_lower (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (γ : I → V) (ep : I) (L : ℕ) : - 1/(2*c) ≤ segmentReturnMass G hloc a γ ep L (γ ep) := by - obtain ⟨i,g,hg,hx⟩ := hcov (γ ep) - obtain ⟨b,hb⟩ := hΓ hg - have hO := vertexOrbit_eq_of_mem G (root i) (γ ep) ⟨g,b,hb,hx⟩ - rw [←hx,segmentReturnMass_aut G hloc a γ ep L (root i) P hpos hP hb] - rw [segmentReturnMass_operator G hloc a γ ep L (root i) P hpos hP] - rw [hO] - have hh := walkPower_orbit_return_lower G hloc a root weight Γ hΓ htr - (fun i => (hw i).le) hw1 i (hw i) P hpos hsym hP hdiag L - have hi : weight i ≤ ∑ r, if root r ∈ vertexOrbit G (root i) then weight r else 0 := by - have hx' : root i ∈ vertexOrbit G (root i) := ⟨Equiv.refl _,Equiv.refl _,isAut_refl G,rfl⟩ - simpa only [ite_eq_left hx'] using Finset.single_le_sum - (f := fun r => if root r ∈ vertexOrbit G (root i) then weight r else 0) - (fun r _ => by split_ifs <;> first | exact (hw r).le | rfl) (Finset.mem_univ i) - apply le_trans _ hh - have hct : 0 < 2*c := mul_pos (by norm_num) hc - apply (div_le_iff₀ hct).mpr - have hh' := mul_le_mul_of_nonneg_left hi hc.le - nlinarith [hmin i] - - - -theorem rooted_label_probability_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) : - HasSum (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) 1 := by - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ ep L - have hp : 0 < segmentReturnMass G hloc a γ ep L (γ ep) := - (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq - have hs : Summable (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) := - summable_of_hasFiniteSupport (Set.toFinite _) - rw [←rooted_label_probability_sum G hloc a γ n hdiam center ep neg L m x hx P hpos hP (ne_of_gt hp)] - exact hs.hasSum - -end UniformLabeledLaw -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section LabeledTransport -attribute [local instance] Classical.propDecidable Classical.decEq -variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} - -def labelEndpointEquiv (center : I) (x : V) : - (Σ y : V, {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}) ≃ - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} where - toFun ξ := ⟨ξ.2.1,ξ.2.2.1⟩ - invFun ξ := ⟨ξ.1.last center,ξ.1,ξ.2,rfl⟩ - left_inv ξ := by rcases ξ with ⟨y,ξ,hx,hy⟩; subst y; rfl - right_inv ξ := rfl - -def labelAutPairEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (center : I) (x y : V) : - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} ≃ - {ξ : EscapeLabel G γ ep neg L m // ξ.first center = a x ∧ ξ.last center = a y} where - toFun ξ := ⟨EscapeLabel.autMap hab ξ.1,congrArg a ξ.2.1,congrArg a ξ.2.2⟩ - invFun ξ := ⟨EscapeLabel.autMap (isAut_symm G hab) ξ.1,by - change a.symm (ξ.1.first center) = x ∧ a.symm (ξ.1.last center) = y - rw [ξ.2.1,ξ.2.2,a.symm_apply_apply,a.symm_apply_apply] - exact ⟨rfl,rfl⟩⟩ - left_inv ξ := Subtype.ext (EscapeLabel.autMap_symm hab ξ.1) - right_inv ξ := Subtype.ext (EscapeLabel.autMap_symm (isAut_symm G hab) ξ.1) - -noncomputable def escapeLabelTransport (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) (x y : V) : ℝ := - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}, B ξ.1 - -theorem escapeLabelTransport_reverse (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) (x y : V) : - escapeLabelTransport center B x y = - escapeLabelTransport center (fun ξ => B ξ.reverse) y x := by - unfold escapeLabelTransport - exact (EscapeLabel.reverseRootedEquiv center y x).tsum_eq _ |>.symm - -theorem escapeLabelTransport_aut (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (hB : ∀ ξ, B (EscapeLabel.autMap hab ξ) = B ξ) (x y : V) : - escapeLabelTransport center B (a x) (a y) = escapeLabelTransport center B x y := by - unfold escapeLabelTransport - rw [←(labelAutPairEquiv hab center x y).tsum_eq] - exact tsum_congr (fun ξ => hB ξ.1) - -variable [Fintype I] - -theorem finite_pair_label_sigma (hloc : LocallyFinite G) (n : ℕ) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) (x : V) : - Finite (Σ y : V, {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}) := by - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - exact Finite.of_equiv _ (labelEndpointEquiv center x).symm - -theorem escapeLabelTransport_row_sum (hloc : LocallyFinite G) (n : ℕ) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) - (B : EscapeLabel G γ ep neg L m → ℝ) (x : V) : - (∑' y, escapeLabelTransport center B x y) = - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1 := by - let := finite_pair_label_sigma hloc n hdiam center (ep := ep) (neg := neg) (L := L) (m := m) x - have hs : Summable (fun ξ : Σ y : V, {ξ : EscapeLabel G γ ep neg L m // - ξ.first center = x ∧ ξ.last center = y} => B ξ.2.1) := - summable_of_hasFiniteSupport (Set.toFinite _) - unfold escapeLabelTransport - rw [←hs.tsum_sigma] - exact (labelEndpointEquiv (G := G) (γ := γ) (ep := ep) (neg := neg) (L := L) (m := m) center x).tsum_eq (fun ξ => B ξ.1) - -theorem escapeLabelTransport_rowSummable (hloc : LocallyFinite G) (n : ℕ) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) - (B : EscapeLabel G γ ep neg L m → ℝ) (x : V) : - Summable (escapeLabelTransport center B x) := by - let := finite_pair_label_sigma hloc n hdiam center (ep := ep) (neg := neg) (L := L) (m := m) x - have hs : Summable (fun ξ : Σ y : V, {ξ : EscapeLabel G γ ep neg L m // - ξ.first center = x ∧ ξ.last center = y} => B ξ.2.1) := - summable_of_hasFiniteSupport (Set.toFinite _) - exact hs.sigma - -theorem escapeLabelTransport_columnSummable (hloc : LocallyFinite G) (n : ℕ) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) - (B : EscapeLabel G γ ep neg L m → ℝ) (y : V) : - Summable (fun x => escapeLabelTransport center B x y) := by - simp only [escapeLabelTransport_reverse center B] - exact escapeLabelTransport_rowSummable hloc n hdiam center (fun ξ => B ξ.reverse) y - -end LabeledTransport -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section LabeledReRooting -attribute [local instance] Classical.propDecidable Classical.decEq -variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} - -theorem EscapeLabel.first_orbit (ξ : EscapeLabel G γ ep neg L m) (i : I) : - ξ.first i ∈ vertexOrbit G (γ i) := by - obtain ⟨a,b,h,he⟩ := ξ.first_mem - exact ⟨a,b,h,(congrFun he i).symm⟩ - -theorem EscapeLabel.last_orbit (ξ : EscapeLabel G γ ep neg L m) (i : I) : - ξ.last i ∈ vertexOrbit G (γ i) := by - obtain ⟨a,b,h,he⟩ := ξ.last_mem - exact ⟨a,b,h,(congrFun he i).symm⟩ - -theorem escapeLabelTransport_zero (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) - (x y : V) (hxy : x ∉ vertexOrbit G (γ center) ∨ y ∉ vertexOrbit G (γ center)) : - escapeLabelTransport center B x y = 0 := by - let : IsEmpty {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} := - ⟨fun ξ => by - rcases hxy with hx | hy - · exact hx (ξ.2.1 ▸ ξ.1.first_orbit center) - · exact hy (ξ.2.2 ▸ ξ.1.last_orbit center)⟩ - exact tsum_empty - -variable [Fintype I] - - - -theorem rooted_label_weight_reversal (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) - (hθ : 0 < ∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0) - (B : EscapeLabel G γ ep neg L m → ℝ) - (hB : ∀ (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) ξ, B (EscapeLabel.autMap hab ξ) = B ξ) - (x : V) (hx : x ∈ vertexOrbit G (γ center)) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1) = - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1.reverse := by - let M := escapeLabelTransport center B - have hM (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (u v : V) : M (a u) (a v) = M u v := - escapeLabelTransport_aut center B hab (hB a b hab) u v - have hr (u : V) : (∑' v, M u v) = if u ∈ vertexOrbit G (γ center) then ∑' v, M (γ center) v else 0 := by - split_ifs with hu - · obtain ⟨a,b,hab,rfl⟩ := hu - rw [←a.tsum_eq] - exact tsum_congr (fun v => hM a b hab (γ center) v) - · calc - _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun v => escapeLabelTransport_zero center B u v (Or.inl hu)) - _ = 0 := tsum_zero - have hc (v : V) : (∑' u, M u v) = if v ∈ vertexOrbit G (γ center) then ∑' u, M u (γ center) else 0 := by - split_ifs with hv - · obtain ⟨a,b,hab,rfl⟩ := hv - rw [←a.tsum_eq] - exact tsum_congr (fun u => hM a b hab u (γ center)) - · calc - _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun u => escapeLabelTransport_zero center B u v (Or.inr hv)) - _ = 0 := tsum_zero - have ht := htr.real root weight Γ M - (fun a ha u v => by obtain ⟨b,hb⟩ := hΓ ha; exact hM a b hb u v) - (escapeLabelTransport_rowSummable hloc n hdiam center B) - (escapeLabelTransport_columnSummable hloc n hdiam center B) - have hfactor (f : V → ℝ) (q : ℝ) (he : ∀ u, f u = if u ∈ vertexOrbit G (γ center) then q else 0) : - (∑ i, weight i*f (root i)) = (∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0)*q := by - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro i _ - rw [he] - split_ifs <;> simp only [mul_zero,zero_mul] - rw [hfactor _ _ hr,hfactor _ _ hc] at ht - have hrc := (mul_left_cancel₀ (ne_of_gt hθ)) ht - have hxe : (∑' v, M x v) = ∑' u, M u x := by - rw [hr x,hc x,ite_eq_left hx,ite_eq_left hx] - exact hrc - calc - _ = ∑' v, M x v := (escapeLabelTransport_row_sum hloc n hdiam center B x).symm - _ = ∑' u, M u x := hxe - _ = ∑' u, escapeLabelTransport center (fun ξ => B ξ.reverse) x u := - tsum_congr (fun u => escapeLabelTransport_reverse center B u x) - _ = _ := escapeLabelTransport_row_sum hloc n hdiam center (fun ξ => B ξ.reverse) x - -end LabeledReRooting -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section ExactLabeledReversal -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -theorem escapeLabelProbability_aut (G : BondGraph V E) (hloc : LocallyFinite G) - (a₀ : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (ξ : EscapeLabel G γ ep neg L m) : - escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m (EscapeLabel.autMap hab ξ) = - escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ := by - simp only [escapeLabelProbability,EscapeLabel.mass_autMap] - - - -theorem rooted_escape_label_reversal (G : BondGraph V E) (hloc : LocallyFinite G) (a₀ : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) (L m : ℕ) - (hθ : 0 < ∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0) - (F : EscapeLabel G γ ep neg L m → ℝ) - (hF : ∀ (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) ξ, F (EscapeLabel.autMap hab ξ) = F ξ) - (x : V) (hx : x ∈ vertexOrbit G (γ center)) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ.1 * F ξ.1) = - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ.1 * F ξ.1.reverse := by - have hh := rooted_label_weight_reversal hloc root weight Γ hΓ htr n hdiam center hθ - (fun ξ => escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ * F ξ) - (fun a b hab ξ => by rw [escapeLabelProbability_aut G hloc a₀ γ n hdiam center ep neg L m hab,hF a b hab]) x hx - simpa only [escapeLabelProbability_reverse] using hh - -theorem escapeLabelProbability_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : - 0 ≤ escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by - have hq : 0 ≤ segmentReturnMass G hloc a γ ep L (γ ep) := by - apply tsum_nonneg - intro mid - split_ifs - · exact mid.2.mass_nonneg _ hP - · rfl - exact div_nonneg (ξ.mass_nonneg _ hP) (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) hq) - -end ExactLabeledReversal -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LongGeodesics -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_geodesic_length (G : BondGraph V E) [Infinite V] - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) (N : ℕ) : - ∃ y : V, ∃ q : (openSimpleGraph G Set.univ).Walk x y, - q.length = N ∧ q.length = (openSimpleGraph G Set.univ).dist x y := by - obtain ⟨z,hz⟩ := (finite_reachBall hloc x N).exists_notMem - have hc := (conn_iff_reachable G Set.univ x z).mp (conn_univ_of_connected G hconn x z) - obtain ⟨q,hq⟩ := hc.exists_walk_length_eq_dist - have hN : N < q.length := by - by_contra hh - have hm := walk_mem_reachBall G Set.univ q 0 (show x ∈ reachBall G x 0 from rfl) - have hm' : z ∈ reachBall G x q.length := by simpa only [Nat.zero_add] using hm - exact hz (reachBall_mono_local G x (Nat.le_of_not_gt hh) hm') - refine ⟨q.getVert N,q.take N,?_,?_⟩ - · simp only [SimpleGraph.Walk.take_length,inf_eq_left.mpr hN.le] - · exact SimpleGraph.length_eq_dist_of_subwalk hq (q.isSubwalk_take N) - - - -theorem geodesic_getVert_dist (H : SimpleGraph V) {x y : V} (q : H.Walk x y) - (hq : q.length = H.dist x y) (i j : ℕ) (hij : i ≤ j) (hj : j ≤ q.length) : - H.dist (q.getVert i) (q.getVert j) = j-i := by - have hs := SimpleGraph.length_eq_dist_of_subwalk hq - (((q.drop i).isSubwalk_take (j-i)).trans (q.isSubwalk_drop i)) - have he : (q.drop i).getVert (j-i) = q.getVert j := by - rw [SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hij] - rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length,he, - min_eq_left (Nat.sub_le_sub_right hj i)] at hs - exact hs.symm - -end LongGeodesics -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -namespace HoldingWalk -variable {H : SimpleGraph V} - - - -def append : {k l : ℕ} → {x y z : V} → HoldingWalk H k x y → HoldingWalk H l y z → HoldingWalk H (l+k) x z - | _,_,_,_,_,.nil _,v => v - | _,_,_,_,_,.hold w,v => .hold (w.append v) - | _,_,_,_,_,.step h w,v => .step h (w.append v) - -def ofWalk : {x y : V} → (w : H.Walk x y) → HoldingWalk H w.length x y - | _,_,.nil => .nil _ - | _,_,.cons h w => .step h (ofWalk w) - -theorem mass_append (P : V → V → ℝ) {k l : ℕ} {x y z : V} - (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : - (w.append v).mass P = w.mass P*v.mass P := by - induction w with - | nil => simp only [append,mass,one_mul] - | hold w ih => simp only [append,mass,ih,mul_assoc] - | step h w ih => simp only [append,mass,ih,mul_assoc] - -theorem mass_ofWalk (P : V → V → ℝ) (a : ℝ) (hP : ∀ x y, H.Adj x y → P x y = a) - {x y : V} (w : H.Walk x y) : (ofWalk w).mass P = a^w.length := by - induction w with - | nil => rfl - | @cons x z y h w ih => simp only [ofWalk,mass,hP x z h,ih,SimpleGraph.Walk.length_cons,pow_succ']; - -theorem ofWalk_vertices {x y : V} (w : H.Walk x y) : (ofWalk w).vertices = w.support := by - induction w with - | nil => rfl - | cons h w ih => simp only [ofWalk,vertices,SimpleGraph.Walk.support_cons,ih] - -theorem append_vertices {k l : ℕ} {x y z : V} - (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : - (w.append v).vertices = w.vertices.dropLast ++ v.vertices := by - induction w with - | nil => rfl - | hold w ih => - have hn : w.vertices ≠ [] := by cases w <;> simp [vertices] - simp only [append,vertices,ih,List.dropLast_cons_of_ne_nil hn,List.cons_append] - | step h w ih => - have hn : w.vertices ≠ [] := by cases w <;> simp [vertices] - simp only [append,vertices,ih,List.dropLast_cons_of_ne_nil hn,List.cons_append] - -end HoldingWalk -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section GeodesicSegments -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def geodesicSegment (G : BondGraph V E) {x y : V} - (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) : Fin (N+1) → V := - fun i => q.getVert i - -theorem geodesicSegment_adj (G : BondGraph V E) {x y : V} - (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) - (i : ℕ) (hi : i < N) : - (openSimpleGraph G Set.univ).Adj - (geodesicSegment G q N ⟨i,by omega⟩) (geodesicSegment G q N ⟨i+1,by omega⟩) := by - change (openSimpleGraph G Set.univ).Adj (q.getVert i) (q.getVert (i+1)) - exact q.adj_getVert_succ (by omega) - -theorem geodesicSegment_injective (G : BondGraph V E) {x y : V} - (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) - (hq : q.length = (openSimpleGraph G Set.univ).dist x y) : - Function.Injective (geodesicSegment G q N) := by - intro i j hh - apply Fin.ext - exact (q.isPath_of_length_eq_dist hq).getVert_injOn - (by change i.val ≤ q.length; omega) (by change j.val ≤ q.length; omega) hh - -theorem geodesicSegment_diameter (G : BondGraph V E) {x y : V} - (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) : - ∀ i j, geodesicSegment G q N j ∈ reachBall G (geodesicSegment G q N i) N := by - intro i j - have hc : (openSimpleGraph G Set.univ).Reachable (q.getVert i) (q.getVert j) := - (q.take i).reachable.symm.trans (q.take j).reachable - obtain ⟨r,hr⟩ := hc.exists_walk_length_eq_dist - have hd : (openSimpleGraph G Set.univ).dist (q.getVert i) (q.getVert j) ≤ N := by - rcases le_total i.val j.val with hij | hji - · have hle := SimpleGraph.dist_le ((q.drop i).take (j-i)) - rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length, - SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hij] at hle - exact hle.trans (by omega) - · have hle := SimpleGraph.dist_le ((q.drop j).take (i-j)) - rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length, - SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hji] at hle - rw [SimpleGraph.dist_comm] at hle - exact hle.trans (by omega) - have hm := walk_mem_reachBall G Set.univ r 0 (show q.getVert i ∈ reachBall G (q.getVert i) 0 from rfl) - apply reachBall_mono_local G (q.getVert i) (a := r.length) (by omega) - simpa only [Nat.zero_add, geodesicSegment] using hm - -theorem segmentOrbit_adj (G : BondGraph V E) {I : Type*} (γ s : I → V) - (hs : s ∈ segmentOrbit G γ) (i j : I) (hij : (openSimpleGraph G Set.univ).Adj (γ i) (γ j)) : - (openSimpleGraph G Set.univ).Adj (s i) (s j) := by - obtain ⟨a,b,hab,rfl⟩ := hs - exact (autSimpleGraph G hab).map_rel_iff.mpr hij - -theorem walkKernel_step (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {x y : V} (h : (openSimpleGraph G Set.univ).Adj x y) : walkKernel G hloc a x y = a := by - have hh := (openSimpleGraph_univ_adj G x y).mp h - simp only [walkKernel,ite_eq_right hh.1,ite_eq_left hh.2,zero_add] - -theorem walkKernel_ofWalk_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {x y : V} (q : (openSimpleGraph G Set.univ).Walk x y) : - (HoldingWalk.ofWalk q).mass (walkKernel G hloc a) = a^q.length := - HoldingWalk.mass_ofWalk _ a (fun _ _ h => walkKernel_step G hloc a h) q - -end GeodesicSegments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualTailPotentials -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_tail_twoPoint_expectation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x b : V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - w.2.mass (walkKernel G hloc a) * twoPoint G p w.1 b) = - (matrixCoeff (P^m*A) x b).re := by - have he : (fun y => twoPoint G p y b) = (fun y => (matrixCoeff A y b).re) := by - funext y - rw [matrixCoeff,hA y b,Complex.ofReal_re] - change RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) m x (twoPoint G p · b) = _ - rw [he,raw_integral_operator G hloc a P hpos hP] - exact ((hpos.pow m).mul_hasSum A x b).tsum_eq - - - -theorem raw_tail_potential_bound [Countable V] [Countable E] [Nonempty V] - {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x : V) (S : Finset V) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - w.2.mass (walkKernel G hloc a) * ∑ b ∈ S, twoPoint G p w.1 b) ≤ - (S.card:ℝ) * Real.sqrt c * ‖P‖^m := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) - have hPinv : KernelInvariant (vertexAut G) P := by - intro e he x y - obtain ⟨f,hf⟩ := he - rw [hP,hP,walkKernel_covariant G hloc a hf] - calc - _ = ∑ b ∈ S, (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - w.2.mass (walkKernel G hloc a) * twoPoint G p w.1 b) := by - simp only [tsum_fintype,Finset.mul_sum] - exact Finset.sum_comm - _ = ∑ b ∈ S, (matrixCoeff (P^m*A) x b).re := by - apply Finset.sum_congr rfl - intro b _ - exact raw_tail_twoPoint_expectation G hloc a P A hpos hP p hA m x b - _ ≤ ∑ _b ∈ S, Real.sqrt c * ‖P‖^m := by - apply Finset.sum_le_sum - intro b _ - exact (Complex.re_le_norm _).trans (twoPoint_operator_smoothing G p root weight htr hcov hw hsum c hc hmin A P hA hPinv m x b) - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,mul_assoc] - -end ActualTailPotentials -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AuxiliaryTailMarkov -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finite_weighted_markov {α : Type*} [Fintype α] (μ F : α → ℝ) - (hμ : ∀ x, 0 ≤ μ x) (hF : ∀ x, 0 ≤ F x) (t : ℝ) (ht : 0 < t) : - (∑ x, if t < F x then μ x else 0) ≤ (∑ x, μ x*F x)/t := by - apply (le_div_iff₀ ht).mpr - rw [Finset.sum_mul] - apply Finset.sum_le_sum - intro x _ - split_ifs with hx - · exact mul_le_mul_of_nonneg_left hx.le (hμ x) - · exact (by simpa only [zero_mul] using mul_nonneg (hμ x) (hF x)) - -theorem raw_tail_potential_failure [Countable V] [Countable E] [Nonempty V] - {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x : V) (S : Finset V) - (t : ℝ) (ht : 0 < t) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - if t < ∑ b ∈ S, twoPoint G p w.1 b then w.2.mass (walkKernel G hloc a) else 0) ≤ - ((S.card:ℝ) * Real.sqrt c * ‖P‖^m)/t := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hM := finite_weighted_markov - (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) - (fun w => ∑ b ∈ S, twoPoint G p w.1 b) - (fun w => w.2.mass_nonneg _ hK) - (fun w => Finset.sum_nonneg (fun b _ => twoPoint_nonneg G p w.1 b)) t ht - have hB := raw_tail_potential_bound G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m x S - simp only [tsum_fintype] at hB ⊢ - exact hM.trans (div_le_div_of_nonneg_right hB ht.le) - - - -theorem finite_product_failure_union {α β : Type*} [Fintype α] [Fintype β] - (μ : α → ℝ) (ν : β → ℝ) (hμ : ∀ x, 0 ≤ μ x) (hν : ∀ y, 0 ≤ ν y) - (hμ1 : ∑ x, μ x = 1) (hν1 : ∑ y, ν y = 1) (B : α → Prop) (C : β → Prop) : - (∑ z : α × β, if B z.1 ∨ C z.2 then μ z.1*ν z.2 else 0) ≤ - (∑ x, if B x then μ x else 0) + ∑ y, if C y then ν y else 0 := by - calc - _ ≤ ∑ z : α × β, ((if B z.1 then μ z.1 else 0)*ν z.2 + μ z.1*(if C z.2 then ν z.2 else 0)) := by - apply Finset.sum_le_sum - intro z _ - by_cases hB : B z.1 <;> by_cases hC : C z.2 <;> - simp [hB,hC] - exact mul_nonneg (hμ _) (hν _) - _ = _ := by - rw [Fintype.sum_prod_type] - simp only [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.sum_mul,hμ1,hν1,mul_one,one_mul] - -end AuxiliaryTailMarkov -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IndependentTailPotentialTests -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem two_raw_tail_potential_failure [Countable V] [Countable E] [Nonempty V] - {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x y : V) (S : Finset V) - (t : ℝ) (ht : 0 < t) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) m y, - if (t < ∑ b ∈ S, twoPoint G p w.1.1 b) ∨ (t < ∑ b ∈ S, twoPoint G p w.2.1 b) - then w.1.2.mass (walkKernel G hloc a) * w.2.2.mass (walkKernel G hloc a) else 0) ≤ - 2*((S.card:ℝ) * Real.sqrt c * ‖P‖^m)/t := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) - let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m y) - have hK (u v : V) : 0 ≤ walkKernel G hloc a u v := by - simpa only [hP,Complex.ofReal_re] using (hpos u v).2 - have hμ := rawFrom_probability_sum G hloc a m x - have hν := rawFrom_probability_sum G hloc a m y - simp only [tsum_fintype] at hμ hν - have hU := finite_product_failure_union - (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) - (fun w : RawFrom (openSimpleGraph G Set.univ) m y => w.2.mass (walkKernel G hloc a)) - (fun w => w.2.mass_nonneg _ hK) (fun w => w.2.mass_nonneg _ hK) hμ hν - (fun w => t < ∑ b ∈ S, twoPoint G p w.1 b) - (fun w => t < ∑ b ∈ S, twoPoint G p w.1 b) - have hx := raw_tail_potential_failure G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m x S t ht - have hy := raw_tail_potential_failure G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m y S t ht - simp only [tsum_fintype] at hx hy ⊢ - exact hU.trans ((add_le_add hx hy).trans_eq (by ring)) - -end IndependentTailPotentialTests -end Percolation - - -namespace Percolation -section LogarithmicTailLength - - - -theorem logarithmic_tail_power (ρ X : ℝ) (hρ : 0 < ρ) (hρ1 : ρ < 1) (hX : 0 < X) : - ρ ^ ⌈(2/(-Real.log ρ))*Real.log X⌉₊ ≤ X^(-2:ℝ) := by - have hl : Real.log ρ ≠ 0 := ne_of_lt (Real.log_neg hρ hρ1) - calc - _ = ρ ^ (⌈(2/(-Real.log ρ))*Real.log X⌉₊ : ℝ) := (Real.rpow_natCast _ _).symm - _ ≤ ρ ^ ((2/(-Real.log ρ))*Real.log X) := - Real.rpow_le_rpow_of_exponent_ge hρ hρ1.le (Nat.le_ceil _) - _ = X^(-2:ℝ) := by - rw [Real.rpow_def_of_pos hρ,Real.rpow_def_of_pos hX] - congr 1 - field_simp [hl] - - - -theorem exists_uniform_logarithmic_tail_cutoff (ρ A : ℝ) - (hρ : 0 < ρ) (hρ1 : ρ < 1) (hA : 0 ≤ A) (kmin : ℕ) : - ∃ C₁ : ℝ, 0 < C₁ ∧ 1 < (-Real.log ρ)*C₁ ∧ - ∃ k₀ : ℕ, kmin ≤ k₀ ∧ ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → - A*((k:ℝ)+1)*R*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ ≤ 1/4 := by - have hlambda : 0 < -Real.log ρ := neg_pos.mpr (Real.log_neg hρ hρ1) - refine ⟨2/(-Real.log ρ),div_pos (by norm_num) hlambda,?_,max kmin ⌈4*A⌉₊,le_max_left _ _,?_⟩ - · rw [mul_div_cancel₀ _ (ne_of_gt hlambda)] - norm_num - · intro k hk R hR - have hk' : ⌈4*A⌉₊ ≤ k := (le_max_right _ _).trans hk - have hAk : 4*A ≤ (k:ℝ) := (Nat.le_ceil (4*A)).trans (by exact_mod_cast hk') - have hkpos : 0 < (k:ℝ)+1 := by positivity - have hRp : 0 < R := lt_of_lt_of_le (by norm_num) hR - let X : ℝ := ((k:ℝ)+1)*R - have hX : 0 < X := mul_pos hkpos hRp - have hXk : (k:ℝ)+1 ≤ X := by dsimp [X]; exact le_mul_of_one_le_right hkpos.le hR - have hp := logarithmic_tail_power ρ X hρ hρ1 hX - have hneg : X^(-2:ℝ) = (X^2)⁻¹ := by rw [Real.rpow_neg,show (2:ℝ) = (2:ℕ) by norm_num,Real.rpow_natCast]; exact hX.le - calc - _ = A*X*ρ^⌈(2/(-Real.log ρ))*Real.log X⌉₊ := by dsimp [X]; ring - _ ≤ A*X*X^(-2:ℝ) := mul_le_mul_of_nonneg_left hp (mul_nonneg hA hX.le) - _ = A/X := by rw [hneg]; field_simp [ne_of_gt hX] - _ ≤ 1/4 := (div_le_iff₀ hX).mpr (by linarith) - -end LogarithmicTailLength -end Percolation - - -namespace Percolation -universe u -variable {V : Type u} -namespace HoldingWalk -variable {H : SimpleGraph V} - - - -def position : {k : ℕ} → {x y : V} → HoldingWalk H k x y → ℕ → V - | _,x,_,.nil _,_ => x - | _,x,_,.hold _,0 => x - | _,_,_,.hold w,n+1 => w.position n - | _,x,_,.step _ _,0 => x - | _,_,_,.step _ w,n+1 => w.position n - -@[simp] theorem position_zero {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.position 0 = x := by - cases w <;> rfl - -@[simp] theorem position_length {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.position k = y := by - induction w with - | nil => rfl - | hold w ih => exact ih - | step h w ih => exact ih - -theorem position_mem_vertices {k : ℕ} {x y : V} (w : HoldingWalk H k x y) (i : ℕ) : - w.position i ∈ w.vertices := by - induction w generalizing i with - | nil => simp only [position,vertices,List.mem_singleton] - | hold w ih => cases i <;> simp only [position,vertices,List.mem_cons,true_or,ih,or_true] - | step h w ih => cases i <;> simp only [position,vertices,List.mem_cons,true_or,ih,or_true] - -theorem mem_vertices_iff_position {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) : - z ∈ w.vertices ↔ ∃ i : ℕ, i ≤ k ∧ w.position i = z := by - induction w with - | nil => simp only [vertices,List.mem_singleton,Nat.le_zero,exists_eq_left,position,eq_comm] - | @hold k x y w ih => - constructor - · intro hz - rcases List.mem_cons.mp hz with rfl | hz - · exact ⟨0,Nat.zero_le _,rfl⟩ - · obtain ⟨i,hi,he⟩ := ih.mp hz - exact ⟨i+1,Nat.succ_le_succ hi,he⟩ - · rintro ⟨i,hi,he⟩ - cases i with - | zero => exact List.mem_cons.mpr (Or.inl he.symm) - | succ i => exact List.mem_cons.mpr (Or.inr (ih.mpr ⟨i,Nat.le_of_succ_le_succ hi,he⟩)) - | @step k x u y h w ih => - constructor - · intro hz - rcases List.mem_cons.mp hz with rfl | hz - · exact ⟨0,Nat.zero_le _,rfl⟩ - · obtain ⟨i,hi,he⟩ := ih.mp hz - exact ⟨i+1,Nat.succ_le_succ hi,he⟩ - · rintro ⟨i,hi,he⟩ - cases i with - | zero => exact List.mem_cons.mpr (Or.inl he.symm) - | succ i => exact List.mem_cons.mpr (Or.inr (ih.mpr ⟨i,Nat.le_of_succ_le_succ hi,he⟩)) - -end HoldingWalk -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Deformation.AveragedDecrease + +namespace OAI + +/-! Labels for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section LabeledEscapeExperiment + + + +structure EscapeLabel (G : BondGraph V E) (γ : I → V) (endpoint negative : I) (L m : ℕ) where + first : I → V + first_mem : first ∈ segmentOrbit G γ + last : I → V + last_mem : last ∈ segmentOrbit G γ + middle : HoldingWalk (openSimpleGraph G Set.univ) L (first endpoint) (last endpoint) + leftTail : RawFrom (openSimpleGraph G Set.univ) m (first negative) + rightTail : RawFrom (openSimpleGraph G Set.univ) m (last negative) + +namespace EscapeLabel +variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} + +def reverse (ξ : EscapeLabel G γ ep neg L m) : EscapeLabel G γ ep neg L m where + first := ξ.last + first_mem := ξ.last_mem + last := ξ.first + last_mem := ξ.first_mem + middle := ξ.middle.reverse + leftTail := ξ.rightTail + rightTail := ξ.leftTail + +theorem reverse_reverse (ξ : EscapeLabel G γ ep neg L m) : ξ.reverse.reverse = ξ := by + cases ξ + simp only [reverse,HoldingWalk.reverse_reverse] + +def reverseEquiv : EscapeLabel G γ ep neg L m ≃ EscapeLabel G γ ep neg L m where + toFun := reverse + invFun := reverse + left_inv := reverse_reverse + right_inv := reverse_reverse + +noncomputable def mass (P : V → V → ℝ) (ξ : EscapeLabel G γ ep neg L m) : ℝ := + ξ.middle.mass P * ξ.leftTail.2.mass P * ξ.rightTail.2.mass P + +theorem mass_nonneg (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (ξ : EscapeLabel G γ ep neg L m) : 0 ≤ ξ.mass P := + mul_nonneg (mul_nonneg (ξ.middle.mass_nonneg P hP) (ξ.leftTail.2.mass_nonneg P hP)) + (ξ.rightTail.2.mass_nonneg P hP) + +theorem mass_reverse (P : V → V → ℝ) (hP : ∀ x y, P x y = P y x) + (ξ : EscapeLabel G γ ep neg L m) : ξ.reverse.mass P = ξ.mass P := by + simp only [mass,reverse,HoldingWalk.mass_reverse P hP] + ring + + + +def reverseRootedEquiv (center : I) (x y : V) : + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} ≃ + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = y ∧ ξ.last center = x} where + toFun ξ := ⟨ξ.1.reverse,ξ.2.2,ξ.2.1⟩ + invFun ξ := ⟨ξ.1.reverse,ξ.2.2,ξ.2.1⟩ + left_inv ξ := Subtype.ext (reverse_reverse ξ.1) + right_inv ξ := Subtype.ext (reverse_reverse ξ.1) + +end EscapeLabel +end LabeledEscapeExperiment +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section FiniteRootedLabels +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +noncomputable def RootedLabelCode (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) : Type (max u w) := + Σ s : (segmentAnchors G hloc γ n hdiam center x), + Σ mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + Σ h : (segmentAnchors G hloc γ n hdiam ep mid.1), + RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg) + +instance finite_rootedLabelCode (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) : + Finite (RootedLabelCode G hloc γ n hdiam center ep neg L m x) := by + let (z : V) := finite_openSimpleGraph_neighbors G hloc z + unfold RootedLabelCode + infer_instance + +noncomputable def labelFromCode (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) + (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + have hsm := ((mem_segmentAnchors G hloc γ n hdiam center x s).mp hs).1 + have hsx := ((mem_segmentAnchors G hloc γ n hdiam center x s).mp hs).2 + have hhm := ((mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh).1 + have hhz := ((mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh).2 + subst z + exact ⟨⟨s,hsm,h,hhm,mid,α,β⟩,hsx⟩ + +noncomputable def labelToCode (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) + (ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}) : + RootedLabelCode G hloc γ n hdiam center ep neg L m x := + ⟨⟨ξ.1.first,(mem_segmentAnchors G hloc γ n hdiam center x ξ.1.first).mpr ⟨ξ.1.first_mem,ξ.2⟩⟩, + ⟨ξ.1.last ep,ξ.1.middle⟩, + ⟨ξ.1.last,(mem_segmentAnchors G hloc γ n hdiam ep (ξ.1.last ep) ξ.1.last).mpr ⟨ξ.1.last_mem,rfl⟩⟩, + ξ.1.leftTail,ξ.1.rightTail⟩ + +noncomputable def rootedLabelEquiv (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) : + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} ≃ + RootedLabelCode G hloc γ n hdiam center ep neg L m x where + toFun := labelToCode G hloc γ n hdiam center ep neg L m x + invFun := labelFromCode G hloc γ n hdiam center ep neg L m x + left_inv ξ := by + cases ξ with + | mk ξ hξ => cases ξ; rfl + right_inv c := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + have hh' := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + obtain ⟨hhm,hhz⟩ := hh' + subst z + rfl + +theorem finite_rootedEscapeLabels (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) : + Finite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} := + Finite.of_equiv _ (rootedLabelEquiv G hloc γ n hdiam center ep neg L m x).symm + +end FiniteRootedLabels +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section LabeledMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +theorem segmentAnchors_card_on_orbit (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) + (hx : x ∈ vertexOrbit G (γ i)) : + (segmentAnchors G hloc γ n hdiam i x).card = (segmentAnchors G hloc γ n hdiam i (γ i)).card := by + obtain ⟨a,b,h,rfl⟩ := hx + exact segmentAnchors_card_aut G hloc γ n hdiam i (γ i) h + +theorem segmentAnchors_card_eq_indicator (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (i : I) (x : V) : + ((segmentAnchors G hloc γ n hdiam i x).card : ℝ) = + if x ∈ vertexOrbit G (γ i) then (segmentAnchors G hloc γ n hdiam i (γ i)).card else 0 := by + split_ifs with hx + · exact congrArg Nat.cast (segmentAnchors_card_on_orbit G hloc γ n hdiam i x hx) + · have hh := (segmentAnchors_nonempty_iff G hloc γ n hdiam i x).not.mpr hx + rw [Finset.not_nonempty_iff_eq_empty.mp hh] + rfl + +noncomputable def segmentReturnMass (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) : ℝ := + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L x, + if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0 + +theorem labelFromCode_mass (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (P : V → V → ℝ) + (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : + (labelFromCode G hloc γ n hdiam center ep neg L m x c).1.mass P = + c.2.1.2.mass P * c.2.2.2.1.2.mass P * c.2.2.2.2.2.mass P := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + obtain ⟨hhm,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + + + +theorem rooted_label_mass_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + ξ.1.mass (walkKernel G hloc a)) = + ∑ s ∈ segmentAnchors G hloc γ n hdiam center x, + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * + segmentReturnMass G hloc a γ ep L (s ep) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x + rw [←R.symm.tsum_eq] + simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] + unfold RootedLabelCode at * + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + change (∑' s : (segmentAnchors G hloc γ n hdiam center x), _) = _ + rw [tsum_fintype] + conv_rhs => rw [←Finset.sum_coe_sort] + apply Finset.sum_congr rfl + intro s _ + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + have he (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) : + (∑' h : (segmentAnchors G hloc γ n hdiam ep mid.1), + ∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * + tails.2.2.mass (walkKernel G hloc a)) = + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * + (if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0) := by + have ht (h : (segmentAnchors G hloc γ n hdiam ep mid.1)) : + (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + mid.2.mass (walkKernel G hloc a) * tails.1.2.mass (walkKernel G hloc a) * + tails.2.2.mass (walkKernel G hloc a)) = mid.2.mass (walkKernel G hloc a) := by + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] + simp only [tsum_mul_left,rawFrom_probability_sum G hloc a,mul_one] + simp only [ht,tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] + split_ifs <;> ring + calc + _ = ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * + (if mid.1 ∈ vertexOrbit G (γ ep) then mid.2.mass (walkKernel G hloc a) else 0) := by + apply tsum_congr + intro mid + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + exact he mid + _ = _ := tsum_mul_left + +end LabeledMass +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section LabeledNormalization +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +omit [Fintype I] in +theorem segmentReturnMass_operator (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) : + segmentReturnMass G hloc a γ ep L x = + ∑' y, if y ∈ vertexOrbit G (γ ep) then (matrixCoeff (P^L) x y).re else 0 := by + have hh := raw_integral_operator G hloc a P hpos hP L x + (fun y => if y ∈ vertexOrbit G (γ ep) then 1 else 0) + simpa only [RawFrom.integral,mul_ite,mul_one,mul_zero,segmentReturnMass] using hh + +omit [Fintype I] in +theorem segmentReturnMass_aut (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) : + segmentReturnMass G hloc a γ ep L (g x) = segmentReturnMass G hloc a γ ep L x := by + rw [segmentReturnMass_operator G hloc a γ ep L (g x) P hpos hP, + segmentReturnMass_operator G hloc a γ ep L x P hpos hP,←g.tsum_eq] + apply tsum_congr + intro y + rw [mem_vertexOrbit_aut_iff G (γ ep) hg] + have hh := walkPower_invariant G hloc a P hP L g ⟨b,hg⟩ x y + rw [hh] + +omit [Fintype I] in +theorem segmentReturnMass_on_orbit (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (ep : I) (L : ℕ) (x : V) + (hx : x ∈ vertexOrbit G (γ ep)) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) : + segmentReturnMass G hloc a γ ep L x = segmentReturnMass G hloc a γ ep L (γ ep) := by + obtain ⟨g,b,hg,rfl⟩ := hx + exact segmentReturnMass_aut G hloc a γ ep L (γ ep) P hpos hP hg + + + +noncomputable def escapeLabelProbability (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : ℝ := + ξ.mass (walkKernel G hloc a) / + (((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) * + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * + segmentReturnMass G hloc a γ ep L (γ ep)) + +theorem rooted_label_probability_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hq : segmentReturnMass G hloc a γ ep L (γ ep) ≠ 0) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) = 1 := by + have hN (i : I) : ((segmentAnchors G hloc γ n hdiam i (γ i)).card : ℝ) ≠ 0 := by + apply ne_of_gt + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam i (γ i)).mpr + (by exact ⟨Equiv.refl V,Equiv.refl E,(fun e => by simp),rfl⟩)) + simp only [escapeLabelProbability,tsum_div_const] + rw [rooted_label_mass_sum G hloc a γ n hdiam center ep neg L m x] + have he (s : I → V) (hs : s ∈ segmentAnchors G hloc γ n hdiam center x) : + segmentReturnMass G hloc a γ ep L (s ep) = segmentReturnMass G hloc a γ ep L (γ ep) := by + obtain ⟨⟨g,b,hg,rfl⟩,_⟩ := (mem_segmentAnchors G hloc γ n hdiam center x s).mp hs + exact segmentReturnMass_aut G hloc a γ ep L (γ ep) P hpos hP hg + rw [Finset.sum_congr rfl (fun s hs => congrArg (fun q => _ * q) (he s hs))] + simp only [Finset.sum_const,nsmul_eq_mul] + rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx,←mul_assoc] + exact div_self (mul_ne_zero (mul_ne_zero (hN center) (hN ep)) hq) + +theorem escapeLabelProbability_reverse (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.reverse = + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by + simp only [escapeLabelProbability,EscapeLabel.mass_reverse _ (walkKernel_symmetric G hloc a)] + +end LabeledNormalization +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +theorem isAut_refl (G : BondGraph V E) : IsAut G (Equiv.refl V) (Equiv.refl E) := by + intro e + simp + +namespace EscapeLabel +variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} + +def autMap {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (ξ : EscapeLabel G γ ep neg L m) : EscapeLabel G γ ep neg L m where + first := a ∘ ξ.first + first_mem := (segmentOrbit_aut_iff G γ ξ.first hab).mpr ξ.first_mem + last := a ∘ ξ.last + last_mem := (segmentOrbit_aut_iff G γ ξ.last hab).mpr ξ.last_mem + middle := ξ.middle.map (autSimpleGraph G hab).toHom + leftTail := ⟨a ξ.leftTail.1,ξ.leftTail.2.map (autSimpleGraph G hab).toHom⟩ + rightTail := ⟨a ξ.rightTail.1,ξ.rightTail.2.map (autSimpleGraph G hab).toHom⟩ + +theorem autMap_trans {a c : V ≃ V} {b d : E ≃ E} (hab : IsAut G a b) (hcd : IsAut G c d) + (ξ : EscapeLabel G γ ep neg L m) : + autMap hcd (autMap hab ξ) = autMap (isAut_trans G hab hcd) ξ := by + cases ξ + dsimp only [autMap,autSimpleGraph] + simp only [HoldingWalk.map_map] + rfl + +theorem autMap_refl (ξ : EscapeLabel G γ ep neg L m) : + autMap (isAut_refl G) ξ = ξ := by + cases ξ with + | mk f hf l hl mid α β => + change EscapeLabel.mk f hf l hl (mid.map SimpleGraph.Hom.id) + ⟨α.1,α.2.map SimpleGraph.Hom.id⟩ ⟨β.1,β.2.map SimpleGraph.Hom.id⟩ = _ + simp only [HoldingWalk.map_id] + +theorem autMap_symm {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (ξ : EscapeLabel G γ ep neg L m) : + autMap (isAut_symm G hab) (autMap hab ξ) = ξ := by + rw [autMap_trans] + have ha : a.trans a.symm = Equiv.refl V := by ext x; exact a.symm_apply_apply x + have hb : b.trans b.symm = Equiv.refl E := by ext x; exact b.symm_apply_apply x + generalize hp : isAut_trans G hab (isAut_symm G hab) = h + clear hp + revert h + rw [ha,hb] + intro h + exact autMap_refl ξ + +def autEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) : + EscapeLabel G γ ep neg L m ≃ EscapeLabel G γ ep neg L m where + toFun := autMap hab + invFun := autMap (isAut_symm G hab) + left_inv := autMap_symm hab + right_inv := autMap_symm (isAut_symm G hab) + +def autRootedEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (center : I) (x : V) : + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} ≃ + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = a x} where + toFun ξ := ⟨autMap hab ξ.1,congrArg a ξ.2⟩ + invFun ξ := ⟨autMap (isAut_symm G hab) ξ.1,by + change a.symm (ξ.1.first center) = x + rw [ξ.2,a.symm_apply_apply]⟩ + left_inv ξ := Subtype.ext (autMap_symm hab ξ.1) + right_inv ξ := Subtype.ext (autMap_symm (isAut_symm G hab) ξ.1) + +theorem mass_autMap (hloc : LocallyFinite G) (a₀ : ℝ) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (ξ : EscapeLabel G γ ep neg L m) : + (autMap hab ξ).mass (walkKernel G hloc a₀) = ξ.mass (walkKernel G hloc a₀) := by + change (ξ.middle.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) * + (ξ.leftTail.2.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) * + (ξ.rightTail.2.map (autSimpleGraph G hab).toHom).mass (walkKernel G hloc a₀) = _ + simp only [HoldingWalk.mass_map (autSimpleGraph G hab).toHom _ _ (walkKernel_covariant G hloc a₀ hab)] + rfl + +end EscapeLabel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LazyOrbitReturn +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem walkKernel_lazy (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1/2) + (x : V) : 1/2 ≤ walkKernel G hloc a x x := by + have hn : ((neighbors G hloc x).card : ℝ) ≤ D := by + exact_mod_cast (neighbors_card_le_degree G hloc x).trans (hD x) + have hh := mul_le_mul_of_nonneg_left hn ha + simp only [walkKernel,ite_true] + split_ifs <;> linarith + +theorem positive_lazy_power_step (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (k : ℕ) (x y : V) : + (1/2) * (matrixCoeff (P^k) x y).re ≤ (matrixCoeff (P^(k+1)) x y).re := by + have hs := hpos.mul_hasSum (P^k) x y + have hh := hs.summable.sum_le_tsum ({x} : Finset V) + (fun z _ => mul_nonneg (hpos x z).2 ((hpos.pow k) z y).2) + simp only [Finset.sum_singleton,hs.tsum_eq,←pow_succ'] at hh + exact (mul_le_mul_of_nonneg_right (hdiag x) ((hpos.pow k) x y).2).trans hh + + + +theorem walkPower_orbit_return_lower (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (L : ℕ) : + (1/2) * (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ + ∑' y, if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^L) (root i₀) y).re else 0 := by + have hsum (k : ℕ) : Summable (fun y => + if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^k) (root i₀) y).re else 0) := by + simpa only [mul_ite,mul_one,mul_zero] using finiteKernel_summable_mul + (fun x y => (matrixCoeff (P^k) x y).re) (walkPower_finite_support G hloc a P hpos hP k) + (root i₀) (fun y => if y ∈ vertexOrbit G (root i₀) then 1 else 0) + obtain ⟨k,hk | hk⟩ := Nat.even_or_odd' L + · rw [hk] + have hh := walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k + have hn : 0 ≤ ∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0 := + Finset.sum_nonneg (fun i _ => by split_ifs <;> first | exact hw i | rfl) + linarith + · rw [hk] + have hh := mul_le_mul_of_nonneg_left + (walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k) + (show (0:ℝ) ≤ 1/2 by norm_num) + apply hh.trans + rw [←tsum_mul_left] + apply ((hsum (2*k)).mul_left (1/2)).tsum_le_tsum _ (hsum (2*k+1)) + intro y + split_ifs + · exact positive_lazy_power_step P hpos hdiag (2*k) (root i₀) y + · simp only [mul_zero,le_refl] + +end LazyOrbitReturn +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section UniformLabeledLaw +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +omit [Fintype I] in + + +theorem segmentReturnMass_uniform_lower (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (γ : I → V) (ep : I) (L : ℕ) : + 1/(2*c) ≤ segmentReturnMass G hloc a γ ep L (γ ep) := by + obtain ⟨i,g,hg,hx⟩ := hcov (γ ep) + obtain ⟨b,hb⟩ := hΓ hg + have hO := vertexOrbit_eq_of_mem G (root i) (γ ep) ⟨g,b,hb,hx⟩ + rw [←hx,segmentReturnMass_aut G hloc a γ ep L (root i) P hpos hP hb] + rw [segmentReturnMass_operator G hloc a γ ep L (root i) P hpos hP] + rw [hO] + have hh := walkPower_orbit_return_lower G hloc a root weight Γ hΓ htr + (fun i => (hw i).le) hw1 i (hw i) P hpos hsym hP hdiag L + have hi : weight i ≤ ∑ r, if root r ∈ vertexOrbit G (root i) then weight r else 0 := by + have hx' : root i ∈ vertexOrbit G (root i) := ⟨Equiv.refl _,Equiv.refl _,isAut_refl G,rfl⟩ + simpa only [ite_eq_left hx'] using Finset.single_le_sum + (f := fun r => if root r ∈ vertexOrbit G (root i) then weight r else 0) + (fun r _ => by split_ifs <;> first | exact (hw r).le | rfl) (Finset.mem_univ i) + apply le_trans _ hh + have hct : 0 < 2*c := mul_pos (by norm_num) hc + apply (div_le_iff₀ hct).mpr + have hh' := mul_le_mul_of_nonneg_left hi hc.le + nlinarith [hmin i] + + + +theorem rooted_label_probability_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) : + HasSum (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) 1 := by + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ ep L + have hp : 0 < segmentReturnMass G hloc a γ ep L (γ ep) := + (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq + have hs : Summable (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) := + summable_of_hasFiniteSupport (Set.toFinite _) + rw [←rooted_label_probability_sum G hloc a γ n hdiam center ep neg L m x hx P hpos hP (ne_of_gt hp)] + exact hs.hasSum + +end UniformLabeledLaw +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section LabeledTransport +attribute [local instance] Classical.propDecidable Classical.decEq +variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} + +def labelEndpointEquiv (center : I) (x : V) : + (Σ y : V, {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}) ≃ + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} where + toFun ξ := ⟨ξ.2.1,ξ.2.2.1⟩ + invFun ξ := ⟨ξ.1.last center,ξ.1,ξ.2,rfl⟩ + left_inv ξ := by rcases ξ with ⟨y,ξ,hx,hy⟩; subst y; rfl + right_inv ξ := rfl + +def labelAutPairEquiv {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (center : I) (x y : V) : + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} ≃ + {ξ : EscapeLabel G γ ep neg L m // ξ.first center = a x ∧ ξ.last center = a y} where + toFun ξ := ⟨EscapeLabel.autMap hab ξ.1,congrArg a ξ.2.1,congrArg a ξ.2.2⟩ + invFun ξ := ⟨EscapeLabel.autMap (isAut_symm G hab) ξ.1,by + change a.symm (ξ.1.first center) = x ∧ a.symm (ξ.1.last center) = y + rw [ξ.2.1,ξ.2.2,a.symm_apply_apply,a.symm_apply_apply] + exact ⟨rfl,rfl⟩⟩ + left_inv ξ := Subtype.ext (EscapeLabel.autMap_symm hab ξ.1) + right_inv ξ := Subtype.ext (EscapeLabel.autMap_symm (isAut_symm G hab) ξ.1) + +noncomputable def escapeLabelTransport (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) (x y : V) : ℝ := + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}, B ξ.1 + +theorem escapeLabelTransport_reverse (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) (x y : V) : + escapeLabelTransport center B x y = + escapeLabelTransport center (fun ξ => B ξ.reverse) y x := by + unfold escapeLabelTransport + exact (EscapeLabel.reverseRootedEquiv center y x).tsum_eq _ |>.symm + +theorem escapeLabelTransport_aut (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (hB : ∀ ξ, B (EscapeLabel.autMap hab ξ) = B ξ) (x y : V) : + escapeLabelTransport center B (a x) (a y) = escapeLabelTransport center B x y := by + unfold escapeLabelTransport + rw [←(labelAutPairEquiv hab center x y).tsum_eq] + exact tsum_congr (fun ξ => hB ξ.1) + +variable [Fintype I] + +theorem finite_pair_label_sigma (hloc : LocallyFinite G) (n : ℕ) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) (x : V) : + Finite (Σ y : V, {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y}) := by + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + exact Finite.of_equiv _ (labelEndpointEquiv center x).symm + +theorem escapeLabelTransport_row_sum (hloc : LocallyFinite G) (n : ℕ) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) + (B : EscapeLabel G γ ep neg L m → ℝ) (x : V) : + (∑' y, escapeLabelTransport center B x y) = + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1 := by + let := finite_pair_label_sigma hloc n hdiam center (ep := ep) (neg := neg) (L := L) (m := m) x + have hs : Summable (fun ξ : Σ y : V, {ξ : EscapeLabel G γ ep neg L m // + ξ.first center = x ∧ ξ.last center = y} => B ξ.2.1) := + summable_of_hasFiniteSupport (Set.toFinite _) + unfold escapeLabelTransport + rw [←hs.tsum_sigma] + exact (labelEndpointEquiv (G := G) (γ := γ) (ep := ep) (neg := neg) (L := L) (m := m) center x).tsum_eq (fun ξ => B ξ.1) + +theorem escapeLabelTransport_rowSummable (hloc : LocallyFinite G) (n : ℕ) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) + (B : EscapeLabel G γ ep neg L m → ℝ) (x : V) : + Summable (escapeLabelTransport center B x) := by + let := finite_pair_label_sigma hloc n hdiam center (ep := ep) (neg := neg) (L := L) (m := m) x + have hs : Summable (fun ξ : Σ y : V, {ξ : EscapeLabel G γ ep neg L m // + ξ.first center = x ∧ ξ.last center = y} => B ξ.2.1) := + summable_of_hasFiniteSupport (Set.toFinite _) + exact hs.sigma + +theorem escapeLabelTransport_columnSummable (hloc : LocallyFinite G) (n : ℕ) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) + (B : EscapeLabel G γ ep neg L m → ℝ) (y : V) : + Summable (fun x => escapeLabelTransport center B x y) := by + simp only [escapeLabelTransport_reverse center B] + exact escapeLabelTransport_rowSummable hloc n hdiam center (fun ξ => B ξ.reverse) y + +end LabeledTransport +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section LabeledReRooting +attribute [local instance] Classical.propDecidable Classical.decEq +variable {G : BondGraph V E} {γ : I → V} {ep neg : I} {L m : ℕ} + +theorem EscapeLabel.first_orbit (ξ : EscapeLabel G γ ep neg L m) (i : I) : + ξ.first i ∈ vertexOrbit G (γ i) := by + obtain ⟨a,b,h,he⟩ := ξ.first_mem + exact ⟨a,b,h,(congrFun he i).symm⟩ + +theorem EscapeLabel.last_orbit (ξ : EscapeLabel G γ ep neg L m) (i : I) : + ξ.last i ∈ vertexOrbit G (γ i) := by + obtain ⟨a,b,h,he⟩ := ξ.last_mem + exact ⟨a,b,h,(congrFun he i).symm⟩ + +theorem escapeLabelTransport_zero (center : I) (B : EscapeLabel G γ ep neg L m → ℝ) + (x y : V) (hxy : x ∉ vertexOrbit G (γ center) ∨ y ∉ vertexOrbit G (γ center)) : + escapeLabelTransport center B x y = 0 := by + let : IsEmpty {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x ∧ ξ.last center = y} := + ⟨fun ξ => by + rcases hxy with hx | hy + · exact hx (ξ.2.1 ▸ ξ.1.first_orbit center) + · exact hy (ξ.2.2 ▸ ξ.1.last_orbit center)⟩ + exact tsum_empty + +variable [Fintype I] + + + +theorem rooted_label_weight_reversal (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center : I) + (hθ : 0 < ∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0) + (B : EscapeLabel G γ ep neg L m → ℝ) + (hB : ∀ (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) ξ, B (EscapeLabel.autMap hab ξ) = B ξ) + (x : V) (hx : x ∈ vertexOrbit G (γ center)) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1) = + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, B ξ.1.reverse := by + let M := escapeLabelTransport center B + have hM (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (u v : V) : M (a u) (a v) = M u v := + escapeLabelTransport_aut center B hab (hB a b hab) u v + have hr (u : V) : (∑' v, M u v) = if u ∈ vertexOrbit G (γ center) then ∑' v, M (γ center) v else 0 := by + split_ifs with hu + · obtain ⟨a,b,hab,rfl⟩ := hu + rw [←a.tsum_eq] + exact tsum_congr (fun v => hM a b hab (γ center) v) + · calc + _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun v => escapeLabelTransport_zero center B u v (Or.inl hu)) + _ = 0 := tsum_zero + have hc (v : V) : (∑' u, M u v) = if v ∈ vertexOrbit G (γ center) then ∑' u, M u (γ center) else 0 := by + split_ifs with hv + · obtain ⟨a,b,hab,rfl⟩ := hv + rw [←a.tsum_eq] + exact tsum_congr (fun u => hM a b hab u (γ center)) + · calc + _ = ∑' _ : V, (0:ℝ) := tsum_congr (fun u => escapeLabelTransport_zero center B u v (Or.inr hv)) + _ = 0 := tsum_zero + have ht := htr.real root weight Γ M + (fun a ha u v => by obtain ⟨b,hb⟩ := hΓ ha; exact hM a b hb u v) + (escapeLabelTransport_rowSummable hloc n hdiam center B) + (escapeLabelTransport_columnSummable hloc n hdiam center B) + have hfactor (f : V → ℝ) (q : ℝ) (he : ∀ u, f u = if u ∈ vertexOrbit G (γ center) then q else 0) : + (∑ i, weight i*f (root i)) = (∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0)*q := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + rw [he] + split_ifs <;> simp only [mul_zero,zero_mul] + rw [hfactor _ _ hr,hfactor _ _ hc] at ht + have hrc := (mul_left_cancel₀ (ne_of_gt hθ)) ht + have hxe : (∑' v, M x v) = ∑' u, M u x := by + rw [hr x,hc x,ite_eq_left hx,ite_eq_left hx] + exact hrc + calc + _ = ∑' v, M x v := (escapeLabelTransport_row_sum hloc n hdiam center B x).symm + _ = ∑' u, M u x := hxe + _ = ∑' u, escapeLabelTransport center (fun ξ => B ξ.reverse) x u := + tsum_congr (fun u => escapeLabelTransport_reverse center B u x) + _ = _ := escapeLabelTransport_row_sum hloc n hdiam center (fun ξ => B ξ.reverse) x + +end LabeledReRooting +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section ExactLabeledReversal +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +theorem escapeLabelProbability_aut (G : BondGraph V E) (hloc : LocallyFinite G) + (a₀ : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (ξ : EscapeLabel G γ ep neg L m) : + escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m (EscapeLabel.autMap hab ξ) = + escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ := by + simp only [escapeLabelProbability,EscapeLabel.mass_autMap] + + + +theorem rooted_escape_label_reversal (G : BondGraph V E) (hloc : LocallyFinite G) (a₀ : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) (L m : ℕ) + (hθ : 0 < ∑ i, if root i ∈ vertexOrbit G (γ center) then weight i else 0) + (F : EscapeLabel G γ ep neg L m → ℝ) + (hF : ∀ (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) ξ, F (EscapeLabel.autMap hab ξ) = F ξ) + (x : V) (hx : x ∈ vertexOrbit G (γ center)) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ.1 * F ξ.1) = + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ.1 * F ξ.1.reverse := by + have hh := rooted_label_weight_reversal hloc root weight Γ hΓ htr n hdiam center hθ + (fun ξ => escapeLabelProbability G hloc a₀ γ n hdiam center ep neg L m ξ * F ξ) + (fun a b hab ξ => by rw [escapeLabelProbability_aut G hloc a₀ γ n hdiam center ep neg L m hab,hF a b hab]) x hx + simpa only [escapeLabelProbability_reverse] using hh + +theorem escapeLabelProbability_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (hP : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (ξ : EscapeLabel G γ ep neg L m) : + 0 ≤ escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by + have hq : 0 ≤ segmentReturnMass G hloc a γ ep L (γ ep) := by + apply tsum_nonneg + intro mid + split_ifs + · exact mid.2.mass_nonneg _ hP + · rfl + exact div_nonneg (ξ.mass_nonneg _ hP) (mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) hq) + +end ExactLabeledReversal +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LongGeodesics +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_geodesic_length (G : BondGraph V E) [Infinite V] + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) (N : ℕ) : + ∃ y : V, ∃ q : (openSimpleGraph G Set.univ).Walk x y, + q.length = N ∧ q.length = (openSimpleGraph G Set.univ).dist x y := by + obtain ⟨z,hz⟩ := (finite_reachBall hloc x N).exists_notMem + have hc := (conn_iff_reachable G Set.univ x z).mp (conn_univ_of_connected G hconn x z) + obtain ⟨q,hq⟩ := hc.exists_walk_length_eq_dist + have hN : N < q.length := by + by_contra hh + have hm := walk_mem_reachBall G Set.univ q 0 (show x ∈ reachBall G x 0 from rfl) + have hm' : z ∈ reachBall G x q.length := by simpa only [Nat.zero_add] using hm + exact hz (reachBall_mono_local G x (Nat.le_of_not_gt hh) hm') + refine ⟨q.getVert N,q.take N,?_,?_⟩ + · simp only [SimpleGraph.Walk.take_length,inf_eq_left.mpr hN.le] + · exact SimpleGraph.length_eq_dist_of_subwalk hq (q.isSubwalk_take N) + + + +theorem geodesic_getVert_dist (H : SimpleGraph V) {x y : V} (q : H.Walk x y) + (hq : q.length = H.dist x y) (i j : ℕ) (hij : i ≤ j) (hj : j ≤ q.length) : + H.dist (q.getVert i) (q.getVert j) = j-i := by + have hs := SimpleGraph.length_eq_dist_of_subwalk hq + (((q.drop i).isSubwalk_take (j-i)).trans (q.isSubwalk_drop i)) + have he : (q.drop i).getVert (j-i) = q.getVert j := by + rw [SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hij] + rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length,he, + min_eq_left (Nat.sub_le_sub_right hj i)] at hs + exact hs.symm + +end LongGeodesics +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +namespace HoldingWalk +variable {H : SimpleGraph V} + + + +def append : {k l : ℕ} → {x y z : V} → HoldingWalk H k x y → HoldingWalk H l y z → HoldingWalk H (l+k) x z + | _,_,_,_,_,.nil _,v => v + | _,_,_,_,_,.hold w,v => .hold (w.append v) + | _,_,_,_,_,.step h w,v => .step h (w.append v) + +def ofWalk : {x y : V} → (w : H.Walk x y) → HoldingWalk H w.length x y + | _,_,.nil => .nil _ + | _,_,.cons h w => .step h (ofWalk w) + +theorem mass_append (P : V → V → ℝ) {k l : ℕ} {x y z : V} + (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : + (w.append v).mass P = w.mass P*v.mass P := by + induction w with + | nil => simp only [append,mass,one_mul] + | hold w ih => simp only [append,mass,ih,mul_assoc] + | step h w ih => simp only [append,mass,ih,mul_assoc] + +theorem mass_ofWalk (P : V → V → ℝ) (a : ℝ) (hP : ∀ x y, H.Adj x y → P x y = a) + {x y : V} (w : H.Walk x y) : (ofWalk w).mass P = a^w.length := by + induction w with + | nil => rfl + | @cons x z y h w ih => simp only [ofWalk,mass,hP x z h,ih,SimpleGraph.Walk.length_cons,pow_succ']; + +theorem ofWalk_vertices {x y : V} (w : H.Walk x y) : (ofWalk w).vertices = w.support := by + induction w with + | nil => rfl + | cons h w ih => simp only [ofWalk,vertices,SimpleGraph.Walk.support_cons,ih] + +theorem append_vertices {k l : ℕ} {x y z : V} + (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : + (w.append v).vertices = w.vertices.dropLast ++ v.vertices := by + induction w with + | nil => rfl + | hold w ih => + have hn : w.vertices ≠ [] := by cases w <;> simp [vertices] + simp only [append,vertices,ih,List.dropLast_cons_of_ne_nil hn,List.cons_append] + | step h w ih => + have hn : w.vertices ≠ [] := by cases w <;> simp [vertices] + simp only [append,vertices,ih,List.dropLast_cons_of_ne_nil hn,List.cons_append] + +end HoldingWalk +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section GeodesicSegments +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def geodesicSegment (G : BondGraph V E) {x y : V} + (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) : Fin (N+1) → V := + fun i => q.getVert i + +theorem geodesicSegment_adj (G : BondGraph V E) {x y : V} + (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) + (i : ℕ) (hi : i < N) : + (openSimpleGraph G Set.univ).Adj + (geodesicSegment G q N ⟨i,by omega⟩) (geodesicSegment G q N ⟨i+1,by omega⟩) := by + change (openSimpleGraph G Set.univ).Adj (q.getVert i) (q.getVert (i+1)) + exact q.adj_getVert_succ (by omega) + +theorem geodesicSegment_injective (G : BondGraph V E) {x y : V} + (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) + (hq : q.length = (openSimpleGraph G Set.univ).dist x y) : + Function.Injective (geodesicSegment G q N) := by + intro i j hh + apply Fin.ext + exact (q.isPath_of_length_eq_dist hq).getVert_injOn + (by change i.val ≤ q.length; omega) (by change j.val ≤ q.length; omega) hh + +theorem geodesicSegment_diameter (G : BondGraph V E) {x y : V} + (q : (openSimpleGraph G Set.univ).Walk x y) (N : ℕ) (hN : q.length = N) : + ∀ i j, geodesicSegment G q N j ∈ reachBall G (geodesicSegment G q N i) N := by + intro i j + have hc : (openSimpleGraph G Set.univ).Reachable (q.getVert i) (q.getVert j) := + (q.take i).reachable.symm.trans (q.take j).reachable + obtain ⟨r,hr⟩ := hc.exists_walk_length_eq_dist + have hd : (openSimpleGraph G Set.univ).dist (q.getVert i) (q.getVert j) ≤ N := by + rcases le_total i.val j.val with hij | hji + · have hle := SimpleGraph.dist_le ((q.drop i).take (j-i)) + rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length, + SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hij] at hle + exact hle.trans (by omega) + · have hle := SimpleGraph.dist_le ((q.drop j).take (i-j)) + rw [SimpleGraph.Walk.take_length,SimpleGraph.Walk.drop_length, + SimpleGraph.Walk.drop_getVert,Nat.add_sub_of_le hji] at hle + rw [SimpleGraph.dist_comm] at hle + exact hle.trans (by omega) + have hm := walk_mem_reachBall G Set.univ r 0 (show q.getVert i ∈ reachBall G (q.getVert i) 0 from rfl) + apply reachBall_mono_local G (q.getVert i) (a := r.length) (by omega) + simpa only [Nat.zero_add, geodesicSegment] using hm + +theorem segmentOrbit_adj (G : BondGraph V E) {I : Type*} (γ s : I → V) + (hs : s ∈ segmentOrbit G γ) (i j : I) (hij : (openSimpleGraph G Set.univ).Adj (γ i) (γ j)) : + (openSimpleGraph G Set.univ).Adj (s i) (s j) := by + obtain ⟨a,b,hab,rfl⟩ := hs + exact (autSimpleGraph G hab).map_rel_iff.mpr hij + +theorem walkKernel_step (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {x y : V} (h : (openSimpleGraph G Set.univ).Adj x y) : walkKernel G hloc a x y = a := by + have hh := (openSimpleGraph_univ_adj G x y).mp h + simp only [walkKernel,ite_eq_right hh.1,ite_eq_left hh.2,zero_add] + +theorem walkKernel_ofWalk_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {x y : V} (q : (openSimpleGraph G Set.univ).Walk x y) : + (HoldingWalk.ofWalk q).mass (walkKernel G hloc a) = a^q.length := + HoldingWalk.mass_ofWalk _ a (fun _ _ h => walkKernel_step G hloc a h) q + +end GeodesicSegments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualTailPotentials +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_tail_twoPoint_expectation (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x b : V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + w.2.mass (walkKernel G hloc a) * twoPoint G p w.1 b) = + (matrixCoeff (P^m*A) x b).re := by + have he : (fun y => twoPoint G p y b) = (fun y => (matrixCoeff A y b).re) := by + funext y + rw [matrixCoeff,hA y b,Complex.ofReal_re] + change RawFrom.integral (H := openSimpleGraph G Set.univ) (walkKernel G hloc a) m x (twoPoint G p · b) = _ + rw [he,raw_integral_operator G hloc a P hpos hP] + exact ((hpos.pow m).mul_hasSum A x b).tsum_eq + + + +theorem raw_tail_potential_bound [Countable V] [Countable E] [Nonempty V] + {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x : V) (S : Finset V) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + w.2.mass (walkKernel G hloc a) * ∑ b ∈ S, twoPoint G p w.1 b) ≤ + (S.card:ℝ) * Real.sqrt c * ‖P‖^m := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) + have hPinv : KernelInvariant (vertexAut G) P := by + intro e he x y + obtain ⟨f,hf⟩ := he + rw [hP,hP,walkKernel_covariant G hloc a hf] + calc + _ = ∑ b ∈ S, (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + w.2.mass (walkKernel G hloc a) * twoPoint G p w.1 b) := by + simp only [tsum_fintype,Finset.mul_sum] + exact Finset.sum_comm + _ = ∑ b ∈ S, (matrixCoeff (P^m*A) x b).re := by + apply Finset.sum_congr rfl + intro b _ + exact raw_tail_twoPoint_expectation G hloc a P A hpos hP p hA m x b + _ ≤ ∑ _b ∈ S, Real.sqrt c * ‖P‖^m := by + apply Finset.sum_le_sum + intro b _ + exact (Complex.re_le_norm _).trans (twoPoint_operator_smoothing G p root weight htr hcov hw hsum c hc hmin A P hA hPinv m x b) + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul,mul_assoc] + +end ActualTailPotentials +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AuxiliaryTailMarkov +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finite_weighted_markov {α : Type*} [Fintype α] (μ F : α → ℝ) + (hμ : ∀ x, 0 ≤ μ x) (hF : ∀ x, 0 ≤ F x) (t : ℝ) (ht : 0 < t) : + (∑ x, if t < F x then μ x else 0) ≤ (∑ x, μ x*F x)/t := by + apply (le_div_iff₀ ht).mpr + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro x _ + split_ifs with hx + · exact mul_le_mul_of_nonneg_left hx.le (hμ x) + · exact (by simpa only [zero_mul] using mul_nonneg (hμ x) (hF x)) + +theorem raw_tail_potential_failure [Countable V] [Countable E] [Nonempty V] + {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x : V) (S : Finset V) + (t : ℝ) (ht : 0 < t) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + if t < ∑ b ∈ S, twoPoint G p w.1 b then w.2.mass (walkKernel G hloc a) else 0) ≤ + ((S.card:ℝ) * Real.sqrt c * ‖P‖^m)/t := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hM := finite_weighted_markov + (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) + (fun w => ∑ b ∈ S, twoPoint G p w.1 b) + (fun w => w.2.mass_nonneg _ hK) + (fun w => Finset.sum_nonneg (fun b _ => twoPoint_nonneg G p w.1 b)) t ht + have hB := raw_tail_potential_bound G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m x S + simp only [tsum_fintype] at hB ⊢ + exact hM.trans (div_le_div_of_nonneg_right hB ht.le) + + + +theorem finite_product_failure_union {α β : Type*} [Fintype α] [Fintype β] + (μ : α → ℝ) (ν : β → ℝ) (hμ : ∀ x, 0 ≤ μ x) (hν : ∀ y, 0 ≤ ν y) + (hμ1 : ∑ x, μ x = 1) (hν1 : ∑ y, ν y = 1) (B : α → Prop) (C : β → Prop) : + (∑ z : α × β, if B z.1 ∨ C z.2 then μ z.1*ν z.2 else 0) ≤ + (∑ x, if B x then μ x else 0) + ∑ y, if C y then ν y else 0 := by + calc + _ ≤ ∑ z : α × β, ((if B z.1 then μ z.1 else 0)*ν z.2 + μ z.1*(if C z.2 then ν z.2 else 0)) := by + apply Finset.sum_le_sum + intro z _ + by_cases hB : B z.1 <;> by_cases hC : C z.2 <;> + simp [hB,hC] + exact mul_nonneg (hμ _) (hν _) + _ = _ := by + rw [Fintype.sum_prod_type] + simp only [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.sum_mul,hμ1,hν1,mul_one,one_mul] + +end AuxiliaryTailMarkov +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IndependentTailPotentialTests +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem two_raw_tail_potential_failure [Countable V] [Countable E] [Nonempty V] + {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ i, ∃ e ∈ vertexAut G, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (p : unitInterval) (hA : HasKernel G p A) (m : ℕ) (x y : V) (S : Finset V) + (t : ℝ) (ht : 0 < t) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) m y, + if (t < ∑ b ∈ S, twoPoint G p w.1.1 b) ∨ (t < ∑ b ∈ S, twoPoint G p w.2.1 b) + then w.1.2.mass (walkKernel G hloc a) * w.2.2.mass (walkKernel G hloc a) else 0) ≤ + 2*((S.card:ℝ) * Real.sqrt c * ‖P‖^m)/t := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m x) + let := Fintype.ofFinite (RawFrom (openSimpleGraph G Set.univ) m y) + have hK (u v : V) : 0 ≤ walkKernel G hloc a u v := by + simpa only [hP,Complex.ofReal_re] using (hpos u v).2 + have hμ := rawFrom_probability_sum G hloc a m x + have hν := rawFrom_probability_sum G hloc a m y + simp only [tsum_fintype] at hμ hν + have hU := finite_product_failure_union + (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) + (fun w : RawFrom (openSimpleGraph G Set.univ) m y => w.2.mass (walkKernel G hloc a)) + (fun w => w.2.mass_nonneg _ hK) (fun w => w.2.mass_nonneg _ hK) hμ hν + (fun w => t < ∑ b ∈ S, twoPoint G p w.1 b) + (fun w => t < ∑ b ∈ S, twoPoint G p w.1 b) + have hx := raw_tail_potential_failure G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m x S t ht + have hy := raw_tail_potential_failure G hloc a root weight htr hcov hw hsum c hc hmin P A hpos hP p hA m y S t ht + simp only [tsum_fintype] at hx hy ⊢ + exact hU.trans ((add_le_add hx hy).trans_eq (by ring)) + +end IndependentTailPotentialTests +end Percolation + + +namespace Percolation +section LogarithmicTailLength + + + +theorem logarithmic_tail_power (ρ X : ℝ) (hρ : 0 < ρ) (hρ1 : ρ < 1) (hX : 0 < X) : + ρ ^ ⌈(2/(-Real.log ρ))*Real.log X⌉₊ ≤ X^(-2:ℝ) := by + have hl : Real.log ρ ≠ 0 := ne_of_lt (Real.log_neg hρ hρ1) + calc + _ = ρ ^ (⌈(2/(-Real.log ρ))*Real.log X⌉₊ : ℝ) := (Real.rpow_natCast _ _).symm + _ ≤ ρ ^ ((2/(-Real.log ρ))*Real.log X) := + Real.rpow_le_rpow_of_exponent_ge hρ hρ1.le (Nat.le_ceil _) + _ = X^(-2:ℝ) := by + rw [Real.rpow_def_of_pos hρ,Real.rpow_def_of_pos hX] + congr 1 + field_simp [hl] + + + +theorem exists_uniform_logarithmic_tail_cutoff (ρ A : ℝ) + (hρ : 0 < ρ) (hρ1 : ρ < 1) (hA : 0 ≤ A) (kmin : ℕ) : + ∃ C₁ : ℝ, 0 < C₁ ∧ 1 < (-Real.log ρ)*C₁ ∧ + ∃ k₀ : ℕ, kmin ≤ k₀ ∧ ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → + A*((k:ℝ)+1)*R*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ ≤ 1/4 := by + have hlambda : 0 < -Real.log ρ := neg_pos.mpr (Real.log_neg hρ hρ1) + refine ⟨2/(-Real.log ρ),div_pos (by norm_num) hlambda,?_,max kmin ⌈4*A⌉₊,le_max_left _ _,?_⟩ + · rw [mul_div_cancel₀ _ (ne_of_gt hlambda)] + norm_num + · intro k hk R hR + have hk' : ⌈4*A⌉₊ ≤ k := (le_max_right _ _).trans hk + have hAk : 4*A ≤ (k:ℝ) := (Nat.le_ceil (4*A)).trans (by exact_mod_cast hk') + have hkpos : 0 < (k:ℝ)+1 := by positivity + have hRp : 0 < R := lt_of_lt_of_le (by norm_num) hR + let X : ℝ := ((k:ℝ)+1)*R + have hX : 0 < X := mul_pos hkpos hRp + have hXk : (k:ℝ)+1 ≤ X := by dsimp [X]; exact le_mul_of_one_le_right hkpos.le hR + have hp := logarithmic_tail_power ρ X hρ hρ1 hX + have hneg : X^(-2:ℝ) = (X^2)⁻¹ := by rw [Real.rpow_neg,show (2:ℝ) = (2:ℕ) by norm_num,Real.rpow_natCast]; exact hX.le + calc + _ = A*X*ρ^⌈(2/(-Real.log ρ))*Real.log X⌉₊ := by dsimp [X]; ring + _ ≤ A*X*X^(-2:ℝ) := mul_le_mul_of_nonneg_left hp (mul_nonneg hA hX.le) + _ = A/X := by rw [hneg]; field_simp [ne_of_gt hX] + _ ≤ 1/4 := (div_le_iff₀ hX).mpr (by linarith) + +end LogarithmicTailLength +end Percolation + + +namespace Percolation +universe u +variable {V : Type u} +namespace HoldingWalk +variable {H : SimpleGraph V} + + + +def position : {k : ℕ} → {x y : V} → HoldingWalk H k x y → ℕ → V + | _,x,_,.nil _,_ => x + | _,x,_,.hold _,0 => x + | _,_,_,.hold w,n+1 => w.position n + | _,x,_,.step _ _,0 => x + | _,_,_,.step _ w,n+1 => w.position n + +@[simp] theorem position_zero {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.position 0 = x := by + cases w <;> rfl + +@[simp] theorem position_length {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : w.position k = y := by + induction w with + | nil => rfl + | hold w ih => exact ih + | step h w ih => exact ih + +theorem position_mem_vertices {k : ℕ} {x y : V} (w : HoldingWalk H k x y) (i : ℕ) : + w.position i ∈ w.vertices := by + induction w generalizing i with + | nil => simp only [position,vertices,List.mem_singleton] + | hold w ih => cases i <;> simp only [position,vertices,List.mem_cons,true_or,ih,or_true] + | step h w ih => cases i <;> simp only [position,vertices,List.mem_cons,true_or,ih,or_true] + +theorem mem_vertices_iff_position {k : ℕ} {x y z : V} (w : HoldingWalk H k x y) : + z ∈ w.vertices ↔ ∃ i : ℕ, i ≤ k ∧ w.position i = z := by + induction w with + | nil => simp only [vertices,List.mem_singleton,Nat.le_zero,exists_eq_left,position,eq_comm] + | @hold k x y w ih => + constructor + · intro hz + rcases List.mem_cons.mp hz with rfl | hz + · exact ⟨0,Nat.zero_le _,rfl⟩ + · obtain ⟨i,hi,he⟩ := ih.mp hz + exact ⟨i+1,Nat.succ_le_succ hi,he⟩ + · rintro ⟨i,hi,he⟩ + cases i with + | zero => exact List.mem_cons.mpr (Or.inl he.symm) + | succ i => exact List.mem_cons.mpr (Or.inr (ih.mpr ⟨i,Nat.le_of_succ_le_succ hi,he⟩)) + | @step k x u y h w ih => + constructor + · intro hz + rcases List.mem_cons.mp hz with rfl | hz + · exact ⟨0,Nat.zero_le _,rfl⟩ + · obtain ⟨i,hi,he⟩ := ih.mp hz + exact ⟨i+1,Nat.succ_le_succ hi,he⟩ + · rintro ⟨i,hi,he⟩ + cases i with + | zero => exact List.mem_cons.mpr (Or.inl he.symm) + | succ i => exact List.mem_cons.mpr (Or.inr (ih.mpr ⟨i,Nat.le_of_succ_le_succ hi,he⟩)) + +end HoldingWalk +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Escape/PathSelection.lean b/lean/OAI/Probability/UnimodularPercolation/Escape/PathSelection.lean index b1756ad27bcf378bce02258d541be95f1a50056d..696641b6be8b3458a3b55c67a0a55941b7d99b28 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Escape/PathSelection.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Escape/PathSelection.lean @@ -1,563 +1,563 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.SelectionBounds - -namespace OAI - -/-! Selection of geometrically separated paths from labelled escape events. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section EscapeGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace HoldingWalk -variable {H : SimpleGraph V} - -theorem mem_vertices_append {k l : ℕ} {x y z b : V} - (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : - b ∈ (w.append v).vertices ↔ b ∈ w.vertices ∨ b ∈ v.vertices := by - induction w with - | nil x => - have hx : x ∈ v.vertices := by simpa using v.position_mem_vertices 0 - simp only [append, vertices, List.mem_singleton] - exact ⟨fun h => Or.inr h, fun h => h.elim (fun he => he ▸ hx) id⟩ - | hold w ih => simp only [append, vertices, List.mem_cons, ih, or_assoc] - | step h w ih => simp only [append, vertices, List.mem_cons, ih, or_assoc] - -theorem mem_vertices_fromPositions (k : ℕ) (f : Fin (k+1) → V) - (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) (b : V) : - b ∈ (fromPositions k f h).vertices ↔ ∃ i, f i = b := by - rw [mem_vertices_iff_position] - constructor - · rintro ⟨i, hi, he⟩ - exact ⟨⟨i,by omega⟩, (position_fromPositions k f h i hi).symm.trans he⟩ - · rintro ⟨i,hi⟩ - exact ⟨i.val,by omega,(position_fromPositions k f h i.val (by omega)).trans hi⟩ - -end HoldingWalk - - -def negativeStem (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) - (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) : - HoldingWalk H J (s (segmentCenter J)) (s 0) := - (HoldingWalk.fromPositions J (fun i => s ⟨i.val,by omega⟩) - (fun i => hs ⟨i.val,by omega⟩)).reverse - -theorem positiveStem_vertices (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) - (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) (z : V) : - z ∈ (positiveStem H J s hs).vertices ↔ ∃ i : Fin (J+1), s ⟨J+i.val,by omega⟩ = z := by - exact HoldingWalk.mem_vertices_fromPositions J _ _ z - -theorem negativeStem_vertices (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) - (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) (z : V) : - z ∈ (negativeStem H J s hs).vertices ↔ ∃ i : Fin (J+1), s ⟨i.val,by omega⟩ = z := by - let w := HoldingWalk.fromPositions J (fun i : Fin (J+1) => s ⟨i.val,by omega⟩) - (fun i : Fin J => hs ⟨i.val,by omega⟩) - have he : z ∈ w.reverse.vertices ↔ z ∈ w.vertices := by - rw [HoldingWalk.vertices_reverse, List.mem_reverse] - exact he.trans (HoldingWalk.mem_vertices_fromPositions J _ _ z) - - -def labelLeftEscape (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : - HoldingWalk (openSimpleGraph G Set.univ) (m+J) - (ξ.first (segmentCenter J)) ξ.leftTail.1 := - (negativeStem _ J ξ.first (orbitSegment_consecutive G J γ ξ.first hγ ξ.first_mem)).append ξ.leftTail.2 - - -def labelCorridor (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : RawCorridor G ((J+L)+J) := - ⟨ξ.first (segmentCenter J), ξ.last (segmentCenter J), escapeLabelRaw G J L m γ hγ ξ⟩ - -def segmentPositiveIndex (J : ℕ) : Fin (J+1) → Fin (J+J+1) := - fun i => ⟨J+i.val,by omega⟩ -def segmentNegativeIndex (J : ℕ) : Fin (J+1) → Fin (J+J+1) := - fun i => ⟨i.val,by omega⟩ - -theorem segmentOrbit_injective {I : Type*} (G : BondGraph V E) (γ s : I → V) - (hγ : Function.Injective γ) (hs : s ∈ segmentOrbit G γ) : Function.Injective s := by - obtain ⟨a,b,hab,rfl⟩ := hs - exact a.injective.comp hγ - - - -theorem labelLeftEscape_raw_intersection (G : BondGraph V E) (J L m : ℕ) - (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) - (hgood : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m - (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ) - (z : V) (hz : z ∈ (labelLeftEscape G J L m γ hγ ξ).vertices) - (hr : z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices) : - z = ξ.first (segmentCenter J) := by - have hfirst := segmentOrbit_injective G γ ξ.first hinj ξ.first_mem - have hfail := hgood - unfold labelFirstEscapeCollision firstEscapeCollision at hfail - have hraw : (∃ i : Fin (J+1), ξ.first (segmentPositiveIndex J i) = z) ∨ - z ∈ ξ.middle.vertices ∨ (∃ i : Fin (J+1), ξ.last (segmentPositiveIndex J i) = z) := by - simpa only [escapeLabelRaw, HoldingWalk.mem_vertices_append, - HoldingWalk.vertices_reverse, List.mem_reverse, positiveStem_vertices, - segmentPositiveIndex] using hr - have hleft : (∃ i : Fin (J+1), ξ.first (segmentNegativeIndex J i) = z) ∨ - z ∈ ξ.leftTail.2.vertices := by - simpa only [labelLeftEscape, HoldingWalk.mem_vertices_append, - negativeStem_vertices, segmentNegativeIndex] using hz - rcases hleft with ⟨i,hi⟩ | ht - · rcases hraw with ⟨j,hj⟩ | hm | ⟨j,hj⟩ - · have he := congrArg Fin.val (hfirst (hi.trans hj.symm)) - change i.val = J+j.val at he - have hiJ : i.val = J := by omega - rw [←hi] - congr 1 - apply Fin.ext - exact hiJ - · exact False.elim (hfail (Or.inl (Or.inl (Or.inr ⟨i,by simpa only [hi] using hm⟩)))) - · exact False.elim (hfail (Or.inr (Or.inl ⟨(j,i),hj.trans hi.symm⟩))) - · rcases hraw with ⟨i,hi⟩ | hm | ⟨i,hi⟩ - · exact False.elim (hfail (Or.inl (Or.inl (Or.inl ⟨i,by simpa only [hi] using ht⟩)))) - · exact False.elim (hfail (Or.inl (Or.inr ⟨z,ht,hm⟩))) - · obtain ⟨l,hl,he⟩ := ξ.leftTail.2.mem_vertices_iff_position.mp ht - exact False.elim (hfail (Or.inr (Or.inr ⟨(⟨l,by omega⟩,i),he.trans hi.symm⟩))) - - -theorem labelRaw_reverse_vertices (G : BondGraph V E) (J L m : ℕ) - (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (z : V) : - z ∈ (escapeLabelRaw G J L m γ hγ ξ.reverse).vertices ↔ - z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices := by - simp only [escapeLabelRaw, HoldingWalk.mem_vertices_append, - HoldingWalk.vertices_reverse, List.mem_reverse, EscapeLabel.reverse] - tauto - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -theorem interior_mem_raw (w : RawCorridor G k) {z : V} (hz : z ∈ w.interior) : - z ∈ w.2.2.vertices := by - have hp : z ∈ w.path.support := List.mem_toFinset.mp (Finset.mem_sdiff.mp hz).1 - exact w.2.2.erase_support.subset hp - - -noncomputable def neighborhood (hloc : LocallyFinite G) (w : RawCorridor G k) : Finset V := - w.interior ∪ w.interior.biUnion (neighbors G hloc) - -theorem coe_neighborhood (hloc : LocallyFinite G) (w : RawCorridor G k) : - (w.neighborhood hloc : Set V) = closedBondNeighborhood G (w.interior : Set V) := - (closedBondNeighborhood_finset G hloc w.interior).symm - - -def HasEscape (hloc : LocallyFinite G) (p : unitInterval) (j : ℕ) (t : ℝ) - (w : RawCorridor G k) (x : V) : Prop := - ∃ z, ∃ q : (openSimpleGraph G Set.univ).Walk x z, - q.IsPath ∧ q.length ≤ j ∧ (∀ v ∈ q.support, v ∉ w.interior) ∧ - (∑ b ∈ w.neighborhood hloc, twoPoint G p z b) ≤ t - - -def Selected (hloc : LocallyFinite G) (p : unitInterval) (j : ℕ) (t : ℝ) - (w : RawCorridor G k) : Prop := - 3 ≤ w.path.length ∧ w.HasEscape hloc p j t w.base ∧ w.HasEscape hloc p j t w.endpoint - -end RawCorridor - - - -noncomputable def spineVertices (G : BondGraph V E) (J L : ℕ) - (s : Fin (J+J+1) → V) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) - (h : Fin (J+J+1) → V) : Finset V := - Finset.univ.image (s ∘ segmentPositiveIndex J) ∪ mid.2.vertices.toFinset ∪ - Finset.univ.image (h ∘ segmentPositiveIndex J) - -noncomputable def spineNeighborhood (G : BondGraph V E) (hloc : LocallyFinite G) (J L : ℕ) - (s : Fin (J+J+1) → V) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) - (h : Fin (J+J+1) → V) : Finset V := - let W := spineVertices G J L s mid h - W ∪ W.biUnion (neighbors G hloc) - -theorem mem_spineVertices (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (z : V) : - z ∈ spineVertices G J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last ↔ - z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices := by - simp only [spineVertices, Finset.mem_union, Finset.mem_image, Finset.mem_univ, - true_and, Function.comp_apply, List.mem_toFinset, escapeLabelRaw, - HoldingWalk.mem_vertices_append, HoldingWalk.vertices_reverse, List.mem_reverse, - positiveStem_vertices, segmentPositiveIndex] - tauto - -theorem labelCorridor_neighborhood_subset (G : BondGraph V E) (hloc : LocallyFinite G) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : - (labelCorridor G J L m γ hγ ξ).neighborhood hloc ⊆ - spineNeighborhood G hloc J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last := by - have hi : (labelCorridor G J L m γ hγ ξ).interior ⊆ - spineVertices G J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last := by - intro z hz - exact (mem_spineVertices G J L m γ hγ ξ z).mpr - ((labelCorridor G J L m γ hγ ξ).interior_mem_raw hz) - exact Finset.union_subset_union hi (Finset.biUnion_subset_biUnion_of_subset_left _ hi) - -theorem neighborhood_card_le (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (W : Finset V) : - (W ∪ W.biUnion (neighbors G hloc)).card ≤ (d+1)*W.card := by - have hb : (W.biUnion (neighbors G hloc)).card ≤ W.card*d := - Finset.card_biUnion_le_card_mul _ _ _ - (fun x _ => (neighbors_card_le_degree G hloc x).trans (hd x)) - calc - _ ≤ W.card + (W.biUnion (neighbors G hloc)).card := Finset.card_union_le _ _ - _ ≤ W.card + W.card*d := Nat.add_le_add_left hb _ - _ = _ := by ring - -theorem spineVertices_card_le (G : BondGraph V E) (J L : ℕ) - (s : Fin (J+J+1) → V) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) - (h : Fin (J+J+1) → V) : - (spineVertices G J L s mid h).card ≤ ((J+L)+J)+3 := by - have h₁ : (Finset.univ.image (s ∘ segmentPositiveIndex J)).card ≤ J+1 := - (Finset.card_image_le).trans (by simp) - have h₂ : mid.2.vertices.toFinset.card ≤ L+1 := - (List.toFinset_card_le _).trans (le_of_eq mid.2.length_vertices) - have h₃ : (Finset.univ.image (h ∘ segmentPositiveIndex J)).card ≤ J+1 := - (Finset.card_image_le).trans (by simp) - have hauto := (Finset.card_union_le - (Finset.univ.image (s ∘ segmentPositiveIndex J)) mid.2.vertices.toFinset) - have hauto' := (Finset.card_union_le - (Finset.univ.image (s ∘ segmentPositiveIndex J) ∪ mid.2.vertices.toFinset) - (Finset.univ.image (h ∘ segmentPositiveIndex J))) - unfold spineVertices - omega - -theorem spineNeighborhood_card_le (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (J L : ℕ) - (s : Fin (J+J+1) → V) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) - (h : Fin (J+J+1) → V) : - ((spineNeighborhood G hloc J L s mid h).card : ℝ) ≤ - (3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1) := by - have hn := neighborhood_card_le G hloc d hd (spineVertices G J L s mid h) - have hs := spineVertices_card_le G J L s mid h - have hb : (spineNeighborhood G hloc J L s mid h).card ≤ (d+1)*(((J+L)+J)+3) := - hn.trans (Nat.mul_le_mul_left _ hs) - have hb' : ((spineNeighborhood G hloc J L s mid h).card : ℝ) ≤ - ((d:ℝ)+1)*((((J+L)+J):ℕ)+3) := by exact_mod_cast hb - have hk : (0:ℝ) ≤ (((J+L)+J):ℕ) := Nat.cast_nonneg _ - nlinarith [show (0:ℝ) ≤ (d:ℝ) from Nat.cast_nonneg d] - - - -theorem selected_of_good_label (G : BondGraph V E) (hloc : LocallyFinite G) - (J L m : ℕ) (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (p : unitInterval) (t : ℝ) - (hleft : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m - (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ) - (hright : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m - (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.reverse) - (hdist : ξ.last (segmentCenter J) ∉ reachBall G (ξ.first (segmentCenter J)) 2) - (hpot : ¬labelPotentialFailure G p γ (Fin.last (J+J)) 0 L m - (spineNeighborhood G hloc J L) t ξ) : - (labelCorridor G J L m γ hγ ξ).Selected hloc p (J+m) t := by - let w := labelCorridor G J L m γ hγ ξ - have hlength : 3 ≤ w.path.length := by - by_contra h - have hx : w.endpoint ∈ reachBall G w.base w.path.length := by - simpa only [Nat.zero_add] using walk_mem_reachBall G Set.univ w.path 0 rfl - exact hdist (reachBall_mono_local G w.base (by omega : w.path.length ≤ 2) hx) - have hn := labelCorridor_neighborhood_subset G hloc J L m γ hγ ξ - have hp := not_or.mp hpot - have hp₁ : (∑ b ∈ w.neighborhood hloc, twoPoint G p ξ.leftTail.1 b) ≤ t := by - apply le_trans (Finset.sum_le_sum_of_subset_of_nonneg hn (fun b _ _ => twoPoint_nonneg G p _ b)) - exact le_of_not_gt hp.1 - have hp₂ : (∑ b ∈ w.neighborhood hloc, twoPoint G p ξ.rightTail.1 b) ≤ t := by - apply le_trans (Finset.sum_le_sum_of_subset_of_nonneg hn (fun b _ _ => twoPoint_nonneg G p _ b)) - exact le_of_not_gt hp.2 - refine ⟨hlength, ?_, ?_⟩ - · let e := labelLeftEscape G J L m γ hγ ξ - refine ⟨ξ.leftTail.1, e.erase, e.erase_isPath, ?_, ?_, hp₁⟩ - · exact e.erase_length.trans (by omega) - · intro z hz hzI - have hr := w.interior_mem_raw hzI - have he := labelLeftEscape_raw_intersection G J L m γ hinj hγ ξ hleft z - (e.erase_support.subset hz) hr - change z = w.base at he - apply w.base_not_interior - simpa only [he] using hzI - · let e := labelLeftEscape G J L m γ hγ ξ.reverse - refine ⟨ξ.rightTail.1, e.erase, e.erase_isPath, ?_, ?_, hp₂⟩ - · exact e.erase_length.trans (by omega) - · intro z hz hzI - have hr := w.interior_mem_raw hzI - have he := labelLeftEscape_raw_intersection G J L m γ hinj hγ ξ.reverse hright z - (e.erase_support.subset hz) ((labelRaw_reverse_vertices G J L m γ hγ ξ z).mpr hr) - change z = w.endpoint at he - apply w.endpoint_not_interior - simpa only [he] using hzI - -end EscapeGeometry -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SelectedLabelMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - - - -theorem rooted_selected_label_mass_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (p : unitInterval) (hA : HasKernel G p A) - (J L m : ℕ) (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) (J+J)) - (x : V) (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) (hρ : ‖P‖ < 1) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (segmentPositiveIndex J i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s (Fin.last (J+J))) (s (segmentNegativeIndex J i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (Fin.last (J+J)))) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (t : ℝ) (ht : 0 < t) : - 1 - (4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + - 2*((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)*Real.sqrt c*‖P‖^m)/t + - 2*c*(((d+1)^2:ℕ):ℝ)*Real.sqrt c*‖P‖^L) ≤ - ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, - if (labelCorridor G J L m γ hγ ξ.1).Selected hloc p (J+m) t then - escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0 := by - let F := spineNeighborhood G hloc J L - let μ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => - escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 - let B₁ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => - (labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m - (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.1 ∨ - labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m - (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.1.reverse) ∨ - labelPotentialFailure G p γ (Fin.last (J+J)) 0 L m F t ξ.1 - let B₂ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => - ξ.1.last (segmentCenter J) ∈ reachBall G x 2 - have hb := rooted_label_collision_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin - P A hpos hsym hP hdiag p hA γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x hx hρ - J (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) hsep F - ((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)) (spineNeighborhood_card_le G hloc d hd J L) t ht - have he := rooted_label_endpoint_ball_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hw hw1 hcov c hc hmin γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 - P hpos hsym hP hdiag m L x hx d hd 2 - have hs := (rooted_label_probability_hasSum G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ (J+J) hdiam - (segmentCenter J) (Fin.last (J+J)) 0 L m x hx).tsum_eq - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - let := finite_rootedEscapeLabels G hloc γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x - let := Fintype.ofFinite {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} - have hμ (ξ) : 0 ≤ μ ξ := escapeLabelProbability_nonneg G hloc a hK γ (J+J) hdiam - (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 - simp only [tsum_fintype] at hs hb he ⊢ - have hu := (finite_weighted_event_or μ hμ B₁ B₂).trans (add_le_add hb he) - have hl := finite_weighted_success_lower μ hs (fun ξ => B₁ ξ ∨ B₂ ξ) _ hu - apply hl.trans - apply Finset.sum_le_sum - intro ξ _ - by_cases h : B₁ ξ ∨ B₂ ξ - · simp only [h,not_true_eq_false,ite_false] - split_ifs <;> first | exact hμ ξ | rfl - · have h₁ := not_or.mp (not_or.mp h).1 - have h₂ := not_or.mp h₁.1 - have hdist : ξ.1.last (segmentCenter J) ∉ reachBall G (ξ.1.first (segmentCenter J)) 2 := by - simpa only [ξ.2] using (not_or.mp h).2 - have hsel := selected_of_good_label G hloc J L m γ hinj hγ ξ.1 p t h₂.1 h₂.2 hdist h₁.2 - simp only [h,not_false_eq_true,hsel,ite_true] - exact le_rfl - -end SelectedLabelMass -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SelectedRawMass -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem rootedEscapeLabelRaw_corridor (G : BondGraph V E) (J L m : ℕ) - (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : - (⟨x,rootedEscapeLabelRaw G J L m γ hγ x ξ⟩ : RawCorridor G ((J+L)+J)) = - labelCorridor G J L m γ hγ ξ.1 := by - rcases ξ with ⟨ξ,hξ⟩ - subst x - rfl - - - -theorem selected_raw_mass_of_label_mass (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) (J+J)) (x : V) - (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) - (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) - (p : unitInterval) (t b : ℝ) - (hb : b ≤ ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, - if (labelCorridor G J L m γ hγ ξ.1).Selected hloc p (J+m) t then - escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) : - b*(a^(J+J)*q) ≤ ∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x, - if RawCorridor.Selected hloc p (J+m) t (⟨x,w⟩ : RawCorridor G ((J+L)+J)) then - w.2.mass (walkKernel G hloc a) else 0 := by - have hh := rooted_label_raw_event_bound G hloc a ha hK J L m γ hγ (J+J) hdiam x hx - q hq hqle (fun w => RawCorridor.Selected hloc p (J+m) t (⟨x,w⟩ : RawCorridor G ((J+L)+J))) - simp only [rootedEscapeLabelRaw_corridor] at hh - exact (le_div_iff₀ (mul_pos (pow_pos ha _) hq)).mp (hb.trans hh) - -end SelectedRawMass - -section FullSelectionCutoffs - - -theorem exists_full_selection_cutoffs (ρ c d τ : ℝ) - (hρ : 0 < ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hd : 0 ≤ d) (hτ : 0 < τ) : - ∃ J : ℕ, 0 < J ∧ ∃ C₁ : ℝ, 0 < C₁ ∧ ∃ k₀ : ℕ, J+J ≤ k₀ ∧ - ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → - 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^(k-(J+J))) + - 2*((3*d+3)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) + - 2*c*(d+1)^2*Real.sqrt c*ρ^(k-(J+J)) ≤ 1/2 := by - obtain ⟨J,hJ,L₀,C₁,hC₁,_,k₀,hk₀,hk⟩ := - exists_joint_collision_potential_cutoffs ρ c (3*d+2) τ hρ hρ1 hc (by linarith) hτ - have ht : Filter.Tendsto (fun L : ℕ => 2*c*(d+1)^2*Real.sqrt c*ρ^L) Filter.atTop (nhds 0) := by - simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hρ.le hρ1).const_mul - (2*c*(d+1)^2*Real.sqrt c) - obtain ⟨L₁,hL₁⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds (show (0:ℝ) < 1/8 by norm_num))) - refine ⟨J,hJ,C₁,hC₁,max k₀ (J+J+L₁),by omega,fun k hk' R hR => ?_⟩ - have h₁ := hk k (le_trans (le_max_left _ _) hk') R hR - have h₂ := hL₁ (k-(J+J)) (by omega) - have he : 3*d+2+1 = 3*d+3 := by ring - rw [he] at h₁ - linarith -end FullSelectionCutoffs -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FullPathSelection -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - - - -theorem exists_selected_path_mass [Countable V] [Countable E] [Infinite V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (τ : ℝ) (hτ : 0 < τ) : - ∃ J : ℕ, ∃ C₁ : ℝ, ∃ k₀ : ℕ, ∃ b : ℝ, - 0 < J ∧ 0 < C₁ ∧ 3 ≤ k₀ ∧ 0 < b ∧ - ∀ p : unitInterval, (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → - b ≤ rawPathAverage G (walkKernel G hloc a) k root weight - (fun w => if w.Selected hloc p (J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊) (τ/R) then 1 else 0) := by - let x₀ : V := Classical.arbitrary V - have hρpos : 0 < ‖P‖ := by - have hh := (hdiag x₀).trans ((Complex.re_le_norm _).trans (matrixCoeff_norm_le P x₀ x₀)) - linarith - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - obtain ⟨J,hJ,C₁,hC₁,k₀,hJk,hcut⟩ := exists_full_selection_cutoffs ‖P‖ c d τ hρpos hρ hc (Nat.cast_nonneg d) hτ - obtain ⟨y,q,hqN,hq⟩ := exists_geodesic_length G hloc hconn x₀ (J+J) - let γ := geodesicSegment G q (J+J) - have hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ) := - fun i => geodesicSegment_adj G q (J+J) hqN i.val i.isLt - have hinj : Function.Injective γ := geodesicSegment_injective G q (J+J) hqN hq - have hdiam := geodesicSegment_diameter G q (J+J) hqN - have hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (segmentPositiveIndex J i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s (Fin.last (J+J))) (s (segmentNegativeIndex J i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (Fin.last (J+J))) := by - rintro s ⟨g,e,hge,rfl⟩ - constructor - · intro i - change J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert 0)) (g (q.getVert (J+i.val))) - rw [graph_dist_aut G hconn hge,geodesic_getVert_dist _ q hq 0 (J+i.val) (by omega) (by omega)] - omega - constructor - · intro i - change J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert (J+J))) (g (q.getVert i.val)) - rw [graph_dist_aut G hconn hge,SimpleGraph.dist_comm, - geodesic_getVert_dist _ q hq i.val (J+J) (by omega) (by omega)] - omega - · change 2*J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert 0)) (g (q.getVert (J+J))) - rw [graph_dist_aut G hconn hge,geodesic_getVert_dist _ q hq 0 (J+J) (by omega) (by omega)] - omega - obtain ⟨i,g,hg,hgx⟩ := hcov (γ (segmentCenter J)) - obtain ⟨e,he⟩ := hg - have hx : root i ∈ vertexOrbit G (γ (segmentCenter J)) := - ⟨g.symm,e.symm,isAut_symm G he,by rw [←hgx,g.symm_apply_apply]⟩ - let b : ℝ := weight i * ((1/2)*(a^(J+J)*(1/(2*c)))) - have hb : 0 < b := mul_pos (hw i) (mul_pos (by norm_num) - (mul_pos (pow_pos ha _) (by positivity))) - refine ⟨J,C₁,max k₀ 3,b,hJ,hC₁,le_max_right _ _,hb,?_⟩ - intro p _hpnear hp k hk R hR - have hk₀ : k₀ ≤ k := (le_max_left _ _).trans hk - have hJk' : J+J ≤ k := hJk.trans hk₀ - obtain ⟨L,rfl⟩ : ∃ L : ℕ, (J+L)+J = k := ⟨k-(J+J),by omega⟩ - let m' := ⌈C₁*Real.log ((((((J+L)+J):ℕ):ℝ)+1)*R)⌉₊ - obtain ⟨A,hA⟩ := operatorBounded_of_lt_pc G hloc hqt p hp - have hcost := hcut ((J+L)+J) hk₀ R hR - have hL : (J+L)+J-(J+J) = L := by omega - rw [hL] at hcost - have hcost' : - 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + - 2*((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)*Real.sqrt c*‖P‖^m')/(τ/R) + - 2*c*(((d+1)^2:ℕ):ℝ)*Real.sqrt c*‖P‖^L ≤ 1/2 := by - simpa only [m',Nat.cast_pow,Nat.cast_add,Nat.cast_one] using hcost - have hl := rooted_selected_label_mass_lower G hloc a root weight htr hcov hw hw1 c hc hmin - P A hpos hsym hP hdiag p hA J L m' γ hinj hγ hdiam (root i) hx hρ hsep d hd (τ/R) - (div_pos hτ (lt_of_lt_of_le zero_lt_one hR)) - have hhalf : (1/2:ℝ) ≤ ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m' // ξ.first (segmentCenter J) = root i}, - if (labelCorridor G J L m' γ hγ ξ.1).Selected hloc p (J+m') (τ/R) then - escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m' ξ.1 else 0 := by - linarith - have hqreturn := segmentReturnMass_uniform_lower G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ (Fin.last (J+J)) L - have hmraw := selected_raw_mass_of_label_mass G hloc a ha hK J L m' γ hγ hdiam (root i) hx - (1/(2*c)) (by positivity) hqreturn p (τ/R) (1/2) hhalf - have hroot := mul_le_mul_of_nonneg_left hmraw (hw i).le - apply hroot.trans - unfold rawPathAverage - have hall (r : ι) : 0 ≤ weight r * ∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) (root r), - w.2.mass (walkKernel G hloc a) * - (if RawCorridor.Selected hloc p (J+m') (τ/R) ⟨root r,w⟩ then 1 else 0) := by - apply mul_nonneg (hw r).le - apply tsum_nonneg - intro w - apply mul_nonneg (w.2.mass_nonneg _ hK) - split_ifs <;> norm_num - have hi := Finset.single_le_sum (s := Finset.univ) (fun r _ => hall r) (Finset.mem_univ i) - simpa only [mul_ite,mul_one,mul_zero] using hi - -end FullPathSelection -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.SelectionBounds + +namespace OAI + +/-! Selection of geometrically separated paths from labelled escape events. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section EscapeGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace HoldingWalk +variable {H : SimpleGraph V} + +theorem mem_vertices_append {k l : ℕ} {x y z b : V} + (w : HoldingWalk H k x y) (v : HoldingWalk H l y z) : + b ∈ (w.append v).vertices ↔ b ∈ w.vertices ∨ b ∈ v.vertices := by + induction w with + | nil x => + have hx : x ∈ v.vertices := by simpa using v.position_mem_vertices 0 + simp only [append, vertices, List.mem_singleton] + exact ⟨fun h => Or.inr h, fun h => h.elim (fun he => he ▸ hx) id⟩ + | hold w ih => simp only [append, vertices, List.mem_cons, ih, or_assoc] + | step h w ih => simp only [append, vertices, List.mem_cons, ih, or_assoc] + +theorem mem_vertices_fromPositions (k : ℕ) (f : Fin (k+1) → V) + (h : ∀ i : Fin k, H.Adj (f i.castSucc) (f i.succ)) (b : V) : + b ∈ (fromPositions k f h).vertices ↔ ∃ i, f i = b := by + rw [mem_vertices_iff_position] + constructor + · rintro ⟨i, hi, he⟩ + exact ⟨⟨i,by omega⟩, (position_fromPositions k f h i hi).symm.trans he⟩ + · rintro ⟨i,hi⟩ + exact ⟨i.val,by omega,(position_fromPositions k f h i.val (by omega)).trans hi⟩ + +end HoldingWalk + + +def negativeStem (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) + (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) : + HoldingWalk H J (s (segmentCenter J)) (s 0) := + (HoldingWalk.fromPositions J (fun i => s ⟨i.val,by omega⟩) + (fun i => hs ⟨i.val,by omega⟩)).reverse + +theorem positiveStem_vertices (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) + (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) (z : V) : + z ∈ (positiveStem H J s hs).vertices ↔ ∃ i : Fin (J+1), s ⟨J+i.val,by omega⟩ = z := by + exact HoldingWalk.mem_vertices_fromPositions J _ _ z + +theorem negativeStem_vertices (H : SimpleGraph V) (J : ℕ) (s : Fin (J+J+1) → V) + (hs : ∀ i : Fin (J+J), H.Adj (s i.castSucc) (s i.succ)) (z : V) : + z ∈ (negativeStem H J s hs).vertices ↔ ∃ i : Fin (J+1), s ⟨i.val,by omega⟩ = z := by + let w := HoldingWalk.fromPositions J (fun i : Fin (J+1) => s ⟨i.val,by omega⟩) + (fun i : Fin J => hs ⟨i.val,by omega⟩) + have he : z ∈ w.reverse.vertices ↔ z ∈ w.vertices := by + rw [HoldingWalk.vertices_reverse, List.mem_reverse] + exact he.trans (HoldingWalk.mem_vertices_fromPositions J _ _ z) + + +def labelLeftEscape (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : + HoldingWalk (openSimpleGraph G Set.univ) (m+J) + (ξ.first (segmentCenter J)) ξ.leftTail.1 := + (negativeStem _ J ξ.first (orbitSegment_consecutive G J γ ξ.first hγ ξ.first_mem)).append ξ.leftTail.2 + + +def labelCorridor (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : RawCorridor G ((J+L)+J) := + ⟨ξ.first (segmentCenter J), ξ.last (segmentCenter J), escapeLabelRaw G J L m γ hγ ξ⟩ + +def segmentPositiveIndex (J : ℕ) : Fin (J+1) → Fin (J+J+1) := + fun i => ⟨J+i.val,by omega⟩ +def segmentNegativeIndex (J : ℕ) : Fin (J+1) → Fin (J+J+1) := + fun i => ⟨i.val,by omega⟩ + +theorem segmentOrbit_injective {I : Type*} (G : BondGraph V E) (γ s : I → V) + (hγ : Function.Injective γ) (hs : s ∈ segmentOrbit G γ) : Function.Injective s := by + obtain ⟨a,b,hab,rfl⟩ := hs + exact a.injective.comp hγ + + + +theorem labelLeftEscape_raw_intersection (G : BondGraph V E) (J L m : ℕ) + (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) + (hgood : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m + (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ) + (z : V) (hz : z ∈ (labelLeftEscape G J L m γ hγ ξ).vertices) + (hr : z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices) : + z = ξ.first (segmentCenter J) := by + have hfirst := segmentOrbit_injective G γ ξ.first hinj ξ.first_mem + have hfail := hgood + unfold labelFirstEscapeCollision firstEscapeCollision at hfail + have hraw : (∃ i : Fin (J+1), ξ.first (segmentPositiveIndex J i) = z) ∨ + z ∈ ξ.middle.vertices ∨ (∃ i : Fin (J+1), ξ.last (segmentPositiveIndex J i) = z) := by + simpa only [escapeLabelRaw, HoldingWalk.mem_vertices_append, + HoldingWalk.vertices_reverse, List.mem_reverse, positiveStem_vertices, + segmentPositiveIndex] using hr + have hleft : (∃ i : Fin (J+1), ξ.first (segmentNegativeIndex J i) = z) ∨ + z ∈ ξ.leftTail.2.vertices := by + simpa only [labelLeftEscape, HoldingWalk.mem_vertices_append, + negativeStem_vertices, segmentNegativeIndex] using hz + rcases hleft with ⟨i,hi⟩ | ht + · rcases hraw with ⟨j,hj⟩ | hm | ⟨j,hj⟩ + · have he := congrArg Fin.val (hfirst (hi.trans hj.symm)) + change i.val = J+j.val at he + have hiJ : i.val = J := by omega + rw [←hi] + congr 1 + apply Fin.ext + exact hiJ + · exact False.elim (hfail (Or.inl (Or.inl (Or.inr ⟨i,by simpa only [hi] using hm⟩)))) + · exact False.elim (hfail (Or.inr (Or.inl ⟨(j,i),hj.trans hi.symm⟩))) + · rcases hraw with ⟨i,hi⟩ | hm | ⟨i,hi⟩ + · exact False.elim (hfail (Or.inl (Or.inl (Or.inl ⟨i,by simpa only [hi] using ht⟩)))) + · exact False.elim (hfail (Or.inl (Or.inr ⟨z,ht,hm⟩))) + · obtain ⟨l,hl,he⟩ := ξ.leftTail.2.mem_vertices_iff_position.mp ht + exact False.elim (hfail (Or.inr (Or.inr ⟨(⟨l,by omega⟩,i),he.trans hi.symm⟩))) + + +theorem labelRaw_reverse_vertices (G : BondGraph V E) (J L m : ℕ) + (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (z : V) : + z ∈ (escapeLabelRaw G J L m γ hγ ξ.reverse).vertices ↔ + z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices := by + simp only [escapeLabelRaw, HoldingWalk.mem_vertices_append, + HoldingWalk.vertices_reverse, List.mem_reverse, EscapeLabel.reverse] + tauto + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +theorem interior_mem_raw (w : RawCorridor G k) {z : V} (hz : z ∈ w.interior) : + z ∈ w.2.2.vertices := by + have hp : z ∈ w.path.support := List.mem_toFinset.mp (Finset.mem_sdiff.mp hz).1 + exact w.2.2.erase_support.subset hp + + +noncomputable def neighborhood (hloc : LocallyFinite G) (w : RawCorridor G k) : Finset V := + w.interior ∪ w.interior.biUnion (neighbors G hloc) + +theorem coe_neighborhood (hloc : LocallyFinite G) (w : RawCorridor G k) : + (w.neighborhood hloc : Set V) = closedBondNeighborhood G (w.interior : Set V) := + (closedBondNeighborhood_finset G hloc w.interior).symm + + +def HasEscape (hloc : LocallyFinite G) (p : unitInterval) (j : ℕ) (t : ℝ) + (w : RawCorridor G k) (x : V) : Prop := + ∃ z, ∃ q : (openSimpleGraph G Set.univ).Walk x z, + q.IsPath ∧ q.length ≤ j ∧ (∀ v ∈ q.support, v ∉ w.interior) ∧ + (∑ b ∈ w.neighborhood hloc, twoPoint G p z b) ≤ t + + +def Selected (hloc : LocallyFinite G) (p : unitInterval) (j : ℕ) (t : ℝ) + (w : RawCorridor G k) : Prop := + 3 ≤ w.path.length ∧ w.HasEscape hloc p j t w.base ∧ w.HasEscape hloc p j t w.endpoint + +end RawCorridor + + + +noncomputable def spineVertices (G : BondGraph V E) (J L : ℕ) + (s : Fin (J+J+1) → V) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) + (h : Fin (J+J+1) → V) : Finset V := + Finset.univ.image (s ∘ segmentPositiveIndex J) ∪ mid.2.vertices.toFinset ∪ + Finset.univ.image (h ∘ segmentPositiveIndex J) + +noncomputable def spineNeighborhood (G : BondGraph V E) (hloc : LocallyFinite G) (J L : ℕ) + (s : Fin (J+J+1) → V) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) + (h : Fin (J+J+1) → V) : Finset V := + let W := spineVertices G J L s mid h + W ∪ W.biUnion (neighbors G hloc) + +theorem mem_spineVertices (G : BondGraph V E) (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (z : V) : + z ∈ spineVertices G J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last ↔ + z ∈ (escapeLabelRaw G J L m γ hγ ξ).vertices := by + simp only [spineVertices, Finset.mem_union, Finset.mem_image, Finset.mem_univ, + true_and, Function.comp_apply, List.mem_toFinset, escapeLabelRaw, + HoldingWalk.mem_vertices_append, HoldingWalk.vertices_reverse, List.mem_reverse, + positiveStem_vertices, segmentPositiveIndex] + tauto + +theorem labelCorridor_neighborhood_subset (G : BondGraph V E) (hloc : LocallyFinite G) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) : + (labelCorridor G J L m γ hγ ξ).neighborhood hloc ⊆ + spineNeighborhood G hloc J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last := by + have hi : (labelCorridor G J L m γ hγ ξ).interior ⊆ + spineVertices G J L ξ.first ⟨ξ.last (Fin.last (J+J)),ξ.middle⟩ ξ.last := by + intro z hz + exact (mem_spineVertices G J L m γ hγ ξ z).mpr + ((labelCorridor G J L m γ hγ ξ).interior_mem_raw hz) + exact Finset.union_subset_union hi (Finset.biUnion_subset_biUnion_of_subset_left _ hi) + +theorem neighborhood_card_le (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (W : Finset V) : + (W ∪ W.biUnion (neighbors G hloc)).card ≤ (d+1)*W.card := by + have hb : (W.biUnion (neighbors G hloc)).card ≤ W.card*d := + Finset.card_biUnion_le_card_mul _ _ _ + (fun x _ => (neighbors_card_le_degree G hloc x).trans (hd x)) + calc + _ ≤ W.card + (W.biUnion (neighbors G hloc)).card := Finset.card_union_le _ _ + _ ≤ W.card + W.card*d := Nat.add_le_add_left hb _ + _ = _ := by ring + +theorem spineVertices_card_le (G : BondGraph V E) (J L : ℕ) + (s : Fin (J+J+1) → V) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) + (h : Fin (J+J+1) → V) : + (spineVertices G J L s mid h).card ≤ ((J+L)+J)+3 := by + have h₁ : (Finset.univ.image (s ∘ segmentPositiveIndex J)).card ≤ J+1 := + (Finset.card_image_le).trans (by simp) + have h₂ : mid.2.vertices.toFinset.card ≤ L+1 := + (List.toFinset_card_le _).trans (le_of_eq mid.2.length_vertices) + have h₃ : (Finset.univ.image (h ∘ segmentPositiveIndex J)).card ≤ J+1 := + (Finset.card_image_le).trans (by simp) + have hauto := (Finset.card_union_le + (Finset.univ.image (s ∘ segmentPositiveIndex J)) mid.2.vertices.toFinset) + have hauto' := (Finset.card_union_le + (Finset.univ.image (s ∘ segmentPositiveIndex J) ∪ mid.2.vertices.toFinset) + (Finset.univ.image (h ∘ segmentPositiveIndex J))) + unfold spineVertices + omega + +theorem spineNeighborhood_card_le (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (J L : ℕ) + (s : Fin (J+J+1) → V) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s (Fin.last (J+J)))) + (h : Fin (J+J+1) → V) : + ((spineNeighborhood G hloc J L s mid h).card : ℝ) ≤ + (3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1) := by + have hn := neighborhood_card_le G hloc d hd (spineVertices G J L s mid h) + have hs := spineVertices_card_le G J L s mid h + have hb : (spineNeighborhood G hloc J L s mid h).card ≤ (d+1)*(((J+L)+J)+3) := + hn.trans (Nat.mul_le_mul_left _ hs) + have hb' : ((spineNeighborhood G hloc J L s mid h).card : ℝ) ≤ + ((d:ℝ)+1)*((((J+L)+J):ℕ)+3) := by exact_mod_cast hb + have hk : (0:ℝ) ≤ (((J+L)+J):ℕ) := Nat.cast_nonneg _ + nlinarith [show (0:ℝ) ≤ (d:ℝ) from Nat.cast_nonneg d] + + + +theorem selected_of_good_label (G : BondGraph V E) (hloc : LocallyFinite G) + (J L m : ℕ) (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m) (p : unitInterval) (t : ℝ) + (hleft : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m + (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ) + (hright : ¬labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m + (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.reverse) + (hdist : ξ.last (segmentCenter J) ∉ reachBall G (ξ.first (segmentCenter J)) 2) + (hpot : ¬labelPotentialFailure G p γ (Fin.last (J+J)) 0 L m + (spineNeighborhood G hloc J L) t ξ) : + (labelCorridor G J L m γ hγ ξ).Selected hloc p (J+m) t := by + let w := labelCorridor G J L m γ hγ ξ + have hlength : 3 ≤ w.path.length := by + by_contra h + have hx : w.endpoint ∈ reachBall G w.base w.path.length := by + simpa only [Nat.zero_add] using walk_mem_reachBall G Set.univ w.path 0 rfl + exact hdist (reachBall_mono_local G w.base (by omega : w.path.length ≤ 2) hx) + have hn := labelCorridor_neighborhood_subset G hloc J L m γ hγ ξ + have hp := not_or.mp hpot + have hp₁ : (∑ b ∈ w.neighborhood hloc, twoPoint G p ξ.leftTail.1 b) ≤ t := by + apply le_trans (Finset.sum_le_sum_of_subset_of_nonneg hn (fun b _ _ => twoPoint_nonneg G p _ b)) + exact le_of_not_gt hp.1 + have hp₂ : (∑ b ∈ w.neighborhood hloc, twoPoint G p ξ.rightTail.1 b) ≤ t := by + apply le_trans (Finset.sum_le_sum_of_subset_of_nonneg hn (fun b _ _ => twoPoint_nonneg G p _ b)) + exact le_of_not_gt hp.2 + refine ⟨hlength, ?_, ?_⟩ + · let e := labelLeftEscape G J L m γ hγ ξ + refine ⟨ξ.leftTail.1, e.erase, e.erase_isPath, ?_, ?_, hp₁⟩ + · exact e.erase_length.trans (by omega) + · intro z hz hzI + have hr := w.interior_mem_raw hzI + have he := labelLeftEscape_raw_intersection G J L m γ hinj hγ ξ hleft z + (e.erase_support.subset hz) hr + change z = w.base at he + apply w.base_not_interior + simpa only [he] using hzI + · let e := labelLeftEscape G J L m γ hγ ξ.reverse + refine ⟨ξ.rightTail.1, e.erase, e.erase_isPath, ?_, ?_, hp₂⟩ + · exact e.erase_length.trans (by omega) + · intro z hz hzI + have hr := w.interior_mem_raw hzI + have he := labelLeftEscape_raw_intersection G J L m γ hinj hγ ξ.reverse hright z + (e.erase_support.subset hz) ((labelRaw_reverse_vertices G J L m γ hγ ξ z).mpr hr) + change z = w.endpoint at he + apply w.endpoint_not_interior + simpa only [he] using hzI + +end EscapeGeometry +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SelectedLabelMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + + + +theorem rooted_selected_label_mass_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (p : unitInterval) (hA : HasKernel G p A) + (J L m : ℕ) (γ : Fin (J+J+1) → V) (hinj : Function.Injective γ) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) (J+J)) + (x : V) (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) (hρ : ‖P‖ < 1) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (segmentPositiveIndex J i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s (Fin.last (J+J))) (s (segmentNegativeIndex J i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (Fin.last (J+J)))) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (t : ℝ) (ht : 0 < t) : + 1 - (4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + + 2*((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)*Real.sqrt c*‖P‖^m)/t + + 2*c*(((d+1)^2:ℕ):ℝ)*Real.sqrt c*‖P‖^L) ≤ + ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, + if (labelCorridor G J L m γ hγ ξ.1).Selected hloc p (J+m) t then + escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0 := by + let F := spineNeighborhood G hloc J L + let μ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => + escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 + let B₁ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => + (labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m + (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.1 ∨ + labelFirstEscapeCollision G γ (Fin.last (J+J)) 0 J L m + (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) ξ.1.reverse) ∨ + labelPotentialFailure G p γ (Fin.last (J+J)) 0 L m F t ξ.1 + let B₂ := fun ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} => + ξ.1.last (segmentCenter J) ∈ reachBall G x 2 + have hb := rooted_label_collision_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin + P A hpos hsym hP hdiag p hA γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x hx hρ + J (segmentPositiveIndex J) (segmentNegativeIndex J) (segmentPositiveIndex J) hsep F + ((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)) (spineNeighborhood_card_le G hloc d hd J L) t ht + have he := rooted_label_endpoint_ball_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hw hw1 hcov c hc hmin γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 + P hpos hsym hP hdiag m L x hx d hd 2 + have hs := (rooted_label_probability_hasSum G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ (J+J) hdiam + (segmentCenter J) (Fin.last (J+J)) 0 L m x hx).tsum_eq + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + let := finite_rootedEscapeLabels G hloc γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x + let := Fintype.ofFinite {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} + have hμ (ξ) : 0 ≤ μ ξ := escapeLabelProbability_nonneg G hloc a hK γ (J+J) hdiam + (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 + simp only [tsum_fintype] at hs hb he ⊢ + have hu := (finite_weighted_event_or μ hμ B₁ B₂).trans (add_le_add hb he) + have hl := finite_weighted_success_lower μ hs (fun ξ => B₁ ξ ∨ B₂ ξ) _ hu + apply hl.trans + apply Finset.sum_le_sum + intro ξ _ + by_cases h : B₁ ξ ∨ B₂ ξ + · simp only [h,not_true_eq_false,ite_false] + split_ifs <;> first | exact hμ ξ | rfl + · have h₁ := not_or.mp (not_or.mp h).1 + have h₂ := not_or.mp h₁.1 + have hdist : ξ.1.last (segmentCenter J) ∉ reachBall G (ξ.1.first (segmentCenter J)) 2 := by + simpa only [ξ.2] using (not_or.mp h).2 + have hsel := selected_of_good_label G hloc J L m γ hinj hγ ξ.1 p t h₂.1 h₂.2 hdist h₁.2 + simp only [h,not_false_eq_true,hsel,ite_true] + exact le_rfl + +end SelectedLabelMass +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SelectedRawMass +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem rootedEscapeLabelRaw_corridor (G : BondGraph V E) (J L m : ℕ) + (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (x : V) (ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}) : + (⟨x,rootedEscapeLabelRaw G J L m γ hγ x ξ⟩ : RawCorridor G ((J+L)+J)) = + labelCorridor G J L m γ hγ ξ.1 := by + rcases ξ with ⟨ξ,hξ⟩ + subst x + rfl + + + +theorem selected_raw_mass_of_label_mass (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) (J+J)) (x : V) + (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) + (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) + (p : unitInterval) (t b : ℝ) + (hb : b ≤ ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, + if (labelCorridor G J L m γ hγ ξ.1).Selected hloc p (J+m) t then + escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) : + b*(a^(J+J)*q) ≤ ∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x, + if RawCorridor.Selected hloc p (J+m) t (⟨x,w⟩ : RawCorridor G ((J+L)+J)) then + w.2.mass (walkKernel G hloc a) else 0 := by + have hh := rooted_label_raw_event_bound G hloc a ha hK J L m γ hγ (J+J) hdiam x hx + q hq hqle (fun w => RawCorridor.Selected hloc p (J+m) t (⟨x,w⟩ : RawCorridor G ((J+L)+J))) + simp only [rootedEscapeLabelRaw_corridor] at hh + exact (le_div_iff₀ (mul_pos (pow_pos ha _) hq)).mp (hb.trans hh) + +end SelectedRawMass + +section FullSelectionCutoffs + + +theorem exists_full_selection_cutoffs (ρ c d τ : ℝ) + (hρ : 0 < ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hd : 0 ≤ d) (hτ : 0 < τ) : + ∃ J : ℕ, 0 < J ∧ ∃ C₁ : ℝ, 0 < C₁ ∧ ∃ k₀ : ℕ, J+J ≤ k₀ ∧ + ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → + 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^(k-(J+J))) + + 2*((3*d+3)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) + + 2*c*(d+1)^2*Real.sqrt c*ρ^(k-(J+J)) ≤ 1/2 := by + obtain ⟨J,hJ,L₀,C₁,hC₁,_,k₀,hk₀,hk⟩ := + exists_joint_collision_potential_cutoffs ρ c (3*d+2) τ hρ hρ1 hc (by linarith) hτ + have ht : Filter.Tendsto (fun L : ℕ => 2*c*(d+1)^2*Real.sqrt c*ρ^L) Filter.atTop (nhds 0) := by + simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hρ.le hρ1).const_mul + (2*c*(d+1)^2*Real.sqrt c) + obtain ⟨L₁,hL₁⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds (show (0:ℝ) < 1/8 by norm_num))) + refine ⟨J,hJ,C₁,hC₁,max k₀ (J+J+L₁),by omega,fun k hk' R hR => ?_⟩ + have h₁ := hk k (le_trans (le_max_left _ _) hk') R hR + have h₂ := hL₁ (k-(J+J)) (by omega) + have he : 3*d+2+1 = 3*d+3 := by ring + rw [he] at h₁ + linarith +end FullSelectionCutoffs +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FullPathSelection +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + + + +theorem exists_selected_path_mass [Countable V] [Countable E] [Infinite V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (a : ℝ) (ha : 0 < a) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (τ : ℝ) (hτ : 0 < τ) : + ∃ J : ℕ, ∃ C₁ : ℝ, ∃ k₀ : ℕ, ∃ b : ℝ, + 0 < J ∧ 0 < C₁ ∧ 3 ≤ k₀ ∧ 0 < b ∧ + ∀ p : unitInterval, (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → + b ≤ rawPathAverage G (walkKernel G hloc a) k root weight + (fun w => if w.Selected hloc p (J+⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊) (τ/R) then 1 else 0) := by + let x₀ : V := Classical.arbitrary V + have hρpos : 0 < ‖P‖ := by + have hh := (hdiag x₀).trans ((Complex.re_le_norm _).trans (matrixCoeff_norm_le P x₀ x₀)) + linarith + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + obtain ⟨J,hJ,C₁,hC₁,k₀,hJk,hcut⟩ := exists_full_selection_cutoffs ‖P‖ c d τ hρpos hρ hc (Nat.cast_nonneg d) hτ + obtain ⟨y,q,hqN,hq⟩ := exists_geodesic_length G hloc hconn x₀ (J+J) + let γ := geodesicSegment G q (J+J) + have hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ) := + fun i => geodesicSegment_adj G q (J+J) hqN i.val i.isLt + have hinj : Function.Injective γ := geodesicSegment_injective G q (J+J) hqN hq + have hdiam := geodesicSegment_diameter G q (J+J) hqN + have hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (segmentPositiveIndex J i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s (Fin.last (J+J))) (s (segmentNegativeIndex J i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s 0) (s (Fin.last (J+J))) := by + rintro s ⟨g,e,hge,rfl⟩ + constructor + · intro i + change J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert 0)) (g (q.getVert (J+i.val))) + rw [graph_dist_aut G hconn hge,geodesic_getVert_dist _ q hq 0 (J+i.val) (by omega) (by omega)] + omega + constructor + · intro i + change J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert (J+J))) (g (q.getVert i.val)) + rw [graph_dist_aut G hconn hge,SimpleGraph.dist_comm, + geodesic_getVert_dist _ q hq i.val (J+J) (by omega) (by omega)] + omega + · change 2*J ≤ (openSimpleGraph G Set.univ).dist (g (q.getVert 0)) (g (q.getVert (J+J))) + rw [graph_dist_aut G hconn hge,geodesic_getVert_dist _ q hq 0 (J+J) (by omega) (by omega)] + omega + obtain ⟨i,g,hg,hgx⟩ := hcov (γ (segmentCenter J)) + obtain ⟨e,he⟩ := hg + have hx : root i ∈ vertexOrbit G (γ (segmentCenter J)) := + ⟨g.symm,e.symm,isAut_symm G he,by rw [←hgx,g.symm_apply_apply]⟩ + let b : ℝ := weight i * ((1/2)*(a^(J+J)*(1/(2*c)))) + have hb : 0 < b := mul_pos (hw i) (mul_pos (by norm_num) + (mul_pos (pow_pos ha _) (by positivity))) + refine ⟨J,C₁,max k₀ 3,b,hJ,hC₁,le_max_right _ _,hb,?_⟩ + intro p _hpnear hp k hk R hR + have hk₀ : k₀ ≤ k := (le_max_left _ _).trans hk + have hJk' : J+J ≤ k := hJk.trans hk₀ + obtain ⟨L,rfl⟩ : ∃ L : ℕ, (J+L)+J = k := ⟨k-(J+J),by omega⟩ + let m' := ⌈C₁*Real.log ((((((J+L)+J):ℕ):ℝ)+1)*R)⌉₊ + obtain ⟨A,hA⟩ := operatorBounded_of_lt_pc G hloc hqt p hp + have hcost := hcut ((J+L)+J) hk₀ R hR + have hL : (J+L)+J-(J+J) = L := by omega + rw [hL] at hcost + have hcost' : + 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + + 2*((3*(d:ℝ)+3)*((((J+L)+J):ℕ)+1)*Real.sqrt c*‖P‖^m')/(τ/R) + + 2*c*(((d+1)^2:ℕ):ℝ)*Real.sqrt c*‖P‖^L ≤ 1/2 := by + simpa only [m',Nat.cast_pow,Nat.cast_add,Nat.cast_one] using hcost + have hl := rooted_selected_label_mass_lower G hloc a root weight htr hcov hw hw1 c hc hmin + P A hpos hsym hP hdiag p hA J L m' γ hinj hγ hdiam (root i) hx hρ hsep d hd (τ/R) + (div_pos hτ (lt_of_lt_of_le zero_lt_one hR)) + have hhalf : (1/2:ℝ) ≤ ∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m' // ξ.first (segmentCenter J) = root i}, + if (labelCorridor G J L m' γ hγ ξ.1).Selected hloc p (J+m') (τ/R) then + escapeLabelProbability G hloc a γ (J+J) hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m' ξ.1 else 0 := by + linarith + have hqreturn := segmentReturnMass_uniform_lower G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ (Fin.last (J+J)) L + have hmraw := selected_raw_mass_of_label_mass G hloc a ha hK J L m' γ hγ hdiam (root i) hx + (1/(2*c)) (by positivity) hqreturn p (τ/R) (1/2) hhalf + have hroot := mul_le_mul_of_nonneg_left hmraw (hw i).le + apply hroot.trans + unfold rawPathAverage + have hall (r : ι) : 0 ≤ weight r * ∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) (root r), + w.2.mass (walkKernel G hloc a) * + (if RawCorridor.Selected hloc p (J+m') (τ/R) ⟨root r,w⟩ then 1 else 0) := by + apply mul_nonneg (hw r).le + apply tsum_nonneg + intro w + apply mul_nonneg (w.2.mass_nonneg _ hK) + split_ifs <;> norm_num + have hi := Finset.single_le_sum (s := Finset.univ) (fun r _ => hall r) (Finset.mem_univ i) + simpa only [mul_ite,mul_one,mul_zero] using hi + +end FullPathSelection +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Escape/PositiveEscapes.lean b/lean/OAI/Probability/UnimodularPercolation/Escape/PositiveEscapes.lean index 0d57d840b58800a484f9cc4bcd179d6ac6d61bfa..f3769f2fe8151c0a4fd94f4f35415dc0c0995f30 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Escape/PositiveEscapes.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Escape/PositiveEscapes.lean @@ -1,1221 +1,1221 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.CollisionTails - -namespace OAI - -/-! Positive Escapes for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -section DependentFiniteUnion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_dependent_event_union {β δ : Type*} [Fintype β] [Fintype δ] - {γ : β → Type*} [∀ b, Fintype (γ b)] - (μ : (b : β) → γ b → ℝ) (hμ : ∀ b c, 0 ≤ μ b c) - (B : (b : β) → γ b → δ → Prop) : - (∑ b, ∑ c, if ∃ d, B b c d then μ b c else 0) ≤ - ∑ d, ∑ b, ∑ c, if B b c d then μ b c else 0 := by - have hh := finite_nonnegative_event_union - (fun ξ : Sigma γ => μ ξ.1 ξ.2) - (fun ξ => hμ ξ.1 ξ.2) - (fun ξ : Sigma γ => B ξ.1 ξ.2) - simpa only [Fintype.sum_sigma] using hh - -end DependentFiniteUnion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualFinitePositionHits -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι S T : Type*} [Fintype I] [Fintype ι] [Fintype S] [Fintype T] - - - -theorem raw_anchor_finite_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (j : S → I) (z : T → V) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (L : ℕ) (y : V) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if ∃ st : S × T, h.val (j st.1) = z st.2 then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - (Fintype.card S : ℝ)*(Fintype.card T : ℝ)*Real.sqrt c*‖P‖^L := by - let (v : V) : Finite ((openSimpleGraph G Set.univ).neighborSet v) := finite_openSimpleGraph_neighbors G hloc v - let : Fintype (RawFrom (openSimpleGraph G Set.univ) L y) := Fintype.ofFinite _ - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - simp only [tsum_fintype] - have hu := finite_dependent_event_union - (β := RawFrom (openSimpleGraph G Set.univ) L y) - (γ := fun mid => segmentAnchors G hloc γ n hdiam ep mid.1) - (δ := S × T) - (fun mid _ => mid.2.mass (walkKernel G hloc a)/(segmentAnchors G hloc γ n hdiam ep (γ ep)).card) - (fun mid _ => div_nonneg (mid.2.mass_nonneg _ hK) (Nat.cast_nonneg _)) - (fun _ h st => h.val (j st.1) = z st.2) - apply hu.trans - calc - _ ≤ ∑ _st : S × T, Real.sqrt c*‖P‖^L := by - apply Finset.sum_le_sum - intro st _ - obtain ⟨H,hH,hHn⟩ := exists_anchoredPositionOperator_uniform G hloc root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep (j st.1) - simpa only [tsum_fintype] using raw_anchor_point_collision_bound G hloc a γ n hdiam ep (j st.1) - P H hpos hP hH (Real.sqrt c) hHn L y (z st.2) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,Nat.cast_mul,nsmul_eq_mul]; ring - -end ActualFinitePositionHits -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EarlyFiniteCollisions -attribute [local instance] Classical.propDecidable Classical.decEq -variable {S : Type*} [Fintype S] - - - -theorem raw_hits_distant_set_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) - (m J : ℕ) (x : V) (z : S → V) (hD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (z s)) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, - if ∃ s, z s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ - (Fintype.card S : ℝ)*‖P‖^J/(1-‖P‖) := by - let (v : V) : Finite ((openSimpleGraph G Set.univ).neighborSet v) := finite_openSimpleGraph_neighbors G hloc v - let : Fintype (RawFrom (openSimpleGraph G Set.univ) m x) := Fintype.ofFinite _ - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have he (w : RawFrom (openSimpleGraph G Set.univ) m x) : - (∃ s, z s ∈ w.2.vertices) ↔ ∃ si : S × Fin (m+1), w.2.position si.2.val = z si.1 := by - constructor - · rintro ⟨s,hs⟩ - obtain ⟨i,hi,he⟩ := w.2.mem_vertices_iff_position.mp hs - exact ⟨(s,⟨i,by omega⟩),he⟩ - · rintro ⟨⟨s,i⟩,he⟩ - exact ⟨s,he ▸ w.2.position_mem_vertices i.val⟩ - simp only [he,tsum_fintype] - have hu := finite_nonnegative_event_union - (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) - (fun w => w.2.mass_nonneg _ hK) - (fun w (si : S × Fin (m+1)) => w.2.position si.2.val = z si.1) - apply hu.trans - rw [Fintype.sum_prod_type] - calc - _ ≤ ∑ _s : S, ∑ i : Fin (m+1), if J ≤ i.val then ‖P‖^i.val else 0 := by - apply Finset.sum_le_sum - intro s _ - apply Finset.sum_le_sum - intro i _ - have hh := raw_position_probability G hloc a P hpos hP i.val m (by omega) x (z s) - simp only [tsum_fintype] at hh - rw [hh] - split_ifs with hi - · exact matrixCoeff_power_le P i.val x (z s) - · exact (walkPower_zero_of_lt_dist G hloc a P hpos hP i.val x (z s) (by have hd := hD s; omega)).le - _ ≤ ∑ _s : S, ‖P‖^J/(1-‖P‖) := Finset.sum_le_sum (fun _ _ => - finite_geometric_cutoff_bound ‖P‖ (norm_nonneg _) hρ J (m+1)) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring - -end EarlyFiniteCollisions -end Percolation - - -namespace Percolation -section QuantitativeEarlyCutoff - - - -noncomputable def earlyCollisionCost (ρ : ℝ) (J : ℕ) : ℝ := - 2*((J:ℝ)+1)*ρ^J/(1-ρ) + 2*ρ^J/(1-ρ)^2 - -theorem earlyCollisionCost_tendsto (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) : - Filter.Tendsto (earlyCollisionCost ρ) Filter.atTop (nhds 0) := by - have hn : ‖ρ‖ < 1 := by simpa only [Real.norm_eq_abs,abs_of_nonneg hρ] using hρ1 - have ht : Filter.Tendsto (fun J : ℕ => (J:ℝ)*ρ^J) Filter.atTop (nhds 0) := by - simpa only [pow_one] using (summable_pow_mul_geometric_of_norm_lt_one 1 hn).tendsto_atTop_zero - have hp := tendsto_pow_atTop_nhds_zero_of_lt_one hρ hρ1 - have hh := (((ht.add hp).const_mul 2).div_const (1-ρ)).add ((hp.const_mul 2).div_const ((1-ρ)^2)) - have he : earlyCollisionCost ρ = (fun J : ℕ => 2*((J:ℝ)*ρ^J+ρ^J)/(1-ρ)+2*ρ^J/(1-ρ)^2) := by - funext J - unfold earlyCollisionCost - ring - rw [he] - simpa only [zero_add,mul_zero,zero_div] using hh - -theorem exists_earlyCollisionCutoff (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (ε : ℝ) (hε : 0 < ε) : - ∃ J₀ : ℕ, ∀ J : ℕ, J₀ ≤ J → earlyCollisionCost ρ J < ε := by - exact Filter.eventually_atTop.mp ((earlyCollisionCost_tendsto ρ hρ hρ1).eventually (gt_mem_nhds hε)) - -end QuantitativeEarlyCutoff -end Percolation - - -namespace Percolation -section WeightedBinaryUnion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_weighted_event_or {α : Type*} [Fintype α] - (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (B C : α → Prop) [DecidablePred B] [DecidablePred C] : - (∑ a, if B a ∨ C a then μ a else 0) ≤ - (∑ a, if B a then μ a else 0) + ∑ a, if C a then μ a else 0 := by - rw [←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro a _ - by_cases hb : B a <;> by_cases hc : C a <;> simp only [hb,hc,or_self,or_false,false_or,ite_true,ite_false,add_zero,zero_add,le_refl] - exact le_add_of_nonneg_right (hμ a) - -end WeightedBinaryUnion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ActualEarlyExperiment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem raw_early_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) - (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) - (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) - (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, - if ((∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices)) ∨ - (∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ - earlyCollisionCost ‖P‖ J := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let : Fintype (RawFrom (openSimpleGraph G Set.univ) m x) := Fintype.ofFinite _ - let : Fintype (RawFrom (openSimpleGraph G Set.univ) L y) := Fintype.ofFinite _ - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hu := finite_weighted_event_or - (fun w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y => - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a)) - (fun w => mul_nonneg (w.1.2.mass_nonneg _ hK) (w.2.2.mass_nonneg _ hK)) - (fun w => (∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices)) - (fun w => ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) - have hp := finite_product_failure_union - (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) - (fun w : RawFrom (openSimpleGraph G Set.univ) L y => w.2.mass (walkKernel G hloc a)) - (fun w => w.2.mass_nonneg _ hK) (fun w => w.2.mass_nonneg _ hK) - (by simpa only [tsum_fintype] using rawFrom_probability_sum G hloc a m x) - (by simpa only [tsum_fintype] using rawFrom_probability_sum G hloc a L y) - (fun w => ∃ s, pos s ∈ w.2.vertices) (fun w => ∃ s, neg s ∈ w.2.vertices) - have hx := raw_hits_distant_set_bound G hloc a P hpos hP hρ m J x pos hposD - have hy := raw_hits_distant_set_bound G hloc a P hpos hP hρ L J y neg hnegD - have hi := raw_intersection_uniform_bound G hloc a P hpos hsym hP hρ m L J x y hxy - simp only [tsum_fintype,Fintype.card_fin,Nat.cast_add,Nat.cast_one] at hx hy hi ⊢ - have hx' : (∑ w : RawFrom (openSimpleGraph G Set.univ) m x, - if ∃ s, pos s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ - ((J:ℝ)+1)*‖P‖^J/(1-‖P‖) := by - convert hx using 1 - apply Finset.sum_congr rfl - intro w _ - split_ifs <;> rfl - have hy' : (∑ w : RawFrom (openSimpleGraph G Set.univ) L y, - if ∃ s, neg s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ - ((J:ℝ)+1)*‖P‖^J/(1-‖P‖) := by - convert hy using 1 - apply Finset.sum_congr rfl - intro w _ - split_ifs <;> rfl - have hp' : (∑ w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, - if (∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices) then - w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ - (∑ w : RawFrom (openSimpleGraph G Set.univ) m x, - if ∃ s, pos s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) + - (∑ w : RawFrom (openSimpleGraph G Set.univ) L y, - if ∃ s, neg s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) := by - convert hp using 1 - · apply Finset.sum_congr rfl - intro w _ - split_ifs <;> rfl - · congr 1 <;> apply Finset.sum_congr rfl <;> intro w _ <;> split_ifs <;> rfl - have hr : (((J:ℝ)+1)*‖P‖^J/(1-‖P‖) + ((J:ℝ)+1)*‖P‖^J/(1-‖P‖)) + - 2*‖P‖^J/(1-‖P‖)^2 = earlyCollisionCost ‖P‖ J := by - unfold earlyCollisionCost - ring - have hh := hu.trans ((add_le_add (hp'.trans (add_le_add hx' hy')) hi).trans_eq hr) - exact hh - -end ActualEarlyExperiment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ConditioningCost -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem raw_anchor_event_le_unconditioned (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (m L : ℕ) (x y : V) - (B : RawFrom (openSimpleGraph G Set.univ) m x → RawFrom (openSimpleGraph G Set.univ) L y → Prop) [∀ tail mid, Decidable (B tail mid)] : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, - if B tail mid then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, - if B w.1 w.2 then w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - have hN : 0 < ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) := by - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep (γ ep)).mpr - ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) - simp only [tsum_fintype,Fintype.sum_prod_type] - apply Finset.sum_le_sum - intro tail _ - apply Finset.sum_le_sum - intro mid _ - by_cases hb : B tail mid - · simp only [ite_eq_left hb,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] - have hc : ((segmentAnchors G hloc γ n hdiam ep mid.1).card : ℝ) ≤ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card := by - rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] - split_ifs - · exact le_rfl - · exact_mod_cast Nat.zero_le _ - rw [←mul_div_assoc] - apply (div_le_iff₀ hN).mpr - have hh := mul_le_mul_of_nonneg_right hc - (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) - nlinarith - · simp only [ite_eq_right hb,Finset.sum_const_zero] - exact le_rfl - -end ConditioningCost -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EarlyAnchoredCollision -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem raw_anchor_early_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) - (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) - (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) - (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, - if ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ - (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices) then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - earlyCollisionCost ‖P‖ J := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - exact (raw_anchor_event_le_unconditioned G hloc a hK γ n hdiam ep m L x y - (fun tail mid => ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ - (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices))).trans - (raw_early_collision_bound G hloc a P hpos hsym hP hρ m L J x y pos neg hposD hnegD hxy) - - - -theorem raw_tail_integrate_anchor_event (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (m L : ℕ) (x y : V) - (B : (mid : RawFrom (openSimpleGraph G Set.univ) L y) → - segmentAnchors G hloc γ n hdiam ep mid.1 → Prop) [∀ mid h, Decidable (B mid h)] : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if B mid h then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if B mid h then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) := by - have he (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (h : segmentAnchors G hloc γ n hdiam ep mid.1) : - (if B mid h then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = - tail.2.mass (walkKernel G hloc a) * - (if B mid h then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) := by - split_ifs <;> ring - simp only [he,tsum_mul_left,tsum_mul_right,rawFrom_probability_sum G hloc a,one_mul] - -end EarlyAnchoredCollision -end Percolation - - -namespace Percolation -section DependentUnion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_threefold_event_or {α β : Type*} {γ : β → Type*} - [Fintype α] [Fintype β] [∀ b, Fintype (γ b)] - (μ : α → (b : β) → γ b → ℝ) (hμ : ∀ a b c, 0 ≤ μ a b c) - (B C : α → (b : β) → γ b → Prop) - [∀ a b c, Decidable (B a b c)] [∀ a b c, Decidable (C a b c)] : - (∑ a, ∑ b, ∑ c, if B a b c ∨ C a b c then μ a b c else 0) ≤ - (∑ a, ∑ b, ∑ c, if B a b c then μ a b c else 0) + - (∑ a, ∑ b, ∑ c, if C a b c then μ a b c else 0) := by - simp only [←Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro a _ - apply Finset.sum_le_sum - intro b _ - apply Finset.sum_le_sum - intro c _ - by_cases hb : B a b c <;> by_cases hc : C a b c <;> - simp only [hb,hc,or_self,or_false,false_or,ite_true,ite_false,add_zero,zero_add,le_refl] - exact le_add_of_nonneg_right (hμ a b c) - -end DependentUnion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CombinedRawAvoidance -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι : Type*} [Fintype I] [Fintype ι] - - - -def firstEscapeCollision (G : BondGraph V E) (J m L : ℕ) (x y : V) - (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) - (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) (h : I → V) : Prop := - (((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ - (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices)) ∨ - ((∃ st : Fin (J+1) × Fin (J+1), h (j st.1) = neg st.2) ∨ - (∃ ij : Fin (m+1) × Fin (J+1), tail.2.position ij.1.val = h (j ij.2))) - -noncomputable def suffixCollisionCost (ρ c : ℝ) (J : ℕ) : ℝ := - ((J:ℝ)+1)^2*Real.sqrt c + ((J:ℝ)+1)*Real.sqrt c/(1-ρ) - - - -theorem raw_first_escape_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) - (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) - (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) - (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if firstEscapeCollision G J m L x y pos neg j tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - let μ := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (_h : segmentAnchors G hloc γ n hdiam ep mid.1) => - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card - have hμ : ∀ tail mid h, 0 ≤ μ tail mid h := fun tail mid _ => - div_nonneg (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) (Nat.cast_nonneg _) - let B := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (_h : segmentAnchors G hloc γ n hdiam ep mid.1) => - ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ - (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices) - let C := fun (_tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (h : segmentAnchors G hloc γ n hdiam ep mid.1) => - ∃ st : Fin (J+1) × Fin (J+1), h.val (j st.1) = neg st.2 - let D := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (h : segmentAnchors G hloc γ n hdiam ep mid.1) => - ∃ ij : Fin (m+1) × Fin (J+1), tail.2.position ij.1.val = h.val (j ij.2) - have hu := finite_threefold_event_or μ hμ B (fun tail mid h => C tail mid h ∨ D tail mid h) - have hv := finite_threefold_event_or μ hμ C D - have he := raw_anchor_early_collision_bound G hloc a γ n hdiam ep P hpos hsym hP hρ - m L J x y pos neg hposD hnegD hxy - have hn := raw_anchor_finite_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep j neg P hpos hP L y - rw [←raw_tail_integrate_anchor_event G hloc a γ n hdiam ep m L x y - (fun _ h => ∃ st : Fin (J+1) × Fin (J+1), h.val (j st.1) = neg st.2)] at hn - have ht := raw_tail_whole_suffix_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep j P hpos hP hρ m L x y - simp only [tsum_fintype,Fintype.card_fin,Nat.cast_add,Nat.cast_one] at he hn ht ⊢ - have hr : earlyCollisionCost ‖P‖ J + - ((((J:ℝ)+1)*((J:ℝ)+1)*Real.sqrt c*‖P‖^L) + - ((J:ℝ)+1)*Real.sqrt c*‖P‖^L/(1-‖P‖)) = - earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by - unfold suffixCollisionCost - ring - have hh := hu.trans ((add_le_add he (hv.trans (add_le_add hn ht))).trans_eq hr) - apply le_trans ?_ hh - apply le_of_eq - apply Finset.sum_congr rfl - intro tail _ - apply Finset.sum_congr rfl - intro mid _ - apply Finset.sum_congr rfl - intro h _ - unfold firstEscapeCollision B C D μ - split_ifs <;> rfl - -end CombinedRawAvoidance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NormalizedFirstEscape -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι : Type*} [Fintype I] [Fintype ι] - - - -theorem conditional_first_escape_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x y : V) (hy : y ∈ vertexOrbit G (γ ep)) - (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) - (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) - (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) - (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if firstEscapeCollision G J m L x y pos neg j tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / - segmentReturnMass G hloc a γ ep L y ≤ - 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by - have hb := raw_first_escape_collision_bound G hloc a root weight Γ hΓ htr - (fun r => (hw r).le) hw1 hcov c hc.le hmin γ n hdiam ep P hpos hsym hP hρ - m L J x y pos neg j hposD hnegD hxy - have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ ep L - rw [←segmentReturnMass_on_orbit G hloc a γ ep L y hy P hpos hP] at hq - have htc : 0 < 2*c := mul_pos (by norm_num) hc - have hqp : 0 < segmentReturnMass G hloc a γ ep L y := (one_div_pos.mpr htc).trans_le hq - apply (div_le_iff₀ hqp).mpr - apply hb.trans - have hB : 0 ≤ earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by - unfold earlyCollisionCost suffixCollisionCost - have : 0 < 1-‖P‖ := sub_pos.mpr hρ - positivity - have h1 : 1 ≤ (2*c)*segmentReturnMass G hloc a γ ep L y := by - exact (div_le_iff₀ htc).mp hq |>.trans_eq (mul_comm _ _) - have hh := mul_le_mul_of_nonneg_right h1 hB - nlinarith only [hh] - -end NormalizedFirstEscape -end Percolation - - -namespace Percolation -section FirstEscapeChoiceOrder - - - -theorem exists_first_escape_uniform_cutoffs (ρ c ε : ℝ) - (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hε : 0 < ε) : - ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∀ L : ℕ, L₀ ≤ L → - 2*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L) < ε := by - have hδ : 0 < ε/(4*c) := div_pos hε (by positivity) - obtain ⟨J₀,hJ₀⟩ := exists_earlyCollisionCutoff ρ hρ hρ1 (ε/(4*c)) hδ - let J := max J₀ 1 - have hJ : 0 < J := lt_of_lt_of_le (by omega : 0 < 1) (le_max_right _ _) - have he : earlyCollisionCost ρ J < ε/(4*c) := hJ₀ J (le_max_left _ _) - have hel : 2*c*earlyCollisionCost ρ J < ε := by - have hh := (lt_div_iff₀ (by positivity : 0 < 4*c)).mp he - nlinarith - have ht : Filter.Tendsto - (fun L : ℕ => 2*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L)) - Filter.atTop (nhds (2*c*earlyCollisionCost ρ J)) := by - have hh := ((tendsto_pow_atTop_nhds_zero_of_lt_one hρ hρ1).const_mul - (suffixCollisionCost ρ c J)).const_add (earlyCollisionCost ρ J) - have hh' := hh.const_mul (2*c) - simpa only [mul_zero,add_zero] using hh' - obtain ⟨L₀,hL₀⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds hel)) - exact ⟨J,hJ,L₀,hL₀⟩ - -end FirstEscapeChoiceOrder -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralConditionalMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I : Type*} [Fintype I] - - - -theorem raw_tail_anchor_total_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (m L : ℕ) (x y : V) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card) = - segmentReturnMass G hloc a γ ep L y := by - have hN : ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) ≠ 0 := by - apply ne_of_gt - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep (γ ep)).mpr - ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) - have hh := raw_tail_integrate_anchor_event G hloc a γ n hdiam ep m L x y (fun _ _ => True) - simp only [ite_true] at hh - rw [hh] - unfold segmentReturnMass - apply tsum_congr - intro mid - simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] - rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] - split_ifs - · field_simp - · simp only [Nat.cast_zero,zero_mul] - - - -theorem raw_tail_anchor_conditional_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (m L : ℕ) (x y : V) (hq : segmentReturnMass G hloc a γ ep L y ≠ 0) : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card / - segmentReturnMass G hloc a γ ep L y) = 1 := by - have hh := raw_tail_anchor_total_mass G hloc a γ n hdiam ep m L x y - simp only [tsum_div_const] at hh ⊢ - rw [hh] - exact div_self hq - -end LiteralConditionalMass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralGeodesicSeparation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem graph_dist_aut (G : BondGraph V E) (hconn : Connected G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : - (openSimpleGraph G Set.univ).dist (a x) (a y) = - (openSimpleGraph G Set.univ).dist x y := by - have hreach (x y : V) : (openSimpleGraph G Set.univ).Reachable x y := - (conn_iff_reachable G Set.univ x y).mp (conn_univ_of_connected G hconn x y) - obtain ⟨q,hq⟩ := (hreach x y).exists_walk_length_eq_dist - obtain ⟨r,hr⟩ := (hreach (a x) (a y)).exists_walk_length_eq_dist - have hq' := SimpleGraph.dist_le (q.map (autSimpleGraph G hab).toHom) - have hr' := SimpleGraph.dist_le (r.map (autSimpleGraph G (isAut_symm G hab)).toHom) - simp only [SimpleGraph.Walk.length_map,hq] at hq' - change (openSimpleGraph G Set.univ).dist (a.symm (a x)) (a.symm (a y)) ≤ _ at hr' - simp only [a.symm_apply_apply,SimpleGraph.Walk.length_map,hr] at hr' - exact le_antisymm hq' hr' - - - -theorem geodesic_anchor_early_separations (G : BondGraph V E) (hconn : Connected G) - {x y : V} (q : (openSimpleGraph G Set.univ).Walk x y) (J : ℕ) - (hlen : q.length = 2*J) (hq : q.length = (openSimpleGraph G Set.univ).dist x y) - (s : Fin (2*J+1) → V) (hs : s ∈ segmentOrbit G (geodesicSegment G q (2*J))) : - (∀ i : Fin (J+1), J ≤ (openSimpleGraph G Set.univ).dist - (s ⟨0,by omega⟩) (s ⟨J+i.val,by omega⟩)) ∧ - (∀ i : Fin (J+1), J ≤ (openSimpleGraph G Set.univ).dist - (s ⟨2*J,by omega⟩) (s ⟨i.val,by omega⟩)) ∧ - (2*J ≤ (openSimpleGraph G Set.univ).dist (s ⟨0,by omega⟩) (s ⟨2*J,by omega⟩)) := by - obtain ⟨a,b,hab,rfl⟩ := hs - constructor - · intro i - dsimp only [Function.comp_apply,geodesicSegment] - rw [graph_dist_aut G hconn hab] - rw [geodesic_getVert_dist _ q hq 0 (J+i.val) (by omega) (by omega)] - omega - constructor - · intro i - dsimp only [Function.comp_apply,geodesicSegment] - rw [graph_dist_aut G hconn hab,SimpleGraph.dist_comm] - rw [geodesic_getVert_dist _ q hq i.val (2*J) (by omega) (by omega)] - omega - · dsimp only [Function.comp_apply,geodesicSegment] - rw [graph_dist_aut G hconn hab] - rw [geodesic_getVert_dist _ q hq 0 (2*J) (by omega) (by omega)] - omega - -end LiteralGeodesicSeparation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PositiveFirstEscape -attribute [local instance] Classical.propDecidable Classical.decEq -variable {I ι : Type*} [Fintype I] [Fintype ι] - - - -theorem exists_positive_first_escape (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x y : V) (hy : y ∈ vertexOrbit G (γ ep)) - (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) - (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) - (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) - (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) - (hsmall : 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) < 1) : - ∃ (tail : RawFrom (openSimpleGraph G Set.univ) m x) - (mid : RawFrom (openSimpleGraph G Set.univ) L y) - (h : segmentAnchors G hloc γ n hdiam ep mid.1), - ¬firstEscapeCollision G J m L x y pos neg j tail mid h.val ∧ - 0 < tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) := by - have hb := conditional_first_escape_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep P hpos hsym hP hdiag hρ m L J x y hy pos neg j hposD hnegD hxy - have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ ep L - rw [←segmentReturnMass_on_orbit G hloc a γ ep L y hy P hpos hP] at hq - have hqp : 0 < segmentReturnMass G hloc a γ ep L y := - (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - by_contra H - have heq : - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if firstEscapeCollision G J m L x y pos neg j tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = - ∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, - ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card := by - apply tsum_congr - intro tail - apply tsum_congr - intro mid - apply tsum_congr - intro h - split_ifs with ht - · rfl - · have hz : tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) = 0 := by - apply le_antisymm - · exact le_of_not_gt (fun hp => H ⟨tail,mid,h,ht,hp⟩) - · exact mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK) - rw [hz,zero_div] - rw [heq,raw_tail_anchor_total_mass G hloc a γ n hdiam ep m L x y,div_self hqp.ne'] at hb - exact (not_lt_of_ge hb) hsmall - -end PositiveFirstEscape -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ProjectionEvents -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finite_event_fiber_sum {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] - (f : α → β) (μ : α → ℝ) (B : β → Prop) [DecidablePred B] : - (∑ a, if B (f a) then μ a else 0) = - ∑ b, if B b then ∑ a, if f a = b then μ a else 0 else 0 := by - calc - _ = ∑ a, ∑ b, if B b then (if f a = b then μ a else 0) else 0 := by - apply Finset.sum_congr rfl - intro a _ - have hf : (fun b => if B b then (if f a = b then μ a else 0) else 0) = - fun b => if f a = b then (if B (f a) then μ a else 0) else 0 := by - funext b - by_cases h : f a = b - · subst b - simp - · simp [h] - rw [hf] - simp - _ = _ := by - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - by_cases h : B b <;> simp [h] - - - -theorem rooted_label_raw_event_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (J L m : ℕ) (γ : Fin (J+J+1) → V) - (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) - (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) - (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) - (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) - (B : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x → Prop) [DecidablePred B] : - (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, - if B (rootedEscapeLabelRaw G J L m γ hγ x ξ) then - escapeLabelProbability G hloc a γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) ≤ - (∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x, - if B w then w.2.mass (walkKernel G hloc a) else 0)/(a^(J+J)*q) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let := finite_rootedEscapeLabels G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x - let : Fintype {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} := Fintype.ofFinite _ - let : Fintype (RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) := Fintype.ofFinite _ - rw [←tsum_indicator_div] - simp only [tsum_fintype] - rw [finite_event_fiber_sum] - apply Finset.sum_le_sum - intro w _ - by_cases hw : B w - · simp only [hw,ite_true] - simpa only [tsum_fintype] using - rooted_label_raw_projection_bound G hloc a ha hK J L m γ hγ n hdiam x hx q hq hqle w - · simp only [hw,ite_false,le_refl] - -end ProjectionEvents -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section FirstLabeledMarginal -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - -def labelFirstEscapeCollision (G : BondGraph V E) (γ : I → V) (ep neg : I) - (J L m : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) - (ξ : EscapeLabel G γ ep neg L m) : Prop := - firstEscapeCollision G J m L (ξ.first neg) (ξ.first ep) - (fun t => ξ.first (posIdx t)) (fun t => ξ.first (negIdx t)) suffixIdx - ξ.leftTail ⟨ξ.last ep,ξ.middle⟩ ξ.last - -theorem labelFromCode_first_collision (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (J L m : ℕ) (x : V) - (posIdx negIdx suffixIdx : Fin (J+1) → I) - (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx - (labelFromCode G hloc γ n hdiam center ep neg L m x c).1 = - firstEscapeCollision G J m L (c.1.val neg) (c.1.val ep) - (fun t => c.1.val (posIdx t)) (fun t => c.1.val (negIdx t)) suffixIdx - c.2.2.2.1 c.2.1 c.2.2.1.val := by - rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ - obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - - - -theorem raw_rooted_first_collision_marginal (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (J L m : ℕ) (x : V) - (posIdx negIdx suffixIdx : Fin (J+1) → I) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then - ξ.1.mass (walkKernel G hloc a) else 0) = - ∑' s : segmentAnchors G hloc γ n hdiam center x, - ∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if firstEscapeCollision G J m L (s.val neg) (s.val ep) - (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) else 0 := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x - rw [←R.symm.tsum_eq] - simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass,labelFromCode_first_collision] - unfold RootedLabelCode at * - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - apply tsum_congr - intro s - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - have hh (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) : - (∑' hh : Σ h : segmentAnchors G hloc γ n hdiam ep mid.1, - RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - if firstEscapeCollision G J m L (s.val neg) (s.val ep) - (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx hh.2.1 mid hh.1.val then - mid.2.mass (walkKernel G hloc a)*hh.2.1.2.mass (walkKernel G hloc a)*hh.2.2.2.mass (walkKernel G hloc a) else 0) = - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - ∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), - if firstEscapeCollision G J m L (s.val neg) (s.val ep) - (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) else 0 := by - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] - apply tsum_congr - intro h - rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] - apply tsum_congr - intro tail - split_ifs - · simp only [tsum_mul_left,rawFrom_probability_sum G hloc a,mul_one] - exact mul_comm _ _ - · simp only [tsum_zero] - simp_rw [hh] - simp only [tsum_fintype] - conv_lhs => - arg 2 - intro mid - rw [Finset.sum_comm] - rw [Finset.sum_comm] - -end FirstLabeledMarginal -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section NormalizedMarginal -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - - -theorem rooted_first_collision_probability_marginal (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (J L m : ℕ) (x : V) - (posIdx negIdx suffixIdx : Fin (J+1) → I) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = - (∑' s : segmentAnchors G hloc γ n hdiam center x, - (∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if firstEscapeCollision G J m L (s.val neg) (s.val ep) - (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then - tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / - segmentReturnMass G hloc a γ ep L (γ ep)) / - (segmentAnchors G hloc γ n hdiam center (γ center)).card := by - simp only [escapeLabelProbability,tsum_indicator_div,tsum_div_const] - rw [raw_rooted_first_collision_marginal G hloc a γ n hdiam center ep neg J L m x posIdx negIdx suffixIdx] - ring - -end NormalizedMarginal -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section FullFirstEscapeBound -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - - -theorem rooted_first_collision_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (posIdx negIdx suffixIdx : Fin (J+1) → I) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by - rw [rooted_first_collision_probability_marginal G hloc a γ n hdiam center ep neg J L m x posIdx negIdx suffixIdx] - have hN : 0 < ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) := by - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam center (γ center)).mpr - ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) - apply (div_le_iff₀ hN).mpr - simp only [tsum_fintype] - calc - _ ≤ ∑ s : segmentAnchors G hloc γ n hdiam center x, - 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by - apply Finset.sum_le_sum - intro s _ - have hs := ((mem_segmentAnchors G hloc γ n hdiam center x s.val).mp s.property).1 - have hy : s.val ep ∈ vertexOrbit G (γ ep) := by - obtain ⟨g,b,hg,he⟩ := hs - rw [he] - exact ⟨g,b,hg,rfl⟩ - obtain ⟨hp,hn,hxy⟩ := hsep s.val hs - have hh := conditional_first_escape_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam ep P hpos hsym hP hdiag hρ m L J (s.val neg) (s.val ep) hy - (fun i => s.val (posIdx i)) (fun i => s.val (negIdx i)) suffixIdx hp hn hxy - rw [segmentReturnMass_on_orbit G hloc a γ ep L (s.val ep) hy P hpos hP] at hh - simpa only [tsum_fintype] using hh - _ = _ := by - simp only [Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] - rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx] - ring - -end FullFirstEscapeBound -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section CollisionNaturality -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace HoldingWalk -variable {W : Type*} {H : SimpleGraph V} {H' : SimpleGraph W} -theorem map_position (f : H →g H') {k : ℕ} {x y : V} (q : HoldingWalk H k x y) (i : ℕ) : - (q.map f).position i = f (q.position i) := by - induction q generalizing i with - | nil => rfl - | hold q ih => cases i <;> simp only [map,position,ih] - | step h q ih => cases i <;> simp only [map,position,ih] -end HoldingWalk - -theorem list_common_vertex_map_iff {W : Type*} (f : V → W) (hf : Function.Injective f) - (l r : List V) : - (∃ z, z ∈ l.map f ∧ z ∈ r.map f) ↔ ∃ z, z ∈ l ∧ z ∈ r := by - constructor - · rintro ⟨z,hz,hz'⟩ - obtain ⟨x,hx,rfl⟩ := List.mem_map.mp hz - obtain ⟨y,hy,he⟩ := List.mem_map.mp hz' - have : y = x := hf he - subst y - exact ⟨x,hx,hy⟩ - · rintro ⟨z,hz,hz'⟩ - exact ⟨f z,List.mem_map.mpr ⟨z,hz,rfl⟩,List.mem_map.mpr ⟨z,hz',rfl⟩⟩ - - -theorem labelFirstEscapeCollision_aut (G : BondGraph V E) (γ : I → V) (ep neg : I) - (J L m : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) - (ξ : EscapeLabel G γ ep neg L m) : - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx (EscapeLabel.autMap hab ξ) ↔ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ := by - dsimp only [labelFirstEscapeCollision,firstEscapeCollision,EscapeLabel.autMap,Function.comp_apply,autSimpleGraph] - simp only [HoldingWalk.map_vertices,HoldingWalk.map_position] - change (((∃ s, a (ξ.first (posIdx s)) ∈ ξ.leftTail.2.vertices.map a) ∨ - (∃ s, a (ξ.first (negIdx s)) ∈ ξ.middle.vertices.map a)) ∨ - (∃ z, z ∈ ξ.leftTail.2.vertices.map a ∧ z ∈ ξ.middle.vertices.map a)) ∨ - ((∃ st : Fin (J+1) × Fin (J+1), a (ξ.last (suffixIdx st.1)) = a (ξ.first (negIdx st.2))) ∨ - (∃ ij : Fin (m+1) × Fin (J+1), a (ξ.leftTail.2.position ij.1.val) = a (ξ.last (suffixIdx ij.2)))) ↔ _ - rw [list_common_vertex_map_iff a a.injective] - simp only [List.mem_map,Equiv.apply_eq_iff_eq] - simp - -end CollisionNaturality -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section BothEscapeEvents -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - -theorem rootOrbitWeight_pos (G : BondGraph V E) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (hw : ∀ i, 0 < weight i) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) (x : V) : - 0 < ∑ i, if root i ∈ vertexOrbit G x then weight i else 0 := by - obtain ⟨r,g,hg,he⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ hg - have hr : root r ∈ vertexOrbit G x := by - refine ⟨g.symm,b.symm,isAut_symm G hab,?_⟩ - rw [←he,Equiv.symm_apply_apply] - have hh : (if root r ∈ vertexOrbit G x then weight r else 0) ≤ - ∑ i, if root i ∈ vertexOrbit G x then weight i else 0 := - Finset.single_le_sum (f := fun i => if root i ∈ vertexOrbit G x then weight i else 0) - (fun i _ => by split_ifs <;> first | exact (hw i).le | rfl) (Finset.mem_univ r) - simpa only [ite_eq_left hr] using lt_of_lt_of_le (by simpa only [ite_eq_left hr] using hw r) hh - - - -theorem rooted_escape_collision_reversal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (posIdx negIdx suffixIdx : Fin (J+1) → I) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0 := by - have hh := rooted_escape_label_reversal G hloc a root weight Γ hΓ htr γ n hdiam center ep neg L m - (rootOrbitWeight_pos G root weight Γ hΓ hw hcov (γ center)) - (fun ξ => if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ then (1:ℝ) else 0) - (fun g b hab ξ => by rw [labelFirstEscapeCollision_aut G γ ep neg J L m posIdx negIdx suffixIdx hab ξ]) x hx - simpa only [mul_ite,mul_one,mul_zero] using hh - -end BothEscapeEvents -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section BothEscapeBound -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - -theorem rooted_both_collision_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (posIdx negIdx suffixIdx : Fin (J+1) → I) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hb := rooted_first_collision_probability_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep - have he := rooted_escape_collision_reversal G hloc a root weight Γ hΓ htr hw hcov - γ n hdiam center ep neg m L J x hx posIdx negIdx suffixIdx - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} - have hu := finite_weighted_event_or - (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) - (fun ξ => escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1) - (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1) - (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) - simp only [tsum_fintype] at hb he ⊢ - rw [←he] at hu - linarith - -end BothEscapeBound -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section PositiveTwoEscapes -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - - -theorem exists_positive_two_escape_label (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) - (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (posIdx negIdx suffixIdx : Fin (J+1) → I) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) (hsmall : 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) < 1) : - ∃ ξ : EscapeLabel G γ ep neg L m, ξ.first center = x ∧ - ¬labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ ∧ - ¬labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.reverse ∧ - 0 < escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by - have hb := rooted_both_collision_probability_bound G hloc a root weight Γ hΓ htr hw hw1 hcov - c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep - have hs := (rooted_label_probability_hasSum G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - by_contra H - have heq : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 := by - apply tsum_congr - intro ξ - split_ifs with ht - · rfl - · apply Eq.symm - apply le_antisymm - · exact le_of_not_gt (fun hp => H ⟨ξ.1,ξ.2,(not_or.mp ht).1,(not_or.mp ht).2,hp⟩) - · exact escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1 - rw [heq,hs] at hb - exact (not_lt_of_ge hb) hsmall - -end PositiveTwoEscapes -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.CollisionTails + +namespace OAI + +/-! Positive Escapes for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +section DependentFiniteUnion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_dependent_event_union {β δ : Type*} [Fintype β] [Fintype δ] + {γ : β → Type*} [∀ b, Fintype (γ b)] + (μ : (b : β) → γ b → ℝ) (hμ : ∀ b c, 0 ≤ μ b c) + (B : (b : β) → γ b → δ → Prop) : + (∑ b, ∑ c, if ∃ d, B b c d then μ b c else 0) ≤ + ∑ d, ∑ b, ∑ c, if B b c d then μ b c else 0 := by + have hh := finite_nonnegative_event_union + (fun ξ : Sigma γ => μ ξ.1 ξ.2) + (fun ξ => hμ ξ.1 ξ.2) + (fun ξ : Sigma γ => B ξ.1 ξ.2) + simpa only [Fintype.sum_sigma] using hh + +end DependentFiniteUnion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualFinitePositionHits +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι S T : Type*} [Fintype I] [Fintype ι] [Fintype S] [Fintype T] + + + +theorem raw_anchor_finite_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (j : S → I) (z : T → V) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (L : ℕ) (y : V) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if ∃ st : S × T, h.val (j st.1) = z st.2 then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + (Fintype.card S : ℝ)*(Fintype.card T : ℝ)*Real.sqrt c*‖P‖^L := by + let (v : V) : Finite ((openSimpleGraph G Set.univ).neighborSet v) := finite_openSimpleGraph_neighbors G hloc v + let : Fintype (RawFrom (openSimpleGraph G Set.univ) L y) := Fintype.ofFinite _ + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + simp only [tsum_fintype] + have hu := finite_dependent_event_union + (β := RawFrom (openSimpleGraph G Set.univ) L y) + (γ := fun mid => segmentAnchors G hloc γ n hdiam ep mid.1) + (δ := S × T) + (fun mid _ => mid.2.mass (walkKernel G hloc a)/(segmentAnchors G hloc γ n hdiam ep (γ ep)).card) + (fun mid _ => div_nonneg (mid.2.mass_nonneg _ hK) (Nat.cast_nonneg _)) + (fun _ h st => h.val (j st.1) = z st.2) + apply hu.trans + calc + _ ≤ ∑ _st : S × T, Real.sqrt c*‖P‖^L := by + apply Finset.sum_le_sum + intro st _ + obtain ⟨H,hH,hHn⟩ := exists_anchoredPositionOperator_uniform G hloc root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep (j st.1) + simpa only [tsum_fintype] using raw_anchor_point_collision_bound G hloc a γ n hdiam ep (j st.1) + P H hpos hP hH (Real.sqrt c) hHn L y (z st.2) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,Nat.cast_mul,nsmul_eq_mul]; ring + +end ActualFinitePositionHits +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EarlyFiniteCollisions +attribute [local instance] Classical.propDecidable Classical.decEq +variable {S : Type*} [Fintype S] + + + +theorem raw_hits_distant_set_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) + (m J : ℕ) (x : V) (z : S → V) (hD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (z s)) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x, + if ∃ s, z s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ + (Fintype.card S : ℝ)*‖P‖^J/(1-‖P‖) := by + let (v : V) : Finite ((openSimpleGraph G Set.univ).neighborSet v) := finite_openSimpleGraph_neighbors G hloc v + let : Fintype (RawFrom (openSimpleGraph G Set.univ) m x) := Fintype.ofFinite _ + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have he (w : RawFrom (openSimpleGraph G Set.univ) m x) : + (∃ s, z s ∈ w.2.vertices) ↔ ∃ si : S × Fin (m+1), w.2.position si.2.val = z si.1 := by + constructor + · rintro ⟨s,hs⟩ + obtain ⟨i,hi,he⟩ := w.2.mem_vertices_iff_position.mp hs + exact ⟨(s,⟨i,by omega⟩),he⟩ + · rintro ⟨⟨s,i⟩,he⟩ + exact ⟨s,he ▸ w.2.position_mem_vertices i.val⟩ + simp only [he,tsum_fintype] + have hu := finite_nonnegative_event_union + (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) + (fun w => w.2.mass_nonneg _ hK) + (fun w (si : S × Fin (m+1)) => w.2.position si.2.val = z si.1) + apply hu.trans + rw [Fintype.sum_prod_type] + calc + _ ≤ ∑ _s : S, ∑ i : Fin (m+1), if J ≤ i.val then ‖P‖^i.val else 0 := by + apply Finset.sum_le_sum + intro s _ + apply Finset.sum_le_sum + intro i _ + have hh := raw_position_probability G hloc a P hpos hP i.val m (by omega) x (z s) + simp only [tsum_fintype] at hh + rw [hh] + split_ifs with hi + · exact matrixCoeff_power_le P i.val x (z s) + · exact (walkPower_zero_of_lt_dist G hloc a P hpos hP i.val x (z s) (by have hd := hD s; omega)).le + _ ≤ ∑ _s : S, ‖P‖^J/(1-‖P‖) := Finset.sum_le_sum (fun _ _ => + finite_geometric_cutoff_bound ‖P‖ (norm_nonneg _) hρ J (m+1)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end EarlyFiniteCollisions +end Percolation + + +namespace Percolation +section QuantitativeEarlyCutoff + + + +noncomputable def earlyCollisionCost (ρ : ℝ) (J : ℕ) : ℝ := + 2*((J:ℝ)+1)*ρ^J/(1-ρ) + 2*ρ^J/(1-ρ)^2 + +theorem earlyCollisionCost_tendsto (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) : + Filter.Tendsto (earlyCollisionCost ρ) Filter.atTop (nhds 0) := by + have hn : ‖ρ‖ < 1 := by simpa only [Real.norm_eq_abs,abs_of_nonneg hρ] using hρ1 + have ht : Filter.Tendsto (fun J : ℕ => (J:ℝ)*ρ^J) Filter.atTop (nhds 0) := by + simpa only [pow_one] using (summable_pow_mul_geometric_of_norm_lt_one 1 hn).tendsto_atTop_zero + have hp := tendsto_pow_atTop_nhds_zero_of_lt_one hρ hρ1 + have hh := (((ht.add hp).const_mul 2).div_const (1-ρ)).add ((hp.const_mul 2).div_const ((1-ρ)^2)) + have he : earlyCollisionCost ρ = (fun J : ℕ => 2*((J:ℝ)*ρ^J+ρ^J)/(1-ρ)+2*ρ^J/(1-ρ)^2) := by + funext J + unfold earlyCollisionCost + ring + rw [he] + simpa only [zero_add,mul_zero,zero_div] using hh + +theorem exists_earlyCollisionCutoff (ρ : ℝ) (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (ε : ℝ) (hε : 0 < ε) : + ∃ J₀ : ℕ, ∀ J : ℕ, J₀ ≤ J → earlyCollisionCost ρ J < ε := by + exact Filter.eventually_atTop.mp ((earlyCollisionCost_tendsto ρ hρ hρ1).eventually (gt_mem_nhds hε)) + +end QuantitativeEarlyCutoff +end Percolation + + +namespace Percolation +section WeightedBinaryUnion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_weighted_event_or {α : Type*} [Fintype α] + (μ : α → ℝ) (hμ : ∀ a, 0 ≤ μ a) (B C : α → Prop) [DecidablePred B] [DecidablePred C] : + (∑ a, if B a ∨ C a then μ a else 0) ≤ + (∑ a, if B a then μ a else 0) + ∑ a, if C a then μ a else 0 := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro a _ + by_cases hb : B a <;> by_cases hc : C a <;> simp only [hb,hc,or_self,or_false,false_or,ite_true,ite_false,add_zero,zero_add,le_refl] + exact le_add_of_nonneg_right (hμ a) + +end WeightedBinaryUnion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ActualEarlyExperiment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem raw_early_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) + (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) + (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) + (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, + if ((∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices)) ∨ + (∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ + earlyCollisionCost ‖P‖ J := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let : Fintype (RawFrom (openSimpleGraph G Set.univ) m x) := Fintype.ofFinite _ + let : Fintype (RawFrom (openSimpleGraph G Set.univ) L y) := Fintype.ofFinite _ + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hu := finite_weighted_event_or + (fun w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y => + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a)) + (fun w => mul_nonneg (w.1.2.mass_nonneg _ hK) (w.2.2.mass_nonneg _ hK)) + (fun w => (∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices)) + (fun w => ∃ z, z ∈ w.1.2.vertices ∧ z ∈ w.2.2.vertices) + have hp := finite_product_failure_union + (fun w : RawFrom (openSimpleGraph G Set.univ) m x => w.2.mass (walkKernel G hloc a)) + (fun w : RawFrom (openSimpleGraph G Set.univ) L y => w.2.mass (walkKernel G hloc a)) + (fun w => w.2.mass_nonneg _ hK) (fun w => w.2.mass_nonneg _ hK) + (by simpa only [tsum_fintype] using rawFrom_probability_sum G hloc a m x) + (by simpa only [tsum_fintype] using rawFrom_probability_sum G hloc a L y) + (fun w => ∃ s, pos s ∈ w.2.vertices) (fun w => ∃ s, neg s ∈ w.2.vertices) + have hx := raw_hits_distant_set_bound G hloc a P hpos hP hρ m J x pos hposD + have hy := raw_hits_distant_set_bound G hloc a P hpos hP hρ L J y neg hnegD + have hi := raw_intersection_uniform_bound G hloc a P hpos hsym hP hρ m L J x y hxy + simp only [tsum_fintype,Fintype.card_fin,Nat.cast_add,Nat.cast_one] at hx hy hi ⊢ + have hx' : (∑ w : RawFrom (openSimpleGraph G Set.univ) m x, + if ∃ s, pos s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ + ((J:ℝ)+1)*‖P‖^J/(1-‖P‖) := by + convert hx using 1 + apply Finset.sum_congr rfl + intro w _ + split_ifs <;> rfl + have hy' : (∑ w : RawFrom (openSimpleGraph G Set.univ) L y, + if ∃ s, neg s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) ≤ + ((J:ℝ)+1)*‖P‖^J/(1-‖P‖) := by + convert hy using 1 + apply Finset.sum_congr rfl + intro w _ + split_ifs <;> rfl + have hp' : (∑ w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, + if (∃ s, pos s ∈ w.1.2.vertices) ∨ (∃ s, neg s ∈ w.2.2.vertices) then + w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) ≤ + (∑ w : RawFrom (openSimpleGraph G Set.univ) m x, + if ∃ s, pos s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) + + (∑ w : RawFrom (openSimpleGraph G Set.univ) L y, + if ∃ s, neg s ∈ w.2.vertices then w.2.mass (walkKernel G hloc a) else 0) := by + convert hp using 1 + · apply Finset.sum_congr rfl + intro w _ + split_ifs <;> rfl + · congr 1 <;> apply Finset.sum_congr rfl <;> intro w _ <;> split_ifs <;> rfl + have hr : (((J:ℝ)+1)*‖P‖^J/(1-‖P‖) + ((J:ℝ)+1)*‖P‖^J/(1-‖P‖)) + + 2*‖P‖^J/(1-‖P‖)^2 = earlyCollisionCost ‖P‖ J := by + unfold earlyCollisionCost + ring + have hh := hu.trans ((add_le_add (hp'.trans (add_le_add hx' hy')) hi).trans_eq hr) + exact hh + +end ActualEarlyExperiment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ConditioningCost +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem raw_anchor_event_le_unconditioned (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (m L : ℕ) (x y : V) + (B : RawFrom (openSimpleGraph G Set.univ) m x → RawFrom (openSimpleGraph G Set.univ) L y → Prop) [∀ tail mid, Decidable (B tail mid)] : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, + if B tail mid then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + (∑' w : RawFrom (openSimpleGraph G Set.univ) m x × RawFrom (openSimpleGraph G Set.univ) L y, + if B w.1 w.2 then w.1.2.mass (walkKernel G hloc a)*w.2.2.mass (walkKernel G hloc a) else 0) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + have hN : 0 < ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep (γ ep)).mpr + ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) + simp only [tsum_fintype,Fintype.sum_prod_type] + apply Finset.sum_le_sum + intro tail _ + apply Finset.sum_le_sum + intro mid _ + by_cases hb : B tail mid + · simp only [ite_eq_left hb,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + have hc : ((segmentAnchors G hloc γ n hdiam ep mid.1).card : ℝ) ≤ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card := by + rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] + split_ifs + · exact le_rfl + · exact_mod_cast Nat.zero_le _ + rw [←mul_div_assoc] + apply (div_le_iff₀ hN).mpr + have hh := mul_le_mul_of_nonneg_right hc + (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) + nlinarith + · simp only [ite_eq_right hb,Finset.sum_const_zero] + exact le_rfl + +end ConditioningCost +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EarlyAnchoredCollision +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem raw_anchor_early_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) + (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) + (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) + (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, + if ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ + (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices) then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + earlyCollisionCost ‖P‖ J := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + exact (raw_anchor_event_le_unconditioned G hloc a hK γ n hdiam ep m L x y + (fun tail mid => ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ + (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices))).trans + (raw_early_collision_bound G hloc a P hpos hsym hP hρ m L J x y pos neg hposD hnegD hxy) + + + +theorem raw_tail_integrate_anchor_event (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (m L : ℕ) (x y : V) + (B : (mid : RawFrom (openSimpleGraph G Set.univ) L y) → + segmentAnchors G hloc γ n hdiam ep mid.1 → Prop) [∀ mid h, Decidable (B mid h)] : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if B mid h then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if B mid h then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) := by + have he (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (h : segmentAnchors G hloc γ n hdiam ep mid.1) : + (if B mid h then tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = + tail.2.mass (walkKernel G hloc a) * + (if B mid h then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) := by + split_ifs <;> ring + simp only [he,tsum_mul_left,tsum_mul_right,rawFrom_probability_sum G hloc a,one_mul] + +end EarlyAnchoredCollision +end Percolation + + +namespace Percolation +section DependentUnion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_threefold_event_or {α β : Type*} {γ : β → Type*} + [Fintype α] [Fintype β] [∀ b, Fintype (γ b)] + (μ : α → (b : β) → γ b → ℝ) (hμ : ∀ a b c, 0 ≤ μ a b c) + (B C : α → (b : β) → γ b → Prop) + [∀ a b c, Decidable (B a b c)] [∀ a b c, Decidable (C a b c)] : + (∑ a, ∑ b, ∑ c, if B a b c ∨ C a b c then μ a b c else 0) ≤ + (∑ a, ∑ b, ∑ c, if B a b c then μ a b c else 0) + + (∑ a, ∑ b, ∑ c, if C a b c then μ a b c else 0) := by + simp only [←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro b _ + apply Finset.sum_le_sum + intro c _ + by_cases hb : B a b c <;> by_cases hc : C a b c <;> + simp only [hb,hc,or_self,or_false,false_or,ite_true,ite_false,add_zero,zero_add,le_refl] + exact le_add_of_nonneg_right (hμ a b c) + +end DependentUnion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CombinedRawAvoidance +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι : Type*} [Fintype I] [Fintype ι] + + + +def firstEscapeCollision (G : BondGraph V E) (J m L : ℕ) (x y : V) + (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) + (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) (h : I → V) : Prop := + (((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ + (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices)) ∨ + ((∃ st : Fin (J+1) × Fin (J+1), h (j st.1) = neg st.2) ∨ + (∃ ij : Fin (m+1) × Fin (J+1), tail.2.position ij.1.val = h (j ij.2))) + +noncomputable def suffixCollisionCost (ρ c : ℝ) (J : ℕ) : ℝ := + ((J:ℝ)+1)^2*Real.sqrt c + ((J:ℝ)+1)*Real.sqrt c/(1-ρ) + + + +theorem raw_first_escape_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 ≤ weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x y : V) (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) + (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) + (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) + (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if firstEscapeCollision G J m L x y pos neg j tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + let μ := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (_h : segmentAnchors G hloc γ n hdiam ep mid.1) => + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card + have hμ : ∀ tail mid h, 0 ≤ μ tail mid h := fun tail mid _ => + div_nonneg (mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK)) (Nat.cast_nonneg _) + let B := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (_h : segmentAnchors G hloc γ n hdiam ep mid.1) => + ((∃ s, pos s ∈ tail.2.vertices) ∨ (∃ s, neg s ∈ mid.2.vertices)) ∨ + (∃ z, z ∈ tail.2.vertices ∧ z ∈ mid.2.vertices) + let C := fun (_tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (h : segmentAnchors G hloc γ n hdiam ep mid.1) => + ∃ st : Fin (J+1) × Fin (J+1), h.val (j st.1) = neg st.2 + let D := fun (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (h : segmentAnchors G hloc γ n hdiam ep mid.1) => + ∃ ij : Fin (m+1) × Fin (J+1), tail.2.position ij.1.val = h.val (j ij.2) + have hu := finite_threefold_event_or μ hμ B (fun tail mid h => C tail mid h ∨ D tail mid h) + have hv := finite_threefold_event_or μ hμ C D + have he := raw_anchor_early_collision_bound G hloc a γ n hdiam ep P hpos hsym hP hρ + m L J x y pos neg hposD hnegD hxy + have hn := raw_anchor_finite_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep j neg P hpos hP L y + rw [←raw_tail_integrate_anchor_event G hloc a γ n hdiam ep m L x y + (fun _ h => ∃ st : Fin (J+1) × Fin (J+1), h.val (j st.1) = neg st.2)] at hn + have ht := raw_tail_whole_suffix_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep j P hpos hP hρ m L x y + simp only [tsum_fintype,Fintype.card_fin,Nat.cast_add,Nat.cast_one] at he hn ht ⊢ + have hr : earlyCollisionCost ‖P‖ J + + ((((J:ℝ)+1)*((J:ℝ)+1)*Real.sqrt c*‖P‖^L) + + ((J:ℝ)+1)*Real.sqrt c*‖P‖^L/(1-‖P‖)) = + earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by + unfold suffixCollisionCost + ring + have hh := hu.trans ((add_le_add he (hv.trans (add_le_add hn ht))).trans_eq hr) + apply le_trans ?_ hh + apply le_of_eq + apply Finset.sum_congr rfl + intro tail _ + apply Finset.sum_congr rfl + intro mid _ + apply Finset.sum_congr rfl + intro h _ + unfold firstEscapeCollision B C D μ + split_ifs <;> rfl + +end CombinedRawAvoidance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NormalizedFirstEscape +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι : Type*} [Fintype I] [Fintype ι] + + + +theorem conditional_first_escape_collision_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x y : V) (hy : y ∈ vertexOrbit G (γ ep)) + (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) + (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) + (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) + (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if firstEscapeCollision G J m L x y pos neg j tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / + segmentReturnMass G hloc a γ ep L y ≤ + 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by + have hb := raw_first_escape_collision_bound G hloc a root weight Γ hΓ htr + (fun r => (hw r).le) hw1 hcov c hc.le hmin γ n hdiam ep P hpos hsym hP hρ + m L J x y pos neg j hposD hnegD hxy + have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ ep L + rw [←segmentReturnMass_on_orbit G hloc a γ ep L y hy P hpos hP] at hq + have htc : 0 < 2*c := mul_pos (by norm_num) hc + have hqp : 0 < segmentReturnMass G hloc a γ ep L y := (one_div_pos.mpr htc).trans_le hq + apply (div_le_iff₀ hqp).mpr + apply hb.trans + have hB : 0 ≤ earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L := by + unfold earlyCollisionCost suffixCollisionCost + have : 0 < 1-‖P‖ := sub_pos.mpr hρ + positivity + have h1 : 1 ≤ (2*c)*segmentReturnMass G hloc a γ ep L y := by + exact (div_le_iff₀ htc).mp hq |>.trans_eq (mul_comm _ _) + have hh := mul_le_mul_of_nonneg_right h1 hB + nlinarith only [hh] + +end NormalizedFirstEscape +end Percolation + + +namespace Percolation +section FirstEscapeChoiceOrder + + + +theorem exists_first_escape_uniform_cutoffs (ρ c ε : ℝ) + (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hε : 0 < ε) : + ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∀ L : ℕ, L₀ ≤ L → + 2*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L) < ε := by + have hδ : 0 < ε/(4*c) := div_pos hε (by positivity) + obtain ⟨J₀,hJ₀⟩ := exists_earlyCollisionCutoff ρ hρ hρ1 (ε/(4*c)) hδ + let J := max J₀ 1 + have hJ : 0 < J := lt_of_lt_of_le (by omega : 0 < 1) (le_max_right _ _) + have he : earlyCollisionCost ρ J < ε/(4*c) := hJ₀ J (le_max_left _ _) + have hel : 2*c*earlyCollisionCost ρ J < ε := by + have hh := (lt_div_iff₀ (by positivity : 0 < 4*c)).mp he + nlinarith + have ht : Filter.Tendsto + (fun L : ℕ => 2*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L)) + Filter.atTop (nhds (2*c*earlyCollisionCost ρ J)) := by + have hh := ((tendsto_pow_atTop_nhds_zero_of_lt_one hρ hρ1).const_mul + (suffixCollisionCost ρ c J)).const_add (earlyCollisionCost ρ J) + have hh' := hh.const_mul (2*c) + simpa only [mul_zero,add_zero] using hh' + obtain ⟨L₀,hL₀⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds hel)) + exact ⟨J,hJ,L₀,hL₀⟩ + +end FirstEscapeChoiceOrder +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralConditionalMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I : Type*} [Fintype I] + + + +theorem raw_tail_anchor_total_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (m L : ℕ) (x y : V) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card) = + segmentReturnMass G hloc a γ ep L y := by + have hN : ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) ≠ 0 := by + apply ne_of_gt + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam ep (γ ep)).mpr + ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) + have hh := raw_tail_integrate_anchor_event G hloc a γ n hdiam ep m L x y (fun _ _ => True) + simp only [ite_true] at hh + rw [hh] + unfold segmentReturnMass + apply tsum_congr + intro mid + simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + rw [segmentAnchors_card_eq_indicator G hloc γ n hdiam ep mid.1] + split_ifs + · field_simp + · simp only [Nat.cast_zero,zero_mul] + + + +theorem raw_tail_anchor_conditional_mass (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (m L : ℕ) (x y : V) (hq : segmentReturnMass G hloc a γ ep L y ≠ 0) : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card / + segmentReturnMass G hloc a γ ep L y) = 1 := by + have hh := raw_tail_anchor_total_mass G hloc a γ n hdiam ep m L x y + simp only [tsum_div_const] at hh ⊢ + rw [hh] + exact div_self hq + +end LiteralConditionalMass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralGeodesicSeparation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem graph_dist_aut (G : BondGraph V E) (hconn : Connected G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : + (openSimpleGraph G Set.univ).dist (a x) (a y) = + (openSimpleGraph G Set.univ).dist x y := by + have hreach (x y : V) : (openSimpleGraph G Set.univ).Reachable x y := + (conn_iff_reachable G Set.univ x y).mp (conn_univ_of_connected G hconn x y) + obtain ⟨q,hq⟩ := (hreach x y).exists_walk_length_eq_dist + obtain ⟨r,hr⟩ := (hreach (a x) (a y)).exists_walk_length_eq_dist + have hq' := SimpleGraph.dist_le (q.map (autSimpleGraph G hab).toHom) + have hr' := SimpleGraph.dist_le (r.map (autSimpleGraph G (isAut_symm G hab)).toHom) + simp only [SimpleGraph.Walk.length_map,hq] at hq' + change (openSimpleGraph G Set.univ).dist (a.symm (a x)) (a.symm (a y)) ≤ _ at hr' + simp only [a.symm_apply_apply,SimpleGraph.Walk.length_map,hr] at hr' + exact le_antisymm hq' hr' + + + +theorem geodesic_anchor_early_separations (G : BondGraph V E) (hconn : Connected G) + {x y : V} (q : (openSimpleGraph G Set.univ).Walk x y) (J : ℕ) + (hlen : q.length = 2*J) (hq : q.length = (openSimpleGraph G Set.univ).dist x y) + (s : Fin (2*J+1) → V) (hs : s ∈ segmentOrbit G (geodesicSegment G q (2*J))) : + (∀ i : Fin (J+1), J ≤ (openSimpleGraph G Set.univ).dist + (s ⟨0,by omega⟩) (s ⟨J+i.val,by omega⟩)) ∧ + (∀ i : Fin (J+1), J ≤ (openSimpleGraph G Set.univ).dist + (s ⟨2*J,by omega⟩) (s ⟨i.val,by omega⟩)) ∧ + (2*J ≤ (openSimpleGraph G Set.univ).dist (s ⟨0,by omega⟩) (s ⟨2*J,by omega⟩)) := by + obtain ⟨a,b,hab,rfl⟩ := hs + constructor + · intro i + dsimp only [Function.comp_apply,geodesicSegment] + rw [graph_dist_aut G hconn hab] + rw [geodesic_getVert_dist _ q hq 0 (J+i.val) (by omega) (by omega)] + omega + constructor + · intro i + dsimp only [Function.comp_apply,geodesicSegment] + rw [graph_dist_aut G hconn hab,SimpleGraph.dist_comm] + rw [geodesic_getVert_dist _ q hq i.val (2*J) (by omega) (by omega)] + omega + · dsimp only [Function.comp_apply,geodesicSegment] + rw [graph_dist_aut G hconn hab] + rw [geodesic_getVert_dist _ q hq 0 (2*J) (by omega) (by omega)] + omega + +end LiteralGeodesicSeparation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PositiveFirstEscape +attribute [local instance] Classical.propDecidable Classical.decEq +variable {I ι : Type*} [Fintype I] [Fintype ι] + + + +theorem exists_positive_first_escape (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (ep : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x y : V) (hy : y ∈ vertexOrbit G (γ ep)) + (pos neg : Fin (J+1) → V) (j : Fin (J+1) → I) + (hposD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist x (pos s)) + (hnegD : ∀ s, J ≤ (openSimpleGraph G Set.univ).dist y (neg s)) + (hxy : 2*J ≤ (openSimpleGraph G Set.univ).dist x y) + (hsmall : 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) < 1) : + ∃ (tail : RawFrom (openSimpleGraph G Set.univ) m x) + (mid : RawFrom (openSimpleGraph G Set.univ) L y) + (h : segmentAnchors G hloc γ n hdiam ep mid.1), + ¬firstEscapeCollision G J m L x y pos neg j tail mid h.val ∧ + 0 < tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) := by + have hb := conditional_first_escape_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep P hpos hsym hP hdiag hρ m L J x y hy pos neg j hposD hnegD hxy + have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ ep L + rw [←segmentReturnMass_on_orbit G hloc a γ ep L y hy P hpos hP] at hq + have hqp : 0 < segmentReturnMass G hloc a γ ep L y := + (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + by_contra H + have heq : + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if firstEscapeCollision G J m L x y pos neg j tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) = + ∑' tail : RawFrom (openSimpleGraph G Set.univ) m x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L y, + ∑' _h : segmentAnchors G hloc γ n hdiam ep mid.1, + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card := by + apply tsum_congr + intro tail + apply tsum_congr + intro mid + apply tsum_congr + intro h + split_ifs with ht + · rfl + · have hz : tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) = 0 := by + apply le_antisymm + · exact le_of_not_gt (fun hp => H ⟨tail,mid,h,ht,hp⟩) + · exact mul_nonneg (tail.2.mass_nonneg _ hK) (mid.2.mass_nonneg _ hK) + rw [hz,zero_div] + rw [heq,raw_tail_anchor_total_mass G hloc a γ n hdiam ep m L x y,div_self hqp.ne'] at hb + exact (not_lt_of_ge hb) hsmall + +end PositiveFirstEscape +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ProjectionEvents +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finite_event_fiber_sum {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] + (f : α → β) (μ : α → ℝ) (B : β → Prop) [DecidablePred B] : + (∑ a, if B (f a) then μ a else 0) = + ∑ b, if B b then ∑ a, if f a = b then μ a else 0 else 0 := by + calc + _ = ∑ a, ∑ b, if B b then (if f a = b then μ a else 0) else 0 := by + apply Finset.sum_congr rfl + intro a _ + have hf : (fun b => if B b then (if f a = b then μ a else 0) else 0) = + fun b => if f a = b then (if B (f a) then μ a else 0) else 0 := by + funext b + by_cases h : f a = b + · subst b + simp + · simp [h] + rw [hf] + simp + _ = _ := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + by_cases h : B b <;> simp [h] + + + +theorem rooted_label_raw_event_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (ha : 0 < a) (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (J L m : ℕ) (γ : Fin (J+J+1) → V) + (hγ : ∀ i : Fin (J+J), (openSimpleGraph G Set.univ).Adj (γ i.castSucc) (γ i.succ)) + (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (x : V) + (hx : x ∈ vertexOrbit G (γ (segmentCenter J))) + (q : ℝ) (hq : 0 < q) (hqle : q ≤ segmentReturnMass G hloc a γ (Fin.last (J+J)) L (γ (Fin.last (J+J)))) + (B : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x → Prop) [DecidablePred B] : + (∑' ξ : {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x}, + if B (rootedEscapeLabelRaw G J L m γ hγ x ξ) then + escapeLabelProbability G hloc a γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m ξ.1 else 0) ≤ + (∑' w : RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x, + if B w then w.2.mass (walkKernel G hloc a) else 0)/(a^(J+J)*q) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let := finite_rootedEscapeLabels G hloc γ n hdiam (segmentCenter J) (Fin.last (J+J)) 0 L m x + let : Fintype {ξ : EscapeLabel G γ (Fin.last (J+J)) 0 L m // ξ.first (segmentCenter J) = x} := Fintype.ofFinite _ + let : Fintype (RawFrom (openSimpleGraph G Set.univ) ((J+L)+J) x) := Fintype.ofFinite _ + rw [←tsum_indicator_div] + simp only [tsum_fintype] + rw [finite_event_fiber_sum] + apply Finset.sum_le_sum + intro w _ + by_cases hw : B w + · simp only [hw,ite_true] + simpa only [tsum_fintype] using + rooted_label_raw_projection_bound G hloc a ha hK J L m γ hγ n hdiam x hx q hq hqle w + · simp only [hw,ite_false,le_refl] + +end ProjectionEvents +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section FirstLabeledMarginal +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + +def labelFirstEscapeCollision (G : BondGraph V E) (γ : I → V) (ep neg : I) + (J L m : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) + (ξ : EscapeLabel G γ ep neg L m) : Prop := + firstEscapeCollision G J m L (ξ.first neg) (ξ.first ep) + (fun t => ξ.first (posIdx t)) (fun t => ξ.first (negIdx t)) suffixIdx + ξ.leftTail ⟨ξ.last ep,ξ.middle⟩ ξ.last + +theorem labelFromCode_first_collision (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (J L m : ℕ) (x : V) + (posIdx negIdx suffixIdx : Fin (J+1) → I) + (c : RootedLabelCode G hloc γ n hdiam center ep neg L m x) : + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx + (labelFromCode G hloc γ n hdiam center ep neg L m x c).1 = + firstEscapeCollision G J m L (c.1.val neg) (c.1.val ep) + (fun t => c.1.val (posIdx t)) (fun t => c.1.val (negIdx t)) suffixIdx + c.2.2.2.1 c.2.1 c.2.2.1.val := by + rcases c with ⟨⟨s,hs⟩,⟨z,mid⟩,⟨h,hh⟩,α,β⟩ + obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + + + +theorem raw_rooted_first_collision_marginal (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (J L m : ℕ) (x : V) + (posIdx negIdx suffixIdx : Fin (J+1) → I) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then + ξ.1.mass (walkKernel G hloc a) else 0) = + ∑' s : segmentAnchors G hloc γ n hdiam center x, + ∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if firstEscapeCollision G J m L (s.val neg) (s.val ep) + (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) else 0 := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x + rw [←R.symm.tsum_eq] + simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass,labelFromCode_first_collision] + unfold RootedLabelCode at * + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + apply tsum_congr + intro s + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + have hh (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) : + (∑' hh : Σ h : segmentAnchors G hloc γ n hdiam ep mid.1, + RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + if firstEscapeCollision G J m L (s.val neg) (s.val ep) + (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx hh.2.1 mid hh.1.val then + mid.2.mass (walkKernel G hloc a)*hh.2.1.2.mass (walkKernel G hloc a)*hh.2.2.2.mass (walkKernel G hloc a) else 0) = + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + ∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), + if firstEscapeCollision G J m L (s.val neg) (s.val ep) + (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a) else 0 := by + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_sigma] + apply tsum_congr + intro h + rw [(summable_of_hasFiniteSupport (Set.toFinite _)).tsum_prod] + apply tsum_congr + intro tail + split_ifs + · simp only [tsum_mul_left,rawFrom_probability_sum G hloc a,mul_one] + exact mul_comm _ _ + · simp only [tsum_zero] + simp_rw [hh] + simp only [tsum_fintype] + conv_lhs => + arg 2 + intro mid + rw [Finset.sum_comm] + rw [Finset.sum_comm] + +end FirstLabeledMarginal +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section NormalizedMarginal +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + + +theorem rooted_first_collision_probability_marginal (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (J L m : ℕ) (x : V) + (posIdx negIdx suffixIdx : Fin (J+1) → I) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = + (∑' s : segmentAnchors G hloc γ n hdiam center x, + (∑' tail : RawFrom (openSimpleGraph G Set.univ) m (s.val neg), + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if firstEscapeCollision G J m L (s.val neg) (s.val ep) + (fun t => s.val (posIdx t)) (fun t => s.val (negIdx t)) suffixIdx tail mid h.val then + tail.2.mass (walkKernel G hloc a)*mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / + segmentReturnMass G hloc a γ ep L (γ ep)) / + (segmentAnchors G hloc γ n hdiam center (γ center)).card := by + simp only [escapeLabelProbability,tsum_indicator_div,tsum_div_const] + rw [raw_rooted_first_collision_marginal G hloc a γ n hdiam center ep neg J L m x posIdx negIdx suffixIdx] + ring + +end NormalizedMarginal +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section FullFirstEscapeBound +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + + +theorem rooted_first_collision_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (posIdx negIdx suffixIdx : Fin (J+1) → I) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by + rw [rooted_first_collision_probability_marginal G hloc a γ n hdiam center ep neg J L m x posIdx negIdx suffixIdx] + have hN : 0 < ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam center (γ center)).mpr + ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) + apply (div_le_iff₀ hN).mpr + simp only [tsum_fintype] + calc + _ ≤ ∑ s : segmentAnchors G hloc γ n hdiam center x, + 2*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by + apply Finset.sum_le_sum + intro s _ + have hs := ((mem_segmentAnchors G hloc γ n hdiam center x s.val).mp s.property).1 + have hy : s.val ep ∈ vertexOrbit G (γ ep) := by + obtain ⟨g,b,hg,he⟩ := hs + rw [he] + exact ⟨g,b,hg,rfl⟩ + obtain ⟨hp,hn,hxy⟩ := hsep s.val hs + have hh := conditional_first_escape_collision_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam ep P hpos hsym hP hdiag hρ m L J (s.val neg) (s.val ep) hy + (fun i => s.val (posIdx i)) (fun i => s.val (negIdx i)) suffixIdx hp hn hxy + rw [segmentReturnMass_on_orbit G hloc a γ ep L (s.val ep) hy P hpos hP] at hh + simpa only [tsum_fintype] using hh + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] + rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx] + ring + +end FullFirstEscapeBound +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section CollisionNaturality +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace HoldingWalk +variable {W : Type*} {H : SimpleGraph V} {H' : SimpleGraph W} +theorem map_position (f : H →g H') {k : ℕ} {x y : V} (q : HoldingWalk H k x y) (i : ℕ) : + (q.map f).position i = f (q.position i) := by + induction q generalizing i with + | nil => rfl + | hold q ih => cases i <;> simp only [map,position,ih] + | step h q ih => cases i <;> simp only [map,position,ih] +end HoldingWalk + +theorem list_common_vertex_map_iff {W : Type*} (f : V → W) (hf : Function.Injective f) + (l r : List V) : + (∃ z, z ∈ l.map f ∧ z ∈ r.map f) ↔ ∃ z, z ∈ l ∧ z ∈ r := by + constructor + · rintro ⟨z,hz,hz'⟩ + obtain ⟨x,hx,rfl⟩ := List.mem_map.mp hz + obtain ⟨y,hy,he⟩ := List.mem_map.mp hz' + have : y = x := hf he + subst y + exact ⟨x,hx,hy⟩ + · rintro ⟨z,hz,hz'⟩ + exact ⟨f z,List.mem_map.mpr ⟨z,hz,rfl⟩,List.mem_map.mpr ⟨z,hz',rfl⟩⟩ + + +theorem labelFirstEscapeCollision_aut (G : BondGraph V E) (γ : I → V) (ep neg : I) + (J L m : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) + (ξ : EscapeLabel G γ ep neg L m) : + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx (EscapeLabel.autMap hab ξ) ↔ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ := by + dsimp only [labelFirstEscapeCollision,firstEscapeCollision,EscapeLabel.autMap,Function.comp_apply,autSimpleGraph] + simp only [HoldingWalk.map_vertices,HoldingWalk.map_position] + change (((∃ s, a (ξ.first (posIdx s)) ∈ ξ.leftTail.2.vertices.map a) ∨ + (∃ s, a (ξ.first (negIdx s)) ∈ ξ.middle.vertices.map a)) ∨ + (∃ z, z ∈ ξ.leftTail.2.vertices.map a ∧ z ∈ ξ.middle.vertices.map a)) ∨ + ((∃ st : Fin (J+1) × Fin (J+1), a (ξ.last (suffixIdx st.1)) = a (ξ.first (negIdx st.2))) ∨ + (∃ ij : Fin (m+1) × Fin (J+1), a (ξ.leftTail.2.position ij.1.val) = a (ξ.last (suffixIdx ij.2)))) ↔ _ + rw [list_common_vertex_map_iff a a.injective] + simp only [List.mem_map,Equiv.apply_eq_iff_eq] + simp + +end CollisionNaturality +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section BothEscapeEvents +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + +theorem rootOrbitWeight_pos (G : BondGraph V E) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (hw : ∀ i, 0 < weight i) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) (x : V) : + 0 < ∑ i, if root i ∈ vertexOrbit G x then weight i else 0 := by + obtain ⟨r,g,hg,he⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ hg + have hr : root r ∈ vertexOrbit G x := by + refine ⟨g.symm,b.symm,isAut_symm G hab,?_⟩ + rw [←he,Equiv.symm_apply_apply] + have hh : (if root r ∈ vertexOrbit G x then weight r else 0) ≤ + ∑ i, if root i ∈ vertexOrbit G x then weight i else 0 := + Finset.single_le_sum (f := fun i => if root i ∈ vertexOrbit G x then weight i else 0) + (fun i _ => by split_ifs <;> first | exact (hw i).le | rfl) (Finset.mem_univ r) + simpa only [ite_eq_left hr] using lt_of_lt_of_le (by simpa only [ite_eq_left hr] using hw r) hh + + + +theorem rooted_escape_collision_reversal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (posIdx negIdx suffixIdx : Fin (J+1) → I) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0 := by + have hh := rooted_escape_label_reversal G hloc a root weight Γ hΓ htr γ n hdiam center ep neg L m + (rootOrbitWeight_pos G root weight Γ hΓ hw hcov (γ center)) + (fun ξ => if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ then (1:ℝ) else 0) + (fun g b hab ξ => by rw [labelFirstEscapeCollision_aut G γ ep neg J L m posIdx negIdx suffixIdx hab ξ]) x hx + simpa only [mul_ite,mul_one,mul_zero] using hh + +end BothEscapeEvents +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section BothEscapeBound +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + +theorem rooted_both_collision_probability_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (posIdx negIdx suffixIdx : Fin (J+1) → I) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hb := rooted_first_collision_probability_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep + have he := rooted_escape_collision_reversal G hloc a root weight Γ hΓ htr hw hcov + γ n hdiam center ep neg m L J x hx posIdx negIdx suffixIdx + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} + have hu := finite_weighted_event_or + (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) + (fun ξ => escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1) + (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1) + (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) + simp only [tsum_fintype] at hb he ⊢ + rw [←he] at hu + linarith + +end BothEscapeBound +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section PositiveTwoEscapes +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + + +theorem exists_positive_two_escape_label (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) (hρ : ‖P‖ < 1) + (m L J : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (posIdx negIdx suffixIdx : Fin (J+1) → I) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) (hsmall : 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) < 1) : + ∃ ξ : EscapeLabel G γ ep neg L m, ξ.first center = x ∧ + ¬labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ ∧ + ¬labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.reverse ∧ + 0 < escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ := by + have hb := rooted_both_collision_probability_bound G hloc a root weight Γ hΓ htr hw hw1 hcov + c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep + have hs := (rooted_label_probability_hasSum G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + by_contra H + have heq : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 := by + apply tsum_congr + intro ξ + split_ifs with ht + · rfl + · apply Eq.symm + apply le_antisymm + · exact le_of_not_gt (fun hp => H ⟨ξ.1,ξ.2,(not_or.mp ht).1,(not_or.mp ht).2,hp⟩) + · exact escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1 + rw [heq,hs] at hb + exact (not_lt_of_ge hb) hsmall + +end PositiveTwoEscapes +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Escape/SelectionBounds.lean b/lean/OAI/Probability/UnimodularPercolation/Escape/SelectionBounds.lean index ee327c3c7cd97e24c9be4b23e7ec74d933138861..f6160315e5ac72428dd155faa73b2b88b8556899 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Escape/SelectionBounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Escape/SelectionBounds.lean @@ -1,553 +1,553 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.PositiveEscapes - -namespace OAI - -/-! Selection Bounds for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -section BothEscapeChoiceOrder - - - -theorem exists_both_escape_uniform_cutoffs (ρ c ε : ℝ) - (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hε : 0 < ε) : - ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∀ L : ℕ, L₀ ≤ L → - 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L) < ε := by - obtain ⟨J,hJ,L₀,hL₀⟩ := exists_first_escape_uniform_cutoffs ρ c (ε/2) hρ hρ1 hc (by positivity) - refine ⟨J,hJ,L₀,fun L hL => ?_⟩ - have hh := hL₀ L hL - linarith - -end BothEscapeChoiceOrder -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section TailConditioning -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - - -theorem rooted_label_event_of_tail_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) - (B : EscapeLabel G γ ep neg L m → Prop) (ε : ℝ) - (hB : ∀ (s : segmentAnchors G hloc γ n hdiam center x) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) - (h : segmentAnchors G hloc γ n hdiam ep mid.1), - (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then - tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0) ≤ ε) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if B ξ.1 then ξ.1.mass (walkKernel G hloc a) else 0) ≤ - ε * ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - ξ.1.mass (walkKernel G hloc a) := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x - rw [←R.symm.tsum_eq,←R.symm.tsum_eq] - simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] - unfold RootedLabelCode at * - simp only [tsum_fintype,Fintype.sum_sigma,Finset.mul_sum] - apply Finset.sum_le_sum - intro s _ - apply Finset.sum_le_sum - intro mid _ - apply Finset.sum_le_sum - intro h _ - have hh := hB s mid h - simp only [tsum_fintype] at hh - have ht : (∑ tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a)) = 1 := by - rw [Fintype.sum_prod_type] - simp only [←Finset.mul_sum,←Finset.sum_mul] - simpa only [tsum_fintype,mul_one] using congrArg₂ (fun r t : ℝ => r*t) - (rawFrom_probability_sum G hloc a m (s.val neg)) - (rawFrom_probability_sum G hloc a m (h.val neg)) - calc - _ = mid.2.mass (walkKernel G hloc a) * - ∑ tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then - tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0 := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro tails _ - split_ifs <;> simp only [mul_zero,mul_assoc] - _ ≤ mid.2.mass (walkKernel G hloc a)*ε := mul_le_mul_of_nonneg_left hh (mid.2.mass_nonneg _ hK) - _ = _ := by - simp only [mul_assoc,←Finset.mul_sum] - rw [ht] - ring - -end TailConditioning -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section NormalizedTailConditioning -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - - -theorem rooted_label_probability_of_tail_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (B : EscapeLabel G γ ep neg L m → Prop) (ε : ℝ) - (hB : ∀ (s : segmentAnchors G hloc γ n hdiam center x) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) - (h : segmentAnchors G hloc γ n hdiam ep mid.1), - (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg), - if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then - tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0) ≤ ε) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if B ξ.1 then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ ε := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ ep L - have hqp : 0 ≤ segmentReturnMass G hloc a γ ep L (γ ep) := - (one_div_pos.mpr (mul_pos (by norm_num) hc)).le.trans hq - let D := ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) * - ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * - segmentReturnMass G hloc a γ ep L (γ ep) - have hD : 0 ≤ D := mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) hqp - have hr := rooted_label_event_of_tail_bound G hloc a hK γ n hdiam center ep neg L m x B ε hB - have hs := (rooted_label_probability_hasSum G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq - have hd := div_le_div_of_nonneg_right hr hD - have he : (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - ξ.1.mass (walkKernel G hloc a))/D = 1 := by - simpa only [escapeLabelProbability,tsum_div_const,D] using hs - simpa only [escapeLabelProbability,tsum_indicator_div,tsum_div_const,D, - mul_div_assoc,he,mul_one] using hd - -end NormalizedTailConditioning -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section FullPotentialTests -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - -def labelPotentialFailure (G : BondGraph V E) (p : unitInterval) (γ : I → V) - (ep neg : I) (L m : ℕ) - (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) - (t : ℝ) (ξ : EscapeLabel G γ ep neg L m) : Prop := - (t < ∑ b ∈ F ξ.first ⟨ξ.last ep,ξ.middle⟩ ξ.last, twoPoint G p ξ.leftTail.1 b) ∨ - (t < ∑ b ∈ F ξ.first ⟨ξ.last ep,ξ.middle⟩ ξ.last, twoPoint G p ξ.rightTail.1 b) - -theorem labelFromCode_potential_failure (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) - (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) - (t : ℝ) (s : segmentAnchors G hloc γ n hdiam center x) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) - (h : segmentAnchors G hloc γ n hdiam ep mid.1) - (tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg)) : - labelPotentialFailure G p γ ep neg L m F t - (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 ↔ - (t < ∑ b ∈ F s.val mid h.val, twoPoint G p tails.1.1 b) ∨ - (t < ∑ b ∈ F s.val mid h.val, twoPoint G p tails.2.1 b) := by - rcases s with ⟨s,hs⟩ - rcases mid with ⟨z,mid⟩ - rcases h with ⟨h,hh⟩ - obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - - - -theorem rooted_label_potential_failure_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (p : unitInterval) (hA : HasKernel G p A) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) - (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if labelPotentialFailure G p γ ep neg L m F t ξ.1 then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 2*(N*Real.sqrt c*‖P‖^m)/t := by - apply rooted_label_probability_of_tail_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx - intro s mid h - simp only [labelFromCode_potential_failure] - have hh := two_raw_tail_potential_failure G hloc a root weight htr hcov (fun r => (hw r).le) hw1 - c hc.le hmin P A hpos hP p hA m (s.val neg) (h.val neg) (F s.val mid h.val) t ht - apply hh.trans - gcongr - exact hN s.val mid h.val - -end FullPotentialTests -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section CombinedSelectionEvents -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - - -theorem rooted_label_collision_potential_failure_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (p : unitInterval) (hA : HasKernel G p A) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (hρ : ‖P‖ < 1) (J : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) - (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) - (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if (labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) ∨ - labelPotentialFailure G p γ ep neg L m F t ξ.1 then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + - 2*(N*Real.sqrt c*‖P‖^m)/t := by - have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by - simpa only [hP,Complex.ofReal_re] using (hpos x y).2 - have hb := rooted_both_collision_probability_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hw hw1 hcov c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep - have hp := rooted_label_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin - P A hpos hsym hP hdiag p hA γ n hdiam center ep neg L m x hx F N hN t ht - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} - have hu := finite_weighted_event_or - (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) - (fun ξ => escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1) - (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) - (fun ξ => labelPotentialFailure G p γ ep neg L m F t ξ.1) - simp only [tsum_fintype] at hb hp ⊢ - exact hu.trans (add_le_add hb hp) - -end CombinedSelectionEvents -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section QuantitativeSelectionMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -theorem finite_weighted_success_lower {α : Type*} [Fintype α] - (μ : α → ℝ) (hμ : ∑ a, μ a = 1) (B : α → Prop) [DecidablePred B] (ε : ℝ) - (hB : (∑ a, if B a then μ a else 0) ≤ ε) : - 1-ε ≤ ∑ a, if ¬B a then μ a else 0 := by - have he : (∑ a, if ¬B a then μ a else 0) + (∑ a, if B a then μ a else 0) = 1 := by - rw [←Finset.sum_add_distrib,←hμ] - apply Finset.sum_congr rfl - intro a _ - by_cases h : B a <;> simp only [h,not_true_eq_false,not_false_eq_true,ite_true,ite_false,zero_add,add_zero] - linarith - - - -theorem rooted_label_collision_potential_success_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) - (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (p : unitInterval) (hA : HasKernel G p A) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (hρ : ‖P‖ < 1) (J : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) - (hsep : ∀ s ∈ segmentOrbit G γ, - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ - (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ - 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) - (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) - (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : - 1 - (4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + - 2*(N*Real.sqrt c*‖P‖^m)/t) ≤ - ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if ¬((labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ - labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) ∨ - labelPotentialFailure G p γ ep neg L m F t ξ.1) then - escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0 := by - have hb := rooted_label_collision_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin - P A hpos hsym hP hdiag p hA γ n hdiam center ep neg L m x hx hρ J posIdx negIdx suffixIdx hsep F N hN t ht - have hs := (rooted_label_probability_hasSum G hloc a root weight (vertexAut G) (Set.Subset.refl _) - htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} - simp only [tsum_fintype] at hs hb ⊢ - exact finite_weighted_success_lower _ hs _ _ hb - -end QuantitativeSelectionMass -end Percolation - - -namespace Percolation -section JointSelectionChoiceOrder - - - -theorem exists_joint_collision_potential_cutoffs (ρ c d τ : ℝ) - (hρ : 0 < ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hd : 0 ≤ d) (hτ : 0 < τ) : - ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∃ C₁ : ℝ, 0 < C₁ ∧ 1 < (-Real.log ρ)*C₁ ∧ - ∃ k₀ : ℕ, J+J+L₀ ≤ k₀ ∧ ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → - 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^(k-(J+J))) + - 2*((d+1)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) ≤ 3/8 := by - obtain ⟨J,hJ,L₀,hL₀⟩ := exists_both_escape_uniform_cutoffs ρ c (1/8) hρ.le hρ1 hc (by norm_num) - let A : ℝ := 2*(d+1)*Real.sqrt c/τ - have hA : 0 ≤ A := div_nonneg (mul_nonneg (mul_nonneg (by norm_num) (by linarith)) (Real.sqrt_nonneg _)) hτ.le - obtain ⟨C₁,hC₁,hlam,k₀,hk₀,hk⟩ := exists_uniform_logarithmic_tail_cutoff ρ A hρ hρ1 hA (J+J+L₀) - refine ⟨J,hJ,L₀,C₁,hC₁,hlam,k₀,hk₀,fun k hk' R hR => ?_⟩ - have hL : L₀ ≤ k-(J+J) := by omega - have hb := hL₀ (k-(J+J)) hL - have hp := hk k hk' R hR - have hRp : 0 < R := lt_of_lt_of_le (by norm_num) hR - have he : 2*((d+1)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) = - A*((k:ℝ)+1)*R*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ := by - dsimp only [A] - field_simp [hτ.ne',hRp.ne'] - rw [he] - linarith - -end JointSelectionChoiceOrder -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section SpineMarginal -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - -theorem labelFromCode_anchor_event (G : BondGraph V E) (hloc : LocallyFinite G) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (B : (I → V) → (I → V) → Prop) - (s : segmentAnchors G hloc γ n hdiam center x) - (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) - (h : segmentAnchors G hloc γ n hdiam ep mid.1) - (tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × - RawFrom (openSimpleGraph G Set.univ) m (h.val neg)) : - B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1.first - (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1.last ↔ B s.val h.val := by - rcases s with ⟨s,hs⟩ - rcases mid with ⟨z,mid⟩ - rcases h with ⟨h,hh⟩ - obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh - subst z - rfl - - -theorem rooted_label_anchor_event_marginal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (B : (I → V) → (I → V) → Prop) - [∀ s h, Decidable (B s h)] : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if B ξ.1.first ξ.1.last then ξ.1.mass (walkKernel G hloc a) else 0) = - ∑' s : segmentAnchors G hloc γ n hdiam center x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if B s.val h.val then mid.2.mass (walkKernel G hloc a) else 0 := by - let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z - let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ - let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x - let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x - rw [←R.symm.tsum_eq] - simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] - unfold RootedLabelCode at * - simp only [tsum_fintype,Fintype.sum_sigma,labelFromCode_anchor_event] - apply Finset.sum_congr rfl - intro s _ - apply Finset.sum_congr rfl - intro mid _ - apply Finset.sum_congr rfl - intro h _ - by_cases hb : B s.val h.val - · simp only [hb,ite_true,Fintype.sum_prod_type,mul_assoc,←Finset.mul_sum,←Finset.sum_mul] - have hl := rawFrom_probability_sum G hloc a m (s.val neg) - have hr := rawFrom_probability_sum G hloc a m (h.val neg) - simp only [tsum_fintype] at hl hr - rw [hl,hr] - ring - · simp only [hb,ite_false,Finset.sum_const_zero] - -end SpineMarginal -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section EndpointMarginal -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] - - -theorem rooted_label_endpoint_marginal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) - (center ep neg : I) (L m : ℕ) (x : V) (S : Finset V) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if ξ.1.last center ∈ S then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = - (∑' s : segmentAnchors G hloc γ n hdiam center x, - ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if h.val center ∈ S then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / - (((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ)* - segmentReturnMass G hloc a γ ep L (γ ep)) := by - simp only [escapeLabelProbability,tsum_indicator_div,tsum_div_const] - rw [rooted_label_anchor_event_marginal G hloc a γ n hdiam center ep neg L m x (fun _ h => h center ∈ S)] - ring - -end EndpointMarginal -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section ActualEndpointSeparation -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - - -theorem rooted_label_endpoint_hit_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (m L : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (S : Finset V) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if ξ.1.last center ∈ S then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 2*c*(S.card:ℝ)*Real.sqrt c*‖P‖^L := by - rw [rooted_label_endpoint_marginal G hloc a γ n hdiam center ep neg L m x S] - have hN : 0 < ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) := by - exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam center (γ center)).mpr - ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) - have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin - P hpos hsym hP hdiag γ ep L - have hqp : 0 < segmentReturnMass G hloc a γ ep L (γ ep) := - (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq - apply (div_le_iff₀ (mul_pos hN hqp)).mpr - have hb (s : segmentAnchors G hloc γ n hdiam center x) : - (∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), - ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, - if h.val center ∈ S then mid.2.mass (walkKernel G hloc a)/ - (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ - (S.card:ℝ)*Real.sqrt c*‖P‖^L := by - have hh := raw_anchor_finite_collision_bound G hloc a root weight Γ hΓ htr (fun r => (hw r).le) - hw1 hcov c hc.le hmin γ n hdiam ep (fun _ : PUnit.{1} => center) (fun z : S => z.val) - P hpos hP L (s.val ep) - simpa [Subtype.exists] using hh - have hu := Finset.sum_le_sum (s := Finset.univ) (fun s _ => hb s) - simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] at hu ⊢ - rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx] at hu - apply hu.trans - have he : 1 ≤ 2*c*segmentReturnMass G hloc a γ ep L (γ ep) := by - have hh := (div_le_iff₀ (by positivity : 0 < 2*c)).mp hq - nlinarith - have hp : 0 ≤ ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ)* - (S.card:ℝ)*Real.sqrt c*‖P‖^L := by positivity - nlinarith [mul_le_mul_of_nonneg_left he hp] - -end ActualEndpointSeparation -end Percolation - - -namespace Percolation -universe u v w -variable {V : Type u} {E : Type v} {I : Type w} -section EndpointBallBound -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Fintype I] {ι : Type*} [Fintype ι] - - -theorem rooted_label_endpoint_ball_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) - (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) - (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) - (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) - (m L : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (r : ℕ) : - (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, - if ξ.1.last center ∈ reachBall G x r then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ - 2*c*(((d+1)^r:ℕ):ℝ)*Real.sqrt c*‖P‖^L := by - have hh := rooted_label_endpoint_hit_bound G hloc a root weight Γ hΓ htr hw hw1 hcov c hc hmin - γ n hdiam center ep neg P hpos hsym hP hdiag m L x hx (finite_reachBall hloc x r).toFinset - have hb : ((finite_reachBall hloc x r).toFinset.card : ℝ) ≤ (((d+1)^r:ℕ):ℝ) := by - exact_mod_cast (by - simpa only [←Set.ncard_eq_toFinset_card] using reachBall_ncard_le_pow G hloc d hd x r) - calc - _ ≤ 2*c*((finite_reachBall hloc x r).toFinset.card:ℝ)*Real.sqrt c*‖P‖^L := by - simpa only [Set.Finite.mem_toFinset] using hh - _ ≤ _ := by gcongr - -end EndpointBallBound -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.PositiveEscapes + +namespace OAI + +/-! Selection Bounds for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +section BothEscapeChoiceOrder + + + +theorem exists_both_escape_uniform_cutoffs (ρ c ε : ℝ) + (hρ : 0 ≤ ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hε : 0 < ε) : + ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∀ L : ℕ, L₀ ≤ L → + 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^L) < ε := by + obtain ⟨J,hJ,L₀,hL₀⟩ := exists_first_escape_uniform_cutoffs ρ c (ε/2) hρ hρ1 hc (by positivity) + refine ⟨J,hJ,L₀,fun L hL => ?_⟩ + have hh := hL₀ L hL + linarith + +end BothEscapeChoiceOrder +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section TailConditioning +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + + +theorem rooted_label_event_of_tail_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (hK : ∀ x y, 0 ≤ walkKernel G hloc a x y) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) + (B : EscapeLabel G γ ep neg L m → Prop) (ε : ℝ) + (hB : ∀ (s : segmentAnchors G hloc γ n hdiam center x) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) + (h : segmentAnchors G hloc γ n hdiam ep mid.1), + (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then + tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0) ≤ ε) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if B ξ.1 then ξ.1.mass (walkKernel G hloc a) else 0) ≤ + ε * ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + ξ.1.mass (walkKernel G hloc a) := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x + rw [←R.symm.tsum_eq,←R.symm.tsum_eq] + simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] + unfold RootedLabelCode at * + simp only [tsum_fintype,Fintype.sum_sigma,Finset.mul_sum] + apply Finset.sum_le_sum + intro s _ + apply Finset.sum_le_sum + intro mid _ + apply Finset.sum_le_sum + intro h _ + have hh := hB s mid h + simp only [tsum_fintype] at hh + have ht : (∑ tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a)) = 1 := by + rw [Fintype.sum_prod_type] + simp only [←Finset.mul_sum,←Finset.sum_mul] + simpa only [tsum_fintype,mul_one] using congrArg₂ (fun r t : ℝ => r*t) + (rawFrom_probability_sum G hloc a m (s.val neg)) + (rawFrom_probability_sum G hloc a m (h.val neg)) + calc + _ = mid.2.mass (walkKernel G hloc a) * + ∑ tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then + tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0 := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro tails _ + split_ifs <;> simp only [mul_zero,mul_assoc] + _ ≤ mid.2.mass (walkKernel G hloc a)*ε := mul_le_mul_of_nonneg_left hh (mid.2.mass_nonneg _ hK) + _ = _ := by + simp only [mul_assoc,←Finset.mul_sum] + rw [ht] + ring + +end TailConditioning +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section NormalizedTailConditioning +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + + +theorem rooted_label_probability_of_tail_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ g ∈ Γ, g (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ i, 1 ≤ c*weight i) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (B : EscapeLabel G γ ep neg L m → Prop) (ε : ℝ) + (hB : ∀ (s : segmentAnchors G hloc γ n hdiam center x) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) + (h : segmentAnchors G hloc γ n hdiam ep mid.1), + (∑' tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg), + if B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 then + tails.1.2.mass (walkKernel G hloc a)*tails.2.2.mass (walkKernel G hloc a) else 0) ≤ ε) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if B ξ.1 then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ ε := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ ep L + have hqp : 0 ≤ segmentReturnMass G hloc a γ ep L (γ ep) := + (one_div_pos.mpr (mul_pos (by norm_num) hc)).le.trans hq + let D := ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) * + ((segmentAnchors G hloc γ n hdiam ep (γ ep)).card : ℝ) * + segmentReturnMass G hloc a γ ep L (γ ep) + have hD : 0 ≤ D := mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) hqp + have hr := rooted_label_event_of_tail_bound G hloc a hK γ n hdiam center ep neg L m x B ε hB + have hs := (rooted_label_probability_hasSum G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq + have hd := div_le_div_of_nonneg_right hr hD + have he : (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + ξ.1.mass (walkKernel G hloc a))/D = 1 := by + simpa only [escapeLabelProbability,tsum_div_const,D] using hs + simpa only [escapeLabelProbability,tsum_indicator_div,tsum_div_const,D, + mul_div_assoc,he,mul_one] using hd + +end NormalizedTailConditioning +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section FullPotentialTests +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + +def labelPotentialFailure (G : BondGraph V E) (p : unitInterval) (γ : I → V) + (ep neg : I) (L m : ℕ) + (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) + (t : ℝ) (ξ : EscapeLabel G γ ep neg L m) : Prop := + (t < ∑ b ∈ F ξ.first ⟨ξ.last ep,ξ.middle⟩ ξ.last, twoPoint G p ξ.leftTail.1 b) ∨ + (t < ∑ b ∈ F ξ.first ⟨ξ.last ep,ξ.middle⟩ ξ.last, twoPoint G p ξ.rightTail.1 b) + +theorem labelFromCode_potential_failure (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) + (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) + (t : ℝ) (s : segmentAnchors G hloc γ n hdiam center x) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) + (h : segmentAnchors G hloc γ n hdiam ep mid.1) + (tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg)) : + labelPotentialFailure G p γ ep neg L m F t + (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1 ↔ + (t < ∑ b ∈ F s.val mid h.val, twoPoint G p tails.1.1 b) ∨ + (t < ∑ b ∈ F s.val mid h.val, twoPoint G p tails.2.1 b) := by + rcases s with ⟨s,hs⟩ + rcases mid with ⟨z,mid⟩ + rcases h with ⟨h,hh⟩ + obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + + + +theorem rooted_label_potential_failure_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (p : unitInterval) (hA : HasKernel G p A) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) + (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if labelPotentialFailure G p γ ep neg L m F t ξ.1 then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 2*(N*Real.sqrt c*‖P‖^m)/t := by + apply rooted_label_probability_of_tail_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx + intro s mid h + simp only [labelFromCode_potential_failure] + have hh := two_raw_tail_potential_failure G hloc a root weight htr hcov (fun r => (hw r).le) hw1 + c hc.le hmin P A hpos hP p hA m (s.val neg) (h.val neg) (F s.val mid h.val) t ht + apply hh.trans + gcongr + exact hN s.val mid h.val + +end FullPotentialTests +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section CombinedSelectionEvents +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + + +theorem rooted_label_collision_potential_failure_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (p : unitInterval) (hA : HasKernel G p A) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (hρ : ‖P‖ < 1) (J : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) + (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) + (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if (labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) ∨ + labelPotentialFailure G p γ ep neg L m F t ξ.1 then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + + 2*(N*Real.sqrt c*‖P‖^m)/t := by + have hK (x y : V) : 0 ≤ walkKernel G hloc a x y := by + simpa only [hP,Complex.ofReal_re] using (hpos x y).2 + have hb := rooted_both_collision_probability_bound G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hw hw1 hcov c hc hmin γ n hdiam center ep neg P hpos hsym hP hdiag hρ m L J x hx posIdx negIdx suffixIdx hsep + have hp := rooted_label_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin + P A hpos hsym hP hdiag p hA γ n hdiam center ep neg L m x hx F N hN t ht + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} + have hu := finite_weighted_event_or + (fun ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} => + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1) + (fun ξ => escapeLabelProbability_nonneg G hloc a hK γ n hdiam center ep neg L m ξ.1) + (fun ξ => labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) + (fun ξ => labelPotentialFailure G p γ ep neg L m F t ξ.1) + simp only [tsum_fintype] at hb hp ⊢ + exact hu.trans (add_le_add hb hp) + +end CombinedSelectionEvents +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section QuantitativeSelectionMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +theorem finite_weighted_success_lower {α : Type*} [Fintype α] + (μ : α → ℝ) (hμ : ∑ a, μ a = 1) (B : α → Prop) [DecidablePred B] (ε : ℝ) + (hB : (∑ a, if B a then μ a else 0) ≤ ε) : + 1-ε ≤ ∑ a, if ¬B a then μ a else 0 := by + have he : (∑ a, if ¬B a then μ a else 0) + (∑ a, if B a then μ a else 0) = 1 := by + rw [←Finset.sum_add_distrib,←hμ] + apply Finset.sum_congr rfl + intro a _ + by_cases h : B a <;> simp only [h,not_true_eq_false,not_false_eq_true,ite_true,ite_false,zero_add,add_zero] + linarith + + + +theorem rooted_label_collision_potential_success_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ r, ∃ g ∈ vertexAut G, g (root r) = x) + (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (P A : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (p : unitInterval) (hA : HasKernel G p A) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (hρ : ‖P‖ < 1) (J : ℕ) (posIdx negIdx suffixIdx : Fin (J+1) → I) + (hsep : ∀ s ∈ segmentOrbit G γ, + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s (posIdx i))) ∧ + (∀ i, J ≤ (openSimpleGraph G Set.univ).dist (s ep) (s (negIdx i))) ∧ + 2*J ≤ (openSimpleGraph G Set.univ).dist (s neg) (s ep)) + (F : (s : I → V) → RawFrom (openSimpleGraph G Set.univ) L (s ep) → (I → V) → Finset V) + (N : ℝ) (hN : ∀ s mid h, ((F s mid h).card : ℝ) ≤ N) (t : ℝ) (ht : 0 < t) : + 1 - (4*c*(earlyCollisionCost ‖P‖ J + suffixCollisionCost ‖P‖ c J*‖P‖^L) + + 2*(N*Real.sqrt c*‖P‖^m)/t) ≤ + ∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if ¬((labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1 ∨ + labelFirstEscapeCollision G γ ep neg J L m posIdx negIdx suffixIdx ξ.1.reverse) ∨ + labelPotentialFailure G p γ ep neg L m F t ξ.1) then + escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0 := by + have hb := rooted_label_collision_potential_failure_bound G hloc a root weight htr hcov hw hw1 c hc hmin + P A hpos hsym hP hdiag p hA γ n hdiam center ep neg L m x hx hρ J posIdx negIdx suffixIdx hsep F N hN t ht + have hs := (rooted_label_probability_hasSum G hloc a root weight (vertexAut G) (Set.Subset.refl _) + htr hcov hw hw1 c hc hmin P hpos hsym hP hdiag γ n hdiam center ep neg L m x hx).tsum_eq + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let := Fintype.ofFinite {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x} + simp only [tsum_fintype] at hs hb ⊢ + exact finite_weighted_success_lower _ hs _ _ hb + +end QuantitativeSelectionMass +end Percolation + + +namespace Percolation +section JointSelectionChoiceOrder + + + +theorem exists_joint_collision_potential_cutoffs (ρ c d τ : ℝ) + (hρ : 0 < ρ) (hρ1 : ρ < 1) (hc : 0 < c) (hd : 0 ≤ d) (hτ : 0 < τ) : + ∃ J : ℕ, 0 < J ∧ ∃ L₀ : ℕ, ∃ C₁ : ℝ, 0 < C₁ ∧ 1 < (-Real.log ρ)*C₁ ∧ + ∃ k₀ : ℕ, J+J+L₀ ≤ k₀ ∧ ∀ k : ℕ, k₀ ≤ k → ∀ R : ℝ, 1 ≤ R → + 4*c*(earlyCollisionCost ρ J + suffixCollisionCost ρ c J*ρ^(k-(J+J))) + + 2*((d+1)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) ≤ 3/8 := by + obtain ⟨J,hJ,L₀,hL₀⟩ := exists_both_escape_uniform_cutoffs ρ c (1/8) hρ.le hρ1 hc (by norm_num) + let A : ℝ := 2*(d+1)*Real.sqrt c/τ + have hA : 0 ≤ A := div_nonneg (mul_nonneg (mul_nonneg (by norm_num) (by linarith)) (Real.sqrt_nonneg _)) hτ.le + obtain ⟨C₁,hC₁,hlam,k₀,hk₀,hk⟩ := exists_uniform_logarithmic_tail_cutoff ρ A hρ hρ1 hA (J+J+L₀) + refine ⟨J,hJ,L₀,C₁,hC₁,hlam,k₀,hk₀,fun k hk' R hR => ?_⟩ + have hL : L₀ ≤ k-(J+J) := by omega + have hb := hL₀ (k-(J+J)) hL + have hp := hk k hk' R hR + have hRp : 0 < R := lt_of_lt_of_le (by norm_num) hR + have he : 2*((d+1)*((k:ℝ)+1)*Real.sqrt c*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊)/(τ/R) = + A*((k:ℝ)+1)*R*ρ^⌈C₁*Real.log (((k:ℝ)+1)*R)⌉₊ := by + dsimp only [A] + field_simp [hτ.ne',hRp.ne'] + rw [he] + linarith + +end JointSelectionChoiceOrder +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section SpineMarginal +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + +theorem labelFromCode_anchor_event (G : BondGraph V E) (hloc : LocallyFinite G) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (B : (I → V) → (I → V) → Prop) + (s : segmentAnchors G hloc γ n hdiam center x) + (mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep)) + (h : segmentAnchors G hloc γ n hdiam ep mid.1) + (tails : RawFrom (openSimpleGraph G Set.univ) m (s.val neg) × + RawFrom (openSimpleGraph G Set.univ) m (h.val neg)) : + B (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1.first + (labelFromCode G hloc γ n hdiam center ep neg L m x ⟨s,mid,h,tails⟩).1.last ↔ B s.val h.val := by + rcases s with ⟨s,hs⟩ + rcases mid with ⟨z,mid⟩ + rcases h with ⟨h,hh⟩ + obtain ⟨_,hhz⟩ := (mem_segmentAnchors G hloc γ n hdiam ep z h).mp hh + subst z + rfl + + +theorem rooted_label_anchor_event_marginal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (B : (I → V) → (I → V) → Prop) + [∀ s h, Decidable (B s h)] : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if B ξ.1.first ξ.1.last then ξ.1.mass (walkKernel G hloc a) else 0) = + ∑' s : segmentAnchors G hloc γ n hdiam center x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if B s.val h.val then mid.2.mass (walkKernel G hloc a) else 0 := by + let (z : V) : Finite ((openSimpleGraph G Set.univ).neighborSet z) := finite_openSimpleGraph_neighbors G hloc z + let (k : ℕ) (z : V) : Fintype (RawFrom (openSimpleGraph G Set.univ) k z) := Fintype.ofFinite _ + let := finite_rootedEscapeLabels G hloc γ n hdiam center ep neg L m x + let R := rootedLabelEquiv G hloc γ n hdiam center ep neg L m x + rw [←R.symm.tsum_eq] + simp only [R,rootedLabelEquiv,Equiv.coe_fn_symm_mk,labelFromCode_mass] + unfold RootedLabelCode at * + simp only [tsum_fintype,Fintype.sum_sigma,labelFromCode_anchor_event] + apply Finset.sum_congr rfl + intro s _ + apply Finset.sum_congr rfl + intro mid _ + apply Finset.sum_congr rfl + intro h _ + by_cases hb : B s.val h.val + · simp only [hb,ite_true,Fintype.sum_prod_type,mul_assoc,←Finset.mul_sum,←Finset.sum_mul] + have hl := rawFrom_probability_sum G hloc a m (s.val neg) + have hr := rawFrom_probability_sum G hloc a m (h.val neg) + simp only [tsum_fintype] at hl hr + rw [hl,hr] + ring + · simp only [hb,ite_false,Finset.sum_const_zero] + +end SpineMarginal +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section EndpointMarginal +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] + + +theorem rooted_label_endpoint_marginal (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) + (center ep neg : I) (L m : ℕ) (x : V) (S : Finset V) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if ξ.1.last center ∈ S then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) = + (∑' s : segmentAnchors G hloc γ n hdiam center x, + ∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if h.val center ∈ S then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) / + (((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ)* + segmentReturnMass G hloc a γ ep L (γ ep)) := by + simp only [escapeLabelProbability,tsum_indicator_div,tsum_div_const] + rw [rooted_label_anchor_event_marginal G hloc a γ n hdiam center ep neg L m x (fun _ h => h center ∈ S)] + ring + +end EndpointMarginal +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section ActualEndpointSeparation +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + + +theorem rooted_label_endpoint_hit_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (m L : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (S : Finset V) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if ξ.1.last center ∈ S then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 2*c*(S.card:ℝ)*Real.sqrt c*‖P‖^L := by + rw [rooted_label_endpoint_marginal G hloc a γ n hdiam center ep neg L m x S] + have hN : 0 < ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ) := by + exact_mod_cast Finset.card_pos.mpr ((segmentAnchors_nonempty_iff G hloc γ n hdiam center (γ center)).mpr + ⟨Equiv.refl V,Equiv.refl E,isAut_refl G,rfl⟩) + have hq := segmentReturnMass_uniform_lower G hloc a root weight Γ hΓ htr hcov hw hw1 c hc hmin + P hpos hsym hP hdiag γ ep L + have hqp : 0 < segmentReturnMass G hloc a γ ep L (γ ep) := + (one_div_pos.mpr (mul_pos (by norm_num) hc)).trans_le hq + apply (div_le_iff₀ (mul_pos hN hqp)).mpr + have hb (s : segmentAnchors G hloc γ n hdiam center x) : + (∑' mid : RawFrom (openSimpleGraph G Set.univ) L (s.val ep), + ∑' h : segmentAnchors G hloc γ n hdiam ep mid.1, + if h.val center ∈ S then mid.2.mass (walkKernel G hloc a)/ + (segmentAnchors G hloc γ n hdiam ep (γ ep)).card else 0) ≤ + (S.card:ℝ)*Real.sqrt c*‖P‖^L := by + have hh := raw_anchor_finite_collision_bound G hloc a root weight Γ hΓ htr (fun r => (hw r).le) + hw1 hcov c hc.le hmin γ n hdiam ep (fun _ : PUnit.{1} => center) (fun z : S => z.val) + P hpos hP L (s.val ep) + simpa [Subtype.exists] using hh + have hu := Finset.sum_le_sum (s := Finset.univ) (fun s _ => hb s) + simp only [tsum_fintype,Finset.sum_const,Finset.card_univ,Fintype.card_coe,nsmul_eq_mul] at hu ⊢ + rw [segmentAnchors_card_on_orbit G hloc γ n hdiam center x hx] at hu + apply hu.trans + have he : 1 ≤ 2*c*segmentReturnMass G hloc a γ ep L (γ ep) := by + have hh := (div_le_iff₀ (by positivity : 0 < 2*c)).mp hq + nlinarith + have hp : 0 ≤ ((segmentAnchors G hloc γ n hdiam center (γ center)).card : ℝ)* + (S.card:ℝ)*Real.sqrt c*‖P‖^L := by positivity + nlinarith [mul_le_mul_of_nonneg_left he hp] + +end ActualEndpointSeparation +end Percolation + + +namespace Percolation +universe u v w +variable {V : Type u} {E : Type v} {I : Type w} +section EndpointBallBound +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Fintype I] {ι : Type*} [Fintype ι] + + +theorem rooted_label_endpoint_ball_bound (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (htr : RootTransport root weight Γ) (hw : ∀ r, 0 < weight r) (hw1 : ∑ r, weight r = 1) + (hcov : ∀ x, ∃ r, ∃ g ∈ Γ, g (root r) = x) + (c : ℝ) (hc : 0 < c) (hmin : ∀ r, 1 ≤ c*weight r) + (γ : I → V) (n : ℕ) (hdiam : ∀ i j, γ j ∈ reachBall G (γ i) n) (center ep neg : I) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (hdiag : ∀ x, 1/2 ≤ (matrixCoeff P x x).re) + (m L : ℕ) (x : V) (hx : x ∈ vertexOrbit G (γ center)) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (r : ℕ) : + (∑' ξ : {ξ : EscapeLabel G γ ep neg L m // ξ.first center = x}, + if ξ.1.last center ∈ reachBall G x r then escapeLabelProbability G hloc a γ n hdiam center ep neg L m ξ.1 else 0) ≤ + 2*c*(((d+1)^r:ℕ):ℝ)*Real.sqrt c*‖P‖^L := by + have hh := rooted_label_endpoint_hit_bound G hloc a root weight Γ hΓ htr hw hw1 hcov c hc hmin + γ n hdiam center ep neg P hpos hsym hP hdiag m L x hx (finite_reachBall hloc x r).toFinset + have hb : ((finite_reachBall hloc x r).toFinset.card : ℝ) ≤ (((d+1)^r:ℕ):ℝ) := by + exact_mod_cast (by + simpa only [←Set.ncard_eq_toFinset_card] using reachBall_ncard_le_pow G hloc d hd x r) + calc + _ ≤ 2*c*((finite_reachBall hloc x r).toFinset.card:ℝ)*Real.sqrt c*‖P‖^L := by + simpa only [Set.Finite.mem_toFinset] using hh + _ ≤ _ := by gcongr + +end EndpointBallBound +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Exploration/FractionalMoments.lean b/lean/OAI/Probability/UnimodularPercolation/Exploration/FractionalMoments.lean index cea62e429347915fef391347e72116bed67ffbab..82fc755eb4f74c5bad31dedce83803424ec55ece 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Exploration/FractionalMoments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Exploration/FractionalMoments.lean @@ -1,1219 +1,1219 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Criticality.Susceptibility - -namespace OAI - -/-! Fractional Moments for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section GhostPowerTransfer -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem sqrt_log_power_bound (h : unitInterval) (hh : 0 < (h:ℝ)) - (a : ℝ) (ha : 1/2 < a) : - Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a ≤ Real.sqrt (1/(2*a-1)) := by - let ε := 2*a-1 - have hε : 0 < ε := by dsimp [ε]; linarith - have hpow := Real.rpow_pos_of_pos hh ε - have hl := Real.log_le_rpow_div (show 0 ≤ 1/(h:ℝ) by positivity) hε - rw [Real.div_rpow (by norm_num) hh.le,Real.one_rpow] at hl - have hpowid : ((h:ℝ)^a)^2 = (h:ℝ)^ε*(h:ℝ) := by - rw [←Real.rpow_natCast,←Real.rpow_mul hh.le] - have he : a*(2:ℝ) = ε+1 := by dsimp [ε]; ring - norm_num only [Nat.cast_ofNat] - rw [he,Real.rpow_add hh,Real.rpow_one] - have hbase : (Real.log (1/(h:ℝ))/(h:ℝ))*((h:ℝ)^a)^2 ≤ 1/ε := by - rw [hpowid] - calc - _ = Real.log (1/(h:ℝ))*(h:ℝ)^ε := by field_simp - _ ≤ ((1/(h:ℝ)^ε)/ε)*(h:ℝ)^ε := mul_le_mul_of_nonneg_right hl hpow.le - _ = 1/ε := by field_simp - have hlog : 0 ≤ Real.log (1/(h:ℝ))/(h:ℝ) := div_nonneg - (Real.log_nonneg ((one_le_div hh).mpr h.2.2)) hh.le - have hsq := Real.sq_sqrt hlog - have htarget := Real.sq_sqrt (one_div_pos.mpr hε).le - have hn := Real.sqrt_nonneg (1/ε) - change _ ≤ Real.sqrt (1/ε) - nlinarith [sq_nonneg (Real.sqrt (1/ε)-Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a)] - - - -theorem markedConnection_power_transfer (G : BondGraph V E) (Q : Finset E) (x : V) - (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (p q h : unitInterval) (hq0 : 0 < (q:ℝ)) (hq1 : (q:ℝ) < 1) - (hp : (q:ℝ)/2 ≤ (p:ℝ)) (hh : 0 < (h:ℝ)) - (a : ℝ) (ha : 1/2 < a) (he : (q:ℝ)-(p:ℝ) = (h:ℝ)^a) : - markedConnectionPolynomial G Q x h q ≤ - Real.exp ((Real.sqrt ((d:ℝ)/2)/(((q:ℝ)/2)*(1-(q:ℝ)))) * - Real.sqrt (1/(2*a-1))) * markedConnectionPolynomial G Q x h p := by - have hp0 : 0 < (p:ℝ) := lt_of_lt_of_le (half_pos hq0) hp - have hpq : p ≤ q := by change (p:ℝ) ≤ (q:ℝ); linarith [Real.rpow_pos_of_pos hh a] - have H := markedConnection_transfer G Q x d hd hdeg p q h hp0 hpq hq1 hh - apply H.trans - apply mul_le_mul_of_nonneg_right - · apply Real.exp_le_exp.mpr - rw [he] - have hr : Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ))) ≤ - Real.sqrt ((d:ℝ)/2)/(((q:ℝ)/2)*(1-(q:ℝ))) := - div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (mul_pos (half_pos hq0) (sub_pos.mpr hq1)) - (mul_le_mul_of_nonneg_right hp (sub_pos.mpr hq1).le) - calc - _ = (Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ)))) * - (Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a) := by ring - _ ≤ _ := mul_le_mul hr (sqrt_log_power_bound h hh a ha) - (mul_nonneg (Real.sqrt_nonneg _) (Real.rpow_nonneg h.2.1 _)) (by positivity) - · rw [markedConnectionPolynomial_eq_tree] - exact ProbeTree.successMass_nonneg p h _ - -end GhostPowerTransfer -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section DyadicGhostParameters -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def dyadicGhost (j : ℕ) : unitInterval := - ⟨(1/2:ℝ)^j,⟨pow_nonneg (by norm_num) _,pow_le_one₀ (by norm_num) (by norm_num)⟩⟩ - -theorem dyadicGhost_pos (j : ℕ) : 0 < (dyadicGhost j:ℝ) := pow_pos (by norm_num) _ - -theorem dyadicGhost_volume (j : ℕ) : (dyadicGhost j:ℝ)*(2^j:ℕ) = 1 := by - simp only [dyadicGhost,Nat.cast_pow,Nat.cast_ofNat,←mul_pow] - norm_num - -theorem tendsto_dyadicGhost : Tendsto (fun j => (dyadicGhost j:ℝ)) atTop (nhds 0) := - tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num) - -theorem dyadicGhost_rpow (j : ℕ) (t : ℝ) : - (dyadicGhost j:ℝ)^t = (2:ℝ)^(-t*(j:ℝ)) := by - change ((1/2:ℝ)^j)^t = _ - rw [←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 1/2)] - rw [show (1/2:ℝ) = (2:ℝ)^(-1:ℝ) by norm_num, - ←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)] - congr 1 - ring - - - -theorem eventually_dyadic_backstep (q : unitInterval) (hq : 0 < (q:ℝ)) - (a : ℝ) (ha : 0 < a) (P : unitInterval → Prop) (hP : ∀ᶠ p in nhds q, P p) : - ∀ᶠ j : ℕ in atTop, ∃ p : unitInterval, - (q:ℝ)/2 ≤ (p:ℝ) ∧ p < q ∧ (q:ℝ)-(p:ℝ) = (dyadicGhost j:ℝ)^a ∧ P p := by - obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp hP - have ht : Tendsto (fun j => (dyadicGhost j:ℝ)^a) atTop (nhds 0) := by - simpa only [Real.zero_rpow ha.ne', Function.comp_apply] using! - (Real.continuousAt_rpow_const 0 a (Or.inr ha.le)).tendsto.comp tendsto_dyadicGhost - filter_upwards [ht.eventually (eventually_lt_nhds (half_pos hq)),ht.eventually (eventually_lt_nhds hε)] with j hj hεj - have hz := Real.rpow_pos_of_pos (dyadicGhost_pos j) a - let p : unitInterval := ⟨(q:ℝ)-(dyadicGhost j:ℝ)^a,⟨by linarith,by linarith [q.2.2]⟩⟩ - refine ⟨p,by dsimp [p]; linarith,by change (q:ℝ)-(dyadicGhost j:ℝ)^a < (q:ℝ); linarith, - by dsimp [p]; ring,?_⟩ - apply hball - change |((q:ℝ)-(dyadicGhost j:ℝ)^a)-(q:ℝ)| < ε - rw [show (q:ℝ)-(dyadicGhost j:ℝ)^a-(q:ℝ) = -(dyadicGhost j:ℝ)^a by ring,abs_neg,abs_of_pos hz] - exact hεj - -end DyadicGhostParameters -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section CriticalDyadicTail -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_dyadic_bound_of_susceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hq0 : 0 < (pc G:ℝ)) (hq1 : (pc G:ℝ) < 1) - (C b a : ℝ) (hC : 0 < C) (ha : 1/2 < a) - (hχ : ∀ᶠ p in nhds (pc G), p < pc G → ∀ x, - susceptibility G p x ≤ C*((pc G:ℝ)-(p:ℝ))^(-b)) : - ∃ K : ℝ, 0 < K ∧ ∀ᶠ j : ℕ in atTop, ∀ x, - clusterWindowProbability G (pc G) x (2^j) (2^(j+1)) ≤ - K*(dyadicGhost j:ℝ)^(1-a*b) := by - obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt - let B := Real.exp ((Real.sqrt ((d:ℝ)/2)/(((pc G:ℝ)/2)*(1-(pc G:ℝ)))) * Real.sqrt (1/(2*a-1))) - have hB : 0 < B := Real.exp_pos _ - refine ⟨2*B*C,by positivity,?_⟩ - filter_upwards [eventually_dyadic_backstep (pc G) hq0 a (by linarith) _ hχ] with j hj - obtain ⟨p,hp,hpc,he,hχp⟩ := hj - intro x - let Q := incidentSupport G hloc (finite_reachBall hloc x (2^(j+1))).toFinset - have hwin := clusterWindow_le_markedConnection G hloc x (2^j) (2^(j+1)) (pc G) (dyadicGhost j) - (by rw [dyadicGhost_volume]) - have htra := markedConnection_power_transfer G Q x d hd - (fun v => (incident_filter_card_le_degree G hloc Q v).trans (hdeg v)) p (pc G) (dyadicGhost j) - hq0 hq1 hp (dyadicGhost_pos j) a ha he - have hsub := markedConnection_le_susceptibility G hloc hqt Q x (dyadicGhost j) p hpc - have hid : (dyadicGhost j:ℝ)*((dyadicGhost j:ℝ)^a)^(-b) = (dyadicGhost j:ℝ)^(1-a*b) := by - rw [←Real.rpow_mul (dyadicGhost j).2.1] - calc - _ = (dyadicGhost j:ℝ)^1*(dyadicGhost j:ℝ)^(a*(-b)) := by rw [Real.rpow_one] - _ = (dyadicGhost j:ℝ)^(1+a*(-b)) := (Real.rpow_add (dyadicGhost_pos j) _ _).symm - _ = _ := by congr 1; ring - calc - _ ≤ 2*markedConnectionPolynomial G Q x (dyadicGhost j) (pc G) := hwin - _ ≤ 2*(B*markedConnectionPolynomial G Q x (dyadicGhost j) p) := - mul_le_mul_of_nonneg_left htra (by norm_num) - _ ≤ 2*(B*((dyadicGhost j:ℝ)*susceptibility G p x)) := - mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hsub hB.le) (by norm_num) - _ ≤ 2*(B*((dyadicGhost j:ℝ)*(C*((pc G:ℝ)-(p:ℝ))^(-b)))) := - mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_left (hχp hpc x) (dyadicGhost j).2.1) hB.le) (by norm_num) - _ = 2*B*C*((dyadicGhost j:ℝ)*((dyadicGhost j:ℝ)^a)^(-b)) := by rw [he]; ring - _ = _ := by rw [hid] - - - -theorem critical_power_integrable_of_dyadic_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (α θ K : ℝ) (hα : 0 < α) (hθ : α < θ) - (hbound : ∀ᶠ j : ℕ in atTop, ∀ x, - clusterWindowProbability G p x (2^j) (2^(j+1)) ≤ K*(dyadicGhost j:ℝ)^θ) : - ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by - intro x - apply integrable_cluster_power_of_dyadic G hloc p x α hα - have hs : Summable (fun j : ℕ => K*((2:ℝ)^(α-θ))^j) := by - apply Summable.mul_left - apply summable_geometric_of_norm_lt_one - rw [Real.norm_of_nonneg (Real.rpow_nonneg (by norm_num) _)] - exact Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (sub_neg.mpr hθ) - apply hs.of_norm_bounded_eventually - rw [Nat.cofinite_eq_atTop] - filter_upwards [hbound] with j hj - rw [Real.norm_of_nonneg (mul_nonneg (Real.rpow_nonneg (by norm_num) _) - (clusterWindowProbability_nonneg G p x _ _))] - calc - _ ≤ (2:ℝ)^(α*(j:ℝ))*(K*(dyadicGhost j:ℝ)^θ) := - mul_le_mul_of_nonneg_left (hj x) (Real.rpow_nonneg (by norm_num) _) - _ = K*((2:ℝ)^(α-θ))^j := by - rw [dyadicGhost_rpow,←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)] - rw [show (α-θ)*(j:ℝ) = α*(j:ℝ)+(-θ*(j:ℝ)) by ring,Real.rpow_add (by norm_num : (0:ℝ)<2)] - ring - -end CriticalDyadicTail -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section MomentFromGrowth -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_moment_of_susceptibility_growth [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hq0 : 0 < (pc G:ℝ)) (hq1 : (pc G:ℝ) < 1) - (hgrowth : ∀ γ : ℝ, 0 < γ → γ < 1 → ∃ C : ℝ, 0 < C ∧ - ∀ᶠ p in nhds (pc G), p < pc G → ∀ x, - susceptibility G p x ≤ C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ))) - (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) : - ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law (pc G)) := by - let γ := (1/2-α)/2 - have hγ : 0 < γ := by dsimp [γ]; linarith - have hγ1 : γ < 1 := by dsimp [γ]; linarith - have hprod : (1/2:ℝ) < (1-γ)*(1-α) := by - have : 0 < γ*α := mul_pos hγ hα - dsimp [γ] at * - nlinarith - obtain ⟨a,ha,hap⟩ := exists_between hprod - have hden : 0 < 1-γ := sub_pos.mpr hγ1 - obtain ⟨C,hC,hnear⟩ := hgrowth γ hγ hγ1 - have he : -(1/(1-γ)) = -1/(1-γ) := by ring - obtain ⟨K,hK,hbound⟩ := critical_dyadic_bound_of_susceptibility G hloc hqt hq0 hq1 - C (1/(1-γ)) a hC ha (by simpa only [he] using hnear) - apply critical_power_integrable_of_dyadic_bound G hloc (pc G) α (1-a*(1/(1-γ))) K hα _ hbound - have : a*(1/(1-γ)) < 1-α := by - rw [mul_one_div] - apply (div_lt_iff₀ hden).mpr - nlinarith [hap] - linarith - -end MomentFromGrowth -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section CriticalRootMoments -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_root_power_integrable - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) : - ∀ i, Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G)) := by - by_contra hbad - have hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G)) := - not_forall.mp hbad - obtain ⟨β,hαβ,hβ⟩ := exists_between hα1 - let ε := (1/2-β)/2 - have hε : 0 < ε := by dsimp [ε]; linarith - have hε1 : ε < 1/2 := by dsimp [ε]; linarith - have hsmall : β+(1/2+ε) < 1 := by dsimp [ε]; linarith - have hg := susceptibility_growth_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr - hcov hw hw1 hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - let c : ℝ := ∑ i, 1/weight i - have hc : 0 < c := Finset.sum_pos (fun i _ => one_div_pos.mpr (hw i)) Finset.univ_nonempty - have hmin (i : ι) : 1 ≤ c*weight i := by - apply (div_le_iff₀ (hw i)).mp - exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) - have hall := critical_moment_of_susceptibility_growth G hloc hqt hp₀ hp₁ (by - intro γ hγ hγ1 - obtain ⟨C,hC,hnear⟩ := hg γ hγ hγ1 - refine ⟨c*C,mul_pos hc hC,?_⟩ - filter_upwards [hnear] with p hp - intro hpc x - calc - _ ≤ c*rootSusceptibility G root weight p := - susceptibility_le_rootSusceptibility G root weight (fun i => (hw i).le) hcover c hc.le hmin p x - _ ≤ c*(C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ))) := mul_le_mul_of_nonneg_left (hp hpc) hc.le - _ = _ := by ring) α hα hα1 - obtain ⟨i,hi⟩ := hdiv - exact hi (hall (root i)) - -end CriticalRootMoments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformFractionalMoments -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_cluster_power (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (α : ℝ) : - Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α) := - (measurable_of_countable (fun n : ℕ => (n:ℝ)^α)).comp (measurable_cluster_ncard G hloc x) - -theorem integrable_cluster_power_covariant [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (α : ℝ) : - Integrable (fun ω => ((cluster G ω (a x)).ncard:ℝ)^α) (law p) ↔ - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by - have h := integrable_map_measure (μ := law p) - (measurable_cluster_power G hloc x α).aestronglyMeasurable - (measurable_set_preimage b).aemeasurable - rw [law_map_preimage_equiv] at h - have he : ((fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α) ∘ (fun ω => b ⁻¹' ω)) = - (fun ω : Set E => ((cluster G ω (a x)).ncard:ℝ)^α) := by - funext ω - dsimp only [Function.comp_apply] - rw [cluster_ncard_covariant G hab] - rw [he] at h - exact h.symm - -theorem integral_cluster_power_covariant [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (α : ℝ) : - (∫ ω, ((cluster G ω (a x)).ncard:ℝ)^α ∂law p) = - ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p := by - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable - (measurable_cluster_power G hloc x α).aestronglyMeasurable - rw [law_map_preimage_equiv] at h - simpa only [cluster_ncard_covariant G hab] using! h.symm - - -theorem uniform_cluster_power_of_root [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (α : ℝ) - (hi : ∀ i, Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : - ∃ C : ℝ, 0 < C ∧ ∀ x, - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) ∧ - (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C := by - let C := 1+∑ i, ∫ ω, ((cluster G ω (root i)).ncard:ℝ)^α ∂law p - have hn (x : V) : 0 ≤ ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p := - integral_nonneg (fun _ => Real.rpow_nonneg (Nat.cast_nonneg _) _) - have hC : 0 < C := by dsimp [C]; linarith [Finset.sum_nonneg (fun i (_ : i ∈ Finset.univ) => hn (root i))] - refine ⟨C,hC,?_⟩ - intro x - obtain ⟨i,a,b,hab,rfl⟩ := hcover x - refine ⟨(integrable_cluster_power_covariant G hloc p hab (root i) α).mpr (hi i),?_⟩ - rw [integral_cluster_power_covariant G hloc p hab] - have hh := Finset.single_le_sum (fun j (_ : j ∈ Finset.univ) => hn (root j)) (Finset.mem_univ i) - dsimp [C] - linarith - -end UniformFractionalMoments -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FractionalMomentCoupling -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem cluster_power_mono_integral [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (p q : unitInterval) (hpq : p ≤ q) - (α : ℝ) (hα : 0 ≤ α) - (hfin : ∀ᵐ ω ∂law q, (cluster G ω x).Finite) - (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law q)) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) ∧ - (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ - ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law q := by - let f (r : unitInterval) (labels : E → unitInterval) := ((cluster G (openEdges labels r) x).ncard:ℝ)^α - have hm (r : unitInterval) : Measurable (f r) := - (measurable_cluster_power G hloc x α).comp (measurable_openEdges r) - have hmap (r : unitInterval) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law r) ↔ Integrable (f r) labelLaw := by - rw [←map_openEdges r] - exact integrable_map_measure (measurable_cluster_power G hloc x α).aestronglyMeasurable - (measurable_openEdges r).aemeasurable - have hf : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), (cluster G (openEdges labels q) x).Finite := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges q).aemeasurable - rwa [map_openEdges] - have hle : f p ≤ᵐ[labelLaw] f q := by - filter_upwards [hf] with labels hlabels - apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hα - exact_mod_cast Set.ncard_le_ncard (show cluster G (openEdges labels p) x ⊆ cluster G (openEdges labels q) x from - fun y hy => conn_mono G (openEdges_mono labels hpq) hy) hlabels - have hiq := (hmap q).mp hi - have hip : Integrable (f p) labelLaw := hiq.mono' (hm p).aestronglyMeasurable (by - filter_upwards [hle] with labels hl - rwa [Real.norm_of_nonneg (Real.rpow_nonneg (Nat.cast_nonneg _) _)] ) - refine ⟨(hmap p).mpr hip,?_⟩ - have he (r : unitInterval) : (∫ labels, f r labels ∂labelLaw) = - ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law r := by - rw [←map_openEdges r] - exact (integral_map (measurable_openEdges r).aemeasurable - (measurable_cluster_power G hloc x α).aestronglyMeasurable).symm - rw [←he p,←he q] - exact integral_mono_ae hip hiq hle - -end FractionalMomentCoupling -end Percolation - - -namespace Percolation -universe u v -variable {E : Type v} -section DecisionCovarianceAlgebra -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteCovariance (Q : Finset E) (p : ℝ) (f g : Finset E → ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => f ω*g ω) p - bernoulliPolynomial Q f p*bernoulliPolynomial Q g p - -noncomputable def coordinateAverage (e : E) (p : ℝ) (f : Finset E → ℝ) (ω : Finset E) : ℝ := - (1-p)*f ω+p*f (insert e ω) - -noncomputable def coordinateVariation (Q : Finset E) (p : ℝ) (f : Finset E → ℝ) (e : E) : ℝ := - bernoulliPolynomial (Q.erase e) (fun ω => |f (insert e ω)-f ω|) p - -theorem bernoulliPolynomial_abs (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) : - |bernoulliPolynomial Q f p| ≤ bernoulliPolynomial Q (fun ω => |f ω|) p := by - rw [abs_le] - constructor - · have h := bernoulliPolynomial_mono Q (fun ω => -|f ω|) f p p.2 - (fun _ _ => neg_abs_le _) - have he : bernoulliPolynomial Q (fun ω => -|f ω|) p = - -bernoulliPolynomial Q (fun ω => |f ω|) p := by - simp only [bernoulliPolynomial,neg_mul,Finset.sum_neg_distrib] - rwa [he] at h - · exact bernoulliPolynomial_mono Q f (fun ω => |f ω|) p p.2 (fun _ _ => le_abs_self _) - -theorem coordinateVariation_nonneg (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) (e : E) : - 0 ≤ coordinateVariation Q p f e := - bernoulliPolynomial_nonneg _ _ p p.2 (fun _ _ => abs_nonneg _) - - -theorem finiteCovariance_first_coordinate (S : Finset E) (e : E) (he : e ∉ S) - (p : ℝ) (f g : Finset E → ℝ) : - finiteCovariance (insert e S) p f g = - (1-p)*finiteCovariance S p (coordinateAverage e p f) g + - p*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω)) + - p*(1-p)*bernoulliPolynomial S - (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p := by - unfold finiteCovariance - rw [bernoulliPolynomial_insert S e he,bernoulliPolynomial_insert S e he, - bernoulliPolynomial_insert S e he] - have hav := bernoulliPolynomial_affine S f (fun ω => f (insert e ω)) (1-p) p p - change bernoulliPolynomial S (coordinateAverage e p f) p = _ at hav - rw [hav] - have h0 : bernoulliPolynomial S (fun ω => coordinateAverage e p f ω*g ω) p = - (1-p)*bernoulliPolynomial S (fun ω => f ω*g ω) p+ - p*bernoulliPolynomial S (fun ω => f (insert e ω)*g ω) p := by - simpa only [coordinateAverage,add_mul,mul_assoc] using - bernoulliPolynomial_affine S (fun ω => f ω*g ω) (fun ω => f (insert e ω)*g ω) (1-p) p p - have h1 : bernoulliPolynomial S (fun ω => coordinateAverage e p f ω*g (insert e ω)) p = - (1-p)*bernoulliPolynomial S (fun ω => f ω*g (insert e ω)) p+ - p*bernoulliPolynomial S (fun ω => f (insert e ω)*g (insert e ω)) p := by - simpa only [coordinateAverage,add_mul,mul_assoc] using - bernoulliPolynomial_affine S (fun ω => f ω*g (insert e ω)) (fun ω => f (insert e ω)*g (insert e ω)) (1-p) p p - rw [h0,h1] - have herr : bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p = - bernoulliPolynomial S (fun ω => f (insert e ω)*g (insert e ω)) p- - bernoulliPolynomial S (fun ω => f (insert e ω)*g ω) p- - bernoulliPolynomial S (fun ω => f ω*g (insert e ω)) p+ - bernoulliPolynomial S (fun ω => f ω*g ω) p := by - simp only [bernoulliPolynomial] - simp only [←Finset.sum_sub_distrib,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro ω _ - ring - rw [herr] - ring - -end DecisionCovarianceAlgebra -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section CoordinateAveragingBounds -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem coordinateVariation_average_le (S : Finset E) (e j : E) (he : e ∉ S) (hje : j ≠ e) - (p : unitInterval) (f : Finset E → ℝ) : - coordinateVariation S p (coordinateAverage e p f) j ≤ coordinateVariation (insert e S) p f j := by - unfold coordinateVariation - rw [Finset.erase_insert_of_ne hje.symm,bernoulliPolynomial_insert _ e (by simp [he])] - let f₀ := fun ω : Finset E => |f (insert j ω)-f ω| - let f₁ := fun ω : Finset E => |f (insert j (insert e ω))-f (insert e ω)| - change _ ≤ (1-(p:ℝ))*bernoulliPolynomial (S.erase j) f₀ p+ - (p:ℝ)*bernoulliPolynomial (S.erase j) f₁ p - rw [←bernoulliPolynomial_affine] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - have hid : coordinateAverage e p f (insert j ω)-coordinateAverage e p f ω = - (1-(p:ℝ))*(f (insert j ω)-f ω)+(p:ℝ)*(f (insert j (insert e ω))-f (insert e ω)) := by - simp only [coordinateAverage,Finset.insert_comm e j] - ring - rw [hid] - calc - _ ≤ |(1-(p:ℝ))*(f (insert j ω)-f ω)|+|(p:ℝ)*(f (insert j (insert e ω))-f (insert e ω))| := abs_add_le _ _ - _ = _ := by rw [abs_mul,abs_mul,abs_of_nonneg (sub_nonneg.mpr p.2.2),abs_of_nonneg p.2.1] - - - -theorem finiteCovariance_first_bound (S : Finset E) (e : E) (he : e ∉ S) - (p : unitInterval) (f g : Finset E → ℝ) - (hg : ∀ ω ⊆ insert e S, g ω ∈ Set.Icc (0:ℝ) 1) : - |finiteCovariance (insert e S) p f g| ≤ - (1-(p:ℝ))*|finiteCovariance S p (coordinateAverage e p f) g|+ - (p:ℝ)*|finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ - (p:ℝ)*(1-(p:ℝ))*coordinateVariation (insert e S) p f e := by - have hgood : |bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| ≤ - coordinateVariation (insert e S) p f e := by - apply (bernoulliPolynomial_abs S p _).trans - unfold coordinateVariation - rw [Finset.erase_insert he] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω hω - rw [abs_mul] - have h₀ := hg ω (hω.trans (Finset.subset_insert _ _)) - have h₁ := hg (insert e ω) (Finset.insert_subset_insert e hω) - have hd : |g (insert e ω)-g ω| ≤ 1 := by rw [abs_le]; constructor <;> linarith [h₀.1,h₀.2,h₁.1,h₁.2] - simpa only [mul_one] using mul_le_mul_of_nonneg_left hd (abs_nonneg (f (insert e ω)-f ω)) - rw [finiteCovariance_first_coordinate S e he] - calc - _ ≤ |(1-(p:ℝ))*finiteCovariance S p (coordinateAverage e p f) g+ - (p:ℝ)*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ - |(p:ℝ)*(1-(p:ℝ))*bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| := abs_add_le _ _ - _ ≤ |(1-(p:ℝ))*finiteCovariance S p (coordinateAverage e p f) g|+ - |(p:ℝ)*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ - |(p:ℝ)*(1-(p:ℝ))*bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| := - add_le_add (abs_add_le _ _) le_rfl - _ ≤ _ := by - rw [abs_mul,abs_mul,abs_mul,abs_of_nonneg (sub_nonneg.mpr p.2.2),abs_of_nonneg p.2.1, - abs_of_nonneg (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))] - exact add_le_add le_rfl (mul_le_mul_of_nonneg_left hgood (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) - -end CoordinateAveragingBounds -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section EdgeDecisionTrees -attribute [local instance] Classical.propDecidable Classical.decEq - - -inductive EdgeQueryTree (E : Type v) where - | done (b : Bool) - | query (e : E) (closed opened : EdgeQueryTree E) - -namespace EdgeQueryTree - -def Valid (Q : Finset E) : EdgeQueryTree E → Prop - | .done _ => True - | .query e t₀ t₁ => e ∈ Q ∧ Valid (Q.erase e) t₀ ∧ Valid (Q.erase e) t₁ - -noncomputable def eval (ω : Finset E) : EdgeQueryTree E → Bool - | .done b => b - | .query e t₀ t₁ => if e ∈ ω then eval ω t₁ else eval ω t₀ - -noncomputable def value (t : EdgeQueryTree E) (ω : Finset E) : ℝ := if t.eval ω then 1 else 0 - -noncomputable def reads (ω : Finset E) (i : E) : EdgeQueryTree E → Prop - | .done _ => False - | .query e t₀ t₁ => i = e ∨ if e ∈ ω then reads ω i t₁ else reads ω i t₀ - -noncomputable def revealment (p : ℝ) (i : E) : EdgeQueryTree E → ℝ - | .done _ => 0 - | .query e t₀ t₁ => if i = e then 1 else (1-p)*revealment p i t₀+p*revealment p i t₁ - -theorem value_mem (t : EdgeQueryTree E) (ω : Finset E) : t.value ω ∈ Set.Icc (0:ℝ) 1 := by - unfold value - split <;> simp - -theorem revealment_nonneg (p : unitInterval) (i : E) (t : EdgeQueryTree E) : 0 ≤ t.revealment p i := by - induction t with - | done => rfl - | query e t₀ t₁ ih₀ ih₁ => - simp only [revealment] - split_ifs - · norm_num - · exact add_nonneg (mul_nonneg (sub_nonneg.mpr p.2.2) ih₀) (mul_nonneg p.2.1 ih₁) - -theorem eval_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) : t.eval ω = t.eval η := by - induction t generalizing Q with - | done => rfl - | query e t₀ t₁ ih₀ ih₁ => - simp only [eval,h e ht.1] - split - · exact ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha)) - · exact ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha)) - -theorem eval_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {e : E} (he : e ∉ Q) (ω : Finset E) : t.eval (insert e ω) = t.eval ω := by - apply eval_congr t ht - intro a ha - simp [show a ≠ e from fun h => he (h ▸ ha)] - -theorem value_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {e : E} (he : e ∉ Q) (ω : Finset E) : t.value (insert e ω) = t.value ω := by - simp only [value,eval_insert t ht he] - -theorem reads_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) (i : E) : t.reads ω i ↔ t.reads η i := by - induction t generalizing Q with - | done => rfl - | query e t₀ t₁ ih₀ ih₁ => - simp only [reads,h e ht.1] - split - · rw [ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha))] - · rw [ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha))] - -theorem reads_mem (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (ω : Finset E) (i : E) (hi : t.reads ω i) : i ∈ Q := by - induction t generalizing Q with - | done => exact hi.elim - | query e t₀ t₁ ih₀ ih₁ => - rcases hi with rfl | hi - · exact ht.1 - · split_ifs at hi - · exact Finset.mem_of_mem_erase (ih₁ ht.2.2 hi) - · exact Finset.mem_of_mem_erase (ih₀ ht.2.1 hi) - -end EdgeQueryTree -end EdgeDecisionTrees -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section EdgeTreeCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteCovariance_congr_right (Q : Finset E) (p : ℝ) (f : Finset E → ℝ) - {g h : Finset E → ℝ} (he : ∀ ω ⊆ Q, g ω = h ω) : - finiteCovariance Q p f g = finiteCovariance Q p f h := by - unfold finiteCovariance - rw [bernoulliPolynomial_congr Q (fun ω hω => congrArg (f ω * ·) (he ω hω)), - bernoulliPolynomial_congr Q he] - -namespace EdgeQueryTree - - - -theorem covariance_bound (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (f : Finset E → ℝ) : - |finiteCovariance Q p f t.value| ≤ - ∑ i ∈ Q, t.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by - induction t generalizing Q f with - | done b => - have hv : (done b : EdgeQueryTree E).value = (fun _ => if b then (1:ℝ) else 0) := rfl - rw [hv] - cases b - · simp [finiteCovariance,revealment] - · simp [finiteCovariance,revealment,bernoulliPolynomial_const] - | query e t₀ t₁ ih₀ ih₁ => - have he := ht.1 - have heS : e ∉ Q.erase e := Finset.notMem_erase _ _ - have hQ : insert e (Q.erase e) = Q := Finset.insert_erase he - let fav := coordinateAverage e (p:ℝ) f - have hcov₀ : finiteCovariance (Q.erase e) p fav (query e t₀ t₁).value = - finiteCovariance (Q.erase e) p fav t₀.value := by - apply finiteCovariance_congr_right - intro ω hω - have heω : e ∉ ω := fun h => heS (hω h) - simp only [value,eval,ite_eq_right heω] - have hcov₁ : finiteCovariance (Q.erase e) p fav (fun ω => (query e t₀ t₁).value (insert e ω)) = - finiteCovariance (Q.erase e) p fav t₁.value := by - apply finiteCovariance_congr_right - intro ω _ - simp only [value,eval,Finset.mem_insert_self,ite_true,eval_insert t₁ ht.2.2 heS] - have hav (i : E) (hi : i ∈ Q.erase e) : - coordinateVariation (Q.erase e) p fav i ≤ coordinateVariation Q p f i := by - simpa only [hQ] using coordinateVariation_average_le (Q.erase e) e i heS - (Finset.ne_of_mem_erase hi) p f - have hb₀ : |finiteCovariance (Q.erase e) p fav t₀.value| ≤ - ∑ i ∈ Q.erase e, t₀.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by - apply (ih₀ ht.2.1 fav).trans - apply Finset.sum_le_sum - intro i hi - exact mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_left (hav i hi) (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) - (revealment_nonneg p i t₀) - have hb₁ : |finiteCovariance (Q.erase e) p fav t₁.value| ≤ - ∑ i ∈ Q.erase e, t₁.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by - apply (ih₁ ht.2.2 fav).trans - apply Finset.sum_le_sum - intro i hi - exact mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_left (hav i hi) (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) - (revealment_nonneg p i t₁) - have hfirst := finiteCovariance_first_bound (Q.erase e) e heS p f (query e t₀ t₁).value - (fun ω _ => value_mem _ ω) - change _ ≤ (1-(p:ℝ))*|finiteCovariance (Q.erase e) p fav (query e t₀ t₁).value|+ - (p:ℝ)*|finiteCovariance (Q.erase e) p fav (fun ω => (query e t₀ t₁).value (insert e ω))|+_ at hfirst - rw [hQ,hcov₀,hcov₁] at hfirst - apply hfirst.trans - calc - _ ≤ (1-(p:ℝ))*(∑ i ∈ Q.erase e, t₀.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i))+ - (p:ℝ)*(∑ i ∈ Q.erase e, t₁.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i))+ - (p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f e := - add_le_add (add_le_add (mul_le_mul_of_nonneg_left hb₀ (sub_nonneg.mpr p.2.2)) - (mul_le_mul_of_nonneg_left hb₁ p.2.1)) le_rfl - _ = _ := by - rw [←Finset.sum_erase_add _ _ he] - congr 1 - · rw [Finset.mul_sum,Finset.mul_sum,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro i hi - rw [revealment,ite_eq_right (Finset.ne_of_mem_erase hi)] - ring - · simp [revealment] - -end EdgeQueryTree -end EdgeTreeCovariance -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section RevealmentProbability -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EdgeQueryTree - -theorem reads_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {e : E} (he : e ∉ Q) (ω : Finset E) (i : E) : t.reads (insert e ω) i ↔ t.reads ω i := by - apply reads_congr t ht - intro a ha - simp [show a ≠ e from fun h => he (h ▸ ha)] - - -theorem revealment_eq_probability (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : ℝ) (i : E) : - t.revealment p i = bernoulliPolynomial Q (fun ω => if t.reads ω i then 1 else 0) p := by - induction t generalizing Q with - | done => simp [revealment,reads] - | query e t₀ t₁ ih₀ ih₁ => - by_cases hie : i = e - · subst i - simp [revealment,reads,bernoulliPolynomial_const] - · have heS : e ∉ Q.erase e := Finset.notMem_erase _ _ - conv_rhs => rw [←Finset.insert_erase ht.1] - rw [bernoulliPolynomial_insert _ e heS] - simp only [revealment,ite_eq_right hie] - rw [ih₀ ht.2.1,ih₁ ht.2.2] - congr 1 - · congr 1 - apply bernoulliPolynomial_congr - intro ω hω - have heω : e ∉ ω := fun h => heS (hω h) - simp only [reads,hie,false_or,ite_eq_right heω] - · congr 1 - apply bernoulliPolynomial_congr - intro ω _ - simp only [reads,hie,false_or,Finset.mem_insert_self,ite_true,reads_insert t₁ ht.2.2 heS] - -end EdgeQueryTree -end RevealmentProbability -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SeededEdgeSearch -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def seededEdgeSearch (G : BondGraph V E) (x : V) : - ℕ → Finset E → Finset V → EdgeQueryTree E - | 0, _, R => .done (decide (x ∈ R)) - | n+1, Q, R => - if hc : SearchCrossing G Q R then - let t := searchCrossing G Q R hc - .query t.1 (seededEdgeSearch G x n (Q.erase t.1) R) - (seededEdgeSearch G x n (Q.erase t.1) (insert t.2.2 R)) - else .done (decide (x ∈ R)) - -theorem seededEdgeSearch_valid (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) : - (seededEdgeSearch G x n Q R).Valid Q := by - induction n generalizing Q R with - | zero => trivial - | succ n ih => - simp only [seededEdgeSearch] - split_ifs with hc - · exact ⟨(searchCrossing_spec G Q R hc).1,ih _ _,ih _ _⟩ - · trivial - -theorem seedMarked_singleton_of_no_crossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (x : V) (h : ¬ SearchCrossing G Q R) (ω : Finset E) (hω : ω ⊆ Q) : - SeedMarked G (ω : Set E) R {x} ↔ x ∈ R := by - constructor - · intro hx - by_contra hn - exact seedMarked_false_of_no_crossing G Q R {x} h (by simpa using hn) ω hω hx - · intro hx - exact ⟨x,hx,x,Finset.mem_singleton_self x,conn_refl G _ x⟩ - - -theorem seededEdgeSearch_correct (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) - (hn : Q.card ≤ n) (ω : Finset E) (hω : ω ⊆ Q) : - (seededEdgeSearch G x n Q R).eval ω = true ↔ SeedMarked G (ω : Set E) R {x} := by - induction n generalizing Q R ω with - | zero => - have hQ : Q = ∅ := Finset.card_eq_zero.mp (by omega) - simp only [seededEdgeSearch,EdgeQueryTree.eval,decide_eq_true_eq] - exact (seedMarked_singleton_of_no_crossing G Q R x (by simp [SearchCrossing,hQ]) ω hω).symm - | succ n ih => - simp only [seededEdgeSearch] - split_ifs with hc - · obtain ⟨he,ha,hb,hends⟩ := searchCrossing_spec G Q R hc - have hcard : (Q.erase (searchCrossing G Q R hc).1).card ≤ n := by - rw [Finset.card_erase_of_mem he]; omega - simp only [EdgeQueryTree.eval] - by_cases heω : (searchCrossing G Q R hc).1 ∈ ω - · simp only [ite_eq_left heω] - rw [←Finset.insert_erase heω,Finset.coe_insert,seedMarked_insert_edge G _ R {x} _ _ _ ha hends, - EdgeQueryTree.eval_insert _ (seededEdgeSearch_valid G x n _ _) (Finset.notMem_erase _ _)] - exact ih _ _ hcard _ (Finset.erase_subset_erase _ hω) - · simp only [ite_eq_right heω] - exact ih _ _ hcard ω (Finset.subset_erase.mpr ⟨hω,heω⟩) - · simp only [EdgeQueryTree.eval,decide_eq_true_eq] - exact (seedMarked_singleton_of_no_crossing G Q R x hc ω hω).symm - - - -theorem seededEdgeSearch_reads (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) - (ω : Finset E) (i : E) (hi : (seededEdgeSearch G x n Q R).reads ω i) : - ∃ a ∈ G i, ∃ r ∈ R, Conn G (ω : Set E) r a := by - induction n generalizing Q R with - | zero => exact hi.elim - | succ n ih => - simp only [seededEdgeSearch] at hi - split_ifs at hi with hc - · obtain ⟨he,ha,hb,hends⟩ := searchCrossing_spec G Q R hc - rcases hi with rfl | hi - · refine ⟨(searchCrossing G Q R hc).2.1,?_,_,ha,conn_refl G _ _⟩ - rw [hends]; simp - · split_ifs at hi with heω - · obtain ⟨a,hai,r,hr,hra⟩ := ih _ _ hi - rcases Finset.mem_insert.mp hr with rfl | hr - · refine ⟨a,hai,(searchCrossing G Q R hc).2.1,ha,?_⟩ - exact (Relation.ReflTransGen.single ⟨(searchCrossing G Q R hc).1,heω,hends⟩).trans hra - · exact ⟨a,hai,r,hr,hra⟩ - · exact ih _ _ hi - · exact hi.elim - -end SeededEdgeSearch -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RandomizedDecisionCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteCovariance_average_right (Q : Finset E) (F : Finset V) (p h : ℝ) - (f : Finset E → ℝ) (g : Finset V → Finset E → ℝ) : - finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => g m ω) h) = - bernoulliPolynomial F (fun m => finiteCovariance Q p f (g m)) h := by - unfold finiteCovariance - rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul, - ←bernoulliPolynomial_commute Q F (fun ω m => g m ω) p h] - congr 1 - calc - _ = bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => f ω*g m ω) h) p := by - apply bernoulliPolynomial_congr - intro ω _ - exact (bernoulliPolynomial_const_mul F (fun m => g m ω) (f ω) h).symm - _ = _ := bernoulliPolynomial_commute Q F _ p h - - - -theorem EdgeQueryTree.randomized_covariance_bound (Q : Finset E) (F : Finset V) - (p h : unitInterval) (f : Finset E → ℝ) (trees : Finset V → EdgeQueryTree E) - (ht : ∀ m ⊆ F, (trees m).Valid Q) : - |finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => (trees m).value ω) h)| ≤ - ∑ i ∈ Q, bernoulliPolynomial F (fun m => (trees m).revealment p i) h * - ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by - rw [finiteCovariance_average_right] - apply (bernoulliPolynomial_abs F h _).trans - calc - _ ≤ bernoulliPolynomial F (fun m => ∑ i ∈ Q, (trees m).revealment p i * - ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i)) h := by - apply bernoulliPolynomial_mono _ _ _ h h.2 - intro m hm - exact (trees m).covariance_bound (ht m hm) p f - _ = _ := by simp only [bernoulliPolynomial_sum,bernoulliPolynomial_mul_const] - -noncomputable def finiteSeedProbability (G : BondGraph V E) (F : Finset V) - (ω : Finset E) (x : V) (h : ℝ) : ℝ := - bernoulliPolynomial F (fun m => if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0) h - -theorem seededEdgeSearch_value (G : BondGraph V E) (x : V) (Q : Finset E) - (m : Finset V) (ω : Finset E) (hω : ω ⊆ Q) : - (seededEdgeSearch G x Q.card Q m).value ω = - if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0 := by - have hc := seededEdgeSearch_correct G x Q.card Q m le_rfl ω hω - have he : SeedMarked G (ω:Set E) m {x} ↔ ∃ y ∈ m, Conn G (ω:Set E) x y := by - simp only [SeedMarked,Finset.mem_singleton,exists_eq_left] - exact exists_congr (fun y => and_congr_right (fun _ => ⟨conn_symm G _,conn_symm G _⟩)) - unfold EdgeQueryTree.value - simp only [hc,he] - -theorem finiteSeedProbability_tree (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (h : ℝ) (ω : Finset E) (hω : ω ⊆ Q) : - finiteSeedProbability G F ω x h = - bernoulliPolynomial F (fun m => (seededEdgeSearch G x Q.card Q m).value ω) h := by - apply bernoulliPolynomial_congr - intro m _ - exact (seededEdgeSearch_value G x Q m ω hω).symm - -end RandomizedDecisionCovariance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SeedRevealmentBounds -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem seededEdgeSearch_reads_endpoints (G : BondGraph V E) (x : V) (Q : Finset E) - (m : Finset V) (ω : Finset E) (i : E) (a b : V) (he : G i = s(a,b)) - (hi : (seededEdgeSearch G x Q.card Q m).reads ω i) : - (∃ y ∈ m, Conn G (ω:Set E) a y) ∨ (∃ y ∈ m, Conn G (ω:Set E) b y) := by - obtain ⟨z,hz,r,hr,hrz⟩ := seededEdgeSearch_reads G x Q.card Q m ω i hi - rw [he] at hz - rcases (by simpa using hz : z = a ∨ z = b) with rfl | rfl - · exact Or.inl ⟨r,hr,conn_symm G _ hrz⟩ - · exact Or.inr ⟨r,hr,conn_symm G _ hrz⟩ - -theorem seededEdgeSearch_mean_revealment_le (G : BondGraph V E) (x : V) - (Q : Finset E) (F : Finset V) (p h : unitInterval) (i : E) (a b : V) (he : G i = s(a,b)) : - bernoulliPolynomial F (fun m => (seededEdgeSearch G x Q.card Q m).revealment p i) h ≤ - bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω a h) p + - bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω b h) p := by - simp_rw [EdgeQueryTree.revealment_eq_probability _ (seededEdgeSearch_valid G x Q.card Q _)] - rw [←bernoulliPolynomial_commute,←bernoulliPolynomial_add] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - unfold finiteSeedProbability - rw [←bernoulliPolynomial_add] - apply bernoulliPolynomial_mono _ _ _ h h.2 - intro m _ - have hr := seededEdgeSearch_reads_endpoints G x Q m ω i a b he - by_cases hread : (seededEdgeSearch G x Q.card Q m).reads ω i - · rcases hr hread with ha | hb - · simp only [ite_eq_left hread,ite_eq_left ha] - split_ifs <;> norm_num - · simp only [ite_eq_left hread,ite_eq_left hb] - split_ifs <;> norm_num - · simp only [ite_eq_right hread] - split_ifs <;> norm_num - - - -theorem finiteSeedProbability_component (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (hF : insert x (searchVertices G Q) ⊆ F) - (ω : Finset E) (hω : ω ⊆ Q) (h : ℝ) : - finiteSeedProbability G F ω x h = 1-(1-h)^(finiteRootComponent G ω x).card := by - let C := finiteRootComponent G ω x - have hCF : C ⊆ F := finiteRootComponent_subset G Q F x ω hω hF - have he (m : Finset V) : (∃ y ∈ m, Conn G (ω:Set E) x y) ↔ m ∩ C ≠ ∅ := by - rw [Finset.nonempty_iff_ne_empty.symm] - constructor - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,Finset.mem_inter.mpr ⟨hy,by change y ∈ (C:Set V); simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hxy⟩⟩ - · rintro ⟨y,hy⟩ - refine ⟨y,(Finset.mem_inter.mp hy).1,?_⟩ - have hm : y ∈ (C:Set V) := (Finset.mem_inter.mp hy).2 - simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hm - calc - _ = bernoulliPolynomial F (fun m => 1-(if m ∩ C = ∅ then 1 else 0)) h := by - apply bernoulliPolynomial_congr - intro m _ - by_cases hm : m ∩ C = ∅ - · have hn : ¬∃ y ∈ m, Conn G (ω:Set E) x y := fun hc => (he m).mp hc hm - simp only [hm,hn,ite_false,ite_true,sub_self] - · have hy := (he m).mpr hm - simp only [hm,hy,ite_false,ite_true,sub_zero] - _ = 1-bernoulliPolynomial F (fun m => if m ∩ C = ∅ then 1 else 0) h := by - rw [bernoulliPolynomial_sub,bernoulliPolynomial_const] - _ = _ := by rw [bernoulliPolynomial_restrict C F hCF (fun m => if m = ∅ then 1 else 0) h, - bernoulliPolynomial_empty_indicator] - -end SeedRevealmentBounds -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section GhostFractionalPower -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem one_sub_pow_one_sub_le_power (h : unitInterval) (n : ℕ) (α : ℝ) - (hα : 0 ≤ α) (hα1 : α ≤ 1) : - 1-(1-(h:ℝ))^n ≤ (h:ℝ)^α*(n:ℝ)^α := by - rw [←Real.mul_rpow h.2.1 (Nat.cast_nonneg _)] - by_cases ht : (h:ℝ)*n ≤ 1 - · exact (one_sub_pow_one_sub_le h n).trans (Real.self_le_rpow_of_le_one (mul_nonneg h.2.1 (Nat.cast_nonneg _)) ht hα1) - · have ht' : 1 ≤ (h:ℝ)*n := (lt_of_not_ge ht).le - exact (sub_le_self _ (pow_nonneg (sub_nonneg.mpr h.2.2) _)).trans (Real.one_le_rpow ht' hα) - -theorem markedConnection_le_cluster_power (G : BondGraph V E) (Q : Finset E) - (x : V) (h p : unitInterval) (α : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : - markedConnectionPolynomial G Q x h p ≤ (h:ℝ)^α*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by - rw [markedConnection_integral,←integral_const_mul] - apply integral_mono_ae - · exact integrable_finite_local Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]) - · exact hi.const_mul _ - · filter_upwards [hfin] with ω hω - apply (one_sub_pow_one_sub_le_power h _ α hα hα1).trans - apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg h.2.1 _) - apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hα - exact_mod_cast Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω - -theorem finiteSeedProbability_expectation (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (hF : insert x (searchVertices G Q) ⊆ F) (h p : ℝ) : - bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω x h) p = - markedConnectionPolynomial G Q x h p := by - rw [markedConnection_component_polynomial] - apply bernoulliPolynomial_congr - intro ω hω - exact finiteSeedProbability_component G Q F x hF ω hω h - -theorem finiteSeedProbability_le_cluster_power (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (hF : insert x (searchVertices G Q) ⊆ F) (h p : unitInterval) - (α : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : - bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω x h) p ≤ - (h:ℝ)^α*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by - rw [finiteSeedProbability_expectation G Q F x hF] - exact markedConnection_le_cluster_power G Q x h p α hα hα1 hfin hi - -end GhostFractionalPower -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section MonotoneDecisionRusso -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem sum_coordinateVariation_eq_deriv (Q : Finset E) (f : Finset E → ℝ) - (hf : Monotone f) (p : ℝ) : - (∑ i ∈ Q, coordinateVariation Q p f i) = deriv (bernoulliPolynomial Q f) p := by - rw [(hasDerivAt_bernoulliPolynomial Q f p).deriv] - apply Finset.sum_congr rfl - intro i _ - apply bernoulliPolynomial_congr - intro ω _ - exact abs_of_nonneg (sub_nonneg.mpr (hf (Finset.subset_insert _ _))) - -theorem EdgeQueryTree.randomized_covariance_le_deriv (Q : Finset E) (F : Finset V) - (p h : unitInterval) (f : Finset E → ℝ) (hf : Monotone f) - (trees : Finset V → EdgeQueryTree E) (ht : ∀ m ⊆ F, (trees m).Valid Q) - (R : ℝ) (hR : ∀ i ∈ Q, bernoulliPolynomial F (fun m => (trees m).revealment p i) h ≤ R) : - |finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => (trees m).value ω) h)| ≤ - R*((p:ℝ)*(1-(p:ℝ)))*deriv (bernoulliPolynomial Q f) p := by - apply (randomized_covariance_bound Q F p h f trees ht).trans - calc - _ ≤ ∑ i ∈ Q, R*((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by - apply Finset.sum_le_sum - intro i hi - exact mul_le_mul_of_nonneg_right (hR i hi) - (mul_nonneg (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2)) (coordinateVariation_nonneg Q p f i)) - _ = _ := by simp only [←mul_assoc,←Finset.mul_sum,sum_coordinateVariation_eq_deriv Q f hf] - - - -theorem seededEdgeSearch_revealment_of_moments (G : BondGraph V E) (Q : Finset E) - (x : V) (p h : unitInterval) (α C : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) : - ∀ i ∈ Q, bernoulliPolynomial (insert x (searchVertices G Q)) - (fun m => (seededEdgeSearch G x Q.card Q m).revealment p i) h ≤ 2*C*(h:ℝ)^α := by - intro i hi - obtain ⟨⟨a,b⟩,he⟩ := Quot.exists_rep (G i) - have he' : G i = s(a,b) := he.symm - have hFa : insert a (searchVertices G Q) ⊆ insert x (searchVertices G Q) := - Finset.insert_subset_iff.mpr ⟨Finset.mem_insert_of_mem (mem_searchVertices G hi (by rw [he']; simp)),Finset.subset_insert _ _⟩ - have hFb : insert b (searchVertices G Q) ⊆ insert x (searchVertices G Q) := - Finset.insert_subset_iff.mpr ⟨Finset.mem_insert_of_mem (mem_searchVertices G hi (by rw [he']; simp)),Finset.subset_insert _ _⟩ - have ha := finiteSeedProbability_le_cluster_power G Q _ a hFa h p α hα hα1 (hfin a) (hI a) - have hb := finiteSeedProbability_le_cluster_power G Q _ b hFb h p α hα hα1 (hfin b) (hI b) - have hca := mul_le_mul_of_nonneg_left (hC a) (Real.rpow_nonneg h.2.1 α) - have hcb := mul_le_mul_of_nonneg_left (hC b) (Real.rpow_nonneg h.2.1 α) - have hr := seededEdgeSearch_mean_revealment_le G x Q (insert x (searchVertices G Q)) p h i a b he' - linarith - -theorem finiteSeed_covariance_upper (G : BondGraph V E) (Q : Finset E) (x : V) - (p h : unitInterval) (α C : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) - (f : Finset E → ℝ) (hf : Monotone f) : - |finiteCovariance Q p f (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h)| ≤ - (2*C*(h:ℝ)^α)*((p:ℝ)*(1-(p:ℝ)))*deriv (bernoulliPolynomial Q f) p := by - have hc := EdgeQueryTree.randomized_covariance_le_deriv Q (insert x (searchVertices G Q)) p h f hf - (fun m => seededEdgeSearch G x Q.card Q m) (fun _ _ => seededEdgeSearch_valid G x Q.card Q _) - (2*C*(h:ℝ)^α) (seededEdgeSearch_revealment_of_moments G Q x p h α C hα hα1 hfin hI hC) - convert hc using 2 - apply finiteCovariance_congr_right - intro ω hω - exact finiteSeedProbability_tree G Q _ x h ω hω - -end MonotoneDecisionRusso -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterTailCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteClusterTailIndicator (G : BondGraph V E) (x : V) (n : ℕ) - (ω : Finset E) : ℝ := if n ≤ (finiteRootComponent G ω x).card then 1 else 0 - -noncomputable def finiteClusterTail (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : ℝ) : ℝ := - bernoulliPolynomial Q (finiteClusterTailIndicator G x n) p - -theorem finiteClusterTailIndicator_mono (G : BondGraph V E) (x : V) (n : ℕ) : - Monotone (finiteClusterTailIndicator G x n) := by - intro ω η hωη - have hc := Finset.card_le_card (finiteRootComponent_mono G hωη x) - unfold finiteClusterTailIndicator - split_ifs <;> norm_num - omega - -theorem finiteClusterTail_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : unitInterval) : - 0 ≤ finiteClusterTail G Q x n p := by - apply bernoulliPolynomial_nonneg _ _ p p.2 - intro ω _ - unfold finiteClusterTailIndicator - split_ifs <;> norm_num - -theorem finiteClusterTail_deriv_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : unitInterval) : - 0 ≤ deriv (finiteClusterTail G Q x n) p := by - change 0 ≤ deriv (bernoulliPolynomial Q (finiteClusterTailIndicator G x n)) p - rw [←sum_coordinateVariation_eq_deriv Q _ (finiteClusterTailIndicator_mono G x n)] - exact Finset.sum_nonneg (fun i _ => coordinateVariation_nonneg Q p _ i) - - - -theorem finiteSeed_covariance_lower (G : BondGraph V E) (Q : Finset E) (x : V) - (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) (B : ℝ) - (hB : markedConnectionPolynomial G Q x h p ≤ B) : - (1/2-B)*finiteClusterTail G Q x n p ≤ finiteCovariance Q p - (finiteClusterTailIndicator G x n) - (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h) := by - have hprod : (1:ℝ)/2*finiteClusterTail G Q x n p ≤ - bernoulliPolynomial Q (fun ω => finiteClusterTailIndicator G x n ω* - finiteSeedProbability G (insert x (searchVertices G Q)) ω x h) p := by - rw [finiteClusterTail,←bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω hω - rw [finiteSeedProbability_component G Q _ x le_rfl ω hω] - unfold finiteClusterTailIndicator - by_cases hsize : n ≤ (finiteRootComponent G ω x).card - · simp only [ite_eq_left hsize,mul_one,one_mul] - apply one_sub_pow_one_sub_ge_half - exact hn.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hsize) h.2.1) - · simp only [ite_eq_right hsize,mul_zero,zero_mul,le_refl] - have hmean := finiteSeedProbability_expectation G Q (insert x (searchVertices G Q)) x le_rfl (h:ℝ) p - unfold finiteCovariance - rw [hmean] - change _ ≤ _-finiteClusterTail G Q x n p*markedConnectionPolynomial G Q x h p - have hm := mul_le_mul_of_nonneg_left hB (finiteClusterTail_nonneg G Q x n p) - nlinarith - -end ClusterTailCovariance -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Criticality.Susceptibility + +namespace OAI + +/-! Fractional Moments for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section GhostPowerTransfer +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem sqrt_log_power_bound (h : unitInterval) (hh : 0 < (h:ℝ)) + (a : ℝ) (ha : 1/2 < a) : + Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a ≤ Real.sqrt (1/(2*a-1)) := by + let ε := 2*a-1 + have hε : 0 < ε := by dsimp [ε]; linarith + have hpow := Real.rpow_pos_of_pos hh ε + have hl := Real.log_le_rpow_div (show 0 ≤ 1/(h:ℝ) by positivity) hε + rw [Real.div_rpow (by norm_num) hh.le,Real.one_rpow] at hl + have hpowid : ((h:ℝ)^a)^2 = (h:ℝ)^ε*(h:ℝ) := by + rw [←Real.rpow_natCast,←Real.rpow_mul hh.le] + have he : a*(2:ℝ) = ε+1 := by dsimp [ε]; ring + norm_num only [Nat.cast_ofNat] + rw [he,Real.rpow_add hh,Real.rpow_one] + have hbase : (Real.log (1/(h:ℝ))/(h:ℝ))*((h:ℝ)^a)^2 ≤ 1/ε := by + rw [hpowid] + calc + _ = Real.log (1/(h:ℝ))*(h:ℝ)^ε := by field_simp + _ ≤ ((1/(h:ℝ)^ε)/ε)*(h:ℝ)^ε := mul_le_mul_of_nonneg_right hl hpow.le + _ = 1/ε := by field_simp + have hlog : 0 ≤ Real.log (1/(h:ℝ))/(h:ℝ) := div_nonneg + (Real.log_nonneg ((one_le_div hh).mpr h.2.2)) hh.le + have hsq := Real.sq_sqrt hlog + have htarget := Real.sq_sqrt (one_div_pos.mpr hε).le + have hn := Real.sqrt_nonneg (1/ε) + change _ ≤ Real.sqrt (1/ε) + nlinarith [sq_nonneg (Real.sqrt (1/ε)-Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a)] + + + +theorem markedConnection_power_transfer (G : BondGraph V E) (Q : Finset E) (x : V) + (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (p q h : unitInterval) (hq0 : 0 < (q:ℝ)) (hq1 : (q:ℝ) < 1) + (hp : (q:ℝ)/2 ≤ (p:ℝ)) (hh : 0 < (h:ℝ)) + (a : ℝ) (ha : 1/2 < a) (he : (q:ℝ)-(p:ℝ) = (h:ℝ)^a) : + markedConnectionPolynomial G Q x h q ≤ + Real.exp ((Real.sqrt ((d:ℝ)/2)/(((q:ℝ)/2)*(1-(q:ℝ)))) * + Real.sqrt (1/(2*a-1))) * markedConnectionPolynomial G Q x h p := by + have hp0 : 0 < (p:ℝ) := lt_of_lt_of_le (half_pos hq0) hp + have hpq : p ≤ q := by change (p:ℝ) ≤ (q:ℝ); linarith [Real.rpow_pos_of_pos hh a] + have H := markedConnection_transfer G Q x d hd hdeg p q h hp0 hpq hq1 hh + apply H.trans + apply mul_le_mul_of_nonneg_right + · apply Real.exp_le_exp.mpr + rw [he] + have hr : Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ))) ≤ + Real.sqrt ((d:ℝ)/2)/(((q:ℝ)/2)*(1-(q:ℝ))) := + div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (mul_pos (half_pos hq0) (sub_pos.mpr hq1)) + (mul_le_mul_of_nonneg_right hp (sub_pos.mpr hq1).le) + calc + _ = (Real.sqrt ((d:ℝ)/2)/((p:ℝ)*(1-(q:ℝ)))) * + (Real.sqrt (Real.log (1/(h:ℝ))/(h:ℝ))*(h:ℝ)^a) := by ring + _ ≤ _ := mul_le_mul hr (sqrt_log_power_bound h hh a ha) + (mul_nonneg (Real.sqrt_nonneg _) (Real.rpow_nonneg h.2.1 _)) (by positivity) + · rw [markedConnectionPolynomial_eq_tree] + exact ProbeTree.successMass_nonneg p h _ + +end GhostPowerTransfer +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section DyadicGhostParameters +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def dyadicGhost (j : ℕ) : unitInterval := + ⟨(1/2:ℝ)^j,⟨pow_nonneg (by norm_num) _,pow_le_one₀ (by norm_num) (by norm_num)⟩⟩ + +theorem dyadicGhost_pos (j : ℕ) : 0 < (dyadicGhost j:ℝ) := pow_pos (by norm_num) _ + +theorem dyadicGhost_volume (j : ℕ) : (dyadicGhost j:ℝ)*(2^j:ℕ) = 1 := by + simp only [dyadicGhost,Nat.cast_pow,Nat.cast_ofNat,←mul_pow] + norm_num + +theorem tendsto_dyadicGhost : Tendsto (fun j => (dyadicGhost j:ℝ)) atTop (nhds 0) := + tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num) + +theorem dyadicGhost_rpow (j : ℕ) (t : ℝ) : + (dyadicGhost j:ℝ)^t = (2:ℝ)^(-t*(j:ℝ)) := by + change ((1/2:ℝ)^j)^t = _ + rw [←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 1/2)] + rw [show (1/2:ℝ) = (2:ℝ)^(-1:ℝ) by norm_num, + ←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)] + congr 1 + ring + + + +theorem eventually_dyadic_backstep (q : unitInterval) (hq : 0 < (q:ℝ)) + (a : ℝ) (ha : 0 < a) (P : unitInterval → Prop) (hP : ∀ᶠ p in nhds q, P p) : + ∀ᶠ j : ℕ in atTop, ∃ p : unitInterval, + (q:ℝ)/2 ≤ (p:ℝ) ∧ p < q ∧ (q:ℝ)-(p:ℝ) = (dyadicGhost j:ℝ)^a ∧ P p := by + obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp hP + have ht : Tendsto (fun j => (dyadicGhost j:ℝ)^a) atTop (nhds 0) := by + simpa only [Real.zero_rpow ha.ne', Function.comp_apply] using! + (Real.continuousAt_rpow_const 0 a (Or.inr ha.le)).tendsto.comp tendsto_dyadicGhost + filter_upwards [ht.eventually (eventually_lt_nhds (half_pos hq)),ht.eventually (eventually_lt_nhds hε)] with j hj hεj + have hz := Real.rpow_pos_of_pos (dyadicGhost_pos j) a + let p : unitInterval := ⟨(q:ℝ)-(dyadicGhost j:ℝ)^a,⟨by linarith,by linarith [q.2.2]⟩⟩ + refine ⟨p,by dsimp [p]; linarith,by change (q:ℝ)-(dyadicGhost j:ℝ)^a < (q:ℝ); linarith, + by dsimp [p]; ring,?_⟩ + apply hball + change |((q:ℝ)-(dyadicGhost j:ℝ)^a)-(q:ℝ)| < ε + rw [show (q:ℝ)-(dyadicGhost j:ℝ)^a-(q:ℝ) = -(dyadicGhost j:ℝ)^a by ring,abs_neg,abs_of_pos hz] + exact hεj + +end DyadicGhostParameters +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section CriticalDyadicTail +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_dyadic_bound_of_susceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hq0 : 0 < (pc G:ℝ)) (hq1 : (pc G:ℝ) < 1) + (C b a : ℝ) (hC : 0 < C) (ha : 1/2 < a) + (hχ : ∀ᶠ p in nhds (pc G), p < pc G → ∀ x, + susceptibility G p x ≤ C*((pc G:ℝ)-(p:ℝ))^(-b)) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ j : ℕ in atTop, ∀ x, + clusterWindowProbability G (pc G) x (2^j) (2^(j+1)) ≤ + K*(dyadicGhost j:ℝ)^(1-a*b) := by + obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt + let B := Real.exp ((Real.sqrt ((d:ℝ)/2)/(((pc G:ℝ)/2)*(1-(pc G:ℝ)))) * Real.sqrt (1/(2*a-1))) + have hB : 0 < B := Real.exp_pos _ + refine ⟨2*B*C,by positivity,?_⟩ + filter_upwards [eventually_dyadic_backstep (pc G) hq0 a (by linarith) _ hχ] with j hj + obtain ⟨p,hp,hpc,he,hχp⟩ := hj + intro x + let Q := incidentSupport G hloc (finite_reachBall hloc x (2^(j+1))).toFinset + have hwin := clusterWindow_le_markedConnection G hloc x (2^j) (2^(j+1)) (pc G) (dyadicGhost j) + (by rw [dyadicGhost_volume]) + have htra := markedConnection_power_transfer G Q x d hd + (fun v => (incident_filter_card_le_degree G hloc Q v).trans (hdeg v)) p (pc G) (dyadicGhost j) + hq0 hq1 hp (dyadicGhost_pos j) a ha he + have hsub := markedConnection_le_susceptibility G hloc hqt Q x (dyadicGhost j) p hpc + have hid : (dyadicGhost j:ℝ)*((dyadicGhost j:ℝ)^a)^(-b) = (dyadicGhost j:ℝ)^(1-a*b) := by + rw [←Real.rpow_mul (dyadicGhost j).2.1] + calc + _ = (dyadicGhost j:ℝ)^1*(dyadicGhost j:ℝ)^(a*(-b)) := by rw [Real.rpow_one] + _ = (dyadicGhost j:ℝ)^(1+a*(-b)) := (Real.rpow_add (dyadicGhost_pos j) _ _).symm + _ = _ := by congr 1; ring + calc + _ ≤ 2*markedConnectionPolynomial G Q x (dyadicGhost j) (pc G) := hwin + _ ≤ 2*(B*markedConnectionPolynomial G Q x (dyadicGhost j) p) := + mul_le_mul_of_nonneg_left htra (by norm_num) + _ ≤ 2*(B*((dyadicGhost j:ℝ)*susceptibility G p x)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hsub hB.le) (by norm_num) + _ ≤ 2*(B*((dyadicGhost j:ℝ)*(C*((pc G:ℝ)-(p:ℝ))^(-b)))) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (hχp hpc x) (dyadicGhost j).2.1) hB.le) (by norm_num) + _ = 2*B*C*((dyadicGhost j:ℝ)*((dyadicGhost j:ℝ)^a)^(-b)) := by rw [he]; ring + _ = _ := by rw [hid] + + + +theorem critical_power_integrable_of_dyadic_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (α θ K : ℝ) (hα : 0 < α) (hθ : α < θ) + (hbound : ∀ᶠ j : ℕ in atTop, ∀ x, + clusterWindowProbability G p x (2^j) (2^(j+1)) ≤ K*(dyadicGhost j:ℝ)^θ) : + ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by + intro x + apply integrable_cluster_power_of_dyadic G hloc p x α hα + have hs : Summable (fun j : ℕ => K*((2:ℝ)^(α-θ))^j) := by + apply Summable.mul_left + apply summable_geometric_of_norm_lt_one + rw [Real.norm_of_nonneg (Real.rpow_nonneg (by norm_num) _)] + exact Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (sub_neg.mpr hθ) + apply hs.of_norm_bounded_eventually + rw [Nat.cofinite_eq_atTop] + filter_upwards [hbound] with j hj + rw [Real.norm_of_nonneg (mul_nonneg (Real.rpow_nonneg (by norm_num) _) + (clusterWindowProbability_nonneg G p x _ _))] + calc + _ ≤ (2:ℝ)^(α*(j:ℝ))*(K*(dyadicGhost j:ℝ)^θ) := + mul_le_mul_of_nonneg_left (hj x) (Real.rpow_nonneg (by norm_num) _) + _ = K*((2:ℝ)^(α-θ))^j := by + rw [dyadicGhost_rpow,←Real.rpow_natCast,←Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)] + rw [show (α-θ)*(j:ℝ) = α*(j:ℝ)+(-θ*(j:ℝ)) by ring,Real.rpow_add (by norm_num : (0:ℝ)<2)] + ring + +end CriticalDyadicTail +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section MomentFromGrowth +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_moment_of_susceptibility_growth [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hq0 : 0 < (pc G:ℝ)) (hq1 : (pc G:ℝ) < 1) + (hgrowth : ∀ γ : ℝ, 0 < γ → γ < 1 → ∃ C : ℝ, 0 < C ∧ + ∀ᶠ p in nhds (pc G), p < pc G → ∀ x, + susceptibility G p x ≤ C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ))) + (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) : + ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law (pc G)) := by + let γ := (1/2-α)/2 + have hγ : 0 < γ := by dsimp [γ]; linarith + have hγ1 : γ < 1 := by dsimp [γ]; linarith + have hprod : (1/2:ℝ) < (1-γ)*(1-α) := by + have : 0 < γ*α := mul_pos hγ hα + dsimp [γ] at * + nlinarith + obtain ⟨a,ha,hap⟩ := exists_between hprod + have hden : 0 < 1-γ := sub_pos.mpr hγ1 + obtain ⟨C,hC,hnear⟩ := hgrowth γ hγ hγ1 + have he : -(1/(1-γ)) = -1/(1-γ) := by ring + obtain ⟨K,hK,hbound⟩ := critical_dyadic_bound_of_susceptibility G hloc hqt hq0 hq1 + C (1/(1-γ)) a hC ha (by simpa only [he] using hnear) + apply critical_power_integrable_of_dyadic_bound G hloc (pc G) α (1-a*(1/(1-γ))) K hα _ hbound + have : a*(1/(1-γ)) < 1-α := by + rw [mul_one_div] + apply (div_lt_iff₀ hden).mpr + nlinarith [hap] + linarith + +end MomentFromGrowth +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section CriticalRootMoments +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_root_power_integrable + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) : + ∀ i, Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G)) := by + by_contra hbad + have hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law (pc G)) := + not_forall.mp hbad + obtain ⟨β,hαβ,hβ⟩ := exists_between hα1 + let ε := (1/2-β)/2 + have hε : 0 < ε := by dsimp [ε]; linarith + have hε1 : ε < 1/2 := by dsimp [ε]; linarith + have hsmall : β+(1/2+ε) < 1 := by dsimp [ε]; linarith + have hg := susceptibility_growth_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr + hcov hw hw1 hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + let c : ℝ := ∑ i, 1/weight i + have hc : 0 < c := Finset.sum_pos (fun i _ => one_div_pos.mpr (hw i)) Finset.univ_nonempty + have hmin (i : ι) : 1 ≤ c*weight i := by + apply (div_le_iff₀ (hw i)).mp + exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) + have hall := critical_moment_of_susceptibility_growth G hloc hqt hp₀ hp₁ (by + intro γ hγ hγ1 + obtain ⟨C,hC,hnear⟩ := hg γ hγ hγ1 + refine ⟨c*C,mul_pos hc hC,?_⟩ + filter_upwards [hnear] with p hp + intro hpc x + calc + _ ≤ c*rootSusceptibility G root weight p := + susceptibility_le_rootSusceptibility G root weight (fun i => (hw i).le) hcover c hc.le hmin p x + _ ≤ c*(C*((pc G:ℝ)-(p:ℝ))^(-1/(1-γ))) := mul_le_mul_of_nonneg_left (hp hpc) hc.le + _ = _ := by ring) α hα hα1 + obtain ⟨i,hi⟩ := hdiv + exact hi (hall (root i)) + +end CriticalRootMoments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformFractionalMoments +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_cluster_power (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (α : ℝ) : + Measurable (fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α) := + (measurable_of_countable (fun n : ℕ => (n:ℝ)^α)).comp (measurable_cluster_ncard G hloc x) + +theorem integrable_cluster_power_covariant [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (α : ℝ) : + Integrable (fun ω => ((cluster G ω (a x)).ncard:ℝ)^α) (law p) ↔ + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by + have h := integrable_map_measure (μ := law p) + (measurable_cluster_power G hloc x α).aestronglyMeasurable + (measurable_set_preimage b).aemeasurable + rw [law_map_preimage_equiv] at h + have he : ((fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α) ∘ (fun ω => b ⁻¹' ω)) = + (fun ω : Set E => ((cluster G ω (a x)).ncard:ℝ)^α) := by + funext ω + dsimp only [Function.comp_apply] + rw [cluster_ncard_covariant G hab] + rw [he] at h + exact h.symm + +theorem integral_cluster_power_covariant [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (α : ℝ) : + (∫ ω, ((cluster G ω (a x)).ncard:ℝ)^α ∂law p) = + ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p := by + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable + (measurable_cluster_power G hloc x α).aestronglyMeasurable + rw [law_map_preimage_equiv] at h + simpa only [cluster_ncard_covariant G hab] using! h.symm + + +theorem uniform_cluster_power_of_root [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (α : ℝ) + (hi : ∀ i, Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : + ∃ C : ℝ, 0 < C ∧ ∀ x, + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) ∧ + (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C := by + let C := 1+∑ i, ∫ ω, ((cluster G ω (root i)).ncard:ℝ)^α ∂law p + have hn (x : V) : 0 ≤ ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p := + integral_nonneg (fun _ => Real.rpow_nonneg (Nat.cast_nonneg _) _) + have hC : 0 < C := by dsimp [C]; linarith [Finset.sum_nonneg (fun i (_ : i ∈ Finset.univ) => hn (root i))] + refine ⟨C,hC,?_⟩ + intro x + obtain ⟨i,a,b,hab,rfl⟩ := hcover x + refine ⟨(integrable_cluster_power_covariant G hloc p hab (root i) α).mpr (hi i),?_⟩ + rw [integral_cluster_power_covariant G hloc p hab] + have hh := Finset.single_le_sum (fun j (_ : j ∈ Finset.univ) => hn (root j)) (Finset.mem_univ i) + dsimp [C] + linarith + +end UniformFractionalMoments +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FractionalMomentCoupling +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem cluster_power_mono_integral [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (p q : unitInterval) (hpq : p ≤ q) + (α : ℝ) (hα : 0 ≤ α) + (hfin : ∀ᵐ ω ∂law q, (cluster G ω x).Finite) + (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law q)) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) ∧ + (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ + ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law q := by + let f (r : unitInterval) (labels : E → unitInterval) := ((cluster G (openEdges labels r) x).ncard:ℝ)^α + have hm (r : unitInterval) : Measurable (f r) := + (measurable_cluster_power G hloc x α).comp (measurable_openEdges r) + have hmap (r : unitInterval) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law r) ↔ Integrable (f r) labelLaw := by + rw [←map_openEdges r] + exact integrable_map_measure (measurable_cluster_power G hloc x α).aestronglyMeasurable + (measurable_openEdges r).aemeasurable + have hf : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), (cluster G (openEdges labels q) x).Finite := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges q).aemeasurable + rwa [map_openEdges] + have hle : f p ≤ᵐ[labelLaw] f q := by + filter_upwards [hf] with labels hlabels + apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hα + exact_mod_cast Set.ncard_le_ncard (show cluster G (openEdges labels p) x ⊆ cluster G (openEdges labels q) x from + fun y hy => conn_mono G (openEdges_mono labels hpq) hy) hlabels + have hiq := (hmap q).mp hi + have hip : Integrable (f p) labelLaw := hiq.mono' (hm p).aestronglyMeasurable (by + filter_upwards [hle] with labels hl + rwa [Real.norm_of_nonneg (Real.rpow_nonneg (Nat.cast_nonneg _) _)] ) + refine ⟨(hmap p).mpr hip,?_⟩ + have he (r : unitInterval) : (∫ labels, f r labels ∂labelLaw) = + ∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law r := by + rw [←map_openEdges r] + exact (integral_map (measurable_openEdges r).aemeasurable + (measurable_cluster_power G hloc x α).aestronglyMeasurable).symm + rw [←he p,←he q] + exact integral_mono_ae hip hiq hle + +end FractionalMomentCoupling +end Percolation + + +namespace Percolation +universe u v +variable {E : Type v} +section DecisionCovarianceAlgebra +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteCovariance (Q : Finset E) (p : ℝ) (f g : Finset E → ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => f ω*g ω) p - bernoulliPolynomial Q f p*bernoulliPolynomial Q g p + +noncomputable def coordinateAverage (e : E) (p : ℝ) (f : Finset E → ℝ) (ω : Finset E) : ℝ := + (1-p)*f ω+p*f (insert e ω) + +noncomputable def coordinateVariation (Q : Finset E) (p : ℝ) (f : Finset E → ℝ) (e : E) : ℝ := + bernoulliPolynomial (Q.erase e) (fun ω => |f (insert e ω)-f ω|) p + +theorem bernoulliPolynomial_abs (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) : + |bernoulliPolynomial Q f p| ≤ bernoulliPolynomial Q (fun ω => |f ω|) p := by + rw [abs_le] + constructor + · have h := bernoulliPolynomial_mono Q (fun ω => -|f ω|) f p p.2 + (fun _ _ => neg_abs_le _) + have he : bernoulliPolynomial Q (fun ω => -|f ω|) p = + -bernoulliPolynomial Q (fun ω => |f ω|) p := by + simp only [bernoulliPolynomial,neg_mul,Finset.sum_neg_distrib] + rwa [he] at h + · exact bernoulliPolynomial_mono Q f (fun ω => |f ω|) p p.2 (fun _ _ => le_abs_self _) + +theorem coordinateVariation_nonneg (Q : Finset E) (p : unitInterval) (f : Finset E → ℝ) (e : E) : + 0 ≤ coordinateVariation Q p f e := + bernoulliPolynomial_nonneg _ _ p p.2 (fun _ _ => abs_nonneg _) + + +theorem finiteCovariance_first_coordinate (S : Finset E) (e : E) (he : e ∉ S) + (p : ℝ) (f g : Finset E → ℝ) : + finiteCovariance (insert e S) p f g = + (1-p)*finiteCovariance S p (coordinateAverage e p f) g + + p*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω)) + + p*(1-p)*bernoulliPolynomial S + (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p := by + unfold finiteCovariance + rw [bernoulliPolynomial_insert S e he,bernoulliPolynomial_insert S e he, + bernoulliPolynomial_insert S e he] + have hav := bernoulliPolynomial_affine S f (fun ω => f (insert e ω)) (1-p) p p + change bernoulliPolynomial S (coordinateAverage e p f) p = _ at hav + rw [hav] + have h0 : bernoulliPolynomial S (fun ω => coordinateAverage e p f ω*g ω) p = + (1-p)*bernoulliPolynomial S (fun ω => f ω*g ω) p+ + p*bernoulliPolynomial S (fun ω => f (insert e ω)*g ω) p := by + simpa only [coordinateAverage,add_mul,mul_assoc] using + bernoulliPolynomial_affine S (fun ω => f ω*g ω) (fun ω => f (insert e ω)*g ω) (1-p) p p + have h1 : bernoulliPolynomial S (fun ω => coordinateAverage e p f ω*g (insert e ω)) p = + (1-p)*bernoulliPolynomial S (fun ω => f ω*g (insert e ω)) p+ + p*bernoulliPolynomial S (fun ω => f (insert e ω)*g (insert e ω)) p := by + simpa only [coordinateAverage,add_mul,mul_assoc] using + bernoulliPolynomial_affine S (fun ω => f ω*g (insert e ω)) (fun ω => f (insert e ω)*g (insert e ω)) (1-p) p p + rw [h0,h1] + have herr : bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p = + bernoulliPolynomial S (fun ω => f (insert e ω)*g (insert e ω)) p- + bernoulliPolynomial S (fun ω => f (insert e ω)*g ω) p- + bernoulliPolynomial S (fun ω => f ω*g (insert e ω)) p+ + bernoulliPolynomial S (fun ω => f ω*g ω) p := by + simp only [bernoulliPolynomial] + simp only [←Finset.sum_sub_distrib,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro ω _ + ring + rw [herr] + ring + +end DecisionCovarianceAlgebra +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section CoordinateAveragingBounds +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem coordinateVariation_average_le (S : Finset E) (e j : E) (he : e ∉ S) (hje : j ≠ e) + (p : unitInterval) (f : Finset E → ℝ) : + coordinateVariation S p (coordinateAverage e p f) j ≤ coordinateVariation (insert e S) p f j := by + unfold coordinateVariation + rw [Finset.erase_insert_of_ne hje.symm,bernoulliPolynomial_insert _ e (by simp [he])] + let f₀ := fun ω : Finset E => |f (insert j ω)-f ω| + let f₁ := fun ω : Finset E => |f (insert j (insert e ω))-f (insert e ω)| + change _ ≤ (1-(p:ℝ))*bernoulliPolynomial (S.erase j) f₀ p+ + (p:ℝ)*bernoulliPolynomial (S.erase j) f₁ p + rw [←bernoulliPolynomial_affine] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + have hid : coordinateAverage e p f (insert j ω)-coordinateAverage e p f ω = + (1-(p:ℝ))*(f (insert j ω)-f ω)+(p:ℝ)*(f (insert j (insert e ω))-f (insert e ω)) := by + simp only [coordinateAverage,Finset.insert_comm e j] + ring + rw [hid] + calc + _ ≤ |(1-(p:ℝ))*(f (insert j ω)-f ω)|+|(p:ℝ)*(f (insert j (insert e ω))-f (insert e ω))| := abs_add_le _ _ + _ = _ := by rw [abs_mul,abs_mul,abs_of_nonneg (sub_nonneg.mpr p.2.2),abs_of_nonneg p.2.1] + + + +theorem finiteCovariance_first_bound (S : Finset E) (e : E) (he : e ∉ S) + (p : unitInterval) (f g : Finset E → ℝ) + (hg : ∀ ω ⊆ insert e S, g ω ∈ Set.Icc (0:ℝ) 1) : + |finiteCovariance (insert e S) p f g| ≤ + (1-(p:ℝ))*|finiteCovariance S p (coordinateAverage e p f) g|+ + (p:ℝ)*|finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ + (p:ℝ)*(1-(p:ℝ))*coordinateVariation (insert e S) p f e := by + have hgood : |bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| ≤ + coordinateVariation (insert e S) p f e := by + apply (bernoulliPolynomial_abs S p _).trans + unfold coordinateVariation + rw [Finset.erase_insert he] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω hω + rw [abs_mul] + have h₀ := hg ω (hω.trans (Finset.subset_insert _ _)) + have h₁ := hg (insert e ω) (Finset.insert_subset_insert e hω) + have hd : |g (insert e ω)-g ω| ≤ 1 := by rw [abs_le]; constructor <;> linarith [h₀.1,h₀.2,h₁.1,h₁.2] + simpa only [mul_one] using mul_le_mul_of_nonneg_left hd (abs_nonneg (f (insert e ω)-f ω)) + rw [finiteCovariance_first_coordinate S e he] + calc + _ ≤ |(1-(p:ℝ))*finiteCovariance S p (coordinateAverage e p f) g+ + (p:ℝ)*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ + |(p:ℝ)*(1-(p:ℝ))*bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| := abs_add_le _ _ + _ ≤ |(1-(p:ℝ))*finiteCovariance S p (coordinateAverage e p f) g|+ + |(p:ℝ)*finiteCovariance S p (coordinateAverage e p f) (fun ω => g (insert e ω))|+ + |(p:ℝ)*(1-(p:ℝ))*bernoulliPolynomial S (fun ω => (f (insert e ω)-f ω)*(g (insert e ω)-g ω)) p| := + add_le_add (abs_add_le _ _) le_rfl + _ ≤ _ := by + rw [abs_mul,abs_mul,abs_mul,abs_of_nonneg (sub_nonneg.mpr p.2.2),abs_of_nonneg p.2.1, + abs_of_nonneg (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))] + exact add_le_add le_rfl (mul_le_mul_of_nonneg_left hgood (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) + +end CoordinateAveragingBounds +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section EdgeDecisionTrees +attribute [local instance] Classical.propDecidable Classical.decEq + + +inductive EdgeQueryTree (E : Type v) where + | done (b : Bool) + | query (e : E) (closed opened : EdgeQueryTree E) + +namespace EdgeQueryTree + +def Valid (Q : Finset E) : EdgeQueryTree E → Prop + | .done _ => True + | .query e t₀ t₁ => e ∈ Q ∧ Valid (Q.erase e) t₀ ∧ Valid (Q.erase e) t₁ + +noncomputable def eval (ω : Finset E) : EdgeQueryTree E → Bool + | .done b => b + | .query e t₀ t₁ => if e ∈ ω then eval ω t₁ else eval ω t₀ + +noncomputable def value (t : EdgeQueryTree E) (ω : Finset E) : ℝ := if t.eval ω then 1 else 0 + +noncomputable def reads (ω : Finset E) (i : E) : EdgeQueryTree E → Prop + | .done _ => False + | .query e t₀ t₁ => i = e ∨ if e ∈ ω then reads ω i t₁ else reads ω i t₀ + +noncomputable def revealment (p : ℝ) (i : E) : EdgeQueryTree E → ℝ + | .done _ => 0 + | .query e t₀ t₁ => if i = e then 1 else (1-p)*revealment p i t₀+p*revealment p i t₁ + +theorem value_mem (t : EdgeQueryTree E) (ω : Finset E) : t.value ω ∈ Set.Icc (0:ℝ) 1 := by + unfold value + split <;> simp + +theorem revealment_nonneg (p : unitInterval) (i : E) (t : EdgeQueryTree E) : 0 ≤ t.revealment p i := by + induction t with + | done => rfl + | query e t₀ t₁ ih₀ ih₁ => + simp only [revealment] + split_ifs + · norm_num + · exact add_nonneg (mul_nonneg (sub_nonneg.mpr p.2.2) ih₀) (mul_nonneg p.2.1 ih₁) + +theorem eval_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) : t.eval ω = t.eval η := by + induction t generalizing Q with + | done => rfl + | query e t₀ t₁ ih₀ ih₁ => + simp only [eval,h e ht.1] + split + · exact ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha)) + · exact ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha)) + +theorem eval_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {e : E} (he : e ∉ Q) (ω : Finset E) : t.eval (insert e ω) = t.eval ω := by + apply eval_congr t ht + intro a ha + simp [show a ≠ e from fun h => he (h ▸ ha)] + +theorem value_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {e : E} (he : e ∉ Q) (ω : Finset E) : t.value (insert e ω) = t.value ω := by + simp only [value,eval_insert t ht he] + +theorem reads_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) (i : E) : t.reads ω i ↔ t.reads η i := by + induction t generalizing Q with + | done => rfl + | query e t₀ t₁ ih₀ ih₁ => + simp only [reads,h e ht.1] + split + · rw [ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha))] + · rw [ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha))] + +theorem reads_mem (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (ω : Finset E) (i : E) (hi : t.reads ω i) : i ∈ Q := by + induction t generalizing Q with + | done => exact hi.elim + | query e t₀ t₁ ih₀ ih₁ => + rcases hi with rfl | hi + · exact ht.1 + · split_ifs at hi + · exact Finset.mem_of_mem_erase (ih₁ ht.2.2 hi) + · exact Finset.mem_of_mem_erase (ih₀ ht.2.1 hi) + +end EdgeQueryTree +end EdgeDecisionTrees +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section EdgeTreeCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteCovariance_congr_right (Q : Finset E) (p : ℝ) (f : Finset E → ℝ) + {g h : Finset E → ℝ} (he : ∀ ω ⊆ Q, g ω = h ω) : + finiteCovariance Q p f g = finiteCovariance Q p f h := by + unfold finiteCovariance + rw [bernoulliPolynomial_congr Q (fun ω hω => congrArg (f ω * ·) (he ω hω)), + bernoulliPolynomial_congr Q he] + +namespace EdgeQueryTree + + + +theorem covariance_bound (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (f : Finset E → ℝ) : + |finiteCovariance Q p f t.value| ≤ + ∑ i ∈ Q, t.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by + induction t generalizing Q f with + | done b => + have hv : (done b : EdgeQueryTree E).value = (fun _ => if b then (1:ℝ) else 0) := rfl + rw [hv] + cases b + · simp [finiteCovariance,revealment] + · simp [finiteCovariance,revealment,bernoulliPolynomial_const] + | query e t₀ t₁ ih₀ ih₁ => + have he := ht.1 + have heS : e ∉ Q.erase e := Finset.notMem_erase _ _ + have hQ : insert e (Q.erase e) = Q := Finset.insert_erase he + let fav := coordinateAverage e (p:ℝ) f + have hcov₀ : finiteCovariance (Q.erase e) p fav (query e t₀ t₁).value = + finiteCovariance (Q.erase e) p fav t₀.value := by + apply finiteCovariance_congr_right + intro ω hω + have heω : e ∉ ω := fun h => heS (hω h) + simp only [value,eval,ite_eq_right heω] + have hcov₁ : finiteCovariance (Q.erase e) p fav (fun ω => (query e t₀ t₁).value (insert e ω)) = + finiteCovariance (Q.erase e) p fav t₁.value := by + apply finiteCovariance_congr_right + intro ω _ + simp only [value,eval,Finset.mem_insert_self,ite_true,eval_insert t₁ ht.2.2 heS] + have hav (i : E) (hi : i ∈ Q.erase e) : + coordinateVariation (Q.erase e) p fav i ≤ coordinateVariation Q p f i := by + simpa only [hQ] using coordinateVariation_average_le (Q.erase e) e i heS + (Finset.ne_of_mem_erase hi) p f + have hb₀ : |finiteCovariance (Q.erase e) p fav t₀.value| ≤ + ∑ i ∈ Q.erase e, t₀.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by + apply (ih₀ ht.2.1 fav).trans + apply Finset.sum_le_sum + intro i hi + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (hav i hi) (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) + (revealment_nonneg p i t₀) + have hb₁ : |finiteCovariance (Q.erase e) p fav t₁.value| ≤ + ∑ i ∈ Q.erase e, t₁.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by + apply (ih₁ ht.2.2 fav).trans + apply Finset.sum_le_sum + intro i hi + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (hav i hi) (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2))) + (revealment_nonneg p i t₁) + have hfirst := finiteCovariance_first_bound (Q.erase e) e heS p f (query e t₀ t₁).value + (fun ω _ => value_mem _ ω) + change _ ≤ (1-(p:ℝ))*|finiteCovariance (Q.erase e) p fav (query e t₀ t₁).value|+ + (p:ℝ)*|finiteCovariance (Q.erase e) p fav (fun ω => (query e t₀ t₁).value (insert e ω))|+_ at hfirst + rw [hQ,hcov₀,hcov₁] at hfirst + apply hfirst.trans + calc + _ ≤ (1-(p:ℝ))*(∑ i ∈ Q.erase e, t₀.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i))+ + (p:ℝ)*(∑ i ∈ Q.erase e, t₁.revealment p i * ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i))+ + (p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f e := + add_le_add (add_le_add (mul_le_mul_of_nonneg_left hb₀ (sub_nonneg.mpr p.2.2)) + (mul_le_mul_of_nonneg_left hb₁ p.2.1)) le_rfl + _ = _ := by + rw [←Finset.sum_erase_add _ _ he] + congr 1 + · rw [Finset.mul_sum,Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + rw [revealment,ite_eq_right (Finset.ne_of_mem_erase hi)] + ring + · simp [revealment] + +end EdgeQueryTree +end EdgeTreeCovariance +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section RevealmentProbability +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EdgeQueryTree + +theorem reads_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {e : E} (he : e ∉ Q) (ω : Finset E) (i : E) : t.reads (insert e ω) i ↔ t.reads ω i := by + apply reads_congr t ht + intro a ha + simp [show a ≠ e from fun h => he (h ▸ ha)] + + +theorem revealment_eq_probability (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : ℝ) (i : E) : + t.revealment p i = bernoulliPolynomial Q (fun ω => if t.reads ω i then 1 else 0) p := by + induction t generalizing Q with + | done => simp [revealment,reads] + | query e t₀ t₁ ih₀ ih₁ => + by_cases hie : i = e + · subst i + simp [revealment,reads,bernoulliPolynomial_const] + · have heS : e ∉ Q.erase e := Finset.notMem_erase _ _ + conv_rhs => rw [←Finset.insert_erase ht.1] + rw [bernoulliPolynomial_insert _ e heS] + simp only [revealment,ite_eq_right hie] + rw [ih₀ ht.2.1,ih₁ ht.2.2] + congr 1 + · congr 1 + apply bernoulliPolynomial_congr + intro ω hω + have heω : e ∉ ω := fun h => heS (hω h) + simp only [reads,hie,false_or,ite_eq_right heω] + · congr 1 + apply bernoulliPolynomial_congr + intro ω _ + simp only [reads,hie,false_or,Finset.mem_insert_self,ite_true,reads_insert t₁ ht.2.2 heS] + +end EdgeQueryTree +end RevealmentProbability +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SeededEdgeSearch +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def seededEdgeSearch (G : BondGraph V E) (x : V) : + ℕ → Finset E → Finset V → EdgeQueryTree E + | 0, _, R => .done (decide (x ∈ R)) + | n+1, Q, R => + if hc : SearchCrossing G Q R then + let t := searchCrossing G Q R hc + .query t.1 (seededEdgeSearch G x n (Q.erase t.1) R) + (seededEdgeSearch G x n (Q.erase t.1) (insert t.2.2 R)) + else .done (decide (x ∈ R)) + +theorem seededEdgeSearch_valid (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) : + (seededEdgeSearch G x n Q R).Valid Q := by + induction n generalizing Q R with + | zero => trivial + | succ n ih => + simp only [seededEdgeSearch] + split_ifs with hc + · exact ⟨(searchCrossing_spec G Q R hc).1,ih _ _,ih _ _⟩ + · trivial + +theorem seedMarked_singleton_of_no_crossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (x : V) (h : ¬ SearchCrossing G Q R) (ω : Finset E) (hω : ω ⊆ Q) : + SeedMarked G (ω : Set E) R {x} ↔ x ∈ R := by + constructor + · intro hx + by_contra hn + exact seedMarked_false_of_no_crossing G Q R {x} h (by simpa using hn) ω hω hx + · intro hx + exact ⟨x,hx,x,Finset.mem_singleton_self x,conn_refl G _ x⟩ + + +theorem seededEdgeSearch_correct (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) + (hn : Q.card ≤ n) (ω : Finset E) (hω : ω ⊆ Q) : + (seededEdgeSearch G x n Q R).eval ω = true ↔ SeedMarked G (ω : Set E) R {x} := by + induction n generalizing Q R ω with + | zero => + have hQ : Q = ∅ := Finset.card_eq_zero.mp (by omega) + simp only [seededEdgeSearch,EdgeQueryTree.eval,decide_eq_true_eq] + exact (seedMarked_singleton_of_no_crossing G Q R x (by simp [SearchCrossing,hQ]) ω hω).symm + | succ n ih => + simp only [seededEdgeSearch] + split_ifs with hc + · obtain ⟨he,ha,hb,hends⟩ := searchCrossing_spec G Q R hc + have hcard : (Q.erase (searchCrossing G Q R hc).1).card ≤ n := by + rw [Finset.card_erase_of_mem he]; omega + simp only [EdgeQueryTree.eval] + by_cases heω : (searchCrossing G Q R hc).1 ∈ ω + · simp only [ite_eq_left heω] + rw [←Finset.insert_erase heω,Finset.coe_insert,seedMarked_insert_edge G _ R {x} _ _ _ ha hends, + EdgeQueryTree.eval_insert _ (seededEdgeSearch_valid G x n _ _) (Finset.notMem_erase _ _)] + exact ih _ _ hcard _ (Finset.erase_subset_erase _ hω) + · simp only [ite_eq_right heω] + exact ih _ _ hcard ω (Finset.subset_erase.mpr ⟨hω,heω⟩) + · simp only [EdgeQueryTree.eval,decide_eq_true_eq] + exact (seedMarked_singleton_of_no_crossing G Q R x hc ω hω).symm + + + +theorem seededEdgeSearch_reads (G : BondGraph V E) (x : V) (n : ℕ) (Q : Finset E) (R : Finset V) + (ω : Finset E) (i : E) (hi : (seededEdgeSearch G x n Q R).reads ω i) : + ∃ a ∈ G i, ∃ r ∈ R, Conn G (ω : Set E) r a := by + induction n generalizing Q R with + | zero => exact hi.elim + | succ n ih => + simp only [seededEdgeSearch] at hi + split_ifs at hi with hc + · obtain ⟨he,ha,hb,hends⟩ := searchCrossing_spec G Q R hc + rcases hi with rfl | hi + · refine ⟨(searchCrossing G Q R hc).2.1,?_,_,ha,conn_refl G _ _⟩ + rw [hends]; simp + · split_ifs at hi with heω + · obtain ⟨a,hai,r,hr,hra⟩ := ih _ _ hi + rcases Finset.mem_insert.mp hr with rfl | hr + · refine ⟨a,hai,(searchCrossing G Q R hc).2.1,ha,?_⟩ + exact (Relation.ReflTransGen.single ⟨(searchCrossing G Q R hc).1,heω,hends⟩).trans hra + · exact ⟨a,hai,r,hr,hra⟩ + · exact ih _ _ hi + · exact hi.elim + +end SeededEdgeSearch +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RandomizedDecisionCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteCovariance_average_right (Q : Finset E) (F : Finset V) (p h : ℝ) + (f : Finset E → ℝ) (g : Finset V → Finset E → ℝ) : + finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => g m ω) h) = + bernoulliPolynomial F (fun m => finiteCovariance Q p f (g m)) h := by + unfold finiteCovariance + rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul, + ←bernoulliPolynomial_commute Q F (fun ω m => g m ω) p h] + congr 1 + calc + _ = bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => f ω*g m ω) h) p := by + apply bernoulliPolynomial_congr + intro ω _ + exact (bernoulliPolynomial_const_mul F (fun m => g m ω) (f ω) h).symm + _ = _ := bernoulliPolynomial_commute Q F _ p h + + + +theorem EdgeQueryTree.randomized_covariance_bound (Q : Finset E) (F : Finset V) + (p h : unitInterval) (f : Finset E → ℝ) (trees : Finset V → EdgeQueryTree E) + (ht : ∀ m ⊆ F, (trees m).Valid Q) : + |finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => (trees m).value ω) h)| ≤ + ∑ i ∈ Q, bernoulliPolynomial F (fun m => (trees m).revealment p i) h * + ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by + rw [finiteCovariance_average_right] + apply (bernoulliPolynomial_abs F h _).trans + calc + _ ≤ bernoulliPolynomial F (fun m => ∑ i ∈ Q, (trees m).revealment p i * + ((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i)) h := by + apply bernoulliPolynomial_mono _ _ _ h h.2 + intro m hm + exact (trees m).covariance_bound (ht m hm) p f + _ = _ := by simp only [bernoulliPolynomial_sum,bernoulliPolynomial_mul_const] + +noncomputable def finiteSeedProbability (G : BondGraph V E) (F : Finset V) + (ω : Finset E) (x : V) (h : ℝ) : ℝ := + bernoulliPolynomial F (fun m => if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0) h + +theorem seededEdgeSearch_value (G : BondGraph V E) (x : V) (Q : Finset E) + (m : Finset V) (ω : Finset E) (hω : ω ⊆ Q) : + (seededEdgeSearch G x Q.card Q m).value ω = + if ∃ y ∈ m, Conn G (ω:Set E) x y then 1 else 0 := by + have hc := seededEdgeSearch_correct G x Q.card Q m le_rfl ω hω + have he : SeedMarked G (ω:Set E) m {x} ↔ ∃ y ∈ m, Conn G (ω:Set E) x y := by + simp only [SeedMarked,Finset.mem_singleton,exists_eq_left] + exact exists_congr (fun y => and_congr_right (fun _ => ⟨conn_symm G _,conn_symm G _⟩)) + unfold EdgeQueryTree.value + simp only [hc,he] + +theorem finiteSeedProbability_tree (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (h : ℝ) (ω : Finset E) (hω : ω ⊆ Q) : + finiteSeedProbability G F ω x h = + bernoulliPolynomial F (fun m => (seededEdgeSearch G x Q.card Q m).value ω) h := by + apply bernoulliPolynomial_congr + intro m _ + exact (seededEdgeSearch_value G x Q m ω hω).symm + +end RandomizedDecisionCovariance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SeedRevealmentBounds +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem seededEdgeSearch_reads_endpoints (G : BondGraph V E) (x : V) (Q : Finset E) + (m : Finset V) (ω : Finset E) (i : E) (a b : V) (he : G i = s(a,b)) + (hi : (seededEdgeSearch G x Q.card Q m).reads ω i) : + (∃ y ∈ m, Conn G (ω:Set E) a y) ∨ (∃ y ∈ m, Conn G (ω:Set E) b y) := by + obtain ⟨z,hz,r,hr,hrz⟩ := seededEdgeSearch_reads G x Q.card Q m ω i hi + rw [he] at hz + rcases (by simpa using hz : z = a ∨ z = b) with rfl | rfl + · exact Or.inl ⟨r,hr,conn_symm G _ hrz⟩ + · exact Or.inr ⟨r,hr,conn_symm G _ hrz⟩ + +theorem seededEdgeSearch_mean_revealment_le (G : BondGraph V E) (x : V) + (Q : Finset E) (F : Finset V) (p h : unitInterval) (i : E) (a b : V) (he : G i = s(a,b)) : + bernoulliPolynomial F (fun m => (seededEdgeSearch G x Q.card Q m).revealment p i) h ≤ + bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω a h) p + + bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω b h) p := by + simp_rw [EdgeQueryTree.revealment_eq_probability _ (seededEdgeSearch_valid G x Q.card Q _)] + rw [←bernoulliPolynomial_commute,←bernoulliPolynomial_add] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + unfold finiteSeedProbability + rw [←bernoulliPolynomial_add] + apply bernoulliPolynomial_mono _ _ _ h h.2 + intro m _ + have hr := seededEdgeSearch_reads_endpoints G x Q m ω i a b he + by_cases hread : (seededEdgeSearch G x Q.card Q m).reads ω i + · rcases hr hread with ha | hb + · simp only [ite_eq_left hread,ite_eq_left ha] + split_ifs <;> norm_num + · simp only [ite_eq_left hread,ite_eq_left hb] + split_ifs <;> norm_num + · simp only [ite_eq_right hread] + split_ifs <;> norm_num + + + +theorem finiteSeedProbability_component (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (hF : insert x (searchVertices G Q) ⊆ F) + (ω : Finset E) (hω : ω ⊆ Q) (h : ℝ) : + finiteSeedProbability G F ω x h = 1-(1-h)^(finiteRootComponent G ω x).card := by + let C := finiteRootComponent G ω x + have hCF : C ⊆ F := finiteRootComponent_subset G Q F x ω hω hF + have he (m : Finset V) : (∃ y ∈ m, Conn G (ω:Set E) x y) ↔ m ∩ C ≠ ∅ := by + rw [Finset.nonempty_iff_ne_empty.symm] + constructor + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,Finset.mem_inter.mpr ⟨hy,by change y ∈ (C:Set V); simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hxy⟩⟩ + · rintro ⟨y,hy⟩ + refine ⟨y,(Finset.mem_inter.mp hy).1,?_⟩ + have hm : y ∈ (C:Set V) := (Finset.mem_inter.mp hy).2 + simpa only [C,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hm + calc + _ = bernoulliPolynomial F (fun m => 1-(if m ∩ C = ∅ then 1 else 0)) h := by + apply bernoulliPolynomial_congr + intro m _ + by_cases hm : m ∩ C = ∅ + · have hn : ¬∃ y ∈ m, Conn G (ω:Set E) x y := fun hc => (he m).mp hc hm + simp only [hm,hn,ite_false,ite_true,sub_self] + · have hy := (he m).mpr hm + simp only [hm,hy,ite_false,ite_true,sub_zero] + _ = 1-bernoulliPolynomial F (fun m => if m ∩ C = ∅ then 1 else 0) h := by + rw [bernoulliPolynomial_sub,bernoulliPolynomial_const] + _ = _ := by rw [bernoulliPolynomial_restrict C F hCF (fun m => if m = ∅ then 1 else 0) h, + bernoulliPolynomial_empty_indicator] + +end SeedRevealmentBounds +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section GhostFractionalPower +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem one_sub_pow_one_sub_le_power (h : unitInterval) (n : ℕ) (α : ℝ) + (hα : 0 ≤ α) (hα1 : α ≤ 1) : + 1-(1-(h:ℝ))^n ≤ (h:ℝ)^α*(n:ℝ)^α := by + rw [←Real.mul_rpow h.2.1 (Nat.cast_nonneg _)] + by_cases ht : (h:ℝ)*n ≤ 1 + · exact (one_sub_pow_one_sub_le h n).trans (Real.self_le_rpow_of_le_one (mul_nonneg h.2.1 (Nat.cast_nonneg _)) ht hα1) + · have ht' : 1 ≤ (h:ℝ)*n := (lt_of_not_ge ht).le + exact (sub_le_self _ (pow_nonneg (sub_nonneg.mpr h.2.2) _)).trans (Real.one_le_rpow ht' hα) + +theorem markedConnection_le_cluster_power (G : BondGraph V E) (Q : Finset E) + (x : V) (h p : unitInterval) (α : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : + markedConnectionPolynomial G Q x h p ≤ (h:ℝ)^α*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by + rw [markedConnection_integral,←integral_const_mul] + apply integral_mono_ae + · exact integrable_finite_local Q p _ (by intro ω; simp only [Set.inter_assoc,Set.inter_self]) + · exact hi.const_mul _ + · filter_upwards [hfin] with ω hω + apply (one_sub_pow_one_sub_le_power h _ α hα hα1).trans + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg h.2.1 _) + apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hα + exact_mod_cast Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω + +theorem finiteSeedProbability_expectation (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (hF : insert x (searchVertices G Q) ⊆ F) (h p : ℝ) : + bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω x h) p = + markedConnectionPolynomial G Q x h p := by + rw [markedConnection_component_polynomial] + apply bernoulliPolynomial_congr + intro ω hω + exact finiteSeedProbability_component G Q F x hF ω hω h + +theorem finiteSeedProbability_le_cluster_power (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (hF : insert x (searchVertices G Q) ⊆ F) (h p : unitInterval) + (α : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hi : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : + bernoulliPolynomial Q (fun ω => finiteSeedProbability G F ω x h) p ≤ + (h:ℝ)^α*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by + rw [finiteSeedProbability_expectation G Q F x hF] + exact markedConnection_le_cluster_power G Q x h p α hα hα1 hfin hi + +end GhostFractionalPower +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section MonotoneDecisionRusso +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem sum_coordinateVariation_eq_deriv (Q : Finset E) (f : Finset E → ℝ) + (hf : Monotone f) (p : ℝ) : + (∑ i ∈ Q, coordinateVariation Q p f i) = deriv (bernoulliPolynomial Q f) p := by + rw [(hasDerivAt_bernoulliPolynomial Q f p).deriv] + apply Finset.sum_congr rfl + intro i _ + apply bernoulliPolynomial_congr + intro ω _ + exact abs_of_nonneg (sub_nonneg.mpr (hf (Finset.subset_insert _ _))) + +theorem EdgeQueryTree.randomized_covariance_le_deriv (Q : Finset E) (F : Finset V) + (p h : unitInterval) (f : Finset E → ℝ) (hf : Monotone f) + (trees : Finset V → EdgeQueryTree E) (ht : ∀ m ⊆ F, (trees m).Valid Q) + (R : ℝ) (hR : ∀ i ∈ Q, bernoulliPolynomial F (fun m => (trees m).revealment p i) h ≤ R) : + |finiteCovariance Q p f (fun ω => bernoulliPolynomial F (fun m => (trees m).value ω) h)| ≤ + R*((p:ℝ)*(1-(p:ℝ)))*deriv (bernoulliPolynomial Q f) p := by + apply (randomized_covariance_bound Q F p h f trees ht).trans + calc + _ ≤ ∑ i ∈ Q, R*((p:ℝ)*(1-(p:ℝ))*coordinateVariation Q p f i) := by + apply Finset.sum_le_sum + intro i hi + exact mul_le_mul_of_nonneg_right (hR i hi) + (mul_nonneg (mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2)) (coordinateVariation_nonneg Q p f i)) + _ = _ := by simp only [←mul_assoc,←Finset.mul_sum,sum_coordinateVariation_eq_deriv Q f hf] + + + +theorem seededEdgeSearch_revealment_of_moments (G : BondGraph V E) (Q : Finset E) + (x : V) (p h : unitInterval) (α C : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) : + ∀ i ∈ Q, bernoulliPolynomial (insert x (searchVertices G Q)) + (fun m => (seededEdgeSearch G x Q.card Q m).revealment p i) h ≤ 2*C*(h:ℝ)^α := by + intro i hi + obtain ⟨⟨a,b⟩,he⟩ := Quot.exists_rep (G i) + have he' : G i = s(a,b) := he.symm + have hFa : insert a (searchVertices G Q) ⊆ insert x (searchVertices G Q) := + Finset.insert_subset_iff.mpr ⟨Finset.mem_insert_of_mem (mem_searchVertices G hi (by rw [he']; simp)),Finset.subset_insert _ _⟩ + have hFb : insert b (searchVertices G Q) ⊆ insert x (searchVertices G Q) := + Finset.insert_subset_iff.mpr ⟨Finset.mem_insert_of_mem (mem_searchVertices G hi (by rw [he']; simp)),Finset.subset_insert _ _⟩ + have ha := finiteSeedProbability_le_cluster_power G Q _ a hFa h p α hα hα1 (hfin a) (hI a) + have hb := finiteSeedProbability_le_cluster_power G Q _ b hFb h p α hα hα1 (hfin b) (hI b) + have hca := mul_le_mul_of_nonneg_left (hC a) (Real.rpow_nonneg h.2.1 α) + have hcb := mul_le_mul_of_nonneg_left (hC b) (Real.rpow_nonneg h.2.1 α) + have hr := seededEdgeSearch_mean_revealment_le G x Q (insert x (searchVertices G Q)) p h i a b he' + linarith + +theorem finiteSeed_covariance_upper (G : BondGraph V E) (Q : Finset E) (x : V) + (p h : unitInterval) (α C : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) + (f : Finset E → ℝ) (hf : Monotone f) : + |finiteCovariance Q p f (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h)| ≤ + (2*C*(h:ℝ)^α)*((p:ℝ)*(1-(p:ℝ)))*deriv (bernoulliPolynomial Q f) p := by + have hc := EdgeQueryTree.randomized_covariance_le_deriv Q (insert x (searchVertices G Q)) p h f hf + (fun m => seededEdgeSearch G x Q.card Q m) (fun _ _ => seededEdgeSearch_valid G x Q.card Q _) + (2*C*(h:ℝ)^α) (seededEdgeSearch_revealment_of_moments G Q x p h α C hα hα1 hfin hI hC) + convert hc using 2 + apply finiteCovariance_congr_right + intro ω hω + exact finiteSeedProbability_tree G Q _ x h ω hω + +end MonotoneDecisionRusso +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterTailCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteClusterTailIndicator (G : BondGraph V E) (x : V) (n : ℕ) + (ω : Finset E) : ℝ := if n ≤ (finiteRootComponent G ω x).card then 1 else 0 + +noncomputable def finiteClusterTail (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : ℝ) : ℝ := + bernoulliPolynomial Q (finiteClusterTailIndicator G x n) p + +theorem finiteClusterTailIndicator_mono (G : BondGraph V E) (x : V) (n : ℕ) : + Monotone (finiteClusterTailIndicator G x n) := by + intro ω η hωη + have hc := Finset.card_le_card (finiteRootComponent_mono G hωη x) + unfold finiteClusterTailIndicator + split_ifs <;> norm_num + omega + +theorem finiteClusterTail_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : unitInterval) : + 0 ≤ finiteClusterTail G Q x n p := by + apply bernoulliPolynomial_nonneg _ _ p p.2 + intro ω _ + unfold finiteClusterTailIndicator + split_ifs <;> norm_num + +theorem finiteClusterTail_deriv_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) (n : ℕ) (p : unitInterval) : + 0 ≤ deriv (finiteClusterTail G Q x n) p := by + change 0 ≤ deriv (bernoulliPolynomial Q (finiteClusterTailIndicator G x n)) p + rw [←sum_coordinateVariation_eq_deriv Q _ (finiteClusterTailIndicator_mono G x n)] + exact Finset.sum_nonneg (fun i _ => coordinateVariation_nonneg Q p _ i) + + + +theorem finiteSeed_covariance_lower (G : BondGraph V E) (Q : Finset E) (x : V) + (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) (B : ℝ) + (hB : markedConnectionPolynomial G Q x h p ≤ B) : + (1/2-B)*finiteClusterTail G Q x n p ≤ finiteCovariance Q p + (finiteClusterTailIndicator G x n) + (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h) := by + have hprod : (1:ℝ)/2*finiteClusterTail G Q x n p ≤ + bernoulliPolynomial Q (fun ω => finiteClusterTailIndicator G x n ω* + finiteSeedProbability G (insert x (searchVertices G Q)) ω x h) p := by + rw [finiteClusterTail,←bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω hω + rw [finiteSeedProbability_component G Q _ x le_rfl ω hω] + unfold finiteClusterTailIndicator + by_cases hsize : n ≤ (finiteRootComponent G ω x).card + · simp only [ite_eq_left hsize,mul_one,one_mul] + apply one_sub_pow_one_sub_ge_half + exact hn.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hsize) h.2.1) + · simp only [ite_eq_right hsize,mul_zero,zero_mul,le_refl] + have hmean := finiteSeedProbability_expectation G Q (insert x (searchVertices G Q)) x le_rfl (h:ℝ) p + unfold finiteCovariance + rw [hmean] + change _ ≤ _-finiteClusterTail G Q x n p*markedConnectionPolynomial G Q x h p + have hm := mul_le_mul_of_nonneg_left hB (finiteClusterTail_nonneg G Q x n p) + nlinarith + +end ClusterTailCovariance +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Exploration/Goodness.lean b/lean/OAI/Probability/UnimodularPercolation/Exploration/Goodness.lean index 4dcf51caf407d855ac6c4582e708c6436e612671..7998b0b4906ce8ba4ff5aa3e5c9b4714c66c136e 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Exploration/Goodness.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Exploration/Goodness.lean @@ -1,1316 +1,1316 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.Moments - -namespace OAI - -/-! Pruning, finite and infinite goodness events and uniform bounds. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteCappedRadius -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def pairOpenPivotals (G : BondGraph V E) (Q : Finset E) (x y : V) - (ω : Finset E) : Finset E := - Q.filter fun e => e ∈ ω ∧ Conn G (ω : Set E) x y ∧ ¬Conn G (ω.erase e : Set E) x y - - -def CappedRadiusEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M r : ℕ) - (ω : Finset E) : Prop := - (finiteRootComponent G ω x).card ≤ M ∧ - ∃ y, Conn G (ω : Set E) x y ∧ r ≤ (pairOpenPivotals G Q x y ω).card - -noncomputable def finiteCappedRadiusTail (G : BondGraph V E) (Q : Finset E) - (x : V) (M r : ℕ) (p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => if CappedRadiusEvent G Q x M r ω then 1 else 0) p - - -theorem sole_root_mark (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) - (m : Finset V) (hxy : Conn G (ω : Set E) x y) - (hm : m ∩ finiteRootComponent G ω x = {y}) : - MarkedEvent G ω m x ∧ markedOpenPivotals G Q x ω m = pairOpenPivotals G Q x y ω := by - have hyW : y ∈ finiteRootComponent G ω x := by - change y ∈ (finiteRootComponent G ω x : Set V) - rwa [coe_finiteRootComponent] - have hym : y ∈ m := (Finset.mem_inter.mp (hm ▸ Finset.mem_singleton_self y)).1 - have hmconn (η : Finset E) (hη : η ⊆ ω) : - MarkedEvent G η m x ↔ Conn G (η : Set E) x y := by - constructor - · rintro ⟨z,hzm,hxz⟩ - have hzW : z ∈ finiteRootComponent G ω x := by - change z ∈ (finiteRootComponent G ω x : Set V) - rw [coe_finiteRootComponent] - exact conn_mono G (by exact_mod_cast hη) hxz - have hzy : z = y := Finset.mem_singleton.mp (hm ▸ Finset.mem_inter.mpr ⟨hzm,hzW⟩) - rwa [hzy] at hxz - · exact fun h => ⟨y,hym,h⟩ - refine ⟨⟨y,hym,hxy⟩,?_⟩ - ext e - simp only [markedOpenPivotals,pairOpenPivotals,Finset.mem_filter] - change (e ∈ Q ∧ e ∈ ω ∧ MarkedEvent G ω m x ∧ ¬MarkedEvent G (ω.erase e) m x) ↔ _ - rw [hmconn ω Finset.Subset.rfl,hmconn (ω.erase e) (Finset.erase_subset e ω)] - - -theorem bernoulliPolynomial_exact_indicator (F S : Finset V) (hSF : S ⊆ F) (h : ℝ) : - bernoulliPolynomial F (fun m => if m = S then (1:ℝ) else 0) h = - h^S.card*(1-h)^(F.card-S.card) := by - unfold bernoulliPolynomial - rw [Finset.sum_eq_single_of_mem S (Finset.mem_powerset.mpr hSF)] - · simp - · intro m hm hne - simp [hne] - - -theorem bernoulliPolynomial_sole_root_mark (G : BondGraph V E) (Q : Finset E) - (F : Finset V) (x y : V) (ω : Finset E) (hω : ω ⊆ Q) - (hF : insert x (searchVertices G Q) ⊆ F) (hxy : Conn G (ω : Set E) x y) (h : ℝ) : - bernoulliPolynomial F (fun m => if m ∩ finiteRootComponent G ω x = {y} then (1:ℝ) else 0) h = - h*(1-h)^((finiteRootComponent G ω x).card-1) := by - rw [bernoulliPolynomial_restrict _ _ (finiteRootComponent_subset G Q F x ω hω hF) - (fun a => if a = {y} then (1:ℝ) else 0) h] - have hy : y ∈ finiteRootComponent G ω x := by - change y ∈ (finiteRootComponent G ω x : Set V) - rwa [coe_finiteRootComponent] - rw [bernoulliPolynomial_exact_indicator _ {y} (Finset.singleton_subset_iff.mpr hy)] - simp - - -theorem cappedRadius_mark_comparison (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (M r : ℕ) (p h : unitInterval) - (hF : insert x (searchVertices G Q) ⊆ F) : - (h:ℝ)*(1-h)^M*finiteCappedRadiusTail G Q x M r p ≤ finiteMarkedTail G Q F x r h p := by - unfold finiteCappedRadiusTail finiteMarkedTail - rw [← bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_mono _ _ _ _ p.2 - intro ω hω - by_cases he : CappedRadiusEvent G Q x M r ω - · obtain ⟨hcap,y,hxy,hr⟩ := he - have he : CappedRadiusEvent G Q x M r ω := ⟨hcap,y,hxy,hr⟩ - simp only [he,ite_true,mul_one] - calc - (h:ℝ)*(1-h)^M ≤ (h:ℝ)*(1-h)^((finiteRootComponent G ω x).card-1) := by - apply mul_le_mul_of_nonneg_left _ h.2.1 - exact pow_le_pow_of_le_one (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) - (Nat.le_trans (Nat.sub_le _ _) hcap) - _ = bernoulliPolynomial F - (fun m => if m ∩ finiteRootComponent G ω x = {y} then (1:ℝ) else 0) h := - (bernoulliPolynomial_sole_root_mark G Q F x y ω hω hF hxy h).symm - _ ≤ _ := by - apply bernoulliPolynomial_mono _ _ _ _ h.2 - intro m hm - by_cases hs : m ∩ finiteRootComponent G ω x = {y} - · obtain ⟨heq,hpiv⟩ := sole_root_mark G Q x y ω m hxy hs - have hlarge : r ≤ (markedOpenPivotals G Q x ω m).card := hpiv ▸ hr - simp only [hs,heq,hlarge,and_self,ite_true,le_refl] - · simp only [hs,ite_false] - split_ifs <;> norm_num - · simp only [he,ite_false,mul_zero] - apply bernoulliPolynomial_nonneg _ _ _ h.2 - intro m hm - split_ifs <;> norm_num - -theorem finiteMarkedMoment_zero_le_one (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (p h : unitInterval) : finiteMarkedMoment G Q F x 0 h p ≤ 1 := by - unfold finiteMarkedMoment - rw [← bernoulliPolynomial_const Q (1:ℝ) (p:ℝ)] - apply bernoulliPolynomial_mono _ _ _ _ p.2 - intro ω hω - rw [← bernoulliPolynomial_const F (1:ℝ) (h:ℝ)] - apply bernoulliPolynomial_mono _ _ _ _ h.2 - intro m hm - rw [markedMomentValue_zero] - split_ifs <;> norm_num - - -theorem finiteCappedRadiusTail_exponential [Nonempty V] (G : BondGraph V E) - (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) - (d : ℕ) (hd : 0 < d) (Q : Finset E) (x : V) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (B : ℝ) (hB : 1 ≤ B) - (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) (M r : ℕ) : - finiteCappedRadiusTail G Q x M r p ≤ - (2/((h:ℝ)*(1-h)^M))*Real.exp (-(r:ℝ)/(4*B)) := by - let F := insert x (searchVertices G Q) - have hcomp := cappedRadius_mark_comparison G Q F x M r p h Finset.Subset.rfl - have ht := finiteMarkedTail_exponential G p h hp hh d hd Q F x hdeg Finset.Subset.rfl B hB hAB r - have hm := finiteMarkedMoment_zero_le_one G Q F x p h - have hb : 0 < (h:ℝ)*(1-h)^M := mul_pos hh (pow_pos (sub_pos.mpr hh1) _) - have hbound : (h:ℝ)*(1-h)^M*finiteCappedRadiusTail G Q x M r p ≤ - 2*Real.exp (-(r:ℝ)/(4*B)) := by - have hpos : 0 ≤ 2*Real.exp (-(r:ℝ)/(4*B)) := by positivity - have hl := mul_le_mul_of_nonneg_left hm hpos - rw [mul_one] at hl - exact hcomp.trans (ht.trans hl) - calc - _ ≤ (2*Real.exp (-(r:ℝ)/(4*B)))/((h:ℝ)*(1-h)^M) := - (le_div_iff₀ hb).mpr (by simpa only [mul_comm] using hbound) - _ = _ := by ring - -end FiniteCappedRadius - -section PruningGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem pairOpenPivotals_symm (G : BondGraph V E) (Q : Finset E) (ω : Finset E) (x y : V) : - pairOpenPivotals G Q x y ω = pairOpenPivotals G Q y x ω := by - ext e - simp only [pairOpenPivotals,Finset.mem_filter] - have h₁ : Conn G (ω : Set E) x y ↔ Conn G (ω : Set E) y x := - ⟨conn_symm G _,conn_symm G _⟩ - have h₂ : Conn G (ω.erase e : Set E) x y ↔ Conn G (ω.erase e : Set E) y x := - ⟨conn_symm G _,conn_symm G _⟩ - rw [h₁,h₂] - - -theorem pairOpenPivotals_triangle_subset (G : BondGraph V E) (Q : Finset E) (ω : Finset E) - (x y z : V) (hxy : Conn G (ω : Set E) x y) (hyz : Conn G (ω : Set E) y z) : - pairOpenPivotals G Q x z ω ⊆ pairOpenPivotals G Q x y ω ∪ pairOpenPivotals G Q y z ω := by - intro e he - obtain ⟨heQ,heω,_,hnxz⟩ := Finset.mem_filter.mp he - by_cases hxy' : Conn G (ω.erase e : Set E) x y - · exact Finset.mem_union_right _ (Finset.mem_filter.mpr - ⟨heQ,heω,hyz,fun hyz' => hnxz (hxy'.trans hyz')⟩) - · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨heQ,heω,hxy,hxy'⟩) - -theorem pairOpenPivotals_triangle (G : BondGraph V E) (Q : Finset E) (ω : Finset E) - (x y z : V) (hxy : Conn G (ω : Set E) x y) (hyz : Conn G (ω : Set E) y z) : - (pairOpenPivotals G Q x z ω).card ≤ - (pairOpenPivotals G Q x y ω).card+(pairOpenPivotals G Q y z ω).card := - (Finset.card_le_card (pairOpenPivotals_triangle_subset G Q ω x y z hxy hyz)).trans - (Finset.card_union_le _ _) - - -theorem conn_no_crossing_internal (G : BondGraph V E) (W : Set V) (ω : Set E) - (hc : ∀ e ∈ ω, ¬CutExists G W e) {x y : V} (hx : x ∈ W) (hxy : Conn G ω x y) : - Conn G (ω ∩ internalEdges G W) x y ∧ y ∈ W := by - induction hxy with - | refl => exact ⟨conn_refl _ _ _,hx⟩ - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - have hb : b ∈ W := by - by_contra hn - exact hc e he ⟨a,b,heq,ih.2,hn⟩ - exact ⟨ih.1.tail ⟨e,⟨he,(mem_internalEdges_of_ends G W e a b heq).mpr ⟨ih.2,hb⟩⟩,heq⟩,hb⟩ - - -theorem conn_one_attachment_internal (G : BondGraph V E) (W : Set V) (ω : Set E) - (e : E) (he : e ∈ ω) (hec : CutExists G W e) - (hone : ∀ f ∈ ω, CutExists G W f → f = e) - {x y : V} (hx : x ∈ W) (hy : y ∈ W) (hxy : Conn G ω x y) : - Conn G (ω ∩ internalEdges G W) x y := by - obtain ⟨a,b,hab,ha,hb⟩ := hec - let η := ω \ {e} - have hn : ∀ f ∈ η, ¬CutExists G W f := by - intro f hf hc - exact hf.2 (Set.mem_singleton_iff.mpr (hone f hf.1 hc)) - have hη (u v : V) (hu : u ∈ W) (huv : Conn G η u v) := - conn_no_crossing_internal G W η hn hu huv - have hω : insert e η = ω := by dsimp [η]; ext f; simp [he] - have hw : Conn G (insert e η) x y := hω ▸ hxy - rcases (conn_insert_iff G η e a b x y hab).mp hw with h | ⟨_,h⟩ | ⟨h,_⟩ - · exact conn_mono G (show η ∩ internalEdges G W ⊆ ω ∩ internalEdges G W from - fun _ hf => ⟨hf.1.1,hf.2⟩) (hη x y hx h).1 - · exact (hb (hη y b hy (conn_symm G η h)).2).elim - · exact (hb (hη x b hx h).2).elim - -noncomputable def internalBonds (G : BondGraph V E) (ω : Finset E) (W : Set V) : Finset E := - ω.filter fun e => e ∈ internalEdges G W - -@[simp] theorem coe_internalBonds (G : BondGraph V E) (ω : Finset E) (W : Set V) : - (internalBonds G ω W : Set E) = (ω : Set E) ∩ internalEdges G W := by - ext e; simp [internalBonds] - - -theorem pairOpenPivotals_one_attachment (G : BondGraph V E) (Q ω : Finset E) (W : Set V) - (e : E) (he : e ∈ ω) (hec : CutExists G W e) - (hone : ∀ f ∈ ω, CutExists G W f → f = e) - {x y : V} (hx : x ∈ W) (hy : y ∈ W) : - pairOpenPivotals G Q x y (internalBonds G ω W) ⊆ pairOpenPivotals G Q x y ω := by - intro f hf - obtain ⟨hfQ,hfω,hxy,hnxy⟩ := Finset.mem_filter.mp hf - have hfint : f ∈ internalEdges G W := (Finset.mem_filter.mp hfω).2 - have hfe : e ≠ f := by - intro hef - obtain ⟨a,b,hab,ha,hb⟩ := hec - have hh : e ∈ internalEdges G W := hef ▸ hfint - exact hb ((mem_internalEdges_of_ends G W e a b hab).mp hh).2 - have he' : e ∈ ω.erase f := Finset.mem_erase.mpr ⟨hfe,he⟩ - have hcoe : (internalBonds G ω W).erase f = internalBonds G (ω.erase f) W := by - ext g; simp [internalBonds]; tauto - refine Finset.mem_filter.mpr ⟨hfQ,(Finset.mem_filter.mp hfω).1,?_,?_⟩ - · exact conn_mono G (by simpa only [coe_internalBonds] using Set.inter_subset_left) hxy - · intro h - have hh := conn_one_attachment_internal G W (ω.erase f : Set E) e he' hec - (fun g hg hc => hone g (Finset.mem_of_mem_erase hg) hc) hx hy h - apply hnxy - simpa only [hcoe,coe_internalBonds] using hh - - -theorem conn_first_entry (G : BondGraph V E) (W : Set V) (ω : Set E) - {x y : V} (hx : x ∉ W) (hy : y ∈ W) (hxy : Conn G ω x y) : - ∃ a b e, a ∉ W ∧ b ∈ W ∧ e ∈ ω ∧ G e = s(a,b) ∧ - Conn G (ω ∩ internalEdges G Wᶜ) x a := by - let Entry : Prop := ∃ a b e, a ∉ W ∧ b ∈ W ∧ e ∈ ω ∧ G e = s(a,b) ∧ - Conn G (ω ∩ internalEdges G Wᶜ) x a - have haux : Conn G (ω ∩ internalEdges G Wᶜ) x y ∨ Entry := by - clear hy - induction hxy with - | refl => exact Or.inl (conn_refl _ _ _) - | @tail a b hxa hab ih => - rcases ih with ih | ih - · have ha : a ∉ W := conn_internal_endpoint G Wᶜ hx ih - obtain ⟨e,he,heq⟩ := hab - by_cases hb : b ∈ W - · exact Or.inr ⟨a,b,e,ha,hb,he,heq,ih⟩ - · exact Or.inl (ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G Wᶜ e a b heq).mpr ⟨ha,hb⟩⟩,heq⟩) - · exact Or.inr ih - rcases haux with h | h - · exact ((conn_internal_endpoint G Wᶜ hx h) hy).elim - · exact h - - -noncomputable def pruneContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : Finset E := - ω.filter fun f => ¬CutExists G W f ∨ f = e - -theorem internal_not_cut (G : BondGraph V E) (W : Set V) {e : E} - (he : e ∈ internalEdges G W) : ¬CutExists G W e := by - rintro ⟨a,b,hab,ha,hb⟩ - exact hb ((mem_internalEdges_of_ends G W e a b hab).mp he).2 - -theorem exterior_not_cut (G : BondGraph V E) (W : Set V) {e : E} - (he : e ∈ internalEdges G Wᶜ) : ¬CutExists G W e := by - rintro ⟨a,b,hab,ha,hb⟩ - exact ((mem_internalEdges_of_ends G Wᶜ e a b hab).mp he).1 ha - -theorem internal_pruneContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : - internalBonds G (pruneContacts G ω W e) W = internalBonds G ω W := by - ext f - simp only [internalBonds,pruneContacts,Finset.mem_filter] - constructor - · exact fun h => ⟨h.1.1,h.2⟩ - · exact fun h => ⟨⟨h.1,Or.inl (internal_not_cut G W h.2)⟩,h.2⟩ - -theorem pruneContacts_only_attachment (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : - ∀ f ∈ pruneContacts G ω W e, CutExists G W f → f = e := by - intro f hf hc - exact (Finset.mem_filter.mp hf).2.resolve_left (not_not.mpr hc) - - -theorem exists_pruneContacts_root (G : BondGraph V E) (ω : Finset E) (W : Set V) (x : V) - (hWroot : W ⊆ cluster G ω x) (hWconn : ∀ a ∈ W, ∀ b ∈ W, - Conn G (ω ∩ internalEdges G W) a b) - (hcontact : ∃ e ∈ ω, CutExists G W e) : - ∃ e ∈ ω, CutExists G W e ∧ W ⊆ cluster G (pruneContacts G ω W e) x := by - by_cases hx : x ∈ W - · obtain ⟨e,he,hec⟩ := hcontact - refine ⟨e,he,hec,?_⟩ - intro y hy - apply conn_mono G _ (hWconn x hx y hy) - intro f hf - exact Finset.mem_filter.mpr ⟨hf.1,Or.inl (internal_not_cut G W hf.2)⟩ - · obtain ⟨e₀,he₀,a,b,hab,ha,hb⟩ := hcontact - obtain ⟨c,z,e,hc,hz,he,hez,hxc⟩ := conn_first_entry G W ω hx ha (hWroot ha) - have hec : CutExists G W e := ⟨z,c,by simpa only [Sym2.eq_swap] using hez,hz,hc⟩ - have hep : e ∈ pruneContacts G ω W e := Finset.mem_filter.mpr ⟨he,Or.inr rfl⟩ - have hxz : Conn G (pruneContacts G ω W e : Set E) x z := - (conn_mono G (fun f hf => Finset.mem_filter.mpr ⟨hf.1,Or.inl (exterior_not_cut G W hf.2)⟩) hxc).tail - ⟨e,hep,hez⟩ - refine ⟨e,he,hec,?_⟩ - intro y hy - exact hxz.trans (conn_mono G (fun f hf => - Finset.mem_filter.mpr ⟨hf.1,Or.inl (internal_not_cut G W hf.2)⟩) (hWconn z hz y hy)) - -end PruningGeometry - -section GoodnessGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -@[simp] theorem mem_pairOpenPivotals (G : BondGraph V E) (Q : Finset E) (x y : V) - (ω : Finset E) (e : E) : e ∈ pairOpenPivotals G Q x y ω ↔ - e ∈ Q ∧ OpenMarkedPivotal G (ω : Set E) {y} x e := by - simp only [pairOpenPivotals,Finset.mem_filter,OpenMarkedPivotal,MarkedEvent, - Set.mem_singleton_iff,exists_eq_left,Finset.coe_erase,Finset.mem_coe] - - -theorem pairOpenPivotals_card_le (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) : - (pairOpenPivotals G Q x y ω).card ≤ (finiteRootComponent G ω x).card-1 := by - let N := (finiteRootComponent G ω x).card - have hN : (cluster G (ω : Set E) x).ncard = N := by - rw [← coe_finiteRootComponent,Set.ncard_coe_finset] - have hm : Set.MapsTo (pivotalRank G ω x) (pairOpenPivotals G Q x y ω : Set E) - (Finset.Ico 1 N : Set ℕ) := by - intro e he - have he' := ((mem_pairOpenPivotals G Q x y ω e).mp he).2 - have hfin := cluster_finite_of_finite_edges G (ω := (ω : Set E) \ {e}) (ω.finite_toSet.subset Set.sdiff_subset) x - have hpos : 0 < pivotalRank G ω x e := - (Set.ncard_pos hfin).mpr ⟨x,conn_refl G _ x⟩ - have hlt : pivotalRank G ω x e < N := by - rw [pivotalRank,← hN] - apply Set.ncard_lt_ncard _ (cluster_finite_of_finite_edges G ω.finite_toSet x) - refine Set.ssubset_iff_subset_ne.mpr ⟨fun z hz => conn_mono G Set.sdiff_subset hz,?_⟩ - intro heq - obtain ⟨z,hz,hxz⟩ := he'.2.1 - have hz' : z ∈ cluster G (ω : Set E) x := hxz - have hz'' : z ∈ cluster G ((ω : Set E) \ {e}) x := heq.symm ▸ hz' - exact he'.2.2 ⟨z,hz,hz''⟩ - exact Finset.mem_Ico.mpr ⟨hpos,hlt⟩ - have hi : Set.InjOn (pivotalRank G ω x) (pairOpenPivotals G Q x y ω : Set E) := by - intro e he f hf h - exact pivotalRank_injective G ω.finite_toSet {y} x - ((mem_pairOpenPivotals G Q x y ω e).mp he).2 - ((mem_pairOpenPivotals G Q x y ω f).mp hf).2 h - simpa [N] using Finset.card_le_card_of_injOn (pivotalRank G ω x) hm hi - -theorem finiteRootComponent_mono (G : BondGraph V E) {ω η : Finset E} (h : ω ⊆ η) (x : V) : - finiteRootComponent G ω x ⊆ finiteRootComponent G η x := by - intro y hy - change y ∈ (finiteRootComponent G η x : Set V) - rw [coe_finiteRootComponent] - apply conn_mono G (show (ω : Set E) ⊆ η from h) - change y ∈ (finiteRootComponent G ω x : Set V) at hy - rwa [coe_finiteRootComponent] at hy - - -noncomputable def openContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) : Finset E := - ω.filter fun e => CutExists G W e - - -def BadPieceEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M K : ℕ) (L : ℝ) - (ω : Finset E) : Prop := - (finiteRootComponent G ω x).card ≤ M ∧ ∃ W : Finset V, - W ⊆ finiteRootComponent G ω x ∧ - (∀ a ∈ W, ∀ b ∈ W, Conn G (internalBonds G ω (W : Set V) : Set E) a b) ∧ - (openContacts G ω (W : Set V)).card = K ∧ - ∃ a ∈ W, ∃ b ∈ W, (K:ℝ)*L < (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card - - -theorem badPieceEvent_contact_bound (G : BondGraph V E) (Q : Finset E) (x : V) - (M K : ℕ) (L : ℝ) (ω : Finset E) (h : BadPieceEvent G Q x M K L ω) : - (K:ℝ)*L < (M:ℝ) := by - obtain ⟨hcap,W,hW,_,_,a,ha,b,_,hbad⟩ := h - have hsub : finiteRootComponent G (internalBonds G ω (W : Set V)) a ⊆ W := by - intro z hz - apply conn_internal_endpoint G (W : Set V) (ω := (ω : Set E)) ha - change z ∈ (finiteRootComponent G (internalBonds G ω (W : Set V)) a : Set V) at hz - rw [coe_finiteRootComponent] at hz - simpa only [coe_internalBonds,cluster,Set.mem_ofPred_eq] using hz - have hab := pairOpenPivotals_card_le G Q a b (internalBonds G ω (W : Set V)) - have hpos : 0 < (finiteRootComponent G (internalBonds G ω (W : Set V)) a).card := by - apply Finset.card_pos.mpr - refine ⟨a,?_⟩ - change a ∈ (finiteRootComponent G (internalBonds G ω (W : Set V)) a : Set V) - rw [coe_finiteRootComponent] - exact conn_refl G _ a - have hn : (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card < M := by - have h₁ := Finset.card_le_card hsub - have h₂ := Finset.card_le_card hW - omega - exact hbad.trans (by exact_mod_cast hn) - - -noncomputable def incidentBonds (G : BondGraph V E) (Q : Finset E) (W : Finset V) : Finset E := - W.biUnion fun v => Q.filter fun e => v ∈ G e - -@[simp] theorem mem_incidentBonds (G : BondGraph V E) (Q : Finset E) (W : Finset V) (e : E) : - e ∈ incidentBonds G Q W ↔ e ∈ Q ∧ ∃ v ∈ W, v ∈ G e := by - simp only [incidentBonds,Finset.mem_biUnion,Finset.mem_filter] - aesop - -theorem incidentBonds_card_le (G : BondGraph V E) (Q : Finset E) (W : Finset V) (d : ℕ) - (hd : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : - (incidentBonds G Q W).card ≤ d*W.card := by - calc - _ ≤ ∑ v ∈ W, (Q.filter fun e => v ∈ G e).card := Finset.card_biUnion_le - _ ≤ ∑ _v ∈ W, d := Finset.sum_le_sum fun _ _ => hd _ - _ = _ := by simp [Nat.mul_comm] - - - -theorem badPieceEvent_pruning (G : BondGraph V E) (Q : Finset E) (x : V) (M K r : ℕ) - (L : ℝ) (hK : 0 < K) (hr : 2*(r:ℝ) ≤ (K:ℝ)*L) - (ω : Finset E) (hω : ω ⊆ Q) (h : BadPieceEvent G Q x M K L ω) : - ∃ η : Finset E, η ⊆ ω ∧ CappedRadiusEvent G Q x M r η ∧ - (ω \ η).card ≤ K ∧ ω \ η ⊆ incidentBonds G Q (finiteRootComponent G η x) := by - obtain ⟨hcap,W,hW,hWconn,hcontacts,a,ha,b,hb,hbad⟩ := h - have hcontact : ∃ e ∈ ω, CutExists G (W : Set V) e := by - have : (openContacts G ω (W : Set V)).Nonempty := Finset.card_pos.mp (hcontacts ▸ hK) - obtain ⟨e,he⟩ := this - exact ⟨e,(Finset.mem_filter.mp he).1,(Finset.mem_filter.mp he).2⟩ - have hWroot : (W : Set V) ⊆ cluster G ω x := by - intro z hz - have hh : z ∈ (finiteRootComponent G ω x : Set V) := hW hz - rwa [coe_finiteRootComponent] at hh - obtain ⟨e,he,hec,hWη⟩ := exists_pruneContacts_root G ω (W : Set V) x hWroot - (by intro a ha b hb; simpa only [coe_internalBonds] using hWconn a ha b hb) hcontact - let η := pruneContacts G ω (W : Set V) e - have hη : η ⊆ ω := Finset.filter_subset _ _ - have hep : e ∈ η := Finset.mem_filter.mpr ⟨he,Or.inr rfl⟩ - have hpiv := pairOpenPivotals_one_attachment G Q η (W : Set V) e hep hec - (pruneContacts_only_attachment G ω (W : Set V) e) ha hb - rw [internal_pruneContacts] at hpiv - have hfar : (K:ℝ)*L < (pairOpenPivotals G Q a b η).card := - hbad.trans_le (by exact_mod_cast Finset.card_le_card hpiv) - have hxa : Conn G (η : Set E) x a := hWη ha - have hxb : Conn G (η : Set E) x b := hWη hb - have htri := pairOpenPivotals_triangle G Q η a x b (conn_symm G η hxa) hxb - rw [pairOpenPivotals_symm G Q η a x] at htri - have hlarge : r ≤ (pairOpenPivotals G Q x a η).card ∨ - r ≤ (pairOpenPivotals G Q x b η).card := by - by_contra hn - push Not at hn - have htri' : ((pairOpenPivotals G Q a b η).card:ℝ) ≤ - (pairOpenPivotals G Q x a η).card+(pairOpenPivotals G Q x b η).card := by exact_mod_cast htri - have h₁ : ((pairOpenPivotals G Q x a η).card:ℝ) < r := by exact_mod_cast hn.1 - have h₂ : ((pairOpenPivotals G Q x b η).card:ℝ) < r := by exact_mod_cast hn.2 - linarith - have hchanges : ω \ η ⊆ openContacts G ω (W : Set V) := by - intro f hf - obtain ⟨hfω,hfη⟩ := Finset.mem_sdiff.mp hf - refine Finset.mem_filter.mpr ⟨hfω,?_⟩ - by_contra hn - exact hfη (Finset.mem_filter.mpr ⟨hfω,Or.inl hn⟩) - refine ⟨η,hη,⟨(Finset.card_le_card (finiteRootComponent_mono G hη x)).trans hcap,?_⟩, - (Finset.card_le_card hchanges).trans (le_of_eq hcontacts),?_⟩ - · rcases hlarge with h | h - · exact ⟨a,hxa,h⟩ - · exact ⟨b,hxb,h⟩ - · intro f hf - obtain ⟨hfω,c,z,hcz,hc,_⟩ := Finset.mem_filter.mp (hchanges hf) - refine (mem_incidentBonds G Q _ f).mpr ⟨hω hfω,c,?_,?_⟩ - · change c ∈ (finiteRootComponent G η x : Set V) - rw [coe_finiteRootComponent] - exact hWη hc - · simp [hcz] - -end GoodnessGeometry - -section FiniteInverseCost -attribute [local instance] Classical.propDecidable Classical.decEq - - -def bernoulliWeight (Q ω : Finset E) (p : ℝ) : ℝ := - p^ω.card*(1-p)^(Q.card-ω.card) - -theorem bernoulliWeight_nonneg (Q ω : Finset E) (p : unitInterval) : - 0 ≤ bernoulliWeight Q ω p := mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) - - -theorem bernoulliWeight_closure_ratio (Q ω η : Finset E) (hη : η ⊆ ω) (hω : ω ⊆ Q) - (p : ℝ) (hp : p < 1) : - bernoulliWeight Q ω p = bernoulliWeight Q η p*(p/(1-p))^((ω \ η).card) := by - have h₁ := Finset.card_le_card hη - have h₂ := Finset.card_le_card hω - have hj : (ω \ η).card = ω.card-η.card := Finset.card_sdiff_of_subset hη - have ha : ω.card = η.card+(ω \ η).card := by omega - have hb : Q.card-η.card = (Q.card-ω.card)+(ω \ η).card := by omega - have hq : (1-p) ≠ 0 := ne_of_gt (sub_pos.mpr hp) - unfold bernoulliWeight - rw [hb,pow_add,div_pow] - rw [← mul_div_assoc] - apply (eq_div_iff (pow_ne_zero _ hq)).mpr - rw [ha,pow_add] - ring - - -theorem bernoulliWeight_closure_le (Q ω η : Finset E) (hη : η ⊆ ω) (hω : ω ⊆ Q) - (p : unitInterval) (hp : (p:ℝ) < 1) (K : ℕ) (hj : (ω \ η).card ≤ K) : - bernoulliWeight Q ω p ≤ (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := by - rw [bernoulliWeight_closure_ratio Q ω η hη hω p hp,mul_comm] - apply mul_le_mul_of_nonneg_right _ (bernoulliWeight_nonneg Q η p) - calc - _ ≤ (max 1 ((p:ℝ)/(1-p)))^((ω \ η).card) := - pow_le_pow_left₀ (div_nonneg p.2.1 (sub_nonneg.mpr p.2.2)) (le_max_right ..) _ - _ ≤ _ := pow_le_pow_right₀ (le_max_left ..) hj - - -theorem card_small_subsets_le (S : Finset E) (K N : ℕ) (hS : S.card ≤ N) (hN : 1 ≤ N) : - (S.powerset.filter fun T => T.card ≤ K).card ≤ (K+1)*N^K := by - have hsub : S.powerset.filter (fun T => T.card ≤ K) ⊆ - (Finset.range (K+1)).biUnion (fun j => S.powersetCard j) := by - intro T hT - obtain ⟨hTS,hTK⟩ := Finset.mem_filter.mp hT - exact Finset.mem_biUnion.mpr ⟨T.card,Finset.mem_range.mpr (Nat.lt_succ_of_le hTK), - Finset.mem_powersetCard.mpr ⟨Finset.mem_powerset.mp hTS,rfl⟩⟩ - calc - _ ≤ _ := Finset.card_le_card hsub - _ ≤ ∑ j ∈ Finset.range (K+1), (S.powersetCard j).card := Finset.card_biUnion_le - _ ≤ ∑ _j ∈ Finset.range (K+1), N^K := by - apply Finset.sum_le_sum - intro j hj - rw [Finset.card_powersetCard] - exact (Nat.choose_le_pow _ _).trans ((Nat.pow_le_pow_left hS _).trans - (Nat.pow_le_pow_right hN (Nat.le_of_lt_succ (Finset.mem_range.mp hj)))) - _ = _ := by simp - - -theorem closure_fiber_card_le (A : Finset (Finset E)) (f : Finset E → Finset E) - (S : Finset E) (η : Finset E) (K N : ℕ) (hN : 1 ≤ N) (hS : S.card ≤ N) - (hf : ∀ ω ∈ A, f ω = η → f ω ⊆ ω ∧ (ω \ f ω).card ≤ K ∧ ω \ f ω ⊆ S) : - (A.filter fun ω => f ω = η).card ≤ (K+1)*N^K := by - have hm : Set.MapsTo (fun ω : Finset E => ω \ η) (A.filter fun ω => f ω = η : Set (Finset E)) - (S.powerset.filter fun T => T.card ≤ K : Set (Finset E)) := by - intro ω hω - obtain ⟨hωA,heq⟩ := Finset.mem_filter.mp hω - obtain ⟨_,hj,hs⟩ := hf ω hωA heq - rw [heq] at hj hs - exact Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr hs,hj⟩ - have hi : Set.InjOn (fun ω : Finset E => ω \ η) (A.filter fun ω => f ω = η : Set (Finset E)) := by - intro ω hω ζ hζ heq - obtain ⟨hωA,hωη⟩ := Finset.mem_filter.mp hω - obtain ⟨hζA,hζη⟩ := Finset.mem_filter.mp hζ - have h₁ := (hf ω hωA hωη).1 - have h₂ := (hf ζ hζA hζη).1 - rw [hωη] at h₁ - rw [hζη] at h₂ - have : η ∪ (ω \ η) = η ∪ (ζ \ η) := congrArg (fun s => η ∪ s) heq - simpa only [Finset.union_sdiff_of_subset h₁,Finset.union_sdiff_of_subset h₂] using this - exact (Finset.card_le_card_of_injOn (fun ω => ω \ η) hm hi).trans (card_small_subsets_le S K N hS hN) - - -theorem finite_closure_comparison (Q : Finset E) (A B : Finset (Finset E)) - (hA : A ⊆ Q.powerset) (f : Finset E → Finset E) (S : Finset E → Finset E) - (K N : ℕ) (hN : 1 ≤ N) (p : unitInterval) (hp : (p:ℝ) < 1) - (hf : ∀ ω ∈ A, f ω ∈ B ∧ f ω ⊆ ω ∧ (ω \ f ω).card ≤ K ∧ ω \ f ω ⊆ S (f ω)) - (hS : ∀ η ∈ B, (S η).card ≤ N) : - (∑ ω ∈ A, bernoulliWeight Q ω p) ≤ - (((K+1)*N^K : ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K*∑ η ∈ B, bernoulliWeight Q η p := by - rw [← Finset.sum_fiberwise_of_maps_to (fun ω hω => (hf ω hω).1) (fun ω => bernoulliWeight Q ω p), - Finset.mul_sum] - apply Finset.sum_le_sum - intro η hη - let T := A.filter fun ω => f ω = η - have hc : T.card ≤ (K+1)*N^K := closure_fiber_card_le A f (S η) η K N hN (hS η hη) (by - intro ω hω heq - have hh := (hf ω hω).2 - simpa only [heq] using hh) - have hweight : ∀ ω ∈ T, bernoulliWeight Q ω p ≤ - (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := by - intro ω hω - obtain ⟨hωA,heq⟩ := Finset.mem_filter.mp hω - have hh := bernoulliWeight_closure_le Q ω (f ω) (hf ω hωA).2.1 - (Finset.mem_powerset.mp (hA hωA)) p hp K (hf ω hωA).2.2.1 - simpa only [heq] using hh - calc - _ ≤ ∑ _ω ∈ T, (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := Finset.sum_le_sum hweight - _ = (T.card:ℝ)*((max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p) := by simp - _ ≤ (((K+1)*N^K:ℕ):ℝ)*((max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p) := - mul_le_mul_of_nonneg_right (by exact_mod_cast hc) - (mul_nonneg (pow_nonneg (le_trans zero_le_one (le_max_left ..)) _) (bernoulliWeight_nonneg Q η p)) - _ = _ := by ring - -end FiniteInverseCost - -section FiniteGoodnessProbability -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteBadPieceProbability (G : BondGraph V E) (Q : Finset E) - (x : V) (M K : ℕ) (L p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => if BadPieceEvent G Q x M K L ω then 1 else 0) p - -theorem bernoulliPolynomial_indicator_weight (Q : Finset E) (P : Finset E → Prop) (p : ℝ) : - bernoulliPolynomial Q (fun ω => if P ω then 1 else 0) p = - ∑ ω ∈ Q.powerset.filter P, bernoulliWeight Q ω p := by - rw [Finset.sum_filter] - unfold bernoulliPolynomial - apply Finset.sum_congr rfl - intro ω hω - by_cases h : P ω <;> simp [h,bernoulliWeight] - - -theorem finiteBadPieceProbability_le_radius (G : BondGraph V E) (Q : Finset E) (x : V) - (M K r d : ℕ) (L : ℝ) (hK : 0 < K) (hN : 1 ≤ d*M) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) - (hr : 2*(r:ℝ) ≤ (K:ℝ)*L) (p : unitInterval) (hp : (p:ℝ) < 1) : - finiteBadPieceProbability G Q x M K L p ≤ - (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K*finiteCappedRadiusTail G Q x M r p := by - let A := Q.powerset.filter (BadPieceEvent G Q x M K L) - let B := Q.powerset.filter (CappedRadiusEvent G Q x M r) - let S := fun η => incidentBonds G Q (finiteRootComponent G η x) - have hex : ∀ ω : Finset E, ∃ η : Finset E, ω ∈ A → - η ∈ B ∧ η ⊆ ω ∧ (ω \ η).card ≤ K ∧ ω \ η ⊆ S η := by - intro ω - by_cases hω : ω ∈ A - · obtain ⟨hωQ,hωbad⟩ := Finset.mem_filter.mp hω - have hωsub := Finset.mem_powerset.mp hωQ - obtain ⟨η,hη,hcap,hcard,hS⟩ := badPieceEvent_pruning G Q x M K r L hK hr ω hωsub hωbad - exact ⟨η,fun _ => ⟨Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr (hη.trans hωsub),hcap⟩, - hη,hcard,hS⟩⟩ - · exact ⟨∅,fun h => (hω h).elim⟩ - choose f hf using hex - have hS : ∀ η ∈ B, (S η).card ≤ d*M := by - intro η hη - exact (incidentBonds_card_le G Q (finiteRootComponent G η x) d hdeg).trans - (Nat.mul_le_mul_left d (Finset.mem_filter.mp hη).2.1) - have hc := finite_closure_comparison Q A B (Finset.filter_subset _ _) f S K (d*M) hN p hp hf hS - simpa only [finiteBadPieceProbability,finiteCappedRadiusTail,bernoulliPolynomial_indicator_weight, - A,B] using hc - - -theorem finiteBadPieceProbability_exponential [Nonempty V] (G : BondGraph V E) - (Q : Finset E) (x : V) (M K d : ℕ) (L : ℝ) (hK : 0 < K) (hN : 1 ≤ d*M) - (hL : 4 ≤ (K:ℝ)*L) (hd : 0 < d) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) - (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) - (B : ℝ) (hB : 1 ≤ B) - (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) : - finiteBadPieceProbability G Q x M K L p ≤ - (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K* - (2/((h:ℝ)*(1-h)^M))*Real.exp (-((K:ℝ)*L)/(16*B)) := by - let r := ⌈(K:ℝ)*L/4⌉₊ - have hpos : 0 ≤ (K:ℝ)*L/4 := by linarith - have hrlo : (K:ℝ)*L/4 ≤ r := Nat.le_ceil _ - have hrhi : (r:ℝ) < (K:ℝ)*L/4+1 := Nat.ceil_lt_add_one hpos - have hr : 2*(r:ℝ) ≤ (K:ℝ)*L := by linarith - have hrad := finiteCappedRadiusTail_exponential G p h hp hh hh1 d hd Q x hdeg B hB hAB M r - have hcmp := finiteBadPieceProbability_le_radius G Q x M K r d L hK hN hdeg hr p hp - have hc : 0 ≤ (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K := by positivity - have hhfac : 0 ≤ 2/((h:ℝ)*(1-h)^M) := by positivity - have hBpos : 0 < B := lt_of_lt_of_le zero_lt_one hB - have hratio : -((r:ℝ)/(4*B)) ≤ -((K:ℝ)*L)/(16*B) := by - apply (le_div_iff₀ (by positivity : 0 < 16*B)).mpr - field_simp - nlinarith - exact hcmp.trans ((mul_le_mul_of_nonneg_left hrad hc).trans (by - rw [← mul_assoc] - exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by simpa only [neg_div] using hratio)) (mul_nonneg hc hhfac))) - - - -def FiniteGoodForScale (G : BondGraph V E) (Q : Finset E) (x : V) (L : ℝ) (ω : Finset E) : Prop := - ∀ W : Finset V, W ⊆ finiteRootComponent G ω x → - (∀ a ∈ W, ∀ b ∈ W, Conn G (internalBonds G ω (W : Set V) : Set E) a b) → - 0 < (openContacts G ω (W : Set V)).card → - ∀ a ∈ W, ∀ b ∈ W, - (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card ≤ - ((openContacts G ω (W : Set V)).card:ℝ)*L - -def CappedBadGoodnessEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M : ℕ) (L : ℝ) - (ω : Finset E) : Prop := - (finiteRootComponent G ω x).card ≤ M ∧ ¬FiniteGoodForScale G Q x L ω - -noncomputable def finiteBadGoodnessProbability (G : BondGraph V E) (Q : Finset E) - (x : V) (M : ℕ) (L p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => if CappedBadGoodnessEvent G Q x M L ω then 1 else 0) p - - -theorem cappedBadGoodness_iff (G : BondGraph V E) (Q : Finset E) (x : V) (M d : ℕ) - (L : ℝ) (ω : Finset E) (hω : ω ⊆ Q) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : - CappedBadGoodnessEvent G Q x M L ω ↔ - ∃ K ∈ Finset.Icc 1 (d*M), BadPieceEvent G Q x M K L ω := by - constructor - · rintro ⟨hcap,hbad⟩ - simp only [FiniteGoodForScale,not_forall] at hbad - obtain ⟨W,hbad⟩ := hbad - push Not at hbad - obtain ⟨hW,hWconn,hK,a,ha,b,hb,hfar⟩ := hbad - have hinc : openContacts G ω (W : Set V) ⊆ incidentBonds G Q W := by - intro e he - obtain ⟨heω,c,z,hcz,hc,_⟩ := Finset.mem_filter.mp he - exact (mem_incidentBonds G Q W e).mpr ⟨hω heω,c,hc,by simp [hcz]⟩ - have hbound := (Finset.card_le_card hinc).trans ((incidentBonds_card_le G Q W d hdeg).trans - (Nat.mul_le_mul_left d ((Finset.card_le_card hW).trans hcap))) - exact ⟨_,Finset.mem_Icc.mpr ⟨hK,hbound⟩,hcap,W,hW,hWconn,rfl,a,ha,b,hb,hfar⟩ - · rintro ⟨K,hK,hcap,W,hW,hWconn,hcontacts,a,ha,b,hb,hfar⟩ - refine ⟨hcap,fun hgood => ?_⟩ - have hh := hgood W hW hWconn (by rw [hcontacts]; exact (Finset.mem_Icc.mp hK).1) a ha b hb - rw [hcontacts] at hh - exact not_lt_of_ge hh hfar - - -theorem finiteBadGoodnessProbability_le_sum (G : BondGraph V E) (Q : Finset E) (x : V) - (M d : ℕ) (L : ℝ) (p : unitInterval) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : - finiteBadGoodnessProbability G Q x M L p ≤ - ∑ K ∈ Finset.Icc 1 (d*M), finiteBadPieceProbability G Q x M K L p := by - unfold finiteBadPieceProbability finiteBadGoodnessProbability - rw [← bernoulliPolynomial_sum] - apply bernoulliPolynomial_mono _ _ _ _ p.2 - intro ω hω - by_cases he : CappedBadGoodnessEvent G Q x M L ω - · obtain ⟨K,hK,hbad⟩ := (cappedBadGoodness_iff G Q x M d L ω hω hdeg).mp he - simp only [he,ite_true] - exact (by simp [hbad] : (1:ℝ) ≤ if BadPieceEvent G Q x M K L ω then 1 else 0).trans - (Finset.single_le_sum (f := fun j => if BadPieceEvent G Q x M j L ω then (1:ℝ) else 0) - (fun j _ => by split_ifs <;> norm_num) hK) - · simp only [he,ite_false] - exact Finset.sum_nonneg fun j _ => by split_ifs <;> norm_num - - -theorem finiteBadGoodnessProbability_geometric [Nonempty V] (G : BondGraph V E) - (Q : Finset E) (x : V) (M d : ℕ) (L : ℝ) (hN : 1 ≤ d*M) (hL : 4 ≤ L) - (hd : 0 < d) (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) - (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) - (B : ℝ) (hB : 1 ≤ B) - (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) - (hq : ((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B)) ≤ 1) : - finiteBadGoodnessProbability G Q x M L p ≤ - (2/((h:ℝ)*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* - (((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B))) := by - let N := d*M - let a := max 1 ((p:ℝ)/(1-p)) - let H := 2/((h:ℝ)*(1-h)^M) - let q := (N:ℝ)*a*Real.exp (-L/(16*B)) - have ha : 0 ≤ a := le_trans zero_le_one (le_max_left ..) - have hq0 : 0 ≤ q := mul_nonneg (mul_nonneg (Nat.cast_nonneg _) ha) (Real.exp_nonneg _) - have hH : 0 ≤ H := by dsimp [H]; positivity - have hkbound : ∀ K ∈ Finset.Icc 1 N, finiteBadPieceProbability G Q x M K L p ≤ H*((N:ℝ)+1)*q := by - intro K hK - obtain ⟨hK1,hKN⟩ := Finset.mem_Icc.mp hK - have hKR : (1:ℝ) ≤ K := by exact_mod_cast hK1 - have hKL : 4 ≤ (K:ℝ)*L := by nlinarith - have hexp := finiteBadPieceProbability_exponential G Q x M K d L hK1 hN hKL hd hdeg - p h hp hh hh1 B hB hAB - have hid : (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K* - (2/((h:ℝ)*(1-h)^M))*Real.exp (-((K:ℝ)*L)/(16*B)) = H*((K:ℝ)+1)*q^K := by - rw [show -((K:ℝ)*L)/(16*B) = (K:ℝ)*(-L/(16*B)) by ring,Real.exp_nat_mul] - simp only [q,H,N,a,mul_pow,Nat.cast_mul,Nat.cast_add,Nat.cast_pow,Nat.cast_one] - ring - rw [hid] at hexp - have hpow : q^K ≤ q := by - simpa only [pow_one] using pow_le_pow_of_le_one hq0 hq hK1 - calc - _ ≤ H*((K:ℝ)+1)*q^K := hexp - _ ≤ H*((N:ℝ)+1)*q := mul_le_mul - (mul_le_mul_of_nonneg_left (by exact_mod_cast Nat.add_le_add_right hKN 1) hH) - hpow (pow_nonneg hq0 _) (mul_nonneg hH (by positivity)) - calc - _ ≤ ∑ K ∈ Finset.Icc 1 N, finiteBadPieceProbability G Q x M K L p := - finiteBadGoodnessProbability_le_sum G Q x M d L p hdeg - _ ≤ ∑ _K ∈ Finset.Icc 1 N, H*((N:ℝ)+1)*q := Finset.sum_le_sum hkbound - _ = (N:ℝ)*(H*((N:ℝ)+1)*q) := by simp - _ = _ := by dsimp [N,H,q,a]; push_cast; ring - -end FiniteGoodnessProbability - -section GoodnessAsymptotics - - -theorem inverse_mark_cost_le (h : ℝ) (hh : 0 ≤ h) (hh2 : h ≤ 1/2) (M : ℕ) : - ((1-h)^M)⁻¹ ≤ Real.exp (2*(M:ℝ)*h) := by - have hq : 0 < 1-h := by linarith - have hi : 1/(1-h) ≤ 1+2*h := (div_le_iff₀ hq).mpr (by nlinarith) - have hl := Real.one_sub_inv_le_log_of_pos hq - rw [one_div] at hi - have hlog : -2*h ≤ Real.log (1-h) := by linarith - calc - ((1-h)^M)⁻¹ = Real.exp (-((M:ℝ)*Real.log (1-h))) := by - rw [← Real.log_pow,Real.exp_neg,Real.exp_log (pow_pos hq _)] - _ ≤ _ := Real.exp_le_exp.mpr (by - have := mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg M) - nlinarith) - - - -theorem ghost_scale_estimates (M : ℕ) (ε c a : ℝ) (d : ℕ) - (hM : 1 ≤ (M:ℝ)) (hε : 0 < ε) (hε1 : ε < 1/2) (hc : 1 ≤ c) - (ha : 1 ≤ a) (hd : 1 ≤ d) - (hsmall : (M:ℝ)^(ε-1) ≤ 1/2) - (hlog : 4*Real.log M ≤ (M:ℝ)^ε) - (hlog2 : Real.log M ≤ (M:ℝ)^(ε/2)) - (hgrowth : 80*c ≤ (M:ℝ)^(ε/4)) - (hconstant : Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a) ≤ (M:ℝ)^ε) : - let h := (M:ℝ)^(ε-1) - let B := c*(M:ℝ)^(1/2-ε/4) - let L := (M:ℝ)^(1/2+ε) - 0 < h ∧ h ≤ 1/2 ∧ 1 ≤ B ∧ - c*Real.sqrt (Real.log (1/h)/h) ≤ B ∧ - (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* - (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε) := by - dsimp only - let h := (M:ℝ)^(ε-1) - let B := c*(M:ℝ)^(1/2-ε/4) - let L := (M:ℝ)^(1/2+ε) - have hMp : 0 < (M:ℝ) := lt_of_lt_of_le zero_lt_one hM - have hcp : 0 < c := lt_of_lt_of_le zero_lt_one hc - have hap : 0 < a := lt_of_lt_of_le zero_lt_one ha - have hdp : 0 < (d:ℝ) := by exact_mod_cast (show 0 < d by omega) - have hhp : 0 < h := Real.rpow_pos_of_pos hMp _ - have hq : 0 < 1-h := by dsimp [h] at *; linarith - have hlogM : 0 ≤ Real.log M := Real.log_nonneg hM - have hinv : 1/h = (M:ℝ)^(1-ε) := by - dsimp [h] - rw [show 1-ε = -(ε-1) by ring,Real.rpow_neg hMp.le,one_div] - have hmh : (M:ℝ)*h = (M:ℝ)^ε := by - dsimp [h] - calc - _ = (M:ℝ)^((1:ℝ)+(ε-1)) := by rw [Real.rpow_add hMp,Real.rpow_one] - _ = _ := by congr 1; ring - have hhM : 1/h ≤ (M:ℝ) := by - rw [hinv] - simpa only [Real.rpow_one] using - Real.rpow_le_rpow_of_exponent_le hM (show 1-ε ≤ (1:ℝ) by linarith) - have hB1 : 1 ≤ B := by - have hp := Real.one_le_rpow hM (show 0 ≤ 1/2-ε/4 by linarith) - dsimp [B] - nlinarith - have hBp : 0 < B := lt_of_lt_of_le zero_lt_one hB1 - have hAB : c*Real.sqrt (Real.log (1/h)/h) ≤ B := by - apply mul_le_mul_of_nonneg_left _ hcp.le - have hl : Real.log (1/h) ≤ Real.log M := by - rw [hinv,Real.log_rpow hMp] - nlinarith - have hl2 : Real.log (1/h)/h ≤ (M:ℝ)^(1-ε/2) := by - calc - _ = Real.log (1/h)*(M:ℝ)^(1-ε) := by rw [div_eq_mul_one_div,hinv] - _ ≤ (M:ℝ)^(ε/2)*(M:ℝ)^(1-ε) := - mul_le_mul_of_nonneg_right (hl.trans hlog2) (Real.rpow_nonneg hMp.le _) - _ = _ := by rw [← Real.rpow_add hMp]; congr 1; ring - calc - _ ≤ Real.sqrt ((M:ℝ)^(1-ε/2)) := Real.sqrt_le_sqrt hl2 - _ = (M:ℝ)^(1/2-ε/4) := by - rw [Real.sqrt_eq_rpow,← Real.rpow_mul hMp.le] - congr 1 - ring - have hratio : 5*(M:ℝ)^ε ≤ L/(16*B) := by - have hid : (M:ℝ)^ε*(M:ℝ)^(ε/4)*(M:ℝ)^(1/2-ε/4) = L := by - dsimp [L] - rw [← Real.rpow_add hMp,← Real.rpow_add hMp] - congr 1 - ring - apply (le_div_iff₀ (by positivity : 0 < 16*B)).mpr - have hh := mul_le_mul_of_nonneg_left hgrowth - (mul_nonneg (Real.rpow_nonneg hMp.le ε) (Real.rpow_nonneg hMp.le (1/2-ε/4))) - dsimp [B] - nlinarith [hid] - refine ⟨hhp,hsmall,hB1,hAB,?_⟩ - let A := 2*(d:ℝ)^2*((d:ℝ)+1)*a - have hAp : 0 < A := by dsimp [A]; positivity - have hcost : 2/(h*(1-h)^M) ≤ 2*(M:ℝ)*Real.exp (2*(M:ℝ)^ε) := by - calc - _ = 2*(1/h)*((1-h)^M)⁻¹ := by field_simp - _ ≤ 2*(M:ℝ)*Real.exp (2*(M:ℝ)*h) := - mul_le_mul (mul_le_mul_of_nonneg_left hhM (by norm_num)) - (inverse_mark_cost_le h hhp.le hsmall M) (inv_nonneg.mpr (pow_nonneg hq.le _)) (by positivity) - _ = _ := by rw [show 2*(M:ℝ)*h = 2*(M:ℝ)^ε by rw [mul_assoc,hmh]] - have hN1 : ((d*M:ℕ):ℝ)+1 ≤ ((d:ℝ)+1)*(M:ℝ) := by push_cast; nlinarith - have hpoint : - (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* - (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ - A*(M:ℝ)^4*Real.exp (2*(M:ℝ)^ε-L/(16*B)) := by - calc - _ ≤ (2*(M:ℝ)*Real.exp (2*(M:ℝ)^ε))*((d*M:ℕ):ℝ)*(((d:ℝ)+1)*(M:ℝ))* - (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) := by - apply mul_le_mul_of_nonneg_right _ (by positivity) - exact mul_le_mul (mul_le_mul_of_nonneg_right hcost (by positivity)) hN1 - (by positivity) (by positivity) - _ = _ := by - rw [show 2*(M:ℝ)^ε-L/(16*B) = 2*(M:ℝ)^ε+(-L/(16*B)) by ring,Real.exp_add] - dsimp [A] - push_cast - ring - have heq : A*(M:ℝ)^4*Real.exp (2*(M:ℝ)^ε-L/(16*B)) = - Real.exp (Real.log A+4*Real.log M+2*(M:ℝ)^ε-L/(16*B)) := by - rw [show Real.log A+4*Real.log M+2*(M:ℝ)^ε-L/(16*B) = - Real.log A+4*Real.log M+(2*(M:ℝ)^ε-L/(16*B)) by ring,Real.exp_add, - Real.exp_add,Real.exp_log hAp] - have hh : Real.exp (4*Real.log M) = (M:ℝ)^4 := by - simpa only [Nat.cast_ofNat,Real.exp_log hMp] using Real.exp_nat_mul (Real.log M) 4 - rw [hh] - rw [heq] at hpoint - exact hpoint.trans (Real.exp_le_exp.mpr (by linarith)) - - - -theorem eventually_ghost_scale (ε c a : ℝ) (d : ℕ) (hε : 0 < ε) (hε1 : ε < 1/2) - (hc : 1 ≤ c) (ha : 1 ≤ a) (hd : 1 ≤ d) : - ∀ᶠ M : ℕ in Filter.atTop, - let h := (M:ℝ)^(ε-1) - let B := c*(M:ℝ)^(1/2-ε/4) - let L := (M:ℝ)^(1/2+ε) - 1 ≤ M ∧ 4 ≤ L ∧ 0 < h ∧ h ≤ 1/2 ∧ 1 ≤ B ∧ - c*Real.sqrt (Real.log (1/h)/h) ≤ B ∧ - (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* - (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε) := by - have hh : ∀ᶠ m : ℝ in Filter.atTop, m^(ε-1) ≤ 1/2 := by - have ht := tendsto_rpow_neg_atTop (show 0 < 1-ε by linarith) - filter_upwards [ht.eventually (Iio_mem_nhds (by norm_num : (0:ℝ) < 1/2))] with m hm - simpa only [neg_sub] using (show m^(-(1-ε)) < 1/2 from hm).le - have hl := (isLittleO_log_rpow_atTop hε).bound (show (0:ℝ) < 1/4 by norm_num) - have hl2 := (isLittleO_log_rpow_atTop (show 0 < ε/2 by linarith)).bound zero_lt_one - have hg := (tendsto_rpow_atTop (show 0 < ε/4 by linarith)).eventually (Filter.eventually_ge_atTop (80*c)) - have hC := (tendsto_rpow_atTop hε).eventually - (Filter.eventually_ge_atTop (Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a))) - have hL := (tendsto_rpow_atTop (show 0 < 1/2+ε by linarith)).eventually (Filter.eventually_ge_atTop 4) - have hnum : ∀ᶠ m : ℝ in Filter.atTop, 1 ≤ m ∧ 4 ≤ m^(1/2+ε) ∧ m^(ε-1) ≤ 1/2 ∧ - 4*Real.log m ≤ m^ε ∧ Real.log m ≤ m^(ε/2) ∧ 80*c ≤ m^(ε/4) ∧ - Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a) ≤ m^ε := by - filter_upwards [Filter.eventually_ge_atTop (1:ℝ),hh,hl,hl2,hg,hC,hL] with m hm hh hl hl2 hg hC hL - have hm0 : 0 ≤ m := le_trans zero_le_one hm - simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hm), - abs_of_nonneg (Real.rpow_nonneg hm0 ε)] at hl - simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hm), - abs_of_nonneg (Real.rpow_nonneg hm0 (ε/2)),one_mul] at hl2 - exact ⟨hm,hL,hh,by linarith,hl2,hg,hC⟩ - have hcast : Filter.Tendsto (fun M : ℕ => (M:ℝ)) Filter.atTop Filter.atTop := tendsto_natCast_atTop_atTop - filter_upwards [hcast.eventually hnum] with M hM - obtain ⟨hM,hL,hh,hl,hl2,hg,hC⟩ := hM - exact ⟨by exact_mod_cast hM,hL,ghost_scale_estimates M ε c a d hM hε hε1 hc ha hd hh hl hl2 hg hC⟩ - - -theorem ghost_ratio_le_one (M d : ℕ) (hM : 1 ≤ M) (hd : 1 ≤ d) - (h B L a ε : ℝ) (hh : 0 < h) (hh2 : h ≤ 1/2) (ha : 0 ≤ a) - (hb : (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* - (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε)) : - ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) ≤ 1 := by - have hq : 0 < 1-h := by linarith - have hp : (1-h)^M ≤ 1 := pow_le_one₀ hq.le (by linarith) - have hden : 0 < h*(1-h)^M := mul_pos hh (pow_pos hq _) - have hH : 1 ≤ 2/(h*(1-h)^M) := by - apply (le_div_iff₀ hden).mpr - have := mul_le_mul_of_nonneg_left hp hh.le - nlinarith - have hN : (1:ℝ) ≤ (d*M:ℕ) := by exact_mod_cast Nat.mul_le_mul hd hM - have hprod : 1 ≤ (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1) := - one_le_mul_of_one_le_of_one_le (one_le_mul_of_one_le_of_one_le hH hN) (by linarith) - have hq0 : 0 ≤ ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) := by positivity - exact (le_mul_of_one_le_left hq0 hprod).trans (hb.trans - (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Real.rpow_nonneg (Nat.cast_nonneg M) ε)))) - -end GoodnessAsymptotics - -section UniformFiniteGoodness -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_bad_goodness_stretched_exp [Nonempty V] (G : BondGraph V E) - (d : ℕ) (hd : 0 < d) (pbar : unitInterval) (hpbar : (pbar:ℝ) < 1) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) : - ∀ᶠ M : ℕ in Filter.atTop, ∀ (Q : Finset E) (x : V), - (∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) → - ∀ p : unitInterval, p ≤ pbar → - finiteBadGoodnessProbability G Q x M ((M:ℝ)^(1/2+ε)) p ≤ - Real.exp (-(M:ℝ)^ε) := by - let c := max 1 (Real.sqrt ((d:ℝ)/2)/(1-pbar)) - let a := max 1 ((pbar:ℝ)/(1-pbar)) - have hc : 1 ≤ c := le_max_left .. - have ha : 1 ≤ a := le_max_left .. - filter_upwards [eventually_ghost_scale ε c a d hε hε1 hc ha hd] with M hM - dsimp only at hM - obtain ⟨hM1,hL,hh,hh2,hB,hAB,hpref⟩ := hM - intro Q x hdeg p hpp - have hpp' : (p:ℝ) ≤ pbar := hpp - have hp : (p:ℝ) < 1 := hpp'.trans_lt hpbar - let h : unitInterval := ⟨(M:ℝ)^(ε-1),hh.le,by linarith⟩ - let B := c*(M:ℝ)^(1/2-ε/4) - let L := (M:ℝ)^(1/2+ε) - have hodds : max 1 ((p:ℝ)/(1-p)) ≤ a := by - apply max_le (le_max_left ..) - have hr : (p:ℝ)/(1-p) ≤ (pbar:ℝ)/(1-pbar) := - div_le_div₀ pbar.2.1 hpp' (by linarith) (by linarith) - exact hr.trans (le_max_right ..) - have hcoeff : Real.sqrt ((d:ℝ)/2)/(1-p) ≤ c := by - have hr : Real.sqrt ((d:ℝ)/2)/(1-p) ≤ Real.sqrt ((d:ℝ)/2)/(1-pbar) := - div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (by linarith) (by linarith) - exact hr.trans (le_max_right ..) - have hsqrt : 0 ≤ Real.sqrt (Real.log (1/(h:ℝ))/h) := Real.sqrt_nonneg _ - have hqbar := ghost_ratio_le_one M d hM1 hd h B L a ε hh hh2 - (le_trans zero_le_one ha) hpref - have hqcmp : ((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B)) ≤ - ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hodds (Nat.cast_nonneg _)) (Real.exp_nonneg _) - have hg := finiteBadGoodnessProbability_geometric G Q x M d L (Nat.mul_le_mul hd hM1) - hL hd hdeg p h hp hh (by dsimp [h]; linarith) B hB - ((mul_le_mul_of_nonneg_right hcoeff hsqrt).trans hAB) (hqcmp.trans hqbar) - refine hg.trans ((mul_le_mul_of_nonneg_left hqcmp ?_).trans hpref) - have hnon : 0 ≤ 1-(h:ℝ) := sub_nonneg.mpr h.2.2 - positivity - -end UniformFiniteGoodness - -section ClusterLocality -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem reachBall_le_step (G : BondGraph V E) (x : V) (n : ℕ) : - reachBall G x n ⊆ reachBall G x (n+1) := fun _ h => Or.inl h - -theorem reachBall_mono_local (G : BondGraph V E) (x : V) : Monotone (reachBall G x) := - monotone_nat_of_le_succ (reachBall_le_step G x) - -theorem walk_mem_reachBall (G : BondGraph V E) (ω : Set E) {a b x : V} - (w : (openSimpleGraph G ω).Walk a b) (n : ℕ) (ha : a ∈ reachBall G x n) : - b ∈ reachBall G x (n+w.length) := by - induction w generalizing n with - | nil => simpa using ha - | @cons a z b hz w ih => - have hz' : z ∈ reachBall G x (n+1) := by - apply Or.inr - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] - obtain ⟨e,he,hend⟩ := hz.2 - exact ⟨a,ha,e,hend⟩ - simpa only [SimpleGraph.Walk.length_cons,Nat.add_assoc,Nat.add_left_comm,Nat.add_comm] - using ih (n+1) hz' - - -theorem finite_cluster_subset_reachBall (G : BondGraph V E) (ω : Set E) (x : V) - (hfin : (cluster G ω x).Finite) (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) : - cluster G ω x ⊆ reachBall G x M := by - intro y hy - obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp hy - let q := w.toPath - have hs : q.val.support.toFinset ⊆ hfin.toFinset := by - intro z hz - have hz' : z ∈ q.val.support := List.mem_toFinset.mp hz - exact hfin.mem_toFinset.mpr ((conn_iff_reachable G ω x z).mpr ⟨q.val.takeUntil z hz'⟩) - have hc : q.val.length+1 ≤ (cluster G ω x).ncard := by - have hc := Finset.card_le_card hs - rwa [List.toFinset_card_of_nodup q.property.support_nodup, - SimpleGraph.Walk.length_support,← Set.ncard_eq_toFinset_card _ hfin] at hc - have hr := walk_mem_reachBall G ω q.val 0 (Set.mem_singleton x) - simp only [Nat.zero_add] at hr - exact reachBall_mono_local G x (by omega) hr - - - -theorem cluster_restrict_incident_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (ω : Set E) (x : V) - (hsub : cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x ⊆ Λ) : - cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x = cluster G ω x := by - apply Set.Subset.antisymm - · exact fun _ h => conn_mono G Set.inter_subset_left h - · intro y hy - induction hy with - | refl => exact conn_refl G _ x - | @tail a b _ hab ih => - obtain ⟨e,he,hend⟩ := hab - have heQ : e ∈ incidentSupport G hloc Λ := - (mem_incidentSupport G hloc Λ e).mpr ⟨a,hsub ih,by simp [hend]⟩ - exact ih.tail ⟨e,⟨he,heQ⟩,hend⟩ - -theorem cluster_restrict_incident_of_full (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (ω : Set E) (x : V) (hsub : cluster G ω x ⊆ Λ) : - cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x = cluster G ω x := by - apply cluster_restrict_incident_eq G hloc Λ ω x - exact (fun _ h => hsub (conn_mono G Set.inter_subset_left h)) - - -theorem capped_cluster_local (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (ω : Set E) : - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) ↔ - ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ - (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M) := by - dsimp only - let Λ := (finite_reachBall hloc x M).toFinset - let Q := incidentSupport G hloc Λ - constructor - · rintro ⟨hfin,hcap⟩ - have hsub : cluster G ω x ⊆ Λ := by - simpa only [Λ,Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hfin M hcap - rw [cluster_restrict_incident_of_full G hloc Λ ω x hsub] - exact ⟨hfin,hcap⟩ - · rintro ⟨hfin,hcap⟩ - have hsub : cluster G (ω ∩ (Q : Set E)) x ⊆ Λ := by - simpa only [Λ,Set.Finite.coe_toFinset] using - finite_cluster_subset_reachBall G (ω ∩ (Q : Set E)) x hfin M hcap - have heq := cluster_restrict_incident_eq G hloc Λ ω x hsub - rw [heq] at hfin hcap - exact ⟨hfin,hcap⟩ - -end ClusterLocality - -section InfiniteGoodness -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def pivotalDistance (G : BondGraph V E) (ω : Set E) (a b : V) : ℕ := - {e | OpenMarkedPivotal G ω {b} a e}.ncard - - -def contactSet (G : BondGraph V E) (ω : Set E) (W : Set V) : Set E := - {e | e ∈ ω ∧ CutExists G W e} - - -def GoodForScale (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) : Prop := - ∀ W : Finset V, (W : Set V) ⊆ cluster G ω x → - (∀ a ∈ W, ∀ b ∈ W, Conn G (ω ∩ internalEdges G (W : Set V)) a b) → - 0 < (contactSet G ω (W : Set V)).ncard → - ∀ a ∈ W, ∀ b ∈ W, - (pivotalDistance G (ω ∩ internalEdges G (W : Set V)) a b : ℝ) ≤ - (contactSet G ω (W : Set V)).ncard*L - - -def CappedBadGoodness (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : Prop := - (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ ¬GoodForScale G ω x L - -theorem pivotalDistance_finset (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) (a b : V) : - pivotalDistance G (ω : Set E) a b = (pairOpenPivotals G Q a b ω).card := by - have he : {e | OpenMarkedPivotal G (ω : Set E) {b} a e} = - (pairOpenPivotals G Q a b ω : Set E) := by - ext e - simp only [Finset.mem_coe,mem_pairOpenPivotals,Set.mem_ofPred_eq] - exact ⟨fun h => ⟨hω h.1,h⟩,And.right⟩ - simp only [pivotalDistance,he,Set.ncard_coe_finset] - -theorem contactSet_finset (G : BondGraph V E) (ω : Finset E) (W : Set V) : - contactSet G (ω : Set E) W = (openContacts G ω W : Set E) := by - ext e - simp only [contactSet,openContacts,Finset.mem_coe,Finset.mem_filter,Set.mem_ofPred_eq] - -theorem finiteGoodForScale_iff (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) - (x : V) (L : ℝ) : FiniteGoodForScale G Q x L ω ↔ GoodForScale G (ω : Set E) x L := by - have hroot : ∀ W : Finset V, W ⊆ finiteRootComponent G ω x ↔ (W : Set V) ⊆ cluster G ω x := by - intro W - rw [← coe_finiteRootComponent] - exact Finset.coe_subset.symm - have hpiv (W : Finset V) (a b : V) := pivotalDistance_finset G Q - (internalBonds G ω (W : Set V)) ((Finset.filter_subset _ _).trans hω) a b - simp only [FiniteGoodForScale,GoodForScale,hroot,← coe_internalBonds,contactSet_finset, - Set.ncard_coe_finset,hpiv] - -theorem cappedBadGoodness_finset_iff (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) - (x : V) (M : ℕ) (L : ℝ) : - CappedBadGoodness G (ω : Set E) x M L ↔ CappedBadGoodnessEvent G Q x M L ω := by - have hfin := cluster_finite_of_finite_edges G ω.finite_toSet x - simp only [CappedBadGoodness,CappedBadGoodnessEvent,hfin,true_and] - rw [← coe_finiteRootComponent,Set.ncard_coe_finset,finiteGoodForScale_iff G Q ω hω] - - -theorem internal_config_eq_of_incident (G : BondGraph V E) (ω η : Set E) (C W : Set V) - (hW : W ⊆ C) (he : ∀ e, (∃ v ∈ C, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : - ω ∩ internalEdges G W = η ∩ internalEdges G W := by - ext e - by_cases hi : e ∈ internalEdges G W - · have hinc : ∃ v ∈ C, v ∈ G e := - ⟨(G e).out.1,hW (hi _ (Sym2.out_fst_mem _)),Sym2.out_fst_mem _⟩ - simp only [Set.mem_inter_iff,hi,and_true,he e hinc] - · simp only [Set.mem_inter_iff,hi,and_false] - -theorem contacts_eq_of_incident (G : BondGraph V E) (ω η : Set E) (C W : Set V) - (hW : W ⊆ C) (he : ∀ e, (∃ v ∈ C, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : - contactSet G ω W = contactSet G η W := by - ext e - by_cases hi : CutExists G W e - · obtain ⟨a,b,hab,ha,_⟩ := hi - have hinc : ∃ v ∈ C, v ∈ G e := ⟨a,hW ha,by simp [hab]⟩ - simp only [contactSet,Set.mem_ofPred_eq,he e hinc] - · simp only [contactSet,Set.mem_ofPred_eq,hi,and_false] - - -theorem goodForScale_congr (G : BondGraph V E) (ω η : Set E) (x : V) (L : ℝ) - (hC : cluster G ω x = cluster G η x) - (he : ∀ e, (∃ v ∈ cluster G ω x, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : - GoodForScale G ω x L ↔ GoodForScale G η x L := by - unfold GoodForScale - apply forall_congr' - intro W - rw [← hC] - apply forall_congr' - intro hW - rw [internal_config_eq_of_incident G ω η _ _ hW he,contacts_eq_of_incident G ω η _ _ hW he] - -theorem goodForScale_restrict_incident (G : BondGraph V E) (hloc : LocallyFinite G) - (Λ : Finset V) (ω : Set E) (x : V) (L : ℝ) (hsub : cluster G ω x ⊆ Λ) : - GoodForScale G ω x L ↔ GoodForScale G (ω ∩ (incidentSupport G hloc Λ : Set E)) x L := by - apply goodForScale_congr G ω _ x L - (cluster_restrict_incident_of_full G hloc Λ ω x hsub).symm - intro e he - obtain ⟨v,hv,hve⟩ := he - have hQ := (mem_incidentSupport G hloc Λ e).mpr ⟨v,hsub hv,hve⟩ - simp only [Set.mem_inter_iff,Finset.mem_coe,hQ,and_true] - - -theorem cappedBadGoodness_local (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (L : ℝ) (ω : Set E) : - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - CappedBadGoodness G ω x M L ↔ CappedBadGoodness G (ω ∩ (Q : Set E)) x M L := by - let Λ := (finite_reachBall hloc x M).toFinset - let Q := incidentSupport G hloc Λ - change CappedBadGoodness G ω x M L ↔ CappedBadGoodness G (ω ∩ (Q : Set E)) x M L - have hcap := capped_cluster_local G hloc x M ω - change ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) ↔ - ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M) at hcap - have hg : ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) → - (GoodForScale G ω x L ↔ GoodForScale G (ω ∩ (Q : Set E)) x L) := by - rintro ⟨hfin,hM⟩ - apply goodForScale_restrict_incident G hloc Λ ω x L - simpa only [Λ,Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hfin M hM - constructor - · rintro ⟨hfin,hM,hbad⟩ - exact ⟨(hcap.mp ⟨hfin,hM⟩).1,(hcap.mp ⟨hfin,hM⟩).2,fun hh => hbad ((hg ⟨hfin,hM⟩).mpr hh)⟩ - · rintro ⟨hfin,hM,hbad⟩ - have hc := hcap.mpr ⟨hfin,hM⟩ - exact ⟨hc.1,hc.2,fun hh => hbad ((hg hc).mp hh)⟩ - -end InfiniteGoodness - -section GoodnessLaw -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurableSet_finite_restriction (Q : Finset E) (A : Set (Set E)) : - MeasurableSet {ω : Set E | ω ∩ (Q : Set E) ∈ A} := by - have hm : MeasurableSet {η : Set (Q : Set E) | (Subtype.val '' η : Set E) ∈ A} := .of_discrete - convert hm.preimage (measurable_set_restrict (Q : Set E)) using 1 - ext ω - have he : (Subtype.val '' (Subtype.val ⁻¹' ω : Set (Q : Set E)) : Set E) = ω ∩ (Q : Set E) := by - ext e - simp [and_comm] - simp only [Set.mem_preimage,Set.mem_ofPred_eq,he] - -theorem measurableSet_cappedBadGoodness (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (L : ℝ) : MeasurableSet {ω | CappedBadGoodness G ω x M L} := by - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - have he : {ω | CappedBadGoodness G ω x M L} = - {ω | ω ∩ (Q : Set E) ∈ {η | CappedBadGoodness G η x M L}} := by - ext ω - exact cappedBadGoodness_local G hloc x M L ω - rw [he] - exact measurableSet_finite_restriction Q _ - - -theorem bad_goodness_law_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (L : ℝ) (p : unitInterval) : - (law p).real {ω | CappedBadGoodness G ω x M L} = - finiteBadGoodnessProbability G - (incidentSupport G hloc (finite_reachBall hloc x M).toFinset) x M L p := by - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - have he : finiteBadGoodnessProbability G Q x M L p = - finiteEventPolynomial Q {ω | CappedBadGoodness G ω x M L} p := by - apply bernoulliPolynomial_congr - intro ω hω - simp only [Set.mem_ofPred_eq,cappedBadGoodness_finset_iff G Q ω hω] - change _ = finiteBadGoodnessProbability G Q x M L p - rw [he,finiteEventPolynomial_restrict] - congr 1 - ext ω - exact cappedBadGoodness_local G hloc x M L ω - -theorem incident_filter_card_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (x : V) : (Q.filter fun e => x ∈ G e).card ≤ degree G x := by - let : Fintype (Step G x) := (finite_steps G hloc x).fintype - have hex (e : {e // e ∈ Q.filter fun e => x ∈ G e}) : ∃ y, G e.val = s(x,y) := - Sym2.mem_iff_exists.mp (Finset.mem_filter.mp e.property).2 - let f : {e // e ∈ Q.filter fun e => x ∈ G e} → Step G x := - fun e => ⟨(e.val,(hex e).choose),(hex e).choose_spec⟩ - have hf : Function.Injective f := by - intro a b hab - exact Subtype.ext (congrArg (fun z : Step G x => z.val.1) hab) - simpa only [degree,Nat.card_eq_fintype_card,Fintype.card_coe] using Fintype.card_le_of_injective f hf - - - -theorem bad_goodness_stretched_exp [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (pbar : unitInterval) (hpbar : (pbar:ℝ) < 1) (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) : - ∀ᶠ M : ℕ in Filter.atTop, ∀ x : V, ∀ p : unitInterval, p ≤ pbar → - (law p).real {ω | CappedBadGoodness G ω x M ((M:ℝ)^(1/2+ε))} ≤ - Real.exp (-(M:ℝ)^ε) := by - obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt - filter_upwards [finite_bad_goodness_stretched_exp G d hd pbar hpbar ε hε hε1] with M hM - intro x p hp - rw [bad_goodness_law_eq_finite G hloc] - exact hM _ x (fun v => (incident_filter_card_le_degree G hloc _ v).trans (hdeg v)) p hp - -end GoodnessLaw - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.Moments + +namespace OAI + +/-! Pruning, finite and infinite goodness events and uniform bounds. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteCappedRadius +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def pairOpenPivotals (G : BondGraph V E) (Q : Finset E) (x y : V) + (ω : Finset E) : Finset E := + Q.filter fun e => e ∈ ω ∧ Conn G (ω : Set E) x y ∧ ¬Conn G (ω.erase e : Set E) x y + + +def CappedRadiusEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M r : ℕ) + (ω : Finset E) : Prop := + (finiteRootComponent G ω x).card ≤ M ∧ + ∃ y, Conn G (ω : Set E) x y ∧ r ≤ (pairOpenPivotals G Q x y ω).card + +noncomputable def finiteCappedRadiusTail (G : BondGraph V E) (Q : Finset E) + (x : V) (M r : ℕ) (p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => if CappedRadiusEvent G Q x M r ω then 1 else 0) p + + +theorem sole_root_mark (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) + (m : Finset V) (hxy : Conn G (ω : Set E) x y) + (hm : m ∩ finiteRootComponent G ω x = {y}) : + MarkedEvent G ω m x ∧ markedOpenPivotals G Q x ω m = pairOpenPivotals G Q x y ω := by + have hyW : y ∈ finiteRootComponent G ω x := by + change y ∈ (finiteRootComponent G ω x : Set V) + rwa [coe_finiteRootComponent] + have hym : y ∈ m := (Finset.mem_inter.mp (hm ▸ Finset.mem_singleton_self y)).1 + have hmconn (η : Finset E) (hη : η ⊆ ω) : + MarkedEvent G η m x ↔ Conn G (η : Set E) x y := by + constructor + · rintro ⟨z,hzm,hxz⟩ + have hzW : z ∈ finiteRootComponent G ω x := by + change z ∈ (finiteRootComponent G ω x : Set V) + rw [coe_finiteRootComponent] + exact conn_mono G (by exact_mod_cast hη) hxz + have hzy : z = y := Finset.mem_singleton.mp (hm ▸ Finset.mem_inter.mpr ⟨hzm,hzW⟩) + rwa [hzy] at hxz + · exact fun h => ⟨y,hym,h⟩ + refine ⟨⟨y,hym,hxy⟩,?_⟩ + ext e + simp only [markedOpenPivotals,pairOpenPivotals,Finset.mem_filter] + change (e ∈ Q ∧ e ∈ ω ∧ MarkedEvent G ω m x ∧ ¬MarkedEvent G (ω.erase e) m x) ↔ _ + rw [hmconn ω Finset.Subset.rfl,hmconn (ω.erase e) (Finset.erase_subset e ω)] + + +theorem bernoulliPolynomial_exact_indicator (F S : Finset V) (hSF : S ⊆ F) (h : ℝ) : + bernoulliPolynomial F (fun m => if m = S then (1:ℝ) else 0) h = + h^S.card*(1-h)^(F.card-S.card) := by + unfold bernoulliPolynomial + rw [Finset.sum_eq_single_of_mem S (Finset.mem_powerset.mpr hSF)] + · simp + · intro m hm hne + simp [hne] + + +theorem bernoulliPolynomial_sole_root_mark (G : BondGraph V E) (Q : Finset E) + (F : Finset V) (x y : V) (ω : Finset E) (hω : ω ⊆ Q) + (hF : insert x (searchVertices G Q) ⊆ F) (hxy : Conn G (ω : Set E) x y) (h : ℝ) : + bernoulliPolynomial F (fun m => if m ∩ finiteRootComponent G ω x = {y} then (1:ℝ) else 0) h = + h*(1-h)^((finiteRootComponent G ω x).card-1) := by + rw [bernoulliPolynomial_restrict _ _ (finiteRootComponent_subset G Q F x ω hω hF) + (fun a => if a = {y} then (1:ℝ) else 0) h] + have hy : y ∈ finiteRootComponent G ω x := by + change y ∈ (finiteRootComponent G ω x : Set V) + rwa [coe_finiteRootComponent] + rw [bernoulliPolynomial_exact_indicator _ {y} (Finset.singleton_subset_iff.mpr hy)] + simp + + +theorem cappedRadius_mark_comparison (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (M r : ℕ) (p h : unitInterval) + (hF : insert x (searchVertices G Q) ⊆ F) : + (h:ℝ)*(1-h)^M*finiteCappedRadiusTail G Q x M r p ≤ finiteMarkedTail G Q F x r h p := by + unfold finiteCappedRadiusTail finiteMarkedTail + rw [← bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_mono _ _ _ _ p.2 + intro ω hω + by_cases he : CappedRadiusEvent G Q x M r ω + · obtain ⟨hcap,y,hxy,hr⟩ := he + have he : CappedRadiusEvent G Q x M r ω := ⟨hcap,y,hxy,hr⟩ + simp only [he,ite_true,mul_one] + calc + (h:ℝ)*(1-h)^M ≤ (h:ℝ)*(1-h)^((finiteRootComponent G ω x).card-1) := by + apply mul_le_mul_of_nonneg_left _ h.2.1 + exact pow_le_pow_of_le_one (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) + (Nat.le_trans (Nat.sub_le _ _) hcap) + _ = bernoulliPolynomial F + (fun m => if m ∩ finiteRootComponent G ω x = {y} then (1:ℝ) else 0) h := + (bernoulliPolynomial_sole_root_mark G Q F x y ω hω hF hxy h).symm + _ ≤ _ := by + apply bernoulliPolynomial_mono _ _ _ _ h.2 + intro m hm + by_cases hs : m ∩ finiteRootComponent G ω x = {y} + · obtain ⟨heq,hpiv⟩ := sole_root_mark G Q x y ω m hxy hs + have hlarge : r ≤ (markedOpenPivotals G Q x ω m).card := hpiv ▸ hr + simp only [hs,heq,hlarge,and_self,ite_true,le_refl] + · simp only [hs,ite_false] + split_ifs <;> norm_num + · simp only [he,ite_false,mul_zero] + apply bernoulliPolynomial_nonneg _ _ _ h.2 + intro m hm + split_ifs <;> norm_num + +theorem finiteMarkedMoment_zero_le_one (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (p h : unitInterval) : finiteMarkedMoment G Q F x 0 h p ≤ 1 := by + unfold finiteMarkedMoment + rw [← bernoulliPolynomial_const Q (1:ℝ) (p:ℝ)] + apply bernoulliPolynomial_mono _ _ _ _ p.2 + intro ω hω + rw [← bernoulliPolynomial_const F (1:ℝ) (h:ℝ)] + apply bernoulliPolynomial_mono _ _ _ _ h.2 + intro m hm + rw [markedMomentValue_zero] + split_ifs <;> norm_num + + +theorem finiteCappedRadiusTail_exponential [Nonempty V] (G : BondGraph V E) + (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) + (d : ℕ) (hd : 0 < d) (Q : Finset E) (x : V) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (B : ℝ) (hB : 1 ≤ B) + (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) (M r : ℕ) : + finiteCappedRadiusTail G Q x M r p ≤ + (2/((h:ℝ)*(1-h)^M))*Real.exp (-(r:ℝ)/(4*B)) := by + let F := insert x (searchVertices G Q) + have hcomp := cappedRadius_mark_comparison G Q F x M r p h Finset.Subset.rfl + have ht := finiteMarkedTail_exponential G p h hp hh d hd Q F x hdeg Finset.Subset.rfl B hB hAB r + have hm := finiteMarkedMoment_zero_le_one G Q F x p h + have hb : 0 < (h:ℝ)*(1-h)^M := mul_pos hh (pow_pos (sub_pos.mpr hh1) _) + have hbound : (h:ℝ)*(1-h)^M*finiteCappedRadiusTail G Q x M r p ≤ + 2*Real.exp (-(r:ℝ)/(4*B)) := by + have hpos : 0 ≤ 2*Real.exp (-(r:ℝ)/(4*B)) := by positivity + have hl := mul_le_mul_of_nonneg_left hm hpos + rw [mul_one] at hl + exact hcomp.trans (ht.trans hl) + calc + _ ≤ (2*Real.exp (-(r:ℝ)/(4*B)))/((h:ℝ)*(1-h)^M) := + (le_div_iff₀ hb).mpr (by simpa only [mul_comm] using hbound) + _ = _ := by ring + +end FiniteCappedRadius + +section PruningGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem pairOpenPivotals_symm (G : BondGraph V E) (Q : Finset E) (ω : Finset E) (x y : V) : + pairOpenPivotals G Q x y ω = pairOpenPivotals G Q y x ω := by + ext e + simp only [pairOpenPivotals,Finset.mem_filter] + have h₁ : Conn G (ω : Set E) x y ↔ Conn G (ω : Set E) y x := + ⟨conn_symm G _,conn_symm G _⟩ + have h₂ : Conn G (ω.erase e : Set E) x y ↔ Conn G (ω.erase e : Set E) y x := + ⟨conn_symm G _,conn_symm G _⟩ + rw [h₁,h₂] + + +theorem pairOpenPivotals_triangle_subset (G : BondGraph V E) (Q : Finset E) (ω : Finset E) + (x y z : V) (hxy : Conn G (ω : Set E) x y) (hyz : Conn G (ω : Set E) y z) : + pairOpenPivotals G Q x z ω ⊆ pairOpenPivotals G Q x y ω ∪ pairOpenPivotals G Q y z ω := by + intro e he + obtain ⟨heQ,heω,_,hnxz⟩ := Finset.mem_filter.mp he + by_cases hxy' : Conn G (ω.erase e : Set E) x y + · exact Finset.mem_union_right _ (Finset.mem_filter.mpr + ⟨heQ,heω,hyz,fun hyz' => hnxz (hxy'.trans hyz')⟩) + · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨heQ,heω,hxy,hxy'⟩) + +theorem pairOpenPivotals_triangle (G : BondGraph V E) (Q : Finset E) (ω : Finset E) + (x y z : V) (hxy : Conn G (ω : Set E) x y) (hyz : Conn G (ω : Set E) y z) : + (pairOpenPivotals G Q x z ω).card ≤ + (pairOpenPivotals G Q x y ω).card+(pairOpenPivotals G Q y z ω).card := + (Finset.card_le_card (pairOpenPivotals_triangle_subset G Q ω x y z hxy hyz)).trans + (Finset.card_union_le _ _) + + +theorem conn_no_crossing_internal (G : BondGraph V E) (W : Set V) (ω : Set E) + (hc : ∀ e ∈ ω, ¬CutExists G W e) {x y : V} (hx : x ∈ W) (hxy : Conn G ω x y) : + Conn G (ω ∩ internalEdges G W) x y ∧ y ∈ W := by + induction hxy with + | refl => exact ⟨conn_refl _ _ _,hx⟩ + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + have hb : b ∈ W := by + by_contra hn + exact hc e he ⟨a,b,heq,ih.2,hn⟩ + exact ⟨ih.1.tail ⟨e,⟨he,(mem_internalEdges_of_ends G W e a b heq).mpr ⟨ih.2,hb⟩⟩,heq⟩,hb⟩ + + +theorem conn_one_attachment_internal (G : BondGraph V E) (W : Set V) (ω : Set E) + (e : E) (he : e ∈ ω) (hec : CutExists G W e) + (hone : ∀ f ∈ ω, CutExists G W f → f = e) + {x y : V} (hx : x ∈ W) (hy : y ∈ W) (hxy : Conn G ω x y) : + Conn G (ω ∩ internalEdges G W) x y := by + obtain ⟨a,b,hab,ha,hb⟩ := hec + let η := ω \ {e} + have hn : ∀ f ∈ η, ¬CutExists G W f := by + intro f hf hc + exact hf.2 (Set.mem_singleton_iff.mpr (hone f hf.1 hc)) + have hη (u v : V) (hu : u ∈ W) (huv : Conn G η u v) := + conn_no_crossing_internal G W η hn hu huv + have hω : insert e η = ω := by dsimp [η]; ext f; simp [he] + have hw : Conn G (insert e η) x y := hω ▸ hxy + rcases (conn_insert_iff G η e a b x y hab).mp hw with h | ⟨_,h⟩ | ⟨h,_⟩ + · exact conn_mono G (show η ∩ internalEdges G W ⊆ ω ∩ internalEdges G W from + fun _ hf => ⟨hf.1.1,hf.2⟩) (hη x y hx h).1 + · exact (hb (hη y b hy (conn_symm G η h)).2).elim + · exact (hb (hη x b hx h).2).elim + +noncomputable def internalBonds (G : BondGraph V E) (ω : Finset E) (W : Set V) : Finset E := + ω.filter fun e => e ∈ internalEdges G W + +@[simp] theorem coe_internalBonds (G : BondGraph V E) (ω : Finset E) (W : Set V) : + (internalBonds G ω W : Set E) = (ω : Set E) ∩ internalEdges G W := by + ext e; simp [internalBonds] + + +theorem pairOpenPivotals_one_attachment (G : BondGraph V E) (Q ω : Finset E) (W : Set V) + (e : E) (he : e ∈ ω) (hec : CutExists G W e) + (hone : ∀ f ∈ ω, CutExists G W f → f = e) + {x y : V} (hx : x ∈ W) (hy : y ∈ W) : + pairOpenPivotals G Q x y (internalBonds G ω W) ⊆ pairOpenPivotals G Q x y ω := by + intro f hf + obtain ⟨hfQ,hfω,hxy,hnxy⟩ := Finset.mem_filter.mp hf + have hfint : f ∈ internalEdges G W := (Finset.mem_filter.mp hfω).2 + have hfe : e ≠ f := by + intro hef + obtain ⟨a,b,hab,ha,hb⟩ := hec + have hh : e ∈ internalEdges G W := hef ▸ hfint + exact hb ((mem_internalEdges_of_ends G W e a b hab).mp hh).2 + have he' : e ∈ ω.erase f := Finset.mem_erase.mpr ⟨hfe,he⟩ + have hcoe : (internalBonds G ω W).erase f = internalBonds G (ω.erase f) W := by + ext g; simp [internalBonds]; tauto + refine Finset.mem_filter.mpr ⟨hfQ,(Finset.mem_filter.mp hfω).1,?_,?_⟩ + · exact conn_mono G (by simpa only [coe_internalBonds] using Set.inter_subset_left) hxy + · intro h + have hh := conn_one_attachment_internal G W (ω.erase f : Set E) e he' hec + (fun g hg hc => hone g (Finset.mem_of_mem_erase hg) hc) hx hy h + apply hnxy + simpa only [hcoe,coe_internalBonds] using hh + + +theorem conn_first_entry (G : BondGraph V E) (W : Set V) (ω : Set E) + {x y : V} (hx : x ∉ W) (hy : y ∈ W) (hxy : Conn G ω x y) : + ∃ a b e, a ∉ W ∧ b ∈ W ∧ e ∈ ω ∧ G e = s(a,b) ∧ + Conn G (ω ∩ internalEdges G Wᶜ) x a := by + let Entry : Prop := ∃ a b e, a ∉ W ∧ b ∈ W ∧ e ∈ ω ∧ G e = s(a,b) ∧ + Conn G (ω ∩ internalEdges G Wᶜ) x a + have haux : Conn G (ω ∩ internalEdges G Wᶜ) x y ∨ Entry := by + clear hy + induction hxy with + | refl => exact Or.inl (conn_refl _ _ _) + | @tail a b hxa hab ih => + rcases ih with ih | ih + · have ha : a ∉ W := conn_internal_endpoint G Wᶜ hx ih + obtain ⟨e,he,heq⟩ := hab + by_cases hb : b ∈ W + · exact Or.inr ⟨a,b,e,ha,hb,he,heq,ih⟩ + · exact Or.inl (ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G Wᶜ e a b heq).mpr ⟨ha,hb⟩⟩,heq⟩) + · exact Or.inr ih + rcases haux with h | h + · exact ((conn_internal_endpoint G Wᶜ hx h) hy).elim + · exact h + + +noncomputable def pruneContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : Finset E := + ω.filter fun f => ¬CutExists G W f ∨ f = e + +theorem internal_not_cut (G : BondGraph V E) (W : Set V) {e : E} + (he : e ∈ internalEdges G W) : ¬CutExists G W e := by + rintro ⟨a,b,hab,ha,hb⟩ + exact hb ((mem_internalEdges_of_ends G W e a b hab).mp he).2 + +theorem exterior_not_cut (G : BondGraph V E) (W : Set V) {e : E} + (he : e ∈ internalEdges G Wᶜ) : ¬CutExists G W e := by + rintro ⟨a,b,hab,ha,hb⟩ + exact ((mem_internalEdges_of_ends G Wᶜ e a b hab).mp he).1 ha + +theorem internal_pruneContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : + internalBonds G (pruneContacts G ω W e) W = internalBonds G ω W := by + ext f + simp only [internalBonds,pruneContacts,Finset.mem_filter] + constructor + · exact fun h => ⟨h.1.1,h.2⟩ + · exact fun h => ⟨⟨h.1,Or.inl (internal_not_cut G W h.2)⟩,h.2⟩ + +theorem pruneContacts_only_attachment (G : BondGraph V E) (ω : Finset E) (W : Set V) (e : E) : + ∀ f ∈ pruneContacts G ω W e, CutExists G W f → f = e := by + intro f hf hc + exact (Finset.mem_filter.mp hf).2.resolve_left (not_not.mpr hc) + + +theorem exists_pruneContacts_root (G : BondGraph V E) (ω : Finset E) (W : Set V) (x : V) + (hWroot : W ⊆ cluster G ω x) (hWconn : ∀ a ∈ W, ∀ b ∈ W, + Conn G (ω ∩ internalEdges G W) a b) + (hcontact : ∃ e ∈ ω, CutExists G W e) : + ∃ e ∈ ω, CutExists G W e ∧ W ⊆ cluster G (pruneContacts G ω W e) x := by + by_cases hx : x ∈ W + · obtain ⟨e,he,hec⟩ := hcontact + refine ⟨e,he,hec,?_⟩ + intro y hy + apply conn_mono G _ (hWconn x hx y hy) + intro f hf + exact Finset.mem_filter.mpr ⟨hf.1,Or.inl (internal_not_cut G W hf.2)⟩ + · obtain ⟨e₀,he₀,a,b,hab,ha,hb⟩ := hcontact + obtain ⟨c,z,e,hc,hz,he,hez,hxc⟩ := conn_first_entry G W ω hx ha (hWroot ha) + have hec : CutExists G W e := ⟨z,c,by simpa only [Sym2.eq_swap] using hez,hz,hc⟩ + have hep : e ∈ pruneContacts G ω W e := Finset.mem_filter.mpr ⟨he,Or.inr rfl⟩ + have hxz : Conn G (pruneContacts G ω W e : Set E) x z := + (conn_mono G (fun f hf => Finset.mem_filter.mpr ⟨hf.1,Or.inl (exterior_not_cut G W hf.2)⟩) hxc).tail + ⟨e,hep,hez⟩ + refine ⟨e,he,hec,?_⟩ + intro y hy + exact hxz.trans (conn_mono G (fun f hf => + Finset.mem_filter.mpr ⟨hf.1,Or.inl (internal_not_cut G W hf.2)⟩) (hWconn z hz y hy)) + +end PruningGeometry + +section GoodnessGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +@[simp] theorem mem_pairOpenPivotals (G : BondGraph V E) (Q : Finset E) (x y : V) + (ω : Finset E) (e : E) : e ∈ pairOpenPivotals G Q x y ω ↔ + e ∈ Q ∧ OpenMarkedPivotal G (ω : Set E) {y} x e := by + simp only [pairOpenPivotals,Finset.mem_filter,OpenMarkedPivotal,MarkedEvent, + Set.mem_singleton_iff,exists_eq_left,Finset.coe_erase,Finset.mem_coe] + + +theorem pairOpenPivotals_card_le (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) : + (pairOpenPivotals G Q x y ω).card ≤ (finiteRootComponent G ω x).card-1 := by + let N := (finiteRootComponent G ω x).card + have hN : (cluster G (ω : Set E) x).ncard = N := by + rw [← coe_finiteRootComponent,Set.ncard_coe_finset] + have hm : Set.MapsTo (pivotalRank G ω x) (pairOpenPivotals G Q x y ω : Set E) + (Finset.Ico 1 N : Set ℕ) := by + intro e he + have he' := ((mem_pairOpenPivotals G Q x y ω e).mp he).2 + have hfin := cluster_finite_of_finite_edges G (ω := (ω : Set E) \ {e}) (ω.finite_toSet.subset Set.sdiff_subset) x + have hpos : 0 < pivotalRank G ω x e := + (Set.ncard_pos hfin).mpr ⟨x,conn_refl G _ x⟩ + have hlt : pivotalRank G ω x e < N := by + rw [pivotalRank,← hN] + apply Set.ncard_lt_ncard _ (cluster_finite_of_finite_edges G ω.finite_toSet x) + refine Set.ssubset_iff_subset_ne.mpr ⟨fun z hz => conn_mono G Set.sdiff_subset hz,?_⟩ + intro heq + obtain ⟨z,hz,hxz⟩ := he'.2.1 + have hz' : z ∈ cluster G (ω : Set E) x := hxz + have hz'' : z ∈ cluster G ((ω : Set E) \ {e}) x := heq.symm ▸ hz' + exact he'.2.2 ⟨z,hz,hz''⟩ + exact Finset.mem_Ico.mpr ⟨hpos,hlt⟩ + have hi : Set.InjOn (pivotalRank G ω x) (pairOpenPivotals G Q x y ω : Set E) := by + intro e he f hf h + exact pivotalRank_injective G ω.finite_toSet {y} x + ((mem_pairOpenPivotals G Q x y ω e).mp he).2 + ((mem_pairOpenPivotals G Q x y ω f).mp hf).2 h + simpa [N] using Finset.card_le_card_of_injOn (pivotalRank G ω x) hm hi + +theorem finiteRootComponent_mono (G : BondGraph V E) {ω η : Finset E} (h : ω ⊆ η) (x : V) : + finiteRootComponent G ω x ⊆ finiteRootComponent G η x := by + intro y hy + change y ∈ (finiteRootComponent G η x : Set V) + rw [coe_finiteRootComponent] + apply conn_mono G (show (ω : Set E) ⊆ η from h) + change y ∈ (finiteRootComponent G ω x : Set V) at hy + rwa [coe_finiteRootComponent] at hy + + +noncomputable def openContacts (G : BondGraph V E) (ω : Finset E) (W : Set V) : Finset E := + ω.filter fun e => CutExists G W e + + +def BadPieceEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M K : ℕ) (L : ℝ) + (ω : Finset E) : Prop := + (finiteRootComponent G ω x).card ≤ M ∧ ∃ W : Finset V, + W ⊆ finiteRootComponent G ω x ∧ + (∀ a ∈ W, ∀ b ∈ W, Conn G (internalBonds G ω (W : Set V) : Set E) a b) ∧ + (openContacts G ω (W : Set V)).card = K ∧ + ∃ a ∈ W, ∃ b ∈ W, (K:ℝ)*L < (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card + + +theorem badPieceEvent_contact_bound (G : BondGraph V E) (Q : Finset E) (x : V) + (M K : ℕ) (L : ℝ) (ω : Finset E) (h : BadPieceEvent G Q x M K L ω) : + (K:ℝ)*L < (M:ℝ) := by + obtain ⟨hcap,W,hW,_,_,a,ha,b,_,hbad⟩ := h + have hsub : finiteRootComponent G (internalBonds G ω (W : Set V)) a ⊆ W := by + intro z hz + apply conn_internal_endpoint G (W : Set V) (ω := (ω : Set E)) ha + change z ∈ (finiteRootComponent G (internalBonds G ω (W : Set V)) a : Set V) at hz + rw [coe_finiteRootComponent] at hz + simpa only [coe_internalBonds,cluster,Set.mem_ofPred_eq] using hz + have hab := pairOpenPivotals_card_le G Q a b (internalBonds G ω (W : Set V)) + have hpos : 0 < (finiteRootComponent G (internalBonds G ω (W : Set V)) a).card := by + apply Finset.card_pos.mpr + refine ⟨a,?_⟩ + change a ∈ (finiteRootComponent G (internalBonds G ω (W : Set V)) a : Set V) + rw [coe_finiteRootComponent] + exact conn_refl G _ a + have hn : (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card < M := by + have h₁ := Finset.card_le_card hsub + have h₂ := Finset.card_le_card hW + omega + exact hbad.trans (by exact_mod_cast hn) + + +noncomputable def incidentBonds (G : BondGraph V E) (Q : Finset E) (W : Finset V) : Finset E := + W.biUnion fun v => Q.filter fun e => v ∈ G e + +@[simp] theorem mem_incidentBonds (G : BondGraph V E) (Q : Finset E) (W : Finset V) (e : E) : + e ∈ incidentBonds G Q W ↔ e ∈ Q ∧ ∃ v ∈ W, v ∈ G e := by + simp only [incidentBonds,Finset.mem_biUnion,Finset.mem_filter] + aesop + +theorem incidentBonds_card_le (G : BondGraph V E) (Q : Finset E) (W : Finset V) (d : ℕ) + (hd : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : + (incidentBonds G Q W).card ≤ d*W.card := by + calc + _ ≤ ∑ v ∈ W, (Q.filter fun e => v ∈ G e).card := Finset.card_biUnion_le + _ ≤ ∑ _v ∈ W, d := Finset.sum_le_sum fun _ _ => hd _ + _ = _ := by simp [Nat.mul_comm] + + + +theorem badPieceEvent_pruning (G : BondGraph V E) (Q : Finset E) (x : V) (M K r : ℕ) + (L : ℝ) (hK : 0 < K) (hr : 2*(r:ℝ) ≤ (K:ℝ)*L) + (ω : Finset E) (hω : ω ⊆ Q) (h : BadPieceEvent G Q x M K L ω) : + ∃ η : Finset E, η ⊆ ω ∧ CappedRadiusEvent G Q x M r η ∧ + (ω \ η).card ≤ K ∧ ω \ η ⊆ incidentBonds G Q (finiteRootComponent G η x) := by + obtain ⟨hcap,W,hW,hWconn,hcontacts,a,ha,b,hb,hbad⟩ := h + have hcontact : ∃ e ∈ ω, CutExists G (W : Set V) e := by + have : (openContacts G ω (W : Set V)).Nonempty := Finset.card_pos.mp (hcontacts ▸ hK) + obtain ⟨e,he⟩ := this + exact ⟨e,(Finset.mem_filter.mp he).1,(Finset.mem_filter.mp he).2⟩ + have hWroot : (W : Set V) ⊆ cluster G ω x := by + intro z hz + have hh : z ∈ (finiteRootComponent G ω x : Set V) := hW hz + rwa [coe_finiteRootComponent] at hh + obtain ⟨e,he,hec,hWη⟩ := exists_pruneContacts_root G ω (W : Set V) x hWroot + (by intro a ha b hb; simpa only [coe_internalBonds] using hWconn a ha b hb) hcontact + let η := pruneContacts G ω (W : Set V) e + have hη : η ⊆ ω := Finset.filter_subset _ _ + have hep : e ∈ η := Finset.mem_filter.mpr ⟨he,Or.inr rfl⟩ + have hpiv := pairOpenPivotals_one_attachment G Q η (W : Set V) e hep hec + (pruneContacts_only_attachment G ω (W : Set V) e) ha hb + rw [internal_pruneContacts] at hpiv + have hfar : (K:ℝ)*L < (pairOpenPivotals G Q a b η).card := + hbad.trans_le (by exact_mod_cast Finset.card_le_card hpiv) + have hxa : Conn G (η : Set E) x a := hWη ha + have hxb : Conn G (η : Set E) x b := hWη hb + have htri := pairOpenPivotals_triangle G Q η a x b (conn_symm G η hxa) hxb + rw [pairOpenPivotals_symm G Q η a x] at htri + have hlarge : r ≤ (pairOpenPivotals G Q x a η).card ∨ + r ≤ (pairOpenPivotals G Q x b η).card := by + by_contra hn + push Not at hn + have htri' : ((pairOpenPivotals G Q a b η).card:ℝ) ≤ + (pairOpenPivotals G Q x a η).card+(pairOpenPivotals G Q x b η).card := by exact_mod_cast htri + have h₁ : ((pairOpenPivotals G Q x a η).card:ℝ) < r := by exact_mod_cast hn.1 + have h₂ : ((pairOpenPivotals G Q x b η).card:ℝ) < r := by exact_mod_cast hn.2 + linarith + have hchanges : ω \ η ⊆ openContacts G ω (W : Set V) := by + intro f hf + obtain ⟨hfω,hfη⟩ := Finset.mem_sdiff.mp hf + refine Finset.mem_filter.mpr ⟨hfω,?_⟩ + by_contra hn + exact hfη (Finset.mem_filter.mpr ⟨hfω,Or.inl hn⟩) + refine ⟨η,hη,⟨(Finset.card_le_card (finiteRootComponent_mono G hη x)).trans hcap,?_⟩, + (Finset.card_le_card hchanges).trans (le_of_eq hcontacts),?_⟩ + · rcases hlarge with h | h + · exact ⟨a,hxa,h⟩ + · exact ⟨b,hxb,h⟩ + · intro f hf + obtain ⟨hfω,c,z,hcz,hc,_⟩ := Finset.mem_filter.mp (hchanges hf) + refine (mem_incidentBonds G Q _ f).mpr ⟨hω hfω,c,?_,?_⟩ + · change c ∈ (finiteRootComponent G η x : Set V) + rw [coe_finiteRootComponent] + exact hWη hc + · simp [hcz] + +end GoodnessGeometry + +section FiniteInverseCost +attribute [local instance] Classical.propDecidable Classical.decEq + + +def bernoulliWeight (Q ω : Finset E) (p : ℝ) : ℝ := + p^ω.card*(1-p)^(Q.card-ω.card) + +theorem bernoulliWeight_nonneg (Q ω : Finset E) (p : unitInterval) : + 0 ≤ bernoulliWeight Q ω p := mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) + + +theorem bernoulliWeight_closure_ratio (Q ω η : Finset E) (hη : η ⊆ ω) (hω : ω ⊆ Q) + (p : ℝ) (hp : p < 1) : + bernoulliWeight Q ω p = bernoulliWeight Q η p*(p/(1-p))^((ω \ η).card) := by + have h₁ := Finset.card_le_card hη + have h₂ := Finset.card_le_card hω + have hj : (ω \ η).card = ω.card-η.card := Finset.card_sdiff_of_subset hη + have ha : ω.card = η.card+(ω \ η).card := by omega + have hb : Q.card-η.card = (Q.card-ω.card)+(ω \ η).card := by omega + have hq : (1-p) ≠ 0 := ne_of_gt (sub_pos.mpr hp) + unfold bernoulliWeight + rw [hb,pow_add,div_pow] + rw [← mul_div_assoc] + apply (eq_div_iff (pow_ne_zero _ hq)).mpr + rw [ha,pow_add] + ring + + +theorem bernoulliWeight_closure_le (Q ω η : Finset E) (hη : η ⊆ ω) (hω : ω ⊆ Q) + (p : unitInterval) (hp : (p:ℝ) < 1) (K : ℕ) (hj : (ω \ η).card ≤ K) : + bernoulliWeight Q ω p ≤ (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := by + rw [bernoulliWeight_closure_ratio Q ω η hη hω p hp,mul_comm] + apply mul_le_mul_of_nonneg_right _ (bernoulliWeight_nonneg Q η p) + calc + _ ≤ (max 1 ((p:ℝ)/(1-p)))^((ω \ η).card) := + pow_le_pow_left₀ (div_nonneg p.2.1 (sub_nonneg.mpr p.2.2)) (le_max_right ..) _ + _ ≤ _ := pow_le_pow_right₀ (le_max_left ..) hj + + +theorem card_small_subsets_le (S : Finset E) (K N : ℕ) (hS : S.card ≤ N) (hN : 1 ≤ N) : + (S.powerset.filter fun T => T.card ≤ K).card ≤ (K+1)*N^K := by + have hsub : S.powerset.filter (fun T => T.card ≤ K) ⊆ + (Finset.range (K+1)).biUnion (fun j => S.powersetCard j) := by + intro T hT + obtain ⟨hTS,hTK⟩ := Finset.mem_filter.mp hT + exact Finset.mem_biUnion.mpr ⟨T.card,Finset.mem_range.mpr (Nat.lt_succ_of_le hTK), + Finset.mem_powersetCard.mpr ⟨Finset.mem_powerset.mp hTS,rfl⟩⟩ + calc + _ ≤ _ := Finset.card_le_card hsub + _ ≤ ∑ j ∈ Finset.range (K+1), (S.powersetCard j).card := Finset.card_biUnion_le + _ ≤ ∑ _j ∈ Finset.range (K+1), N^K := by + apply Finset.sum_le_sum + intro j hj + rw [Finset.card_powersetCard] + exact (Nat.choose_le_pow _ _).trans ((Nat.pow_le_pow_left hS _).trans + (Nat.pow_le_pow_right hN (Nat.le_of_lt_succ (Finset.mem_range.mp hj)))) + _ = _ := by simp + + +theorem closure_fiber_card_le (A : Finset (Finset E)) (f : Finset E → Finset E) + (S : Finset E) (η : Finset E) (K N : ℕ) (hN : 1 ≤ N) (hS : S.card ≤ N) + (hf : ∀ ω ∈ A, f ω = η → f ω ⊆ ω ∧ (ω \ f ω).card ≤ K ∧ ω \ f ω ⊆ S) : + (A.filter fun ω => f ω = η).card ≤ (K+1)*N^K := by + have hm : Set.MapsTo (fun ω : Finset E => ω \ η) (A.filter fun ω => f ω = η : Set (Finset E)) + (S.powerset.filter fun T => T.card ≤ K : Set (Finset E)) := by + intro ω hω + obtain ⟨hωA,heq⟩ := Finset.mem_filter.mp hω + obtain ⟨_,hj,hs⟩ := hf ω hωA heq + rw [heq] at hj hs + exact Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr hs,hj⟩ + have hi : Set.InjOn (fun ω : Finset E => ω \ η) (A.filter fun ω => f ω = η : Set (Finset E)) := by + intro ω hω ζ hζ heq + obtain ⟨hωA,hωη⟩ := Finset.mem_filter.mp hω + obtain ⟨hζA,hζη⟩ := Finset.mem_filter.mp hζ + have h₁ := (hf ω hωA hωη).1 + have h₂ := (hf ζ hζA hζη).1 + rw [hωη] at h₁ + rw [hζη] at h₂ + have : η ∪ (ω \ η) = η ∪ (ζ \ η) := congrArg (fun s => η ∪ s) heq + simpa only [Finset.union_sdiff_of_subset h₁,Finset.union_sdiff_of_subset h₂] using this + exact (Finset.card_le_card_of_injOn (fun ω => ω \ η) hm hi).trans (card_small_subsets_le S K N hS hN) + + +theorem finite_closure_comparison (Q : Finset E) (A B : Finset (Finset E)) + (hA : A ⊆ Q.powerset) (f : Finset E → Finset E) (S : Finset E → Finset E) + (K N : ℕ) (hN : 1 ≤ N) (p : unitInterval) (hp : (p:ℝ) < 1) + (hf : ∀ ω ∈ A, f ω ∈ B ∧ f ω ⊆ ω ∧ (ω \ f ω).card ≤ K ∧ ω \ f ω ⊆ S (f ω)) + (hS : ∀ η ∈ B, (S η).card ≤ N) : + (∑ ω ∈ A, bernoulliWeight Q ω p) ≤ + (((K+1)*N^K : ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K*∑ η ∈ B, bernoulliWeight Q η p := by + rw [← Finset.sum_fiberwise_of_maps_to (fun ω hω => (hf ω hω).1) (fun ω => bernoulliWeight Q ω p), + Finset.mul_sum] + apply Finset.sum_le_sum + intro η hη + let T := A.filter fun ω => f ω = η + have hc : T.card ≤ (K+1)*N^K := closure_fiber_card_le A f (S η) η K N hN (hS η hη) (by + intro ω hω heq + have hh := (hf ω hω).2 + simpa only [heq] using hh) + have hweight : ∀ ω ∈ T, bernoulliWeight Q ω p ≤ + (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := by + intro ω hω + obtain ⟨hωA,heq⟩ := Finset.mem_filter.mp hω + have hh := bernoulliWeight_closure_le Q ω (f ω) (hf ω hωA).2.1 + (Finset.mem_powerset.mp (hA hωA)) p hp K (hf ω hωA).2.2.1 + simpa only [heq] using hh + calc + _ ≤ ∑ _ω ∈ T, (max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p := Finset.sum_le_sum hweight + _ = (T.card:ℝ)*((max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p) := by simp + _ ≤ (((K+1)*N^K:ℕ):ℝ)*((max 1 ((p:ℝ)/(1-p)))^K*bernoulliWeight Q η p) := + mul_le_mul_of_nonneg_right (by exact_mod_cast hc) + (mul_nonneg (pow_nonneg (le_trans zero_le_one (le_max_left ..)) _) (bernoulliWeight_nonneg Q η p)) + _ = _ := by ring + +end FiniteInverseCost + +section FiniteGoodnessProbability +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteBadPieceProbability (G : BondGraph V E) (Q : Finset E) + (x : V) (M K : ℕ) (L p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => if BadPieceEvent G Q x M K L ω then 1 else 0) p + +theorem bernoulliPolynomial_indicator_weight (Q : Finset E) (P : Finset E → Prop) (p : ℝ) : + bernoulliPolynomial Q (fun ω => if P ω then 1 else 0) p = + ∑ ω ∈ Q.powerset.filter P, bernoulliWeight Q ω p := by + rw [Finset.sum_filter] + unfold bernoulliPolynomial + apply Finset.sum_congr rfl + intro ω hω + by_cases h : P ω <;> simp [h,bernoulliWeight] + + +theorem finiteBadPieceProbability_le_radius (G : BondGraph V E) (Q : Finset E) (x : V) + (M K r d : ℕ) (L : ℝ) (hK : 0 < K) (hN : 1 ≤ d*M) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) + (hr : 2*(r:ℝ) ≤ (K:ℝ)*L) (p : unitInterval) (hp : (p:ℝ) < 1) : + finiteBadPieceProbability G Q x M K L p ≤ + (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K*finiteCappedRadiusTail G Q x M r p := by + let A := Q.powerset.filter (BadPieceEvent G Q x M K L) + let B := Q.powerset.filter (CappedRadiusEvent G Q x M r) + let S := fun η => incidentBonds G Q (finiteRootComponent G η x) + have hex : ∀ ω : Finset E, ∃ η : Finset E, ω ∈ A → + η ∈ B ∧ η ⊆ ω ∧ (ω \ η).card ≤ K ∧ ω \ η ⊆ S η := by + intro ω + by_cases hω : ω ∈ A + · obtain ⟨hωQ,hωbad⟩ := Finset.mem_filter.mp hω + have hωsub := Finset.mem_powerset.mp hωQ + obtain ⟨η,hη,hcap,hcard,hS⟩ := badPieceEvent_pruning G Q x M K r L hK hr ω hωsub hωbad + exact ⟨η,fun _ => ⟨Finset.mem_filter.mpr ⟨Finset.mem_powerset.mpr (hη.trans hωsub),hcap⟩, + hη,hcard,hS⟩⟩ + · exact ⟨∅,fun h => (hω h).elim⟩ + choose f hf using hex + have hS : ∀ η ∈ B, (S η).card ≤ d*M := by + intro η hη + exact (incidentBonds_card_le G Q (finiteRootComponent G η x) d hdeg).trans + (Nat.mul_le_mul_left d (Finset.mem_filter.mp hη).2.1) + have hc := finite_closure_comparison Q A B (Finset.filter_subset _ _) f S K (d*M) hN p hp hf hS + simpa only [finiteBadPieceProbability,finiteCappedRadiusTail,bernoulliPolynomial_indicator_weight, + A,B] using hc + + +theorem finiteBadPieceProbability_exponential [Nonempty V] (G : BondGraph V E) + (Q : Finset E) (x : V) (M K d : ℕ) (L : ℝ) (hK : 0 < K) (hN : 1 ≤ d*M) + (hL : 4 ≤ (K:ℝ)*L) (hd : 0 < d) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) + (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) + (B : ℝ) (hB : 1 ≤ B) + (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) : + finiteBadPieceProbability G Q x M K L p ≤ + (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K* + (2/((h:ℝ)*(1-h)^M))*Real.exp (-((K:ℝ)*L)/(16*B)) := by + let r := ⌈(K:ℝ)*L/4⌉₊ + have hpos : 0 ≤ (K:ℝ)*L/4 := by linarith + have hrlo : (K:ℝ)*L/4 ≤ r := Nat.le_ceil _ + have hrhi : (r:ℝ) < (K:ℝ)*L/4+1 := Nat.ceil_lt_add_one hpos + have hr : 2*(r:ℝ) ≤ (K:ℝ)*L := by linarith + have hrad := finiteCappedRadiusTail_exponential G p h hp hh hh1 d hd Q x hdeg B hB hAB M r + have hcmp := finiteBadPieceProbability_le_radius G Q x M K r d L hK hN hdeg hr p hp + have hc : 0 ≤ (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K := by positivity + have hhfac : 0 ≤ 2/((h:ℝ)*(1-h)^M) := by positivity + have hBpos : 0 < B := lt_of_lt_of_le zero_lt_one hB + have hratio : -((r:ℝ)/(4*B)) ≤ -((K:ℝ)*L)/(16*B) := by + apply (le_div_iff₀ (by positivity : 0 < 16*B)).mpr + field_simp + nlinarith + exact hcmp.trans ((mul_le_mul_of_nonneg_left hrad hc).trans (by + rw [← mul_assoc] + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by simpa only [neg_div] using hratio)) (mul_nonneg hc hhfac))) + + + +def FiniteGoodForScale (G : BondGraph V E) (Q : Finset E) (x : V) (L : ℝ) (ω : Finset E) : Prop := + ∀ W : Finset V, W ⊆ finiteRootComponent G ω x → + (∀ a ∈ W, ∀ b ∈ W, Conn G (internalBonds G ω (W : Set V) : Set E) a b) → + 0 < (openContacts G ω (W : Set V)).card → + ∀ a ∈ W, ∀ b ∈ W, + (pairOpenPivotals G Q a b (internalBonds G ω (W : Set V))).card ≤ + ((openContacts G ω (W : Set V)).card:ℝ)*L + +def CappedBadGoodnessEvent (G : BondGraph V E) (Q : Finset E) (x : V) (M : ℕ) (L : ℝ) + (ω : Finset E) : Prop := + (finiteRootComponent G ω x).card ≤ M ∧ ¬FiniteGoodForScale G Q x L ω + +noncomputable def finiteBadGoodnessProbability (G : BondGraph V E) (Q : Finset E) + (x : V) (M : ℕ) (L p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => if CappedBadGoodnessEvent G Q x M L ω then 1 else 0) p + + +theorem cappedBadGoodness_iff (G : BondGraph V E) (Q : Finset E) (x : V) (M d : ℕ) + (L : ℝ) (ω : Finset E) (hω : ω ⊆ Q) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : + CappedBadGoodnessEvent G Q x M L ω ↔ + ∃ K ∈ Finset.Icc 1 (d*M), BadPieceEvent G Q x M K L ω := by + constructor + · rintro ⟨hcap,hbad⟩ + simp only [FiniteGoodForScale,not_forall] at hbad + obtain ⟨W,hbad⟩ := hbad + push Not at hbad + obtain ⟨hW,hWconn,hK,a,ha,b,hb,hfar⟩ := hbad + have hinc : openContacts G ω (W : Set V) ⊆ incidentBonds G Q W := by + intro e he + obtain ⟨heω,c,z,hcz,hc,_⟩ := Finset.mem_filter.mp he + exact (mem_incidentBonds G Q W e).mpr ⟨hω heω,c,hc,by simp [hcz]⟩ + have hbound := (Finset.card_le_card hinc).trans ((incidentBonds_card_le G Q W d hdeg).trans + (Nat.mul_le_mul_left d ((Finset.card_le_card hW).trans hcap))) + exact ⟨_,Finset.mem_Icc.mpr ⟨hK,hbound⟩,hcap,W,hW,hWconn,rfl,a,ha,b,hb,hfar⟩ + · rintro ⟨K,hK,hcap,W,hW,hWconn,hcontacts,a,ha,b,hb,hfar⟩ + refine ⟨hcap,fun hgood => ?_⟩ + have hh := hgood W hW hWconn (by rw [hcontacts]; exact (Finset.mem_Icc.mp hK).1) a ha b hb + rw [hcontacts] at hh + exact not_lt_of_ge hh hfar + + +theorem finiteBadGoodnessProbability_le_sum (G : BondGraph V E) (Q : Finset E) (x : V) + (M d : ℕ) (L : ℝ) (p : unitInterval) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : + finiteBadGoodnessProbability G Q x M L p ≤ + ∑ K ∈ Finset.Icc 1 (d*M), finiteBadPieceProbability G Q x M K L p := by + unfold finiteBadPieceProbability finiteBadGoodnessProbability + rw [← bernoulliPolynomial_sum] + apply bernoulliPolynomial_mono _ _ _ _ p.2 + intro ω hω + by_cases he : CappedBadGoodnessEvent G Q x M L ω + · obtain ⟨K,hK,hbad⟩ := (cappedBadGoodness_iff G Q x M d L ω hω hdeg).mp he + simp only [he,ite_true] + exact (by simp [hbad] : (1:ℝ) ≤ if BadPieceEvent G Q x M K L ω then 1 else 0).trans + (Finset.single_le_sum (f := fun j => if BadPieceEvent G Q x M j L ω then (1:ℝ) else 0) + (fun j _ => by split_ifs <;> norm_num) hK) + · simp only [he,ite_false] + exact Finset.sum_nonneg fun j _ => by split_ifs <;> norm_num + + +theorem finiteBadGoodnessProbability_geometric [Nonempty V] (G : BondGraph V E) + (Q : Finset E) (x : V) (M d : ℕ) (L : ℝ) (hN : 1 ≤ d*M) (hL : 4 ≤ L) + (hd : 0 < d) (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) + (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (hh1 : (h:ℝ) < 1) + (B : ℝ) (hB : 1 ≤ B) + (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) + (hq : ((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B)) ≤ 1) : + finiteBadGoodnessProbability G Q x M L p ≤ + (2/((h:ℝ)*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* + (((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B))) := by + let N := d*M + let a := max 1 ((p:ℝ)/(1-p)) + let H := 2/((h:ℝ)*(1-h)^M) + let q := (N:ℝ)*a*Real.exp (-L/(16*B)) + have ha : 0 ≤ a := le_trans zero_le_one (le_max_left ..) + have hq0 : 0 ≤ q := mul_nonneg (mul_nonneg (Nat.cast_nonneg _) ha) (Real.exp_nonneg _) + have hH : 0 ≤ H := by dsimp [H]; positivity + have hkbound : ∀ K ∈ Finset.Icc 1 N, finiteBadPieceProbability G Q x M K L p ≤ H*((N:ℝ)+1)*q := by + intro K hK + obtain ⟨hK1,hKN⟩ := Finset.mem_Icc.mp hK + have hKR : (1:ℝ) ≤ K := by exact_mod_cast hK1 + have hKL : 4 ≤ (K:ℝ)*L := by nlinarith + have hexp := finiteBadPieceProbability_exponential G Q x M K d L hK1 hN hKL hd hdeg + p h hp hh hh1 B hB hAB + have hid : (((K+1)*(d*M)^K:ℕ):ℝ)*(max 1 ((p:ℝ)/(1-p)))^K* + (2/((h:ℝ)*(1-h)^M))*Real.exp (-((K:ℝ)*L)/(16*B)) = H*((K:ℝ)+1)*q^K := by + rw [show -((K:ℝ)*L)/(16*B) = (K:ℝ)*(-L/(16*B)) by ring,Real.exp_nat_mul] + simp only [q,H,N,a,mul_pow,Nat.cast_mul,Nat.cast_add,Nat.cast_pow,Nat.cast_one] + ring + rw [hid] at hexp + have hpow : q^K ≤ q := by + simpa only [pow_one] using pow_le_pow_of_le_one hq0 hq hK1 + calc + _ ≤ H*((K:ℝ)+1)*q^K := hexp + _ ≤ H*((N:ℝ)+1)*q := mul_le_mul + (mul_le_mul_of_nonneg_left (by exact_mod_cast Nat.add_le_add_right hKN 1) hH) + hpow (pow_nonneg hq0 _) (mul_nonneg hH (by positivity)) + calc + _ ≤ ∑ K ∈ Finset.Icc 1 N, finiteBadPieceProbability G Q x M K L p := + finiteBadGoodnessProbability_le_sum G Q x M d L p hdeg + _ ≤ ∑ _K ∈ Finset.Icc 1 N, H*((N:ℝ)+1)*q := Finset.sum_le_sum hkbound + _ = (N:ℝ)*(H*((N:ℝ)+1)*q) := by simp + _ = _ := by dsimp [N,H,q,a]; push_cast; ring + +end FiniteGoodnessProbability + +section GoodnessAsymptotics + + +theorem inverse_mark_cost_le (h : ℝ) (hh : 0 ≤ h) (hh2 : h ≤ 1/2) (M : ℕ) : + ((1-h)^M)⁻¹ ≤ Real.exp (2*(M:ℝ)*h) := by + have hq : 0 < 1-h := by linarith + have hi : 1/(1-h) ≤ 1+2*h := (div_le_iff₀ hq).mpr (by nlinarith) + have hl := Real.one_sub_inv_le_log_of_pos hq + rw [one_div] at hi + have hlog : -2*h ≤ Real.log (1-h) := by linarith + calc + ((1-h)^M)⁻¹ = Real.exp (-((M:ℝ)*Real.log (1-h))) := by + rw [← Real.log_pow,Real.exp_neg,Real.exp_log (pow_pos hq _)] + _ ≤ _ := Real.exp_le_exp.mpr (by + have := mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg M) + nlinarith) + + + +theorem ghost_scale_estimates (M : ℕ) (ε c a : ℝ) (d : ℕ) + (hM : 1 ≤ (M:ℝ)) (hε : 0 < ε) (hε1 : ε < 1/2) (hc : 1 ≤ c) + (ha : 1 ≤ a) (hd : 1 ≤ d) + (hsmall : (M:ℝ)^(ε-1) ≤ 1/2) + (hlog : 4*Real.log M ≤ (M:ℝ)^ε) + (hlog2 : Real.log M ≤ (M:ℝ)^(ε/2)) + (hgrowth : 80*c ≤ (M:ℝ)^(ε/4)) + (hconstant : Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a) ≤ (M:ℝ)^ε) : + let h := (M:ℝ)^(ε-1) + let B := c*(M:ℝ)^(1/2-ε/4) + let L := (M:ℝ)^(1/2+ε) + 0 < h ∧ h ≤ 1/2 ∧ 1 ≤ B ∧ + c*Real.sqrt (Real.log (1/h)/h) ≤ B ∧ + (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* + (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε) := by + dsimp only + let h := (M:ℝ)^(ε-1) + let B := c*(M:ℝ)^(1/2-ε/4) + let L := (M:ℝ)^(1/2+ε) + have hMp : 0 < (M:ℝ) := lt_of_lt_of_le zero_lt_one hM + have hcp : 0 < c := lt_of_lt_of_le zero_lt_one hc + have hap : 0 < a := lt_of_lt_of_le zero_lt_one ha + have hdp : 0 < (d:ℝ) := by exact_mod_cast (show 0 < d by omega) + have hhp : 0 < h := Real.rpow_pos_of_pos hMp _ + have hq : 0 < 1-h := by dsimp [h] at *; linarith + have hlogM : 0 ≤ Real.log M := Real.log_nonneg hM + have hinv : 1/h = (M:ℝ)^(1-ε) := by + dsimp [h] + rw [show 1-ε = -(ε-1) by ring,Real.rpow_neg hMp.le,one_div] + have hmh : (M:ℝ)*h = (M:ℝ)^ε := by + dsimp [h] + calc + _ = (M:ℝ)^((1:ℝ)+(ε-1)) := by rw [Real.rpow_add hMp,Real.rpow_one] + _ = _ := by congr 1; ring + have hhM : 1/h ≤ (M:ℝ) := by + rw [hinv] + simpa only [Real.rpow_one] using + Real.rpow_le_rpow_of_exponent_le hM (show 1-ε ≤ (1:ℝ) by linarith) + have hB1 : 1 ≤ B := by + have hp := Real.one_le_rpow hM (show 0 ≤ 1/2-ε/4 by linarith) + dsimp [B] + nlinarith + have hBp : 0 < B := lt_of_lt_of_le zero_lt_one hB1 + have hAB : c*Real.sqrt (Real.log (1/h)/h) ≤ B := by + apply mul_le_mul_of_nonneg_left _ hcp.le + have hl : Real.log (1/h) ≤ Real.log M := by + rw [hinv,Real.log_rpow hMp] + nlinarith + have hl2 : Real.log (1/h)/h ≤ (M:ℝ)^(1-ε/2) := by + calc + _ = Real.log (1/h)*(M:ℝ)^(1-ε) := by rw [div_eq_mul_one_div,hinv] + _ ≤ (M:ℝ)^(ε/2)*(M:ℝ)^(1-ε) := + mul_le_mul_of_nonneg_right (hl.trans hlog2) (Real.rpow_nonneg hMp.le _) + _ = _ := by rw [← Real.rpow_add hMp]; congr 1; ring + calc + _ ≤ Real.sqrt ((M:ℝ)^(1-ε/2)) := Real.sqrt_le_sqrt hl2 + _ = (M:ℝ)^(1/2-ε/4) := by + rw [Real.sqrt_eq_rpow,← Real.rpow_mul hMp.le] + congr 1 + ring + have hratio : 5*(M:ℝ)^ε ≤ L/(16*B) := by + have hid : (M:ℝ)^ε*(M:ℝ)^(ε/4)*(M:ℝ)^(1/2-ε/4) = L := by + dsimp [L] + rw [← Real.rpow_add hMp,← Real.rpow_add hMp] + congr 1 + ring + apply (le_div_iff₀ (by positivity : 0 < 16*B)).mpr + have hh := mul_le_mul_of_nonneg_left hgrowth + (mul_nonneg (Real.rpow_nonneg hMp.le ε) (Real.rpow_nonneg hMp.le (1/2-ε/4))) + dsimp [B] + nlinarith [hid] + refine ⟨hhp,hsmall,hB1,hAB,?_⟩ + let A := 2*(d:ℝ)^2*((d:ℝ)+1)*a + have hAp : 0 < A := by dsimp [A]; positivity + have hcost : 2/(h*(1-h)^M) ≤ 2*(M:ℝ)*Real.exp (2*(M:ℝ)^ε) := by + calc + _ = 2*(1/h)*((1-h)^M)⁻¹ := by field_simp + _ ≤ 2*(M:ℝ)*Real.exp (2*(M:ℝ)*h) := + mul_le_mul (mul_le_mul_of_nonneg_left hhM (by norm_num)) + (inverse_mark_cost_le h hhp.le hsmall M) (inv_nonneg.mpr (pow_nonneg hq.le _)) (by positivity) + _ = _ := by rw [show 2*(M:ℝ)*h = 2*(M:ℝ)^ε by rw [mul_assoc,hmh]] + have hN1 : ((d*M:ℕ):ℝ)+1 ≤ ((d:ℝ)+1)*(M:ℝ) := by push_cast; nlinarith + have hpoint : + (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* + (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ + A*(M:ℝ)^4*Real.exp (2*(M:ℝ)^ε-L/(16*B)) := by + calc + _ ≤ (2*(M:ℝ)*Real.exp (2*(M:ℝ)^ε))*((d*M:ℕ):ℝ)*(((d:ℝ)+1)*(M:ℝ))* + (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + exact mul_le_mul (mul_le_mul_of_nonneg_right hcost (by positivity)) hN1 + (by positivity) (by positivity) + _ = _ := by + rw [show 2*(M:ℝ)^ε-L/(16*B) = 2*(M:ℝ)^ε+(-L/(16*B)) by ring,Real.exp_add] + dsimp [A] + push_cast + ring + have heq : A*(M:ℝ)^4*Real.exp (2*(M:ℝ)^ε-L/(16*B)) = + Real.exp (Real.log A+4*Real.log M+2*(M:ℝ)^ε-L/(16*B)) := by + rw [show Real.log A+4*Real.log M+2*(M:ℝ)^ε-L/(16*B) = + Real.log A+4*Real.log M+(2*(M:ℝ)^ε-L/(16*B)) by ring,Real.exp_add, + Real.exp_add,Real.exp_log hAp] + have hh : Real.exp (4*Real.log M) = (M:ℝ)^4 := by + simpa only [Nat.cast_ofNat,Real.exp_log hMp] using Real.exp_nat_mul (Real.log M) 4 + rw [hh] + rw [heq] at hpoint + exact hpoint.trans (Real.exp_le_exp.mpr (by linarith)) + + + +theorem eventually_ghost_scale (ε c a : ℝ) (d : ℕ) (hε : 0 < ε) (hε1 : ε < 1/2) + (hc : 1 ≤ c) (ha : 1 ≤ a) (hd : 1 ≤ d) : + ∀ᶠ M : ℕ in Filter.atTop, + let h := (M:ℝ)^(ε-1) + let B := c*(M:ℝ)^(1/2-ε/4) + let L := (M:ℝ)^(1/2+ε) + 1 ≤ M ∧ 4 ≤ L ∧ 0 < h ∧ h ≤ 1/2 ∧ 1 ≤ B ∧ + c*Real.sqrt (Real.log (1/h)/h) ≤ B ∧ + (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* + (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε) := by + have hh : ∀ᶠ m : ℝ in Filter.atTop, m^(ε-1) ≤ 1/2 := by + have ht := tendsto_rpow_neg_atTop (show 0 < 1-ε by linarith) + filter_upwards [ht.eventually (Iio_mem_nhds (by norm_num : (0:ℝ) < 1/2))] with m hm + simpa only [neg_sub] using (show m^(-(1-ε)) < 1/2 from hm).le + have hl := (isLittleO_log_rpow_atTop hε).bound (show (0:ℝ) < 1/4 by norm_num) + have hl2 := (isLittleO_log_rpow_atTop (show 0 < ε/2 by linarith)).bound zero_lt_one + have hg := (tendsto_rpow_atTop (show 0 < ε/4 by linarith)).eventually (Filter.eventually_ge_atTop (80*c)) + have hC := (tendsto_rpow_atTop hε).eventually + (Filter.eventually_ge_atTop (Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a))) + have hL := (tendsto_rpow_atTop (show 0 < 1/2+ε by linarith)).eventually (Filter.eventually_ge_atTop 4) + have hnum : ∀ᶠ m : ℝ in Filter.atTop, 1 ≤ m ∧ 4 ≤ m^(1/2+ε) ∧ m^(ε-1) ≤ 1/2 ∧ + 4*Real.log m ≤ m^ε ∧ Real.log m ≤ m^(ε/2) ∧ 80*c ≤ m^(ε/4) ∧ + Real.log (2*(d:ℝ)^2*((d:ℝ)+1)*a) ≤ m^ε := by + filter_upwards [Filter.eventually_ge_atTop (1:ℝ),hh,hl,hl2,hg,hC,hL] with m hm hh hl hl2 hg hC hL + have hm0 : 0 ≤ m := le_trans zero_le_one hm + simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hm), + abs_of_nonneg (Real.rpow_nonneg hm0 ε)] at hl + simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hm), + abs_of_nonneg (Real.rpow_nonneg hm0 (ε/2)),one_mul] at hl2 + exact ⟨hm,hL,hh,by linarith,hl2,hg,hC⟩ + have hcast : Filter.Tendsto (fun M : ℕ => (M:ℝ)) Filter.atTop Filter.atTop := tendsto_natCast_atTop_atTop + filter_upwards [hcast.eventually hnum] with M hM + obtain ⟨hM,hL,hh,hl,hl2,hg,hC⟩ := hM + exact ⟨by exact_mod_cast hM,hL,ghost_scale_estimates M ε c a d hM hε hε1 hc ha hd hh hl hl2 hg hC⟩ + + +theorem ghost_ratio_le_one (M d : ℕ) (hM : 1 ≤ M) (hd : 1 ≤ d) + (h B L a ε : ℝ) (hh : 0 < h) (hh2 : h ≤ 1/2) (ha : 0 ≤ a) + (hb : (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1)* + (((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B))) ≤ Real.exp (-(M:ℝ)^ε)) : + ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) ≤ 1 := by + have hq : 0 < 1-h := by linarith + have hp : (1-h)^M ≤ 1 := pow_le_one₀ hq.le (by linarith) + have hden : 0 < h*(1-h)^M := mul_pos hh (pow_pos hq _) + have hH : 1 ≤ 2/(h*(1-h)^M) := by + apply (le_div_iff₀ hden).mpr + have := mul_le_mul_of_nonneg_left hp hh.le + nlinarith + have hN : (1:ℝ) ≤ (d*M:ℕ) := by exact_mod_cast Nat.mul_le_mul hd hM + have hprod : 1 ≤ (2/(h*(1-h)^M))*((d*M:ℕ):ℝ)*((d*M:ℕ)+1) := + one_le_mul_of_one_le_of_one_le (one_le_mul_of_one_le_of_one_le hH hN) (by linarith) + have hq0 : 0 ≤ ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) := by positivity + exact (le_mul_of_one_le_left hq0 hprod).trans (hb.trans + (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (Real.rpow_nonneg (Nat.cast_nonneg M) ε)))) + +end GoodnessAsymptotics + +section UniformFiniteGoodness +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_bad_goodness_stretched_exp [Nonempty V] (G : BondGraph V E) + (d : ℕ) (hd : 0 < d) (pbar : unitInterval) (hpbar : (pbar:ℝ) < 1) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) : + ∀ᶠ M : ℕ in Filter.atTop, ∀ (Q : Finset E) (x : V), + (∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) → + ∀ p : unitInterval, p ≤ pbar → + finiteBadGoodnessProbability G Q x M ((M:ℝ)^(1/2+ε)) p ≤ + Real.exp (-(M:ℝ)^ε) := by + let c := max 1 (Real.sqrt ((d:ℝ)/2)/(1-pbar)) + let a := max 1 ((pbar:ℝ)/(1-pbar)) + have hc : 1 ≤ c := le_max_left .. + have ha : 1 ≤ a := le_max_left .. + filter_upwards [eventually_ghost_scale ε c a d hε hε1 hc ha hd] with M hM + dsimp only at hM + obtain ⟨hM1,hL,hh,hh2,hB,hAB,hpref⟩ := hM + intro Q x hdeg p hpp + have hpp' : (p:ℝ) ≤ pbar := hpp + have hp : (p:ℝ) < 1 := hpp'.trans_lt hpbar + let h : unitInterval := ⟨(M:ℝ)^(ε-1),hh.le,by linarith⟩ + let B := c*(M:ℝ)^(1/2-ε/4) + let L := (M:ℝ)^(1/2+ε) + have hodds : max 1 ((p:ℝ)/(1-p)) ≤ a := by + apply max_le (le_max_left ..) + have hr : (p:ℝ)/(1-p) ≤ (pbar:ℝ)/(1-pbar) := + div_le_div₀ pbar.2.1 hpp' (by linarith) (by linarith) + exact hr.trans (le_max_right ..) + have hcoeff : Real.sqrt ((d:ℝ)/2)/(1-p) ≤ c := by + have hr : Real.sqrt ((d:ℝ)/2)/(1-p) ≤ Real.sqrt ((d:ℝ)/2)/(1-pbar) := + div_le_div_of_nonneg_left (Real.sqrt_nonneg _) (by linarith) (by linarith) + exact hr.trans (le_max_right ..) + have hsqrt : 0 ≤ Real.sqrt (Real.log (1/(h:ℝ))/h) := Real.sqrt_nonneg _ + have hqbar := ghost_ratio_le_one M d hM1 hd h B L a ε hh hh2 + (le_trans zero_le_one ha) hpref + have hqcmp : ((d*M:ℕ):ℝ)*max 1 ((p:ℝ)/(1-p))*Real.exp (-L/(16*B)) ≤ + ((d*M:ℕ):ℝ)*a*Real.exp (-L/(16*B)) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hodds (Nat.cast_nonneg _)) (Real.exp_nonneg _) + have hg := finiteBadGoodnessProbability_geometric G Q x M d L (Nat.mul_le_mul hd hM1) + hL hd hdeg p h hp hh (by dsimp [h]; linarith) B hB + ((mul_le_mul_of_nonneg_right hcoeff hsqrt).trans hAB) (hqcmp.trans hqbar) + refine hg.trans ((mul_le_mul_of_nonneg_left hqcmp ?_).trans hpref) + have hnon : 0 ≤ 1-(h:ℝ) := sub_nonneg.mpr h.2.2 + positivity + +end UniformFiniteGoodness + +section ClusterLocality +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem reachBall_le_step (G : BondGraph V E) (x : V) (n : ℕ) : + reachBall G x n ⊆ reachBall G x (n+1) := fun _ h => Or.inl h + +theorem reachBall_mono_local (G : BondGraph V E) (x : V) : Monotone (reachBall G x) := + monotone_nat_of_le_succ (reachBall_le_step G x) + +theorem walk_mem_reachBall (G : BondGraph V E) (ω : Set E) {a b x : V} + (w : (openSimpleGraph G ω).Walk a b) (n : ℕ) (ha : a ∈ reachBall G x n) : + b ∈ reachBall G x (n+w.length) := by + induction w generalizing n with + | nil => simpa using ha + | @cons a z b hz w ih => + have hz' : z ∈ reachBall G x (n+1) := by + apply Or.inr + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] + obtain ⟨e,he,hend⟩ := hz.2 + exact ⟨a,ha,e,hend⟩ + simpa only [SimpleGraph.Walk.length_cons,Nat.add_assoc,Nat.add_left_comm,Nat.add_comm] + using ih (n+1) hz' + + +theorem finite_cluster_subset_reachBall (G : BondGraph V E) (ω : Set E) (x : V) + (hfin : (cluster G ω x).Finite) (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) : + cluster G ω x ⊆ reachBall G x M := by + intro y hy + obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp hy + let q := w.toPath + have hs : q.val.support.toFinset ⊆ hfin.toFinset := by + intro z hz + have hz' : z ∈ q.val.support := List.mem_toFinset.mp hz + exact hfin.mem_toFinset.mpr ((conn_iff_reachable G ω x z).mpr ⟨q.val.takeUntil z hz'⟩) + have hc : q.val.length+1 ≤ (cluster G ω x).ncard := by + have hc := Finset.card_le_card hs + rwa [List.toFinset_card_of_nodup q.property.support_nodup, + SimpleGraph.Walk.length_support,← Set.ncard_eq_toFinset_card _ hfin] at hc + have hr := walk_mem_reachBall G ω q.val 0 (Set.mem_singleton x) + simp only [Nat.zero_add] at hr + exact reachBall_mono_local G x (by omega) hr + + + +theorem cluster_restrict_incident_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (ω : Set E) (x : V) + (hsub : cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x ⊆ Λ) : + cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x = cluster G ω x := by + apply Set.Subset.antisymm + · exact fun _ h => conn_mono G Set.inter_subset_left h + · intro y hy + induction hy with + | refl => exact conn_refl G _ x + | @tail a b _ hab ih => + obtain ⟨e,he,hend⟩ := hab + have heQ : e ∈ incidentSupport G hloc Λ := + (mem_incidentSupport G hloc Λ e).mpr ⟨a,hsub ih,by simp [hend]⟩ + exact ih.tail ⟨e,⟨he,heQ⟩,hend⟩ + +theorem cluster_restrict_incident_of_full (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (ω : Set E) (x : V) (hsub : cluster G ω x ⊆ Λ) : + cluster G (ω ∩ (incidentSupport G hloc Λ : Set E)) x = cluster G ω x := by + apply cluster_restrict_incident_eq G hloc Λ ω x + exact (fun _ h => hsub (conn_mono G Set.inter_subset_left h)) + + +theorem capped_cluster_local (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (ω : Set E) : + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) ↔ + ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ + (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M) := by + dsimp only + let Λ := (finite_reachBall hloc x M).toFinset + let Q := incidentSupport G hloc Λ + constructor + · rintro ⟨hfin,hcap⟩ + have hsub : cluster G ω x ⊆ Λ := by + simpa only [Λ,Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hfin M hcap + rw [cluster_restrict_incident_of_full G hloc Λ ω x hsub] + exact ⟨hfin,hcap⟩ + · rintro ⟨hfin,hcap⟩ + have hsub : cluster G (ω ∩ (Q : Set E)) x ⊆ Λ := by + simpa only [Λ,Set.Finite.coe_toFinset] using + finite_cluster_subset_reachBall G (ω ∩ (Q : Set E)) x hfin M hcap + have heq := cluster_restrict_incident_eq G hloc Λ ω x hsub + rw [heq] at hfin hcap + exact ⟨hfin,hcap⟩ + +end ClusterLocality + +section InfiniteGoodness +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def pivotalDistance (G : BondGraph V E) (ω : Set E) (a b : V) : ℕ := + {e | OpenMarkedPivotal G ω {b} a e}.ncard + + +def contactSet (G : BondGraph V E) (ω : Set E) (W : Set V) : Set E := + {e | e ∈ ω ∧ CutExists G W e} + + +def GoodForScale (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) : Prop := + ∀ W : Finset V, (W : Set V) ⊆ cluster G ω x → + (∀ a ∈ W, ∀ b ∈ W, Conn G (ω ∩ internalEdges G (W : Set V)) a b) → + 0 < (contactSet G ω (W : Set V)).ncard → + ∀ a ∈ W, ∀ b ∈ W, + (pivotalDistance G (ω ∩ internalEdges G (W : Set V)) a b : ℝ) ≤ + (contactSet G ω (W : Set V)).ncard*L + + +def CappedBadGoodness (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : Prop := + (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ ¬GoodForScale G ω x L + +theorem pivotalDistance_finset (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) (a b : V) : + pivotalDistance G (ω : Set E) a b = (pairOpenPivotals G Q a b ω).card := by + have he : {e | OpenMarkedPivotal G (ω : Set E) {b} a e} = + (pairOpenPivotals G Q a b ω : Set E) := by + ext e + simp only [Finset.mem_coe,mem_pairOpenPivotals,Set.mem_ofPred_eq] + exact ⟨fun h => ⟨hω h.1,h⟩,And.right⟩ + simp only [pivotalDistance,he,Set.ncard_coe_finset] + +theorem contactSet_finset (G : BondGraph V E) (ω : Finset E) (W : Set V) : + contactSet G (ω : Set E) W = (openContacts G ω W : Set E) := by + ext e + simp only [contactSet,openContacts,Finset.mem_coe,Finset.mem_filter,Set.mem_ofPred_eq] + +theorem finiteGoodForScale_iff (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) + (x : V) (L : ℝ) : FiniteGoodForScale G Q x L ω ↔ GoodForScale G (ω : Set E) x L := by + have hroot : ∀ W : Finset V, W ⊆ finiteRootComponent G ω x ↔ (W : Set V) ⊆ cluster G ω x := by + intro W + rw [← coe_finiteRootComponent] + exact Finset.coe_subset.symm + have hpiv (W : Finset V) (a b : V) := pivotalDistance_finset G Q + (internalBonds G ω (W : Set V)) ((Finset.filter_subset _ _).trans hω) a b + simp only [FiniteGoodForScale,GoodForScale,hroot,← coe_internalBonds,contactSet_finset, + Set.ncard_coe_finset,hpiv] + +theorem cappedBadGoodness_finset_iff (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) + (x : V) (M : ℕ) (L : ℝ) : + CappedBadGoodness G (ω : Set E) x M L ↔ CappedBadGoodnessEvent G Q x M L ω := by + have hfin := cluster_finite_of_finite_edges G ω.finite_toSet x + simp only [CappedBadGoodness,CappedBadGoodnessEvent,hfin,true_and] + rw [← coe_finiteRootComponent,Set.ncard_coe_finset,finiteGoodForScale_iff G Q ω hω] + + +theorem internal_config_eq_of_incident (G : BondGraph V E) (ω η : Set E) (C W : Set V) + (hW : W ⊆ C) (he : ∀ e, (∃ v ∈ C, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : + ω ∩ internalEdges G W = η ∩ internalEdges G W := by + ext e + by_cases hi : e ∈ internalEdges G W + · have hinc : ∃ v ∈ C, v ∈ G e := + ⟨(G e).out.1,hW (hi _ (Sym2.out_fst_mem _)),Sym2.out_fst_mem _⟩ + simp only [Set.mem_inter_iff,hi,and_true,he e hinc] + · simp only [Set.mem_inter_iff,hi,and_false] + +theorem contacts_eq_of_incident (G : BondGraph V E) (ω η : Set E) (C W : Set V) + (hW : W ⊆ C) (he : ∀ e, (∃ v ∈ C, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : + contactSet G ω W = contactSet G η W := by + ext e + by_cases hi : CutExists G W e + · obtain ⟨a,b,hab,ha,_⟩ := hi + have hinc : ∃ v ∈ C, v ∈ G e := ⟨a,hW ha,by simp [hab]⟩ + simp only [contactSet,Set.mem_ofPred_eq,he e hinc] + · simp only [contactSet,Set.mem_ofPred_eq,hi,and_false] + + +theorem goodForScale_congr (G : BondGraph V E) (ω η : Set E) (x : V) (L : ℝ) + (hC : cluster G ω x = cluster G η x) + (he : ∀ e, (∃ v ∈ cluster G ω x, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : + GoodForScale G ω x L ↔ GoodForScale G η x L := by + unfold GoodForScale + apply forall_congr' + intro W + rw [← hC] + apply forall_congr' + intro hW + rw [internal_config_eq_of_incident G ω η _ _ hW he,contacts_eq_of_incident G ω η _ _ hW he] + +theorem goodForScale_restrict_incident (G : BondGraph V E) (hloc : LocallyFinite G) + (Λ : Finset V) (ω : Set E) (x : V) (L : ℝ) (hsub : cluster G ω x ⊆ Λ) : + GoodForScale G ω x L ↔ GoodForScale G (ω ∩ (incidentSupport G hloc Λ : Set E)) x L := by + apply goodForScale_congr G ω _ x L + (cluster_restrict_incident_of_full G hloc Λ ω x hsub).symm + intro e he + obtain ⟨v,hv,hve⟩ := he + have hQ := (mem_incidentSupport G hloc Λ e).mpr ⟨v,hsub hv,hve⟩ + simp only [Set.mem_inter_iff,Finset.mem_coe,hQ,and_true] + + +theorem cappedBadGoodness_local (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (L : ℝ) (ω : Set E) : + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + CappedBadGoodness G ω x M L ↔ CappedBadGoodness G (ω ∩ (Q : Set E)) x M L := by + let Λ := (finite_reachBall hloc x M).toFinset + let Q := incidentSupport G hloc Λ + change CappedBadGoodness G ω x M L ↔ CappedBadGoodness G (ω ∩ (Q : Set E)) x M L + have hcap := capped_cluster_local G hloc x M ω + change ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) ↔ + ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M) at hcap + have hg : ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M) → + (GoodForScale G ω x L ↔ GoodForScale G (ω ∩ (Q : Set E)) x L) := by + rintro ⟨hfin,hM⟩ + apply goodForScale_restrict_incident G hloc Λ ω x L + simpa only [Λ,Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hfin M hM + constructor + · rintro ⟨hfin,hM,hbad⟩ + exact ⟨(hcap.mp ⟨hfin,hM⟩).1,(hcap.mp ⟨hfin,hM⟩).2,fun hh => hbad ((hg ⟨hfin,hM⟩).mpr hh)⟩ + · rintro ⟨hfin,hM,hbad⟩ + have hc := hcap.mpr ⟨hfin,hM⟩ + exact ⟨hc.1,hc.2,fun hh => hbad ((hg hc).mp hh)⟩ + +end InfiniteGoodness + +section GoodnessLaw +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurableSet_finite_restriction (Q : Finset E) (A : Set (Set E)) : + MeasurableSet {ω : Set E | ω ∩ (Q : Set E) ∈ A} := by + have hm : MeasurableSet {η : Set (Q : Set E) | (Subtype.val '' η : Set E) ∈ A} := .of_discrete + convert hm.preimage (measurable_set_restrict (Q : Set E)) using 1 + ext ω + have he : (Subtype.val '' (Subtype.val ⁻¹' ω : Set (Q : Set E)) : Set E) = ω ∩ (Q : Set E) := by + ext e + simp [and_comm] + simp only [Set.mem_preimage,Set.mem_ofPred_eq,he] + +theorem measurableSet_cappedBadGoodness (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (L : ℝ) : MeasurableSet {ω | CappedBadGoodness G ω x M L} := by + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + have he : {ω | CappedBadGoodness G ω x M L} = + {ω | ω ∩ (Q : Set E) ∈ {η | CappedBadGoodness G η x M L}} := by + ext ω + exact cappedBadGoodness_local G hloc x M L ω + rw [he] + exact measurableSet_finite_restriction Q _ + + +theorem bad_goodness_law_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (L : ℝ) (p : unitInterval) : + (law p).real {ω | CappedBadGoodness G ω x M L} = + finiteBadGoodnessProbability G + (incidentSupport G hloc (finite_reachBall hloc x M).toFinset) x M L p := by + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + have he : finiteBadGoodnessProbability G Q x M L p = + finiteEventPolynomial Q {ω | CappedBadGoodness G ω x M L} p := by + apply bernoulliPolynomial_congr + intro ω hω + simp only [Set.mem_ofPred_eq,cappedBadGoodness_finset_iff G Q ω hω] + change _ = finiteBadGoodnessProbability G Q x M L p + rw [he,finiteEventPolynomial_restrict] + congr 1 + ext ω + exact cappedBadGoodness_local G hloc x M L ω + +theorem incident_filter_card_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (x : V) : (Q.filter fun e => x ∈ G e).card ≤ degree G x := by + let : Fintype (Step G x) := (finite_steps G hloc x).fintype + have hex (e : {e // e ∈ Q.filter fun e => x ∈ G e}) : ∃ y, G e.val = s(x,y) := + Sym2.mem_iff_exists.mp (Finset.mem_filter.mp e.property).2 + let f : {e // e ∈ Q.filter fun e => x ∈ G e} → Step G x := + fun e => ⟨(e.val,(hex e).choose),(hex e).choose_spec⟩ + have hf : Function.Injective f := by + intro a b hab + exact Subtype.ext (congrArg (fun z : Step G x => z.val.1) hab) + simpa only [degree,Nat.card_eq_fintype_card,Fintype.card_coe] using Fintype.card_le_of_injective f hf + + + +theorem bad_goodness_stretched_exp [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (pbar : unitInterval) (hpbar : (pbar:ℝ) < 1) (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) : + ∀ᶠ M : ℕ in Filter.atTop, ∀ x : V, ∀ p : unitInterval, p ≤ pbar → + (law p).real {ω | CappedBadGoodness G ω x M ((M:ℝ)^(1/2+ε))} ≤ + Real.exp (-(M:ℝ)^ε) := by + obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt + filter_upwards [finite_bad_goodness_stretched_exp G d hd pbar hpbar ε hε hε1] with M hM + intro x p hp + rw [bad_goodness_law_eq_finite G hloc] + exact hM _ x (fun v => (incident_filter_card_le_degree G hloc _ v).trans (hdeg v)) p hp + +end GoodnessLaw + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Exploration/Marked.lean b/lean/OAI/Probability/UnimodularPercolation/Exploration/Marked.lean index 11f6c1836b4f2f6831ccc2786ba797ddbbd9827b..cd25034ecb04e701bb7304fb46ae53851b136285 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Exploration/Marked.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Exploration/Marked.lean @@ -1,1226 +1,1226 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Criticality.Sharpness - -namespace OAI - -/-! Marked decision trees, graph searches and pivotal geometry. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section MarkedExploration - - -theorem centered_bernoulli_mgf_le (p : unitInterval) (lam : ℝ) : - (1-(p:ℝ))*Real.exp (-lam*p) + p*Real.exp (lam*(1-p)) ≤ Real.exp (lam^2/8) := by - let X : Bool → ℝ := fun b => if b then 1-(p:ℝ) else -(p:ℝ) - have hb : ∀ᵐ b ∂bernoulliMeasure true false p, X b ∈ Set.Icc (-(p:ℝ)) (1-p) := by - filter_upwards with b - cases b <;> simp [X] - have hc : ∫ b, X b ∂bernoulliMeasure true false p = 0 := by - rw [integral_bernoulliMeasure] - simp [X] - ring - have hg := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero - (μ := bernoulliMeasure true false p) (X := X) - (Measurable.of_discrete.aemeasurable) hb hc - have hh := hg.mgf_le lam - simp only [mgf,integral_bernoulliMeasure] at hh - norm_num [X,sub_neg_eq_add,sub_add_cancel,smul_eq_mul] at hh - rw [show (1/4:ℝ)*lam^2/2 = lam^2/8 by ring] at hh - simpa only [neg_mul,add_comm] using hh - - -inductive ProbeTree where - | done (success : Bool) - | edge (closed open_ : ProbeTree) - | mark (unmarked marked : ProbeTree) - -namespace ProbeTree - -@[reducible] def Leaf : ProbeTree → Type - | .done _ => Unit - | .edge t₀ t₁ => Leaf t₀ ⊕ Leaf t₁ - | .mark t₀ t₁ => Leaf t₀ ⊕ Leaf t₁ - -instance leafFintype : (t : ProbeTree) → Fintype t.Leaf - | .done _ => inferInstanceAs (Fintype Unit) - | .edge t₀ t₁ => @instFintypeSum _ _ (leafFintype t₀) (leafFintype t₁) - | .mark t₀ t₁ => @instFintypeSum _ _ (leafFintype t₀) (leafFintype t₁) - -noncomputable def weight (p h : ℝ) : (t : ProbeTree) → t.Leaf → ℝ - | .done _, _ => 1 - | .edge t₀ _, .inl l => (1-p)*weight p h t₀ l - | .edge _ t₁, .inr l => p*weight p h t₁ l - | .mark t₀ _, .inl l => (1-h)*weight p h t₀ l - | .mark _ t₁, .inr l => h*weight p h t₁ l - -noncomputable def score (p : ℝ) : (t : ProbeTree) → t.Leaf → ℝ - | .done _, _ => 0 - | .edge t₀ _, .inl l => score p t₀ l-p - | .edge _ t₁, .inr l => score p t₁ l+(1-p) - | .mark t₀ _, .inl l => score p t₀ l - | .mark _ t₁, .inr l => score p t₁ l - -def queries : (t : ProbeTree) → t.Leaf → ℕ - | .done _, _ => 0 - | .edge t₀ _, .inl l => queries t₀ l+1 - | .edge _ t₁, .inr l => queries t₁ l+1 - | .mark t₀ _, .inl l => queries t₀ l - | .mark _ t₁, .inr l => queries t₁ l - -@[reducible] def outcome : (t : ProbeTree) → t.Leaf → Bool - | .done b, _ => b - | .edge t₀ _, .inl l => outcome t₀ l - | .edge _ t₁, .inr l => outcome t₁ l - | .mark t₀ _, .inl l => outcome t₀ l - | .mark _ t₁, .inr l => outcome t₁ l - -lemma weight_nonneg (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : - 0 ≤ weight p h t l := by - induction t with - | done b => exact zero_le_one - | edge t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => exact mul_nonneg (sub_nonneg.mpr p.2.2) (ih₀ l) - | inr l => exact mul_nonneg p.2.1 (ih₁ l) - | mark t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => exact mul_nonneg (sub_nonneg.mpr h.2.2) (ih₀ l) - | inr l => exact mul_nonneg h.2.1 (ih₁ l) - -lemma sum_weight (p h : ℝ) (t : ProbeTree) : ∑ l, weight p h t l = 1 := by - induction t with - | done b => change (∑ _ : Unit, (1:ℝ)) = 1; simp - | edge t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 1 - simp only [Fintype.sum_sum_type,weight,← Finset.mul_sum,ih₀,ih₁] - ring - | mark t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 1 - simp only [Fintype.sum_sum_type,weight,← Finset.mul_sum,ih₀,ih₁] - ring - - -theorem score_mgf (p h : unitInterval) (lam : ℝ) (t : ProbeTree) : - ∑ l, weight p h t l * Real.exp (lam*score p t l-lam^2*(queries t l : ℝ)/8) ≤ 1 := by - induction t with - | done b => change (∑ l : Unit, _) ≤ (1:ℝ); simp [weight,score,queries] - | edge t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) ≤ (1:ℝ) - rw [Fintype.sum_sum_type] - have h₀ (l : t₀.Leaf) : - weight p h (.edge t₀ t₁) (.inl l) * - Real.exp (lam*score p (.edge t₀ t₁) (.inl l)-lam^2*(queries (.edge t₀ t₁) (.inl l):ℝ)/8) = - ((1-(p:ℝ))*Real.exp (-lam*p-lam^2/8)) * - (weight p h t₀ l * Real.exp (lam*score p t₀ l-lam^2*(queries t₀ l:ℝ)/8)) := by - simp only [weight,score,queries,Nat.cast_add,Nat.cast_one] - rw [show lam*(score p t₀ l-p)-lam^2*((queries t₀ l:ℝ)+1)/8 = - (-lam*p-lam^2/8)+(lam*score p t₀ l-lam^2*(queries t₀ l:ℝ)/8) by ring,Real.exp_add] - ring - have h₁ (l : t₁.Leaf) : - weight p h (.edge t₀ t₁) (.inr l) * - Real.exp (lam*score p (.edge t₀ t₁) (.inr l)-lam^2*(queries (.edge t₀ t₁) (.inr l):ℝ)/8) = - ((p:ℝ)*Real.exp (lam*(1-p)-lam^2/8)) * - (weight p h t₁ l * Real.exp (lam*score p t₁ l-lam^2*(queries t₁ l:ℝ)/8)) := by - simp only [weight,score,queries,Nat.cast_add,Nat.cast_one] - rw [show lam*(score p t₁ l+(1-p))-lam^2*((queries t₁ l:ℝ)+1)/8 = - (lam*(1-p)-lam^2/8)+(lam*score p t₁ l-lam^2*(queries t₁ l:ℝ)/8) by ring,Real.exp_add] - ring - simp only [h₀,h₁,← Finset.mul_sum] - have hc₀ : 0 ≤ (1-(p:ℝ))*Real.exp (-lam*p-lam^2/8) := - mul_nonneg (sub_nonneg.mpr p.2.2) (Real.exp_pos _).le - have hc₁ : 0 ≤ (p:ℝ)*Real.exp (lam*(1-p)-lam^2/8) := - mul_nonneg p.2.1 (Real.exp_pos _).le - calc - _ ≤ (1-(p:ℝ))*Real.exp (-lam*p-lam^2/8) + p*Real.exp (lam*(1-p)-lam^2/8) := by - simpa using add_le_add (mul_le_mul_of_nonneg_left ih₀ hc₀) (mul_le_mul_of_nonneg_left ih₁ hc₁) - _ = ((1-(p:ℝ))*Real.exp (-lam*p)+p*Real.exp (lam*(1-p))) / Real.exp (lam^2/8) := by - simp only [Real.exp_sub]; ring - _ ≤ 1 := (div_le_one (Real.exp_pos _)).mpr (centered_bernoulli_mgf_le p lam) - | mark t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) ≤ (1:ℝ) - simp only [Fintype.sum_sum_type,weight,score,queries,mul_assoc,← Finset.mul_sum] - calc - _ ≤ (1-(h:ℝ))*1+(h:ℝ)*1 := - add_le_add (mul_le_mul_of_nonneg_left ih₀ (sub_nonneg.mpr h.2.2)) - (mul_le_mul_of_nonneg_left ih₁ h.2.1) - _ = 1 := by ring - -noncomputable def successWeight (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : ℝ := - if outcome t l then weight p h t l else 0 - -noncomputable def successMass (p h : ℝ) (t : ProbeTree) : ℝ := - ∑ l, successWeight p h t l - -noncomputable def successScore (p h : ℝ) (t : ProbeTree) : ℝ := - ∑ l, successWeight p h t l * score p t l - -noncomputable def successQueries (p h : ℝ) (t : ProbeTree) : ℝ := - ∑ l, successWeight p h t l * queries t l - -lemma successWeight_nonneg (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : - 0 ≤ successWeight p h t l := by - unfold successWeight - split <;> simp_all [weight_nonneg] - -lemma successWeight_le (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : - successWeight p h t l ≤ weight p h t l := by - unfold successWeight - split - · exact le_rfl - · exact weight_nonneg p h t l - -lemma successMass_nonneg (p h : unitInterval) (t : ProbeTree) : 0 ≤ successMass p h t := - Finset.sum_nonneg fun _ _ => successWeight_nonneg p h t _ - -lemma successMass_le_one (p h : unitInterval) (t : ProbeTree) : successMass p h t ≤ 1 := by - rw [← sum_weight p h t] - exact Finset.sum_le_sum fun _ _ => successWeight_le p h t _ - -lemma successQueries_nonneg (p h : unitInterval) (t : ProbeTree) : 0 ≤ successQueries p h t := - Finset.sum_nonneg fun _ _ => mul_nonneg (successWeight_nonneg p h t _) (Nat.cast_nonneg _) - - -theorem conditional_score_bound (p h : unitInterval) (t : ProbeTree) - (hH : 0 < successMass p h t) (lam : ℝ) : - lam*(successScore p h t / successMass p h t) ≤ - Real.log (1/successMass p h t) + lam^2/8*(successQueries p h t / successMass p h t) := by - let H := successMass p h t - let w : t.Leaf → ℝ := fun l => successWeight p h t l / H - let X : t.Leaf → ℝ := fun l => lam*score p t l-lam^2*(queries t l : ℝ)/8 - have hw : ∀ l ∈ (Finset.univ : Finset t.Leaf), 0 ≤ w l := - fun l _ => div_nonneg (successWeight_nonneg p h t l) hH.le - have hw1 : ∑ l, w l = 1 := by - simp only [w,← Finset.sum_div] - exact div_self hH.ne' - have hJ := convexOn_exp.map_sum_le hw hw1 (fun _ _ => Set.mem_univ _ : ∀ l ∈ - (Finset.univ : Finset t.Leaf), X l ∈ Set.univ) - simp only [smul_eq_mul] at hJ - have hsum : ∑ l, w l * X l = lam*(successScore p h t/H)- - lam^2/8*(successQueries p h t/H) := by - simp only [w,X,successScore,successQueries,Finset.sum_div,Finset.mul_sum,← Finset.sum_sub_distrib] - apply Finset.sum_congr rfl - intro l _ - ring - have he : ∑ l, w l * Real.exp (X l) ≤ 1/H := by - calc - _ = (∑ l, successWeight p h t l * Real.exp (X l))/H := by - simp only [Finset.sum_div,w]; apply Finset.sum_congr rfl; intro l _; ring - _ ≤ (∑ l, weight p h t l * Real.exp (X l))/H := by - apply div_le_div_of_nonneg_right _ hH.le - exact Finset.sum_le_sum fun l _ => mul_le_mul_of_nonneg_right (successWeight_le p h t l) - (Real.exp_pos _).le - _ ≤ 1/H := div_le_div_of_nonneg_right (score_mgf p h lam t) hH.le - rw [hsum] at hJ - have hb := (Real.le_log_iff_exp_le (one_div_pos.mpr hH)).mpr (hJ.trans he) - linarith - -noncomputable def dweight (p h : ℝ) : (t : ProbeTree) → t.Leaf → ℝ - | .done _, _ => 0 - | .edge t₀ _, .inl l => -weight p h t₀ l+(1-p)*dweight p h t₀ l - | .edge _ t₁, .inr l => weight p h t₁ l+p*dweight p h t₁ l - | .mark t₀ _, .inl l => (1-h)*dweight p h t₀ l - | .mark _ t₁, .inr l => h*dweight p h t₁ l - -lemma hasDerivAt_weight (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : - HasDerivAt (fun q => weight q h t l) (dweight p h t l) p := by - induction t with - | done b => exact hasDerivAt_const p 1 - | edge t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => convert ((hasDerivAt_const p 1).sub (hasDerivAt_id p)).mul (ih₀ l) using 1 <;> try rfl - simp [dweight] - | inr l => convert (hasDerivAt_id p).mul (ih₁ l) using 1 <;> try rfl - simp [dweight] - | mark t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => exact (ih₀ l).const_mul (1-h) - | inr l => exact (ih₁ l).const_mul h - -lemma score_eq_derivative (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : - p*(1-p)*dweight p h t l = weight p h t l * score p t l := by - induction t with - | done b => simp [dweight,weight,score] - | edge t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => dsimp [dweight,weight,score]; linear_combination (1-p)*(ih₀ l) - | inr l => dsimp [dweight,weight,score]; linear_combination p*(ih₁ l) - | mark t₀ t₁ ih₀ ih₁ => - cases l with - | inl l => dsimp [dweight,weight,score]; linear_combination (1-h)*(ih₀ l) - | inr l => dsimp [dweight,weight,score]; linear_combination h*(ih₁ l) - - -theorem successScore_eq_deriv (p h : ℝ) (t : ProbeTree) : - successScore p h t = p*(1-p)*deriv (fun q => successMass q h t) p := by - have hd : HasDerivAt (fun q => successMass q h t) - (∑ l, if outcome t l then dweight p h t l else 0) p := by - have hh (l : t.Leaf) (_ : l ∈ (Finset.univ : Finset t.Leaf)) : - HasDerivAt (fun q => successWeight q h t l) (if outcome t l then dweight p h t l else 0) p := by - by_cases hl : outcome t l - · simpa [successWeight,hl] using hasDerivAt_weight p h t l - · simpa [successWeight,hl] using hasDerivAt_const p (0:ℝ) - simpa only [successMass,Finset.sum_apply] using HasDerivAt.fun_sum hh - rw [hd.deriv,Finset.mul_sum] - apply Finset.sum_congr rfl - intro l _ - by_cases hl : outcome t l - · simpa [successWeight,hl] using (score_eq_derivative p h t l).symm - · simp [successWeight,hl] - - -inductive IsMarkSearch : ProbeTree → Prop - | fail : IsMarkSearch (.done false) - | edge {t₀ t₁} : IsMarkSearch t₀ → IsMarkSearch t₁ → IsMarkSearch (.edge t₀ t₁) - | mark {t₀} : IsMarkSearch t₀ → IsMarkSearch (.mark t₀ (.done true)) - -def marks : (t : ProbeTree) → t.Leaf → ℕ - | .done _, _ => 0 - | .edge t₀ _, .inl l => marks t₀ l - | .edge _ t₁, .inr l => marks t₁ l - | .mark t₀ _, .inl l => marks t₀ l+1 - | .mark _ t₁, .inr l => marks t₁ l+1 - -noncomputable def successMarks (p h : ℝ) (t : ProbeTree) : ℝ := - ∑ l, successWeight p h t l * marks t l - -lemma successMass_edge (p h : ℝ) (t₀ t₁ : ProbeTree) : - successMass p h (.edge t₀ t₁) = (1-p)*successMass p h t₀+p*successMass p h t₁ := by - simp only [successMass,Fintype.sum_sum_type,successWeight,outcome,weight,Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp - -lemma successMass_mark (p h : ℝ) (t₀ t₁ : ProbeTree) : - successMass p h (.mark t₀ t₁) = (1-h)*successMass p h t₀+h*successMass p h t₁ := by - simp only [successMass,Fintype.sum_sum_type,successWeight,outcome,weight,Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp - -@[simp] lemma successMass_done (p h : ℝ) (b : Bool) : - successMass p h (.done b) = if b then 1 else 0 := by - cases b <;> simp [successMass,successWeight,outcome,weight] - -lemma successMarks_edge (p h : ℝ) (t₀ t₁ : ProbeTree) : - successMarks p h (.edge t₀ t₁) = (1-p)*successMarks p h t₀+p*successMarks p h t₁ := by - simp only [successMarks,Fintype.sum_sum_type,successWeight,outcome,weight,marks,Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp [mul_assoc] - -lemma successMarks_mark (p h : ℝ) (t₀ t₁ : ProbeTree) : - successMarks p h (.mark t₀ t₁) = - (1-h)*(successMarks p h t₀+successMass p h t₀) + - h*(successMarks p h t₁+successMass p h t₁) := by - simp only [successMarks,successMass,Fintype.sum_sum_type,successWeight,outcome,weight,marks, - Nat.cast_add,Nat.cast_one,← Finset.sum_add_distrib,Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split_ifs <;> ring - -@[simp] lemma successMarks_done (p h : ℝ) (b : Bool) : successMarks p h (.done b) = 0 := by - simp [successMarks,marks] - - -theorem marks_times_parameter_le (p h : unitInterval) {t : ProbeTree} (ht : IsMarkSearch t) : - (h:ℝ)*successMarks p h t ≤ successMass p h t := by - induction ht with - | fail => simp - | @edge t₀ t₁ _ _ ih₀ ih₁ => - rw [successMarks_edge,successMass_edge] - nlinarith [mul_nonneg (sub_nonneg.mpr p.2.2) (sub_nonneg.mpr ih₀), - mul_nonneg p.2.1 (sub_nonneg.mpr ih₁)] - | @mark t₀ _ ih => - rw [successMarks_mark,successMass_mark] - simp only [successMarks_done,successMass_done,ite_true,zero_add,mul_one] - have hn := mul_nonneg (mul_nonneg h.2.1 (sub_nonneg.mpr h.2.2)) - (sub_nonneg.mpr (successMass_le_one p h t₀)) - nlinarith [mul_nonneg (sub_nonneg.mpr h.2.2) (sub_nonneg.mpr ih)] - -theorem successQueries_times_parameter_le (p h : unitInterval) {t : ProbeTree} - (ht : IsMarkSearch t) (d : ℕ) (hcost : ∀ l, queries t l ≤ d*marks t l) : - (h:ℝ)*successQueries p h t ≤ d*successMass p h t := by - have hs : successQueries p h t ≤ d*successMarks p h t := by - simp only [successQueries,successMarks,Finset.mul_sum] - apply Finset.sum_le_sum - intro l _ - calc - _ ≤ successWeight p h t l * ((d:ℝ)*marks t l) := - mul_le_mul_of_nonneg_left (by exact_mod_cast hcost l) (successWeight_nonneg p h t l) - _ = _ := by ring - calc - _ ≤ (h:ℝ)*(d*successMarks p h t) := mul_le_mul_of_nonneg_left hs h.2.1 - _ = d*((h:ℝ)*successMarks p h t) := by ring - _ ≤ d*successMass p h t := mul_le_mul_of_nonneg_left (marks_times_parameter_le p h ht) - (Nat.cast_nonneg _) - - -theorem marked_score_bound (p h : unitInterval) (hh : 0 < (h:ℝ)) - {t : ProbeTree} (ht : IsMarkSearch t) (d : ℕ) - (hcost : ∀ l, queries t l ≤ d*marks t l) (hroot : (h:ℝ) ≤ successMass p h t) - (lam : ℝ) : - lam*(successScore p h t / successMass p h t) ≤ - Real.log (1/(h:ℝ)) + lam^2*(d:ℝ)/(8*h) := by - have hH := hh.trans_le hroot - have hlog : Real.log (1/successMass p h t) ≤ Real.log (1/(h:ℝ)) := - Real.log_le_log (one_div_pos.mpr hH) (one_div_le_one_div_of_le hh hroot) - have hQ : successQueries p h t / successMass p h t ≤ (d:ℝ)/h := by - apply (div_le_div_iff₀ hH hh).mpr - simpa [mul_comm] using successQueries_times_parameter_le p h ht d hcost - calc - _ ≤ Real.log (1/successMass p h t)+lam^2/8*(successQueries p h t/successMass p h t) := - conditional_score_bound p h t hH lam - _ ≤ Real.log (1/(h:ℝ))+lam^2/8*((d:ℝ)/h) := - add_le_add hlog (mul_le_mul_of_nonneg_left hQ (by positivity)) - _ = _ := by ring - -end ProbeTree -end MarkedExploration - -section LabelledExploration -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - -inductive LabelledTree (V E : Type*) where - | done (success : Bool) - | edge (e : E) (closed opened : LabelledTree V E) - | mark (v : V) (unmarked marked : LabelledTree V E) - -namespace LabelledTree - -def forget : LabelledTree V E → ProbeTree - | .done b => .done b - | .edge _ t₀ t₁ => .edge t₀.forget t₁.forget - | .mark _ t₀ t₁ => .mark t₀.forget t₁.forget - -@[reducible] noncomputable def eval (ω : Finset E) (m : Finset V) : LabelledTree V E → Bool - | .done b => b - | .edge e t₀ t₁ => if e ∈ ω then eval ω m t₁ else eval ω m t₀ - | .mark v t₀ t₁ => if v ∈ m then eval ω m t₁ else eval ω m t₀ - -def Valid (Q : Finset E) (F : Finset V) : LabelledTree V E → Prop - | .done _ => True - | .edge e t₀ t₁ => e ∈ Q ∧ Valid (Q.erase e) F t₀ ∧ Valid (Q.erase e) F t₁ - | .mark v t₀ t₁ => v ∈ F ∧ Valid Q (F.erase v) t₀ ∧ Valid Q (F.erase v) t₁ - -theorem eval_congr (t : LabelledTree V E) {Q : Finset E} {F : Finset V} - (ht : Valid Q F t) {ω ω' : Finset E} {m m' : Finset V} - (hω : ∀ e ∈ Q, e ∈ ω ↔ e ∈ ω') (hm : ∀ v ∈ F, v ∈ m ↔ v ∈ m') : - t.eval ω m = t.eval ω' m' := by - induction t generalizing Q F with - | done b => rfl - | edge e t₀ t₁ ih₀ ih₁ => - obtain ⟨he,h₀,h₁⟩ := ht - simp only [eval,hω e he] - split - · exact ih₁ h₁ (fun a ha => hω a (Finset.mem_of_mem_erase ha)) hm - · exact ih₀ h₀ (fun a ha => hω a (Finset.mem_of_mem_erase ha)) hm - | mark v t₀ t₁ ih₀ ih₁ => - obtain ⟨hv,h₀,h₁⟩ := ht - simp only [eval,hm v hv] - split - · exact ih₁ h₁ hω (fun a ha => hm a (Finset.mem_of_mem_erase ha)) - · exact ih₀ h₀ hω (fun a ha => hm a (Finset.mem_of_mem_erase ha)) - -lemma eval_insert_edge (t : LabelledTree V E) {Q : Finset E} {F : Finset V} - (ht : Valid Q F t) {e : E} (he : e ∉ Q) (ω : Finset E) (m : Finset V) : - t.eval (insert e ω) m = t.eval ω m := by - apply eval_congr t ht - · intro a ha - simp [show a ≠ e from fun hh => he (hh ▸ ha)] - · simp - -lemma eval_insert_mark (t : LabelledTree V E) {Q : Finset E} {F : Finset V} - (ht : Valid Q F t) {v : V} (hv : v ∉ F) (ω : Finset E) (m : Finset V) : - t.eval ω (insert v m) = t.eval ω m := by - apply eval_congr t ht - · simp - · intro a ha - simp [show a ≠ v from fun hh => hv (hh ▸ ha)] - -end LabelledTree - -theorem bernoulliPolynomial_affine (s : Finset E) (f g : Finset E → ℝ) (a b p : ℝ) : - bernoulliPolynomial s (fun t => a*f t+b*g t) p = - a*bernoulliPolynomial s f p+b*bernoulliPolynomial s g p := by - simp only [bernoulliPolynomial,add_mul,Finset.sum_add_distrib,Finset.mul_sum] - congr 1 <;> apply Finset.sum_congr rfl <;> intro t _ <;> ring - -namespace LabelledTree - - -theorem expectation_eq (t : LabelledTree V E) {Q : Finset E} {F : Finset V} - (ht : Valid Q F t) (p h : ℝ) : - bernoulliPolynomial Q (fun ω => bernoulliPolynomial F - (fun m => if t.eval ω m then 1 else 0) h) p = - ProbeTree.successMass p h t.forget := by - induction t generalizing Q F with - | done b => - cases b <;> simp [eval,forget,ProbeTree.successMass_done,bernoulliPolynomial_const] - | edge e t₀ t₁ ih₀ ih₁ => - obtain ⟨he,h₀,h₁⟩ := ht - conv_lhs => rw [← Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] - have hc : bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (fun m => if (edge e t₀ t₁).eval ω m then 1 else 0) h) p = - bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (fun m => if t₀.eval ω m then 1 else 0) h) p := by - apply bernoulliPolynomial_congr - intro ω hω - have heω : e ∉ ω := fun hh => Finset.notMem_erase e Q (hω hh) - simp only [eval,heω,ite_false] - have ho : bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (fun m => if (edge e t₀ t₁).eval (insert e ω) m then 1 else 0) h) p = - bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (fun m => if t₁.eval ω m then 1 else 0) h) p := by - apply bernoulliPolynomial_congr - intro ω _ - simp only [eval,Finset.mem_insert_self,ite_true] - apply bernoulliPolynomial_congr - intro m _ - rw [eval_insert_edge t₁ h₁ (Finset.notMem_erase e Q)] - rw [hc,ho,ih₀ h₀,ih₁ h₁,forget,ProbeTree.successMass_edge] - | mark v t₀ t₁ ih₀ ih₁ => - obtain ⟨hv,h₀,h₁⟩ := ht - have hh : ∀ ω, bernoulliPolynomial F - (fun m => if (mark v t₀ t₁).eval ω m then 1 else 0) h = - (1-h)*bernoulliPolynomial (F.erase v) (fun m => if t₀.eval ω m then 1 else 0) h + - h*bernoulliPolynomial (F.erase v) (fun m => if t₁.eval ω m then 1 else 0) h := by - intro ω - conv_lhs => rw [← Finset.insert_erase hv] - rw [bernoulliPolynomial_insert _ v (Finset.notMem_erase v F)] - congr 1 - · congr 1 - apply bernoulliPolynomial_congr - intro m hm - have hvm : v ∉ m := fun hh => Finset.notMem_erase v F (hm hh) - simp only [eval,hvm,ite_false] - · congr 1 - apply bernoulliPolynomial_congr - intro m _ - simp only [eval,Finset.mem_insert_self,ite_true] - rw [eval_insert_mark t₁ h₁ (Finset.notMem_erase v F)] - simp_rw [hh] - rw [bernoulliPolynomial_affine,ih₀ h₀,ih₁ h₁,forget,ProbeTree.successMass_mark] - -end LabelledTree -end LabelledExploration - -section GraphMarkedSearch -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - - -def SearchCrossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Prop := - ∃ t : E × V × V, t.1 ∈ Q ∧ t.2.1 ∈ R ∧ t.2.2 ∉ R ∧ G t.1 = s(t.2.1,t.2.2) - -noncomputable def searchCrossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (h : SearchCrossing G Q R) : E × V × V := Classical.choose h - -theorem searchCrossing_spec (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (h : SearchCrossing G Q R) : - (searchCrossing G Q R h).1 ∈ Q ∧ (searchCrossing G Q R h).2.1 ∈ R ∧ - (searchCrossing G Q R h).2.2 ∉ R ∧ - G (searchCrossing G Q R h).1 = s((searchCrossing G Q R h).2.1,(searchCrossing G Q R h).2.2) := - Classical.choose_spec h - - -def SearchAvailable (G : BondGraph V E) (Q : Finset E) (R F : Finset V) : Prop := - ∀ e ∈ Q, ∀ v ∈ G e, v ∈ R ∨ v ∈ F - -noncomputable def clusterSearch (G : BondGraph V E) : ℕ → Finset E → Finset V → LabelledTree V E - | 0, _, _ => .done false - | n+1, Q, R => - if hc : SearchCrossing G Q R then - let t := searchCrossing G Q R hc - .edge t.1 (clusterSearch G n (Q.erase t.1) R) - (.mark t.2.2 (clusterSearch G n (Q.erase t.1) (insert t.2.2 R)) (.done true)) - else .done false - -lemma searchAvailable_erase (G : BondGraph V E) {Q : Finset E} {R F : Finset V} - (h : SearchAvailable G Q R F) (e : E) : SearchAvailable G (Q.erase e) R F := - fun _ ha _ hv => h _ (Finset.mem_of_mem_erase ha) _ hv - -lemma searchAvailable_discover (G : BondGraph V E) {Q : Finset E} {R F : Finset V} - (h : SearchAvailable G Q R F) (e : E) (v : V) : - SearchAvailable G (Q.erase e) (insert v R) (F.erase v) := by - intro a ha b hb - rcases h a (Finset.mem_of_mem_erase ha) b hb with hb | hb - · exact Or.inl (Finset.mem_insert_of_mem hb) - · by_cases hbe : b = v - · exact Or.inl (by simp [hbe]) - · exact Or.inr (Finset.mem_erase.mpr ⟨hbe,hb⟩) - -theorem clusterSearch_valid (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R F : Finset V) - (ha : SearchAvailable G Q R F) : LabelledTree.Valid Q F (clusterSearch G n Q R) := by - induction n generalizing Q R F with - | zero => trivial - | succ n ih => - simp only [clusterSearch] - split_ifs with hc - · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc - refine ⟨he,ih _ _ _ (searchAvailable_erase G ha _),?_,?_,trivial⟩ - · exact (ha _ he _ (by rw [hends]; simp)).resolve_left hw - · exact ih _ _ _ (searchAvailable_discover G ha _ _) - · trivial - -theorem clusterSearch_markSearch (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) : - ProbeTree.IsMarkSearch (clusterSearch G n Q R).forget := by - induction n generalizing Q R with - | zero => exact .fail - | succ n ih => - simp only [clusterSearch] - split_ifs - · exact .edge (ih _ _) (.mark (ih _ _)) - · exact .fail - - -def SeedMarked (G : BondGraph V E) (ω : Set E) (R m : Finset V) : Prop := - ∃ a ∈ R, ∃ b ∈ m, Conn G ω a b - -theorem seedMarked_insert_edge (G : BondGraph V E) (ω : Set E) (R m : Finset V) - (e : E) (a b : V) (ha : a ∈ R) (he : G e = s(a,b)) : - SeedMarked G (insert e ω) R m ↔ SeedMarked G ω (insert b R) m := by - constructor - · rintro ⟨x,hx,y,hy,hxy⟩ - rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | ⟨_,h⟩ | ⟨_,h⟩ - · exact ⟨x,Finset.mem_insert_of_mem hx,y,hy,h⟩ - · exact ⟨b,by simp,y,hy,h⟩ - · exact ⟨a,Finset.mem_insert_of_mem ha,y,hy,h⟩ - · rintro ⟨x,hx,y,hy,hxy⟩ - rcases Finset.mem_insert.mp hx with rfl | hx - · refine ⟨a,ha,y,hy,?_⟩ - exact (Relation.ReflTransGen.single ⟨e,Set.mem_insert e ω,he⟩).trans - (conn_mono G (Set.subset_insert e ω) hxy) - · exact ⟨x,hx,y,hy,conn_mono G (Set.subset_insert e ω) hxy⟩ - -theorem seedMarked_false_of_no_crossing (G : BondGraph V E) (Q : Finset E) (R m : Finset V) - (hc : ¬ SearchCrossing G Q R) (hm : Disjoint R m) (ω : Finset E) (hω : ω ⊆ Q) : - ¬ SeedMarked G (ω : Set E) R m := by - rintro ⟨a,ha,b,hb,hab⟩ - have hclosed : ∀ x ∈ R, ∀ y, Conn G (ω : Set E) x y → y ∈ R := by - intro x hx y hxy - induction hxy with - | refl => exact hx - | @tail v w hv hw ih => - by_contra hn - obtain ⟨e,he,hevw⟩ := hw - exact hc ⟨(e,v,w),hω he,ih,hn,hevw⟩ - exact Finset.disjoint_left.mp hm (hclosed a ha b hab) hb - - -theorem clusterSearch_correct (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R F m : Finset V) - (hn : Q.card ≤ n) (ha : SearchAvailable G Q R F) (hm : Disjoint R m) - (ω : Finset E) (hω : ω ⊆ Q) : - (clusterSearch G n Q R).eval ω m = true ↔ SeedMarked G (ω : Set E) R m := by - induction n generalizing Q R F ω with - | zero => - have hQ : Q = ∅ := Finset.card_eq_zero.mp (by omega) - have hωe : ω = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (by simp_all) - simp only [clusterSearch,LabelledTree.eval,Bool.false_eq_true,false_iff] - exact seedMarked_false_of_no_crossing G Q R m (by simp [SearchCrossing,hQ]) hm ω hω - | succ n ih => - simp only [clusterSearch] - split_ifs with hc - · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc - have hcard : (Q.erase (searchCrossing G Q R hc).1).card ≤ n := by - rw [Finset.card_erase_of_mem he]; omega - simp only [LabelledTree.eval] - by_cases heω : (searchCrossing G Q R hc).1 ∈ ω - · simp only [heω,ite_true] - rw [← Finset.insert_erase heω,Finset.coe_insert, - seedMarked_insert_edge G _ R m _ _ _ hv hends] - by_cases hwm : (searchCrossing G Q R hc).2.2 ∈ m - · simp only [hwm,ite_true,true_iff] - exact ⟨_,by simp,_,hwm,conn_refl G _ _⟩ - · simp only [hwm,ite_false] - rw [LabelledTree.eval_insert_edge _ - (clusterSearch_valid G n _ _ (F.erase (searchCrossing G Q R hc).2.2) - (searchAvailable_discover G ha _ _)) (Finset.notMem_erase _ _)] - exact ih _ _ _ hcard (searchAvailable_discover G ha _ _) - (Finset.disjoint_insert_left.mpr ⟨hwm,hm⟩) (ω.erase (searchCrossing G Q R hc).1) - (Finset.erase_subset_erase _ hω) - · simp only [heω,ite_false] - exact ih _ _ _ hcard (searchAvailable_erase G ha _ ) hm ω - (fun e he => Finset.mem_erase.mpr ⟨fun heq => heω (heq ▸ he),hω he⟩) - · simp only [false_iff] - exact seedMarked_false_of_no_crossing G Q R m hc hm ω hω - -end GraphMarkedSearch - -section GraphSearchCost -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - -namespace ProbeTree - -def Budget (t : ProbeTree) (K d : ℕ) : Prop := ∀ l, queries t l ≤ K+d*marks t l - -lemma budget_done (b : Bool) (K d : ℕ) : Budget (.done b) K d := by - intro l - simp [queries,marks] - -lemma budget_mono {t : ProbeTree} {K L d : ℕ} (h : Budget t K d) (hKL : K ≤ L) : - Budget t L d := fun l => (h l).trans (Nat.add_le_add_right hKL _) - -lemma budget_edge {t₀ t₁ : ProbeTree} {K d : ℕ} (h₀ : Budget t₀ K d) (h₁ : Budget t₁ K d) : - Budget (.edge t₀ t₁) (K+1) d := by - intro l - cases l with - | inl l => simpa [queries,marks,Nat.add_right_comm] using Nat.add_le_add_right (h₀ l) 1 - | inr l => simpa [queries,marks,Nat.add_right_comm] using Nat.add_le_add_right (h₁ l) 1 - -lemma budget_mark {t₀ t₁ : ProbeTree} {K d : ℕ} - (h₀ : Budget t₀ (K+d) d) (h₁ : Budget t₁ (K+d) d) : - Budget (.mark t₀ t₁) K d := by - intro l - cases l with - | inl l => simpa [queries,marks,Nat.mul_add,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using h₀ l - | inr l => simpa [queries,marks,Nat.mul_add,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using h₁ l - -end ProbeTree - - -noncomputable def queryPotential (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Finset E := - Q.filter (fun e => ∃ v ∈ R, v ∈ G e) - -lemma queryPotential_erase (G : BondGraph V E) (Q : Finset E) (R : Finset V) (e : E) : - queryPotential G (Q.erase e) R = (queryPotential G Q R).erase e := by - ext a - simp [queryPotential,and_assoc] - -lemma queryPotential_insert (G : BondGraph V E) (Q : Finset E) (R : Finset V) (v : V) : - queryPotential G Q (insert v R) = queryPotential G Q R ∪ Q.filter (fun e => v ∈ G e) := by - ext a - simp [queryPotential,and_or_left,or_comm] - -lemma filtered_degree_erase (G : BondGraph V E) (Q : Finset E) (d : ℕ) - (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) (a : E) : - ∀ v, ((Q.erase a).filter (fun e => v ∈ G e)).card ≤ d := by - intro v - apply (Finset.card_le_card ?_).trans (hd v) - intro e he - exact Finset.mem_filter.mpr ⟨Finset.mem_of_mem_erase (Finset.mem_filter.mp he).1, - (Finset.mem_filter.mp he).2⟩ - -lemma queryPotential_discover_card (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (e : E) (v : V) (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - (queryPotential G (Q.erase e) (insert v R)).card ≤ - ((queryPotential G Q R).erase e).card+d := by - rw [queryPotential_insert,queryPotential_erase] - exact (Finset.card_union_le _ _).trans - (Nat.add_le_add_left (filtered_degree_erase G Q d hd e v) _) - - -theorem clusterSearch_budget (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) - (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - ProbeTree.Budget (clusterSearch G n Q R).forget (queryPotential G Q R).card d := by - induction n generalizing Q R with - | zero => exact ProbeTree.budget_done _ _ _ - | succ n ih => - simp only [clusterSearch] - split_ifs with hc - · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc - have hpot : (searchCrossing G Q R hc).1 ∈ queryPotential G Q R := by - exact Finset.mem_filter.mpr ⟨he,_,hv,by rw [hends]; simp⟩ - have hpos : 0 < (queryPotential G Q R).card := Finset.card_pos.mpr ⟨_,hpot⟩ - have hclosed := ih (Q.erase (searchCrossing G Q R hc).1) R - (filtered_degree_erase G Q d hd _) - have hopen := ih (Q.erase (searchCrossing G Q R hc).1) - (insert (searchCrossing G Q R hc).2.2 R) (filtered_degree_erase G Q d hd _) - rw [queryPotential_erase,Finset.card_erase_of_mem hpot] at hclosed - have hnew := queryPotential_discover_card G Q R (searchCrossing G Q R hc).1 - (searchCrossing G Q R hc).2.2 d hd - rw [Finset.card_erase_of_mem hpot] at hnew - have hh := ProbeTree.budget_edge hclosed - (ProbeTree.budget_mark (ProbeTree.budget_mono hopen hnew) (ProbeTree.budget_done true _ _)) - have hcadd : (queryPotential G Q R).card-1+1 = (queryPotential G Q R).card := by omega - simpa only [LabelledTree.forget,hcadd] using hh - · exact ProbeTree.budget_done _ _ _ - -noncomputable def searchVertices (G : BondGraph V E) (Q : Finset E) : Finset V := - Q.biUnion fun e => (G e).toFinset - -lemma mem_searchVertices (G : BondGraph V E) {Q : Finset E} {e : E} (he : e ∈ Q) - {v : V} (hv : v ∈ G e) : v ∈ searchVertices G Q := - Finset.mem_biUnion.mpr ⟨e,he,Sym2.mem_toFinset.mpr hv⟩ - -noncomputable def markedClusterTree (G : BondGraph V E) (Q : Finset E) (x : V) : LabelledTree V E := - .mark x (clusterSearch G Q.card Q {x}) (.done true) - -lemma markedClusterTree_available (G : BondGraph V E) (Q : Finset E) (x : V) : - SearchAvailable G Q {x} ((insert x (searchVertices G Q)).erase x) := by - intro e he v hv - by_cases hx : v = x - · exact Or.inl (by simpa using hx) - · exact Or.inr (Finset.mem_erase.mpr ⟨hx,Finset.mem_insert_of_mem (mem_searchVertices G he hv)⟩) - -theorem markedClusterTree_valid (G : BondGraph V E) (Q : Finset E) (x : V) : - LabelledTree.Valid Q (insert x (searchVertices G Q)) (markedClusterTree G Q x) := - ⟨by simp,clusterSearch_valid G _ _ _ _ (markedClusterTree_available G Q x),trivial⟩ - -theorem markedClusterTree_budget (G : BondGraph V E) (Q : Finset E) (x : V) - (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - ProbeTree.Budget (markedClusterTree G Q x).forget 0 d := by - have hh := clusterSearch_budget G Q.card Q {x} d hd - have hcost : (queryPotential G Q {x}).card ≤ 0+d := by simpa [queryPotential] using hd x - exact ProbeTree.budget_mark (ProbeTree.budget_mono hh hcost) (ProbeTree.budget_done true _ _) - -theorem markedClusterTree_correct (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : - (markedClusterTree G Q x).eval ω m = true ↔ ∃ y ∈ m, Conn G (ω : Set E) x y := by - simp only [markedClusterTree,LabelledTree.eval] - by_cases hxm : x ∈ m - · simp only [hxm,ite_true,true_iff] - exact ⟨x,hxm,conn_refl G _ x⟩ - · simp only [hxm,ite_false] - rw [clusterSearch_correct G Q.card Q {x} ((insert x (searchVertices G Q)).erase x) m - le_rfl (markedClusterTree_available G Q x) (by simpa) ω hω] - simp only [SeedMarked,Finset.mem_singleton,exists_eq_left] - -end GraphSearchCost - -section MarkedFirstMoment -attribute [local instance] Classical.propDecidable -attribute [local instance] Classical.decEq - -theorem quadratic_test_bound {z L B : ℝ} (hL : 0 ≤ L) (hB : 0 < B) - (h : ∀ lam : ℝ, lam*z ≤ L+lam^2*B) : z ≤ Real.sqrt (4*B*L) := by - have hh := h (z/(2*B)) - have hid : z/(2*B)*z-(z/(2*B))^2*B = z^2/(4*B) := by - field_simp - ring - have hs : z^2/(4*B) ≤ L := by rw [← hid]; linarith - have hs' := (div_le_iff₀ (by positivity : 0 < 4*B)).mp hs - have hn : 0 ≤ 4*B*L := by positivity - have hsq := Real.sq_sqrt hn - have hpos := Real.sqrt_nonneg (4*B*L) - nlinarith - - -noncomputable def markedConnectionPolynomial (G : BondGraph V E) (Q : Finset E) - (x : V) (h p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => bernoulliPolynomial (insert x (searchVertices G Q)) - (fun m => if ∃ y ∈ m, Conn G (ω : Set E) x y then 1 else 0) h) p - -theorem markedConnectionPolynomial_eq_tree (G : BondGraph V E) (Q : Finset E) - (x : V) (h p : ℝ) : - markedConnectionPolynomial G Q x h p = - ProbeTree.successMass p h (markedClusterTree G Q x).forget := by - rw [← LabelledTree.expectation_eq _ (markedClusterTree_valid G Q x) p h] - apply bernoulliPolynomial_congr - intro ω hω - apply bernoulliPolynomial_congr - intro m _ - simp only [markedClusterTree_correct G Q x ω hω m] - -theorem markedConnectionPolynomial_ge_mark (G : BondGraph V E) (Q : Finset E) - (x : V) (p h : unitInterval) : (h:ℝ) ≤ markedConnectionPolynomial G Q x h p := by - rw [markedConnectionPolynomial_eq_tree,markedClusterTree,LabelledTree.forget, - ProbeTree.successMass_mark] - simp only [LabelledTree.forget,ProbeTree.successMass_done,ite_true,mul_one] - exact le_add_of_nonneg_left (mul_nonneg (sub_nonneg.mpr h.2.2) - (ProbeTree.successMass_nonneg p h _)) - - -theorem markedConnection_derivative_bound (G : BondGraph V E) (Q : Finset E) - (x : V) (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) - (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - (p:ℝ)*deriv (markedConnectionPolynomial G Q x h) p ≤ - (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* - markedConnectionPolynomial G Q x h p := by - let t := (markedClusterTree G Q x).forget - have ht : ProbeTree.IsMarkSearch t := .mark (clusterSearch_markSearch G _ _ _) - have hcost : ∀ l, ProbeTree.queries t l ≤ d*ProbeTree.marks t l := by - simpa only [ProbeTree.Budget,zero_add] using markedClusterTree_budget G Q x d hdeg - have hroot : (h:ℝ) ≤ ProbeTree.successMass p h t := by - simpa only [markedConnectionPolynomial_eq_tree] using markedConnectionPolynomial_ge_mark G Q x p h - have hB : 0 < (d:ℝ)/(8*h) := div_pos (by exact_mod_cast hd) (by positivity) - have hL : 0 ≤ Real.log (1/(h:ℝ)) := Real.log_nonneg ((one_le_div hh).mpr h.2.2) - have htest (lam : ℝ) : lam*(ProbeTree.successScore p h t/ProbeTree.successMass p h t) ≤ - Real.log (1/(h:ℝ))+lam^2*((d:ℝ)/(8*h)) := by - simpa only [mul_div_assoc] using ProbeTree.marked_score_bound p h hh ht d hcost hroot lam - have hz := quadratic_test_bound hL hB htest - have hsqrt : Real.sqrt (4*((d:ℝ)/(8*h))*Real.log (1/(h:ℝ))) = - Real.sqrt ((d:ℝ)/2)*Real.sqrt (Real.log (1/(h:ℝ))/h) := by - rw [show 4*((d:ℝ)/(8*h))*Real.log (1/(h:ℝ)) = - ((d:ℝ)/2)*(Real.log (1/(h:ℝ))/h) by ring,Real.sqrt_mul (by positivity)] - rw [hsqrt] at hz - have hH : 0 < ProbeTree.successMass p h t := hh.trans_le hroot - have hscore := (div_le_iff₀ hH).mp hz - rw [ProbeTree.successScore_eq_deriv] at hscore - have heq : markedConnectionPolynomial G Q x h = fun q => ProbeTree.successMass q h t := - funext fun q => markedConnectionPolynomial_eq_tree G Q x h q - rw [heq] - have hq : 0 < 1-(p:ℝ) := sub_pos.mpr hp - calc - _ = ((p:ℝ)*(1-p)*deriv (fun q => ProbeTree.successMass q h t) p)/(1-p) := by - field_simp - _ ≤ (Real.sqrt ((d:ℝ)/2)*Real.sqrt (Real.log (1/(h:ℝ))/h)* - ProbeTree.successMass p h t)/(1-p) := div_le_div_of_nonneg_right hscore hq.le - _ = _ := by ring - -theorem bernoulliPolynomial_open_difference (s : Finset E) (e : E) (he : e ∈ s) - (f : Finset E → ℝ) (p : ℝ) : - bernoulliPolynomial s (fun t => if e ∈ t then f t-f (t.erase e) else 0) p = - p*bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by - conv_lhs => rw [← Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e s)] - have hclosed : bernoulliPolynomial (s.erase e) - (fun t => if e ∈ t then f t-f (t.erase e) else 0) p = 0 := by - rw [← bernoulliPolynomial_zero (s.erase e) p] - apply bernoulliPolynomial_congr - intro t ht - simp [show e ∉ t from fun hh => Finset.notMem_erase e s (ht hh)] - rw [hclosed,mul_zero,zero_add] - congr 1 - apply bernoulliPolynomial_congr - intro t ht - have het : e ∉ t := fun hh => Finset.notMem_erase e s (ht hh) - simp [het] - - -noncomputable def markedOpenPivotals (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (m : Finset V) : Finset E := - Q.filter fun e => e ∈ ω ∧ (∃ y ∈ m, Conn G (ω : Set E) x y) ∧ - ¬ ∃ y ∈ m, Conn G (ω.erase e : Set E) x y - - -noncomputable def markedPivotalMomentOne (G : BondGraph V E) (Q : Finset E) (x : V) - (h p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => bernoulliPolynomial (insert x (searchVertices G Q)) - (fun m => ((markedOpenPivotals G Q x ω m).card:ℝ)) h) p - -theorem marked_pivotal_russo (G : BondGraph V E) (Q : Finset E) (x : V) (h p : ℝ) : - markedPivotalMomentOne G Q x h p = p*deriv (markedConnectionPolynomial G Q x h) p := by - let F := insert x (searchVertices G Q) - let f : Finset E → Finset V → ℝ := fun ω m => - if ∃ y ∈ m, Conn G (ω : Set E) x y then 1 else 0 - have hcard (ω : Finset E) (m : Finset V) : ((markedOpenPivotals G Q x ω m).card:ℝ) = - ∑ e ∈ Q, if e ∈ ω then f ω m-f (ω.erase e) m else 0 := by - rw [markedOpenPivotals,Finset.card_filter,Nat.cast_sum] - apply Finset.sum_congr rfl - intro e _ - have hmono : (∃ y ∈ m, Conn G (ω.erase e : Set E) x y) → - ∃ y ∈ m, Conn G (ω : Set E) x y := by - rintro ⟨y,hy,hxy⟩ - exact ⟨y,hy,conn_mono G (by exact_mod_cast Finset.erase_subset e ω) hxy⟩ - by_cases he : e ∈ ω <;> by_cases h₁ : ∃ y ∈ m, Conn G (ω : Set E) x y <;> - by_cases h₀ : ∃ y ∈ m, Conn G (ω.erase e : Set E) x y <;> - simp only [f,he,h₁,h₀,and_true,and_false,not_true_eq_false, - not_false_eq_true,ite_true,ite_false,Nat.cast_one,Nat.cast_zero,sub_self,sub_zero] - exact False.elim (h₁ (hmono h₀)) - have heq : markedConnectionPolynomial G Q x h = - bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (f ω) h) := rfl - rw [heq,(hasDerivAt_bernoulliPolynomial Q _ p).deriv,Finset.mul_sum] - simp only [markedPivotalMomentOne,hcard,bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro e he - rw [← bernoulliPolynomial_open_difference Q e he (fun ω => bernoulliPolynomial F (f ω) h) p] - apply bernoulliPolynomial_congr - intro ω _ - by_cases heω : e ∈ ω - · simp only [heω,ite_true,F] - exact bernoulliPolynomial_sub _ _ _ _ - · simp only [heω,ite_false,bernoulliPolynomial_zero] - - -theorem marked_pivotal_first_moment (G : BondGraph V E) (Q : Finset E) (x : V) - (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - markedPivotalMomentOne G Q x h p ≤ - (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* - markedConnectionPolynomial G Q x h p := by - rw [marked_pivotal_russo] - exact markedConnection_derivative_bound G Q x p h hp hh d hd hdeg - -end MarkedFirstMoment - -section PivotalGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -def MarkedEvent (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) : Prop := - ∃ y ∈ m, Conn G ω x y - - -def OpenMarkedPivotal (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) - (e : E) : Prop := - e ∈ ω ∧ MarkedEvent G ω m x ∧ ¬MarkedEvent G (ω \ {e}) m x - -theorem markedEvent_mono (G : BondGraph V E) {ω η : Set E} (h : ω ⊆ η) - {m : Set V} {x : V} (hx : MarkedEvent G ω m x) : MarkedEvent G η m x := by - obtain ⟨y,hy,hxy⟩ := hx - exact ⟨y,hy,conn_mono G h hxy⟩ - -theorem edge_cluster_sides (G : BondGraph V E) (ω : Set E) (x : V) - {e : E} {a b : V} (he : e ∈ ω) (hab : G e = s(a,b)) : - a ∈ cluster G ω x ↔ b ∈ cluster G ω x := by - have hc : Conn G ω a b := .single ⟨e,he,hab⟩ - exact ⟨fun h => h.trans hc,fun h => h.trans (conn_symm G ω hc)⟩ - - -theorem conn_restrict_cluster_compl (G : BondGraph V E) (ω : Set E) (x : V) - {a b : V} (ha : a ∉ cluster G ω x) (hab : Conn G ω a b) : - Conn G (ω ∩ internalEdges G (cluster G ω x)ᶜ) a b := by - induction hab with - | refl => exact conn_refl G _ a - | @tail u v hau huv ih => - obtain ⟨e,he,heq⟩ := huv - have hu : u ∉ cluster G ω x := fun h => ha (h.trans (conn_symm G ω hau)) - have hv : v ∉ cluster G ω x := fun h => hu ((edge_cluster_sides G ω x he heq).mpr h) - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ - -theorem conn_restrict_cluster (G : BondGraph V E) (ω : Set E) (x : V) - {a b : V} (ha : a ∈ cluster G ω x) (hab : Conn G ω a b) : - Conn G (ω ∩ internalEdges G (cluster G ω x)) a b := by - induction hab with - | refl => exact conn_refl G _ a - | @tail u v hau huv ih => - obtain ⟨e,he,heq⟩ := huv - have hu : u ∈ cluster G ω x := ha.trans hau - have hv : v ∈ cluster G ω x := (edge_cluster_sides G ω x he heq).mp hu - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ - - -theorem openMarkedPivotal_oriented (G : BondGraph V E) (ω : Set E) (m : Set V) - (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) : - ∃ a b, G e = s(a,b) ∧ Conn G (ω \ {e}) x a ∧ - ¬Conn G (ω \ {e}) x b ∧ MarkedEvent G (ω \ {e}) m b := by - obtain ⟨y,hy,hxy⟩ := he.2.1 - obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) - exact ⟨a,b,h.symm⟩ - have heq : insert e (ω \ {e}) = ω := by - have heω : e ∈ ω := he.1 - ext d - simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] - by_cases h : d = e <;> simp_all - rw [← heq,conn_insert_iff G _ e a b x y hab] at hxy - rcases hxy with hxy | ⟨hxa,hby⟩ | ⟨hxb,hay⟩ - · exact (he.2.2 ⟨y,hy,hxy⟩).elim - · exact ⟨a,b,hab,hxa,fun hxb => he.2.2 ⟨y,hy,hxb.trans hby⟩,y,hy,hby⟩ - · exact ⟨b,a,hab.trans (Sym2.eq_swap ..),hxb, - fun hxa => he.2.2 ⟨y,hy,hxa.trans hay⟩,y,hy,hay⟩ - - -theorem pivotal_rootSide_disjoint_marks (G : BondGraph V E) (ω : Set E) - (m : Set V) (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) : - Disjoint (cluster G (ω \ {e}) x) m := by - rw [Set.disjoint_left] - exact fun y hy hm => he.2.2 ⟨y,hm,hy⟩ - - -theorem conn_delete_internal_of_outside (G : BondGraph V E) (ω : Set E) (x : V) - {f : E} {a b : V} (hf : f ∈ internalEdges G (cluster G ω x)) - (ha : a ∉ cluster G ω x) (hab : Conn G ω a b) : Conn G (ω \ {f}) a b := by - apply conn_mono G _ (conn_restrict_cluster_compl G ω x ha hab) - intro e he - refine ⟨he.1,?_⟩ - intro hef - have hef' : e = f := Set.mem_singleton_iff.mp hef - subst e - obtain ⟨u,v,heq⟩ : ∃ u v, G f = s(u,v) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G f) - exact ⟨a,b,h.symm⟩ - exact ((mem_internalEdges_of_ends G _ f u v heq).mp he.2).1 - ((mem_internalEdges_of_ends G _ f u v heq).mp hf).1 - - -theorem pivotal_other_sides (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) - {e f : E} (_he : OpenMarkedPivotal G ω m x e) - (hf : OpenMarkedPivotal G ω m x f) (hne : f ≠ e) : - f ∈ internalEdges G (cluster G (ω \ {e}) x) ∨ - f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by - obtain ⟨a,b,hab⟩ : ∃ a b, G f = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G f) - exact ⟨a,b,h.symm⟩ - have hop : f ∈ ω \ {e} := ⟨hf.1,hne⟩ - have hiff := edge_cluster_sides G (ω \ {e}) x hop hab - by_cases ha : a ∈ cluster G (ω \ {e}) x - · exact Or.inl ((mem_internalEdges_of_ends G _ f a b hab).mpr ⟨ha,hiff.mp ha⟩) - · exact Or.inr ((mem_internalEdges_of_ends G _ f a b hab).mpr ⟨ha,fun hb => ha (hiff.mpr hb)⟩) - - -theorem conn_delete_exterior_of_inside (G : BondGraph V E) (ω : Set E) (x : V) - {f : E} {a b : V} (hf : f ∈ internalEdges G (cluster G ω x)ᶜ) - (ha : a ∈ cluster G ω x) (hab : Conn G ω a b) : Conn G (ω \ {f}) a b := by - apply conn_mono G _ (conn_restrict_cluster G ω x ha hab) - intro e he - refine ⟨he.1,?_⟩ - intro hef - have hef' : e = f := Set.mem_singleton_iff.mp hef - subst e - obtain ⟨⟨u,v⟩,heq⟩ := Quot.exists_rep (G f) - exact ((mem_internalEdges_of_ends G _ f u v heq.symm).mp hf).1 - ((mem_internalEdges_of_ends G _ f u v heq.symm).mp he.2).1 - - -theorem pivotal_rootSide_ssubset (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) - {e f : E} (he : OpenMarkedPivotal G ω m x e) (hne : e ≠ f) - (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : - cluster G (ω \ {e}) x ⊂ cluster G (ω \ {f}) x := by - have hsub : cluster G (ω \ {e}) x ⊆ cluster G (ω \ {f}) x := by - intro y hy - exact conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_exterior_of_inside G (ω \ {e}) x hf (conn_refl G _ x) hy) - refine ⟨hsub,?_⟩ - obtain ⟨a,b,hab,hxa,hxb,_⟩ := openMarkedPivotal_oriented G ω m x he - intro hback - apply hxb - apply hback - exact (hsub hxa).tail ⟨e,⟨he.1,hne⟩,hab⟩ - - -theorem pivotal_rootSides_nested (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) - {e f : E} (he : OpenMarkedPivotal G ω m x e) - (hf : OpenMarkedPivotal G ω m x f) (hne : e ≠ f) : - cluster G (ω \ {e}) x ⊂ cluster G (ω \ {f}) x ∨ - cluster G (ω \ {f}) x ⊂ cluster G (ω \ {e}) x := by - rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | houtside - · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he - obtain ⟨y,hy,hby⟩ := hbm - have hby' : Conn G (ω \ {f}) b y := conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) - have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ - have ha : a ∉ cluster G (ω \ {f}) x := fun h => - hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) - exact Or.inr (pivotal_rootSide_ssubset G ω m x hf hne.symm - ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩)) - · exact Or.inl (pivotal_rootSide_ssubset G ω m x he hne houtside) - - -theorem conn_restrict_cluster_compl_of_subset (G : BondGraph V E) (ω : Set E) (x : V) - {η : Set E} (hη : η ⊆ ω) {a b : V} (ha : a ∉ cluster G ω x) - (hab : Conn G η a b) : Conn G (η ∩ internalEdges G (cluster G ω x)ᶜ) a b := by - induction hab with - | refl => exact conn_refl G _ a - | @tail u v hau huv ih => - obtain ⟨e,he,heq⟩ := huv - have hu : u ∉ cluster G ω x := fun h => ha (h.trans (conn_symm G ω (conn_mono G hη hau))) - have hv : v ∉ cluster G ω x := fun h => hu ((edge_cluster_sides G ω x (hη he) heq).mpr h) - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ - - - -theorem markedEvent_after_pivotal (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) - {e f : E} (he : OpenMarkedPivotal G ω m x e) (hne : e ≠ f) - {a b : V} (hab : G e = s(a,b)) (hxa : Conn G (ω \ {e}) x a) - (hxb : ¬Conn G (ω \ {e}) x b) - (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : - MarkedEvent G (ω \ {f}) m x ↔ - MarkedEvent G ((ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) \ {f}) m b := by - let W := cluster G (ω \ {e}) x - have heq : insert e ((ω \ {e}) \ {f}) = ω \ {f} := by - ext d - simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] - constructor - · rintro (rfl | ⟨⟨hd,hde⟩,hdf⟩) - · exact ⟨he.1,hne⟩ - · exact ⟨hd,hdf⟩ - · rintro ⟨hd,hdf⟩ - by_cases hde : d = e - · exact Or.inl hde - · exact Or.inr ⟨⟨hd,hde⟩,hdf⟩ - constructor - · rintro ⟨y,hy,hxy⟩ - rw [← heq,conn_insert_iff G _ e a b x y hab] at hxy - rcases hxy with hxy | ⟨_,hby⟩ | ⟨hxb',_⟩ - · exact (he.2.2 ⟨y,hy,conn_mono G Set.sdiff_subset hxy⟩).elim - · refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl_of_subset G (ω \ {e}) x - Set.sdiff_subset hxb hby)⟩ - intro d hd - exact ⟨⟨hd.1.1.1,hd.2⟩,hd.1.2⟩ - · exact (hxb (conn_mono G Set.sdiff_subset hxb')).elim - · rintro ⟨y,hy,hby⟩ - have hxa' : Conn G (ω \ {f}) x a := conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_exterior_of_inside G (ω \ {e}) x hf (conn_refl G _ x) hxa) - refine ⟨y,hy,(hxa'.tail ⟨e,⟨he.1,hne⟩,hab⟩).trans (conn_mono G ?_ hby)⟩ - exact fun _ h => ⟨h.1.1,h.2⟩ - - -theorem openMarkedPivotal_exterior_iff (G : BondGraph V E) (ω : Set E) (m : Set V) - (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) - {a b : V} (hab : G e = s(a,b)) (hxa : Conn G (ω \ {e}) x a) - (hxb : ¬Conn G (ω \ {e}) x b) (hbm : MarkedEvent G (ω \ {e}) m b) - (f : E) : - OpenMarkedPivotal G (ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) m b f ↔ - OpenMarkedPivotal G ω m x f ∧ f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by - have hbase : MarkedEvent G (ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) m b := by - obtain ⟨y,hy,hby⟩ := hbm - refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl G (ω \ {e}) x hxb hby)⟩ - exact fun _ h => ⟨h.1.1,h.2⟩ - have hexterior (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by - intro h; subst f - exact ((mem_internalEdges_of_ends G _ e a b hab).mp hf).1 hxa - constructor - · intro hf - have hiff := markedEvent_after_pivotal G ω m x he (hexterior hf.1.2) hab hxa hxb hf.1.2 - exact ⟨⟨hf.1.1,he.2.1,fun h => hf.2.2 (hiff.mp h)⟩,hf.1.2⟩ - · rintro ⟨hf,hout⟩ - have hiff := markedEvent_after_pivotal G ω m x he (hexterior hout) hab hxa hxb hout - exact ⟨⟨hf.1,hout⟩,hbase,fun h => hf.2.2 (hiff.mpr h)⟩ - - -theorem cluster_finite_of_finite_edges (G : BondGraph V E) {ω : Set E} - (hω : ω.Finite) (x : V) : (cluster G ω x).Finite := by - let F : Finset V := insert x (hω.toFinset.biUnion fun e => (G e).toFinset) - apply F.finite_toSet.subset - intro y hxy - induction hxy with - | refl => exact Finset.mem_insert_self x _ - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - apply Finset.mem_insert_of_mem - apply Finset.mem_biUnion.mpr - exact ⟨e,hω.mem_toFinset.mpr he,by simp [heq]⟩ - - -noncomputable def pivotalRank (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : ℕ := - (cluster G (ω \ {e}) x).ncard - -theorem pivotalRank_injective (G : BondGraph V E) {ω : Set E} (hω : ω.Finite) - (m : Set V) (x : V) : Set.InjOn (pivotalRank G ω x) {e | OpenMarkedPivotal G ω m x e} := by - intro e he f hf hsame - by_contra hne - rcases pivotal_rootSides_nested G ω m x he hf hne with h | h - · have hh := Set.ncard_lt_ncard h (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) - exact (Nat.ne_of_lt hh) hsame - · have hh := Set.ncard_lt_ncard h (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) - exact (Nat.ne_of_lt hh) hsame.symm - - -theorem pivotalRank_lt_iff (G : BondGraph V E) {ω : Set E} (hω : ω.Finite) - (m : Set V) (x : V) {e f : E} (he : OpenMarkedPivotal G ω m x e) - (hf : OpenMarkedPivotal G ω m x f) : - pivotalRank G ω x e < pivotalRank G ω x f ↔ - f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by - have hexterior (hout : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by - obtain ⟨a,b,hab,hxa,_,_⟩ := openMarkedPivotal_oriented G ω m x he - intro h; subst f - exact ((mem_internalEdges_of_ends G _ e a b hab).mp hout).1 hxa - constructor - · intro hlt - have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) - rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | hout - · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he - obtain ⟨y,hy,hby⟩ := hbm - have hby' : Conn G (ω \ {f}) b y := conn_mono G - (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) - have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ - have ha : a ∉ cluster G (ω \ {f}) x := fun h => - hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) - have hs := pivotal_rootSide_ssubset G ω m x hf hne.symm - ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩) - have hrev := Set.ncard_lt_ncard hs - (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) - exact (Nat.not_lt_of_ge (Nat.le_of_lt hrev) hlt).elim - · exact hout - · intro hout - exact Set.ncard_lt_ncard (pivotal_rootSide_ssubset G ω m x he (hexterior hout) hout) - (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) - -end PivotalGeometry - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Criticality.Sharpness + +namespace OAI + +/-! Marked decision trees, graph searches and pivotal geometry. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section MarkedExploration + + +theorem centered_bernoulli_mgf_le (p : unitInterval) (lam : ℝ) : + (1-(p:ℝ))*Real.exp (-lam*p) + p*Real.exp (lam*(1-p)) ≤ Real.exp (lam^2/8) := by + let X : Bool → ℝ := fun b => if b then 1-(p:ℝ) else -(p:ℝ) + have hb : ∀ᵐ b ∂bernoulliMeasure true false p, X b ∈ Set.Icc (-(p:ℝ)) (1-p) := by + filter_upwards with b + cases b <;> simp [X] + have hc : ∫ b, X b ∂bernoulliMeasure true false p = 0 := by + rw [integral_bernoulliMeasure] + simp [X] + ring + have hg := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero + (μ := bernoulliMeasure true false p) (X := X) + (Measurable.of_discrete.aemeasurable) hb hc + have hh := hg.mgf_le lam + simp only [mgf,integral_bernoulliMeasure] at hh + norm_num [X,sub_neg_eq_add,sub_add_cancel,smul_eq_mul] at hh + rw [show (1/4:ℝ)*lam^2/2 = lam^2/8 by ring] at hh + simpa only [neg_mul,add_comm] using hh + + +inductive ProbeTree where + | done (success : Bool) + | edge (closed open_ : ProbeTree) + | mark (unmarked marked : ProbeTree) + +namespace ProbeTree + +@[reducible] def Leaf : ProbeTree → Type + | .done _ => Unit + | .edge t₀ t₁ => Leaf t₀ ⊕ Leaf t₁ + | .mark t₀ t₁ => Leaf t₀ ⊕ Leaf t₁ + +instance leafFintype : (t : ProbeTree) → Fintype t.Leaf + | .done _ => inferInstanceAs (Fintype Unit) + | .edge t₀ t₁ => @instFintypeSum _ _ (leafFintype t₀) (leafFintype t₁) + | .mark t₀ t₁ => @instFintypeSum _ _ (leafFintype t₀) (leafFintype t₁) + +noncomputable def weight (p h : ℝ) : (t : ProbeTree) → t.Leaf → ℝ + | .done _, _ => 1 + | .edge t₀ _, .inl l => (1-p)*weight p h t₀ l + | .edge _ t₁, .inr l => p*weight p h t₁ l + | .mark t₀ _, .inl l => (1-h)*weight p h t₀ l + | .mark _ t₁, .inr l => h*weight p h t₁ l + +noncomputable def score (p : ℝ) : (t : ProbeTree) → t.Leaf → ℝ + | .done _, _ => 0 + | .edge t₀ _, .inl l => score p t₀ l-p + | .edge _ t₁, .inr l => score p t₁ l+(1-p) + | .mark t₀ _, .inl l => score p t₀ l + | .mark _ t₁, .inr l => score p t₁ l + +def queries : (t : ProbeTree) → t.Leaf → ℕ + | .done _, _ => 0 + | .edge t₀ _, .inl l => queries t₀ l+1 + | .edge _ t₁, .inr l => queries t₁ l+1 + | .mark t₀ _, .inl l => queries t₀ l + | .mark _ t₁, .inr l => queries t₁ l + +@[reducible] def outcome : (t : ProbeTree) → t.Leaf → Bool + | .done b, _ => b + | .edge t₀ _, .inl l => outcome t₀ l + | .edge _ t₁, .inr l => outcome t₁ l + | .mark t₀ _, .inl l => outcome t₀ l + | .mark _ t₁, .inr l => outcome t₁ l + +lemma weight_nonneg (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : + 0 ≤ weight p h t l := by + induction t with + | done b => exact zero_le_one + | edge t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => exact mul_nonneg (sub_nonneg.mpr p.2.2) (ih₀ l) + | inr l => exact mul_nonneg p.2.1 (ih₁ l) + | mark t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => exact mul_nonneg (sub_nonneg.mpr h.2.2) (ih₀ l) + | inr l => exact mul_nonneg h.2.1 (ih₁ l) + +lemma sum_weight (p h : ℝ) (t : ProbeTree) : ∑ l, weight p h t l = 1 := by + induction t with + | done b => change (∑ _ : Unit, (1:ℝ)) = 1; simp + | edge t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 1 + simp only [Fintype.sum_sum_type,weight,← Finset.mul_sum,ih₀,ih₁] + ring + | mark t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 1 + simp only [Fintype.sum_sum_type,weight,← Finset.mul_sum,ih₀,ih₁] + ring + + +theorem score_mgf (p h : unitInterval) (lam : ℝ) (t : ProbeTree) : + ∑ l, weight p h t l * Real.exp (lam*score p t l-lam^2*(queries t l : ℝ)/8) ≤ 1 := by + induction t with + | done b => change (∑ l : Unit, _) ≤ (1:ℝ); simp [weight,score,queries] + | edge t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) ≤ (1:ℝ) + rw [Fintype.sum_sum_type] + have h₀ (l : t₀.Leaf) : + weight p h (.edge t₀ t₁) (.inl l) * + Real.exp (lam*score p (.edge t₀ t₁) (.inl l)-lam^2*(queries (.edge t₀ t₁) (.inl l):ℝ)/8) = + ((1-(p:ℝ))*Real.exp (-lam*p-lam^2/8)) * + (weight p h t₀ l * Real.exp (lam*score p t₀ l-lam^2*(queries t₀ l:ℝ)/8)) := by + simp only [weight,score,queries,Nat.cast_add,Nat.cast_one] + rw [show lam*(score p t₀ l-p)-lam^2*((queries t₀ l:ℝ)+1)/8 = + (-lam*p-lam^2/8)+(lam*score p t₀ l-lam^2*(queries t₀ l:ℝ)/8) by ring,Real.exp_add] + ring + have h₁ (l : t₁.Leaf) : + weight p h (.edge t₀ t₁) (.inr l) * + Real.exp (lam*score p (.edge t₀ t₁) (.inr l)-lam^2*(queries (.edge t₀ t₁) (.inr l):ℝ)/8) = + ((p:ℝ)*Real.exp (lam*(1-p)-lam^2/8)) * + (weight p h t₁ l * Real.exp (lam*score p t₁ l-lam^2*(queries t₁ l:ℝ)/8)) := by + simp only [weight,score,queries,Nat.cast_add,Nat.cast_one] + rw [show lam*(score p t₁ l+(1-p))-lam^2*((queries t₁ l:ℝ)+1)/8 = + (lam*(1-p)-lam^2/8)+(lam*score p t₁ l-lam^2*(queries t₁ l:ℝ)/8) by ring,Real.exp_add] + ring + simp only [h₀,h₁,← Finset.mul_sum] + have hc₀ : 0 ≤ (1-(p:ℝ))*Real.exp (-lam*p-lam^2/8) := + mul_nonneg (sub_nonneg.mpr p.2.2) (Real.exp_pos _).le + have hc₁ : 0 ≤ (p:ℝ)*Real.exp (lam*(1-p)-lam^2/8) := + mul_nonneg p.2.1 (Real.exp_pos _).le + calc + _ ≤ (1-(p:ℝ))*Real.exp (-lam*p-lam^2/8) + p*Real.exp (lam*(1-p)-lam^2/8) := by + simpa using add_le_add (mul_le_mul_of_nonneg_left ih₀ hc₀) (mul_le_mul_of_nonneg_left ih₁ hc₁) + _ = ((1-(p:ℝ))*Real.exp (-lam*p)+p*Real.exp (lam*(1-p))) / Real.exp (lam^2/8) := by + simp only [Real.exp_sub]; ring + _ ≤ 1 := (div_le_one (Real.exp_pos _)).mpr (centered_bernoulli_mgf_le p lam) + | mark t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) ≤ (1:ℝ) + simp only [Fintype.sum_sum_type,weight,score,queries,mul_assoc,← Finset.mul_sum] + calc + _ ≤ (1-(h:ℝ))*1+(h:ℝ)*1 := + add_le_add (mul_le_mul_of_nonneg_left ih₀ (sub_nonneg.mpr h.2.2)) + (mul_le_mul_of_nonneg_left ih₁ h.2.1) + _ = 1 := by ring + +noncomputable def successWeight (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : ℝ := + if outcome t l then weight p h t l else 0 + +noncomputable def successMass (p h : ℝ) (t : ProbeTree) : ℝ := + ∑ l, successWeight p h t l + +noncomputable def successScore (p h : ℝ) (t : ProbeTree) : ℝ := + ∑ l, successWeight p h t l * score p t l + +noncomputable def successQueries (p h : ℝ) (t : ProbeTree) : ℝ := + ∑ l, successWeight p h t l * queries t l + +lemma successWeight_nonneg (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : + 0 ≤ successWeight p h t l := by + unfold successWeight + split <;> simp_all [weight_nonneg] + +lemma successWeight_le (p h : unitInterval) (t : ProbeTree) (l : t.Leaf) : + successWeight p h t l ≤ weight p h t l := by + unfold successWeight + split + · exact le_rfl + · exact weight_nonneg p h t l + +lemma successMass_nonneg (p h : unitInterval) (t : ProbeTree) : 0 ≤ successMass p h t := + Finset.sum_nonneg fun _ _ => successWeight_nonneg p h t _ + +lemma successMass_le_one (p h : unitInterval) (t : ProbeTree) : successMass p h t ≤ 1 := by + rw [← sum_weight p h t] + exact Finset.sum_le_sum fun _ _ => successWeight_le p h t _ + +lemma successQueries_nonneg (p h : unitInterval) (t : ProbeTree) : 0 ≤ successQueries p h t := + Finset.sum_nonneg fun _ _ => mul_nonneg (successWeight_nonneg p h t _) (Nat.cast_nonneg _) + + +theorem conditional_score_bound (p h : unitInterval) (t : ProbeTree) + (hH : 0 < successMass p h t) (lam : ℝ) : + lam*(successScore p h t / successMass p h t) ≤ + Real.log (1/successMass p h t) + lam^2/8*(successQueries p h t / successMass p h t) := by + let H := successMass p h t + let w : t.Leaf → ℝ := fun l => successWeight p h t l / H + let X : t.Leaf → ℝ := fun l => lam*score p t l-lam^2*(queries t l : ℝ)/8 + have hw : ∀ l ∈ (Finset.univ : Finset t.Leaf), 0 ≤ w l := + fun l _ => div_nonneg (successWeight_nonneg p h t l) hH.le + have hw1 : ∑ l, w l = 1 := by + simp only [w,← Finset.sum_div] + exact div_self hH.ne' + have hJ := convexOn_exp.map_sum_le hw hw1 (fun _ _ => Set.mem_univ _ : ∀ l ∈ + (Finset.univ : Finset t.Leaf), X l ∈ Set.univ) + simp only [smul_eq_mul] at hJ + have hsum : ∑ l, w l * X l = lam*(successScore p h t/H)- + lam^2/8*(successQueries p h t/H) := by + simp only [w,X,successScore,successQueries,Finset.sum_div,Finset.mul_sum,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro l _ + ring + have he : ∑ l, w l * Real.exp (X l) ≤ 1/H := by + calc + _ = (∑ l, successWeight p h t l * Real.exp (X l))/H := by + simp only [Finset.sum_div,w]; apply Finset.sum_congr rfl; intro l _; ring + _ ≤ (∑ l, weight p h t l * Real.exp (X l))/H := by + apply div_le_div_of_nonneg_right _ hH.le + exact Finset.sum_le_sum fun l _ => mul_le_mul_of_nonneg_right (successWeight_le p h t l) + (Real.exp_pos _).le + _ ≤ 1/H := div_le_div_of_nonneg_right (score_mgf p h lam t) hH.le + rw [hsum] at hJ + have hb := (Real.le_log_iff_exp_le (one_div_pos.mpr hH)).mpr (hJ.trans he) + linarith + +noncomputable def dweight (p h : ℝ) : (t : ProbeTree) → t.Leaf → ℝ + | .done _, _ => 0 + | .edge t₀ _, .inl l => -weight p h t₀ l+(1-p)*dweight p h t₀ l + | .edge _ t₁, .inr l => weight p h t₁ l+p*dweight p h t₁ l + | .mark t₀ _, .inl l => (1-h)*dweight p h t₀ l + | .mark _ t₁, .inr l => h*dweight p h t₁ l + +lemma hasDerivAt_weight (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : + HasDerivAt (fun q => weight q h t l) (dweight p h t l) p := by + induction t with + | done b => exact hasDerivAt_const p 1 + | edge t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => convert ((hasDerivAt_const p 1).sub (hasDerivAt_id p)).mul (ih₀ l) using 1 <;> try rfl + simp [dweight] + | inr l => convert (hasDerivAt_id p).mul (ih₁ l) using 1 <;> try rfl + simp [dweight] + | mark t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => exact (ih₀ l).const_mul (1-h) + | inr l => exact (ih₁ l).const_mul h + +lemma score_eq_derivative (p h : ℝ) (t : ProbeTree) (l : t.Leaf) : + p*(1-p)*dweight p h t l = weight p h t l * score p t l := by + induction t with + | done b => simp [dweight,weight,score] + | edge t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => dsimp [dweight,weight,score]; linear_combination (1-p)*(ih₀ l) + | inr l => dsimp [dweight,weight,score]; linear_combination p*(ih₁ l) + | mark t₀ t₁ ih₀ ih₁ => + cases l with + | inl l => dsimp [dweight,weight,score]; linear_combination (1-h)*(ih₀ l) + | inr l => dsimp [dweight,weight,score]; linear_combination h*(ih₁ l) + + +theorem successScore_eq_deriv (p h : ℝ) (t : ProbeTree) : + successScore p h t = p*(1-p)*deriv (fun q => successMass q h t) p := by + have hd : HasDerivAt (fun q => successMass q h t) + (∑ l, if outcome t l then dweight p h t l else 0) p := by + have hh (l : t.Leaf) (_ : l ∈ (Finset.univ : Finset t.Leaf)) : + HasDerivAt (fun q => successWeight q h t l) (if outcome t l then dweight p h t l else 0) p := by + by_cases hl : outcome t l + · simpa [successWeight,hl] using hasDerivAt_weight p h t l + · simpa [successWeight,hl] using hasDerivAt_const p (0:ℝ) + simpa only [successMass,Finset.sum_apply] using HasDerivAt.fun_sum hh + rw [hd.deriv,Finset.mul_sum] + apply Finset.sum_congr rfl + intro l _ + by_cases hl : outcome t l + · simpa [successWeight,hl] using (score_eq_derivative p h t l).symm + · simp [successWeight,hl] + + +inductive IsMarkSearch : ProbeTree → Prop + | fail : IsMarkSearch (.done false) + | edge {t₀ t₁} : IsMarkSearch t₀ → IsMarkSearch t₁ → IsMarkSearch (.edge t₀ t₁) + | mark {t₀} : IsMarkSearch t₀ → IsMarkSearch (.mark t₀ (.done true)) + +def marks : (t : ProbeTree) → t.Leaf → ℕ + | .done _, _ => 0 + | .edge t₀ _, .inl l => marks t₀ l + | .edge _ t₁, .inr l => marks t₁ l + | .mark t₀ _, .inl l => marks t₀ l+1 + | .mark _ t₁, .inr l => marks t₁ l+1 + +noncomputable def successMarks (p h : ℝ) (t : ProbeTree) : ℝ := + ∑ l, successWeight p h t l * marks t l + +lemma successMass_edge (p h : ℝ) (t₀ t₁ : ProbeTree) : + successMass p h (.edge t₀ t₁) = (1-p)*successMass p h t₀+p*successMass p h t₁ := by + simp only [successMass,Fintype.sum_sum_type,successWeight,outcome,weight,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp + +lemma successMass_mark (p h : ℝ) (t₀ t₁ : ProbeTree) : + successMass p h (.mark t₀ t₁) = (1-h)*successMass p h t₀+h*successMass p h t₁ := by + simp only [successMass,Fintype.sum_sum_type,successWeight,outcome,weight,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp + +@[simp] lemma successMass_done (p h : ℝ) (b : Bool) : + successMass p h (.done b) = if b then 1 else 0 := by + cases b <;> simp [successMass,successWeight,outcome,weight] + +lemma successMarks_edge (p h : ℝ) (t₀ t₁ : ProbeTree) : + successMarks p h (.edge t₀ t₁) = (1-p)*successMarks p h t₀+p*successMarks p h t₁ := by + simp only [successMarks,Fintype.sum_sum_type,successWeight,outcome,weight,marks,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split <;> simp [mul_assoc] + +lemma successMarks_mark (p h : ℝ) (t₀ t₁ : ProbeTree) : + successMarks p h (.mark t₀ t₁) = + (1-h)*(successMarks p h t₀+successMass p h t₀) + + h*(successMarks p h t₁+successMass p h t₁) := by + simp only [successMarks,successMass,Fintype.sum_sum_type,successWeight,outcome,weight,marks, + Nat.cast_add,Nat.cast_one,← Finset.sum_add_distrib,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro l _ <;> split_ifs <;> ring + +@[simp] lemma successMarks_done (p h : ℝ) (b : Bool) : successMarks p h (.done b) = 0 := by + simp [successMarks,marks] + + +theorem marks_times_parameter_le (p h : unitInterval) {t : ProbeTree} (ht : IsMarkSearch t) : + (h:ℝ)*successMarks p h t ≤ successMass p h t := by + induction ht with + | fail => simp + | @edge t₀ t₁ _ _ ih₀ ih₁ => + rw [successMarks_edge,successMass_edge] + nlinarith [mul_nonneg (sub_nonneg.mpr p.2.2) (sub_nonneg.mpr ih₀), + mul_nonneg p.2.1 (sub_nonneg.mpr ih₁)] + | @mark t₀ _ ih => + rw [successMarks_mark,successMass_mark] + simp only [successMarks_done,successMass_done,ite_true,zero_add,mul_one] + have hn := mul_nonneg (mul_nonneg h.2.1 (sub_nonneg.mpr h.2.2)) + (sub_nonneg.mpr (successMass_le_one p h t₀)) + nlinarith [mul_nonneg (sub_nonneg.mpr h.2.2) (sub_nonneg.mpr ih)] + +theorem successQueries_times_parameter_le (p h : unitInterval) {t : ProbeTree} + (ht : IsMarkSearch t) (d : ℕ) (hcost : ∀ l, queries t l ≤ d*marks t l) : + (h:ℝ)*successQueries p h t ≤ d*successMass p h t := by + have hs : successQueries p h t ≤ d*successMarks p h t := by + simp only [successQueries,successMarks,Finset.mul_sum] + apply Finset.sum_le_sum + intro l _ + calc + _ ≤ successWeight p h t l * ((d:ℝ)*marks t l) := + mul_le_mul_of_nonneg_left (by exact_mod_cast hcost l) (successWeight_nonneg p h t l) + _ = _ := by ring + calc + _ ≤ (h:ℝ)*(d*successMarks p h t) := mul_le_mul_of_nonneg_left hs h.2.1 + _ = d*((h:ℝ)*successMarks p h t) := by ring + _ ≤ d*successMass p h t := mul_le_mul_of_nonneg_left (marks_times_parameter_le p h ht) + (Nat.cast_nonneg _) + + +theorem marked_score_bound (p h : unitInterval) (hh : 0 < (h:ℝ)) + {t : ProbeTree} (ht : IsMarkSearch t) (d : ℕ) + (hcost : ∀ l, queries t l ≤ d*marks t l) (hroot : (h:ℝ) ≤ successMass p h t) + (lam : ℝ) : + lam*(successScore p h t / successMass p h t) ≤ + Real.log (1/(h:ℝ)) + lam^2*(d:ℝ)/(8*h) := by + have hH := hh.trans_le hroot + have hlog : Real.log (1/successMass p h t) ≤ Real.log (1/(h:ℝ)) := + Real.log_le_log (one_div_pos.mpr hH) (one_div_le_one_div_of_le hh hroot) + have hQ : successQueries p h t / successMass p h t ≤ (d:ℝ)/h := by + apply (div_le_div_iff₀ hH hh).mpr + simpa [mul_comm] using successQueries_times_parameter_le p h ht d hcost + calc + _ ≤ Real.log (1/successMass p h t)+lam^2/8*(successQueries p h t/successMass p h t) := + conditional_score_bound p h t hH lam + _ ≤ Real.log (1/(h:ℝ))+lam^2/8*((d:ℝ)/h) := + add_le_add hlog (mul_le_mul_of_nonneg_left hQ (by positivity)) + _ = _ := by ring + +end ProbeTree +end MarkedExploration + +section LabelledExploration +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +inductive LabelledTree (V E : Type*) where + | done (success : Bool) + | edge (e : E) (closed opened : LabelledTree V E) + | mark (v : V) (unmarked marked : LabelledTree V E) + +namespace LabelledTree + +def forget : LabelledTree V E → ProbeTree + | .done b => .done b + | .edge _ t₀ t₁ => .edge t₀.forget t₁.forget + | .mark _ t₀ t₁ => .mark t₀.forget t₁.forget + +@[reducible] noncomputable def eval (ω : Finset E) (m : Finset V) : LabelledTree V E → Bool + | .done b => b + | .edge e t₀ t₁ => if e ∈ ω then eval ω m t₁ else eval ω m t₀ + | .mark v t₀ t₁ => if v ∈ m then eval ω m t₁ else eval ω m t₀ + +def Valid (Q : Finset E) (F : Finset V) : LabelledTree V E → Prop + | .done _ => True + | .edge e t₀ t₁ => e ∈ Q ∧ Valid (Q.erase e) F t₀ ∧ Valid (Q.erase e) F t₁ + | .mark v t₀ t₁ => v ∈ F ∧ Valid Q (F.erase v) t₀ ∧ Valid Q (F.erase v) t₁ + +theorem eval_congr (t : LabelledTree V E) {Q : Finset E} {F : Finset V} + (ht : Valid Q F t) {ω ω' : Finset E} {m m' : Finset V} + (hω : ∀ e ∈ Q, e ∈ ω ↔ e ∈ ω') (hm : ∀ v ∈ F, v ∈ m ↔ v ∈ m') : + t.eval ω m = t.eval ω' m' := by + induction t generalizing Q F with + | done b => rfl + | edge e t₀ t₁ ih₀ ih₁ => + obtain ⟨he,h₀,h₁⟩ := ht + simp only [eval,hω e he] + split + · exact ih₁ h₁ (fun a ha => hω a (Finset.mem_of_mem_erase ha)) hm + · exact ih₀ h₀ (fun a ha => hω a (Finset.mem_of_mem_erase ha)) hm + | mark v t₀ t₁ ih₀ ih₁ => + obtain ⟨hv,h₀,h₁⟩ := ht + simp only [eval,hm v hv] + split + · exact ih₁ h₁ hω (fun a ha => hm a (Finset.mem_of_mem_erase ha)) + · exact ih₀ h₀ hω (fun a ha => hm a (Finset.mem_of_mem_erase ha)) + +lemma eval_insert_edge (t : LabelledTree V E) {Q : Finset E} {F : Finset V} + (ht : Valid Q F t) {e : E} (he : e ∉ Q) (ω : Finset E) (m : Finset V) : + t.eval (insert e ω) m = t.eval ω m := by + apply eval_congr t ht + · intro a ha + simp [show a ≠ e from fun hh => he (hh ▸ ha)] + · simp + +lemma eval_insert_mark (t : LabelledTree V E) {Q : Finset E} {F : Finset V} + (ht : Valid Q F t) {v : V} (hv : v ∉ F) (ω : Finset E) (m : Finset V) : + t.eval ω (insert v m) = t.eval ω m := by + apply eval_congr t ht + · simp + · intro a ha + simp [show a ≠ v from fun hh => hv (hh ▸ ha)] + +end LabelledTree + +theorem bernoulliPolynomial_affine (s : Finset E) (f g : Finset E → ℝ) (a b p : ℝ) : + bernoulliPolynomial s (fun t => a*f t+b*g t) p = + a*bernoulliPolynomial s f p+b*bernoulliPolynomial s g p := by + simp only [bernoulliPolynomial,add_mul,Finset.sum_add_distrib,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro t _ <;> ring + +namespace LabelledTree + + +theorem expectation_eq (t : LabelledTree V E) {Q : Finset E} {F : Finset V} + (ht : Valid Q F t) (p h : ℝ) : + bernoulliPolynomial Q (fun ω => bernoulliPolynomial F + (fun m => if t.eval ω m then 1 else 0) h) p = + ProbeTree.successMass p h t.forget := by + induction t generalizing Q F with + | done b => + cases b <;> simp [eval,forget,ProbeTree.successMass_done,bernoulliPolynomial_const] + | edge e t₀ t₁ ih₀ ih₁ => + obtain ⟨he,h₀,h₁⟩ := ht + conv_lhs => rw [← Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] + have hc : bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (fun m => if (edge e t₀ t₁).eval ω m then 1 else 0) h) p = + bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (fun m => if t₀.eval ω m then 1 else 0) h) p := by + apply bernoulliPolynomial_congr + intro ω hω + have heω : e ∉ ω := fun hh => Finset.notMem_erase e Q (hω hh) + simp only [eval,heω,ite_false] + have ho : bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (fun m => if (edge e t₀ t₁).eval (insert e ω) m then 1 else 0) h) p = + bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (fun m => if t₁.eval ω m then 1 else 0) h) p := by + apply bernoulliPolynomial_congr + intro ω _ + simp only [eval,Finset.mem_insert_self,ite_true] + apply bernoulliPolynomial_congr + intro m _ + rw [eval_insert_edge t₁ h₁ (Finset.notMem_erase e Q)] + rw [hc,ho,ih₀ h₀,ih₁ h₁,forget,ProbeTree.successMass_edge] + | mark v t₀ t₁ ih₀ ih₁ => + obtain ⟨hv,h₀,h₁⟩ := ht + have hh : ∀ ω, bernoulliPolynomial F + (fun m => if (mark v t₀ t₁).eval ω m then 1 else 0) h = + (1-h)*bernoulliPolynomial (F.erase v) (fun m => if t₀.eval ω m then 1 else 0) h + + h*bernoulliPolynomial (F.erase v) (fun m => if t₁.eval ω m then 1 else 0) h := by + intro ω + conv_lhs => rw [← Finset.insert_erase hv] + rw [bernoulliPolynomial_insert _ v (Finset.notMem_erase v F)] + congr 1 + · congr 1 + apply bernoulliPolynomial_congr + intro m hm + have hvm : v ∉ m := fun hh => Finset.notMem_erase v F (hm hh) + simp only [eval,hvm,ite_false] + · congr 1 + apply bernoulliPolynomial_congr + intro m _ + simp only [eval,Finset.mem_insert_self,ite_true] + rw [eval_insert_mark t₁ h₁ (Finset.notMem_erase v F)] + simp_rw [hh] + rw [bernoulliPolynomial_affine,ih₀ h₀,ih₁ h₁,forget,ProbeTree.successMass_mark] + +end LabelledTree +end LabelledExploration + +section GraphMarkedSearch +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + + +def SearchCrossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Prop := + ∃ t : E × V × V, t.1 ∈ Q ∧ t.2.1 ∈ R ∧ t.2.2 ∉ R ∧ G t.1 = s(t.2.1,t.2.2) + +noncomputable def searchCrossing (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (h : SearchCrossing G Q R) : E × V × V := Classical.choose h + +theorem searchCrossing_spec (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (h : SearchCrossing G Q R) : + (searchCrossing G Q R h).1 ∈ Q ∧ (searchCrossing G Q R h).2.1 ∈ R ∧ + (searchCrossing G Q R h).2.2 ∉ R ∧ + G (searchCrossing G Q R h).1 = s((searchCrossing G Q R h).2.1,(searchCrossing G Q R h).2.2) := + Classical.choose_spec h + + +def SearchAvailable (G : BondGraph V E) (Q : Finset E) (R F : Finset V) : Prop := + ∀ e ∈ Q, ∀ v ∈ G e, v ∈ R ∨ v ∈ F + +noncomputable def clusterSearch (G : BondGraph V E) : ℕ → Finset E → Finset V → LabelledTree V E + | 0, _, _ => .done false + | n+1, Q, R => + if hc : SearchCrossing G Q R then + let t := searchCrossing G Q R hc + .edge t.1 (clusterSearch G n (Q.erase t.1) R) + (.mark t.2.2 (clusterSearch G n (Q.erase t.1) (insert t.2.2 R)) (.done true)) + else .done false + +lemma searchAvailable_erase (G : BondGraph V E) {Q : Finset E} {R F : Finset V} + (h : SearchAvailable G Q R F) (e : E) : SearchAvailable G (Q.erase e) R F := + fun _ ha _ hv => h _ (Finset.mem_of_mem_erase ha) _ hv + +lemma searchAvailable_discover (G : BondGraph V E) {Q : Finset E} {R F : Finset V} + (h : SearchAvailable G Q R F) (e : E) (v : V) : + SearchAvailable G (Q.erase e) (insert v R) (F.erase v) := by + intro a ha b hb + rcases h a (Finset.mem_of_mem_erase ha) b hb with hb | hb + · exact Or.inl (Finset.mem_insert_of_mem hb) + · by_cases hbe : b = v + · exact Or.inl (by simp [hbe]) + · exact Or.inr (Finset.mem_erase.mpr ⟨hbe,hb⟩) + +theorem clusterSearch_valid (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R F : Finset V) + (ha : SearchAvailable G Q R F) : LabelledTree.Valid Q F (clusterSearch G n Q R) := by + induction n generalizing Q R F with + | zero => trivial + | succ n ih => + simp only [clusterSearch] + split_ifs with hc + · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc + refine ⟨he,ih _ _ _ (searchAvailable_erase G ha _),?_,?_,trivial⟩ + · exact (ha _ he _ (by rw [hends]; simp)).resolve_left hw + · exact ih _ _ _ (searchAvailable_discover G ha _ _) + · trivial + +theorem clusterSearch_markSearch (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) : + ProbeTree.IsMarkSearch (clusterSearch G n Q R).forget := by + induction n generalizing Q R with + | zero => exact .fail + | succ n ih => + simp only [clusterSearch] + split_ifs + · exact .edge (ih _ _) (.mark (ih _ _)) + · exact .fail + + +def SeedMarked (G : BondGraph V E) (ω : Set E) (R m : Finset V) : Prop := + ∃ a ∈ R, ∃ b ∈ m, Conn G ω a b + +theorem seedMarked_insert_edge (G : BondGraph V E) (ω : Set E) (R m : Finset V) + (e : E) (a b : V) (ha : a ∈ R) (he : G e = s(a,b)) : + SeedMarked G (insert e ω) R m ↔ SeedMarked G ω (insert b R) m := by + constructor + · rintro ⟨x,hx,y,hy,hxy⟩ + rcases (conn_insert_iff G ω e a b x y he).mp hxy with h | ⟨_,h⟩ | ⟨_,h⟩ + · exact ⟨x,Finset.mem_insert_of_mem hx,y,hy,h⟩ + · exact ⟨b,by simp,y,hy,h⟩ + · exact ⟨a,Finset.mem_insert_of_mem ha,y,hy,h⟩ + · rintro ⟨x,hx,y,hy,hxy⟩ + rcases Finset.mem_insert.mp hx with rfl | hx + · refine ⟨a,ha,y,hy,?_⟩ + exact (Relation.ReflTransGen.single ⟨e,Set.mem_insert e ω,he⟩).trans + (conn_mono G (Set.subset_insert e ω) hxy) + · exact ⟨x,hx,y,hy,conn_mono G (Set.subset_insert e ω) hxy⟩ + +theorem seedMarked_false_of_no_crossing (G : BondGraph V E) (Q : Finset E) (R m : Finset V) + (hc : ¬ SearchCrossing G Q R) (hm : Disjoint R m) (ω : Finset E) (hω : ω ⊆ Q) : + ¬ SeedMarked G (ω : Set E) R m := by + rintro ⟨a,ha,b,hb,hab⟩ + have hclosed : ∀ x ∈ R, ∀ y, Conn G (ω : Set E) x y → y ∈ R := by + intro x hx y hxy + induction hxy with + | refl => exact hx + | @tail v w hv hw ih => + by_contra hn + obtain ⟨e,he,hevw⟩ := hw + exact hc ⟨(e,v,w),hω he,ih,hn,hevw⟩ + exact Finset.disjoint_left.mp hm (hclosed a ha b hab) hb + + +theorem clusterSearch_correct (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R F m : Finset V) + (hn : Q.card ≤ n) (ha : SearchAvailable G Q R F) (hm : Disjoint R m) + (ω : Finset E) (hω : ω ⊆ Q) : + (clusterSearch G n Q R).eval ω m = true ↔ SeedMarked G (ω : Set E) R m := by + induction n generalizing Q R F ω with + | zero => + have hQ : Q = ∅ := Finset.card_eq_zero.mp (by omega) + have hωe : ω = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (by simp_all) + simp only [clusterSearch,LabelledTree.eval,Bool.false_eq_true,false_iff] + exact seedMarked_false_of_no_crossing G Q R m (by simp [SearchCrossing,hQ]) hm ω hω + | succ n ih => + simp only [clusterSearch] + split_ifs with hc + · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc + have hcard : (Q.erase (searchCrossing G Q R hc).1).card ≤ n := by + rw [Finset.card_erase_of_mem he]; omega + simp only [LabelledTree.eval] + by_cases heω : (searchCrossing G Q R hc).1 ∈ ω + · simp only [heω,ite_true] + rw [← Finset.insert_erase heω,Finset.coe_insert, + seedMarked_insert_edge G _ R m _ _ _ hv hends] + by_cases hwm : (searchCrossing G Q R hc).2.2 ∈ m + · simp only [hwm,ite_true,true_iff] + exact ⟨_,by simp,_,hwm,conn_refl G _ _⟩ + · simp only [hwm,ite_false] + rw [LabelledTree.eval_insert_edge _ + (clusterSearch_valid G n _ _ (F.erase (searchCrossing G Q R hc).2.2) + (searchAvailable_discover G ha _ _)) (Finset.notMem_erase _ _)] + exact ih _ _ _ hcard (searchAvailable_discover G ha _ _) + (Finset.disjoint_insert_left.mpr ⟨hwm,hm⟩) (ω.erase (searchCrossing G Q R hc).1) + (Finset.erase_subset_erase _ hω) + · simp only [heω,ite_false] + exact ih _ _ _ hcard (searchAvailable_erase G ha _ ) hm ω + (fun e he => Finset.mem_erase.mpr ⟨fun heq => heω (heq ▸ he),hω he⟩) + · simp only [false_iff] + exact seedMarked_false_of_no_crossing G Q R m hc hm ω hω + +end GraphMarkedSearch + +section GraphSearchCost +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +namespace ProbeTree + +def Budget (t : ProbeTree) (K d : ℕ) : Prop := ∀ l, queries t l ≤ K+d*marks t l + +lemma budget_done (b : Bool) (K d : ℕ) : Budget (.done b) K d := by + intro l + simp [queries,marks] + +lemma budget_mono {t : ProbeTree} {K L d : ℕ} (h : Budget t K d) (hKL : K ≤ L) : + Budget t L d := fun l => (h l).trans (Nat.add_le_add_right hKL _) + +lemma budget_edge {t₀ t₁ : ProbeTree} {K d : ℕ} (h₀ : Budget t₀ K d) (h₁ : Budget t₁ K d) : + Budget (.edge t₀ t₁) (K+1) d := by + intro l + cases l with + | inl l => simpa [queries,marks,Nat.add_right_comm] using Nat.add_le_add_right (h₀ l) 1 + | inr l => simpa [queries,marks,Nat.add_right_comm] using Nat.add_le_add_right (h₁ l) 1 + +lemma budget_mark {t₀ t₁ : ProbeTree} {K d : ℕ} + (h₀ : Budget t₀ (K+d) d) (h₁ : Budget t₁ (K+d) d) : + Budget (.mark t₀ t₁) K d := by + intro l + cases l with + | inl l => simpa [queries,marks,Nat.mul_add,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using h₀ l + | inr l => simpa [queries,marks,Nat.mul_add,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using h₁ l + +end ProbeTree + + +noncomputable def queryPotential (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Finset E := + Q.filter (fun e => ∃ v ∈ R, v ∈ G e) + +lemma queryPotential_erase (G : BondGraph V E) (Q : Finset E) (R : Finset V) (e : E) : + queryPotential G (Q.erase e) R = (queryPotential G Q R).erase e := by + ext a + simp [queryPotential,and_assoc] + +lemma queryPotential_insert (G : BondGraph V E) (Q : Finset E) (R : Finset V) (v : V) : + queryPotential G Q (insert v R) = queryPotential G Q R ∪ Q.filter (fun e => v ∈ G e) := by + ext a + simp [queryPotential,and_or_left,or_comm] + +lemma filtered_degree_erase (G : BondGraph V E) (Q : Finset E) (d : ℕ) + (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) (a : E) : + ∀ v, ((Q.erase a).filter (fun e => v ∈ G e)).card ≤ d := by + intro v + apply (Finset.card_le_card ?_).trans (hd v) + intro e he + exact Finset.mem_filter.mpr ⟨Finset.mem_of_mem_erase (Finset.mem_filter.mp he).1, + (Finset.mem_filter.mp he).2⟩ + +lemma queryPotential_discover_card (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (e : E) (v : V) (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + (queryPotential G (Q.erase e) (insert v R)).card ≤ + ((queryPotential G Q R).erase e).card+d := by + rw [queryPotential_insert,queryPotential_erase] + exact (Finset.card_union_le _ _).trans + (Nat.add_le_add_left (filtered_degree_erase G Q d hd e v) _) + + +theorem clusterSearch_budget (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) + (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + ProbeTree.Budget (clusterSearch G n Q R).forget (queryPotential G Q R).card d := by + induction n generalizing Q R with + | zero => exact ProbeTree.budget_done _ _ _ + | succ n ih => + simp only [clusterSearch] + split_ifs with hc + · obtain ⟨he,hv,hw,hends⟩ := searchCrossing_spec G Q R hc + have hpot : (searchCrossing G Q R hc).1 ∈ queryPotential G Q R := by + exact Finset.mem_filter.mpr ⟨he,_,hv,by rw [hends]; simp⟩ + have hpos : 0 < (queryPotential G Q R).card := Finset.card_pos.mpr ⟨_,hpot⟩ + have hclosed := ih (Q.erase (searchCrossing G Q R hc).1) R + (filtered_degree_erase G Q d hd _) + have hopen := ih (Q.erase (searchCrossing G Q R hc).1) + (insert (searchCrossing G Q R hc).2.2 R) (filtered_degree_erase G Q d hd _) + rw [queryPotential_erase,Finset.card_erase_of_mem hpot] at hclosed + have hnew := queryPotential_discover_card G Q R (searchCrossing G Q R hc).1 + (searchCrossing G Q R hc).2.2 d hd + rw [Finset.card_erase_of_mem hpot] at hnew + have hh := ProbeTree.budget_edge hclosed + (ProbeTree.budget_mark (ProbeTree.budget_mono hopen hnew) (ProbeTree.budget_done true _ _)) + have hcadd : (queryPotential G Q R).card-1+1 = (queryPotential G Q R).card := by omega + simpa only [LabelledTree.forget,hcadd] using hh + · exact ProbeTree.budget_done _ _ _ + +noncomputable def searchVertices (G : BondGraph V E) (Q : Finset E) : Finset V := + Q.biUnion fun e => (G e).toFinset + +lemma mem_searchVertices (G : BondGraph V E) {Q : Finset E} {e : E} (he : e ∈ Q) + {v : V} (hv : v ∈ G e) : v ∈ searchVertices G Q := + Finset.mem_biUnion.mpr ⟨e,he,Sym2.mem_toFinset.mpr hv⟩ + +noncomputable def markedClusterTree (G : BondGraph V E) (Q : Finset E) (x : V) : LabelledTree V E := + .mark x (clusterSearch G Q.card Q {x}) (.done true) + +lemma markedClusterTree_available (G : BondGraph V E) (Q : Finset E) (x : V) : + SearchAvailable G Q {x} ((insert x (searchVertices G Q)).erase x) := by + intro e he v hv + by_cases hx : v = x + · exact Or.inl (by simpa using hx) + · exact Or.inr (Finset.mem_erase.mpr ⟨hx,Finset.mem_insert_of_mem (mem_searchVertices G he hv)⟩) + +theorem markedClusterTree_valid (G : BondGraph V E) (Q : Finset E) (x : V) : + LabelledTree.Valid Q (insert x (searchVertices G Q)) (markedClusterTree G Q x) := + ⟨by simp,clusterSearch_valid G _ _ _ _ (markedClusterTree_available G Q x),trivial⟩ + +theorem markedClusterTree_budget (G : BondGraph V E) (Q : Finset E) (x : V) + (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + ProbeTree.Budget (markedClusterTree G Q x).forget 0 d := by + have hh := clusterSearch_budget G Q.card Q {x} d hd + have hcost : (queryPotential G Q {x}).card ≤ 0+d := by simpa [queryPotential] using hd x + exact ProbeTree.budget_mark (ProbeTree.budget_mono hh hcost) (ProbeTree.budget_done true _ _) + +theorem markedClusterTree_correct (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : + (markedClusterTree G Q x).eval ω m = true ↔ ∃ y ∈ m, Conn G (ω : Set E) x y := by + simp only [markedClusterTree,LabelledTree.eval] + by_cases hxm : x ∈ m + · simp only [hxm,ite_true,true_iff] + exact ⟨x,hxm,conn_refl G _ x⟩ + · simp only [hxm,ite_false] + rw [clusterSearch_correct G Q.card Q {x} ((insert x (searchVertices G Q)).erase x) m + le_rfl (markedClusterTree_available G Q x) (by simpa) ω hω] + simp only [SeedMarked,Finset.mem_singleton,exists_eq_left] + +end GraphSearchCost + +section MarkedFirstMoment +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem quadratic_test_bound {z L B : ℝ} (hL : 0 ≤ L) (hB : 0 < B) + (h : ∀ lam : ℝ, lam*z ≤ L+lam^2*B) : z ≤ Real.sqrt (4*B*L) := by + have hh := h (z/(2*B)) + have hid : z/(2*B)*z-(z/(2*B))^2*B = z^2/(4*B) := by + field_simp + ring + have hs : z^2/(4*B) ≤ L := by rw [← hid]; linarith + have hs' := (div_le_iff₀ (by positivity : 0 < 4*B)).mp hs + have hn : 0 ≤ 4*B*L := by positivity + have hsq := Real.sq_sqrt hn + have hpos := Real.sqrt_nonneg (4*B*L) + nlinarith + + +noncomputable def markedConnectionPolynomial (G : BondGraph V E) (Q : Finset E) + (x : V) (h p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => bernoulliPolynomial (insert x (searchVertices G Q)) + (fun m => if ∃ y ∈ m, Conn G (ω : Set E) x y then 1 else 0) h) p + +theorem markedConnectionPolynomial_eq_tree (G : BondGraph V E) (Q : Finset E) + (x : V) (h p : ℝ) : + markedConnectionPolynomial G Q x h p = + ProbeTree.successMass p h (markedClusterTree G Q x).forget := by + rw [← LabelledTree.expectation_eq _ (markedClusterTree_valid G Q x) p h] + apply bernoulliPolynomial_congr + intro ω hω + apply bernoulliPolynomial_congr + intro m _ + simp only [markedClusterTree_correct G Q x ω hω m] + +theorem markedConnectionPolynomial_ge_mark (G : BondGraph V E) (Q : Finset E) + (x : V) (p h : unitInterval) : (h:ℝ) ≤ markedConnectionPolynomial G Q x h p := by + rw [markedConnectionPolynomial_eq_tree,markedClusterTree,LabelledTree.forget, + ProbeTree.successMass_mark] + simp only [LabelledTree.forget,ProbeTree.successMass_done,ite_true,mul_one] + exact le_add_of_nonneg_left (mul_nonneg (sub_nonneg.mpr h.2.2) + (ProbeTree.successMass_nonneg p h _)) + + +theorem markedConnection_derivative_bound (G : BondGraph V E) (Q : Finset E) + (x : V) (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) + (d : ℕ) (hd : 0 < d) (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + (p:ℝ)*deriv (markedConnectionPolynomial G Q x h) p ≤ + (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* + markedConnectionPolynomial G Q x h p := by + let t := (markedClusterTree G Q x).forget + have ht : ProbeTree.IsMarkSearch t := .mark (clusterSearch_markSearch G _ _ _) + have hcost : ∀ l, ProbeTree.queries t l ≤ d*ProbeTree.marks t l := by + simpa only [ProbeTree.Budget,zero_add] using markedClusterTree_budget G Q x d hdeg + have hroot : (h:ℝ) ≤ ProbeTree.successMass p h t := by + simpa only [markedConnectionPolynomial_eq_tree] using markedConnectionPolynomial_ge_mark G Q x p h + have hB : 0 < (d:ℝ)/(8*h) := div_pos (by exact_mod_cast hd) (by positivity) + have hL : 0 ≤ Real.log (1/(h:ℝ)) := Real.log_nonneg ((one_le_div hh).mpr h.2.2) + have htest (lam : ℝ) : lam*(ProbeTree.successScore p h t/ProbeTree.successMass p h t) ≤ + Real.log (1/(h:ℝ))+lam^2*((d:ℝ)/(8*h)) := by + simpa only [mul_div_assoc] using ProbeTree.marked_score_bound p h hh ht d hcost hroot lam + have hz := quadratic_test_bound hL hB htest + have hsqrt : Real.sqrt (4*((d:ℝ)/(8*h))*Real.log (1/(h:ℝ))) = + Real.sqrt ((d:ℝ)/2)*Real.sqrt (Real.log (1/(h:ℝ))/h) := by + rw [show 4*((d:ℝ)/(8*h))*Real.log (1/(h:ℝ)) = + ((d:ℝ)/2)*(Real.log (1/(h:ℝ))/h) by ring,Real.sqrt_mul (by positivity)] + rw [hsqrt] at hz + have hH : 0 < ProbeTree.successMass p h t := hh.trans_le hroot + have hscore := (div_le_iff₀ hH).mp hz + rw [ProbeTree.successScore_eq_deriv] at hscore + have heq : markedConnectionPolynomial G Q x h = fun q => ProbeTree.successMass q h t := + funext fun q => markedConnectionPolynomial_eq_tree G Q x h q + rw [heq] + have hq : 0 < 1-(p:ℝ) := sub_pos.mpr hp + calc + _ = ((p:ℝ)*(1-p)*deriv (fun q => ProbeTree.successMass q h t) p)/(1-p) := by + field_simp + _ ≤ (Real.sqrt ((d:ℝ)/2)*Real.sqrt (Real.log (1/(h:ℝ))/h)* + ProbeTree.successMass p h t)/(1-p) := div_le_div_of_nonneg_right hscore hq.le + _ = _ := by ring + +theorem bernoulliPolynomial_open_difference (s : Finset E) (e : E) (he : e ∈ s) + (f : Finset E → ℝ) (p : ℝ) : + bernoulliPolynomial s (fun t => if e ∈ t then f t-f (t.erase e) else 0) p = + p*bernoulliPolynomial (s.erase e) (fun t => f (insert e t)-f t) p := by + conv_lhs => rw [← Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e s)] + have hclosed : bernoulliPolynomial (s.erase e) + (fun t => if e ∈ t then f t-f (t.erase e) else 0) p = 0 := by + rw [← bernoulliPolynomial_zero (s.erase e) p] + apply bernoulliPolynomial_congr + intro t ht + simp [show e ∉ t from fun hh => Finset.notMem_erase e s (ht hh)] + rw [hclosed,mul_zero,zero_add] + congr 1 + apply bernoulliPolynomial_congr + intro t ht + have het : e ∉ t := fun hh => Finset.notMem_erase e s (ht hh) + simp [het] + + +noncomputable def markedOpenPivotals (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (m : Finset V) : Finset E := + Q.filter fun e => e ∈ ω ∧ (∃ y ∈ m, Conn G (ω : Set E) x y) ∧ + ¬ ∃ y ∈ m, Conn G (ω.erase e : Set E) x y + + +noncomputable def markedPivotalMomentOne (G : BondGraph V E) (Q : Finset E) (x : V) + (h p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => bernoulliPolynomial (insert x (searchVertices G Q)) + (fun m => ((markedOpenPivotals G Q x ω m).card:ℝ)) h) p + +theorem marked_pivotal_russo (G : BondGraph V E) (Q : Finset E) (x : V) (h p : ℝ) : + markedPivotalMomentOne G Q x h p = p*deriv (markedConnectionPolynomial G Q x h) p := by + let F := insert x (searchVertices G Q) + let f : Finset E → Finset V → ℝ := fun ω m => + if ∃ y ∈ m, Conn G (ω : Set E) x y then 1 else 0 + have hcard (ω : Finset E) (m : Finset V) : ((markedOpenPivotals G Q x ω m).card:ℝ) = + ∑ e ∈ Q, if e ∈ ω then f ω m-f (ω.erase e) m else 0 := by + rw [markedOpenPivotals,Finset.card_filter,Nat.cast_sum] + apply Finset.sum_congr rfl + intro e _ + have hmono : (∃ y ∈ m, Conn G (ω.erase e : Set E) x y) → + ∃ y ∈ m, Conn G (ω : Set E) x y := by + rintro ⟨y,hy,hxy⟩ + exact ⟨y,hy,conn_mono G (by exact_mod_cast Finset.erase_subset e ω) hxy⟩ + by_cases he : e ∈ ω <;> by_cases h₁ : ∃ y ∈ m, Conn G (ω : Set E) x y <;> + by_cases h₀ : ∃ y ∈ m, Conn G (ω.erase e : Set E) x y <;> + simp only [f,he,h₁,h₀,and_true,and_false,not_true_eq_false, + not_false_eq_true,ite_true,ite_false,Nat.cast_one,Nat.cast_zero,sub_self,sub_zero] + exact False.elim (h₁ (hmono h₀)) + have heq : markedConnectionPolynomial G Q x h = + bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (f ω) h) := rfl + rw [heq,(hasDerivAt_bernoulliPolynomial Q _ p).deriv,Finset.mul_sum] + simp only [markedPivotalMomentOne,hcard,bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro e he + rw [← bernoulliPolynomial_open_difference Q e he (fun ω => bernoulliPolynomial F (f ω) h) p] + apply bernoulliPolynomial_congr + intro ω _ + by_cases heω : e ∈ ω + · simp only [heω,ite_true,F] + exact bernoulliPolynomial_sub _ _ _ _ + · simp only [heω,ite_false,bernoulliPolynomial_zero] + + +theorem marked_pivotal_first_moment (G : BondGraph V E) (Q : Finset E) (x : V) + (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + markedPivotalMomentOne G Q x h p ≤ + (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* + markedConnectionPolynomial G Q x h p := by + rw [marked_pivotal_russo] + exact markedConnection_derivative_bound G Q x p h hp hh d hd hdeg + +end MarkedFirstMoment + +section PivotalGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +def MarkedEvent (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) : Prop := + ∃ y ∈ m, Conn G ω x y + + +def OpenMarkedPivotal (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) + (e : E) : Prop := + e ∈ ω ∧ MarkedEvent G ω m x ∧ ¬MarkedEvent G (ω \ {e}) m x + +theorem markedEvent_mono (G : BondGraph V E) {ω η : Set E} (h : ω ⊆ η) + {m : Set V} {x : V} (hx : MarkedEvent G ω m x) : MarkedEvent G η m x := by + obtain ⟨y,hy,hxy⟩ := hx + exact ⟨y,hy,conn_mono G h hxy⟩ + +theorem edge_cluster_sides (G : BondGraph V E) (ω : Set E) (x : V) + {e : E} {a b : V} (he : e ∈ ω) (hab : G e = s(a,b)) : + a ∈ cluster G ω x ↔ b ∈ cluster G ω x := by + have hc : Conn G ω a b := .single ⟨e,he,hab⟩ + exact ⟨fun h => h.trans hc,fun h => h.trans (conn_symm G ω hc)⟩ + + +theorem conn_restrict_cluster_compl (G : BondGraph V E) (ω : Set E) (x : V) + {a b : V} (ha : a ∉ cluster G ω x) (hab : Conn G ω a b) : + Conn G (ω ∩ internalEdges G (cluster G ω x)ᶜ) a b := by + induction hab with + | refl => exact conn_refl G _ a + | @tail u v hau huv ih => + obtain ⟨e,he,heq⟩ := huv + have hu : u ∉ cluster G ω x := fun h => ha (h.trans (conn_symm G ω hau)) + have hv : v ∉ cluster G ω x := fun h => hu ((edge_cluster_sides G ω x he heq).mpr h) + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ + +theorem conn_restrict_cluster (G : BondGraph V E) (ω : Set E) (x : V) + {a b : V} (ha : a ∈ cluster G ω x) (hab : Conn G ω a b) : + Conn G (ω ∩ internalEdges G (cluster G ω x)) a b := by + induction hab with + | refl => exact conn_refl G _ a + | @tail u v hau huv ih => + obtain ⟨e,he,heq⟩ := huv + have hu : u ∈ cluster G ω x := ha.trans hau + have hv : v ∈ cluster G ω x := (edge_cluster_sides G ω x he heq).mp hu + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ + + +theorem openMarkedPivotal_oriented (G : BondGraph V E) (ω : Set E) (m : Set V) + (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) : + ∃ a b, G e = s(a,b) ∧ Conn G (ω \ {e}) x a ∧ + ¬Conn G (ω \ {e}) x b ∧ MarkedEvent G (ω \ {e}) m b := by + obtain ⟨y,hy,hxy⟩ := he.2.1 + obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) + exact ⟨a,b,h.symm⟩ + have heq : insert e (ω \ {e}) = ω := by + have heω : e ∈ ω := he.1 + ext d + simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] + by_cases h : d = e <;> simp_all + rw [← heq,conn_insert_iff G _ e a b x y hab] at hxy + rcases hxy with hxy | ⟨hxa,hby⟩ | ⟨hxb,hay⟩ + · exact (he.2.2 ⟨y,hy,hxy⟩).elim + · exact ⟨a,b,hab,hxa,fun hxb => he.2.2 ⟨y,hy,hxb.trans hby⟩,y,hy,hby⟩ + · exact ⟨b,a,hab.trans (Sym2.eq_swap ..),hxb, + fun hxa => he.2.2 ⟨y,hy,hxa.trans hay⟩,y,hy,hay⟩ + + +theorem pivotal_rootSide_disjoint_marks (G : BondGraph V E) (ω : Set E) + (m : Set V) (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) : + Disjoint (cluster G (ω \ {e}) x) m := by + rw [Set.disjoint_left] + exact fun y hy hm => he.2.2 ⟨y,hm,hy⟩ + + +theorem conn_delete_internal_of_outside (G : BondGraph V E) (ω : Set E) (x : V) + {f : E} {a b : V} (hf : f ∈ internalEdges G (cluster G ω x)) + (ha : a ∉ cluster G ω x) (hab : Conn G ω a b) : Conn G (ω \ {f}) a b := by + apply conn_mono G _ (conn_restrict_cluster_compl G ω x ha hab) + intro e he + refine ⟨he.1,?_⟩ + intro hef + have hef' : e = f := Set.mem_singleton_iff.mp hef + subst e + obtain ⟨u,v,heq⟩ : ∃ u v, G f = s(u,v) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G f) + exact ⟨a,b,h.symm⟩ + exact ((mem_internalEdges_of_ends G _ f u v heq).mp he.2).1 + ((mem_internalEdges_of_ends G _ f u v heq).mp hf).1 + + +theorem pivotal_other_sides (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) + {e f : E} (_he : OpenMarkedPivotal G ω m x e) + (hf : OpenMarkedPivotal G ω m x f) (hne : f ≠ e) : + f ∈ internalEdges G (cluster G (ω \ {e}) x) ∨ + f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by + obtain ⟨a,b,hab⟩ : ∃ a b, G f = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G f) + exact ⟨a,b,h.symm⟩ + have hop : f ∈ ω \ {e} := ⟨hf.1,hne⟩ + have hiff := edge_cluster_sides G (ω \ {e}) x hop hab + by_cases ha : a ∈ cluster G (ω \ {e}) x + · exact Or.inl ((mem_internalEdges_of_ends G _ f a b hab).mpr ⟨ha,hiff.mp ha⟩) + · exact Or.inr ((mem_internalEdges_of_ends G _ f a b hab).mpr ⟨ha,fun hb => ha (hiff.mpr hb)⟩) + + +theorem conn_delete_exterior_of_inside (G : BondGraph V E) (ω : Set E) (x : V) + {f : E} {a b : V} (hf : f ∈ internalEdges G (cluster G ω x)ᶜ) + (ha : a ∈ cluster G ω x) (hab : Conn G ω a b) : Conn G (ω \ {f}) a b := by + apply conn_mono G _ (conn_restrict_cluster G ω x ha hab) + intro e he + refine ⟨he.1,?_⟩ + intro hef + have hef' : e = f := Set.mem_singleton_iff.mp hef + subst e + obtain ⟨⟨u,v⟩,heq⟩ := Quot.exists_rep (G f) + exact ((mem_internalEdges_of_ends G _ f u v heq.symm).mp hf).1 + ((mem_internalEdges_of_ends G _ f u v heq.symm).mp he.2).1 + + +theorem pivotal_rootSide_ssubset (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) + {e f : E} (he : OpenMarkedPivotal G ω m x e) (hne : e ≠ f) + (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : + cluster G (ω \ {e}) x ⊂ cluster G (ω \ {f}) x := by + have hsub : cluster G (ω \ {e}) x ⊆ cluster G (ω \ {f}) x := by + intro y hy + exact conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_exterior_of_inside G (ω \ {e}) x hf (conn_refl G _ x) hy) + refine ⟨hsub,?_⟩ + obtain ⟨a,b,hab,hxa,hxb,_⟩ := openMarkedPivotal_oriented G ω m x he + intro hback + apply hxb + apply hback + exact (hsub hxa).tail ⟨e,⟨he.1,hne⟩,hab⟩ + + +theorem pivotal_rootSides_nested (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) + {e f : E} (he : OpenMarkedPivotal G ω m x e) + (hf : OpenMarkedPivotal G ω m x f) (hne : e ≠ f) : + cluster G (ω \ {e}) x ⊂ cluster G (ω \ {f}) x ∨ + cluster G (ω \ {f}) x ⊂ cluster G (ω \ {e}) x := by + rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | houtside + · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he + obtain ⟨y,hy,hby⟩ := hbm + have hby' : Conn G (ω \ {f}) b y := conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) + have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ + have ha : a ∉ cluster G (ω \ {f}) x := fun h => + hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) + exact Or.inr (pivotal_rootSide_ssubset G ω m x hf hne.symm + ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩)) + · exact Or.inl (pivotal_rootSide_ssubset G ω m x he hne houtside) + + +theorem conn_restrict_cluster_compl_of_subset (G : BondGraph V E) (ω : Set E) (x : V) + {η : Set E} (hη : η ⊆ ω) {a b : V} (ha : a ∉ cluster G ω x) + (hab : Conn G η a b) : Conn G (η ∩ internalEdges G (cluster G ω x)ᶜ) a b := by + induction hab with + | refl => exact conn_refl G _ a + | @tail u v hau huv ih => + obtain ⟨e,he,heq⟩ := huv + have hu : u ∉ cluster G ω x := fun h => ha (h.trans (conn_symm G ω (conn_mono G hη hau))) + have hv : v ∉ cluster G ω x := fun h => hu ((edge_cluster_sides G ω x (hη he) heq).mpr h) + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ + + + +theorem markedEvent_after_pivotal (G : BondGraph V E) (ω : Set E) (m : Set V) (x : V) + {e f : E} (he : OpenMarkedPivotal G ω m x e) (hne : e ≠ f) + {a b : V} (hab : G e = s(a,b)) (hxa : Conn G (ω \ {e}) x a) + (hxb : ¬Conn G (ω \ {e}) x b) + (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : + MarkedEvent G (ω \ {f}) m x ↔ + MarkedEvent G ((ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) \ {f}) m b := by + let W := cluster G (ω \ {e}) x + have heq : insert e ((ω \ {e}) \ {f}) = ω \ {f} := by + ext d + simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] + constructor + · rintro (rfl | ⟨⟨hd,hde⟩,hdf⟩) + · exact ⟨he.1,hne⟩ + · exact ⟨hd,hdf⟩ + · rintro ⟨hd,hdf⟩ + by_cases hde : d = e + · exact Or.inl hde + · exact Or.inr ⟨⟨hd,hde⟩,hdf⟩ + constructor + · rintro ⟨y,hy,hxy⟩ + rw [← heq,conn_insert_iff G _ e a b x y hab] at hxy + rcases hxy with hxy | ⟨_,hby⟩ | ⟨hxb',_⟩ + · exact (he.2.2 ⟨y,hy,conn_mono G Set.sdiff_subset hxy⟩).elim + · refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl_of_subset G (ω \ {e}) x + Set.sdiff_subset hxb hby)⟩ + intro d hd + exact ⟨⟨hd.1.1.1,hd.2⟩,hd.1.2⟩ + · exact (hxb (conn_mono G Set.sdiff_subset hxb')).elim + · rintro ⟨y,hy,hby⟩ + have hxa' : Conn G (ω \ {f}) x a := conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_exterior_of_inside G (ω \ {e}) x hf (conn_refl G _ x) hxa) + refine ⟨y,hy,(hxa'.tail ⟨e,⟨he.1,hne⟩,hab⟩).trans (conn_mono G ?_ hby)⟩ + exact fun _ h => ⟨h.1.1,h.2⟩ + + +theorem openMarkedPivotal_exterior_iff (G : BondGraph V E) (ω : Set E) (m : Set V) + (x : V) {e : E} (he : OpenMarkedPivotal G ω m x e) + {a b : V} (hab : G e = s(a,b)) (hxa : Conn G (ω \ {e}) x a) + (hxb : ¬Conn G (ω \ {e}) x b) (hbm : MarkedEvent G (ω \ {e}) m b) + (f : E) : + OpenMarkedPivotal G (ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) m b f ↔ + OpenMarkedPivotal G ω m x f ∧ f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by + have hbase : MarkedEvent G (ω ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) m b := by + obtain ⟨y,hy,hby⟩ := hbm + refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl G (ω \ {e}) x hxb hby)⟩ + exact fun _ h => ⟨h.1.1,h.2⟩ + have hexterior (hf : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by + intro h; subst f + exact ((mem_internalEdges_of_ends G _ e a b hab).mp hf).1 hxa + constructor + · intro hf + have hiff := markedEvent_after_pivotal G ω m x he (hexterior hf.1.2) hab hxa hxb hf.1.2 + exact ⟨⟨hf.1.1,he.2.1,fun h => hf.2.2 (hiff.mp h)⟩,hf.1.2⟩ + · rintro ⟨hf,hout⟩ + have hiff := markedEvent_after_pivotal G ω m x he (hexterior hout) hab hxa hxb hout + exact ⟨⟨hf.1,hout⟩,hbase,fun h => hf.2.2 (hiff.mpr h)⟩ + + +theorem cluster_finite_of_finite_edges (G : BondGraph V E) {ω : Set E} + (hω : ω.Finite) (x : V) : (cluster G ω x).Finite := by + let F : Finset V := insert x (hω.toFinset.biUnion fun e => (G e).toFinset) + apply F.finite_toSet.subset + intro y hxy + induction hxy with + | refl => exact Finset.mem_insert_self x _ + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + apply Finset.mem_insert_of_mem + apply Finset.mem_biUnion.mpr + exact ⟨e,hω.mem_toFinset.mpr he,by simp [heq]⟩ + + +noncomputable def pivotalRank (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : ℕ := + (cluster G (ω \ {e}) x).ncard + +theorem pivotalRank_injective (G : BondGraph V E) {ω : Set E} (hω : ω.Finite) + (m : Set V) (x : V) : Set.InjOn (pivotalRank G ω x) {e | OpenMarkedPivotal G ω m x e} := by + intro e he f hf hsame + by_contra hne + rcases pivotal_rootSides_nested G ω m x he hf hne with h | h + · have hh := Set.ncard_lt_ncard h (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) + exact (Nat.ne_of_lt hh) hsame + · have hh := Set.ncard_lt_ncard h (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) + exact (Nat.ne_of_lt hh) hsame.symm + + +theorem pivotalRank_lt_iff (G : BondGraph V E) {ω : Set E} (hω : ω.Finite) + (m : Set V) (x : V) {e f : E} (he : OpenMarkedPivotal G ω m x e) + (hf : OpenMarkedPivotal G ω m x f) : + pivotalRank G ω x e < pivotalRank G ω x f ↔ + f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by + have hexterior (hout : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by + obtain ⟨a,b,hab,hxa,_,_⟩ := openMarkedPivotal_oriented G ω m x he + intro h; subst f + exact ((mem_internalEdges_of_ends G _ e a b hab).mp hout).1 hxa + constructor + · intro hlt + have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) + rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | hout + · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he + obtain ⟨y,hy,hby⟩ := hbm + have hby' : Conn G (ω \ {f}) b y := conn_mono G + (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) + have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ + have ha : a ∉ cluster G (ω \ {f}) x := fun h => + hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) + have hs := pivotal_rootSide_ssubset G ω m x hf hne.symm + ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩) + have hrev := Set.ncard_lt_ncard hs + (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) + exact (Nat.not_lt_of_ge (Nat.le_of_lt hrev) hlt).elim + · exact hout + · intro hout + exact Set.ncard_lt_ncard (pivotal_rootSide_ssubset G ω m x he (hexterior hout) hout) + (cluster_finite_of_finite_edges G (hω.subset Set.sdiff_subset) x) + +end PivotalGeometry + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Exploration/Moments.lean b/lean/OAI/Probability/UnimodularPercolation/Exploration/Moments.lean index 266cf36c0c6ec555502b96fdd02df2d6f9cc5b3a..58f20a82f835bf42c2fd84704a4ed2f07cc01087 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Exploration/Moments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Exploration/Moments.lean @@ -1,928 +1,928 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.Marked - -namespace OAI - -/-! Recursive marked moments and exponential estimates. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section OrderedPivotalMoments -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem sum_choose_rank_suffix {I : Type*} (P : Finset I) (rank : I → ℕ) - (hinj : Set.InjOn rank (P : Set I)) (i : ℕ) : - (∑ e ∈ P, ((P.filter fun f => rank e < rank f).card).choose i) = - P.card.choose (i+1) := by - induction P using Finset.strongInductionOn with - | _ P ih => - rcases P.eq_empty_or_nonempty with rfl | hP - · simp - obtain ⟨e,he,hmin⟩ := Finset.exists_min_image P rank hP - have hT : P.erase e ⊂ P := Finset.erase_ssubset he - have hinjT : Set.InjOn rank (↑(P.erase e) : Set I) := fun a ha b hb => - hinj (Finset.mem_of_mem_erase ha) (Finset.mem_of_mem_erase hb) - have hroot : P.filter (fun f => rank e < rank f) = P.erase e := by - ext f - simp only [Finset.mem_filter,Finset.mem_erase] - constructor - · rintro ⟨hf,hlt⟩ - exact ⟨fun h => (Nat.ne_of_lt hlt) (congrArg rank h.symm),hf⟩ - · rintro ⟨hne,hf⟩ - exact ⟨hf,lt_of_le_of_ne (hmin f hf) (fun h => hne (hinj he hf h).symm)⟩ - have hrest (f : I) (hf : f ∈ P.erase e) : - P.filter (fun g => rank f < rank g) = (P.erase e).filter (fun g => rank f < rank g) := by - ext g - simp only [Finset.mem_filter,Finset.mem_erase] - constructor - · rintro ⟨hg,hfg⟩ - refine ⟨⟨?_,hg⟩,hfg⟩ - intro h; subst g - exact (not_lt_of_ge (hmin f (Finset.mem_of_mem_erase hf))) hfg - · exact fun h => ⟨h.1.2,h.2⟩ - calc - _ = (∑ f ∈ P.erase e, ((P.filter fun g => rank f < rank g).card).choose i) + - ((P.filter fun f => rank e < rank f).card).choose i := - (Finset.sum_erase_add _ _ he).symm - _ = (∑ f ∈ P.erase e, (((P.erase e).filter fun g => rank f < rank g).card).choose i) + - (P.erase e).card.choose i := by - rw [hroot] - congr 1 - exact Finset.sum_congr rfl fun f hf => congrArg (fun s : Finset I => s.card.choose i) (hrest f hf) - _ = (P.erase e).card.choose (i+1)+(P.erase e).card.choose i := by rw [ih _ hT hinjT] - _ = P.card.choose (i+1) := by - have hc : (P.erase e).card+1=P.card := by - rw [Finset.card_erase_of_mem he] - have hp := Finset.card_pos.mpr hP - omega - rw [← hc,Nat.choose_succ_succ] - simp [Nat.succ_eq_add_one,Nat.add_comm] - -end OrderedPivotalMoments - -section MarkedRecursion -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem cluster_union_external (G : BondGraph V E) (ω η : Set E) (x : V) (W : Set V) - (hω : cluster G ω x ⊆ W) (hη : η ⊆ internalEdges G Wᶜ) : - cluster G (ω ∪ η) x = cluster G ω x := by - apply Set.Subset.antisymm - · intro y hy - induction hy with - | refl => exact conn_refl G ω x - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - rcases he with he | he - · exact ih.tail ⟨e,he,heq⟩ - · exact (((mem_internalEdges_of_ends G _ e a b heq).mp (hη he)).1 (hω ih)).elim - · exact fun _ h => conn_mono G Set.subset_union_left h - - -theorem cluster_union_external_eq_iff (G : BondGraph V E) (ω η : Set E) - (x : V) (W : Set V) (hη : η ⊆ internalEdges G Wᶜ) : - cluster G (ω ∪ η) x = W ↔ cluster G ω x = W := by - constructor - · intro h - have hω : cluster G ω x ⊆ W := fun y hy => h ▸ conn_mono G Set.subset_union_left hy - rwa [cluster_union_external G ω η x W hω hη] at h - · intro h - rw [cluster_union_external G ω η x W (h ▸ Set.Subset.rfl) hη,h] - - -theorem markedEvent_internal_marks (G : BondGraph V E) (ω : Set E) (m W : Set V) - (x : V) (hx : x ∈ W) (hω : ω ⊆ internalEdges G W) : - MarkedEvent G ω m x ↔ MarkedEvent G ω (m ∩ W) x := by - constructor - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,⟨hy,conn_internal_endpoint G W hx (conn_mono G - (ω₁ := ω) (ω₂ := ω ∩ internalEdges G W) (fun _ h => ⟨h,hω h⟩) hxy)⟩,hxy⟩ - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,hy.1,hxy⟩ - -theorem openMarkedPivotal_internal_marks (G : BondGraph V E) (ω : Set E) - (m W : Set V) (x : V) (hx : x ∈ W) (hω : ω ⊆ internalEdges G W) (e : E) : - OpenMarkedPivotal G ω m x e ↔ OpenMarkedPivotal G ω (m ∩ W) x e := by - simp only [OpenMarkedPivotal,markedEvent_internal_marks G ω m W x hx hω, - markedEvent_internal_marks G (ω \ {e}) m W x hx (Set.Subset.trans Set.sdiff_subset hω)] - - -theorem openMarkedPivotal_insert_cut (G : BondGraph V E) (ω : Set E) (m W : Set V) - (x : V) {e : E} {a b : V} (hW : cluster G ω x = W) - (hab : G e = s(a,b)) (ha : a ∈ W) (hb : b ∉ W) : - OpenMarkedPivotal G (insert e ω) m x e ↔ - Disjoint W m ∧ MarkedEvent G (ω ∩ internalEdges G Wᶜ) (m ∩ Wᶜ) b := by - have he : e ∉ ω := fun he => hb (hW ▸ ((edge_cluster_sides G ω x he hab).mp (hW ▸ ha))) - have hdel : insert e ω \ {e} = ω := by ext f; simp [he] - have hxa : Conn G ω x a := by change a ∈ cluster G ω x; rwa [hW] - constructor - · intro hp - have hdis := pivotal_rootSide_disjoint_marks G (insert e ω) m x hp - rw [hdel,hW] at hdis - refine ⟨hdis,?_⟩ - obtain ⟨y,hy,hxy⟩ := hp.2.1 - rw [conn_insert_iff G ω e a b x y hab] at hxy - rcases hxy with hxy | ⟨_,hby⟩ | ⟨hxb,_⟩ - · exact (Set.disjoint_left.mp hdis (hW ▸ hxy) hy).elim - · have hby' := conn_restrict_cluster_compl G ω x (a := b) (hW ▸ hb) hby - rw [hW] at hby' - exact (markedEvent_internal_marks G _ m Wᶜ b hb Set.inter_subset_right).mp ⟨y,hy,hby'⟩ - · exact (hb (hW ▸ hxb)).elim - · rintro ⟨hdis,y,hy,hby⟩ - refine ⟨Set.mem_insert _ _,?_,?_⟩ - · exact ⟨y,hy.1,(conn_mono G (Set.subset_insert e ω) hxa).tail - ⟨e,Set.mem_insert _ _,hab⟩ |>.trans (conn_mono G - (fun _ h => Set.mem_insert_of_mem _ h.1) hby)⟩ - · rw [hdel] - rintro ⟨z,hz,hxz⟩ - exact Set.disjoint_left.mp hdis (hW ▸ hxz) hz - -@[simp] theorem mem_markedOpenPivotals (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (m : Finset V) (e : E) : - e ∈ markedOpenPivotals G Q x ω m ↔ e ∈ Q ∧ OpenMarkedPivotal G ω m x e := by - simp only [markedOpenPivotals,Finset.mem_filter,OpenMarkedPivotal,MarkedEvent,Finset.coe_erase, - Finset.mem_coe] - - -noncomputable def markedMomentValue (G : BondGraph V E) (Q : Finset E) (x : V) - (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := - if MarkedEvent G ω m x then ((markedOpenPivotals G Q x ω m).card.choose i : ℝ) else 0 - - -theorem markedMomentValue_succ (G : BondGraph V E) (Q : Finset E) (x : V) - (i : ℕ) (ω : Finset E) (m : Finset V) : - markedMomentValue G Q x (i+1) ω m = - ∑ e ∈ markedOpenPivotals G Q x ω m, - (((markedOpenPivotals G Q x ω m).filter - (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ)).card.choose i : ℝ) := by - have hinj : Set.InjOn (pivotalRank G ω x) (↑(markedOpenPivotals G Q x ω m) : Set E) := by - intro e he f hf - exact pivotalRank_injective G ω.finite_toSet m x - ((mem_markedOpenPivotals G Q x ω m e).mp he).2 - ((mem_markedOpenPivotals G Q x ω m f).mp hf).2 - have hs := sum_choose_rank_suffix (markedOpenPivotals G Q x ω m) (pivotalRank G ω x) hinj i - have heq (e : E) (he : e ∈ markedOpenPivotals G Q x ω m) : - (markedOpenPivotals G Q x ω m).filter (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) = - (markedOpenPivotals G Q x ω m).filter (fun f => pivotalRank G ω x e < pivotalRank G ω x f) := by - apply Finset.filter_congr - intro f hf - exact (pivotalRank_lt_iff G ω.finite_toSet m x - ((mem_markedOpenPivotals G Q x ω m e).mp he).2 - ((mem_markedOpenPivotals G Q x ω m f).mp hf).2).symm - by_cases h : MarkedEvent G ω m x - · simp only [markedMomentValue,h,ite_true] - rw [← hs,Nat.cast_sum] - apply Finset.sum_congr rfl - intro e he - rw [heq e he] - · have hempty : markedOpenPivotals G Q x ω m = ∅ := by - apply Finset.eq_empty_iff_forall_notMem.mpr - intro e he - exact h ((mem_markedOpenPivotals G Q x ω m e).mp he).2.2.1 - simp [markedMomentValue,h,hempty] - - -theorem conn_mem_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) - {ω : Set E} (hω : ω ⊆ Q) {y : V} (hxy : Conn G ω x y) : - y ∈ insert x (searchVertices G Q) := by - induction hxy with - | refl => exact Finset.mem_insert_self _ _ - | @tail a b hxa hab ih => - obtain ⟨e,he,heq⟩ := hab - exact Finset.mem_insert_of_mem (mem_searchVertices G (hω he) (by simp [heq])) - -theorem markedEvent_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) - {ω : Set E} (hω : ω ⊆ Q) (m : Set V) : - MarkedEvent G ω m x ↔ MarkedEvent G ω (m ∩ ↑(insert x (searchVertices G Q))) x := by - constructor - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,⟨hy,conn_mem_searchSupport G Q x hω hxy⟩,hxy⟩ - · rintro ⟨y,hy,hxy⟩ - exact ⟨y,hy.1,hxy⟩ - -theorem markedOpenPivotals_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : - markedOpenPivotals G Q x ω m = - markedOpenPivotals G Q x ω (m ∩ insert x (searchVertices G Q)) := by - ext e - simp only [mem_markedOpenPivotals,OpenMarkedPivotal,Finset.coe_inter] - rw [markedEvent_searchSupport G Q x (by exact_mod_cast hω), - markedEvent_searchSupport G Q x (ω := (ω : Set E) \ {e}) - (fun _ h => hω h.1)] - -theorem markedMomentValue_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) - (i : ℕ) (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : - markedMomentValue G Q x i ω m = - markedMomentValue G Q x i ω (m ∩ insert x (searchVertices G Q)) := by - unfold markedMomentValue - rw [markedOpenPivotals_searchSupport G Q x ω hω m] - simp only [Finset.coe_inter] - rw [markedEvent_searchSupport G Q x (by exact_mod_cast hω)] - -@[simp] theorem markedMomentValue_zero (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (m : Finset V) : - markedMomentValue G Q x 0 ω m = if MarkedEvent G ω m x then 1 else 0 := by - simp only [markedMomentValue,Nat.choose_zero_right,Nat.cast_one] - -@[simp] theorem markedMomentValue_one (G : BondGraph V E) (Q : Finset E) (x : V) - (ω : Finset E) (m : Finset V) : - markedMomentValue G Q x 1 ω m = ((markedOpenPivotals G Q x ω m).card : ℝ) := by - by_cases h : MarkedEvent G ω m x - · simp [markedMomentValue,h] - · have he : markedOpenPivotals G Q x ω m = ∅ := by - apply Finset.eq_empty_iff_forall_notMem.mpr - intro e he - exact h ((mem_markedOpenPivotals G Q x ω m e).mp he).2.2.1 - simp [markedMomentValue,h,he] - - -noncomputable def finiteMarkedMoment (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (i : ℕ) (h p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (markedMomentValue G Q x i ω) h) p - -theorem finiteMarkedMoment_support (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (i : ℕ) (h p : ℝ) (hF : insert x (searchVertices G Q) ⊆ F) : - finiteMarkedMoment G Q F x i h p = - finiteMarkedMoment G Q (insert x (searchVertices G Q)) x i h p := by - apply bernoulliPolynomial_congr - intro ω hω - rw [← bernoulliPolynomial_restrict _ F hF] - apply bernoulliPolynomial_congr - intro m _ - exact markedMomentValue_searchSupport G Q x i ω hω m - - -theorem finiteMarkedMoment_first_bound (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (hF : insert x (searchVertices G Q) ⊆ F) : - finiteMarkedMoment G Q F x 1 h p ≤ - (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* - finiteMarkedMoment G Q F x 0 h p := by - rw [finiteMarkedMoment_support G Q F x 1 h p hF, - finiteMarkedMoment_support G Q F x 0 h p hF] - simpa only [finiteMarkedMoment,markedMomentValue_one,markedMomentValue_zero,MarkedEvent, - markedPivotalMomentOne,markedConnectionPolynomial,bernoulliPolynomial,Finset.mem_coe] using - marked_pivotal_first_moment G Q x p h hp hh d hd hdeg - -noncomputable def exteriorBonds (G : BondGraph V E) (Q : Finset E) (W : Set V) : Finset E := - Q.filter fun e => e ∈ internalEdges G Wᶜ - -noncomputable def exteriorMarks (m : Finset V) (W : Set V) : Finset V := - m.filter fun x => x ∉ W - -@[simp] theorem coe_exteriorBonds (G : BondGraph V E) (Q : Finset E) (W : Set V) : - (exteriorBonds G Q W : Set E) = (Q : Set E) ∩ internalEdges G Wᶜ := by - ext e; simp [exteriorBonds] - -@[simp] theorem coe_exteriorMarks (m : Finset V) (W : Set V) : - (exteriorMarks m W : Set V) = (m : Set V) ∩ Wᶜ := by - ext x; simp [exteriorMarks] - - -theorem markedOpenPivotals_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) - (x : V) (ω : Finset E) (m : Finset V) {e : E} - (he : OpenMarkedPivotal G ω m x e) : - markedOpenPivotals G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) - (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) = - (markedOpenPivotals G Q x ω m).filter - (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) := by - obtain ⟨a,b,hab,hxa,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he - have hb := (cut_unique G (cluster G (↑ω \ {e}) x) hab hxa hxb).2 - rw [← hb] - ext f - simp only [mem_markedOpenPivotals,exteriorBonds,Finset.mem_filter,coe_exteriorMarks, - Finset.coe_filter] - have hmarks := openMarkedPivotal_internal_marks G - ((ω : Set E) ∩ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) - m (cluster G (↑ω \ {e}) x)ᶜ b hxb Set.inter_subset_right f - have hiff := openMarkedPivotal_exterior_iff G ω m x he hab hxa hxb hbm f - change (f ∈ Q ∧ f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) ∧ - OpenMarkedPivotal G ((ω : Set E) ∩ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) - ((m : Set V) ∩ (cluster G (↑ω \ {e}) x)ᶜ) b f ↔ _ - rw [← hmarks,hiff] - tauto - - -theorem markedMomentValue_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) - (x : V) (i : ℕ) (ω : Finset E) (m : Finset V) {e : E} - (he : OpenMarkedPivotal G ω m x e) : - markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) i - (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) = - (((markedOpenPivotals G Q x ω m).filter - (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ)).card.choose i : ℝ) := by - have hsuccess : MarkedEvent G (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) := by - obtain ⟨a,b,hab,hxa,hxb,y,hy,hby⟩ := openMarkedPivotal_oriented G ω m x he - rw [← (cut_unique G (cluster G (↑ω \ {e}) x) hab hxa hxb).2, - coe_exteriorBonds,coe_exteriorMarks] - apply (markedEvent_internal_marks G _ m (cluster G (↑ω \ {e}) x)ᶜ b hxb - Set.inter_subset_right).mp - refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl G (↑ω \ {e}) x hxb hby)⟩ - exact fun _ h => ⟨h.1.1,h.2⟩ - rw [markedMomentValue,ite_eq_left hsuccess,markedOpenPivotals_exterior G Q x ω m he] - - -theorem markedMomentValue_succ_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) - (x : V) (i : ℕ) (ω : Finset E) (m : Finset V) : - markedMomentValue G Q x (i+1) ω m = ∑ e ∈ Q, - if OpenMarkedPivotal G ω m x e then - markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) i - (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) else 0 := by - rw [markedMomentValue_succ] - trans ∑ e ∈ markedOpenPivotals G Q x ω m, - markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) i - (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) - · apply Finset.sum_congr rfl - intro e he - exact (markedMomentValue_exterior G Q x i ω m - ((mem_markedOpenPivotals G Q x ω m e).mp he).2).symm - · have heq : markedOpenPivotals G Q x ω m = Q.filter (fun e => OpenMarkedPivotal G ω m x e) := by - ext e; simp only [mem_markedOpenPivotals,Finset.mem_filter] - rw [heq,Finset.sum_filter] - -end MarkedRecursion - -section CutFactor -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Nonempty V] - -noncomputable def cutMomentValue (G : BondGraph V E) (Q : Finset E) (x : V) - (e : E) (W : Finset V) (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := - if cluster G ω x = (W : Set V) then - if Disjoint (W : Set V) (m : Set V) then - markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i - (exteriorBonds G ω W) (exteriorMarks m W) - else 0 - else 0 - -omit [Nonempty V] in -theorem cut_not_exterior (G : BondGraph V E) (W : Set V) {e : E} - (hc : CutExists G W e) : e ∉ internalEdges G Wᶜ := by - obtain ⟨a,b,hab,ha,hb⟩ := hc - intro he - exact ((mem_internalEdges_of_ends G Wᶜ e a b hab).mp he).1 ha - -omit [Nonempty V] in -theorem exteriorBonds_subset_erase (G : BondGraph V E) (Q : Finset E) - (W : Set V) {e : E} (hc : CutExists G W e) : exteriorBonds G Q W ⊆ Q.erase e := by - intro f hf - obtain ⟨hf,hout⟩ := Finset.mem_filter.mp hf - exact Finset.mem_erase.mpr ⟨fun h => cut_not_exterior G W hc (h ▸ hout),hf⟩ - - -theorem cutMomentValue_blocks (G : BondGraph V E) (Q : Finset E) (F W : Finset V) - (x : V) (e : E) (i : ℕ) (a b : Finset E) (u v : Finset V) - (ha : a ⊆ (Q.erase e) \ exteriorBonds G Q W) - (hb : b ⊆ exteriorBonds G Q W) (hu : u ⊆ W) (hv : v ⊆ F \ W) : - cutMomentValue G Q x e W i (a ∪ b) (u ∪ v) = - (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * - (if u = ∅ then (1:ℝ) else 0) * - markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i b v := by - have hbout : (b : Set E) ⊆ internalEdges G (W : Set V)ᶜ := - fun f hf => (Finset.mem_filter.mp (hb hf)).2 - have hc := cluster_union_external_eq_iff G (a : Set E) b x W hbout - have he : exteriorBonds G (a ∪ b) W = b := by - ext f - simp only [exteriorBonds,Finset.mem_filter,Finset.mem_union] - constructor - · rintro ⟨hf,hout⟩ - rcases hf with hf | hf - · have hfa := Finset.mem_sdiff.mp (ha hf) - exact (hfa.2 (Finset.mem_filter.mpr ⟨Finset.mem_of_mem_erase hfa.1,hout⟩)).elim - · exact hf - · exact fun hf => ⟨Or.inr hf,hbout hf⟩ - have hm : exteriorMarks (u ∪ v) W = v := by - ext y - simp only [exteriorMarks,Finset.mem_filter,Finset.mem_union,Finset.mem_coe] - constructor - · rintro ⟨hy,hyW⟩ - rcases hy with hy | hy - · exact (hyW (hu hy)).elim - · exact hy - · intro hy - exact ⟨Or.inr hy,(Finset.mem_sdiff.mp (hv hy)).2⟩ - have hd : Disjoint (W : Set V) ((u ∪ v : Finset V) : Set V) ↔ u = ∅ := by - constructor - · intro h - apply Finset.eq_empty_iff_forall_notMem.mpr - intro y hy - exact Set.disjoint_left.mp h (hu hy) (Finset.mem_union_left v hy) - · rintro rfl - apply Set.disjoint_left.mpr - intro y hy hyv - have hyv' : y ∈ v := by simpa using hyv - exact (Finset.mem_sdiff.mp (hv hyv')).2 hy - rw [Finset.coe_union] at hd - simp only [cutMomentValue,Finset.coe_union,hc,hd,he,hm] - split_ifs <;> simp_all - -omit [Nonempty V] in - -theorem bernoulliPolynomial_empty_indicator (F : Finset V) (h : ℝ) : - bernoulliPolynomial F (fun m => if m = ∅ then (1:ℝ) else 0) h = (1-h)^F.card := by - unfold bernoulliPolynomial - rw [Finset.sum_eq_single ∅] - · simp - · intro m hm hne - simp [hne] - · simp - - -theorem cutMoment_factor (G : BondGraph V E) (Q : Finset E) (F W : Finset V) - (x : V) (e : E) (i : ℕ) (h p : ℝ) (hW : W ⊆ F) (hc : CutExists G W e) : - bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (cutMomentValue G Q x e W i ω) h) p = - bernoulliPolynomial ((Q.erase e) \ exteriorBonds G Q W) - (fun a => if cluster G a x = (W : Set V) then (1:ℝ) else 0) p * - (1-h)^W.card * finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) - (cutOutside G W e) i h p := by - let R := exteriorBonds G Q W - let A := (Q.erase e) \ R - let B := F \ W - have hR : R ⊆ Q.erase e := exteriorBonds_subset_erase G Q W hc - have hQR : Q.erase e = A ∪ R := by - dsimp [A]; ext f; simp only [Finset.mem_union,Finset.mem_sdiff] - tauto - have hAR : Disjoint A R := Finset.disjoint_sdiff.symm - have hFB : F = W ∪ B := (Finset.union_sdiff_of_subset hW).symm - have hWB : Disjoint W B := Finset.disjoint_sdiff - conv_lhs => rw [hQR,bernoulliPolynomial_union A R hAR] - trans bernoulliPolynomial A (fun a => - (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * - ((1-h)^W.card * finiteMarkedMoment G R B (cutOutside G W e) i h p)) p - · apply bernoulliPolynomial_congr - intro a ha - trans bernoulliPolynomial R (fun b => - (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * (1-h)^W.card * - bernoulliPolynomial B (markedMomentValue G R (cutOutside G W e) i b) h) p - · apply bernoulliPolynomial_congr - intro b hb - rw [hFB,bernoulliPolynomial_union W B hWB] - trans bernoulliPolynomial W (fun u => - (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * - (if u = ∅ then (1:ℝ) else 0) * - bernoulliPolynomial B (markedMomentValue G R (cutOutside G W e) i b) h) h - · apply bernoulliPolynomial_congr - intro u hu - rw [← bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro v hv - exact cutMomentValue_blocks G Q F W x e i a b u v ha hb hu hv - · rw [bernoulliPolynomial_mul_const,bernoulliPolynomial_const_mul, - bernoulliPolynomial_empty_indicator] - · rw [bernoulliPolynomial_const_mul] - exact mul_assoc _ _ _ - · rw [bernoulliPolynomial_mul_const] - exact (mul_assoc _ _ _).symm - -end CutFactor - -section PointwiseRecursion -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Nonempty V] - -noncomputable def pivotalSuffixValue (G : BondGraph V E) (Q : Finset E) (x : V) - (e : E) (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := - if OpenMarkedPivotal G ω m x e then - markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) - (cutOutside G (cluster G (↑ω \ {e}) x) e) i - (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) - (exteriorMarks m (cluster G (↑ω \ {e}) x)) else 0 - - -theorem pivotalSuffixValue_insert (G : BondGraph V E) (Q : Finset E) (x : V) - (e : E) (i : ℕ) (ω : Finset E) (he : e ∉ ω) (m : Finset V) : - pivotalSuffixValue G Q x e i (insert e ω) m = - if CutExists G (cluster G ω x) e then - if Disjoint (cluster G ω x) (m : Set V) then - markedMomentValue G (exteriorBonds G Q (cluster G ω x)) - (cutOutside G (cluster G ω x) e) i - (exteriorBonds G ω (cluster G ω x)) (exteriorMarks m (cluster G ω x)) - else 0 - else 0 := by - have hdel : ((insert e ω : Finset E) : Set E) \ {e} = (ω : Set E) := by - simp [he] - by_cases hc : CutExists G (cluster G ω x) e - · obtain ⟨hab,ha,hb⟩ := cut_spec G (cluster G ω x) hc - have heout := cut_not_exterior G (cluster G ω x) hc - have hbe : exteriorBonds G (insert e ω) (cluster G ω x) = exteriorBonds G ω (cluster G ω x) := by - ext f - simp only [exteriorBonds,Finset.mem_filter,Finset.mem_insert] - constructor - · rintro ⟨hf,hout⟩ - rcases hf with rfl | hf - · exact (heout hout).elim - · exact ⟨hf,hout⟩ - · exact fun h => ⟨Or.inr h.1,h.2⟩ - have hp := openMarkedPivotal_insert_cut G (ω : Set E) m (cluster G ω x) x rfl hab ha hb - have hps : OpenMarkedPivotal G (insert e ω : Finset E) m x e ↔ - Disjoint (cluster G ω x) (m : Set V) ∧ - MarkedEvent G (exteriorBonds G ω (cluster G ω x)) - (exteriorMarks m (cluster G ω x)) (cutOutside G (cluster G ω x) e) := by - simpa only [Finset.coe_insert,coe_exteriorBonds,coe_exteriorMarks] using hp - simp only [pivotalSuffixValue,hdel,hbe,hc,ite_true,hps] - by_cases hd : Disjoint (cluster G ω x) (m : Set V) <;> - by_cases hm : MarkedEvent G (exteriorBonds G ω (cluster G ω x)) - (exteriorMarks m (cluster G ω x)) (cutOutside G (cluster G ω x) e) <;> - simp only [markedMomentValue,hd,hm,and_true,and_false,ite_true,ite_false] - · have hn : ¬OpenMarkedPivotal G (insert e ω : Finset E) m x e := by - intro hp - obtain ⟨a,b,hab,hxa,hxb,_⟩ := openMarkedPivotal_oriented G (insert e ω : Finset E) m x hp - rw [hdel] at hxa hxb - exact hc ⟨a,b,hab,hxa,hxb⟩ - simp only [pivotalSuffixValue,hn,hc,ite_false] - -noncomputable def finiteRootComponent (G : BondGraph V E) (ω : Finset E) (x : V) : Finset V := - (cluster_finite_of_finite_edges G ω.finite_toSet x).toFinset - -omit [Nonempty V] in -@[simp] -theorem coe_finiteRootComponent (G : BondGraph V E) (ω : Finset E) (x : V) : - (finiteRootComponent G ω x : Set V) = cluster G ω x := by simp [finiteRootComponent] - -omit [Nonempty V] in -theorem finiteRootComponent_subset (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (ω : Finset E) (hω : ω ⊆ Q) (hF : insert x (searchVertices G Q) ⊆ F) : - finiteRootComponent G ω x ⊆ F := by - intro y hy - have hxy : Conn G (ω : Set E) x y := by - change y ∈ (finiteRootComponent G ω x : Set V) at hy - rwa [coe_finiteRootComponent] at hy - exact hF (conn_mem_searchSupport G Q x (by exact_mod_cast hω) hxy) - -omit [Nonempty V] in - -theorem sum_component_partition (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (ω : Finset E) (hω : ω ⊆ Q) (hF : insert x (searchVertices G Q) ⊆ F) - (f : Finset V → ℝ) : - (∑ W ∈ F.powerset, if cluster G ω x = (W : Set V) then f W else 0) = - f (finiteRootComponent G ω x) := by - have hmem : finiteRootComponent G ω x ∈ F.powerset := - Finset.mem_powerset.mpr (finiteRootComponent_subset G Q F x ω hω hF) - rw [Finset.sum_eq_single_of_mem _ hmem] - · simp - · intro W hW hne - have hn : cluster G ω x ≠ (W : Set V) := by - intro h - apply hne - apply Finset.coe_injective - exact h.symm.trans (coe_finiteRootComponent G ω x).symm - simp [hn] - - -theorem pivotalSuffixValue_component_sum (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (e : E) (i : ℕ) (ω : Finset E) (he : e ∉ ω) (hω : ω ⊆ Q) - (hF : insert x (searchVertices G Q) ⊆ F) (m : Finset V) : - pivotalSuffixValue G Q x e i (insert e ω) m = ∑ W ∈ F.powerset, - if CutExists G W e then cutMomentValue G Q x e W i ω m else 0 := by - rw [pivotalSuffixValue_insert G Q x e i ω he m] - symm - trans ∑ W ∈ F.powerset, if cluster G ω x = (W : Set V) then - (if CutExists G W e then - if Disjoint (W : Set V) (m : Set V) then - markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i - (exteriorBonds G ω W) (exteriorMarks m W) else 0 - else 0) else 0 - · apply Finset.sum_congr rfl - intro W _ - by_cases hc : CutExists G W e <;> by_cases hw : cluster G ω x = (W : Set V) <;> - simp [cutMomentValue,hc,hw] - · rw [sum_component_partition G Q F x ω hω hF] - simp only [coe_finiteRootComponent] - -omit [Nonempty V] in - -theorem bernoulliPolynomial_open_gate (Q : Finset E) (e : E) (he : e ∈ Q) - (f : Finset E → ℝ) (p : ℝ) (hf : ∀ ω ⊆ Q, e ∉ ω → f ω = 0) : - bernoulliPolynomial Q f p = - p*bernoulliPolynomial (Q.erase e) (fun ω => f (insert e ω)) p := by - conv_lhs => rw [← Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] - have hz : bernoulliPolynomial (Q.erase e) f p = 0 := by - rw [← bernoulliPolynomial_zero (Q.erase e) p] - apply bernoulliPolynomial_congr - intro ω hω - exact hf ω (Finset.Subset.trans hω (Finset.erase_subset e Q)) - (fun h => Finset.notMem_erase e Q (hω h)) - rw [hz,mul_zero,zero_add] - -end PointwiseRecursion - -section FiniteMomentRecursion -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Nonempty V] - - -noncomputable def cutCoefficient (G : BondGraph V E) (Q : Finset E) (x : V) - (e : E) (W : Finset V) (h p : ℝ) : ℝ := - bernoulliPolynomial ((Q.erase e) \ exteriorBonds G Q W) - (fun a => if cluster G a x = (W : Set V) then (1:ℝ) else 0) p * (1-h)^W.card - - -theorem finiteMarkedMoment_recursion (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (i : ℕ) (h p : ℝ) (hF : insert x (searchVertices G Q) ⊆ F) : - finiteMarkedMoment G Q F x (i+1) h p = p * ∑ e ∈ Q, ∑ W ∈ F.powerset, - if CutExists G W e then cutCoefficient G Q x e W h p * - finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) i h p else 0 := by - have hsum : finiteMarkedMoment G Q F x (i+1) h p = - ∑ e ∈ Q, bernoulliPolynomial Q (fun ω => bernoulliPolynomial F - (pivotalSuffixValue G Q x e i ω) h) p := by - change bernoulliPolynomial Q (fun ω => bernoulliPolynomial F - (fun m => markedMomentValue G Q x (i+1) ω m) h) p = _ - simp only [markedMomentValue_succ_exterior,bernoulliPolynomial_sum] - rfl - rw [hsum,Finset.mul_sum] - apply Finset.sum_congr rfl - intro e he - rw [bernoulliPolynomial_open_gate Q e he] - · congr 1 - trans bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F - (fun m => ∑ W ∈ F.powerset, if CutExists G W e then cutMomentValue G Q x e W i ω m else 0) h) p - · apply bernoulliPolynomial_congr - intro ω hω - apply bernoulliPolynomial_congr - intro m _ - exact pivotalSuffixValue_component_sum G Q F x e i ω - (fun h => Finset.notMem_erase e Q (hω h)) - (Finset.Subset.trans hω (Finset.erase_subset e Q)) hF m - · simp only [bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro W hW - by_cases hc : CutExists G W e - · simp only [hc,ite_true] - exact cutMoment_factor G Q F W x e i h p (Finset.mem_powerset.mp hW) hc - · simp only [hc,ite_false,bernoulliPolynomial_zero] - · intro ω hω heω - rw [← bernoulliPolynomial_zero F h] - apply bernoulliPolynomial_congr - intro m _ - have hpiv : ¬OpenMarkedPivotal G ω m x e := fun h => heω h.1 - simp only [pivotalSuffixValue,hpiv,ite_false] - -omit [Nonempty V] in -theorem cutCoefficient_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) - (e : E) (W : Finset V) (h p : unitInterval) : 0 ≤ cutCoefficient G Q x e W h p := by - apply mul_nonneg - · exact bernoulliPolynomial_nonneg _ _ _ p.2 (fun _ _ => by split_ifs <;> norm_num) - · exact pow_nonneg (sub_nonneg.mpr h.2.2) _ - -omit [Nonempty V] in -theorem finiteMarkedMoment_nonneg (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (i : ℕ) (h p : unitInterval) : 0 ≤ finiteMarkedMoment G Q F x i h p := by - apply bernoulliPolynomial_nonneg _ _ _ p.2 - intro ω _ - apply bernoulliPolynomial_nonneg _ _ _ h.2 - intro m _ - unfold markedMomentValue - split_ifs <;> positivity - - -theorem exterior_mark_support (G : BondGraph V E) (Q : Finset E) (F W : Finset V) - (x : V) (e : E) (he : e ∈ Q) (hc : CutExists G W e) - (hF : insert x (searchVertices G Q) ⊆ F) : - insert (cutOutside G W e) (searchVertices G (exteriorBonds G Q W)) ⊆ F \ W := by - have hs := cut_spec G W hc - intro y hy - rcases Finset.mem_insert.mp hy with rfl | hy - · exact Finset.mem_sdiff.mpr ⟨hF (Finset.mem_insert_of_mem - (mem_searchVertices G he (by simp [hs.1]))),hs.2.2⟩ - · obtain ⟨f,hf,hyf⟩ := Finset.mem_biUnion.mp hy - have hfQ := (Finset.mem_filter.mp hf).1 - have hfo := (Finset.mem_filter.mp hf).2 - have hyf' := Sym2.mem_toFinset.mp hyf - exact Finset.mem_sdiff.mpr ⟨hF (Finset.mem_insert_of_mem - (mem_searchVertices G hfQ hyf')),hfo y hyf'⟩ - -omit [Nonempty V] in - -theorem exterior_degree_bound (G : BondGraph V E) (Q : Finset E) (W : Set V) - (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : - ∀ v, ((exteriorBonds G Q W).filter (fun e => v ∈ G e)).card ≤ d := by - intro v - apply le_trans (Finset.card_le_card ?_) (hd v) - intro e he - exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp (Finset.mem_filter.mp he).1).1, - (Finset.mem_filter.mp he).2⟩ - - -theorem finiteMarkedMoment_geometric (G : BondGraph V E) (p h : unitInterval) - (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) (i : ℕ) - (Q : Finset E) (F : Finset V) (x : V) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (hF : insert x (searchVertices G Q) ⊆ F) : - finiteMarkedMoment G Q F x i h p ≤ - ((Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h))^i * - finiteMarkedMoment G Q F x 0 h p := by - let A : ℝ := (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) - have hA : 0 ≤ A := mul_nonneg (div_nonneg (Real.sqrt_nonneg _) (sub_nonneg.mpr p.2.2)) - (Real.sqrt_nonneg _) - change _ ≤ A^i * _ - induction i generalizing Q F x with - | zero => simp - | succ i ih => - have hpow := pow_nonneg hA i - calc - finiteMarkedMoment G Q F x (i+1) h p = - (p:ℝ) * ∑ e ∈ Q, ∑ W ∈ F.powerset, - if CutExists G W e then cutCoefficient G Q x e W h p * - finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) i h p else 0 := - finiteMarkedMoment_recursion G Q F x i h p hF - _ ≤ (p:ℝ) * ∑ e ∈ Q, ∑ W ∈ F.powerset, - if CutExists G W e then cutCoefficient G Q x e W h p * - (A^i * finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) 0 h p) - else 0 := by - apply mul_le_mul_of_nonneg_left _ p.2.1 - apply Finset.sum_le_sum - intro e he - apply Finset.sum_le_sum - intro W hW - by_cases hc : CutExists G W e - · simp only [hc,ite_true] - apply mul_le_mul_of_nonneg_left _ (cutCoefficient_nonneg G Q x e W h p) - exact ih _ _ _ (exterior_degree_bound G Q W d hdeg) (exterior_mark_support G Q F W x e he hc hF) - · simp only [hc,ite_false,le_refl] - _ = A^i * finiteMarkedMoment G Q F x 1 h p := by - rw [show (1:ℕ) = 0+1 from rfl,finiteMarkedMoment_recursion G Q F x 0 h p hF] - simp only [Finset.mul_sum] - apply Finset.sum_congr rfl - intro e he - apply Finset.sum_congr rfl - intro W hW - by_cases hc : CutExists G W e <;> simp only [hc,ite_true,ite_false] <;> ring - _ ≤ A^i * (A * finiteMarkedMoment G Q F x 0 h p) := - mul_le_mul_of_nonneg_left (finiteMarkedMoment_first_bound G Q F x p h hp hh d hd hdeg hF) hpow - _ = A^(i+1) * finiteMarkedMoment G Q F x 0 h p := by rw [pow_succ]; ring - -end FiniteMomentRecursion - -section MarkedExponential -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem choose_generating_sum (n N : ℕ) (hn : n ≤ N) (z : ℝ) : - (1+z)^n = ∑ i ∈ Finset.range (N+1), z^i*(n.choose i : ℝ) := by - rw [add_comm (1:ℝ),add_pow] - simp only [one_pow,mul_one] - apply Finset.sum_subset (Finset.range_mono (Nat.succ_le_succ hn)) - intro i hi hin - have hni : n < i := by simp only [Finset.mem_range,not_lt] at hin; omega - simp [Nat.choose_eq_zero_of_lt hni] - - -theorem markedMomentValue_generating (G : BondGraph V E) (Q : Finset E) (x : V) - (z : ℝ) (ω : Finset E) (m : Finset V) : - (if MarkedEvent G ω m x then (1+z)^(markedOpenPivotals G Q x ω m).card else 0) = - ∑ i ∈ Finset.range (Q.card+1), z^i*markedMomentValue G Q x i ω m := by - by_cases hm : MarkedEvent G ω m x - · simp only [markedMomentValue,hm,ite_true] - exact choose_generating_sum _ _ (Finset.card_filter_le ..) z - · simp only [markedMomentValue,hm,ite_false,mul_zero,Finset.sum_const_zero] - -noncomputable def finiteMarkedGenerating (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (z h p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => - if MarkedEvent G ω m x then (1+z)^(markedOpenPivotals G Q x ω m).card else 0) h) p - -noncomputable def finiteMarkedTail (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (r : ℕ) (h p : ℝ) : ℝ := - bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => - if MarkedEvent G ω m x ∧ r ≤ (markedOpenPivotals G Q x ω m).card then (1:ℝ) else 0) h) p - -theorem finiteMarkedTail_nonneg (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (r : ℕ) (h p : unitInterval) : 0 ≤ finiteMarkedTail G Q F x r h p := by - apply bernoulliPolynomial_nonneg _ _ _ p.2 - intro ω _ - apply bernoulliPolynomial_nonneg _ _ _ h.2 - intro m _ - split_ifs <;> norm_num - -theorem finiteMarkedGenerating_eq (G : BondGraph V E) (Q : Finset E) (F : Finset V) - (x : V) (z h p : ℝ) : - finiteMarkedGenerating G Q F x z h p = - ∑ i ∈ Finset.range (Q.card+1), z^i*finiteMarkedMoment G Q F x i h p := by - simp only [finiteMarkedGenerating,markedMomentValue_generating,bernoulliPolynomial_sum, - bernoulliPolynomial_const_mul] - rfl - -theorem half_geometric_sum_le (N : ℕ) : - (∑ i ∈ Finset.range N, (1/2:ℝ)^i) ≤ 2 := by - have heq : (∑ i ∈ Finset.range N, (1/2:ℝ)^i) = 2*(1-(1/2:ℝ)^N) := by - induction N with - | zero => simp - | succ N ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring - rw [heq] - have := pow_nonneg (by norm_num : (0:ℝ) ≤ 1/2) N - linarith - - -theorem finiteMarkedGenerating_le [Nonempty V] (G : BondGraph V E) (p h : unitInterval) - (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) - (Q : Finset E) (F : Finset V) (x : V) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (hF : insert x (searchVertices G Q) ⊆ F) (B : ℝ) (hB : 0 < B) - (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) : - finiteMarkedGenerating G Q F x (1/(2*B)) h p ≤ 2*finiteMarkedMoment G Q F x 0 h p := by - let A : ℝ := (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) - have hA : 0 ≤ A := mul_nonneg (div_nonneg (Real.sqrt_nonneg _) (sub_nonneg.mpr p.2.2)) - (Real.sqrt_nonneg _) - have hb0 := finiteMarkedMoment_nonneg G Q F x 0 h p - rw [finiteMarkedGenerating_eq] - calc - _ ≤ ∑ i ∈ Finset.range (Q.card+1), (1/(2*B))^i*(B^i*finiteMarkedMoment G Q F x 0 h p) := by - apply Finset.sum_le_sum - intro i hi - apply mul_le_mul_of_nonneg_left _ (pow_nonneg (by positivity) i) - apply (finiteMarkedMoment_geometric G p h hp hh d hd i Q F x hdeg hF).trans - exact mul_le_mul_of_nonneg_right (pow_le_pow_left₀ hA hAB i) hb0 - _ = (∑ i ∈ Finset.range (Q.card+1), (1/2:ℝ)^i)*finiteMarkedMoment G Q F x 0 h p := by - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro i hi - rw [← mul_assoc,← mul_pow] - congr 2 - field_simp - _ ≤ 2*finiteMarkedMoment G Q F x 0 h p := mul_le_mul_of_nonneg_right (half_geometric_sum_le _) hb0 - - -theorem finiteMarkedTail_markov (G : BondGraph V E) (p h : unitInterval) (Q : Finset E) - (F : Finset V) (x : V) (z : ℝ) (hz : 0 ≤ z) (r : ℕ) : - (1+z)^r * finiteMarkedTail G Q F x r h p ≤ finiteMarkedGenerating G Q F x z h p := by - unfold finiteMarkedTail finiteMarkedGenerating - rw [← bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_mono _ _ _ _ p.2 - intro ω hω - rw [← bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_mono _ _ _ _ h.2 - intro m hm - by_cases he : MarkedEvent G ω m x - · by_cases hc : r ≤ (markedOpenPivotals G Q x ω m).card - · simp only [he,hc,and_self,ite_true,mul_one] - exact pow_le_pow_right₀ (by linarith : (1:ℝ) ≤ 1+z) hc - · simp only [he,hc,and_false,ite_true,ite_false,mul_zero] - exact pow_nonneg (by linarith) _ - · simp only [he,false_and,ite_false,mul_zero,le_refl] - - -theorem log_one_add_half_inv_ge (B : ℝ) (hB : 1 ≤ B) : - 1/(4*B) ≤ Real.log (1+1/(2*B)) := by - have hBp : 0 < B := by linarith - let z : ℝ := 1/(2*B) - have hz : 0 ≤ z := by dsimp [z]; positivity - have hzle : z ≤ 2 := by dsimp [z]; apply (div_le_iff₀ (by positivity)).mpr; linarith - calc - 1/(4*B) = z/2 := by dsimp [z]; ring - _ ≤ 2*z/(z+2) := by - apply (le_div_iff₀ (by linarith : 0 < z+2)).mpr - have hs := mul_le_mul_of_nonneg_right hzle hz - nlinarith - _ ≤ Real.log (1+z) := Real.le_log_one_add_of_nonneg hz - - -theorem finiteMarkedTail_exponential [Nonempty V] (G : BondGraph V E) (p h : unitInterval) - (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) - (Q : Finset E) (F : Finset V) (x : V) - (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) - (hF : insert x (searchVertices G Q) ⊆ F) (B : ℝ) (hB : 1 ≤ B) - (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) (r : ℕ) : - finiteMarkedTail G Q F x r h p ≤ - 2*Real.exp (-(r:ℝ)/(4*B))*finiteMarkedMoment G Q F x 0 h p := by - have hBp : 0 < B := by linarith - have hz : 0 ≤ 1/(2*B) := by positivity - have hbase : 0 < 1+1/(2*B) := by positivity - have hpow : Real.exp ((r:ℝ)/(4*B)) ≤ (1+1/(2*B))^r := by - rw [← Real.exp_log (pow_pos hbase r),Real.log_pow] - apply Real.exp_le_exp.mpr - have hlog := mul_le_mul_of_nonneg_left (log_one_add_half_inv_ge B hB) (Nat.cast_nonneg r : (0:ℝ) ≤ r) - simpa only [mul_one_div] using hlog - have hm := (finiteMarkedTail_markov G p h Q F x (1/(2*B)) hz r).trans - (finiteMarkedGenerating_le G p h hp hh d hd Q F x hdeg hF B hBp hAB) - have ht := finiteMarkedTail_nonneg G Q F x r h p - have he := (mul_le_mul_of_nonneg_right hpow ht).trans hm - calc - finiteMarkedTail G Q F x r h p ≤ (2*finiteMarkedMoment G Q F x 0 h p)/Real.exp ((r:ℝ)/(4*B)) := - (le_div_iff₀ (Real.exp_pos _)).mpr (by simpa only [mul_comm] using he) - _ = 2*Real.exp (-(r:ℝ)/(4*B))*finiteMarkedMoment G Q F x 0 h p := by - rw [neg_div,Real.exp_neg,div_eq_mul_inv] - ring - -end MarkedExponential - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.Marked + +namespace OAI + +/-! Recursive marked moments and exponential estimates. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section OrderedPivotalMoments +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem sum_choose_rank_suffix {I : Type*} (P : Finset I) (rank : I → ℕ) + (hinj : Set.InjOn rank (P : Set I)) (i : ℕ) : + (∑ e ∈ P, ((P.filter fun f => rank e < rank f).card).choose i) = + P.card.choose (i+1) := by + induction P using Finset.strongInductionOn with + | _ P ih => + rcases P.eq_empty_or_nonempty with rfl | hP + · simp + obtain ⟨e,he,hmin⟩ := Finset.exists_min_image P rank hP + have hT : P.erase e ⊂ P := Finset.erase_ssubset he + have hinjT : Set.InjOn rank (↑(P.erase e) : Set I) := fun a ha b hb => + hinj (Finset.mem_of_mem_erase ha) (Finset.mem_of_mem_erase hb) + have hroot : P.filter (fun f => rank e < rank f) = P.erase e := by + ext f + simp only [Finset.mem_filter,Finset.mem_erase] + constructor + · rintro ⟨hf,hlt⟩ + exact ⟨fun h => (Nat.ne_of_lt hlt) (congrArg rank h.symm),hf⟩ + · rintro ⟨hne,hf⟩ + exact ⟨hf,lt_of_le_of_ne (hmin f hf) (fun h => hne (hinj he hf h).symm)⟩ + have hrest (f : I) (hf : f ∈ P.erase e) : + P.filter (fun g => rank f < rank g) = (P.erase e).filter (fun g => rank f < rank g) := by + ext g + simp only [Finset.mem_filter,Finset.mem_erase] + constructor + · rintro ⟨hg,hfg⟩ + refine ⟨⟨?_,hg⟩,hfg⟩ + intro h; subst g + exact (not_lt_of_ge (hmin f (Finset.mem_of_mem_erase hf))) hfg + · exact fun h => ⟨h.1.2,h.2⟩ + calc + _ = (∑ f ∈ P.erase e, ((P.filter fun g => rank f < rank g).card).choose i) + + ((P.filter fun f => rank e < rank f).card).choose i := + (Finset.sum_erase_add _ _ he).symm + _ = (∑ f ∈ P.erase e, (((P.erase e).filter fun g => rank f < rank g).card).choose i) + + (P.erase e).card.choose i := by + rw [hroot] + congr 1 + exact Finset.sum_congr rfl fun f hf => congrArg (fun s : Finset I => s.card.choose i) (hrest f hf) + _ = (P.erase e).card.choose (i+1)+(P.erase e).card.choose i := by rw [ih _ hT hinjT] + _ = P.card.choose (i+1) := by + have hc : (P.erase e).card+1=P.card := by + rw [Finset.card_erase_of_mem he] + have hp := Finset.card_pos.mpr hP + omega + rw [← hc,Nat.choose_succ_succ] + simp [Nat.succ_eq_add_one,Nat.add_comm] + +end OrderedPivotalMoments + +section MarkedRecursion +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem cluster_union_external (G : BondGraph V E) (ω η : Set E) (x : V) (W : Set V) + (hω : cluster G ω x ⊆ W) (hη : η ⊆ internalEdges G Wᶜ) : + cluster G (ω ∪ η) x = cluster G ω x := by + apply Set.Subset.antisymm + · intro y hy + induction hy with + | refl => exact conn_refl G ω x + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + rcases he with he | he + · exact ih.tail ⟨e,he,heq⟩ + · exact (((mem_internalEdges_of_ends G _ e a b heq).mp (hη he)).1 (hω ih)).elim + · exact fun _ h => conn_mono G Set.subset_union_left h + + +theorem cluster_union_external_eq_iff (G : BondGraph V E) (ω η : Set E) + (x : V) (W : Set V) (hη : η ⊆ internalEdges G Wᶜ) : + cluster G (ω ∪ η) x = W ↔ cluster G ω x = W := by + constructor + · intro h + have hω : cluster G ω x ⊆ W := fun y hy => h ▸ conn_mono G Set.subset_union_left hy + rwa [cluster_union_external G ω η x W hω hη] at h + · intro h + rw [cluster_union_external G ω η x W (h ▸ Set.Subset.rfl) hη,h] + + +theorem markedEvent_internal_marks (G : BondGraph V E) (ω : Set E) (m W : Set V) + (x : V) (hx : x ∈ W) (hω : ω ⊆ internalEdges G W) : + MarkedEvent G ω m x ↔ MarkedEvent G ω (m ∩ W) x := by + constructor + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,⟨hy,conn_internal_endpoint G W hx (conn_mono G + (ω₁ := ω) (ω₂ := ω ∩ internalEdges G W) (fun _ h => ⟨h,hω h⟩) hxy)⟩,hxy⟩ + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,hy.1,hxy⟩ + +theorem openMarkedPivotal_internal_marks (G : BondGraph V E) (ω : Set E) + (m W : Set V) (x : V) (hx : x ∈ W) (hω : ω ⊆ internalEdges G W) (e : E) : + OpenMarkedPivotal G ω m x e ↔ OpenMarkedPivotal G ω (m ∩ W) x e := by + simp only [OpenMarkedPivotal,markedEvent_internal_marks G ω m W x hx hω, + markedEvent_internal_marks G (ω \ {e}) m W x hx (Set.Subset.trans Set.sdiff_subset hω)] + + +theorem openMarkedPivotal_insert_cut (G : BondGraph V E) (ω : Set E) (m W : Set V) + (x : V) {e : E} {a b : V} (hW : cluster G ω x = W) + (hab : G e = s(a,b)) (ha : a ∈ W) (hb : b ∉ W) : + OpenMarkedPivotal G (insert e ω) m x e ↔ + Disjoint W m ∧ MarkedEvent G (ω ∩ internalEdges G Wᶜ) (m ∩ Wᶜ) b := by + have he : e ∉ ω := fun he => hb (hW ▸ ((edge_cluster_sides G ω x he hab).mp (hW ▸ ha))) + have hdel : insert e ω \ {e} = ω := by ext f; simp [he] + have hxa : Conn G ω x a := by change a ∈ cluster G ω x; rwa [hW] + constructor + · intro hp + have hdis := pivotal_rootSide_disjoint_marks G (insert e ω) m x hp + rw [hdel,hW] at hdis + refine ⟨hdis,?_⟩ + obtain ⟨y,hy,hxy⟩ := hp.2.1 + rw [conn_insert_iff G ω e a b x y hab] at hxy + rcases hxy with hxy | ⟨_,hby⟩ | ⟨hxb,_⟩ + · exact (Set.disjoint_left.mp hdis (hW ▸ hxy) hy).elim + · have hby' := conn_restrict_cluster_compl G ω x (a := b) (hW ▸ hb) hby + rw [hW] at hby' + exact (markedEvent_internal_marks G _ m Wᶜ b hb Set.inter_subset_right).mp ⟨y,hy,hby'⟩ + · exact (hb (hW ▸ hxb)).elim + · rintro ⟨hdis,y,hy,hby⟩ + refine ⟨Set.mem_insert _ _,?_,?_⟩ + · exact ⟨y,hy.1,(conn_mono G (Set.subset_insert e ω) hxa).tail + ⟨e,Set.mem_insert _ _,hab⟩ |>.trans (conn_mono G + (fun _ h => Set.mem_insert_of_mem _ h.1) hby)⟩ + · rw [hdel] + rintro ⟨z,hz,hxz⟩ + exact Set.disjoint_left.mp hdis (hW ▸ hxz) hz + +@[simp] theorem mem_markedOpenPivotals (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (m : Finset V) (e : E) : + e ∈ markedOpenPivotals G Q x ω m ↔ e ∈ Q ∧ OpenMarkedPivotal G ω m x e := by + simp only [markedOpenPivotals,Finset.mem_filter,OpenMarkedPivotal,MarkedEvent,Finset.coe_erase, + Finset.mem_coe] + + +noncomputable def markedMomentValue (G : BondGraph V E) (Q : Finset E) (x : V) + (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := + if MarkedEvent G ω m x then ((markedOpenPivotals G Q x ω m).card.choose i : ℝ) else 0 + + +theorem markedMomentValue_succ (G : BondGraph V E) (Q : Finset E) (x : V) + (i : ℕ) (ω : Finset E) (m : Finset V) : + markedMomentValue G Q x (i+1) ω m = + ∑ e ∈ markedOpenPivotals G Q x ω m, + (((markedOpenPivotals G Q x ω m).filter + (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ)).card.choose i : ℝ) := by + have hinj : Set.InjOn (pivotalRank G ω x) (↑(markedOpenPivotals G Q x ω m) : Set E) := by + intro e he f hf + exact pivotalRank_injective G ω.finite_toSet m x + ((mem_markedOpenPivotals G Q x ω m e).mp he).2 + ((mem_markedOpenPivotals G Q x ω m f).mp hf).2 + have hs := sum_choose_rank_suffix (markedOpenPivotals G Q x ω m) (pivotalRank G ω x) hinj i + have heq (e : E) (he : e ∈ markedOpenPivotals G Q x ω m) : + (markedOpenPivotals G Q x ω m).filter (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) = + (markedOpenPivotals G Q x ω m).filter (fun f => pivotalRank G ω x e < pivotalRank G ω x f) := by + apply Finset.filter_congr + intro f hf + exact (pivotalRank_lt_iff G ω.finite_toSet m x + ((mem_markedOpenPivotals G Q x ω m e).mp he).2 + ((mem_markedOpenPivotals G Q x ω m f).mp hf).2).symm + by_cases h : MarkedEvent G ω m x + · simp only [markedMomentValue,h,ite_true] + rw [← hs,Nat.cast_sum] + apply Finset.sum_congr rfl + intro e he + rw [heq e he] + · have hempty : markedOpenPivotals G Q x ω m = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro e he + exact h ((mem_markedOpenPivotals G Q x ω m e).mp he).2.2.1 + simp [markedMomentValue,h,hempty] + + +theorem conn_mem_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) + {ω : Set E} (hω : ω ⊆ Q) {y : V} (hxy : Conn G ω x y) : + y ∈ insert x (searchVertices G Q) := by + induction hxy with + | refl => exact Finset.mem_insert_self _ _ + | @tail a b hxa hab ih => + obtain ⟨e,he,heq⟩ := hab + exact Finset.mem_insert_of_mem (mem_searchVertices G (hω he) (by simp [heq])) + +theorem markedEvent_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) + {ω : Set E} (hω : ω ⊆ Q) (m : Set V) : + MarkedEvent G ω m x ↔ MarkedEvent G ω (m ∩ ↑(insert x (searchVertices G Q))) x := by + constructor + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,⟨hy,conn_mem_searchSupport G Q x hω hxy⟩,hxy⟩ + · rintro ⟨y,hy,hxy⟩ + exact ⟨y,hy.1,hxy⟩ + +theorem markedOpenPivotals_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : + markedOpenPivotals G Q x ω m = + markedOpenPivotals G Q x ω (m ∩ insert x (searchVertices G Q)) := by + ext e + simp only [mem_markedOpenPivotals,OpenMarkedPivotal,Finset.coe_inter] + rw [markedEvent_searchSupport G Q x (by exact_mod_cast hω), + markedEvent_searchSupport G Q x (ω := (ω : Set E) \ {e}) + (fun _ h => hω h.1)] + +theorem markedMomentValue_searchSupport (G : BondGraph V E) (Q : Finset E) (x : V) + (i : ℕ) (ω : Finset E) (hω : ω ⊆ Q) (m : Finset V) : + markedMomentValue G Q x i ω m = + markedMomentValue G Q x i ω (m ∩ insert x (searchVertices G Q)) := by + unfold markedMomentValue + rw [markedOpenPivotals_searchSupport G Q x ω hω m] + simp only [Finset.coe_inter] + rw [markedEvent_searchSupport G Q x (by exact_mod_cast hω)] + +@[simp] theorem markedMomentValue_zero (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (m : Finset V) : + markedMomentValue G Q x 0 ω m = if MarkedEvent G ω m x then 1 else 0 := by + simp only [markedMomentValue,Nat.choose_zero_right,Nat.cast_one] + +@[simp] theorem markedMomentValue_one (G : BondGraph V E) (Q : Finset E) (x : V) + (ω : Finset E) (m : Finset V) : + markedMomentValue G Q x 1 ω m = ((markedOpenPivotals G Q x ω m).card : ℝ) := by + by_cases h : MarkedEvent G ω m x + · simp [markedMomentValue,h] + · have he : markedOpenPivotals G Q x ω m = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro e he + exact h ((mem_markedOpenPivotals G Q x ω m e).mp he).2.2.1 + simp [markedMomentValue,h,he] + + +noncomputable def finiteMarkedMoment (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (i : ℕ) (h p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (markedMomentValue G Q x i ω) h) p + +theorem finiteMarkedMoment_support (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (i : ℕ) (h p : ℝ) (hF : insert x (searchVertices G Q) ⊆ F) : + finiteMarkedMoment G Q F x i h p = + finiteMarkedMoment G Q (insert x (searchVertices G Q)) x i h p := by + apply bernoulliPolynomial_congr + intro ω hω + rw [← bernoulliPolynomial_restrict _ F hF] + apply bernoulliPolynomial_congr + intro m _ + exact markedMomentValue_searchSupport G Q x i ω hω m + + +theorem finiteMarkedMoment_first_bound (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (p h : unitInterval) (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (hF : insert x (searchVertices G Q) ⊆ F) : + finiteMarkedMoment G Q F x 1 h p ≤ + (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h)* + finiteMarkedMoment G Q F x 0 h p := by + rw [finiteMarkedMoment_support G Q F x 1 h p hF, + finiteMarkedMoment_support G Q F x 0 h p hF] + simpa only [finiteMarkedMoment,markedMomentValue_one,markedMomentValue_zero,MarkedEvent, + markedPivotalMomentOne,markedConnectionPolynomial,bernoulliPolynomial,Finset.mem_coe] using + marked_pivotal_first_moment G Q x p h hp hh d hd hdeg + +noncomputable def exteriorBonds (G : BondGraph V E) (Q : Finset E) (W : Set V) : Finset E := + Q.filter fun e => e ∈ internalEdges G Wᶜ + +noncomputable def exteriorMarks (m : Finset V) (W : Set V) : Finset V := + m.filter fun x => x ∉ W + +@[simp] theorem coe_exteriorBonds (G : BondGraph V E) (Q : Finset E) (W : Set V) : + (exteriorBonds G Q W : Set E) = (Q : Set E) ∩ internalEdges G Wᶜ := by + ext e; simp [exteriorBonds] + +@[simp] theorem coe_exteriorMarks (m : Finset V) (W : Set V) : + (exteriorMarks m W : Set V) = (m : Set V) ∩ Wᶜ := by + ext x; simp [exteriorMarks] + + +theorem markedOpenPivotals_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) + (x : V) (ω : Finset E) (m : Finset V) {e : E} + (he : OpenMarkedPivotal G ω m x e) : + markedOpenPivotals G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) + (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) = + (markedOpenPivotals G Q x ω m).filter + (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) := by + obtain ⟨a,b,hab,hxa,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he + have hb := (cut_unique G (cluster G (↑ω \ {e}) x) hab hxa hxb).2 + rw [← hb] + ext f + simp only [mem_markedOpenPivotals,exteriorBonds,Finset.mem_filter,coe_exteriorMarks, + Finset.coe_filter] + have hmarks := openMarkedPivotal_internal_marks G + ((ω : Set E) ∩ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) + m (cluster G (↑ω \ {e}) x)ᶜ b hxb Set.inter_subset_right f + have hiff := openMarkedPivotal_exterior_iff G ω m x he hab hxa hxb hbm f + change (f ∈ Q ∧ f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) ∧ + OpenMarkedPivotal G ((ω : Set E) ∩ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ) + ((m : Set V) ∩ (cluster G (↑ω \ {e}) x)ᶜ) b f ↔ _ + rw [← hmarks,hiff] + tauto + + +theorem markedMomentValue_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) + (x : V) (i : ℕ) (ω : Finset E) (m : Finset V) {e : E} + (he : OpenMarkedPivotal G ω m x e) : + markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) i + (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) = + (((markedOpenPivotals G Q x ω m).filter + (fun f => f ∈ internalEdges G (cluster G (↑ω \ {e}) x)ᶜ)).card.choose i : ℝ) := by + have hsuccess : MarkedEvent G (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) := by + obtain ⟨a,b,hab,hxa,hxb,y,hy,hby⟩ := openMarkedPivotal_oriented G ω m x he + rw [← (cut_unique G (cluster G (↑ω \ {e}) x) hab hxa hxb).2, + coe_exteriorBonds,coe_exteriorMarks] + apply (markedEvent_internal_marks G _ m (cluster G (↑ω \ {e}) x)ᶜ b hxb + Set.inter_subset_right).mp + refine ⟨y,hy,conn_mono G ?_ (conn_restrict_cluster_compl G (↑ω \ {e}) x hxb hby)⟩ + exact fun _ h => ⟨h.1.1,h.2⟩ + rw [markedMomentValue,ite_eq_left hsuccess,markedOpenPivotals_exterior G Q x ω m he] + + +theorem markedMomentValue_succ_exterior [Nonempty V] (G : BondGraph V E) (Q : Finset E) + (x : V) (i : ℕ) (ω : Finset E) (m : Finset V) : + markedMomentValue G Q x (i+1) ω m = ∑ e ∈ Q, + if OpenMarkedPivotal G ω m x e then + markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) i + (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) else 0 := by + rw [markedMomentValue_succ] + trans ∑ e ∈ markedOpenPivotals G Q x ω m, + markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) i + (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) + · apply Finset.sum_congr rfl + intro e he + exact (markedMomentValue_exterior G Q x i ω m + ((mem_markedOpenPivotals G Q x ω m e).mp he).2).symm + · have heq : markedOpenPivotals G Q x ω m = Q.filter (fun e => OpenMarkedPivotal G ω m x e) := by + ext e; simp only [mem_markedOpenPivotals,Finset.mem_filter] + rw [heq,Finset.sum_filter] + +end MarkedRecursion + +section CutFactor +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Nonempty V] + +noncomputable def cutMomentValue (G : BondGraph V E) (Q : Finset E) (x : V) + (e : E) (W : Finset V) (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := + if cluster G ω x = (W : Set V) then + if Disjoint (W : Set V) (m : Set V) then + markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i + (exteriorBonds G ω W) (exteriorMarks m W) + else 0 + else 0 + +omit [Nonempty V] in +theorem cut_not_exterior (G : BondGraph V E) (W : Set V) {e : E} + (hc : CutExists G W e) : e ∉ internalEdges G Wᶜ := by + obtain ⟨a,b,hab,ha,hb⟩ := hc + intro he + exact ((mem_internalEdges_of_ends G Wᶜ e a b hab).mp he).1 ha + +omit [Nonempty V] in +theorem exteriorBonds_subset_erase (G : BondGraph V E) (Q : Finset E) + (W : Set V) {e : E} (hc : CutExists G W e) : exteriorBonds G Q W ⊆ Q.erase e := by + intro f hf + obtain ⟨hf,hout⟩ := Finset.mem_filter.mp hf + exact Finset.mem_erase.mpr ⟨fun h => cut_not_exterior G W hc (h ▸ hout),hf⟩ + + +theorem cutMomentValue_blocks (G : BondGraph V E) (Q : Finset E) (F W : Finset V) + (x : V) (e : E) (i : ℕ) (a b : Finset E) (u v : Finset V) + (ha : a ⊆ (Q.erase e) \ exteriorBonds G Q W) + (hb : b ⊆ exteriorBonds G Q W) (hu : u ⊆ W) (hv : v ⊆ F \ W) : + cutMomentValue G Q x e W i (a ∪ b) (u ∪ v) = + (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * + (if u = ∅ then (1:ℝ) else 0) * + markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i b v := by + have hbout : (b : Set E) ⊆ internalEdges G (W : Set V)ᶜ := + fun f hf => (Finset.mem_filter.mp (hb hf)).2 + have hc := cluster_union_external_eq_iff G (a : Set E) b x W hbout + have he : exteriorBonds G (a ∪ b) W = b := by + ext f + simp only [exteriorBonds,Finset.mem_filter,Finset.mem_union] + constructor + · rintro ⟨hf,hout⟩ + rcases hf with hf | hf + · have hfa := Finset.mem_sdiff.mp (ha hf) + exact (hfa.2 (Finset.mem_filter.mpr ⟨Finset.mem_of_mem_erase hfa.1,hout⟩)).elim + · exact hf + · exact fun hf => ⟨Or.inr hf,hbout hf⟩ + have hm : exteriorMarks (u ∪ v) W = v := by + ext y + simp only [exteriorMarks,Finset.mem_filter,Finset.mem_union,Finset.mem_coe] + constructor + · rintro ⟨hy,hyW⟩ + rcases hy with hy | hy + · exact (hyW (hu hy)).elim + · exact hy + · intro hy + exact ⟨Or.inr hy,(Finset.mem_sdiff.mp (hv hy)).2⟩ + have hd : Disjoint (W : Set V) ((u ∪ v : Finset V) : Set V) ↔ u = ∅ := by + constructor + · intro h + apply Finset.eq_empty_iff_forall_notMem.mpr + intro y hy + exact Set.disjoint_left.mp h (hu hy) (Finset.mem_union_left v hy) + · rintro rfl + apply Set.disjoint_left.mpr + intro y hy hyv + have hyv' : y ∈ v := by simpa using hyv + exact (Finset.mem_sdiff.mp (hv hyv')).2 hy + rw [Finset.coe_union] at hd + simp only [cutMomentValue,Finset.coe_union,hc,hd,he,hm] + split_ifs <;> simp_all + +omit [Nonempty V] in + +theorem bernoulliPolynomial_empty_indicator (F : Finset V) (h : ℝ) : + bernoulliPolynomial F (fun m => if m = ∅ then (1:ℝ) else 0) h = (1-h)^F.card := by + unfold bernoulliPolynomial + rw [Finset.sum_eq_single ∅] + · simp + · intro m hm hne + simp [hne] + · simp + + +theorem cutMoment_factor (G : BondGraph V E) (Q : Finset E) (F W : Finset V) + (x : V) (e : E) (i : ℕ) (h p : ℝ) (hW : W ⊆ F) (hc : CutExists G W e) : + bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (cutMomentValue G Q x e W i ω) h) p = + bernoulliPolynomial ((Q.erase e) \ exteriorBonds G Q W) + (fun a => if cluster G a x = (W : Set V) then (1:ℝ) else 0) p * + (1-h)^W.card * finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) + (cutOutside G W e) i h p := by + let R := exteriorBonds G Q W + let A := (Q.erase e) \ R + let B := F \ W + have hR : R ⊆ Q.erase e := exteriorBonds_subset_erase G Q W hc + have hQR : Q.erase e = A ∪ R := by + dsimp [A]; ext f; simp only [Finset.mem_union,Finset.mem_sdiff] + tauto + have hAR : Disjoint A R := Finset.disjoint_sdiff.symm + have hFB : F = W ∪ B := (Finset.union_sdiff_of_subset hW).symm + have hWB : Disjoint W B := Finset.disjoint_sdiff + conv_lhs => rw [hQR,bernoulliPolynomial_union A R hAR] + trans bernoulliPolynomial A (fun a => + (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * + ((1-h)^W.card * finiteMarkedMoment G R B (cutOutside G W e) i h p)) p + · apply bernoulliPolynomial_congr + intro a ha + trans bernoulliPolynomial R (fun b => + (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * (1-h)^W.card * + bernoulliPolynomial B (markedMomentValue G R (cutOutside G W e) i b) h) p + · apply bernoulliPolynomial_congr + intro b hb + rw [hFB,bernoulliPolynomial_union W B hWB] + trans bernoulliPolynomial W (fun u => + (if cluster G a x = (W : Set V) then (1:ℝ) else 0) * + (if u = ∅ then (1:ℝ) else 0) * + bernoulliPolynomial B (markedMomentValue G R (cutOutside G W e) i b) h) h + · apply bernoulliPolynomial_congr + intro u hu + rw [← bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro v hv + exact cutMomentValue_blocks G Q F W x e i a b u v ha hb hu hv + · rw [bernoulliPolynomial_mul_const,bernoulliPolynomial_const_mul, + bernoulliPolynomial_empty_indicator] + · rw [bernoulliPolynomial_const_mul] + exact mul_assoc _ _ _ + · rw [bernoulliPolynomial_mul_const] + exact (mul_assoc _ _ _).symm + +end CutFactor + +section PointwiseRecursion +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Nonempty V] + +noncomputable def pivotalSuffixValue (G : BondGraph V E) (Q : Finset E) (x : V) + (e : E) (i : ℕ) (ω : Finset E) (m : Finset V) : ℝ := + if OpenMarkedPivotal G ω m x e then + markedMomentValue G (exteriorBonds G Q (cluster G (↑ω \ {e}) x)) + (cutOutside G (cluster G (↑ω \ {e}) x) e) i + (exteriorBonds G ω (cluster G (↑ω \ {e}) x)) + (exteriorMarks m (cluster G (↑ω \ {e}) x)) else 0 + + +theorem pivotalSuffixValue_insert (G : BondGraph V E) (Q : Finset E) (x : V) + (e : E) (i : ℕ) (ω : Finset E) (he : e ∉ ω) (m : Finset V) : + pivotalSuffixValue G Q x e i (insert e ω) m = + if CutExists G (cluster G ω x) e then + if Disjoint (cluster G ω x) (m : Set V) then + markedMomentValue G (exteriorBonds G Q (cluster G ω x)) + (cutOutside G (cluster G ω x) e) i + (exteriorBonds G ω (cluster G ω x)) (exteriorMarks m (cluster G ω x)) + else 0 + else 0 := by + have hdel : ((insert e ω : Finset E) : Set E) \ {e} = (ω : Set E) := by + simp [he] + by_cases hc : CutExists G (cluster G ω x) e + · obtain ⟨hab,ha,hb⟩ := cut_spec G (cluster G ω x) hc + have heout := cut_not_exterior G (cluster G ω x) hc + have hbe : exteriorBonds G (insert e ω) (cluster G ω x) = exteriorBonds G ω (cluster G ω x) := by + ext f + simp only [exteriorBonds,Finset.mem_filter,Finset.mem_insert] + constructor + · rintro ⟨hf,hout⟩ + rcases hf with rfl | hf + · exact (heout hout).elim + · exact ⟨hf,hout⟩ + · exact fun h => ⟨Or.inr h.1,h.2⟩ + have hp := openMarkedPivotal_insert_cut G (ω : Set E) m (cluster G ω x) x rfl hab ha hb + have hps : OpenMarkedPivotal G (insert e ω : Finset E) m x e ↔ + Disjoint (cluster G ω x) (m : Set V) ∧ + MarkedEvent G (exteriorBonds G ω (cluster G ω x)) + (exteriorMarks m (cluster G ω x)) (cutOutside G (cluster G ω x) e) := by + simpa only [Finset.coe_insert,coe_exteriorBonds,coe_exteriorMarks] using hp + simp only [pivotalSuffixValue,hdel,hbe,hc,ite_true,hps] + by_cases hd : Disjoint (cluster G ω x) (m : Set V) <;> + by_cases hm : MarkedEvent G (exteriorBonds G ω (cluster G ω x)) + (exteriorMarks m (cluster G ω x)) (cutOutside G (cluster G ω x) e) <;> + simp only [markedMomentValue,hd,hm,and_true,and_false,ite_true,ite_false] + · have hn : ¬OpenMarkedPivotal G (insert e ω : Finset E) m x e := by + intro hp + obtain ⟨a,b,hab,hxa,hxb,_⟩ := openMarkedPivotal_oriented G (insert e ω : Finset E) m x hp + rw [hdel] at hxa hxb + exact hc ⟨a,b,hab,hxa,hxb⟩ + simp only [pivotalSuffixValue,hn,hc,ite_false] + +noncomputable def finiteRootComponent (G : BondGraph V E) (ω : Finset E) (x : V) : Finset V := + (cluster_finite_of_finite_edges G ω.finite_toSet x).toFinset + +omit [Nonempty V] in +@[simp] +theorem coe_finiteRootComponent (G : BondGraph V E) (ω : Finset E) (x : V) : + (finiteRootComponent G ω x : Set V) = cluster G ω x := by simp [finiteRootComponent] + +omit [Nonempty V] in +theorem finiteRootComponent_subset (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (ω : Finset E) (hω : ω ⊆ Q) (hF : insert x (searchVertices G Q) ⊆ F) : + finiteRootComponent G ω x ⊆ F := by + intro y hy + have hxy : Conn G (ω : Set E) x y := by + change y ∈ (finiteRootComponent G ω x : Set V) at hy + rwa [coe_finiteRootComponent] at hy + exact hF (conn_mem_searchSupport G Q x (by exact_mod_cast hω) hxy) + +omit [Nonempty V] in + +theorem sum_component_partition (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (ω : Finset E) (hω : ω ⊆ Q) (hF : insert x (searchVertices G Q) ⊆ F) + (f : Finset V → ℝ) : + (∑ W ∈ F.powerset, if cluster G ω x = (W : Set V) then f W else 0) = + f (finiteRootComponent G ω x) := by + have hmem : finiteRootComponent G ω x ∈ F.powerset := + Finset.mem_powerset.mpr (finiteRootComponent_subset G Q F x ω hω hF) + rw [Finset.sum_eq_single_of_mem _ hmem] + · simp + · intro W hW hne + have hn : cluster G ω x ≠ (W : Set V) := by + intro h + apply hne + apply Finset.coe_injective + exact h.symm.trans (coe_finiteRootComponent G ω x).symm + simp [hn] + + +theorem pivotalSuffixValue_component_sum (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (e : E) (i : ℕ) (ω : Finset E) (he : e ∉ ω) (hω : ω ⊆ Q) + (hF : insert x (searchVertices G Q) ⊆ F) (m : Finset V) : + pivotalSuffixValue G Q x e i (insert e ω) m = ∑ W ∈ F.powerset, + if CutExists G W e then cutMomentValue G Q x e W i ω m else 0 := by + rw [pivotalSuffixValue_insert G Q x e i ω he m] + symm + trans ∑ W ∈ F.powerset, if cluster G ω x = (W : Set V) then + (if CutExists G W e then + if Disjoint (W : Set V) (m : Set V) then + markedMomentValue G (exteriorBonds G Q W) (cutOutside G W e) i + (exteriorBonds G ω W) (exteriorMarks m W) else 0 + else 0) else 0 + · apply Finset.sum_congr rfl + intro W _ + by_cases hc : CutExists G W e <;> by_cases hw : cluster G ω x = (W : Set V) <;> + simp [cutMomentValue,hc,hw] + · rw [sum_component_partition G Q F x ω hω hF] + simp only [coe_finiteRootComponent] + +omit [Nonempty V] in + +theorem bernoulliPolynomial_open_gate (Q : Finset E) (e : E) (he : e ∈ Q) + (f : Finset E → ℝ) (p : ℝ) (hf : ∀ ω ⊆ Q, e ∉ ω → f ω = 0) : + bernoulliPolynomial Q f p = + p*bernoulliPolynomial (Q.erase e) (fun ω => f (insert e ω)) p := by + conv_lhs => rw [← Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] + have hz : bernoulliPolynomial (Q.erase e) f p = 0 := by + rw [← bernoulliPolynomial_zero (Q.erase e) p] + apply bernoulliPolynomial_congr + intro ω hω + exact hf ω (Finset.Subset.trans hω (Finset.erase_subset e Q)) + (fun h => Finset.notMem_erase e Q (hω h)) + rw [hz,mul_zero,zero_add] + +end PointwiseRecursion + +section FiniteMomentRecursion +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Nonempty V] + + +noncomputable def cutCoefficient (G : BondGraph V E) (Q : Finset E) (x : V) + (e : E) (W : Finset V) (h p : ℝ) : ℝ := + bernoulliPolynomial ((Q.erase e) \ exteriorBonds G Q W) + (fun a => if cluster G a x = (W : Set V) then (1:ℝ) else 0) p * (1-h)^W.card + + +theorem finiteMarkedMoment_recursion (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (i : ℕ) (h p : ℝ) (hF : insert x (searchVertices G Q) ⊆ F) : + finiteMarkedMoment G Q F x (i+1) h p = p * ∑ e ∈ Q, ∑ W ∈ F.powerset, + if CutExists G W e then cutCoefficient G Q x e W h p * + finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) i h p else 0 := by + have hsum : finiteMarkedMoment G Q F x (i+1) h p = + ∑ e ∈ Q, bernoulliPolynomial Q (fun ω => bernoulliPolynomial F + (pivotalSuffixValue G Q x e i ω) h) p := by + change bernoulliPolynomial Q (fun ω => bernoulliPolynomial F + (fun m => markedMomentValue G Q x (i+1) ω m) h) p = _ + simp only [markedMomentValue_succ_exterior,bernoulliPolynomial_sum] + rfl + rw [hsum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + rw [bernoulliPolynomial_open_gate Q e he] + · congr 1 + trans bernoulliPolynomial (Q.erase e) (fun ω => bernoulliPolynomial F + (fun m => ∑ W ∈ F.powerset, if CutExists G W e then cutMomentValue G Q x e W i ω m else 0) h) p + · apply bernoulliPolynomial_congr + intro ω hω + apply bernoulliPolynomial_congr + intro m _ + exact pivotalSuffixValue_component_sum G Q F x e i ω + (fun h => Finset.notMem_erase e Q (hω h)) + (Finset.Subset.trans hω (Finset.erase_subset e Q)) hF m + · simp only [bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro W hW + by_cases hc : CutExists G W e + · simp only [hc,ite_true] + exact cutMoment_factor G Q F W x e i h p (Finset.mem_powerset.mp hW) hc + · simp only [hc,ite_false,bernoulliPolynomial_zero] + · intro ω hω heω + rw [← bernoulliPolynomial_zero F h] + apply bernoulliPolynomial_congr + intro m _ + have hpiv : ¬OpenMarkedPivotal G ω m x e := fun h => heω h.1 + simp only [pivotalSuffixValue,hpiv,ite_false] + +omit [Nonempty V] in +theorem cutCoefficient_nonneg (G : BondGraph V E) (Q : Finset E) (x : V) + (e : E) (W : Finset V) (h p : unitInterval) : 0 ≤ cutCoefficient G Q x e W h p := by + apply mul_nonneg + · exact bernoulliPolynomial_nonneg _ _ _ p.2 (fun _ _ => by split_ifs <;> norm_num) + · exact pow_nonneg (sub_nonneg.mpr h.2.2) _ + +omit [Nonempty V] in +theorem finiteMarkedMoment_nonneg (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (i : ℕ) (h p : unitInterval) : 0 ≤ finiteMarkedMoment G Q F x i h p := by + apply bernoulliPolynomial_nonneg _ _ _ p.2 + intro ω _ + apply bernoulliPolynomial_nonneg _ _ _ h.2 + intro m _ + unfold markedMomentValue + split_ifs <;> positivity + + +theorem exterior_mark_support (G : BondGraph V E) (Q : Finset E) (F W : Finset V) + (x : V) (e : E) (he : e ∈ Q) (hc : CutExists G W e) + (hF : insert x (searchVertices G Q) ⊆ F) : + insert (cutOutside G W e) (searchVertices G (exteriorBonds G Q W)) ⊆ F \ W := by + have hs := cut_spec G W hc + intro y hy + rcases Finset.mem_insert.mp hy with rfl | hy + · exact Finset.mem_sdiff.mpr ⟨hF (Finset.mem_insert_of_mem + (mem_searchVertices G he (by simp [hs.1]))),hs.2.2⟩ + · obtain ⟨f,hf,hyf⟩ := Finset.mem_biUnion.mp hy + have hfQ := (Finset.mem_filter.mp hf).1 + have hfo := (Finset.mem_filter.mp hf).2 + have hyf' := Sym2.mem_toFinset.mp hyf + exact Finset.mem_sdiff.mpr ⟨hF (Finset.mem_insert_of_mem + (mem_searchVertices G hfQ hyf')),hfo y hyf'⟩ + +omit [Nonempty V] in + +theorem exterior_degree_bound (G : BondGraph V E) (Q : Finset E) (W : Set V) + (d : ℕ) (hd : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) : + ∀ v, ((exteriorBonds G Q W).filter (fun e => v ∈ G e)).card ≤ d := by + intro v + apply le_trans (Finset.card_le_card ?_) (hd v) + intro e he + exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp (Finset.mem_filter.mp he).1).1, + (Finset.mem_filter.mp he).2⟩ + + +theorem finiteMarkedMoment_geometric (G : BondGraph V E) (p h : unitInterval) + (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) (i : ℕ) + (Q : Finset E) (F : Finset V) (x : V) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (hF : insert x (searchVertices G Q) ⊆ F) : + finiteMarkedMoment G Q F x i h p ≤ + ((Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h))^i * + finiteMarkedMoment G Q F x 0 h p := by + let A : ℝ := (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) + have hA : 0 ≤ A := mul_nonneg (div_nonneg (Real.sqrt_nonneg _) (sub_nonneg.mpr p.2.2)) + (Real.sqrt_nonneg _) + change _ ≤ A^i * _ + induction i generalizing Q F x with + | zero => simp + | succ i ih => + have hpow := pow_nonneg hA i + calc + finiteMarkedMoment G Q F x (i+1) h p = + (p:ℝ) * ∑ e ∈ Q, ∑ W ∈ F.powerset, + if CutExists G W e then cutCoefficient G Q x e W h p * + finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) i h p else 0 := + finiteMarkedMoment_recursion G Q F x i h p hF + _ ≤ (p:ℝ) * ∑ e ∈ Q, ∑ W ∈ F.powerset, + if CutExists G W e then cutCoefficient G Q x e W h p * + (A^i * finiteMarkedMoment G (exteriorBonds G Q W) (F \ W) (cutOutside G W e) 0 h p) + else 0 := by + apply mul_le_mul_of_nonneg_left _ p.2.1 + apply Finset.sum_le_sum + intro e he + apply Finset.sum_le_sum + intro W hW + by_cases hc : CutExists G W e + · simp only [hc,ite_true] + apply mul_le_mul_of_nonneg_left _ (cutCoefficient_nonneg G Q x e W h p) + exact ih _ _ _ (exterior_degree_bound G Q W d hdeg) (exterior_mark_support G Q F W x e he hc hF) + · simp only [hc,ite_false,le_refl] + _ = A^i * finiteMarkedMoment G Q F x 1 h p := by + rw [show (1:ℕ) = 0+1 from rfl,finiteMarkedMoment_recursion G Q F x 0 h p hF] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + apply Finset.sum_congr rfl + intro W hW + by_cases hc : CutExists G W e <;> simp only [hc,ite_true,ite_false] <;> ring + _ ≤ A^i * (A * finiteMarkedMoment G Q F x 0 h p) := + mul_le_mul_of_nonneg_left (finiteMarkedMoment_first_bound G Q F x p h hp hh d hd hdeg hF) hpow + _ = A^(i+1) * finiteMarkedMoment G Q F x 0 h p := by rw [pow_succ]; ring + +end FiniteMomentRecursion + +section MarkedExponential +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem choose_generating_sum (n N : ℕ) (hn : n ≤ N) (z : ℝ) : + (1+z)^n = ∑ i ∈ Finset.range (N+1), z^i*(n.choose i : ℝ) := by + rw [add_comm (1:ℝ),add_pow] + simp only [one_pow,mul_one] + apply Finset.sum_subset (Finset.range_mono (Nat.succ_le_succ hn)) + intro i hi hin + have hni : n < i := by simp only [Finset.mem_range,not_lt] at hin; omega + simp [Nat.choose_eq_zero_of_lt hni] + + +theorem markedMomentValue_generating (G : BondGraph V E) (Q : Finset E) (x : V) + (z : ℝ) (ω : Finset E) (m : Finset V) : + (if MarkedEvent G ω m x then (1+z)^(markedOpenPivotals G Q x ω m).card else 0) = + ∑ i ∈ Finset.range (Q.card+1), z^i*markedMomentValue G Q x i ω m := by + by_cases hm : MarkedEvent G ω m x + · simp only [markedMomentValue,hm,ite_true] + exact choose_generating_sum _ _ (Finset.card_filter_le ..) z + · simp only [markedMomentValue,hm,ite_false,mul_zero,Finset.sum_const_zero] + +noncomputable def finiteMarkedGenerating (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (z h p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => + if MarkedEvent G ω m x then (1+z)^(markedOpenPivotals G Q x ω m).card else 0) h) p + +noncomputable def finiteMarkedTail (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (r : ℕ) (h p : ℝ) : ℝ := + bernoulliPolynomial Q (fun ω => bernoulliPolynomial F (fun m => + if MarkedEvent G ω m x ∧ r ≤ (markedOpenPivotals G Q x ω m).card then (1:ℝ) else 0) h) p + +theorem finiteMarkedTail_nonneg (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (r : ℕ) (h p : unitInterval) : 0 ≤ finiteMarkedTail G Q F x r h p := by + apply bernoulliPolynomial_nonneg _ _ _ p.2 + intro ω _ + apply bernoulliPolynomial_nonneg _ _ _ h.2 + intro m _ + split_ifs <;> norm_num + +theorem finiteMarkedGenerating_eq (G : BondGraph V E) (Q : Finset E) (F : Finset V) + (x : V) (z h p : ℝ) : + finiteMarkedGenerating G Q F x z h p = + ∑ i ∈ Finset.range (Q.card+1), z^i*finiteMarkedMoment G Q F x i h p := by + simp only [finiteMarkedGenerating,markedMomentValue_generating,bernoulliPolynomial_sum, + bernoulliPolynomial_const_mul] + rfl + +theorem half_geometric_sum_le (N : ℕ) : + (∑ i ∈ Finset.range N, (1/2:ℝ)^i) ≤ 2 := by + have heq : (∑ i ∈ Finset.range N, (1/2:ℝ)^i) = 2*(1-(1/2:ℝ)^N) := by + induction N with + | zero => simp + | succ N ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring + rw [heq] + have := pow_nonneg (by norm_num : (0:ℝ) ≤ 1/2) N + linarith + + +theorem finiteMarkedGenerating_le [Nonempty V] (G : BondGraph V E) (p h : unitInterval) + (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) + (Q : Finset E) (F : Finset V) (x : V) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (hF : insert x (searchVertices G Q) ⊆ F) (B : ℝ) (hB : 0 < B) + (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) : + finiteMarkedGenerating G Q F x (1/(2*B)) h p ≤ 2*finiteMarkedMoment G Q F x 0 h p := by + let A : ℝ := (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) + have hA : 0 ≤ A := mul_nonneg (div_nonneg (Real.sqrt_nonneg _) (sub_nonneg.mpr p.2.2)) + (Real.sqrt_nonneg _) + have hb0 := finiteMarkedMoment_nonneg G Q F x 0 h p + rw [finiteMarkedGenerating_eq] + calc + _ ≤ ∑ i ∈ Finset.range (Q.card+1), (1/(2*B))^i*(B^i*finiteMarkedMoment G Q F x 0 h p) := by + apply Finset.sum_le_sum + intro i hi + apply mul_le_mul_of_nonneg_left _ (pow_nonneg (by positivity) i) + apply (finiteMarkedMoment_geometric G p h hp hh d hd i Q F x hdeg hF).trans + exact mul_le_mul_of_nonneg_right (pow_le_pow_left₀ hA hAB i) hb0 + _ = (∑ i ∈ Finset.range (Q.card+1), (1/2:ℝ)^i)*finiteMarkedMoment G Q F x 0 h p := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i hi + rw [← mul_assoc,← mul_pow] + congr 2 + field_simp + _ ≤ 2*finiteMarkedMoment G Q F x 0 h p := mul_le_mul_of_nonneg_right (half_geometric_sum_le _) hb0 + + +theorem finiteMarkedTail_markov (G : BondGraph V E) (p h : unitInterval) (Q : Finset E) + (F : Finset V) (x : V) (z : ℝ) (hz : 0 ≤ z) (r : ℕ) : + (1+z)^r * finiteMarkedTail G Q F x r h p ≤ finiteMarkedGenerating G Q F x z h p := by + unfold finiteMarkedTail finiteMarkedGenerating + rw [← bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_mono _ _ _ _ p.2 + intro ω hω + rw [← bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_mono _ _ _ _ h.2 + intro m hm + by_cases he : MarkedEvent G ω m x + · by_cases hc : r ≤ (markedOpenPivotals G Q x ω m).card + · simp only [he,hc,and_self,ite_true,mul_one] + exact pow_le_pow_right₀ (by linarith : (1:ℝ) ≤ 1+z) hc + · simp only [he,hc,and_false,ite_true,ite_false,mul_zero] + exact pow_nonneg (by linarith) _ + · simp only [he,false_and,ite_false,mul_zero,le_refl] + + +theorem log_one_add_half_inv_ge (B : ℝ) (hB : 1 ≤ B) : + 1/(4*B) ≤ Real.log (1+1/(2*B)) := by + have hBp : 0 < B := by linarith + let z : ℝ := 1/(2*B) + have hz : 0 ≤ z := by dsimp [z]; positivity + have hzle : z ≤ 2 := by dsimp [z]; apply (div_le_iff₀ (by positivity)).mpr; linarith + calc + 1/(4*B) = z/2 := by dsimp [z]; ring + _ ≤ 2*z/(z+2) := by + apply (le_div_iff₀ (by linarith : 0 < z+2)).mpr + have hs := mul_le_mul_of_nonneg_right hzle hz + nlinarith + _ ≤ Real.log (1+z) := Real.le_log_one_add_of_nonneg hz + + +theorem finiteMarkedTail_exponential [Nonempty V] (G : BondGraph V E) (p h : unitInterval) + (hp : (p:ℝ) < 1) (hh : 0 < (h:ℝ)) (d : ℕ) (hd : 0 < d) + (Q : Finset E) (F : Finset V) (x : V) + (hdeg : ∀ v, (Q.filter (fun e => v ∈ G e)).card ≤ d) + (hF : insert x (searchVertices G Q) ⊆ F) (B : ℝ) (hB : 1 ≤ B) + (hAB : (Real.sqrt ((d:ℝ)/2)/(1-p))*Real.sqrt (Real.log (1/(h:ℝ))/h) ≤ B) (r : ℕ) : + finiteMarkedTail G Q F x r h p ≤ + 2*Real.exp (-(r:ℝ)/(4*B))*finiteMarkedMoment G Q F x 0 h p := by + have hBp : 0 < B := by linarith + have hz : 0 ≤ 1/(2*B) := by positivity + have hbase : 0 < 1+1/(2*B) := by positivity + have hpow : Real.exp ((r:ℝ)/(4*B)) ≤ (1+1/(2*B))^r := by + rw [← Real.exp_log (pow_pos hbase r),Real.log_pow] + apply Real.exp_le_exp.mpr + have hlog := mul_le_mul_of_nonneg_left (log_one_add_half_inv_ge B hB) (Nat.cast_nonneg r : (0:ℝ) ≤ r) + simpa only [mul_one_div] using hlog + have hm := (finiteMarkedTail_markov G p h Q F x (1/(2*B)) hz r).trans + (finiteMarkedGenerating_le G p h hp hh d hd Q F x hdeg hF B hBp hAB) + have ht := finiteMarkedTail_nonneg G Q F x r h p + have he := (mul_le_mul_of_nonneg_right hpow ht).trans hm + calc + finiteMarkedTail G Q F x r h p ≤ (2*finiteMarkedMoment G Q F x 0 h p)/Real.exp ((r:ℝ)/(4*B)) := + (le_div_iff₀ (Real.exp_pos _)).mpr (by simpa only [mul_comm] using he) + _ = 2*Real.exp (-(r:ℝ)/(4*B))*finiteMarkedMoment G Q F x 0 h p := by + rw [neg_div,Real.exp_neg,div_eq_mul_inv] + ring + +end MarkedExponential + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Exploration/TailBounds.lean b/lean/OAI/Probability/UnimodularPercolation/Exploration/TailBounds.lean index d49958a65a19a64223700800c3ec4584cd6926fa..7139dcbdbdba552db159d7b1f43af6a7457c62c7 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Exploration/TailBounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Exploration/TailBounds.lean @@ -1,1241 +1,1241 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.FractionalMoments - -namespace OAI - -/-! Tail Bounds for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterTailDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteClusterTail_derivative_bound (G : BondGraph V E) (Q : Finset E) (x : V) - (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) (α C : ℝ) - (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) (hsmall : C*(h:ℝ)^α ≤ 1/4) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) : - finiteClusterTail G Q x n p ≤ 8*C*(h:ℝ)^α*deriv (finiteClusterTail G Q x n) p := by - have hmark := (markedConnection_le_cluster_power G Q x h p α hα hα1 (hfin x) (hI x)).trans - (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg h.2.1 α)) - rw [mul_comm ((h:ℝ)^α) C] at hmark - have hlow := finiteSeed_covariance_lower G Q x n p h hn (C*(h:ℝ)^α) hmark - have hupp := finiteSeed_covariance_upper G Q x p h α C hα hα1 hfin hI hC - (finiteClusterTailIndicator G x n) (finiteClusterTailIndicator_mono G x n) - have hF := finiteClusterTail_nonneg G Q x n p - have hd := finiteClusterTail_deriv_nonneg G Q x n p - have hp : (p:ℝ)*(1-(p:ℝ)) ≤ 1 := by nlinarith [p.2.1,p.2.2] - have hprod := mul_le_mul_of_nonneg_right hp hd - have hR : 0 ≤ 2*C*(h:ℝ)^α := mul_nonneg (by positivity) (Real.rpow_nonneg h.2.1 α) - have hh := mul_le_mul_of_nonneg_left hprod hR - have ha := le_abs_self (finiteCovariance Q p (finiteClusterTailIndicator G x n) - (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h)) - have hs := mul_le_mul_of_nonneg_right hsmall hF - change |_| ≤ _*deriv (finiteClusterTail G Q x n) p at hupp - nlinarith - -theorem exponential_transfer_of_deriv_lower (H : ℝ → ℝ) (a b K : ℝ) - (hH : Differentiable ℝ H) (hab : a ≤ b) - (hb : ∀ t ∈ Set.Icc a b, K*H t ≤ deriv H t) : - H a ≤ Real.exp (-K*(b-a))*H b := by - let F (t : ℝ) := Real.exp (-K*(t-a))*H t - have hF (t : ℝ) : HasDerivAt F (Real.exp (-K*(t-a))*(deriv H t-K*H t)) t := by - have he := (((hasDerivAt_id t).sub_const a).const_mul (-K)).exp - convert! he.mul (hH t).hasDerivAt using 1 - simp only [id_eq] - ring - have hmono : MonotoneOn F (Set.Icc a b) := by - apply monotoneOn_of_deriv_nonneg (convex_Icc a b) - (fun t _ => (hF t).continuousAt.continuousWithinAt) - (fun t _ => (hF t).differentiableAt.differentiableWithinAt) - intro t ht - rw [(hF t).deriv] - exact mul_nonneg (Real.exp_pos _).le (sub_nonneg.mpr (hb t (interior_subset ht))) - have hh := hmono ⟨le_rfl,hab⟩ ⟨hab,le_rfl⟩ hab - simpa only [F,sub_self,mul_zero,Real.exp_zero,one_mul] using hh - -end ClusterTailDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteStretchedTail -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cluster_finite_ae_mono [Countable E] (G : BondGraph V E) - (x : V) (p q : unitInterval) (hpq : p ≤ q) - (hq : ∀ᵐ ω ∂law q, (cluster G ω x).Finite) : - ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by - have hlabels : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), - (cluster G (openEdges labels q) x).Finite := by - apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) - (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges q).aemeasurable - rwa [map_openEdges] - rw [←map_openEdges p] - apply (ae_map_iff (measurable_openEdges p).aemeasurable - (by simpa only [Set.compl_ofPred,Set.not_infinite] using (measurableSet_infinite_cluster G x).compl)).mpr - filter_upwards [hlabels] with labels hl - exact hl.subset (fun y h => conn_mono G (openEdges_mono labels hpq) h) - -theorem finiteClusterTail_le_markedConnection (G : BondGraph V E) (Q : Finset E) - (x : V) (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) : - finiteClusterTail G Q x n p ≤ 2*markedConnectionPolynomial G Q x h p := by - have hh : (1:ℝ)/2*finiteClusterTail G Q x n p ≤ markedConnectionPolynomial G Q x h p := by - rw [finiteClusterTail,←bernoulliPolynomial_const_mul,markedConnection_component_polynomial] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - unfold finiteClusterTailIndicator - by_cases hs : n ≤ (finiteRootComponent G ω x).card - · simp only [ite_eq_left hs,mul_one] - apply one_sub_pow_one_sub_ge_half - exact hn.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hs) h.2.1) - · simp only [ite_eq_right hs,mul_zero] - apply sub_nonneg.mpr - exact pow_le_one₀ (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) - linarith - - - -theorem finiteClusterTail_stretched [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (x : V) (n : ℕ) (p q h : unitInterval) (hpq : p ≤ q) - (hh : 0 < (h:ℝ)) (hn : 1 ≤ (h:ℝ)*n) (α C : ℝ) - (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) (hsmall : C*(h:ℝ)^α ≤ 1/4) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : - finiteClusterTail G Q x n p ≤ - Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*C*(h:ℝ)^α) := by - have hden : 0 < 8*C*(h:ℝ)^α := by positivity - have hexp := exponential_transfer_of_deriv_lower (finiteClusterTail G Q x n) p q - (1/(8*C*(h:ℝ)^α)) (fun t => (hasDerivAt_bernoulliPolynomial Q _ t).differentiableAt) hpq - have hder : ∀ t ∈ Set.Icc (p:ℝ) (q:ℝ), - (1/(8*C*(h:ℝ)^α))*finiteClusterTail G Q x n t ≤ deriv (finiteClusterTail G Q x n) t := by - intro t ht - let r : unitInterval := ⟨t,⟨p.2.1.trans ht.1,ht.2.trans q.2.2⟩⟩ - have hrq : r ≤ q := ht.2 - have hmoment (y : V) := cluster_power_mono_integral G hloc y r q hrq α hα (hfin y) (hI y) - have he := finiteClusterTail_derivative_bound G Q x n r h hn α C hα hα1 hC0 hsmall - (fun y => cluster_finite_ae_mono G y r q hrq (hfin y)) (fun y => (hmoment y).1) - (fun y => (hmoment y).2.trans (hC y)) - rw [one_div,mul_comm,←div_eq_mul_inv] - apply (div_le_iff₀ hden).mpr - simpa only [mul_comm (deriv (finiteClusterTail G Q x n) t)] using he - have he := hexp hder - have hb := (finiteClusterTail_le_markedConnection G Q x n q h hn).trans - (mul_le_mul_of_nonneg_left ((markedConnection_le_cluster_power G Q x h q α hα hα1 (hfin x) (hI x)).trans - (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg hh.le α))) (by norm_num : (0:ℝ) ≤ 2)) - have hm := mul_le_mul_of_nonneg_left hb (Real.exp_pos (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))).le - have heq : -(1/(8*C*(h:ℝ)^α))*((q:ℝ)-(p:ℝ)) = -((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α) := by ring - rw [heq] at he - have hb' : Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*((h:ℝ)^α*C)) = - Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*C*(h:ℝ)^α) := by ring - exact he.trans (hm.trans_eq hb') - -end FiniteStretchedTail -end Percolation - - -namespace Percolation -open MeasureTheory Filter -section ExponentialPowerBound - - - -theorem exists_exp_neg_le_rpow (r : ℝ) (hr : 0 ≤ r) : - ∃ K : ℝ, 0 < K ∧ ∀ t : ℝ, 0 < t → Real.exp (-t) ≤ K*t^(-r) := by - obtain ⟨m,hm⟩ := exists_nat_ge r - let K : ℝ := m.factorial - have hK1 : 1 ≤ K := by - dsimp [K] - exact_mod_cast (Nat.succ_le_of_lt (Nat.factorial_pos m)) - refine ⟨K,by linarith,?_⟩ - intro t ht - rw [Real.rpow_neg ht.le,←div_eq_mul_inv] - apply (le_div_iff₀ (Real.rpow_pos_of_pos ht r)).mpr - by_cases ht1 : t ≤ 1 - · have hp := Real.rpow_le_one ht.le ht1 hr - have he : Real.exp (-t) ≤ 1 := by rw [Real.exp_le_one_iff]; linarith - exact (mul_le_of_le_one_left (Real.rpow_nonneg ht.le r) he).trans (hp.trans hK1) - · have hpow : t^r ≤ t^m := by - simpa only [Real.rpow_natCast] using Real.rpow_le_rpow_of_exponent_le (le_of_not_ge ht1) hm - have hTaylor : t^m ≤ K*Real.exp t := by - have hh := Real.pow_div_factorial_le_exp t ht.le m - exact (div_le_iff₀ (show (0:ℝ) < (m.factorial:ℝ) by positivity)).mp hh |>.trans_eq (mul_comm _ _) - calc - _ ≤ Real.exp (-t)*(K*Real.exp t) := - mul_le_mul_of_nonneg_left (hpow.trans hTaylor) (Real.exp_pos _).le - _ = K := by rw [Real.exp_neg]; field_simp - -end ExponentialPowerBound -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section PolynomialTails -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem exp_stretched_power_bound (r K δ C z : ℝ) (hδ : 0 < δ) (hC : 0 < C) - (hz : 0 < z) (hK : ∀ t : ℝ, 0 < t → Real.exp (-t) ≤ K*t^(-r)) : - Real.exp (-δ/(8*C*z))*(2*C*z) ≤ - (2*C*K*(8*C)^r)*δ^(-r)*z^(1+r) := by - have he := mul_le_mul_of_nonneg_right (hK (δ/(8*C*z)) (by positivity)) - (by positivity : 0 ≤ 2*C*z) - have hid : (δ/(8*C*z))^(-r)*(2*C*z) = - (2*C*(8*C)^r)*δ^(-r)*z^(1+r) := by - rw [Real.div_rpow hδ.le (by positivity),Real.mul_rpow (by positivity : 0 ≤ 8*C) hz.le, - Real.rpow_neg (by positivity : 0 ≤ 8*C),Real.rpow_neg hz.le, - Real.rpow_add hz,Real.rpow_one] - field_simp - calc - _ ≤ K*(δ/(8*C*z))^(-r)*(2*C*z) := by simpa only [neg_div] using he - _ = K*((δ/(8*C*z))^(-r)*(2*C*z)) := by ring - _ = _ := by rw [hid]; ring - - - -theorem finiteClusterTail_polynomial_large [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (q : unitInterval) (α C r : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) - (hr : 0 ≤ r) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : - ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E) (x : V) (p : unitInterval), p < q → - ∀ n : ℕ, 1 ≤ n → C*(n:ℝ)^(-α) ≤ 1/4 → - finiteClusterTail G Q x n p ≤ A*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-α*(1+r)) := by - obtain ⟨K,hK,hKb⟩ := exists_exp_neg_le_rpow r hr - refine ⟨2*C*K*(8*C)^r,by positivity,?_⟩ - intro Q x p hp n hn hsmall - have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) - let h : unitInterval := ⟨1/(n:ℝ),⟨by positivity,by apply (div_le_one hn0).mpr; exact_mod_cast hn⟩⟩ - have hh : 0 < (h:ℝ) := by dsimp [h]; positivity - have hhpow : (h:ℝ)^α = (n:ℝ)^(-α) := by - dsimp [h] - rw [one_div,Real.inv_rpow hn0.le,Real.rpow_neg hn0.le] - have hhprod : 1 ≤ (h:ℝ)*n := by dsimp [h]; rw [one_div,inv_mul_cancel₀ hn0.ne'] - have hst := finiteClusterTail_stretched G hloc Q x n p q h hp.le hh hhprod α C hα hα1 hC0 - (by rwa [hhpow]) hfin hI hC - have he := exp_stretched_power_bound r K ((q:ℝ)-(p:ℝ)) C ((h:ℝ)^α) - (sub_pos.mpr hp) hC0 (Real.rpow_pos_of_pos hh α) hKb - apply hst.trans - convert! he using 1 - rw [hhpow,←Real.rpow_mul hn0.le] - -end PolynomialTails -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section UniformPolynomialTails -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteClusterTail_le_one (G : BondGraph V E) (Q : Finset E) (x : V) - (n : ℕ) (p : unitInterval) : finiteClusterTail G Q x n p ≤ 1 := by - rw [finiteClusterTail,←bernoulliPolynomial_const Q 1 p] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - unfold finiteClusterTailIndicator - split_ifs <;> norm_num - - - -theorem finiteClusterTail_polynomial [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (q : unitInterval) (α C r : ℝ) (hα : 0 < α) (hα1 : α ≤ 1) (hC0 : 0 < C) - (hr : 0 ≤ r) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : - ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E) (x : V) (p : unitInterval), p < q → - ∀ n : ℕ, 1 ≤ n → - finiteClusterTail G Q x n p ≤ A*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-α*(1+r)) := by - obtain ⟨A,hA,hbig⟩ := finiteClusterTail_polynomial_large G hloc q α C r hα.le hα1 hC0 hr hfin hI hC - have ht : Tendsto (fun n : ℕ => C*(n:ℝ)^(-α)) atTop (nhds 0) := by - simpa only [mul_zero,Function.comp_apply] using tendsto_const_nhds.mul - ((tendsto_rpow_neg_atTop hα).comp tendsto_natCast_atTop_atTop) - obtain ⟨N,hN⟩ := eventually_atTop.mp (ht.eventually (gt_mem_nhds (by norm_num : (0:ℝ) < 1/4))) - let s := α*(1+r) - have hs : 0 ≤ s := by dsimp [s]; positivity - let B : ℝ := ((N+1:ℕ):ℝ)^s+A - have hB : 0 < B := by dsimp [B]; positivity - refine ⟨B,hB,?_⟩ - intro Q x p hp n hn - have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) - have hδ : 0 < (q:ℝ)-(p:ℝ) := sub_pos.mpr hp - have hhead : 1 ≤ ((q:ℝ)-(p:ℝ))^(-r) := - Real.one_le_rpow_of_pos_of_le_one_of_nonpos hδ (by linarith [p.2.1,q.2.2]) (by linarith) - by_cases hnN : N ≤ n - · apply (hbig Q x p hp n hn (hN n hnN).le).trans - exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right - (by dsimp [B]; linarith [Real.rpow_nonneg (Nat.cast_nonneg (N+1)) s]) (Real.rpow_nonneg hδ.le _)) (Real.rpow_nonneg hn0.le _) - · have hnB : (n:ℝ)^s ≤ B := by - apply (Real.rpow_le_rpow hn0.le (show (n:ℝ) ≤ ((N+1:ℕ):ℝ) by exact_mod_cast (by omega : n ≤ N+1)) hs).trans - dsimp [B] - linarith - have hBδ : B ≤ B*((q:ℝ)-(p:ℝ))^(-r) := by nlinarith - have hbound : 1 ≤ B*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-s) := by - rw [Real.rpow_neg hn0.le,←div_eq_mul_inv] - exact (one_le_div (Real.rpow_pos_of_pos hn0 s)).mpr (hnB.trans hBδ) - exact (finiteClusterTail_le_one G Q x n p).trans (by simpa only [s,neg_mul] using hbound) - -end UniformPolynomialTails -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section TailSummation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem natCast_eq_sum_tail (k M : ℕ) (hk : k ≤ M) : - (k:ℝ) = ∑ i ∈ Finset.range M, if i+1 ≤ k then (1:ℝ) else 0 := by - rw [Finset.sum_boole] - congr 1 - have hh : (Finset.range M).filter (fun i => i+1 ≤ k) = Finset.range k := by - ext i - simp only [Finset.mem_filter,Finset.mem_range] - omega - rw [hh,Finset.card_range] - -theorem finiteClusterSize_eq_sum_tail (G : BondGraph V E) (Q : Finset E) (x : V) (p : ℝ) : - bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p = - ∑ n ∈ Finset.range (insert x (searchVertices G Q)).card, finiteClusterTail G Q x (n+1) p := by - simp only [finiteClusterTail] - rw [←bernoulliPolynomial_sum] - apply bernoulliPolynomial_congr - intro ω hω - exact natCast_eq_sum_tail _ _ (Finset.card_le_card (finiteRootComponent_subset G Q _ x ω hω (by rfl))) - -theorem summable_shifted_rpow (s : ℝ) (hs : 1 < s) : - Summable (fun n : ℕ => ((n+1:ℕ):ℝ)^(-s)) := by - exact (summable_nat_add_iff 1).mpr (Real.summable_nat_rpow.mpr (by linarith)) - - -theorem finiteClusterSize_bound_of_tail (G : BondGraph V E) (Q : Finset E) (x : V) - (p : unitInterval) (A s : ℝ) (hA : 0 ≤ A) (hs : 1 < s) - (hf : ∀ n : ℕ, 1 ≤ n → finiteClusterTail G Q x n p ≤ A*(n:ℝ)^(-s)) : - bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p ≤ - A*(∑' n : ℕ, ((n+1:ℕ):ℝ)^(-s)) := by - rw [finiteClusterSize_eq_sum_tail,←tsum_mul_left] - have hsumm := (summable_shifted_rpow s hs).mul_left A - apply (Finset.sum_le_sum (fun n _ => hf (n+1) (by omega))).trans - exact hsumm.sum_le_tsum _ (fun n _ => mul_nonneg hA (Real.rpow_nonneg (Nat.cast_nonneg _) _)) - -end TailSummation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section SusceptibilityExhaustion -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_connection_row_le_size (G : BondGraph V E) (Q : Finset E) - (x : V) (K : Finset V) (p : unitInterval) : - (∑ y ∈ K, bernoulliPolynomial Q (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) ≤ - bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p := by - rw [←bernoulliPolynomial_sum] - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - rw [Finset.sum_boole] - apply Nat.cast_le.mpr - apply Finset.card_le_card - intro y hy - change y ∈ (finiteRootComponent G ω x : Set V) - rw [coe_finiteRootComponent] - exact (Finset.mem_filter.mp hy).2 - - - -theorem susceptibility_bound_of_finite_size [Countable E] (G : BondGraph V E) - (x : V) (p : unitInterval) (B : ℝ) - (hB : ∀ Q : Finset E, bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p ≤ B) : - Summable (twoPoint G p x) ∧ susceptibility G p x ≤ B := by - let : Encodable E := Encodable.ofCountable E - let Q := vertexExhaustion (V := E) - have hrow (K : Finset V) : (∑ y ∈ K, twoPoint G p x y) ≤ B := by - have ht (y : V) : Tendsto (fun n => bernoulliPolynomial (Q n) - (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) atTop (nhds (twoPoint G p x y)) := by - have hc (e : E) (_ : e ∈ (Set.univ : Set E)) : ∃ n, e ∈ Q n := by - obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e} : Finset E) - exact ⟨n,hn (by simp)⟩ - simpa only [Set.inter_univ,twoPoint,Measure.real] using! finite_connection_polynomial_tendsto G Set.univ Q - vertexExhaustion_mono (fun _ => Set.subset_univ _) hc p x y - apply le_of_tendsto (tendsto_finsetSum K (fun y _ => ht y)) - exact Filter.Eventually.of_forall (fun n => (finite_connection_row_le_size G (Q n) x K p).trans (hB (Q n))) - exact ⟨summable_of_sum_le (twoPoint_nonneg G p x) hrow, - Real.tsum_le_of_sum_le (twoPoint_nonneg G p x) hrow⟩ - -end SusceptibilityExhaustion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section SusceptibilityPowerFromMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem susceptibility_power_of_uniform_moment [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (q : unitInterval) (α C r : ℝ) (hα : 0 < α) (hα1 : α ≤ 1) (hC0 : 0 < C) - (hr : 0 ≤ r) (hs : 1 < α*(1+r)) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) - (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : - ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < q → ∀ x, - Summable (twoPoint G p x) ∧ susceptibility G p x ≤ D*((q:ℝ)-(p:ℝ))^(-r) := by - obtain ⟨A,hA,hbound⟩ := finiteClusterTail_polynomial G hloc q α C r hα hα1 hC0 hr hfin hI hC - let S := ∑' n : ℕ, ((n+1:ℕ):ℝ)^(-(α*(1+r))) - have hS : 0 ≤ S := tsum_nonneg (fun _ => Real.rpow_nonneg (Nat.cast_nonneg _) _) - refine ⟨1+A*S,by positivity,?_⟩ - intro p hp x - have hδ : 0 < (q:ℝ)-(p:ℝ) := sub_pos.mpr (show (p:ℝ)<(q:ℝ) from hp) - apply susceptibility_bound_of_finite_size - intro Q - have hh := finiteClusterSize_bound_of_tail G Q x p (A*((q:ℝ)-(p:ℝ))^(-r)) (α*(1+r)) - (mul_nonneg hA.le (Real.rpow_nonneg hδ.le _)) hs (by - intro n hn - simpa only [neg_mul] using hbound Q x p hp n hn) - calc - _ ≤ (A*((q:ℝ)-(p:ℝ))^(-r))*S := hh - _ = (A*S)*((q:ℝ)-(p:ℝ))^(-r) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_right (by linarith) (Real.rpow_nonneg hδ.le _) - - - -theorem almost_linear_susceptibility_of_moments [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) - (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) - (hmom : ∀ α : ℝ, 0 < α → α < 1/2 → ∃ C : ℝ, 0 < C ∧ ∀ y, - Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q) ∧ - (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) - (η : ℝ) (hη : 0 < η) : - ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < q → ∀ x, - Summable (twoPoint G p x) ∧ susceptibility G p x ≤ D*((q:ℝ)-(p:ℝ))^(-1-η) := by - let α : ℝ := 1/(2+η/2) - have hden : 0 < 2+η/2 := by linarith - have hα : 0 < α := one_div_pos.mpr hden - have hαhalf : α < 1/2 := by - apply (div_lt_div_iff₀ hden (by norm_num : (0:ℝ) < 2)).mpr - linarith - have hs : 1 < α*(1+(1+η)) := by - dsimp [α] - rw [one_div,mul_comm,←div_eq_mul_inv] - apply (one_lt_div hden).mpr - linarith - obtain ⟨C,hC,hm⟩ := hmom α hα hαhalf - obtain ⟨D,hD,hbound⟩ := susceptibility_power_of_uniform_moment G hloc q α C (1+η) hα - (by linarith) hC (by linarith) hs hfin (fun y => (hm y).1) (fun y => (hm y).2) - refine ⟨D,hD,?_⟩ - intro p hp x - simpa only [neg_add_rev,sub_eq_add_neg,add_comm] using hbound p hp x - -end SusceptibilityPowerFromMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section SourceAlmostLinear -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cluster_finite_ae_covariant [Countable E] (G : BondGraph V E) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : - ∀ᵐ ω ∂law p, (cluster G ω (a x)).Finite := by - have hh : ∀ᵐ ω ∂law p, (cluster G (b ⁻¹' ω) x).Finite := by - apply ae_of_ae_map (μ := law p) (p := fun ω : Set E => (cluster G ω x).Finite) - (measurable_set_preimage b).aemeasurable - rwa [law_map_preimage_equiv] - filter_upwards [hh] with ω hω - rw [←cluster_aut G hab ω x] - exact hω.image a - - - -theorem almost_linear_susceptibility - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (η : ℝ) (hη : 0 < η) : - ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < pc G → ∀ x, - susceptibility G p x ≤ D*((pc G:ℝ)-(p:ℝ))^(-1-η) := by - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by - intro x - obtain ⟨i,a,b,hab,rfl⟩ := hcover x - exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) - have hmom (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) := - uniform_cluster_power_of_root G hloc (pc G) root hcover α - (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) - obtain ⟨D,hD,hb⟩ := almost_linear_susceptibility_of_moments G hloc (pc G) hfinite hmom η hη - exact ⟨D,hD,fun p hp x => (hb p hp x).2⟩ - -end SourceAlmostLinear -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section QueryTranscriptLaw -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EdgeQueryTree - -@[reducible] def forget : EdgeQueryTree E → ProbeTree - | .done b => .done b - | .query _ t₀ t₁ => .edge t₀.forget t₁.forget - -noncomputable def leaf (ω : Finset E) : (t : EdgeQueryTree E) → t.forget.Leaf - | .done _ => () - | .query e t₀ t₁ => if e ∈ ω then Sum.inr (t₁.leaf ω) else Sum.inl (t₀.leaf ω) - -theorem leaf_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) : t.leaf ω = t.leaf η := by - induction t generalizing Q with - | done => rfl - | query e t₀ t₁ ih₀ ih₁ => - simp only [leaf,h e ht.1] - split - · rw [ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha))] - · rw [ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha))] - -theorem leaf_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - {e : E} (he : e ∉ Q) (ω : Finset E) : t.leaf (insert e ω) = t.leaf ω := by - apply leaf_congr t ht - intro a ha - simp [show a ≠ e from fun h => he (h ▸ ha)] - - -theorem leaf_expectation (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : ℝ) (f : t.forget.Leaf → ℝ) : - bernoulliPolynomial Q (fun ω => f (t.leaf ω)) p = - ∑ l, ProbeTree.weight p 0 t.forget l*f l := by - induction t generalizing Q with - | done b => - change bernoulliPolynomial Q (fun _ => f ()) p = ∑ l : Unit, 1*f l - simp [bernoulliPolynomial_const,Finset.sum_singleton] - | query e t₀ t₁ ih₀ ih₁ => - obtain ⟨he,h₀,h₁⟩ := ht - conv_lhs => rw [←Finset.insert_erase he] - rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] - have hc : bernoulliPolynomial (Q.erase e) (fun ω => f ((query e t₀ t₁).leaf ω)) p = - bernoulliPolynomial (Q.erase e) (fun ω => f (Sum.inl (t₀.leaf ω))) p := by - apply bernoulliPolynomial_congr - intro ω hω - simp only [leaf,show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),ite_false] - have ho : bernoulliPolynomial (Q.erase e) (fun ω => f ((query e t₀ t₁).leaf (insert e ω))) p = - bernoulliPolynomial (Q.erase e) (fun ω => f (Sum.inr (t₁.leaf ω))) p := by - apply bernoulliPolynomial_congr - intro ω _ - simp only [leaf,Finset.mem_insert_self,ite_true, - leaf_insert t₁ h₁ (Finset.notMem_erase e Q)] - rw [hc,ho,ih₀ h₀ (fun l => f (Sum.inl l)),ih₁ h₁ (fun l => f (Sum.inr l))] - change _ = ∑ l : t₀.forget.Leaf ⊕ t₁.forget.Leaf, _ - simp only [Fintype.sum_sum_type,ProbeTree.weight,Finset.mul_sum,mul_assoc] - -noncomputable def score (p : ℝ) (t : EdgeQueryTree E) (ω : Finset E) : ℝ := - ProbeTree.score p t.forget (t.leaf ω) - -noncomputable def queryCount (t : EdgeQueryTree E) (ω : Finset E) : ℕ := - ProbeTree.queries t.forget (t.leaf ω) - - -theorem score_mgf (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (lam : ℝ) : - bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p ≤ 1 := by - change bernoulliPolynomial Q (fun ω => Real.exp (lam*ProbeTree.score p t.forget (t.leaf ω)- - lam^2*(ProbeTree.queries t.forget (t.leaf ω):ℝ)/8)) p ≤ 1 - rw [leaf_expectation t ht p (fun l => Real.exp (lam*ProbeTree.score p t.forget l- - lam^2*(ProbeTree.queries t.forget l:ℝ)/8))] - exact ProbeTree.score_mgf p 0 lam t.forget - -end EdgeQueryTree -end QueryTranscriptLaw -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section CappedQueryConcentration -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EdgeQueryTree - - - -theorem capped_score_mgf (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (lam : ℝ) (N : ℕ) (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : - bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω)) p ≤ Real.exp (lam^2*(N:ℝ)/8) := by - calc - _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (lam^2*(N:ℝ)/8)* - Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω hω - rw [←Real.exp_add] - apply Real.exp_le_exp.mpr - have hn : (t.queryCount ω:ℝ) ≤ (N:ℝ) := Nat.cast_le.mpr (hN ω hω) - nlinarith [sq_nonneg lam] - _ = Real.exp (lam^2*(N:ℝ)/8)*bernoulliPolynomial Q - (fun ω => Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p := - bernoulliPolynomial_const_mul _ _ _ _ - _ ≤ _ := by simpa using mul_le_mul_of_nonneg_left (t.score_mgf ht p lam) (Real.exp_pos _).le - -theorem capped_score_chernoff (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (lam a : ℝ) (hlam : 0 ≤ lam) (N : ℕ) - (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : - bernoulliPolynomial Q (fun ω => if a ≤ t.score p ω then 1 else 0) p ≤ - Real.exp (-lam*a+lam^2*(N:ℝ)/8) := by - calc - _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (-lam*a)*Real.exp (lam*t.score p ω)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - split_ifs with h - · rw [←Real.exp_add] - exact Real.one_le_exp (by nlinarith) - · positivity - _ = Real.exp (-lam*a)*bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω)) p := - bernoulliPolynomial_const_mul _ _ _ _ - _ ≤ Real.exp (-lam*a)*Real.exp (lam^2*(N:ℝ)/8) := - mul_le_mul_of_nonneg_left (t.capped_score_mgf ht p lam N hN) (Real.exp_pos _).le - _ = _ := (Real.exp_add _ _).symm - -theorem capped_neg_score_chernoff (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (lam a : ℝ) (hlam : 0 ≤ lam) (N : ℕ) - (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : - bernoulliPolynomial Q (fun ω => if a ≤ -t.score p ω then 1 else 0) p ≤ - Real.exp (-lam*a+lam^2*(N:ℝ)/8) := by - calc - _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (-lam*a)*Real.exp ((-lam)*t.score p ω)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - split_ifs with h - · rw [←Real.exp_add] - exact Real.one_le_exp (by nlinarith) - · positivity - _ = Real.exp (-lam*a)*bernoulliPolynomial Q (fun ω => Real.exp ((-lam)*t.score p ω)) p := - bernoulliPolynomial_const_mul _ _ _ _ - _ ≤ Real.exp (-lam*a)*Real.exp ((-lam)^2*(N:ℝ)/8) := - mul_le_mul_of_nonneg_left (t.capped_score_mgf ht p (-lam) N hN) (Real.exp_pos _).le - _ = _ := by rw [←Real.exp_add]; congr 1; ring - - - -theorem capped_score_tail (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (a : ℝ) (ha : 0 ≤ a) (N : ℕ) (hN0 : 0 < N) - (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : - bernoulliPolynomial Q (fun ω => if a ≤ |t.score p ω| then 1 else 0) p ≤ - 2*Real.exp (-2*a^2/(N:ℝ)) := by - let lam : ℝ := 4*a/(N:ℝ) - have hNr : 0 < (N:ℝ) := Nat.cast_pos.mpr hN0 - have hlam : 0 ≤ lam := div_nonneg (by positivity) hNr.le - have he : -lam*a+lam^2*(N:ℝ)/8 = -2*a^2/(N:ℝ) := by - dsimp [lam] - field_simp - ring - calc - _ ≤ bernoulliPolynomial Q (fun ω => (if a ≤ t.score p ω then 1 else 0)+ - (if a ≤ -t.score p ω then 1 else 0)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω _ - by_cases h : a ≤ |t.score p ω| - · rcases le_abs.mp h with h₁ | h₂ - · simp only [ite_eq_left h,ite_eq_left h₁]; split_ifs <;> norm_num - · simp only [ite_eq_left h,ite_eq_left h₂]; split_ifs <;> norm_num - · simp only [ite_eq_right h]; split_ifs <;> norm_num - _ = bernoulliPolynomial Q (fun ω => if a ≤ t.score p ω then 1 else 0) p+ - bernoulliPolynomial Q (fun ω => if a ≤ -t.score p ω then 1 else 0) p := - bernoulliPolynomial_add _ _ _ _ - _ ≤ Real.exp (-lam*a+lam^2*(N:ℝ)/8)+Real.exp (-lam*a+lam^2*(N:ℝ)/8) := - add_le_add (t.capped_score_chernoff ht p lam a hlam N hN) - (t.capped_neg_score_chernoff ht p lam a hlam N hN) - _ = _ := by rw [he]; ring - -end EdgeQueryTree -end CappedQueryConcentration -end Percolation - - -namespace Percolation -universe v -variable {E : Type v} -section QueryScoreSets -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EdgeQueryTree - -noncomputable def readSet (t : EdgeQueryTree E) (Q ω : Finset E) : Finset E := - Q.filter (fun e => t.reads ω e) - -@[simp] theorem mem_readSet (t : EdgeQueryTree E) (Q ω : Finset E) (e : E) : - e ∈ t.readSet Q ω ↔ e ∈ Q ∧ t.reads ω e := Finset.mem_filter - -theorem readSet_query (e : E) (t₀ t₁ : EdgeQueryTree E) {Q : Finset E} - (ht : (query e t₀ t₁).Valid Q) (ω : Finset E) : - (query e t₀ t₁).readSet Q ω = insert e - (if e ∈ ω then t₁.readSet (Q.erase e) ω else t₀.readSet (Q.erase e) ω) := by - ext i - by_cases hie : i = e - · subst i - simp only [mem_readSet,reads,true_or,and_true,Finset.mem_insert_self,iff_true] - exact ht.1 - · by_cases heω : e ∈ ω <;> simp [mem_readSet,reads,hie,heω] - -theorem score_query (e : E) (t₀ t₁ : EdgeQueryTree E) (ω : Finset E) (p : ℝ) : - (query e t₀ t₁).score p ω = - (if e ∈ ω then t₁.score p ω else t₀.score p ω)+(if e ∈ ω then 1 else 0)-p := by - by_cases h : e ∈ ω - · simp only [score,leaf,ite_eq_left h,ProbeTree.score]; ring - · simp only [score,leaf,ite_eq_right h,ProbeTree.score]; ring - -theorem queryCount_query (e : E) (t₀ t₁ : EdgeQueryTree E) (ω : Finset E) : - (query e t₀ t₁).queryCount ω = - (if e ∈ ω then t₁.queryCount ω else t₀.queryCount ω)+1 := by - by_cases h : e ∈ ω <;> simp [queryCount,leaf,h,ProbeTree.queries] - -theorem queryCount_eq_card (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (ω : Finset E) : t.queryCount ω = (t.readSet Q ω).card := by - induction t generalizing Q with - | done b => - have hs : (done b : EdgeQueryTree E).readSet Q ω = ∅ := by - ext e - simp only [mem_readSet,reads,and_false,Finset.notMem_empty] - rw [hs] - rfl - | query e t₀ t₁ ih₀ ih₁ => - rw [queryCount_query,readSet_query _ _ _ ht] - have h₀ : e ∉ t₀.readSet (Q.erase e) ω := by simp [readSet] - have h₁ : e ∉ t₁.readSet (Q.erase e) ω := by simp [readSet] - by_cases heω : e ∈ ω - · simp only [ite_eq_left heω,Finset.card_insert_of_notMem h₁,ih₁ ht.2.2] - · simp only [ite_eq_right heω,Finset.card_insert_of_notMem h₀,ih₀ ht.2.1] - - -theorem score_eq_sum (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (ω : Finset E) (p : ℝ) : - t.score p ω = ∑ e ∈ t.readSet Q ω, ((if e ∈ ω then 1 else 0)-p) := by - induction t generalizing Q with - | done b => - have hs : (done b : EdgeQueryTree E).readSet Q ω = ∅ := by - ext e - simp only [mem_readSet,reads,and_false,Finset.notMem_empty] - rw [hs,Finset.sum_empty] - rfl - | query e t₀ t₁ ih₀ ih₁ => - rw [score_query,readSet_query _ _ _ ht] - have h₀ : e ∉ t₀.readSet (Q.erase e) ω := by simp [readSet] - have h₁ : e ∉ t₁.readSet (Q.erase e) ω := by simp [readSet] - by_cases heω : e ∈ ω - · simp only [ite_eq_left heω,Finset.sum_insert h₁,ih₁ ht.2.2]; ring - · simp only [ite_eq_right heω,Finset.sum_insert h₀,ih₀ ht.2.1]; ring - -end EdgeQueryTree -end QueryScoreSets -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IncidenceExploration -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def IncidencePending (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Prop := - ∃ t : E × V × V, t.1 ∈ Q ∧ t.2.1 ∈ R ∧ G t.1 = s(t.2.1,t.2.2) - -noncomputable def incidencePick (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (h : IncidencePending G Q R) : E × V × V := Classical.choose h - -theorem incidencePick_spec (G : BondGraph V E) (Q : Finset E) (R : Finset V) - (h : IncidencePending G Q R) : - (incidencePick G Q R h).1 ∈ Q ∧ (incidencePick G Q R h).2.1 ∈ R ∧ - G (incidencePick G Q R h).1 = s((incidencePick G Q R h).2.1,(incidencePick G Q R h).2.2) := - Classical.choose_spec h - -noncomputable def incidenceSearch (G : BondGraph V E) : - ℕ → Finset E → Finset V → EdgeQueryTree E - | 0, _, _ => .done false - | n+1, Q, R => - if hc : IncidencePending G Q R then - let t := incidencePick G Q R hc - .query t.1 (incidenceSearch G n (Q.erase t.1) R) - (incidenceSearch G n (Q.erase t.1) (insert t.2.2 R)) - else .done false - -theorem incidenceSearch_valid (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) : - (incidenceSearch G n Q R).Valid Q := by - induction n generalizing Q R with - | zero => trivial - | succ n ih => - simp only [incidenceSearch] - split_ifs with hc - · exact ⟨(incidencePick_spec G Q R hc).1,ih _ _,ih _ _⟩ - · trivial - -theorem incidenceSearch_cap (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) - (ω : Finset E) : (incidenceSearch G n Q R).queryCount ω ≤ n := by - induction n generalizing Q R with - | zero => exact le_rfl - | succ n ih => - simp only [incidenceSearch] - split_ifs - · rw [EdgeQueryTree.queryCount_query] - split <;> exact Nat.add_le_add_right (ih _ _) 1 - · exact Nat.zero_le _ - - - -structure IncidenceInvariant (G : BondGraph V E) (Q ω : Finset E) (R C : Finset V) : Prop where - discovered : R ⊆ C - closed : ∀ a ∈ C, ∀ e ∈ ω, ∀ b, G e = s(a,b) → b ∈ C - reachable : ∀ y ∈ C, ∃ r ∈ R, Conn G ((ω ∩ Q : Finset E):Set E) r y - -theorem incidentBonds_erase (G : BondGraph V E) (Q : Finset E) (C : Finset V) (e : E) : - incidentBonds G (Q.erase e) C = (incidentBonds G Q C).erase e := by - ext f - simp only [mem_incidentBonds,Finset.mem_erase] - tauto - -theorem incidencePending_of_mem (G : BondGraph V E) {Q : Finset E} {R : Finset V} - {e : E} (h : e ∈ incidentBonds G Q R) : IncidencePending G Q R := by - obtain ⟨he,a,ha,hae⟩ := (mem_incidentBonds G Q R e).mp h - obtain ⟨b,hab⟩ := Sym2.mem_iff_exists.mp hae - exact ⟨(e,a,b),he,ha,hab⟩ - -end IncidenceExploration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IncidenceInvariantSteps -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace IncidenceInvariant - -theorem closed_step {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} - (h : IncidenceInvariant G Q ω R C) (e : E) (he : e ∉ ω) : - IncidenceInvariant G (Q.erase e) ω R C := by - refine ⟨h.discovered,h.closed,?_⟩ - have heq : ω ∩ Q.erase e = ω ∩ Q := by ext f; simp only [Finset.mem_inter,Finset.mem_erase]; grind - simpa only [heq] using h.reachable - -theorem open_step {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} - (h : IncidenceInvariant G Q ω R C) {e : E} (heQ : e ∈ Q) (heω : e ∈ ω) - {a b : V} (ha : a ∈ R) (hab : G e = s(a,b)) : - IncidenceInvariant G (Q.erase e) ω (insert b R) C := by - have hb : b ∈ C := h.closed a (h.discovered ha) e heω b hab - refine ⟨Finset.insert_subset hb h.discovered,h.closed,?_⟩ - have heq : ((ω ∩ Q : Finset E):Set E) = insert e ((ω ∩ Q.erase e : Finset E):Set E) := by - ext f - simp only [Finset.mem_coe,Finset.mem_inter,Finset.mem_erase,Set.mem_insert_iff] - grind - intro y hy - obtain ⟨r,hr,hry⟩ := h.reachable y hy - rw [heq] at hry - rcases (conn_insert_iff G _ e a b r y hab).mp hry with h₀ | h₁ | h₁ - · exact ⟨r,Finset.mem_insert_of_mem hr,h₀⟩ - · exact ⟨b,Finset.mem_insert_self _ _,h₁.2⟩ - · exact ⟨a,Finset.mem_insert_of_mem ha,h₁.2⟩ - -theorem no_pending {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} - (h : IncidenceInvariant G Q ω R C) (hp : ¬ IncidencePending G Q R) : - incidentBonds G Q C = ∅ := by - have hCR : C ⊆ R := by - intro y hy - obtain ⟨r,hr,hry⟩ := h.reachable y hy - clear hy - induction hry with - | refl => exact hr - | @tail a b _ hab ih => - obtain ⟨e,he,heab⟩ := hab - exact (hp ⟨(e,a,b),(Finset.mem_inter.mp he).2,ih,heab⟩).elim - apply Finset.eq_empty_iff_forall_notMem.mpr - intro e he - apply hp - apply incidencePending_of_mem G (e := e) - obtain ⟨heQ,a,ha,hae⟩ := (mem_incidentBonds G Q C e).mp he - exact (mem_incidentBonds G Q R e).mpr ⟨heQ,a,hCR ha,hae⟩ - -end IncidenceInvariant -end IncidenceInvariantSteps -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IncidenceCompletion -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem incidenceSearch_readSet (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) (R C : Finset V) - (hinv : IncidenceInvariant G Q ω R C) (hn : (incidentBonds G Q C).card ≤ n) : - (incidenceSearch G n Q R).readSet Q ω = incidentBonds G Q C := by - induction n generalizing Q R with - | zero => - have he : incidentBonds G Q C = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hn) - simp [incidenceSearch,EdgeQueryTree.readSet,EdgeQueryTree.reads,he] - | succ n ih => - simp only [incidenceSearch] - split_ifs with hc - · obtain ⟨he,ha,hab⟩ := incidencePick_spec G Q R hc - have heC : (incidencePick G Q R hc).1 ∈ incidentBonds G Q C := - (mem_incidentBonds G Q C _).mpr ⟨he,_,hinv.discovered ha,by rw [hab]; simp⟩ - have hn' : (incidentBonds G (Q.erase (incidencePick G Q R hc).1) C).card ≤ n := by - rw [incidentBonds_erase,Finset.card_erase_of_mem heC] - have hh := Finset.card_pos.mpr ⟨_,heC⟩ - omega - rw [EdgeQueryTree.readSet_query _ _ _ ⟨he,incidenceSearch_valid ..,incidenceSearch_valid ..⟩] - by_cases heω : (incidencePick G Q R hc).1 ∈ ω - · rw [ite_eq_left heω,ih _ _ (hinv.open_step he heω ha hab) hn',incidentBonds_erase, - Finset.insert_erase heC] - · rw [ite_eq_right heω,ih _ _ (hinv.closed_step _ heω) hn',incidentBonds_erase, - Finset.insert_erase heC] - · rw [hinv.no_pending hc] - ext e - simp only [EdgeQueryTree.mem_readSet,EdgeQueryTree.reads, - Finset.notMem_empty,and_false] - -theorem incidenceInvariant_root (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) (x : V) : - IncidenceInvariant G Q ω {x} (finiteRootComponent G ω x) := by - have hmem (y : V) : y ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x y := by - change y ∈ ((finiteRootComponent G ω x:Set V)) ↔ _ - rw [coe_finiteRootComponent] - rfl - refine ⟨?_,?_,?_⟩ - · intro y hy - rw [Finset.mem_singleton] at hy - subst y - exact (hmem x).mpr (conn_refl G _ _) - · intro a ha e he b hab - exact (hmem b).mpr ((hmem a).mp ha |>.tail ⟨e,he,hab⟩) - · intro y hy - refine ⟨x,Finset.mem_singleton_self _,?_⟩ - rw [Finset.inter_eq_left.mpr hω] - exact (hmem y).mp hy - - - -theorem incidenceSearch_completed_score (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) - (hω : ω ⊆ Q) (x : V) (p : ℝ) - (hn : (incidentBonds G Q (finiteRootComponent G ω x)).card ≤ n) : - (incidenceSearch G n Q {x}).score p ω = - ∑ e ∈ incidentBonds G Q (finiteRootComponent G ω x), ((if e ∈ ω then 1 else 0)-p) := by - rw [EdgeQueryTree.score_eq_sum _ (incidenceSearch_valid ..), - incidenceSearch_readSet G n Q ω {x} _ (incidenceInvariant_root G Q ω hω x) hn] - -theorem incidenceSearch_score_tail (G : BondGraph V E) (n : ℕ) (hn : 0 < n) - (Q : Finset E) (R : Finset V) (p : unitInterval) (a : ℝ) (ha : 0 ≤ a) : - bernoulliPolynomial Q (fun ω => if a ≤ |(incidenceSearch G n Q R).score p ω| then 1 else 0) p ≤ - 2*Real.exp (-2*a^2/(n:ℝ)) := - EdgeQueryTree.capped_score_tail _ (incidenceSearch_valid ..) p a ha n hn - (fun ω _ => incidenceSearch_cap G n Q R ω) - -end IncidenceCompletion -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExteriorExplorationLaw -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem cluster_exterior_expectation_bound (G : BondGraph V E) (Q : Finset E) - (x : V) (p : unitInterval) (f : Finset V → Finset E → ℝ) (K : ℝ) - (hf : ∀ W : Finset V, bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ K) : - bernoulliPolynomial Q (fun ω => f (finiteRootComponent G ω x) - (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p ≤ K := by - let F := insert x (searchVertices G Q) - have hpoint (ω : Finset E) (hω : ω ⊆ Q) : - f (finiteRootComponent G ω x) (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) = - ∑ W ∈ F.powerset, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)* - f W (exteriorBonds G ω (W:Set V)) := by - rw [←sum_component_partition G Q F x ω hω (by rfl) - (fun W => f W (exteriorBonds G ω (W:Set V)))] - apply Finset.sum_congr rfl - intro W _ - split_ifs <;> simp - rw [bernoulliPolynomial_congr Q hpoint,bernoulliPolynomial_sum] - calc - _ = ∑ W ∈ F.powerset, - bernoulliPolynomial Q (fun ω => if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p* - bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p := by - apply Finset.sum_congr rfl - intro W _ - rw [cluster_cell_exterior_factor,←cluster_cell_incident_probability G Q x (W:Set V) p] - _ ≤ ∑ W ∈ F.powerset, - bernoulliPolynomial Q (fun ω => if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p*K := by - apply Finset.sum_le_sum - intro W _ - apply mul_le_mul_of_nonneg_left (hf W) - exact bernoulliPolynomial_nonneg _ _ p p.2 (fun _ _ => by split_ifs <;> norm_num) - _ = K := by - rw [←Finset.sum_mul,←bernoulliPolynomial_sum] - have hh : bernoulliPolynomial Q (fun ω => ∑ W ∈ F.powerset, - if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p = 1 := by - trans bernoulliPolynomial Q (fun _ => (1:ℝ)) p - · apply bernoulliPolynomial_congr - intro ω hω - exact sum_component_partition G Q F x ω hω (by rfl) (fun _ => 1) - · exact bernoulliPolynomial_const Q 1 p - rw [hh,one_mul] - -noncomputable def exteriorSearchScore (G : BondGraph V E) (n : ℕ) (Q : Finset E) - (x v : V) (p : ℝ) (ω : Finset E) : ℝ := - let W := finiteRootComponent G ω x - if v ∈ W then 0 else - (incidenceSearch G n (exteriorBonds G Q (W:Set V)) {v}).score p (exteriorBonds G ω (W:Set V)) - -theorem exteriorSearchScore_tail (G : BondGraph V E) (n : ℕ) (hn : 0 < n) - (Q : Finset E) (x v : V) (p : unitInterval) (a : ℝ) (ha : 0 < a) : - bernoulliPolynomial Q (fun ω => if a ≤ |exteriorSearchScore G n Q x v p ω| then 1 else 0) p ≤ - 2*Real.exp (-2*a^2/(n:ℝ)) := by - apply cluster_exterior_expectation_bound G Q x p - (fun W η => if a ≤ |if v ∈ W then 0 else - (incidenceSearch G n (exteriorBonds G Q (W:Set V)) {v}).score p η| then 1 else 0) - intro W - by_cases hv : v ∈ W - · simp only [ite_eq_left hv,abs_zero,ite_eq_right (not_le.mpr ha),bernoulliPolynomial_zero] - positivity - · simp only [ite_eq_right hv] - exact incidenceSearch_score_tail G n hn _ _ p a ha.le - -end ExteriorExplorationLaw -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ClosedClusterContacts -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def contactBonds (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : Finset E := - Q.filter (fun e => ∃ a ∈ A, ∃ b ∈ B, G e = s(a,b)) - -theorem incident_exterior_subset (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : - incidentBonds G (exteriorBonds G Q (A:Set V)) B ⊆ incidentBonds G Q B := by - intro e he - obtain ⟨he,b,hb,hbe⟩ := (mem_incidentBonds G _ B e).mp he - exact (mem_incidentBonds G Q B e).mpr ⟨(Finset.mem_filter.mp he).1,b,hb,hbe⟩ - - - -theorem incident_exterior_difference (G : BondGraph V E) (Q : Finset E) (A B : Finset V) - (hAB : Disjoint A B) : - incidentBonds G Q B \ incidentBonds G (exteriorBonds G Q (A:Set V)) B = - contactBonds G Q A B := by - ext e - simp only [Finset.mem_sdiff,mem_incidentBonds,contactBonds,Finset.mem_filter] - constructor - · rintro ⟨⟨he,b,hb,hbe⟩,hn⟩ - obtain ⟨a,hea⟩ := Sym2.mem_iff_exists.mp hbe - have hbA : b ∉ A := fun hh => Finset.disjoint_left.mp hAB hh hb - have ha : a ∈ A := by - by_contra ha - apply hn - refine ⟨Finset.mem_filter.mpr ⟨he,?_⟩,b,hb,hbe⟩ - exact (mem_internalEdges_of_ends G (A:Set V)ᶜ e b a hea).mpr ⟨hbA,ha⟩ - exact ⟨he,a,ha,b,hb,hea.trans (Sym2.eq_swap ..)⟩ - · rintro ⟨he,a,ha,b,hb,hab⟩ - refine ⟨⟨he,b,hb,by rw [hab]; simp⟩,?_⟩ - rintro ⟨he',_⟩ - exact (Finset.mem_filter.mp he').2 a (by rw [hab]; simp) ha - -theorem finiteRootComponent_disjoint (G : BondGraph V E) (ω : Finset E) (x v : V) - (h : ¬Conn G (ω:Set E) x v) : - Disjoint (finiteRootComponent G ω x) (finiteRootComponent G ω v) := by - apply Finset.disjoint_left.mpr - intro z hz hz' - have h₁ : Conn G (ω:Set E) x z := by - change z ∈ (finiteRootComponent G ω x:Set V) at hz - rwa [coe_finiteRootComponent] at hz - have h₂ : Conn G (ω:Set E) v z := by - change z ∈ (finiteRootComponent G ω v:Set V) at hz' - rwa [coe_finiteRootComponent] at hz' - exact h (h₁.trans (conn_symm G _ h₂)) - -theorem distinct_contact_closed (G : BondGraph V E) (Q ω : Finset E) (x v : V) - (h : ¬Conn G (ω:Set E) x v) {e : E} - (he : e ∈ contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)) : e ∉ ω := by - obtain ⟨_,a,ha,b,hb,hab⟩ := Finset.mem_filter.mp he - have h₁ : Conn G (ω:Set E) x a := by - change a ∈ (finiteRootComponent G ω x:Set V) at ha - rwa [coe_finiteRootComponent] at ha - have h₂ : Conn G (ω:Set E) v b := by - change b ∈ (finiteRootComponent G ω v:Set V) at hb - rwa [coe_finiteRootComponent] at hb - intro heω - exact h ((h₁.tail ⟨e,heω,hab⟩).trans (conn_symm G _ h₂)) - -theorem finiteRootComponent_exterior (G : BondGraph V E) (ω : Finset E) (x v : V) - (h : ¬Conn G (ω:Set E) x v) : - finiteRootComponent G (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) v = - finiteRootComponent G ω v := by - apply Finset.coe_injective - simp only [coe_finiteRootComponent,coe_exteriorBonds] - ext z - exact conn_exterior_of_cluster_eq G ω x v z (cluster G ω x) rfl h - -end ClosedClusterContacts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ExplorationScoreDifference -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem incidence_exterior_score_difference (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) - (hω : ω ⊆ Q) (x v : V) (p : ℝ) (h : ¬Conn G (ω:Set E) x v) - (hn : (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ n) : - (incidenceSearch G n Q {v}).score p ω - exteriorSearchScore G n Q x v p ω = - -p*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := by - let A := finiteRootComponent G ω x - let B := finiteRootComponent G ω v - let R := exteriorBonds G Q (A:Set V) - let η := exteriorBonds G ω (A:Set V) - have hv : v ∉ A := by - intro hv - apply h - change v ∈ (A:Set V) at hv - simpa only [A,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hv - have hη : η ⊆ R := by - intro e he - obtain ⟨he,heA⟩ := Finset.mem_filter.mp he - exact Finset.mem_filter.mpr ⟨hω he,heA⟩ - have hB : finiteRootComponent G η v = B := finiteRootComponent_exterior G ω x v h - have hsub : incidentBonds G R B ⊆ incidentBonds G Q B := incident_exterior_subset G Q A B - have hn' : (incidentBonds G R (finiteRootComponent G η v)).card ≤ n := by - rw [hB] - exact (Finset.card_le_card hsub).trans hn - have hs₁ := incidenceSearch_completed_score G n Q ω hω v p hn - have hs₂ := incidenceSearch_completed_score G n R η hη v p hn' - rw [hB] at hs₂ - have hb (e : E) (he : e ∈ incidentBonds G R B) : (e ∈ η ↔ e ∈ ω) := by - have heR := ((mem_incidentBonds G R B e).mp he).1 - change e ∈ exteriorBonds G ω (A:Set V) ↔ e ∈ ω - simp only [exteriorBonds,Finset.mem_filter] - exact and_iff_left (Finset.mem_filter.mp heR).2 - have hs₂' : (incidenceSearch G n R {v}).score p η = - ∑ e ∈ incidentBonds G R B, ((if e ∈ ω then 1 else 0)-p) := by - rw [hs₂] - exact Finset.sum_congr rfl (fun e he => by simp only [hb e he]) - change (incidenceSearch G n Q {v}).score p ω - - (if v ∈ A then 0 else (incidenceSearch G n R {v}).score p η) = _ - rw [ite_eq_right hv,hs₁,hs₂',←Finset.sum_sdiff hsub,add_sub_cancel_right] - change (∑ e ∈ incidentBonds G Q B \ incidentBonds G (exteriorBonds G Q (A:Set V)) B, - ((if e ∈ ω then (1:ℝ) else 0)-p)) = _ - rw [incident_exterior_difference G Q A B (finiteRootComponent_disjoint G ω x v h)] - have hc (e : E) (he : e ∈ contactBonds G Q A B) : e ∉ ω := distinct_contact_closed G Q ω x v h he - rw [show (∑ e ∈ contactBonds G Q A B, ((if e ∈ ω then (1:ℝ) else 0)-p)) = - ∑ _e ∈ contactBonds G Q A B, -p from Finset.sum_congr rfl (fun e he => by rw [ite_eq_right (hc e he)]; ring)] - simp only [Finset.sum_const,nsmul_eq_mul] - ring - -end ExplorationScoreDifference -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ContactConcentration -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem contactBonds_comm (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : - contactBonds G Q A B = contactBonds G Q B A := by - ext e - simp only [contactBonds,Finset.mem_filter] - constructor <;> rintro ⟨he,a,ha,b,hb,hab⟩ - · exact ⟨he,b,hb,a,ha,hab.trans (Sym2.eq_swap ..)⟩ - · exact ⟨he,b,hb,a,ha,hab.trans (Sym2.eq_swap ..)⟩ - - - -theorem ordered_cluster_contact_tail (G : BondGraph V E) (Q : Finset E) - (x v : V) (p : unitInterval) (N : ℕ) (hN : 0 < N) (a : ℝ) (ha : 0 < a) : - bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ - (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ N ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) - (finiteRootComponent G ω v)).card then 1 else 0) p ≤ - 4*Real.exp (-2*a^2/(N:ℝ)) := by - calc - _ ≤ bernoulliPolynomial Q (fun ω => - (if a ≤ |(incidenceSearch G N Q {v}).score p ω| then 1 else 0)+ - (if a ≤ |exteriorSearchScore G N Q x v p ω| then 1 else 0)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω hω - by_cases h : ¬Conn G (ω:Set E) x v ∧ - (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ N ∧ - 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) - (finiteRootComponent G ω v)).card - · have hd := incidence_exterior_score_difference G N Q ω hω x v p h.1 h.2.1 - have huo : a ≤ |(incidenceSearch G N Q {v}).score p ω| ∨ - a ≤ |exteriorSearchScore G N Q x v p ω| := by - by_contra hh - push Not at hh - have h₁ := (abs_lt.mp hh.1).1 - have h₂ := (abs_lt.mp hh.2).2 - nlinarith [h.2.2] - simp only [ite_eq_left h] - rcases huo with huo | huo <;> simp only [ite_eq_left huo] <;> split_ifs <;> norm_num - · simp only [ite_eq_right h]; split_ifs <;> norm_num - _ = bernoulliPolynomial Q (fun ω => - if a ≤ |(incidenceSearch G N Q {v}).score p ω| then 1 else 0) p+ - bernoulliPolynomial Q (fun ω => - if a ≤ |exteriorSearchScore G N Q x v p ω| then 1 else 0) p := - bernoulliPolynomial_add _ _ _ _ - _ ≤ 2*Real.exp (-2*a^2/(N:ℝ))+2*Real.exp (-2*a^2/(N:ℝ)) := - add_le_add (incidenceSearch_score_tail G N hN Q {v} p a ha.le) - (exteriorSearchScore_tail G N hN Q x v p a ha) - _ = _ := by ring - -end ContactConcentration -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.FractionalMoments + +namespace OAI + +/-! Tail Bounds for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterTailDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteClusterTail_derivative_bound (G : BondGraph V E) (Q : Finset E) (x : V) + (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) (α C : ℝ) + (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) (hsmall : C*(h:ℝ)^α ≤ 1/4) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law p)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law p) ≤ C) : + finiteClusterTail G Q x n p ≤ 8*C*(h:ℝ)^α*deriv (finiteClusterTail G Q x n) p := by + have hmark := (markedConnection_le_cluster_power G Q x h p α hα hα1 (hfin x) (hI x)).trans + (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg h.2.1 α)) + rw [mul_comm ((h:ℝ)^α) C] at hmark + have hlow := finiteSeed_covariance_lower G Q x n p h hn (C*(h:ℝ)^α) hmark + have hupp := finiteSeed_covariance_upper G Q x p h α C hα hα1 hfin hI hC + (finiteClusterTailIndicator G x n) (finiteClusterTailIndicator_mono G x n) + have hF := finiteClusterTail_nonneg G Q x n p + have hd := finiteClusterTail_deriv_nonneg G Q x n p + have hp : (p:ℝ)*(1-(p:ℝ)) ≤ 1 := by nlinarith [p.2.1,p.2.2] + have hprod := mul_le_mul_of_nonneg_right hp hd + have hR : 0 ≤ 2*C*(h:ℝ)^α := mul_nonneg (by positivity) (Real.rpow_nonneg h.2.1 α) + have hh := mul_le_mul_of_nonneg_left hprod hR + have ha := le_abs_self (finiteCovariance Q p (finiteClusterTailIndicator G x n) + (fun ω => finiteSeedProbability G (insert x (searchVertices G Q)) ω x h)) + have hs := mul_le_mul_of_nonneg_right hsmall hF + change |_| ≤ _*deriv (finiteClusterTail G Q x n) p at hupp + nlinarith + +theorem exponential_transfer_of_deriv_lower (H : ℝ → ℝ) (a b K : ℝ) + (hH : Differentiable ℝ H) (hab : a ≤ b) + (hb : ∀ t ∈ Set.Icc a b, K*H t ≤ deriv H t) : + H a ≤ Real.exp (-K*(b-a))*H b := by + let F (t : ℝ) := Real.exp (-K*(t-a))*H t + have hF (t : ℝ) : HasDerivAt F (Real.exp (-K*(t-a))*(deriv H t-K*H t)) t := by + have he := (((hasDerivAt_id t).sub_const a).const_mul (-K)).exp + convert! he.mul (hH t).hasDerivAt using 1 + simp only [id_eq] + ring + have hmono : MonotoneOn F (Set.Icc a b) := by + apply monotoneOn_of_deriv_nonneg (convex_Icc a b) + (fun t _ => (hF t).continuousAt.continuousWithinAt) + (fun t _ => (hF t).differentiableAt.differentiableWithinAt) + intro t ht + rw [(hF t).deriv] + exact mul_nonneg (Real.exp_pos _).le (sub_nonneg.mpr (hb t (interior_subset ht))) + have hh := hmono ⟨le_rfl,hab⟩ ⟨hab,le_rfl⟩ hab + simpa only [F,sub_self,mul_zero,Real.exp_zero,one_mul] using hh + +end ClusterTailDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteStretchedTail +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cluster_finite_ae_mono [Countable E] (G : BondGraph V E) + (x : V) (p q : unitInterval) (hpq : p ≤ q) + (hq : ∀ᵐ ω ∂law q, (cluster G ω x).Finite) : + ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by + have hlabels : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), + (cluster G (openEdges labels q) x).Finite := by + apply ae_of_ae_map (μ := (labelLaw : Measure (E → unitInterval))) + (p := fun ω : Set E => (cluster G ω x).Finite) (measurable_openEdges q).aemeasurable + rwa [map_openEdges] + rw [←map_openEdges p] + apply (ae_map_iff (measurable_openEdges p).aemeasurable + (by simpa only [Set.compl_ofPred,Set.not_infinite] using (measurableSet_infinite_cluster G x).compl)).mpr + filter_upwards [hlabels] with labels hl + exact hl.subset (fun y h => conn_mono G (openEdges_mono labels hpq) h) + +theorem finiteClusterTail_le_markedConnection (G : BondGraph V E) (Q : Finset E) + (x : V) (n : ℕ) (p h : unitInterval) (hn : 1 ≤ (h:ℝ)*n) : + finiteClusterTail G Q x n p ≤ 2*markedConnectionPolynomial G Q x h p := by + have hh : (1:ℝ)/2*finiteClusterTail G Q x n p ≤ markedConnectionPolynomial G Q x h p := by + rw [finiteClusterTail,←bernoulliPolynomial_const_mul,markedConnection_component_polynomial] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + unfold finiteClusterTailIndicator + by_cases hs : n ≤ (finiteRootComponent G ω x).card + · simp only [ite_eq_left hs,mul_one] + apply one_sub_pow_one_sub_ge_half + exact hn.trans (mul_le_mul_of_nonneg_left (by exact_mod_cast hs) h.2.1) + · simp only [ite_eq_right hs,mul_zero] + apply sub_nonneg.mpr + exact pow_le_one₀ (sub_nonneg.mpr h.2.2) (by linarith [h.2.1]) + linarith + + + +theorem finiteClusterTail_stretched [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (x : V) (n : ℕ) (p q h : unitInterval) (hpq : p ≤ q) + (hh : 0 < (h:ℝ)) (hn : 1 ≤ (h:ℝ)*n) (α C : ℝ) + (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) (hsmall : C*(h:ℝ)^α ≤ 1/4) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : + finiteClusterTail G Q x n p ≤ + Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*C*(h:ℝ)^α) := by + have hden : 0 < 8*C*(h:ℝ)^α := by positivity + have hexp := exponential_transfer_of_deriv_lower (finiteClusterTail G Q x n) p q + (1/(8*C*(h:ℝ)^α)) (fun t => (hasDerivAt_bernoulliPolynomial Q _ t).differentiableAt) hpq + have hder : ∀ t ∈ Set.Icc (p:ℝ) (q:ℝ), + (1/(8*C*(h:ℝ)^α))*finiteClusterTail G Q x n t ≤ deriv (finiteClusterTail G Q x n) t := by + intro t ht + let r : unitInterval := ⟨t,⟨p.2.1.trans ht.1,ht.2.trans q.2.2⟩⟩ + have hrq : r ≤ q := ht.2 + have hmoment (y : V) := cluster_power_mono_integral G hloc y r q hrq α hα (hfin y) (hI y) + have he := finiteClusterTail_derivative_bound G Q x n r h hn α C hα hα1 hC0 hsmall + (fun y => cluster_finite_ae_mono G y r q hrq (hfin y)) (fun y => (hmoment y).1) + (fun y => (hmoment y).2.trans (hC y)) + rw [one_div,mul_comm,←div_eq_mul_inv] + apply (div_le_iff₀ hden).mpr + simpa only [mul_comm (deriv (finiteClusterTail G Q x n) t)] using he + have he := hexp hder + have hb := (finiteClusterTail_le_markedConnection G Q x n q h hn).trans + (mul_le_mul_of_nonneg_left ((markedConnection_le_cluster_power G Q x h q α hα hα1 (hfin x) (hI x)).trans + (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg hh.le α))) (by norm_num : (0:ℝ) ≤ 2)) + have hm := mul_le_mul_of_nonneg_left hb (Real.exp_pos (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))).le + have heq : -(1/(8*C*(h:ℝ)^α))*((q:ℝ)-(p:ℝ)) = -((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α) := by ring + rw [heq] at he + have hb' : Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*((h:ℝ)^α*C)) = + Real.exp (-((q:ℝ)-(p:ℝ))/(8*C*(h:ℝ)^α))*(2*C*(h:ℝ)^α) := by ring + exact he.trans (hm.trans_eq hb') + +end FiniteStretchedTail +end Percolation + + +namespace Percolation +open MeasureTheory Filter +section ExponentialPowerBound + + + +theorem exists_exp_neg_le_rpow (r : ℝ) (hr : 0 ≤ r) : + ∃ K : ℝ, 0 < K ∧ ∀ t : ℝ, 0 < t → Real.exp (-t) ≤ K*t^(-r) := by + obtain ⟨m,hm⟩ := exists_nat_ge r + let K : ℝ := m.factorial + have hK1 : 1 ≤ K := by + dsimp [K] + exact_mod_cast (Nat.succ_le_of_lt (Nat.factorial_pos m)) + refine ⟨K,by linarith,?_⟩ + intro t ht + rw [Real.rpow_neg ht.le,←div_eq_mul_inv] + apply (le_div_iff₀ (Real.rpow_pos_of_pos ht r)).mpr + by_cases ht1 : t ≤ 1 + · have hp := Real.rpow_le_one ht.le ht1 hr + have he : Real.exp (-t) ≤ 1 := by rw [Real.exp_le_one_iff]; linarith + exact (mul_le_of_le_one_left (Real.rpow_nonneg ht.le r) he).trans (hp.trans hK1) + · have hpow : t^r ≤ t^m := by + simpa only [Real.rpow_natCast] using Real.rpow_le_rpow_of_exponent_le (le_of_not_ge ht1) hm + have hTaylor : t^m ≤ K*Real.exp t := by + have hh := Real.pow_div_factorial_le_exp t ht.le m + exact (div_le_iff₀ (show (0:ℝ) < (m.factorial:ℝ) by positivity)).mp hh |>.trans_eq (mul_comm _ _) + calc + _ ≤ Real.exp (-t)*(K*Real.exp t) := + mul_le_mul_of_nonneg_left (hpow.trans hTaylor) (Real.exp_pos _).le + _ = K := by rw [Real.exp_neg]; field_simp + +end ExponentialPowerBound +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section PolynomialTails +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem exp_stretched_power_bound (r K δ C z : ℝ) (hδ : 0 < δ) (hC : 0 < C) + (hz : 0 < z) (hK : ∀ t : ℝ, 0 < t → Real.exp (-t) ≤ K*t^(-r)) : + Real.exp (-δ/(8*C*z))*(2*C*z) ≤ + (2*C*K*(8*C)^r)*δ^(-r)*z^(1+r) := by + have he := mul_le_mul_of_nonneg_right (hK (δ/(8*C*z)) (by positivity)) + (by positivity : 0 ≤ 2*C*z) + have hid : (δ/(8*C*z))^(-r)*(2*C*z) = + (2*C*(8*C)^r)*δ^(-r)*z^(1+r) := by + rw [Real.div_rpow hδ.le (by positivity),Real.mul_rpow (by positivity : 0 ≤ 8*C) hz.le, + Real.rpow_neg (by positivity : 0 ≤ 8*C),Real.rpow_neg hz.le, + Real.rpow_add hz,Real.rpow_one] + field_simp + calc + _ ≤ K*(δ/(8*C*z))^(-r)*(2*C*z) := by simpa only [neg_div] using he + _ = K*((δ/(8*C*z))^(-r)*(2*C*z)) := by ring + _ = _ := by rw [hid]; ring + + + +theorem finiteClusterTail_polynomial_large [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (q : unitInterval) (α C r : ℝ) (hα : 0 ≤ α) (hα1 : α ≤ 1) (hC0 : 0 < C) + (hr : 0 ≤ r) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : + ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E) (x : V) (p : unitInterval), p < q → + ∀ n : ℕ, 1 ≤ n → C*(n:ℝ)^(-α) ≤ 1/4 → + finiteClusterTail G Q x n p ≤ A*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-α*(1+r)) := by + obtain ⟨K,hK,hKb⟩ := exists_exp_neg_le_rpow r hr + refine ⟨2*C*K*(8*C)^r,by positivity,?_⟩ + intro Q x p hp n hn hsmall + have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) + let h : unitInterval := ⟨1/(n:ℝ),⟨by positivity,by apply (div_le_one hn0).mpr; exact_mod_cast hn⟩⟩ + have hh : 0 < (h:ℝ) := by dsimp [h]; positivity + have hhpow : (h:ℝ)^α = (n:ℝ)^(-α) := by + dsimp [h] + rw [one_div,Real.inv_rpow hn0.le,Real.rpow_neg hn0.le] + have hhprod : 1 ≤ (h:ℝ)*n := by dsimp [h]; rw [one_div,inv_mul_cancel₀ hn0.ne'] + have hst := finiteClusterTail_stretched G hloc Q x n p q h hp.le hh hhprod α C hα hα1 hC0 + (by rwa [hhpow]) hfin hI hC + have he := exp_stretched_power_bound r K ((q:ℝ)-(p:ℝ)) C ((h:ℝ)^α) + (sub_pos.mpr hp) hC0 (Real.rpow_pos_of_pos hh α) hKb + apply hst.trans + convert! he using 1 + rw [hhpow,←Real.rpow_mul hn0.le] + +end PolynomialTails +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section UniformPolynomialTails +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteClusterTail_le_one (G : BondGraph V E) (Q : Finset E) (x : V) + (n : ℕ) (p : unitInterval) : finiteClusterTail G Q x n p ≤ 1 := by + rw [finiteClusterTail,←bernoulliPolynomial_const Q 1 p] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + unfold finiteClusterTailIndicator + split_ifs <;> norm_num + + + +theorem finiteClusterTail_polynomial [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (q : unitInterval) (α C r : ℝ) (hα : 0 < α) (hα1 : α ≤ 1) (hC0 : 0 < C) + (hr : 0 ≤ r) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : + ∃ A : ℝ, 0 < A ∧ ∀ (Q : Finset E) (x : V) (p : unitInterval), p < q → + ∀ n : ℕ, 1 ≤ n → + finiteClusterTail G Q x n p ≤ A*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-α*(1+r)) := by + obtain ⟨A,hA,hbig⟩ := finiteClusterTail_polynomial_large G hloc q α C r hα.le hα1 hC0 hr hfin hI hC + have ht : Tendsto (fun n : ℕ => C*(n:ℝ)^(-α)) atTop (nhds 0) := by + simpa only [mul_zero,Function.comp_apply] using tendsto_const_nhds.mul + ((tendsto_rpow_neg_atTop hα).comp tendsto_natCast_atTop_atTop) + obtain ⟨N,hN⟩ := eventually_atTop.mp (ht.eventually (gt_mem_nhds (by norm_num : (0:ℝ) < 1/4))) + let s := α*(1+r) + have hs : 0 ≤ s := by dsimp [s]; positivity + let B : ℝ := ((N+1:ℕ):ℝ)^s+A + have hB : 0 < B := by dsimp [B]; positivity + refine ⟨B,hB,?_⟩ + intro Q x p hp n hn + have hn0 : (0:ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hδ : 0 < (q:ℝ)-(p:ℝ) := sub_pos.mpr hp + have hhead : 1 ≤ ((q:ℝ)-(p:ℝ))^(-r) := + Real.one_le_rpow_of_pos_of_le_one_of_nonpos hδ (by linarith [p.2.1,q.2.2]) (by linarith) + by_cases hnN : N ≤ n + · apply (hbig Q x p hp n hn (hN n hnN).le).trans + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right + (by dsimp [B]; linarith [Real.rpow_nonneg (Nat.cast_nonneg (N+1)) s]) (Real.rpow_nonneg hδ.le _)) (Real.rpow_nonneg hn0.le _) + · have hnB : (n:ℝ)^s ≤ B := by + apply (Real.rpow_le_rpow hn0.le (show (n:ℝ) ≤ ((N+1:ℕ):ℝ) by exact_mod_cast (by omega : n ≤ N+1)) hs).trans + dsimp [B] + linarith + have hBδ : B ≤ B*((q:ℝ)-(p:ℝ))^(-r) := by nlinarith + have hbound : 1 ≤ B*((q:ℝ)-(p:ℝ))^(-r)*(n:ℝ)^(-s) := by + rw [Real.rpow_neg hn0.le,←div_eq_mul_inv] + exact (one_le_div (Real.rpow_pos_of_pos hn0 s)).mpr (hnB.trans hBδ) + exact (finiteClusterTail_le_one G Q x n p).trans (by simpa only [s,neg_mul] using hbound) + +end UniformPolynomialTails +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section TailSummation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem natCast_eq_sum_tail (k M : ℕ) (hk : k ≤ M) : + (k:ℝ) = ∑ i ∈ Finset.range M, if i+1 ≤ k then (1:ℝ) else 0 := by + rw [Finset.sum_boole] + congr 1 + have hh : (Finset.range M).filter (fun i => i+1 ≤ k) = Finset.range k := by + ext i + simp only [Finset.mem_filter,Finset.mem_range] + omega + rw [hh,Finset.card_range] + +theorem finiteClusterSize_eq_sum_tail (G : BondGraph V E) (Q : Finset E) (x : V) (p : ℝ) : + bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p = + ∑ n ∈ Finset.range (insert x (searchVertices G Q)).card, finiteClusterTail G Q x (n+1) p := by + simp only [finiteClusterTail] + rw [←bernoulliPolynomial_sum] + apply bernoulliPolynomial_congr + intro ω hω + exact natCast_eq_sum_tail _ _ (Finset.card_le_card (finiteRootComponent_subset G Q _ x ω hω (by rfl))) + +theorem summable_shifted_rpow (s : ℝ) (hs : 1 < s) : + Summable (fun n : ℕ => ((n+1:ℕ):ℝ)^(-s)) := by + exact (summable_nat_add_iff 1).mpr (Real.summable_nat_rpow.mpr (by linarith)) + + +theorem finiteClusterSize_bound_of_tail (G : BondGraph V E) (Q : Finset E) (x : V) + (p : unitInterval) (A s : ℝ) (hA : 0 ≤ A) (hs : 1 < s) + (hf : ∀ n : ℕ, 1 ≤ n → finiteClusterTail G Q x n p ≤ A*(n:ℝ)^(-s)) : + bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p ≤ + A*(∑' n : ℕ, ((n+1:ℕ):ℝ)^(-s)) := by + rw [finiteClusterSize_eq_sum_tail,←tsum_mul_left] + have hsumm := (summable_shifted_rpow s hs).mul_left A + apply (Finset.sum_le_sum (fun n _ => hf (n+1) (by omega))).trans + exact hsumm.sum_le_tsum _ (fun n _ => mul_nonneg hA (Real.rpow_nonneg (Nat.cast_nonneg _) _)) + +end TailSummation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section SusceptibilityExhaustion +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_connection_row_le_size (G : BondGraph V E) (Q : Finset E) + (x : V) (K : Finset V) (p : unitInterval) : + (∑ y ∈ K, bernoulliPolynomial Q (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) ≤ + bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p := by + rw [←bernoulliPolynomial_sum] + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + rw [Finset.sum_boole] + apply Nat.cast_le.mpr + apply Finset.card_le_card + intro y hy + change y ∈ (finiteRootComponent G ω x : Set V) + rw [coe_finiteRootComponent] + exact (Finset.mem_filter.mp hy).2 + + + +theorem susceptibility_bound_of_finite_size [Countable E] (G : BondGraph V E) + (x : V) (p : unitInterval) (B : ℝ) + (hB : ∀ Q : Finset E, bernoulliPolynomial Q (fun ω => ((finiteRootComponent G ω x).card:ℝ)) p ≤ B) : + Summable (twoPoint G p x) ∧ susceptibility G p x ≤ B := by + let : Encodable E := Encodable.ofCountable E + let Q := vertexExhaustion (V := E) + have hrow (K : Finset V) : (∑ y ∈ K, twoPoint G p x y) ≤ B := by + have ht (y : V) : Tendsto (fun n => bernoulliPolynomial (Q n) + (fun ω => if Conn G ω x y then (1:ℝ) else 0) p) atTop (nhds (twoPoint G p x y)) := by + have hc (e : E) (_ : e ∈ (Set.univ : Set E)) : ∃ n, e ∈ Q n := by + obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e} : Finset E) + exact ⟨n,hn (by simp)⟩ + simpa only [Set.inter_univ,twoPoint,Measure.real] using! finite_connection_polynomial_tendsto G Set.univ Q + vertexExhaustion_mono (fun _ => Set.subset_univ _) hc p x y + apply le_of_tendsto (tendsto_finsetSum K (fun y _ => ht y)) + exact Filter.Eventually.of_forall (fun n => (finite_connection_row_le_size G (Q n) x K p).trans (hB (Q n))) + exact ⟨summable_of_sum_le (twoPoint_nonneg G p x) hrow, + Real.tsum_le_of_sum_le (twoPoint_nonneg G p x) hrow⟩ + +end SusceptibilityExhaustion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section SusceptibilityPowerFromMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem susceptibility_power_of_uniform_moment [Countable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (q : unitInterval) (α C r : ℝ) (hα : 0 < α) (hα1 : α ≤ 1) (hC0 : 0 < C) + (hr : 0 ≤ r) (hs : 1 < α*(1+r)) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hI : ∀ y, Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q)) + (hC : ∀ y, (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) : + ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < q → ∀ x, + Summable (twoPoint G p x) ∧ susceptibility G p x ≤ D*((q:ℝ)-(p:ℝ))^(-r) := by + obtain ⟨A,hA,hbound⟩ := finiteClusterTail_polynomial G hloc q α C r hα hα1 hC0 hr hfin hI hC + let S := ∑' n : ℕ, ((n+1:ℕ):ℝ)^(-(α*(1+r))) + have hS : 0 ≤ S := tsum_nonneg (fun _ => Real.rpow_nonneg (Nat.cast_nonneg _) _) + refine ⟨1+A*S,by positivity,?_⟩ + intro p hp x + have hδ : 0 < (q:ℝ)-(p:ℝ) := sub_pos.mpr (show (p:ℝ)<(q:ℝ) from hp) + apply susceptibility_bound_of_finite_size + intro Q + have hh := finiteClusterSize_bound_of_tail G Q x p (A*((q:ℝ)-(p:ℝ))^(-r)) (α*(1+r)) + (mul_nonneg hA.le (Real.rpow_nonneg hδ.le _)) hs (by + intro n hn + simpa only [neg_mul] using hbound Q x p hp n hn) + calc + _ ≤ (A*((q:ℝ)-(p:ℝ))^(-r))*S := hh + _ = (A*S)*((q:ℝ)-(p:ℝ))^(-r) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (by linarith) (Real.rpow_nonneg hδ.le _) + + + +theorem almost_linear_susceptibility_of_moments [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) + (hfin : ∀ y, ∀ᵐ ω ∂law q, (cluster G ω y).Finite) + (hmom : ∀ α : ℝ, 0 < α → α < 1/2 → ∃ C : ℝ, 0 < C ∧ ∀ y, + Integrable (fun ω => ((cluster G ω y).ncard:ℝ)^α) (law q) ∧ + (∫ ω, ((cluster G ω y).ncard:ℝ)^α ∂law q) ≤ C) + (η : ℝ) (hη : 0 < η) : + ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < q → ∀ x, + Summable (twoPoint G p x) ∧ susceptibility G p x ≤ D*((q:ℝ)-(p:ℝ))^(-1-η) := by + let α : ℝ := 1/(2+η/2) + have hden : 0 < 2+η/2 := by linarith + have hα : 0 < α := one_div_pos.mpr hden + have hαhalf : α < 1/2 := by + apply (div_lt_div_iff₀ hden (by norm_num : (0:ℝ) < 2)).mpr + linarith + have hs : 1 < α*(1+(1+η)) := by + dsimp [α] + rw [one_div,mul_comm,←div_eq_mul_inv] + apply (one_lt_div hden).mpr + linarith + obtain ⟨C,hC,hm⟩ := hmom α hα hαhalf + obtain ⟨D,hD,hbound⟩ := susceptibility_power_of_uniform_moment G hloc q α C (1+η) hα + (by linarith) hC (by linarith) hs hfin (fun y => (hm y).1) (fun y => (hm y).2) + refine ⟨D,hD,?_⟩ + intro p hp x + simpa only [neg_add_rev,sub_eq_add_neg,add_comm] using hbound p hp x + +end SusceptibilityPowerFromMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section SourceAlmostLinear +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cluster_finite_ae_covariant [Countable E] (G : BondGraph V E) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : + ∀ᵐ ω ∂law p, (cluster G ω (a x)).Finite := by + have hh : ∀ᵐ ω ∂law p, (cluster G (b ⁻¹' ω) x).Finite := by + apply ae_of_ae_map (μ := law p) (p := fun ω : Set E => (cluster G ω x).Finite) + (measurable_set_preimage b).aemeasurable + rwa [law_map_preimage_equiv] + filter_upwards [hh] with ω hω + rw [←cluster_aut G hab ω x] + exact hω.image a + + + +theorem almost_linear_susceptibility + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (η : ℝ) (hη : 0 < η) : + ∃ D : ℝ, 0 < D ∧ ∀ (p : unitInterval), p < pc G → ∀ x, + susceptibility G p x ≤ D*((pc G:ℝ)-(p:ℝ))^(-1-η) := by + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by + intro x + obtain ⟨i,a,b,hab,rfl⟩ := hcover x + exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) + have hmom (α : ℝ) (hα : 0 < α) (hα1 : α < 1/2) := + uniform_cluster_power_of_root G hloc (pc G) root hcover α + (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) + obtain ⟨D,hD,hb⟩ := almost_linear_susceptibility_of_moments G hloc (pc G) hfinite hmom η hη + exact ⟨D,hD,fun p hp x => (hb p hp x).2⟩ + +end SourceAlmostLinear +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section QueryTranscriptLaw +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EdgeQueryTree + +@[reducible] def forget : EdgeQueryTree E → ProbeTree + | .done b => .done b + | .query _ t₀ t₁ => .edge t₀.forget t₁.forget + +noncomputable def leaf (ω : Finset E) : (t : EdgeQueryTree E) → t.forget.Leaf + | .done _ => () + | .query e t₀ t₁ => if e ∈ ω then Sum.inr (t₁.leaf ω) else Sum.inl (t₀.leaf ω) + +theorem leaf_congr (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {ω η : Finset E} (h : ∀ e ∈ Q, e ∈ ω ↔ e ∈ η) : t.leaf ω = t.leaf η := by + induction t generalizing Q with + | done => rfl + | query e t₀ t₁ ih₀ ih₁ => + simp only [leaf,h e ht.1] + split + · rw [ih₁ ht.2.2 (fun a ha => h a (Finset.mem_of_mem_erase ha))] + · rw [ih₀ ht.2.1 (fun a ha => h a (Finset.mem_of_mem_erase ha))] + +theorem leaf_insert (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + {e : E} (he : e ∉ Q) (ω : Finset E) : t.leaf (insert e ω) = t.leaf ω := by + apply leaf_congr t ht + intro a ha + simp [show a ≠ e from fun h => he (h ▸ ha)] + + +theorem leaf_expectation (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : ℝ) (f : t.forget.Leaf → ℝ) : + bernoulliPolynomial Q (fun ω => f (t.leaf ω)) p = + ∑ l, ProbeTree.weight p 0 t.forget l*f l := by + induction t generalizing Q with + | done b => + change bernoulliPolynomial Q (fun _ => f ()) p = ∑ l : Unit, 1*f l + simp [bernoulliPolynomial_const,Finset.sum_singleton] + | query e t₀ t₁ ih₀ ih₁ => + obtain ⟨he,h₀,h₁⟩ := ht + conv_lhs => rw [←Finset.insert_erase he] + rw [bernoulliPolynomial_insert _ e (Finset.notMem_erase e Q)] + have hc : bernoulliPolynomial (Q.erase e) (fun ω => f ((query e t₀ t₁).leaf ω)) p = + bernoulliPolynomial (Q.erase e) (fun ω => f (Sum.inl (t₀.leaf ω))) p := by + apply bernoulliPolynomial_congr + intro ω hω + simp only [leaf,show e ∉ ω from fun h => Finset.notMem_erase e Q (hω h),ite_false] + have ho : bernoulliPolynomial (Q.erase e) (fun ω => f ((query e t₀ t₁).leaf (insert e ω))) p = + bernoulliPolynomial (Q.erase e) (fun ω => f (Sum.inr (t₁.leaf ω))) p := by + apply bernoulliPolynomial_congr + intro ω _ + simp only [leaf,Finset.mem_insert_self,ite_true, + leaf_insert t₁ h₁ (Finset.notMem_erase e Q)] + rw [hc,ho,ih₀ h₀ (fun l => f (Sum.inl l)),ih₁ h₁ (fun l => f (Sum.inr l))] + change _ = ∑ l : t₀.forget.Leaf ⊕ t₁.forget.Leaf, _ + simp only [Fintype.sum_sum_type,ProbeTree.weight,Finset.mul_sum,mul_assoc] + +noncomputable def score (p : ℝ) (t : EdgeQueryTree E) (ω : Finset E) : ℝ := + ProbeTree.score p t.forget (t.leaf ω) + +noncomputable def queryCount (t : EdgeQueryTree E) (ω : Finset E) : ℕ := + ProbeTree.queries t.forget (t.leaf ω) + + +theorem score_mgf (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (lam : ℝ) : + bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p ≤ 1 := by + change bernoulliPolynomial Q (fun ω => Real.exp (lam*ProbeTree.score p t.forget (t.leaf ω)- + lam^2*(ProbeTree.queries t.forget (t.leaf ω):ℝ)/8)) p ≤ 1 + rw [leaf_expectation t ht p (fun l => Real.exp (lam*ProbeTree.score p t.forget l- + lam^2*(ProbeTree.queries t.forget l:ℝ)/8))] + exact ProbeTree.score_mgf p 0 lam t.forget + +end EdgeQueryTree +end QueryTranscriptLaw +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section CappedQueryConcentration +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EdgeQueryTree + + + +theorem capped_score_mgf (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (lam : ℝ) (N : ℕ) (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : + bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω)) p ≤ Real.exp (lam^2*(N:ℝ)/8) := by + calc + _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (lam^2*(N:ℝ)/8)* + Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω hω + rw [←Real.exp_add] + apply Real.exp_le_exp.mpr + have hn : (t.queryCount ω:ℝ) ≤ (N:ℝ) := Nat.cast_le.mpr (hN ω hω) + nlinarith [sq_nonneg lam] + _ = Real.exp (lam^2*(N:ℝ)/8)*bernoulliPolynomial Q + (fun ω => Real.exp (lam*t.score p ω-lam^2*(t.queryCount ω:ℝ)/8)) p := + bernoulliPolynomial_const_mul _ _ _ _ + _ ≤ _ := by simpa using mul_le_mul_of_nonneg_left (t.score_mgf ht p lam) (Real.exp_pos _).le + +theorem capped_score_chernoff (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (lam a : ℝ) (hlam : 0 ≤ lam) (N : ℕ) + (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : + bernoulliPolynomial Q (fun ω => if a ≤ t.score p ω then 1 else 0) p ≤ + Real.exp (-lam*a+lam^2*(N:ℝ)/8) := by + calc + _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (-lam*a)*Real.exp (lam*t.score p ω)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + split_ifs with h + · rw [←Real.exp_add] + exact Real.one_le_exp (by nlinarith) + · positivity + _ = Real.exp (-lam*a)*bernoulliPolynomial Q (fun ω => Real.exp (lam*t.score p ω)) p := + bernoulliPolynomial_const_mul _ _ _ _ + _ ≤ Real.exp (-lam*a)*Real.exp (lam^2*(N:ℝ)/8) := + mul_le_mul_of_nonneg_left (t.capped_score_mgf ht p lam N hN) (Real.exp_pos _).le + _ = _ := (Real.exp_add _ _).symm + +theorem capped_neg_score_chernoff (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (lam a : ℝ) (hlam : 0 ≤ lam) (N : ℕ) + (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : + bernoulliPolynomial Q (fun ω => if a ≤ -t.score p ω then 1 else 0) p ≤ + Real.exp (-lam*a+lam^2*(N:ℝ)/8) := by + calc + _ ≤ bernoulliPolynomial Q (fun ω => Real.exp (-lam*a)*Real.exp ((-lam)*t.score p ω)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + split_ifs with h + · rw [←Real.exp_add] + exact Real.one_le_exp (by nlinarith) + · positivity + _ = Real.exp (-lam*a)*bernoulliPolynomial Q (fun ω => Real.exp ((-lam)*t.score p ω)) p := + bernoulliPolynomial_const_mul _ _ _ _ + _ ≤ Real.exp (-lam*a)*Real.exp ((-lam)^2*(N:ℝ)/8) := + mul_le_mul_of_nonneg_left (t.capped_score_mgf ht p (-lam) N hN) (Real.exp_pos _).le + _ = _ := by rw [←Real.exp_add]; congr 1; ring + + + +theorem capped_score_tail (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (a : ℝ) (ha : 0 ≤ a) (N : ℕ) (hN0 : 0 < N) + (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : + bernoulliPolynomial Q (fun ω => if a ≤ |t.score p ω| then 1 else 0) p ≤ + 2*Real.exp (-2*a^2/(N:ℝ)) := by + let lam : ℝ := 4*a/(N:ℝ) + have hNr : 0 < (N:ℝ) := Nat.cast_pos.mpr hN0 + have hlam : 0 ≤ lam := div_nonneg (by positivity) hNr.le + have he : -lam*a+lam^2*(N:ℝ)/8 = -2*a^2/(N:ℝ) := by + dsimp [lam] + field_simp + ring + calc + _ ≤ bernoulliPolynomial Q (fun ω => (if a ≤ t.score p ω then 1 else 0)+ + (if a ≤ -t.score p ω then 1 else 0)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω _ + by_cases h : a ≤ |t.score p ω| + · rcases le_abs.mp h with h₁ | h₂ + · simp only [ite_eq_left h,ite_eq_left h₁]; split_ifs <;> norm_num + · simp only [ite_eq_left h,ite_eq_left h₂]; split_ifs <;> norm_num + · simp only [ite_eq_right h]; split_ifs <;> norm_num + _ = bernoulliPolynomial Q (fun ω => if a ≤ t.score p ω then 1 else 0) p+ + bernoulliPolynomial Q (fun ω => if a ≤ -t.score p ω then 1 else 0) p := + bernoulliPolynomial_add _ _ _ _ + _ ≤ Real.exp (-lam*a+lam^2*(N:ℝ)/8)+Real.exp (-lam*a+lam^2*(N:ℝ)/8) := + add_le_add (t.capped_score_chernoff ht p lam a hlam N hN) + (t.capped_neg_score_chernoff ht p lam a hlam N hN) + _ = _ := by rw [he]; ring + +end EdgeQueryTree +end CappedQueryConcentration +end Percolation + + +namespace Percolation +universe v +variable {E : Type v} +section QueryScoreSets +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EdgeQueryTree + +noncomputable def readSet (t : EdgeQueryTree E) (Q ω : Finset E) : Finset E := + Q.filter (fun e => t.reads ω e) + +@[simp] theorem mem_readSet (t : EdgeQueryTree E) (Q ω : Finset E) (e : E) : + e ∈ t.readSet Q ω ↔ e ∈ Q ∧ t.reads ω e := Finset.mem_filter + +theorem readSet_query (e : E) (t₀ t₁ : EdgeQueryTree E) {Q : Finset E} + (ht : (query e t₀ t₁).Valid Q) (ω : Finset E) : + (query e t₀ t₁).readSet Q ω = insert e + (if e ∈ ω then t₁.readSet (Q.erase e) ω else t₀.readSet (Q.erase e) ω) := by + ext i + by_cases hie : i = e + · subst i + simp only [mem_readSet,reads,true_or,and_true,Finset.mem_insert_self,iff_true] + exact ht.1 + · by_cases heω : e ∈ ω <;> simp [mem_readSet,reads,hie,heω] + +theorem score_query (e : E) (t₀ t₁ : EdgeQueryTree E) (ω : Finset E) (p : ℝ) : + (query e t₀ t₁).score p ω = + (if e ∈ ω then t₁.score p ω else t₀.score p ω)+(if e ∈ ω then 1 else 0)-p := by + by_cases h : e ∈ ω + · simp only [score,leaf,ite_eq_left h,ProbeTree.score]; ring + · simp only [score,leaf,ite_eq_right h,ProbeTree.score]; ring + +theorem queryCount_query (e : E) (t₀ t₁ : EdgeQueryTree E) (ω : Finset E) : + (query e t₀ t₁).queryCount ω = + (if e ∈ ω then t₁.queryCount ω else t₀.queryCount ω)+1 := by + by_cases h : e ∈ ω <;> simp [queryCount,leaf,h,ProbeTree.queries] + +theorem queryCount_eq_card (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (ω : Finset E) : t.queryCount ω = (t.readSet Q ω).card := by + induction t generalizing Q with + | done b => + have hs : (done b : EdgeQueryTree E).readSet Q ω = ∅ := by + ext e + simp only [mem_readSet,reads,and_false,Finset.notMem_empty] + rw [hs] + rfl + | query e t₀ t₁ ih₀ ih₁ => + rw [queryCount_query,readSet_query _ _ _ ht] + have h₀ : e ∉ t₀.readSet (Q.erase e) ω := by simp [readSet] + have h₁ : e ∉ t₁.readSet (Q.erase e) ω := by simp [readSet] + by_cases heω : e ∈ ω + · simp only [ite_eq_left heω,Finset.card_insert_of_notMem h₁,ih₁ ht.2.2] + · simp only [ite_eq_right heω,Finset.card_insert_of_notMem h₀,ih₀ ht.2.1] + + +theorem score_eq_sum (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (ω : Finset E) (p : ℝ) : + t.score p ω = ∑ e ∈ t.readSet Q ω, ((if e ∈ ω then 1 else 0)-p) := by + induction t generalizing Q with + | done b => + have hs : (done b : EdgeQueryTree E).readSet Q ω = ∅ := by + ext e + simp only [mem_readSet,reads,and_false,Finset.notMem_empty] + rw [hs,Finset.sum_empty] + rfl + | query e t₀ t₁ ih₀ ih₁ => + rw [score_query,readSet_query _ _ _ ht] + have h₀ : e ∉ t₀.readSet (Q.erase e) ω := by simp [readSet] + have h₁ : e ∉ t₁.readSet (Q.erase e) ω := by simp [readSet] + by_cases heω : e ∈ ω + · simp only [ite_eq_left heω,Finset.sum_insert h₁,ih₁ ht.2.2]; ring + · simp only [ite_eq_right heω,Finset.sum_insert h₀,ih₀ ht.2.1]; ring + +end EdgeQueryTree +end QueryScoreSets +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IncidenceExploration +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def IncidencePending (G : BondGraph V E) (Q : Finset E) (R : Finset V) : Prop := + ∃ t : E × V × V, t.1 ∈ Q ∧ t.2.1 ∈ R ∧ G t.1 = s(t.2.1,t.2.2) + +noncomputable def incidencePick (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (h : IncidencePending G Q R) : E × V × V := Classical.choose h + +theorem incidencePick_spec (G : BondGraph V E) (Q : Finset E) (R : Finset V) + (h : IncidencePending G Q R) : + (incidencePick G Q R h).1 ∈ Q ∧ (incidencePick G Q R h).2.1 ∈ R ∧ + G (incidencePick G Q R h).1 = s((incidencePick G Q R h).2.1,(incidencePick G Q R h).2.2) := + Classical.choose_spec h + +noncomputable def incidenceSearch (G : BondGraph V E) : + ℕ → Finset E → Finset V → EdgeQueryTree E + | 0, _, _ => .done false + | n+1, Q, R => + if hc : IncidencePending G Q R then + let t := incidencePick G Q R hc + .query t.1 (incidenceSearch G n (Q.erase t.1) R) + (incidenceSearch G n (Q.erase t.1) (insert t.2.2 R)) + else .done false + +theorem incidenceSearch_valid (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) : + (incidenceSearch G n Q R).Valid Q := by + induction n generalizing Q R with + | zero => trivial + | succ n ih => + simp only [incidenceSearch] + split_ifs with hc + · exact ⟨(incidencePick_spec G Q R hc).1,ih _ _,ih _ _⟩ + · trivial + +theorem incidenceSearch_cap (G : BondGraph V E) (n : ℕ) (Q : Finset E) (R : Finset V) + (ω : Finset E) : (incidenceSearch G n Q R).queryCount ω ≤ n := by + induction n generalizing Q R with + | zero => exact le_rfl + | succ n ih => + simp only [incidenceSearch] + split_ifs + · rw [EdgeQueryTree.queryCount_query] + split <;> exact Nat.add_le_add_right (ih _ _) 1 + · exact Nat.zero_le _ + + + +structure IncidenceInvariant (G : BondGraph V E) (Q ω : Finset E) (R C : Finset V) : Prop where + discovered : R ⊆ C + closed : ∀ a ∈ C, ∀ e ∈ ω, ∀ b, G e = s(a,b) → b ∈ C + reachable : ∀ y ∈ C, ∃ r ∈ R, Conn G ((ω ∩ Q : Finset E):Set E) r y + +theorem incidentBonds_erase (G : BondGraph V E) (Q : Finset E) (C : Finset V) (e : E) : + incidentBonds G (Q.erase e) C = (incidentBonds G Q C).erase e := by + ext f + simp only [mem_incidentBonds,Finset.mem_erase] + tauto + +theorem incidencePending_of_mem (G : BondGraph V E) {Q : Finset E} {R : Finset V} + {e : E} (h : e ∈ incidentBonds G Q R) : IncidencePending G Q R := by + obtain ⟨he,a,ha,hae⟩ := (mem_incidentBonds G Q R e).mp h + obtain ⟨b,hab⟩ := Sym2.mem_iff_exists.mp hae + exact ⟨(e,a,b),he,ha,hab⟩ + +end IncidenceExploration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IncidenceInvariantSteps +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace IncidenceInvariant + +theorem closed_step {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} + (h : IncidenceInvariant G Q ω R C) (e : E) (he : e ∉ ω) : + IncidenceInvariant G (Q.erase e) ω R C := by + refine ⟨h.discovered,h.closed,?_⟩ + have heq : ω ∩ Q.erase e = ω ∩ Q := by ext f; simp only [Finset.mem_inter,Finset.mem_erase]; grind + simpa only [heq] using h.reachable + +theorem open_step {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} + (h : IncidenceInvariant G Q ω R C) {e : E} (heQ : e ∈ Q) (heω : e ∈ ω) + {a b : V} (ha : a ∈ R) (hab : G e = s(a,b)) : + IncidenceInvariant G (Q.erase e) ω (insert b R) C := by + have hb : b ∈ C := h.closed a (h.discovered ha) e heω b hab + refine ⟨Finset.insert_subset hb h.discovered,h.closed,?_⟩ + have heq : ((ω ∩ Q : Finset E):Set E) = insert e ((ω ∩ Q.erase e : Finset E):Set E) := by + ext f + simp only [Finset.mem_coe,Finset.mem_inter,Finset.mem_erase,Set.mem_insert_iff] + grind + intro y hy + obtain ⟨r,hr,hry⟩ := h.reachable y hy + rw [heq] at hry + rcases (conn_insert_iff G _ e a b r y hab).mp hry with h₀ | h₁ | h₁ + · exact ⟨r,Finset.mem_insert_of_mem hr,h₀⟩ + · exact ⟨b,Finset.mem_insert_self _ _,h₁.2⟩ + · exact ⟨a,Finset.mem_insert_of_mem ha,h₁.2⟩ + +theorem no_pending {G : BondGraph V E} {Q ω : Finset E} {R C : Finset V} + (h : IncidenceInvariant G Q ω R C) (hp : ¬ IncidencePending G Q R) : + incidentBonds G Q C = ∅ := by + have hCR : C ⊆ R := by + intro y hy + obtain ⟨r,hr,hry⟩ := h.reachable y hy + clear hy + induction hry with + | refl => exact hr + | @tail a b _ hab ih => + obtain ⟨e,he,heab⟩ := hab + exact (hp ⟨(e,a,b),(Finset.mem_inter.mp he).2,ih,heab⟩).elim + apply Finset.eq_empty_iff_forall_notMem.mpr + intro e he + apply hp + apply incidencePending_of_mem G (e := e) + obtain ⟨heQ,a,ha,hae⟩ := (mem_incidentBonds G Q C e).mp he + exact (mem_incidentBonds G Q R e).mpr ⟨heQ,a,hCR ha,hae⟩ + +end IncidenceInvariant +end IncidenceInvariantSteps +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IncidenceCompletion +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem incidenceSearch_readSet (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) (R C : Finset V) + (hinv : IncidenceInvariant G Q ω R C) (hn : (incidentBonds G Q C).card ≤ n) : + (incidenceSearch G n Q R).readSet Q ω = incidentBonds G Q C := by + induction n generalizing Q R with + | zero => + have he : incidentBonds G Q C = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hn) + simp [incidenceSearch,EdgeQueryTree.readSet,EdgeQueryTree.reads,he] + | succ n ih => + simp only [incidenceSearch] + split_ifs with hc + · obtain ⟨he,ha,hab⟩ := incidencePick_spec G Q R hc + have heC : (incidencePick G Q R hc).1 ∈ incidentBonds G Q C := + (mem_incidentBonds G Q C _).mpr ⟨he,_,hinv.discovered ha,by rw [hab]; simp⟩ + have hn' : (incidentBonds G (Q.erase (incidencePick G Q R hc).1) C).card ≤ n := by + rw [incidentBonds_erase,Finset.card_erase_of_mem heC] + have hh := Finset.card_pos.mpr ⟨_,heC⟩ + omega + rw [EdgeQueryTree.readSet_query _ _ _ ⟨he,incidenceSearch_valid ..,incidenceSearch_valid ..⟩] + by_cases heω : (incidencePick G Q R hc).1 ∈ ω + · rw [ite_eq_left heω,ih _ _ (hinv.open_step he heω ha hab) hn',incidentBonds_erase, + Finset.insert_erase heC] + · rw [ite_eq_right heω,ih _ _ (hinv.closed_step _ heω) hn',incidentBonds_erase, + Finset.insert_erase heC] + · rw [hinv.no_pending hc] + ext e + simp only [EdgeQueryTree.mem_readSet,EdgeQueryTree.reads, + Finset.notMem_empty,and_false] + +theorem incidenceInvariant_root (G : BondGraph V E) (Q ω : Finset E) (hω : ω ⊆ Q) (x : V) : + IncidenceInvariant G Q ω {x} (finiteRootComponent G ω x) := by + have hmem (y : V) : y ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x y := by + change y ∈ ((finiteRootComponent G ω x:Set V)) ↔ _ + rw [coe_finiteRootComponent] + rfl + refine ⟨?_,?_,?_⟩ + · intro y hy + rw [Finset.mem_singleton] at hy + subst y + exact (hmem x).mpr (conn_refl G _ _) + · intro a ha e he b hab + exact (hmem b).mpr ((hmem a).mp ha |>.tail ⟨e,he,hab⟩) + · intro y hy + refine ⟨x,Finset.mem_singleton_self _,?_⟩ + rw [Finset.inter_eq_left.mpr hω] + exact (hmem y).mp hy + + + +theorem incidenceSearch_completed_score (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) + (hω : ω ⊆ Q) (x : V) (p : ℝ) + (hn : (incidentBonds G Q (finiteRootComponent G ω x)).card ≤ n) : + (incidenceSearch G n Q {x}).score p ω = + ∑ e ∈ incidentBonds G Q (finiteRootComponent G ω x), ((if e ∈ ω then 1 else 0)-p) := by + rw [EdgeQueryTree.score_eq_sum _ (incidenceSearch_valid ..), + incidenceSearch_readSet G n Q ω {x} _ (incidenceInvariant_root G Q ω hω x) hn] + +theorem incidenceSearch_score_tail (G : BondGraph V E) (n : ℕ) (hn : 0 < n) + (Q : Finset E) (R : Finset V) (p : unitInterval) (a : ℝ) (ha : 0 ≤ a) : + bernoulliPolynomial Q (fun ω => if a ≤ |(incidenceSearch G n Q R).score p ω| then 1 else 0) p ≤ + 2*Real.exp (-2*a^2/(n:ℝ)) := + EdgeQueryTree.capped_score_tail _ (incidenceSearch_valid ..) p a ha n hn + (fun ω _ => incidenceSearch_cap G n Q R ω) + +end IncidenceCompletion +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExteriorExplorationLaw +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem cluster_exterior_expectation_bound (G : BondGraph V E) (Q : Finset E) + (x : V) (p : unitInterval) (f : Finset V → Finset E → ℝ) (K : ℝ) + (hf : ∀ W : Finset V, bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ K) : + bernoulliPolynomial Q (fun ω => f (finiteRootComponent G ω x) + (exteriorBonds G ω (finiteRootComponent G ω x:Set V))) p ≤ K := by + let F := insert x (searchVertices G Q) + have hpoint (ω : Finset E) (hω : ω ⊆ Q) : + f (finiteRootComponent G ω x) (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) = + ∑ W ∈ F.powerset, (if cluster G ω x = (W:Set V) then (1:ℝ) else 0)* + f W (exteriorBonds G ω (W:Set V)) := by + rw [←sum_component_partition G Q F x ω hω (by rfl) + (fun W => f W (exteriorBonds G ω (W:Set V)))] + apply Finset.sum_congr rfl + intro W _ + split_ifs <;> simp + rw [bernoulliPolynomial_congr Q hpoint,bernoulliPolynomial_sum] + calc + _ = ∑ W ∈ F.powerset, + bernoulliPolynomial Q (fun ω => if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p* + bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p := by + apply Finset.sum_congr rfl + intro W _ + rw [cluster_cell_exterior_factor,←cluster_cell_incident_probability G Q x (W:Set V) p] + _ ≤ ∑ W ∈ F.powerset, + bernoulliPolynomial Q (fun ω => if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p*K := by + apply Finset.sum_le_sum + intro W _ + apply mul_le_mul_of_nonneg_left (hf W) + exact bernoulliPolynomial_nonneg _ _ p p.2 (fun _ _ => by split_ifs <;> norm_num) + _ = K := by + rw [←Finset.sum_mul,←bernoulliPolynomial_sum] + have hh : bernoulliPolynomial Q (fun ω => ∑ W ∈ F.powerset, + if cluster G ω x = (W:Set V) then (1:ℝ) else 0) p = 1 := by + trans bernoulliPolynomial Q (fun _ => (1:ℝ)) p + · apply bernoulliPolynomial_congr + intro ω hω + exact sum_component_partition G Q F x ω hω (by rfl) (fun _ => 1) + · exact bernoulliPolynomial_const Q 1 p + rw [hh,one_mul] + +noncomputable def exteriorSearchScore (G : BondGraph V E) (n : ℕ) (Q : Finset E) + (x v : V) (p : ℝ) (ω : Finset E) : ℝ := + let W := finiteRootComponent G ω x + if v ∈ W then 0 else + (incidenceSearch G n (exteriorBonds G Q (W:Set V)) {v}).score p (exteriorBonds G ω (W:Set V)) + +theorem exteriorSearchScore_tail (G : BondGraph V E) (n : ℕ) (hn : 0 < n) + (Q : Finset E) (x v : V) (p : unitInterval) (a : ℝ) (ha : 0 < a) : + bernoulliPolynomial Q (fun ω => if a ≤ |exteriorSearchScore G n Q x v p ω| then 1 else 0) p ≤ + 2*Real.exp (-2*a^2/(n:ℝ)) := by + apply cluster_exterior_expectation_bound G Q x p + (fun W η => if a ≤ |if v ∈ W then 0 else + (incidenceSearch G n (exteriorBonds G Q (W:Set V)) {v}).score p η| then 1 else 0) + intro W + by_cases hv : v ∈ W + · simp only [ite_eq_left hv,abs_zero,ite_eq_right (not_le.mpr ha),bernoulliPolynomial_zero] + positivity + · simp only [ite_eq_right hv] + exact incidenceSearch_score_tail G n hn _ _ p a ha.le + +end ExteriorExplorationLaw +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ClosedClusterContacts +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def contactBonds (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : Finset E := + Q.filter (fun e => ∃ a ∈ A, ∃ b ∈ B, G e = s(a,b)) + +theorem incident_exterior_subset (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : + incidentBonds G (exteriorBonds G Q (A:Set V)) B ⊆ incidentBonds G Q B := by + intro e he + obtain ⟨he,b,hb,hbe⟩ := (mem_incidentBonds G _ B e).mp he + exact (mem_incidentBonds G Q B e).mpr ⟨(Finset.mem_filter.mp he).1,b,hb,hbe⟩ + + + +theorem incident_exterior_difference (G : BondGraph V E) (Q : Finset E) (A B : Finset V) + (hAB : Disjoint A B) : + incidentBonds G Q B \ incidentBonds G (exteriorBonds G Q (A:Set V)) B = + contactBonds G Q A B := by + ext e + simp only [Finset.mem_sdiff,mem_incidentBonds,contactBonds,Finset.mem_filter] + constructor + · rintro ⟨⟨he,b,hb,hbe⟩,hn⟩ + obtain ⟨a,hea⟩ := Sym2.mem_iff_exists.mp hbe + have hbA : b ∉ A := fun hh => Finset.disjoint_left.mp hAB hh hb + have ha : a ∈ A := by + by_contra ha + apply hn + refine ⟨Finset.mem_filter.mpr ⟨he,?_⟩,b,hb,hbe⟩ + exact (mem_internalEdges_of_ends G (A:Set V)ᶜ e b a hea).mpr ⟨hbA,ha⟩ + exact ⟨he,a,ha,b,hb,hea.trans (Sym2.eq_swap ..)⟩ + · rintro ⟨he,a,ha,b,hb,hab⟩ + refine ⟨⟨he,b,hb,by rw [hab]; simp⟩,?_⟩ + rintro ⟨he',_⟩ + exact (Finset.mem_filter.mp he').2 a (by rw [hab]; simp) ha + +theorem finiteRootComponent_disjoint (G : BondGraph V E) (ω : Finset E) (x v : V) + (h : ¬Conn G (ω:Set E) x v) : + Disjoint (finiteRootComponent G ω x) (finiteRootComponent G ω v) := by + apply Finset.disjoint_left.mpr + intro z hz hz' + have h₁ : Conn G (ω:Set E) x z := by + change z ∈ (finiteRootComponent G ω x:Set V) at hz + rwa [coe_finiteRootComponent] at hz + have h₂ : Conn G (ω:Set E) v z := by + change z ∈ (finiteRootComponent G ω v:Set V) at hz' + rwa [coe_finiteRootComponent] at hz' + exact h (h₁.trans (conn_symm G _ h₂)) + +theorem distinct_contact_closed (G : BondGraph V E) (Q ω : Finset E) (x v : V) + (h : ¬Conn G (ω:Set E) x v) {e : E} + (he : e ∈ contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)) : e ∉ ω := by + obtain ⟨_,a,ha,b,hb,hab⟩ := Finset.mem_filter.mp he + have h₁ : Conn G (ω:Set E) x a := by + change a ∈ (finiteRootComponent G ω x:Set V) at ha + rwa [coe_finiteRootComponent] at ha + have h₂ : Conn G (ω:Set E) v b := by + change b ∈ (finiteRootComponent G ω v:Set V) at hb + rwa [coe_finiteRootComponent] at hb + intro heω + exact h ((h₁.tail ⟨e,heω,hab⟩).trans (conn_symm G _ h₂)) + +theorem finiteRootComponent_exterior (G : BondGraph V E) (ω : Finset E) (x v : V) + (h : ¬Conn G (ω:Set E) x v) : + finiteRootComponent G (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) v = + finiteRootComponent G ω v := by + apply Finset.coe_injective + simp only [coe_finiteRootComponent,coe_exteriorBonds] + ext z + exact conn_exterior_of_cluster_eq G ω x v z (cluster G ω x) rfl h + +end ClosedClusterContacts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ExplorationScoreDifference +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem incidence_exterior_score_difference (G : BondGraph V E) (n : ℕ) (Q ω : Finset E) + (hω : ω ⊆ Q) (x v : V) (p : ℝ) (h : ¬Conn G (ω:Set E) x v) + (hn : (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ n) : + (incidenceSearch G n Q {v}).score p ω - exteriorSearchScore G n Q x v p ω = + -p*(contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω v)).card := by + let A := finiteRootComponent G ω x + let B := finiteRootComponent G ω v + let R := exteriorBonds G Q (A:Set V) + let η := exteriorBonds G ω (A:Set V) + have hv : v ∉ A := by + intro hv + apply h + change v ∈ (A:Set V) at hv + simpa only [A,coe_finiteRootComponent,cluster,Set.mem_ofPred_eq] using hv + have hη : η ⊆ R := by + intro e he + obtain ⟨he,heA⟩ := Finset.mem_filter.mp he + exact Finset.mem_filter.mpr ⟨hω he,heA⟩ + have hB : finiteRootComponent G η v = B := finiteRootComponent_exterior G ω x v h + have hsub : incidentBonds G R B ⊆ incidentBonds G Q B := incident_exterior_subset G Q A B + have hn' : (incidentBonds G R (finiteRootComponent G η v)).card ≤ n := by + rw [hB] + exact (Finset.card_le_card hsub).trans hn + have hs₁ := incidenceSearch_completed_score G n Q ω hω v p hn + have hs₂ := incidenceSearch_completed_score G n R η hη v p hn' + rw [hB] at hs₂ + have hb (e : E) (he : e ∈ incidentBonds G R B) : (e ∈ η ↔ e ∈ ω) := by + have heR := ((mem_incidentBonds G R B e).mp he).1 + change e ∈ exteriorBonds G ω (A:Set V) ↔ e ∈ ω + simp only [exteriorBonds,Finset.mem_filter] + exact and_iff_left (Finset.mem_filter.mp heR).2 + have hs₂' : (incidenceSearch G n R {v}).score p η = + ∑ e ∈ incidentBonds G R B, ((if e ∈ ω then 1 else 0)-p) := by + rw [hs₂] + exact Finset.sum_congr rfl (fun e he => by simp only [hb e he]) + change (incidenceSearch G n Q {v}).score p ω - + (if v ∈ A then 0 else (incidenceSearch G n R {v}).score p η) = _ + rw [ite_eq_right hv,hs₁,hs₂',←Finset.sum_sdiff hsub,add_sub_cancel_right] + change (∑ e ∈ incidentBonds G Q B \ incidentBonds G (exteriorBonds G Q (A:Set V)) B, + ((if e ∈ ω then (1:ℝ) else 0)-p)) = _ + rw [incident_exterior_difference G Q A B (finiteRootComponent_disjoint G ω x v h)] + have hc (e : E) (he : e ∈ contactBonds G Q A B) : e ∉ ω := distinct_contact_closed G Q ω x v h he + rw [show (∑ e ∈ contactBonds G Q A B, ((if e ∈ ω then (1:ℝ) else 0)-p)) = + ∑ _e ∈ contactBonds G Q A B, -p from Finset.sum_congr rfl (fun e he => by rw [ite_eq_right (hc e he)]; ring)] + simp only [Finset.sum_const,nsmul_eq_mul] + ring + +end ExplorationScoreDifference +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ContactConcentration +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem contactBonds_comm (G : BondGraph V E) (Q : Finset E) (A B : Finset V) : + contactBonds G Q A B = contactBonds G Q B A := by + ext e + simp only [contactBonds,Finset.mem_filter] + constructor <;> rintro ⟨he,a,ha,b,hb,hab⟩ + · exact ⟨he,b,hb,a,ha,hab.trans (Sym2.eq_swap ..)⟩ + · exact ⟨he,b,hb,a,ha,hab.trans (Sym2.eq_swap ..)⟩ + + + +theorem ordered_cluster_contact_tail (G : BondGraph V E) (Q : Finset E) + (x v : V) (p : unitInterval) (N : ℕ) (hN : 0 < N) (a : ℝ) (ha : 0 < a) : + bernoulliPolynomial Q (fun ω => if ¬Conn G (ω:Set E) x v ∧ + (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ N ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) + (finiteRootComponent G ω v)).card then 1 else 0) p ≤ + 4*Real.exp (-2*a^2/(N:ℝ)) := by + calc + _ ≤ bernoulliPolynomial Q (fun ω => + (if a ≤ |(incidenceSearch G N Q {v}).score p ω| then 1 else 0)+ + (if a ≤ |exteriorSearchScore G N Q x v p ω| then 1 else 0)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω hω + by_cases h : ¬Conn G (ω:Set E) x v ∧ + (incidentBonds G Q (finiteRootComponent G ω v)).card ≤ N ∧ + 2*a ≤ (p:ℝ)*(contactBonds G Q (finiteRootComponent G ω x) + (finiteRootComponent G ω v)).card + · have hd := incidence_exterior_score_difference G N Q ω hω x v p h.1 h.2.1 + have huo : a ≤ |(incidenceSearch G N Q {v}).score p ω| ∨ + a ≤ |exteriorSearchScore G N Q x v p ω| := by + by_contra hh + push Not at hh + have h₁ := (abs_lt.mp hh.1).1 + have h₂ := (abs_lt.mp hh.2).2 + nlinarith [h.2.2] + simp only [ite_eq_left h] + rcases huo with huo | huo <;> simp only [ite_eq_left huo] <;> split_ifs <;> norm_num + · simp only [ite_eq_right h]; split_ifs <;> norm_num + _ = bernoulliPolynomial Q (fun ω => + if a ≤ |(incidenceSearch G N Q {v}).score p ω| then 1 else 0) p+ + bernoulliPolynomial Q (fun ω => + if a ≤ |exteriorSearchScore G N Q x v p ω| then 1 else 0) p := + bernoulliPolynomial_add _ _ _ _ + _ ≤ 2*Real.exp (-2*a^2/(N:ℝ))+2*Real.exp (-2*a^2/(N:ℝ)) := + add_le_add (incidenceSearch_score_tail G N hN Q {v} p a ha.le) + (exteriorSearchScore_tail G N hN Q x v p a ha) + _ = _ := by ring + +end ContactConcentration +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Graph/Automorphisms.lean b/lean/OAI/Probability/UnimodularPercolation/Graph/Automorphisms.lean index 46cb1ed728f0044a9cce385f1fe7edf4ee541180..cf432cdd3d21687df2843ebbdecfc6a6dd2823a5 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Graph/Automorphisms.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Graph/Automorphisms.lean @@ -1,272 +1,272 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Escape.Labels -import OAI.Probability.UnimodularPercolation.Graph.Topology -import OAI.Probability.UnimodularPercolation.Transport.Haar - -namespace OAI - -/-! Locally compact graph automorphism groups and unimodular root data. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory Topology -open scoped ENNReal -universe u v -variable {V : Type u} {E : Type v} - - -def graphAut (G : BondGraph V E) : Subgroup (Equiv.Perm V) where - carrier := vertexAut G - one_mem' := ⟨Equiv.refl E, isAut_refl G⟩ - mul_mem' := by - rintro a c ⟨b,hb⟩ ⟨d,hd⟩ - exact ⟨d.trans b, isAut_trans G hd hb⟩ - inv_mem' := by - rintro a ⟨b,hb⟩ - exact ⟨b.symm,isAut_symm G hb⟩ - - - -theorem mem_vertexAut_iff (G : BondGraph V E) (hG : Function.Injective G) - (a : Equiv.Perm V) : - a ∈ vertexAut G ↔ ∀ x y, Adj G (a x) (a y) ↔ Adj G x y := by - constructor - · rintro ⟨b,hb⟩ x y - exact ⟨fun h => by simpa using adj_aut G (isAut_symm G hb) h,adj_aut G hb⟩ - · intro ha - have he (s : Sym2 V) : s ∈ Set.range G ↔ s.map a ∈ Set.range G := by - induction s using Sym2.inductionOn with - | _ x y => exact (ha x y).symm - let a₂ : Equiv.Perm (Sym2 V) := - ⟨Sym2.map a,Sym2.map a.symm, - fun s => by simp only [Sym2.map_map,Equiv.symm_comp_self,Sym2.map_id',id_eq], - fun s => by simp only [Sym2.map_map,Equiv.self_comp_symm,Sym2.map_id',id_eq]⟩ - let e : E ≃ Set.range G := Equiv.ofInjective G hG - let b : E ≃ E := (e.trans (a₂.subtypeEquiv he)).trans e.symm - refine ⟨b,?_⟩ - intro z - have hb : e (b z) = a₂.subtypeEquiv he (e z) := by - exact e.apply_symm_apply _ - exact congrArg Subtype.val hb - - - -abbrev graphOrbitType (G : BondGraph V E) := Quotient (MulAction.orbitRel (graphAut G) V) - -instance graphOrbitType_nonempty [Nonempty V] (G : BondGraph V E) : - Nonempty (graphOrbitType G) := ⟨Quotient.mk _ (Classical.arbitrary V)⟩ - -noncomputable def graphOrbitRoot (G : BondGraph V E) : graphOrbitType G → V := Quotient.out - -theorem graphOrbitRoot_cover (G : BondGraph V E) (x : V) : - ∃ i : graphOrbitType G, x ∈ actionOrbit (H := graphAut G) (graphOrbitRoot G i) := by - refine ⟨Quotient.mk _ x,?_⟩ - apply (MulAction.mem_orbit_iff).mp - apply MulAction.orbitRel_apply.mp - apply Quotient.exact - exact (Quotient.out_eq (Quotient.mk (MulAction.orbitRel (graphAut G) V) x)).symm - -theorem graphOrbitRoot_separate (G : BondGraph V E) (i j : graphOrbitType G) - (h : graphOrbitRoot G j ∈ actionOrbit (H := graphAut G) (graphOrbitRoot G i)) : i = j := by - have he : (Quotient.mk _ (graphOrbitRoot G j) : graphOrbitType G) = - Quotient.mk _ (graphOrbitRoot G i) := - Quotient.sound (MulAction.orbitRel_apply.mpr (MulAction.mem_orbit_iff.mpr h)) - simpa only [graphOrbitRoot,Quotient.out_eq] using he.symm - -theorem finite_graphOrbitType (G : BondGraph V E) (hqt : QuasiTransitive G) : - Finite (graphOrbitType G) := by - classical - obtain ⟨R,hR⟩ := hqt - apply Finite.of_surjective (fun r : R => (Quotient.mk _ r.val : graphOrbitType G)) - intro i - induction i using Quotient.inductionOn with - | _ x => - obtain ⟨r,hr,a,b,hab,hax⟩ := hR x - refine ⟨⟨r,hr⟩,?_⟩ - symm - apply Quotient.sound - apply MulAction.orbitRel_apply.mpr - apply MulAction.mem_orbit_iff.mpr - exact ⟨⟨a,⟨b,hab⟩⟩,hax⟩ - -section Topology -variable [TopologicalSpace V] [DiscreteTopology V] - -theorem isClosed_vertexAut (G : BondGraph V E) (hG : Function.Injective G) : - IsClosed (vertexAut G) := by - have h (x y : V) : IsClosed {a : Equiv.Perm V | Adj G (a x) (a y) ↔ Adj G x y} := by - have hf : Continuous (fun a : Equiv.Perm V => (a x,a y)) := - (PointwisePerm.continuous_apply x).prodMk (PointwisePerm.continuous_apply y) - exact (isClosed_discrete {p : V × V | Adj G p.1 p.2 ↔ Adj G x y}).preimage hf - convert isClosed_iInter (fun x => isClosed_iInter (h x)) using 1 - ext a - simp only [Set.mem_iInter,Set.mem_ofPred_eq,mem_vertexAut_iff G hG] - - -theorem isCompact_vertexStabilizer (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (x : V) : - IsCompact {a : Equiv.Perm V | a ∈ vertexAut G ∧ a x = x} := by - apply PointwisePerm.isCompact_of_finite_images _ - ((isClosed_vertexAut G hG).inter (PointwisePerm.isClosed_fixed x x)) - · intro y - obtain ⟨n,hn⟩ := exists_mem_reachBall (hconn x y) - apply (finite_reachBall hloc x n).subset - rintro z ⟨a,⟨⟨b,hb⟩,hx⟩,rfl⟩ - change a x = x at hx - simpa only [hx] using mem_reachBall_aut G hb hn - · intro y - obtain ⟨n,hn⟩ := exists_mem_reachBall (hconn x y) - apply (finite_reachBall hloc x n).subset - rintro z ⟨a,⟨⟨b,hb⟩,hx⟩,rfl⟩ - have hx' : a.symm x = x := by rw [Equiv.symm_apply_eq,hx] - simpa only [hx'] using mem_reachBall_aut G (isAut_symm G hb) hn - - -omit [DiscreteTopology V] in -theorem graphAut_continuous_apply (G : BondGraph V E) (x : V) : - Continuous (fun g : graphAut G => g • x) := - (PointwisePerm.continuous_apply x).comp continuous_subtype_val - -theorem graphAut_isOpen_stabilizer (G : BondGraph V E) (x : V) : - IsOpen (actionStabilizer (H := graphAut G) x) := - (isOpen_discrete ({x} : Set V)).preimage (graphAut_continuous_apply G x) - -theorem graphAut_isCompact_stabilizer (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) (x : V) : - IsCompact (actionStabilizer (H := graphAut G) x) := by - apply Topology.IsEmbedding.subtypeVal.isCompact_iff.mpr - convert isCompact_vertexStabilizer G hG hconn hloc x using 1 - ext a - constructor - · rintro ⟨g,hg,rfl⟩ - exact ⟨g.property,hg⟩ - · rintro ⟨ha,hax⟩ - exact ⟨⟨a,ha⟩,hax,rfl⟩ - - - -theorem graphAut_locallyCompact [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : - LocallyCompactSpace (graphAut G) := by - let x : V := Classical.arbitrary V - have hK := graphAut_isCompact_stabilizer G hG hconn hloc x - have hKo := graphAut_isOpen_stabilizer G x - have hw : WeaklyLocallyCompactSpace (graphAut G) := by - refine ⟨fun g => ?_⟩ - refine ⟨(fun h : graphAut G => g * h) '' actionStabilizer (H := graphAut G) x, - hK.image (continuous_const.mul continuous_id),?_⟩ - have h1 : actionStabilizer (H := graphAut G) x ∈ nhds (1 : graphAut G) := - hKo.mem_nhds (one_smul _ _) - have he := (Homeomorph.mulLeft g).map_nhds_eq (1 : graphAut G) - change Filter.map (fun h : graphAut G => g * h) (nhds 1) = nhds (g * 1) at he - rw [mul_one] at he - rw [←he] - exact Filter.image_mem_map h1 - let := hw - infer_instance - -instance graphAutSecondCountable [Countable V] (G : BondGraph V E) : - SecondCountableTopology (graphAut G) := - Topology.IsEmbedding.subtypeVal.secondCountableTopology - -instance graphAutMeasurableSpace (G : BondGraph V E) : MeasurableSpace (graphAut G) := - borel (graphAut G) - -instance graphAutBorelSpace (G : BondGraph V E) : BorelSpace (graphAut G) := ⟨rfl⟩ - - -noncomputable def graphHaar [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : - Measure (graphAut G) := by - letI := graphAut_locallyCompact G hG hconn hloc - exact Measure.haar - -theorem graphHaar_isHaar [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : - (graphHaar G hG hconn hloc).IsHaarMeasure := by - let := graphAut_locallyCompact G hG hconn hloc - exact inferInstanceAs ((Measure.haar : Measure (graphAut G)).IsHaarMeasure) - -theorem graphHaar_regular [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : - (graphHaar G hG hconn hloc).Regular := by - let := graphAut_locallyCompact G hG hconn hloc - exact inferInstanceAs ((Measure.haar : Measure (graphAut G)).Regular) - - -theorem graphStabilizer_volume_pos (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) - (μ : Measure (graphAut G)) [μ.IsHaarMeasure] (x : V) : - 0 < μ.real (actionStabilizer (H := graphAut G) x) := by - apply ENNReal.toReal_pos - · exact ((graphAut_isOpen_stabilizer G x).measure_pos μ ⟨1,one_smul _ _⟩).ne' - · exact (graphAut_isCompact_stabilizer G hG hconn hloc x).measure_lt_top.ne - -section Countable -variable [Countable V] [MeasurableSpace V] [BorelSpace V] - - - -theorem graphHaar_rootTransport (G : BondGraph V E) (hG : Function.Injective G) - (hconn : Connected G) (hloc : LocallyFinite G) - [Fintype (graphOrbitType G)] [Nonempty V] - (μ : Measure (graphAut G)) [μ.IsHaarMeasure] [μ.IsInvInvariant] : - RootTransport (graphOrbitRoot G) (inverseStabilizerWeight μ (graphOrbitRoot G)) (vertexAut G) := by - apply rootTransport_of_invariant_measure μ - (fun x => (graphAut_continuous_apply G x).measurable) - (graphOrbitRoot G) - (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) - (fun i => (graphAut_isCompact_stabilizer G hG hconn hloc (graphOrbitRoot G i)).measure_lt_top.ne) - (graphOrbitRoot_cover G) (graphOrbitRoot_separate G) (vertexAut G) - intro g - exact g.property - - - -theorem exists_graphHaar_rootData [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) - (μ : Measure (graphAut G)) [μ.IsHaarMeasure] [μ.IsInvInvariant] : - ∃ (ι : Type u) (_ : Fintype ι) (_ : Nonempty ι) (root : ι → V) (weight : ι → ℝ), - RootTransport root weight (vertexAut G) ∧ - (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) ∧ - (∀ i, 0 < weight i) ∧ ∑ i, weight i = 1 := by - let := finite_graphOrbitType G hqt - let := Fintype.ofFinite (graphOrbitType G) - refine ⟨graphOrbitType G,inferInstance,inferInstance,graphOrbitRoot G, - inverseStabilizerWeight μ (graphOrbitRoot G), - graphHaar_rootTransport G hG hconn hloc μ,?_,?_,?_⟩ - · intro x - obtain ⟨i,g,hg⟩ := graphOrbitRoot_cover G x - exact ⟨i,g.val,g.property,hg⟩ - · exact inverseStabilizerWeight_pos μ (graphOrbitRoot G) - (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) - · exact inverseStabilizerWeight_sum μ (graphOrbitRoot G) - (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) - - - -theorem exists_rootData_of_unimodular [Nonempty V] (G : BondGraph V E) - (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) - (huni : (graphHaar G hG hconn hloc).IsMulRightInvariant) : - ∃ (ι : Type u) (_ : Fintype ι) (_ : Nonempty ι) (root : ι → V) (weight : ι → ℝ), - RootTransport root weight (vertexAut G) ∧ - (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) ∧ - (∀ i, 0 < weight i) ∧ ∑ i, weight i = 1 := by - let := graphAut_locallyCompact G hG hconn hloc - let μ := graphHaar G hG hconn hloc - let : μ.IsHaarMeasure := graphHaar_isHaar G hG hconn hloc - let : μ.Regular := graphHaar_regular G hG hconn hloc - let : μ.IsMulRightInvariant := huni - let : μ.IsInvInvariant := haar_invInvariant_of_rightInvariant μ - exact exists_graphHaar_rootData G hG hconn hloc hqt μ - -end Countable - -end Topology -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Escape.Labels +import OAI.Probability.UnimodularPercolation.Graph.Topology +import OAI.Probability.UnimodularPercolation.Transport.Haar + +namespace OAI + +/-! Locally compact graph automorphism groups and unimodular root data. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory Topology +open scoped ENNReal +universe u v +variable {V : Type u} {E : Type v} + + +def graphAut (G : BondGraph V E) : Subgroup (Equiv.Perm V) where + carrier := vertexAut G + one_mem' := ⟨Equiv.refl E, isAut_refl G⟩ + mul_mem' := by + rintro a c ⟨b,hb⟩ ⟨d,hd⟩ + exact ⟨d.trans b, isAut_trans G hd hb⟩ + inv_mem' := by + rintro a ⟨b,hb⟩ + exact ⟨b.symm,isAut_symm G hb⟩ + + + +theorem mem_vertexAut_iff (G : BondGraph V E) (hG : Function.Injective G) + (a : Equiv.Perm V) : + a ∈ vertexAut G ↔ ∀ x y, Adj G (a x) (a y) ↔ Adj G x y := by + constructor + · rintro ⟨b,hb⟩ x y + exact ⟨fun h => by simpa using adj_aut G (isAut_symm G hb) h,adj_aut G hb⟩ + · intro ha + have he (s : Sym2 V) : s ∈ Set.range G ↔ s.map a ∈ Set.range G := by + induction s using Sym2.inductionOn with + | _ x y => exact (ha x y).symm + let a₂ : Equiv.Perm (Sym2 V) := + ⟨Sym2.map a,Sym2.map a.symm, + fun s => by simp only [Sym2.map_map,Equiv.symm_comp_self,Sym2.map_id',id_eq], + fun s => by simp only [Sym2.map_map,Equiv.self_comp_symm,Sym2.map_id',id_eq]⟩ + let e : E ≃ Set.range G := Equiv.ofInjective G hG + let b : E ≃ E := (e.trans (a₂.subtypeEquiv he)).trans e.symm + refine ⟨b,?_⟩ + intro z + have hb : e (b z) = a₂.subtypeEquiv he (e z) := by + exact e.apply_symm_apply _ + exact congrArg Subtype.val hb + + + +abbrev graphOrbitType (G : BondGraph V E) := Quotient (MulAction.orbitRel (graphAut G) V) + +instance graphOrbitType_nonempty [Nonempty V] (G : BondGraph V E) : + Nonempty (graphOrbitType G) := ⟨Quotient.mk _ (Classical.arbitrary V)⟩ + +noncomputable def graphOrbitRoot (G : BondGraph V E) : graphOrbitType G → V := Quotient.out + +theorem graphOrbitRoot_cover (G : BondGraph V E) (x : V) : + ∃ i : graphOrbitType G, x ∈ actionOrbit (H := graphAut G) (graphOrbitRoot G i) := by + refine ⟨Quotient.mk _ x,?_⟩ + apply (MulAction.mem_orbit_iff).mp + apply MulAction.orbitRel_apply.mp + apply Quotient.exact + exact (Quotient.out_eq (Quotient.mk (MulAction.orbitRel (graphAut G) V) x)).symm + +theorem graphOrbitRoot_separate (G : BondGraph V E) (i j : graphOrbitType G) + (h : graphOrbitRoot G j ∈ actionOrbit (H := graphAut G) (graphOrbitRoot G i)) : i = j := by + have he : (Quotient.mk _ (graphOrbitRoot G j) : graphOrbitType G) = + Quotient.mk _ (graphOrbitRoot G i) := + Quotient.sound (MulAction.orbitRel_apply.mpr (MulAction.mem_orbit_iff.mpr h)) + simpa only [graphOrbitRoot,Quotient.out_eq] using he.symm + +theorem finite_graphOrbitType (G : BondGraph V E) (hqt : QuasiTransitive G) : + Finite (graphOrbitType G) := by + classical + obtain ⟨R,hR⟩ := hqt + apply Finite.of_surjective (fun r : R => (Quotient.mk _ r.val : graphOrbitType G)) + intro i + induction i using Quotient.inductionOn with + | _ x => + obtain ⟨r,hr,a,b,hab,hax⟩ := hR x + refine ⟨⟨r,hr⟩,?_⟩ + symm + apply Quotient.sound + apply MulAction.orbitRel_apply.mpr + apply MulAction.mem_orbit_iff.mpr + exact ⟨⟨a,⟨b,hab⟩⟩,hax⟩ + +section Topology +variable [TopologicalSpace V] [DiscreteTopology V] + +theorem isClosed_vertexAut (G : BondGraph V E) (hG : Function.Injective G) : + IsClosed (vertexAut G) := by + have h (x y : V) : IsClosed {a : Equiv.Perm V | Adj G (a x) (a y) ↔ Adj G x y} := by + have hf : Continuous (fun a : Equiv.Perm V => (a x,a y)) := + (PointwisePerm.continuous_apply x).prodMk (PointwisePerm.continuous_apply y) + exact (isClosed_discrete {p : V × V | Adj G p.1 p.2 ↔ Adj G x y}).preimage hf + convert isClosed_iInter (fun x => isClosed_iInter (h x)) using 1 + ext a + simp only [Set.mem_iInter,Set.mem_ofPred_eq,mem_vertexAut_iff G hG] + + +theorem isCompact_vertexStabilizer (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (x : V) : + IsCompact {a : Equiv.Perm V | a ∈ vertexAut G ∧ a x = x} := by + apply PointwisePerm.isCompact_of_finite_images _ + ((isClosed_vertexAut G hG).inter (PointwisePerm.isClosed_fixed x x)) + · intro y + obtain ⟨n,hn⟩ := exists_mem_reachBall (hconn x y) + apply (finite_reachBall hloc x n).subset + rintro z ⟨a,⟨⟨b,hb⟩,hx⟩,rfl⟩ + change a x = x at hx + simpa only [hx] using mem_reachBall_aut G hb hn + · intro y + obtain ⟨n,hn⟩ := exists_mem_reachBall (hconn x y) + apply (finite_reachBall hloc x n).subset + rintro z ⟨a,⟨⟨b,hb⟩,hx⟩,rfl⟩ + have hx' : a.symm x = x := by rw [Equiv.symm_apply_eq,hx] + simpa only [hx'] using mem_reachBall_aut G (isAut_symm G hb) hn + + +omit [DiscreteTopology V] in +theorem graphAut_continuous_apply (G : BondGraph V E) (x : V) : + Continuous (fun g : graphAut G => g • x) := + (PointwisePerm.continuous_apply x).comp continuous_subtype_val + +theorem graphAut_isOpen_stabilizer (G : BondGraph V E) (x : V) : + IsOpen (actionStabilizer (H := graphAut G) x) := + (isOpen_discrete ({x} : Set V)).preimage (graphAut_continuous_apply G x) + +theorem graphAut_isCompact_stabilizer (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) (x : V) : + IsCompact (actionStabilizer (H := graphAut G) x) := by + apply Topology.IsEmbedding.subtypeVal.isCompact_iff.mpr + convert isCompact_vertexStabilizer G hG hconn hloc x using 1 + ext a + constructor + · rintro ⟨g,hg,rfl⟩ + exact ⟨g.property,hg⟩ + · rintro ⟨ha,hax⟩ + exact ⟨⟨a,ha⟩,hax,rfl⟩ + + + +theorem graphAut_locallyCompact [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : + LocallyCompactSpace (graphAut G) := by + let x : V := Classical.arbitrary V + have hK := graphAut_isCompact_stabilizer G hG hconn hloc x + have hKo := graphAut_isOpen_stabilizer G x + have hw : WeaklyLocallyCompactSpace (graphAut G) := by + refine ⟨fun g => ?_⟩ + refine ⟨(fun h : graphAut G => g * h) '' actionStabilizer (H := graphAut G) x, + hK.image (continuous_const.mul continuous_id),?_⟩ + have h1 : actionStabilizer (H := graphAut G) x ∈ nhds (1 : graphAut G) := + hKo.mem_nhds (one_smul _ _) + have he := (Homeomorph.mulLeft g).map_nhds_eq (1 : graphAut G) + change Filter.map (fun h : graphAut G => g * h) (nhds 1) = nhds (g * 1) at he + rw [mul_one] at he + rw [←he] + exact Filter.image_mem_map h1 + let := hw + infer_instance + +instance graphAutSecondCountable [Countable V] (G : BondGraph V E) : + SecondCountableTopology (graphAut G) := + Topology.IsEmbedding.subtypeVal.secondCountableTopology + +instance graphAutMeasurableSpace (G : BondGraph V E) : MeasurableSpace (graphAut G) := + borel (graphAut G) + +instance graphAutBorelSpace (G : BondGraph V E) : BorelSpace (graphAut G) := ⟨rfl⟩ + + +noncomputable def graphHaar [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : + Measure (graphAut G) := by + letI := graphAut_locallyCompact G hG hconn hloc + exact Measure.haar + +theorem graphHaar_isHaar [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : + (graphHaar G hG hconn hloc).IsHaarMeasure := by + let := graphAut_locallyCompact G hG hconn hloc + exact inferInstanceAs ((Measure.haar : Measure (graphAut G)).IsHaarMeasure) + +theorem graphHaar_regular [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) : + (graphHaar G hG hconn hloc).Regular := by + let := graphAut_locallyCompact G hG hconn hloc + exact inferInstanceAs ((Measure.haar : Measure (graphAut G)).Regular) + + +theorem graphStabilizer_volume_pos (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) + (μ : Measure (graphAut G)) [μ.IsHaarMeasure] (x : V) : + 0 < μ.real (actionStabilizer (H := graphAut G) x) := by + apply ENNReal.toReal_pos + · exact ((graphAut_isOpen_stabilizer G x).measure_pos μ ⟨1,one_smul _ _⟩).ne' + · exact (graphAut_isCompact_stabilizer G hG hconn hloc x).measure_lt_top.ne + +section Countable +variable [Countable V] [MeasurableSpace V] [BorelSpace V] + + + +theorem graphHaar_rootTransport (G : BondGraph V E) (hG : Function.Injective G) + (hconn : Connected G) (hloc : LocallyFinite G) + [Fintype (graphOrbitType G)] [Nonempty V] + (μ : Measure (graphAut G)) [μ.IsHaarMeasure] [μ.IsInvInvariant] : + RootTransport (graphOrbitRoot G) (inverseStabilizerWeight μ (graphOrbitRoot G)) (vertexAut G) := by + apply rootTransport_of_invariant_measure μ + (fun x => (graphAut_continuous_apply G x).measurable) + (graphOrbitRoot G) + (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) + (fun i => (graphAut_isCompact_stabilizer G hG hconn hloc (graphOrbitRoot G i)).measure_lt_top.ne) + (graphOrbitRoot_cover G) (graphOrbitRoot_separate G) (vertexAut G) + intro g + exact g.property + + + +theorem exists_graphHaar_rootData [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) + (μ : Measure (graphAut G)) [μ.IsHaarMeasure] [μ.IsInvInvariant] : + ∃ (ι : Type u) (_ : Fintype ι) (_ : Nonempty ι) (root : ι → V) (weight : ι → ℝ), + RootTransport root weight (vertexAut G) ∧ + (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) ∧ + (∀ i, 0 < weight i) ∧ ∑ i, weight i = 1 := by + let := finite_graphOrbitType G hqt + let := Fintype.ofFinite (graphOrbitType G) + refine ⟨graphOrbitType G,inferInstance,inferInstance,graphOrbitRoot G, + inverseStabilizerWeight μ (graphOrbitRoot G), + graphHaar_rootTransport G hG hconn hloc μ,?_,?_,?_⟩ + · intro x + obtain ⟨i,g,hg⟩ := graphOrbitRoot_cover G x + exact ⟨i,g.val,g.property,hg⟩ + · exact inverseStabilizerWeight_pos μ (graphOrbitRoot G) + (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) + · exact inverseStabilizerWeight_sum μ (graphOrbitRoot G) + (fun i => graphStabilizer_volume_pos G hG hconn hloc μ (graphOrbitRoot G i)) + + + +theorem exists_rootData_of_unimodular [Nonempty V] (G : BondGraph V E) + (hG : Function.Injective G) (hconn : Connected G) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) + (huni : (graphHaar G hG hconn hloc).IsMulRightInvariant) : + ∃ (ι : Type u) (_ : Fintype ι) (_ : Nonempty ι) (root : ι → V) (weight : ι → ℝ), + RootTransport root weight (vertexAut G) ∧ + (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) ∧ + (∀ i, 0 < weight i) ∧ ∑ i, weight i = 1 := by + let := graphAut_locallyCompact G hG hconn hloc + let μ := graphHaar G hG hconn hloc + let : μ.IsHaarMeasure := graphHaar_isHaar G hG hconn hloc + let : μ.Regular := graphHaar_regular G hG hconn hloc + let : μ.IsMulRightInvariant := huni + let : μ.IsInvInvariant := haar_invInvariant_of_rightInvariant μ + exact exists_graphHaar_rootData G hG hconn hloc hqt μ + +end Countable + +end Topology +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Graph/Basic.lean b/lean/OAI/Probability/UnimodularPercolation/Graph/Basic.lean index 4b3152b8d6d690fbea4b15a7f93f63b0a0518b3f..179886547fde03a342c523531703285ccd697f5b 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Graph/Basic.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Graph/Basic.lean @@ -1,381 +1,381 @@ -import Mathlib - -namespace OAI - -/-! Indexed bond graphs, connectivity, percolation laws, kernels and countability. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -abbrev BondGraph (V : Type u) (E : Type v) := E → Sym2 V - - -def Adj (G : BondGraph V E) (x y : V) : Prop := ∃ e, G e = s(x, y) - - -def LocallyFinite (G : BondGraph V E) : Prop := ∀ x, {e | x ∈ G e}.Finite - - -def Connected (G : BondGraph V E) : Prop := - ∀ x y, Relation.ReflTransGen (Adj G) x y - - -def IsAut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) : Prop := - ∀ e, G (b e) = (G e).map a - - -def QuasiTransitive (G : BondGraph V E) : Prop := - ∃ representatives : Finset V, ∀ x, ∃ o ∈ representatives, - ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ a o = x - - -def vertexBoundary (G : BondGraph V E) (A : Finset V) : Set V := - {y | y ∉ A ∧ ∃ x ∈ A, Adj G x y} - - -noncomputable def hV (G : BondGraph V E) : ℝ := - sInf {r | ∃ A : Finset V, A.Nonempty ∧ - r = (vertexBoundary G A).ncard / (A.card : ℝ)} - - -def Conn (G : BondGraph V E) (ω : Set E) (x y : V) : Prop := - Relation.ReflTransGen (fun a b => ∃ e ∈ ω, G e = s(a, b)) x y - -def cluster (G : BondGraph V E) (ω : Set E) (x : V) : Set V := - {y | Conn G ω x y} - - -def infiniteClusters (G : BondGraph V E) (ω : Set E) : Set (Set V) := - {C | C.Infinite ∧ ∃ x, C = cluster G ω x} - - -noncomputable def law (p : unitInterval) : Measure (Set E) := - setBernoulli Set.univ p - -noncomputable def pc (G : BondGraph V E) : unitInterval := - sInf {p | 0 < law p {ω | (infiniteClusters G ω).Nonempty}} - -noncomputable def pu (G : BondGraph V E) : unitInterval := - sInf {p | law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 1} - -noncomputable def twoPoint (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := - (law p {ω | Conn G ω x y}).toReal - -noncomputable abbrev Hilbert (V : Type u) := lp (fun _ : V => ℂ) 2 - - -noncomputable def HasKernel [DecidableEq V] - (G : BondGraph V E) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) : Prop := - ∀ x y, (A (lp.single 2 y (1 : ℂ))) x = (twoPoint G p x y : ℂ) - -noncomputable def OperatorBounded (G : BondGraph V E) (p : unitInterval) : Prop := by - classical - exact ∃ A : Hilbert V →L[ℂ] Hilbert V, HasKernel G p A - - -noncomputable def operatorNorm (G : BondGraph V E) (p : unitInterval) : ℝ≥0∞ := by - classical - exact sInf {r | ∃ A : Hilbert V →L[ℂ] Hilbert V, - HasKernel G p A ∧ r = ENNReal.ofReal ‖A‖} - -noncomputable def ptwo (G : BondGraph V E) : unitInterval := - sSup {p | OperatorBounded G p} - - -noncomputable def labelLaw : Measure (E → unitInterval) := - Measure.infinitePi (fun _ => (volume : Measure unitInterval)) - -def openEdges (labels : E → unitInterval) (p : unitInterval) : Set E := - {e | labels e ≤ p} - - -def MainConclusion (G : BondGraph V E) : Prop := - (sSup {r | ∃ p : unitInterval, p < pc G ∧ r = operatorNorm G p} = - operatorNorm G (pc G)) ∧ - operatorNorm G (pc G) < ⊤ ∧ - pc G < ptwo G ∧ ptwo G ≤ pu G ∧ - ∃ p₁ p₂ : unitInterval, pc G < p₁ ∧ p₁ < p₂ ∧ p₂ < 1 ∧ - ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), - ∀ p ∈ Set.Icc p₁ p₂, (infiniteClusters G (openEdges labels p)).Infinite - - - -section Deterministic -variable (G : BondGraph V E) (ω : Set E) - -@[simp] theorem conn_refl (x : V) : Conn G ω x x := - Relation.ReflTransGen.refl - -theorem conn_trans {x y z : V} (hxy : Conn G ω x y) (hyz : Conn G ω y z) : - Conn G ω x z := hxy.trans hyz - -theorem conn_symm {x y : V} (h : Conn G ω x y) : Conn G ω y x := by - induction h with - | refl => exact conn_refl G ω _ - | @tail y z _ hyz ih => - rcases hyz with ⟨e, he, hlink⟩ - exact (Relation.ReflTransGen.single ⟨e, he, hlink.trans (Sym2.eq_swap ..)⟩).trans ih - -theorem conn_mono {ω₁ ω₂ : Set E} (hω : ω₁ ⊆ ω₂) {x y : V} - (h : Conn G ω₁ x y) : Conn G ω₂ x y := by - apply Relation.ReflTransGen.mono (r := fun a b => ∃ e ∈ ω₁, G e = s(a, b)) ?_ x y h - rintro a b ⟨e, he, hab⟩ - exact ⟨e, hω he, hab⟩ - -theorem cluster_eq_of_conn {x y : V} (h : Conn G ω x y) : - cluster G ω x = cluster G ω y := by - ext z - exact ⟨fun hxz => conn_trans G ω (conn_symm G ω h) hxz, - fun hyz => conn_trans G ω h hyz⟩ - -@[simp] theorem mem_cluster_self (x : V) : x ∈ cluster G ω x := conn_refl G ω x - -theorem clusters_eq_or_disjoint (x y : V) : - cluster G ω x = cluster G ω y ∨ Disjoint (cluster G ω x) (cluster G ω y) := by - by_cases h : Conn G ω x y - · exact Or.inl (cluster_eq_of_conn G ω h) - · right - apply Set.disjoint_left.mpr - intro z hxz hyz - exact h (conn_trans G ω hxz (conn_symm G ω hyz)) - -@[simp] theorem conn_empty_iff (x y : V) : Conn G ∅ x y ↔ x = y := by - constructor - · intro h - induction h with - | refl => rfl - | tail _ he _ => rcases he with ⟨e, he, _⟩; exact he.elim - · rintro rfl - exact conn_refl G ∅ _ - -@[simp] theorem cluster_empty (x : V) : cluster G ∅ x = {x} := by - ext y - simp [cluster, eq_comm] - -@[simp] theorem infiniteClusters_empty : infiniteClusters G ∅ = ∅ := by - ext C - simp only [infiniteClusters, Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false, - not_and, not_exists] - intro h x hx - subst C - simp at h - -theorem conn_univ_of_connected (h : Connected G) (x y : V) : Conn G Set.univ x y := by - apply Relation.ReflTransGen.mono (r := Adj G) ?_ x y (h x y) - rintro a b ⟨e, he⟩ - exact ⟨e, Set.mem_univ _, he⟩ - -theorem cluster_univ_of_connected (h : Connected G) (x : V) : - cluster G Set.univ x = Set.univ := by - ext y - simp only [cluster, Set.mem_ofPred_eq, Set.mem_univ, iff_true] - exact conn_univ_of_connected G h x y - -theorem infiniteClusters_univ [Infinite V] (h : Connected G) : - infiniteClusters G Set.univ = {Set.univ} := by - ext C - constructor - · rintro ⟨_, x, rfl⟩ - simp [cluster_univ_of_connected G h] - · intro hC - have hC' : C = Set.univ := Set.mem_singleton_iff.mp hC - subst C - exact ⟨Set.infinite_univ, Classical.arbitrary V, - (cluster_univ_of_connected G h _).symm⟩ - -end Deterministic - -section Probability -variable (G : BondGraph V E) - -instance law_isProbabilityMeasure (p : unitInterval) : - IsProbabilityMeasure (law p : Measure (Set E)) := by - dsimp [law] - infer_instance - -@[simp] theorem law_zero : (law 0 : Measure (Set E)) = Measure.dirac ∅ := by - simp [law] - -@[simp] theorem law_one : (law 1 : Measure (Set E)) = Measure.dirac Set.univ := by - simp [law] - -@[simp] theorem twoPoint_self (p : unitInterval) (x : V) : twoPoint G p x x = 1 := by - simp [twoPoint] - -theorem twoPoint_nonneg (p : unitInterval) (x y : V) : 0 ≤ twoPoint G p x y := - ENNReal.toReal_nonneg - -theorem twoPoint_le_one (p : unitInterval) (x y : V) : twoPoint G p x y ≤ 1 := by - exact ENNReal.toReal_le_of_le_ofReal (by norm_num) (by simpa using - (prob_le_one (μ := law p) (s := {ω | Conn G ω x y}))) - -theorem twoPoint_symm (p : unitInterval) (x y : V) : twoPoint G p x y = twoPoint G p y x := by - have he : {ω | Conn G ω x y} = {ω | Conn G ω y x} := by - ext ω - exact ⟨conn_symm G ω, conn_symm G ω⟩ - simp only [twoPoint, he] - -@[simp] theorem twoPoint_zero [Countable E] [DecidableEq V] (x y : V) : - twoPoint G 0 x y = if x = y then 1 else 0 := by - rw [twoPoint, law_zero, Measure.dirac_apply] - by_cases h : x = y - · simp [h] - · rw [Set.indicator_of_notMem (by simpa using h)] - simp [h] - -theorem twoPoint_one (h : Connected G) (x y : V) : twoPoint G 1 x y = 1 := by - have hv : law (E := E) 1 {ω | Conn G ω x y} = 1 := by - rw [law_one] - exact Measure.dirac_apply_of_mem (conn_univ_of_connected G h x y) - change (law 1 {ω | Conn G ω x y}).toReal = 1 - rw [hv] - norm_num - -end Probability - -section Kernel -attribute [local instance] Classical.propDecidable - - -theorem kernel_extension_unique {K : V → V → ℂ} - {A B : Hilbert V →L[ℂ] Hilbert V} - (hA : ∀ x y, (A (lp.single 2 y (1 : ℂ))) x = K x y) - (hB : ∀ x y, (B (lp.single 2 y (1 : ℂ))) x = K x y) : A = B := by - apply lp.ext_continuousLinearMap (by norm_num : (2 : ℝ≥0∞) ≠ ⊤) - intro y - apply ContinuousLinearMap.ext - intro z - apply lp.ext - funext x - have hz : lp.single (E := fun _ : V => ℂ) 2 y z = - z • lp.single (E := fun _ : V => ℂ) 2 y (1 : ℂ) := by - simpa using (lp.single_smul (E := fun _ : V => ℂ) 2 y z (1 : ℂ)) - simp only [ContinuousLinearMap.coe_comp, Function.comp_apply, - lp.singleContinuousLinearMap_apply, hz, map_smul, lp.coeFn_smul, Pi.smul_apply, - hA, hB] - -theorem HasKernel.unique {G : BondGraph V E} {p : unitInterval} - {A B : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) (hB : HasKernel G p B) : - A = B := kernel_extension_unique hA hB - - -theorem operatorNorm_of_hasKernel {G : BondGraph V E} {p : unitInterval} - {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) : - operatorNorm G p = ENNReal.ofReal ‖A‖ := by - have he : {r | ∃ B : Hilbert V →L[ℂ] Hilbert V, - HasKernel G p B ∧ r = ENNReal.ofReal ‖B‖} = {ENNReal.ofReal ‖A‖} := by - ext r - constructor - · rintro ⟨B, hB, rfl⟩ - rw [hB.unique hA] - exact Set.mem_singleton _ - · intro hr - exact ⟨A, hA, Set.mem_singleton_iff.mp hr⟩ - change sInf _ = _ - rw [he, sInf_singleton] - -theorem operatorNorm_eq_top_iff (G : BondGraph V E) (p : unitInterval) : - operatorNorm G p = ⊤ ↔ ¬ OperatorBounded G p := by - constructor - · intro h ⟨A, hA⟩ - rw [operatorNorm_of_hasKernel hA] at h - exact ENNReal.ofReal_ne_top h - · intro h - unfold operatorNorm - have he : {r | ∃ A : Hilbert V →L[ℂ] Hilbert V, - HasKernel G p A ∧ r = ENNReal.ofReal ‖A‖} = ∅ := by - ext r - simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false] - rintro ⟨A, hA, _⟩ - exact h ⟨A, hA⟩ - rw [he, sInf_empty] - -theorem operatorNorm_lt_top_iff (G : BondGraph V E) (p : unitInterval) : - operatorNorm G p < ⊤ ↔ OperatorBounded G p := by - rw [lt_top_iff_ne_top, ne_eq, operatorNorm_eq_top_iff, not_not] - -theorem hasKernel_zero [Countable E] (G : BondGraph V E) : - HasKernel G 0 (ContinuousLinearMap.id ℂ (Hilbert V)) := by - intro x y - simp only [ContinuousLinearMap.id_apply, lp.single_apply, twoPoint_zero] - by_cases h : x = y - · subst y - simp - · simp [h] - -@[simp] theorem operatorBounded_zero [Countable E] (G : BondGraph V E) : - OperatorBounded G 0 := ⟨_, hasKernel_zero G⟩ - -end Kernel - -section Countability - - -theorem finite_neighbors {G : BondGraph V E} (hG : LocallyFinite G) (x : V) : - {y | Adj G x y}.Finite := by - classical - have hends (e : E) : {y | y ∈ G e}.Finite := by - apply (G e).toFinset.finite_toSet.subset - intro y hy - exact Sym2.mem_toFinset.mpr hy - have hs : (⋃ e ∈ {e | x ∈ G e}, {y | y ∈ G e}).Finite := - (hG x).biUnion (fun e _ => hends e) - apply hs.subset - rintro y ⟨e, he⟩ - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] - exact ⟨e, he ▸ by simp, he ▸ by simp⟩ - - -def reachBall (G : BondGraph V E) (x : V) : ℕ → Set V - | 0 => {x} - | n + 1 => reachBall G x n ∪ ⋃ y ∈ reachBall G x n, {z | Adj G y z} - -theorem finite_reachBall {G : BondGraph V E} (hG : LocallyFinite G) (x : V) : - ∀ n, (reachBall G x n).Finite := by - intro n - induction n with - | zero => exact Set.finite_singleton x - | succ n hn => - exact hn.union (hn.biUnion (fun y _ => finite_neighbors hG y)) - -theorem exists_mem_reachBall {G : BondGraph V E} {x y : V} - (h : Relation.ReflTransGen (Adj G) x y) : ∃ n, y ∈ reachBall G x n := by - induction h with - | refl => exact ⟨0, Set.mem_singleton _⟩ - | @tail y z _ hyz ih => - rcases ih with ⟨n, hn⟩ - refine ⟨n + 1, Or.inr ?_⟩ - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] - exact ⟨y, hn, hyz⟩ - -theorem countable_vertices [Nonempty V] {G : BondGraph V E} - (hG : LocallyFinite G) (hconn : Connected G) : Countable V := by - let x : V := Classical.arbitrary V - have he : (Set.univ : Set V) = ⋃ n, reachBall G x n := by - ext y - simp only [Set.mem_univ, Set.mem_iUnion, true_iff] - exact exists_mem_reachBall (hconn x y) - apply Set.countable_univ_iff.mp - rw [he] - exact Set.countable_iUnion (fun n => (finite_reachBall hG x n).countable) - -theorem countable_edges [Countable V] {G : BondGraph V E} - (hG : LocallyFinite G) : Countable E := by - have he : (Set.univ : Set E) = ⋃ x, {e | x ∈ G e} := by - ext e - simp only [Set.mem_univ, Set.mem_iUnion, Set.mem_ofPred_eq, true_iff] - exact ⟨(G e).out.1, Sym2.out_fst_mem _⟩ - apply Set.countable_univ_iff.mp - rw [he] - exact Set.countable_iUnion (fun x => (hG x).countable) - -end Countability - -end Percolation - -end OAI +import Mathlib + +namespace OAI + +/-! Indexed bond graphs, connectivity, percolation laws, kernels and countability. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +abbrev BondGraph (V : Type u) (E : Type v) := E → Sym2 V + + +def Adj (G : BondGraph V E) (x y : V) : Prop := ∃ e, G e = s(x, y) + + +def LocallyFinite (G : BondGraph V E) : Prop := ∀ x, {e | x ∈ G e}.Finite + + +def Connected (G : BondGraph V E) : Prop := + ∀ x y, Relation.ReflTransGen (Adj G) x y + + +def IsAut (G : BondGraph V E) (a : V ≃ V) (b : E ≃ E) : Prop := + ∀ e, G (b e) = (G e).map a + + +def QuasiTransitive (G : BondGraph V E) : Prop := + ∃ representatives : Finset V, ∀ x, ∃ o ∈ representatives, + ∃ a : V ≃ V, ∃ b : E ≃ E, IsAut G a b ∧ a o = x + + +def vertexBoundary (G : BondGraph V E) (A : Finset V) : Set V := + {y | y ∉ A ∧ ∃ x ∈ A, Adj G x y} + + +noncomputable def hV (G : BondGraph V E) : ℝ := + sInf {r | ∃ A : Finset V, A.Nonempty ∧ + r = (vertexBoundary G A).ncard / (A.card : ℝ)} + + +def Conn (G : BondGraph V E) (ω : Set E) (x y : V) : Prop := + Relation.ReflTransGen (fun a b => ∃ e ∈ ω, G e = s(a, b)) x y + +def cluster (G : BondGraph V E) (ω : Set E) (x : V) : Set V := + {y | Conn G ω x y} + + +def infiniteClusters (G : BondGraph V E) (ω : Set E) : Set (Set V) := + {C | C.Infinite ∧ ∃ x, C = cluster G ω x} + + +noncomputable def law (p : unitInterval) : Measure (Set E) := + setBernoulli Set.univ p + +noncomputable def pc (G : BondGraph V E) : unitInterval := + sInf {p | 0 < law p {ω | (infiniteClusters G ω).Nonempty}} + +noncomputable def pu (G : BondGraph V E) : unitInterval := + sInf {p | law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 1} + +noncomputable def twoPoint (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := + (law p {ω | Conn G ω x y}).toReal + +noncomputable abbrev Hilbert (V : Type u) := lp (fun _ : V => ℂ) 2 + + +noncomputable def HasKernel [DecidableEq V] + (G : BondGraph V E) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) : Prop := + ∀ x y, (A (lp.single 2 y (1 : ℂ))) x = (twoPoint G p x y : ℂ) + +noncomputable def OperatorBounded (G : BondGraph V E) (p : unitInterval) : Prop := by + classical + exact ∃ A : Hilbert V →L[ℂ] Hilbert V, HasKernel G p A + + +noncomputable def operatorNorm (G : BondGraph V E) (p : unitInterval) : ℝ≥0∞ := by + classical + exact sInf {r | ∃ A : Hilbert V →L[ℂ] Hilbert V, + HasKernel G p A ∧ r = ENNReal.ofReal ‖A‖} + +noncomputable def ptwo (G : BondGraph V E) : unitInterval := + sSup {p | OperatorBounded G p} + + +noncomputable def labelLaw : Measure (E → unitInterval) := + Measure.infinitePi (fun _ => (volume : Measure unitInterval)) + +def openEdges (labels : E → unitInterval) (p : unitInterval) : Set E := + {e | labels e ≤ p} + + +def MainConclusion (G : BondGraph V E) : Prop := + (sSup {r | ∃ p : unitInterval, p < pc G ∧ r = operatorNorm G p} = + operatorNorm G (pc G)) ∧ + operatorNorm G (pc G) < ⊤ ∧ + pc G < ptwo G ∧ ptwo G ≤ pu G ∧ + ∃ p₁ p₂ : unitInterval, pc G < p₁ ∧ p₁ < p₂ ∧ p₂ < 1 ∧ + ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), + ∀ p ∈ Set.Icc p₁ p₂, (infiniteClusters G (openEdges labels p)).Infinite + + + +section Deterministic +variable (G : BondGraph V E) (ω : Set E) + +@[simp] theorem conn_refl (x : V) : Conn G ω x x := + Relation.ReflTransGen.refl + +theorem conn_trans {x y z : V} (hxy : Conn G ω x y) (hyz : Conn G ω y z) : + Conn G ω x z := hxy.trans hyz + +theorem conn_symm {x y : V} (h : Conn G ω x y) : Conn G ω y x := by + induction h with + | refl => exact conn_refl G ω _ + | @tail y z _ hyz ih => + rcases hyz with ⟨e, he, hlink⟩ + exact (Relation.ReflTransGen.single ⟨e, he, hlink.trans (Sym2.eq_swap ..)⟩).trans ih + +theorem conn_mono {ω₁ ω₂ : Set E} (hω : ω₁ ⊆ ω₂) {x y : V} + (h : Conn G ω₁ x y) : Conn G ω₂ x y := by + apply Relation.ReflTransGen.mono (r := fun a b => ∃ e ∈ ω₁, G e = s(a, b)) ?_ x y h + rintro a b ⟨e, he, hab⟩ + exact ⟨e, hω he, hab⟩ + +theorem cluster_eq_of_conn {x y : V} (h : Conn G ω x y) : + cluster G ω x = cluster G ω y := by + ext z + exact ⟨fun hxz => conn_trans G ω (conn_symm G ω h) hxz, + fun hyz => conn_trans G ω h hyz⟩ + +@[simp] theorem mem_cluster_self (x : V) : x ∈ cluster G ω x := conn_refl G ω x + +theorem clusters_eq_or_disjoint (x y : V) : + cluster G ω x = cluster G ω y ∨ Disjoint (cluster G ω x) (cluster G ω y) := by + by_cases h : Conn G ω x y + · exact Or.inl (cluster_eq_of_conn G ω h) + · right + apply Set.disjoint_left.mpr + intro z hxz hyz + exact h (conn_trans G ω hxz (conn_symm G ω hyz)) + +@[simp] theorem conn_empty_iff (x y : V) : Conn G ∅ x y ↔ x = y := by + constructor + · intro h + induction h with + | refl => rfl + | tail _ he _ => rcases he with ⟨e, he, _⟩; exact he.elim + · rintro rfl + exact conn_refl G ∅ _ + +@[simp] theorem cluster_empty (x : V) : cluster G ∅ x = {x} := by + ext y + simp [cluster, eq_comm] + +@[simp] theorem infiniteClusters_empty : infiniteClusters G ∅ = ∅ := by + ext C + simp only [infiniteClusters, Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false, + not_and, not_exists] + intro h x hx + subst C + simp at h + +theorem conn_univ_of_connected (h : Connected G) (x y : V) : Conn G Set.univ x y := by + apply Relation.ReflTransGen.mono (r := Adj G) ?_ x y (h x y) + rintro a b ⟨e, he⟩ + exact ⟨e, Set.mem_univ _, he⟩ + +theorem cluster_univ_of_connected (h : Connected G) (x : V) : + cluster G Set.univ x = Set.univ := by + ext y + simp only [cluster, Set.mem_ofPred_eq, Set.mem_univ, iff_true] + exact conn_univ_of_connected G h x y + +theorem infiniteClusters_univ [Infinite V] (h : Connected G) : + infiniteClusters G Set.univ = {Set.univ} := by + ext C + constructor + · rintro ⟨_, x, rfl⟩ + simp [cluster_univ_of_connected G h] + · intro hC + have hC' : C = Set.univ := Set.mem_singleton_iff.mp hC + subst C + exact ⟨Set.infinite_univ, Classical.arbitrary V, + (cluster_univ_of_connected G h _).symm⟩ + +end Deterministic + +section Probability +variable (G : BondGraph V E) + +instance law_isProbabilityMeasure (p : unitInterval) : + IsProbabilityMeasure (law p : Measure (Set E)) := by + dsimp [law] + infer_instance + +@[simp] theorem law_zero : (law 0 : Measure (Set E)) = Measure.dirac ∅ := by + simp [law] + +@[simp] theorem law_one : (law 1 : Measure (Set E)) = Measure.dirac Set.univ := by + simp [law] + +@[simp] theorem twoPoint_self (p : unitInterval) (x : V) : twoPoint G p x x = 1 := by + simp [twoPoint] + +theorem twoPoint_nonneg (p : unitInterval) (x y : V) : 0 ≤ twoPoint G p x y := + ENNReal.toReal_nonneg + +theorem twoPoint_le_one (p : unitInterval) (x y : V) : twoPoint G p x y ≤ 1 := by + exact ENNReal.toReal_le_of_le_ofReal (by norm_num) (by simpa using + (prob_le_one (μ := law p) (s := {ω | Conn G ω x y}))) + +theorem twoPoint_symm (p : unitInterval) (x y : V) : twoPoint G p x y = twoPoint G p y x := by + have he : {ω | Conn G ω x y} = {ω | Conn G ω y x} := by + ext ω + exact ⟨conn_symm G ω, conn_symm G ω⟩ + simp only [twoPoint, he] + +@[simp] theorem twoPoint_zero [Countable E] [DecidableEq V] (x y : V) : + twoPoint G 0 x y = if x = y then 1 else 0 := by + rw [twoPoint, law_zero, Measure.dirac_apply] + by_cases h : x = y + · simp [h] + · rw [Set.indicator_of_notMem (by simpa using h)] + simp [h] + +theorem twoPoint_one (h : Connected G) (x y : V) : twoPoint G 1 x y = 1 := by + have hv : law (E := E) 1 {ω | Conn G ω x y} = 1 := by + rw [law_one] + exact Measure.dirac_apply_of_mem (conn_univ_of_connected G h x y) + change (law 1 {ω | Conn G ω x y}).toReal = 1 + rw [hv] + norm_num + +end Probability + +section Kernel +attribute [local instance] Classical.propDecidable + + +theorem kernel_extension_unique {K : V → V → ℂ} + {A B : Hilbert V →L[ℂ] Hilbert V} + (hA : ∀ x y, (A (lp.single 2 y (1 : ℂ))) x = K x y) + (hB : ∀ x y, (B (lp.single 2 y (1 : ℂ))) x = K x y) : A = B := by + apply lp.ext_continuousLinearMap (by norm_num : (2 : ℝ≥0∞) ≠ ⊤) + intro y + apply ContinuousLinearMap.ext + intro z + apply lp.ext + funext x + have hz : lp.single (E := fun _ : V => ℂ) 2 y z = + z • lp.single (E := fun _ : V => ℂ) 2 y (1 : ℂ) := by + simpa using (lp.single_smul (E := fun _ : V => ℂ) 2 y z (1 : ℂ)) + simp only [ContinuousLinearMap.coe_comp, Function.comp_apply, + lp.singleContinuousLinearMap_apply, hz, map_smul, lp.coeFn_smul, Pi.smul_apply, + hA, hB] + +theorem HasKernel.unique {G : BondGraph V E} {p : unitInterval} + {A B : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) (hB : HasKernel G p B) : + A = B := kernel_extension_unique hA hB + + +theorem operatorNorm_of_hasKernel {G : BondGraph V E} {p : unitInterval} + {A : Hilbert V →L[ℂ] Hilbert V} (hA : HasKernel G p A) : + operatorNorm G p = ENNReal.ofReal ‖A‖ := by + have he : {r | ∃ B : Hilbert V →L[ℂ] Hilbert V, + HasKernel G p B ∧ r = ENNReal.ofReal ‖B‖} = {ENNReal.ofReal ‖A‖} := by + ext r + constructor + · rintro ⟨B, hB, rfl⟩ + rw [hB.unique hA] + exact Set.mem_singleton _ + · intro hr + exact ⟨A, hA, Set.mem_singleton_iff.mp hr⟩ + change sInf _ = _ + rw [he, sInf_singleton] + +theorem operatorNorm_eq_top_iff (G : BondGraph V E) (p : unitInterval) : + operatorNorm G p = ⊤ ↔ ¬ OperatorBounded G p := by + constructor + · intro h ⟨A, hA⟩ + rw [operatorNorm_of_hasKernel hA] at h + exact ENNReal.ofReal_ne_top h + · intro h + unfold operatorNorm + have he : {r | ∃ A : Hilbert V →L[ℂ] Hilbert V, + HasKernel G p A ∧ r = ENNReal.ofReal ‖A‖} = ∅ := by + ext r + simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false] + rintro ⟨A, hA, _⟩ + exact h ⟨A, hA⟩ + rw [he, sInf_empty] + +theorem operatorNorm_lt_top_iff (G : BondGraph V E) (p : unitInterval) : + operatorNorm G p < ⊤ ↔ OperatorBounded G p := by + rw [lt_top_iff_ne_top, ne_eq, operatorNorm_eq_top_iff, not_not] + +theorem hasKernel_zero [Countable E] (G : BondGraph V E) : + HasKernel G 0 (ContinuousLinearMap.id ℂ (Hilbert V)) := by + intro x y + simp only [ContinuousLinearMap.id_apply, lp.single_apply, twoPoint_zero] + by_cases h : x = y + · subst y + simp + · simp [h] + +@[simp] theorem operatorBounded_zero [Countable E] (G : BondGraph V E) : + OperatorBounded G 0 := ⟨_, hasKernel_zero G⟩ + +end Kernel + +section Countability + + +theorem finite_neighbors {G : BondGraph V E} (hG : LocallyFinite G) (x : V) : + {y | Adj G x y}.Finite := by + classical + have hends (e : E) : {y | y ∈ G e}.Finite := by + apply (G e).toFinset.finite_toSet.subset + intro y hy + exact Sym2.mem_toFinset.mpr hy + have hs : (⋃ e ∈ {e | x ∈ G e}, {y | y ∈ G e}).Finite := + (hG x).biUnion (fun e _ => hends e) + apply hs.subset + rintro y ⟨e, he⟩ + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] + exact ⟨e, he ▸ by simp, he ▸ by simp⟩ + + +def reachBall (G : BondGraph V E) (x : V) : ℕ → Set V + | 0 => {x} + | n + 1 => reachBall G x n ∪ ⋃ y ∈ reachBall G x n, {z | Adj G y z} + +theorem finite_reachBall {G : BondGraph V E} (hG : LocallyFinite G) (x : V) : + ∀ n, (reachBall G x n).Finite := by + intro n + induction n with + | zero => exact Set.finite_singleton x + | succ n hn => + exact hn.union (hn.biUnion (fun y _ => finite_neighbors hG y)) + +theorem exists_mem_reachBall {G : BondGraph V E} {x y : V} + (h : Relation.ReflTransGen (Adj G) x y) : ∃ n, y ∈ reachBall G x n := by + induction h with + | refl => exact ⟨0, Set.mem_singleton _⟩ + | @tail y z _ hyz ih => + rcases ih with ⟨n, hn⟩ + refine ⟨n + 1, Or.inr ?_⟩ + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] + exact ⟨y, hn, hyz⟩ + +theorem countable_vertices [Nonempty V] {G : BondGraph V E} + (hG : LocallyFinite G) (hconn : Connected G) : Countable V := by + let x : V := Classical.arbitrary V + have he : (Set.univ : Set V) = ⋃ n, reachBall G x n := by + ext y + simp only [Set.mem_univ, Set.mem_iUnion, true_iff] + exact exists_mem_reachBall (hconn x y) + apply Set.countable_univ_iff.mp + rw [he] + exact Set.countable_iUnion (fun n => (finite_reachBall hG x n).countable) + +theorem countable_edges [Countable V] {G : BondGraph V E} + (hG : LocallyFinite G) : Countable E := by + have he : (Set.univ : Set E) = ⋃ x, {e | x ∈ G e} := by + ext e + simp only [Set.mem_univ, Set.mem_iUnion, Set.mem_ofPred_eq, true_iff] + exact ⟨(G e).out.1, Sym2.out_fst_mem _⟩ + apply Set.countable_univ_iff.mp + rw [he] + exact Set.countable_iUnion (fun x => (hG x).countable) + +end Countability + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Graph/FullTopology.lean b/lean/OAI/Probability/UnimodularPercolation/Graph/FullTopology.lean index 96c5b8402440fca91be45ab5434671559e598aae..9b7acc7fcfe8483c6ef5debfb36e3cace85d2051 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Graph/FullTopology.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Graph/FullTopology.lean @@ -1,310 +1,310 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main - -namespace OAI - -/-! The automorphism group with its topology of pointwise convergence. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open Topology -universe u v -variable {V : Type u} {E : Type v} - -noncomputable def graphAutSubgroup (G : BondGraph V E) : Subgroup (Equiv.Perm V) where - carrier := vertexAut G - one_mem' := ⟨Equiv.refl E, isAut_refl G⟩ - mul_mem' := by - rintro a b ⟨c,hc⟩ ⟨d,hd⟩ - exact ⟨d.trans c,isAut_trans G hd hc⟩ - inv_mem' := by - rintro a ⟨b,hb⟩ - exact ⟨b.symm,isAut_symm G hb⟩ - -def GraphAut (G : BondGraph V E) := ↥(graphAutSubgroup G) - -noncomputable instance (G : BondGraph V E) : Group (GraphAut G) := - inferInstanceAs (Group ↥(graphAutSubgroup G)) - -noncomputable instance (G : BondGraph V E) : MulAction (GraphAut G) V := - inferInstanceAs (MulAction ↥(graphAutSubgroup G) V) - -noncomputable def graphAutPerm (G : BondGraph V E) : GraphAut G →* Equiv.Perm V := - (graphAutSubgroup G).subtype - -theorem graphAutPerm_mem (G : BondGraph V E) (g : GraphAut G) : - graphAutPerm G g ∈ vertexAut G := g.property - -theorem mem_vertexAut_iff_adj (G : BondGraph V E) (hG : Function.Injective G) - (a : V ≃ V) : a ∈ vertexAut G ↔ ∀ x y, Adj G (a x) (a y) ↔ Adj G x y := by - classical - constructor - · rintro ⟨b,hb⟩ x y - refine ⟨fun h => ?_,adj_aut G hb⟩ - simpa only [Equiv.symm_apply_apply] using adj_aut G (isAut_symm G hb) h - · intro ha - have hex (e : E) : ∃ f : E, G f = (G e).map a := by - obtain ⟨x,y,hxy⟩ := Sym2.exists.mp (show ∃ t : Sym2 V, t = G e from ⟨_,rfl⟩) - have h := (ha x y).mpr ⟨e,hxy.symm⟩ - simpa only [←hxy,Sym2.map_mk] using (show ∃ f, G f = s(a x,a y) from h) - let f : E → E := fun e => Classical.choose (hex e) - have hf (e : E) : G (f e) = (G e).map a := Classical.choose_spec (hex e) - have hfi : Function.Injective f := by - intro e d hed - apply hG - have heq := congrArg (fun z => z.map a.symm) (congrArg G hed) - simpa only [hf,Sym2.map_map,Function.comp_def,Equiv.symm_apply_apply,Sym2.map_id',id_eq] using heq - have hfs : Function.Surjective f := by - intro e - obtain ⟨x,y,hxy⟩ := Sym2.exists.mp (show ∃ t : Sym2 V, t = G e from ⟨_,rfl⟩) - have h : Adj G (a.symm x) (a.symm y) := (ha _ _).mp (by - simpa only [Equiv.apply_symm_apply] using (show Adj G x y from ⟨e,hxy.symm⟩)) - obtain ⟨d,hd⟩ := h - refine ⟨d,hG ?_⟩ - rw [hf,hd,Sym2.map_mk,Equiv.apply_symm_apply,Equiv.apply_symm_apply,hxy] - exact ⟨Equiv.ofBijective f ⟨hfi,hfs⟩,hf⟩ - -section Topology -variable [TopologicalSpace V] [DiscreteTopology V] - -noncomputable def autCoordinates (G : BondGraph V E) (g : GraphAut G) : - (V → V) × (V → V) := (graphAutPerm G g,graphAutPerm G (g⁻¹)) - -noncomputable instance graphAutTopology (G : BondGraph V E) : TopologicalSpace (GraphAut G) := - TopologicalSpace.induced (autCoordinates G) inferInstance - -omit [DiscreteTopology V] in -theorem inducing_autCoordinates (G : BondGraph V E) : - IsInducing (autCoordinates G) := ⟨rfl⟩ - -omit [DiscreteTopology V] in -theorem embedding_autCoordinates (G : BondGraph V E) : - IsEmbedding (autCoordinates G) := by - refine ⟨inducing_autCoordinates G,?_⟩ - intro f g h - apply Subtype.ext - apply Equiv.ext - intro x - exact congrFun (congrArg Prod.fst h) x - -noncomputable instance graphAutT2 (G : BondGraph V E) : T2Space (GraphAut G) := - (embedding_autCoordinates G).t2Space - -omit [DiscreteTopology V] in -theorem continuous_aut_apply (G : BondGraph V E) (x : V) : - Continuous (fun g : GraphAut G => graphAutPerm G g x) := - (continuous_apply x).comp ((inducing_autCoordinates G).continuous.fst) - -omit [DiscreteTopology V] in -theorem continuous_aut_inv_apply (G : BondGraph V E) (x : V) : - Continuous (fun g : GraphAut G => graphAutPerm G (g⁻¹) x) := - (continuous_apply x).comp ((inducing_autCoordinates G).continuous.snd) - -theorem continuous_discrete_eval : Continuous (fun p : (V → V) × V => p.1 p.2) := - continuous_prod_of_discrete_right.mpr fun x => continuous_apply x - -noncomputable instance graphAutTopologicalGroup (G : BondGraph V E) : - IsTopologicalGroup (GraphAut G) where - continuous_mul := by - apply (inducing_autCoordinates G).continuous_iff.mpr - apply Continuous.prodMk - · apply continuous_pi - intro x - exact continuous_discrete_eval.comp - (((inducing_autCoordinates G).continuous.fst.comp continuous_fst).prodMk - ((continuous_aut_apply G x).comp continuous_snd)) - · apply continuous_pi - intro x - exact continuous_discrete_eval.comp - (((inducing_autCoordinates G).continuous.snd.comp continuous_snd).prodMk - ((continuous_aut_inv_apply G x).comp continuous_fst)) - continuous_inv := by - apply (inducing_autCoordinates G).continuous_iff.mpr - simpa only [Function.comp_def,autCoordinates,inv_inv] using ((inducing_autCoordinates G).continuous.snd.prodMk (inducing_autCoordinates G).continuous.fst) - -def autCoordinateSet (G : BondGraph V E) : Set ((V → V) × (V → V)) := - {p | (∀ x, p.1 (p.2 x) = x) ∧ (∀ x, p.2 (p.1 x) = x) ∧ - ∀ x y, Adj G (p.1 x) (p.1 y) ↔ Adj G x y} - -omit [TopologicalSpace V] [DiscreteTopology V] in -theorem range_autCoordinates (G : BondGraph V E) (hG : Function.Injective G) : - Set.range (autCoordinates G) = autCoordinateSet G := by - classical - ext p - constructor - · rintro ⟨g,rfl⟩ - refine ⟨fun x => ?_,fun x => ?_,?_⟩ - · exact Equiv.apply_symm_apply (graphAutPerm G g) x - · exact Equiv.symm_apply_apply (graphAutPerm G g) x - · exact (mem_vertexAut_iff_adj G hG _).mp (graphAutPerm_mem G g) - · rintro ⟨h₁,h₂,hA⟩ - let a : Equiv.Perm V := ⟨p.1,p.2,h₂,h₁⟩ - let g : GraphAut G := ⟨a,(mem_vertexAut_iff_adj G hG a).mpr hA⟩ - exact ⟨g,rfl⟩ - -theorem continuous_coordinate_forward_inverse (x : V) : - Continuous (fun p : (V → V) × (V → V) => p.1 (p.2 x)) := by - have h₁ : Continuous (fun p : (V → V) × (V → V) => p.1) := continuous_fst - have h₂ : Continuous (fun p : (V → V) × (V → V) => p.2 x) := - (continuous_apply x).comp continuous_snd - exact (continuous_discrete_eval (V := V)).comp (h₁.prodMk h₂) - -theorem continuous_coordinate_inverse_forward (x : V) : - Continuous (fun p : (V → V) × (V → V) => p.2 (p.1 x)) := by - have h₁ : Continuous (fun p : (V → V) × (V → V) => p.2) := continuous_snd - have h₂ : Continuous (fun p : (V → V) × (V → V) => p.1 x) := - (continuous_apply x).comp continuous_fst - exact (continuous_discrete_eval (V := V)).comp (h₁.prodMk h₂) - -theorem isClosed_coordinate_forward_inverse : - IsClosed {p : (V → V) × (V → V) | ∀ x, p.1 (p.2 x) = x} := by - have h (x : V) : IsClosed {p : (V → V) × (V → V) | p.1 (p.2 x) = x} := - isClosed_eq (continuous_coordinate_forward_inverse x) continuous_const - convert isClosed_iInter h using 1 - ext p - simp only [Set.mem_iInter,Set.mem_ofPred_eq] - -theorem isClosed_coordinate_inverse_forward : - IsClosed {p : (V → V) × (V → V) | ∀ x, p.2 (p.1 x) = x} := by - have h (x : V) : IsClosed {p : (V → V) × (V → V) | p.2 (p.1 x) = x} := - isClosed_eq (continuous_coordinate_inverse_forward x) continuous_const - convert isClosed_iInter h using 1 - ext p - simp only [Set.mem_iInter,Set.mem_ofPred_eq] - -theorem isClosed_coordinate_adjacency (G : BondGraph V E) : - IsClosed {p : (V → V) × (V → V) | - ∀ x y, Adj G (p.1 x) (p.1 y) ↔ Adj G x y} := by - have h (x y : V) : IsClosed {p : (V → V) × (V → V) | - Adj G (p.1 x) (p.1 y) ↔ Adj G x y} := by - have hx : Continuous (fun p : (V → V) × (V → V) => p.1 x) := - (continuous_apply x).comp continuous_fst - have hy : Continuous (fun p : (V → V) × (V → V) => p.1 y) := - (continuous_apply y).comp continuous_fst - exact (isClosed_discrete {q : V × V | Adj G q.1 q.2 ↔ Adj G x y}).preimage - (hx.prodMk hy) - convert isClosed_iInter (fun x => isClosed_iInter (h x)) using 1 - ext p - simp only [Set.mem_iInter,Set.mem_ofPred_eq] - -theorem isClosed_autCoordinateSet (G : BondGraph V E) : - IsClosed (autCoordinateSet G) := - isClosed_coordinate_forward_inverse.inter - (isClosed_coordinate_inverse_forward.inter (isClosed_coordinate_adjacency G)) - -def graphStabilizer (G : BondGraph V E) (x : V) : Set (GraphAut G) := - {g | graphAutPerm G g x = x} - -theorem isOpen_graphStabilizer (G : BondGraph V E) (x : V) : - IsOpen (graphStabilizer G x) := - (isOpen_discrete {x}).preimage (continuous_aut_apply G x) - -theorem isClosed_stabilizer_coordinates (G : BondGraph V E) - (hG : Function.Injective G) (x : V) : - IsClosed (autCoordinates G '' graphStabilizer G x) := by - have he : autCoordinates G '' graphStabilizer G x = - autCoordinateSet G ∩ {p | p.1 x = x} := by - ext p - constructor - · rintro ⟨g,hg,rfl⟩ - refine ⟨?_,hg⟩ - rw [←range_autCoordinates G hG] - exact ⟨g,rfl⟩ - · rintro ⟨hp,hpx⟩ - rw [←range_autCoordinates G hG] at hp - obtain ⟨g,rfl⟩ := hp - exact ⟨g,hpx,rfl⟩ - rw [he] - exact (isClosed_autCoordinateSet G).inter - (isClosed_eq ((continuous_apply x).comp continuous_fst) continuous_const) - -theorem isCompact_graphStabilizer (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : - IsCompact (graphStabilizer G x) := by - classical - choose n hn using fun y => exists_mem_reachBall (hconn x y) - let K : Set (V → V) := {f | ∀ y, f y ∈ reachBall G x (n y)} - have hK : IsCompact K := isCompact_pi_infinite fun y => - (finite_reachBall hloc x (n y)).isCompact - apply (embedding_autCoordinates G).isCompact_iff.mpr - apply (hK.prod hK).of_isClosed_subset (isClosed_stabilizer_coordinates G hG x) - rintro p ⟨g,hg,rfl⟩ - have hball (g : GraphAut G) (hg : graphAutPerm G g x = x) (y : V) : - graphAutPerm G g y ∈ reachBall G x (n y) := by - obtain ⟨b,hb⟩ := graphAutPerm_mem G g - simpa only [hg] using mem_reachBall_aut G hb (hn y) - refine ⟨fun y => hball g hg y,fun y => hball g⁻¹ ?_ y⟩ - have he := congrArg (graphAutPerm G (g⁻¹)) hg - exact he.symm.trans (Equiv.symm_apply_apply (graphAutPerm G g) x) - -theorem locallyCompact_graphAut (G : BondGraph V E) (hG : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : - LocallyCompactSpace (GraphAut G) := - (isCompact_graphStabilizer G hG hloc hconn x).locallyCompactSpace_of_mem_nhds_of_group - ((isOpen_graphStabilizer G x).mem_nhds (show (1 : GraphAut G) ∈ graphStabilizer G x from rfl)) - -theorem graphAutTopology_eq_pointwise (G : BondGraph V E) : - graphAutTopology G = TopologicalSpace.induced - (fun g : GraphAut G => (graphAutPerm G g : V → V)) inferInstance := by - apply le_antisymm - · apply continuous_iff_le_induced.mp - exact continuous_pi fun x => continuous_aut_apply G x - · let : TopologicalSpace (GraphAut G) := TopologicalSpace.induced - (fun g : GraphAut G => (graphAutPerm G g : V → V)) inferInstance - have hf : Continuous (fun g : GraphAut G => (graphAutPerm G g : V → V)) := - continuous_induced_dom - have hi : Continuous (fun g : GraphAut G => (graphAutPerm G (g⁻¹) : V → V)) := by - apply continuous_pi - intro x - apply continuous_discrete_rng.mpr - intro y - have he : (fun g : GraphAut G => graphAutPerm G (g⁻¹) x) ⁻¹' {y} = - (fun g : GraphAut G => graphAutPerm G g y) ⁻¹' {x} := by - ext g - change (graphAutPerm G g).symm x = y ↔ graphAutPerm G g y = x - rw [Equiv.symm_apply_eq,eq_comm] - rw [he] - exact (isOpen_discrete {x}).preimage ((continuous_apply y).comp hf) - exact continuous_iff_le_induced.mp (hf.prodMk hi) - -instance fullGraphAutSecondCountable (G : BondGraph V E) [Countable V] : - SecondCountableTopology (GraphAut G) := - (inducing_autCoordinates G).secondCountableTopology - -end Topology - -abbrev GraphOrbit (G : BondGraph V E) := MulAction.orbitRel.Quotient (GraphAut G) V - -theorem finite_graphOrbit (G : BondGraph V E) (hqt : QuasiTransitive G) : - Finite (GraphOrbit G) := by - classical - obtain ⟨R,hR⟩ := hqt - apply Finite.of_surjective (fun o : (R : Set V) => - (Quotient.mk'' o.1 : GraphOrbit G)) - intro q - induction q using Quotient.inductionOn with - | h x => - obtain ⟨o,ho,a,b,hab,hao⟩ := hR x - refine ⟨⟨o,ho⟩,?_⟩ - symm - exact Quotient.sound (show MulAction.orbitRel (GraphAut G) V x o from - ⟨(⟨a,⟨b,hab⟩⟩ : GraphAut G),hao⟩) - -noncomputable def fullGraphOrbitRoot (G : BondGraph V E) (q : GraphOrbit G) : V := q.out - -theorem graphOrbitRoot_covers (G : BondGraph V E) (x : V) : - ∃ i : GraphOrbit G, ∃ g : GraphAut G, g • fullGraphOrbitRoot G i = x := by - refine ⟨Quotient.mk'' x,?_⟩ - exact Quotient.exact (Quotient.out_eq' (Quotient.mk'' x : GraphOrbit G)).symm - -theorem graphOrbitRoot_separates (G : BondGraph V E) (i j : GraphOrbit G) - (h : ∃ g : GraphAut G, g • fullGraphOrbitRoot G i = fullGraphOrbitRoot G j) : i = j := by - have he : (Quotient.mk'' (fullGraphOrbitRoot G j) : GraphOrbit G) = - Quotient.mk'' (fullGraphOrbitRoot G i) := Quotient.sound h - simpa only [fullGraphOrbitRoot,Quotient.out_eq'] using he.symm - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main + +namespace OAI + +/-! The automorphism group with its topology of pointwise convergence. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open Topology +universe u v +variable {V : Type u} {E : Type v} + +noncomputable def graphAutSubgroup (G : BondGraph V E) : Subgroup (Equiv.Perm V) where + carrier := vertexAut G + one_mem' := ⟨Equiv.refl E, isAut_refl G⟩ + mul_mem' := by + rintro a b ⟨c,hc⟩ ⟨d,hd⟩ + exact ⟨d.trans c,isAut_trans G hd hc⟩ + inv_mem' := by + rintro a ⟨b,hb⟩ + exact ⟨b.symm,isAut_symm G hb⟩ + +def GraphAut (G : BondGraph V E) := ↥(graphAutSubgroup G) + +noncomputable instance (G : BondGraph V E) : Group (GraphAut G) := + inferInstanceAs (Group ↥(graphAutSubgroup G)) + +noncomputable instance (G : BondGraph V E) : MulAction (GraphAut G) V := + inferInstanceAs (MulAction ↥(graphAutSubgroup G) V) + +noncomputable def graphAutPerm (G : BondGraph V E) : GraphAut G →* Equiv.Perm V := + (graphAutSubgroup G).subtype + +theorem graphAutPerm_mem (G : BondGraph V E) (g : GraphAut G) : + graphAutPerm G g ∈ vertexAut G := g.property + +theorem mem_vertexAut_iff_adj (G : BondGraph V E) (hG : Function.Injective G) + (a : V ≃ V) : a ∈ vertexAut G ↔ ∀ x y, Adj G (a x) (a y) ↔ Adj G x y := by + classical + constructor + · rintro ⟨b,hb⟩ x y + refine ⟨fun h => ?_,adj_aut G hb⟩ + simpa only [Equiv.symm_apply_apply] using adj_aut G (isAut_symm G hb) h + · intro ha + have hex (e : E) : ∃ f : E, G f = (G e).map a := by + obtain ⟨x,y,hxy⟩ := Sym2.exists.mp (show ∃ t : Sym2 V, t = G e from ⟨_,rfl⟩) + have h := (ha x y).mpr ⟨e,hxy.symm⟩ + simpa only [←hxy,Sym2.map_mk] using (show ∃ f, G f = s(a x,a y) from h) + let f : E → E := fun e => Classical.choose (hex e) + have hf (e : E) : G (f e) = (G e).map a := Classical.choose_spec (hex e) + have hfi : Function.Injective f := by + intro e d hed + apply hG + have heq := congrArg (fun z => z.map a.symm) (congrArg G hed) + simpa only [hf,Sym2.map_map,Function.comp_def,Equiv.symm_apply_apply,Sym2.map_id',id_eq] using heq + have hfs : Function.Surjective f := by + intro e + obtain ⟨x,y,hxy⟩ := Sym2.exists.mp (show ∃ t : Sym2 V, t = G e from ⟨_,rfl⟩) + have h : Adj G (a.symm x) (a.symm y) := (ha _ _).mp (by + simpa only [Equiv.apply_symm_apply] using (show Adj G x y from ⟨e,hxy.symm⟩)) + obtain ⟨d,hd⟩ := h + refine ⟨d,hG ?_⟩ + rw [hf,hd,Sym2.map_mk,Equiv.apply_symm_apply,Equiv.apply_symm_apply,hxy] + exact ⟨Equiv.ofBijective f ⟨hfi,hfs⟩,hf⟩ + +section Topology +variable [TopologicalSpace V] [DiscreteTopology V] + +noncomputable def autCoordinates (G : BondGraph V E) (g : GraphAut G) : + (V → V) × (V → V) := (graphAutPerm G g,graphAutPerm G (g⁻¹)) + +noncomputable instance graphAutTopology (G : BondGraph V E) : TopologicalSpace (GraphAut G) := + TopologicalSpace.induced (autCoordinates G) inferInstance + +omit [DiscreteTopology V] in +theorem inducing_autCoordinates (G : BondGraph V E) : + IsInducing (autCoordinates G) := ⟨rfl⟩ + +omit [DiscreteTopology V] in +theorem embedding_autCoordinates (G : BondGraph V E) : + IsEmbedding (autCoordinates G) := by + refine ⟨inducing_autCoordinates G,?_⟩ + intro f g h + apply Subtype.ext + apply Equiv.ext + intro x + exact congrFun (congrArg Prod.fst h) x + +noncomputable instance graphAutT2 (G : BondGraph V E) : T2Space (GraphAut G) := + (embedding_autCoordinates G).t2Space + +omit [DiscreteTopology V] in +theorem continuous_aut_apply (G : BondGraph V E) (x : V) : + Continuous (fun g : GraphAut G => graphAutPerm G g x) := + (continuous_apply x).comp ((inducing_autCoordinates G).continuous.fst) + +omit [DiscreteTopology V] in +theorem continuous_aut_inv_apply (G : BondGraph V E) (x : V) : + Continuous (fun g : GraphAut G => graphAutPerm G (g⁻¹) x) := + (continuous_apply x).comp ((inducing_autCoordinates G).continuous.snd) + +theorem continuous_discrete_eval : Continuous (fun p : (V → V) × V => p.1 p.2) := + continuous_prod_of_discrete_right.mpr fun x => continuous_apply x + +noncomputable instance graphAutTopologicalGroup (G : BondGraph V E) : + IsTopologicalGroup (GraphAut G) where + continuous_mul := by + apply (inducing_autCoordinates G).continuous_iff.mpr + apply Continuous.prodMk + · apply continuous_pi + intro x + exact continuous_discrete_eval.comp + (((inducing_autCoordinates G).continuous.fst.comp continuous_fst).prodMk + ((continuous_aut_apply G x).comp continuous_snd)) + · apply continuous_pi + intro x + exact continuous_discrete_eval.comp + (((inducing_autCoordinates G).continuous.snd.comp continuous_snd).prodMk + ((continuous_aut_inv_apply G x).comp continuous_fst)) + continuous_inv := by + apply (inducing_autCoordinates G).continuous_iff.mpr + simpa only [Function.comp_def,autCoordinates,inv_inv] using ((inducing_autCoordinates G).continuous.snd.prodMk (inducing_autCoordinates G).continuous.fst) + +def autCoordinateSet (G : BondGraph V E) : Set ((V → V) × (V → V)) := + {p | (∀ x, p.1 (p.2 x) = x) ∧ (∀ x, p.2 (p.1 x) = x) ∧ + ∀ x y, Adj G (p.1 x) (p.1 y) ↔ Adj G x y} + +omit [TopologicalSpace V] [DiscreteTopology V] in +theorem range_autCoordinates (G : BondGraph V E) (hG : Function.Injective G) : + Set.range (autCoordinates G) = autCoordinateSet G := by + classical + ext p + constructor + · rintro ⟨g,rfl⟩ + refine ⟨fun x => ?_,fun x => ?_,?_⟩ + · exact Equiv.apply_symm_apply (graphAutPerm G g) x + · exact Equiv.symm_apply_apply (graphAutPerm G g) x + · exact (mem_vertexAut_iff_adj G hG _).mp (graphAutPerm_mem G g) + · rintro ⟨h₁,h₂,hA⟩ + let a : Equiv.Perm V := ⟨p.1,p.2,h₂,h₁⟩ + let g : GraphAut G := ⟨a,(mem_vertexAut_iff_adj G hG a).mpr hA⟩ + exact ⟨g,rfl⟩ + +theorem continuous_coordinate_forward_inverse (x : V) : + Continuous (fun p : (V → V) × (V → V) => p.1 (p.2 x)) := by + have h₁ : Continuous (fun p : (V → V) × (V → V) => p.1) := continuous_fst + have h₂ : Continuous (fun p : (V → V) × (V → V) => p.2 x) := + (continuous_apply x).comp continuous_snd + exact (continuous_discrete_eval (V := V)).comp (h₁.prodMk h₂) + +theorem continuous_coordinate_inverse_forward (x : V) : + Continuous (fun p : (V → V) × (V → V) => p.2 (p.1 x)) := by + have h₁ : Continuous (fun p : (V → V) × (V → V) => p.2) := continuous_snd + have h₂ : Continuous (fun p : (V → V) × (V → V) => p.1 x) := + (continuous_apply x).comp continuous_fst + exact (continuous_discrete_eval (V := V)).comp (h₁.prodMk h₂) + +theorem isClosed_coordinate_forward_inverse : + IsClosed {p : (V → V) × (V → V) | ∀ x, p.1 (p.2 x) = x} := by + have h (x : V) : IsClosed {p : (V → V) × (V → V) | p.1 (p.2 x) = x} := + isClosed_eq (continuous_coordinate_forward_inverse x) continuous_const + convert isClosed_iInter h using 1 + ext p + simp only [Set.mem_iInter,Set.mem_ofPred_eq] + +theorem isClosed_coordinate_inverse_forward : + IsClosed {p : (V → V) × (V → V) | ∀ x, p.2 (p.1 x) = x} := by + have h (x : V) : IsClosed {p : (V → V) × (V → V) | p.2 (p.1 x) = x} := + isClosed_eq (continuous_coordinate_inverse_forward x) continuous_const + convert isClosed_iInter h using 1 + ext p + simp only [Set.mem_iInter,Set.mem_ofPred_eq] + +theorem isClosed_coordinate_adjacency (G : BondGraph V E) : + IsClosed {p : (V → V) × (V → V) | + ∀ x y, Adj G (p.1 x) (p.1 y) ↔ Adj G x y} := by + have h (x y : V) : IsClosed {p : (V → V) × (V → V) | + Adj G (p.1 x) (p.1 y) ↔ Adj G x y} := by + have hx : Continuous (fun p : (V → V) × (V → V) => p.1 x) := + (continuous_apply x).comp continuous_fst + have hy : Continuous (fun p : (V → V) × (V → V) => p.1 y) := + (continuous_apply y).comp continuous_fst + exact (isClosed_discrete {q : V × V | Adj G q.1 q.2 ↔ Adj G x y}).preimage + (hx.prodMk hy) + convert isClosed_iInter (fun x => isClosed_iInter (h x)) using 1 + ext p + simp only [Set.mem_iInter,Set.mem_ofPred_eq] + +theorem isClosed_autCoordinateSet (G : BondGraph V E) : + IsClosed (autCoordinateSet G) := + isClosed_coordinate_forward_inverse.inter + (isClosed_coordinate_inverse_forward.inter (isClosed_coordinate_adjacency G)) + +def graphStabilizer (G : BondGraph V E) (x : V) : Set (GraphAut G) := + {g | graphAutPerm G g x = x} + +theorem isOpen_graphStabilizer (G : BondGraph V E) (x : V) : + IsOpen (graphStabilizer G x) := + (isOpen_discrete {x}).preimage (continuous_aut_apply G x) + +theorem isClosed_stabilizer_coordinates (G : BondGraph V E) + (hG : Function.Injective G) (x : V) : + IsClosed (autCoordinates G '' graphStabilizer G x) := by + have he : autCoordinates G '' graphStabilizer G x = + autCoordinateSet G ∩ {p | p.1 x = x} := by + ext p + constructor + · rintro ⟨g,hg,rfl⟩ + refine ⟨?_,hg⟩ + rw [←range_autCoordinates G hG] + exact ⟨g,rfl⟩ + · rintro ⟨hp,hpx⟩ + rw [←range_autCoordinates G hG] at hp + obtain ⟨g,rfl⟩ := hp + exact ⟨g,hpx,rfl⟩ + rw [he] + exact (isClosed_autCoordinateSet G).inter + (isClosed_eq ((continuous_apply x).comp continuous_fst) continuous_const) + +theorem isCompact_graphStabilizer (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : + IsCompact (graphStabilizer G x) := by + classical + choose n hn using fun y => exists_mem_reachBall (hconn x y) + let K : Set (V → V) := {f | ∀ y, f y ∈ reachBall G x (n y)} + have hK : IsCompact K := isCompact_pi_infinite fun y => + (finite_reachBall hloc x (n y)).isCompact + apply (embedding_autCoordinates G).isCompact_iff.mpr + apply (hK.prod hK).of_isClosed_subset (isClosed_stabilizer_coordinates G hG x) + rintro p ⟨g,hg,rfl⟩ + have hball (g : GraphAut G) (hg : graphAutPerm G g x = x) (y : V) : + graphAutPerm G g y ∈ reachBall G x (n y) := by + obtain ⟨b,hb⟩ := graphAutPerm_mem G g + simpa only [hg] using mem_reachBall_aut G hb (hn y) + refine ⟨fun y => hball g hg y,fun y => hball g⁻¹ ?_ y⟩ + have he := congrArg (graphAutPerm G (g⁻¹)) hg + exact he.symm.trans (Equiv.symm_apply_apply (graphAutPerm G g) x) + +theorem locallyCompact_graphAut (G : BondGraph V E) (hG : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : + LocallyCompactSpace (GraphAut G) := + (isCompact_graphStabilizer G hG hloc hconn x).locallyCompactSpace_of_mem_nhds_of_group + ((isOpen_graphStabilizer G x).mem_nhds (show (1 : GraphAut G) ∈ graphStabilizer G x from rfl)) + +theorem graphAutTopology_eq_pointwise (G : BondGraph V E) : + graphAutTopology G = TopologicalSpace.induced + (fun g : GraphAut G => (graphAutPerm G g : V → V)) inferInstance := by + apply le_antisymm + · apply continuous_iff_le_induced.mp + exact continuous_pi fun x => continuous_aut_apply G x + · let : TopologicalSpace (GraphAut G) := TopologicalSpace.induced + (fun g : GraphAut G => (graphAutPerm G g : V → V)) inferInstance + have hf : Continuous (fun g : GraphAut G => (graphAutPerm G g : V → V)) := + continuous_induced_dom + have hi : Continuous (fun g : GraphAut G => (graphAutPerm G (g⁻¹) : V → V)) := by + apply continuous_pi + intro x + apply continuous_discrete_rng.mpr + intro y + have he : (fun g : GraphAut G => graphAutPerm G (g⁻¹) x) ⁻¹' {y} = + (fun g : GraphAut G => graphAutPerm G g y) ⁻¹' {x} := by + ext g + change (graphAutPerm G g).symm x = y ↔ graphAutPerm G g y = x + rw [Equiv.symm_apply_eq,eq_comm] + rw [he] + exact (isOpen_discrete {x}).preimage ((continuous_apply y).comp hf) + exact continuous_iff_le_induced.mp (hf.prodMk hi) + +instance fullGraphAutSecondCountable (G : BondGraph V E) [Countable V] : + SecondCountableTopology (GraphAut G) := + (inducing_autCoordinates G).secondCountableTopology + +end Topology + +abbrev GraphOrbit (G : BondGraph V E) := MulAction.orbitRel.Quotient (GraphAut G) V + +theorem finite_graphOrbit (G : BondGraph V E) (hqt : QuasiTransitive G) : + Finite (GraphOrbit G) := by + classical + obtain ⟨R,hR⟩ := hqt + apply Finite.of_surjective (fun o : (R : Set V) => + (Quotient.mk'' o.1 : GraphOrbit G)) + intro q + induction q using Quotient.inductionOn with + | h x => + obtain ⟨o,ho,a,b,hab,hao⟩ := hR x + refine ⟨⟨o,ho⟩,?_⟩ + symm + exact Quotient.sound (show MulAction.orbitRel (GraphAut G) V x o from + ⟨(⟨a,⟨b,hab⟩⟩ : GraphAut G),hao⟩) + +noncomputable def fullGraphOrbitRoot (G : BondGraph V E) (q : GraphOrbit G) : V := q.out + +theorem graphOrbitRoot_covers (G : BondGraph V E) (x : V) : + ∃ i : GraphOrbit G, ∃ g : GraphAut G, g • fullGraphOrbitRoot G i = x := by + refine ⟨Quotient.mk'' x,?_⟩ + exact Quotient.exact (Quotient.out_eq' (Quotient.mk'' x : GraphOrbit G)).symm + +theorem graphOrbitRoot_separates (G : BondGraph V E) (i j : GraphOrbit G) + (h : ∃ g : GraphAut G, g • fullGraphOrbitRoot G i = fullGraphOrbitRoot G j) : i = j := by + have he : (Quotient.mk'' (fullGraphOrbitRoot G j) : GraphOrbit G) = + Quotient.mk'' (fullGraphOrbitRoot G i) := Quotient.sound h + simpa only [fullGraphOrbitRoot,Quotient.out_eq'] using he.symm + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Graph/Paths.lean b/lean/OAI/Probability/UnimodularPercolation/Graph/Paths.lean index 841551406451569844569ca72d18402f81a61cd2..d6ebcbc96f4e8f263b94e2591a6f6df5fa788414 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Graph/Paths.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Graph/Paths.lean @@ -1,314 +1,314 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.Uniqueness - -namespace OAI - -/-! Bond paths, degree bounds and positivity of the critical parameter. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section BondPaths -attribute [local instance] Classical.propDecidable - - -inductive Along (G : BondGraph V E) : V → List E → V → Prop - | nil (x : V) : Along G x [] x - | cons {x z y : V} {l : List E} (e : E) (he : G e = s(x,z)) - (tail : Along G z l y) : Along G x (e :: l) y - - theorem Along.conn {G : BondGraph V E} {x y : V} {l : List E} (h : Along G x l y) - {ω : Set E} (ho : ∀ e ∈ l, e ∈ ω) : Conn G ω x y := by - induction h with - | nil => exact conn_refl G ω _ - | @cons x z y l e he ht ih => - exact (Relation.ReflTransGen.single ⟨e, ho e (by simp), he⟩).trans - (ih (fun e' he' => ho e' (by simp [he']))) - - def openSimpleGraph (G : BondGraph V E) (ω : Set E) : SimpleGraph V where - Adj x y := x ≠ y ∧ ∃ e ∈ ω, G e = s(x,y) - symm := ⟨by - rintro x y ⟨hxy, e, he, h⟩ - exact ⟨hxy.symm, e, he, h.trans (Sym2.eq_swap ..)⟩⟩ - loopless := ⟨by simp⟩ - - theorem conn_iff_reachable (G : BondGraph V E) (ω : Set E) (x y : V) : - Conn G ω x y ↔ (openSimpleGraph G ω).Reachable x y := by - constructor - · intro h - induction h with - | refl => exact ⟨.nil⟩ - | @tail z y h hy ih => - obtain ⟨w⟩ := ih - by_cases hzy : z = y - · subst y; exact ⟨w⟩ - · exact ⟨w.concat ⟨hzy, hy⟩⟩ - · rintro ⟨w⟩ - induction w with - | nil => exact conn_refl G ω _ - | @cons x z y hadj w ih => - exact (Relation.ReflTransGen.single hadj.2).trans ih - - theorem walk_lift_bonds (G : BondGraph V E) (ω : Set E) {x y : V} - (w : (openSimpleGraph G ω).Walk x y) : - ∃ l : List E, Along G x l y ∧ l.map G = w.edges ∧ ∀ e ∈ l, e ∈ ω := by - induction w with - | nil => exact ⟨[], .nil _, rfl, by simp⟩ - | @cons x z y hadj w ih => - obtain ⟨e, he, heq⟩ := hadj.2 - obtain ⟨l, hl, hmap, hopen⟩ := ih - refine ⟨e :: l, .cons e heq hl, ?_, ?_⟩ - · simp [hmap, heq] - · intro e' he' - rcases List.mem_cons.mp he' with rfl | he' - · exact he - · exact hopen e' he' - - - theorem conn_exists_bond_trail (G : BondGraph V E) {ω : Set E} {x y : V} - (h : Conn G ω x y) : - ∃ l : List E, Along G x l y ∧ l.Nodup ∧ ∀ e ∈ l, e ∈ ω := by - obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp h - obtain ⟨l, hl, hmap, hopen⟩ := walk_lift_bonds G ω (w.toPath : (openSimpleGraph G ω).Walk x y) - refine ⟨l, hl, ?_, hopen⟩ - apply List.Nodup.of_map (f := G) - rw [hmap] - exact w.toPath.property.isTrail.edges_nodup - - theorem Along.append {G : BondGraph V E} {x y z : V} {l k : List E} - (hl : Along G x l y) (hk : Along G y k z) : Along G x (l ++ k) z := by - induction hl with - | nil => exact hk - | cons e he ht ih => exact .cons e he (ih hk) - -end BondPaths - -section DegreeBound -attribute [local instance] Classical.propDecidable - - def Step (G : BondGraph V E) (x : V) := {ey : E × V // G ey.1 = s(x,ey.2)} - - theorem finite_steps (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - Set.Finite {ey : E × V | G ey.1 = s(x,ey.2)} := by - apply ((hloc x).prod (finite_neighbors hloc x)).subset - rintro ⟨e,y⟩ he - change G e = s(x,y) at he - exact ⟨by change x ∈ G e; rw [he]; simp, e, he⟩ - - noncomputable def stepEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (x : V) : Step G x ≃ Step G (a x) where - toFun d := ⟨(b d.val.1, a d.val.2), by rw [h, d.property, Sym2.map_mk]⟩ - invFun d := ⟨(b.symm d.val.1, a.symm d.val.2), by - rw [isAut_symm G h, d.property, Sym2.map_mk, Equiv.symm_apply_apply]⟩ - left_inv d := by apply Subtype.ext; exact Prod.ext (b.symm_apply_apply _) (a.symm_apply_apply _) - right_inv d := by apply Subtype.ext; exact Prod.ext (b.apply_symm_apply _) (a.apply_symm_apply _) - - noncomputable def degree (G : BondGraph V E) (x : V) : ℕ := Nat.card (Step G x) - - theorem degree_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (x : V) : degree G (a x) = degree G x := - (Nat.card_congr (stepEquiv G h x)).symm - - theorem exists_degree_bound (G : BondGraph V E) (hqt : QuasiTransitive G) : - ∃ D : ℕ, 0 < D ∧ ∀ x, degree G x ≤ D := by - obtain ⟨F, hF⟩ := hqt - refine ⟨(∑ x ∈ F, degree G x) + 1, Nat.zero_lt_succ _, ?_⟩ - intro x - obtain ⟨o, ho, a, b, hab, rfl⟩ := hF x - rw [degree_aut G hab] - exact (Finset.single_le_sum (fun _ _ => Nat.zero_le _) ho).trans (Nat.le_succ _) - -end DegreeBound - -section SmallParameter -attribute [local instance] Classical.propDecidable - -def TrailLength (G : BondGraph V E) (x : V) (n : ℕ) : Set (Set E) := - {ω | ∃ y l, Along G x l y ∧ l.Nodup ∧ l.length = n ∧ ∀ e ∈ l, e ∈ ω} - -theorem trailLength_upper (G : BondGraph V E) (x : V) (n : ℕ) : - IsUpperSet (TrailLength G x n) := by - rintro ω η h ⟨y,l,hl,hn,hlen,ho⟩ - exact ⟨y,l,hl,hn,hlen,fun e he => h (ho e he)⟩ - -theorem finiteWitness_trailLength (G : BondGraph V E) (x : V) (n : ℕ) : - FiniteWitness (TrailLength G x n) := by - rintro ω ⟨y,l,hl,hn,hlen,ho⟩ - exact ⟨l.toFinset, fun e he => ho e (List.mem_toFinset.mp he), - y,l,hl,hn,hlen, fun e he => List.mem_toFinset.mpr he⟩ - -theorem finiteWitness_edge (e : E) : FiniteWitness {ω : Set E | e ∈ ω} := by - intro ω he - exact ⟨{e}, by simpa using he, by simp⟩ - -theorem trailLength_succ_subset (G : BondGraph V E) (x : V) (n : ℕ) : - TrailLength G x (n+1) ⊆ ⋃ d : Step G x, - DisjointOccurrence {ω | d.val.1 ∈ ω} (TrailLength G d.val.2 n) := by - rintro ω ⟨y,l,hl,hn,hlen,ho⟩ - cases hl with - | nil => simp at hlen - | @cons x z y l e he tail => - refine Set.mem_iUnion.mpr ⟨⟨(e,z),he⟩, {e}, l.toFinset, ?_, ?_, ?_, ?_, ?_⟩ - · simpa using ho e (by simp) - · intro e' he'; exact ho e' (by simpa using Or.inr (List.mem_toFinset.mp he')) - · simpa using (List.nodup_cons.mp hn).1 - · simp - · exact ⟨y,l,tail,(List.nodup_cons.mp hn).2, by simpa using hlen, - fun e' he' => List.mem_toFinset.mpr he'⟩ - -theorem trailLength_probability_le [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (p : unitInterval) (x : V) (n : ℕ) : - (law p).real (TrailLength G x n) ≤ ((D : ℝ) * p) ^ n := by - induction n generalizing x with - | zero => simpa only [pow_zero] using (measureReal_le_one (μ := law p) (s := TrailLength G x 0)) - | succ n ih => - let : Fintype (Step G x) := (finite_steps G hloc x).fintype - let F := fun d : Step G x => - DisjointOccurrence {ω : Set E | d.val.1 ∈ ω} (TrailLength G d.val.2 n) - calc - (law p).real (TrailLength G x (n+1)) ≤ (law p).real (⋃ d, F d) := - measureReal_mono (trailLength_succ_subset G x n) - _ ≤ ∑ d, (law p).real (F d) := measureReal_iUnion_fintype_le _ - _ ≤ ∑ _d : Step G x, (p : ℝ) * ((D : ℝ) * p) ^ n := by - apply Finset.sum_le_sum - intro d _ - have hb := bk p {ω : Set E | d.val.1 ∈ ω} (TrailLength G d.val.2 n) - (fun _ _ hω he => hω he) (trailLength_upper G d.val.2 n) - (finiteWitness_edge _) (finiteWitness_trailLength G d.val.2 n) - have heq : (law p).real {ω : Set E | d.val.1 ∈ ω} = (p : ℝ) := by - simpa using finite_open_probability p {d.val.1} - rw [heq] at hb - exact hb.trans (mul_le_mul_of_nonneg_left (ih d.val.2) p.2.1) - _ ≤ (D : ℝ) * ((p : ℝ) * ((D : ℝ) * p) ^ n) := by - simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] - apply mul_le_mul_of_nonneg_right _ (mul_nonneg p.2.1 (pow_nonneg (mul_nonneg (Nat.cast_nonneg D) p.2.1) n)) - exact_mod_cast (show Fintype.card (Step G x) ≤ D by - simpa only [degree, Nat.card_eq_fintype_card] using hD x) - _ = ((D : ℝ) * p) ^ (n+1) := by ring - - theorem Along.mem_reachBall {G : BondGraph V E} {x y : V} {l : List E} - (h : Along G x l y) : y ∈ reachBall G x l.length := by - induction h with - | nil => exact Set.mem_singleton _ - | @cons x z y l e he ht ih => - have hadj : Adj G x z := ⟨e,he⟩ - have hstep : ∀ n, reachBall G z n ⊆ reachBall G x (n+1) := by - intro n - induction n with - | zero => - rintro w rfl - exact Or.inr (Set.mem_iUnion.mpr ⟨x, Set.mem_iUnion.mpr ⟨Set.mem_singleton _, hadj⟩⟩) - | succ n ih => - rintro w (hw | hw) - · exact Or.inl (ih hw) - · right - simp only [Set.mem_iUnion] at hw ⊢ - obtain ⟨v,hv,hvw⟩ := hw - exact ⟨v,ih hv,hvw⟩ - exact hstep _ ih - - theorem Along.take {G : BondGraph V E} {x y : V} {l : List E} - (h : Along G x l y) (n : ℕ) : ∃ z, Along G x (l.take n) z := by - induction h generalizing n with - | @nil z => exact ⟨z, by simpa using (Along.nil (G := G) z)⟩ - | @cons x z y l e he ht ih => - cases n with - | zero => exact ⟨x,.nil x⟩ - | succ n => - obtain ⟨v,hv⟩ := ih n - exact ⟨v,.cons e he hv⟩ - - theorem reachBall_mono (G : BondGraph V E) (x : V) : Monotone (reachBall G x) := by - apply monotone_nat_of_le_succ - intro n - exact Set.subset_union_left - - theorem infinite_cluster_subset_trailLength (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (n : ℕ) : {ω | (cluster G ω x).Infinite} ⊆ TrailLength G x n := by - intro ω hω - obtain ⟨y,hy,hyball⟩ := hω.exists_notMem_finite (finite_reachBall hloc x n) - obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G hy - have hlen : n ≤ l.length := by - by_contra h - exact hyball ((reachBall_mono G x (le_of_lt (Nat.lt_of_not_ge h))) hl.mem_reachBall) - obtain ⟨z,hz⟩ := hl.take n - exact ⟨z,l.take n,hz,hn.take,List.length_take_of_le hlen, - fun e he => ho e (List.mem_of_mem_take he)⟩ - - theorem infinite_cluster_probability_eq_zero_of_small [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (p : unitInterval) (hp : (D : ℝ) * p < 1) (x : V) : - law p {ω | (cluster G ω x).Infinite} = 0 := by - apply (measureReal_eq_zero_iff).mp - apply le_antisymm _ measureReal_nonneg - apply ge_of_tendsto (tendsto_pow_atTop_nhds_zero_of_lt_one (mul_nonneg (Nat.cast_nonneg D) p.2.1) hp) - filter_upwards [] with n - exact (measureReal_mono (infinite_cluster_subset_trailLength G hloc x n)).trans - (trailLength_probability_le G hloc D hD p x n) - - theorem exists_infinite_cluster_probability_eq_zero_of_small [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (p : unitInterval) (hp : (D : ℝ) * p < 1) : - law p {ω | (infiniteClusters G ω).Nonempty} = 0 := by - have heq : {ω | (infiniteClusters G ω).Nonempty} = - ⋃ x : V, {ω | (cluster G ω x).Infinite} := by - ext ω - simp only [Set.mem_ofPred_eq, infiniteClusters_nonempty_iff, Set.mem_iUnion] - rw [heq, measure_iUnion_null_iff] - exact infinite_cluster_probability_eq_zero_of_small G hloc D hD p hp - - theorem pc_pos [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) : - 0 < pc G := by - obtain ⟨D, hDpos, hD⟩ := exists_degree_bound G hqt - let t : unitInterval := ⟨1 / ((D : ℝ) + 1), by - constructor - · positivity - · apply (div_le_one (by positivity)).mpr - linarith [Nat.cast_nonneg (α := ℝ) D]⟩ - have ht : (0 : unitInterval) < t := by - change (0 : ℝ) < 1 / ((D : ℝ) + 1) - positivity - apply ht.trans_le - apply le_sInf - intro p hp - by_contra h - have hp' : (p : ℝ) < 1 / ((D : ℝ) + 1) := lt_of_not_ge h - have hsmall : (D : ℝ) * p < 1 := by - have hmul := (lt_div_iff₀ (show (0 : ℝ) < D + 1 by positivity)).mp hp' - nlinarith [p.2.1] - have hz := exists_infinite_cluster_probability_eq_zero_of_small G hloc D hD p hsmall - exact (ne_of_gt hp) hz - -end SmallParameter - -section MainBridge -attribute [local instance] Classical.propDecidable - - - -theorem mainConclusion_of_strict_gap [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hgap : pc G < ptwo G) : MainConclusion G := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - obtain ⟨q, hq, hpq⟩ := lt_sSup_iff.mp hgap - obtain ⟨p₂, hp₂, hp₂q⟩ := exists_between hpq - obtain ⟨p₁, hp₁, hp₁₂⟩ := exists_between hp₂ - have hc : OperatorBounded G (pc G) := operatorBounded_of_le G hpq.le hq - refine ⟨(operatorNorm_eq_sup_below G (pc G) (pc_pos G hloc hqt)).symm, - (operatorNorm_lt_top_iff G (pc G)).mpr hc, hgap, ptwo_le_pu G hconn hqt, ?_⟩ - refine ⟨p₁, p₂, hp₁, hp₁₂, hp₂q.trans_le (show q ≤ 1 from q.2.2), ?_⟩ - exact coupled_interval G hconn hloc hqt p₁ p₂ hp₁ - (operatorBounded_of_le G hp₂q.le hq) - -end MainBridge - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.Uniqueness + +namespace OAI + +/-! Bond paths, degree bounds and positivity of the critical parameter. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section BondPaths +attribute [local instance] Classical.propDecidable + + +inductive Along (G : BondGraph V E) : V → List E → V → Prop + | nil (x : V) : Along G x [] x + | cons {x z y : V} {l : List E} (e : E) (he : G e = s(x,z)) + (tail : Along G z l y) : Along G x (e :: l) y + + theorem Along.conn {G : BondGraph V E} {x y : V} {l : List E} (h : Along G x l y) + {ω : Set E} (ho : ∀ e ∈ l, e ∈ ω) : Conn G ω x y := by + induction h with + | nil => exact conn_refl G ω _ + | @cons x z y l e he ht ih => + exact (Relation.ReflTransGen.single ⟨e, ho e (by simp), he⟩).trans + (ih (fun e' he' => ho e' (by simp [he']))) + + def openSimpleGraph (G : BondGraph V E) (ω : Set E) : SimpleGraph V where + Adj x y := x ≠ y ∧ ∃ e ∈ ω, G e = s(x,y) + symm := ⟨by + rintro x y ⟨hxy, e, he, h⟩ + exact ⟨hxy.symm, e, he, h.trans (Sym2.eq_swap ..)⟩⟩ + loopless := ⟨by simp⟩ + + theorem conn_iff_reachable (G : BondGraph V E) (ω : Set E) (x y : V) : + Conn G ω x y ↔ (openSimpleGraph G ω).Reachable x y := by + constructor + · intro h + induction h with + | refl => exact ⟨.nil⟩ + | @tail z y h hy ih => + obtain ⟨w⟩ := ih + by_cases hzy : z = y + · subst y; exact ⟨w⟩ + · exact ⟨w.concat ⟨hzy, hy⟩⟩ + · rintro ⟨w⟩ + induction w with + | nil => exact conn_refl G ω _ + | @cons x z y hadj w ih => + exact (Relation.ReflTransGen.single hadj.2).trans ih + + theorem walk_lift_bonds (G : BondGraph V E) (ω : Set E) {x y : V} + (w : (openSimpleGraph G ω).Walk x y) : + ∃ l : List E, Along G x l y ∧ l.map G = w.edges ∧ ∀ e ∈ l, e ∈ ω := by + induction w with + | nil => exact ⟨[], .nil _, rfl, by simp⟩ + | @cons x z y hadj w ih => + obtain ⟨e, he, heq⟩ := hadj.2 + obtain ⟨l, hl, hmap, hopen⟩ := ih + refine ⟨e :: l, .cons e heq hl, ?_, ?_⟩ + · simp [hmap, heq] + · intro e' he' + rcases List.mem_cons.mp he' with rfl | he' + · exact he + · exact hopen e' he' + + + theorem conn_exists_bond_trail (G : BondGraph V E) {ω : Set E} {x y : V} + (h : Conn G ω x y) : + ∃ l : List E, Along G x l y ∧ l.Nodup ∧ ∀ e ∈ l, e ∈ ω := by + obtain ⟨w⟩ := (conn_iff_reachable G ω x y).mp h + obtain ⟨l, hl, hmap, hopen⟩ := walk_lift_bonds G ω (w.toPath : (openSimpleGraph G ω).Walk x y) + refine ⟨l, hl, ?_, hopen⟩ + apply List.Nodup.of_map (f := G) + rw [hmap] + exact w.toPath.property.isTrail.edges_nodup + + theorem Along.append {G : BondGraph V E} {x y z : V} {l k : List E} + (hl : Along G x l y) (hk : Along G y k z) : Along G x (l ++ k) z := by + induction hl with + | nil => exact hk + | cons e he ht ih => exact .cons e he (ih hk) + +end BondPaths + +section DegreeBound +attribute [local instance] Classical.propDecidable + + def Step (G : BondGraph V E) (x : V) := {ey : E × V // G ey.1 = s(x,ey.2)} + + theorem finite_steps (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + Set.Finite {ey : E × V | G ey.1 = s(x,ey.2)} := by + apply ((hloc x).prod (finite_neighbors hloc x)).subset + rintro ⟨e,y⟩ he + change G e = s(x,y) at he + exact ⟨by change x ∈ G e; rw [he]; simp, e, he⟩ + + noncomputable def stepEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (x : V) : Step G x ≃ Step G (a x) where + toFun d := ⟨(b d.val.1, a d.val.2), by rw [h, d.property, Sym2.map_mk]⟩ + invFun d := ⟨(b.symm d.val.1, a.symm d.val.2), by + rw [isAut_symm G h, d.property, Sym2.map_mk, Equiv.symm_apply_apply]⟩ + left_inv d := by apply Subtype.ext; exact Prod.ext (b.symm_apply_apply _) (a.symm_apply_apply _) + right_inv d := by apply Subtype.ext; exact Prod.ext (b.apply_symm_apply _) (a.apply_symm_apply _) + + noncomputable def degree (G : BondGraph V E) (x : V) : ℕ := Nat.card (Step G x) + + theorem degree_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (x : V) : degree G (a x) = degree G x := + (Nat.card_congr (stepEquiv G h x)).symm + + theorem exists_degree_bound (G : BondGraph V E) (hqt : QuasiTransitive G) : + ∃ D : ℕ, 0 < D ∧ ∀ x, degree G x ≤ D := by + obtain ⟨F, hF⟩ := hqt + refine ⟨(∑ x ∈ F, degree G x) + 1, Nat.zero_lt_succ _, ?_⟩ + intro x + obtain ⟨o, ho, a, b, hab, rfl⟩ := hF x + rw [degree_aut G hab] + exact (Finset.single_le_sum (fun _ _ => Nat.zero_le _) ho).trans (Nat.le_succ _) + +end DegreeBound + +section SmallParameter +attribute [local instance] Classical.propDecidable + +def TrailLength (G : BondGraph V E) (x : V) (n : ℕ) : Set (Set E) := + {ω | ∃ y l, Along G x l y ∧ l.Nodup ∧ l.length = n ∧ ∀ e ∈ l, e ∈ ω} + +theorem trailLength_upper (G : BondGraph V E) (x : V) (n : ℕ) : + IsUpperSet (TrailLength G x n) := by + rintro ω η h ⟨y,l,hl,hn,hlen,ho⟩ + exact ⟨y,l,hl,hn,hlen,fun e he => h (ho e he)⟩ + +theorem finiteWitness_trailLength (G : BondGraph V E) (x : V) (n : ℕ) : + FiniteWitness (TrailLength G x n) := by + rintro ω ⟨y,l,hl,hn,hlen,ho⟩ + exact ⟨l.toFinset, fun e he => ho e (List.mem_toFinset.mp he), + y,l,hl,hn,hlen, fun e he => List.mem_toFinset.mpr he⟩ + +theorem finiteWitness_edge (e : E) : FiniteWitness {ω : Set E | e ∈ ω} := by + intro ω he + exact ⟨{e}, by simpa using he, by simp⟩ + +theorem trailLength_succ_subset (G : BondGraph V E) (x : V) (n : ℕ) : + TrailLength G x (n+1) ⊆ ⋃ d : Step G x, + DisjointOccurrence {ω | d.val.1 ∈ ω} (TrailLength G d.val.2 n) := by + rintro ω ⟨y,l,hl,hn,hlen,ho⟩ + cases hl with + | nil => simp at hlen + | @cons x z y l e he tail => + refine Set.mem_iUnion.mpr ⟨⟨(e,z),he⟩, {e}, l.toFinset, ?_, ?_, ?_, ?_, ?_⟩ + · simpa using ho e (by simp) + · intro e' he'; exact ho e' (by simpa using Or.inr (List.mem_toFinset.mp he')) + · simpa using (List.nodup_cons.mp hn).1 + · simp + · exact ⟨y,l,tail,(List.nodup_cons.mp hn).2, by simpa using hlen, + fun e' he' => List.mem_toFinset.mpr he'⟩ + +theorem trailLength_probability_le [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (p : unitInterval) (x : V) (n : ℕ) : + (law p).real (TrailLength G x n) ≤ ((D : ℝ) * p) ^ n := by + induction n generalizing x with + | zero => simpa only [pow_zero] using (measureReal_le_one (μ := law p) (s := TrailLength G x 0)) + | succ n ih => + let : Fintype (Step G x) := (finite_steps G hloc x).fintype + let F := fun d : Step G x => + DisjointOccurrence {ω : Set E | d.val.1 ∈ ω} (TrailLength G d.val.2 n) + calc + (law p).real (TrailLength G x (n+1)) ≤ (law p).real (⋃ d, F d) := + measureReal_mono (trailLength_succ_subset G x n) + _ ≤ ∑ d, (law p).real (F d) := measureReal_iUnion_fintype_le _ + _ ≤ ∑ _d : Step G x, (p : ℝ) * ((D : ℝ) * p) ^ n := by + apply Finset.sum_le_sum + intro d _ + have hb := bk p {ω : Set E | d.val.1 ∈ ω} (TrailLength G d.val.2 n) + (fun _ _ hω he => hω he) (trailLength_upper G d.val.2 n) + (finiteWitness_edge _) (finiteWitness_trailLength G d.val.2 n) + have heq : (law p).real {ω : Set E | d.val.1 ∈ ω} = (p : ℝ) := by + simpa using finite_open_probability p {d.val.1} + rw [heq] at hb + exact hb.trans (mul_le_mul_of_nonneg_left (ih d.val.2) p.2.1) + _ ≤ (D : ℝ) * ((p : ℝ) * ((D : ℝ) * p) ^ n) := by + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + apply mul_le_mul_of_nonneg_right _ (mul_nonneg p.2.1 (pow_nonneg (mul_nonneg (Nat.cast_nonneg D) p.2.1) n)) + exact_mod_cast (show Fintype.card (Step G x) ≤ D by + simpa only [degree, Nat.card_eq_fintype_card] using hD x) + _ = ((D : ℝ) * p) ^ (n+1) := by ring + + theorem Along.mem_reachBall {G : BondGraph V E} {x y : V} {l : List E} + (h : Along G x l y) : y ∈ reachBall G x l.length := by + induction h with + | nil => exact Set.mem_singleton _ + | @cons x z y l e he ht ih => + have hadj : Adj G x z := ⟨e,he⟩ + have hstep : ∀ n, reachBall G z n ⊆ reachBall G x (n+1) := by + intro n + induction n with + | zero => + rintro w rfl + exact Or.inr (Set.mem_iUnion.mpr ⟨x, Set.mem_iUnion.mpr ⟨Set.mem_singleton _, hadj⟩⟩) + | succ n ih => + rintro w (hw | hw) + · exact Or.inl (ih hw) + · right + simp only [Set.mem_iUnion] at hw ⊢ + obtain ⟨v,hv,hvw⟩ := hw + exact ⟨v,ih hv,hvw⟩ + exact hstep _ ih + + theorem Along.take {G : BondGraph V E} {x y : V} {l : List E} + (h : Along G x l y) (n : ℕ) : ∃ z, Along G x (l.take n) z := by + induction h generalizing n with + | @nil z => exact ⟨z, by simpa using (Along.nil (G := G) z)⟩ + | @cons x z y l e he ht ih => + cases n with + | zero => exact ⟨x,.nil x⟩ + | succ n => + obtain ⟨v,hv⟩ := ih n + exact ⟨v,.cons e he hv⟩ + + theorem reachBall_mono (G : BondGraph V E) (x : V) : Monotone (reachBall G x) := by + apply monotone_nat_of_le_succ + intro n + exact Set.subset_union_left + + theorem infinite_cluster_subset_trailLength (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (n : ℕ) : {ω | (cluster G ω x).Infinite} ⊆ TrailLength G x n := by + intro ω hω + obtain ⟨y,hy,hyball⟩ := hω.exists_notMem_finite (finite_reachBall hloc x n) + obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G hy + have hlen : n ≤ l.length := by + by_contra h + exact hyball ((reachBall_mono G x (le_of_lt (Nat.lt_of_not_ge h))) hl.mem_reachBall) + obtain ⟨z,hz⟩ := hl.take n + exact ⟨z,l.take n,hz,hn.take,List.length_take_of_le hlen, + fun e he => ho e (List.mem_of_mem_take he)⟩ + + theorem infinite_cluster_probability_eq_zero_of_small [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (p : unitInterval) (hp : (D : ℝ) * p < 1) (x : V) : + law p {ω | (cluster G ω x).Infinite} = 0 := by + apply (measureReal_eq_zero_iff).mp + apply le_antisymm _ measureReal_nonneg + apply ge_of_tendsto (tendsto_pow_atTop_nhds_zero_of_lt_one (mul_nonneg (Nat.cast_nonneg D) p.2.1) hp) + filter_upwards [] with n + exact (measureReal_mono (infinite_cluster_subset_trailLength G hloc x n)).trans + (trailLength_probability_le G hloc D hD p x n) + + theorem exists_infinite_cluster_probability_eq_zero_of_small [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (p : unitInterval) (hp : (D : ℝ) * p < 1) : + law p {ω | (infiniteClusters G ω).Nonempty} = 0 := by + have heq : {ω | (infiniteClusters G ω).Nonempty} = + ⋃ x : V, {ω | (cluster G ω x).Infinite} := by + ext ω + simp only [Set.mem_ofPred_eq, infiniteClusters_nonempty_iff, Set.mem_iUnion] + rw [heq, measure_iUnion_null_iff] + exact infinite_cluster_probability_eq_zero_of_small G hloc D hD p hp + + theorem pc_pos [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) : + 0 < pc G := by + obtain ⟨D, hDpos, hD⟩ := exists_degree_bound G hqt + let t : unitInterval := ⟨1 / ((D : ℝ) + 1), by + constructor + · positivity + · apply (div_le_one (by positivity)).mpr + linarith [Nat.cast_nonneg (α := ℝ) D]⟩ + have ht : (0 : unitInterval) < t := by + change (0 : ℝ) < 1 / ((D : ℝ) + 1) + positivity + apply ht.trans_le + apply le_sInf + intro p hp + by_contra h + have hp' : (p : ℝ) < 1 / ((D : ℝ) + 1) := lt_of_not_ge h + have hsmall : (D : ℝ) * p < 1 := by + have hmul := (lt_div_iff₀ (show (0 : ℝ) < D + 1 by positivity)).mp hp' + nlinarith [p.2.1] + have hz := exists_infinite_cluster_probability_eq_zero_of_small G hloc D hD p hsmall + exact (ne_of_gt hp) hz + +end SmallParameter + +section MainBridge +attribute [local instance] Classical.propDecidable + + + +theorem mainConclusion_of_strict_gap [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hgap : pc G < ptwo G) : MainConclusion G := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + obtain ⟨q, hq, hpq⟩ := lt_sSup_iff.mp hgap + obtain ⟨p₂, hp₂, hp₂q⟩ := exists_between hpq + obtain ⟨p₁, hp₁, hp₁₂⟩ := exists_between hp₂ + have hc : OperatorBounded G (pc G) := operatorBounded_of_le G hpq.le hq + refine ⟨(operatorNorm_eq_sup_below G (pc G) (pc_pos G hloc hqt)).symm, + (operatorNorm_lt_top_iff G (pc G)).mpr hc, hgap, ptwo_le_pu G hconn hqt, ?_⟩ + refine ⟨p₁, p₂, hp₁, hp₁₂, hp₂q.trans_le (show q ≤ 1 from q.2.2), ?_⟩ + exact coupled_interval G hconn hloc hqt p₁ p₂ hp₁ + (operatorBounded_of_le G hp₂q.le hq) + +end MainBridge + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Graph/Topology.lean b/lean/OAI/Probability/UnimodularPercolation/Graph/Topology.lean index 0ad89d50b4f4dad7dd5934b5ae1ce8fd63aa4dae..09d91fcafddd5a20f8a94f496cf5662ebc6c3e8e 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Graph/Topology.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Graph/Topology.lean @@ -1,140 +1,140 @@ -import Mathlib - -namespace OAI - -/-! Pointwise topology on permutation groups. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -namespace PointwisePerm -open Topology Set -universe u -variable {X : Type u} [TopologicalSpace X] [DiscreteTopology X] - - -def coordinates (g : Equiv.Perm X) : (X → X) × (X → X) := (g, g.symm) - -instance topology : TopologicalSpace (Equiv.Perm X) := - TopologicalSpace.induced coordinates inferInstance - -omit [DiscreteTopology X] in -theorem isEmbedding_coordinates : Topology.IsEmbedding (coordinates (X := X)) := by - refine ⟨⟨rfl⟩, ?_⟩ - intro g h he - exact Equiv.ext (congrFun (congrArg Prod.fst he)) - -omit [DiscreteTopology X] in -theorem continuous_apply (x : X) : Continuous (fun g : Equiv.Perm X => g x) := - (_root_.continuous_apply x).comp (continuous_fst.comp isEmbedding_coordinates.continuous) - -omit [DiscreteTopology X] in -theorem continuous_symm_apply (x : X) : Continuous (fun g : Equiv.Perm X => g.symm x) := - (_root_.continuous_apply x).comp (continuous_snd.comp isEmbedding_coordinates.continuous) - -theorem continuous_eval : Continuous (fun p : (X → X) × X => p.1 p.2) := - continuous_prod_of_discrete_right.mpr fun x => _root_.continuous_apply x - -instance topologicalGroup : IsTopologicalGroup (Equiv.Perm X) where - continuous_mul := by - apply continuous_induced_rng.mpr - apply Continuous.prodMk - · apply continuous_pi - intro x - exact (continuous_eval (X := X)).comp - ((continuous_fst.comp (isEmbedding_coordinates.continuous.comp continuous_fst)).prodMk - ((continuous_apply x).comp continuous_snd)) - · apply continuous_pi - intro x - exact (continuous_eval (X := X)).comp - ((continuous_snd.comp (isEmbedding_coordinates.continuous.comp continuous_snd)).prodMk - ((continuous_symm_apply x).comp continuous_fst)) - continuous_inv := by - apply continuous_induced_rng.mpr - exact (continuous_snd.comp isEmbedding_coordinates.continuous).prodMk - (continuous_fst.comp isEmbedding_coordinates.continuous) - -instance hausdorff : T2Space (Equiv.Perm X) := - isEmbedding_coordinates.t2Space - -instance secondCountable [Countable X] : SecondCountableTopology (Equiv.Perm X) := - isEmbedding_coordinates.secondCountableTopology - - - -theorem topology_eq_pointwise : topology (X := X) = - TopologicalSpace.induced (fun g : Equiv.Perm X => (g : X → X)) inferInstance := by - apply le_antisymm - · exact continuous_iff_le_induced.mp - (continuous_fst.comp isEmbedding_coordinates.continuous) - · let t : TopologicalSpace (Equiv.Perm X) := - TopologicalSpace.induced (fun g : Equiv.Perm X => (g : X → X)) inferInstance - have hc : @Continuous (Equiv.Perm X) ((X → X) × (X → X)) t _ coordinates := by - let := t - have hf : Continuous (fun g : Equiv.Perm X => (g : X → X)) := continuous_induced_dom - have hi : Continuous (fun g : Equiv.Perm X => (g.symm : X → X)) := by - apply continuous_pi - intro x - apply continuous_discrete_rng.mpr - intro y - have he : (fun g : Equiv.Perm X => g.symm x) ⁻¹' {y} = - (fun g : Equiv.Perm X => g y) ⁻¹' {x} := by - ext g - simp only [Set.mem_preimage,Set.mem_singleton_iff] - exact (Equiv.symm_apply_eq g).trans eq_comm - rw [he] - exact (isOpen_discrete _).preimage ((_root_.continuous_apply y).comp hf) - exact hf.prodMk hi - exact continuous_iff_le_induced.mp hc - - -omit [TopologicalSpace X] [DiscreteTopology X] in -theorem range_coordinates : Set.range (coordinates (X := X)) = - {p | (∀ x, p.1 (p.2 x) = x) ∧ (∀ x, p.2 (p.1 x) = x)} := by - ext p - constructor - · rintro ⟨g,rfl⟩ - exact ⟨g.apply_symm_apply, g.symm_apply_apply⟩ - · rintro ⟨hfg,hgf⟩ - exact ⟨⟨p.1,p.2,hgf,hfg⟩,rfl⟩ - -theorem isClosed_range_coordinates : IsClosed (Set.range (coordinates (X := X))) := by - rw [range_coordinates] - have hf (x : X) : IsClosed {p : (X → X) × (X → X) | p.1 (p.2 x) = x} := - isClosed_eq - ((continuous_eval (X := X)).comp (continuous_fst.prodMk ((_root_.continuous_apply x).comp continuous_snd))) - continuous_const - have hg (x : X) : IsClosed {p : (X → X) × (X → X) | p.2 (p.1 x) = x} := - isClosed_eq - ((continuous_eval (X := X)).comp (continuous_snd.prodMk ((_root_.continuous_apply x).comp continuous_fst))) - continuous_const - convert (isClosed_iInter hf).inter (isClosed_iInter hg) using 1 - ext p - simp only [Set.mem_inter_iff, Set.mem_iInter, Set.mem_ofPred_eq] - - - -theorem isCompact_of_finite_images (S : Set (Equiv.Perm X)) (hS : IsClosed S) - (hf : ∀ x, ((fun g : Equiv.Perm X => g x) '' S).Finite) - (hg : ∀ x, ((fun g : Equiv.Perm X => g.symm x) '' S).Finite) : - IsCompact S := by - have he : Topology.IsClosedEmbedding (coordinates (X := X)) := - ⟨isEmbedding_coordinates, isClosed_range_coordinates⟩ - apply he.isEmbedding.isCompact_iff.mpr - apply ((isCompact_pi_infinite fun x => (hf x).isCompact).prod - (isCompact_pi_infinite fun x => (hg x).isCompact)).of_isClosed_subset - (he.isClosedMap S hS) - rintro _ ⟨g,hgS,rfl⟩ - exact ⟨fun x => ⟨g,hgS,rfl⟩, fun x => ⟨g,hgS,rfl⟩⟩ - -theorem isOpen_fixed (x y : X) : IsOpen {g : Equiv.Perm X | g x = y} := - (isOpen_discrete ({y} : Set X)).preimage (continuous_apply x) - -theorem isClosed_fixed (x y : X) : IsClosed {g : Equiv.Perm X | g x = y} := - isClosed_eq (continuous_apply x) continuous_const - -end PointwisePerm -end Percolation - -end OAI +import Mathlib + +namespace OAI + +/-! Pointwise topology on permutation groups. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +namespace PointwisePerm +open Topology Set +universe u +variable {X : Type u} [TopologicalSpace X] [DiscreteTopology X] + + +def coordinates (g : Equiv.Perm X) : (X → X) × (X → X) := (g, g.symm) + +instance topology : TopologicalSpace (Equiv.Perm X) := + TopologicalSpace.induced coordinates inferInstance + +omit [DiscreteTopology X] in +theorem isEmbedding_coordinates : Topology.IsEmbedding (coordinates (X := X)) := by + refine ⟨⟨rfl⟩, ?_⟩ + intro g h he + exact Equiv.ext (congrFun (congrArg Prod.fst he)) + +omit [DiscreteTopology X] in +theorem continuous_apply (x : X) : Continuous (fun g : Equiv.Perm X => g x) := + (_root_.continuous_apply x).comp (continuous_fst.comp isEmbedding_coordinates.continuous) + +omit [DiscreteTopology X] in +theorem continuous_symm_apply (x : X) : Continuous (fun g : Equiv.Perm X => g.symm x) := + (_root_.continuous_apply x).comp (continuous_snd.comp isEmbedding_coordinates.continuous) + +theorem continuous_eval : Continuous (fun p : (X → X) × X => p.1 p.2) := + continuous_prod_of_discrete_right.mpr fun x => _root_.continuous_apply x + +instance topologicalGroup : IsTopologicalGroup (Equiv.Perm X) where + continuous_mul := by + apply continuous_induced_rng.mpr + apply Continuous.prodMk + · apply continuous_pi + intro x + exact (continuous_eval (X := X)).comp + ((continuous_fst.comp (isEmbedding_coordinates.continuous.comp continuous_fst)).prodMk + ((continuous_apply x).comp continuous_snd)) + · apply continuous_pi + intro x + exact (continuous_eval (X := X)).comp + ((continuous_snd.comp (isEmbedding_coordinates.continuous.comp continuous_snd)).prodMk + ((continuous_symm_apply x).comp continuous_fst)) + continuous_inv := by + apply continuous_induced_rng.mpr + exact (continuous_snd.comp isEmbedding_coordinates.continuous).prodMk + (continuous_fst.comp isEmbedding_coordinates.continuous) + +instance hausdorff : T2Space (Equiv.Perm X) := + isEmbedding_coordinates.t2Space + +instance secondCountable [Countable X] : SecondCountableTopology (Equiv.Perm X) := + isEmbedding_coordinates.secondCountableTopology + + + +theorem topology_eq_pointwise : topology (X := X) = + TopologicalSpace.induced (fun g : Equiv.Perm X => (g : X → X)) inferInstance := by + apply le_antisymm + · exact continuous_iff_le_induced.mp + (continuous_fst.comp isEmbedding_coordinates.continuous) + · let t : TopologicalSpace (Equiv.Perm X) := + TopologicalSpace.induced (fun g : Equiv.Perm X => (g : X → X)) inferInstance + have hc : @Continuous (Equiv.Perm X) ((X → X) × (X → X)) t _ coordinates := by + let := t + have hf : Continuous (fun g : Equiv.Perm X => (g : X → X)) := continuous_induced_dom + have hi : Continuous (fun g : Equiv.Perm X => (g.symm : X → X)) := by + apply continuous_pi + intro x + apply continuous_discrete_rng.mpr + intro y + have he : (fun g : Equiv.Perm X => g.symm x) ⁻¹' {y} = + (fun g : Equiv.Perm X => g y) ⁻¹' {x} := by + ext g + simp only [Set.mem_preimage,Set.mem_singleton_iff] + exact (Equiv.symm_apply_eq g).trans eq_comm + rw [he] + exact (isOpen_discrete _).preimage ((_root_.continuous_apply y).comp hf) + exact hf.prodMk hi + exact continuous_iff_le_induced.mp hc + + +omit [TopologicalSpace X] [DiscreteTopology X] in +theorem range_coordinates : Set.range (coordinates (X := X)) = + {p | (∀ x, p.1 (p.2 x) = x) ∧ (∀ x, p.2 (p.1 x) = x)} := by + ext p + constructor + · rintro ⟨g,rfl⟩ + exact ⟨g.apply_symm_apply, g.symm_apply_apply⟩ + · rintro ⟨hfg,hgf⟩ + exact ⟨⟨p.1,p.2,hgf,hfg⟩,rfl⟩ + +theorem isClosed_range_coordinates : IsClosed (Set.range (coordinates (X := X))) := by + rw [range_coordinates] + have hf (x : X) : IsClosed {p : (X → X) × (X → X) | p.1 (p.2 x) = x} := + isClosed_eq + ((continuous_eval (X := X)).comp (continuous_fst.prodMk ((_root_.continuous_apply x).comp continuous_snd))) + continuous_const + have hg (x : X) : IsClosed {p : (X → X) × (X → X) | p.2 (p.1 x) = x} := + isClosed_eq + ((continuous_eval (X := X)).comp (continuous_snd.prodMk ((_root_.continuous_apply x).comp continuous_fst))) + continuous_const + convert (isClosed_iInter hf).inter (isClosed_iInter hg) using 1 + ext p + simp only [Set.mem_inter_iff, Set.mem_iInter, Set.mem_ofPred_eq] + + + +theorem isCompact_of_finite_images (S : Set (Equiv.Perm X)) (hS : IsClosed S) + (hf : ∀ x, ((fun g : Equiv.Perm X => g x) '' S).Finite) + (hg : ∀ x, ((fun g : Equiv.Perm X => g.symm x) '' S).Finite) : + IsCompact S := by + have he : Topology.IsClosedEmbedding (coordinates (X := X)) := + ⟨isEmbedding_coordinates, isClosed_range_coordinates⟩ + apply he.isEmbedding.isCompact_iff.mpr + apply ((isCompact_pi_infinite fun x => (hf x).isCompact).prod + (isCompact_pi_infinite fun x => (hg x).isCompact)).of_isClosed_subset + (he.isClosedMap S hS) + rintro _ ⟨g,hgS,rfl⟩ + exact ⟨fun x => ⟨g,hgS,rfl⟩, fun x => ⟨g,hgS,rfl⟩⟩ + +theorem isOpen_fixed (x y : X) : IsOpen {g : Equiv.Perm X | g x = y} := + (isOpen_discrete ({y} : Set X)).preimage (continuous_apply x) + +theorem isClosed_fixed (x y : X) : IsClosed {g : Equiv.Perm X | g x = y} := + isClosed_eq (continuous_apply x) continuous_const + +end PointwisePerm +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Amplification.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Amplification.lean index 6b5e8d89ac7c17e6cf2308050917e099a6ec75ad..1e7f20f32c87085c3d9cd3c99c7a4bdd2f543c90 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Amplification.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Amplification.lean @@ -1,1240 +1,1240 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Transport.EndpointKernels - -namespace OAI - -/-! Amplification for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AmplificationMarginal -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def restrictFiniteField (Q : Finset E) (ω : Set E) : FiniteField Q := - ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ - -@[simp] theorem finiteFieldSet_restrict (Q : Finset E) (ω : Set E) : - finiteFieldSet Q (restrictFiniteField Q ω) = ω ∩ (Q : Set E) := by - ext e - simp [restrictFiniteField,domainBits,finiteFieldSet,and_comm] - -@[simp] theorem restrictFiniteField_fieldSet (Q : Finset E) (ω : FiniteField Q) : - restrictFiniteField Q (finiteFieldSet Q ω) = ω := by - apply Subtype.ext - exact domainBits_finiteFieldSet Q ω - -theorem cluster_restrict_of_cap (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (ω : Set E) (x : V) (C : ℕ) - (hQ : incidentSupport G hloc (finite_reachBall hloc x C).toFinset ⊆ Q) - (hf : (cluster G (ω ∩ (Q : Set E)) x).Finite) - (hC : (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ C) : - cluster G (ω ∩ (Q : Set E)) x = cluster G ω x := by - apply Set.Subset.antisymm - · exact fun _ h => conn_mono G Set.inter_subset_left h - · intro y hy - induction hy with - | refl => exact conn_refl G _ x - | @tail a b _ hab ih => - obtain ⟨e,he,hab⟩ := hab - have ha := finite_cluster_subset_reachBall G (ω ∩ (Q : Set E)) x hf C hC ih - have heQ := hQ ((mem_incidentSupport G hloc _ e).mpr - ⟨a,by simpa only [Set.Finite.mem_toFinset] using ha,by simp [hab]⟩) - exact ih.tail ⟨e,⟨he,heQ⟩,hab⟩ - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -noncomputable def amplificationMarginal (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : ℝ := - finiteRootLoad Q (Finset.Icc 1 k) p - (finiteChoiceForwardLoad G x k Q (q.amplificationInputs Q B x k n z) - (fun r _ => amplificationVertices B k z r) (q.amplificationWeight B k z)) (restrictFiniteField Q ω) - -theorem amplificationMarginal_local (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : - q.amplificationMarginal Q B x k n z p ω = - q.amplificationMarginal Q B x k n z p (ω ∩ (Q : Set E)) := by - unfold amplificationMarginal - congr 1 - apply (finiteFieldSet_injective Q) - simp only [finiteFieldSet_restrict,Set.inter_assoc,Set.inter_self] - -theorem amplificationMarginal_bounds (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : - 0 ≤ q.amplificationMarginal Q B x k n z p ω ∧ - q.amplificationMarginal Q B x k n z p ω ≤ inverseCodeMass M L ^ k := by - have hb := finiteChoiceForwardLoad_bounds G hloc x z.val k M L hL Q - (q.amplificationInputs Q B x k n z) (fun r _ => amplificationVertices B k z r) - (q.amplificationWeight B k z) (q.amplificationWeight_nonneg B k z) - (q.amplificationWeight_row B k z) (q.amplificationInputs_subset Q B x k n z) - (fun _ _ _ => congrArg Subtype.val (oldRunVertices_last ..)) - (fun r s hs i hi hik => (q.amplificationInputs_chain Q B x k n z r s hs i hi hik).2) - exact ⟨finiteRootLoad_nonneg _ _ p _ (fun s _ => (hb s).1) _, - finiteRootLoad_le _ _ p _ _ (fun s _ => (hb s).2) _⟩ - -theorem amplificationMarginal_support (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) - (h : q.amplificationMarginal Q B x k n z p ω ≠ 0) : - x ∈ O ∧ z.val ∈ O ∧ Conn G (ω ∩ (Q : Set E)) x z.val ∧ - (cluster G (ω ∩ (Q : Set E)) x).Finite ∧ - (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ 2*n+k*M := by - let A := q.amplificationInputs Q B x k n z - let y := fun r (_ : SpliceState E) => amplificationVertices B k z r - let I := FiniteChoiceTraceIndex G x k Q A y - let out := choiceTraceOutput G x k Q A y - have ho (a : I) : out a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := - traceIndexOutput_mem G x k Q (A a.1) (y a.1) (q.amplificationInputs_subset Q B x k n z a.1) a.2 - have he := finiteRootLoad_eq_sum Q (Finset.Icc 1 k) p out - (choiceTraceMass G x k Q A y (q.amplificationWeight B k z)) ho (restrictFiniteField Q ω) - have ha : ∃ a : I, (out a).1 = ω ∩ (Q : Set E) := by - by_contra hn - push Not at hn - apply h - change finiteRootLoad Q (Finset.Icc 1 k) p (finiteInverseLoad out _) _ = 0 - rw [he,finiteFieldSet_restrict] - simp only [hn,ite_false,Finset.sum_const_zero] - obtain ⟨a,ha⟩ := ha - have ht := (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1 - have hs := q.amplificationTrace_support Q B x k n z a.1 a.2.1.val a.2.1.property - (choiceTraceCode G x k Q A y a) (out a).1 ht - rwa [ha] at hs - -theorem amplificationMarginal_physical_support (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) - (hQ : incidentSupport G hloc (finite_reachBall hloc x (2*n+k*M)).toFinset ⊆ Q) - (h : q.amplificationMarginal Q B x k n z p ω ≠ 0) : - x ∈ O ∧ z.val ∈ O ∧ Conn G ω x z.val ∧ (cluster G ω x).Finite ∧ - (cluster G ω x).ncard ≤ 2*n+k*M := by - obtain ⟨hx,hz,hc,hf,hcap⟩ := q.amplificationMarginal_support Q B x k n z p ω h - have he := cluster_restrict_of_cap G hloc Q ω x (2*n+k*M) hQ hf hcap - exact ⟨hx,hz,conn_mono G Set.inter_subset_left hc,he ▸ hf,he ▸ hcap⟩ - - - -theorem amplificationMarginal_mean [Nonempty E] (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) : - (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = - ∑ r, ∑ s ∈ q.amplificationInputs Q B x k n z r, - spliceTupleWeight Q (Finset.Icc 1 k) p s * q.amplificationWeight B k z s r := by - rw [integral_finite_local Q p _ (q.amplificationMarginal_local Q B x k n z p)] - simp only [amplificationMarginal,restrictFiniteField_fieldSet] - rw [finiteRootLoad_mean] - apply finiteChoiceForwardLoad_mean G hloc x k M Q p - · exact q.amplificationInputs_subset Q B x k n z - · intro r s hs - exact ((q.mem_amplificationInputs Q B x k n z r s).mp hs).2.2.2.2.2.1 - · intro r s hs i hi - exact (q.amplificationInputs_chain Q B x k n z r s hs i - (Finset.mem_Icc.mp hi).1 (Finset.mem_Icc.mp hi).2).1 - · intro r s hs i hi - have hc := q.amplificationInputs_chain Q B x k n z r s hs i - (Finset.mem_Icc.mp hi).1 (Finset.mem_Icc.mp hi).2 - exact ⟨hc.2.1,hc.2.2.1⟩ - -end LocalEndpointRule -end AmplificationMarginal - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AmplificationMeanKernel -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finiteSpliceDomain_integral_factor (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (f : Set E → ℝ) (g : (ℕ → Set E) → ℝ) : - (∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s * f s.1 * g s.2) = - finiteFieldIntegral Q p f * finiteFamilyIntegral Q J p g := by - have hh := finiteRootLoad_mean Q J p (fun s => f s.1 * g s.2) - simp only [← mul_assoc] at hh - rw [← hh] - simp only [finiteRootLoad,finiteFieldIntegral,finiteFamilyIntegral,Finset.sum_mul] - apply Finset.sum_congr rfl - intro ω _ - simp only [Finset.mul_sum] - apply Finset.sum_congr rfl - intro η _ - ring - - -noncomputable def finiteBinConnection (G : BondGraph V E) (Q : Finset E) (p : ℝ) - (x : V) (n : ℕ) (y : V) : ℝ := finiteFieldIntegral Q p (fun ω => - if n ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < 2*n ∧ y ∈ cluster G ω x then 1 else 0) - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -theorem finiteOldKernel_eq_kernel (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (p : unitInterval) (a b : V) - (hQ : incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : - finiteOldKernel Q p q.mass a b = q.kernel p a b := by - symm - exact integral_finite_local Q p _ (finite_local_of_subset _ Q hQ _ (q.locality · a b)) - - - -theorem amplificationMarginal_mean_kernel [Nonempty E] (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) - (hx : x ∈ O) (hz : z.val ∈ O) - (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : - (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = - ∑ r : Fin k → ↥B, finiteBinConnection G Q p x n (amplificationVertices B k z r 0) * - oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r := by - rw [q.amplificationMarginal_mean Q B x k n z p] - apply Finset.sum_congr rfl - intro r _ - let f : Set E → ℝ := fun ω => if n ≤ (cluster G ω x).ncard ∧ - (cluster G ω x).ncard < 2*n ∧ amplificationVertices B k z r 0 ∈ cluster G ω x then 1 else 0 - let g : (ℕ → Set E) → ℝ := fun η => - oldRunWeight (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z r - have he : (∑ s ∈ q.amplificationInputs Q B x k n z r, - spliceTupleWeight Q (Finset.Icc 1 k) p s * q.amplificationWeight B k z s r) = - ∑ s ∈ finiteSpliceDomain Q (Finset.Icc 1 k), spliceTupleWeight Q (Finset.Icc 1 k) p s * f s.1 * g s.2 := by - rw [amplificationInputs,Finset.sum_filter] - apply Finset.sum_congr rfl - intro s _ - change (if _ then _ else _) = _ - by_cases hw : q.amplificationWeight B k z s r = 0 - · have hg : g s.2 = 0 := hw - simp [hx,hz,hw,hg] - · simp only [hx,hz,true_and,hw,ne_eq,not_false_eq_true,and_true] - by_cases hbin : n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ - amplificationVertices B k z r 0 ∈ cluster G s.1 x - · simp [f,hbin,g,amplificationWeight] - · simp only [hbin,ite_false,f,mul_zero,zero_mul] - rw [he,finiteSpliceDomain_integral_factor] - dsimp only [g] - rw [oldRunWeight_integral Q p k (fun ω (a b : ↥B) => q.mass ω a.val b.val) z r] - change finiteBinConnection G Q p x n _ * _ = _ - congr 1 - apply congrArg (fun K : ℕ → ↥B → ↥B → ℝ => oldRunWeight K k z r) - funext i a b - exact q.finiteOldKernel_eq_kernel Q p a.val b.val (hQ a.val a.property) - -end LocalEndpointRule -end AmplificationMeanKernel - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section BinConnection -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def binConnectionMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : ℝ := - if (cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ - (cluster G ω x).ncard < 2*n ∧ Conn G ω x y then 1 else 0 - -theorem binConnectionMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : - 0 ≤ binConnectionMass G n ω x y := by unfold binConnectionMass; split_ifs <;> norm_num - -theorem binConnectionMass_symm (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : - binConnectionMass G n ω x y = binConnectionMass G n ω y x := by - by_cases hc : Conn G ω x y - · have he := cluster_eq_of_conn G ω hc - simp only [binConnectionMass,hc,conn_symm G ω hc,and_true,he] - · have hc' : ¬Conn G ω y x := fun h => hc (conn_symm G ω h) - simp only [binConnectionMass,hc,hc',and_false,ite_false] - -theorem binConnectionMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (ω : Set E) (x y : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binConnectionMass G n ω x y = binConnectionMass G n (ω ∩ (Q : Set E)) x y := by - dsimp only - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - have hp : ((cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ - (cluster G ω x).ncard < 2*n ∧ Conn G ω x y) ↔ - ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ n ≤ (cluster G (ω ∩ (Q : Set E)) x).ncard ∧ - (cluster G (ω ∩ (Q : Set E)) x).ncard < 2*n ∧ Conn G (ω ∩ (Q : Set E)) x y) := by - constructor - · rintro ⟨hf,hn,hN,hc⟩ - have hs : cluster G ω x ⊆ (finite_reachBall hloc x (2*n)).toFinset := by - simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hf (2*n) hN.le - have he := cluster_restrict_incident_of_full G hloc _ ω x hs - change cluster G (ω ∩ (Q : Set E)) x = cluster G ω x at he - refine ⟨he.symm ▸ hf,he.symm ▸ hn,he.symm ▸ hN,?_⟩ - change y ∈ cluster G (ω ∩ (Q : Set E)) x - rw [he] - exact hc - · rintro ⟨hf,hn,hN,hc⟩ - have he := cluster_restrict_of_cap G hloc Q ω x (2*n) (Finset.Subset.refl _) hf hN.le - exact ⟨he ▸ hf,he ▸ hn,he ▸ hN,conn_mono G Set.inter_subset_left hc⟩ - exact if_congr hp rfl rfl - -theorem binConnectionMass_support (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (h : binConnectionMass G n ω x y ≠ 0) : - (cluster G ω x).Finite ∧ (cluster G ω x).ncard < 2*n ∧ Conn G ω x y := by - unfold binConnectionMass at h - split_ifs at h with hp - · exact ⟨hp.1,hp.2.2.1,hp.2.2.2⟩ - · exact (h rfl).elim - -theorem binConnectionMass_outside (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (hy : y ∉ reachBall G x (2*n)) : binConnectionMass G n ω x y = 0 := by - by_contra h - obtain ⟨hf,hN,hc⟩ := binConnectionMass_support G n ω x y h - exact hy (finite_cluster_subset_reachBall G ω x hf (2*n) hN.le hc) - -theorem binConnectionMass_row (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : - (∑' y, binConnectionMass G n ω x y) ≤ 2*n := by - by_cases hb : (cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < 2*n - · have hs : (∑' y, binConnectionMass G n ω x y) = (cluster G ω x).ncard := by - rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by - have hc : ¬Conn G ω x y := fun h => hy (hb.1.mem_toFinset.mpr h) - simp only [binConnectionMass,hc,and_false,ite_false])] - have he : (∑ y ∈ hb.1.toFinset, binConnectionMass G n ω x y) = - ∑ _y ∈ hb.1.toFinset, (1 : ℝ) := by - apply Finset.sum_congr rfl - intro y hy - exact ite_eq_left ⟨hb.1,hb.2.1,hb.2.2,hb.1.mem_toFinset.mp hy⟩ - rw [he] - simp only [Finset.sum_const,nsmul_eq_mul,mul_one] - exact_mod_cast (Set.ncard_eq_toFinset_card _ hb.1).symm - rw [hs] - exact_mod_cast hb.2.2.le - · have hz (y : V) : binConnectionMass G n ω x y = 0 := by - apply ite_eq_right - exact fun h => hb ⟨h.1,h.2.1,h.2.2.1⟩ - simp only [hz,tsum_zero] - positivity - -noncomputable def binConnection (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : ℝ := - ∫ ω, binConnectionMass G n ω x y ∂law p - -theorem binConnection_nonneg (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : - 0 ≤ binConnection G p n x y := integral_nonneg fun ω => binConnectionMass_nonneg G n ω x y - -theorem binConnection_symm (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : - binConnection G p n x y = binConnection G p n y x := - integral_congr_ae (ae_of_all _ fun ω => binConnectionMass_symm G n ω x y) - -theorem binConnection_outside (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) - (hy : y ∉ reachBall G x (2*n)) : binConnection G p n x y = 0 := by - simp only [binConnection,fun ω => binConnectionMass_outside G n ω x y hy,integral_zero] - -theorem binConnection_row (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) (x : V) : (∑' y, binConnection G p n x y) ≤ 2*n := by - let B := (finite_reachBall hloc x (2*n)).toFinset - let Q := incidentSupport G hloc B - have hi (y : V) : Integrable (fun ω => binConnectionMass G n ω x y) (law p) := - integrable_finite_local Q p _ (fun ω => binConnectionMass_local G hloc n ω x y) - have he (ω : Set E) : (∑' y, binConnectionMass G n ω x y) = ∑ y ∈ B, binConnectionMass G n ω x y := - tsum_eq_sum fun y hy => binConnectionMass_outside G n ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - have hs : (∑' y, binConnection G p n x y) = ∑ y ∈ B, binConnection G p n x y := - tsum_eq_sum fun y hy => binConnection_outside G p n x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - rw [hs] - simp only [binConnection] - rw [← integral_finsetSum B (fun y _ => hi y)] - calc - _ ≤ ∫ _ω, (2*n : ℝ) ∂law p := integral_mono (integrable_finsetSum B (fun y _ => hi y)) - (integrable_const _) (fun ω => (he ω).symm ▸ binConnectionMass_row G n ω x) - _ = 2*n := by simp - - - -theorem exists_binConnection_operator (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ 2*n ∧ - ∀ x y, A (lp.single 2 y (1:ℂ)) x = (binConnection G p n x y : ℂ) := by - have hs (x : V) : Summable (binConnection G p n x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) - intro y hy - exact binConnection_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) - have hr (x : V) (S : Finset V) : (∑ y ∈ S, binConnection G p n x y) ≤ 2*n := - ((hs x).sum_le_tsum S (fun y _ => binConnection_nonneg G p n x y)).trans (binConnection_row G hloc p n x) - apply exists_operator_of_row_column_bound (binConnection G p n) (2*n) (by positivity) (binConnection_nonneg G p n) hr - intro y S - simpa only [binConnection_symm G p n] using hr y S - -end BinConnection - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteBinConnection -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteBinConnection_eq_binConnection (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (p : unitInterval) (x : V) (n : ℕ) (y : V) - (hQ : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) : - finiteBinConnection G Q p x n y = binConnection G p n x y := by - rw [binConnection, integral_finite_local Q p _ - (finite_local_of_subset _ Q hQ _ (fun ω => binConnectionMass_local G hloc n ω x y))] - unfold finiteBinConnection finiteFieldIntegral - apply Finset.sum_congr rfl - intro ω _ - congr 1 - have hf : (cluster G (finiteFieldSet Q ω) x).Finite := - cluster_finite_of_finite_edges G ω.val.finite_toSet x - unfold cluster at hf - simp only [binConnectionMass,cluster,Set.mem_ofPred_eq,hf,true_and] - exact if_congr Iff.rfl rfl rfl - -end FiniteBinConnection - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PositivePathOperator -attribute [local instance] Classical.propDecidable Classical.decEq - - -def PositiveRealMatrix (A : Hilbert V →L[ℂ] Hilbert V) : Prop := - ∀ x y, (matrixCoeff A x y).im = 0 ∧ 0 ≤ (matrixCoeff A x y).re - -namespace PositiveRealMatrix -variable {A H : Hilbert V →L[ℂ] Hilbert V} - -theorem real (hA : PositiveRealMatrix A) (x y : V) : - matrixCoeff A x y = ((matrixCoeff A x y).re : ℂ) := by - apply Complex.ext - · rfl - · exact (hA x y).1 - -theorem mul_hasSum (hA : PositiveRealMatrix A) (H : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - HasSum (fun z => (matrixCoeff A x z).re * (matrixCoeff H z y).re) - (matrixCoeff (A*H) x y).re := by - have h := Complex.reCLM.hasSum (operator_kernel_hasSum A (H (lp.single 2 y (1:ℂ))) x) - change HasSum (fun z => (matrixCoeff A x z * matrixCoeff H z y).re) - (matrixCoeff (A*H) x y).re at h - simpa only [Complex.mul_re,(hA _ _).1,zero_mul,sub_zero] using h - -theorem mul (hA : PositiveRealMatrix A) (hH : PositiveRealMatrix H) : - PositiveRealMatrix (A*H) := by - intro x y - constructor - · have hs := (operator_kernel_hasSum A (H (lp.single 2 y (1:ℂ))) x).summable - change Summable (fun z => matrixCoeff A x z * matrixCoeff H z y) at hs - rw [matrixCoeff_mul,Complex.im_tsum hs] - simp only [Complex.mul_im,(hA _ _).1,(hH _ _).1,mul_zero,zero_mul,add_zero,tsum_zero] - · rw [← (hA.mul_hasSum H x y).tsum_eq] - exact tsum_nonneg fun z => mul_nonneg (hA x z).2 (hH z y).2 - -theorem one : PositiveRealMatrix (1 : Hilbert V →L[ℂ] Hilbert V) := by - intro x y - simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply] - split_ifs <;> norm_num - -theorem pow (hA : PositiveRealMatrix A) (k : ℕ) : PositiveRealMatrix (A^k) := by - induction k with - | zero => simpa only [pow_zero] using (one (V := V)) - | succ k ih => rw [pow_succ]; exact ih.mul hA - -theorem star (hA : PositiveRealMatrix A) : PositiveRealMatrix (star A) := by - intro x y - simpa only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_im,Complex.conj_re,neg_eq_zero] using hA y x - -end PositiveRealMatrix - - - -theorem oldRun_test_succ {W : Type*} [Fintype W] - (K : ℕ → W → W → ℝ) (F : W → ℝ) (k : ℕ) (z : W) : - (∑ r : Fin (k+1) → W, oldRunWeight K (k+1) z r * F (oldRunVertices (k+1) z r 0)) = - ∑ a : W, K (k+1) z a * - ∑ r : Fin k → W, oldRunWeight K k a r * F (oldRunVertices k a r 0) := by - rw [Fintype.sum_equiv (oldRunConsEquiv k) _ - (fun r => K (k+1) z r.1 * oldRunWeight K k r.1 r.2 * F (oldRunVertices k r.1 r.2 0)) - (by intro r; simp only [oldRunWeight,oldRunConsEquiv,Equiv.coe_fn_mk, - oldRunVertices_succ_of_le k z r 0 (Nat.zero_le k)]), Fintype.sum_prod_type] - simp only [Finset.mul_sum,mul_assoc] - - - -theorem finite_oldRun_operator_domination (A H : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) (hH : PositiveRealMatrix H) - (B : Finset V) (k : ℕ) (z : ↥B) (x : V) : - (∑ r : Fin k → ↥B, - oldRunWeight (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) k z r * - (matrixCoeff H (oldRunVertices k z r 0).val x).re) ≤ - (matrixCoeff (A^k*H) z.val x).re := by - induction k generalizing z with - | zero => simp [oldRunWeight,oldRunVertices] - | succ k ih => - rw [oldRun_test_succ (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) - (fun a : ↥B => (matrixCoeff H a.val x).re) k z] - calc - _ ≤ ∑ a : ↥B, (matrixCoeff A z.val a.val).re * (matrixCoeff (A^k*H) a.val x).re := - Finset.sum_le_sum fun a _ => mul_le_mul_of_nonneg_left (ih a) (hA z.val a.val).2 - _ ≤ ∑' a, (matrixCoeff A z.val a).re * (matrixCoeff (A^k*H) a x).re := by - rw [Finset.sum_coe_sort B (fun a => (matrixCoeff A z.val a).re * (matrixCoeff (A^k*H) a x).re)] - exact (hA.mul_hasSum (A^k*H) z.val x).summable.sum_le_tsum B - (fun a _ => mul_nonneg (hA z.val a).2 (((hA.pow k).mul hH) a x).2) - _ = (matrixCoeff (A^(k+1)*H) z.val x).re := by - rw [(hA.mul_hasSum (A^k*H) z.val x).tsum_eq,pow_succ',mul_assoc] - -end PositivePathOperator - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section OrbitBinOperator -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem isAut_trans (G : BondGraph V E) {a c : V ≃ V} {b d : E ≃ E} - (hab : IsAut G a b) (hcd : IsAut G c d) : IsAut G (a.trans c) (b.trans d) := by - intro e - change G (d (b e)) = (G e).map (c ∘ a) - rw [hcd,hab,Sym2.map_map] - -theorem mem_vertexOrbit_aut_iff (G : BondGraph V E) (o : V) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) : a x ∈ vertexOrbit G o ↔ x ∈ vertexOrbit G o := by - constructor - · rintro ⟨c,d,hcd,hc⟩ - refine ⟨c.trans a.symm,d.trans b.symm,isAut_trans G hcd (isAut_symm G hab),?_⟩ - simp only [Equiv.trans_apply,hc,Equiv.symm_apply_apply] - · rintro ⟨c,d,hcd,rfl⟩ - exact ⟨c.trans a,d.trans b,isAut_trans G hcd hab,rfl⟩ - -theorem binConnectionMass_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (n : ℕ) (ω : Set E) (x y : V) : - binConnectionMass G n (b ⁻¹' ω) x y = binConnectionMass G n ω (a x) (a y) := by - have hf : (cluster G (b ⁻¹' ω) x).Finite ↔ (cluster G ω (a x)).Finite := by - rw [← cluster_aut G hab ω x] - exact (Set.finite_image_iff a.injective.injOn).symm - have hn : (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by - rw [← cluster_aut G hab ω x,Set.ncard_image_of_injective _ a.injective] - simp only [binConnectionMass,hf,hn,conn_aut_iff G hab] - -theorem binConnection_covariant (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : - binConnection G p n (a x) (a y) = binConnection G p n x y := by - have hm : Measurable (fun ω => binConnectionMass G n ω x y) := - measurable_finite_local _ _ (fun ω => binConnectionMass_local G hloc n ω x y) - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [binConnection,binConnectionMass_covariant G hab] using h.symm - - -noncomputable def orbitBinConnection (G : BondGraph V E) (p : unitInterval) (o : V) - (n : ℕ) (x y : V) : ℝ := - if x ∈ vertexOrbit G o ∧ y ∈ vertexOrbit G o then binConnection G p n x y else 0 - -theorem orbitBinConnection_nonneg (G : BondGraph V E) (p : unitInterval) (o : V) - (n : ℕ) (x y : V) : 0 ≤ orbitBinConnection G p o n x y := by - unfold orbitBinConnection - split_ifs - · exact binConnection_nonneg G p n x y - · exact le_rfl - -theorem orbitBinConnection_symm (G : BondGraph V E) (p : unitInterval) (o : V) - (n : ℕ) (x y : V) : orbitBinConnection G p o n x y = orbitBinConnection G p o n y x := by - simp only [orbitBinConnection,and_comm,binConnection_symm G p n] - -theorem orbitBinConnection_covariant (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : - orbitBinConnection G p o n (a x) (a y) = orbitBinConnection G p o n x y := by - simp only [orbitBinConnection,mem_vertexOrbit_aut_iff G o hab,binConnection_covariant G hloc p hab n] - -theorem orbitBinConnection_summable (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (x : V) : Summable (orbitBinConnection G p o n x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) - intro y hy - have hz := binConnection_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) - simp only [orbitBinConnection,hz,ite_self] - -noncomputable def binOrbitRow (G : BondGraph V E) (p : unitInterval) (o : V) (n : ℕ) : ℝ := - ∑' y, orbitBinConnection G p o n o y - -theorem orbitBinConnection_row (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (x : V) (hx : x ∈ vertexOrbit G o) : - (∑' y, orbitBinConnection G p o n x y) = binOrbitRow G p o n := by - obtain ⟨a,b,hab,rfl⟩ := hx - rw [← a.tsum_eq (fun y => orbitBinConnection G p o n (a o) y)] - exact tsum_congr (fun y => orbitBinConnection_covariant G hloc p o hab n o y) - -theorem orbitBinConnection_row_le (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) (x : V) : - (∑' y, orbitBinConnection G p o n x y) ≤ binOrbitRow G p o n := by - by_cases hx : x ∈ vertexOrbit G o - · exact (orbitBinConnection_row G hloc p o n x hx).le - · simp only [orbitBinConnection,hx,false_and,ite_false,tsum_zero] - exact tsum_nonneg (orbitBinConnection_nonneg G p o n o) - - - -theorem exists_orbitBinConnection_operator (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (n : ℕ) : - ∃ H : Hilbert V →L[ℂ] Hilbert V, ‖H‖ ≤ binOrbitRow G p o n ∧ - ∀ x y, matrixCoeff H x y = (orbitBinConnection G p o n x y : ℂ) := by - have hr (x : V) (S : Finset V) : (∑ y ∈ S, orbitBinConnection G p o n x y) ≤ binOrbitRow G p o n := - ((orbitBinConnection_summable G hloc p o n x).sum_le_tsum S - (fun y _ => orbitBinConnection_nonneg G p o n x y)).trans (orbitBinConnection_row_le G hloc p o n x) - exact exists_operator_of_row_column_bound (orbitBinConnection G p o n) (binOrbitRow G p o n) - (tsum_nonneg (orbitBinConnection_nonneg G p o n o)) (orbitBinConnection_nonneg G p o n) hr - (fun y S => by simpa only [orbitBinConnection_symm G p o n] using hr y S) - -end OrbitBinOperator - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open MeasureTheory -section AmplificationOperatorDomination -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem oldRun_endpoint_mem {W : Type*} (P : W → Prop) (K : ℕ → W → W → ℝ) - (hK : ∀ i a b, K i a b ≠ 0 → P b) (k : ℕ) (z : W) (hz : P z) - (r : Fin k → W) (hr : oldRunWeight K k z r ≠ 0) : P (oldRunVertices k z r 0) := by - induction k generalizing z with - | zero => exact hz - | succ k ih => - have hm := mul_ne_zero_iff.mp hr - rw [oldRunVertices_succ_of_le _ _ _ _ (Nat.zero_le k)] - exact ih (r 0) (hK _ _ _ hm.1) (Fin.tail r) hm.2 - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem amplificationMarginal_operator_le [Nonempty E] (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) - (hx : x ∈ vertexOrbit G o) (hz : z.val ∈ vertexOrbit G o) - (hroot : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) - (hquery : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) - (A H : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ a b, matrixCoeff A a b = (q.kernel p a b : ℂ)) - (hH : ∀ a b, matrixCoeff H a b = (orbitBinConnection G p o n a b : ℂ)) : - (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) ≤ - (matrixCoeff (A^k*H) z.val x).re := by - have hposA : PositiveRealMatrix A := fun a b => by - rw [hA a b] - exact ⟨rfl,q.kernel_nonneg p a b⟩ - have hposH : PositiveRealMatrix H := fun a b => by - rw [hH a b] - exact ⟨rfl,orbitBinConnection_nonneg G p o n a b⟩ - rw [q.amplificationMarginal_mean_kernel Q B x k n z p hx hz hquery] - have he : (∑ r : Fin k → ↥B, finiteBinConnection G Q p x n (amplificationVertices B k z r 0) * - oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r) = - ∑ r : Fin k → ↥B, - oldRunWeight (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) k z r * - (matrixCoeff H (oldRunVertices k z r 0).val x).re := by - apply Finset.sum_congr rfl - intro r _ - simp only [hA,hH,Complex.ofReal_re, - finiteBinConnection_eq_binConnection G hloc Q p x n _ hroot] - by_cases hr : oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r = 0 - · simp only [hr,mul_zero,zero_mul] - · have hy : (oldRunVertices k z r 0).val ∈ vertexOrbit G o := - oldRun_endpoint_mem (fun a : ↥B => a.val ∈ vertexOrbit G o) - (fun _ (a b : ↥B) => q.kernel p a.val b.val) - (fun _ a b hab => by - by_contra hb - exact hab (q.kernel_zero_of_end_not_mem p a.val b.val hb)) k z hz r hr - rw [orbitBinConnection,ite_eq_left ⟨hy,hx⟩,binConnection_symm G p n] - exact mul_comm _ _ - rw [he] - exact finite_oldRun_operator_domination A H hposA hposH B k z x - -end LocalEndpointRule - - - -theorem exists_operator_of_amplification_domination - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (o : V) (n k : ℕ) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (F : V → V → ℝ) (hF : ∀ x z, 0 ≤ F x z) - (hdom : ∀ (H : Hilbert V →L[ℂ] Hilbert V), - (∀ x y, matrixCoeff H x y = (orbitBinConnection G p o n x y : ℂ)) → - ∀ x z, F x z ≤ (matrixCoeff (A^k*H) z x).re) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ binOrbitRow G p o n * ‖A‖^k ∧ - ∀ x z, matrixCoeff T x z = (F x z : ℂ) := by - obtain ⟨H,hHnorm,hH⟩ := exists_orbitBinConnection_operator G hloc p o n - have hposH : PositiveRealMatrix H := fun x y => by - rw [hH x y] - exact ⟨rfl,orbitBinConnection_nonneg G p o n x y⟩ - have hpos := ((hA.pow k).mul hposH).star - have htr (x z : V) : (matrixCoeff (star (A^k*H)) x z).re = (matrixCoeff (A^k*H) z x).re := by - simp only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_re] - obtain ⟨T,hTnorm,hT⟩ := exists_operator_of_matrix_domination - (fun x z => (matrixCoeff (star (A^k*H)) x z).re) F (fun x z => (hpos x z).2) - (fun x z => by rw [abs_of_nonneg (hF x z),htr]; exact hdom H hH x z) - (star (A^k*H)) (fun x z => hpos.real x z) - refine ⟨T,hTnorm.trans ?_,hT⟩ - have hpow : ∀ j : ℕ, ‖A^j‖ ≤ ‖A‖^j := by - intro j - induction j with - | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) - | succ j ih => - rw [pow_succ, pow_succ] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg _)) - calc - ‖star (A^k*H)‖ = ‖A^k*H‖ := by - change ‖ContinuousLinearMap.adjoint (A^k*H)‖ = _ - exact LinearIsometryEquiv.norm_map _ _ - _ ≤ ‖A^k‖ * ‖H‖ := norm_mul_le _ _ - _ ≤ ‖A‖^k * binOrbitRow G p o n := mul_le_mul (hpow k) hHnorm - (norm_nonneg _) (pow_nonneg (norm_nonneg _) _) - _ = binOrbitRow G p o n * ‖A‖^k := mul_comm _ _ - -end AmplificationOperatorDomination - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterVisitKernel -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -noncomputable def conditionalSuccess (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : ℝ := - ∑' y, q.mass ω x y - -theorem conditionalSuccess_nonneg (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : - 0 ≤ q.conditionalSuccess ω x := tsum_nonneg (q.nonneg ω x) - -theorem conditionalSuccess_support (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) - (h : q.conditionalSuccess ω x ≠ 0) : - x ∈ O ∧ (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M := by - have he : ∃ y, q.mass ω x y ≠ 0 := by - by_contra hn - push Not at hn - exact h (by simp only [conditionalSuccess,hn,tsum_zero]) - obtain ⟨y,hy⟩ := he - obtain ⟨hx,_,_,hf,hc,_⟩ := q.support ω x y hy - exact ⟨hx,hf,hc⟩ - -theorem conditionalSuccess_local (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : - q.conditionalSuccess ω x = q.conditionalSuccess - (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset : Set E)) x := - tsum_congr (q.locality ω x) - -theorem conditionalSuccess_integrable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - Integrable (fun ω => q.conditionalSuccess ω x) (law p) := - integrable_finite_local _ p _ (fun ω => q.conditionalSuccess_local ω x) - -theorem conditionalSuccess_mean (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - (∫ ω, q.conditionalSuccess ω x ∂law p) = q.successProbability p x := - (q.kernel_row_integral p x).symm - -theorem conditionalSuccess_covariant (q : LocalEndpointRule G hloc O M L) - (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x : V) : - q.conditionalSuccess (b ⁻¹' ω) x = q.conditionalSuccess ω (a x) := by - unfold conditionalSuccess - simp_rw [q.covariance a b hab] - exact a.tsum_eq _ - - - -noncomputable def clusterVisitMass (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : ℝ := - if a ∈ cluster G ω x then q.conditionalSuccess ω x else 0 - -theorem clusterVisitMass_nonneg (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : - 0 ≤ q.clusterVisitMass ω x a := by - unfold clusterVisitMass - split_ifs - · exact q.conditionalSuccess_nonneg ω x - · exact le_refl _ - -theorem clusterVisitMass_outside (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) - (ha : a ∉ reachBall G x M) : q.clusterVisitMass ω x a = 0 := by - by_cases h : q.conditionalSuccess ω x = 0 - · simp only [clusterVisitMass,h,ite_self] - · obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h - exact ite_eq_right (fun hmem => ha (finite_cluster_subset_reachBall G ω x hf M hc hmem)) - -theorem clusterVisitMass_local (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset - q.clusterVisitMass ω x a = q.clusterVisitMass (ω ∩ (Q : Set E)) x a := by - dsimp only - let Q := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset - change q.clusterVisitMass ω x a = q.clusterVisitMass (ω ∩ (Q:Set E)) x a - have he := finite_local_of_subset _ Q - (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) - (fun ω => q.conditionalSuccess ω x) (fun ω => q.conditionalSuccess_local ω x) ω - by_cases h : q.conditionalSuccess ω x = 0 - · have h' : q.conditionalSuccess (ω ∩ (Q:Set E)) x = 0 := he.symm.trans h - simp only [clusterVisitMass,h,h',ite_self] - · obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h - have hs : cluster G ω x ⊆ (finite_reachBall hloc x (max q.radius M)).toFinset := by - simpa only [Set.Finite.coe_toFinset] using - finite_cluster_subset_reachBall G ω x hf _ (hc.trans (le_max_right _ _)) - have hc' := cluster_restrict_incident_of_full G hloc _ ω x hs - change cluster G (ω ∩ (Q:Set E)) x = cluster G ω x at hc' - change (if a ∈ cluster G ω x then _ else _) = (if a ∈ cluster G (ω ∩ (Q:Set E)) x then _ else _) - rw [hc',he] - -theorem clusterVisitMass_integrable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) : - Integrable (fun ω => q.clusterVisitMass ω x a) (law p) := - integrable_finite_local _ p _ (fun ω => q.clusterVisitMass_local ω x a) - -theorem clusterVisitMass_covariant (q : LocalEndpointRule G hloc O M L) - (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x y : V) : - q.clusterVisitMass (b ⁻¹' ω) x y = q.clusterVisitMass ω (a x) (a y) := by - have hc : y ∈ cluster G (b ⁻¹' ω) x ↔ a y ∈ cluster G ω (a x) := by - rw [← cluster_aut G hab ω x] - constructor - · intro hy; exact ⟨y,hy,rfl⟩ - · rintro ⟨z,hz,he⟩ - exact (a.injective he) ▸ hz - simp only [clusterVisitMass,hc,q.conditionalSuccess_covariant a b hab] - -theorem clusterVisitMass_row_le (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : - (∑' a, q.clusterVisitMass ω x a) ≤ M * q.conditionalSuccess ω x := by - by_cases h : q.conditionalSuccess ω x = 0 - · simp only [clusterVisitMass,h,ite_self,tsum_zero,mul_zero,le_refl] - obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h - rw [tsum_eq_sum (f := q.clusterVisitMass ω x) (s := hf.toFinset) (fun a ha => ite_eq_right (by simpa only [Set.Finite.mem_toFinset] using ha))] - have he : (∑ a ∈ hf.toFinset, q.clusterVisitMass ω x a) = - (hf.toFinset.card:ℝ) * q.conditionalSuccess ω x := by - calc - _ = ∑ _a ∈ hf.toFinset, q.conditionalSuccess ω x := Finset.sum_congr rfl (fun a ha => ite_eq_left (hf.mem_toFinset.mp ha)) - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul] - rw [he] - apply mul_le_mul_of_nonneg_right _ (q.conditionalSuccess_nonneg ω x) - exact_mod_cast (by simpa only [← Set.ncard_eq_toFinset_card _ hf] using hc) - -noncomputable def clusterVisitKernel (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (x a : V) : ℝ := ∫ ω, q.clusterVisitMass ω x a ∂law p - -theorem clusterVisitKernel_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) : - 0 ≤ q.clusterVisitKernel p x a := integral_nonneg (fun ω => q.clusterVisitMass_nonneg ω x a) - -theorem clusterVisitKernel_outside (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) - (ha : a ∉ reachBall G x M) : q.clusterVisitKernel p x a = 0 := by - simp only [clusterVisitKernel,q.clusterVisitMass_outside _ x a ha,integral_zero] - -theorem clusterVisitKernel_summable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - Summable (q.clusterVisitKernel p x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro a ha - exact q.clusterVisitKernel_outside p x a (by simpa only [Set.Finite.mem_toFinset] using ha) - -theorem clusterVisitKernel_row_le (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - (∑' a, q.clusterVisitKernel p x a) ≤ M * q.successProbability p x := by - let B := (finite_reachBall hloc x M).toFinset - have he (ω : Set E) : (∑' a, q.clusterVisitMass ω x a) = ∑ a ∈ B, q.clusterVisitMass ω x a := - tsum_eq_sum (fun a ha => q.clusterVisitMass_outside ω x a (by simpa only [B,Set.Finite.mem_toFinset] using ha)) - rw [tsum_eq_sum (s := B) (fun a ha => q.clusterVisitKernel_outside p x a (by simpa only [B,Set.Finite.mem_toFinset] using ha))] - simp only [clusterVisitKernel] - rw [← integral_finsetSum B (fun a _ => q.clusterVisitMass_integrable p x a)] - calc - _ ≤ ∫ ω, (M:ℝ) * q.conditionalSuccess ω x ∂law p := - integral_mono (integrable_finsetSum B (fun a _ => q.clusterVisitMass_integrable p x a)) - ((q.conditionalSuccess_integrable p x).const_mul _) (fun ω => by rw [← he]; exact q.clusterVisitMass_row_le ω x) - _ = _ := by rw [integral_const_mul,q.conditionalSuccess_mean] - -theorem clusterVisitKernel_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x y : V) : - q.clusterVisitKernel p (a x) (a y) = q.clusterVisitKernel p x y := by - have hm : Measurable (fun ω => q.clusterVisitMass ω x y) := - measurable_finite_local _ _ (fun ω => q.clusterVisitMass_local ω x y) - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [clusterVisitKernel,q.clusterVisitMass_covariant a b hab] using h.symm - -end LocalEndpointRule -end ClusterVisitKernel - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section VisitEnvelope -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -noncomputable def visitEnvelope (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) : ℕ → V → V → ℝ - | 0, _, _ => 0 - | k+1, x, a => q.successProbability p o ^ k * q.clusterVisitKernel p x a + - ∑' y, q.kernel p x y * q.visitEnvelope o p k y a - -theorem visitEnvelope_nonneg (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (k : ℕ) (x a : V) : 0 ≤ q.visitEnvelope o p k x a := by - induction k generalizing x with - | zero => exact le_refl _ - | succ k ih => - exact add_nonneg (mul_nonneg (pow_nonneg (q.successProbability_nonneg p o) _) (q.clusterVisitKernel_nonneg p x a)) - (tsum_nonneg (fun y => mul_nonneg (q.kernel_nonneg p x y) (ih y))) - -theorem visitEnvelope_covariant (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (k : ℕ) (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x y : V) : - q.visitEnvelope o p k (a x) (a y) = q.visitEnvelope o p k x y := by - induction k generalizing x y with - | zero => rfl - | succ k ih => - simp only [visitEnvelope,q.clusterVisitKernel_covariant p a b hab] - congr 1 - rw [← a.tsum_eq (fun z => q.kernel p (a x) z * q.visitEnvelope o p k z (a y))] - exact tsum_congr fun z => by rw [q.kernel_covariant p a b hab,ih] - - - -theorem visitEnvelope_row_bound (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (k : ℕ) (x : V) : - Summable (q.visitEnvelope o p k x) ∧ - (∑' a, q.visitEnvelope o p k x a) ≤ (k*M:ℕ) * q.successProbability p o ^ k := by - let u := q.successProbability p o - have hu : 0 ≤ u := q.successProbability_nonneg p o - induction k generalizing x with - | zero => simp only [visitEnvelope,zero_mul,Nat.cast_zero,pow_zero,mul_one,tsum_zero,le_refl,and_true]; exact summable_zero - | succ k ih => - let B := (finite_reachBall hloc x M).toFinset - have he (a : V) : (∑' y, q.kernel p x y * q.visitEnvelope o p k y a) = - ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a := - tsum_eq_sum (fun y hy => by - rw [q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul]) - have ht (a : V) : q.visitEnvelope o p (k+1) x a = - u^k * q.clusterVisitKernel p x a + ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a := by - exact congrArg (_ + ·) (he a) - have hsum : Summable (fun a => ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a) := - summable_sum (s := B) (fun y _ => (ih y).1.mul_left _) - have hs := ((q.clusterVisitKernel_summable p x).mul_left (u^k)).add hsum - have hs' : Summable (q.visitEnvelope o p (k+1) x) := by - change Summable (fun a => q.visitEnvelope o p (k+1) x a) - simpa only [ht] using hs - refine ⟨hs',?_⟩ - simp_rw [ht] - rw [Summable.tsum_add ((q.clusterVisitKernel_summable p x).mul_left _) hsum,tsum_mul_left, - Summable.tsum_finsetSum (fun y _ => (ih y).1.mul_left _)] - simp_rw [tsum_mul_left] - have hr : (∑ y ∈ B, q.kernel p x y) ≤ u := - ((q.summable_kernel p x).sum_le_tsum B (fun y _ => q.kernel_nonneg p x y)).trans - (q.kernel_row_le_success o p x) - calc - _ ≤ u^k * (M*u) + ∑ y ∈ B, q.kernel p x y * ((k*M:ℕ)*u^k) := by - apply add_le_add - · apply mul_le_mul_of_nonneg_left _ (pow_nonneg hu _) - exact (q.clusterVisitKernel_row_le p x).trans - (mul_le_mul_of_nonneg_left (q.kernel_row_le_success o p x) (Nat.cast_nonneg _)) - · exact Finset.sum_le_sum fun y _ => mul_le_mul_of_nonneg_left (ih y).2 (q.kernel_nonneg p x y) - _ ≤ u^k * (M*u) + u*((k*M:ℕ)*u^k) := by - rw [← Finset.sum_mul] - exact add_le_add (le_refl _) (mul_le_mul_of_nonneg_right hr (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg hu _))) - _ = ((k+1)*M:ℕ) * q.successProbability p o ^ (k+1) := by - change _ = ((k+1)*M:ℕ) * u^(k+1) - simp only [Nat.cast_mul,Nat.cast_add,Nat.cast_one,pow_succ] - ring - -end LocalEndpointRule -end VisitEnvelope - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section MarkedOldRun -attribute [local instance] Classical.propDecidable Classical.decEq -variable {W : Type*} - -theorem oldRunWeight_congr (K K' : ℕ → W → W → ℝ) (k : ℕ) - (h : ∀ i, 1 ≤ i → i ≤ k → ∀ a b, K i a b = K' i a b) (z : W) (r : Fin k → W) : - oldRunWeight K k z r = oldRunWeight K' k z r := by - induction k generalizing z with - | zero => rfl - | succ k ih => - simp only [oldRunWeight] - rw [h (k+1) (by omega) (by omega),ih (fun i hi hik => h i hi (by omega))] - -theorem oldRunWeight_prod (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : - oldRunWeight K k z r = ∏ i ∈ Finset.Icc 1 k, - K i (oldRunVertices k z r i) (oldRunVertices k z r (i-1)) := by - induction k generalizing z with - | zero => simp [oldRunWeight] - | succ k ih => - rw [Finset.prod_Icc_succ_top (by omega)] - have he : (∏ i ∈ Finset.Icc 1 k, K i (oldRunVertices (k+1) z r i) - (oldRunVertices (k+1) z r (i-1))) = oldRunWeight K k (r 0) (Fin.tail r) := by - rw [ih] - apply Finset.prod_congr rfl - intro i hi - have hi' := Finset.mem_Icc.mp hi - rw [oldRunVertices_succ_of_le _ _ _ _ hi'.2, - oldRunVertices_succ_of_le _ _ _ _ (by omega)] - rw [he,oldRunVertices_last,Nat.add_sub_cancel, - oldRunVertices_succ_of_le _ _ _ _ (le_refl _),oldRunVertices_last] - exact mul_comm _ _ - - - -noncomputable def markedOldRun (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : ℝ := - ∑ i ∈ Finset.Icc 1 k, oldRunWeight (fun j a b => if j = i then C j a b else K j a b) k z r - -theorem markedOldRun_nonneg (K C : ℕ → W → W → ℝ) - (hK : ∀ i a b, 0 ≤ K i a b) (hC : ∀ i a b, 0 ≤ C i a b) - (k : ℕ) (z : W) (r : Fin k → W) : 0 ≤ markedOldRun K C k z r := by - apply Finset.sum_nonneg - intro i _ - apply oldRunWeight_nonneg - intro j a b - split_ifs - · exact hC j a b - · exact hK j a b - -theorem markedOldRun_succ (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin (k+1) → W) : - markedOldRun K C (k+1) z r = - K (k+1) z (r 0) * markedOldRun K C k (r 0) (Fin.tail r) + - C (k+1) z (r 0) * oldRunWeight K k (r 0) (Fin.tail r) := by - unfold markedOldRun - rw [Finset.sum_Icc_succ_top (by omega),Finset.mul_sum] - congr 1 - · apply Finset.sum_congr rfl - intro i hi - have hne : k+1 ≠ i := by have := Finset.mem_Icc.mp hi; omega - simp only [oldRunWeight,ite_eq_right hne] - · simp only [oldRunWeight,ite_true] - congr 1 - apply oldRunWeight_congr - intro i hi hik a b - exact ite_eq_right (by omega) - -theorem sum_markedOldRun_succ [Fintype W] (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) : - (∑ r : Fin (k+1) → W, markedOldRun K C (k+1) z r) = - ∑ b : W, (K (k+1) z b * (∑ r : Fin k → W, markedOldRun K C k b r) + - C (k+1) z b * (∑ r : Fin k → W, oldRunWeight K k b r)) := by - rw [Fintype.sum_equiv (oldRunConsEquiv k) _ - (fun r => K (k+1) z r.1 * markedOldRun K C k r.1 r.2 + C (k+1) z r.1 * oldRunWeight K k r.1 r.2) - (by intro r; exact markedOldRun_succ K C k z r),Fintype.sum_prod_type] - simp only [Finset.sum_add_distrib,Finset.mul_sum] - - -theorem oldRunWeight_integral_indexed (Q : Finset E) (p : ℝ) - (q : ℕ → Set E → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => oldRunWeight (fun i => q i (η i)) k z r) = - oldRunWeight (fun i a b => finiteFieldIntegral Q p (fun ω => q i ω a b)) k z r := by - calc - _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - ∏ i : ↥(Finset.Icc 1 k), q i (η i) (oldRunVertices k z r i) - (oldRunVertices k z r (i.val-1))) := by - congr 1 - funext η - rw [oldRunWeight_prod] - exact (Finset.prod_coe_sort (Finset.Icc 1 k) - (fun i => q i (η i) (oldRunVertices k z r i) (oldRunVertices k z r (i-1)))).symm - _ = ∏ i : ↥(Finset.Icc 1 k), finiteFieldIntegral Q p (fun ω => - q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i.val-1))) := - finiteFamilyIntegral_prod Q (Finset.Icc 1 k) p - (fun i ω => q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i.val-1))) - _ = _ := by - rw [oldRunWeight_prod] - exact Finset.prod_coe_sort (Finset.Icc 1 k) (fun i => finiteFieldIntegral Q p - (fun ω => q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i-1)))) - -theorem markedOldRun_integral (Q : Finset E) (p : ℝ) - (q c : ℕ → Set E → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p - (fun η => markedOldRun (fun i => q i (η i)) (fun i => c i (η i)) k z r) = - markedOldRun (fun i a b => finiteFieldIntegral Q p (fun ω => q i ω a b)) - (fun i a b => finiteFieldIntegral Q p (fun ω => c i ω a b)) k z r := by - unfold markedOldRun - rw [finiteFamilyIntegral_sum] - apply Finset.sum_congr rfl - intro i _ - change finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - oldRunWeight (fun j => (fun ω a b => if j=i then c j ω a b else q j ω a b) (η j)) k z r) = _ - rw [oldRunWeight_integral_indexed Q p (fun j ω a b => if j=i then c j ω a b else q j ω a b) k z r] - congr 1 - funext j a b - by_cases h : j = i <;> simp only [h,ite_true,ite_false] - - - -theorem trajectory_indicator_le_marked (G : BondGraph V E) (e : W → V) - (q : Set E → W → W → ℝ) (hq : ∀ ω x y, 0 ≤ q ω x y) - (k : ℕ) (η : ℕ → Set E) (z : W) (r : Fin k → W) (a : V) : - (if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z r) k then - oldRunWeight (fun i => q (η i)) k z r else 0) ≤ - markedOldRun (fun i => q (η i)) - (fun i x y => if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) k z r := by - have hC : ∀ i x y, 0 ≤ (if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) := by - intro i x y; split_ifs; exact hq _ _ _; exact le_refl _ - by_cases ha : a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z r) k - · rw [ite_eq_left ha] - obtain ⟨i,hi,hik,hai⟩ := (mem_trajectoryUnion G η (e ∘ oldRunVertices k z r) k a).mp ha - have he : oldRunWeight (fun j x y => if j=i then - (if a ∈ cluster G (η j) (e x) then q (η j) x y else 0) else q (η j) x y) k z r = - oldRunWeight (fun j => q (η j)) k z r := by - simp_rw [oldRunWeight_prod] - apply Finset.prod_congr rfl - intro j _ - by_cases hji : j = i - · subst j - simp only [ite_true,Function.comp_apply] at hai ⊢ - exact ite_eq_left hai - · exact ite_eq_right hji - rw [← he] - unfold markedOldRun - apply Finset.single_le_sum _ (Finset.mem_Icc.mpr ⟨hi,hik⟩) - intro j _ - apply oldRunWeight_nonneg - intro l x y - split_ifs - · exact hq _ _ _ - · exact le_refl _ - · exact hq _ _ _ - · rw [ite_eq_right ha] - exact markedOldRun_nonneg _ _ (fun _ => hq _) hC k z r - -end MarkedOldRun - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TrajectoryEnvelopeDomination -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteTrajectoryMass_le_marked {W : Type*} [Fintype W] - (G : BondGraph V E) (e : W → V) (Q : Finset E) (p : unitInterval) (k : ℕ) - (q : Set E → W → W → ℝ) (hq : ∀ ω x y, 0 ≤ q ω x y) (z : W) (a : V) : - finiteTrajectoryMass G e Q p k q z a ≤ - ∑ r : Fin k → W, markedOldRun (fun _ => finiteOldKernel Q p q) - (fun _ x y => finiteFieldIntegral Q p (fun ω => if a ∈ cluster G ω (e x) then q ω x y else 0)) k z r := by - unfold finiteTrajectoryMass - calc - _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => ∑ r : Fin k → W, - markedOldRun (fun i => q (η i)) - (fun i x y => if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) k z r) := - finiteFamilyIntegral_mono Q (Finset.Icc 1 k) p _ _ (fun η => Finset.sum_le_sum (fun r _ => - trajectory_indicator_le_marked G e q hq k η z r a)) - _ = _ := by - rw [finiteFamilyIntegral_sum] - apply Finset.sum_congr rfl - intro r _ - exact markedOldRun_integral Q p (fun _ => q) - (fun _ ω x y => if a ∈ cluster G ω (e x) then q ω x y else 0) k z r - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem finite_marked_step_row_le (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (x a : V) - (hQ : incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : - (∑ y : ↥B, finiteFieldIntegral Q p (fun ω => - if a ∈ cluster G ω x then q.mass ω x y.val else 0)) ≤ q.clusterVisitKernel p x a := by - rw [← finiteFieldIntegral_sum] - have he : q.clusterVisitKernel p x a = finiteFieldIntegral Q p (fun ω => q.clusterVisitMass ω x a) := - integral_finite_local Q p _ (finite_local_of_subset _ Q hQ _ (q.clusterVisitMass_local · x a)) - rw [he] - apply Finset.sum_le_sum - intro ω _ - apply mul_le_mul_of_nonneg_left _ (finiteFieldWeight_nonneg Q p ω) - dsimp only - by_cases ha : a ∈ cluster G (finiteFieldSet Q ω) x - · simp only [ha,ite_true,clusterVisitMass] - rw [Finset.sum_coe_sort B (fun y => q.mass (finiteFieldSet Q ω) x y)] - exact (q.summable_mass _ x).sum_le_tsum B (fun y _ => q.nonneg _ x y) - · simp only [ha,ite_false,clusterVisitMass,Finset.sum_const_zero,le_refl] - - - -theorem sum_markedOldRun_le_envelope (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (z : ↥B) (a : V) - (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : - (∑ r : Fin k → ↥B, markedOldRun - (fun _ => finiteOldKernel Q p (fun ω (x y : ↥B) => q.mass ω x.val y.val)) - (fun _ (x y : ↥B) => finiteFieldIntegral Q p (fun ω => - if a ∈ cluster G ω x.val then q.mass ω x.val y.val else 0)) k z r) ≤ - q.visitEnvelope o p k z.val a := by - let u := q.successProbability p o - let K : ↥B → ↥B → ℝ := finiteOldKernel Q p (fun ω (x y : ↥B) => q.mass ω x.val y.val) - let C : ↥B → ↥B → ℝ := fun x y => finiteFieldIntegral Q p (fun ω => - if a ∈ cluster G ω x.val then q.mass ω x.val y.val else 0) - have hK (x y : ↥B) : K x y = q.kernel p x.val y.val := - q.finiteOldKernel_eq_kernel Q p x.val y.val - ((incidentSupport_ball_mono G hloc x.val (le_max_left _ _)).trans (hQ x.val x.property)) - have hKn (x y : ↥B) : 0 ≤ K x y := by rw [hK]; exact q.kernel_nonneg p _ _ - have hCn (x y : ↥B) : 0 ≤ C x y := by - apply finiteFieldIntegral_nonneg - intro ω; split_ifs; exact q.nonneg ω _ _; exact le_refl _ - have hKr (x : ↥B) : (∑ y, K x y) ≤ u := by - simp only [hK] - rw [Finset.sum_coe_sort B (fun y => q.kernel p x.val y)] - exact ((q.summable_kernel p x.val).sum_le_tsum B (fun y _ => q.kernel_nonneg p x.val y)).trans - (q.kernel_row_le_success o p x.val) - have hCr (x : ↥B) : (∑ y, C x y) ≤ q.clusterVisitKernel p x.val a := - q.finite_marked_step_row_le o Q B p x.val a (hQ x.val x.property) - change (∑ r : Fin k → ↥B, markedOldRun (fun _ => K) (fun _ => C) k z r) ≤ _ - induction k generalizing z with - | zero => simp [markedOldRun,visitEnvelope] - | succ k ih => - rw [sum_markedOldRun_succ] - have hs : Summable (fun y => q.kernel p z.val y * q.visitEnvelope o p k y a) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc z.val M).toFinset) - intro y hy - rw [q.kernel_outside_ball_zero p z.val y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] - calc - _ ≤ ∑ y : ↥B, (K z y * q.visitEnvelope o p k y.val a + C z y * u^k) := - Finset.sum_le_sum fun y _ => add_le_add - (mul_le_mul_of_nonneg_left (ih y) (hKn z y)) - (mul_le_mul_of_nonneg_left (sum_oldRunWeight_le (fun _ => K) (fun _ => hKn) - u (q.successProbability_nonneg p o) (fun _ => hKr) k y) (hCn z y)) - _ = (∑ y : ↥B, K z y * q.visitEnvelope o p k y.val a) + (∑ y : ↥B, C z y)*u^k := by - rw [Finset.sum_add_distrib,Finset.sum_mul] - _ ≤ (∑' y, q.kernel p z.val y * q.visitEnvelope o p k y a) + q.clusterVisitKernel p z.val a * u^k := by - apply add_le_add - · simp only [hK] - rw [Finset.sum_coe_sort B (fun y => q.kernel p z.val y * q.visitEnvelope o p k y a)] - exact hs.sum_le_tsum B (fun y _ => mul_nonneg (q.kernel_nonneg p z.val y) (q.visitEnvelope_nonneg o p k y a)) - · exact mul_le_mul_of_nonneg_right (hCr z) (pow_nonneg (q.successProbability_nonneg p o) _) - _ = q.visitEnvelope o p (k+1) z.val a := by rw [visitEnvelope]; ring - -theorem finiteTrajectoryMass_le_envelope (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (z : ↥B) (a : V) - (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : - finiteTrajectoryMass G Subtype.val Q p k (fun ω (x y : ↥B) => q.mass ω x.val y.val) z a ≤ - q.visitEnvelope o p k z.val a := - (finiteTrajectoryMass_le_marked G Subtype.val Q p k _ (fun ω x y => q.nonneg ω x.val y.val) z a).trans - (q.sum_markedOldRun_le_envelope o Q B p k z a hQ) - -end LocalEndpointRule -end TrajectoryEnvelopeDomination - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Transport.EndpointKernels + +namespace OAI + +/-! Amplification for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AmplificationMarginal +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def restrictFiniteField (Q : Finset E) (ω : Set E) : FiniteField Q := + ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ + +@[simp] theorem finiteFieldSet_restrict (Q : Finset E) (ω : Set E) : + finiteFieldSet Q (restrictFiniteField Q ω) = ω ∩ (Q : Set E) := by + ext e + simp [restrictFiniteField,domainBits,finiteFieldSet,and_comm] + +@[simp] theorem restrictFiniteField_fieldSet (Q : Finset E) (ω : FiniteField Q) : + restrictFiniteField Q (finiteFieldSet Q ω) = ω := by + apply Subtype.ext + exact domainBits_finiteFieldSet Q ω + +theorem cluster_restrict_of_cap (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (ω : Set E) (x : V) (C : ℕ) + (hQ : incidentSupport G hloc (finite_reachBall hloc x C).toFinset ⊆ Q) + (hf : (cluster G (ω ∩ (Q : Set E)) x).Finite) + (hC : (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ C) : + cluster G (ω ∩ (Q : Set E)) x = cluster G ω x := by + apply Set.Subset.antisymm + · exact fun _ h => conn_mono G Set.inter_subset_left h + · intro y hy + induction hy with + | refl => exact conn_refl G _ x + | @tail a b _ hab ih => + obtain ⟨e,he,hab⟩ := hab + have ha := finite_cluster_subset_reachBall G (ω ∩ (Q : Set E)) x hf C hC ih + have heQ := hQ ((mem_incidentSupport G hloc _ e).mpr + ⟨a,by simpa only [Set.Finite.mem_toFinset] using ha,by simp [hab]⟩) + exact ih.tail ⟨e,⟨he,heQ⟩,hab⟩ + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +noncomputable def amplificationMarginal (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : ℝ := + finiteRootLoad Q (Finset.Icc 1 k) p + (finiteChoiceForwardLoad G x k Q (q.amplificationInputs Q B x k n z) + (fun r _ => amplificationVertices B k z r) (q.amplificationWeight B k z)) (restrictFiniteField Q ω) + +theorem amplificationMarginal_local (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : + q.amplificationMarginal Q B x k n z p ω = + q.amplificationMarginal Q B x k n z p (ω ∩ (Q : Set E)) := by + unfold amplificationMarginal + congr 1 + apply (finiteFieldSet_injective Q) + simp only [finiteFieldSet_restrict,Set.inter_assoc,Set.inter_self] + +theorem amplificationMarginal_bounds (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : + 0 ≤ q.amplificationMarginal Q B x k n z p ω ∧ + q.amplificationMarginal Q B x k n z p ω ≤ inverseCodeMass M L ^ k := by + have hb := finiteChoiceForwardLoad_bounds G hloc x z.val k M L hL Q + (q.amplificationInputs Q B x k n z) (fun r _ => amplificationVertices B k z r) + (q.amplificationWeight B k z) (q.amplificationWeight_nonneg B k z) + (q.amplificationWeight_row B k z) (q.amplificationInputs_subset Q B x k n z) + (fun _ _ _ => congrArg Subtype.val (oldRunVertices_last ..)) + (fun r s hs i hi hik => (q.amplificationInputs_chain Q B x k n z r s hs i hi hik).2) + exact ⟨finiteRootLoad_nonneg _ _ p _ (fun s _ => (hb s).1) _, + finiteRootLoad_le _ _ p _ _ (fun s _ => (hb s).2) _⟩ + +theorem amplificationMarginal_support (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) + (h : q.amplificationMarginal Q B x k n z p ω ≠ 0) : + x ∈ O ∧ z.val ∈ O ∧ Conn G (ω ∩ (Q : Set E)) x z.val ∧ + (cluster G (ω ∩ (Q : Set E)) x).Finite ∧ + (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ 2*n+k*M := by + let A := q.amplificationInputs Q B x k n z + let y := fun r (_ : SpliceState E) => amplificationVertices B k z r + let I := FiniteChoiceTraceIndex G x k Q A y + let out := choiceTraceOutput G x k Q A y + have ho (a : I) : out a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := + traceIndexOutput_mem G x k Q (A a.1) (y a.1) (q.amplificationInputs_subset Q B x k n z a.1) a.2 + have he := finiteRootLoad_eq_sum Q (Finset.Icc 1 k) p out + (choiceTraceMass G x k Q A y (q.amplificationWeight B k z)) ho (restrictFiniteField Q ω) + have ha : ∃ a : I, (out a).1 = ω ∩ (Q : Set E) := by + by_contra hn + push Not at hn + apply h + change finiteRootLoad Q (Finset.Icc 1 k) p (finiteInverseLoad out _) _ = 0 + rw [he,finiteFieldSet_restrict] + simp only [hn,ite_false,Finset.sum_const_zero] + obtain ⟨a,ha⟩ := ha + have ht := (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1 + have hs := q.amplificationTrace_support Q B x k n z a.1 a.2.1.val a.2.1.property + (choiceTraceCode G x k Q A y a) (out a).1 ht + rwa [ha] at hs + +theorem amplificationMarginal_physical_support (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) + (hQ : incidentSupport G hloc (finite_reachBall hloc x (2*n+k*M)).toFinset ⊆ Q) + (h : q.amplificationMarginal Q B x k n z p ω ≠ 0) : + x ∈ O ∧ z.val ∈ O ∧ Conn G ω x z.val ∧ (cluster G ω x).Finite ∧ + (cluster G ω x).ncard ≤ 2*n+k*M := by + obtain ⟨hx,hz,hc,hf,hcap⟩ := q.amplificationMarginal_support Q B x k n z p ω h + have he := cluster_restrict_of_cap G hloc Q ω x (2*n+k*M) hQ hf hcap + exact ⟨hx,hz,conn_mono G Set.inter_subset_left hc,he ▸ hf,he ▸ hcap⟩ + + + +theorem amplificationMarginal_mean [Nonempty E] (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) : + (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = + ∑ r, ∑ s ∈ q.amplificationInputs Q B x k n z r, + spliceTupleWeight Q (Finset.Icc 1 k) p s * q.amplificationWeight B k z s r := by + rw [integral_finite_local Q p _ (q.amplificationMarginal_local Q B x k n z p)] + simp only [amplificationMarginal,restrictFiniteField_fieldSet] + rw [finiteRootLoad_mean] + apply finiteChoiceForwardLoad_mean G hloc x k M Q p + · exact q.amplificationInputs_subset Q B x k n z + · intro r s hs + exact ((q.mem_amplificationInputs Q B x k n z r s).mp hs).2.2.2.2.2.1 + · intro r s hs i hi + exact (q.amplificationInputs_chain Q B x k n z r s hs i + (Finset.mem_Icc.mp hi).1 (Finset.mem_Icc.mp hi).2).1 + · intro r s hs i hi + have hc := q.amplificationInputs_chain Q B x k n z r s hs i + (Finset.mem_Icc.mp hi).1 (Finset.mem_Icc.mp hi).2 + exact ⟨hc.2.1,hc.2.2.1⟩ + +end LocalEndpointRule +end AmplificationMarginal + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AmplificationMeanKernel +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finiteSpliceDomain_integral_factor (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (f : Set E → ℝ) (g : (ℕ → Set E) → ℝ) : + (∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s * f s.1 * g s.2) = + finiteFieldIntegral Q p f * finiteFamilyIntegral Q J p g := by + have hh := finiteRootLoad_mean Q J p (fun s => f s.1 * g s.2) + simp only [← mul_assoc] at hh + rw [← hh] + simp only [finiteRootLoad,finiteFieldIntegral,finiteFamilyIntegral,Finset.sum_mul] + apply Finset.sum_congr rfl + intro ω _ + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro η _ + ring + + +noncomputable def finiteBinConnection (G : BondGraph V E) (Q : Finset E) (p : ℝ) + (x : V) (n : ℕ) (y : V) : ℝ := finiteFieldIntegral Q p (fun ω => + if n ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < 2*n ∧ y ∈ cluster G ω x then 1 else 0) + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +theorem finiteOldKernel_eq_kernel (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (p : unitInterval) (a b : V) + (hQ : incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : + finiteOldKernel Q p q.mass a b = q.kernel p a b := by + symm + exact integral_finite_local Q p _ (finite_local_of_subset _ Q hQ _ (q.locality · a b)) + + + +theorem amplificationMarginal_mean_kernel [Nonempty E] (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) + (hx : x ∈ O) (hz : z.val ∈ O) + (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : + (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = + ∑ r : Fin k → ↥B, finiteBinConnection G Q p x n (amplificationVertices B k z r 0) * + oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r := by + rw [q.amplificationMarginal_mean Q B x k n z p] + apply Finset.sum_congr rfl + intro r _ + let f : Set E → ℝ := fun ω => if n ≤ (cluster G ω x).ncard ∧ + (cluster G ω x).ncard < 2*n ∧ amplificationVertices B k z r 0 ∈ cluster G ω x then 1 else 0 + let g : (ℕ → Set E) → ℝ := fun η => + oldRunWeight (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z r + have he : (∑ s ∈ q.amplificationInputs Q B x k n z r, + spliceTupleWeight Q (Finset.Icc 1 k) p s * q.amplificationWeight B k z s r) = + ∑ s ∈ finiteSpliceDomain Q (Finset.Icc 1 k), spliceTupleWeight Q (Finset.Icc 1 k) p s * f s.1 * g s.2 := by + rw [amplificationInputs,Finset.sum_filter] + apply Finset.sum_congr rfl + intro s _ + change (if _ then _ else _) = _ + by_cases hw : q.amplificationWeight B k z s r = 0 + · have hg : g s.2 = 0 := hw + simp [hx,hz,hw,hg] + · simp only [hx,hz,true_and,hw,ne_eq,not_false_eq_true,and_true] + by_cases hbin : n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ + amplificationVertices B k z r 0 ∈ cluster G s.1 x + · simp [f,hbin,g,amplificationWeight] + · simp only [hbin,ite_false,f,mul_zero,zero_mul] + rw [he,finiteSpliceDomain_integral_factor] + dsimp only [g] + rw [oldRunWeight_integral Q p k (fun ω (a b : ↥B) => q.mass ω a.val b.val) z r] + change finiteBinConnection G Q p x n _ * _ = _ + congr 1 + apply congrArg (fun K : ℕ → ↥B → ↥B → ℝ => oldRunWeight K k z r) + funext i a b + exact q.finiteOldKernel_eq_kernel Q p a.val b.val (hQ a.val a.property) + +end LocalEndpointRule +end AmplificationMeanKernel + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section BinConnection +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def binConnectionMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : ℝ := + if (cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ + (cluster G ω x).ncard < 2*n ∧ Conn G ω x y then 1 else 0 + +theorem binConnectionMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : + 0 ≤ binConnectionMass G n ω x y := by unfold binConnectionMass; split_ifs <;> norm_num + +theorem binConnectionMass_symm (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : + binConnectionMass G n ω x y = binConnectionMass G n ω y x := by + by_cases hc : Conn G ω x y + · have he := cluster_eq_of_conn G ω hc + simp only [binConnectionMass,hc,conn_symm G ω hc,and_true,he] + · have hc' : ¬Conn G ω y x := fun h => hc (conn_symm G ω h) + simp only [binConnectionMass,hc,hc',and_false,ite_false] + +theorem binConnectionMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (ω : Set E) (x y : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binConnectionMass G n ω x y = binConnectionMass G n (ω ∩ (Q : Set E)) x y := by + dsimp only + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + have hp : ((cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ + (cluster G ω x).ncard < 2*n ∧ Conn G ω x y) ↔ + ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ n ≤ (cluster G (ω ∩ (Q : Set E)) x).ncard ∧ + (cluster G (ω ∩ (Q : Set E)) x).ncard < 2*n ∧ Conn G (ω ∩ (Q : Set E)) x y) := by + constructor + · rintro ⟨hf,hn,hN,hc⟩ + have hs : cluster G ω x ⊆ (finite_reachBall hloc x (2*n)).toFinset := by + simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hf (2*n) hN.le + have he := cluster_restrict_incident_of_full G hloc _ ω x hs + change cluster G (ω ∩ (Q : Set E)) x = cluster G ω x at he + refine ⟨he.symm ▸ hf,he.symm ▸ hn,he.symm ▸ hN,?_⟩ + change y ∈ cluster G (ω ∩ (Q : Set E)) x + rw [he] + exact hc + · rintro ⟨hf,hn,hN,hc⟩ + have he := cluster_restrict_of_cap G hloc Q ω x (2*n) (Finset.Subset.refl _) hf hN.le + exact ⟨he ▸ hf,he ▸ hn,he ▸ hN,conn_mono G Set.inter_subset_left hc⟩ + exact if_congr hp rfl rfl + +theorem binConnectionMass_support (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (h : binConnectionMass G n ω x y ≠ 0) : + (cluster G ω x).Finite ∧ (cluster G ω x).ncard < 2*n ∧ Conn G ω x y := by + unfold binConnectionMass at h + split_ifs at h with hp + · exact ⟨hp.1,hp.2.2.1,hp.2.2.2⟩ + · exact (h rfl).elim + +theorem binConnectionMass_outside (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (hy : y ∉ reachBall G x (2*n)) : binConnectionMass G n ω x y = 0 := by + by_contra h + obtain ⟨hf,hN,hc⟩ := binConnectionMass_support G n ω x y h + exact hy (finite_cluster_subset_reachBall G ω x hf (2*n) hN.le hc) + +theorem binConnectionMass_row (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : + (∑' y, binConnectionMass G n ω x y) ≤ 2*n := by + by_cases hb : (cluster G ω x).Finite ∧ n ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < 2*n + · have hs : (∑' y, binConnectionMass G n ω x y) = (cluster G ω x).ncard := by + rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by + have hc : ¬Conn G ω x y := fun h => hy (hb.1.mem_toFinset.mpr h) + simp only [binConnectionMass,hc,and_false,ite_false])] + have he : (∑ y ∈ hb.1.toFinset, binConnectionMass G n ω x y) = + ∑ _y ∈ hb.1.toFinset, (1 : ℝ) := by + apply Finset.sum_congr rfl + intro y hy + exact ite_eq_left ⟨hb.1,hb.2.1,hb.2.2,hb.1.mem_toFinset.mp hy⟩ + rw [he] + simp only [Finset.sum_const,nsmul_eq_mul,mul_one] + exact_mod_cast (Set.ncard_eq_toFinset_card _ hb.1).symm + rw [hs] + exact_mod_cast hb.2.2.le + · have hz (y : V) : binConnectionMass G n ω x y = 0 := by + apply ite_eq_right + exact fun h => hb ⟨h.1,h.2.1,h.2.2.1⟩ + simp only [hz,tsum_zero] + positivity + +noncomputable def binConnection (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : ℝ := + ∫ ω, binConnectionMass G n ω x y ∂law p + +theorem binConnection_nonneg (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : + 0 ≤ binConnection G p n x y := integral_nonneg fun ω => binConnectionMass_nonneg G n ω x y + +theorem binConnection_symm (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : + binConnection G p n x y = binConnection G p n y x := + integral_congr_ae (ae_of_all _ fun ω => binConnectionMass_symm G n ω x y) + +theorem binConnection_outside (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) + (hy : y ∉ reachBall G x (2*n)) : binConnection G p n x y = 0 := by + simp only [binConnection,fun ω => binConnectionMass_outside G n ω x y hy,integral_zero] + +theorem binConnection_row (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) (x : V) : (∑' y, binConnection G p n x y) ≤ 2*n := by + let B := (finite_reachBall hloc x (2*n)).toFinset + let Q := incidentSupport G hloc B + have hi (y : V) : Integrable (fun ω => binConnectionMass G n ω x y) (law p) := + integrable_finite_local Q p _ (fun ω => binConnectionMass_local G hloc n ω x y) + have he (ω : Set E) : (∑' y, binConnectionMass G n ω x y) = ∑ y ∈ B, binConnectionMass G n ω x y := + tsum_eq_sum fun y hy => binConnectionMass_outside G n ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + have hs : (∑' y, binConnection G p n x y) = ∑ y ∈ B, binConnection G p n x y := + tsum_eq_sum fun y hy => binConnection_outside G p n x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + rw [hs] + simp only [binConnection] + rw [← integral_finsetSum B (fun y _ => hi y)] + calc + _ ≤ ∫ _ω, (2*n : ℝ) ∂law p := integral_mono (integrable_finsetSum B (fun y _ => hi y)) + (integrable_const _) (fun ω => (he ω).symm ▸ binConnectionMass_row G n ω x) + _ = 2*n := by simp + + + +theorem exists_binConnection_operator (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ 2*n ∧ + ∀ x y, A (lp.single 2 y (1:ℂ)) x = (binConnection G p n x y : ℂ) := by + have hs (x : V) : Summable (binConnection G p n x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) + intro y hy + exact binConnection_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) + have hr (x : V) (S : Finset V) : (∑ y ∈ S, binConnection G p n x y) ≤ 2*n := + ((hs x).sum_le_tsum S (fun y _ => binConnection_nonneg G p n x y)).trans (binConnection_row G hloc p n x) + apply exists_operator_of_row_column_bound (binConnection G p n) (2*n) (by positivity) (binConnection_nonneg G p n) hr + intro y S + simpa only [binConnection_symm G p n] using hr y S + +end BinConnection + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteBinConnection +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteBinConnection_eq_binConnection (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (p : unitInterval) (x : V) (n : ℕ) (y : V) + (hQ : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) : + finiteBinConnection G Q p x n y = binConnection G p n x y := by + rw [binConnection, integral_finite_local Q p _ + (finite_local_of_subset _ Q hQ _ (fun ω => binConnectionMass_local G hloc n ω x y))] + unfold finiteBinConnection finiteFieldIntegral + apply Finset.sum_congr rfl + intro ω _ + congr 1 + have hf : (cluster G (finiteFieldSet Q ω) x).Finite := + cluster_finite_of_finite_edges G ω.val.finite_toSet x + unfold cluster at hf + simp only [binConnectionMass,cluster,Set.mem_ofPred_eq,hf,true_and] + exact if_congr Iff.rfl rfl rfl + +end FiniteBinConnection + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PositivePathOperator +attribute [local instance] Classical.propDecidable Classical.decEq + + +def PositiveRealMatrix (A : Hilbert V →L[ℂ] Hilbert V) : Prop := + ∀ x y, (matrixCoeff A x y).im = 0 ∧ 0 ≤ (matrixCoeff A x y).re + +namespace PositiveRealMatrix +variable {A H : Hilbert V →L[ℂ] Hilbert V} + +theorem real (hA : PositiveRealMatrix A) (x y : V) : + matrixCoeff A x y = ((matrixCoeff A x y).re : ℂ) := by + apply Complex.ext + · rfl + · exact (hA x y).1 + +theorem mul_hasSum (hA : PositiveRealMatrix A) (H : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + HasSum (fun z => (matrixCoeff A x z).re * (matrixCoeff H z y).re) + (matrixCoeff (A*H) x y).re := by + have h := Complex.reCLM.hasSum (operator_kernel_hasSum A (H (lp.single 2 y (1:ℂ))) x) + change HasSum (fun z => (matrixCoeff A x z * matrixCoeff H z y).re) + (matrixCoeff (A*H) x y).re at h + simpa only [Complex.mul_re,(hA _ _).1,zero_mul,sub_zero] using h + +theorem mul (hA : PositiveRealMatrix A) (hH : PositiveRealMatrix H) : + PositiveRealMatrix (A*H) := by + intro x y + constructor + · have hs := (operator_kernel_hasSum A (H (lp.single 2 y (1:ℂ))) x).summable + change Summable (fun z => matrixCoeff A x z * matrixCoeff H z y) at hs + rw [matrixCoeff_mul,Complex.im_tsum hs] + simp only [Complex.mul_im,(hA _ _).1,(hH _ _).1,mul_zero,zero_mul,add_zero,tsum_zero] + · rw [← (hA.mul_hasSum H x y).tsum_eq] + exact tsum_nonneg fun z => mul_nonneg (hA x z).2 (hH z y).2 + +theorem one : PositiveRealMatrix (1 : Hilbert V →L[ℂ] Hilbert V) := by + intro x y + simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply] + split_ifs <;> norm_num + +theorem pow (hA : PositiveRealMatrix A) (k : ℕ) : PositiveRealMatrix (A^k) := by + induction k with + | zero => simpa only [pow_zero] using (one (V := V)) + | succ k ih => rw [pow_succ]; exact ih.mul hA + +theorem star (hA : PositiveRealMatrix A) : PositiveRealMatrix (star A) := by + intro x y + simpa only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_im,Complex.conj_re,neg_eq_zero] using hA y x + +end PositiveRealMatrix + + + +theorem oldRun_test_succ {W : Type*} [Fintype W] + (K : ℕ → W → W → ℝ) (F : W → ℝ) (k : ℕ) (z : W) : + (∑ r : Fin (k+1) → W, oldRunWeight K (k+1) z r * F (oldRunVertices (k+1) z r 0)) = + ∑ a : W, K (k+1) z a * + ∑ r : Fin k → W, oldRunWeight K k a r * F (oldRunVertices k a r 0) := by + rw [Fintype.sum_equiv (oldRunConsEquiv k) _ + (fun r => K (k+1) z r.1 * oldRunWeight K k r.1 r.2 * F (oldRunVertices k r.1 r.2 0)) + (by intro r; simp only [oldRunWeight,oldRunConsEquiv,Equiv.coe_fn_mk, + oldRunVertices_succ_of_le k z r 0 (Nat.zero_le k)]), Fintype.sum_prod_type] + simp only [Finset.mul_sum,mul_assoc] + + + +theorem finite_oldRun_operator_domination (A H : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) (hH : PositiveRealMatrix H) + (B : Finset V) (k : ℕ) (z : ↥B) (x : V) : + (∑ r : Fin k → ↥B, + oldRunWeight (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) k z r * + (matrixCoeff H (oldRunVertices k z r 0).val x).re) ≤ + (matrixCoeff (A^k*H) z.val x).re := by + induction k generalizing z with + | zero => simp [oldRunWeight,oldRunVertices] + | succ k ih => + rw [oldRun_test_succ (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) + (fun a : ↥B => (matrixCoeff H a.val x).re) k z] + calc + _ ≤ ∑ a : ↥B, (matrixCoeff A z.val a.val).re * (matrixCoeff (A^k*H) a.val x).re := + Finset.sum_le_sum fun a _ => mul_le_mul_of_nonneg_left (ih a) (hA z.val a.val).2 + _ ≤ ∑' a, (matrixCoeff A z.val a).re * (matrixCoeff (A^k*H) a x).re := by + rw [Finset.sum_coe_sort B (fun a => (matrixCoeff A z.val a).re * (matrixCoeff (A^k*H) a x).re)] + exact (hA.mul_hasSum (A^k*H) z.val x).summable.sum_le_tsum B + (fun a _ => mul_nonneg (hA z.val a).2 (((hA.pow k).mul hH) a x).2) + _ = (matrixCoeff (A^(k+1)*H) z.val x).re := by + rw [(hA.mul_hasSum (A^k*H) z.val x).tsum_eq,pow_succ',mul_assoc] + +end PositivePathOperator + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section OrbitBinOperator +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem isAut_trans (G : BondGraph V E) {a c : V ≃ V} {b d : E ≃ E} + (hab : IsAut G a b) (hcd : IsAut G c d) : IsAut G (a.trans c) (b.trans d) := by + intro e + change G (d (b e)) = (G e).map (c ∘ a) + rw [hcd,hab,Sym2.map_map] + +theorem mem_vertexOrbit_aut_iff (G : BondGraph V E) (o : V) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) : a x ∈ vertexOrbit G o ↔ x ∈ vertexOrbit G o := by + constructor + · rintro ⟨c,d,hcd,hc⟩ + refine ⟨c.trans a.symm,d.trans b.symm,isAut_trans G hcd (isAut_symm G hab),?_⟩ + simp only [Equiv.trans_apply,hc,Equiv.symm_apply_apply] + · rintro ⟨c,d,hcd,rfl⟩ + exact ⟨c.trans a,d.trans b,isAut_trans G hcd hab,rfl⟩ + +theorem binConnectionMass_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (n : ℕ) (ω : Set E) (x y : V) : + binConnectionMass G n (b ⁻¹' ω) x y = binConnectionMass G n ω (a x) (a y) := by + have hf : (cluster G (b ⁻¹' ω) x).Finite ↔ (cluster G ω (a x)).Finite := by + rw [← cluster_aut G hab ω x] + exact (Set.finite_image_iff a.injective.injOn).symm + have hn : (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by + rw [← cluster_aut G hab ω x,Set.ncard_image_of_injective _ a.injective] + simp only [binConnectionMass,hf,hn,conn_aut_iff G hab] + +theorem binConnection_covariant (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : + binConnection G p n (a x) (a y) = binConnection G p n x y := by + have hm : Measurable (fun ω => binConnectionMass G n ω x y) := + measurable_finite_local _ _ (fun ω => binConnectionMass_local G hloc n ω x y) + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [binConnection,binConnectionMass_covariant G hab] using h.symm + + +noncomputable def orbitBinConnection (G : BondGraph V E) (p : unitInterval) (o : V) + (n : ℕ) (x y : V) : ℝ := + if x ∈ vertexOrbit G o ∧ y ∈ vertexOrbit G o then binConnection G p n x y else 0 + +theorem orbitBinConnection_nonneg (G : BondGraph V E) (p : unitInterval) (o : V) + (n : ℕ) (x y : V) : 0 ≤ orbitBinConnection G p o n x y := by + unfold orbitBinConnection + split_ifs + · exact binConnection_nonneg G p n x y + · exact le_rfl + +theorem orbitBinConnection_symm (G : BondGraph V E) (p : unitInterval) (o : V) + (n : ℕ) (x y : V) : orbitBinConnection G p o n x y = orbitBinConnection G p o n y x := by + simp only [orbitBinConnection,and_comm,binConnection_symm G p n] + +theorem orbitBinConnection_covariant (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : + orbitBinConnection G p o n (a x) (a y) = orbitBinConnection G p o n x y := by + simp only [orbitBinConnection,mem_vertexOrbit_aut_iff G o hab,binConnection_covariant G hloc p hab n] + +theorem orbitBinConnection_summable (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (x : V) : Summable (orbitBinConnection G p o n x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) + intro y hy + have hz := binConnection_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) + simp only [orbitBinConnection,hz,ite_self] + +noncomputable def binOrbitRow (G : BondGraph V E) (p : unitInterval) (o : V) (n : ℕ) : ℝ := + ∑' y, orbitBinConnection G p o n o y + +theorem orbitBinConnection_row (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (x : V) (hx : x ∈ vertexOrbit G o) : + (∑' y, orbitBinConnection G p o n x y) = binOrbitRow G p o n := by + obtain ⟨a,b,hab,rfl⟩ := hx + rw [← a.tsum_eq (fun y => orbitBinConnection G p o n (a o) y)] + exact tsum_congr (fun y => orbitBinConnection_covariant G hloc p o hab n o y) + +theorem orbitBinConnection_row_le (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) (x : V) : + (∑' y, orbitBinConnection G p o n x y) ≤ binOrbitRow G p o n := by + by_cases hx : x ∈ vertexOrbit G o + · exact (orbitBinConnection_row G hloc p o n x hx).le + · simp only [orbitBinConnection,hx,false_and,ite_false,tsum_zero] + exact tsum_nonneg (orbitBinConnection_nonneg G p o n o) + + + +theorem exists_orbitBinConnection_operator (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (n : ℕ) : + ∃ H : Hilbert V →L[ℂ] Hilbert V, ‖H‖ ≤ binOrbitRow G p o n ∧ + ∀ x y, matrixCoeff H x y = (orbitBinConnection G p o n x y : ℂ) := by + have hr (x : V) (S : Finset V) : (∑ y ∈ S, orbitBinConnection G p o n x y) ≤ binOrbitRow G p o n := + ((orbitBinConnection_summable G hloc p o n x).sum_le_tsum S + (fun y _ => orbitBinConnection_nonneg G p o n x y)).trans (orbitBinConnection_row_le G hloc p o n x) + exact exists_operator_of_row_column_bound (orbitBinConnection G p o n) (binOrbitRow G p o n) + (tsum_nonneg (orbitBinConnection_nonneg G p o n o)) (orbitBinConnection_nonneg G p o n) hr + (fun y S => by simpa only [orbitBinConnection_symm G p o n] using hr y S) + +end OrbitBinOperator + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open MeasureTheory +section AmplificationOperatorDomination +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem oldRun_endpoint_mem {W : Type*} (P : W → Prop) (K : ℕ → W → W → ℝ) + (hK : ∀ i a b, K i a b ≠ 0 → P b) (k : ℕ) (z : W) (hz : P z) + (r : Fin k → W) (hr : oldRunWeight K k z r ≠ 0) : P (oldRunVertices k z r 0) := by + induction k generalizing z with + | zero => exact hz + | succ k ih => + have hm := mul_ne_zero_iff.mp hr + rw [oldRunVertices_succ_of_le _ _ _ _ (Nat.zero_le k)] + exact ih (r 0) (hK _ _ _ hm.1) (Fin.tail r) hm.2 + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem amplificationMarginal_operator_le [Nonempty E] (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) + (hx : x ∈ vertexOrbit G o) (hz : z.val ∈ vertexOrbit G o) + (hroot : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) + (hquery : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) + (A H : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ a b, matrixCoeff A a b = (q.kernel p a b : ℂ)) + (hH : ∀ a b, matrixCoeff H a b = (orbitBinConnection G p o n a b : ℂ)) : + (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) ≤ + (matrixCoeff (A^k*H) z.val x).re := by + have hposA : PositiveRealMatrix A := fun a b => by + rw [hA a b] + exact ⟨rfl,q.kernel_nonneg p a b⟩ + have hposH : PositiveRealMatrix H := fun a b => by + rw [hH a b] + exact ⟨rfl,orbitBinConnection_nonneg G p o n a b⟩ + rw [q.amplificationMarginal_mean_kernel Q B x k n z p hx hz hquery] + have he : (∑ r : Fin k → ↥B, finiteBinConnection G Q p x n (amplificationVertices B k z r 0) * + oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r) = + ∑ r : Fin k → ↥B, + oldRunWeight (fun _ (a b : ↥B) => (matrixCoeff A a.val b.val).re) k z r * + (matrixCoeff H (oldRunVertices k z r 0).val x).re := by + apply Finset.sum_congr rfl + intro r _ + simp only [hA,hH,Complex.ofReal_re, + finiteBinConnection_eq_binConnection G hloc Q p x n _ hroot] + by_cases hr : oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r = 0 + · simp only [hr,mul_zero,zero_mul] + · have hy : (oldRunVertices k z r 0).val ∈ vertexOrbit G o := + oldRun_endpoint_mem (fun a : ↥B => a.val ∈ vertexOrbit G o) + (fun _ (a b : ↥B) => q.kernel p a.val b.val) + (fun _ a b hab => by + by_contra hb + exact hab (q.kernel_zero_of_end_not_mem p a.val b.val hb)) k z hz r hr + rw [orbitBinConnection,ite_eq_left ⟨hy,hx⟩,binConnection_symm G p n] + exact mul_comm _ _ + rw [he] + exact finite_oldRun_operator_domination A H hposA hposH B k z x + +end LocalEndpointRule + + + +theorem exists_operator_of_amplification_domination + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (o : V) (n k : ℕ) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (F : V → V → ℝ) (hF : ∀ x z, 0 ≤ F x z) + (hdom : ∀ (H : Hilbert V →L[ℂ] Hilbert V), + (∀ x y, matrixCoeff H x y = (orbitBinConnection G p o n x y : ℂ)) → + ∀ x z, F x z ≤ (matrixCoeff (A^k*H) z x).re) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ binOrbitRow G p o n * ‖A‖^k ∧ + ∀ x z, matrixCoeff T x z = (F x z : ℂ) := by + obtain ⟨H,hHnorm,hH⟩ := exists_orbitBinConnection_operator G hloc p o n + have hposH : PositiveRealMatrix H := fun x y => by + rw [hH x y] + exact ⟨rfl,orbitBinConnection_nonneg G p o n x y⟩ + have hpos := ((hA.pow k).mul hposH).star + have htr (x z : V) : (matrixCoeff (star (A^k*H)) x z).re = (matrixCoeff (A^k*H) z x).re := by + simp only [matrixCoeff_adjoint,Complex.star_def,Complex.conj_re] + obtain ⟨T,hTnorm,hT⟩ := exists_operator_of_matrix_domination + (fun x z => (matrixCoeff (star (A^k*H)) x z).re) F (fun x z => (hpos x z).2) + (fun x z => by rw [abs_of_nonneg (hF x z),htr]; exact hdom H hH x z) + (star (A^k*H)) (fun x z => hpos.real x z) + refine ⟨T,hTnorm.trans ?_,hT⟩ + have hpow : ∀ j : ℕ, ‖A^j‖ ≤ ‖A‖^j := by + intro j + induction j with + | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) + | succ j ih => + rw [pow_succ, pow_succ] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg _)) + calc + ‖star (A^k*H)‖ = ‖A^k*H‖ := by + change ‖ContinuousLinearMap.adjoint (A^k*H)‖ = _ + exact LinearIsometryEquiv.norm_map _ _ + _ ≤ ‖A^k‖ * ‖H‖ := norm_mul_le _ _ + _ ≤ ‖A‖^k * binOrbitRow G p o n := mul_le_mul (hpow k) hHnorm + (norm_nonneg _) (pow_nonneg (norm_nonneg _) _) + _ = binOrbitRow G p o n * ‖A‖^k := mul_comm _ _ + +end AmplificationOperatorDomination + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterVisitKernel +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +noncomputable def conditionalSuccess (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : ℝ := + ∑' y, q.mass ω x y + +theorem conditionalSuccess_nonneg (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : + 0 ≤ q.conditionalSuccess ω x := tsum_nonneg (q.nonneg ω x) + +theorem conditionalSuccess_support (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) + (h : q.conditionalSuccess ω x ≠ 0) : + x ∈ O ∧ (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M := by + have he : ∃ y, q.mass ω x y ≠ 0 := by + by_contra hn + push Not at hn + exact h (by simp only [conditionalSuccess,hn,tsum_zero]) + obtain ⟨y,hy⟩ := he + obtain ⟨hx,_,_,hf,hc,_⟩ := q.support ω x y hy + exact ⟨hx,hf,hc⟩ + +theorem conditionalSuccess_local (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : + q.conditionalSuccess ω x = q.conditionalSuccess + (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset : Set E)) x := + tsum_congr (q.locality ω x) + +theorem conditionalSuccess_integrable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + Integrable (fun ω => q.conditionalSuccess ω x) (law p) := + integrable_finite_local _ p _ (fun ω => q.conditionalSuccess_local ω x) + +theorem conditionalSuccess_mean (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + (∫ ω, q.conditionalSuccess ω x ∂law p) = q.successProbability p x := + (q.kernel_row_integral p x).symm + +theorem conditionalSuccess_covariant (q : LocalEndpointRule G hloc O M L) + (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x : V) : + q.conditionalSuccess (b ⁻¹' ω) x = q.conditionalSuccess ω (a x) := by + unfold conditionalSuccess + simp_rw [q.covariance a b hab] + exact a.tsum_eq _ + + + +noncomputable def clusterVisitMass (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : ℝ := + if a ∈ cluster G ω x then q.conditionalSuccess ω x else 0 + +theorem clusterVisitMass_nonneg (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : + 0 ≤ q.clusterVisitMass ω x a := by + unfold clusterVisitMass + split_ifs + · exact q.conditionalSuccess_nonneg ω x + · exact le_refl _ + +theorem clusterVisitMass_outside (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) + (ha : a ∉ reachBall G x M) : q.clusterVisitMass ω x a = 0 := by + by_cases h : q.conditionalSuccess ω x = 0 + · simp only [clusterVisitMass,h,ite_self] + · obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h + exact ite_eq_right (fun hmem => ha (finite_cluster_subset_reachBall G ω x hf M hc hmem)) + +theorem clusterVisitMass_local (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x a : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset + q.clusterVisitMass ω x a = q.clusterVisitMass (ω ∩ (Q : Set E)) x a := by + dsimp only + let Q := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset + change q.clusterVisitMass ω x a = q.clusterVisitMass (ω ∩ (Q:Set E)) x a + have he := finite_local_of_subset _ Q + (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) + (fun ω => q.conditionalSuccess ω x) (fun ω => q.conditionalSuccess_local ω x) ω + by_cases h : q.conditionalSuccess ω x = 0 + · have h' : q.conditionalSuccess (ω ∩ (Q:Set E)) x = 0 := he.symm.trans h + simp only [clusterVisitMass,h,h',ite_self] + · obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h + have hs : cluster G ω x ⊆ (finite_reachBall hloc x (max q.radius M)).toFinset := by + simpa only [Set.Finite.coe_toFinset] using + finite_cluster_subset_reachBall G ω x hf _ (hc.trans (le_max_right _ _)) + have hc' := cluster_restrict_incident_of_full G hloc _ ω x hs + change cluster G (ω ∩ (Q:Set E)) x = cluster G ω x at hc' + change (if a ∈ cluster G ω x then _ else _) = (if a ∈ cluster G (ω ∩ (Q:Set E)) x then _ else _) + rw [hc',he] + +theorem clusterVisitMass_integrable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) : + Integrable (fun ω => q.clusterVisitMass ω x a) (law p) := + integrable_finite_local _ p _ (fun ω => q.clusterVisitMass_local ω x a) + +theorem clusterVisitMass_covariant (q : LocalEndpointRule G hloc O M L) + (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (ω : Set E) (x y : V) : + q.clusterVisitMass (b ⁻¹' ω) x y = q.clusterVisitMass ω (a x) (a y) := by + have hc : y ∈ cluster G (b ⁻¹' ω) x ↔ a y ∈ cluster G ω (a x) := by + rw [← cluster_aut G hab ω x] + constructor + · intro hy; exact ⟨y,hy,rfl⟩ + · rintro ⟨z,hz,he⟩ + exact (a.injective he) ▸ hz + simp only [clusterVisitMass,hc,q.conditionalSuccess_covariant a b hab] + +theorem clusterVisitMass_row_le (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : + (∑' a, q.clusterVisitMass ω x a) ≤ M * q.conditionalSuccess ω x := by + by_cases h : q.conditionalSuccess ω x = 0 + · simp only [clusterVisitMass,h,ite_self,tsum_zero,mul_zero,le_refl] + obtain ⟨_,hf,hc⟩ := q.conditionalSuccess_support ω x h + rw [tsum_eq_sum (f := q.clusterVisitMass ω x) (s := hf.toFinset) (fun a ha => ite_eq_right (by simpa only [Set.Finite.mem_toFinset] using ha))] + have he : (∑ a ∈ hf.toFinset, q.clusterVisitMass ω x a) = + (hf.toFinset.card:ℝ) * q.conditionalSuccess ω x := by + calc + _ = ∑ _a ∈ hf.toFinset, q.conditionalSuccess ω x := Finset.sum_congr rfl (fun a ha => ite_eq_left (hf.mem_toFinset.mp ha)) + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul] + rw [he] + apply mul_le_mul_of_nonneg_right _ (q.conditionalSuccess_nonneg ω x) + exact_mod_cast (by simpa only [← Set.ncard_eq_toFinset_card _ hf] using hc) + +noncomputable def clusterVisitKernel (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (x a : V) : ℝ := ∫ ω, q.clusterVisitMass ω x a ∂law p + +theorem clusterVisitKernel_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) : + 0 ≤ q.clusterVisitKernel p x a := integral_nonneg (fun ω => q.clusterVisitMass_nonneg ω x a) + +theorem clusterVisitKernel_outside (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x a : V) + (ha : a ∉ reachBall G x M) : q.clusterVisitKernel p x a = 0 := by + simp only [clusterVisitKernel,q.clusterVisitMass_outside _ x a ha,integral_zero] + +theorem clusterVisitKernel_summable (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + Summable (q.clusterVisitKernel p x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro a ha + exact q.clusterVisitKernel_outside p x a (by simpa only [Set.Finite.mem_toFinset] using ha) + +theorem clusterVisitKernel_row_le (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + (∑' a, q.clusterVisitKernel p x a) ≤ M * q.successProbability p x := by + let B := (finite_reachBall hloc x M).toFinset + have he (ω : Set E) : (∑' a, q.clusterVisitMass ω x a) = ∑ a ∈ B, q.clusterVisitMass ω x a := + tsum_eq_sum (fun a ha => q.clusterVisitMass_outside ω x a (by simpa only [B,Set.Finite.mem_toFinset] using ha)) + rw [tsum_eq_sum (s := B) (fun a ha => q.clusterVisitKernel_outside p x a (by simpa only [B,Set.Finite.mem_toFinset] using ha))] + simp only [clusterVisitKernel] + rw [← integral_finsetSum B (fun a _ => q.clusterVisitMass_integrable p x a)] + calc + _ ≤ ∫ ω, (M:ℝ) * q.conditionalSuccess ω x ∂law p := + integral_mono (integrable_finsetSum B (fun a _ => q.clusterVisitMass_integrable p x a)) + ((q.conditionalSuccess_integrable p x).const_mul _) (fun ω => by rw [← he]; exact q.clusterVisitMass_row_le ω x) + _ = _ := by rw [integral_const_mul,q.conditionalSuccess_mean] + +theorem clusterVisitKernel_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x y : V) : + q.clusterVisitKernel p (a x) (a y) = q.clusterVisitKernel p x y := by + have hm : Measurable (fun ω => q.clusterVisitMass ω x y) := + measurable_finite_local _ _ (fun ω => q.clusterVisitMass_local ω x y) + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [clusterVisitKernel,q.clusterVisitMass_covariant a b hab] using h.symm + +end LocalEndpointRule +end ClusterVisitKernel + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section VisitEnvelope +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +noncomputable def visitEnvelope (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) : ℕ → V → V → ℝ + | 0, _, _ => 0 + | k+1, x, a => q.successProbability p o ^ k * q.clusterVisitKernel p x a + + ∑' y, q.kernel p x y * q.visitEnvelope o p k y a + +theorem visitEnvelope_nonneg (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (k : ℕ) (x a : V) : 0 ≤ q.visitEnvelope o p k x a := by + induction k generalizing x with + | zero => exact le_refl _ + | succ k ih => + exact add_nonneg (mul_nonneg (pow_nonneg (q.successProbability_nonneg p o) _) (q.clusterVisitKernel_nonneg p x a)) + (tsum_nonneg (fun y => mul_nonneg (q.kernel_nonneg p x y) (ih y))) + +theorem visitEnvelope_covariant (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (k : ℕ) (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x y : V) : + q.visitEnvelope o p k (a x) (a y) = q.visitEnvelope o p k x y := by + induction k generalizing x y with + | zero => rfl + | succ k ih => + simp only [visitEnvelope,q.clusterVisitKernel_covariant p a b hab] + congr 1 + rw [← a.tsum_eq (fun z => q.kernel p (a x) z * q.visitEnvelope o p k z (a y))] + exact tsum_congr fun z => by rw [q.kernel_covariant p a b hab,ih] + + + +theorem visitEnvelope_row_bound (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (k : ℕ) (x : V) : + Summable (q.visitEnvelope o p k x) ∧ + (∑' a, q.visitEnvelope o p k x a) ≤ (k*M:ℕ) * q.successProbability p o ^ k := by + let u := q.successProbability p o + have hu : 0 ≤ u := q.successProbability_nonneg p o + induction k generalizing x with + | zero => simp only [visitEnvelope,zero_mul,Nat.cast_zero,pow_zero,mul_one,tsum_zero,le_refl,and_true]; exact summable_zero + | succ k ih => + let B := (finite_reachBall hloc x M).toFinset + have he (a : V) : (∑' y, q.kernel p x y * q.visitEnvelope o p k y a) = + ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a := + tsum_eq_sum (fun y hy => by + rw [q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy),zero_mul]) + have ht (a : V) : q.visitEnvelope o p (k+1) x a = + u^k * q.clusterVisitKernel p x a + ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a := by + exact congrArg (_ + ·) (he a) + have hsum : Summable (fun a => ∑ y ∈ B, q.kernel p x y * q.visitEnvelope o p k y a) := + summable_sum (s := B) (fun y _ => (ih y).1.mul_left _) + have hs := ((q.clusterVisitKernel_summable p x).mul_left (u^k)).add hsum + have hs' : Summable (q.visitEnvelope o p (k+1) x) := by + change Summable (fun a => q.visitEnvelope o p (k+1) x a) + simpa only [ht] using hs + refine ⟨hs',?_⟩ + simp_rw [ht] + rw [Summable.tsum_add ((q.clusterVisitKernel_summable p x).mul_left _) hsum,tsum_mul_left, + Summable.tsum_finsetSum (fun y _ => (ih y).1.mul_left _)] + simp_rw [tsum_mul_left] + have hr : (∑ y ∈ B, q.kernel p x y) ≤ u := + ((q.summable_kernel p x).sum_le_tsum B (fun y _ => q.kernel_nonneg p x y)).trans + (q.kernel_row_le_success o p x) + calc + _ ≤ u^k * (M*u) + ∑ y ∈ B, q.kernel p x y * ((k*M:ℕ)*u^k) := by + apply add_le_add + · apply mul_le_mul_of_nonneg_left _ (pow_nonneg hu _) + exact (q.clusterVisitKernel_row_le p x).trans + (mul_le_mul_of_nonneg_left (q.kernel_row_le_success o p x) (Nat.cast_nonneg _)) + · exact Finset.sum_le_sum fun y _ => mul_le_mul_of_nonneg_left (ih y).2 (q.kernel_nonneg p x y) + _ ≤ u^k * (M*u) + u*((k*M:ℕ)*u^k) := by + rw [← Finset.sum_mul] + exact add_le_add (le_refl _) (mul_le_mul_of_nonneg_right hr (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg hu _))) + _ = ((k+1)*M:ℕ) * q.successProbability p o ^ (k+1) := by + change _ = ((k+1)*M:ℕ) * u^(k+1) + simp only [Nat.cast_mul,Nat.cast_add,Nat.cast_one,pow_succ] + ring + +end LocalEndpointRule +end VisitEnvelope + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section MarkedOldRun +attribute [local instance] Classical.propDecidable Classical.decEq +variable {W : Type*} + +theorem oldRunWeight_congr (K K' : ℕ → W → W → ℝ) (k : ℕ) + (h : ∀ i, 1 ≤ i → i ≤ k → ∀ a b, K i a b = K' i a b) (z : W) (r : Fin k → W) : + oldRunWeight K k z r = oldRunWeight K' k z r := by + induction k generalizing z with + | zero => rfl + | succ k ih => + simp only [oldRunWeight] + rw [h (k+1) (by omega) (by omega),ih (fun i hi hik => h i hi (by omega))] + +theorem oldRunWeight_prod (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : + oldRunWeight K k z r = ∏ i ∈ Finset.Icc 1 k, + K i (oldRunVertices k z r i) (oldRunVertices k z r (i-1)) := by + induction k generalizing z with + | zero => simp [oldRunWeight] + | succ k ih => + rw [Finset.prod_Icc_succ_top (by omega)] + have he : (∏ i ∈ Finset.Icc 1 k, K i (oldRunVertices (k+1) z r i) + (oldRunVertices (k+1) z r (i-1))) = oldRunWeight K k (r 0) (Fin.tail r) := by + rw [ih] + apply Finset.prod_congr rfl + intro i hi + have hi' := Finset.mem_Icc.mp hi + rw [oldRunVertices_succ_of_le _ _ _ _ hi'.2, + oldRunVertices_succ_of_le _ _ _ _ (by omega)] + rw [he,oldRunVertices_last,Nat.add_sub_cancel, + oldRunVertices_succ_of_le _ _ _ _ (le_refl _),oldRunVertices_last] + exact mul_comm _ _ + + + +noncomputable def markedOldRun (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : ℝ := + ∑ i ∈ Finset.Icc 1 k, oldRunWeight (fun j a b => if j = i then C j a b else K j a b) k z r + +theorem markedOldRun_nonneg (K C : ℕ → W → W → ℝ) + (hK : ∀ i a b, 0 ≤ K i a b) (hC : ∀ i a b, 0 ≤ C i a b) + (k : ℕ) (z : W) (r : Fin k → W) : 0 ≤ markedOldRun K C k z r := by + apply Finset.sum_nonneg + intro i _ + apply oldRunWeight_nonneg + intro j a b + split_ifs + · exact hC j a b + · exact hK j a b + +theorem markedOldRun_succ (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) (r : Fin (k+1) → W) : + markedOldRun K C (k+1) z r = + K (k+1) z (r 0) * markedOldRun K C k (r 0) (Fin.tail r) + + C (k+1) z (r 0) * oldRunWeight K k (r 0) (Fin.tail r) := by + unfold markedOldRun + rw [Finset.sum_Icc_succ_top (by omega),Finset.mul_sum] + congr 1 + · apply Finset.sum_congr rfl + intro i hi + have hne : k+1 ≠ i := by have := Finset.mem_Icc.mp hi; omega + simp only [oldRunWeight,ite_eq_right hne] + · simp only [oldRunWeight,ite_true] + congr 1 + apply oldRunWeight_congr + intro i hi hik a b + exact ite_eq_right (by omega) + +theorem sum_markedOldRun_succ [Fintype W] (K C : ℕ → W → W → ℝ) (k : ℕ) (z : W) : + (∑ r : Fin (k+1) → W, markedOldRun K C (k+1) z r) = + ∑ b : W, (K (k+1) z b * (∑ r : Fin k → W, markedOldRun K C k b r) + + C (k+1) z b * (∑ r : Fin k → W, oldRunWeight K k b r)) := by + rw [Fintype.sum_equiv (oldRunConsEquiv k) _ + (fun r => K (k+1) z r.1 * markedOldRun K C k r.1 r.2 + C (k+1) z r.1 * oldRunWeight K k r.1 r.2) + (by intro r; exact markedOldRun_succ K C k z r),Fintype.sum_prod_type] + simp only [Finset.sum_add_distrib,Finset.mul_sum] + + +theorem oldRunWeight_integral_indexed (Q : Finset E) (p : ℝ) + (q : ℕ → Set E → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => oldRunWeight (fun i => q i (η i)) k z r) = + oldRunWeight (fun i a b => finiteFieldIntegral Q p (fun ω => q i ω a b)) k z r := by + calc + _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + ∏ i : ↥(Finset.Icc 1 k), q i (η i) (oldRunVertices k z r i) + (oldRunVertices k z r (i.val-1))) := by + congr 1 + funext η + rw [oldRunWeight_prod] + exact (Finset.prod_coe_sort (Finset.Icc 1 k) + (fun i => q i (η i) (oldRunVertices k z r i) (oldRunVertices k z r (i-1)))).symm + _ = ∏ i : ↥(Finset.Icc 1 k), finiteFieldIntegral Q p (fun ω => + q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i.val-1))) := + finiteFamilyIntegral_prod Q (Finset.Icc 1 k) p + (fun i ω => q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i.val-1))) + _ = _ := by + rw [oldRunWeight_prod] + exact Finset.prod_coe_sort (Finset.Icc 1 k) (fun i => finiteFieldIntegral Q p + (fun ω => q i ω (oldRunVertices k z r i) (oldRunVertices k z r (i-1)))) + +theorem markedOldRun_integral (Q : Finset E) (p : ℝ) + (q c : ℕ → Set E → W → W → ℝ) (k : ℕ) (z : W) (r : Fin k → W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p + (fun η => markedOldRun (fun i => q i (η i)) (fun i => c i (η i)) k z r) = + markedOldRun (fun i a b => finiteFieldIntegral Q p (fun ω => q i ω a b)) + (fun i a b => finiteFieldIntegral Q p (fun ω => c i ω a b)) k z r := by + unfold markedOldRun + rw [finiteFamilyIntegral_sum] + apply Finset.sum_congr rfl + intro i _ + change finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + oldRunWeight (fun j => (fun ω a b => if j=i then c j ω a b else q j ω a b) (η j)) k z r) = _ + rw [oldRunWeight_integral_indexed Q p (fun j ω a b => if j=i then c j ω a b else q j ω a b) k z r] + congr 1 + funext j a b + by_cases h : j = i <;> simp only [h,ite_true,ite_false] + + + +theorem trajectory_indicator_le_marked (G : BondGraph V E) (e : W → V) + (q : Set E → W → W → ℝ) (hq : ∀ ω x y, 0 ≤ q ω x y) + (k : ℕ) (η : ℕ → Set E) (z : W) (r : Fin k → W) (a : V) : + (if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z r) k then + oldRunWeight (fun i => q (η i)) k z r else 0) ≤ + markedOldRun (fun i => q (η i)) + (fun i x y => if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) k z r := by + have hC : ∀ i x y, 0 ≤ (if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) := by + intro i x y; split_ifs; exact hq _ _ _; exact le_refl _ + by_cases ha : a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z r) k + · rw [ite_eq_left ha] + obtain ⟨i,hi,hik,hai⟩ := (mem_trajectoryUnion G η (e ∘ oldRunVertices k z r) k a).mp ha + have he : oldRunWeight (fun j x y => if j=i then + (if a ∈ cluster G (η j) (e x) then q (η j) x y else 0) else q (η j) x y) k z r = + oldRunWeight (fun j => q (η j)) k z r := by + simp_rw [oldRunWeight_prod] + apply Finset.prod_congr rfl + intro j _ + by_cases hji : j = i + · subst j + simp only [ite_true,Function.comp_apply] at hai ⊢ + exact ite_eq_left hai + · exact ite_eq_right hji + rw [← he] + unfold markedOldRun + apply Finset.single_le_sum _ (Finset.mem_Icc.mpr ⟨hi,hik⟩) + intro j _ + apply oldRunWeight_nonneg + intro l x y + split_ifs + · exact hq _ _ _ + · exact le_refl _ + · exact hq _ _ _ + · rw [ite_eq_right ha] + exact markedOldRun_nonneg _ _ (fun _ => hq _) hC k z r + +end MarkedOldRun + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TrajectoryEnvelopeDomination +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteTrajectoryMass_le_marked {W : Type*} [Fintype W] + (G : BondGraph V E) (e : W → V) (Q : Finset E) (p : unitInterval) (k : ℕ) + (q : Set E → W → W → ℝ) (hq : ∀ ω x y, 0 ≤ q ω x y) (z : W) (a : V) : + finiteTrajectoryMass G e Q p k q z a ≤ + ∑ r : Fin k → W, markedOldRun (fun _ => finiteOldKernel Q p q) + (fun _ x y => finiteFieldIntegral Q p (fun ω => if a ∈ cluster G ω (e x) then q ω x y else 0)) k z r := by + unfold finiteTrajectoryMass + calc + _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => ∑ r : Fin k → W, + markedOldRun (fun i => q (η i)) + (fun i x y => if a ∈ cluster G (η i) (e x) then q (η i) x y else 0) k z r) := + finiteFamilyIntegral_mono Q (Finset.Icc 1 k) p _ _ (fun η => Finset.sum_le_sum (fun r _ => + trajectory_indicator_le_marked G e q hq k η z r a)) + _ = _ := by + rw [finiteFamilyIntegral_sum] + apply Finset.sum_congr rfl + intro r _ + exact markedOldRun_integral Q p (fun _ => q) + (fun _ ω x y => if a ∈ cluster G ω (e x) then q ω x y else 0) k z r + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem finite_marked_step_row_le (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (x a : V) + (hQ : incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : + (∑ y : ↥B, finiteFieldIntegral Q p (fun ω => + if a ∈ cluster G ω x then q.mass ω x y.val else 0)) ≤ q.clusterVisitKernel p x a := by + rw [← finiteFieldIntegral_sum] + have he : q.clusterVisitKernel p x a = finiteFieldIntegral Q p (fun ω => q.clusterVisitMass ω x a) := + integral_finite_local Q p _ (finite_local_of_subset _ Q hQ _ (q.clusterVisitMass_local · x a)) + rw [he] + apply Finset.sum_le_sum + intro ω _ + apply mul_le_mul_of_nonneg_left _ (finiteFieldWeight_nonneg Q p ω) + dsimp only + by_cases ha : a ∈ cluster G (finiteFieldSet Q ω) x + · simp only [ha,ite_true,clusterVisitMass] + rw [Finset.sum_coe_sort B (fun y => q.mass (finiteFieldSet Q ω) x y)] + exact (q.summable_mass _ x).sum_le_tsum B (fun y _ => q.nonneg _ x y) + · simp only [ha,ite_false,clusterVisitMass,Finset.sum_const_zero,le_refl] + + + +theorem sum_markedOldRun_le_envelope (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (z : ↥B) (a : V) + (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : + (∑ r : Fin k → ↥B, markedOldRun + (fun _ => finiteOldKernel Q p (fun ω (x y : ↥B) => q.mass ω x.val y.val)) + (fun _ (x y : ↥B) => finiteFieldIntegral Q p (fun ω => + if a ∈ cluster G ω x.val then q.mass ω x.val y.val else 0)) k z r) ≤ + q.visitEnvelope o p k z.val a := by + let u := q.successProbability p o + let K : ↥B → ↥B → ℝ := finiteOldKernel Q p (fun ω (x y : ↥B) => q.mass ω x.val y.val) + let C : ↥B → ↥B → ℝ := fun x y => finiteFieldIntegral Q p (fun ω => + if a ∈ cluster G ω x.val then q.mass ω x.val y.val else 0) + have hK (x y : ↥B) : K x y = q.kernel p x.val y.val := + q.finiteOldKernel_eq_kernel Q p x.val y.val + ((incidentSupport_ball_mono G hloc x.val (le_max_left _ _)).trans (hQ x.val x.property)) + have hKn (x y : ↥B) : 0 ≤ K x y := by rw [hK]; exact q.kernel_nonneg p _ _ + have hCn (x y : ↥B) : 0 ≤ C x y := by + apply finiteFieldIntegral_nonneg + intro ω; split_ifs; exact q.nonneg ω _ _; exact le_refl _ + have hKr (x : ↥B) : (∑ y, K x y) ≤ u := by + simp only [hK] + rw [Finset.sum_coe_sort B (fun y => q.kernel p x.val y)] + exact ((q.summable_kernel p x.val).sum_le_tsum B (fun y _ => q.kernel_nonneg p x.val y)).trans + (q.kernel_row_le_success o p x.val) + have hCr (x : ↥B) : (∑ y, C x y) ≤ q.clusterVisitKernel p x.val a := + q.finite_marked_step_row_le o Q B p x.val a (hQ x.val x.property) + change (∑ r : Fin k → ↥B, markedOldRun (fun _ => K) (fun _ => C) k z r) ≤ _ + induction k generalizing z with + | zero => simp [markedOldRun,visitEnvelope] + | succ k ih => + rw [sum_markedOldRun_succ] + have hs : Summable (fun y => q.kernel p z.val y * q.visitEnvelope o p k y a) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc z.val M).toFinset) + intro y hy + rw [q.kernel_outside_ball_zero p z.val y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul] + calc + _ ≤ ∑ y : ↥B, (K z y * q.visitEnvelope o p k y.val a + C z y * u^k) := + Finset.sum_le_sum fun y _ => add_le_add + (mul_le_mul_of_nonneg_left (ih y) (hKn z y)) + (mul_le_mul_of_nonneg_left (sum_oldRunWeight_le (fun _ => K) (fun _ => hKn) + u (q.successProbability_nonneg p o) (fun _ => hKr) k y) (hCn z y)) + _ = (∑ y : ↥B, K z y * q.visitEnvelope o p k y.val a) + (∑ y : ↥B, C z y)*u^k := by + rw [Finset.sum_add_distrib,Finset.sum_mul] + _ ≤ (∑' y, q.kernel p z.val y * q.visitEnvelope o p k y a) + q.clusterVisitKernel p z.val a * u^k := by + apply add_le_add + · simp only [hK] + rw [Finset.sum_coe_sort B (fun y => q.kernel p z.val y * q.visitEnvelope o p k y a)] + exact hs.sum_le_tsum B (fun y _ => mul_nonneg (q.kernel_nonneg p z.val y) (q.visitEnvelope_nonneg o p k y a)) + · exact mul_le_mul_of_nonneg_right (hCr z) (pow_nonneg (q.successProbability_nonneg p o) _) + _ = q.visitEnvelope o p (k+1) z.val a := by rw [visitEnvelope]; ring + +theorem finiteTrajectoryMass_le_envelope (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (z : ↥B) (a : V) + (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : + finiteTrajectoryMass G Subtype.val Q p k (fun ω (x y : ↥B) => q.mass ω x.val y.val) z a ≤ + q.visitEnvelope o p k z.val a := + (finiteTrajectoryMass_le_marked G Subtype.val Q p k _ (fun ω x y => q.nonneg ω x.val y.val) z a).trans + (q.sum_markedOldRun_le_envelope o Q B p k z a hQ) + +end LocalEndpointRule +end TrajectoryEnvelopeDomination + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Bounds.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Bounds.lean index 25acc230afee3f4010badc5083f4aba83837a44b..8e50a57b88d5b2a1d273a6ba0c6cab503b11fc6a 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Bounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Bounds.lean @@ -1,482 +1,482 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Graph.Basic - -namespace OAI - -/-! Kernel domination, monotone couplings and endpoint bounds. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section PositiveColumn -attribute [local instance] Classical.propDecidable - - - -theorem no_positive_lower_bound [Infinite V] (f : Hilbert V) {c : ℝ} - (hc : 0 < c) (hf : ∀ x, c ≤ ‖f x‖) : False := by - have hs : Summable (fun x => ‖f x‖ ^ (2 : ℕ)) := by - simpa using (lp.hasSum_norm (by norm_num : 0 < (2 : ℝ≥0∞).toReal) f).summable - have hconst : Summable (fun _ : V => c ^ 2) := - Summable.of_nonneg_of_le (fun _ => sq_nonneg c) - (fun x => pow_le_pow_left₀ hc.le (hf x) 2) hs - have hz : c ^ 2 = 0 := (summable_const_iff _).mp hconst - nlinarith - - - -theorem not_operatorBounded_of_positive_column [Infinite V] - (G : BondGraph V E) (p : unitInterval) (y : V) {c : ℝ} - (hc : 0 < c) (hcol : ∀ x, c ≤ twoPoint G p x y) : - ¬ OperatorBounded G p := by - rintro ⟨A, hA⟩ - apply no_positive_lower_bound (A (lp.single 2 y (1 : ℂ))) hc - intro x - rw [hA x y, Complex.norm_real, Real.norm_eq_abs, - abs_of_nonneg (twoPoint_nonneg G p x y)] - exact hcol x - -@[simp] theorem not_operatorBounded_one [Infinite V] (G : BondGraph V E) - (h : Connected G) : ¬ OperatorBounded G 1 := by - apply not_operatorBounded_of_positive_column G 1 (Classical.arbitrary V) - (c := 1) (by norm_num) - intro x - rw [twoPoint_one G h] - -@[simp] theorem operatorNorm_one [Infinite V] (G : BondGraph V E) - (h : Connected G) : operatorNorm G 1 = ⊤ := - (operatorNorm_eq_top_iff G 1).mpr (not_operatorBounded_one G h) - -end PositiveColumn - -section KernelLimits -open scoped Topology -open Filter -attribute [local instance] Classical.propDecidable - - -noncomputable def finiteEmbedding : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := - Finsupp.linearCombination ℂ (fun y => lp.single 2 y (1 : ℂ)) - -@[simp] theorem finiteEmbedding_single (y : V) (c : ℂ) : - finiteEmbedding (Finsupp.single y c) = lp.single 2 y c := by - simp [finiteEmbedding, ← lp.single_smul] - -theorem finiteEmbedding_dense : DenseRange (finiteEmbedding (V := V)) := by - intro f - apply isClosed_closure.mem_of_tendsto (lp.hasSum_single (by norm_num) f) - apply Eventually.of_forall - intro s - apply subset_closure - refine ⟨∑ y ∈ s, Finsupp.single y (f y), ?_⟩ - simp - - - -theorem exists_operator_of_matrix_tendsto - (A : ℕ → Hilbert V →L[ℂ] Hilbert V) (K : V → V → ℂ) - {M : ℝ} (hM : 0 ≤ M) (hA : ∀ n, ‖A n‖ ≤ M) - (hlim : ∀ x y, Tendsto (fun n => A n (lp.single 2 y (1 : ℂ)) x) - atTop (𝓝 (K x y))) : - ∃ B : Hilbert V →L[ℂ] Hilbert V, - ‖B‖ ≤ M ∧ ∀ x y, B (lp.single 2 y (1 : ℂ)) x = K x y := by - have hn (n : ℕ) (f : Hilbert V) : ‖A n f‖ ≤ M * ‖f‖ := - (A n).le_opNorm f |>.trans (mul_le_mul_of_nonneg_right (hA n) (norm_nonneg _)) - have hcol (y : V) : Memℓp (fun x => K x y) 2 := by - apply lp.memℓp_of_tendsto (l := atTop) (F := fun n => A n (lp.single 2 y (1 : ℂ))) - · apply isBounded_iff_forall_norm_le.mpr - refine ⟨M, ?_⟩ - rintro _ ⟨n, rfl⟩ - simpa [lp.norm_single] using hn n (lp.single 2 y (1 : ℂ)) - · exact tendsto_pi_nhds.mpr (fun x => hlim x y) - let col (y : V) : Hilbert V := ⟨fun x => K x y, hcol y⟩ - let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col - have hLlim (f : V →₀ ℂ) : - Tendsto (fun n => (A n (finiteEmbedding f) : V → ℂ)) atTop - (𝓝 (L f : V → ℂ)) := by - apply tendsto_pi_nhds.mpr - intro x - simp only [finiteEmbedding, L, Finsupp.linearCombination_apply, Finsupp.sum, - map_sum, map_smul, lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, - smul_eq_mul] - exact tendsto_finsetSum _ (fun y _ => (hlim x y).const_mul (f y)) - have hLn (f : V →₀ ℂ) : ‖L f‖ ≤ M * ‖finiteEmbedding f‖ := by - exact lp.norm_le_of_tendsto (Eventually.of_forall (fun n => hn n _)) (hLlim f) - refine ⟨L.extendOfNorm finiteEmbedding, - LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense hM hLn, ?_⟩ - intro x y - have h := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨M, hLn⟩ - (Finsupp.single y (1 : ℂ)) - simp only [finiteEmbedding_single] at h - rw [h] - simp [L, col] - -end KernelLimits - -section Measurability - - - -theorem measurableSet_conn [Countable V] [Countable E] - (G : BondGraph V E) (x y : V) : MeasurableSet {ω | Conn G ω x y} := by - classical - have hedge (a b : V) : MeasurableSet {ω : Set E | ∃ e ∈ ω, G e = s(a, b)} := by - simp only [Set.ofPred_exists] - apply MeasurableSet.iUnion - intro e - by_cases he : G e = s(a, b) - · simpa [he] using (measurableSet_setOfPred.mpr (measurable_set_mem e)) - · simp [he] - have hlist (l : List V) : MeasurableSet {ω : Set E | - l.IsChain (fun a b => ∃ e ∈ ω, G e = s(a, b))} := by - induction l with - | nil => simp - | cons a l ih => - cases l with - | nil => simp - | cons b l => - simpa only [List.isChain_cons_cons, Set.ofPred_and] using (hedge a b).inter ih - have he : {ω | Conn G ω x y} = ⋃ l : List V, - {ω | (x :: l).IsChain (fun a b => ∃ e ∈ ω, G e = s(a, b)) ∧ - (x :: l).getLast (by simp) = y} := by - ext ω - simp only [Set.mem_ofPred_eq, Set.mem_iUnion] - exact ⟨List.exists_isChain_cons_of_relationReflTransGen, - fun ⟨l, hl, hy⟩ => List.relationReflTransGen_of_exists_isChain_cons l hl hy⟩ - rw [he] - apply MeasurableSet.iUnion - intro l - by_cases hlast : (x :: l).getLast (by simp) = y - · simpa [hlast] using hlist (x :: l) - · simp [hlast] - -end Measurability - -section Coupling - -instance labelLaw_isProbabilityMeasure : - IsProbabilityMeasure (labelLaw : Measure (E → unitInterval)) := by - dsimp [labelLaw] - infer_instance - -theorem measurable_threshold (p : unitInterval) : - Measurable (fun t : unitInterval => t ≤ p) := - measurableSet_setOfPred.mp measurableSet_Iic - - -theorem map_threshold (p : unitInterval) : - (volume : Measure unitInterval).map (fun t => t ≤ p) = - unitInterval.toNNReal p • Measure.dirac True + - unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False := by - apply Measure.ext_of_singleton - intro b - by_cases hb : b - · have he : b = True := propext (iff_true_intro hb) - subst b - simp [Measure.map_apply (measurable_threshold p), Set.preimage] - change volume (Set.Iic p) = _ - rw [unitInterval.volume_Iic, ← unitInterval.coe_toNNReal p, - ENNReal.ofReal_coe_nnreal] - · have he : b = False := propext (iff_false_intro hb) - subst b - simp [Measure.map_apply (measurable_threshold p), Set.preimage] - change volume (Set.Ioi p) = _ - rw [unitInterval.volume_Ioi, ← unitInterval.coe_symm_eq, - ← unitInterval.coe_toNNReal (unitInterval.symm p), ENNReal.ofReal_coe_nnreal] - - -theorem map_openEdges (p : unitInterval) : - (labelLaw : Measure (E → unitInterval)).map (fun labels => openEdges labels p) = - law p := by - unfold law - rw [setBernoulli_eq_map] - have hmeas : Measurable (fun labels : E → unitInterval => fun e => labels e ≤ p) := - Measurable.of_eval (fun e => (measurable_threshold p).comp (measurable_pi_apply e)) - have he : (fun labels : E → unitInterval => openEdges labels p) = - (fun f : E → Prop => {e | f e}) ∘ (fun labels e => labels e ≤ p) := rfl - rw [he, ← Measure.map_map measurable_setOfPred hmeas] - unfold labelLaw - rw [Measure.infinitePi_map_pi _ (fun _ => measurable_threshold p)] - simp only [map_threshold, Set.mem_univ, bernoulliMeasure_def] - -end Coupling - -section KernelDomination -attribute [local instance] Classical.propDecidable - -@[simp] theorem finiteEmbedding_apply (f : V →₀ ℂ) (x : V) : - finiteEmbedding f x = f x := by - simp only [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, - ← lp.single_smul, lp.coeFn_sum, lp.coeFn_single] - rw [Finset.sum_apply, Finset.sum_pi_single] - split_ifs with h - · simp - · exact (Finsupp.notMem_support_iff.mp h).symm - - -noncomputable def positivePart (f : Hilbert V) : Hilbert V := - ⟨fun x => (‖f x‖ : ℂ), (lp.memℓp f).mono' (by intro x; simp)⟩ - -@[simp] theorem positivePart_apply (f : Hilbert V) (x : V) : - positivePart f x = (‖f x‖ : ℂ) := rfl - -@[simp] theorem norm_positivePart (f : Hilbert V) : ‖positivePart f‖ = ‖f‖ := by - apply le_antisymm - · apply lp.norm_mono (by norm_num : (2 : ℝ≥0∞) ≠ 0) - intro x - simp - · apply lp.norm_mono (by norm_num : (2 : ℝ≥0∞) ≠ 0) - intro x - simp - - - -theorem exists_operator_of_matrix_domination - (U K : V → V → ℝ) (hU : ∀ x y, 0 ≤ U x y) - (hKU : ∀ x y, |K x y| ≤ U x y) - (B : Hilbert V →L[ℂ] Hilbert V) - (hB : ∀ x y, B (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ ‖B‖ ∧ - ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (K x y : ℂ) := by - have hcol (y : V) : Memℓp (fun x => (K x y : ℂ)) 2 := by - apply (lp.memℓp (B (lp.single 2 y (1 : ℂ)))).mono' - intro x - simpa [hB x y, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (hU x y)] - using hKU x y - let col (y : V) : Hilbert V := ⟨fun x => (K x y : ℂ), hcol y⟩ - let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col - have hLn (f : V →₀ ℂ) : ‖L f‖ ≤ ‖B‖ * ‖finiteEmbedding f‖ := by - let g : V →₀ ℂ := f.mapRange (fun z => (‖z‖ : ℂ)) (by simp) - have hg : finiteEmbedding g = positivePart (finiteEmbedding f) := by - apply lp.ext - funext x - simp [g] - have hpoint (x : V) : ‖L f x‖ ≤ ‖B (finiteEmbedding g) x‖ := by - have hright : B (finiteEmbedding g) x = - (∑ y ∈ f.support, ‖f y‖ * U x y : ℝ) := by - simp only [finiteEmbedding, g, Finsupp.linearCombination_apply] - rw [Finsupp.sum_mapRange_index (by simp)] - simp only [Finsupp.sum, map_sum, map_smul, lp.coeFn_sum, Finset.sum_apply, - lp.coeFn_smul, Pi.smul_apply, smul_eq_mul, hB, Complex.ofReal_sum, - Complex.ofReal_mul] - have hnn : 0 ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := - Finset.sum_nonneg (fun y _ => mul_nonneg (norm_nonneg _) (hU x y)) - rw [hright, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg hnn] - simp only [L, Finsupp.linearCombination_apply, Finsupp.sum, - lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, smul_eq_mul] - calc - ‖∑ y ∈ f.support, f y * col y x‖ ≤ - ∑ y ∈ f.support, ‖f y * col y x‖ := norm_sum_le _ _ - _ ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := by - apply Finset.sum_le_sum - intro y _ - simpa [col, norm_mul, Complex.norm_real, Real.norm_eq_abs] using - mul_le_mul_of_nonneg_left (hKU x y) (norm_nonneg (f y)) - calc - ‖L f‖ ≤ ‖B (finiteEmbedding g)‖ := lp.norm_mono (by norm_num) hpoint - _ ≤ ‖B‖ * ‖finiteEmbedding g‖ := B.le_opNorm _ - _ = ‖B‖ * ‖finiteEmbedding f‖ := by rw [hg, norm_positivePart] - refine ⟨L.extendOfNorm finiteEmbedding, - LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense (norm_nonneg _) hLn, ?_⟩ - intro x y - have h := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨‖B‖, hLn⟩ - (Finsupp.single y (1 : ℂ)) - simp only [finiteEmbedding_single] at h - rw [h] - simp [L, col] - -end KernelDomination - -section CouplingOrder -variable [Countable V] [Countable E] (G : BondGraph V E) - -omit [Countable E] in -theorem measurable_openEdges (p : unitInterval) : - Measurable (fun labels : E → unitInterval => openEdges labels p) := - measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_threshold p).comp (measurable_pi_apply e))) - -theorem twoPoint_eq_labelLaw (p : unitInterval) (x y : V) : - twoPoint G p x y = - (labelLaw {labels : E → unitInterval | Conn G (openEdges labels p) x y}).toReal := by - unfold twoPoint - rw [← map_openEdges p, Measure.map_apply (measurable_openEdges p) - (measurableSet_conn G x y)] - rfl - -omit [Countable E] in -theorem openEdges_mono (labels : E → unitInterval) : Monotone (openEdges labels) := by - intro p q hpq e he - exact he.trans hpq - -theorem twoPoint_mono (x y : V) : Monotone (fun p => twoPoint G p x y) := by - intro p q hpq - change twoPoint G p x y ≤ twoPoint G q x y - rw [twoPoint_eq_labelLaw, twoPoint_eq_labelLaw] - apply ENNReal.toReal_mono (measure_ne_top _ _) - apply measure_mono - intro labels h - exact conn_mono G (openEdges_mono labels hpq) h - -end CouplingOrder - -section NormOrder -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] (G : BondGraph V E) - -theorem operatorBounded_of_le {p q : unitInterval} (hpq : p ≤ q) - (hq : OperatorBounded G q) : OperatorBounded G p := by - obtain ⟨B, hB⟩ := hq - obtain ⟨A, _, hA⟩ := exists_operator_of_matrix_domination - (twoPoint G q) (twoPoint G p) (twoPoint_nonneg G q) - (fun x y => (abs_of_nonneg (twoPoint_nonneg G p x y)).le.trans - (twoPoint_mono G x y hpq)) B hB - exact ⟨A, hA⟩ - -theorem operatorNorm_mono : Monotone (operatorNorm G) := by - intro p q hpq - by_cases hq : OperatorBounded G q - · obtain ⟨B, hB⟩ := hq - obtain ⟨A, hnorm, hA⟩ := exists_operator_of_matrix_domination - (twoPoint G q) (twoPoint G p) (twoPoint_nonneg G q) - (fun x y => (abs_of_nonneg (twoPoint_nonneg G p x y)).le.trans - (twoPoint_mono G x y hpq)) B hB - rw [operatorNorm_of_hasKernel hA, operatorNorm_of_hasKernel hB] - exact ENNReal.ofReal_le_ofReal hnorm - · rw [(operatorNorm_eq_top_iff G q).mpr hq] - exact le_top - -end NormOrder - -section CouplingLimits -open Filter Topology - -theorem conn_iUnion_iff (G : BondGraph V E) (ω : ℕ → Set E) (hω : Monotone ω) - (x y : V) : Conn G (⋃ n, ω n) x y ↔ ∃ n, Conn G (ω n) x y := by - constructor - · intro h - induction h with - | refl => exact ⟨0, conn_refl G _ _⟩ - | @tail y z _ hyz ih => - obtain ⟨m, hm⟩ := ih - obtain ⟨e, he, heq⟩ := hyz - obtain ⟨n, hn⟩ := Set.mem_iUnion.mp he - exact ⟨max m n, (conn_mono G (hω (le_max_left _ _)) hm).tail - ⟨e, hω (le_max_right _ _) hn, heq⟩⟩ - · rintro ⟨n, hn⟩ - exact conn_mono G (Set.subset_iUnion ω n) hn - - -theorem ae_labels_ne [Countable E] (q : unitInterval) : - ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), ∀ e, labels e ≠ q := by - rw [ae_all_iff] - intro e - rw [ae_iff] - simp only [not_not] - change labelLaw ((fun labels : E → unitInterval => labels e) ⁻¹' {q}) = 0 - rw [← Measure.map_apply (measurable_pi_apply e) (measurableSet_singleton q)] - change (Measure.infinitePi (fun _ : E => (volume : Measure unitInterval))).map - (fun labels => labels e) {q} = 0 - rw [Measure.infinitePi_map_eval] - simp - -theorem openEdges_eq_iUnion_of_tendsto (labels : E → unitInterval) - (q : unitInterval) (hneq : ∀ e, labels e ≠ q) (p : ℕ → unitInterval) - (hle : ∀ n, p n ≤ q) (hlim : Tendsto p atTop (𝓝 q)) : - openEdges labels q = ⋃ n, openEdges labels (p n) := by - ext e - constructor - · intro he - have hlt : labels e < q := lt_of_le_of_ne he (hneq e) - obtain ⟨n, hn⟩ := ((tendsto_order.mp hlim).1 _ hlt).exists - exact Set.mem_iUnion.mpr ⟨n, hn.le⟩ - · intro he - obtain ⟨n, hn⟩ := Set.mem_iUnion.mp he - exact hn.trans (hle n) - - - -theorem twoPoint_tendsto_of_monotone [Countable V] [Countable E] - (G : BondGraph V E) (p : ℕ → unitInterval) (hp : Monotone p) - (q : unitInterval) (hle : ∀ n, p n ≤ q) (hlim : Tendsto p atTop (𝓝 q)) - (x y : V) : Tendsto (fun n => twoPoint G (p n) x y) atTop (𝓝 (twoPoint G q x y)) := by - let s (n : ℕ) : Set (E → unitInterval) := {labels | Conn G (openEdges labels (p n)) x y} - have hs : Monotone s := by - intro m n hmn labels hl - exact conn_mono G (openEdges_mono labels (hp hmn)) hl - have he : {labels : E → unitInterval | Conn G (openEdges labels q) x y} =ᵐ[labelLaw] - ⋃ n, s n := by - filter_upwards [ae_labels_ne (E := E) q] with labels hlabels - apply propext - rw [openEdges_eq_iUnion_of_tendsto labels q hlabels p hle hlim, conn_iUnion_iff] - · simp [s] - · exact fun m n hmn => openEdges_mono labels (hp hmn) - rw [twoPoint_eq_labelLaw G q x y, measure_congr he] - have ht := (tendsto_measure_iUnion_atTop (μ := (labelLaw : Measure (E → unitInterval))) hs) - have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht - simpa only [Function.comp_def, s, ← twoPoint_eq_labelLaw] using hr - -end CouplingLimits - -section Endpoint -open Filter Topology -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] (G : BondGraph V E) - - - -theorem operatorNorm_eq_sup_below (q : unitInterval) (hq : 0 < q) : - operatorNorm G q = sSup {r | ∃ p : unitInterval, p < q ∧ r = operatorNorm G p} := by - let S : ℝ≥0∞ := sSup {r | ∃ p : unitInterval, p < q ∧ r = operatorNorm G p} - change operatorNorm G q = S - apply le_antisymm - · by_cases hS : S = ⊤ - · rw [hS] - exact le_top - obtain ⟨p, hp, hpq, hlim⟩ := exists_seq_strictMono_tendsto' hq - have hbound (n : ℕ) : operatorNorm G (p n) ≤ S := - le_sSup ⟨p n, (hpq n).2, rfl⟩ - have hbounded (n : ℕ) : OperatorBounded G (p n) := - (operatorNorm_lt_top_iff G (p n)).mp ((hbound n).trans_lt (lt_top_iff_ne_top.mpr hS)) - choose A hA using hbounded - have hnorm (n : ℕ) : ‖A n‖ ≤ S.toReal := by - apply (ENNReal.ofReal_le_iff_le_toReal hS).mp - rw [← operatorNorm_of_hasKernel (hA n)] - exact hbound n - have hmatrix (x y : V) : Tendsto (fun n => A n (lp.single 2 y (1 : ℂ)) x) - atTop (𝓝 (twoPoint G q x y : ℂ)) := by - have ht := (Complex.continuous_ofReal.tendsto (twoPoint G q x y)).comp - (twoPoint_tendsto_of_monotone G p hp.monotone q (fun n => (hpq n).2.le) hlim x y) - convert ht using 1 - funext n - exact hA n x y - obtain ⟨B, hBn, hB⟩ := exists_operator_of_matrix_tendsto A - (fun x y => (twoPoint G q x y : ℂ)) ENNReal.toReal_nonneg hnorm hmatrix - rw [operatorNorm_of_hasKernel hB] - exact (ENNReal.ofReal_le_iff_le_toReal hS).mpr hBn - · apply sSup_le - rintro r ⟨p, hp, rfl⟩ - exact operatorNorm_mono G hp.le - -theorem operatorBounded_iff_uniform_below (q : unitInterval) (hq : 0 < q) : - OperatorBounded G q ↔ ∃ M : ℝ≥0∞, M < ⊤ ∧ ∀ p < q, operatorNorm G p ≤ M := by - rw [← operatorNorm_lt_top_iff] - constructor - · intro h - exact ⟨operatorNorm G q, h, fun p hp => operatorNorm_mono G hp.le⟩ - · rintro ⟨M, hM, h⟩ - rw [operatorNorm_eq_sup_below G q hq] - apply lt_of_le_of_lt ?_ hM - apply sSup_le - rintro r ⟨p, hp, rfl⟩ - exact h p hp - -end Endpoint - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Graph.Basic + +namespace OAI + +/-! Kernel domination, monotone couplings and endpoint bounds. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section PositiveColumn +attribute [local instance] Classical.propDecidable + + + +theorem no_positive_lower_bound [Infinite V] (f : Hilbert V) {c : ℝ} + (hc : 0 < c) (hf : ∀ x, c ≤ ‖f x‖) : False := by + have hs : Summable (fun x => ‖f x‖ ^ (2 : ℕ)) := by + simpa using (lp.hasSum_norm (by norm_num : 0 < (2 : ℝ≥0∞).toReal) f).summable + have hconst : Summable (fun _ : V => c ^ 2) := + Summable.of_nonneg_of_le (fun _ => sq_nonneg c) + (fun x => pow_le_pow_left₀ hc.le (hf x) 2) hs + have hz : c ^ 2 = 0 := (summable_const_iff _).mp hconst + nlinarith + + + +theorem not_operatorBounded_of_positive_column [Infinite V] + (G : BondGraph V E) (p : unitInterval) (y : V) {c : ℝ} + (hc : 0 < c) (hcol : ∀ x, c ≤ twoPoint G p x y) : + ¬ OperatorBounded G p := by + rintro ⟨A, hA⟩ + apply no_positive_lower_bound (A (lp.single 2 y (1 : ℂ))) hc + intro x + rw [hA x y, Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg (twoPoint_nonneg G p x y)] + exact hcol x + +@[simp] theorem not_operatorBounded_one [Infinite V] (G : BondGraph V E) + (h : Connected G) : ¬ OperatorBounded G 1 := by + apply not_operatorBounded_of_positive_column G 1 (Classical.arbitrary V) + (c := 1) (by norm_num) + intro x + rw [twoPoint_one G h] + +@[simp] theorem operatorNorm_one [Infinite V] (G : BondGraph V E) + (h : Connected G) : operatorNorm G 1 = ⊤ := + (operatorNorm_eq_top_iff G 1).mpr (not_operatorBounded_one G h) + +end PositiveColumn + +section KernelLimits +open scoped Topology +open Filter +attribute [local instance] Classical.propDecidable + + +noncomputable def finiteEmbedding : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := + Finsupp.linearCombination ℂ (fun y => lp.single 2 y (1 : ℂ)) + +@[simp] theorem finiteEmbedding_single (y : V) (c : ℂ) : + finiteEmbedding (Finsupp.single y c) = lp.single 2 y c := by + simp [finiteEmbedding, ← lp.single_smul] + +theorem finiteEmbedding_dense : DenseRange (finiteEmbedding (V := V)) := by + intro f + apply isClosed_closure.mem_of_tendsto (lp.hasSum_single (by norm_num) f) + apply Eventually.of_forall + intro s + apply subset_closure + refine ⟨∑ y ∈ s, Finsupp.single y (f y), ?_⟩ + simp + + + +theorem exists_operator_of_matrix_tendsto + (A : ℕ → Hilbert V →L[ℂ] Hilbert V) (K : V → V → ℂ) + {M : ℝ} (hM : 0 ≤ M) (hA : ∀ n, ‖A n‖ ≤ M) + (hlim : ∀ x y, Tendsto (fun n => A n (lp.single 2 y (1 : ℂ)) x) + atTop (𝓝 (K x y))) : + ∃ B : Hilbert V →L[ℂ] Hilbert V, + ‖B‖ ≤ M ∧ ∀ x y, B (lp.single 2 y (1 : ℂ)) x = K x y := by + have hn (n : ℕ) (f : Hilbert V) : ‖A n f‖ ≤ M * ‖f‖ := + (A n).le_opNorm f |>.trans (mul_le_mul_of_nonneg_right (hA n) (norm_nonneg _)) + have hcol (y : V) : Memℓp (fun x => K x y) 2 := by + apply lp.memℓp_of_tendsto (l := atTop) (F := fun n => A n (lp.single 2 y (1 : ℂ))) + · apply isBounded_iff_forall_norm_le.mpr + refine ⟨M, ?_⟩ + rintro _ ⟨n, rfl⟩ + simpa [lp.norm_single] using hn n (lp.single 2 y (1 : ℂ)) + · exact tendsto_pi_nhds.mpr (fun x => hlim x y) + let col (y : V) : Hilbert V := ⟨fun x => K x y, hcol y⟩ + let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col + have hLlim (f : V →₀ ℂ) : + Tendsto (fun n => (A n (finiteEmbedding f) : V → ℂ)) atTop + (𝓝 (L f : V → ℂ)) := by + apply tendsto_pi_nhds.mpr + intro x + simp only [finiteEmbedding, L, Finsupp.linearCombination_apply, Finsupp.sum, + map_sum, map_smul, lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, + smul_eq_mul] + exact tendsto_finsetSum _ (fun y _ => (hlim x y).const_mul (f y)) + have hLn (f : V →₀ ℂ) : ‖L f‖ ≤ M * ‖finiteEmbedding f‖ := by + exact lp.norm_le_of_tendsto (Eventually.of_forall (fun n => hn n _)) (hLlim f) + refine ⟨L.extendOfNorm finiteEmbedding, + LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense hM hLn, ?_⟩ + intro x y + have h := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨M, hLn⟩ + (Finsupp.single y (1 : ℂ)) + simp only [finiteEmbedding_single] at h + rw [h] + simp [L, col] + +end KernelLimits + +section Measurability + + + +theorem measurableSet_conn [Countable V] [Countable E] + (G : BondGraph V E) (x y : V) : MeasurableSet {ω | Conn G ω x y} := by + classical + have hedge (a b : V) : MeasurableSet {ω : Set E | ∃ e ∈ ω, G e = s(a, b)} := by + simp only [Set.ofPred_exists] + apply MeasurableSet.iUnion + intro e + by_cases he : G e = s(a, b) + · simpa [he] using (measurableSet_setOfPred.mpr (measurable_set_mem e)) + · simp [he] + have hlist (l : List V) : MeasurableSet {ω : Set E | + l.IsChain (fun a b => ∃ e ∈ ω, G e = s(a, b))} := by + induction l with + | nil => simp + | cons a l ih => + cases l with + | nil => simp + | cons b l => + simpa only [List.isChain_cons_cons, Set.ofPred_and] using (hedge a b).inter ih + have he : {ω | Conn G ω x y} = ⋃ l : List V, + {ω | (x :: l).IsChain (fun a b => ∃ e ∈ ω, G e = s(a, b)) ∧ + (x :: l).getLast (by simp) = y} := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_iUnion] + exact ⟨List.exists_isChain_cons_of_relationReflTransGen, + fun ⟨l, hl, hy⟩ => List.relationReflTransGen_of_exists_isChain_cons l hl hy⟩ + rw [he] + apply MeasurableSet.iUnion + intro l + by_cases hlast : (x :: l).getLast (by simp) = y + · simpa [hlast] using hlist (x :: l) + · simp [hlast] + +end Measurability + +section Coupling + +instance labelLaw_isProbabilityMeasure : + IsProbabilityMeasure (labelLaw : Measure (E → unitInterval)) := by + dsimp [labelLaw] + infer_instance + +theorem measurable_threshold (p : unitInterval) : + Measurable (fun t : unitInterval => t ≤ p) := + measurableSet_setOfPred.mp measurableSet_Iic + + +theorem map_threshold (p : unitInterval) : + (volume : Measure unitInterval).map (fun t => t ≤ p) = + unitInterval.toNNReal p • Measure.dirac True + + unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False := by + apply Measure.ext_of_singleton + intro b + by_cases hb : b + · have he : b = True := propext (iff_true_intro hb) + subst b + simp [Measure.map_apply (measurable_threshold p), Set.preimage] + change volume (Set.Iic p) = _ + rw [unitInterval.volume_Iic, ← unitInterval.coe_toNNReal p, + ENNReal.ofReal_coe_nnreal] + · have he : b = False := propext (iff_false_intro hb) + subst b + simp [Measure.map_apply (measurable_threshold p), Set.preimage] + change volume (Set.Ioi p) = _ + rw [unitInterval.volume_Ioi, ← unitInterval.coe_symm_eq, + ← unitInterval.coe_toNNReal (unitInterval.symm p), ENNReal.ofReal_coe_nnreal] + + +theorem map_openEdges (p : unitInterval) : + (labelLaw : Measure (E → unitInterval)).map (fun labels => openEdges labels p) = + law p := by + unfold law + rw [setBernoulli_eq_map] + have hmeas : Measurable (fun labels : E → unitInterval => fun e => labels e ≤ p) := + Measurable.of_eval (fun e => (measurable_threshold p).comp (measurable_pi_apply e)) + have he : (fun labels : E → unitInterval => openEdges labels p) = + (fun f : E → Prop => {e | f e}) ∘ (fun labels e => labels e ≤ p) := rfl + rw [he, ← Measure.map_map measurable_setOfPred hmeas] + unfold labelLaw + rw [Measure.infinitePi_map_pi _ (fun _ => measurable_threshold p)] + simp only [map_threshold, Set.mem_univ, bernoulliMeasure_def] + +end Coupling + +section KernelDomination +attribute [local instance] Classical.propDecidable + +@[simp] theorem finiteEmbedding_apply (f : V →₀ ℂ) (x : V) : + finiteEmbedding f x = f x := by + simp only [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, + ← lp.single_smul, lp.coeFn_sum, lp.coeFn_single] + rw [Finset.sum_apply, Finset.sum_pi_single] + split_ifs with h + · simp + · exact (Finsupp.notMem_support_iff.mp h).symm + + +noncomputable def positivePart (f : Hilbert V) : Hilbert V := + ⟨fun x => (‖f x‖ : ℂ), (lp.memℓp f).mono' (by intro x; simp)⟩ + +@[simp] theorem positivePart_apply (f : Hilbert V) (x : V) : + positivePart f x = (‖f x‖ : ℂ) := rfl + +@[simp] theorem norm_positivePart (f : Hilbert V) : ‖positivePart f‖ = ‖f‖ := by + apply le_antisymm + · apply lp.norm_mono (by norm_num : (2 : ℝ≥0∞) ≠ 0) + intro x + simp + · apply lp.norm_mono (by norm_num : (2 : ℝ≥0∞) ≠ 0) + intro x + simp + + + +theorem exists_operator_of_matrix_domination + (U K : V → V → ℝ) (hU : ∀ x y, 0 ≤ U x y) + (hKU : ∀ x y, |K x y| ≤ U x y) + (B : Hilbert V →L[ℂ] Hilbert V) + (hB : ∀ x y, B (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ ‖B‖ ∧ + ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (K x y : ℂ) := by + have hcol (y : V) : Memℓp (fun x => (K x y : ℂ)) 2 := by + apply (lp.memℓp (B (lp.single 2 y (1 : ℂ)))).mono' + intro x + simpa [hB x y, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (hU x y)] + using hKU x y + let col (y : V) : Hilbert V := ⟨fun x => (K x y : ℂ), hcol y⟩ + let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col + have hLn (f : V →₀ ℂ) : ‖L f‖ ≤ ‖B‖ * ‖finiteEmbedding f‖ := by + let g : V →₀ ℂ := f.mapRange (fun z => (‖z‖ : ℂ)) (by simp) + have hg : finiteEmbedding g = positivePart (finiteEmbedding f) := by + apply lp.ext + funext x + simp [g] + have hpoint (x : V) : ‖L f x‖ ≤ ‖B (finiteEmbedding g) x‖ := by + have hright : B (finiteEmbedding g) x = + (∑ y ∈ f.support, ‖f y‖ * U x y : ℝ) := by + simp only [finiteEmbedding, g, Finsupp.linearCombination_apply] + rw [Finsupp.sum_mapRange_index (by simp)] + simp only [Finsupp.sum, map_sum, map_smul, lp.coeFn_sum, Finset.sum_apply, + lp.coeFn_smul, Pi.smul_apply, smul_eq_mul, hB, Complex.ofReal_sum, + Complex.ofReal_mul] + have hnn : 0 ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := + Finset.sum_nonneg (fun y _ => mul_nonneg (norm_nonneg _) (hU x y)) + rw [hright, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg hnn] + simp only [L, Finsupp.linearCombination_apply, Finsupp.sum, + lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, smul_eq_mul] + calc + ‖∑ y ∈ f.support, f y * col y x‖ ≤ + ∑ y ∈ f.support, ‖f y * col y x‖ := norm_sum_le _ _ + _ ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := by + apply Finset.sum_le_sum + intro y _ + simpa [col, norm_mul, Complex.norm_real, Real.norm_eq_abs] using + mul_le_mul_of_nonneg_left (hKU x y) (norm_nonneg (f y)) + calc + ‖L f‖ ≤ ‖B (finiteEmbedding g)‖ := lp.norm_mono (by norm_num) hpoint + _ ≤ ‖B‖ * ‖finiteEmbedding g‖ := B.le_opNorm _ + _ = ‖B‖ * ‖finiteEmbedding f‖ := by rw [hg, norm_positivePart] + refine ⟨L.extendOfNorm finiteEmbedding, + LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense (norm_nonneg _) hLn, ?_⟩ + intro x y + have h := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨‖B‖, hLn⟩ + (Finsupp.single y (1 : ℂ)) + simp only [finiteEmbedding_single] at h + rw [h] + simp [L, col] + +end KernelDomination + +section CouplingOrder +variable [Countable V] [Countable E] (G : BondGraph V E) + +omit [Countable E] in +theorem measurable_openEdges (p : unitInterval) : + Measurable (fun labels : E → unitInterval => openEdges labels p) := + measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_threshold p).comp (measurable_pi_apply e))) + +theorem twoPoint_eq_labelLaw (p : unitInterval) (x y : V) : + twoPoint G p x y = + (labelLaw {labels : E → unitInterval | Conn G (openEdges labels p) x y}).toReal := by + unfold twoPoint + rw [← map_openEdges p, Measure.map_apply (measurable_openEdges p) + (measurableSet_conn G x y)] + rfl + +omit [Countable E] in +theorem openEdges_mono (labels : E → unitInterval) : Monotone (openEdges labels) := by + intro p q hpq e he + exact he.trans hpq + +theorem twoPoint_mono (x y : V) : Monotone (fun p => twoPoint G p x y) := by + intro p q hpq + change twoPoint G p x y ≤ twoPoint G q x y + rw [twoPoint_eq_labelLaw, twoPoint_eq_labelLaw] + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono + intro labels h + exact conn_mono G (openEdges_mono labels hpq) h + +end CouplingOrder + +section NormOrder +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] (G : BondGraph V E) + +theorem operatorBounded_of_le {p q : unitInterval} (hpq : p ≤ q) + (hq : OperatorBounded G q) : OperatorBounded G p := by + obtain ⟨B, hB⟩ := hq + obtain ⟨A, _, hA⟩ := exists_operator_of_matrix_domination + (twoPoint G q) (twoPoint G p) (twoPoint_nonneg G q) + (fun x y => (abs_of_nonneg (twoPoint_nonneg G p x y)).le.trans + (twoPoint_mono G x y hpq)) B hB + exact ⟨A, hA⟩ + +theorem operatorNorm_mono : Monotone (operatorNorm G) := by + intro p q hpq + by_cases hq : OperatorBounded G q + · obtain ⟨B, hB⟩ := hq + obtain ⟨A, hnorm, hA⟩ := exists_operator_of_matrix_domination + (twoPoint G q) (twoPoint G p) (twoPoint_nonneg G q) + (fun x y => (abs_of_nonneg (twoPoint_nonneg G p x y)).le.trans + (twoPoint_mono G x y hpq)) B hB + rw [operatorNorm_of_hasKernel hA, operatorNorm_of_hasKernel hB] + exact ENNReal.ofReal_le_ofReal hnorm + · rw [(operatorNorm_eq_top_iff G q).mpr hq] + exact le_top + +end NormOrder + +section CouplingLimits +open Filter Topology + +theorem conn_iUnion_iff (G : BondGraph V E) (ω : ℕ → Set E) (hω : Monotone ω) + (x y : V) : Conn G (⋃ n, ω n) x y ↔ ∃ n, Conn G (ω n) x y := by + constructor + · intro h + induction h with + | refl => exact ⟨0, conn_refl G _ _⟩ + | @tail y z _ hyz ih => + obtain ⟨m, hm⟩ := ih + obtain ⟨e, he, heq⟩ := hyz + obtain ⟨n, hn⟩ := Set.mem_iUnion.mp he + exact ⟨max m n, (conn_mono G (hω (le_max_left _ _)) hm).tail + ⟨e, hω (le_max_right _ _) hn, heq⟩⟩ + · rintro ⟨n, hn⟩ + exact conn_mono G (Set.subset_iUnion ω n) hn + + +theorem ae_labels_ne [Countable E] (q : unitInterval) : + ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), ∀ e, labels e ≠ q := by + rw [ae_all_iff] + intro e + rw [ae_iff] + simp only [not_not] + change labelLaw ((fun labels : E → unitInterval => labels e) ⁻¹' {q}) = 0 + rw [← Measure.map_apply (measurable_pi_apply e) (measurableSet_singleton q)] + change (Measure.infinitePi (fun _ : E => (volume : Measure unitInterval))).map + (fun labels => labels e) {q} = 0 + rw [Measure.infinitePi_map_eval] + simp + +theorem openEdges_eq_iUnion_of_tendsto (labels : E → unitInterval) + (q : unitInterval) (hneq : ∀ e, labels e ≠ q) (p : ℕ → unitInterval) + (hle : ∀ n, p n ≤ q) (hlim : Tendsto p atTop (𝓝 q)) : + openEdges labels q = ⋃ n, openEdges labels (p n) := by + ext e + constructor + · intro he + have hlt : labels e < q := lt_of_le_of_ne he (hneq e) + obtain ⟨n, hn⟩ := ((tendsto_order.mp hlim).1 _ hlt).exists + exact Set.mem_iUnion.mpr ⟨n, hn.le⟩ + · intro he + obtain ⟨n, hn⟩ := Set.mem_iUnion.mp he + exact hn.trans (hle n) + + + +theorem twoPoint_tendsto_of_monotone [Countable V] [Countable E] + (G : BondGraph V E) (p : ℕ → unitInterval) (hp : Monotone p) + (q : unitInterval) (hle : ∀ n, p n ≤ q) (hlim : Tendsto p atTop (𝓝 q)) + (x y : V) : Tendsto (fun n => twoPoint G (p n) x y) atTop (𝓝 (twoPoint G q x y)) := by + let s (n : ℕ) : Set (E → unitInterval) := {labels | Conn G (openEdges labels (p n)) x y} + have hs : Monotone s := by + intro m n hmn labels hl + exact conn_mono G (openEdges_mono labels (hp hmn)) hl + have he : {labels : E → unitInterval | Conn G (openEdges labels q) x y} =ᵐ[labelLaw] + ⋃ n, s n := by + filter_upwards [ae_labels_ne (E := E) q] with labels hlabels + apply propext + rw [openEdges_eq_iUnion_of_tendsto labels q hlabels p hle hlim, conn_iUnion_iff] + · simp [s] + · exact fun m n hmn => openEdges_mono labels (hp hmn) + rw [twoPoint_eq_labelLaw G q x y, measure_congr he] + have ht := (tendsto_measure_iUnion_atTop (μ := (labelLaw : Measure (E → unitInterval))) hs) + have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp ht + simpa only [Function.comp_def, s, ← twoPoint_eq_labelLaw] using hr + +end CouplingLimits + +section Endpoint +open Filter Topology +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] (G : BondGraph V E) + + + +theorem operatorNorm_eq_sup_below (q : unitInterval) (hq : 0 < q) : + operatorNorm G q = sSup {r | ∃ p : unitInterval, p < q ∧ r = operatorNorm G p} := by + let S : ℝ≥0∞ := sSup {r | ∃ p : unitInterval, p < q ∧ r = operatorNorm G p} + change operatorNorm G q = S + apply le_antisymm + · by_cases hS : S = ⊤ + · rw [hS] + exact le_top + obtain ⟨p, hp, hpq, hlim⟩ := exists_seq_strictMono_tendsto' hq + have hbound (n : ℕ) : operatorNorm G (p n) ≤ S := + le_sSup ⟨p n, (hpq n).2, rfl⟩ + have hbounded (n : ℕ) : OperatorBounded G (p n) := + (operatorNorm_lt_top_iff G (p n)).mp ((hbound n).trans_lt (lt_top_iff_ne_top.mpr hS)) + choose A hA using hbounded + have hnorm (n : ℕ) : ‖A n‖ ≤ S.toReal := by + apply (ENNReal.ofReal_le_iff_le_toReal hS).mp + rw [← operatorNorm_of_hasKernel (hA n)] + exact hbound n + have hmatrix (x y : V) : Tendsto (fun n => A n (lp.single 2 y (1 : ℂ)) x) + atTop (𝓝 (twoPoint G q x y : ℂ)) := by + have ht := (Complex.continuous_ofReal.tendsto (twoPoint G q x y)).comp + (twoPoint_tendsto_of_monotone G p hp.monotone q (fun n => (hpq n).2.le) hlim x y) + convert ht using 1 + funext n + exact hA n x y + obtain ⟨B, hBn, hB⟩ := exists_operator_of_matrix_tendsto A + (fun x y => (twoPoint G q x y : ℂ)) ENNReal.toReal_nonneg hnorm hmatrix + rw [operatorNorm_of_hasKernel hB] + exact (ENNReal.ofReal_le_iff_le_toReal hS).mpr hBn + · apply sSup_le + rintro r ⟨p, hp, rfl⟩ + exact operatorNorm_mono G hp.le + +theorem operatorBounded_iff_uniform_below (q : unitInterval) (hq : 0 < q) : + OperatorBounded G q ↔ ∃ M : ℝ≥0∞, M < ⊤ ∧ ∀ p < q, operatorNorm G p ≤ M := by + rw [← operatorNorm_lt_top_iff] + constructor + · intro h + exact ⟨operatorNorm G q, h, fun p hp => operatorNorm_mono G hp.le⟩ + · rintro ⟨M, hM, h⟩ + rw [operatorNorm_eq_sup_below G q hq] + apply lt_of_le_of_lt ?_ hM + apply sSup_le + rintro r ⟨p, hp, rfl⟩ + exact h p hp + +end Endpoint + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Connections.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Connections.lean index d9ac9257cae341bace336549f3d649ce0c865e8c..01fa6972fadbc1ebeb7453a6a0d88ac41a3f861b 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Connections.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Connections.lean @@ -1,1264 +1,1264 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Covariance - -namespace OAI - -/-! Connections for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterWindowLaw -attribute [local instance] Classical.propDecidable Classical.decEq - -def ClusterWindow (G : BondGraph V E) (x : V) (lo hi : ℕ) (ω : Set E) : Prop := - (cluster G ω x).Finite ∧ lo ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < hi - -theorem clusterWindow_local (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (lo hi : ℕ) (ω : Set E) : - let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset - ClusterWindow G x lo hi ω ↔ ClusterWindow G x lo hi (ω ∩ (Q : Set E)) := by - let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset - change ClusterWindow G x lo hi ω ↔ ClusterWindow G x lo hi (ω ∩ (Q : Set E)) - constructor - · rintro ⟨hf,hl,hh⟩ - have hs : cluster G ω x ⊆ (finite_reachBall hloc x hi).toFinset := by - simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hf hi hh.le - have he := cluster_restrict_incident_of_full G hloc _ ω x hs - change cluster G (ω ∩ (Q : Set E)) x = cluster G ω x at he - exact ⟨he.symm ▸ hf,he.symm ▸ hl,he.symm ▸ hh⟩ - · rintro ⟨hf,hl,hh⟩ - have he := cluster_restrict_of_cap G hloc Q ω x hi (Finset.Subset.refl _) hf hh.le - exact ⟨he ▸ hf,he ▸ hl,he ▸ hh⟩ - -theorem measurableSet_clusterWindow (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (lo hi : ℕ) : MeasurableSet {ω | ClusterWindow G x lo hi ω} := by - let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset - have he : {ω | ClusterWindow G x lo hi ω} = - {ω | ω ∩ (Q : Set E) ∈ {η | ClusterWindow G x lo hi η}} := by - ext ω - exact clusterWindow_local G hloc x lo hi ω - rw [he] - exact measurableSet_finite_restriction Q _ - -noncomputable def clusterWindowProbability (G : BondGraph V E) (p : unitInterval) - (x : V) (lo hi : ℕ) : ℝ := (law p).real {ω | ClusterWindow G x lo hi ω} - -theorem finiteClusterWindowMass_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (p : unitInterval) (x : V) (lo hi : ℕ) - (hQ : incidentSupport G hloc (finite_reachBall hloc x hi).toFinset ⊆ Q) : - finiteClusterWindowMass G Q p x lo hi = clusterWindowProbability G p x lo hi := by - let S := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset - let f : Set E → ℝ := fun ω => if ClusterWindow G x lo hi ω then 1 else 0 - have hf (ω) : f ω = f (ω ∩ (S : Set E)) := - if_congr (clusterWindow_local G hloc x lo hi ω) rfl rfl - have he := integral_finite_local Q p f (finite_local_of_subset S Q hQ f hf) - trans ∫ ω, f ω ∂law p - · rw [he] - unfold finiteClusterWindowMass finiteFieldIntegral - apply Finset.sum_congr rfl - intro η _ - congr 1 - unfold f ClusterWindow - dsimp only - split_ifs <;> rfl - change (∫ ω, ({η | ClusterWindow G x lo hi η}.indicator (1 : Set E → ℝ)) ω ∂law p) = _ - exact integral_indicator_one (measurableSet_clusterWindow G hloc x lo hi) - -theorem clusterWindowProbability_nonneg (G : BondGraph V E) (p : unitInterval) - (x : V) (lo hi : ℕ) : 0 ≤ clusterWindowProbability G p x lo hi := ENNReal.toReal_nonneg - -theorem clusterWindowProbability_mono (G : BondGraph V E) (p : unitInterval) - (x : V) {a b c d : ℕ} (hac : c ≤ a) (hbd : b ≤ d) : - clusterWindowProbability G p x a b ≤ clusterWindowProbability G p x c d := by - apply measureReal_mono - · intro ω h - exact ⟨h.1,hac.trans h.2.1,h.2.2.trans_le hbd⟩ - · exact measure_ne_top _ _ - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem finiteClusterWindowMass_amplification (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (k n : ℕ) (p : unitInterval) (x : V) : - finiteClusterWindowMass G (q.amplificationBonds k n x) p x (n-k*M) (2*n) = - clusterWindowProbability G p x (n-k*M) (2*n) := by - apply finiteClusterWindowMass_eq G hloc - exact incidentSupport_ball_mono G hloc x (by dsimp [amplificationRadius]; omega) - -end LocalEndpointRule -end ClusterWindowLaw -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section QuantitativeAmplificationMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def amplificationMomentFactor (k M d : ℕ) (c a t : ℝ) : ℝ := - 4 + (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) + (2*c*(k*M:ℕ))^2*t/a - -theorem amplificationMomentFactor_pos (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : - 0 < amplificationMomentFactor k M d c a t := by - unfold amplificationMomentFactor - positivity - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem amplificationLoad_moment_factor [Nonempty E] (hconn : Connected G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (k n d : ℕ) (hn : 0 < n) (hdeg : ∀ x, degree G x ≤ d) - (a t π : ℝ) (ha : 0 < a) (ht : 0 ≤ t) (hπ : 0 ≤ π) - (hbin : a*n*π ≤ binOrbitRow G p (root i₀) n) - (hwindow : clusterWindowProbability G p (root i₀) (n-k*M) (2*n) ≤ t*π) - (hcode : inverseCodeMass M L^k ≤ n*q.successProbability p (root i₀)^k) : - (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p) ≤ - amplificationMomentFactor k M d c a t * q.successProbability p (root i₀)^k * - (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n) := by - let u := q.successProbability p (root i₀) - let B := u^k * binOrbitRow G p (root i₀) n / n - let D : ℝ := (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) - have hu : 0 ≤ u^k := pow_nonneg (q.successProbability_nonneg p _) _ - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have hB : a*π*u^k ≤ B := by - apply (le_div_iff₀ hn').mpr - calc - _ = u^k*(a*n*π) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hbin hu - have hB0 : 0 ≤ B := (mul_nonneg (mul_nonneg ha.le hπ) hu).trans hB - have hcoef : 4*u^k+D*inverseCodeMass M L^k/n ≤ (4+D)*u^k := by - have h := mul_le_mul_of_nonneg_left hcode (show 0 ≤ D by positivity) - have h' : D*inverseCodeMass M L^k/n ≤ D*u^k := by - apply (div_le_iff₀ hn').mpr - nlinarith only [h] - nlinarith only [h'] - have hrem : (2*(c*((k*M:ℕ)*u^k)))^2*(t*π) ≤ - ((2*c*(k*M:ℕ))^2*t/a)*u^k*B := by - have h := mul_le_mul_of_nonneg_left hB - (show 0 ≤ ((2*c*(k*M:ℕ))^2*t/a)*u^k from - mul_nonneg (div_nonneg (mul_nonneg (sq_nonneg _) ht) ha.le) hu) - calc - _ = (((2*c*(k*M:ℕ))^2*t/a)*u^k)*(a*π*u^k) := by - field_simp - _ ≤ _ := h - have hself : root i₀ ∈ vertexOrbit G (root i₀) := by - refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ - intro e - simp - have he := q.amplificationLoad_mean root weight Γ htr - (fun e he => hΓ he) hw i₀ hw₀ hL p k n (root i₀) hself - have hm := q.amplificationLoad_second_moment_le hconn root weight Γ hΓ htr hcov hw hw1 - c hc hmin i₀ hw₀ hL p (root i₀) k n d hn hdeg - rw [he,q.finiteClusterWindowMass_amplification] at hm - change _ ≤ (4*u^k+D*inverseCodeMass M L^k/n)*B + - (2*(c*((k*M:ℕ)*u^k)))^2*clusterWindowProbability G p (root i₀) (n-k*M) (2*n) at hm - calc - _ ≤ _ := hm - _ ≤ (4+D)*u^k*B + (2*(c*((k*M:ℕ)*u^k)))^2*(t*π) := - add_le_add (mul_le_mul_of_nonneg_right hcoef hB0) - (mul_le_mul_of_nonneg_left hwindow (sq_nonneg _)) - _ ≤ (4+D)*u^k*B + ((2*c*(k*M:ℕ))^2*t/a)*u^k*B := add_le_add (le_refl _) hrem - _ = _ := by dsimp [amplificationMomentFactor,D,B,u]; ring - -end LocalEndpointRule -end QuantitativeAmplificationMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section QuantitativeAmplificationStep -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem quantitative_amplification_step [Nonempty E] (hconn : Connected G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (k n d : ℕ) (hn : 0 < n) (hdeg : ∀ x, degree G x ≤ d) - (hu : 0 < q.successProbability p (root i₀)) - (a t π L' : ℝ) (ha : 0 < a) (ht : 0 ≤ t) (hπ : 0 < π) - (hbin : a*n*π ≤ binOrbitRow G p (root i₀) n) - (hwindow : clusterWindowProbability G p (root i₀) (n-k*M) (2*n) ≤ t*π) - (hcode : inverseCodeMass M L^k ≤ n*q.successProbability p (root i₀)^k) - (hbad : 16*amplificationMomentFactor k M d c a t * - (law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ a*π) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : - ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) (2*n+k*M) L', - a*π/(8*amplificationMomentFactor k M d c a t) ≤ q'.successProbability p (root i₀) ∧ - ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ ‖A'‖ ≤ 2*‖A‖^k ∧ - ∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ) := by - let Q := amplificationMomentFactor k M d c a t - let u := q.successProbability p (root i₀) - let B := u^k*binOrbitRow G p (root i₀) n / n - let b := 4*Q*u^k - have hQ : 0 < Q := amplificationMomentFactor_pos k M d c a t ha ht - have huk : 0 < u^k := pow_pos hu _ - have hb : 0 < b := mul_pos (mul_pos (by norm_num) hQ) huk - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have hbin0 : 0 < binOrbitRow G p (root i₀) n := - (mul_pos (mul_pos ha hn') hπ).trans_le hbin - have hB : a*π*u^k ≤ B := by - apply (le_div_iff₀ hn').mpr - calc - _ = u^k*(a*n*π) := by ring - _ ≤ _ := mul_le_mul_of_nonneg_left hbin huk.le - have hm := q.amplificationLoad_moment_factor hconn root weight Γ hΓ htr hcov hw hw1 - c hc hmin i₀ hw₀ hL p k n d hn hdeg a t π ha ht hπ.le hbin hwindow hcode - have hmoment : (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p)/b ≤ B/4 := by - apply (div_le_iff₀ hb).mpr - change _ ≤ Q*u^k*B at hm - calc - _ ≤ Q*u^k*B := hm - _ = _ := by dsimp [b]; ring - have hbad' : b*(law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ B/4 := by - have hh := mul_le_mul_of_nonneg_right hbad huk.le - dsimp [b] - nlinarith only [hh,hB] - obtain ⟨q',hq',A',hA'pos,hA'norm,hA'⟩ := q.amplification_truncation_step root weight Γ htr - (fun e he => hΓ he) hw i₀ hw₀ hL p k n hn hu hbin0 b L' hb hmoment hbad' A hA - refine ⟨q',?_,A',hA'pos,hA'norm,hA'⟩ - apply le_trans _ hq' - change a*π/(8*Q) ≤ B/(2*b) - apply (div_le_div_iff₀ (mul_pos (by norm_num) hQ) (mul_pos (by norm_num) hb)).mpr - have hh := mul_le_mul_of_nonneg_left hB (show 0 ≤ 8*Q by positivity) - dsimp [b] - nlinarith only [hh] - -end LocalEndpointRule -end QuantitativeAmplificationStep -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ConnectionAdjustedRule -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def cappedConnectionMass (G : BondGraph V E) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : ℝ := - if CappedGoodness G ω x M L ∧ Conn G ω x y then c*S x y/twoPoint G p x y else 0 - -theorem cappedConnectionMass_nonneg (G : BondGraph V E) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (hc : 0 ≤ c) (hS : ∀ x y, 0 ≤ S x y) - (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : 0 ≤ cappedConnectionMass G p S c M L ω x y := by - unfold cappedConnectionMass - split_ifs - · exact div_nonneg (mul_nonneg hc (hS x y)) (twoPoint_nonneg G p x y) - · rfl - -theorem cappedConnectionMass_support (G : BondGraph V E) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) - (h : cappedConnectionMass G p S c M L ω x y ≠ 0) : - S x y ≠ 0 ∧ CappedGoodness G ω x M L ∧ Conn G ω x y := by - unfold cappedConnectionMass at h - split_ifs at h with hh - · refine ⟨?_,hh⟩ - intro hz - simp only [hz,mul_zero,zero_div] at h - exact h rfl - · exact (h rfl).elim - -theorem cappedConnectionMass_le (G : BondGraph V E) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) - (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) - (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : cappedConnectionMass G p S c M L ω x y ≤ S x y := by - by_cases hs : S x y = 0 - · simp only [cappedConnectionMass,hs,mul_zero,zero_div,ite_self,le_refl] - · unfold cappedConnectionMass - split_ifs - · apply (div_le_iff₀ (hc.trans_le (hτ x y hs))).mpr - exact (mul_le_mul_of_nonneg_right (hτ x y hs) (hS x y)).trans_eq (mul_comm _ _) - · exact hS x y - -theorem cappedConnectionMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - cappedConnectionMass G p S c M L ω x y = cappedConnectionMass G p S c M L (ω ∩ (Q:Set E)) x y := by - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - change cappedConnectionMass G p S c M L ω x y = cappedConnectionMass G p S c M L (ω ∩ (Q:Set E)) x y - have hg := cappedGoodness_local G hloc ω x M L - change CappedGoodness G ω x M L ↔ CappedGoodness G (ω ∩ (Q:Set E)) x M L at hg - unfold cappedConnectionMass - apply if_congr _ rfl rfl - constructor - · rintro ⟨h,hxy⟩ - have h' := hg.mp h - have he := cluster_restrict_of_cap G hloc Q ω x M (Finset.Subset.refl _) h'.1 h'.2.1 - refine ⟨h',?_⟩ - change y ∈ cluster G (ω ∩ (Q:Set E)) x - rw [he] - exact hxy - · rintro ⟨h,hxy⟩ - exact ⟨hg.mpr h,conn_mono G Set.inter_subset_left hxy⟩ - -theorem cappedConnectionMass_covariant [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) - (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) - (hS : ∀ x y, S (a x) (a y) = S x y) (ω : Set E) (x y : V) : - cappedConnectionMass G p S c M L (b ⁻¹' ω) x y = cappedConnectionMass G p S c M L ω (a x) (a y) := by - simp only [cappedConnectionMass,cappedGoodness_aut_iff G hab,conn_aut_iff G hab, - hS,twoPoint_aut G p hab] - -noncomputable def connectionAdjustedRule [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) - (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) - (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) - (hO : ∀ x y, S x y ≠ 0 → x ∈ O ∧ y ∈ O) - (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) - (M : ℕ) (L : ℝ) : LocalEndpointRule G hloc O M L where - mass := cappedConnectionMass G p S c M L - radius := M - nonneg := cappedConnectionMass_nonneg G p S c hc.le hS M L - support := by - intro ω x y h - obtain ⟨hs,hg,hxy⟩ := cappedConnectionMass_support G p S c M L ω x y h - exact ⟨(hO x y hs).1,(hO x y hs).2,hxy,hg⟩ - locality := fun ω x y => cappedConnectionMass_local G hloc p S c M L ω x y - covariance := fun a b hab ω x y => cappedConnectionMass_covariant G p S c M L a b hab (hcov a b hab) ω x y - row_le_one := by - intro ω x - have hs : Summable (cappedConnectionMass G p S c M L ω x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - by_contra hn - obtain ⟨_,hg,hxy⟩ := cappedConnectionMass_support G p S c M L ω x y hn - apply hy - simp only [Set.Finite.mem_toFinset] - exact finite_cluster_subset_reachBall G ω x hg.1 M hg.2.1 hxy - exact (hs.tsum_le_tsum (cappedConnectionMass_le G p S c hc hS hτ M L ω x) (hSsum x)).trans (hrow x) - -end ConnectionAdjustedRule - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ConnectionAdjustedKernel -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - -theorem integral_cappedConnectionMass (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (x y : V) : - (∫ ω, cappedConnectionMass G p S c M L ω x y ∂law p) = - c*S x y/twoPoint G p x y * (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} := by - have hm : MeasurableSet {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} := - (measurableSet_capped_good G hloc x M L).inter (measurableSet_conn G x y) - simpa only [cappedConnectionMass,Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_comm] using - integral_indicator_const (μ := law p) (c*S x y/twoPoint G p x y) hm - -theorem integral_cappedConnectionMass_bounds (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) - (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) - (M : ℕ) (L : ℝ) (x y : V) : - let K := ∫ ω, cappedConnectionMass G p S c M L ω x y ∂law p - K ≤ c*S x y ∧ c*S x y ≤ K + S x y * (law p).real {ω | ¬ CappedGoodness G ω x M L} := by - dsimp only - rw [integral_cappedConnectionMass G hloc] - by_cases hs : S x y = 0 - · simp only [hs,mul_zero,zero_div,zero_mul,zero_add,le_refl,and_self] - have ht : 0 < twoPoint G p x y := hc.trans_le (hτ x y hs) - let a := c*S x y/twoPoint G p x y - have ha : 0 ≤ a := div_nonneg (mul_nonneg hc.le (hS x y)) ht.le - have hle : a ≤ S x y := by - apply (div_le_iff₀ ht).mpr - exact (mul_le_mul_of_nonneg_right (hτ x y hs) (hS x y)).trans_eq (mul_comm _ _) - have he : a*twoPoint G p x y = c*S x y := div_mul_cancel₀ _ ht.ne' - have hsub : {ω : Set E | CappedGoodness G ω x M L ∧ Conn G ω x y} ⊆ {ω | Conn G ω x y} := - fun _ h => h.2 - have hm : (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} ≤ twoPoint G p x y := by - exact measureReal_mono hsub (measure_ne_top _ _) - have hcover : {ω : Set E | Conn G ω x y} ⊆ - {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} ∪ {ω | ¬ CappedGoodness G ω x M L} := by - intro ω h - by_cases hg : CappedGoodness G ω x M L - · exact Or.inl ⟨hg,h⟩ - · exact Or.inr hg - have hb : twoPoint G p x y ≤ - (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + - (law p).real {ω | ¬ CappedGoodness G ω x M L} := - (measureReal_mono hcover (measure_ne_top _ _)).trans (measureReal_union_le _ _) - constructor - · exact (mul_le_mul_of_nonneg_left hm ha).trans_eq he - · calc - c*S x y = a*twoPoint G p x y := he.symm - _ ≤ a*((law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + - (law p).real {ω | ¬ CappedGoodness G ω x M L}) := mul_le_mul_of_nonneg_left hb ha - _ ≤ a*(law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + - S x y*(law p).real {ω | ¬ CappedGoodness G ω x M L} := by - rw [mul_add] - exact add_le_add le_rfl (mul_le_mul_of_nonneg_right hle measureReal_nonneg) - - - -theorem connectionAdjustedRule_success_lower - (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) - (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) - (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) - (hO : ∀ x y, S x y ≠ 0 → x ∈ O ∧ y ∈ O) - (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) - (M : ℕ) (L : ℝ) (x : V) : - c*(∑' y, S x y) ≤ - (connectionAdjustedRule G hloc O p S c hc hS hSsum hrow hτ hO hcov M L).successProbability p x + - (law p).real {ω | ¬ CappedGoodness G ω x M L} := by - let q := connectionAdjustedRule G hloc O p S c hc hS hSsum hrow hτ hO hcov M L - let ε := (law p).real {ω | ¬ CappedGoodness G ω x M L} - have h (y : V) : c*S x y ≤ q.kernel p x y + S x y * ε := - (integral_cappedConnectionMass_bounds G hloc p S c hc hS hτ M L x y).2 - have hh := ((hSsum x).mul_left c).tsum_le_tsum h - ((q.summable_kernel p x).add ((hSsum x).mul_right ε)) - rw [(q.summable_kernel p x).tsum_add ((hSsum x).mul_right ε),tsum_mul_left,tsum_mul_right] at hh - exact hh.trans (add_le_add le_rfl ((mul_le_mul_of_nonneg_right (hrow x) measureReal_nonneg).trans_eq (one_mul ε))) - -end ConnectionAdjustedKernel - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ConnectionAdjustedOperator -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - - - -theorem connectionAdjustedRule_operator - (G : BondGraph V E) (hloc : LocallyFinite G) (o : V) (p : unitInterval) - (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) - (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) - (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) - (hO : ∀ x y, S x y ≠ 0 → x ∈ vertexOrbit G o ∧ y ∈ vertexOrbit G o) - (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) - (M : ℕ) (L b : ℝ) (hb : 0 < b) (hret : b ≤ ∑' y, S o y) - (hbad : (law p).real {ω | ¬ CappedGoodness G ω o M L} ≤ c*b/2) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (S x y : ℂ)) : - ∃ q : LocalEndpointRule G hloc (vertexOrbit G o) M L, - c*b/2 ≤ q.successProbability p o ∧ - ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ ≤ 2*‖A‖/b ∧ - ∀ x y, matrixCoeff T x y = (q.normalizedKernel o p x y : ℂ) := by - let q := connectionAdjustedRule G hloc (vertexOrbit G o) p S c hc hS hSsum hrow hτ hO hcov M L - have hlo := connectionAdjustedRule_success_lower G hloc (vertexOrbit G o) p S c hc hS hSsum hrow hτ hO hcov M L o - have hs : c*b/2 ≤ q.successProbability p o := by - have hmul := mul_le_mul_of_nonneg_left hret hc.le - change _ ≤ q.successProbability p o + _ at hlo - linarith - have hu : 0 < q.successProbability p o := (by positivity : 0 < c*b/2).trans_le hs - have hcA (x y : V) : matrixCoeff ((c:ℂ) • A) x y = (c*S x y : ℝ) := by - change (c:ℂ)*matrixCoeff A x y = _ - rw [hA,Complex.ofReal_mul] - obtain ⟨B,hBn,hB⟩ := exists_operator_of_matrix_domination - (fun x y => c*S x y) (q.kernel p) (fun x y => mul_nonneg hc.le (hS x y)) - (fun x y => by - rw [abs_of_nonneg (q.kernel_nonneg p x y)] - exact (integral_cappedConnectionMass_bounds G hloc p S c hc hS hτ M L x y).1) - ((c:ℂ) • A) hcA - have hBn' : ‖B‖ ≤ c*‖A‖ := by - simpa only [norm_smul,Complex.norm_of_nonneg hc.le] using hBn - obtain ⟨T,hTn,hT⟩ := q.normalize_mass_operator o p hu B _ hBn' hB - refine ⟨q,hs,T,q.normalized_operator_norm_pos o p hu T hT,hTn.trans ?_,hT⟩ - apply (div_le_iff₀ hu).mpr - rw [div_mul_eq_mul_div] - apply (le_div_iff₀ hb).mpr - have hh := mul_le_mul_of_nonneg_right hs (show 0 ≤ 2*‖A‖ by positivity) - nlinarith only [hh] - -end ConnectionAdjustedOperator - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter Real -open scoped Topology -section CappedGoodnessLimit -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] - -omit [Countable V] in -theorem clusterLarge_probability_tendsto_zero (G : BondGraph V E) (p : unitInterval) (x : V) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : - Tendsto (fun M : ℕ => (law p).real (clusterLarge G x M)) atTop (𝓝 0) := by - have hz : law p {ω | (cluster G ω x).Infinite} = 0 := by - simpa only [Set.Infinite] using (ae_iff.mp hfin) - have ht := (ENNReal.tendsto_toReal (measure_ne_top (law p) (⋂ M, clusterLarge G x M))).comp - (tendsto_measure_iInter_atTop (fun M => (measurableSet_clusterLarge G x M).nullMeasurableSet) - (clusterLarge_antitone G x) ⟨0,measure_ne_top _ _⟩) - rw [← infinite_cluster_eq_iInter,hz,ENNReal.toReal_zero] at ht - exact ht - -omit [Countable V] [Countable E] in -theorem cappedGoodness_failure_le (G : BondGraph V E) (p : unitInterval) - (x : V) (M : ℕ) (L : ℝ) : - (law p).real {ω | ¬ CappedGoodness G ω x M L} ≤ - (law p).real (clusterLarge G x M) + (law p).real {ω | CappedBadGoodness G ω x M L} := by - have hsub : {ω : Set E | ¬ CappedGoodness G ω x M L} ⊆ - clusterLarge G x M ∪ {ω | CappedBadGoodness G ω x M L} := by - intro ω hbad - by_cases hf : (cluster G ω x).Finite - · by_cases hM : (cluster G ω x).ncard ≤ M - · exact Or.inr ⟨hf,hM,fun hg => hbad ⟨hf,hM,hg⟩⟩ - · apply Or.inl - refine ⟨hf.toFinset,?_,fun y hy => hf.mem_toFinset.mp hy⟩ - rw [← Set.ncard_eq_toFinset_card _ hf] - omega - · obtain ⟨t,ht,hcard⟩ := (show (cluster G ω x).Infinite from hf).exists_subset_card_eq M - exact Or.inl ⟨t,hcard.ge,ht⟩ - exact (measureReal_mono hsub (measure_ne_top _ _)).trans (measureReal_union_le _ _) - -omit [Countable V] in - - -theorem cappedGoodness_failure_eventually_small [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : (p:ℝ) < 1) (x : V) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (δ : ℝ) (hδ : 0 < δ) : - ∀ᶠ M : ℕ in atTop, (law p).real {ω | ¬ CappedGoodness G ω x M ((M:ℝ)^(1/2+ε))} ≤ δ := by - have htail := (clusterLarge_probability_tendsto_zero G p x hfin).eventually - (Iio_mem_nhds (show (0:ℝ) < δ/2 by positivity)) - have hr : Tendsto (fun M : ℕ => (M:ℝ)^ε) atTop atTop := - (tendsto_rpow_atTop hε).comp tendsto_natCast_atTop_atTop - have hexp : Tendsto (fun M : ℕ => Real.exp (-(M:ℝ)^ε)) atTop (𝓝 0) := - Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp hr) - have he := hexp.eventually (Iio_mem_nhds (show (0:ℝ) < δ/2 by positivity)) - filter_upwards [htail,he,bad_goodness_stretched_exp G hloc hqt p hp ε hε hε1] with M ht he hg - have hbad := hg x p le_rfl - have hle := cappedGoodness_failure_le G p x M ((M:ℝ)^(1/2+ε)) - linarith - -end CappedGoodnessLimit - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WalkPowerSupport -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem walkKernel_zero_of_not_step (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (x y : V) (hxy : x ≠ y) (hadj : ¬ Adj G x y) : - walkKernel G hloc a x y = 0 := by simp only [walkKernel,ite_eq_right hxy,ite_eq_right hadj,zero_add] - -theorem walkKernel_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) (x : V) : - HasSum (walkKernel G hloc a x) 1 := by - rw [← walkKernel_row_sum G hloc a x] - apply hasSum_sum_of_ne_finset_zero - intro y hy - simp only [Finset.mem_insert,mem_neighbors,not_or] at hy - exact walkKernel_zero_of_not_step G hloc a x y (Ne.symm hy.1) hy.2 - -theorem walkPower_support (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (k : ℕ) (x y : V) (hy : y ∉ reachBall G x k) : (matrixCoeff (P^k) x y).re = 0 := by - induction k generalizing y with - | zero => - have he : y ≠ x := by simpa only [reachBall,Set.mem_singleton_iff] using hy - simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right (Ne.symm he),Complex.zero_re] - | succ k ih => - rw [pow_succ,← ((hpos.pow k).mul_hasSum P x y).tsum_eq] - rw [← tsum_zero] - apply tsum_congr - intro z - by_cases hz : z ∈ reachBall G x k - · have hzy : z ≠ y := by intro he; subst y; exact hy (Or.inl hz) - have hadj : ¬ Adj G z y := by - intro h - apply hy - apply Or.inr - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] - exact ⟨z,hz,h⟩ - rw [hP,walkKernel_zero_of_not_step G hloc a z y hzy hadj,Complex.ofReal_zero,Complex.zero_re,mul_zero] - · rw [ih z hz,zero_mul] - -theorem walkPower_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (k : ℕ) (x : V) : HasSum (fun y => (matrixCoeff (P^k) x y).re) 1 := by - induction k with - | zero => - have h : HasSum (fun y : V => if x=y then (1:ℝ) else 0) 1 := by - exact hasSum_ite_eq' x (1:ℝ) - simpa only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,apply_ite,Complex.one_re,Complex.zero_re] using h - | succ k ih => - let B := (finite_reachBall hloc x k).toFinset - have he (y : V) : (matrixCoeff (P^(k+1)) x y).re = - ∑ z ∈ B, (matrixCoeff (P^k) x z).re * walkKernel G hloc a z y := by - rw [pow_succ,← ((hpos.pow k).mul_hasSum P x y).tsum_eq] - simp only [hP,Complex.ofReal_re] - apply tsum_eq_sum - intro z hz - rw [walkPower_support G hloc a P hpos hP k x z (by simpa only [B,Set.Finite.mem_toFinset] using hz),zero_mul] - have hs := hasSum_sum (s := B) (fun z _ => (walkKernel_hasSum G hloc a z).mul_left (matrixCoeff (P^k) x z).re) - simp only [mul_one] at hs - have hr : (∑ z ∈ B, (matrixCoeff (P^k) x z).re) = 1 := by - rw [← ih.tsum_eq] - exact (tsum_eq_sum fun z hz => walkPower_support G hloc a P hpos hP k x z - (by simpa only [B,Set.Finite.mem_toFinset] using hz)).symm - simpa only [← he,hr] using hs - -end WalkPowerSupport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WalkCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem neighbors_aut_card (G : BondGraph V E) (hloc : LocallyFinite G) - {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) (x : V) : - (neighbors G hloc (g x)).card = (neighbors G hloc x).card := by - have he : neighbors G hloc (g x) = (neighbors G hloc x).map g.toEmbedding := by - ext y - simp only [mem_neighbors,Finset.mem_map,Equiv.coe_toEmbedding] - constructor - · intro h - refine ⟨g.symm y,?_,by simp⟩ - simpa only [g.symm_apply_apply] using adj_aut G (isAut_symm G hg) h - · rintro ⟨z,hz,rfl⟩ - exact adj_aut G hg hz - rw [he,Finset.card_map] - -theorem walkKernel_covariant (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) (x y : V) : - walkKernel G hloc a (g x) (g y) = walkKernel G hloc a x y := by - have hadj : Adj G (g x) (g y) ↔ Adj G x y := - ⟨fun h => by simpa using adj_aut G (isAut_symm G hg) h,adj_aut G hg⟩ - simp only [walkKernel,g.apply_eq_iff_eq,neighbors_aut_card G hloc hg,hadj] - -theorem twoPoint_reachBall_lower [Countable E] (G : BondGraph V E) (p : unitInterval) - (x : V) (k : ℕ) (y : V) (hy : y ∈ reachBall G x k) : - (p:ℝ)^k ≤ twoPoint G p x y := by - induction k generalizing y with - | zero => - simp only [reachBall,Set.mem_singleton_iff] at hy - subst y - simp only [pow_zero,twoPoint_self,le_refl] - | succ k ih => - rcases hy with hy | hy - · have h : (p:ℝ)^(k+1) ≤ (p:ℝ)^k := by - rw [pow_succ] - exact mul_le_of_le_one_right (pow_nonneg p.2.1 k) p.2.2 - exact h.trans (ih y hy) - · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy - obtain ⟨z,hz,hzy⟩ := hy - have h := mul_le_mul_of_nonneg_left (ih z hz) p.2.1 - rw [←pow_succ'] at h - exact h.trans (twoPoint_adj_lower G p x z y hzy) - -end WalkCovariance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OrbitReturn -attribute [local instance] Classical.propDecidable Classical.decEq - -lemma finiteKernel_summable_mul (K : V → V → ℝ) - (hf : ∀ x, (Function.support (K x)).Finite) (x : V) (f : V → ℝ) : - Summable (fun y => K x y * f y) := by - apply summable_of_ne_finset_zero (s := (hf x).toFinset) - intro y hy - have hd : K x y = 0 := by simpa only [Set.Finite.mem_toFinset,Function.mem_support,not_not] using hy - rw [hd,zero_mul] - - - -theorem orbit_two_step_return_lower (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (K : V → V → ℝ) - (hfin : ∀ x, (Function.support (K x)).Finite) - (hrow : ∀ x, HasSum (K x) 1) (hsym : ∀ x y, K x y = K y x) - (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) : - (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ - ∑' z, K (root i₀) z * ∑' y, if y ∈ vertexOrbit G (root i₀) then K z y else 0 := by - let O := vertexOrbit G (root i₀) - let I : V → ℝ := fun x => if x ∈ O then 1 else 0 - let f : V → ℝ := fun x => ∑' y, K x y * I y - let g : V → ℝ := fun x => ∑' y, K x y * f y - let σ := ∑ i, weight i * I (root i) - have hI (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : I (a x) = I x := by - simp only [I,O,mem_vertexOrbit_aut_iff G (root i₀) hab] - have hf (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : f (a x) = f x := by - dsimp only [f] - rw [←a.tsum_eq (fun y => K (a x) y*I y)] - simp only [hcov a b hab,hI a b hab] - have hg (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : g (a x) = g x := by - dsimp only [g] - rw [←a.tsum_eq (fun y => K (a x) y*f y)] - simp only [hcov a b hab,hf a b hab] - have hgO (x : V) (hx : x ∈ O) : g x = g (root i₀) := by - obtain ⟨a,b,hab,rfl⟩ := hx - exact hg a b hab _ - have hmean : ∑ i, weight i*f (root i) = σ := by - have ht := htr.real root weight Γ (fun x y => K x y*I y) - (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; rw [hcov a b hab,hI a b hab]) - (fun x => finiteKernel_summable_mul K hfin x I) - (fun y => by simpa only [hsym, mul_comm] using (hrow y).summable.mul_left (I y)) - calc - _ = ∑ i, weight i * ∑' x, K x (root i)*I (root i) := ht - _ = σ := by simp only [tsum_mul_right,show ∀ y, ∑' x, K x y = 1 from fun y => by simpa only [hsym] using (hrow y).tsum_eq,one_mul,σ] - have hsecond : σ*g (root i₀) = ∑ i, weight i*f (root i)^2 := by - have ht := htr.real root weight Γ (fun x y => I x*K x y*f y) - (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; rw [hcov a b hab,hI a b hab,hf a b hab]) - (fun x => by simpa only [mul_assoc] using (finiteKernel_summable_mul K hfin x f).mul_left (I x)) - (fun y => by simpa only [hsym,mul_comm,mul_left_comm,mul_assoc] using (finiteKernel_summable_mul K hfin y I).mul_right (f y)) - have hr (i : ι) : I (root i)*g (root i) = I (root i)*g (root i₀) := by - by_cases hi : root i ∈ O - · rw [hgO _ hi] - · simp only [I,ite_eq_right hi,zero_mul] - calc - _ = ∑ i, weight i*(I (root i)*g (root i)) := by - simp only [hr,σ,Finset.sum_mul,mul_assoc] - _ = ∑ i, weight i*∑' x, I x*K x (root i)*f (root i) := by - simpa only [mul_assoc,tsum_mul_left,g] using ht - _ = ∑ i, weight i*f (root i)^2 := by - simp only [tsum_mul_right] - congr 1 - ext i - congr 1 - rw [show (∑' x, I x*K x (root i)) = f (root i) by simp only [f,hsym,mul_comm]] - ring - have hvariance : 0 ≤ ∑ i, weight i*(f (root i)-σ)^2 := - Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (sq_nonneg _)) - have he : (∑ i, weight i*(f (root i)-σ)^2) = (∑ i, weight i*f (root i)^2)-σ^2 := by - simp_rw [sub_sq,mul_add,mul_sub] - rw [Finset.sum_add_distrib,Finset.sum_sub_distrib] - have hc : (∑ i, weight i*(2*f (root i)*σ)) = 2*σ*(∑ i, weight i*f (root i)) := by - rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i hi; ring - rw [hc,hmean,←Finset.sum_mul,hw1,one_mul] - ring - rw [he,←hsecond] at hvariance - have hσ : 0 < σ := by - have hx : root i₀ ∈ O := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ - have hIn (x : V) : 0 ≤ I x := by dsimp [I]; split_ifs <;> norm_num - have hb := Finset.single_le_sum (fun i _ => mul_nonneg (hw i) (hIn (root i))) (Finset.mem_univ i₀) - have he₀ : weight i₀*I (root i₀) = weight i₀ := by simp only [I,ite_eq_left hx,mul_one] - rw [he₀] at hb - exact hw₀.trans_le hb - have hbound : σ ≤ g (root i₀) := by nlinarith only [hvariance,hσ] - simpa only [σ,g,f,I,mul_ite,mul_one,mul_zero,zero_mul] using hbound - -end OrbitReturn -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WalkOrbitReturn -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem matrixCoeff_real_symm (A : Hilbert V →L[ℂ] Hilbert V) - (hA : IsSelfAdjoint A) (x y : V) : (matrixCoeff A x y).re = (matrixCoeff A y x).re := by - have h := congrArg Complex.re (matrixCoeff_adjoint A x y) - simpa only [hA.star_eq,Complex.star_def,Complex.conj_re] using h - -theorem finite_positive_square_row (A : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) (hfin : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (f : V → ℝ) (x : V) : - (∑' y, (matrixCoeff (A*A) x y).re*f y) = - ∑' z, (matrixCoeff A x z).re*∑' y, (matrixCoeff A z y).re*f y := by - let K := fun x y => (matrixCoeff A x y).re - let B := (hfin x).toFinset - have hz (z : V) (hz : z ∉ B) : K x z = 0 := by - simpa only [B,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz - have he (y : V) : (matrixCoeff (A*A) x y).re*f y = ∑ z ∈ B, K x z*(K z y*f y) := by - rw [←(hA.mul_hasSum A x y).tsum_eq,tsum_eq_sum (s := B) (fun z h => by change K x z*K z y = 0; rw [hz z h,zero_mul]),Finset.sum_mul] - apply Finset.sum_congr rfl - intro z h - exact mul_assoc _ _ _ - have hs := hasSum_sum (s := B) (fun z _ => - (finiteKernel_summable_mul K hfin z f).hasSum.mul_left (K x z)) - have hr : (∑' z, K x z*∑' y, K z y*f y) = ∑ z ∈ B, K x z*∑' y, K z y*f y := - tsum_eq_sum (fun z h => by rw [hz z h,zero_mul]) - simpa only [←he,←hr] using hs.tsum_eq - -theorem walkPower_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) (x : V) : - (Function.support (fun y => (matrixCoeff (P^k) x y).re)).Finite := by - apply (finite_reachBall hloc x k).subset - intro y hy - by_contra hn - exact hy (walkPower_support G hloc a P hpos hP k x y hn) - -theorem walkPower_invariant (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) : - KernelInvariant (vertexAut G) (P^k) := by - apply KernelInvariant.pow - intro g hg x y - obtain ⟨b,hb⟩ := hg - simp only [hP,walkKernel_covariant G hloc a hb] - - - -theorem walkPower_even_orbit_return (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) : - (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ - ∑' y, if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^(2*k)) (root i₀) y).re else 0 := by - have h := orbit_two_step_return_lower G root weight Γ hΓ htr hw hw1 i₀ hw₀ - (fun x y => (matrixCoeff (P^k) x y).re) - (walkPower_finite_support G hloc a P hpos hP k) - (walkPower_hasSum G hloc a P hpos hP k) - (matrixCoeff_real_symm (P^k) (hsym.pow k)) - (fun g b hb x y => congrArg Complex.re (walkPower_invariant G hloc a P hP k g ⟨b,hb⟩ x y)) - have he := finite_positive_square_row (P^k) (hpos.pow k) - (walkPower_finite_support G hloc a P hpos hP k) - (fun y => if y ∈ vertexOrbit G (root i₀) then 1 else 0) (root i₀) - simp only [mul_ite,mul_one,mul_zero] at he - rw [←he] at h - simpa only [←pow_add,←two_mul] using h - -end WalkOrbitReturn -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped Topology -section StartingEndpointRule -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem starting_endpoint_rule_of_walk (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) - (a : ℝ) (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) - (hsym : IsSelfAdjoint P) (hnorm : ‖P‖ < 1) - (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (η : ℝ) (hη : 0 < η) (M₀ : ℕ) : - ∃ M ≥ M₀, ∃ q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M ((M:ℝ)^(1/2+ε)), - 0 < q.successProbability p (root i₀) ∧ - ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ < η ∧ - ∀ x y, matrixCoeff T x y = (q.normalizedKernel (root i₀) p x y : ℂ) := by - let O := vertexOrbit G (root i₀) - have ho : root i₀ ∈ O := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ - let b : ℝ := ∑ i, if root i ∈ O then weight i else 0 - have hb : 0 < b := by - have hn (i : ι) : 0 ≤ if root i ∈ O then weight i else 0 := by split_ifs; exact hw i; exact le_rfl - have hh := Finset.single_le_sum (fun i _ => hn i) (Finset.mem_univ i₀) - simp only [ite_eq_left ho] at hh - exact hw₀.trans_le hh - have ht := tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg P) hnorm - obtain ⟨k,hk⟩ := (ht.eventually (Iio_mem_nhds (show (0:ℝ) < η*b/2 by positivity))).exists - have hk1 : ‖P‖^k ≤ 1 := pow_le_one₀ (norm_nonneg P) hnorm.le - have hk2 : 2*‖P‖^(2*k)/b < η := by - rw [show 2*k = k+k from Nat.two_mul k,pow_add] - have hh : ‖P‖^k*‖P‖^k ≤ ‖P‖^k := mul_le_of_le_one_right (pow_nonneg (norm_nonneg P) _) hk1 - apply (div_lt_iff₀ hb).mpr - change ‖P‖^k < η*b/2 at hk - nlinarith only [hh,hk] - let K : V → V → ℝ := fun x y => (matrixCoeff (P^(2*k)) x y).re - let S : V → V → ℝ := fun x y => if x ∈ O ∧ y ∈ O then K x y else 0 - have hK (x y : V) : 0 ≤ K x y := (hpos.pow (2*k) x y).2 - have hS (x y : V) : 0 ≤ S x y := by dsimp [S]; split_ifs; exact hK x y; exact le_rfl - have hSK (x y : V) : S x y ≤ K x y := by dsimp [S]; split_ifs; exact le_rfl; exact hK x y - have hsum (x : V) : HasSum (K x) 1 := walkPower_hasSum G hloc a P hpos hP (2*k) x - have hSsum (x : V) : Summable (S x) := Summable.of_nonneg_of_le (hS x) (hSK x) (hsum x).summable - have hrow (x : V) : ∑' y, S x y ≤ 1 := by - rw [←(hsum x).tsum_eq] - exact (hSsum x).tsum_le_tsum (hSK x) (hsum x).summable - have hτ (x y : V) (hxy : S x y ≠ 0) : (p:ℝ)^(2*k) ≤ twoPoint G p x y := by - apply twoPoint_reachBall_lower G p x (2*k) y - by_contra hn - have hz := walkPower_support G hloc a P hpos hP (2*k) x y hn - apply hxy - dsimp [S,K] - rw [hz] - split_ifs <;> rfl - have hO (x y : V) (hxy : S x y ≠ 0) : x ∈ O ∧ y ∈ O := by - by_contra ho - exact hxy (ite_eq_right ho) - have hcov (g : V ≃ V) (d : E ≃ E) (hg : IsAut G g d) (x y : V) : S (g x) (g y) = S x y := by - simp only [S,O,mem_vertexOrbit_aut_iff G (root i₀) hg,K, - walkPower_invariant G hloc a P hP (2*k) g ⟨d,hg⟩] - have hret : b ≤ ∑' y, S (root i₀) y := by - simpa only [b,S,K,ho,true_and,O] using - walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k - obtain ⟨A,hAn,hA⟩ := exists_operator_of_matrix_domination K S hK - (fun x y => by rw [abs_of_nonneg (hS x y)]; exact hSK x y) (P^(2*k)) (hpos.pow (2*k)).real - have hc : 0 < (p:ℝ)^(2*k) := pow_pos hp _ - have hbad := cappedGoodness_failure_eventually_small G hloc hqt p hp1 (root i₀) hfin ε hε hε1 - ((p:ℝ)^(2*k)*b/2) (by positivity) - obtain ⟨M,hM,hMb⟩ := ((eventually_ge_atTop M₀).and hbad).exists - obtain ⟨q,hq,T,hTpos,hTn,hT⟩ := connectionAdjustedRule_operator G hloc (root i₀) p S - ((p:ℝ)^(2*k)) hc hS hSsum hrow hτ hO hcov M ((M:ℝ)^(1/2+ε)) b hb hret hMb A hA - refine ⟨M,hM,q,(by positivity : 0 < (p:ℝ)^(2*k)*b/2).trans_le hq,T,hTpos,?_,hT⟩ - apply lt_of_le_of_lt hTn - apply lt_of_le_of_lt _ hk2 - have hpow (j : ℕ) : ‖P^j‖ ≤ ‖P‖^j := by - induction j with - | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) - | succ j ih => - rw [pow_succ,pow_succ] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) - exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hAn.trans (hpow (2*k))) (by norm_num)) hb.le - -end StartingEndpointRule -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section NonamenableStartingMap -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Countable V] [Countable E] [Nonempty V] - - - -theorem nonamenable_starting_endpoint_rule (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (η : ℝ) (hη : 0 < η) (M₀ : ℕ) : - ∃ M ≥ M₀, ∃ q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M ((M:ℝ)^(1/2+ε)), - 0 < q.successProbability p (root i₀) ∧ - ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ < η ∧ - ∀ x y, matrixCoeff T x y = (q.normalizedKernel (root i₀) p x y : ℂ) := by - obtain ⟨D,P,hD,hdeg,hPn,hPs,hP⟩ := exists_strict_walk_operator G hloc hqt hh - have hDr : (0:ℝ) < D := Nat.cast_pos.mpr hD - have ha : 0 ≤ (1:ℝ)/(2*D) := by positivity - have haD : (1:ℝ)/(2*D)*D ≤ 1 := by - rw [div_mul_eq_mul_div] - apply (div_le_iff₀ (by positivity)).mpr - nlinarith - have hpos : PositiveRealMatrix P := by - intro x y - change (P (lp.single 2 y (1:ℂ)) x).im = 0 ∧ 0 ≤ (P (lp.single 2 y (1:ℂ)) x).re - rw [hP] - exact ⟨Complex.ofReal_im _,walkKernel_nonneg G hloc D hdeg _ ha haD x y⟩ - exact starting_endpoint_rule_of_walk G hloc hqt p hp hp1 root weight Γ hΓ htr hw hw1 i₀ hw₀ hfin - _ P hpos hPs.isSelfAdjoint hPn hP ε hε hε1 η hη M₀ - -end NonamenableStartingMap -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteOrbitPartition -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_partition_square_bound {α ι : Type*} [Fintype ι] - (C : Finset α) (color : α → ι) (q : α → ℝ) - (hq : ∀ x ∈ C, (∑ y ∈ C, if color y = color x then (1:ℝ) else 0) ≤ q x) : - (C.card:ℝ)^2 ≤ Fintype.card ι * ∑ x ∈ C, q x := by - let c : ι → ℝ := fun i => ∑ x ∈ C, if color x=i then 1 else 0 - have hsum : (∑ i, c i) = C.card := by - dsimp only [c] - rw [Finset.sum_comm] - simp - have hsq : (∑ i, c i^2) = ∑ x ∈ C, c (color x) := by - have he (i : ι) : c i^2 = ∑ x ∈ C, if color x=i then c i else 0 := by - rw [pow_two] - conv_lhs => lhs; change ∑ x ∈ C, if color x=i then (1:ℝ) else 0 - rw [Finset.sum_mul] - apply Finset.sum_congr rfl - intro x hx - split_ifs <;> simp only [one_mul,zero_mul] - simp only [he] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x hx - simp - have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : ι => (1:ℝ)) c - simp only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one,hsum,hsq] at h - exact h.trans (mul_le_mul_of_nonneg_left (Finset.sum_le_sum hq) (Nat.cast_nonneg _)) - -theorem vertexOrbit_eq_of_mem (G : BondGraph V E) (o x : V) (hx : x ∈ vertexOrbit G o) : - vertexOrbit G x = vertexOrbit G o := by - obtain ⟨a,b,hab,rfl⟩ := hx - ext y - constructor - · rintro ⟨c,d,hcd,hc⟩ - exact ⟨a.trans c,b.trans d,isAut_trans G hab hcd,hc⟩ - · rintro ⟨c,d,hcd,hc⟩ - exact ⟨a.symm.trans c,b.symm.trans d,isAut_trans G (isAut_symm G hab) hcd,by simpa using hc⟩ - - - -theorem finite_sameOrbit_pairs_lower (G : BondGraph V E) - {ι : Type*} [Fintype ι] (root : ι → V) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (C : Finset V) : - (C.card:ℝ)^2 ≤ Fintype.card ι * - ∑ x ∈ C, ∑ y ∈ C, if y ∈ vertexOrbit G x then (1:ℝ) else 0 := by - let color : V → ι := fun x => (hcover x).choose - have hc (x : V) : x ∈ vertexOrbit G (root (color x)) := (hcover x).choose_spec - apply finite_partition_square_bound C color - intro x hx - apply Finset.sum_le_sum - intro y hy - by_cases h : color y = color x - · have hm : y ∈ vertexOrbit G x := by - rw [vertexOrbit_eq_of_mem G (root (color x)) x (hc x)] - simpa only [h] using hc y - simp only [ite_eq_left h,ite_eq_left hm,le_refl] - · simp only [ite_eq_right h] - split_ifs <;> norm_num - -end FiniteOrbitPartition -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section BinOrbitRowMass -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binSizeMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : ℝ := - ∑' y, binConnectionMass G n ω x y - -noncomputable def binOrbitRowMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : ℝ := - ∑' y, if y ∈ vertexOrbit G x then binConnectionMass G n ω x y else 0 - -theorem binMass_eq_of_window (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (hb : ClusterWindow G x n (2*n) ω) : - binConnectionMass G n ω x y = if y ∈ cluster G ω x then 1 else 0 := by - simp only [binConnectionMass,hb.1,hb.2.1,hb.2.2,true_and] - rfl - -theorem binMass_zero_of_not_window (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (hb : ¬ ClusterWindow G x n (2*n) ω) : binConnectionMass G n ω x y = 0 := by - apply ite_eq_right - exact fun h => hb ⟨h.1,h.2.1,h.2.2.1⟩ - -theorem binSizeMass_eq (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) - (hb : ClusterWindow G x n (2*n) ω) : binSizeMass G n ω x = (cluster G ω x).ncard := by - unfold binSizeMass - simp only [binMass_eq_of_window G n ω x _ hb] - rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by simp only [Set.Finite.mem_toFinset] at hy; simp only [ite_eq_right hy])] - have he : (∑ y ∈ hb.1.toFinset, if y ∈ cluster G ω x then (1:ℝ) else 0) = ∑ _y ∈ hb.1.toFinset, (1:ℝ) := by - apply Finset.sum_congr rfl - intro y hy - exact ite_eq_left (hb.1.mem_toFinset.mp hy) - rw [he] - simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hb.1] - -theorem binOrbitRowMass_eq (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) - (hb : ClusterWindow G x n (2*n) ω) : - binOrbitRowMass G n ω x = ∑ y ∈ hb.1.toFinset, if y ∈ vertexOrbit G x then (1:ℝ) else 0 := by - unfold binOrbitRowMass - rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by - have hc : y ∉ cluster G ω x := fun h => hy (hb.1.mem_toFinset.mpr h) - rw [binMass_eq_of_window G n ω x y hb,ite_eq_right hc,ite_self])] - apply Finset.sum_congr rfl - intro y hy - rw [binMass_eq_of_window G n ω x y hb,ite_eq_left (hb.1.mem_toFinset.mp hy)] - -theorem binOrbitRowMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : - 0 ≤ binOrbitRowMass G n ω x := by - apply tsum_nonneg - intro y - split_ifs - · exact binConnectionMass_nonneg G n ω x y - · exact le_rfl - -theorem binOrbitRowMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (ω : Set E) (x : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binOrbitRowMass G n ω x = binOrbitRowMass G n (ω ∩ (Q : Set E)) x := by - dsimp only [binOrbitRowMass] - apply tsum_congr - intro y - rw [binConnectionMass_local G hloc n ω x y] - -theorem binSizeMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (ω : Set E) (x : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - binSizeMass G n ω x = binSizeMass G n (ω ∩ (Q : Set E)) x := by - dsimp only [binSizeMass] - apply tsum_congr - intro y - exact binConnectionMass_local G hloc n ω x y - -theorem binOrbitRowMass_covariant (G : BondGraph V E) (n : ℕ) (ω : Set E) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : - binOrbitRowMass G n (b ⁻¹' ω) x = binOrbitRowMass G n ω (a x) := by - unfold binOrbitRowMass - rw [←a.tsum_eq (fun y => if y ∈ vertexOrbit G (a x) then binConnectionMass G n ω (a x) y else 0)] - have ho : vertexOrbit G (a x) = vertexOrbit G x := vertexOrbit_eq_of_mem G x (a x) ⟨a,b,hab,rfl⟩ - simp only [ho,mem_vertexOrbit_aut_iff G x hab,binConnectionMass_covariant G hab] - -theorem binSizeMass_covariant (G : BondGraph V E) (n : ℕ) (ω : Set E) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : - binSizeMass G n (b ⁻¹' ω) x = binSizeMass G n ω (a x) := by - unfold binSizeMass - rw [←a.tsum_eq (fun y => binConnectionMass G n ω (a x) y)] - simp only [binConnectionMass_covariant G hab] - -end BinOrbitRowMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BinOrbitTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def binOrbitTransportMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : ℝ := - binConnectionMass G n ω x y * binOrbitRowMass G n ω y / binSizeMass G n ω x - -theorem binOrbitRowMass_zero (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) - (hb : ¬ ClusterWindow G x n (2*n) ω) : binOrbitRowMass G n ω x = 0 := by - simp only [binOrbitRowMass,binMass_zero_of_not_window G n ω x _ hb,ite_self,tsum_zero] - -theorem binOrbitTransportMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : - 0 ≤ binOrbitTransportMass G n ω x y := by - exact div_nonneg (mul_nonneg (binConnectionMass_nonneg G n ω x y) (binOrbitRowMass_nonneg G n ω y)) - (tsum_nonneg (binConnectionMass_nonneg G n ω x)) - -theorem binOrbitTransportMass_column (G : BondGraph V E) (n : ℕ) (hn : 0 < n) - (ω : Set E) (y : V) : (∑' x, binOrbitTransportMass G n ω x y) = binOrbitRowMass G n ω y := by - by_cases hb : ClusterWindow G y n (2*n) ω - · have he (x : V) : binOrbitTransportMass G n ω x y = - binConnectionMass G n ω x y * (binOrbitRowMass G n ω y / binSizeMass G n ω y) := by - by_cases hz : binConnectionMass G n ω x y = 0 - · simp only [binOrbitTransportMass,hz,zero_mul,zero_div] - · obtain ⟨hf,hN,hc⟩ := binConnectionMass_support G n ω x y hz - have hset := cluster_eq_of_conn G ω hc - have hbx : ClusterWindow G x n (2*n) ω := by - unfold ClusterWindow at hb ⊢ - simpa only [hset] using hb - rw [binOrbitTransportMass,binSizeMass_eq G n ω x hbx,binSizeMass_eq G n ω y hb,hset] - exact mul_div_assoc _ _ _ - rw [show (∑' x, binOrbitTransportMass G n ω x y) = - ∑' x, binConnectionMass G n ω x y*(binOrbitRowMass G n ω y/binSizeMass G n ω y) from tsum_congr he, - tsum_mul_right] - have hcol : (∑' x, binConnectionMass G n ω x y) = binSizeMass G n ω y := by - simp only [binConnectionMass_symm G n ω,binSizeMass] - rw [hcol] - have hs : binSizeMass G n ω y ≠ 0 := by - rw [binSizeMass_eq G n ω y hb] - exact Nat.cast_ne_zero.mpr (Nat.ne_of_gt (hn.trans_le hb.2.1)) - exact mul_div_cancel₀ _ hs - · have he : ∀ x, binOrbitTransportMass G n ω x y = 0 := by - intro x - simp only [binOrbitTransportMass,binOrbitRowMass_zero G n ω y hb,mul_zero,zero_div] - simp only [he,tsum_zero,binOrbitRowMass_zero G n ω y hb] - -theorem binOrbitTransportMass_row (G : BondGraph V E) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (n : ℕ) (hn : 0 < n) (ω : Set E) (x : V) : - (if ClusterWindow G x n (2*n) ω then (n:ℝ)/Fintype.card ι else 0) ≤ - ∑' y, binOrbitTransportMass G n ω x y := by - by_cases hb : ClusterWindow G x n (2*n) ω - · rw [ite_eq_left hb] - let C := hb.1.toFinset - have hs : (0:ℝ) < (cluster G ω x).ncard := Nat.cast_pos.mpr (hn.trans_le hb.2.1) - have ht : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos - have hqy (y : V) (hy : y ∈ C) : binOrbitRowMass G n ω y = - ∑ z ∈ C, if z ∈ vertexOrbit G y then (1:ℝ) else 0 := by - have hc : Conn G ω x y := hb.1.mem_toFinset.mp hy - have he := cluster_eq_of_conn G ω hc - have hby : ClusterWindow G y n (2*n) ω := by - unfold ClusterWindow at hb ⊢ - simpa only [←he] using hb - rw [binOrbitRowMass_eq G n ω y hby] - have hC : hby.1.toFinset = C := by - apply Finset.coe_injective - simpa only [C,Set.Finite.coe_toFinset] using he.symm - rw [hC] - have he : (∑' y, binOrbitTransportMass G n ω x y) = - (∑ y ∈ C, ∑ z ∈ C, if z ∈ vertexOrbit G y then (1:ℝ) else 0)/(cluster G ω x).ncard := by - rw [tsum_eq_sum (s := C) (fun y hy => by - have hc : y ∉ cluster G ω x := fun h => hy (hb.1.mem_toFinset.mpr h) - simp only [binOrbitTransportMass,binMass_eq_of_window G n ω x y hb,ite_eq_right hc,zero_mul,zero_div])] - rw [Finset.sum_div] - apply Finset.sum_congr rfl - intro y hy - simp only [binOrbitTransportMass,binMass_eq_of_window G n ω x y hb, - ite_eq_left (hb.1.mem_toFinset.mp hy),one_mul,binSizeMass_eq G n ω x hb,hqy y hy] - rw [he] - apply (div_le_div_iff₀ ht hs).mpr - have h := finite_sameOrbit_pairs_lower G root hcover C - have hC : (C.card:ℝ) = (cluster G ω x).ncard := by - exact_mod_cast (Set.ncard_eq_toFinset_card _ hb.1).symm - rw [hC] at h - have hn' : (n:ℝ) ≤ (cluster G ω x).ncard := by exact_mod_cast hb.2.1 - nlinarith [mul_le_mul_of_nonneg_right hn' hs.le] - · rw [ite_eq_right hb] - exact tsum_nonneg (binOrbitTransportMass_nonneg G n ω x) - -end BinOrbitTransport - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Covariance + +namespace OAI + +/-! Connections for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterWindowLaw +attribute [local instance] Classical.propDecidable Classical.decEq + +def ClusterWindow (G : BondGraph V E) (x : V) (lo hi : ℕ) (ω : Set E) : Prop := + (cluster G ω x).Finite ∧ lo ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < hi + +theorem clusterWindow_local (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (lo hi : ℕ) (ω : Set E) : + let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset + ClusterWindow G x lo hi ω ↔ ClusterWindow G x lo hi (ω ∩ (Q : Set E)) := by + let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset + change ClusterWindow G x lo hi ω ↔ ClusterWindow G x lo hi (ω ∩ (Q : Set E)) + constructor + · rintro ⟨hf,hl,hh⟩ + have hs : cluster G ω x ⊆ (finite_reachBall hloc x hi).toFinset := by + simpa only [Set.Finite.coe_toFinset] using finite_cluster_subset_reachBall G ω x hf hi hh.le + have he := cluster_restrict_incident_of_full G hloc _ ω x hs + change cluster G (ω ∩ (Q : Set E)) x = cluster G ω x at he + exact ⟨he.symm ▸ hf,he.symm ▸ hl,he.symm ▸ hh⟩ + · rintro ⟨hf,hl,hh⟩ + have he := cluster_restrict_of_cap G hloc Q ω x hi (Finset.Subset.refl _) hf hh.le + exact ⟨he ▸ hf,he ▸ hl,he ▸ hh⟩ + +theorem measurableSet_clusterWindow (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (lo hi : ℕ) : MeasurableSet {ω | ClusterWindow G x lo hi ω} := by + let Q := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset + have he : {ω | ClusterWindow G x lo hi ω} = + {ω | ω ∩ (Q : Set E) ∈ {η | ClusterWindow G x lo hi η}} := by + ext ω + exact clusterWindow_local G hloc x lo hi ω + rw [he] + exact measurableSet_finite_restriction Q _ + +noncomputable def clusterWindowProbability (G : BondGraph V E) (p : unitInterval) + (x : V) (lo hi : ℕ) : ℝ := (law p).real {ω | ClusterWindow G x lo hi ω} + +theorem finiteClusterWindowMass_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (p : unitInterval) (x : V) (lo hi : ℕ) + (hQ : incidentSupport G hloc (finite_reachBall hloc x hi).toFinset ⊆ Q) : + finiteClusterWindowMass G Q p x lo hi = clusterWindowProbability G p x lo hi := by + let S := incidentSupport G hloc (finite_reachBall hloc x hi).toFinset + let f : Set E → ℝ := fun ω => if ClusterWindow G x lo hi ω then 1 else 0 + have hf (ω) : f ω = f (ω ∩ (S : Set E)) := + if_congr (clusterWindow_local G hloc x lo hi ω) rfl rfl + have he := integral_finite_local Q p f (finite_local_of_subset S Q hQ f hf) + trans ∫ ω, f ω ∂law p + · rw [he] + unfold finiteClusterWindowMass finiteFieldIntegral + apply Finset.sum_congr rfl + intro η _ + congr 1 + unfold f ClusterWindow + dsimp only + split_ifs <;> rfl + change (∫ ω, ({η | ClusterWindow G x lo hi η}.indicator (1 : Set E → ℝ)) ω ∂law p) = _ + exact integral_indicator_one (measurableSet_clusterWindow G hloc x lo hi) + +theorem clusterWindowProbability_nonneg (G : BondGraph V E) (p : unitInterval) + (x : V) (lo hi : ℕ) : 0 ≤ clusterWindowProbability G p x lo hi := ENNReal.toReal_nonneg + +theorem clusterWindowProbability_mono (G : BondGraph V E) (p : unitInterval) + (x : V) {a b c d : ℕ} (hac : c ≤ a) (hbd : b ≤ d) : + clusterWindowProbability G p x a b ≤ clusterWindowProbability G p x c d := by + apply measureReal_mono + · intro ω h + exact ⟨h.1,hac.trans h.2.1,h.2.2.trans_le hbd⟩ + · exact measure_ne_top _ _ + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem finiteClusterWindowMass_amplification (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (k n : ℕ) (p : unitInterval) (x : V) : + finiteClusterWindowMass G (q.amplificationBonds k n x) p x (n-k*M) (2*n) = + clusterWindowProbability G p x (n-k*M) (2*n) := by + apply finiteClusterWindowMass_eq G hloc + exact incidentSupport_ball_mono G hloc x (by dsimp [amplificationRadius]; omega) + +end LocalEndpointRule +end ClusterWindowLaw +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section QuantitativeAmplificationMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def amplificationMomentFactor (k M d : ℕ) (c a t : ℝ) : ℝ := + 4 + (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) + (2*c*(k*M:ℕ))^2*t/a + +theorem amplificationMomentFactor_pos (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : + 0 < amplificationMomentFactor k M d c a t := by + unfold amplificationMomentFactor + positivity + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem amplificationLoad_moment_factor [Nonempty E] (hconn : Connected G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (k n d : ℕ) (hn : 0 < n) (hdeg : ∀ x, degree G x ≤ d) + (a t π : ℝ) (ha : 0 < a) (ht : 0 ≤ t) (hπ : 0 ≤ π) + (hbin : a*n*π ≤ binOrbitRow G p (root i₀) n) + (hwindow : clusterWindowProbability G p (root i₀) (n-k*M) (2*n) ≤ t*π) + (hcode : inverseCodeMass M L^k ≤ n*q.successProbability p (root i₀)^k) : + (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p) ≤ + amplificationMomentFactor k M d c a t * q.successProbability p (root i₀)^k * + (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n) := by + let u := q.successProbability p (root i₀) + let B := u^k * binOrbitRow G p (root i₀) n / n + let D : ℝ := (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) + have hu : 0 ≤ u^k := pow_nonneg (q.successProbability_nonneg p _) _ + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hB : a*π*u^k ≤ B := by + apply (le_div_iff₀ hn').mpr + calc + _ = u^k*(a*n*π) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hbin hu + have hB0 : 0 ≤ B := (mul_nonneg (mul_nonneg ha.le hπ) hu).trans hB + have hcoef : 4*u^k+D*inverseCodeMass M L^k/n ≤ (4+D)*u^k := by + have h := mul_le_mul_of_nonneg_left hcode (show 0 ≤ D by positivity) + have h' : D*inverseCodeMass M L^k/n ≤ D*u^k := by + apply (div_le_iff₀ hn').mpr + nlinarith only [h] + nlinarith only [h'] + have hrem : (2*(c*((k*M:ℕ)*u^k)))^2*(t*π) ≤ + ((2*c*(k*M:ℕ))^2*t/a)*u^k*B := by + have h := mul_le_mul_of_nonneg_left hB + (show 0 ≤ ((2*c*(k*M:ℕ))^2*t/a)*u^k from + mul_nonneg (div_nonneg (mul_nonneg (sq_nonneg _) ht) ha.le) hu) + calc + _ = (((2*c*(k*M:ℕ))^2*t/a)*u^k)*(a*π*u^k) := by + field_simp + _ ≤ _ := h + have hself : root i₀ ∈ vertexOrbit G (root i₀) := by + refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ + intro e + simp + have he := q.amplificationLoad_mean root weight Γ htr + (fun e he => hΓ he) hw i₀ hw₀ hL p k n (root i₀) hself + have hm := q.amplificationLoad_second_moment_le hconn root weight Γ hΓ htr hcov hw hw1 + c hc hmin i₀ hw₀ hL p (root i₀) k n d hn hdeg + rw [he,q.finiteClusterWindowMass_amplification] at hm + change _ ≤ (4*u^k+D*inverseCodeMass M L^k/n)*B + + (2*(c*((k*M:ℕ)*u^k)))^2*clusterWindowProbability G p (root i₀) (n-k*M) (2*n) at hm + calc + _ ≤ _ := hm + _ ≤ (4+D)*u^k*B + (2*(c*((k*M:ℕ)*u^k)))^2*(t*π) := + add_le_add (mul_le_mul_of_nonneg_right hcoef hB0) + (mul_le_mul_of_nonneg_left hwindow (sq_nonneg _)) + _ ≤ (4+D)*u^k*B + ((2*c*(k*M:ℕ))^2*t/a)*u^k*B := add_le_add (le_refl _) hrem + _ = _ := by dsimp [amplificationMomentFactor,D,B,u]; ring + +end LocalEndpointRule +end QuantitativeAmplificationMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section QuantitativeAmplificationStep +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem quantitative_amplification_step [Nonempty E] (hconn : Connected G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (k n d : ℕ) (hn : 0 < n) (hdeg : ∀ x, degree G x ≤ d) + (hu : 0 < q.successProbability p (root i₀)) + (a t π L' : ℝ) (ha : 0 < a) (ht : 0 ≤ t) (hπ : 0 < π) + (hbin : a*n*π ≤ binOrbitRow G p (root i₀) n) + (hwindow : clusterWindowProbability G p (root i₀) (n-k*M) (2*n) ≤ t*π) + (hcode : inverseCodeMass M L^k ≤ n*q.successProbability p (root i₀)^k) + (hbad : 16*amplificationMomentFactor k M d c a t * + (law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ a*π) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : + ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) (2*n+k*M) L', + a*π/(8*amplificationMomentFactor k M d c a t) ≤ q'.successProbability p (root i₀) ∧ + ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ ‖A'‖ ≤ 2*‖A‖^k ∧ + ∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ) := by + let Q := amplificationMomentFactor k M d c a t + let u := q.successProbability p (root i₀) + let B := u^k*binOrbitRow G p (root i₀) n / n + let b := 4*Q*u^k + have hQ : 0 < Q := amplificationMomentFactor_pos k M d c a t ha ht + have huk : 0 < u^k := pow_pos hu _ + have hb : 0 < b := mul_pos (mul_pos (by norm_num) hQ) huk + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hbin0 : 0 < binOrbitRow G p (root i₀) n := + (mul_pos (mul_pos ha hn') hπ).trans_le hbin + have hB : a*π*u^k ≤ B := by + apply (le_div_iff₀ hn').mpr + calc + _ = u^k*(a*n*π) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hbin huk.le + have hm := q.amplificationLoad_moment_factor hconn root weight Γ hΓ htr hcov hw hw1 + c hc hmin i₀ hw₀ hL p k n d hn hdeg a t π ha ht hπ.le hbin hwindow hcode + have hmoment : (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p)/b ≤ B/4 := by + apply (div_le_iff₀ hb).mpr + change _ ≤ Q*u^k*B at hm + calc + _ ≤ Q*u^k*B := hm + _ = _ := by dsimp [b]; ring + have hbad' : b*(law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ B/4 := by + have hh := mul_le_mul_of_nonneg_right hbad huk.le + dsimp [b] + nlinarith only [hh,hB] + obtain ⟨q',hq',A',hA'pos,hA'norm,hA'⟩ := q.amplification_truncation_step root weight Γ htr + (fun e he => hΓ he) hw i₀ hw₀ hL p k n hn hu hbin0 b L' hb hmoment hbad' A hA + refine ⟨q',?_,A',hA'pos,hA'norm,hA'⟩ + apply le_trans _ hq' + change a*π/(8*Q) ≤ B/(2*b) + apply (div_le_div_iff₀ (mul_pos (by norm_num) hQ) (mul_pos (by norm_num) hb)).mpr + have hh := mul_le_mul_of_nonneg_left hB (show 0 ≤ 8*Q by positivity) + dsimp [b] + nlinarith only [hh] + +end LocalEndpointRule +end QuantitativeAmplificationStep +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ConnectionAdjustedRule +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def cappedConnectionMass (G : BondGraph V E) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : ℝ := + if CappedGoodness G ω x M L ∧ Conn G ω x y then c*S x y/twoPoint G p x y else 0 + +theorem cappedConnectionMass_nonneg (G : BondGraph V E) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (hc : 0 ≤ c) (hS : ∀ x y, 0 ≤ S x y) + (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : 0 ≤ cappedConnectionMass G p S c M L ω x y := by + unfold cappedConnectionMass + split_ifs + · exact div_nonneg (mul_nonneg hc (hS x y)) (twoPoint_nonneg G p x y) + · rfl + +theorem cappedConnectionMass_support (G : BondGraph V E) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) + (h : cappedConnectionMass G p S c M L ω x y ≠ 0) : + S x y ≠ 0 ∧ CappedGoodness G ω x M L ∧ Conn G ω x y := by + unfold cappedConnectionMass at h + split_ifs at h with hh + · refine ⟨?_,hh⟩ + intro hz + simp only [hz,mul_zero,zero_div] at h + exact h rfl + · exact (h rfl).elim + +theorem cappedConnectionMass_le (G : BondGraph V E) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) + (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) + (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : cappedConnectionMass G p S c M L ω x y ≤ S x y := by + by_cases hs : S x y = 0 + · simp only [cappedConnectionMass,hs,mul_zero,zero_div,ite_self,le_refl] + · unfold cappedConnectionMass + split_ifs + · apply (div_le_iff₀ (hc.trans_le (hτ x y hs))).mpr + exact (mul_le_mul_of_nonneg_right (hτ x y hs) (hS x y)).trans_eq (mul_comm _ _) + · exact hS x y + +theorem cappedConnectionMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (ω : Set E) (x y : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + cappedConnectionMass G p S c M L ω x y = cappedConnectionMass G p S c M L (ω ∩ (Q:Set E)) x y := by + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + change cappedConnectionMass G p S c M L ω x y = cappedConnectionMass G p S c M L (ω ∩ (Q:Set E)) x y + have hg := cappedGoodness_local G hloc ω x M L + change CappedGoodness G ω x M L ↔ CappedGoodness G (ω ∩ (Q:Set E)) x M L at hg + unfold cappedConnectionMass + apply if_congr _ rfl rfl + constructor + · rintro ⟨h,hxy⟩ + have h' := hg.mp h + have he := cluster_restrict_of_cap G hloc Q ω x M (Finset.Subset.refl _) h'.1 h'.2.1 + refine ⟨h',?_⟩ + change y ∈ cluster G (ω ∩ (Q:Set E)) x + rw [he] + exact hxy + · rintro ⟨h,hxy⟩ + exact ⟨hg.mpr h,conn_mono G Set.inter_subset_left hxy⟩ + +theorem cappedConnectionMass_covariant [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) + (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) + (hS : ∀ x y, S (a x) (a y) = S x y) (ω : Set E) (x y : V) : + cappedConnectionMass G p S c M L (b ⁻¹' ω) x y = cappedConnectionMass G p S c M L ω (a x) (a y) := by + simp only [cappedConnectionMass,cappedGoodness_aut_iff G hab,conn_aut_iff G hab, + hS,twoPoint_aut G p hab] + +noncomputable def connectionAdjustedRule [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) + (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) + (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) + (hO : ∀ x y, S x y ≠ 0 → x ∈ O ∧ y ∈ O) + (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) + (M : ℕ) (L : ℝ) : LocalEndpointRule G hloc O M L where + mass := cappedConnectionMass G p S c M L + radius := M + nonneg := cappedConnectionMass_nonneg G p S c hc.le hS M L + support := by + intro ω x y h + obtain ⟨hs,hg,hxy⟩ := cappedConnectionMass_support G p S c M L ω x y h + exact ⟨(hO x y hs).1,(hO x y hs).2,hxy,hg⟩ + locality := fun ω x y => cappedConnectionMass_local G hloc p S c M L ω x y + covariance := fun a b hab ω x y => cappedConnectionMass_covariant G p S c M L a b hab (hcov a b hab) ω x y + row_le_one := by + intro ω x + have hs : Summable (cappedConnectionMass G p S c M L ω x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + by_contra hn + obtain ⟨_,hg,hxy⟩ := cappedConnectionMass_support G p S c M L ω x y hn + apply hy + simp only [Set.Finite.mem_toFinset] + exact finite_cluster_subset_reachBall G ω x hg.1 M hg.2.1 hxy + exact (hs.tsum_le_tsum (cappedConnectionMass_le G p S c hc hS hτ M L ω x) (hSsum x)).trans (hrow x) + +end ConnectionAdjustedRule + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ConnectionAdjustedKernel +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + +theorem integral_cappedConnectionMass (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (M : ℕ) (L : ℝ) (x y : V) : + (∫ ω, cappedConnectionMass G p S c M L ω x y ∂law p) = + c*S x y/twoPoint G p x y * (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} := by + have hm : MeasurableSet {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} := + (measurableSet_capped_good G hloc x M L).inter (measurableSet_conn G x y) + simpa only [cappedConnectionMass,Set.indicator,Set.mem_ofPred_eq,smul_eq_mul,mul_comm] using + integral_indicator_const (μ := law p) (c*S x y/twoPoint G p x y) hm + +theorem integral_cappedConnectionMass_bounds (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) + (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) + (M : ℕ) (L : ℝ) (x y : V) : + let K := ∫ ω, cappedConnectionMass G p S c M L ω x y ∂law p + K ≤ c*S x y ∧ c*S x y ≤ K + S x y * (law p).real {ω | ¬ CappedGoodness G ω x M L} := by + dsimp only + rw [integral_cappedConnectionMass G hloc] + by_cases hs : S x y = 0 + · simp only [hs,mul_zero,zero_div,zero_mul,zero_add,le_refl,and_self] + have ht : 0 < twoPoint G p x y := hc.trans_le (hτ x y hs) + let a := c*S x y/twoPoint G p x y + have ha : 0 ≤ a := div_nonneg (mul_nonneg hc.le (hS x y)) ht.le + have hle : a ≤ S x y := by + apply (div_le_iff₀ ht).mpr + exact (mul_le_mul_of_nonneg_right (hτ x y hs) (hS x y)).trans_eq (mul_comm _ _) + have he : a*twoPoint G p x y = c*S x y := div_mul_cancel₀ _ ht.ne' + have hsub : {ω : Set E | CappedGoodness G ω x M L ∧ Conn G ω x y} ⊆ {ω | Conn G ω x y} := + fun _ h => h.2 + have hm : (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} ≤ twoPoint G p x y := by + exact measureReal_mono hsub (measure_ne_top _ _) + have hcover : {ω : Set E | Conn G ω x y} ⊆ + {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} ∪ {ω | ¬ CappedGoodness G ω x M L} := by + intro ω h + by_cases hg : CappedGoodness G ω x M L + · exact Or.inl ⟨hg,h⟩ + · exact Or.inr hg + have hb : twoPoint G p x y ≤ + (law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + + (law p).real {ω | ¬ CappedGoodness G ω x M L} := + (measureReal_mono hcover (measure_ne_top _ _)).trans (measureReal_union_le _ _) + constructor + · exact (mul_le_mul_of_nonneg_left hm ha).trans_eq he + · calc + c*S x y = a*twoPoint G p x y := he.symm + _ ≤ a*((law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + + (law p).real {ω | ¬ CappedGoodness G ω x M L}) := mul_le_mul_of_nonneg_left hb ha + _ ≤ a*(law p).real {ω | CappedGoodness G ω x M L ∧ Conn G ω x y} + + S x y*(law p).real {ω | ¬ CappedGoodness G ω x M L} := by + rw [mul_add] + exact add_le_add le_rfl (mul_le_mul_of_nonneg_right hle measureReal_nonneg) + + + +theorem connectionAdjustedRule_success_lower + (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) + (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) + (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) + (hO : ∀ x y, S x y ≠ 0 → x ∈ O ∧ y ∈ O) + (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) + (M : ℕ) (L : ℝ) (x : V) : + c*(∑' y, S x y) ≤ + (connectionAdjustedRule G hloc O p S c hc hS hSsum hrow hτ hO hcov M L).successProbability p x + + (law p).real {ω | ¬ CappedGoodness G ω x M L} := by + let q := connectionAdjustedRule G hloc O p S c hc hS hSsum hrow hτ hO hcov M L + let ε := (law p).real {ω | ¬ CappedGoodness G ω x M L} + have h (y : V) : c*S x y ≤ q.kernel p x y + S x y * ε := + (integral_cappedConnectionMass_bounds G hloc p S c hc hS hτ M L x y).2 + have hh := ((hSsum x).mul_left c).tsum_le_tsum h + ((q.summable_kernel p x).add ((hSsum x).mul_right ε)) + rw [(q.summable_kernel p x).tsum_add ((hSsum x).mul_right ε),tsum_mul_left,tsum_mul_right] at hh + exact hh.trans (add_le_add le_rfl ((mul_le_mul_of_nonneg_right (hrow x) measureReal_nonneg).trans_eq (one_mul ε))) + +end ConnectionAdjustedKernel + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ConnectionAdjustedOperator +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + + + +theorem connectionAdjustedRule_operator + (G : BondGraph V E) (hloc : LocallyFinite G) (o : V) (p : unitInterval) + (S : V → V → ℝ) (c : ℝ) (hc : 0 < c) (hS : ∀ x y, 0 ≤ S x y) + (hSsum : ∀ x, Summable (S x)) (hrow : ∀ x, ∑' y, S x y ≤ 1) + (hτ : ∀ x y, S x y ≠ 0 → c ≤ twoPoint G p x y) + (hO : ∀ x y, S x y ≠ 0 → x ∈ vertexOrbit G o ∧ y ∈ vertexOrbit G o) + (hcov : ∀ a b, IsAut G a b → ∀ x y, S (a x) (a y) = S x y) + (M : ℕ) (L b : ℝ) (hb : 0 < b) (hret : b ≤ ∑' y, S o y) + (hbad : (law p).real {ω | ¬ CappedGoodness G ω o M L} ≤ c*b/2) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (S x y : ℂ)) : + ∃ q : LocalEndpointRule G hloc (vertexOrbit G o) M L, + c*b/2 ≤ q.successProbability p o ∧ + ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ ≤ 2*‖A‖/b ∧ + ∀ x y, matrixCoeff T x y = (q.normalizedKernel o p x y : ℂ) := by + let q := connectionAdjustedRule G hloc (vertexOrbit G o) p S c hc hS hSsum hrow hτ hO hcov M L + have hlo := connectionAdjustedRule_success_lower G hloc (vertexOrbit G o) p S c hc hS hSsum hrow hτ hO hcov M L o + have hs : c*b/2 ≤ q.successProbability p o := by + have hmul := mul_le_mul_of_nonneg_left hret hc.le + change _ ≤ q.successProbability p o + _ at hlo + linarith + have hu : 0 < q.successProbability p o := (by positivity : 0 < c*b/2).trans_le hs + have hcA (x y : V) : matrixCoeff ((c:ℂ) • A) x y = (c*S x y : ℝ) := by + change (c:ℂ)*matrixCoeff A x y = _ + rw [hA,Complex.ofReal_mul] + obtain ⟨B,hBn,hB⟩ := exists_operator_of_matrix_domination + (fun x y => c*S x y) (q.kernel p) (fun x y => mul_nonneg hc.le (hS x y)) + (fun x y => by + rw [abs_of_nonneg (q.kernel_nonneg p x y)] + exact (integral_cappedConnectionMass_bounds G hloc p S c hc hS hτ M L x y).1) + ((c:ℂ) • A) hcA + have hBn' : ‖B‖ ≤ c*‖A‖ := by + simpa only [norm_smul,Complex.norm_of_nonneg hc.le] using hBn + obtain ⟨T,hTn,hT⟩ := q.normalize_mass_operator o p hu B _ hBn' hB + refine ⟨q,hs,T,q.normalized_operator_norm_pos o p hu T hT,hTn.trans ?_,hT⟩ + apply (div_le_iff₀ hu).mpr + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hb).mpr + have hh := mul_le_mul_of_nonneg_right hs (show 0 ≤ 2*‖A‖ by positivity) + nlinarith only [hh] + +end ConnectionAdjustedOperator + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter Real +open scoped Topology +section CappedGoodnessLimit +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] + +omit [Countable V] in +theorem clusterLarge_probability_tendsto_zero (G : BondGraph V E) (p : unitInterval) (x : V) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : + Tendsto (fun M : ℕ => (law p).real (clusterLarge G x M)) atTop (𝓝 0) := by + have hz : law p {ω | (cluster G ω x).Infinite} = 0 := by + simpa only [Set.Infinite] using (ae_iff.mp hfin) + have ht := (ENNReal.tendsto_toReal (measure_ne_top (law p) (⋂ M, clusterLarge G x M))).comp + (tendsto_measure_iInter_atTop (fun M => (measurableSet_clusterLarge G x M).nullMeasurableSet) + (clusterLarge_antitone G x) ⟨0,measure_ne_top _ _⟩) + rw [← infinite_cluster_eq_iInter,hz,ENNReal.toReal_zero] at ht + exact ht + +omit [Countable V] [Countable E] in +theorem cappedGoodness_failure_le (G : BondGraph V E) (p : unitInterval) + (x : V) (M : ℕ) (L : ℝ) : + (law p).real {ω | ¬ CappedGoodness G ω x M L} ≤ + (law p).real (clusterLarge G x M) + (law p).real {ω | CappedBadGoodness G ω x M L} := by + have hsub : {ω : Set E | ¬ CappedGoodness G ω x M L} ⊆ + clusterLarge G x M ∪ {ω | CappedBadGoodness G ω x M L} := by + intro ω hbad + by_cases hf : (cluster G ω x).Finite + · by_cases hM : (cluster G ω x).ncard ≤ M + · exact Or.inr ⟨hf,hM,fun hg => hbad ⟨hf,hM,hg⟩⟩ + · apply Or.inl + refine ⟨hf.toFinset,?_,fun y hy => hf.mem_toFinset.mp hy⟩ + rw [← Set.ncard_eq_toFinset_card _ hf] + omega + · obtain ⟨t,ht,hcard⟩ := (show (cluster G ω x).Infinite from hf).exists_subset_card_eq M + exact Or.inl ⟨t,hcard.ge,ht⟩ + exact (measureReal_mono hsub (measure_ne_top _ _)).trans (measureReal_union_le _ _) + +omit [Countable V] in + + +theorem cappedGoodness_failure_eventually_small [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : (p:ℝ) < 1) (x : V) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (δ : ℝ) (hδ : 0 < δ) : + ∀ᶠ M : ℕ in atTop, (law p).real {ω | ¬ CappedGoodness G ω x M ((M:ℝ)^(1/2+ε))} ≤ δ := by + have htail := (clusterLarge_probability_tendsto_zero G p x hfin).eventually + (Iio_mem_nhds (show (0:ℝ) < δ/2 by positivity)) + have hr : Tendsto (fun M : ℕ => (M:ℝ)^ε) atTop atTop := + (tendsto_rpow_atTop hε).comp tendsto_natCast_atTop_atTop + have hexp : Tendsto (fun M : ℕ => Real.exp (-(M:ℝ)^ε)) atTop (𝓝 0) := + Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp hr) + have he := hexp.eventually (Iio_mem_nhds (show (0:ℝ) < δ/2 by positivity)) + filter_upwards [htail,he,bad_goodness_stretched_exp G hloc hqt p hp ε hε hε1] with M ht he hg + have hbad := hg x p le_rfl + have hle := cappedGoodness_failure_le G p x M ((M:ℝ)^(1/2+ε)) + linarith + +end CappedGoodnessLimit + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WalkPowerSupport +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem walkKernel_zero_of_not_step (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (x y : V) (hxy : x ≠ y) (hadj : ¬ Adj G x y) : + walkKernel G hloc a x y = 0 := by simp only [walkKernel,ite_eq_right hxy,ite_eq_right hadj,zero_add] + +theorem walkKernel_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) (x : V) : + HasSum (walkKernel G hloc a x) 1 := by + rw [← walkKernel_row_sum G hloc a x] + apply hasSum_sum_of_ne_finset_zero + intro y hy + simp only [Finset.mem_insert,mem_neighbors,not_or] at hy + exact walkKernel_zero_of_not_step G hloc a x y (Ne.symm hy.1) hy.2 + +theorem walkPower_support (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (k : ℕ) (x y : V) (hy : y ∉ reachBall G x k) : (matrixCoeff (P^k) x y).re = 0 := by + induction k generalizing y with + | zero => + have he : y ≠ x := by simpa only [reachBall,Set.mem_singleton_iff] using hy + simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right (Ne.symm he),Complex.zero_re] + | succ k ih => + rw [pow_succ,← ((hpos.pow k).mul_hasSum P x y).tsum_eq] + rw [← tsum_zero] + apply tsum_congr + intro z + by_cases hz : z ∈ reachBall G x k + · have hzy : z ≠ y := by intro he; subst y; exact hy (Or.inl hz) + have hadj : ¬ Adj G z y := by + intro h + apply hy + apply Or.inr + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] + exact ⟨z,hz,h⟩ + rw [hP,walkKernel_zero_of_not_step G hloc a z y hzy hadj,Complex.ofReal_zero,Complex.zero_re,mul_zero] + · rw [ih z hz,zero_mul] + +theorem walkPower_hasSum (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (k : ℕ) (x : V) : HasSum (fun y => (matrixCoeff (P^k) x y).re) 1 := by + induction k with + | zero => + have h : HasSum (fun y : V => if x=y then (1:ℝ) else 0) 1 := by + exact hasSum_ite_eq' x (1:ℝ) + simpa only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,apply_ite,Complex.one_re,Complex.zero_re] using h + | succ k ih => + let B := (finite_reachBall hloc x k).toFinset + have he (y : V) : (matrixCoeff (P^(k+1)) x y).re = + ∑ z ∈ B, (matrixCoeff (P^k) x z).re * walkKernel G hloc a z y := by + rw [pow_succ,← ((hpos.pow k).mul_hasSum P x y).tsum_eq] + simp only [hP,Complex.ofReal_re] + apply tsum_eq_sum + intro z hz + rw [walkPower_support G hloc a P hpos hP k x z (by simpa only [B,Set.Finite.mem_toFinset] using hz),zero_mul] + have hs := hasSum_sum (s := B) (fun z _ => (walkKernel_hasSum G hloc a z).mul_left (matrixCoeff (P^k) x z).re) + simp only [mul_one] at hs + have hr : (∑ z ∈ B, (matrixCoeff (P^k) x z).re) = 1 := by + rw [← ih.tsum_eq] + exact (tsum_eq_sum fun z hz => walkPower_support G hloc a P hpos hP k x z + (by simpa only [B,Set.Finite.mem_toFinset] using hz)).symm + simpa only [← he,hr] using hs + +end WalkPowerSupport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WalkCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem neighbors_aut_card (G : BondGraph V E) (hloc : LocallyFinite G) + {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) (x : V) : + (neighbors G hloc (g x)).card = (neighbors G hloc x).card := by + have he : neighbors G hloc (g x) = (neighbors G hloc x).map g.toEmbedding := by + ext y + simp only [mem_neighbors,Finset.mem_map,Equiv.coe_toEmbedding] + constructor + · intro h + refine ⟨g.symm y,?_,by simp⟩ + simpa only [g.symm_apply_apply] using adj_aut G (isAut_symm G hg) h + · rintro ⟨z,hz,rfl⟩ + exact adj_aut G hg hz + rw [he,Finset.card_map] + +theorem walkKernel_covariant (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {g : V ≃ V} {b : E ≃ E} (hg : IsAut G g b) (x y : V) : + walkKernel G hloc a (g x) (g y) = walkKernel G hloc a x y := by + have hadj : Adj G (g x) (g y) ↔ Adj G x y := + ⟨fun h => by simpa using adj_aut G (isAut_symm G hg) h,adj_aut G hg⟩ + simp only [walkKernel,g.apply_eq_iff_eq,neighbors_aut_card G hloc hg,hadj] + +theorem twoPoint_reachBall_lower [Countable E] (G : BondGraph V E) (p : unitInterval) + (x : V) (k : ℕ) (y : V) (hy : y ∈ reachBall G x k) : + (p:ℝ)^k ≤ twoPoint G p x y := by + induction k generalizing y with + | zero => + simp only [reachBall,Set.mem_singleton_iff] at hy + subst y + simp only [pow_zero,twoPoint_self,le_refl] + | succ k ih => + rcases hy with hy | hy + · have h : (p:ℝ)^(k+1) ≤ (p:ℝ)^k := by + rw [pow_succ] + exact mul_le_of_le_one_right (pow_nonneg p.2.1 k) p.2.2 + exact h.trans (ih y hy) + · simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hy + obtain ⟨z,hz,hzy⟩ := hy + have h := mul_le_mul_of_nonneg_left (ih z hz) p.2.1 + rw [←pow_succ'] at h + exact h.trans (twoPoint_adj_lower G p x z y hzy) + +end WalkCovariance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OrbitReturn +attribute [local instance] Classical.propDecidable Classical.decEq + +lemma finiteKernel_summable_mul (K : V → V → ℝ) + (hf : ∀ x, (Function.support (K x)).Finite) (x : V) (f : V → ℝ) : + Summable (fun y => K x y * f y) := by + apply summable_of_ne_finset_zero (s := (hf x).toFinset) + intro y hy + have hd : K x y = 0 := by simpa only [Set.Finite.mem_toFinset,Function.mem_support,not_not] using hy + rw [hd,zero_mul] + + + +theorem orbit_two_step_return_lower (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (K : V → V → ℝ) + (hfin : ∀ x, (Function.support (K x)).Finite) + (hrow : ∀ x, HasSum (K x) 1) (hsym : ∀ x y, K x y = K y x) + (hcov : ∀ a b, IsAut G a b → ∀ x y, K (a x) (a y) = K x y) : + (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ + ∑' z, K (root i₀) z * ∑' y, if y ∈ vertexOrbit G (root i₀) then K z y else 0 := by + let O := vertexOrbit G (root i₀) + let I : V → ℝ := fun x => if x ∈ O then 1 else 0 + let f : V → ℝ := fun x => ∑' y, K x y * I y + let g : V → ℝ := fun x => ∑' y, K x y * f y + let σ := ∑ i, weight i * I (root i) + have hI (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : I (a x) = I x := by + simp only [I,O,mem_vertexOrbit_aut_iff G (root i₀) hab] + have hf (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : f (a x) = f x := by + dsimp only [f] + rw [←a.tsum_eq (fun y => K (a x) y*I y)] + simp only [hcov a b hab,hI a b hab] + have hg (a : V ≃ V) (b : E ≃ E) (hab : IsAut G a b) (x : V) : g (a x) = g x := by + dsimp only [g] + rw [←a.tsum_eq (fun y => K (a x) y*f y)] + simp only [hcov a b hab,hf a b hab] + have hgO (x : V) (hx : x ∈ O) : g x = g (root i₀) := by + obtain ⟨a,b,hab,rfl⟩ := hx + exact hg a b hab _ + have hmean : ∑ i, weight i*f (root i) = σ := by + have ht := htr.real root weight Γ (fun x y => K x y*I y) + (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; rw [hcov a b hab,hI a b hab]) + (fun x => finiteKernel_summable_mul K hfin x I) + (fun y => by simpa only [hsym, mul_comm] using (hrow y).summable.mul_left (I y)) + calc + _ = ∑ i, weight i * ∑' x, K x (root i)*I (root i) := ht + _ = σ := by simp only [tsum_mul_right,show ∀ y, ∑' x, K x y = 1 from fun y => by simpa only [hsym] using (hrow y).tsum_eq,one_mul,σ] + have hsecond : σ*g (root i₀) = ∑ i, weight i*f (root i)^2 := by + have ht := htr.real root weight Γ (fun x y => I x*K x y*f y) + (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; rw [hcov a b hab,hI a b hab,hf a b hab]) + (fun x => by simpa only [mul_assoc] using (finiteKernel_summable_mul K hfin x f).mul_left (I x)) + (fun y => by simpa only [hsym,mul_comm,mul_left_comm,mul_assoc] using (finiteKernel_summable_mul K hfin y I).mul_right (f y)) + have hr (i : ι) : I (root i)*g (root i) = I (root i)*g (root i₀) := by + by_cases hi : root i ∈ O + · rw [hgO _ hi] + · simp only [I,ite_eq_right hi,zero_mul] + calc + _ = ∑ i, weight i*(I (root i)*g (root i)) := by + simp only [hr,σ,Finset.sum_mul,mul_assoc] + _ = ∑ i, weight i*∑' x, I x*K x (root i)*f (root i) := by + simpa only [mul_assoc,tsum_mul_left,g] using ht + _ = ∑ i, weight i*f (root i)^2 := by + simp only [tsum_mul_right] + congr 1 + ext i + congr 1 + rw [show (∑' x, I x*K x (root i)) = f (root i) by simp only [f,hsym,mul_comm]] + ring + have hvariance : 0 ≤ ∑ i, weight i*(f (root i)-σ)^2 := + Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (sq_nonneg _)) + have he : (∑ i, weight i*(f (root i)-σ)^2) = (∑ i, weight i*f (root i)^2)-σ^2 := by + simp_rw [sub_sq,mul_add,mul_sub] + rw [Finset.sum_add_distrib,Finset.sum_sub_distrib] + have hc : (∑ i, weight i*(2*f (root i)*σ)) = 2*σ*(∑ i, weight i*f (root i)) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i hi; ring + rw [hc,hmean,←Finset.sum_mul,hw1,one_mul] + ring + rw [he,←hsecond] at hvariance + have hσ : 0 < σ := by + have hx : root i₀ ∈ O := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ + have hIn (x : V) : 0 ≤ I x := by dsimp [I]; split_ifs <;> norm_num + have hb := Finset.single_le_sum (fun i _ => mul_nonneg (hw i) (hIn (root i))) (Finset.mem_univ i₀) + have he₀ : weight i₀*I (root i₀) = weight i₀ := by simp only [I,ite_eq_left hx,mul_one] + rw [he₀] at hb + exact hw₀.trans_le hb + have hbound : σ ≤ g (root i₀) := by nlinarith only [hvariance,hσ] + simpa only [σ,g,f,I,mul_ite,mul_one,mul_zero,zero_mul] using hbound + +end OrbitReturn +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WalkOrbitReturn +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem matrixCoeff_real_symm (A : Hilbert V →L[ℂ] Hilbert V) + (hA : IsSelfAdjoint A) (x y : V) : (matrixCoeff A x y).re = (matrixCoeff A y x).re := by + have h := congrArg Complex.re (matrixCoeff_adjoint A x y) + simpa only [hA.star_eq,Complex.star_def,Complex.conj_re] using h + +theorem finite_positive_square_row (A : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) (hfin : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (f : V → ℝ) (x : V) : + (∑' y, (matrixCoeff (A*A) x y).re*f y) = + ∑' z, (matrixCoeff A x z).re*∑' y, (matrixCoeff A z y).re*f y := by + let K := fun x y => (matrixCoeff A x y).re + let B := (hfin x).toFinset + have hz (z : V) (hz : z ∉ B) : K x z = 0 := by + simpa only [B,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz + have he (y : V) : (matrixCoeff (A*A) x y).re*f y = ∑ z ∈ B, K x z*(K z y*f y) := by + rw [←(hA.mul_hasSum A x y).tsum_eq,tsum_eq_sum (s := B) (fun z h => by change K x z*K z y = 0; rw [hz z h,zero_mul]),Finset.sum_mul] + apply Finset.sum_congr rfl + intro z h + exact mul_assoc _ _ _ + have hs := hasSum_sum (s := B) (fun z _ => + (finiteKernel_summable_mul K hfin z f).hasSum.mul_left (K x z)) + have hr : (∑' z, K x z*∑' y, K z y*f y) = ∑ z ∈ B, K x z*∑' y, K z y*f y := + tsum_eq_sum (fun z h => by rw [hz z h,zero_mul]) + simpa only [←he,←hr] using hs.tsum_eq + +theorem walkPower_finite_support (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) (x : V) : + (Function.support (fun y => (matrixCoeff (P^k) x y).re)).Finite := by + apply (finite_reachBall hloc x k).subset + intro y hy + by_contra hn + exact hy (walkPower_support G hloc a P hpos hP k x y hn) + +theorem walkPower_invariant (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) : + KernelInvariant (vertexAut G) (P^k) := by + apply KernelInvariant.pow + intro g hg x y + obtain ⟨b,hb⟩ := hg + simp only [hP,walkKernel_covariant G hloc a hb] + + + +theorem walkPower_even_orbit_return (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) (hsym : IsSelfAdjoint P) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) (k : ℕ) : + (∑ i, if root i ∈ vertexOrbit G (root i₀) then weight i else 0) ≤ + ∑' y, if y ∈ vertexOrbit G (root i₀) then (matrixCoeff (P^(2*k)) (root i₀) y).re else 0 := by + have h := orbit_two_step_return_lower G root weight Γ hΓ htr hw hw1 i₀ hw₀ + (fun x y => (matrixCoeff (P^k) x y).re) + (walkPower_finite_support G hloc a P hpos hP k) + (walkPower_hasSum G hloc a P hpos hP k) + (matrixCoeff_real_symm (P^k) (hsym.pow k)) + (fun g b hb x y => congrArg Complex.re (walkPower_invariant G hloc a P hP k g ⟨b,hb⟩ x y)) + have he := finite_positive_square_row (P^k) (hpos.pow k) + (walkPower_finite_support G hloc a P hpos hP k) + (fun y => if y ∈ vertexOrbit G (root i₀) then 1 else 0) (root i₀) + simp only [mul_ite,mul_one,mul_zero] at he + rw [←he] at h + simpa only [←pow_add,←two_mul] using h + +end WalkOrbitReturn +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped Topology +section StartingEndpointRule +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem starting_endpoint_rule_of_walk (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) + (a : ℝ) (P : Hilbert V →L[ℂ] Hilbert V) (hpos : PositiveRealMatrix P) + (hsym : IsSelfAdjoint P) (hnorm : ‖P‖ < 1) + (hP : ∀ x y, matrixCoeff P x y = (walkKernel G hloc a x y : ℂ)) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (η : ℝ) (hη : 0 < η) (M₀ : ℕ) : + ∃ M ≥ M₀, ∃ q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M ((M:ℝ)^(1/2+ε)), + 0 < q.successProbability p (root i₀) ∧ + ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ < η ∧ + ∀ x y, matrixCoeff T x y = (q.normalizedKernel (root i₀) p x y : ℂ) := by + let O := vertexOrbit G (root i₀) + have ho : root i₀ ∈ O := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ + let b : ℝ := ∑ i, if root i ∈ O then weight i else 0 + have hb : 0 < b := by + have hn (i : ι) : 0 ≤ if root i ∈ O then weight i else 0 := by split_ifs; exact hw i; exact le_rfl + have hh := Finset.single_le_sum (fun i _ => hn i) (Finset.mem_univ i₀) + simp only [ite_eq_left ho] at hh + exact hw₀.trans_le hh + have ht := tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg P) hnorm + obtain ⟨k,hk⟩ := (ht.eventually (Iio_mem_nhds (show (0:ℝ) < η*b/2 by positivity))).exists + have hk1 : ‖P‖^k ≤ 1 := pow_le_one₀ (norm_nonneg P) hnorm.le + have hk2 : 2*‖P‖^(2*k)/b < η := by + rw [show 2*k = k+k from Nat.two_mul k,pow_add] + have hh : ‖P‖^k*‖P‖^k ≤ ‖P‖^k := mul_le_of_le_one_right (pow_nonneg (norm_nonneg P) _) hk1 + apply (div_lt_iff₀ hb).mpr + change ‖P‖^k < η*b/2 at hk + nlinarith only [hh,hk] + let K : V → V → ℝ := fun x y => (matrixCoeff (P^(2*k)) x y).re + let S : V → V → ℝ := fun x y => if x ∈ O ∧ y ∈ O then K x y else 0 + have hK (x y : V) : 0 ≤ K x y := (hpos.pow (2*k) x y).2 + have hS (x y : V) : 0 ≤ S x y := by dsimp [S]; split_ifs; exact hK x y; exact le_rfl + have hSK (x y : V) : S x y ≤ K x y := by dsimp [S]; split_ifs; exact le_rfl; exact hK x y + have hsum (x : V) : HasSum (K x) 1 := walkPower_hasSum G hloc a P hpos hP (2*k) x + have hSsum (x : V) : Summable (S x) := Summable.of_nonneg_of_le (hS x) (hSK x) (hsum x).summable + have hrow (x : V) : ∑' y, S x y ≤ 1 := by + rw [←(hsum x).tsum_eq] + exact (hSsum x).tsum_le_tsum (hSK x) (hsum x).summable + have hτ (x y : V) (hxy : S x y ≠ 0) : (p:ℝ)^(2*k) ≤ twoPoint G p x y := by + apply twoPoint_reachBall_lower G p x (2*k) y + by_contra hn + have hz := walkPower_support G hloc a P hpos hP (2*k) x y hn + apply hxy + dsimp [S,K] + rw [hz] + split_ifs <;> rfl + have hO (x y : V) (hxy : S x y ≠ 0) : x ∈ O ∧ y ∈ O := by + by_contra ho + exact hxy (ite_eq_right ho) + have hcov (g : V ≃ V) (d : E ≃ E) (hg : IsAut G g d) (x y : V) : S (g x) (g y) = S x y := by + simp only [S,O,mem_vertexOrbit_aut_iff G (root i₀) hg,K, + walkPower_invariant G hloc a P hP (2*k) g ⟨d,hg⟩] + have hret : b ≤ ∑' y, S (root i₀) y := by + simpa only [b,S,K,ho,true_and,O] using + walkPower_even_orbit_return G hloc a root weight Γ hΓ htr hw hw1 i₀ hw₀ P hpos hsym hP k + obtain ⟨A,hAn,hA⟩ := exists_operator_of_matrix_domination K S hK + (fun x y => by rw [abs_of_nonneg (hS x y)]; exact hSK x y) (P^(2*k)) (hpos.pow (2*k)).real + have hc : 0 < (p:ℝ)^(2*k) := pow_pos hp _ + have hbad := cappedGoodness_failure_eventually_small G hloc hqt p hp1 (root i₀) hfin ε hε hε1 + ((p:ℝ)^(2*k)*b/2) (by positivity) + obtain ⟨M,hM,hMb⟩ := ((eventually_ge_atTop M₀).and hbad).exists + obtain ⟨q,hq,T,hTpos,hTn,hT⟩ := connectionAdjustedRule_operator G hloc (root i₀) p S + ((p:ℝ)^(2*k)) hc hS hSsum hrow hτ hO hcov M ((M:ℝ)^(1/2+ε)) b hb hret hMb A hA + refine ⟨M,hM,q,(by positivity : 0 < (p:ℝ)^(2*k)*b/2).trans_le hq,T,hTpos,?_,hT⟩ + apply lt_of_le_of_lt hTn + apply lt_of_le_of_lt _ hk2 + have hpow (j : ℕ) : ‖P^j‖ ≤ ‖P‖^j := by + induction j with + | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) + | succ j ih => + rw [pow_succ,pow_succ] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hAn.trans (hpow (2*k))) (by norm_num)) hb.le + +end StartingEndpointRule +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section NonamenableStartingMap +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Countable V] [Countable E] [Nonempty V] + + + +theorem nonamenable_starting_endpoint_rule (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (η : ℝ) (hη : 0 < η) (M₀ : ℕ) : + ∃ M ≥ M₀, ∃ q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M ((M:ℝ)^(1/2+ε)), + 0 < q.successProbability p (root i₀) ∧ + ∃ T : Hilbert V →L[ℂ] Hilbert V, 0 < ‖T‖ ∧ ‖T‖ < η ∧ + ∀ x y, matrixCoeff T x y = (q.normalizedKernel (root i₀) p x y : ℂ) := by + obtain ⟨D,P,hD,hdeg,hPn,hPs,hP⟩ := exists_strict_walk_operator G hloc hqt hh + have hDr : (0:ℝ) < D := Nat.cast_pos.mpr hD + have ha : 0 ≤ (1:ℝ)/(2*D) := by positivity + have haD : (1:ℝ)/(2*D)*D ≤ 1 := by + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity)).mpr + nlinarith + have hpos : PositiveRealMatrix P := by + intro x y + change (P (lp.single 2 y (1:ℂ)) x).im = 0 ∧ 0 ≤ (P (lp.single 2 y (1:ℂ)) x).re + rw [hP] + exact ⟨Complex.ofReal_im _,walkKernel_nonneg G hloc D hdeg _ ha haD x y⟩ + exact starting_endpoint_rule_of_walk G hloc hqt p hp hp1 root weight Γ hΓ htr hw hw1 i₀ hw₀ hfin + _ P hpos hPs.isSelfAdjoint hPn hP ε hε hε1 η hη M₀ + +end NonamenableStartingMap +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteOrbitPartition +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_partition_square_bound {α ι : Type*} [Fintype ι] + (C : Finset α) (color : α → ι) (q : α → ℝ) + (hq : ∀ x ∈ C, (∑ y ∈ C, if color y = color x then (1:ℝ) else 0) ≤ q x) : + (C.card:ℝ)^2 ≤ Fintype.card ι * ∑ x ∈ C, q x := by + let c : ι → ℝ := fun i => ∑ x ∈ C, if color x=i then 1 else 0 + have hsum : (∑ i, c i) = C.card := by + dsimp only [c] + rw [Finset.sum_comm] + simp + have hsq : (∑ i, c i^2) = ∑ x ∈ C, c (color x) := by + have he (i : ι) : c i^2 = ∑ x ∈ C, if color x=i then c i else 0 := by + rw [pow_two] + conv_lhs => lhs; change ∑ x ∈ C, if color x=i then (1:ℝ) else 0 + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro x hx + split_ifs <;> simp only [one_mul,zero_mul] + simp only [he] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x hx + simp + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : ι => (1:ℝ)) c + simp only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one,hsum,hsq] at h + exact h.trans (mul_le_mul_of_nonneg_left (Finset.sum_le_sum hq) (Nat.cast_nonneg _)) + +theorem vertexOrbit_eq_of_mem (G : BondGraph V E) (o x : V) (hx : x ∈ vertexOrbit G o) : + vertexOrbit G x = vertexOrbit G o := by + obtain ⟨a,b,hab,rfl⟩ := hx + ext y + constructor + · rintro ⟨c,d,hcd,hc⟩ + exact ⟨a.trans c,b.trans d,isAut_trans G hab hcd,hc⟩ + · rintro ⟨c,d,hcd,hc⟩ + exact ⟨a.symm.trans c,b.symm.trans d,isAut_trans G (isAut_symm G hab) hcd,by simpa using hc⟩ + + + +theorem finite_sameOrbit_pairs_lower (G : BondGraph V E) + {ι : Type*} [Fintype ι] (root : ι → V) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (C : Finset V) : + (C.card:ℝ)^2 ≤ Fintype.card ι * + ∑ x ∈ C, ∑ y ∈ C, if y ∈ vertexOrbit G x then (1:ℝ) else 0 := by + let color : V → ι := fun x => (hcover x).choose + have hc (x : V) : x ∈ vertexOrbit G (root (color x)) := (hcover x).choose_spec + apply finite_partition_square_bound C color + intro x hx + apply Finset.sum_le_sum + intro y hy + by_cases h : color y = color x + · have hm : y ∈ vertexOrbit G x := by + rw [vertexOrbit_eq_of_mem G (root (color x)) x (hc x)] + simpa only [h] using hc y + simp only [ite_eq_left h,ite_eq_left hm,le_refl] + · simp only [ite_eq_right h] + split_ifs <;> norm_num + +end FiniteOrbitPartition +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section BinOrbitRowMass +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binSizeMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : ℝ := + ∑' y, binConnectionMass G n ω x y + +noncomputable def binOrbitRowMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : ℝ := + ∑' y, if y ∈ vertexOrbit G x then binConnectionMass G n ω x y else 0 + +theorem binMass_eq_of_window (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (hb : ClusterWindow G x n (2*n) ω) : + binConnectionMass G n ω x y = if y ∈ cluster G ω x then 1 else 0 := by + simp only [binConnectionMass,hb.1,hb.2.1,hb.2.2,true_and] + rfl + +theorem binMass_zero_of_not_window (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (hb : ¬ ClusterWindow G x n (2*n) ω) : binConnectionMass G n ω x y = 0 := by + apply ite_eq_right + exact fun h => hb ⟨h.1,h.2.1,h.2.2.1⟩ + +theorem binSizeMass_eq (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) + (hb : ClusterWindow G x n (2*n) ω) : binSizeMass G n ω x = (cluster G ω x).ncard := by + unfold binSizeMass + simp only [binMass_eq_of_window G n ω x _ hb] + rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by simp only [Set.Finite.mem_toFinset] at hy; simp only [ite_eq_right hy])] + have he : (∑ y ∈ hb.1.toFinset, if y ∈ cluster G ω x then (1:ℝ) else 0) = ∑ _y ∈ hb.1.toFinset, (1:ℝ) := by + apply Finset.sum_congr rfl + intro y hy + exact ite_eq_left (hb.1.mem_toFinset.mp hy) + rw [he] + simp only [Finset.sum_const,nsmul_eq_mul,mul_one,←Set.ncard_eq_toFinset_card _ hb.1] + +theorem binOrbitRowMass_eq (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) + (hb : ClusterWindow G x n (2*n) ω) : + binOrbitRowMass G n ω x = ∑ y ∈ hb.1.toFinset, if y ∈ vertexOrbit G x then (1:ℝ) else 0 := by + unfold binOrbitRowMass + rw [tsum_eq_sum (s := hb.1.toFinset) (fun y hy => by + have hc : y ∉ cluster G ω x := fun h => hy (hb.1.mem_toFinset.mpr h) + rw [binMass_eq_of_window G n ω x y hb,ite_eq_right hc,ite_self])] + apply Finset.sum_congr rfl + intro y hy + rw [binMass_eq_of_window G n ω x y hb,ite_eq_left (hb.1.mem_toFinset.mp hy)] + +theorem binOrbitRowMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) : + 0 ≤ binOrbitRowMass G n ω x := by + apply tsum_nonneg + intro y + split_ifs + · exact binConnectionMass_nonneg G n ω x y + · exact le_rfl + +theorem binOrbitRowMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (ω : Set E) (x : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binOrbitRowMass G n ω x = binOrbitRowMass G n (ω ∩ (Q : Set E)) x := by + dsimp only [binOrbitRowMass] + apply tsum_congr + intro y + rw [binConnectionMass_local G hloc n ω x y] + +theorem binSizeMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (ω : Set E) (x : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + binSizeMass G n ω x = binSizeMass G n (ω ∩ (Q : Set E)) x := by + dsimp only [binSizeMass] + apply tsum_congr + intro y + exact binConnectionMass_local G hloc n ω x y + +theorem binOrbitRowMass_covariant (G : BondGraph V E) (n : ℕ) (ω : Set E) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : + binOrbitRowMass G n (b ⁻¹' ω) x = binOrbitRowMass G n ω (a x) := by + unfold binOrbitRowMass + rw [←a.tsum_eq (fun y => if y ∈ vertexOrbit G (a x) then binConnectionMass G n ω (a x) y else 0)] + have ho : vertexOrbit G (a x) = vertexOrbit G x := vertexOrbit_eq_of_mem G x (a x) ⟨a,b,hab,rfl⟩ + simp only [ho,mem_vertexOrbit_aut_iff G x hab,binConnectionMass_covariant G hab] + +theorem binSizeMass_covariant (G : BondGraph V E) (n : ℕ) (ω : Set E) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) : + binSizeMass G n (b ⁻¹' ω) x = binSizeMass G n ω (a x) := by + unfold binSizeMass + rw [←a.tsum_eq (fun y => binConnectionMass G n ω (a x) y)] + simp only [binConnectionMass_covariant G hab] + +end BinOrbitRowMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BinOrbitTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def binOrbitTransportMass (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : ℝ := + binConnectionMass G n ω x y * binOrbitRowMass G n ω y / binSizeMass G n ω x + +theorem binOrbitRowMass_zero (G : BondGraph V E) (n : ℕ) (ω : Set E) (x : V) + (hb : ¬ ClusterWindow G x n (2*n) ω) : binOrbitRowMass G n ω x = 0 := by + simp only [binOrbitRowMass,binMass_zero_of_not_window G n ω x _ hb,ite_self,tsum_zero] + +theorem binOrbitTransportMass_nonneg (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) : + 0 ≤ binOrbitTransportMass G n ω x y := by + exact div_nonneg (mul_nonneg (binConnectionMass_nonneg G n ω x y) (binOrbitRowMass_nonneg G n ω y)) + (tsum_nonneg (binConnectionMass_nonneg G n ω x)) + +theorem binOrbitTransportMass_column (G : BondGraph V E) (n : ℕ) (hn : 0 < n) + (ω : Set E) (y : V) : (∑' x, binOrbitTransportMass G n ω x y) = binOrbitRowMass G n ω y := by + by_cases hb : ClusterWindow G y n (2*n) ω + · have he (x : V) : binOrbitTransportMass G n ω x y = + binConnectionMass G n ω x y * (binOrbitRowMass G n ω y / binSizeMass G n ω y) := by + by_cases hz : binConnectionMass G n ω x y = 0 + · simp only [binOrbitTransportMass,hz,zero_mul,zero_div] + · obtain ⟨hf,hN,hc⟩ := binConnectionMass_support G n ω x y hz + have hset := cluster_eq_of_conn G ω hc + have hbx : ClusterWindow G x n (2*n) ω := by + unfold ClusterWindow at hb ⊢ + simpa only [hset] using hb + rw [binOrbitTransportMass,binSizeMass_eq G n ω x hbx,binSizeMass_eq G n ω y hb,hset] + exact mul_div_assoc _ _ _ + rw [show (∑' x, binOrbitTransportMass G n ω x y) = + ∑' x, binConnectionMass G n ω x y*(binOrbitRowMass G n ω y/binSizeMass G n ω y) from tsum_congr he, + tsum_mul_right] + have hcol : (∑' x, binConnectionMass G n ω x y) = binSizeMass G n ω y := by + simp only [binConnectionMass_symm G n ω,binSizeMass] + rw [hcol] + have hs : binSizeMass G n ω y ≠ 0 := by + rw [binSizeMass_eq G n ω y hb] + exact Nat.cast_ne_zero.mpr (Nat.ne_of_gt (hn.trans_le hb.2.1)) + exact mul_div_cancel₀ _ hs + · have he : ∀ x, binOrbitTransportMass G n ω x y = 0 := by + intro x + simp only [binOrbitTransportMass,binOrbitRowMass_zero G n ω y hb,mul_zero,zero_div] + simp only [he,tsum_zero,binOrbitRowMass_zero G n ω y hb] + +theorem binOrbitTransportMass_row (G : BondGraph V E) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (n : ℕ) (hn : 0 < n) (ω : Set E) (x : V) : + (if ClusterWindow G x n (2*n) ω then (n:ℝ)/Fintype.card ι else 0) ≤ + ∑' y, binOrbitTransportMass G n ω x y := by + by_cases hb : ClusterWindow G x n (2*n) ω + · rw [ite_eq_left hb] + let C := hb.1.toFinset + have hs : (0:ℝ) < (cluster G ω x).ncard := Nat.cast_pos.mpr (hn.trans_le hb.2.1) + have ht : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hqy (y : V) (hy : y ∈ C) : binOrbitRowMass G n ω y = + ∑ z ∈ C, if z ∈ vertexOrbit G y then (1:ℝ) else 0 := by + have hc : Conn G ω x y := hb.1.mem_toFinset.mp hy + have he := cluster_eq_of_conn G ω hc + have hby : ClusterWindow G y n (2*n) ω := by + unfold ClusterWindow at hb ⊢ + simpa only [←he] using hb + rw [binOrbitRowMass_eq G n ω y hby] + have hC : hby.1.toFinset = C := by + apply Finset.coe_injective + simpa only [C,Set.Finite.coe_toFinset] using he.symm + rw [hC] + have he : (∑' y, binOrbitTransportMass G n ω x y) = + (∑ y ∈ C, ∑ z ∈ C, if z ∈ vertexOrbit G y then (1:ℝ) else 0)/(cluster G ω x).ncard := by + rw [tsum_eq_sum (s := C) (fun y hy => by + have hc : y ∉ cluster G ω x := fun h => hy (hb.1.mem_toFinset.mpr h) + simp only [binOrbitTransportMass,binMass_eq_of_window G n ω x y hb,ite_eq_right hc,zero_mul,zero_div])] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro y hy + simp only [binOrbitTransportMass,binMass_eq_of_window G n ω x y hb, + ite_eq_left (hb.1.mem_toFinset.mp hy),one_mul,binSizeMass_eq G n ω x hb,hqy y hy] + rw [he] + apply (div_le_div_iff₀ ht hs).mpr + have h := finite_sameOrbit_pairs_lower G root hcover C + have hC : (C.card:ℝ) = (cluster G ω x).ncard := by + exact_mod_cast (Set.ncard_eq_toFinset_card _ hb.1).symm + rw [hC] at h + have hn' : (n:ℝ) ≤ (cluster G ω x).ncard := by exact_mod_cast hb.2.1 + nlinarith [mul_le_mul_of_nonneg_right hn' hs.le] + · rw [ite_eq_right hb] + exact tsum_nonneg (binOrbitTransportMass_nonneg G n ω x) + +end BinOrbitTransport + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/ContactTrace.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/ContactTrace.lean index a558686dd94a2380f077e07046e38e09da33cbc8..0290a085308329d3e44259e9176f4481b758376a 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/ContactTrace.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/ContactTrace.lean @@ -1,1240 +1,1240 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts - -namespace OAI - -/-! Contact Trace for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section IndexedEdgeKernel -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem enn_ncard_eq_tsum {α : Type*} (A : Set α) (hA : A.Finite) : - (A.ncard:ℝ≥0∞) = ∑' a, if a ∈ A then (1:ℝ≥0∞) else 0 := by - rw [tsum_eq_sum (s := hA.toFinset) (fun a ha => by - simp only [Set.Finite.mem_toFinset] at ha - exact ite_eq_right ha)] - simp only [Set.ncard_eq_toFinset_card A hA] - rw [Finset.sum_congr rfl (fun a ha => ite_eq_left ((Set.Finite.mem_toFinset _).mp ha))] - simp - - - -noncomputable def indexedEdgeKernel (G : BondGraph V E) (x y : V) : ℝ≥0∞ := - ∑' e, if G e = s(x,y) then 1 else 0 - -theorem indexedEdgeKernel_eq_ncard (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : - indexedEdgeKernel G x y = ({e | G e = s(x,y)}.ncard:ℝ≥0∞) := by - have hf : ({e | G e = s(x,y)} : Set E).Finite := (hloc x).subset (fun e he => by change x ∈ G e; change G e = s(x,y) at he; rw [he]; simp) - unfold indexedEdgeKernel - convert (enn_ncard_eq_tsum _ hf).symm using 1 - apply tsum_congr - intro e - by_cases h : G e = s(x,y) <;> simp only [Set.mem_ofPred_eq,h,ite_true,ite_false] - -theorem indexedEdgeKernel_symm (G : BondGraph V E) (x y : V) : - indexedEdgeKernel G x y = indexedEdgeKernel G y x := by rw [indexedEdgeKernel,indexedEdgeKernel,Sym2.eq_swap] - -theorem indexedEdgeKernel_row (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - (∑' y, indexedEdgeKernel G x y) = (degree G x:ℝ≥0∞) := by - change (∑' y, ∑' e, if G e = s(x,y) then (1:ℝ≥0∞) else 0) = _ - rw [ENNReal.tsum_comm,←ENNReal.tsum_prod] - have hn := (enn_ncard_eq_tsum _ (finite_steps G hloc x)).symm - have he : (∑' (p : E × V), if G p.1 = s(x,p.2) then (1:ℝ≥0∞) else 0) = - (({ey : E × V | G ey.1 = s(x,ey.2)} : Set (E × V)).ncard:ℝ≥0∞) := by - convert hn using 1 - apply tsum_congr - intro ey - by_cases h : G ey.1 = s(x,ey.2) <;> simp only [Set.mem_ofPred_eq,h,ite_true,ite_false] - rw [he] - change (({ey : E × V | G ey.1 = s(x,ey.2)} : Set (E × V)).ncard:ℝ≥0∞) = (Nat.card (Step G x):ℝ≥0∞) - rw [←Nat.card_coe_set_eq]; rfl - -theorem indexedEdgeKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x y : V) : - indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by - unfold indexedEdgeKernel - rw [←b.tsum_eq (fun e => if G e = s(a x,a y) then (1:ℝ≥0∞) else 0)] - apply tsum_congr - intro e - have he : G (b e) = s(a x,a y) ↔ G e = s(x,y) := by - rw [hab e,←Sym2.map_mk] - exact (Sym2.map.injective a.injective).eq_iff - simp only [he] - -end IndexedEdgeKernel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ContactKernelCounting -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem contact_endpoints_unique (G : BondGraph V E) (ω : Set E) (x y : V) - (hd : ¬Conn G ω x y) {e : E} {a b c d : V} - (ha : Conn G ω x a) (_hb : Conn G ω y b) - (_hc : Conn G ω x c) (he : Conn G ω y d) - (hab : G e = s(a,b)) (hcd : G e = s(c,d)) : a = c ∧ b = d := by - rcases Sym2.eq_iff.mp (hab.symm.trans hcd) with h | h - · exact h - · exfalso - apply hd - exact conn_trans G ω ha (by simpa only [h.1] using conn_symm G ω he) - -theorem closedContactSet_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (A B : Set V) (hA : A.Finite) : (closedContactSet G A B).Finite := by - have hs := contactSet_subset_incident G hloc hA.toFinset B - rw [Set.Finite.coe_toFinset] at hs - exact (incidentSupport G hloc hA.toFinset).finite_toSet.subset hs - -theorem clusterPairKernel_edge (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x y : V) (hd : ¬Conn G ω x y) (hx : (cluster G ω x).Finite) : - clusterPairKernel G ω (indexedEdgeKernel G) x y = (clusterContactCount G ω x y:ℝ≥0∞) := by - have hed (e : E) : - (∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0) = - if e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) then 1 else 0 := by - by_cases h : e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) - · obtain ⟨a,ha,b,hb,hab⟩ := h - change Conn G ω x a at ha - change Conn G ω y b at hb - have hh : e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) := ⟨a,ha,b,hb,hab⟩ - rw [ite_eq_left hh,tsum_eq_single a] - · rw [tsum_eq_single b] - · exact ite_eq_left ⟨ha,hb,hab⟩ - · intro d hdb - apply ite_eq_right - intro hc - exact hdb (contact_endpoints_unique G ω x y hd hc.1 hc.2.1 ha hb hc.2.2 hab).2 - · intro c hca - apply ENNReal.tsum_eq_zero.mpr - intro d - apply ite_eq_right - intro hc - exact hca (contact_endpoints_unique G ω x y hd hc.1 hc.2.1 ha hb hc.2.2 hab).1 - · rw [ite_eq_right h] - apply ENNReal.tsum_eq_zero.mpr - intro a - apply ENNReal.tsum_eq_zero.mpr - intro b - apply ite_eq_right - intro hab - exact h ⟨a,hab.1,b,hab.2.1,hab.2.2⟩ - have he (a b : V) : (if Conn G ω x a ∧ Conn G ω y b then indexedEdgeKernel G a b else 0) = - ∑' e, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by - by_cases ha : Conn G ω x a <;> by_cases hb : Conn G ω y b <;> - simp only [ha,hb,and_self,true_and,false_and,ite_true,ite_false,indexedEdgeKernel,tsum_zero] - rw [clusterPairKernel] - simp_rw [he] - calc - _ = ∑' e, ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by - calc - _ = ∑' a, ∑' e, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by - apply tsum_congr; intro a; exact ENNReal.tsum_comm - _ = _ := ENNReal.tsum_comm - _ = ∑' e, if e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) then (1:ℝ≥0∞) else 0 := tsum_congr hed - _ = _ := (enn_ncard_eq_tsum _ (closedContactSet_finite G hloc _ _ hx)).symm - -end ContactKernelCounting -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ContactCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem closedContactSet_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (A B : Set V) : - b '' closedContactSet G A B = closedContactSet G (a '' A) (a '' B) := by - ext e - constructor - · rintro ⟨f,⟨x,hx,y,hy,hf⟩,rfl⟩ - exact ⟨a x,Set.mem_image_of_mem a hx,a y,Set.mem_image_of_mem a hy,by rw [hab f,hf,Sym2.map_mk]⟩ - · rintro ⟨z,⟨x,hx,rfl⟩,w,⟨y,hy,rfl⟩,he⟩ - refine ⟨b.symm e,⟨x,hx,y,hy,?_⟩,b.apply_symm_apply e⟩ - apply Sym2.map.injective a.injective - rw [←hab,Sym2.map_mk] - simpa only [Equiv.apply_symm_apply] using he - -theorem clusterContactCount_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) : - clusterContactCount G (b ⁻¹' ω) x y = clusterContactCount G ω (a x) (a y) := by - unfold clusterContactCount - rw [←cluster_aut G hab ω x,←cluster_aut G hab ω y,←closedContactSet_aut G hab, - Set.ncard_image_of_injective _ b.injective] - -theorem fullLargeContact_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) (L : ℕ) : - fullLargeContact G x y L (b ⁻¹' ω) = fullLargeContact G (a x) (a y) L ω := by - simp only [fullLargeContact,conn_aut_iff G hab,cluster_ncard_covariant G hab,clusterContactCount_aut G hab] - -theorem fullLargeContact_cluster_constant (G : BondGraph V E) (ω : Set E) - (L : ℕ) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : - fullLargeContact G x y L ω = fullLargeContact G a b L ω := by - have hc : Conn G ω x y ↔ Conn G ω a b := by - constructor - · intro h; exact conn_trans G ω (conn_symm G ω hxa) (conn_trans G ω h hyb) - · intro h; exact conn_trans G ω hxa (conn_trans G ω h (conn_symm G ω hyb)) - simp only [fullLargeContact,clusterContactCount,cluster_eq_of_conn G ω hxa, - cluster_eq_of_conn G ω hyb,hc] - -theorem fullLargeContact_distinct (G : BondGraph V E) (ω : Set E) (x y : V) (L : ℕ) : - (if ¬Conn G ω x y then ENNReal.ofReal (fullLargeContact G x y L ω) else 0) = - ENNReal.ofReal (fullLargeContact G x y L ω) := by - by_cases h : Conn G ω x y - · simp only [fullLargeContact,h,not_true_eq_false,false_and,ite_false,ENNReal.ofReal_zero] - · exact ite_eq_left h - -end ContactCovariance -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ContactSquareTrace -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def contactSquareLarge (G : BondGraph V E) (L : ℕ) - (ω : Set E) (x y : V) : ℝ≥0∞ := - if L ≤ min (cluster G ω x).ncard (cluster G ω y).ncard then - (clusterContactCount G ω x y:ℝ≥0∞)^2 else 0 - -theorem contactSquareLarge_reroot [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) (L : ℕ) : - clusterPairFunctional G p root weight (contactSquareLarge G L) = - ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, - indexedEdgeKernel G (root i) y * ENNReal.ofReal (fullLargeContact G (root i) y L ω) ∂law p := by - have hj : ∀ a ∈ Γ, ∀ x y, indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by - intro a ha x y - obtain ⟨b,hab⟩ := hΓ ha - exact indexedEdgeKernel_aut G hab x y - have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin - (indexedEdgeKernel G) hj (fun ω x y => ENNReal.ofReal (fullLargeContact G x y L ω)) - (fun x y => (measurable_fullLargeContact G hloc x y L).ennreal_ofReal) - (fun ω x y a b hxa hyb => congrArg ENNReal.ofReal (fullLargeContact_cluster_constant G ω L x y a b hxa hyb)) - (fun a _ b hab ω x y => congrArg ENNReal.ofReal (fullLargeContact_aut G hab ω x y L)) - simp_rw [fullLargeContact_distinct] at ht - rw [←ht] - unfold clusterPairFunctional - apply Finset.sum_congr rfl - intro i _ - congr 1 - apply lintegral_congr_ae - filter_upwards [hfin (root i)] with ω hω - unfold clusterPairDensity - congr 1 - apply tsum_congr - intro y - congr 1 - by_cases hd : Conn G ω (root i) y - · simp only [hd,not_true_eq_false,ite_false] - · rw [ite_eq_left hd,ite_eq_left hd] - dsimp only - rw [clusterPairKernel_edge G hloc ω (root i) y hd hω] - unfold contactSquareLarge fullLargeContact - by_cases hs : L ≤ min (cluster G ω (root i)).ncard (cluster G ω y).ncard - · simp only [hd,hs,not_false_eq_true,true_and,ite_true,ENNReal.ofReal_natCast,pow_two] - · simp only [hs,and_false,ite_false,ENNReal.ofReal_zero,mul_zero] - -theorem contactSquareLarge_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) (L d : ℕ) - (hd : ∀ x, degree G x ≤ d) (B : ℝ) (_hB : 0 ≤ B) - (hI : ∀ x y, Integrable (fullLargeContact G x y L) (law p)) - (hb : ∀ x y, (∫ ω, fullLargeContact G x y L ω ∂law p) ≤ B) : - clusterPairFunctional G p root weight (contactSquareLarge G L) ≤ ENNReal.ofReal ((d:ℝ)*B) := by - have hi (x y : V) : (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y L ω) ∂law p) ≤ ENNReal.ofReal B := by - rw [←ofReal_integral_eq_lintegral_ofReal (hI x y) (Filter.Eventually.of_forall (fullLargeContact_nonneg G x y L))] - exact ENNReal.ofReal_le_ofReal (hb x y) - have hr (x : V) : (∫⁻ ω, ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal (fullLargeContact G x y L ω) ∂law p) ≤ - ENNReal.ofReal ((d:ℝ)*B) := by - have hm (y : V) : Measurable (fun ω => indexedEdgeKernel G x y * ENNReal.ofReal (fullLargeContact G x y L ω)) := - (measurable_const : Measurable (fun _ : Set E => indexedEdgeKernel G x y)).mul (measurable_fullLargeContact G hloc x y L).ennreal_ofReal - rw [lintegral_tsum (fun y => (hm y).aemeasurable)] - simp_rw [lintegral_const_mul _ (measurable_fullLargeContact G hloc x _ L).ennreal_ofReal] - calc - _ ≤ ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal B := ENNReal.tsum_le_tsum (fun y => mul_le_mul_right (hi x y) _) - _ = (degree G x:ℝ≥0∞)*ENNReal.ofReal B := by rw [ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc x] - _ ≤ (d:ℝ≥0∞)*ENNReal.ofReal B := mul_le_mul_left (by exact_mod_cast hd x) _ - _ = _ := by rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_natCast] - rw [contactSquareLarge_reroot G hconn hloc root weight Γ hΓ htr hw p hfin L] - calc - _ ≤ ∑ i, ENNReal.ofReal (weight i)*ENNReal.ofReal ((d:ℝ)*B) := - Finset.sum_le_sum (fun i _ => mul_le_mul_right (hr (root i)) _) - _ = _ := by rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1,ENNReal.ofReal_one,one_mul] - -end ContactSquareTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section CriticalContactSquare -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_contact_square_bound_nat - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → - ∀ L : ℕ, 1 ≤ L → clusterPairFunctional G p root weight (contactSquareLarge G L) ≤ - ENNReal.ofReal (C*(L:ℝ)^((1:ℝ)/2+ε-2*α)) := by - obtain ⟨A,hA,hb⟩ := critical_large_contact_bound G hloc hconn hqt hh root weight Γ hΓ htr - hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt - refine ⟨(d:ℝ)*A,mul_pos (by exact_mod_cast hd) hA,?_⟩ - intro p hp hpq L hL - have hf : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by - intro x - obtain ⟨i,a,ha,rfl⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact cluster_finite_ae_mono G (a (root i)) p (pc G) hpq - (cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i)) - have h := contactSquareLarge_bound G hconn hloc root weight Γ hΓ htr (fun i => (hw i).le) hw1 p hf - L d hdeg (A*(L:ℝ)^((1:ℝ)/2+ε-2*α)) (mul_nonneg hA.le (Real.rpow_nonneg (by positivity) _)) - (fun x y => (hb x y p hp hpq L hL).1) (fun x y => (hb x y p hp hpq L hL).2) - simpa only [mul_assoc] using h - -end CriticalContactSquare -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section DistinctClusterBK -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem distinct_cluster_disjoint_occurrence (G : BondGraph V E) (ω : Set E) - (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) (hd : ¬Conn G ω x y) : - ω ∈ DisjointOccurrence {η | Conn G η x a} {η | Conn G η y b} := by - obtain ⟨s,hs,hsa⟩ := finiteWitness_conn G x a _ (conn_restrict_cluster G ω x (mem_cluster_self G ω x) hxa) - obtain ⟨t,ht,htb⟩ := finiteWitness_conn G y b _ (conn_restrict_cluster_compl G ω x hd hyb) - refine ⟨s,t,fun e he => (hs he).1,fun e he => (ht he).1,?_,hsa,htb⟩ - apply Finset.disjoint_left.mpr - intro e he ht' - obtain ⟨⟨z,w⟩,hr⟩ := Quot.exists_rep (G e) - have hz : z ∈ G e := by rw [←hr]; exact Sym2.mem_mk_left z w - exact (ht ht').2 z hz ((hs he).2 z hz) - -theorem distinct_cluster_two_point_bound [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y a b : V) : - law p {ω | Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y} ≤ - law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b} := by - calc - _ ≤ law p (DisjointOccurrence {ω | Conn G ω x a} {ω | Conn G ω y b}) := - measure_mono (fun ω h => distinct_cluster_disjoint_occurrence G ω x y a b h.1 h.2.1 h.2.2) - _ ≤ _ := bk_ennreal p _ _ (fun _ _ h hc => conn_mono G h hc) - (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x a) (finiteWitness_conn G y b) - -theorem measurable_clusterPairKernel [Countable V] [Countable E] - (G : BondGraph V E) (J : V → V → ℝ≥0∞) (x y : V) : - Measurable (fun ω => clusterPairKernel G ω J x y) := by - apply Measurable.tsum - intro a - apply Measurable.tsum - intro b - exact measurable_const.ite ((measurableSet_conn G x a).inter (measurableSet_conn G y b)) measurable_const - -theorem clusterPairKernel_cluster_constant (G : BondGraph V E) (ω : Set E) - (J : V → V → ℝ≥0∞) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : - clusterPairKernel G ω J x y = clusterPairKernel G ω J a b := by - have hx (z : V) : Conn G ω x z ↔ Conn G ω a z := - ⟨fun h => conn_trans G ω (conn_symm G ω hxa) h,fun h => conn_trans G ω hxa h⟩ - have hy (z : V) : Conn G ω y z ↔ Conn G ω b z := - ⟨fun h => conn_trans G ω (conn_symm G ω hyb) h,fun h => conn_trans G ω hyb h⟩ - simp only [clusterPairKernel,hx,hy] - -theorem clusterPairKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J (a x) (a y) = J x y) - (ω : Set E) (x y : V) : - clusterPairKernel G (b ⁻¹' ω) J x y = clusterPairKernel G ω J (a x) (a y) := by - unfold clusterPairKernel - rw [←a.tsum_eq (fun x' => ∑' y', if Conn G ω (a x) x' ∧ Conn G ω (a y) y' then J x' y' else 0)] - apply tsum_congr - intro x' - rw [←a.tsum_eq (fun y' => if Conn G ω (a x) (a x') ∧ Conn G ω (a y) y' then J (a x') y' else 0)] - simp only [hJ,conn_aut_iff G hab] - -end DistinctClusterBK -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PairSquareDiagram -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem clusterPairKernel_distinct_integral [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (J : V → V → ℝ≥0∞) (x y : V) : - (∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 ∂law p) = - ∑' a, ∑' b, J a b * law p {ω | Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y} := by - have he (ω : Set E) : (if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0) = - ∑' a, ∑' b, J a b * (if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0) := by - by_cases hd : Conn G ω x y - · simp only [hd,not_true_eq_false,and_false,ite_false,mul_zero,tsum_zero] - · rw [ite_eq_left hd,clusterPairKernel] - apply tsum_congr; intro a - apply tsum_congr; intro b - by_cases h : Conn G ω x a ∧ Conn G ω y b - · simp only [h.1,h.2,hd,not_false_eq_true,and_self,ite_true,mul_one] - · have hn : ¬ (Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y) := fun h' => h ⟨h'.1,h'.2.1⟩ - simp only [ite_eq_right h,ite_eq_right hn,mul_zero] - have hm (a b : V) : Measurable (fun ω => if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0) := - measurable_const.ite ((measurableSet_conn G x a).inter ((measurableSet_conn G y b).inter (measurableSet_conn G x y).compl)) measurable_const - have hm' (a b : V) : Measurable (fun ω : Set E => J a b * (if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0)) := - (measurable_const : Measurable (fun _ : Set E => J a b)).mul (hm a b) - simp_rw [he] - rw [lintegral_tsum (fun a => (Measurable.tsum (fun b => hm' a b)).aemeasurable)] - apply tsum_congr; intro a - rw [lintegral_tsum (fun b => (hm' a b).aemeasurable)] - apply tsum_congr; intro b - rw [lintegral_const_mul _ (hm a b)] - congr 1 - convert - (lintegral_indicator_one (μ := law p) ((measurableSet_conn G x a).inter ((measurableSet_conn G y b).inter (measurableSet_conn G x y).compl))) using 1 - · apply lintegral_congr - intro ω - simp only [Set.indicator,Set.mem_inter_iff,Set.mem_compl_iff,Set.mem_ofPred_eq,Pi.one_apply] - · congr 1 - -theorem clusterPairKernel_distinct_bound [Countable V] [Countable E] - (G : BondGraph V E) (p : unitInterval) (J : V → V → ℝ≥0∞) (x y : V) : - (∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 ∂law p) ≤ - ∑' a, ∑' b, J a b * (law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b}) := by - rw [clusterPairKernel_distinct_integral] - exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => - mul_le_mul_right (distinct_cluster_two_point_bound G p x y a b) _)) - - - -theorem clusterPairFunctional_square_diagram [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) : - clusterPairFunctional G p root weight (fun ω x y => (clusterPairKernel G ω J x y)^2) ≤ - ∑ i, ENNReal.ofReal (weight i) * ∑' v, ∑' a, ∑' b, - J (root i) v * (J a b * (law p {ω | Conn G ω (root i) a} * law p {ω | Conn G ω v b})) := by - have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin J hJ - (fun ω x y => clusterPairKernel G ω J x y) (measurable_clusterPairKernel G J) - (fun ω x y a b => clusterPairKernel_cluster_constant G ω J x y a b) - (fun a ha b hab ω x y => clusterPairKernel_aut G hab J (hJ a ha) ω x y) - simp only [←pow_two] at ht - rw [ht] - apply Finset.sum_le_sum - intro i _ - apply mul_le_mul_right - have hm (v : V) : Measurable (fun ω : Set E => if ¬Conn G ω (root i) v then clusterPairKernel G ω J (root i) v else 0) := - (measurable_clusterPairKernel G J (root i) v).ite (measurableSet_conn G (root i) v).compl measurable_const - have hm' (v : V) : Measurable (fun ω : Set E => J (root i) v * (if ¬Conn G ω (root i) v then clusterPairKernel G ω J (root i) v else 0)) := - (measurable_const : Measurable (fun _ : Set E => J (root i) v)).mul (hm v) - rw [lintegral_tsum (fun v => (hm' v).aemeasurable)] - apply ENNReal.tsum_le_tsum - intro v - rw [lintegral_const_mul _ (hm v)] - simp_rw [ENNReal.tsum_mul_left] - exact mul_le_mul_right (clusterPairKernel_distinct_bound G p J (root i) v) _ - -end PairSquareDiagram -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ContactRealCutoff -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def contactSquareLargeReal (G : BondGraph V E) (L : ℝ) - (ω : Set E) (x y : V) : ℝ≥0∞ := - if L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) then - (clusterContactCount G ω x y:ℝ≥0∞)^2 else 0 - -theorem contactSquareLargeReal_eq_ceil (G : BondGraph V E) (L : ℝ) - (ω : Set E) (x y : V) : - contactSquareLargeReal G L ω x y = contactSquareLarge G ⌈L⌉₊ ω x y := by - have he : L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) ↔ - ⌈L⌉₊ ≤ min (cluster G ω x).ncard (cluster G ω y).ncard := by - rw [←Nat.cast_min, Nat.ceil_le] - simp only [contactSquareLargeReal,contactSquareLarge,he] - - - -theorem critical_contact_square_bound - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → - ∀ L : ℝ, 1 ≤ L → clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ - ENNReal.ofReal (C*L^((1:ℝ)/2+ε-2*α)) := by - obtain ⟨C,hC,hb⟩ := critical_contact_square_bound_nat G hloc hconn hqt hh root weight Γ hΓ htr - hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - refine ⟨C,hC,?_⟩ - intro p hp hpq L hL - have hLn : 1 ≤ ⌈L⌉₊ := by - have hc : (1:ℝ) ≤ (⌈L⌉₊:ℝ) := hL.trans (Nat.le_ceil L) - exact_mod_cast hc - have hEq : contactSquareLargeReal G L = contactSquareLarge G ⌈L⌉₊ := funext fun ω => funext fun x => funext fun y => contactSquareLargeReal_eq_ceil G L ω x y - rw [hEq] - exact (hb p hp hpq _ hLn).trans (ENNReal.ofReal_le_ofReal - (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_nonpos (by linarith : 0 < L) (Nat.le_ceil L) hr.le) hC.le)) - -end ContactRealCutoff -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section NonnegativeOperatorDiagram -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def ennMatrixCoeff (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : ℝ≥0∞ := - ENNReal.ofReal (matrixCoeff A x y).re - -theorem ennMatrixCoeff_mul {A B : Hilbert V →L[ℂ] Hilbert V} - (hA : PositiveRealMatrix A) (hB : PositiveRealMatrix B) (x y : V) : - ennMatrixCoeff (A*B) x y = ∑' z, ennMatrixCoeff A x z * ennMatrixCoeff B z y := by - unfold ennMatrixCoeff - rw [←(hA.mul_hasSum B x y).tsum_eq, ENNReal.ofReal_tsum_of_nonneg - (fun z => mul_nonneg (hA x z).2 (hB z y).2) (hA.mul_hasSum B x y).summable] - apply tsum_congr; intro z - exact ENNReal.ofReal_mul (hA x z).2 - -theorem ennMatrixCoeff_symm {A : Hilbert V →L[ℂ] Hilbert V} - (hA : IsSelfAdjoint A) (x y : V) : ennMatrixCoeff A x y = ennMatrixCoeff A y x := by - unfold ennMatrixCoeff - rw [matrixCoeff_real_symm A hA x y] - -theorem HasKernel.ennMatrixCoeff [Countable E] (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : - ennMatrixCoeff T x y = law p {ω | Conn G ω x y} := by - unfold Percolation.ennMatrixCoeff matrixCoeff - rw [hT x y] - simp only [Complex.ofReal_re,twoPoint,ENNReal.ofReal_toReal (measure_ne_top _ _)] - -theorem HasKernel.positiveRealMatrix (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : PositiveRealMatrix T := by - intro x y - change (T (lp.single 2 y (1:ℂ)) x).im = 0 ∧ 0 ≤ (T (lp.single 2 y (1:ℂ)) x).re - rw [hT x y] - exact ⟨rfl,twoPoint_nonneg G p x y⟩ - -theorem square_kernel_diagram (J T : Hilbert V →L[ℂ] Hilbert V) - (hJ : PositiveRealMatrix J) (hT : PositiveRealMatrix T) - (hsJ : IsSelfAdjoint J) (hsT : IsSelfAdjoint T) (x : V) : - (∑' v, ∑' a, ∑' b, ennMatrixCoeff J x v * (ennMatrixCoeff J a b * - (ennMatrixCoeff T x a * ennMatrixCoeff T v b))) = ennMatrixCoeff (J*T*J*T) x x := by - rw [mul_assoc,mul_assoc,ennMatrixCoeff_mul hJ (hT.mul (hJ.mul hT))] - apply tsum_congr; intro v - rw [ennMatrixCoeff_mul hT (hJ.mul hT)] - simp_rw [ennMatrixCoeff_mul hJ hT] - simp_rw [←ENNReal.tsum_mul_left] - rw [ENNReal.tsum_comm] - apply tsum_congr; intro b - apply tsum_congr; intro a - rw [ennMatrixCoeff_symm hsJ b a,ennMatrixCoeff_symm hsT a x] - ac_rfl - -theorem enn_rootTrace {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) : - (∑ i, ENNReal.ofReal (weight i) * ennMatrixCoeff A (root i) (root i)) = - ENNReal.ofReal (rootTrace root weight A).re := by - unfold rootTrace ennMatrixCoeff - simp only [Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] - rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) (hA _ _).2)] - apply Finset.sum_congr rfl; intro i _ - exact (ENNReal.ofReal_mul (hw i)).symm - -end NonnegativeOperatorDiagram -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal ComplexOrder -section KernelSquareTrace -attribute [local instance] Classical.propDecidable Classical.decEq -attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass -local instance : NonUnitalContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -local instance : ContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) - -theorem rootTrace_six_le_cube {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) {Γ : Set (V ≃ V)} - (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : KernelInvariant Γ T) (hpos : 0 ≤ T) : - (rootTrace root weight (T^6)).re ≤ ‖T‖^3*(rootTrace root weight (T^3)).re := by - have hp3 : 0 ≤ T^3 := CStarAlgebra.pow_nonneg T 3 hpos - have h := rootTrace_positive_mul_le root weight htr hw (T^3) (T^3) - (hT.pow 3) (hT.pow 3) hp3 (IsSelfAdjoint.of_nonneg hp3) - have he : T^3*T^3 = T^6 := by rw [←pow_add] - rw [he] at h - have hr := (Complex.le_def.mp h).1 - simp only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] at hr - exact hr.trans (mul_le_mul_of_nonneg_right (norm_pow_le' T (by norm_num : 0 < (3:ℕ))) - (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw (T^3) hp3)).1) - - - -theorem clusterPairFunctional_twoPoint_square_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : - clusterPairFunctional G p root weight (fun ω x y => - (clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)^2) ≤ - ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re) := by - have hp := hT.positiveRealMatrix G p T - have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) - have hsa := IsSelfAdjoint.of_nonneg hpos - have hI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - have hJ : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff (T^2) (a x) (a y) = ennMatrixCoeff (T^2) x y := by - intro a ha x y - unfold ennMatrixCoeff - rw [(hI.pow 2) a ha] - have hb := clusterPairFunctional_square_diagram G hconn hloc root weight Γ hΓ htr hw p hfin - (ennMatrixCoeff (T^2)) hJ - have hd (x : V) : (∑' v, ∑' a, ∑' b, ennMatrixCoeff (T^2) x v * (ennMatrixCoeff (T^2) a b * - (law p {ω | Conn G ω x a} * law p {ω | Conn G ω v b}))) = ennMatrixCoeff (T^6) x x := by - simp_rw [←hT.ennMatrixCoeff G p T] - rw [square_kernel_diagram (T^2) T (hp.pow 2) hp (hsa.pow 2) hsa] - congr 1 - simp_rw [hd] at hb - rw [enn_rootTrace root weight hw (T^6) (hp.pow 6)] at hb - exact hb.trans (ENNReal.ofReal_le_ofReal (rootTrace_six_le_cube root weight htr hw T hI hpos)) - -end KernelSquareTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteClusterKernel -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteClusterWeight (G : BondGraph V E) (f : V → ℝ) - (x : V) (ω : Finset E) : ℝ := ∑ y ∈ finiteRootComponent G ω x, f y - -theorem finiteClusterWeight_expand (G : BondGraph V E) (f : V → ℝ) - (Q ω : Finset E) (hω : ω ⊆ Q) (x : V) : - finiteClusterWeight G f x ω = ∑ y ∈ insert x (searchVertices G Q), - f y * (if Conn G (ω:Set E) x y then (1:ℝ) else 0) := by - unfold finiteClusterWeight - calc - _ = ∑ y ∈ finiteRootComponent G ω x, f y * (if Conn G (ω:Set E) x y then (1:ℝ) else 0) := by - apply Finset.sum_congr rfl - intro y hy - have hc : Conn G (ω:Set E) x y := by - change y ∈ (finiteRootComponent G ω x:Set V) at hy - rwa [coe_finiteRootComponent] at hy - rw [ite_eq_left hc,mul_one] - _ = _ := Finset.sum_subset (finiteRootComponent_subset G Q _ x ω hω (by rfl)) (by - intro y _ hy - have hn : ¬Conn G (ω:Set E) x y := by - intro h - apply hy - change y ∈ (finiteRootComponent G ω x:Set V) - rwa [coe_finiteRootComponent] - rw [ite_eq_right hn,mul_zero]) - -theorem finiteClusterWeight_expectation_le [Countable E] - (G : BondGraph V E) (Q : Finset E) (f : V → ℝ) (hf : ∀ y, 0 ≤ f y) - (x : V) (p : unitInterval) (hs : Summable (fun y => f y*twoPoint G p x y)) : - bernoulliPolynomial Q (finiteClusterWeight G f x) p ≤ ∑' y, f y*twoPoint G p x y := by - have he : bernoulliPolynomial Q (finiteClusterWeight G f x) p = - bernoulliPolynomial Q (fun ω => ∑ y ∈ insert x (searchVertices G Q), f y*(if Conn G (ω:Set E) x y then (1:ℝ) else 0)) p := by - apply bernoulliPolynomial_congr - intro ω hω - exact finiteClusterWeight_expand G f Q ω hω x - rw [he,bernoulliPolynomial_sum] - calc - _ ≤ ∑ y ∈ insert x (searchVertices G Q), f y*twoPoint G p x y := by - apply Finset.sum_le_sum - intro y _ - have hpQ : bernoulliPolynomial Q (fun ω => if Conn G (ω:Set E) x y then (1:ℝ) else 0) p = - (law p).real {ω | Conn G (ω ∩ (Q:Set E)) x y} := - finiteEventPolynomial_restrict Q {ω | Conn G ω x y} p - rw [bernoulliPolynomial_const_mul,hpQ] - apply mul_le_mul_of_nonneg_left _ (hf y) - exact measureReal_mono (fun ω h => conn_mono G Set.inter_subset_left h) - _ ≤ _ := hs.sum_le_tsum _ (fun y _ => mul_nonneg (hf y) (twoPoint_nonneg G p x y)) - -noncomputable def finitePairKernel (G : BondGraph V E) (J : V → V → ℝ) - (ω : Finset E) (x y : V) : ℝ := - ∑ a ∈ finiteRootComponent G ω x, finiteClusterWeight G (J a) y ω - -theorem finitePairKernel_nonneg (G : BondGraph V E) (J : V → V → ℝ) - (hJ : ∀ a b, 0 ≤ J a b) (ω : Finset E) (x y : V) : 0 ≤ finitePairKernel G J ω x y := - Finset.sum_nonneg fun a _ => Finset.sum_nonneg fun b _ => hJ a b - -theorem finitePairKernel_exterior (G : BondGraph V E) (J : V → V → ℝ) - (ω : Finset E) (x y : V) (hd : ¬Conn G (ω:Set E) x y) : - finitePairKernel G J ω x y = ∑ a ∈ finiteRootComponent G ω x, - finiteClusterWeight G (J a) y (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) := by - unfold finitePairKernel finiteClusterWeight - rw [finiteRootComponent_exterior G ω x y hd] - -end FiniteClusterKernel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SmallFinitePairKernel -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteSmallPairKernel (G : BondGraph V E) (J : V → V → ℝ) - (L : ℝ) (x y : V) (ω : Finset E) : ℝ := - if (finiteRootComponent G ω x).card < L ∧ ¬Conn G (ω:Set E) x y then finitePairKernel G J ω x y else 0 - -noncomputable def finiteSmallClusterSize (G : BondGraph V E) (L : ℝ) (x : V) (ω : Finset E) : ℝ := - if (finiteRootComponent G ω x).card < L then (finiteRootComponent G ω x).card else 0 - - -theorem finiteSmallPairKernel_bound [Countable E] - (G : BondGraph V E) (Q : Finset E) (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) - (x y : V) (p : unitInterval) (L M : ℝ) (hM : 0 ≤ M) - (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) - (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : - bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ - M*bernoulliPolynomial Q (finiteSmallClusterSize G L x) p := by - let f (W : Finset V) (η : Finset E) : ℝ := - (if (W.card:ℝ) < L ∧ y ∉ W then ∑ a ∈ W, finiteClusterWeight G (J a) y η else 0) - - M*(if (W.card:ℝ) < L then (W.card:ℝ) else 0) - have hf (W : Finset V) : bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ 0 := by - by_cases hW : (W.card:ℝ) < L - · by_cases hy : y ∈ W - · simp only [f,hW,hy,not_true_eq_false,and_false,ite_false,ite_true,zero_sub, - bernoulliPolynomial_const] - exact neg_nonpos.mpr (mul_nonneg hM (Nat.cast_nonneg _)) - · simp only [f,hW,hy,not_false_eq_true,and_self,ite_true,bernoulliPolynomial_sub, - bernoulliPolynomial_const,bernoulliPolynomial_sum] - apply sub_nonpos.mpr - calc - _ ≤ ∑ _a ∈ W, M := Finset.sum_le_sum fun a _ => - (finiteClusterWeight_expectation_le G _ (J a) (hJ a) y p (hs a)).trans (hb a) - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul]; ring - · simp only [f,hW,false_and,ite_false,mul_zero,sub_zero,bernoulliPolynomial_zero] - exact le_rfl - have ht := cluster_exterior_expectation_bound G Q x p f 0 hf - have he (ω : Finset E) : f (finiteRootComponent G ω x) - (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) = - finiteSmallPairKernel G J L x y ω - M*finiteSmallClusterSize G L x ω := by - have hm : y ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x y := by - change y ∈ (finiteRootComponent G ω x:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - unfold f finiteSmallPairKernel finiteSmallClusterSize - simp only [hm] - by_cases hc : (finiteRootComponent G ω x).card < L ∧ ¬Conn G (ω:Set E) x y - · rw [ite_eq_left hc,ite_eq_left hc,finitePairKernel_exterior G J ω x y hc.2] - · rw [ite_eq_right hc,ite_eq_right hc] - simp_rw [he] at ht - rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul] at ht - exact sub_nonpos.mp ht - -end SmallFinitePairKernel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SmallSizeFractionalMoment -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem small_count_le_power (s L α : ℝ) (hs : 0 ≤ s) (hL : 0 ≤ L) (hα : α ≤ 1) : - (if s < L then s else 0) ≤ L^(1-α)*s^α := by - by_cases h : s < L - · rw [ite_eq_left h] - rcases eq_or_lt_of_le hs with rfl | hs' - · positivity - · calc - s = s^(1-α)*s^α := by rw [←Real.rpow_add hs']; simp only [sub_add_cancel,Real.rpow_one] - _ ≤ _ := mul_le_mul_of_nonneg_right (Real.rpow_le_rpow hs h.le (by linarith)) (Real.rpow_nonneg hs α) - · rw [ite_eq_right h] - exact mul_nonneg (Real.rpow_nonneg hL _) (Real.rpow_nonneg hs _) - -theorem finiteSmallClusterSize_moment_bound [Countable E] - (G : BondGraph V E) (Q : Finset E) (x : V) (p : unitInterval) - (L α : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : - bernoulliPolynomial Q (finiteSmallClusterSize G L x) p ≤ - L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by - let f (ω : Set E) := finiteSmallClusterSize G L x (domainBits Q ω) - have hf : Integrable f (law p) := integrable_finite_local Q p f (fun ω => by - dsimp [f]; rw [domainBits_local]) - rw [←integral_domainBits Q p (finiteSmallClusterSize G L x),←integral_const_mul] - apply integral_mono_ae hf (hI.const_mul _) - filter_upwards [hfin] with ω hω - have hc : (finiteRootComponent G (domainBits Q ω) x).card ≤ (cluster G ω x).ncard := by - rw [←Set.ncard_coe_finset,coe_finiteRootComponent,coe_domainBits] - exact Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω - have hc' : ((finiteRootComponent G (domainBits Q ω) x).card:ℝ) ≤ (cluster G ω x).ncard := by exact_mod_cast hc - exact (small_count_le_power _ L α (Nat.cast_nonneg _) hL hα1).trans - (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow (Nat.cast_nonneg _) hc' hα0) (Real.rpow_nonneg hL _)) - -theorem finiteSmallPairKernel_moment_bound [Countable E] - (G : BondGraph V E) (Q : Finset E) (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) - (x y : V) (p : unitInterval) (L M α : ℝ) (hL : 0 ≤ L) (hM : 0 ≤ M) - (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) - (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) - (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : - bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ - M*(L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p)) := - (finiteSmallPairKernel_bound G Q J hJ x y p L M hM hs hb).trans - (mul_le_mul_of_nonneg_left (finiteSmallClusterSize_moment_bound G Q x p L α hL hα0 hα1 hfin hI) hM) - -end SmallSizeFractionalMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section SmallKernelLimit -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem clusterPairKernel_finite (G : BondGraph V E) (J : V → V → ℝ≥0∞) - (ω : Finset E) (x y : V) : - clusterPairKernel G ω J x y = - ∑ a ∈ finiteRootComponent G ω x, ∑ b ∈ finiteRootComponent G ω y, J a b := by - have hm (x a : V) : a ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x a := by - change a ∈ (finiteRootComponent G ω x:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - rw [clusterPairKernel,tsum_eq_sum (s := finiteRootComponent G ω x) (fun a ha => by - simp only [←hm x a,ha,false_and,ite_false,tsum_zero])] - apply Finset.sum_congr rfl - intro a ha - rw [tsum_eq_sum (s := finiteRootComponent G ω y) (fun b hb => by - simp only [←hm y b,hb,and_false,ite_false])] - apply Finset.sum_congr rfl - intro b hb - rw [ite_eq_left ⟨(hm x a).mp ha,(hm y b).mp hb⟩] - -theorem ofReal_finitePairKernel (G : BondGraph V E) (J : V → V → ℝ) - (hJ : ∀ a b, 0 ≤ J a b) (ω : Finset E) (x y : V) : - ENNReal.ofReal (finitePairKernel G J ω x y) = - clusterPairKernel G ω (fun a b => ENNReal.ofReal (J a b)) x y := by - rw [clusterPairKernel_finite] - unfold finitePairKernel finiteClusterWeight - rw [ENNReal.ofReal_sum_of_nonneg (fun a _ => Finset.sum_nonneg fun b _ => hJ a b)] - apply Finset.sum_congr rfl - intro a _ - exact ENNReal.ofReal_sum_of_nonneg (fun b _ => hJ a b) - -noncomputable def smallPairKernel (G : BondGraph V E) (J : V → V → ℝ≥0∞) - (L : ℝ) (x y : V) (ω : Set E) : ℝ≥0∞ := - if ((cluster G ω x).ncard:ℝ) < L ∧ ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 - -theorem smallPairKernel_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) (L : ℝ) - (ω : Set E) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) - (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) - (hQy : incidentSupport G hloc hy.toFinset ⊆ Q) : - ENNReal.ofReal (finiteSmallPairKernel G J L x y (domainBits Q ω)) = - smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω := by - have hcluster (z : V) (hz : (cluster G ω z).Finite) (hQ : incidentSupport G hloc hz.toFinset ⊆ Q) : - cluster G (domainBits Q ω:Set E) z = cluster G ω z := by - rw [coe_domainBits] - have hh := (cluster_restrict_incident_eq_iff G hloc hz.toFinset Q hQ ω z).mpr - (Set.Finite.coe_toFinset hz).symm - simpa only [Set.Finite.coe_toFinset] using hh - have hxC := hcluster x hx hQx - have hyC := hcluster y hy hQy - have hxN : (finiteRootComponent G (domainBits Q ω) x).card = (cluster G ω x).ncard := by - rw [←Set.ncard_coe_finset,coe_finiteRootComponent,hxC] - have hxconn (a : V) : Conn G (domainBits Q ω:Set E) x a ↔ Conn G ω x a := by - change a ∈ cluster G (domainBits Q ω:Set E) x ↔ a ∈ cluster G ω x - rw [hxC] - have hyconn (b : V) : Conn G (domainBits Q ω:Set E) y b ↔ Conn G ω y b := by - change b ∈ cluster G (domainBits Q ω:Set E) y ↔ b ∈ cluster G ω y - rw [hyC] - unfold finiteSmallPairKernel smallPairKernel - rw [hxN] - simp only [hxconn] - split_ifs - · rw [ofReal_finitePairKernel G J hJ] - simp only [clusterPairKernel,hxconn,hyconn] - · exact ENNReal.ofReal_zero - -end SmallKernelLimit -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section SmallKernelFatou -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem smallPairKernel_lintegral_le_of_finite [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) (L : ℝ) (x y : V) (p : unitInterval) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (B : ℝ) - (hB : ∀ Q : Finset E, bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ B) : - (∫⁻ ω, smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω ∂law p) ≤ ENNReal.ofReal B := by - let : Encodable E := Encodable.ofCountable E - let Q := vertexExhaustion (V := E) - let f := fun j ω => finiteSmallPairKernel G J L x y (domainBits (Q j) ω) - have hfi (j : ℕ) : Integrable (f j) (law p) := integrable_finite_local (Q j) p (f j) (fun ω => by - dsimp [f]; rw [domainBits_local]) - have hfn (j : ℕ) : 0 ≤ᵐ[law p] f j := Eventually.of_forall (fun ω => by - dsimp [f,finiteSmallPairKernel] - split_ifs - · exact finitePairKernel_nonneg G J hJ _ x y - · exact le_rfl) - have heq : ∀ᵐ ω ∂law p, - liminf (fun j => ENNReal.ofReal (f j ω)) atTop = - smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω := by - filter_upwards [hx,hy] with ω hωx hωy - obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hωx.toFinset) - obtain ⟨jy,hjy⟩ := subset_vertexExhaustion (incidentSupport G hloc hωy.toFinset) - have he : (fun j => ENNReal.ofReal (f j ω)) =ᶠ[atTop] - (fun _ => smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω) := by - filter_upwards [eventually_ge_atTop (max jx jy)] with j hj - exact smallPairKernel_eq_finite G hloc J hJ L ω x y hωx hωy (Q j) - (hjx.trans (vertexExhaustion_mono (le_max_left jx jy |>.trans hj))) - (hjy.trans (vertexExhaustion_mono (le_max_right jx jy |>.trans hj))) - exact (tendsto_const_nhds.congr' he.symm).liminf_eq - calc - _ = ∫⁻ ω, liminf (fun j => ENNReal.ofReal (f j ω)) atTop ∂law p := lintegral_congr_ae (heq.mono (fun _ h => h.symm)) - _ ≤ liminf (fun j => ∫⁻ ω, ENNReal.ofReal (f j ω) ∂law p) atTop := - lintegral_liminf_le' (fun j => (hfi j).aemeasurable.ennreal_ofReal) - _ ≤ ENNReal.ofReal B := liminf_le_of_frequently_le' (Eventually.frequently (Eventually.of_forall (fun j => by - rw [←ofReal_integral_eq_lintegral_ofReal (hfi j) (hfn j)] - apply ENNReal.ofReal_le_ofReal - rw [show (∫ ω, f j ω ∂law p) = bernoulliPolynomial (Q j) (finiteSmallPairKernel G J L x y) p from - integral_domainBits (Q j) p (finiteSmallPairKernel G J L x y)] - exact hB (Q j)))) - - - -theorem smallPairKernel_moment_bound [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) - (x y : V) (p : unitInterval) (L M α : ℝ) (hL : 0 ≤ L) (hM : 0 ≤ M) - (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) - (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) - (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : - (∫⁻ ω, smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω ∂law p) ≤ - ENNReal.ofReal (M*(L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p))) := - smallPairKernel_lintegral_le_of_finite G hloc J hJ L x y p hx hy _ (fun Q => - finiteSmallPairKernel_moment_bound G Q J hJ x y p L M α hL hM hα0 hα1 hx hI hs hb) - -end SmallKernelFatou -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal ComplexOrder -section SmallTwoPointKernel -attribute [local instance] Classical.propDecidable Classical.decEq -attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass -local instance : NonUnitalContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -local instance : ContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) - -theorem matrixCoeff_positive_trace_norm {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : KernelInvariant Γ A) (hpos : 0 ≤ A) (x y : V) : - ‖matrixCoeff A x y‖ ≤ c*(rootTrace root weight A).re := by - have hd (z : V) : (matrixCoeff A z z).re ≤ c*(rootTrace root weight A).re := by - have h := (Complex.le_def.mp (rootTrace_diag_le root weight hcov hw c hc hmin A hA hpos z)).1 - simpa only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] using h - have hn (z : V) : 0 ≤ (matrixCoeff A z z).re := (Complex.nonneg_iff.mp (matrixCoeff_nonneg A hpos z)).1 - have hC : 0 ≤ c*(rootTrace root weight A).re := mul_nonneg hc - (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw A hpos)).1 - have hs := matrixCoeff_positive_product_norm_sq_le A 1 hpos x y - simp only [one_mul,star_one,mul_one] at hs - have hp := mul_le_mul (hd x) (hd y) (hn y) hC - nlinarith [norm_nonneg (matrixCoeff A x y)] - -theorem smallPairKernel_twoPoint_bound [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (x y : V) (p : unitInterval) (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (L α : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : - (∫⁻ ω, smallPairKernel G (ennMatrixCoeff (T^2)) L x y ω ∂law p) ≤ - ENNReal.ofReal ((c*(rootTrace root weight (T^3)).re)* - (L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p))) := by - have hp := hT.positiveRealMatrix G p T - have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) - have hp3 := CStarAlgebra.pow_nonneg T 3 hpos - have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - have hM : 0 ≤ c*(rootTrace root weight (T^3)).re := mul_nonneg hc - (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw _ hp3)).1 - have he (b : V) : (matrixCoeff T b y).re = twoPoint G p y b := by - change (T (lp.single 2 y (1:ℂ)) b).re = _ - rw [hT b y,Complex.ofReal_re,twoPoint_symm G p b y] - have hs (a : V) : HasSum (fun b => (matrixCoeff (T^2) a b).re * twoPoint G p y b) - (matrixCoeff (T^3) a y).re := by - simpa only [he,←pow_succ] using (hp.pow 2).mul_hasSum T a y - apply smallPairKernel_moment_bound G hloc (fun a b => (matrixCoeff (T^2) a b).re) - (fun a b => ((hp.pow 2) a b).2) x y p L _ α hL hM hα0 hα1 hx hy hI - (fun a => (hs a).summable) - intro a - rw [(hs a).tsum_eq] - exact (Complex.re_le_norm _).trans (matrixCoeff_positive_trace_norm root weight Γ hcov hw c hc hmin _ (hTI.pow 3) hp3 a y) - -end SmallTwoPointKernel -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section ContactSmallReroot -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_smallPairKernel [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (J : V → V → ℝ≥0∞) (L : ℝ) (x y : V) : - Measurable (smallPairKernel G J L x y) := by - exact (measurable_clusterPairKernel G J x y).ite - ((measurableSet_lt ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x)) - measurable_const).inter (measurableSet_conn G x y).compl) measurable_const - -theorem smallPairKernel_cluster_constant (G : BondGraph V E) (J : V → V → ℝ≥0∞) - (L : ℝ) (ω : Set E) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : - smallPairKernel G J L x y ω = smallPairKernel G J L a b ω := by - have hc : Conn G ω x y ↔ Conn G ω a b := by - constructor - · intro h; exact conn_trans G ω (conn_symm G ω hxa) (conn_trans G ω h hyb) - · intro h; exact conn_trans G ω hxa (conn_trans G ω h (conn_symm G ω hyb)) - simp only [smallPairKernel,cluster_eq_of_conn G ω hxa,hc, - clusterPairKernel_cluster_constant G ω J x y a b hxa hyb] - -theorem smallPairKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J (a x) (a y) = J x y) - (L : ℝ) (ω : Set E) (x y : V) : - smallPairKernel G J L x y (b ⁻¹' ω) = smallPairKernel G J L (a x) (a y) ω := by - simp only [smallPairKernel,cluster_ncard_covariant G hab,conn_aut_iff G hab, - clusterPairKernel_aut G hab J hJ] - -theorem smallPairKernel_distinct (G : BondGraph V E) (J : V → V → ℝ≥0∞) - (L : ℝ) (ω : Set E) (x y : V) : - (if ¬Conn G ω x y then smallPairKernel G J L x y ω else 0) = smallPairKernel G J L x y ω := by - by_cases h : Conn G ω x y - · simp only [smallPairKernel,h,not_true_eq_false,and_false,ite_false] - · exact ite_eq_left h - - -theorem contact_smallPairKernel_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) - (L : ℝ) (d : ℕ) (hd : ∀ x, degree G x ≤ d) (B : ℝ) - (hb : ∀ x y, (∫⁻ ω, smallPairKernel G J L x y ω ∂law p) ≤ ENNReal.ofReal B) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) ≤ - ENNReal.ofReal ((d:ℝ)*B) := by - have hj : ∀ a ∈ Γ, ∀ x y, indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by - intro a ha x y - obtain ⟨b,hab⟩ := hΓ ha - exact indexedEdgeKernel_aut G hab x y - rw [clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin - (indexedEdgeKernel G) hj (fun ω x y => smallPairKernel G J L x y ω) - (measurable_smallPairKernel G hloc J L) - (fun ω x y a b hxa hyb => smallPairKernel_cluster_constant G J L ω x y a b hxa hyb) - (fun a ha b hab ω x y => smallPairKernel_aut G hab J (hJ a ha) L ω x y)] - simp_rw [smallPairKernel_distinct] - have hr (x : V) : (∫⁻ ω, ∑' y, indexedEdgeKernel G x y * smallPairKernel G J L x y ω ∂law p) ≤ - ENNReal.ofReal ((d:ℝ)*B) := by - have hm (y : V) : Measurable (fun ω => indexedEdgeKernel G x y * smallPairKernel G J L x y ω) := - (measurable_const : Measurable (fun _ : Set E => indexedEdgeKernel G x y)).mul (measurable_smallPairKernel G hloc J L x y) - rw [lintegral_tsum (fun y => (hm y).aemeasurable)] - simp_rw [lintegral_const_mul _ (measurable_smallPairKernel G hloc J L x _)] - calc - _ ≤ ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal B := ENNReal.tsum_le_tsum (fun y => mul_le_mul_right (hb x y) _) - _ = (degree G x:ℝ≥0∞)*ENNReal.ofReal B := by rw [ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc x] - _ ≤ (d:ℝ≥0∞)*ENNReal.ofReal B := mul_le_mul_left (by exact_mod_cast hd x) _ - _ = _ := by rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_natCast] - calc - _ ≤ ∑ i, ENNReal.ofReal (weight i)*ENNReal.ofReal ((d:ℝ)*B) := - Finset.sum_le_sum (fun i _ => mul_le_mul_right (hr (root i)) _) - _ = _ := by rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1,ENNReal.ofReal_one,one_mul] - -end ContactSmallReroot -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PairMeasure -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def clusterPairMeasure [MeasurableSpace V] - {ι : Type*} [MeasurableSpace ι] (G : BondGraph V E) (p : unitInterval) - (root : ι → V) (weight : ι → ℝ) : Measure (Set E × (ι × V)) := - ((law p).prod Measure.count).withDensity (fun t => ENNReal.ofReal (weight t.2.1) * - clusterPairMass G t.1 (fun _ _ => 1) (root t.2.1) t.2.2) - -theorem clusterPairFunctional_eq_lintegral [Countable V] [Countable E] - [MeasurableSpace V] [MeasurableSingletonClass V] - {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - (root : ι → V) (weight : ι → ℝ) - (F : Set E → V → V → ℝ≥0∞) (hF : ∀ x y, Measurable (fun ω => F ω x y)) : - clusterPairFunctional G p root weight F = - ∫⁻ t, F t.1 (root t.2.1) t.2.2 ∂clusterPairMeasure G p root weight := by - let d : Set E × (ι × V) → ℝ≥0∞ := fun t => ENNReal.ofReal (weight t.2.1) * - clusterPairMass G t.1 (fun _ _ => 1) (root t.2.1) t.2.2 - let f : Set E × (ι × V) → ℝ≥0∞ := fun t => F t.1 (root t.2.1) t.2.2 - have hd : Measurable d := by - apply measurable_from_prod_countable_left - intro q - exact (measurable_const : Measurable (fun _ : Set E => ENNReal.ofReal (weight q.1))).mul - (measurable_clusterPairMass G hloc (fun _ _ _ => 1) (fun _ _ => measurable_const) (root q.1) q.2) - have hf : Measurable f := measurable_from_prod_countable_left (fun q => hF (root q.1) q.2) - change _ = ∫⁻ t, f t ∂((law p).prod Measure.count).withDensity d - rw [lintegral_withDensity_eq_lintegral_mul _ hd hf,lintegral_prod _ ((hd.mul hf).aemeasurable)] - have he (ω : Set E) (i : ι) (y : V) : - (d*f) (ω,(i,y)) = ENNReal.ofReal (weight i)*clusterPairMass G ω (F ω) (root i) y := by - dsimp [d,f,clusterPairMass] - (split_ifs <;> simp only [mul_one,mul_zero,zero_mul]); ring - simp_rw [lintegral_count,ENNReal.tsum_prod',he,tsum_fintype] - have hm (i : ι) : Measurable (fun ω => ∑' y, ENNReal.ofReal (weight i)*clusterPairMass G ω (F ω) (root i) y) := - Measurable.tsum (fun y => measurable_const.mul (measurable_clusterPairMass G hloc F hF (root i) y)) - rw [lintegral_finsetSum _ (fun i _ => hm i)] - simp_rw [ENNReal.tsum_mul_left] - rw [clusterPairFunctional] - apply Finset.sum_congr rfl - intro i _ - rw [lintegral_const_mul _ (Measurable.tsum (fun y => measurable_clusterPairMass G hloc F hF (root i) y))] - congr 1 - apply lintegral_congr - intro ω - exact clusterPairDensity_eq_tsum G ω (F ω) (root i) - - - -theorem clusterPairFunctional_cauchy_schwarz [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (F H : Set E → V → V → ℝ≥0∞) - (hF : ∀ x y, Measurable (fun ω => F ω x y)) - (hH : ∀ x y, Measurable (fun ω => H ω x y)) : - clusterPairFunctional G p root weight (fun ω x y => F ω x y*H ω x y) ≤ - (clusterPairFunctional G p root weight (fun ω x y => (F ω x y)^2))^((1:ℝ)/2) * - (clusterPairFunctional G p root weight (fun ω x y => (H ω x y)^2))^((1:ℝ)/2) := by - let : MeasurableSpace V := ⊤ - let : MeasurableSingletonClass V := ⟨fun _ => trivial⟩ - let : MeasurableSpace ι := ⊤ - let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ - rw [clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => F ω x y*H ω x y) (fun x y => (hF x y).mul (hH x y)), - clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => (F ω x y)^2) (fun x y => (hF x y).pow_const 2), - clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => (H ω x y)^2) (fun x y => (hH x y).pow_const 2)] - have hf : Measurable (fun t : Set E × (ι × V) => F t.1 (root t.2.1) t.2.2) := - measurable_from_prod_countable_left (fun q => hF (root q.1) q.2) - have hh : Measurable (fun t : Set E × (ι × V) => H t.1 (root t.2.1) t.2.2) := - measurable_from_prod_countable_left (fun q => hH (root q.1) q.2) - simpa only [Pi.mul_apply,ENNReal.rpow_two] using - ENNReal.lintegral_mul_le_Lp_mul_Lq (clusterPairMeasure G p root weight) Real.HolderConjugate.two_two hf.aemeasurable hh.aemeasurable - -end PairMeasure -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts + +namespace OAI + +/-! Contact Trace for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section IndexedEdgeKernel +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem enn_ncard_eq_tsum {α : Type*} (A : Set α) (hA : A.Finite) : + (A.ncard:ℝ≥0∞) = ∑' a, if a ∈ A then (1:ℝ≥0∞) else 0 := by + rw [tsum_eq_sum (s := hA.toFinset) (fun a ha => by + simp only [Set.Finite.mem_toFinset] at ha + exact ite_eq_right ha)] + simp only [Set.ncard_eq_toFinset_card A hA] + rw [Finset.sum_congr rfl (fun a ha => ite_eq_left ((Set.Finite.mem_toFinset _).mp ha))] + simp + + + +noncomputable def indexedEdgeKernel (G : BondGraph V E) (x y : V) : ℝ≥0∞ := + ∑' e, if G e = s(x,y) then 1 else 0 + +theorem indexedEdgeKernel_eq_ncard (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : + indexedEdgeKernel G x y = ({e | G e = s(x,y)}.ncard:ℝ≥0∞) := by + have hf : ({e | G e = s(x,y)} : Set E).Finite := (hloc x).subset (fun e he => by change x ∈ G e; change G e = s(x,y) at he; rw [he]; simp) + unfold indexedEdgeKernel + convert (enn_ncard_eq_tsum _ hf).symm using 1 + apply tsum_congr + intro e + by_cases h : G e = s(x,y) <;> simp only [Set.mem_ofPred_eq,h,ite_true,ite_false] + +theorem indexedEdgeKernel_symm (G : BondGraph V E) (x y : V) : + indexedEdgeKernel G x y = indexedEdgeKernel G y x := by rw [indexedEdgeKernel,indexedEdgeKernel,Sym2.eq_swap] + +theorem indexedEdgeKernel_row (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + (∑' y, indexedEdgeKernel G x y) = (degree G x:ℝ≥0∞) := by + change (∑' y, ∑' e, if G e = s(x,y) then (1:ℝ≥0∞) else 0) = _ + rw [ENNReal.tsum_comm,←ENNReal.tsum_prod] + have hn := (enn_ncard_eq_tsum _ (finite_steps G hloc x)).symm + have he : (∑' (p : E × V), if G p.1 = s(x,p.2) then (1:ℝ≥0∞) else 0) = + (({ey : E × V | G ey.1 = s(x,ey.2)} : Set (E × V)).ncard:ℝ≥0∞) := by + convert hn using 1 + apply tsum_congr + intro ey + by_cases h : G ey.1 = s(x,ey.2) <;> simp only [Set.mem_ofPred_eq,h,ite_true,ite_false] + rw [he] + change (({ey : E × V | G ey.1 = s(x,ey.2)} : Set (E × V)).ncard:ℝ≥0∞) = (Nat.card (Step G x):ℝ≥0∞) + rw [←Nat.card_coe_set_eq]; rfl + +theorem indexedEdgeKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x y : V) : + indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by + unfold indexedEdgeKernel + rw [←b.tsum_eq (fun e => if G e = s(a x,a y) then (1:ℝ≥0∞) else 0)] + apply tsum_congr + intro e + have he : G (b e) = s(a x,a y) ↔ G e = s(x,y) := by + rw [hab e,←Sym2.map_mk] + exact (Sym2.map.injective a.injective).eq_iff + simp only [he] + +end IndexedEdgeKernel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ContactKernelCounting +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem contact_endpoints_unique (G : BondGraph V E) (ω : Set E) (x y : V) + (hd : ¬Conn G ω x y) {e : E} {a b c d : V} + (ha : Conn G ω x a) (_hb : Conn G ω y b) + (_hc : Conn G ω x c) (he : Conn G ω y d) + (hab : G e = s(a,b)) (hcd : G e = s(c,d)) : a = c ∧ b = d := by + rcases Sym2.eq_iff.mp (hab.symm.trans hcd) with h | h + · exact h + · exfalso + apply hd + exact conn_trans G ω ha (by simpa only [h.1] using conn_symm G ω he) + +theorem closedContactSet_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (A B : Set V) (hA : A.Finite) : (closedContactSet G A B).Finite := by + have hs := contactSet_subset_incident G hloc hA.toFinset B + rw [Set.Finite.coe_toFinset] at hs + exact (incidentSupport G hloc hA.toFinset).finite_toSet.subset hs + +theorem clusterPairKernel_edge (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x y : V) (hd : ¬Conn G ω x y) (hx : (cluster G ω x).Finite) : + clusterPairKernel G ω (indexedEdgeKernel G) x y = (clusterContactCount G ω x y:ℝ≥0∞) := by + have hed (e : E) : + (∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0) = + if e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) then 1 else 0 := by + by_cases h : e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) + · obtain ⟨a,ha,b,hb,hab⟩ := h + change Conn G ω x a at ha + change Conn G ω y b at hb + have hh : e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) := ⟨a,ha,b,hb,hab⟩ + rw [ite_eq_left hh,tsum_eq_single a] + · rw [tsum_eq_single b] + · exact ite_eq_left ⟨ha,hb,hab⟩ + · intro d hdb + apply ite_eq_right + intro hc + exact hdb (contact_endpoints_unique G ω x y hd hc.1 hc.2.1 ha hb hc.2.2 hab).2 + · intro c hca + apply ENNReal.tsum_eq_zero.mpr + intro d + apply ite_eq_right + intro hc + exact hca (contact_endpoints_unique G ω x y hd hc.1 hc.2.1 ha hb hc.2.2 hab).1 + · rw [ite_eq_right h] + apply ENNReal.tsum_eq_zero.mpr + intro a + apply ENNReal.tsum_eq_zero.mpr + intro b + apply ite_eq_right + intro hab + exact h ⟨a,hab.1,b,hab.2.1,hab.2.2⟩ + have he (a b : V) : (if Conn G ω x a ∧ Conn G ω y b then indexedEdgeKernel G a b else 0) = + ∑' e, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by + by_cases ha : Conn G ω x a <;> by_cases hb : Conn G ω y b <;> + simp only [ha,hb,and_self,true_and,false_and,ite_true,ite_false,indexedEdgeKernel,tsum_zero] + rw [clusterPairKernel] + simp_rw [he] + calc + _ = ∑' e, ∑' a, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by + calc + _ = ∑' a, ∑' e, ∑' b, if Conn G ω x a ∧ Conn G ω y b ∧ G e = s(a,b) then (1:ℝ≥0∞) else 0 := by + apply tsum_congr; intro a; exact ENNReal.tsum_comm + _ = _ := ENNReal.tsum_comm + _ = ∑' e, if e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) then (1:ℝ≥0∞) else 0 := tsum_congr hed + _ = _ := (enn_ncard_eq_tsum _ (closedContactSet_finite G hloc _ _ hx)).symm + +end ContactKernelCounting +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ContactCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem closedContactSet_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (A B : Set V) : + b '' closedContactSet G A B = closedContactSet G (a '' A) (a '' B) := by + ext e + constructor + · rintro ⟨f,⟨x,hx,y,hy,hf⟩,rfl⟩ + exact ⟨a x,Set.mem_image_of_mem a hx,a y,Set.mem_image_of_mem a hy,by rw [hab f,hf,Sym2.map_mk]⟩ + · rintro ⟨z,⟨x,hx,rfl⟩,w,⟨y,hy,rfl⟩,he⟩ + refine ⟨b.symm e,⟨x,hx,y,hy,?_⟩,b.apply_symm_apply e⟩ + apply Sym2.map.injective a.injective + rw [←hab,Sym2.map_mk] + simpa only [Equiv.apply_symm_apply] using he + +theorem clusterContactCount_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) : + clusterContactCount G (b ⁻¹' ω) x y = clusterContactCount G ω (a x) (a y) := by + unfold clusterContactCount + rw [←cluster_aut G hab ω x,←cluster_aut G hab ω y,←closedContactSet_aut G hab, + Set.ncard_image_of_injective _ b.injective] + +theorem fullLargeContact_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) (L : ℕ) : + fullLargeContact G x y L (b ⁻¹' ω) = fullLargeContact G (a x) (a y) L ω := by + simp only [fullLargeContact,conn_aut_iff G hab,cluster_ncard_covariant G hab,clusterContactCount_aut G hab] + +theorem fullLargeContact_cluster_constant (G : BondGraph V E) (ω : Set E) + (L : ℕ) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : + fullLargeContact G x y L ω = fullLargeContact G a b L ω := by + have hc : Conn G ω x y ↔ Conn G ω a b := by + constructor + · intro h; exact conn_trans G ω (conn_symm G ω hxa) (conn_trans G ω h hyb) + · intro h; exact conn_trans G ω hxa (conn_trans G ω h (conn_symm G ω hyb)) + simp only [fullLargeContact,clusterContactCount,cluster_eq_of_conn G ω hxa, + cluster_eq_of_conn G ω hyb,hc] + +theorem fullLargeContact_distinct (G : BondGraph V E) (ω : Set E) (x y : V) (L : ℕ) : + (if ¬Conn G ω x y then ENNReal.ofReal (fullLargeContact G x y L ω) else 0) = + ENNReal.ofReal (fullLargeContact G x y L ω) := by + by_cases h : Conn G ω x y + · simp only [fullLargeContact,h,not_true_eq_false,false_and,ite_false,ENNReal.ofReal_zero] + · exact ite_eq_left h + +end ContactCovariance +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ContactSquareTrace +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def contactSquareLarge (G : BondGraph V E) (L : ℕ) + (ω : Set E) (x y : V) : ℝ≥0∞ := + if L ≤ min (cluster G ω x).ncard (cluster G ω y).ncard then + (clusterContactCount G ω x y:ℝ≥0∞)^2 else 0 + +theorem contactSquareLarge_reroot [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) (L : ℕ) : + clusterPairFunctional G p root weight (contactSquareLarge G L) = + ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, + indexedEdgeKernel G (root i) y * ENNReal.ofReal (fullLargeContact G (root i) y L ω) ∂law p := by + have hj : ∀ a ∈ Γ, ∀ x y, indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by + intro a ha x y + obtain ⟨b,hab⟩ := hΓ ha + exact indexedEdgeKernel_aut G hab x y + have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin + (indexedEdgeKernel G) hj (fun ω x y => ENNReal.ofReal (fullLargeContact G x y L ω)) + (fun x y => (measurable_fullLargeContact G hloc x y L).ennreal_ofReal) + (fun ω x y a b hxa hyb => congrArg ENNReal.ofReal (fullLargeContact_cluster_constant G ω L x y a b hxa hyb)) + (fun a _ b hab ω x y => congrArg ENNReal.ofReal (fullLargeContact_aut G hab ω x y L)) + simp_rw [fullLargeContact_distinct] at ht + rw [←ht] + unfold clusterPairFunctional + apply Finset.sum_congr rfl + intro i _ + congr 1 + apply lintegral_congr_ae + filter_upwards [hfin (root i)] with ω hω + unfold clusterPairDensity + congr 1 + apply tsum_congr + intro y + congr 1 + by_cases hd : Conn G ω (root i) y + · simp only [hd,not_true_eq_false,ite_false] + · rw [ite_eq_left hd,ite_eq_left hd] + dsimp only + rw [clusterPairKernel_edge G hloc ω (root i) y hd hω] + unfold contactSquareLarge fullLargeContact + by_cases hs : L ≤ min (cluster G ω (root i)).ncard (cluster G ω y).ncard + · simp only [hd,hs,not_false_eq_true,true_and,ite_true,ENNReal.ofReal_natCast,pow_two] + · simp only [hs,and_false,ite_false,ENNReal.ofReal_zero,mul_zero] + +theorem contactSquareLarge_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) (L d : ℕ) + (hd : ∀ x, degree G x ≤ d) (B : ℝ) (_hB : 0 ≤ B) + (hI : ∀ x y, Integrable (fullLargeContact G x y L) (law p)) + (hb : ∀ x y, (∫ ω, fullLargeContact G x y L ω ∂law p) ≤ B) : + clusterPairFunctional G p root weight (contactSquareLarge G L) ≤ ENNReal.ofReal ((d:ℝ)*B) := by + have hi (x y : V) : (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y L ω) ∂law p) ≤ ENNReal.ofReal B := by + rw [←ofReal_integral_eq_lintegral_ofReal (hI x y) (Filter.Eventually.of_forall (fullLargeContact_nonneg G x y L))] + exact ENNReal.ofReal_le_ofReal (hb x y) + have hr (x : V) : (∫⁻ ω, ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal (fullLargeContact G x y L ω) ∂law p) ≤ + ENNReal.ofReal ((d:ℝ)*B) := by + have hm (y : V) : Measurable (fun ω => indexedEdgeKernel G x y * ENNReal.ofReal (fullLargeContact G x y L ω)) := + (measurable_const : Measurable (fun _ : Set E => indexedEdgeKernel G x y)).mul (measurable_fullLargeContact G hloc x y L).ennreal_ofReal + rw [lintegral_tsum (fun y => (hm y).aemeasurable)] + simp_rw [lintegral_const_mul _ (measurable_fullLargeContact G hloc x _ L).ennreal_ofReal] + calc + _ ≤ ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal B := ENNReal.tsum_le_tsum (fun y => mul_le_mul_right (hi x y) _) + _ = (degree G x:ℝ≥0∞)*ENNReal.ofReal B := by rw [ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc x] + _ ≤ (d:ℝ≥0∞)*ENNReal.ofReal B := mul_le_mul_left (by exact_mod_cast hd x) _ + _ = _ := by rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_natCast] + rw [contactSquareLarge_reroot G hconn hloc root weight Γ hΓ htr hw p hfin L] + calc + _ ≤ ∑ i, ENNReal.ofReal (weight i)*ENNReal.ofReal ((d:ℝ)*B) := + Finset.sum_le_sum (fun i _ => mul_le_mul_right (hr (root i)) _) + _ = _ := by rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1,ENNReal.ofReal_one,one_mul] + +end ContactSquareTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section CriticalContactSquare +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_contact_square_bound_nat + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → + ∀ L : ℕ, 1 ≤ L → clusterPairFunctional G p root weight (contactSquareLarge G L) ≤ + ENNReal.ofReal (C*(L:ℝ)^((1:ℝ)/2+ε-2*α)) := by + obtain ⟨A,hA,hb⟩ := critical_large_contact_bound G hloc hconn hqt hh root weight Γ hΓ htr + hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + obtain ⟨d,hd,hdeg⟩ := exists_degree_bound G hqt + refine ⟨(d:ℝ)*A,mul_pos (by exact_mod_cast hd) hA,?_⟩ + intro p hp hpq L hL + have hf : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite := by + intro x + obtain ⟨i,a,ha,rfl⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact cluster_finite_ae_mono G (a (root i)) p (pc G) hpq + (cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i)) + have h := contactSquareLarge_bound G hconn hloc root weight Γ hΓ htr (fun i => (hw i).le) hw1 p hf + L d hdeg (A*(L:ℝ)^((1:ℝ)/2+ε-2*α)) (mul_nonneg hA.le (Real.rpow_nonneg (by positivity) _)) + (fun x y => (hb x y p hp hpq L hL).1) (fun x y => (hb x y p hp hpq L hL).2) + simpa only [mul_assoc] using h + +end CriticalContactSquare +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section DistinctClusterBK +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem distinct_cluster_disjoint_occurrence (G : BondGraph V E) (ω : Set E) + (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) (hd : ¬Conn G ω x y) : + ω ∈ DisjointOccurrence {η | Conn G η x a} {η | Conn G η y b} := by + obtain ⟨s,hs,hsa⟩ := finiteWitness_conn G x a _ (conn_restrict_cluster G ω x (mem_cluster_self G ω x) hxa) + obtain ⟨t,ht,htb⟩ := finiteWitness_conn G y b _ (conn_restrict_cluster_compl G ω x hd hyb) + refine ⟨s,t,fun e he => (hs he).1,fun e he => (ht he).1,?_,hsa,htb⟩ + apply Finset.disjoint_left.mpr + intro e he ht' + obtain ⟨⟨z,w⟩,hr⟩ := Quot.exists_rep (G e) + have hz : z ∈ G e := by rw [←hr]; exact Sym2.mem_mk_left z w + exact (ht ht').2 z hz ((hs he).2 z hz) + +theorem distinct_cluster_two_point_bound [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y a b : V) : + law p {ω | Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y} ≤ + law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b} := by + calc + _ ≤ law p (DisjointOccurrence {ω | Conn G ω x a} {ω | Conn G ω y b}) := + measure_mono (fun ω h => distinct_cluster_disjoint_occurrence G ω x y a b h.1 h.2.1 h.2.2) + _ ≤ _ := bk_ennreal p _ _ (fun _ _ h hc => conn_mono G h hc) + (fun _ _ h hc => conn_mono G h hc) (finiteWitness_conn G x a) (finiteWitness_conn G y b) + +theorem measurable_clusterPairKernel [Countable V] [Countable E] + (G : BondGraph V E) (J : V → V → ℝ≥0∞) (x y : V) : + Measurable (fun ω => clusterPairKernel G ω J x y) := by + apply Measurable.tsum + intro a + apply Measurable.tsum + intro b + exact measurable_const.ite ((measurableSet_conn G x a).inter (measurableSet_conn G y b)) measurable_const + +theorem clusterPairKernel_cluster_constant (G : BondGraph V E) (ω : Set E) + (J : V → V → ℝ≥0∞) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : + clusterPairKernel G ω J x y = clusterPairKernel G ω J a b := by + have hx (z : V) : Conn G ω x z ↔ Conn G ω a z := + ⟨fun h => conn_trans G ω (conn_symm G ω hxa) h,fun h => conn_trans G ω hxa h⟩ + have hy (z : V) : Conn G ω y z ↔ Conn G ω b z := + ⟨fun h => conn_trans G ω (conn_symm G ω hyb) h,fun h => conn_trans G ω hyb h⟩ + simp only [clusterPairKernel,hx,hy] + +theorem clusterPairKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J (a x) (a y) = J x y) + (ω : Set E) (x y : V) : + clusterPairKernel G (b ⁻¹' ω) J x y = clusterPairKernel G ω J (a x) (a y) := by + unfold clusterPairKernel + rw [←a.tsum_eq (fun x' => ∑' y', if Conn G ω (a x) x' ∧ Conn G ω (a y) y' then J x' y' else 0)] + apply tsum_congr + intro x' + rw [←a.tsum_eq (fun y' => if Conn G ω (a x) (a x') ∧ Conn G ω (a y) y' then J (a x') y' else 0)] + simp only [hJ,conn_aut_iff G hab] + +end DistinctClusterBK +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PairSquareDiagram +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem clusterPairKernel_distinct_integral [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (J : V → V → ℝ≥0∞) (x y : V) : + (∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 ∂law p) = + ∑' a, ∑' b, J a b * law p {ω | Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y} := by + have he (ω : Set E) : (if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0) = + ∑' a, ∑' b, J a b * (if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0) := by + by_cases hd : Conn G ω x y + · simp only [hd,not_true_eq_false,and_false,ite_false,mul_zero,tsum_zero] + · rw [ite_eq_left hd,clusterPairKernel] + apply tsum_congr; intro a + apply tsum_congr; intro b + by_cases h : Conn G ω x a ∧ Conn G ω y b + · simp only [h.1,h.2,hd,not_false_eq_true,and_self,ite_true,mul_one] + · have hn : ¬ (Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y) := fun h' => h ⟨h'.1,h'.2.1⟩ + simp only [ite_eq_right h,ite_eq_right hn,mul_zero] + have hm (a b : V) : Measurable (fun ω => if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0) := + measurable_const.ite ((measurableSet_conn G x a).inter ((measurableSet_conn G y b).inter (measurableSet_conn G x y).compl)) measurable_const + have hm' (a b : V) : Measurable (fun ω : Set E => J a b * (if Conn G ω x a ∧ Conn G ω y b ∧ ¬Conn G ω x y then (1:ℝ≥0∞) else 0)) := + (measurable_const : Measurable (fun _ : Set E => J a b)).mul (hm a b) + simp_rw [he] + rw [lintegral_tsum (fun a => (Measurable.tsum (fun b => hm' a b)).aemeasurable)] + apply tsum_congr; intro a + rw [lintegral_tsum (fun b => (hm' a b).aemeasurable)] + apply tsum_congr; intro b + rw [lintegral_const_mul _ (hm a b)] + congr 1 + convert + (lintegral_indicator_one (μ := law p) ((measurableSet_conn G x a).inter ((measurableSet_conn G y b).inter (measurableSet_conn G x y).compl))) using 1 + · apply lintegral_congr + intro ω + simp only [Set.indicator,Set.mem_inter_iff,Set.mem_compl_iff,Set.mem_ofPred_eq,Pi.one_apply] + · congr 1 + +theorem clusterPairKernel_distinct_bound [Countable V] [Countable E] + (G : BondGraph V E) (p : unitInterval) (J : V → V → ℝ≥0∞) (x y : V) : + (∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 ∂law p) ≤ + ∑' a, ∑' b, J a b * (law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b}) := by + rw [clusterPairKernel_distinct_integral] + exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => + mul_le_mul_right (distinct_cluster_two_point_bound G p x y a b) _)) + + + +theorem clusterPairFunctional_square_diagram [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) : + clusterPairFunctional G p root weight (fun ω x y => (clusterPairKernel G ω J x y)^2) ≤ + ∑ i, ENNReal.ofReal (weight i) * ∑' v, ∑' a, ∑' b, + J (root i) v * (J a b * (law p {ω | Conn G ω (root i) a} * law p {ω | Conn G ω v b})) := by + have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin J hJ + (fun ω x y => clusterPairKernel G ω J x y) (measurable_clusterPairKernel G J) + (fun ω x y a b => clusterPairKernel_cluster_constant G ω J x y a b) + (fun a ha b hab ω x y => clusterPairKernel_aut G hab J (hJ a ha) ω x y) + simp only [←pow_two] at ht + rw [ht] + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_right + have hm (v : V) : Measurable (fun ω : Set E => if ¬Conn G ω (root i) v then clusterPairKernel G ω J (root i) v else 0) := + (measurable_clusterPairKernel G J (root i) v).ite (measurableSet_conn G (root i) v).compl measurable_const + have hm' (v : V) : Measurable (fun ω : Set E => J (root i) v * (if ¬Conn G ω (root i) v then clusterPairKernel G ω J (root i) v else 0)) := + (measurable_const : Measurable (fun _ : Set E => J (root i) v)).mul (hm v) + rw [lintegral_tsum (fun v => (hm' v).aemeasurable)] + apply ENNReal.tsum_le_tsum + intro v + rw [lintegral_const_mul _ (hm v)] + simp_rw [ENNReal.tsum_mul_left] + exact mul_le_mul_right (clusterPairKernel_distinct_bound G p J (root i) v) _ + +end PairSquareDiagram +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ContactRealCutoff +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def contactSquareLargeReal (G : BondGraph V E) (L : ℝ) + (ω : Set E) (x y : V) : ℝ≥0∞ := + if L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) then + (clusterContactCount G ω x y:ℝ≥0∞)^2 else 0 + +theorem contactSquareLargeReal_eq_ceil (G : BondGraph V E) (L : ℝ) + (ω : Set E) (x y : V) : + contactSquareLargeReal G L ω x y = contactSquareLarge G ⌈L⌉₊ ω x y := by + have he : L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) ↔ + ⌈L⌉₊ ≤ min (cluster G ω x).ncard (cluster G ω y).ncard := by + rw [←Nat.cast_min, Nat.ceil_le] + simp only [contactSquareLargeReal,contactSquareLarge,he] + + + +theorem critical_contact_square_bound + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → + ∀ L : ℝ, 1 ≤ L → clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ + ENNReal.ofReal (C*L^((1:ℝ)/2+ε-2*α)) := by + obtain ⟨C,hC,hb⟩ := critical_contact_square_bound_nat G hloc hconn hqt hh root weight Γ hΓ htr + hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + refine ⟨C,hC,?_⟩ + intro p hp hpq L hL + have hLn : 1 ≤ ⌈L⌉₊ := by + have hc : (1:ℝ) ≤ (⌈L⌉₊:ℝ) := hL.trans (Nat.le_ceil L) + exact_mod_cast hc + have hEq : contactSquareLargeReal G L = contactSquareLarge G ⌈L⌉₊ := funext fun ω => funext fun x => funext fun y => contactSquareLargeReal_eq_ceil G L ω x y + rw [hEq] + exact (hb p hp hpq _ hLn).trans (ENNReal.ofReal_le_ofReal + (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_nonpos (by linarith : 0 < L) (Nat.le_ceil L) hr.le) hC.le)) + +end ContactRealCutoff +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section NonnegativeOperatorDiagram +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def ennMatrixCoeff (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : ℝ≥0∞ := + ENNReal.ofReal (matrixCoeff A x y).re + +theorem ennMatrixCoeff_mul {A B : Hilbert V →L[ℂ] Hilbert V} + (hA : PositiveRealMatrix A) (hB : PositiveRealMatrix B) (x y : V) : + ennMatrixCoeff (A*B) x y = ∑' z, ennMatrixCoeff A x z * ennMatrixCoeff B z y := by + unfold ennMatrixCoeff + rw [←(hA.mul_hasSum B x y).tsum_eq, ENNReal.ofReal_tsum_of_nonneg + (fun z => mul_nonneg (hA x z).2 (hB z y).2) (hA.mul_hasSum B x y).summable] + apply tsum_congr; intro z + exact ENNReal.ofReal_mul (hA x z).2 + +theorem ennMatrixCoeff_symm {A : Hilbert V →L[ℂ] Hilbert V} + (hA : IsSelfAdjoint A) (x y : V) : ennMatrixCoeff A x y = ennMatrixCoeff A y x := by + unfold ennMatrixCoeff + rw [matrixCoeff_real_symm A hA x y] + +theorem HasKernel.ennMatrixCoeff [Countable E] (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : + ennMatrixCoeff T x y = law p {ω | Conn G ω x y} := by + unfold Percolation.ennMatrixCoeff matrixCoeff + rw [hT x y] + simp only [Complex.ofReal_re,twoPoint,ENNReal.ofReal_toReal (measure_ne_top _ _)] + +theorem HasKernel.positiveRealMatrix (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : PositiveRealMatrix T := by + intro x y + change (T (lp.single 2 y (1:ℂ)) x).im = 0 ∧ 0 ≤ (T (lp.single 2 y (1:ℂ)) x).re + rw [hT x y] + exact ⟨rfl,twoPoint_nonneg G p x y⟩ + +theorem square_kernel_diagram (J T : Hilbert V →L[ℂ] Hilbert V) + (hJ : PositiveRealMatrix J) (hT : PositiveRealMatrix T) + (hsJ : IsSelfAdjoint J) (hsT : IsSelfAdjoint T) (x : V) : + (∑' v, ∑' a, ∑' b, ennMatrixCoeff J x v * (ennMatrixCoeff J a b * + (ennMatrixCoeff T x a * ennMatrixCoeff T v b))) = ennMatrixCoeff (J*T*J*T) x x := by + rw [mul_assoc,mul_assoc,ennMatrixCoeff_mul hJ (hT.mul (hJ.mul hT))] + apply tsum_congr; intro v + rw [ennMatrixCoeff_mul hT (hJ.mul hT)] + simp_rw [ennMatrixCoeff_mul hJ hT] + simp_rw [←ENNReal.tsum_mul_left] + rw [ENNReal.tsum_comm] + apply tsum_congr; intro b + apply tsum_congr; intro a + rw [ennMatrixCoeff_symm hsJ b a,ennMatrixCoeff_symm hsT a x] + ac_rfl + +theorem enn_rootTrace {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) : + (∑ i, ENNReal.ofReal (weight i) * ennMatrixCoeff A (root i) (root i)) = + ENNReal.ofReal (rootTrace root weight A).re := by + unfold rootTrace ennMatrixCoeff + simp only [Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] + rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => mul_nonneg (hw i) (hA _ _).2)] + apply Finset.sum_congr rfl; intro i _ + exact (ENNReal.ofReal_mul (hw i)).symm + +end NonnegativeOperatorDiagram +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal ComplexOrder +section KernelSquareTrace +attribute [local instance] Classical.propDecidable Classical.decEq +attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass +local instance : NonUnitalContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +local instance : ContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) + +theorem rootTrace_six_le_cube {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) {Γ : Set (V ≃ V)} + (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : KernelInvariant Γ T) (hpos : 0 ≤ T) : + (rootTrace root weight (T^6)).re ≤ ‖T‖^3*(rootTrace root weight (T^3)).re := by + have hp3 : 0 ≤ T^3 := CStarAlgebra.pow_nonneg T 3 hpos + have h := rootTrace_positive_mul_le root weight htr hw (T^3) (T^3) + (hT.pow 3) (hT.pow 3) hp3 (IsSelfAdjoint.of_nonneg hp3) + have he : T^3*T^3 = T^6 := by rw [←pow_add] + rw [he] at h + have hr := (Complex.le_def.mp h).1 + simp only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] at hr + exact hr.trans (mul_le_mul_of_nonneg_right (norm_pow_le' T (by norm_num : 0 < (3:ℕ))) + (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw (T^3) hp3)).1) + + + +theorem clusterPairFunctional_twoPoint_square_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : + clusterPairFunctional G p root weight (fun ω x y => + (clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)^2) ≤ + ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re) := by + have hp := hT.positiveRealMatrix G p T + have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) + have hsa := IsSelfAdjoint.of_nonneg hpos + have hI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + have hJ : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff (T^2) (a x) (a y) = ennMatrixCoeff (T^2) x y := by + intro a ha x y + unfold ennMatrixCoeff + rw [(hI.pow 2) a ha] + have hb := clusterPairFunctional_square_diagram G hconn hloc root weight Γ hΓ htr hw p hfin + (ennMatrixCoeff (T^2)) hJ + have hd (x : V) : (∑' v, ∑' a, ∑' b, ennMatrixCoeff (T^2) x v * (ennMatrixCoeff (T^2) a b * + (law p {ω | Conn G ω x a} * law p {ω | Conn G ω v b}))) = ennMatrixCoeff (T^6) x x := by + simp_rw [←hT.ennMatrixCoeff G p T] + rw [square_kernel_diagram (T^2) T (hp.pow 2) hp (hsa.pow 2) hsa] + congr 1 + simp_rw [hd] at hb + rw [enn_rootTrace root weight hw (T^6) (hp.pow 6)] at hb + exact hb.trans (ENNReal.ofReal_le_ofReal (rootTrace_six_le_cube root weight htr hw T hI hpos)) + +end KernelSquareTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteClusterKernel +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteClusterWeight (G : BondGraph V E) (f : V → ℝ) + (x : V) (ω : Finset E) : ℝ := ∑ y ∈ finiteRootComponent G ω x, f y + +theorem finiteClusterWeight_expand (G : BondGraph V E) (f : V → ℝ) + (Q ω : Finset E) (hω : ω ⊆ Q) (x : V) : + finiteClusterWeight G f x ω = ∑ y ∈ insert x (searchVertices G Q), + f y * (if Conn G (ω:Set E) x y then (1:ℝ) else 0) := by + unfold finiteClusterWeight + calc + _ = ∑ y ∈ finiteRootComponent G ω x, f y * (if Conn G (ω:Set E) x y then (1:ℝ) else 0) := by + apply Finset.sum_congr rfl + intro y hy + have hc : Conn G (ω:Set E) x y := by + change y ∈ (finiteRootComponent G ω x:Set V) at hy + rwa [coe_finiteRootComponent] at hy + rw [ite_eq_left hc,mul_one] + _ = _ := Finset.sum_subset (finiteRootComponent_subset G Q _ x ω hω (by rfl)) (by + intro y _ hy + have hn : ¬Conn G (ω:Set E) x y := by + intro h + apply hy + change y ∈ (finiteRootComponent G ω x:Set V) + rwa [coe_finiteRootComponent] + rw [ite_eq_right hn,mul_zero]) + +theorem finiteClusterWeight_expectation_le [Countable E] + (G : BondGraph V E) (Q : Finset E) (f : V → ℝ) (hf : ∀ y, 0 ≤ f y) + (x : V) (p : unitInterval) (hs : Summable (fun y => f y*twoPoint G p x y)) : + bernoulliPolynomial Q (finiteClusterWeight G f x) p ≤ ∑' y, f y*twoPoint G p x y := by + have he : bernoulliPolynomial Q (finiteClusterWeight G f x) p = + bernoulliPolynomial Q (fun ω => ∑ y ∈ insert x (searchVertices G Q), f y*(if Conn G (ω:Set E) x y then (1:ℝ) else 0)) p := by + apply bernoulliPolynomial_congr + intro ω hω + exact finiteClusterWeight_expand G f Q ω hω x + rw [he,bernoulliPolynomial_sum] + calc + _ ≤ ∑ y ∈ insert x (searchVertices G Q), f y*twoPoint G p x y := by + apply Finset.sum_le_sum + intro y _ + have hpQ : bernoulliPolynomial Q (fun ω => if Conn G (ω:Set E) x y then (1:ℝ) else 0) p = + (law p).real {ω | Conn G (ω ∩ (Q:Set E)) x y} := + finiteEventPolynomial_restrict Q {ω | Conn G ω x y} p + rw [bernoulliPolynomial_const_mul,hpQ] + apply mul_le_mul_of_nonneg_left _ (hf y) + exact measureReal_mono (fun ω h => conn_mono G Set.inter_subset_left h) + _ ≤ _ := hs.sum_le_tsum _ (fun y _ => mul_nonneg (hf y) (twoPoint_nonneg G p x y)) + +noncomputable def finitePairKernel (G : BondGraph V E) (J : V → V → ℝ) + (ω : Finset E) (x y : V) : ℝ := + ∑ a ∈ finiteRootComponent G ω x, finiteClusterWeight G (J a) y ω + +theorem finitePairKernel_nonneg (G : BondGraph V E) (J : V → V → ℝ) + (hJ : ∀ a b, 0 ≤ J a b) (ω : Finset E) (x y : V) : 0 ≤ finitePairKernel G J ω x y := + Finset.sum_nonneg fun a _ => Finset.sum_nonneg fun b _ => hJ a b + +theorem finitePairKernel_exterior (G : BondGraph V E) (J : V → V → ℝ) + (ω : Finset E) (x y : V) (hd : ¬Conn G (ω:Set E) x y) : + finitePairKernel G J ω x y = ∑ a ∈ finiteRootComponent G ω x, + finiteClusterWeight G (J a) y (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) := by + unfold finitePairKernel finiteClusterWeight + rw [finiteRootComponent_exterior G ω x y hd] + +end FiniteClusterKernel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SmallFinitePairKernel +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteSmallPairKernel (G : BondGraph V E) (J : V → V → ℝ) + (L : ℝ) (x y : V) (ω : Finset E) : ℝ := + if (finiteRootComponent G ω x).card < L ∧ ¬Conn G (ω:Set E) x y then finitePairKernel G J ω x y else 0 + +noncomputable def finiteSmallClusterSize (G : BondGraph V E) (L : ℝ) (x : V) (ω : Finset E) : ℝ := + if (finiteRootComponent G ω x).card < L then (finiteRootComponent G ω x).card else 0 + + +theorem finiteSmallPairKernel_bound [Countable E] + (G : BondGraph V E) (Q : Finset E) (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) + (x y : V) (p : unitInterval) (L M : ℝ) (hM : 0 ≤ M) + (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) + (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : + bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ + M*bernoulliPolynomial Q (finiteSmallClusterSize G L x) p := by + let f (W : Finset V) (η : Finset E) : ℝ := + (if (W.card:ℝ) < L ∧ y ∉ W then ∑ a ∈ W, finiteClusterWeight G (J a) y η else 0) - + M*(if (W.card:ℝ) < L then (W.card:ℝ) else 0) + have hf (W : Finset V) : bernoulliPolynomial (exteriorBonds G Q (W:Set V)) (f W) p ≤ 0 := by + by_cases hW : (W.card:ℝ) < L + · by_cases hy : y ∈ W + · simp only [f,hW,hy,not_true_eq_false,and_false,ite_false,ite_true,zero_sub, + bernoulliPolynomial_const] + exact neg_nonpos.mpr (mul_nonneg hM (Nat.cast_nonneg _)) + · simp only [f,hW,hy,not_false_eq_true,and_self,ite_true,bernoulliPolynomial_sub, + bernoulliPolynomial_const,bernoulliPolynomial_sum] + apply sub_nonpos.mpr + calc + _ ≤ ∑ _a ∈ W, M := Finset.sum_le_sum fun a _ => + (finiteClusterWeight_expectation_le G _ (J a) (hJ a) y p (hs a)).trans (hb a) + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul]; ring + · simp only [f,hW,false_and,ite_false,mul_zero,sub_zero,bernoulliPolynomial_zero] + exact le_rfl + have ht := cluster_exterior_expectation_bound G Q x p f 0 hf + have he (ω : Finset E) : f (finiteRootComponent G ω x) + (exteriorBonds G ω (finiteRootComponent G ω x:Set V)) = + finiteSmallPairKernel G J L x y ω - M*finiteSmallClusterSize G L x ω := by + have hm : y ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x y := by + change y ∈ (finiteRootComponent G ω x:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + unfold f finiteSmallPairKernel finiteSmallClusterSize + simp only [hm] + by_cases hc : (finiteRootComponent G ω x).card < L ∧ ¬Conn G (ω:Set E) x y + · rw [ite_eq_left hc,ite_eq_left hc,finitePairKernel_exterior G J ω x y hc.2] + · rw [ite_eq_right hc,ite_eq_right hc] + simp_rw [he] at ht + rw [bernoulliPolynomial_sub,bernoulliPolynomial_const_mul] at ht + exact sub_nonpos.mp ht + +end SmallFinitePairKernel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SmallSizeFractionalMoment +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem small_count_le_power (s L α : ℝ) (hs : 0 ≤ s) (hL : 0 ≤ L) (hα : α ≤ 1) : + (if s < L then s else 0) ≤ L^(1-α)*s^α := by + by_cases h : s < L + · rw [ite_eq_left h] + rcases eq_or_lt_of_le hs with rfl | hs' + · positivity + · calc + s = s^(1-α)*s^α := by rw [←Real.rpow_add hs']; simp only [sub_add_cancel,Real.rpow_one] + _ ≤ _ := mul_le_mul_of_nonneg_right (Real.rpow_le_rpow hs h.le (by linarith)) (Real.rpow_nonneg hs α) + · rw [ite_eq_right h] + exact mul_nonneg (Real.rpow_nonneg hL _) (Real.rpow_nonneg hs _) + +theorem finiteSmallClusterSize_moment_bound [Countable E] + (G : BondGraph V E) (Q : Finset E) (x : V) (p : unitInterval) + (L α : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : + bernoulliPolynomial Q (finiteSmallClusterSize G L x) p ≤ + L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) := by + let f (ω : Set E) := finiteSmallClusterSize G L x (domainBits Q ω) + have hf : Integrable f (law p) := integrable_finite_local Q p f (fun ω => by + dsimp [f]; rw [domainBits_local]) + rw [←integral_domainBits Q p (finiteSmallClusterSize G L x),←integral_const_mul] + apply integral_mono_ae hf (hI.const_mul _) + filter_upwards [hfin] with ω hω + have hc : (finiteRootComponent G (domainBits Q ω) x).card ≤ (cluster G ω x).ncard := by + rw [←Set.ncard_coe_finset,coe_finiteRootComponent,coe_domainBits] + exact Set.ncard_le_ncard (fun y hy => conn_mono G Set.inter_subset_left hy) hω + have hc' : ((finiteRootComponent G (domainBits Q ω) x).card:ℝ) ≤ (cluster G ω x).ncard := by exact_mod_cast hc + exact (small_count_le_power _ L α (Nat.cast_nonneg _) hL hα1).trans + (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow (Nat.cast_nonneg _) hc' hα0) (Real.rpow_nonneg hL _)) + +theorem finiteSmallPairKernel_moment_bound [Countable E] + (G : BondGraph V E) (Q : Finset E) (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) + (x y : V) (p : unitInterval) (L M α : ℝ) (hL : 0 ≤ L) (hM : 0 ≤ M) + (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) + (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) + (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : + bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ + M*(L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p)) := + (finiteSmallPairKernel_bound G Q J hJ x y p L M hM hs hb).trans + (mul_le_mul_of_nonneg_left (finiteSmallClusterSize_moment_bound G Q x p L α hL hα0 hα1 hfin hI) hM) + +end SmallSizeFractionalMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section SmallKernelLimit +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem clusterPairKernel_finite (G : BondGraph V E) (J : V → V → ℝ≥0∞) + (ω : Finset E) (x y : V) : + clusterPairKernel G ω J x y = + ∑ a ∈ finiteRootComponent G ω x, ∑ b ∈ finiteRootComponent G ω y, J a b := by + have hm (x a : V) : a ∈ finiteRootComponent G ω x ↔ Conn G (ω:Set E) x a := by + change a ∈ (finiteRootComponent G ω x:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + rw [clusterPairKernel,tsum_eq_sum (s := finiteRootComponent G ω x) (fun a ha => by + simp only [←hm x a,ha,false_and,ite_false,tsum_zero])] + apply Finset.sum_congr rfl + intro a ha + rw [tsum_eq_sum (s := finiteRootComponent G ω y) (fun b hb => by + simp only [←hm y b,hb,and_false,ite_false])] + apply Finset.sum_congr rfl + intro b hb + rw [ite_eq_left ⟨(hm x a).mp ha,(hm y b).mp hb⟩] + +theorem ofReal_finitePairKernel (G : BondGraph V E) (J : V → V → ℝ) + (hJ : ∀ a b, 0 ≤ J a b) (ω : Finset E) (x y : V) : + ENNReal.ofReal (finitePairKernel G J ω x y) = + clusterPairKernel G ω (fun a b => ENNReal.ofReal (J a b)) x y := by + rw [clusterPairKernel_finite] + unfold finitePairKernel finiteClusterWeight + rw [ENNReal.ofReal_sum_of_nonneg (fun a _ => Finset.sum_nonneg fun b _ => hJ a b)] + apply Finset.sum_congr rfl + intro a _ + exact ENNReal.ofReal_sum_of_nonneg (fun b _ => hJ a b) + +noncomputable def smallPairKernel (G : BondGraph V E) (J : V → V → ℝ≥0∞) + (L : ℝ) (x y : V) (ω : Set E) : ℝ≥0∞ := + if ((cluster G ω x).ncard:ℝ) < L ∧ ¬Conn G ω x y then clusterPairKernel G ω J x y else 0 + +theorem smallPairKernel_eq_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) (L : ℝ) + (ω : Set E) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) + (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) + (hQy : incidentSupport G hloc hy.toFinset ⊆ Q) : + ENNReal.ofReal (finiteSmallPairKernel G J L x y (domainBits Q ω)) = + smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω := by + have hcluster (z : V) (hz : (cluster G ω z).Finite) (hQ : incidentSupport G hloc hz.toFinset ⊆ Q) : + cluster G (domainBits Q ω:Set E) z = cluster G ω z := by + rw [coe_domainBits] + have hh := (cluster_restrict_incident_eq_iff G hloc hz.toFinset Q hQ ω z).mpr + (Set.Finite.coe_toFinset hz).symm + simpa only [Set.Finite.coe_toFinset] using hh + have hxC := hcluster x hx hQx + have hyC := hcluster y hy hQy + have hxN : (finiteRootComponent G (domainBits Q ω) x).card = (cluster G ω x).ncard := by + rw [←Set.ncard_coe_finset,coe_finiteRootComponent,hxC] + have hxconn (a : V) : Conn G (domainBits Q ω:Set E) x a ↔ Conn G ω x a := by + change a ∈ cluster G (domainBits Q ω:Set E) x ↔ a ∈ cluster G ω x + rw [hxC] + have hyconn (b : V) : Conn G (domainBits Q ω:Set E) y b ↔ Conn G ω y b := by + change b ∈ cluster G (domainBits Q ω:Set E) y ↔ b ∈ cluster G ω y + rw [hyC] + unfold finiteSmallPairKernel smallPairKernel + rw [hxN] + simp only [hxconn] + split_ifs + · rw [ofReal_finitePairKernel G J hJ] + simp only [clusterPairKernel,hxconn,hyconn] + · exact ENNReal.ofReal_zero + +end SmallKernelLimit +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section SmallKernelFatou +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem smallPairKernel_lintegral_le_of_finite [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) (L : ℝ) (x y : V) (p : unitInterval) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (B : ℝ) + (hB : ∀ Q : Finset E, bernoulliPolynomial Q (finiteSmallPairKernel G J L x y) p ≤ B) : + (∫⁻ ω, smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω ∂law p) ≤ ENNReal.ofReal B := by + let : Encodable E := Encodable.ofCountable E + let Q := vertexExhaustion (V := E) + let f := fun j ω => finiteSmallPairKernel G J L x y (domainBits (Q j) ω) + have hfi (j : ℕ) : Integrable (f j) (law p) := integrable_finite_local (Q j) p (f j) (fun ω => by + dsimp [f]; rw [domainBits_local]) + have hfn (j : ℕ) : 0 ≤ᵐ[law p] f j := Eventually.of_forall (fun ω => by + dsimp [f,finiteSmallPairKernel] + split_ifs + · exact finitePairKernel_nonneg G J hJ _ x y + · exact le_rfl) + have heq : ∀ᵐ ω ∂law p, + liminf (fun j => ENNReal.ofReal (f j ω)) atTop = + smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω := by + filter_upwards [hx,hy] with ω hωx hωy + obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hωx.toFinset) + obtain ⟨jy,hjy⟩ := subset_vertexExhaustion (incidentSupport G hloc hωy.toFinset) + have he : (fun j => ENNReal.ofReal (f j ω)) =ᶠ[atTop] + (fun _ => smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω) := by + filter_upwards [eventually_ge_atTop (max jx jy)] with j hj + exact smallPairKernel_eq_finite G hloc J hJ L ω x y hωx hωy (Q j) + (hjx.trans (vertexExhaustion_mono (le_max_left jx jy |>.trans hj))) + (hjy.trans (vertexExhaustion_mono (le_max_right jx jy |>.trans hj))) + exact (tendsto_const_nhds.congr' he.symm).liminf_eq + calc + _ = ∫⁻ ω, liminf (fun j => ENNReal.ofReal (f j ω)) atTop ∂law p := lintegral_congr_ae (heq.mono (fun _ h => h.symm)) + _ ≤ liminf (fun j => ∫⁻ ω, ENNReal.ofReal (f j ω) ∂law p) atTop := + lintegral_liminf_le' (fun j => (hfi j).aemeasurable.ennreal_ofReal) + _ ≤ ENNReal.ofReal B := liminf_le_of_frequently_le' (Eventually.frequently (Eventually.of_forall (fun j => by + rw [←ofReal_integral_eq_lintegral_ofReal (hfi j) (hfn j)] + apply ENNReal.ofReal_le_ofReal + rw [show (∫ ω, f j ω ∂law p) = bernoulliPolynomial (Q j) (finiteSmallPairKernel G J L x y) p from + integral_domainBits (Q j) p (finiteSmallPairKernel G J L x y)] + exact hB (Q j)))) + + + +theorem smallPairKernel_moment_bound [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (J : V → V → ℝ) (hJ : ∀ a b, 0 ≤ J a b) + (x y : V) (p : unitInterval) (L M α : ℝ) (hL : 0 ≤ L) (hM : 0 ≤ M) + (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) + (hs : ∀ a, Summable (fun b => J a b*twoPoint G p y b)) + (hb : ∀ a, (∑' b, J a b*twoPoint G p y b) ≤ M) : + (∫⁻ ω, smallPairKernel G (fun a b => ENNReal.ofReal (J a b)) L x y ω ∂law p) ≤ + ENNReal.ofReal (M*(L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p))) := + smallPairKernel_lintegral_le_of_finite G hloc J hJ L x y p hx hy _ (fun Q => + finiteSmallPairKernel_moment_bound G Q J hJ x y p L M α hL hM hα0 hα1 hx hI hs hb) + +end SmallKernelFatou +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal ComplexOrder +section SmallTwoPointKernel +attribute [local instance] Classical.propDecidable Classical.decEq +attribute [local instance] spectralRealOperatorScalarTower spectralRealOperatorSMulCommClass +local instance : NonUnitalContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +local instance : ContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) + +theorem matrixCoeff_positive_trace_norm {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : KernelInvariant Γ A) (hpos : 0 ≤ A) (x y : V) : + ‖matrixCoeff A x y‖ ≤ c*(rootTrace root weight A).re := by + have hd (z : V) : (matrixCoeff A z z).re ≤ c*(rootTrace root weight A).re := by + have h := (Complex.le_def.mp (rootTrace_diag_le root weight hcov hw c hc hmin A hA hpos z)).1 + simpa only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] using h + have hn (z : V) : 0 ≤ (matrixCoeff A z z).re := (Complex.nonneg_iff.mp (matrixCoeff_nonneg A hpos z)).1 + have hC : 0 ≤ c*(rootTrace root weight A).re := mul_nonneg hc + (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw A hpos)).1 + have hs := matrixCoeff_positive_product_norm_sq_le A 1 hpos x y + simp only [one_mul,star_one,mul_one] at hs + have hp := mul_le_mul (hd x) (hd y) (hn y) hC + nlinarith [norm_nonneg (matrixCoeff A x y)] + +theorem smallPairKernel_twoPoint_bound [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (x y : V) (p : unitInterval) (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (L α : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (hy : ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (hI : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) : + (∫⁻ ω, smallPairKernel G (ennMatrixCoeff (T^2)) L x y ω ∂law p) ≤ + ENNReal.ofReal ((c*(rootTrace root weight (T^3)).re)* + (L^(1-α)*(∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p))) := by + have hp := hT.positiveRealMatrix G p T + have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) + have hp3 := CStarAlgebra.pow_nonneg T 3 hpos + have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + have hM : 0 ≤ c*(rootTrace root weight (T^3)).re := mul_nonneg hc + (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw _ hp3)).1 + have he (b : V) : (matrixCoeff T b y).re = twoPoint G p y b := by + change (T (lp.single 2 y (1:ℂ)) b).re = _ + rw [hT b y,Complex.ofReal_re,twoPoint_symm G p b y] + have hs (a : V) : HasSum (fun b => (matrixCoeff (T^2) a b).re * twoPoint G p y b) + (matrixCoeff (T^3) a y).re := by + simpa only [he,←pow_succ] using (hp.pow 2).mul_hasSum T a y + apply smallPairKernel_moment_bound G hloc (fun a b => (matrixCoeff (T^2) a b).re) + (fun a b => ((hp.pow 2) a b).2) x y p L _ α hL hM hα0 hα1 hx hy hI + (fun a => (hs a).summable) + intro a + rw [(hs a).tsum_eq] + exact (Complex.re_le_norm _).trans (matrixCoeff_positive_trace_norm root weight Γ hcov hw c hc hmin _ (hTI.pow 3) hp3 a y) + +end SmallTwoPointKernel +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section ContactSmallReroot +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_smallPairKernel [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (J : V → V → ℝ≥0∞) (L : ℝ) (x y : V) : + Measurable (smallPairKernel G J L x y) := by + exact (measurable_clusterPairKernel G J x y).ite + ((measurableSet_lt ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x)) + measurable_const).inter (measurableSet_conn G x y).compl) measurable_const + +theorem smallPairKernel_cluster_constant (G : BondGraph V E) (J : V → V → ℝ≥0∞) + (L : ℝ) (ω : Set E) (x y a b : V) (hxa : Conn G ω x a) (hyb : Conn G ω y b) : + smallPairKernel G J L x y ω = smallPairKernel G J L a b ω := by + have hc : Conn G ω x y ↔ Conn G ω a b := by + constructor + · intro h; exact conn_trans G ω (conn_symm G ω hxa) (conn_trans G ω h hyb) + · intro h; exact conn_trans G ω hxa (conn_trans G ω h (conn_symm G ω hyb)) + simp only [smallPairKernel,cluster_eq_of_conn G ω hxa,hc, + clusterPairKernel_cluster_constant G ω J x y a b hxa hyb] + +theorem smallPairKernel_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J (a x) (a y) = J x y) + (L : ℝ) (ω : Set E) (x y : V) : + smallPairKernel G J L x y (b ⁻¹' ω) = smallPairKernel G J L (a x) (a y) ω := by + simp only [smallPairKernel,cluster_ncard_covariant G hab,conn_aut_iff G hab, + clusterPairKernel_aut G hab J hJ] + +theorem smallPairKernel_distinct (G : BondGraph V E) (J : V → V → ℝ≥0∞) + (L : ℝ) (ω : Set E) (x y : V) : + (if ¬Conn G ω x y then smallPairKernel G J L x y ω else 0) = smallPairKernel G J L x y ω := by + by_cases h : Conn G ω x y + · simp only [smallPairKernel,h,not_true_eq_false,and_false,ite_false] + · exact ite_eq_left h + + +theorem contact_smallPairKernel_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) + (L : ℝ) (d : ℕ) (hd : ∀ x, degree G x ≤ d) (B : ℝ) + (hb : ∀ x y, (∫⁻ ω, smallPairKernel G J L x y ω ∂law p) ≤ ENNReal.ofReal B) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) ≤ + ENNReal.ofReal ((d:ℝ)*B) := by + have hj : ∀ a ∈ Γ, ∀ x y, indexedEdgeKernel G (a x) (a y) = indexedEdgeKernel G x y := by + intro a ha x y + obtain ⟨b,hab⟩ := hΓ ha + exact indexedEdgeKernel_aut G hab x y + rw [clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin + (indexedEdgeKernel G) hj (fun ω x y => smallPairKernel G J L x y ω) + (measurable_smallPairKernel G hloc J L) + (fun ω x y a b hxa hyb => smallPairKernel_cluster_constant G J L ω x y a b hxa hyb) + (fun a ha b hab ω x y => smallPairKernel_aut G hab J (hJ a ha) L ω x y)] + simp_rw [smallPairKernel_distinct] + have hr (x : V) : (∫⁻ ω, ∑' y, indexedEdgeKernel G x y * smallPairKernel G J L x y ω ∂law p) ≤ + ENNReal.ofReal ((d:ℝ)*B) := by + have hm (y : V) : Measurable (fun ω => indexedEdgeKernel G x y * smallPairKernel G J L x y ω) := + (measurable_const : Measurable (fun _ : Set E => indexedEdgeKernel G x y)).mul (measurable_smallPairKernel G hloc J L x y) + rw [lintegral_tsum (fun y => (hm y).aemeasurable)] + simp_rw [lintegral_const_mul _ (measurable_smallPairKernel G hloc J L x _)] + calc + _ ≤ ∑' y, indexedEdgeKernel G x y * ENNReal.ofReal B := ENNReal.tsum_le_tsum (fun y => mul_le_mul_right (hb x y) _) + _ = (degree G x:ℝ≥0∞)*ENNReal.ofReal B := by rw [ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc x] + _ ≤ (d:ℝ≥0∞)*ENNReal.ofReal B := mul_le_mul_left (by exact_mod_cast hd x) _ + _ = _ := by rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_natCast] + calc + _ ≤ ∑ i, ENNReal.ofReal (weight i)*ENNReal.ofReal ((d:ℝ)*B) := + Finset.sum_le_sum (fun i _ => mul_le_mul_right (hr (root i)) _) + _ = _ := by rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1,ENNReal.ofReal_one,one_mul] + +end ContactSmallReroot +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PairMeasure +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def clusterPairMeasure [MeasurableSpace V] + {ι : Type*} [MeasurableSpace ι] (G : BondGraph V E) (p : unitInterval) + (root : ι → V) (weight : ι → ℝ) : Measure (Set E × (ι × V)) := + ((law p).prod Measure.count).withDensity (fun t => ENNReal.ofReal (weight t.2.1) * + clusterPairMass G t.1 (fun _ _ => 1) (root t.2.1) t.2.2) + +theorem clusterPairFunctional_eq_lintegral [Countable V] [Countable E] + [MeasurableSpace V] [MeasurableSingletonClass V] + {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + (root : ι → V) (weight : ι → ℝ) + (F : Set E → V → V → ℝ≥0∞) (hF : ∀ x y, Measurable (fun ω => F ω x y)) : + clusterPairFunctional G p root weight F = + ∫⁻ t, F t.1 (root t.2.1) t.2.2 ∂clusterPairMeasure G p root weight := by + let d : Set E × (ι × V) → ℝ≥0∞ := fun t => ENNReal.ofReal (weight t.2.1) * + clusterPairMass G t.1 (fun _ _ => 1) (root t.2.1) t.2.2 + let f : Set E × (ι × V) → ℝ≥0∞ := fun t => F t.1 (root t.2.1) t.2.2 + have hd : Measurable d := by + apply measurable_from_prod_countable_left + intro q + exact (measurable_const : Measurable (fun _ : Set E => ENNReal.ofReal (weight q.1))).mul + (measurable_clusterPairMass G hloc (fun _ _ _ => 1) (fun _ _ => measurable_const) (root q.1) q.2) + have hf : Measurable f := measurable_from_prod_countable_left (fun q => hF (root q.1) q.2) + change _ = ∫⁻ t, f t ∂((law p).prod Measure.count).withDensity d + rw [lintegral_withDensity_eq_lintegral_mul _ hd hf,lintegral_prod _ ((hd.mul hf).aemeasurable)] + have he (ω : Set E) (i : ι) (y : V) : + (d*f) (ω,(i,y)) = ENNReal.ofReal (weight i)*clusterPairMass G ω (F ω) (root i) y := by + dsimp [d,f,clusterPairMass] + (split_ifs <;> simp only [mul_one,mul_zero,zero_mul]); ring + simp_rw [lintegral_count,ENNReal.tsum_prod',he,tsum_fintype] + have hm (i : ι) : Measurable (fun ω => ∑' y, ENNReal.ofReal (weight i)*clusterPairMass G ω (F ω) (root i) y) := + Measurable.tsum (fun y => measurable_const.mul (measurable_clusterPairMass G hloc F hF (root i) y)) + rw [lintegral_finsetSum _ (fun i _ => hm i)] + simp_rw [ENNReal.tsum_mul_left] + rw [clusterPairFunctional] + apply Finset.sum_congr rfl + intro i _ + rw [lintegral_const_mul _ (Measurable.tsum (fun y => measurable_clusterPairMass G hloc F hF (root i) y))] + congr 1 + apply lintegral_congr + intro ω + exact clusterPairDensity_eq_tsum G ω (F ω) (root i) + + + +theorem clusterPairFunctional_cauchy_schwarz [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (F H : Set E → V → V → ℝ≥0∞) + (hF : ∀ x y, Measurable (fun ω => F ω x y)) + (hH : ∀ x y, Measurable (fun ω => H ω x y)) : + clusterPairFunctional G p root weight (fun ω x y => F ω x y*H ω x y) ≤ + (clusterPairFunctional G p root weight (fun ω x y => (F ω x y)^2))^((1:ℝ)/2) * + (clusterPairFunctional G p root weight (fun ω x y => (H ω x y)^2))^((1:ℝ)/2) := by + let : MeasurableSpace V := ⊤ + let : MeasurableSingletonClass V := ⟨fun _ => trivial⟩ + let : MeasurableSpace ι := ⊤ + let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ + rw [clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => F ω x y*H ω x y) (fun x y => (hF x y).mul (hH x y)), + clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => (F ω x y)^2) (fun x y => (hF x y).pow_const 2), + clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => (H ω x y)^2) (fun x y => (hH x y).pow_const 2)] + have hf : Measurable (fun t : Set E × (ι × V) => F t.1 (root t.2.1) t.2.2) := + measurable_from_prod_countable_left (fun q => hF (root q.1) q.2) + have hh : Measurable (fun t : Set E × (ι × V) => H t.1 (root t.2.1) t.2.2) := + measurable_from_prod_countable_left (fun q => hH (root q.1) q.2) + simpa only [Pi.mul_apply,ENNReal.rpow_two] using + ENNReal.lintegral_mul_le_Lp_mul_Lq (clusterPairMeasure G p root weight) Real.HolderConjugate.two_two hf.aemeasurable hh.aemeasurable + +end PairMeasure +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Covariance.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Covariance.lean index 698a2f1207762b087b09ea269d993c4d9348adf7..96a53ae5b9012f619663864e74adc36edbcbef71 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Covariance.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Covariance.lean @@ -1,1192 +1,1192 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.EndpointMoments - -namespace OAI - -/-! Covariance for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteTraceCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -@[simp] theorem edgeFieldEquiv_symm_edgeFieldEquiv (b : E ≃ E) (ω : Set E) : - edgeFieldEquiv b.symm (edgeFieldEquiv b ω) = ω := by - ext e - simp only [edgeFieldEquiv_apply,Set.mem_preimage,Equiv.symm_symm,Equiv.symm_apply_apply] - -@[simp] theorem spliceStateEquiv_symm_spliceStateEquiv (b : E ≃ E) (s : SpliceState E) : - spliceStateEquiv b.symm (spliceStateEquiv b s) = s := by - apply Prod.ext - · exact edgeFieldEquiv_symm_edgeFieldEquiv b s.1 - · funext i - exact edgeFieldEquiv_symm_edgeFieldEquiv b (s.2 i) - -@[simp] theorem spliceCodeEquiv_symm_spliceCodeEquiv (b : E ≃ E) (c : List (ℕ × E)) : - spliceCodeEquiv b.symm (spliceCodeEquiv b c) = c := by - induction c with - | nil => rfl - | cons q c ih => - rcases q with ⟨i,e⟩ - simpa only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,Equiv.symm_apply_apply] using - congrArg (List.cons (i,e)) ih - -theorem spliceTrace_aut_map_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) - (ω ωf : Set E) (c : List (ℕ × E)) : - SpliceTrace G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j - (edgeFieldEquiv b ω) (spliceCodeEquiv b c) (edgeFieldEquiv b ωf) ↔ - SpliceTrace G x η y k j ω c ωf := by - constructor - · intro ht - have hh := ht.aut_map G (isAut_symm G hab) (a x) (fun i => edgeFieldEquiv b (η i)) - (fun i => a (y i)) k j (edgeFieldEquiv b ω) (edgeFieldEquiv b ωf) (spliceCodeEquiv b c) - simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_symm_edgeFieldEquiv, - spliceCodeEquiv_symm_spliceCodeEquiv] using hh - · exact SpliceTrace.aut_map G hab x η y k j ω ωf c - -theorem boundedTraceCodes_aut_map_iff (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (k : ℕ) (c : List (ℕ × E)) : - spliceCodeEquiv b c ∈ boundedTraceCodes Q' k ↔ c ∈ boundedTraceCodes Q k := by - simp only [mem_boundedTraceCodes,spliceCodeEquiv_apply,List.length_map] - apply and_congr_right - intro _ - constructor - · intro h q hq - have hh := h (q.1,b q.2) (List.mem_map.mpr ⟨q,hq,rfl⟩) - exact ⟨hh.1,hh.2.1,(hQ q.2).mpr hh.2.2⟩ - · intro h r hr - obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hr - exact ⟨(h q hq).1,(h q hq).2.1,(hQ q.2).mp (h q hq).2.2⟩ - -theorem finiteTraceCodes_aut_map_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (Q Q' : Finset E) (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω : Set E) (c : List (ℕ × E)) : - spliceCodeEquiv b c ∈ finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (η i)) - (fun i => a (y i)) k j (edgeFieldEquiv b ω) Q' ↔ - c ∈ finiteTraceCodes G x η y k j ω Q := by - rw [mem_finiteTraceCodes_iff,mem_finiteTraceCodes_iff,boundedTraceCodes_aut_map_iff b Q Q' hQ, - replaySplice_aut_map G hab,spliceTrace_aut_map_iff G hab] - - -def finiteTraceCodesEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (Q Q' : Finset E) (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω : Set E) : - ↥(finiteTraceCodes G x η y k j ω Q) ≃ - ↥(finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j - (edgeFieldEquiv b ω) Q') := - (spliceCodeEquiv b).subtypeEquiv (fun c => (finiteTraceCodes_aut_map_iff G hab Q Q' hQ x η y k j ω c).symm) - -end FiniteTraceCovariance - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteIndexCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -def finiteTraceIndexEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') - (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) : - FiniteTraceIndex G x k Q A y ≃ FiniteTraceIndex G (a x) k Q' A' y' := - Equiv.sigmaCongr ((spliceStateEquiv b).subtypeEquiv hA) (fun s => - (spliceCodeEquiv b).subtypeEquiv (fun c => by - have hy' : y' (spliceStateEquiv b s.val) = fun i => a (y s.val i) := funext (hy s.val) - change c ∈ finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q ↔ - spliceCodeEquiv b c ∈ finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (s.val.2 i)) - (y' (spliceStateEquiv b s.val)) k 0 (edgeFieldEquiv b s.val.1) Q' - rw [hy'] - exact (finiteTraceCodes_aut_map_iff G hab Q Q' hQ x s.val.2 (y s.val) k 0 s.val.1 c).symm)) - -namespace FiniteTraceIndexEquiv -variable (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') - (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) - -@[simp] theorem input (t : FiniteTraceIndex G x k Q A y) : - traceIndexInput G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = - spliceStateEquiv b (traceIndexInput G x k Q A y t) := rfl - -@[simp] theorem code (t : FiniteTraceIndex G x k Q A y) : - traceIndexCode G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = - spliceCodeEquiv b (traceIndexCode G x k Q A y t) := rfl - -@[simp] theorem output (t : FiniteTraceIndex G x k Q A y) : - traceIndexOutput G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = - spliceStateEquiv b (traceIndexOutput G x k Q A y t) := by - have hy' : y' (spliceStateEquiv b t.1.val) = fun i => a (y t.1.val i) := funext (hy t.1.val) - change runMasks (replayMasks G (a x) (fun i => edgeFieldEquiv b (t.1.val.2 i)) - (y' (spliceStateEquiv b t.1.val)) (spliceCodeEquiv b t.2.val) (edgeFieldEquiv b t.1.val.1)) - (spliceStateEquiv b t.1.val) = _ - rw [hy',replayMasks_aut_map G hab,runMasks_aut_map] - rfl - -@[simp] theorem mass (t : FiniteTraceIndex G x k Q A y) : - traceIndexMass G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = - traceIndexMass G x k Q A y t := by - unfold traceIndexMass - rw [output G hab x k Q Q' A A' hQ hA y y' hy t] - apply Finset.prod_congr rfl - intro i _ - have hy' : y' (spliceStateEquiv b t.1.val) = fun i => a (y t.1.val i) := funext (hy t.1.val) - change (traceContactCount G (fun j => edgeFieldEquiv b (t.1.val.2 j)) - (y' (spliceStateEquiv b t.1.val)) (edgeFieldEquiv b (traceIndexOutput G x k Q A y t).1) - (a x) (spliceCodeEquiv b t.2.val) (i.val+1):ℝ)⁻¹ = _ - rw [hy',traceContactCount_aut_map G hab] - -end FiniteTraceIndexEquiv - - - -theorem finiteForwardLoad_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') - (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) - (s : SpliceState E) : - finiteForwardLoad G (a x) k Q' A' y' (spliceStateEquiv b s) = finiteForwardLoad G x k Q A y s := by - unfold finiteForwardLoad finiteInverseLoad - rw [← (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy).sum_comp] - apply Finset.sum_congr rfl - intro t _ - rw [FiniteTraceIndexEquiv.output,FiniteTraceIndexEquiv.mass] - simp only [(spliceStateEquiv b).injective.eq_iff] - -end FiniteIndexCovariance - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteFieldCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finset_aut_eq_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') : Q' = Q.map b.toEmbedding := by - ext e - simpa only [Finset.mem_map_equiv,b.apply_symm_apply] using (hQ (b.symm e)).symm - -noncomputable def finiteFieldAutEquiv (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') : FiniteField Q ≃ FiniteField Q' := - (Equiv.finsetCongr b).subtypeEquiv (fun ω => by - simp only [Finset.mem_powerset] - change ω ⊆ Q ↔ ω.map b.toEmbedding ⊆ Q' - rw [finset_aut_eq_map b Q Q' hQ,Finset.map_subset_map]) - -@[simp] theorem finiteFieldSet_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : FiniteField Q) : - finiteFieldSet Q' (finiteFieldAutEquiv b Q Q' hQ ω) = edgeFieldEquiv b (finiteFieldSet Q ω) := by - change (ω.val.map b.toEmbedding : Set E) = b.symm ⁻¹' (ω.val : Set E) - rw [Finset.coe_map] - exact b.image_eq_preimage_symm _ - -@[simp] theorem finiteFieldWeight_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (p : ℝ) (ω : FiniteField Q) : - finiteFieldWeight Q' p (finiteFieldAutEquiv b Q Q' hQ ω) = finiteFieldWeight Q p ω := by - change p^(ω.val.map b.toEmbedding).card * (1-p)^(Q'.card-(ω.val.map b.toEmbedding).card) = _ - simp only [Finset.card_map,finset_aut_eq_map b Q Q' hQ] - rfl - -noncomputable def finiteFamilyEquiv (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) : - (↥J → FiniteField Q) ≃ (↥J → FiniteField Q') := - Equiv.piCongrRight fun _ => finiteFieldAutEquiv b Q Q' hQ - -@[simp] theorem finiteFieldFamily_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (η : ↥J → FiniteField Q) (i : ℕ) : - finiteFieldFamily Q' J (finiteFamilyEquiv b Q Q' hQ J η) i = - edgeFieldEquiv b (finiteFieldFamily Q J η i) := by - unfold finiteFieldFamily - split_ifs with hi - · exact finiteFieldSet_aut_map b Q Q' hQ (η ⟨i,hi⟩) - · rfl - -@[simp] theorem finiteFamilyWeight_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (p : ℝ) (η : ↥J → FiniteField Q) : - finiteFamilyWeight Q' J p (finiteFamilyEquiv b Q Q' hQ J η) = finiteFamilyWeight Q J p η := by - apply Finset.prod_congr rfl - intro i _ - exact finiteFieldWeight_aut_map b Q Q' hQ p (η i) - -@[simp] theorem restrictFiniteField_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : Set E) : - restrictFiniteField Q' (edgeFieldEquiv b ω) = finiteFieldAutEquiv b Q Q' hQ (restrictFiniteField Q ω) := by - apply finiteFieldSet_injective Q' - rw [finiteFieldSet_aut_map,finiteFieldSet_restrict,finiteFieldSet_restrict] - ext e - change (b.symm e ∈ ω ∧ e ∈ Q') ↔ (b.symm e ∈ ω ∧ b.symm e ∈ Q) - rw [hQ (b.symm e),b.apply_symm_apply] - - - -theorem finiteRootLoad_aut_map (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (p : ℝ) - (f f' : SpliceState E → ℝ) (hf : ∀ s, f' (spliceStateEquiv b s) = f s) - (ω : FiniteField Q) : - finiteRootLoad Q' J p f' (finiteFieldAutEquiv b Q Q' hQ ω) = finiteRootLoad Q J p f ω := by - unfold finiteRootLoad - rw [← (finiteFamilyEquiv b Q Q' hQ J).sum_comp] - apply Finset.sum_congr rfl - intro η _ - rw [finiteFamilyWeight_aut_map,finiteFieldSet_aut_map] - have he : finiteFieldFamily Q' J (finiteFamilyEquiv b Q Q' hQ J η) = - fun i => edgeFieldEquiv b (finiteFieldFamily Q J η i) := - funext (finiteFieldFamily_aut_map b Q Q' hQ J η) - rw [he] - exact congrArg (fun t => finiteFamilyWeight Q J p η * t) - (hf (finiteFieldSet Q ω,finiteFieldFamily Q J η)) - -end FiniteFieldCovariance - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section ChoiceIndexCovariance -attribute [local instance] Classical.propDecidable Classical.decEq -variable {P P' : Type*} - -def finiteChoiceTraceIndexEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') - (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) - (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) - (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) - (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) : - FiniteChoiceTraceIndex G x k Q A y ≃ FiniteChoiceTraceIndex G (a x) k Q' A' y' := - Equiv.sigmaCongr e (fun r => finiteTraceIndexEquiv G hab x k Q Q' (A r) (A' (e r)) hQ (hA r) - (y r) (y' (e r)) (hy r)) - -namespace FiniteChoiceTraceIndexEquiv -variable (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') - (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) - (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) - (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) - (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) - -@[simp] theorem input (t : FiniteChoiceTraceIndex G x k Q A y) : - choiceTraceInput G (a x) k Q' A' y' (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = - spliceStateEquiv b (choiceTraceInput G x k Q A y t) := rfl - -@[simp] theorem output (t : FiniteChoiceTraceIndex G x k Q A y) : - choiceTraceOutput G (a x) k Q' A' y' (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = - spliceStateEquiv b (choiceTraceOutput G x k Q A y t) := - FiniteTraceIndexEquiv.output G hab x k Q Q' (A t.1) (A' (e t.1)) hQ (hA t.1) - (y t.1) (y' (e t.1)) (hy t.1) t.2 - -@[simp] theorem mass (q : SpliceState E → P → ℝ) (q' : SpliceState E → P' → ℝ) - (hq : ∀ s r, q' (spliceStateEquiv b s) (e r) = q s r) - (t : FiniteChoiceTraceIndex G x k Q A y) : - choiceTraceMass G (a x) k Q' A' y' q' - (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = - choiceTraceMass G x k Q A y q t := by - unfold choiceTraceMass - rw [input G hab x k Q Q' hQ e A A' hA y y' hy] - change q' (spliceStateEquiv b (choiceTraceInput G x k Q A y t)) (e t.1) * _ = _ - rw [hq] - exact congrArg (fun m => q (choiceTraceInput G x k Q A y t) t.1 * m) - (FiniteTraceIndexEquiv.mass G hab x k Q Q' (A t.1) (A' (e t.1)) hQ (hA t.1) - (y t.1) (y' (e t.1)) (hy t.1) t.2) - -end FiniteChoiceTraceIndexEquiv - -theorem finiteChoiceForwardLoad_aut_map [Fintype P] [Fintype P'] - (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') - (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) - (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) - (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) - (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) - (q : SpliceState E → P → ℝ) (q' : SpliceState E → P' → ℝ) - (hq : ∀ s r, q' (spliceStateEquiv b s) (e r) = q s r) (s : SpliceState E) : - finiteChoiceForwardLoad G (a x) k Q' A' y' q' (spliceStateEquiv b s) = - finiteChoiceForwardLoad G x k Q A y q s := by - unfold finiteChoiceForwardLoad finiteInverseLoad - rw [← (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy).sum_comp] - apply Finset.sum_congr rfl - intro t _ - rw [FiniteChoiceTraceIndexEquiv.output,FiniteChoiceTraceIndexEquiv.mass G hab x k Q Q' hQ e A A' hA y y' hy q q' hq] - simp only [(spliceStateEquiv b).injective.eq_iff] - -end ChoiceIndexCovariance - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AmplificationCovarianceInput -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem edgeField_subset_aut_iff (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : Set E) : - edgeFieldEquiv b ω ⊆ (Q' : Set E) ↔ ω ⊆ (Q : Set E) := by - constructor - · intro h e he - exact (hQ e).mpr (h (by simpa using he : b e ∈ edgeFieldEquiv b ω)) - · intro h e he - have hh := (hQ (b.symm e)).mp (h he) - simpa only [b.apply_symm_apply,Finset.mem_coe] using hh - -theorem finiteSpliceDomain_aut_map_iff (b : E ≃ E) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (s : SpliceState E) : - spliceStateEquiv b s ∈ finiteSpliceDomain Q' J ↔ s ∈ finiteSpliceDomain Q J := by - rw [mem_finiteSpliceDomain_iff,mem_finiteSpliceDomain_iff] - change (edgeFieldEquiv b s.1 ⊆ (Q':Set E) ∧ - (∀ i,edgeFieldEquiv b (s.2 i) ⊆ (Q':Set E)) ∧ ∀ i ∉ J,edgeFieldEquiv b (s.2 i)=∅) ↔ _ - have hz (η : Set E) : edgeFieldEquiv b η = ∅ ↔ η = ∅ := by - change edgeFieldEquiv b η = edgeFieldEquiv b ∅ ↔ _ - exact (edgeFieldEquiv b).injective.eq_iff - simp only [edgeField_subset_aut_iff b Q Q' hQ,hz] - -theorem oldRunVertices_map {W W' : Type*} (f : W → W') (k : ℕ) (z : W) - (r : Fin k → W) (i : ℕ) : - oldRunVertices k (f z) (fun j => f (r j)) i = f (oldRunVertices k z r i) := by - induction k generalizing z with - | zero => rfl - | succ k ih => - simp only [oldRunVertices] - split_ifs with hi - · exact ih (r 0) (Fin.tail r) - · rfl - -theorem oldRunWeight_map {W W' : Type*} (f : W → W') - (K : ℕ → W → W → ℝ) (K' : ℕ → W' → W' → ℝ) - (hK : ∀ i a b, K' i (f a) (f b) = K i a b) (k : ℕ) (z : W) (r : Fin k → W) : - oldRunWeight K' k (f z) (fun i => f (r i)) = oldRunWeight K k z r := by - induction k generalizing z with - | zero => rfl - | succ k ih => - simp only [oldRunWeight,hK] - rw [show Fin.tail (fun i => f (r i)) = (fun i => f (Fin.tail r i)) from rfl,ih] - -def finiteVertexEquiv (a : V ≃ V) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') : ↥B ≃ ↥B' := - a.subtypeEquiv hB - -def finiteRunEquiv (a : V ≃ V) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') (k : ℕ) : - (Fin k → ↥B) ≃ (Fin k → ↥B') := - Equiv.piCongrRight fun _ => finiteVertexEquiv a B B' hB - -theorem amplificationVertices_aut_map (a : V ≃ V) (B B' : Finset V) - (hB : ∀ x, x ∈ B ↔ a x ∈ B') (k : ℕ) (z : ↥B) (r : Fin k → ↥B) (i : ℕ) : - amplificationVertices B' k (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) i = - a (amplificationVertices B k z r i) := - congrArg Subtype.val (oldRunVertices_map (finiteVertexEquiv a B B' hB) k z r i) - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -theorem mass_aut_map (q : LocalEndpointRule G hloc O M L) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) : - q.mass (edgeFieldEquiv b ω) (a x) (a y) = q.mass ω x y := by - simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_apply] using - q.covariance a.symm b.symm (isAut_symm G hab) ω (a x) (a y) - -theorem amplificationWeight_aut_map (q : LocalEndpointRule G hloc O M L) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') - (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : - q.amplificationWeight B' k (finiteVertexEquiv a B B' hB z) (spliceStateEquiv b s) - (finiteRunEquiv a B B' hB k r) = q.amplificationWeight B k z s r := by - apply oldRunWeight_map (finiteVertexEquiv a B B' hB) - intro i v w - exact q.mass_aut_map hab (s.2 i) v.val w.val - -theorem amplificationInputs_aut_map_iff (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') - (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) : - spliceStateEquiv b s ∈ q.amplificationInputs Q' B' (a x) k n - (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) ↔ - s ∈ q.amplificationInputs Q B x k n z r := by - rw [q.mem_amplificationInputs,q.mem_amplificationInputs] - have hn : (cluster G (edgeFieldEquiv b s.1) (a x)).ncard = (cluster G s.1 x).ncard := by - rw [cluster_edgeFieldEquiv G hab,← a.image_eq_preimage_symm,Set.ncard_image_of_injective _ a.injective] - change (spliceStateEquiv b s ∈ finiteSpliceDomain Q' (Finset.Icc 1 k) ∧ - a x ∈ vertexOrbit G o ∧ a z.val ∈ vertexOrbit G o ∧ - n ≤ (cluster G (edgeFieldEquiv b s.1) (a x)).ncard ∧ - (cluster G (edgeFieldEquiv b s.1) (a x)).ncard < 2*n ∧ - amplificationVertices B' k (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) 0 ∈ - cluster G (edgeFieldEquiv b s.1) (a x) ∧ _) ↔ _ - rw [finiteSpliceDomain_aut_map_iff b Q Q' hQ,mem_vertexOrbit_aut_iff G o hab, - mem_vertexOrbit_aut_iff G o hab,hn,amplificationVertices_aut_map, - cluster_edgeFieldEquiv G hab,q.amplificationWeight_aut_map hab B B' hB] - simp only [Set.mem_preimage,Equiv.symm_apply_apply] - -end LocalEndpointRule -end AmplificationCovarianceInput - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AmplificationCovarianceMarginal -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem amplificationMarginal_aut_map (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (Q Q' : Finset E) - (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') - (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : - q.amplificationMarginal Q' B' (a x) k n (finiteVertexEquiv a B B' hB z) p (edgeFieldEquiv b ω) = - q.amplificationMarginal Q B x k n z p ω := by - unfold amplificationMarginal - rw [restrictFiniteField_aut_map b Q Q' hQ] - apply finiteRootLoad_aut_map - intro s - apply finiteChoiceForwardLoad_aut_map G hab x k Q Q' hQ (finiteRunEquiv a B B' hB k) - · intro r s - exact (q.amplificationInputs_aut_map_iff o hab Q Q' hQ B B' hB x k n z r s).symm - · intro r s i - exact amplificationVertices_aut_map a B B' hB k z r i - · intro s r - exact q.amplificationWeight_aut_map hab B B' hB k z s r - -end LocalEndpointRule - -theorem mem_incidentSupport_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (B B' : Finset V) - (hB : ∀ x, x ∈ B ↔ a x ∈ B') (e : E) : - b e ∈ incidentSupport G hloc B' ↔ e ∈ incidentSupport G hloc B := by - rw [finset_aut_eq_map a B B' hB,incidentSupport_aut G hloc hab] - simp only [Finset.mem_map_equiv,Equiv.symm_apply_apply] - -theorem finiteBall_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) (R : ℕ) : - y ∈ (finite_reachBall hloc x R).toFinset ↔ a y ∈ (finite_reachBall hloc (a x) R).toFinset := by - simpa only [Set.Finite.mem_toFinset] using (mem_reachBall_aut_iff G hab x y R).symm - -theorem localBondBall_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (R : ℕ) (e : E) : - e ∈ incidentSupport G hloc (finite_reachBall hloc x R).toFinset ↔ - b e ∈ incidentSupport G hloc (finite_reachBall hloc (a x) R).toFinset := - (mem_incidentSupport_aut_iff G hloc hab _ _ (fun y => finiteBall_aut_iff G hloc hab x y R) e).symm - -end AmplificationCovarianceMarginal - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section CanonicalAmplificationLoad -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -def amplificationRadius (q : LocalEndpointRule G hloc O M L) (k n : ℕ) : ℕ := - 2*n+k*M+max q.radius M - -noncomputable def amplificationBall (_q : LocalEndpointRule G hloc O M L) (k n : ℕ) (x : V) : Finset V := - (finite_reachBall hloc x (2*n+k*M)).toFinset - -noncomputable def amplificationBonds (q : LocalEndpointRule G hloc O M L) (k n : ℕ) (x : V) : Finset E := - incidentSupport G hloc (finite_reachBall hloc x (q.amplificationRadius k n)).toFinset - - - -noncomputable def amplifiedMass (q : LocalEndpointRule G hloc O M L) (k n : ℕ) (p : unitInterval) - (ω : Set E) (x z : V) : ℝ := - if hz : z ∈ q.amplificationBall k n x then - q.amplificationMarginal (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω / n - else 0 - -theorem amplifiedMass_nonneg (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) - (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) : 0 ≤ q.amplifiedMass k n p ω x z := by - unfold amplifiedMass - split_ifs - · exact div_nonneg (q.amplificationMarginal_bounds hL _ _ _ _ _ _ _ _).1 (Nat.cast_nonneg _) - · exact le_rfl - -theorem amplifiedMass_support (q : LocalEndpointRule G hloc O M L) - (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) (h : q.amplifiedMass k n p ω x z ≠ 0) : - x ∈ O ∧ z ∈ O ∧ Conn G ω x z ∧ (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ 2*n+k*M := by - unfold amplifiedMass at h - split_ifs at h with hz - · apply q.amplificationMarginal_physical_support (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω - · exact incidentSupport_ball_mono G hloc x (Nat.le_add_right (2*n+k*M) (max q.radius M)) - · intro he - exact h (by rw [he,zero_div]) - · exact (h rfl).elim - -theorem amplifiedMass_local (q : LocalEndpointRule G hloc O M L) - (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) : - q.amplifiedMass k n p ω x z = - q.amplifiedMass k n p (ω ∩ (q.amplificationBonds k n x : Set E)) x z := by - unfold amplifiedMass - split_ifs - · exact congrArg (fun t : ℝ => t / n) (q.amplificationMarginal_local _ _ _ _ _ _ _ _) - · rfl - -theorem amplifiedMass_aut_map (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (k n : ℕ) (p : unitInterval) - (ω : Set E) (x z : V) : - q.amplifiedMass k n p (edgeFieldEquiv b ω) (a x) (a z) = q.amplifiedMass k n p ω x z := by - have hB (y : V) : y ∈ q.amplificationBall k n x ↔ a y ∈ q.amplificationBall k n (a x) := - finiteBall_aut_iff G hloc hab x y (2*n+k*M) - have hQ (e : E) : e ∈ q.amplificationBonds k n x ↔ b e ∈ q.amplificationBonds k n (a x) := - localBondBall_aut_iff G hloc hab x (q.amplificationRadius k n) e - unfold amplifiedMass - by_cases hz : z ∈ q.amplificationBall k n x - · simp only [dite_eq_left hz,dite_eq_left ((hB z).mp hz)] - exact congrArg (fun t : ℝ => t / n) - (q.amplificationMarginal_aut_map o hab _ _ hQ _ _ hB x k n ⟨z,hz⟩ p ω) - · simp only [dite_eq_right hz,dite_eq_right (mt (hB z).mpr hz)] - - - -noncomputable def amplificationLoad (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) : - CappedLocalLoad G hloc (vertexOrbit G o) (2*n+k*M) where - mass := q.amplifiedMass k n p - radius := q.amplificationRadius k n - nonneg := q.amplifiedMass_nonneg hL k n p - support := q.amplifiedMass_support k n p - locality := q.amplifiedMass_local k n p - covariance := by - intro a b hab ω x z - simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_apply,Equiv.symm_symm] using - q.amplifiedMass_aut_map o (isAut_symm G hab) k n p ω (a x) (a z) - -end LocalEndpointRule -end CanonicalAmplificationLoad - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section CanonicalAmplificationRow -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem amplificationBonds_query {O : Set V} (q : LocalEndpointRule G hloc O M L) - (k n : ℕ) (x a : V) (ha : a ∈ q.amplificationBall k n x) : - incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ - q.amplificationBonds k n x := by - apply incidentSupport_mono - intro y hy - simp only [Set.Finite.mem_toFinset] at hy ⊢ - exact reachBall_triangle G x a (2*n+k*M) (max q.radius M) - (by simpa only [amplificationBall,Set.Finite.mem_toFinset] using ha) hy - -theorem amplificationBonds_root {O : Set V} (q : LocalEndpointRule G hloc O M L) - (k n : ℕ) (x : V) : - incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ - q.amplificationBonds k n x := by - apply incidentSupport_ball_mono - unfold amplificationRadius - omega - -theorem amplificationLoad_row (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (ω : Set E) (x : V) : - (q.amplificationLoad o hL k n p).row ω x = - q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p ω / n := by - change (∑' z, q.amplifiedMass k n p ω x z) = _ - rw [tsum_eq_sum (s := q.amplificationBall k n x) (fun z hz => by - simp only [amplifiedMass,dite_eq_right hz])] - rw [← Finset.sum_coe_sort] - simp only [amplifiedMass,dite_eq_left (Subtype.prop _)] - exact (Finset.sum_div _ _ _).symm - -theorem amplificationRow_local {O : Set V} (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : - q.amplificationRow Q B x k n p ω = q.amplificationRow Q B x k n p (ω ∩ (Q : Set E)) := by - unfold amplificationRow - apply Finset.sum_congr rfl - intro z _ - exact q.amplificationMarginal_local Q B x k n z p ω - -theorem amplificationLoad_mean_finite (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (x : V) : - (∫ ω, (q.amplificationLoad o hL k n p).row ω x ∂law p) = - finiteFieldIntegral (q.amplificationBonds k n x) p - (q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p) / n := by - simp_rw [q.amplificationLoad_row o hL k n p] - rw [integral_div] - congr 1 - exact integral_finite_local _ p _ (q.amplificationRow_local _ _ x k n p) - -theorem amplificationLoad_second_moment_finite (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (x : V) : - (∫ ω, (q.amplificationLoad o hL k n p).row ω x ^ 2 ∂law p) = - finiteFieldIntegral (q.amplificationBonds k n x) p (fun ω => - q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p ω ^ 2) / (n:ℝ)^2 := by - simp_rw [q.amplificationLoad_row o hL k n p,div_pow] - rw [integral_div] - congr 1 - exact integral_finite_local _ p _ (fun ω => congrArg (·^2) (q.amplificationRow_local _ _ x k n p ω)) - -end LocalEndpointRule -end CanonicalAmplificationRow - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section NormalizedAmplificationMoment -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem amplificationLoad_second_moment_le [Nonempty E] (hconn : Connected G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (x : V) (k n d : ℕ) (hn : 0 < n) - (hdeg : ∀ a, degree G a ≤ d) : - (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ^ 2 ∂law p) ≤ - (4 * q.successProbability p (root i₀)^k + - (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L^k / n) * - (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ∂law p) + - (2 * (c*((k*M:ℕ)*q.successProbability p (root i₀)^k)))^2 * - finiteClusterWindowMass G (q.amplificationBonds k n x) p x (n-k*M) (2*n) := by - rw [q.amplificationLoad_second_moment_finite,q.amplificationLoad_mean_finite] - have h := q.amplificationRow_second_moment_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin - i₀ hw₀ hL (q.amplificationBonds k n x) (q.amplificationBall k n x) p x k n d hdeg - (fun a ha => q.amplificationBonds_query k n x a ha) - have hn' : (n:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr hn) - apply (div_le_div_of_nonneg_right h (sq_nonneg (n:ℝ))).trans_eq - push_cast - field_simp - -end LocalEndpointRule -end NormalizedAmplificationMoment - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FinitePathExhaustion -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finitePathTest (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (k : ℕ) (z : ↥B) : ℝ := - ∑ r : Fin k → ↥B, oldRunWeight (fun _ a b => K a.val b.val) k z r * F (oldRunVertices k z r 0).val - -@[simp] theorem finitePathTest_zero (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (z : ↥B) : - finitePathTest B K F 0 z = F z.val := by - simp [finitePathTest,oldRunWeight,oldRunVertices] - -theorem finitePathTest_succ (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (k : ℕ) (z : ↥B) : - finitePathTest B K F (k+1) z = ∑ a : ↥B, K z.val a.val * finitePathTest B K F k a := - oldRun_test_succ (fun _ (a b : ↥B) => K a.val b.val) (fun (a : ↥B) => F a.val) k z - - - -theorem finitePathTest_support (G : BondGraph V E) (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) - (O : Set V) (x : V) (R M : ℕ) - (hK : ∀ a b, K a b ≠ 0 → a ∈ O ∧ a ∈ reachBall G b M) - (hF : ∀ a, F a ≠ 0 → a ∈ O ∧ a ∈ reachBall G x R) - (k : ℕ) (z : ↥B) (hz : finitePathTest B K F k z ≠ 0) : - z.val ∈ O ∧ z.val ∈ reachBall G x (R+k*M) := by - induction k generalizing z with - | zero => simpa using hF z.val (by simpa using hz) - | succ k ih => - rw [finitePathTest_succ] at hz - obtain ⟨a,_,ha⟩ := Finset.exists_ne_zero_of_sum_ne_zero hz - have hh := mul_ne_zero_iff.mp ha - obtain ⟨haO,haB⟩ := ih a hh.2 - obtain ⟨hzO,hzB⟩ := hK z.val a.val hh.1 - refine ⟨hzO,?_⟩ - have hg := reachBall_triangle G x a.val (R+k*M) M haB hzB - simpa only [Nat.add_mul,one_mul,Nat.add_assoc] using hg - - - -theorem finitePathTest_total (G : BondGraph V E) (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) - (O : Set V) (x : V) (R M N : ℕ) (u : ℝ) - (hK : ∀ a b, K a b ≠ 0 → a ∈ O ∧ a ∈ reachBall G b M) - (hF : ∀ a, F a ≠ 0 → a ∈ O ∧ a ∈ reachBall G x R) - (hcolumn : ∀ j < N, ∀ a : ↥B, a.val ∈ O → a.val ∈ reachBall G x (R+j*M) → - ∑ z : ↥B, K z.val a.val = u) : - ∀ j ≤ N, (∑ z : ↥B, finitePathTest B K F j z) = u^j * ∑ z : ↥B, F z.val := by - intro j hj - induction j with - | zero => simp - | succ j ih => - simp_rw [finitePathTest_succ] - rw [Finset.sum_comm] - have he : (∑ a : ↥B, ∑ z : ↥B, K z.val a.val * finitePathTest B K F j a) = - u * ∑ a : ↥B, finitePathTest B K F j a := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - rw [← Finset.sum_mul] - by_cases ha : finitePathTest B K F j a = 0 - · simp only [ha,mul_zero] - · obtain ⟨haO,haB⟩ := finitePathTest_support G B K F O x R M hK hF j a ha - rw [hcolumn j (by omega) a haO haB] - rw [he,ih (by omega)] - ring - -end FinitePathExhaustion - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section AmplificationBoundaryExhaustion -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem kernel_range_support {O : Set V} (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (a b : V) (h : q.kernel p a b ≠ 0) : a ∈ O ∧ a ∈ reachBall G b M := by - constructor - · by_contra ha - exact h (q.kernel_zero_of_start_not_mem p a b ha) - · by_contra ha - exact h (q.kernel_outside_reverse_ball_zero p a b ha) - -theorem orbitBinConnection_range_support (o : V) (p : unitInterval) (n : ℕ) (x a : V) - (h : orbitBinConnection G p o n x a ≠ 0) : - a ∈ vertexOrbit G o ∧ a ∈ reachBall G x (2*n) := by - have ha : a ∈ vertexOrbit G o := by - by_contra ha - exact h (by simp only [orbitBinConnection,ha,and_false,ite_false]) - refine ⟨ha,?_⟩ - by_contra hb - exact h (by simp only [orbitBinConnection,binConnection_outside G p n x a hb,ite_self]) - -theorem amplificationBall_column {O : Set V} (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (k n j : ℕ) (hj : j < k) (x a : V) - (ha : a ∈ reachBall G x (2*n+j*M)) : - (∑ z : ↥(q.amplificationBall k n x), q.kernel p z.val a) = ∑' z, q.kernel p z a := by - rw [Finset.sum_coe_sort (q.amplificationBall k n x) (fun z => q.kernel p z a)] - symm - apply tsum_eq_sum - intro z hz - apply q.kernel_outside_reverse_ball_zero - intro hza - have hh := reachBall_triangle G x a (2*n+j*M) M ha hza - have hle : (2*n+j*M)+M ≤ 2*n+k*M := by - calc - _ = 2*n+(j+1)*M := by ring - _ ≤ _ := Nat.add_le_add_left (Nat.mul_le_mul_right M (by omega)) _ - exact hz (by - simpa only [amplificationBall,Set.Finite.mem_toFinset] using (reachBall_mono G x hle hh)) - -theorem amplificationPath_total {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (p : unitInterval) (k n : ℕ) (x : V) (hx : x ∈ vertexOrbit G (root i₀)) : - (∑ z : ↥(q.amplificationBall k n x), - finitePathTest (q.amplificationBall k n x) (q.kernel p) (orbitBinConnection G p (root i₀) n x) k z) = - q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n := by - have ht := finitePathTest_total G (q.amplificationBall k n x) (q.kernel p) - (orbitBinConnection G p (root i₀) n x) (vertexOrbit G (root i₀)) x (2*n) M k - (q.successProbability p (root i₀)) (q.kernel_range_support p) - (orbitBinConnection_range_support (root i₀) p n x) (by - intro j hj a haO haB - rw [q.amplificationBall_column p k n j hj x a.val haB] - exact q.kernel_column_eq_success root weight Γ htr hΓ hw i₀ hw₀ p a.val haO) k le_rfl - rw [ht] - congr 1 - rw [Finset.sum_coe_sort (q.amplificationBall k n x) (orbitBinConnection G p (root i₀) n x),← orbitBinConnection_row G hloc p (root i₀) n x hx] - symm - apply tsum_eq_sum - intro z hz - by_contra h - have hb := (orbitBinConnection_range_support (root i₀) p n x z h).2 - exact hz (by - simpa only [amplificationBall,Set.Finite.mem_toFinset] using - reachBall_mono G x (Nat.le_add_right (2*n) (k*M)) hb) - -end LocalEndpointRule -end AmplificationBoundaryExhaustion - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section AmplificationExactMean -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem amplificationMarginal_mean_pathTest [Nonempty E] (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) - (hx : x ∈ vertexOrbit G o) - (hroot : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) - (hquery : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : - (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = - finitePathTest B (q.kernel p) (orbitBinConnection G p o n x) k z := by - by_cases hz : z.val ∈ vertexOrbit G o - · rw [q.amplificationMarginal_mean_kernel Q B x k n z p hx hz hquery] - unfold finitePathTest - apply Finset.sum_congr rfl - intro r _ - rw [finiteBinConnection_eq_binConnection G hloc Q p x n _ hroot] - by_cases hr : oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r = 0 - · simp only [hr,mul_zero,zero_mul] - · have hy : (oldRunVertices k z r 0).val ∈ vertexOrbit G o := - oldRun_endpoint_mem (fun a : ↥B => a.val ∈ vertexOrbit G o) - (fun _ (a b : ↥B) => q.kernel p a.val b.val) - (fun _ a b hab => by - by_contra hb - exact hab (q.kernel_zero_of_end_not_mem p a.val b.val hb)) k z hz r hr - rw [orbitBinConnection,ite_eq_left ⟨hx,hy⟩] - exact mul_comm _ _ - · have hm (ω : Set E) : q.amplificationMarginal Q B x k n z p ω = 0 := by - by_contra h - exact hz (q.amplificationMarginal_support Q B x k n z p ω h).2.1 - simp_rw [hm,integral_zero] - symm - by_contra h - exact hz (finitePathTest_support G B (q.kernel p) (orbitBinConnection G p o n x) - (vertexOrbit G o) x (2*n) M (q.kernel_range_support p) - (orbitBinConnection_range_support o p n x) k z h).1 - - - -theorem amplificationLoad_mean [Nonempty E] {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (k n : ℕ) (x : V) (hx : x ∈ vertexOrbit G (root i₀)) : - (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ∂law p) = - q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n := by - simp_rw [q.amplificationLoad_row] - rw [integral_div] - congr 1 - unfold amplificationRow - rw [integral_finsetSum _ (fun z _ => integrable_finite_local _ p _ - (q.amplificationMarginal_local _ _ x k n z p))] - simp_rw [q.amplificationMarginal_mean_pathTest (root i₀) _ _ x k n _ p hx - (q.amplificationBonds_root k n x) (fun a ha => - (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (q.amplificationBonds_query k n x a ha))] - exact q.amplificationPath_total root weight Γ htr hΓ hw i₀ hw₀ p k n x hx - -end LocalEndpointRule -end AmplificationExactMean - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section AmplificationLoadOperator -attribute [local instance] Classical.propDecidable Classical.decEq -namespace CappedLocalLoad -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} - -noncomputable def kernel (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : ℝ := - ∫ ω, q.mass ω x y ∂law p - -theorem kernel_nonneg (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : - 0 ≤ q.kernel p x y := integral_nonneg (q.nonneg · x y) - -end CappedLocalLoad - - -theorem exists_operator_of_scaled_matrix (F : V → V → ℝ) (c C : ℝ) (hc : 0 < c) - (A : Hilbert V →L[ℂ] Hilbert V) (hAnorm : ‖A‖ ≤ C) - (hA : ∀ x y, matrixCoeff A x y = (c * F x y : ℂ)) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ C/c ∧ - ∀ x y, matrixCoeff T x y = (F x y : ℂ) := by - refine ⟨((c⁻¹:ℝ):ℂ) • A,?_,?_⟩ - · rw [norm_smul,Complex.norm_of_nonneg (inv_nonneg.mpr hc.le)] - simpa only [div_eq_mul_inv,mul_comm] using - mul_le_mul_of_nonneg_left hAnorm (inv_nonneg.mpr hc.le) - · intro x y - change ((c⁻¹:ℝ):ℂ)*matrixCoeff A x y = _ - rw [hA] - have hc' : (c:ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr hc.ne' - simp only [Complex.ofReal_inv] - field_simp - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem amplificationLoad_scaled_kernel [Nonempty E] (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hL : 1 ≤ L) - (k n : ℕ) (hn : 0 < n) (p : unitInterval) (x z : V) - (hz : z ∈ q.amplificationBall k n x) : - (n:ℝ) * (q.amplificationLoad o hL k n p).kernel p x z = - ∫ ω, q.amplificationMarginal (q.amplificationBonds k n x) (q.amplificationBall k n x) - x k n ⟨z,hz⟩ p ω ∂law p := by - change (n:ℝ) * (∫ ω, q.amplifiedMass k n p ω x z ∂law p) = _ - simp only [amplifiedMass,dite_eq_left hz,integral_div] - have hn' : (n:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr hn) - field_simp - - - -theorem amplificationLoad_exists_operator [Nonempty E] (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hL : 1 ≤ L) - (k n : ℕ) (hn : 0 < n) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ a b, matrixCoeff A a b = (q.kernel p a b : ℂ)) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ binOrbitRow G p o n * ‖A‖^k / n ∧ - ∀ x z, matrixCoeff T x z = ((q.amplificationLoad o hL k n p).kernel p x z : ℂ) := by - let F := (q.amplificationLoad o hL k n p).kernel p - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have hposA : PositiveRealMatrix A := fun x z => by - rw [hA] - exact ⟨rfl,q.kernel_nonneg p x z⟩ - obtain ⟨S,hSnorm,hS⟩ := exists_operator_of_amplification_domination G hloc p o n k A hposA - (fun x z => (n:ℝ)*F x z) (fun x z => mul_nonneg hn'.le ((q.amplificationLoad o hL k n p).kernel_nonneg p x z)) - (by - intro H hH x z - have hposH : PositiveRealMatrix H := fun a b => by - rw [hH] - exact ⟨rfl,orbitBinConnection_nonneg G p o n a b⟩ - have hpos := (((hposA.pow k).mul hposH) z x).2 - by_cases hz : z ∈ q.amplificationBall k n x - · rw [q.amplificationLoad_scaled_kernel o hL k n hn p x z hz] - by_cases ho : x ∈ vertexOrbit G o ∧ z ∈ vertexOrbit G o - · exact q.amplificationMarginal_operator_le o _ _ x k n ⟨z,hz⟩ p ho.1 ho.2 - (q.amplificationBonds_root k n x) (fun a ha => - (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (q.amplificationBonds_query k n x a ha)) A H hA hH - · have hm (ω : Set E) : q.amplificationMarginal (q.amplificationBonds k n x) - (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω = 0 := by - by_contra h - have hs := q.amplificationMarginal_support _ _ x k n ⟨z,hz⟩ p ω h - exact ho ⟨hs.1,hs.2.1⟩ - simpa only [hm,integral_zero] using hpos - · have he : F x z = 0 := by - change (∫ ω, q.amplifiedMass k n p ω x z ∂law p) = 0 - simp only [amplifiedMass,dite_eq_right hz,integral_zero] - simpa only [he,mul_zero] using hpos) - exact exists_operator_of_scaled_matrix F n _ hn' S hSnorm (by - intro x z - simpa only [Complex.ofReal_mul] using hS x z) - -end LocalEndpointRule -end AmplificationLoadOperator - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section TruncationOperator -attribute [local instance] Classical.propDecidable Classical.decEq -namespace CappedLocalLoad -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} - -theorem truncate_kernel_le (q : CappedLocalLoad G hloc O M) (p : unitInterval) - (b : ℝ) (hb : 0 < b) (L : ℝ) (x y : V) : - (q.truncate b hb L).kernel p x y ≤ b⁻¹ * q.kernel p x y := by - rw [kernel,← integral_const_mul] - exact integral_mono ((q.truncate b hb L).integrable_mass p x y) - ((q.integrable_mass p x y).const_mul b⁻¹) (q.truncate_mass_le b hb L · x y) - - - -theorem truncate_exists_operator (q : CappedLocalLoad G hloc O M) (p : unitInterval) - (b : ℝ) (hb : 0 < b) (L : ℝ) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.kernel p x y : ℂ)) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ ‖A‖/b ∧ - ∀ x y, matrixCoeff T x y = ((q.truncate b hb L).kernel p x y : ℂ) := by - have hscale (x y : V) : matrixCoeff (((b⁻¹:ℝ):ℂ) • A) x y = (b⁻¹ * q.kernel p x y : ℝ) := by - change ((b⁻¹:ℝ):ℂ)*matrixCoeff A x y = _ - rw [hA,Complex.ofReal_mul] - obtain ⟨T,hT,hK⟩ := exists_operator_of_matrix_domination - (fun x y => b⁻¹ * q.kernel p x y) ((q.truncate b hb L).kernel p) - (fun x y => mul_nonneg (inv_nonneg.mpr hb.le) (q.kernel_nonneg p x y)) - (fun x y => by - rw [abs_of_nonneg ((q.truncate b hb L).kernel_nonneg p x y)] - exact q.truncate_kernel_le p b hb L x y) - (((b⁻¹:ℝ):ℂ) • A) hscale - refine ⟨T,hT.trans_eq ?_,hK⟩ - rw [norm_smul,Complex.norm_of_nonneg (inv_nonneg.mpr hb.le)] - ring - -end CappedLocalLoad -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - -theorem normalize_mass_operator (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (hu : 0 < q.successProbability p o) - (A : Hilbert V →L[ℂ] Hilbert V) (C : ℝ) (hAnorm : ‖A‖ ≤ C) - (hA : ∀ x y, matrixCoeff A x y = (q.kernel p x y : ℂ)) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ C/q.successProbability p o ∧ - ∀ x y, matrixCoeff T x y = (q.normalizedKernel o p x y : ℂ) := by - apply exists_operator_of_scaled_matrix (q.normalizedKernel o p) (q.successProbability p o) C hu A hAnorm - intro x y - rw [hA] - simp only [normalizedKernel,← Complex.ofReal_mul] - congr 1 - rw [← mul_assoc,mul_inv_cancel₀ hu.ne',one_mul] - - - -theorem mass_operator_of_normalized (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (hu : 0 < q.successProbability p o) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : - ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ = q.successProbability p o * ‖A‖ ∧ - ∀ x y, matrixCoeff T x y = (q.kernel p x y : ℂ) := by - refine ⟨(q.successProbability p o : ℂ) • A,?_,?_⟩ - · rw [norm_smul,Complex.norm_of_nonneg hu.le] - · intro x y - change (q.successProbability p o : ℂ)*matrixCoeff A x y = _ - rw [hA] - simp only [normalizedKernel,← Complex.ofReal_mul] - congr 1 - rw [← mul_assoc,mul_inv_cancel₀ hu.ne',one_mul] - -end LocalEndpointRule -end TruncationOperator - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -open MeasureTheory -section AmplificationTruncationStep -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem normalized_operator_norm_pos (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (hu : 0 < q.successProbability p o) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : 0 < ‖A‖ := by - apply norm_pos_iff.mpr - intro ha - have hz (y : V) : q.kernel p o y = 0 := by - have he := hA o y - rw [ha] at he - have he' : (q.successProbability p o)⁻¹ * q.kernel p o y = 0 := - Complex.ofReal_eq_zero.mp he.symm - exact (mul_eq_zero.mp he').resolve_left (inv_ne_zero hu.ne') - have he : q.successProbability p o = 0 := by - simp only [successProbability,hz,tsum_zero] - exact hu.ne' he - - - -theorem amplification_truncation_step [Nonempty E] {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (k n : ℕ) (hn : 0 < n) - (hu : 0 < q.successProbability p (root i₀)) - (hbin : 0 < binOrbitRow G p (root i₀) n) - (b L' : ℝ) (hb : 0 < b) - (hmoment : (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p) / b ≤ - (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/4) - (hbad : b * (law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ - (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/4) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : - ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) (2*n+k*M) L', - (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/(2*b) ≤ - q'.successProbability p (root i₀) ∧ - ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ ‖A'‖ ≤ 2*‖A‖^k ∧ - ∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ) := by - let load := q.amplificationLoad (root i₀) hL k n p - let q' := load.truncate b hb L' - have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn - have hb₀ : 0 < q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n := - div_pos (mul_pos (pow_pos hu _) hbin) hn' - have hself : root i₀ ∈ vertexOrbit G (root i₀) := by - refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ - intro e - simp - have hmean := q.amplificationLoad_mean root weight Γ htr hΓ hw i₀ hw₀ hL p k n (root i₀) hself - have hnew := load.truncate_success_lower p b hb L' (root i₀) _ hmean.ge hmoment hbad - have hu' : 0 < q'.successProbability p (root i₀) := - (div_pos hb₀ (mul_pos (by norm_num) hb)).trans_le hnew - obtain ⟨B,hBnorm,hB⟩ := q.mass_operator_of_normalized (root i₀) p hu A hA - obtain ⟨C,hCnorm,hC⟩ := q.amplificationLoad_exists_operator (root i₀) hL k n hn p B hB - obtain ⟨D,hDnorm,hD⟩ := load.truncate_exists_operator p b hb L' C hC - have hD' : ‖D‖ ≤ (binOrbitRow G p (root i₀) n * (q.successProbability p (root i₀)*‖A‖)^k/n)/b := by - rw [hBnorm] at hCnorm - exact hDnorm.trans (div_le_div_of_nonneg_right hCnorm hb.le) - obtain ⟨A',hA'norm,hA'⟩ := q'.normalize_mass_operator (root i₀) p hu' D _ hD' hD - refine ⟨q',hnew,A',q'.normalized_operator_norm_pos (root i₀) p hu' A' hA',hA'norm.trans ?_,hA'⟩ - apply (div_le_iff₀ hu').mpr - apply (div_le_iff₀ hb).mpr - apply (div_le_iff₀ hn').mpr - have hret := (div_le_iff₀ (mul_pos (show (0:ℝ)<2 by norm_num) hb)).mp hnew - have hret' := (div_le_iff₀ hn').mp hret - rw [mul_pow] - calc - _ = (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n) * ‖A‖^k := by ring - _ ≤ (q'.successProbability p (root i₀)*(2*b)*n)*‖A‖^k := - mul_le_mul_of_nonneg_right hret' (pow_nonneg (norm_nonneg _) _) - _ = _ := by ring - -end LocalEndpointRule -end AmplificationTruncationStep - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.EndpointMoments + +namespace OAI + +/-! Covariance for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteTraceCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +@[simp] theorem edgeFieldEquiv_symm_edgeFieldEquiv (b : E ≃ E) (ω : Set E) : + edgeFieldEquiv b.symm (edgeFieldEquiv b ω) = ω := by + ext e + simp only [edgeFieldEquiv_apply,Set.mem_preimage,Equiv.symm_symm,Equiv.symm_apply_apply] + +@[simp] theorem spliceStateEquiv_symm_spliceStateEquiv (b : E ≃ E) (s : SpliceState E) : + spliceStateEquiv b.symm (spliceStateEquiv b s) = s := by + apply Prod.ext + · exact edgeFieldEquiv_symm_edgeFieldEquiv b s.1 + · funext i + exact edgeFieldEquiv_symm_edgeFieldEquiv b (s.2 i) + +@[simp] theorem spliceCodeEquiv_symm_spliceCodeEquiv (b : E ≃ E) (c : List (ℕ × E)) : + spliceCodeEquiv b.symm (spliceCodeEquiv b c) = c := by + induction c with + | nil => rfl + | cons q c ih => + rcases q with ⟨i,e⟩ + simpa only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,Equiv.symm_apply_apply] using + congrArg (List.cons (i,e)) ih + +theorem spliceTrace_aut_map_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) + (ω ωf : Set E) (c : List (ℕ × E)) : + SpliceTrace G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j + (edgeFieldEquiv b ω) (spliceCodeEquiv b c) (edgeFieldEquiv b ωf) ↔ + SpliceTrace G x η y k j ω c ωf := by + constructor + · intro ht + have hh := ht.aut_map G (isAut_symm G hab) (a x) (fun i => edgeFieldEquiv b (η i)) + (fun i => a (y i)) k j (edgeFieldEquiv b ω) (edgeFieldEquiv b ωf) (spliceCodeEquiv b c) + simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_symm_edgeFieldEquiv, + spliceCodeEquiv_symm_spliceCodeEquiv] using hh + · exact SpliceTrace.aut_map G hab x η y k j ω ωf c + +theorem boundedTraceCodes_aut_map_iff (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (k : ℕ) (c : List (ℕ × E)) : + spliceCodeEquiv b c ∈ boundedTraceCodes Q' k ↔ c ∈ boundedTraceCodes Q k := by + simp only [mem_boundedTraceCodes,spliceCodeEquiv_apply,List.length_map] + apply and_congr_right + intro _ + constructor + · intro h q hq + have hh := h (q.1,b q.2) (List.mem_map.mpr ⟨q,hq,rfl⟩) + exact ⟨hh.1,hh.2.1,(hQ q.2).mpr hh.2.2⟩ + · intro h r hr + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hr + exact ⟨(h q hq).1,(h q hq).2.1,(hQ q.2).mp (h q hq).2.2⟩ + +theorem finiteTraceCodes_aut_map_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (Q Q' : Finset E) (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω : Set E) (c : List (ℕ × E)) : + spliceCodeEquiv b c ∈ finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (η i)) + (fun i => a (y i)) k j (edgeFieldEquiv b ω) Q' ↔ + c ∈ finiteTraceCodes G x η y k j ω Q := by + rw [mem_finiteTraceCodes_iff,mem_finiteTraceCodes_iff,boundedTraceCodes_aut_map_iff b Q Q' hQ, + replaySplice_aut_map G hab,spliceTrace_aut_map_iff G hab] + + +def finiteTraceCodesEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (Q Q' : Finset E) (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω : Set E) : + ↥(finiteTraceCodes G x η y k j ω Q) ≃ + ↥(finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j + (edgeFieldEquiv b ω) Q') := + (spliceCodeEquiv b).subtypeEquiv (fun c => (finiteTraceCodes_aut_map_iff G hab Q Q' hQ x η y k j ω c).symm) + +end FiniteTraceCovariance + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteIndexCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +def finiteTraceIndexEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') + (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) : + FiniteTraceIndex G x k Q A y ≃ FiniteTraceIndex G (a x) k Q' A' y' := + Equiv.sigmaCongr ((spliceStateEquiv b).subtypeEquiv hA) (fun s => + (spliceCodeEquiv b).subtypeEquiv (fun c => by + have hy' : y' (spliceStateEquiv b s.val) = fun i => a (y s.val i) := funext (hy s.val) + change c ∈ finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q ↔ + spliceCodeEquiv b c ∈ finiteTraceCodes G (a x) (fun i => edgeFieldEquiv b (s.val.2 i)) + (y' (spliceStateEquiv b s.val)) k 0 (edgeFieldEquiv b s.val.1) Q' + rw [hy'] + exact (finiteTraceCodes_aut_map_iff G hab Q Q' hQ x s.val.2 (y s.val) k 0 s.val.1 c).symm)) + +namespace FiniteTraceIndexEquiv +variable (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') + (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) + +@[simp] theorem input (t : FiniteTraceIndex G x k Q A y) : + traceIndexInput G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = + spliceStateEquiv b (traceIndexInput G x k Q A y t) := rfl + +@[simp] theorem code (t : FiniteTraceIndex G x k Q A y) : + traceIndexCode G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = + spliceCodeEquiv b (traceIndexCode G x k Q A y t) := rfl + +@[simp] theorem output (t : FiniteTraceIndex G x k Q A y) : + traceIndexOutput G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = + spliceStateEquiv b (traceIndexOutput G x k Q A y t) := by + have hy' : y' (spliceStateEquiv b t.1.val) = fun i => a (y t.1.val i) := funext (hy t.1.val) + change runMasks (replayMasks G (a x) (fun i => edgeFieldEquiv b (t.1.val.2 i)) + (y' (spliceStateEquiv b t.1.val)) (spliceCodeEquiv b t.2.val) (edgeFieldEquiv b t.1.val.1)) + (spliceStateEquiv b t.1.val) = _ + rw [hy',replayMasks_aut_map G hab,runMasks_aut_map] + rfl + +@[simp] theorem mass (t : FiniteTraceIndex G x k Q A y) : + traceIndexMass G (a x) k Q' A' y' (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy t) = + traceIndexMass G x k Q A y t := by + unfold traceIndexMass + rw [output G hab x k Q Q' A A' hQ hA y y' hy t] + apply Finset.prod_congr rfl + intro i _ + have hy' : y' (spliceStateEquiv b t.1.val) = fun i => a (y t.1.val i) := funext (hy t.1.val) + change (traceContactCount G (fun j => edgeFieldEquiv b (t.1.val.2 j)) + (y' (spliceStateEquiv b t.1.val)) (edgeFieldEquiv b (traceIndexOutput G x k Q A y t).1) + (a x) (spliceCodeEquiv b t.2.val) (i.val+1):ℝ)⁻¹ = _ + rw [hy',traceContactCount_aut_map G hab] + +end FiniteTraceIndexEquiv + + + +theorem finiteForwardLoad_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) (A A' : Finset (SpliceState E)) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (hA : ∀ s, s ∈ A ↔ spliceStateEquiv b s ∈ A') + (y y' : SpliceState E → ℕ → V) (hy : ∀ s i, y' (spliceStateEquiv b s) i = a (y s i)) + (s : SpliceState E) : + finiteForwardLoad G (a x) k Q' A' y' (spliceStateEquiv b s) = finiteForwardLoad G x k Q A y s := by + unfold finiteForwardLoad finiteInverseLoad + rw [← (finiteTraceIndexEquiv G hab x k Q Q' A A' hQ hA y y' hy).sum_comp] + apply Finset.sum_congr rfl + intro t _ + rw [FiniteTraceIndexEquiv.output,FiniteTraceIndexEquiv.mass] + simp only [(spliceStateEquiv b).injective.eq_iff] + +end FiniteIndexCovariance + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteFieldCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finset_aut_eq_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') : Q' = Q.map b.toEmbedding := by + ext e + simpa only [Finset.mem_map_equiv,b.apply_symm_apply] using (hQ (b.symm e)).symm + +noncomputable def finiteFieldAutEquiv (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') : FiniteField Q ≃ FiniteField Q' := + (Equiv.finsetCongr b).subtypeEquiv (fun ω => by + simp only [Finset.mem_powerset] + change ω ⊆ Q ↔ ω.map b.toEmbedding ⊆ Q' + rw [finset_aut_eq_map b Q Q' hQ,Finset.map_subset_map]) + +@[simp] theorem finiteFieldSet_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : FiniteField Q) : + finiteFieldSet Q' (finiteFieldAutEquiv b Q Q' hQ ω) = edgeFieldEquiv b (finiteFieldSet Q ω) := by + change (ω.val.map b.toEmbedding : Set E) = b.symm ⁻¹' (ω.val : Set E) + rw [Finset.coe_map] + exact b.image_eq_preimage_symm _ + +@[simp] theorem finiteFieldWeight_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (p : ℝ) (ω : FiniteField Q) : + finiteFieldWeight Q' p (finiteFieldAutEquiv b Q Q' hQ ω) = finiteFieldWeight Q p ω := by + change p^(ω.val.map b.toEmbedding).card * (1-p)^(Q'.card-(ω.val.map b.toEmbedding).card) = _ + simp only [Finset.card_map,finset_aut_eq_map b Q Q' hQ] + rfl + +noncomputable def finiteFamilyEquiv (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) : + (↥J → FiniteField Q) ≃ (↥J → FiniteField Q') := + Equiv.piCongrRight fun _ => finiteFieldAutEquiv b Q Q' hQ + +@[simp] theorem finiteFieldFamily_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (η : ↥J → FiniteField Q) (i : ℕ) : + finiteFieldFamily Q' J (finiteFamilyEquiv b Q Q' hQ J η) i = + edgeFieldEquiv b (finiteFieldFamily Q J η i) := by + unfold finiteFieldFamily + split_ifs with hi + · exact finiteFieldSet_aut_map b Q Q' hQ (η ⟨i,hi⟩) + · rfl + +@[simp] theorem finiteFamilyWeight_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (p : ℝ) (η : ↥J → FiniteField Q) : + finiteFamilyWeight Q' J p (finiteFamilyEquiv b Q Q' hQ J η) = finiteFamilyWeight Q J p η := by + apply Finset.prod_congr rfl + intro i _ + exact finiteFieldWeight_aut_map b Q Q' hQ p (η i) + +@[simp] theorem restrictFiniteField_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : Set E) : + restrictFiniteField Q' (edgeFieldEquiv b ω) = finiteFieldAutEquiv b Q Q' hQ (restrictFiniteField Q ω) := by + apply finiteFieldSet_injective Q' + rw [finiteFieldSet_aut_map,finiteFieldSet_restrict,finiteFieldSet_restrict] + ext e + change (b.symm e ∈ ω ∧ e ∈ Q') ↔ (b.symm e ∈ ω ∧ b.symm e ∈ Q) + rw [hQ (b.symm e),b.apply_symm_apply] + + + +theorem finiteRootLoad_aut_map (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (p : ℝ) + (f f' : SpliceState E → ℝ) (hf : ∀ s, f' (spliceStateEquiv b s) = f s) + (ω : FiniteField Q) : + finiteRootLoad Q' J p f' (finiteFieldAutEquiv b Q Q' hQ ω) = finiteRootLoad Q J p f ω := by + unfold finiteRootLoad + rw [← (finiteFamilyEquiv b Q Q' hQ J).sum_comp] + apply Finset.sum_congr rfl + intro η _ + rw [finiteFamilyWeight_aut_map,finiteFieldSet_aut_map] + have he : finiteFieldFamily Q' J (finiteFamilyEquiv b Q Q' hQ J η) = + fun i => edgeFieldEquiv b (finiteFieldFamily Q J η i) := + funext (finiteFieldFamily_aut_map b Q Q' hQ J η) + rw [he] + exact congrArg (fun t => finiteFamilyWeight Q J p η * t) + (hf (finiteFieldSet Q ω,finiteFieldFamily Q J η)) + +end FiniteFieldCovariance + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section ChoiceIndexCovariance +attribute [local instance] Classical.propDecidable Classical.decEq +variable {P P' : Type*} + +def finiteChoiceTraceIndexEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') + (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) + (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) + (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) + (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) : + FiniteChoiceTraceIndex G x k Q A y ≃ FiniteChoiceTraceIndex G (a x) k Q' A' y' := + Equiv.sigmaCongr e (fun r => finiteTraceIndexEquiv G hab x k Q Q' (A r) (A' (e r)) hQ (hA r) + (y r) (y' (e r)) (hy r)) + +namespace FiniteChoiceTraceIndexEquiv +variable (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') + (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) + (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) + (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) + (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) + +@[simp] theorem input (t : FiniteChoiceTraceIndex G x k Q A y) : + choiceTraceInput G (a x) k Q' A' y' (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = + spliceStateEquiv b (choiceTraceInput G x k Q A y t) := rfl + +@[simp] theorem output (t : FiniteChoiceTraceIndex G x k Q A y) : + choiceTraceOutput G (a x) k Q' A' y' (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = + spliceStateEquiv b (choiceTraceOutput G x k Q A y t) := + FiniteTraceIndexEquiv.output G hab x k Q Q' (A t.1) (A' (e t.1)) hQ (hA t.1) + (y t.1) (y' (e t.1)) (hy t.1) t.2 + +@[simp] theorem mass (q : SpliceState E → P → ℝ) (q' : SpliceState E → P' → ℝ) + (hq : ∀ s r, q' (spliceStateEquiv b s) (e r) = q s r) + (t : FiniteChoiceTraceIndex G x k Q A y) : + choiceTraceMass G (a x) k Q' A' y' q' + (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy t) = + choiceTraceMass G x k Q A y q t := by + unfold choiceTraceMass + rw [input G hab x k Q Q' hQ e A A' hA y y' hy] + change q' (spliceStateEquiv b (choiceTraceInput G x k Q A y t)) (e t.1) * _ = _ + rw [hq] + exact congrArg (fun m => q (choiceTraceInput G x k Q A y t) t.1 * m) + (FiniteTraceIndexEquiv.mass G hab x k Q Q' (A t.1) (A' (e t.1)) hQ (hA t.1) + (y t.1) (y' (e t.1)) (hy t.1) t.2) + +end FiniteChoiceTraceIndexEquiv + +theorem finiteChoiceForwardLoad_aut_map [Fintype P] [Fintype P'] + (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (k : ℕ) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (e : P ≃ P') + (A : P → Finset (SpliceState E)) (A' : P' → Finset (SpliceState E)) + (hA : ∀ r s, s ∈ A r ↔ spliceStateEquiv b s ∈ A' (e r)) + (y : P → SpliceState E → ℕ → V) (y' : P' → SpliceState E → ℕ → V) + (hy : ∀ r s i, y' (e r) (spliceStateEquiv b s) i = a (y r s i)) + (q : SpliceState E → P → ℝ) (q' : SpliceState E → P' → ℝ) + (hq : ∀ s r, q' (spliceStateEquiv b s) (e r) = q s r) (s : SpliceState E) : + finiteChoiceForwardLoad G (a x) k Q' A' y' q' (spliceStateEquiv b s) = + finiteChoiceForwardLoad G x k Q A y q s := by + unfold finiteChoiceForwardLoad finiteInverseLoad + rw [← (finiteChoiceTraceIndexEquiv G hab x k Q Q' hQ e A A' hA y y' hy).sum_comp] + apply Finset.sum_congr rfl + intro t _ + rw [FiniteChoiceTraceIndexEquiv.output,FiniteChoiceTraceIndexEquiv.mass G hab x k Q Q' hQ e A A' hA y y' hy q q' hq] + simp only [(spliceStateEquiv b).injective.eq_iff] + +end ChoiceIndexCovariance + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AmplificationCovarianceInput +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem edgeField_subset_aut_iff (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (ω : Set E) : + edgeFieldEquiv b ω ⊆ (Q' : Set E) ↔ ω ⊆ (Q : Set E) := by + constructor + · intro h e he + exact (hQ e).mpr (h (by simpa using he : b e ∈ edgeFieldEquiv b ω)) + · intro h e he + have hh := (hQ (b.symm e)).mp (h he) + simpa only [b.apply_symm_apply,Finset.mem_coe] using hh + +theorem finiteSpliceDomain_aut_map_iff (b : E ≃ E) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (J : Finset ℕ) (s : SpliceState E) : + spliceStateEquiv b s ∈ finiteSpliceDomain Q' J ↔ s ∈ finiteSpliceDomain Q J := by + rw [mem_finiteSpliceDomain_iff,mem_finiteSpliceDomain_iff] + change (edgeFieldEquiv b s.1 ⊆ (Q':Set E) ∧ + (∀ i,edgeFieldEquiv b (s.2 i) ⊆ (Q':Set E)) ∧ ∀ i ∉ J,edgeFieldEquiv b (s.2 i)=∅) ↔ _ + have hz (η : Set E) : edgeFieldEquiv b η = ∅ ↔ η = ∅ := by + change edgeFieldEquiv b η = edgeFieldEquiv b ∅ ↔ _ + exact (edgeFieldEquiv b).injective.eq_iff + simp only [edgeField_subset_aut_iff b Q Q' hQ,hz] + +theorem oldRunVertices_map {W W' : Type*} (f : W → W') (k : ℕ) (z : W) + (r : Fin k → W) (i : ℕ) : + oldRunVertices k (f z) (fun j => f (r j)) i = f (oldRunVertices k z r i) := by + induction k generalizing z with + | zero => rfl + | succ k ih => + simp only [oldRunVertices] + split_ifs with hi + · exact ih (r 0) (Fin.tail r) + · rfl + +theorem oldRunWeight_map {W W' : Type*} (f : W → W') + (K : ℕ → W → W → ℝ) (K' : ℕ → W' → W' → ℝ) + (hK : ∀ i a b, K' i (f a) (f b) = K i a b) (k : ℕ) (z : W) (r : Fin k → W) : + oldRunWeight K' k (f z) (fun i => f (r i)) = oldRunWeight K k z r := by + induction k generalizing z with + | zero => rfl + | succ k ih => + simp only [oldRunWeight,hK] + rw [show Fin.tail (fun i => f (r i)) = (fun i => f (Fin.tail r i)) from rfl,ih] + +def finiteVertexEquiv (a : V ≃ V) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') : ↥B ≃ ↥B' := + a.subtypeEquiv hB + +def finiteRunEquiv (a : V ≃ V) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') (k : ℕ) : + (Fin k → ↥B) ≃ (Fin k → ↥B') := + Equiv.piCongrRight fun _ => finiteVertexEquiv a B B' hB + +theorem amplificationVertices_aut_map (a : V ≃ V) (B B' : Finset V) + (hB : ∀ x, x ∈ B ↔ a x ∈ B') (k : ℕ) (z : ↥B) (r : Fin k → ↥B) (i : ℕ) : + amplificationVertices B' k (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) i = + a (amplificationVertices B k z r i) := + congrArg Subtype.val (oldRunVertices_map (finiteVertexEquiv a B B' hB) k z r i) + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +theorem mass_aut_map (q : LocalEndpointRule G hloc O M L) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) : + q.mass (edgeFieldEquiv b ω) (a x) (a y) = q.mass ω x y := by + simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_apply] using + q.covariance a.symm b.symm (isAut_symm G hab) ω (a x) (a y) + +theorem amplificationWeight_aut_map (q : LocalEndpointRule G hloc O M L) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') + (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : + q.amplificationWeight B' k (finiteVertexEquiv a B B' hB z) (spliceStateEquiv b s) + (finiteRunEquiv a B B' hB k r) = q.amplificationWeight B k z s r := by + apply oldRunWeight_map (finiteVertexEquiv a B B' hB) + intro i v w + exact q.mass_aut_map hab (s.2 i) v.val w.val + +theorem amplificationInputs_aut_map_iff (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') + (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) : + spliceStateEquiv b s ∈ q.amplificationInputs Q' B' (a x) k n + (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) ↔ + s ∈ q.amplificationInputs Q B x k n z r := by + rw [q.mem_amplificationInputs,q.mem_amplificationInputs] + have hn : (cluster G (edgeFieldEquiv b s.1) (a x)).ncard = (cluster G s.1 x).ncard := by + rw [cluster_edgeFieldEquiv G hab,← a.image_eq_preimage_symm,Set.ncard_image_of_injective _ a.injective] + change (spliceStateEquiv b s ∈ finiteSpliceDomain Q' (Finset.Icc 1 k) ∧ + a x ∈ vertexOrbit G o ∧ a z.val ∈ vertexOrbit G o ∧ + n ≤ (cluster G (edgeFieldEquiv b s.1) (a x)).ncard ∧ + (cluster G (edgeFieldEquiv b s.1) (a x)).ncard < 2*n ∧ + amplificationVertices B' k (finiteVertexEquiv a B B' hB z) (finiteRunEquiv a B B' hB k r) 0 ∈ + cluster G (edgeFieldEquiv b s.1) (a x) ∧ _) ↔ _ + rw [finiteSpliceDomain_aut_map_iff b Q Q' hQ,mem_vertexOrbit_aut_iff G o hab, + mem_vertexOrbit_aut_iff G o hab,hn,amplificationVertices_aut_map, + cluster_edgeFieldEquiv G hab,q.amplificationWeight_aut_map hab B B' hB] + simp only [Set.mem_preimage,Equiv.symm_apply_apply] + +end LocalEndpointRule +end AmplificationCovarianceInput + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AmplificationCovarianceMarginal +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem amplificationMarginal_aut_map (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (Q Q' : Finset E) + (hQ : ∀ e, e ∈ Q ↔ b e ∈ Q') (B B' : Finset V) (hB : ∀ x, x ∈ B ↔ a x ∈ B') + (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) (ω : Set E) : + q.amplificationMarginal Q' B' (a x) k n (finiteVertexEquiv a B B' hB z) p (edgeFieldEquiv b ω) = + q.amplificationMarginal Q B x k n z p ω := by + unfold amplificationMarginal + rw [restrictFiniteField_aut_map b Q Q' hQ] + apply finiteRootLoad_aut_map + intro s + apply finiteChoiceForwardLoad_aut_map G hab x k Q Q' hQ (finiteRunEquiv a B B' hB k) + · intro r s + exact (q.amplificationInputs_aut_map_iff o hab Q Q' hQ B B' hB x k n z r s).symm + · intro r s i + exact amplificationVertices_aut_map a B B' hB k z r i + · intro s r + exact q.amplificationWeight_aut_map hab B B' hB k z s r + +end LocalEndpointRule + +theorem mem_incidentSupport_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (B B' : Finset V) + (hB : ∀ x, x ∈ B ↔ a x ∈ B') (e : E) : + b e ∈ incidentSupport G hloc B' ↔ e ∈ incidentSupport G hloc B := by + rw [finset_aut_eq_map a B B' hB,incidentSupport_aut G hloc hab] + simp only [Finset.mem_map_equiv,Equiv.symm_apply_apply] + +theorem finiteBall_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) (R : ℕ) : + y ∈ (finite_reachBall hloc x R).toFinset ↔ a y ∈ (finite_reachBall hloc (a x) R).toFinset := by + simpa only [Set.Finite.mem_toFinset] using (mem_reachBall_aut_iff G hab x y R).symm + +theorem localBondBall_aut_iff (G : BondGraph V E) (hloc : LocallyFinite G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x : V) (R : ℕ) (e : E) : + e ∈ incidentSupport G hloc (finite_reachBall hloc x R).toFinset ↔ + b e ∈ incidentSupport G hloc (finite_reachBall hloc (a x) R).toFinset := + (mem_incidentSupport_aut_iff G hloc hab _ _ (fun y => finiteBall_aut_iff G hloc hab x y R) e).symm + +end AmplificationCovarianceMarginal + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section CanonicalAmplificationLoad +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +def amplificationRadius (q : LocalEndpointRule G hloc O M L) (k n : ℕ) : ℕ := + 2*n+k*M+max q.radius M + +noncomputable def amplificationBall (_q : LocalEndpointRule G hloc O M L) (k n : ℕ) (x : V) : Finset V := + (finite_reachBall hloc x (2*n+k*M)).toFinset + +noncomputable def amplificationBonds (q : LocalEndpointRule G hloc O M L) (k n : ℕ) (x : V) : Finset E := + incidentSupport G hloc (finite_reachBall hloc x (q.amplificationRadius k n)).toFinset + + + +noncomputable def amplifiedMass (q : LocalEndpointRule G hloc O M L) (k n : ℕ) (p : unitInterval) + (ω : Set E) (x z : V) : ℝ := + if hz : z ∈ q.amplificationBall k n x then + q.amplificationMarginal (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω / n + else 0 + +theorem amplifiedMass_nonneg (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) + (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) : 0 ≤ q.amplifiedMass k n p ω x z := by + unfold amplifiedMass + split_ifs + · exact div_nonneg (q.amplificationMarginal_bounds hL _ _ _ _ _ _ _ _).1 (Nat.cast_nonneg _) + · exact le_rfl + +theorem amplifiedMass_support (q : LocalEndpointRule G hloc O M L) + (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) (h : q.amplifiedMass k n p ω x z ≠ 0) : + x ∈ O ∧ z ∈ O ∧ Conn G ω x z ∧ (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ 2*n+k*M := by + unfold amplifiedMass at h + split_ifs at h with hz + · apply q.amplificationMarginal_physical_support (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω + · exact incidentSupport_ball_mono G hloc x (Nat.le_add_right (2*n+k*M) (max q.radius M)) + · intro he + exact h (by rw [he,zero_div]) + · exact (h rfl).elim + +theorem amplifiedMass_local (q : LocalEndpointRule G hloc O M L) + (k n : ℕ) (p : unitInterval) (ω : Set E) (x z : V) : + q.amplifiedMass k n p ω x z = + q.amplifiedMass k n p (ω ∩ (q.amplificationBonds k n x : Set E)) x z := by + unfold amplifiedMass + split_ifs + · exact congrArg (fun t : ℝ => t / n) (q.amplificationMarginal_local _ _ _ _ _ _ _ _) + · rfl + +theorem amplifiedMass_aut_map (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (k n : ℕ) (p : unitInterval) + (ω : Set E) (x z : V) : + q.amplifiedMass k n p (edgeFieldEquiv b ω) (a x) (a z) = q.amplifiedMass k n p ω x z := by + have hB (y : V) : y ∈ q.amplificationBall k n x ↔ a y ∈ q.amplificationBall k n (a x) := + finiteBall_aut_iff G hloc hab x y (2*n+k*M) + have hQ (e : E) : e ∈ q.amplificationBonds k n x ↔ b e ∈ q.amplificationBonds k n (a x) := + localBondBall_aut_iff G hloc hab x (q.amplificationRadius k n) e + unfold amplifiedMass + by_cases hz : z ∈ q.amplificationBall k n x + · simp only [dite_eq_left hz,dite_eq_left ((hB z).mp hz)] + exact congrArg (fun t : ℝ => t / n) + (q.amplificationMarginal_aut_map o hab _ _ hQ _ _ hB x k n ⟨z,hz⟩ p ω) + · simp only [dite_eq_right hz,dite_eq_right (mt (hB z).mpr hz)] + + + +noncomputable def amplificationLoad (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) : + CappedLocalLoad G hloc (vertexOrbit G o) (2*n+k*M) where + mass := q.amplifiedMass k n p + radius := q.amplificationRadius k n + nonneg := q.amplifiedMass_nonneg hL k n p + support := q.amplifiedMass_support k n p + locality := q.amplifiedMass_local k n p + covariance := by + intro a b hab ω x z + simpa only [Equiv.symm_apply_apply,edgeFieldEquiv_apply,Equiv.symm_symm] using + q.amplifiedMass_aut_map o (isAut_symm G hab) k n p ω (a x) (a z) + +end LocalEndpointRule +end CanonicalAmplificationLoad + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section CanonicalAmplificationRow +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem amplificationBonds_query {O : Set V} (q : LocalEndpointRule G hloc O M L) + (k n : ℕ) (x a : V) (ha : a ∈ q.amplificationBall k n x) : + incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ + q.amplificationBonds k n x := by + apply incidentSupport_mono + intro y hy + simp only [Set.Finite.mem_toFinset] at hy ⊢ + exact reachBall_triangle G x a (2*n+k*M) (max q.radius M) + (by simpa only [amplificationBall,Set.Finite.mem_toFinset] using ha) hy + +theorem amplificationBonds_root {O : Set V} (q : LocalEndpointRule G hloc O M L) + (k n : ℕ) (x : V) : + incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ + q.amplificationBonds k n x := by + apply incidentSupport_ball_mono + unfold amplificationRadius + omega + +theorem amplificationLoad_row (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (ω : Set E) (x : V) : + (q.amplificationLoad o hL k n p).row ω x = + q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p ω / n := by + change (∑' z, q.amplifiedMass k n p ω x z) = _ + rw [tsum_eq_sum (s := q.amplificationBall k n x) (fun z hz => by + simp only [amplifiedMass,dite_eq_right hz])] + rw [← Finset.sum_coe_sort] + simp only [amplifiedMass,dite_eq_left (Subtype.prop _)] + exact (Finset.sum_div _ _ _).symm + +theorem amplificationRow_local {O : Set V} (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : + q.amplificationRow Q B x k n p ω = q.amplificationRow Q B x k n p (ω ∩ (Q : Set E)) := by + unfold amplificationRow + apply Finset.sum_congr rfl + intro z _ + exact q.amplificationMarginal_local Q B x k n z p ω + +theorem amplificationLoad_mean_finite (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (x : V) : + (∫ ω, (q.amplificationLoad o hL k n p).row ω x ∂law p) = + finiteFieldIntegral (q.amplificationBonds k n x) p + (q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p) / n := by + simp_rw [q.amplificationLoad_row o hL k n p] + rw [integral_div] + congr 1 + exact integral_finite_local _ p _ (q.amplificationRow_local _ _ x k n p) + +theorem amplificationLoad_second_moment_finite (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (hL : 1 ≤ L) (k n : ℕ) (p : unitInterval) (x : V) : + (∫ ω, (q.amplificationLoad o hL k n p).row ω x ^ 2 ∂law p) = + finiteFieldIntegral (q.amplificationBonds k n x) p (fun ω => + q.amplificationRow (q.amplificationBonds k n x) (q.amplificationBall k n x) x k n p ω ^ 2) / (n:ℝ)^2 := by + simp_rw [q.amplificationLoad_row o hL k n p,div_pow] + rw [integral_div] + congr 1 + exact integral_finite_local _ p _ (fun ω => congrArg (·^2) (q.amplificationRow_local _ _ x k n p ω)) + +end LocalEndpointRule +end CanonicalAmplificationRow + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section NormalizedAmplificationMoment +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem amplificationLoad_second_moment_le [Nonempty E] (hconn : Connected G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (x : V) (k n d : ℕ) (hn : 0 < n) + (hdeg : ∀ a, degree G a ≤ d) : + (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ^ 2 ∂law p) ≤ + (4 * q.successProbability p (root i₀)^k + + (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L^k / n) * + (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ∂law p) + + (2 * (c*((k*M:ℕ)*q.successProbability p (root i₀)^k)))^2 * + finiteClusterWindowMass G (q.amplificationBonds k n x) p x (n-k*M) (2*n) := by + rw [q.amplificationLoad_second_moment_finite,q.amplificationLoad_mean_finite] + have h := q.amplificationRow_second_moment_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin + i₀ hw₀ hL (q.amplificationBonds k n x) (q.amplificationBall k n x) p x k n d hdeg + (fun a ha => q.amplificationBonds_query k n x a ha) + have hn' : (n:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr hn) + apply (div_le_div_of_nonneg_right h (sq_nonneg (n:ℝ))).trans_eq + push_cast + field_simp + +end LocalEndpointRule +end NormalizedAmplificationMoment + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FinitePathExhaustion +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finitePathTest (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (k : ℕ) (z : ↥B) : ℝ := + ∑ r : Fin k → ↥B, oldRunWeight (fun _ a b => K a.val b.val) k z r * F (oldRunVertices k z r 0).val + +@[simp] theorem finitePathTest_zero (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (z : ↥B) : + finitePathTest B K F 0 z = F z.val := by + simp [finitePathTest,oldRunWeight,oldRunVertices] + +theorem finitePathTest_succ (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) (k : ℕ) (z : ↥B) : + finitePathTest B K F (k+1) z = ∑ a : ↥B, K z.val a.val * finitePathTest B K F k a := + oldRun_test_succ (fun _ (a b : ↥B) => K a.val b.val) (fun (a : ↥B) => F a.val) k z + + + +theorem finitePathTest_support (G : BondGraph V E) (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) + (O : Set V) (x : V) (R M : ℕ) + (hK : ∀ a b, K a b ≠ 0 → a ∈ O ∧ a ∈ reachBall G b M) + (hF : ∀ a, F a ≠ 0 → a ∈ O ∧ a ∈ reachBall G x R) + (k : ℕ) (z : ↥B) (hz : finitePathTest B K F k z ≠ 0) : + z.val ∈ O ∧ z.val ∈ reachBall G x (R+k*M) := by + induction k generalizing z with + | zero => simpa using hF z.val (by simpa using hz) + | succ k ih => + rw [finitePathTest_succ] at hz + obtain ⟨a,_,ha⟩ := Finset.exists_ne_zero_of_sum_ne_zero hz + have hh := mul_ne_zero_iff.mp ha + obtain ⟨haO,haB⟩ := ih a hh.2 + obtain ⟨hzO,hzB⟩ := hK z.val a.val hh.1 + refine ⟨hzO,?_⟩ + have hg := reachBall_triangle G x a.val (R+k*M) M haB hzB + simpa only [Nat.add_mul,one_mul,Nat.add_assoc] using hg + + + +theorem finitePathTest_total (G : BondGraph V E) (B : Finset V) (K : V → V → ℝ) (F : V → ℝ) + (O : Set V) (x : V) (R M N : ℕ) (u : ℝ) + (hK : ∀ a b, K a b ≠ 0 → a ∈ O ∧ a ∈ reachBall G b M) + (hF : ∀ a, F a ≠ 0 → a ∈ O ∧ a ∈ reachBall G x R) + (hcolumn : ∀ j < N, ∀ a : ↥B, a.val ∈ O → a.val ∈ reachBall G x (R+j*M) → + ∑ z : ↥B, K z.val a.val = u) : + ∀ j ≤ N, (∑ z : ↥B, finitePathTest B K F j z) = u^j * ∑ z : ↥B, F z.val := by + intro j hj + induction j with + | zero => simp + | succ j ih => + simp_rw [finitePathTest_succ] + rw [Finset.sum_comm] + have he : (∑ a : ↥B, ∑ z : ↥B, K z.val a.val * finitePathTest B K F j a) = + u * ∑ a : ↥B, finitePathTest B K F j a := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [← Finset.sum_mul] + by_cases ha : finitePathTest B K F j a = 0 + · simp only [ha,mul_zero] + · obtain ⟨haO,haB⟩ := finitePathTest_support G B K F O x R M hK hF j a ha + rw [hcolumn j (by omega) a haO haB] + rw [he,ih (by omega)] + ring + +end FinitePathExhaustion + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section AmplificationBoundaryExhaustion +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem kernel_range_support {O : Set V} (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (a b : V) (h : q.kernel p a b ≠ 0) : a ∈ O ∧ a ∈ reachBall G b M := by + constructor + · by_contra ha + exact h (q.kernel_zero_of_start_not_mem p a b ha) + · by_contra ha + exact h (q.kernel_outside_reverse_ball_zero p a b ha) + +theorem orbitBinConnection_range_support (o : V) (p : unitInterval) (n : ℕ) (x a : V) + (h : orbitBinConnection G p o n x a ≠ 0) : + a ∈ vertexOrbit G o ∧ a ∈ reachBall G x (2*n) := by + have ha : a ∈ vertexOrbit G o := by + by_contra ha + exact h (by simp only [orbitBinConnection,ha,and_false,ite_false]) + refine ⟨ha,?_⟩ + by_contra hb + exact h (by simp only [orbitBinConnection,binConnection_outside G p n x a hb,ite_self]) + +theorem amplificationBall_column {O : Set V} (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (k n j : ℕ) (hj : j < k) (x a : V) + (ha : a ∈ reachBall G x (2*n+j*M)) : + (∑ z : ↥(q.amplificationBall k n x), q.kernel p z.val a) = ∑' z, q.kernel p z a := by + rw [Finset.sum_coe_sort (q.amplificationBall k n x) (fun z => q.kernel p z a)] + symm + apply tsum_eq_sum + intro z hz + apply q.kernel_outside_reverse_ball_zero + intro hza + have hh := reachBall_triangle G x a (2*n+j*M) M ha hza + have hle : (2*n+j*M)+M ≤ 2*n+k*M := by + calc + _ = 2*n+(j+1)*M := by ring + _ ≤ _ := Nat.add_le_add_left (Nat.mul_le_mul_right M (by omega)) _ + exact hz (by + simpa only [amplificationBall,Set.Finite.mem_toFinset] using (reachBall_mono G x hle hh)) + +theorem amplificationPath_total {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (p : unitInterval) (k n : ℕ) (x : V) (hx : x ∈ vertexOrbit G (root i₀)) : + (∑ z : ↥(q.amplificationBall k n x), + finitePathTest (q.amplificationBall k n x) (q.kernel p) (orbitBinConnection G p (root i₀) n x) k z) = + q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n := by + have ht := finitePathTest_total G (q.amplificationBall k n x) (q.kernel p) + (orbitBinConnection G p (root i₀) n x) (vertexOrbit G (root i₀)) x (2*n) M k + (q.successProbability p (root i₀)) (q.kernel_range_support p) + (orbitBinConnection_range_support (root i₀) p n x) (by + intro j hj a haO haB + rw [q.amplificationBall_column p k n j hj x a.val haB] + exact q.kernel_column_eq_success root weight Γ htr hΓ hw i₀ hw₀ p a.val haO) k le_rfl + rw [ht] + congr 1 + rw [Finset.sum_coe_sort (q.amplificationBall k n x) (orbitBinConnection G p (root i₀) n x),← orbitBinConnection_row G hloc p (root i₀) n x hx] + symm + apply tsum_eq_sum + intro z hz + by_contra h + have hb := (orbitBinConnection_range_support (root i₀) p n x z h).2 + exact hz (by + simpa only [amplificationBall,Set.Finite.mem_toFinset] using + reachBall_mono G x (Nat.le_add_right (2*n) (k*M)) hb) + +end LocalEndpointRule +end AmplificationBoundaryExhaustion + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section AmplificationExactMean +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem amplificationMarginal_mean_pathTest [Nonempty E] (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (p : unitInterval) + (hx : x ∈ vertexOrbit G o) + (hroot : incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset ⊆ Q) + (hquery : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : + (∫ ω, q.amplificationMarginal Q B x k n z p ω ∂law p) = + finitePathTest B (q.kernel p) (orbitBinConnection G p o n x) k z := by + by_cases hz : z.val ∈ vertexOrbit G o + · rw [q.amplificationMarginal_mean_kernel Q B x k n z p hx hz hquery] + unfold finitePathTest + apply Finset.sum_congr rfl + intro r _ + rw [finiteBinConnection_eq_binConnection G hloc Q p x n _ hroot] + by_cases hr : oldRunWeight (fun _ (a b : ↥B) => q.kernel p a.val b.val) k z r = 0 + · simp only [hr,mul_zero,zero_mul] + · have hy : (oldRunVertices k z r 0).val ∈ vertexOrbit G o := + oldRun_endpoint_mem (fun a : ↥B => a.val ∈ vertexOrbit G o) + (fun _ (a b : ↥B) => q.kernel p a.val b.val) + (fun _ a b hab => by + by_contra hb + exact hab (q.kernel_zero_of_end_not_mem p a.val b.val hb)) k z hz r hr + rw [orbitBinConnection,ite_eq_left ⟨hx,hy⟩] + exact mul_comm _ _ + · have hm (ω : Set E) : q.amplificationMarginal Q B x k n z p ω = 0 := by + by_contra h + exact hz (q.amplificationMarginal_support Q B x k n z p ω h).2.1 + simp_rw [hm,integral_zero] + symm + by_contra h + exact hz (finitePathTest_support G B (q.kernel p) (orbitBinConnection G p o n x) + (vertexOrbit G o) x (2*n) M (q.kernel_range_support p) + (orbitBinConnection_range_support o p n x) k z h).1 + + + +theorem amplificationLoad_mean [Nonempty E] {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (k n : ℕ) (x : V) (hx : x ∈ vertexOrbit G (root i₀)) : + (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω x ∂law p) = + q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n := by + simp_rw [q.amplificationLoad_row] + rw [integral_div] + congr 1 + unfold amplificationRow + rw [integral_finsetSum _ (fun z _ => integrable_finite_local _ p _ + (q.amplificationMarginal_local _ _ x k n z p))] + simp_rw [q.amplificationMarginal_mean_pathTest (root i₀) _ _ x k n _ p hx + (q.amplificationBonds_root k n x) (fun a ha => + (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (q.amplificationBonds_query k n x a ha))] + exact q.amplificationPath_total root weight Γ htr hΓ hw i₀ hw₀ p k n x hx + +end LocalEndpointRule +end AmplificationExactMean + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section AmplificationLoadOperator +attribute [local instance] Classical.propDecidable Classical.decEq +namespace CappedLocalLoad +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} + +noncomputable def kernel (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : ℝ := + ∫ ω, q.mass ω x y ∂law p + +theorem kernel_nonneg (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : + 0 ≤ q.kernel p x y := integral_nonneg (q.nonneg · x y) + +end CappedLocalLoad + + +theorem exists_operator_of_scaled_matrix (F : V → V → ℝ) (c C : ℝ) (hc : 0 < c) + (A : Hilbert V →L[ℂ] Hilbert V) (hAnorm : ‖A‖ ≤ C) + (hA : ∀ x y, matrixCoeff A x y = (c * F x y : ℂ)) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ C/c ∧ + ∀ x y, matrixCoeff T x y = (F x y : ℂ) := by + refine ⟨((c⁻¹:ℝ):ℂ) • A,?_,?_⟩ + · rw [norm_smul,Complex.norm_of_nonneg (inv_nonneg.mpr hc.le)] + simpa only [div_eq_mul_inv,mul_comm] using + mul_le_mul_of_nonneg_left hAnorm (inv_nonneg.mpr hc.le) + · intro x y + change ((c⁻¹:ℝ):ℂ)*matrixCoeff A x y = _ + rw [hA] + have hc' : (c:ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr hc.ne' + simp only [Complex.ofReal_inv] + field_simp + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem amplificationLoad_scaled_kernel [Nonempty E] (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hL : 1 ≤ L) + (k n : ℕ) (hn : 0 < n) (p : unitInterval) (x z : V) + (hz : z ∈ q.amplificationBall k n x) : + (n:ℝ) * (q.amplificationLoad o hL k n p).kernel p x z = + ∫ ω, q.amplificationMarginal (q.amplificationBonds k n x) (q.amplificationBall k n x) + x k n ⟨z,hz⟩ p ω ∂law p := by + change (n:ℝ) * (∫ ω, q.amplifiedMass k n p ω x z ∂law p) = _ + simp only [amplifiedMass,dite_eq_left hz,integral_div] + have hn' : (n:ℝ) ≠ 0 := ne_of_gt (Nat.cast_pos.mpr hn) + field_simp + + + +theorem amplificationLoad_exists_operator [Nonempty E] (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hL : 1 ≤ L) + (k n : ℕ) (hn : 0 < n) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ a b, matrixCoeff A a b = (q.kernel p a b : ℂ)) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ binOrbitRow G p o n * ‖A‖^k / n ∧ + ∀ x z, matrixCoeff T x z = ((q.amplificationLoad o hL k n p).kernel p x z : ℂ) := by + let F := (q.amplificationLoad o hL k n p).kernel p + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hposA : PositiveRealMatrix A := fun x z => by + rw [hA] + exact ⟨rfl,q.kernel_nonneg p x z⟩ + obtain ⟨S,hSnorm,hS⟩ := exists_operator_of_amplification_domination G hloc p o n k A hposA + (fun x z => (n:ℝ)*F x z) (fun x z => mul_nonneg hn'.le ((q.amplificationLoad o hL k n p).kernel_nonneg p x z)) + (by + intro H hH x z + have hposH : PositiveRealMatrix H := fun a b => by + rw [hH] + exact ⟨rfl,orbitBinConnection_nonneg G p o n a b⟩ + have hpos := (((hposA.pow k).mul hposH) z x).2 + by_cases hz : z ∈ q.amplificationBall k n x + · rw [q.amplificationLoad_scaled_kernel o hL k n hn p x z hz] + by_cases ho : x ∈ vertexOrbit G o ∧ z ∈ vertexOrbit G o + · exact q.amplificationMarginal_operator_le o _ _ x k n ⟨z,hz⟩ p ho.1 ho.2 + (q.amplificationBonds_root k n x) (fun a ha => + (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (q.amplificationBonds_query k n x a ha)) A H hA hH + · have hm (ω : Set E) : q.amplificationMarginal (q.amplificationBonds k n x) + (q.amplificationBall k n x) x k n ⟨z,hz⟩ p ω = 0 := by + by_contra h + have hs := q.amplificationMarginal_support _ _ x k n ⟨z,hz⟩ p ω h + exact ho ⟨hs.1,hs.2.1⟩ + simpa only [hm,integral_zero] using hpos + · have he : F x z = 0 := by + change (∫ ω, q.amplifiedMass k n p ω x z ∂law p) = 0 + simp only [amplifiedMass,dite_eq_right hz,integral_zero] + simpa only [he,mul_zero] using hpos) + exact exists_operator_of_scaled_matrix F n _ hn' S hSnorm (by + intro x z + simpa only [Complex.ofReal_mul] using hS x z) + +end LocalEndpointRule +end AmplificationLoadOperator + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section TruncationOperator +attribute [local instance] Classical.propDecidable Classical.decEq +namespace CappedLocalLoad +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} + +theorem truncate_kernel_le (q : CappedLocalLoad G hloc O M) (p : unitInterval) + (b : ℝ) (hb : 0 < b) (L : ℝ) (x y : V) : + (q.truncate b hb L).kernel p x y ≤ b⁻¹ * q.kernel p x y := by + rw [kernel,← integral_const_mul] + exact integral_mono ((q.truncate b hb L).integrable_mass p x y) + ((q.integrable_mass p x y).const_mul b⁻¹) (q.truncate_mass_le b hb L · x y) + + + +theorem truncate_exists_operator (q : CappedLocalLoad G hloc O M) (p : unitInterval) + (b : ℝ) (hb : 0 < b) (L : ℝ) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.kernel p x y : ℂ)) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ ‖A‖/b ∧ + ∀ x y, matrixCoeff T x y = ((q.truncate b hb L).kernel p x y : ℂ) := by + have hscale (x y : V) : matrixCoeff (((b⁻¹:ℝ):ℂ) • A) x y = (b⁻¹ * q.kernel p x y : ℝ) := by + change ((b⁻¹:ℝ):ℂ)*matrixCoeff A x y = _ + rw [hA,Complex.ofReal_mul] + obtain ⟨T,hT,hK⟩ := exists_operator_of_matrix_domination + (fun x y => b⁻¹ * q.kernel p x y) ((q.truncate b hb L).kernel p) + (fun x y => mul_nonneg (inv_nonneg.mpr hb.le) (q.kernel_nonneg p x y)) + (fun x y => by + rw [abs_of_nonneg ((q.truncate b hb L).kernel_nonneg p x y)] + exact q.truncate_kernel_le p b hb L x y) + (((b⁻¹:ℝ):ℂ) • A) hscale + refine ⟨T,hT.trans_eq ?_,hK⟩ + rw [norm_smul,Complex.norm_of_nonneg (inv_nonneg.mpr hb.le)] + ring + +end CappedLocalLoad +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + +theorem normalize_mass_operator (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (hu : 0 < q.successProbability p o) + (A : Hilbert V →L[ℂ] Hilbert V) (C : ℝ) (hAnorm : ‖A‖ ≤ C) + (hA : ∀ x y, matrixCoeff A x y = (q.kernel p x y : ℂ)) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ ≤ C/q.successProbability p o ∧ + ∀ x y, matrixCoeff T x y = (q.normalizedKernel o p x y : ℂ) := by + apply exists_operator_of_scaled_matrix (q.normalizedKernel o p) (q.successProbability p o) C hu A hAnorm + intro x y + rw [hA] + simp only [normalizedKernel,← Complex.ofReal_mul] + congr 1 + rw [← mul_assoc,mul_inv_cancel₀ hu.ne',one_mul] + + + +theorem mass_operator_of_normalized (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (hu : 0 < q.successProbability p o) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : + ∃ T : Hilbert V →L[ℂ] Hilbert V, ‖T‖ = q.successProbability p o * ‖A‖ ∧ + ∀ x y, matrixCoeff T x y = (q.kernel p x y : ℂ) := by + refine ⟨(q.successProbability p o : ℂ) • A,?_,?_⟩ + · rw [norm_smul,Complex.norm_of_nonneg hu.le] + · intro x y + change (q.successProbability p o : ℂ)*matrixCoeff A x y = _ + rw [hA] + simp only [normalizedKernel,← Complex.ofReal_mul] + congr 1 + rw [← mul_assoc,mul_inv_cancel₀ hu.ne',one_mul] + +end LocalEndpointRule +end TruncationOperator + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +open MeasureTheory +section AmplificationTruncationStep +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem normalized_operator_norm_pos (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (hu : 0 < q.successProbability p o) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : 0 < ‖A‖ := by + apply norm_pos_iff.mpr + intro ha + have hz (y : V) : q.kernel p o y = 0 := by + have he := hA o y + rw [ha] at he + have he' : (q.successProbability p o)⁻¹ * q.kernel p o y = 0 := + Complex.ofReal_eq_zero.mp he.symm + exact (mul_eq_zero.mp he').resolve_left (inv_ne_zero hu.ne') + have he : q.successProbability p o = 0 := by + simp only [successProbability,hz,tsum_zero] + exact hu.ne' he + + + +theorem amplification_truncation_step [Nonempty E] {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (k n : ℕ) (hn : 0 < n) + (hu : 0 < q.successProbability p (root i₀)) + (hbin : 0 < binOrbitRow G p (root i₀) n) + (b L' : ℝ) (hb : 0 < b) + (hmoment : (∫ ω, (q.amplificationLoad (root i₀) hL k n p).row ω (root i₀)^2 ∂law p) / b ≤ + (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/4) + (hbad : b * (law p).real {ω | CappedBadGoodness G ω (root i₀) (2*n+k*M) L'} ≤ + (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/4) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : + ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) (2*n+k*M) L', + (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n)/(2*b) ≤ + q'.successProbability p (root i₀) ∧ + ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ ‖A'‖ ≤ 2*‖A‖^k ∧ + ∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ) := by + let load := q.amplificationLoad (root i₀) hL k n p + let q' := load.truncate b hb L' + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hb₀ : 0 < q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n / n := + div_pos (mul_pos (pow_pos hu _) hbin) hn' + have hself : root i₀ ∈ vertexOrbit G (root i₀) := by + refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ + intro e + simp + have hmean := q.amplificationLoad_mean root weight Γ htr hΓ hw i₀ hw₀ hL p k n (root i₀) hself + have hnew := load.truncate_success_lower p b hb L' (root i₀) _ hmean.ge hmoment hbad + have hu' : 0 < q'.successProbability p (root i₀) := + (div_pos hb₀ (mul_pos (by norm_num) hb)).trans_le hnew + obtain ⟨B,hBnorm,hB⟩ := q.mass_operator_of_normalized (root i₀) p hu A hA + obtain ⟨C,hCnorm,hC⟩ := q.amplificationLoad_exists_operator (root i₀) hL k n hn p B hB + obtain ⟨D,hDnorm,hD⟩ := load.truncate_exists_operator p b hb L' C hC + have hD' : ‖D‖ ≤ (binOrbitRow G p (root i₀) n * (q.successProbability p (root i₀)*‖A‖)^k/n)/b := by + rw [hBnorm] at hCnorm + exact hDnorm.trans (div_le_div_of_nonneg_right hCnorm hb.le) + obtain ⟨A',hA'norm,hA'⟩ := q'.normalize_mass_operator (root i₀) p hu' D _ hD' hD + refine ⟨q',hnew,A',q'.normalized_operator_norm_pos (root i₀) p hu' A' hA',hA'norm.trans ?_,hA'⟩ + apply (div_le_iff₀ hu').mpr + apply (div_le_iff₀ hb).mpr + apply (div_le_iff₀ hn').mpr + have hret := (div_le_iff₀ (mul_pos (show (0:ℝ)<2 by norm_num) hb)).mp hnew + have hret' := (div_le_iff₀ hn').mp hret + rw [mul_pow] + calc + _ = (q.successProbability p (root i₀)^k * binOrbitRow G p (root i₀) n) * ‖A‖^k := by ring + _ ≤ (q'.successProbability p (root i₀)*(2*b)*n)*‖A‖^k := + mul_le_mul_of_nonneg_right hret' (pow_nonneg (norm_nonneg _) _) + _ = _ := by ring + +end LocalEndpointRule +end AmplificationTruncationStep + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/DistinctMoments.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/DistinctMoments.lean index fb349efe8071d036f45d2882312f3850fbc62ce4..f3be7c90a8d03e4c43bae6538b31922f9b72601f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/DistinctMoments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/DistinctMoments.lean @@ -1,1213 +1,1213 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.ExteriorMoments - -namespace OAI - -/-! Distinct Moments for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ExposedBoundaryPotential -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def exposedVertexPotential (G : BondGraph V E) (p : unitInterval) - (x a b : V) (ω : Set E) : ℝ := - if Conn G ω x a then freshExteriorMoment G p a b ω else 0 - -theorem integrable_exposedVertexPotential [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x a b : V) : - Integrable (exposedVertexPotential G p x a b) (law p) := by - have he : exposedVertexPotential G p x a b = {ω | Conn G ω x a}.indicator (freshExteriorMoment G p a b) := by - funext ω - simp only [exposedVertexPotential,Set.indicator,Set.mem_ofPred_eq] - rw [he] - exact (integrable_freshExteriorMoment G hloc hqt p hp a b).indicator (measurableSet_conn G x a) - -theorem integral_exposedVertexPotential_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x a b : V) : - (∫ ω, exposedVertexPotential G p x a b ω ∂law p) ≤ distinctClusterMoment G p a b := by - rw [←show (∫ ω, freshExteriorMoment G p a b ω ∂law p) = distinctClusterMoment G p a b from - integral_freshExteriorMoment G hloc hqt p hp a b] - apply integral_mono (integrable_exposedVertexPotential G hloc hqt p hp x a b) - (integrable_freshExteriorMoment G hloc hqt p hp a b) - intro ω - unfold exposedVertexPotential - split_ifs - · rfl - · exact freshExteriorMoment_nonneg G p a b ω - -theorem exposedBoundaryPotential_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x v : V) (M : ℕ) (ω : Set E) : - ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M = - ∑ a ∈ (finite_reachBall hloc v M).toFinset, - ∑ b ∈ neighbors G hloc a, exposedVertexPotential G p x a b ω := by - unfold deletedBoundaryPotential - rw [Finset.sum_filter,Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - by_cases ha : Conn G ω x a - · have hc := cluster_eq_of_conn G ω ha - have hn : a ∉ (cluster G ω x)ᶜ := by exact not_not.mpr ha - simp only [ite_eq_left hn,Finset.mul_sum] - simp only [exposedVertexPotential,ite_eq_left ha,freshExteriorMoment,hc] - · have hn : ¬a ∉ (cluster G ω x)ᶜ := by exact not_not.mpr ha - simp only [ite_eq_right hn,mul_zero,exposedVertexPotential,ite_eq_right ha,Finset.sum_const_zero] - - - -theorem integral_exposedBoundaryPotential_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x v : V) (M : ℕ) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M) (law p) ∧ - (∫ ω, ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M ∂law p) ≤ - ∑ a ∈ (finite_reachBall hloc v M).toFinset, neighborClusterMoment G hloc p a := by - simp_rw [exposedBoundaryPotential_eq G hloc p x v M] - have hi (a : V) := integrable_finsetSum (neighbors G hloc a) - (fun b _ => integrable_exposedVertexPotential G hloc hqt p hp x a b) - refine ⟨integrable_finsetSum _ (fun a _ => hi a),?_⟩ - rw [integral_finsetSum _ (fun a _ => hi a)] - apply Finset.sum_le_sum - intro a _ - rw [integral_finsetSum _ (fun b _ => integrable_exposedVertexPotential G hloc hqt p hp x a b)] - exact Finset.sum_le_sum (fun b _ => integral_exposedVertexPotential_le G hloc hqt p hp x a b) - -end ExposedBoundaryPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformExposedBoundary -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem reachBall_ncard_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (M : ℕ) : - (reachBall G (a x) M).ncard = (reachBall G x M).ncard := by - have he : reachBall G (a x) M = a '' reachBall G x M := by - ext y - constructor - · intro h - exact ⟨a.symm y,by simpa only [Equiv.symm_apply_apply] using mem_reachBall_aut G (isAut_symm G hab) h,by simp⟩ - · rintro ⟨z,hz,rfl⟩ - exact mem_reachBall_aut G hab hz - rw [he,Set.ncard_image_of_injective _ a.injective] - -theorem reachBall_card_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (M : ℕ) (x : V) : (finite_reachBall hloc x M).toFinset.card ≤ - ∑ i, (reachBall G (root i) M).ncard := by - obtain ⟨i,a,b,hab,hax⟩ := hcover x - rw [←Set.ncard_eq_toFinset_card (reachBall G x M) (finite_reachBall hloc x M),←hax,reachBall_ncard_covariant G hab] - exact Finset.single_le_sum (f := fun i => (reachBall G (root i) M).ncard) (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) - -theorem rootNeighborMoment_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) - (p : unitInterval) : 0 ≤ rootNeighborMoment G hloc root weight p := - Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (neighborClusterMoment_nonneg G hloc p _)) - - - -theorem integral_exposedBoundaryPotential_uniform [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (x v : V) (M : ℕ) : - (∫ ω, ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M ∂law p) ≤ - (∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p := by - let B := (finite_reachBall hloc v M).toFinset - calc - _ ≤ ∑ a ∈ B, neighborClusterMoment G hloc p a := - (integral_exposedBoundaryPotential_le G hloc hqt p hp x v M).2 - _ ≤ ∑ _a ∈ B, c*rootNeighborMoment G hloc root weight p := - Finset.sum_le_sum (fun a _ => neighborMoment_le_rootMoment G hloc root weight hw hcover c hc hmin p a) - _ = (B.card:ℝ)*(c*rootNeighborMoment G hloc root weight p) := by rw [Finset.sum_const,nsmul_eq_mul] - _ ≤ _ := by - have hb : (B.card:ℝ) ≤ ∑ i, ((reachBall G (root i) M).ncard:ℝ) := by - exact_mod_cast reachBall_card_le_root_sum G hloc root hcover M v - simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hb - (mul_nonneg hc (rootNeighborMoment_nonneg G hloc root weight hw p)) - -end UniformExposedBoundary -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DistinctMomentPotential -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -theorem kernel_distinctMoment_integral [Countable V] [Countable E] [Nonempty V] - (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x v : V) : - (∑' y, q.kernel p v y * distinctClusterMoment G p x y) = - ∫ ω, (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) ∂law p := by - rw [integral_tsum_of_finite_support (law p) (finite_reachBall hloc v M).toFinset _ - (fun y => (integrable_freshExteriorMoment G hloc hqt p hp x y).const_mul (q.kernel p v y)) - (fun ω y hy => by rw [q.kernel_outside_ball_zero p v y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul])] - apply tsum_congr - intro y - rw [integral_const_mul,integral_freshExteriorMoment G hloc hqt p hp] - rfl - -theorem integrable_kernel_freshMoment [Countable V] [Countable E] [Nonempty V] - (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x v : V) : - Integrable (fun ω => ∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) (law p) := by - have he (ω) : (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) = - ∑ y ∈ (finite_reachBall hloc v M).toFinset, q.kernel p v y * freshExteriorMoment G p x y ω := - tsum_eq_sum (fun y hy => by rw [q.kernel_outside_ball_zero p v y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul]) - simp_rw [he] - exact integrable_finsetSum _ (fun y _ => (integrable_freshExteriorMoment G hloc hqt p hp x y).const_mul _) - - -theorem kernel_distinctMoment_bound [Countable V] [Countable E] [Nonempty V] - (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x v : V) : - (∑' y, q.kernel p v y * distinctClusterMoment G p x y) ≤ - (1+(1-(p:ℝ))/p*M)*distinctClusterMoment G p x v + - (p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p := by - let C := 1+(1-(p:ℝ))/p*M - let R := (p:ℝ)^(-(M:ℤ)) - let b := fun ω : Set E => ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M - have hi := (integral_exposedBoundaryPotential_le G hloc hqt p hpc x v M).1 - have hpoint (ω : Set E) : (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) ≤ - C*freshExteriorMoment G p x v ω + R*b ω := by - have h := mul_le_mul_of_nonneg_left (q.kernel_deleted_potential_bound hqt (cluster G ω x)ᶜ p hp hpc v) - (Nat.cast_nonneg (cluster G ω x).ncard : (0:ℝ) ≤ _) - rw [←tsum_mul_left] at h - calc - _ = ∑' y, ((cluster G ω x).ncard:ℝ)*(q.kernel p v y * inducedSusceptibility G (cluster G ω x)ᶜ p y) := by - apply tsum_congr - intro y - simp only [freshExteriorMoment] - ring - _ ≤ _ := h - _ = _ := by dsimp [C,R,b,freshExteriorMoment]; ring - rw [q.kernel_distinctMoment_integral hqt p hpc x v] - calc - _ ≤ ∫ ω, C*freshExteriorMoment G p x v ω + R*b ω ∂law p := - integral_mono (q.integrable_kernel_freshMoment hqt p hpc x v) - (((integrable_freshExteriorMoment G hloc hqt p hpc x v).const_mul C).add (hi.const_mul R)) hpoint - _ = C*distinctClusterMoment G p x v + R*(∫ ω, b ω ∂law p) := by - rw [integral_add ((integrable_freshExteriorMoment G hloc hqt p hpc x v).const_mul C) (hi.const_mul R), - integral_const_mul,integral_const_mul,integral_freshExteriorMoment G hloc hqt p hpc] - rfl - _ ≤ _ := by - have h := mul_le_mul_of_nonneg_left - (integral_exposedBoundaryPotential_uniform G hloc hqt root weight hw hcover c hc hmin p hpc x v M) - (zpow_nonneg p.2.1 (-(M:ℤ))) - dsimp [C,R,b] at * - nlinarith - -end LocalEndpointRule -end DistinctMomentPotential -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FinitePositiveOperatorPowers -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finite_positive_product_support (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hb : ∀ x, (Function.support (fun y => (matrixCoeff B x y).re)).Finite) (x : V) : - (Function.support (fun y => (matrixCoeff (A*B) x y).re)).Finite := by - let S := (ha x).toFinset - let T := S.biUnion (fun z => (hb z).toFinset) - apply T.finite_toSet.subset - intro y hy - by_contra hn - apply hy - change (matrixCoeff (A*B) x y).re = 0 - rw [←(hA.mul_hasSum B x y).tsum_eq] - rw [←tsum_zero] - apply tsum_congr - intro z - by_cases hz : z ∈ S - · have hzy : (matrixCoeff B z y).re = 0 := by - by_contra hh - apply hn - exact Finset.mem_biUnion.mpr ⟨z,hz,by simpa only [Set.Finite.mem_toFinset,Function.mem_support] using hh⟩ - rw [hzy,mul_zero] - · have hzx : (matrixCoeff A x z).re = 0 := by - simpa only [S,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz - rw [hzx,zero_mul] - -theorem finite_positive_product_action (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hb : ∀ x, (Function.support (fun y => (matrixCoeff B x y).re)).Finite) - (f : V → ℝ) (x : V) : - (∑' y, (matrixCoeff (A*B) x y).re*f y) = - ∑' z, (matrixCoeff A x z).re*∑' y, (matrixCoeff B z y).re*f y := by - let K := fun x y => (matrixCoeff A x y).re - let J := fun x y => (matrixCoeff B x y).re - let S := (ha x).toFinset - have hz (z : V) (hz : z ∉ S) : K x z = 0 := by - simpa only [S,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz - have he (y : V) : (matrixCoeff (A*B) x y).re*f y = ∑ z ∈ S, K x z*(J z y*f y) := by - rw [←(hA.mul_hasSum B x y).tsum_eq,tsum_eq_sum (s := S) - (fun z h => by change K x z*J z y = 0; rw [hz z h,zero_mul]),Finset.sum_mul] - exact Finset.sum_congr rfl (fun z _ => mul_assoc _ _ _) - have hs := hasSum_sum (s := S) (fun z _ => - (finiteKernel_summable_mul J hb z f).hasSum.mul_left (K x z)) - have hr : (∑' z, K x z*∑' y, J z y*f y) = ∑ z ∈ S, K x z*∑' y, J z y*f y := - tsum_eq_sum (fun z h => by rw [hz z h,zero_mul]) - simpa only [←he,←hr] using hs.tsum_eq - -theorem finite_positive_pow_support (A : Hilbert V →L[ℂ] Hilbert V) - (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (j : ℕ) (x : V) : (Function.support (fun y => (matrixCoeff (A^j) x y).re)).Finite := by - induction j generalizing x with - | zero => - apply (Set.finite_singleton x).subset - intro y hy - by_contra hn - apply hy - have he : x ≠ y := fun h => hn (by simp only [Set.mem_singleton_iff]; exact h.symm) - simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right he,Complex.zero_re] - | succ j ih => - rw [pow_succ'] - exact finite_positive_product_support A (A^j) hA ha ih x - -theorem positive_identity_action (f : V → ℝ) (x : V) : - (∑' y, (matrixCoeff (1 : Hilbert V →L[ℂ] Hilbert V) x y).re*f y) = f x := by - rw [tsum_eq_single x (fun y hy => by - simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right (Ne.symm hy),Complex.zero_re,zero_mul])] - simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_true,Complex.one_re,one_mul] - -end FinitePositiveOperatorPowers -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PositivePotentialIteration -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def realAction (A : Hilbert V →L[ℂ] Hilbert V) (f : V → ℝ) (x : V) : ℝ := - ∑' y, (matrixCoeff A x y).re*f y - -theorem realAction_mono (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (f g : V → ℝ) (hfg : ∀ x, f x ≤ g x) (x : V) : realAction A f x ≤ realAction A g x := by - exact (finiteKernel_summable_mul _ ha x f).tsum_le_tsum - (fun y => mul_le_mul_of_nonneg_left (hfg y) (hA x y).2) (finiteKernel_summable_mul _ ha x g) - -theorem realAction_affine (A : Hilbert V →L[ℂ] Hilbert V) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (f : V → ℝ) (a b : ℝ) (x : V) : - realAction A (fun y => a*f y+b) x = a*realAction A f x + b*realAction A (fun _ => 1) x := by - unfold realAction - simp_rw [mul_add] - rw [Summable.tsum_add] - · have he (y : V) : (matrixCoeff A x y).re*(a*f y) = a*((matrixCoeff A x y).re*f y) := by ring - simp_rw [he] - simp only [tsum_mul_left,tsum_mul_right,mul_one] - ring - · exact finiteKernel_summable_mul _ ha x (fun y => a*f y) - · exact finiteKernel_summable_mul _ ha x (fun _ => b) - -theorem realAction_pow_succ (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (j : ℕ) (f : V → ℝ) (x : V) : - realAction (A^(j+1)) f x = realAction A (realAction (A^j) f) x := by - rw [pow_succ'] - exact finite_positive_product_action A (A^j) hA ha (finite_positive_pow_support A hA ha j) f x - - - -theorem realAction_pow_potential_bound (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) - (f : V → ℝ) (Z B : ℝ) (hZ : 2 ≤ Z) (hB : 0 ≤ B) - (hf : ∀ x, realAction A f x ≤ Z*f x+B) (j : ℕ) (x : V) : - realAction (A^j) f x ≤ Z^j*f x + B*(Z^j-1) := by - have hz : 0 ≤ Z := by linarith - have hz1 : 1 ≤ Z := by linarith - induction j generalizing x with - | zero => - simp only [pow_zero,realAction,positive_identity_action,one_mul,sub_self,mul_zero,add_zero,le_refl] - | succ j ih => - rw [realAction_pow_succ A hA ha] - calc - _ ≤ realAction A (fun y => Z^j*f y+B*(Z^j-1)) x := realAction_mono A hA ha _ _ ih x - _ = Z^j*realAction A f x + (B*(Z^j-1))*realAction A (fun _ => 1) x := realAction_affine A ha f _ _ x - _ ≤ Z^j*(Z*f x+B) + B*(Z^j-1) := add_le_add - (mul_le_mul_of_nonneg_left (hf x) (pow_nonneg hz _)) - (by - simpa only [mul_one] using (mul_le_mul_of_nonneg_left (hrow x) - (mul_nonneg hB (sub_nonneg.mpr (one_le_pow₀ hz1))))) - _ ≤ Z^(j+1)*f x+B*(Z^(j+1)-1) := by - have hh := mul_nonneg (mul_nonneg hB (pow_nonneg hz j)) (show 0 ≤ Z-2 by linarith) - rw [pow_succ] - nlinarith only [hh] - -theorem realAction_pow_potential_at_zero (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) - (f : V → ℝ) (Z B : ℝ) (hZ : 2 ≤ Z) (hB : 0 ≤ B) - (hf : ∀ x, realAction A f x ≤ Z*f x+B) (j : ℕ) (x : V) (hx : f x = 0) : - realAction (A^j) f x ≤ B*Z^j := by - have h := realAction_pow_potential_bound A hA ha hrow f Z B hZ hB hf j x - rw [hx,mul_zero,zero_add] at h - nlinarith - -end PositivePotentialIteration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NormalizedPositiveOperator -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem normalized_operator_positive (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : PositiveRealMatrix A := by - intro x y - rw [hA] - exact ⟨rfl,mul_nonneg (inv_nonneg.mpr (q.successProbability_nonneg p o)) (q.kernel_nonneg p x y)⟩ - -theorem normalized_operator_finite (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) : - (Function.support (fun y => (matrixCoeff A x y).re)).Finite := by - apply (finite_reachBall hloc x M).subset - intro y hy - by_contra hn - apply hy - change (matrixCoeff A x y).re = 0 - simp only [hA,normalizedKernel,q.kernel_outside_ball_zero p x y hn,mul_zero,Complex.ofReal_zero,Complex.zero_re] - -theorem normalized_operator_action (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (f : V → ℝ) (x : V) : - realAction A f x = (q.successProbability p o)⁻¹ * (∑' y, q.kernel p x y*f y) := by - simp only [realAction,hA,Complex.ofReal_re,normalizedKernel,mul_assoc,tsum_mul_left] - -theorem normalized_operator_row_le (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (hu : 0 < q.successProbability p o) (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) : - realAction A (fun _ => 1) x ≤ 1 := by - rw [q.normalized_operator_action o p A hA] - simp only [mul_one] - calc - _ ≤ (q.successProbability p o)⁻¹ * q.successProbability p o := - mul_le_mul_of_nonneg_left (q.kernel_row_le_success o p x) (inv_nonneg.mpr hu.le) - _ = 1 := inv_mul_cancel₀ hu.ne' - -theorem normalized_operator_row_eq (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (hu : 0 < q.successProbability p o) (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) - (hx : x ∈ vertexOrbit G o) : realAction A (fun _ => 1) x = 1 := by - rw [q.normalized_operator_action o p A hA] - simp only [mul_one] - change (q.successProbability p o)⁻¹ * q.successProbability p x = 1 - rw [q.successProbability_orbit p o x hx,inv_mul_cancel₀ hu.ne'] - -theorem normalized_operator_invariant (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : - KernelInvariant (vertexAut G) A := by - rintro a ⟨b,hab⟩ x y - simp only [hA,normalizedKernel,q.kernel_covariant p a b hab] - -theorem normalized_operator_end_support (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) - (x y : V) (hy : y ∉ vertexOrbit G o) : (matrixCoeff A x y).re = 0 := by - simp only [hA,normalizedKernel,q.kernel_zero_of_end_not_mem p x y hy,mul_zero,Complex.ofReal_zero,Complex.zero_re] - -end LocalEndpointRule -end NormalizedPositiveOperator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UpperDistinctMomentIteration -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem distinctClusterMoment_self (G : BondGraph V E) (p : unitInterval) (x : V) : - distinctClusterMoment G p x x = 0 := by - have hs (ω : Set E) : Conn G ω x x := .refl - simp only [distinctClusterMoment,hs,not_true_eq_false,ite_false,integral_zero] - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem normalized_power_distinctMoment_upper [Countable V] [Countable E] [Nonempty V] - (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) - (hu : 0 < q.successProbability p o) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) - (Z : ℝ) (hZ : 2 ≤ Z) - (hscale : (q.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*M) ≤ Z) - (j : ℕ) (x : V) : - realAction (A^j) (distinctClusterMoment G p x) x ≤ - ((q.successProbability p o)⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* - rootNeighborMoment G hloc root weight p * Z^j := by - let B := ((q.successProbability p o)⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* - rootNeighborMoment G hloc root weight p - have hB : 0 ≤ B := by - exact mul_nonneg (mul_nonneg (mul_nonneg - (mul_nonneg (inv_nonneg.mpr hu.le) (zpow_nonneg p.2.1 _)) - (Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _))) hc) - (rootNeighborMoment_nonneg G hloc root weight hw p) - have hf (v : V) : realAction A (distinctClusterMoment G p x) v ≤ Z*distinctClusterMoment G p x v+B := by - rw [q.normalized_operator_action o p A hA] - calc - _ ≤ (q.successProbability p o)⁻¹ * - ((1+(1-(p:ℝ))/p*M)*distinctClusterMoment G p x v+ - (p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p) := - mul_le_mul_of_nonneg_left - (q.kernel_distinctMoment_bound hqt root weight hw hcover c hc hmin p hp hpc x v) (inv_nonneg.mpr hu.le) - _ = ((q.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*M))*distinctClusterMoment G p x v+B := by dsimp [B]; ring - _ ≤ _ := by - have hh := mul_le_mul_of_nonneg_right hscale (distinctClusterMoment_nonneg G p x v) - linarith - exact realAction_pow_potential_at_zero A (q.normalized_operator_positive o p A hA) - (q.normalized_operator_finite o p A hA) (q.normalized_operator_row_le o p hu A hA) - (distinctClusterMoment G p x) Z B hZ hB hf j x (distinctClusterMoment_self G p x) - -end LocalEndpointRule -end UpperDistinctMomentIteration -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section PositivePowerStochasticity -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem realAction_pow_row_le (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) (j : ℕ) (x : V) : - realAction (A^j) (fun _ => 1) x ≤ 1 := by - induction j generalizing x with - | zero => rw [pow_zero]; exact (positive_identity_action (fun _ => 1) x).le - | succ j ih => - rw [realAction_pow_succ A hA ha] - exact (realAction_mono A hA ha _ (fun _ => 1) ih x).trans (hrow x) - -theorem positive_pow_end_support (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (O : Set V) (hO : ∀ x y, y ∉ O → (matrixCoeff A x y).re = 0) - (j : ℕ) (x y : V) (hx : x ∈ O) (hy : y ∉ O) : (matrixCoeff (A^j) x y).re = 0 := by - cases j with - | zero => - have hxy : x ≠ y := fun h => hy (h ▸ hx) - simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right hxy,Complex.zero_re] - | succ j => - rw [pow_succ,←((hA.pow j).mul_hasSum A x y).tsum_eq] - simp only [hO _ y hy,mul_zero,tsum_zero] - -theorem realAction_pow_row_eq_on (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (O : Set V) (hO : ∀ x y, y ∉ O → (matrixCoeff A x y).re = 0) - (hrow : ∀ x ∈ O, realAction A (fun _ => 1) x = 1) - (j : ℕ) (x : V) (hx : x ∈ O) : realAction (A^j) (fun _ => 1) x = 1 := by - induction j generalizing x with - | zero => rw [pow_zero]; exact positive_identity_action (fun _ => 1) x - | succ j ih => - rw [realAction_pow_succ A hA ha] - calc - _ = realAction A (fun _ => 1) x := by - apply tsum_congr - intro y - by_cases hy : y ∈ O - · rw [ih y hy] - · rw [hO x y hy,zero_mul,zero_mul] - _ = 1 := hrow x hx - -end PositivePowerStochasticity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ConnectedMomentLoss -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def connectedClusterMoment (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := - ∫ ω, (if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) ∂law p - -theorem integrable_connected_cluster_square [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (fun ω => if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) (law p) := by - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - have he : (fun ω : Set E => if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) = - {ω | Conn G ω x y}.indicator (fun ω => ((cluster G ω x).ncard:ℝ)^2) := by - funext ω - simp only [Set.indicator,Set.mem_ofPred_eq] - rw [he] - exact (hs x).1.indicator (measurableSet_conn G x y) - -theorem distinct_add_connected_cluster_moment [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - distinctClusterMoment G p x y + connectedClusterMoment G p x y = - ∫ ω, ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) ∂law p := by - rw [distinctClusterMoment,connectedClusterMoment, - ←integral_add (integrable_distinct_cluster_product G hloc hqt p hp x y) - (integrable_connected_cluster_square G hloc hqt p hp x y)] - apply integral_congr_ae - exact Filter.Eventually.of_forall (fun ω => by - by_cases h : Conn G ω x y - · simp only [h,not_true_eq_false,ite_false,ite_true,zero_add,cluster_eq_of_conn G ω h,pow_two] - · simp only [h,not_false_eq_true,ite_true,ite_false,add_zero]) - -theorem distinctClusterMoment_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - susceptibility G p x * susceptibility G p y - connectedClusterMoment G p x y ≤ - distinctClusterMoment G p x y := by - have h := (subcritical_cluster_association G hloc hqt p hp x y).2 - rw [←distinct_add_connected_cluster_moment G hloc hqt p hp] at h - linarith - - -theorem realAction_connectedMoment_eq_diagonalLoss [Countable V] [Countable E] - (G : BondGraph V E) (o : V) (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) - (x : V) (hend : ∀ y, y ∉ vertexOrbit G o → (matrixCoeff A x y).re = 0) - (p : unitInterval) (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : - realAction A (connectedClusterMoment G p x) x = - ∫ ω, diagonalLossMass G o (fun a b => (matrixCoeff A a b).re) ω x ∂law p := by - have hr (z : V) (S : Finset V) : (∑ y ∈ S, (matrixCoeff A z y).re) ≤ 1 := by - have hsrow : Summable (fun y => (matrixCoeff A z y).re) := by - simpa only [mul_one] using finiteKernel_summable_mul (fun a b => (matrixCoeff A a b).re) ha z (fun _ => 1) - exact (hsrow.sum_le_tsum S (fun y _ => (hA z y).2)).trans (by simpa only [realAction,mul_one] using hrow z) - rw [integral_diagonalLoss_eq_series G o _ (fun a b => (hA a b).2) 1 hr x p hs] - apply tsum_congr - intro y - by_cases hy : y ∈ vertexOrbit G o - · rw [ite_eq_left hy] - rfl - · simp only [ite_eq_right hy,hend y hy,zero_mul] - -end ConnectedMomentLoss -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LowerDistinctMomentOperator -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem realAction_distinctMoment_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : p < pc G) (b : ℝ) (hb : 0 ≤ b) - (hχ : ∀ x, b ≤ susceptibility G p x) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) - (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) - (hinv : KernelInvariant (vertexAut G) A) - (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) - (heq : realAction A (fun _ => 1) (root i₀) = 1) - (hend : ∀ y, y ∉ vertexOrbit G (root i₀) → (matrixCoeff A (root i₀) y).re = 0) : - b^2-‖A‖*(c*rootSusceptibility G root weight p)^3 ≤ - realAction A (distinctClusterMoment G p (root i₀)) (root i₀) := by - let x := root i₀ - let f := connectedClusterMoment G p x - have hr (z : V) (S : Finset V) : (∑ y ∈ S, (matrixCoeff A z y).re) ≤ 1 := by - have hsrow : Summable (fun y => (matrixCoeff A z y).re) := by - simpa only [mul_one] using finiteKernel_summable_mul (fun a b => (matrixCoeff A a b).re) ha z (fun _ => 1) - exact (hsrow.sum_le_tsum S (fun y _ => (hA z y).2)).trans (by simpa only [realAction,mul_one] using hrow z) - obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp - have hf : realAction A f x ≤ ‖A‖*(c*rootSusceptibility G root weight p)^3 := by - rw [realAction_connectedMoment_eq_diagonalLoss G (root i₀) A hA ha hrow x hend p (hs x).1] - exact diagonalLoss_le_rootSusceptibility_cube G hloc hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hp - (fun a b => (matrixCoeff A a b).re) (fun a b => (hA a b).2) - (fun a b hab z y => congrArg Complex.re (hinv a ⟨b,hab⟩ z y)) 1 hr A (hA.real) - have hpnt (y : V) : (-1)*f y+b^2 ≤ distinctClusterMoment G p x y := by - have h := distinctClusterMoment_lower G hloc hqt p hp x y - have hprod : b*b ≤ susceptibility G p x * susceptibility G p y := - mul_le_mul (hχ x) (hχ y) hb (susceptibility_nonneg G p x) - dsimp [f] - nlinarith only [h,hprod] - have hi := realAction_mono A hA ha (fun y => (-1)*f y+b^2) - (distinctClusterMoment G p x) hpnt x - rw [realAction_affine A ha f (-1) (b^2) x,heq] at hi - nlinarith only [hi,hf] - -end LowerDistinctMomentOperator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section DistinctMomentSandwich -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem normalized_power_moment_sandwich [Countable V] [Countable E] [Nonempty V] - (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) - (hu : 0 < q.successProbability p (root i₀)) - (A : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) - (a : ℝ) (ha : 0 ≤ a) (hχ : ∀ x, a*rootSusceptibility G root weight p ≤ susceptibility G p x) - (Z : ℝ) (hZ : 2 ≤ Z) - (hscale : (q.successProbability p (root i₀))⁻¹*(1+(1-(p:ℝ))/p*M) ≤ Z) (j : ℕ) : - (a*rootSusceptibility G root weight p)^2 - ‖A‖^j*(c*rootSusceptibility G root weight p)^3 ≤ - ((q.successProbability p (root i₀))⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* - rootNeighborMoment G hloc root weight p * Z^j := by - have hpos := q.normalized_operator_positive (root i₀) p A hA - have hfin := q.normalized_operator_finite (root i₀) p A hA - have hrow := q.normalized_operator_row_le (root i₀) p hu A hA - have hend := q.normalized_operator_end_support (root i₀) p A hA - have hx : root i₀ ∈ vertexOrbit G (root i₀) := ⟨Equiv.refl V,Equiv.refl E,(fun _ => by simp),rfl⟩ - have hlo := realAction_distinctMoment_lower G hloc hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hpc - (a*rootSusceptibility G root weight p) (mul_nonneg ha (rootSusceptibility_nonneg G root weight hw p)) hχ - (A^j) (hpos.pow j) (finite_positive_pow_support A hpos hfin j) - ((q.normalized_operator_invariant (root i₀) p A hA).pow j) - (realAction_pow_row_le A hpos hfin hrow j) - (realAction_pow_row_eq_on A hpos hfin _ hend - (q.normalized_operator_row_eq (root i₀) p hu A hA) j (root i₀) hx) - (positive_pow_end_support A hpos _ hend j (root i₀) · hx) - have hhi := q.normalized_power_distinctMoment_upper (root i₀) hqt root weight hw hcover c hc hmin p hp hpc hu A hA Z hZ hscale j (root i₀) - have hpow : ‖A^j‖ ≤ ‖A‖^j := by - cases j with - | zero => - simp only [pow_zero] - have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext x; rfl - rw [he] - exact ContinuousLinearMap.norm_id_le - | succ j => exact norm_pow_le' A (Nat.succ_pos j) - have hn := mul_le_mul_of_nonneg_right hpow - (pow_nonneg (mul_nonneg hc (rootSusceptibility_nonneg G root weight hw p)) 3) - linarith - -end LocalEndpointRule -end DistinctMomentSandwich -end Percolation - - -namespace Percolation -section LogarithmicPowerChoice - - - -theorem exists_logarithmic_power (r h Z T : ℝ) (hr : 0 ≤ r) (hh : 0 < h) - (hrh : r ≤ Real.exp (-h)) (hZ : 1 ≤ Z) (hT : 1 ≤ T) : - ∃ j : ℕ, r^j ≤ T⁻¹ ∧ Z^j ≤ Z*T^(Real.log Z/h) := by - let t := Real.log T/h - have ht : 0 ≤ t := div_nonneg (Real.log_nonneg hT) hh.le - let j := Nat.ceil t - have hlo : t ≤ (j:ℝ) := Nat.le_ceil t - have hhi : (j:ℝ) ≤ t+1 := (Nat.ceil_lt_add_one ht).le - have hTp : 0 < T := zero_lt_one.trans_le hT - have hZp : 0 < Z := zero_lt_one.trans_le hZ - have hlogZ : 0 ≤ Real.log Z := Real.log_nonneg hZ - refine ⟨j,?_,?_⟩ - · calc - r^j ≤ (Real.exp (-h))^j := pow_le_pow_left₀ hr hrh j - _ = Real.exp ((j:ℝ)*(-h)) := (Real.exp_nat_mul _ _).symm - _ ≤ Real.exp (-Real.log T) := by - apply Real.exp_le_exp.mpr - have hl : Real.log T ≤ (j:ℝ)*h := (div_le_iff₀ hh).mp hlo - nlinarith - _ = T⁻¹ := by rw [Real.exp_neg,Real.exp_log hTp] - · calc - Z^j = Real.exp ((j:ℝ)*Real.log Z) := by rw [Real.exp_nat_mul,Real.exp_log hZp] - _ ≤ Real.exp ((t+1)*Real.log Z) := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hlogZ) - _ = Z*T^(Real.log Z/h) := by - rw [Real.rpow_def_of_pos hTp,←Real.exp_log hZp,←Real.exp_add] - simp only [Real.log_exp] - congr 1 - dsimp [t] - ring - - - -theorem moment_sandwich_power_law (a c C Z h r χ N : ℝ) - (ha : 0 < a) (hc : 0 ≤ c) (hC : 0 < C) (hZ : 1 ≤ Z) (hh : 0 < h) - (hr : 0 ≤ r) (hrh : r ≤ Real.exp (-h)) (hχ : 1 ≤ χ) (hN : 0 ≤ N) - (hs : ∀ j : ℕ, (a*χ)^2-r^j*(c*χ)^3 ≤ C*N*Z^j) : - let T := 1+2*c^3/a^2 - a^2/(2*C*Z*T^(Real.log Z/h))*χ^(2-Real.log Z/h) ≤ N := by - let T := 1+2*c^3/a^2 - have hap : 0 < a^2 := sq_pos_of_pos ha - have hT : 1 ≤ T := by - have hn : 0 ≤ 2*c^3/a^2 := by positivity - dsimp [T] - linarith - have hTp : 0 < T := zero_lt_one.trans_le hT - have hχp : 0 < χ := zero_lt_one.trans_le hχ - have hZp : 0 < Z := zero_lt_one.trans_le hZ - have hTx : 1 ≤ T*χ := by nlinarith - obtain ⟨j,hrj,hZj⟩ := exists_logarithmic_power r h Z (T*χ) hr hh hrh hZ hTx - have hbudget : 2*c^3 ≤ a^2*T := by dsimp [T]; field_simp; nlinarith - have hsmall : r^j*(c*χ)^3 ≤ a^2/2*χ^2 := by - calc - _ ≤ (T*χ)⁻¹*(c*χ)^3 := mul_le_mul_of_nonneg_right hrj (pow_nonneg (mul_nonneg hc hχp.le) _) - _ = c^3/T*χ^2 := by field_simp - _ ≤ a^2/2*χ^2 := mul_le_mul_of_nonneg_right ((div_le_iff₀ hTp).mpr (by nlinarith [hbudget])) (sq_nonneg χ) - have hlarge : a^2/2*χ^2 ≤ C*N*(Z*(T*χ)^(Real.log Z/h)) := by - have hs' := hs j - have hprod := mul_le_mul_of_nonneg_left hZj (mul_nonneg hC.le hN) - nlinarith only [hsmall,hs',hprod] - have hpow : 0 < χ^(Real.log Z/h) := Real.rpow_pos_of_pos hχp _ - have hTpow : 0 < T^(Real.log Z/h) := Real.rpow_pos_of_pos hTp _ - have he : C*N*(Z*(T*χ)^(Real.log Z/h)) = - (C*Z*T^(Real.log Z/h))*N*χ^(Real.log Z/h) := by - rw [Real.mul_rpow hTp.le hχp.le] - ring - rw [he] at hlarge - have hden : 0 < 2*C*Z*T^(Real.log Z/h) := by positivity - change a^2/(2*C*Z*T^(Real.log Z/h))*χ^(2-Real.log Z/h) ≤ N - rw [Real.rpow_sub hχp,Real.rpow_two] - calc - _ = (a^2*χ^2)/(2*C*Z*T^(Real.log Z/h)*χ^(Real.log Z/h)) := by - rw [div_mul_div_comm] - _ ≤ N := (div_le_iff₀ (mul_pos hden hpow)).mpr (by nlinarith only [hlarge]) - -end LogarithmicPowerChoice -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section ProfileContinuity -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} - -theorem exp_neg_H (q : EndpointProfile G hloc p₀ o s) : Real.exp (-q.H) = ‖q.op‖ := by - rw [H,one_div,Real.log_inv,neg_neg,Real.exp_log q.norm_pos] - - - -theorem exists_nearby_operators {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : EndpointProfile G hloc p₀ (root i₀) s) (hp₀ : 0 < (p₀:ℝ)) : - ∃ A : unitInterval → (Hilbert V →L[ℂ] Hilbert V), - (∀ p x y, matrixCoeff (A p) x y = (q.rule.normalizedKernel (root i₀) p x y : ℂ)) ∧ - ∀ᶠ p in nhds p₀, q.rule.successProbability p₀ (root i₀)/2 ≤ q.rule.successProbability p (root i₀) ∧ - ‖A p‖ ≤ Real.exp (-(q.H-1)) ∧ (p₀:ℝ)/2 ≤ (p:ℝ) := by - obtain ⟨A,_,hA,hcont⟩ := q.rule.exists_continuous_normalized_operators root weight Γ htr hΓ hw i₀ hw₀ - have he : A p₀ = q.op := kernel_extension_unique (hA p₀) q.coeff - have hnorm : ContinuousAt (fun p => ‖A p‖) p₀ := (hcont p₀ q.success_pos.ne').norm - have hb : ‖A p₀‖ < Real.exp (-(q.H-1)) := by - rw [he,←q.exp_neg_H] - exact Real.exp_lt_exp.mpr (by linarith) - have ha := hnorm.eventually_lt continuousAt_const hb - have hu : ∀ᶠ p in nhds p₀, q.rule.successProbability p₀ (root i₀)/2 < q.rule.successProbability p (root i₀) := - continuousAt_const.eventually_lt (q.rule.continuous_successProbability (root i₀)).continuousAt (by linarith [q.success_pos]) - have hp : ∀ᶠ p : unitInterval in nhds p₀, (p₀:ℝ)/2 < (p:ℝ) := - continuousAt_const.eventually_lt continuous_subtype_val.continuousAt (by linarith) - refine ⟨A,hA,?_⟩ - filter_upwards [ha,hu,hp] with p ha hu hp - exact ⟨hu.le,ha.le,hp.le⟩ - -end EndpointProfile -end ProfileContinuity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section MapScaleBudget -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} - -noncomputable def potentialScale (q : EndpointProfile G hloc p₀ o s) (p : unitInterval) : ℝ := - (q.rule.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*q.cap) - -noncomputable def geometricScale (q : EndpointProfile G hloc p₀ o s) : ℝ := 2*q.potentialScale p₀ - -theorem potentialScale_pos (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : - 0 < q.potentialScale p₀ := by - exact mul_pos (inv_pos.mpr q.success_pos) (by - have hn : 0 ≤ (1-(p₀:ℝ))/p₀*q.cap := mul_nonneg (div_nonneg (sub_nonneg.mpr p₀.2.2) hp₀.le) (Nat.cast_nonneg _) - linarith) - -theorem geometricScale_two_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : - 2 ≤ q.geometricScale := by - have hu : 1 ≤ (q.rule.successProbability p₀ o)⁻¹ := - (one_le_inv₀ q.success_pos).mpr (q.rule.successProbability_le_one p₀ o) - have hb : 0 ≤ (1-(p₀:ℝ))/p₀*q.cap := - mul_nonneg (div_nonneg (sub_nonneg.mpr p₀.2.2) hp₀.le) (Nat.cast_nonneg _) - dsimp [geometricScale,potentialScale] - nlinarith - -theorem log_geometricScale_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) - (hM : 1 ≤ q.cap) : - Real.log q.geometricScale ≤ q.U+q.m+Real.log (2*(1+1/(p₀:ℝ))) := by - have hM' : (1:ℝ) ≤ q.cap := by exact_mod_cast hM - have hMp : (0:ℝ) < q.cap := zero_lt_one.trans_le hM' - have hb : 1+(1-(p₀:ℝ))/p₀*q.cap ≤ (1+1/(p₀:ℝ))*q.cap := by - apply (mul_le_mul_iff_of_pos_right hp₀).mp - field_simp - nlinarith - have Hz : q.geometricScale ≤ (1/q.rule.successProbability p₀ o)*(q.cap:ℝ)*(2*(1+1/(p₀:ℝ))) := by - have h := mul_le_mul_of_nonneg_left hb (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) (inv_nonneg.mpr q.success_pos.le)) - simpa only [geometricScale,potentialScale,one_div,mul_assoc,mul_comm,mul_left_comm] using h - have hc : 0 < 2*(1+1/(p₀:ℝ)) := by positivity - have h := Real.log_le_log (lt_of_lt_of_le (by norm_num : (0:ℝ)<2) (q.geometricScale_two_le hp₀)) Hz - rw [Real.log_mul (mul_ne_zero (one_div_ne_zero q.success_pos.ne') hMp.ne') hc.ne', - Real.log_mul (one_div_ne_zero q.success_pos.ne') hMp.ne'] at h - exact h - -theorem eventually_potentialScale_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : - ∀ᶠ p in nhds p₀, q.potentialScale p ≤ q.geometricScale := by - have hu := (q.rule.continuous_successProbability o).continuousAt.inv₀ q.success_pos.ne' - have hv : ContinuousAt (fun p : unitInterval => ((1-(p:ℝ))/p)) p₀ := - (continuousAt_const.sub continuous_subtype_val.continuousAt).div continuous_subtype_val.continuousAt hp₀.ne' - have he : ContinuousAt q.potentialScale p₀ := hu.mul (continuousAt_const.add (hv.mul continuousAt_const)) - have hlt : q.potentialScale p₀ < q.geometricScale := by - dsimp only [geometricScale] - linarith [q.potentialScale_pos hp₀] - filter_upwards [he.eventually_lt continuousAt_const hlt] with p hp - exact hp.le - -end EndpointProfile -end MapScaleBudget -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section ProfileNeighborMoment -attribute [local instance] Classical.propDecidable Classical.decEq -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} - - - -theorem eventually_neighborMoment_lower [Countable V] [Countable E] [Nonempty V] - (hconn : Connected G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (q : EndpointProfile G hloc p₀ (root i₀) s) (hp₀ : 0 < (p₀:ℝ)) (hH : 1 < q.H) : - ∃ b : ℝ, 0 < b ∧ ∀ᶠ p in nhds p₀, p < pc G → - b*(rootSusceptibility G root weight p)^(2-Real.log q.geometricScale/(q.H-1)) ≤ - rootNeighborMoment G hloc root weight p := by - obtain ⟨a,ha,hχ⟩ := exists_rootSusceptibility_lower G hconn hloc hqt root weight hw hw1 hcover - ((p₀:ℝ)/2) (by linarith) - obtain ⟨A,hA,hnear⟩ := q.exists_nearby_operators root weight Γ htr hΓ hw i₀ hw₀ hp₀ - let B : unitInterval → ℝ := fun p => - (q.rule.successProbability p (root i₀))⁻¹*(p:ℝ)^(-(q.cap:ℤ))*(∑ i, ((reachBall G (root i) q.cap).ncard:ℝ))*c - have hB (p : unitInterval) : 0 ≤ B p := by - dsimp [B] - exact mul_nonneg (mul_nonneg (mul_nonneg (inv_nonneg.mpr (q.rule.successProbability_nonneg p _)) - (zpow_nonneg p.2.1 _)) (Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _))) hc - have hBc : ContinuousAt B p₀ := by - exact ((((q.rule.continuous_successProbability (root i₀)).continuousAt.inv₀ q.success_pos.ne').mul - (continuous_subtype_val.continuousAt.zpow₀ (-(q.cap:ℤ)) (Or.inl hp₀.ne'))).mul continuousAt_const).mul continuousAt_const - let C := B p₀+1 - have hC : 0 < C := by dsimp [C]; linarith [hB p₀] - have hCB : ∀ᶠ p in nhds p₀, B p ≤ C := by - filter_upwards [hBc.eventually_lt continuousAt_const (show B p₀ < C by dsimp [C]; linarith)] with p hp - exact hp.le - let Z := q.geometricScale - let h := q.H-1 - let T := 1+2*c^3/a^2 - let b := a^2/(2*C*Z*T^(Real.log Z/h)) - have hz : 2 ≤ Z := q.geometricScale_two_le hp₀ - have ht : 0 < T := by - have hh : 0 ≤ 2*c^3/a^2 := by positivity - dsimp [T] - linarith - have hb : 0 < b := div_pos (sq_pos_of_pos ha) (by - have hp := Real.rpow_pos_of_pos ht (Real.log Z/h) - have hZp : 0 < Z := by linarith - positivity) - refine ⟨b,hb,?_⟩ - filter_upwards [hnear,hCB,q.eventually_potentialScale_le hp₀] with p hnear hCB hscale - intro hpc - obtain ⟨hu,hAn,hpp⟩ := hnear - have hp : 0 < (p:ℝ) := lt_of_lt_of_le (by linarith : 0 < (p₀:ℝ)/2) hpp - have hup : 0 < q.rule.successProbability p (root i₀) := - lt_of_lt_of_le (by linarith [q.success_pos]) hu - have hχ1 : 1 ≤ rootSusceptibility G root weight p := by - calc - 1 = ∑ i, weight i*1 := by simp only [mul_one,hw1] - _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left - (susceptibility_one_le G hloc hqt p hpc (root i)) (hw i)) - apply moment_sandwich_power_law a c C Z h ‖A p‖ (rootSusceptibility G root weight p) - (rootNeighborMoment G hloc root weight p) ha hc hC (by linarith) (by dsimp [h]; linarith) - (norm_nonneg _) hAn hχ1 (rootNeighborMoment_nonneg G hloc root weight hw p) - intro j - have hs := q.rule.normalized_power_moment_sandwich hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hp hpc hup - (A p) (hA p) a ha.le (hχ p hpp hpc) Z hz hscale j - exact hs.trans (mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_right hCB (rootNeighborMoment_nonneg G hloc root weight hw p)) (pow_nonneg (by linarith) j)) - -end EndpointProfile -end ProfileNeighborMoment -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section EfficientProfileMomentConsequence -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem neighborMoment_growth_of_divergent_moment - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (p₀ : unitInterval) (hp₀ : 0 < (p₀:ℝ)) (hp₁ : (p₀:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law p₀, (cluster G ω (root i)).Finite) - (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) - (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) - (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p₀)) : - ∀ γ : ℝ, 0 < γ → ∃ b : ℝ, 0 < b ∧ ∀ᶠ p in nhds p₀, p < pc G → - b*(rootSusceptibility G root weight p)^(2-γ) ≤ rootNeighborMoment G hloc root weight p := by - obtain ⟨i,heff⟩ := efficient_endpoint_profiles_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr - hcov hw hw1 p₀ hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - let c : ℝ := ∑ i, 1/weight i - have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) - have hmin (i : ι) : 1 ≤ c*weight i := by - apply (div_le_iff₀ (hw i)).mp - exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) - intro γ hγ - let C := Real.log (2*(1+1/(p₀:ℝ))) - have hC : 0 ≤ C := Real.log_nonneg (by - have hinv : 0 ≤ 1/(p₀:ℝ) := (one_div_pos.mpr hp₀).le - nlinarith) - obtain ⟨q,hM,hH,hR,hcost⟩ := heff (γ/4) (by linarith) (2+4*C/γ) - have hH2 : 2 < q.H := by - have hn : 0 ≤ 4*C/γ := div_nonneg (mul_nonneg (by norm_num) hC) hγ.le - linarith - have hCsmall : C < γ*q.H/4 := by - have hx : 4*C < (q.H-2)*γ := (div_lt_iff₀ hγ).mp (by linarith : 4*C/γ < q.H-2) - nlinarith - have hexp : Real.log q.geometricScale/(q.H-1) ≤ γ := by - apply (div_le_iff₀ (by linarith : 0 < q.H-1)).mpr - have hz := q.log_geometricScale_le hp₀ (by omega) - have hm : γ*q.H/2 ≤ γ*(q.H-1) := by nlinarith - dsimp [C] at hCsmall - nlinarith only [hz,hcost,hCsmall,hm] - obtain ⟨b,hb,hnear⟩ := q.eventually_neighborMoment_lower hconn hqt root weight Γ htr - (fun a ha => hΓ ha) (fun i => (hw i).le) hw1 i (hw i) hcover c hc hmin hp₀ hH - refine ⟨b,hb,?_⟩ - filter_upwards [hnear] with p hp - intro hpc - have hχ : 1 ≤ rootSusceptibility G root weight p := by - calc - 1 = ∑ i, weight i*1 := by simp only [mul_one,hw1] - _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left - (susceptibility_one_le G hloc hqt p hpc (root i)) (hw i).le) - exact (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_exponent_le hχ (by linarith : - 2-γ ≤ 2-Real.log q.geometricScale/(q.H-1))) hb.le).trans (hp hpc) - -end EfficientProfileMomentConsequence -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory ProbabilityTheory Function -section PivotalSprinklingGain -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_set_union_pair : Measurable (fun f : Set E × Set E => f.1 ∪ f.2) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - apply measurableSet_setOfPred.mp - change MeasurableSet ({f : Set E × Set E | e ∈ f.1} ∪ {f | e ∈ f.2}) - apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_fst - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_snd - -theorem measurable_set_insert (e : E) : Measurable (fun ω : Set E => insert e ω) := by - have h : Measurable (fun ω : Set E => ({e}:Set E) ∪ ω) := - measurable_set_union_pair.comp (measurable_const.prodMk measurable_id) - simpa only [Set.singleton_union] using (h : Measurable (fun ω : Set E => {e} ∪ ω)) - -theorem measurableSet_closedPivotal (A : Set (Set E)) (hA : MeasurableSet A) (e : E) : - MeasurableSet (closedPivotal A e) := by - exact (measurableSet_mem e).compl.inter (hA.compl.inter (hA.preimage (measurable_set_insert e))) - -def singleSprinkle (Q : Finset E) (e : (Q : Set E)) : Set (Set E) := - {η | Subtype.val ⁻¹' η = {e}} - -theorem measurableSet_singleSprinkle (Q : Finset E) (e : (Q : Set E)) : - MeasurableSet (singleSprinkle Q e) := - (measurableSet_singleton _).preimage (measurable_set_restrict (Q:Set E)) - -theorem singleSprinkle_disjoint (Q : Finset E) : - Pairwise (Disjoint on singleSprinkle Q) := by - intro a b hab - apply Set.disjoint_left.mpr - intro η ha hb - apply hab - have h : ({a} : Set (Q:Set E)) = {b} := ha.symm.trans hb - simpa only [Set.singleton_eq_singleton_iff] using h - -theorem singleSprinkle_mem (Q : Finset E) (e : (Q:Set E)) {η : Set E} - (hη : η ∈ singleSprinkle Q e) : e.val ∈ η := by - have h : e ∈ Subtype.val ⁻¹' η := by rw [hη]; exact Set.mem_singleton e - exact h - -theorem singleSprinkle_probability (Q : Finset E) (e : (Q:Set E)) (a : unitInterval) : - (law a).real (singleSprinkle Q e) = (a:ℝ)*(1-(a:ℝ))^(Q.card-1) := by - have h := congrArg (fun μ : Measure (Set (Q:Set E)) => μ.real {({e}:Set (Q:Set E))}) - (law_map_restrict a (Q:Set E)) - rw [Measure.real,Measure.map_apply (measurable_set_restrict _) (measurableSet_singleton _)] at h - change (law a).real (singleSprinkle Q e) = _ at h - rw [h,law,setBernoulli_real_singleton a (Set.subset_univ _) Set.finite_univ, - Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ,Set.ncard_singleton] - simp only [Set.ncard_univ,Nat.card_eq_fintype_card,pow_one] - rw [show Fintype.card (Q:Set E) = Q.card from Fintype.card_coe Q] - - - -theorem event_sprinkling_gain (p a : unitInterval) (Q : Finset E) - (A : Set (Set E)) (hA : MeasurableSet A) (hup : IsUpperSet A) : - (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * (∑ e ∈ Q, (law p).real (closedPivotal A e)) ≤ - (law (sprinkleParameter p a)).real A - (law p).real A := by - let μ : Measure (Set E × Set E) := (law p).prod (law a) - let B : Set (Set E × Set E) := {f | f.1 ∉ A ∧ f.1 ∪ f.2 ∈ A} - let C (e : (Q:Set E)) := (closedPivotal A e.val) ×ˢ singleSprinkle Q e - have hB : MeasurableSet B := (hA.compl.preimage measurable_fst).inter (hA.preimage measurable_set_union_pair) - have hC (e : (Q:Set E)) : MeasurableSet (C e) := - (measurableSet_closedPivotal A hA e.val).prod (measurableSet_singleSprinkle Q e) - have hd : Pairwise (Disjoint on C) := by - intro e f hef - apply Set.disjoint_left.mpr - intro z hz hz' - exact Set.disjoint_left.mp (singleSprinkle_disjoint Q hef) hz.2 hz'.2 - have hsub : (⋃ e, C e) ⊆ B := by - intro z hz - obtain ⟨e,he⟩ := Set.mem_iUnion.mp hz - refine ⟨he.1.2.1,?_⟩ - apply hup _ he.1.2.2 - intro f hf - rcases Set.mem_insert_iff.mp hf with rfl | hf - · exact Or.inr (singleSprinkle_mem Q e he.2) - · exact Or.inl hf - have hgain : μ.real B = (law (sprinkleParameter p a)).real A - (law p).real A := by - have he : (fun f : Set E × Set E => f.1 ∪ f.2) ⁻¹' A = (A ×ˢ Set.univ) ∪ B := by - ext f - simp only [Set.mem_preimage,Set.mem_union,Set.mem_prod,Set.mem_univ,and_true,B,Set.mem_ofPred_eq] - exact ⟨fun h => by by_cases ha : f.1 ∈ A; exact Or.inl ha; exact Or.inr ⟨ha,h⟩, - fun h => h.elim (fun ha => hup Set.subset_union_left ha) And.right⟩ - have hd : Disjoint (A ×ˢ (Set.univ : Set (Set E))) B := by - apply Set.disjoint_left.mpr - intro f hf hf' - exact hf'.1 hf.1 - have hm := congrArg (fun ν : Measure (Set E) => ν.real A) (law_map_union p a) - rw [Measure.real,Measure.map_apply measurable_set_union_pair hA] at hm - change μ.real ((fun f : Set E × Set E => f.1 ∪ f.2) ⁻¹' A) = _ at hm - rw [he,measureReal_union hd hB] at hm - have hp : μ.real (A ×ˢ Set.univ) = (law p).real A := by - rw [measureReal_prod_prod,probReal_univ,mul_one] - rw [hp] at hm - linarith - have hs : μ.real (⋃ e, C e) = - (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * (∑ e ∈ Q, (law p).real (closedPivotal A e)) := by - rw [measureReal_iUnion_fintype hd hC] - simp only [C,μ,measureReal_prod_prod,singleSprinkle_probability] - rw [←Finset.sum_mul,mul_comm] - congr 1 - apply Finset.sum_bij (fun e _ => e.val) - · intro e _; exact e.property - · intro e _ f _ h; exact Subtype.ext h - · intro e he; exact ⟨⟨e,he⟩,Finset.mem_univ _,rfl⟩ - · intro _ _; rfl - rw [←hs,←hgain] - exact measureReal_mono hsub - -end PivotalSprinklingGain -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.ExteriorMoments + +namespace OAI + +/-! Distinct Moments for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ExposedBoundaryPotential +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def exposedVertexPotential (G : BondGraph V E) (p : unitInterval) + (x a b : V) (ω : Set E) : ℝ := + if Conn G ω x a then freshExteriorMoment G p a b ω else 0 + +theorem integrable_exposedVertexPotential [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x a b : V) : + Integrable (exposedVertexPotential G p x a b) (law p) := by + have he : exposedVertexPotential G p x a b = {ω | Conn G ω x a}.indicator (freshExteriorMoment G p a b) := by + funext ω + simp only [exposedVertexPotential,Set.indicator,Set.mem_ofPred_eq] + rw [he] + exact (integrable_freshExteriorMoment G hloc hqt p hp a b).indicator (measurableSet_conn G x a) + +theorem integral_exposedVertexPotential_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x a b : V) : + (∫ ω, exposedVertexPotential G p x a b ω ∂law p) ≤ distinctClusterMoment G p a b := by + rw [←show (∫ ω, freshExteriorMoment G p a b ω ∂law p) = distinctClusterMoment G p a b from + integral_freshExteriorMoment G hloc hqt p hp a b] + apply integral_mono (integrable_exposedVertexPotential G hloc hqt p hp x a b) + (integrable_freshExteriorMoment G hloc hqt p hp a b) + intro ω + unfold exposedVertexPotential + split_ifs + · rfl + · exact freshExteriorMoment_nonneg G p a b ω + +theorem exposedBoundaryPotential_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x v : V) (M : ℕ) (ω : Set E) : + ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M = + ∑ a ∈ (finite_reachBall hloc v M).toFinset, + ∑ b ∈ neighbors G hloc a, exposedVertexPotential G p x a b ω := by + unfold deletedBoundaryPotential + rw [Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + by_cases ha : Conn G ω x a + · have hc := cluster_eq_of_conn G ω ha + have hn : a ∉ (cluster G ω x)ᶜ := by exact not_not.mpr ha + simp only [ite_eq_left hn,Finset.mul_sum] + simp only [exposedVertexPotential,ite_eq_left ha,freshExteriorMoment,hc] + · have hn : ¬a ∉ (cluster G ω x)ᶜ := by exact not_not.mpr ha + simp only [ite_eq_right hn,mul_zero,exposedVertexPotential,ite_eq_right ha,Finset.sum_const_zero] + + + +theorem integral_exposedBoundaryPotential_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x v : V) (M : ℕ) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M) (law p) ∧ + (∫ ω, ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M ∂law p) ≤ + ∑ a ∈ (finite_reachBall hloc v M).toFinset, neighborClusterMoment G hloc p a := by + simp_rw [exposedBoundaryPotential_eq G hloc p x v M] + have hi (a : V) := integrable_finsetSum (neighbors G hloc a) + (fun b _ => integrable_exposedVertexPotential G hloc hqt p hp x a b) + refine ⟨integrable_finsetSum _ (fun a _ => hi a),?_⟩ + rw [integral_finsetSum _ (fun a _ => hi a)] + apply Finset.sum_le_sum + intro a _ + rw [integral_finsetSum _ (fun b _ => integrable_exposedVertexPotential G hloc hqt p hp x a b)] + exact Finset.sum_le_sum (fun b _ => integral_exposedVertexPotential_le G hloc hqt p hp x a b) + +end ExposedBoundaryPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformExposedBoundary +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem reachBall_ncard_covariant (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (M : ℕ) : + (reachBall G (a x) M).ncard = (reachBall G x M).ncard := by + have he : reachBall G (a x) M = a '' reachBall G x M := by + ext y + constructor + · intro h + exact ⟨a.symm y,by simpa only [Equiv.symm_apply_apply] using mem_reachBall_aut G (isAut_symm G hab) h,by simp⟩ + · rintro ⟨z,hz,rfl⟩ + exact mem_reachBall_aut G hab hz + rw [he,Set.ncard_image_of_injective _ a.injective] + +theorem reachBall_card_le_root_sum (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (M : ℕ) (x : V) : (finite_reachBall hloc x M).toFinset.card ≤ + ∑ i, (reachBall G (root i) M).ncard := by + obtain ⟨i,a,b,hab,hax⟩ := hcover x + rw [←Set.ncard_eq_toFinset_card (reachBall G x M) (finite_reachBall hloc x M),←hax,reachBall_ncard_covariant G hab] + exact Finset.single_le_sum (f := fun i => (reachBall G (root i) M).ncard) (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + +theorem rootNeighborMoment_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 ≤ weight i) + (p : unitInterval) : 0 ≤ rootNeighborMoment G hloc root weight p := + Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (neighborClusterMoment_nonneg G hloc p _)) + + + +theorem integral_exposedBoundaryPotential_uniform [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (x v : V) (M : ℕ) : + (∫ ω, ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M ∂law p) ≤ + (∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p := by + let B := (finite_reachBall hloc v M).toFinset + calc + _ ≤ ∑ a ∈ B, neighborClusterMoment G hloc p a := + (integral_exposedBoundaryPotential_le G hloc hqt p hp x v M).2 + _ ≤ ∑ _a ∈ B, c*rootNeighborMoment G hloc root weight p := + Finset.sum_le_sum (fun a _ => neighborMoment_le_rootMoment G hloc root weight hw hcover c hc hmin p a) + _ = (B.card:ℝ)*(c*rootNeighborMoment G hloc root weight p) := by rw [Finset.sum_const,nsmul_eq_mul] + _ ≤ _ := by + have hb : (B.card:ℝ) ≤ ∑ i, ((reachBall G (root i) M).ncard:ℝ) := by + exact_mod_cast reachBall_card_le_root_sum G hloc root hcover M v + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hb + (mul_nonneg hc (rootNeighborMoment_nonneg G hloc root weight hw p)) + +end UniformExposedBoundary +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DistinctMomentPotential +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +theorem kernel_distinctMoment_integral [Countable V] [Countable E] [Nonempty V] + (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x v : V) : + (∑' y, q.kernel p v y * distinctClusterMoment G p x y) = + ∫ ω, (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) ∂law p := by + rw [integral_tsum_of_finite_support (law p) (finite_reachBall hloc v M).toFinset _ + (fun y => (integrable_freshExteriorMoment G hloc hqt p hp x y).const_mul (q.kernel p v y)) + (fun ω y hy => by rw [q.kernel_outside_ball_zero p v y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul])] + apply tsum_congr + intro y + rw [integral_const_mul,integral_freshExteriorMoment G hloc hqt p hp] + rfl + +theorem integrable_kernel_freshMoment [Countable V] [Countable E] [Nonempty V] + (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x v : V) : + Integrable (fun ω => ∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) (law p) := by + have he (ω) : (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) = + ∑ y ∈ (finite_reachBall hloc v M).toFinset, q.kernel p v y * freshExteriorMoment G p x y ω := + tsum_eq_sum (fun y hy => by rw [q.kernel_outside_ball_zero p v y (by simpa only [Set.Finite.mem_toFinset] using hy),zero_mul]) + simp_rw [he] + exact integrable_finsetSum _ (fun y _ => (integrable_freshExteriorMoment G hloc hqt p hp x y).const_mul _) + + +theorem kernel_distinctMoment_bound [Countable V] [Countable E] [Nonempty V] + (q : LocalEndpointRule G hloc O M L) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) (x v : V) : + (∑' y, q.kernel p v y * distinctClusterMoment G p x y) ≤ + (1+(1-(p:ℝ))/p*M)*distinctClusterMoment G p x v + + (p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p := by + let C := 1+(1-(p:ℝ))/p*M + let R := (p:ℝ)^(-(M:ℤ)) + let b := fun ω : Set E => ((cluster G ω x).ncard:ℝ)*deletedBoundaryPotential G hloc (cluster G ω x)ᶜ p v M + have hi := (integral_exposedBoundaryPotential_le G hloc hqt p hpc x v M).1 + have hpoint (ω : Set E) : (∑' y, q.kernel p v y * freshExteriorMoment G p x y ω) ≤ + C*freshExteriorMoment G p x v ω + R*b ω := by + have h := mul_le_mul_of_nonneg_left (q.kernel_deleted_potential_bound hqt (cluster G ω x)ᶜ p hp hpc v) + (Nat.cast_nonneg (cluster G ω x).ncard : (0:ℝ) ≤ _) + rw [←tsum_mul_left] at h + calc + _ = ∑' y, ((cluster G ω x).ncard:ℝ)*(q.kernel p v y * inducedSusceptibility G (cluster G ω x)ᶜ p y) := by + apply tsum_congr + intro y + simp only [freshExteriorMoment] + ring + _ ≤ _ := h + _ = _ := by dsimp [C,R,b,freshExteriorMoment]; ring + rw [q.kernel_distinctMoment_integral hqt p hpc x v] + calc + _ ≤ ∫ ω, C*freshExteriorMoment G p x v ω + R*b ω ∂law p := + integral_mono (q.integrable_kernel_freshMoment hqt p hpc x v) + (((integrable_freshExteriorMoment G hloc hqt p hpc x v).const_mul C).add (hi.const_mul R)) hpoint + _ = C*distinctClusterMoment G p x v + R*(∫ ω, b ω ∂law p) := by + rw [integral_add ((integrable_freshExteriorMoment G hloc hqt p hpc x v).const_mul C) (hi.const_mul R), + integral_const_mul,integral_const_mul,integral_freshExteriorMoment G hloc hqt p hpc] + rfl + _ ≤ _ := by + have h := mul_le_mul_of_nonneg_left + (integral_exposedBoundaryPotential_uniform G hloc hqt root weight hw hcover c hc hmin p hpc x v M) + (zpow_nonneg p.2.1 (-(M:ℤ))) + dsimp [C,R,b] at * + nlinarith + +end LocalEndpointRule +end DistinctMomentPotential +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FinitePositiveOperatorPowers +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finite_positive_product_support (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hb : ∀ x, (Function.support (fun y => (matrixCoeff B x y).re)).Finite) (x : V) : + (Function.support (fun y => (matrixCoeff (A*B) x y).re)).Finite := by + let S := (ha x).toFinset + let T := S.biUnion (fun z => (hb z).toFinset) + apply T.finite_toSet.subset + intro y hy + by_contra hn + apply hy + change (matrixCoeff (A*B) x y).re = 0 + rw [←(hA.mul_hasSum B x y).tsum_eq] + rw [←tsum_zero] + apply tsum_congr + intro z + by_cases hz : z ∈ S + · have hzy : (matrixCoeff B z y).re = 0 := by + by_contra hh + apply hn + exact Finset.mem_biUnion.mpr ⟨z,hz,by simpa only [Set.Finite.mem_toFinset,Function.mem_support] using hh⟩ + rw [hzy,mul_zero] + · have hzx : (matrixCoeff A x z).re = 0 := by + simpa only [S,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz + rw [hzx,zero_mul] + +theorem finite_positive_product_action (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hb : ∀ x, (Function.support (fun y => (matrixCoeff B x y).re)).Finite) + (f : V → ℝ) (x : V) : + (∑' y, (matrixCoeff (A*B) x y).re*f y) = + ∑' z, (matrixCoeff A x z).re*∑' y, (matrixCoeff B z y).re*f y := by + let K := fun x y => (matrixCoeff A x y).re + let J := fun x y => (matrixCoeff B x y).re + let S := (ha x).toFinset + have hz (z : V) (hz : z ∉ S) : K x z = 0 := by + simpa only [S,Set.Finite.mem_toFinset,Function.mem_support,not_not] using hz + have he (y : V) : (matrixCoeff (A*B) x y).re*f y = ∑ z ∈ S, K x z*(J z y*f y) := by + rw [←(hA.mul_hasSum B x y).tsum_eq,tsum_eq_sum (s := S) + (fun z h => by change K x z*J z y = 0; rw [hz z h,zero_mul]),Finset.sum_mul] + exact Finset.sum_congr rfl (fun z _ => mul_assoc _ _ _) + have hs := hasSum_sum (s := S) (fun z _ => + (finiteKernel_summable_mul J hb z f).hasSum.mul_left (K x z)) + have hr : (∑' z, K x z*∑' y, J z y*f y) = ∑ z ∈ S, K x z*∑' y, J z y*f y := + tsum_eq_sum (fun z h => by rw [hz z h,zero_mul]) + simpa only [←he,←hr] using hs.tsum_eq + +theorem finite_positive_pow_support (A : Hilbert V →L[ℂ] Hilbert V) + (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (j : ℕ) (x : V) : (Function.support (fun y => (matrixCoeff (A^j) x y).re)).Finite := by + induction j generalizing x with + | zero => + apply (Set.finite_singleton x).subset + intro y hy + by_contra hn + apply hy + have he : x ≠ y := fun h => hn (by simp only [Set.mem_singleton_iff]; exact h.symm) + simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right he,Complex.zero_re] + | succ j ih => + rw [pow_succ'] + exact finite_positive_product_support A (A^j) hA ha ih x + +theorem positive_identity_action (f : V → ℝ) (x : V) : + (∑' y, (matrixCoeff (1 : Hilbert V →L[ℂ] Hilbert V) x y).re*f y) = f x := by + rw [tsum_eq_single x (fun y hy => by + simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right (Ne.symm hy),Complex.zero_re,zero_mul])] + simp only [matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_true,Complex.one_re,one_mul] + +end FinitePositiveOperatorPowers +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PositivePotentialIteration +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def realAction (A : Hilbert V →L[ℂ] Hilbert V) (f : V → ℝ) (x : V) : ℝ := + ∑' y, (matrixCoeff A x y).re*f y + +theorem realAction_mono (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (f g : V → ℝ) (hfg : ∀ x, f x ≤ g x) (x : V) : realAction A f x ≤ realAction A g x := by + exact (finiteKernel_summable_mul _ ha x f).tsum_le_tsum + (fun y => mul_le_mul_of_nonneg_left (hfg y) (hA x y).2) (finiteKernel_summable_mul _ ha x g) + +theorem realAction_affine (A : Hilbert V →L[ℂ] Hilbert V) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (f : V → ℝ) (a b : ℝ) (x : V) : + realAction A (fun y => a*f y+b) x = a*realAction A f x + b*realAction A (fun _ => 1) x := by + unfold realAction + simp_rw [mul_add] + rw [Summable.tsum_add] + · have he (y : V) : (matrixCoeff A x y).re*(a*f y) = a*((matrixCoeff A x y).re*f y) := by ring + simp_rw [he] + simp only [tsum_mul_left,tsum_mul_right,mul_one] + ring + · exact finiteKernel_summable_mul _ ha x (fun y => a*f y) + · exact finiteKernel_summable_mul _ ha x (fun _ => b) + +theorem realAction_pow_succ (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (j : ℕ) (f : V → ℝ) (x : V) : + realAction (A^(j+1)) f x = realAction A (realAction (A^j) f) x := by + rw [pow_succ'] + exact finite_positive_product_action A (A^j) hA ha (finite_positive_pow_support A hA ha j) f x + + + +theorem realAction_pow_potential_bound (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) + (f : V → ℝ) (Z B : ℝ) (hZ : 2 ≤ Z) (hB : 0 ≤ B) + (hf : ∀ x, realAction A f x ≤ Z*f x+B) (j : ℕ) (x : V) : + realAction (A^j) f x ≤ Z^j*f x + B*(Z^j-1) := by + have hz : 0 ≤ Z := by linarith + have hz1 : 1 ≤ Z := by linarith + induction j generalizing x with + | zero => + simp only [pow_zero,realAction,positive_identity_action,one_mul,sub_self,mul_zero,add_zero,le_refl] + | succ j ih => + rw [realAction_pow_succ A hA ha] + calc + _ ≤ realAction A (fun y => Z^j*f y+B*(Z^j-1)) x := realAction_mono A hA ha _ _ ih x + _ = Z^j*realAction A f x + (B*(Z^j-1))*realAction A (fun _ => 1) x := realAction_affine A ha f _ _ x + _ ≤ Z^j*(Z*f x+B) + B*(Z^j-1) := add_le_add + (mul_le_mul_of_nonneg_left (hf x) (pow_nonneg hz _)) + (by + simpa only [mul_one] using (mul_le_mul_of_nonneg_left (hrow x) + (mul_nonneg hB (sub_nonneg.mpr (one_le_pow₀ hz1))))) + _ ≤ Z^(j+1)*f x+B*(Z^(j+1)-1) := by + have hh := mul_nonneg (mul_nonneg hB (pow_nonneg hz j)) (show 0 ≤ Z-2 by linarith) + rw [pow_succ] + nlinarith only [hh] + +theorem realAction_pow_potential_at_zero (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) + (f : V → ℝ) (Z B : ℝ) (hZ : 2 ≤ Z) (hB : 0 ≤ B) + (hf : ∀ x, realAction A f x ≤ Z*f x+B) (j : ℕ) (x : V) (hx : f x = 0) : + realAction (A^j) f x ≤ B*Z^j := by + have h := realAction_pow_potential_bound A hA ha hrow f Z B hZ hB hf j x + rw [hx,mul_zero,zero_add] at h + nlinarith + +end PositivePotentialIteration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NormalizedPositiveOperator +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem normalized_operator_positive (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : PositiveRealMatrix A := by + intro x y + rw [hA] + exact ⟨rfl,mul_nonneg (inv_nonneg.mpr (q.successProbability_nonneg p o)) (q.kernel_nonneg p x y)⟩ + +theorem normalized_operator_finite (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) : + (Function.support (fun y => (matrixCoeff A x y).re)).Finite := by + apply (finite_reachBall hloc x M).subset + intro y hy + by_contra hn + apply hy + change (matrixCoeff A x y).re = 0 + simp only [hA,normalizedKernel,q.kernel_outside_ball_zero p x y hn,mul_zero,Complex.ofReal_zero,Complex.zero_re] + +theorem normalized_operator_action (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (f : V → ℝ) (x : V) : + realAction A f x = (q.successProbability p o)⁻¹ * (∑' y, q.kernel p x y*f y) := by + simp only [realAction,hA,Complex.ofReal_re,normalizedKernel,mul_assoc,tsum_mul_left] + +theorem normalized_operator_row_le (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (hu : 0 < q.successProbability p o) (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) : + realAction A (fun _ => 1) x ≤ 1 := by + rw [q.normalized_operator_action o p A hA] + simp only [mul_one] + calc + _ ≤ (q.successProbability p o)⁻¹ * q.successProbability p o := + mul_le_mul_of_nonneg_left (q.kernel_row_le_success o p x) (inv_nonneg.mpr hu.le) + _ = 1 := inv_mul_cancel₀ hu.ne' + +theorem normalized_operator_row_eq (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (hu : 0 < q.successProbability p o) (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) (x : V) + (hx : x ∈ vertexOrbit G o) : realAction A (fun _ => 1) x = 1 := by + rw [q.normalized_operator_action o p A hA] + simp only [mul_one] + change (q.successProbability p o)⁻¹ * q.successProbability p x = 1 + rw [q.successProbability_orbit p o x hx,inv_mul_cancel₀ hu.ne'] + +theorem normalized_operator_invariant (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) : + KernelInvariant (vertexAut G) A := by + rintro a ⟨b,hab⟩ x y + simp only [hA,normalizedKernel,q.kernel_covariant p a b hab] + +theorem normalized_operator_end_support (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) + (x y : V) (hy : y ∉ vertexOrbit G o) : (matrixCoeff A x y).re = 0 := by + simp only [hA,normalizedKernel,q.kernel_zero_of_end_not_mem p x y hy,mul_zero,Complex.ofReal_zero,Complex.zero_re] + +end LocalEndpointRule +end NormalizedPositiveOperator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UpperDistinctMomentIteration +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem distinctClusterMoment_self (G : BondGraph V E) (p : unitInterval) (x : V) : + distinctClusterMoment G p x x = 0 := by + have hs (ω : Set E) : Conn G ω x x := .refl + simp only [distinctClusterMoment,hs,not_true_eq_false,ite_false,integral_zero] + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem normalized_power_distinctMoment_upper [Countable V] [Countable E] [Nonempty V] + (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) + (hu : 0 < q.successProbability p o) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel o p x y : ℂ)) + (Z : ℝ) (hZ : 2 ≤ Z) + (hscale : (q.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*M) ≤ Z) + (j : ℕ) (x : V) : + realAction (A^j) (distinctClusterMoment G p x) x ≤ + ((q.successProbability p o)⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* + rootNeighborMoment G hloc root weight p * Z^j := by + let B := ((q.successProbability p o)⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* + rootNeighborMoment G hloc root weight p + have hB : 0 ≤ B := by + exact mul_nonneg (mul_nonneg (mul_nonneg + (mul_nonneg (inv_nonneg.mpr hu.le) (zpow_nonneg p.2.1 _)) + (Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _))) hc) + (rootNeighborMoment_nonneg G hloc root weight hw p) + have hf (v : V) : realAction A (distinctClusterMoment G p x) v ≤ Z*distinctClusterMoment G p x v+B := by + rw [q.normalized_operator_action o p A hA] + calc + _ ≤ (q.successProbability p o)⁻¹ * + ((1+(1-(p:ℝ))/p*M)*distinctClusterMoment G p x v+ + (p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c*rootNeighborMoment G hloc root weight p) := + mul_le_mul_of_nonneg_left + (q.kernel_distinctMoment_bound hqt root weight hw hcover c hc hmin p hp hpc x v) (inv_nonneg.mpr hu.le) + _ = ((q.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*M))*distinctClusterMoment G p x v+B := by dsimp [B]; ring + _ ≤ _ := by + have hh := mul_le_mul_of_nonneg_right hscale (distinctClusterMoment_nonneg G p x v) + linarith + exact realAction_pow_potential_at_zero A (q.normalized_operator_positive o p A hA) + (q.normalized_operator_finite o p A hA) (q.normalized_operator_row_le o p hu A hA) + (distinctClusterMoment G p x) Z B hZ hB hf j x (distinctClusterMoment_self G p x) + +end LocalEndpointRule +end UpperDistinctMomentIteration +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section PositivePowerStochasticity +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem realAction_pow_row_le (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) (j : ℕ) (x : V) : + realAction (A^j) (fun _ => 1) x ≤ 1 := by + induction j generalizing x with + | zero => rw [pow_zero]; exact (positive_identity_action (fun _ => 1) x).le + | succ j ih => + rw [realAction_pow_succ A hA ha] + exact (realAction_mono A hA ha _ (fun _ => 1) ih x).trans (hrow x) + +theorem positive_pow_end_support (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (O : Set V) (hO : ∀ x y, y ∉ O → (matrixCoeff A x y).re = 0) + (j : ℕ) (x y : V) (hx : x ∈ O) (hy : y ∉ O) : (matrixCoeff (A^j) x y).re = 0 := by + cases j with + | zero => + have hxy : x ≠ y := fun h => hy (h ▸ hx) + simp only [pow_zero,matrixCoeff,one_apply_eq_self,lp.single_apply,Pi.single_apply,ite_eq_right hxy,Complex.zero_re] + | succ j => + rw [pow_succ,←((hA.pow j).mul_hasSum A x y).tsum_eq] + simp only [hO _ y hy,mul_zero,tsum_zero] + +theorem realAction_pow_row_eq_on (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (O : Set V) (hO : ∀ x y, y ∉ O → (matrixCoeff A x y).re = 0) + (hrow : ∀ x ∈ O, realAction A (fun _ => 1) x = 1) + (j : ℕ) (x : V) (hx : x ∈ O) : realAction (A^j) (fun _ => 1) x = 1 := by + induction j generalizing x with + | zero => rw [pow_zero]; exact positive_identity_action (fun _ => 1) x + | succ j ih => + rw [realAction_pow_succ A hA ha] + calc + _ = realAction A (fun _ => 1) x := by + apply tsum_congr + intro y + by_cases hy : y ∈ O + · rw [ih y hy] + · rw [hO x y hy,zero_mul,zero_mul] + _ = 1 := hrow x hx + +end PositivePowerStochasticity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ConnectedMomentLoss +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def connectedClusterMoment (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ := + ∫ ω, (if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) ∂law p + +theorem integrable_connected_cluster_square [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (fun ω => if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) (law p) := by + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + have he : (fun ω : Set E => if Conn G ω x y then ((cluster G ω x).ncard:ℝ)^2 else 0) = + {ω | Conn G ω x y}.indicator (fun ω => ((cluster G ω x).ncard:ℝ)^2) := by + funext ω + simp only [Set.indicator,Set.mem_ofPred_eq] + rw [he] + exact (hs x).1.indicator (measurableSet_conn G x y) + +theorem distinct_add_connected_cluster_moment [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + distinctClusterMoment G p x y + connectedClusterMoment G p x y = + ∫ ω, ((cluster G ω x).ncard:ℝ)*((cluster G ω y).ncard:ℝ) ∂law p := by + rw [distinctClusterMoment,connectedClusterMoment, + ←integral_add (integrable_distinct_cluster_product G hloc hqt p hp x y) + (integrable_connected_cluster_square G hloc hqt p hp x y)] + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun ω => by + by_cases h : Conn G ω x y + · simp only [h,not_true_eq_false,ite_false,ite_true,zero_add,cluster_eq_of_conn G ω h,pow_two] + · simp only [h,not_false_eq_true,ite_true,ite_false,add_zero]) + +theorem distinctClusterMoment_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + susceptibility G p x * susceptibility G p y - connectedClusterMoment G p x y ≤ + distinctClusterMoment G p x y := by + have h := (subcritical_cluster_association G hloc hqt p hp x y).2 + rw [←distinct_add_connected_cluster_moment G hloc hqt p hp] at h + linarith + + +theorem realAction_connectedMoment_eq_diagonalLoss [Countable V] [Countable E] + (G : BondGraph V E) (o : V) (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) + (x : V) (hend : ∀ y, y ∉ vertexOrbit G o → (matrixCoeff A x y).re = 0) + (p : unitInterval) (hs : Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^2) (law p)) : + realAction A (connectedClusterMoment G p x) x = + ∫ ω, diagonalLossMass G o (fun a b => (matrixCoeff A a b).re) ω x ∂law p := by + have hr (z : V) (S : Finset V) : (∑ y ∈ S, (matrixCoeff A z y).re) ≤ 1 := by + have hsrow : Summable (fun y => (matrixCoeff A z y).re) := by + simpa only [mul_one] using finiteKernel_summable_mul (fun a b => (matrixCoeff A a b).re) ha z (fun _ => 1) + exact (hsrow.sum_le_tsum S (fun y _ => (hA z y).2)).trans (by simpa only [realAction,mul_one] using hrow z) + rw [integral_diagonalLoss_eq_series G o _ (fun a b => (hA a b).2) 1 hr x p hs] + apply tsum_congr + intro y + by_cases hy : y ∈ vertexOrbit G o + · rw [ite_eq_left hy] + rfl + · simp only [ite_eq_right hy,hend y hy,zero_mul] + +end ConnectedMomentLoss +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LowerDistinctMomentOperator +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem realAction_distinctMoment_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : p < pc G) (b : ℝ) (hb : 0 ≤ b) + (hχ : ∀ x, b ≤ susceptibility G p x) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : PositiveRealMatrix A) + (ha : ∀ x, (Function.support (fun y => (matrixCoeff A x y).re)).Finite) + (hinv : KernelInvariant (vertexAut G) A) + (hrow : ∀ x, realAction A (fun _ => 1) x ≤ 1) + (heq : realAction A (fun _ => 1) (root i₀) = 1) + (hend : ∀ y, y ∉ vertexOrbit G (root i₀) → (matrixCoeff A (root i₀) y).re = 0) : + b^2-‖A‖*(c*rootSusceptibility G root weight p)^3 ≤ + realAction A (distinctClusterMoment G p (root i₀)) (root i₀) := by + let x := root i₀ + let f := connectedClusterMoment G p x + have hr (z : V) (S : Finset V) : (∑ y ∈ S, (matrixCoeff A z y).re) ≤ 1 := by + have hsrow : Summable (fun y => (matrixCoeff A z y).re) := by + simpa only [mul_one] using finiteKernel_summable_mul (fun a b => (matrixCoeff A a b).re) ha z (fun _ => 1) + exact (hsrow.sum_le_tsum S (fun y _ => (hA z y).2)).trans (by simpa only [realAction,mul_one] using hrow z) + obtain ⟨_,_,hs⟩ := subcritical_second_moment G hloc hqt p hp + have hf : realAction A f x ≤ ‖A‖*(c*rootSusceptibility G root weight p)^3 := by + rw [realAction_connectedMoment_eq_diagonalLoss G (root i₀) A hA ha hrow x hend p (hs x).1] + exact diagonalLoss_le_rootSusceptibility_cube G hloc hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hp + (fun a b => (matrixCoeff A a b).re) (fun a b => (hA a b).2) + (fun a b hab z y => congrArg Complex.re (hinv a ⟨b,hab⟩ z y)) 1 hr A (hA.real) + have hpnt (y : V) : (-1)*f y+b^2 ≤ distinctClusterMoment G p x y := by + have h := distinctClusterMoment_lower G hloc hqt p hp x y + have hprod : b*b ≤ susceptibility G p x * susceptibility G p y := + mul_le_mul (hχ x) (hχ y) hb (susceptibility_nonneg G p x) + dsimp [f] + nlinarith only [h,hprod] + have hi := realAction_mono A hA ha (fun y => (-1)*f y+b^2) + (distinctClusterMoment G p x) hpnt x + rw [realAction_affine A ha f (-1) (b^2) x,heq] at hi + nlinarith only [hi,hf] + +end LowerDistinctMomentOperator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section DistinctMomentSandwich +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem normalized_power_moment_sandwich [Countable V] [Countable E] [Nonempty V] + (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hpc : p < pc G) + (hu : 0 < q.successProbability p (root i₀)) + (A : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) + (a : ℝ) (ha : 0 ≤ a) (hχ : ∀ x, a*rootSusceptibility G root weight p ≤ susceptibility G p x) + (Z : ℝ) (hZ : 2 ≤ Z) + (hscale : (q.successProbability p (root i₀))⁻¹*(1+(1-(p:ℝ))/p*M) ≤ Z) (j : ℕ) : + (a*rootSusceptibility G root weight p)^2 - ‖A‖^j*(c*rootSusceptibility G root weight p)^3 ≤ + ((q.successProbability p (root i₀))⁻¹*(p:ℝ)^(-(M:ℤ))*(∑ i, ((reachBall G (root i) M).ncard:ℝ))*c)* + rootNeighborMoment G hloc root weight p * Z^j := by + have hpos := q.normalized_operator_positive (root i₀) p A hA + have hfin := q.normalized_operator_finite (root i₀) p A hA + have hrow := q.normalized_operator_row_le (root i₀) p hu A hA + have hend := q.normalized_operator_end_support (root i₀) p A hA + have hx : root i₀ ∈ vertexOrbit G (root i₀) := ⟨Equiv.refl V,Equiv.refl E,(fun _ => by simp),rfl⟩ + have hlo := realAction_distinctMoment_lower G hloc hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hpc + (a*rootSusceptibility G root weight p) (mul_nonneg ha (rootSusceptibility_nonneg G root weight hw p)) hχ + (A^j) (hpos.pow j) (finite_positive_pow_support A hpos hfin j) + ((q.normalized_operator_invariant (root i₀) p A hA).pow j) + (realAction_pow_row_le A hpos hfin hrow j) + (realAction_pow_row_eq_on A hpos hfin _ hend + (q.normalized_operator_row_eq (root i₀) p hu A hA) j (root i₀) hx) + (positive_pow_end_support A hpos _ hend j (root i₀) · hx) + have hhi := q.normalized_power_distinctMoment_upper (root i₀) hqt root weight hw hcover c hc hmin p hp hpc hu A hA Z hZ hscale j (root i₀) + have hpow : ‖A^j‖ ≤ ‖A‖^j := by + cases j with + | zero => + simp only [pow_zero] + have he : (1 : Hilbert V →L[ℂ] Hilbert V) = ContinuousLinearMap.id ℂ (Hilbert V) := by ext x; rfl + rw [he] + exact ContinuousLinearMap.norm_id_le + | succ j => exact norm_pow_le' A (Nat.succ_pos j) + have hn := mul_le_mul_of_nonneg_right hpow + (pow_nonneg (mul_nonneg hc (rootSusceptibility_nonneg G root weight hw p)) 3) + linarith + +end LocalEndpointRule +end DistinctMomentSandwich +end Percolation + + +namespace Percolation +section LogarithmicPowerChoice + + + +theorem exists_logarithmic_power (r h Z T : ℝ) (hr : 0 ≤ r) (hh : 0 < h) + (hrh : r ≤ Real.exp (-h)) (hZ : 1 ≤ Z) (hT : 1 ≤ T) : + ∃ j : ℕ, r^j ≤ T⁻¹ ∧ Z^j ≤ Z*T^(Real.log Z/h) := by + let t := Real.log T/h + have ht : 0 ≤ t := div_nonneg (Real.log_nonneg hT) hh.le + let j := Nat.ceil t + have hlo : t ≤ (j:ℝ) := Nat.le_ceil t + have hhi : (j:ℝ) ≤ t+1 := (Nat.ceil_lt_add_one ht).le + have hTp : 0 < T := zero_lt_one.trans_le hT + have hZp : 0 < Z := zero_lt_one.trans_le hZ + have hlogZ : 0 ≤ Real.log Z := Real.log_nonneg hZ + refine ⟨j,?_,?_⟩ + · calc + r^j ≤ (Real.exp (-h))^j := pow_le_pow_left₀ hr hrh j + _ = Real.exp ((j:ℝ)*(-h)) := (Real.exp_nat_mul _ _).symm + _ ≤ Real.exp (-Real.log T) := by + apply Real.exp_le_exp.mpr + have hl : Real.log T ≤ (j:ℝ)*h := (div_le_iff₀ hh).mp hlo + nlinarith + _ = T⁻¹ := by rw [Real.exp_neg,Real.exp_log hTp] + · calc + Z^j = Real.exp ((j:ℝ)*Real.log Z) := by rw [Real.exp_nat_mul,Real.exp_log hZp] + _ ≤ Real.exp ((t+1)*Real.log Z) := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hhi hlogZ) + _ = Z*T^(Real.log Z/h) := by + rw [Real.rpow_def_of_pos hTp,←Real.exp_log hZp,←Real.exp_add] + simp only [Real.log_exp] + congr 1 + dsimp [t] + ring + + + +theorem moment_sandwich_power_law (a c C Z h r χ N : ℝ) + (ha : 0 < a) (hc : 0 ≤ c) (hC : 0 < C) (hZ : 1 ≤ Z) (hh : 0 < h) + (hr : 0 ≤ r) (hrh : r ≤ Real.exp (-h)) (hχ : 1 ≤ χ) (hN : 0 ≤ N) + (hs : ∀ j : ℕ, (a*χ)^2-r^j*(c*χ)^3 ≤ C*N*Z^j) : + let T := 1+2*c^3/a^2 + a^2/(2*C*Z*T^(Real.log Z/h))*χ^(2-Real.log Z/h) ≤ N := by + let T := 1+2*c^3/a^2 + have hap : 0 < a^2 := sq_pos_of_pos ha + have hT : 1 ≤ T := by + have hn : 0 ≤ 2*c^3/a^2 := by positivity + dsimp [T] + linarith + have hTp : 0 < T := zero_lt_one.trans_le hT + have hχp : 0 < χ := zero_lt_one.trans_le hχ + have hZp : 0 < Z := zero_lt_one.trans_le hZ + have hTx : 1 ≤ T*χ := by nlinarith + obtain ⟨j,hrj,hZj⟩ := exists_logarithmic_power r h Z (T*χ) hr hh hrh hZ hTx + have hbudget : 2*c^3 ≤ a^2*T := by dsimp [T]; field_simp; nlinarith + have hsmall : r^j*(c*χ)^3 ≤ a^2/2*χ^2 := by + calc + _ ≤ (T*χ)⁻¹*(c*χ)^3 := mul_le_mul_of_nonneg_right hrj (pow_nonneg (mul_nonneg hc hχp.le) _) + _ = c^3/T*χ^2 := by field_simp + _ ≤ a^2/2*χ^2 := mul_le_mul_of_nonneg_right ((div_le_iff₀ hTp).mpr (by nlinarith [hbudget])) (sq_nonneg χ) + have hlarge : a^2/2*χ^2 ≤ C*N*(Z*(T*χ)^(Real.log Z/h)) := by + have hs' := hs j + have hprod := mul_le_mul_of_nonneg_left hZj (mul_nonneg hC.le hN) + nlinarith only [hsmall,hs',hprod] + have hpow : 0 < χ^(Real.log Z/h) := Real.rpow_pos_of_pos hχp _ + have hTpow : 0 < T^(Real.log Z/h) := Real.rpow_pos_of_pos hTp _ + have he : C*N*(Z*(T*χ)^(Real.log Z/h)) = + (C*Z*T^(Real.log Z/h))*N*χ^(Real.log Z/h) := by + rw [Real.mul_rpow hTp.le hχp.le] + ring + rw [he] at hlarge + have hden : 0 < 2*C*Z*T^(Real.log Z/h) := by positivity + change a^2/(2*C*Z*T^(Real.log Z/h))*χ^(2-Real.log Z/h) ≤ N + rw [Real.rpow_sub hχp,Real.rpow_two] + calc + _ = (a^2*χ^2)/(2*C*Z*T^(Real.log Z/h)*χ^(Real.log Z/h)) := by + rw [div_mul_div_comm] + _ ≤ N := (div_le_iff₀ (mul_pos hden hpow)).mpr (by nlinarith only [hlarge]) + +end LogarithmicPowerChoice +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section ProfileContinuity +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} + +theorem exp_neg_H (q : EndpointProfile G hloc p₀ o s) : Real.exp (-q.H) = ‖q.op‖ := by + rw [H,one_div,Real.log_inv,neg_neg,Real.exp_log q.norm_pos] + + + +theorem exists_nearby_operators {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : EndpointProfile G hloc p₀ (root i₀) s) (hp₀ : 0 < (p₀:ℝ)) : + ∃ A : unitInterval → (Hilbert V →L[ℂ] Hilbert V), + (∀ p x y, matrixCoeff (A p) x y = (q.rule.normalizedKernel (root i₀) p x y : ℂ)) ∧ + ∀ᶠ p in nhds p₀, q.rule.successProbability p₀ (root i₀)/2 ≤ q.rule.successProbability p (root i₀) ∧ + ‖A p‖ ≤ Real.exp (-(q.H-1)) ∧ (p₀:ℝ)/2 ≤ (p:ℝ) := by + obtain ⟨A,_,hA,hcont⟩ := q.rule.exists_continuous_normalized_operators root weight Γ htr hΓ hw i₀ hw₀ + have he : A p₀ = q.op := kernel_extension_unique (hA p₀) q.coeff + have hnorm : ContinuousAt (fun p => ‖A p‖) p₀ := (hcont p₀ q.success_pos.ne').norm + have hb : ‖A p₀‖ < Real.exp (-(q.H-1)) := by + rw [he,←q.exp_neg_H] + exact Real.exp_lt_exp.mpr (by linarith) + have ha := hnorm.eventually_lt continuousAt_const hb + have hu : ∀ᶠ p in nhds p₀, q.rule.successProbability p₀ (root i₀)/2 < q.rule.successProbability p (root i₀) := + continuousAt_const.eventually_lt (q.rule.continuous_successProbability (root i₀)).continuousAt (by linarith [q.success_pos]) + have hp : ∀ᶠ p : unitInterval in nhds p₀, (p₀:ℝ)/2 < (p:ℝ) := + continuousAt_const.eventually_lt continuous_subtype_val.continuousAt (by linarith) + refine ⟨A,hA,?_⟩ + filter_upwards [ha,hu,hp] with p ha hu hp + exact ⟨hu.le,ha.le,hp.le⟩ + +end EndpointProfile +end ProfileContinuity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section MapScaleBudget +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} + +noncomputable def potentialScale (q : EndpointProfile G hloc p₀ o s) (p : unitInterval) : ℝ := + (q.rule.successProbability p o)⁻¹*(1+(1-(p:ℝ))/p*q.cap) + +noncomputable def geometricScale (q : EndpointProfile G hloc p₀ o s) : ℝ := 2*q.potentialScale p₀ + +theorem potentialScale_pos (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : + 0 < q.potentialScale p₀ := by + exact mul_pos (inv_pos.mpr q.success_pos) (by + have hn : 0 ≤ (1-(p₀:ℝ))/p₀*q.cap := mul_nonneg (div_nonneg (sub_nonneg.mpr p₀.2.2) hp₀.le) (Nat.cast_nonneg _) + linarith) + +theorem geometricScale_two_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : + 2 ≤ q.geometricScale := by + have hu : 1 ≤ (q.rule.successProbability p₀ o)⁻¹ := + (one_le_inv₀ q.success_pos).mpr (q.rule.successProbability_le_one p₀ o) + have hb : 0 ≤ (1-(p₀:ℝ))/p₀*q.cap := + mul_nonneg (div_nonneg (sub_nonneg.mpr p₀.2.2) hp₀.le) (Nat.cast_nonneg _) + dsimp [geometricScale,potentialScale] + nlinarith + +theorem log_geometricScale_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) + (hM : 1 ≤ q.cap) : + Real.log q.geometricScale ≤ q.U+q.m+Real.log (2*(1+1/(p₀:ℝ))) := by + have hM' : (1:ℝ) ≤ q.cap := by exact_mod_cast hM + have hMp : (0:ℝ) < q.cap := zero_lt_one.trans_le hM' + have hb : 1+(1-(p₀:ℝ))/p₀*q.cap ≤ (1+1/(p₀:ℝ))*q.cap := by + apply (mul_le_mul_iff_of_pos_right hp₀).mp + field_simp + nlinarith + have Hz : q.geometricScale ≤ (1/q.rule.successProbability p₀ o)*(q.cap:ℝ)*(2*(1+1/(p₀:ℝ))) := by + have h := mul_le_mul_of_nonneg_left hb (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) (inv_nonneg.mpr q.success_pos.le)) + simpa only [geometricScale,potentialScale,one_div,mul_assoc,mul_comm,mul_left_comm] using h + have hc : 0 < 2*(1+1/(p₀:ℝ)) := by positivity + have h := Real.log_le_log (lt_of_lt_of_le (by norm_num : (0:ℝ)<2) (q.geometricScale_two_le hp₀)) Hz + rw [Real.log_mul (mul_ne_zero (one_div_ne_zero q.success_pos.ne') hMp.ne') hc.ne', + Real.log_mul (one_div_ne_zero q.success_pos.ne') hMp.ne'] at h + exact h + +theorem eventually_potentialScale_le (q : EndpointProfile G hloc p₀ o s) (hp₀ : 0 < (p₀:ℝ)) : + ∀ᶠ p in nhds p₀, q.potentialScale p ≤ q.geometricScale := by + have hu := (q.rule.continuous_successProbability o).continuousAt.inv₀ q.success_pos.ne' + have hv : ContinuousAt (fun p : unitInterval => ((1-(p:ℝ))/p)) p₀ := + (continuousAt_const.sub continuous_subtype_val.continuousAt).div continuous_subtype_val.continuousAt hp₀.ne' + have he : ContinuousAt q.potentialScale p₀ := hu.mul (continuousAt_const.add (hv.mul continuousAt_const)) + have hlt : q.potentialScale p₀ < q.geometricScale := by + dsimp only [geometricScale] + linarith [q.potentialScale_pos hp₀] + filter_upwards [he.eventually_lt continuousAt_const hlt] with p hp + exact hp.le + +end EndpointProfile +end MapScaleBudget +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section ProfileNeighborMoment +attribute [local instance] Classical.propDecidable Classical.decEq +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} {p₀ : unitInterval} {o : V} {s : ℝ} + + + +theorem eventually_neighborMoment_lower [Countable V] [Countable E] [Nonempty V] + (hconn : Connected G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (q : EndpointProfile G hloc p₀ (root i₀) s) (hp₀ : 0 < (p₀:ℝ)) (hH : 1 < q.H) : + ∃ b : ℝ, 0 < b ∧ ∀ᶠ p in nhds p₀, p < pc G → + b*(rootSusceptibility G root weight p)^(2-Real.log q.geometricScale/(q.H-1)) ≤ + rootNeighborMoment G hloc root weight p := by + obtain ⟨a,ha,hχ⟩ := exists_rootSusceptibility_lower G hconn hloc hqt root weight hw hw1 hcover + ((p₀:ℝ)/2) (by linarith) + obtain ⟨A,hA,hnear⟩ := q.exists_nearby_operators root weight Γ htr hΓ hw i₀ hw₀ hp₀ + let B : unitInterval → ℝ := fun p => + (q.rule.successProbability p (root i₀))⁻¹*(p:ℝ)^(-(q.cap:ℤ))*(∑ i, ((reachBall G (root i) q.cap).ncard:ℝ))*c + have hB (p : unitInterval) : 0 ≤ B p := by + dsimp [B] + exact mul_nonneg (mul_nonneg (mul_nonneg (inv_nonneg.mpr (q.rule.successProbability_nonneg p _)) + (zpow_nonneg p.2.1 _)) (Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _))) hc + have hBc : ContinuousAt B p₀ := by + exact ((((q.rule.continuous_successProbability (root i₀)).continuousAt.inv₀ q.success_pos.ne').mul + (continuous_subtype_val.continuousAt.zpow₀ (-(q.cap:ℤ)) (Or.inl hp₀.ne'))).mul continuousAt_const).mul continuousAt_const + let C := B p₀+1 + have hC : 0 < C := by dsimp [C]; linarith [hB p₀] + have hCB : ∀ᶠ p in nhds p₀, B p ≤ C := by + filter_upwards [hBc.eventually_lt continuousAt_const (show B p₀ < C by dsimp [C]; linarith)] with p hp + exact hp.le + let Z := q.geometricScale + let h := q.H-1 + let T := 1+2*c^3/a^2 + let b := a^2/(2*C*Z*T^(Real.log Z/h)) + have hz : 2 ≤ Z := q.geometricScale_two_le hp₀ + have ht : 0 < T := by + have hh : 0 ≤ 2*c^3/a^2 := by positivity + dsimp [T] + linarith + have hb : 0 < b := div_pos (sq_pos_of_pos ha) (by + have hp := Real.rpow_pos_of_pos ht (Real.log Z/h) + have hZp : 0 < Z := by linarith + positivity) + refine ⟨b,hb,?_⟩ + filter_upwards [hnear,hCB,q.eventually_potentialScale_le hp₀] with p hnear hCB hscale + intro hpc + obtain ⟨hu,hAn,hpp⟩ := hnear + have hp : 0 < (p:ℝ) := lt_of_lt_of_le (by linarith : 0 < (p₀:ℝ)/2) hpp + have hup : 0 < q.rule.successProbability p (root i₀) := + lt_of_lt_of_le (by linarith [q.success_pos]) hu + have hχ1 : 1 ≤ rootSusceptibility G root weight p := by + calc + 1 = ∑ i, weight i*1 := by simp only [mul_one,hw1] + _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left + (susceptibility_one_le G hloc hqt p hpc (root i)) (hw i)) + apply moment_sandwich_power_law a c C Z h ‖A p‖ (rootSusceptibility G root weight p) + (rootNeighborMoment G hloc root weight p) ha hc hC (by linarith) (by dsimp [h]; linarith) + (norm_nonneg _) hAn hχ1 (rootNeighborMoment_nonneg G hloc root weight hw p) + intro j + have hs := q.rule.normalized_power_moment_sandwich hqt root weight Γ htr hΓ hw i₀ hw₀ hcover c hc hmin p hp hpc hup + (A p) (hA p) a ha.le (hχ p hpp hpc) Z hz hscale j + exact hs.trans (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hCB (rootNeighborMoment_nonneg G hloc root weight hw p)) (pow_nonneg (by linarith) j)) + +end EndpointProfile +end ProfileNeighborMoment +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section EfficientProfileMomentConsequence +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem neighborMoment_growth_of_divergent_moment + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (p₀ : unitInterval) (hp₀ : 0 < (p₀:ℝ)) (hp₁ : (p₀:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law p₀, (cluster G ω (root i)).Finite) + (α β ε : ℝ) (hα : 0 < α) (hαβ : α < β) + (hε : 0 < ε) (hε1 : ε < 1/2) (hsmall : β+(1/2+ε) < 1) + (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p₀)) : + ∀ γ : ℝ, 0 < γ → ∃ b : ℝ, 0 < b ∧ ∀ᶠ p in nhds p₀, p < pc G → + b*(rootSusceptibility G root weight p)^(2-γ) ≤ rootNeighborMoment G hloc root weight p := by + obtain ⟨i,heff⟩ := efficient_endpoint_profiles_of_divergent_moment G hloc hconn hqt hh root weight Γ hΓ htr + hcov hw hw1 p₀ hp₀ hp₁ hfin α β ε hα hαβ hε hε1 hsmall hdiv + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + let c : ℝ := ∑ i, 1/weight i + have hc : 0 ≤ c := Finset.sum_nonneg (fun i _ => (one_div_pos.mpr (hw i)).le) + have hmin (i : ι) : 1 ≤ c*weight i := by + apply (div_le_iff₀ (hw i)).mp + exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) + intro γ hγ + let C := Real.log (2*(1+1/(p₀:ℝ))) + have hC : 0 ≤ C := Real.log_nonneg (by + have hinv : 0 ≤ 1/(p₀:ℝ) := (one_div_pos.mpr hp₀).le + nlinarith) + obtain ⟨q,hM,hH,hR,hcost⟩ := heff (γ/4) (by linarith) (2+4*C/γ) + have hH2 : 2 < q.H := by + have hn : 0 ≤ 4*C/γ := div_nonneg (mul_nonneg (by norm_num) hC) hγ.le + linarith + have hCsmall : C < γ*q.H/4 := by + have hx : 4*C < (q.H-2)*γ := (div_lt_iff₀ hγ).mp (by linarith : 4*C/γ < q.H-2) + nlinarith + have hexp : Real.log q.geometricScale/(q.H-1) ≤ γ := by + apply (div_le_iff₀ (by linarith : 0 < q.H-1)).mpr + have hz := q.log_geometricScale_le hp₀ (by omega) + have hm : γ*q.H/2 ≤ γ*(q.H-1) := by nlinarith + dsimp [C] at hCsmall + nlinarith only [hz,hcost,hCsmall,hm] + obtain ⟨b,hb,hnear⟩ := q.eventually_neighborMoment_lower hconn hqt root weight Γ htr + (fun a ha => hΓ ha) (fun i => (hw i).le) hw1 i (hw i) hcover c hc hmin hp₀ hH + refine ⟨b,hb,?_⟩ + filter_upwards [hnear] with p hp + intro hpc + have hχ : 1 ≤ rootSusceptibility G root weight p := by + calc + 1 = ∑ i, weight i*1 := by simp only [mul_one,hw1] + _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left + (susceptibility_one_le G hloc hqt p hpc (root i)) (hw i).le) + exact (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_exponent_le hχ (by linarith : + 2-γ ≤ 2-Real.log q.geometricScale/(q.H-1))) hb.le).trans (hp hpc) + +end EfficientProfileMomentConsequence +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory ProbabilityTheory Function +section PivotalSprinklingGain +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_set_union_pair : Measurable (fun f : Set E × Set E => f.1 ∪ f.2) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + apply measurableSet_setOfPred.mp + change MeasurableSet ({f : Set E × Set E | e ∈ f.1} ∪ {f | e ∈ f.2}) + apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_fst + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_snd + +theorem measurable_set_insert (e : E) : Measurable (fun ω : Set E => insert e ω) := by + have h : Measurable (fun ω : Set E => ({e}:Set E) ∪ ω) := + measurable_set_union_pair.comp (measurable_const.prodMk measurable_id) + simpa only [Set.singleton_union] using (h : Measurable (fun ω : Set E => {e} ∪ ω)) + +theorem measurableSet_closedPivotal (A : Set (Set E)) (hA : MeasurableSet A) (e : E) : + MeasurableSet (closedPivotal A e) := by + exact (measurableSet_mem e).compl.inter (hA.compl.inter (hA.preimage (measurable_set_insert e))) + +def singleSprinkle (Q : Finset E) (e : (Q : Set E)) : Set (Set E) := + {η | Subtype.val ⁻¹' η = {e}} + +theorem measurableSet_singleSprinkle (Q : Finset E) (e : (Q : Set E)) : + MeasurableSet (singleSprinkle Q e) := + (measurableSet_singleton _).preimage (measurable_set_restrict (Q:Set E)) + +theorem singleSprinkle_disjoint (Q : Finset E) : + Pairwise (Disjoint on singleSprinkle Q) := by + intro a b hab + apply Set.disjoint_left.mpr + intro η ha hb + apply hab + have h : ({a} : Set (Q:Set E)) = {b} := ha.symm.trans hb + simpa only [Set.singleton_eq_singleton_iff] using h + +theorem singleSprinkle_mem (Q : Finset E) (e : (Q:Set E)) {η : Set E} + (hη : η ∈ singleSprinkle Q e) : e.val ∈ η := by + have h : e ∈ Subtype.val ⁻¹' η := by rw [hη]; exact Set.mem_singleton e + exact h + +theorem singleSprinkle_probability (Q : Finset E) (e : (Q:Set E)) (a : unitInterval) : + (law a).real (singleSprinkle Q e) = (a:ℝ)*(1-(a:ℝ))^(Q.card-1) := by + have h := congrArg (fun μ : Measure (Set (Q:Set E)) => μ.real {({e}:Set (Q:Set E))}) + (law_map_restrict a (Q:Set E)) + rw [Measure.real,Measure.map_apply (measurable_set_restrict _) (measurableSet_singleton _)] at h + change (law a).real (singleSprinkle Q e) = _ at h + rw [h,law,setBernoulli_real_singleton a (Set.subset_univ _) Set.finite_univ, + Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ,Set.ncard_singleton] + simp only [Set.ncard_univ,Nat.card_eq_fintype_card,pow_one] + rw [show Fintype.card (Q:Set E) = Q.card from Fintype.card_coe Q] + + + +theorem event_sprinkling_gain (p a : unitInterval) (Q : Finset E) + (A : Set (Set E)) (hA : MeasurableSet A) (hup : IsUpperSet A) : + (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * (∑ e ∈ Q, (law p).real (closedPivotal A e)) ≤ + (law (sprinkleParameter p a)).real A - (law p).real A := by + let μ : Measure (Set E × Set E) := (law p).prod (law a) + let B : Set (Set E × Set E) := {f | f.1 ∉ A ∧ f.1 ∪ f.2 ∈ A} + let C (e : (Q:Set E)) := (closedPivotal A e.val) ×ˢ singleSprinkle Q e + have hB : MeasurableSet B := (hA.compl.preimage measurable_fst).inter (hA.preimage measurable_set_union_pair) + have hC (e : (Q:Set E)) : MeasurableSet (C e) := + (measurableSet_closedPivotal A hA e.val).prod (measurableSet_singleSprinkle Q e) + have hd : Pairwise (Disjoint on C) := by + intro e f hef + apply Set.disjoint_left.mpr + intro z hz hz' + exact Set.disjoint_left.mp (singleSprinkle_disjoint Q hef) hz.2 hz'.2 + have hsub : (⋃ e, C e) ⊆ B := by + intro z hz + obtain ⟨e,he⟩ := Set.mem_iUnion.mp hz + refine ⟨he.1.2.1,?_⟩ + apply hup _ he.1.2.2 + intro f hf + rcases Set.mem_insert_iff.mp hf with rfl | hf + · exact Or.inr (singleSprinkle_mem Q e he.2) + · exact Or.inl hf + have hgain : μ.real B = (law (sprinkleParameter p a)).real A - (law p).real A := by + have he : (fun f : Set E × Set E => f.1 ∪ f.2) ⁻¹' A = (A ×ˢ Set.univ) ∪ B := by + ext f + simp only [Set.mem_preimage,Set.mem_union,Set.mem_prod,Set.mem_univ,and_true,B,Set.mem_ofPred_eq] + exact ⟨fun h => by by_cases ha : f.1 ∈ A; exact Or.inl ha; exact Or.inr ⟨ha,h⟩, + fun h => h.elim (fun ha => hup Set.subset_union_left ha) And.right⟩ + have hd : Disjoint (A ×ˢ (Set.univ : Set (Set E))) B := by + apply Set.disjoint_left.mpr + intro f hf hf' + exact hf'.1 hf.1 + have hm := congrArg (fun ν : Measure (Set E) => ν.real A) (law_map_union p a) + rw [Measure.real,Measure.map_apply measurable_set_union_pair hA] at hm + change μ.real ((fun f : Set E × Set E => f.1 ∪ f.2) ⁻¹' A) = _ at hm + rw [he,measureReal_union hd hB] at hm + have hp : μ.real (A ×ˢ Set.univ) = (law p).real A := by + rw [measureReal_prod_prod,probReal_univ,mul_one] + rw [hp] at hm + linarith + have hs : μ.real (⋃ e, C e) = + (a:ℝ)*(1-(a:ℝ))^(Q.card-1) * (∑ e ∈ Q, (law p).real (closedPivotal A e)) := by + rw [measureReal_iUnion_fintype hd hC] + simp only [C,μ,measureReal_prod_prod,singleSprinkle_probability] + rw [←Finset.sum_mul,mul_comm] + congr 1 + apply Finset.sum_bij (fun e _ => e.val) + · intro e _; exact e.property + · intro e _ f _ h; exact Subtype.ext h + · intro e he; exact ⟨⟨e,he⟩,Finset.mem_univ _,rfl⟩ + · intro _ _; rfl + rw [←hs,←hgain] + exact measureReal_mono hsub + +end PivotalSprinklingGain +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/RussoRows.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/RussoRows.lean index b88be35a9645bf463ab8a8c96556684e8441539a..f671e759c7bb95efd24fe223cc08b7a8203b0483 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/RussoRows.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/RussoRows.lean @@ -1,1201 +1,1201 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.ContactTrace - -namespace OAI - -/-! Russo Rows for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section PairFunctionalAlgebra -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem clusterPairFunctional_mono_distinct (G : BondGraph V E) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (F H : Set E → V → V → ℝ≥0∞) - (h : ∀ ω x y, ¬Conn G ω x y → F ω x y ≤ H ω x y) : - clusterPairFunctional G p root weight F ≤ clusterPairFunctional G p root weight H := by - apply Finset.sum_le_sum - intro i _ - apply mul_le_mul_right - apply lintegral_mono - intro ω - unfold clusterPairDensity - apply mul_le_mul_right - apply ENNReal.tsum_le_tsum - intro y - apply mul_le_mul_right - by_cases hc : Conn G ω (root i) y - · simp only [hc,not_true_eq_false,ite_false,le_refl] - · simpa only [ite_eq_left hc] using h ω (root i) y hc - -theorem clusterPairFunctional_congr_ae (G : BondGraph V E) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (F H : Set E → V → V → ℝ≥0∞) - (h : ∀ᵐ ω ∂law p, ∀ x y, ¬Conn G ω x y → F ω x y = H ω x y) : - clusterPairFunctional G p root weight F = clusterPairFunctional G p root weight H := by - apply Finset.sum_congr rfl - intro i _ - congr 1 - apply lintegral_congr_ae - filter_upwards [h] with ω hω - unfold clusterPairDensity - congr 1 - apply tsum_congr - intro y - congr 1 - by_cases hc : Conn G ω (root i) y - · simp only [hc,not_true_eq_false,ite_false] - · rw [ite_eq_left hc,ite_eq_left hc,hω (root i) y hc] - -theorem clusterPairFunctional_add [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (F H : Set E → V → V → ℝ≥0∞) - (hF : ∀ x y, Measurable (fun ω => F ω x y)) - (hH : ∀ x y, Measurable (fun ω => H ω x y)) : - clusterPairFunctional G p root weight (fun ω x y => F ω x y+H ω x y) = - clusterPairFunctional G p root weight F + clusterPairFunctional G p root weight H := by - let : MeasurableSpace V := ⊤ - let : MeasurableSingletonClass V := ⟨fun _ => trivial⟩ - let : MeasurableSpace ι := ⊤ - let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ - rw [clusterPairFunctional_eq_lintegral G hloc p root weight _ hF, - clusterPairFunctional_eq_lintegral G hloc p root weight _ hH, - clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => F ω x y+H ω x y) (fun x y => (hF x y).add (hH x y))] - exact lintegral_add_left (measurable_from_prod_countable_left (fun q => hF (root q.1) q.2)) _ - -theorem clusterPairKernel_symm (G : BondGraph V E) (ω : Set E) - (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J x y = J y x) (x y : V) : - clusterPairKernel G ω J x y = clusterPairKernel G ω J y x := by - unfold clusterPairKernel - rw [ENNReal.tsum_comm] - apply tsum_congr - intro a - apply tsum_congr - intro b - simp only [and_comm,hJ b a] - -end PairFunctionalAlgebra -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section LargeContactCauchySchwarz -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def largeContactKernel (G : BondGraph V E) (L : ℝ) - (ω : Set E) (x y : V) : ℝ≥0∞ := - if L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) then - clusterPairKernel G ω (indexedEdgeKernel G) x y else 0 - -theorem measurable_largeContactKernel [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (L : ℝ) (x y : V) : - Measurable (fun ω => largeContactKernel G L ω x y) := by - have hm (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := - (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) - exact (measurable_clusterPairKernel G (indexedEdgeKernel G) x y).ite - (measurableSet_le measurable_const ((hm x).min (hm y))) measurable_const - -theorem clusterPairFunctional_largeContact_sq [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (L : ℝ) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : - clusterPairFunctional G p root weight (fun ω x y => (largeContactKernel G L ω x y)^2) = - clusterPairFunctional G p root weight (contactSquareLargeReal G L) := by - apply clusterPairFunctional_congr_ae G p root weight - filter_upwards [ae_all_iff.mpr hfin] with ω hω - intro x y hxy - dsimp only [largeContactKernel,contactSquareLargeReal] - split_ifs - · rw [clusterPairKernel_edge G hloc ω x y hxy (hω x)] - · rw [zero_pow (by decide : 2 ≠ 0)] - -theorem clusterPairFunctional_largeContact_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (L : ℝ) (B : ℝ≥0∞) - (hB : clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ B) : - clusterPairFunctional G p root weight (fun ω x y => - largeContactKernel G L ω x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ - B^((1:ℝ)/2)* (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by - have hh := clusterPairFunctional_cauchy_schwarz G hloc p root weight - (largeContactKernel G L) (fun ω x y => clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) - (measurable_largeContactKernel G hloc L) (measurable_clusterPairKernel G _) - rw [clusterPairFunctional_largeContact_sq G hloc L p root weight hfin] at hh - exact hh.trans (mul_le_mul - (ENNReal.rpow_le_rpow hB (by positivity)) - (ENNReal.rpow_le_rpow (clusterPairFunctional_twoPoint_square_bound G hconn hloc root weight Γ hΓ htr hw p hfin T hT) (by positivity)) - bot_le bot_le) - -end LargeContactCauchySchwarz -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal ComplexOrder -section SmallTraceTerm -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem contact_smallTwoPoint_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (L α C : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hI : ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) - (hC : ∀ x, (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G (ennMatrixCoeff (T^2)) L x y ω) ≤ - ENNReal.ofReal ((d:ℝ)*c*C*L^(1-α)*(rootTrace root weight (T^3)).re) := by - have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - have hJ : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff (T^2) (a x) (a y) = ennMatrixCoeff (T^2) x y := by - intro a ha x y - unfold ennMatrixCoeff - rw [(hTI.pow 2) a ha] - have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) - have hMt : 0 ≤ c*(rootTrace root weight (T^3)).re := mul_nonneg hc - (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw _ (CStarAlgebra.pow_nonneg T 3 hpos))).1 - have hh := contact_smallPairKernel_bound G hconn hloc root weight Γ hΓ htr hw hw1 p hfin - (ennMatrixCoeff (T^2)) hJ L d hd (c*C*L^(1-α)*(rootTrace root weight (T^3)).re) (fun x y => by - refine (smallPairKernel_twoPoint_bound G hloc root weight Γ hΓ hcov hw c hc hmin x y p T hT L α hL hα0 hα1 (hfin x) (hfin y) (hI x)).trans ?_ - apply ENNReal.ofReal_le_ofReal - calc - _ ≤ (c*(rootTrace root weight (T^3)).re)*(L^(1-α)*C) := - mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg hL _)) hMt - _ = _ := by ring) - convert hh using 1; congr 1; ring - -end SmallTraceTerm -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal ComplexOrder -section MixedTraceTerm -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem contact_smallPairKernel_swap [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) (L : ℝ) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) y x * smallPairKernel G J L y x ω) = - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) := by - symm - apply clusterPairFunctional_swap G hconn hloc root weight Γ hΓ htr hw p - (fun ω x y => clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) - · intro x y - exact (measurable_clusterPairKernel G _ x y).mul (measurable_smallPairKernel G hloc J L x y) - · intro a ha b hab ω x y - rw [clusterPairKernel_aut G hab _ (indexedEdgeKernel_aut G hab),smallPairKernel_aut G hab J (hJ a ha)] - - - -theorem clusterPairFunctional_twoPoint_mixed_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (p : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (L α C : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) - (hI : ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) - (hC : ∀ x, (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (B : ℝ≥0∞) - (hB : clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ B) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ - 2*ENNReal.ofReal ((d:ℝ)*c*C*L^(1-α)*(rootTrace root weight (T^3)).re) + - B^((1:ℝ)/2)* (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by - let J := ennMatrixCoeff (T^2) - let A := fun ω x y => clusterPairKernel G ω (indexedEdgeKernel G) x y*smallPairKernel G J L x y ω - let D := fun ω x y => largeContactKernel G L ω x y*clusterPairKernel G ω J x y - have heS (ω : Set E) (x y : V) : clusterPairKernel G ω (indexedEdgeKernel G) y x = - clusterPairKernel G ω (indexedEdgeKernel G) x y := clusterPairKernel_symm G ω _ (indexedEdgeKernel_symm G) y x - have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) - have hJS (ω : Set E) (x y : V) : clusterPairKernel G ω J y x = clusterPairKernel G ω J x y := - clusterPairKernel_symm G ω J (ennMatrixCoeff_symm ((IsSelfAdjoint.of_nonneg hpos).pow 2)) y x - have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - have hJI : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y := by - intro a ha x y - dsimp [J,ennMatrixCoeff] - rw [(hTI.pow 2) a ha] - have hA (x y : V) : Measurable (fun ω => A ω x y) := - (measurable_clusterPairKernel G _ x y).mul (measurable_smallPairKernel G hloc J L x y) - have hD (x y : V) : Measurable (fun ω => D ω x y) := - (measurable_largeContactKernel G hloc L x y).mul (measurable_clusterPairKernel G J x y) - have hpw (ω : Set E) (x y : V) (hxy : ¬Conn G ω x y) : - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y ≤ A ω x y + A ω y x + D ω x y := by - have hyx : ¬Conn G ω y x := fun h => hxy (conn_symm G ω h) - by_cases hx : ((cluster G ω x).ncard:ℝ) < L - · have ha : A ω x y = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by - dsimp [A,smallPairKernel]; rw [ite_eq_left ⟨hx,hxy⟩] - rw [←ha] - exact le_add_of_le_left (le_add_right le_rfl) - · by_cases hy : ((cluster G ω y).ncard:ℝ) < L - · have ha : A ω y x = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by - dsimp [A,smallPairKernel]; rw [ite_eq_left ⟨hy,hyx⟩,heS ω x y,hJS ω x y] - rw [←ha] - exact le_add_of_le_left (le_add_left le_rfl) - · have hg : L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) := le_min (le_of_not_gt hx) (le_of_not_gt hy) - have hh : D ω x y = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by - dsimp [D,largeContactKernel]; rw [ite_eq_left hg] - rw [←hh] - exact le_add_left le_rfl - have ha := contact_smallTwoPoint_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin p hfin T hT L α C hL hα0 hα1 hI hC d hd - have hb := clusterPairFunctional_largeContact_bound G hconn hloc root weight Γ hΓ htr hw p hfin T hT L B hB - calc - _ ≤ clusterPairFunctional G p root weight (fun ω x y => A ω x y+A ω y x+D ω x y) := - clusterPairFunctional_mono_distinct G p root weight _ _ hpw - _ = (clusterPairFunctional G p root weight A + clusterPairFunctional G p root weight A) + clusterPairFunctional G p root weight D := by - rw [clusterPairFunctional_add G hloc p root weight (fun ω x y => A ω x y+A ω y x) D (fun x y => (hA x y).add (hA y x)) hD, - clusterPairFunctional_add G hloc p root weight A (fun ω x y => A ω y x) hA (fun x y => hA y x)] - rw [contact_smallPairKernel_swap G hconn hloc root weight Γ hΓ htr hw p J hJI L] - _ ≤ _ := by simpa only [two_mul] using add_le_add (add_le_add ha ha) hb - -end MixedTraceTerm -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section UniformMixedTrace -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_mixed_trace_bound - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ A B : ℝ, 0 < A ∧ 0 < B ∧ ∀ (p : unitInterval), - (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → - ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → - ∀ L : ℝ, 1 ≤ L → - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * - clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ - 2*ENNReal.ofReal (A*L^(1-α)*(rootTrace root weight (T^3)).re) + - (ENNReal.ofReal (B*L^((1:ℝ)/2+ε-2*α)))^((1:ℝ)/2) * - (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by - have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by - intro x - obtain ⟨i,a,ha,hax⟩ := hcov x - obtain ⟨b,hab⟩ := hΓ ha - exact ⟨i,a,b,hab,hax⟩ - have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by - intro x - obtain ⟨i,a,b,hab,rfl⟩ := hcover x - exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) - obtain ⟨C,hC,hCb⟩ := uniform_cluster_power_of_root G hloc (pc G) root hcover α - (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) - obtain ⟨B,hB,hBb⟩ := critical_contact_square_bound G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - obtain ⟨d,hd,hdg⟩ := exists_degree_bound G hqt - let c : ℝ := ∑ i, 1/weight i - have hc : 0 < c := Finset.sum_pos (fun i _ => one_div_pos.mpr (hw i)) Finset.univ_nonempty - have hmin (i : ι) : 1 ≤ c*weight i := by - apply (div_le_iff₀ (hw i)).mp - exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) - refine ⟨(d:ℝ)*c*C,B,mul_pos (mul_pos (by exact_mod_cast hd) hc) hC,hB,?_⟩ - intro p hp hpq T hT L hL - have hm (x : V) := cluster_power_mono_integral G hloc x p (pc G) hpq α hα.le (hfinite x) (hCb x).1 - exact clusterPairFunctional_twoPoint_mixed_bound G hconn hloc root weight Γ hΓ htr hcov - (fun i => (hw i).le) hw1 c hc.le hmin p - (fun x => cluster_finite_ae_mono G x p (pc G) hpq (hfinite x)) - T hT L α C (by linarith) hα.le (by linarith) - (fun x => (hm x).1) (fun x => (hm x).2.trans (hCb x).2) d hdg _ (hBb p hp hpq L hL) - -end UniformMixedTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ConnectionRussoContacts -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem closedPivotal_connection_iff (G : BondGraph V E) (ω : Set E) (x y : V) (e : E) : - ω ∈ closedPivotal {η | Conn G η x y} e ↔ - ¬Conn G ω x y ∧ e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) := by - constructor - · rintro ⟨_,hxy,hins⟩ - refine ⟨hxy,?_⟩ - obtain ⟨⟨a,b⟩,hab⟩ := Quot.exists_rep (G e) - have he : G e = s(a,b) := hab.symm - rcases (conn_insert_iff G ω e a b x y he).mp hins with h | h | h - · exact (hxy h).elim - · exact ⟨a,h.1,b,conn_symm G ω h.2,he⟩ - · exact ⟨b,h.1,a,conn_symm G ω h.2,by rw [he,Sym2.eq_swap]⟩ - · rintro ⟨hxy,a,hxa,b,hyb,he⟩ - have hclosed : e ∉ ω := by - intro heω - exact hxy (hxa.trans ((Relation.ReflTransGen.single ⟨e,heω,he⟩).trans (conn_symm G ω hyb))) - refine ⟨hclosed,hxy,?_⟩ - exact (conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨hxa,conn_symm G ω hyb⟩)) - -noncomputable def finiteClosedContact (G : BondGraph V E) (Q : Finset E) (x y : V) - (ω : Finset E) : ℝ := - if ¬Conn G (ω:Set E) x y then - (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω y)).card else 0 - -theorem finiteClosedContact_eq_sum (G : BondGraph V E) (Q : Finset E) (x y : V) - (ω : Finset E) : - finiteClosedContact G Q x y ω = - ∑ e ∈ Q, if (ω:Set E) ∈ closedPivotal {η | Conn G η x y} e then (1:ℝ) else 0 := by - have hm (z a : V) : a ∈ finiteRootComponent G ω z ↔ Conn G (ω:Set E) z a := by - change a ∈ (finiteRootComponent G ω z:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - simp only [closedPivotal_connection_iff,closedContactSet,Set.mem_ofPred_eq,finiteClosedContact] - by_cases hxy : Conn G (ω:Set E) x y - · simp only [hxy,not_true_eq_false,false_and,ite_false,Finset.sum_const_zero] - · rw [ite_eq_left hxy] - simp only [hxy,not_false_eq_true,true_and,contactBonds,hm,cluster,Set.mem_ofPred_eq] - rw [Finset.sum_boole] - -theorem finite_connection_russo_contacts (G : BondGraph V E) (Q : Finset E) - (x y : V) (p : ℝ) : - (1-p)*deriv (finiteEventPolynomial Q {ω | Conn G ω x y}) p = - bernoulliPolynomial Q (finiteClosedContact G Q x y) p := by - change (1-p)*deriv (bernoulliPolynomial Q (fun ω => if Conn G (ω:Set E) x y then 1 else 0)) p = _ - rw [closed_difference_russo] - have he : finiteClosedContact G Q x y = fun (ω : Finset E) => - ∑ e ∈ Q, if (ω:Set E) ∈ closedPivotal {η | Conn G η x y} e then (1:ℝ) else 0 := - funext (finiteClosedContact_eq_sum G Q x y) - rw [he,bernoulliPolynomial_sum] - apply Finset.sum_congr rfl - intro e _ - apply bernoulliPolynomial_congr - intro ω _ - exact (closedPivotal_difference {η | Conn G η x y} - (fun _ _ h hc => conn_mono G h hc) e ω).symm - -end ConnectionRussoContacts -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section UniformContactApproximation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteClosedContact_eq_full (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) - (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) - (hQy : incidentSupport G hloc hy.toFinset ⊆ Q) : - finiteClosedContact G Q x y (domainBits Q ω) = fullLargeContact G x y 0 ω := by - have hcluster (z : V) (hz : (cluster G ω z).Finite) (hQ : incidentSupport G hloc hz.toFinset ⊆ Q) : - cluster G (domainBits Q ω:Set E) z = cluster G ω z := by - rw [coe_domainBits] - have hh := (cluster_restrict_incident_eq_iff G hloc hz.toFinset Q hQ ω z).mpr - (Set.Finite.coe_toFinset hz).symm - simpa only [Set.Finite.coe_toFinset] using hh - have hcx := hcluster x hx hQx - have hcy := hcluster y hy hQy - have hFx : finiteRootComponent G (domainBits Q ω) x = hx.toFinset := by - apply Finset.coe_injective - rw [coe_finiteRootComponent,hcx,Set.Finite.coe_toFinset] - have hFy : finiteRootComponent G (domainBits Q ω) y = hy.toFinset := by - apply Finset.coe_injective - rw [coe_finiteRootComponent,hcy,Set.Finite.coe_toFinset] - have hconn : Conn G (domainBits Q ω:Set E) x y ↔ Conn G ω x y := by - change y ∈ cluster G (domainBits Q ω:Set E) x ↔ y ∈ cluster G ω x - rw [hcx] - have hc : (contactBonds G Q hx.toFinset hy.toFinset).card = clusterContactCount G ω x y := by - rw [←Set.ncard_coe_finset,coe_contactBonds_eq G hloc Q _ _ hQx] - simp only [Set.Finite.coe_toFinset,clusterContactCount] - simp only [finiteClosedContact,fullLargeContact,hconn,hFx,hFy,hc,Nat.zero_le,and_true] - -theorem finiteClosedContact_nonneg (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) : - 0 ≤ finiteClosedContact G Q x y ω := by - unfold finiteClosedContact - split_ifs <;> positivity - -theorem finiteClosedContact_le_size (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q η : Finset E) (ω : Set E) - (hη : (η:Set E) ⊆ ω) (x y : V) (hfin : (cluster G ω x).Finite) : - finiteClosedContact G Q x y η ≤ (d:ℝ)*(cluster G ω x).ncard := by - have hdQ (z : V) : (Q.filter fun e => z ∈ G e).card ≤ d := - (incident_filter_card_le_degree G hloc Q z).trans (hd z) - have hs : (finiteRootComponent G η x).card ≤ (cluster G ω x).ncard := by - rw [←Set.ncard_coe_finset,coe_finiteRootComponent] - exact Set.ncard_le_ncard (fun z hz => conn_mono G hη hz) hfin - unfold finiteClosedContact - split_ifs - · positivity - · exact_mod_cast (contactBonds_card_le G Q d hdQ _ _).trans - (Nat.mul_le_mul_left d ((min_le_left _ _).trans hs)) - - - -theorem lower_cluster_restrict_eq (G : BondGraph V E) (hloc : LocallyFinite G) - (ω η : Set E) (hη : η ⊆ ω) (x : V) (hx : (cluster G ω x).Finite) - (Q : Finset E) (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : - cluster G (η ∩ (Q:Set E)) x = cluster G η x := by - have hfin : (cluster G η x).Finite := hx.subset (fun z hz => conn_mono G hη hz) - have hs : hfin.toFinset ⊆ hx.toFinset := by - intro z hz - exact hx.mem_toFinset.mpr (conn_mono G hη (hfin.mem_toFinset.mp hz)) - have hQ' := (incidentSupport_mono G hloc hs).trans hQ - have hh := (cluster_restrict_incident_eq_iff G hloc hfin.toFinset Q hQ' η x).mpr - (Set.Finite.coe_toFinset hfin).symm - simpa only [Set.Finite.coe_toFinset] using hh - -end UniformContactApproximation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section ContactRegularity -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem fullLargeContact_zero_le_size (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (ω : Set E) (x y : V) - (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) : - fullLargeContact G x y 0 ω ≤ (d:ℝ)*(cluster G ω x).ncard := by - let Q := incidentSupport G hloc hx.toFinset ∪ incidentSupport G hloc hy.toFinset - rw [←finiteClosedContact_eq_full G hloc ω x y hx hy Q Finset.subset_union_left Finset.subset_union_right] - exact finiteClosedContact_le_size G hloc d hd Q (domainBits Q ω) ω - (by rw [coe_domainBits]; exact Set.inter_subset_left) x y hx - -theorem integrable_fullContact_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - Integrable (fullLargeContact G x y 0) (law p) := by - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - apply ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)).mono' - (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable - filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy - rw [Real.norm_of_nonneg (fullLargeContact_nonneg G x y 0 ω)] - exact fullLargeContact_zero_le_size G hloc d hd ω x y hx hy - -theorem fullContact_label_integral [Countable E] [Countable V] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) : - (∫ labels, fullLargeContact G x y 0 (openEdges labels p) ∂labelLaw) = - ∫ ω, fullLargeContact G x y 0 ω ∂law p := by - rw [←map_openEdges p] - exact (integral_map (measurable_openEdges p).aemeasurable - (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable).symm - -theorem fullContact_label_integrable [Countable E] [Countable V] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) : - Integrable (fun labels => fullLargeContact G x y 0 (openEdges labels p)) labelLaw ↔ - Integrable (fullLargeContact G x y 0) (law p) := by - rw [←map_openEdges p] - exact (integrable_map_measure (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable - (measurable_openEdges p).aemeasurable).symm - -theorem fullContact_eq_of_clusters (G : BondGraph V E) (ω η : Set E) (x y : V) - (hx : cluster G ω x = cluster G η x) (hy : cluster G ω y = cluster G η y) : - fullLargeContact G x y 0 ω = fullLargeContact G x y 0 η := by - have hc : Conn G ω x y ↔ Conn G η x y := by - change y ∈ cluster G ω x ↔ y ∈ cluster G η x - rw [hx] - simp only [fullLargeContact,clusterContactCount,hx,hy,hc] - - - -theorem continuousAt_fullContact_expectation [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - ContinuousAt (fun q => ∫ ω, fullLargeContact G x y 0 ω ∂law q) p := by - obtain ⟨r,hpr,hr⟩ := exists_between hp - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - let F (q : unitInterval) (labels : E → unitInterval) := fullLargeContact G x y 0 (openEdges labels q) - let B (labels : E → unitInterval) : ℝ := (d:ℝ)*(cluster G (openEdges labels r) x).ncard - have hm (q : unitInterval) : Measurable (F q) := - (measurable_fullLargeContact G hloc x y 0).comp (measurable_openEdges q) - have hc : ContinuousAt (fun q => ∫ labels, F q labels ∂labelLaw) p := by - apply continuousAt_of_dominated (bound := B) - (Eventually.of_forall (fun q => (hm q).aestronglyMeasurable)) - · filter_upwards [eventually_lt_nhds hpr] with q hqr - filter_upwards [label_cluster_finite_ae_subcritical G r hr x,label_cluster_finite_ae_subcritical G r hr y] with labels hx hy - have hsub (z : V) : cluster G (openEdges labels q) z ⊆ cluster G (openEdges labels r) z := - fun w hw => conn_mono G (openEdges_mono labels hqr.le) hw - rw [Real.norm_of_nonneg (fullLargeContact_nonneg G x y 0 _)] - calc - _ ≤ (d:ℝ)*(cluster G (openEdges labels q) x).ncard := - fullLargeContact_zero_le_size G hloc d hd _ x y (hx.subset (hsub x)) (hy.subset (hsub y)) - _ ≤ B labels := mul_le_mul_of_nonneg_left (by exact_mod_cast Set.ncard_le_ncard (hsub x) hx) (Nat.cast_nonneg _) - · exact (susceptibility_eq_label_integral G hloc hqt r hr x).1.const_mul (d:ℝ) - · filter_upwards [ae_labels_ne (E := E) p,label_cluster_finite_ae_subcritical G p hp x, - label_cluster_finite_ae_subcritical G p hp y] with labels hneq hx hy - apply Filter.EventuallyEq.continuousAt - filter_upwards [eventually_cluster_eq_at_finite G hloc labels p x hneq hx, - eventually_cluster_eq_at_finite G hloc labels p y hneq hy] with q hqx hqy - exact fullContact_eq_of_clusters G _ _ x y hqx hqy - simpa only [F,fullContact_label_integral G hloc] using hc - -end ContactRegularity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section UniformContactError -attribute [local instance] Classical.propDecidable Classical.decEq - -def ClusterSupportIn (G : BondGraph V E) (Q : Finset E) (ω : Set E) (x : V) : Prop := - ∀ a, Conn G ω x a → ∀ e, a ∈ G e → e ∈ Q - -theorem measurableSet_clusterSupportIn [Countable V] [Countable E] - (G : BondGraph V E) (Q : Finset E) (x : V) : - MeasurableSet {ω : Set E | ClusterSupportIn G Q ω x} := by - simp only [ClusterSupportIn,Set.ofPred_forall] - apply MeasurableSet.iInter - intro a - have he : {ω : Set E | Conn G ω x a → ∀ e, a ∈ G e → e ∈ Q} = - {ω | ¬Conn G ω x a} ∪ {ω | ∀ e, a ∈ G e → e ∈ Q} := by ext ω; simp only [Set.mem_union,Set.mem_ofPred_eq]; tauto - rw [he] - apply (measurableSet_conn G x a).compl.union - by_cases h : ∀ e, a ∈ G e → e ∈ Q - · convert (MeasurableSet.univ : MeasurableSet (Set.univ : Set (Set E))) using 1 - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_univ,iff_true] - exact h - · convert (MeasurableSet.empty : MeasurableSet (∅ : Set (Set E))) using 1 - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] - exact h - -theorem clusterSupportIn_of_incident (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (ω : Set E) (x : V) (hx : (cluster G ω x).Finite) - (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : ClusterSupportIn G Q ω x := by - intro a ha e he - exact hQ ((mem_incidentSupport G hloc hx.toFinset e).mpr ⟨a,hx.mem_toFinset.mpr ha,he⟩) - -theorem finiteClosedContact_eq_full_of_support (G : BondGraph V E) (hloc : LocallyFinite G) - (Q : Finset E) (ω η : Set E) (hη : η ⊆ ω) (x y : V) - (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) - (hQx : ClusterSupportIn G Q ω x) (hQy : ClusterSupportIn G Q ω y) : - finiteClosedContact G Q x y (domainBits Q η) = fullLargeContact G x y 0 η := by - have hsub (z : V) : cluster G η z ⊆ cluster G ω z := fun a ha => conn_mono G hη ha - have hfx := hx.subset (hsub x) - have hfy := hy.subset (hsub y) - apply finiteClosedContact_eq_full G hloc η x y hfx hfy - · intro e he - obtain ⟨a,ha,he⟩ := (mem_incidentSupport G hloc hfx.toFinset e).mp he - exact hQx a (hsub x (hfx.mem_toFinset.mp ha)) e he - · intro e he - obtain ⟨a,ha,he⟩ := (mem_incidentSupport G hloc hfy.toFinset e).mp he - exact hQy a (hsub y (hfy.mem_toFinset.mp ha)) e he - -noncomputable def contactApproxError (G : BondGraph V E) (Q : Finset E) (d : ℕ) - (x y : V) (ω : Set E) : ℝ := - if ClusterSupportIn G Q ω x ∧ ClusterSupportIn G Q ω y then 0 - else (d:ℝ)*(cluster G ω x).ncard - -theorem measurable_contactApproxError [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (Q : Finset E) (d : ℕ) (x y : V) : - Measurable (contactApproxError G Q d x y) := by - exact measurable_const.ite ((measurableSet_clusterSupportIn G Q x).inter - (measurableSet_clusterSupportIn G Q y)) - (measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x))) - -theorem contactApproxError_nonneg (G : BondGraph V E) (Q : Finset E) (d : ℕ) (x y : V) (ω : Set E) : - 0 ≤ contactApproxError G Q d x y ω := by unfold contactApproxError; split_ifs <;> positivity - -theorem contactApproxError_le (G : BondGraph V E) (Q : Finset E) (d : ℕ) (x y : V) (ω : Set E) : - contactApproxError G Q d x y ω ≤ (d:ℝ)*(cluster G ω x).ncard := by - unfold contactApproxError; split_ifs <;> first | positivity | exact le_rfl - -theorem contact_uniform_error_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q : Finset E) (ω η : Set E) - (hη : η ⊆ ω) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) : - ‖finiteClosedContact G Q x y (domainBits Q η) - fullLargeContact G x y 0 η‖ ≤ - contactApproxError G Q d x y ω := by - unfold contactApproxError - split_ifs with h - · rw [finiteClosedContact_eq_full_of_support G hloc Q ω η hη x y hx hy h.1 h.2,sub_self,norm_zero] - · have hsub (z : V) : cluster G η z ⊆ cluster G ω z := fun a ha => conn_mono G hη ha - have hf := finiteClosedContact_le_size G hloc d hd Q (domainBits Q η) ω - (by rw [coe_domainBits]; exact Set.inter_subset_left.trans hη) x y hx - have hg : fullLargeContact G x y 0 η ≤ (d:ℝ)*(cluster G ω x).ncard := by - exact (fullLargeContact_zero_le_size G hloc d hd η x y (hx.subset (hsub x)) (hy.subset (hsub y))).trans - (mul_le_mul_of_nonneg_left (by exact_mod_cast Set.ncard_le_ncard (hsub x) hx) (Nat.cast_nonneg _)) - rw [Real.norm_eq_abs,abs_sub_le_iff] - have hfn := finiteClosedContact_nonneg G Q x y (domainBits Q η) - have hgn := fullLargeContact_nonneg G x y 0 η - constructor <;> linarith - -end UniformContactError -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section UniformContactExpectation -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integrable_contactApproxError [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (Q : Finset E) (d : ℕ) (x y : V) : - Integrable (contactApproxError G Q d x y) (law p) := by - apply ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)).mono' - (measurable_contactApproxError G hloc Q d x y).aestronglyMeasurable - exact Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (contactApproxError_nonneg G Q d x y ω)]; exact contactApproxError_le G Q d x y ω) - -theorem contactApproxError_integral_tendsto_zero [Countable V] [Encodable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (d : ℕ) (x y : V) : - Tendsto (fun n => ∫ ω, contactApproxError G (vertexExhaustion n) d x y ω ∂law p) atTop (nhds 0) := by - have ht : ∀ᵐ ω ∂law p, Tendsto (fun n => contactApproxError G (vertexExhaustion n) d x y ω) atTop (nhds 0) := by - filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy - obtain ⟨nx,hnx⟩ := subset_vertexExhaustion (incidentSupport G hloc hx.toFinset) - obtain ⟨ny,hny⟩ := subset_vertexExhaustion (incidentSupport G hloc hy.toFinset) - apply tendsto_const_nhds.congr' - filter_upwards [eventually_ge_atTop (max nx ny)] with n hn - exact (ite_eq_left ⟨clusterSupportIn_of_incident G hloc _ ω x hx - (hnx.trans (vertexExhaustion_mono ((le_max_left nx ny).trans hn))), - clusterSupportIn_of_incident G hloc _ ω y hy - (hny.trans (vertexExhaustion_mono ((le_max_right nx ny).trans hn)))⟩).symm - have hh := tendsto_integral_of_dominated_convergence (fun ω : Set E => (d:ℝ)*(cluster G ω x).ncard) - (fun n => (measurable_contactApproxError G hloc (vertexExhaustion n) d x y).aestronglyMeasurable) - ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)) - (fun n => Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (contactApproxError_nonneg G _ d x y ω)]; exact contactApproxError_le G _ d x y ω)) ht - simpa only [integral_zero] using hh - -theorem finiteClosedContact_label_integral [Countable E] (G : BondGraph V E) - (Q : Finset E) (p : unitInterval) (x y : V) : - (∫ labels, finiteClosedContact G Q x y (domainBits Q (openEdges labels p)) ∂labelLaw) = - bernoulliPolynomial Q (finiteClosedContact G Q x y) p := by - rw [←integral_domainBits Q p (finiteClosedContact G Q x y),←map_openEdges p] - exact (integral_map (measurable_openEdges p).aemeasurable - (measurable_finite_local Q (fun ω => finiteClosedContact G Q x y (domainBits Q ω)) (fun ω => by rw [domainBits_local])).aestronglyMeasurable).symm - -theorem contactApproxError_label_integral [Countable V] [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (Q : Finset E) (p : unitInterval) (d : ℕ) (x y : V) : - (∫ labels, contactApproxError G Q d x y (openEdges labels p) ∂labelLaw) = - ∫ ω, contactApproxError G Q d x y ω ∂law p := by - rw [←map_openEdges p] - exact (integral_map (measurable_openEdges p).aemeasurable - (measurable_contactApproxError G hloc Q d x y).aestronglyMeasurable).symm - -theorem contact_expectation_uniform_error [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q : Finset E) (b q : unitInterval) - (hb : b < pc G) (hq : q ≤ b) (x y : V) : - ‖bernoulliPolynomial Q (finiteClosedContact G Q x y) q - - ∫ ω, fullLargeContact G x y 0 ω ∂law q‖ ≤ - ∫ ω, contactApproxError G Q d x y ω ∂law b := by - have hf : Integrable (fun labels => finiteClosedContact G Q x y (domainBits Q (openEdges labels q))) labelLaw := by - have hi := integrable_finite_local Q q (fun ω => finiteClosedContact G Q x y (domainBits Q ω)) - (fun ω => by rw [domainBits_local]) - rw [←map_openEdges q] at hi - exact hi.comp_measurable (measurable_openEdges q) - have hg := (fullContact_label_integrable G hloc q x y).mpr - (integrable_fullContact_subcritical G hloc hqt q (hq.trans_lt hb) x y) - have hi : Integrable (fun labels => contactApproxError G Q d x y (openEdges labels b)) labelLaw := by - have hh := integrable_contactApproxError G hloc hqt b hb Q d x y - rw [←map_openEdges b] at hh - exact hh.comp_measurable (measurable_openEdges b) - rw [←finiteClosedContact_label_integral G Q q x y,←fullContact_label_integral G hloc q x y, - ←integral_sub hf hg,←contactApproxError_label_integral G hloc Q b d x y] - apply (norm_integral_le_integral_norm _).trans - apply integral_mono_ae (hf.sub hg).norm hi - filter_upwards [label_cluster_finite_ae_subcritical G b hb x,label_cluster_finite_ae_subcritical G b hb y] with labels hx hy - exact contact_uniform_error_bound G hloc d hd Q _ _ (openEdges_mono labels hq) x y hx hy - -end UniformContactExpectation -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section PointwiseRussoLimit -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def realContactExpectation (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := - ∫ ω, fullLargeContact G x y 0 ω ∂law (Set.projIcc 0 1 zero_le_one t) - -@[simp] theorem realContactExpectation_coe (G : BondGraph V E) (x y : V) (p : unitInterval) : - realContactExpectation G x y (p:ℝ) = ∫ ω, fullLargeContact G x y 0 ω ∂law p := by - simp only [realContactExpectation,Set.projIcc_val] - -noncomputable def realTwoPoint (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := - twoPoint G (Set.projIcc 0 1 zero_le_one t) x y - -@[simp] theorem realTwoPoint_coe (G : BondGraph V E) (x y : V) (p : unitInterval) : - realTwoPoint G x y (p:ℝ) = twoPoint G p x y := by - simp only [realTwoPoint,Set.projIcc_val] - -theorem finite_connection_deriv_eq (G : BondGraph V E) (Q : Finset E) - (x y : V) (t : ℝ) (ht : t ≠ 1) : - deriv (finiteEventPolynomial Q {ω | Conn G ω x y}) t = - bernoulliPolynomial Q (finiteClosedContact G Q x y) t / (1-t) := by - apply (eq_div_iff (sub_ne_zero.mpr (Ne.symm ht))).mpr - rw [mul_comm] - exact finite_connection_russo_contacts G Q x y t - -theorem finite_connection_deriv_tendstoUniformlyOn [Countable V] [Encodable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) (x y : V) : - TendstoUniformlyOn (fun n => deriv (finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y})) - (fun t => realContactExpectation G x y t / (1-t)) atTop (Set.Icc 0 (b:ℝ)) := by - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - have hb1 : (b:ℝ) < 1 := lt_of_lt_of_le hb (pc G).2.2 - have hden : 0 < 1-(b:ℝ) := sub_pos.mpr hb1 - have ht := (contactApproxError_integral_tendsto_zero G hloc hqt b hb d x y).div_const (1-(b:ℝ)) - rw [zero_div] at ht - rw [Metric.tendstoUniformlyOn_iff] - intro ε hε - filter_upwards [ht.eventually (eventually_lt_nhds hε)] with n hn t ht - let q : unitInterval := ⟨t,ht.1,ht.2.trans b.2.2⟩ - have hqb : q ≤ b := ht.2 - have hqt1 : t < 1 := ht.2.trans_lt hb1 - have he := contact_expectation_uniform_error G hloc hqt d hd (vertexExhaustion n) b q hb hqb x y - have hn0 : 0 ≤ ∫ ω, contactApproxError G (vertexExhaustion n) d x y ω ∂law b := - integral_nonneg (contactApproxError_nonneg G _ d x y) - rw [dist_comm,Real.dist_eq,finite_connection_deriv_eq G _ x y t (ne_of_lt hqt1),←sub_div,abs_div, - abs_of_pos (sub_pos.mpr hqt1)] - change |bernoulliPolynomial _ _ (q:ℝ) - realContactExpectation G x y (q:ℝ)| / (1-t) < ε - rw [realContactExpectation_coe] - apply lt_of_le_of_lt _ hn - exact div_le_div₀ hn0 (by simpa only [Real.norm_eq_abs] using he) hden (sub_le_sub_left ht.2 1) - -theorem finite_connection_polynomial_tendsto_twoPoint [Encodable E] - (G : BondGraph V E) (p : unitInterval) (x y : V) : - Tendsto (fun n => finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y} p) - atTop (nhds (twoPoint G p x y)) := by - have ht := finite_connection_polynomial_tendsto G Set.univ (vertexExhaustion (V := E)) - vertexExhaustion_mono (fun _ => Set.subset_univ _) (fun e _ => by - obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e}:Finset E) - exact ⟨n,hn (by simp)⟩) p x y - simpa only [Set.inter_univ,finiteEventPolynomial,Set.mem_ofPred_eq,twoPoint,Measure.real] using ht - - - -theorem hasDerivAt_realTwoPoint_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x y : V) : - HasDerivAt (realTwoPoint G x y) - ((∫ ω, fullLargeContact G x y 0 ω ∂law p)/(1-(p:ℝ))) (p:ℝ) := by - let : Encodable E := Encodable.ofCountable E - obtain ⟨b,hpb,hb⟩ := exists_between hp - have hu := (finite_connection_deriv_tendstoUniformlyOn G hloc hqt b hb x y).mono - (show Set.Ioo 0 (b:ℝ) ⊆ Set.Icc 0 (b:ℝ) from Set.Ioo_subset_Icc_self) - have hh := hasDerivAt_of_tendstoUniformlyOn (f := fun n => finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y}) - (g := realTwoPoint G x y) (g' := fun t => realContactExpectation G x y t/(1-t)) isOpen_Ioo hu - (Eventually.of_forall (fun n t _ => by - change HasDerivAt (bernoulliPolynomial (vertexExhaustion n) (fun (ω : Finset E) => if Conn G (ω:Set E) x y then (1:ℝ) else 0)) _ t - exact (hasDerivAt_bernoulliPolynomial (vertexExhaustion n) - (fun (ω : Finset E) => if Conn G (ω:Set E) x y then (1:ℝ) else 0) t).differentiableAt.hasDerivAt)) - (fun t ht => by - let q : unitInterval := ⟨t,ht.1.le,ht.2.le.trans b.2.2⟩ - simpa only [←realTwoPoint_coe G x y q] using finite_connection_polynomial_tendsto_twoPoint G q x y) - (show (p:ℝ) ∈ Set.Ioo 0 (b:ℝ) from ⟨hp0,hpb⟩) - simpa only [realContactExpectation_coe] using hh - -end PointwiseRussoLimit -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section RussoDiagram -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def russoDiagram (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ≥0∞ := - ∑' a, ∑' b, indexedEdgeKernel G a b * - (law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b}) - -theorem conn_probability_symm (G : BondGraph V E) (p : unitInterval) (x y : V) : - law p {ω | Conn G ω x y} = law p {ω | Conn G ω y x} := by - congr 1 - ext ω - exact ⟨conn_symm G ω,conn_symm G ω⟩ - -theorem conn_probability_mono [Countable V] [Countable E] (G : BondGraph V E) - (p q : unitInterval) (hpq : p ≤ q) (x y : V) : - law p {ω | Conn G ω x y} ≤ law q {ω | Conn G ω x y} := by - rw [←ENNReal.ofReal_toReal (measure_ne_top (law p) _),←ENNReal.ofReal_toReal (measure_ne_top (law q) _)] - exact ENNReal.ofReal_le_ofReal (twoPoint_mono G x y hpq) - -theorem fullContact_lintegral_eq_kernel [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) - (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : - (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = - ∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω (indexedEdgeKernel G) x y else 0 ∂law p := by - apply lintegral_congr_ae - filter_upwards [hx] with ω hω - by_cases hxy : Conn G ω x y - · simp only [fullLargeContact,hxy,not_true_eq_false,false_and,ite_false,ENNReal.ofReal_zero] - · rw [ite_eq_left hxy,clusterPairKernel_edge G hloc ω x y hxy hω] - simp only [fullLargeContact,hxy,Nat.zero_le,not_false_eq_true,and_self,ite_true,ENNReal.ofReal_natCast] - -theorem fullContact_expectation_le_diagram [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x y : V) : - ENNReal.ofReal (∫ ω, fullLargeContact G x y 0 ω ∂law p) ≤ russoDiagram G p x y := by - rw [ofReal_integral_eq_lintegral_ofReal (integrable_fullContact_subcritical G hloc hqt p hp x y) - (Eventually.of_forall (fullLargeContact_nonneg G x y 0))] - rw [fullContact_lintegral_eq_kernel G hloc p x y (subcritical_cluster_finite_ae G p hp x)] - exact clusterPairKernel_distinct_bound G p (indexedEdgeKernel G) x y - -theorem russoDiagram_mono [Countable V] [Countable E] (G : BondGraph V E) - (p q : unitInterval) (hpq : p ≤ q) (x y : V) : russoDiagram G p x y ≤ russoDiagram G q x y := by - exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => - mul_le_mul_right (mul_le_mul' (conn_probability_mono G p q hpq x a) - (conn_probability_mono G p q hpq y b)) _)) - -theorem russoDiagram_symm (G : BondGraph V E) (p : unitInterval) (x y : V) : - russoDiagram G p x y = russoDiagram G p y x := by - unfold russoDiagram - rw [ENNReal.tsum_comm] - apply tsum_congr; intro b - apply tsum_congr; intro a - rw [indexedEdgeKernel_symm G a b,mul_comm (law p {ω | Conn G ω x a})] - -theorem russoDiagram_row_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ z, degree G z ≤ d) (p : unitInterval) (C : ℝ≥0∞) - (hC : ∀ x, ∑' y, law p {ω | Conn G ω x y} ≤ C) (x : V) : - (∑' y, russoDiagram G p x y) ≤ (d:ℝ≥0∞)*C^2 := by - unfold russoDiagram - rw [ENNReal.tsum_comm] - calc - _ = ∑' a, ∑' b, indexedEdgeKernel G a b * law p {ω | Conn G ω x a} * - ∑' y, law p {ω | Conn G ω b y} := by - apply tsum_congr; intro a - rw [ENNReal.tsum_comm] - apply tsum_congr; intro b - simp_rw [←mul_assoc,conn_probability_symm G p _ b] - rw [ENNReal.tsum_mul_left] - _ ≤ ∑' a, ∑' b, indexedEdgeKernel G a b * law p {ω | Conn G ω x a} * C := by - exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => mul_le_mul_right (hC b) _)) - _ = ∑' a, (degree G a:ℝ≥0∞) * law p {ω | Conn G ω x a} * C := by - apply tsum_congr; intro a - rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc a] - _ ≤ ∑' a, (d:ℝ≥0∞) * law p {ω | Conn G ω x a} * C := by - exact ENNReal.tsum_le_tsum (fun a => mul_le_mul_left (mul_le_mul_left (show (degree G a:ℝ≥0∞) ≤ (d:ℝ≥0∞) by exact_mod_cast hd a) _) _) - _ = (d:ℝ≥0∞)*(∑' a, law p {ω | Conn G ω x a})*C := by - rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_left] - _ ≤ (d:ℝ≥0∞)*C^2 := by - rw [pow_two,←mul_assoc] - exact mul_le_mul_left (mul_le_mul_right (hC x) _) _ - -end RussoDiagram -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section RussoMajorant -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def russoSlope (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := - realContactExpectation G x y t / (1-t) - -noncomputable def russoMajorant (G : BondGraph V E) (b : unitInterval) (x y : V) : ℝ := - (russoDiagram G b x y).toReal / (1-(b:ℝ)) - -theorem russoDiagram_row_ne_top [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) (x : V) : (∑' y, russoDiagram G b x y) ≠ ⊤ := by - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - obtain ⟨C,_,hC⟩ := subcritical_ennreal_row_bound G hloc hqt b hb - exact ne_top_of_le_ne_top (by finiteness) (russoDiagram_row_bound G hloc d hd b _ hC x) - -theorem russoDiagram_ne_top [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) (x y : V) : russoDiagram G b x y ≠ ⊤ := - ne_top_of_le_ne_top (russoDiagram_row_ne_top G hloc hqt b hb x) (ENNReal.le_tsum y) - -theorem summable_russoMajorant [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) (x : V) : Summable (russoMajorant G b x) := - (ENNReal.summable_toReal (russoDiagram_row_ne_top G hloc hqt b hb x)).div_const _ - -theorem russoSlope_nonneg (G : BondGraph V E) (x y : V) (t : ℝ) (ht : t ≤ 1) : - 0 ≤ russoSlope G x y t := by - exact div_nonneg (integral_nonneg (fullLargeContact_nonneg G x y 0)) (sub_nonneg.mpr ht) - -theorem russoMajorant_nonneg (G : BondGraph V E) (b : unitInterval) (x y : V) : - 0 ≤ russoMajorant G b x y := div_nonneg ENNReal.toReal_nonneg (sub_nonneg.mpr b.2.2) - -theorem russoSlope_le_majorant [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b p : unitInterval) (hb : b < pc G) (hp : p ≤ b) (x y : V) : - russoSlope G x y (p:ℝ) ≤ russoMajorant G b x y := by - have hp' := hp.trans_lt hb - have he := (fullContact_expectation_le_diagram G hloc hqt p hp' x y).trans (russoDiagram_mono G p b hp x y) - have hn : 0 ≤ ∫ ω, fullLargeContact G x y 0 ω ∂law p := integral_nonneg (fullLargeContact_nonneg G x y 0) - have hc : (∫ ω, fullLargeContact G x y 0 ω ∂law p) ≤ (russoDiagram G b x y).toReal := by - simpa only [ENNReal.toReal_ofReal hn] using ENNReal.toReal_mono (russoDiagram_ne_top G hloc hqt b hb x y) he - simp only [russoSlope,realContactExpectation_coe,russoMajorant] - exact div_le_div₀ ENNReal.toReal_nonneg hc (sub_pos.mpr ((show (b:ℝ) < (pc G:ℝ) from hb).trans_le (pc G).2.2)) (sub_le_sub_left (show (p:ℝ) ≤ (b:ℝ) from hp) 1) - -theorem hasDerivAt_realTwoPoint_slope [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (t : ℝ) (ht : t ∈ Set.Ioo 0 (pc G:ℝ)) (x y : V) : - HasDerivAt (realTwoPoint G x y) (russoSlope G x y t) t := by - let p : unitInterval := ⟨t, ht.1.le,ht.2.le.trans (pc G).2.2⟩ - change HasDerivAt (realTwoPoint G x y) (russoSlope G x y (p:ℝ)) (p:ℝ) - simpa only [russoSlope,realContactExpectation_coe] using hasDerivAt_realTwoPoint_subcritical G hloc hqt p ht.1 ht.2 x y - -end RussoMajorant -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section RussoRows -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem russoMajorant_symm (G : BondGraph V E) (b : unitInterval) (x y : V) : - russoMajorant G b x y = russoMajorant G b y x := by - rw [russoMajorant,russoDiagram_symm,russoMajorant] - -theorem russoMajorant_uniform_row_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) : - ∃ R : ℝ, 0 ≤ R ∧ ∀ x, ∑' y, russoMajorant G b x y ≤ R := by - obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt - obtain ⟨C,_,hC⟩ := subcritical_ennreal_row_bound G hloc hqt b hb - let R : ℝ≥0∞ := (d:ℝ≥0∞)*(ENNReal.ofReal C)^2 - have hR : R ≠ ⊤ := by dsimp [R]; finiteness - have hden : 0 < 1-(b:ℝ) := sub_pos.mpr ((show (b:ℝ) < (pc G:ℝ) from hb).trans_le (pc G).2.2) - refine ⟨R.toReal/(1-(b:ℝ)),div_nonneg ENNReal.toReal_nonneg hden.le,fun x => ?_⟩ - simp only [russoMajorant,tsum_div_const] - rw [←ENNReal.tsum_toReal_eq (russoDiagram_ne_top G hloc hqt b hb x)] - exact div_le_div_of_nonneg_right (ENNReal.toReal_mono hR (russoDiagram_row_bound G hloc d hd b _ hC x)) hden.le - - - -theorem summable_kernel_pair (A B : V → V → ℝ) - (hA : ∀ x y, 0 ≤ A x y) (hB : ∀ x y, 0 ≤ B x y) - (hsA : ∀ x, Summable (A x)) (hsB : ∀ x, Summable (B x)) - (C : ℝ) (hC : ∀ x, ∑' y, B x y ≤ C) (x : V) : - Summable (fun ab : V×V => A x ab.1 * B ab.1 ab.2) := by - apply (summable_prod_of_nonneg (f := fun ab : V×V => A x ab.1 * B ab.1 ab.2) - (fun ab => mul_nonneg (hA x ab.1) (hB ab.1 ab.2))).mpr - refine ⟨fun a => (hsB a).mul_left (A x a),?_⟩ - simp only [tsum_mul_left] - exact Summable.of_nonneg_of_le (fun a => mul_nonneg (hA x a) (tsum_nonneg (hB a))) - (fun a => mul_le_mul_of_nonneg_left (hC a) (hA x a)) ((hsA x).mul_right C) - -theorem summable_twoPoint_pair [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Summable (fun ab : V×V => twoPoint G p x ab.1 * twoPoint G p ab.1 ab.2) := by - obtain ⟨C,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp - have hs := summable_twoPoint_subcritical G hloc hqt p hp - exact summable_kernel_pair (twoPoint G p) (twoPoint G p) (twoPoint_nonneg G p) - (twoPoint_nonneg G p) hs hs C (fun x => (hs x).tsum_le_of_sum_le (hrow x)) x - -theorem summable_russoMajorant_pair [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Summable (fun ab : V×V => russoMajorant G p x ab.1 * twoPoint G p ab.1 ab.2) ∧ - Summable (fun ab : V×V => twoPoint G p x ab.1 * russoMajorant G p ab.1 ab.2) := by - obtain ⟨C,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp - have hs := summable_twoPoint_subcritical G hloc hqt p hp - have hr := summable_russoMajorant G hloc hqt p hp - obtain ⟨R,_,hR⟩ := russoMajorant_uniform_row_bound G hloc hqt p hp - exact ⟨summable_kernel_pair _ _ (russoMajorant_nonneg G p) (twoPoint_nonneg G p) hr hs C - (fun x => (hs x).tsum_le_of_sum_le (hrow x)) x, - summable_kernel_pair _ _ (twoPoint_nonneg G p) (russoMajorant_nonneg G p) hs hr R hR x⟩ - -end RussoRows -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section RealTriangle -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def realTriangleTerm (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) : ℝ := - realTwoPoint G x ab.1 t * realTwoPoint G ab.1 ab.2 t * realTwoPoint G ab.2 x t - -noncomputable def realTriangleSlope (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) : ℝ := - russoSlope G x ab.1 t * realTwoPoint G ab.1 ab.2 t * realTwoPoint G ab.2 x t + - realTwoPoint G x ab.1 t * russoSlope G ab.1 ab.2 t * realTwoPoint G ab.2 x t + - realTwoPoint G x ab.1 t * realTwoPoint G ab.1 ab.2 t * russoSlope G ab.2 x t - -noncomputable def triangleMajorant (G : BondGraph V E) (b : unitInterval) (x : V) (ab : V×V) : ℝ := - russoMajorant G b x ab.1 * twoPoint G b ab.1 ab.2 + - twoPoint G b x ab.1 * russoMajorant G b ab.1 ab.2 + - russoMajorant G b x ab.2 * twoPoint G b ab.2 ab.1 - -theorem summable_triangleMajorant [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b : unitInterval) (hb : b < pc G) (x : V) : Summable (triangleMajorant G b x) := by - obtain ⟨h₁,h₂⟩ := summable_russoMajorant_pair G hloc hqt b hb x - have h₃ : Summable (fun ab : V×V => russoMajorant G b x ab.2 * twoPoint G b ab.2 ab.1) := by - exact h₁.comp_injective (i := fun ab : V×V => (ab.2,ab.1)) (Equiv.prodComm V V).injective - exact (h₁.add h₂).add h₃ - -theorem hasDerivAt_realTriangleTerm [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (t : ℝ) (ht : t ∈ Set.Ioo 0 (pc G:ℝ)) (x : V) (ab : V×V) : - HasDerivAt (realTriangleTerm G x ab) (realTriangleSlope G x ab t) t := by - have hs := hasDerivAt_realTwoPoint_slope G hloc hqt t ht - convert! ((hs x ab.1).mul (hs ab.1 ab.2)).mul (hs ab.2 x) using 1 - simp only [realTriangleSlope,Pi.mul_apply] - ring - -theorem realTriangleSlope_nonneg (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) (ht : t ≤ 1) : - 0 ≤ realTriangleSlope G x ab t := by - have hT (a b : V) : 0 ≤ realTwoPoint G a b t := twoPoint_nonneg G _ a b - dsimp [realTriangleSlope] - exact add_nonneg (add_nonneg (mul_nonneg (mul_nonneg (russoSlope_nonneg G _ _ t ht) (hT _ _)) (hT _ _)) - (mul_nonneg (mul_nonneg (hT _ _) (russoSlope_nonneg G _ _ t ht)) (hT _ _))) - (mul_nonneg (mul_nonneg (hT _ _) (hT _ _)) (russoSlope_nonneg G _ _ t ht)) - -theorem realTriangleSlope_le_majorant [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (b p : unitInterval) (hb : b < pc G) (hp : p ≤ b) (x : V) (ab : V×V) : - realTriangleSlope G x ab (p:ℝ) ≤ triangleMajorant G b x ab := by - have hs := russoSlope_le_majorant G hloc hqt b p hb hp - have hn := russoSlope_nonneg (G := G) - have hm (a z : V) : twoPoint G p a z ≤ twoPoint G b a z := twoPoint_mono G a z hp - simp only [realTriangleSlope,realTwoPoint_coe,triangleMajorant] - apply add_le_add - · apply add_le_add - · calc - _ ≤ russoMajorant G b x ab.1 * twoPoint G b ab.1 ab.2 * 1 := - mul_le_mul (mul_le_mul (hs _ _) (hm _ _) (twoPoint_nonneg G p _ _) (russoMajorant_nonneg G b _ _)) - (twoPoint_le_one G p _ _) (twoPoint_nonneg G p _ _) (mul_nonneg (russoMajorant_nonneg G b _ _) (twoPoint_nonneg G b _ _)) - _ = _ := mul_one _ - · calc - _ ≤ twoPoint G b x ab.1 * russoMajorant G b ab.1 ab.2 * 1 := - mul_le_mul (mul_le_mul (hm _ _) (hs _ _) (hn _ _ _ p.2.2) (twoPoint_nonneg G b _ _)) - (twoPoint_le_one G p _ _) (twoPoint_nonneg G p _ _) (mul_nonneg (twoPoint_nonneg G b _ _) (russoMajorant_nonneg G b _ _)) - _ = _ := mul_one _ - · calc - _ ≤ 1 * twoPoint G b ab.1 ab.2 * russoMajorant G b ab.2 x := - mul_le_mul (mul_le_mul (twoPoint_le_one G p _ _) (hm _ _) (twoPoint_nonneg G p _ _) zero_le_one) - (hs _ _) (hn _ _ _ p.2.2) (mul_nonneg zero_le_one (twoPoint_nonneg G b _ _)) - _ = _ := by rw [one_mul,twoPoint_symm G b,russoMajorant_symm G b]; ring - -end RealTriangle -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section TriangleDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def realTriangle (G : BondGraph V E) (x : V) (t : ℝ) : ℝ := - ∑' ab, realTriangleTerm G x ab t - -noncomputable def rootTriangle (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := - ∑ i, weight i * realTriangle G (root i) t - -theorem summable_realTriangleTerm [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Summable (fun ab => realTriangleTerm G x ab (p:ℝ)) := by - simp only [realTriangleTerm,realTwoPoint_coe] - apply (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le - · intro ab - exact mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _) - · intro ab - exact mul_le_of_le_one_right (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_le_one G p _ _) - -theorem summable_realTriangleSlope [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - Summable (fun ab => realTriangleSlope G x ab (p:ℝ)) := by - exact (summable_triangleMajorant G hloc hqt p hp x).of_nonneg_of_le - (fun ab => realTriangleSlope_nonneg G x ab p p.2.2) - (fun ab => realTriangleSlope_le_majorant G hloc hqt p p hp le_rfl x ab) - - - -theorem hasDerivAt_realTriangle_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x : V) : - HasDerivAt (realTriangle G x) (∑' ab, realTriangleSlope G x ab (p:ℝ)) (p:ℝ) := by - obtain ⟨b,hpb,hb⟩ := exists_between hp - apply hasDerivAt_tsum_of_isPreconnected (summable_triangleMajorant G hloc hqt b hb x) - isOpen_Ioo isPreconnected_Ioo - (fun ab t ht => hasDerivAt_realTriangleTerm G hloc hqt t ⟨ht.1,lt_trans ht.2 hb⟩ x ab) - (fun ab t ht => ?_) (show (p:ℝ) ∈ Set.Ioo 0 (b:ℝ) from ⟨hp0,hpb⟩) - (summable_realTriangleTerm G hloc hqt p hp x) ⟨hp0,hpb⟩ - let q : unitInterval := ⟨t,ht.1.le,ht.2.le.trans b.2.2⟩ - have hq : q ≤ b := ht.2.le - rw [Real.norm_eq_abs,abs_of_nonneg (realTriangleSlope_nonneg G x ab t q.2.2)] - exact realTriangleSlope_le_majorant G hloc hqt b q hb hq x ab - -theorem hasDerivAt_rootTriangle_subcritical [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : - HasDerivAt (rootTriangle G root weight) - (∑ i, weight i * ∑' ab, realTriangleSlope G (root i) ab (p:ℝ)) (p:ℝ) := by - exact HasDerivAt.fun_sum (fun i _ => (hasDerivAt_realTriangle_subcritical G hloc hqt p hp0 hp (root i)).const_mul (weight i)) - -end TriangleDerivative -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.ContactTrace + +namespace OAI + +/-! Russo Rows for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section PairFunctionalAlgebra +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem clusterPairFunctional_mono_distinct (G : BondGraph V E) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (F H : Set E → V → V → ℝ≥0∞) + (h : ∀ ω x y, ¬Conn G ω x y → F ω x y ≤ H ω x y) : + clusterPairFunctional G p root weight F ≤ clusterPairFunctional G p root weight H := by + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_right + apply lintegral_mono + intro ω + unfold clusterPairDensity + apply mul_le_mul_right + apply ENNReal.tsum_le_tsum + intro y + apply mul_le_mul_right + by_cases hc : Conn G ω (root i) y + · simp only [hc,not_true_eq_false,ite_false,le_refl] + · simpa only [ite_eq_left hc] using h ω (root i) y hc + +theorem clusterPairFunctional_congr_ae (G : BondGraph V E) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (F H : Set E → V → V → ℝ≥0∞) + (h : ∀ᵐ ω ∂law p, ∀ x y, ¬Conn G ω x y → F ω x y = H ω x y) : + clusterPairFunctional G p root weight F = clusterPairFunctional G p root weight H := by + apply Finset.sum_congr rfl + intro i _ + congr 1 + apply lintegral_congr_ae + filter_upwards [h] with ω hω + unfold clusterPairDensity + congr 1 + apply tsum_congr + intro y + congr 1 + by_cases hc : Conn G ω (root i) y + · simp only [hc,not_true_eq_false,ite_false] + · rw [ite_eq_left hc,ite_eq_left hc,hω (root i) y hc] + +theorem clusterPairFunctional_add [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (F H : Set E → V → V → ℝ≥0∞) + (hF : ∀ x y, Measurable (fun ω => F ω x y)) + (hH : ∀ x y, Measurable (fun ω => H ω x y)) : + clusterPairFunctional G p root weight (fun ω x y => F ω x y+H ω x y) = + clusterPairFunctional G p root weight F + clusterPairFunctional G p root weight H := by + let : MeasurableSpace V := ⊤ + let : MeasurableSingletonClass V := ⟨fun _ => trivial⟩ + let : MeasurableSpace ι := ⊤ + let : MeasurableSingletonClass ι := ⟨fun _ => trivial⟩ + rw [clusterPairFunctional_eq_lintegral G hloc p root weight _ hF, + clusterPairFunctional_eq_lintegral G hloc p root weight _ hH, + clusterPairFunctional_eq_lintegral G hloc p root weight (fun ω x y => F ω x y+H ω x y) (fun x y => (hF x y).add (hH x y))] + exact lintegral_add_left (measurable_from_prod_countable_left (fun q => hF (root q.1) q.2)) _ + +theorem clusterPairKernel_symm (G : BondGraph V E) (ω : Set E) + (J : V → V → ℝ≥0∞) (hJ : ∀ x y, J x y = J y x) (x y : V) : + clusterPairKernel G ω J x y = clusterPairKernel G ω J y x := by + unfold clusterPairKernel + rw [ENNReal.tsum_comm] + apply tsum_congr + intro a + apply tsum_congr + intro b + simp only [and_comm,hJ b a] + +end PairFunctionalAlgebra +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section LargeContactCauchySchwarz +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def largeContactKernel (G : BondGraph V E) (L : ℝ) + (ω : Set E) (x y : V) : ℝ≥0∞ := + if L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) then + clusterPairKernel G ω (indexedEdgeKernel G) x y else 0 + +theorem measurable_largeContactKernel [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (L : ℝ) (x y : V) : + Measurable (fun ω => largeContactKernel G L ω x y) := by + have hm (z : V) : Measurable (fun ω : Set E => ((cluster G ω z).ncard:ℝ)) := + (measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc z) + exact (measurable_clusterPairKernel G (indexedEdgeKernel G) x y).ite + (measurableSet_le measurable_const ((hm x).min (hm y))) measurable_const + +theorem clusterPairFunctional_largeContact_sq [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (L : ℝ) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : + clusterPairFunctional G p root weight (fun ω x y => (largeContactKernel G L ω x y)^2) = + clusterPairFunctional G p root weight (contactSquareLargeReal G L) := by + apply clusterPairFunctional_congr_ae G p root weight + filter_upwards [ae_all_iff.mpr hfin] with ω hω + intro x y hxy + dsimp only [largeContactKernel,contactSquareLargeReal] + split_ifs + · rw [clusterPairKernel_edge G hloc ω x y hxy (hω x)] + · rw [zero_pow (by decide : 2 ≠ 0)] + +theorem clusterPairFunctional_largeContact_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (L : ℝ) (B : ℝ≥0∞) + (hB : clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ B) : + clusterPairFunctional G p root weight (fun ω x y => + largeContactKernel G L ω x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ + B^((1:ℝ)/2)* (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by + have hh := clusterPairFunctional_cauchy_schwarz G hloc p root weight + (largeContactKernel G L) (fun ω x y => clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) + (measurable_largeContactKernel G hloc L) (measurable_clusterPairKernel G _) + rw [clusterPairFunctional_largeContact_sq G hloc L p root weight hfin] at hh + exact hh.trans (mul_le_mul + (ENNReal.rpow_le_rpow hB (by positivity)) + (ENNReal.rpow_le_rpow (clusterPairFunctional_twoPoint_square_bound G hconn hloc root weight Γ hΓ htr hw p hfin T hT) (by positivity)) + bot_le bot_le) + +end LargeContactCauchySchwarz +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal ComplexOrder +section SmallTraceTerm +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem contact_smallTwoPoint_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (L α C : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hI : ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) + (hC : ∀ x, (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G (ennMatrixCoeff (T^2)) L x y ω) ≤ + ENNReal.ofReal ((d:ℝ)*c*C*L^(1-α)*(rootTrace root weight (T^3)).re) := by + have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + have hJ : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff (T^2) (a x) (a y) = ennMatrixCoeff (T^2) x y := by + intro a ha x y + unfold ennMatrixCoeff + rw [(hTI.pow 2) a ha] + have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) + have hMt : 0 ≤ c*(rootTrace root weight (T^3)).re := mul_nonneg hc + (Complex.nonneg_iff.mp (rootTrace_nonneg root weight hw _ (CStarAlgebra.pow_nonneg T 3 hpos))).1 + have hh := contact_smallPairKernel_bound G hconn hloc root weight Γ hΓ htr hw hw1 p hfin + (ennMatrixCoeff (T^2)) hJ L d hd (c*C*L^(1-α)*(rootTrace root weight (T^3)).re) (fun x y => by + refine (smallPairKernel_twoPoint_bound G hloc root weight Γ hΓ hcov hw c hc hmin x y p T hT L α hL hα0 hα1 (hfin x) (hfin y) (hI x)).trans ?_ + apply ENNReal.ofReal_le_ofReal + calc + _ ≤ (c*(rootTrace root weight (T^3)).re)*(L^(1-α)*C) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left (hC x) (Real.rpow_nonneg hL _)) hMt + _ = _ := by ring) + convert hh using 1; congr 1; ring + +end SmallTraceTerm +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal ComplexOrder +section MixedTraceTerm +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem contact_smallPairKernel_swap [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) (L : ℝ) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) y x * smallPairKernel G J L y x ω) = + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) := by + symm + apply clusterPairFunctional_swap G hconn hloc root weight Γ hΓ htr hw p + (fun ω x y => clusterPairKernel G ω (indexedEdgeKernel G) x y * smallPairKernel G J L x y ω) + · intro x y + exact (measurable_clusterPairKernel G _ x y).mul (measurable_smallPairKernel G hloc J L x y) + · intro a ha b hab ω x y + rw [clusterPairKernel_aut G hab _ (indexedEdgeKernel_aut G hab),smallPairKernel_aut G hab J (hJ a ha)] + + + +theorem clusterPairFunctional_twoPoint_mixed_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (p : unitInterval) (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (L α C : ℝ) (hL : 0 ≤ L) (hα0 : 0 ≤ α) (hα1 : α ≤ 1) + (hI : ∀ x, Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p)) + (hC : ∀ x, (∫ ω, ((cluster G ω x).ncard:ℝ)^α ∂law p) ≤ C) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (B : ℝ≥0∞) + (hB : clusterPairFunctional G p root weight (contactSquareLargeReal G L) ≤ B) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ + 2*ENNReal.ofReal ((d:ℝ)*c*C*L^(1-α)*(rootTrace root weight (T^3)).re) + + B^((1:ℝ)/2)* (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by + let J := ennMatrixCoeff (T^2) + let A := fun ω x y => clusterPairKernel G ω (indexedEdgeKernel G) x y*smallPairKernel G J L x y ω + let D := fun ω x y => largeContactKernel G L ω x y*clusterPairKernel G ω J x y + have heS (ω : Set E) (x y : V) : clusterPairKernel G ω (indexedEdgeKernel G) y x = + clusterPairKernel G ω (indexedEdgeKernel G) x y := clusterPairKernel_symm G ω _ (indexedEdgeKernel_symm G) y x + have hpos : 0 ≤ T := ContinuousLinearMap.nonneg_iff_isPositive.mpr (hT.isPositive G p T) + have hJS (ω : Set E) (x y : V) : clusterPairKernel G ω J y x = clusterPairKernel G ω J x y := + clusterPairKernel_symm G ω J (ennMatrixCoeff_symm ((IsSelfAdjoint.of_nonneg hpos).pow 2)) y x + have hTI : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + have hJI : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y := by + intro a ha x y + dsimp [J,ennMatrixCoeff] + rw [(hTI.pow 2) a ha] + have hA (x y : V) : Measurable (fun ω => A ω x y) := + (measurable_clusterPairKernel G _ x y).mul (measurable_smallPairKernel G hloc J L x y) + have hD (x y : V) : Measurable (fun ω => D ω x y) := + (measurable_largeContactKernel G hloc L x y).mul (measurable_clusterPairKernel G J x y) + have hpw (ω : Set E) (x y : V) (hxy : ¬Conn G ω x y) : + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y ≤ A ω x y + A ω y x + D ω x y := by + have hyx : ¬Conn G ω y x := fun h => hxy (conn_symm G ω h) + by_cases hx : ((cluster G ω x).ncard:ℝ) < L + · have ha : A ω x y = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by + dsimp [A,smallPairKernel]; rw [ite_eq_left ⟨hx,hxy⟩] + rw [←ha] + exact le_add_of_le_left (le_add_right le_rfl) + · by_cases hy : ((cluster G ω y).ncard:ℝ) < L + · have ha : A ω y x = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by + dsimp [A,smallPairKernel]; rw [ite_eq_left ⟨hy,hyx⟩,heS ω x y,hJS ω x y] + rw [←ha] + exact le_add_of_le_left (le_add_left le_rfl) + · have hg : L ≤ min ((cluster G ω x).ncard:ℝ) ((cluster G ω y).ncard:ℝ) := le_min (le_of_not_gt hx) (le_of_not_gt hy) + have hh : D ω x y = clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y := by + dsimp [D,largeContactKernel]; rw [ite_eq_left hg] + rw [←hh] + exact le_add_left le_rfl + have ha := contact_smallTwoPoint_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin p hfin T hT L α C hL hα0 hα1 hI hC d hd + have hb := clusterPairFunctional_largeContact_bound G hconn hloc root weight Γ hΓ htr hw p hfin T hT L B hB + calc + _ ≤ clusterPairFunctional G p root weight (fun ω x y => A ω x y+A ω y x+D ω x y) := + clusterPairFunctional_mono_distinct G p root weight _ _ hpw + _ = (clusterPairFunctional G p root weight A + clusterPairFunctional G p root weight A) + clusterPairFunctional G p root weight D := by + rw [clusterPairFunctional_add G hloc p root weight (fun ω x y => A ω x y+A ω y x) D (fun x y => (hA x y).add (hA y x)) hD, + clusterPairFunctional_add G hloc p root weight A (fun ω x y => A ω y x) hA (fun x y => hA y x)] + rw [contact_smallPairKernel_swap G hconn hloc root weight Γ hΓ htr hw p J hJI L] + _ ≤ _ := by simpa only [two_mul] using add_le_add (add_le_add ha ha) hb + +end MixedTraceTerm +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section UniformMixedTrace +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_mixed_trace_bound + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ A B : ℝ, 0 < A ∧ 0 < B ∧ ∀ (p : unitInterval), + (pc G:ℝ)/2 ≤ (p:ℝ) → p ≤ pc G → + ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → + ∀ L : ℝ, 1 ≤ L → + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * + clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y) ≤ + 2*ENNReal.ofReal (A*L^(1-α)*(rootTrace root weight (T^3)).re) + + (ENNReal.ofReal (B*L^((1:ℝ)/2+ε-2*α)))^((1:ℝ)/2) * + (ENNReal.ofReal (‖T‖^3*(rootTrace root weight (T^3)).re))^((1:ℝ)/2) := by + have hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i) := by + intro x + obtain ⟨i,a,ha,hax⟩ := hcov x + obtain ⟨b,hab⟩ := hΓ ha + exact ⟨i,a,b,hab,hax⟩ + have hfinite : ∀ x, ∀ᵐ ω ∂law (pc G), (cluster G ω x).Finite := by + intro x + obtain ⟨i,a,b,hab,rfl⟩ := hcover x + exact cluster_finite_ae_covariant G (pc G) hab (root i) (hfin i) + obtain ⟨C,hC,hCb⟩ := uniform_cluster_power_of_root G hloc (pc G) root hcover α + (critical_root_power_integrable G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α hα hα1) + obtain ⟨B,hB,hBb⟩ := critical_contact_square_bound G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + obtain ⟨d,hd,hdg⟩ := exists_degree_bound G hqt + let c : ℝ := ∑ i, 1/weight i + have hc : 0 < c := Finset.sum_pos (fun i _ => one_div_pos.mpr (hw i)) Finset.univ_nonempty + have hmin (i : ι) : 1 ≤ c*weight i := by + apply (div_le_iff₀ (hw i)).mp + exact Finset.single_le_sum (fun j _ => (one_div_pos.mpr (hw j)).le) (Finset.mem_univ i) + refine ⟨(d:ℝ)*c*C,B,mul_pos (mul_pos (by exact_mod_cast hd) hc) hC,hB,?_⟩ + intro p hp hpq T hT L hL + have hm (x : V) := cluster_power_mono_integral G hloc x p (pc G) hpq α hα.le (hfinite x) (hCb x).1 + exact clusterPairFunctional_twoPoint_mixed_bound G hconn hloc root weight Γ hΓ htr hcov + (fun i => (hw i).le) hw1 c hc.le hmin p + (fun x => cluster_finite_ae_mono G x p (pc G) hpq (hfinite x)) + T hT L α C (by linarith) hα.le (by linarith) + (fun x => (hm x).1) (fun x => (hm x).2.trans (hCb x).2) d hdg _ (hBb p hp hpq L hL) + +end UniformMixedTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ConnectionRussoContacts +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem closedPivotal_connection_iff (G : BondGraph V E) (ω : Set E) (x y : V) (e : E) : + ω ∈ closedPivotal {η | Conn G η x y} e ↔ + ¬Conn G ω x y ∧ e ∈ closedContactSet G (cluster G ω x) (cluster G ω y) := by + constructor + · rintro ⟨_,hxy,hins⟩ + refine ⟨hxy,?_⟩ + obtain ⟨⟨a,b⟩,hab⟩ := Quot.exists_rep (G e) + have he : G e = s(a,b) := hab.symm + rcases (conn_insert_iff G ω e a b x y he).mp hins with h | h | h + · exact (hxy h).elim + · exact ⟨a,h.1,b,conn_symm G ω h.2,he⟩ + · exact ⟨b,h.1,a,conn_symm G ω h.2,by rw [he,Sym2.eq_swap]⟩ + · rintro ⟨hxy,a,hxa,b,hyb,he⟩ + have hclosed : e ∉ ω := by + intro heω + exact hxy (hxa.trans ((Relation.ReflTransGen.single ⟨e,heω,he⟩).trans (conn_symm G ω hyb))) + refine ⟨hclosed,hxy,?_⟩ + exact (conn_insert_iff G ω e a b x y he).mpr (Or.inr (Or.inl ⟨hxa,conn_symm G ω hyb⟩)) + +noncomputable def finiteClosedContact (G : BondGraph V E) (Q : Finset E) (x y : V) + (ω : Finset E) : ℝ := + if ¬Conn G (ω:Set E) x y then + (contactBonds G Q (finiteRootComponent G ω x) (finiteRootComponent G ω y)).card else 0 + +theorem finiteClosedContact_eq_sum (G : BondGraph V E) (Q : Finset E) (x y : V) + (ω : Finset E) : + finiteClosedContact G Q x y ω = + ∑ e ∈ Q, if (ω:Set E) ∈ closedPivotal {η | Conn G η x y} e then (1:ℝ) else 0 := by + have hm (z a : V) : a ∈ finiteRootComponent G ω z ↔ Conn G (ω:Set E) z a := by + change a ∈ (finiteRootComponent G ω z:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + simp only [closedPivotal_connection_iff,closedContactSet,Set.mem_ofPred_eq,finiteClosedContact] + by_cases hxy : Conn G (ω:Set E) x y + · simp only [hxy,not_true_eq_false,false_and,ite_false,Finset.sum_const_zero] + · rw [ite_eq_left hxy] + simp only [hxy,not_false_eq_true,true_and,contactBonds,hm,cluster,Set.mem_ofPred_eq] + rw [Finset.sum_boole] + +theorem finite_connection_russo_contacts (G : BondGraph V E) (Q : Finset E) + (x y : V) (p : ℝ) : + (1-p)*deriv (finiteEventPolynomial Q {ω | Conn G ω x y}) p = + bernoulliPolynomial Q (finiteClosedContact G Q x y) p := by + change (1-p)*deriv (bernoulliPolynomial Q (fun ω => if Conn G (ω:Set E) x y then 1 else 0)) p = _ + rw [closed_difference_russo] + have he : finiteClosedContact G Q x y = fun (ω : Finset E) => + ∑ e ∈ Q, if (ω:Set E) ∈ closedPivotal {η | Conn G η x y} e then (1:ℝ) else 0 := + funext (finiteClosedContact_eq_sum G Q x y) + rw [he,bernoulliPolynomial_sum] + apply Finset.sum_congr rfl + intro e _ + apply bernoulliPolynomial_congr + intro ω _ + exact (closedPivotal_difference {η | Conn G η x y} + (fun _ _ h hc => conn_mono G h hc) e ω).symm + +end ConnectionRussoContacts +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section UniformContactApproximation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteClosedContact_eq_full (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) + (Q : Finset E) (hQx : incidentSupport G hloc hx.toFinset ⊆ Q) + (hQy : incidentSupport G hloc hy.toFinset ⊆ Q) : + finiteClosedContact G Q x y (domainBits Q ω) = fullLargeContact G x y 0 ω := by + have hcluster (z : V) (hz : (cluster G ω z).Finite) (hQ : incidentSupport G hloc hz.toFinset ⊆ Q) : + cluster G (domainBits Q ω:Set E) z = cluster G ω z := by + rw [coe_domainBits] + have hh := (cluster_restrict_incident_eq_iff G hloc hz.toFinset Q hQ ω z).mpr + (Set.Finite.coe_toFinset hz).symm + simpa only [Set.Finite.coe_toFinset] using hh + have hcx := hcluster x hx hQx + have hcy := hcluster y hy hQy + have hFx : finiteRootComponent G (domainBits Q ω) x = hx.toFinset := by + apply Finset.coe_injective + rw [coe_finiteRootComponent,hcx,Set.Finite.coe_toFinset] + have hFy : finiteRootComponent G (domainBits Q ω) y = hy.toFinset := by + apply Finset.coe_injective + rw [coe_finiteRootComponent,hcy,Set.Finite.coe_toFinset] + have hconn : Conn G (domainBits Q ω:Set E) x y ↔ Conn G ω x y := by + change y ∈ cluster G (domainBits Q ω:Set E) x ↔ y ∈ cluster G ω x + rw [hcx] + have hc : (contactBonds G Q hx.toFinset hy.toFinset).card = clusterContactCount G ω x y := by + rw [←Set.ncard_coe_finset,coe_contactBonds_eq G hloc Q _ _ hQx] + simp only [Set.Finite.coe_toFinset,clusterContactCount] + simp only [finiteClosedContact,fullLargeContact,hconn,hFx,hFy,hc,Nat.zero_le,and_true] + +theorem finiteClosedContact_nonneg (G : BondGraph V E) (Q : Finset E) (x y : V) (ω : Finset E) : + 0 ≤ finiteClosedContact G Q x y ω := by + unfold finiteClosedContact + split_ifs <;> positivity + +theorem finiteClosedContact_le_size (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q η : Finset E) (ω : Set E) + (hη : (η:Set E) ⊆ ω) (x y : V) (hfin : (cluster G ω x).Finite) : + finiteClosedContact G Q x y η ≤ (d:ℝ)*(cluster G ω x).ncard := by + have hdQ (z : V) : (Q.filter fun e => z ∈ G e).card ≤ d := + (incident_filter_card_le_degree G hloc Q z).trans (hd z) + have hs : (finiteRootComponent G η x).card ≤ (cluster G ω x).ncard := by + rw [←Set.ncard_coe_finset,coe_finiteRootComponent] + exact Set.ncard_le_ncard (fun z hz => conn_mono G hη hz) hfin + unfold finiteClosedContact + split_ifs + · positivity + · exact_mod_cast (contactBonds_card_le G Q d hdQ _ _).trans + (Nat.mul_le_mul_left d ((min_le_left _ _).trans hs)) + + + +theorem lower_cluster_restrict_eq (G : BondGraph V E) (hloc : LocallyFinite G) + (ω η : Set E) (hη : η ⊆ ω) (x : V) (hx : (cluster G ω x).Finite) + (Q : Finset E) (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : + cluster G (η ∩ (Q:Set E)) x = cluster G η x := by + have hfin : (cluster G η x).Finite := hx.subset (fun z hz => conn_mono G hη hz) + have hs : hfin.toFinset ⊆ hx.toFinset := by + intro z hz + exact hx.mem_toFinset.mpr (conn_mono G hη (hfin.mem_toFinset.mp hz)) + have hQ' := (incidentSupport_mono G hloc hs).trans hQ + have hh := (cluster_restrict_incident_eq_iff G hloc hfin.toFinset Q hQ' η x).mpr + (Set.Finite.coe_toFinset hfin).symm + simpa only [Set.Finite.coe_toFinset] using hh + +end UniformContactApproximation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section ContactRegularity +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem fullLargeContact_zero_le_size (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (ω : Set E) (x y : V) + (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) : + fullLargeContact G x y 0 ω ≤ (d:ℝ)*(cluster G ω x).ncard := by + let Q := incidentSupport G hloc hx.toFinset ∪ incidentSupport G hloc hy.toFinset + rw [←finiteClosedContact_eq_full G hloc ω x y hx hy Q Finset.subset_union_left Finset.subset_union_right] + exact finiteClosedContact_le_size G hloc d hd Q (domainBits Q ω) ω + (by rw [coe_domainBits]; exact Set.inter_subset_left) x y hx + +theorem integrable_fullContact_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + Integrable (fullLargeContact G x y 0) (law p) := by + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + apply ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)).mono' + (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable + filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy + rw [Real.norm_of_nonneg (fullLargeContact_nonneg G x y 0 ω)] + exact fullLargeContact_zero_le_size G hloc d hd ω x y hx hy + +theorem fullContact_label_integral [Countable E] [Countable V] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) : + (∫ labels, fullLargeContact G x y 0 (openEdges labels p) ∂labelLaw) = + ∫ ω, fullLargeContact G x y 0 ω ∂law p := by + rw [←map_openEdges p] + exact (integral_map (measurable_openEdges p).aemeasurable + (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable).symm + +theorem fullContact_label_integrable [Countable E] [Countable V] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) : + Integrable (fun labels => fullLargeContact G x y 0 (openEdges labels p)) labelLaw ↔ + Integrable (fullLargeContact G x y 0) (law p) := by + rw [←map_openEdges p] + exact (integrable_map_measure (measurable_fullLargeContact G hloc x y 0).aestronglyMeasurable + (measurable_openEdges p).aemeasurable).symm + +theorem fullContact_eq_of_clusters (G : BondGraph V E) (ω η : Set E) (x y : V) + (hx : cluster G ω x = cluster G η x) (hy : cluster G ω y = cluster G η y) : + fullLargeContact G x y 0 ω = fullLargeContact G x y 0 η := by + have hc : Conn G ω x y ↔ Conn G η x y := by + change y ∈ cluster G ω x ↔ y ∈ cluster G η x + rw [hx] + simp only [fullLargeContact,clusterContactCount,hx,hy,hc] + + + +theorem continuousAt_fullContact_expectation [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + ContinuousAt (fun q => ∫ ω, fullLargeContact G x y 0 ω ∂law q) p := by + obtain ⟨r,hpr,hr⟩ := exists_between hp + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + let F (q : unitInterval) (labels : E → unitInterval) := fullLargeContact G x y 0 (openEdges labels q) + let B (labels : E → unitInterval) : ℝ := (d:ℝ)*(cluster G (openEdges labels r) x).ncard + have hm (q : unitInterval) : Measurable (F q) := + (measurable_fullLargeContact G hloc x y 0).comp (measurable_openEdges q) + have hc : ContinuousAt (fun q => ∫ labels, F q labels ∂labelLaw) p := by + apply continuousAt_of_dominated (bound := B) + (Eventually.of_forall (fun q => (hm q).aestronglyMeasurable)) + · filter_upwards [eventually_lt_nhds hpr] with q hqr + filter_upwards [label_cluster_finite_ae_subcritical G r hr x,label_cluster_finite_ae_subcritical G r hr y] with labels hx hy + have hsub (z : V) : cluster G (openEdges labels q) z ⊆ cluster G (openEdges labels r) z := + fun w hw => conn_mono G (openEdges_mono labels hqr.le) hw + rw [Real.norm_of_nonneg (fullLargeContact_nonneg G x y 0 _)] + calc + _ ≤ (d:ℝ)*(cluster G (openEdges labels q) x).ncard := + fullLargeContact_zero_le_size G hloc d hd _ x y (hx.subset (hsub x)) (hy.subset (hsub y)) + _ ≤ B labels := mul_le_mul_of_nonneg_left (by exact_mod_cast Set.ncard_le_ncard (hsub x) hx) (Nat.cast_nonneg _) + · exact (susceptibility_eq_label_integral G hloc hqt r hr x).1.const_mul (d:ℝ) + · filter_upwards [ae_labels_ne (E := E) p,label_cluster_finite_ae_subcritical G p hp x, + label_cluster_finite_ae_subcritical G p hp y] with labels hneq hx hy + apply Filter.EventuallyEq.continuousAt + filter_upwards [eventually_cluster_eq_at_finite G hloc labels p x hneq hx, + eventually_cluster_eq_at_finite G hloc labels p y hneq hy] with q hqx hqy + exact fullContact_eq_of_clusters G _ _ x y hqx hqy + simpa only [F,fullContact_label_integral G hloc] using hc + +end ContactRegularity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section UniformContactError +attribute [local instance] Classical.propDecidable Classical.decEq + +def ClusterSupportIn (G : BondGraph V E) (Q : Finset E) (ω : Set E) (x : V) : Prop := + ∀ a, Conn G ω x a → ∀ e, a ∈ G e → e ∈ Q + +theorem measurableSet_clusterSupportIn [Countable V] [Countable E] + (G : BondGraph V E) (Q : Finset E) (x : V) : + MeasurableSet {ω : Set E | ClusterSupportIn G Q ω x} := by + simp only [ClusterSupportIn,Set.ofPred_forall] + apply MeasurableSet.iInter + intro a + have he : {ω : Set E | Conn G ω x a → ∀ e, a ∈ G e → e ∈ Q} = + {ω | ¬Conn G ω x a} ∪ {ω | ∀ e, a ∈ G e → e ∈ Q} := by ext ω; simp only [Set.mem_union,Set.mem_ofPred_eq]; tauto + rw [he] + apply (measurableSet_conn G x a).compl.union + by_cases h : ∀ e, a ∈ G e → e ∈ Q + · convert (MeasurableSet.univ : MeasurableSet (Set.univ : Set (Set E))) using 1 + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_univ,iff_true] + exact h + · convert (MeasurableSet.empty : MeasurableSet (∅ : Set (Set E))) using 1 + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + exact h + +theorem clusterSupportIn_of_incident (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (ω : Set E) (x : V) (hx : (cluster G ω x).Finite) + (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : ClusterSupportIn G Q ω x := by + intro a ha e he + exact hQ ((mem_incidentSupport G hloc hx.toFinset e).mpr ⟨a,hx.mem_toFinset.mpr ha,he⟩) + +theorem finiteClosedContact_eq_full_of_support (G : BondGraph V E) (hloc : LocallyFinite G) + (Q : Finset E) (ω η : Set E) (hη : η ⊆ ω) (x y : V) + (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) + (hQx : ClusterSupportIn G Q ω x) (hQy : ClusterSupportIn G Q ω y) : + finiteClosedContact G Q x y (domainBits Q η) = fullLargeContact G x y 0 η := by + have hsub (z : V) : cluster G η z ⊆ cluster G ω z := fun a ha => conn_mono G hη ha + have hfx := hx.subset (hsub x) + have hfy := hy.subset (hsub y) + apply finiteClosedContact_eq_full G hloc η x y hfx hfy + · intro e he + obtain ⟨a,ha,he⟩ := (mem_incidentSupport G hloc hfx.toFinset e).mp he + exact hQx a (hsub x (hfx.mem_toFinset.mp ha)) e he + · intro e he + obtain ⟨a,ha,he⟩ := (mem_incidentSupport G hloc hfy.toFinset e).mp he + exact hQy a (hsub y (hfy.mem_toFinset.mp ha)) e he + +noncomputable def contactApproxError (G : BondGraph V E) (Q : Finset E) (d : ℕ) + (x y : V) (ω : Set E) : ℝ := + if ClusterSupportIn G Q ω x ∧ ClusterSupportIn G Q ω y then 0 + else (d:ℝ)*(cluster G ω x).ncard + +theorem measurable_contactApproxError [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (Q : Finset E) (d : ℕ) (x y : V) : + Measurable (contactApproxError G Q d x y) := by + exact measurable_const.ite ((measurableSet_clusterSupportIn G Q x).inter + (measurableSet_clusterSupportIn G Q y)) + (measurable_const.mul ((measurable_of_countable (fun n : ℕ => (n:ℝ))).comp (measurable_cluster_ncard G hloc x))) + +theorem contactApproxError_nonneg (G : BondGraph V E) (Q : Finset E) (d : ℕ) (x y : V) (ω : Set E) : + 0 ≤ contactApproxError G Q d x y ω := by unfold contactApproxError; split_ifs <;> positivity + +theorem contactApproxError_le (G : BondGraph V E) (Q : Finset E) (d : ℕ) (x y : V) (ω : Set E) : + contactApproxError G Q d x y ω ≤ (d:ℝ)*(cluster G ω x).ncard := by + unfold contactApproxError; split_ifs <;> first | positivity | exact le_rfl + +theorem contact_uniform_error_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q : Finset E) (ω η : Set E) + (hη : η ⊆ ω) (x y : V) (hx : (cluster G ω x).Finite) (hy : (cluster G ω y).Finite) : + ‖finiteClosedContact G Q x y (domainBits Q η) - fullLargeContact G x y 0 η‖ ≤ + contactApproxError G Q d x y ω := by + unfold contactApproxError + split_ifs with h + · rw [finiteClosedContact_eq_full_of_support G hloc Q ω η hη x y hx hy h.1 h.2,sub_self,norm_zero] + · have hsub (z : V) : cluster G η z ⊆ cluster G ω z := fun a ha => conn_mono G hη ha + have hf := finiteClosedContact_le_size G hloc d hd Q (domainBits Q η) ω + (by rw [coe_domainBits]; exact Set.inter_subset_left.trans hη) x y hx + have hg : fullLargeContact G x y 0 η ≤ (d:ℝ)*(cluster G ω x).ncard := by + exact (fullLargeContact_zero_le_size G hloc d hd η x y (hx.subset (hsub x)) (hy.subset (hsub y))).trans + (mul_le_mul_of_nonneg_left (by exact_mod_cast Set.ncard_le_ncard (hsub x) hx) (Nat.cast_nonneg _)) + rw [Real.norm_eq_abs,abs_sub_le_iff] + have hfn := finiteClosedContact_nonneg G Q x y (domainBits Q η) + have hgn := fullLargeContact_nonneg G x y 0 η + constructor <;> linarith + +end UniformContactError +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section UniformContactExpectation +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integrable_contactApproxError [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (Q : Finset E) (d : ℕ) (x y : V) : + Integrable (contactApproxError G Q d x y) (law p) := by + apply ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)).mono' + (measurable_contactApproxError G hloc Q d x y).aestronglyMeasurable + exact Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (contactApproxError_nonneg G Q d x y ω)]; exact contactApproxError_le G Q d x y ω) + +theorem contactApproxError_integral_tendsto_zero [Countable V] [Encodable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (d : ℕ) (x y : V) : + Tendsto (fun n => ∫ ω, contactApproxError G (vertexExhaustion n) d x y ω ∂law p) atTop (nhds 0) := by + have ht : ∀ᵐ ω ∂law p, Tendsto (fun n => contactApproxError G (vertexExhaustion n) d x y ω) atTop (nhds 0) := by + filter_upwards [subcritical_cluster_finite_ae G p hp x,subcritical_cluster_finite_ae G p hp y] with ω hx hy + obtain ⟨nx,hnx⟩ := subset_vertexExhaustion (incidentSupport G hloc hx.toFinset) + obtain ⟨ny,hny⟩ := subset_vertexExhaustion (incidentSupport G hloc hy.toFinset) + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (max nx ny)] with n hn + exact (ite_eq_left ⟨clusterSupportIn_of_incident G hloc _ ω x hx + (hnx.trans (vertexExhaustion_mono ((le_max_left nx ny).trans hn))), + clusterSupportIn_of_incident G hloc _ ω y hy + (hny.trans (vertexExhaustion_mono ((le_max_right nx ny).trans hn)))⟩).symm + have hh := tendsto_integral_of_dominated_convergence (fun ω : Set E => (d:ℝ)*(cluster G ω x).ncard) + (fun n => (measurable_contactApproxError G hloc (vertexExhaustion n) d x y).aestronglyMeasurable) + ((susceptibility_eq_integral G hloc hqt p hp x).1.const_mul (d:ℝ)) + (fun n => Eventually.of_forall (fun ω => by rw [Real.norm_of_nonneg (contactApproxError_nonneg G _ d x y ω)]; exact contactApproxError_le G _ d x y ω)) ht + simpa only [integral_zero] using hh + +theorem finiteClosedContact_label_integral [Countable E] (G : BondGraph V E) + (Q : Finset E) (p : unitInterval) (x y : V) : + (∫ labels, finiteClosedContact G Q x y (domainBits Q (openEdges labels p)) ∂labelLaw) = + bernoulliPolynomial Q (finiteClosedContact G Q x y) p := by + rw [←integral_domainBits Q p (finiteClosedContact G Q x y),←map_openEdges p] + exact (integral_map (measurable_openEdges p).aemeasurable + (measurable_finite_local Q (fun ω => finiteClosedContact G Q x y (domainBits Q ω)) (fun ω => by rw [domainBits_local])).aestronglyMeasurable).symm + +theorem contactApproxError_label_integral [Countable V] [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (Q : Finset E) (p : unitInterval) (d : ℕ) (x y : V) : + (∫ labels, contactApproxError G Q d x y (openEdges labels p) ∂labelLaw) = + ∫ ω, contactApproxError G Q d x y ω ∂law p := by + rw [←map_openEdges p] + exact (integral_map (measurable_openEdges p).aemeasurable + (measurable_contactApproxError G hloc Q d x y).aestronglyMeasurable).symm + +theorem contact_expectation_uniform_error [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (Q : Finset E) (b q : unitInterval) + (hb : b < pc G) (hq : q ≤ b) (x y : V) : + ‖bernoulliPolynomial Q (finiteClosedContact G Q x y) q - + ∫ ω, fullLargeContact G x y 0 ω ∂law q‖ ≤ + ∫ ω, contactApproxError G Q d x y ω ∂law b := by + have hf : Integrable (fun labels => finiteClosedContact G Q x y (domainBits Q (openEdges labels q))) labelLaw := by + have hi := integrable_finite_local Q q (fun ω => finiteClosedContact G Q x y (domainBits Q ω)) + (fun ω => by rw [domainBits_local]) + rw [←map_openEdges q] at hi + exact hi.comp_measurable (measurable_openEdges q) + have hg := (fullContact_label_integrable G hloc q x y).mpr + (integrable_fullContact_subcritical G hloc hqt q (hq.trans_lt hb) x y) + have hi : Integrable (fun labels => contactApproxError G Q d x y (openEdges labels b)) labelLaw := by + have hh := integrable_contactApproxError G hloc hqt b hb Q d x y + rw [←map_openEdges b] at hh + exact hh.comp_measurable (measurable_openEdges b) + rw [←finiteClosedContact_label_integral G Q q x y,←fullContact_label_integral G hloc q x y, + ←integral_sub hf hg,←contactApproxError_label_integral G hloc Q b d x y] + apply (norm_integral_le_integral_norm _).trans + apply integral_mono_ae (hf.sub hg).norm hi + filter_upwards [label_cluster_finite_ae_subcritical G b hb x,label_cluster_finite_ae_subcritical G b hb y] with labels hx hy + exact contact_uniform_error_bound G hloc d hd Q _ _ (openEdges_mono labels hq) x y hx hy + +end UniformContactExpectation +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section PointwiseRussoLimit +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def realContactExpectation (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := + ∫ ω, fullLargeContact G x y 0 ω ∂law (Set.projIcc 0 1 zero_le_one t) + +@[simp] theorem realContactExpectation_coe (G : BondGraph V E) (x y : V) (p : unitInterval) : + realContactExpectation G x y (p:ℝ) = ∫ ω, fullLargeContact G x y 0 ω ∂law p := by + simp only [realContactExpectation,Set.projIcc_val] + +noncomputable def realTwoPoint (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := + twoPoint G (Set.projIcc 0 1 zero_le_one t) x y + +@[simp] theorem realTwoPoint_coe (G : BondGraph V E) (x y : V) (p : unitInterval) : + realTwoPoint G x y (p:ℝ) = twoPoint G p x y := by + simp only [realTwoPoint,Set.projIcc_val] + +theorem finite_connection_deriv_eq (G : BondGraph V E) (Q : Finset E) + (x y : V) (t : ℝ) (ht : t ≠ 1) : + deriv (finiteEventPolynomial Q {ω | Conn G ω x y}) t = + bernoulliPolynomial Q (finiteClosedContact G Q x y) t / (1-t) := by + apply (eq_div_iff (sub_ne_zero.mpr (Ne.symm ht))).mpr + rw [mul_comm] + exact finite_connection_russo_contacts G Q x y t + +theorem finite_connection_deriv_tendstoUniformlyOn [Countable V] [Encodable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) (x y : V) : + TendstoUniformlyOn (fun n => deriv (finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y})) + (fun t => realContactExpectation G x y t / (1-t)) atTop (Set.Icc 0 (b:ℝ)) := by + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + have hb1 : (b:ℝ) < 1 := lt_of_lt_of_le hb (pc G).2.2 + have hden : 0 < 1-(b:ℝ) := sub_pos.mpr hb1 + have ht := (contactApproxError_integral_tendsto_zero G hloc hqt b hb d x y).div_const (1-(b:ℝ)) + rw [zero_div] at ht + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + filter_upwards [ht.eventually (eventually_lt_nhds hε)] with n hn t ht + let q : unitInterval := ⟨t,ht.1,ht.2.trans b.2.2⟩ + have hqb : q ≤ b := ht.2 + have hqt1 : t < 1 := ht.2.trans_lt hb1 + have he := contact_expectation_uniform_error G hloc hqt d hd (vertexExhaustion n) b q hb hqb x y + have hn0 : 0 ≤ ∫ ω, contactApproxError G (vertexExhaustion n) d x y ω ∂law b := + integral_nonneg (contactApproxError_nonneg G _ d x y) + rw [dist_comm,Real.dist_eq,finite_connection_deriv_eq G _ x y t (ne_of_lt hqt1),←sub_div,abs_div, + abs_of_pos (sub_pos.mpr hqt1)] + change |bernoulliPolynomial _ _ (q:ℝ) - realContactExpectation G x y (q:ℝ)| / (1-t) < ε + rw [realContactExpectation_coe] + apply lt_of_le_of_lt _ hn + exact div_le_div₀ hn0 (by simpa only [Real.norm_eq_abs] using he) hden (sub_le_sub_left ht.2 1) + +theorem finite_connection_polynomial_tendsto_twoPoint [Encodable E] + (G : BondGraph V E) (p : unitInterval) (x y : V) : + Tendsto (fun n => finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y} p) + atTop (nhds (twoPoint G p x y)) := by + have ht := finite_connection_polynomial_tendsto G Set.univ (vertexExhaustion (V := E)) + vertexExhaustion_mono (fun _ => Set.subset_univ _) (fun e _ => by + obtain ⟨n,hn⟩ := subset_vertexExhaustion ({e}:Finset E) + exact ⟨n,hn (by simp)⟩) p x y + simpa only [Set.inter_univ,finiteEventPolynomial,Set.mem_ofPred_eq,twoPoint,Measure.real] using ht + + + +theorem hasDerivAt_realTwoPoint_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x y : V) : + HasDerivAt (realTwoPoint G x y) + ((∫ ω, fullLargeContact G x y 0 ω ∂law p)/(1-(p:ℝ))) (p:ℝ) := by + let : Encodable E := Encodable.ofCountable E + obtain ⟨b,hpb,hb⟩ := exists_between hp + have hu := (finite_connection_deriv_tendstoUniformlyOn G hloc hqt b hb x y).mono + (show Set.Ioo 0 (b:ℝ) ⊆ Set.Icc 0 (b:ℝ) from Set.Ioo_subset_Icc_self) + have hh := hasDerivAt_of_tendstoUniformlyOn (f := fun n => finiteEventPolynomial (vertexExhaustion n) {ω | Conn G ω x y}) + (g := realTwoPoint G x y) (g' := fun t => realContactExpectation G x y t/(1-t)) isOpen_Ioo hu + (Eventually.of_forall (fun n t _ => by + change HasDerivAt (bernoulliPolynomial (vertexExhaustion n) (fun (ω : Finset E) => if Conn G (ω:Set E) x y then (1:ℝ) else 0)) _ t + exact (hasDerivAt_bernoulliPolynomial (vertexExhaustion n) + (fun (ω : Finset E) => if Conn G (ω:Set E) x y then (1:ℝ) else 0) t).differentiableAt.hasDerivAt)) + (fun t ht => by + let q : unitInterval := ⟨t,ht.1.le,ht.2.le.trans b.2.2⟩ + simpa only [←realTwoPoint_coe G x y q] using finite_connection_polynomial_tendsto_twoPoint G q x y) + (show (p:ℝ) ∈ Set.Ioo 0 (b:ℝ) from ⟨hp0,hpb⟩) + simpa only [realContactExpectation_coe] using hh + +end PointwiseRussoLimit +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section RussoDiagram +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def russoDiagram (G : BondGraph V E) (p : unitInterval) (x y : V) : ℝ≥0∞ := + ∑' a, ∑' b, indexedEdgeKernel G a b * + (law p {ω | Conn G ω x a} * law p {ω | Conn G ω y b}) + +theorem conn_probability_symm (G : BondGraph V E) (p : unitInterval) (x y : V) : + law p {ω | Conn G ω x y} = law p {ω | Conn G ω y x} := by + congr 1 + ext ω + exact ⟨conn_symm G ω,conn_symm G ω⟩ + +theorem conn_probability_mono [Countable V] [Countable E] (G : BondGraph V E) + (p q : unitInterval) (hpq : p ≤ q) (x y : V) : + law p {ω | Conn G ω x y} ≤ law q {ω | Conn G ω x y} := by + rw [←ENNReal.ofReal_toReal (measure_ne_top (law p) _),←ENNReal.ofReal_toReal (measure_ne_top (law q) _)] + exact ENNReal.ofReal_le_ofReal (twoPoint_mono G x y hpq) + +theorem fullContact_lintegral_eq_kernel [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (x y : V) + (hx : ∀ᵐ ω ∂law p, (cluster G ω x).Finite) : + (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = + ∫⁻ ω, if ¬Conn G ω x y then clusterPairKernel G ω (indexedEdgeKernel G) x y else 0 ∂law p := by + apply lintegral_congr_ae + filter_upwards [hx] with ω hω + by_cases hxy : Conn G ω x y + · simp only [fullLargeContact,hxy,not_true_eq_false,false_and,ite_false,ENNReal.ofReal_zero] + · rw [ite_eq_left hxy,clusterPairKernel_edge G hloc ω x y hxy hω] + simp only [fullLargeContact,hxy,Nat.zero_le,not_false_eq_true,and_self,ite_true,ENNReal.ofReal_natCast] + +theorem fullContact_expectation_le_diagram [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x y : V) : + ENNReal.ofReal (∫ ω, fullLargeContact G x y 0 ω ∂law p) ≤ russoDiagram G p x y := by + rw [ofReal_integral_eq_lintegral_ofReal (integrable_fullContact_subcritical G hloc hqt p hp x y) + (Eventually.of_forall (fullLargeContact_nonneg G x y 0))] + rw [fullContact_lintegral_eq_kernel G hloc p x y (subcritical_cluster_finite_ae G p hp x)] + exact clusterPairKernel_distinct_bound G p (indexedEdgeKernel G) x y + +theorem russoDiagram_mono [Countable V] [Countable E] (G : BondGraph V E) + (p q : unitInterval) (hpq : p ≤ q) (x y : V) : russoDiagram G p x y ≤ russoDiagram G q x y := by + exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => + mul_le_mul_right (mul_le_mul' (conn_probability_mono G p q hpq x a) + (conn_probability_mono G p q hpq y b)) _)) + +theorem russoDiagram_symm (G : BondGraph V E) (p : unitInterval) (x y : V) : + russoDiagram G p x y = russoDiagram G p y x := by + unfold russoDiagram + rw [ENNReal.tsum_comm] + apply tsum_congr; intro b + apply tsum_congr; intro a + rw [indexedEdgeKernel_symm G a b,mul_comm (law p {ω | Conn G ω x a})] + +theorem russoDiagram_row_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ z, degree G z ≤ d) (p : unitInterval) (C : ℝ≥0∞) + (hC : ∀ x, ∑' y, law p {ω | Conn G ω x y} ≤ C) (x : V) : + (∑' y, russoDiagram G p x y) ≤ (d:ℝ≥0∞)*C^2 := by + unfold russoDiagram + rw [ENNReal.tsum_comm] + calc + _ = ∑' a, ∑' b, indexedEdgeKernel G a b * law p {ω | Conn G ω x a} * + ∑' y, law p {ω | Conn G ω b y} := by + apply tsum_congr; intro a + rw [ENNReal.tsum_comm] + apply tsum_congr; intro b + simp_rw [←mul_assoc,conn_probability_symm G p _ b] + rw [ENNReal.tsum_mul_left] + _ ≤ ∑' a, ∑' b, indexedEdgeKernel G a b * law p {ω | Conn G ω x a} * C := by + exact ENNReal.tsum_le_tsum (fun a => ENNReal.tsum_le_tsum (fun b => mul_le_mul_right (hC b) _)) + _ = ∑' a, (degree G a:ℝ≥0∞) * law p {ω | Conn G ω x a} * C := by + apply tsum_congr; intro a + rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_right,indexedEdgeKernel_row G hloc a] + _ ≤ ∑' a, (d:ℝ≥0∞) * law p {ω | Conn G ω x a} * C := by + exact ENNReal.tsum_le_tsum (fun a => mul_le_mul_left (mul_le_mul_left (show (degree G a:ℝ≥0∞) ≤ (d:ℝ≥0∞) by exact_mod_cast hd a) _) _) + _ = (d:ℝ≥0∞)*(∑' a, law p {ω | Conn G ω x a})*C := by + rw [ENNReal.tsum_mul_right,ENNReal.tsum_mul_left] + _ ≤ (d:ℝ≥0∞)*C^2 := by + rw [pow_two,←mul_assoc] + exact mul_le_mul_left (mul_le_mul_right (hC x) _) _ + +end RussoDiagram +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section RussoMajorant +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def russoSlope (G : BondGraph V E) (x y : V) (t : ℝ) : ℝ := + realContactExpectation G x y t / (1-t) + +noncomputable def russoMajorant (G : BondGraph V E) (b : unitInterval) (x y : V) : ℝ := + (russoDiagram G b x y).toReal / (1-(b:ℝ)) + +theorem russoDiagram_row_ne_top [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) (x : V) : (∑' y, russoDiagram G b x y) ≠ ⊤ := by + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + obtain ⟨C,_,hC⟩ := subcritical_ennreal_row_bound G hloc hqt b hb + exact ne_top_of_le_ne_top (by finiteness) (russoDiagram_row_bound G hloc d hd b _ hC x) + +theorem russoDiagram_ne_top [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) (x y : V) : russoDiagram G b x y ≠ ⊤ := + ne_top_of_le_ne_top (russoDiagram_row_ne_top G hloc hqt b hb x) (ENNReal.le_tsum y) + +theorem summable_russoMajorant [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) (x : V) : Summable (russoMajorant G b x) := + (ENNReal.summable_toReal (russoDiagram_row_ne_top G hloc hqt b hb x)).div_const _ + +theorem russoSlope_nonneg (G : BondGraph V E) (x y : V) (t : ℝ) (ht : t ≤ 1) : + 0 ≤ russoSlope G x y t := by + exact div_nonneg (integral_nonneg (fullLargeContact_nonneg G x y 0)) (sub_nonneg.mpr ht) + +theorem russoMajorant_nonneg (G : BondGraph V E) (b : unitInterval) (x y : V) : + 0 ≤ russoMajorant G b x y := div_nonneg ENNReal.toReal_nonneg (sub_nonneg.mpr b.2.2) + +theorem russoSlope_le_majorant [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b p : unitInterval) (hb : b < pc G) (hp : p ≤ b) (x y : V) : + russoSlope G x y (p:ℝ) ≤ russoMajorant G b x y := by + have hp' := hp.trans_lt hb + have he := (fullContact_expectation_le_diagram G hloc hqt p hp' x y).trans (russoDiagram_mono G p b hp x y) + have hn : 0 ≤ ∫ ω, fullLargeContact G x y 0 ω ∂law p := integral_nonneg (fullLargeContact_nonneg G x y 0) + have hc : (∫ ω, fullLargeContact G x y 0 ω ∂law p) ≤ (russoDiagram G b x y).toReal := by + simpa only [ENNReal.toReal_ofReal hn] using ENNReal.toReal_mono (russoDiagram_ne_top G hloc hqt b hb x y) he + simp only [russoSlope,realContactExpectation_coe,russoMajorant] + exact div_le_div₀ ENNReal.toReal_nonneg hc (sub_pos.mpr ((show (b:ℝ) < (pc G:ℝ) from hb).trans_le (pc G).2.2)) (sub_le_sub_left (show (p:ℝ) ≤ (b:ℝ) from hp) 1) + +theorem hasDerivAt_realTwoPoint_slope [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (t : ℝ) (ht : t ∈ Set.Ioo 0 (pc G:ℝ)) (x y : V) : + HasDerivAt (realTwoPoint G x y) (russoSlope G x y t) t := by + let p : unitInterval := ⟨t, ht.1.le,ht.2.le.trans (pc G).2.2⟩ + change HasDerivAt (realTwoPoint G x y) (russoSlope G x y (p:ℝ)) (p:ℝ) + simpa only [russoSlope,realContactExpectation_coe] using hasDerivAt_realTwoPoint_subcritical G hloc hqt p ht.1 ht.2 x y + +end RussoMajorant +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section RussoRows +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem russoMajorant_symm (G : BondGraph V E) (b : unitInterval) (x y : V) : + russoMajorant G b x y = russoMajorant G b y x := by + rw [russoMajorant,russoDiagram_symm,russoMajorant] + +theorem russoMajorant_uniform_row_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) : + ∃ R : ℝ, 0 ≤ R ∧ ∀ x, ∑' y, russoMajorant G b x y ≤ R := by + obtain ⟨d,_,hd⟩ := exists_degree_bound G hqt + obtain ⟨C,_,hC⟩ := subcritical_ennreal_row_bound G hloc hqt b hb + let R : ℝ≥0∞ := (d:ℝ≥0∞)*(ENNReal.ofReal C)^2 + have hR : R ≠ ⊤ := by dsimp [R]; finiteness + have hden : 0 < 1-(b:ℝ) := sub_pos.mpr ((show (b:ℝ) < (pc G:ℝ) from hb).trans_le (pc G).2.2) + refine ⟨R.toReal/(1-(b:ℝ)),div_nonneg ENNReal.toReal_nonneg hden.le,fun x => ?_⟩ + simp only [russoMajorant,tsum_div_const] + rw [←ENNReal.tsum_toReal_eq (russoDiagram_ne_top G hloc hqt b hb x)] + exact div_le_div_of_nonneg_right (ENNReal.toReal_mono hR (russoDiagram_row_bound G hloc d hd b _ hC x)) hden.le + + + +theorem summable_kernel_pair (A B : V → V → ℝ) + (hA : ∀ x y, 0 ≤ A x y) (hB : ∀ x y, 0 ≤ B x y) + (hsA : ∀ x, Summable (A x)) (hsB : ∀ x, Summable (B x)) + (C : ℝ) (hC : ∀ x, ∑' y, B x y ≤ C) (x : V) : + Summable (fun ab : V×V => A x ab.1 * B ab.1 ab.2) := by + apply (summable_prod_of_nonneg (f := fun ab : V×V => A x ab.1 * B ab.1 ab.2) + (fun ab => mul_nonneg (hA x ab.1) (hB ab.1 ab.2))).mpr + refine ⟨fun a => (hsB a).mul_left (A x a),?_⟩ + simp only [tsum_mul_left] + exact Summable.of_nonneg_of_le (fun a => mul_nonneg (hA x a) (tsum_nonneg (hB a))) + (fun a => mul_le_mul_of_nonneg_left (hC a) (hA x a)) ((hsA x).mul_right C) + +theorem summable_twoPoint_pair [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Summable (fun ab : V×V => twoPoint G p x ab.1 * twoPoint G p ab.1 ab.2) := by + obtain ⟨C,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp + have hs := summable_twoPoint_subcritical G hloc hqt p hp + exact summable_kernel_pair (twoPoint G p) (twoPoint G p) (twoPoint_nonneg G p) + (twoPoint_nonneg G p) hs hs C (fun x => (hs x).tsum_le_of_sum_le (hrow x)) x + +theorem summable_russoMajorant_pair [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Summable (fun ab : V×V => russoMajorant G p x ab.1 * twoPoint G p ab.1 ab.2) ∧ + Summable (fun ab : V×V => twoPoint G p x ab.1 * russoMajorant G p ab.1 ab.2) := by + obtain ⟨C,_,hrow⟩ := subcritical_row_bound G hloc hqt p hp + have hs := summable_twoPoint_subcritical G hloc hqt p hp + have hr := summable_russoMajorant G hloc hqt p hp + obtain ⟨R,_,hR⟩ := russoMajorant_uniform_row_bound G hloc hqt p hp + exact ⟨summable_kernel_pair _ _ (russoMajorant_nonneg G p) (twoPoint_nonneg G p) hr hs C + (fun x => (hs x).tsum_le_of_sum_le (hrow x)) x, + summable_kernel_pair _ _ (twoPoint_nonneg G p) (russoMajorant_nonneg G p) hs hr R hR x⟩ + +end RussoRows +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section RealTriangle +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def realTriangleTerm (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) : ℝ := + realTwoPoint G x ab.1 t * realTwoPoint G ab.1 ab.2 t * realTwoPoint G ab.2 x t + +noncomputable def realTriangleSlope (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) : ℝ := + russoSlope G x ab.1 t * realTwoPoint G ab.1 ab.2 t * realTwoPoint G ab.2 x t + + realTwoPoint G x ab.1 t * russoSlope G ab.1 ab.2 t * realTwoPoint G ab.2 x t + + realTwoPoint G x ab.1 t * realTwoPoint G ab.1 ab.2 t * russoSlope G ab.2 x t + +noncomputable def triangleMajorant (G : BondGraph V E) (b : unitInterval) (x : V) (ab : V×V) : ℝ := + russoMajorant G b x ab.1 * twoPoint G b ab.1 ab.2 + + twoPoint G b x ab.1 * russoMajorant G b ab.1 ab.2 + + russoMajorant G b x ab.2 * twoPoint G b ab.2 ab.1 + +theorem summable_triangleMajorant [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b : unitInterval) (hb : b < pc G) (x : V) : Summable (triangleMajorant G b x) := by + obtain ⟨h₁,h₂⟩ := summable_russoMajorant_pair G hloc hqt b hb x + have h₃ : Summable (fun ab : V×V => russoMajorant G b x ab.2 * twoPoint G b ab.2 ab.1) := by + exact h₁.comp_injective (i := fun ab : V×V => (ab.2,ab.1)) (Equiv.prodComm V V).injective + exact (h₁.add h₂).add h₃ + +theorem hasDerivAt_realTriangleTerm [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (t : ℝ) (ht : t ∈ Set.Ioo 0 (pc G:ℝ)) (x : V) (ab : V×V) : + HasDerivAt (realTriangleTerm G x ab) (realTriangleSlope G x ab t) t := by + have hs := hasDerivAt_realTwoPoint_slope G hloc hqt t ht + convert! ((hs x ab.1).mul (hs ab.1 ab.2)).mul (hs ab.2 x) using 1 + simp only [realTriangleSlope,Pi.mul_apply] + ring + +theorem realTriangleSlope_nonneg (G : BondGraph V E) (x : V) (ab : V×V) (t : ℝ) (ht : t ≤ 1) : + 0 ≤ realTriangleSlope G x ab t := by + have hT (a b : V) : 0 ≤ realTwoPoint G a b t := twoPoint_nonneg G _ a b + dsimp [realTriangleSlope] + exact add_nonneg (add_nonneg (mul_nonneg (mul_nonneg (russoSlope_nonneg G _ _ t ht) (hT _ _)) (hT _ _)) + (mul_nonneg (mul_nonneg (hT _ _) (russoSlope_nonneg G _ _ t ht)) (hT _ _))) + (mul_nonneg (mul_nonneg (hT _ _) (hT _ _)) (russoSlope_nonneg G _ _ t ht)) + +theorem realTriangleSlope_le_majorant [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (b p : unitInterval) (hb : b < pc G) (hp : p ≤ b) (x : V) (ab : V×V) : + realTriangleSlope G x ab (p:ℝ) ≤ triangleMajorant G b x ab := by + have hs := russoSlope_le_majorant G hloc hqt b p hb hp + have hn := russoSlope_nonneg (G := G) + have hm (a z : V) : twoPoint G p a z ≤ twoPoint G b a z := twoPoint_mono G a z hp + simp only [realTriangleSlope,realTwoPoint_coe,triangleMajorant] + apply add_le_add + · apply add_le_add + · calc + _ ≤ russoMajorant G b x ab.1 * twoPoint G b ab.1 ab.2 * 1 := + mul_le_mul (mul_le_mul (hs _ _) (hm _ _) (twoPoint_nonneg G p _ _) (russoMajorant_nonneg G b _ _)) + (twoPoint_le_one G p _ _) (twoPoint_nonneg G p _ _) (mul_nonneg (russoMajorant_nonneg G b _ _) (twoPoint_nonneg G b _ _)) + _ = _ := mul_one _ + · calc + _ ≤ twoPoint G b x ab.1 * russoMajorant G b ab.1 ab.2 * 1 := + mul_le_mul (mul_le_mul (hm _ _) (hs _ _) (hn _ _ _ p.2.2) (twoPoint_nonneg G b _ _)) + (twoPoint_le_one G p _ _) (twoPoint_nonneg G p _ _) (mul_nonneg (twoPoint_nonneg G b _ _) (russoMajorant_nonneg G b _ _)) + _ = _ := mul_one _ + · calc + _ ≤ 1 * twoPoint G b ab.1 ab.2 * russoMajorant G b ab.2 x := + mul_le_mul (mul_le_mul (twoPoint_le_one G p _ _) (hm _ _) (twoPoint_nonneg G p _ _) zero_le_one) + (hs _ _) (hn _ _ _ p.2.2) (mul_nonneg zero_le_one (twoPoint_nonneg G b _ _)) + _ = _ := by rw [one_mul,twoPoint_symm G b,russoMajorant_symm G b]; ring + +end RealTriangle +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section TriangleDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def realTriangle (G : BondGraph V E) (x : V) (t : ℝ) : ℝ := + ∑' ab, realTriangleTerm G x ab t + +noncomputable def rootTriangle (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := + ∑ i, weight i * realTriangle G (root i) t + +theorem summable_realTriangleTerm [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Summable (fun ab => realTriangleTerm G x ab (p:ℝ)) := by + simp only [realTriangleTerm,realTwoPoint_coe] + apply (summable_twoPoint_pair G hloc hqt p hp x).of_nonneg_of_le + · intro ab + exact mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _) + · intro ab + exact mul_le_of_le_one_right (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_le_one G p _ _) + +theorem summable_realTriangleSlope [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + Summable (fun ab => realTriangleSlope G x ab (p:ℝ)) := by + exact (summable_triangleMajorant G hloc hqt p hp x).of_nonneg_of_le + (fun ab => realTriangleSlope_nonneg G x ab p p.2.2) + (fun ab => realTriangleSlope_le_majorant G hloc hqt p p hp le_rfl x ab) + + + +theorem hasDerivAt_realTriangle_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x : V) : + HasDerivAt (realTriangle G x) (∑' ab, realTriangleSlope G x ab (p:ℝ)) (p:ℝ) := by + obtain ⟨b,hpb,hb⟩ := exists_between hp + apply hasDerivAt_tsum_of_isPreconnected (summable_triangleMajorant G hloc hqt b hb x) + isOpen_Ioo isPreconnected_Ioo + (fun ab t ht => hasDerivAt_realTriangleTerm G hloc hqt t ⟨ht.1,lt_trans ht.2 hb⟩ x ab) + (fun ab t ht => ?_) (show (p:ℝ) ∈ Set.Ioo 0 (b:ℝ) from ⟨hp0,hpb⟩) + (summable_realTriangleTerm G hloc hqt p hp x) ⟨hp0,hpb⟩ + let q : unitInterval := ⟨t,ht.1.le,ht.2.le.trans b.2.2⟩ + have hq : q ≤ b := ht.2.le + rw [Real.norm_eq_abs,abs_of_nonneg (realTriangleSlope_nonneg G x ab t q.2.2)] + exact realTriangleSlope_le_majorant G hloc hqt b q hb hq x ab + +theorem hasDerivAt_rootTriangle_subcritical [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : + HasDerivAt (rootTriangle G root weight) + (∑ i, weight i * ∑' ab, realTriangleSlope G (root i) ab (p:ℝ)) (p:ℝ) := by + exact HasDerivAt.fun_sum (fun i _ => (hasDerivAt_realTriangle_subcritical G hloc hqt p hp0 hp (root i)).const_mul (weight i)) + +end TriangleDerivative +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/ScaleBudget.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/ScaleBudget.lean index 17d6d36e7320ddd77217a1717d8bd64264c311f8..f80d3839163bcb6ff3d4cef83402663b3750d724 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/ScaleBudget.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/ScaleBudget.lean @@ -1,1214 +1,1214 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Connections - -namespace OAI - -/-! Scale Budget for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section AveragedBinOrbitTransport -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integral_tsum_of_finite_support {α Ω : Type*} [MeasurableSpace Ω] - (μ : Measure Ω) (S : Finset α) (f : Ω → α → ℝ) - (hi : ∀ x, Integrable (fun ω => f ω x) μ) - (hs : ∀ ω x, x ∉ S → f ω x = 0) : - (∫ ω, ∑' x, f ω x ∂μ) = ∑' x, ∫ ω, f ω x ∂μ := by - have he (ω) : (∑' x, f ω x) = ∑ x ∈ S, f ω x := tsum_eq_sum (hs ω) - rw [show (∫ ω, ∑' x, f ω x ∂μ) = ∫ ω, ∑ x ∈ S, f ω x ∂μ by simp only [he], - integral_finsetSum _ (fun x _ => hi x),tsum_eq_sum (s := S) (fun x hx => by simp only [hs _ x hx,integral_zero])] - -theorem binOrbitTransportMass_local (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (ω : Set E) (x y : V) : - let Qx := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - let Qy := incidentSupport G hloc (finite_reachBall hloc y (2*n)).toFinset - binOrbitTransportMass G n ω x y = binOrbitTransportMass G n (ω ∩ ((Qx∪Qy : Finset E) : Set E)) x y := by - let Qx := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset - let Qy := incidentSupport G hloc (finite_reachBall hloc y (2*n)).toFinset - have hB := finite_local_of_subset Qx (Qx∪Qy) Finset.subset_union_left - (fun ω => binConnectionMass G n ω x y) (fun ω => binConnectionMass_local G hloc n ω x y) ω - have hq := finite_local_of_subset Qy (Qx∪Qy) Finset.subset_union_right - (fun ω => binOrbitRowMass G n ω y) (fun ω => binOrbitRowMass_local G hloc n ω y) ω - have hs := finite_local_of_subset Qx (Qx∪Qy) Finset.subset_union_left - (fun ω => binSizeMass G n ω x) (fun ω => binSizeMass_local G hloc n ω x) ω - exact congrArg₂ (· / ·) (congrArg₂ (· * ·) hB hq) hs - -theorem binOrbitTransportMass_integrable (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) (x y : V) : Integrable (fun ω => binOrbitTransportMass G n ω x y) (law p) := - integrable_finite_local _ p _ (fun ω => binOrbitTransportMass_local G hloc n ω x y) - -theorem binOrbitTransportMass_outside (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (hy : y ∉ reachBall G x (2*n)) : binOrbitTransportMass G n ω x y = 0 := by - simp only [binOrbitTransportMass,binConnectionMass_outside G n ω x y hy,zero_mul,zero_div] - -noncomputable def binOrbitTransport (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : ℝ := - ∫ ω, binOrbitTransportMass G n ω x y ∂law p - -theorem binOrbitTransport_covariant (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : - binOrbitTransport G p n (a x) (a y) = binOrbitTransport G p n x y := by - have hm : Measurable (fun ω => binOrbitTransportMass G n ω x y) := - measurable_finite_local _ _ (fun ω => binOrbitTransportMass_local G hloc n ω x y) - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [binOrbitTransport,binOrbitTransportMass,binConnectionMass_covariant G hab, - binOrbitRowMass_covariant G n _ hab,binSizeMass_covariant G n _ hab] using h.symm - -theorem binOrbitTransport_outside (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) - (hy : y ∉ reachBall G x (2*n)) : binOrbitTransport G p n x y = 0 := by - simp only [binOrbitTransport,binOrbitTransportMass_outside G n _ x y hy,integral_zero] - -theorem binOrbitTransportMass_outside_column (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) - (hx : x ∉ reachBall G y (2*n)) : binOrbitTransportMass G n ω x y = 0 := by - have hB : binConnectionMass G n ω x y = 0 := by - rw [binConnectionMass_symm] - exact binConnectionMass_outside G n ω y x hx - simp only [binOrbitTransportMass,hB,zero_mul,zero_div] - -theorem binOrbitTransport_row_integral (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) (x : V) : - (∑' y, binOrbitTransport G p n x y) = ∫ ω, ∑' y, binOrbitTransportMass G n ω x y ∂law p := by - symm - apply integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ - (binOrbitTransportMass_integrable G hloc p n x) - intro ω y hy - exact binOrbitTransportMass_outside G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) - -theorem integral_binOrbitRowMass (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) (x : V) : - (∫ ω, binOrbitRowMass G n ω x ∂law p) = binOrbitRow G p x n := by - have hx : x ∈ vertexOrbit G x := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ - unfold binOrbitRowMass - rw [integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ - (fun y => by - by_cases hy : y ∈ vertexOrbit G x - · simp only [ite_eq_left hy] - exact integrable_finite_local _ p _ (fun ω => binConnectionMass_local G hloc n ω x y) - · simp only [ite_eq_right hy]; exact integrable_const (0:ℝ)) - (fun ω y hy => by - have hz := binConnectionMass_outside G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) - simp only [hz,ite_self])] - apply tsum_congr - intro y - by_cases hy : y ∈ vertexOrbit G x - · simp only [orbitBinConnection,hx,hy,true_and,ite_true,binConnection] - · simp only [orbitBinConnection,hy,and_false,ite_false,integral_zero] - -theorem binOrbitTransport_column (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (n : ℕ) (hn : 0 < n) (y : V) : - (∑' x, binOrbitTransport G p n x y) = binOrbitRow G p y n := by - rw [←integral_binOrbitRowMass G hloc p n y,←show (∫ ω, ∑' x, binOrbitTransportMass G n ω x y ∂law p) = - ∑' x, binOrbitTransport G p n x y from - integral_tsum_of_finite_support (law p) (finite_reachBall hloc y (2*n)).toFinset _ - (fun x => binOrbitTransportMass_integrable G hloc p n x y) - (fun ω x hx => binOrbitTransportMass_outside_column G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hx))] - simp only [binOrbitTransportMass_column G n hn] - -end AveragedBinOrbitTransport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedOrbitBinLower -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem binOrbitTransport_row_lower (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (p : unitInterval) (n : ℕ) (hn : 0 < n) (x : V) : - (n:ℝ)/Fintype.card ι * clusterWindowProbability G p x n (2*n) ≤ - ∑' y, binOrbitTransport G p n x y := by - let B := (finite_reachBall hloc x (2*n)).toFinset - have he (ω) : (∑' y, binOrbitTransportMass G n ω x y) = - ∑ y ∈ B, binOrbitTransportMass G n ω x y := by - apply tsum_eq_sum - intro y hy - exact binOrbitTransportMass_outside G n ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - have hi : Integrable (fun ω => ∑' y, binOrbitTransportMass G n ω x y) (law p) := by - simp only [he] - exact integrable_finsetSum B (fun y _ => binOrbitTransportMass_integrable G hloc p n x y) - let W := {ω | ClusterWindow G x n (2*n) ω} - have hm : MeasurableSet W := measurableSet_clusterWindow G hloc x n (2*n) - have hl : Integrable (W.indicator (fun _ => (n:ℝ)/Fintype.card ι)) (law p) := - (integrable_const _).indicator hm - calc - _ = ∫ ω, W.indicator (fun _ => (n:ℝ)/Fintype.card ι) ω ∂law p := by - rw [integral_indicator_const _ hm] - simp only [smul_eq_mul,clusterWindowProbability,W,mul_comm] - _ ≤ ∫ ω, ∑' y, binOrbitTransportMass G n ω x y ∂law p := by - apply integral_mono hl hi - intro ω - exact binOrbitTransportMass_row G root hcover n hn ω x - _ = _ := (binOrbitTransport_row_integral G hloc p n x).symm - - - -theorem weighted_binOrbitRow_lower (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (p : unitInterval) (n : ℕ) (hn : 0 < n) : - (n:ℝ)/Fintype.card ι * (∑ i, weight i * clusterWindowProbability G p (root i) n (2*n)) ≤ - ∑ i, weight i * binOrbitRow G p (root i) n := by - have hr (x : V) : Summable (binOrbitTransport G p n x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) - intro y hy - exact binOrbitTransport_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) - have hc (y : V) : Summable (fun x => binOrbitTransport G p n x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y (2*n)).toFinset) - intro x hx - have hz (ω) := binOrbitTransportMass_outside_column G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hx) - simp only [binOrbitTransport,hz,integral_zero] - have ht := htr.real root weight Γ (binOrbitTransport G p n) - (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact binOrbitTransport_covariant G hloc p hab n x y) hr hc - calc - _ = ∑ i, weight i * ((n:ℝ)/Fintype.card ι * clusterWindowProbability G p (root i) n (2*n)) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i hi - ring - _ ≤ ∑ i, weight i * ∑' y, binOrbitTransport G p n (root i) y := - Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (binOrbitTransport_row_lower G hloc root hcover p n hn (root i)) (hw i)) - _ = ∑ i, weight i * ∑' x, binOrbitTransport G p n x (root i) := ht - _ = _ := by simp only [binOrbitTransport_column G hloc p n hn] - -theorem exists_binOrbitRow_lower (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) - (p : unitInterval) (n : ℕ) (hn : 0 < n) : - ∃ i, (n:ℝ)/Fintype.card ι * (∑ j, weight j * clusterWindowProbability G p (root j) n (2*n)) ≤ - binOrbitRow G p (root i) n := by - have h := weighted_binOrbitRow_lower G hloc root weight Γ hΓ htr (fun i => (hw i).le) hcover p n hn - by_contra! he - let c := (n:ℝ)/Fintype.card ι * (∑ j, weight j * clusterWindowProbability G p (root j) n (2*n)) - have hs : (∑ i, weight i * binOrbitRow G p (root i) n) < ∑ i, weight i*c := by - apply Finset.sum_lt_sum (fun i _ => (mul_lt_mul_of_pos_left (he i) (hw i)).le) - exact ⟨Classical.arbitrary ι,Finset.mem_univ _,mul_lt_mul_of_pos_left (he _) (hw _)⟩ - rw [←Finset.sum_mul,hw1,one_mul] at hs - exact (not_lt_of_ge h) hs - -end WeightedOrbitBinLower - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DyadicRecords -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem summable_dyadic_of_scaled_bound (π : ℕ → ℝ) (hπ : ∀ j, 0 ≤ π j) - (α β C : ℝ) (hαβ : α < β) - (hC : ∀ j : ℕ, (2:ℝ)^(β*(j:ℝ))*π j ≤ C) : - Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*π j) := by - let r := (2:ℝ)^(α-β) - have hr0 : 0 ≤ r := Real.rpow_nonneg (by norm_num) _ - have hr1 : r < 1 := Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (sub_neg.mpr hαβ) - have hs := (summable_geometric_of_lt_one hr0 hr1).mul_left C - apply hs.of_nonneg_of_le (fun j => mul_nonneg (Real.rpow_nonneg (by norm_num) _) (hπ j)) - intro j - have he : (2:ℝ)^(α*(j:ℝ)) = r^j * (2:ℝ)^(β*(j:ℝ)) := by - rw [show r^j = (2:ℝ)^((α-β)*(j:ℝ)) by rw [Real.rpow_mul (by norm_num),Real.rpow_natCast], - ←Real.rpow_add (by norm_num)] - congr 1 - ring - rw [he,mul_assoc] - exact (mul_le_mul_of_nonneg_left (hC j) (pow_nonneg hr0 j)).trans_eq (mul_comm _ _) - -theorem unbounded_scaled_dyadic (π : ℕ → ℝ) (hπ : ∀ j, 0 ≤ π j) - (α β : ℝ) (hαβ : α < β) - (hdiv : ¬ Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*π j)) : - ∀ C : ℝ, ∃ j : ℕ, C < (2:ℝ)^(β*(j:ℝ))*π j := by - intro C - by_contra! hC - exact hdiv (summable_dyadic_of_scaled_bound π hπ α β C hαβ hC) - - -theorem late_record_of_unbounded (f : ℕ → ℝ) (hf : ∀ C : ℝ, ∃ j, C < f j) (N : ℕ) : - ∃ j, N < j ∧ 1 ≤ f j ∧ ∀ i ≤ j, f i ≤ f j := by - obtain ⟨a,ha,hamax⟩ := (Finset.range (N+1)).exists_max_image f ⟨0,by simp⟩ - obtain ⟨b,hb⟩ := hf (max 1 (f a)) - obtain ⟨j,hj,hjmax⟩ := (Finset.range (b+1)).exists_max_image f ⟨0,by simp⟩ - have hb' : max 1 (f a) < f j := hb.trans_le (hjmax b (by simp)) - refine ⟨j,?_,(le_max_left _ _).trans hb'.le,?_⟩ - · by_contra! hjN - have he := hamax j (Finset.mem_range.mpr (by omega)) - exact (not_lt_of_ge he) ((le_max_right _ _).trans_lt hb') - · intro i hi - exact hjmax i (Finset.mem_range.mpr (by have := Finset.mem_range.mp hj; omega)) - - - -theorem finite_family_unbounded_choice {ι : Type*} [Fintype ι] - (P : ι → ℕ → Prop) (h : ∀ N, ∃ j, N ≤ j ∧ ∃ i, P i j) : - ∃ i, ∀ N, ∃ j, N ≤ j ∧ P i j := by - by_contra! hnot - choose L hL using hnot - obtain ⟨j,hj,i,hi⟩ := h (∑ i, L i) - have hLi : L i ≤ ∑ t, L t := Finset.single_le_sum (fun t _ => Nat.zero_le (L t)) (Finset.mem_univ i) - exact hL i j (hLi.trans hj) hi - -theorem record_dyadic_bounds (π : ℕ → ℝ) (β : ℝ) (j : ℕ) - (hrec : ∀ i ≤ j+1, (2:ℝ)^(β*(i:ℝ))*π i ≤ (2:ℝ)^(β*((j+1:ℕ):ℝ))*π (j+1)) - (h1 : 1 ≤ (2:ℝ)^(β*((j+1:ℕ):ℝ))*π (j+1)) : - (2:ℝ)^(-β*((j+1:ℕ):ℝ)) ≤ π (j+1) ∧ π j ≤ (2:ℝ)^β*π (j+1) := by - have hpos : 0 < (2:ℝ)^(β*((j+1:ℕ):ℝ)) := Real.rpow_pos_of_pos (by norm_num) _ - have hinv : (2:ℝ)^(-β*((j+1:ℕ):ℝ)) = 1/(2:ℝ)^(β*((j+1:ℕ):ℝ)) := by - rw [show -β*((j+1:ℕ):ℝ) = -(β*((j+1:ℕ):ℝ)) by ring,Real.rpow_neg (by norm_num)] - simp only [one_div] - refine ⟨?_,?_⟩ - · rw [hinv] - exact (div_le_iff₀ hpos).mpr (by simpa only [mul_comm] using h1) - · have hr := hrec j (by omega) - have he : (2:ℝ)^(β*((j+1:ℕ):ℝ)) = (2:ℝ)^(β*(j:ℝ))*(2:ℝ)^β := by - rw [Nat.cast_add,Nat.cast_one,mul_add,mul_one,Real.rpow_add (by norm_num)] - rw [he,mul_assoc] at hr - exact (mul_le_mul_iff_right₀ (Real.rpow_pos_of_pos (by norm_num : (0:ℝ)<2) _)).mp hr - -end DyadicRecords - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section OrbitDyadicScales -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem clusterWindowProbability_split (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x : V) (a b c : ℕ) (hab : a ≤ b) (hbc : b ≤ c) : - clusterWindowProbability G p x a c = clusterWindowProbability G p x a b + clusterWindowProbability G p x b c := by - have he : {ω | ClusterWindow G x a c ω} = - {ω | ClusterWindow G x a b ω} ∪ {ω | ClusterWindow G x b c ω} := by - ext ω - simp only [Set.mem_ofPred_eq,Set.mem_union,ClusterWindow] - constructor - · rintro ⟨hf,ha,hc⟩ - by_cases hb : (cluster G ω x).ncard < b - · exact Or.inl ⟨hf,ha,hb⟩ - · exact Or.inr ⟨hf,by omega,hc⟩ - · rintro (⟨hf,ha,hb⟩|⟨hf,hb,hc⟩) - · exact ⟨hf,ha,hb.trans_le hbc⟩ - · exact ⟨hf,hab.trans hb,hc⟩ - have hd : Disjoint {ω | ClusterWindow G x a b ω} {ω | ClusterWindow G x b c ω} := by - apply Set.disjoint_left.mpr - intro ω h₁ h₂ - exact (not_lt_of_ge h₂.2.1) h₁.2.2 - unfold clusterWindowProbability - rw [he,measureReal_union hd (measurableSet_clusterWindow G hloc x b c)] - -noncomputable def weightedWindowProbability {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) (a b : ℕ) : ℝ := - ∑ i, weight i * clusterWindowProbability G p (root i) a b - -theorem weightedWindowProbability_nonneg {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (a b : ℕ) : - 0 ≤ weightedWindowProbability G p root weight a b := by - exact Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (clusterWindowProbability_nonneg G p (root i) a b)) - -theorem weightedWindowProbability_split {ι : Type*} [Fintype ι] - (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) - (a b c : ℕ) (hab : a ≤ b) (hbc : b ≤ c) : - weightedWindowProbability G p root weight a c = - weightedWindowProbability G p root weight a b + weightedWindowProbability G p root weight b c := by - simp only [weightedWindowProbability,clusterWindowProbability_split G hloc p _ a b c hab hbc, - mul_add,Finset.sum_add_distrib] - -noncomputable def dyadicBinProbability {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) (j : ℕ) : ℝ := - weightedWindowProbability G p root weight (2^j) (2^(j+1)) - - - -theorem orbit_dyadic_scales (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (p : unitInterval) - (α β : ℝ) (hαβ : α < β) - (hdiv : ¬ Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*dyadicBinProbability G p root weight j)) : - ∃ i, ∀ N, ∃ j, N ≤ j ∧ - ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ - weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ - (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ - (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ - binOrbitRow G p (root i) (2^(j+1)) := by - let π := dyadicBinProbability G p root weight - let f := fun j : ℕ => (2:ℝ)^(β*(j:ℝ))*π j - have hπ : ∀ j, 0 ≤ π j := fun j => weightedWindowProbability_nonneg G p root weight (fun i => (hw i).le) _ _ - have hf := unbounded_scaled_dyadic π hπ α β hαβ hdiv - let P := fun i j => 1 ≤ f (j+1) ∧ (∀ t ≤ j+1, f t ≤ f (j+1)) ∧ - (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*π (j+1) ≤ binOrbitRow G p (root i) (2^(j+1)) - have hpick : ∀ N, ∃ j, N ≤ j ∧ ∃ i, P i j := by - intro N - obtain ⟨t,ht,h1,hr⟩ := late_record_of_unbounded f hf N - obtain ⟨j,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : t ≠ 0) - obtain ⟨i,hi⟩ := exists_binOrbitRow_lower G hloc root weight Γ hΓ htr hw hw1 hcover p (2^(j+1)) (by positivity) - have he : 2*2^(j+1) = 2^(j+2) := by rw [show j+2 = (j+1)+1 by omega,pow_succ]; omega - refine ⟨j,by omega,i,h1,hr,?_⟩ - simpa only [P,π,dyadicBinProbability,weightedWindowProbability,he] using hi - obtain ⟨i,hi⟩ := finite_family_unbounded_choice P hpick - refine ⟨i,?_⟩ - intro N - obtain ⟨j,hj,h1,hr,hb⟩ := hi N - have hs := record_dyadic_bounds π β j hr h1 - refine ⟨j,hj,?_,?_,hb⟩ - · have he : (((2^(j+1):ℕ):ℝ)^(-β)) = (2:ℝ)^(-β*((j+1:ℕ):ℝ)) := by - rw [Nat.cast_pow,Nat.cast_ofNat,←Real.rpow_natCast,←Real.rpow_mul (by norm_num)] - congr 1 - ring - rw [he] - exact hs.1 - · rw [weightedWindowProbability_split G hloc p root weight (2^j) (2^(j+1)) (2^(j+2)) - (Nat.pow_le_pow_right (by norm_num) (by omega)) (Nat.pow_le_pow_right (by norm_num) (by omega))] - change π j + π (j+1) ≤ (1+(2:ℝ)^β)*π (j+1) - nlinarith only [hs.2] - -end OrbitDyadicScales - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ClusterSizeMomentIntegrable -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_cluster_ncard (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - Measurable (fun ω : Set E => (cluster G ω x).ncard) := by - have hm (k : ℕ) (hk : k ≠ 0) : MeasurableSet {ω : Set E | (cluster G ω x).ncard = k} := by - have he : {ω : Set E | (cluster G ω x).ncard = k} = {ω | ClusterWindow G x k (k+1) ω} := by - ext ω - constructor - · intro h - have hf := Set.finite_of_ncard_ne_zero (by rw [h]; exact hk) - exact ⟨hf,by rw [h],by rw [h]; omega⟩ - · rintro ⟨hf,hl,hu⟩ - exact le_antisymm (by omega) hl - rw [he] - exact measurableSet_clusterWindow G hloc x k (k+1) - have hm0 : MeasurableSet {ω : Set E | (cluster G ω x).ncard = 0} := by - have he : {ω : Set E | (cluster G ω x).ncard = 0} = - (⋃ k : ℕ, {ω : Set E | (cluster G ω x).ncard = k+1})ᶜ := by - ext ω - simp only [Set.mem_compl_iff,Set.mem_iUnion,Set.mem_ofPred_eq,not_exists] - constructor - · intro h k - omega - · intro h - by_contra hz - obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero hz - exact h k hk - rw [he] - exact (MeasurableSet.iUnion (fun k => hm (k+1) (by omega))).compl - apply measurable_to_countable - intro ω - change MeasurableSet {ω' | (cluster G ω' x).ncard = (cluster G ω x).ncard} - by_cases h : (cluster G ω x).ncard = 0 - · simpa only [h] using hm0 - · exact hm _ h - - - -theorem integrable_cluster_power_of_dyadic (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (x : V) (α : ℝ) (hα : 0 < α) - (hs : Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p x (2^j) (2^(j+1)))) : - Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by - let f := fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α - let F := fun j : ℕ => {ω | ClusterWindow G x (2^j) (2^(j+1)) ω}.indicator - (fun _ => (2:ℝ)^(α*((j+1:ℕ):ℝ))) - have hFm (j : ℕ) : Measurable (F j) := - measurable_const.indicator (measurableSet_clusterWindow G hloc x _ _) - have hFi (j : ℕ) : Integrable (F j) (law p) := - (integrable_const _).indicator (measurableSet_clusterWindow G hloc x _ _) - have hFn (j : ℕ) (ω : Set E) : 0 ≤ F j ω := by - exact Set.indicator_nonneg (fun _ _ => (Real.rpow_pos_of_pos (by norm_num) _).le) _ - have hFe (j : ℕ) : (∫ ω, F j ω ∂law p) = - (2:ℝ)^α * ((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p x (2^j) (2^(j+1))) := by - rw [integral_indicator_const _ (measurableSet_clusterWindow G hloc x _ _)] - simp only [smul_eq_mul,clusterWindowProbability,Nat.cast_add,Nat.cast_one,mul_add,mul_one, - Real.rpow_add (by norm_num : (0:ℝ)<2)] - ring - have hsum : Summable (fun j => ∫ ω, F j ω ∂law p) := by - simp only [hFe] - exact hs.mul_left _ - have hbound (ω : Set E) : ENNReal.ofReal (f ω) ≤ ∑' j, ENNReal.ofReal (F j ω) := by - by_cases hz : (cluster G ω x).ncard = 0 - · simp only [f,hz,Nat.cast_zero,Real.zero_rpow hα.ne',ENNReal.ofReal_zero] - exact bot_le - · let j := Nat.log 2 (cluster G ω x).ncard - have hl := Nat.pow_log_le_self 2 hz - have hu := Nat.lt_pow_succ_log_self (by norm_num : 1 < (2:ℕ)) (cluster G ω x).ncard - have hb : ClusterWindow G x (2^j) (2^(j+1)) ω := - ⟨Set.finite_of_ncard_ne_zero hz,hl,hu⟩ - have hle : f ω ≤ (2:ℝ)^(α*((j+1:ℕ):ℝ)) := by - have hcast : ((cluster G ω x).ncard:ℝ) ≤ ((2^(j+1):ℕ):ℝ) := by exact_mod_cast hu.le - have h := Real.rpow_le_rpow (Nat.cast_nonneg _) hcast hα.le - have he : (((2^(j+1):ℕ):ℝ)^α) = (2:ℝ)^(α*((j+1:ℕ):ℝ)) := by - rw [Nat.cast_pow,Nat.cast_ofNat,←Real.rpow_natCast,←Real.rpow_mul (by norm_num)] - congr 1 - ring - exact h.trans_eq he - have he : F j ω = (2:ℝ)^(α*((j+1:ℕ):ℝ)) := Set.indicator_of_mem (show ω ∈ {ω | ClusterWindow G x (2^j) (2^(j+1)) ω} from hb) _ - exact (ENNReal.ofReal_le_ofReal (hle.trans_eq he.symm)).trans - (ENNReal.le_tsum (f := fun scale => ENNReal.ofReal (F scale ω)) j) - have hfn (ω : Set E) : 0 ≤ f ω := Real.rpow_nonneg (Nat.cast_nonneg _) _ - refine ⟨((measurable_of_countable (fun m : ℕ => (m:ℝ)^α)).comp (measurable_cluster_ncard G hloc x)).aestronglyMeasurable,?_⟩ - apply (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hfn)).mpr - have hlin : (∫⁻ ω, ∑' j, ENNReal.ofReal (F j ω) ∂law p) < ⊤ := by - rw [lintegral_tsum (fun j => (hFm j).ennreal_ofReal.aemeasurable)] - simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hFn _))] - rw [←ENNReal.ofReal_tsum_of_nonneg (fun j => integral_nonneg (hFn j)) hsum] - exact ENNReal.ofReal_lt_top - exact (lintegral_mono hbound).trans_lt hlin - -end ClusterSizeMomentIntegrable - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedMomentScales -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem integrable_cluster_power_of_weighted_dyadic (G : BondGraph V E) - (hloc : LocallyFinite G) {ι : Type*} [Fintype ι] (p : unitInterval) - (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 < weight i) - (α : ℝ) (hα : 0 < α) - (hs : Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*dyadicBinProbability G p root weight j)) - (i : ι) : Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p) := by - have hle (j : ℕ) : weight i * clusterWindowProbability G p (root i) (2^j) (2^(j+1)) ≤ - dyadicBinProbability G p root weight j := by - exact Finset.single_le_sum - (fun t _ => mul_nonneg (hw t).le (clusterWindowProbability_nonneg G p (root t) _ _)) - (Finset.mem_univ i) - have hs' : Summable (fun j : ℕ => weight i * - ((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1)))) := by - apply hs.of_nonneg_of_le - · intro j - exact mul_nonneg (hw i).le (mul_nonneg (Real.rpow_nonneg (by norm_num) _) - (clusterWindowProbability_nonneg G p (root i) _ _)) - · intro j - have h := mul_le_mul_of_nonneg_left (hle j) (Real.rpow_nonneg (by norm_num : (0:ℝ) ≤ 2) (α*(j:ℝ))) - nlinarith only [h] - apply integrable_cluster_power_of_dyadic G hloc p (root i) α hα - have he : (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1))) = - (fun j : ℕ => (weight i)⁻¹ * (weight i *((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1))))) := by - funext j - rw [←mul_assoc,inv_mul_cancel₀ (hw i).ne',one_mul] - rw [he] - exact hs'.mul_left _ - - - -theorem orbit_scales_of_divergent_moment (G : BondGraph V E) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (p : unitInterval) - (α β : ℝ) (hα : 0 < α) (hαβ : α < β) - (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : - ∃ i, ∀ N, ∃ j, N ≤ j ∧ - ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ - weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ - (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ - (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ - binOrbitRow G p (root i) (2^(j+1)) := by - apply orbit_dyadic_scales G hloc root weight Γ hΓ htr hw hw1 hcover p α β hαβ - intro hs - obtain ⟨i,hi⟩ := hdiv - exact hi (integrable_cluster_power_of_weighted_dyadic G hloc p root weight hw α hα hs i) - -end WeightedMomentScales -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section LogarithmicChainLength - -noncomputable def logarithmicChainLength (t : ℝ) (n : ℕ) : ℕ := ⌊Real.log n / t⌋₊ - -theorem logarithmicChainLength_bounds (t : ℝ) (ht : 0 < t) (n : ℕ) (hn : 1 ≤ n) : - (logarithmicChainLength t n:ℝ)*t ≤ Real.log n ∧ - Real.log n < ((logarithmicChainLength t n:ℝ)+1)*t := by - have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn - have hlog := Real.log_nonneg hn' - constructor - · exact (le_div_iff₀ ht).mp (Nat.floor_le (div_nonneg hlog ht.le)) - · exact (div_lt_iff₀ ht).mp (Nat.lt_floor_add_one (Real.log n/t)) - -theorem tendsto_logarithmicChainLength (t : ℝ) (ht : 0 < t) : - Tendsto (logarithmicChainLength t) atTop atTop := - tendsto_nat_floor_atTop.comp ((Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).atTop_div_const ht) - -theorem tendsto_log_div_chainLength (t : ℝ) (ht : 0 < t) : - Tendsto (fun n : ℕ => Real.log n / logarithmicChainLength t n) atTop (nhds t) := by - have hk : Tendsto (fun n : ℕ => (logarithmicChainLength t n:ℝ)) atTop atTop := - tendsto_natCast_atTop_atTop.comp (tendsto_logarithmicChainLength t ht) - have hlim : Tendsto (fun n : ℕ => t + t/(logarithmicChainLength t n:ℝ)) atTop (nhds t) := by - simpa only [add_zero] using tendsto_const_nhds.add (tendsto_const_nhds.div_atTop hk) - apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlim - · filter_upwards [eventually_ge_atTop (1:ℕ),hk.eventually_gt_atTop 0] with n hn hk0 - exact (le_div_iff₀ hk0).mpr (by simpa only [mul_comm] using (logarithmicChainLength_bounds t ht n hn).1) - · filter_upwards [eventually_ge_atTop (1:ℕ),hk.eventually_gt_atTop 0] with n hn hk0 - have h := (logarithmicChainLength_bounds t ht n hn).2.le - apply (div_le_iff₀ hk0).mpr - calc - _ ≤ ((logarithmicChainLength t n:ℝ)+1)*t := h - _ = _ := by field_simp - -theorem tendsto_chainLength_div_scale (t : ℝ) (ht : 0 < t) : - Tendsto (fun n : ℕ => (logarithmicChainLength t n:ℝ)/n) atTop (nhds 0) := by - have hlog : Tendsto (fun n : ℕ => (Real.log n/(n:ℝ))/t) atTop (nhds 0) := by - simpa only [zero_div,Function.comp_def,id_eq] using - (Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp tendsto_natCast_atTop_atTop).div_const t - apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlog - · exact Eventually.of_forall (fun n => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) - · filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn - have hn' : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) - apply (le_div_iff₀ ht).mpr - rw [div_mul_eq_mul_div] - exact (div_le_div_iff_of_pos_right hn').mpr (logarithmicChainLength_bounds t ht n hn).1 - -theorem eventually_chain_volume_small (t : ℝ) (ht : 0 < t) (M : ℕ) : - ∀ᶠ n : ℕ in atTop, 2*logarithmicChainLength t n*M ≤ n := by - have hlim : Tendsto (fun n : ℕ => (2*(logarithmicChainLength t n:ℝ)*M)/(n:ℝ)) atTop (nhds 0) := by - have h := (tendsto_chainLength_div_scale t ht).const_mul (2*(M:ℝ)) - simpa only [mul_zero] using h.congr (fun n => by ring) - filter_upwards [(tendsto_order.mp hlim).2 1 (by norm_num),eventually_ge_atTop (1:ℕ)] with n hn hn1 - have hn' : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) - have h := (div_lt_iff₀ hn').mp hn - norm_num only [one_mul] at h - exact_mod_cast h.le - -end LogarithmicChainLength -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section AmplificationPolynomial - -theorem amplificationMomentFactor_ge_four (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : - 4 ≤ amplificationMomentFactor k M d c a t := by - unfold amplificationMomentFactor - have h1 : (0:ℝ) ≤ ((k*M)+(k*M)^2+d*(k*M)^3:ℕ) := Nat.cast_nonneg _ - have h2 : (0:ℝ) ≤ (2*c*(k*M:ℕ))^2*t/a := by positivity - linarith - -theorem amplificationMomentFactor_cubic (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : - amplificationMomentFactor k M d c a t ≤ amplificationMomentFactor 1 M d c a t * ((k:ℝ)+1)^3 := by - let b := (2*c*(M:ℝ))^2*t/a - have hb : 0 ≤ b := by dsimp [b]; positivity - have hk : (0:ℝ) ≤ k := Nat.cast_nonneg _ - have hk1 : (1:ℝ) ≤ (k:ℝ)+1 := by linarith - have h13 : (1:ℝ) ≤ ((k:ℝ)+1)^3 := one_le_pow₀ hk1 - have h1 : (k:ℝ) ≤ ((k:ℝ)+1)^3 := by - calc - _ ≤ (k:ℝ)+1 := by linarith - _ = ((k:ℝ)+1)^1 := (pow_one _).symm - _ ≤ _ := pow_le_pow_right₀ hk1 (by omega) - have h2 : (k:ℝ)^2 ≤ ((k:ℝ)+1)^3 := - (pow_le_pow_left₀ hk (by linarith : (k:ℝ) ≤ (k:ℝ)+1) 2).trans (pow_le_pow_right₀ hk1 (by omega)) - have h3 : (k:ℝ)^3 ≤ ((k:ℝ)+1)^3 := pow_le_pow_left₀ hk (by linarith) 3 - have he (j : ℕ) : amplificationMomentFactor j M d c a t = - 4 + (M:ℝ)*j + (M:ℝ)^2*(j:ℝ)^2 + ((d:ℝ)*(M:ℝ)^3)*(j:ℝ)^3 + b*(j:ℝ)^2 := by - simp only [amplificationMomentFactor,Nat.cast_add,Nat.cast_mul,Nat.cast_pow,b] - ring - rw [he k,he 1] - norm_num only [Nat.cast_one,one_pow,mul_one] - have hh0 := mul_le_mul_of_nonneg_left h13 (by norm_num : (0:ℝ) ≤ 4) - have hh1 := mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg M : (0:ℝ) ≤ M) - have hh2 := mul_le_mul_of_nonneg_left h2 (sq_nonneg (M:ℝ)) - have hh3 := mul_le_mul_of_nonneg_left h3 (show 0 ≤ (d:ℝ)*(M:ℝ)^3 by positivity) - have hhb := mul_le_mul_of_nonneg_left h2 hb - nlinarith only [hh0,hh1,hh2,hh3,hhb] - -theorem tendsto_log_amplificationMomentFactor_div (M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : - Tendsto (fun k : ℕ => Real.log (amplificationMomentFactor k M d c a t)/(k:ℝ)) atTop (nhds 0) := by - let C := amplificationMomentFactor 1 M d c a t - have hC : 0 < C := amplificationMomentFactor_pos _ _ _ _ _ _ ha ht - have hplus : Tendsto (fun k : ℕ => (k:ℝ)+1) atTop atTop := by - simpa only [Function.comp_def,Nat.cast_add,Nat.cast_one] using - (tendsto_natCast_atTop_atTop (R := ℝ)).comp (tendsto_add_atTop_nat 1) - have hlog : Tendsto (fun k : ℕ => Real.log ((k:ℝ)+1)/(k:ℝ)) atTop (nhds 0) := by - simpa only [Function.comp_def,pow_one,one_mul,add_neg_cancel_right] using - (Real.tendsto_pow_log_div_mul_add_atTop 1 (-1) 1 one_ne_zero).comp hplus - have hupper : Tendsto (fun k : ℕ => (Real.log C + 3*Real.log ((k:ℝ)+1))/(k:ℝ)) atTop (nhds 0) := by - have h := ((tendsto_const_nhds (x := Real.log C)).div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))).add (hlog.const_mul 3) - simpa only [zero_add,mul_zero,add_div,mul_div_assoc] using h - apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper - · exact Eventually.of_forall (fun k => div_nonneg - (Real.log_nonneg (by have := amplificationMomentFactor_ge_four k M d c a t ha ht; linarith)) (Nat.cast_nonneg _)) - · exact Eventually.of_forall (fun k => by - apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - have hh := Real.log_le_log (amplificationMomentFactor_pos k M d c a t ha ht) - (amplificationMomentFactor_cubic k M d c a t ha ht) - have hp : (0:ℝ) < (k:ℝ)+1 := by positivity - simpa only [C,Real.log_mul hC.ne' (pow_pos hp 3).ne',Real.log_pow,Nat.cast_ofNat] using hh) - -end AmplificationPolynomial -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section AmplificationScalarBudget - -theorem eventually_inverseCodeMass_budget (s ξ : ℝ) (hs : 0 ≤ s) (hξ : 0 < ξ) : - ∀ᶠ M : ℕ in atTop, 2 ≤ M ∧ 1 ≤ (M:ℝ)^s ∧ - inverseCodeMass M ((M:ℝ)^s) ≤ (M:ℝ)^(s+ξ) := by - have hl := (isLittleO_log_rpow_atTop hξ).bound (by norm_num : (0:ℝ) < 1/8) - have hcast : Tendsto (fun M : ℕ => (M:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop - filter_upwards [eventually_ge_atTop (2:ℕ),hcast.eventually hl] with M hM hl - have hM' : (1:ℝ) ≤ M := by exact_mod_cast (show 1 ≤ M by omega) - have hM0 : (0:ℝ) < M := lt_of_lt_of_le zero_lt_one hM' - have hL : 1 ≤ (M:ℝ)^s := Real.one_le_rpow hM' hs - refine ⟨hM,hL,?_⟩ - simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hM'), - abs_of_nonneg (Real.rpow_nonneg hM0.le ξ)] at hl - calc - _ ≤ 8*(M:ℝ)^s*Real.log M := inverseCodeMass_le_log M _ hM hL - _ ≤ (M:ℝ)^s*(M:ℝ)^ξ := by - have hh := mul_le_mul_of_nonneg_left hl (Real.rpow_nonneg hM0.le s) - nlinarith only [hh] - _ = _ := (Real.rpow_add hM0 _ _).symm - -theorem code_bound_of_logarithmic_chain (u W t : ℝ) (hu : 0 < u) (hW : 0 ≤ W) - (ht : 0 < t) (hbudget : W ≤ u*Real.exp t) (n : ℕ) (hn : 1 ≤ n) : - W^logarithmicChainLength t n ≤ (n:ℝ)*u^logarithmicChainLength t n := by - let k := logarithmicChainLength t n - have hexp : Real.exp ((k:ℝ)*t) ≤ (n:ℝ) := by - have h := Real.exp_le_exp.mpr (logarithmicChainLength_bounds t ht n hn).1 - have hnp : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) - simpa only [Real.exp_log hnp] using h - calc - W^k ≤ (u*Real.exp t)^k := pow_le_pow_left₀ hW hbudget _ - _ = u^k*Real.exp ((k:ℝ)*t) := by rw [mul_pow,←Real.exp_nat_mul] - _ ≤ u^k*n := mul_le_mul_of_nonneg_left hexp (pow_nonneg hu.le _) - _ = _ := mul_comm _ _ - -theorem tendsto_rpow_mul_stretched_exp (γ ε : ℝ) (hε : 0 < ε) : - Tendsto (fun x : ℝ => x^γ * Real.exp (-(x^ε))) atTop (nhds 0) := by - have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (γ/ε) 1 zero_lt_one).comp (tendsto_rpow_atTop hε) - apply h.congr' - filter_upwards [eventually_ge_atTop (0:ℝ)] with x hx - simp only [Function.comp_def,neg_mul,one_mul,←Real.rpow_mul hx] - rw [mul_div_cancel₀ γ hε.ne'] - -end AmplificationScalarBudget -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section AmplificationGoodnessDecay - -theorem eventually_amplification_goodness_decay (T : ℝ) (hT : 0 < T) - (M d : ℕ) (c a b β ε : ℝ) (ha : 0 < a) (hb : 0 ≤ b) (hε : 0 < ε) : - ∀ᶠ n : ℕ in atTop, - 16*amplificationMomentFactor (logarithmicChainLength T n) M d c a b * - Real.exp (-((2*n+logarithmicChainLength T n*M:ℕ):ℝ)^ε) ≤ a*(n:ℝ)^(-β) := by - let C := amplificationMomentFactor 1 M d c a b - have hC : 0 < C := amplificationMomentFactor_pos _ _ _ _ _ _ ha hb - have hd : Tendsto (fun n : ℕ => 128*C*((n:ℝ)^(β+3)*Real.exp (-(n:ℝ)^ε))) atTop (nhds 0) := by - simpa only [mul_zero,Function.comp_def] using - ((tendsto_rpow_mul_stretched_exp (β+3) ε hε).comp tendsto_natCast_atTop_atTop).const_mul (128*C) - have hk := (tendsto_order.mp (tendsto_chainLength_div_scale T hT)).2 1 (by norm_num) - filter_upwards [eventually_ge_atTop (1:ℕ),hk,(tendsto_order.mp hd).2 a ha] with n hn hk hd - let k := logarithmicChainLength T n - have hn0 : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) - have hn1 : (1:ℝ) ≤ n := by exact_mod_cast hn - have hkn : (k:ℝ) ≤ n := by - exact ((div_lt_iff₀ hn0).mp hk).le.trans_eq (one_mul _) - have hQ : amplificationMomentFactor k M d c a b ≤ 8*C*(n:ℝ)^3 := by - have hp : ((k:ℝ)+1)^3 ≤ (2*(n:ℝ))^3 := - pow_le_pow_left₀ (by positivity) (by linarith) 3 - calc - _ ≤ C*((k:ℝ)+1)^3 := amplificationMomentFactor_cubic k M d c a b ha hb - _ ≤ C*(2*(n:ℝ))^3 := mul_le_mul_of_nonneg_left hp hC.le - _ = _ := by ring - have he : Real.exp (-((2*n+k*M:ℕ):ℝ)^ε) ≤ Real.exp (-(n:ℝ)^ε) := by - apply Real.exp_le_exp.mpr - apply neg_le_neg - apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hε.le - exact_mod_cast (show n ≤ 2*n+k*M by omega) - have hpow : 0 < (n:ℝ)^β := Real.rpow_pos_of_pos hn0 _ - rw [Real.rpow_neg hn0.le,←div_eq_mul_inv] - apply (le_div_iff₀ hpow).mpr - calc - _ ≤ (16*(8*C*(n:ℝ)^3)*Real.exp (-(n:ℝ)^ε))*(n:ℝ)^β := by - apply mul_le_mul_of_nonneg_right _ hpow.le - exact mul_le_mul (mul_le_mul_of_nonneg_left hQ (by norm_num)) he - (Real.exp_pos _).le (by positivity) - _ = 128*C*((n:ℝ)^(β+3)*Real.exp (-(n:ℝ)^ε)) := by - rw [Real.rpow_add hn0,show (n:ℝ)^(3:ℝ) = (n:ℝ)^3 by norm_cast] - ring - _ ≤ a := hd.le - -end AmplificationGoodnessDecay -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section AmplificationLogEstimates - -theorem log_inv_success_le (a Q n β u : ℝ) (ha : 0 < a) (hQ : 0 < Q) - (hn : 0 < n) (hbound : a*n^(-β)/(8*Q) ≤ u) : - Real.log (1/u) ≤ β*Real.log n + Real.log Q + Real.log (8/a) := by - have hl : 0 < a*n^(-β)/(8*Q) := by positivity - have hu : 0 < u := hl.trans_le hbound - have h := Real.log_le_log hl hbound - rw [Real.log_div (mul_pos ha (Real.rpow_pos_of_pos hn _)).ne' (mul_pos (by norm_num) hQ).ne', - Real.log_mul ha.ne' (Real.rpow_pos_of_pos hn _).ne',Real.log_rpow hn, - Real.log_mul (by norm_num : (8:ℝ) ≠ 0) hQ.ne'] at h - rw [one_div,Real.log_inv,Real.log_div (by norm_num : (8:ℝ) ≠ 0) ha.ne'] - linarith - -theorem log_inv_norm_ge (r r' : ℝ) (k : ℕ) (hr : 0 < r) (hr' : 0 < r') - (hbound : r' ≤ 2*r^k) : - (k:ℝ)*Real.log (1/r) - Real.log 2 ≤ Real.log (1/r') := by - have h := Real.log_le_log hr' hbound - rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) (pow_pos hr _).ne',Real.log_pow] at h - simp only [one_div,Real.log_inv] - linarith - - - -theorem eventually_amplification_log_estimates (T ξ β H : ℝ) - (hT : 0 < T) (hξ : 0 < ξ) (hξ1 : ξ < 1) (hH : 0 < H) - (M d : ℕ) (c a b : ℝ) (ha : 0 < a) (hb : 0 ≤ b) : - ∀ᶠ n : ℕ in atTop, - let k := logarithmicChainLength T n - β*Real.log n + Real.log (amplificationMomentFactor k M d c a b) + Real.log (8/a) ≤ - (k:ℝ)*(β+ξ)*T ∧ - Real.log ((2*n+k*M:ℕ):ℝ) ≤ (k:ℝ)*(1+ξ)*T ∧ - (k:ℝ)*(1-ξ)*H ≤ (k:ℝ)*H-Real.log 2 ∧ - 2*H ≤ (k:ℝ)*(1-ξ)*H ∧ 1 ≤ k := by - let k := logarithmicChainLength T - have hk : Tendsto k atTop atTop := tendsto_logarithmicChainLength T hT - have hkR : Tendsto (fun n => (k n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp hk - have hU : Tendsto (fun n : ℕ => - (β*Real.log n + Real.log (amplificationMomentFactor (k n) M d c a b) + Real.log (8/a))/(k n:ℝ)) - atTop (nhds (β*T)) := by - have h1 := (tendsto_log_div_chainLength T hT).const_mul β - have h2 := (tendsto_log_amplificationMomentFactor_div M d c a b ha hb).comp hk - have h3 := (tendsto_const_nhds (x := Real.log (8/a))).div_atTop hkR - simpa only [add_zero,add_div,mul_div_assoc,Function.comp_def] using (h1.add h2).add h3 - have hm : Tendsto (fun n : ℕ => (Real.log n+Real.log 3)/(k n:ℝ)) atTop (nhds T) := by - simpa only [add_zero,add_div] using (tendsto_log_div_chainLength T hT).add - ((tendsto_const_nhds (x := Real.log 3)).div_atTop hkR) - have hHlim : Tendsto (fun n : ℕ => Real.log 2/(k n:ℝ)) atTop (nhds 0) := - tendsto_const_nhds.div_atTop hkR - have hU' := (tendsto_order.mp hU).2 ((β+ξ)*T) (by nlinarith) - have hm' := (tendsto_order.mp hm).2 ((1+ξ)*T) (by nlinarith) - have hH' := (tendsto_order.mp hHlim).2 (ξ*H) (mul_pos hξ hH) - filter_upwards [hU',hm',hH',hkR.eventually_ge_atTop (2/(1-ξ)), - hk.eventually_ge_atTop 1,eventually_ge_atTop (1:ℕ),eventually_chain_volume_small T hT M] - with n hUn hmn hHn hklarge hk1 hn hvol - have hkp : (0:ℝ) < k n := by exact_mod_cast (show 0 < k n by omega) - have hnp : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) - have hcap : (2*n+k n*M:ℕ) ≤ 3*n := by - dsimp [k] at * - rw [Nat.mul_assoc] at hvol - omega - have hcap0 : (0:ℝ) < (2*n+k n*M:ℕ) := by exact_mod_cast (show 0 < 2*n+k n*M by omega) - refine ⟨?_,?_,?_,?_,hk1⟩ - · have h := (div_lt_iff₀ hkp).mp hUn - nlinarith only [h] - · calc - _ ≤ Real.log (3*(n:ℝ)) := Real.log_le_log hcap0 (by exact_mod_cast hcap) - _ = Real.log n + Real.log 3 := by rw [Real.log_mul (by norm_num : (3:ℝ) ≠ 0) hnp.ne']; ring - _ ≤ _ := by have h := (div_lt_iff₀ hkp).mp hmn; nlinarith only [h] - · have h := (div_lt_iff₀ hkp).mp hHn - nlinarith only [h] - · have h := (div_le_iff₀ (sub_pos.mpr hξ1)).mp hklarge - have hh := mul_le_mul_of_nonneg_right h hH.le - nlinarith only [hh] - -end AmplificationLogEstimates -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section AsymptoticAmplificationStep -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem asymptotic_amplification_step [Nonempty V] [Nonempty E] - (hconn : Connected G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (p : unitInterval) (hp : (p:ℝ) < 1) (d : ℕ) (hdeg : ∀ x, degree G x ≤ d) - (hu : 0 < q.successProbability p (root i₀)) - (a b β ε ξ T : ℝ) (ha : 0 < a) (hb : 0 ≤ b) - (hε : 0 < ε) (hε1 : ε < 1/2) (hξ : 0 < ξ) (hξ1 : ξ < 1) (hT : 0 < T) - (hbudget : inverseCodeMass M L ≤ q.successProbability p (root i₀)*Real.exp T) - (A : Hilbert V →L[ℂ] Hilbert V) (hApos : 0 < ‖A‖) - (hH : 0 < Real.log (1/‖A‖)) - (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : - ∀ᶠ n : ℕ in atTop, ∀ π : ℝ, - (n:ℝ)^(-β) ≤ π → - a*n*π ≤ binOrbitRow G p (root i₀) n → - clusterWindowProbability G p (root i₀) (n-logarithmicChainLength T n*M) (2*n) ≤ b*π → - ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) - (2*n+logarithmicChainLength T n*M) (((2*n+logarithmicChainLength T n*M:ℕ):ℝ)^(1/2+ε)), - 0 < q'.successProbability p (root i₀) ∧ - Real.log (1/q'.successProbability p (root i₀)) ≤ (logarithmicChainLength T n:ℝ)*(β+ξ)*T ∧ - Real.log ((2*n+logarithmicChainLength T n*M:ℕ):ℝ) ≤ (logarithmicChainLength T n:ℝ)*(1+ξ)*T ∧ - ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ - (logarithmicChainLength T n:ℝ)*(1-ξ)*Real.log (1/‖A‖) ≤ Real.log (1/‖A'‖) ∧ - 2*Real.log (1/‖A‖) ≤ Real.log (1/‖A'‖) ∧ - (∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ)) ∧ - 1 ≤ logarithmicChainLength T n := by - let k := logarithmicChainLength T - let cap := fun n => 2*n+k n*M - have hcap : Tendsto cap atTop atTop := - tendsto_atTop_mono (fun n => show n ≤ cap n by dsimp [cap]; omega) tendsto_id - have hgood := hcap.eventually (bad_goodness_stretched_exp G hloc hqt p hp ε hε hε1) - have hdecay := eventually_amplification_goodness_decay T hT M d c a b β ε ha hb hε - have hlogs := eventually_amplification_log_estimates T ξ β (Real.log (1/‖A‖)) - hT hξ hξ1 hH M d c a b ha hb - filter_upwards [hgood,hdecay,hlogs,eventually_ge_atTop (1:ℕ)] with n hgood hdecay hlogs hn - intro π hπ hbin hwindow - have hn0 : 0 < n := by omega - have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn0 - have hπ0 : 0 < π := (Real.rpow_pos_of_pos hnR (-β)).trans_le hπ - have hQ : 0 < amplificationMomentFactor (k n) M d c a b := amplificationMomentFactor_pos _ _ _ _ _ _ ha hb - have hcoden : inverseCodeMass M L^(k n) ≤ n*q.successProbability p (root i₀)^(k n) := by - apply code_bound_of_logarithmic_chain _ _ _ hu _ hT hbudget n hn - unfold inverseCodeMass - exact add_nonneg zero_le_one (Finset.sum_nonneg (fun l _ => gapWeight_nonneg L (by linarith) l)) - have hbad : 16*amplificationMomentFactor (k n) M d c a b * - (law p).real {ω | CappedBadGoodness G ω (root i₀) (cap n) ((cap n:ℝ)^(1/2+ε))} ≤ a*π := by - calc - _ ≤ 16*amplificationMomentFactor (k n) M d c a b * Real.exp (-(cap n:ℝ)^ε) := - mul_le_mul_of_nonneg_left (hgood (root i₀) p le_rfl) (by positivity) - _ ≤ a*(n:ℝ)^(-β) := hdecay - _ ≤ _ := mul_le_mul_of_nonneg_left hπ ha.le - obtain ⟨q',hup,A',hAp,hAr,hA'⟩ := q.quantitative_amplification_step hconn root weight Γ hΓ htr hcov - hw hw1 c hc hmin i₀ hw₀ hL p (k n) n d hn0 hdeg hu a b π ((cap n:ℝ)^(1/2+ε)) - ha hb hπ0 hbin hwindow hcoden hbad A hA - have hup0 : 0 < q'.successProbability p (root i₀) := (by positivity : 0 < a*π/(8*amplificationMomentFactor (k n) M d c a b)).trans_le hup - have hulo : a*(n:ℝ)^(-β)/(8*amplificationMomentFactor (k n) M d c a b) ≤ q'.successProbability p (root i₀) := by - apply le_trans _ hup - exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hπ ha.le) (by positivity) - have hulo' := log_inv_success_le a (amplificationMomentFactor (k n) M d c a b) (n:ℝ) β - (q'.successProbability p (root i₀)) ha hQ hnR hulo - have hH' := log_inv_norm_ge ‖A‖ ‖A'‖ (k n) hApos hAp hAr - exact ⟨q',hup0,hulo'.trans hlogs.1,hlogs.2.1,A',hAp,hlogs.2.2.1.trans hH', - hlogs.2.2.2.1.trans (hlogs.2.2.1.trans hH'),hA',hlogs.2.2.2.2⟩ - -end LocalEndpointRule -end AsymptoticAmplificationStep -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section WeightedScaleWindow -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem weightedWindowProbability_term_le {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (i : ι) (a b : ℕ) : - weight i * clusterWindowProbability G p (root i) a b ≤ weightedWindowProbability G p root weight a b := - Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (clusterWindowProbability_nonneg G p (root j) a b)) (Finset.mem_univ i) - -theorem orbit_scale_window_bound {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (i : ι) (hi : 0 < weight i) - (j k M : ℕ) (hvol : 2*k*M ≤ 2^(j+1)) (β π : ℝ) - (hwindow : weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ (1+(2:ℝ)^β)*π) : - clusterWindowProbability G p (root i) (2^(j+1)-k*M) (2*2^(j+1)) ≤ - ((1+(2:ℝ)^β)/weight i)*π := by - have he : 2^(j+1) = 2*2^j := by rw [pow_succ]; omega - have he' : 2*2^(j+1) = 2^(j+2) := by rw [show j+2 = (j+1)+1 by omega,pow_succ]; omega - have hl : 2^j ≤ 2^(j+1)-k*M := by - rw [he,Nat.mul_assoc] at hvol - rw [he] - omega - have hmono := clusterWindowProbability_mono G p (root i) hl (le_of_eq he') - have hterm := weightedWindowProbability_term_le G p root weight hw i (2^j) (2^(j+2)) - have hb := (mul_le_mul_of_nonneg_left hmono hi.le).trans (hterm.trans hwindow) - rw [div_mul_eq_mul_div] - exact (le_div_iff₀ hi).mpr (by simpa only [mul_comm] using hb) - -theorem tendsto_dyadic_scale : Tendsto (fun j : ℕ => 2^(j+1)) atTop atTop := - tendsto_atTop_mono (fun j => (Nat.le_succ j).trans (j+1).lt_two_pow_self.le) tendsto_id - -end WeightedScaleWindow -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section EndpointProfile - - - -structure EndpointProfile (G : BondGraph V E) (hloc : LocallyFinite G) - (p : unitInterval) (o : V) (s : ℝ) where - cap : ℕ - rule : LocalEndpointRule G hloc (vertexOrbit G o) cap ((cap:ℝ)^s) - success_pos : 0 < rule.successProbability p o - op : Hilbert V →L[ℂ] Hilbert V - norm_pos : 0 < ‖op‖ - coeff : ∀ x y, matrixCoeff op x y = (rule.normalizedKernel o p x y : ℂ) - -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} {p : unitInterval} {o : V} {s : ℝ} - -noncomputable def U (q : EndpointProfile G hloc p o s) : ℝ := Real.log (1/q.rule.successProbability p o) -noncomputable def m (q : EndpointProfile G hloc p o s) : ℝ := Real.log q.cap -noncomputable def H (q : EndpointProfile G hloc p o s) : ℝ := Real.log (1/‖q.op‖) -noncomputable def cost (q : EndpointProfile G hloc p o s) (ξ : ℝ) : ℝ := q.U+(s+ξ)*q.m - -theorem U_nonneg (q : EndpointProfile G hloc p o s) : 0 ≤ q.U := by - unfold U - rw [one_div,Real.log_inv] - have h := Real.log_nonpos q.success_pos.le (q.rule.successProbability_le_one p o) - linarith - -theorem m_pos (q : EndpointProfile G hloc p o s) (hcap : 2 ≤ q.cap) : 0 < q.m := by - exact Real.log_pos (by exact_mod_cast (show 1 < q.cap by omega)) - -theorem cost_pos (q : EndpointProfile G hloc p o s) (hcap : 2 ≤ q.cap) - (ξ : ℝ) (hsξ : 0 < s+ξ) : 0 < q.cost ξ := by - exact add_pos_of_nonneg_of_pos q.U_nonneg (mul_pos hsξ (q.m_pos hcap)) - -theorem exp_cost_identity (q : EndpointProfile G hloc p o s) (hcap : 0 < q.cap) (ξ : ℝ) : - q.rule.successProbability p o * Real.exp (q.cost ξ) = (q.cap:ℝ)^(s+ξ) := by - have hcp : (0:ℝ) < q.cap := Nat.cast_pos.mpr hcap - simp only [cost,U,m,Real.exp_add,Real.exp_log (one_div_pos.mpr q.success_pos)] - calc - _ = Real.exp ((s+ξ)*Real.log q.cap) := by field_simp [ne_of_gt q.success_pos] - _ = _ := by rw [Real.rpow_def_of_pos hcp]; congr 1; ring - -end EndpointProfile - -variable [Countable V] [Countable E] [Nonempty V] - -theorem starting_endpoint_profile (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (M₀ : ℕ) : - ∃ q : EndpointProfile G hloc p (root i₀) (1/2+ε), M₀ ≤ q.cap ∧ 1 < q.H := by - obtain ⟨M,hM,q,hq,A,hAp,hAn,hA⟩ := nonamenable_starting_endpoint_rule G hloc hqt hh p hp hp1 - root weight Γ hΓ htr hw hw1 i₀ hw₀ hfin ε hε hε1 (Real.exp (-2)) (Real.exp_pos _) M₀ - refine ⟨⟨M,q,hq,A,hAp,hA⟩,hM,?_⟩ - have h := Real.log_lt_log hAp hAn - rw [Real.log_exp] at h - change 1 < Real.log (1/‖A‖) - rw [one_div,Real.log_inv] - linarith - -end EndpointProfile - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section EndpointProfileStep -attribute [local instance] Classical.propDecidable Classical.decEq - -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} - -theorem amplify_at_scales [Nonempty V] [Nonempty E] - (hconn : Connected G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i : ι) (p : unitInterval) (hp : (p:ℝ) < 1) - (d : ℕ) (hdeg : ∀ x, degree G x ≤ d) - (ε ξ β : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (hξ : 0 < ξ) (hξ1 : ξ < 1) - (hscales : ∀ N, ∃ j, N ≤ j ∧ - ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ - weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ - (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ - (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ - binOrbitRow G p (root i) (2^(j+1))) - (q : EndpointProfile G hloc p (root i) (1/2+ε)) (hM : 2 ≤ q.cap) - (hL : 1 ≤ (q.cap:ℝ)^(1/2+ε)) - (hbudget : inverseCodeMass q.cap ((q.cap:ℝ)^(1/2+ε)) ≤ (q.cap:ℝ)^(1/2+ε+ξ)) - (hH : 0 < q.H) (N : ℕ) : - ∃ (q' : EndpointProfile G hloc p (root i) (1/2+ε)) (k : ℕ), - N ≤ q'.cap ∧ 1 ≤ k ∧ - q'.U ≤ (k:ℝ)*(β+ξ)*q.cost ξ ∧ - q'.m ≤ (k:ℝ)*(1+ξ)*q.cost ξ ∧ - (k:ℝ)*(1-ξ)*q.H ≤ q'.H ∧ 2*q.H ≤ q'.H := by - let a : ℝ := 1/Fintype.card ι - let b : ℝ := (1+(2:ℝ)^β)/weight i - let T := q.cost ξ - have ht : 0 < T := q.cost_pos hM ξ (by linarith) - have hcard : (0:ℝ) < Fintype.card ι := by - exact_mod_cast (Fintype.card_pos_iff.mpr ⟨i⟩) - have ha : 0 < a := one_div_pos.mpr hcard - have hb : 0 ≤ b := div_nonneg (by positivity) (hw i).le - have hbudget' : inverseCodeMass q.cap ((q.cap:ℝ)^(1/2+ε)) ≤ - q.rule.successProbability p (root i)*Real.exp T := by - rw [q.exp_cost_identity (by omega) ξ] - exact hbudget - have hstep := q.rule.asymptotic_amplification_step hconn hqt root weight Γ hΓ htr hcov - (fun i => (hw i).le) hw1 c hc hmin i (hw i) hL p hp d hdeg q.success_pos - a b β ε ξ T ha hb hε hε1 hξ hξ1 ht hbudget' q.op q.norm_pos hH q.coeff - have hvol := eventually_chain_volume_small T ht q.cap - have he := tendsto_dyadic_scale.eventually (hstep.and (hvol.and (eventually_ge_atTop N))) - obtain ⟨J,hJ⟩ := eventually_atTop.1 he - obtain ⟨j,hj,hπ,hwide,hbin⟩ := hscales J - obtain ⟨hs,hvol,hN⟩ := hJ j hj - have hwin := orbit_scale_window_bound G p root weight (fun i => (hw i).le) i (hw i) - j (logarithmicChainLength T (2^(j+1))) q.cap hvol β _ hwide - have hbin' : a*(2^(j+1):ℕ)*dyadicBinProbability G p root weight (j+1) ≤ - binOrbitRow G p (root i) (2^(j+1)) := by - dsimp [a] - simpa only [div_eq_mul_inv,one_mul,mul_comm (_⁻¹)] using hbin - obtain ⟨q',hup,hU,hm,A',hAp,hH',hH'',hA',hk⟩ := hs _ hπ hbin' hwin - refine ⟨⟨_,q',hup,A',hAp,hA'⟩,_,?_,hk,hU,hm,hH',hH''⟩ - change N ≤ 2*2^(j+1)+logarithmicChainLength T (2^(j+1))*q.cap - omega - -end EndpointProfile -end EndpointProfileStep - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open Filter -section AmplificationContraction - -noncomputable def amplificationContraction (β s ξ : ℝ) : ℝ := - (β+ξ+(s+ξ)*(1+ξ))/(1-ξ) - -theorem exists_amplification_contraction (β s : ℝ) (hβ : 0 ≤ β) (hs : 0 ≤ s) - (hsmall : β+s < 1) : ∃ ξ : ℝ, 0 < ξ ∧ ξ < 1 ∧ - 0 ≤ amplificationContraction β s ξ ∧ amplificationContraction β s ξ < 1 := by - have hd : 0 < 4+s := by linarith - have hδ : 0 < (1-(β+s))/(4+s) := div_pos (by linarith) hd - obtain ⟨ξ,hξ,hξupper⟩ := exists_between (lt_min zero_lt_one hδ) - have hξ1 := hξupper.trans_le (min_le_left _ _) - have hprod : ξ*(4+s) < 1-(β+s) := (lt_div_iff₀ hd).mp (hξupper.trans_le (min_le_right _ _)) - have hx2 : ξ^2 < ξ := by nlinarith [mul_pos hξ (sub_pos.mpr hξ1)] - refine ⟨ξ,hξ,hξ1,?_,?_⟩ - · unfold amplificationContraction - positivity - · unfold amplificationContraction - apply (div_lt_one (by linarith : 0 < 1-ξ)).mpr - nlinarith - - - -theorem amplification_cost_contraction (t t' H H' β s ξ : ℝ) (k : ℕ) - (ht : 0 ≤ t) (hH : 0 < H) (hξ1 : ξ < 1) (hk : 1 ≤ k) - (hC : 0 ≤ amplificationContraction β s ξ) - (ht' : t' ≤ (k:ℝ)*(β+ξ+(s+ξ)*(1+ξ))*t) - (hH' : (k:ℝ)*(1-ξ)*H ≤ H') : - t'/H' ≤ amplificationContraction β s ξ*(t/H) := by - have hk0 : (0:ℝ) < k := by exact_mod_cast (show 0 < k by omega) - have hd : 0 < (k:ℝ)*(1-ξ)*H := mul_pos (mul_pos hk0 (by linarith)) hH - have hH'p := hd.trans_le hH' - apply (div_le_iff₀ hH'p).mpr - have he : (k:ℝ)*(β+ξ+(s+ξ)*(1+ξ))*t = - amplificationContraction β s ξ*(t/H)*((k:ℝ)*(1-ξ)*H) := by - unfold amplificationContraction - field_simp [hH.ne', (sub_pos.mpr hξ1).ne'] - rw [he] at ht' - exact ht'.trans (mul_le_mul_of_nonneg_left hH' (mul_nonneg hC (div_nonneg ht hH.le))) - -namespace EndpointProfile -variable {G : BondGraph V E} {hloc : LocallyFinite G} {p : unitInterval} {o : V} {s : ℝ} - -theorem cost_contraction (q q' : EndpointProfile G hloc p o s) (β ξ : ℝ) (k : ℕ) - (hM : 2 ≤ q.cap) (hsξ : 0 < s+ξ) (hH : 0 < q.H) (hξ1 : ξ < 1) (hk : 1 ≤ k) - (hC : 0 ≤ amplificationContraction β s ξ) - (hU : q'.U ≤ (k:ℝ)*(β+ξ)*q.cost ξ) - (hm : q'.m ≤ (k:ℝ)*(1+ξ)*q.cost ξ) - (hH' : (k:ℝ)*(1-ξ)*q.H ≤ q'.H) : - q'.cost ξ/q'.H ≤ amplificationContraction β s ξ*(q.cost ξ/q.H) := by - apply amplification_cost_contraction _ _ _ _ β s ξ k (q.cost_pos hM ξ hsξ).le hH hξ1 hk hC _ hH' - unfold cost at * - have hh := mul_le_mul_of_nonneg_left hm hsξ.le - nlinarith only [hU,hh] - -theorem total_cost_le (q : EndpointProfile G hloc p o s) (hM : 2 ≤ q.cap) - (ξ : ℝ) (hsξ : 0 < s+ξ) : q.U+q.m ≤ (1+1/(s+ξ))*q.cost ξ := by - have hm := (q.m_pos hM).le - have hU := q.U_nonneg - have hU' : q.U ≤ q.cost ξ := by unfold cost; nlinarith - have hm' : q.m ≤ q.cost ξ/(s+ξ) := by - apply (le_div_iff₀ hsξ).mpr - unfold cost - nlinarith - calc - _ ≤ q.cost ξ+q.cost ξ/(s+ξ) := add_le_add hU' hm' - _ = _ := by ring - -end EndpointProfile -end AmplificationContraction - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Connections + +namespace OAI + +/-! Scale Budget for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section AveragedBinOrbitTransport +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integral_tsum_of_finite_support {α Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (S : Finset α) (f : Ω → α → ℝ) + (hi : ∀ x, Integrable (fun ω => f ω x) μ) + (hs : ∀ ω x, x ∉ S → f ω x = 0) : + (∫ ω, ∑' x, f ω x ∂μ) = ∑' x, ∫ ω, f ω x ∂μ := by + have he (ω) : (∑' x, f ω x) = ∑ x ∈ S, f ω x := tsum_eq_sum (hs ω) + rw [show (∫ ω, ∑' x, f ω x ∂μ) = ∫ ω, ∑ x ∈ S, f ω x ∂μ by simp only [he], + integral_finsetSum _ (fun x _ => hi x),tsum_eq_sum (s := S) (fun x hx => by simp only [hs _ x hx,integral_zero])] + +theorem binOrbitTransportMass_local (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (ω : Set E) (x y : V) : + let Qx := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + let Qy := incidentSupport G hloc (finite_reachBall hloc y (2*n)).toFinset + binOrbitTransportMass G n ω x y = binOrbitTransportMass G n (ω ∩ ((Qx∪Qy : Finset E) : Set E)) x y := by + let Qx := incidentSupport G hloc (finite_reachBall hloc x (2*n)).toFinset + let Qy := incidentSupport G hloc (finite_reachBall hloc y (2*n)).toFinset + have hB := finite_local_of_subset Qx (Qx∪Qy) Finset.subset_union_left + (fun ω => binConnectionMass G n ω x y) (fun ω => binConnectionMass_local G hloc n ω x y) ω + have hq := finite_local_of_subset Qy (Qx∪Qy) Finset.subset_union_right + (fun ω => binOrbitRowMass G n ω y) (fun ω => binOrbitRowMass_local G hloc n ω y) ω + have hs := finite_local_of_subset Qx (Qx∪Qy) Finset.subset_union_left + (fun ω => binSizeMass G n ω x) (fun ω => binSizeMass_local G hloc n ω x) ω + exact congrArg₂ (· / ·) (congrArg₂ (· * ·) hB hq) hs + +theorem binOrbitTransportMass_integrable (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) (x y : V) : Integrable (fun ω => binOrbitTransportMass G n ω x y) (law p) := + integrable_finite_local _ p _ (fun ω => binOrbitTransportMass_local G hloc n ω x y) + +theorem binOrbitTransportMass_outside (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (hy : y ∉ reachBall G x (2*n)) : binOrbitTransportMass G n ω x y = 0 := by + simp only [binOrbitTransportMass,binConnectionMass_outside G n ω x y hy,zero_mul,zero_div] + +noncomputable def binOrbitTransport (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) : ℝ := + ∫ ω, binOrbitTransportMass G n ω x y ∂law p + +theorem binOrbitTransport_covariant (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (n : ℕ) (x y : V) : + binOrbitTransport G p n (a x) (a y) = binOrbitTransport G p n x y := by + have hm : Measurable (fun ω => binOrbitTransportMass G n ω x y) := + measurable_finite_local _ _ (fun ω => binOrbitTransportMass_local G hloc n ω x y) + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable hm.aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [binOrbitTransport,binOrbitTransportMass,binConnectionMass_covariant G hab, + binOrbitRowMass_covariant G n _ hab,binSizeMass_covariant G n _ hab] using h.symm + +theorem binOrbitTransport_outside (G : BondGraph V E) (p : unitInterval) (n : ℕ) (x y : V) + (hy : y ∉ reachBall G x (2*n)) : binOrbitTransport G p n x y = 0 := by + simp only [binOrbitTransport,binOrbitTransportMass_outside G n _ x y hy,integral_zero] + +theorem binOrbitTransportMass_outside_column (G : BondGraph V E) (n : ℕ) (ω : Set E) (x y : V) + (hx : x ∉ reachBall G y (2*n)) : binOrbitTransportMass G n ω x y = 0 := by + have hB : binConnectionMass G n ω x y = 0 := by + rw [binConnectionMass_symm] + exact binConnectionMass_outside G n ω y x hx + simp only [binOrbitTransportMass,hB,zero_mul,zero_div] + +theorem binOrbitTransport_row_integral (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) (x : V) : + (∑' y, binOrbitTransport G p n x y) = ∫ ω, ∑' y, binOrbitTransportMass G n ω x y ∂law p := by + symm + apply integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ + (binOrbitTransportMass_integrable G hloc p n x) + intro ω y hy + exact binOrbitTransportMass_outside G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) + +theorem integral_binOrbitRowMass (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) (x : V) : + (∫ ω, binOrbitRowMass G n ω x ∂law p) = binOrbitRow G p x n := by + have hx : x ∈ vertexOrbit G x := ⟨Equiv.refl _,Equiv.refl _,fun _ => by simp,rfl⟩ + unfold binOrbitRowMass + rw [integral_tsum_of_finite_support (law p) (finite_reachBall hloc x (2*n)).toFinset _ + (fun y => by + by_cases hy : y ∈ vertexOrbit G x + · simp only [ite_eq_left hy] + exact integrable_finite_local _ p _ (fun ω => binConnectionMass_local G hloc n ω x y) + · simp only [ite_eq_right hy]; exact integrable_const (0:ℝ)) + (fun ω y hy => by + have hz := binConnectionMass_outside G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) + simp only [hz,ite_self])] + apply tsum_congr + intro y + by_cases hy : y ∈ vertexOrbit G x + · simp only [orbitBinConnection,hx,hy,true_and,ite_true,binConnection] + · simp only [orbitBinConnection,hy,and_false,ite_false,integral_zero] + +theorem binOrbitTransport_column (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (n : ℕ) (hn : 0 < n) (y : V) : + (∑' x, binOrbitTransport G p n x y) = binOrbitRow G p y n := by + rw [←integral_binOrbitRowMass G hloc p n y,←show (∫ ω, ∑' x, binOrbitTransportMass G n ω x y ∂law p) = + ∑' x, binOrbitTransport G p n x y from + integral_tsum_of_finite_support (law p) (finite_reachBall hloc y (2*n)).toFinset _ + (fun x => binOrbitTransportMass_integrable G hloc p n x y) + (fun ω x hx => binOrbitTransportMass_outside_column G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hx))] + simp only [binOrbitTransportMass_column G n hn] + +end AveragedBinOrbitTransport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedOrbitBinLower +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem binOrbitTransport_row_lower (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (p : unitInterval) (n : ℕ) (hn : 0 < n) (x : V) : + (n:ℝ)/Fintype.card ι * clusterWindowProbability G p x n (2*n) ≤ + ∑' y, binOrbitTransport G p n x y := by + let B := (finite_reachBall hloc x (2*n)).toFinset + have he (ω) : (∑' y, binOrbitTransportMass G n ω x y) = + ∑ y ∈ B, binOrbitTransportMass G n ω x y := by + apply tsum_eq_sum + intro y hy + exact binOrbitTransportMass_outside G n ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + have hi : Integrable (fun ω => ∑' y, binOrbitTransportMass G n ω x y) (law p) := by + simp only [he] + exact integrable_finsetSum B (fun y _ => binOrbitTransportMass_integrable G hloc p n x y) + let W := {ω | ClusterWindow G x n (2*n) ω} + have hm : MeasurableSet W := measurableSet_clusterWindow G hloc x n (2*n) + have hl : Integrable (W.indicator (fun _ => (n:ℝ)/Fintype.card ι)) (law p) := + (integrable_const _).indicator hm + calc + _ = ∫ ω, W.indicator (fun _ => (n:ℝ)/Fintype.card ι) ω ∂law p := by + rw [integral_indicator_const _ hm] + simp only [smul_eq_mul,clusterWindowProbability,W,mul_comm] + _ ≤ ∫ ω, ∑' y, binOrbitTransportMass G n ω x y ∂law p := by + apply integral_mono hl hi + intro ω + exact binOrbitTransportMass_row G root hcover n hn ω x + _ = _ := (binOrbitTransport_row_integral G hloc p n x).symm + + + +theorem weighted_binOrbitRow_lower (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (p : unitInterval) (n : ℕ) (hn : 0 < n) : + (n:ℝ)/Fintype.card ι * (∑ i, weight i * clusterWindowProbability G p (root i) n (2*n)) ≤ + ∑ i, weight i * binOrbitRow G p (root i) n := by + have hr (x : V) : Summable (binOrbitTransport G p n x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x (2*n)).toFinset) + intro y hy + exact binOrbitTransport_outside G p n x y (by simpa only [Set.Finite.mem_toFinset] using hy) + have hc (y : V) : Summable (fun x => binOrbitTransport G p n x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y (2*n)).toFinset) + intro x hx + have hz (ω) := binOrbitTransportMass_outside_column G n ω x y (by simpa only [Set.Finite.mem_toFinset] using hx) + simp only [binOrbitTransport,hz,integral_zero] + have ht := htr.real root weight Γ (binOrbitTransport G p n) + (fun a ha x y => by obtain ⟨b,hab⟩ := hΓ ha; exact binOrbitTransport_covariant G hloc p hab n x y) hr hc + calc + _ = ∑ i, weight i * ((n:ℝ)/Fintype.card ι * clusterWindowProbability G p (root i) n (2*n)) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + ring + _ ≤ ∑ i, weight i * ∑' y, binOrbitTransport G p n (root i) y := + Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (binOrbitTransport_row_lower G hloc root hcover p n hn (root i)) (hw i)) + _ = ∑ i, weight i * ∑' x, binOrbitTransport G p n x (root i) := ht + _ = _ := by simp only [binOrbitTransport_column G hloc p n hn] + +theorem exists_binOrbitRow_lower (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) + (p : unitInterval) (n : ℕ) (hn : 0 < n) : + ∃ i, (n:ℝ)/Fintype.card ι * (∑ j, weight j * clusterWindowProbability G p (root j) n (2*n)) ≤ + binOrbitRow G p (root i) n := by + have h := weighted_binOrbitRow_lower G hloc root weight Γ hΓ htr (fun i => (hw i).le) hcover p n hn + by_contra! he + let c := (n:ℝ)/Fintype.card ι * (∑ j, weight j * clusterWindowProbability G p (root j) n (2*n)) + have hs : (∑ i, weight i * binOrbitRow G p (root i) n) < ∑ i, weight i*c := by + apply Finset.sum_lt_sum (fun i _ => (mul_lt_mul_of_pos_left (he i) (hw i)).le) + exact ⟨Classical.arbitrary ι,Finset.mem_univ _,mul_lt_mul_of_pos_left (he _) (hw _)⟩ + rw [←Finset.sum_mul,hw1,one_mul] at hs + exact (not_lt_of_ge h) hs + +end WeightedOrbitBinLower + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DyadicRecords +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem summable_dyadic_of_scaled_bound (π : ℕ → ℝ) (hπ : ∀ j, 0 ≤ π j) + (α β C : ℝ) (hαβ : α < β) + (hC : ∀ j : ℕ, (2:ℝ)^(β*(j:ℝ))*π j ≤ C) : + Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*π j) := by + let r := (2:ℝ)^(α-β) + have hr0 : 0 ≤ r := Real.rpow_nonneg (by norm_num) _ + have hr1 : r < 1 := Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (sub_neg.mpr hαβ) + have hs := (summable_geometric_of_lt_one hr0 hr1).mul_left C + apply hs.of_nonneg_of_le (fun j => mul_nonneg (Real.rpow_nonneg (by norm_num) _) (hπ j)) + intro j + have he : (2:ℝ)^(α*(j:ℝ)) = r^j * (2:ℝ)^(β*(j:ℝ)) := by + rw [show r^j = (2:ℝ)^((α-β)*(j:ℝ)) by rw [Real.rpow_mul (by norm_num),Real.rpow_natCast], + ←Real.rpow_add (by norm_num)] + congr 1 + ring + rw [he,mul_assoc] + exact (mul_le_mul_of_nonneg_left (hC j) (pow_nonneg hr0 j)).trans_eq (mul_comm _ _) + +theorem unbounded_scaled_dyadic (π : ℕ → ℝ) (hπ : ∀ j, 0 ≤ π j) + (α β : ℝ) (hαβ : α < β) + (hdiv : ¬ Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*π j)) : + ∀ C : ℝ, ∃ j : ℕ, C < (2:ℝ)^(β*(j:ℝ))*π j := by + intro C + by_contra! hC + exact hdiv (summable_dyadic_of_scaled_bound π hπ α β C hαβ hC) + + +theorem late_record_of_unbounded (f : ℕ → ℝ) (hf : ∀ C : ℝ, ∃ j, C < f j) (N : ℕ) : + ∃ j, N < j ∧ 1 ≤ f j ∧ ∀ i ≤ j, f i ≤ f j := by + obtain ⟨a,ha,hamax⟩ := (Finset.range (N+1)).exists_max_image f ⟨0,by simp⟩ + obtain ⟨b,hb⟩ := hf (max 1 (f a)) + obtain ⟨j,hj,hjmax⟩ := (Finset.range (b+1)).exists_max_image f ⟨0,by simp⟩ + have hb' : max 1 (f a) < f j := hb.trans_le (hjmax b (by simp)) + refine ⟨j,?_,(le_max_left _ _).trans hb'.le,?_⟩ + · by_contra! hjN + have he := hamax j (Finset.mem_range.mpr (by omega)) + exact (not_lt_of_ge he) ((le_max_right _ _).trans_lt hb') + · intro i hi + exact hjmax i (Finset.mem_range.mpr (by have := Finset.mem_range.mp hj; omega)) + + + +theorem finite_family_unbounded_choice {ι : Type*} [Fintype ι] + (P : ι → ℕ → Prop) (h : ∀ N, ∃ j, N ≤ j ∧ ∃ i, P i j) : + ∃ i, ∀ N, ∃ j, N ≤ j ∧ P i j := by + by_contra! hnot + choose L hL using hnot + obtain ⟨j,hj,i,hi⟩ := h (∑ i, L i) + have hLi : L i ≤ ∑ t, L t := Finset.single_le_sum (fun t _ => Nat.zero_le (L t)) (Finset.mem_univ i) + exact hL i j (hLi.trans hj) hi + +theorem record_dyadic_bounds (π : ℕ → ℝ) (β : ℝ) (j : ℕ) + (hrec : ∀ i ≤ j+1, (2:ℝ)^(β*(i:ℝ))*π i ≤ (2:ℝ)^(β*((j+1:ℕ):ℝ))*π (j+1)) + (h1 : 1 ≤ (2:ℝ)^(β*((j+1:ℕ):ℝ))*π (j+1)) : + (2:ℝ)^(-β*((j+1:ℕ):ℝ)) ≤ π (j+1) ∧ π j ≤ (2:ℝ)^β*π (j+1) := by + have hpos : 0 < (2:ℝ)^(β*((j+1:ℕ):ℝ)) := Real.rpow_pos_of_pos (by norm_num) _ + have hinv : (2:ℝ)^(-β*((j+1:ℕ):ℝ)) = 1/(2:ℝ)^(β*((j+1:ℕ):ℝ)) := by + rw [show -β*((j+1:ℕ):ℝ) = -(β*((j+1:ℕ):ℝ)) by ring,Real.rpow_neg (by norm_num)] + simp only [one_div] + refine ⟨?_,?_⟩ + · rw [hinv] + exact (div_le_iff₀ hpos).mpr (by simpa only [mul_comm] using h1) + · have hr := hrec j (by omega) + have he : (2:ℝ)^(β*((j+1:ℕ):ℝ)) = (2:ℝ)^(β*(j:ℝ))*(2:ℝ)^β := by + rw [Nat.cast_add,Nat.cast_one,mul_add,mul_one,Real.rpow_add (by norm_num)] + rw [he,mul_assoc] at hr + exact (mul_le_mul_iff_right₀ (Real.rpow_pos_of_pos (by norm_num : (0:ℝ)<2) _)).mp hr + +end DyadicRecords + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section OrbitDyadicScales +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem clusterWindowProbability_split (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x : V) (a b c : ℕ) (hab : a ≤ b) (hbc : b ≤ c) : + clusterWindowProbability G p x a c = clusterWindowProbability G p x a b + clusterWindowProbability G p x b c := by + have he : {ω | ClusterWindow G x a c ω} = + {ω | ClusterWindow G x a b ω} ∪ {ω | ClusterWindow G x b c ω} := by + ext ω + simp only [Set.mem_ofPred_eq,Set.mem_union,ClusterWindow] + constructor + · rintro ⟨hf,ha,hc⟩ + by_cases hb : (cluster G ω x).ncard < b + · exact Or.inl ⟨hf,ha,hb⟩ + · exact Or.inr ⟨hf,by omega,hc⟩ + · rintro (⟨hf,ha,hb⟩|⟨hf,hb,hc⟩) + · exact ⟨hf,ha,hb.trans_le hbc⟩ + · exact ⟨hf,hab.trans hb,hc⟩ + have hd : Disjoint {ω | ClusterWindow G x a b ω} {ω | ClusterWindow G x b c ω} := by + apply Set.disjoint_left.mpr + intro ω h₁ h₂ + exact (not_lt_of_ge h₂.2.1) h₁.2.2 + unfold clusterWindowProbability + rw [he,measureReal_union hd (measurableSet_clusterWindow G hloc x b c)] + +noncomputable def weightedWindowProbability {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) (a b : ℕ) : ℝ := + ∑ i, weight i * clusterWindowProbability G p (root i) a b + +theorem weightedWindowProbability_nonneg {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (a b : ℕ) : + 0 ≤ weightedWindowProbability G p root weight a b := by + exact Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (clusterWindowProbability_nonneg G p (root i) a b)) + +theorem weightedWindowProbability_split {ι : Type*} [Fintype ι] + (G : BondGraph V E) (hloc : LocallyFinite G) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) + (a b c : ℕ) (hab : a ≤ b) (hbc : b ≤ c) : + weightedWindowProbability G p root weight a c = + weightedWindowProbability G p root weight a b + weightedWindowProbability G p root weight b c := by + simp only [weightedWindowProbability,clusterWindowProbability_split G hloc p _ a b c hab hbc, + mul_add,Finset.sum_add_distrib] + +noncomputable def dyadicBinProbability {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) (j : ℕ) : ℝ := + weightedWindowProbability G p root weight (2^j) (2^(j+1)) + + + +theorem orbit_dyadic_scales (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (p : unitInterval) + (α β : ℝ) (hαβ : α < β) + (hdiv : ¬ Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*dyadicBinProbability G p root weight j)) : + ∃ i, ∀ N, ∃ j, N ≤ j ∧ + ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ + weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ + (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ + (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ + binOrbitRow G p (root i) (2^(j+1)) := by + let π := dyadicBinProbability G p root weight + let f := fun j : ℕ => (2:ℝ)^(β*(j:ℝ))*π j + have hπ : ∀ j, 0 ≤ π j := fun j => weightedWindowProbability_nonneg G p root weight (fun i => (hw i).le) _ _ + have hf := unbounded_scaled_dyadic π hπ α β hαβ hdiv + let P := fun i j => 1 ≤ f (j+1) ∧ (∀ t ≤ j+1, f t ≤ f (j+1)) ∧ + (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*π (j+1) ≤ binOrbitRow G p (root i) (2^(j+1)) + have hpick : ∀ N, ∃ j, N ≤ j ∧ ∃ i, P i j := by + intro N + obtain ⟨t,ht,h1,hr⟩ := late_record_of_unbounded f hf N + obtain ⟨j,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : t ≠ 0) + obtain ⟨i,hi⟩ := exists_binOrbitRow_lower G hloc root weight Γ hΓ htr hw hw1 hcover p (2^(j+1)) (by positivity) + have he : 2*2^(j+1) = 2^(j+2) := by rw [show j+2 = (j+1)+1 by omega,pow_succ]; omega + refine ⟨j,by omega,i,h1,hr,?_⟩ + simpa only [P,π,dyadicBinProbability,weightedWindowProbability,he] using hi + obtain ⟨i,hi⟩ := finite_family_unbounded_choice P hpick + refine ⟨i,?_⟩ + intro N + obtain ⟨j,hj,h1,hr,hb⟩ := hi N + have hs := record_dyadic_bounds π β j hr h1 + refine ⟨j,hj,?_,?_,hb⟩ + · have he : (((2^(j+1):ℕ):ℝ)^(-β)) = (2:ℝ)^(-β*((j+1:ℕ):ℝ)) := by + rw [Nat.cast_pow,Nat.cast_ofNat,←Real.rpow_natCast,←Real.rpow_mul (by norm_num)] + congr 1 + ring + rw [he] + exact hs.1 + · rw [weightedWindowProbability_split G hloc p root weight (2^j) (2^(j+1)) (2^(j+2)) + (Nat.pow_le_pow_right (by norm_num) (by omega)) (Nat.pow_le_pow_right (by norm_num) (by omega))] + change π j + π (j+1) ≤ (1+(2:ℝ)^β)*π (j+1) + nlinarith only [hs.2] + +end OrbitDyadicScales + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ClusterSizeMomentIntegrable +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_cluster_ncard (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + Measurable (fun ω : Set E => (cluster G ω x).ncard) := by + have hm (k : ℕ) (hk : k ≠ 0) : MeasurableSet {ω : Set E | (cluster G ω x).ncard = k} := by + have he : {ω : Set E | (cluster G ω x).ncard = k} = {ω | ClusterWindow G x k (k+1) ω} := by + ext ω + constructor + · intro h + have hf := Set.finite_of_ncard_ne_zero (by rw [h]; exact hk) + exact ⟨hf,by rw [h],by rw [h]; omega⟩ + · rintro ⟨hf,hl,hu⟩ + exact le_antisymm (by omega) hl + rw [he] + exact measurableSet_clusterWindow G hloc x k (k+1) + have hm0 : MeasurableSet {ω : Set E | (cluster G ω x).ncard = 0} := by + have he : {ω : Set E | (cluster G ω x).ncard = 0} = + (⋃ k : ℕ, {ω : Set E | (cluster G ω x).ncard = k+1})ᶜ := by + ext ω + simp only [Set.mem_compl_iff,Set.mem_iUnion,Set.mem_ofPred_eq,not_exists] + constructor + · intro h k + omega + · intro h + by_contra hz + obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero hz + exact h k hk + rw [he] + exact (MeasurableSet.iUnion (fun k => hm (k+1) (by omega))).compl + apply measurable_to_countable + intro ω + change MeasurableSet {ω' | (cluster G ω' x).ncard = (cluster G ω x).ncard} + by_cases h : (cluster G ω x).ncard = 0 + · simpa only [h] using hm0 + · exact hm _ h + + + +theorem integrable_cluster_power_of_dyadic (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (x : V) (α : ℝ) (hα : 0 < α) + (hs : Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p x (2^j) (2^(j+1)))) : + Integrable (fun ω => ((cluster G ω x).ncard:ℝ)^α) (law p) := by + let f := fun ω : Set E => ((cluster G ω x).ncard:ℝ)^α + let F := fun j : ℕ => {ω | ClusterWindow G x (2^j) (2^(j+1)) ω}.indicator + (fun _ => (2:ℝ)^(α*((j+1:ℕ):ℝ))) + have hFm (j : ℕ) : Measurable (F j) := + measurable_const.indicator (measurableSet_clusterWindow G hloc x _ _) + have hFi (j : ℕ) : Integrable (F j) (law p) := + (integrable_const _).indicator (measurableSet_clusterWindow G hloc x _ _) + have hFn (j : ℕ) (ω : Set E) : 0 ≤ F j ω := by + exact Set.indicator_nonneg (fun _ _ => (Real.rpow_pos_of_pos (by norm_num) _).le) _ + have hFe (j : ℕ) : (∫ ω, F j ω ∂law p) = + (2:ℝ)^α * ((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p x (2^j) (2^(j+1))) := by + rw [integral_indicator_const _ (measurableSet_clusterWindow G hloc x _ _)] + simp only [smul_eq_mul,clusterWindowProbability,Nat.cast_add,Nat.cast_one,mul_add,mul_one, + Real.rpow_add (by norm_num : (0:ℝ)<2)] + ring + have hsum : Summable (fun j => ∫ ω, F j ω ∂law p) := by + simp only [hFe] + exact hs.mul_left _ + have hbound (ω : Set E) : ENNReal.ofReal (f ω) ≤ ∑' j, ENNReal.ofReal (F j ω) := by + by_cases hz : (cluster G ω x).ncard = 0 + · simp only [f,hz,Nat.cast_zero,Real.zero_rpow hα.ne',ENNReal.ofReal_zero] + exact bot_le + · let j := Nat.log 2 (cluster G ω x).ncard + have hl := Nat.pow_log_le_self 2 hz + have hu := Nat.lt_pow_succ_log_self (by norm_num : 1 < (2:ℕ)) (cluster G ω x).ncard + have hb : ClusterWindow G x (2^j) (2^(j+1)) ω := + ⟨Set.finite_of_ncard_ne_zero hz,hl,hu⟩ + have hle : f ω ≤ (2:ℝ)^(α*((j+1:ℕ):ℝ)) := by + have hcast : ((cluster G ω x).ncard:ℝ) ≤ ((2^(j+1):ℕ):ℝ) := by exact_mod_cast hu.le + have h := Real.rpow_le_rpow (Nat.cast_nonneg _) hcast hα.le + have he : (((2^(j+1):ℕ):ℝ)^α) = (2:ℝ)^(α*((j+1:ℕ):ℝ)) := by + rw [Nat.cast_pow,Nat.cast_ofNat,←Real.rpow_natCast,←Real.rpow_mul (by norm_num)] + congr 1 + ring + exact h.trans_eq he + have he : F j ω = (2:ℝ)^(α*((j+1:ℕ):ℝ)) := Set.indicator_of_mem (show ω ∈ {ω | ClusterWindow G x (2^j) (2^(j+1)) ω} from hb) _ + exact (ENNReal.ofReal_le_ofReal (hle.trans_eq he.symm)).trans + (ENNReal.le_tsum (f := fun scale => ENNReal.ofReal (F scale ω)) j) + have hfn (ω : Set E) : 0 ≤ f ω := Real.rpow_nonneg (Nat.cast_nonneg _) _ + refine ⟨((measurable_of_countable (fun m : ℕ => (m:ℝ)^α)).comp (measurable_cluster_ncard G hloc x)).aestronglyMeasurable,?_⟩ + apply (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall hfn)).mpr + have hlin : (∫⁻ ω, ∑' j, ENNReal.ofReal (F j ω) ∂law p) < ⊤ := by + rw [lintegral_tsum (fun j => (hFm j).ennreal_ofReal.aemeasurable)] + simp_rw [←ofReal_integral_eq_lintegral_ofReal (hFi _) (Filter.Eventually.of_forall (hFn _))] + rw [←ENNReal.ofReal_tsum_of_nonneg (fun j => integral_nonneg (hFn j)) hsum] + exact ENNReal.ofReal_lt_top + exact (lintegral_mono hbound).trans_lt hlin + +end ClusterSizeMomentIntegrable + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedMomentScales +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem integrable_cluster_power_of_weighted_dyadic (G : BondGraph V E) + (hloc : LocallyFinite G) {ι : Type*} [Fintype ι] (p : unitInterval) + (root : ι → V) (weight : ι → ℝ) (hw : ∀ i, 0 < weight i) + (α : ℝ) (hα : 0 < α) + (hs : Summable (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*dyadicBinProbability G p root weight j)) + (i : ι) : Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p) := by + have hle (j : ℕ) : weight i * clusterWindowProbability G p (root i) (2^j) (2^(j+1)) ≤ + dyadicBinProbability G p root weight j := by + exact Finset.single_le_sum + (fun t _ => mul_nonneg (hw t).le (clusterWindowProbability_nonneg G p (root t) _ _)) + (Finset.mem_univ i) + have hs' : Summable (fun j : ℕ => weight i * + ((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1)))) := by + apply hs.of_nonneg_of_le + · intro j + exact mul_nonneg (hw i).le (mul_nonneg (Real.rpow_nonneg (by norm_num) _) + (clusterWindowProbability_nonneg G p (root i) _ _)) + · intro j + have h := mul_le_mul_of_nonneg_left (hle j) (Real.rpow_nonneg (by norm_num : (0:ℝ) ≤ 2) (α*(j:ℝ))) + nlinarith only [h] + apply integrable_cluster_power_of_dyadic G hloc p (root i) α hα + have he : (fun j : ℕ => (2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1))) = + (fun j : ℕ => (weight i)⁻¹ * (weight i *((2:ℝ)^(α*(j:ℝ))*clusterWindowProbability G p (root i) (2^j) (2^(j+1))))) := by + funext j + rw [←mul_assoc,inv_mul_cancel₀ (hw i).ne',one_mul] + rw [he] + exact hs'.mul_left _ + + + +theorem orbit_scales_of_divergent_moment (G : BondGraph V E) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hcover : ∀ x, ∃ i, x ∈ vertexOrbit G (root i)) (p : unitInterval) + (α β : ℝ) (hα : 0 < α) (hαβ : α < β) + (hdiv : ∃ i, ¬ Integrable (fun ω => ((cluster G ω (root i)).ncard:ℝ)^α) (law p)) : + ∃ i, ∀ N, ∃ j, N ≤ j ∧ + ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ + weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ + (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ + (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ + binOrbitRow G p (root i) (2^(j+1)) := by + apply orbit_dyadic_scales G hloc root weight Γ hΓ htr hw hw1 hcover p α β hαβ + intro hs + obtain ⟨i,hi⟩ := hdiv + exact hi (integrable_cluster_power_of_weighted_dyadic G hloc p root weight hw α hα hs i) + +end WeightedMomentScales +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section LogarithmicChainLength + +noncomputable def logarithmicChainLength (t : ℝ) (n : ℕ) : ℕ := ⌊Real.log n / t⌋₊ + +theorem logarithmicChainLength_bounds (t : ℝ) (ht : 0 < t) (n : ℕ) (hn : 1 ≤ n) : + (logarithmicChainLength t n:ℝ)*t ≤ Real.log n ∧ + Real.log n < ((logarithmicChainLength t n:ℝ)+1)*t := by + have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn + have hlog := Real.log_nonneg hn' + constructor + · exact (le_div_iff₀ ht).mp (Nat.floor_le (div_nonneg hlog ht.le)) + · exact (div_lt_iff₀ ht).mp (Nat.lt_floor_add_one (Real.log n/t)) + +theorem tendsto_logarithmicChainLength (t : ℝ) (ht : 0 < t) : + Tendsto (logarithmicChainLength t) atTop atTop := + tendsto_nat_floor_atTop.comp ((Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).atTop_div_const ht) + +theorem tendsto_log_div_chainLength (t : ℝ) (ht : 0 < t) : + Tendsto (fun n : ℕ => Real.log n / logarithmicChainLength t n) atTop (nhds t) := by + have hk : Tendsto (fun n : ℕ => (logarithmicChainLength t n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_logarithmicChainLength t ht) + have hlim : Tendsto (fun n : ℕ => t + t/(logarithmicChainLength t n:ℝ)) atTop (nhds t) := by + simpa only [add_zero] using tendsto_const_nhds.add (tendsto_const_nhds.div_atTop hk) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlim + · filter_upwards [eventually_ge_atTop (1:ℕ),hk.eventually_gt_atTop 0] with n hn hk0 + exact (le_div_iff₀ hk0).mpr (by simpa only [mul_comm] using (logarithmicChainLength_bounds t ht n hn).1) + · filter_upwards [eventually_ge_atTop (1:ℕ),hk.eventually_gt_atTop 0] with n hn hk0 + have h := (logarithmicChainLength_bounds t ht n hn).2.le + apply (div_le_iff₀ hk0).mpr + calc + _ ≤ ((logarithmicChainLength t n:ℝ)+1)*t := h + _ = _ := by field_simp + +theorem tendsto_chainLength_div_scale (t : ℝ) (ht : 0 < t) : + Tendsto (fun n : ℕ => (logarithmicChainLength t n:ℝ)/n) atTop (nhds 0) := by + have hlog : Tendsto (fun n : ℕ => (Real.log n/(n:ℝ))/t) atTop (nhds 0) := by + simpa only [zero_div,Function.comp_def,id_eq] using + (Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp tendsto_natCast_atTop_atTop).div_const t + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlog + · exact Eventually.of_forall (fun n => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) + · filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn + have hn' : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) + apply (le_div_iff₀ ht).mpr + rw [div_mul_eq_mul_div] + exact (div_le_div_iff_of_pos_right hn').mpr (logarithmicChainLength_bounds t ht n hn).1 + +theorem eventually_chain_volume_small (t : ℝ) (ht : 0 < t) (M : ℕ) : + ∀ᶠ n : ℕ in atTop, 2*logarithmicChainLength t n*M ≤ n := by + have hlim : Tendsto (fun n : ℕ => (2*(logarithmicChainLength t n:ℝ)*M)/(n:ℝ)) atTop (nhds 0) := by + have h := (tendsto_chainLength_div_scale t ht).const_mul (2*(M:ℝ)) + simpa only [mul_zero] using h.congr (fun n => by ring) + filter_upwards [(tendsto_order.mp hlim).2 1 (by norm_num),eventually_ge_atTop (1:ℕ)] with n hn hn1 + have hn' : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have h := (div_lt_iff₀ hn').mp hn + norm_num only [one_mul] at h + exact_mod_cast h.le + +end LogarithmicChainLength +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section AmplificationPolynomial + +theorem amplificationMomentFactor_ge_four (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : + 4 ≤ amplificationMomentFactor k M d c a t := by + unfold amplificationMomentFactor + have h1 : (0:ℝ) ≤ ((k*M)+(k*M)^2+d*(k*M)^3:ℕ) := Nat.cast_nonneg _ + have h2 : (0:ℝ) ≤ (2*c*(k*M:ℕ))^2*t/a := by positivity + linarith + +theorem amplificationMomentFactor_cubic (k M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : + amplificationMomentFactor k M d c a t ≤ amplificationMomentFactor 1 M d c a t * ((k:ℝ)+1)^3 := by + let b := (2*c*(M:ℝ))^2*t/a + have hb : 0 ≤ b := by dsimp [b]; positivity + have hk : (0:ℝ) ≤ k := Nat.cast_nonneg _ + have hk1 : (1:ℝ) ≤ (k:ℝ)+1 := by linarith + have h13 : (1:ℝ) ≤ ((k:ℝ)+1)^3 := one_le_pow₀ hk1 + have h1 : (k:ℝ) ≤ ((k:ℝ)+1)^3 := by + calc + _ ≤ (k:ℝ)+1 := by linarith + _ = ((k:ℝ)+1)^1 := (pow_one _).symm + _ ≤ _ := pow_le_pow_right₀ hk1 (by omega) + have h2 : (k:ℝ)^2 ≤ ((k:ℝ)+1)^3 := + (pow_le_pow_left₀ hk (by linarith : (k:ℝ) ≤ (k:ℝ)+1) 2).trans (pow_le_pow_right₀ hk1 (by omega)) + have h3 : (k:ℝ)^3 ≤ ((k:ℝ)+1)^3 := pow_le_pow_left₀ hk (by linarith) 3 + have he (j : ℕ) : amplificationMomentFactor j M d c a t = + 4 + (M:ℝ)*j + (M:ℝ)^2*(j:ℝ)^2 + ((d:ℝ)*(M:ℝ)^3)*(j:ℝ)^3 + b*(j:ℝ)^2 := by + simp only [amplificationMomentFactor,Nat.cast_add,Nat.cast_mul,Nat.cast_pow,b] + ring + rw [he k,he 1] + norm_num only [Nat.cast_one,one_pow,mul_one] + have hh0 := mul_le_mul_of_nonneg_left h13 (by norm_num : (0:ℝ) ≤ 4) + have hh1 := mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg M : (0:ℝ) ≤ M) + have hh2 := mul_le_mul_of_nonneg_left h2 (sq_nonneg (M:ℝ)) + have hh3 := mul_le_mul_of_nonneg_left h3 (show 0 ≤ (d:ℝ)*(M:ℝ)^3 by positivity) + have hhb := mul_le_mul_of_nonneg_left h2 hb + nlinarith only [hh0,hh1,hh2,hh3,hhb] + +theorem tendsto_log_amplificationMomentFactor_div (M d : ℕ) (c a t : ℝ) (ha : 0 < a) (ht : 0 ≤ t) : + Tendsto (fun k : ℕ => Real.log (amplificationMomentFactor k M d c a t)/(k:ℝ)) atTop (nhds 0) := by + let C := amplificationMomentFactor 1 M d c a t + have hC : 0 < C := amplificationMomentFactor_pos _ _ _ _ _ _ ha ht + have hplus : Tendsto (fun k : ℕ => (k:ℝ)+1) atTop atTop := by + simpa only [Function.comp_def,Nat.cast_add,Nat.cast_one] using + (tendsto_natCast_atTop_atTop (R := ℝ)).comp (tendsto_add_atTop_nat 1) + have hlog : Tendsto (fun k : ℕ => Real.log ((k:ℝ)+1)/(k:ℝ)) atTop (nhds 0) := by + simpa only [Function.comp_def,pow_one,one_mul,add_neg_cancel_right] using + (Real.tendsto_pow_log_div_mul_add_atTop 1 (-1) 1 one_ne_zero).comp hplus + have hupper : Tendsto (fun k : ℕ => (Real.log C + 3*Real.log ((k:ℝ)+1))/(k:ℝ)) atTop (nhds 0) := by + have h := ((tendsto_const_nhds (x := Real.log C)).div_atTop (tendsto_natCast_atTop_atTop (R := ℝ))).add (hlog.const_mul 3) + simpa only [zero_add,mul_zero,add_div,mul_div_assoc] using h + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hupper + · exact Eventually.of_forall (fun k => div_nonneg + (Real.log_nonneg (by have := amplificationMomentFactor_ge_four k M d c a t ha ht; linarith)) (Nat.cast_nonneg _)) + · exact Eventually.of_forall (fun k => by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + have hh := Real.log_le_log (amplificationMomentFactor_pos k M d c a t ha ht) + (amplificationMomentFactor_cubic k M d c a t ha ht) + have hp : (0:ℝ) < (k:ℝ)+1 := by positivity + simpa only [C,Real.log_mul hC.ne' (pow_pos hp 3).ne',Real.log_pow,Nat.cast_ofNat] using hh) + +end AmplificationPolynomial +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section AmplificationScalarBudget + +theorem eventually_inverseCodeMass_budget (s ξ : ℝ) (hs : 0 ≤ s) (hξ : 0 < ξ) : + ∀ᶠ M : ℕ in atTop, 2 ≤ M ∧ 1 ≤ (M:ℝ)^s ∧ + inverseCodeMass M ((M:ℝ)^s) ≤ (M:ℝ)^(s+ξ) := by + have hl := (isLittleO_log_rpow_atTop hξ).bound (by norm_num : (0:ℝ) < 1/8) + have hcast : Tendsto (fun M : ℕ => (M:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + filter_upwards [eventually_ge_atTop (2:ℕ),hcast.eventually hl] with M hM hl + have hM' : (1:ℝ) ≤ M := by exact_mod_cast (show 1 ≤ M by omega) + have hM0 : (0:ℝ) < M := lt_of_lt_of_le zero_lt_one hM' + have hL : 1 ≤ (M:ℝ)^s := Real.one_le_rpow hM' hs + refine ⟨hM,hL,?_⟩ + simp only [Real.norm_eq_abs,abs_of_nonneg (Real.log_nonneg hM'), + abs_of_nonneg (Real.rpow_nonneg hM0.le ξ)] at hl + calc + _ ≤ 8*(M:ℝ)^s*Real.log M := inverseCodeMass_le_log M _ hM hL + _ ≤ (M:ℝ)^s*(M:ℝ)^ξ := by + have hh := mul_le_mul_of_nonneg_left hl (Real.rpow_nonneg hM0.le s) + nlinarith only [hh] + _ = _ := (Real.rpow_add hM0 _ _).symm + +theorem code_bound_of_logarithmic_chain (u W t : ℝ) (hu : 0 < u) (hW : 0 ≤ W) + (ht : 0 < t) (hbudget : W ≤ u*Real.exp t) (n : ℕ) (hn : 1 ≤ n) : + W^logarithmicChainLength t n ≤ (n:ℝ)*u^logarithmicChainLength t n := by + let k := logarithmicChainLength t n + have hexp : Real.exp ((k:ℝ)*t) ≤ (n:ℝ) := by + have h := Real.exp_le_exp.mpr (logarithmicChainLength_bounds t ht n hn).1 + have hnp : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) + simpa only [Real.exp_log hnp] using h + calc + W^k ≤ (u*Real.exp t)^k := pow_le_pow_left₀ hW hbudget _ + _ = u^k*Real.exp ((k:ℝ)*t) := by rw [mul_pow,←Real.exp_nat_mul] + _ ≤ u^k*n := mul_le_mul_of_nonneg_left hexp (pow_nonneg hu.le _) + _ = _ := mul_comm _ _ + +theorem tendsto_rpow_mul_stretched_exp (γ ε : ℝ) (hε : 0 < ε) : + Tendsto (fun x : ℝ => x^γ * Real.exp (-(x^ε))) atTop (nhds 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (γ/ε) 1 zero_lt_one).comp (tendsto_rpow_atTop hε) + apply h.congr' + filter_upwards [eventually_ge_atTop (0:ℝ)] with x hx + simp only [Function.comp_def,neg_mul,one_mul,←Real.rpow_mul hx] + rw [mul_div_cancel₀ γ hε.ne'] + +end AmplificationScalarBudget +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section AmplificationGoodnessDecay + +theorem eventually_amplification_goodness_decay (T : ℝ) (hT : 0 < T) + (M d : ℕ) (c a b β ε : ℝ) (ha : 0 < a) (hb : 0 ≤ b) (hε : 0 < ε) : + ∀ᶠ n : ℕ in atTop, + 16*amplificationMomentFactor (logarithmicChainLength T n) M d c a b * + Real.exp (-((2*n+logarithmicChainLength T n*M:ℕ):ℝ)^ε) ≤ a*(n:ℝ)^(-β) := by + let C := amplificationMomentFactor 1 M d c a b + have hC : 0 < C := amplificationMomentFactor_pos _ _ _ _ _ _ ha hb + have hd : Tendsto (fun n : ℕ => 128*C*((n:ℝ)^(β+3)*Real.exp (-(n:ℝ)^ε))) atTop (nhds 0) := by + simpa only [mul_zero,Function.comp_def] using + ((tendsto_rpow_mul_stretched_exp (β+3) ε hε).comp tendsto_natCast_atTop_atTop).const_mul (128*C) + have hk := (tendsto_order.mp (tendsto_chainLength_div_scale T hT)).2 1 (by norm_num) + filter_upwards [eventually_ge_atTop (1:ℕ),hk,(tendsto_order.mp hd).2 a ha] with n hn hk hd + let k := logarithmicChainLength T n + have hn0 : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hn1 : (1:ℝ) ≤ n := by exact_mod_cast hn + have hkn : (k:ℝ) ≤ n := by + exact ((div_lt_iff₀ hn0).mp hk).le.trans_eq (one_mul _) + have hQ : amplificationMomentFactor k M d c a b ≤ 8*C*(n:ℝ)^3 := by + have hp : ((k:ℝ)+1)^3 ≤ (2*(n:ℝ))^3 := + pow_le_pow_left₀ (by positivity) (by linarith) 3 + calc + _ ≤ C*((k:ℝ)+1)^3 := amplificationMomentFactor_cubic k M d c a b ha hb + _ ≤ C*(2*(n:ℝ))^3 := mul_le_mul_of_nonneg_left hp hC.le + _ = _ := by ring + have he : Real.exp (-((2*n+k*M:ℕ):ℝ)^ε) ≤ Real.exp (-(n:ℝ)^ε) := by + apply Real.exp_le_exp.mpr + apply neg_le_neg + apply Real.rpow_le_rpow (Nat.cast_nonneg _) _ hε.le + exact_mod_cast (show n ≤ 2*n+k*M by omega) + have hpow : 0 < (n:ℝ)^β := Real.rpow_pos_of_pos hn0 _ + rw [Real.rpow_neg hn0.le,←div_eq_mul_inv] + apply (le_div_iff₀ hpow).mpr + calc + _ ≤ (16*(8*C*(n:ℝ)^3)*Real.exp (-(n:ℝ)^ε))*(n:ℝ)^β := by + apply mul_le_mul_of_nonneg_right _ hpow.le + exact mul_le_mul (mul_le_mul_of_nonneg_left hQ (by norm_num)) he + (Real.exp_pos _).le (by positivity) + _ = 128*C*((n:ℝ)^(β+3)*Real.exp (-(n:ℝ)^ε)) := by + rw [Real.rpow_add hn0,show (n:ℝ)^(3:ℝ) = (n:ℝ)^3 by norm_cast] + ring + _ ≤ a := hd.le + +end AmplificationGoodnessDecay +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section AmplificationLogEstimates + +theorem log_inv_success_le (a Q n β u : ℝ) (ha : 0 < a) (hQ : 0 < Q) + (hn : 0 < n) (hbound : a*n^(-β)/(8*Q) ≤ u) : + Real.log (1/u) ≤ β*Real.log n + Real.log Q + Real.log (8/a) := by + have hl : 0 < a*n^(-β)/(8*Q) := by positivity + have hu : 0 < u := hl.trans_le hbound + have h := Real.log_le_log hl hbound + rw [Real.log_div (mul_pos ha (Real.rpow_pos_of_pos hn _)).ne' (mul_pos (by norm_num) hQ).ne', + Real.log_mul ha.ne' (Real.rpow_pos_of_pos hn _).ne',Real.log_rpow hn, + Real.log_mul (by norm_num : (8:ℝ) ≠ 0) hQ.ne'] at h + rw [one_div,Real.log_inv,Real.log_div (by norm_num : (8:ℝ) ≠ 0) ha.ne'] + linarith + +theorem log_inv_norm_ge (r r' : ℝ) (k : ℕ) (hr : 0 < r) (hr' : 0 < r') + (hbound : r' ≤ 2*r^k) : + (k:ℝ)*Real.log (1/r) - Real.log 2 ≤ Real.log (1/r') := by + have h := Real.log_le_log hr' hbound + rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) (pow_pos hr _).ne',Real.log_pow] at h + simp only [one_div,Real.log_inv] + linarith + + + +theorem eventually_amplification_log_estimates (T ξ β H : ℝ) + (hT : 0 < T) (hξ : 0 < ξ) (hξ1 : ξ < 1) (hH : 0 < H) + (M d : ℕ) (c a b : ℝ) (ha : 0 < a) (hb : 0 ≤ b) : + ∀ᶠ n : ℕ in atTop, + let k := logarithmicChainLength T n + β*Real.log n + Real.log (amplificationMomentFactor k M d c a b) + Real.log (8/a) ≤ + (k:ℝ)*(β+ξ)*T ∧ + Real.log ((2*n+k*M:ℕ):ℝ) ≤ (k:ℝ)*(1+ξ)*T ∧ + (k:ℝ)*(1-ξ)*H ≤ (k:ℝ)*H-Real.log 2 ∧ + 2*H ≤ (k:ℝ)*(1-ξ)*H ∧ 1 ≤ k := by + let k := logarithmicChainLength T + have hk : Tendsto k atTop atTop := tendsto_logarithmicChainLength T hT + have hkR : Tendsto (fun n => (k n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp hk + have hU : Tendsto (fun n : ℕ => + (β*Real.log n + Real.log (amplificationMomentFactor (k n) M d c a b) + Real.log (8/a))/(k n:ℝ)) + atTop (nhds (β*T)) := by + have h1 := (tendsto_log_div_chainLength T hT).const_mul β + have h2 := (tendsto_log_amplificationMomentFactor_div M d c a b ha hb).comp hk + have h3 := (tendsto_const_nhds (x := Real.log (8/a))).div_atTop hkR + simpa only [add_zero,add_div,mul_div_assoc,Function.comp_def] using (h1.add h2).add h3 + have hm : Tendsto (fun n : ℕ => (Real.log n+Real.log 3)/(k n:ℝ)) atTop (nhds T) := by + simpa only [add_zero,add_div] using (tendsto_log_div_chainLength T hT).add + ((tendsto_const_nhds (x := Real.log 3)).div_atTop hkR) + have hHlim : Tendsto (fun n : ℕ => Real.log 2/(k n:ℝ)) atTop (nhds 0) := + tendsto_const_nhds.div_atTop hkR + have hU' := (tendsto_order.mp hU).2 ((β+ξ)*T) (by nlinarith) + have hm' := (tendsto_order.mp hm).2 ((1+ξ)*T) (by nlinarith) + have hH' := (tendsto_order.mp hHlim).2 (ξ*H) (mul_pos hξ hH) + filter_upwards [hU',hm',hH',hkR.eventually_ge_atTop (2/(1-ξ)), + hk.eventually_ge_atTop 1,eventually_ge_atTop (1:ℕ),eventually_chain_volume_small T hT M] + with n hUn hmn hHn hklarge hk1 hn hvol + have hkp : (0:ℝ) < k n := by exact_mod_cast (show 0 < k n by omega) + have hnp : (0:ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hcap : (2*n+k n*M:ℕ) ≤ 3*n := by + dsimp [k] at * + rw [Nat.mul_assoc] at hvol + omega + have hcap0 : (0:ℝ) < (2*n+k n*M:ℕ) := by exact_mod_cast (show 0 < 2*n+k n*M by omega) + refine ⟨?_,?_,?_,?_,hk1⟩ + · have h := (div_lt_iff₀ hkp).mp hUn + nlinarith only [h] + · calc + _ ≤ Real.log (3*(n:ℝ)) := Real.log_le_log hcap0 (by exact_mod_cast hcap) + _ = Real.log n + Real.log 3 := by rw [Real.log_mul (by norm_num : (3:ℝ) ≠ 0) hnp.ne']; ring + _ ≤ _ := by have h := (div_lt_iff₀ hkp).mp hmn; nlinarith only [h] + · have h := (div_lt_iff₀ hkp).mp hHn + nlinarith only [h] + · have h := (div_le_iff₀ (sub_pos.mpr hξ1)).mp hklarge + have hh := mul_le_mul_of_nonneg_right h hH.le + nlinarith only [hh] + +end AmplificationLogEstimates +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section AsymptoticAmplificationStep +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem asymptotic_amplification_step [Nonempty V] [Nonempty E] + (hconn : Connected G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (p : unitInterval) (hp : (p:ℝ) < 1) (d : ℕ) (hdeg : ∀ x, degree G x ≤ d) + (hu : 0 < q.successProbability p (root i₀)) + (a b β ε ξ T : ℝ) (ha : 0 < a) (hb : 0 ≤ b) + (hε : 0 < ε) (hε1 : ε < 1/2) (hξ : 0 < ξ) (hξ1 : ξ < 1) (hT : 0 < T) + (hbudget : inverseCodeMass M L ≤ q.successProbability p (root i₀)*Real.exp T) + (A : Hilbert V →L[ℂ] Hilbert V) (hApos : 0 < ‖A‖) + (hH : 0 < Real.log (1/‖A‖)) + (hA : ∀ x y, matrixCoeff A x y = (q.normalizedKernel (root i₀) p x y : ℂ)) : + ∀ᶠ n : ℕ in atTop, ∀ π : ℝ, + (n:ℝ)^(-β) ≤ π → + a*n*π ≤ binOrbitRow G p (root i₀) n → + clusterWindowProbability G p (root i₀) (n-logarithmicChainLength T n*M) (2*n) ≤ b*π → + ∃ q' : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) + (2*n+logarithmicChainLength T n*M) (((2*n+logarithmicChainLength T n*M:ℕ):ℝ)^(1/2+ε)), + 0 < q'.successProbability p (root i₀) ∧ + Real.log (1/q'.successProbability p (root i₀)) ≤ (logarithmicChainLength T n:ℝ)*(β+ξ)*T ∧ + Real.log ((2*n+logarithmicChainLength T n*M:ℕ):ℝ) ≤ (logarithmicChainLength T n:ℝ)*(1+ξ)*T ∧ + ∃ A' : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A'‖ ∧ + (logarithmicChainLength T n:ℝ)*(1-ξ)*Real.log (1/‖A‖) ≤ Real.log (1/‖A'‖) ∧ + 2*Real.log (1/‖A‖) ≤ Real.log (1/‖A'‖) ∧ + (∀ x y, matrixCoeff A' x y = (q'.normalizedKernel (root i₀) p x y : ℂ)) ∧ + 1 ≤ logarithmicChainLength T n := by + let k := logarithmicChainLength T + let cap := fun n => 2*n+k n*M + have hcap : Tendsto cap atTop atTop := + tendsto_atTop_mono (fun n => show n ≤ cap n by dsimp [cap]; omega) tendsto_id + have hgood := hcap.eventually (bad_goodness_stretched_exp G hloc hqt p hp ε hε hε1) + have hdecay := eventually_amplification_goodness_decay T hT M d c a b β ε ha hb hε + have hlogs := eventually_amplification_log_estimates T ξ β (Real.log (1/‖A‖)) + hT hξ hξ1 hH M d c a b ha hb + filter_upwards [hgood,hdecay,hlogs,eventually_ge_atTop (1:ℕ)] with n hgood hdecay hlogs hn + intro π hπ hbin hwindow + have hn0 : 0 < n := by omega + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn0 + have hπ0 : 0 < π := (Real.rpow_pos_of_pos hnR (-β)).trans_le hπ + have hQ : 0 < amplificationMomentFactor (k n) M d c a b := amplificationMomentFactor_pos _ _ _ _ _ _ ha hb + have hcoden : inverseCodeMass M L^(k n) ≤ n*q.successProbability p (root i₀)^(k n) := by + apply code_bound_of_logarithmic_chain _ _ _ hu _ hT hbudget n hn + unfold inverseCodeMass + exact add_nonneg zero_le_one (Finset.sum_nonneg (fun l _ => gapWeight_nonneg L (by linarith) l)) + have hbad : 16*amplificationMomentFactor (k n) M d c a b * + (law p).real {ω | CappedBadGoodness G ω (root i₀) (cap n) ((cap n:ℝ)^(1/2+ε))} ≤ a*π := by + calc + _ ≤ 16*amplificationMomentFactor (k n) M d c a b * Real.exp (-(cap n:ℝ)^ε) := + mul_le_mul_of_nonneg_left (hgood (root i₀) p le_rfl) (by positivity) + _ ≤ a*(n:ℝ)^(-β) := hdecay + _ ≤ _ := mul_le_mul_of_nonneg_left hπ ha.le + obtain ⟨q',hup,A',hAp,hAr,hA'⟩ := q.quantitative_amplification_step hconn root weight Γ hΓ htr hcov + hw hw1 c hc hmin i₀ hw₀ hL p (k n) n d hn0 hdeg hu a b π ((cap n:ℝ)^(1/2+ε)) + ha hb hπ0 hbin hwindow hcoden hbad A hA + have hup0 : 0 < q'.successProbability p (root i₀) := (by positivity : 0 < a*π/(8*amplificationMomentFactor (k n) M d c a b)).trans_le hup + have hulo : a*(n:ℝ)^(-β)/(8*amplificationMomentFactor (k n) M d c a b) ≤ q'.successProbability p (root i₀) := by + apply le_trans _ hup + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hπ ha.le) (by positivity) + have hulo' := log_inv_success_le a (amplificationMomentFactor (k n) M d c a b) (n:ℝ) β + (q'.successProbability p (root i₀)) ha hQ hnR hulo + have hH' := log_inv_norm_ge ‖A‖ ‖A'‖ (k n) hApos hAp hAr + exact ⟨q',hup0,hulo'.trans hlogs.1,hlogs.2.1,A',hAp,hlogs.2.2.1.trans hH', + hlogs.2.2.2.1.trans (hlogs.2.2.1.trans hH'),hA',hlogs.2.2.2.2⟩ + +end LocalEndpointRule +end AsymptoticAmplificationStep +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section WeightedScaleWindow +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem weightedWindowProbability_term_le {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (i : ι) (a b : ℕ) : + weight i * clusterWindowProbability G p (root i) a b ≤ weightedWindowProbability G p root weight a b := + Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (clusterWindowProbability_nonneg G p (root j) a b)) (Finset.mem_univ i) + +theorem orbit_scale_window_bound {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (i : ι) (hi : 0 < weight i) + (j k M : ℕ) (hvol : 2*k*M ≤ 2^(j+1)) (β π : ℝ) + (hwindow : weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ (1+(2:ℝ)^β)*π) : + clusterWindowProbability G p (root i) (2^(j+1)-k*M) (2*2^(j+1)) ≤ + ((1+(2:ℝ)^β)/weight i)*π := by + have he : 2^(j+1) = 2*2^j := by rw [pow_succ]; omega + have he' : 2*2^(j+1) = 2^(j+2) := by rw [show j+2 = (j+1)+1 by omega,pow_succ]; omega + have hl : 2^j ≤ 2^(j+1)-k*M := by + rw [he,Nat.mul_assoc] at hvol + rw [he] + omega + have hmono := clusterWindowProbability_mono G p (root i) hl (le_of_eq he') + have hterm := weightedWindowProbability_term_le G p root weight hw i (2^j) (2^(j+2)) + have hb := (mul_le_mul_of_nonneg_left hmono hi.le).trans (hterm.trans hwindow) + rw [div_mul_eq_mul_div] + exact (le_div_iff₀ hi).mpr (by simpa only [mul_comm] using hb) + +theorem tendsto_dyadic_scale : Tendsto (fun j : ℕ => 2^(j+1)) atTop atTop := + tendsto_atTop_mono (fun j => (Nat.le_succ j).trans (j+1).lt_two_pow_self.le) tendsto_id + +end WeightedScaleWindow +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section EndpointProfile + + + +structure EndpointProfile (G : BondGraph V E) (hloc : LocallyFinite G) + (p : unitInterval) (o : V) (s : ℝ) where + cap : ℕ + rule : LocalEndpointRule G hloc (vertexOrbit G o) cap ((cap:ℝ)^s) + success_pos : 0 < rule.successProbability p o + op : Hilbert V →L[ℂ] Hilbert V + norm_pos : 0 < ‖op‖ + coeff : ∀ x y, matrixCoeff op x y = (rule.normalizedKernel o p x y : ℂ) + +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} {p : unitInterval} {o : V} {s : ℝ} + +noncomputable def U (q : EndpointProfile G hloc p o s) : ℝ := Real.log (1/q.rule.successProbability p o) +noncomputable def m (q : EndpointProfile G hloc p o s) : ℝ := Real.log q.cap +noncomputable def H (q : EndpointProfile G hloc p o s) : ℝ := Real.log (1/‖q.op‖) +noncomputable def cost (q : EndpointProfile G hloc p o s) (ξ : ℝ) : ℝ := q.U+(s+ξ)*q.m + +theorem U_nonneg (q : EndpointProfile G hloc p o s) : 0 ≤ q.U := by + unfold U + rw [one_div,Real.log_inv] + have h := Real.log_nonpos q.success_pos.le (q.rule.successProbability_le_one p o) + linarith + +theorem m_pos (q : EndpointProfile G hloc p o s) (hcap : 2 ≤ q.cap) : 0 < q.m := by + exact Real.log_pos (by exact_mod_cast (show 1 < q.cap by omega)) + +theorem cost_pos (q : EndpointProfile G hloc p o s) (hcap : 2 ≤ q.cap) + (ξ : ℝ) (hsξ : 0 < s+ξ) : 0 < q.cost ξ := by + exact add_pos_of_nonneg_of_pos q.U_nonneg (mul_pos hsξ (q.m_pos hcap)) + +theorem exp_cost_identity (q : EndpointProfile G hloc p o s) (hcap : 0 < q.cap) (ξ : ℝ) : + q.rule.successProbability p o * Real.exp (q.cost ξ) = (q.cap:ℝ)^(s+ξ) := by + have hcp : (0:ℝ) < q.cap := Nat.cast_pos.mpr hcap + simp only [cost,U,m,Real.exp_add,Real.exp_log (one_div_pos.mpr q.success_pos)] + calc + _ = Real.exp ((s+ξ)*Real.log q.cap) := by field_simp [ne_of_gt q.success_pos] + _ = _ := by rw [Real.rpow_def_of_pos hcp]; congr 1; ring + +end EndpointProfile + +variable [Countable V] [Countable E] [Nonempty V] + +theorem starting_endpoint_profile (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + (p : unitInterval) (hp : 0 < (p:ℝ)) (hp1 : (p:ℝ) < 1) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (hfin : ∀ᵐ ω ∂law p, (cluster G ω (root i₀)).Finite) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (M₀ : ℕ) : + ∃ q : EndpointProfile G hloc p (root i₀) (1/2+ε), M₀ ≤ q.cap ∧ 1 < q.H := by + obtain ⟨M,hM,q,hq,A,hAp,hAn,hA⟩ := nonamenable_starting_endpoint_rule G hloc hqt hh p hp hp1 + root weight Γ hΓ htr hw hw1 i₀ hw₀ hfin ε hε hε1 (Real.exp (-2)) (Real.exp_pos _) M₀ + refine ⟨⟨M,q,hq,A,hAp,hA⟩,hM,?_⟩ + have h := Real.log_lt_log hAp hAn + rw [Real.log_exp] at h + change 1 < Real.log (1/‖A‖) + rw [one_div,Real.log_inv] + linarith + +end EndpointProfile + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section EndpointProfileStep +attribute [local instance] Classical.propDecidable Classical.decEq + +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} + +theorem amplify_at_scales [Nonempty V] [Nonempty E] + (hconn : Connected G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i : ι) (p : unitInterval) (hp : (p:ℝ) < 1) + (d : ℕ) (hdeg : ∀ x, degree G x ≤ d) + (ε ξ β : ℝ) (hε : 0 < ε) (hε1 : ε < 1/2) (hξ : 0 < ξ) (hξ1 : ξ < 1) + (hscales : ∀ N, ∃ j, N ≤ j ∧ + ((2^(j+1):ℕ):ℝ)^(-β) ≤ dyadicBinProbability G p root weight (j+1) ∧ + weightedWindowProbability G p root weight (2^j) (2^(j+2)) ≤ + (1+(2:ℝ)^β)*dyadicBinProbability G p root weight (j+1) ∧ + (((2^(j+1):ℕ):ℝ)/Fintype.card ι)*dyadicBinProbability G p root weight (j+1) ≤ + binOrbitRow G p (root i) (2^(j+1))) + (q : EndpointProfile G hloc p (root i) (1/2+ε)) (hM : 2 ≤ q.cap) + (hL : 1 ≤ (q.cap:ℝ)^(1/2+ε)) + (hbudget : inverseCodeMass q.cap ((q.cap:ℝ)^(1/2+ε)) ≤ (q.cap:ℝ)^(1/2+ε+ξ)) + (hH : 0 < q.H) (N : ℕ) : + ∃ (q' : EndpointProfile G hloc p (root i) (1/2+ε)) (k : ℕ), + N ≤ q'.cap ∧ 1 ≤ k ∧ + q'.U ≤ (k:ℝ)*(β+ξ)*q.cost ξ ∧ + q'.m ≤ (k:ℝ)*(1+ξ)*q.cost ξ ∧ + (k:ℝ)*(1-ξ)*q.H ≤ q'.H ∧ 2*q.H ≤ q'.H := by + let a : ℝ := 1/Fintype.card ι + let b : ℝ := (1+(2:ℝ)^β)/weight i + let T := q.cost ξ + have ht : 0 < T := q.cost_pos hM ξ (by linarith) + have hcard : (0:ℝ) < Fintype.card ι := by + exact_mod_cast (Fintype.card_pos_iff.mpr ⟨i⟩) + have ha : 0 < a := one_div_pos.mpr hcard + have hb : 0 ≤ b := div_nonneg (by positivity) (hw i).le + have hbudget' : inverseCodeMass q.cap ((q.cap:ℝ)^(1/2+ε)) ≤ + q.rule.successProbability p (root i)*Real.exp T := by + rw [q.exp_cost_identity (by omega) ξ] + exact hbudget + have hstep := q.rule.asymptotic_amplification_step hconn hqt root weight Γ hΓ htr hcov + (fun i => (hw i).le) hw1 c hc hmin i (hw i) hL p hp d hdeg q.success_pos + a b β ε ξ T ha hb hε hε1 hξ hξ1 ht hbudget' q.op q.norm_pos hH q.coeff + have hvol := eventually_chain_volume_small T ht q.cap + have he := tendsto_dyadic_scale.eventually (hstep.and (hvol.and (eventually_ge_atTop N))) + obtain ⟨J,hJ⟩ := eventually_atTop.1 he + obtain ⟨j,hj,hπ,hwide,hbin⟩ := hscales J + obtain ⟨hs,hvol,hN⟩ := hJ j hj + have hwin := orbit_scale_window_bound G p root weight (fun i => (hw i).le) i (hw i) + j (logarithmicChainLength T (2^(j+1))) q.cap hvol β _ hwide + have hbin' : a*(2^(j+1):ℕ)*dyadicBinProbability G p root weight (j+1) ≤ + binOrbitRow G p (root i) (2^(j+1)) := by + dsimp [a] + simpa only [div_eq_mul_inv,one_mul,mul_comm (_⁻¹)] using hbin + obtain ⟨q',hup,hU,hm,A',hAp,hH',hH'',hA',hk⟩ := hs _ hπ hbin' hwin + refine ⟨⟨_,q',hup,A',hAp,hA'⟩,_,?_,hk,hU,hm,hH',hH''⟩ + change N ≤ 2*2^(j+1)+logarithmicChainLength T (2^(j+1))*q.cap + omega + +end EndpointProfile +end EndpointProfileStep + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open Filter +section AmplificationContraction + +noncomputable def amplificationContraction (β s ξ : ℝ) : ℝ := + (β+ξ+(s+ξ)*(1+ξ))/(1-ξ) + +theorem exists_amplification_contraction (β s : ℝ) (hβ : 0 ≤ β) (hs : 0 ≤ s) + (hsmall : β+s < 1) : ∃ ξ : ℝ, 0 < ξ ∧ ξ < 1 ∧ + 0 ≤ amplificationContraction β s ξ ∧ amplificationContraction β s ξ < 1 := by + have hd : 0 < 4+s := by linarith + have hδ : 0 < (1-(β+s))/(4+s) := div_pos (by linarith) hd + obtain ⟨ξ,hξ,hξupper⟩ := exists_between (lt_min zero_lt_one hδ) + have hξ1 := hξupper.trans_le (min_le_left _ _) + have hprod : ξ*(4+s) < 1-(β+s) := (lt_div_iff₀ hd).mp (hξupper.trans_le (min_le_right _ _)) + have hx2 : ξ^2 < ξ := by nlinarith [mul_pos hξ (sub_pos.mpr hξ1)] + refine ⟨ξ,hξ,hξ1,?_,?_⟩ + · unfold amplificationContraction + positivity + · unfold amplificationContraction + apply (div_lt_one (by linarith : 0 < 1-ξ)).mpr + nlinarith + + + +theorem amplification_cost_contraction (t t' H H' β s ξ : ℝ) (k : ℕ) + (ht : 0 ≤ t) (hH : 0 < H) (hξ1 : ξ < 1) (hk : 1 ≤ k) + (hC : 0 ≤ amplificationContraction β s ξ) + (ht' : t' ≤ (k:ℝ)*(β+ξ+(s+ξ)*(1+ξ))*t) + (hH' : (k:ℝ)*(1-ξ)*H ≤ H') : + t'/H' ≤ amplificationContraction β s ξ*(t/H) := by + have hk0 : (0:ℝ) < k := by exact_mod_cast (show 0 < k by omega) + have hd : 0 < (k:ℝ)*(1-ξ)*H := mul_pos (mul_pos hk0 (by linarith)) hH + have hH'p := hd.trans_le hH' + apply (div_le_iff₀ hH'p).mpr + have he : (k:ℝ)*(β+ξ+(s+ξ)*(1+ξ))*t = + amplificationContraction β s ξ*(t/H)*((k:ℝ)*(1-ξ)*H) := by + unfold amplificationContraction + field_simp [hH.ne', (sub_pos.mpr hξ1).ne'] + rw [he] at ht' + exact ht'.trans (mul_le_mul_of_nonneg_left hH' (mul_nonneg hC (div_nonneg ht hH.le))) + +namespace EndpointProfile +variable {G : BondGraph V E} {hloc : LocallyFinite G} {p : unitInterval} {o : V} {s : ℝ} + +theorem cost_contraction (q q' : EndpointProfile G hloc p o s) (β ξ : ℝ) (k : ℕ) + (hM : 2 ≤ q.cap) (hsξ : 0 < s+ξ) (hH : 0 < q.H) (hξ1 : ξ < 1) (hk : 1 ≤ k) + (hC : 0 ≤ amplificationContraction β s ξ) + (hU : q'.U ≤ (k:ℝ)*(β+ξ)*q.cost ξ) + (hm : q'.m ≤ (k:ℝ)*(1+ξ)*q.cost ξ) + (hH' : (k:ℝ)*(1-ξ)*q.H ≤ q'.H) : + q'.cost ξ/q'.H ≤ amplificationContraction β s ξ*(q.cost ξ/q.H) := by + apply amplification_cost_contraction _ _ _ _ β s ξ k (q.cost_pos hM ξ hsξ).le hH hξ1 hk hC _ hH' + unfold cost at * + have hh := mul_le_mul_of_nonneg_left hm hsξ.le + nlinarith only [hU,hh] + +theorem total_cost_le (q : EndpointProfile G hloc p o s) (hM : 2 ≤ q.cap) + (ξ : ℝ) (hsξ : 0 < s+ξ) : q.U+q.m ≤ (1+1/(s+ξ))*q.cost ξ := by + have hm := (q.m_pos hM).le + have hU := q.U_nonneg + have hU' : q.U ≤ q.cost ξ := by unfold cost; nlinarith + have hm' : q.m ≤ q.cost ξ/(s+ξ) := by + apply (le_div_iff₀ hsξ).mpr + unfold cost + nlinarith + calc + _ ≤ q.cost ξ+q.cost ξ/(s+ξ) := add_le_add hU' hm' + _ = _ := by ring + +end EndpointProfile +end AmplificationContraction + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Spectral.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Spectral.lean index 8cbcbe6a45a60473e2be0b3042cf4cd6639e3bb3..273261e40a13079fdc0f7e063735f9cbf525971a 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Spectral.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Spectral.lean @@ -1,1166 +1,1166 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Sprinkling - -namespace OAI - -/-! Isoperimetric energy, symmetric walks and invariant operator traces. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section IsoperimetricEnergy -attribute [local instance] Classical.propDecidable - - -noncomputable def levelIndicator (a t : ℝ) : ℝ := if 0 ≤ t ∧ t < a then 1 else 0 - -theorem levelIndicator_eq (a : ℝ) : - levelIndicator a = Set.indicator (Set.Ico 0 a) (fun _ => (1:ℝ)) := by - funext t - simp [levelIndicator, Set.indicator_apply, Set.mem_Ico] - -theorem integrable_levelIndicator (a : ℝ) : Integrable (levelIndicator a) := by - rw [levelIndicator_eq] - exact (integrableOn_const (isCompact_Icc.measure_lt_top.ne) : - IntegrableOn (fun _ : ℝ => (1:ℝ)) (Set.Icc 0 a)).mono_set - Set.Ico_subset_Icc_self |>.integrable_indicator measurableSet_Ico - -theorem integral_levelIndicator {a : ℝ} (ha : 0 ≤ a) : - ∫ t, levelIndicator a t = a := by - rw [levelIndicator_eq, integral_indicator measurableSet_Ico] - simp [ha] - -theorem abs_sub_levelIndicator {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : - (fun t => |levelIndicator a t - levelIndicator b t|) = - Set.indicator (Set.Ico (min a b) (max a b)) (fun _ => (1:ℝ)) := by - funext t - rcases le_total a b with hab | hba - · simp only [min_eq_left hab, max_eq_right hab, Set.indicator_apply, Set.mem_Ico, - levelIndicator] - by_cases ht : 0 ≤ t - · by_cases hta : t < a - · have htb : t < b := hta.trans_le hab - have hna : ¬a ≤ t := not_le.mpr hta - simp [ht,hta,htb,hna] - · by_cases htb : t < b <;> simp [ht,hta,htb,le_of_not_gt hta] - · have hna : ¬a ≤ t := fun h => ht (ha.trans h) - simp [ht,hna] - · simp only [min_eq_right hba, max_eq_left hba, Set.indicator_apply, Set.mem_Ico, - levelIndicator] - by_cases ht : 0 ≤ t - · by_cases htb : t < b - · have hta : t < a := htb.trans_le hba - have hnb : ¬b ≤ t := not_le.mpr htb - simp [ht,hta,htb,hnb] - · by_cases hta : t < a <;> simp [ht,hta,htb,le_of_not_gt htb] - · have hnb : ¬b ≤ t := fun h => ht (hb.trans h) - simp [ht,hnb] - -theorem integrable_abs_sub_levelIndicator (a b : ℝ) : - Integrable (fun t => |levelIndicator a t - levelIndicator b t|) := - ((integrable_levelIndicator a).sub (integrable_levelIndicator b)).abs - -theorem integral_abs_sub_levelIndicator {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : - ∫ t, |levelIndicator a t - levelIndicator b t| = |a-b| := by - rw [abs_sub_levelIndicator ha hb, integral_indicator measurableSet_Ico] - simp only [setIntegral_const, smul_eq_mul, mul_one, - Real.volume_real_Ico_of_le min_le_max] - exact (max_sub_min_eq_abs a b).trans (abs_sub_comm _ _) - - -theorem finite_coarea_lower_bound {α : Type*} (S : Finset α) (P : Finset (α × α)) - (f : α → ℝ) (hf : ∀ x, 0 ≤ f x) (hout : ∀ x ∉ S, f x = 0) (h : ℝ) - (hcut : ∀ A : Finset α, A ⊆ S → - h * A.card ≤ ∑ e ∈ P, - |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)|) : - h * ∑ x ∈ S, f x ≤ ∑ e ∈ P, |f e.1 - f e.2| := by - let F : ℝ → ℝ := fun t => h * ∑ x ∈ S, levelIndicator (f x) t - let J : ℝ → ℝ := fun t => ∑ e ∈ P, - |levelIndicator (f e.1) t - levelIndicator (f e.2) t| - have hF : Integrable F := - (integrable_finsetSum S (fun x _ => integrable_levelIndicator (f x))).const_mul h - have hJ : Integrable J := - integrable_finsetSum P (fun e _ => integrable_abs_sub_levelIndicator _ _) - have hle : ∀ t, F t ≤ J t := by - intro t - let A := S.filter (fun x => 0 ≤ t ∧ t < f x) - have hi (x : α) : levelIndicator (f x) t = if x ∈ A then (1:ℝ) else 0 := by - by_cases hx : x ∈ S - · simp [A,levelIndicator,hx] - · rw [hout x hx] - have hz : ¬(0 ≤ t ∧ t < 0) := fun ht => (not_lt_of_ge ht.1) ht.2 - simp [A,levelIndicator,hx,hz] - have hc : ∑ x ∈ S, levelIndicator (f x) t = (A.card : ℝ) := by - simp [levelIndicator,A,Finset.sum_boole] - dsimp [F,J] - rw [hc] - simpa only [hi] using hcut A (Finset.filter_subset _ _) - have H := integral_mono hF hJ hle - dsimp [F,J] at H - rw [integral_const_mul, integral_finsetSum _ - (fun x _ => integrable_levelIndicator (f x)), integral_finsetSum _ - (fun e _ => integrable_abs_sub_levelIndicator _ _)] at H - simpa only [integral_levelIndicator (hf _), - integral_abs_sub_levelIndicator (hf _) (hf _)] using H - -theorem hV_mul_card_le (G : BondGraph V E) (A : Finset V) : - hV G * A.card ≤ (vertexBoundary G A).ncard := by - by_cases hA : A.Nonempty - · have hb : BddBelow {r : ℝ | ∃ B : Finset V, B.Nonempty ∧ - r = (vertexBoundary G B).ncard / (B.card : ℝ)} := by - refine ⟨0, ?_⟩ - rintro _ ⟨B,_,rfl⟩ - positivity - have hh : hV G ≤ (vertexBoundary G A).ncard / (A.card : ℝ) := - csInf_le hb ⟨A,hA,rfl⟩ - exact (le_div_iff₀ (by exact_mod_cast hA.card_pos)).mp hh - · simp [Finset.not_nonempty_iff_eq_empty.mp hA] - -theorem finite_vertexBoundary (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset V) : (vertexBoundary G A).Finite := by - apply (A.finite_toSet.biUnion (fun x _ => finite_neighbors hloc x)).subset - rintro y ⟨_,x,hx,hxy⟩ - exact Set.mem_iUnion.mpr ⟨x,Set.mem_iUnion.mpr ⟨hx,hxy⟩⟩ - -noncomputable def neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - Finset V := (finite_neighbors hloc x).toFinset - -@[simp] theorem mem_neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : - y ∈ neighbors G hloc x ↔ Adj G x y := by simp [neighbors] - -noncomputable def neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) : Finset V := S ∪ S.biUnion (neighbors G hloc) - -theorem subset_neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) : S ⊆ neighborClosure G hloc S := Finset.subset_union_left - -theorem neighbor_mem_neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) {x y : V} (hx : x ∈ S) (hxy : Adj G x y) : - y ∈ neighborClosure G hloc S := by - exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨x,hx,(mem_neighbors ..).mpr hxy⟩) - -noncomputable def finiteAdjPairs (G : BondGraph V E) (K : Finset V) : Finset (V × V) := - (K ×ˢ K).filter (fun e => Adj G e.1 e.2) - -@[simp] theorem mem_finiteAdjPairs (G : BondGraph V E) (K : Finset V) (e : V × V) : - e ∈ finiteAdjPairs G K ↔ e.1 ∈ K ∧ e.2 ∈ K ∧ Adj G e.1 e.2 := by - simp [finiteAdjPairs,and_assoc] - -theorem adj_symm (G : BondGraph V E) {x y : V} (h : Adj G x y) : Adj G y x := by - obtain ⟨e,he⟩ := h - exact ⟨e,he.trans (Sym2.eq_swap)⟩ - -theorem sum_swap_finiteAdjPairs (G : BondGraph V E) (K : Finset V) - (f : V × V → ℝ) : - ∑ e ∈ finiteAdjPairs G K, f e.swap = ∑ e ∈ finiteAdjPairs G K, f e := by - apply Finset.sum_bij (fun e _ => e.swap) - · intro e he - rw [mem_finiteAdjPairs] at he ⊢ - exact ⟨he.2.1,he.1,adj_symm G he.2.2⟩ - · intro a _ b _ h - exact Prod.swap_injective h - · intro b hb - refine ⟨b.swap,?_,Prod.swap_swap b⟩ - rw [mem_finiteAdjPairs] at hb ⊢ - exact ⟨hb.2.1,hb.1,adj_symm G hb.2.2⟩ - · intros; rfl - - -theorem finiteAdjPairs_cut_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (S A : Finset V) (hAS : A ⊆ S) : - (2 * hV G) * A.card ≤ ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), - |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| := by - let K := neighborClosure G hloc S - let P := finiteAdjPairs G K - let R := P.filter (fun e => e.1 ∈ A ∧ e.2 ∉ A) - have hs : (finite_vertexBoundary G hloc A).toFinset ⊆ R.image Prod.snd := by - intro y hy - have hy' : y ∈ vertexBoundary G A := by simpa using hy - obtain ⟨hyA,x,hx,hxy⟩ := hy' - apply Finset.mem_image.mpr - refine ⟨(x,y),Finset.mem_filter.mpr ⟨?_,hx,hyA⟩,rfl⟩ - exact (mem_finiteAdjPairs G K (x,y)).mpr - ⟨subset_neighborClosure G hloc S (hAS hx), - neighbor_mem_neighborClosure G hloc S (hAS hx) hxy,hxy⟩ - have hc : (vertexBoundary G A).ncard ≤ R.card := by - rw [Set.ncard_eq_toFinset_card (vertexBoundary G A) (finite_vertexBoundary G hloc A)] - exact (Finset.card_le_card hs).trans (Finset.card_image_le) - have hcross : hV G * A.card ≤ ∑ e ∈ P, - if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0 := by - rw [Finset.sum_boole] - exact (hV_mul_card_le G A).trans (by exact_mod_cast hc) - have hsplit : ∑ e ∈ P, - |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| = - 2 * ∑ e ∈ P, if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0 := by - have ht (e : V × V) : - |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| = - (if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0) + - (if e.2 ∈ A ∧ e.1 ∉ A then (1:ℝ) else 0) := by - by_cases h₁ : e.1 ∈ A <;> by_cases h₂ : e.2 ∈ A <;> simp [h₁,h₂] - simp_rw [ht] - rw [Finset.sum_add_distrib] - have he := sum_swap_finiteAdjPairs G K - (fun e => if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0) - change (∑ e ∈ P, if e.2 ∈ A ∧ e.1 ∉ A then (1:ℝ) else 0) = _ at he - rw [he] - ring - change _ ≤ ∑ e ∈ P, _ - rw [hsplit] - nlinarith - - -theorem bondGraph_coarea (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) - (hout : ∀ x ∉ S, f x = 0) : - (2 * hV G) * ∑ x ∈ S, f x ≤ - ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), |f e.1 - f e.2| := - finite_coarea_lower_bound S _ f hf hout _ - (fun A hAS => finiteAdjPairs_cut_bound G hloc S A hAS) - -theorem neighbors_card_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : - (neighbors G hloc x).card ≤ degree G x := by - let : Fintype (Step G x) := (finite_steps G hloc x).fintype - let p : Step G x → {y // y ∈ neighbors G hloc x} := - fun d => ⟨d.val.2, (mem_neighbors G hloc x d.val.2).mpr ⟨d.val.1,d.property⟩⟩ - have hp : Function.Surjective p := by - intro y - obtain ⟨e,he⟩ := (mem_neighbors G hloc x y.val).mp y.property - exact ⟨⟨(e,y.val),he⟩,Subtype.ext rfl⟩ - simpa only [degree,Nat.card_eq_fintype_card,Fintype.card_coe] using - Fintype.card_le_of_surjective p hp - -theorem finiteAdjPairs_source_sum_le (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (K : Finset V) (f : V → ℝ) - (hf : ∀ x, 0 ≤ f x) : - ∑ e ∈ finiteAdjPairs G K, f e.1 ≤ (D:ℝ) * ∑ x ∈ K, f x := by - rw [Finset.mul_sum] - simp only [finiteAdjPairs,Finset.sum_filter,Finset.sum_product] - apply Finset.sum_le_sum - intro x _ - have hc : (K.filter (fun y => Adj G x y)).card ≤ D := by - apply (Finset.card_le_card ?_).trans ((neighbors_card_le_degree G hloc x).trans (hD x)) - intro y hy - exact (mem_neighbors G hloc x y).mpr (Finset.mem_filter.mp hy).2 - calc - (∑ y ∈ K, if Adj G x y then f x else 0) = - ((K.filter (fun y => Adj G x y)).card:ℝ) * f x := by - rw [← Finset.sum_filter] - simp - _ ≤ (D:ℝ) * f x := mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (hf x) - -theorem finiteAdjPairs_square_sum_le (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (S : Finset V) (f : V → ℝ) - (hout : ∀ x ∉ S, f x = 0) : - ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1 + f e.2)^2 ≤ - 4 * (D:ℝ) * ∑ x ∈ S, (f x)^2 := by - let K := neighborClosure G hloc S - let P := finiteAdjPairs G K - have hs : ∑ x ∈ K, (f x)^2 = ∑ x ∈ S, (f x)^2 := by - symm - apply Finset.sum_subset (subset_neighborClosure G hloc S) - intro x _ hx - simp [hout x hx] - have hfirst := finiteAdjPairs_source_sum_le G hloc D hD K (fun x => (f x)^2) (fun _ => sq_nonneg _) - rw [hs] at hfirst - have hsecond := sum_swap_finiteAdjPairs G K (fun e => (f e.1)^2) - change (∑ e ∈ P, (f e.2)^2) = ∑ e ∈ P, (f e.1)^2 at hsecond - calc - (∑ e ∈ P, (f e.1 + f e.2)^2) ≤ ∑ e ∈ P, (2*(f e.1)^2+2*(f e.2)^2) := by - apply Finset.sum_le_sum - intro e _ - nlinarith [sq_nonneg (f e.1 - f e.2)] - _ = 4 * ∑ e ∈ P, (f e.1)^2 := by - rw [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.mul_sum,hsecond] - ring - _ ≤ 4 * (D:ℝ) * ∑ x ∈ S, (f x)^2 := by - nlinarith - - - -theorem bondGraph_cheeger_energy (G : BondGraph V E) (hloc : LocallyFinite G) - (hh : 0 < hV G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (S : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) - (hout : ∀ x ∉ S, f x = 0) : - (hV G)^2 * ∑ x ∈ S, (f x)^2 ≤ - (D:ℝ) * ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := by - let P := finiteAdjPairs G (neighborClosure G hloc S) - let N := ∑ x ∈ S, (f x)^2 - let E := ∑ e ∈ P, (f e.1-f e.2)^2 - have hN : 0 ≤ N := Finset.sum_nonneg (fun _ _ => sq_nonneg _) - have hE : 0 ≤ E := Finset.sum_nonneg (fun _ _ => sq_nonneg _) - have hc := bondGraph_coarea G hloc S (fun x => (f x)^2) - (fun _ => sq_nonneg _) (fun x hx => by rw [hout x hx]; norm_num) - have ht (e : V × V) : |(f e.1)^2-(f e.2)^2| = |f e.1-f e.2| * (f e.1+f e.2) := by - rw [show (f e.1)^2-(f e.2)^2 = (f e.1-f e.2)*(f e.1+f e.2) by ring, - abs_mul,abs_of_nonneg (add_nonneg (hf _) (hf _))] - simp_rw [ht] at hc - have hc' : ((2*hV G)*N)^2 ≤ - (∑ e ∈ P, |f e.1-f e.2| * (f e.1+f e.2))^2 := by - exact sq_le_sq₀ (by positivity) (Finset.sum_nonneg (fun e _ => mul_nonneg (abs_nonneg _) - (add_nonneg (hf _) (hf _)))) |>.mpr hc - have hcs := Finset.sum_mul_sq_le_sq_mul_sq P - (fun e => |f e.1-f e.2|) (fun e => f e.1+f e.2) - simp only [sq_abs] at hcs - have hbound := finiteAdjPairs_square_sum_le G hloc D hD S f hout - have hall : ((2*hV G)*N)^2 ≤ E*(4*(D:ℝ)*N) := - (hc'.trans hcs).trans (mul_le_mul_of_nonneg_left hbound hE) - change (hV G)^2*N ≤ (D:ℝ)*E - rcases hN.eq_or_lt with hzero | hpos - · rw [←hzero,mul_zero] - positivity - · apply (mul_le_mul_iff_left₀ (by positivity : 0 < 4*N)).mp - nlinarith [hall] - -end IsoperimetricEnergy - -section FiniteQuadraticForms -attribute [local instance] Classical.propDecidable - -@[simp] theorem finiteEmbedding_inner_left (f : V →₀ ℂ) (g : Hilbert V) : - inner ℂ (finiteEmbedding f) g = ∑ x ∈ f.support, star (f x) * g x := by - simp [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, - lp.inner_single_left, mul_comm] - -@[simp] theorem finiteEmbedding_inner_right (f : Hilbert V) (g : V →₀ ℂ) : - inner ℂ f (finiteEmbedding g) = ∑ x ∈ g.support, star (f x) * g x := by - simp [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, - lp.inner_single_right, mul_comm] - -@[simp] theorem finiteEmbedding_norm_sq (f : V →₀ ℂ) : - ‖finiteEmbedding f‖^2 = ∑ x ∈ f.support, ‖f x‖^2 := by - rw [norm_sq_eq_re_inner (𝕜 := ℂ)] - rw [finiteEmbedding_inner_left] - simp only [map_sum, finiteEmbedding_apply] - apply Finset.sum_congr rfl - intro x _ - simp [← Complex.normSq_eq_norm_sq, Complex.normSq_apply] - - theorem kernel_finiteEmbedding (A : Hilbert V →L[ℂ] Hilbert V) - (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) - (f : V →₀ ℂ) (x : V) : - A (finiteEmbedding f) x = ∑ y ∈ f.support, f y * (U x y : ℂ) := by - simp only [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, - map_sum, map_smul] - change (∑ y ∈ f.support, f y • A (lp.single 2 y (1 : ℂ))) x = _ - simp only [lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, - hA, smul_eq_mul] - - theorem symmetric_of_symmetric_kernel (A : Hilbert V →L[ℂ] Hilbert V) - (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) - (hU : ∀ x y, U x y = U y x) : A.toLinearMap.IsSymmetric := by - apply finiteEmbedding_dense.induction_on₂ - (p := fun f g => inner ℂ (A f) g = inner ℂ f (A g)) - · exact isClosed_eq (by fun_prop) (by fun_prop) - · intro f g - simp only [finiteEmbedding_inner_left, finiteEmbedding_inner_right, - kernel_finiteEmbedding A U hA, map_sum, map_mul, RCLike.star_def, - Complex.conj_ofReal] - simp_rw [Finset.sum_mul, Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - rw [hU y x] - ring - - theorem norm_le_of_finite_quadratic (A : Hilbert V →L[ℂ] Hilbert V) - (hA : A.toLinearMap.IsSymmetric) (C : ℝ) (hC : 0 ≤ C) - (h : ∀ f : V →₀ ℂ, - |(inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f)).re| ≤ - C * ‖finiteEmbedding f‖^2) : ‖A‖ ≤ C := by - have hall (f : Hilbert V) : |(inner ℂ (A f) f).re| ≤ C * ‖f‖^2 := by - exact finiteEmbedding_dense.induction_on f - (p := fun g => |(inner ℂ (A g) g).re| ≤ C * ‖g‖^2) - (isClosed_le (by fun_prop) (by fun_prop)) h - rw [A.norm_eq_iSup_rayleighQuotient hA] - apply ciSup_le - intro f - by_cases hf : f = 0 - · simp [hf, hC] - · rw [ContinuousLinearMap.rayleighQuotient, abs_div, abs_sq] - exact (div_le_iff₀ (sq_pos_of_pos (norm_pos_iff.mpr hf))).mpr (hall f) - - theorem abs_inner_kernel_finite_le (A : Hilbert V →L[ℂ] Hilbert V) - (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) - (hU : ∀ x y, 0 ≤ U x y) (f : V →₀ ℂ) : - |(inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f)).re| ≤ - ∑ x ∈ f.support, ∑ y ∈ f.support, ‖f x‖ * ‖f y‖ * U x y := by - change |RCLike.re (inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f))| ≤ _ - rw [inner_re_symm] - apply (Complex.abs_re_le_norm _).trans - rw [finiteEmbedding_inner_left] - simp_rw [kernel_finiteEmbedding A U hA, Finset.mul_sum] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro x _ - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - simp [abs_of_nonneg (hU x y), mul_assoc] - -end FiniteQuadraticForms - -section SymmetricWalk -attribute [local instance] Classical.propDecidable - - - -noncomputable def walkKernel (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (x y : V) : ℝ := - (if x = y then 1 - a * (neighbors G hloc x).card else 0) + - (if Adj G x y then a else 0) - - theorem walkKernel_symmetric (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (x y : V) : walkKernel G hloc a x y = walkKernel G hloc a y x := by - have ha : Adj G x y ↔ Adj G y x := ⟨adj_symm G,adj_symm G⟩ - by_cases h : x = y - · subst y; rfl - · simp [walkKernel,h,Ne.symm h,ha] - - theorem walkKernel_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) - (x y : V) : 0 ≤ walkKernel G hloc a x y := by - have hn : ((neighbors G hloc x).card : ℝ) ≤ D := by - exact_mod_cast (neighbors_card_le_degree G hloc x).trans (hD x) - have hh : 0 ≤ 1-a*(neighbors G hloc x).card := by nlinarith - unfold walkKernel - split_ifs <;> positivity - - theorem walkKernel_row_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (x : V) : - ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y = 1 := by - let N := neighbors G hloc x - have hf : (insert x N).filter (fun y => Adj G x y) = N := by - ext y - simp only [Finset.mem_filter, Finset.mem_insert] - rw [mem_neighbors] - exact ⟨fun h => h.2, fun h => ⟨Or.inr h,h⟩⟩ - simp only [walkKernel, Finset.sum_add_distrib] - rw [Finset.sum_ite_eq] - simp only [Finset.mem_insert_self,ite_true] - rw [← Finset.sum_filter,hf] - simp only [Finset.sum_const, nsmul_eq_mul] - dsimp [N] - ring - - theorem walkKernel_row_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) - (x : V) (S : Finset V) : ∑ y ∈ S, walkKernel G hloc a x y ≤ 1 := by - let N := insert x (neighbors G hloc x) - calc - ∑ y ∈ S, walkKernel G hloc a x y ≤ ∑ y ∈ S ∪ N, walkKernel G hloc a x y := - Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_left - (fun y _ _ => walkKernel_nonneg G hloc D hD a ha haD x y) - _ = ∑ y ∈ N, walkKernel G hloc a x y := by - symm - apply Finset.sum_subset Finset.subset_union_right - intro y _ hy - have hxy : x ≠ y := by intro h; subst y; exact hy (by simp [N]) - have hna : ¬ Adj G x y := by intro h; exact hy (by simp [N,h]) - simp [walkKernel,hxy,hna] - _ = 1 := walkKernel_row_sum G hloc a x - - theorem exists_walk_operator (G : BondGraph V E) (hloc : LocallyFinite G) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) : - ∃ P : Hilbert V →L[ℂ] Hilbert V, ‖P‖ ≤ 1 ∧ - P.toLinearMap.IsSymmetric ∧ - ∀ x y, P (lp.single 2 y (1 : ℂ)) x = (walkKernel G hloc a x y : ℂ) := by - obtain ⟨P,hP,hK⟩ := exists_operator_of_row_column_bound (walkKernel G hloc a) 1 - zero_le_one (walkKernel_nonneg G hloc D hD a ha haD) - (walkKernel_row_bound G hloc D hD a ha haD) (by - intro y S - simp_rw [walkKernel_symmetric G hloc a] - exact walkKernel_row_bound G hloc D hD a ha haD y S) - exact ⟨P,hP,symmetric_of_symmetric_kernel P _ hK (walkKernel_symmetric G hloc a),hK⟩ - - theorem finiteAdjPairs_sum (G : BondGraph V E) (K : Finset V) (f : V × V → ℝ) : - (∑ e ∈ finiteAdjPairs G K, f e) = - ∑ x ∈ K, ∑ y ∈ K, if Adj G x y then f (x,y) else 0 := by - simp [finiteAdjPairs,Finset.sum_filter,Finset.sum_product] - - theorem finiteAdjPairs_source_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : - (∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), f e.1) = - ∑ x ∈ S, ((neighbors G hloc x).card : ℝ) * f x := by - let K := neighborClosure G hloc S - rw [finiteAdjPairs_sum] - have he (x : V) (hx : x ∈ S) : - K.filter (fun y => Adj G x y) = neighbors G hloc x := by - ext y - simp only [Finset.mem_filter,mem_neighbors] - exact ⟨fun h => h.2,fun h => ⟨neighbor_mem_neighborClosure G hloc S hx h,h⟩⟩ - have hout' : ∀ x ∉ S, (∑ y ∈ K, if Adj G x y then f x else 0) = 0 := by - intro x hx; simp [hout x hx] - change (∑ x ∈ K, ∑ y ∈ K, if Adj G x y then f x else 0) = _ - rw [← Finset.sum_subset (subset_neighborClosure G hloc S) - (fun x _ hx => hout' x hx)] - apply Finset.sum_congr rfl - intro x hx - rw [← Finset.sum_filter,he x hx] - simp - - theorem finiteAdjPairs_product_sum (G : BondGraph V E) (hloc : LocallyFinite G) - (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : - (∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), f e.1 * f e.2) = - ∑ x ∈ S, ∑ y ∈ S, if Adj G x y then f x*f y else 0 := by - rw [finiteAdjPairs_sum] - have hs := subset_neighborClosure G hloc S - calc - _ = ∑ x ∈ S, ∑ y ∈ neighborClosure G hloc S, - if Adj G x y then f x*f y else 0 := by - symm; apply Finset.sum_subset hs - intro x _ hx; simp [hout x hx] - _ = _ := by - apply Finset.sum_congr rfl - intro x _ - symm; apply Finset.sum_subset hs - intro y _ hy; simp [hout y hy] - - theorem walkKernel_energy (G : BondGraph V E) (hloc : LocallyFinite G) - (a : ℝ) (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : - (∑ x ∈ S, ∑ y ∈ S, f x*f y*walkKernel G hloc a x y) = - ∑ x ∈ S, (f x)^2 - a/2 * - ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := by - let P := finiteAdjPairs G (neighborClosure G hloc S) - have henergy : (∑ e ∈ P, (f e.1-f e.2)^2) = - 2*(∑ x ∈ S, (neighbors G hloc x).card * (f x)^2) - - 2*(∑ x ∈ S, ∑ y ∈ S, if Adj G x y then f x*f y else 0) := by - have hs := sum_swap_finiteAdjPairs G (neighborClosure G hloc S) - (fun e => (f e.1)^2) - change (∑ e ∈ P,(f e.2)^2) = (∑ e ∈ P,(f e.1)^2) at hs - have hfirst := finiteAdjPairs_source_sum G hloc S (fun x => (f x)^2) - (fun x hx => by rw [hout x hx]; norm_num) - calc - _ = (∑ e ∈ P, (f e.1)^2) + (∑ e ∈ P,(f e.2)^2) - - 2*(∑ e ∈ P,f e.1*f e.2) := by - simp_rw [sub_sq] - rw [Finset.sum_add_distrib,Finset.sum_sub_distrib] - simp_rw [mul_assoc,← Finset.mul_sum] - ring - _ = _ := by rw [hs,hfirst,finiteAdjPairs_product_sum G hloc S f hout]; ring - rw [henergy] - have hpoint (x : V) (hx : x ∈ S) : - (∑ y ∈ S, f x*f y*walkKernel G hloc a x y) = - (f x)^2 - a*((neighbors G hloc x).card*(f x)^2) + - a*(∑ y ∈ S, if Adj G x y then f x*f y else 0) := by - simp only [walkKernel,mul_add,Finset.sum_add_distrib] - have hi : (∑ y ∈ S, f x*f y*(if x=y then 1-a*(neighbors G hloc x).card else 0)) = - (f x)^2*(1-a*(neighbors G hloc x).card) := by - simp_rw [mul_ite,mul_zero] - rw [Finset.sum_ite_eq] - simp only [hx,ite_true] - ring - rw [hi,Finset.mul_sum] - have hj : (∑ y ∈ S, f x*f y*(if Adj G x y then a else 0)) = - ∑ y ∈ S, a*(if Adj G x y then f x*f y else 0) := by - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> ring - rw [hj] - ring - simp_rw [Finset.sum_congr rfl hpoint,Finset.sum_add_distrib, - Finset.sum_sub_distrib,←Finset.mul_sum] - ring - - - -theorem walkKernel_quadratic_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (hh : 0 < hV G) (D : ℕ) (hDp : 0 < D) (hD : ∀ x, degree G x ≤ D) - (a : ℝ) (ha : 0 ≤ a) (S : Finset V) (f : V → ℝ) - (hf : ∀ x, 0 ≤ f x) (hout : ∀ x ∉ S, f x = 0) : - (∑ x ∈ S, ∑ y ∈ S, f x*f y*walkKernel G hloc a x y) ≤ - (1 - a*(hV G)^2/(2*D)) * ∑ x ∈ S, (f x)^2 := by - have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp - have hc := bondGraph_cheeger_energy G hloc hh D hD S f hf hout - have he : ((hV G)^2 * ∑ x ∈ S, (f x)^2)/(D:ℝ) ≤ - ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := - (div_le_iff₀ hDp').mpr (by simpa only [mul_comm] using hc) - rw [walkKernel_energy G hloc a S f hout] - calc - _ ≤ (∑ x ∈ S, (f x)^2) - a/2 * - (((hV G)^2 * ∑ x ∈ S, (f x)^2)/(D:ℝ)) := - sub_le_sub_left (mul_le_mul_of_nonneg_left he (by positivity)) _ - _ = _ := by ring - - - -theorem walk_operator_norm_lt_one (G : BondGraph V E) (hloc : LocallyFinite G) - (hh : 0 < hV G) (D : ℕ) (hDp : 0 < D) (hD : ∀ x, degree G x ≤ D) - (a : ℝ) (ha : 0 < a) (haD : a*D ≤ 1) - (P : Hilbert V →L[ℂ] Hilbert V) - (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) : - ‖P‖ < 1 := by - let C := max 0 (1-a*(hV G)^2/(2*D)) - have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp - have hC : 0 ≤ C := le_max_left _ _ - have hC1 : C < 1 := by - apply max_lt (by norm_num) - have : 0 < a*(hV G)^2/(2*D) := by positivity - linarith - have hn : ‖P‖ ≤ C := by - apply norm_le_of_finite_quadratic P - (symmetric_of_symmetric_kernel P _ hP (walkKernel_symmetric G hloc a)) C hC - intro f - calc - _ ≤ ∑ x ∈ f.support, ∑ y ∈ f.support, ‖f x‖*‖f y‖*walkKernel G hloc a x y := - abs_inner_kernel_finite_le P _ hP (walkKernel_nonneg G hloc D hD a ha.le haD) f - _ ≤ (1-a*(hV G)^2/(2*D)) * ∑ x ∈ f.support, ‖f x‖^2 := - walkKernel_quadratic_bound G hloc hh D hDp hD a ha.le f.support - (fun x => ‖f x‖) (fun _ => norm_nonneg _) (by - intro x hx; simp [Finsupp.notMem_support_iff.mp hx]) - _ ≤ C * ∑ x ∈ f.support, ‖f x‖^2 := - mul_le_mul_of_nonneg_right (le_max_right _ _) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) - _ = C * ‖finiteEmbedding f‖^2 := by rw [finiteEmbedding_norm_sq] - exact hn.trans_lt hC1 - - - -theorem exists_strict_walk_operator (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) : - ∃ (D : ℕ) (P : Hilbert V →L[ℂ] Hilbert V), 0 < D ∧ - (∀ x, degree G x ≤ D) ∧ ‖P‖ < 1 ∧ P.toLinearMap.IsSymmetric ∧ - ∀ x y, P (lp.single 2 y (1:ℂ)) x = - (walkKernel G hloc (1/(2*(D:ℝ))) x y : ℂ) := by - obtain ⟨D,hDp,hD⟩ := exists_degree_bound G hqt - have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp - have ha : 0 < (1:ℝ)/(2*D) := by positivity - have haD : (1:ℝ)/(2*D)*D ≤ 1 := by - rw [div_mul_eq_mul_div] - apply (div_le_iff₀ (by positivity)).mpr - nlinarith - obtain ⟨P,_,hPs,hP⟩ := exists_walk_operator G hloc D hD _ ha.le haD - exact ⟨D,P,hDp,hD,walk_operator_norm_lt_one G hloc hh D hDp hD _ ha haD P hP,hPs,hP⟩ - -end SymmetricWalk - -section PositiveConnectionKernel -open scoped ComplexOrder Matrix -attribute [local instance] Classical.propDecidable - - - -theorem equivalenceMatrix_posSemidef {α : Type*} [Fintype α] (R : Setoid α) : - Matrix.PosSemidef (fun x y => if R.r x y then (1:ℂ) else 0) := by - classical - let : Fintype (Quotient R) := Fintype.ofFinite (Quotient R) - let J : Matrix (Quotient R) α ℂ := fun q x => if q = Quotient.mk R x then 1 else 0 - have hJ : Jᴴ * J = (fun x y => if R.r x y then (1:ℂ) else 0) := by - ext x y - change (∑ q : Quotient R, star (J q x) * J q y) = _ - have hr : R.r y x ↔ R.r x y := ⟨R.symm, R.symm⟩ - simp [J, Quotient.eq, hr] - rw [← hJ] - exact Matrix.posSemidef_conjTranspose_mul_self J - -theorem connection_quadratic_nonneg (G : BondGraph V E) (ω : Set E) - (S : Finset V) (f : V → ℂ) : - 0 ≤ ∑ x ∈ S, ∑ y ∈ S, - star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y := by - classical - let R : Setoid S := ⟨fun x y => Conn G ω x y, - ⟨fun x => conn_refl G ω x, fun h => conn_symm G ω h, fun h h' => conn_trans G ω h h'⟩⟩ - have h := (equivalenceMatrix_posSemidef R).dotProduct_mulVec_nonneg - (fun x : S => f x) - simp only [dotProduct, Matrix.mulVec, Finset.mul_sum, Pi.star_apply] at h - change 0 ≤ ∑ x : S, ∑ y : S, - star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y) at h - have he : (∑ x : S, ∑ y : S, - star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y)) = - ∑ x ∈ S, ∑ y ∈ S, - star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y) := by - rw [Finset.sum_coe_sort S (fun x => ∑ y : S, - star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y))] - apply Finset.sum_congr rfl - intro x _ - exact Finset.sum_coe_sort S (fun y => - star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y)) - rw [he] at h - simpa only [mul_assoc] using h - -variable [Countable V] [Countable E] - -theorem conn_indicator_integrable (G : BondGraph V E) (p : unitInterval) (x y : V) : - Integrable (fun ω => if Conn G ω x y then (1:ℂ) else 0) (law p) := by - change Integrable ({ω | Conn G ω x y}.indicator (fun _ => (1:ℂ))) (law p) - exact (integrable_const (1:ℂ)).indicator (measurableSet_conn G x y) - -theorem twoPoint_eq_integral (G : BondGraph V E) (p : unitInterval) (x y : V) : - (twoPoint G p x y : ℂ) = - ∫ ω, (if Conn G ω x y then (1:ℂ) else 0) ∂law p := by - simpa only [Set.indicator, Set.mem_ofPred_eq, Measure.real, twoPoint, - Complex.real_smul, mul_one] using - (integral_indicator_const (μ := law p) (1:ℂ) (measurableSet_conn G x y)).symm - -theorem twoPoint_quadratic_nonneg (G : BondGraph V E) (p : unitInterval) - (S : Finset V) (f : V → ℂ) : - 0 ≤ ∑ x ∈ S, ∑ y ∈ S, star (f x) * (twoPoint G p x y : ℂ) * f y := by - have hi (x y : V) : Integrable - (fun ω => star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y) (law p) := - ((conn_indicator_integrable G p x y).const_mul _).mul_const _ - have hsum : (∑ x ∈ S, ∑ y ∈ S, star (f x) * (twoPoint G p x y : ℂ) * f y) = - ∫ ω, ∑ x ∈ S, ∑ y ∈ S, - star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y ∂law p := by - rw [integral_finsetSum S (fun x _ => integrable_finsetSum S (fun y _ => hi x y))] - apply Finset.sum_congr rfl - intro x _ - rw [integral_finsetSum S (fun y _ => hi x y)] - apply Finset.sum_congr rfl - intro y _ - rw [integral_mul_const, integral_const_mul, twoPoint_eq_integral] - rw [hsum] - exact integral_nonneg (fun ω => connection_quadratic_nonneg G ω S f) - - - -theorem HasKernel.isPositive (G : BondGraph V E) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) : A.IsPositive := by - have hs : A.toLinearMap.IsSymmetric := - symmetric_of_symmetric_kernel A (twoPoint G p) (fun x y => hA x y) (twoPoint_symm G p) - refine ⟨hs, ?_⟩ - intro f - apply finiteEmbedding_dense.induction_on f - (p := fun g => 0 ≤ (inner ℂ (A g) g).re) - · exact isClosed_le continuous_const (by fun_prop) - · intro g - rw [show inner ℂ (A (finiteEmbedding g)) (finiteEmbedding g) = - inner ℂ (finiteEmbedding g) (A (finiteEmbedding g)) from hs _ _, finiteEmbedding_inner_left] - simp only [kernel_finiteEmbedding A (twoPoint G p) (fun x y => hA x y)] - simp_rw [Finset.mul_sum] - have h := twoPoint_quadratic_nonneg G p g.support g - apply Complex.nonneg_iff.mp at h - convert h.1 using 1 - congr 1 - apply Finset.sum_congr rfl - intro x _ - apply Finset.sum_congr rfl - intro y _ - ring - -end PositiveConnectionKernel - -section InvariantOperatorTrace -open scoped ComplexOrder InnerProduct -attribute [local instance] Classical.propDecidable -local instance spectralRealOperatorScalarTower : - IsScalarTower ℝ (Hilbert V →L[ℂ] Hilbert V) (Hilbert V →L[ℂ] Hilbert V) where - smul_assoc scalar first second := by - ext vector vertex - rfl -local instance spectralRealOperatorSMulCommClass : - SMulCommClass ℝ (Hilbert V →L[ℂ] Hilbert V) (Hilbert V →L[ℂ] Hilbert V) where - smul_comm scalar first second := by - apply ContinuousLinearMap.ext - intro vector - exact (first.map_smul_of_tower scalar (second vector)).symm -local instance spectralNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -local instance spectralContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ - (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := - IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) -noncomputable def permuteHilbert (a : V ≃ V) : Hilbert V ≃ₗᵢ[ℂ] Hilbert V where - toFun f := ⟨fun x => f (a.symm x), by - apply memℓp_gen - exact a.symm.summable_iff.mpr (lp.memℓp f |>.summable (by norm_num))⟩ - invFun f := ⟨fun x => f (a x), by - apply memℓp_gen - exact a.summable_iff.mpr (lp.memℓp f |>.summable (by norm_num))⟩ - left_inv f := by ext x; simp - right_inv f := by ext x; simp - map_add' f g := by ext x; rfl - map_smul' c f := by ext x; rfl - norm_map' f := by - rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] - congr 1 - exact a.symm.tsum_eq (fun x => ‖f x‖ ^ (2:ℝ≥0∞).toReal) - -@[simp] theorem permuteHilbert_apply (a : V ≃ V) (f : Hilbert V) (x : V) : - permuteHilbert a f x = f (a.symm x) := rfl - -@[simp] theorem permuteHilbert_single (a : V ≃ V) (x : V) (c : ℂ) : - permuteHilbert a (lp.single 2 x c) = lp.single 2 (a x) c := by - ext y - simp only [permuteHilbert_apply, lp.coeFn_single] - simp [Pi.single_apply, eq_comm, Equiv.eq_symm_apply] - -noncomputable def matrixCoeff (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : ℂ := - A (lp.single 2 y (1:ℂ)) x - -@[simp] theorem matrixCoeff_eq_inner (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - matrixCoeff A x y = inner ℂ (lp.single 2 x (1:ℂ)) (A (lp.single 2 y (1:ℂ))) := by - simp [matrixCoeff,lp.inner_single_left] - -theorem operator_kernel_hasSum (A : Hilbert V →L[ℂ] Hilbert V) (f : Hilbert V) (x : V) : - HasSum (fun y => matrixCoeff A x y * f y) (A f x) := by - have h := ((lp.evalCLM ℂ (fun _ : V => ℂ) 2 x).comp A).hasSum - (lp.hasSum_single (by norm_num : (2:ℝ≥0∞) ≠ ⊤) f) - change HasSum (fun y => A (lp.single 2 y (f y)) x) (A f x) at h - have heq : (fun y : V => A (lp.single 2 y (f y)) x) = - (fun y => matrixCoeff A x y * f y) := by - funext y - have he : lp.single (E := fun _ : V => ℂ) 2 y (f y) = - f y • lp.single 2 y (1:ℂ) := by - rw [← lp.single_smul]; simp - simp [he, matrixCoeff, mul_comm] - rw [heq] at h - exact h - -@[simp] theorem matrixCoeff_mul (A B : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - matrixCoeff (A*B) x y = ∑' z, matrixCoeff A x z * matrixCoeff B z y := by - exact (operator_kernel_hasSum A (B (lp.single 2 y (1:ℂ))) x).tsum_eq.symm - -@[simp] theorem matrixCoeff_adjoint (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - matrixCoeff (star A) x y = star (matrixCoeff A y x) := by - rw [matrixCoeff_eq_inner, matrixCoeff_eq_inner] - change inner ℂ _ ((ContinuousLinearMap.adjoint A) _) = _ - rw [ContinuousLinearMap.adjoint_inner_right] - simpa only [RCLike.star_def] using - (inner_conj_symm (A (lp.single 2 x (1:ℂ))) (lp.single 2 y (1:ℂ))).symm - - -theorem matrixCoeff_invariant_iff (a : V ≃ V) (A : Hilbert V →L[ℂ] Hilbert V) : - (∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) ↔ - Commute A (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap := by - constructor - · intro h - change A * (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap = - (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap * A - apply lp.ext_continuousLinearMap (by norm_num : (2:ℝ≥0∞) ≠ ⊤) - intro y - apply ContinuousLinearMap.ext - intro c - ext x - have hs : lp.single (E := fun _ : V => ℂ) 2 y c = - c • lp.single 2 y (1:ℂ) := by rw [← lp.single_smul]; simp - have hh := h (a.symm x) y - simp only [Equiv.apply_symm_apply] at hh - change A (permuteHilbert a (lp.single 2 y c)) x = - permuteHilbert a (A (lp.single 2 y c)) x - rw [hs] - simp only [map_smul, permuteHilbert_single, lp.coeFn_smul, Pi.smul_apply, - permuteHilbert_apply] - change c * matrixCoeff A x (a y) = c * matrixCoeff A (a.symm x) y - rw [hh] - · intro h x y - have hh := congrArg (fun F : Hilbert V →L[ℂ] Hilbert V => - F (lp.single 2 y (1:ℂ)) (a x)) h.eq - simpa only [mul_apply_eq_comp, LinearIsometryEquiv.coe_toContinuousLinearEquiv, - ContinuousLinearEquiv.coe_coe, permuteHilbert_single, permuteHilbert_apply, - Equiv.symm_apply_apply, matrixCoeff] using hh - - theorem matrixCoeff_sqrt_invariant (a : V ≃ V) (A : Hilbert V →L[ℂ] Hilbert V) - (h : ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) : - ∀ x y, matrixCoeff (CFC.sqrt A) (a x) (a y) = matrixCoeff (CFC.sqrt A) x y := by - apply (matrixCoeff_invariant_iff a _).mpr - rw [CFC.sqrt_eq_cfc] - exact ((matrixCoeff_invariant_iff a A).mp h).cfc_nnreal NNReal.sqrt - - theorem matrixCoeff_mul_invariant (a : V ≃ V) (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) - (hB : ∀ x y, matrixCoeff B (a x) (a y) = matrixCoeff B x y) : - ∀ x y, matrixCoeff (A*B) (a x) (a y) = matrixCoeff (A*B) x y := by - intro x y - simp only [matrixCoeff_mul] - rw [← a.tsum_eq (fun z => matrixCoeff A (a x) z * matrixCoeff B z (a y))] - simp only [hA,hB] - - theorem matrixCoeff_nonneg (A : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) (x : V) : - 0 ≤ matrixCoeff A x x := by - rw [matrixCoeff_eq_inner] - exact (ContinuousLinearMap.nonneg_iff_isPositive |>.mp hA).inner_nonneg_right _ - - theorem matrixCoeff_mono {A B : Hilbert V →L[ℂ] Hilbert V} (h : A ≤ B) (x : V) : - matrixCoeff A x x ≤ matrixCoeff B x x := by - have hh := matrixCoeff_nonneg (B-A) (sub_nonneg.mpr h) x - simpa only [matrixCoeff, sub_apply, lp.coeFn_sub, - Pi.sub_apply, sub_nonneg] using hh - -section RootTrace -variable {ι : Type*} [Fintype ι] -variable (root : ι → V) (weight : ι → ℝ) - -noncomputable def rootTrace (A : Hilbert V →L[ℂ] Hilbert V) : ℂ := - ∑ i, (weight i : ℂ) * matrixCoeff A (root i) (root i) - -@[simp] theorem rootTrace_add (A B : Hilbert V →L[ℂ] Hilbert V) : - rootTrace root weight (A+B) = rootTrace root weight A + rootTrace root weight B := by - simp [rootTrace, matrixCoeff, add_apply, mul_add, Finset.sum_add_distrib] - -@[simp] theorem rootTrace_smul (c : ℂ) (A : Hilbert V →L[ℂ] Hilbert V) : - rootTrace root weight (c • A) = c * rootTrace root weight A := by - simp [rootTrace, matrixCoeff, smul_apply, ← Finset.mul_sum, mul_left_comm] - -theorem rootTrace_nonneg (hw : ∀ i, 0 ≤ weight i) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) : 0 ≤ rootTrace root weight A := by - exact Finset.sum_nonneg fun i _ => mul_nonneg (by simpa using hw i) - (matrixCoeff_nonneg A hA (root i)) - -theorem rootTrace_mono (hw : ∀ i, 0 ≤ weight i) - {A B : Hilbert V →L[ℂ] Hilbert V} (h : A ≤ B) : - rootTrace root weight A ≤ rootTrace root weight B := by - apply Finset.sum_le_sum - intro i _ - exact mul_le_mul_of_nonneg_left (matrixCoeff_mono h (root i)) (by simpa using hw i) - -@[simp] theorem rootTrace_one (hw : ∑ i, weight i = 1) : - rootTrace root weight (1 : Hilbert V →L[ℂ] Hilbert V) = 1 := by - simpa [rootTrace, matrixCoeff, lp.coeFn_single, ← Complex.ofReal_sum] using - congrArg (fun t : ℝ => (t : ℂ)) hw - - -def KernelInvariant (Γ : Set (V ≃ V)) (A : Hilbert V →L[ℂ] Hilbert V) : Prop := - ∀ a ∈ Γ, ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y - -theorem KernelInvariant.mul {Γ : Set (V ≃ V)} - {A B : Hilbert V →L[ℂ] Hilbert V} - (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) : - KernelInvariant Γ (A*B) := by - intro a ha - exact matrixCoeff_mul_invariant a A B (hA a ha) (hB a ha) - -theorem KernelInvariant.star {Γ : Set (V ≃ V)} - {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) : - KernelInvariant Γ (star A) := by - intro a ha x y - simp only [matrixCoeff_adjoint, hA a ha] - -theorem KernelInvariant.sqrt {Γ : Set (V ≃ V)} - {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) : - KernelInvariant Γ (CFC.sqrt A) := by - intro a ha - exact matrixCoeff_sqrt_invariant a A (hA a ha) - - - -def RootTransport (Γ : Set (V ≃ V)) : Prop := - ∀ m : V → V → ℂ, - (∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) → - (∀ x, Summable (m x)) → (∀ y, Summable (fun x => m x y)) → - (∑ i, (weight i : ℂ) * ∑' y, m (root i) y) = - (∑ i, (weight i : ℂ) * ∑' x, m x (root i)) - -theorem rootTrace_cyclic {Γ : Set (V ≃ V)} - (htr : RootTransport root weight Γ) - (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) : - rootTrace root weight (A*B) = rootTrace root weight (B*A) := by - have ht := htr (fun x y => matrixCoeff A x y * matrixCoeff B y x) - (by intro a ha x y; rw [hA a ha, hB a ha]) - (fun x => (operator_kernel_hasSum A (B (lp.single 2 x (1:ℂ))) x).summable) - (fun y => by - simpa only [matrixCoeff, mul_comm] using - (operator_kernel_hasSum B (A (lp.single 2 y (1:ℂ))) y).summable) - simpa only [rootTrace, matrixCoeff_mul, mul_comm] using ht - -theorem rootTrace_diag_le {Γ : Set (V ≃ V)} - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) - (hmin : ∀ i, 1 ≤ c * weight i) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : KernelInvariant Γ A) - (hApos : 0 ≤ A) (x : V) : - matrixCoeff A x x ≤ (c : ℂ) * rootTrace root weight A := by - obtain ⟨i,a,ha,hax⟩ := hcov x - have hi : (weight i : ℂ) * matrixCoeff A (root i) (root i) ≤ - rootTrace root weight A := by - unfold rootTrace - exact Finset.single_le_sum (s := Finset.univ) - (f := fun j => (weight j : ℂ) * matrixCoeff A (root j) (root j)) - (fun j _ => mul_nonneg (by simpa using hw j) (matrixCoeff_nonneg A hApos _)) - (Finset.mem_univ i) - calc - matrixCoeff A x x = matrixCoeff A (root i) (root i) := by - rw [← hax, hA a ha] - _ ≤ (c * weight i : ℝ) * matrixCoeff A (root i) (root i) := by - simpa only [one_mul] using mul_le_mul_of_nonneg_right - (show (1:ℂ) ≤ ((c * weight i : ℝ) : ℂ) by exact_mod_cast hmin i) - (matrixCoeff_nonneg A hApos (root i)) - _ = (c : ℂ) * ((weight i : ℂ) * matrixCoeff A (root i) (root i)) := by - push_cast; ring - _ ≤ (c : ℂ) * rootTrace root weight A := - mul_le_mul_of_nonneg_left hi (by exact_mod_cast hc) - -@[simp] theorem rootTrace_real_smul (c : ℝ) (A : Hilbert V →L[ℂ] Hilbert V) : - rootTrace root weight (c • A) = (c : ℂ) * rootTrace root weight A := by - simp [rootTrace, matrixCoeff, smul_apply, Complex.real_smul, - ← Finset.mul_sum, mul_left_comm] - -theorem rootTrace_positive_mul_le {Γ : Set (V ≃ V)} - (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) - (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) - (hApos : 0 ≤ A) (hBsa : IsSelfAdjoint B) : - rootTrace root weight (B*A) ≤ (‖B‖ : ℂ) * rootTrace root weight A := by - let S := CFC.sqrt A - have hS : S*S = A := CFC.sqrt_mul_sqrt_self A hApos - have hSstar : star S = S := (IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg A)).star_eq - have hSI : KernelInvariant Γ S := hA.sqrt - have hbound : S*B*S ≤ ‖B‖ • A := by - convert (CStarAlgebra.star_left_conjugate_le_norm_smul (a := S) (b := B) hBsa) using 1 - · rw [hSstar] - · rw [hSstar, hS] - ext f x - rfl - calc - rootTrace root weight (B*A) = rootTrace root weight (S*(B*S)) := by - rw [rootTrace_cyclic root weight htr S (B*S) hSI (hB.mul hSI)] - rw [mul_assoc, hS] - _ = rootTrace root weight (S*B*S) := by rw [mul_assoc] - _ ≤ rootTrace root weight (‖B‖ • A) := rootTrace_mono root weight hw hbound - _ = (‖B‖ : ℂ) * rootTrace root weight A := rootTrace_real_smul root weight _ _ - -theorem rootTrace_conjugate_le {Γ : Set (V ≃ V)} - (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) - (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) - (hApos : 0 ≤ A) : - rootTrace root weight (B*A*star B) ≤ ((‖B‖ ^ 2 : ℝ) : ℂ) * rootTrace root weight A := by - calc - rootTrace root weight (B*A*star B) = rootTrace root weight (star B*(B*A)) := - rootTrace_cyclic root weight htr (B*A) (star B) (hB.mul hA) hB.star - _ = rootTrace root weight ((star B*B)*A) := by rw [mul_assoc] - _ ≤ (‖star B*B‖ : ℂ) * rootTrace root weight A := - rootTrace_positive_mul_le root weight htr hw A (star B*B) hA (hB.star.mul hB) - hApos (IsSelfAdjoint.of_nonneg (star_mul_self_nonneg B)) - _ = ((‖B‖ ^ 2 : ℝ) : ℂ) * rootTrace root weight A := by - have hnorm := CStarRing.norm_star_mul_self (x := B) - have hn : ‖star B * B‖ = ‖B‖ ^ 2 := by - convert hnorm using 1; simp only [pow_two] - rw [hn] - - theorem matrixCoeff_gram (L M : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - matrixCoeff (L*star M) x y = - inner ℂ (star L (lp.single 2 x (1:ℂ))) (star M (lp.single 2 y (1:ℂ))) := by - rw [matrixCoeff_eq_inner] - change inner ℂ _ (L ((ContinuousLinearMap.adjoint M) _)) = _ - rw [← ContinuousLinearMap.adjoint_inner_left] - rfl - - theorem matrixCoeff_gram_norm_sq_le - (L M : Hilbert V →L[ℂ] Hilbert V) (x y : V) : - ‖matrixCoeff (L*star M) x y‖ ^ 2 ≤ - (matrixCoeff (L*star L) x x).re * (matrixCoeff (M*star M) y y).re := by - simp only [matrixCoeff_gram] - have h := inner_mul_inner_self_le (𝕜 := ℂ) - (star L (lp.single 2 x (1:ℂ))) (star M (lp.single 2 y (1:ℂ))) - rw [norm_inner_symm (star M (lp.single 2 y (1:ℂ)))] at h - simpa only [pow_two, RCLike.re_to_complex] using h - - theorem matrixCoeff_positive_product_norm_sq_le - (A B : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) (x y : V) : - ‖matrixCoeff (B*A) x y‖ ^ 2 ≤ - (matrixCoeff (B*A*star B) x x).re * (matrixCoeff A y y).re := by - let S := CFC.sqrt A - have hSS : S*S = A := CFC.sqrt_mul_sqrt_self A hA - have hSstar : star S = S := (IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg A)).star_eq - convert matrixCoeff_gram_norm_sq_le (B*S) S x y using 1 <;> - simp only [star_mul, hSstar, mul_assoc, ← mul_assoc S S, hSS] - - - -theorem matrixCoeff_smoothing {Γ : Set (V ≃ V)} - (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) - (A B : Hilbert V →L[ℂ] Hilbert V) - (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) - (hApos : 0 ≤ A) (hdiag : ∀ y, matrixCoeff A y y = 1) (x y : V) : - ‖matrixCoeff (B*A) x y‖ ≤ Real.sqrt c * ‖B‖ := by - have htA : rootTrace root weight A = 1 := by - simp only [rootTrace, hdiag, mul_one, ← Complex.ofReal_sum, hsum, Complex.ofReal_one] - have hD : 0 ≤ B*A*star B := star_right_conjugate_nonneg hApos B - have hi : KernelInvariant Γ (B*A*star B) := (hB.mul hA).mul hB.star - have ht := rootTrace_conjugate_le root weight htr hw A B hA hB hApos - rw [htA, mul_one] at ht - have hd : matrixCoeff (B*A*star B) x x ≤ ((c * ‖B‖^2 : ℝ) : ℂ) := by - calc - _ ≤ (c : ℂ) * rootTrace root weight (B*A*star B) := - rootTrace_diag_le root weight hcov hw c hc hmin _ hi hD x - _ ≤ (c : ℂ) * ((‖B‖^2 : ℝ) : ℂ) := - mul_le_mul_of_nonneg_left ht (by exact_mod_cast hc) - _ = _ := by push_cast; rfl - have hd' : (matrixCoeff (B*A*star B) x x).re ≤ c * ‖B‖^2 := - (Complex.le_def.mp hd).1 - have hs : ‖matrixCoeff (B*A) x y‖ ^ 2 ≤ c * ‖B‖ ^ 2 := by - have hh := matrixCoeff_positive_product_norm_sq_le A B hApos x y - rw [hdiag, Complex.one_re, mul_one] at hh - exact hh.trans hd' - apply (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _))).mp - rwa [mul_pow, Real.sq_sqrt hc] - -end RootTrace - -end InvariantOperatorTrace - -section InvariantPercolationOperators -open scoped ComplexOrder InnerProduct -attribute [local instance] Classical.propDecidable - - -def vertexAut (G : BondGraph V E) : Set (V ≃ V) := {a | ∃ b : E ≃ E, IsAut G a b} - -theorem twoPoint_aut [Countable V] [Countable E] (G : BondGraph V E) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x y : V) : - twoPoint G p (a x) (a y) = twoPoint G p x y := by - have he : {ω | Conn G ω (a x) (a y)} = - (fun ω => b ⁻¹' ω) ⁻¹' {ω | Conn G ω x y} := by - ext ω - exact (conn_aut_iff G h ω x y).symm - unfold twoPoint - rw [he, ← Measure.map_apply (measurable_set_preimage b) - (measurableSet_conn G x y), law_map_preimage_equiv] - -theorem HasKernel.invariant [Countable V] [Countable E] (G : BondGraph V E) (p : unitInterval) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) : - KernelInvariant (vertexAut G) A := by - rintro a ⟨b, hab⟩ x y - change A (lp.single 2 (a y) (1:ℂ)) (a x) = A (lp.single 2 y (1:ℂ)) x - rw [hA, hA, twoPoint_aut G p hab] - -theorem KernelInvariant.one (Γ : Set (V ≃ V)) : - KernelInvariant Γ (1 : Hilbert V →L[ℂ] Hilbert V) := by - intro a _ x y - simp only [matrixCoeff, one_apply_eq_self, lp.coeFn_single] - simp [Pi.single_apply, a.injective.eq_iff] - -theorem KernelInvariant.pow {Γ : Set (V ≃ V)} - {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) (n : ℕ) : - KernelInvariant Γ (A^n) := by - induction n with - | zero => simpa only [pow_zero] using KernelInvariant.one Γ - | succ n ih => simpa only [pow_succ] using ih.mul hA - - - -theorem twoPoint_operator_smoothing [Countable V] [Countable E] [Nonempty V] {ι : Type*} [Fintype ι] - (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) - (htr : RootTransport root weight (vertexAut G)) - (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) - (A P : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) - (hP : KernelInvariant (vertexAut G) P) (l : ℕ) (x y : V) : - ‖matrixCoeff (P^l*A) x y‖ ≤ Real.sqrt c * ‖P‖^l := by - have hdiag (y : V) : matrixCoeff A y y = 1 := by - change A (lp.single 2 y (1:ℂ)) y = 1 - rw [hA y y, twoPoint_self, Complex.ofReal_one] - have h := matrixCoeff_smoothing root weight htr hcov hw hsum c hc hmin A (P^l) - (hA.invariant G p A) (hP.pow l) (ContinuousLinearMap.nonneg_iff_isPositive.mpr - (hA.isPositive G p A)) hdiag x y - have hn (n : ℕ) : ‖P^n‖ ≤ ‖P‖^n := by - induction n with - | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) - | succ n ih => - rw [pow_succ, pow_succ] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) - exact h.trans (mul_le_mul_of_nonneg_left (hn l) (Real.sqrt_nonneg c)) -end InvariantPercolationOperators - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Sprinkling + +namespace OAI + +/-! Isoperimetric energy, symmetric walks and invariant operator traces. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section IsoperimetricEnergy +attribute [local instance] Classical.propDecidable + + +noncomputable def levelIndicator (a t : ℝ) : ℝ := if 0 ≤ t ∧ t < a then 1 else 0 + +theorem levelIndicator_eq (a : ℝ) : + levelIndicator a = Set.indicator (Set.Ico 0 a) (fun _ => (1:ℝ)) := by + funext t + simp [levelIndicator, Set.indicator_apply, Set.mem_Ico] + +theorem integrable_levelIndicator (a : ℝ) : Integrable (levelIndicator a) := by + rw [levelIndicator_eq] + exact (integrableOn_const (isCompact_Icc.measure_lt_top.ne) : + IntegrableOn (fun _ : ℝ => (1:ℝ)) (Set.Icc 0 a)).mono_set + Set.Ico_subset_Icc_self |>.integrable_indicator measurableSet_Ico + +theorem integral_levelIndicator {a : ℝ} (ha : 0 ≤ a) : + ∫ t, levelIndicator a t = a := by + rw [levelIndicator_eq, integral_indicator measurableSet_Ico] + simp [ha] + +theorem abs_sub_levelIndicator {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : + (fun t => |levelIndicator a t - levelIndicator b t|) = + Set.indicator (Set.Ico (min a b) (max a b)) (fun _ => (1:ℝ)) := by + funext t + rcases le_total a b with hab | hba + · simp only [min_eq_left hab, max_eq_right hab, Set.indicator_apply, Set.mem_Ico, + levelIndicator] + by_cases ht : 0 ≤ t + · by_cases hta : t < a + · have htb : t < b := hta.trans_le hab + have hna : ¬a ≤ t := not_le.mpr hta + simp [ht,hta,htb,hna] + · by_cases htb : t < b <;> simp [ht,hta,htb,le_of_not_gt hta] + · have hna : ¬a ≤ t := fun h => ht (ha.trans h) + simp [ht,hna] + · simp only [min_eq_right hba, max_eq_left hba, Set.indicator_apply, Set.mem_Ico, + levelIndicator] + by_cases ht : 0 ≤ t + · by_cases htb : t < b + · have hta : t < a := htb.trans_le hba + have hnb : ¬b ≤ t := not_le.mpr htb + simp [ht,hta,htb,hnb] + · by_cases hta : t < a <;> simp [ht,hta,htb,le_of_not_gt htb] + · have hnb : ¬b ≤ t := fun h => ht (hb.trans h) + simp [ht,hnb] + +theorem integrable_abs_sub_levelIndicator (a b : ℝ) : + Integrable (fun t => |levelIndicator a t - levelIndicator b t|) := + ((integrable_levelIndicator a).sub (integrable_levelIndicator b)).abs + +theorem integral_abs_sub_levelIndicator {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : + ∫ t, |levelIndicator a t - levelIndicator b t| = |a-b| := by + rw [abs_sub_levelIndicator ha hb, integral_indicator measurableSet_Ico] + simp only [setIntegral_const, smul_eq_mul, mul_one, + Real.volume_real_Ico_of_le min_le_max] + exact (max_sub_min_eq_abs a b).trans (abs_sub_comm _ _) + + +theorem finite_coarea_lower_bound {α : Type*} (S : Finset α) (P : Finset (α × α)) + (f : α → ℝ) (hf : ∀ x, 0 ≤ f x) (hout : ∀ x ∉ S, f x = 0) (h : ℝ) + (hcut : ∀ A : Finset α, A ⊆ S → + h * A.card ≤ ∑ e ∈ P, + |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)|) : + h * ∑ x ∈ S, f x ≤ ∑ e ∈ P, |f e.1 - f e.2| := by + let F : ℝ → ℝ := fun t => h * ∑ x ∈ S, levelIndicator (f x) t + let J : ℝ → ℝ := fun t => ∑ e ∈ P, + |levelIndicator (f e.1) t - levelIndicator (f e.2) t| + have hF : Integrable F := + (integrable_finsetSum S (fun x _ => integrable_levelIndicator (f x))).const_mul h + have hJ : Integrable J := + integrable_finsetSum P (fun e _ => integrable_abs_sub_levelIndicator _ _) + have hle : ∀ t, F t ≤ J t := by + intro t + let A := S.filter (fun x => 0 ≤ t ∧ t < f x) + have hi (x : α) : levelIndicator (f x) t = if x ∈ A then (1:ℝ) else 0 := by + by_cases hx : x ∈ S + · simp [A,levelIndicator,hx] + · rw [hout x hx] + have hz : ¬(0 ≤ t ∧ t < 0) := fun ht => (not_lt_of_ge ht.1) ht.2 + simp [A,levelIndicator,hx,hz] + have hc : ∑ x ∈ S, levelIndicator (f x) t = (A.card : ℝ) := by + simp [levelIndicator,A,Finset.sum_boole] + dsimp [F,J] + rw [hc] + simpa only [hi] using hcut A (Finset.filter_subset _ _) + have H := integral_mono hF hJ hle + dsimp [F,J] at H + rw [integral_const_mul, integral_finsetSum _ + (fun x _ => integrable_levelIndicator (f x)), integral_finsetSum _ + (fun e _ => integrable_abs_sub_levelIndicator _ _)] at H + simpa only [integral_levelIndicator (hf _), + integral_abs_sub_levelIndicator (hf _) (hf _)] using H + +theorem hV_mul_card_le (G : BondGraph V E) (A : Finset V) : + hV G * A.card ≤ (vertexBoundary G A).ncard := by + by_cases hA : A.Nonempty + · have hb : BddBelow {r : ℝ | ∃ B : Finset V, B.Nonempty ∧ + r = (vertexBoundary G B).ncard / (B.card : ℝ)} := by + refine ⟨0, ?_⟩ + rintro _ ⟨B,_,rfl⟩ + positivity + have hh : hV G ≤ (vertexBoundary G A).ncard / (A.card : ℝ) := + csInf_le hb ⟨A,hA,rfl⟩ + exact (le_div_iff₀ (by exact_mod_cast hA.card_pos)).mp hh + · simp [Finset.not_nonempty_iff_eq_empty.mp hA] + +theorem finite_vertexBoundary (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset V) : (vertexBoundary G A).Finite := by + apply (A.finite_toSet.biUnion (fun x _ => finite_neighbors hloc x)).subset + rintro y ⟨_,x,hx,hxy⟩ + exact Set.mem_iUnion.mpr ⟨x,Set.mem_iUnion.mpr ⟨hx,hxy⟩⟩ + +noncomputable def neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + Finset V := (finite_neighbors hloc x).toFinset + +@[simp] theorem mem_neighbors (G : BondGraph V E) (hloc : LocallyFinite G) (x y : V) : + y ∈ neighbors G hloc x ↔ Adj G x y := by simp [neighbors] + +noncomputable def neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) : Finset V := S ∪ S.biUnion (neighbors G hloc) + +theorem subset_neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) : S ⊆ neighborClosure G hloc S := Finset.subset_union_left + +theorem neighbor_mem_neighborClosure (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) {x y : V} (hx : x ∈ S) (hxy : Adj G x y) : + y ∈ neighborClosure G hloc S := by + exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨x,hx,(mem_neighbors ..).mpr hxy⟩) + +noncomputable def finiteAdjPairs (G : BondGraph V E) (K : Finset V) : Finset (V × V) := + (K ×ˢ K).filter (fun e => Adj G e.1 e.2) + +@[simp] theorem mem_finiteAdjPairs (G : BondGraph V E) (K : Finset V) (e : V × V) : + e ∈ finiteAdjPairs G K ↔ e.1 ∈ K ∧ e.2 ∈ K ∧ Adj G e.1 e.2 := by + simp [finiteAdjPairs,and_assoc] + +theorem adj_symm (G : BondGraph V E) {x y : V} (h : Adj G x y) : Adj G y x := by + obtain ⟨e,he⟩ := h + exact ⟨e,he.trans (Sym2.eq_swap)⟩ + +theorem sum_swap_finiteAdjPairs (G : BondGraph V E) (K : Finset V) + (f : V × V → ℝ) : + ∑ e ∈ finiteAdjPairs G K, f e.swap = ∑ e ∈ finiteAdjPairs G K, f e := by + apply Finset.sum_bij (fun e _ => e.swap) + · intro e he + rw [mem_finiteAdjPairs] at he ⊢ + exact ⟨he.2.1,he.1,adj_symm G he.2.2⟩ + · intro a _ b _ h + exact Prod.swap_injective h + · intro b hb + refine ⟨b.swap,?_,Prod.swap_swap b⟩ + rw [mem_finiteAdjPairs] at hb ⊢ + exact ⟨hb.2.1,hb.1,adj_symm G hb.2.2⟩ + · intros; rfl + + +theorem finiteAdjPairs_cut_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (S A : Finset V) (hAS : A ⊆ S) : + (2 * hV G) * A.card ≤ ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), + |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| := by + let K := neighborClosure G hloc S + let P := finiteAdjPairs G K + let R := P.filter (fun e => e.1 ∈ A ∧ e.2 ∉ A) + have hs : (finite_vertexBoundary G hloc A).toFinset ⊆ R.image Prod.snd := by + intro y hy + have hy' : y ∈ vertexBoundary G A := by simpa using hy + obtain ⟨hyA,x,hx,hxy⟩ := hy' + apply Finset.mem_image.mpr + refine ⟨(x,y),Finset.mem_filter.mpr ⟨?_,hx,hyA⟩,rfl⟩ + exact (mem_finiteAdjPairs G K (x,y)).mpr + ⟨subset_neighborClosure G hloc S (hAS hx), + neighbor_mem_neighborClosure G hloc S (hAS hx) hxy,hxy⟩ + have hc : (vertexBoundary G A).ncard ≤ R.card := by + rw [Set.ncard_eq_toFinset_card (vertexBoundary G A) (finite_vertexBoundary G hloc A)] + exact (Finset.card_le_card hs).trans (Finset.card_image_le) + have hcross : hV G * A.card ≤ ∑ e ∈ P, + if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0 := by + rw [Finset.sum_boole] + exact (hV_mul_card_le G A).trans (by exact_mod_cast hc) + have hsplit : ∑ e ∈ P, + |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| = + 2 * ∑ e ∈ P, if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0 := by + have ht (e : V × V) : + |(if e.1 ∈ A then (1:ℝ) else 0) - (if e.2 ∈ A then (1:ℝ) else 0)| = + (if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0) + + (if e.2 ∈ A ∧ e.1 ∉ A then (1:ℝ) else 0) := by + by_cases h₁ : e.1 ∈ A <;> by_cases h₂ : e.2 ∈ A <;> simp [h₁,h₂] + simp_rw [ht] + rw [Finset.sum_add_distrib] + have he := sum_swap_finiteAdjPairs G K + (fun e => if e.1 ∈ A ∧ e.2 ∉ A then (1:ℝ) else 0) + change (∑ e ∈ P, if e.2 ∈ A ∧ e.1 ∉ A then (1:ℝ) else 0) = _ at he + rw [he] + ring + change _ ≤ ∑ e ∈ P, _ + rw [hsplit] + nlinarith + + +theorem bondGraph_coarea (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) + (hout : ∀ x ∉ S, f x = 0) : + (2 * hV G) * ∑ x ∈ S, f x ≤ + ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), |f e.1 - f e.2| := + finite_coarea_lower_bound S _ f hf hout _ + (fun A hAS => finiteAdjPairs_cut_bound G hloc S A hAS) + +theorem neighbors_card_le_degree (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) : + (neighbors G hloc x).card ≤ degree G x := by + let : Fintype (Step G x) := (finite_steps G hloc x).fintype + let p : Step G x → {y // y ∈ neighbors G hloc x} := + fun d => ⟨d.val.2, (mem_neighbors G hloc x d.val.2).mpr ⟨d.val.1,d.property⟩⟩ + have hp : Function.Surjective p := by + intro y + obtain ⟨e,he⟩ := (mem_neighbors G hloc x y.val).mp y.property + exact ⟨⟨(e,y.val),he⟩,Subtype.ext rfl⟩ + simpa only [degree,Nat.card_eq_fintype_card,Fintype.card_coe] using + Fintype.card_le_of_surjective p hp + +theorem finiteAdjPairs_source_sum_le (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (K : Finset V) (f : V → ℝ) + (hf : ∀ x, 0 ≤ f x) : + ∑ e ∈ finiteAdjPairs G K, f e.1 ≤ (D:ℝ) * ∑ x ∈ K, f x := by + rw [Finset.mul_sum] + simp only [finiteAdjPairs,Finset.sum_filter,Finset.sum_product] + apply Finset.sum_le_sum + intro x _ + have hc : (K.filter (fun y => Adj G x y)).card ≤ D := by + apply (Finset.card_le_card ?_).trans ((neighbors_card_le_degree G hloc x).trans (hD x)) + intro y hy + exact (mem_neighbors G hloc x y).mpr (Finset.mem_filter.mp hy).2 + calc + (∑ y ∈ K, if Adj G x y then f x else 0) = + ((K.filter (fun y => Adj G x y)).card:ℝ) * f x := by + rw [← Finset.sum_filter] + simp + _ ≤ (D:ℝ) * f x := mul_le_mul_of_nonneg_right (by exact_mod_cast hc) (hf x) + +theorem finiteAdjPairs_square_sum_le (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (S : Finset V) (f : V → ℝ) + (hout : ∀ x ∉ S, f x = 0) : + ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1 + f e.2)^2 ≤ + 4 * (D:ℝ) * ∑ x ∈ S, (f x)^2 := by + let K := neighborClosure G hloc S + let P := finiteAdjPairs G K + have hs : ∑ x ∈ K, (f x)^2 = ∑ x ∈ S, (f x)^2 := by + symm + apply Finset.sum_subset (subset_neighborClosure G hloc S) + intro x _ hx + simp [hout x hx] + have hfirst := finiteAdjPairs_source_sum_le G hloc D hD K (fun x => (f x)^2) (fun _ => sq_nonneg _) + rw [hs] at hfirst + have hsecond := sum_swap_finiteAdjPairs G K (fun e => (f e.1)^2) + change (∑ e ∈ P, (f e.2)^2) = ∑ e ∈ P, (f e.1)^2 at hsecond + calc + (∑ e ∈ P, (f e.1 + f e.2)^2) ≤ ∑ e ∈ P, (2*(f e.1)^2+2*(f e.2)^2) := by + apply Finset.sum_le_sum + intro e _ + nlinarith [sq_nonneg (f e.1 - f e.2)] + _ = 4 * ∑ e ∈ P, (f e.1)^2 := by + rw [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.mul_sum,hsecond] + ring + _ ≤ 4 * (D:ℝ) * ∑ x ∈ S, (f x)^2 := by + nlinarith + + + +theorem bondGraph_cheeger_energy (G : BondGraph V E) (hloc : LocallyFinite G) + (hh : 0 < hV G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (S : Finset V) (f : V → ℝ) (hf : ∀ x, 0 ≤ f x) + (hout : ∀ x ∉ S, f x = 0) : + (hV G)^2 * ∑ x ∈ S, (f x)^2 ≤ + (D:ℝ) * ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := by + let P := finiteAdjPairs G (neighborClosure G hloc S) + let N := ∑ x ∈ S, (f x)^2 + let E := ∑ e ∈ P, (f e.1-f e.2)^2 + have hN : 0 ≤ N := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hE : 0 ≤ E := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hc := bondGraph_coarea G hloc S (fun x => (f x)^2) + (fun _ => sq_nonneg _) (fun x hx => by rw [hout x hx]; norm_num) + have ht (e : V × V) : |(f e.1)^2-(f e.2)^2| = |f e.1-f e.2| * (f e.1+f e.2) := by + rw [show (f e.1)^2-(f e.2)^2 = (f e.1-f e.2)*(f e.1+f e.2) by ring, + abs_mul,abs_of_nonneg (add_nonneg (hf _) (hf _))] + simp_rw [ht] at hc + have hc' : ((2*hV G)*N)^2 ≤ + (∑ e ∈ P, |f e.1-f e.2| * (f e.1+f e.2))^2 := by + exact sq_le_sq₀ (by positivity) (Finset.sum_nonneg (fun e _ => mul_nonneg (abs_nonneg _) + (add_nonneg (hf _) (hf _)))) |>.mpr hc + have hcs := Finset.sum_mul_sq_le_sq_mul_sq P + (fun e => |f e.1-f e.2|) (fun e => f e.1+f e.2) + simp only [sq_abs] at hcs + have hbound := finiteAdjPairs_square_sum_le G hloc D hD S f hout + have hall : ((2*hV G)*N)^2 ≤ E*(4*(D:ℝ)*N) := + (hc'.trans hcs).trans (mul_le_mul_of_nonneg_left hbound hE) + change (hV G)^2*N ≤ (D:ℝ)*E + rcases hN.eq_or_lt with hzero | hpos + · rw [←hzero,mul_zero] + positivity + · apply (mul_le_mul_iff_left₀ (by positivity : 0 < 4*N)).mp + nlinarith [hall] + +end IsoperimetricEnergy + +section FiniteQuadraticForms +attribute [local instance] Classical.propDecidable + +@[simp] theorem finiteEmbedding_inner_left (f : V →₀ ℂ) (g : Hilbert V) : + inner ℂ (finiteEmbedding f) g = ∑ x ∈ f.support, star (f x) * g x := by + simp [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, + lp.inner_single_left, mul_comm] + +@[simp] theorem finiteEmbedding_inner_right (f : Hilbert V) (g : V →₀ ℂ) : + inner ℂ f (finiteEmbedding g) = ∑ x ∈ g.support, star (f x) * g x := by + simp [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, + lp.inner_single_right, mul_comm] + +@[simp] theorem finiteEmbedding_norm_sq (f : V →₀ ℂ) : + ‖finiteEmbedding f‖^2 = ∑ x ∈ f.support, ‖f x‖^2 := by + rw [norm_sq_eq_re_inner (𝕜 := ℂ)] + rw [finiteEmbedding_inner_left] + simp only [map_sum, finiteEmbedding_apply] + apply Finset.sum_congr rfl + intro x _ + simp [← Complex.normSq_eq_norm_sq, Complex.normSq_apply] + + theorem kernel_finiteEmbedding (A : Hilbert V →L[ℂ] Hilbert V) + (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) + (f : V →₀ ℂ) (x : V) : + A (finiteEmbedding f) x = ∑ y ∈ f.support, f y * (U x y : ℂ) := by + simp only [finiteEmbedding, Finsupp.linearCombination_apply, Finsupp.sum, + map_sum, map_smul] + change (∑ y ∈ f.support, f y • A (lp.single 2 y (1 : ℂ))) x = _ + simp only [lp.coeFn_sum, Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, + hA, smul_eq_mul] + + theorem symmetric_of_symmetric_kernel (A : Hilbert V →L[ℂ] Hilbert V) + (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) + (hU : ∀ x y, U x y = U y x) : A.toLinearMap.IsSymmetric := by + apply finiteEmbedding_dense.induction_on₂ + (p := fun f g => inner ℂ (A f) g = inner ℂ f (A g)) + · exact isClosed_eq (by fun_prop) (by fun_prop) + · intro f g + simp only [finiteEmbedding_inner_left, finiteEmbedding_inner_right, + kernel_finiteEmbedding A U hA, map_sum, map_mul, RCLike.star_def, + Complex.conj_ofReal] + simp_rw [Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + rw [hU y x] + ring + + theorem norm_le_of_finite_quadratic (A : Hilbert V →L[ℂ] Hilbert V) + (hA : A.toLinearMap.IsSymmetric) (C : ℝ) (hC : 0 ≤ C) + (h : ∀ f : V →₀ ℂ, + |(inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f)).re| ≤ + C * ‖finiteEmbedding f‖^2) : ‖A‖ ≤ C := by + have hall (f : Hilbert V) : |(inner ℂ (A f) f).re| ≤ C * ‖f‖^2 := by + exact finiteEmbedding_dense.induction_on f + (p := fun g => |(inner ℂ (A g) g).re| ≤ C * ‖g‖^2) + (isClosed_le (by fun_prop) (by fun_prop)) h + rw [A.norm_eq_iSup_rayleighQuotient hA] + apply ciSup_le + intro f + by_cases hf : f = 0 + · simp [hf, hC] + · rw [ContinuousLinearMap.rayleighQuotient, abs_div, abs_sq] + exact (div_le_iff₀ (sq_pos_of_pos (norm_pos_iff.mpr hf))).mpr (hall f) + + theorem abs_inner_kernel_finite_le (A : Hilbert V →L[ℂ] Hilbert V) + (U : V → V → ℝ) (hA : ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ)) + (hU : ∀ x y, 0 ≤ U x y) (f : V →₀ ℂ) : + |(inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f)).re| ≤ + ∑ x ∈ f.support, ∑ y ∈ f.support, ‖f x‖ * ‖f y‖ * U x y := by + change |RCLike.re (inner ℂ (A (finiteEmbedding f)) (finiteEmbedding f))| ≤ _ + rw [inner_re_symm] + apply (Complex.abs_re_le_norm _).trans + rw [finiteEmbedding_inner_left] + simp_rw [kernel_finiteEmbedding A U hA, Finset.mul_sum] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro x _ + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + simp [abs_of_nonneg (hU x y), mul_assoc] + +end FiniteQuadraticForms + +section SymmetricWalk +attribute [local instance] Classical.propDecidable + + + +noncomputable def walkKernel (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (x y : V) : ℝ := + (if x = y then 1 - a * (neighbors G hloc x).card else 0) + + (if Adj G x y then a else 0) + + theorem walkKernel_symmetric (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (x y : V) : walkKernel G hloc a x y = walkKernel G hloc a y x := by + have ha : Adj G x y ↔ Adj G y x := ⟨adj_symm G,adj_symm G⟩ + by_cases h : x = y + · subst y; rfl + · simp [walkKernel,h,Ne.symm h,ha] + + theorem walkKernel_nonneg (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) + (x y : V) : 0 ≤ walkKernel G hloc a x y := by + have hn : ((neighbors G hloc x).card : ℝ) ≤ D := by + exact_mod_cast (neighbors_card_le_degree G hloc x).trans (hD x) + have hh : 0 ≤ 1-a*(neighbors G hloc x).card := by nlinarith + unfold walkKernel + split_ifs <;> positivity + + theorem walkKernel_row_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (x : V) : + ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y = 1 := by + let N := neighbors G hloc x + have hf : (insert x N).filter (fun y => Adj G x y) = N := by + ext y + simp only [Finset.mem_filter, Finset.mem_insert] + rw [mem_neighbors] + exact ⟨fun h => h.2, fun h => ⟨Or.inr h,h⟩⟩ + simp only [walkKernel, Finset.sum_add_distrib] + rw [Finset.sum_ite_eq] + simp only [Finset.mem_insert_self,ite_true] + rw [← Finset.sum_filter,hf] + simp only [Finset.sum_const, nsmul_eq_mul] + dsimp [N] + ring + + theorem walkKernel_row_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) + (x : V) (S : Finset V) : ∑ y ∈ S, walkKernel G hloc a x y ≤ 1 := by + let N := insert x (neighbors G hloc x) + calc + ∑ y ∈ S, walkKernel G hloc a x y ≤ ∑ y ∈ S ∪ N, walkKernel G hloc a x y := + Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_left + (fun y _ _ => walkKernel_nonneg G hloc D hD a ha haD x y) + _ = ∑ y ∈ N, walkKernel G hloc a x y := by + symm + apply Finset.sum_subset Finset.subset_union_right + intro y _ hy + have hxy : x ≠ y := by intro h; subst y; exact hy (by simp [N]) + have hna : ¬ Adj G x y := by intro h; exact hy (by simp [N,h]) + simp [walkKernel,hxy,hna] + _ = 1 := walkKernel_row_sum G hloc a x + + theorem exists_walk_operator (G : BondGraph V E) (hloc : LocallyFinite G) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) : + ∃ P : Hilbert V →L[ℂ] Hilbert V, ‖P‖ ≤ 1 ∧ + P.toLinearMap.IsSymmetric ∧ + ∀ x y, P (lp.single 2 y (1 : ℂ)) x = (walkKernel G hloc a x y : ℂ) := by + obtain ⟨P,hP,hK⟩ := exists_operator_of_row_column_bound (walkKernel G hloc a) 1 + zero_le_one (walkKernel_nonneg G hloc D hD a ha haD) + (walkKernel_row_bound G hloc D hD a ha haD) (by + intro y S + simp_rw [walkKernel_symmetric G hloc a] + exact walkKernel_row_bound G hloc D hD a ha haD y S) + exact ⟨P,hP,symmetric_of_symmetric_kernel P _ hK (walkKernel_symmetric G hloc a),hK⟩ + + theorem finiteAdjPairs_sum (G : BondGraph V E) (K : Finset V) (f : V × V → ℝ) : + (∑ e ∈ finiteAdjPairs G K, f e) = + ∑ x ∈ K, ∑ y ∈ K, if Adj G x y then f (x,y) else 0 := by + simp [finiteAdjPairs,Finset.sum_filter,Finset.sum_product] + + theorem finiteAdjPairs_source_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : + (∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), f e.1) = + ∑ x ∈ S, ((neighbors G hloc x).card : ℝ) * f x := by + let K := neighborClosure G hloc S + rw [finiteAdjPairs_sum] + have he (x : V) (hx : x ∈ S) : + K.filter (fun y => Adj G x y) = neighbors G hloc x := by + ext y + simp only [Finset.mem_filter,mem_neighbors] + exact ⟨fun h => h.2,fun h => ⟨neighbor_mem_neighborClosure G hloc S hx h,h⟩⟩ + have hout' : ∀ x ∉ S, (∑ y ∈ K, if Adj G x y then f x else 0) = 0 := by + intro x hx; simp [hout x hx] + change (∑ x ∈ K, ∑ y ∈ K, if Adj G x y then f x else 0) = _ + rw [← Finset.sum_subset (subset_neighborClosure G hloc S) + (fun x _ hx => hout' x hx)] + apply Finset.sum_congr rfl + intro x hx + rw [← Finset.sum_filter,he x hx] + simp + + theorem finiteAdjPairs_product_sum (G : BondGraph V E) (hloc : LocallyFinite G) + (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : + (∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), f e.1 * f e.2) = + ∑ x ∈ S, ∑ y ∈ S, if Adj G x y then f x*f y else 0 := by + rw [finiteAdjPairs_sum] + have hs := subset_neighborClosure G hloc S + calc + _ = ∑ x ∈ S, ∑ y ∈ neighborClosure G hloc S, + if Adj G x y then f x*f y else 0 := by + symm; apply Finset.sum_subset hs + intro x _ hx; simp [hout x hx] + _ = _ := by + apply Finset.sum_congr rfl + intro x _ + symm; apply Finset.sum_subset hs + intro y _ hy; simp [hout y hy] + + theorem walkKernel_energy (G : BondGraph V E) (hloc : LocallyFinite G) + (a : ℝ) (S : Finset V) (f : V → ℝ) (hout : ∀ x ∉ S, f x = 0) : + (∑ x ∈ S, ∑ y ∈ S, f x*f y*walkKernel G hloc a x y) = + ∑ x ∈ S, (f x)^2 - a/2 * + ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := by + let P := finiteAdjPairs G (neighborClosure G hloc S) + have henergy : (∑ e ∈ P, (f e.1-f e.2)^2) = + 2*(∑ x ∈ S, (neighbors G hloc x).card * (f x)^2) - + 2*(∑ x ∈ S, ∑ y ∈ S, if Adj G x y then f x*f y else 0) := by + have hs := sum_swap_finiteAdjPairs G (neighborClosure G hloc S) + (fun e => (f e.1)^2) + change (∑ e ∈ P,(f e.2)^2) = (∑ e ∈ P,(f e.1)^2) at hs + have hfirst := finiteAdjPairs_source_sum G hloc S (fun x => (f x)^2) + (fun x hx => by rw [hout x hx]; norm_num) + calc + _ = (∑ e ∈ P, (f e.1)^2) + (∑ e ∈ P,(f e.2)^2) - + 2*(∑ e ∈ P,f e.1*f e.2) := by + simp_rw [sub_sq] + rw [Finset.sum_add_distrib,Finset.sum_sub_distrib] + simp_rw [mul_assoc,← Finset.mul_sum] + ring + _ = _ := by rw [hs,hfirst,finiteAdjPairs_product_sum G hloc S f hout]; ring + rw [henergy] + have hpoint (x : V) (hx : x ∈ S) : + (∑ y ∈ S, f x*f y*walkKernel G hloc a x y) = + (f x)^2 - a*((neighbors G hloc x).card*(f x)^2) + + a*(∑ y ∈ S, if Adj G x y then f x*f y else 0) := by + simp only [walkKernel,mul_add,Finset.sum_add_distrib] + have hi : (∑ y ∈ S, f x*f y*(if x=y then 1-a*(neighbors G hloc x).card else 0)) = + (f x)^2*(1-a*(neighbors G hloc x).card) := by + simp_rw [mul_ite,mul_zero] + rw [Finset.sum_ite_eq] + simp only [hx,ite_true] + ring + rw [hi,Finset.mul_sum] + have hj : (∑ y ∈ S, f x*f y*(if Adj G x y then a else 0)) = + ∑ y ∈ S, a*(if Adj G x y then f x*f y else 0) := by + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> ring + rw [hj] + ring + simp_rw [Finset.sum_congr rfl hpoint,Finset.sum_add_distrib, + Finset.sum_sub_distrib,←Finset.mul_sum] + ring + + + +theorem walkKernel_quadratic_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (hh : 0 < hV G) (D : ℕ) (hDp : 0 < D) (hD : ∀ x, degree G x ≤ D) + (a : ℝ) (ha : 0 ≤ a) (S : Finset V) (f : V → ℝ) + (hf : ∀ x, 0 ≤ f x) (hout : ∀ x ∉ S, f x = 0) : + (∑ x ∈ S, ∑ y ∈ S, f x*f y*walkKernel G hloc a x y) ≤ + (1 - a*(hV G)^2/(2*D)) * ∑ x ∈ S, (f x)^2 := by + have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp + have hc := bondGraph_cheeger_energy G hloc hh D hD S f hf hout + have he : ((hV G)^2 * ∑ x ∈ S, (f x)^2)/(D:ℝ) ≤ + ∑ e ∈ finiteAdjPairs G (neighborClosure G hloc S), (f e.1-f e.2)^2 := + (div_le_iff₀ hDp').mpr (by simpa only [mul_comm] using hc) + rw [walkKernel_energy G hloc a S f hout] + calc + _ ≤ (∑ x ∈ S, (f x)^2) - a/2 * + (((hV G)^2 * ∑ x ∈ S, (f x)^2)/(D:ℝ)) := + sub_le_sub_left (mul_le_mul_of_nonneg_left he (by positivity)) _ + _ = _ := by ring + + + +theorem walk_operator_norm_lt_one (G : BondGraph V E) (hloc : LocallyFinite G) + (hh : 0 < hV G) (D : ℕ) (hDp : 0 < D) (hD : ∀ x, degree G x ≤ D) + (a : ℝ) (ha : 0 < a) (haD : a*D ≤ 1) + (P : Hilbert V →L[ℂ] Hilbert V) + (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) : + ‖P‖ < 1 := by + let C := max 0 (1-a*(hV G)^2/(2*D)) + have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp + have hC : 0 ≤ C := le_max_left _ _ + have hC1 : C < 1 := by + apply max_lt (by norm_num) + have : 0 < a*(hV G)^2/(2*D) := by positivity + linarith + have hn : ‖P‖ ≤ C := by + apply norm_le_of_finite_quadratic P + (symmetric_of_symmetric_kernel P _ hP (walkKernel_symmetric G hloc a)) C hC + intro f + calc + _ ≤ ∑ x ∈ f.support, ∑ y ∈ f.support, ‖f x‖*‖f y‖*walkKernel G hloc a x y := + abs_inner_kernel_finite_le P _ hP (walkKernel_nonneg G hloc D hD a ha.le haD) f + _ ≤ (1-a*(hV G)^2/(2*D)) * ∑ x ∈ f.support, ‖f x‖^2 := + walkKernel_quadratic_bound G hloc hh D hDp hD a ha.le f.support + (fun x => ‖f x‖) (fun _ => norm_nonneg _) (by + intro x hx; simp [Finsupp.notMem_support_iff.mp hx]) + _ ≤ C * ∑ x ∈ f.support, ‖f x‖^2 := + mul_le_mul_of_nonneg_right (le_max_right _ _) (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + _ = C * ‖finiteEmbedding f‖^2 := by rw [finiteEmbedding_norm_sq] + exact hn.trans_lt hC1 + + + +theorem exists_strict_walk_operator (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) : + ∃ (D : ℕ) (P : Hilbert V →L[ℂ] Hilbert V), 0 < D ∧ + (∀ x, degree G x ≤ D) ∧ ‖P‖ < 1 ∧ P.toLinearMap.IsSymmetric ∧ + ∀ x y, P (lp.single 2 y (1:ℂ)) x = + (walkKernel G hloc (1/(2*(D:ℝ))) x y : ℂ) := by + obtain ⟨D,hDp,hD⟩ := exists_degree_bound G hqt + have hDp' : 0 < (D:ℝ) := by exact_mod_cast hDp + have ha : 0 < (1:ℝ)/(2*D) := by positivity + have haD : (1:ℝ)/(2*D)*D ≤ 1 := by + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity)).mpr + nlinarith + obtain ⟨P,_,hPs,hP⟩ := exists_walk_operator G hloc D hD _ ha.le haD + exact ⟨D,P,hDp,hD,walk_operator_norm_lt_one G hloc hh D hDp hD _ ha haD P hP,hPs,hP⟩ + +end SymmetricWalk + +section PositiveConnectionKernel +open scoped ComplexOrder Matrix +attribute [local instance] Classical.propDecidable + + + +theorem equivalenceMatrix_posSemidef {α : Type*} [Fintype α] (R : Setoid α) : + Matrix.PosSemidef (fun x y => if R.r x y then (1:ℂ) else 0) := by + classical + let : Fintype (Quotient R) := Fintype.ofFinite (Quotient R) + let J : Matrix (Quotient R) α ℂ := fun q x => if q = Quotient.mk R x then 1 else 0 + have hJ : Jᴴ * J = (fun x y => if R.r x y then (1:ℂ) else 0) := by + ext x y + change (∑ q : Quotient R, star (J q x) * J q y) = _ + have hr : R.r y x ↔ R.r x y := ⟨R.symm, R.symm⟩ + simp [J, Quotient.eq, hr] + rw [← hJ] + exact Matrix.posSemidef_conjTranspose_mul_self J + +theorem connection_quadratic_nonneg (G : BondGraph V E) (ω : Set E) + (S : Finset V) (f : V → ℂ) : + 0 ≤ ∑ x ∈ S, ∑ y ∈ S, + star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y := by + classical + let R : Setoid S := ⟨fun x y => Conn G ω x y, + ⟨fun x => conn_refl G ω x, fun h => conn_symm G ω h, fun h h' => conn_trans G ω h h'⟩⟩ + have h := (equivalenceMatrix_posSemidef R).dotProduct_mulVec_nonneg + (fun x : S => f x) + simp only [dotProduct, Matrix.mulVec, Finset.mul_sum, Pi.star_apply] at h + change 0 ≤ ∑ x : S, ∑ y : S, + star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y) at h + have he : (∑ x : S, ∑ y : S, + star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y)) = + ∑ x ∈ S, ∑ y ∈ S, + star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y) := by + rw [Finset.sum_coe_sort S (fun x => ∑ y : S, + star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y))] + apply Finset.sum_congr rfl + intro x _ + exact Finset.sum_coe_sort S (fun y => + star (f x) * ((if Conn G ω x y then (1:ℂ) else 0) * f y)) + rw [he] at h + simpa only [mul_assoc] using h + +variable [Countable V] [Countable E] + +theorem conn_indicator_integrable (G : BondGraph V E) (p : unitInterval) (x y : V) : + Integrable (fun ω => if Conn G ω x y then (1:ℂ) else 0) (law p) := by + change Integrable ({ω | Conn G ω x y}.indicator (fun _ => (1:ℂ))) (law p) + exact (integrable_const (1:ℂ)).indicator (measurableSet_conn G x y) + +theorem twoPoint_eq_integral (G : BondGraph V E) (p : unitInterval) (x y : V) : + (twoPoint G p x y : ℂ) = + ∫ ω, (if Conn G ω x y then (1:ℂ) else 0) ∂law p := by + simpa only [Set.indicator, Set.mem_ofPred_eq, Measure.real, twoPoint, + Complex.real_smul, mul_one] using + (integral_indicator_const (μ := law p) (1:ℂ) (measurableSet_conn G x y)).symm + +theorem twoPoint_quadratic_nonneg (G : BondGraph V E) (p : unitInterval) + (S : Finset V) (f : V → ℂ) : + 0 ≤ ∑ x ∈ S, ∑ y ∈ S, star (f x) * (twoPoint G p x y : ℂ) * f y := by + have hi (x y : V) : Integrable + (fun ω => star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y) (law p) := + ((conn_indicator_integrable G p x y).const_mul _).mul_const _ + have hsum : (∑ x ∈ S, ∑ y ∈ S, star (f x) * (twoPoint G p x y : ℂ) * f y) = + ∫ ω, ∑ x ∈ S, ∑ y ∈ S, + star (f x) * (if Conn G ω x y then (1:ℂ) else 0) * f y ∂law p := by + rw [integral_finsetSum S (fun x _ => integrable_finsetSum S (fun y _ => hi x y))] + apply Finset.sum_congr rfl + intro x _ + rw [integral_finsetSum S (fun y _ => hi x y)] + apply Finset.sum_congr rfl + intro y _ + rw [integral_mul_const, integral_const_mul, twoPoint_eq_integral] + rw [hsum] + exact integral_nonneg (fun ω => connection_quadratic_nonneg G ω S f) + + + +theorem HasKernel.isPositive (G : BondGraph V E) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) : A.IsPositive := by + have hs : A.toLinearMap.IsSymmetric := + symmetric_of_symmetric_kernel A (twoPoint G p) (fun x y => hA x y) (twoPoint_symm G p) + refine ⟨hs, ?_⟩ + intro f + apply finiteEmbedding_dense.induction_on f + (p := fun g => 0 ≤ (inner ℂ (A g) g).re) + · exact isClosed_le continuous_const (by fun_prop) + · intro g + rw [show inner ℂ (A (finiteEmbedding g)) (finiteEmbedding g) = + inner ℂ (finiteEmbedding g) (A (finiteEmbedding g)) from hs _ _, finiteEmbedding_inner_left] + simp only [kernel_finiteEmbedding A (twoPoint G p) (fun x y => hA x y)] + simp_rw [Finset.mul_sum] + have h := twoPoint_quadratic_nonneg G p g.support g + apply Complex.nonneg_iff.mp at h + convert h.1 using 1 + congr 1 + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +end PositiveConnectionKernel + +section InvariantOperatorTrace +open scoped ComplexOrder InnerProduct +attribute [local instance] Classical.propDecidable +local instance spectralRealOperatorScalarTower : + IsScalarTower ℝ (Hilbert V →L[ℂ] Hilbert V) (Hilbert V →L[ℂ] Hilbert V) where + smul_assoc scalar first second := by + ext vector vertex + rfl +local instance spectralRealOperatorSMulCommClass : + SMulCommClass ℝ (Hilbert V →L[ℂ] Hilbert V) (Hilbert V →L[ℂ] Hilbert V) where + smul_comm scalar first second := by + apply ContinuousLinearMap.ext + intro vector + exact (first.map_smul_of_tower scalar (second vector)).symm +local instance spectralNonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +local instance spectralContinuousFunctionalCalculus : ContinuousFunctionalCalculus ℝ + (Hilbert V →L[ℂ] Hilbert V) IsSelfAdjoint := + IsSelfAdjoint.instContinuousFunctionalCalculus (A := Hilbert V →L[ℂ] Hilbert V) +noncomputable def permuteHilbert (a : V ≃ V) : Hilbert V ≃ₗᵢ[ℂ] Hilbert V where + toFun f := ⟨fun x => f (a.symm x), by + apply memℓp_gen + exact a.symm.summable_iff.mpr (lp.memℓp f |>.summable (by norm_num))⟩ + invFun f := ⟨fun x => f (a x), by + apply memℓp_gen + exact a.summable_iff.mpr (lp.memℓp f |>.summable (by norm_num))⟩ + left_inv f := by ext x; simp + right_inv f := by ext x; simp + map_add' f g := by ext x; rfl + map_smul' c f := by ext x; rfl + norm_map' f := by + rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] + congr 1 + exact a.symm.tsum_eq (fun x => ‖f x‖ ^ (2:ℝ≥0∞).toReal) + +@[simp] theorem permuteHilbert_apply (a : V ≃ V) (f : Hilbert V) (x : V) : + permuteHilbert a f x = f (a.symm x) := rfl + +@[simp] theorem permuteHilbert_single (a : V ≃ V) (x : V) (c : ℂ) : + permuteHilbert a (lp.single 2 x c) = lp.single 2 (a x) c := by + ext y + simp only [permuteHilbert_apply, lp.coeFn_single] + simp [Pi.single_apply, eq_comm, Equiv.eq_symm_apply] + +noncomputable def matrixCoeff (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : ℂ := + A (lp.single 2 y (1:ℂ)) x + +@[simp] theorem matrixCoeff_eq_inner (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + matrixCoeff A x y = inner ℂ (lp.single 2 x (1:ℂ)) (A (lp.single 2 y (1:ℂ))) := by + simp [matrixCoeff,lp.inner_single_left] + +theorem operator_kernel_hasSum (A : Hilbert V →L[ℂ] Hilbert V) (f : Hilbert V) (x : V) : + HasSum (fun y => matrixCoeff A x y * f y) (A f x) := by + have h := ((lp.evalCLM ℂ (fun _ : V => ℂ) 2 x).comp A).hasSum + (lp.hasSum_single (by norm_num : (2:ℝ≥0∞) ≠ ⊤) f) + change HasSum (fun y => A (lp.single 2 y (f y)) x) (A f x) at h + have heq : (fun y : V => A (lp.single 2 y (f y)) x) = + (fun y => matrixCoeff A x y * f y) := by + funext y + have he : lp.single (E := fun _ : V => ℂ) 2 y (f y) = + f y • lp.single 2 y (1:ℂ) := by + rw [← lp.single_smul]; simp + simp [he, matrixCoeff, mul_comm] + rw [heq] at h + exact h + +@[simp] theorem matrixCoeff_mul (A B : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + matrixCoeff (A*B) x y = ∑' z, matrixCoeff A x z * matrixCoeff B z y := by + exact (operator_kernel_hasSum A (B (lp.single 2 y (1:ℂ))) x).tsum_eq.symm + +@[simp] theorem matrixCoeff_adjoint (A : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + matrixCoeff (star A) x y = star (matrixCoeff A y x) := by + rw [matrixCoeff_eq_inner, matrixCoeff_eq_inner] + change inner ℂ _ ((ContinuousLinearMap.adjoint A) _) = _ + rw [ContinuousLinearMap.adjoint_inner_right] + simpa only [RCLike.star_def] using + (inner_conj_symm (A (lp.single 2 x (1:ℂ))) (lp.single 2 y (1:ℂ))).symm + + +theorem matrixCoeff_invariant_iff (a : V ≃ V) (A : Hilbert V →L[ℂ] Hilbert V) : + (∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) ↔ + Commute A (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap := by + constructor + · intro h + change A * (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap = + (permuteHilbert a).toContinuousLinearEquiv.toContinuousLinearMap * A + apply lp.ext_continuousLinearMap (by norm_num : (2:ℝ≥0∞) ≠ ⊤) + intro y + apply ContinuousLinearMap.ext + intro c + ext x + have hs : lp.single (E := fun _ : V => ℂ) 2 y c = + c • lp.single 2 y (1:ℂ) := by rw [← lp.single_smul]; simp + have hh := h (a.symm x) y + simp only [Equiv.apply_symm_apply] at hh + change A (permuteHilbert a (lp.single 2 y c)) x = + permuteHilbert a (A (lp.single 2 y c)) x + rw [hs] + simp only [map_smul, permuteHilbert_single, lp.coeFn_smul, Pi.smul_apply, + permuteHilbert_apply] + change c * matrixCoeff A x (a y) = c * matrixCoeff A (a.symm x) y + rw [hh] + · intro h x y + have hh := congrArg (fun F : Hilbert V →L[ℂ] Hilbert V => + F (lp.single 2 y (1:ℂ)) (a x)) h.eq + simpa only [mul_apply_eq_comp, LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe, permuteHilbert_single, permuteHilbert_apply, + Equiv.symm_apply_apply, matrixCoeff] using hh + + theorem matrixCoeff_sqrt_invariant (a : V ≃ V) (A : Hilbert V →L[ℂ] Hilbert V) + (h : ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) : + ∀ x y, matrixCoeff (CFC.sqrt A) (a x) (a y) = matrixCoeff (CFC.sqrt A) x y := by + apply (matrixCoeff_invariant_iff a _).mpr + rw [CFC.sqrt_eq_cfc] + exact ((matrixCoeff_invariant_iff a A).mp h).cfc_nnreal NNReal.sqrt + + theorem matrixCoeff_mul_invariant (a : V ≃ V) (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y) + (hB : ∀ x y, matrixCoeff B (a x) (a y) = matrixCoeff B x y) : + ∀ x y, matrixCoeff (A*B) (a x) (a y) = matrixCoeff (A*B) x y := by + intro x y + simp only [matrixCoeff_mul] + rw [← a.tsum_eq (fun z => matrixCoeff A (a x) z * matrixCoeff B z (a y))] + simp only [hA,hB] + + theorem matrixCoeff_nonneg (A : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) (x : V) : + 0 ≤ matrixCoeff A x x := by + rw [matrixCoeff_eq_inner] + exact (ContinuousLinearMap.nonneg_iff_isPositive |>.mp hA).inner_nonneg_right _ + + theorem matrixCoeff_mono {A B : Hilbert V →L[ℂ] Hilbert V} (h : A ≤ B) (x : V) : + matrixCoeff A x x ≤ matrixCoeff B x x := by + have hh := matrixCoeff_nonneg (B-A) (sub_nonneg.mpr h) x + simpa only [matrixCoeff, sub_apply, lp.coeFn_sub, + Pi.sub_apply, sub_nonneg] using hh + +section RootTrace +variable {ι : Type*} [Fintype ι] +variable (root : ι → V) (weight : ι → ℝ) + +noncomputable def rootTrace (A : Hilbert V →L[ℂ] Hilbert V) : ℂ := + ∑ i, (weight i : ℂ) * matrixCoeff A (root i) (root i) + +@[simp] theorem rootTrace_add (A B : Hilbert V →L[ℂ] Hilbert V) : + rootTrace root weight (A+B) = rootTrace root weight A + rootTrace root weight B := by + simp [rootTrace, matrixCoeff, add_apply, mul_add, Finset.sum_add_distrib] + +@[simp] theorem rootTrace_smul (c : ℂ) (A : Hilbert V →L[ℂ] Hilbert V) : + rootTrace root weight (c • A) = c * rootTrace root weight A := by + simp [rootTrace, matrixCoeff, smul_apply, ← Finset.mul_sum, mul_left_comm] + +theorem rootTrace_nonneg (hw : ∀ i, 0 ≤ weight i) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) : 0 ≤ rootTrace root weight A := by + exact Finset.sum_nonneg fun i _ => mul_nonneg (by simpa using hw i) + (matrixCoeff_nonneg A hA (root i)) + +theorem rootTrace_mono (hw : ∀ i, 0 ≤ weight i) + {A B : Hilbert V →L[ℂ] Hilbert V} (h : A ≤ B) : + rootTrace root weight A ≤ rootTrace root weight B := by + apply Finset.sum_le_sum + intro i _ + exact mul_le_mul_of_nonneg_left (matrixCoeff_mono h (root i)) (by simpa using hw i) + +@[simp] theorem rootTrace_one (hw : ∑ i, weight i = 1) : + rootTrace root weight (1 : Hilbert V →L[ℂ] Hilbert V) = 1 := by + simpa [rootTrace, matrixCoeff, lp.coeFn_single, ← Complex.ofReal_sum] using + congrArg (fun t : ℝ => (t : ℂ)) hw + + +def KernelInvariant (Γ : Set (V ≃ V)) (A : Hilbert V →L[ℂ] Hilbert V) : Prop := + ∀ a ∈ Γ, ∀ x y, matrixCoeff A (a x) (a y) = matrixCoeff A x y + +theorem KernelInvariant.mul {Γ : Set (V ≃ V)} + {A B : Hilbert V →L[ℂ] Hilbert V} + (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) : + KernelInvariant Γ (A*B) := by + intro a ha + exact matrixCoeff_mul_invariant a A B (hA a ha) (hB a ha) + +theorem KernelInvariant.star {Γ : Set (V ≃ V)} + {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) : + KernelInvariant Γ (star A) := by + intro a ha x y + simp only [matrixCoeff_adjoint, hA a ha] + +theorem KernelInvariant.sqrt {Γ : Set (V ≃ V)} + {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) : + KernelInvariant Γ (CFC.sqrt A) := by + intro a ha + exact matrixCoeff_sqrt_invariant a A (hA a ha) + + + +def RootTransport (Γ : Set (V ≃ V)) : Prop := + ∀ m : V → V → ℂ, + (∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) → + (∀ x, Summable (m x)) → (∀ y, Summable (fun x => m x y)) → + (∑ i, (weight i : ℂ) * ∑' y, m (root i) y) = + (∑ i, (weight i : ℂ) * ∑' x, m x (root i)) + +theorem rootTrace_cyclic {Γ : Set (V ≃ V)} + (htr : RootTransport root weight Γ) + (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) : + rootTrace root weight (A*B) = rootTrace root weight (B*A) := by + have ht := htr (fun x y => matrixCoeff A x y * matrixCoeff B y x) + (by intro a ha x y; rw [hA a ha, hB a ha]) + (fun x => (operator_kernel_hasSum A (B (lp.single 2 x (1:ℂ))) x).summable) + (fun y => by + simpa only [matrixCoeff, mul_comm] using + (operator_kernel_hasSum B (A (lp.single 2 y (1:ℂ))) y).summable) + simpa only [rootTrace, matrixCoeff_mul, mul_comm] using ht + +theorem rootTrace_diag_le {Γ : Set (V ≃ V)} + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (c : ℝ) (hc : 0 ≤ c) + (hmin : ∀ i, 1 ≤ c * weight i) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : KernelInvariant Γ A) + (hApos : 0 ≤ A) (x : V) : + matrixCoeff A x x ≤ (c : ℂ) * rootTrace root weight A := by + obtain ⟨i,a,ha,hax⟩ := hcov x + have hi : (weight i : ℂ) * matrixCoeff A (root i) (root i) ≤ + rootTrace root weight A := by + unfold rootTrace + exact Finset.single_le_sum (s := Finset.univ) + (f := fun j => (weight j : ℂ) * matrixCoeff A (root j) (root j)) + (fun j _ => mul_nonneg (by simpa using hw j) (matrixCoeff_nonneg A hApos _)) + (Finset.mem_univ i) + calc + matrixCoeff A x x = matrixCoeff A (root i) (root i) := by + rw [← hax, hA a ha] + _ ≤ (c * weight i : ℝ) * matrixCoeff A (root i) (root i) := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right + (show (1:ℂ) ≤ ((c * weight i : ℝ) : ℂ) by exact_mod_cast hmin i) + (matrixCoeff_nonneg A hApos (root i)) + _ = (c : ℂ) * ((weight i : ℂ) * matrixCoeff A (root i) (root i)) := by + push_cast; ring + _ ≤ (c : ℂ) * rootTrace root weight A := + mul_le_mul_of_nonneg_left hi (by exact_mod_cast hc) + +@[simp] theorem rootTrace_real_smul (c : ℝ) (A : Hilbert V →L[ℂ] Hilbert V) : + rootTrace root weight (c • A) = (c : ℂ) * rootTrace root weight A := by + simp [rootTrace, matrixCoeff, smul_apply, Complex.real_smul, + ← Finset.mul_sum, mul_left_comm] + +theorem rootTrace_positive_mul_le {Γ : Set (V ≃ V)} + (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) + (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) + (hApos : 0 ≤ A) (hBsa : IsSelfAdjoint B) : + rootTrace root weight (B*A) ≤ (‖B‖ : ℂ) * rootTrace root weight A := by + let S := CFC.sqrt A + have hS : S*S = A := CFC.sqrt_mul_sqrt_self A hApos + have hSstar : star S = S := (IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg A)).star_eq + have hSI : KernelInvariant Γ S := hA.sqrt + have hbound : S*B*S ≤ ‖B‖ • A := by + convert (CStarAlgebra.star_left_conjugate_le_norm_smul (a := S) (b := B) hBsa) using 1 + · rw [hSstar] + · rw [hSstar, hS] + ext f x + rfl + calc + rootTrace root weight (B*A) = rootTrace root weight (S*(B*S)) := by + rw [rootTrace_cyclic root weight htr S (B*S) hSI (hB.mul hSI)] + rw [mul_assoc, hS] + _ = rootTrace root weight (S*B*S) := by rw [mul_assoc] + _ ≤ rootTrace root weight (‖B‖ • A) := rootTrace_mono root weight hw hbound + _ = (‖B‖ : ℂ) * rootTrace root weight A := rootTrace_real_smul root weight _ _ + +theorem rootTrace_conjugate_le {Γ : Set (V ≃ V)} + (htr : RootTransport root weight Γ) (hw : ∀ i, 0 ≤ weight i) + (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) + (hApos : 0 ≤ A) : + rootTrace root weight (B*A*star B) ≤ ((‖B‖ ^ 2 : ℝ) : ℂ) * rootTrace root weight A := by + calc + rootTrace root weight (B*A*star B) = rootTrace root weight (star B*(B*A)) := + rootTrace_cyclic root weight htr (B*A) (star B) (hB.mul hA) hB.star + _ = rootTrace root weight ((star B*B)*A) := by rw [mul_assoc] + _ ≤ (‖star B*B‖ : ℂ) * rootTrace root weight A := + rootTrace_positive_mul_le root weight htr hw A (star B*B) hA (hB.star.mul hB) + hApos (IsSelfAdjoint.of_nonneg (star_mul_self_nonneg B)) + _ = ((‖B‖ ^ 2 : ℝ) : ℂ) * rootTrace root weight A := by + have hnorm := CStarRing.norm_star_mul_self (x := B) + have hn : ‖star B * B‖ = ‖B‖ ^ 2 := by + convert hnorm using 1; simp only [pow_two] + rw [hn] + + theorem matrixCoeff_gram (L M : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + matrixCoeff (L*star M) x y = + inner ℂ (star L (lp.single 2 x (1:ℂ))) (star M (lp.single 2 y (1:ℂ))) := by + rw [matrixCoeff_eq_inner] + change inner ℂ _ (L ((ContinuousLinearMap.adjoint M) _)) = _ + rw [← ContinuousLinearMap.adjoint_inner_left] + rfl + + theorem matrixCoeff_gram_norm_sq_le + (L M : Hilbert V →L[ℂ] Hilbert V) (x y : V) : + ‖matrixCoeff (L*star M) x y‖ ^ 2 ≤ + (matrixCoeff (L*star L) x x).re * (matrixCoeff (M*star M) y y).re := by + simp only [matrixCoeff_gram] + have h := inner_mul_inner_self_le (𝕜 := ℂ) + (star L (lp.single 2 x (1:ℂ))) (star M (lp.single 2 y (1:ℂ))) + rw [norm_inner_symm (star M (lp.single 2 y (1:ℂ)))] at h + simpa only [pow_two, RCLike.re_to_complex] using h + + theorem matrixCoeff_positive_product_norm_sq_le + (A B : Hilbert V →L[ℂ] Hilbert V) (hA : 0 ≤ A) (x y : V) : + ‖matrixCoeff (B*A) x y‖ ^ 2 ≤ + (matrixCoeff (B*A*star B) x x).re * (matrixCoeff A y y).re := by + let S := CFC.sqrt A + have hSS : S*S = A := CFC.sqrt_mul_sqrt_self A hA + have hSstar : star S = S := (IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg A)).star_eq + convert matrixCoeff_gram_norm_sq_le (B*S) S x y using 1 <;> + simp only [star_mul, hSstar, mul_assoc, ← mul_assoc S S, hSS] + + + +theorem matrixCoeff_smoothing {Γ : Set (V ≃ V)} + (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) + (A B : Hilbert V →L[ℂ] Hilbert V) + (hA : KernelInvariant Γ A) (hB : KernelInvariant Γ B) + (hApos : 0 ≤ A) (hdiag : ∀ y, matrixCoeff A y y = 1) (x y : V) : + ‖matrixCoeff (B*A) x y‖ ≤ Real.sqrt c * ‖B‖ := by + have htA : rootTrace root weight A = 1 := by + simp only [rootTrace, hdiag, mul_one, ← Complex.ofReal_sum, hsum, Complex.ofReal_one] + have hD : 0 ≤ B*A*star B := star_right_conjugate_nonneg hApos B + have hi : KernelInvariant Γ (B*A*star B) := (hB.mul hA).mul hB.star + have ht := rootTrace_conjugate_le root weight htr hw A B hA hB hApos + rw [htA, mul_one] at ht + have hd : matrixCoeff (B*A*star B) x x ≤ ((c * ‖B‖^2 : ℝ) : ℂ) := by + calc + _ ≤ (c : ℂ) * rootTrace root weight (B*A*star B) := + rootTrace_diag_le root weight hcov hw c hc hmin _ hi hD x + _ ≤ (c : ℂ) * ((‖B‖^2 : ℝ) : ℂ) := + mul_le_mul_of_nonneg_left ht (by exact_mod_cast hc) + _ = _ := by push_cast; rfl + have hd' : (matrixCoeff (B*A*star B) x x).re ≤ c * ‖B‖^2 := + (Complex.le_def.mp hd).1 + have hs : ‖matrixCoeff (B*A) x y‖ ^ 2 ≤ c * ‖B‖ ^ 2 := by + have hh := matrixCoeff_positive_product_norm_sq_le A B hApos x y + rw [hdiag, Complex.one_re, mul_one] at hh + exact hh.trans hd' + apply (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _))).mp + rwa [mul_pow, Real.sq_sqrt hc] + +end RootTrace + +end InvariantOperatorTrace + +section InvariantPercolationOperators +open scoped ComplexOrder InnerProduct +attribute [local instance] Classical.propDecidable + + +def vertexAut (G : BondGraph V E) : Set (V ≃ V) := {a | ∃ b : E ≃ E, IsAut G a b} + +theorem twoPoint_aut [Countable V] [Countable E] (G : BondGraph V E) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x y : V) : + twoPoint G p (a x) (a y) = twoPoint G p x y := by + have he : {ω | Conn G ω (a x) (a y)} = + (fun ω => b ⁻¹' ω) ⁻¹' {ω | Conn G ω x y} := by + ext ω + exact (conn_aut_iff G h ω x y).symm + unfold twoPoint + rw [he, ← Measure.map_apply (measurable_set_preimage b) + (measurableSet_conn G x y), law_map_preimage_equiv] + +theorem HasKernel.invariant [Countable V] [Countable E] (G : BondGraph V E) (p : unitInterval) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) : + KernelInvariant (vertexAut G) A := by + rintro a ⟨b, hab⟩ x y + change A (lp.single 2 (a y) (1:ℂ)) (a x) = A (lp.single 2 y (1:ℂ)) x + rw [hA, hA, twoPoint_aut G p hab] + +theorem KernelInvariant.one (Γ : Set (V ≃ V)) : + KernelInvariant Γ (1 : Hilbert V →L[ℂ] Hilbert V) := by + intro a _ x y + simp only [matrixCoeff, one_apply_eq_self, lp.coeFn_single] + simp [Pi.single_apply, a.injective.eq_iff] + +theorem KernelInvariant.pow {Γ : Set (V ≃ V)} + {A : Hilbert V →L[ℂ] Hilbert V} (hA : KernelInvariant Γ A) (n : ℕ) : + KernelInvariant Γ (A^n) := by + induction n with + | zero => simpa only [pow_zero] using KernelInvariant.one Γ + | succ n ih => simpa only [pow_succ] using ih.mul hA + + + +theorem twoPoint_operator_smoothing [Countable V] [Countable E] [Nonempty V] {ι : Type*} [Fintype ι] + (G : BondGraph V E) (p : unitInterval) (root : ι → V) (weight : ι → ℝ) + (htr : RootTransport root weight (vertexAut G)) + (hcov : ∀ x, ∃ i, ∃ a ∈ vertexAut G, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hsum : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c * weight i) + (A P : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) + (hP : KernelInvariant (vertexAut G) P) (l : ℕ) (x y : V) : + ‖matrixCoeff (P^l*A) x y‖ ≤ Real.sqrt c * ‖P‖^l := by + have hdiag (y : V) : matrixCoeff A y y = 1 := by + change A (lp.single 2 y (1:ℂ)) y = 1 + rw [hA y y, twoPoint_self, Complex.ofReal_one] + have h := matrixCoeff_smoothing root weight htr hcov hw hsum c hc hmin A (P^l) + (hA.invariant G p A) (hP.pow l) (ContinuousLinearMap.nonneg_iff_isPositive.mpr + (hA.isPositive G p A)) hdiag x y + have hn (n : ℕ) : ‖P^n‖ ≤ ‖P‖^n := by + induction n with + | zero => simpa only [pow_zero, ContinuousLinearMap.one_def] using (ContinuousLinearMap.norm_id_le (𝕜 := ℂ) (E := Hilbert V)) + | succ n ih => + rw [pow_succ, pow_succ] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right ih (norm_nonneg P)) + exact h.trans (mul_le_mul_of_nonneg_left (hn l) (Real.sqrt_nonneg c)) +end InvariantPercolationOperators + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/Sprinkling.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/Sprinkling.lean index 753a5c5756a491db8b4f46ac514c01c4c473de29..575402ef5017ea7418e6d807ecbed88b344572eb 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/Sprinkling.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/Sprinkling.lean @@ -1,840 +1,840 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Graph.Paths - -namespace OAI - -/-! Sprinkling estimates for finite and infinite graph operators. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section SprinklingLaw -attribute [local instance] Classical.propDecidable - -noncomputable def sprinkleParameter (p a : unitInterval) : unitInterval := - ⟨(p : ℝ) + (1-p)*a, by - constructor - · exact add_nonneg p.2.1 (mul_nonneg (sub_nonneg.mpr p.2.2) a.2.1) - · nlinarith [mul_nonneg (sub_nonneg.mpr p.2.2) (sub_nonneg.mpr a.2.2)]⟩ - - def pairParameter (p a : unitInterval) (b : Bool) : unitInterval := if b then p else a - - theorem map_bool_or (p a : unitInterval) : - (Measure.infinitePi (fun b : Bool => bitLaw (pairParameter p a b))).map - (fun f : Bool → Prop => ∃ b, f b) = bitLaw (sprinkleParameter p a) := by - let μ := (Measure.infinitePi (fun b : Bool => bitLaw (pairParameter p a b))).map - (fun f : Bool → Prop => ∃ b, f b) - have hm : Measurable (fun f : Bool → Prop => ∃ b, f b) := .of_discrete - have : IsProbabilityMeasure μ := inferInstance - have hf : μ.real {False} = (1-(p : ℝ)) * (1-(a : ℝ)) := by - change ((Measure.infinitePi _).map _).real _ = _ - rw [Measure.real, Measure.map_apply hm (measurableSet_singleton _)] - have he : (fun f : Bool → Prop => ∃ b, f b) ⁻¹' ({False} : Set Prop) = - ((Finset.univ : Finset Bool) : Set Bool).pi (fun _ => ({False} : Set Prop)) := by - ext f - simp [and_comm] - rw [he, Measure.infinitePi_pi _ (fun _ _ => measurableSet_singleton _)] - simp [pairParameter, bitLaw, ENNReal.toReal_mul] - have ht : μ.real {True} = (p : ℝ) + (1-p)*a := by - have he : ({True} : Set Prop) = ({False} : Set Prop)ᶜ := by ext b; simp - rw [he, measureReal_compl (measurableSet_singleton _), probReal_univ, hf] - ring - apply Measure.ext_of_singleton - intro b - apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp - change μ.real {b} = (bitLaw (sprinkleParameter p a)).real {b} - by_cases hb : b - · have he : b = True := propext (iff_true_intro hb) - subst b - rw [ht] - simp [bitLaw, Measure.real, sprinkleParameter] - · have he : b = False := propext (iff_false_intro hb) - subst b - rw [hf] - simp [bitLaw, Measure.real, sprinkleParameter] - ring - -noncomputable def fieldLaw (p a : unitInterval) : Measure (Bool → Set E) := - Measure.infinitePi (fun b => law (pairParameter p a b)) - -def fieldUnion (f : Bool → Set E) : Set E := f true ∪ f false - - theorem measurable_fieldUnion : Measurable (fieldUnion : (Bool → Set E) → Set E) := by - have hm (e : E) : Measurable (fun f : Bool → Set E => e ∈ fieldUnion f) := by - apply measurableSet_setOfPred.mp - change MeasurableSet ({f : Bool → Set E | e ∈ f true} ∪ {f | e ∈ f false}) - apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp - (measurable_pi_apply true) - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp - (measurable_pi_apply false) - exact measurable_setOfPred.comp (Measurable.of_eval hm) - - theorem map_fieldUnion (p a : unitInterval) : - (fieldLaw p a).map (fieldUnion : (Bool → Set E) → Set E) = law (sprinkleParameter p a) := by - let μ := fun b : Bool => bitLaw (pairParameter p a b) - let s := fun f : Bool → E → Prop => fun b => {e | f b e} - have hs : Measurable s := Measurable.of_eval - (fun b => measurable_setOfPred.comp (measurable_pi_apply b)) - have hstart : (Measure.infinitePi (fun b : Bool => Measure.infinitePi (fun _ : E => μ b))).map s = - fieldLaw p a := by - rw [Measure.infinitePi_map_pi _ (fun _ => measurable_setOfPred)] - congr 1 - funext b - rw [law, setBernoulli_eq_map] - rfl - rw [← hstart, Measure.map_map measurable_fieldUnion hs] - let f := (MeasurableEquiv.curry Bool E Prop).symm - let swap := MeasurableEquiv.piCongrLeft (fun _ : E × Bool => Prop) (Equiv.prodComm Bool E) - let c := MeasurableEquiv.curry E Bool Prop - let b := fun g : E → Bool → Prop => fun e => ∃ j, g e j - have hb : Measurable b := Measurable.of_eval - (fun e => (Measurable.of_discrete : Measurable (fun f : Bool → Prop => ∃ j, f j)).comp - (measurable_pi_apply e)) - have he : fieldUnion ∘ s = (fun g : E → Prop => {e | g e}) ∘ b ∘ c ∘ swap ∘ f := by - funext g - ext e - simp [fieldUnion, s, b, c, swap, f, Function.comp_def, Bool.exists_bool, or_comm, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft] - rw [he, ← Measure.map_map measurable_setOfPred (hb.comp (c.measurable.comp (swap.measurable.comp f.measurable))), - ← Measure.map_map hb (c.measurable.comp (swap.measurable.comp f.measurable))] - rw [← Measure.map_map c.measurable (swap.measurable.comp f.measurable), - ← Measure.map_map swap.measurable f.measurable] - rw [Measure.infinitePi_map_curry_symm] - rw [show (Measure.infinitePi (fun x : Bool × E => μ x.1)).map swap = - Measure.infinitePi (fun x : E × Bool => μ x.2) from - Measure.infinitePi_map_piCongrLeft (fun x : E × Bool => μ x.2) (Equiv.prodComm Bool E)] - rw [Measure.infinitePi_map_curry (fun (_ : E) (j : Bool) => μ j)] - dsimp only [b] - rw [Measure.infinitePi_map_pi _ (fun _ => Measurable.of_discrete)] - have hm : (Measure.infinitePi (fun j : Bool => μ j)).map Exists = - bitLaw (sprinkleParameter p a) := map_bool_or p a - rw [hm, law, setBernoulli_eq_map] - rfl - - theorem fieldLaw_map_pair (p a : unitInterval) : - (fieldLaw p a).map (fun f : Bool → Set E => (f true, f false)) = - (law p).prod (law a) := by - simpa [fieldLaw, pairParameter] using - (Measure.infinitePi_map_eval_prod (P := fun b : Bool => (law (pairParameter p a b) : Measure (Set E))) - (by decide : true ≠ false)) - - theorem law_map_union (p a : unitInterval) : - ((law p : Measure (Set E)).prod (law a)).map (fun f => f.1 ∪ f.2) = - law (sprinkleParameter p a) := by - rw [← fieldLaw_map_pair p a, Measure.map_map] - · exact map_fieldUnion p a - · have h : Measurable (fun f : Set E × Set E => fun e => e ∈ f.1 ∪ f.2) := by - apply Measurable.of_eval - intro e - apply measurableSet_setOfPred.mp - change MeasurableSet ({f : Set E × Set E | e ∈ f.1} ∪ {f | e ∈ f.2}) - apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_fst - · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_snd - exact measurable_setOfPred.comp h - · exact (measurable_pi_apply true).prodMk (measurable_pi_apply false) - -end SprinklingLaw - -section Schur -attribute [local instance] Classical.propDecidable - - -theorem exists_operator_of_row_column_bound (U : V → V → ℝ) (D : ℝ) - (hD : 0 ≤ D) (hU : ∀ x y, 0 ≤ U x y) - (hrow : ∀ x (s : Finset V), ∑ y ∈ s, U x y ≤ D) - (hcol : ∀ y (s : Finset V), ∑ x ∈ s, U x y ≤ D) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ D ∧ - ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ) := by - have hentry (x y : V) : U x y ≤ D := by simpa using hrow x {y} - have hcm (y : V) : Memℓp (fun x => (U x y : ℂ)) 2 := by - apply (memℓp_gen_iff'' (by norm_num : 0 < (2 : ℝ≥0∞).toReal)).mpr - refine ⟨D^2, sq_nonneg _, fun s => ?_⟩ - simp only [ENNReal.toReal_ofNat, Real.rpow_two, Complex.norm_real, - Real.norm_eq_abs, sq_abs] - calc - ∑ x ∈ s, U x y ^ 2 ≤ ∑ x ∈ s, D * U x y := by - apply Finset.sum_le_sum - intro x _ - nlinarith [hentry x y, hU x y] - _ = D * ∑ x ∈ s, U x y := by rw [Finset.mul_sum] - _ ≤ D * D := mul_le_mul_of_nonneg_left (hcol y s) hD - _ = D^2 := by ring - let col (y : V) : Hilbert V := ⟨fun x => (U x y : ℂ), hcm y⟩ - let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col - have hn (f : V →₀ ℂ) : ‖L f‖ ≤ D * ‖finiteEmbedding f‖ := by - apply lp.norm_le_of_forall_sum_le (by norm_num) - (mul_nonneg hD (norm_nonneg _)) - intro s - simp only [ENNReal.toReal_ofNat, Real.rpow_two] - have hpoint (x : V) : ‖L f x‖^2 ≤ D * ∑ y ∈ f.support, ‖f y‖^2 * U x y := by - have hn0 : 0 ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := - Finset.sum_nonneg fun y _ => mul_nonneg (norm_nonneg _) (hU x y) - have hn1 : ‖L f x‖ ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := by - simp only [L, Finsupp.linearCombination_apply, Finsupp.sum, lp.coeFn_sum, - Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, smul_eq_mul] - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro y _ - simp [col, abs_of_nonneg (hU x y)] - have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul f.support - (f := fun y => U x y) (g := fun y => ‖f y‖^2 * U x y) - (r := fun y => ‖f y‖ * U x y) - (fun y _ => hU x y) - (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) - (fun y _ => by nlinarith) - exact (sq_le_sq₀ (norm_nonneg _) hn0 |>.mpr hn1).trans - (hcs.trans (mul_le_mul_of_nonneg_right (hrow x f.support) - (Finset.sum_nonneg fun y _ => mul_nonneg (sq_nonneg _) (hU x y)))) - calc - ∑ x ∈ s, ‖L f x‖^2 ≤ ∑ x ∈ s, D * ∑ y ∈ f.support, ‖f y‖^2 * U x y := - Finset.sum_le_sum fun x _ => hpoint x - _ = D * ∑ y ∈ f.support, ‖f y‖^2 * ∑ x ∈ s, U x y := by - rw [← Finset.mul_sum, Finset.sum_comm] - simp_rw [← Finset.mul_sum] - _ ≤ D * ∑ y ∈ f.support, ‖f y‖^2 * D := by - apply mul_le_mul_of_nonneg_left _ hD - apply Finset.sum_le_sum - intro y _ - exact mul_le_mul_of_nonneg_left (hcol y s) (sq_nonneg _) - _ = D^2 * ∑ y ∈ f.support, ‖finiteEmbedding f y‖^2 := by - simp only [finiteEmbedding_apply, ← Finset.sum_mul] - ring - _ ≤ D^2 * ‖finiteEmbedding f‖^2 := by - apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) - simpa only [ENNReal.toReal_ofNat, Real.rpow_two] using - (lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2 : ℝ≥0∞).toReal) - (finiteEmbedding f) f.support) - _ = (D * ‖finiteEmbedding f‖)^2 := by ring - refine ⟨L.extendOfNorm finiteEmbedding, - LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense hD hn, ?_⟩ - intro x y - have he := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨D, hn⟩ - (Finsupp.single y (1 : ℂ)) - simp only [finiteEmbedding_single] at he - rw [he] - simp [L, col] - -end Schur - -section SprinklingPaths -attribute [local instance] Classical.propDecidable - - -theorem Along.first_outside {G : BondGraph V E} {x y : V} {l : List E} - (h : Along G x l y) (S : Set E) : - (∀ e ∈ l, e ∈ S) ∨ ∃ a b e l₁ l₂, - l = l₁ ++ e :: l₂ ∧ Along G x l₁ a ∧ G e = s(a,b) ∧ - Along G b l₂ y ∧ (∀ d ∈ l₁, d ∈ S) ∧ e ∉ S := by - induction h with - | nil => left; simp - | @cons x z y l e he ht ih => - by_cases hes : e ∈ S - · rcases ih with hall | ⟨a,b,d,l₁,l₂,hl,h₁,hd,h₂,hopen,hnot⟩ - · left - simpa only [List.mem_cons, forall_eq_or_imp] using And.intro hes hall - · right - refine ⟨a,b,d,e::l₁,l₂,by simp [hl], .cons e he h₁, hd, h₂, ?_, hnot⟩ - simpa only [List.mem_cons, forall_eq_or_imp] using And.intro hes hopen - · right - exact ⟨x,z,e,[],l,rfl,.nil x,he,ht,by simp,hes⟩ - - -theorem conn_first_outside (G : BondGraph V E) (S : Set E) {ω : Set E} {x y : V} - (h : Conn G ω x y) : - Conn G (ω ∩ S) x y ∨ ∃ a b e, G e = s(a,b) ∧ e ∉ S ∧ - ω ∈ DisjointOccurrence {η | Conn G (η ∩ S) x a} - (DisjointOccurrence {η | e ∈ η} {η | Conn G η b y}) := by - obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G h - rcases hl.first_outside S with hall | ⟨a,b,e,l₁,l₂,heq,h₁,he,h₂,hfirst,hnot⟩ - · exact Or.inl (hl.conn fun e he => ⟨ho e he,hall e he⟩) - · subst l - have hnod := List.nodup_append.mp hn - have hen : e ∉ l₂ := (List.nodup_cons.mp hnod.2.1).1 - right - refine ⟨a,b,e,he,hnot,l₁.toFinset,(e::l₂).toFinset,?_,?_,?_,?_,?_⟩ - · intro d hd - exact ho d (List.mem_append_left _ (List.mem_toFinset.mp hd)) - · intro d hd - exact ho d (List.mem_append_right _ (List.mem_toFinset.mp hd)) - · apply Finset.disjoint_left.mpr - intro d hd hd' - exact hnod.2.2 d (List.mem_toFinset.mp hd) d (List.mem_toFinset.mp hd') rfl - · exact h₁.conn (fun d hd => ⟨by simpa using hd, hfirst d hd⟩) - · refine ⟨{e},l₂.toFinset,?_,?_,?_,by simp,?_⟩ - · simp - · simp - · simpa using hen - · exact h₂.conn (fun d hd => by simpa using hd) - - -theorem law_map_preimage_embedding {F : Type*} (p : unitInterval) (f : F ↪ E) : - (law p : Measure (Set E)).map (fun ω => f ⁻¹' ω) = law p := by - have hm : Measurable (fun ω : Set E => f ⁻¹' ω) := - measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_pi_apply (f e)).comp MeasurableEquiv.setOfPred.symm.measurable)) - unfold law - rw [setBernoulli_eq_map, Measure.map_map hm measurable_setOfPred] - have he : (fun ω : Set E => f ⁻¹' ω) ∘ (fun g => {e | g e}) = - (fun g : F → Prop => {e | g e}) ∘ (fun g : E → Prop => fun e => g (f e)) := rfl - rw [he, ← Measure.map_map measurable_setOfPred (by fun_prop)] - simp only [Set.mem_univ] - have hi := (iIndepFun_infinitePi (P := fun _ : E => bernoulliMeasure True False p) - (X := fun (_ : E) (b : Prop) => b) (fun _ => measurable_id)).precomp f.injective - have hh := hi.map_fun_eq_infinitePi_map (fun _ => measurable_pi_apply _) - simp only [Measure.infinitePi_map_eval] at hh - rw [hh, setBernoulli_eq_map] - rfl - - - -theorem exists_orParameter_small (p : unitInterval) (hp : p < 1) - (ε : ℝ) (hε : 0 < ε) (hε1 : ε ≤ 1) : - ∃ m : ℕ, ∃ q : unitInterval, (q : ℝ) ≤ ε ∧ orParameter q m = p := by - obtain ⟨m, hm⟩ := exists_pow_lt_of_lt_one (show 0 < 1 - (p : ℝ) by exact sub_pos.mpr hp) - (show 1-ε < 1 by linarith) - let f := fun x : ℝ => 1 - (1-x)^m - have hf : Continuous f := by fun_prop - have h0 : f 0 = 0 := by simp [f] - have hp' : (p : ℝ) ∈ Set.Icc (f 0) (f ε) := by - rw [h0] - exact ⟨p.2.1, by dsimp [f]; linarith⟩ - obtain ⟨q,hq,hqp⟩ := intermediate_value_Icc hε.le hf.continuousOn hp' - exact ⟨m,⟨q,hq.1,hq.2.trans hε1⟩,hq.2,Subtype.ext hqp⟩ - -end SprinklingPaths - -section ColoredSprinkling -attribute [local instance] Classical.propDecidable - - theorem conn_map_edges {F : Type*} (G : BondGraph V E) (f : F → E) - (ω : Set F) (x y : V) : Conn (G ∘ f) ω x y ↔ Conn G (f '' ω) x y := by - constructor <;> intro h - · induction h with - | refl => exact conn_refl _ _ _ - | @tail a b hab he ih => - rcases he with ⟨e,he,heq⟩ - exact ih.tail ⟨f e,Set.mem_image_of_mem _ he,heq⟩ - · induction h with - | refl => exact conn_refl _ _ _ - | @tail a b hab he ih => - rcases he with ⟨e,⟨d,hd,rfl⟩,heq⟩ - exact ih.tail ⟨d,hd,heq⟩ - - theorem finiteWitness_inter (A : Set (Set E)) (hA : FiniteWitness A) (S : Set E) : - FiniteWitness {ω | ω ∩ S ∈ A} := by - intro ω h - obtain ⟨s,hs,hsa⟩ := hA (ω ∩ S) h - refine ⟨s,hs.trans Set.inter_subset_left,?_⟩ - have he : (s : Set E) ∩ S = s := Set.inter_eq_left.mpr (hs.trans Set.inter_subset_right) - change (s : Set E) ∩ S ∈ A - rwa [he] - - def colorInclusion (m : ℕ) : E × Fin m ↪ E × Fin (m+1) := - Function.Embedding.prodMap (Function.Embedding.refl E) Fin.castSuccEmb - - def baseColors (m : ℕ) : Set (E × Fin (m+1)) := Set.range (colorInclusion (E := E) m) - - def baseField (m : ℕ) (ω : Set (E × Fin (m+1))) : Set E := - Prod.fst '' (colorInclusion m ⁻¹' ω) - - theorem not_mem_baseColors (m : ℕ) (e : E) (j : Fin (m+1)) : - (e,j) ∉ baseColors m ↔ j = Fin.last m := by - constructor - · intro h - apply Fin.eq_last_of_not_lt - intro hj - apply h - exact ⟨(e,⟨j.val,hj⟩),Prod.ext rfl (Fin.ext rfl)⟩ - · rintro rfl ⟨⟨e',i⟩,hi⟩ - exact Fin.castSucc_ne_last i (congrArg Prod.snd hi) - - theorem fst_inter_baseColors (m : ℕ) (ω : Set (E × Fin (m+1))) : - Prod.fst '' (ω ∩ baseColors m) = baseField m ω := by - ext e - constructor - · rintro ⟨⟨e',j⟩,⟨ho,⟨⟨f,i⟩,he⟩⟩,rfl⟩ - refine ⟨(f,i),?_,?_⟩ - · change colorInclusion m (f,i) ∈ ω - rwa [he] - · exact congrArg Prod.fst he - · rintro ⟨⟨e',i⟩,ho,rfl⟩ - exact ⟨colorInclusion m (e',i),⟨ho,Set.mem_range_self _⟩,rfl⟩ - - theorem measurable_baseField (m : ℕ) : Measurable (baseField (E := E) m) := by - apply (measurable_image_fst (Fin m)).comp - exact measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_pi_apply (colorInclusion m e)).comp - MeasurableEquiv.setOfPred.symm.measurable)) - - theorem law_map_baseField (q : unitInterval) (m : ℕ) : - (law q : Measure (Set (E × Fin (m+1)))).map (baseField m) = law (orParameter q m) := by - have hm : Measurable (fun ω : Set (E × Fin (m+1)) => colorInclusion m ⁻¹' ω) := - measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_pi_apply (colorInclusion m e)).comp - MeasurableEquiv.setOfPred.symm.measurable)) - change (law q).map ((fun ω : Set (E × Fin m) => Prod.fst '' ω) ∘ - (fun ω => colorInclusion m ⁻¹' ω)) = _ - rw [← Measure.map_map (measurable_image_fst (Fin m)) hm, - law_map_preimage_embedding, law_map_image_fst, Fintype.card_fin] - - noncomputable def dartSource (G : BondGraph V E) (d : E × Bool) : V := - if d.2 then (G d.1).out.1 else (G d.1).out.2 - noncomputable def dartTarget (G : BondGraph V E) (d : E × Bool) : V := - if d.2 then (G d.1).out.2 else (G d.1).out.1 - - theorem exists_dart (G : BondGraph V E) {e : E} {a b : V} (h : G e = s(a,b)) : - ∃ j : Bool, dartSource G (e,j) = a ∧ dartTarget G (e,j) = b := by - have he : s((G e).out.1, (G e).out.2) = s(a,b) := (G e).out_eq.trans h - rcases Sym2.eq_iff.mp he with h | h - · exact ⟨true,h⟩ - · exact ⟨false,h.2,h.1⟩ - - theorem colored_conn_probability [Countable V] [Countable E] (G : BondGraph V E) - (q : unitInterval) (m : ℕ) (x y : V) : - (law q).real {ω : Set (E × Fin m) | Conn (G ∘ Prod.fst) ω x y} = - twoPoint G (orParameter q m) x y := by - have h := law_map_image_fst (E := E) q (Fin m) - simp only [Fintype.card_fin] at h - rw [twoPoint, ← h, Measure.map_apply (measurable_image_fst (Fin m)) - (measurableSet_conn G x y)] - congr 1 - ext ω - exact conn_map_edges G Prod.fst ω x y - - theorem base_conn_probability [Countable V] [Countable E] (G : BondGraph V E) - (q : unitInterval) (m : ℕ) (x y : V) : - (law q).real {ω : Set (E × Fin (m+1)) | - Conn (G ∘ Prod.fst) (ω ∩ baseColors m) x y} = - twoPoint G (orParameter q m) x y := by - rw [twoPoint, ← law_map_baseField (E := E) q m, - Measure.map_apply (measurable_baseField m) (measurableSet_conn G x y)] - congr 1 - ext ω - change Conn (G ∘ Prod.fst) (ω ∩ baseColors m) x y ↔ Conn G (baseField m ω) x y - rw [conn_map_edges, fst_inter_baseColors] - - - - theorem twoPoint_or_succ_le [Countable V] [Fintype E] (G : BondGraph V E) (q : unitInterval) - (m : ℕ) (x y : V) : - twoPoint G (orParameter q (m+1)) x y ≤ twoPoint G (orParameter q m) x y + - (q : ℝ) * ∑ d : E × Bool, - twoPoint G (orParameter q m) x (dartSource G d) * - twoPoint G (orParameter q (m+1)) (dartTarget G d) y := by - let H : BondGraph V (E × Fin (m+1)) := G ∘ Prod.fst - let A (a : V) : Set (Set (E × Fin (m+1))) := - {ω | Conn H (ω ∩ baseColors m) x a} - let B (b : V) : Set (Set (E × Fin (m+1))) := {ω | Conn H ω b y} - let C (d : E × Bool) := DisjointOccurrence (A (dartSource G d)) - (DisjointOccurrence {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d))) - have huA (a : V) : IsUpperSet (A a) := - fun _ _ h hω => conn_mono H (Set.inter_subset_inter_left _ h) hω - have hfA (a : V) : FiniteWitness (A a) := - finiteWitness_inter _ (finiteWitness_conn H x a) _ - have huB (b : V) : IsUpperSet (B b) := fun _ _ h hω => conn_mono H h hω - have hfB (b : V) : FiniteWitness (B b) := finiteWitness_conn H b y - have hsub : {ω | Conn H ω x y} ⊆ A y ∪ ⋃ d : E × Bool, C d := by - intro ω hω - rcases conn_first_outside H (baseColors m) hω with ha | ⟨a,b,⟨e,j⟩,he,hj,hc⟩ - · exact Or.inl ha - · have hj' := (not_mem_baseColors m e j).mp hj - subst j - obtain ⟨k,hk₁,hk₂⟩ := exists_dart G he - right - refine Set.mem_iUnion.mpr ⟨(e,k),?_⟩ - simpa only [C,hk₁,hk₂] using hc - calc - twoPoint G (orParameter q (m+1)) x y = (law q).real {ω | Conn H ω x y} := - (colored_conn_probability G q (m+1) x y).symm - _ ≤ (law q).real (A y ∪ ⋃ d : E × Bool, C d) := measureReal_mono hsub - _ ≤ (law q).real (A y) + (law q).real (⋃ d : E × Bool, C d) := measureReal_union_le _ _ - _ ≤ (law q).real (A y) + ∑ d : E × Bool, (law q).real (C d) := - add_le_add_right (measureReal_iUnion_fintype_le _) _ - _ ≤ twoPoint G (orParameter q m) x y + - ∑ d : E × Bool, twoPoint G (orParameter q m) x (dartSource G d) * - ((q : ℝ) * twoPoint G (orParameter q (m+1)) (dartTarget G d) y) := by - rw [show (law q).real (A y) = twoPoint G (orParameter q m) x y from - base_conn_probability G q m x y] - apply add_le_add_right - apply Finset.sum_le_sum - intro d _ - have hb := bk q {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d)) - (fun _ _ hh he => hh he) (huB _) (finiteWitness_edge _) (hfB _) - have heq : (law q).real {ω : Set (E × Fin (m+1)) | (d.1,Fin.last m) ∈ ω} = - (q : ℝ) := by simpa using finite_open_probability q {(d.1,Fin.last m)} - rw [heq, show (law q).real (B (dartTarget G d)) = - twoPoint G (orParameter q (m+1)) (dartTarget G d) y from - colored_conn_probability G q (m+1) _ _] at hb - have ha := bk q (A (dartSource G d)) - (DisjointOccurrence {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d))) - (huA _) (disjointOccurrence_upper _ _) (hfA _) (finiteWitness_disjointOccurrence _ _) - rw [show (law q).real (A (dartSource G d)) = - twoPoint G (orParameter q m) x (dartSource G d) from base_conn_probability G q m _ _] at ha - exact ha.trans (mul_le_mul_of_nonneg_left hb (twoPoint_nonneg G _ _ _)) - _ = _ := by rw [Finset.mul_sum]; congr 1; apply Finset.sum_congr rfl; intro d _; ring - -end ColoredSprinkling - -section FiniteGraphOperators -attribute [local instance] Classical.propDecidable - - noncomputable def edgeVertices [Fintype E] (G : BondGraph V E) : Finset V := - Finset.univ.biUnion (fun e => (G e).toFinset) - - theorem mem_edgeVertices [Fintype E] (G : BondGraph V E) (x : V) : - x ∈ edgeVertices G ↔ ∃ e, x ∈ G e := by simp [edgeVertices] - - theorem conn_eq_or_mem_edgeVertices [Fintype E] (G : BondGraph V E) - {ω : Set E} {x y : V} (h : Conn G ω x y) : x = y ∨ y ∈ edgeVertices G := by - cases h with - | refl => exact Or.inl rfl - | @tail a b hab he => - rcases he with ⟨e,_,he⟩ - exact Or.inr ((mem_edgeVertices G y).mpr ⟨e,by rw [he]; simp⟩) - - theorem operatorBounded_finite_edges [Fintype E] (G : BondGraph V E) (p : unitInterval) : - OperatorBounded G p := by - have hr (x : V) (s : Finset V) : ∑ y ∈ s, twoPoint G p x y ≤ - (edgeVertices G).card + (1 : ℝ) := by - let F := insert x (edgeVertices G) - have bound (y : V) : twoPoint G p x y ≤ if y ∈ F then 1 else 0 := by - split_ifs with hy - · exact twoPoint_le_one G p x y - · have he : {ω | Conn G ω x y} = ∅ := by - apply Set.eq_empty_iff_forall_notMem.mpr - intro ω h - rcases conn_eq_or_mem_edgeVertices G h with rfl | hmem - · exact hy (by simp [F]) - · exact hy (by simp [F,hmem]) - simp [twoPoint,he] - calc - ∑ y ∈ s, twoPoint G p x y ≤ ∑ y ∈ s, if y ∈ F then (1:ℝ) else 0 := - Finset.sum_le_sum (fun y _ => bound y) - _ = ((s ∩ F).card : ℝ) := by simp - _ ≤ (F.card : ℝ) := by - exact_mod_cast Finset.card_le_card Finset.inter_subset_right - _ ≤ (edgeVertices G).card + (1 : ℝ) := by - exact_mod_cast Finset.card_insert_le x (edgeVertices G) - obtain ⟨A,_,hA⟩ := exists_operator_of_row_column_bound (twoPoint G p) - ((edgeVertices G).card+1) (by positivity) (twoPoint_nonneg G p) hr - (fun y s => by simpa only [twoPoint_symm G p] using hr y s) - exact ⟨A,hA⟩ - - theorem dart_edge (G : BondGraph V E) (d : E × Bool) : - G d.1 = s(dartSource G d, dartTarget G d) := by - rcases d with ⟨e,j⟩ - cases j - · exact (G e).out_eq.symm.trans (Sym2.eq_swap ..) - · exact (G e).out_eq.symm - - theorem card_darts_at_source [Fintype E] (G : BondGraph V E) (x : V) : - Fintype.card {d : E × Bool // dartSource G d = x} ≤ 2 * degree G x := by - let : Fintype (Step G x) := (finite_steps G (fun _ => Set.toFinite _) x).fintype - let f : {d : E × Bool // dartSource G d = x} → Step G x × Bool := fun d => - (⟨(d.val.1,dartTarget G d.val), by rw [dart_edge G d.val,d.property]⟩,d.val.2) - have hf : Function.Injective f := by - intro d d' h - apply Subtype.ext - apply Prod.ext - · exact congrArg (fun t : Step G x × Bool => t.1.val.1) h - · exact congrArg (fun t : Step G x × Bool => t.2) h - have hc := Fintype.card_le_of_injective f hf - simpa only [Fintype.card_prod,Fintype.card_bool,degree,Nat.card_eq_fintype_card,Nat.mul_comm] using hc - - theorem card_darts_at_target [Fintype E] (G : BondGraph V E) (x : V) : - Fintype.card {d : E × Bool // dartTarget G d = x} ≤ 2 * degree G x := by - let : Fintype (Step G x) := (finite_steps G (fun _ => Set.toFinite _) x).fintype - let f : {d : E × Bool // dartTarget G d = x} → Step G x × Bool := fun d => - (⟨(d.val.1,dartSource G d.val), by - rw [dart_edge G d.val,d.property]; exact Sym2.eq_swap ..⟩,d.val.2) - have hf : Function.Injective f := by - intro d d' h - apply Subtype.ext - apply Prod.ext - · exact congrArg (fun t : Step G x × Bool => t.1.val.1) h - · exact congrArg (fun t : Step G x × Bool => t.2) h - have hc := Fintype.card_le_of_injective f hf - simpa only [Fintype.card_prod,Fintype.card_bool,degree,Nat.card_eq_fintype_card,Nat.mul_comm] using hc - - noncomputable def adjacencyOperator [Fintype E] (G : BondGraph V E) : - Hilbert V →L[ℂ] Hilbert V := - ∑ d : E × Bool, (lp.singleContinuousLinearMap ℂ (fun _ : V => ℂ) 2 (dartSource G d)).comp - (lp.evalCLM ℂ (fun _ : V => ℂ) 2 (dartTarget G d)) - - theorem adjacencyOperator_apply [Fintype E] (G : BondGraph V E) (f : Hilbert V) : - adjacencyOperator G f = ∑ d : E × Bool, lp.single 2 (dartSource G d) (f (dartTarget G d)) := by - simp [adjacencyOperator,lp.singleContinuousLinearMap_apply, - lp.evalCLM,lp.evalₗ] - rfl - - theorem adjacencyOperator_norm_le [Fintype E] (G : BondGraph V E) - (D : ℕ) (hD : ∀ x, degree G x ≤ D) : ‖adjacencyOperator G‖ ≤ 2 * (D : ℝ) := by - let U (x y : V) : ℝ := ∑ d : E × Bool, - if dartSource G d = x ∧ dartTarget G d = y then 1 else 0 - have hU : ∀ x y, 0 ≤ U x y := by intro x y; apply Finset.sum_nonneg; intro d _; positivity - have hmat : ∀ x y, adjacencyOperator G (lp.single 2 y (1:ℂ)) x = (U x y : ℂ) := by - intro x y - rw [adjacencyOperator_apply] - simp only [lp.coeFn_sum,Finset.sum_apply,U,Complex.ofReal_sum] - apply Finset.sum_congr rfl - intro d _ - simp only [lp.single_apply] - by_cases hx : dartSource G d = x <;> by_cases hy : dartTarget G d = y <;> - simp [hx,hy] - have hrow (x : V) (s : Finset V) : ∑ y ∈ s, U x y ≤ 2 * (D : ℝ) := by - calc - ∑ y ∈ s, U x y = ∑ d : E × Bool, - ∑ y ∈ s, if dartSource G d = x ∧ dartTarget G d = y then (1:ℝ) else 0 := - Finset.sum_comm - _ ≤ ∑ d : E × Bool, if dartSource G d = x then (1:ℝ) else 0 := by - apply Finset.sum_le_sum - intro d _ - by_cases hx : dartSource G d = x - · simp only [hx,true_and,ite_true] - rw [Finset.sum_ite_eq] - split_ifs <;> norm_num - · simp [hx] - _ = (Fintype.card {d : E × Bool // dartSource G d = x} : ℝ) := by simp [Fintype.card_subtype] - _ ≤ 2 * (D : ℝ) := by exact_mod_cast (card_darts_at_source G x).trans (Nat.mul_le_mul_left 2 (hD x)) - have hcol (y : V) (s : Finset V) : ∑ x ∈ s, U x y ≤ 2 * (D : ℝ) := by - calc - ∑ x ∈ s, U x y = ∑ d : E × Bool, - ∑ x ∈ s, if dartSource G d = x ∧ dartTarget G d = y then (1:ℝ) else 0 := - Finset.sum_comm - _ ≤ ∑ d : E × Bool, if dartTarget G d = y then (1:ℝ) else 0 := by - apply Finset.sum_le_sum - intro d _ - by_cases hy : dartTarget G d = y - · simp only [hy,and_true,ite_true] - rw [Finset.sum_ite_eq] - split_ifs <;> norm_num - · simp [hy] - _ = (Fintype.card {d : E × Bool // dartTarget G d = y} : ℝ) := by simp [Fintype.card_subtype] - _ ≤ 2 * (D : ℝ) := by exact_mod_cast (card_darts_at_target G y).trans (Nat.mul_le_mul_left 2 (hD y)) - obtain ⟨A,hn,hA⟩ := exists_operator_of_row_column_bound U (2*D) (by positivity) hU hrow hcol - rwa [kernel_extension_unique hmat hA] - -end FiniteGraphOperators - -section FiniteSprinklingBound -attribute [local instance] Classical.propDecidable -variable [Countable V] [Fintype E] - - theorem finite_sprinkling_bound (G : BondGraph V E) (q : unitInterval) (m D : ℕ) - (hD : ∀ x, degree G x ≤ D) (A : Hilbert V →L[ℂ] Hilbert V) - (hA : HasKernel G (orParameter q m) A) (M : ℝ) (hM : ‖A‖ ≤ M) - (hq : (q : ℝ) * (2*D) * M < 1) : - ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+1)) B ∧ - ‖B‖ ≤ M / (1-(q:ℝ)*(2*D)*M) := by - obtain ⟨B,hB⟩ := operatorBounded_finite_edges G (orParameter q (m+1)) - let R := (adjacencyOperator G).comp B - let C := A + (q : ℂ) • A.comp R - let U (x y : V) := twoPoint G (orParameter q m) x y + (q:ℝ) * - ∑ d : E × Bool, twoPoint G (orParameter q m) x (dartSource G d) * - twoPoint G (orParameter q (m+1)) (dartTarget G d) y - have hU : ∀ x y, 0 ≤ U x y := by - intro x y - exact add_nonneg (twoPoint_nonneg G _ _ _) - (mul_nonneg q.2.1 (Finset.sum_nonneg fun d _ => - mul_nonneg (twoPoint_nonneg G _ _ _) (twoPoint_nonneg G _ _ _))) - have hC : ∀ x y, C (lp.single 2 y (1:ℂ)) x = (U x y : ℂ) := by - intro x y - simp only [C,add_apply,smul_apply, - ContinuousLinearMap.comp_apply,R,adjacencyOperator_apply,map_sum,lp.coeFn_add,Pi.add_apply, - lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,lp.coeFn_sum,Finset.sum_apply,U, - Complex.ofReal_add,Complex.ofReal_mul,Complex.ofReal_sum] - rw [hA x y] - congr 1 - congr 1 - apply Finset.sum_congr rfl - intro d _ - have hs (c : ℂ) : (lp.single 2 (dartSource G d) c : Hilbert V) = c • lp.single 2 (dartSource G d) (1:ℂ) := by - rw [← lp.single_smul]; simp - rw [hs,map_smul,lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,hA,hB] - ring - obtain ⟨B',hn,hB'⟩ := exists_operator_of_matrix_domination U - (twoPoint G (orParameter q (m+1))) hU - (fun x y => by rw [abs_of_nonneg (twoPoint_nonneg G _ _ _)]; exact twoPoint_or_succ_le G q m x y) - C hC - have he : B' = B := kernel_extension_unique hB' hB - rw [he] at hn - have hqn : ‖(q : ℂ)‖ = (q : ℝ) := by simp [abs_of_nonneg q.2.1] - have hcoef : (q : ℝ) * ‖A‖ * (2*D) * ‖B‖ ≤ (q : ℝ) * M * (2*D) * ‖B‖ := by - gcongr - exact q.2.1 - have hbnd : ‖B‖ ≤ M + (q : ℝ) * (2*D) * M * ‖B‖ := by - calc - ‖B‖ ≤ ‖C‖ := hn - _ ≤ ‖A‖ + ‖(q : ℂ) • A.comp R‖ := norm_add_le _ _ - _ = ‖A‖ + (q : ℝ) * ‖A.comp R‖ := by rw [norm_smul,hqn] - _ ≤ ‖A‖ + (q : ℝ) * (‖A‖ * (‖adjacencyOperator G‖ * ‖B‖)) := by - apply add_le_add_right - apply mul_le_mul_of_nonneg_left _ q.2.1 - exact (A.opNorm_comp_le R).trans - (mul_le_mul_of_nonneg_left ((adjacencyOperator G).opNorm_comp_le B) (norm_nonneg _)) - _ ≤ ‖A‖ + (q : ℝ) * (‖A‖ * ((2*D) * ‖B‖)) := by - gcongr - · exact q.2.1 - · exact adjacencyOperator_norm_le G D hD - _ ≤ M + (q : ℝ) * M * (2*D) * ‖B‖ := by - rw [show (q : ℝ) * (‖A‖ * ((2*D) * ‖B‖)) = (q : ℝ) * ‖A‖ * (2*D) * ‖B‖ by ring] - exact add_le_add hM hcoef - _ = _ := by ring - refine ⟨B,hB,?_⟩ - apply (le_div_iff₀ (sub_pos.mpr hq)).mpr - nlinarith - -end FiniteSprinklingBound - -section ExhaustionSprinkling -attribute [local instance] Classical.propDecidable -open Filter Topology -variable [Countable V] [Countable E] - - theorem twoPoint_restrict_edges (G : BondGraph V E) (p : unitInterval) (S : Set E) (x y : V) : - twoPoint (G ∘ (Subtype.val : S → E)) p x y = - (law p).real {ω : Set E | Conn G (ω ∩ S) x y} := by - unfold twoPoint - rw [← law_map_restrict p S, Measure.map_apply (measurable_set_restrict S) - (measurableSet_conn (G ∘ Subtype.val) x y)] - apply congrArg ENNReal.toReal - congr 1 - ext ω - change Conn (G ∘ Subtype.val) (Subtype.val ⁻¹' ω) x y ↔ _ - rw [conn_map_edges] - have he : (Subtype.val '' (Subtype.val ⁻¹' ω : Set S)) = ω ∩ S := by - ext e - simp only [Set.mem_image,Set.mem_preimage,Set.mem_inter_iff] - constructor - · rintro ⟨d,hd,rfl⟩; exact ⟨hd,d.property⟩ - · rintro ⟨ho,hs⟩; exact ⟨⟨e,hs⟩,ho,rfl⟩ - rw [he] - rfl - - theorem twoPoint_restrict_le (G : BondGraph V E) (p : unitInterval) (S : Set E) (x y : V) : - twoPoint (G ∘ (Subtype.val : S → E)) p x y ≤ twoPoint G p x y := by - rw [twoPoint_restrict_edges] - exact measureReal_mono (fun ω h => conn_mono G Set.inter_subset_left h) (measure_ne_top _ _) - - omit [Countable V] [Countable E] in - theorem degree_restrict_le (G : BondGraph V E) (hloc : LocallyFinite G) (S : Set E) (x : V) : - degree (G ∘ (Subtype.val : S → E)) x ≤ degree G x := by - let : Fintype (Step G x) := (finite_steps G hloc x).fintype - let f : Step (G ∘ (Subtype.val : S → E)) x → Step G x := - fun d => ⟨(d.val.1.val,d.val.2),d.property⟩ - apply Nat.card_le_card_of_injective f - intro d d' h - apply Subtype.ext - apply Prod.ext - · apply Subtype.ext - exact congrArg (fun t : Step G x => t.val.1) h - · exact congrArg (fun t : Step G x => t.val.2) h - - theorem sprinkling_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (q : unitInterval) (m D : ℕ) (hD : ∀ x, degree G x ≤ D) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G (orParameter q m) A) - (hq : (q : ℝ) * (2*D) * ‖A‖ < 1) : - ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+1)) B ∧ - ‖B‖ ≤ ‖A‖ / (1-(q:ℝ)*(2*D)*‖A‖) := by - let := Encodable.ofCountable E - let F (n : ℕ) := edgeExhaustion (E := E) n - let H (n : ℕ) : BondGraph V (F n) := G ∘ Subtype.val - have hb (n : ℕ) : ∃ B : Hilbert V →L[ℂ] Hilbert V, - HasKernel (H n) (orParameter q (m+1)) B ∧ - ‖B‖ ≤ ‖A‖ / (1-(q:ℝ)*(2*D)*‖A‖) := by - obtain ⟨A',hn,hA'⟩ := exists_operator_of_matrix_domination - (twoPoint G (orParameter q m)) (twoPoint (H n) (orParameter q m)) - (twoPoint_nonneg G _) (fun x y => by - rw [abs_of_nonneg (twoPoint_nonneg (H n) _ _ _)] - exact twoPoint_restrict_le G _ (F n) x y) A hA - exact finite_sprinkling_bound (H n) q m D - (fun x => (degree_restrict_le G hloc (F n) x).trans (hD x)) A' hA' ‖A‖ hn hq - choose B hB hn using hb - have hlim (x y : V) : Tendsto (fun n => twoPoint (H n) (orParameter q (m+1)) x y) - atTop (𝓝 (twoPoint G (orParameter q (m+1)) x y)) := by - have hm : Monotone (fun n => {ω : Set E | Conn G (ω ∩ (F n : Set E)) x y}) := by - intro m n h ω hω - exact conn_mono G (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω - have h := tendsto_measure_iUnion_atTop (μ := law (orParameter q (m+1))) hm - have he := witness_eq_union {ω | Conn G ω x y} (fun _ _ h hc => conn_mono G h hc) - (finiteWitness_conn G x y) - change {ω : Set E | Conn G ω x y} = ⋃ n, {ω | Conn G (ω ∩ (F n : Set E)) x y} at he - rw [← he] at h - have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h - apply hr.congr' - apply Filter.Eventually.of_forall - intro n - exact (twoPoint_restrict_edges G (orParameter q (m+1)) (F n) x y).symm - obtain ⟨C,hCn,hC⟩ := exists_operator_of_matrix_tendsto B - (fun x y => (twoPoint G (orParameter q (m+1)) x y : ℂ)) - (div_nonneg (norm_nonneg _) (sub_pos.mpr hq).le) hn (fun x y => by - have hBm : ∀ n x y, B n (lp.single 2 y (1:ℂ)) x = (twoPoint (H n) (orParameter q (m+1)) x y : ℂ) := hB - simp only [hBm] - exact Complex.continuous_ofReal.continuousAt.tendsto.comp (hlim x y)) - exact ⟨C,hC,hCn⟩ - -end ExhaustionSprinkling - -section Openness -attribute [local instance] Classical.propDecidable - - theorem operatorBounded_open_right [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (p : unitInterval) (hp0 : 0 < p) (hp1 : p < 1) (hb : OperatorBounded G p) : - ∃ r : unitInterval, p < r ∧ OperatorBounded G r := by - obtain ⟨A,hA⟩ := hb - let c : ℝ := (2*D)*‖A‖ - have hc : 0 ≤ c := by dsimp [c]; positivity - obtain ⟨m,q,hq,hqp⟩ := exists_orParameter_small p hp1 (1/(c+1)) - (by positivity) (by apply (div_le_one (by positivity)).mpr; linarith) - have hq0 : (0:ℝ) < q := by - by_contra h - have hqe : q = 0 := Subtype.ext ((le_of_not_gt h).antisymm q.2.1) - have hpe : p = 0 := by rw [← hqp,hqe]; apply Subtype.ext; simp [orParameter] - exact (ne_of_gt hp0) hpe - have hsmall : (q:ℝ)*(2*D)*‖A‖ < 1 := by - have hm := mul_le_mul_of_nonneg_right hq hc - have hh : c/(c+1) < 1 := (div_lt_one (by positivity)).mpr (by linarith) - calc - (q:ℝ)*(2*D)*‖A‖ = (q:ℝ)*c := by dsimp [c]; ring - _ ≤ 1/(c+1)*c := hm - _ = c/(c+1) := by ring - _ < 1 := hh - obtain ⟨B,hB,_⟩ := sprinkling_bound G hloc q m D hD A (hqp ▸ hA) hsmall - refine ⟨orParameter q (m+1),?_,B,hB⟩ - change (p:ℝ) < (orParameter q (m+1):ℝ) - have he : (orParameter q (m+1):ℝ) = (p:ℝ)+(1-p)*q := by - rw [← hqp] - simp only [orParameter,pow_succ] - ring - rw [he] - have ht := mul_pos (show (0:ℝ) < 1-p from sub_pos.mpr hp1) hq0 - linarith - - - - theorem mainConclusion_of_critical_bounded [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hc : OperatorBounded G (pc G)) : MainConclusion G := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - have hpc1 : pc G < 1 := by - apply lt_of_le_of_ne (show pc G ≤ 1 from (pc G).2.2) - intro he - exact not_operatorBounded_one G hconn (he ▸ hc) - obtain ⟨D,_,hD⟩ := exists_degree_bound G hqt - obtain ⟨q,hq,hb⟩ := operatorBounded_open_right G hloc D hD (pc G) - (pc_pos G hloc hqt) hpc1 hc - exact mainConclusion_of_strict_gap G hconn hloc hqt - (hq.trans_le (le_sSup hb)) - -end Openness - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Graph.Paths + +namespace OAI + +/-! Sprinkling estimates for finite and infinite graph operators. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section SprinklingLaw +attribute [local instance] Classical.propDecidable + +noncomputable def sprinkleParameter (p a : unitInterval) : unitInterval := + ⟨(p : ℝ) + (1-p)*a, by + constructor + · exact add_nonneg p.2.1 (mul_nonneg (sub_nonneg.mpr p.2.2) a.2.1) + · nlinarith [mul_nonneg (sub_nonneg.mpr p.2.2) (sub_nonneg.mpr a.2.2)]⟩ + + def pairParameter (p a : unitInterval) (b : Bool) : unitInterval := if b then p else a + + theorem map_bool_or (p a : unitInterval) : + (Measure.infinitePi (fun b : Bool => bitLaw (pairParameter p a b))).map + (fun f : Bool → Prop => ∃ b, f b) = bitLaw (sprinkleParameter p a) := by + let μ := (Measure.infinitePi (fun b : Bool => bitLaw (pairParameter p a b))).map + (fun f : Bool → Prop => ∃ b, f b) + have hm : Measurable (fun f : Bool → Prop => ∃ b, f b) := .of_discrete + have : IsProbabilityMeasure μ := inferInstance + have hf : μ.real {False} = (1-(p : ℝ)) * (1-(a : ℝ)) := by + change ((Measure.infinitePi _).map _).real _ = _ + rw [Measure.real, Measure.map_apply hm (measurableSet_singleton _)] + have he : (fun f : Bool → Prop => ∃ b, f b) ⁻¹' ({False} : Set Prop) = + ((Finset.univ : Finset Bool) : Set Bool).pi (fun _ => ({False} : Set Prop)) := by + ext f + simp [and_comm] + rw [he, Measure.infinitePi_pi _ (fun _ _ => measurableSet_singleton _)] + simp [pairParameter, bitLaw, ENNReal.toReal_mul] + have ht : μ.real {True} = (p : ℝ) + (1-p)*a := by + have he : ({True} : Set Prop) = ({False} : Set Prop)ᶜ := by ext b; simp + rw [he, measureReal_compl (measurableSet_singleton _), probReal_univ, hf] + ring + apply Measure.ext_of_singleton + intro b + apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp + change μ.real {b} = (bitLaw (sprinkleParameter p a)).real {b} + by_cases hb : b + · have he : b = True := propext (iff_true_intro hb) + subst b + rw [ht] + simp [bitLaw, Measure.real, sprinkleParameter] + · have he : b = False := propext (iff_false_intro hb) + subst b + rw [hf] + simp [bitLaw, Measure.real, sprinkleParameter] + ring + +noncomputable def fieldLaw (p a : unitInterval) : Measure (Bool → Set E) := + Measure.infinitePi (fun b => law (pairParameter p a b)) + +def fieldUnion (f : Bool → Set E) : Set E := f true ∪ f false + + theorem measurable_fieldUnion : Measurable (fieldUnion : (Bool → Set E) → Set E) := by + have hm (e : E) : Measurable (fun f : Bool → Set E => e ∈ fieldUnion f) := by + apply measurableSet_setOfPred.mp + change MeasurableSet ({f : Bool → Set E | e ∈ f true} ∪ {f | e ∈ f false}) + apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp + (measurable_pi_apply true) + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp + (measurable_pi_apply false) + exact measurable_setOfPred.comp (Measurable.of_eval hm) + + theorem map_fieldUnion (p a : unitInterval) : + (fieldLaw p a).map (fieldUnion : (Bool → Set E) → Set E) = law (sprinkleParameter p a) := by + let μ := fun b : Bool => bitLaw (pairParameter p a b) + let s := fun f : Bool → E → Prop => fun b => {e | f b e} + have hs : Measurable s := Measurable.of_eval + (fun b => measurable_setOfPred.comp (measurable_pi_apply b)) + have hstart : (Measure.infinitePi (fun b : Bool => Measure.infinitePi (fun _ : E => μ b))).map s = + fieldLaw p a := by + rw [Measure.infinitePi_map_pi _ (fun _ => measurable_setOfPred)] + congr 1 + funext b + rw [law, setBernoulli_eq_map] + rfl + rw [← hstart, Measure.map_map measurable_fieldUnion hs] + let f := (MeasurableEquiv.curry Bool E Prop).symm + let swap := MeasurableEquiv.piCongrLeft (fun _ : E × Bool => Prop) (Equiv.prodComm Bool E) + let c := MeasurableEquiv.curry E Bool Prop + let b := fun g : E → Bool → Prop => fun e => ∃ j, g e j + have hb : Measurable b := Measurable.of_eval + (fun e => (Measurable.of_discrete : Measurable (fun f : Bool → Prop => ∃ j, f j)).comp + (measurable_pi_apply e)) + have he : fieldUnion ∘ s = (fun g : E → Prop => {e | g e}) ∘ b ∘ c ∘ swap ∘ f := by + funext g + ext e + simp [fieldUnion, s, b, c, swap, f, Function.comp_def, Bool.exists_bool, or_comm, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft] + rw [he, ← Measure.map_map measurable_setOfPred (hb.comp (c.measurable.comp (swap.measurable.comp f.measurable))), + ← Measure.map_map hb (c.measurable.comp (swap.measurable.comp f.measurable))] + rw [← Measure.map_map c.measurable (swap.measurable.comp f.measurable), + ← Measure.map_map swap.measurable f.measurable] + rw [Measure.infinitePi_map_curry_symm] + rw [show (Measure.infinitePi (fun x : Bool × E => μ x.1)).map swap = + Measure.infinitePi (fun x : E × Bool => μ x.2) from + Measure.infinitePi_map_piCongrLeft (fun x : E × Bool => μ x.2) (Equiv.prodComm Bool E)] + rw [Measure.infinitePi_map_curry (fun (_ : E) (j : Bool) => μ j)] + dsimp only [b] + rw [Measure.infinitePi_map_pi _ (fun _ => Measurable.of_discrete)] + have hm : (Measure.infinitePi (fun j : Bool => μ j)).map Exists = + bitLaw (sprinkleParameter p a) := map_bool_or p a + rw [hm, law, setBernoulli_eq_map] + rfl + + theorem fieldLaw_map_pair (p a : unitInterval) : + (fieldLaw p a).map (fun f : Bool → Set E => (f true, f false)) = + (law p).prod (law a) := by + simpa [fieldLaw, pairParameter] using + (Measure.infinitePi_map_eval_prod (P := fun b : Bool => (law (pairParameter p a b) : Measure (Set E))) + (by decide : true ≠ false)) + + theorem law_map_union (p a : unitInterval) : + ((law p : Measure (Set E)).prod (law a)).map (fun f => f.1 ∪ f.2) = + law (sprinkleParameter p a) := by + rw [← fieldLaw_map_pair p a, Measure.map_map] + · exact map_fieldUnion p a + · have h : Measurable (fun f : Set E × Set E => fun e => e ∈ f.1 ∪ f.2) := by + apply Measurable.of_eval + intro e + apply measurableSet_setOfPred.mp + change MeasurableSet ({f : Set E × Set E | e ∈ f.1} ∪ {f | e ∈ f.2}) + apply MeasurableSet.union <;> apply measurableSet_setOfPred.mpr + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_fst + · exact ((measurable_pi_apply e).comp MeasurableEquiv.setOfPred.symm.measurable).comp measurable_snd + exact measurable_setOfPred.comp h + · exact (measurable_pi_apply true).prodMk (measurable_pi_apply false) + +end SprinklingLaw + +section Schur +attribute [local instance] Classical.propDecidable + + +theorem exists_operator_of_row_column_bound (U : V → V → ℝ) (D : ℝ) + (hD : 0 ≤ D) (hU : ∀ x y, 0 ≤ U x y) + (hrow : ∀ x (s : Finset V), ∑ y ∈ s, U x y ≤ D) + (hcol : ∀ y (s : Finset V), ∑ x ∈ s, U x y ≤ D) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, ‖A‖ ≤ D ∧ + ∀ x y, A (lp.single 2 y (1 : ℂ)) x = (U x y : ℂ) := by + have hentry (x y : V) : U x y ≤ D := by simpa using hrow x {y} + have hcm (y : V) : Memℓp (fun x => (U x y : ℂ)) 2 := by + apply (memℓp_gen_iff'' (by norm_num : 0 < (2 : ℝ≥0∞).toReal)).mpr + refine ⟨D^2, sq_nonneg _, fun s => ?_⟩ + simp only [ENNReal.toReal_ofNat, Real.rpow_two, Complex.norm_real, + Real.norm_eq_abs, sq_abs] + calc + ∑ x ∈ s, U x y ^ 2 ≤ ∑ x ∈ s, D * U x y := by + apply Finset.sum_le_sum + intro x _ + nlinarith [hentry x y, hU x y] + _ = D * ∑ x ∈ s, U x y := by rw [Finset.mul_sum] + _ ≤ D * D := mul_le_mul_of_nonneg_left (hcol y s) hD + _ = D^2 := by ring + let col (y : V) : Hilbert V := ⟨fun x => (U x y : ℂ), hcm y⟩ + let L : (V →₀ ℂ) →ₗ[ℂ] Hilbert V := Finsupp.linearCombination ℂ col + have hn (f : V →₀ ℂ) : ‖L f‖ ≤ D * ‖finiteEmbedding f‖ := by + apply lp.norm_le_of_forall_sum_le (by norm_num) + (mul_nonneg hD (norm_nonneg _)) + intro s + simp only [ENNReal.toReal_ofNat, Real.rpow_two] + have hpoint (x : V) : ‖L f x‖^2 ≤ D * ∑ y ∈ f.support, ‖f y‖^2 * U x y := by + have hn0 : 0 ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := + Finset.sum_nonneg fun y _ => mul_nonneg (norm_nonneg _) (hU x y) + have hn1 : ‖L f x‖ ≤ ∑ y ∈ f.support, ‖f y‖ * U x y := by + simp only [L, Finsupp.linearCombination_apply, Finsupp.sum, lp.coeFn_sum, + Finset.sum_apply, lp.coeFn_smul, Pi.smul_apply, smul_eq_mul] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro y _ + simp [col, abs_of_nonneg (hU x y)] + have hcs := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul f.support + (f := fun y => U x y) (g := fun y => ‖f y‖^2 * U x y) + (r := fun y => ‖f y‖ * U x y) + (fun y _ => hU x y) + (fun y _ => mul_nonneg (sq_nonneg _) (hU x y)) + (fun y _ => by nlinarith) + exact (sq_le_sq₀ (norm_nonneg _) hn0 |>.mpr hn1).trans + (hcs.trans (mul_le_mul_of_nonneg_right (hrow x f.support) + (Finset.sum_nonneg fun y _ => mul_nonneg (sq_nonneg _) (hU x y)))) + calc + ∑ x ∈ s, ‖L f x‖^2 ≤ ∑ x ∈ s, D * ∑ y ∈ f.support, ‖f y‖^2 * U x y := + Finset.sum_le_sum fun x _ => hpoint x + _ = D * ∑ y ∈ f.support, ‖f y‖^2 * ∑ x ∈ s, U x y := by + rw [← Finset.mul_sum, Finset.sum_comm] + simp_rw [← Finset.mul_sum] + _ ≤ D * ∑ y ∈ f.support, ‖f y‖^2 * D := by + apply mul_le_mul_of_nonneg_left _ hD + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul_of_nonneg_left (hcol y s) (sq_nonneg _) + _ = D^2 * ∑ y ∈ f.support, ‖finiteEmbedding f y‖^2 := by + simp only [finiteEmbedding_apply, ← Finset.sum_mul] + ring + _ ≤ D^2 * ‖finiteEmbedding f‖^2 := by + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + simpa only [ENNReal.toReal_ofNat, Real.rpow_two] using + (lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2 : ℝ≥0∞).toReal) + (finiteEmbedding f) f.support) + _ = (D * ‖finiteEmbedding f‖)^2 := by ring + refine ⟨L.extendOfNorm finiteEmbedding, + LinearMap.opNorm_extendOfNorm_le finiteEmbedding_dense hD hn, ?_⟩ + intro x y + have he := LinearMap.extendOfNorm_eq (f := L) finiteEmbedding_dense ⟨D, hn⟩ + (Finsupp.single y (1 : ℂ)) + simp only [finiteEmbedding_single] at he + rw [he] + simp [L, col] + +end Schur + +section SprinklingPaths +attribute [local instance] Classical.propDecidable + + +theorem Along.first_outside {G : BondGraph V E} {x y : V} {l : List E} + (h : Along G x l y) (S : Set E) : + (∀ e ∈ l, e ∈ S) ∨ ∃ a b e l₁ l₂, + l = l₁ ++ e :: l₂ ∧ Along G x l₁ a ∧ G e = s(a,b) ∧ + Along G b l₂ y ∧ (∀ d ∈ l₁, d ∈ S) ∧ e ∉ S := by + induction h with + | nil => left; simp + | @cons x z y l e he ht ih => + by_cases hes : e ∈ S + · rcases ih with hall | ⟨a,b,d,l₁,l₂,hl,h₁,hd,h₂,hopen,hnot⟩ + · left + simpa only [List.mem_cons, forall_eq_or_imp] using And.intro hes hall + · right + refine ⟨a,b,d,e::l₁,l₂,by simp [hl], .cons e he h₁, hd, h₂, ?_, hnot⟩ + simpa only [List.mem_cons, forall_eq_or_imp] using And.intro hes hopen + · right + exact ⟨x,z,e,[],l,rfl,.nil x,he,ht,by simp,hes⟩ + + +theorem conn_first_outside (G : BondGraph V E) (S : Set E) {ω : Set E} {x y : V} + (h : Conn G ω x y) : + Conn G (ω ∩ S) x y ∨ ∃ a b e, G e = s(a,b) ∧ e ∉ S ∧ + ω ∈ DisjointOccurrence {η | Conn G (η ∩ S) x a} + (DisjointOccurrence {η | e ∈ η} {η | Conn G η b y}) := by + obtain ⟨l,hl,hn,ho⟩ := conn_exists_bond_trail G h + rcases hl.first_outside S with hall | ⟨a,b,e,l₁,l₂,heq,h₁,he,h₂,hfirst,hnot⟩ + · exact Or.inl (hl.conn fun e he => ⟨ho e he,hall e he⟩) + · subst l + have hnod := List.nodup_append.mp hn + have hen : e ∉ l₂ := (List.nodup_cons.mp hnod.2.1).1 + right + refine ⟨a,b,e,he,hnot,l₁.toFinset,(e::l₂).toFinset,?_,?_,?_,?_,?_⟩ + · intro d hd + exact ho d (List.mem_append_left _ (List.mem_toFinset.mp hd)) + · intro d hd + exact ho d (List.mem_append_right _ (List.mem_toFinset.mp hd)) + · apply Finset.disjoint_left.mpr + intro d hd hd' + exact hnod.2.2 d (List.mem_toFinset.mp hd) d (List.mem_toFinset.mp hd') rfl + · exact h₁.conn (fun d hd => ⟨by simpa using hd, hfirst d hd⟩) + · refine ⟨{e},l₂.toFinset,?_,?_,?_,by simp,?_⟩ + · simp + · simp + · simpa using hen + · exact h₂.conn (fun d hd => by simpa using hd) + + +theorem law_map_preimage_embedding {F : Type*} (p : unitInterval) (f : F ↪ E) : + (law p : Measure (Set E)).map (fun ω => f ⁻¹' ω) = law p := by + have hm : Measurable (fun ω : Set E => f ⁻¹' ω) := + measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_pi_apply (f e)).comp MeasurableEquiv.setOfPred.symm.measurable)) + unfold law + rw [setBernoulli_eq_map, Measure.map_map hm measurable_setOfPred] + have he : (fun ω : Set E => f ⁻¹' ω) ∘ (fun g => {e | g e}) = + (fun g : F → Prop => {e | g e}) ∘ (fun g : E → Prop => fun e => g (f e)) := rfl + rw [he, ← Measure.map_map measurable_setOfPred (by fun_prop)] + simp only [Set.mem_univ] + have hi := (iIndepFun_infinitePi (P := fun _ : E => bernoulliMeasure True False p) + (X := fun (_ : E) (b : Prop) => b) (fun _ => measurable_id)).precomp f.injective + have hh := hi.map_fun_eq_infinitePi_map (fun _ => measurable_pi_apply _) + simp only [Measure.infinitePi_map_eval] at hh + rw [hh, setBernoulli_eq_map] + rfl + + + +theorem exists_orParameter_small (p : unitInterval) (hp : p < 1) + (ε : ℝ) (hε : 0 < ε) (hε1 : ε ≤ 1) : + ∃ m : ℕ, ∃ q : unitInterval, (q : ℝ) ≤ ε ∧ orParameter q m = p := by + obtain ⟨m, hm⟩ := exists_pow_lt_of_lt_one (show 0 < 1 - (p : ℝ) by exact sub_pos.mpr hp) + (show 1-ε < 1 by linarith) + let f := fun x : ℝ => 1 - (1-x)^m + have hf : Continuous f := by fun_prop + have h0 : f 0 = 0 := by simp [f] + have hp' : (p : ℝ) ∈ Set.Icc (f 0) (f ε) := by + rw [h0] + exact ⟨p.2.1, by dsimp [f]; linarith⟩ + obtain ⟨q,hq,hqp⟩ := intermediate_value_Icc hε.le hf.continuousOn hp' + exact ⟨m,⟨q,hq.1,hq.2.trans hε1⟩,hq.2,Subtype.ext hqp⟩ + +end SprinklingPaths + +section ColoredSprinkling +attribute [local instance] Classical.propDecidable + + theorem conn_map_edges {F : Type*} (G : BondGraph V E) (f : F → E) + (ω : Set F) (x y : V) : Conn (G ∘ f) ω x y ↔ Conn G (f '' ω) x y := by + constructor <;> intro h + · induction h with + | refl => exact conn_refl _ _ _ + | @tail a b hab he ih => + rcases he with ⟨e,he,heq⟩ + exact ih.tail ⟨f e,Set.mem_image_of_mem _ he,heq⟩ + · induction h with + | refl => exact conn_refl _ _ _ + | @tail a b hab he ih => + rcases he with ⟨e,⟨d,hd,rfl⟩,heq⟩ + exact ih.tail ⟨d,hd,heq⟩ + + theorem finiteWitness_inter (A : Set (Set E)) (hA : FiniteWitness A) (S : Set E) : + FiniteWitness {ω | ω ∩ S ∈ A} := by + intro ω h + obtain ⟨s,hs,hsa⟩ := hA (ω ∩ S) h + refine ⟨s,hs.trans Set.inter_subset_left,?_⟩ + have he : (s : Set E) ∩ S = s := Set.inter_eq_left.mpr (hs.trans Set.inter_subset_right) + change (s : Set E) ∩ S ∈ A + rwa [he] + + def colorInclusion (m : ℕ) : E × Fin m ↪ E × Fin (m+1) := + Function.Embedding.prodMap (Function.Embedding.refl E) Fin.castSuccEmb + + def baseColors (m : ℕ) : Set (E × Fin (m+1)) := Set.range (colorInclusion (E := E) m) + + def baseField (m : ℕ) (ω : Set (E × Fin (m+1))) : Set E := + Prod.fst '' (colorInclusion m ⁻¹' ω) + + theorem not_mem_baseColors (m : ℕ) (e : E) (j : Fin (m+1)) : + (e,j) ∉ baseColors m ↔ j = Fin.last m := by + constructor + · intro h + apply Fin.eq_last_of_not_lt + intro hj + apply h + exact ⟨(e,⟨j.val,hj⟩),Prod.ext rfl (Fin.ext rfl)⟩ + · rintro rfl ⟨⟨e',i⟩,hi⟩ + exact Fin.castSucc_ne_last i (congrArg Prod.snd hi) + + theorem fst_inter_baseColors (m : ℕ) (ω : Set (E × Fin (m+1))) : + Prod.fst '' (ω ∩ baseColors m) = baseField m ω := by + ext e + constructor + · rintro ⟨⟨e',j⟩,⟨ho,⟨⟨f,i⟩,he⟩⟩,rfl⟩ + refine ⟨(f,i),?_,?_⟩ + · change colorInclusion m (f,i) ∈ ω + rwa [he] + · exact congrArg Prod.fst he + · rintro ⟨⟨e',i⟩,ho,rfl⟩ + exact ⟨colorInclusion m (e',i),⟨ho,Set.mem_range_self _⟩,rfl⟩ + + theorem measurable_baseField (m : ℕ) : Measurable (baseField (E := E) m) := by + apply (measurable_image_fst (Fin m)).comp + exact measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_pi_apply (colorInclusion m e)).comp + MeasurableEquiv.setOfPred.symm.measurable)) + + theorem law_map_baseField (q : unitInterval) (m : ℕ) : + (law q : Measure (Set (E × Fin (m+1)))).map (baseField m) = law (orParameter q m) := by + have hm : Measurable (fun ω : Set (E × Fin (m+1)) => colorInclusion m ⁻¹' ω) := + measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_pi_apply (colorInclusion m e)).comp + MeasurableEquiv.setOfPred.symm.measurable)) + change (law q).map ((fun ω : Set (E × Fin m) => Prod.fst '' ω) ∘ + (fun ω => colorInclusion m ⁻¹' ω)) = _ + rw [← Measure.map_map (measurable_image_fst (Fin m)) hm, + law_map_preimage_embedding, law_map_image_fst, Fintype.card_fin] + + noncomputable def dartSource (G : BondGraph V E) (d : E × Bool) : V := + if d.2 then (G d.1).out.1 else (G d.1).out.2 + noncomputable def dartTarget (G : BondGraph V E) (d : E × Bool) : V := + if d.2 then (G d.1).out.2 else (G d.1).out.1 + + theorem exists_dart (G : BondGraph V E) {e : E} {a b : V} (h : G e = s(a,b)) : + ∃ j : Bool, dartSource G (e,j) = a ∧ dartTarget G (e,j) = b := by + have he : s((G e).out.1, (G e).out.2) = s(a,b) := (G e).out_eq.trans h + rcases Sym2.eq_iff.mp he with h | h + · exact ⟨true,h⟩ + · exact ⟨false,h.2,h.1⟩ + + theorem colored_conn_probability [Countable V] [Countable E] (G : BondGraph V E) + (q : unitInterval) (m : ℕ) (x y : V) : + (law q).real {ω : Set (E × Fin m) | Conn (G ∘ Prod.fst) ω x y} = + twoPoint G (orParameter q m) x y := by + have h := law_map_image_fst (E := E) q (Fin m) + simp only [Fintype.card_fin] at h + rw [twoPoint, ← h, Measure.map_apply (measurable_image_fst (Fin m)) + (measurableSet_conn G x y)] + congr 1 + ext ω + exact conn_map_edges G Prod.fst ω x y + + theorem base_conn_probability [Countable V] [Countable E] (G : BondGraph V E) + (q : unitInterval) (m : ℕ) (x y : V) : + (law q).real {ω : Set (E × Fin (m+1)) | + Conn (G ∘ Prod.fst) (ω ∩ baseColors m) x y} = + twoPoint G (orParameter q m) x y := by + rw [twoPoint, ← law_map_baseField (E := E) q m, + Measure.map_apply (measurable_baseField m) (measurableSet_conn G x y)] + congr 1 + ext ω + change Conn (G ∘ Prod.fst) (ω ∩ baseColors m) x y ↔ Conn G (baseField m ω) x y + rw [conn_map_edges, fst_inter_baseColors] + + + + theorem twoPoint_or_succ_le [Countable V] [Fintype E] (G : BondGraph V E) (q : unitInterval) + (m : ℕ) (x y : V) : + twoPoint G (orParameter q (m+1)) x y ≤ twoPoint G (orParameter q m) x y + + (q : ℝ) * ∑ d : E × Bool, + twoPoint G (orParameter q m) x (dartSource G d) * + twoPoint G (orParameter q (m+1)) (dartTarget G d) y := by + let H : BondGraph V (E × Fin (m+1)) := G ∘ Prod.fst + let A (a : V) : Set (Set (E × Fin (m+1))) := + {ω | Conn H (ω ∩ baseColors m) x a} + let B (b : V) : Set (Set (E × Fin (m+1))) := {ω | Conn H ω b y} + let C (d : E × Bool) := DisjointOccurrence (A (dartSource G d)) + (DisjointOccurrence {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d))) + have huA (a : V) : IsUpperSet (A a) := + fun _ _ h hω => conn_mono H (Set.inter_subset_inter_left _ h) hω + have hfA (a : V) : FiniteWitness (A a) := + finiteWitness_inter _ (finiteWitness_conn H x a) _ + have huB (b : V) : IsUpperSet (B b) := fun _ _ h hω => conn_mono H h hω + have hfB (b : V) : FiniteWitness (B b) := finiteWitness_conn H b y + have hsub : {ω | Conn H ω x y} ⊆ A y ∪ ⋃ d : E × Bool, C d := by + intro ω hω + rcases conn_first_outside H (baseColors m) hω with ha | ⟨a,b,⟨e,j⟩,he,hj,hc⟩ + · exact Or.inl ha + · have hj' := (not_mem_baseColors m e j).mp hj + subst j + obtain ⟨k,hk₁,hk₂⟩ := exists_dart G he + right + refine Set.mem_iUnion.mpr ⟨(e,k),?_⟩ + simpa only [C,hk₁,hk₂] using hc + calc + twoPoint G (orParameter q (m+1)) x y = (law q).real {ω | Conn H ω x y} := + (colored_conn_probability G q (m+1) x y).symm + _ ≤ (law q).real (A y ∪ ⋃ d : E × Bool, C d) := measureReal_mono hsub + _ ≤ (law q).real (A y) + (law q).real (⋃ d : E × Bool, C d) := measureReal_union_le _ _ + _ ≤ (law q).real (A y) + ∑ d : E × Bool, (law q).real (C d) := + add_le_add_right (measureReal_iUnion_fintype_le _) _ + _ ≤ twoPoint G (orParameter q m) x y + + ∑ d : E × Bool, twoPoint G (orParameter q m) x (dartSource G d) * + ((q : ℝ) * twoPoint G (orParameter q (m+1)) (dartTarget G d) y) := by + rw [show (law q).real (A y) = twoPoint G (orParameter q m) x y from + base_conn_probability G q m x y] + apply add_le_add_right + apply Finset.sum_le_sum + intro d _ + have hb := bk q {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d)) + (fun _ _ hh he => hh he) (huB _) (finiteWitness_edge _) (hfB _) + have heq : (law q).real {ω : Set (E × Fin (m+1)) | (d.1,Fin.last m) ∈ ω} = + (q : ℝ) := by simpa using finite_open_probability q {(d.1,Fin.last m)} + rw [heq, show (law q).real (B (dartTarget G d)) = + twoPoint G (orParameter q (m+1)) (dartTarget G d) y from + colored_conn_probability G q (m+1) _ _] at hb + have ha := bk q (A (dartSource G d)) + (DisjointOccurrence {ω | (d.1,Fin.last m) ∈ ω} (B (dartTarget G d))) + (huA _) (disjointOccurrence_upper _ _) (hfA _) (finiteWitness_disjointOccurrence _ _) + rw [show (law q).real (A (dartSource G d)) = + twoPoint G (orParameter q m) x (dartSource G d) from base_conn_probability G q m _ _] at ha + exact ha.trans (mul_le_mul_of_nonneg_left hb (twoPoint_nonneg G _ _ _)) + _ = _ := by rw [Finset.mul_sum]; congr 1; apply Finset.sum_congr rfl; intro d _; ring + +end ColoredSprinkling + +section FiniteGraphOperators +attribute [local instance] Classical.propDecidable + + noncomputable def edgeVertices [Fintype E] (G : BondGraph V E) : Finset V := + Finset.univ.biUnion (fun e => (G e).toFinset) + + theorem mem_edgeVertices [Fintype E] (G : BondGraph V E) (x : V) : + x ∈ edgeVertices G ↔ ∃ e, x ∈ G e := by simp [edgeVertices] + + theorem conn_eq_or_mem_edgeVertices [Fintype E] (G : BondGraph V E) + {ω : Set E} {x y : V} (h : Conn G ω x y) : x = y ∨ y ∈ edgeVertices G := by + cases h with + | refl => exact Or.inl rfl + | @tail a b hab he => + rcases he with ⟨e,_,he⟩ + exact Or.inr ((mem_edgeVertices G y).mpr ⟨e,by rw [he]; simp⟩) + + theorem operatorBounded_finite_edges [Fintype E] (G : BondGraph V E) (p : unitInterval) : + OperatorBounded G p := by + have hr (x : V) (s : Finset V) : ∑ y ∈ s, twoPoint G p x y ≤ + (edgeVertices G).card + (1 : ℝ) := by + let F := insert x (edgeVertices G) + have bound (y : V) : twoPoint G p x y ≤ if y ∈ F then 1 else 0 := by + split_ifs with hy + · exact twoPoint_le_one G p x y + · have he : {ω | Conn G ω x y} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro ω h + rcases conn_eq_or_mem_edgeVertices G h with rfl | hmem + · exact hy (by simp [F]) + · exact hy (by simp [F,hmem]) + simp [twoPoint,he] + calc + ∑ y ∈ s, twoPoint G p x y ≤ ∑ y ∈ s, if y ∈ F then (1:ℝ) else 0 := + Finset.sum_le_sum (fun y _ => bound y) + _ = ((s ∩ F).card : ℝ) := by simp + _ ≤ (F.card : ℝ) := by + exact_mod_cast Finset.card_le_card Finset.inter_subset_right + _ ≤ (edgeVertices G).card + (1 : ℝ) := by + exact_mod_cast Finset.card_insert_le x (edgeVertices G) + obtain ⟨A,_,hA⟩ := exists_operator_of_row_column_bound (twoPoint G p) + ((edgeVertices G).card+1) (by positivity) (twoPoint_nonneg G p) hr + (fun y s => by simpa only [twoPoint_symm G p] using hr y s) + exact ⟨A,hA⟩ + + theorem dart_edge (G : BondGraph V E) (d : E × Bool) : + G d.1 = s(dartSource G d, dartTarget G d) := by + rcases d with ⟨e,j⟩ + cases j + · exact (G e).out_eq.symm.trans (Sym2.eq_swap ..) + · exact (G e).out_eq.symm + + theorem card_darts_at_source [Fintype E] (G : BondGraph V E) (x : V) : + Fintype.card {d : E × Bool // dartSource G d = x} ≤ 2 * degree G x := by + let : Fintype (Step G x) := (finite_steps G (fun _ => Set.toFinite _) x).fintype + let f : {d : E × Bool // dartSource G d = x} → Step G x × Bool := fun d => + (⟨(d.val.1,dartTarget G d.val), by rw [dart_edge G d.val,d.property]⟩,d.val.2) + have hf : Function.Injective f := by + intro d d' h + apply Subtype.ext + apply Prod.ext + · exact congrArg (fun t : Step G x × Bool => t.1.val.1) h + · exact congrArg (fun t : Step G x × Bool => t.2) h + have hc := Fintype.card_le_of_injective f hf + simpa only [Fintype.card_prod,Fintype.card_bool,degree,Nat.card_eq_fintype_card,Nat.mul_comm] using hc + + theorem card_darts_at_target [Fintype E] (G : BondGraph V E) (x : V) : + Fintype.card {d : E × Bool // dartTarget G d = x} ≤ 2 * degree G x := by + let : Fintype (Step G x) := (finite_steps G (fun _ => Set.toFinite _) x).fintype + let f : {d : E × Bool // dartTarget G d = x} → Step G x × Bool := fun d => + (⟨(d.val.1,dartSource G d.val), by + rw [dart_edge G d.val,d.property]; exact Sym2.eq_swap ..⟩,d.val.2) + have hf : Function.Injective f := by + intro d d' h + apply Subtype.ext + apply Prod.ext + · exact congrArg (fun t : Step G x × Bool => t.1.val.1) h + · exact congrArg (fun t : Step G x × Bool => t.2) h + have hc := Fintype.card_le_of_injective f hf + simpa only [Fintype.card_prod,Fintype.card_bool,degree,Nat.card_eq_fintype_card,Nat.mul_comm] using hc + + noncomputable def adjacencyOperator [Fintype E] (G : BondGraph V E) : + Hilbert V →L[ℂ] Hilbert V := + ∑ d : E × Bool, (lp.singleContinuousLinearMap ℂ (fun _ : V => ℂ) 2 (dartSource G d)).comp + (lp.evalCLM ℂ (fun _ : V => ℂ) 2 (dartTarget G d)) + + theorem adjacencyOperator_apply [Fintype E] (G : BondGraph V E) (f : Hilbert V) : + adjacencyOperator G f = ∑ d : E × Bool, lp.single 2 (dartSource G d) (f (dartTarget G d)) := by + simp [adjacencyOperator,lp.singleContinuousLinearMap_apply, + lp.evalCLM,lp.evalₗ] + rfl + + theorem adjacencyOperator_norm_le [Fintype E] (G : BondGraph V E) + (D : ℕ) (hD : ∀ x, degree G x ≤ D) : ‖adjacencyOperator G‖ ≤ 2 * (D : ℝ) := by + let U (x y : V) : ℝ := ∑ d : E × Bool, + if dartSource G d = x ∧ dartTarget G d = y then 1 else 0 + have hU : ∀ x y, 0 ≤ U x y := by intro x y; apply Finset.sum_nonneg; intro d _; positivity + have hmat : ∀ x y, adjacencyOperator G (lp.single 2 y (1:ℂ)) x = (U x y : ℂ) := by + intro x y + rw [adjacencyOperator_apply] + simp only [lp.coeFn_sum,Finset.sum_apply,U,Complex.ofReal_sum] + apply Finset.sum_congr rfl + intro d _ + simp only [lp.single_apply] + by_cases hx : dartSource G d = x <;> by_cases hy : dartTarget G d = y <;> + simp [hx,hy] + have hrow (x : V) (s : Finset V) : ∑ y ∈ s, U x y ≤ 2 * (D : ℝ) := by + calc + ∑ y ∈ s, U x y = ∑ d : E × Bool, + ∑ y ∈ s, if dartSource G d = x ∧ dartTarget G d = y then (1:ℝ) else 0 := + Finset.sum_comm + _ ≤ ∑ d : E × Bool, if dartSource G d = x then (1:ℝ) else 0 := by + apply Finset.sum_le_sum + intro d _ + by_cases hx : dartSource G d = x + · simp only [hx,true_and,ite_true] + rw [Finset.sum_ite_eq] + split_ifs <;> norm_num + · simp [hx] + _ = (Fintype.card {d : E × Bool // dartSource G d = x} : ℝ) := by simp [Fintype.card_subtype] + _ ≤ 2 * (D : ℝ) := by exact_mod_cast (card_darts_at_source G x).trans (Nat.mul_le_mul_left 2 (hD x)) + have hcol (y : V) (s : Finset V) : ∑ x ∈ s, U x y ≤ 2 * (D : ℝ) := by + calc + ∑ x ∈ s, U x y = ∑ d : E × Bool, + ∑ x ∈ s, if dartSource G d = x ∧ dartTarget G d = y then (1:ℝ) else 0 := + Finset.sum_comm + _ ≤ ∑ d : E × Bool, if dartTarget G d = y then (1:ℝ) else 0 := by + apply Finset.sum_le_sum + intro d _ + by_cases hy : dartTarget G d = y + · simp only [hy,and_true,ite_true] + rw [Finset.sum_ite_eq] + split_ifs <;> norm_num + · simp [hy] + _ = (Fintype.card {d : E × Bool // dartTarget G d = y} : ℝ) := by simp [Fintype.card_subtype] + _ ≤ 2 * (D : ℝ) := by exact_mod_cast (card_darts_at_target G y).trans (Nat.mul_le_mul_left 2 (hD y)) + obtain ⟨A,hn,hA⟩ := exists_operator_of_row_column_bound U (2*D) (by positivity) hU hrow hcol + rwa [kernel_extension_unique hmat hA] + +end FiniteGraphOperators + +section FiniteSprinklingBound +attribute [local instance] Classical.propDecidable +variable [Countable V] [Fintype E] + + theorem finite_sprinkling_bound (G : BondGraph V E) (q : unitInterval) (m D : ℕ) + (hD : ∀ x, degree G x ≤ D) (A : Hilbert V →L[ℂ] Hilbert V) + (hA : HasKernel G (orParameter q m) A) (M : ℝ) (hM : ‖A‖ ≤ M) + (hq : (q : ℝ) * (2*D) * M < 1) : + ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+1)) B ∧ + ‖B‖ ≤ M / (1-(q:ℝ)*(2*D)*M) := by + obtain ⟨B,hB⟩ := operatorBounded_finite_edges G (orParameter q (m+1)) + let R := (adjacencyOperator G).comp B + let C := A + (q : ℂ) • A.comp R + let U (x y : V) := twoPoint G (orParameter q m) x y + (q:ℝ) * + ∑ d : E × Bool, twoPoint G (orParameter q m) x (dartSource G d) * + twoPoint G (orParameter q (m+1)) (dartTarget G d) y + have hU : ∀ x y, 0 ≤ U x y := by + intro x y + exact add_nonneg (twoPoint_nonneg G _ _ _) + (mul_nonneg q.2.1 (Finset.sum_nonneg fun d _ => + mul_nonneg (twoPoint_nonneg G _ _ _) (twoPoint_nonneg G _ _ _))) + have hC : ∀ x y, C (lp.single 2 y (1:ℂ)) x = (U x y : ℂ) := by + intro x y + simp only [C,add_apply,smul_apply, + ContinuousLinearMap.comp_apply,R,adjacencyOperator_apply,map_sum,lp.coeFn_add,Pi.add_apply, + lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,lp.coeFn_sum,Finset.sum_apply,U, + Complex.ofReal_add,Complex.ofReal_mul,Complex.ofReal_sum] + rw [hA x y] + congr 1 + congr 1 + apply Finset.sum_congr rfl + intro d _ + have hs (c : ℂ) : (lp.single 2 (dartSource G d) c : Hilbert V) = c • lp.single 2 (dartSource G d) (1:ℂ) := by + rw [← lp.single_smul]; simp + rw [hs,map_smul,lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,hA,hB] + ring + obtain ⟨B',hn,hB'⟩ := exists_operator_of_matrix_domination U + (twoPoint G (orParameter q (m+1))) hU + (fun x y => by rw [abs_of_nonneg (twoPoint_nonneg G _ _ _)]; exact twoPoint_or_succ_le G q m x y) + C hC + have he : B' = B := kernel_extension_unique hB' hB + rw [he] at hn + have hqn : ‖(q : ℂ)‖ = (q : ℝ) := by simp [abs_of_nonneg q.2.1] + have hcoef : (q : ℝ) * ‖A‖ * (2*D) * ‖B‖ ≤ (q : ℝ) * M * (2*D) * ‖B‖ := by + gcongr + exact q.2.1 + have hbnd : ‖B‖ ≤ M + (q : ℝ) * (2*D) * M * ‖B‖ := by + calc + ‖B‖ ≤ ‖C‖ := hn + _ ≤ ‖A‖ + ‖(q : ℂ) • A.comp R‖ := norm_add_le _ _ + _ = ‖A‖ + (q : ℝ) * ‖A.comp R‖ := by rw [norm_smul,hqn] + _ ≤ ‖A‖ + (q : ℝ) * (‖A‖ * (‖adjacencyOperator G‖ * ‖B‖)) := by + apply add_le_add_right + apply mul_le_mul_of_nonneg_left _ q.2.1 + exact (A.opNorm_comp_le R).trans + (mul_le_mul_of_nonneg_left ((adjacencyOperator G).opNorm_comp_le B) (norm_nonneg _)) + _ ≤ ‖A‖ + (q : ℝ) * (‖A‖ * ((2*D) * ‖B‖)) := by + gcongr + · exact q.2.1 + · exact adjacencyOperator_norm_le G D hD + _ ≤ M + (q : ℝ) * M * (2*D) * ‖B‖ := by + rw [show (q : ℝ) * (‖A‖ * ((2*D) * ‖B‖)) = (q : ℝ) * ‖A‖ * (2*D) * ‖B‖ by ring] + exact add_le_add hM hcoef + _ = _ := by ring + refine ⟨B,hB,?_⟩ + apply (le_div_iff₀ (sub_pos.mpr hq)).mpr + nlinarith + +end FiniteSprinklingBound + +section ExhaustionSprinkling +attribute [local instance] Classical.propDecidable +open Filter Topology +variable [Countable V] [Countable E] + + theorem twoPoint_restrict_edges (G : BondGraph V E) (p : unitInterval) (S : Set E) (x y : V) : + twoPoint (G ∘ (Subtype.val : S → E)) p x y = + (law p).real {ω : Set E | Conn G (ω ∩ S) x y} := by + unfold twoPoint + rw [← law_map_restrict p S, Measure.map_apply (measurable_set_restrict S) + (measurableSet_conn (G ∘ Subtype.val) x y)] + apply congrArg ENNReal.toReal + congr 1 + ext ω + change Conn (G ∘ Subtype.val) (Subtype.val ⁻¹' ω) x y ↔ _ + rw [conn_map_edges] + have he : (Subtype.val '' (Subtype.val ⁻¹' ω : Set S)) = ω ∩ S := by + ext e + simp only [Set.mem_image,Set.mem_preimage,Set.mem_inter_iff] + constructor + · rintro ⟨d,hd,rfl⟩; exact ⟨hd,d.property⟩ + · rintro ⟨ho,hs⟩; exact ⟨⟨e,hs⟩,ho,rfl⟩ + rw [he] + rfl + + theorem twoPoint_restrict_le (G : BondGraph V E) (p : unitInterval) (S : Set E) (x y : V) : + twoPoint (G ∘ (Subtype.val : S → E)) p x y ≤ twoPoint G p x y := by + rw [twoPoint_restrict_edges] + exact measureReal_mono (fun ω h => conn_mono G Set.inter_subset_left h) (measure_ne_top _ _) + + omit [Countable V] [Countable E] in + theorem degree_restrict_le (G : BondGraph V E) (hloc : LocallyFinite G) (S : Set E) (x : V) : + degree (G ∘ (Subtype.val : S → E)) x ≤ degree G x := by + let : Fintype (Step G x) := (finite_steps G hloc x).fintype + let f : Step (G ∘ (Subtype.val : S → E)) x → Step G x := + fun d => ⟨(d.val.1.val,d.val.2),d.property⟩ + apply Nat.card_le_card_of_injective f + intro d d' h + apply Subtype.ext + apply Prod.ext + · apply Subtype.ext + exact congrArg (fun t : Step G x => t.val.1) h + · exact congrArg (fun t : Step G x => t.val.2) h + + theorem sprinkling_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (q : unitInterval) (m D : ℕ) (hD : ∀ x, degree G x ≤ D) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G (orParameter q m) A) + (hq : (q : ℝ) * (2*D) * ‖A‖ < 1) : + ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+1)) B ∧ + ‖B‖ ≤ ‖A‖ / (1-(q:ℝ)*(2*D)*‖A‖) := by + let := Encodable.ofCountable E + let F (n : ℕ) := edgeExhaustion (E := E) n + let H (n : ℕ) : BondGraph V (F n) := G ∘ Subtype.val + have hb (n : ℕ) : ∃ B : Hilbert V →L[ℂ] Hilbert V, + HasKernel (H n) (orParameter q (m+1)) B ∧ + ‖B‖ ≤ ‖A‖ / (1-(q:ℝ)*(2*D)*‖A‖) := by + obtain ⟨A',hn,hA'⟩ := exists_operator_of_matrix_domination + (twoPoint G (orParameter q m)) (twoPoint (H n) (orParameter q m)) + (twoPoint_nonneg G _) (fun x y => by + rw [abs_of_nonneg (twoPoint_nonneg (H n) _ _ _)] + exact twoPoint_restrict_le G _ (F n) x y) A hA + exact finite_sprinkling_bound (H n) q m D + (fun x => (degree_restrict_le G hloc (F n) x).trans (hD x)) A' hA' ‖A‖ hn hq + choose B hB hn using hb + have hlim (x y : V) : Tendsto (fun n => twoPoint (H n) (orParameter q (m+1)) x y) + atTop (𝓝 (twoPoint G (orParameter q (m+1)) x y)) := by + have hm : Monotone (fun n => {ω : Set E | Conn G (ω ∩ (F n : Set E)) x y}) := by + intro m n h ω hω + exact conn_mono G (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω + have h := tendsto_measure_iUnion_atTop (μ := law (orParameter q (m+1))) hm + have he := witness_eq_union {ω | Conn G ω x y} (fun _ _ h hc => conn_mono G h hc) + (finiteWitness_conn G x y) + change {ω : Set E | Conn G ω x y} = ⋃ n, {ω | Conn G (ω ∩ (F n : Set E)) x y} at he + rw [← he] at h + have hr := (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h + apply hr.congr' + apply Filter.Eventually.of_forall + intro n + exact (twoPoint_restrict_edges G (orParameter q (m+1)) (F n) x y).symm + obtain ⟨C,hCn,hC⟩ := exists_operator_of_matrix_tendsto B + (fun x y => (twoPoint G (orParameter q (m+1)) x y : ℂ)) + (div_nonneg (norm_nonneg _) (sub_pos.mpr hq).le) hn (fun x y => by + have hBm : ∀ n x y, B n (lp.single 2 y (1:ℂ)) x = (twoPoint (H n) (orParameter q (m+1)) x y : ℂ) := hB + simp only [hBm] + exact Complex.continuous_ofReal.continuousAt.tendsto.comp (hlim x y)) + exact ⟨C,hC,hCn⟩ + +end ExhaustionSprinkling + +section Openness +attribute [local instance] Classical.propDecidable + + theorem operatorBounded_open_right [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (p : unitInterval) (hp0 : 0 < p) (hp1 : p < 1) (hb : OperatorBounded G p) : + ∃ r : unitInterval, p < r ∧ OperatorBounded G r := by + obtain ⟨A,hA⟩ := hb + let c : ℝ := (2*D)*‖A‖ + have hc : 0 ≤ c := by dsimp [c]; positivity + obtain ⟨m,q,hq,hqp⟩ := exists_orParameter_small p hp1 (1/(c+1)) + (by positivity) (by apply (div_le_one (by positivity)).mpr; linarith) + have hq0 : (0:ℝ) < q := by + by_contra h + have hqe : q = 0 := Subtype.ext ((le_of_not_gt h).antisymm q.2.1) + have hpe : p = 0 := by rw [← hqp,hqe]; apply Subtype.ext; simp [orParameter] + exact (ne_of_gt hp0) hpe + have hsmall : (q:ℝ)*(2*D)*‖A‖ < 1 := by + have hm := mul_le_mul_of_nonneg_right hq hc + have hh : c/(c+1) < 1 := (div_lt_one (by positivity)).mpr (by linarith) + calc + (q:ℝ)*(2*D)*‖A‖ = (q:ℝ)*c := by dsimp [c]; ring + _ ≤ 1/(c+1)*c := hm + _ = c/(c+1) := by ring + _ < 1 := hh + obtain ⟨B,hB,_⟩ := sprinkling_bound G hloc q m D hD A (hqp ▸ hA) hsmall + refine ⟨orParameter q (m+1),?_,B,hB⟩ + change (p:ℝ) < (orParameter q (m+1):ℝ) + have he : (orParameter q (m+1):ℝ) = (p:ℝ)+(1-p)*q := by + rw [← hqp] + simp only [orParameter,pow_succ] + ring + rw [he] + have ht := mul_pos (show (0:ℝ) < 1-p from sub_pos.mpr hp1) hq0 + linarith + + + + theorem mainConclusion_of_critical_bounded [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hc : OperatorBounded G (pc G)) : MainConclusion G := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + have hpc1 : pc G < 1 := by + apply lt_of_le_of_ne (show pc G ≤ 1 from (pc G).2.2) + intro he + exact not_operatorBounded_one G hconn (he ▸ hc) + obtain ⟨D,_,hD⟩ := exists_degree_bound G hqt + obtain ⟨q,hq,hb⟩ := operatorBounded_open_right G hloc D hD (pc G) + (pc_pos G hloc hqt) hpc1 hc + exact mainConclusion_of_strict_gap G hconn hloc hqt + (hq.trans_le (le_sSup hb)) + +end Openness + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Kernel/TraceBounds.lean b/lean/OAI/Probability/UnimodularPercolation/Kernel/TraceBounds.lean index c05739004a95ab08a01fd2b7605f724242c78d71..4324e98aa9eec1d5f2652dfb6bc79bfd6dc281c7 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Kernel/TraceBounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Kernel/TraceBounds.lean @@ -1,1270 +1,1270 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.RussoRows - -namespace OAI - -/-! Trace Bounds for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section RussoOperator -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem russoSlope_symm [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x y : V) : - russoSlope G x y (p:ℝ) = russoSlope G y x (p:ℝ) := by - have hh := hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ x y - have he : realTwoPoint G x y = realTwoPoint G y x := funext (fun _ => twoPoint_symm G _ x y) - rw [he] at hh - exact hh.unique (hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ y x) - -theorem russoSlope_aut [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : - russoSlope G (a x) (a y) (p:ℝ) = russoSlope G x y (p:ℝ) := by - have hh := hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ (a x) (a y) - have he : realTwoPoint G (a x) (a y) = realTwoPoint G x y := funext (fun _ => twoPoint_aut G _ hab x y) - rw [he] at hh - exact hh.unique (hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ x y) - - - -theorem exists_russoOperator [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : - ∃ D : Hilbert V →L[ℂ] Hilbert V, - ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ) := by - obtain ⟨R,hR,hrow⟩ := russoMajorant_uniform_row_bound G hloc hqt p hp - have hb (x : V) (s : Finset V) : ∑ y ∈ s, russoSlope G x y (p:ℝ) ≤ R := by - calc - _ ≤ ∑ y ∈ s, russoMajorant G p x y := Finset.sum_le_sum (fun y _ => russoSlope_le_majorant G hloc hqt p p hp le_rfl x y) - _ ≤ ∑' y, russoMajorant G p x y := Summable.sum_le_tsum s (fun y _ => russoMajorant_nonneg G p x y) - (summable_russoMajorant G hloc hqt p hp x) - _ ≤ R := hrow x - obtain ⟨D,_,hD⟩ := exists_operator_of_row_column_bound (fun x y => russoSlope G x y (p:ℝ)) R hR - (fun x y => russoSlope_nonneg G x y p p.2.2) hb - (fun y s => by simpa only [russoSlope_symm G hloc hqt p hp0 hp] using hb y s) - exact ⟨D,hD⟩ - -theorem russoOperator_positiveReal (G : BondGraph V E) (p : unitInterval) - (D : Hilbert V →L[ℂ] Hilbert V) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : PositiveRealMatrix D := by - intro x y - rw [hD x y] - exact ⟨rfl,russoSlope_nonneg G x y p p.2.2⟩ - -theorem russoOperator_invariant [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (D : Hilbert V →L[ℂ] Hilbert V) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) : KernelInvariant Γ D := by - intro a ha x y - obtain ⟨b,hab⟩ := hΓ ha - simp only [hD,russoSlope_aut G hloc hqt p hp0 hp hab] - -end RussoOperator -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section PositiveTriangleSeries -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem PositiveRealMatrix.triple_hasSum - {A B C : Hilbert V →L[ℂ] Hilbert V} - (hA : PositiveRealMatrix A) (hB : PositiveRealMatrix B) (hC : PositiveRealMatrix C) - (x y : V) : - HasSum (fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * - (matrixCoeff C ab.2 y).re) (matrixCoeff (A*B*C) x y).re := by - have hi (a : V) : HasSum (fun b => (matrixCoeff A x a).re * (matrixCoeff B a b).re * (matrixCoeff C b y).re) - ((matrixCoeff A x a).re * (matrixCoeff (B*C) a y).re) := by - simpa only [mul_assoc] using (hB.mul_hasSum C a y).mul_left (matrixCoeff A x a).re - have ho := hA.mul_hasSum (B*C) x y - have hs : Summable (fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) := by - apply (summable_prod_of_nonneg (f := fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) - (fun ab => mul_nonneg (mul_nonneg (hA _ _).2 (hB _ _).2) (hC _ _).2)).mpr - refine ⟨fun a => (hi a).summable,?_⟩ - simp only [(hi _).tsum_eq] - exact ho.summable - have he : (∑' ab : V×V, (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) = - (matrixCoeff (A*B*C) x y).re := by - rw [hs.tsum_prod] - simp only [(hi _).tsum_eq] - rw [ho.tsum_eq,mul_assoc] - exact he ▸ hs.hasSum - -theorem HasKernel.matrixCoeff_re (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : - (matrixCoeff T x y).re = twoPoint G p x y := by - change (T (lp.single 2 y (1:ℂ)) x).re = _ - rw [hT x y,Complex.ofReal_re] - -theorem realTriangle_eq_matrixCoeff (G : BondGraph V E) (p : unitInterval) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x : V) : - realTriangle G x (p:ℝ) = (matrixCoeff (T^3) x x).re := by - have ht := hT.positiveRealMatrix G p T - have hs := ht.triple_hasSum ht ht x x - rw [show T*T*T = T^3 by simp only [pow_succ,pow_zero,one_mul]] at hs - simpa only [HasKernel.matrixCoeff_re G p T hT,realTriangle,realTriangleTerm,realTwoPoint_coe] using hs.tsum_eq - -theorem rootTriangle_eq_trace (G : BondGraph V E) (p : unitInterval) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : - rootTriangle G root weight (p:ℝ) = (rootTrace root weight (T^3)).re := by - simp only [rootTriangle,realTriangle_eq_matrixCoeff G p T hT,rootTrace,Complex.re_sum, - Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] - -theorem triangleSlope_eq_matrixCoeff (G : BondGraph V E) (p : unitInterval) - (T D : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) (x : V) : - (∑' ab, realTriangleSlope G x ab (p:ℝ)) = - (matrixCoeff (D*T*T + T*D*T + T*T*D) x x).re := by - have ht := hT.positiveRealMatrix G p T - have hd := russoOperator_positiveReal G p D hD - have h₁ := (hd.triple_hasSum ht ht x x) - have h₂ := (ht.triple_hasSum hd ht x x) - have h₃ := (ht.triple_hasSum ht hd x x) - have h := (h₁.add h₂).add h₃ - have ha (A B : Hilbert V →L[ℂ] Hilbert V) : matrixCoeff (A+B) x x = matrixCoeff A x x + matrixCoeff B x x := rfl - simp only [ha,Complex.add_re] - simpa only [hD,Complex.ofReal_re,HasKernel.matrixCoeff_re G p T hT, - realTriangleSlope,realTwoPoint_coe] using h.tsum_eq - -end PositiveTriangleSeries -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section RootTriangleTraceDerivative -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem rootTrace_triangleSlope_cyclic - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - {Γ : Set (V ≃ V)} (htr : RootTransport root weight Γ) - (T D : Hilbert V →L[ℂ] Hilbert V) (hT : KernelInvariant Γ T) (hD : KernelInvariant Γ D) : - rootTrace root weight (D*T*T+T*D*T+T*T*D) = 3*rootTrace root weight (T^2*D) := by - have h₁ : rootTrace root weight (D*T*T) = rootTrace root weight (T^2*D) := by - rw [mul_assoc,rootTrace_cyclic root weight htr D (T*T) hD (hT.mul hT),pow_two] - have h₂ : rootTrace root weight (T*D*T) = rootTrace root weight (T^2*D) := by - rw [mul_assoc,rootTrace_cyclic root weight htr T (D*T) hT (hD.mul hT),h₁] - rw [rootTrace_add,rootTrace_add,h₁,h₂,←pow_two] - ring - - - -theorem hasDerivAt_rootTriangle_trace [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (T D : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : - HasDerivAt (rootTriangle G root weight) (3*(rootTrace root weight (T^2*D)).re) (p:ℝ) := by - have hti : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - have hdi := russoOperator_invariant G hloc hqt p hp0 hp D hD Γ hΓ - have hs := hasDerivAt_rootTriangle_subcritical G hloc hqt root weight p hp0 hp - have he : (∑ i, weight i * ∑' ab, realTriangleSlope G (root i) ab (p:ℝ)) = - 3*(rootTrace root weight (T^2*D)).re := by - simp only [triangleSlope_eq_matrixCoeff G p T D hT hD] - have hr := congrArg Complex.re (rootTrace_triangleSlope_cyclic root weight htr T D hti hdi) - simpa only [rootTrace,Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im, - Complex.re_ofNat,Complex.im_ofNat,zero_mul,sub_zero] using hr - exact he ▸ hs - -end RootTriangleTraceDerivative -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section ContactKernelReroot -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem contactKernel_reroot [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) - (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) - (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y) = - ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, - J (root i) y * ENNReal.ofReal (fullLargeContact G (root i) y 0 ω) ∂law p := by - have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin - J hJ (fun ω x y => ENNReal.ofReal (fullLargeContact G x y 0 ω)) - (fun x y => (measurable_fullLargeContact G hloc x y 0).ennreal_ofReal) - (fun ω x y a b hxa hyb => congrArg ENNReal.ofReal (fullLargeContact_cluster_constant G ω 0 x y a b hxa hyb)) - (fun a _ b hab ω x y => congrArg ENNReal.ofReal (fullLargeContact_aut G hab ω x y 0)) - simp_rw [fullLargeContact_distinct] at ht - rw [←ht] - unfold clusterPairFunctional - apply Finset.sum_congr rfl - intro i _ - congr 1 - apply lintegral_congr_ae - filter_upwards [hfin (root i)] with ω hω - unfold clusterPairDensity - congr 1 - apply tsum_congr - intro y - congr 1 - by_cases hd : Conn G ω (root i) y - · simp only [hd,not_true_eq_false,ite_false] - · rw [ite_eq_left hd,ite_eq_left hd] - dsimp only - rw [clusterPairKernel_edge G hloc ω (root i) y hd hω] - simp only [fullLargeContact,hd,not_false_eq_true,Nat.zero_le,and_self,ite_true,ENNReal.ofReal_natCast] - exact mul_comm _ _ - -theorem contact_lintegral_eq_russoOperator [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (D : Hilbert V →L[ℂ] Hilbert V) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) (x y : V) : - (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = - ENNReal.ofReal (1-(p:ℝ)) * ennMatrixCoeff D x y := by - rw [←ofReal_integral_eq_lintegral_ofReal (integrable_fullContact_subcritical G hloc hqt p hp x y) - (Eventually.of_forall (fullLargeContact_nonneg G x y 0))] - simp only [ennMatrixCoeff,hD,Complex.ofReal_re,russoSlope,realContactExpectation_coe] - rw [←ENNReal.ofReal_mul (sub_nonneg.mpr p.2.2)] - congr 1 - have hd : 1-(p:ℝ) ≠ 0 := ne_of_gt (sub_pos.mpr ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2)) - exact (mul_div_cancel₀ _ hd).symm - -end ContactKernelReroot -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -open scoped ENNReal -section MixedRussoTrace -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem mixedFunctional_eq_russoTrace [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (J D : Hilbert V →L[ℂ] Hilbert V) (hJ : PositiveRealMatrix J) (hiJ : KernelInvariant Γ J) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : - clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff J) x y) = - ENNReal.ofReal ((1-(p:ℝ))*(rootTrace root weight (J*D)).re) := by - have hd := russoOperator_positiveReal G p D hD - have hdi (x y : V) : ennMatrixCoeff D x y = ennMatrixCoeff D y x := by - simp only [ennMatrixCoeff,hD,Complex.ofReal_re,russoSlope_symm G hloc hqt p hp0 hp x y] - have hji : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff J (a x) (a y) = ennMatrixCoeff J x y := by - intro a ha x y; unfold ennMatrixCoeff; rw [hiJ a ha] - rw [contactKernel_reroot G hconn hloc root weight Γ hΓ htr hw p - (subcritical_cluster_finite_ae G p hp) (ennMatrixCoeff J) hji] - have he (x : V) : (∫⁻ ω, ∑' y, ennMatrixCoeff J x y * ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = - ENNReal.ofReal (1-(p:ℝ)) * ennMatrixCoeff (J*D) x x := by - have hm (y : V) : Measurable (fun ω : Set E => ennMatrixCoeff J x y * ENNReal.ofReal (fullLargeContact G x y 0 ω)) := - (measurable_const : Measurable (fun _ : Set E => ennMatrixCoeff J x y)).mul - (measurable_fullLargeContact G hloc x y 0).ennreal_ofReal - rw [lintegral_tsum (fun y => (hm y).aemeasurable)] - simp_rw [lintegral_const_mul _ (measurable_fullLargeContact G hloc x _ 0).ennreal_ofReal, - contact_lintegral_eq_russoOperator G hloc hqt p hp D hD] - rw [ennMatrixCoeff_mul hJ hd,←ENNReal.tsum_mul_left] - apply tsum_congr - intro y - rw [hdi x y] - ac_rfl - simp_rw [he] - rw [ENNReal.ofReal_mul (sub_nonneg.mpr p.2.2),←enn_rootTrace root weight hw (J*D) (hJ.mul hd),Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - ac_rfl - -theorem mixedFunctional_toReal_eq_russoTrace [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (J D : Hilbert V →L[ℂ] Hilbert V) (hJ : PositiveRealMatrix J) (hiJ : KernelInvariant Γ J) - (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : - (clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff J) x y)).toReal = - (1-(p:ℝ))*(rootTrace root weight (J*D)).re := by - rw [mixedFunctional_eq_russoTrace G hconn hloc hqt root weight Γ hΓ htr hw p hp0 hp J D hJ hiJ hD] - apply ENNReal.toReal_ofReal - apply mul_nonneg (sub_nonneg.mpr p.2.2) - have hd := hJ.mul (russoOperator_positiveReal G p D hD) - simp only [rootTrace,Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] - exact Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (hd _ _).2) - -end MixedRussoTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory Filter -section RootTriangleRusso -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem rootTriangle_russo [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) - (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : - (1-(p:ℝ))*deriv (rootTriangle G root weight) (p:ℝ) = - 3*(clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)).toReal := by - obtain ⟨D,hD⟩ := exists_russoOperator G hloc hqt p hp0 hp - have hi : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) - rw [(hasDerivAt_rootTriangle_trace G hloc hqt root weight Γ hΓ htr p hp0 hp T D hT hD).deriv, - mixedFunctional_toReal_eq_russoTrace G hconn hloc hqt root weight Γ hΓ htr hw p hp0 hp - (T^2) D ((hT.positiveRealMatrix G p T).pow 2) (hi.pow 2) hD] - ring - -theorem realTriangle_one_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : 1 ≤ realTriangle G x (p:ℝ) := by - have hh := (summable_realTriangleTerm G hloc hqt p hp x).le_tsum (x,x) - (fun ab _ => by - simp only [realTriangleTerm,realTwoPoint_coe] - exact mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _)) - simpa only [realTriangleTerm,realTwoPoint_coe,twoPoint_self,mul_one,realTriangle] using hh - -theorem rootTriangle_one_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (p : unitInterval) (hp : p < pc G) : 1 ≤ rootTriangle G root weight (p:ℝ) := by - calc - 1 = ∑ i, weight i * 1 := by simpa using hw1.symm - _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left - (realTriangle_one_le G hloc hqt p hp (root i)) (hw i)) - -end RootTriangleRusso -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal -section RealMixedTrace -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem critical_mixed_trace_bound_real - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ A B : ℝ, 0 < A ∧ 0 < B ∧ ∀ (p : unitInterval), - (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → - ∀ L : ℝ, 1 ≤ L → - (clusterPairFunctional G p root weight (fun ω x y => - clusterPairKernel G ω (indexedEdgeKernel G) x y * - clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)).toReal ≤ - 2*(A*L^(1-α)*rootTriangle G root weight (p:ℝ)) + - (B*L^((1:ℝ)/2+ε-2*α))^((1:ℝ)/2) * - (‖T‖^3*rootTriangle G root weight (p:ℝ))^((1:ℝ)/2) := by - obtain ⟨A,B,hA,hB,hb⟩ := critical_mixed_trace_bound G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - refine ⟨A,B,hA,hB,?_⟩ - intro p hp hpq T hT L hL - have ht : 0 ≤ rootTriangle G root weight (p:ℝ) := (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq).trans' (by norm_num) - have ha : 0 ≤ A*L^(1-α)*rootTriangle G root weight (p:ℝ) := mul_nonneg (mul_nonneg hA.le (Real.rpow_nonneg (by linarith) _)) ht - have hc : 0 ≤ B*L^((1:ℝ)/2+ε-2*α) := mul_nonneg hB.le (Real.rpow_nonneg (by linarith) _) - have hn : 0 ≤ ‖T‖^3*rootTriangle G root weight (p:ℝ) := mul_nonneg (pow_nonneg (norm_nonneg _) _) ht - have hb' := hb p hp hpq.le T hT L hL - rw [←rootTriangle_eq_trace G p root weight T hT] at hb' - have htop : 2*ENNReal.ofReal (A*L^(1-α)*rootTriangle G root weight (p:ℝ)) + - (ENNReal.ofReal (B*L^((1:ℝ)/2+ε-2*α)))^((1:ℝ)/2) * - (ENNReal.ofReal (‖T‖^3*rootTriangle G root weight (p:ℝ)))^((1:ℝ)/2) ≠ ⊤ := by finiteness - have hh := ENNReal.toReal_mono htop hb' - rw [ENNReal.toReal_add (by finiteness) (by finiteness)] at hh - simpa only [ENNReal.toReal_mul, - ENNReal.toReal_ofNat,←ENNReal.toReal_rpow,ENNReal.toReal_ofReal ha, - ENNReal.toReal_ofReal hc,ENNReal.toReal_ofReal hn] using hh - -end RealMixedTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TraceNumerics -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem HasKernel.norm_le_susceptibility_bound [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (T : Hilbert V →L[ℂ] Hilbert V) - (hT : HasKernel G p T) (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, susceptibility G p x ≤ C) : - ‖T‖ ≤ C := by - have hr (x : V) (s : Finset V) : ∑ y ∈ s, twoPoint G p x y ≤ C := - ((summable_twoPoint_subcritical G hloc hqt p hp x).sum_le_tsum s - (fun y _ => twoPoint_nonneg G p x y)).trans (hb x) - obtain ⟨S,hS,hK⟩ := exists_operator_of_row_column_bound (twoPoint G p) C hC (twoPoint_nonneg G p) - hr (fun y s => by simpa only [twoPoint_symm G p] using hr y s) - rwa [hT.unique hK] - -lemma sqrt_mixed_power (B L m a r : ℝ) (hB : 0 ≤ B) (hL : 0 ≤ L) (hm : 0 ≤ m) (ha : 0 ≤ a) : - (B*L^r)^((1:ℝ)/2) * (m^3*a)^((1:ℝ)/2) = - Real.sqrt B * L^(r/2) * m^((3:ℝ)/2) * Real.sqrt a := by - rw [Real.mul_rpow hB (Real.rpow_nonneg hL _), Real.mul_rpow (pow_nonneg hm _) ha, - ←Real.rpow_mul hL,←Real.rpow_natCast m 3,←Real.rpow_mul hm, - ←Real.sqrt_eq_rpow,←Real.sqrt_eq_rpow] - rw [show r*(1/2:ℝ) = r/2 by ring] - norm_num only [Nat.cast_ofNat] - ring - -lemma sqrt_derivative_estimate (p q A B L m a a' F : ℝ) - (hp : p ≤ q) (hq : q < 1) (hA : 0 ≤ A) (hB : 0 ≤ B) - (hL : 1 ≤ L) (hm : 0 ≤ m) (ha : 1 ≤ a) - (α r : ℝ) (hid : (1-p)*a' = 3*F) - (hF : F ≤ 2*(A*L^(1-α)*a) + (B*L^r)^((1:ℝ)/2)*(m^3*a)^((1:ℝ)/2)) : - a'/(2*Real.sqrt a) ≤ - (3*(A+Real.sqrt B)/(1-q))*L^(1-α)*Real.sqrt a + - (3*(A+Real.sqrt B)/(1-q))*L^(r/2)*m^((3:ℝ)/2) := by - have ha0 : 0 < a := by linarith - have hs : 0 < Real.sqrt a := Real.sqrt_pos.mpr ha0 - have hp1 : 0 < 1-p := by linarith - have hq1 : 0 < 1-q := by linarith - have he := Real.sq_sqrt ha0.le - have hL0 : 0 ≤ L := by linarith - rw [sqrt_mixed_power B L m a r hB hL0 hm ha0.le] at hF - have hu : 0 ≤ L^(1-α) := Real.rpow_nonneg hL0 _ - have hv : 0 ≤ L^(r/2)*m^((3:ℝ)/2) := mul_nonneg (Real.rpow_nonneg hL0 _) (Real.rpow_nonneg hm _) - have hB0 := Real.sqrt_nonneg B - have hcoef : 3*A/(1-p) ≤ 3*(A+Real.sqrt B)/(1-q) := by - apply (div_le_div_iff₀ hp1 hq1).mpr - nlinarith - have hcoef2 : 3*Real.sqrt B/(2*(1-p)) ≤ 3*(A+Real.sqrt B)/(1-q) := by - apply (div_le_div_iff₀ (mul_pos (by norm_num) hp1) hq1).mpr - nlinarith - have hbase : a'/(2*Real.sqrt a) ≤ 3*A/(1-p)*L^(1-α)*Real.sqrt a + - (3*Real.sqrt B/(2*(1-p)))*(L^(r/2)*m^((3:ℝ)/2)) := by - apply (div_le_iff₀ (mul_pos (by norm_num) hs)).mpr - apply (mul_le_mul_iff_right₀ hp1).mp - have hex : (3*A/(1-p)*L^(1-α)*Real.sqrt a + - (3*Real.sqrt B/(2*(1-p)))*(L^(r/2)*m^((3:ℝ)/2))) * (2*Real.sqrt a) * (1-p) = - 3*(2*(A*L^(1-α)*a) + Real.sqrt B*L^(r/2)*m^((3:ℝ)/2)*Real.sqrt a) := by - field_simp - ring_nf - rw [he] - ring - rw [hid,mul_comm (1-p) _,hex] - linarith - exact hbase.trans (add_le_add - (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hcoef hu) hs.le) - (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hcoef2 hv)) - -end TraceNumerics -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section TraceSquareRoot -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def rootTriangleSqrt (G : BondGraph V E) {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := Real.sqrt (rootTriangle G root weight t) - -theorem hasDerivAt_rootTriangleSqrt [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : - HasDerivAt (rootTriangleSqrt G root weight) - (deriv (rootTriangle G root weight) (p:ℝ) / (2*rootTriangleSqrt G root weight (p:ℝ))) (p:ℝ) := by - apply (hasDerivAt_rootTriangle_subcritical G hloc hqt root weight p hp0 hp).differentiableAt.hasDerivAt.sqrt - have hh := rootTriangle_one_le G hloc hqt root weight hw hw1 p hp - linarith - - -theorem critical_rootTriangleSqrt_derivative - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) - (hr : (1:ℝ)/2+ε-2*α < 0) : - ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), - (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → - ∀ L : ℝ, 1 ≤ L → - deriv (rootTriangleSqrt G root weight) (p:ℝ) ≤ - C*L^(1-α)*rootTriangleSqrt G root weight (p:ℝ) + - C*L^(((1:ℝ)/2+ε-2*α)/2)*‖T‖^((3:ℝ)/2) := by - obtain ⟨A,B,hA,hB,hb⟩ := critical_mixed_trace_bound_real G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - refine ⟨3*(A+Real.sqrt B)/(1-(pc G:ℝ)),div_pos (mul_pos (by norm_num) - (add_pos_of_pos_of_nonneg hA (Real.sqrt_nonneg B))) (sub_pos.mpr hp₁),?_⟩ - intro p hp hpq T hT L hL - have hp0 : 0 < (p:ℝ) := lt_of_lt_of_le (half_pos hp₀) hp - rw [(hasDerivAt_rootTriangleSqrt G hloc hqt root weight (fun i => (hw i).le) hw1 p hp0 hpq).deriv] - exact sqrt_derivative_estimate p (pc G) A B L ‖T‖ (rootTriangle G root weight p) - (deriv (rootTriangle G root weight) p) _ hpq.le hp₁ hA.le hB.le hL (norm_nonneg _) - (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq) α _ - (rootTriangle_russo G hconn hloc hqt root weight Γ hΓ htr (fun i => (hw i).le) p hp0 hpq T hT) - (hb p hp hpq T hT L hL) - -end TraceSquareRoot -end Percolation - - -namespace Percolation -section TraceExponents - -lemma trace_exponent_choices (η : ℝ) (hη : 0 < η) : - ∃ α ε ρ lambda : ℝ, 0 < α ∧ α < 1/2 ∧ 0 < ε ∧ 0 < ρ ∧ 0 < lambda ∧ - (1:ℝ)/2+ε-2*α < 0 ∧ lambda*(1-α) < 1 ∧ - lambda*(((1:ℝ)/2+ε-2*α)/2) + (3:ℝ)/2*(1+ρ) < 1+η/2 := by - let ζ := min (1/2:ℝ) η - let d := min (ζ/16) (η/32) - have hz : 0 < ζ := lt_min (by norm_num) hη - have hz1 : ζ ≤ 1/2 := min_le_left _ _ - have hze : ζ ≤ η := min_le_right _ _ - have hd : 0 < d := lt_min (div_pos hz (by norm_num)) (div_pos hη (by norm_num)) - have hdz : d ≤ ζ/16 := min_le_left _ _ - have hde : d ≤ η/32 := min_le_right _ _ - have hzd : 0 ≤ ζ*d := mul_nonneg hz.le hd.le - refine ⟨1/2-d,d,d,2-ζ,?_,?_,hd,hd,?_,?_,?_,?_⟩ <;> nlinarith - -lemma trace_scale_large_term (δ D lambda r ρ : ℝ) (hδ : 0 < δ) (hD : 0 ≤ D) : - (δ^(-lambda))^(r/2)*(D*δ^(-1-ρ))^((3:ℝ)/2) = - D^((3:ℝ)/2)*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by - rw [Real.mul_rpow hD (Real.rpow_nonneg hδ.le _),←Real.rpow_mul hδ.le,←Real.rpow_mul hδ.le] - rw [show δ^(-lambda*(r/2))*(D^((3:ℝ)/2)*δ^((-1-ρ)*((3:ℝ)/2))) = - D^((3:ℝ)/2)*(δ^(-lambda*(r/2))*δ^((-1-ρ)*((3:ℝ)/2))) by ring, - ←Real.rpow_add hδ] - congr 2 - ring - -lemma trace_scale_derivative (δ D C lambda r ρ α b b' m : ℝ) - (hδ : 0 < δ) (hD : 0 ≤ D) (hC : 0 ≤ C) - (hb : 0 ≤ b) (hm : 0 ≤ m) (hmD : m ≤ D*δ^(-1-ρ)) - (hd : b' ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*m^((3:ℝ)/2)) : - b' ≤ (C*(1+D^((3:ℝ)/2)))*δ^(-(lambda*(1-α)))*b + - (C*(1+D^((3:ℝ)/2)))*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by - have hs := Real.rpow_le_rpow hm hmD (by norm_num : (0:ℝ) ≤ 3/2) - have he : (δ^(-lambda))^(1-α) = δ^(-(lambda*(1-α))) := by rw [←Real.rpow_mul hδ.le]; congr 1; ring - have hc1 : C ≤ C*(1+D^((3:ℝ)/2)) := by nlinarith [Real.rpow_nonneg hD ((3:ℝ)/2)] - have hc2 : C*D^((3:ℝ)/2) ≤ C*(1+D^((3:ℝ)/2)) := by nlinarith - calc - b' ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*m^((3:ℝ)/2) := hd - _ ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*(D*δ^(-1-ρ))^((3:ℝ)/2) := - add_le_add le_rfl (mul_le_mul_of_nonneg_left hs (mul_nonneg hC (Real.rpow_nonneg (Real.rpow_nonneg hδ.le _) _))) - _ = C*δ^(-(lambda*(1-α)))*b + (C*D^((3:ℝ)/2))*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by - rw [he,mul_assoc C ((δ^(-lambda))^(r/2)),trace_scale_large_term δ D lambda r ρ hδ hD]; ring - _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right - (mul_le_mul_of_nonneg_right hc1 (Real.rpow_nonneg hδ.le _)) hb) - (mul_le_mul_of_nonneg_right hc2 (Real.rpow_nonneg hδ.le _)) - -end TraceExponents -end Percolation - - -namespace Percolation -section IntegratingFactor - -lemma hasDerivAt_gap_rpow (q r t : ℝ) (ht : t < q) : - HasDerivAt (fun x : ℝ => (q-x)^r) (-r*(q-t)^(r-1)) t := by - convert! ((hasDerivAt_const t q).sub (hasDerivAt_id t)).rpow_const - (Or.inl (ne_of_gt (sub_pos.mpr ht))) using 1 - simp only [Pi.sub_apply, id_eq] - ring - -noncomputable def traceIntegratingFactor (q C A t : ℝ) : ℝ := - Real.exp (C/(1-A)*(q-t)^(1-A)) - -lemma hasDerivAt_traceIntegratingFactor (q C A t : ℝ) (hA : A < 1) (ht : t < q) : - HasDerivAt (traceIntegratingFactor q C A) - (-C*(q-t)^(-A)*traceIntegratingFactor q C A t) t := by - have hd := ((hasDerivAt_gap_rpow q (1-A) t ht).const_mul (C/(1-A))).exp - convert! hd using 1 - unfold traceIntegratingFactor - rw [show 1-A-1 = -A by ring] - field_simp [ne_of_gt (sub_pos.mpr hA)] - -lemma traceIntegratingFactor_bounds (q C A t : ℝ) (hC : 0 ≤ C) (hA : A < 1) - (ht : t < q) (hd : q-t ≤ 1) : - 1 ≤ traceIntegratingFactor q C A t ∧ - traceIntegratingFactor q C A t ≤ Real.exp (C/(1-A)) := by - have hk : 0 ≤ C/(1-A) := div_nonneg hC (sub_pos.mpr hA).le - have hr : 0 ≤ (q-t)^(1-A) := Real.rpow_nonneg (sub_pos.mpr ht).le _ - constructor - · exact Real.one_le_exp (mul_nonneg hk hr) - · apply Real.exp_le_exp.mpr - exact mul_le_of_le_one_right hk (Real.rpow_le_one (sub_pos.mpr ht).le hd (sub_pos.mpr hA).le) - -lemma hasDerivAt_traceComparison (f : ℝ → ℝ) (q C A κ t : ℝ) - (hA : A < 1) (hκ : 0 < κ) (ht : t < q) (hf : DifferentiableAt ℝ f t) : - HasDerivAt (fun x => traceIntegratingFactor q C A x*f x - - (C*Real.exp (C/(1-A))/κ)*(q-x)^(-κ)) - (traceIntegratingFactor q C A t*(deriv f t-C*(q-t)^(-A)*f t) - - C*Real.exp (C/(1-A))*(q-t)^(-κ-1)) t := by - have hh := ((hasDerivAt_traceIntegratingFactor q C A t hA ht).mul hf.hasDerivAt).sub - ((hasDerivAt_gap_rpow q (-κ) t ht).const_mul (C*Real.exp (C/(1-A))/κ)) - convert! hh using 1 - field_simp [ne_of_gt hκ] - ring - - - -theorem singular_ode_subpower (f : ℝ → ℝ) (q s C A B κ : ℝ) - (hs : s < q) (hqs : q-s ≤ 1) (hC : 0 < C) (hA : A < 1) - (hκ : 0 < κ) (hB : B ≤ 1+κ) - (hf : ∀ t ∈ Set.Ico s q, DifferentiableAt ℝ f t) - (hn : ∀ t ∈ Set.Ico s q, 0 ≤ f t) - (hd : ∀ t ∈ Set.Ico s q, - deriv f t ≤ C*(q-t)^(-A)*f t + C*(q-t)^(-B)) : - ∃ K : ℝ, 0 < K ∧ ∀ t ∈ Set.Ico s q, f t ≤ K*(q-t)^(-κ) := by - let M := Real.exp (C/(1-A)) - let Q := C*M/κ - let g := fun t => traceIntegratingFactor q C A t*f t - Q*(q-t)^(-κ) - have hM : 0 < M := Real.exp_pos _ - have hQ : 0 < Q := div_pos (mul_pos hC hM) hκ - have hgs (t : ℝ) (ht : t ∈ Set.Ico s q) : - HasDerivAt g (traceIntegratingFactor q C A t*(deriv f t-C*(q-t)^(-A)*f t) - - C*M*(q-t)^(-κ-1)) t := hasDerivAt_traceComparison f q C A κ t hA hκ ht.2 (hf t ht) - have hgn (t : ℝ) (ht : t ∈ Set.Ico s q) : deriv g t ≤ 0 := by - have htq : 0 < q-t := sub_pos.mpr ht.2 - have ht1 : q-t ≤ 1 := by linarith [ht.1] - obtain ⟨hw,hwM⟩ := traceIntegratingFactor_bounds q C A t hC.le hA ht.2 ht1 - have hpow : (q-t)^(-B) ≤ (q-t)^(-κ-1) := - Real.rpow_le_rpow_of_exponent_ge htq ht1 (by linarith) - have hmul := mul_le_mul_of_nonneg_left (hd t ht) (show 0 ≤ traceIntegratingFactor q C A t by linarith) - have h₂ := mul_le_mul_of_nonneg_right hwM (mul_nonneg hC.le (Real.rpow_nonneg htq.le (-B))) - have h₃ := mul_le_mul_of_nonneg_left hpow (mul_nonneg hC.le hM.le) - rw [(hgs t ht).deriv] - dsimp only [M] at hM ⊢ - dsimp only [M] at h₃ - nlinarith - have hgmono : AntitoneOn g (Set.Ico s q) := by - apply antitoneOn_of_deriv_nonpos (convex_Ico s q) - · intro t ht - exact (hgs t ht).continuousAt.continuousWithinAt - · intro t ht - exact (hgs t (interior_subset ht)).differentiableAt.differentiableWithinAt - · intro t ht - exact hgn t (interior_subset ht) - have hsI : s ∈ Set.Ico s q := ⟨le_rfl,hs⟩ - refine ⟨M*f s+Q,add_pos_of_nonneg_of_pos (mul_nonneg hM.le (hn s hsI)) hQ,?_⟩ - intro t ht - have htq : 0 < q-t := sub_pos.mpr ht.2 - have ht1 : q-t ≤ 1 := by linarith [ht.1] - obtain ⟨hwt,_⟩ := traceIntegratingFactor_bounds q C A t hC.le hA ht.2 ht1 - obtain ⟨_,hws⟩ := traceIntegratingFactor_bounds q C A s hC.le hA hs hqs - have hmono := hgmono hsI ht ht.1 - have hneg : 0 ≤ Q*(q-s)^(-κ) := mul_nonneg hQ.le (Real.rpow_nonneg (sub_pos.mpr hs).le _) - have hft := mul_le_mul_of_nonneg_right hwt (hn t ht) - have hfs := mul_le_mul_of_nonneg_right hws (hn s hsI) - have hpow : 1 ≤ (q-t)^(-κ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos htq ht1 (neg_nonpos.mpr hκ.le) - have hscale := mul_le_mul_of_nonneg_left hpow (mul_nonneg hM.le (hn s hsI)) - dsimp only [g] at hmono - dsimp only [M] at hscale ⊢ - nlinarith - -end IntegratingFactor -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SubpowerTrace -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem critical_rootTriangle_subpower - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (η : ℝ) (hη : 0 < η) : - ∃ K : ℝ, 0 < K ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - rootTriangle G root weight (p:ℝ) ≤ K*((pc G:ℝ)-(p:ℝ))^(-η) := by - obtain ⟨α,ε,ρ,lambda,hα,hα1,hε,hρ,hlambda,hr,hA,hB⟩ := trace_exponent_choices η hη - obtain ⟨C₀,hC₀,hder⟩ := critical_rootTriangleSqrt_derivative G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr - obtain ⟨D,hD,hχ⟩ := almost_linear_susceptibility G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin ρ hρ - let C := C₀*(1+D^((3:ℝ)/2)) - let A := lambda*(1-α) - let B := lambda*(((1:ℝ)/2+ε-2*α)/2)+(3:ℝ)/2*(1+ρ) - have hC : 0 < C := mul_pos hC₀ (by linarith [Real.rpow_nonneg hD.le ((3:ℝ)/2)]) - have hunit (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : t ∈ unitInterval := - ⟨(half_pos hp₀).le.trans ht.1,ht.2.le.trans (pc G).2.2⟩ - have hdf (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : - DifferentiableAt ℝ (rootTriangleSqrt G root weight) t := by - exact (hasDerivAt_rootTriangleSqrt G hloc hqt root weight (fun i => (hw i).le) hw1 - ⟨t,hunit t ht⟩ ((half_pos hp₀).trans_le ht.1) ht.2).differentiableAt - have hod (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : - deriv (rootTriangleSqrt G root weight) t ≤ C*((pc G:ℝ)-t)^(-A)*rootTriangleSqrt G root weight t + - C*((pc G:ℝ)-t)^(-B) := by - let p : unitInterval := ⟨t,hunit t ht⟩ - have hδ : 0 < (pc G:ℝ)-t := sub_pos.mpr ht.2 - have hδ1 : (pc G:ℝ)-t ≤ 1 := by linarith [(pc G).2.2,ht.1] - obtain ⟨T,hT⟩ := operatorBounded_of_lt_pc G hloc hqt p ht.2 - have hm := hT.norm_le_susceptibility_bound G hloc hqt p ht.2 T (D*((pc G:ℝ)-t)^(-1-ρ)) - (mul_nonneg hD.le (Real.rpow_nonneg hδ.le _)) (hχ p ht.2) - have hL : 1 ≤ (((pc G:ℝ)-t)^(-lambda)) := - Real.one_le_rpow_of_pos_of_le_one_of_nonpos hδ hδ1 (neg_nonpos.mpr hlambda.le) - exact trace_scale_derivative ((pc G:ℝ)-t) D C₀ lambda ((1:ℝ)/2+ε-2*α) ρ α - (rootTriangleSqrt G root weight t) (deriv (rootTriangleSqrt G root weight) t) ‖T‖ - hδ hD.le hC₀.le (Real.sqrt_nonneg _) (norm_nonneg _) hm - (hder p ht.1 ht.2 T hT (((pc G:ℝ)-t)^(-lambda)) hL) - obtain ⟨K,hK,hb⟩ := singular_ode_subpower (rootTriangleSqrt G root weight) (pc G) ((pc G:ℝ)/2) - C A B (η/2) (by linarith) (by linarith [(pc G).2.2]) hC hA (half_pos hη) hB.le - hdf (fun _ _ => Real.sqrt_nonneg _) hod - refine ⟨K^2,sq_pos_of_pos hK,?_⟩ - intro p hp hpq - have ha : 0 ≤ rootTriangle G root weight (p:ℝ) := - le_trans (by norm_num) (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq) - have hb' := pow_le_pow_left₀ (Real.sqrt_nonneg (rootTriangle G root weight (p:ℝ))) (hb p ⟨hp,hpq⟩) 2 - change (Real.sqrt (rootTriangle G root weight (p:ℝ)))^2 ≤ _ at hb' - rw [Real.sq_sqrt ha,mul_pow] at hb' - have he : (((pc G:ℝ)-(p:ℝ))^(-(η/2)))^2 = ((pc G:ℝ)-(p:ℝ))^(-η) := by - rw [←Real.rpow_natCast _ 2,←Real.rpow_mul (sub_pos.mpr (show (p:ℝ)<(pc G:ℝ) from hpq)).le] - congr 1 - norm_num - rw [he] at hb' - exact hb' - -end SubpowerTrace -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section QuantitativeSprinkling -attribute [local instance] Classical.propDecidable Classical.decEq - -lemma riccati_step (a M n x : ℝ) (ha : 0 ≤ a) (hM : 0 ≤ M) (_hn : 0 ≤ n) - (_hx : 0 ≤ x) (hb : x ≤ M/(1-a*n*M)) (hh : a*(n+1)*M < 1) : - a*x < 1 ∧ x/(1-a*x) ≤ M/(1-a*(n+1)*M) := by - have haM : 0 ≤ a*M := mul_nonneg ha hM - have hp : 0 < 1-a*n*M := by nlinarith - have hb' := (le_div_iff₀ hp).mp hb - have hs : a*(M/(1-a*n*M)) < 1 := by - rw [←mul_div_assoc,div_lt_one hp] - nlinarith - have hax : a*x < 1 := (mul_le_mul_of_nonneg_left hb ha).trans_lt hs - refine ⟨hax,?_⟩ - apply (div_le_div_iff₀ (sub_pos.mpr hax) (sub_pos.mpr hh)).mpr - nlinarith - - - -theorem sprinkling_iterated_bound [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (m D : ℕ) - (hD : ∀ x, degree G x ≤ D) (A : Hilbert V →L[ℂ] Hilbert V) - (hA : HasKernel G (orParameter q m) A) (n : ℕ) - (hn : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1) : - ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+n)) B ∧ - ‖B‖ ≤ ‖A‖/(1-(q:ℝ)*(2*D)*(n:ℝ)*‖A‖) := by - induction n with - | zero => exact ⟨A,by simpa using hA,by simp⟩ - | succ n ih => - have ha : 0 ≤ (q:ℝ)*(2*D) := mul_nonneg q.2.1 (by positivity) - have hnext : (q:ℝ)*(2*D)*((n:ℝ)+1)*‖A‖ < 1 := by simpa using hn - have hprev : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1 := by - nlinarith [mul_nonneg ha (norm_nonneg A)] - obtain ⟨B,hB,hBn⟩ := ih hprev - obtain ⟨hs,hbound⟩ := riccati_step ((q:ℝ)*(2*D)) ‖A‖ n ‖B‖ ha (norm_nonneg _) (Nat.cast_nonneg _) (norm_nonneg _) hBn hnext - obtain ⟨C,hC,hCn⟩ := sprinkling_bound G hloc q (m+n) D hD B hB hs - exact ⟨C,by simpa [Nat.add_assoc] using hC,by simpa using hCn.trans hbound⟩ - -lemma closed_power_bound (q : unitInterval) (n : ℕ) : - (1-(q:ℝ))^n * (1+(n:ℝ)*(q:ℝ)) ≤ 1 := by - induction n with - | zero => simp - | succ n ih => - have hp : 0 ≤ (1-(q:ℝ))^n := pow_nonneg (sub_nonneg.mpr q.2.2) _ - have hn : 0 ≤ (n:ℝ)*(q:ℝ)^2 := mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _) - rw [pow_succ,Nat.cast_add,Nat.cast_one] - nlinarith [mul_nonneg hp hn,mul_nonneg hp (sq_nonneg (q:ℝ))] - -lemma orParameter_gap_bound (p q : unitInterval) (m n : ℕ) (hm : orParameter q m = p) : - (1+(n:ℝ)*(q:ℝ))*(1-(orParameter q (m+n):ℝ)) ≤ 1-(p:ℝ) := by - have hh := mul_le_mul_of_nonneg_left (closed_power_bound q n) (sub_nonneg.mpr p.2.2) - have he : 1-(p:ℝ) = (1-(q:ℝ))^m := by rw [←hm]; simp [orParameter] - rw [he] at hh ⊢ - change (1+(n:ℝ)*(q:ℝ))*(1-(1-(1-(q:ℝ))^(m+n))) ≤ _ - rw [sub_sub_cancel,pow_add] - nlinarith - -end QuantitativeSprinkling -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section QuantitativeOpenness -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem operatorBounded_of_quantitative_gap [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) - (hD : ∀ x, degree G x ≤ D) (p r : unitInterval) - (hp : 0 < p) (hpr : p < r) (hr : r < 1) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) - (hsmall : ((r:ℝ)-(p:ℝ))*(4*D)*‖A‖ < 1-(r:ℝ)) : OperatorBounded G r := by - let a := ((r:ℝ)-(p:ℝ))/(1-(r:ℝ)) - have hden : 0 < 1-(r:ℝ) := sub_pos.mpr hr - have ha : 0 < a := div_pos (sub_pos.mpr hpr) hden - obtain ⟨m,q,hq,hqp⟩ := exists_orParameter_small p (hpr.trans hr) (min a 1) - (lt_min ha zero_lt_one) (min_le_right _ _) - have hq0 : (0:ℝ) < q := by - by_contra hn - have hqe : q = 0 := Subtype.ext ((le_of_not_gt hn).antisymm q.2.1) - have hpe : p = 0 := by rw [←hqp,hqe]; apply Subtype.ext; simp [orParameter] - exact (ne_of_gt hp) hpe - let n := ⌈a/(q:ℝ)⌉₊ - have hna : a ≤ (n:ℝ)*(q:ℝ) := (div_le_iff₀ hq0).mp (Nat.le_ceil _) - have han : (n:ℝ)*(q:ℝ) < a+(q:ℝ) := by - have hn := Nat.ceil_lt_add_one (div_nonneg ha.le hq0.le) - have hh := mul_lt_mul_of_pos_right hn hq0 - dsimp only [n] at * - field_simp at hh - nlinarith - have hn2 : (n:ℝ)*(q:ℝ) < 2*a := by linarith [hq.trans (min_le_left _ _)] - have hbase : (2*a)*(2*D)*‖A‖ < 1 := by - rw [show (2*a)*(2*D)*‖A‖ = (((r:ℝ)-(p:ℝ))*(4*D)*‖A‖)/(1-(r:ℝ)) by dsimp [a]; ring] - exact (div_lt_one hden).mpr hsmall - have hnsmall : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1 := by - have hs := mul_le_mul_of_nonneg_right hn2.le (show 0 ≤ (2*(D:ℝ))*‖A‖ by positivity) - nlinarith - obtain ⟨B,hB,_⟩ := sprinkling_iterated_bound G hloc q m D hD A (hqp ▸ hA) n hnsmall - apply operatorBounded_of_le G (q := orParameter q (m+n)) ?_ ⟨B,hB⟩ - have hgap := orParameter_gap_bound p q m n hqp - have hae : a*(1-(r:ℝ)) = (r:ℝ)-(p:ℝ) := div_mul_cancel₀ _ (ne_of_gt hden) - have hs := mul_le_mul_of_nonneg_right hna hden.le - change (r:ℝ) ≤ (orParameter q (m+n):ℝ) - nlinarith [mul_nonneg (Nat.cast_nonneg n) q.2.1] - - - -theorem norm_gap_lower_of_endpoint_unbounded [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) - (hD : ∀ x, degree G x ≤ D) (p r : unitInterval) - (hp : 0 < p) (hpr : p < r) (hr : r < 1) - (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) - (hu : ¬OperatorBounded G r) : - 1-(r:ℝ) ≤ ((r:ℝ)-(p:ℝ))*(4*D)*‖A‖ := by - by_contra h - exact hu (operatorBounded_of_quantitative_gap G hloc D hD p r hp hpr hr A hA (lt_of_not_ge h)) - -end QuantitativeOpenness -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NormRatio -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def maxSusceptibility (G : BondGraph V E) (p : unitInterval) : ℝ := - sSup (Set.range (susceptibility G p)) - -theorem susceptibility_bddAbove [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : BddAbove (Set.range (susceptibility G p)) := by - obtain ⟨C,_,hC⟩ := subcritical_row_bound G hloc hqt p hp - refine ⟨C,?_⟩ - rintro _ ⟨x,rfl⟩ - exact (summable_twoPoint_subcritical G hloc hqt p hp x).tsum_le_of_sum_le (hC x) - -theorem susceptibility_le_max [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (x : V) : - susceptibility G p x ≤ maxSusceptibility G p := - le_csSup (susceptibility_bddAbove G hloc hqt p hp) (Set.mem_range_self x) - -theorem maxSusceptibility_le [Nonempty V] (G : BondGraph V E) (p : unitInterval) - (C : ℝ) (hC : ∀ x, susceptibility G p x ≤ C) : maxSusceptibility G p ≤ C := by - apply csSup_le (Set.range_nonempty _) - rintro _ ⟨x,rfl⟩ - exact hC x - -theorem maxSusceptibility_one_le [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) : 1 ≤ maxSusceptibility G p := by - let x : V := Classical.choice inferInstance - exact (susceptibility_one_le G hloc hqt p hp x).trans (susceptibility_le_max G hloc hqt p hp x) - -theorem HasKernel.norm_le_maxSusceptibility [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (p : unitInterval) (hp : p < pc G) (T : Hilbert V →L[ℂ] Hilbert V) - (hT : HasKernel G p T) : ‖T‖ ≤ maxSusceptibility G p := - hT.norm_le_susceptibility_bound G hloc hqt p hp T _ - (le_trans zero_le_one (maxSusceptibility_one_le G hloc hqt p hp)) - (susceptibility_le_max G hloc hqt p hp) - -theorem HasKernel.norm_one_le [Countable E] [Nonempty V] - (G : BondGraph V E) (p : unitInterval) (T : Hilbert V →L[ℂ] Hilbert V) - (hT : HasKernel G p T) : 1 ≤ ‖T‖ := by - let x : V := Classical.choice inferInstance - have hd : twoPoint G p x x = 1 := twoPoint_self G p x - have hh := (lp.norm_apply_le_norm (by norm_num : (2:ENNReal) ≠ 0) (T (lp.single 2 x (1:ℂ))) x).trans (T.le_opNorm (lp.single 2 x (1:ℂ))) - simpa [hT x x,hd,lp.norm_single] using hh - -end NormRatio -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SourceNormRatio -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem critical_norm_inverse_lower [Countable V] [Countable E] [Nonempty V] - (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hp₁ : (pc G:ℝ) < 1) (hu : ¬OperatorBounded G (pc G)) : - ∃ c : ℝ, 0 < c ∧ ∀ (p : unitInterval), 0 < p → p < pc G → - ∀ T : Hilbert V →L[ℂ] Hilbert V, HasKernel G p T → - c/((pc G:ℝ)-(p:ℝ)) ≤ ‖T‖ := by - obtain ⟨D,hDp,hD⟩ := exists_degree_bound G hqt - have hDpos : 0 < (4*(D:ℝ)) := by positivity - refine ⟨(1-(pc G:ℝ))/(4*D),div_pos (sub_pos.mpr hp₁) hDpos,?_⟩ - intro p hp hpq T hT - have hh := norm_gap_lower_of_endpoint_unbounded G hloc D hD p (pc G) hp hpq hp₁ T hT hu - apply (div_le_iff₀ (sub_pos.mpr (show (p:ℝ)<(pc G:ℝ) from hpq))).mpr - apply (div_le_iff₀ hDpos).mpr - nlinarith - - - -theorem critical_normRatio_subpower - [Countable V] [Countable E] [Nonempty V] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) - {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) - (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) - (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) - (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) - (hu : ¬OperatorBounded G (pc G)) (η : ℝ) (hη : 0 < η) : - ∃ K : ℝ, 0 < K ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → - ∀ T : Hilbert V →L[ℂ] Hilbert V, HasKernel G p T → - 1 ≤ maxSusceptibility G p/‖T‖ ∧ - maxSusceptibility G p/‖T‖ ≤ K*((pc G:ℝ)-(p:ℝ))^(-η) := by - obtain ⟨c,hc,hm⟩ := critical_norm_inverse_lower G hloc hqt hp₁ hu - obtain ⟨D,hD,hχ⟩ := almost_linear_susceptibility G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin η hη - refine ⟨D/c,div_pos hD hc,?_⟩ - intro p hp hpq T hT - have hδ : 0 < (pc G:ℝ)-(p:ℝ) := sub_pos.mpr hpq - have hnorm : 0 < ‖T‖ := zero_lt_one.trans_le (hT.norm_one_le G p T) - have hM := hm p ((half_pos hp₀).trans_le hp) hpq T hT - have hχb := maxSusceptibility_le G p _ (hχ p hpq) - have he : ((pc G:ℝ)-(p:ℝ))^(-1-η)*((pc G:ℝ)-(p:ℝ)) = ((pc G:ℝ)-(p:ℝ))^(-η) := by - calc - _ = ((pc G:ℝ)-(p:ℝ))^(-1-η)*((pc G:ℝ)-(p:ℝ))^(1:ℝ) := by rw [Real.rpow_one] - _ = _ := by rw [←Real.rpow_add hδ]; congr 1; ring - refine ⟨(one_le_div hnorm).mpr (hT.norm_le_maxSusceptibility G hloc hqt p hpq T),?_⟩ - calc - maxSusceptibility G p/‖T‖ ≤ (D*((pc G:ℝ)-(p:ℝ))^(-1-η))/(c/((pc G:ℝ)-(p:ℝ))) := - div_le_div₀ (mul_nonneg hD.le (Real.rpow_nonneg hδ.le _)) hχb (div_pos hc hδ) hM - _ = (D/c)*((pc G:ℝ)-(p:ℝ))^(-η) := by rw [←he]; field_simp - -end SourceNormRatio -end Percolation - - -namespace Percolation -universe u -section ChronologicalErasure -open List -variable {V : Type u} -attribute [local instance] Classical.propDecidable Classical.decEq - - - -inductive HoldingWalk (H : SimpleGraph V) : ℕ → V → V → Type u - | nil (x : V) : HoldingWalk H 0 x x - | hold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : HoldingWalk H (k+1) x y - | step {k : ℕ} {x z y : V} (h : H.Adj x z) (w : HoldingWalk H k z y) : - HoldingWalk H (k+1) x y - -namespace HoldingWalk -variable {H : SimpleGraph V} {k : ℕ} {x y : V} - -def withoutHolds : {k : ℕ} → {x y : V} → HoldingWalk H k x y → H.Walk x y - | _,_,_,.nil _ => .nil - | _,_,_,.hold w => w.withoutHolds - | _,_,_,.step h w => .cons h w.withoutHolds - -def vertices : {k : ℕ} → {x y : V} → HoldingWalk H k x y → List V - | _,x,_,.nil _ => [x] - | _,x,_,.hold w => x :: w.vertices - | _,x,_,.step _ w => x :: w.vertices - -noncomputable def mass (P : V → V → ℝ) : {k : ℕ} → {x y : V} → HoldingWalk H k x y → ℝ - | _,_,_,.nil _ => 1 - | _,x,_,.hold w => P x x * w.mass P - | _,x,_,.step (z := z) _ w => P x z * w.mass P - -theorem mass_nonneg (P : V → V → ℝ) (hP : ∀ a b, 0 ≤ P a b) (w : HoldingWalk H k x y) : - 0 ≤ w.mass P := by - induction w with - | nil => exact zero_le_one - | hold w ih => exact mul_nonneg (hP _ _) ih - | step h w ih => exact mul_nonneg (hP _ _) ih - -theorem length_vertices (w : HoldingWalk H k x y) : w.vertices.length = k+1 := by - induction w with - | nil => rfl - | hold w ih => simpa only [vertices,List.length_cons] using congrArg (fun n => n+1) ih - | step h w ih => simpa only [vertices,List.length_cons] using congrArg (fun n => n+1) ih - -theorem withoutHolds_length (w : HoldingWalk H k x y) : w.withoutHolds.length ≤ k := by - induction w with - | nil => simp [withoutHolds] - | hold w ih => exact ih.trans (Nat.le_succ _) - | step h w ih => simpa only [withoutHolds,SimpleGraph.Walk.length_cons] using Nat.succ_le_succ ih - -theorem withoutHolds_support (w : HoldingWalk H k x y) : w.withoutHolds.support <+ w.vertices := by - induction w with - | nil => exact List.Sublist.refl _ - | hold w ih => exact ih.cons _ - | step h w ih => exact ih.cons_cons _ - - - -noncomputable def erase (w : HoldingWalk H k x y) : H.Walk x y := - w.withoutHolds.reverse.bypass.reverse - -theorem erase_isPath (w : HoldingWalk H k x y) : w.erase.IsPath := - w.withoutHolds.reverse.bypass_isPath.reverse - -theorem erase_length (w : HoldingWalk H k x y) : w.erase.length ≤ k := by - have hh := w.withoutHolds.reverse.length_bypass_le_length - simpa only [erase,SimpleGraph.Walk.length_reverse] using hh.trans (by simpa using w.withoutHolds_length) - -theorem erase_support (w : HoldingWalk H k x y) : w.erase.support <+ w.vertices := by - have hh := w.withoutHolds.reverse.support_bypass_sublist_support.reverse - simp only [SimpleGraph.Walk.support_reverse,List.reverse_reverse] at hh - simpa only [erase,SimpleGraph.Walk.support_reverse] using hh.trans w.withoutHolds_support - -theorem erase_edges (w : HoldingWalk H k x y) : w.erase.edges <+ w.withoutHolds.edges := by - have hh := w.withoutHolds.reverse.edges_bypass_sublist_edges.reverse - simpa only [erase,SimpleGraph.Walk.edges_reverse,List.reverse_reverse] using hh - -end HoldingWalk -end ChronologicalErasure -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CorridorMonotonicity -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def corridorCounted (G : BondGraph V E) (retained blockers : Set E) - (D : Set V) (ω : Set E) (x y : V) : Prop := - Conn G (ω ∩ internalEdges G D) x y ∧ - (∀ e ∈ retained, e ∈ ω ∩ internalEdges G D ∧ - ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y) ∧ - Disjoint blockers (ω ∩ internalEdges G D) - -lemma pivotal_restrict_of_conn (G : BondGraph V E) {S T : Set E} (hST : S ⊆ T) - {x y : V} (hc : Conn G S x y) (e : E) (hp : ¬Conn G (T \ {e}) x y) : - e ∈ S ∧ ¬Conn G (S \ {e}) x y := by - constructor - · by_contra he - apply hp - apply conn_mono G ?_ hc - intro d hd - exact ⟨hST hd,fun hde => he ((Set.mem_singleton_iff.mp hde) ▸ hd)⟩ - · intro h - exact hp (conn_mono G (Set.sdiff_subset_sdiff_left hST) h) - - - -theorem corridorCounted_restrict (G : BondGraph V E) (retained blockers : Set E) - {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') (x y : V) - (hc : Conn G (ω ∩ internalEdges G D) x y) - (ht : corridorCounted G retained blockers D' ω' x y) : - corridorCounted G retained blockers D ω x y := by - have hs : ω ∩ internalEdges G D ⊆ ω' ∩ internalEdges G D' := - Set.inter_subset_inter hω (internalEdges_mono G hD) - refine ⟨hc,fun e he => pivotal_restrict_of_conn G hs hc e (ht.2.1 e he).2,?_⟩ - exact ht.2.2.mono_right hs - -lemma corridorCounted_symm (G : BondGraph V E) (retained blockers : Set E) - (D : Set V) (ω : Set E) (x y : V) : - corridorCounted G retained blockers D ω x y ↔ corridorCounted G retained blockers D ω y x := by - constructor <;> rintro ⟨hc,hp,hb⟩ - · exact ⟨conn_symm G _ hc,fun e he => ⟨(hp e he).1,fun hc => (hp e he).2 (conn_symm G _ hc)⟩,hb⟩ - · exact ⟨conn_symm G _ hc,fun e he => ⟨(hp e he).1,fun hc => (hp e he).2 (conn_symm G _ hc)⟩,hb⟩ - - - -theorem measurableSet_corridorCounted [Countable E] (G : BondGraph V E) - (retained blockers : Set E) (D : Set V) (x y : V) : - MeasurableSet {ω | corridorCounted G retained blockers D ω x y} := by - have hmem (e : E) : MeasurableSet {ω : Set E | e ∈ ω ∩ internalEdges G D} := by - by_cases he : e ∈ internalEdges G D - · simpa only [Set.mem_inter_iff,he,and_true] using measurableSet_mem e - · simp only [Set.mem_inter_iff,he,and_false,Set.ofPred_false]; exact MeasurableSet.empty - have hp (e : E) : MeasurableSet {ω : Set E | e ∈ ω ∩ internalEdges G D ∧ - ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y} := by - apply (hmem e).inter - have heq (ω : Set E) : (ω ∩ internalEdges G D) \ {e} = ω ∩ (internalEdges G D \ {e}) := by - ext d; simp only [Set.mem_inter_iff,Set.mem_sdiff]; tauto - simp_rw [heq] - exact (measurableSet_restrictedConn G _ x y).compl - have hb : MeasurableSet {ω : Set E | Disjoint blockers (ω ∩ internalEdges G D)} := by - simp only [Set.disjoint_left,Set.ofPred_forall] - exact MeasurableSet.iInter (fun e => MeasurableSet.iInter (fun (_ : e ∈ blockers) => (hmem e).compl)) - have hkeep : MeasurableSet {ω : Set E | ∀ e ∈ retained, e ∈ ω ∩ internalEdges G D ∧ - ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y} := by - simp only [Set.ofPred_forall] - exact MeasurableSet.iInter (fun e => MeasurableSet.iInter (fun (_ : e ∈ retained) => hp e)) - exact (measurableSet_restrictedConn G _ x y).inter (hkeep.inter hb) - -end CorridorMonotonicity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section LiteralCorridors -attribute [local instance] Classical.propDecidable Classical.decEq - -instance HoldingWalk.countable [Countable V] (H : SimpleGraph V) (k : ℕ) (x y : V) : - Countable (HoldingWalk H k x y) := by - induction k generalizing x y with - | zero => - apply Function.Injective.countable (f := fun _ : HoldingWalk H 0 x y => ()) - intro a b _ - cases a - cases b - rfl - | succ k ih => - let (a b : V) : Countable (HoldingWalk H k a b) := ih a b - let f : HoldingWalk H (k+1) x y → - HoldingWalk H k x y ⊕ (Σ z : {z // H.Adj x z}, HoldingWalk H k z.val y) - | .hold w => .inl w - | .step (z := z) h w => .inr ⟨⟨z,h⟩,w⟩ - apply Function.Injective.countable (f := f) - intro a b hab - cases a with - | hold a => - cases b with - | hold b => exact congrArg HoldingWalk.hold (Sum.inl.inj hab) - | step h b => cases hab - | @step _ _ z _ h a => - cases b with - | hold b => cases hab - | @step _ _ z' _ h' b => - have he := Sum.inr.inj hab - have hz := congrArg (fun t => t.1.val) he - change z = z' at hz - subst z' - have hab' : a = b := by simpa only [Sigma.mk.inj_iff,heq_eq_eq,true_and] using he - subst b - rfl - - -abbrev RawCorridor (G : BondGraph V E) (k : ℕ) := - Σ x y : V, HoldingWalk (openSimpleGraph G Set.univ) k x y - -namespace RawCorridor -variable {G : BondGraph V E} {k : ℕ} - -def base (w : RawCorridor G k) : V := w.1 -def endpoint (w : RawCorridor G k) : V := w.2.1 -noncomputable def path (w : RawCorridor G k) : - (openSimpleGraph G Set.univ).Walk w.base w.endpoint := w.2.2.erase -noncomputable def interior (w : RawCorridor G k) : Finset V := - w.path.support.toFinset \ {w.base,w.endpoint} -def retained (w : RawCorridor G k) : Set E := {e | G e ∈ w.path.edges} -noncomputable def blockers (w : RawCorridor G k) : Set E := - {e | ∃ z ∈ w.interior, z ∈ G e} \ w.retained -noncomputable def probability (P : V → V → ℝ) (w : RawCorridor G k) : ℝ := w.2.2.mass P -noncomputable def weight (P : V → V → ℝ) (p : ℝ) (w : RawCorridor G k) : ℝ := - w.probability P * (p^w.path.length)⁻¹ * ((1-p)^w.blockers.ncard)⁻¹ - -theorem path_isPath (w : RawCorridor G k) : w.path.IsPath := w.2.2.erase_isPath - -theorem path_length (w : RawCorridor G k) : w.path.length ≤ k := w.2.2.erase_length - -theorem retained_finite (hG : Function.Injective G) (w : RawCorridor G k) : w.retained.Finite := - (List.finite_toSet w.path.edges).preimage hG.injOn - -theorem blockers_finite (hloc : LocallyFinite G) (w : RawCorridor G k) : w.blockers.Finite := by - apply Set.Finite.subset (s := (incidentSupport G hloc w.interior : Set E)) (Finset.finite_toSet _) - intro e he - exact (mem_incidentSupport G hloc w.interior e).mpr he.1 - -theorem retained_disjoint_blockers (w : RawCorridor G k) : Disjoint w.retained w.blockers := by - exact Set.disjoint_left.mpr (fun e he hb => hb.2 he) - -theorem weight_nonneg (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) - (p : unitInterval) (w : RawCorridor G k) : 0 ≤ w.weight P p := by - exact mul_nonneg (mul_nonneg (w.2.2.mass_nonneg P hP) (inv_nonneg.mpr (pow_nonneg p.2.1 _))) - (inv_nonneg.mpr (pow_nonneg (sub_nonneg.mpr p.2.2) _)) - -end RawCorridor -end LiteralCorridors -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.RussoRows + +namespace OAI + +/-! Trace Bounds for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section RussoOperator +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem russoSlope_symm [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) (x y : V) : + russoSlope G x y (p:ℝ) = russoSlope G y x (p:ℝ) := by + have hh := hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ x y + have he : realTwoPoint G x y = realTwoPoint G y x := funext (fun _ => twoPoint_symm G _ x y) + rw [he] at hh + exact hh.unique (hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ y x) + +theorem russoSlope_aut [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + {a : V ≃ V} {b : E ≃ E} (hab : IsAut G a b) (x y : V) : + russoSlope G (a x) (a y) (p:ℝ) = russoSlope G x y (p:ℝ) := by + have hh := hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ (a x) (a y) + have he : realTwoPoint G (a x) (a y) = realTwoPoint G x y := funext (fun _ => twoPoint_aut G _ hab x y) + rw [he] at hh + exact hh.unique (hasDerivAt_realTwoPoint_slope G hloc hqt p ⟨hp0,hp⟩ x y) + + + +theorem exists_russoOperator [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : + ∃ D : Hilbert V →L[ℂ] Hilbert V, + ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ) := by + obtain ⟨R,hR,hrow⟩ := russoMajorant_uniform_row_bound G hloc hqt p hp + have hb (x : V) (s : Finset V) : ∑ y ∈ s, russoSlope G x y (p:ℝ) ≤ R := by + calc + _ ≤ ∑ y ∈ s, russoMajorant G p x y := Finset.sum_le_sum (fun y _ => russoSlope_le_majorant G hloc hqt p p hp le_rfl x y) + _ ≤ ∑' y, russoMajorant G p x y := Summable.sum_le_tsum s (fun y _ => russoMajorant_nonneg G p x y) + (summable_russoMajorant G hloc hqt p hp x) + _ ≤ R := hrow x + obtain ⟨D,_,hD⟩ := exists_operator_of_row_column_bound (fun x y => russoSlope G x y (p:ℝ)) R hR + (fun x y => russoSlope_nonneg G x y p p.2.2) hb + (fun y s => by simpa only [russoSlope_symm G hloc hqt p hp0 hp] using hb y s) + exact ⟨D,hD⟩ + +theorem russoOperator_positiveReal (G : BondGraph V E) (p : unitInterval) + (D : Hilbert V →L[ℂ] Hilbert V) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : PositiveRealMatrix D := by + intro x y + rw [hD x y] + exact ⟨rfl,russoSlope_nonneg G x y p p.2.2⟩ + +theorem russoOperator_invariant [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (D : Hilbert V →L[ℂ] Hilbert V) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) : KernelInvariant Γ D := by + intro a ha x y + obtain ⟨b,hab⟩ := hΓ ha + simp only [hD,russoSlope_aut G hloc hqt p hp0 hp hab] + +end RussoOperator +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section PositiveTriangleSeries +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem PositiveRealMatrix.triple_hasSum + {A B C : Hilbert V →L[ℂ] Hilbert V} + (hA : PositiveRealMatrix A) (hB : PositiveRealMatrix B) (hC : PositiveRealMatrix C) + (x y : V) : + HasSum (fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * + (matrixCoeff C ab.2 y).re) (matrixCoeff (A*B*C) x y).re := by + have hi (a : V) : HasSum (fun b => (matrixCoeff A x a).re * (matrixCoeff B a b).re * (matrixCoeff C b y).re) + ((matrixCoeff A x a).re * (matrixCoeff (B*C) a y).re) := by + simpa only [mul_assoc] using (hB.mul_hasSum C a y).mul_left (matrixCoeff A x a).re + have ho := hA.mul_hasSum (B*C) x y + have hs : Summable (fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) := by + apply (summable_prod_of_nonneg (f := fun ab : V×V => (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) + (fun ab => mul_nonneg (mul_nonneg (hA _ _).2 (hB _ _).2) (hC _ _).2)).mpr + refine ⟨fun a => (hi a).summable,?_⟩ + simp only [(hi _).tsum_eq] + exact ho.summable + have he : (∑' ab : V×V, (matrixCoeff A x ab.1).re * (matrixCoeff B ab.1 ab.2).re * (matrixCoeff C ab.2 y).re) = + (matrixCoeff (A*B*C) x y).re := by + rw [hs.tsum_prod] + simp only [(hi _).tsum_eq] + rw [ho.tsum_eq,mul_assoc] + exact he ▸ hs.hasSum + +theorem HasKernel.matrixCoeff_re (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x y : V) : + (matrixCoeff T x y).re = twoPoint G p x y := by + change (T (lp.single 2 y (1:ℂ)) x).re = _ + rw [hT x y,Complex.ofReal_re] + +theorem realTriangle_eq_matrixCoeff (G : BondGraph V E) (p : unitInterval) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) (x : V) : + realTriangle G x (p:ℝ) = (matrixCoeff (T^3) x x).re := by + have ht := hT.positiveRealMatrix G p T + have hs := ht.triple_hasSum ht ht x x + rw [show T*T*T = T^3 by simp only [pow_succ,pow_zero,one_mul]] at hs + simpa only [HasKernel.matrixCoeff_re G p T hT,realTriangle,realTriangleTerm,realTwoPoint_coe] using hs.tsum_eq + +theorem rootTriangle_eq_trace (G : BondGraph V E) (p : unitInterval) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : + rootTriangle G root weight (p:ℝ) = (rootTrace root weight (T^3)).re := by + simp only [rootTriangle,realTriangle_eq_matrixCoeff G p T hT,rootTrace,Complex.re_sum, + Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] + +theorem triangleSlope_eq_matrixCoeff (G : BondGraph V E) (p : unitInterval) + (T D : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) (x : V) : + (∑' ab, realTriangleSlope G x ab (p:ℝ)) = + (matrixCoeff (D*T*T + T*D*T + T*T*D) x x).re := by + have ht := hT.positiveRealMatrix G p T + have hd := russoOperator_positiveReal G p D hD + have h₁ := (hd.triple_hasSum ht ht x x) + have h₂ := (ht.triple_hasSum hd ht x x) + have h₃ := (ht.triple_hasSum ht hd x x) + have h := (h₁.add h₂).add h₃ + have ha (A B : Hilbert V →L[ℂ] Hilbert V) : matrixCoeff (A+B) x x = matrixCoeff A x x + matrixCoeff B x x := rfl + simp only [ha,Complex.add_re] + simpa only [hD,Complex.ofReal_re,HasKernel.matrixCoeff_re G p T hT, + realTriangleSlope,realTwoPoint_coe] using h.tsum_eq + +end PositiveTriangleSeries +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section RootTriangleTraceDerivative +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem rootTrace_triangleSlope_cyclic + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + {Γ : Set (V ≃ V)} (htr : RootTransport root weight Γ) + (T D : Hilbert V →L[ℂ] Hilbert V) (hT : KernelInvariant Γ T) (hD : KernelInvariant Γ D) : + rootTrace root weight (D*T*T+T*D*T+T*T*D) = 3*rootTrace root weight (T^2*D) := by + have h₁ : rootTrace root weight (D*T*T) = rootTrace root weight (T^2*D) := by + rw [mul_assoc,rootTrace_cyclic root weight htr D (T*T) hD (hT.mul hT),pow_two] + have h₂ : rootTrace root weight (T*D*T) = rootTrace root weight (T^2*D) := by + rw [mul_assoc,rootTrace_cyclic root weight htr T (D*T) hT (hD.mul hT),h₁] + rw [rootTrace_add,rootTrace_add,h₁,h₂,←pow_two] + ring + + + +theorem hasDerivAt_rootTriangle_trace [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (T D : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : + HasDerivAt (rootTriangle G root weight) (3*(rootTrace root weight (T^2*D)).re) (p:ℝ) := by + have hti : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + have hdi := russoOperator_invariant G hloc hqt p hp0 hp D hD Γ hΓ + have hs := hasDerivAt_rootTriangle_subcritical G hloc hqt root weight p hp0 hp + have he : (∑ i, weight i * ∑' ab, realTriangleSlope G (root i) ab (p:ℝ)) = + 3*(rootTrace root weight (T^2*D)).re := by + simp only [triangleSlope_eq_matrixCoeff G p T D hT hD] + have hr := congrArg Complex.re (rootTrace_triangleSlope_cyclic root weight htr T D hti hdi) + simpa only [rootTrace,Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im, + Complex.re_ofNat,Complex.im_ofNat,zero_mul,sub_zero] using hr + exact he ▸ hs + +end RootTriangleTraceDerivative +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section ContactKernelReroot +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem contactKernel_reroot [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) + (hfin : ∀ x, ∀ᵐ ω ∂law p, (cluster G ω x).Finite) + (J : V → V → ℝ≥0∞) (hJ : ∀ a ∈ Γ, ∀ x y, J (a x) (a y) = J x y) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω J x y) = + ∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, ∑' y, + J (root i) y * ENNReal.ofReal (fullLargeContact G (root i) y 0 ω) ∂law p := by + have ht := clusterPairFunctional_reroot G hconn hloc root weight Γ hΓ htr hw p hfin + J hJ (fun ω x y => ENNReal.ofReal (fullLargeContact G x y 0 ω)) + (fun x y => (measurable_fullLargeContact G hloc x y 0).ennreal_ofReal) + (fun ω x y a b hxa hyb => congrArg ENNReal.ofReal (fullLargeContact_cluster_constant G ω 0 x y a b hxa hyb)) + (fun a _ b hab ω x y => congrArg ENNReal.ofReal (fullLargeContact_aut G hab ω x y 0)) + simp_rw [fullLargeContact_distinct] at ht + rw [←ht] + unfold clusterPairFunctional + apply Finset.sum_congr rfl + intro i _ + congr 1 + apply lintegral_congr_ae + filter_upwards [hfin (root i)] with ω hω + unfold clusterPairDensity + congr 1 + apply tsum_congr + intro y + congr 1 + by_cases hd : Conn G ω (root i) y + · simp only [hd,not_true_eq_false,ite_false] + · rw [ite_eq_left hd,ite_eq_left hd] + dsimp only + rw [clusterPairKernel_edge G hloc ω (root i) y hd hω] + simp only [fullLargeContact,hd,not_false_eq_true,Nat.zero_le,and_self,ite_true,ENNReal.ofReal_natCast] + exact mul_comm _ _ + +theorem contact_lintegral_eq_russoOperator [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (D : Hilbert V →L[ℂ] Hilbert V) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) (x y : V) : + (∫⁻ ω, ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = + ENNReal.ofReal (1-(p:ℝ)) * ennMatrixCoeff D x y := by + rw [←ofReal_integral_eq_lintegral_ofReal (integrable_fullContact_subcritical G hloc hqt p hp x y) + (Eventually.of_forall (fullLargeContact_nonneg G x y 0))] + simp only [ennMatrixCoeff,hD,Complex.ofReal_re,russoSlope,realContactExpectation_coe] + rw [←ENNReal.ofReal_mul (sub_nonneg.mpr p.2.2)] + congr 1 + have hd : 1-(p:ℝ) ≠ 0 := ne_of_gt (sub_pos.mpr ((show (p:ℝ) < (pc G:ℝ) from hp).trans_le (pc G).2.2)) + exact (mul_div_cancel₀ _ hd).symm + +end ContactKernelReroot +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +open scoped ENNReal +section MixedRussoTrace +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem mixedFunctional_eq_russoTrace [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (J D : Hilbert V →L[ℂ] Hilbert V) (hJ : PositiveRealMatrix J) (hiJ : KernelInvariant Γ J) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : + clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff J) x y) = + ENNReal.ofReal ((1-(p:ℝ))*(rootTrace root weight (J*D)).re) := by + have hd := russoOperator_positiveReal G p D hD + have hdi (x y : V) : ennMatrixCoeff D x y = ennMatrixCoeff D y x := by + simp only [ennMatrixCoeff,hD,Complex.ofReal_re,russoSlope_symm G hloc hqt p hp0 hp x y] + have hji : ∀ a ∈ Γ, ∀ x y, ennMatrixCoeff J (a x) (a y) = ennMatrixCoeff J x y := by + intro a ha x y; unfold ennMatrixCoeff; rw [hiJ a ha] + rw [contactKernel_reroot G hconn hloc root weight Γ hΓ htr hw p + (subcritical_cluster_finite_ae G p hp) (ennMatrixCoeff J) hji] + have he (x : V) : (∫⁻ ω, ∑' y, ennMatrixCoeff J x y * ENNReal.ofReal (fullLargeContact G x y 0 ω) ∂law p) = + ENNReal.ofReal (1-(p:ℝ)) * ennMatrixCoeff (J*D) x x := by + have hm (y : V) : Measurable (fun ω : Set E => ennMatrixCoeff J x y * ENNReal.ofReal (fullLargeContact G x y 0 ω)) := + (measurable_const : Measurable (fun _ : Set E => ennMatrixCoeff J x y)).mul + (measurable_fullLargeContact G hloc x y 0).ennreal_ofReal + rw [lintegral_tsum (fun y => (hm y).aemeasurable)] + simp_rw [lintegral_const_mul _ (measurable_fullLargeContact G hloc x _ 0).ennreal_ofReal, + contact_lintegral_eq_russoOperator G hloc hqt p hp D hD] + rw [ennMatrixCoeff_mul hJ hd,←ENNReal.tsum_mul_left] + apply tsum_congr + intro y + rw [hdi x y] + ac_rfl + simp_rw [he] + rw [ENNReal.ofReal_mul (sub_nonneg.mpr p.2.2),←enn_rootTrace root weight hw (J*D) (hJ.mul hd),Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ac_rfl + +theorem mixedFunctional_toReal_eq_russoTrace [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (J D : Hilbert V →L[ℂ] Hilbert V) (hJ : PositiveRealMatrix J) (hiJ : KernelInvariant Γ J) + (hD : ∀ x y, matrixCoeff D x y = (russoSlope G x y (p:ℝ):ℂ)) : + (clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff J) x y)).toReal = + (1-(p:ℝ))*(rootTrace root weight (J*D)).re := by + rw [mixedFunctional_eq_russoTrace G hconn hloc hqt root weight Γ hΓ htr hw p hp0 hp J D hJ hiJ hD] + apply ENNReal.toReal_ofReal + apply mul_nonneg (sub_nonneg.mpr p.2.2) + have hd := hJ.mul (russoOperator_positiveReal G p D hD) + simp only [rootTrace,Complex.re_sum,Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero] + exact Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (hd _ _).2) + +end MixedRussoTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory Filter +section RootTriangleRusso +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem rootTriangle_russo [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) + (T : Hilbert V →L[ℂ] Hilbert V) (hT : HasKernel G p T) : + (1-(p:ℝ))*deriv (rootTriangle G root weight) (p:ℝ) = + 3*(clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)).toReal := by + obtain ⟨D,hD⟩ := exists_russoOperator G hloc hqt p hp0 hp + have hi : KernelInvariant Γ T := fun a ha => hT.invariant G p T a (hΓ ha) + rw [(hasDerivAt_rootTriangle_trace G hloc hqt root weight Γ hΓ htr p hp0 hp T D hT hD).deriv, + mixedFunctional_toReal_eq_russoTrace G hconn hloc hqt root weight Γ hΓ htr hw p hp0 hp + (T^2) D ((hT.positiveRealMatrix G p T).pow 2) (hi.pow 2) hD] + ring + +theorem realTriangle_one_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : 1 ≤ realTriangle G x (p:ℝ) := by + have hh := (summable_realTriangleTerm G hloc hqt p hp x).le_tsum (x,x) + (fun ab _ => by + simp only [realTriangleTerm,realTwoPoint_coe] + exact mul_nonneg (mul_nonneg (twoPoint_nonneg G p _ _) (twoPoint_nonneg G p _ _)) (twoPoint_nonneg G p _ _)) + simpa only [realTriangleTerm,realTwoPoint_coe,twoPoint_self,mul_one,realTriangle] using hh + +theorem rootTriangle_one_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (p : unitInterval) (hp : p < pc G) : 1 ≤ rootTriangle G root weight (p:ℝ) := by + calc + 1 = ∑ i, weight i * 1 := by simpa using hw1.symm + _ ≤ _ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left + (realTriangle_one_le G hloc hqt p hp (root i)) (hw i)) + +end RootTriangleRusso +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal +section RealMixedTrace +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem critical_mixed_trace_bound_real + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ A B : ℝ, 0 < A ∧ 0 < B ∧ ∀ (p : unitInterval), + (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → + ∀ L : ℝ, 1 ≤ L → + (clusterPairFunctional G p root weight (fun ω x y => + clusterPairKernel G ω (indexedEdgeKernel G) x y * + clusterPairKernel G ω (ennMatrixCoeff (T^2)) x y)).toReal ≤ + 2*(A*L^(1-α)*rootTriangle G root weight (p:ℝ)) + + (B*L^((1:ℝ)/2+ε-2*α))^((1:ℝ)/2) * + (‖T‖^3*rootTriangle G root weight (p:ℝ))^((1:ℝ)/2) := by + obtain ⟨A,B,hA,hB,hb⟩ := critical_mixed_trace_bound G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + refine ⟨A,B,hA,hB,?_⟩ + intro p hp hpq T hT L hL + have ht : 0 ≤ rootTriangle G root weight (p:ℝ) := (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq).trans' (by norm_num) + have ha : 0 ≤ A*L^(1-α)*rootTriangle G root weight (p:ℝ) := mul_nonneg (mul_nonneg hA.le (Real.rpow_nonneg (by linarith) _)) ht + have hc : 0 ≤ B*L^((1:ℝ)/2+ε-2*α) := mul_nonneg hB.le (Real.rpow_nonneg (by linarith) _) + have hn : 0 ≤ ‖T‖^3*rootTriangle G root weight (p:ℝ) := mul_nonneg (pow_nonneg (norm_nonneg _) _) ht + have hb' := hb p hp hpq.le T hT L hL + rw [←rootTriangle_eq_trace G p root weight T hT] at hb' + have htop : 2*ENNReal.ofReal (A*L^(1-α)*rootTriangle G root weight (p:ℝ)) + + (ENNReal.ofReal (B*L^((1:ℝ)/2+ε-2*α)))^((1:ℝ)/2) * + (ENNReal.ofReal (‖T‖^3*rootTriangle G root weight (p:ℝ)))^((1:ℝ)/2) ≠ ⊤ := by finiteness + have hh := ENNReal.toReal_mono htop hb' + rw [ENNReal.toReal_add (by finiteness) (by finiteness)] at hh + simpa only [ENNReal.toReal_mul, + ENNReal.toReal_ofNat,←ENNReal.toReal_rpow,ENNReal.toReal_ofReal ha, + ENNReal.toReal_ofReal hc,ENNReal.toReal_ofReal hn] using hh + +end RealMixedTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TraceNumerics +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem HasKernel.norm_le_susceptibility_bound [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (T : Hilbert V →L[ℂ] Hilbert V) + (hT : HasKernel G p T) (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, susceptibility G p x ≤ C) : + ‖T‖ ≤ C := by + have hr (x : V) (s : Finset V) : ∑ y ∈ s, twoPoint G p x y ≤ C := + ((summable_twoPoint_subcritical G hloc hqt p hp x).sum_le_tsum s + (fun y _ => twoPoint_nonneg G p x y)).trans (hb x) + obtain ⟨S,hS,hK⟩ := exists_operator_of_row_column_bound (twoPoint G p) C hC (twoPoint_nonneg G p) + hr (fun y s => by simpa only [twoPoint_symm G p] using hr y s) + rwa [hT.unique hK] + +lemma sqrt_mixed_power (B L m a r : ℝ) (hB : 0 ≤ B) (hL : 0 ≤ L) (hm : 0 ≤ m) (ha : 0 ≤ a) : + (B*L^r)^((1:ℝ)/2) * (m^3*a)^((1:ℝ)/2) = + Real.sqrt B * L^(r/2) * m^((3:ℝ)/2) * Real.sqrt a := by + rw [Real.mul_rpow hB (Real.rpow_nonneg hL _), Real.mul_rpow (pow_nonneg hm _) ha, + ←Real.rpow_mul hL,←Real.rpow_natCast m 3,←Real.rpow_mul hm, + ←Real.sqrt_eq_rpow,←Real.sqrt_eq_rpow] + rw [show r*(1/2:ℝ) = r/2 by ring] + norm_num only [Nat.cast_ofNat] + ring + +lemma sqrt_derivative_estimate (p q A B L m a a' F : ℝ) + (hp : p ≤ q) (hq : q < 1) (hA : 0 ≤ A) (hB : 0 ≤ B) + (hL : 1 ≤ L) (hm : 0 ≤ m) (ha : 1 ≤ a) + (α r : ℝ) (hid : (1-p)*a' = 3*F) + (hF : F ≤ 2*(A*L^(1-α)*a) + (B*L^r)^((1:ℝ)/2)*(m^3*a)^((1:ℝ)/2)) : + a'/(2*Real.sqrt a) ≤ + (3*(A+Real.sqrt B)/(1-q))*L^(1-α)*Real.sqrt a + + (3*(A+Real.sqrt B)/(1-q))*L^(r/2)*m^((3:ℝ)/2) := by + have ha0 : 0 < a := by linarith + have hs : 0 < Real.sqrt a := Real.sqrt_pos.mpr ha0 + have hp1 : 0 < 1-p := by linarith + have hq1 : 0 < 1-q := by linarith + have he := Real.sq_sqrt ha0.le + have hL0 : 0 ≤ L := by linarith + rw [sqrt_mixed_power B L m a r hB hL0 hm ha0.le] at hF + have hu : 0 ≤ L^(1-α) := Real.rpow_nonneg hL0 _ + have hv : 0 ≤ L^(r/2)*m^((3:ℝ)/2) := mul_nonneg (Real.rpow_nonneg hL0 _) (Real.rpow_nonneg hm _) + have hB0 := Real.sqrt_nonneg B + have hcoef : 3*A/(1-p) ≤ 3*(A+Real.sqrt B)/(1-q) := by + apply (div_le_div_iff₀ hp1 hq1).mpr + nlinarith + have hcoef2 : 3*Real.sqrt B/(2*(1-p)) ≤ 3*(A+Real.sqrt B)/(1-q) := by + apply (div_le_div_iff₀ (mul_pos (by norm_num) hp1) hq1).mpr + nlinarith + have hbase : a'/(2*Real.sqrt a) ≤ 3*A/(1-p)*L^(1-α)*Real.sqrt a + + (3*Real.sqrt B/(2*(1-p)))*(L^(r/2)*m^((3:ℝ)/2)) := by + apply (div_le_iff₀ (mul_pos (by norm_num) hs)).mpr + apply (mul_le_mul_iff_right₀ hp1).mp + have hex : (3*A/(1-p)*L^(1-α)*Real.sqrt a + + (3*Real.sqrt B/(2*(1-p)))*(L^(r/2)*m^((3:ℝ)/2))) * (2*Real.sqrt a) * (1-p) = + 3*(2*(A*L^(1-α)*a) + Real.sqrt B*L^(r/2)*m^((3:ℝ)/2)*Real.sqrt a) := by + field_simp + ring_nf + rw [he] + ring + rw [hid,mul_comm (1-p) _,hex] + linarith + exact hbase.trans (add_le_add + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hcoef hu) hs.le) + (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hcoef2 hv)) + +end TraceNumerics +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section TraceSquareRoot +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def rootTriangleSqrt (G : BondGraph V E) {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (t : ℝ) : ℝ := Real.sqrt (rootTriangle G root weight t) + +theorem hasDerivAt_rootTriangleSqrt [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (p : unitInterval) (hp0 : 0 < (p:ℝ)) (hp : p < pc G) : + HasDerivAt (rootTriangleSqrt G root weight) + (deriv (rootTriangle G root weight) (p:ℝ) / (2*rootTriangleSqrt G root weight (p:ℝ))) (p:ℝ) := by + apply (hasDerivAt_rootTriangle_subcritical G hloc hqt root weight p hp0 hp).differentiableAt.hasDerivAt.sqrt + have hh := rootTriangle_one_le G hloc hqt root weight hw hw1 p hp + linarith + + +theorem critical_rootTriangleSqrt_derivative + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (α ε : ℝ) (hα : 0 < α) (hα1 : α < 1/2) (hε : 0 < ε) + (hr : (1:ℝ)/2+ε-2*α < 0) : + ∃ C : ℝ, 0 < C ∧ ∀ (p : unitInterval), + (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ (T : Hilbert V →L[ℂ] Hilbert V), HasKernel G p T → + ∀ L : ℝ, 1 ≤ L → + deriv (rootTriangleSqrt G root weight) (p:ℝ) ≤ + C*L^(1-α)*rootTriangleSqrt G root weight (p:ℝ) + + C*L^(((1:ℝ)/2+ε-2*α)/2)*‖T‖^((3:ℝ)/2) := by + obtain ⟨A,B,hA,hB,hb⟩ := critical_mixed_trace_bound_real G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + refine ⟨3*(A+Real.sqrt B)/(1-(pc G:ℝ)),div_pos (mul_pos (by norm_num) + (add_pos_of_pos_of_nonneg hA (Real.sqrt_nonneg B))) (sub_pos.mpr hp₁),?_⟩ + intro p hp hpq T hT L hL + have hp0 : 0 < (p:ℝ) := lt_of_lt_of_le (half_pos hp₀) hp + rw [(hasDerivAt_rootTriangleSqrt G hloc hqt root weight (fun i => (hw i).le) hw1 p hp0 hpq).deriv] + exact sqrt_derivative_estimate p (pc G) A B L ‖T‖ (rootTriangle G root weight p) + (deriv (rootTriangle G root weight) p) _ hpq.le hp₁ hA.le hB.le hL (norm_nonneg _) + (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq) α _ + (rootTriangle_russo G hconn hloc hqt root weight Γ hΓ htr (fun i => (hw i).le) p hp0 hpq T hT) + (hb p hp hpq T hT L hL) + +end TraceSquareRoot +end Percolation + + +namespace Percolation +section TraceExponents + +lemma trace_exponent_choices (η : ℝ) (hη : 0 < η) : + ∃ α ε ρ lambda : ℝ, 0 < α ∧ α < 1/2 ∧ 0 < ε ∧ 0 < ρ ∧ 0 < lambda ∧ + (1:ℝ)/2+ε-2*α < 0 ∧ lambda*(1-α) < 1 ∧ + lambda*(((1:ℝ)/2+ε-2*α)/2) + (3:ℝ)/2*(1+ρ) < 1+η/2 := by + let ζ := min (1/2:ℝ) η + let d := min (ζ/16) (η/32) + have hz : 0 < ζ := lt_min (by norm_num) hη + have hz1 : ζ ≤ 1/2 := min_le_left _ _ + have hze : ζ ≤ η := min_le_right _ _ + have hd : 0 < d := lt_min (div_pos hz (by norm_num)) (div_pos hη (by norm_num)) + have hdz : d ≤ ζ/16 := min_le_left _ _ + have hde : d ≤ η/32 := min_le_right _ _ + have hzd : 0 ≤ ζ*d := mul_nonneg hz.le hd.le + refine ⟨1/2-d,d,d,2-ζ,?_,?_,hd,hd,?_,?_,?_,?_⟩ <;> nlinarith + +lemma trace_scale_large_term (δ D lambda r ρ : ℝ) (hδ : 0 < δ) (hD : 0 ≤ D) : + (δ^(-lambda))^(r/2)*(D*δ^(-1-ρ))^((3:ℝ)/2) = + D^((3:ℝ)/2)*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by + rw [Real.mul_rpow hD (Real.rpow_nonneg hδ.le _),←Real.rpow_mul hδ.le,←Real.rpow_mul hδ.le] + rw [show δ^(-lambda*(r/2))*(D^((3:ℝ)/2)*δ^((-1-ρ)*((3:ℝ)/2))) = + D^((3:ℝ)/2)*(δ^(-lambda*(r/2))*δ^((-1-ρ)*((3:ℝ)/2))) by ring, + ←Real.rpow_add hδ] + congr 2 + ring + +lemma trace_scale_derivative (δ D C lambda r ρ α b b' m : ℝ) + (hδ : 0 < δ) (hD : 0 ≤ D) (hC : 0 ≤ C) + (hb : 0 ≤ b) (hm : 0 ≤ m) (hmD : m ≤ D*δ^(-1-ρ)) + (hd : b' ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*m^((3:ℝ)/2)) : + b' ≤ (C*(1+D^((3:ℝ)/2)))*δ^(-(lambda*(1-α)))*b + + (C*(1+D^((3:ℝ)/2)))*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by + have hs := Real.rpow_le_rpow hm hmD (by norm_num : (0:ℝ) ≤ 3/2) + have he : (δ^(-lambda))^(1-α) = δ^(-(lambda*(1-α))) := by rw [←Real.rpow_mul hδ.le]; congr 1; ring + have hc1 : C ≤ C*(1+D^((3:ℝ)/2)) := by nlinarith [Real.rpow_nonneg hD ((3:ℝ)/2)] + have hc2 : C*D^((3:ℝ)/2) ≤ C*(1+D^((3:ℝ)/2)) := by nlinarith + calc + b' ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*m^((3:ℝ)/2) := hd + _ ≤ C*(δ^(-lambda))^(1-α)*b + C*(δ^(-lambda))^(r/2)*(D*δ^(-1-ρ))^((3:ℝ)/2) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left hs (mul_nonneg hC (Real.rpow_nonneg (Real.rpow_nonneg hδ.le _) _))) + _ = C*δ^(-(lambda*(1-α)))*b + (C*D^((3:ℝ)/2))*δ^(-(lambda*(r/2)+(3:ℝ)/2*(1+ρ))) := by + rw [he,mul_assoc C ((δ^(-lambda))^(r/2)),trace_scale_large_term δ D lambda r ρ hδ hD]; ring + _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hc1 (Real.rpow_nonneg hδ.le _)) hb) + (mul_le_mul_of_nonneg_right hc2 (Real.rpow_nonneg hδ.le _)) + +end TraceExponents +end Percolation + + +namespace Percolation +section IntegratingFactor + +lemma hasDerivAt_gap_rpow (q r t : ℝ) (ht : t < q) : + HasDerivAt (fun x : ℝ => (q-x)^r) (-r*(q-t)^(r-1)) t := by + convert! ((hasDerivAt_const t q).sub (hasDerivAt_id t)).rpow_const + (Or.inl (ne_of_gt (sub_pos.mpr ht))) using 1 + simp only [Pi.sub_apply, id_eq] + ring + +noncomputable def traceIntegratingFactor (q C A t : ℝ) : ℝ := + Real.exp (C/(1-A)*(q-t)^(1-A)) + +lemma hasDerivAt_traceIntegratingFactor (q C A t : ℝ) (hA : A < 1) (ht : t < q) : + HasDerivAt (traceIntegratingFactor q C A) + (-C*(q-t)^(-A)*traceIntegratingFactor q C A t) t := by + have hd := ((hasDerivAt_gap_rpow q (1-A) t ht).const_mul (C/(1-A))).exp + convert! hd using 1 + unfold traceIntegratingFactor + rw [show 1-A-1 = -A by ring] + field_simp [ne_of_gt (sub_pos.mpr hA)] + +lemma traceIntegratingFactor_bounds (q C A t : ℝ) (hC : 0 ≤ C) (hA : A < 1) + (ht : t < q) (hd : q-t ≤ 1) : + 1 ≤ traceIntegratingFactor q C A t ∧ + traceIntegratingFactor q C A t ≤ Real.exp (C/(1-A)) := by + have hk : 0 ≤ C/(1-A) := div_nonneg hC (sub_pos.mpr hA).le + have hr : 0 ≤ (q-t)^(1-A) := Real.rpow_nonneg (sub_pos.mpr ht).le _ + constructor + · exact Real.one_le_exp (mul_nonneg hk hr) + · apply Real.exp_le_exp.mpr + exact mul_le_of_le_one_right hk (Real.rpow_le_one (sub_pos.mpr ht).le hd (sub_pos.mpr hA).le) + +lemma hasDerivAt_traceComparison (f : ℝ → ℝ) (q C A κ t : ℝ) + (hA : A < 1) (hκ : 0 < κ) (ht : t < q) (hf : DifferentiableAt ℝ f t) : + HasDerivAt (fun x => traceIntegratingFactor q C A x*f x - + (C*Real.exp (C/(1-A))/κ)*(q-x)^(-κ)) + (traceIntegratingFactor q C A t*(deriv f t-C*(q-t)^(-A)*f t) - + C*Real.exp (C/(1-A))*(q-t)^(-κ-1)) t := by + have hh := ((hasDerivAt_traceIntegratingFactor q C A t hA ht).mul hf.hasDerivAt).sub + ((hasDerivAt_gap_rpow q (-κ) t ht).const_mul (C*Real.exp (C/(1-A))/κ)) + convert! hh using 1 + field_simp [ne_of_gt hκ] + ring + + + +theorem singular_ode_subpower (f : ℝ → ℝ) (q s C A B κ : ℝ) + (hs : s < q) (hqs : q-s ≤ 1) (hC : 0 < C) (hA : A < 1) + (hκ : 0 < κ) (hB : B ≤ 1+κ) + (hf : ∀ t ∈ Set.Ico s q, DifferentiableAt ℝ f t) + (hn : ∀ t ∈ Set.Ico s q, 0 ≤ f t) + (hd : ∀ t ∈ Set.Ico s q, + deriv f t ≤ C*(q-t)^(-A)*f t + C*(q-t)^(-B)) : + ∃ K : ℝ, 0 < K ∧ ∀ t ∈ Set.Ico s q, f t ≤ K*(q-t)^(-κ) := by + let M := Real.exp (C/(1-A)) + let Q := C*M/κ + let g := fun t => traceIntegratingFactor q C A t*f t - Q*(q-t)^(-κ) + have hM : 0 < M := Real.exp_pos _ + have hQ : 0 < Q := div_pos (mul_pos hC hM) hκ + have hgs (t : ℝ) (ht : t ∈ Set.Ico s q) : + HasDerivAt g (traceIntegratingFactor q C A t*(deriv f t-C*(q-t)^(-A)*f t) - + C*M*(q-t)^(-κ-1)) t := hasDerivAt_traceComparison f q C A κ t hA hκ ht.2 (hf t ht) + have hgn (t : ℝ) (ht : t ∈ Set.Ico s q) : deriv g t ≤ 0 := by + have htq : 0 < q-t := sub_pos.mpr ht.2 + have ht1 : q-t ≤ 1 := by linarith [ht.1] + obtain ⟨hw,hwM⟩ := traceIntegratingFactor_bounds q C A t hC.le hA ht.2 ht1 + have hpow : (q-t)^(-B) ≤ (q-t)^(-κ-1) := + Real.rpow_le_rpow_of_exponent_ge htq ht1 (by linarith) + have hmul := mul_le_mul_of_nonneg_left (hd t ht) (show 0 ≤ traceIntegratingFactor q C A t by linarith) + have h₂ := mul_le_mul_of_nonneg_right hwM (mul_nonneg hC.le (Real.rpow_nonneg htq.le (-B))) + have h₃ := mul_le_mul_of_nonneg_left hpow (mul_nonneg hC.le hM.le) + rw [(hgs t ht).deriv] + dsimp only [M] at hM ⊢ + dsimp only [M] at h₃ + nlinarith + have hgmono : AntitoneOn g (Set.Ico s q) := by + apply antitoneOn_of_deriv_nonpos (convex_Ico s q) + · intro t ht + exact (hgs t ht).continuousAt.continuousWithinAt + · intro t ht + exact (hgs t (interior_subset ht)).differentiableAt.differentiableWithinAt + · intro t ht + exact hgn t (interior_subset ht) + have hsI : s ∈ Set.Ico s q := ⟨le_rfl,hs⟩ + refine ⟨M*f s+Q,add_pos_of_nonneg_of_pos (mul_nonneg hM.le (hn s hsI)) hQ,?_⟩ + intro t ht + have htq : 0 < q-t := sub_pos.mpr ht.2 + have ht1 : q-t ≤ 1 := by linarith [ht.1] + obtain ⟨hwt,_⟩ := traceIntegratingFactor_bounds q C A t hC.le hA ht.2 ht1 + obtain ⟨_,hws⟩ := traceIntegratingFactor_bounds q C A s hC.le hA hs hqs + have hmono := hgmono hsI ht ht.1 + have hneg : 0 ≤ Q*(q-s)^(-κ) := mul_nonneg hQ.le (Real.rpow_nonneg (sub_pos.mpr hs).le _) + have hft := mul_le_mul_of_nonneg_right hwt (hn t ht) + have hfs := mul_le_mul_of_nonneg_right hws (hn s hsI) + have hpow : 1 ≤ (q-t)^(-κ) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos htq ht1 (neg_nonpos.mpr hκ.le) + have hscale := mul_le_mul_of_nonneg_left hpow (mul_nonneg hM.le (hn s hsI)) + dsimp only [g] at hmono + dsimp only [M] at hscale ⊢ + nlinarith + +end IntegratingFactor +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SubpowerTrace +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem critical_rootTriangle_subpower + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (η : ℝ) (hη : 0 < η) : + ∃ K : ℝ, 0 < K ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + rootTriangle G root weight (p:ℝ) ≤ K*((pc G:ℝ)-(p:ℝ))^(-η) := by + obtain ⟨α,ε,ρ,lambda,hα,hα1,hε,hρ,hlambda,hr,hA,hB⟩ := trace_exponent_choices η hη + obtain ⟨C₀,hC₀,hder⟩ := critical_rootTriangleSqrt_derivative G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin α ε hα hα1 hε hr + obtain ⟨D,hD,hχ⟩ := almost_linear_susceptibility G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin ρ hρ + let C := C₀*(1+D^((3:ℝ)/2)) + let A := lambda*(1-α) + let B := lambda*(((1:ℝ)/2+ε-2*α)/2)+(3:ℝ)/2*(1+ρ) + have hC : 0 < C := mul_pos hC₀ (by linarith [Real.rpow_nonneg hD.le ((3:ℝ)/2)]) + have hunit (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : t ∈ unitInterval := + ⟨(half_pos hp₀).le.trans ht.1,ht.2.le.trans (pc G).2.2⟩ + have hdf (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : + DifferentiableAt ℝ (rootTriangleSqrt G root weight) t := by + exact (hasDerivAt_rootTriangleSqrt G hloc hqt root weight (fun i => (hw i).le) hw1 + ⟨t,hunit t ht⟩ ((half_pos hp₀).trans_le ht.1) ht.2).differentiableAt + have hod (t : ℝ) (ht : t ∈ Set.Ico ((pc G:ℝ)/2) (pc G:ℝ)) : + deriv (rootTriangleSqrt G root weight) t ≤ C*((pc G:ℝ)-t)^(-A)*rootTriangleSqrt G root weight t + + C*((pc G:ℝ)-t)^(-B) := by + let p : unitInterval := ⟨t,hunit t ht⟩ + have hδ : 0 < (pc G:ℝ)-t := sub_pos.mpr ht.2 + have hδ1 : (pc G:ℝ)-t ≤ 1 := by linarith [(pc G).2.2,ht.1] + obtain ⟨T,hT⟩ := operatorBounded_of_lt_pc G hloc hqt p ht.2 + have hm := hT.norm_le_susceptibility_bound G hloc hqt p ht.2 T (D*((pc G:ℝ)-t)^(-1-ρ)) + (mul_nonneg hD.le (Real.rpow_nonneg hδ.le _)) (hχ p ht.2) + have hL : 1 ≤ (((pc G:ℝ)-t)^(-lambda)) := + Real.one_le_rpow_of_pos_of_le_one_of_nonpos hδ hδ1 (neg_nonpos.mpr hlambda.le) + exact trace_scale_derivative ((pc G:ℝ)-t) D C₀ lambda ((1:ℝ)/2+ε-2*α) ρ α + (rootTriangleSqrt G root weight t) (deriv (rootTriangleSqrt G root weight) t) ‖T‖ + hδ hD.le hC₀.le (Real.sqrt_nonneg _) (norm_nonneg _) hm + (hder p ht.1 ht.2 T hT (((pc G:ℝ)-t)^(-lambda)) hL) + obtain ⟨K,hK,hb⟩ := singular_ode_subpower (rootTriangleSqrt G root weight) (pc G) ((pc G:ℝ)/2) + C A B (η/2) (by linarith) (by linarith [(pc G).2.2]) hC hA (half_pos hη) hB.le + hdf (fun _ _ => Real.sqrt_nonneg _) hod + refine ⟨K^2,sq_pos_of_pos hK,?_⟩ + intro p hp hpq + have ha : 0 ≤ rootTriangle G root weight (p:ℝ) := + le_trans (by norm_num) (rootTriangle_one_le G hloc hqt root weight (fun i => (hw i).le) hw1 p hpq) + have hb' := pow_le_pow_left₀ (Real.sqrt_nonneg (rootTriangle G root weight (p:ℝ))) (hb p ⟨hp,hpq⟩) 2 + change (Real.sqrt (rootTriangle G root weight (p:ℝ)))^2 ≤ _ at hb' + rw [Real.sq_sqrt ha,mul_pow] at hb' + have he : (((pc G:ℝ)-(p:ℝ))^(-(η/2)))^2 = ((pc G:ℝ)-(p:ℝ))^(-η) := by + rw [←Real.rpow_natCast _ 2,←Real.rpow_mul (sub_pos.mpr (show (p:ℝ)<(pc G:ℝ) from hpq)).le] + congr 1 + norm_num + rw [he] at hb' + exact hb' + +end SubpowerTrace +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section QuantitativeSprinkling +attribute [local instance] Classical.propDecidable Classical.decEq + +lemma riccati_step (a M n x : ℝ) (ha : 0 ≤ a) (hM : 0 ≤ M) (_hn : 0 ≤ n) + (_hx : 0 ≤ x) (hb : x ≤ M/(1-a*n*M)) (hh : a*(n+1)*M < 1) : + a*x < 1 ∧ x/(1-a*x) ≤ M/(1-a*(n+1)*M) := by + have haM : 0 ≤ a*M := mul_nonneg ha hM + have hp : 0 < 1-a*n*M := by nlinarith + have hb' := (le_div_iff₀ hp).mp hb + have hs : a*(M/(1-a*n*M)) < 1 := by + rw [←mul_div_assoc,div_lt_one hp] + nlinarith + have hax : a*x < 1 := (mul_le_mul_of_nonneg_left hb ha).trans_lt hs + refine ⟨hax,?_⟩ + apply (div_le_div_iff₀ (sub_pos.mpr hax) (sub_pos.mpr hh)).mpr + nlinarith + + + +theorem sprinkling_iterated_bound [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) (m D : ℕ) + (hD : ∀ x, degree G x ≤ D) (A : Hilbert V →L[ℂ] Hilbert V) + (hA : HasKernel G (orParameter q m) A) (n : ℕ) + (hn : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1) : + ∃ B : Hilbert V →L[ℂ] Hilbert V, HasKernel G (orParameter q (m+n)) B ∧ + ‖B‖ ≤ ‖A‖/(1-(q:ℝ)*(2*D)*(n:ℝ)*‖A‖) := by + induction n with + | zero => exact ⟨A,by simpa using hA,by simp⟩ + | succ n ih => + have ha : 0 ≤ (q:ℝ)*(2*D) := mul_nonneg q.2.1 (by positivity) + have hnext : (q:ℝ)*(2*D)*((n:ℝ)+1)*‖A‖ < 1 := by simpa using hn + have hprev : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1 := by + nlinarith [mul_nonneg ha (norm_nonneg A)] + obtain ⟨B,hB,hBn⟩ := ih hprev + obtain ⟨hs,hbound⟩ := riccati_step ((q:ℝ)*(2*D)) ‖A‖ n ‖B‖ ha (norm_nonneg _) (Nat.cast_nonneg _) (norm_nonneg _) hBn hnext + obtain ⟨C,hC,hCn⟩ := sprinkling_bound G hloc q (m+n) D hD B hB hs + exact ⟨C,by simpa [Nat.add_assoc] using hC,by simpa using hCn.trans hbound⟩ + +lemma closed_power_bound (q : unitInterval) (n : ℕ) : + (1-(q:ℝ))^n * (1+(n:ℝ)*(q:ℝ)) ≤ 1 := by + induction n with + | zero => simp + | succ n ih => + have hp : 0 ≤ (1-(q:ℝ))^n := pow_nonneg (sub_nonneg.mpr q.2.2) _ + have hn : 0 ≤ (n:ℝ)*(q:ℝ)^2 := mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _) + rw [pow_succ,Nat.cast_add,Nat.cast_one] + nlinarith [mul_nonneg hp hn,mul_nonneg hp (sq_nonneg (q:ℝ))] + +lemma orParameter_gap_bound (p q : unitInterval) (m n : ℕ) (hm : orParameter q m = p) : + (1+(n:ℝ)*(q:ℝ))*(1-(orParameter q (m+n):ℝ)) ≤ 1-(p:ℝ) := by + have hh := mul_le_mul_of_nonneg_left (closed_power_bound q n) (sub_nonneg.mpr p.2.2) + have he : 1-(p:ℝ) = (1-(q:ℝ))^m := by rw [←hm]; simp [orParameter] + rw [he] at hh ⊢ + change (1+(n:ℝ)*(q:ℝ))*(1-(1-(1-(q:ℝ))^(m+n))) ≤ _ + rw [sub_sub_cancel,pow_add] + nlinarith + +end QuantitativeSprinkling +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section QuantitativeOpenness +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem operatorBounded_of_quantitative_gap [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) + (hD : ∀ x, degree G x ≤ D) (p r : unitInterval) + (hp : 0 < p) (hpr : p < r) (hr : r < 1) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) + (hsmall : ((r:ℝ)-(p:ℝ))*(4*D)*‖A‖ < 1-(r:ℝ)) : OperatorBounded G r := by + let a := ((r:ℝ)-(p:ℝ))/(1-(r:ℝ)) + have hden : 0 < 1-(r:ℝ) := sub_pos.mpr hr + have ha : 0 < a := div_pos (sub_pos.mpr hpr) hden + obtain ⟨m,q,hq,hqp⟩ := exists_orParameter_small p (hpr.trans hr) (min a 1) + (lt_min ha zero_lt_one) (min_le_right _ _) + have hq0 : (0:ℝ) < q := by + by_contra hn + have hqe : q = 0 := Subtype.ext ((le_of_not_gt hn).antisymm q.2.1) + have hpe : p = 0 := by rw [←hqp,hqe]; apply Subtype.ext; simp [orParameter] + exact (ne_of_gt hp) hpe + let n := ⌈a/(q:ℝ)⌉₊ + have hna : a ≤ (n:ℝ)*(q:ℝ) := (div_le_iff₀ hq0).mp (Nat.le_ceil _) + have han : (n:ℝ)*(q:ℝ) < a+(q:ℝ) := by + have hn := Nat.ceil_lt_add_one (div_nonneg ha.le hq0.le) + have hh := mul_lt_mul_of_pos_right hn hq0 + dsimp only [n] at * + field_simp at hh + nlinarith + have hn2 : (n:ℝ)*(q:ℝ) < 2*a := by linarith [hq.trans (min_le_left _ _)] + have hbase : (2*a)*(2*D)*‖A‖ < 1 := by + rw [show (2*a)*(2*D)*‖A‖ = (((r:ℝ)-(p:ℝ))*(4*D)*‖A‖)/(1-(r:ℝ)) by dsimp [a]; ring] + exact (div_lt_one hden).mpr hsmall + have hnsmall : (q:ℝ)*(2*D)*(n:ℝ)*‖A‖ < 1 := by + have hs := mul_le_mul_of_nonneg_right hn2.le (show 0 ≤ (2*(D:ℝ))*‖A‖ by positivity) + nlinarith + obtain ⟨B,hB,_⟩ := sprinkling_iterated_bound G hloc q m D hD A (hqp ▸ hA) n hnsmall + apply operatorBounded_of_le G (q := orParameter q (m+n)) ?_ ⟨B,hB⟩ + have hgap := orParameter_gap_bound p q m n hqp + have hae : a*(1-(r:ℝ)) = (r:ℝ)-(p:ℝ) := div_mul_cancel₀ _ (ne_of_gt hden) + have hs := mul_le_mul_of_nonneg_right hna hden.le + change (r:ℝ) ≤ (orParameter q (m+n):ℝ) + nlinarith [mul_nonneg (Nat.cast_nonneg n) q.2.1] + + + +theorem norm_gap_lower_of_endpoint_unbounded [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (D : ℕ) + (hD : ∀ x, degree G x ≤ D) (p r : unitInterval) + (hp : 0 < p) (hpr : p < r) (hr : r < 1) + (A : Hilbert V →L[ℂ] Hilbert V) (hA : HasKernel G p A) + (hu : ¬OperatorBounded G r) : + 1-(r:ℝ) ≤ ((r:ℝ)-(p:ℝ))*(4*D)*‖A‖ := by + by_contra h + exact hu (operatorBounded_of_quantitative_gap G hloc D hD p r hp hpr hr A hA (lt_of_not_ge h)) + +end QuantitativeOpenness +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NormRatio +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def maxSusceptibility (G : BondGraph V E) (p : unitInterval) : ℝ := + sSup (Set.range (susceptibility G p)) + +theorem susceptibility_bddAbove [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : BddAbove (Set.range (susceptibility G p)) := by + obtain ⟨C,_,hC⟩ := subcritical_row_bound G hloc hqt p hp + refine ⟨C,?_⟩ + rintro _ ⟨x,rfl⟩ + exact (summable_twoPoint_subcritical G hloc hqt p hp x).tsum_le_of_sum_le (hC x) + +theorem susceptibility_le_max [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (x : V) : + susceptibility G p x ≤ maxSusceptibility G p := + le_csSup (susceptibility_bddAbove G hloc hqt p hp) (Set.mem_range_self x) + +theorem maxSusceptibility_le [Nonempty V] (G : BondGraph V E) (p : unitInterval) + (C : ℝ) (hC : ∀ x, susceptibility G p x ≤ C) : maxSusceptibility G p ≤ C := by + apply csSup_le (Set.range_nonempty _) + rintro _ ⟨x,rfl⟩ + exact hC x + +theorem maxSusceptibility_one_le [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) : 1 ≤ maxSusceptibility G p := by + let x : V := Classical.choice inferInstance + exact (susceptibility_one_le G hloc hqt p hp x).trans (susceptibility_le_max G hloc hqt p hp x) + +theorem HasKernel.norm_le_maxSusceptibility [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (p : unitInterval) (hp : p < pc G) (T : Hilbert V →L[ℂ] Hilbert V) + (hT : HasKernel G p T) : ‖T‖ ≤ maxSusceptibility G p := + hT.norm_le_susceptibility_bound G hloc hqt p hp T _ + (le_trans zero_le_one (maxSusceptibility_one_le G hloc hqt p hp)) + (susceptibility_le_max G hloc hqt p hp) + +theorem HasKernel.norm_one_le [Countable E] [Nonempty V] + (G : BondGraph V E) (p : unitInterval) (T : Hilbert V →L[ℂ] Hilbert V) + (hT : HasKernel G p T) : 1 ≤ ‖T‖ := by + let x : V := Classical.choice inferInstance + have hd : twoPoint G p x x = 1 := twoPoint_self G p x + have hh := (lp.norm_apply_le_norm (by norm_num : (2:ENNReal) ≠ 0) (T (lp.single 2 x (1:ℂ))) x).trans (T.le_opNorm (lp.single 2 x (1:ℂ))) + simpa [hT x x,hd,lp.norm_single] using hh + +end NormRatio +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SourceNormRatio +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem critical_norm_inverse_lower [Countable V] [Countable E] [Nonempty V] + (G : BondGraph V E) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hp₁ : (pc G:ℝ) < 1) (hu : ¬OperatorBounded G (pc G)) : + ∃ c : ℝ, 0 < c ∧ ∀ (p : unitInterval), 0 < p → p < pc G → + ∀ T : Hilbert V →L[ℂ] Hilbert V, HasKernel G p T → + c/((pc G:ℝ)-(p:ℝ)) ≤ ‖T‖ := by + obtain ⟨D,hDp,hD⟩ := exists_degree_bound G hqt + have hDpos : 0 < (4*(D:ℝ)) := by positivity + refine ⟨(1-(pc G:ℝ))/(4*D),div_pos (sub_pos.mpr hp₁) hDpos,?_⟩ + intro p hp hpq T hT + have hh := norm_gap_lower_of_endpoint_unbounded G hloc D hD p (pc G) hp hpq hp₁ T hT hu + apply (div_le_iff₀ (sub_pos.mpr (show (p:ℝ)<(pc G:ℝ) from hpq))).mpr + apply (div_le_iff₀ hDpos).mpr + nlinarith + + + +theorem critical_normRatio_subpower + [Countable V] [Countable E] [Nonempty V] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (hconn : Connected G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) + {ι : Type*} [Fintype ι] [Nonempty ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ e ∈ Γ, e (root i) = x) + (hw : ∀ i, 0 < weight i) (hw1 : ∑ i, weight i = 1) + (hp₀ : 0 < (pc G:ℝ)) (hp₁ : (pc G:ℝ) < 1) + (hfin : ∀ i, ∀ᵐ ω ∂law (pc G), (cluster G ω (root i)).Finite) + (hu : ¬OperatorBounded G (pc G)) (η : ℝ) (hη : 0 < η) : + ∃ K : ℝ, 0 < K ∧ ∀ (p : unitInterval), (pc G:ℝ)/2 ≤ (p:ℝ) → p < pc G → + ∀ T : Hilbert V →L[ℂ] Hilbert V, HasKernel G p T → + 1 ≤ maxSusceptibility G p/‖T‖ ∧ + maxSusceptibility G p/‖T‖ ≤ K*((pc G:ℝ)-(p:ℝ))^(-η) := by + obtain ⟨c,hc,hm⟩ := critical_norm_inverse_lower G hloc hqt hp₁ hu + obtain ⟨D,hD,hχ⟩ := almost_linear_susceptibility G hloc hconn hqt hh root weight Γ hΓ htr hcov hw hw1 hp₀ hp₁ hfin η hη + refine ⟨D/c,div_pos hD hc,?_⟩ + intro p hp hpq T hT + have hδ : 0 < (pc G:ℝ)-(p:ℝ) := sub_pos.mpr hpq + have hnorm : 0 < ‖T‖ := zero_lt_one.trans_le (hT.norm_one_le G p T) + have hM := hm p ((half_pos hp₀).trans_le hp) hpq T hT + have hχb := maxSusceptibility_le G p _ (hχ p hpq) + have he : ((pc G:ℝ)-(p:ℝ))^(-1-η)*((pc G:ℝ)-(p:ℝ)) = ((pc G:ℝ)-(p:ℝ))^(-η) := by + calc + _ = ((pc G:ℝ)-(p:ℝ))^(-1-η)*((pc G:ℝ)-(p:ℝ))^(1:ℝ) := by rw [Real.rpow_one] + _ = _ := by rw [←Real.rpow_add hδ]; congr 1; ring + refine ⟨(one_le_div hnorm).mpr (hT.norm_le_maxSusceptibility G hloc hqt p hpq T),?_⟩ + calc + maxSusceptibility G p/‖T‖ ≤ (D*((pc G:ℝ)-(p:ℝ))^(-1-η))/(c/((pc G:ℝ)-(p:ℝ))) := + div_le_div₀ (mul_nonneg hD.le (Real.rpow_nonneg hδ.le _)) hχb (div_pos hc hδ) hM + _ = (D/c)*((pc G:ℝ)-(p:ℝ))^(-η) := by rw [←he]; field_simp + +end SourceNormRatio +end Percolation + + +namespace Percolation +universe u +section ChronologicalErasure +open List +variable {V : Type u} +attribute [local instance] Classical.propDecidable Classical.decEq + + + +inductive HoldingWalk (H : SimpleGraph V) : ℕ → V → V → Type u + | nil (x : V) : HoldingWalk H 0 x x + | hold {k : ℕ} {x y : V} (w : HoldingWalk H k x y) : HoldingWalk H (k+1) x y + | step {k : ℕ} {x z y : V} (h : H.Adj x z) (w : HoldingWalk H k z y) : + HoldingWalk H (k+1) x y + +namespace HoldingWalk +variable {H : SimpleGraph V} {k : ℕ} {x y : V} + +def withoutHolds : {k : ℕ} → {x y : V} → HoldingWalk H k x y → H.Walk x y + | _,_,_,.nil _ => .nil + | _,_,_,.hold w => w.withoutHolds + | _,_,_,.step h w => .cons h w.withoutHolds + +def vertices : {k : ℕ} → {x y : V} → HoldingWalk H k x y → List V + | _,x,_,.nil _ => [x] + | _,x,_,.hold w => x :: w.vertices + | _,x,_,.step _ w => x :: w.vertices + +noncomputable def mass (P : V → V → ℝ) : {k : ℕ} → {x y : V} → HoldingWalk H k x y → ℝ + | _,_,_,.nil _ => 1 + | _,x,_,.hold w => P x x * w.mass P + | _,x,_,.step (z := z) _ w => P x z * w.mass P + +theorem mass_nonneg (P : V → V → ℝ) (hP : ∀ a b, 0 ≤ P a b) (w : HoldingWalk H k x y) : + 0 ≤ w.mass P := by + induction w with + | nil => exact zero_le_one + | hold w ih => exact mul_nonneg (hP _ _) ih + | step h w ih => exact mul_nonneg (hP _ _) ih + +theorem length_vertices (w : HoldingWalk H k x y) : w.vertices.length = k+1 := by + induction w with + | nil => rfl + | hold w ih => simpa only [vertices,List.length_cons] using congrArg (fun n => n+1) ih + | step h w ih => simpa only [vertices,List.length_cons] using congrArg (fun n => n+1) ih + +theorem withoutHolds_length (w : HoldingWalk H k x y) : w.withoutHolds.length ≤ k := by + induction w with + | nil => simp [withoutHolds] + | hold w ih => exact ih.trans (Nat.le_succ _) + | step h w ih => simpa only [withoutHolds,SimpleGraph.Walk.length_cons] using Nat.succ_le_succ ih + +theorem withoutHolds_support (w : HoldingWalk H k x y) : w.withoutHolds.support <+ w.vertices := by + induction w with + | nil => exact List.Sublist.refl _ + | hold w ih => exact ih.cons _ + | step h w ih => exact ih.cons_cons _ + + + +noncomputable def erase (w : HoldingWalk H k x y) : H.Walk x y := + w.withoutHolds.reverse.bypass.reverse + +theorem erase_isPath (w : HoldingWalk H k x y) : w.erase.IsPath := + w.withoutHolds.reverse.bypass_isPath.reverse + +theorem erase_length (w : HoldingWalk H k x y) : w.erase.length ≤ k := by + have hh := w.withoutHolds.reverse.length_bypass_le_length + simpa only [erase,SimpleGraph.Walk.length_reverse] using hh.trans (by simpa using w.withoutHolds_length) + +theorem erase_support (w : HoldingWalk H k x y) : w.erase.support <+ w.vertices := by + have hh := w.withoutHolds.reverse.support_bypass_sublist_support.reverse + simp only [SimpleGraph.Walk.support_reverse,List.reverse_reverse] at hh + simpa only [erase,SimpleGraph.Walk.support_reverse] using hh.trans w.withoutHolds_support + +theorem erase_edges (w : HoldingWalk H k x y) : w.erase.edges <+ w.withoutHolds.edges := by + have hh := w.withoutHolds.reverse.edges_bypass_sublist_edges.reverse + simpa only [erase,SimpleGraph.Walk.edges_reverse,List.reverse_reverse] using hh + +end HoldingWalk +end ChronologicalErasure +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CorridorMonotonicity +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def corridorCounted (G : BondGraph V E) (retained blockers : Set E) + (D : Set V) (ω : Set E) (x y : V) : Prop := + Conn G (ω ∩ internalEdges G D) x y ∧ + (∀ e ∈ retained, e ∈ ω ∩ internalEdges G D ∧ + ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y) ∧ + Disjoint blockers (ω ∩ internalEdges G D) + +lemma pivotal_restrict_of_conn (G : BondGraph V E) {S T : Set E} (hST : S ⊆ T) + {x y : V} (hc : Conn G S x y) (e : E) (hp : ¬Conn G (T \ {e}) x y) : + e ∈ S ∧ ¬Conn G (S \ {e}) x y := by + constructor + · by_contra he + apply hp + apply conn_mono G ?_ hc + intro d hd + exact ⟨hST hd,fun hde => he ((Set.mem_singleton_iff.mp hde) ▸ hd)⟩ + · intro h + exact hp (conn_mono G (Set.sdiff_subset_sdiff_left hST) h) + + + +theorem corridorCounted_restrict (G : BondGraph V E) (retained blockers : Set E) + {D D' : Set V} {ω ω' : Set E} (hD : D ⊆ D') (hω : ω ⊆ ω') (x y : V) + (hc : Conn G (ω ∩ internalEdges G D) x y) + (ht : corridorCounted G retained blockers D' ω' x y) : + corridorCounted G retained blockers D ω x y := by + have hs : ω ∩ internalEdges G D ⊆ ω' ∩ internalEdges G D' := + Set.inter_subset_inter hω (internalEdges_mono G hD) + refine ⟨hc,fun e he => pivotal_restrict_of_conn G hs hc e (ht.2.1 e he).2,?_⟩ + exact ht.2.2.mono_right hs + +lemma corridorCounted_symm (G : BondGraph V E) (retained blockers : Set E) + (D : Set V) (ω : Set E) (x y : V) : + corridorCounted G retained blockers D ω x y ↔ corridorCounted G retained blockers D ω y x := by + constructor <;> rintro ⟨hc,hp,hb⟩ + · exact ⟨conn_symm G _ hc,fun e he => ⟨(hp e he).1,fun hc => (hp e he).2 (conn_symm G _ hc)⟩,hb⟩ + · exact ⟨conn_symm G _ hc,fun e he => ⟨(hp e he).1,fun hc => (hp e he).2 (conn_symm G _ hc)⟩,hb⟩ + + + +theorem measurableSet_corridorCounted [Countable E] (G : BondGraph V E) + (retained blockers : Set E) (D : Set V) (x y : V) : + MeasurableSet {ω | corridorCounted G retained blockers D ω x y} := by + have hmem (e : E) : MeasurableSet {ω : Set E | e ∈ ω ∩ internalEdges G D} := by + by_cases he : e ∈ internalEdges G D + · simpa only [Set.mem_inter_iff,he,and_true] using measurableSet_mem e + · simp only [Set.mem_inter_iff,he,and_false,Set.ofPred_false]; exact MeasurableSet.empty + have hp (e : E) : MeasurableSet {ω : Set E | e ∈ ω ∩ internalEdges G D ∧ + ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y} := by + apply (hmem e).inter + have heq (ω : Set E) : (ω ∩ internalEdges G D) \ {e} = ω ∩ (internalEdges G D \ {e}) := by + ext d; simp only [Set.mem_inter_iff,Set.mem_sdiff]; tauto + simp_rw [heq] + exact (measurableSet_restrictedConn G _ x y).compl + have hb : MeasurableSet {ω : Set E | Disjoint blockers (ω ∩ internalEdges G D)} := by + simp only [Set.disjoint_left,Set.ofPred_forall] + exact MeasurableSet.iInter (fun e => MeasurableSet.iInter (fun (_ : e ∈ blockers) => (hmem e).compl)) + have hkeep : MeasurableSet {ω : Set E | ∀ e ∈ retained, e ∈ ω ∩ internalEdges G D ∧ + ¬Conn G ((ω ∩ internalEdges G D) \ {e}) x y} := by + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter (fun e => MeasurableSet.iInter (fun (_ : e ∈ retained) => hp e)) + exact (measurableSet_restrictedConn G _ x y).inter (hkeep.inter hb) + +end CorridorMonotonicity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section LiteralCorridors +attribute [local instance] Classical.propDecidable Classical.decEq + +instance HoldingWalk.countable [Countable V] (H : SimpleGraph V) (k : ℕ) (x y : V) : + Countable (HoldingWalk H k x y) := by + induction k generalizing x y with + | zero => + apply Function.Injective.countable (f := fun _ : HoldingWalk H 0 x y => ()) + intro a b _ + cases a + cases b + rfl + | succ k ih => + let (a b : V) : Countable (HoldingWalk H k a b) := ih a b + let f : HoldingWalk H (k+1) x y → + HoldingWalk H k x y ⊕ (Σ z : {z // H.Adj x z}, HoldingWalk H k z.val y) + | .hold w => .inl w + | .step (z := z) h w => .inr ⟨⟨z,h⟩,w⟩ + apply Function.Injective.countable (f := f) + intro a b hab + cases a with + | hold a => + cases b with + | hold b => exact congrArg HoldingWalk.hold (Sum.inl.inj hab) + | step h b => cases hab + | @step _ _ z _ h a => + cases b with + | hold b => cases hab + | @step _ _ z' _ h' b => + have he := Sum.inr.inj hab + have hz := congrArg (fun t => t.1.val) he + change z = z' at hz + subst z' + have hab' : a = b := by simpa only [Sigma.mk.inj_iff,heq_eq_eq,true_and] using he + subst b + rfl + + +abbrev RawCorridor (G : BondGraph V E) (k : ℕ) := + Σ x y : V, HoldingWalk (openSimpleGraph G Set.univ) k x y + +namespace RawCorridor +variable {G : BondGraph V E} {k : ℕ} + +def base (w : RawCorridor G k) : V := w.1 +def endpoint (w : RawCorridor G k) : V := w.2.1 +noncomputable def path (w : RawCorridor G k) : + (openSimpleGraph G Set.univ).Walk w.base w.endpoint := w.2.2.erase +noncomputable def interior (w : RawCorridor G k) : Finset V := + w.path.support.toFinset \ {w.base,w.endpoint} +def retained (w : RawCorridor G k) : Set E := {e | G e ∈ w.path.edges} +noncomputable def blockers (w : RawCorridor G k) : Set E := + {e | ∃ z ∈ w.interior, z ∈ G e} \ w.retained +noncomputable def probability (P : V → V → ℝ) (w : RawCorridor G k) : ℝ := w.2.2.mass P +noncomputable def weight (P : V → V → ℝ) (p : ℝ) (w : RawCorridor G k) : ℝ := + w.probability P * (p^w.path.length)⁻¹ * ((1-p)^w.blockers.ncard)⁻¹ + +theorem path_isPath (w : RawCorridor G k) : w.path.IsPath := w.2.2.erase_isPath + +theorem path_length (w : RawCorridor G k) : w.path.length ≤ k := w.2.2.erase_length + +theorem retained_finite (hG : Function.Injective G) (w : RawCorridor G k) : w.retained.Finite := + (List.finite_toSet w.path.edges).preimage hG.injOn + +theorem blockers_finite (hloc : LocallyFinite G) (w : RawCorridor G k) : w.blockers.Finite := by + apply Set.Finite.subset (s := (incidentSupport G hloc w.interior : Set E)) (Finset.finite_toSet _) + intro e he + exact (mem_incidentSupport G hloc w.interior e).mpr he.1 + +theorem retained_disjoint_blockers (w : RawCorridor G k) : Disjoint w.retained w.blockers := by + exact Set.disjoint_left.mpr (fun e he hb => hb.2 he) + +theorem weight_nonneg (P : V → V → ℝ) (hP : ∀ x y, 0 ≤ P x y) + (p : unitInterval) (w : RawCorridor G k) : 0 ≤ w.weight P p := by + exact mul_nonneg (mul_nonneg (w.2.2.mass_nonneg P hP) (inv_nonneg.mpr (pow_nonneg p.2.1 _))) + (inv_nonneg.mpr (pow_nonneg (sub_nonneg.mpr p.2.2) _)) + +end RawCorridor +end LiteralCorridors +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Main.lean b/lean/OAI/Probability/UnimodularPercolation/Main.lean index 3032a0f771039ca88071b90304a8976ec29bccb3..be76339a5626383fefb6e1d54bb220cdabdc56ff 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Main.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Main.lean @@ -1,2 +1,2 @@ -import OAI.Probability.UnimodularPercolation.Criticality.Operator -import OAI.Probability.UnimodularPercolation.Subdivision.Operator +import OAI.Probability.UnimodularPercolation.Criticality.Operator +import OAI.Probability.UnimodularPercolation.Subdivision.Operator diff --git a/lean/OAI/Probability/UnimodularPercolation/ProductMeasure/Association.lean b/lean/OAI/Probability/UnimodularPercolation/ProductMeasure/Association.lean index 650d99c1c6ddcbe0c7ebd7f1e6d95edec7f89fac..2d60b090e30e95ebd16e1ea65fcd2d17da876be9 100644 --- a/lean/OAI/Probability/UnimodularPercolation/ProductMeasure/Association.lean +++ b/lean/OAI/Probability/UnimodularPercolation/ProductMeasure/Association.lean @@ -1,1094 +1,1094 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Bounds - -namespace OAI - -/-! Association, disjoint witnesses and the BK inequality. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteAssociation -attribute [local instance] Classical.propDecidable -variable [Fintype E] - -private theorem bernoulli_atom_product (p : unitInterval) (ω : Set E) : - (law p).real {ω} = ∏ e : E, if e ∈ ω then (p : ℝ) else 1 - p := by - rw [law, setBernoulli_real_singleton p (Set.subset_univ ω) (Set.finite_univ)] - simp [Finset.prod_ite, ← Set.ncard_coe_finset, Set.sdiff_eq] - exact Or.inl rfl - -private theorem bernoulli_atom_modular (p : unitInterval) (a b : Set E) : - (law p).real {a} * (law p).real {b} = - (law p).real {a ∩ b} * (law p).real {a ∪ b} := by - simp only [bernoulli_atom_product, ← Finset.prod_mul_distrib] - apply Finset.prod_congr rfl - intro e _ - by_cases ha : e ∈ a <;> by_cases hb : e ∈ b <;> simp [ha, hb, mul_comm] - - - -theorem association_finite (p : unitInterval) (f g : Set E → ℝ) - (hf : Monotone f) (hg : Monotone g) (hf0 : ∀ ω, 0 ≤ f ω) (hg0 : ∀ ω, 0 ≤ g ω) : - (∫ ω, f ω ∂law p) * (∫ ω, g ω ∂law p) ≤ ∫ ω, f ω * g ω ∂law p := by - have h := fkg f g (fun ω : Set E => (law p).real {ω}) - (fun _ => measureReal_nonneg) hf0 hg0 hf hg - (fun a b => (bernoulli_atom_modular p a b).le) - have hsum : (∑ ω : Set E, (law p).real {ω}) = 1 := by - simp - rw [hsum, one_mul] at h - simpa only [integral_fintype Integrable.of_finite, smul_eq_mul] using h - - -theorem association_events_finite (p : unitInterval) (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) : - (law p).real A * (law p).real B ≤ (law p).real (A ∩ B) := by - have hm (S : Set (Set E)) (hS : IsUpperSet S) : - Monotone (S.indicator (fun _ => (1 : ℝ))) := by - intro a b hab - by_cases ha : a ∈ S - · simp [ha, hS hab ha] - · simp only [Set.indicator_of_notMem ha] - exact Set.indicator_nonneg (fun _ _ => zero_le_one) _ - have he : (fun ω => A.indicator (fun _ => (1 : ℝ)) ω * - B.indicator (fun _ => (1 : ℝ)) ω) = (A ∩ B).indicator (fun _ => 1) := by - funext ω - by_cases ha : ω ∈ A <;> by_cases hb : ω ∈ B <;> simp [ha, hb] - have h := association_finite p _ _ (hm A hA) (hm B hB) - (Set.indicator_nonneg (fun _ _ => zero_le_one)) - (Set.indicator_nonneg (fun _ _ => zero_le_one)) - rw [he] at h - simpa only [integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet A), - integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet B), - integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet (A ∩ B)), - smul_eq_mul, mul_one] using h - -end FiniteAssociation - -section Restriction - -theorem measurable_set_restrict (s : Set E) : - Measurable (fun ω : Set E => (Subtype.val ⁻¹' ω : Set s)) := - measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_pi_apply e.val).comp MeasurableEquiv.setOfPred.symm.measurable)) - - -theorem law_map_restrict (p : unitInterval) (s : Set E) : - (law p : Measure (Set E)).map (fun ω => (Subtype.val ⁻¹' ω : Set s)) = law p := by - have hm := measurable_set_restrict s - unfold law - rw [setBernoulli_eq_map, Measure.map_map hm measurable_setOfPred] - have he : (fun ω : Set E => (Subtype.val ⁻¹' ω : Set s)) ∘ - (fun f : E → Prop => {e | f e}) = - (fun f : s → Prop => {e | f e}) ∘ s.domRestrict := rfl - rw [he, ← Measure.map_map measurable_setOfPred (by fun_prop), - Measure.infinitePi_map_restrict', setBernoulli_eq_map] - simp only [Set.mem_univ] - -end Restriction - -section WitnessAssociation -attribute [local instance] Classical.propDecidable -open Filter Topology - - -def FiniteWitness (A : Set (Set E)) : Prop := - ∀ ω ∈ A, ∃ s : Finset E, (s : Set E) ⊆ ω ∧ (s : Set E) ∈ A - -theorem association_restricted (p : unitInterval) (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) (s : Finset E) : - (law p).real {ω | ω ∩ (s : Set E) ∈ A} * - (law p).real {ω | ω ∩ (s : Set E) ∈ B} ≤ - (law p).real {ω | ω ∩ (s : Set E) ∈ A ∩ B} := by - let A' : Set (Set (s : Set E)) := {η | Subtype.val '' η ∈ A} - let B' : Set (Set (s : Set E)) := {η | Subtype.val '' η ∈ B} - have hA' : IsUpperSet A' := fun _ _ h ha => hA (Set.image_mono h) ha - have hB' : IsUpperSet B' := fun _ _ h hb => hB (Set.image_mono h) hb - have he (ω : Set E) : Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) = - ω ∩ (s : Set E) := by - ext e - simp [and_comm] - have hl (C : Set (Set E)) : - (law p : Measure (Set (s : Set E))).real {η | Subtype.val '' η ∈ C} = - (law p).real {ω | ω ∩ (s : Set E) ∈ C} := by - rw [← law_map_restrict p (s : Set E), measureReal_def, - Measure.map_apply (measurable_set_restrict _) .of_discrete] - simp only [Set.preimage_ofPred_eq, he, measureReal_def] - have ht := association_events_finite p A' B' hA' hB' - change (law p).real {η | Subtype.val '' η ∈ A} * - (law p).real {η | Subtype.val '' η ∈ B} ≤ - (law p).real {η | Subtype.val '' η ∈ A ∩ B} at ht - simpa only [hl] using ht - - noncomputable def edgeExhaustion [Encodable E] (n : ℕ) : Finset E := - (Finset.range n).preimage Encodable.encode Encodable.encode_injective.injOn - - theorem edgeExhaustion_mono [Encodable E] : - Monotone (edgeExhaustion : ℕ → Finset E) := by - intro m n h e he - simp only [edgeExhaustion, Finset.mem_preimage, Finset.mem_range] at he ⊢ - exact he.trans_le h - -private theorem subset_edgeExhaustion [Encodable E] (s : Finset E) : - ∃ n, s ⊆ edgeExhaustion n := by - refine ⟨s.sup Encodable.encode + 1, ?_⟩ - intro e he - simp only [edgeExhaustion, Finset.mem_preimage, Finset.mem_range] - exact Nat.lt_succ_of_le (Finset.le_sup he) - - theorem witness_eq_union [Encodable E] (A : Set (Set E)) - (hA : IsUpperSet A) (hf : FiniteWitness A) : - A = ⋃ n, {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ A} := by - ext ω - simp only [Set.mem_iUnion, Set.mem_ofPred_eq] - constructor - · intro hω - obtain ⟨s, hs, hsa⟩ := hf ω hω - obtain ⟨n, hn⟩ := subset_edgeExhaustion s - exact ⟨n, hA (fun _ he => ⟨hs he, hn he⟩) hsa⟩ - · rintro ⟨n, hn⟩ - exact hA Set.inter_subset_left hn - - - -theorem association_finiteWitness [Countable E] (p : unitInterval) - (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) - (hfA : FiniteWitness A) (hfB : FiniteWitness B) : - (law p).real A * (law p).real B ≤ (law p).real (A ∩ B) := by - let := Encodable.ofCountable E - have hfAB : FiniteWitness (A ∩ B) := by - intro ω hω - obtain ⟨s, hs, hsa⟩ := hfA ω hω.1 - obtain ⟨t, ht, htb⟩ := hfB ω hω.2 - refine ⟨s ∪ t, ?_, hA ?_ hsa, hB ?_ htb⟩ - · simpa only [Finset.coe_union] using Set.union_subset hs ht - · simp only [Finset.coe_union]; exact Set.subset_union_left - · simp only [Finset.coe_union]; exact Set.subset_union_right - have hlim (C : Set (Set E)) (hC : IsUpperSet C) (hfC : FiniteWitness C) : - Tendsto (fun n => (law p).real {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) - atTop (𝓝 ((law p).real C)) := by - have hm : Monotone (fun n => {ω : Set E | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) := by - intro m n h ω hω - exact hC (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω - have h := tendsto_measure_iUnion_atTop (μ := law p) hm - rw [← witness_eq_union C hC hfC] at h - exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h - exact le_of_tendsto_of_tendsto - ((hlim A hA hfA).mul (hlim B hB hfB)) (hlim (A ∩ B) (hA.inter hB) hfAB) - (Filter.Eventually.of_forall fun n => association_restricted p A B hA hB (edgeExhaustion n)) - -end WitnessAssociation - -section ClusterEvents -attribute [local instance] Classical.propDecidable -open Filter Topology - - -theorem measurableSet_finiteWitness [Countable E] (A : Set (Set E)) - (hA : IsUpperSet A) (hfA : FiniteWitness A) : MeasurableSet A := by - let := Encodable.ofCountable E - rw [witness_eq_union A hA hfA] - apply MeasurableSet.iUnion - intro n - let s := edgeExhaustion (E := E) n - have he : {ω : Set E | ω ∩ (s : Set E) ∈ A} = - (fun ω => (Subtype.val ⁻¹' ω : Set (s : Set E))) ⁻¹' - {η | Subtype.val '' η ∈ A} := by - ext ω - change ω ∩ (s : Set E) ∈ A ↔ Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) ∈ A - have hi : Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) = ω ∩ (s : Set E) := by - ext e - simp [and_comm] - rw [hi] - change MeasurableSet {ω : Set E | ω ∩ (s : Set E) ∈ A} - rw [he] - exact MeasurableSet.preimage .of_discrete (measurable_set_restrict _) - -theorem finiteWitness_conn (G : BondGraph V E) (x y : V) : - FiniteWitness {ω | Conn G ω x y} := by - intro ω h - induction h with - | refl => exact ⟨∅, by simp, by simp⟩ - | @tail b c hab hbc ih => - obtain ⟨s, hs, hconn⟩ := ih - obtain ⟨e, he, hGe⟩ := hbc - refine ⟨insert e s, ?_, ?_⟩ - · simpa only [Finset.coe_insert] using Set.insert_subset he hs - · exact (conn_mono G (by simp) hconn).tail ⟨e, by simp, hGe⟩ - -theorem finiteWitness_conn_finset (G : BondGraph V E) (x : V) (t : Finset V) : - FiniteWitness {ω | ∀ y ∈ t, Conn G ω x y} := by - intro ω h - induction t using Finset.induction_on with - | empty => exact ⟨∅, by simp, by simp⟩ - | @insert a t ha ih => - obtain ⟨s, hs, hsa⟩ := finiteWitness_conn G x a ω (h a (by simp)) - obtain ⟨r, hr, hrt⟩ := ih (fun y hy => h y (by simp [hy])) - refine ⟨s ∪ r, ?_, ?_⟩ - · simpa only [Finset.coe_union] using Set.union_subset hs hr - · intro y hy - rcases Finset.mem_insert.mp hy with rfl | hy - · exact conn_mono G (by simp) hsa - · exact conn_mono G (by simp) (hrt y hy) - - -def clusterLarge (G : BondGraph V E) (x : V) (n : ℕ) : Set (Set E) := - {ω | ∃ t : Finset V, n ≤ t.card ∧ ∀ y ∈ t, Conn G ω x y} - -theorem clusterLarge_upper (G : BondGraph V E) (x : V) (n : ℕ) : - IsUpperSet (clusterLarge G x n) := by - rintro ω η h ⟨t, ht, hc⟩ - exact ⟨t, ht, fun y hy => conn_mono G h (hc y hy)⟩ - -theorem finiteWitness_clusterLarge (G : BondGraph V E) (x : V) (n : ℕ) : - FiniteWitness (clusterLarge G x n) := by - rintro ω ⟨t, ht, hc⟩ - obtain ⟨s, hs, hsc⟩ := finiteWitness_conn_finset G x t ω hc - exact ⟨s, hs, t, ht, hsc⟩ - -theorem measurableSet_clusterLarge [Countable E] (G : BondGraph V E) (x : V) (n : ℕ) : - MeasurableSet (clusterLarge G x n) := - measurableSet_finiteWitness _ (clusterLarge_upper G x n) (finiteWitness_clusterLarge G x n) - -theorem clusterLarge_antitone (G : BondGraph V E) (x : V) : - Antitone (clusterLarge G x) := by - rintro m n h ω ⟨t, ht, hc⟩ - exact ⟨t, h.trans ht, hc⟩ - -theorem infinite_cluster_eq_iInter (G : BondGraph V E) (x : V) : - {ω | (cluster G ω x).Infinite} = ⋂ n, clusterLarge G x n := by - ext ω - simp only [Set.mem_iInter, Set.mem_ofPred_eq] - constructor - · intro h n - obtain ⟨t, ht, hcard⟩ := h.exists_subset_card_eq n - exact ⟨t, hcard.ge, ht⟩ - · intro h hfin - obtain ⟨t, ht, hc⟩ := h (hfin.toFinset.card + 1) - have hsub : t ⊆ hfin.toFinset := fun y hy => hfin.mem_toFinset.mpr (hc y hy) - have := Finset.card_le_card hsub - omega - -theorem measurableSet_infinite_cluster [Countable E] (G : BondGraph V E) (x : V) : - MeasurableSet {ω | (cluster G ω x).Infinite} := by - rw [infinite_cluster_eq_iInter] - exact MeasurableSet.iInter (measurableSet_clusterLarge G x) - - -theorem association_decreasing [Countable E] (p : unitInterval) - (A B : ℕ → Set (Set E)) (hA : Antitone A) (hB : Antitone B) - (huA : ∀ n, IsUpperSet (A n)) (huB : ∀ n, IsUpperSet (B n)) - (hfA : ∀ n, FiniteWitness (A n)) (hfB : ∀ n, FiniteWitness (B n)) : - (law p).real (⋂ n, A n) * (law p).real (⋂ n, B n) ≤ - (law p).real ((⋂ n, A n) ∩ (⋂ n, B n)) := by - have hlim (C : ℕ → Set (Set E)) (hm : Antitone C) (hC : ∀ n, MeasurableSet (C n)) : - Tendsto (fun n => (law p).real (C n)) atTop (𝓝 ((law p).real (⋂ n, C n))) := - (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp - (tendsto_measure_iInter_atTop (fun n => (hC n).nullMeasurableSet) hm - ⟨0, measure_ne_top _ _⟩) - have hmA n := measurableSet_finiteWitness (A n) (huA n) (hfA n) - have hmB n := measurableSet_finiteWitness (B n) (huB n) (hfB n) - have h := le_of_tendsto_of_tendsto ((hlim A hA hmA).mul (hlim B hB hmB)) - (hlim (fun n => A n ∩ B n) (fun m n h => Set.inter_subset_inter (hA h) (hB h)) - (fun n => (hmA n).inter (hmB n))) - (Filter.Eventually.of_forall fun n => - association_finiteWitness p (A n) (B n) (huA n) (huB n) (hfA n) (hfB n)) - simpa only [Set.iInter_inter_distrib] using h - - - -theorem association_infinite_cluster [Countable E] - (G : BondGraph V E) (p : unitInterval) (x y : V) : - (law p).real {ω | (cluster G ω x).Infinite} * - (law p).real {ω | (cluster G ω y).Infinite} ≤ - (law p).real {ω | (cluster G ω x).Infinite ∧ (cluster G ω y).Infinite} := by - rw [infinite_cluster_eq_iInter, infinite_cluster_eq_iInter] - change _ ≤ (law p).real ({ω | (cluster G ω x).Infinite} ∩ - {ω | (cluster G ω y).Infinite}) - rw [infinite_cluster_eq_iInter, infinite_cluster_eq_iInter] - exact association_decreasing p _ _ (clusterLarge_antitone G x) (clusterLarge_antitone G y) - (clusterLarge_upper G x) (clusterLarge_upper G y) - (finiteWitness_clusterLarge G x) (finiteWitness_clusterLarge G y) - -end ClusterEvents - -section Automorphisms -attribute [local instance] Classical.propDecidable - -theorem measurable_set_preimage (b : E ≃ E) : - Measurable (fun ω : Set E => b ⁻¹' ω) := - measurable_setOfPred.comp (Measurable.of_eval - (fun e => (measurable_pi_apply (b e)).comp MeasurableEquiv.setOfPred.symm.measurable)) - - -theorem law_map_preimage_equiv (p : unitInterval) (b : E ≃ E) : - (law p : Measure (Set E)).map (fun ω => b ⁻¹' ω) = law p := by - unfold law - rw [setBernoulli_eq_map, Measure.map_map (measurable_set_preimage b) measurable_setOfPred] - have he : (fun ω : Set E => b ⁻¹' ω) ∘ (fun f : E → Prop => {e | f e}) = - (fun f : E → Prop => {e | f e}) ∘ - MeasurableEquiv.piCongrLeft (fun _ : E => Prop) b.symm := by - funext f - ext e - simp only [Function.comp_apply, Set.mem_preimage, Set.mem_ofPred_eq] - have hh := MeasurableEquiv.piCongrLeft_apply_apply (β := fun _ : E => Prop) b.symm f (b e) - exact iff_of_eq (by simpa only [Equiv.symm_apply_apply] using hh.symm) - rw [he, ← Measure.map_map measurable_setOfPred (MeasurableEquiv.measurable _)] - simp only [Set.mem_univ] - congr 1 - exact Measure.infinitePi_map_piCongrLeft - (fun _ : E => unitInterval.toNNReal p • Measure.dirac True + - unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False) b.symm - -theorem isAut_symm (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) : IsAut G a.symm b.symm := by - intro e - have hh := congrArg (Sym2.map a.symm) (h (b.symm e)) - simpa only [Equiv.apply_symm_apply, Sym2.map_map, Equiv.symm_comp_self, - Sym2.map_id', id_eq] using hh.symm - -theorem conn_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) {ω : Set E} {x y : V} (hc : Conn G ω x y) : - Conn G (b '' ω) (a x) (a y) := by - induction hc with - | refl => exact conn_refl G _ _ - | @tail v w hvw hed ih => - obtain ⟨e, he, hGe⟩ := hed - exact ih.tail ⟨b e, Set.mem_image_of_mem _ he, by rw [h e, hGe, Sym2.map_mk]⟩ - -theorem conn_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (ω : Set E) (x y : V) : - Conn G (b ⁻¹' ω) x y ↔ Conn G ω (a x) (a y) := by - constructor - · intro hc - simpa only [Set.image_preimage_eq _ b.surjective] using conn_aut G h hc - · intro hc - have he : b.symm '' ω = b ⁻¹' ω := by - ext e - simp - simpa only [Equiv.symm_apply_apply, he] using - conn_aut G (isAut_symm G h) hc - -theorem cluster_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (h : IsAut G a b) (ω : Set E) (x : V) : - a '' cluster G (b ⁻¹' ω) x = cluster G ω (a x) := by - ext y - constructor - · rintro ⟨z, hz, rfl⟩ - exact (conn_aut_iff G h ω x z).mp hz - · intro hy - change Conn G ω (a x) y at hy - refine ⟨a.symm y, ?_, by simp⟩ - exact (conn_aut_iff G h ω x (a.symm y)).mpr (by simpa only [Equiv.apply_symm_apply] using hy) - -theorem infinite_cluster_aut [Countable E] (G : BondGraph V E) (p : unitInterval) - {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : - (law p).real {ω | (cluster G ω (a x)).Infinite} = - (law p).real {ω | (cluster G ω x).Infinite} := by - have he : {ω | (cluster G ω (a x)).Infinite} = - (fun ω => b ⁻¹' ω) ⁻¹' {ω | (cluster G ω x).Infinite} := by - ext ω - change (cluster G ω (a x)).Infinite ↔ (cluster G (b ⁻¹' ω) x).Infinite - rw [← cluster_aut G h] - exact Set.infinite_image_iff (fun _ _ _ _ hab => a.injective hab) - unfold Measure.real - rw [he, ← Measure.map_apply (measurable_set_preimage b) - (measurableSet_infinite_cluster G x), law_map_preimage_equiv] - - -theorem finite_open_probability (p : unitInterval) (s : Finset E) : - (law p).real {ω | (s : Set E) ⊆ ω} = (p : ℝ) ^ s.card := by - have he : {ω : Set E | (s : Set E) ⊆ ω} = - (fun ω => (Subtype.val ⁻¹' ω : Set (s : Set E))) ⁻¹' {Set.univ} := by - ext ω - simp only [Set.mem_ofPred_eq, Set.mem_preimage, Set.mem_singleton_iff] - exact ⟨fun h => Set.eq_univ_of_forall fun e => h e.property, - fun h e he => show (⟨e, he⟩ : (s : Set E)) ∈ (Subtype.val ⁻¹' ω) from - h.symm ▸ Set.mem_univ _⟩ - unfold Measure.real - rw [he, ← Measure.map_apply (measurable_set_restrict _) (by measurability), - law_map_restrict] - change (law p : Measure (Set (s : Set E))).real {Set.univ} = _ - simp [law, setBernoulli_real_singleton p (Set.Subset.refl _) (Set.toFinite _)] - -theorem twoPoint_pos [Countable E] (G : BondGraph V E) (hG : Connected G) - (p : unitInterval) (hp : 0 < p) (x y : V) : 0 < twoPoint G p x y := by - obtain ⟨s, _, hs⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hG x y) - have hpos : 0 < (law p).real {ω | (s : Set E) ⊆ ω} := by - rw [finite_open_probability] - exact pow_pos hp _ - apply lt_of_lt_of_le hpos - exact measureReal_mono (fun _ hω => conn_mono G hω hs) - -end Automorphisms - -section UniquenessThreshold -attribute [local instance] Classical.propDecidable -variable [Countable V] [Countable E] - -omit [Countable V] in - -theorem association_infinite_conn (G : BondGraph V E) (p : unitInterval) (x y z : V) : - (law p).real {ω | (cluster G ω x).Infinite} * twoPoint G p y z ≤ - (law p).real {ω | (cluster G ω x).Infinite ∧ Conn G ω y z} := by - have h := association_decreasing p (clusterLarge G x) (fun _ => {ω | Conn G ω y z}) - (clusterLarge_antitone G x) antitone_const (clusterLarge_upper G x) - (fun _ _ _ hsub hconn => conn_mono G hsub hconn) (finiteWitness_clusterLarge G x) - (fun _ => finiteWitness_conn G y z) - simpa only [← infinite_cluster_eq_iInter, Set.iInter_const, twoPoint, Measure.real, Set.inter_def, Set.mem_ofPred_eq] using h - -omit [Countable V] in -theorem survival_pos_of_survival_pos (G : BondGraph V E) (hG : Connected G) - (p : unitInterval) (hp : 0 < p) {x : V} - (hx : 0 < (law p).real {ω | (cluster G ω x).Infinite}) (y : V) : - 0 < (law p).real {ω | (cluster G ω y).Infinite} := by - apply lt_of_lt_of_le (mul_pos hx (twoPoint_pos G hG p hp x y)) - refine (association_infinite_conn G p x x y).trans (measureReal_mono ?_) - rintro ω ⟨hi, hc⟩ - change (cluster G ω y).Infinite - rwa [← cluster_eq_of_conn G ω hc] - -omit [Countable V] [Countable E] in -theorem exists_infinite_cluster_iff (G : BondGraph V E) (ω : Set E) : - (infiniteClusters G ω).Nonempty ↔ ∃ x, (cluster G ω x).Infinite := by - constructor - · rintro ⟨C, hi, x, rfl⟩ - exact ⟨x, hi⟩ - · rintro ⟨x, hx⟩ - exact ⟨cluster G ω x, hx, x, rfl⟩ - -omit [Countable V] [Countable E] in -theorem unique_infinite_cluster_iff (G : BondGraph V E) (ω : Set E) : - (∃! C, C ∈ infiniteClusters G ω) ↔ - ∃ x, (cluster G ω x).Infinite ∧ ∀ y, (cluster G ω y).Infinite → Conn G ω x y := by - constructor - · rintro ⟨C, ⟨hi, x, rfl⟩, hu⟩ - refine ⟨x, hi, fun y hy => ?_⟩ - have he := hu (cluster G ω y) ⟨hy, y, rfl⟩ - have hm := mem_cluster_self G ω y - rwa [he] at hm - · rintro ⟨x, hx, hu⟩ - refine ⟨cluster G ω x, ⟨hx, x, rfl⟩, ?_⟩ - rintro C ⟨hi, y, rfl⟩ - exact (cluster_eq_of_conn G ω (hu y hi)).symm - -theorem measurableSet_unique_infinite_cluster (G : BondGraph V E) : - MeasurableSet {ω | ∃! C, C ∈ infiniteClusters G ω} := by - have he : {ω | ∃! C, C ∈ infiniteClusters G ω} = - ⋃ x, ({ω | (cluster G ω x).Infinite} ∩ - ⋂ y, ({ω | (cluster G ω y).Infinite}ᶜ ∪ {ω | Conn G ω x y})) := by - ext ω - simp only [Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_inter_iff, - Set.mem_iInter, Set.mem_union, Set.mem_compl_iff, unique_infinite_cluster_iff, - imp_iff_not_or] - rw [he] - exact MeasurableSet.iUnion fun x => (measurableSet_infinite_cluster G x).inter - (MeasurableSet.iInter fun y => - (measurableSet_infinite_cluster G y).compl.union (measurableSet_conn G x y)) - -theorem uniform_survival_pos (G : BondGraph V E) (hconn : Connected G) - (hqt : QuasiTransitive G) (p : unitInterval) (hp : 0 < p) - (hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty}) : - ∃ θ : ℝ, 0 < θ ∧ ∀ x, θ ≤ (law p).real {ω | (cluster G ω x).Infinite} := by - have hunion : {ω | (infiniteClusters G ω).Nonempty} = - ⋃ x, {ω | (cluster G ω x).Infinite} := by - ext ω - simp only [Set.mem_ofPred_eq, Set.mem_iUnion, exists_infinite_cluster_iff] - rw [hunion] at hpos - obtain ⟨x, hx⟩ := exists_measure_pos_of_not_measure_iUnion_null (ne_of_gt hpos) - have hxp : 0 < (law p).real {ω | (cluster G ω x).Infinite} := - ENNReal.toReal_pos hx.ne' (measure_ne_top _ _) - have hroot := survival_pos_of_survival_pos G hconn p hp hxp - obtain ⟨s, hs⟩ := hqt - have hsn : s.Nonempty := by obtain ⟨o, ho, _⟩ := hs x; exact ⟨o, ho⟩ - let vals := s.image (fun o => (law p).real {ω | (cluster G ω o).Infinite}) - have hv : vals.Nonempty := hsn.image _ - refine ⟨vals.min' hv, ?_, fun y => ?_⟩ - · obtain ⟨o, _, he⟩ := Finset.mem_image.mp (Finset.min'_mem vals hv) - rw [← he] - exact hroot o - · obtain ⟨o, ho, a, b, ha, hay⟩ := hs y - rw [← hay, infinite_cluster_aut G p ha] - exact Finset.min'_le _ _ (Finset.mem_image.mpr ⟨o, ho, rfl⟩) - - - -theorem not_operatorBounded_of_unique [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hqt : QuasiTransitive G) (p : unitInterval) - (hu : law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 1) : ¬ OperatorBounded G p := by - have hp : 0 < p := by - by_contra h - have hp0 : p = 0 := le_antisymm (not_lt.mp h) (bot_le) - subst p - simp [law] at hu - have hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty} := by - exact lt_of_lt_of_le (show 0 < law p {ω | ∃! C, C ∈ infiniteClusters G ω} by rw [hu]; exact zero_lt_one) - (measure_mono fun ω hω => ⟨hω.choose, hω.choose_spec.1⟩) - obtain ⟨θ, hθ, hroot⟩ := uniform_survival_pos G hconn hqt p hp hpos - have hue : ∀ᵐ ω ∂law p, ∃! C, C ∈ infiniteClusters G ω := - (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu - refine not_operatorBounded_of_positive_column G p (Classical.arbitrary V) (mul_pos hθ hθ) - (fun x => ?_) - refine (mul_le_mul (hroot x) (hroot (Classical.arbitrary V)) hθ.le measureReal_nonneg).trans - ((association_infinite_cluster G p x (Classical.arbitrary V)).trans ?_) - apply ENNReal.toReal_mono (measure_ne_top _ _) - apply measure_mono_ae - filter_upwards [hue] with ω hω - intro hi - obtain ⟨r, _, hconnr⟩ := (unique_infinite_cluster_iff G ω).mp hω - exact conn_trans G ω (conn_symm G ω (hconnr x hi.1)) (hconnr _ hi.2) - - - -theorem ptwo_le_pu [Infinite V] (G : BondGraph V E) - (hconn : Connected G) (hqt : QuasiTransitive G) : ptwo G ≤ pu G := by - unfold pu ptwo - apply le_sInf - intro p hp - apply sSup_le - intro q hq - by_contra hqp - have hb := operatorBounded_of_le G (le_of_lt (not_le.mp hqp)) hq - exact not_operatorBounded_of_unique G hconn hqt p hp hb - -end UniquenessThreshold - -section DisjointWitness -attribute [local instance] Classical.propDecidable - - -def DisjointOccurrence (A B : Set (Set E)) : Set (Set E) := - {ω | ∃ s t : Finset E, (s : Set E) ⊆ ω ∧ (t : Set E) ⊆ ω ∧ - Disjoint s t ∧ (s : Set E) ∈ A ∧ (t : Set E) ∈ B} - -theorem disjointOccurrence_upper (A B : Set (Set E)) : IsUpperSet (DisjointOccurrence A B) := by - rintro ω η h ⟨s, t, hs, ht, hd, ha, hb⟩ - exact ⟨s, t, hs.trans h, ht.trans h, hd, ha, hb⟩ - -theorem finiteWitness_disjointOccurrence (A B : Set (Set E)) : - FiniteWitness (DisjointOccurrence A B) := by - rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ - refine ⟨s ∪ t, ?_, s, t, ?_, ?_, hd, ha, hb⟩ - · simpa only [Finset.coe_union] using Set.union_subset hs ht - · simp - · simp - -theorem disjointOccurrence_mono {A A' B B' : Set (Set E)} - (hA : A ⊆ A') (hB : B ⊆ B') : DisjointOccurrence A B ⊆ DisjointOccurrence A' B' := by - rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ - exact ⟨s, t, hs, ht, hd, hA ha, hB hb⟩ - - -def openSection (A : Set (Set E)) (e : E) : Set (Set E) := {ω | insert e ω ∈ A} - -theorem openSection_upper {A : Set (Set E)} (hA : IsUpperSet A) (e : E) : - IsUpperSet (openSection A e) := - fun _ _ h hω => hA (Set.insert_subset_insert h) hω - -theorem subset_openSection {A : Set (Set E)} (hA : IsUpperSet A) (e : E) : - A ⊆ openSection A e := fun ω hω => hA (Set.subset_insert e ω) hω - - -theorem openSection_disjointOccurrence (A B : Set (Set E)) (_hA : IsUpperSet A) - (hB : IsUpperSet B) (e : E) : - openSection (DisjointOccurrence A B) e ⊆ - DisjointOccurrence (openSection A e) B ∪ DisjointOccurrence A (openSection B e) := by - rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ - by_cases he : e ∈ s - · left - have het : e ∉ t := fun h => Finset.disjoint_left.mp hd he h - refine ⟨s.erase e, t, ?_, ?_, Finset.disjoint_of_subset_left (Finset.erase_subset _ _) hd, ?_, hb⟩ - · intro z hz - exact (hs (Finset.mem_of_mem_erase hz)).resolve_left (Finset.ne_of_mem_erase hz) - · intro z hz - rcases ht hz with rfl | hz' - · exact (het hz).elim - · exact hz' - · change insert e (↑(s.erase e) : Set E) ∈ A - simpa only [← Finset.coe_insert, Finset.insert_erase he] using ha - · right - refine ⟨s, t.erase e, ?_, ?_, Finset.disjoint_of_subset_right (Finset.erase_subset _ _) hd, ha, ?_⟩ - · intro z hz - rcases hs hz with rfl | hz' - · exact (he hz).elim - · exact hz' - · intro z hz - exact (ht (Finset.mem_of_mem_erase hz)).resolve_left (Finset.ne_of_mem_erase hz) - · apply hB ?_ hb - intro z hz - by_cases hze : z = e - · exact Or.inl hze - · exact Or.inr (Finset.mem_erase.mpr ⟨hze, hz⟩) - - - -noncomputable def finiteProbability (p : unitInterval) (s : Finset E) (A : Set (Set E)) : ℝ := - ∑ t ∈ s.powerset, if (t : Set E) ∈ A then - (p : ℝ) ^ t.card * (1 - p : ℝ) ^ (s.card - t.card) else 0 - -theorem finiteProbability_nonneg (p : unitInterval) (s : Finset E) (A : Set (Set E)) : - 0 ≤ finiteProbability p s A := by - apply Finset.sum_nonneg - intro t _ - split_ifs - · exact mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) - · exact le_rfl - -theorem finiteProbability_mono (p : unitInterval) (s : Finset E) - {A B : Set (Set E)} (h : A ⊆ B) : finiteProbability p s A ≤ finiteProbability p s B := by - apply Finset.sum_le_sum - intro t _ - split_ifs with ha hb hb - · exact le_rfl - · exact (hb (h ha)).elim - · exact mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) - · exact le_rfl - -theorem finiteProbability_union_add_inter (p : unitInterval) (s : Finset E) - (A B : Set (Set E)) : - finiteProbability p s (A ∪ B) + finiteProbability p s (A ∩ B) = - finiteProbability p s A + finiteProbability p s B := by - simp only [finiteProbability, ← Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro t _ - by_cases ha : (t : Set E) ∈ A <;> by_cases hb : (t : Set E) ∈ B <;> simp [ha, hb] - -@[simp] theorem finiteProbability_empty (p : unitInterval) (A : Set (Set E)) : - finiteProbability p ∅ A = if ∅ ∈ A then 1 else 0 := by - simp [finiteProbability] - -theorem finiteProbability_insert (p : unitInterval) (s : Finset E) (e : E) (he : e ∉ s) - (A : Set (Set E)) : - finiteProbability p (insert e s) A = - (1 - p : ℝ) * finiteProbability p s A + (p : ℝ) * finiteProbability p s (openSection A e) := by - have hd : Disjoint s.powerset (s.powerset.image (insert e)) := by - apply Finset.disjoint_left.mpr - intro t ht himg - obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp himg - exact he ((Finset.mem_powerset.mp ht) (by simp)) - have hinj : Set.InjOn (insert e) (↑s.powerset : Set (Finset E)) := by - intro t ht r hr h - have ht' : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) - have hr' : e ∉ r := fun h => he (Finset.mem_powerset.mp hr h) - have hh := congrArg (fun t : Finset E => t.erase e) h - simpa [ht', hr'] using hh - simp only [finiteProbability, Finset.powerset_insert, Finset.sum_union hd, - Finset.sum_image hinj, Finset.mul_sum, Finset.card_insert_of_notMem he] - congr 1 - · apply Finset.sum_congr rfl - intro t ht - have hcard := Finset.card_le_card (Finset.mem_powerset.mp ht) - have hexp : s.card + 1 - t.card = (s.card - t.card) + 1 := by omega - rw [hexp, pow_succ] - split_ifs <;> simp_all [mul_comm, mul_left_comm] - · apply Finset.sum_congr rfl - intro t ht - have het : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) - simp only [Finset.card_insert_of_notMem het, Nat.add_sub_add_right, pow_succ, - Finset.coe_insert, openSection, Set.mem_ofPred_eq] - split_ifs <;> simp_all [mul_assoc, mul_comm] - -end DisjointWitness - -section FiniteBK -attribute [local instance] Classical.propDecidable - -@[simp] theorem empty_mem_disjointOccurrence (A B : Set (Set E)) : - (∅ : Set E) ∈ DisjointOccurrence A B ↔ ∅ ∈ A ∧ ∅ ∈ B := by - constructor - · rintro ⟨s, t, hs, ht, _, ha, hb⟩ - have hse : (s : Set E) = ∅ := Set.subset_empty_iff.mp hs - have hte : (t : Set E) = ∅ := Set.subset_empty_iff.mp ht - exact ⟨hse ▸ ha, hte ▸ hb⟩ - · rintro ⟨ha, hb⟩ - exact ⟨∅, ∅, by simp, by simp, by simp, by simpa using ha, by simpa using hb⟩ - - - -theorem finiteProbability_disjointOccurrence_le_half (p : unitInterval) - (hp : (p : ℝ) ≤ 1 / 2) (s : Finset E) (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) : - finiteProbability p s (DisjointOccurrence A B) ≤ - finiteProbability p s A * finiteProbability p s B := by - induction s using Finset.induction_on generalizing A B with - | empty => - simp only [finiteProbability_empty, empty_mem_disjointOccurrence] - by_cases ha : (∅ : Set E) ∈ A <;> by_cases hb : (∅ : Set E) ∈ B <;> simp [ha, hb] - | @insert e s he ih => - let A1 := openSection A e - let B1 := openSection B e - let D00 := DisjointOccurrence A B - let D10 := DisjointOccurrence A1 B - let D01 := DisjointOccurrence A B1 - have hD : D00 ⊆ D10 ∩ D01 := by - intro ω hω - exact ⟨disjointOccurrence_mono (subset_openSection hA e) (Set.Subset.refl _) hω, - disjointOccurrence_mono (Set.Subset.refl _) (subset_openSection hB e) hω⟩ - have hsec : finiteProbability p s (openSection D00 e) ≤ - finiteProbability p s D10 + finiteProbability p s D01 - finiteProbability p s D00 := by - have h1 := finiteProbability_mono p s (openSection_disjointOccurrence A B hA hB e) - have h2 := finiteProbability_mono p s hD - have h3 := finiteProbability_union_add_inter p s D10 D01 - change finiteProbability p s (openSection D00 e) ≤ - finiteProbability p s (D10 ∪ D01) at h1 - linarith - have h00 := ih A B hA hB - have h10 := ih A1 B (openSection_upper hA e) hB - have h01 := ih A B1 hA (openSection_upper hB e) - have ha := finiteProbability_mono p s (subset_openSection hA e) - have hb := finiteProbability_mono p s (subset_openSection hB e) - have hcoef : 0 ≤ 1 - 2 * (p : ℝ) := by linarith - have hdif : 0 ≤ ((p : ℝ) ^ 2) * - (finiteProbability p s A1 - finiteProbability p s A) * - (finiteProbability p s B1 - finiteProbability p s B) := - mul_nonneg (mul_nonneg (sq_nonneg _) (sub_nonneg.mpr ha)) (sub_nonneg.mpr hb) - rw [finiteProbability_insert p s e he, finiteProbability_insert p s e he, - finiteProbability_insert p s e he] - have hm := mul_le_mul_of_nonneg_left hsec p.2.1 - have hm00 := mul_le_mul_of_nonneg_left h00 hcoef - have hm10 := mul_le_mul_of_nonneg_left h10 p.2.1 - have hm01 := mul_le_mul_of_nonneg_left h01 p.2.1 - change (1 - (p : ℝ)) * finiteProbability p s D00 + - (p : ℝ) * finiteProbability p s (openSection D00 e) ≤ - ((1 - (p : ℝ)) * finiteProbability p s A + (p : ℝ) * finiteProbability p s A1) * - ((1 - (p : ℝ)) * finiteProbability p s B + (p : ℝ) * finiteProbability p s B1) - nlinarith - -end FiniteBK - -section BKMeasure -attribute [local instance] Classical.propDecidable -open Filter Topology - - -theorem finiteProbability_univ [Fintype E] (p : unitInterval) (A : Set (Set E)) : - finiteProbability p Finset.univ A = (law p).real A := by - have he : (law p).real A = ∑ ω : Set E, if ω ∈ A then (law p).real {ω} else 0 := by - have h := integral_fintype (μ := law p) (f := A.indicator (fun _ => (1 : ℝ))) - Integrable.of_finite - rw [integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet A)] at h - simpa [smul_eq_mul, mul_ite, Set.indicator_apply] using h - rw [he, finiteProbability] - apply Finset.sum_bij (fun (t : Finset E) _ => (t : Set E)) - · simp - · intro a _ b _ h - exact Finset.coe_injective h - · intro ω _ - exact ⟨ω.toFinset, by simp, by simp⟩ - · intro t _ - rw [law, setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ] - simp [Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ, Set.ncard_univ, - Nat.card_eq_fintype_card] - -theorem disjointOccurrence_image {F : Type*} (f : F ↪ E) (A B : Set (Set E)) : - (fun ω => f '' ω) ⁻¹' DisjointOccurrence A B = - DisjointOccurrence ((fun ω => f '' ω) ⁻¹' A) ((fun ω => f '' ω) ⁻¹' B) := by - ext ω - constructor - · rintro ⟨s, t, hs, ht, hd, ha, hb⟩ - let s' := s.preimage f f.injective.injOn - let t' := t.preimage f f.injective.injOn - have hs' : (s' : Set F) = f ⁻¹' (s : Set E) := by simp [s'] - have ht' : (t' : Set F) = f ⁻¹' (t : Set E) := by simp [t'] - have hsI : f '' (s' : Set F) = (s : Set E) := by - rw [hs', Set.image_preimage_eq_of_subset] - exact hs.trans (Set.image_subset_range _ _) - have htI : f '' (t' : Set F) = (t : Set E) := by - rw [ht', Set.image_preimage_eq_of_subset] - exact ht.trans (Set.image_subset_range _ _) - refine ⟨s', t', ?_, ?_, ?_, ?_, ?_⟩ - · rw [hs'] - exact (Set.preimage_mono hs).trans (by rw [Set.preimage_image_eq _ f.injective]) - · rw [ht'] - exact (Set.preimage_mono ht).trans (by rw [Set.preimage_image_eq _ f.injective]) - · apply Finset.disjoint_left.mpr - intro x hx hy - exact Finset.disjoint_left.mp hd (by simpa [s'] using hx) (by simpa [t'] using hy) - · change f '' (s' : Set F) ∈ A - rwa [hsI] - · change f '' (t' : Set F) ∈ B - rwa [htI] - · rintro ⟨s, t, hs, ht, hd, ha, hb⟩ - refine ⟨s.map f, t.map f, ?_, ?_, ?_, ?_, ?_⟩ - · simpa only [Finset.coe_map] using Set.image_mono hs - · simpa only [Finset.coe_map] using Set.image_mono ht - · exact (Finset.disjoint_map f).mpr hd - · simpa only [Finset.coe_map, Set.mem_preimage] using ha - · simpa only [Finset.coe_map, Set.mem_preimage] using hb - -theorem bk_finite_half [Fintype E] (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) - (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) : - (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by - simpa only [finiteProbability_univ] using - finiteProbability_disjointOccurrence_le_half p hp Finset.univ A B hA hB - -theorem bk_restricted_half (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) - (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) (s : Finset E) : - (law p).real {ω | ω ∩ (s : Set E) ∈ DisjointOccurrence A B} ≤ - (law p).real {ω | ω ∩ (s : Set E) ∈ A} * - (law p).real {ω | ω ∩ (s : Set E) ∈ B} := by - let f : (s : Set E) ↪ E := ⟨Subtype.val, Subtype.val_injective⟩ - have hreal (C : Set (Set E)) : - (law p).real {ω | ω ∩ (s : Set E) ∈ C} = - (law p).real {η : Set (s : Set E) | f '' η ∈ C} := by - rw [← law_map_restrict p (s : Set E)] - simp only [Measure.real] - rw [Measure.map_apply (measurable_set_restrict _) MeasurableSet.of_discrete] - congr 2 - ext ω - change ω ∩ (s : Set E) ∈ C ↔ f '' (Subtype.val ⁻¹' ω) ∈ C - have he : f '' (Subtype.val ⁻¹' ω) = ω ∩ (s : Set E) := by - ext e - simp [f, and_comm] - rw [he] - rw [hreal, hreal, hreal] - have hh := bk_finite_half p hp ((fun ω => f '' ω) ⁻¹' A) - ((fun ω => f '' ω) ⁻¹' B) - (fun _ _ h hω => hA (Set.image_mono h) hω) - (fun _ _ h hω => hB (Set.image_mono h) hω) - rw [← disjointOccurrence_image] at hh - exact hh - - -theorem bk_finiteWitness_half [Countable E] (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) - (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) - (hfA : FiniteWitness A) (hfB : FiniteWitness B) : - (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by - let := Encodable.ofCountable E - have hlim (C : Set (Set E)) (hC : IsUpperSet C) (hfC : FiniteWitness C) : - Tendsto (fun n => (law p).real {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) - atTop (𝓝 ((law p).real C)) := by - have hm : Monotone (fun n => {ω : Set E | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) := by - intro m n h ω hω - exact hC (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω - have h := tendsto_measure_iUnion_atTop (μ := law p) hm - rw [← witness_eq_union C hC hfC] at h - exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h - apply le_of_tendsto_of_tendsto - (hlim _ (disjointOccurrence_upper A B) (finiteWitness_disjointOccurrence A B)) - ((hlim A hA hfA).mul (hlim B hB hfB)) - exact Filter.Eventually.of_forall fun n => bk_restricted_half p hp A B hA hB (edgeExhaustion n) - -end BKMeasure - -section ORLift -attribute [local instance] Classical.propDecidable - -noncomputable def orParameter (q : unitInterval) (m : ℕ) : unitInterval := - ⟨1 - (1 - (q : ℝ)) ^ m, - sub_nonneg.mpr (pow_le_one₀ (sub_nonneg.mpr q.2.2) (by linarith [q.2.1])), - by linarith [pow_nonneg (sub_nonneg.mpr q.2.2) m]⟩ - -noncomputable abbrev bitLaw (q : unitInterval) : Measure Prop := - unitInterval.toNNReal q • Measure.dirac True + - unitInterval.toNNReal (unitInterval.symm q) • Measure.dirac False - -instance bitLaw_isProbabilityMeasure (q : unitInterval) : IsProbabilityMeasure (bitLaw q) := by - rw [bitLaw, ← map_threshold q] - infer_instance - - -theorem map_nonempty (q : unitInterval) (F : Type*) [Fintype F] : - (law q : Measure (Set F)).map Set.Nonempty = bitLaw (orParameter q (Fintype.card F)) := by - let μ := (law q : Measure (Set F)).map Set.Nonempty - have hm : Measurable (Set.Nonempty : Set F → Prop) := .of_discrete - have : IsProbabilityMeasure μ := inferInstance - have hfalse : μ.real {False} = (1 - (q : ℝ)) ^ Fintype.card F := by - change ((law q).map Set.Nonempty).real {False} = _ - simp only [Measure.real, Measure.map_apply hm (measurableSet_singleton _)] - have he : Set.Nonempty ⁻¹' ({False} : Set Prop) = ({∅} : Set (Set F)) := by - ext ω - simp [Set.not_nonempty_iff_eq_empty] - rw [he] - change (law q).real {∅} = _ - rw [law, setBernoulli_real_singleton q (Set.empty_subset _) Set.finite_univ] - simp [Set.ncard_univ, Nat.card_eq_fintype_card] - have htrue : μ.real {True} = 1 - (1 - (q : ℝ)) ^ Fintype.card F := by - have he : ({True} : Set Prop) = ({False} : Set Prop)ᶜ := by ext b; simp - rw [he, measureReal_compl (measurableSet_singleton _), probReal_univ, hfalse] - apply Measure.ext_of_singleton - intro b - apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp - change μ.real {b} = (bitLaw (orParameter q (Fintype.card F))).real {b} - by_cases hb : b - · have he : b = True := propext (iff_true_intro hb) - subst b - rw [htrue] - simp [bitLaw, Measure.real, orParameter] - · have he : b = False := propext (iff_false_intro hb) - subst b - rw [hfalse] - simp [bitLaw, Measure.real, orParameter] - - -theorem finite_image_lift {F : Type*} (f : F → E) {ω : Set F} (s : Finset E) - (hs : (s : Set E) ⊆ f '' ω) : - ∃ t : Finset F, (t : Set F) ⊆ ω ∧ f '' (t : Set F) = (s : Set E) := by - have hex : ∃ t ⊆ f '' ω, t.Finite ∧ t = (s : Set E) := - ⟨s, hs, s.finite_toSet, rfl⟩ - obtain ⟨t, ht, htf, hti⟩ := Set.exists_subset_image_finite_and.mp hex - exact ⟨htf.toFinset, by simpa using ht, by simpa using hti⟩ - -theorem finiteWitness_image_preimage {F : Type*} (f : F → E) (A : Set (Set E)) - (hA : FiniteWitness A) : FiniteWitness ((fun ω => f '' ω) ⁻¹' A) := by - intro ω hω - obtain ⟨s, hs, ha⟩ := hA (f '' ω) hω - obtain ⟨t, ht, htI⟩ := finite_image_lift f s hs - exact ⟨t, ht, by simpa only [Set.mem_preimage, htI] using ha⟩ - -theorem image_preimage_disjointOccurrence {F : Type*} (f : F → E) (A B : Set (Set E)) : - (fun ω => f '' ω) ⁻¹' DisjointOccurrence A B ⊆ - DisjointOccurrence ((fun ω => f '' ω) ⁻¹' A) ((fun ω => f '' ω) ⁻¹' B) := by - rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ - obtain ⟨s', hs', hsI⟩ := finite_image_lift f s hs - obtain ⟨t', ht', htI⟩ := finite_image_lift f t ht - refine ⟨s', t', hs', ht', ?_, ?_, ?_⟩ - · apply Finset.disjoint_left.mpr - intro x hx hy - have hxs : f x ∈ (s : Set E) := hsI ▸ Set.mem_image_of_mem f hx - have hxt : f x ∈ (t : Set E) := htI ▸ Set.mem_image_of_mem f hy - exact Finset.disjoint_left.mp hd hxs hxt - · simpa only [Set.mem_preimage, hsI] using ha - · simpa only [Set.mem_preimage, htI] using hb - -end ORLift - -section ORLaw -attribute [local instance] Classical.propDecidable - -theorem map_exists_bitLaw (q : unitInterval) (F : Type*) [Fintype F] : - (Measure.infinitePi (fun _ : F => bitLaw q)).map (fun f : F → Prop => ∃ j, f j) = - bitLaw (orParameter q (Fintype.card F)) := by - have h := map_nonempty q F - unfold law at h - rw [setBernoulli_eq_map, Measure.map_map (Measurable.of_discrete) measurable_setOfPred] at h - simpa only [Set.mem_univ, Function.comp_def, Set.Nonempty, Set.mem_ofPred_eq, - bernoulliMeasure_def, bitLaw] using h - -theorem measurable_image_fst (F : Type*) [Fintype F] : - Measurable (fun ω : Set (E × F) => Prod.fst '' ω) := by - have hm : Measurable (fun ω : Set (E × F) => fun e => ∃ j : F, (e,j) ∈ ω) := by - apply Measurable.of_eval - intro e - apply measurableSet_setOfPred.mp - have he : {ω : Set (E × F) | ∃ j : F, (e,j) ∈ ω} = - ⋃ j : F, {ω : Set (E × F) | (e,j) ∈ ω} := by ext ω; simp - rw [he] - exact MeasurableSet.iUnion fun j => measurableSet_setOfPred.mpr - ((measurable_pi_apply (e,j)).comp MeasurableEquiv.setOfPred.symm.measurable) - have he : (fun ω : Set (E × F) => Prod.fst '' ω) = - (fun f : E → Prop => {e | f e}) ∘ (fun ω e => ∃ j : F, (e,j) ∈ ω) := by - funext ω - ext e - simp [Prod.exists] - rw [he] - exact measurable_setOfPred.comp hm - - -theorem law_map_image_fst (q : unitInterval) (F : Type*) [Fintype F] : - (law q : Measure (Set (E × F))).map (fun ω => Prod.fst '' ω) = - law (orParameter q (Fintype.card F)) := by - let c := MeasurableEquiv.curry E F Prop - let b := fun f : E → F → Prop => fun e => ∃ j, f e j - have hb : Measurable b := Measurable.of_eval - (fun e => (Measurable.of_discrete : Measurable (fun f : F → Prop => ∃j, f j)).comp - (measurable_pi_apply e)) - unfold law - rw [setBernoulli_eq_map, Measure.map_map (measurable_image_fst F) measurable_setOfPred] - simp only [Set.mem_univ] - have he : (fun ω : Set (E × F) => Prod.fst '' ω) ∘ (fun f => {e | f e}) = - (fun f : E → Prop => {e | f e}) ∘ b ∘ c := by - funext f - ext e - simp [b, c, Function.comp_def, Prod.exists] - rw [he, ← Measure.map_map measurable_setOfPred (hb.comp c.measurable), - ← Measure.map_map hb c.measurable] - change ((Measure.infinitePi (fun _ : E × F => bitLaw q)).map c |>.map b |>.map - (fun f : E → Prop => {e | f e})) = _ - rw [Measure.infinitePi_map_curry (fun (_ : E) (_ : F) => bitLaw q)] - dsimp only [b] - rw [Measure.infinitePi_map_pi _ (fun _ => Measurable.of_discrete)] - rw [map_exists_bitLaw q F] - rw [setBernoulli_eq_map] - rfl - - -theorem exists_orParameter (p : unitInterval) (hp : p < 1) : - ∃ m : ℕ, ∃ q : unitInterval, (q : ℝ) ≤ 1 / 2 ∧ orParameter q m = p := by - obtain ⟨m, hm⟩ := exists_pow_lt_of_lt_one (show 0 < 1 - (p : ℝ) by exact sub_pos.mpr hp) - (show (1 / 2 : ℝ) < 1 by norm_num) - let f := fun x : ℝ => 1 - (1-x)^m - have hf : Continuous f := by fun_prop - have h0 : f 0 = 0 := by simp [f] - have hp' : (p : ℝ) ∈ Set.Icc (f 0) (f (1/2)) := by - rw [h0] - refine ⟨p.2.1, ?_⟩ - dsimp [f] - norm_num at hm ⊢ - linarith - obtain ⟨q, hq, hqp⟩ := intermediate_value_Icc (by norm_num : (0 : ℝ) ≤ 1/2) - hf.continuousOn hp' - refine ⟨m, ⟨q, hq.1, hq.2.trans (by norm_num)⟩, hq.2, ?_⟩ - apply Subtype.ext - exact hqp - -end ORLaw - -section BK -attribute [local instance] Classical.propDecidable - -theorem disjointOccurrence_subset_inter (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) : DisjointOccurrence A B ⊆ A ∩ B := by - rintro ω ⟨s,t,hs,ht,_,ha,hb⟩ - exact ⟨hA hs ha, hB ht hb⟩ - - - -theorem bk [Countable E] (p : unitInterval) (A B : Set (Set E)) - (hA : IsUpperSet A) (hB : IsUpperSet B) - (hfA : FiniteWitness A) (hfB : FiniteWitness B) : - (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by - by_cases hp : p = 1 - · subst p - by_cases hu : Set.univ ∈ DisjointOccurrence A B - · have ha := (disjointOccurrence_subset_inter A B hA hB hu).1 - have hb := (disjointOccurrence_subset_inter A B hA hB hu).2 - simp [law, Measure.real, hu, ha, hb] - · simp [law, Measure.real, hu] - positivity - · have hp' : p < 1 := lt_of_le_of_ne p.2.2 hp - obtain ⟨m, q, hq, hqp⟩ := exists_orParameter p hp' - let f : E × Fin m → E := Prod.fst - let A' := (fun ω => f '' ω) ⁻¹' A - let B' := (fun ω => f '' ω) ⁻¹' B - have hreal (C : Set (Set E)) (hC : MeasurableSet C) : - (law p).real C = (law q).real ((fun ω : Set (E × Fin m) => f '' ω) ⁻¹' C) := by - have hh := law_map_image_fst (E := E) q (Fin m) - simp only [Fintype.card_fin, hqp] at hh - rw [← hh] - simp only [Measure.real, Measure.map_apply (measurable_image_fst (Fin m)) hC] - rfl - calc - (law p).real (DisjointOccurrence A B) = - (law q).real ((fun ω : Set (E × Fin m) => f '' ω) ⁻¹' DisjointOccurrence A B) := - hreal _ (measurableSet_finiteWitness _ (disjointOccurrence_upper A B) - (finiteWitness_disjointOccurrence A B)) - _ ≤ (law q).real (DisjointOccurrence A' B') := - measureReal_mono (image_preimage_disjointOccurrence f A B) - _ ≤ (law q).real A' * (law q).real B' := bk_finiteWitness_half q hq A' B' - (fun _ _ h hω => hA (Set.image_mono h) hω) - (fun _ _ h hω => hB (Set.image_mono h) hω) - (finiteWitness_image_preimage f A hfA) (finiteWitness_image_preimage f B hfB) - _ = (law p).real A * (law p).real B := by - rw [hreal A (measurableSet_finiteWitness A hA hfA), - hreal B (measurableSet_finiteWitness B hB hfB)] - -end BK - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Bounds + +namespace OAI + +/-! Association, disjoint witnesses and the BK inequality. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteAssociation +attribute [local instance] Classical.propDecidable +variable [Fintype E] + +private theorem bernoulli_atom_product (p : unitInterval) (ω : Set E) : + (law p).real {ω} = ∏ e : E, if e ∈ ω then (p : ℝ) else 1 - p := by + rw [law, setBernoulli_real_singleton p (Set.subset_univ ω) (Set.finite_univ)] + simp [Finset.prod_ite, ← Set.ncard_coe_finset, Set.sdiff_eq] + exact Or.inl rfl + +private theorem bernoulli_atom_modular (p : unitInterval) (a b : Set E) : + (law p).real {a} * (law p).real {b} = + (law p).real {a ∩ b} * (law p).real {a ∪ b} := by + simp only [bernoulli_atom_product, ← Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro e _ + by_cases ha : e ∈ a <;> by_cases hb : e ∈ b <;> simp [ha, hb, mul_comm] + + + +theorem association_finite (p : unitInterval) (f g : Set E → ℝ) + (hf : Monotone f) (hg : Monotone g) (hf0 : ∀ ω, 0 ≤ f ω) (hg0 : ∀ ω, 0 ≤ g ω) : + (∫ ω, f ω ∂law p) * (∫ ω, g ω ∂law p) ≤ ∫ ω, f ω * g ω ∂law p := by + have h := fkg f g (fun ω : Set E => (law p).real {ω}) + (fun _ => measureReal_nonneg) hf0 hg0 hf hg + (fun a b => (bernoulli_atom_modular p a b).le) + have hsum : (∑ ω : Set E, (law p).real {ω}) = 1 := by + simp + rw [hsum, one_mul] at h + simpa only [integral_fintype Integrable.of_finite, smul_eq_mul] using h + + +theorem association_events_finite (p : unitInterval) (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) : + (law p).real A * (law p).real B ≤ (law p).real (A ∩ B) := by + have hm (S : Set (Set E)) (hS : IsUpperSet S) : + Monotone (S.indicator (fun _ => (1 : ℝ))) := by + intro a b hab + by_cases ha : a ∈ S + · simp [ha, hS hab ha] + · simp only [Set.indicator_of_notMem ha] + exact Set.indicator_nonneg (fun _ _ => zero_le_one) _ + have he : (fun ω => A.indicator (fun _ => (1 : ℝ)) ω * + B.indicator (fun _ => (1 : ℝ)) ω) = (A ∩ B).indicator (fun _ => 1) := by + funext ω + by_cases ha : ω ∈ A <;> by_cases hb : ω ∈ B <;> simp [ha, hb] + have h := association_finite p _ _ (hm A hA) (hm B hB) + (Set.indicator_nonneg (fun _ _ => zero_le_one)) + (Set.indicator_nonneg (fun _ _ => zero_le_one)) + rw [he] at h + simpa only [integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet A), + integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet B), + integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet (A ∩ B)), + smul_eq_mul, mul_one] using h + +end FiniteAssociation + +section Restriction + +theorem measurable_set_restrict (s : Set E) : + Measurable (fun ω : Set E => (Subtype.val ⁻¹' ω : Set s)) := + measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_pi_apply e.val).comp MeasurableEquiv.setOfPred.symm.measurable)) + + +theorem law_map_restrict (p : unitInterval) (s : Set E) : + (law p : Measure (Set E)).map (fun ω => (Subtype.val ⁻¹' ω : Set s)) = law p := by + have hm := measurable_set_restrict s + unfold law + rw [setBernoulli_eq_map, Measure.map_map hm measurable_setOfPred] + have he : (fun ω : Set E => (Subtype.val ⁻¹' ω : Set s)) ∘ + (fun f : E → Prop => {e | f e}) = + (fun f : s → Prop => {e | f e}) ∘ s.domRestrict := rfl + rw [he, ← Measure.map_map measurable_setOfPred (by fun_prop), + Measure.infinitePi_map_restrict', setBernoulli_eq_map] + simp only [Set.mem_univ] + +end Restriction + +section WitnessAssociation +attribute [local instance] Classical.propDecidable +open Filter Topology + + +def FiniteWitness (A : Set (Set E)) : Prop := + ∀ ω ∈ A, ∃ s : Finset E, (s : Set E) ⊆ ω ∧ (s : Set E) ∈ A + +theorem association_restricted (p : unitInterval) (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) (s : Finset E) : + (law p).real {ω | ω ∩ (s : Set E) ∈ A} * + (law p).real {ω | ω ∩ (s : Set E) ∈ B} ≤ + (law p).real {ω | ω ∩ (s : Set E) ∈ A ∩ B} := by + let A' : Set (Set (s : Set E)) := {η | Subtype.val '' η ∈ A} + let B' : Set (Set (s : Set E)) := {η | Subtype.val '' η ∈ B} + have hA' : IsUpperSet A' := fun _ _ h ha => hA (Set.image_mono h) ha + have hB' : IsUpperSet B' := fun _ _ h hb => hB (Set.image_mono h) hb + have he (ω : Set E) : Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) = + ω ∩ (s : Set E) := by + ext e + simp [and_comm] + have hl (C : Set (Set E)) : + (law p : Measure (Set (s : Set E))).real {η | Subtype.val '' η ∈ C} = + (law p).real {ω | ω ∩ (s : Set E) ∈ C} := by + rw [← law_map_restrict p (s : Set E), measureReal_def, + Measure.map_apply (measurable_set_restrict _) .of_discrete] + simp only [Set.preimage_ofPred_eq, he, measureReal_def] + have ht := association_events_finite p A' B' hA' hB' + change (law p).real {η | Subtype.val '' η ∈ A} * + (law p).real {η | Subtype.val '' η ∈ B} ≤ + (law p).real {η | Subtype.val '' η ∈ A ∩ B} at ht + simpa only [hl] using ht + + noncomputable def edgeExhaustion [Encodable E] (n : ℕ) : Finset E := + (Finset.range n).preimage Encodable.encode Encodable.encode_injective.injOn + + theorem edgeExhaustion_mono [Encodable E] : + Monotone (edgeExhaustion : ℕ → Finset E) := by + intro m n h e he + simp only [edgeExhaustion, Finset.mem_preimage, Finset.mem_range] at he ⊢ + exact he.trans_le h + +private theorem subset_edgeExhaustion [Encodable E] (s : Finset E) : + ∃ n, s ⊆ edgeExhaustion n := by + refine ⟨s.sup Encodable.encode + 1, ?_⟩ + intro e he + simp only [edgeExhaustion, Finset.mem_preimage, Finset.mem_range] + exact Nat.lt_succ_of_le (Finset.le_sup he) + + theorem witness_eq_union [Encodable E] (A : Set (Set E)) + (hA : IsUpperSet A) (hf : FiniteWitness A) : + A = ⋃ n, {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ A} := by + ext ω + simp only [Set.mem_iUnion, Set.mem_ofPred_eq] + constructor + · intro hω + obtain ⟨s, hs, hsa⟩ := hf ω hω + obtain ⟨n, hn⟩ := subset_edgeExhaustion s + exact ⟨n, hA (fun _ he => ⟨hs he, hn he⟩) hsa⟩ + · rintro ⟨n, hn⟩ + exact hA Set.inter_subset_left hn + + + +theorem association_finiteWitness [Countable E] (p : unitInterval) + (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) + (hfA : FiniteWitness A) (hfB : FiniteWitness B) : + (law p).real A * (law p).real B ≤ (law p).real (A ∩ B) := by + let := Encodable.ofCountable E + have hfAB : FiniteWitness (A ∩ B) := by + intro ω hω + obtain ⟨s, hs, hsa⟩ := hfA ω hω.1 + obtain ⟨t, ht, htb⟩ := hfB ω hω.2 + refine ⟨s ∪ t, ?_, hA ?_ hsa, hB ?_ htb⟩ + · simpa only [Finset.coe_union] using Set.union_subset hs ht + · simp only [Finset.coe_union]; exact Set.subset_union_left + · simp only [Finset.coe_union]; exact Set.subset_union_right + have hlim (C : Set (Set E)) (hC : IsUpperSet C) (hfC : FiniteWitness C) : + Tendsto (fun n => (law p).real {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) + atTop (𝓝 ((law p).real C)) := by + have hm : Monotone (fun n => {ω : Set E | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) := by + intro m n h ω hω + exact hC (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω + have h := tendsto_measure_iUnion_atTop (μ := law p) hm + rw [← witness_eq_union C hC hfC] at h + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h + exact le_of_tendsto_of_tendsto + ((hlim A hA hfA).mul (hlim B hB hfB)) (hlim (A ∩ B) (hA.inter hB) hfAB) + (Filter.Eventually.of_forall fun n => association_restricted p A B hA hB (edgeExhaustion n)) + +end WitnessAssociation + +section ClusterEvents +attribute [local instance] Classical.propDecidable +open Filter Topology + + +theorem measurableSet_finiteWitness [Countable E] (A : Set (Set E)) + (hA : IsUpperSet A) (hfA : FiniteWitness A) : MeasurableSet A := by + let := Encodable.ofCountable E + rw [witness_eq_union A hA hfA] + apply MeasurableSet.iUnion + intro n + let s := edgeExhaustion (E := E) n + have he : {ω : Set E | ω ∩ (s : Set E) ∈ A} = + (fun ω => (Subtype.val ⁻¹' ω : Set (s : Set E))) ⁻¹' + {η | Subtype.val '' η ∈ A} := by + ext ω + change ω ∩ (s : Set E) ∈ A ↔ Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) ∈ A + have hi : Subtype.val '' (Subtype.val ⁻¹' ω : Set (s : Set E)) = ω ∩ (s : Set E) := by + ext e + simp [and_comm] + rw [hi] + change MeasurableSet {ω : Set E | ω ∩ (s : Set E) ∈ A} + rw [he] + exact MeasurableSet.preimage .of_discrete (measurable_set_restrict _) + +theorem finiteWitness_conn (G : BondGraph V E) (x y : V) : + FiniteWitness {ω | Conn G ω x y} := by + intro ω h + induction h with + | refl => exact ⟨∅, by simp, by simp⟩ + | @tail b c hab hbc ih => + obtain ⟨s, hs, hconn⟩ := ih + obtain ⟨e, he, hGe⟩ := hbc + refine ⟨insert e s, ?_, ?_⟩ + · simpa only [Finset.coe_insert] using Set.insert_subset he hs + · exact (conn_mono G (by simp) hconn).tail ⟨e, by simp, hGe⟩ + +theorem finiteWitness_conn_finset (G : BondGraph V E) (x : V) (t : Finset V) : + FiniteWitness {ω | ∀ y ∈ t, Conn G ω x y} := by + intro ω h + induction t using Finset.induction_on with + | empty => exact ⟨∅, by simp, by simp⟩ + | @insert a t ha ih => + obtain ⟨s, hs, hsa⟩ := finiteWitness_conn G x a ω (h a (by simp)) + obtain ⟨r, hr, hrt⟩ := ih (fun y hy => h y (by simp [hy])) + refine ⟨s ∪ r, ?_, ?_⟩ + · simpa only [Finset.coe_union] using Set.union_subset hs hr + · intro y hy + rcases Finset.mem_insert.mp hy with rfl | hy + · exact conn_mono G (by simp) hsa + · exact conn_mono G (by simp) (hrt y hy) + + +def clusterLarge (G : BondGraph V E) (x : V) (n : ℕ) : Set (Set E) := + {ω | ∃ t : Finset V, n ≤ t.card ∧ ∀ y ∈ t, Conn G ω x y} + +theorem clusterLarge_upper (G : BondGraph V E) (x : V) (n : ℕ) : + IsUpperSet (clusterLarge G x n) := by + rintro ω η h ⟨t, ht, hc⟩ + exact ⟨t, ht, fun y hy => conn_mono G h (hc y hy)⟩ + +theorem finiteWitness_clusterLarge (G : BondGraph V E) (x : V) (n : ℕ) : + FiniteWitness (clusterLarge G x n) := by + rintro ω ⟨t, ht, hc⟩ + obtain ⟨s, hs, hsc⟩ := finiteWitness_conn_finset G x t ω hc + exact ⟨s, hs, t, ht, hsc⟩ + +theorem measurableSet_clusterLarge [Countable E] (G : BondGraph V E) (x : V) (n : ℕ) : + MeasurableSet (clusterLarge G x n) := + measurableSet_finiteWitness _ (clusterLarge_upper G x n) (finiteWitness_clusterLarge G x n) + +theorem clusterLarge_antitone (G : BondGraph V E) (x : V) : + Antitone (clusterLarge G x) := by + rintro m n h ω ⟨t, ht, hc⟩ + exact ⟨t, h.trans ht, hc⟩ + +theorem infinite_cluster_eq_iInter (G : BondGraph V E) (x : V) : + {ω | (cluster G ω x).Infinite} = ⋂ n, clusterLarge G x n := by + ext ω + simp only [Set.mem_iInter, Set.mem_ofPred_eq] + constructor + · intro h n + obtain ⟨t, ht, hcard⟩ := h.exists_subset_card_eq n + exact ⟨t, hcard.ge, ht⟩ + · intro h hfin + obtain ⟨t, ht, hc⟩ := h (hfin.toFinset.card + 1) + have hsub : t ⊆ hfin.toFinset := fun y hy => hfin.mem_toFinset.mpr (hc y hy) + have := Finset.card_le_card hsub + omega + +theorem measurableSet_infinite_cluster [Countable E] (G : BondGraph V E) (x : V) : + MeasurableSet {ω | (cluster G ω x).Infinite} := by + rw [infinite_cluster_eq_iInter] + exact MeasurableSet.iInter (measurableSet_clusterLarge G x) + + +theorem association_decreasing [Countable E] (p : unitInterval) + (A B : ℕ → Set (Set E)) (hA : Antitone A) (hB : Antitone B) + (huA : ∀ n, IsUpperSet (A n)) (huB : ∀ n, IsUpperSet (B n)) + (hfA : ∀ n, FiniteWitness (A n)) (hfB : ∀ n, FiniteWitness (B n)) : + (law p).real (⋂ n, A n) * (law p).real (⋂ n, B n) ≤ + (law p).real ((⋂ n, A n) ∩ (⋂ n, B n)) := by + have hlim (C : ℕ → Set (Set E)) (hm : Antitone C) (hC : ∀ n, MeasurableSet (C n)) : + Tendsto (fun n => (law p).real (C n)) atTop (𝓝 ((law p).real (⋂ n, C n))) := + (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp + (tendsto_measure_iInter_atTop (fun n => (hC n).nullMeasurableSet) hm + ⟨0, measure_ne_top _ _⟩) + have hmA n := measurableSet_finiteWitness (A n) (huA n) (hfA n) + have hmB n := measurableSet_finiteWitness (B n) (huB n) (hfB n) + have h := le_of_tendsto_of_tendsto ((hlim A hA hmA).mul (hlim B hB hmB)) + (hlim (fun n => A n ∩ B n) (fun m n h => Set.inter_subset_inter (hA h) (hB h)) + (fun n => (hmA n).inter (hmB n))) + (Filter.Eventually.of_forall fun n => + association_finiteWitness p (A n) (B n) (huA n) (huB n) (hfA n) (hfB n)) + simpa only [Set.iInter_inter_distrib] using h + + + +theorem association_infinite_cluster [Countable E] + (G : BondGraph V E) (p : unitInterval) (x y : V) : + (law p).real {ω | (cluster G ω x).Infinite} * + (law p).real {ω | (cluster G ω y).Infinite} ≤ + (law p).real {ω | (cluster G ω x).Infinite ∧ (cluster G ω y).Infinite} := by + rw [infinite_cluster_eq_iInter, infinite_cluster_eq_iInter] + change _ ≤ (law p).real ({ω | (cluster G ω x).Infinite} ∩ + {ω | (cluster G ω y).Infinite}) + rw [infinite_cluster_eq_iInter, infinite_cluster_eq_iInter] + exact association_decreasing p _ _ (clusterLarge_antitone G x) (clusterLarge_antitone G y) + (clusterLarge_upper G x) (clusterLarge_upper G y) + (finiteWitness_clusterLarge G x) (finiteWitness_clusterLarge G y) + +end ClusterEvents + +section Automorphisms +attribute [local instance] Classical.propDecidable + +theorem measurable_set_preimage (b : E ≃ E) : + Measurable (fun ω : Set E => b ⁻¹' ω) := + measurable_setOfPred.comp (Measurable.of_eval + (fun e => (measurable_pi_apply (b e)).comp MeasurableEquiv.setOfPred.symm.measurable)) + + +theorem law_map_preimage_equiv (p : unitInterval) (b : E ≃ E) : + (law p : Measure (Set E)).map (fun ω => b ⁻¹' ω) = law p := by + unfold law + rw [setBernoulli_eq_map, Measure.map_map (measurable_set_preimage b) measurable_setOfPred] + have he : (fun ω : Set E => b ⁻¹' ω) ∘ (fun f : E → Prop => {e | f e}) = + (fun f : E → Prop => {e | f e}) ∘ + MeasurableEquiv.piCongrLeft (fun _ : E => Prop) b.symm := by + funext f + ext e + simp only [Function.comp_apply, Set.mem_preimage, Set.mem_ofPred_eq] + have hh := MeasurableEquiv.piCongrLeft_apply_apply (β := fun _ : E => Prop) b.symm f (b e) + exact iff_of_eq (by simpa only [Equiv.symm_apply_apply] using hh.symm) + rw [he, ← Measure.map_map measurable_setOfPred (MeasurableEquiv.measurable _)] + simp only [Set.mem_univ] + congr 1 + exact Measure.infinitePi_map_piCongrLeft + (fun _ : E => unitInterval.toNNReal p • Measure.dirac True + + unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False) b.symm + +theorem isAut_symm (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) : IsAut G a.symm b.symm := by + intro e + have hh := congrArg (Sym2.map a.symm) (h (b.symm e)) + simpa only [Equiv.apply_symm_apply, Sym2.map_map, Equiv.symm_comp_self, + Sym2.map_id', id_eq] using hh.symm + +theorem conn_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) {ω : Set E} {x y : V} (hc : Conn G ω x y) : + Conn G (b '' ω) (a x) (a y) := by + induction hc with + | refl => exact conn_refl G _ _ + | @tail v w hvw hed ih => + obtain ⟨e, he, hGe⟩ := hed + exact ih.tail ⟨b e, Set.mem_image_of_mem _ he, by rw [h e, hGe, Sym2.map_mk]⟩ + +theorem conn_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (ω : Set E) (x y : V) : + Conn G (b ⁻¹' ω) x y ↔ Conn G ω (a x) (a y) := by + constructor + · intro hc + simpa only [Set.image_preimage_eq _ b.surjective] using conn_aut G h hc + · intro hc + have he : b.symm '' ω = b ⁻¹' ω := by + ext e + simp + simpa only [Equiv.symm_apply_apply, he] using + conn_aut G (isAut_symm G h) hc + +theorem cluster_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (h : IsAut G a b) (ω : Set E) (x : V) : + a '' cluster G (b ⁻¹' ω) x = cluster G ω (a x) := by + ext y + constructor + · rintro ⟨z, hz, rfl⟩ + exact (conn_aut_iff G h ω x z).mp hz + · intro hy + change Conn G ω (a x) y at hy + refine ⟨a.symm y, ?_, by simp⟩ + exact (conn_aut_iff G h ω x (a.symm y)).mpr (by simpa only [Equiv.apply_symm_apply] using hy) + +theorem infinite_cluster_aut [Countable E] (G : BondGraph V E) (p : unitInterval) + {a : V ≃ V} {b : E ≃ E} (h : IsAut G a b) (x : V) : + (law p).real {ω | (cluster G ω (a x)).Infinite} = + (law p).real {ω | (cluster G ω x).Infinite} := by + have he : {ω | (cluster G ω (a x)).Infinite} = + (fun ω => b ⁻¹' ω) ⁻¹' {ω | (cluster G ω x).Infinite} := by + ext ω + change (cluster G ω (a x)).Infinite ↔ (cluster G (b ⁻¹' ω) x).Infinite + rw [← cluster_aut G h] + exact Set.infinite_image_iff (fun _ _ _ _ hab => a.injective hab) + unfold Measure.real + rw [he, ← Measure.map_apply (measurable_set_preimage b) + (measurableSet_infinite_cluster G x), law_map_preimage_equiv] + + +theorem finite_open_probability (p : unitInterval) (s : Finset E) : + (law p).real {ω | (s : Set E) ⊆ ω} = (p : ℝ) ^ s.card := by + have he : {ω : Set E | (s : Set E) ⊆ ω} = + (fun ω => (Subtype.val ⁻¹' ω : Set (s : Set E))) ⁻¹' {Set.univ} := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_preimage, Set.mem_singleton_iff] + exact ⟨fun h => Set.eq_univ_of_forall fun e => h e.property, + fun h e he => show (⟨e, he⟩ : (s : Set E)) ∈ (Subtype.val ⁻¹' ω) from + h.symm ▸ Set.mem_univ _⟩ + unfold Measure.real + rw [he, ← Measure.map_apply (measurable_set_restrict _) (by measurability), + law_map_restrict] + change (law p : Measure (Set (s : Set E))).real {Set.univ} = _ + simp [law, setBernoulli_real_singleton p (Set.Subset.refl _) (Set.toFinite _)] + +theorem twoPoint_pos [Countable E] (G : BondGraph V E) (hG : Connected G) + (p : unitInterval) (hp : 0 < p) (x y : V) : 0 < twoPoint G p x y := by + obtain ⟨s, _, hs⟩ := finiteWitness_conn G x y Set.univ (conn_univ_of_connected G hG x y) + have hpos : 0 < (law p).real {ω | (s : Set E) ⊆ ω} := by + rw [finite_open_probability] + exact pow_pos hp _ + apply lt_of_lt_of_le hpos + exact measureReal_mono (fun _ hω => conn_mono G hω hs) + +end Automorphisms + +section UniquenessThreshold +attribute [local instance] Classical.propDecidable +variable [Countable V] [Countable E] + +omit [Countable V] in + +theorem association_infinite_conn (G : BondGraph V E) (p : unitInterval) (x y z : V) : + (law p).real {ω | (cluster G ω x).Infinite} * twoPoint G p y z ≤ + (law p).real {ω | (cluster G ω x).Infinite ∧ Conn G ω y z} := by + have h := association_decreasing p (clusterLarge G x) (fun _ => {ω | Conn G ω y z}) + (clusterLarge_antitone G x) antitone_const (clusterLarge_upper G x) + (fun _ _ _ hsub hconn => conn_mono G hsub hconn) (finiteWitness_clusterLarge G x) + (fun _ => finiteWitness_conn G y z) + simpa only [← infinite_cluster_eq_iInter, Set.iInter_const, twoPoint, Measure.real, Set.inter_def, Set.mem_ofPred_eq] using h + +omit [Countable V] in +theorem survival_pos_of_survival_pos (G : BondGraph V E) (hG : Connected G) + (p : unitInterval) (hp : 0 < p) {x : V} + (hx : 0 < (law p).real {ω | (cluster G ω x).Infinite}) (y : V) : + 0 < (law p).real {ω | (cluster G ω y).Infinite} := by + apply lt_of_lt_of_le (mul_pos hx (twoPoint_pos G hG p hp x y)) + refine (association_infinite_conn G p x x y).trans (measureReal_mono ?_) + rintro ω ⟨hi, hc⟩ + change (cluster G ω y).Infinite + rwa [← cluster_eq_of_conn G ω hc] + +omit [Countable V] [Countable E] in +theorem exists_infinite_cluster_iff (G : BondGraph V E) (ω : Set E) : + (infiniteClusters G ω).Nonempty ↔ ∃ x, (cluster G ω x).Infinite := by + constructor + · rintro ⟨C, hi, x, rfl⟩ + exact ⟨x, hi⟩ + · rintro ⟨x, hx⟩ + exact ⟨cluster G ω x, hx, x, rfl⟩ + +omit [Countable V] [Countable E] in +theorem unique_infinite_cluster_iff (G : BondGraph V E) (ω : Set E) : + (∃! C, C ∈ infiniteClusters G ω) ↔ + ∃ x, (cluster G ω x).Infinite ∧ ∀ y, (cluster G ω y).Infinite → Conn G ω x y := by + constructor + · rintro ⟨C, ⟨hi, x, rfl⟩, hu⟩ + refine ⟨x, hi, fun y hy => ?_⟩ + have he := hu (cluster G ω y) ⟨hy, y, rfl⟩ + have hm := mem_cluster_self G ω y + rwa [he] at hm + · rintro ⟨x, hx, hu⟩ + refine ⟨cluster G ω x, ⟨hx, x, rfl⟩, ?_⟩ + rintro C ⟨hi, y, rfl⟩ + exact (cluster_eq_of_conn G ω (hu y hi)).symm + +theorem measurableSet_unique_infinite_cluster (G : BondGraph V E) : + MeasurableSet {ω | ∃! C, C ∈ infiniteClusters G ω} := by + have he : {ω | ∃! C, C ∈ infiniteClusters G ω} = + ⋃ x, ({ω | (cluster G ω x).Infinite} ∩ + ⋂ y, ({ω | (cluster G ω y).Infinite}ᶜ ∪ {ω | Conn G ω x y})) := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_iUnion, Set.mem_inter_iff, + Set.mem_iInter, Set.mem_union, Set.mem_compl_iff, unique_infinite_cluster_iff, + imp_iff_not_or] + rw [he] + exact MeasurableSet.iUnion fun x => (measurableSet_infinite_cluster G x).inter + (MeasurableSet.iInter fun y => + (measurableSet_infinite_cluster G y).compl.union (measurableSet_conn G x y)) + +theorem uniform_survival_pos (G : BondGraph V E) (hconn : Connected G) + (hqt : QuasiTransitive G) (p : unitInterval) (hp : 0 < p) + (hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty}) : + ∃ θ : ℝ, 0 < θ ∧ ∀ x, θ ≤ (law p).real {ω | (cluster G ω x).Infinite} := by + have hunion : {ω | (infiniteClusters G ω).Nonempty} = + ⋃ x, {ω | (cluster G ω x).Infinite} := by + ext ω + simp only [Set.mem_ofPred_eq, Set.mem_iUnion, exists_infinite_cluster_iff] + rw [hunion] at hpos + obtain ⟨x, hx⟩ := exists_measure_pos_of_not_measure_iUnion_null (ne_of_gt hpos) + have hxp : 0 < (law p).real {ω | (cluster G ω x).Infinite} := + ENNReal.toReal_pos hx.ne' (measure_ne_top _ _) + have hroot := survival_pos_of_survival_pos G hconn p hp hxp + obtain ⟨s, hs⟩ := hqt + have hsn : s.Nonempty := by obtain ⟨o, ho, _⟩ := hs x; exact ⟨o, ho⟩ + let vals := s.image (fun o => (law p).real {ω | (cluster G ω o).Infinite}) + have hv : vals.Nonempty := hsn.image _ + refine ⟨vals.min' hv, ?_, fun y => ?_⟩ + · obtain ⟨o, _, he⟩ := Finset.mem_image.mp (Finset.min'_mem vals hv) + rw [← he] + exact hroot o + · obtain ⟨o, ho, a, b, ha, hay⟩ := hs y + rw [← hay, infinite_cluster_aut G p ha] + exact Finset.min'_le _ _ (Finset.mem_image.mpr ⟨o, ho, rfl⟩) + + + +theorem not_operatorBounded_of_unique [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hqt : QuasiTransitive G) (p : unitInterval) + (hu : law p {ω | ∃! C, C ∈ infiniteClusters G ω} = 1) : ¬ OperatorBounded G p := by + have hp : 0 < p := by + by_contra h + have hp0 : p = 0 := le_antisymm (not_lt.mp h) (bot_le) + subst p + simp [law] at hu + have hpos : 0 < law p {ω | (infiniteClusters G ω).Nonempty} := by + exact lt_of_lt_of_le (show 0 < law p {ω | ∃! C, C ∈ infiniteClusters G ω} by rw [hu]; exact zero_lt_one) + (measure_mono fun ω hω => ⟨hω.choose, hω.choose_spec.1⟩) + obtain ⟨θ, hθ, hroot⟩ := uniform_survival_pos G hconn hqt p hp hpos + have hue : ∀ᵐ ω ∂law p, ∃! C, C ∈ infiniteClusters G ω := + (mem_ae_iff_prob_eq_one (measurableSet_unique_infinite_cluster G)).mpr hu + refine not_operatorBounded_of_positive_column G p (Classical.arbitrary V) (mul_pos hθ hθ) + (fun x => ?_) + refine (mul_le_mul (hroot x) (hroot (Classical.arbitrary V)) hθ.le measureReal_nonneg).trans + ((association_infinite_cluster G p x (Classical.arbitrary V)).trans ?_) + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono_ae + filter_upwards [hue] with ω hω + intro hi + obtain ⟨r, _, hconnr⟩ := (unique_infinite_cluster_iff G ω).mp hω + exact conn_trans G ω (conn_symm G ω (hconnr x hi.1)) (hconnr _ hi.2) + + + +theorem ptwo_le_pu [Infinite V] (G : BondGraph V E) + (hconn : Connected G) (hqt : QuasiTransitive G) : ptwo G ≤ pu G := by + unfold pu ptwo + apply le_sInf + intro p hp + apply sSup_le + intro q hq + by_contra hqp + have hb := operatorBounded_of_le G (le_of_lt (not_le.mp hqp)) hq + exact not_operatorBounded_of_unique G hconn hqt p hp hb + +end UniquenessThreshold + +section DisjointWitness +attribute [local instance] Classical.propDecidable + + +def DisjointOccurrence (A B : Set (Set E)) : Set (Set E) := + {ω | ∃ s t : Finset E, (s : Set E) ⊆ ω ∧ (t : Set E) ⊆ ω ∧ + Disjoint s t ∧ (s : Set E) ∈ A ∧ (t : Set E) ∈ B} + +theorem disjointOccurrence_upper (A B : Set (Set E)) : IsUpperSet (DisjointOccurrence A B) := by + rintro ω η h ⟨s, t, hs, ht, hd, ha, hb⟩ + exact ⟨s, t, hs.trans h, ht.trans h, hd, ha, hb⟩ + +theorem finiteWitness_disjointOccurrence (A B : Set (Set E)) : + FiniteWitness (DisjointOccurrence A B) := by + rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ + refine ⟨s ∪ t, ?_, s, t, ?_, ?_, hd, ha, hb⟩ + · simpa only [Finset.coe_union] using Set.union_subset hs ht + · simp + · simp + +theorem disjointOccurrence_mono {A A' B B' : Set (Set E)} + (hA : A ⊆ A') (hB : B ⊆ B') : DisjointOccurrence A B ⊆ DisjointOccurrence A' B' := by + rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ + exact ⟨s, t, hs, ht, hd, hA ha, hB hb⟩ + + +def openSection (A : Set (Set E)) (e : E) : Set (Set E) := {ω | insert e ω ∈ A} + +theorem openSection_upper {A : Set (Set E)} (hA : IsUpperSet A) (e : E) : + IsUpperSet (openSection A e) := + fun _ _ h hω => hA (Set.insert_subset_insert h) hω + +theorem subset_openSection {A : Set (Set E)} (hA : IsUpperSet A) (e : E) : + A ⊆ openSection A e := fun ω hω => hA (Set.subset_insert e ω) hω + + +theorem openSection_disjointOccurrence (A B : Set (Set E)) (_hA : IsUpperSet A) + (hB : IsUpperSet B) (e : E) : + openSection (DisjointOccurrence A B) e ⊆ + DisjointOccurrence (openSection A e) B ∪ DisjointOccurrence A (openSection B e) := by + rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ + by_cases he : e ∈ s + · left + have het : e ∉ t := fun h => Finset.disjoint_left.mp hd he h + refine ⟨s.erase e, t, ?_, ?_, Finset.disjoint_of_subset_left (Finset.erase_subset _ _) hd, ?_, hb⟩ + · intro z hz + exact (hs (Finset.mem_of_mem_erase hz)).resolve_left (Finset.ne_of_mem_erase hz) + · intro z hz + rcases ht hz with rfl | hz' + · exact (het hz).elim + · exact hz' + · change insert e (↑(s.erase e) : Set E) ∈ A + simpa only [← Finset.coe_insert, Finset.insert_erase he] using ha + · right + refine ⟨s, t.erase e, ?_, ?_, Finset.disjoint_of_subset_right (Finset.erase_subset _ _) hd, ha, ?_⟩ + · intro z hz + rcases hs hz with rfl | hz' + · exact (he hz).elim + · exact hz' + · intro z hz + exact (ht (Finset.mem_of_mem_erase hz)).resolve_left (Finset.ne_of_mem_erase hz) + · apply hB ?_ hb + intro z hz + by_cases hze : z = e + · exact Or.inl hze + · exact Or.inr (Finset.mem_erase.mpr ⟨hze, hz⟩) + + + +noncomputable def finiteProbability (p : unitInterval) (s : Finset E) (A : Set (Set E)) : ℝ := + ∑ t ∈ s.powerset, if (t : Set E) ∈ A then + (p : ℝ) ^ t.card * (1 - p : ℝ) ^ (s.card - t.card) else 0 + +theorem finiteProbability_nonneg (p : unitInterval) (s : Finset E) (A : Set (Set E)) : + 0 ≤ finiteProbability p s A := by + apply Finset.sum_nonneg + intro t _ + split_ifs + · exact mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) + · exact le_rfl + +theorem finiteProbability_mono (p : unitInterval) (s : Finset E) + {A B : Set (Set E)} (h : A ⊆ B) : finiteProbability p s A ≤ finiteProbability p s B := by + apply Finset.sum_le_sum + intro t _ + split_ifs with ha hb hb + · exact le_rfl + · exact (hb (h ha)).elim + · exact mul_nonneg (pow_nonneg p.2.1 _) (pow_nonneg (sub_nonneg.mpr p.2.2) _) + · exact le_rfl + +theorem finiteProbability_union_add_inter (p : unitInterval) (s : Finset E) + (A B : Set (Set E)) : + finiteProbability p s (A ∪ B) + finiteProbability p s (A ∩ B) = + finiteProbability p s A + finiteProbability p s B := by + simp only [finiteProbability, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro t _ + by_cases ha : (t : Set E) ∈ A <;> by_cases hb : (t : Set E) ∈ B <;> simp [ha, hb] + +@[simp] theorem finiteProbability_empty (p : unitInterval) (A : Set (Set E)) : + finiteProbability p ∅ A = if ∅ ∈ A then 1 else 0 := by + simp [finiteProbability] + +theorem finiteProbability_insert (p : unitInterval) (s : Finset E) (e : E) (he : e ∉ s) + (A : Set (Set E)) : + finiteProbability p (insert e s) A = + (1 - p : ℝ) * finiteProbability p s A + (p : ℝ) * finiteProbability p s (openSection A e) := by + have hd : Disjoint s.powerset (s.powerset.image (insert e)) := by + apply Finset.disjoint_left.mpr + intro t ht himg + obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp himg + exact he ((Finset.mem_powerset.mp ht) (by simp)) + have hinj : Set.InjOn (insert e) (↑s.powerset : Set (Finset E)) := by + intro t ht r hr h + have ht' : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) + have hr' : e ∉ r := fun h => he (Finset.mem_powerset.mp hr h) + have hh := congrArg (fun t : Finset E => t.erase e) h + simpa [ht', hr'] using hh + simp only [finiteProbability, Finset.powerset_insert, Finset.sum_union hd, + Finset.sum_image hinj, Finset.mul_sum, Finset.card_insert_of_notMem he] + congr 1 + · apply Finset.sum_congr rfl + intro t ht + have hcard := Finset.card_le_card (Finset.mem_powerset.mp ht) + have hexp : s.card + 1 - t.card = (s.card - t.card) + 1 := by omega + rw [hexp, pow_succ] + split_ifs <;> simp_all [mul_comm, mul_left_comm] + · apply Finset.sum_congr rfl + intro t ht + have het : e ∉ t := fun h => he (Finset.mem_powerset.mp ht h) + simp only [Finset.card_insert_of_notMem het, Nat.add_sub_add_right, pow_succ, + Finset.coe_insert, openSection, Set.mem_ofPred_eq] + split_ifs <;> simp_all [mul_assoc, mul_comm] + +end DisjointWitness + +section FiniteBK +attribute [local instance] Classical.propDecidable + +@[simp] theorem empty_mem_disjointOccurrence (A B : Set (Set E)) : + (∅ : Set E) ∈ DisjointOccurrence A B ↔ ∅ ∈ A ∧ ∅ ∈ B := by + constructor + · rintro ⟨s, t, hs, ht, _, ha, hb⟩ + have hse : (s : Set E) = ∅ := Set.subset_empty_iff.mp hs + have hte : (t : Set E) = ∅ := Set.subset_empty_iff.mp ht + exact ⟨hse ▸ ha, hte ▸ hb⟩ + · rintro ⟨ha, hb⟩ + exact ⟨∅, ∅, by simp, by simp, by simp, by simpa using ha, by simpa using hb⟩ + + + +theorem finiteProbability_disjointOccurrence_le_half (p : unitInterval) + (hp : (p : ℝ) ≤ 1 / 2) (s : Finset E) (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) : + finiteProbability p s (DisjointOccurrence A B) ≤ + finiteProbability p s A * finiteProbability p s B := by + induction s using Finset.induction_on generalizing A B with + | empty => + simp only [finiteProbability_empty, empty_mem_disjointOccurrence] + by_cases ha : (∅ : Set E) ∈ A <;> by_cases hb : (∅ : Set E) ∈ B <;> simp [ha, hb] + | @insert e s he ih => + let A1 := openSection A e + let B1 := openSection B e + let D00 := DisjointOccurrence A B + let D10 := DisjointOccurrence A1 B + let D01 := DisjointOccurrence A B1 + have hD : D00 ⊆ D10 ∩ D01 := by + intro ω hω + exact ⟨disjointOccurrence_mono (subset_openSection hA e) (Set.Subset.refl _) hω, + disjointOccurrence_mono (Set.Subset.refl _) (subset_openSection hB e) hω⟩ + have hsec : finiteProbability p s (openSection D00 e) ≤ + finiteProbability p s D10 + finiteProbability p s D01 - finiteProbability p s D00 := by + have h1 := finiteProbability_mono p s (openSection_disjointOccurrence A B hA hB e) + have h2 := finiteProbability_mono p s hD + have h3 := finiteProbability_union_add_inter p s D10 D01 + change finiteProbability p s (openSection D00 e) ≤ + finiteProbability p s (D10 ∪ D01) at h1 + linarith + have h00 := ih A B hA hB + have h10 := ih A1 B (openSection_upper hA e) hB + have h01 := ih A B1 hA (openSection_upper hB e) + have ha := finiteProbability_mono p s (subset_openSection hA e) + have hb := finiteProbability_mono p s (subset_openSection hB e) + have hcoef : 0 ≤ 1 - 2 * (p : ℝ) := by linarith + have hdif : 0 ≤ ((p : ℝ) ^ 2) * + (finiteProbability p s A1 - finiteProbability p s A) * + (finiteProbability p s B1 - finiteProbability p s B) := + mul_nonneg (mul_nonneg (sq_nonneg _) (sub_nonneg.mpr ha)) (sub_nonneg.mpr hb) + rw [finiteProbability_insert p s e he, finiteProbability_insert p s e he, + finiteProbability_insert p s e he] + have hm := mul_le_mul_of_nonneg_left hsec p.2.1 + have hm00 := mul_le_mul_of_nonneg_left h00 hcoef + have hm10 := mul_le_mul_of_nonneg_left h10 p.2.1 + have hm01 := mul_le_mul_of_nonneg_left h01 p.2.1 + change (1 - (p : ℝ)) * finiteProbability p s D00 + + (p : ℝ) * finiteProbability p s (openSection D00 e) ≤ + ((1 - (p : ℝ)) * finiteProbability p s A + (p : ℝ) * finiteProbability p s A1) * + ((1 - (p : ℝ)) * finiteProbability p s B + (p : ℝ) * finiteProbability p s B1) + nlinarith + +end FiniteBK + +section BKMeasure +attribute [local instance] Classical.propDecidable +open Filter Topology + + +theorem finiteProbability_univ [Fintype E] (p : unitInterval) (A : Set (Set E)) : + finiteProbability p Finset.univ A = (law p).real A := by + have he : (law p).real A = ∑ ω : Set E, if ω ∈ A then (law p).real {ω} else 0 := by + have h := integral_fintype (μ := law p) (f := A.indicator (fun _ => (1 : ℝ))) + Integrable.of_finite + rw [integral_indicator_const (1 : ℝ) (.of_discrete : MeasurableSet A)] at h + simpa [smul_eq_mul, mul_ite, Set.indicator_apply] using h + rw [he, finiteProbability] + apply Finset.sum_bij (fun (t : Finset E) _ => (t : Set E)) + · simp + · intro a _ b _ h + exact Finset.coe_injective h + · intro ω _ + exact ⟨ω.toFinset, by simp, by simp⟩ + · intro t _ + rw [law, setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ] + simp [Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ, Set.ncard_univ, + Nat.card_eq_fintype_card] + +theorem disjointOccurrence_image {F : Type*} (f : F ↪ E) (A B : Set (Set E)) : + (fun ω => f '' ω) ⁻¹' DisjointOccurrence A B = + DisjointOccurrence ((fun ω => f '' ω) ⁻¹' A) ((fun ω => f '' ω) ⁻¹' B) := by + ext ω + constructor + · rintro ⟨s, t, hs, ht, hd, ha, hb⟩ + let s' := s.preimage f f.injective.injOn + let t' := t.preimage f f.injective.injOn + have hs' : (s' : Set F) = f ⁻¹' (s : Set E) := by simp [s'] + have ht' : (t' : Set F) = f ⁻¹' (t : Set E) := by simp [t'] + have hsI : f '' (s' : Set F) = (s : Set E) := by + rw [hs', Set.image_preimage_eq_of_subset] + exact hs.trans (Set.image_subset_range _ _) + have htI : f '' (t' : Set F) = (t : Set E) := by + rw [ht', Set.image_preimage_eq_of_subset] + exact ht.trans (Set.image_subset_range _ _) + refine ⟨s', t', ?_, ?_, ?_, ?_, ?_⟩ + · rw [hs'] + exact (Set.preimage_mono hs).trans (by rw [Set.preimage_image_eq _ f.injective]) + · rw [ht'] + exact (Set.preimage_mono ht).trans (by rw [Set.preimage_image_eq _ f.injective]) + · apply Finset.disjoint_left.mpr + intro x hx hy + exact Finset.disjoint_left.mp hd (by simpa [s'] using hx) (by simpa [t'] using hy) + · change f '' (s' : Set F) ∈ A + rwa [hsI] + · change f '' (t' : Set F) ∈ B + rwa [htI] + · rintro ⟨s, t, hs, ht, hd, ha, hb⟩ + refine ⟨s.map f, t.map f, ?_, ?_, ?_, ?_, ?_⟩ + · simpa only [Finset.coe_map] using Set.image_mono hs + · simpa only [Finset.coe_map] using Set.image_mono ht + · exact (Finset.disjoint_map f).mpr hd + · simpa only [Finset.coe_map, Set.mem_preimage] using ha + · simpa only [Finset.coe_map, Set.mem_preimage] using hb + +theorem bk_finite_half [Fintype E] (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) + (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) : + (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by + simpa only [finiteProbability_univ] using + finiteProbability_disjointOccurrence_le_half p hp Finset.univ A B hA hB + +theorem bk_restricted_half (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) + (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) (s : Finset E) : + (law p).real {ω | ω ∩ (s : Set E) ∈ DisjointOccurrence A B} ≤ + (law p).real {ω | ω ∩ (s : Set E) ∈ A} * + (law p).real {ω | ω ∩ (s : Set E) ∈ B} := by + let f : (s : Set E) ↪ E := ⟨Subtype.val, Subtype.val_injective⟩ + have hreal (C : Set (Set E)) : + (law p).real {ω | ω ∩ (s : Set E) ∈ C} = + (law p).real {η : Set (s : Set E) | f '' η ∈ C} := by + rw [← law_map_restrict p (s : Set E)] + simp only [Measure.real] + rw [Measure.map_apply (measurable_set_restrict _) MeasurableSet.of_discrete] + congr 2 + ext ω + change ω ∩ (s : Set E) ∈ C ↔ f '' (Subtype.val ⁻¹' ω) ∈ C + have he : f '' (Subtype.val ⁻¹' ω) = ω ∩ (s : Set E) := by + ext e + simp [f, and_comm] + rw [he] + rw [hreal, hreal, hreal] + have hh := bk_finite_half p hp ((fun ω => f '' ω) ⁻¹' A) + ((fun ω => f '' ω) ⁻¹' B) + (fun _ _ h hω => hA (Set.image_mono h) hω) + (fun _ _ h hω => hB (Set.image_mono h) hω) + rw [← disjointOccurrence_image] at hh + exact hh + + +theorem bk_finiteWitness_half [Countable E] (p : unitInterval) (hp : (p : ℝ) ≤ 1 / 2) + (A B : Set (Set E)) (hA : IsUpperSet A) (hB : IsUpperSet B) + (hfA : FiniteWitness A) (hfB : FiniteWitness B) : + (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by + let := Encodable.ofCountable E + have hlim (C : Set (Set E)) (hC : IsUpperSet C) (hfC : FiniteWitness C) : + Tendsto (fun n => (law p).real {ω | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) + atTop (𝓝 ((law p).real C)) := by + have hm : Monotone (fun n => {ω : Set E | ω ∩ (edgeExhaustion (E := E) n : Set E) ∈ C}) := by + intro m n h ω hω + exact hC (Set.inter_subset_inter_right _ (edgeExhaustion_mono h)) hω + have h := tendsto_measure_iUnion_atTop (μ := law p) hm + rw [← witness_eq_union C hC hfC] at h + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp h + apply le_of_tendsto_of_tendsto + (hlim _ (disjointOccurrence_upper A B) (finiteWitness_disjointOccurrence A B)) + ((hlim A hA hfA).mul (hlim B hB hfB)) + exact Filter.Eventually.of_forall fun n => bk_restricted_half p hp A B hA hB (edgeExhaustion n) + +end BKMeasure + +section ORLift +attribute [local instance] Classical.propDecidable + +noncomputable def orParameter (q : unitInterval) (m : ℕ) : unitInterval := + ⟨1 - (1 - (q : ℝ)) ^ m, + sub_nonneg.mpr (pow_le_one₀ (sub_nonneg.mpr q.2.2) (by linarith [q.2.1])), + by linarith [pow_nonneg (sub_nonneg.mpr q.2.2) m]⟩ + +noncomputable abbrev bitLaw (q : unitInterval) : Measure Prop := + unitInterval.toNNReal q • Measure.dirac True + + unitInterval.toNNReal (unitInterval.symm q) • Measure.dirac False + +instance bitLaw_isProbabilityMeasure (q : unitInterval) : IsProbabilityMeasure (bitLaw q) := by + rw [bitLaw, ← map_threshold q] + infer_instance + + +theorem map_nonempty (q : unitInterval) (F : Type*) [Fintype F] : + (law q : Measure (Set F)).map Set.Nonempty = bitLaw (orParameter q (Fintype.card F)) := by + let μ := (law q : Measure (Set F)).map Set.Nonempty + have hm : Measurable (Set.Nonempty : Set F → Prop) := .of_discrete + have : IsProbabilityMeasure μ := inferInstance + have hfalse : μ.real {False} = (1 - (q : ℝ)) ^ Fintype.card F := by + change ((law q).map Set.Nonempty).real {False} = _ + simp only [Measure.real, Measure.map_apply hm (measurableSet_singleton _)] + have he : Set.Nonempty ⁻¹' ({False} : Set Prop) = ({∅} : Set (Set F)) := by + ext ω + simp [Set.not_nonempty_iff_eq_empty] + rw [he] + change (law q).real {∅} = _ + rw [law, setBernoulli_real_singleton q (Set.empty_subset _) Set.finite_univ] + simp [Set.ncard_univ, Nat.card_eq_fintype_card] + have htrue : μ.real {True} = 1 - (1 - (q : ℝ)) ^ Fintype.card F := by + have he : ({True} : Set Prop) = ({False} : Set Prop)ᶜ := by ext b; simp + rw [he, measureReal_compl (measurableSet_singleton _), probReal_univ, hfalse] + apply Measure.ext_of_singleton + intro b + apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp + change μ.real {b} = (bitLaw (orParameter q (Fintype.card F))).real {b} + by_cases hb : b + · have he : b = True := propext (iff_true_intro hb) + subst b + rw [htrue] + simp [bitLaw, Measure.real, orParameter] + · have he : b = False := propext (iff_false_intro hb) + subst b + rw [hfalse] + simp [bitLaw, Measure.real, orParameter] + + +theorem finite_image_lift {F : Type*} (f : F → E) {ω : Set F} (s : Finset E) + (hs : (s : Set E) ⊆ f '' ω) : + ∃ t : Finset F, (t : Set F) ⊆ ω ∧ f '' (t : Set F) = (s : Set E) := by + have hex : ∃ t ⊆ f '' ω, t.Finite ∧ t = (s : Set E) := + ⟨s, hs, s.finite_toSet, rfl⟩ + obtain ⟨t, ht, htf, hti⟩ := Set.exists_subset_image_finite_and.mp hex + exact ⟨htf.toFinset, by simpa using ht, by simpa using hti⟩ + +theorem finiteWitness_image_preimage {F : Type*} (f : F → E) (A : Set (Set E)) + (hA : FiniteWitness A) : FiniteWitness ((fun ω => f '' ω) ⁻¹' A) := by + intro ω hω + obtain ⟨s, hs, ha⟩ := hA (f '' ω) hω + obtain ⟨t, ht, htI⟩ := finite_image_lift f s hs + exact ⟨t, ht, by simpa only [Set.mem_preimage, htI] using ha⟩ + +theorem image_preimage_disjointOccurrence {F : Type*} (f : F → E) (A B : Set (Set E)) : + (fun ω => f '' ω) ⁻¹' DisjointOccurrence A B ⊆ + DisjointOccurrence ((fun ω => f '' ω) ⁻¹' A) ((fun ω => f '' ω) ⁻¹' B) := by + rintro ω ⟨s, t, hs, ht, hd, ha, hb⟩ + obtain ⟨s', hs', hsI⟩ := finite_image_lift f s hs + obtain ⟨t', ht', htI⟩ := finite_image_lift f t ht + refine ⟨s', t', hs', ht', ?_, ?_, ?_⟩ + · apply Finset.disjoint_left.mpr + intro x hx hy + have hxs : f x ∈ (s : Set E) := hsI ▸ Set.mem_image_of_mem f hx + have hxt : f x ∈ (t : Set E) := htI ▸ Set.mem_image_of_mem f hy + exact Finset.disjoint_left.mp hd hxs hxt + · simpa only [Set.mem_preimage, hsI] using ha + · simpa only [Set.mem_preimage, htI] using hb + +end ORLift + +section ORLaw +attribute [local instance] Classical.propDecidable + +theorem map_exists_bitLaw (q : unitInterval) (F : Type*) [Fintype F] : + (Measure.infinitePi (fun _ : F => bitLaw q)).map (fun f : F → Prop => ∃ j, f j) = + bitLaw (orParameter q (Fintype.card F)) := by + have h := map_nonempty q F + unfold law at h + rw [setBernoulli_eq_map, Measure.map_map (Measurable.of_discrete) measurable_setOfPred] at h + simpa only [Set.mem_univ, Function.comp_def, Set.Nonempty, Set.mem_ofPred_eq, + bernoulliMeasure_def, bitLaw] using h + +theorem measurable_image_fst (F : Type*) [Fintype F] : + Measurable (fun ω : Set (E × F) => Prod.fst '' ω) := by + have hm : Measurable (fun ω : Set (E × F) => fun e => ∃ j : F, (e,j) ∈ ω) := by + apply Measurable.of_eval + intro e + apply measurableSet_setOfPred.mp + have he : {ω : Set (E × F) | ∃ j : F, (e,j) ∈ ω} = + ⋃ j : F, {ω : Set (E × F) | (e,j) ∈ ω} := by ext ω; simp + rw [he] + exact MeasurableSet.iUnion fun j => measurableSet_setOfPred.mpr + ((measurable_pi_apply (e,j)).comp MeasurableEquiv.setOfPred.symm.measurable) + have he : (fun ω : Set (E × F) => Prod.fst '' ω) = + (fun f : E → Prop => {e | f e}) ∘ (fun ω e => ∃ j : F, (e,j) ∈ ω) := by + funext ω + ext e + simp [Prod.exists] + rw [he] + exact measurable_setOfPred.comp hm + + +theorem law_map_image_fst (q : unitInterval) (F : Type*) [Fintype F] : + (law q : Measure (Set (E × F))).map (fun ω => Prod.fst '' ω) = + law (orParameter q (Fintype.card F)) := by + let c := MeasurableEquiv.curry E F Prop + let b := fun f : E → F → Prop => fun e => ∃ j, f e j + have hb : Measurable b := Measurable.of_eval + (fun e => (Measurable.of_discrete : Measurable (fun f : F → Prop => ∃j, f j)).comp + (measurable_pi_apply e)) + unfold law + rw [setBernoulli_eq_map, Measure.map_map (measurable_image_fst F) measurable_setOfPred] + simp only [Set.mem_univ] + have he : (fun ω : Set (E × F) => Prod.fst '' ω) ∘ (fun f => {e | f e}) = + (fun f : E → Prop => {e | f e}) ∘ b ∘ c := by + funext f + ext e + simp [b, c, Function.comp_def, Prod.exists] + rw [he, ← Measure.map_map measurable_setOfPred (hb.comp c.measurable), + ← Measure.map_map hb c.measurable] + change ((Measure.infinitePi (fun _ : E × F => bitLaw q)).map c |>.map b |>.map + (fun f : E → Prop => {e | f e})) = _ + rw [Measure.infinitePi_map_curry (fun (_ : E) (_ : F) => bitLaw q)] + dsimp only [b] + rw [Measure.infinitePi_map_pi _ (fun _ => Measurable.of_discrete)] + rw [map_exists_bitLaw q F] + rw [setBernoulli_eq_map] + rfl + + +theorem exists_orParameter (p : unitInterval) (hp : p < 1) : + ∃ m : ℕ, ∃ q : unitInterval, (q : ℝ) ≤ 1 / 2 ∧ orParameter q m = p := by + obtain ⟨m, hm⟩ := exists_pow_lt_of_lt_one (show 0 < 1 - (p : ℝ) by exact sub_pos.mpr hp) + (show (1 / 2 : ℝ) < 1 by norm_num) + let f := fun x : ℝ => 1 - (1-x)^m + have hf : Continuous f := by fun_prop + have h0 : f 0 = 0 := by simp [f] + have hp' : (p : ℝ) ∈ Set.Icc (f 0) (f (1/2)) := by + rw [h0] + refine ⟨p.2.1, ?_⟩ + dsimp [f] + norm_num at hm ⊢ + linarith + obtain ⟨q, hq, hqp⟩ := intermediate_value_Icc (by norm_num : (0 : ℝ) ≤ 1/2) + hf.continuousOn hp' + refine ⟨m, ⟨q, hq.1, hq.2.trans (by norm_num)⟩, hq.2, ?_⟩ + apply Subtype.ext + exact hqp + +end ORLaw + +section BK +attribute [local instance] Classical.propDecidable + +theorem disjointOccurrence_subset_inter (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) : DisjointOccurrence A B ⊆ A ∩ B := by + rintro ω ⟨s,t,hs,ht,_,ha,hb⟩ + exact ⟨hA hs ha, hB ht hb⟩ + + + +theorem bk [Countable E] (p : unitInterval) (A B : Set (Set E)) + (hA : IsUpperSet A) (hB : IsUpperSet B) + (hfA : FiniteWitness A) (hfB : FiniteWitness B) : + (law p).real (DisjointOccurrence A B) ≤ (law p).real A * (law p).real B := by + by_cases hp : p = 1 + · subst p + by_cases hu : Set.univ ∈ DisjointOccurrence A B + · have ha := (disjointOccurrence_subset_inter A B hA hB hu).1 + have hb := (disjointOccurrence_subset_inter A B hA hB hu).2 + simp [law, Measure.real, hu, ha, hb] + · simp [law, Measure.real, hu] + positivity + · have hp' : p < 1 := lt_of_le_of_ne p.2.2 hp + obtain ⟨m, q, hq, hqp⟩ := exists_orParameter p hp' + let f : E × Fin m → E := Prod.fst + let A' := (fun ω => f '' ω) ⁻¹' A + let B' := (fun ω => f '' ω) ⁻¹' B + have hreal (C : Set (Set E)) (hC : MeasurableSet C) : + (law p).real C = (law q).real ((fun ω : Set (E × Fin m) => f '' ω) ⁻¹' C) := by + have hh := law_map_image_fst (E := E) q (Fin m) + simp only [Fintype.card_fin, hqp] at hh + rw [← hh] + simp only [Measure.real, Measure.map_apply (measurable_image_fst (Fin m)) hC] + rfl + calc + (law p).real (DisjointOccurrence A B) = + (law q).real ((fun ω : Set (E × Fin m) => f '' ω) ⁻¹' DisjointOccurrence A B) := + hreal _ (measurableSet_finiteWitness _ (disjointOccurrence_upper A B) + (finiteWitness_disjointOccurrence A B)) + _ ≤ (law q).real (DisjointOccurrence A' B') := + measureReal_mono (image_preimage_disjointOccurrence f A B) + _ ≤ (law q).real A' * (law q).real B' := bk_finiteWitness_half q hq A' B' + (fun _ _ h hω => hA (Set.image_mono h) hω) + (fun _ _ h hω => hB (Set.image_mono h) hω) + (finiteWitness_image_preimage f A hfA) (finiteWitness_image_preimage f B hfB) + _ = (law p).real A * (law p).real B := by + rw [hreal A (measurableSet_finiteWitness A hA hfA), + hreal B (measurableSet_finiteWitness B hB hfB)] + +end BK + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/EndpointMoments.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/EndpointMoments.lean index 5e3d48e180c603ef781b2ed8839b934314728916..99cf8ccbfaf811fed15070fde1cd355326bb5b22 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/EndpointMoments.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/EndpointMoments.lean @@ -1,1272 +1,1272 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Amplification - -namespace OAI - -/-! Endpoint Moments for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TrajectoryHitTransport -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} -variable {ι : Type*} [Fintype ι] - - - -theorem visitEnvelope_column_bound (hconn : Connected G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (k : ℕ) (a : V) : - Summable (fun z => q.visitEnvelope o p k z a) ∧ - (∑' z, q.visitEnvelope o p k z a) ≤ c*((k*M:ℕ)*q.successProbability p o ^ k) := by - apply transported_column_of_row_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin - (q.visitEnvelope o p k) (q.visitEnvelope_nonneg o p k) _ - (fun z => (q.visitEnvelope_row_bound o p k z).1) _ - (fun z => (q.visitEnvelope_row_bound o p k z).2) a - intro b hb x y - obtain ⟨d,hd⟩ := hΓ hb - exact q.visitEnvelope_covariant o p k b d hd x y - - - -theorem finiteTrajectoryHit_sum_le (hconn : Connected G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (A : Finset V) - (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : - (∑ z : ↥B, finiteTrajectoryHit G Subtype.val Q p k - (fun ω (x y : ↥B) => q.mass ω x.val y.val) z A) ≤ - (A.card:ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)) := by - have hcol := fun a => q.visitEnvelope_column_bound hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin o p k a - calc - _ ≤ ∑ z : ↥B, ∑ a ∈ A, q.visitEnvelope o p k z.val a := by - apply Finset.sum_le_sum - intro z _ - exact (finiteTrajectoryHit_le_sum G Subtype.val Q p k _ (fun ω x y => q.nonneg ω x.val y.val) z A).trans - (Finset.sum_le_sum fun a _ => q.finiteTrajectoryMass_le_envelope o Q B p k z a hQ) - _ = ∑ a ∈ A, ∑ z : ↥B, q.visitEnvelope o p k z.val a := Finset.sum_comm - _ ≤ ∑ _a ∈ A, c*((k*M:ℕ)*q.successProbability p o ^ k) := by - apply Finset.sum_le_sum - intro a _ - rw [Finset.sum_coe_sort B (fun z => q.visitEnvelope o p k z a)] - exact ((hcol a).1.sum_le_tsum B (fun z _ => q.visitEnvelope_nonneg o p k z a)).trans (hcol a).2 - _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul] - -end LocalEndpointRule -end TrajectoryHitTransport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AllEndpointHit -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteChoiceHit_allRuns {W : Type*} [Fintype W] - (G : BondGraph V E) (e : W → V) (Q : Finset E) (p : ℝ) (k : ℕ) - (q : Set E → W → W → ℝ) (A : Finset V) : - finiteChoiceHit G k Q p - (fun (r : W × (Fin k → W)) _ => e ∘ oldRunVertices k r.1 r.2) - (fun r η => oldRunWeight (fun i => q (η i)) k r.1 r.2) (A : Set V) = - ∑ z : W, finiteTrajectoryHit G e Q p k q z A := by - unfold finiteChoiceHit finiteTrajectoryHit - rw [Fintype.sum_prod_type] - simp only [finiteFamilyIntegral_sum] - -noncomputable def allAmplificationVertices (B : Finset V) (k : ℕ) - (r : ↥B × (Fin k → ↥B)) (_η : ℕ → Set E) : ℕ → V := - amplificationVertices B k r.1 r.2 - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -noncomputable def allAmplificationWeight (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (r : ↥B × (Fin k → ↥B)) (η : ℕ → Set E) : ℝ := - oldRunWeight (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k r.1 r.2 - -noncomputable def allAmplificationInputs (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) - (r : ↥B × (Fin k → ↥B)) : Finset (SpliceState E) := - q.amplificationInputs Q B x k n r.1 r.2 - -theorem allAmplificationWeight_nonneg (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (r : ↥B × (Fin k → ↥B)) (η : ℕ → Set E) : - 0 ≤ q.allAmplificationWeight B k r η := - oldRunWeight_nonneg (fun i (a b : ↥B) => q.mass (η i) a.val b.val) (fun i a b => q.nonneg (η i) a.val b.val) k r.1 r.2 - -variable {ι : Type*} [Fintype ι] - -theorem allAmplificationHit_bound (hconn : Connected G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (A : Set V) (hf : A.Finite) - (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : - finiteChoiceHit G k Q p (allAmplificationVertices B k) (q.allAmplificationWeight B k) A ≤ - (A.ncard:ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)) := by - have he : finiteChoiceHit G k Q p (allAmplificationVertices B k) (q.allAmplificationWeight B k) A = - ∑ z : ↥B, finiteTrajectoryHit G Subtype.val Q p k - (fun ω (a b : ↥B) => q.mass ω a.val b.val) z hf.toFinset := by - rw [← finiteChoiceHit_allRuns] - rw [hf.coe_toFinset] - rfl - rw [he,Set.ncard_eq_toFinset_card A hf] - exact q.finiteTrajectoryHit_sum_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin o Q B p k hf.toFinset hQ - -end LocalEndpointRule -end AllEndpointHit - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AllEndpointSeparated -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteClusterWindowMass (G : BondGraph V E) (Q : Finset E) (p : ℝ) - (x : V) (lo hi : ℕ) : ℝ := - finiteFieldIntegral Q p (fun ω => if (cluster G ω x).Finite ∧ - lo ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < hi then 1 else 0) - -theorem finiteChoiceHit_nonneg {P : Type*} [Fintype P] - (G : BondGraph V E) (k : ℕ) (Q : Finset E) (p : unitInterval) - (y : P → (ℕ → Set E) → ℕ → V) (m : P → (ℕ → Set E) → ℝ) - (hm : ∀ r η, 0 ≤ m r η) (A : Set V) : 0 ≤ finiteChoiceHit G k Q p y m A := by - apply Finset.sum_nonneg - intro r _ - apply finiteFamilyIntegral_nonneg - intro η - split_ifs - · exact hm r η - · exact le_refl _ - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} -variable {ι : Type*} [Fintype ι] - - - -theorem amplificationSeparatedSecondMoment_le [Nonempty E] (hconn : Connected G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (x : V) (k n : ℕ) - (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ Q) : - finiteChoiceSeparatedPairMass G x k Q p - (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) - (allAmplificationVertices B k) (allAmplificationVertices B k) - (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) ≤ - (((2*n:ℕ):ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)))^2 * - finiteClusterWindowMass G Q p x (n-k*M) (2*n) := by - let A := q.allAmplificationInputs Q B x k n - let y := allAmplificationVertices (E := E) B k - let m := q.allAmplificationWeight B k - have hA (r) : A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k) := - q.amplificationInputs_subset Q B x k n r.1 r.2 - have hbin r s (hs : s ∈ A r) : (cluster G s.1 x).Finite ∧ - n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n := by - have hd := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s).mp (hA r hs) - have hb := (q.mem_amplificationInputs Q B x k n r.1 r.2 s).mp hs - exact ⟨cluster_finite_of_finite_edges G (Q.finite_toSet.subset hd.1) x,hb.2.2.2.1,hb.2.2.2.2.1⟩ - have hcap r s (hs : s ∈ A r) (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : - (cluster G (s.2 i) (y r s.2 i)).Finite ∧ (cluster G (s.2 i) (y r s.2 i)).ncard ≤ M := by - have hd := q.amplificationInputs_chain Q B x k n r.1 r.2 s hs i hi hik - exact ⟨hd.2.1,hd.2.2.1⟩ - have hm := q.allAmplificationWeight_nonneg B k - have hb := finiteChoiceSeparatedPairMass_le G hloc x k n M Q p A A y y m m hm hm hA hA hbin - (fun r s hs i hi hik => (hcap r s hs i hi hik).1) hcap - let d : ℝ := c*((k*M:ℕ)*q.successProbability p o ^ k) - have hd : 0 ≤ d := mul_nonneg hc (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (q.successProbability_nonneg p o) _)) - let t : ℝ := ((2*n:ℕ):ℝ)*d - apply hb.trans - unfold finiteClusterWindowMass finiteFieldIntegral - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro ω _ - have he : t^2 * (finiteFieldWeight Q p ω * (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then 1 else 0)) = - finiteFieldWeight Q p ω * (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then t^2 else 0) := by - split_ifs <;> ring - change _ ≤ t^2 * _ - rw [he] - apply mul_le_mul_of_nonneg_left _ (finiteFieldWeight_nonneg Q p ω) - by_cases h : (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n - · rw [ite_eq_left h,ite_eq_left h] - have hhit := q.allAmplificationHit_bound hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin - o Q B p k (cluster G (finiteFieldSet Q ω) x) h.1 hQ - have hc' : ((cluster G (finiteFieldSet Q ω) x).ncard:ℝ) ≤ ((2*n:ℕ):ℝ) := by exact_mod_cast h.2.2.le - have hhit' : finiteChoiceHit G k Q p y m (cluster G (finiteFieldSet Q ω) x) ≤ t := - hhit.trans (mul_le_mul_of_nonneg_right hc' hd) - simpa only [pow_two] using mul_self_le_mul_self - (finiteChoiceHit_nonneg G k Q p y m hm _) hhit' - · rw [ite_eq_right h,ite_eq_right h] - -end LocalEndpointRule -end AllEndpointSeparated - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AllEndpointMarginal -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finiteRootLoad_sum {P : Type*} (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (S : Finset P) (f : P → SpliceState E → ℝ) (ω : FiniteField Q) : - finiteRootLoad Q J p (fun s => ∑ z ∈ S, f z s) ω = - ∑ z ∈ S, finiteRootLoad Q J p (f z) ω := by - simp only [finiteRootLoad,Finset.mul_sum] - exact Finset.sum_comm - - - -theorem finiteChoiceForwardLoad_prod {P R : Type*} [Fintype P] [Fintype R] - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P × R → Finset (SpliceState E)) (y : P × R → SpliceState E → ℕ → V) - (m : SpliceState E → P × R → ℝ) (t : SpliceState E) : - finiteChoiceForwardLoad G x k Q A y m t = ∑ z : P, - finiteChoiceForwardLoad G x k Q (fun r => A (z,r)) (fun r => y (z,r)) - (fun s r => m s (z,r)) t := by - unfold finiteChoiceForwardLoad finiteInverseLoad - rw [Fintype.sum_sigma,Fintype.sum_prod_type] - simp only [Fintype.sum_sigma,choiceTraceOutput,choiceTraceMass,choiceTraceInput] - rfl - - -theorem endpointRootMass_choice_prod {P R : Type*} [Fintype P] [Fintype R] - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) - (A : P × R → Finset (SpliceState E)) (y : P × R → SpliceState E → ℕ → V) - (m : SpliceState E → P × R → ℝ) (e : P → V) (he : Function.Injective e) - (z : P) (ω : Set E) : - endpointRootMass Q (Finset.Icc 1 k) p (choiceTraceOutput G x k Q A y) - (fun a => e a.1.1) (choiceTraceMass G x k Q A y m) ω (e z) = - ∑ a : FiniteChoiceTraceIndex G x k Q (fun r => A (z,r)) (fun r => y (z,r)), - if (choiceTraceOutput G x k Q (fun r => A (z,r)) (fun r => y (z,r)) a).1 = ω then - auxiliaryTupleWeight Q (Finset.Icc 1 k) p - (choiceTraceOutput G x k Q (fun r => A (z,r)) (fun r => y (z,r)) a) * - choiceTraceMass G x k Q (fun r => A (z,r)) (fun r => y (z,r)) (fun s r => m s (z,r)) a else 0 := by - unfold endpointRootMass - rw [Fintype.sum_sigma,Fintype.sum_prod_type] - rw [Finset.sum_eq_single z] - · rw [Fintype.sum_sigma] - simp only [choiceTraceOutput,choiceTraceMass,choiceTraceInput,and_true] - rfl - · intro z' _ hz' - have hh : e z' ≠ e z := fun h => hz' (he h) - simp only [hh,and_false,ite_false,Finset.sum_const_zero] - · intro hz - exact (hz (Finset.mem_univ z)).elim - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -abbrev AmplificationIndex (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) := - FiniteChoiceTraceIndex G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) - -noncomputable def amplificationOutput (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → SpliceState E := - choiceTraceOutput G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) - -noncomputable def amplificationInput (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → SpliceState E := - choiceTraceInput G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) - -noncomputable def amplificationCode (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → List (ℕ × E) := - choiceTraceCode G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) - -noncomputable def amplificationMass (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → ℝ := - choiceTraceMass G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2) - -noncomputable def amplificationRow (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : ℝ := - ∑ z : ↥B, q.amplificationMarginal Q B x k n z p ω - -theorem amplificationRow_eq_load (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : - q.amplificationRow Q B x k n p ω = finiteRootLoad Q (Finset.Icc 1 k) p - (finiteInverseLoad (q.amplificationOutput Q B x k n) (q.amplificationMass Q B x k n)) - (restrictFiniteField Q ω) := by - change _ = finiteRootLoad Q (Finset.Icc 1 k) p - (finiteChoiceForwardLoad G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2)) _ - have hf : (finiteChoiceForwardLoad G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2)) = - (fun t => ∑ z : ↥B, finiteChoiceForwardLoad G x k Q (q.amplificationInputs Q B x k n z) - (fun r _ => amplificationVertices B k z r) (q.amplificationWeight B k z) t) := by - funext t - exact finiteChoiceForwardLoad_prod G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2) t - rw [hf,finiteRootLoad_sum] - rfl - -theorem amplificationEndpointMass_eq (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) (z : ↥B) : - endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) - (fun a => a.1.1.val) (q.amplificationMass Q B x k n) (finiteFieldSet Q ω) z.val = - q.amplificationMarginal Q B x k n z p (finiteFieldSet Q ω) := by - change endpointRootMass Q (Finset.Icc 1 k) p (choiceTraceOutput G x k Q _ _) - _ (choiceTraceMass G x k Q _ _ _) _ _ = _ - rw [endpointRootMass_choice_prod G x k Q p _ _ _ Subtype.val Subtype.val_injective z] - unfold amplificationMarginal finiteChoiceForwardLoad - rw [restrictFiniteField_fieldSet,finiteRootLoad_eq_sum] - · rfl - · intro a - exact traceIndexOutput_mem G x k Q _ _ (q.amplificationInputs_subset Q B x k n z a.1) a.2 - -end LocalEndpointRule -end AllEndpointMarginal - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AmplificationIndexFacts -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -theorem amplificationOutput_mem (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : - q.amplificationOutput Q B x k n a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := - traceIndexOutput_mem G x k Q _ _ (q.amplificationInputs_subset Q B x k n a.1.1 a.1.2) a.2 - -theorem amplificationMass_nonneg (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : - 0 ≤ q.amplificationMass Q B x k n a := - mul_nonneg (q.allAmplificationWeight_nonneg B k a.1 (q.amplificationInput Q B x k n a).2) - (Finset.prod_nonneg fun _ _ => inv_nonneg.mpr (Nat.cast_nonneg _)) - -theorem amplificationIndex_trace (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : - SpliceTrace G x (q.amplificationInput Q B x k n a).2 - (amplificationVertices B k a.1.1 a.1.2) k 0 (q.amplificationInput Q B x k n a).1 - (q.amplificationCode Q B x k n a) (q.amplificationOutput Q B x k n a).1 := - (traceIndex_valid G x k Q _ _ a.2).1 - -theorem amplificationIndex_execution (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : - SpliceExecution G x (q.amplificationInput Q B x k n a) - (q.amplificationCode Q B x k n a) (q.amplificationOutput Q B x k n a) := - (traceIndex_valid G x k Q _ _ a.2).2 - -theorem amplificationIndex_support (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : - x ∈ O ∧ a.1.1.val ∈ O ∧ Conn G (q.amplificationOutput Q B x k n a).1 x a.1.1.val ∧ - (cluster G (q.amplificationOutput Q B x k n a).1 x).Finite ∧ - (cluster G (q.amplificationOutput Q B x k n a).1 x).ncard ≤ 2*n+k*M := - q.amplificationTrace_support Q B x k n a.1.1 a.1.2 a.2.1.val a.2.1.property _ _ - (q.amplificationIndex_trace Q B x k n a) - -theorem amplificationIndex_caps (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) - (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : - (cluster G ((q.amplificationInput Q B x k n a).2 i) (amplificationVertices B k a.1.1 a.1.2 i)).Finite ∧ - (cluster G ((q.amplificationInput Q B x k n a).2 i) (amplificationVertices B k a.1.1 a.1.2 i)).ncard ≤ M := by - have hc := q.amplificationInputs_chain Q B x k n a.1.1 a.1.2 a.2.1.val a.2.1.property i hi hik - exact ⟨hc.2.1,hc.2.2.1⟩ - -theorem amplificationEndpointMass_outside (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) - (z : V) (hz : z ∉ B) : - endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) - (fun a => a.1.1.val) (q.amplificationMass Q B x k n) ω z = 0 := by - apply Finset.sum_eq_zero - intro a _ - split_ifs with h - · exact (hz (h.2 ▸ a.1.1.property)).elim - · rfl - - - -theorem amplificationEndpointMass_bound (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) - (hω : ω ⊆ (Q : Set E)) (z : V) : - endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) - (fun a => a.1.1.val) (q.amplificationMass Q B x k n) ω z ≤ inverseCodeMass M L ^ k := by - by_cases hz : z ∈ B - · let z' : ↥B := ⟨z,hz⟩ - have hfield : finiteFieldSet Q (restrictFiniteField Q ω) = ω := by - rw [finiteFieldSet_restrict,Set.inter_eq_left.mpr hω] - rw [← hfield,q.amplificationEndpointMass_eq Q B x k n p _ z'] - exact (q.amplificationMarginal_bounds hL Q B x k n z' p _).2 - · rw [q.amplificationEndpointMass_outside Q B x k n p ω z hz] - apply pow_nonneg - exact add_nonneg zero_le_one (Finset.sum_nonneg fun l _ => gapWeight_nonneg L (by linarith) l) - -end LocalEndpointRule -end AmplificationIndexFacts - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NoSwitchDensity -attribute [local instance] Classical.propDecidable Classical.decEq - -@[simp] theorem SpliceExecution.nil_iff (G : BondGraph V E) (x : V) (s t : SpliceState E) : - SpliceExecution G x s [] t ↔ s = t := by - constructor - · intro h - cases h - rfl - · rintro rfl - exact SpliceExecution.nil s - -theorem traceIndexMass_nil (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) (hc : traceIndexCode G x k Q A y a = []) : - traceIndexMass G x k Q A y a = 1 := by - change a.2.val = [] at hc - simp [traceIndexMass,hc,traceContactCount] - - - -theorem finiteChoiceNilLoad_le {P : Type*} [Fintype P] - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (m : SpliceState E → P → ℝ) (hm : ∀ s r, 0 ≤ m s r) (t : SpliceState E) : - finiteInverseLoad (choiceTraceOutput G x k Q A y) - (fun a => if choiceTraceCode G x k Q A y a = [] then choiceTraceMass G x k Q A y m a else 0) t ≤ - ∑ r, if t ∈ A r then m t r else 0 := by - let I := FiniteChoiceTraceIndex G x k Q A y - let S : I → Prop := fun a => choiceTraceOutput G x k Q A y a = t ∧ choiceTraceCode G x k Q A y a = [] - let J := {a : I // S a} - have hin (a : J) : choiceTraceInput G x k Q A y a.val = t := by - have he := (traceIndex_valid G x k Q (A a.val.1) (y a.val.1) a.val.2).2 - change SpliceExecution G x (choiceTraceInput G x k Q A y a.val) - (choiceTraceCode G x k Q A y a.val) (choiceTraceOutput G x k Q A y a.val) at he - rw [a.property.1,a.property.2,SpliceExecution.nil_iff] at he - exact he - have hi : Function.Injective (fun a : J => a.val.1) := by - intro a b hab - apply Subtype.ext - apply choiceTrace_injective G x k Q A y - exact Prod.ext ((hin a).trans (hin b).symm) - (Prod.ext hab (a.property.2.trans b.property.2.symm)) - have hm' (a : J) : choiceTraceMass G x k Q A y m a.val = m t a.val.1 := by - unfold choiceTraceMass - rw [hin a,traceIndexMass_nil G x k Q (A a.val.1) (y a.val.1) a.val.2 a.property.2,mul_one] - have hA (a : J) : t ∈ A a.val.1 := (hin a) ▸ a.val.2.1.property - have he : finiteInverseLoad (choiceTraceOutput G x k Q A y) - (fun a => if choiceTraceCode G x k Q A y a = [] then choiceTraceMass G x k Q A y m a else 0) t = - ∑ a : J, m t a.val.1 := by - unfold finiteInverseLoad - simp only [← ite_and] - change (∑ a : I, if S a then choiceTraceMass G x k Q A y m a else 0) = _ - calc - _ = ∑ a : J, choiceTraceMass G x k Q A y m a.val := by - rw [← Finset.sum_filter] - exact Finset.sum_subtype _ (by intro a; simp) _ - _ = _ := Finset.sum_congr rfl (fun a _ => hm' a) - rw [he] - have hb := sum_comp_le_sum_of_injective (fun a : J => a.val.1) hi - (fun r => if t ∈ A r then m t r else 0) (by intro r; split_ifs; exact hm t r; exact le_refl _) - simpa only [ite_eq_left (hA _)] using hb - -end NoSwitchDensity - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section AllEndpointNil -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem oldRunArrival_integral {W : Type*} [Fintype W] - (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (A : Finset W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => oldRunArrival (fun i => q (η i)) k z A) = - oldRunArrival (fun _ => finiteOldKernel Q p q) k z A := by - unfold oldRunArrival - rw [finiteFamilyIntegral_sum] - apply Finset.sum_congr rfl - intro r _ - by_cases h : oldRunVertices k z r 0 ∈ A - · simp only [ite_eq_left h] - exact oldRunWeight_integral Q p k q z r - · simp [h,finiteFamilyIntegral] - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -noncomputable def amplificationNilRow (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : ℝ := - finiteRootLoad Q (Finset.Icc 1 k) p - (finiteInverseLoad (q.amplificationOutput Q B x k n) - (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0)) ω - - - -theorem amplificationNilRow_arrival_le (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : - q.amplificationNilRow Q B x k n p ω ≤ - if n ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - ∑ z : ↥B, oldRunArrival (fun _ => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val)) k z - (Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x) else 0 := by - let A : Finset ↥B := Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x - let H := n ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ (cluster G (finiteFieldSet Q ω) x).ncard < 2*n - have hb (η : ℕ → Set E) : - finiteInverseLoad (q.amplificationOutput Q B x k n) - (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0) - (finiteFieldSet Q ω,η) ≤ - if H then ∑ z : ↥B, oldRunArrival (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z A else 0 := by - apply (finiteChoiceNilLoad_le G x k Q (q.allAmplificationInputs Q B x k n) - (fun r s => allAmplificationVertices B k r s.2) - (fun s r => q.allAmplificationWeight B k r s.2) - (fun s r => q.allAmplificationWeight_nonneg B k r s.2) (finiteFieldSet Q ω,η)).trans - rw [Fintype.sum_prod_type] - by_cases h : H - · rw [ite_eq_left h] - apply Finset.sum_le_sum - intro z _ - apply Finset.sum_le_sum - intro r _ - by_cases hs : (finiteFieldSet Q ω,η) ∈ q.allAmplificationInputs Q B x k n (z,r) - · rw [ite_eq_left hs] - have hi := (q.mem_amplificationInputs Q B x k n z r _).mp hs - have ha : oldRunVertices k z r 0 ∈ A := by - simpa only [A,Finset.mem_filter,Finset.mem_univ,true_and,amplificationVertices] using hi.2.2.2.2.2.1 - rw [ite_eq_left ha] - exact le_rfl - · rw [ite_eq_right hs] - split_ifs - · exact oldRunWeight_nonneg _ (fun i a b => q.nonneg (η i) a.val b.val) k z r - · exact le_refl _ - · rw [ite_eq_right h] - apply le_of_eq - apply Finset.sum_eq_zero - intro z _ - apply Finset.sum_eq_zero - intro r _ - rw [ite_eq_right (by - intro hs - have hi := (q.mem_amplificationInputs Q B x k n z r _).mp hs - exact h ⟨hi.2.2.2.1,hi.2.2.2.2.1⟩)] - change _ ≤ if H then ∑ z : ↥B, - oldRunArrival (fun _ => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val)) k z A else 0 - calc - _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if H then - ∑ z : ↥B, oldRunArrival (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z A else 0) := by - apply Finset.sum_le_sum - intro η _ - exact mul_le_mul_of_nonneg_left (hb _) (finiteFamilyWeight_nonneg Q (Finset.Icc 1 k) p η) - _ = _ := by - by_cases h : H - · simp only [ite_eq_left h,finiteFamilyIntegral_sum] - apply Finset.sum_congr rfl - intro z _ - exact oldRunArrival_integral Q p k (fun η (a b : ↥B) => q.mass η a.val b.val) z A - · simp only [ite_eq_right h,finiteFamilyIntegral,mul_zero,Finset.sum_const_zero] - -end LocalEndpointRule -end AllEndpointNil - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AllEndpointNilBound -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem amplificationNilRow_nonneg {O : Set V} (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : - 0 ≤ q.amplificationNilRow Q B x k n p ω := by - apply finiteRootLoad_nonneg - intro s _ - apply finiteInverseLoad_nonneg - intro a - split_ifs - · exact q.amplificationMass_nonneg Q B x k n a - all_goals exact le_refl _ - - - -theorem amplificationNilRow_bound {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) - (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) - (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : - q.amplificationNilRow Q B x k n p ω ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k := by - apply (q.amplificationNilRow_arrival_le Q B x k n p ω).trans - split_ifs with h - · let A : Finset ↥B := Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x - let K := fun (_ : ℕ) => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val) - have hK (i : ℕ) (a b : ↥B) : K i a b = q.kernel p a.val b.val := - q.finiteOldKernel_eq_kernel Q p a.val b.val (hQ a.val a.property) - have hnK (i : ℕ) (a b : ↥B) : 0 ≤ K i a b := by rw [hK i a b]; exact q.kernel_nonneg p a.val b.val - have hc (i : ℕ) (b : ↥B) : (∑ a, K i a b) ≤ q.successProbability p (root i₀) := by - simp only [hK] - rw [Finset.sum_coe_sort B (fun a => q.kernel p a b.val)] - exact ((q.summable_kernel_column p b.val).sum_le_tsum B (fun a _ => q.kernel_nonneg p a b.val)).trans - (q.kernel_column_le_success root weight Γ htr hΓ hw i₀ hw₀ p b.val) - have hf : (cluster G (finiteFieldSet Q ω) x).Finite := cluster_finite_of_finite_edges G - ω.val.finite_toSet x - have hcard : A.card ≤ 2*n := by - have hh : A.card ≤ hf.toFinset.card := Finset.card_le_card_of_injOn Subtype.val - (by intro a ha; exact hf.mem_toFinset.mpr (Finset.mem_filter.mp ha).2) - (fun _ _ _ _ he => Subtype.val_injective he) - rw [← Set.ncard_eq_toFinset_card (cluster G (finiteFieldSet Q ω) x) hf] at hh - exact hh.trans h.2.le - calc - _ ≤ (A.card:ℝ) * q.successProbability p (root i₀)^k := - sum_oldRunArrival_le K hnK _ (q.successProbability_nonneg p (root i₀)) hc k A - _ ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k := - mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) (pow_nonneg (q.successProbability_nonneg p (root i₀)) _) - · exact mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (q.successProbability_nonneg p (root i₀)) _) - -end LocalEndpointRule -end AllEndpointNilBound - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AllEndpointNear -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -noncomputable def amplificationAdded (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : Set V := - cluster G (q.amplificationOutput Q B x k n a).1 x \ cluster G (q.amplificationInput Q B x k n a).1 x - -noncomputable def amplificationNearPairMass (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : ℝ := - ∑ a : q.AmplificationIndex Q B x k n, ∑ b : q.AmplificationIndex Q B x k n, - if (q.amplificationOutput Q B x k n a).1 = (q.amplificationOutput Q B x k n b).1 ∧ - q.amplificationCode Q B x k n a ≠ [] ∧ q.amplificationCode Q B x k n b ≠ [] ∧ - ¬GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b) - then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (pairSpliceOutput (q.amplificationOutput Q B x k n a) (q.amplificationOutput Q B x k n b)) * - q.amplificationMass Q B x k n a * q.amplificationMass Q B x k n b else 0 - - - -theorem amplificationNearPairMass_bound [Nonempty E] - (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) - (Q : Finset E) (B : Finset V) (x : V) (k n d : ℕ) (p : unitInterval) - (hdeg : ∀ a, degree G a ≤ d) : - q.amplificationNearPairMass Q B x k n p ≤ - (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L ^ k * - ∑ a : q.AmplificationIndex Q B x k n, - spliceTupleWeight Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n a) * - q.amplificationMass Q B x k n a := by - let out := q.amplificationOutput Q B x k n - let code := q.amplificationCode Q B x k n - let added := q.amplificationAdded Q B x k n - let m := q.amplificationMass Q B x k n - let e (a : q.AmplificationIndex Q B x k n) := (code a).headD (0,Classical.choice ‹Nonempty E›) |>.2 - have hfin (a : q.AmplificationIndex Q B x k n) : (cluster G (out a).1 x).Finite := - (q.amplificationIndex_support Q B x k n a).2.2.2.1 - have hhead (a : q.AmplificationIndex Q B x k n) (hc : code a ≠ []) : - OpenMarkedPivotal G (out a).1 {a.1.1.val} x (e a) ∧ - hangingSide G (out a).1 x (e a) = added a ∧ - (hangingSide G (out a).1 x (e a)).ncard ≤ k*M := by - cases hh : code a with - | nil => exact (hc hh).elim - | cons w rest => - have ht := q.amplificationIndex_trace Q B x k n a - change SpliceTrace G x (q.amplificationInput Q B x k n a).2 - (amplificationVertices B k a.1.1 a.1.2) k 0 (q.amplificationInput Q B x k n a).1 - (code a) (out a).1 at ht - rw [hh] at ht - have he : e a = w.2 := by simp only [e,hh,List.headD_cons] - rw [he] - refine ⟨?_,ht.head_hanging G x _ _ k 0 w.1 _ _ w.2 rest, - ht.head_hanging_cap G x _ _ k 0 w.1 M _ _ w.2 rest (q.amplificationIndex_caps Q B x k n a)⟩ - simpa only [amplificationVertices,oldRunVertices_last] using - ht.seams_pivotal G x _ _ k 0 _ _ (w::rest) w (List.mem_cons_self) - let S (a : q.AmplificationIndex Q B x k n) : Finset V := if code a = [] then ∅ else - nearHangingEndpoints G hloc (out a).1 x a.1.1.val (e a) (k*M) (hfin a) - let R (a b : q.AmplificationIndex Q B x k n) := code a ≠ [] ∧ code b ≠ [] ∧ - ¬GraphSeparated G (added a) (added b) - have hS (a b : q.AmplificationIndex Q B x k n) (he : (out a).1 = (out b).1) (h : R a b) : - b.1.1.val ∈ S a := by - obtain ⟨hpa,hea,_⟩ := hhead a h.1 - obtain ⟨hpb,heb,hcb⟩ := hhead b h.2.1 - have hn := h.2.2 - rw [← hea,← heb,← he] at hn - rw [← he] at hpb hcb - simp only [S,ite_eq_right h.1] - exact mem_nearHangingEndpoints_of_not_separated G hloc (out a).1 x a.1.1.val b.1.1.val - (e a) (e b) (k*M) (hfin a) hpa hpb hcb hn - have hN (a : q.AmplificationIndex Q B x k n) : (S a).card ≤ (k*M)+(k*M)^2+d*(k*M)^3 := by - by_cases h : code a = [] - · simp only [S,ite_eq_left h,Finset.card_empty,Nat.zero_le] - · simp only [S,ite_eq_right h] - exact nearHangingEndpoints_card_le G hloc (out a).1 x a.1.1.val (e a) (k*M) d - (hfin a) (hhead a h).2.2 hdeg - have hC : 0 ≤ inverseCodeMass M L ^ k := pow_nonneg - (add_nonneg zero_le_one (Finset.sum_nonneg fun l _ => gapWeight_nonneg L (by linarith) l)) _ - simpa only [amplificationNearPairMass,out,m,R,added] using finite_near_pair_mass_le Q (Finset.Icc 1 k) (Finset.Icc 1 k) p out out m m - (q.amplificationMass_nonneg Q B x k n) (q.amplificationMass_nonneg Q B x k n) - (fun a => a.1.1.val) R S hS ((k*M)+(k*M)^2+d*(k*M)^3) hN _ hC - (fun a z _ => q.amplificationEndpointMass_bound hL Q B x k n p (out a).1 - ((mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) (out a)).mp (q.amplificationOutput_mem Q B x k n a)).1 z) - -end LocalEndpointRule -end AllEndpointNear - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section FiniteThreeClass -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def commonRootPairMass {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) - (m : I → ℝ) (P : I → I → Prop) : ℝ := - ∑ a, ∑ b, if (out a).1 = (out b).1 ∧ P a b then - jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) * m a * m b else 0 - - - -theorem finiteRootLoad_three_classes_le {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) - (m : I → ℝ) (hm : ∀ a, 0 ≤ m a) (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) - (C : I → Prop) (R : I → I → Prop) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteRootLoad Q J p (finiteInverseLoad out m) ω ^ 2) ≤ - 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteRootLoad Q J p (finiteInverseLoad out (fun a => if C a then m a else 0)) ω * - finiteRootLoad Q J p (finiteInverseLoad out m) ω) + - commonRootPairMass Q J p out m (fun a b => ¬C a ∧ ¬C b ∧ R a b) + - commonRootPairMass Q J p out m (fun a b => ¬C a ∧ ¬C b ∧ ¬R a b) := by - let m₀ := fun a => if C a then m a else 0 - let row := finiteRootLoad Q J p (finiteInverseLoad out m) - let nilrow := finiteRootLoad Q J p (finiteInverseLoad out m₀) - have hcross : (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω * nilrow ω) = - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω := by - apply Finset.sum_congr rfl - intro ω _ - ring - have heq : 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) = - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) + - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω * nilrow ω) := by - rw [hcross]; ring - change _ ≤ 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) + _ + _ - rw [heq] - dsimp only [nilrow,row] - simp only [pow_two,← mul_assoc] - rw [finiteRootLoad_pair_expansion Q J J p out out m m hs hs, - finiteRootLoad_pair_expansion Q J J p out out m₀ m hs hs, - finiteRootLoad_pair_expansion Q J J p out out m m₀ hs hs] - unfold commonRootPairMass - simp only [← Finset.sum_add_distrib] - apply Finset.sum_le_sum - intro a _ - apply Finset.sum_le_sum - intro b _ - have hw : 0 ≤ jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) := - jointTupleWeight_nonneg Q J J p _ - have ht : 0 ≤ jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) * m a * m b := - mul_nonneg (mul_nonneg hw (hm a)) (hm b) - dsimp only [m₀] - by_cases hab : (out a).1 = (out b).1 - · simp only [hab,true_and,ite_true] - by_cases ha : C a <;> by_cases hb : C b <;> by_cases hr : R a b <;> - simp only [ha,hb,hr,not_true_eq_false,not_false_eq_true,and_true,and_false, - ite_true,ite_false,mul_zero,zero_mul] <;> linarith - · simp only [hab,false_and,ite_false,zero_add,le_refl] - -end FiniteThreeClass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AllEndpointMomentIdentities -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finiteRootLoad_inverse_mean {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) (m : I → ℝ) - (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * finiteRootLoad Q J p (finiteInverseLoad out m) ω) = - ∑ a, spliceTupleWeight Q J p (out a) * m a := by - rw [finiteRootLoad_mean] - simp only [finiteInverseLoad,Finset.mul_sum,mul_ite,mul_zero] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - rw [Finset.sum_ite_eq,ite_eq_left (hs a)] - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -theorem amplificationRow_nonneg (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : - 0 ≤ q.amplificationRow Q B x k n p ω := by - rw [q.amplificationRow_eq_load] - apply finiteRootLoad_nonneg - intro s _ - exact finiteInverseLoad_nonneg _ _ (q.amplificationMass_nonneg Q B x k n) s - -theorem amplificationRow_mean_eq (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : - finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) = - ∑ a : q.AmplificationIndex Q B x k n, - spliceTupleWeight Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n a) * - q.amplificationMass Q B x k n a := by - simp only [finiteFieldIntegral,q.amplificationRow_eq_load,restrictFiniteField_fieldSet] - exact finiteRootLoad_inverse_mean Q (Finset.Icc 1 k) p _ _ (q.amplificationOutput_mem Q B x k n) - - - -theorem amplificationSeparated_class_eq (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : - commonRootPairMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) - (q.amplificationMass Q B x k n) (fun a b => - q.amplificationCode Q B x k n a ≠ [] ∧ q.amplificationCode Q B x k n b ≠ [] ∧ - GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b)) = - finiteChoiceSeparatedPairMass G x k Q p - (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) - (allAmplificationVertices B k) (allAmplificationVertices B k) - (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) := by - unfold commonRootPairMass finiteChoiceSeparatedPairMass - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - split_ifs with ha hb hb - · rfl - · exfalso - apply hb - dsimp only [amplificationAdded,amplificationOutput,amplificationCode,amplificationInput] at ha - rcases ha with ⟨he,hca,hcb,hsep⟩ - refine ⟨he,hca,hcb,?_⟩ - simpa only [he] using hsep - · exfalso - apply ha - dsimp only [amplificationAdded,amplificationOutput,amplificationCode,amplificationInput] - rcases hb with ⟨he,hca,hcb,hsep⟩ - refine ⟨he,hca,hcb,?_⟩ - simpa only [he] using hsep - · rfl - -end LocalEndpointRule -end AllEndpointMomentIdentities - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section AllEndpointSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem amplificationRow_second_moment_le [Nonempty E] (hconn : Connected G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) - (Q : Finset E) (B : Finset V) (p : unitInterval) (x : V) (k n d : ℕ) - (hdeg : ∀ a, degree G a ≤ d) - (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ Q) : - finiteFieldIntegral Q p (fun ω => q.amplificationRow Q B x k n p ω ^ 2) ≤ - (((4*n:ℕ):ℝ) * q.successProbability p (root i₀)^k + - (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L ^ k) * - finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) + - (((2*n:ℕ):ℝ) * (c*((k*M:ℕ)*q.successProbability p (root i₀)^k)))^2 * - finiteClusterWindowMass G Q p x (n-k*M) (2*n) := by - let out := q.amplificationOutput Q B x k n - let m := q.amplificationMass Q B x k n - let C := fun a => q.amplificationCode Q B x k n a = [] - let R := fun a b => ¬GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b) - let row := finiteRootLoad Q (Finset.Icc 1 k) p (finiteInverseLoad out m) - let nilrow := q.amplificationNilRow Q B x k n p - let b₀ := ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω - let bnil := ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω - let S := finiteChoiceSeparatedPairMass G x k Q p - (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) - (allAmplificationVertices B k) (allAmplificationVertices B k) - (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) - have hrow (ω : FiniteField Q) : q.amplificationRow Q B x k n p (finiteFieldSet Q ω) = row ω := by - rw [q.amplificationRow_eq_load,restrictFiniteField_fieldSet] - have hmean : finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) = b₀ := by - simp only [finiteFieldIntegral,hrow,b₀] - have hpart := finiteRootLoad_three_classes_le Q (Finset.Icc 1 k) p out m - (q.amplificationMass_nonneg Q B x k n) (q.amplificationOutput_mem Q B x k n) C R - have hnear_eq : commonRootPairMass Q (Finset.Icc 1 k) p out m - (fun a b => ¬C a ∧ ¬C b ∧ R a b) = q.amplificationNearPairMass Q B x k n p := by - simp only [commonRootPairMass,amplificationNearPairMass,C,R,out,m] - have hsep_eq : commonRootPairMass Q (Finset.Icc 1 k) p out m - (fun a b => ¬C a ∧ ¬C b ∧ ¬R a b) = S := by - simpa only [C,R,not_not] using q.amplificationSeparated_class_eq Q B x k n p - rw [hnear_eq,hsep_eq] at hpart - have hnilfun : finiteInverseLoad out (fun a => @ite ℝ (C a) (Classical.propDecidable _) (m a) 0) = - finiteInverseLoad (q.amplificationOutput Q B x k n) - (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0) := by - apply congrArg (finiteInverseLoad out) - funext a - dsimp only [C,m] - split_ifs <;> rfl - rw [hnilfun] at hpart - change (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω ^ 2) ≤ - 2*bnil + q.amplificationNearPairMass Q B x k n p + S at hpart - have hnil : bnil ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k * b₀ := by - dsimp only [bnil,b₀] - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro ω _ - have hr : 0 ≤ row ω := by rw [← hrow]; exact q.amplificationRow_nonneg Q B x k n p _ - have hn := q.amplificationNilRow_bound root weight Γ htr (fun a ha => hΓ ha) hw i₀ hw₀ Q B x k n p ω - (fun a ha => (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (hQ a ha)) - calc - _ ≤ finiteFieldWeight Q p ω * (((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k) * row ω := - mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (finiteFieldWeight_nonneg Q p ω)) hr - _ = _ := by ring - have hnear := q.amplificationNearPairMass_bound hL Q B x k n d p hdeg - rw [← q.amplificationRow_mean_eq Q B x k n p,hmean] at hnear - have hsep := q.amplificationSeparatedSecondMoment_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin - (root i₀) Q B p x k n hQ - have hfinal := add_le_add (add_le_add (mul_le_mul_of_nonneg_left hnil (show (0:ℝ) ≤ 2 by norm_num)) hnear) hsep - rw [hmean] - simp only [finiteFieldIntegral,hrow] - apply hpart.trans - convert hfinal using 1 - push_cast - ring - -end LocalEndpointRule -end AllEndpointSecondMoment - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section SpliceCovarianceGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem cluster_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) : - cluster G (b ⁻¹' ω) x = a ⁻¹' cluster G ω (a x) := by - ext y - exact conn_aut_iff G hab ω x y - -theorem exchangeOn_preimage (b : E ≃ E) (mask ω η : Set E) : - exchangeOn (b ⁻¹' mask) (b ⁻¹' ω) (b ⁻¹' η) = b ⁻¹' exchangeOn mask ω η := by - rfl - -theorem spliceMask_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (S B : Set V) (e : E) : - spliceMask G (a ⁻¹' S) (a ⁻¹' B) e = b ⁻¹' spliceMask G S B (b e) := by - ext f - simp only [spliceMask,Set.mem_insert_iff,Set.mem_ofPred_eq,Set.mem_preimage,b.injective.eq_iff] - apply or_congr_right - have hi : internalEdges G (a ⁻¹' S)ᶜ = b ⁻¹' internalEdges G Sᶜ := - internalEdges_aut_preimage G hab Sᶜ - rw [hi] - apply and_congr_left - intro _ - constructor - · rintro ⟨v,hv,hvf⟩ - refine ⟨a v,hv,?_⟩ - rw [hab f] - exact Sym2.mem_map.mpr ⟨v,hvf,rfl⟩ - · rintro ⟨v,hv,hvf⟩ - rw [hab f] at hvf - obtain ⟨w,hw,rfl⟩ := Sym2.mem_map.mp hvf - exact ⟨w,hv,hw⟩ - -theorem spliceField_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (S B : Set V) (e : E) (ω η : Set E) : - spliceField G (a ⁻¹' S) (a ⁻¹' B) e (b ⁻¹' ω) (b ⁻¹' η) = - b ⁻¹' spliceField G S B (b e) ω η := by - rw [spliceField,spliceMask_aut_preimage G hab,exchangeOn_preimage] - rfl - -theorem seamContactCount_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : - seamContactCount G (fun j => b ⁻¹' η j) y (b ⁻¹' ωf) x i e = - seamContactCount G η (fun j => a (y j)) ωf (a x) i (b e) := by - have he : (b ⁻¹' ωf) \ {e} = b ⁻¹' (ωf \ {b e}) := by - ext f - simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] - unfold seamContactCount - rw [he,cluster_aut_preimage G hab] - rw [show (a ⁻¹' cluster G (ωf \ {b e}) (a x))ᶜ = - a ⁻¹' (cluster G (ωf \ {b e}) (a x))ᶜ from rfl] - rw [internalEdges_aut_preimage G hab,← Set.preimage_inter,cluster_aut_preimage G hab, - contactSet_aut_preimage G hab,Set.ncard_preimage_of_injective_subset_range b.injective] - exact fun f _ => b.surjective f - -theorem traceContactCount_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) - (c : List (ℕ × E)) (i : ℕ) : - traceContactCount G (fun j => b ⁻¹' η j) y (b ⁻¹' ωf) x c i = - traceContactCount G η (fun j => a (y j)) ωf (a x) (c.map (Prod.map id b)) i := by - induction c with - | nil => rfl - | cons q c ih => - rcases q with ⟨j,e⟩ - simp only [traceContactCount,List.map_cons,Prod.map_apply,id_eq] - split_ifs - · exact seamContactCount_aut_preimage G hab η y ωf x j e - · exact ih - -end SpliceCovarianceGeometry - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section SpliceCovarianceTrace -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def edgeFieldEquiv (b : E ≃ E) : Set E ≃ Set E where - toFun ω := b.symm ⁻¹' ω - invFun ω := b ⁻¹' ω - left_inv ω := by ext e; simp - right_inv ω := by ext e; simp - -def spliceStateEquiv (b : E ≃ E) : SpliceState E ≃ SpliceState E := - (edgeFieldEquiv b).prodCongr (Equiv.piCongrRight fun _ => edgeFieldEquiv b) - -def spliceCodeEquiv (b : E ≃ E) : List (ℕ × E) ≃ List (ℕ × E) := - Equiv.listEquivOfEquiv ((Equiv.refl ℕ).prodCongr b) - -@[simp] theorem edgeFieldEquiv_apply (b : E ≃ E) (ω : Set E) : - edgeFieldEquiv b ω = b.symm ⁻¹' ω := rfl - -@[simp] theorem spliceCodeEquiv_apply (b : E ≃ E) (c : List (ℕ × E)) : - spliceCodeEquiv b c = c.map (Prod.map id b) := rfl - -theorem cluster_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) : - cluster G (edgeFieldEquiv b ω) (a x) = a.symm ⁻¹' cluster G ω x := by - simpa only [edgeFieldEquiv_apply,Equiv.symm_apply_apply] using - cluster_aut_preimage G (isAut_symm G hab) ω (a x) - -theorem slitCluster_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω η : Set E) (x y : V) : - cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y) = - a.symm ⁻¹' cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y := by - rw [cluster_edgeFieldEquiv G hab] - rw [show (a.symm ⁻¹' cluster G ω x)ᶜ = a.symm ⁻¹' (cluster G ω x)ᶜ from rfl] - rw [internalEdges_aut_preimage G (isAut_symm G hab),edgeFieldEquiv_apply,← Set.preimage_inter, - cluster_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] - -theorem spliceStep_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω η : Set E) (x y : V) (e : E) : - spliceField G (cluster G (edgeFieldEquiv b ω) (a x)) - (cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y)) - (b e) (edgeFieldEquiv b ω) (edgeFieldEquiv b η) = - edgeFieldEquiv b (spliceField G (cluster G ω x) - (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e ω η) := by - rw [slitCluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab] - rw [edgeFieldEquiv_apply,edgeFieldEquiv_apply, - spliceField_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] - rfl - - - -theorem SpliceTrace.aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) - (ω ωf : Set E) (c : List (ℕ × E)) (ht : SpliceTrace G x η y k j ω c ωf) : - SpliceTrace G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j - (edgeFieldEquiv b ω) (spliceCodeEquiv b c) (edgeFieldEquiv b ωf) := by - induction ht with - | stop j ω hs => - apply SpliceTrace.stop - simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hs - | step j i ω e v w rest ωf hn hji hik hmax hy he hev hv hw ht ih => - change SpliceTrace G (a x) _ _ k j _ ((i,b e)::spliceCodeEquiv b rest) _ - refine SpliceTrace.step j i _ (b e) (a v) (a w) _ _ ?_ hji hik ?_ ?_ ?_ ?_ ?_ ?_ ?_ - · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hn - · intro l hil hlk - rw [cluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab, - Set.disjoint_preimage_iff a.symm.surjective] - exact hmax l hil hlk - · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hy - · simpa only [edgeFieldEquiv_apply,Set.mem_preimage,Equiv.symm_apply_apply] using he - · rw [hab e,hev,Sym2.map_mk] - · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hv - · simpa only [slitCluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hw - · rw [spliceStep_edgeFieldEquiv G hab] - exact ih - -end SpliceCovarianceTrace - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section SpliceCovarianceReplay -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem spliceStepMask_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω η : Set E) (x y : V) (e : E) : - spliceMask G (cluster G (edgeFieldEquiv b ω) (a x)) - (cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y)) - (b e) = - edgeFieldEquiv b (spliceMask G (cluster G ω x) - (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e) := by - rw [slitCluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab, - spliceMask_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] - rfl - -theorem exchangeState_aut_map (b : E ≃ E) (mask : Set E) (i : ℕ) (s : SpliceState E) : - exchangeState (edgeFieldEquiv b mask) i (spliceStateEquiv b s) = - spliceStateEquiv b (exchangeState mask i s) := by - apply Prod.ext - · rfl - · funext j - by_cases hji : j = i - · subst j - rw [exchangeState_at] - change _ = edgeFieldEquiv b ((exchangeState mask i s).2 i) - rw [exchangeState_at] - rfl - · rw [exchangeState_away _ _ _ _ hji] - change edgeFieldEquiv b (s.2 j) = edgeFieldEquiv b ((exchangeState mask i s).2 j) - rw [exchangeState_away _ _ _ _ hji] - -theorem replaySplice_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (c : List (ℕ × E)) (ω : Set E) : - replaySplice G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) - (spliceCodeEquiv b c) (edgeFieldEquiv b ω) = - edgeFieldEquiv b (replaySplice G x η y c ω) := by - induction c generalizing ω with - | nil => rfl - | cons q c ih => - rcases q with ⟨i,e⟩ - change replaySplice G (a x) _ _ (spliceCodeEquiv b c) _ = _ - rw [spliceStep_edgeFieldEquiv G hab,ih] - rfl - -theorem replayMasks_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (c : List (ℕ × E)) (ω : Set E) : - replayMasks G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) - (spliceCodeEquiv b c) (edgeFieldEquiv b ω) = - (replayMasks G x η y c ω).map (Prod.map id (edgeFieldEquiv b)) := by - induction c generalizing ω with - | nil => rfl - | cons q c ih => - rcases q with ⟨i,e⟩ - simp only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,replayMasks] - rw [spliceStepMask_edgeFieldEquiv G hab,spliceStep_edgeFieldEquiv G hab] - exact congrArg (List.cons _) (ih _) - -theorem runMasks_aut_map (b : E ≃ E) (c : List (ℕ × Set E)) (s : SpliceState E) : - runMasks (c.map (Prod.map id (edgeFieldEquiv b))) (spliceStateEquiv b s) = - spliceStateEquiv b (runMasks c s) := by - induction c generalizing s with - | nil => rfl - | cons q c ih => - rcases q with ⟨i,mask⟩ - simp only [List.map_cons,Prod.map_apply,id_eq,runMasks] - rw [exchangeState_aut_map,ih] - -theorem seamContactCount_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : - seamContactCount G (fun j => edgeFieldEquiv b (η j)) (fun j => a (y j)) - (edgeFieldEquiv b ωf) (a x) i (b e) = seamContactCount G η y ωf x i e := by - simpa only [edgeFieldEquiv_apply,Equiv.symm_apply_apply] using - seamContactCount_aut_preimage G (isAut_symm G hab) η (fun j => a (y j)) ωf (a x) i (b e) - -theorem traceContactCount_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) - (c : List (ℕ × E)) (i : ℕ) : - traceContactCount G (fun j => edgeFieldEquiv b (η j)) (fun j => a (y j)) - (edgeFieldEquiv b ωf) (a x) (spliceCodeEquiv b c) i = - traceContactCount G η y ωf x c i := by - induction c with - | nil => rfl - | cons q c ih => - rcases q with ⟨j,e⟩ - simp only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,traceContactCount] - split_ifs - · exact seamContactCount_aut_map G hab η y ωf x j e - · exact ih - -end SpliceCovarianceReplay - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Amplification + +namespace OAI + +/-! Endpoint Moments for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TrajectoryHitTransport +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} +variable {ι : Type*} [Fintype ι] + + + +theorem visitEnvelope_column_bound (hconn : Connected G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (k : ℕ) (a : V) : + Summable (fun z => q.visitEnvelope o p k z a) ∧ + (∑' z, q.visitEnvelope o p k z a) ≤ c*((k*M:ℕ)*q.successProbability p o ^ k) := by + apply transported_column_of_row_bound G hconn hloc root weight Γ hΓ htr hcov hw hw1 c hc hmin + (q.visitEnvelope o p k) (q.visitEnvelope_nonneg o p k) _ + (fun z => (q.visitEnvelope_row_bound o p k z).1) _ + (fun z => (q.visitEnvelope_row_bound o p k z).2) a + intro b hb x y + obtain ⟨d,hd⟩ := hΓ hb + exact q.visitEnvelope_covariant o p k b d hd x y + + + +theorem finiteTrajectoryHit_sum_le (hconn : Connected G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (A : Finset V) + (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : + (∑ z : ↥B, finiteTrajectoryHit G Subtype.val Q p k + (fun ω (x y : ↥B) => q.mass ω x.val y.val) z A) ≤ + (A.card:ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)) := by + have hcol := fun a => q.visitEnvelope_column_bound hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin o p k a + calc + _ ≤ ∑ z : ↥B, ∑ a ∈ A, q.visitEnvelope o p k z.val a := by + apply Finset.sum_le_sum + intro z _ + exact (finiteTrajectoryHit_le_sum G Subtype.val Q p k _ (fun ω x y => q.nonneg ω x.val y.val) z A).trans + (Finset.sum_le_sum fun a _ => q.finiteTrajectoryMass_le_envelope o Q B p k z a hQ) + _ = ∑ a ∈ A, ∑ z : ↥B, q.visitEnvelope o p k z.val a := Finset.sum_comm + _ ≤ ∑ _a ∈ A, c*((k*M:ℕ)*q.successProbability p o ^ k) := by + apply Finset.sum_le_sum + intro a _ + rw [Finset.sum_coe_sort B (fun z => q.visitEnvelope o p k z a)] + exact ((hcol a).1.sum_le_tsum B (fun z _ => q.visitEnvelope_nonneg o p k z a)).trans (hcol a).2 + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul] + +end LocalEndpointRule +end TrajectoryHitTransport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AllEndpointHit +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteChoiceHit_allRuns {W : Type*} [Fintype W] + (G : BondGraph V E) (e : W → V) (Q : Finset E) (p : ℝ) (k : ℕ) + (q : Set E → W → W → ℝ) (A : Finset V) : + finiteChoiceHit G k Q p + (fun (r : W × (Fin k → W)) _ => e ∘ oldRunVertices k r.1 r.2) + (fun r η => oldRunWeight (fun i => q (η i)) k r.1 r.2) (A : Set V) = + ∑ z : W, finiteTrajectoryHit G e Q p k q z A := by + unfold finiteChoiceHit finiteTrajectoryHit + rw [Fintype.sum_prod_type] + simp only [finiteFamilyIntegral_sum] + +noncomputable def allAmplificationVertices (B : Finset V) (k : ℕ) + (r : ↥B × (Fin k → ↥B)) (_η : ℕ → Set E) : ℕ → V := + amplificationVertices B k r.1 r.2 + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +noncomputable def allAmplificationWeight (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (r : ↥B × (Fin k → ↥B)) (η : ℕ → Set E) : ℝ := + oldRunWeight (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k r.1 r.2 + +noncomputable def allAmplificationInputs (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) + (r : ↥B × (Fin k → ↥B)) : Finset (SpliceState E) := + q.amplificationInputs Q B x k n r.1 r.2 + +theorem allAmplificationWeight_nonneg (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (r : ↥B × (Fin k → ↥B)) (η : ℕ → Set E) : + 0 ≤ q.allAmplificationWeight B k r η := + oldRunWeight_nonneg (fun i (a b : ↥B) => q.mass (η i) a.val b.val) (fun i a b => q.nonneg (η i) a.val b.val) k r.1 r.2 + +variable {ι : Type*} [Fintype ι] + +theorem allAmplificationHit_bound (hconn : Connected G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (k : ℕ) (A : Set V) (hf : A.Finite) + (hQ : ∀ x ∈ B, incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset ⊆ Q) : + finiteChoiceHit G k Q p (allAmplificationVertices B k) (q.allAmplificationWeight B k) A ≤ + (A.ncard:ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)) := by + have he : finiteChoiceHit G k Q p (allAmplificationVertices B k) (q.allAmplificationWeight B k) A = + ∑ z : ↥B, finiteTrajectoryHit G Subtype.val Q p k + (fun ω (a b : ↥B) => q.mass ω a.val b.val) z hf.toFinset := by + rw [← finiteChoiceHit_allRuns] + rw [hf.coe_toFinset] + rfl + rw [he,Set.ncard_eq_toFinset_card A hf] + exact q.finiteTrajectoryHit_sum_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin o Q B p k hf.toFinset hQ + +end LocalEndpointRule +end AllEndpointHit + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AllEndpointSeparated +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteClusterWindowMass (G : BondGraph V E) (Q : Finset E) (p : ℝ) + (x : V) (lo hi : ℕ) : ℝ := + finiteFieldIntegral Q p (fun ω => if (cluster G ω x).Finite ∧ + lo ≤ (cluster G ω x).ncard ∧ (cluster G ω x).ncard < hi then 1 else 0) + +theorem finiteChoiceHit_nonneg {P : Type*} [Fintype P] + (G : BondGraph V E) (k : ℕ) (Q : Finset E) (p : unitInterval) + (y : P → (ℕ → Set E) → ℕ → V) (m : P → (ℕ → Set E) → ℝ) + (hm : ∀ r η, 0 ≤ m r η) (A : Set V) : 0 ≤ finiteChoiceHit G k Q p y m A := by + apply Finset.sum_nonneg + intro r _ + apply finiteFamilyIntegral_nonneg + intro η + split_ifs + · exact hm r η + · exact le_refl _ + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} +variable {ι : Type*} [Fintype ι] + + + +theorem amplificationSeparatedSecondMoment_le [Nonempty E] (hconn : Connected G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (x : V) (k n : ℕ) + (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ Q) : + finiteChoiceSeparatedPairMass G x k Q p + (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) + (allAmplificationVertices B k) (allAmplificationVertices B k) + (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) ≤ + (((2*n:ℕ):ℝ) * (c*((k*M:ℕ)*q.successProbability p o ^ k)))^2 * + finiteClusterWindowMass G Q p x (n-k*M) (2*n) := by + let A := q.allAmplificationInputs Q B x k n + let y := allAmplificationVertices (E := E) B k + let m := q.allAmplificationWeight B k + have hA (r) : A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k) := + q.amplificationInputs_subset Q B x k n r.1 r.2 + have hbin r s (hs : s ∈ A r) : (cluster G s.1 x).Finite ∧ + n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n := by + have hd := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s).mp (hA r hs) + have hb := (q.mem_amplificationInputs Q B x k n r.1 r.2 s).mp hs + exact ⟨cluster_finite_of_finite_edges G (Q.finite_toSet.subset hd.1) x,hb.2.2.2.1,hb.2.2.2.2.1⟩ + have hcap r s (hs : s ∈ A r) (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : + (cluster G (s.2 i) (y r s.2 i)).Finite ∧ (cluster G (s.2 i) (y r s.2 i)).ncard ≤ M := by + have hd := q.amplificationInputs_chain Q B x k n r.1 r.2 s hs i hi hik + exact ⟨hd.2.1,hd.2.2.1⟩ + have hm := q.allAmplificationWeight_nonneg B k + have hb := finiteChoiceSeparatedPairMass_le G hloc x k n M Q p A A y y m m hm hm hA hA hbin + (fun r s hs i hi hik => (hcap r s hs i hi hik).1) hcap + let d : ℝ := c*((k*M:ℕ)*q.successProbability p o ^ k) + have hd : 0 ≤ d := mul_nonneg hc (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (q.successProbability_nonneg p o) _)) + let t : ℝ := ((2*n:ℕ):ℝ)*d + apply hb.trans + unfold finiteClusterWindowMass finiteFieldIntegral + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro ω _ + have he : t^2 * (finiteFieldWeight Q p ω * (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then 1 else 0)) = + finiteFieldWeight Q p ω * (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then t^2 else 0) := by + split_ifs <;> ring + change _ ≤ t^2 * _ + rw [he] + apply mul_le_mul_of_nonneg_left _ (finiteFieldWeight_nonneg Q p ω) + by_cases h : (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n + · rw [ite_eq_left h,ite_eq_left h] + have hhit := q.allAmplificationHit_bound hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin + o Q B p k (cluster G (finiteFieldSet Q ω) x) h.1 hQ + have hc' : ((cluster G (finiteFieldSet Q ω) x).ncard:ℝ) ≤ ((2*n:ℕ):ℝ) := by exact_mod_cast h.2.2.le + have hhit' : finiteChoiceHit G k Q p y m (cluster G (finiteFieldSet Q ω) x) ≤ t := + hhit.trans (mul_le_mul_of_nonneg_right hc' hd) + simpa only [pow_two] using mul_self_le_mul_self + (finiteChoiceHit_nonneg G k Q p y m hm _) hhit' + · rw [ite_eq_right h,ite_eq_right h] + +end LocalEndpointRule +end AllEndpointSeparated + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AllEndpointMarginal +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finiteRootLoad_sum {P : Type*} (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (S : Finset P) (f : P → SpliceState E → ℝ) (ω : FiniteField Q) : + finiteRootLoad Q J p (fun s => ∑ z ∈ S, f z s) ω = + ∑ z ∈ S, finiteRootLoad Q J p (f z) ω := by + simp only [finiteRootLoad,Finset.mul_sum] + exact Finset.sum_comm + + + +theorem finiteChoiceForwardLoad_prod {P R : Type*} [Fintype P] [Fintype R] + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P × R → Finset (SpliceState E)) (y : P × R → SpliceState E → ℕ → V) + (m : SpliceState E → P × R → ℝ) (t : SpliceState E) : + finiteChoiceForwardLoad G x k Q A y m t = ∑ z : P, + finiteChoiceForwardLoad G x k Q (fun r => A (z,r)) (fun r => y (z,r)) + (fun s r => m s (z,r)) t := by + unfold finiteChoiceForwardLoad finiteInverseLoad + rw [Fintype.sum_sigma,Fintype.sum_prod_type] + simp only [Fintype.sum_sigma,choiceTraceOutput,choiceTraceMass,choiceTraceInput] + rfl + + +theorem endpointRootMass_choice_prod {P R : Type*} [Fintype P] [Fintype R] + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) + (A : P × R → Finset (SpliceState E)) (y : P × R → SpliceState E → ℕ → V) + (m : SpliceState E → P × R → ℝ) (e : P → V) (he : Function.Injective e) + (z : P) (ω : Set E) : + endpointRootMass Q (Finset.Icc 1 k) p (choiceTraceOutput G x k Q A y) + (fun a => e a.1.1) (choiceTraceMass G x k Q A y m) ω (e z) = + ∑ a : FiniteChoiceTraceIndex G x k Q (fun r => A (z,r)) (fun r => y (z,r)), + if (choiceTraceOutput G x k Q (fun r => A (z,r)) (fun r => y (z,r)) a).1 = ω then + auxiliaryTupleWeight Q (Finset.Icc 1 k) p + (choiceTraceOutput G x k Q (fun r => A (z,r)) (fun r => y (z,r)) a) * + choiceTraceMass G x k Q (fun r => A (z,r)) (fun r => y (z,r)) (fun s r => m s (z,r)) a else 0 := by + unfold endpointRootMass + rw [Fintype.sum_sigma,Fintype.sum_prod_type] + rw [Finset.sum_eq_single z] + · rw [Fintype.sum_sigma] + simp only [choiceTraceOutput,choiceTraceMass,choiceTraceInput,and_true] + rfl + · intro z' _ hz' + have hh : e z' ≠ e z := fun h => hz' (he h) + simp only [hh,and_false,ite_false,Finset.sum_const_zero] + · intro hz + exact (hz (Finset.mem_univ z)).elim + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +abbrev AmplificationIndex (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) := + FiniteChoiceTraceIndex G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) + +noncomputable def amplificationOutput (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → SpliceState E := + choiceTraceOutput G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) + +noncomputable def amplificationInput (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → SpliceState E := + choiceTraceInput G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) + +noncomputable def amplificationCode (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → List (ℕ × E) := + choiceTraceCode G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) + +noncomputable def amplificationMass (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) : q.AmplificationIndex Q B x k n → ℝ := + choiceTraceMass G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2) + +noncomputable def amplificationRow (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : ℝ := + ∑ z : ↥B, q.amplificationMarginal Q B x k n z p ω + +theorem amplificationRow_eq_load (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : + q.amplificationRow Q B x k n p ω = finiteRootLoad Q (Finset.Icc 1 k) p + (finiteInverseLoad (q.amplificationOutput Q B x k n) (q.amplificationMass Q B x k n)) + (restrictFiniteField Q ω) := by + change _ = finiteRootLoad Q (Finset.Icc 1 k) p + (finiteChoiceForwardLoad G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2)) _ + have hf : (finiteChoiceForwardLoad G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2)) = + (fun t => ∑ z : ↥B, finiteChoiceForwardLoad G x k Q (q.amplificationInputs Q B x k n z) + (fun r _ => amplificationVertices B k z r) (q.amplificationWeight B k z) t) := by + funext t + exact finiteChoiceForwardLoad_prod G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) (fun s r => q.allAmplificationWeight B k r s.2) t + rw [hf,finiteRootLoad_sum] + rfl + +theorem amplificationEndpointMass_eq (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) (z : ↥B) : + endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) + (fun a => a.1.1.val) (q.amplificationMass Q B x k n) (finiteFieldSet Q ω) z.val = + q.amplificationMarginal Q B x k n z p (finiteFieldSet Q ω) := by + change endpointRootMass Q (Finset.Icc 1 k) p (choiceTraceOutput G x k Q _ _) + _ (choiceTraceMass G x k Q _ _ _) _ _ = _ + rw [endpointRootMass_choice_prod G x k Q p _ _ _ Subtype.val Subtype.val_injective z] + unfold amplificationMarginal finiteChoiceForwardLoad + rw [restrictFiniteField_fieldSet,finiteRootLoad_eq_sum] + · rfl + · intro a + exact traceIndexOutput_mem G x k Q _ _ (q.amplificationInputs_subset Q B x k n z a.1) a.2 + +end LocalEndpointRule +end AllEndpointMarginal + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AmplificationIndexFacts +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +theorem amplificationOutput_mem (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : + q.amplificationOutput Q B x k n a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := + traceIndexOutput_mem G x k Q _ _ (q.amplificationInputs_subset Q B x k n a.1.1 a.1.2) a.2 + +theorem amplificationMass_nonneg (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : + 0 ≤ q.amplificationMass Q B x k n a := + mul_nonneg (q.allAmplificationWeight_nonneg B k a.1 (q.amplificationInput Q B x k n a).2) + (Finset.prod_nonneg fun _ _ => inv_nonneg.mpr (Nat.cast_nonneg _)) + +theorem amplificationIndex_trace (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : + SpliceTrace G x (q.amplificationInput Q B x k n a).2 + (amplificationVertices B k a.1.1 a.1.2) k 0 (q.amplificationInput Q B x k n a).1 + (q.amplificationCode Q B x k n a) (q.amplificationOutput Q B x k n a).1 := + (traceIndex_valid G x k Q _ _ a.2).1 + +theorem amplificationIndex_execution (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : + SpliceExecution G x (q.amplificationInput Q B x k n a) + (q.amplificationCode Q B x k n a) (q.amplificationOutput Q B x k n a) := + (traceIndex_valid G x k Q _ _ a.2).2 + +theorem amplificationIndex_support (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : + x ∈ O ∧ a.1.1.val ∈ O ∧ Conn G (q.amplificationOutput Q B x k n a).1 x a.1.1.val ∧ + (cluster G (q.amplificationOutput Q B x k n a).1 x).Finite ∧ + (cluster G (q.amplificationOutput Q B x k n a).1 x).ncard ≤ 2*n+k*M := + q.amplificationTrace_support Q B x k n a.1.1 a.1.2 a.2.1.val a.2.1.property _ _ + (q.amplificationIndex_trace Q B x k n a) + +theorem amplificationIndex_caps (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) + (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : + (cluster G ((q.amplificationInput Q B x k n a).2 i) (amplificationVertices B k a.1.1 a.1.2 i)).Finite ∧ + (cluster G ((q.amplificationInput Q B x k n a).2 i) (amplificationVertices B k a.1.1 a.1.2 i)).ncard ≤ M := by + have hc := q.amplificationInputs_chain Q B x k n a.1.1 a.1.2 a.2.1.val a.2.1.property i hi hik + exact ⟨hc.2.1,hc.2.2.1⟩ + +theorem amplificationEndpointMass_outside (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) + (z : V) (hz : z ∉ B) : + endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) + (fun a => a.1.1.val) (q.amplificationMass Q B x k n) ω z = 0 := by + apply Finset.sum_eq_zero + intro a _ + split_ifs with h + · exact (hz (h.2 ▸ a.1.1.property)).elim + · rfl + + + +theorem amplificationEndpointMass_bound (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) + (hω : ω ⊆ (Q : Set E)) (z : V) : + endpointRootMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) + (fun a => a.1.1.val) (q.amplificationMass Q B x k n) ω z ≤ inverseCodeMass M L ^ k := by + by_cases hz : z ∈ B + · let z' : ↥B := ⟨z,hz⟩ + have hfield : finiteFieldSet Q (restrictFiniteField Q ω) = ω := by + rw [finiteFieldSet_restrict,Set.inter_eq_left.mpr hω] + rw [← hfield,q.amplificationEndpointMass_eq Q B x k n p _ z'] + exact (q.amplificationMarginal_bounds hL Q B x k n z' p _).2 + · rw [q.amplificationEndpointMass_outside Q B x k n p ω z hz] + apply pow_nonneg + exact add_nonneg zero_le_one (Finset.sum_nonneg fun l _ => gapWeight_nonneg L (by linarith) l) + +end LocalEndpointRule +end AmplificationIndexFacts + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NoSwitchDensity +attribute [local instance] Classical.propDecidable Classical.decEq + +@[simp] theorem SpliceExecution.nil_iff (G : BondGraph V E) (x : V) (s t : SpliceState E) : + SpliceExecution G x s [] t ↔ s = t := by + constructor + · intro h + cases h + rfl + · rintro rfl + exact SpliceExecution.nil s + +theorem traceIndexMass_nil (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) (hc : traceIndexCode G x k Q A y a = []) : + traceIndexMass G x k Q A y a = 1 := by + change a.2.val = [] at hc + simp [traceIndexMass,hc,traceContactCount] + + + +theorem finiteChoiceNilLoad_le {P : Type*} [Fintype P] + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (m : SpliceState E → P → ℝ) (hm : ∀ s r, 0 ≤ m s r) (t : SpliceState E) : + finiteInverseLoad (choiceTraceOutput G x k Q A y) + (fun a => if choiceTraceCode G x k Q A y a = [] then choiceTraceMass G x k Q A y m a else 0) t ≤ + ∑ r, if t ∈ A r then m t r else 0 := by + let I := FiniteChoiceTraceIndex G x k Q A y + let S : I → Prop := fun a => choiceTraceOutput G x k Q A y a = t ∧ choiceTraceCode G x k Q A y a = [] + let J := {a : I // S a} + have hin (a : J) : choiceTraceInput G x k Q A y a.val = t := by + have he := (traceIndex_valid G x k Q (A a.val.1) (y a.val.1) a.val.2).2 + change SpliceExecution G x (choiceTraceInput G x k Q A y a.val) + (choiceTraceCode G x k Q A y a.val) (choiceTraceOutput G x k Q A y a.val) at he + rw [a.property.1,a.property.2,SpliceExecution.nil_iff] at he + exact he + have hi : Function.Injective (fun a : J => a.val.1) := by + intro a b hab + apply Subtype.ext + apply choiceTrace_injective G x k Q A y + exact Prod.ext ((hin a).trans (hin b).symm) + (Prod.ext hab (a.property.2.trans b.property.2.symm)) + have hm' (a : J) : choiceTraceMass G x k Q A y m a.val = m t a.val.1 := by + unfold choiceTraceMass + rw [hin a,traceIndexMass_nil G x k Q (A a.val.1) (y a.val.1) a.val.2 a.property.2,mul_one] + have hA (a : J) : t ∈ A a.val.1 := (hin a) ▸ a.val.2.1.property + have he : finiteInverseLoad (choiceTraceOutput G x k Q A y) + (fun a => if choiceTraceCode G x k Q A y a = [] then choiceTraceMass G x k Q A y m a else 0) t = + ∑ a : J, m t a.val.1 := by + unfold finiteInverseLoad + simp only [← ite_and] + change (∑ a : I, if S a then choiceTraceMass G x k Q A y m a else 0) = _ + calc + _ = ∑ a : J, choiceTraceMass G x k Q A y m a.val := by + rw [← Finset.sum_filter] + exact Finset.sum_subtype _ (by intro a; simp) _ + _ = _ := Finset.sum_congr rfl (fun a _ => hm' a) + rw [he] + have hb := sum_comp_le_sum_of_injective (fun a : J => a.val.1) hi + (fun r => if t ∈ A r then m t r else 0) (by intro r; split_ifs; exact hm t r; exact le_refl _) + simpa only [ite_eq_left (hA _)] using hb + +end NoSwitchDensity + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section AllEndpointNil +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem oldRunArrival_integral {W : Type*} [Fintype W] + (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (A : Finset W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => oldRunArrival (fun i => q (η i)) k z A) = + oldRunArrival (fun _ => finiteOldKernel Q p q) k z A := by + unfold oldRunArrival + rw [finiteFamilyIntegral_sum] + apply Finset.sum_congr rfl + intro r _ + by_cases h : oldRunVertices k z r 0 ∈ A + · simp only [ite_eq_left h] + exact oldRunWeight_integral Q p k q z r + · simp [h,finiteFamilyIntegral] + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +noncomputable def amplificationNilRow (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : ℝ := + finiteRootLoad Q (Finset.Icc 1 k) p + (finiteInverseLoad (q.amplificationOutput Q B x k n) + (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0)) ω + + + +theorem amplificationNilRow_arrival_le (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : + q.amplificationNilRow Q B x k n p ω ≤ + if n ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + ∑ z : ↥B, oldRunArrival (fun _ => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val)) k z + (Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x) else 0 := by + let A : Finset ↥B := Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x + let H := n ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ (cluster G (finiteFieldSet Q ω) x).ncard < 2*n + have hb (η : ℕ → Set E) : + finiteInverseLoad (q.amplificationOutput Q B x k n) + (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0) + (finiteFieldSet Q ω,η) ≤ + if H then ∑ z : ↥B, oldRunArrival (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z A else 0 := by + apply (finiteChoiceNilLoad_le G x k Q (q.allAmplificationInputs Q B x k n) + (fun r s => allAmplificationVertices B k r s.2) + (fun s r => q.allAmplificationWeight B k r s.2) + (fun s r => q.allAmplificationWeight_nonneg B k r s.2) (finiteFieldSet Q ω,η)).trans + rw [Fintype.sum_prod_type] + by_cases h : H + · rw [ite_eq_left h] + apply Finset.sum_le_sum + intro z _ + apply Finset.sum_le_sum + intro r _ + by_cases hs : (finiteFieldSet Q ω,η) ∈ q.allAmplificationInputs Q B x k n (z,r) + · rw [ite_eq_left hs] + have hi := (q.mem_amplificationInputs Q B x k n z r _).mp hs + have ha : oldRunVertices k z r 0 ∈ A := by + simpa only [A,Finset.mem_filter,Finset.mem_univ,true_and,amplificationVertices] using hi.2.2.2.2.2.1 + rw [ite_eq_left ha] + exact le_rfl + · rw [ite_eq_right hs] + split_ifs + · exact oldRunWeight_nonneg _ (fun i a b => q.nonneg (η i) a.val b.val) k z r + · exact le_refl _ + · rw [ite_eq_right h] + apply le_of_eq + apply Finset.sum_eq_zero + intro z _ + apply Finset.sum_eq_zero + intro r _ + rw [ite_eq_right (by + intro hs + have hi := (q.mem_amplificationInputs Q B x k n z r _).mp hs + exact h ⟨hi.2.2.2.1,hi.2.2.2.2.1⟩)] + change _ ≤ if H then ∑ z : ↥B, + oldRunArrival (fun _ => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val)) k z A else 0 + calc + _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if H then + ∑ z : ↥B, oldRunArrival (fun i (a b : ↥B) => q.mass (η i) a.val b.val) k z A else 0) := by + apply Finset.sum_le_sum + intro η _ + exact mul_le_mul_of_nonneg_left (hb _) (finiteFamilyWeight_nonneg Q (Finset.Icc 1 k) p η) + _ = _ := by + by_cases h : H + · simp only [ite_eq_left h,finiteFamilyIntegral_sum] + apply Finset.sum_congr rfl + intro z _ + exact oldRunArrival_integral Q p k (fun η (a b : ↥B) => q.mass η a.val b.val) z A + · simp only [ite_eq_right h,finiteFamilyIntegral,mul_zero,Finset.sum_const_zero] + +end LocalEndpointRule +end AllEndpointNil + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AllEndpointNilBound +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem amplificationNilRow_nonneg {O : Set V} (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) : + 0 ≤ q.amplificationNilRow Q B x k n p ω := by + apply finiteRootLoad_nonneg + intro s _ + apply finiteInverseLoad_nonneg + intro a + split_ifs + · exact q.amplificationMass_nonneg Q B x k n a + all_goals exact le_refl _ + + + +theorem amplificationNilRow_bound {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) + (hw : ∀ i, 0 ≤ weight i) (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : FiniteField Q) + (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a q.radius).toFinset ⊆ Q) : + q.amplificationNilRow Q B x k n p ω ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k := by + apply (q.amplificationNilRow_arrival_le Q B x k n p ω).trans + split_ifs with h + · let A : Finset ↥B := Finset.univ.filter fun a : ↥B => a.val ∈ cluster G (finiteFieldSet Q ω) x + let K := fun (_ : ℕ) => finiteOldKernel Q p (fun η (a b : ↥B) => q.mass η a.val b.val) + have hK (i : ℕ) (a b : ↥B) : K i a b = q.kernel p a.val b.val := + q.finiteOldKernel_eq_kernel Q p a.val b.val (hQ a.val a.property) + have hnK (i : ℕ) (a b : ↥B) : 0 ≤ K i a b := by rw [hK i a b]; exact q.kernel_nonneg p a.val b.val + have hc (i : ℕ) (b : ↥B) : (∑ a, K i a b) ≤ q.successProbability p (root i₀) := by + simp only [hK] + rw [Finset.sum_coe_sort B (fun a => q.kernel p a b.val)] + exact ((q.summable_kernel_column p b.val).sum_le_tsum B (fun a _ => q.kernel_nonneg p a b.val)).trans + (q.kernel_column_le_success root weight Γ htr hΓ hw i₀ hw₀ p b.val) + have hf : (cluster G (finiteFieldSet Q ω) x).Finite := cluster_finite_of_finite_edges G + ω.val.finite_toSet x + have hcard : A.card ≤ 2*n := by + have hh : A.card ≤ hf.toFinset.card := Finset.card_le_card_of_injOn Subtype.val + (by intro a ha; exact hf.mem_toFinset.mpr (Finset.mem_filter.mp ha).2) + (fun _ _ _ _ he => Subtype.val_injective he) + rw [← Set.ncard_eq_toFinset_card (cluster G (finiteFieldSet Q ω) x) hf] at hh + exact hh.trans h.2.le + calc + _ ≤ (A.card:ℝ) * q.successProbability p (root i₀)^k := + sum_oldRunArrival_le K hnK _ (q.successProbability_nonneg p (root i₀)) hc k A + _ ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k := + mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) (pow_nonneg (q.successProbability_nonneg p (root i₀)) _) + · exact mul_nonneg (Nat.cast_nonneg _) (pow_nonneg (q.successProbability_nonneg p (root i₀)) _) + +end LocalEndpointRule +end AllEndpointNilBound + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AllEndpointNear +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +noncomputable def amplificationAdded (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (a : q.AmplificationIndex Q B x k n) : Set V := + cluster G (q.amplificationOutput Q B x k n a).1 x \ cluster G (q.amplificationInput Q B x k n a).1 x + +noncomputable def amplificationNearPairMass (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : ℝ := + ∑ a : q.AmplificationIndex Q B x k n, ∑ b : q.AmplificationIndex Q B x k n, + if (q.amplificationOutput Q B x k n a).1 = (q.amplificationOutput Q B x k n b).1 ∧ + q.amplificationCode Q B x k n a ≠ [] ∧ q.amplificationCode Q B x k n b ≠ [] ∧ + ¬GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b) + then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (pairSpliceOutput (q.amplificationOutput Q B x k n a) (q.amplificationOutput Q B x k n b)) * + q.amplificationMass Q B x k n a * q.amplificationMass Q B x k n b else 0 + + + +theorem amplificationNearPairMass_bound [Nonempty E] + (q : LocalEndpointRule G hloc O M L) (hL : 1 ≤ L) + (Q : Finset E) (B : Finset V) (x : V) (k n d : ℕ) (p : unitInterval) + (hdeg : ∀ a, degree G a ≤ d) : + q.amplificationNearPairMass Q B x k n p ≤ + (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L ^ k * + ∑ a : q.AmplificationIndex Q B x k n, + spliceTupleWeight Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n a) * + q.amplificationMass Q B x k n a := by + let out := q.amplificationOutput Q B x k n + let code := q.amplificationCode Q B x k n + let added := q.amplificationAdded Q B x k n + let m := q.amplificationMass Q B x k n + let e (a : q.AmplificationIndex Q B x k n) := (code a).headD (0,Classical.choice ‹Nonempty E›) |>.2 + have hfin (a : q.AmplificationIndex Q B x k n) : (cluster G (out a).1 x).Finite := + (q.amplificationIndex_support Q B x k n a).2.2.2.1 + have hhead (a : q.AmplificationIndex Q B x k n) (hc : code a ≠ []) : + OpenMarkedPivotal G (out a).1 {a.1.1.val} x (e a) ∧ + hangingSide G (out a).1 x (e a) = added a ∧ + (hangingSide G (out a).1 x (e a)).ncard ≤ k*M := by + cases hh : code a with + | nil => exact (hc hh).elim + | cons w rest => + have ht := q.amplificationIndex_trace Q B x k n a + change SpliceTrace G x (q.amplificationInput Q B x k n a).2 + (amplificationVertices B k a.1.1 a.1.2) k 0 (q.amplificationInput Q B x k n a).1 + (code a) (out a).1 at ht + rw [hh] at ht + have he : e a = w.2 := by simp only [e,hh,List.headD_cons] + rw [he] + refine ⟨?_,ht.head_hanging G x _ _ k 0 w.1 _ _ w.2 rest, + ht.head_hanging_cap G x _ _ k 0 w.1 M _ _ w.2 rest (q.amplificationIndex_caps Q B x k n a)⟩ + simpa only [amplificationVertices,oldRunVertices_last] using + ht.seams_pivotal G x _ _ k 0 _ _ (w::rest) w (List.mem_cons_self) + let S (a : q.AmplificationIndex Q B x k n) : Finset V := if code a = [] then ∅ else + nearHangingEndpoints G hloc (out a).1 x a.1.1.val (e a) (k*M) (hfin a) + let R (a b : q.AmplificationIndex Q B x k n) := code a ≠ [] ∧ code b ≠ [] ∧ + ¬GraphSeparated G (added a) (added b) + have hS (a b : q.AmplificationIndex Q B x k n) (he : (out a).1 = (out b).1) (h : R a b) : + b.1.1.val ∈ S a := by + obtain ⟨hpa,hea,_⟩ := hhead a h.1 + obtain ⟨hpb,heb,hcb⟩ := hhead b h.2.1 + have hn := h.2.2 + rw [← hea,← heb,← he] at hn + rw [← he] at hpb hcb + simp only [S,ite_eq_right h.1] + exact mem_nearHangingEndpoints_of_not_separated G hloc (out a).1 x a.1.1.val b.1.1.val + (e a) (e b) (k*M) (hfin a) hpa hpb hcb hn + have hN (a : q.AmplificationIndex Q B x k n) : (S a).card ≤ (k*M)+(k*M)^2+d*(k*M)^3 := by + by_cases h : code a = [] + · simp only [S,ite_eq_left h,Finset.card_empty,Nat.zero_le] + · simp only [S,ite_eq_right h] + exact nearHangingEndpoints_card_le G hloc (out a).1 x a.1.1.val (e a) (k*M) d + (hfin a) (hhead a h).2.2 hdeg + have hC : 0 ≤ inverseCodeMass M L ^ k := pow_nonneg + (add_nonneg zero_le_one (Finset.sum_nonneg fun l _ => gapWeight_nonneg L (by linarith) l)) _ + simpa only [amplificationNearPairMass,out,m,R,added] using finite_near_pair_mass_le Q (Finset.Icc 1 k) (Finset.Icc 1 k) p out out m m + (q.amplificationMass_nonneg Q B x k n) (q.amplificationMass_nonneg Q B x k n) + (fun a => a.1.1.val) R S hS ((k*M)+(k*M)^2+d*(k*M)^3) hN _ hC + (fun a z _ => q.amplificationEndpointMass_bound hL Q B x k n p (out a).1 + ((mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) (out a)).mp (q.amplificationOutput_mem Q B x k n a)).1 z) + +end LocalEndpointRule +end AllEndpointNear + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section FiniteThreeClass +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def commonRootPairMass {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) + (m : I → ℝ) (P : I → I → Prop) : ℝ := + ∑ a, ∑ b, if (out a).1 = (out b).1 ∧ P a b then + jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) * m a * m b else 0 + + + +theorem finiteRootLoad_three_classes_le {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) + (m : I → ℝ) (hm : ∀ a, 0 ≤ m a) (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) + (C : I → Prop) (R : I → I → Prop) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteRootLoad Q J p (finiteInverseLoad out m) ω ^ 2) ≤ + 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteRootLoad Q J p (finiteInverseLoad out (fun a => if C a then m a else 0)) ω * + finiteRootLoad Q J p (finiteInverseLoad out m) ω) + + commonRootPairMass Q J p out m (fun a b => ¬C a ∧ ¬C b ∧ R a b) + + commonRootPairMass Q J p out m (fun a b => ¬C a ∧ ¬C b ∧ ¬R a b) := by + let m₀ := fun a => if C a then m a else 0 + let row := finiteRootLoad Q J p (finiteInverseLoad out m) + let nilrow := finiteRootLoad Q J p (finiteInverseLoad out m₀) + have hcross : (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω * nilrow ω) = + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω := by + apply Finset.sum_congr rfl + intro ω _ + ring + have heq : 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) = + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) + + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω * nilrow ω) := by + rw [hcross]; ring + change _ ≤ 2 * (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω) + _ + _ + rw [heq] + dsimp only [nilrow,row] + simp only [pow_two,← mul_assoc] + rw [finiteRootLoad_pair_expansion Q J J p out out m m hs hs, + finiteRootLoad_pair_expansion Q J J p out out m₀ m hs hs, + finiteRootLoad_pair_expansion Q J J p out out m m₀ hs hs] + unfold commonRootPairMass + simp only [← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro b _ + have hw : 0 ≤ jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) := + jointTupleWeight_nonneg Q J J p _ + have ht : 0 ≤ jointTupleWeight Q J J p (pairSpliceOutput (out a) (out b)) * m a * m b := + mul_nonneg (mul_nonneg hw (hm a)) (hm b) + dsimp only [m₀] + by_cases hab : (out a).1 = (out b).1 + · simp only [hab,true_and,ite_true] + by_cases ha : C a <;> by_cases hb : C b <;> by_cases hr : R a b <;> + simp only [ha,hb,hr,not_true_eq_false,not_false_eq_true,and_true,and_false, + ite_true,ite_false,mul_zero,zero_mul] <;> linarith + · simp only [hab,false_and,ite_false,zero_add,le_refl] + +end FiniteThreeClass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AllEndpointMomentIdentities +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finiteRootLoad_inverse_mean {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) (m : I → ℝ) + (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * finiteRootLoad Q J p (finiteInverseLoad out m) ω) = + ∑ a, spliceTupleWeight Q J p (out a) * m a := by + rw [finiteRootLoad_mean] + simp only [finiteInverseLoad,Finset.mul_sum,mul_ite,mul_zero] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_ite_eq,ite_eq_left (hs a)] + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +theorem amplificationRow_nonneg (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) (ω : Set E) : + 0 ≤ q.amplificationRow Q B x k n p ω := by + rw [q.amplificationRow_eq_load] + apply finiteRootLoad_nonneg + intro s _ + exact finiteInverseLoad_nonneg _ _ (q.amplificationMass_nonneg Q B x k n) s + +theorem amplificationRow_mean_eq (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : + finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) = + ∑ a : q.AmplificationIndex Q B x k n, + spliceTupleWeight Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n a) * + q.amplificationMass Q B x k n a := by + simp only [finiteFieldIntegral,q.amplificationRow_eq_load,restrictFiniteField_fieldSet] + exact finiteRootLoad_inverse_mean Q (Finset.Icc 1 k) p _ _ (q.amplificationOutput_mem Q B x k n) + + + +theorem amplificationSeparated_class_eq (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (p : unitInterval) : + commonRootPairMass Q (Finset.Icc 1 k) p (q.amplificationOutput Q B x k n) + (q.amplificationMass Q B x k n) (fun a b => + q.amplificationCode Q B x k n a ≠ [] ∧ q.amplificationCode Q B x k n b ≠ [] ∧ + GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b)) = + finiteChoiceSeparatedPairMass G x k Q p + (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) + (allAmplificationVertices B k) (allAmplificationVertices B k) + (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) := by + unfold commonRootPairMass finiteChoiceSeparatedPairMass + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + split_ifs with ha hb hb + · rfl + · exfalso + apply hb + dsimp only [amplificationAdded,amplificationOutput,amplificationCode,amplificationInput] at ha + rcases ha with ⟨he,hca,hcb,hsep⟩ + refine ⟨he,hca,hcb,?_⟩ + simpa only [he] using hsep + · exfalso + apply ha + dsimp only [amplificationAdded,amplificationOutput,amplificationCode,amplificationInput] + rcases hb with ⟨he,hca,hcb,hsep⟩ + refine ⟨he,hca,hcb,?_⟩ + simpa only [he] using hsep + · rfl + +end LocalEndpointRule +end AllEndpointMomentIdentities + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section AllEndpointSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem amplificationRow_second_moment_le [Nonempty E] (hconn : Connected G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) (hL : 1 ≤ L) + (Q : Finset E) (B : Finset V) (p : unitInterval) (x : V) (k n d : ℕ) + (hdeg : ∀ a, degree G a ≤ d) + (hQ : ∀ a ∈ B, incidentSupport G hloc (finite_reachBall hloc a (max q.radius M)).toFinset ⊆ Q) : + finiteFieldIntegral Q p (fun ω => q.amplificationRow Q B x k n p ω ^ 2) ≤ + (((4*n:ℕ):ℝ) * q.successProbability p (root i₀)^k + + (((k*M)+(k*M)^2+d*(k*M)^3:ℕ):ℝ) * inverseCodeMass M L ^ k) * + finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) + + (((2*n:ℕ):ℝ) * (c*((k*M:ℕ)*q.successProbability p (root i₀)^k)))^2 * + finiteClusterWindowMass G Q p x (n-k*M) (2*n) := by + let out := q.amplificationOutput Q B x k n + let m := q.amplificationMass Q B x k n + let C := fun a => q.amplificationCode Q B x k n a = [] + let R := fun a b => ¬GraphSeparated G (q.amplificationAdded Q B x k n a) (q.amplificationAdded Q B x k n b) + let row := finiteRootLoad Q (Finset.Icc 1 k) p (finiteInverseLoad out m) + let nilrow := q.amplificationNilRow Q B x k n p + let b₀ := ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω + let bnil := ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * nilrow ω * row ω + let S := finiteChoiceSeparatedPairMass G x k Q p + (q.allAmplificationInputs Q B x k n) (q.allAmplificationInputs Q B x k n) + (allAmplificationVertices B k) (allAmplificationVertices B k) + (q.allAmplificationWeight B k) (q.allAmplificationWeight B k) + have hrow (ω : FiniteField Q) : q.amplificationRow Q B x k n p (finiteFieldSet Q ω) = row ω := by + rw [q.amplificationRow_eq_load,restrictFiniteField_fieldSet] + have hmean : finiteFieldIntegral Q p (q.amplificationRow Q B x k n p) = b₀ := by + simp only [finiteFieldIntegral,hrow,b₀] + have hpart := finiteRootLoad_three_classes_le Q (Finset.Icc 1 k) p out m + (q.amplificationMass_nonneg Q B x k n) (q.amplificationOutput_mem Q B x k n) C R + have hnear_eq : commonRootPairMass Q (Finset.Icc 1 k) p out m + (fun a b => ¬C a ∧ ¬C b ∧ R a b) = q.amplificationNearPairMass Q B x k n p := by + simp only [commonRootPairMass,amplificationNearPairMass,C,R,out,m] + have hsep_eq : commonRootPairMass Q (Finset.Icc 1 k) p out m + (fun a b => ¬C a ∧ ¬C b ∧ ¬R a b) = S := by + simpa only [C,R,not_not] using q.amplificationSeparated_class_eq Q B x k n p + rw [hnear_eq,hsep_eq] at hpart + have hnilfun : finiteInverseLoad out (fun a => @ite ℝ (C a) (Classical.propDecidable _) (m a) 0) = + finiteInverseLoad (q.amplificationOutput Q B x k n) + (fun a => if q.amplificationCode Q B x k n a = [] then q.amplificationMass Q B x k n a else 0) := by + apply congrArg (finiteInverseLoad out) + funext a + dsimp only [C,m] + split_ifs <;> rfl + rw [hnilfun] at hpart + change (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * row ω ^ 2) ≤ + 2*bnil + q.amplificationNearPairMass Q B x k n p + S at hpart + have hnil : bnil ≤ ((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k * b₀ := by + dsimp only [bnil,b₀] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro ω _ + have hr : 0 ≤ row ω := by rw [← hrow]; exact q.amplificationRow_nonneg Q B x k n p _ + have hn := q.amplificationNilRow_bound root weight Γ htr (fun a ha => hΓ ha) hw i₀ hw₀ Q B x k n p ω + (fun a ha => (incidentSupport_ball_mono G hloc a (le_max_left _ _)).trans (hQ a ha)) + calc + _ ≤ finiteFieldWeight Q p ω * (((2*n:ℕ):ℝ) * q.successProbability p (root i₀)^k) * row ω := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (finiteFieldWeight_nonneg Q p ω)) hr + _ = _ := by ring + have hnear := q.amplificationNearPairMass_bound hL Q B x k n d p hdeg + rw [← q.amplificationRow_mean_eq Q B x k n p,hmean] at hnear + have hsep := q.amplificationSeparatedSecondMoment_le hconn root weight Γ hΓ htr hcov hw hw1 c hc hmin + (root i₀) Q B p x k n hQ + have hfinal := add_le_add (add_le_add (mul_le_mul_of_nonneg_left hnil (show (0:ℝ) ≤ 2 by norm_num)) hnear) hsep + rw [hmean] + simp only [finiteFieldIntegral,hrow] + apply hpart.trans + convert hfinal using 1 + push_cast + ring + +end LocalEndpointRule +end AllEndpointSecondMoment + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section SpliceCovarianceGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem cluster_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) : + cluster G (b ⁻¹' ω) x = a ⁻¹' cluster G ω (a x) := by + ext y + exact conn_aut_iff G hab ω x y + +theorem exchangeOn_preimage (b : E ≃ E) (mask ω η : Set E) : + exchangeOn (b ⁻¹' mask) (b ⁻¹' ω) (b ⁻¹' η) = b ⁻¹' exchangeOn mask ω η := by + rfl + +theorem spliceMask_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (S B : Set V) (e : E) : + spliceMask G (a ⁻¹' S) (a ⁻¹' B) e = b ⁻¹' spliceMask G S B (b e) := by + ext f + simp only [spliceMask,Set.mem_insert_iff,Set.mem_ofPred_eq,Set.mem_preimage,b.injective.eq_iff] + apply or_congr_right + have hi : internalEdges G (a ⁻¹' S)ᶜ = b ⁻¹' internalEdges G Sᶜ := + internalEdges_aut_preimage G hab Sᶜ + rw [hi] + apply and_congr_left + intro _ + constructor + · rintro ⟨v,hv,hvf⟩ + refine ⟨a v,hv,?_⟩ + rw [hab f] + exact Sym2.mem_map.mpr ⟨v,hvf,rfl⟩ + · rintro ⟨v,hv,hvf⟩ + rw [hab f] at hvf + obtain ⟨w,hw,rfl⟩ := Sym2.mem_map.mp hvf + exact ⟨w,hv,hw⟩ + +theorem spliceField_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (S B : Set V) (e : E) (ω η : Set E) : + spliceField G (a ⁻¹' S) (a ⁻¹' B) e (b ⁻¹' ω) (b ⁻¹' η) = + b ⁻¹' spliceField G S B (b e) ω η := by + rw [spliceField,spliceMask_aut_preimage G hab,exchangeOn_preimage] + rfl + +theorem seamContactCount_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : + seamContactCount G (fun j => b ⁻¹' η j) y (b ⁻¹' ωf) x i e = + seamContactCount G η (fun j => a (y j)) ωf (a x) i (b e) := by + have he : (b ⁻¹' ωf) \ {e} = b ⁻¹' (ωf \ {b e}) := by + ext f + simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] + unfold seamContactCount + rw [he,cluster_aut_preimage G hab] + rw [show (a ⁻¹' cluster G (ωf \ {b e}) (a x))ᶜ = + a ⁻¹' (cluster G (ωf \ {b e}) (a x))ᶜ from rfl] + rw [internalEdges_aut_preimage G hab,← Set.preimage_inter,cluster_aut_preimage G hab, + contactSet_aut_preimage G hab,Set.ncard_preimage_of_injective_subset_range b.injective] + exact fun f _ => b.surjective f + +theorem traceContactCount_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) + (c : List (ℕ × E)) (i : ℕ) : + traceContactCount G (fun j => b ⁻¹' η j) y (b ⁻¹' ωf) x c i = + traceContactCount G η (fun j => a (y j)) ωf (a x) (c.map (Prod.map id b)) i := by + induction c with + | nil => rfl + | cons q c ih => + rcases q with ⟨j,e⟩ + simp only [traceContactCount,List.map_cons,Prod.map_apply,id_eq] + split_ifs + · exact seamContactCount_aut_preimage G hab η y ωf x j e + · exact ih + +end SpliceCovarianceGeometry + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section SpliceCovarianceTrace +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def edgeFieldEquiv (b : E ≃ E) : Set E ≃ Set E where + toFun ω := b.symm ⁻¹' ω + invFun ω := b ⁻¹' ω + left_inv ω := by ext e; simp + right_inv ω := by ext e; simp + +def spliceStateEquiv (b : E ≃ E) : SpliceState E ≃ SpliceState E := + (edgeFieldEquiv b).prodCongr (Equiv.piCongrRight fun _ => edgeFieldEquiv b) + +def spliceCodeEquiv (b : E ≃ E) : List (ℕ × E) ≃ List (ℕ × E) := + Equiv.listEquivOfEquiv ((Equiv.refl ℕ).prodCongr b) + +@[simp] theorem edgeFieldEquiv_apply (b : E ≃ E) (ω : Set E) : + edgeFieldEquiv b ω = b.symm ⁻¹' ω := rfl + +@[simp] theorem spliceCodeEquiv_apply (b : E ≃ E) (c : List (ℕ × E)) : + spliceCodeEquiv b c = c.map (Prod.map id b) := rfl + +theorem cluster_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) : + cluster G (edgeFieldEquiv b ω) (a x) = a.symm ⁻¹' cluster G ω x := by + simpa only [edgeFieldEquiv_apply,Equiv.symm_apply_apply] using + cluster_aut_preimage G (isAut_symm G hab) ω (a x) + +theorem slitCluster_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω η : Set E) (x y : V) : + cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y) = + a.symm ⁻¹' cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y := by + rw [cluster_edgeFieldEquiv G hab] + rw [show (a.symm ⁻¹' cluster G ω x)ᶜ = a.symm ⁻¹' (cluster G ω x)ᶜ from rfl] + rw [internalEdges_aut_preimage G (isAut_symm G hab),edgeFieldEquiv_apply,← Set.preimage_inter, + cluster_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] + +theorem spliceStep_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω η : Set E) (x y : V) (e : E) : + spliceField G (cluster G (edgeFieldEquiv b ω) (a x)) + (cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y)) + (b e) (edgeFieldEquiv b ω) (edgeFieldEquiv b η) = + edgeFieldEquiv b (spliceField G (cluster G ω x) + (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e ω η) := by + rw [slitCluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab] + rw [edgeFieldEquiv_apply,edgeFieldEquiv_apply, + spliceField_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] + rfl + + + +theorem SpliceTrace.aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) + (ω ωf : Set E) (c : List (ℕ × E)) (ht : SpliceTrace G x η y k j ω c ωf) : + SpliceTrace G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) k j + (edgeFieldEquiv b ω) (spliceCodeEquiv b c) (edgeFieldEquiv b ωf) := by + induction ht with + | stop j ω hs => + apply SpliceTrace.stop + simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hs + | step j i ω e v w rest ωf hn hji hik hmax hy he hev hv hw ht ih => + change SpliceTrace G (a x) _ _ k j _ ((i,b e)::spliceCodeEquiv b rest) _ + refine SpliceTrace.step j i _ (b e) (a v) (a w) _ _ ?_ hji hik ?_ ?_ ?_ ?_ ?_ ?_ ?_ + · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hn + · intro l hil hlk + rw [cluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab, + Set.disjoint_preimage_iff a.symm.surjective] + exact hmax l hil hlk + · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hy + · simpa only [edgeFieldEquiv_apply,Set.mem_preimage,Equiv.symm_apply_apply] using he + · rw [hab e,hev,Sym2.map_mk] + · simpa only [cluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hv + · simpa only [slitCluster_edgeFieldEquiv G hab,Set.mem_preimage,Equiv.symm_apply_apply] using hw + · rw [spliceStep_edgeFieldEquiv G hab] + exact ih + +end SpliceCovarianceTrace + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section SpliceCovarianceReplay +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem spliceStepMask_edgeFieldEquiv (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω η : Set E) (x y : V) (e : E) : + spliceMask G (cluster G (edgeFieldEquiv b ω) (a x)) + (cluster G (edgeFieldEquiv b η ∩ internalEdges G (cluster G (edgeFieldEquiv b ω) (a x))ᶜ) (a y)) + (b e) = + edgeFieldEquiv b (spliceMask G (cluster G ω x) + (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e) := by + rw [slitCluster_edgeFieldEquiv G hab,cluster_edgeFieldEquiv G hab, + spliceMask_aut_preimage G (isAut_symm G hab),Equiv.symm_apply_apply] + rfl + +theorem exchangeState_aut_map (b : E ≃ E) (mask : Set E) (i : ℕ) (s : SpliceState E) : + exchangeState (edgeFieldEquiv b mask) i (spliceStateEquiv b s) = + spliceStateEquiv b (exchangeState mask i s) := by + apply Prod.ext + · rfl + · funext j + by_cases hji : j = i + · subst j + rw [exchangeState_at] + change _ = edgeFieldEquiv b ((exchangeState mask i s).2 i) + rw [exchangeState_at] + rfl + · rw [exchangeState_away _ _ _ _ hji] + change edgeFieldEquiv b (s.2 j) = edgeFieldEquiv b ((exchangeState mask i s).2 j) + rw [exchangeState_away _ _ _ _ hji] + +theorem replaySplice_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (c : List (ℕ × E)) (ω : Set E) : + replaySplice G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) + (spliceCodeEquiv b c) (edgeFieldEquiv b ω) = + edgeFieldEquiv b (replaySplice G x η y c ω) := by + induction c generalizing ω with + | nil => rfl + | cons q c ih => + rcases q with ⟨i,e⟩ + change replaySplice G (a x) _ _ (spliceCodeEquiv b c) _ = _ + rw [spliceStep_edgeFieldEquiv G hab,ih] + rfl + +theorem replayMasks_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (c : List (ℕ × E)) (ω : Set E) : + replayMasks G (a x) (fun i => edgeFieldEquiv b (η i)) (fun i => a (y i)) + (spliceCodeEquiv b c) (edgeFieldEquiv b ω) = + (replayMasks G x η y c ω).map (Prod.map id (edgeFieldEquiv b)) := by + induction c generalizing ω with + | nil => rfl + | cons q c ih => + rcases q with ⟨i,e⟩ + simp only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,replayMasks] + rw [spliceStepMask_edgeFieldEquiv G hab,spliceStep_edgeFieldEquiv G hab] + exact congrArg (List.cons _) (ih _) + +theorem runMasks_aut_map (b : E ≃ E) (c : List (ℕ × Set E)) (s : SpliceState E) : + runMasks (c.map (Prod.map id (edgeFieldEquiv b))) (spliceStateEquiv b s) = + spliceStateEquiv b (runMasks c s) := by + induction c generalizing s with + | nil => rfl + | cons q c ih => + rcases q with ⟨i,mask⟩ + simp only [List.map_cons,Prod.map_apply,id_eq,runMasks] + rw [exchangeState_aut_map,ih] + +theorem seamContactCount_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : + seamContactCount G (fun j => edgeFieldEquiv b (η j)) (fun j => a (y j)) + (edgeFieldEquiv b ωf) (a x) i (b e) = seamContactCount G η y ωf x i e := by + simpa only [edgeFieldEquiv_apply,Equiv.symm_apply_apply] using + seamContactCount_aut_preimage G (isAut_symm G hab) η (fun j => a (y j)) ωf (a x) i (b e) + +theorem traceContactCount_aut_map (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (η : ℕ → Set E) (y : ℕ → V) (ωf : Set E) (x : V) + (c : List (ℕ × E)) (i : ℕ) : + traceContactCount G (fun j => edgeFieldEquiv b (η j)) (fun j => a (y j)) + (edgeFieldEquiv b ωf) (a x) (spliceCodeEquiv b c) i = + traceContactCount G η y ωf x c i := by + induction c with + | nil => rfl + | cons q c ih => + rcases q with ⟨j,e⟩ + simp only [spliceCodeEquiv_apply,List.map_cons,Prod.map_apply,id_eq,traceContactCount] + split_ifs + · exact seamContactCount_aut_map G hab η y ωf x j e + · exact ih + +end SpliceCovarianceReplay + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/GapCodes.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/GapCodes.lean index 5609233f7dadc8e5f07960c527d684016473b1f8..0543c7dfb92998575df033f7bb3b13e7f557cbb7 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/GapCodes.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/GapCodes.lean @@ -1,1327 +1,1327 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.Geometry - -namespace OAI - -/-! Gap Codes for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SpliceExecution -attribute [local instance] Classical.propDecidable Classical.decEq - - - -abbrev SpliceState (E : Type v) := Set E × (ℕ → Set E) - - - -def exchangeState (mask : Set E) (i : ℕ) (s : SpliceState E) : SpliceState E := - (exchangeOn mask s.1 (s.2 i), Function.update s.2 i (exchangeOn mask (s.2 i) s.1)) - -@[simp] theorem exchangeState_first (mask : Set E) (i : ℕ) (s : SpliceState E) : - (exchangeState mask i s).1 = exchangeOn mask s.1 (s.2 i) := rfl - -@[simp] theorem exchangeState_at (mask : Set E) (i : ℕ) (s : SpliceState E) : - (exchangeState mask i s).2 i = exchangeOn mask (s.2 i) s.1 := by - simp [exchangeState] - -theorem exchangeState_away (mask : Set E) (i l : ℕ) (s : SpliceState E) (hli : l ≠ i) : - (exchangeState mask i s).2 l = s.2 l := by - simp [exchangeState, Function.update_of_ne hli] - -theorem exchangeState_involutive (mask : Set E) (i : ℕ) : - Function.Involutive (exchangeState mask i (E := E)) := by - intro s - apply Prod.ext - · simp only [exchangeState_first, exchangeState_at] - exact exchangeOn_involutive mask s.1 (s.2 i) - · funext l - by_cases hli : l = i - · subst l - simp only [exchangeState_at, exchangeState_first] - exact exchangeOn_involutive mask (s.2 i) s.1 - · rw [exchangeState_away _ _ _ _ hli, exchangeState_away _ _ _ _ hli] - - - -def undoState (G : BondGraph V E) (x : V) (q : ℕ × E) (s : SpliceState E) : - SpliceState E := exchangeState (recoveredMask G s.1 x q.2) q.1 s - - - -def ValidSpliceStep (G : BondGraph V E) (x : V) (s : SpliceState E) - (q : ℕ × E) (s' : SpliceState E) : Prop := - ∃ y a b, - y ∉ cluster G s.1 x ∧ q.2 ∈ s.2 q.1 ∧ G q.2 = s(a,b) ∧ - a ∈ cluster G s.1 x ∧ - b ∈ cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y ∧ - s' = exchangeState - (spliceMask G (cluster G s.1 x) - (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2) q.1 s - -theorem undoState_of_valid (G : BondGraph V E) (x : V) (s s' : SpliceState E) - (q : ℕ × E) (h : ValidSpliceStep G x s q s') : undoState G x q s' = s := by - obtain ⟨y,a,b,hy,he,hab,ha,hb,rfl⟩ := h - unfold undoState - rw [show recoveredMask G - (exchangeState (spliceMask G (cluster G s.1 x) - (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2) q.1 s).1 x q.2 = - spliceMask G (cluster G s.1 x) - (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2 from - recoveredMask_splice G s.1 (s.2 q.1) x y hy q.2 a b hab he ha hb] - exact exchangeState_involutive _ _ s - - -inductive SpliceExecution (G : BondGraph V E) (x : V) : - SpliceState E → List (ℕ × E) → SpliceState E → Prop - | nil (s) : SpliceExecution G x s [] s - | cons (s s' s'') (q qs) - (hstep : ValidSpliceStep G x s q s') - (hrest : SpliceExecution G x s' qs s'') : SpliceExecution G x s (q::qs) s'' - - -def undoExecution (G : BondGraph V E) (x : V) : - List (ℕ × E) → SpliceState E → SpliceState E - | [], s => s - | q::qs, s => undoState G x q (undoExecution G x qs s) - -theorem SpliceExecution.undo (G : BondGraph V E) (x : V) - (s s' : SpliceState E) (code : List (ℕ × E)) - (h : SpliceExecution G x s code s') : undoExecution G x code s' = s := by - induction h with - | nil => rfl - | cons s s' s'' q qs hstep hrest ih => - change undoState G x q (undoExecution G x qs s'') = s - rw [ih] - exact undoState_of_valid G x s s' q hstep - - - -theorem SpliceExecution.input_unique (G : BondGraph V E) (x : V) - (s₁ s₂ out : SpliceState E) (code : List (ℕ × E)) - (h₁ : SpliceExecution G x s₁ code out) (h₂ : SpliceExecution G x s₂ code out) : - s₁ = s₂ := by - exact (h₁.undo G x s₁ out code).symm.trans (h₂.undo G x s₂ out code) - - - -theorem SpliceTrace.realize (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (code : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω code ωf) : - ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → - ∃ θf, SpliceExecution G x (ω,θ) code (ωf,θf) := by - induction h with - | stop j ω hz => - intro θ _ - exact ⟨θ, SpliceExecution.nil _⟩ - | @step j i ω e a b rest ωf _ hji hik _ hy he hab ha hb ht ih => - intro θ hθ - have hθi := hθ i hji hik - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let mask := spliceMask G S B e - let next := exchangeState mask i (ω,θ) - have hnext : next.1 = spliceField G S B e ω (η i) := by - change exchangeOn mask ω (θ i) = exchangeOn mask ω (η i) - rw [hθi] - obtain ⟨θf,hexec⟩ := ih next.2 (by - intro l hil hlk - rw [exchangeState_away _ _ _ _ (by omega)] - exact hθ l (hji.trans hil) hlk) - refine ⟨θf, SpliceExecution.cons (ω,θ) next (ωf,θf) (i,e) rest ?_ ?_⟩ - · refine ⟨y i,a,b,hy,?_,hab,ha,?_,?_⟩ - · simpa only [hθi] using he - · simpa only [hθi] using hb - · dsimp only [next, mask, B, S] - rw [hθi] - · change SpliceExecution G x (next.1,next.2) rest (ωf,θf) - rw [hnext] - exact hexec - -end SpliceExecution - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BridgeCode -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem pivotal_mem_trail (G : BondGraph V E) (ω : Set E) (x z : V) - (l : List E) (hl : Along G x l z) (hopen : ∀ e ∈ l, e ∈ ω) - {e : E} (he : OpenMarkedPivotal G ω {z} x e) : e ∈ l := by - by_contra hnot - apply he.2.2 - refine ⟨z,rfl,hl.conn ?_⟩ - intro f hf - exact ⟨hopen f hf,fun hfe => hnot ((Set.mem_singleton_iff.mp hfe) ▸ hf)⟩ - - -theorem finite_separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) : - {e | OpenMarkedPivotal G ω {z} x e}.Finite := by - by_cases hc : Conn G ω x z - · obtain ⟨l,hl,_,ho⟩ := conn_exists_bond_trail G hc - exact l.toFinset.finite_toSet.subset fun e he => - List.mem_toFinset.mpr (pivotal_mem_trail G ω x z l hl ho he) - · have hempty : {e | OpenMarkedPivotal G ω {z} x e} = ∅ := by - ext e - simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] - rintro ⟨_,⟨y,hy,hxy⟩,_⟩ - exact hc ((Set.mem_singleton_iff.mp hy) ▸ hxy) - rw [hempty] - exact Set.finite_empty - -noncomputable def separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) : Finset E := - (finite_separatingBonds G ω x z).toFinset - -@[simp] theorem mem_separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) (e : E) : - e ∈ separatingBonds G ω x z ↔ OpenMarkedPivotal G ω {z} x e := by - exact (finite_separatingBonds G ω x z).mem_toFinset - - -theorem pivotalRank_injective_of_cluster_finite (G : BondGraph V E) (ω : Set E) - (m : Set V) (x : V) (hC : (cluster G ω x).Finite) : - Set.InjOn (pivotalRank G ω x) {e | OpenMarkedPivotal G ω m x e} := by - have hcut (f : E) : (cluster G (ω \ {f}) x).Finite := - hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) - intro e he f hf heq - by_contra hne - rcases pivotal_rootSides_nested G ω m x he hf hne with h | h - · exact (Nat.ne_of_lt (Set.ncard_lt_ncard h (hcut f))) heq - · exact (Nat.ne_of_lt (Set.ncard_lt_ncard h (hcut e))) heq.symm - - - -noncomputable def bridgeIndex (G : BondGraph V E) (ω : Set E) (x z : V) (e : E) : ℕ := - ((separatingBonds G ω x z).filter fun f => pivotalRank G ω x f ≤ pivotalRank G ω x e).card - -theorem bridgeIndex_pos (G : BondGraph V E) (ω : Set E) (x z : V) {e : E} - (he : OpenMarkedPivotal G ω {z} x e) : 0 < bridgeIndex G ω x z e := by - apply Finset.card_pos.mpr - exact ⟨e,Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z e).mpr he,le_refl _⟩⟩ - -theorem bridgeIndex_lt_of_rank_lt (G : BondGraph V E) (ω : Set E) (x z : V) {e f : E} - (hf : OpenMarkedPivotal G ω {z} x f) - (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : - bridgeIndex G ω x z e < bridgeIndex G ω x z f := by - apply Finset.card_lt_card - apply Finset.ssubset_iff_subset_ne.mpr - refine ⟨?_,?_⟩ - · intro d hd - exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hd).1, - (Finset.mem_filter.mp hd).2.trans (Nat.le_of_lt hlt)⟩ - · intro heq - have hmem : f ∈ (separatingBonds G ω x z).filter - (fun d => pivotalRank G ω x d ≤ pivotalRank G ω x f) := - Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z f).mpr hf,le_refl _⟩ - rw [← heq] at hmem - exact (Nat.not_le_of_lt hlt) (Finset.mem_filter.mp hmem).2 - -theorem bridgeIndex_injective (G : BondGraph V E) (ω : Set E) (x z : V) - (hC : (cluster G ω x).Finite) : - Set.InjOn (bridgeIndex G ω x z) {e | OpenMarkedPivotal G ω {z} x e} := by - intro e he f hf heq - apply pivotalRank_injective_of_cluster_finite G ω {z} x hC he hf - rcases lt_trichotomy (pivotalRank G ω x e) (pivotalRank G ω x f) with h | h | h - · exact ((Nat.ne_of_lt (bridgeIndex_lt_of_rank_lt G ω x z hf h)) heq).elim - · exact h - · exact ((Nat.ne_of_lt (bridgeIndex_lt_of_rank_lt G ω x z he h)) heq.symm).elim - - -noncomputable def ordinalSpliceCode (G : BondGraph V E) (ω : Set E) (x z : V) - (code : List (ℕ × E)) : List (ℕ × ℕ) := - code.map fun q => (q.1,bridgeIndex G ω x z q.2) - -theorem ordinalSpliceCode_injective (G : BondGraph V E) (ω : Set E) (x z : V) - (hC : (cluster G ω x).Finite) (c₁ c₂ : List (ℕ × E)) - (h₁ : ∀ q ∈ c₁, OpenMarkedPivotal G ω {z} x q.2) - (h₂ : ∀ q ∈ c₂, OpenMarkedPivotal G ω {z} x q.2) - (heq : ordinalSpliceCode G ω x z c₁ = ordinalSpliceCode G ω x z c₂) : c₁ = c₂ := by - induction c₁ generalizing c₂ with - | nil => - cases c₂ with - | nil => rfl - | cons q qs => simp [ordinalSpliceCode] at heq - | cons q qs ih => - cases c₂ with - | nil => simp [ordinalSpliceCode] at heq - | cons r rs => - have heq' := List.cons.inj heq - have hqr : q = r := by - apply Prod.ext - · exact congrArg (fun t : ℕ × ℕ => t.1) heq'.1 - · exact bridgeIndex_injective G ω x z hC (h₁ q (by simp)) (h₂ r (by simp)) - (congrArg Prod.snd heq'.1) - exact congrArg₂ List.cons hqr (ih rs - (fun a ha => h₁ a (List.mem_cons_of_mem _ ha)) - (fun a ha => h₂ a (List.mem_cons_of_mem _ ha)) heq'.2) - - - -theorem SpliceTrace.input_unique_of_ordinalCode (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) - (c₁ c₂ : List (ℕ × E)) - (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) - (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) - (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) - (heq : ordinalSpliceCode G ωf x (y₁ k) c₁ = ordinalSpliceCode G ωf x (y₁ k) c₂) - (θf : ℕ → Set E) - (he₁ : SpliceExecution G x (ω₁,η₁) c₁ (ωf,θf)) - (he₂ : SpliceExecution G x (ω₂,η₂) c₂ (ωf,θf)) : - (ω₁,η₁) = (ω₂,η₂) := by - have hc : c₁ = c₂ := ordinalSpliceCode_injective G ωf x (y₁ k) hC c₁ c₂ - (ht₁.seams_pivotal G x η₁ y₁ k j ω₁ ωf c₁) - (by simpa only [hz] using ht₂.seams_pivotal G x η₂ y₂ k j ω₂ ωf c₂) heq - subst c₂ - exact he₁.input_unique G x (ω₁,η₁) (ω₂,η₂) (ωf,θf) c₁ he₂ - -end BridgeCode - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SpliceWeight -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def domainBits (Q : Finset E) (ω : Set E) : Finset E := Q.filter (· ∈ ω) - -@[simp] theorem mem_domainBits (Q : Finset E) (ω : Set E) (e : E) : - e ∈ domainBits Q ω ↔ e ∈ Q ∧ e ∈ ω := Finset.mem_filter - -theorem domainBits_subset (Q : Finset E) (ω : Set E) : domainBits Q ω ⊆ Q := - Finset.filter_subset _ _ - -theorem domainBits_exchange (Q : Finset E) (M ω η : Set E) : - domainBits Q (exchangeOn M ω η) = - finiteExchange (domainBits Q M) (domainBits Q ω) (domainBits Q η) := by - ext e - simp only [mem_domainBits,exchangeOn,Set.mem_union,Set.mem_sdiff,Set.mem_inter_iff, - finiteExchange,Finset.mem_union,Finset.mem_sdiff,Finset.mem_inter] - tauto - - - -noncomputable def spliceTupleWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (s : SpliceState E) : ℝ := - bernoulliWeight Q (domainBits Q s.1) p * - ∏ i ∈ J, bernoulliWeight Q (domainBits Q (s.2 i)) p - -theorem spliceTupleWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (s : SpliceState E) : 0 ≤ spliceTupleWeight Q J p s := by - exact mul_nonneg (bernoulliWeight_nonneg _ _ p) - (Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p) - - -theorem spliceTupleWeight_exchange (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (s : SpliceState E) (M : Set E) (i : ℕ) (hi : i ∈ J) : - spliceTupleWeight Q J p (exchangeState M i s) = spliceTupleWeight Q J p s := by - unfold spliceTupleWeight - rw [← Finset.mul_prod_erase J (fun l => - bernoulliWeight Q (domainBits Q ((exchangeState M i s).2 l)) p) hi, - ← Finset.mul_prod_erase J (fun l => bernoulliWeight Q (domainBits Q (s.2 l)) p) hi] - have herase : (∏ l ∈ J.erase i, - bernoulliWeight Q (domainBits Q ((exchangeState M i s).2 l)) p) = - ∏ l ∈ J.erase i, bernoulliWeight Q (domainBits Q (s.2 l)) p := by - apply Finset.prod_congr rfl - intro l hl - rw [exchangeState_away _ _ _ _ (Finset.mem_erase.mp hl).1] - rw [herase,exchangeState_first,exchangeState_at,← mul_assoc,← mul_assoc, - domainBits_exchange,domainBits_exchange, - bernoulliWeight_exchange _ _ _ _ (domainBits_subset Q s.1) (domainBits_subset Q (s.2 i)) p] - - -theorem SpliceExecution.weight (G : BondGraph V E) (x : V) - (s s' : SpliceState E) (code : List (ℕ × E)) - (h : SpliceExecution G x s code s') (Q : Finset E) (J : Finset ℕ) - (hJ : ∀ q ∈ code, q.1 ∈ J) (p : ℝ) : - spliceTupleWeight Q J p s' = spliceTupleWeight Q J p s := by - induction h with - | nil => rfl - | cons s s' s'' q code hstep hrest ih => - rw [ih (fun r hr => hJ r (List.mem_cons_of_mem _ hr))] - obtain ⟨y,a,b,_,_,_,_,_,rfl⟩ := hstep - exact spliceTupleWeight_exchange Q J p s _ q.1 (hJ q (List.mem_cons_self ..)) - - - -theorem splice_finite_weight_comparison (G : BondGraph V E) (x : V) - (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (code : List (ℕ × E)) - (hJ : ∀ q ∈ code, q.1 ∈ J) (A B : Finset (SpliceState E)) - (F : SpliceState E → SpliceState E) - (hex : ∀ s ∈ A, SpliceExecution G x s code (F s)) - (hB : ∀ s ∈ A, F s ∈ B) : - (∑ s ∈ A, spliceTupleWeight Q J p s) ≤ ∑ s ∈ B, spliceTupleWeight Q J p s := by - have hinj : Set.InjOn F (A : Set (SpliceState E)) := by - intro s hs t ht heq - exact (hex s hs).input_unique G x s t (F s) code (heq.symm ▸ hex t ht) - have hweight : (∑ s ∈ A, spliceTupleWeight Q J p s) = - ∑ s ∈ A.image F, spliceTupleWeight Q J p s := by - rw [Finset.sum_image hinj] - apply Finset.sum_congr rfl - intro s hs - exact ((hex s hs).weight G x s (F s) code Q J hJ p).symm - rw [hweight] - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro t ht - obtain ⟨s,hs,rfl⟩ := Finset.mem_image.mp ht - exact hB s hs - · intro s _ _ - exact spliceTupleWeight_nonneg Q J p s - -end SpliceWeight - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BridgeGapGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem pivotalRank_lt_iff_of_cluster_finite (G : BondGraph V E) (ω : Set E) - (m : Set V) (x : V) (hC : (cluster G ω x).Finite) {e f : E} - (he : OpenMarkedPivotal G ω m x e) (hf : OpenMarkedPivotal G ω m x f) : - pivotalRank G ω x e < pivotalRank G ω x f ↔ - f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by - have hcut (q : E) : (cluster G (ω \ {q}) x).Finite := - hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) - have hexterior (hout : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by - obtain ⟨a,b,hab,hxa,_,_⟩ := openMarkedPivotal_oriented G ω m x he - intro h; subst f - exact ((mem_internalEdges_of_ends G _ e a b hab).mp hout).1 hxa - constructor - · intro hlt - have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) - rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | hout - · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he - obtain ⟨y,hy,hby⟩ := hbm - have hby' : Conn G (ω \ {f}) b y := conn_mono G - (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) - have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ - have ha : a ∉ cluster G (ω \ {f}) x := fun h => - hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) - have hs := pivotal_rootSide_ssubset G ω m x hf hne.symm - ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩) - have hrev := Set.ncard_lt_ncard hs (hcut e) - exact (Nat.not_lt_of_ge (Nat.le_of_lt hrev) hlt).elim - · exact hout - · intro hout - exact Set.ncard_lt_ncard (pivotal_rootSide_ssubset G ω m x he (hexterior hout) hout) (hcut f) - -theorem pivotal_internal_of_rank_lt (G : BondGraph V E) (ω : Set E) - (m : Set V) (x : V) (hC : (cluster G ω x).Finite) {e f : E} - (he : OpenMarkedPivotal G ω m x e) (hf : OpenMarkedPivotal G ω m x f) - (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : - e ∈ internalEdges G (cluster G (ω \ {f}) x) := by - have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) - rcases pivotal_other_sides G ω m x hf he hne with h | h - · exact h - · have hr := (pivotalRank_lt_iff_of_cluster_finite G ω m x hC hf he).mpr h - omega - - -theorem conn_far_end_avoids_later_pivotal (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e g : E} - (he : OpenMarkedPivotal G ω {z} x e) (hg : OpenMarkedPivotal G ω {z} x g) - (hlt : pivotalRank G ω x e < pivotalRank G ω x g) - (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) : - Conn G (ω \ {g}) x b := by - have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp hlt - have hne : e ≠ g := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) - have hc : Conn G (ω \ {g}) x a := - conn_mono G (ω₁ := (ω \ {e}) \ {g}) (ω₂ := ω \ {g}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_exterior_of_inside G (ω \ {e}) x hout (conn_refl G _ x) ha) - exact hc.tail ⟨e,⟨he.1,hne⟩,hab⟩ - - -theorem conn_near_end_avoids_earlier_pivotal (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {f g : E} - (hf : OpenMarkedPivotal G ω {z} x f) (hg : OpenMarkedPivotal G ω {z} x g) - (hlt : pivotalRank G ω x g < pivotalRank G ω x f) - (c d : V) (hcd : G f = s(c,d)) (hd : ¬Conn G (ω \ {f}) x d) - (hdz : Conn G (ω \ {f}) d z) : Conn G (ω \ {g}) c z := by - have hin := pivotal_internal_of_rank_lt G ω {z} x hC hg hf hlt - have hne : f ≠ g := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h.symm) - have hc : Conn G (ω \ {g}) d z := - conn_mono G (ω₁ := (ω \ {f}) \ {g}) (ω₂ := ω \ {g}) (fun _ h => ⟨h.1.1,h.2⟩) - (conn_delete_internal_of_outside G (ω \ {f}) x hin hd hdz) - exact (Relation.ReflTransGen.single ⟨f,⟨hf.1,hne⟩,hcd⟩).trans hc - - - -theorem pivotal_between_is_internal (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e f g : E} - (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) - (hg : OpenMarkedPivotal G ω {z} x g) - (heg : pivotalRank G ω x e < pivotalRank G ω x g) - (hgf : pivotalRank G ω x g < pivotalRank G ω x f) - (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) - (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) - (hdz : Conn G (ω \ {f}) d z) - (hbc : Conn G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : - OpenMarkedPivotal G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) {c} b g := by - have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp heg - have hin := pivotal_internal_of_rank_lt G ω {z} x hC hg hf hgf - refine ⟨⟨hg.1,fun v hv => ⟨hin v hv,hout v hv⟩⟩,⟨c,rfl,hbc⟩,?_⟩ - rintro ⟨w,hw,hbw⟩ - have hbc' : Conn G (ω \ {g}) b c := by - have hw' : w = c := Set.mem_singleton_iff.mp hw - subst w - apply conn_mono G ?_ hbw - intro q hq - exact ⟨hq.1.1,hq.2⟩ - apply hg.2.2 - exact ⟨z,rfl,(conn_far_end_avoids_later_pivotal G ω x z hC he hg heg a b hab ha).trans - (hbc'.trans (conn_near_end_avoids_earlier_pivotal G ω x z hC hf hg hgf c d hcd hd hdz))⟩ - - -theorem pivotal_after_is_internal (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e g : E} - (he : OpenMarkedPivotal G ω {z} x e) (hg : OpenMarkedPivotal G ω {z} x g) - (heg : pivotalRank G ω x e < pivotalRank G ω x g) - (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) - (hbz : Conn G (ω ∩ internalEdges G - (cluster G ω x \ cluster G (ω \ {e}) x)) b z) : - OpenMarkedPivotal G (ω ∩ internalEdges G - (cluster G ω x \ cluster G (ω \ {e}) x)) {z} b g := by - have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp heg - have hin : g ∈ internalEdges G (cluster G ω x) := by - obtain ⟨u,v,huv,hxu,_,_⟩ := openMarkedPivotal_oriented G ω {z} x hg - have hu : u ∈ cluster G ω x := conn_mono G Set.sdiff_subset hxu - exact (mem_internalEdges_of_ends G _ g u v huv).mpr - ⟨hu,(edge_cluster_sides G ω x hg.1 huv).mp hu⟩ - refine ⟨⟨hg.1,fun v hv => ⟨hin v hv,hout v hv⟩⟩,⟨z,rfl,hbz⟩,?_⟩ - rintro ⟨w,hw,hbw⟩ - have hbz' : Conn G (ω \ {g}) b z := by - have hw' : w = z := Set.mem_singleton_iff.mp hw - subst w - apply conn_mono G ?_ hbw - intro q hq - exact ⟨hq.1.1,hq.2⟩ - exact hg.2.2 ⟨z,rfl, - (conn_far_end_avoids_later_pivotal G ω x z hC he hg heg a b hab ha).trans hbz'⟩ - -end BridgeGapGeometry - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BridgeGapCount -attribute [local instance] Classical.propDecidable Classical.decEq - -@[simp] theorem separatingBonds_card (G : BondGraph V E) (ω : Set E) (x z : V) : - (separatingBonds G ω x z).card = pivotalDistance G ω x z := by - exact Set.ncard_coe_finset (separatingBonds G ω x z) |>.symm.trans (by - congr 1 - ext e - exact mem_separatingBonds G ω x z e) - - -noncomputable def bridgeInterval (G : BondGraph V E) (ω : Set E) (x z : V) (e f : E) : Finset E := - (separatingBonds G ω x z).filter fun g => - pivotalRank G ω x e < pivotalRank G ω x g ∧ pivotalRank G ω x g < pivotalRank G ω x f - -theorem bridgeIndex_interval_identity (G : BondGraph V E) (ω : Set E) (x z : V) - (hC : (cluster G ω x).Finite) {e f : E} - (hf : OpenMarkedPivotal G ω {z} x f) - (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : - bridgeIndex G ω x z f = bridgeIndex G ω x z e + (bridgeInterval G ω x z e f).card + 1 := by - let P := separatingBonds G ω x z - let A := P.filter fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e - let B := bridgeInterval G ω x z e f - have hdis : Disjoint A B := by - apply Finset.disjoint_left.mpr - intro g hgA hgB - have h₁ := (Finset.mem_filter.mp hgA).2 - have h₂ := (Finset.mem_filter.mp hgB).2.1 - omega - have hnot : f ∉ A ∪ B := by - intro hh - rcases Finset.mem_union.mp hh with h | h - · have hr := (Finset.mem_filter.mp h).2 - omega - · exact (Nat.lt_irrefl _) (Finset.mem_filter.mp h).2.2 - have hset : P.filter (fun g => pivotalRank G ω x g ≤ pivotalRank G ω x f) = insert f (A ∪ B) := by - ext g - constructor - · intro hg - obtain ⟨hgP,hgf⟩ := Finset.mem_filter.mp hg - by_cases hge : g = f - · exact Finset.mem_insert.mpr (Or.inl hge) - · apply Finset.mem_insert.mpr - apply Or.inr - by_cases hga : pivotalRank G ω x g ≤ pivotalRank G ω x e - · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨hgP,hga⟩) - · apply Finset.mem_union_right - apply Finset.mem_filter.mpr - refine ⟨hgP,Nat.lt_of_not_ge hga,?_⟩ - apply lt_of_le_of_ne hgf - intro hr - exact hge (pivotalRank_injective_of_cluster_finite G ω {z} x hC - ((mem_separatingBonds G ω x z g).mp hgP) hf hr) - · intro hg - rcases Finset.mem_insert.mp hg with heq | hg - · subst g - exact Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z f).mpr hf,le_refl _⟩ - · rcases Finset.mem_union.mp hg with hg | hg - · exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hg).1, - (Finset.mem_filter.mp hg).2.trans (Nat.le_of_lt hlt)⟩ - · exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hg).1, - Nat.le_of_lt (Finset.mem_filter.mp hg).2.2⟩ - change (P.filter _).card = A.card+B.card+1 - rw [hset,Finset.card_insert_of_notMem hnot,Finset.card_union_of_disjoint hdis] - -theorem bridgeInterval_card_le (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e f : E} - (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) - (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) - (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) - (hdz : Conn G (ω \ {f}) d z) - (hbc : Conn G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : - (bridgeInterval G ω x z e f).card ≤ pivotalDistance G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by - rw [← separatingBonds_card] - apply Finset.card_le_card - intro g hg - obtain ⟨hgP,heg,hgf⟩ := Finset.mem_filter.mp hg - apply (mem_separatingBonds _ _ _ _ _).mpr - exact pivotal_between_is_internal G ω x z hC he hf - ((mem_separatingBonds G ω x z g).mp hgP) heg hgf a b c d hab hcd ha hd hdz hbc - - -theorem bridge_gap_le_internal_distance (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e f : E} - (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) - (hlt : pivotalRank G ω x e < pivotalRank G ω x f) - (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) - (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) - (hdz : Conn G (ω \ {f}) d z) - (hbc : Conn G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : - bridgeIndex G ω x z f - bridgeIndex G ω x z e ≤ - 1 + pivotalDistance G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by - have hid := bridgeIndex_interval_identity G ω x z hC hf hlt - have hle := bridgeInterval_card_le G ω x z hC he hf a b c d hab hcd ha hd hdz hbc - omega - - -theorem bridge_terminal_gap_le_internal_distance (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e : E} - (he : OpenMarkedPivotal G ω {z} x e) - (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) - (hbz : Conn G (ω ∩ internalEdges G - (cluster G ω x \ cluster G (ω \ {e}) x)) b z) : - (separatingBonds G ω x z).card + 1 - bridgeIndex G ω x z e ≤ - 1 + pivotalDistance G (ω ∩ internalEdges G - (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by - let P := separatingBonds G ω x z - let A := P.filter fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e - let B := P.filter fun g => pivotalRank G ω x e < pivotalRank G ω x g - have hid : A.card + B.card = P.card := by - simpa only [A,B,not_le] using Finset.card_filter_add_card_filter_not - (s := P) (fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e) - have hle : B.card ≤ pivotalDistance G (ω ∩ internalEdges G - (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by - rw [← separatingBonds_card] - apply Finset.card_le_card - intro g hg - obtain ⟨hgP,heg⟩ := Finset.mem_filter.mp hg - apply (mem_separatingBonds _ _ _ _ _).mpr - exact pivotal_after_is_internal G ω x z hC he - ((mem_separatingBonds G ω x z g).mp hgP) heg a b hab ha hbz - change P.card+1-A.card ≤ _ - omega - - -theorem pivotalDistance_le_cluster_card (G : BondGraph V E) (ω : Set E) (x z : V) - (hC : (cluster G ω x).Finite) : - pivotalDistance G ω x z ≤ (cluster G ω x).ncard - 1 := by - rw [← separatingBonds_card] - let N := (cluster G ω x).ncard - have hm : Set.MapsTo (pivotalRank G ω x) (separatingBonds G ω x z : Set E) - (Finset.Ico 1 N : Set ℕ) := by - intro e he - have he' := (mem_separatingBonds G ω x z e).mp he - have hfin : (cluster G (ω \ {e}) x).Finite := - hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) - have hpos : 0 < pivotalRank G ω x e := - (Set.ncard_pos hfin).mpr ⟨x,conn_refl G _ x⟩ - have hlt : pivotalRank G ω x e < N := by - apply Set.ncard_lt_ncard _ hC - refine Set.ssubset_iff_subset_ne.mpr ⟨fun v hv => conn_mono G Set.sdiff_subset hv,?_⟩ - intro heq - obtain ⟨v,hv,hxv⟩ := he'.2.1 - apply he'.2.2 - refine ⟨v,hv,?_⟩ - change v ∈ cluster G (ω \ {e}) x - rw [heq] - exact hxv - exact Finset.mem_Ico.mpr ⟨hpos,hlt⟩ - have hi : Set.InjOn (pivotalRank G ω x) (separatingBonds G ω x z : Set E) := by - intro e he f hf h - exact pivotalRank_injective_of_cluster_finite G ω {z} x hC - ((mem_separatingBonds G ω x z e).mp he) ((mem_separatingBonds G ω x z f).mp hf) h - simpa only [Nat.card_Ico,N] using Finset.card_le_card_of_injOn (pivotalRank G ω x) hm hi - - - -theorem inverse_contact_weight_le (K l : ℕ) (L : ℝ) (hK : 1 ≤ K) (hl : 1 ≤ l) - (hL : 1 ≤ L) (hgap : (l:ℝ) ≤ 1 + K*L) : - (K:ℝ)⁻¹ ≤ min 1 (2*L/l) := by - have hKr : (1:ℝ) ≤ K := by exact_mod_cast hK - have hlr : (1:ℝ) ≤ l := by exact_mod_cast hl - have hKpos : (0:ℝ) < K := lt_of_lt_of_le zero_lt_one hKr - have hlpos : (0:ℝ) < l := lt_of_lt_of_le zero_lt_one hlr - apply le_min - · exact inv_le_one_of_one_le₀ hKr - · apply (le_div_iff₀ hlpos).mpr - apply (inv_mul_le_iff₀ hKpos).mpr - by_cases h1 : l = 1 - · simp only [h1,Nat.cast_one] - nlinarith - · have h2 : (2:ℝ) ≤ l := by exact_mod_cast (show 2 ≤ l by omega) - nlinarith - -end BridgeGapCount - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section BridgePiecePath -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem conn_restrict_cluster_of_subset (G : BondGraph V E) (ω : Set E) (x : V) - {η : Set E} (hη : η ⊆ ω) {a b : V} (ha : a ∈ cluster G ω x) - (hab : Conn G η a b) : Conn G (η ∩ internalEdges G (cluster G ω x)) a b := by - induction hab with - | refl => exact conn_refl G _ a - | @tail u v hau huv ih => - obtain ⟨e,he,heq⟩ := huv - have hu : u ∈ cluster G ω x := ha.trans (conn_mono G hη hau) - have hv : v ∈ cluster G ω x := (edge_cluster_sides G ω x (hη he) heq).mp hu - exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ - - - -theorem conn_between_pivotals_internal (G : BondGraph V E) (ω : Set E) - (x z : V) (hC : (cluster G ω x).Finite) {e f : E} - (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) - (hlt : pivotalRank G ω x e < pivotalRank G ω x f) - (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) - (ha : Conn G (ω \ {e}) x a) (hb : ¬Conn G (ω \ {e}) x b) - (hc : Conn G (ω \ {f}) x c) : - Conn G (ω ∩ internalEdges G - (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by - have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) - have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hf).mp hlt - have hcnot : c ∉ cluster G (ω \ {e}) x := - ((mem_internalEdges_of_ends G _ f c d hcd).mp hout).1 - have hins : insert e ((ω \ {e}) \ {f}) = ω \ {f} := by - ext q - simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] - constructor - · rintro (rfl | ⟨⟨hq,hqe⟩,hqf⟩) - · exact ⟨he.1,hne⟩ - · exact ⟨hq,hqf⟩ - · rintro ⟨hq,hqf⟩ - by_cases hqe : q = e - · exact Or.inl hqe - · exact Or.inr ⟨⟨hq,hqe⟩,hqf⟩ - have hbc : Conn G ((ω \ {e}) \ {f}) b c := by - rw [← hins,conn_insert_iff G _ e a b x c hab] at hc - rcases hc with h | ⟨_,h⟩ | ⟨h,_⟩ - · exact (hcnot (conn_mono G Set.sdiff_subset h)).elim - · exact h - · exact (hb (conn_mono G Set.sdiff_subset h)).elim - have hbo : b ∈ cluster G (ω \ {f}) x := - conn_far_end_avoids_later_pivotal G ω x z hC he hf hlt a b hab ha - have hp := conn_restrict_cluster_compl_of_subset G (ω \ {e}) x Set.sdiff_subset hb hbc - have hp' := conn_restrict_cluster_of_subset G (ω \ {f}) x - (η := ((ω \ {e}) \ {f}) ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) - (fun _ h => ⟨h.1.1.1,h.1.2⟩) hbo hp - apply conn_mono G ?_ hp' - intro q hq - exact ⟨hq.1.1.1.1,fun v hv => ⟨hq.2 v hv,hq.1.2 v hv⟩⟩ - - -theorem conn_after_pivotal_internal (G : BondGraph V E) (ω : Set E) - (x z : V) {e : E} (he : OpenMarkedPivotal G ω {z} x e) - (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) - (hb : ¬Conn G (ω \ {e}) x b) (hbz : Conn G (ω \ {e}) b z) : - Conn G (ω ∩ internalEdges G (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by - have hbo : b ∈ cluster G ω x := - (conn_mono G Set.sdiff_subset ha).tail ⟨e,he.1,hab⟩ - have hp := conn_restrict_cluster_compl G (ω \ {e}) x hb hbz - have hp' := conn_restrict_cluster_of_subset G ω x - (η := (ω \ {e}) ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) - (fun _ h => h.1.1) hbo hp - apply conn_mono G ?_ hp' - intro q hq - exact ⟨hq.1.1.1,fun v hv => ⟨hq.2 v hv,hq.1.2 v hv⟩⟩ - - -theorem pivotalDistance_le_induced_card (G : BondGraph V E) (ω : Set E) - (B : Set V) (hB : B.Finite) {a b : V} (ha : a ∈ B) : - pivotalDistance G (ω ∩ internalEdges G B) a b ≤ B.ncard-1 := by - have hsub : cluster G (ω ∩ internalEdges G B) a ⊆ B := - fun _ h => conn_internal_endpoint G B ha h - exact (pivotalDistance_le_cluster_card G (ω ∩ internalEdges G B) a b (hB.subset hsub)).trans - (Nat.sub_le_sub_right (Set.ncard_le_ncard hsub hB) 1) - -end BridgePiecePath - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SplicePieceGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem conn_after_pivotal_of_orientation (G : BondGraph V E) (ω : Set E) - (x z : V) {e : E} (he : OpenMarkedPivotal G ω {z} x e) - (a b : V) (hab : G e = s(a,b)) (hb : ¬Conn G (ω \ {e}) x b) : - Conn G (ω \ {e}) b z := by - have hins : insert e (ω \ {e}) = ω := by - ext q - simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] - by_cases hqe : q = e <;> simp_all [he.1] - obtain ⟨w,hw,hxw⟩ := he.2.1 - have hw' : w = z := Set.mem_singleton_iff.mp hw - subst w - rw [← hins,conn_insert_iff G _ e a b x z hab] at hxw - rcases hxw with h | ⟨_,h⟩ | ⟨h,_⟩ - · exact (he.2.2 ⟨z,rfl,h⟩).elim - · exact h - · exact (hb h).elim - - -theorem SpliceTrace.internal_agreement (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : - ∀ q ∈ internalEdges G (cluster G ω x), q ∈ ωf ↔ q ∈ ω := by - induction h with - | stop => exact fun _ _ => Iff.rfl - | @step j i ω e a b rest ωf _ _ _ _ hy he hab ha hb ht ih => - intro q hq - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - have hB : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy - have hbS : b ∉ S := hB hb - have hqq : q ∈ internalEdges G (cluster G ω' x) := by - rw [splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb] - exact fun v hv => Or.inl (hq v hv) - rw [ih q hqq] - change q ∈ internalEdges G S at hq - have hh := (splice_internal_fields G S B e ω (η i) a b hab hbS hB).1 - exact Iff.of_eq (show (q ∈ ω') = (q ∈ ω) from by - have := congrArg (fun A : Set E => q ∈ A) hh - simpa only [Set.mem_inter_iff,hq,and_true] using this) - - -theorem SpliceTrace.head_cut (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) : - cluster G (ωf \ {e}) x = cluster G ω x := by - cases h with - | step j i ω e a b rest ωf _ _ _ hmax hy he hab ha hb ht => - have hc := splice_close_seam_cluster G ω (η i) x (y i) hy e a b hab he ha hb - rw [SpliceTrace.preserve_cut G x η y k i _ ωf rest ht e] - · exact hc - · intro l hil hlk - rw [hc] - exact hmax l hil hlk - - -theorem contactSet_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (B : Set V) (hB : B.Finite) : (contactSet G ω B).Finite := by - let W := hB.toFinset - have hWB : (W : Set V) = B := hB.coe_toFinset - apply (incidentSupport G hloc W).finite_toSet.subset - rintro e ⟨_,a,b,hab,ha,_⟩ - apply (mem_incidentSupport G hloc W e).mpr - refine ⟨a,?_,?_⟩ - · change a ∈ (W : Set V) - rw [hWB] - exact ha - · simp [hab] - - - -theorem goodForScale_piece (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) - (hg : GoodForScale G ω x L) (B : Set V) (hB : B.Finite) - (hBC : B ⊆ cluster G ω x) - (hconn : ∀ a ∈ B, ∀ b ∈ B, Conn G (ω ∩ internalEdges G B) a b) - (hK : 0 < (contactSet G ω B).ncard) {a b : V} (ha : a ∈ B) (hb : b ∈ B) : - (pivotalDistance G (ω ∩ internalEdges G B) a b : ℝ) ≤ - (contactSet G ω B).ncard*L := by - let W := hB.toFinset - have hWB : (W : Set V) = B := hB.coe_toFinset - have hh := hg W (by simpa only [hWB] using hBC) - (by simpa only [← Finset.mem_coe,hWB] using hconn) - (by simpa only [hWB] using hK) a (by simpa only [← Finset.mem_coe,hWB] using ha) - b (by simpa only [← Finset.mem_coe,hWB] using hb) - simpa only [hWB] using hh - - -theorem slit_piece_connected (G : BondGraph V E) (η : Set E) (S : Set V) (y : V) - (_hy : y ∉ S) : - let B := cluster G (η ∩ internalEdges G Sᶜ) y - ∀ a ∈ B, ∀ b ∈ B, Conn G (η ∩ internalEdges G B) a b := by - intro B a ha b hb - have hc := conn_restrict_cluster G (η ∩ internalEdges G Sᶜ) y ha - (conn_trans G _ (conn_symm G _ ha) hb) - apply conn_mono G ?_ hc - exact fun _ h => ⟨h.1.1,h.2⟩ - -end SplicePieceGeometry - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SpliceGapBound -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def traceHeadGap (G : BondGraph V E) (ωf : Set E) (x z : V) - (e : E) (rest : List (ℕ × E)) : ℕ := - (match rest with - | [] => (separatingBonds G ωf x z).card + 1 - | (_,f)::_ => bridgeIndex G ωf x z f) - bridgeIndex G ωf x z e - - - -theorem SpliceTrace.head_gap_bounds (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j i M : ℕ) - (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) - (hCf : (cluster G ωf x).Finite) - (hCi : (cluster G (η i) (y i)).Finite) - (hM : (cluster G (η i) (y i)).ncard ≤ M) - (L : ℝ) (hgood : GoodForScale G (η i) (y i) L) : - let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) - let K := (contactSet G (η i) B).ncard - let l := traceHeadGap G ωf x (y k) e rest - 1 ≤ K ∧ 1 ≤ l ∧ l ≤ M ∧ (l:ℝ) ≤ 1 + K*L := by - have hfull := h - cases h with - | step j i ω e a b rest ωf hn _ _ _ hy he hab ha hb ht => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - let K := (contactSet G (η i) B).ncard - change 1 ≤ K ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ - traceHeadGap G ωf x (y k) e rest ≤ M ∧ - (traceHeadGap G ωf x (y k) e rest:ℝ) ≤ 1+K*L - have hBo : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy - have hBC : B ⊆ cluster G (η i) (y i) := fun _ h => conn_mono G Set.inter_subset_left h - have hB : B.Finite := hCi.subset hBC - have hKB : (contactSet G (η i) B).Finite := contactSet_finite G hloc (η i) B hB - have heK : e ∈ contactSet G (η i) B := - ⟨he,b,a,hab.trans (Sym2.eq_swap ..),hb,fun h => hBo h ha⟩ - have hK : 0 < K := (Set.ncard_pos hKB).mpr ⟨e,heK⟩ - have hBpos : 0 < B.ncard := (Set.ncard_pos hB).mpr ⟨b,hb⟩ - have hBM : B.ncard ≤ M := (Set.ncard_le_ncard hBC hCi).trans hM - have hcluster : cluster G ω' x = S ∪ B := - splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb - have hcut : cluster G (ωf \ {e}) x = S := - SpliceTrace.head_cut G x η y k j i ω ωf e rest hfull - have hpe : OpenMarkedPivotal G ωf {y k} x e := - SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::rest) hfull (i,e) (by simp) - have hxa : Conn G (ωf \ {e}) x a := by - change a ∈ cluster G (ωf \ {e}) x - rw [hcut] - exact ha - have hxb : ¬Conn G (ωf \ {e}) x b := by - change b ∉ cluster G (ωf \ {e}) x - rw [hcut] - exact hBo hb - have hbits : ωf ∩ internalEdges G B = η i ∩ internalEdges G B := by - have hii := (splice_internal_fields G S B e ω (η i) a b hab (hBo hb) hBo).2 - ext q - by_cases hq : q ∈ internalEdges G B - · have hq' : q ∈ internalEdges G (cluster G ω' x) := by - rw [hcluster] - exact fun v hv => Or.inr (hq v hv) - have hiff := SpliceTrace.internal_agreement G x η y k i ω' ωf rest ht q hq' - have hbit := congrArg (fun A : Set E => q ∈ A) hii - simpa only [Set.mem_inter_iff,hq,and_true,hiff] using Iff.of_eq hbit - · simp only [Set.mem_inter_iff,hq,and_false] - have hconn := slit_piece_connected G (η i) S (y i) hy - have finish (l : ℕ) (c : V) (hc : c ∈ B) (hl : 1 ≤ l) - (hg : l ≤ 1 + pivotalDistance G (ωf ∩ internalEdges G B) b c) : - 1 ≤ l ∧ l ≤ M ∧ (l:ℝ) ≤ 1+K*L := by - rw [hbits] at hg - have hp := pivotalDistance_le_induced_card G (η i) B hB hb (b := c) - have hg' : (l:ℝ) ≤ 1+(pivotalDistance G (η i ∩ internalEdges G B) b c:ℝ) := by - exact_mod_cast hg - have hgood' := goodForScale_piece G (η i) (y i) L hgood B hB hBC hconn hK hb hc - refine ⟨hl,by omega,?_⟩ - change (l:ℝ) ≤ 1+(contactSet G (η i) B).ncard*L - linarith - refine ⟨hK,?_⟩ - cases rest with - | nil => - have hfω : ωf = ω' := by cases ht; rfl - have hdiff : cluster G ωf x \ cluster G (ωf \ {e}) x = B := by - rw [hcut,hfω,hcluster] - ext v - constructor - · rintro ⟨hv,hnv⟩ - exact hv.resolve_left hnv - · intro hv - exact ⟨Or.inr hv,hBo hv⟩ - have hyk : y k ∈ B := by - have hz := SpliceTrace.endpoint G x η y k j ω ωf [(i,e)] hfull - rw [hfω,hcluster] at hz - exact hz.resolve_left hn - have hconnz := conn_after_pivotal_of_orientation G ωf x (y k) hpe a b hab hxb - have hp := conn_after_pivotal_internal G ωf x (y k) hpe a b hab hxa hxb hconnz - have hg := bridge_terminal_gap_le_internal_distance G ωf x (y k) hCf hpe a b hab hxa hp - rw [hdiff] at hg - apply finish _ (y k) hyk _ hg - have hcard : bridgeIndex G ωf x (y k) e ≤ (separatingBonds G ωf x (y k)).card := - Finset.card_filter_le _ _ - omega - | cons q more => - obtain ⟨l,f⟩ := q - have hcutf : cluster G (ωf \ {f}) x = S ∪ B := by - rw [SpliceTrace.head_cut G x η y k i l ω' ωf f more ht,hcluster] - have hss : cluster G (ωf \ {e}) x ⊂ cluster G (ωf \ {f}) x := by - rw [hcut,hcutf] - exact Set.ssubset_iff_subset_ne.mpr ⟨Set.subset_union_left,fun heq => - hBo hb (heq.symm ▸ (show b ∈ S ∪ B from Or.inr hb))⟩ - have hfFin : (cluster G (ωf \ {f}) x).Finite := - hCf.subset (fun _ h => conn_mono G Set.sdiff_subset h) - have hr : pivotalRank G ωf x e < pivotalRank G ωf x f := Set.ncard_lt_ncard hss hfFin - have hpf : OpenMarkedPivotal G ωf {y k} x f := - SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::(l,f)::more) hfull (l,f) (by simp) - obtain ⟨c,d,hcd,hxc,hxd,hdyk⟩ := openMarkedPivotal_oriented G ωf {y k} x hpf - have hdy : Conn G (ωf \ {f}) d (y k) := by - simpa only [MarkedEvent,Set.mem_singleton_iff,exists_eq_left] using hdyk - have hdiff : cluster G (ωf \ {f}) x \ cluster G (ωf \ {e}) x = B := by - rw [hcut,hcutf] - ext v - constructor - · rintro ⟨hv,hnv⟩ - exact hv.resolve_left hnv - · intro hv - exact ⟨Or.inr hv,hBo hv⟩ - have hc : c ∈ B := by - have hfout := (pivotalRank_lt_iff_of_cluster_finite G ωf {y k} x hCf hpe hpf).mp hr - have hcnot := ((mem_internalEdges_of_ends G _ f c d hcd).mp hfout).1 - rw [hcut] at hcnot - change c ∈ cluster G (ωf \ {f}) x at hxc - rw [hcutf] at hxc - exact hxc.resolve_left hcnot - have hp := conn_between_pivotals_internal G ωf x (y k) hCf hpe hpf hr - a b c d hab hcd hxa hxb (by change c ∈ cluster G (ωf \ {f}) x; rw [hcutf]; exact Or.inr hc) - have hg := bridge_gap_le_internal_distance G ωf x (y k) hCf hpe hpf hr - a b c d hab hcd hxa hxd hdy hp - rw [hdiff] at hg - apply finish _ c hc _ hg - have hind := bridgeIndex_interval_identity G ωf x (y k) hCf hpf hr - omega - -end SpliceGapBound - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section GapCode -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem SpliceTrace.seam_data (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : - ∀ q ∈ steps, j < q.1 ∧ q.1 ≤ k ∧ q.2 ∈ η q.1 ∧ - q.2 ∈ internalEdges G (cluster G (η q.1) (y q.1)) := by - induction h with - | stop => simp - | @step j i ω e a b rest ωf _ hji hik _ _ he hab _ hb ht ih => - intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · have hb' : b ∈ cluster G (η i) (y i) := conn_mono G Set.inter_subset_left hb - exact ⟨hji,hik,he,(mem_internalEdges_of_ends G _ e a b hab).mpr - ⟨(edge_cluster_sides G (η i) (y i) he hab).mpr hb',hb'⟩⟩ - · obtain ⟨hqi,hqk,hqe,hqC⟩ := ih q hq - exact ⟨hji.trans hqi,hqk,hqe,hqC⟩ - - -theorem SpliceTrace.head_index_lt (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) - (hC : (cluster G ωf x).Finite) : - ∀ q ∈ rest, bridgeIndex G ωf x (y k) e < bridgeIndex G ωf x (y k) q.2 := by - have hfull := h - have hc := SpliceTrace.head_cut G x η y k j i ω ωf e rest h - have hseams := SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::rest) h - cases h with - | step j i ω e a b rest ωf _ _ _ hmax _ _ _ _ _ ht => - intro q hq - obtain ⟨hqi,hqk,_,hqC⟩ := SpliceTrace.seam_data G x η y k i _ ωf rest ht q hq - have hout : q.2 ∈ internalEdges G (cluster G (ωf \ {e}) x)ᶜ := by - rw [hc] - intro v hv hvS - exact Set.disjoint_left.mp (hmax q.1 hqi hqk) (hqC v hv) hvS - have hpe := hseams (i,e) (by simp) - have hpq := hseams q (List.mem_cons_of_mem _ hq) - exact bridgeIndex_lt_of_rank_lt G ωf x (y k) hpq - ((pivotalRank_lt_iff_of_cluster_finite G ωf {y k} x hC hpe hpq).mpr hout) - - -noncomputable def gapSpliceCode (G : BondGraph V E) (ωf : Set E) (x z : V) : - List (ℕ × E) → List (ℕ × ℕ) - | [] => [] - | (i,e)::rest => (i,traceHeadGap G ωf x z e rest)::gapSpliceCode G ωf x z rest - - -def decodeGapOrdinals (N : ℕ) : List (ℕ × ℕ) → List (ℕ × ℕ) - | [] => [] - | (i,l)::rest => - let decoded := decodeGapOrdinals N rest - (i, (match decoded with | [] => N+1 | (_,r)::_ => r)-l)::decoded - - -theorem SpliceTrace.decode_gap_code (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) (hC : (cluster G ωf x).Finite) : - decodeGapOrdinals (separatingBonds G ωf x (y k)).card - (gapSpliceCode G ωf x (y k) steps) = ordinalSpliceCode G ωf x (y k) steps := by - induction steps generalizing j ω with - | nil => rfl - | cons q rest ih => - obtain ⟨i,e⟩ := q - have hlater := SpliceTrace.head_index_lt G x η y k j i ω ωf e rest h hC - cases h with - | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => - have ih' := ih i _ ht - simp only [gapSpliceCode,decodeGapOrdinals,ih',ordinalSpliceCode,List.map_cons] - congr 2 - cases rest with - | nil => - simp only [List.map_nil,traceHeadGap] - have hle : bridgeIndex G ωf x (y k) e ≤ (separatingBonds G ωf x (y k)).card := - Finset.card_filter_le _ _ - omega - | cons q qs => - obtain ⟨l,f⟩ := q - have hle := hlater (l,f) (by simp) - change bridgeIndex G ωf x (y k) e < bridgeIndex G ωf x (y k) f at hle - simp only [List.map_cons,traceHeadGap] - omega - - -theorem SpliceTrace.input_unique_of_gapCode (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) - (c₁ c₂ : List (ℕ × E)) - (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) - (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) - (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) - (heq : gapSpliceCode G ωf x (y₁ k) c₁ = gapSpliceCode G ωf x (y₁ k) c₂) - (θf : ℕ → Set E) - (he₁ : SpliceExecution G x (ω₁,η₁) c₁ (ωf,θf)) - (he₂ : SpliceExecution G x (ω₂,η₂) c₂ (ωf,θf)) : - (ω₁,η₁) = (ω₂,η₂) := by - apply SpliceTrace.input_unique_of_ordinalCode G x η₁ η₂ y₁ y₂ k j ω₁ ω₂ ωf - c₁ c₂ ht₁ ht₂ hz hC _ θf he₁ he₂ - rw [← SpliceTrace.decode_gap_code G x η₁ y₁ k j ω₁ ωf c₁ ht₁ hC, - heq,hz,SpliceTrace.decode_gap_code G x η₂ y₂ k j ω₂ ωf c₂ ht₂ hC] - -end GapCode - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section InverseCodeMass -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def gapWeight (L : ℝ) (l : ℕ) : ℝ := min 1 (2*L/l) - - -noncomputable def inverseCodeMass (M : ℕ) (L : ℝ) : ℝ := - 1 + ∑ l ∈ Finset.Icc 1 M, gapWeight L l - - -noncomputable def gapLetterWeight (L : ℝ) (l : ℕ) : ℝ := if l = 0 then 1 else gapWeight L l - -theorem gapWeight_nonneg (L : ℝ) (hL : 0 ≤ L) (l : ℕ) : 0 ≤ gapWeight L l := by - exact le_min zero_le_one (by positivity) - -theorem gapLetterWeight_nonneg (L : ℝ) (hL : 0 ≤ L) (l : ℕ) : 0 ≤ gapLetterWeight L l := by - unfold gapLetterWeight - split_ifs - · exact zero_le_one - · exact gapWeight_nonneg L hL l - -theorem sum_fin_succ_eq_Icc (M : ℕ) (f : ℕ → ℝ) : - ∑ l : Fin M, f (l.val+1) = ∑ l ∈ Finset.Icc 1 M, f l := by - rw [Fin.sum_univ_eq_sum_range (fun l => f (l+1)) M] - apply Finset.sum_bij (fun l _ => l+1) - · intro l hl - exact Finset.mem_Icc.mpr ⟨by omega,by have := Finset.mem_range.mp hl; omega⟩ - · intro l hl m hm h - omega - · intro l hl - obtain ⟨h1,hM⟩ := Finset.mem_Icc.mp hl - exact ⟨l-1,Finset.mem_range.mpr (by omega),by omega⟩ - · intros - rfl - -theorem sum_gapLetterWeight (M : ℕ) (L : ℝ) : - ∑ l : Fin (M+1), gapLetterWeight L l.val = inverseCodeMass M L := by - rw [Fin.sum_univ_succ] - simp only [Fin.val_zero,gapLetterWeight,Fin.val_succ,Nat.add_eq_zero_iff, - Nat.one_ne_zero,and_false,ite_false] - exact congrArg (1+·) (sum_fin_succ_eq_Icc M (gapWeight L)) - - - -theorem total_gap_code_mass (k M : ℕ) (L : ℝ) : - ∑ c : Fin k → Fin (M+1), ∏ i : Fin k, gapLetterWeight L (c i).val = - inverseCodeMass M L ^ k := by - rw [← Fintype.prod_sum (fun (_ : Fin k) (l : Fin (M+1)) => gapLetterWeight L l.val)] - simp only [sum_gapLetterWeight,Finset.prod_const,Finset.card_univ,Fintype.card_fin] - - -theorem valid_gap_code_mass_le (k M : ℕ) (L : ℝ) (hL : 0 ≤ L) - (valid : Finset (Fin k → Fin (M+1))) : - ∑ c ∈ valid, ∏ i : Fin k, gapLetterWeight L (c i).val ≤ inverseCodeMass M L ^ k := by - rw [← total_gap_code_mass] - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun c _ _ => Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L hL (c i).val)) - -theorem inverseCodeMass_le_harmonic (M : ℕ) (L : ℝ) (hL : 0 ≤ L) : - inverseCodeMass M L ≤ 1+2*L*(1+Real.log M) := by - have hsum : ∑ l ∈ Finset.Icc 1 M, gapWeight L l ≤ - 2*L*∑ l ∈ Finset.Icc 1 M, (l:ℝ)⁻¹ := by - rw [Finset.mul_sum] - apply Finset.sum_le_sum - intro l _ - simpa only [gapWeight,div_eq_mul_inv] using min_le_right (1:ℝ) (2*L/l) - have hh : ∑ l ∈ Finset.Icc 1 M, (l:ℝ)⁻¹ ≤ 1+Real.log M := by - simpa only [harmonic_eq_sum_Icc,Rat.cast_sum,Rat.cast_inv,Rat.cast_natCast] using - harmonic_le_one_add_log M - unfold inverseCodeMass - have h := hsum.trans (mul_le_mul_of_nonneg_left hh (by positivity)) - linarith - - -theorem inverseCodeMass_le_log (M : ℕ) (L : ℝ) (hM : 2 ≤ M) (hL : 1 ≤ L) : - inverseCodeMass M L ≤ 8*L*Real.log M := by - have hlog2 : (1:ℝ)/2 ≤ Real.log 2 := by - have hh := Real.one_sub_inv_le_log_of_pos (show (0:ℝ) < 2 by norm_num) - norm_num at hh ⊢ - exact hh - have hlog : (1:ℝ)/2 ≤ Real.log M := hlog2.trans - (Real.log_le_log (by norm_num) (by exact_mod_cast hM)) - have hLl : L/2 ≤ L*Real.log M := by nlinarith - have hbound := inverseCodeMass_le_harmonic M L (by linarith) - nlinarith - - -def contactInterval (K a : ℕ) : Set unitInterval := - {u | (a:ℝ)/K ≤ (u:ℝ) ∧ (u:ℝ) < (a+1:ℕ)/K} - -theorem volume_contactInterval (K a : ℕ) (ha : a < K) : - volume (contactInterval K a) = ENNReal.ofReal ((K:ℝ)⁻¹) := by - have hK : (0:ℝ) < K := by exact_mod_cast (show 0 < K by omega) - have hleft : (a:ℝ)/K ∈ Set.Icc (0:ℝ) 1 := by - refine ⟨by positivity,(div_le_one hK).mpr ?_⟩ - exact_mod_cast (Nat.le_of_lt ha) - have hright : ((a+1:ℕ):ℝ)/K ∈ Set.Icc (0:ℝ) 1 := by - refine ⟨by positivity,(div_le_one hK).mpr ?_⟩ - exact_mod_cast (show a+1 ≤ K by omega) - let lo : unitInterval := ⟨_,hleft⟩ - let hi : unitInterval := ⟨_,hright⟩ - have heq : contactInterval K a = Set.Ico lo hi := rfl - rw [heq,unitInterval.volume_Ico] - congr 1 - dsimp only [lo,hi] - push_cast - field_simp - ring - - - -theorem volume_contact_cube {I : Type*} [Fintype I] (K a : I → ℕ) - (ha : ∀ i, a i < K i) : - (volume : Measure (I → unitInterval)) (Set.pi Set.univ (fun i => contactInterval (K i) (a i))) = - ∏ i, ENNReal.ofReal ((K i:ℝ)⁻¹) := by - rw [MeasureTheory.volume_pi,Measure.pi_pi] - exact Finset.prod_congr rfl (fun i _ => volume_contactInterval (K i) (a i) (ha i)) - -theorem real_volume_contact_cube {I : Type*} [Fintype I] (K a : I → ℕ) - (ha : ∀ i, a i < K i) : - ((volume : Measure (I → unitInterval)) - (Set.pi Set.univ (fun i => contactInterval (K i) (a i)))).toReal = - ∏ i, (K i:ℝ)⁻¹ := by - rw [volume_contact_cube K a ha,ENNReal.toReal_prod] - exact Finset.prod_congr rfl (fun i _ => ENNReal.toReal_ofReal (by positivity)) - -end InverseCodeMass - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.Geometry + +namespace OAI + +/-! Gap Codes for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SpliceExecution +attribute [local instance] Classical.propDecidable Classical.decEq + + + +abbrev SpliceState (E : Type v) := Set E × (ℕ → Set E) + + + +def exchangeState (mask : Set E) (i : ℕ) (s : SpliceState E) : SpliceState E := + (exchangeOn mask s.1 (s.2 i), Function.update s.2 i (exchangeOn mask (s.2 i) s.1)) + +@[simp] theorem exchangeState_first (mask : Set E) (i : ℕ) (s : SpliceState E) : + (exchangeState mask i s).1 = exchangeOn mask s.1 (s.2 i) := rfl + +@[simp] theorem exchangeState_at (mask : Set E) (i : ℕ) (s : SpliceState E) : + (exchangeState mask i s).2 i = exchangeOn mask (s.2 i) s.1 := by + simp [exchangeState] + +theorem exchangeState_away (mask : Set E) (i l : ℕ) (s : SpliceState E) (hli : l ≠ i) : + (exchangeState mask i s).2 l = s.2 l := by + simp [exchangeState, Function.update_of_ne hli] + +theorem exchangeState_involutive (mask : Set E) (i : ℕ) : + Function.Involutive (exchangeState mask i (E := E)) := by + intro s + apply Prod.ext + · simp only [exchangeState_first, exchangeState_at] + exact exchangeOn_involutive mask s.1 (s.2 i) + · funext l + by_cases hli : l = i + · subst l + simp only [exchangeState_at, exchangeState_first] + exact exchangeOn_involutive mask (s.2 i) s.1 + · rw [exchangeState_away _ _ _ _ hli, exchangeState_away _ _ _ _ hli] + + + +def undoState (G : BondGraph V E) (x : V) (q : ℕ × E) (s : SpliceState E) : + SpliceState E := exchangeState (recoveredMask G s.1 x q.2) q.1 s + + + +def ValidSpliceStep (G : BondGraph V E) (x : V) (s : SpliceState E) + (q : ℕ × E) (s' : SpliceState E) : Prop := + ∃ y a b, + y ∉ cluster G s.1 x ∧ q.2 ∈ s.2 q.1 ∧ G q.2 = s(a,b) ∧ + a ∈ cluster G s.1 x ∧ + b ∈ cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y ∧ + s' = exchangeState + (spliceMask G (cluster G s.1 x) + (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2) q.1 s + +theorem undoState_of_valid (G : BondGraph V E) (x : V) (s s' : SpliceState E) + (q : ℕ × E) (h : ValidSpliceStep G x s q s') : undoState G x q s' = s := by + obtain ⟨y,a,b,hy,he,hab,ha,hb,rfl⟩ := h + unfold undoState + rw [show recoveredMask G + (exchangeState (spliceMask G (cluster G s.1 x) + (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2) q.1 s).1 x q.2 = + spliceMask G (cluster G s.1 x) + (cluster G (s.2 q.1 ∩ internalEdges G (cluster G s.1 x)ᶜ) y) q.2 from + recoveredMask_splice G s.1 (s.2 q.1) x y hy q.2 a b hab he ha hb] + exact exchangeState_involutive _ _ s + + +inductive SpliceExecution (G : BondGraph V E) (x : V) : + SpliceState E → List (ℕ × E) → SpliceState E → Prop + | nil (s) : SpliceExecution G x s [] s + | cons (s s' s'') (q qs) + (hstep : ValidSpliceStep G x s q s') + (hrest : SpliceExecution G x s' qs s'') : SpliceExecution G x s (q::qs) s'' + + +def undoExecution (G : BondGraph V E) (x : V) : + List (ℕ × E) → SpliceState E → SpliceState E + | [], s => s + | q::qs, s => undoState G x q (undoExecution G x qs s) + +theorem SpliceExecution.undo (G : BondGraph V E) (x : V) + (s s' : SpliceState E) (code : List (ℕ × E)) + (h : SpliceExecution G x s code s') : undoExecution G x code s' = s := by + induction h with + | nil => rfl + | cons s s' s'' q qs hstep hrest ih => + change undoState G x q (undoExecution G x qs s'') = s + rw [ih] + exact undoState_of_valid G x s s' q hstep + + + +theorem SpliceExecution.input_unique (G : BondGraph V E) (x : V) + (s₁ s₂ out : SpliceState E) (code : List (ℕ × E)) + (h₁ : SpliceExecution G x s₁ code out) (h₂ : SpliceExecution G x s₂ code out) : + s₁ = s₂ := by + exact (h₁.undo G x s₁ out code).symm.trans (h₂.undo G x s₂ out code) + + + +theorem SpliceTrace.realize (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (code : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω code ωf) : + ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → + ∃ θf, SpliceExecution G x (ω,θ) code (ωf,θf) := by + induction h with + | stop j ω hz => + intro θ _ + exact ⟨θ, SpliceExecution.nil _⟩ + | @step j i ω e a b rest ωf _ hji hik _ hy he hab ha hb ht ih => + intro θ hθ + have hθi := hθ i hji hik + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let mask := spliceMask G S B e + let next := exchangeState mask i (ω,θ) + have hnext : next.1 = spliceField G S B e ω (η i) := by + change exchangeOn mask ω (θ i) = exchangeOn mask ω (η i) + rw [hθi] + obtain ⟨θf,hexec⟩ := ih next.2 (by + intro l hil hlk + rw [exchangeState_away _ _ _ _ (by omega)] + exact hθ l (hji.trans hil) hlk) + refine ⟨θf, SpliceExecution.cons (ω,θ) next (ωf,θf) (i,e) rest ?_ ?_⟩ + · refine ⟨y i,a,b,hy,?_,hab,ha,?_,?_⟩ + · simpa only [hθi] using he + · simpa only [hθi] using hb + · dsimp only [next, mask, B, S] + rw [hθi] + · change SpliceExecution G x (next.1,next.2) rest (ωf,θf) + rw [hnext] + exact hexec + +end SpliceExecution + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BridgeCode +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem pivotal_mem_trail (G : BondGraph V E) (ω : Set E) (x z : V) + (l : List E) (hl : Along G x l z) (hopen : ∀ e ∈ l, e ∈ ω) + {e : E} (he : OpenMarkedPivotal G ω {z} x e) : e ∈ l := by + by_contra hnot + apply he.2.2 + refine ⟨z,rfl,hl.conn ?_⟩ + intro f hf + exact ⟨hopen f hf,fun hfe => hnot ((Set.mem_singleton_iff.mp hfe) ▸ hf)⟩ + + +theorem finite_separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) : + {e | OpenMarkedPivotal G ω {z} x e}.Finite := by + by_cases hc : Conn G ω x z + · obtain ⟨l,hl,_,ho⟩ := conn_exists_bond_trail G hc + exact l.toFinset.finite_toSet.subset fun e he => + List.mem_toFinset.mpr (pivotal_mem_trail G ω x z l hl ho he) + · have hempty : {e | OpenMarkedPivotal G ω {z} x e} = ∅ := by + ext e + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + rintro ⟨_,⟨y,hy,hxy⟩,_⟩ + exact hc ((Set.mem_singleton_iff.mp hy) ▸ hxy) + rw [hempty] + exact Set.finite_empty + +noncomputable def separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) : Finset E := + (finite_separatingBonds G ω x z).toFinset + +@[simp] theorem mem_separatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) (e : E) : + e ∈ separatingBonds G ω x z ↔ OpenMarkedPivotal G ω {z} x e := by + exact (finite_separatingBonds G ω x z).mem_toFinset + + +theorem pivotalRank_injective_of_cluster_finite (G : BondGraph V E) (ω : Set E) + (m : Set V) (x : V) (hC : (cluster G ω x).Finite) : + Set.InjOn (pivotalRank G ω x) {e | OpenMarkedPivotal G ω m x e} := by + have hcut (f : E) : (cluster G (ω \ {f}) x).Finite := + hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) + intro e he f hf heq + by_contra hne + rcases pivotal_rootSides_nested G ω m x he hf hne with h | h + · exact (Nat.ne_of_lt (Set.ncard_lt_ncard h (hcut f))) heq + · exact (Nat.ne_of_lt (Set.ncard_lt_ncard h (hcut e))) heq.symm + + + +noncomputable def bridgeIndex (G : BondGraph V E) (ω : Set E) (x z : V) (e : E) : ℕ := + ((separatingBonds G ω x z).filter fun f => pivotalRank G ω x f ≤ pivotalRank G ω x e).card + +theorem bridgeIndex_pos (G : BondGraph V E) (ω : Set E) (x z : V) {e : E} + (he : OpenMarkedPivotal G ω {z} x e) : 0 < bridgeIndex G ω x z e := by + apply Finset.card_pos.mpr + exact ⟨e,Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z e).mpr he,le_refl _⟩⟩ + +theorem bridgeIndex_lt_of_rank_lt (G : BondGraph V E) (ω : Set E) (x z : V) {e f : E} + (hf : OpenMarkedPivotal G ω {z} x f) + (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : + bridgeIndex G ω x z e < bridgeIndex G ω x z f := by + apply Finset.card_lt_card + apply Finset.ssubset_iff_subset_ne.mpr + refine ⟨?_,?_⟩ + · intro d hd + exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hd).1, + (Finset.mem_filter.mp hd).2.trans (Nat.le_of_lt hlt)⟩ + · intro heq + have hmem : f ∈ (separatingBonds G ω x z).filter + (fun d => pivotalRank G ω x d ≤ pivotalRank G ω x f) := + Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z f).mpr hf,le_refl _⟩ + rw [← heq] at hmem + exact (Nat.not_le_of_lt hlt) (Finset.mem_filter.mp hmem).2 + +theorem bridgeIndex_injective (G : BondGraph V E) (ω : Set E) (x z : V) + (hC : (cluster G ω x).Finite) : + Set.InjOn (bridgeIndex G ω x z) {e | OpenMarkedPivotal G ω {z} x e} := by + intro e he f hf heq + apply pivotalRank_injective_of_cluster_finite G ω {z} x hC he hf + rcases lt_trichotomy (pivotalRank G ω x e) (pivotalRank G ω x f) with h | h | h + · exact ((Nat.ne_of_lt (bridgeIndex_lt_of_rank_lt G ω x z hf h)) heq).elim + · exact h + · exact ((Nat.ne_of_lt (bridgeIndex_lt_of_rank_lt G ω x z he h)) heq.symm).elim + + +noncomputable def ordinalSpliceCode (G : BondGraph V E) (ω : Set E) (x z : V) + (code : List (ℕ × E)) : List (ℕ × ℕ) := + code.map fun q => (q.1,bridgeIndex G ω x z q.2) + +theorem ordinalSpliceCode_injective (G : BondGraph V E) (ω : Set E) (x z : V) + (hC : (cluster G ω x).Finite) (c₁ c₂ : List (ℕ × E)) + (h₁ : ∀ q ∈ c₁, OpenMarkedPivotal G ω {z} x q.2) + (h₂ : ∀ q ∈ c₂, OpenMarkedPivotal G ω {z} x q.2) + (heq : ordinalSpliceCode G ω x z c₁ = ordinalSpliceCode G ω x z c₂) : c₁ = c₂ := by + induction c₁ generalizing c₂ with + | nil => + cases c₂ with + | nil => rfl + | cons q qs => simp [ordinalSpliceCode] at heq + | cons q qs ih => + cases c₂ with + | nil => simp [ordinalSpliceCode] at heq + | cons r rs => + have heq' := List.cons.inj heq + have hqr : q = r := by + apply Prod.ext + · exact congrArg (fun t : ℕ × ℕ => t.1) heq'.1 + · exact bridgeIndex_injective G ω x z hC (h₁ q (by simp)) (h₂ r (by simp)) + (congrArg Prod.snd heq'.1) + exact congrArg₂ List.cons hqr (ih rs + (fun a ha => h₁ a (List.mem_cons_of_mem _ ha)) + (fun a ha => h₂ a (List.mem_cons_of_mem _ ha)) heq'.2) + + + +theorem SpliceTrace.input_unique_of_ordinalCode (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) + (c₁ c₂ : List (ℕ × E)) + (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) + (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) + (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) + (heq : ordinalSpliceCode G ωf x (y₁ k) c₁ = ordinalSpliceCode G ωf x (y₁ k) c₂) + (θf : ℕ → Set E) + (he₁ : SpliceExecution G x (ω₁,η₁) c₁ (ωf,θf)) + (he₂ : SpliceExecution G x (ω₂,η₂) c₂ (ωf,θf)) : + (ω₁,η₁) = (ω₂,η₂) := by + have hc : c₁ = c₂ := ordinalSpliceCode_injective G ωf x (y₁ k) hC c₁ c₂ + (ht₁.seams_pivotal G x η₁ y₁ k j ω₁ ωf c₁) + (by simpa only [hz] using ht₂.seams_pivotal G x η₂ y₂ k j ω₂ ωf c₂) heq + subst c₂ + exact he₁.input_unique G x (ω₁,η₁) (ω₂,η₂) (ωf,θf) c₁ he₂ + +end BridgeCode + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SpliceWeight +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def domainBits (Q : Finset E) (ω : Set E) : Finset E := Q.filter (· ∈ ω) + +@[simp] theorem mem_domainBits (Q : Finset E) (ω : Set E) (e : E) : + e ∈ domainBits Q ω ↔ e ∈ Q ∧ e ∈ ω := Finset.mem_filter + +theorem domainBits_subset (Q : Finset E) (ω : Set E) : domainBits Q ω ⊆ Q := + Finset.filter_subset _ _ + +theorem domainBits_exchange (Q : Finset E) (M ω η : Set E) : + domainBits Q (exchangeOn M ω η) = + finiteExchange (domainBits Q M) (domainBits Q ω) (domainBits Q η) := by + ext e + simp only [mem_domainBits,exchangeOn,Set.mem_union,Set.mem_sdiff,Set.mem_inter_iff, + finiteExchange,Finset.mem_union,Finset.mem_sdiff,Finset.mem_inter] + tauto + + + +noncomputable def spliceTupleWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (s : SpliceState E) : ℝ := + bernoulliWeight Q (domainBits Q s.1) p * + ∏ i ∈ J, bernoulliWeight Q (domainBits Q (s.2 i)) p + +theorem spliceTupleWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (s : SpliceState E) : 0 ≤ spliceTupleWeight Q J p s := by + exact mul_nonneg (bernoulliWeight_nonneg _ _ p) + (Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p) + + +theorem spliceTupleWeight_exchange (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (s : SpliceState E) (M : Set E) (i : ℕ) (hi : i ∈ J) : + spliceTupleWeight Q J p (exchangeState M i s) = spliceTupleWeight Q J p s := by + unfold spliceTupleWeight + rw [← Finset.mul_prod_erase J (fun l => + bernoulliWeight Q (domainBits Q ((exchangeState M i s).2 l)) p) hi, + ← Finset.mul_prod_erase J (fun l => bernoulliWeight Q (domainBits Q (s.2 l)) p) hi] + have herase : (∏ l ∈ J.erase i, + bernoulliWeight Q (domainBits Q ((exchangeState M i s).2 l)) p) = + ∏ l ∈ J.erase i, bernoulliWeight Q (domainBits Q (s.2 l)) p := by + apply Finset.prod_congr rfl + intro l hl + rw [exchangeState_away _ _ _ _ (Finset.mem_erase.mp hl).1] + rw [herase,exchangeState_first,exchangeState_at,← mul_assoc,← mul_assoc, + domainBits_exchange,domainBits_exchange, + bernoulliWeight_exchange _ _ _ _ (domainBits_subset Q s.1) (domainBits_subset Q (s.2 i)) p] + + +theorem SpliceExecution.weight (G : BondGraph V E) (x : V) + (s s' : SpliceState E) (code : List (ℕ × E)) + (h : SpliceExecution G x s code s') (Q : Finset E) (J : Finset ℕ) + (hJ : ∀ q ∈ code, q.1 ∈ J) (p : ℝ) : + spliceTupleWeight Q J p s' = spliceTupleWeight Q J p s := by + induction h with + | nil => rfl + | cons s s' s'' q code hstep hrest ih => + rw [ih (fun r hr => hJ r (List.mem_cons_of_mem _ hr))] + obtain ⟨y,a,b,_,_,_,_,_,rfl⟩ := hstep + exact spliceTupleWeight_exchange Q J p s _ q.1 (hJ q (List.mem_cons_self ..)) + + + +theorem splice_finite_weight_comparison (G : BondGraph V E) (x : V) + (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (code : List (ℕ × E)) + (hJ : ∀ q ∈ code, q.1 ∈ J) (A B : Finset (SpliceState E)) + (F : SpliceState E → SpliceState E) + (hex : ∀ s ∈ A, SpliceExecution G x s code (F s)) + (hB : ∀ s ∈ A, F s ∈ B) : + (∑ s ∈ A, spliceTupleWeight Q J p s) ≤ ∑ s ∈ B, spliceTupleWeight Q J p s := by + have hinj : Set.InjOn F (A : Set (SpliceState E)) := by + intro s hs t ht heq + exact (hex s hs).input_unique G x s t (F s) code (heq.symm ▸ hex t ht) + have hweight : (∑ s ∈ A, spliceTupleWeight Q J p s) = + ∑ s ∈ A.image F, spliceTupleWeight Q J p s := by + rw [Finset.sum_image hinj] + apply Finset.sum_congr rfl + intro s hs + exact ((hex s hs).weight G x s (F s) code Q J hJ p).symm + rw [hweight] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro t ht + obtain ⟨s,hs,rfl⟩ := Finset.mem_image.mp ht + exact hB s hs + · intro s _ _ + exact spliceTupleWeight_nonneg Q J p s + +end SpliceWeight + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BridgeGapGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem pivotalRank_lt_iff_of_cluster_finite (G : BondGraph V E) (ω : Set E) + (m : Set V) (x : V) (hC : (cluster G ω x).Finite) {e f : E} + (he : OpenMarkedPivotal G ω m x e) (hf : OpenMarkedPivotal G ω m x f) : + pivotalRank G ω x e < pivotalRank G ω x f ↔ + f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ := by + have hcut (q : E) : (cluster G (ω \ {q}) x).Finite := + hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) + have hexterior (hout : f ∈ internalEdges G (cluster G (ω \ {e}) x)ᶜ) : e ≠ f := by + obtain ⟨a,b,hab,hxa,_,_⟩ := openMarkedPivotal_oriented G ω m x he + intro h; subst f + exact ((mem_internalEdges_of_ends G _ e a b hab).mp hout).1 hxa + constructor + · intro hlt + have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) + rcases pivotal_other_sides G ω m x he hf hne.symm with hinside | hout + · obtain ⟨a,b,hab,_,hxb,hbm⟩ := openMarkedPivotal_oriented G ω m x he + obtain ⟨y,hy,hby⟩ := hbm + have hby' : Conn G (ω \ {f}) b y := conn_mono G + (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_internal_of_outside G (ω \ {e}) x hinside hxb hby) + have hb : b ∉ cluster G (ω \ {f}) x := fun h => hf.2.2 ⟨y,hy,h.trans hby'⟩ + have ha : a ∉ cluster G (ω \ {f}) x := fun h => + hb ((edge_cluster_sides G (ω \ {f}) x ⟨he.1,hne⟩ hab).mp h) + have hs := pivotal_rootSide_ssubset G ω m x hf hne.symm + ((mem_internalEdges_of_ends G _ e a b hab).mpr ⟨ha,hb⟩) + have hrev := Set.ncard_lt_ncard hs (hcut e) + exact (Nat.not_lt_of_ge (Nat.le_of_lt hrev) hlt).elim + · exact hout + · intro hout + exact Set.ncard_lt_ncard (pivotal_rootSide_ssubset G ω m x he (hexterior hout) hout) (hcut f) + +theorem pivotal_internal_of_rank_lt (G : BondGraph V E) (ω : Set E) + (m : Set V) (x : V) (hC : (cluster G ω x).Finite) {e f : E} + (he : OpenMarkedPivotal G ω m x e) (hf : OpenMarkedPivotal G ω m x f) + (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : + e ∈ internalEdges G (cluster G (ω \ {f}) x) := by + have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) + rcases pivotal_other_sides G ω m x hf he hne with h | h + · exact h + · have hr := (pivotalRank_lt_iff_of_cluster_finite G ω m x hC hf he).mpr h + omega + + +theorem conn_far_end_avoids_later_pivotal (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e g : E} + (he : OpenMarkedPivotal G ω {z} x e) (hg : OpenMarkedPivotal G ω {z} x g) + (hlt : pivotalRank G ω x e < pivotalRank G ω x g) + (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) : + Conn G (ω \ {g}) x b := by + have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp hlt + have hne : e ≠ g := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) + have hc : Conn G (ω \ {g}) x a := + conn_mono G (ω₁ := (ω \ {e}) \ {g}) (ω₂ := ω \ {g}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_exterior_of_inside G (ω \ {e}) x hout (conn_refl G _ x) ha) + exact hc.tail ⟨e,⟨he.1,hne⟩,hab⟩ + + +theorem conn_near_end_avoids_earlier_pivotal (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {f g : E} + (hf : OpenMarkedPivotal G ω {z} x f) (hg : OpenMarkedPivotal G ω {z} x g) + (hlt : pivotalRank G ω x g < pivotalRank G ω x f) + (c d : V) (hcd : G f = s(c,d)) (hd : ¬Conn G (ω \ {f}) x d) + (hdz : Conn G (ω \ {f}) d z) : Conn G (ω \ {g}) c z := by + have hin := pivotal_internal_of_rank_lt G ω {z} x hC hg hf hlt + have hne : f ≠ g := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h.symm) + have hc : Conn G (ω \ {g}) d z := + conn_mono G (ω₁ := (ω \ {f}) \ {g}) (ω₂ := ω \ {g}) (fun _ h => ⟨h.1.1,h.2⟩) + (conn_delete_internal_of_outside G (ω \ {f}) x hin hd hdz) + exact (Relation.ReflTransGen.single ⟨f,⟨hf.1,hne⟩,hcd⟩).trans hc + + + +theorem pivotal_between_is_internal (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e f g : E} + (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) + (hg : OpenMarkedPivotal G ω {z} x g) + (heg : pivotalRank G ω x e < pivotalRank G ω x g) + (hgf : pivotalRank G ω x g < pivotalRank G ω x f) + (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) + (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) + (hdz : Conn G (ω \ {f}) d z) + (hbc : Conn G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : + OpenMarkedPivotal G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) {c} b g := by + have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp heg + have hin := pivotal_internal_of_rank_lt G ω {z} x hC hg hf hgf + refine ⟨⟨hg.1,fun v hv => ⟨hin v hv,hout v hv⟩⟩,⟨c,rfl,hbc⟩,?_⟩ + rintro ⟨w,hw,hbw⟩ + have hbc' : Conn G (ω \ {g}) b c := by + have hw' : w = c := Set.mem_singleton_iff.mp hw + subst w + apply conn_mono G ?_ hbw + intro q hq + exact ⟨hq.1.1,hq.2⟩ + apply hg.2.2 + exact ⟨z,rfl,(conn_far_end_avoids_later_pivotal G ω x z hC he hg heg a b hab ha).trans + (hbc'.trans (conn_near_end_avoids_earlier_pivotal G ω x z hC hf hg hgf c d hcd hd hdz))⟩ + + +theorem pivotal_after_is_internal (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e g : E} + (he : OpenMarkedPivotal G ω {z} x e) (hg : OpenMarkedPivotal G ω {z} x g) + (heg : pivotalRank G ω x e < pivotalRank G ω x g) + (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) + (hbz : Conn G (ω ∩ internalEdges G + (cluster G ω x \ cluster G (ω \ {e}) x)) b z) : + OpenMarkedPivotal G (ω ∩ internalEdges G + (cluster G ω x \ cluster G (ω \ {e}) x)) {z} b g := by + have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hg).mp heg + have hin : g ∈ internalEdges G (cluster G ω x) := by + obtain ⟨u,v,huv,hxu,_,_⟩ := openMarkedPivotal_oriented G ω {z} x hg + have hu : u ∈ cluster G ω x := conn_mono G Set.sdiff_subset hxu + exact (mem_internalEdges_of_ends G _ g u v huv).mpr + ⟨hu,(edge_cluster_sides G ω x hg.1 huv).mp hu⟩ + refine ⟨⟨hg.1,fun v hv => ⟨hin v hv,hout v hv⟩⟩,⟨z,rfl,hbz⟩,?_⟩ + rintro ⟨w,hw,hbw⟩ + have hbz' : Conn G (ω \ {g}) b z := by + have hw' : w = z := Set.mem_singleton_iff.mp hw + subst w + apply conn_mono G ?_ hbw + intro q hq + exact ⟨hq.1.1,hq.2⟩ + exact hg.2.2 ⟨z,rfl, + (conn_far_end_avoids_later_pivotal G ω x z hC he hg heg a b hab ha).trans hbz'⟩ + +end BridgeGapGeometry + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BridgeGapCount +attribute [local instance] Classical.propDecidable Classical.decEq + +@[simp] theorem separatingBonds_card (G : BondGraph V E) (ω : Set E) (x z : V) : + (separatingBonds G ω x z).card = pivotalDistance G ω x z := by + exact Set.ncard_coe_finset (separatingBonds G ω x z) |>.symm.trans (by + congr 1 + ext e + exact mem_separatingBonds G ω x z e) + + +noncomputable def bridgeInterval (G : BondGraph V E) (ω : Set E) (x z : V) (e f : E) : Finset E := + (separatingBonds G ω x z).filter fun g => + pivotalRank G ω x e < pivotalRank G ω x g ∧ pivotalRank G ω x g < pivotalRank G ω x f + +theorem bridgeIndex_interval_identity (G : BondGraph V E) (ω : Set E) (x z : V) + (hC : (cluster G ω x).Finite) {e f : E} + (hf : OpenMarkedPivotal G ω {z} x f) + (hlt : pivotalRank G ω x e < pivotalRank G ω x f) : + bridgeIndex G ω x z f = bridgeIndex G ω x z e + (bridgeInterval G ω x z e f).card + 1 := by + let P := separatingBonds G ω x z + let A := P.filter fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e + let B := bridgeInterval G ω x z e f + have hdis : Disjoint A B := by + apply Finset.disjoint_left.mpr + intro g hgA hgB + have h₁ := (Finset.mem_filter.mp hgA).2 + have h₂ := (Finset.mem_filter.mp hgB).2.1 + omega + have hnot : f ∉ A ∪ B := by + intro hh + rcases Finset.mem_union.mp hh with h | h + · have hr := (Finset.mem_filter.mp h).2 + omega + · exact (Nat.lt_irrefl _) (Finset.mem_filter.mp h).2.2 + have hset : P.filter (fun g => pivotalRank G ω x g ≤ pivotalRank G ω x f) = insert f (A ∪ B) := by + ext g + constructor + · intro hg + obtain ⟨hgP,hgf⟩ := Finset.mem_filter.mp hg + by_cases hge : g = f + · exact Finset.mem_insert.mpr (Or.inl hge) + · apply Finset.mem_insert.mpr + apply Or.inr + by_cases hga : pivotalRank G ω x g ≤ pivotalRank G ω x e + · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨hgP,hga⟩) + · apply Finset.mem_union_right + apply Finset.mem_filter.mpr + refine ⟨hgP,Nat.lt_of_not_ge hga,?_⟩ + apply lt_of_le_of_ne hgf + intro hr + exact hge (pivotalRank_injective_of_cluster_finite G ω {z} x hC + ((mem_separatingBonds G ω x z g).mp hgP) hf hr) + · intro hg + rcases Finset.mem_insert.mp hg with heq | hg + · subst g + exact Finset.mem_filter.mpr ⟨(mem_separatingBonds G ω x z f).mpr hf,le_refl _⟩ + · rcases Finset.mem_union.mp hg with hg | hg + · exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hg).1, + (Finset.mem_filter.mp hg).2.trans (Nat.le_of_lt hlt)⟩ + · exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hg).1, + Nat.le_of_lt (Finset.mem_filter.mp hg).2.2⟩ + change (P.filter _).card = A.card+B.card+1 + rw [hset,Finset.card_insert_of_notMem hnot,Finset.card_union_of_disjoint hdis] + +theorem bridgeInterval_card_le (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e f : E} + (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) + (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) + (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) + (hdz : Conn G (ω \ {f}) d z) + (hbc : Conn G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : + (bridgeInterval G ω x z e f).card ≤ pivotalDistance G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by + rw [← separatingBonds_card] + apply Finset.card_le_card + intro g hg + obtain ⟨hgP,heg,hgf⟩ := Finset.mem_filter.mp hg + apply (mem_separatingBonds _ _ _ _ _).mpr + exact pivotal_between_is_internal G ω x z hC he hf + ((mem_separatingBonds G ω x z g).mp hgP) heg hgf a b c d hab hcd ha hd hdz hbc + + +theorem bridge_gap_le_internal_distance (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e f : E} + (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) + (hlt : pivotalRank G ω x e < pivotalRank G ω x f) + (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) + (ha : Conn G (ω \ {e}) x a) (hd : ¬Conn G (ω \ {f}) x d) + (hdz : Conn G (ω \ {f}) d z) + (hbc : Conn G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c) : + bridgeIndex G ω x z f - bridgeIndex G ω x z e ≤ + 1 + pivotalDistance G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by + have hid := bridgeIndex_interval_identity G ω x z hC hf hlt + have hle := bridgeInterval_card_le G ω x z hC he hf a b c d hab hcd ha hd hdz hbc + omega + + +theorem bridge_terminal_gap_le_internal_distance (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e : E} + (he : OpenMarkedPivotal G ω {z} x e) + (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) + (hbz : Conn G (ω ∩ internalEdges G + (cluster G ω x \ cluster G (ω \ {e}) x)) b z) : + (separatingBonds G ω x z).card + 1 - bridgeIndex G ω x z e ≤ + 1 + pivotalDistance G (ω ∩ internalEdges G + (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by + let P := separatingBonds G ω x z + let A := P.filter fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e + let B := P.filter fun g => pivotalRank G ω x e < pivotalRank G ω x g + have hid : A.card + B.card = P.card := by + simpa only [A,B,not_le] using Finset.card_filter_add_card_filter_not + (s := P) (fun g => pivotalRank G ω x g ≤ pivotalRank G ω x e) + have hle : B.card ≤ pivotalDistance G (ω ∩ internalEdges G + (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by + rw [← separatingBonds_card] + apply Finset.card_le_card + intro g hg + obtain ⟨hgP,heg⟩ := Finset.mem_filter.mp hg + apply (mem_separatingBonds _ _ _ _ _).mpr + exact pivotal_after_is_internal G ω x z hC he + ((mem_separatingBonds G ω x z g).mp hgP) heg a b hab ha hbz + change P.card+1-A.card ≤ _ + omega + + +theorem pivotalDistance_le_cluster_card (G : BondGraph V E) (ω : Set E) (x z : V) + (hC : (cluster G ω x).Finite) : + pivotalDistance G ω x z ≤ (cluster G ω x).ncard - 1 := by + rw [← separatingBonds_card] + let N := (cluster G ω x).ncard + have hm : Set.MapsTo (pivotalRank G ω x) (separatingBonds G ω x z : Set E) + (Finset.Ico 1 N : Set ℕ) := by + intro e he + have he' := (mem_separatingBonds G ω x z e).mp he + have hfin : (cluster G (ω \ {e}) x).Finite := + hC.subset (fun _ h => conn_mono G Set.sdiff_subset h) + have hpos : 0 < pivotalRank G ω x e := + (Set.ncard_pos hfin).mpr ⟨x,conn_refl G _ x⟩ + have hlt : pivotalRank G ω x e < N := by + apply Set.ncard_lt_ncard _ hC + refine Set.ssubset_iff_subset_ne.mpr ⟨fun v hv => conn_mono G Set.sdiff_subset hv,?_⟩ + intro heq + obtain ⟨v,hv,hxv⟩ := he'.2.1 + apply he'.2.2 + refine ⟨v,hv,?_⟩ + change v ∈ cluster G (ω \ {e}) x + rw [heq] + exact hxv + exact Finset.mem_Ico.mpr ⟨hpos,hlt⟩ + have hi : Set.InjOn (pivotalRank G ω x) (separatingBonds G ω x z : Set E) := by + intro e he f hf h + exact pivotalRank_injective_of_cluster_finite G ω {z} x hC + ((mem_separatingBonds G ω x z e).mp he) ((mem_separatingBonds G ω x z f).mp hf) h + simpa only [Nat.card_Ico,N] using Finset.card_le_card_of_injOn (pivotalRank G ω x) hm hi + + + +theorem inverse_contact_weight_le (K l : ℕ) (L : ℝ) (hK : 1 ≤ K) (hl : 1 ≤ l) + (hL : 1 ≤ L) (hgap : (l:ℝ) ≤ 1 + K*L) : + (K:ℝ)⁻¹ ≤ min 1 (2*L/l) := by + have hKr : (1:ℝ) ≤ K := by exact_mod_cast hK + have hlr : (1:ℝ) ≤ l := by exact_mod_cast hl + have hKpos : (0:ℝ) < K := lt_of_lt_of_le zero_lt_one hKr + have hlpos : (0:ℝ) < l := lt_of_lt_of_le zero_lt_one hlr + apply le_min + · exact inv_le_one_of_one_le₀ hKr + · apply (le_div_iff₀ hlpos).mpr + apply (inv_mul_le_iff₀ hKpos).mpr + by_cases h1 : l = 1 + · simp only [h1,Nat.cast_one] + nlinarith + · have h2 : (2:ℝ) ≤ l := by exact_mod_cast (show 2 ≤ l by omega) + nlinarith + +end BridgeGapCount + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section BridgePiecePath +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem conn_restrict_cluster_of_subset (G : BondGraph V E) (ω : Set E) (x : V) + {η : Set E} (hη : η ⊆ ω) {a b : V} (ha : a ∈ cluster G ω x) + (hab : Conn G η a b) : Conn G (η ∩ internalEdges G (cluster G ω x)) a b := by + induction hab with + | refl => exact conn_refl G _ a + | @tail u v hau huv ih => + obtain ⟨e,he,heq⟩ := huv + have hu : u ∈ cluster G ω x := ha.trans (conn_mono G hη hau) + have hv : v ∈ cluster G ω x := (edge_cluster_sides G ω x (hη he) heq).mp hu + exact ih.tail ⟨e,⟨he,(mem_internalEdges_of_ends G _ e u v heq).mpr ⟨hu,hv⟩⟩,heq⟩ + + + +theorem conn_between_pivotals_internal (G : BondGraph V E) (ω : Set E) + (x z : V) (hC : (cluster G ω x).Finite) {e f : E} + (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {z} x f) + (hlt : pivotalRank G ω x e < pivotalRank G ω x f) + (a b c d : V) (hab : G e = s(a,b)) (hcd : G f = s(c,d)) + (ha : Conn G (ω \ {e}) x a) (hb : ¬Conn G (ω \ {e}) x b) + (hc : Conn G (ω \ {f}) x c) : + Conn G (ω ∩ internalEdges G + (cluster G (ω \ {f}) x \ cluster G (ω \ {e}) x)) b c := by + have hne : e ≠ f := fun h => (Nat.ne_of_lt hlt) (congrArg (pivotalRank G ω x) h) + have hout := (pivotalRank_lt_iff_of_cluster_finite G ω {z} x hC he hf).mp hlt + have hcnot : c ∉ cluster G (ω \ {e}) x := + ((mem_internalEdges_of_ends G _ f c d hcd).mp hout).1 + have hins : insert e ((ω \ {e}) \ {f}) = ω \ {f} := by + ext q + simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] + constructor + · rintro (rfl | ⟨⟨hq,hqe⟩,hqf⟩) + · exact ⟨he.1,hne⟩ + · exact ⟨hq,hqf⟩ + · rintro ⟨hq,hqf⟩ + by_cases hqe : q = e + · exact Or.inl hqe + · exact Or.inr ⟨⟨hq,hqe⟩,hqf⟩ + have hbc : Conn G ((ω \ {e}) \ {f}) b c := by + rw [← hins,conn_insert_iff G _ e a b x c hab] at hc + rcases hc with h | ⟨_,h⟩ | ⟨h,_⟩ + · exact (hcnot (conn_mono G Set.sdiff_subset h)).elim + · exact h + · exact (hb (conn_mono G Set.sdiff_subset h)).elim + have hbo : b ∈ cluster G (ω \ {f}) x := + conn_far_end_avoids_later_pivotal G ω x z hC he hf hlt a b hab ha + have hp := conn_restrict_cluster_compl_of_subset G (ω \ {e}) x Set.sdiff_subset hb hbc + have hp' := conn_restrict_cluster_of_subset G (ω \ {f}) x + (η := ((ω \ {e}) \ {f}) ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) + (fun _ h => ⟨h.1.1.1,h.1.2⟩) hbo hp + apply conn_mono G ?_ hp' + intro q hq + exact ⟨hq.1.1.1.1,fun v hv => ⟨hq.2 v hv,hq.1.2 v hv⟩⟩ + + +theorem conn_after_pivotal_internal (G : BondGraph V E) (ω : Set E) + (x z : V) {e : E} (he : OpenMarkedPivotal G ω {z} x e) + (a b : V) (hab : G e = s(a,b)) (ha : Conn G (ω \ {e}) x a) + (hb : ¬Conn G (ω \ {e}) x b) (hbz : Conn G (ω \ {e}) b z) : + Conn G (ω ∩ internalEdges G (cluster G ω x \ cluster G (ω \ {e}) x)) b z := by + have hbo : b ∈ cluster G ω x := + (conn_mono G Set.sdiff_subset ha).tail ⟨e,he.1,hab⟩ + have hp := conn_restrict_cluster_compl G (ω \ {e}) x hb hbz + have hp' := conn_restrict_cluster_of_subset G ω x + (η := (ω \ {e}) ∩ internalEdges G (cluster G (ω \ {e}) x)ᶜ) + (fun _ h => h.1.1) hbo hp + apply conn_mono G ?_ hp' + intro q hq + exact ⟨hq.1.1.1,fun v hv => ⟨hq.2 v hv,hq.1.2 v hv⟩⟩ + + +theorem pivotalDistance_le_induced_card (G : BondGraph V E) (ω : Set E) + (B : Set V) (hB : B.Finite) {a b : V} (ha : a ∈ B) : + pivotalDistance G (ω ∩ internalEdges G B) a b ≤ B.ncard-1 := by + have hsub : cluster G (ω ∩ internalEdges G B) a ⊆ B := + fun _ h => conn_internal_endpoint G B ha h + exact (pivotalDistance_le_cluster_card G (ω ∩ internalEdges G B) a b (hB.subset hsub)).trans + (Nat.sub_le_sub_right (Set.ncard_le_ncard hsub hB) 1) + +end BridgePiecePath + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SplicePieceGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem conn_after_pivotal_of_orientation (G : BondGraph V E) (ω : Set E) + (x z : V) {e : E} (he : OpenMarkedPivotal G ω {z} x e) + (a b : V) (hab : G e = s(a,b)) (hb : ¬Conn G (ω \ {e}) x b) : + Conn G (ω \ {e}) b z := by + have hins : insert e (ω \ {e}) = ω := by + ext q + simp only [Set.mem_insert_iff,Set.mem_sdiff,Set.mem_singleton_iff] + by_cases hqe : q = e <;> simp_all [he.1] + obtain ⟨w,hw,hxw⟩ := he.2.1 + have hw' : w = z := Set.mem_singleton_iff.mp hw + subst w + rw [← hins,conn_insert_iff G _ e a b x z hab] at hxw + rcases hxw with h | ⟨_,h⟩ | ⟨h,_⟩ + · exact (he.2.2 ⟨z,rfl,h⟩).elim + · exact h + · exact (hb h).elim + + +theorem SpliceTrace.internal_agreement (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : + ∀ q ∈ internalEdges G (cluster G ω x), q ∈ ωf ↔ q ∈ ω := by + induction h with + | stop => exact fun _ _ => Iff.rfl + | @step j i ω e a b rest ωf _ _ _ _ hy he hab ha hb ht ih => + intro q hq + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + have hB : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy + have hbS : b ∉ S := hB hb + have hqq : q ∈ internalEdges G (cluster G ω' x) := by + rw [splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb] + exact fun v hv => Or.inl (hq v hv) + rw [ih q hqq] + change q ∈ internalEdges G S at hq + have hh := (splice_internal_fields G S B e ω (η i) a b hab hbS hB).1 + exact Iff.of_eq (show (q ∈ ω') = (q ∈ ω) from by + have := congrArg (fun A : Set E => q ∈ A) hh + simpa only [Set.mem_inter_iff,hq,and_true] using this) + + +theorem SpliceTrace.head_cut (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) : + cluster G (ωf \ {e}) x = cluster G ω x := by + cases h with + | step j i ω e a b rest ωf _ _ _ hmax hy he hab ha hb ht => + have hc := splice_close_seam_cluster G ω (η i) x (y i) hy e a b hab he ha hb + rw [SpliceTrace.preserve_cut G x η y k i _ ωf rest ht e] + · exact hc + · intro l hil hlk + rw [hc] + exact hmax l hil hlk + + +theorem contactSet_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (B : Set V) (hB : B.Finite) : (contactSet G ω B).Finite := by + let W := hB.toFinset + have hWB : (W : Set V) = B := hB.coe_toFinset + apply (incidentSupport G hloc W).finite_toSet.subset + rintro e ⟨_,a,b,hab,ha,_⟩ + apply (mem_incidentSupport G hloc W e).mpr + refine ⟨a,?_,?_⟩ + · change a ∈ (W : Set V) + rw [hWB] + exact ha + · simp [hab] + + + +theorem goodForScale_piece (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) + (hg : GoodForScale G ω x L) (B : Set V) (hB : B.Finite) + (hBC : B ⊆ cluster G ω x) + (hconn : ∀ a ∈ B, ∀ b ∈ B, Conn G (ω ∩ internalEdges G B) a b) + (hK : 0 < (contactSet G ω B).ncard) {a b : V} (ha : a ∈ B) (hb : b ∈ B) : + (pivotalDistance G (ω ∩ internalEdges G B) a b : ℝ) ≤ + (contactSet G ω B).ncard*L := by + let W := hB.toFinset + have hWB : (W : Set V) = B := hB.coe_toFinset + have hh := hg W (by simpa only [hWB] using hBC) + (by simpa only [← Finset.mem_coe,hWB] using hconn) + (by simpa only [hWB] using hK) a (by simpa only [← Finset.mem_coe,hWB] using ha) + b (by simpa only [← Finset.mem_coe,hWB] using hb) + simpa only [hWB] using hh + + +theorem slit_piece_connected (G : BondGraph V E) (η : Set E) (S : Set V) (y : V) + (_hy : y ∉ S) : + let B := cluster G (η ∩ internalEdges G Sᶜ) y + ∀ a ∈ B, ∀ b ∈ B, Conn G (η ∩ internalEdges G B) a b := by + intro B a ha b hb + have hc := conn_restrict_cluster G (η ∩ internalEdges G Sᶜ) y ha + (conn_trans G _ (conn_symm G _ ha) hb) + apply conn_mono G ?_ hc + exact fun _ h => ⟨h.1.1,h.2⟩ + +end SplicePieceGeometry + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SpliceGapBound +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def traceHeadGap (G : BondGraph V E) (ωf : Set E) (x z : V) + (e : E) (rest : List (ℕ × E)) : ℕ := + (match rest with + | [] => (separatingBonds G ωf x z).card + 1 + | (_,f)::_ => bridgeIndex G ωf x z f) - bridgeIndex G ωf x z e + + + +theorem SpliceTrace.head_gap_bounds (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j i M : ℕ) + (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) + (hCf : (cluster G ωf x).Finite) + (hCi : (cluster G (η i) (y i)).Finite) + (hM : (cluster G (η i) (y i)).ncard ≤ M) + (L : ℝ) (hgood : GoodForScale G (η i) (y i) L) : + let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) + let K := (contactSet G (η i) B).ncard + let l := traceHeadGap G ωf x (y k) e rest + 1 ≤ K ∧ 1 ≤ l ∧ l ≤ M ∧ (l:ℝ) ≤ 1 + K*L := by + have hfull := h + cases h with + | step j i ω e a b rest ωf hn _ _ _ hy he hab ha hb ht => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + let K := (contactSet G (η i) B).ncard + change 1 ≤ K ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ + traceHeadGap G ωf x (y k) e rest ≤ M ∧ + (traceHeadGap G ωf x (y k) e rest:ℝ) ≤ 1+K*L + have hBo : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy + have hBC : B ⊆ cluster G (η i) (y i) := fun _ h => conn_mono G Set.inter_subset_left h + have hB : B.Finite := hCi.subset hBC + have hKB : (contactSet G (η i) B).Finite := contactSet_finite G hloc (η i) B hB + have heK : e ∈ contactSet G (η i) B := + ⟨he,b,a,hab.trans (Sym2.eq_swap ..),hb,fun h => hBo h ha⟩ + have hK : 0 < K := (Set.ncard_pos hKB).mpr ⟨e,heK⟩ + have hBpos : 0 < B.ncard := (Set.ncard_pos hB).mpr ⟨b,hb⟩ + have hBM : B.ncard ≤ M := (Set.ncard_le_ncard hBC hCi).trans hM + have hcluster : cluster G ω' x = S ∪ B := + splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb + have hcut : cluster G (ωf \ {e}) x = S := + SpliceTrace.head_cut G x η y k j i ω ωf e rest hfull + have hpe : OpenMarkedPivotal G ωf {y k} x e := + SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::rest) hfull (i,e) (by simp) + have hxa : Conn G (ωf \ {e}) x a := by + change a ∈ cluster G (ωf \ {e}) x + rw [hcut] + exact ha + have hxb : ¬Conn G (ωf \ {e}) x b := by + change b ∉ cluster G (ωf \ {e}) x + rw [hcut] + exact hBo hb + have hbits : ωf ∩ internalEdges G B = η i ∩ internalEdges G B := by + have hii := (splice_internal_fields G S B e ω (η i) a b hab (hBo hb) hBo).2 + ext q + by_cases hq : q ∈ internalEdges G B + · have hq' : q ∈ internalEdges G (cluster G ω' x) := by + rw [hcluster] + exact fun v hv => Or.inr (hq v hv) + have hiff := SpliceTrace.internal_agreement G x η y k i ω' ωf rest ht q hq' + have hbit := congrArg (fun A : Set E => q ∈ A) hii + simpa only [Set.mem_inter_iff,hq,and_true,hiff] using Iff.of_eq hbit + · simp only [Set.mem_inter_iff,hq,and_false] + have hconn := slit_piece_connected G (η i) S (y i) hy + have finish (l : ℕ) (c : V) (hc : c ∈ B) (hl : 1 ≤ l) + (hg : l ≤ 1 + pivotalDistance G (ωf ∩ internalEdges G B) b c) : + 1 ≤ l ∧ l ≤ M ∧ (l:ℝ) ≤ 1+K*L := by + rw [hbits] at hg + have hp := pivotalDistance_le_induced_card G (η i) B hB hb (b := c) + have hg' : (l:ℝ) ≤ 1+(pivotalDistance G (η i ∩ internalEdges G B) b c:ℝ) := by + exact_mod_cast hg + have hgood' := goodForScale_piece G (η i) (y i) L hgood B hB hBC hconn hK hb hc + refine ⟨hl,by omega,?_⟩ + change (l:ℝ) ≤ 1+(contactSet G (η i) B).ncard*L + linarith + refine ⟨hK,?_⟩ + cases rest with + | nil => + have hfω : ωf = ω' := by cases ht; rfl + have hdiff : cluster G ωf x \ cluster G (ωf \ {e}) x = B := by + rw [hcut,hfω,hcluster] + ext v + constructor + · rintro ⟨hv,hnv⟩ + exact hv.resolve_left hnv + · intro hv + exact ⟨Or.inr hv,hBo hv⟩ + have hyk : y k ∈ B := by + have hz := SpliceTrace.endpoint G x η y k j ω ωf [(i,e)] hfull + rw [hfω,hcluster] at hz + exact hz.resolve_left hn + have hconnz := conn_after_pivotal_of_orientation G ωf x (y k) hpe a b hab hxb + have hp := conn_after_pivotal_internal G ωf x (y k) hpe a b hab hxa hxb hconnz + have hg := bridge_terminal_gap_le_internal_distance G ωf x (y k) hCf hpe a b hab hxa hp + rw [hdiff] at hg + apply finish _ (y k) hyk _ hg + have hcard : bridgeIndex G ωf x (y k) e ≤ (separatingBonds G ωf x (y k)).card := + Finset.card_filter_le _ _ + omega + | cons q more => + obtain ⟨l,f⟩ := q + have hcutf : cluster G (ωf \ {f}) x = S ∪ B := by + rw [SpliceTrace.head_cut G x η y k i l ω' ωf f more ht,hcluster] + have hss : cluster G (ωf \ {e}) x ⊂ cluster G (ωf \ {f}) x := by + rw [hcut,hcutf] + exact Set.ssubset_iff_subset_ne.mpr ⟨Set.subset_union_left,fun heq => + hBo hb (heq.symm ▸ (show b ∈ S ∪ B from Or.inr hb))⟩ + have hfFin : (cluster G (ωf \ {f}) x).Finite := + hCf.subset (fun _ h => conn_mono G Set.sdiff_subset h) + have hr : pivotalRank G ωf x e < pivotalRank G ωf x f := Set.ncard_lt_ncard hss hfFin + have hpf : OpenMarkedPivotal G ωf {y k} x f := + SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::(l,f)::more) hfull (l,f) (by simp) + obtain ⟨c,d,hcd,hxc,hxd,hdyk⟩ := openMarkedPivotal_oriented G ωf {y k} x hpf + have hdy : Conn G (ωf \ {f}) d (y k) := by + simpa only [MarkedEvent,Set.mem_singleton_iff,exists_eq_left] using hdyk + have hdiff : cluster G (ωf \ {f}) x \ cluster G (ωf \ {e}) x = B := by + rw [hcut,hcutf] + ext v + constructor + · rintro ⟨hv,hnv⟩ + exact hv.resolve_left hnv + · intro hv + exact ⟨Or.inr hv,hBo hv⟩ + have hc : c ∈ B := by + have hfout := (pivotalRank_lt_iff_of_cluster_finite G ωf {y k} x hCf hpe hpf).mp hr + have hcnot := ((mem_internalEdges_of_ends G _ f c d hcd).mp hfout).1 + rw [hcut] at hcnot + change c ∈ cluster G (ωf \ {f}) x at hxc + rw [hcutf] at hxc + exact hxc.resolve_left hcnot + have hp := conn_between_pivotals_internal G ωf x (y k) hCf hpe hpf hr + a b c d hab hcd hxa hxb (by change c ∈ cluster G (ωf \ {f}) x; rw [hcutf]; exact Or.inr hc) + have hg := bridge_gap_le_internal_distance G ωf x (y k) hCf hpe hpf hr + a b c d hab hcd hxa hxd hdy hp + rw [hdiff] at hg + apply finish _ c hc _ hg + have hind := bridgeIndex_interval_identity G ωf x (y k) hCf hpf hr + omega + +end SpliceGapBound + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section GapCode +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem SpliceTrace.seam_data (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : + ∀ q ∈ steps, j < q.1 ∧ q.1 ≤ k ∧ q.2 ∈ η q.1 ∧ + q.2 ∈ internalEdges G (cluster G (η q.1) (y q.1)) := by + induction h with + | stop => simp + | @step j i ω e a b rest ωf _ hji hik _ _ he hab _ hb ht ih => + intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · have hb' : b ∈ cluster G (η i) (y i) := conn_mono G Set.inter_subset_left hb + exact ⟨hji,hik,he,(mem_internalEdges_of_ends G _ e a b hab).mpr + ⟨(edge_cluster_sides G (η i) (y i) he hab).mpr hb',hb'⟩⟩ + · obtain ⟨hqi,hqk,hqe,hqC⟩ := ih q hq + exact ⟨hji.trans hqi,hqk,hqe,hqC⟩ + + +theorem SpliceTrace.head_index_lt (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) + (hC : (cluster G ωf x).Finite) : + ∀ q ∈ rest, bridgeIndex G ωf x (y k) e < bridgeIndex G ωf x (y k) q.2 := by + have hfull := h + have hc := SpliceTrace.head_cut G x η y k j i ω ωf e rest h + have hseams := SpliceTrace.seams_pivotal G x η y k j ω ωf ((i,e)::rest) h + cases h with + | step j i ω e a b rest ωf _ _ _ hmax _ _ _ _ _ ht => + intro q hq + obtain ⟨hqi,hqk,_,hqC⟩ := SpliceTrace.seam_data G x η y k i _ ωf rest ht q hq + have hout : q.2 ∈ internalEdges G (cluster G (ωf \ {e}) x)ᶜ := by + rw [hc] + intro v hv hvS + exact Set.disjoint_left.mp (hmax q.1 hqi hqk) (hqC v hv) hvS + have hpe := hseams (i,e) (by simp) + have hpq := hseams q (List.mem_cons_of_mem _ hq) + exact bridgeIndex_lt_of_rank_lt G ωf x (y k) hpq + ((pivotalRank_lt_iff_of_cluster_finite G ωf {y k} x hC hpe hpq).mpr hout) + + +noncomputable def gapSpliceCode (G : BondGraph V E) (ωf : Set E) (x z : V) : + List (ℕ × E) → List (ℕ × ℕ) + | [] => [] + | (i,e)::rest => (i,traceHeadGap G ωf x z e rest)::gapSpliceCode G ωf x z rest + + +def decodeGapOrdinals (N : ℕ) : List (ℕ × ℕ) → List (ℕ × ℕ) + | [] => [] + | (i,l)::rest => + let decoded := decodeGapOrdinals N rest + (i, (match decoded with | [] => N+1 | (_,r)::_ => r)-l)::decoded + + +theorem SpliceTrace.decode_gap_code (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) (hC : (cluster G ωf x).Finite) : + decodeGapOrdinals (separatingBonds G ωf x (y k)).card + (gapSpliceCode G ωf x (y k) steps) = ordinalSpliceCode G ωf x (y k) steps := by + induction steps generalizing j ω with + | nil => rfl + | cons q rest ih => + obtain ⟨i,e⟩ := q + have hlater := SpliceTrace.head_index_lt G x η y k j i ω ωf e rest h hC + cases h with + | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => + have ih' := ih i _ ht + simp only [gapSpliceCode,decodeGapOrdinals,ih',ordinalSpliceCode,List.map_cons] + congr 2 + cases rest with + | nil => + simp only [List.map_nil,traceHeadGap] + have hle : bridgeIndex G ωf x (y k) e ≤ (separatingBonds G ωf x (y k)).card := + Finset.card_filter_le _ _ + omega + | cons q qs => + obtain ⟨l,f⟩ := q + have hle := hlater (l,f) (by simp) + change bridgeIndex G ωf x (y k) e < bridgeIndex G ωf x (y k) f at hle + simp only [List.map_cons,traceHeadGap] + omega + + +theorem SpliceTrace.input_unique_of_gapCode (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) + (c₁ c₂ : List (ℕ × E)) + (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) + (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) + (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) + (heq : gapSpliceCode G ωf x (y₁ k) c₁ = gapSpliceCode G ωf x (y₁ k) c₂) + (θf : ℕ → Set E) + (he₁ : SpliceExecution G x (ω₁,η₁) c₁ (ωf,θf)) + (he₂ : SpliceExecution G x (ω₂,η₂) c₂ (ωf,θf)) : + (ω₁,η₁) = (ω₂,η₂) := by + apply SpliceTrace.input_unique_of_ordinalCode G x η₁ η₂ y₁ y₂ k j ω₁ ω₂ ωf + c₁ c₂ ht₁ ht₂ hz hC _ θf he₁ he₂ + rw [← SpliceTrace.decode_gap_code G x η₁ y₁ k j ω₁ ωf c₁ ht₁ hC, + heq,hz,SpliceTrace.decode_gap_code G x η₂ y₂ k j ω₂ ωf c₂ ht₂ hC] + +end GapCode + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section InverseCodeMass +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def gapWeight (L : ℝ) (l : ℕ) : ℝ := min 1 (2*L/l) + + +noncomputable def inverseCodeMass (M : ℕ) (L : ℝ) : ℝ := + 1 + ∑ l ∈ Finset.Icc 1 M, gapWeight L l + + +noncomputable def gapLetterWeight (L : ℝ) (l : ℕ) : ℝ := if l = 0 then 1 else gapWeight L l + +theorem gapWeight_nonneg (L : ℝ) (hL : 0 ≤ L) (l : ℕ) : 0 ≤ gapWeight L l := by + exact le_min zero_le_one (by positivity) + +theorem gapLetterWeight_nonneg (L : ℝ) (hL : 0 ≤ L) (l : ℕ) : 0 ≤ gapLetterWeight L l := by + unfold gapLetterWeight + split_ifs + · exact zero_le_one + · exact gapWeight_nonneg L hL l + +theorem sum_fin_succ_eq_Icc (M : ℕ) (f : ℕ → ℝ) : + ∑ l : Fin M, f (l.val+1) = ∑ l ∈ Finset.Icc 1 M, f l := by + rw [Fin.sum_univ_eq_sum_range (fun l => f (l+1)) M] + apply Finset.sum_bij (fun l _ => l+1) + · intro l hl + exact Finset.mem_Icc.mpr ⟨by omega,by have := Finset.mem_range.mp hl; omega⟩ + · intro l hl m hm h + omega + · intro l hl + obtain ⟨h1,hM⟩ := Finset.mem_Icc.mp hl + exact ⟨l-1,Finset.mem_range.mpr (by omega),by omega⟩ + · intros + rfl + +theorem sum_gapLetterWeight (M : ℕ) (L : ℝ) : + ∑ l : Fin (M+1), gapLetterWeight L l.val = inverseCodeMass M L := by + rw [Fin.sum_univ_succ] + simp only [Fin.val_zero,gapLetterWeight,Fin.val_succ,Nat.add_eq_zero_iff, + Nat.one_ne_zero,and_false,ite_false] + exact congrArg (1+·) (sum_fin_succ_eq_Icc M (gapWeight L)) + + + +theorem total_gap_code_mass (k M : ℕ) (L : ℝ) : + ∑ c : Fin k → Fin (M+1), ∏ i : Fin k, gapLetterWeight L (c i).val = + inverseCodeMass M L ^ k := by + rw [← Fintype.prod_sum (fun (_ : Fin k) (l : Fin (M+1)) => gapLetterWeight L l.val)] + simp only [sum_gapLetterWeight,Finset.prod_const,Finset.card_univ,Fintype.card_fin] + + +theorem valid_gap_code_mass_le (k M : ℕ) (L : ℝ) (hL : 0 ≤ L) + (valid : Finset (Fin k → Fin (M+1))) : + ∑ c ∈ valid, ∏ i : Fin k, gapLetterWeight L (c i).val ≤ inverseCodeMass M L ^ k := by + rw [← total_gap_code_mass] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun c _ _ => Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L hL (c i).val)) + +theorem inverseCodeMass_le_harmonic (M : ℕ) (L : ℝ) (hL : 0 ≤ L) : + inverseCodeMass M L ≤ 1+2*L*(1+Real.log M) := by + have hsum : ∑ l ∈ Finset.Icc 1 M, gapWeight L l ≤ + 2*L*∑ l ∈ Finset.Icc 1 M, (l:ℝ)⁻¹ := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro l _ + simpa only [gapWeight,div_eq_mul_inv] using min_le_right (1:ℝ) (2*L/l) + have hh : ∑ l ∈ Finset.Icc 1 M, (l:ℝ)⁻¹ ≤ 1+Real.log M := by + simpa only [harmonic_eq_sum_Icc,Rat.cast_sum,Rat.cast_inv,Rat.cast_natCast] using + harmonic_le_one_add_log M + unfold inverseCodeMass + have h := hsum.trans (mul_le_mul_of_nonneg_left hh (by positivity)) + linarith + + +theorem inverseCodeMass_le_log (M : ℕ) (L : ℝ) (hM : 2 ≤ M) (hL : 1 ≤ L) : + inverseCodeMass M L ≤ 8*L*Real.log M := by + have hlog2 : (1:ℝ)/2 ≤ Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (show (0:ℝ) < 2 by norm_num) + norm_num at hh ⊢ + exact hh + have hlog : (1:ℝ)/2 ≤ Real.log M := hlog2.trans + (Real.log_le_log (by norm_num) (by exact_mod_cast hM)) + have hLl : L/2 ≤ L*Real.log M := by nlinarith + have hbound := inverseCodeMass_le_harmonic M L (by linarith) + nlinarith + + +def contactInterval (K a : ℕ) : Set unitInterval := + {u | (a:ℝ)/K ≤ (u:ℝ) ∧ (u:ℝ) < (a+1:ℕ)/K} + +theorem volume_contactInterval (K a : ℕ) (ha : a < K) : + volume (contactInterval K a) = ENNReal.ofReal ((K:ℝ)⁻¹) := by + have hK : (0:ℝ) < K := by exact_mod_cast (show 0 < K by omega) + have hleft : (a:ℝ)/K ∈ Set.Icc (0:ℝ) 1 := by + refine ⟨by positivity,(div_le_one hK).mpr ?_⟩ + exact_mod_cast (Nat.le_of_lt ha) + have hright : ((a+1:ℕ):ℝ)/K ∈ Set.Icc (0:ℝ) 1 := by + refine ⟨by positivity,(div_le_one hK).mpr ?_⟩ + exact_mod_cast (show a+1 ≤ K by omega) + let lo : unitInterval := ⟨_,hleft⟩ + let hi : unitInterval := ⟨_,hright⟩ + have heq : contactInterval K a = Set.Ico lo hi := rfl + rw [heq,unitInterval.volume_Ico] + congr 1 + dsimp only [lo,hi] + push_cast + field_simp + ring + + + +theorem volume_contact_cube {I : Type*} [Fintype I] (K a : I → ℕ) + (ha : ∀ i, a i < K i) : + (volume : Measure (I → unitInterval)) (Set.pi Set.univ (fun i => contactInterval (K i) (a i))) = + ∏ i, ENNReal.ofReal ((K i:ℝ)⁻¹) := by + rw [MeasureTheory.volume_pi,Measure.pi_pi] + exact Finset.prod_congr rfl (fun i _ => volume_contactInterval (K i) (a i) (ha i)) + +theorem real_volume_contact_cube {I : Type*} [Fintype I] (K a : I → ℕ) + (ha : ∀ i, a i < K i) : + ((volume : Measure (I → unitInterval)) + (Set.pi Set.univ (fun i => contactInterval (K i) (a i)))).toReal = + ∏ i, (K i:ℝ)⁻¹ := by + rw [volume_contact_cube K a ha,ENNReal.toReal_prod] + exact Finset.prod_congr rfl (fun i _ => ENNReal.toReal_ofReal (by positivity)) + +end InverseCodeMass + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/Geometry.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/Geometry.lean index 67647ec52b40d78b4e1773121e70ceeb3f88c9a0..3d11bb8b0aa4dfa0d47ea0ef7d87c0af3d8e34ca 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/Geometry.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/Geometry.lean @@ -1,836 +1,836 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.Goodness -import OAI.Probability.UnimodularPercolation.Kernel.Spectral - -namespace OAI - -/-! Critical parameters and the geometry, selection and traces of splices. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} - -section CriticalParameter -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem twoPoint_adj_lower [Countable E] (G : BondGraph V E) (p : unitInterval) - (z x y : V) (hxy : Adj G x y) : (p:ℝ)*twoPoint G p z x ≤ twoPoint G p z y := by - obtain ⟨e,he⟩ := hxy - have h := association_finiteWitness p {ω : Set E | e ∈ ω} {ω | Conn G ω z x} - (fun _ _ hω h => hω h) (fun _ _ hω h => conn_mono G hω h) - (finiteWitness_edge e) (finiteWitness_conn G z x) - have hp : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by - simpa using finite_open_probability p {e} - rw [hp] at h - exact h.trans (measureReal_mono (fun ω hω => - conn_trans G ω hω.2 (Relation.ReflTransGen.single ⟨e,hω.1,he⟩))) - - -theorem walk_operator_apply (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) - (P : Hilbert V →L[ℂ] Hilbert V) - (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) - (f : Hilbert V) (x : V) : - P f x = ∑ y ∈ insert x (neighbors G hloc x), (walkKernel G hloc a x y : ℂ)*f y := by - have hz (y : V) (hy : y ∉ insert x (neighbors G hloc x)) : matrixCoeff P x y*f y = 0 := by - have hxy : x ≠ y := by intro h; subst y; exact hy (Finset.mem_insert_self _ _) - have hAdj : ¬Adj G x y := fun h => hy (Finset.mem_insert_of_mem ((mem_neighbors ..).mpr h)) - simp only [matrixCoeff,hP,walkKernel,ite_eq_right hxy,ite_eq_right hAdj,add_zero,Complex.ofReal_zero,zero_mul] - have hsum := (operator_kernel_hasSum P f x).unique (hasSum_sum_of_ne_finset_zero hz) - simpa only [matrixCoeff,hP] using hsum - - - -theorem parameter_le_walk_norm [Countable E] [Nonempty V] (G : BondGraph V E) - (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) - (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) - (P : Hilbert V →L[ℂ] Hilbert V) - (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) - (p : unitInterval) (hp : OperatorBounded G p) : (p:ℝ) ≤ ‖P‖ := by - obtain ⟨T,hT⟩ := hp - let z := Classical.arbitrary V - let f := T (lp.single 2 z (1:ℂ)) - have hf (x : V) : f x = (twoPoint G p x z : ℂ) := hT x z - have hf0 : 0 < ‖f‖ := by - apply norm_pos_iff.mpr - intro h - have hval := congrArg (fun g : Hilbert V => g z) h - simp [hf] at hval - have hrow (x : V) : (p:ℝ)*twoPoint G p x z ≤ - ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y*twoPoint G p y z := by - calc - _ = ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y*((p:ℝ)*twoPoint G p x z) := by - rw [← Finset.sum_mul,walkKernel_row_sum,one_mul] - _ ≤ _ := by - apply Finset.sum_le_sum - intro y hy - apply mul_le_mul_of_nonneg_left _ (walkKernel_nonneg G hloc D hD a ha haD x y) - rcases Finset.mem_insert.mp hy with rfl | hy - · exact mul_le_of_le_one_left (twoPoint_nonneg G p y z) p.2.2 - · simpa only [twoPoint_symm G p] using twoPoint_adj_lower G p z x y ((mem_neighbors ..).mp hy) - have hpoint (x : V) : ‖((p:ℂ) • f) x‖ ≤ ‖P f x‖ := by - rw [lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,hf,← Complex.ofReal_mul, - Complex.norm_of_nonneg (mul_nonneg p.2.1 (twoPoint_nonneg G p x z)), - walk_operator_apply G hloc a P hP] - simp only [hf,← Complex.ofReal_mul,← Complex.ofReal_sum] - rw [Complex.norm_of_nonneg (le_trans (mul_nonneg p.2.1 (twoPoint_nonneg G p x z)) (hrow x))] - exact hrow x - have hn := (lp.norm_mono (by norm_num : (2:ℝ≥0∞) ≠ 0) hpoint).trans (P.le_opNorm f) - rw [norm_smul,Complex.norm_of_nonneg p.2.1] at hn - exact (mul_le_mul_iff_left₀ hf0).mp hn - - -theorem pc_lt_one_of_nonamenable [Nonempty V] (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) - (hh : 0 < hV G) : pc G < 1 := by - let : Countable V := countable_vertices hloc hconn - let : Countable E := countable_edges hloc - obtain ⟨D,P,hD0,hD,hPn,_,hP⟩ := exists_strict_walk_operator G hloc hqt hh - have hDr : 0 < (D:ℝ) := by exact_mod_cast hD0 - let p : unitInterval := ⟨(‖P‖+1)/2,by constructor <;> linarith [norm_nonneg P]⟩ - have hp1 : p < 1 := by change (‖P‖+1)/2 < 1; linarith - have ha : 0 ≤ (1:ℝ)/(2*D) := by positivity - have haD : (1:ℝ)/(2*D)*D ≤ 1 := by - rw [div_mul_eq_mul_div] - apply (div_le_iff₀ (by positivity)).mpr - linarith - apply lt_of_le_of_ne (show pc G ≤ 1 from (pc G).2.2) - intro he - have hb := operatorBounded_of_lt_pc G hloc hqt p (he ▸ hp1) - have hle := parameter_le_walk_norm G hloc D hD _ ha haD P hP p hb - change (‖P‖+1)/2 ≤ ‖P‖ at hle - linarith - -end CriticalParameter - -section SpliceGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def exchangeOn (mask ω η : Set E) : Set E := (ω \ mask) ∪ (η ∩ mask) - -@[simp] theorem mem_exchangeOn {mask ω η : Set E} {e : E} : - e ∈ exchangeOn mask ω η ↔ if e ∈ mask then e ∈ η else e ∈ ω := by - by_cases h : e ∈ mask <;> simp [exchangeOn,h] - -theorem exchangeOn_involutive (mask ω η : Set E) : - exchangeOn mask (exchangeOn mask ω η) (exchangeOn mask η ω) = ω := by - ext e - by_cases h : e ∈ mask <;> simp [h] - - - -def spliceMask (G : BondGraph V E) (S B : Set V) (e : E) : Set E := - insert e {f | (∃ b ∈ B, b ∈ G f) ∧ f ∈ internalEdges G Sᶜ} - -def spliceField (G : BondGraph V E) (S B : Set V) (e : E) (ω η : Set E) : Set E := - exchangeOn (spliceMask G S B e) ω η - -theorem slit_cluster_subset (G : BondGraph V E) (S : Set V) (η : Set E) - (y : V) (hy : y ∉ S) : cluster G (η ∩ internalEdges G Sᶜ) y ⊆ Sᶜ := by - exact fun z hz => conn_internal_endpoint G Sᶜ hy hz - -theorem spliceMask_not_internal (G : BondGraph V E) (S B : Set V) (e : E) - (a b : V) (he : G e = s(a,b)) (hb : b ∉ S) {f : E} - (hf : f ∈ internalEdges G S) : f ∉ spliceMask G S B e := by - rintro (rfl | ⟨_,hout⟩) - · exact hb (((mem_internalEdges_of_ends G S f a b he).mp hf).2) - · exact (hout _ (Sym2.out_fst_mem _)) (hf _ (Sym2.out_fst_mem _)) - -theorem spliceMask_of_internal_piece (G : BondGraph V E) (S B : Set V) (e : E) - (hB : B ⊆ Sᶜ) {f : E} (hf : f ∈ internalEdges G B) : f ∈ spliceMask G S B e := by - right - exact ⟨⟨(G f).out.1,hf _ (Sym2.out_fst_mem _),Sym2.out_fst_mem _⟩, - fun v hv => hB (hf v hv)⟩ - - -theorem splice_internal_fields (G : BondGraph V E) (S B : Set V) (e : E) - (ω η : Set E) (a b : V) (he : G e = s(a,b)) (hb : b ∉ S) (hB : B ⊆ Sᶜ) : - spliceField G S B e ω η ∩ internalEdges G S = ω ∩ internalEdges G S ∧ - spliceField G S B e ω η ∩ internalEdges G B = η ∩ internalEdges G B := by - constructor - · ext f - by_cases hf : f ∈ internalEdges G S - · simp only [Set.mem_inter_iff,hf,and_true,spliceField,mem_exchangeOn, - ite_eq_right (spliceMask_not_internal G S B e a b he hb hf)] - · simp only [Set.mem_inter_iff,hf,and_false] - · ext f - by_cases hf : f ∈ internalEdges G B - · simp only [Set.mem_inter_iff,hf,and_true,spliceField,mem_exchangeOn, - ite_eq_left (spliceMask_of_internal_piece G S B e hB hf)] - · simp only [Set.mem_inter_iff,hf,and_false] - - -theorem splice_crossing_unique (G : BondGraph V E) (ω η : Set E) (x : V) - (B : Set V) (e : E) {f : E} {a b : V} - (hf : f ∈ spliceField G (cluster G ω x) B e ω η) - (hab : G f = s(a,b)) (ha : a ∈ cluster G ω x) (hb : b ∉ cluster G ω x) : f = e := by - have hno : f ∉ ω := fun h => hb ((edge_cluster_sides G ω x h hab).mp ha) - have hm : f ∈ spliceMask G (cluster G ω x) B e := by - by_contra h - have hh := hf - simp only [spliceField,mem_exchangeOn,ite_eq_right h] at hh - exact hno hh - rcases hm with rfl | ⟨_,hout⟩ - · rfl - · exact ((((mem_internalEdges_of_ends G _ f a b hab).mp hout).1) ha).elim - - - -theorem splice_cluster (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - cluster G (spliceField G S B e ω η) x = S ∪ B := by - let S := cluster G ω x - let ζ := η ∩ internalEdges G Sᶜ - let B := cluster G ζ y - let ω' := spliceField G S B e ω η - change cluster G ω' x = S ∪ B - have hB : B ⊆ Sᶜ := slit_cluster_subset G S η y hy - have hbS : b ∉ S := hB hb - have hfields := splice_internal_fields G S B e ω η a b he hbS hB - have he' : e ∈ ω' := by - change e ∈ exchangeOn (spliceMask G S B e) ω η - rw [mem_exchangeOn,ite_eq_left (show e ∈ spliceMask G S B e from Set.mem_insert _ _)] - exact heη - have hSconn (z : V) (hz : z ∈ S) : Conn G ω' x z := by - have h := conn_restrict_cluster G ω x (mem_cluster_self G ω x) hz - apply conn_mono G _ h - intro f hf - exact (hfields.1.symm ▸ hf).1 - have hBconn (u v : V) (hu : u ∈ B) (hv : v ∈ B) : Conn G ω' u v := by - have h := conn_restrict_cluster G ζ y hu (conn_trans G ζ (conn_symm G ζ hu) hv) - apply conn_mono G _ h - intro f hf - exact (hfields.2.symm ▸ (show f ∈ η ∩ internalEdges G B from ⟨hf.1.1,hf.2⟩)).1 - apply Set.Subset.antisymm - · intro z hz - induction hz with - | refl => exact Or.inl (mem_cluster_self G ω x) - | @tail u v hxu huv ih => - obtain ⟨f,hf,hfv⟩ := huv - by_cases hvS : v ∈ S - · exact Or.inl hvS - · rcases ih with huS | huB - · have hfe := splice_crossing_unique G ω η x B e hf hfv huS hvS - subst f - have hends := Sym2.eq_iff.mp (he.symm.trans hfv) - rcases hends with ⟨hau,hbv⟩ | ⟨hav,hbu⟩ - · exact Or.inr (hbv ▸ hb) - · exact (hvS (hav ▸ ha)).elim - · have huS : u ∉ S := hB huB - have hm : f ∈ spliceMask G S B e := by - right - exact ⟨⟨u,huB,by simp [hfv]⟩,(mem_internalEdges_of_ends G _ f u v hfv).mpr ⟨huS,hvS⟩⟩ - have hfη : f ∈ η := by - change f ∈ exchangeOn (spliceMask G S B e) ω η at hf - rwa [mem_exchangeOn,ite_eq_left hm] at hf - exact Or.inr ((edge_cluster_sides G ζ y - ⟨hfη,(mem_internalEdges_of_ends G _ f u v hfv).mpr ⟨huS,hvS⟩⟩ hfv).mp huB) - · intro z hz - rcases hz with hz | hz - · exact hSconn z hz - · exact ((hSconn a ha).tail ⟨e,he',he⟩).trans (hBconn b z hb hz) - - -theorem splice_seam_pivotal (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) - (z : V) (hz : z ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - OpenMarkedPivotal G (spliceField G S B e ω η) {z} x e := by - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - let ω' := spliceField G S B e ω η - have hB := slit_cluster_subset G S η y hy - have hC := splice_cluster G ω η x y hy e a b he heη ha hb - change cluster G ω' x = S ∪ B at hC - refine ⟨?_,⟨z,Set.mem_singleton z,by change z ∈ cluster G ω' x; rw [hC]; exact Or.inr hz⟩,?_⟩ - · change e ∈ exchangeOn (spliceMask G S B e) ω η - rw [mem_exchangeOn,ite_eq_left (show e ∈ spliceMask G S B e from Set.mem_insert _ _)] - exact heη - · rintro ⟨v,hv,hxv⟩ - have hvz : v = z := Set.mem_singleton_iff.mp hv - subst v - have hsub : cluster G (ω' \ {e}) x ⊆ S := by - intro v hxv - induction hxv with - | refl => exact mem_cluster_self G ω x - | @tail u v hxu huv ih => - obtain ⟨f,hf,hfv⟩ := huv - by_contra hvS - have hfe := splice_crossing_unique G ω η x B e hf.1 hfv ih hvS - exact hf.2 (by simpa only [Set.mem_singleton_iff] using hfe) - exact hB hz (hsub hxv) - -end SpliceGeometry - -section SpliceInverse -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem splice_close_seam_cluster (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (_heη : e ∈ η) (_ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - cluster G (spliceField G S B e ω η \ {e}) x = S := by - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - let ω' := spliceField G S B e ω η - have hB := slit_cluster_subset G S η y hy - have hf := (splice_internal_fields G S B e ω η a b he (hB hb) hB).1 - apply Set.Subset.antisymm - · intro v hxv - induction hxv with - | refl => exact mem_cluster_self G ω x - | @tail u v _ huv ih => - obtain ⟨f,hf,hfv⟩ := huv - by_contra hvS - have hfe := splice_crossing_unique G ω η x B e hf.1 hfv ih hvS - exact hf.2 (Set.mem_singleton_iff.mpr hfe) - · intro z hz - have hc := conn_restrict_cluster G ω x (mem_cluster_self G ω x) hz - apply conn_mono G _ hc - intro f hfin - refine ⟨(hf.symm ▸ hfin).1,?_⟩ - intro hfe - have hfe' := Set.mem_singleton_iff.mp hfe - subst f - exact hB hb (((mem_internalEdges_of_ends G S e a b he).mp hfin.2).2) - - -theorem splice_recover_piece (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - let ω' := spliceField G S B e ω η - cluster G ω' x \ cluster G (ω' \ {e}) x = B := by - dsimp only - rw [splice_cluster G ω η x y hy e a b he heη ha hb, - splice_close_seam_cluster G ω η x y hy e a b he heη ha hb] - have hB := slit_cluster_subset G (cluster G ω x) η y hy - ext z - constructor - · rintro ⟨hz,hzS⟩ - exact hz.resolve_left hzS - · intro hz - exact ⟨Or.inr hz,hB hz⟩ - - -def recoveredMask (G : BondGraph V E) (ω' : Set E) (x : V) (e : E) : Set E := - spliceMask G (cluster G (ω' \ {e}) x) - (cluster G ω' x \ cluster G (ω' \ {e}) x) e - -theorem recoveredMask_splice (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - recoveredMask G (spliceField G S B e ω η) x e = spliceMask G S B e := by - unfold recoveredMask - dsimp only - rw [splice_recover_piece G ω η x y hy e a b he heη ha hb, - splice_close_seam_cluster G ω η x y hy e a b he heη ha hb] - - -def undoSplice (G : BondGraph V E) (x : V) (e : E) (ω' η' : Set E) : Set E × Set E := - let M := recoveredMask G ω' x e - (exchangeOn M ω' η',exchangeOn M η' ω') - - -theorem undoSplice_of_valid (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - let M := spliceMask G S B e - undoSplice G x e (exchangeOn M ω η) (exchangeOn M η ω) = (ω,η) := by - dsimp only [undoSplice] - rw [show recoveredMask G (exchangeOn - (spliceMask G (cluster G ω x) (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e) ω η) x e = - spliceMask G (cluster G ω x) (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e from - recoveredMask_splice G ω η x y hy e a b he heη ha hb] - rw [exchangeOn_involutive,exchangeOn_involutive] - - -theorem spliceMask_finite (G : BondGraph V E) (hloc : LocallyFinite G) - (S B : Set V) (hB : B.Finite) (e : E) : (spliceMask G S B e).Finite := by - apply Set.Finite.insert - apply (hB.biUnion (fun b _ => hloc b)).subset - rintro f ⟨⟨b,hb,hbf⟩,_⟩ - exact Set.mem_iUnion₂.mpr ⟨b,hb,hbf⟩ - -end SpliceInverse - -section FiniteExchange -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteExchange (M ω η : Finset E) : Finset E := (ω \ M) ∪ (η ∩ M) - -@[simp] theorem coe_finiteExchange (M ω η : Finset E) : - (finiteExchange M ω η : Set E) = exchangeOn (M:Set E) (ω:Set E) (η:Set E) := by - simp only [finiteExchange,exchangeOn,Finset.coe_union,Finset.coe_sdiff,Finset.coe_inter] - -theorem finiteExchange_card (M ω η : Finset E) : - (finiteExchange M ω η).card = (ω \ M).card+(η ∩ M).card := by - apply Finset.card_union_of_disjoint - exact Finset.disjoint_left.mpr fun e he he' => (Finset.mem_sdiff.mp he).2 (Finset.mem_inter.mp he').2 - -theorem finiteExchange_card_sum (M ω η : Finset E) : - (finiteExchange M ω η).card+(finiteExchange M η ω).card = ω.card+η.card := by - rw [finiteExchange_card,finiteExchange_card] - have hω := Finset.card_sdiff_add_card_inter ω M - have hη := Finset.card_sdiff_add_card_inter η M - omega - -theorem finiteExchange_subset (M Q ω η : Finset E) (hω : ω ⊆ Q) (hη : η ⊆ Q) : - finiteExchange M ω η ⊆ Q := by - intro e he - rcases Finset.mem_union.mp he with he | he - · exact hω (Finset.mem_sdiff.mp he).1 - · exact hη (Finset.mem_inter.mp he).1 - - -theorem bernoulliWeight_exchange (M Q ω η : Finset E) (hω : ω ⊆ Q) (hη : η ⊆ Q) - (p : ℝ) : - bernoulliWeight Q (finiteExchange M ω η) p * bernoulliWeight Q (finiteExchange M η ω) p = - bernoulliWeight Q ω p * bernoulliWeight Q η p := by - have hc := finiteExchange_card_sum M ω η - have hcω := Finset.card_le_card hω - have hcη := Finset.card_le_card hη - have hcω' := Finset.card_le_card (finiteExchange_subset M Q ω η hω hη) - have hcη' := Finset.card_le_card (finiteExchange_subset M Q η ω hη hω) - have hd : (Q.card-(finiteExchange M ω η).card)+(Q.card-(finiteExchange M η ω).card) = - (Q.card-ω.card)+(Q.card-η.card) := by omega - unfold bernoulliWeight - calc - _ = p^((finiteExchange M ω η).card+(finiteExchange M η ω).card) * - (1-p)^((Q.card-(finiteExchange M ω η).card)+(Q.card-(finiteExchange M η ω).card)) := by - rw [pow_add,pow_add]; ring - _ = p^(ω.card+η.card)*(1-p)^((Q.card-ω.card)+(Q.card-η.card)) := by rw [hc,hd] - _ = _ := by rw [pow_add,pow_add]; ring - -end FiniteExchange - -section DeletionGoodness -attribute [local instance] Classical.propDecidable Classical.decEq - - -def deletionContacts (G : BondGraph V E) (ω : Set E) (A B : Set V) : Set E := - {e | e ∈ ω ∧ ∃ a ∈ B, ∃ b ∈ A, G e = s(a,b)} - - - -def DeletionGoodForScale (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) : Prop := - ∀ A ⊆ cluster G ω x, ∀ y ∈ cluster G ω x \ A, - let B := cluster G (ω ∩ internalEdges G Aᶜ) y - 0 < (deletionContacts G ω A B).ncard → - ∀ a ∈ B, ∀ b ∈ B, - (pivotalDistance G (ω ∩ internalEdges G B) a b : ℝ) ≤ - (deletionContacts G ω A B).ncard*L - -theorem deleted_cluster_subset (G : BondGraph V E) (ω : Set E) (x y : V) - (A : Set V) (hy : y ∈ cluster G ω x \ A) : - cluster G (ω ∩ internalEdges G Aᶜ) y ⊆ cluster G ω x \ A := by - intro z hz - exact ⟨conn_trans G ω hy.1 (conn_mono G Set.inter_subset_left hz), - conn_internal_endpoint G Aᶜ hy.2 hz⟩ - -theorem contactSet_deleted_cluster (G : BondGraph V E) (ω : Set E) (A : Set V) - (y : V) (hy : y ∉ A) : - let B := cluster G (ω ∩ internalEdges G Aᶜ) y - contactSet G ω B = deletionContacts G ω A B := by - let ζ := ω ∩ internalEdges G Aᶜ - let B := cluster G ζ y - have hB : B ⊆ Aᶜ := slit_cluster_subset G A ω y hy - ext e - constructor - · rintro ⟨he,a,b,hab,ha,hb⟩ - refine ⟨he,a,ha,b,?_,hab⟩ - by_contra hbA - have heζ : e ∈ ζ := ⟨he,(mem_internalEdges_of_ends G Aᶜ e a b hab).mpr ⟨hB ha,hbA⟩⟩ - exact hb ((edge_cluster_sides G ζ y heζ hab).mp ha) - · rintro ⟨he,a,ha,b,hb,hab⟩ - exact ⟨he,a,b,hab,ha,fun hh => hB hh hb⟩ - - - -theorem goodForScale_iff_deletion (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) - (hC : (cluster G ω x).Finite) : - GoodForScale G ω x L ↔ DeletionGoodForScale G ω x L := by - constructor - · intro h A _ y hy - let ζ := ω ∩ internalEdges G Aᶜ - let B := cluster G ζ y - have hBC := deleted_cluster_subset G ω x y A hy - have hfin : B.Finite := hC.subset (fun _ hz => (hBC hz).1) - let W := hfin.toFinset - have hW : (W : Set V) = B := hfin.coe_toFinset - have hsub : (W : Set V) ⊆ cluster G ω x := by rw [hW]; exact fun _ hz => (hBC hz).1 - have hi (a : V) (ha : a ∈ W) (b : V) (hb : b ∈ W) : - Conn G (ω ∩ internalEdges G (W : Set V)) a b := by - have ha' : a ∈ B := hW ▸ ha - have hb' : b ∈ B := hW ▸ hb - have hc := conn_restrict_cluster G ζ y ha' (conn_trans G ζ (conn_symm G ζ ha') hb') - rw [hW] - apply conn_mono G ?_ hc - intro e he - exact ⟨he.1.1,he.2⟩ - have hh := h W hsub hi - rw [hW,contactSet_deleted_cluster G ω A y hy.2] at hh - dsimp only - intro hK a ha b hb - exact hh hK a (by change a ∈ (W : Set V); rw [hW]; exact ha) b - (by change b ∈ (W : Set V); rw [hW]; exact hb) - · intro h W hW hconn hK a ha b hb - let C := cluster G ω x - let A := C \ (W : Set V) - have haA : a ∈ C \ A := ⟨hW ha,fun hh => hh.2 ha⟩ - have hWA : (W : Set V) ⊆ Aᶜ := fun _ hz hh => hh.2 hz - have heq : cluster G (ω ∩ internalEdges G Aᶜ) a = (W : Set V) := by - apply Set.Subset.antisymm - · intro z hz - have hzC := deleted_cluster_subset G ω x a A haA hz - by_contra hzW - exact hzC.2 ⟨hzC.1,hzW⟩ - · intro z hz - apply conn_mono G ?_ (hconn a ha z hz) - intro e he - exact ⟨he.1,fun v hv => hWA (he.2 v hv)⟩ - have hh := h A Set.sdiff_subset a haA - dsimp only at hh - have hc := contactSet_deleted_cluster G ω A a haA.2 - dsimp only at hc - rw [heq] at hh hc - rw [← hc] at hh - exact hh hK a ha b hb - - -theorem capped_good_local (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (L : ℝ) (ω : Set E) : - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L) ↔ - ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ - (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M ∧ - GoodForScale G (ω ∩ (Q : Set E)) x L) := by - have hc := capped_cluster_local G hloc x M ω - have hb := cappedBadGoodness_local G hloc x M L ω - unfold CappedBadGoodness at hb - dsimp only at hc hb ⊢ - constructor - · rintro ⟨hf,hM,hg⟩ - obtain ⟨hf',hM'⟩ := hc.mp ⟨hf,hM⟩ - refine ⟨hf',hM',?_⟩ - by_contra hng - exact (hb.mpr ⟨hf',hM',hng⟩).2.2 hg - · rintro ⟨hf,hM,hg⟩ - obtain ⟨hf',hM'⟩ := hc.mpr ⟨hf,hM⟩ - refine ⟨hf',hM',?_⟩ - by_contra hng - exact (hb.mp ⟨hf',hM',hng⟩).2.2 hg - -theorem measurableSet_capped_good (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (M : ℕ) (L : ℝ) : - MeasurableSet {ω : Set E | (cluster G ω x).Finite ∧ - (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L} := by - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - have he : {ω : Set E | (cluster G ω x).Finite ∧ - (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L} = - {ω : Set E | (cluster G (ω ∩ (Q : Set E)) x).Finite ∧ - (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M ∧ GoodForScale G (ω ∩ (Q : Set E)) x L} := by - ext ω - exact capped_good_local G hloc x M L ω - rw [he] - exact measurableSet_finite_restriction Q {η : Set E | (cluster G η x).Finite ∧ - (cluster G η x).ncard ≤ M ∧ GoodForScale G η x L} - -end DeletionGoodness - -section SpliceSelection -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_maximal_splice_index (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) - (k j : ℕ) (hj : j ≤ k) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (S : Set V) (hyj : y j ∈ S) (hyk : y k ∉ S) : - ∃ i ∈ Finset.Icc (j+1) k, - ((cluster G (η i) (y i)) ∩ S).Nonempty ∧ y i ∉ S ∧ - ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) S := by - have hjk : j < k := by - by_contra h - have hEq : j = k := by omega - exact hyk (hEq ▸ hyj) - let T := (Finset.Icc (j+1) k).filter fun i => ((cluster G (η i) (y i)) ∩ S).Nonempty - have hT : T.Nonempty := by - refine ⟨j+1,Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨le_rfl,by omega⟩,?_⟩⟩ - refine ⟨y j,?_,hyj⟩ - simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (j+1) (Finset.mem_Icc.mpr ⟨by omega,by omega⟩) - let i := T.max' hT - have hi : i ∈ T := Finset.max'_mem T hT - obtain ⟨hiI,hiS⟩ := Finset.mem_filter.mp hi - have hiU := (Finset.mem_Icc.mp hiI).2 - have hiL := (Finset.mem_Icc.mp hiI).1 - have hl (l : ℕ) (hil : i < l) (hlk : l ≤ k) : Disjoint (cluster G (η l) (y l)) S := by - apply Set.disjoint_left.mpr - intro z hz hzS - have hlT : l ∈ T := Finset.mem_filter.mpr - ⟨Finset.mem_Icc.mpr ⟨by omega,hlk⟩,⟨z,hz,hzS⟩⟩ - have hli : l ≤ i := Finset.le_max' T l hlT - omega - refine ⟨i,hiI,hiS,?_,hl⟩ - intro hyi - by_cases hik : i = k - · exact hyk (hik ▸ hyi) - · have hic : y i ∈ cluster G (η (i+1)) (y (i+1)) := by - simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (i+1) (Finset.mem_Icc.mpr ⟨by omega,by omega⟩) - exact Set.disjoint_left.mp (hl (i+1) (by omega) (by omega)) hic hyi - - - -theorem exists_splice_contact (G : BondGraph V E) (η : Set E) (S : Set V) (y : V) - (hy : y ∉ S) (hmeet : (cluster G η y ∩ S).Nonempty) : - ∃ e a b, e ∈ η ∧ G e = s(a,b) ∧ a ∈ S ∧ - b ∈ cluster G (η ∩ internalEdges G Sᶜ) y := by - obtain ⟨v,hv,hvS⟩ := hmeet - obtain ⟨b,a,e,_,ha,he,hab,hb⟩ := conn_first_entry G S η hy hvS hv - exact ⟨e,a,b,he,hab.trans (Sym2.eq_swap),ha,hb⟩ - - -theorem splice_cluster_cap (G : BondGraph V E) (ω η : Set E) (x y : V) - (hy : y ∉ cluster G ω x) (e : E) (a b : V) - (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) - (N M : ℕ) (hS : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) - (hC : (cluster G η y).Finite) (hM : (cluster G η y).ncard ≤ M) : - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - (cluster G (spliceField G S B e ω η) x).Finite ∧ - (cluster G (spliceField G S B e ω η) x).ncard ≤ N+M := by - let S := cluster G ω x - let B := cluster G (η ∩ internalEdges G Sᶜ) y - have hBC : B ⊆ cluster G η y := fun _ hz => conn_mono G Set.inter_subset_left hz - have hB : B.Finite := hC.subset hBC - dsimp only - rw [splice_cluster G ω η x y hy e a b he heη ha hb] - refine ⟨hS.union hB,?_⟩ - exact (Set.ncard_union_le _ _).trans (Nat.add_le_add hN ((Set.ncard_le_ncard hBC hC).trans hM)) - - - -theorem cluster_eq_of_incident_agreement (G : BondGraph V E) (ω η : Set E) (x : V) - (he : ∀ e, (∃ v ∈ cluster G ω x, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : - cluster G η x = cluster G ω x := by - have hforward : cluster G ω x ⊆ cluster G η x := by - intro y hy - induction hy with - | refl => exact conn_refl G _ _ - | @tail a b hxa hab ih => - obtain ⟨e,heω,hab⟩ := hab - exact ih.tail ⟨e,(he e ⟨a,hxa,by simp [hab]⟩).mp heω,hab⟩ - apply Set.Subset.antisymm _ hforward - intro y hy - induction hy with - | refl => exact conn_refl G _ _ - | @tail a b _ hab ih => - obtain ⟨e,heη,hab⟩ := hab - exact ih.tail ⟨e,(he e ⟨a,ih,by simp [hab]⟩).mpr heη,hab⟩ - - - -theorem spliceMask_avoids_prefix (G : BondGraph V E) (S B R : Set V) (hRS : R ⊆ S) - (e : E) (a b : V) (hab : G e = s(a,b)) (ha : a ∉ R) (hb : b ∉ S) - {f : E} (hf : ∃ v ∈ R, v ∈ G f) : f ∉ spliceMask G S B e := by - rintro (rfl | ⟨_,hfo⟩) - · obtain ⟨v,hv,hvf⟩ := hf - rw [hab] at hvf - rcases Sym2.mem_iff.mp hvf with rfl | rfl - · exact ha hv - · exact hb (hRS hv) - · obtain ⟨v,hv,hvf⟩ := hf - exact hfo v hvf (hRS hv) - - - -theorem splice_preserves_prefix_cut (G : BondGraph V E) (ω η : Set E) (x : V) - (B : Set V) (e f : E) (a b : V) (hab : G e = s(a,b)) - (ha : a ∉ cluster G (ω \ {f}) x) (hb : b ∉ cluster G ω x) : - cluster G ((spliceField G (cluster G ω x) B e ω η) \ {f}) x = - cluster G (ω \ {f}) x := by - apply cluster_eq_of_incident_agreement - intro g hg - have hRS : cluster G (ω \ {f}) x ⊆ cluster G ω x := fun _ h => conn_mono G Set.sdiff_subset h - have hno := spliceMask_avoids_prefix G _ B _ hRS e a b hab ha hb hg - simp only [Set.mem_sdiff,spliceField,mem_exchangeOn,ite_eq_right hno] - -end SpliceSelection - -section SpliceTrace -attribute [local instance] Classical.propDecidable Classical.decEq - - - -inductive SpliceTrace (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k : ℕ) : - ℕ → Set E → List (ℕ × E) → Set E → Prop - | stop (j : ℕ) (ω : Set E) (hstop : y k ∈ cluster G ω x) : - SpliceTrace G x η y k j ω [] ω - | step (j i : ℕ) (ω : Set E) (e : E) (a b : V) (rest : List (ℕ × E)) (ωf : Set E) - (hnot : y k ∉ cluster G ω x) (hji : j < i) (hik : i ≤ k) - (hmax : ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) (cluster G ω x)) - (hy : y i ∉ cluster G ω x) (he : e ∈ η i) (hab : G e = s(a,b)) - (ha : a ∈ cluster G ω x) - (hb : b ∈ cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) - (htail : SpliceTrace G x η y k i - (spliceField G (cluster G ω x) - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) rest ωf) : - SpliceTrace G x η y k j ω ((i,e)::rest) ωf - - - -theorem exists_spliceTrace (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (k M : ℕ) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M) - (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) - (N : ℕ) (hfin : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) : - ∃ steps ωf, SpliceTrace G x η y k j ω steps ωf ∧ steps.length ≤ k-j ∧ - y k ∈ cluster G ωf x ∧ (cluster G ωf x).Finite ∧ - (cluster G ωf x).ncard ≤ N+(k-j)*M := by - generalize hn : k-j = n - induction n using Nat.strong_induction_on generalizing j ω N with - | h n ih => - by_cases hz : y k ∈ cluster G ω x - · refine ⟨[],ω,SpliceTrace.stop j ω hz,by simp,hz,hfin,?_⟩ - exact hN.trans (Nat.le_add_right ..) - · obtain ⟨i,hiI,hmeet,hyi,hmax⟩ := - exists_maximal_splice_index G η y k j hj hchain (cluster G ω x) hyj hz - obtain ⟨hji,hik⟩ := Finset.mem_Icc.mp hiI - obtain ⟨e,a,b,he,hab,ha,hb⟩ := exists_splice_contact G (η i) (cluster G ω x) (y i) hyi hmeet - let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) - let ω' := spliceField G (cluster G ω x) B e ω (η i) - have hi1 : i ∈ Finset.Icc 1 k := Finset.mem_Icc.mpr ⟨by omega,hik⟩ - have hcap := splice_cluster_cap G ω (η i) x (y i) hyi e a b hab he ha hb N M hfin hN - (hcaps i hi1).1 (hcaps i hi1).2 - have hyt : y i ∈ cluster G ω' x := by - change y i ∈ cluster G (spliceField G (cluster G ω x) B e ω (η i)) x - rw [splice_cluster G ω (η i) x (y i) hyi e a b hab he ha hb] - exact Or.inr (mem_cluster_self G _ _) - have hlt : k-i < n := by omega - obtain ⟨steps,ωf,htrace,hlen,hconn,hf,hs⟩ := - ih (k-i) hlt i hik ω' hyt (N+M) hcap.1 hcap.2 rfl - refine ⟨(i,e)::steps,ωf, - SpliceTrace.step j i ω e a b steps ωf hz (by omega) hik hmax hyi he hab ha hb htrace, - ?_,hconn,hf,?_⟩ - · simp only [List.length_cons] - omega - · have hm : (k-i+1)*M ≤ (k-j)*M := Nat.mul_le_mul_right M (by omega) - rw [Nat.add_mul,one_mul] at hm - calc - _ ≤ (N+M)+(k-i)*M := hs - _ ≤ N+(k-j)*M := by omega - _ = N+n*M := by rw [hn] - - -theorem SpliceTrace.cluster_subset (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : cluster G ω x ⊆ cluster G ωf x := by - induction h with - | stop => exact Set.Subset.rfl - | @step j i ω e a b rest ωf _ _ _ _ hy he hab ha hb ht ih => - apply Set.Subset.trans _ ih - rw [splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb] - exact Set.subset_union_left - - - -theorem SpliceTrace.preserve_cut (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) (f : E) - (havoid : ∀ l, j < l → l ≤ k → - Disjoint (cluster G (η l) (y l)) (cluster G (ω \ {f}) x)) : - cluster G (ωf \ {f}) x = cluster G (ω \ {f}) x := by - induction h with - | stop => rfl - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - have hBC : b ∈ cluster G (η i) (y i) := conn_mono G Set.inter_subset_left hb - have haC : a ∈ cluster G (η i) (y i) := (edge_cluster_sides G (η i) (y i) he hab).mpr hBC - have haR : a ∉ cluster G (ω \ {f}) x := fun hh => Set.disjoint_left.mp (havoid i hji hik) haC hh - have hbS : b ∉ cluster G ω x := slit_cluster_subset G _ (η i) (y i) hy hb - have heq := splice_preserves_prefix_cut G ω (η i) x - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e f a b hab haR hbS - rw [ih] - · exact heq - · intro l hil hlk - rw [heq] - exact havoid l (hji.trans hil) hlk - - -theorem SpliceTrace.endpoint (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : y k ∈ cluster G ωf x := by - induction h with - | stop _ _ hs => exact hs - | step => assumption - - - -theorem SpliceTrace.seams_pivotal (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : - ∀ q ∈ steps, OpenMarkedPivotal G ωf {y k} x q.2 := by - induction h with - | stop => simp - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - have hcut : cluster G (ω' \ {e}) x = S := - splice_close_seam_cluster G ω (η i) x (y i) hy e a b hab he ha hb - have hfinal : cluster G (ωf \ {e}) x = S := by - rw [SpliceTrace.preserve_cut G x η y k i ω' ωf rest ht e] - · exact hcut - · intro l hil hlk - rw [hcut] - exact hmax l hil hlk - have hconn := SpliceTrace.endpoint G x η y k i ω' ωf rest ht - have hno : ¬Conn G (ωf \ {e}) x (y k) := by - intro hc - have : y k ∈ cluster G (ωf \ {e}) x := hc - rw [hfinal] at this - exact hn this - have heω : e ∈ ωf := by - by_contra heω - have heq : ωf \ {e} = ωf := by - ext f - constructor - · exact fun hh => hh.1 - · intro hh - exact ⟨hh,fun hfe => heω ((Set.mem_singleton_iff.mp hfe) ▸ hh)⟩ - exact hno (heq.symm ▸ hconn) - exact ⟨heω,⟨y k,rfl,hconn⟩,by simpa only [MarkedEvent,Set.mem_singleton_iff,exists_eq_left] using hno⟩ - · exact ih q hq - -end SpliceTrace - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.Goodness +import OAI.Probability.UnimodularPercolation.Kernel.Spectral + +namespace OAI + +/-! Critical parameters and the geometry, selection and traces of splices. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} + +section CriticalParameter +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem twoPoint_adj_lower [Countable E] (G : BondGraph V E) (p : unitInterval) + (z x y : V) (hxy : Adj G x y) : (p:ℝ)*twoPoint G p z x ≤ twoPoint G p z y := by + obtain ⟨e,he⟩ := hxy + have h := association_finiteWitness p {ω : Set E | e ∈ ω} {ω | Conn G ω z x} + (fun _ _ hω h => hω h) (fun _ _ hω h => conn_mono G hω h) + (finiteWitness_edge e) (finiteWitness_conn G z x) + have hp : (law p).real {ω : Set E | e ∈ ω} = (p:ℝ) := by + simpa using finite_open_probability p {e} + rw [hp] at h + exact h.trans (measureReal_mono (fun ω hω => + conn_trans G ω hω.2 (Relation.ReflTransGen.single ⟨e,hω.1,he⟩))) + + +theorem walk_operator_apply (G : BondGraph V E) (hloc : LocallyFinite G) (a : ℝ) + (P : Hilbert V →L[ℂ] Hilbert V) + (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) + (f : Hilbert V) (x : V) : + P f x = ∑ y ∈ insert x (neighbors G hloc x), (walkKernel G hloc a x y : ℂ)*f y := by + have hz (y : V) (hy : y ∉ insert x (neighbors G hloc x)) : matrixCoeff P x y*f y = 0 := by + have hxy : x ≠ y := by intro h; subst y; exact hy (Finset.mem_insert_self _ _) + have hAdj : ¬Adj G x y := fun h => hy (Finset.mem_insert_of_mem ((mem_neighbors ..).mpr h)) + simp only [matrixCoeff,hP,walkKernel,ite_eq_right hxy,ite_eq_right hAdj,add_zero,Complex.ofReal_zero,zero_mul] + have hsum := (operator_kernel_hasSum P f x).unique (hasSum_sum_of_ne_finset_zero hz) + simpa only [matrixCoeff,hP] using hsum + + + +theorem parameter_le_walk_norm [Countable E] [Nonempty V] (G : BondGraph V E) + (hloc : LocallyFinite G) (D : ℕ) (hD : ∀ x, degree G x ≤ D) + (a : ℝ) (ha : 0 ≤ a) (haD : a*D ≤ 1) + (P : Hilbert V →L[ℂ] Hilbert V) + (hP : ∀ x y, P (lp.single 2 y (1:ℂ)) x = (walkKernel G hloc a x y : ℂ)) + (p : unitInterval) (hp : OperatorBounded G p) : (p:ℝ) ≤ ‖P‖ := by + obtain ⟨T,hT⟩ := hp + let z := Classical.arbitrary V + let f := T (lp.single 2 z (1:ℂ)) + have hf (x : V) : f x = (twoPoint G p x z : ℂ) := hT x z + have hf0 : 0 < ‖f‖ := by + apply norm_pos_iff.mpr + intro h + have hval := congrArg (fun g : Hilbert V => g z) h + simp [hf] at hval + have hrow (x : V) : (p:ℝ)*twoPoint G p x z ≤ + ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y*twoPoint G p y z := by + calc + _ = ∑ y ∈ insert x (neighbors G hloc x), walkKernel G hloc a x y*((p:ℝ)*twoPoint G p x z) := by + rw [← Finset.sum_mul,walkKernel_row_sum,one_mul] + _ ≤ _ := by + apply Finset.sum_le_sum + intro y hy + apply mul_le_mul_of_nonneg_left _ (walkKernel_nonneg G hloc D hD a ha haD x y) + rcases Finset.mem_insert.mp hy with rfl | hy + · exact mul_le_of_le_one_left (twoPoint_nonneg G p y z) p.2.2 + · simpa only [twoPoint_symm G p] using twoPoint_adj_lower G p z x y ((mem_neighbors ..).mp hy) + have hpoint (x : V) : ‖((p:ℂ) • f) x‖ ≤ ‖P f x‖ := by + rw [lp.coeFn_smul,Pi.smul_apply,smul_eq_mul,hf,← Complex.ofReal_mul, + Complex.norm_of_nonneg (mul_nonneg p.2.1 (twoPoint_nonneg G p x z)), + walk_operator_apply G hloc a P hP] + simp only [hf,← Complex.ofReal_mul,← Complex.ofReal_sum] + rw [Complex.norm_of_nonneg (le_trans (mul_nonneg p.2.1 (twoPoint_nonneg G p x z)) (hrow x))] + exact hrow x + have hn := (lp.norm_mono (by norm_num : (2:ℝ≥0∞) ≠ 0) hpoint).trans (P.le_opNorm f) + rw [norm_smul,Complex.norm_of_nonneg p.2.1] at hn + exact (mul_le_mul_iff_left₀ hf0).mp hn + + +theorem pc_lt_one_of_nonamenable [Nonempty V] (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) (hqt : QuasiTransitive G) + (hh : 0 < hV G) : pc G < 1 := by + let : Countable V := countable_vertices hloc hconn + let : Countable E := countable_edges hloc + obtain ⟨D,P,hD0,hD,hPn,_,hP⟩ := exists_strict_walk_operator G hloc hqt hh + have hDr : 0 < (D:ℝ) := by exact_mod_cast hD0 + let p : unitInterval := ⟨(‖P‖+1)/2,by constructor <;> linarith [norm_nonneg P]⟩ + have hp1 : p < 1 := by change (‖P‖+1)/2 < 1; linarith + have ha : 0 ≤ (1:ℝ)/(2*D) := by positivity + have haD : (1:ℝ)/(2*D)*D ≤ 1 := by + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity)).mpr + linarith + apply lt_of_le_of_ne (show pc G ≤ 1 from (pc G).2.2) + intro he + have hb := operatorBounded_of_lt_pc G hloc hqt p (he ▸ hp1) + have hle := parameter_le_walk_norm G hloc D hD _ ha haD P hP p hb + change (‖P‖+1)/2 ≤ ‖P‖ at hle + linarith + +end CriticalParameter + +section SpliceGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def exchangeOn (mask ω η : Set E) : Set E := (ω \ mask) ∪ (η ∩ mask) + +@[simp] theorem mem_exchangeOn {mask ω η : Set E} {e : E} : + e ∈ exchangeOn mask ω η ↔ if e ∈ mask then e ∈ η else e ∈ ω := by + by_cases h : e ∈ mask <;> simp [exchangeOn,h] + +theorem exchangeOn_involutive (mask ω η : Set E) : + exchangeOn mask (exchangeOn mask ω η) (exchangeOn mask η ω) = ω := by + ext e + by_cases h : e ∈ mask <;> simp [h] + + + +def spliceMask (G : BondGraph V E) (S B : Set V) (e : E) : Set E := + insert e {f | (∃ b ∈ B, b ∈ G f) ∧ f ∈ internalEdges G Sᶜ} + +def spliceField (G : BondGraph V E) (S B : Set V) (e : E) (ω η : Set E) : Set E := + exchangeOn (spliceMask G S B e) ω η + +theorem slit_cluster_subset (G : BondGraph V E) (S : Set V) (η : Set E) + (y : V) (hy : y ∉ S) : cluster G (η ∩ internalEdges G Sᶜ) y ⊆ Sᶜ := by + exact fun z hz => conn_internal_endpoint G Sᶜ hy hz + +theorem spliceMask_not_internal (G : BondGraph V E) (S B : Set V) (e : E) + (a b : V) (he : G e = s(a,b)) (hb : b ∉ S) {f : E} + (hf : f ∈ internalEdges G S) : f ∉ spliceMask G S B e := by + rintro (rfl | ⟨_,hout⟩) + · exact hb (((mem_internalEdges_of_ends G S f a b he).mp hf).2) + · exact (hout _ (Sym2.out_fst_mem _)) (hf _ (Sym2.out_fst_mem _)) + +theorem spliceMask_of_internal_piece (G : BondGraph V E) (S B : Set V) (e : E) + (hB : B ⊆ Sᶜ) {f : E} (hf : f ∈ internalEdges G B) : f ∈ spliceMask G S B e := by + right + exact ⟨⟨(G f).out.1,hf _ (Sym2.out_fst_mem _),Sym2.out_fst_mem _⟩, + fun v hv => hB (hf v hv)⟩ + + +theorem splice_internal_fields (G : BondGraph V E) (S B : Set V) (e : E) + (ω η : Set E) (a b : V) (he : G e = s(a,b)) (hb : b ∉ S) (hB : B ⊆ Sᶜ) : + spliceField G S B e ω η ∩ internalEdges G S = ω ∩ internalEdges G S ∧ + spliceField G S B e ω η ∩ internalEdges G B = η ∩ internalEdges G B := by + constructor + · ext f + by_cases hf : f ∈ internalEdges G S + · simp only [Set.mem_inter_iff,hf,and_true,spliceField,mem_exchangeOn, + ite_eq_right (spliceMask_not_internal G S B e a b he hb hf)] + · simp only [Set.mem_inter_iff,hf,and_false] + · ext f + by_cases hf : f ∈ internalEdges G B + · simp only [Set.mem_inter_iff,hf,and_true,spliceField,mem_exchangeOn, + ite_eq_left (spliceMask_of_internal_piece G S B e hB hf)] + · simp only [Set.mem_inter_iff,hf,and_false] + + +theorem splice_crossing_unique (G : BondGraph V E) (ω η : Set E) (x : V) + (B : Set V) (e : E) {f : E} {a b : V} + (hf : f ∈ spliceField G (cluster G ω x) B e ω η) + (hab : G f = s(a,b)) (ha : a ∈ cluster G ω x) (hb : b ∉ cluster G ω x) : f = e := by + have hno : f ∉ ω := fun h => hb ((edge_cluster_sides G ω x h hab).mp ha) + have hm : f ∈ spliceMask G (cluster G ω x) B e := by + by_contra h + have hh := hf + simp only [spliceField,mem_exchangeOn,ite_eq_right h] at hh + exact hno hh + rcases hm with rfl | ⟨_,hout⟩ + · rfl + · exact ((((mem_internalEdges_of_ends G _ f a b hab).mp hout).1) ha).elim + + + +theorem splice_cluster (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + cluster G (spliceField G S B e ω η) x = S ∪ B := by + let S := cluster G ω x + let ζ := η ∩ internalEdges G Sᶜ + let B := cluster G ζ y + let ω' := spliceField G S B e ω η + change cluster G ω' x = S ∪ B + have hB : B ⊆ Sᶜ := slit_cluster_subset G S η y hy + have hbS : b ∉ S := hB hb + have hfields := splice_internal_fields G S B e ω η a b he hbS hB + have he' : e ∈ ω' := by + change e ∈ exchangeOn (spliceMask G S B e) ω η + rw [mem_exchangeOn,ite_eq_left (show e ∈ spliceMask G S B e from Set.mem_insert _ _)] + exact heη + have hSconn (z : V) (hz : z ∈ S) : Conn G ω' x z := by + have h := conn_restrict_cluster G ω x (mem_cluster_self G ω x) hz + apply conn_mono G _ h + intro f hf + exact (hfields.1.symm ▸ hf).1 + have hBconn (u v : V) (hu : u ∈ B) (hv : v ∈ B) : Conn G ω' u v := by + have h := conn_restrict_cluster G ζ y hu (conn_trans G ζ (conn_symm G ζ hu) hv) + apply conn_mono G _ h + intro f hf + exact (hfields.2.symm ▸ (show f ∈ η ∩ internalEdges G B from ⟨hf.1.1,hf.2⟩)).1 + apply Set.Subset.antisymm + · intro z hz + induction hz with + | refl => exact Or.inl (mem_cluster_self G ω x) + | @tail u v hxu huv ih => + obtain ⟨f,hf,hfv⟩ := huv + by_cases hvS : v ∈ S + · exact Or.inl hvS + · rcases ih with huS | huB + · have hfe := splice_crossing_unique G ω η x B e hf hfv huS hvS + subst f + have hends := Sym2.eq_iff.mp (he.symm.trans hfv) + rcases hends with ⟨hau,hbv⟩ | ⟨hav,hbu⟩ + · exact Or.inr (hbv ▸ hb) + · exact (hvS (hav ▸ ha)).elim + · have huS : u ∉ S := hB huB + have hm : f ∈ spliceMask G S B e := by + right + exact ⟨⟨u,huB,by simp [hfv]⟩,(mem_internalEdges_of_ends G _ f u v hfv).mpr ⟨huS,hvS⟩⟩ + have hfη : f ∈ η := by + change f ∈ exchangeOn (spliceMask G S B e) ω η at hf + rwa [mem_exchangeOn,ite_eq_left hm] at hf + exact Or.inr ((edge_cluster_sides G ζ y + ⟨hfη,(mem_internalEdges_of_ends G _ f u v hfv).mpr ⟨huS,hvS⟩⟩ hfv).mp huB) + · intro z hz + rcases hz with hz | hz + · exact hSconn z hz + · exact ((hSconn a ha).tail ⟨e,he',he⟩).trans (hBconn b z hb hz) + + +theorem splice_seam_pivotal (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) + (z : V) (hz : z ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + OpenMarkedPivotal G (spliceField G S B e ω η) {z} x e := by + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + let ω' := spliceField G S B e ω η + have hB := slit_cluster_subset G S η y hy + have hC := splice_cluster G ω η x y hy e a b he heη ha hb + change cluster G ω' x = S ∪ B at hC + refine ⟨?_,⟨z,Set.mem_singleton z,by change z ∈ cluster G ω' x; rw [hC]; exact Or.inr hz⟩,?_⟩ + · change e ∈ exchangeOn (spliceMask G S B e) ω η + rw [mem_exchangeOn,ite_eq_left (show e ∈ spliceMask G S B e from Set.mem_insert _ _)] + exact heη + · rintro ⟨v,hv,hxv⟩ + have hvz : v = z := Set.mem_singleton_iff.mp hv + subst v + have hsub : cluster G (ω' \ {e}) x ⊆ S := by + intro v hxv + induction hxv with + | refl => exact mem_cluster_self G ω x + | @tail u v hxu huv ih => + obtain ⟨f,hf,hfv⟩ := huv + by_contra hvS + have hfe := splice_crossing_unique G ω η x B e hf.1 hfv ih hvS + exact hf.2 (by simpa only [Set.mem_singleton_iff] using hfe) + exact hB hz (hsub hxv) + +end SpliceGeometry + +section SpliceInverse +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem splice_close_seam_cluster (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (_heη : e ∈ η) (_ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + cluster G (spliceField G S B e ω η \ {e}) x = S := by + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + let ω' := spliceField G S B e ω η + have hB := slit_cluster_subset G S η y hy + have hf := (splice_internal_fields G S B e ω η a b he (hB hb) hB).1 + apply Set.Subset.antisymm + · intro v hxv + induction hxv with + | refl => exact mem_cluster_self G ω x + | @tail u v _ huv ih => + obtain ⟨f,hf,hfv⟩ := huv + by_contra hvS + have hfe := splice_crossing_unique G ω η x B e hf.1 hfv ih hvS + exact hf.2 (Set.mem_singleton_iff.mpr hfe) + · intro z hz + have hc := conn_restrict_cluster G ω x (mem_cluster_self G ω x) hz + apply conn_mono G _ hc + intro f hfin + refine ⟨(hf.symm ▸ hfin).1,?_⟩ + intro hfe + have hfe' := Set.mem_singleton_iff.mp hfe + subst f + exact hB hb (((mem_internalEdges_of_ends G S e a b he).mp hfin.2).2) + + +theorem splice_recover_piece (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + let ω' := spliceField G S B e ω η + cluster G ω' x \ cluster G (ω' \ {e}) x = B := by + dsimp only + rw [splice_cluster G ω η x y hy e a b he heη ha hb, + splice_close_seam_cluster G ω η x y hy e a b he heη ha hb] + have hB := slit_cluster_subset G (cluster G ω x) η y hy + ext z + constructor + · rintro ⟨hz,hzS⟩ + exact hz.resolve_left hzS + · intro hz + exact ⟨Or.inr hz,hB hz⟩ + + +def recoveredMask (G : BondGraph V E) (ω' : Set E) (x : V) (e : E) : Set E := + spliceMask G (cluster G (ω' \ {e}) x) + (cluster G ω' x \ cluster G (ω' \ {e}) x) e + +theorem recoveredMask_splice (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + recoveredMask G (spliceField G S B e ω η) x e = spliceMask G S B e := by + unfold recoveredMask + dsimp only + rw [splice_recover_piece G ω η x y hy e a b he heη ha hb, + splice_close_seam_cluster G ω η x y hy e a b he heη ha hb] + + +def undoSplice (G : BondGraph V E) (x : V) (e : E) (ω' η' : Set E) : Set E × Set E := + let M := recoveredMask G ω' x e + (exchangeOn M ω' η',exchangeOn M η' ω') + + +theorem undoSplice_of_valid (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + let M := spliceMask G S B e + undoSplice G x e (exchangeOn M ω η) (exchangeOn M η ω) = (ω,η) := by + dsimp only [undoSplice] + rw [show recoveredMask G (exchangeOn + (spliceMask G (cluster G ω x) (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e) ω η) x e = + spliceMask G (cluster G ω x) (cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) e from + recoveredMask_splice G ω η x y hy e a b he heη ha hb] + rw [exchangeOn_involutive,exchangeOn_involutive] + + +theorem spliceMask_finite (G : BondGraph V E) (hloc : LocallyFinite G) + (S B : Set V) (hB : B.Finite) (e : E) : (spliceMask G S B e).Finite := by + apply Set.Finite.insert + apply (hB.biUnion (fun b _ => hloc b)).subset + rintro f ⟨⟨b,hb,hbf⟩,_⟩ + exact Set.mem_iUnion₂.mpr ⟨b,hb,hbf⟩ + +end SpliceInverse + +section FiniteExchange +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteExchange (M ω η : Finset E) : Finset E := (ω \ M) ∪ (η ∩ M) + +@[simp] theorem coe_finiteExchange (M ω η : Finset E) : + (finiteExchange M ω η : Set E) = exchangeOn (M:Set E) (ω:Set E) (η:Set E) := by + simp only [finiteExchange,exchangeOn,Finset.coe_union,Finset.coe_sdiff,Finset.coe_inter] + +theorem finiteExchange_card (M ω η : Finset E) : + (finiteExchange M ω η).card = (ω \ M).card+(η ∩ M).card := by + apply Finset.card_union_of_disjoint + exact Finset.disjoint_left.mpr fun e he he' => (Finset.mem_sdiff.mp he).2 (Finset.mem_inter.mp he').2 + +theorem finiteExchange_card_sum (M ω η : Finset E) : + (finiteExchange M ω η).card+(finiteExchange M η ω).card = ω.card+η.card := by + rw [finiteExchange_card,finiteExchange_card] + have hω := Finset.card_sdiff_add_card_inter ω M + have hη := Finset.card_sdiff_add_card_inter η M + omega + +theorem finiteExchange_subset (M Q ω η : Finset E) (hω : ω ⊆ Q) (hη : η ⊆ Q) : + finiteExchange M ω η ⊆ Q := by + intro e he + rcases Finset.mem_union.mp he with he | he + · exact hω (Finset.mem_sdiff.mp he).1 + · exact hη (Finset.mem_inter.mp he).1 + + +theorem bernoulliWeight_exchange (M Q ω η : Finset E) (hω : ω ⊆ Q) (hη : η ⊆ Q) + (p : ℝ) : + bernoulliWeight Q (finiteExchange M ω η) p * bernoulliWeight Q (finiteExchange M η ω) p = + bernoulliWeight Q ω p * bernoulliWeight Q η p := by + have hc := finiteExchange_card_sum M ω η + have hcω := Finset.card_le_card hω + have hcη := Finset.card_le_card hη + have hcω' := Finset.card_le_card (finiteExchange_subset M Q ω η hω hη) + have hcη' := Finset.card_le_card (finiteExchange_subset M Q η ω hη hω) + have hd : (Q.card-(finiteExchange M ω η).card)+(Q.card-(finiteExchange M η ω).card) = + (Q.card-ω.card)+(Q.card-η.card) := by omega + unfold bernoulliWeight + calc + _ = p^((finiteExchange M ω η).card+(finiteExchange M η ω).card) * + (1-p)^((Q.card-(finiteExchange M ω η).card)+(Q.card-(finiteExchange M η ω).card)) := by + rw [pow_add,pow_add]; ring + _ = p^(ω.card+η.card)*(1-p)^((Q.card-ω.card)+(Q.card-η.card)) := by rw [hc,hd] + _ = _ := by rw [pow_add,pow_add]; ring + +end FiniteExchange + +section DeletionGoodness +attribute [local instance] Classical.propDecidable Classical.decEq + + +def deletionContacts (G : BondGraph V E) (ω : Set E) (A B : Set V) : Set E := + {e | e ∈ ω ∧ ∃ a ∈ B, ∃ b ∈ A, G e = s(a,b)} + + + +def DeletionGoodForScale (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) : Prop := + ∀ A ⊆ cluster G ω x, ∀ y ∈ cluster G ω x \ A, + let B := cluster G (ω ∩ internalEdges G Aᶜ) y + 0 < (deletionContacts G ω A B).ncard → + ∀ a ∈ B, ∀ b ∈ B, + (pivotalDistance G (ω ∩ internalEdges G B) a b : ℝ) ≤ + (deletionContacts G ω A B).ncard*L + +theorem deleted_cluster_subset (G : BondGraph V E) (ω : Set E) (x y : V) + (A : Set V) (hy : y ∈ cluster G ω x \ A) : + cluster G (ω ∩ internalEdges G Aᶜ) y ⊆ cluster G ω x \ A := by + intro z hz + exact ⟨conn_trans G ω hy.1 (conn_mono G Set.inter_subset_left hz), + conn_internal_endpoint G Aᶜ hy.2 hz⟩ + +theorem contactSet_deleted_cluster (G : BondGraph V E) (ω : Set E) (A : Set V) + (y : V) (hy : y ∉ A) : + let B := cluster G (ω ∩ internalEdges G Aᶜ) y + contactSet G ω B = deletionContacts G ω A B := by + let ζ := ω ∩ internalEdges G Aᶜ + let B := cluster G ζ y + have hB : B ⊆ Aᶜ := slit_cluster_subset G A ω y hy + ext e + constructor + · rintro ⟨he,a,b,hab,ha,hb⟩ + refine ⟨he,a,ha,b,?_,hab⟩ + by_contra hbA + have heζ : e ∈ ζ := ⟨he,(mem_internalEdges_of_ends G Aᶜ e a b hab).mpr ⟨hB ha,hbA⟩⟩ + exact hb ((edge_cluster_sides G ζ y heζ hab).mp ha) + · rintro ⟨he,a,ha,b,hb,hab⟩ + exact ⟨he,a,b,hab,ha,fun hh => hB hh hb⟩ + + + +theorem goodForScale_iff_deletion (G : BondGraph V E) (ω : Set E) (x : V) (L : ℝ) + (hC : (cluster G ω x).Finite) : + GoodForScale G ω x L ↔ DeletionGoodForScale G ω x L := by + constructor + · intro h A _ y hy + let ζ := ω ∩ internalEdges G Aᶜ + let B := cluster G ζ y + have hBC := deleted_cluster_subset G ω x y A hy + have hfin : B.Finite := hC.subset (fun _ hz => (hBC hz).1) + let W := hfin.toFinset + have hW : (W : Set V) = B := hfin.coe_toFinset + have hsub : (W : Set V) ⊆ cluster G ω x := by rw [hW]; exact fun _ hz => (hBC hz).1 + have hi (a : V) (ha : a ∈ W) (b : V) (hb : b ∈ W) : + Conn G (ω ∩ internalEdges G (W : Set V)) a b := by + have ha' : a ∈ B := hW ▸ ha + have hb' : b ∈ B := hW ▸ hb + have hc := conn_restrict_cluster G ζ y ha' (conn_trans G ζ (conn_symm G ζ ha') hb') + rw [hW] + apply conn_mono G ?_ hc + intro e he + exact ⟨he.1.1,he.2⟩ + have hh := h W hsub hi + rw [hW,contactSet_deleted_cluster G ω A y hy.2] at hh + dsimp only + intro hK a ha b hb + exact hh hK a (by change a ∈ (W : Set V); rw [hW]; exact ha) b + (by change b ∈ (W : Set V); rw [hW]; exact hb) + · intro h W hW hconn hK a ha b hb + let C := cluster G ω x + let A := C \ (W : Set V) + have haA : a ∈ C \ A := ⟨hW ha,fun hh => hh.2 ha⟩ + have hWA : (W : Set V) ⊆ Aᶜ := fun _ hz hh => hh.2 hz + have heq : cluster G (ω ∩ internalEdges G Aᶜ) a = (W : Set V) := by + apply Set.Subset.antisymm + · intro z hz + have hzC := deleted_cluster_subset G ω x a A haA hz + by_contra hzW + exact hzC.2 ⟨hzC.1,hzW⟩ + · intro z hz + apply conn_mono G ?_ (hconn a ha z hz) + intro e he + exact ⟨he.1,fun v hv => hWA (he.2 v hv)⟩ + have hh := h A Set.sdiff_subset a haA + dsimp only at hh + have hc := contactSet_deleted_cluster G ω A a haA.2 + dsimp only at hc + rw [heq] at hh hc + rw [← hc] at hh + exact hh hK a ha b hb + + +theorem capped_good_local (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (L : ℝ) (ω : Set E) : + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + ((cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L) ↔ + ((cluster G (ω ∩ (Q : Set E)) x).Finite ∧ + (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M ∧ + GoodForScale G (ω ∩ (Q : Set E)) x L) := by + have hc := capped_cluster_local G hloc x M ω + have hb := cappedBadGoodness_local G hloc x M L ω + unfold CappedBadGoodness at hb + dsimp only at hc hb ⊢ + constructor + · rintro ⟨hf,hM,hg⟩ + obtain ⟨hf',hM'⟩ := hc.mp ⟨hf,hM⟩ + refine ⟨hf',hM',?_⟩ + by_contra hng + exact (hb.mpr ⟨hf',hM',hng⟩).2.2 hg + · rintro ⟨hf,hM,hg⟩ + obtain ⟨hf',hM'⟩ := hc.mpr ⟨hf,hM⟩ + refine ⟨hf',hM',?_⟩ + by_contra hng + exact (hb.mp ⟨hf',hM',hng⟩).2.2 hg + +theorem measurableSet_capped_good (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (M : ℕ) (L : ℝ) : + MeasurableSet {ω : Set E | (cluster G ω x).Finite ∧ + (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L} := by + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + have he : {ω : Set E | (cluster G ω x).Finite ∧ + (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L} = + {ω : Set E | (cluster G (ω ∩ (Q : Set E)) x).Finite ∧ + (cluster G (ω ∩ (Q : Set E)) x).ncard ≤ M ∧ GoodForScale G (ω ∩ (Q : Set E)) x L} := by + ext ω + exact capped_good_local G hloc x M L ω + rw [he] + exact measurableSet_finite_restriction Q {η : Set E | (cluster G η x).Finite ∧ + (cluster G η x).ncard ≤ M ∧ GoodForScale G η x L} + +end DeletionGoodness + +section SpliceSelection +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_maximal_splice_index (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) + (k j : ℕ) (hj : j ≤ k) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (S : Set V) (hyj : y j ∈ S) (hyk : y k ∉ S) : + ∃ i ∈ Finset.Icc (j+1) k, + ((cluster G (η i) (y i)) ∩ S).Nonempty ∧ y i ∉ S ∧ + ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) S := by + have hjk : j < k := by + by_contra h + have hEq : j = k := by omega + exact hyk (hEq ▸ hyj) + let T := (Finset.Icc (j+1) k).filter fun i => ((cluster G (η i) (y i)) ∩ S).Nonempty + have hT : T.Nonempty := by + refine ⟨j+1,Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨le_rfl,by omega⟩,?_⟩⟩ + refine ⟨y j,?_,hyj⟩ + simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (j+1) (Finset.mem_Icc.mpr ⟨by omega,by omega⟩) + let i := T.max' hT + have hi : i ∈ T := Finset.max'_mem T hT + obtain ⟨hiI,hiS⟩ := Finset.mem_filter.mp hi + have hiU := (Finset.mem_Icc.mp hiI).2 + have hiL := (Finset.mem_Icc.mp hiI).1 + have hl (l : ℕ) (hil : i < l) (hlk : l ≤ k) : Disjoint (cluster G (η l) (y l)) S := by + apply Set.disjoint_left.mpr + intro z hz hzS + have hlT : l ∈ T := Finset.mem_filter.mpr + ⟨Finset.mem_Icc.mpr ⟨by omega,hlk⟩,⟨z,hz,hzS⟩⟩ + have hli : l ≤ i := Finset.le_max' T l hlT + omega + refine ⟨i,hiI,hiS,?_,hl⟩ + intro hyi + by_cases hik : i = k + · exact hyk (hik ▸ hyi) + · have hic : y i ∈ cluster G (η (i+1)) (y (i+1)) := by + simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (i+1) (Finset.mem_Icc.mpr ⟨by omega,by omega⟩) + exact Set.disjoint_left.mp (hl (i+1) (by omega) (by omega)) hic hyi + + + +theorem exists_splice_contact (G : BondGraph V E) (η : Set E) (S : Set V) (y : V) + (hy : y ∉ S) (hmeet : (cluster G η y ∩ S).Nonempty) : + ∃ e a b, e ∈ η ∧ G e = s(a,b) ∧ a ∈ S ∧ + b ∈ cluster G (η ∩ internalEdges G Sᶜ) y := by + obtain ⟨v,hv,hvS⟩ := hmeet + obtain ⟨b,a,e,_,ha,he,hab,hb⟩ := conn_first_entry G S η hy hvS hv + exact ⟨e,a,b,he,hab.trans (Sym2.eq_swap),ha,hb⟩ + + +theorem splice_cluster_cap (G : BondGraph V E) (ω η : Set E) (x y : V) + (hy : y ∉ cluster G ω x) (e : E) (a b : V) + (he : G e = s(a,b)) (heη : e ∈ η) (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η ∩ internalEdges G (cluster G ω x)ᶜ) y) + (N M : ℕ) (hS : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) + (hC : (cluster G η y).Finite) (hM : (cluster G η y).ncard ≤ M) : + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + (cluster G (spliceField G S B e ω η) x).Finite ∧ + (cluster G (spliceField G S B e ω η) x).ncard ≤ N+M := by + let S := cluster G ω x + let B := cluster G (η ∩ internalEdges G Sᶜ) y + have hBC : B ⊆ cluster G η y := fun _ hz => conn_mono G Set.inter_subset_left hz + have hB : B.Finite := hC.subset hBC + dsimp only + rw [splice_cluster G ω η x y hy e a b he heη ha hb] + refine ⟨hS.union hB,?_⟩ + exact (Set.ncard_union_le _ _).trans (Nat.add_le_add hN ((Set.ncard_le_ncard hBC hC).trans hM)) + + + +theorem cluster_eq_of_incident_agreement (G : BondGraph V E) (ω η : Set E) (x : V) + (he : ∀ e, (∃ v ∈ cluster G ω x, v ∈ G e) → (e ∈ ω ↔ e ∈ η)) : + cluster G η x = cluster G ω x := by + have hforward : cluster G ω x ⊆ cluster G η x := by + intro y hy + induction hy with + | refl => exact conn_refl G _ _ + | @tail a b hxa hab ih => + obtain ⟨e,heω,hab⟩ := hab + exact ih.tail ⟨e,(he e ⟨a,hxa,by simp [hab]⟩).mp heω,hab⟩ + apply Set.Subset.antisymm _ hforward + intro y hy + induction hy with + | refl => exact conn_refl G _ _ + | @tail a b _ hab ih => + obtain ⟨e,heη,hab⟩ := hab + exact ih.tail ⟨e,(he e ⟨a,ih,by simp [hab]⟩).mpr heη,hab⟩ + + + +theorem spliceMask_avoids_prefix (G : BondGraph V E) (S B R : Set V) (hRS : R ⊆ S) + (e : E) (a b : V) (hab : G e = s(a,b)) (ha : a ∉ R) (hb : b ∉ S) + {f : E} (hf : ∃ v ∈ R, v ∈ G f) : f ∉ spliceMask G S B e := by + rintro (rfl | ⟨_,hfo⟩) + · obtain ⟨v,hv,hvf⟩ := hf + rw [hab] at hvf + rcases Sym2.mem_iff.mp hvf with rfl | rfl + · exact ha hv + · exact hb (hRS hv) + · obtain ⟨v,hv,hvf⟩ := hf + exact hfo v hvf (hRS hv) + + + +theorem splice_preserves_prefix_cut (G : BondGraph V E) (ω η : Set E) (x : V) + (B : Set V) (e f : E) (a b : V) (hab : G e = s(a,b)) + (ha : a ∉ cluster G (ω \ {f}) x) (hb : b ∉ cluster G ω x) : + cluster G ((spliceField G (cluster G ω x) B e ω η) \ {f}) x = + cluster G (ω \ {f}) x := by + apply cluster_eq_of_incident_agreement + intro g hg + have hRS : cluster G (ω \ {f}) x ⊆ cluster G ω x := fun _ h => conn_mono G Set.sdiff_subset h + have hno := spliceMask_avoids_prefix G _ B _ hRS e a b hab ha hb hg + simp only [Set.mem_sdiff,spliceField,mem_exchangeOn,ite_eq_right hno] + +end SpliceSelection + +section SpliceTrace +attribute [local instance] Classical.propDecidable Classical.decEq + + + +inductive SpliceTrace (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) (k : ℕ) : + ℕ → Set E → List (ℕ × E) → Set E → Prop + | stop (j : ℕ) (ω : Set E) (hstop : y k ∈ cluster G ω x) : + SpliceTrace G x η y k j ω [] ω + | step (j i : ℕ) (ω : Set E) (e : E) (a b : V) (rest : List (ℕ × E)) (ωf : Set E) + (hnot : y k ∉ cluster G ω x) (hji : j < i) (hik : i ≤ k) + (hmax : ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) (cluster G ω x)) + (hy : y i ∉ cluster G ω x) (he : e ∈ η i) (hab : G e = s(a,b)) + (ha : a ∈ cluster G ω x) + (hb : b ∈ cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) + (htail : SpliceTrace G x η y k i + (spliceField G (cluster G ω x) + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) rest ωf) : + SpliceTrace G x η y k j ω ((i,e)::rest) ωf + + + +theorem exists_spliceTrace (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (k M : ℕ) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M) + (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) + (N : ℕ) (hfin : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) : + ∃ steps ωf, SpliceTrace G x η y k j ω steps ωf ∧ steps.length ≤ k-j ∧ + y k ∈ cluster G ωf x ∧ (cluster G ωf x).Finite ∧ + (cluster G ωf x).ncard ≤ N+(k-j)*M := by + generalize hn : k-j = n + induction n using Nat.strong_induction_on generalizing j ω N with + | h n ih => + by_cases hz : y k ∈ cluster G ω x + · refine ⟨[],ω,SpliceTrace.stop j ω hz,by simp,hz,hfin,?_⟩ + exact hN.trans (Nat.le_add_right ..) + · obtain ⟨i,hiI,hmeet,hyi,hmax⟩ := + exists_maximal_splice_index G η y k j hj hchain (cluster G ω x) hyj hz + obtain ⟨hji,hik⟩ := Finset.mem_Icc.mp hiI + obtain ⟨e,a,b,he,hab,ha,hb⟩ := exists_splice_contact G (η i) (cluster G ω x) (y i) hyi hmeet + let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) + let ω' := spliceField G (cluster G ω x) B e ω (η i) + have hi1 : i ∈ Finset.Icc 1 k := Finset.mem_Icc.mpr ⟨by omega,hik⟩ + have hcap := splice_cluster_cap G ω (η i) x (y i) hyi e a b hab he ha hb N M hfin hN + (hcaps i hi1).1 (hcaps i hi1).2 + have hyt : y i ∈ cluster G ω' x := by + change y i ∈ cluster G (spliceField G (cluster G ω x) B e ω (η i)) x + rw [splice_cluster G ω (η i) x (y i) hyi e a b hab he ha hb] + exact Or.inr (mem_cluster_self G _ _) + have hlt : k-i < n := by omega + obtain ⟨steps,ωf,htrace,hlen,hconn,hf,hs⟩ := + ih (k-i) hlt i hik ω' hyt (N+M) hcap.1 hcap.2 rfl + refine ⟨(i,e)::steps,ωf, + SpliceTrace.step j i ω e a b steps ωf hz (by omega) hik hmax hyi he hab ha hb htrace, + ?_,hconn,hf,?_⟩ + · simp only [List.length_cons] + omega + · have hm : (k-i+1)*M ≤ (k-j)*M := Nat.mul_le_mul_right M (by omega) + rw [Nat.add_mul,one_mul] at hm + calc + _ ≤ (N+M)+(k-i)*M := hs + _ ≤ N+(k-j)*M := by omega + _ = N+n*M := by rw [hn] + + +theorem SpliceTrace.cluster_subset (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : cluster G ω x ⊆ cluster G ωf x := by + induction h with + | stop => exact Set.Subset.rfl + | @step j i ω e a b rest ωf _ _ _ _ hy he hab ha hb ht ih => + apply Set.Subset.trans _ ih + rw [splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb] + exact Set.subset_union_left + + + +theorem SpliceTrace.preserve_cut (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) (f : E) + (havoid : ∀ l, j < l → l ≤ k → + Disjoint (cluster G (η l) (y l)) (cluster G (ω \ {f}) x)) : + cluster G (ωf \ {f}) x = cluster G (ω \ {f}) x := by + induction h with + | stop => rfl + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + have hBC : b ∈ cluster G (η i) (y i) := conn_mono G Set.inter_subset_left hb + have haC : a ∈ cluster G (η i) (y i) := (edge_cluster_sides G (η i) (y i) he hab).mpr hBC + have haR : a ∉ cluster G (ω \ {f}) x := fun hh => Set.disjoint_left.mp (havoid i hji hik) haC hh + have hbS : b ∉ cluster G ω x := slit_cluster_subset G _ (η i) (y i) hy hb + have heq := splice_preserves_prefix_cut G ω (η i) x + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e f a b hab haR hbS + rw [ih] + · exact heq + · intro l hil hlk + rw [heq] + exact havoid l (hji.trans hil) hlk + + +theorem SpliceTrace.endpoint (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : y k ∈ cluster G ωf x := by + induction h with + | stop _ _ hs => exact hs + | step => assumption + + + +theorem SpliceTrace.seams_pivotal (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : + ∀ q ∈ steps, OpenMarkedPivotal G ωf {y k} x q.2 := by + induction h with + | stop => simp + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + have hcut : cluster G (ω' \ {e}) x = S := + splice_close_seam_cluster G ω (η i) x (y i) hy e a b hab he ha hb + have hfinal : cluster G (ωf \ {e}) x = S := by + rw [SpliceTrace.preserve_cut G x η y k i ω' ωf rest ht e] + · exact hcut + · intro l hil hlk + rw [hcut] + exact hmax l hil hlk + have hconn := SpliceTrace.endpoint G x η y k i ω' ωf rest ht + have hno : ¬Conn G (ωf \ {e}) x (y k) := by + intro hc + have : y k ∈ cluster G (ωf \ {e}) x := hc + rw [hfinal] at this + exact hn this + have heω : e ∈ ωf := by + by_contra heω + have heq : ωf \ {e} = ωf := by + ext f + constructor + · exact fun hh => hh.1 + · intro hh + exact ⟨hh,fun hfe => heω ((Set.mem_singleton_iff.mp hfe) ▸ hh)⟩ + exact hno (heq.symm ▸ hconn) + exact ⟨heω,⟨y k,rfl,hconn⟩,by simpa only [MarkedEvent,Set.mem_singleton_iff,exists_eq_left] using hno⟩ + · exact ih q hq + +end SpliceTrace + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/MomentBounds.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/MomentBounds.lean index c2464e15ebf686ee4896a34179ecd66c2bc8dd0e..de5eebc5b27b99a6aaed39bc36f3a56cfd6e0d5e 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/MomentBounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/MomentBounds.lean @@ -1,1252 +1,1252 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.ReferenceLaws - -namespace OAI - -/-! Moment Bounds for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SeededTraceMeasurable -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem uniformRank_fiber_eq (K : ℕ) (hK : 0 < K) (a : Fin K) : - {t : unitInterval | uniformRank K hK t = a} = contactInterval K a.val ∪ - (if uniformRank K hK 1 = a then {1} else ∅) := by - ext t - by_cases ht : t = 1 - · subst t - have hnot : (1 : unitInterval) ∉ contactInterval K a.val := by - intro h - have hp : (0:ℝ) < K := by exact_mod_cast hK - have hlt := (lt_div_iff₀ hp).mp h.2 - have ha : (a.val:ℝ)+1 ≤ K := by exact_mod_cast (show a.val+1 ≤ K by omega) - push_cast at hlt - norm_num at hlt - linarith - simp [hnot] - · have hlt : (t:ℝ) < 1 := lt_of_le_of_ne t.property.2 (fun he => ht (Subtype.ext he)) - have he := uniformRank_eq_iff K hK t hlt a - simp only [Set.mem_union,Set.mem_ofPred_eq] - split_ifs <;> simpa [ht] using he - -theorem measurableSet_contactInterval (K a : ℕ) : MeasurableSet (contactInterval K a) := - (measurableSet_le measurable_const measurable_subtype_coe).inter - (measurableSet_lt measurable_subtype_coe measurable_const) - -theorem measurableSet_uniformRank_fiber (K : ℕ) (hK : 0 < K) (a : Fin K) : - MeasurableSet {t : unitInterval | uniformRank K hK t = a} := by - rw [uniformRank_fiber_eq] - apply (measurableSet_contactInterval K a.val).union - split_ifs - · exact measurableSet_singleton _ - · exact MeasurableSet.empty - -theorem measurableSet_uniformContact_fiber (K : Finset E) (hK : K.Nonempty) (e : E) : - MeasurableSet {t : unitInterval | uniformContact K hK t = e} := by - by_cases he : e ∈ K - · simp_rw [uniformContact_eq_iff K hK _ e he] - exact measurableSet_uniformRank_fiber _ _ _ - · have hz : {t : unitInterval | uniformContact K hK t = e} = ∅ := by - ext t - simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] - exact fun h => he (h ▸ uniformContact_mem K hK t) - rw [hz] - exact MeasurableSet.empty - -theorem measurableSet_chooseContact_fiber [Nonempty E] (i : ℕ) (K : Set E) (e : E) : - MeasurableSet {t : unitInterval | chooseContact (fun _ => t) i K = e} := by - unfold chooseContact - split_ifs - · exact measurableSet_uniformContact_fiber _ _ _ - · by_cases he : Classical.arbitrary E = e <;> simp [he] - · by_cases he : Classical.arbitrary E = e <;> simp [he] - -theorem measurableSet_replaySeedFiber [Nonempty E] (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (i : ℕ) : - MeasurableSet (replaySeedFiber G x η y c ω i) := by - induction c generalizing ω with - | nil => exact MeasurableSet.univ - | cons q c ih => - obtain ⟨j,e⟩ := q - simp only [replaySeedFiber] - split_ifs - · exact measurableSet_chooseContact_fiber _ _ _ - · exact ih _ - -theorem SpliceTrace.measurableSet_seed_event [Nonempty E] (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) - (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) : - MeasurableSet {u : Fin k → unitInterval | FollowsContactRule G x η y - (chooseContact (finiteContactSeeds k u)) c ω} := by - rw [h.seed_event_eq_pi G x η y k j ω ωf c] - exact MeasurableSet.univ_pi (fun i => measurableSet_replaySeedFiber G x η y c ω (i.val+1)) - -end SeededTraceMeasurable -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section FiniteTraceDistribution -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finite_bounded_lists {A : Type*} (Q : Finset A) (k : ℕ) : - {c : List A | c.length ≤ k ∧ ∀ q ∈ c, q ∈ Q}.Finite := by - have hf := (List.finite_length_le ↥Q k).image (List.map Subtype.val) - apply hf.subset - rintro c ⟨hc,hQ⟩ - let d : List ↥Q := c.attach.map (fun q => ⟨q.val,hQ q.val q.property⟩) - refine ⟨d,?_,?_⟩ - · simpa only [d,List.length_map,List.length_attach,Set.mem_ofPred_eq] using hc - · simp [d,List.map_map] - -noncomputable def boundedTraceCodes (Q : Finset E) (k : ℕ) : Finset (List (ℕ × E)) := - (finite_bounded_lists ((Finset.Icc 1 k) ×ˢ Q) k).toFinset - -@[simp] theorem mem_boundedTraceCodes (Q : Finset E) (k : ℕ) (c : List (ℕ × E)) : - c ∈ boundedTraceCodes Q k ↔ c.length ≤ k ∧ ∀ q ∈ c, 1 ≤ q.1 ∧ q.1 ≤ k ∧ q.2 ∈ Q := by - simp [boundedTraceCodes,Finset.mem_product,and_assoc] - -theorem SpliceTrace.length_le (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) : c.length ≤ k-j := by - induction h with - | stop => simp - | step => simp only [List.length_cons]; omega - -theorem SpliceTrace.mem_boundedTraceCodes (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) (Q : Finset E) - (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) : c ∈ boundedTraceCodes Q k := by - rw [Percolation.mem_boundedTraceCodes] - refine ⟨(h.length_le G x η y k j ω ωf c).trans (Nat.sub_le ..),?_⟩ - intro q hq - obtain ⟨hj,hk,he,_⟩ := h.seam_data G x η y k j ω ωf c q hq - exact ⟨by omega,hk,hQ q.1 (by omega) hk he⟩ - - - -noncomputable def finiteTraceCodes (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω : Set E) (Q : Finset E) : Finset (List (ℕ × E)) := - (boundedTraceCodes Q k).filter (fun c => - SpliceTrace G x η y k j ω c (replaySplice G x η y c ω)) - -theorem mem_finiteTraceCodes_iff (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω : Set E) (Q : Finset E) (c : List (ℕ × E)) : - c ∈ finiteTraceCodes G x η y k j ω Q ↔ c ∈ boundedTraceCodes Q k ∧ - SpliceTrace G x η y k j ω c (replaySplice G x η y c ω) := by - simp [finiteTraceCodes] - - - -theorem finite_trace_seed_partition [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k M : ℕ) (Q : Finset E) - (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M) - (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) - (hfin : (cluster G ω x).Finite) : - let S := finiteTraceCodes G x η y k j ω Q - let A := fun c => {u : Fin k → unitInterval | FollowsContactRule G x η y - (chooseContact (finiteContactSeeds k u)) c ω} - (⋃ c ∈ S, A c) = Set.univ ∧ Set.PairwiseDisjoint (↑S) A := by - intro S A - constructor - · apply Set.eq_univ_of_forall - intro u - obtain ⟨c,ωf,ht,hr,_⟩ := exists_seeded_spliceTrace G hloc x η y k M hchain hcaps - (chooseContact (finiteContactSeeds k u)) (chooseContact_mem _) j hj ω hyj _ hfin (le_refl _) - have hc : c ∈ S := (mem_finiteTraceCodes_iff ..).mpr - ⟨ht.mem_boundedTraceCodes G x η y k j ω ωf c Q hQ, - (ht.replay_eq G x η y k j ω ωf c).symm ▸ ht⟩ - exact Set.mem_iUnion.mpr ⟨c,Set.mem_iUnion.mpr ⟨hc,hr⟩⟩ - · intro c hc d hd hcd - apply Set.disjoint_left.mpr - intro u huc hud - have ht := (mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc - have hs := (mem_finiteTraceCodes_iff G x η y k j ω Q d).mp hd - exact hcd (ht.2.seeded_unique G x η y k j ω _ _ c d hs.2 - (chooseContact (finiteContactSeeds k u)) huc hud).1 - - -theorem sum_finite_trace_probabilities [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k M : ℕ) (Q : Finset E) - (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M) - (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) - (hfin : (cluster G ω x).Finite) : - (∑ c ∈ finiteTraceCodes G x η y k j ω Q, - ∏ i : Fin k, (traceContactCount G η y (replaySplice G x η y c ω) x c (i.val+1):ℝ)⁻¹) = 1 := by - let S := finiteTraceCodes G x η y k j ω Q - let A := fun c => {u : Fin k → unitInterval | FollowsContactRule G x η y - (chooseContact (finiteContactSeeds k u)) c ω} - have hpart := finite_trace_seed_partition G hloc x η y k M Q hQ hchain hcaps j hj ω hyj hfin - have hm : ∀ c ∈ S, MeasurableSet (A c) := by - intro c hc - exact ((mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc).2.measurableSet_seed_event - G x η y k j ω _ c - have hsum : ∑ c ∈ S, volume (A c) = 1 := by - rw [← measure_biUnion_finset hpart.2 hm,hpart.1,measure_univ] - have hr := congrArg ENNReal.toReal hsum - rw [ENNReal.toReal_sum (fun c _ => measure_ne_top volume (A c)),ENNReal.toReal_one] at hr - rw [← hr] - apply Finset.sum_congr rfl - intro c hc - exact (((mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc).2.seed_probability - G hloc x η y k j ω _ c (fun i hi hik => (hcaps i (Finset.mem_Icc.mpr ⟨hi,hik⟩)).1)).symm - -end FiniteTraceDistribution -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteSpliceState -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem SpliceTrace.runMasks_execution (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) : - ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → - SpliceExecution G x (ω,θ) c (runMasks (replayMasks G x η y c ω) (ω,θ)) := by - induction h with - | stop => intro θ _; exact SpliceExecution.nil _ - | @step j i ω e a b c ωf hn hji hik hm hy he hab ha hb ht ih => - intro θ hθ - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let M := spliceMask G S B e - let ω' := spliceField G S B e ω (η i) - let θ' := Function.update θ i (exchangeOn M (θ i) ω) - have hθi := hθ i hji hik - have hstep : exchangeState M i (ω,θ) = (ω',θ') := by - apply Prod.ext - · change exchangeOn M ω (θ i) = exchangeOn M ω (η i) - rw [hθi] - · rfl - change SpliceExecution G x (ω,θ) ((i,e)::c) - (runMasks (replayMasks G x η y c ω') (exchangeState M i (ω,θ))) - rw [hstep] - refine SpliceExecution.cons (ω,θ) (ω',θ') _ (i,e) c ?_ ?_ - · refine ⟨y i,a,b,hy,?_,hab,ha,?_,?_⟩ - · simpa only [hθi] using he - · simpa only [hθi] using hb - · simpa only [hθi] using hstep.symm - · apply ih θ' - intro l hil hlk - rw [show θ' l = θ l from Function.update_of_ne (by omega) _ _] - exact hθ l (hji.trans hil) hlk - -abbrev FiniteSpliceData (Q : Finset E) (J : Finset ℕ) := - FiniteField Q × (↥J → FiniteField Q) - -def encodeFiniteSplice (Q : Finset E) (J : Finset ℕ) - (s : FiniteSpliceData Q J) : SpliceState E := - (finiteFieldSet Q s.1,finiteFieldFamily Q J s.2) - -theorem encodeFiniteSplice_injective (Q : Finset E) (J : Finset ℕ) : - Function.Injective (encodeFiniteSplice Q J) := by - intro a b he - exact Prod.ext (finiteFieldSet_injective Q (congrArg Prod.fst he)) - (finiteFieldFamily_injective Q J (congrArg Prod.snd he)) - -noncomputable def finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) : Finset (SpliceState E) := - Finset.univ.image (encodeFiniteSplice Q J) - -theorem spliceTupleWeight_encode (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (s : FiniteSpliceData Q J) : spliceTupleWeight Q J p (encodeFiniteSplice Q J s) = - finiteFieldWeight Q p s.1 * finiteFamilyWeight Q J p s.2 := by - simp only [spliceTupleWeight,encodeFiniteSplice,domainBits_finiteFieldSet, - prod_fieldFamilyWeight,finiteFieldWeight] - -theorem sum_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) (p : ℝ) : - ∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s = 1 := by - rw [finiteSpliceDomain,Finset.sum_image (encodeFiniteSplice_injective Q J).injOn] - simp only [spliceTupleWeight_encode,Fintype.sum_prod_type,← Finset.mul_sum, - sum_finiteFamilyWeight,mul_one,sum_finiteFieldWeight] - - -theorem mem_finiteSpliceDomain_iff (Q : Finset E) (J : Finset ℕ) (s : SpliceState E) : - s ∈ finiteSpliceDomain Q J ↔ s.1 ⊆ (Q : Set E) ∧ - (∀ i, s.2 i ⊆ (Q : Set E)) ∧ ∀ i ∉ J, s.2 i = ∅ := by - constructor - · intro hs - obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs - refine ⟨?_,?_,?_⟩ - · exact Finset.coe_subset.mpr (Finset.mem_powerset.mp a.1.property) - · intro i - by_cases hi : i ∈ J - · simpa only [encodeFiniteSplice,finiteFieldFamily,dite_eq_left hi,finiteFieldSet] using - Finset.coe_subset.mpr (Finset.mem_powerset.mp (a.2 ⟨i,hi⟩).property) - · simp [encodeFiniteSplice,finiteFieldFamily,hi] - · intro i hi - simp [encodeFiniteSplice,finiteFieldFamily,hi] - · rintro ⟨hω,hη,hz⟩ - let desc (ω : Set E) : FiniteField Q := ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ - have he (ω : Set E) (h : ω ⊆ (Q : Set E)) : finiteFieldSet Q (desc ω) = ω := by - ext e - simp only [finiteFieldSet,desc,Finset.mem_coe,mem_domainBits] - exact ⟨fun hh => hh.2,fun hh => ⟨h hh,hh⟩⟩ - refine Finset.mem_image.mpr ⟨(desc s.1,fun i => desc (s.2 i)),Finset.mem_univ _,?_⟩ - apply Prod.ext (he s.1 hω) - funext i - by_cases hi : i ∈ J - · simp only [encodeFiniteSplice,finiteFieldFamily,dite_eq_left hi,he _ (hη i)] - · simp only [encodeFiniteSplice,finiteFieldFamily,dite_eq_right hi,hz i hi] - -theorem exchangeState_mem_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) - (s : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J) (i : ℕ) (hi : i ∈ J) (M : Set E) : - exchangeState M i s ∈ finiteSpliceDomain Q J := by - obtain ⟨hω,hη,hz⟩ := (mem_finiteSpliceDomain_iff Q J s).mp hs - apply (mem_finiteSpliceDomain_iff Q J _).mpr - refine ⟨exchangeOn_subset M _ _ _ hω (hη i),?_,?_⟩ - · intro l - by_cases hli : l = i - · simpa only [hli,exchangeState_at] using exchangeOn_subset M _ _ _ (hη i) hω - · rw [exchangeState_away _ _ _ _ hli] - exact hη l - · intro l hl - have hli : l ≠ i := by intro he; subst l; exact hl hi - rw [exchangeState_away _ _ _ _ hli] - exact hz l hl - -theorem runMasks_mem_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) - (s : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J) (ms : List (ℕ × Set E)) - (hJ : ∀ q ∈ ms, q.1 ∈ J) : runMasks ms s ∈ finiteSpliceDomain Q J := by - induction ms generalizing s with - | nil => exact hs - | cons q ms ih => - apply ih _ (exchangeState_mem_finiteSpliceDomain Q J s hs q.1 (hJ q (by simp)) q.2) - exact fun q hq => hJ q (by simp [hq]) - -end FiniteSpliceState - -end Percolation - - -open MeasureTheory -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteSwitchDensity -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def finiteInverseLoad {I : Type*} [Fintype I] - (out : I → SpliceState E) (mass : I → ℝ) (t : SpliceState E) : ℝ := - ∑ a, if out a = t then mass a else 0 - -theorem finiteInverseLoad_nonneg {I : Type*} [Fintype I] - (out : I → SpliceState E) (mass : I → ℝ) (hm : ∀ a, 0 ≤ mass a) (t : SpliceState E) : - 0 ≤ finiteInverseLoad out mass t := by - apply Finset.sum_nonneg - intro a _ - split_ifs - · exact hm a - · exact le_refl 0 - - - -theorem finiteInverseLoad_le {I : Type*} [Fintype I] - (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) - (L : ℝ) (hL : 1 ≤ L) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (hir : Function.Injective (fun a => (inp a,steps a))) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) - (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ - (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) - (t : SpliceState E) : - finiteInverseLoad out (fun a => ∏ i : Fin k, - (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ - inverseCodeMass M L ^ k := by - let J := {a : I // out a = t} - have hr (a : J) (i : Fin k) : 0 < traceContactCount G (inp a.val).2 (y a.val) - (out a.val).1 x (steps a.val) (i.val+1) := by - have hh := ((htrace a.val).contact_weight_bound G hloc x (inp a.val).2 (y a.val) - k 0 M (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L hL - (hgood a.val) (i.val+1)).1 - omega - have hb := finite_inverse_contact_mass_le G hloc x z k M L hL (0 : unitInterval) ∅ - (fun a : J => inp a.val) (fun a : J => out a.val) (fun a : J => steps a.val) - (fun a : J => y a.val) - (fun a b he => Subtype.ext (hir he)) (fun a => htrace a.val) (fun a => hex a.val) - (fun a => hz a.val) (fun a => hfin a.val) (fun a => hgood a.val) - (fun _ _ => 0) hr {t} (fun a => by simpa only [Finset.mem_singleton] using a.property) - simp only [real_volume_contact_choice_cube _ _ (hr _),spliceTupleWeight,domainBits, - Finset.filter_empty,bernoulliWeight,Finset.card_empty,Nat.sub_self,pow_zero, - Finset.prod_const_one,mul_one,one_mul,Finset.sum_singleton] at hb - rw [finiteInverseLoad,← Finset.sum_filter] - rw [Finset.sum_subtype (p := fun a : I => out a = t) _ (by intro a; simp) _] - exact hb - - - -theorem finiteInverseLoad_density {I : Type*} [Fintype I] - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (mass : I → ℝ) (B : Finset (SpliceState E)) (hB : ∀ a, out a ∈ B) - (f : SpliceState E → ℝ) : - (∑ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) * mass a * f (out a)) = - ∑ t ∈ B, spliceTupleWeight Q (Finset.Icc 1 k) p t * finiteInverseLoad out mass t * f t := by - have hw (a : I) : spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) = - spliceTupleWeight Q (Finset.Icc 1 k) p (out a) := by - symm - apply (hex a).weight G x (inp a) (out a) (steps a) Q (Finset.Icc 1 k) _ p - intro q hq - have h := (htrace a).seam_data G x (inp a).2 (y a) k 0 (inp a).1 (out a).1 (steps a) q hq - exact Finset.mem_Icc.mpr ⟨h.1,h.2.1⟩ - simp only [finiteInverseLoad,Finset.mul_sum,Finset.sum_mul] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - simp only [mul_ite,mul_zero,ite_mul,zero_mul] - rw [Finset.sum_ite_eq,ite_eq_left (hB a),hw a] - -end FiniteSwitchDensity - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteForwardDensity -attribute [local instance] Classical.propDecidable Classical.decEq - - - -abbrev FiniteTraceIndex (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) := - (s : ↥A) × ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q) - -def traceIndexInput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) : SpliceState E := a.1.val - -def traceIndexCode (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) : List (ℕ × E) := a.2.val - -def traceIndexOutput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) : SpliceState E := - runMasks (replayMasks G x a.1.val.2 (y a.1.val) a.2.val a.1.val.1) a.1.val - -theorem traceIndex_valid (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) : - SpliceTrace G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 a.2.val - (traceIndexOutput G x k Q A y a).1 ∧ - SpliceExecution G x a.1.val a.2.val (traceIndexOutput G x k Q A y a) := by - have ht := ((mem_finiteTraceCodes_iff G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 Q a.2.val).mp - a.2.property).2 - have hf := ht.runMasks_first G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 _ a.2.val - a.1.val.2 (by intros; rfl) - refine ⟨?_,?_⟩ - · simpa only [traceIndexOutput,hf] using ht - · exact ht.runMasks_execution G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 _ a.2.val - a.1.val.2 (by intros; rfl) - -theorem traceIndex_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) : - Function.Injective (fun a : FiniteTraceIndex G x k Q A y => - (traceIndexInput G x k Q A y a,traceIndexCode G x k Q A y a)) := by - rintro ⟨a,c⟩ ⟨b,d⟩ he - have hah : a = b := Subtype.ext (congrArg Prod.fst he) - subst b - have hcd : c = d := Subtype.ext (congrArg Prod.snd he) - subst d - rfl - -theorem traceIndexOutput_mem (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (a : FiniteTraceIndex G x k Q A y) : - traceIndexOutput G x k Q A y a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := by - apply runMasks_mem_finiteSpliceDomain Q (Finset.Icc 1 k) a.1.val (hA a.1.property) - intro q hq - have hmap : q.1 ∈ (replayMasks G x a.1.val.2 (y a.1.val) a.2.val a.1.val.1).map Prod.fst := - List.mem_map.mpr ⟨q,hq,rfl⟩ - rw [replayMasks_indices] at hmap - obtain ⟨r,hr,her⟩ := List.mem_map.mp hmap - have h := (traceIndex_valid G x k Q A y a).1.seam_data G x a.1.val.2 (y a.1.val) - k 0 a.1.val.1 _ a.2.val r hr - exact her ▸ Finset.mem_Icc.mpr ⟨h.1,h.2.1⟩ - - - -noncomputable def traceIndexMass (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (a : FiniteTraceIndex G x k Q A y) : ℝ := - ∏ i : Fin k, (traceContactCount G a.1.val.2 (y a.1.val) - (traceIndexOutput G x k Q A y a).1 x a.2.val (i.val+1):ℝ)⁻¹ - -noncomputable def finiteForwardLoad (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) (t : SpliceState E) : ℝ := - finiteInverseLoad (traceIndexOutput G x k Q A y) (traceIndexMass G x k Q A y) t - - - -theorem finiteForwardLoad_bounds (G : BondGraph V E) (hloc : LocallyFinite G) - (x z : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hz : ∀ s ∈ A, y s k = z) - (hgood : ∀ s ∈ A, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y s i)).Finite ∧ - (cluster G (s.2 i) (y s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y s i) L) - (t : SpliceState E) : - 0 ≤ finiteForwardLoad G x k Q A y t ∧ finiteForwardLoad G x k Q A y t ≤ inverseCodeMass M L ^ k := by - constructor - · exact finiteInverseLoad_nonneg _ _ (by intro a; unfold traceIndexMass; positivity) t - · apply finiteInverseLoad_le G hloc x z k M L hL - (traceIndexInput G x k Q A y) (traceIndexOutput G x k Q A y) (traceIndexCode G x k Q A y) - (fun a => y a.1.val) (traceIndex_injective G x k Q A y) - (fun a => (traceIndex_valid G x k Q A y a).1) - (fun a => (traceIndex_valid G x k Q A y a).2) (fun a => hz a.1.val a.1.property) - _ (fun a => hgood a.1.val a.1.property) t - intro a - have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp - (traceIndexOutput_mem G x k Q A y hA a) - exact cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x - - - -theorem finiteForwardLoad_mean [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hy : ∀ s ∈ A, y s 0 ∈ cluster G s.1 x) - (hchain : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y s i) (y s (i-1))) - (hcaps : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, (cluster G (s.2 i) (y s i)).Finite ∧ - (cluster G (s.2 i) (y s i)).ncard ≤ M) : - (∑ t ∈ finiteSpliceDomain Q (Finset.Icc 1 k), - spliceTupleWeight Q (Finset.Icc 1 k) p t * finiteForwardLoad G x k Q A y t) = - ∑ s ∈ A, spliceTupleWeight Q (Finset.Icc 1 k) p s := by - have hd := finiteInverseLoad_density G x k Q p - (traceIndexInput G x k Q A y) (traceIndexOutput G x k Q A y) (traceIndexCode G x k Q A y) - (fun a => y a.1.val) (fun a => (traceIndex_valid G x k Q A y a).1) - (fun a => (traceIndex_valid G x k Q A y a).2) - (traceIndexMass G x k Q A y) (finiteSpliceDomain Q (Finset.Icc 1 k)) - (traceIndexOutput_mem G x k Q A y hA) (fun _ => 1) - simp only [mul_one] at hd - unfold finiteForwardLoad - rw [← hd,Fintype.sum_sigma] - rw [← Finset.sum_coe_sort A (fun s => spliceTupleWeight Q (Finset.Icc 1 k) p s)] - apply Finset.sum_congr rfl - intro s _ - change (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), - spliceTupleWeight Q (Finset.Icc 1 k) p s.val * traceIndexMass G x k Q A y ⟨s,c⟩) = _ - rw [← Finset.mul_sum] - suffices hm : (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), - traceIndexMass G x k Q A y ⟨s,c⟩) = 1 by rw [hm,mul_one] - have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s.val).mp (hA s.property) - have hn := sum_finite_trace_probabilities G hloc x s.val.2 (y s.val) k M Q - (fun i _ _ => hs.2.1 i) (hchain s.val s.property) (hcaps s.val s.property) - 0 (Nat.zero_le _) s.val.1 (hy s.val s.property) - (cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x) - rw [← Finset.sum_coe_sort (finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q)] at hn - rw [← hn] - apply Finset.sum_congr rfl - intro c _ - have ht := ((mem_finiteTraceCodes_iff G x s.val.2 (y s.val) k 0 s.val.1 Q c.val).mp c.property).2 - have hf := ht.runMasks_first G x s.val.2 (y s.val) k 0 s.val.1 _ c.val s.val.2 (by intros; rfl) - simp only [traceIndexMass,traceIndexOutput,hf] - -end FiniteForwardDensity - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section ContactIntegratedSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_event_mass_le {Ω I : Type*} [MeasurableSpace Ω] [Fintype I] - (μ : Measure Ω) [IsProbabilityMeasure μ] (P : I → Set Ω) - (hm : ∀ a, MeasurableSet (P a)) (w : I → ℝ) (B : ℝ) - (hpoint : ∀ u, (∑ a, if u ∈ P a then w a else 0) ≤ B) : - (∑ a, w a * μ.real (P a)) ≤ B := by - let f (a : I) : Ω → ℝ := (P a).indicator (fun _ => w a) - have hf : ∀ a, Integrable (f a) μ := fun a => (integrable_const _).indicator (hm a) - have hi := integral_mono (integrable_finsetSum _ (fun a _ => hf a)) - (integrable_const B) (fun u => hpoint u) - change (∫ u, ∑ a, f a u ∂μ) ≤ (∫ _ : Ω, B ∂μ) at hi - rw [integral_finsetSum _ (fun a _ => hf a)] at hi - simpa only [f,integral_indicator_const _ (hm _),smul_eq_mul,mul_comm, - integral_const,probReal_univ,one_smul,mul_one] using hi - - - -theorem finite_separated_contact_second_moment_le {I : Type*} [Fintype I] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (success₁ success₂ : (ℕ → Set E) → Prop) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ - (cluster G (ω₁ a) x).ncard < 2*n) - (hcap₁ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₁ a i) (y₁ (η₁ a) i)).Finite) - (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ - (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) - (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) - (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) - (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) - (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) - (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * - (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * - (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹)) ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₁ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty) * - finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₂ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty) else 0) := by - let S := Fin k → unitInterval - let μ : Measure (S × S) := (volume : Measure S).prod volume - let P₁ (a : I) : Set S := {u | FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) - (chooseContact (finiteContactSeeds k u)) (c₁ a) (ω₁ a)} - let P₂ (a : I) : Set S := {u | FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) - (chooseContact (finiteContactSeeds k u)) (c₂ a) (ω₂ a)} - let w (a : I) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) - have hm₁ (a : I) : MeasurableSet (P₁ a) := - (h₁ a).measurableSet_seed_event G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) - have hm₂ (a : I) : MeasurableSet (P₂ a) := - (h₂ a).measurableSet_seed_event G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) - have hp (a : I) : μ.real (P₁ a ×ˢ P₂ a) = - (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * - (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹) := by - rw [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, - (h₁ a).seed_probability G hloc x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) (hcap₁ a), - (h₂ a).seed_probability G hloc x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) (fun i hi hik => (hcap₂ a i hi hik).1)] - conv_lhs => arg 2; ext a; rw [mul_assoc,← hp a] - apply finite_event_mass_le μ (fun a => P₁ a ×ˢ P₂ a) (fun a => (hm₁ a).prod (hm₂ a)) w - intro u - let J := {a : I // u ∈ P₁ a ×ˢ P₂ a} - have hb := finite_separated_second_moment_le G x k n M p Q - (fun a : J => η₁ a.val) (fun a : J => η₂ a.val) y₁ y₂ success₁ success₂ - (chooseContact (finiteContactSeeds k u.1)) (chooseContact (finiteContactSeeds k u.2)) - (fun a : J => ω₁ a.val) (fun a : J => ω₂ a.val) (fun a : J => ωf a.val) - (fun a : J => c₁ a.val) (fun a : J => c₂ a.val) - (fun _ _ he => Subtype.ext (hir he)) (fun a => h₁ a.val) (fun a => h₂ a.val) - (fun a => hc₁ a.val) (fun a => hc₂ a.val) (fun a => hsep a.val) - (fun a => a.property.1) (fun a => a.property.2) - (fun a => hbin a.val) (fun a => hcap₂ a.val) (fun a => hsc₁ a.val) (fun a => hsc₂ a.val) - (fun a => hsω₁ a.val) (fun a => hsω₂ a.val) (fun a => hsη₁ a.val) (fun a => hsη₂ a.val) - (fun a => hz₁ a.val) (fun a => hz₂ a.val) - convert hb using 1 - have he := Finset.sum_subtype (p := fun a => u ∈ P₁ a ×ˢ P₂ a) (F := inferInstance) (Finset.univ.filter (fun a => u ∈ P₁ a ×ˢ P₂ a)) - (by intro a; simp) w - simpa [Finset.sum_filter,w] using he - -end ContactIntegratedSecondMoment - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteRootLoad -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def finiteRootLoad (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (f : SpliceState E → ℝ) (ω : FiniteField Q) : ℝ := - ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * - f (finiteFieldSet Q ω,finiteFieldFamily Q J η) - -theorem finiteRootLoad_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (f : SpliceState E → ℝ) (hf : ∀ s ∈ finiteSpliceDomain Q J, 0 ≤ f s) - (ω : FiniteField Q) : 0 ≤ finiteRootLoad Q J p f ω := by - apply Finset.sum_nonneg - intro η _ - apply mul_nonneg (finiteFamilyWeight_nonneg Q J p η) - exact hf _ (Finset.mem_image.mpr ⟨(ω,η),Finset.mem_univ _,rfl⟩) - -theorem finiteRootLoad_le (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (f : SpliceState E → ℝ) (C : ℝ) - (hf : ∀ s ∈ finiteSpliceDomain Q J, f s ≤ C) - (ω : FiniteField Q) : finiteRootLoad Q J p f ω ≤ C := by - calc - _ ≤ ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * C := by - apply Finset.sum_le_sum - intro η _ - apply mul_le_mul_of_nonneg_left _ (finiteFamilyWeight_nonneg Q J p η) - exact hf _ (Finset.mem_image.mpr ⟨(ω,η),Finset.mem_univ _,rfl⟩) - _ = C := by rw [← Finset.sum_mul,sum_finiteFamilyWeight,one_mul] - - -theorem finiteRootLoad_mean (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (f : SpliceState E → ℝ) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * finiteRootLoad Q J p f ω) = - ∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s * f s := by - rw [finiteSpliceDomain,Finset.sum_image (encodeFiniteSplice_injective Q J).injOn, - Fintype.sum_prod_type] - simp only [spliceTupleWeight,finiteRootLoad,Finset.mul_sum,encodeFiniteSplice, - domainBits_finiteFieldSet,prod_fieldFamilyWeight,finiteFieldWeight,mul_assoc] - - - -theorem finiteRootLoad_second_moment (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (f₁ f₂ : SpliceState E → ℝ) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteRootLoad Q J₁ p f₁ ω * finiteRootLoad Q J₂ p f₂ ω) = - ∑ s : FiniteJointData Q J₁ J₂, jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) * - f₁ (finiteFieldSet Q s.1,finiteFieldFamily Q J₁ s.2.1) * - f₂ (finiteFieldSet Q s.1,finiteFieldFamily Q J₂ s.2.2) := by - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro ω _ - rw [Fintype.sum_prod_type] - simp only [finiteRootLoad,Finset.mul_sum,Finset.sum_mul,jointTupleWeight_encode] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro η₁ _ - apply Finset.sum_congr rfl - intro η₂ _ - ring - - -theorem finiteForwardRootLoad_bounds (G : BondGraph V E) (hloc : LocallyFinite G) - (x z : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) (p : unitInterval) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hz : ∀ s ∈ A, y s k = z) - (hgood : ∀ s ∈ A, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y s i)).Finite ∧ - (cluster G (s.2 i) (y s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y s i) L) - (ω : FiniteField Q) : - 0 ≤ finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω ∧ - finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω ≤ inverseCodeMass M L ^ k := by - have hb := finiteForwardLoad_bounds G hloc x z k M L hL Q A y hA hz hgood - exact ⟨finiteRootLoad_nonneg _ _ p _ (fun s _ => (hb s).1) _, - finiteRootLoad_le _ _ p _ _ (fun s _ => (hb s).2) _⟩ - - - -theorem finiteForwardRootLoad_mean [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) - (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hy : ∀ s ∈ A, y s 0 ∈ cluster G s.1 x) - (hchain : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y s i) (y s (i-1))) - (hcaps : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, (cluster G (s.2 i) (y s i)).Finite ∧ - (cluster G (s.2 i) (y s i)).ncard ≤ M) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω) = - ∑ s ∈ A, spliceTupleWeight Q (Finset.Icc 1 k) p s := by - rw [finiteRootLoad_mean] - exact finiteForwardLoad_mean G hloc x k M Q p A y hA hy hchain hcaps - -end FiniteRootLoad - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FinitePairLoad -attribute [local instance] Classical.propDecidable Classical.decEq - - -def pairSpliceOutput (s t : SpliceState E) : JointSpliceState E := (s.1,s.2,t.2) - -theorem pairSpliceOutput_mem (Q : Finset E) (J₁ J₂ : Finset ℕ) - (s t : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J₁) - (ht : t ∈ finiteSpliceDomain Q J₂) : - pairSpliceOutput s t ∈ finiteJointDomain Q J₁ J₂ := by - have h₁ := (mem_finiteSpliceDomain_iff Q J₁ s).mp hs - have h₂ := (mem_finiteSpliceDomain_iff Q J₂ t).mp ht - exact mem_finiteJointDomain_of_support Q J₁ J₂ _ h₁.1 h₁.2.1 h₂.2.1 h₁.2.2 h₂.2.2 - - -theorem finiteInverseLoad_mul {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] - (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) - (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (t : JointSpliceState E) : - finiteInverseLoad out₁ m₁ (t.1,t.2.1) * finiteInverseLoad out₂ m₂ (t.1,t.2.2) = - ∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ pairSpliceOutput (out₁ a) (out₂ b) = t - then m₁ a * m₂ b else 0 := by - simp only [finiteInverseLoad,Finset.sum_mul,Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - have he : (out₁ a = (t.1,t.2.1) ∧ out₂ b = (t.1,t.2.2)) ↔ - ((out₁ a).1 = (out₂ b).1 ∧ pairSpliceOutput (out₁ a) (out₂ b) = t) := by - cases h₁ : out₁ a with | mk r₁ u₁ => - cases h₂ : out₂ b with | mk r₂ u₂ => - rcases t with ⟨r,u,v⟩ - simpa [pairSpliceOutput,Prod.mk.injEq] using - (show (r₁ = r ∧ u₁ = u) ∧ (r₂ = r ∧ u₂ = v) ↔ - r₁ = r₂ ∧ r₁ = r ∧ u₁ = u ∧ u₂ = v from by aesop) - simp only [← he] - split_ifs <;> simp_all - - - -theorem finiteRootLoad_pair_expansion {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] - (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) - (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) - (hs₁ : ∀ a, out₁ a ∈ finiteSpliceDomain Q J₁) - (hs₂ : ∀ b, out₂ b ∈ finiteSpliceDomain Q J₂) : - (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteRootLoad Q J₁ p (finiteInverseLoad out₁ m₁) ω * - finiteRootLoad Q J₂ p (finiteInverseLoad out₂ m₂) ω) = - ∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 then - jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0 := by - rw [finiteRootLoad_second_moment] - have hdom : (∑ s : FiniteJointData Q J₁ J₂, - jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) * - finiteInverseLoad out₁ m₁ ((encodeFiniteJoint Q J₁ J₂ s).1,(encodeFiniteJoint Q J₁ J₂ s).2.1) * - finiteInverseLoad out₂ m₂ ((encodeFiniteJoint Q J₁ J₂ s).1,(encodeFiniteJoint Q J₁ J₂ s).2.2)) = - ∑ t ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p t * - finiteInverseLoad out₁ m₁ (t.1,t.2.1) * finiteInverseLoad out₂ m₂ (t.1,t.2.2) := by - rw [finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn] - apply hdom.trans - simp only [mul_assoc,finiteInverseLoad_mul,Finset.mul_sum,mul_ite,mul_zero] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro b _ - by_cases he : (out₁ a).1 = (out₂ b).1 - · simp only [he,true_and,ite_true] - rw [Finset.sum_ite_eq,ite_eq_left (pairSpliceOutput_mem Q J₁ J₂ _ _ (hs₁ a) (hs₂ b))] - · simp [he] - -theorem traceIndex_output_code_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) : - Function.Injective (fun a : FiniteTraceIndex G x k Q A y => - (traceIndexOutput G x k Q A y a,traceIndexCode G x k Q A y a)) := by - intro a b he - have hc : traceIndexCode G x k Q A y a = traceIndexCode G x k Q A y b := congrArg Prod.snd he - have ho : traceIndexOutput G x k Q A y a = traceIndexOutput G x k Q A y b := congrArg Prod.fst he - apply traceIndex_injective G x k Q A y - apply Prod.ext - · apply SpliceExecution.input_unique G x _ _ _ (traceIndexCode G x k Q A y a) - (traceIndex_valid G x k Q A y a).2 - change SpliceExecution G x b.1.val (traceIndexCode G x k Q A y a) (traceIndexOutput G x k Q A y a) - rw [hc,ho] - exact (traceIndex_valid G x k Q A y b).2 - · exact hc - -end FinitePairLoad - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WeightedJointMass -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem jointRestored_injective {I : Type*} - (G : BondGraph V E) (x : V) (k : ℕ) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (choose₁ choose₂ : ℕ → Set E → E) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) - (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) - : Function.Injective (fun a => jointRestored G x (η₁ a) (η₂ a) - (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a)) := by - let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) - let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) - change Function.Injective rest - intro a b he - have hη₁ : η₁ a = η₁ b := congrArg (fun s : JointSpliceState E => s.2.1) he - have hη₂ : η₂ a = η₂ b := congrArg (fun s : JointSpliceState E => s.2.2) he - have gb₁ : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ b) (c₁ b) (ωf b) := by - rw [hη₁]; exact h₁ b - have gb₂ : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ b) (c₂ b) (ωf b) := by - rw [hη₂]; exact h₂ b - have grb₁ : FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ b) (ω₁ b) := by - rw [hη₁]; exact hr₁ b - have grb₂ : FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ b) (ω₂ b) := by - rw [hη₂]; exact hr₂ b - have hfield : exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ a) (ω₂ a))) (ω₁ a) (ω₂ a) = - exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ b) (ω₂ b))) (ω₁ b) (ω₂ b) := by - have hh := congrArg Prod.fst he - simpa only [rest,jointRestored,← hη₂] using hh - obtain ⟨hcode₁,hcode₂,hfieldf,haux₁,haux₂⟩ := joint_restore_seeded_unique G x - (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) choose₁ choose₂ k 0 0 - (ω₁ a) (ω₂ a) (ωf a) (ω₁ b) (ω₂ b) (ωf b) - (c₁ a) (c₂ a) (c₁ b) (c₂ b) (h₁ a) (h₂ a) gb₁ gb₂ - (hc₁ a) (hc₂ a) (hc₁ b) (hc₂ b) (hsep a) (hsep b) - (hr₁ a) (hr₂ a) grb₁ grb₂ hfield - have hout : out a = out b := by - apply Prod.ext hfieldf - apply Prod.ext - · simpa only [out,jointOutput,hη₁] using haux₁ - · simpa only [out,jointOutput,hη₂] using haux₂ - exact hir (Prod.ext hout (Prod.ext hcode₁ hcode₂)) - - - -theorem finite_joint_weighted_mass_le {I : Type*} [Fintype I] - (G : BondGraph V E) (x : V) (k : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (choose₁ choose₂ : ℕ → Set E → E) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) - (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) - (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) - (B : Finset (JointSpliceState E)) - (hB : ∀ a, jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ - ∑ s ∈ B, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s * m₁ s.2.1 * m₂ s.2.2 := by - let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) - let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) - have hinj : Function.Injective rest := jointRestored_injective G x k η₁ η₂ y₁ y₂ choose₁ choose₂ - ω₁ ω₂ ωf c₁ c₂ hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ - have hw : ∀ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (out a) = - jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (rest a) := by - intro a - apply (h₁ a).joint_weight G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) k 0 0 - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hsep a) Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - · intro q hq - have hr := (h₁ a).seam_data G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) q hq - exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ - · intro q hq - have hr := (h₂ a).seam_data G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) q hq - exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ - change (∑ a, jointTupleWeight Q _ _ p (out a) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ _ - simp_rw [hw] - change (∑ a, jointTupleWeight Q _ _ p (rest a) * m₁ (rest a).2.1 * m₂ (rest a).2.2) ≤ _ - rw [← Finset.sum_image (f := fun s : JointSpliceState E => - jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s * m₁ s.2.1 * m₂ s.2.2) hinj.injOn] - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro s hs - obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs - exact hB a - · intro s _ _ - exact mul_nonneg (mul_nonneg (jointTupleWeight_nonneg Q _ _ p s) (hm₁ _)) (hm₂ _) - -end WeightedJointMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteFamilyIntegral -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def finiteFamilyIntegral (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (f : (ℕ → Set E) → ℝ) : ℝ := - ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * f (finiteFieldFamily Q J η) - -theorem finiteFamilyIntegral_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (f : (ℕ → Set E) → ℝ) (hf : ∀ η, 0 ≤ f η) : 0 ≤ finiteFamilyIntegral Q J p f := by - exact Finset.sum_nonneg fun η _ => mul_nonneg (finiteFamilyWeight_nonneg Q J p η) (hf _) - -theorem finiteFamilyIntegral_mono (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (f g : (ℕ → Set E) → ℝ) (hfg : ∀ η, f η ≤ g η) : - finiteFamilyIntegral Q J p f ≤ finiteFamilyIntegral Q J p g := by - exact Finset.sum_le_sum fun η _ => mul_le_mul_of_nonneg_left (hfg _) (finiteFamilyWeight_nonneg Q J p η) - -theorem finiteFamilyIntegral_const (Q : Finset E) (J : Finset ℕ) (p c : ℝ) : - finiteFamilyIntegral Q J p (fun _ => c) = c := by - rw [finiteFamilyIntegral,← Finset.sum_mul,sum_finiteFamilyWeight,one_mul] - -theorem finiteFamilyIntegral_sum {I : Type*} (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (S : Finset I) (f : I → (ℕ → Set E) → ℝ) : - finiteFamilyIntegral Q J p (fun η => ∑ i ∈ S, f i η) = - ∑ i ∈ S, finiteFamilyIntegral Q J p (f i) := by - simp only [finiteFamilyIntegral,Finset.mul_sum] - exact Finset.sum_comm - - -theorem finiteJointDomain_integral_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (f₁ f₂ : Set E → (ℕ → Set E) → ℝ) : - (∑ s ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p s * f₁ s.1 s.2.1 * f₂ s.1 s.2.2) = - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - finiteFamilyIntegral Q J₁ p (f₁ (finiteFieldSet Q ω)) * - finiteFamilyIntegral Q J₂ p (f₂ (finiteFieldSet Q ω)) := by - rw [finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn] - simp only [jointTupleWeight_encode] - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro ω _ - rw [Fintype.sum_prod_type] - simp only [finiteFamilyIntegral,Finset.mul_sum,Finset.sum_mul,encodeFiniteJoint] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro η₂ _ - apply Finset.sum_congr rfl - intro η₁ _ - ring - -theorem finiteJointDomain_weighted_event_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (P : Set E → Prop) (H₁ H₂ : Set E → (ℕ → Set E) → Prop) - (m₁ m₂ : (ℕ → Set E) → ℝ) : - (∑ s ∈ (finiteJointDomain Q J₁ J₂).filter (fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2), - jointTupleWeight Q J₁ J₂ p s * m₁ s.2.1 * m₂ s.2.2) = - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if P (finiteFieldSet Q ω) then - finiteFamilyIntegral Q J₁ p (fun η => if H₁ (finiteFieldSet Q ω) η then m₁ η else 0) * - finiteFamilyIntegral Q J₂ p (fun η => if H₂ (finiteFieldSet Q ω) η then m₂ η else 0) else 0) := by - rw [Finset.sum_filter] - have he : (∑ s ∈ finiteJointDomain Q J₁ J₂, - if P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 then - jointTupleWeight Q J₁ J₂ p s * m₁ s.2.1 * m₂ s.2.2 else 0) = - ∑ s ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p s * - (if P s.1 ∧ H₁ s.1 s.2.1 then m₁ s.2.1 else 0) * - (if H₂ s.1 s.2.2 then m₂ s.2.2 else 0) := by - apply Finset.sum_congr rfl - intro s _ - split_ifs <;> simp_all - rw [he,finiteJointDomain_integral_factor Q J₁ J₂ p - (fun ω η => if P ω ∧ H₁ ω η then m₁ η else 0) - (fun ω η => if H₂ ω η then m₂ η else 0)] - apply Finset.sum_congr rfl - intro ω _ - by_cases hP : P (finiteFieldSet Q ω) - · simp only [hP,true_and,ite_true,mul_assoc] - · simp [hP,finiteFamilyIntegral] - -end FiniteFamilyIntegral - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WeightedSeparatedSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_separated_weighted_second_moment_le {I : Type*} [Fintype I] - (G : BondGraph V E) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (success₁ success₂ : (ℕ → Set E) → Prop) - (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) - (choose₁ choose₂ : ℕ → Set E → E) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) - (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) - (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ - (cluster G (ω₁ a) x).ncard < 2*n) - (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ - (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) - (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) - (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) - (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) - (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) - (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₁ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₂ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by - let J := Finset.Icc 1 k - let P (ω : Set E) := (cluster G ω x).Finite ∧ n-k*M ≤ (cluster G ω x).ncard ∧ - (cluster G ω x).ncard < 2*n - let H₁ (ω : Set E) (η : ℕ → Set E) := success₁ η ∧ - (cluster G ω x ∩ trajectoryUnion G η (y₁ η) k).Nonempty - let H₂ (ω : Set E) (η : ℕ → Set E) := success₂ η ∧ - (cluster G ω x ∩ trajectoryUnion G η (y₂ η) k).Nonempty - let B := (finiteJointDomain Q J J).filter fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 - have hB (a : I) : jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B := by - apply Finset.mem_filter.mpr - refine ⟨mem_finiteJointDomain_of_support Q J J _ - (exchangeOn_subset _ _ _ _ (hsω₁ a) (hsω₂ a)) (hsη₁ a) (hsη₂ a) (hz₁ a) (hz₂ a),?_⟩ - have hroot := (h₁ a).joint_restored_size G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - k 0 0 n M (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) - (hbin a).1 (hbin a).2.1 (hbin a).2.2 (hcap₂ a) - have hhits := (h₁ a).joint_trajectory_hits G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - k 0 0 (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) - exact ⟨hroot,⟨hsc₁ a,hhits.1⟩,hsc₂ a,hhits.2⟩ - have h := finite_joint_weighted_mass_le G x k p Q η₁ η₂ y₁ y₂ choose₁ choose₂ ω₁ ω₂ ωf c₁ c₂ - hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ m₁ m₂ hm₁ hm₂ B hB - apply h.trans_eq - convert finiteJointDomain_weighted_event_factor Q J J p P H₁ H₂ m₁ m₂ using 1 <;> - simp only [B, J, P, H₁, H₂] - apply Finset.sum_congr rfl - intro ω _ - apply congrArg (fun z : ℝ => finiteFieldWeight Q p ω * z) - split_ifs - · apply congrArg₂ (· * ·) - · apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) - funext η - split_ifs <;> rfl - · apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) - funext η - split_ifs <;> rfl - · rfl - -end WeightedSeparatedSecondMoment - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section WeightedContactSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_separated_weighted_contact_second_moment_le {I : Type*} [Fintype I] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (success₁ success₂ : (ℕ → Set E) → Prop) - (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ - (cluster G (ω₁ a) x).ncard < 2*n) - (hcap₁ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₁ a i) (y₁ (η₁ a) i)).Finite) - (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ - (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) - (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) - (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) - (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) - (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) - (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a) * - (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * - (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹)) ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₁ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₂ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by - let S := Fin k → unitInterval - let μ : Measure (S × S) := (volume : Measure S).prod volume - let P₁ (a : I) : Set S := {u | FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) - (chooseContact (finiteContactSeeds k u)) (c₁ a) (ω₁ a)} - let P₂ (a : I) : Set S := {u | FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) - (chooseContact (finiteContactSeeds k u)) (c₂ a) (ω₂ a)} - let w (a : I) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a) - have hmeas₁ (a : I) : MeasurableSet (P₁ a) := - (h₁ a).measurableSet_seed_event G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) - have hmeas₂ (a : I) : MeasurableSet (P₂ a) := - (h₂ a).measurableSet_seed_event G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) - have hp (a : I) : μ.real (P₁ a ×ˢ P₂ a) = - (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * - (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹) := by - rw [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, - (h₁ a).seed_probability G hloc x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) (hcap₁ a), - (h₂ a).seed_probability G hloc x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) (fun i hi hik => (hcap₂ a i hi hik).1)] - conv_lhs => arg 2; ext a; rw [mul_assoc,← hp a] - apply finite_event_mass_le μ (fun a => P₁ a ×ˢ P₂ a) (fun a => (hmeas₁ a).prod (hmeas₂ a)) w - intro u - let J := {a : I // u ∈ P₁ a ×ˢ P₂ a} - have hb := finite_separated_weighted_second_moment_le G x k n M p Q - (fun a : J => η₁ a.val) (fun a : J => η₂ a.val) y₁ y₂ success₁ success₂ m₁ m₂ hm₁ hm₂ - (chooseContact (finiteContactSeeds k u.1)) (chooseContact (finiteContactSeeds k u.2)) - (fun a : J => ω₁ a.val) (fun a : J => ω₂ a.val) (fun a : J => ωf a.val) - (fun a : J => c₁ a.val) (fun a : J => c₂ a.val) - (fun _ _ he => Subtype.ext (hir he)) (fun a => h₁ a.val) (fun a => h₂ a.val) - (fun a => hc₁ a.val) (fun a => hc₂ a.val) (fun a => hsep a.val) - (fun a => a.property.1) (fun a => a.property.2) - (fun a => hbin a.val) (fun a => hcap₂ a.val) (fun a => hsc₁ a.val) (fun a => hsc₂ a.val) - (fun a => hsω₁ a.val) (fun a => hsω₂ a.val) (fun a => hsη₁ a.val) (fun a => hsη₂ a.val) - (fun a => hz₁ a.val) (fun a => hz₂ a.val) - convert hb using 1 - have he := Finset.sum_subtype (p := fun a => u ∈ P₁ a ×ˢ P₂ a) (F := inferInstance) (Finset.univ.filter (fun a => u ∈ P₁ a ×ˢ P₂ a)) - (by intro a; simp) w - simpa [Finset.sum_filter,w] using he - -end WeightedContactSecondMoment - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.ReferenceLaws + +namespace OAI + +/-! Moment Bounds for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SeededTraceMeasurable +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem uniformRank_fiber_eq (K : ℕ) (hK : 0 < K) (a : Fin K) : + {t : unitInterval | uniformRank K hK t = a} = contactInterval K a.val ∪ + (if uniformRank K hK 1 = a then {1} else ∅) := by + ext t + by_cases ht : t = 1 + · subst t + have hnot : (1 : unitInterval) ∉ contactInterval K a.val := by + intro h + have hp : (0:ℝ) < K := by exact_mod_cast hK + have hlt := (lt_div_iff₀ hp).mp h.2 + have ha : (a.val:ℝ)+1 ≤ K := by exact_mod_cast (show a.val+1 ≤ K by omega) + push_cast at hlt + norm_num at hlt + linarith + simp [hnot] + · have hlt : (t:ℝ) < 1 := lt_of_le_of_ne t.property.2 (fun he => ht (Subtype.ext he)) + have he := uniformRank_eq_iff K hK t hlt a + simp only [Set.mem_union,Set.mem_ofPred_eq] + split_ifs <;> simpa [ht] using he + +theorem measurableSet_contactInterval (K a : ℕ) : MeasurableSet (contactInterval K a) := + (measurableSet_le measurable_const measurable_subtype_coe).inter + (measurableSet_lt measurable_subtype_coe measurable_const) + +theorem measurableSet_uniformRank_fiber (K : ℕ) (hK : 0 < K) (a : Fin K) : + MeasurableSet {t : unitInterval | uniformRank K hK t = a} := by + rw [uniformRank_fiber_eq] + apply (measurableSet_contactInterval K a.val).union + split_ifs + · exact measurableSet_singleton _ + · exact MeasurableSet.empty + +theorem measurableSet_uniformContact_fiber (K : Finset E) (hK : K.Nonempty) (e : E) : + MeasurableSet {t : unitInterval | uniformContact K hK t = e} := by + by_cases he : e ∈ K + · simp_rw [uniformContact_eq_iff K hK _ e he] + exact measurableSet_uniformRank_fiber _ _ _ + · have hz : {t : unitInterval | uniformContact K hK t = e} = ∅ := by + ext t + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + exact fun h => he (h ▸ uniformContact_mem K hK t) + rw [hz] + exact MeasurableSet.empty + +theorem measurableSet_chooseContact_fiber [Nonempty E] (i : ℕ) (K : Set E) (e : E) : + MeasurableSet {t : unitInterval | chooseContact (fun _ => t) i K = e} := by + unfold chooseContact + split_ifs + · exact measurableSet_uniformContact_fiber _ _ _ + · by_cases he : Classical.arbitrary E = e <;> simp [he] + · by_cases he : Classical.arbitrary E = e <;> simp [he] + +theorem measurableSet_replaySeedFiber [Nonempty E] (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (i : ℕ) : + MeasurableSet (replaySeedFiber G x η y c ω i) := by + induction c generalizing ω with + | nil => exact MeasurableSet.univ + | cons q c ih => + obtain ⟨j,e⟩ := q + simp only [replaySeedFiber] + split_ifs + · exact measurableSet_chooseContact_fiber _ _ _ + · exact ih _ + +theorem SpliceTrace.measurableSet_seed_event [Nonempty E] (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) + (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) : + MeasurableSet {u : Fin k → unitInterval | FollowsContactRule G x η y + (chooseContact (finiteContactSeeds k u)) c ω} := by + rw [h.seed_event_eq_pi G x η y k j ω ωf c] + exact MeasurableSet.univ_pi (fun i => measurableSet_replaySeedFiber G x η y c ω (i.val+1)) + +end SeededTraceMeasurable +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section FiniteTraceDistribution +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finite_bounded_lists {A : Type*} (Q : Finset A) (k : ℕ) : + {c : List A | c.length ≤ k ∧ ∀ q ∈ c, q ∈ Q}.Finite := by + have hf := (List.finite_length_le ↥Q k).image (List.map Subtype.val) + apply hf.subset + rintro c ⟨hc,hQ⟩ + let d : List ↥Q := c.attach.map (fun q => ⟨q.val,hQ q.val q.property⟩) + refine ⟨d,?_,?_⟩ + · simpa only [d,List.length_map,List.length_attach,Set.mem_ofPred_eq] using hc + · simp [d,List.map_map] + +noncomputable def boundedTraceCodes (Q : Finset E) (k : ℕ) : Finset (List (ℕ × E)) := + (finite_bounded_lists ((Finset.Icc 1 k) ×ˢ Q) k).toFinset + +@[simp] theorem mem_boundedTraceCodes (Q : Finset E) (k : ℕ) (c : List (ℕ × E)) : + c ∈ boundedTraceCodes Q k ↔ c.length ≤ k ∧ ∀ q ∈ c, 1 ≤ q.1 ∧ q.1 ≤ k ∧ q.2 ∈ Q := by + simp [boundedTraceCodes,Finset.mem_product,and_assoc] + +theorem SpliceTrace.length_le (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) : c.length ≤ k-j := by + induction h with + | stop => simp + | step => simp only [List.length_cons]; omega + +theorem SpliceTrace.mem_boundedTraceCodes (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) (Q : Finset E) + (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) : c ∈ boundedTraceCodes Q k := by + rw [Percolation.mem_boundedTraceCodes] + refine ⟨(h.length_le G x η y k j ω ωf c).trans (Nat.sub_le ..),?_⟩ + intro q hq + obtain ⟨hj,hk,he,_⟩ := h.seam_data G x η y k j ω ωf c q hq + exact ⟨by omega,hk,hQ q.1 (by omega) hk he⟩ + + + +noncomputable def finiteTraceCodes (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω : Set E) (Q : Finset E) : Finset (List (ℕ × E)) := + (boundedTraceCodes Q k).filter (fun c => + SpliceTrace G x η y k j ω c (replaySplice G x η y c ω)) + +theorem mem_finiteTraceCodes_iff (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω : Set E) (Q : Finset E) (c : List (ℕ × E)) : + c ∈ finiteTraceCodes G x η y k j ω Q ↔ c ∈ boundedTraceCodes Q k ∧ + SpliceTrace G x η y k j ω c (replaySplice G x η y c ω) := by + simp [finiteTraceCodes] + + + +theorem finite_trace_seed_partition [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k M : ℕ) (Q : Finset E) + (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M) + (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) + (hfin : (cluster G ω x).Finite) : + let S := finiteTraceCodes G x η y k j ω Q + let A := fun c => {u : Fin k → unitInterval | FollowsContactRule G x η y + (chooseContact (finiteContactSeeds k u)) c ω} + (⋃ c ∈ S, A c) = Set.univ ∧ Set.PairwiseDisjoint (↑S) A := by + intro S A + constructor + · apply Set.eq_univ_of_forall + intro u + obtain ⟨c,ωf,ht,hr,_⟩ := exists_seeded_spliceTrace G hloc x η y k M hchain hcaps + (chooseContact (finiteContactSeeds k u)) (chooseContact_mem _) j hj ω hyj _ hfin (le_refl _) + have hc : c ∈ S := (mem_finiteTraceCodes_iff ..).mpr + ⟨ht.mem_boundedTraceCodes G x η y k j ω ωf c Q hQ, + (ht.replay_eq G x η y k j ω ωf c).symm ▸ ht⟩ + exact Set.mem_iUnion.mpr ⟨c,Set.mem_iUnion.mpr ⟨hc,hr⟩⟩ + · intro c hc d hd hcd + apply Set.disjoint_left.mpr + intro u huc hud + have ht := (mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc + have hs := (mem_finiteTraceCodes_iff G x η y k j ω Q d).mp hd + exact hcd (ht.2.seeded_unique G x η y k j ω _ _ c d hs.2 + (chooseContact (finiteContactSeeds k u)) huc hud).1 + + +theorem sum_finite_trace_probabilities [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k M : ℕ) (Q : Finset E) + (hQ : ∀ i, 1 ≤ i → i ≤ k → η i ⊆ (Q : Set E)) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M) + (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) + (hfin : (cluster G ω x).Finite) : + (∑ c ∈ finiteTraceCodes G x η y k j ω Q, + ∏ i : Fin k, (traceContactCount G η y (replaySplice G x η y c ω) x c (i.val+1):ℝ)⁻¹) = 1 := by + let S := finiteTraceCodes G x η y k j ω Q + let A := fun c => {u : Fin k → unitInterval | FollowsContactRule G x η y + (chooseContact (finiteContactSeeds k u)) c ω} + have hpart := finite_trace_seed_partition G hloc x η y k M Q hQ hchain hcaps j hj ω hyj hfin + have hm : ∀ c ∈ S, MeasurableSet (A c) := by + intro c hc + exact ((mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc).2.measurableSet_seed_event + G x η y k j ω _ c + have hsum : ∑ c ∈ S, volume (A c) = 1 := by + rw [← measure_biUnion_finset hpart.2 hm,hpart.1,measure_univ] + have hr := congrArg ENNReal.toReal hsum + rw [ENNReal.toReal_sum (fun c _ => measure_ne_top volume (A c)),ENNReal.toReal_one] at hr + rw [← hr] + apply Finset.sum_congr rfl + intro c hc + exact (((mem_finiteTraceCodes_iff G x η y k j ω Q c).mp hc).2.seed_probability + G hloc x η y k j ω _ c (fun i hi hik => (hcaps i (Finset.mem_Icc.mpr ⟨hi,hik⟩)).1)).symm + +end FiniteTraceDistribution +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteSpliceState +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem SpliceTrace.runMasks_execution (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) : + ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → + SpliceExecution G x (ω,θ) c (runMasks (replayMasks G x η y c ω) (ω,θ)) := by + induction h with + | stop => intro θ _; exact SpliceExecution.nil _ + | @step j i ω e a b c ωf hn hji hik hm hy he hab ha hb ht ih => + intro θ hθ + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let M := spliceMask G S B e + let ω' := spliceField G S B e ω (η i) + let θ' := Function.update θ i (exchangeOn M (θ i) ω) + have hθi := hθ i hji hik + have hstep : exchangeState M i (ω,θ) = (ω',θ') := by + apply Prod.ext + · change exchangeOn M ω (θ i) = exchangeOn M ω (η i) + rw [hθi] + · rfl + change SpliceExecution G x (ω,θ) ((i,e)::c) + (runMasks (replayMasks G x η y c ω') (exchangeState M i (ω,θ))) + rw [hstep] + refine SpliceExecution.cons (ω,θ) (ω',θ') _ (i,e) c ?_ ?_ + · refine ⟨y i,a,b,hy,?_,hab,ha,?_,?_⟩ + · simpa only [hθi] using he + · simpa only [hθi] using hb + · simpa only [hθi] using hstep.symm + · apply ih θ' + intro l hil hlk + rw [show θ' l = θ l from Function.update_of_ne (by omega) _ _] + exact hθ l (hji.trans hil) hlk + +abbrev FiniteSpliceData (Q : Finset E) (J : Finset ℕ) := + FiniteField Q × (↥J → FiniteField Q) + +def encodeFiniteSplice (Q : Finset E) (J : Finset ℕ) + (s : FiniteSpliceData Q J) : SpliceState E := + (finiteFieldSet Q s.1,finiteFieldFamily Q J s.2) + +theorem encodeFiniteSplice_injective (Q : Finset E) (J : Finset ℕ) : + Function.Injective (encodeFiniteSplice Q J) := by + intro a b he + exact Prod.ext (finiteFieldSet_injective Q (congrArg Prod.fst he)) + (finiteFieldFamily_injective Q J (congrArg Prod.snd he)) + +noncomputable def finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) : Finset (SpliceState E) := + Finset.univ.image (encodeFiniteSplice Q J) + +theorem spliceTupleWeight_encode (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (s : FiniteSpliceData Q J) : spliceTupleWeight Q J p (encodeFiniteSplice Q J s) = + finiteFieldWeight Q p s.1 * finiteFamilyWeight Q J p s.2 := by + simp only [spliceTupleWeight,encodeFiniteSplice,domainBits_finiteFieldSet, + prod_fieldFamilyWeight,finiteFieldWeight] + +theorem sum_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) (p : ℝ) : + ∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s = 1 := by + rw [finiteSpliceDomain,Finset.sum_image (encodeFiniteSplice_injective Q J).injOn] + simp only [spliceTupleWeight_encode,Fintype.sum_prod_type,← Finset.mul_sum, + sum_finiteFamilyWeight,mul_one,sum_finiteFieldWeight] + + +theorem mem_finiteSpliceDomain_iff (Q : Finset E) (J : Finset ℕ) (s : SpliceState E) : + s ∈ finiteSpliceDomain Q J ↔ s.1 ⊆ (Q : Set E) ∧ + (∀ i, s.2 i ⊆ (Q : Set E)) ∧ ∀ i ∉ J, s.2 i = ∅ := by + constructor + · intro hs + obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs + refine ⟨?_,?_,?_⟩ + · exact Finset.coe_subset.mpr (Finset.mem_powerset.mp a.1.property) + · intro i + by_cases hi : i ∈ J + · simpa only [encodeFiniteSplice,finiteFieldFamily,dite_eq_left hi,finiteFieldSet] using + Finset.coe_subset.mpr (Finset.mem_powerset.mp (a.2 ⟨i,hi⟩).property) + · simp [encodeFiniteSplice,finiteFieldFamily,hi] + · intro i hi + simp [encodeFiniteSplice,finiteFieldFamily,hi] + · rintro ⟨hω,hη,hz⟩ + let desc (ω : Set E) : FiniteField Q := ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ + have he (ω : Set E) (h : ω ⊆ (Q : Set E)) : finiteFieldSet Q (desc ω) = ω := by + ext e + simp only [finiteFieldSet,desc,Finset.mem_coe,mem_domainBits] + exact ⟨fun hh => hh.2,fun hh => ⟨h hh,hh⟩⟩ + refine Finset.mem_image.mpr ⟨(desc s.1,fun i => desc (s.2 i)),Finset.mem_univ _,?_⟩ + apply Prod.ext (he s.1 hω) + funext i + by_cases hi : i ∈ J + · simp only [encodeFiniteSplice,finiteFieldFamily,dite_eq_left hi,he _ (hη i)] + · simp only [encodeFiniteSplice,finiteFieldFamily,dite_eq_right hi,hz i hi] + +theorem exchangeState_mem_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) + (s : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J) (i : ℕ) (hi : i ∈ J) (M : Set E) : + exchangeState M i s ∈ finiteSpliceDomain Q J := by + obtain ⟨hω,hη,hz⟩ := (mem_finiteSpliceDomain_iff Q J s).mp hs + apply (mem_finiteSpliceDomain_iff Q J _).mpr + refine ⟨exchangeOn_subset M _ _ _ hω (hη i),?_,?_⟩ + · intro l + by_cases hli : l = i + · simpa only [hli,exchangeState_at] using exchangeOn_subset M _ _ _ (hη i) hω + · rw [exchangeState_away _ _ _ _ hli] + exact hη l + · intro l hl + have hli : l ≠ i := by intro he; subst l; exact hl hi + rw [exchangeState_away _ _ _ _ hli] + exact hz l hl + +theorem runMasks_mem_finiteSpliceDomain (Q : Finset E) (J : Finset ℕ) + (s : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J) (ms : List (ℕ × Set E)) + (hJ : ∀ q ∈ ms, q.1 ∈ J) : runMasks ms s ∈ finiteSpliceDomain Q J := by + induction ms generalizing s with + | nil => exact hs + | cons q ms ih => + apply ih _ (exchangeState_mem_finiteSpliceDomain Q J s hs q.1 (hJ q (by simp)) q.2) + exact fun q hq => hJ q (by simp [hq]) + +end FiniteSpliceState + +end Percolation + + +open MeasureTheory +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteSwitchDensity +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def finiteInverseLoad {I : Type*} [Fintype I] + (out : I → SpliceState E) (mass : I → ℝ) (t : SpliceState E) : ℝ := + ∑ a, if out a = t then mass a else 0 + +theorem finiteInverseLoad_nonneg {I : Type*} [Fintype I] + (out : I → SpliceState E) (mass : I → ℝ) (hm : ∀ a, 0 ≤ mass a) (t : SpliceState E) : + 0 ≤ finiteInverseLoad out mass t := by + apply Finset.sum_nonneg + intro a _ + split_ifs + · exact hm a + · exact le_refl 0 + + + +theorem finiteInverseLoad_le {I : Type*} [Fintype I] + (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) + (L : ℝ) (hL : 1 ≤ L) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (hir : Function.Injective (fun a => (inp a,steps a))) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) + (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ + (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) + (t : SpliceState E) : + finiteInverseLoad out (fun a => ∏ i : Fin k, + (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ + inverseCodeMass M L ^ k := by + let J := {a : I // out a = t} + have hr (a : J) (i : Fin k) : 0 < traceContactCount G (inp a.val).2 (y a.val) + (out a.val).1 x (steps a.val) (i.val+1) := by + have hh := ((htrace a.val).contact_weight_bound G hloc x (inp a.val).2 (y a.val) + k 0 M (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L hL + (hgood a.val) (i.val+1)).1 + omega + have hb := finite_inverse_contact_mass_le G hloc x z k M L hL (0 : unitInterval) ∅ + (fun a : J => inp a.val) (fun a : J => out a.val) (fun a : J => steps a.val) + (fun a : J => y a.val) + (fun a b he => Subtype.ext (hir he)) (fun a => htrace a.val) (fun a => hex a.val) + (fun a => hz a.val) (fun a => hfin a.val) (fun a => hgood a.val) + (fun _ _ => 0) hr {t} (fun a => by simpa only [Finset.mem_singleton] using a.property) + simp only [real_volume_contact_choice_cube _ _ (hr _),spliceTupleWeight,domainBits, + Finset.filter_empty,bernoulliWeight,Finset.card_empty,Nat.sub_self,pow_zero, + Finset.prod_const_one,mul_one,one_mul,Finset.sum_singleton] at hb + rw [finiteInverseLoad,← Finset.sum_filter] + rw [Finset.sum_subtype (p := fun a : I => out a = t) _ (by intro a; simp) _] + exact hb + + + +theorem finiteInverseLoad_density {I : Type*} [Fintype I] + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (mass : I → ℝ) (B : Finset (SpliceState E)) (hB : ∀ a, out a ∈ B) + (f : SpliceState E → ℝ) : + (∑ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) * mass a * f (out a)) = + ∑ t ∈ B, spliceTupleWeight Q (Finset.Icc 1 k) p t * finiteInverseLoad out mass t * f t := by + have hw (a : I) : spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) = + spliceTupleWeight Q (Finset.Icc 1 k) p (out a) := by + symm + apply (hex a).weight G x (inp a) (out a) (steps a) Q (Finset.Icc 1 k) _ p + intro q hq + have h := (htrace a).seam_data G x (inp a).2 (y a) k 0 (inp a).1 (out a).1 (steps a) q hq + exact Finset.mem_Icc.mpr ⟨h.1,h.2.1⟩ + simp only [finiteInverseLoad,Finset.mul_sum,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp only [mul_ite,mul_zero,ite_mul,zero_mul] + rw [Finset.sum_ite_eq,ite_eq_left (hB a),hw a] + +end FiniteSwitchDensity + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteForwardDensity +attribute [local instance] Classical.propDecidable Classical.decEq + + + +abbrev FiniteTraceIndex (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) := + (s : ↥A) × ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q) + +def traceIndexInput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) : SpliceState E := a.1.val + +def traceIndexCode (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) : List (ℕ × E) := a.2.val + +def traceIndexOutput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) : SpliceState E := + runMasks (replayMasks G x a.1.val.2 (y a.1.val) a.2.val a.1.val.1) a.1.val + +theorem traceIndex_valid (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) : + SpliceTrace G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 a.2.val + (traceIndexOutput G x k Q A y a).1 ∧ + SpliceExecution G x a.1.val a.2.val (traceIndexOutput G x k Q A y a) := by + have ht := ((mem_finiteTraceCodes_iff G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 Q a.2.val).mp + a.2.property).2 + have hf := ht.runMasks_first G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 _ a.2.val + a.1.val.2 (by intros; rfl) + refine ⟨?_,?_⟩ + · simpa only [traceIndexOutput,hf] using ht + · exact ht.runMasks_execution G x a.1.val.2 (y a.1.val) k 0 a.1.val.1 _ a.2.val + a.1.val.2 (by intros; rfl) + +theorem traceIndex_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) : + Function.Injective (fun a : FiniteTraceIndex G x k Q A y => + (traceIndexInput G x k Q A y a,traceIndexCode G x k Q A y a)) := by + rintro ⟨a,c⟩ ⟨b,d⟩ he + have hah : a = b := Subtype.ext (congrArg Prod.fst he) + subst b + have hcd : c = d := Subtype.ext (congrArg Prod.snd he) + subst d + rfl + +theorem traceIndexOutput_mem (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (a : FiniteTraceIndex G x k Q A y) : + traceIndexOutput G x k Q A y a ∈ finiteSpliceDomain Q (Finset.Icc 1 k) := by + apply runMasks_mem_finiteSpliceDomain Q (Finset.Icc 1 k) a.1.val (hA a.1.property) + intro q hq + have hmap : q.1 ∈ (replayMasks G x a.1.val.2 (y a.1.val) a.2.val a.1.val.1).map Prod.fst := + List.mem_map.mpr ⟨q,hq,rfl⟩ + rw [replayMasks_indices] at hmap + obtain ⟨r,hr,her⟩ := List.mem_map.mp hmap + have h := (traceIndex_valid G x k Q A y a).1.seam_data G x a.1.val.2 (y a.1.val) + k 0 a.1.val.1 _ a.2.val r hr + exact her ▸ Finset.mem_Icc.mpr ⟨h.1,h.2.1⟩ + + + +noncomputable def traceIndexMass (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (a : FiniteTraceIndex G x k Q A y) : ℝ := + ∏ i : Fin k, (traceContactCount G a.1.val.2 (y a.1.val) + (traceIndexOutput G x k Q A y a).1 x a.2.val (i.val+1):ℝ)⁻¹ + +noncomputable def finiteForwardLoad (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) (t : SpliceState E) : ℝ := + finiteInverseLoad (traceIndexOutput G x k Q A y) (traceIndexMass G x k Q A y) t + + + +theorem finiteForwardLoad_bounds (G : BondGraph V E) (hloc : LocallyFinite G) + (x z : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hz : ∀ s ∈ A, y s k = z) + (hgood : ∀ s ∈ A, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y s i)).Finite ∧ + (cluster G (s.2 i) (y s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y s i) L) + (t : SpliceState E) : + 0 ≤ finiteForwardLoad G x k Q A y t ∧ finiteForwardLoad G x k Q A y t ≤ inverseCodeMass M L ^ k := by + constructor + · exact finiteInverseLoad_nonneg _ _ (by intro a; unfold traceIndexMass; positivity) t + · apply finiteInverseLoad_le G hloc x z k M L hL + (traceIndexInput G x k Q A y) (traceIndexOutput G x k Q A y) (traceIndexCode G x k Q A y) + (fun a => y a.1.val) (traceIndex_injective G x k Q A y) + (fun a => (traceIndex_valid G x k Q A y a).1) + (fun a => (traceIndex_valid G x k Q A y a).2) (fun a => hz a.1.val a.1.property) + _ (fun a => hgood a.1.val a.1.property) t + intro a + have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp + (traceIndexOutput_mem G x k Q A y hA a) + exact cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x + + + +theorem finiteForwardLoad_mean [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hy : ∀ s ∈ A, y s 0 ∈ cluster G s.1 x) + (hchain : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y s i) (y s (i-1))) + (hcaps : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, (cluster G (s.2 i) (y s i)).Finite ∧ + (cluster G (s.2 i) (y s i)).ncard ≤ M) : + (∑ t ∈ finiteSpliceDomain Q (Finset.Icc 1 k), + spliceTupleWeight Q (Finset.Icc 1 k) p t * finiteForwardLoad G x k Q A y t) = + ∑ s ∈ A, spliceTupleWeight Q (Finset.Icc 1 k) p s := by + have hd := finiteInverseLoad_density G x k Q p + (traceIndexInput G x k Q A y) (traceIndexOutput G x k Q A y) (traceIndexCode G x k Q A y) + (fun a => y a.1.val) (fun a => (traceIndex_valid G x k Q A y a).1) + (fun a => (traceIndex_valid G x k Q A y a).2) + (traceIndexMass G x k Q A y) (finiteSpliceDomain Q (Finset.Icc 1 k)) + (traceIndexOutput_mem G x k Q A y hA) (fun _ => 1) + simp only [mul_one] at hd + unfold finiteForwardLoad + rw [← hd,Fintype.sum_sigma] + rw [← Finset.sum_coe_sort A (fun s => spliceTupleWeight Q (Finset.Icc 1 k) p s)] + apply Finset.sum_congr rfl + intro s _ + change (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), + spliceTupleWeight Q (Finset.Icc 1 k) p s.val * traceIndexMass G x k Q A y ⟨s,c⟩) = _ + rw [← Finset.mul_sum] + suffices hm : (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), + traceIndexMass G x k Q A y ⟨s,c⟩) = 1 by rw [hm,mul_one] + have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s.val).mp (hA s.property) + have hn := sum_finite_trace_probabilities G hloc x s.val.2 (y s.val) k M Q + (fun i _ _ => hs.2.1 i) (hchain s.val s.property) (hcaps s.val s.property) + 0 (Nat.zero_le _) s.val.1 (hy s.val s.property) + (cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x) + rw [← Finset.sum_coe_sort (finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q)] at hn + rw [← hn] + apply Finset.sum_congr rfl + intro c _ + have ht := ((mem_finiteTraceCodes_iff G x s.val.2 (y s.val) k 0 s.val.1 Q c.val).mp c.property).2 + have hf := ht.runMasks_first G x s.val.2 (y s.val) k 0 s.val.1 _ c.val s.val.2 (by intros; rfl) + simp only [traceIndexMass,traceIndexOutput,hf] + +end FiniteForwardDensity + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section ContactIntegratedSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_event_mass_le {Ω I : Type*} [MeasurableSpace Ω] [Fintype I] + (μ : Measure Ω) [IsProbabilityMeasure μ] (P : I → Set Ω) + (hm : ∀ a, MeasurableSet (P a)) (w : I → ℝ) (B : ℝ) + (hpoint : ∀ u, (∑ a, if u ∈ P a then w a else 0) ≤ B) : + (∑ a, w a * μ.real (P a)) ≤ B := by + let f (a : I) : Ω → ℝ := (P a).indicator (fun _ => w a) + have hf : ∀ a, Integrable (f a) μ := fun a => (integrable_const _).indicator (hm a) + have hi := integral_mono (integrable_finsetSum _ (fun a _ => hf a)) + (integrable_const B) (fun u => hpoint u) + change (∫ u, ∑ a, f a u ∂μ) ≤ (∫ _ : Ω, B ∂μ) at hi + rw [integral_finsetSum _ (fun a _ => hf a)] at hi + simpa only [f,integral_indicator_const _ (hm _),smul_eq_mul,mul_comm, + integral_const,probReal_univ,one_smul,mul_one] using hi + + + +theorem finite_separated_contact_second_moment_le {I : Type*} [Fintype I] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (success₁ success₂ : (ℕ → Set E) → Prop) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ + (cluster G (ω₁ a) x).ncard < 2*n) + (hcap₁ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₁ a i) (y₁ (η₁ a) i)).Finite) + (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ + (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) + (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) + (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) + (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) + (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) + (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * + (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * + (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹)) ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₁ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty) * + finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₂ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty) else 0) := by + let S := Fin k → unitInterval + let μ : Measure (S × S) := (volume : Measure S).prod volume + let P₁ (a : I) : Set S := {u | FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) + (chooseContact (finiteContactSeeds k u)) (c₁ a) (ω₁ a)} + let P₂ (a : I) : Set S := {u | FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) + (chooseContact (finiteContactSeeds k u)) (c₂ a) (ω₂ a)} + let w (a : I) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) + have hm₁ (a : I) : MeasurableSet (P₁ a) := + (h₁ a).measurableSet_seed_event G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) + have hm₂ (a : I) : MeasurableSet (P₂ a) := + (h₂ a).measurableSet_seed_event G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) + have hp (a : I) : μ.real (P₁ a ×ˢ P₂ a) = + (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * + (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹) := by + rw [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, + (h₁ a).seed_probability G hloc x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) (hcap₁ a), + (h₂ a).seed_probability G hloc x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) (fun i hi hik => (hcap₂ a i hi hik).1)] + conv_lhs => arg 2; ext a; rw [mul_assoc,← hp a] + apply finite_event_mass_le μ (fun a => P₁ a ×ˢ P₂ a) (fun a => (hm₁ a).prod (hm₂ a)) w + intro u + let J := {a : I // u ∈ P₁ a ×ˢ P₂ a} + have hb := finite_separated_second_moment_le G x k n M p Q + (fun a : J => η₁ a.val) (fun a : J => η₂ a.val) y₁ y₂ success₁ success₂ + (chooseContact (finiteContactSeeds k u.1)) (chooseContact (finiteContactSeeds k u.2)) + (fun a : J => ω₁ a.val) (fun a : J => ω₂ a.val) (fun a : J => ωf a.val) + (fun a : J => c₁ a.val) (fun a : J => c₂ a.val) + (fun _ _ he => Subtype.ext (hir he)) (fun a => h₁ a.val) (fun a => h₂ a.val) + (fun a => hc₁ a.val) (fun a => hc₂ a.val) (fun a => hsep a.val) + (fun a => a.property.1) (fun a => a.property.2) + (fun a => hbin a.val) (fun a => hcap₂ a.val) (fun a => hsc₁ a.val) (fun a => hsc₂ a.val) + (fun a => hsω₁ a.val) (fun a => hsω₂ a.val) (fun a => hsη₁ a.val) (fun a => hsη₂ a.val) + (fun a => hz₁ a.val) (fun a => hz₂ a.val) + convert hb using 1 + have he := Finset.sum_subtype (p := fun a => u ∈ P₁ a ×ˢ P₂ a) (F := inferInstance) (Finset.univ.filter (fun a => u ∈ P₁ a ×ˢ P₂ a)) + (by intro a; simp) w + simpa [Finset.sum_filter,w] using he + +end ContactIntegratedSecondMoment + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteRootLoad +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def finiteRootLoad (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (f : SpliceState E → ℝ) (ω : FiniteField Q) : ℝ := + ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * + f (finiteFieldSet Q ω,finiteFieldFamily Q J η) + +theorem finiteRootLoad_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (f : SpliceState E → ℝ) (hf : ∀ s ∈ finiteSpliceDomain Q J, 0 ≤ f s) + (ω : FiniteField Q) : 0 ≤ finiteRootLoad Q J p f ω := by + apply Finset.sum_nonneg + intro η _ + apply mul_nonneg (finiteFamilyWeight_nonneg Q J p η) + exact hf _ (Finset.mem_image.mpr ⟨(ω,η),Finset.mem_univ _,rfl⟩) + +theorem finiteRootLoad_le (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (f : SpliceState E → ℝ) (C : ℝ) + (hf : ∀ s ∈ finiteSpliceDomain Q J, f s ≤ C) + (ω : FiniteField Q) : finiteRootLoad Q J p f ω ≤ C := by + calc + _ ≤ ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * C := by + apply Finset.sum_le_sum + intro η _ + apply mul_le_mul_of_nonneg_left _ (finiteFamilyWeight_nonneg Q J p η) + exact hf _ (Finset.mem_image.mpr ⟨(ω,η),Finset.mem_univ _,rfl⟩) + _ = C := by rw [← Finset.sum_mul,sum_finiteFamilyWeight,one_mul] + + +theorem finiteRootLoad_mean (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (f : SpliceState E → ℝ) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * finiteRootLoad Q J p f ω) = + ∑ s ∈ finiteSpliceDomain Q J, spliceTupleWeight Q J p s * f s := by + rw [finiteSpliceDomain,Finset.sum_image (encodeFiniteSplice_injective Q J).injOn, + Fintype.sum_prod_type] + simp only [spliceTupleWeight,finiteRootLoad,Finset.mul_sum,encodeFiniteSplice, + domainBits_finiteFieldSet,prod_fieldFamilyWeight,finiteFieldWeight,mul_assoc] + + + +theorem finiteRootLoad_second_moment (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (f₁ f₂ : SpliceState E → ℝ) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteRootLoad Q J₁ p f₁ ω * finiteRootLoad Q J₂ p f₂ ω) = + ∑ s : FiniteJointData Q J₁ J₂, jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) * + f₁ (finiteFieldSet Q s.1,finiteFieldFamily Q J₁ s.2.1) * + f₂ (finiteFieldSet Q s.1,finiteFieldFamily Q J₂ s.2.2) := by + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro ω _ + rw [Fintype.sum_prod_type] + simp only [finiteRootLoad,Finset.mul_sum,Finset.sum_mul,jointTupleWeight_encode] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro η₁ _ + apply Finset.sum_congr rfl + intro η₂ _ + ring + + +theorem finiteForwardRootLoad_bounds (G : BondGraph V E) (hloc : LocallyFinite G) + (x z : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) (p : unitInterval) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hz : ∀ s ∈ A, y s k = z) + (hgood : ∀ s ∈ A, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y s i)).Finite ∧ + (cluster G (s.2 i) (y s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y s i) L) + (ω : FiniteField Q) : + 0 ≤ finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω ∧ + finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω ≤ inverseCodeMass M L ^ k := by + have hb := finiteForwardLoad_bounds G hloc x z k M L hL Q A y hA hz hgood + exact ⟨finiteRootLoad_nonneg _ _ p _ (fun s _ => (hb s).1) _, + finiteRootLoad_le _ _ p _ _ (fun s _ => (hb s).2) _⟩ + + + +theorem finiteForwardRootLoad_mean [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) + (hA : A ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hy : ∀ s ∈ A, y s 0 ∈ cluster G s.1 x) + (hchain : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y s i) (y s (i-1))) + (hcaps : ∀ s ∈ A, ∀ i ∈ Finset.Icc 1 k, (cluster G (s.2 i) (y s i)).Finite ∧ + (cluster G (s.2 i) (y s i)).ncard ≤ M) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteRootLoad Q (Finset.Icc 1 k) p (finiteForwardLoad G x k Q A y) ω) = + ∑ s ∈ A, spliceTupleWeight Q (Finset.Icc 1 k) p s := by + rw [finiteRootLoad_mean] + exact finiteForwardLoad_mean G hloc x k M Q p A y hA hy hchain hcaps + +end FiniteRootLoad + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FinitePairLoad +attribute [local instance] Classical.propDecidable Classical.decEq + + +def pairSpliceOutput (s t : SpliceState E) : JointSpliceState E := (s.1,s.2,t.2) + +theorem pairSpliceOutput_mem (Q : Finset E) (J₁ J₂ : Finset ℕ) + (s t : SpliceState E) (hs : s ∈ finiteSpliceDomain Q J₁) + (ht : t ∈ finiteSpliceDomain Q J₂) : + pairSpliceOutput s t ∈ finiteJointDomain Q J₁ J₂ := by + have h₁ := (mem_finiteSpliceDomain_iff Q J₁ s).mp hs + have h₂ := (mem_finiteSpliceDomain_iff Q J₂ t).mp ht + exact mem_finiteJointDomain_of_support Q J₁ J₂ _ h₁.1 h₁.2.1 h₂.2.1 h₁.2.2 h₂.2.2 + + +theorem finiteInverseLoad_mul {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] + (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) + (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (t : JointSpliceState E) : + finiteInverseLoad out₁ m₁ (t.1,t.2.1) * finiteInverseLoad out₂ m₂ (t.1,t.2.2) = + ∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ pairSpliceOutput (out₁ a) (out₂ b) = t + then m₁ a * m₂ b else 0 := by + simp only [finiteInverseLoad,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + have he : (out₁ a = (t.1,t.2.1) ∧ out₂ b = (t.1,t.2.2)) ↔ + ((out₁ a).1 = (out₂ b).1 ∧ pairSpliceOutput (out₁ a) (out₂ b) = t) := by + cases h₁ : out₁ a with | mk r₁ u₁ => + cases h₂ : out₂ b with | mk r₂ u₂ => + rcases t with ⟨r,u,v⟩ + simpa [pairSpliceOutput,Prod.mk.injEq] using + (show (r₁ = r ∧ u₁ = u) ∧ (r₂ = r ∧ u₂ = v) ↔ + r₁ = r₂ ∧ r₁ = r ∧ u₁ = u ∧ u₂ = v from by aesop) + simp only [← he] + split_ifs <;> simp_all + + + +theorem finiteRootLoad_pair_expansion {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] + (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) + (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) + (hs₁ : ∀ a, out₁ a ∈ finiteSpliceDomain Q J₁) + (hs₂ : ∀ b, out₂ b ∈ finiteSpliceDomain Q J₂) : + (∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteRootLoad Q J₁ p (finiteInverseLoad out₁ m₁) ω * + finiteRootLoad Q J₂ p (finiteInverseLoad out₂ m₂) ω) = + ∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 then + jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0 := by + rw [finiteRootLoad_second_moment] + have hdom : (∑ s : FiniteJointData Q J₁ J₂, + jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) * + finiteInverseLoad out₁ m₁ ((encodeFiniteJoint Q J₁ J₂ s).1,(encodeFiniteJoint Q J₁ J₂ s).2.1) * + finiteInverseLoad out₂ m₂ ((encodeFiniteJoint Q J₁ J₂ s).1,(encodeFiniteJoint Q J₁ J₂ s).2.2)) = + ∑ t ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p t * + finiteInverseLoad out₁ m₁ (t.1,t.2.1) * finiteInverseLoad out₂ m₂ (t.1,t.2.2) := by + rw [finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn] + apply hdom.trans + simp only [mul_assoc,finiteInverseLoad_mul,Finset.mul_sum,mul_ite,mul_zero] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + by_cases he : (out₁ a).1 = (out₂ b).1 + · simp only [he,true_and,ite_true] + rw [Finset.sum_ite_eq,ite_eq_left (pairSpliceOutput_mem Q J₁ J₂ _ _ (hs₁ a) (hs₂ b))] + · simp [he] + +theorem traceIndex_output_code_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : Finset (SpliceState E)) (y : SpliceState E → ℕ → V) : + Function.Injective (fun a : FiniteTraceIndex G x k Q A y => + (traceIndexOutput G x k Q A y a,traceIndexCode G x k Q A y a)) := by + intro a b he + have hc : traceIndexCode G x k Q A y a = traceIndexCode G x k Q A y b := congrArg Prod.snd he + have ho : traceIndexOutput G x k Q A y a = traceIndexOutput G x k Q A y b := congrArg Prod.fst he + apply traceIndex_injective G x k Q A y + apply Prod.ext + · apply SpliceExecution.input_unique G x _ _ _ (traceIndexCode G x k Q A y a) + (traceIndex_valid G x k Q A y a).2 + change SpliceExecution G x b.1.val (traceIndexCode G x k Q A y a) (traceIndexOutput G x k Q A y a) + rw [hc,ho] + exact (traceIndex_valid G x k Q A y b).2 + · exact hc + +end FinitePairLoad + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WeightedJointMass +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem jointRestored_injective {I : Type*} + (G : BondGraph V E) (x : V) (k : ℕ) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (choose₁ choose₂ : ℕ → Set E → E) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) + (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) + : Function.Injective (fun a => jointRestored G x (η₁ a) (η₂ a) + (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a)) := by + let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) + let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) + change Function.Injective rest + intro a b he + have hη₁ : η₁ a = η₁ b := congrArg (fun s : JointSpliceState E => s.2.1) he + have hη₂ : η₂ a = η₂ b := congrArg (fun s : JointSpliceState E => s.2.2) he + have gb₁ : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ b) (c₁ b) (ωf b) := by + rw [hη₁]; exact h₁ b + have gb₂ : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ b) (c₂ b) (ωf b) := by + rw [hη₂]; exact h₂ b + have grb₁ : FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ b) (ω₁ b) := by + rw [hη₁]; exact hr₁ b + have grb₂ : FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ b) (ω₂ b) := by + rw [hη₂]; exact hr₂ b + have hfield : exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ a) (ω₂ a))) (ω₁ a) (ω₂ a) = + exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ b) (ω₂ b))) (ω₁ b) (ω₂ b) := by + have hh := congrArg Prod.fst he + simpa only [rest,jointRestored,← hη₂] using hh + obtain ⟨hcode₁,hcode₂,hfieldf,haux₁,haux₂⟩ := joint_restore_seeded_unique G x + (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) choose₁ choose₂ k 0 0 + (ω₁ a) (ω₂ a) (ωf a) (ω₁ b) (ω₂ b) (ωf b) + (c₁ a) (c₂ a) (c₁ b) (c₂ b) (h₁ a) (h₂ a) gb₁ gb₂ + (hc₁ a) (hc₂ a) (hc₁ b) (hc₂ b) (hsep a) (hsep b) + (hr₁ a) (hr₂ a) grb₁ grb₂ hfield + have hout : out a = out b := by + apply Prod.ext hfieldf + apply Prod.ext + · simpa only [out,jointOutput,hη₁] using haux₁ + · simpa only [out,jointOutput,hη₂] using haux₂ + exact hir (Prod.ext hout (Prod.ext hcode₁ hcode₂)) + + + +theorem finite_joint_weighted_mass_le {I : Type*} [Fintype I] + (G : BondGraph V E) (x : V) (k : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (choose₁ choose₂ : ℕ → Set E → E) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) + (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) + (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) + (B : Finset (JointSpliceState E)) + (hB : ∀ a, jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ + ∑ s ∈ B, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s * m₁ s.2.1 * m₂ s.2.2 := by + let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) + let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) + have hinj : Function.Injective rest := jointRestored_injective G x k η₁ η₂ y₁ y₂ choose₁ choose₂ + ω₁ ω₂ ωf c₁ c₂ hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ + have hw : ∀ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (out a) = + jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (rest a) := by + intro a + apply (h₁ a).joint_weight G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) k 0 0 + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hsep a) Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + · intro q hq + have hr := (h₁ a).seam_data G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) q hq + exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ + · intro q hq + have hr := (h₂ a).seam_data G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) q hq + exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ + change (∑ a, jointTupleWeight Q _ _ p (out a) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ _ + simp_rw [hw] + change (∑ a, jointTupleWeight Q _ _ p (rest a) * m₁ (rest a).2.1 * m₂ (rest a).2.2) ≤ _ + rw [← Finset.sum_image (f := fun s : JointSpliceState E => + jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s * m₁ s.2.1 * m₂ s.2.2) hinj.injOn] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro s hs + obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs + exact hB a + · intro s _ _ + exact mul_nonneg (mul_nonneg (jointTupleWeight_nonneg Q _ _ p s) (hm₁ _)) (hm₂ _) + +end WeightedJointMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteFamilyIntegral +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def finiteFamilyIntegral (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (f : (ℕ → Set E) → ℝ) : ℝ := + ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * f (finiteFieldFamily Q J η) + +theorem finiteFamilyIntegral_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (f : (ℕ → Set E) → ℝ) (hf : ∀ η, 0 ≤ f η) : 0 ≤ finiteFamilyIntegral Q J p f := by + exact Finset.sum_nonneg fun η _ => mul_nonneg (finiteFamilyWeight_nonneg Q J p η) (hf _) + +theorem finiteFamilyIntegral_mono (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (f g : (ℕ → Set E) → ℝ) (hfg : ∀ η, f η ≤ g η) : + finiteFamilyIntegral Q J p f ≤ finiteFamilyIntegral Q J p g := by + exact Finset.sum_le_sum fun η _ => mul_le_mul_of_nonneg_left (hfg _) (finiteFamilyWeight_nonneg Q J p η) + +theorem finiteFamilyIntegral_const (Q : Finset E) (J : Finset ℕ) (p c : ℝ) : + finiteFamilyIntegral Q J p (fun _ => c) = c := by + rw [finiteFamilyIntegral,← Finset.sum_mul,sum_finiteFamilyWeight,one_mul] + +theorem finiteFamilyIntegral_sum {I : Type*} (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (S : Finset I) (f : I → (ℕ → Set E) → ℝ) : + finiteFamilyIntegral Q J p (fun η => ∑ i ∈ S, f i η) = + ∑ i ∈ S, finiteFamilyIntegral Q J p (f i) := by + simp only [finiteFamilyIntegral,Finset.mul_sum] + exact Finset.sum_comm + + +theorem finiteJointDomain_integral_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (f₁ f₂ : Set E → (ℕ → Set E) → ℝ) : + (∑ s ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p s * f₁ s.1 s.2.1 * f₂ s.1 s.2.2) = + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + finiteFamilyIntegral Q J₁ p (f₁ (finiteFieldSet Q ω)) * + finiteFamilyIntegral Q J₂ p (f₂ (finiteFieldSet Q ω)) := by + rw [finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn] + simp only [jointTupleWeight_encode] + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro ω _ + rw [Fintype.sum_prod_type] + simp only [finiteFamilyIntegral,Finset.mul_sum,Finset.sum_mul,encodeFiniteJoint] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro η₂ _ + apply Finset.sum_congr rfl + intro η₁ _ + ring + +theorem finiteJointDomain_weighted_event_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (P : Set E → Prop) (H₁ H₂ : Set E → (ℕ → Set E) → Prop) + (m₁ m₂ : (ℕ → Set E) → ℝ) : + (∑ s ∈ (finiteJointDomain Q J₁ J₂).filter (fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2), + jointTupleWeight Q J₁ J₂ p s * m₁ s.2.1 * m₂ s.2.2) = + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if P (finiteFieldSet Q ω) then + finiteFamilyIntegral Q J₁ p (fun η => if H₁ (finiteFieldSet Q ω) η then m₁ η else 0) * + finiteFamilyIntegral Q J₂ p (fun η => if H₂ (finiteFieldSet Q ω) η then m₂ η else 0) else 0) := by + rw [Finset.sum_filter] + have he : (∑ s ∈ finiteJointDomain Q J₁ J₂, + if P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 then + jointTupleWeight Q J₁ J₂ p s * m₁ s.2.1 * m₂ s.2.2 else 0) = + ∑ s ∈ finiteJointDomain Q J₁ J₂, jointTupleWeight Q J₁ J₂ p s * + (if P s.1 ∧ H₁ s.1 s.2.1 then m₁ s.2.1 else 0) * + (if H₂ s.1 s.2.2 then m₂ s.2.2 else 0) := by + apply Finset.sum_congr rfl + intro s _ + split_ifs <;> simp_all + rw [he,finiteJointDomain_integral_factor Q J₁ J₂ p + (fun ω η => if P ω ∧ H₁ ω η then m₁ η else 0) + (fun ω η => if H₂ ω η then m₂ η else 0)] + apply Finset.sum_congr rfl + intro ω _ + by_cases hP : P (finiteFieldSet Q ω) + · simp only [hP,true_and,ite_true,mul_assoc] + · simp [hP,finiteFamilyIntegral] + +end FiniteFamilyIntegral + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WeightedSeparatedSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_separated_weighted_second_moment_le {I : Type*} [Fintype I] + (G : BondGraph V E) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (success₁ success₂ : (ℕ → Set E) → Prop) + (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) + (choose₁ choose₂ : ℕ → Set E → E) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) + (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) + (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ + (cluster G (ω₁ a) x).ncard < 2*n) + (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ + (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) + (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) + (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) + (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) + (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) + (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a)) ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₁ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₂ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by + let J := Finset.Icc 1 k + let P (ω : Set E) := (cluster G ω x).Finite ∧ n-k*M ≤ (cluster G ω x).ncard ∧ + (cluster G ω x).ncard < 2*n + let H₁ (ω : Set E) (η : ℕ → Set E) := success₁ η ∧ + (cluster G ω x ∩ trajectoryUnion G η (y₁ η) k).Nonempty + let H₂ (ω : Set E) (η : ℕ → Set E) := success₂ η ∧ + (cluster G ω x ∩ trajectoryUnion G η (y₂ η) k).Nonempty + let B := (finiteJointDomain Q J J).filter fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 + have hB (a : I) : jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B := by + apply Finset.mem_filter.mpr + refine ⟨mem_finiteJointDomain_of_support Q J J _ + (exchangeOn_subset _ _ _ _ (hsω₁ a) (hsω₂ a)) (hsη₁ a) (hsη₂ a) (hz₁ a) (hz₂ a),?_⟩ + have hroot := (h₁ a).joint_restored_size G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + k 0 0 n M (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) + (hbin a).1 (hbin a).2.1 (hbin a).2.2 (hcap₂ a) + have hhits := (h₁ a).joint_trajectory_hits G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + k 0 0 (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) + exact ⟨hroot,⟨hsc₁ a,hhits.1⟩,hsc₂ a,hhits.2⟩ + have h := finite_joint_weighted_mass_le G x k p Q η₁ η₂ y₁ y₂ choose₁ choose₂ ω₁ ω₂ ωf c₁ c₂ + hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ m₁ m₂ hm₁ hm₂ B hB + apply h.trans_eq + convert finiteJointDomain_weighted_event_factor Q J J p P H₁ H₂ m₁ m₂ using 1 <;> + simp only [B, J, P, H₁, H₂] + apply Finset.sum_congr rfl + intro ω _ + apply congrArg (fun z : ℝ => finiteFieldWeight Q p ω * z) + split_ifs + · apply congrArg₂ (· * ·) + · apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) + funext η + split_ifs <;> rfl + · apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) + funext η + split_ifs <;> rfl + · rfl + +end WeightedSeparatedSecondMoment + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section WeightedContactSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_separated_weighted_contact_second_moment_le {I : Type*} [Fintype I] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (success₁ success₂ : (ℕ → Set E) → Prop) + (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ + (cluster G (ω₁ a) x).ncard < 2*n) + (hcap₁ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₁ a i) (y₁ (η₁ a) i)).Finite) + (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ + (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) + (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) + (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) + (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) + (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) + (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a) * + (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * + (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹)) ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₁ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if success₂ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by + let S := Fin k → unitInterval + let μ : Measure (S × S) := (volume : Measure S).prod volume + let P₁ (a : I) : Set S := {u | FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) + (chooseContact (finiteContactSeeds k u)) (c₁ a) (ω₁ a)} + let P₂ (a : I) : Set S := {u | FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) + (chooseContact (finiteContactSeeds k u)) (c₂ a) (ω₂ a)} + let w (a : I) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a)) * m₁ (η₁ a) * m₂ (η₂ a) + have hmeas₁ (a : I) : MeasurableSet (P₁ a) := + (h₁ a).measurableSet_seed_event G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) + have hmeas₂ (a : I) : MeasurableSet (P₂ a) := + (h₂ a).measurableSet_seed_event G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) + have hp (a : I) : μ.real (P₁ a ×ˢ P₂ a) = + (∏ i : Fin k, (traceContactCount G (η₁ a) (y₁ (η₁ a)) (ωf a) x (c₁ a) (i.val+1):ℝ)⁻¹) * + (∏ i : Fin k, (traceContactCount G (η₂ a) (y₂ (η₂ a)) (ωf a) x (c₂ a) (i.val+1):ℝ)⁻¹) := by + rw [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, + (h₁ a).seed_probability G hloc x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) (hcap₁ a), + (h₂ a).seed_probability G hloc x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) (fun i hi hik => (hcap₂ a i hi hik).1)] + conv_lhs => arg 2; ext a; rw [mul_assoc,← hp a] + apply finite_event_mass_le μ (fun a => P₁ a ×ˢ P₂ a) (fun a => (hmeas₁ a).prod (hmeas₂ a)) w + intro u + let J := {a : I // u ∈ P₁ a ×ˢ P₂ a} + have hb := finite_separated_weighted_second_moment_le G x k n M p Q + (fun a : J => η₁ a.val) (fun a : J => η₂ a.val) y₁ y₂ success₁ success₂ m₁ m₂ hm₁ hm₂ + (chooseContact (finiteContactSeeds k u.1)) (chooseContact (finiteContactSeeds k u.2)) + (fun a : J => ω₁ a.val) (fun a : J => ω₂ a.val) (fun a : J => ωf a.val) + (fun a : J => c₁ a.val) (fun a : J => c₂ a.val) + (fun _ _ he => Subtype.ext (hir he)) (fun a => h₁ a.val) (fun a => h₂ a.val) + (fun a => hc₁ a.val) (fun a => hc₂ a.val) (fun a => hsep a.val) + (fun a => a.property.1) (fun a => a.property.2) + (fun a => hbin a.val) (fun a => hcap₂ a.val) (fun a => hsc₁ a.val) (fun a => hsc₂ a.val) + (fun a => hsω₁ a.val) (fun a => hsω₂ a.val) (fun a => hsη₁ a.val) (fun a => hsη₂ a.val) + (fun a => hz₁ a.val) (fun a => hz₂ a.val) + convert hb using 1 + have he := Finset.sum_subtype (p := fun a => u ∈ P₁ a ×ˢ P₂ a) (F := inferInstance) (Finset.univ.filter (fun a => u ∈ P₁ a ×ˢ P₂ a)) + (by intro a; simp) w + simpa [Finset.sum_filter,w] using he + +end WeightedContactSecondMoment + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/ReferenceLaws.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/ReferenceLaws.lean index b714cd9a0606301b8d8089e2aadc88c7ca316518..4f24a3671f96dee3c1f403aaad8fdf0548a99a22 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/ReferenceLaws.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/ReferenceLaws.lean @@ -1,1200 +1,1200 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.Replay - -namespace OAI - -/-! Reference Laws for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteJointMass -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def jointOutput (G : BondGraph V E) (x : V) (η₁ η₂ : ℕ → Set E) - (y₁ y₂ : ℕ → V) (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) : JointSpliceState E := - (ωf,(runMasks (replayMasks G x η₁ y₁ c₁ ω₁) (ω₁,η₁)).2, - (runMasks (replayMasks G x η₂ y₂ c₂ ω₂) (ω₂,η₂)).2) - -def jointRestored (G : BondGraph V E) (x : V) (η₁ η₂ : ℕ → Set E) - (y₂ : ℕ → V) (ω₁ ω₂ : Set E) (c₂ : List (ℕ × E)) : JointSpliceState E := - (exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂,η₁,η₂) - - - -theorem finite_joint_mass_le {I : Type*} [Fintype I] - (G : BondGraph V E) (x : V) (k : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (choose₁ choose₂ : ℕ → Set E → E) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) - (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) - (B : Finset (JointSpliceState E)) - (hB : ∀ a, jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a))) ≤ - ∑ s ∈ B, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s := by - let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) - let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) - have hinj : Function.Injective rest := by - intro a b he - have hη₁ : η₁ a = η₁ b := congrArg (fun s : JointSpliceState E => s.2.1) he - have hη₂ : η₂ a = η₂ b := congrArg (fun s : JointSpliceState E => s.2.2) he - have gb₁ : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ b) (c₁ b) (ωf b) := by - rw [hη₁]; exact h₁ b - have gb₂ : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ b) (c₂ b) (ωf b) := by - rw [hη₂]; exact h₂ b - have grb₁ : FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ b) (ω₁ b) := by - rw [hη₁]; exact hr₁ b - have grb₂ : FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ b) (ω₂ b) := by - rw [hη₂]; exact hr₂ b - have hfield : exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ a) (ω₂ a))) (ω₁ a) (ω₂ a) = - exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ b) (ω₂ b))) (ω₁ b) (ω₂ b) := by - have hh := congrArg Prod.fst he - simpa only [rest,jointRestored,← hη₂] using hh - obtain ⟨hcode₁,hcode₂,hfieldf,haux₁,haux₂⟩ := joint_restore_seeded_unique G x - (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) choose₁ choose₂ k 0 0 - (ω₁ a) (ω₂ a) (ωf a) (ω₁ b) (ω₂ b) (ωf b) - (c₁ a) (c₂ a) (c₁ b) (c₂ b) (h₁ a) (h₂ a) gb₁ gb₂ - (hc₁ a) (hc₂ a) (hc₁ b) (hc₂ b) (hsep a) (hsep b) - (hr₁ a) (hr₂ a) grb₁ grb₂ hfield - have hout : out a = out b := by - apply Prod.ext hfieldf - apply Prod.ext - · simpa only [out,jointOutput,hη₁] using haux₁ - · simpa only [out,jointOutput,hη₂] using haux₂ - exact hir (Prod.ext hout (Prod.ext hcode₁ hcode₂)) - have hw : ∀ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (out a) = - jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (rest a) := by - intro a - apply (h₁ a).joint_weight G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) k 0 0 - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hsep a) Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - · intro q hq - have hr := (h₁ a).seam_data G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) q hq - exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ - · intro q hq - have hr := (h₂ a).seam_data G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) q hq - exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ - change (∑ a, jointTupleWeight Q _ _ p (out a)) ≤ _ - simp_rw [hw] - rw [← Finset.sum_image hinj.injOn] - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro s hs - obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs - exact hB a - · intro s _ _ - exact jointTupleWeight_nonneg Q _ _ p s - -end FiniteJointMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TrajectorySupport -attribute [local instance] Classical.propDecidable Classical.decEq - - -def trajectoryUnion (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) : ℕ → Set V - | 0 => ∅ - | k+1 => trajectoryUnion G η y k ∪ cluster G (η (k+1)) (y (k+1)) - -theorem mem_trajectoryUnion (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) - (k : ℕ) (v : V) : v ∈ trajectoryUnion G η y k ↔ - ∃ i, 1 ≤ i ∧ i ≤ k ∧ v ∈ cluster G (η i) (y i) := by - induction k with - | zero => simp [trajectoryUnion] - | succ k ih => - simp only [trajectoryUnion,Set.mem_union,ih] - constructor - · rintro (⟨i,hi,hik,hv⟩ | hv) - · exact ⟨i,hi,by omega,hv⟩ - · exact ⟨k+1,by omega,by omega,hv⟩ - · rintro ⟨i,hi,hik,hv⟩ - by_cases he : i = k+1 - · exact Or.inr (he ▸ hv) - · exact Or.inl ⟨i,hi,by omega,hv⟩ - -theorem trajectoryUnion_finite_cap (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) - (k M : ℕ) (hcaps : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : - (trajectoryUnion G η y k).Finite ∧ (trajectoryUnion G η y k).ncard ≤ k*M := by - induction k with - | zero => simp [trajectoryUnion] - | succ k ih => - obtain ⟨hf,hc⟩ := ih (fun i hi hik => hcaps i hi (by omega)) - obtain ⟨hf',hc'⟩ := hcaps (k+1) (by omega) (by omega) - refine ⟨hf.union hf',?_⟩ - calc - _ ≤ (trajectoryUnion G η y k).ncard + (cluster G (η (k+1)) (y (k+1))).ncard := Set.ncard_union_le .. - _ ≤ k*M+M := Nat.add_le_add hc hc' - _ = (k+1)*M := by ring - - - -theorem SpliceTrace.added_subset_trajectory (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) : - cluster G ωf x \ cluster G ω x ⊆ trajectoryUnion G η y k := by - induction h with - | stop => exact fun _ hv => (hv.2 hv.1).elim - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb - intro v hv - by_cases hv' : v ∈ cluster G ω' x - · rw [hC] at hv' - have hvB := hv'.resolve_left hv.2 - exact (mem_trajectoryUnion G η y k v).mpr - ⟨i,by omega,hik,conn_mono G Set.inter_subset_left hvB⟩ - · exact ih ⟨hv.1,hv'⟩ - - - -theorem SpliceTrace.trajectory_hits (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) (hc : c ≠ []) : - (cluster G ω x ∩ trajectoryUnion G η y k).Nonempty := by - cases h with - | stop => exact (hc rfl).elim - | step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht => - exact ⟨a,ha,(mem_trajectoryUnion G η y k a).mpr ⟨i,by omega,hik, - (edge_cluster_sides G (η i) (y i) he hab).mpr (conn_mono G Set.inter_subset_left hb)⟩⟩ - - - -theorem SpliceTrace.added_finite_cap (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : - (cluster G ωf x \ cluster G ω x).Finite ∧ (cluster G ωf x \ cluster G ω x).ncard ≤ k*M := by - obtain ⟨hf,hc⟩ := trajectoryUnion_finite_cap G η y k M hcaps - have hs := h.added_subset_trajectory G x η y k j ω ωf c - exact ⟨hf.subset hs,(Set.ncard_le_ncard hs hf).trans hc⟩ - -end TrajectorySupport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section JointReferenceEvent -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem SpliceTrace.joint_restored_field_symm (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 = - (jointRestored G x η₂ η₁ y₁ ω₂ ω₁ c₁).1 := by - apply exchange_patch_symm _ _ ω₁ ω₂ ωf - (h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep) - · intro e he - rw [← h₁.replay_eq G x η₁ y₁ k j₁ ω₁ ωf c₁] - exact (replaySplice_off_masks G x η₁ y₁ c₁ ω₁ e he).symm - · intro e he - rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf c₂] - exact (replaySplice_off_masks G x η₂ y₂ c₂ ω₂ e he).symm - -theorem SpliceTrace.joint_restored_root (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x = - cluster G ω₁ x ∩ cluster G ω₂ x := by - cases c₁ with - | nil => exact (hc₁ rfl).elim - | cons q r₁ => - obtain ⟨i₁,e₁⟩ := q - cases c₂ with - | nil => exact (hc₂ rfl).elim - | cons q r₂ => - obtain ⟨i₂,e₂⟩ := q - exact h₁.joint_root G x η₁ η₂ y₁ y₂ k j₁ j₂ i₁ i₂ ω₁ ω₂ ωf e₁ e₂ r₁ r₂ h₂ hsep - - - -theorem SpliceTrace.joint_trajectory_hits (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - let A := cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x - (A ∩ trajectoryUnion G η₁ y₁ k).Nonempty ∧ (A ∩ trajectoryUnion G η₂ y₂ k).Nonempty := by - intro A - have hv₁ := (h₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep).1 - have hv₂ := (h₂.joint_virtual G x η₂ η₁ y₂ y₁ k j₂ j₁ ω₂ ω₁ ωf c₂ c₁ h₁ hc₂ hc₁ - (hsep.symm G _ _)).1 - refine ⟨hv₁.trajectory_hits G x η₁ y₁ k j₁ _ ω₂ c₁ hc₁,?_⟩ - change (cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x ∩ _).Nonempty - rw [h₁.joint_restored_field_symm G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep] - exact hv₂.trajectory_hits G x η₂ y₂ k j₂ _ ω₁ c₂ hc₂ - - - -theorem SpliceTrace.joint_restored_size (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ n M : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) - (hf : (cluster G ω₁ x).Finite) (hn : n ≤ (cluster G ω₁ x).ncard) - (h2n : (cluster G ω₁ x).ncard < 2*n) - (hcap₂ : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η₂ i) (y₂ i)).Finite ∧ (cluster G (η₂ i) (y₂ i)).ncard ≤ M) : - let A := cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x - A.Finite ∧ n-k*M ≤ A.ncard ∧ A.ncard < 2*n := by - intro A - have hA : A = cluster G ω₁ x ∩ cluster G ω₂ x := - h₁.joint_restored_root G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep - have hdiff : A = cluster G ω₁ x \ (cluster G ωf x \ cluster G ω₂ x) := by - rw [hA] - ext v - constructor - · rintro ⟨h1,h2⟩ - exact ⟨h1,fun hh => hh.2 h2⟩ - · rintro ⟨h1,h2⟩ - refine ⟨h1,?_⟩ - by_contra hn - exact h2 ⟨h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf c₁ h1,hn⟩ - obtain ⟨hBfin,hBcap⟩ := h₂.added_finite_cap G x η₂ y₂ k j₂ M ω₂ ωf c₂ hcap₂ - have hlower := Set.ncard_le_ncard_sdiff_add_ncard (cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x) hBfin - rw [← hdiff] at hlower - refine ⟨hA ▸ hf.inter_of_left _,by omega,?_⟩ - rw [hA] - exact (Set.ncard_inter_le_ncard_left _ _ hf).trans_lt h2n - -end JointReferenceEvent - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SmallHanging -attribute [local instance] Classical.propDecidable Classical.decEq - - -def hangingSide (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : Set V := - cluster G ω x \ cluster G (ω \ {e}) x - -theorem hangingSide_finite (G : BondGraph V E) (ω : Set E) (x : V) (e : E) - (hC : (cluster G ω x).Finite) : (hangingSide G ω x e).Finite := hC.subset Set.sdiff_subset - -theorem mem_hangingSide_iff_pivotal (G : BondGraph V E) (ω : Set E) (x z : V) - (e : E) (he : e ∈ ω) : z ∈ hangingSide G ω x e ↔ OpenMarkedPivotal G ω {z} x e := by - constructor - · rintro ⟨hz,hn⟩ - exact ⟨he,⟨z,rfl,hz⟩,fun ⟨y,hy,hxy⟩ => hn ((Set.mem_singleton_iff.mp hy) ▸ hxy)⟩ - · rintro ⟨_,⟨y,hy,hxy⟩,hn⟩ - exact ⟨(Set.mem_singleton_iff.mp hy) ▸ hxy,fun hz => hn ⟨z,rfl,hz⟩⟩ - -theorem hangingSide_ncard_add_rank (G : BondGraph V E) (ω : Set E) (x : V) - (e : E) (hC : (cluster G ω x).Finite) : - (hangingSide G ω x e).ncard + pivotalRank G ω x e = (cluster G ω x).ncard := by - have hs : cluster G (ω \ {e}) x ⊆ cluster G ω x := fun _ h => conn_mono G Set.sdiff_subset h - rw [hangingSide,Set.ncard_sdiff hs (hC.subset hs)] - exact Nat.sub_add_cancel (Set.ncard_le_ncard hs hC) - - - -noncomputable def smallSeparatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) - (v : ℕ) : Finset E := - (separatingBonds G ω x z).filter fun e => (hangingSide G ω x e).ncard ≤ v - -theorem smallSeparatingBonds_card_le (G : BondGraph V E) (ω : Set E) (x z : V) - (v : ℕ) (hC : (cluster G ω x).Finite) : (smallSeparatingBonds G ω x z v).card ≤ v := by - have hh := Finset.card_le_card_of_injOn (s := smallSeparatingBonds G ω x z v) - (t := Finset.Icc 1 v) (fun e => (hangingSide G ω x e).ncard) - have hmap : Set.MapsTo (fun e => (hangingSide G ω x e).ncard) - (↑(smallSeparatingBonds G ω x z v)) (↑(Finset.Icc 1 v)) := by - intro e he - obtain ⟨he,hcap⟩ := Finset.mem_filter.mp he - have hp := (mem_separatingBonds G ω x z e).mp he - exact Finset.mem_Icc.mpr ⟨(Set.ncard_pos (hangingSide_finite G ω x e hC)).mpr - ⟨z,(mem_hangingSide_iff_pivotal G ω x z e hp.1).mpr hp⟩,hcap⟩ - have hinj : Set.InjOn (fun e => (hangingSide G ω x e).ncard) - (↑(smallSeparatingBonds G ω x z v)) := by - intro e he f hf heq - apply pivotalRank_injective_of_cluster_finite G ω {z} x hC - ((mem_separatingBonds G ω x z e).mp (Finset.mem_filter.mp he).1) - ((mem_separatingBonds G ω x z f).mp (Finset.mem_filter.mp hf).1) - change (hangingSide G ω x e).ncard = (hangingSide G ω x f).ncard at heq - have he' := hangingSide_ncard_add_rank G ω x e hC - have hf' := hangingSide_ncard_add_rank G ω x f hC - omega - simpa only [Nat.card_Icc, Nat.add_sub_cancel] using hh hmap hinj - -noncomputable def smallHangingThrough (G : BondGraph V E) (ω : Set E) (x z : V) - (v : ℕ) (hC : (cluster G ω x).Finite) : Finset V := - (smallSeparatingBonds G ω x z v).biUnion fun e => (hangingSide_finite G ω x e hC).toFinset - -theorem mem_smallHangingThrough (G : BondGraph V E) (ω : Set E) (x z w : V) - (v : ℕ) (hC : (cluster G ω x).Finite) : w ∈ smallHangingThrough G ω x z v hC ↔ - ∃ e, OpenMarkedPivotal G ω {z} x e ∧ (hangingSide G ω x e).ncard ≤ v ∧ - w ∈ hangingSide G ω x e := by - simp [smallHangingThrough, smallSeparatingBonds, and_assoc] - -theorem smallHangingThrough_card_le (G : BondGraph V E) (ω : Set E) (x z : V) - (v : ℕ) (hC : (cluster G ω x).Finite) : - (smallHangingThrough G ω x z v hC).card ≤ v*v := by - calc - _ ≤ ∑ e ∈ smallSeparatingBonds G ω x z v, (hangingSide_finite G ω x e hC).toFinset.card := - Finset.card_biUnion_le - _ ≤ ∑ _e ∈ smallSeparatingBonds G ω x z v, v := by - apply Finset.sum_le_sum - intro e he - rw [← Set.ncard_eq_toFinset_card (hangingSide G ω x e) (hangingSide_finite G ω x e hC)] - exact (Finset.mem_filter.mp he).2 - _ = (smallSeparatingBonds G ω x z v).card*v := by simp - _ ≤ v*v := Nat.mul_le_mul_right v (smallSeparatingBonds_card_le G ω x z v hC) - -end SmallHanging - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NearHanging -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem hangingSide_laminar (G : BondGraph V E) (ω : Set E) (x : V) - (e f : E) (he : e ∈ ω) (hf : f ∈ ω) : - Disjoint (hangingSide G ω x e) (hangingSide G ω x f) ∨ - hangingSide G ω x e ⊆ hangingSide G ω x f ∨ - hangingSide G ω x f ⊆ hangingSide G ω x e := by - by_cases hd : Disjoint (hangingSide G ω x e) (hangingSide G ω x f) - · exact Or.inl hd - obtain ⟨z,hze,hzf⟩ := Set.not_disjoint_iff.mp hd - by_cases hef : e = f - · exact Or.inr (Or.inl (hef ▸ Set.Subset.refl _)) - rcases pivotal_rootSides_nested G ω {z} x - ((mem_hangingSide_iff_pivotal G ω x z e he).mp hze) - ((mem_hangingSide_iff_pivotal G ω x z f hf).mp hzf) hef with h | h - · exact Or.inr (Or.inr (Set.sdiff_subset_sdiff_right h.1)) - · exact Or.inr (Or.inl (Set.sdiff_subset_sdiff_right h.1)) - -noncomputable def graphNeighbors (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset V) : Finset V := A.biUnion (neighbors G hloc) - -theorem graphNeighbors_card_le (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset V) (d : ℕ) (hdeg : ∀ a, degree G a ≤ d) : - (graphNeighbors G hloc A).card ≤ A.card*d := by - calc - _ ≤ ∑ a ∈ A, (neighbors G hloc a).card := Finset.card_biUnion_le - _ ≤ ∑ _a ∈ A, d := Finset.sum_le_sum fun a _ => - (neighbors_card_le_degree G hloc a).trans (hdeg a) - _ = _ := by simp - - - -noncomputable def nearHangingEndpoints (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x z : V) (e : E) (v : ℕ) (hC : (cluster G ω x).Finite) : Finset V := - ((hangingSide_finite G ω x e hC).toFinset ∪ smallHangingThrough G ω x z v hC) ∪ - (graphNeighbors G hloc (hangingSide_finite G ω x e hC).toFinset).biUnion - (fun a => smallHangingThrough G ω x a v hC) - -theorem nearHangingEndpoints_card_le (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x z : V) (e : E) (v d : ℕ) (hC : (cluster G ω x).Finite) - (hcap : (hangingSide G ω x e).ncard ≤ v) (hdeg : ∀ a, degree G a ≤ d) : - (nearHangingEndpoints G hloc ω x z e v hC).card ≤ v+v^2+d*v^3 := by - let B := (hangingSide_finite G ω x e hC).toFinset - let N := graphNeighbors G hloc B - have hB : B.card ≤ v := by - simpa only [B,← Set.ncard_eq_toFinset_card (hangingSide G ω x e) - (hangingSide_finite G ω x e hC)] using hcap - have hN : N.card ≤ v*d := (graphNeighbors_card_le G hloc B d hdeg).trans - (Nat.mul_le_mul_right d hB) - have hU : (N.biUnion fun a => smallHangingThrough G ω x a v hC).card ≤ d*v^3 := by - calc - _ ≤ ∑ a ∈ N, (smallHangingThrough G ω x a v hC).card := Finset.card_biUnion_le - _ ≤ ∑ _a ∈ N, v*v := Finset.sum_le_sum fun a _ => smallHangingThrough_card_le G ω x a v hC - _ = N.card*(v*v) := by simp - _ ≤ (v*d)*(v*v) := Nat.mul_le_mul_right (v*v) hN - _ = d*v^3 := by ring - calc - _ ≤ (B ∪ smallHangingThrough G ω x z v hC).card + - (N.biUnion fun a => smallHangingThrough G ω x a v hC).card := Finset.card_union_le .. - _ ≤ (B.card + (smallHangingThrough G ω x z v hC).card) + d*v^3 := - Nat.add_le_add (Finset.card_union_le ..) hU - _ ≤ (v+v*v)+d*v^3 := Nat.add_le_add_right - (Nat.add_le_add hB (smallHangingThrough_card_le G ω x z v hC)) _ - _ = v+v^2+d*v^3 := by ring - -theorem mem_nearHangingEndpoints_of_not_separated (G : BondGraph V E) - (hloc : LocallyFinite G) (ω : Set E) (x z w : V) (e f : E) (v : ℕ) - (hC : (cluster G ω x).Finite) - (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {w} x f) - (hcap : (hangingSide G ω x f).ncard ≤ v) - (hn : ¬GraphSeparated G (hangingSide G ω x e) (hangingSide G ω x f)) : - w ∈ nearHangingEndpoints G hloc ω x z e v hC := by - have hz := (mem_hangingSide_iff_pivotal G ω x z e he.1).mpr he - have hw := (mem_hangingSide_iff_pivotal G ω x w f hf.1).mpr hf - rcases hangingSide_laminar G ω x e f he.1 hf.1 with hd | hsub | hsub - · have hadj : ∃ a ∈ hangingSide G ω x e, ∃ b ∈ hangingSide G ω x f, Adj G a b := by - by_contra h - apply hn - refine ⟨hd,?_⟩ - intro a ha b hb hab - exact h ⟨a,ha,b,hb,hab⟩ - obtain ⟨a,ha,b,hb,hab⟩ := hadj - apply Finset.mem_union_right - apply Finset.mem_biUnion.mpr - refine ⟨b,Finset.mem_biUnion.mpr ⟨a,?_,(mem_neighbors G hloc a b).mpr hab⟩,?_⟩ - · exact (hangingSide_finite G ω x e hC).mem_toFinset.mpr ha - · exact (mem_smallHangingThrough G ω x b w v hC).mpr - ⟨f,(mem_hangingSide_iff_pivotal G ω x b f hf.1).mp hb,hcap,hw⟩ - · apply Finset.mem_union_left - apply Finset.mem_union_right - exact (mem_smallHangingThrough G ω x z w v hC).mpr - ⟨f,(mem_hangingSide_iff_pivotal G ω x z f hf.1).mp (hsub hz),hcap,hw⟩ - · apply Finset.mem_union_left - apply Finset.mem_union_left - exact (hangingSide_finite G ω x e hC).mem_toFinset.mpr (hsub hw) - -end NearHanging - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteReferenceLaw -attribute [local instance] Classical.propDecidable Classical.decEq - - -abbrev FiniteField (Q : Finset E) := ↥Q.powerset - -def finiteFieldSet (Q : Finset E) (ω : FiniteField Q) : Set E := (ω.val : Set E) - -noncomputable def finiteFieldWeight (Q : Finset E) (p : ℝ) (ω : FiniteField Q) : ℝ := - bernoulliWeight Q ω.val p - -@[simp] theorem domainBits_finiteFieldSet (Q : Finset E) (ω : FiniteField Q) : - domainBits Q (finiteFieldSet Q ω) = ω.val := by - ext e - have hs := Finset.mem_powerset.mp ω.property - simp only [mem_domainBits,finiteFieldSet,Finset.mem_coe] - exact ⟨fun h => h.2,fun h => ⟨hs h,h⟩⟩ - -theorem finiteFieldWeight_nonneg (Q : Finset E) (p : unitInterval) (ω : FiniteField Q) : - 0 ≤ finiteFieldWeight Q p ω := bernoulliWeight_nonneg _ _ p - -theorem sum_finiteFieldWeight (Q : Finset E) (p : ℝ) : - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω = 1 := by - rw [show (fun ω : FiniteField Q => finiteFieldWeight Q p ω) = - (fun ω : FiniteField Q => bernoulliWeight Q ω.val p) from rfl,Finset.sum_coe_sort Q.powerset (fun ω => bernoulliWeight Q ω p)] - simpa only [bernoulliPolynomial,bernoulliWeight,mul_one,one_mul] using bernoulliPolynomial_const Q 1 p - - - -def finiteFieldFamily (Q : Finset E) (J : Finset ℕ) (η : ↥J → FiniteField Q) : ℕ → Set E := - fun i => if hi : i ∈ J then finiteFieldSet Q (η ⟨i,hi⟩) else ∅ - -@[simp] theorem finiteFieldFamily_at (Q : Finset E) (J : Finset ℕ) - (η : ↥J → FiniteField Q) (i : ↥J) : - finiteFieldFamily Q J η i = finiteFieldSet Q (η i) := by - simp [finiteFieldFamily,i.property] - -noncomputable def finiteFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (η : ↥J → FiniteField Q) : ℝ := ∏ i, finiteFieldWeight Q p (η i) - -theorem finiteFamilyWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (η : ↥J → FiniteField Q) : 0 ≤ finiteFamilyWeight Q J p η := - Finset.prod_nonneg fun _ _ => finiteFieldWeight_nonneg Q p _ - -theorem sum_finiteFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) : - ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η = 1 := by - unfold finiteFamilyWeight - rw [← Fintype.prod_sum] - simp only [sum_finiteFieldWeight,Finset.prod_const_one] - -theorem prod_fieldFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (η : ↥J → FiniteField Q) : - (∏ i ∈ J, bernoulliWeight Q (domainBits Q (finiteFieldFamily Q J η i)) p) = - finiteFamilyWeight Q J p η := by - rw [← Finset.prod_coe_sort J] - simp only [finiteFieldFamily_at,domainBits_finiteFieldSet,finiteFamilyWeight,finiteFieldWeight] - -abbrev FiniteJointData (Q : Finset E) (J₁ J₂ : Finset ℕ) := - FiniteField Q × (↥J₁ → FiniteField Q) × (↥J₂ → FiniteField Q) - -def encodeFiniteJoint (Q : Finset E) (J₁ J₂ : Finset ℕ) - (s : FiniteJointData Q J₁ J₂) : JointSpliceState E := - (finiteFieldSet Q s.1,finiteFieldFamily Q J₁ s.2.1,finiteFieldFamily Q J₂ s.2.2) - -theorem finiteFieldSet_injective (Q : Finset E) : Function.Injective (finiteFieldSet Q) := by - intro a b he - exact Subtype.ext (Finset.coe_injective he) - -theorem finiteFieldFamily_injective (Q : Finset E) (J : Finset ℕ) : - Function.Injective (finiteFieldFamily Q J) := by - intro a b he - funext i - apply finiteFieldSet_injective Q - simpa only [finiteFieldFamily_at] using congrFun he i - -theorem encodeFiniteJoint_injective (Q : Finset E) (J₁ J₂ : Finset ℕ) : - Function.Injective (encodeFiniteJoint Q J₁ J₂) := by - intro a b he - apply Prod.ext (finiteFieldSet_injective Q (congrArg Prod.fst he)) - exact Prod.ext (finiteFieldFamily_injective Q J₁ (congrArg (fun s => s.2.1) he)) - (finiteFieldFamily_injective Q J₂ (congrArg (fun s => s.2.2) he)) - -theorem jointTupleWeight_encode (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (s : FiniteJointData Q J₁ J₂) : - jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) = - finiteFieldWeight Q p s.1 * finiteFamilyWeight Q J₁ p s.2.1 * - finiteFamilyWeight Q J₂ p s.2.2 := by - simp only [jointTupleWeight,encodeFiniteJoint,domainBits_finiteFieldSet, - prod_fieldFamilyWeight,finiteFieldWeight] - - - -theorem sum_jointTupleWeight_encode (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) : - ∑ s : FiniteJointData Q J₁ J₂, jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) = 1 := by - simp_rw [jointTupleWeight_encode] - rw [Fintype.sum_prod_type] - simp_rw [Fintype.sum_prod_type,← Finset.mul_sum,sum_finiteFamilyWeight,mul_one, - ← Finset.mul_sum,sum_finiteFamilyWeight,mul_one] - exact sum_finiteFieldWeight Q p - -end FiniteReferenceLaw - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteReferenceFactor -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def finiteFamilyEvent (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (H : (ℕ → Set E) → Prop) : ℝ := - ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * - if H (finiteFieldFamily Q J η) then 1 else 0 - -theorem finiteFamilyEvent_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (H : (ℕ → Set E) → Prop) : 0 ≤ finiteFamilyEvent Q J p H := by - apply Finset.sum_nonneg - intro η _ - exact mul_nonneg (finiteFamilyWeight_nonneg Q J p η) (by split <;> norm_num) - -theorem finiteFamilyEvent_le_one (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (H : (ℕ → Set E) → Prop) : finiteFamilyEvent Q J p H ≤ 1 := by - rw [← sum_finiteFamilyWeight Q J p] - apply Finset.sum_le_sum - intro η _ - exact mul_le_of_le_one_right (finiteFamilyWeight_nonneg Q J p η) (by split <;> norm_num) - -noncomputable def finiteJointDomain (Q : Finset E) (J₁ J₂ : Finset ℕ) : - Finset (JointSpliceState E) := Finset.univ.image (encodeFiniteJoint Q J₁ J₂) - -theorem finiteJointDomain_event_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (P : Set E → Prop) (H₁ H₂ : Set E → (ℕ → Set E) → Prop) : - (∑ s ∈ (finiteJointDomain Q J₁ J₂).filter (fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2), - jointTupleWeight Q J₁ J₂ p s) = - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if P (finiteFieldSet Q ω) then - finiteFamilyEvent Q J₁ p (H₁ (finiteFieldSet Q ω)) * - finiteFamilyEvent Q J₂ p (H₂ (finiteFieldSet Q ω)) else 0) := by - rw [Finset.sum_filter,finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn, - Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro ω _ - rw [Fintype.sum_prod_type] - by_cases hP : P (finiteFieldSet Q ω) - · simp only [encodeFiniteJoint, hP, true_and,ite_true] - have heq (η₁ : ↥J₁ → FiniteField Q) (η₂ : ↥J₂ → FiniteField Q) : - (if H₁ (finiteFieldSet Q ω) (finiteFieldFamily Q J₁ η₁) ∧ - H₂ (finiteFieldSet Q ω) (finiteFieldFamily Q J₂ η₂) then - jointTupleWeight Q J₁ J₂ p - (finiteFieldSet Q ω,finiteFieldFamily Q J₁ η₁,finiteFieldFamily Q J₂ η₂) else 0) = - finiteFieldWeight Q p ω * - (finiteFamilyWeight Q J₁ p η₁ * if H₁ (finiteFieldSet Q ω) (finiteFieldFamily Q J₁ η₁) then 1 else 0) * - (finiteFamilyWeight Q J₂ p η₂ * if H₂ (finiteFieldSet Q ω) (finiteFieldFamily Q J₂ η₂) then 1 else 0) := by - have hw := jointTupleWeight_encode Q J₁ J₂ p (ω,η₁,η₂) - change jointTupleWeight Q J₁ J₂ p (finiteFieldSet Q ω,finiteFieldFamily Q J₁ η₁,finiteFieldFamily Q J₂ η₂) = _ at hw - rw [hw] - split_ifs <;> simp_all - simp_rw [heq,← Finset.mul_sum,← Finset.sum_mul] - rw [← Finset.mul_sum,mul_assoc] - rfl - · simp [encodeFiniteJoint,hP] - - - -theorem mem_finiteJointDomain_of_support (Q : Finset E) (J₁ J₂ : Finset ℕ) - (s : JointSpliceState E) (hω : s.1 ⊆ (Q : Set E)) - (hη₁ : ∀ i, s.2.1 i ⊆ (Q : Set E)) (hη₂ : ∀ i, s.2.2 i ⊆ (Q : Set E)) - (hz₁ : ∀ i ∉ J₁, s.2.1 i = ∅) (hz₂ : ∀ i ∉ J₂, s.2.2 i = ∅) : - s ∈ finiteJointDomain Q J₁ J₂ := by - let desc (ω : Set E) : FiniteField Q := ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ - have hdesc (ω : Set E) (h : ω ⊆ (Q : Set E)) : finiteFieldSet Q (desc ω) = ω := by - ext e - simp only [finiteFieldSet,desc,Finset.mem_coe,mem_domainBits] - exact ⟨fun hh => hh.2,fun hh => ⟨h hh,hh⟩⟩ - let a : FiniteJointData Q J₁ J₂ := (desc s.1,fun i => desc (s.2.1 i),fun i => desc (s.2.2 i)) - apply Finset.mem_image.mpr - refine ⟨a,Finset.mem_univ _,?_⟩ - apply Prod.ext (hdesc s.1 hω) - apply Prod.ext - · funext i - change (if hi : i ∈ J₁ then finiteFieldSet Q (desc (s.2.1 i)) else ∅) = s.2.1 i - by_cases hi : i ∈ J₁ - · simp only [hi,dite_true,hdesc _ (hη₁ i)] - · simp only [hi,dite_false,hz₁ i hi] - · funext i - change (if hi : i ∈ J₂ then finiteFieldSet Q (desc (s.2.2 i)) else ∅) = s.2.2 i - by_cases hi : i ∈ J₂ - · simp only [hi,dite_true,hdesc _ (hη₂ i)] - · simp only [hi,dite_false,hz₂ i hi] - -theorem exchangeOn_subset (M ω η Q : Set E) (hω : ω ⊆ Q) (hη : η ⊆ Q) : - exchangeOn M ω η ⊆ Q := by - rintro e (⟨he,_⟩ | ⟨he,_⟩) - · exact hω he - · exact hη he - -end FiniteReferenceFactor - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteSeparatedSecondMoment -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_separated_second_moment_le {I : Type*} [Fintype I] - (G : BondGraph V E) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) - (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (success₁ success₂ : (ℕ → Set E) → Prop) - (choose₁ choose₂ : ℕ → Set E → E) - (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) - (hir : Function.Injective (fun a => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), - c₁ a,c₂ a))) - (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) - (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) - (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) - (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) - (cluster G (ωf a) x \ cluster G (ω₂ a) x)) - (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) - (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) - (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ - (cluster G (ω₁ a) x).ncard < 2*n) - (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ - (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) - (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) - (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) - (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) - (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) - (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : - (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a))) ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₁ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty) * - finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₂ η ∧ - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty) else 0) := by - let J := Finset.Icc 1 k - let P (ω : Set E) := (cluster G ω x).Finite ∧ n-k*M ≤ (cluster G ω x).ncard ∧ - (cluster G ω x).ncard < 2*n - let H₁ (ω : Set E) (η : ℕ → Set E) := success₁ η ∧ - (cluster G ω x ∩ trajectoryUnion G η (y₁ η) k).Nonempty - let H₂ (ω : Set E) (η : ℕ → Set E) := success₂ η ∧ - (cluster G ω x ∩ trajectoryUnion G η (y₂ η) k).Nonempty - let B := (finiteJointDomain Q J J).filter fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 - have hB (a : I) : jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B := by - apply Finset.mem_filter.mpr - refine ⟨mem_finiteJointDomain_of_support Q J J _ - (exchangeOn_subset _ _ _ _ (hsω₁ a) (hsω₂ a)) (hsη₁ a) (hsη₂ a) (hz₁ a) (hz₂ a),?_⟩ - have hroot := (h₁ a).joint_restored_size G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - k 0 0 n M (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) - (hbin a).1 (hbin a).2.1 (hbin a).2.2 (hcap₂ a) - have hhits := (h₁ a).joint_trajectory_hits G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - k 0 0 (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) - exact ⟨hroot,⟨hsc₁ a,hhits.1⟩,hsc₂ a,hhits.2⟩ - have h := finite_joint_mass_le G x k p Q η₁ η₂ y₁ y₂ choose₁ choose₂ ω₁ ω₂ ωf c₁ c₂ - hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ B hB - apply h.trans_eq - convert finiteJointDomain_event_factor Q J J p P H₁ H₂ using 1 <;> simp [B,J,P,H₁,H₂] - -end FiniteSeparatedSecondMoment - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SeededForward -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem exists_seeded_spliceTrace (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k M : ℕ) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M) - (choose : ℕ → Set E → E) - (hchoose : ∀ i K, K.Finite → K.Nonempty → choose i K ∈ K) - (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) - (N : ℕ) (hfin : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) : - ∃ steps ωf, SpliceTrace G x η y k j ω steps ωf ∧ - FollowsContactRule G x η y choose steps ω ∧ steps.length ≤ k-j ∧ - y k ∈ cluster G ωf x ∧ (cluster G ωf x).Finite ∧ - (cluster G ωf x).ncard ≤ N+(k-j)*M := by - generalize hn : k-j = n - induction n using Nat.strong_induction_on generalizing j ω N with - | h n ih => - by_cases hz : y k ∈ cluster G ω x - · refine ⟨[],ω,SpliceTrace.stop j ω hz,?_,by simp,hz,hfin,?_⟩ - · exact List.Forall₂.nil - · exact hN.trans (Nat.le_add_right ..) - · obtain ⟨i,hiI,hmeet,hyi,hmax⟩ := - exists_maximal_splice_index G η y k j hj hchain (cluster G ω x) hyj hz - obtain ⟨hji,hik⟩ := Finset.mem_Icc.mp hiI - have hi1 : i ∈ Finset.Icc 1 k := Finset.mem_Icc.mpr ⟨by omega,hik⟩ - let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) - let K := contactSet G (η i) B - have hBC : B ⊆ cluster G (η i) (y i) := fun _ h => conn_mono G Set.inter_subset_left h - have hBK : K.Finite := contactSet_finite G hloc (η i) B ((hcaps i hi1).1.subset hBC) - have hK : K.Nonempty := by - obtain ⟨e,a,b,he,hab,ha,hb⟩ := exists_splice_contact G (η i) (cluster G ω x) (y i) hyi hmeet - exact ⟨e,he,b,a,hab.trans (Sym2.eq_swap ..),hb, - fun h => slit_cluster_subset G (cluster G ω x) (η i) (y i) hyi h ha⟩ - let e := choose i K - have heK : e ∈ contactSet G (η i) B := hchoose i K hBK hK - change e ∈ contactSet G (η i) - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) at heK - rw [contactSet_deleted_cluster G (η i) (cluster G ω x) (y i) hyi] at heK - obtain ⟨he,b,hb,a,ha,hba⟩ := heK - have hab : G e = s(a,b) := hba.trans (Sym2.eq_swap ..) - let ω' := spliceField G (cluster G ω x) B e ω (η i) - have hcap := splice_cluster_cap G ω (η i) x (y i) hyi e a b hab he ha hb N M hfin hN - (hcaps i hi1).1 (hcaps i hi1).2 - have hyt : y i ∈ cluster G ω' x := by - change y i ∈ cluster G (spliceField G (cluster G ω x) B e ω (η i)) x - rw [splice_cluster G ω (η i) x (y i) hyi e a b hab he ha hb] - exact Or.inr (mem_cluster_self G _ _) - obtain ⟨steps,ωf,htrace,hrule,hlen,hconn,hf,hs⟩ := - ih (k-i) (by omega) i hik ω' hyt (N+M) hcap.1 hcap.2 rfl - refine ⟨(i,e)::steps,ωf, - SpliceTrace.step j i ω e a b steps ωf hz (by omega) hik hmax hyi he hab ha hb htrace, - ?_,?_,hconn,hf,?_⟩ - · exact (followsContactRule_cons G x η y choose i e steps ω).mpr ⟨rfl,hrule⟩ - · simp only [List.length_cons] - omega - · have hm : (k-i+1)*M ≤ (k-j)*M := Nat.mul_le_mul_right M (by omega) - rw [Nat.add_mul,one_mul] at hm - calc - _ ≤ (N+M)+(k-i)*M := hs - _ ≤ N+(k-j)*M := by omega - _ = N+n*M := by rw [hn] - - - -theorem existsUnique_seeded_spliceTrace (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k M : ℕ) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M) - (choose : ℕ → Set E → E) - (hchoose : ∀ i K, K.Finite → K.Nonempty → choose i K ∈ K) - (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) - (hfin : (cluster G ω x).Finite) : - ∃! out : List (ℕ × E) × Set E, - SpliceTrace G x η y k j ω out.1 out.2 ∧ - FollowsContactRule G x η y choose out.1 ω := by - obtain ⟨c,ωf,ht,hr,_⟩ := exists_seeded_spliceTrace G hloc x η y k M hchain hcaps - choose hchoose j hj ω hyj _ hfin (le_refl _) - refine ⟨(c,ωf),⟨ht,hr⟩,?_⟩ - rintro ⟨d,σf⟩ ⟨hs,hd⟩ - obtain ⟨hc,hf⟩ := hs.seeded_unique G x η y k j ω σf ωf d c ht choose hd hr - exact Prod.ext hc hf - -end SeededForward -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SpliceLocalSupport -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem reachBall_triangle (G : BondGraph V E) (x y : V) (n m : ℕ) - (hy : y ∈ reachBall G x n) : reachBall G y m ⊆ reachBall G x (n+m) := by - induction m with - | zero => simpa only [reachBall,Nat.add_zero,Set.singleton_subset_iff] using hy - | succ m ih => - intro z hz - rcases hz with hz | hz - · exact Or.inl (ih hz) - · apply Or.inr - simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hz ⊢ - obtain ⟨a,ha,haz⟩ := hz - exact ⟨a,ih ha,haz⟩ - - -theorem capped_cluster_ball_of_mem (G : BondGraph V E) (ω : Set E) (x y : V) - (hfin : (cluster G ω x).Finite) (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) - (hy : y ∈ cluster G ω x) : cluster G ω x ⊆ reachBall G y M := by - have he := cluster_eq_of_conn G ω hy - rw [he] at hfin hM ⊢ - exact finite_cluster_subset_reachBall G ω y hfin M hM - - - -theorem oldChain_local_support (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k M N : ℕ) - (hstart : y 0 ∈ reachBall G x N) - (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : - (∀ i, i ≤ k → y i ∈ reachBall G x (N+i*M)) ∧ - trajectoryUnion G η y k ⊆ reachBall G x (N+k*M) := by - have hvertex : ∀ i, i ≤ k → y i ∈ reachBall G x (N+i*M) := by - intro i - induction i with - | zero => simpa using hstart - | succ i ih => - intro hik - obtain ⟨hf,hM⟩ := hcaps (i+1) (by omega) hik - have hc := capped_cluster_ball_of_mem G (η (i+1)) (y (i+1)) (y i) hf M hM - (by simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (i+1) (by omega) hik) - have hh := reachBall_triangle G x (y i) (N+i*M) M (ih (by omega)) - (hc (mem_cluster_self G _ _)) - convert hh using 1 - congr 1 - ring - refine ⟨hvertex,?_⟩ - intro v hv - obtain ⟨i,hi,hik,hv⟩ := (mem_trajectoryUnion G η y k v).mp hv - obtain ⟨hf,hM⟩ := hcaps i hi hik - have hc := capped_cluster_ball_of_mem G (η i) (y i) (y (i-1)) hf M hM (hchain i hi hik) - have hh := reachBall_triangle G x (y (i-1)) (N+(i-1)*M) M - (hvertex (i-1) (by omega)) (hc hv) - apply reachBall_mono_local G x _ hh - have hmul : i*M ≤ k*M := Nat.mul_le_mul_right M hik - have he : (i-1)*M+M = i*M := by - calc _ = (i-1+1)*M := by ring - _ = i*M := by rw [Nat.sub_add_cancel hi] - omega - - - -theorem SpliceTrace.masks_in_deterministic_ball (G : BondGraph V E) - (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (k j M N : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) - (hstart : y 0 ∈ reachBall G x N) - (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : - maskUnion (replayMasks G x η y c ω) ⊆ - (incidentSupport G hloc (finite_reachBall hloc x (N+k*M)).toFinset : Set E) := by - intro e he - obtain ⟨b,hb,hbe⟩ := h.masks_incident G x η y k j ω ωf c e he - have hbt := h.added_subset_trajectory G x η y k j ω ωf c hb - have hball := (oldChain_local_support G x η y k M N hstart hchain hcaps).2 hbt - exact (mem_incidentSupport G hloc _ e).mpr ⟨b,by simpa using hball,hbe⟩ - - - -theorem oldChain_query_support (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k M N R : ℕ) - (hstart : y 0 ∈ reachBall G x N) - (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) - (i : ℕ) (hi : i ≤ k) : - reachBall G (y i) R ⊆ reachBall G x (N+k*M+R) := by - have hv := (oldChain_local_support G x η y k M N hstart hchain hcaps).1 i hi - intro z hz - have hh := reachBall_triangle G x (y i) (N+i*M) R hv hz - exact reachBall_mono_local G x (by nlinarith) hh - -end SpliceLocalSupport -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section UniformContactSelector -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def uniformRank (K : ℕ) (hK : 0 < K) (t : unitInterval) : Fin K := - ⟨min ⌊(K:ℝ)*(t:ℝ)⌋₊ (K-1), lt_of_le_of_lt (min_le_right ..) (by omega)⟩ - -theorem uniformRank_val_of_lt_one (K : ℕ) (hK : 0 < K) (t : unitInterval) - (ht : (t:ℝ) < 1) : (uniformRank K hK t).val = ⌊(K:ℝ)*(t:ℝ)⌋₊ := by - have hp : (0:ℝ) < K := by exact_mod_cast hK - have hf : ⌊(K:ℝ)*(t:ℝ)⌋₊ < K := (Nat.floor_lt (mul_nonneg (Nat.cast_nonneg _) t.property.1)).mpr (by nlinarith) - exact min_eq_left (by omega) - -theorem uniformRank_eq_iff (K : ℕ) (hK : 0 < K) (t : unitInterval) - (ht : (t:ℝ) < 1) (a : Fin K) : - uniformRank K hK t = a ↔ t ∈ contactInterval K a.val := by - rw [Fin.ext_iff,uniformRank_val_of_lt_one K hK t ht, - Nat.floor_eq_iff (mul_nonneg (Nat.cast_nonneg _) t.property.1)] - have hp : (0:ℝ) < K := by exact_mod_cast hK - simp only [contactInterval,Set.mem_ofPred_eq,Nat.cast_add,Nat.cast_one] - rw [div_le_iff₀ hp,lt_div_iff₀ hp] - simp only [mul_comm] - -theorem volume_uniformRank_fiber (K : ℕ) (hK : 0 < K) (a : Fin K) : - volume {t : unitInterval | uniformRank K hK t = a} = - ENNReal.ofReal ((K:ℝ)⁻¹) := by - rw [← volume_contactInterval K a.val a.isLt] - apply measure_congr - filter_upwards [(volume : Measure unitInterval).ae_ne 1] with t ht - exact propext (uniformRank_eq_iff K hK t (lt_of_le_of_ne t.property.2 - (fun he => ht (Subtype.ext he))) a) - - - -noncomputable def uniformContact (K : Finset E) (hK : K.Nonempty) - (t : unitInterval) : E := - ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).val - -theorem uniformContact_mem (K : Finset E) (hK : K.Nonempty) (t : unitInterval) : - uniformContact K hK t ∈ K := - ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).property - -theorem uniformContact_eq_iff (K : Finset E) (hK : K.Nonempty) (t : unitInterval) - (e : E) (he : e ∈ K) : - uniformContact K hK t = e ↔ - uniformRank K.card (Finset.card_pos.mpr hK) t = K.equivFin ⟨e,he⟩ := by - unfold uniformContact - change ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).val = - (⟨e,he⟩ : ↥K).val ↔ _ - rw [← Subtype.ext_iff] - exact K.equivFin.symm_apply_eq - -theorem volume_uniformContact_fiber (K : Finset E) (hK : K.Nonempty) - (e : E) (he : e ∈ K) : volume {t : unitInterval | uniformContact K hK t = e} = - ENNReal.ofReal ((K.card:ℝ)⁻¹) := by - simp_rw [uniformContact_eq_iff K hK _ e he] - exact volume_uniformRank_fiber K.card (Finset.card_pos.mpr hK) _ - - - -noncomputable def chooseContact [Nonempty E] (seed : ℕ → unitInterval) - (i : ℕ) (K : Set E) : E := - if hf : K.Finite then if hn : K.Nonempty then - uniformContact hf.toFinset (by simpa using hn) (seed i) - else Classical.arbitrary E else Classical.arbitrary E - -theorem chooseContact_mem [Nonempty E] (seed : ℕ → unitInterval) - (i : ℕ) (K : Set E) (hf : K.Finite) (hn : K.Nonempty) : - chooseContact seed i K ∈ K := by - simp only [chooseContact,dite_eq_left hf,dite_eq_left hn] - exact hf.mem_toFinset.mp (uniformContact_mem _ _ _) - -end UniformContactSelector -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section SeededTraceLaw -attribute [local instance] Classical.propDecidable Classical.decEq -variable [Nonempty E] - - -theorem chooseContact_congr (u v : ℕ → unitInterval) (i : ℕ) (K : Set E) - (h : u i = v i) : chooseContact u i K = chooseContact v i K := by - unfold chooseContact - split_ifs <;> simp only [h] - - -noncomputable def replaySeedFiber (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) : List (ℕ × E) → Set E → ℕ → Set unitInterval - | [], _, _ => Set.univ - | (j,e)::c, ω, i => - let S := cluster G ω x - let B := cluster G (η j ∩ internalEdges G Sᶜ) (y j) - if i = j then {t | chooseContact (fun _ => t) j (contactSet G (η j) B) = e} - else replaySeedFiber G x η y c (spliceField G S B e ω (η j)) i - -theorem replaySeedFiber_univ (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (i : ℕ) - (hi : ∀ q ∈ c, i ≠ q.1) : replaySeedFiber G x η y c ω i = Set.univ := by - induction c generalizing ω with - | nil => rfl - | cons q c ih => - obtain ⟨j,e⟩ := q - simp only [replaySeedFiber,ite_eq_right (hi (j,e) (by simp))] - exact ih _ (fun q hq => hi q (by simp [hq])) - -theorem SpliceTrace.follows_iff_seedFiber (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) - (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) - (seed : ℕ → unitInterval) : - FollowsContactRule G x η y (chooseContact seed) c ω ↔ - ∀ i, 1 ≤ i → i ≤ k → seed i ∈ replaySeedFiber G x η y c ω i := by - induction h with - | stop j ω hz => simp [FollowsContactRule,replayContacts,replaySeedFiber] - | @step j l ω e a b c ωf hn hjl hlk hm hy he hab ha hb ht ih => - rw [followsContactRule_cons,ih] - have htail : replaySeedFiber G x η y c - (spliceField G (cluster G ω x) - (cluster G (η l ∩ internalEdges G (cluster G ω x)ᶜ) (y l)) e ω (η l)) l = Set.univ := by - apply replaySeedFiber_univ - intro q hq - have hq' := ht.seam_data G x η y k l _ ωf c q hq - omega - constructor - · rintro ⟨hc,hr⟩ i hi hik - by_cases hil : i = l - · subst i - simp only [replaySeedFiber,ite_true,Set.mem_ofPred_eq] - exact (chooseContact_congr _ _ l _ rfl).trans hc - · simpa only [replaySeedFiber,ite_eq_right hil] using hr i hi hik - · intro hr - constructor - · have hh := hr l (by omega) hlk - simp only [replaySeedFiber,ite_true,Set.mem_ofPred_eq] at hh - exact (chooseContact_congr _ _ l _ rfl).trans hh - · intro i hi hik - by_cases hil : i = l - · subst i - rw [htail] - trivial - · simpa only [replaySeedFiber,ite_eq_right hil] using hr i hi hik - - - -def finiteContactSeeds (k : ℕ) (u : Fin k → unitInterval) (i : ℕ) : unitInterval := - if hi : 1 ≤ i ∧ i ≤ k then u ⟨i-1,by omega⟩ else 0 - -@[simp] theorem finiteContactSeeds_at (k : ℕ) (u : Fin k → unitInterval) (i : Fin k) : - finiteContactSeeds k u (i.val+1) = u i := by - have hi : 1 ≤ i.val+1 ∧ i.val+1 ≤ k := ⟨by omega,by omega⟩ - simp only [finiteContactSeeds,dite_eq_left hi,Nat.add_sub_cancel] - -theorem SpliceTrace.seed_event_eq_pi (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) - (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) : - {u : Fin k → unitInterval | FollowsContactRule G x η y - (chooseContact (finiteContactSeeds k u)) c ω} = - Set.pi Set.univ (fun i => replaySeedFiber G x η y c ω (i.val+1)) := by - ext u - rw [Set.mem_ofPred_eq,h.follows_iff_seedFiber G x η y k j ω ωf c] - simp only [Set.mem_pi,Set.mem_univ,true_implies] - constructor - · intro hu i - simpa only [finiteContactSeeds_at] using hu (i.val+1) (by omega) (by omega) - · intro hu i hi hik - have hh := hu ⟨i-1,by omega⟩ - have hii : 1 ≤ i ∧ i ≤ k := ⟨hi,hik⟩ - simpa only [finiteContactSeeds,dite_eq_left hii,Nat.sub_add_cancel hi] using hh - - - -theorem SpliceTrace.volume_seedFiber (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) - (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite) : - ∀ i, volume (replaySeedFiber G x η y c ω i) = - ENNReal.ofReal ((traceContactCount G η y ωf x c i : ℝ)⁻¹) := by - induction c generalizing j ω with - | nil => simp [replaySeedFiber,traceContactCount] - | cons q c ih => - obtain ⟨l,e⟩ := q - have hcut := h.head_cut G x η y k j l ω ωf e c - cases h with - | step j l ω e a b c ωf hn hjl hlk hm hy he hab ha hb ht => - intro i - by_cases hil : i = l - · subst i - simp only [replaySeedFiber,ite_true,traceContactCount,seamContactCount,hcut] - let B := cluster G (η l ∩ internalEdges G (cluster G ω x)ᶜ) (y l) - let K := contactSet G (η l) B - have hB : B.Finite := (hcaps l (by omega) hlk).subset (fun _ h => conn_mono G Set.inter_subset_left h) - have hK : K.Finite := contactSet_finite G hloc (η l) B hB - have heK : e ∈ K := ⟨he,b,a,hab.trans (Sym2.eq_swap ..),hb, - fun haB => slit_cluster_subset G (cluster G ω x) (η l) (y l) hy haB ha⟩ - have hnK : K.Nonempty := ⟨e,heK⟩ - change volume {t : unitInterval | chooseContact (fun _ => t) l K = e} = _ - simp only [chooseContact,dite_eq_left hK,dite_eq_left hnK] - rw [volume_uniformContact_fiber _ _ e (hK.mem_toFinset.mpr heK)] - rw [← Set.ncard_eq_toFinset_card K hK] - · simpa only [replaySeedFiber,traceContactCount,ite_eq_right hil] using ih l _ ht i - - -theorem SpliceTrace.seed_probability (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) - (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) - (hcaps : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite) : - ((volume : Measure (Fin k → unitInterval)) - {u | FollowsContactRule G x η y (chooseContact (finiteContactSeeds k u)) c ω}).toReal = - ∏ i : Fin k, (traceContactCount G η y ωf x c (i.val+1):ℝ)⁻¹ := by - rw [h.seed_event_eq_pi G x η y k j ω ωf c,MeasureTheory.volume_pi,Measure.pi_pi,ENNReal.toReal_prod] - apply Finset.prod_congr rfl - intro i _ - rw [h.volume_seedFiber G hloc x η y k j ω ωf c hcaps,ENNReal.toReal_ofReal (by positivity)] - -end SeededTraceLaw -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.Replay + +namespace OAI + +/-! Reference Laws for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteJointMass +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def jointOutput (G : BondGraph V E) (x : V) (η₁ η₂ : ℕ → Set E) + (y₁ y₂ : ℕ → V) (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) : JointSpliceState E := + (ωf,(runMasks (replayMasks G x η₁ y₁ c₁ ω₁) (ω₁,η₁)).2, + (runMasks (replayMasks G x η₂ y₂ c₂ ω₂) (ω₂,η₂)).2) + +def jointRestored (G : BondGraph V E) (x : V) (η₁ η₂ : ℕ → Set E) + (y₂ : ℕ → V) (ω₁ ω₂ : Set E) (c₂ : List (ℕ × E)) : JointSpliceState E := + (exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂,η₁,η₂) + + + +theorem finite_joint_mass_le {I : Type*} [Fintype I] + (G : BondGraph V E) (x : V) (k : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (choose₁ choose₂ : ℕ → Set E → E) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) + (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) + (B : Finset (JointSpliceState E)) + (hB : ∀ a, jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a))) ≤ + ∑ s ∈ B, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p s := by + let out (a : I) := jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) + let rest (a : I) := jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) + have hinj : Function.Injective rest := by + intro a b he + have hη₁ : η₁ a = η₁ b := congrArg (fun s : JointSpliceState E => s.2.1) he + have hη₂ : η₂ a = η₂ b := congrArg (fun s : JointSpliceState E => s.2.2) he + have gb₁ : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ b) (c₁ b) (ωf b) := by + rw [hη₁]; exact h₁ b + have gb₂ : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ b) (c₂ b) (ωf b) := by + rw [hη₂]; exact h₂ b + have grb₁ : FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ b) (ω₁ b) := by + rw [hη₁]; exact hr₁ b + have grb₂ : FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ b) (ω₂ b) := by + rw [hη₂]; exact hr₂ b + have hfield : exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ a) (ω₂ a))) (ω₁ a) (ω₂ a) = + exchangeOn (maskUnion (replayMasks G x (η₂ a) (y₂ (η₂ a)) (c₂ b) (ω₂ b))) (ω₁ b) (ω₂ b) := by + have hh := congrArg Prod.fst he + simpa only [rest,jointRestored,← hη₂] using hh + obtain ⟨hcode₁,hcode₂,hfieldf,haux₁,haux₂⟩ := joint_restore_seeded_unique G x + (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) choose₁ choose₂ k 0 0 + (ω₁ a) (ω₂ a) (ωf a) (ω₁ b) (ω₂ b) (ωf b) + (c₁ a) (c₂ a) (c₁ b) (c₂ b) (h₁ a) (h₂ a) gb₁ gb₂ + (hc₁ a) (hc₂ a) (hc₁ b) (hc₂ b) (hsep a) (hsep b) + (hr₁ a) (hr₂ a) grb₁ grb₂ hfield + have hout : out a = out b := by + apply Prod.ext hfieldf + apply Prod.ext + · simpa only [out,jointOutput,hη₁] using haux₁ + · simpa only [out,jointOutput,hη₂] using haux₂ + exact hir (Prod.ext hout (Prod.ext hcode₁ hcode₂)) + have hw : ∀ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (out a) = + jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p (rest a) := by + intro a + apply (h₁ a).joint_weight G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) k 0 0 + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hsep a) Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + · intro q hq + have hr := (h₁ a).seam_data G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (ωf a) (c₁ a) q hq + exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ + · intro q hq + have hr := (h₂ a).seam_data G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (ωf a) (c₂ a) q hq + exact Finset.mem_Icc.mpr ⟨hr.1,hr.2.1⟩ + change (∑ a, jointTupleWeight Q _ _ p (out a)) ≤ _ + simp_rw [hw] + rw [← Finset.sum_image hinj.injOn] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro s hs + obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp hs + exact hB a + · intro s _ _ + exact jointTupleWeight_nonneg Q _ _ p s + +end FiniteJointMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TrajectorySupport +attribute [local instance] Classical.propDecidable Classical.decEq + + +def trajectoryUnion (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) : ℕ → Set V + | 0 => ∅ + | k+1 => trajectoryUnion G η y k ∪ cluster G (η (k+1)) (y (k+1)) + +theorem mem_trajectoryUnion (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) + (k : ℕ) (v : V) : v ∈ trajectoryUnion G η y k ↔ + ∃ i, 1 ≤ i ∧ i ≤ k ∧ v ∈ cluster G (η i) (y i) := by + induction k with + | zero => simp [trajectoryUnion] + | succ k ih => + simp only [trajectoryUnion,Set.mem_union,ih] + constructor + · rintro (⟨i,hi,hik,hv⟩ | hv) + · exact ⟨i,hi,by omega,hv⟩ + · exact ⟨k+1,by omega,by omega,hv⟩ + · rintro ⟨i,hi,hik,hv⟩ + by_cases he : i = k+1 + · exact Or.inr (he ▸ hv) + · exact Or.inl ⟨i,hi,by omega,hv⟩ + +theorem trajectoryUnion_finite_cap (G : BondGraph V E) (η : ℕ → Set E) (y : ℕ → V) + (k M : ℕ) (hcaps : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : + (trajectoryUnion G η y k).Finite ∧ (trajectoryUnion G η y k).ncard ≤ k*M := by + induction k with + | zero => simp [trajectoryUnion] + | succ k ih => + obtain ⟨hf,hc⟩ := ih (fun i hi hik => hcaps i hi (by omega)) + obtain ⟨hf',hc'⟩ := hcaps (k+1) (by omega) (by omega) + refine ⟨hf.union hf',?_⟩ + calc + _ ≤ (trajectoryUnion G η y k).ncard + (cluster G (η (k+1)) (y (k+1))).ncard := Set.ncard_union_le .. + _ ≤ k*M+M := Nat.add_le_add hc hc' + _ = (k+1)*M := by ring + + + +theorem SpliceTrace.added_subset_trajectory (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) : + cluster G ωf x \ cluster G ω x ⊆ trajectoryUnion G η y k := by + induction h with + | stop => exact fun _ hv => (hv.2 hv.1).elim + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb + intro v hv + by_cases hv' : v ∈ cluster G ω' x + · rw [hC] at hv' + have hvB := hv'.resolve_left hv.2 + exact (mem_trajectoryUnion G η y k v).mpr + ⟨i,by omega,hik,conn_mono G Set.inter_subset_left hvB⟩ + · exact ih ⟨hv.1,hv'⟩ + + + +theorem SpliceTrace.trajectory_hits (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) (hc : c ≠ []) : + (cluster G ω x ∩ trajectoryUnion G η y k).Nonempty := by + cases h with + | stop => exact (hc rfl).elim + | step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht => + exact ⟨a,ha,(mem_trajectoryUnion G η y k a).mpr ⟨i,by omega,hik, + (edge_cluster_sides G (η i) (y i) he hab).mpr (conn_mono G Set.inter_subset_left hb)⟩⟩ + + + +theorem SpliceTrace.added_finite_cap (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : + (cluster G ωf x \ cluster G ω x).Finite ∧ (cluster G ωf x \ cluster G ω x).ncard ≤ k*M := by + obtain ⟨hf,hc⟩ := trajectoryUnion_finite_cap G η y k M hcaps + have hs := h.added_subset_trajectory G x η y k j ω ωf c + exact ⟨hf.subset hs,(Set.ncard_le_ncard hs hf).trans hc⟩ + +end TrajectorySupport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section JointReferenceEvent +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem SpliceTrace.joint_restored_field_symm (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 = + (jointRestored G x η₂ η₁ y₁ ω₂ ω₁ c₁).1 := by + apply exchange_patch_symm _ _ ω₁ ω₂ ωf + (h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep) + · intro e he + rw [← h₁.replay_eq G x η₁ y₁ k j₁ ω₁ ωf c₁] + exact (replaySplice_off_masks G x η₁ y₁ c₁ ω₁ e he).symm + · intro e he + rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf c₂] + exact (replaySplice_off_masks G x η₂ y₂ c₂ ω₂ e he).symm + +theorem SpliceTrace.joint_restored_root (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x = + cluster G ω₁ x ∩ cluster G ω₂ x := by + cases c₁ with + | nil => exact (hc₁ rfl).elim + | cons q r₁ => + obtain ⟨i₁,e₁⟩ := q + cases c₂ with + | nil => exact (hc₂ rfl).elim + | cons q r₂ => + obtain ⟨i₂,e₂⟩ := q + exact h₁.joint_root G x η₁ η₂ y₁ y₂ k j₁ j₂ i₁ i₂ ω₁ ω₂ ωf e₁ e₂ r₁ r₂ h₂ hsep + + + +theorem SpliceTrace.joint_trajectory_hits (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + let A := cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x + (A ∩ trajectoryUnion G η₁ y₁ k).Nonempty ∧ (A ∩ trajectoryUnion G η₂ y₂ k).Nonempty := by + intro A + have hv₁ := (h₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep).1 + have hv₂ := (h₂.joint_virtual G x η₂ η₁ y₂ y₁ k j₂ j₁ ω₂ ω₁ ωf c₂ c₁ h₁ hc₂ hc₁ + (hsep.symm G _ _)).1 + refine ⟨hv₁.trajectory_hits G x η₁ y₁ k j₁ _ ω₂ c₁ hc₁,?_⟩ + change (cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x ∩ _).Nonempty + rw [h₁.joint_restored_field_symm G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep] + exact hv₂.trajectory_hits G x η₂ y₂ k j₂ _ ω₁ c₂ hc₂ + + + +theorem SpliceTrace.joint_restored_size (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ n M : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) + (hf : (cluster G ω₁ x).Finite) (hn : n ≤ (cluster G ω₁ x).ncard) + (h2n : (cluster G ω₁ x).ncard < 2*n) + (hcap₂ : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η₂ i) (y₂ i)).Finite ∧ (cluster G (η₂ i) (y₂ i)).ncard ≤ M) : + let A := cluster G (jointRestored G x η₁ η₂ y₂ ω₁ ω₂ c₂).1 x + A.Finite ∧ n-k*M ≤ A.ncard ∧ A.ncard < 2*n := by + intro A + have hA : A = cluster G ω₁ x ∩ cluster G ω₂ x := + h₁.joint_restored_root G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep + have hdiff : A = cluster G ω₁ x \ (cluster G ωf x \ cluster G ω₂ x) := by + rw [hA] + ext v + constructor + · rintro ⟨h1,h2⟩ + exact ⟨h1,fun hh => hh.2 h2⟩ + · rintro ⟨h1,h2⟩ + refine ⟨h1,?_⟩ + by_contra hn + exact h2 ⟨h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf c₁ h1,hn⟩ + obtain ⟨hBfin,hBcap⟩ := h₂.added_finite_cap G x η₂ y₂ k j₂ M ω₂ ωf c₂ hcap₂ + have hlower := Set.ncard_le_ncard_sdiff_add_ncard (cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x) hBfin + rw [← hdiff] at hlower + refine ⟨hA ▸ hf.inter_of_left _,by omega,?_⟩ + rw [hA] + exact (Set.ncard_inter_le_ncard_left _ _ hf).trans_lt h2n + +end JointReferenceEvent + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SmallHanging +attribute [local instance] Classical.propDecidable Classical.decEq + + +def hangingSide (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : Set V := + cluster G ω x \ cluster G (ω \ {e}) x + +theorem hangingSide_finite (G : BondGraph V E) (ω : Set E) (x : V) (e : E) + (hC : (cluster G ω x).Finite) : (hangingSide G ω x e).Finite := hC.subset Set.sdiff_subset + +theorem mem_hangingSide_iff_pivotal (G : BondGraph V E) (ω : Set E) (x z : V) + (e : E) (he : e ∈ ω) : z ∈ hangingSide G ω x e ↔ OpenMarkedPivotal G ω {z} x e := by + constructor + · rintro ⟨hz,hn⟩ + exact ⟨he,⟨z,rfl,hz⟩,fun ⟨y,hy,hxy⟩ => hn ((Set.mem_singleton_iff.mp hy) ▸ hxy)⟩ + · rintro ⟨_,⟨y,hy,hxy⟩,hn⟩ + exact ⟨(Set.mem_singleton_iff.mp hy) ▸ hxy,fun hz => hn ⟨z,rfl,hz⟩⟩ + +theorem hangingSide_ncard_add_rank (G : BondGraph V E) (ω : Set E) (x : V) + (e : E) (hC : (cluster G ω x).Finite) : + (hangingSide G ω x e).ncard + pivotalRank G ω x e = (cluster G ω x).ncard := by + have hs : cluster G (ω \ {e}) x ⊆ cluster G ω x := fun _ h => conn_mono G Set.sdiff_subset h + rw [hangingSide,Set.ncard_sdiff hs (hC.subset hs)] + exact Nat.sub_add_cancel (Set.ncard_le_ncard hs hC) + + + +noncomputable def smallSeparatingBonds (G : BondGraph V E) (ω : Set E) (x z : V) + (v : ℕ) : Finset E := + (separatingBonds G ω x z).filter fun e => (hangingSide G ω x e).ncard ≤ v + +theorem smallSeparatingBonds_card_le (G : BondGraph V E) (ω : Set E) (x z : V) + (v : ℕ) (hC : (cluster G ω x).Finite) : (smallSeparatingBonds G ω x z v).card ≤ v := by + have hh := Finset.card_le_card_of_injOn (s := smallSeparatingBonds G ω x z v) + (t := Finset.Icc 1 v) (fun e => (hangingSide G ω x e).ncard) + have hmap : Set.MapsTo (fun e => (hangingSide G ω x e).ncard) + (↑(smallSeparatingBonds G ω x z v)) (↑(Finset.Icc 1 v)) := by + intro e he + obtain ⟨he,hcap⟩ := Finset.mem_filter.mp he + have hp := (mem_separatingBonds G ω x z e).mp he + exact Finset.mem_Icc.mpr ⟨(Set.ncard_pos (hangingSide_finite G ω x e hC)).mpr + ⟨z,(mem_hangingSide_iff_pivotal G ω x z e hp.1).mpr hp⟩,hcap⟩ + have hinj : Set.InjOn (fun e => (hangingSide G ω x e).ncard) + (↑(smallSeparatingBonds G ω x z v)) := by + intro e he f hf heq + apply pivotalRank_injective_of_cluster_finite G ω {z} x hC + ((mem_separatingBonds G ω x z e).mp (Finset.mem_filter.mp he).1) + ((mem_separatingBonds G ω x z f).mp (Finset.mem_filter.mp hf).1) + change (hangingSide G ω x e).ncard = (hangingSide G ω x f).ncard at heq + have he' := hangingSide_ncard_add_rank G ω x e hC + have hf' := hangingSide_ncard_add_rank G ω x f hC + omega + simpa only [Nat.card_Icc, Nat.add_sub_cancel] using hh hmap hinj + +noncomputable def smallHangingThrough (G : BondGraph V E) (ω : Set E) (x z : V) + (v : ℕ) (hC : (cluster G ω x).Finite) : Finset V := + (smallSeparatingBonds G ω x z v).biUnion fun e => (hangingSide_finite G ω x e hC).toFinset + +theorem mem_smallHangingThrough (G : BondGraph V E) (ω : Set E) (x z w : V) + (v : ℕ) (hC : (cluster G ω x).Finite) : w ∈ smallHangingThrough G ω x z v hC ↔ + ∃ e, OpenMarkedPivotal G ω {z} x e ∧ (hangingSide G ω x e).ncard ≤ v ∧ + w ∈ hangingSide G ω x e := by + simp [smallHangingThrough, smallSeparatingBonds, and_assoc] + +theorem smallHangingThrough_card_le (G : BondGraph V E) (ω : Set E) (x z : V) + (v : ℕ) (hC : (cluster G ω x).Finite) : + (smallHangingThrough G ω x z v hC).card ≤ v*v := by + calc + _ ≤ ∑ e ∈ smallSeparatingBonds G ω x z v, (hangingSide_finite G ω x e hC).toFinset.card := + Finset.card_biUnion_le + _ ≤ ∑ _e ∈ smallSeparatingBonds G ω x z v, v := by + apply Finset.sum_le_sum + intro e he + rw [← Set.ncard_eq_toFinset_card (hangingSide G ω x e) (hangingSide_finite G ω x e hC)] + exact (Finset.mem_filter.mp he).2 + _ = (smallSeparatingBonds G ω x z v).card*v := by simp + _ ≤ v*v := Nat.mul_le_mul_right v (smallSeparatingBonds_card_le G ω x z v hC) + +end SmallHanging + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NearHanging +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem hangingSide_laminar (G : BondGraph V E) (ω : Set E) (x : V) + (e f : E) (he : e ∈ ω) (hf : f ∈ ω) : + Disjoint (hangingSide G ω x e) (hangingSide G ω x f) ∨ + hangingSide G ω x e ⊆ hangingSide G ω x f ∨ + hangingSide G ω x f ⊆ hangingSide G ω x e := by + by_cases hd : Disjoint (hangingSide G ω x e) (hangingSide G ω x f) + · exact Or.inl hd + obtain ⟨z,hze,hzf⟩ := Set.not_disjoint_iff.mp hd + by_cases hef : e = f + · exact Or.inr (Or.inl (hef ▸ Set.Subset.refl _)) + rcases pivotal_rootSides_nested G ω {z} x + ((mem_hangingSide_iff_pivotal G ω x z e he).mp hze) + ((mem_hangingSide_iff_pivotal G ω x z f hf).mp hzf) hef with h | h + · exact Or.inr (Or.inr (Set.sdiff_subset_sdiff_right h.1)) + · exact Or.inr (Or.inl (Set.sdiff_subset_sdiff_right h.1)) + +noncomputable def graphNeighbors (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset V) : Finset V := A.biUnion (neighbors G hloc) + +theorem graphNeighbors_card_le (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset V) (d : ℕ) (hdeg : ∀ a, degree G a ≤ d) : + (graphNeighbors G hloc A).card ≤ A.card*d := by + calc + _ ≤ ∑ a ∈ A, (neighbors G hloc a).card := Finset.card_biUnion_le + _ ≤ ∑ _a ∈ A, d := Finset.sum_le_sum fun a _ => + (neighbors_card_le_degree G hloc a).trans (hdeg a) + _ = _ := by simp + + + +noncomputable def nearHangingEndpoints (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x z : V) (e : E) (v : ℕ) (hC : (cluster G ω x).Finite) : Finset V := + ((hangingSide_finite G ω x e hC).toFinset ∪ smallHangingThrough G ω x z v hC) ∪ + (graphNeighbors G hloc (hangingSide_finite G ω x e hC).toFinset).biUnion + (fun a => smallHangingThrough G ω x a v hC) + +theorem nearHangingEndpoints_card_le (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x z : V) (e : E) (v d : ℕ) (hC : (cluster G ω x).Finite) + (hcap : (hangingSide G ω x e).ncard ≤ v) (hdeg : ∀ a, degree G a ≤ d) : + (nearHangingEndpoints G hloc ω x z e v hC).card ≤ v+v^2+d*v^3 := by + let B := (hangingSide_finite G ω x e hC).toFinset + let N := graphNeighbors G hloc B + have hB : B.card ≤ v := by + simpa only [B,← Set.ncard_eq_toFinset_card (hangingSide G ω x e) + (hangingSide_finite G ω x e hC)] using hcap + have hN : N.card ≤ v*d := (graphNeighbors_card_le G hloc B d hdeg).trans + (Nat.mul_le_mul_right d hB) + have hU : (N.biUnion fun a => smallHangingThrough G ω x a v hC).card ≤ d*v^3 := by + calc + _ ≤ ∑ a ∈ N, (smallHangingThrough G ω x a v hC).card := Finset.card_biUnion_le + _ ≤ ∑ _a ∈ N, v*v := Finset.sum_le_sum fun a _ => smallHangingThrough_card_le G ω x a v hC + _ = N.card*(v*v) := by simp + _ ≤ (v*d)*(v*v) := Nat.mul_le_mul_right (v*v) hN + _ = d*v^3 := by ring + calc + _ ≤ (B ∪ smallHangingThrough G ω x z v hC).card + + (N.biUnion fun a => smallHangingThrough G ω x a v hC).card := Finset.card_union_le .. + _ ≤ (B.card + (smallHangingThrough G ω x z v hC).card) + d*v^3 := + Nat.add_le_add (Finset.card_union_le ..) hU + _ ≤ (v+v*v)+d*v^3 := Nat.add_le_add_right + (Nat.add_le_add hB (smallHangingThrough_card_le G ω x z v hC)) _ + _ = v+v^2+d*v^3 := by ring + +theorem mem_nearHangingEndpoints_of_not_separated (G : BondGraph V E) + (hloc : LocallyFinite G) (ω : Set E) (x z w : V) (e f : E) (v : ℕ) + (hC : (cluster G ω x).Finite) + (he : OpenMarkedPivotal G ω {z} x e) (hf : OpenMarkedPivotal G ω {w} x f) + (hcap : (hangingSide G ω x f).ncard ≤ v) + (hn : ¬GraphSeparated G (hangingSide G ω x e) (hangingSide G ω x f)) : + w ∈ nearHangingEndpoints G hloc ω x z e v hC := by + have hz := (mem_hangingSide_iff_pivotal G ω x z e he.1).mpr he + have hw := (mem_hangingSide_iff_pivotal G ω x w f hf.1).mpr hf + rcases hangingSide_laminar G ω x e f he.1 hf.1 with hd | hsub | hsub + · have hadj : ∃ a ∈ hangingSide G ω x e, ∃ b ∈ hangingSide G ω x f, Adj G a b := by + by_contra h + apply hn + refine ⟨hd,?_⟩ + intro a ha b hb hab + exact h ⟨a,ha,b,hb,hab⟩ + obtain ⟨a,ha,b,hb,hab⟩ := hadj + apply Finset.mem_union_right + apply Finset.mem_biUnion.mpr + refine ⟨b,Finset.mem_biUnion.mpr ⟨a,?_,(mem_neighbors G hloc a b).mpr hab⟩,?_⟩ + · exact (hangingSide_finite G ω x e hC).mem_toFinset.mpr ha + · exact (mem_smallHangingThrough G ω x b w v hC).mpr + ⟨f,(mem_hangingSide_iff_pivotal G ω x b f hf.1).mp hb,hcap,hw⟩ + · apply Finset.mem_union_left + apply Finset.mem_union_right + exact (mem_smallHangingThrough G ω x z w v hC).mpr + ⟨f,(mem_hangingSide_iff_pivotal G ω x z f hf.1).mp (hsub hz),hcap,hw⟩ + · apply Finset.mem_union_left + apply Finset.mem_union_left + exact (hangingSide_finite G ω x e hC).mem_toFinset.mpr (hsub hw) + +end NearHanging + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteReferenceLaw +attribute [local instance] Classical.propDecidable Classical.decEq + + +abbrev FiniteField (Q : Finset E) := ↥Q.powerset + +def finiteFieldSet (Q : Finset E) (ω : FiniteField Q) : Set E := (ω.val : Set E) + +noncomputable def finiteFieldWeight (Q : Finset E) (p : ℝ) (ω : FiniteField Q) : ℝ := + bernoulliWeight Q ω.val p + +@[simp] theorem domainBits_finiteFieldSet (Q : Finset E) (ω : FiniteField Q) : + domainBits Q (finiteFieldSet Q ω) = ω.val := by + ext e + have hs := Finset.mem_powerset.mp ω.property + simp only [mem_domainBits,finiteFieldSet,Finset.mem_coe] + exact ⟨fun h => h.2,fun h => ⟨hs h,h⟩⟩ + +theorem finiteFieldWeight_nonneg (Q : Finset E) (p : unitInterval) (ω : FiniteField Q) : + 0 ≤ finiteFieldWeight Q p ω := bernoulliWeight_nonneg _ _ p + +theorem sum_finiteFieldWeight (Q : Finset E) (p : ℝ) : + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω = 1 := by + rw [show (fun ω : FiniteField Q => finiteFieldWeight Q p ω) = + (fun ω : FiniteField Q => bernoulliWeight Q ω.val p) from rfl,Finset.sum_coe_sort Q.powerset (fun ω => bernoulliWeight Q ω p)] + simpa only [bernoulliPolynomial,bernoulliWeight,mul_one,one_mul] using bernoulliPolynomial_const Q 1 p + + + +def finiteFieldFamily (Q : Finset E) (J : Finset ℕ) (η : ↥J → FiniteField Q) : ℕ → Set E := + fun i => if hi : i ∈ J then finiteFieldSet Q (η ⟨i,hi⟩) else ∅ + +@[simp] theorem finiteFieldFamily_at (Q : Finset E) (J : Finset ℕ) + (η : ↥J → FiniteField Q) (i : ↥J) : + finiteFieldFamily Q J η i = finiteFieldSet Q (η i) := by + simp [finiteFieldFamily,i.property] + +noncomputable def finiteFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (η : ↥J → FiniteField Q) : ℝ := ∏ i, finiteFieldWeight Q p (η i) + +theorem finiteFamilyWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (η : ↥J → FiniteField Q) : 0 ≤ finiteFamilyWeight Q J p η := + Finset.prod_nonneg fun _ _ => finiteFieldWeight_nonneg Q p _ + +theorem sum_finiteFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) : + ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η = 1 := by + unfold finiteFamilyWeight + rw [← Fintype.prod_sum] + simp only [sum_finiteFieldWeight,Finset.prod_const_one] + +theorem prod_fieldFamilyWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (η : ↥J → FiniteField Q) : + (∏ i ∈ J, bernoulliWeight Q (domainBits Q (finiteFieldFamily Q J η i)) p) = + finiteFamilyWeight Q J p η := by + rw [← Finset.prod_coe_sort J] + simp only [finiteFieldFamily_at,domainBits_finiteFieldSet,finiteFamilyWeight,finiteFieldWeight] + +abbrev FiniteJointData (Q : Finset E) (J₁ J₂ : Finset ℕ) := + FiniteField Q × (↥J₁ → FiniteField Q) × (↥J₂ → FiniteField Q) + +def encodeFiniteJoint (Q : Finset E) (J₁ J₂ : Finset ℕ) + (s : FiniteJointData Q J₁ J₂) : JointSpliceState E := + (finiteFieldSet Q s.1,finiteFieldFamily Q J₁ s.2.1,finiteFieldFamily Q J₂ s.2.2) + +theorem finiteFieldSet_injective (Q : Finset E) : Function.Injective (finiteFieldSet Q) := by + intro a b he + exact Subtype.ext (Finset.coe_injective he) + +theorem finiteFieldFamily_injective (Q : Finset E) (J : Finset ℕ) : + Function.Injective (finiteFieldFamily Q J) := by + intro a b he + funext i + apply finiteFieldSet_injective Q + simpa only [finiteFieldFamily_at] using congrFun he i + +theorem encodeFiniteJoint_injective (Q : Finset E) (J₁ J₂ : Finset ℕ) : + Function.Injective (encodeFiniteJoint Q J₁ J₂) := by + intro a b he + apply Prod.ext (finiteFieldSet_injective Q (congrArg Prod.fst he)) + exact Prod.ext (finiteFieldFamily_injective Q J₁ (congrArg (fun s => s.2.1) he)) + (finiteFieldFamily_injective Q J₂ (congrArg (fun s => s.2.2) he)) + +theorem jointTupleWeight_encode (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (s : FiniteJointData Q J₁ J₂) : + jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) = + finiteFieldWeight Q p s.1 * finiteFamilyWeight Q J₁ p s.2.1 * + finiteFamilyWeight Q J₂ p s.2.2 := by + simp only [jointTupleWeight,encodeFiniteJoint,domainBits_finiteFieldSet, + prod_fieldFamilyWeight,finiteFieldWeight] + + + +theorem sum_jointTupleWeight_encode (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) : + ∑ s : FiniteJointData Q J₁ J₂, jointTupleWeight Q J₁ J₂ p (encodeFiniteJoint Q J₁ J₂ s) = 1 := by + simp_rw [jointTupleWeight_encode] + rw [Fintype.sum_prod_type] + simp_rw [Fintype.sum_prod_type,← Finset.mul_sum,sum_finiteFamilyWeight,mul_one, + ← Finset.mul_sum,sum_finiteFamilyWeight,mul_one] + exact sum_finiteFieldWeight Q p + +end FiniteReferenceLaw + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteReferenceFactor +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def finiteFamilyEvent (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (H : (ℕ → Set E) → Prop) : ℝ := + ∑ η : ↥J → FiniteField Q, finiteFamilyWeight Q J p η * + if H (finiteFieldFamily Q J η) then 1 else 0 + +theorem finiteFamilyEvent_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (H : (ℕ → Set E) → Prop) : 0 ≤ finiteFamilyEvent Q J p H := by + apply Finset.sum_nonneg + intro η _ + exact mul_nonneg (finiteFamilyWeight_nonneg Q J p η) (by split <;> norm_num) + +theorem finiteFamilyEvent_le_one (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (H : (ℕ → Set E) → Prop) : finiteFamilyEvent Q J p H ≤ 1 := by + rw [← sum_finiteFamilyWeight Q J p] + apply Finset.sum_le_sum + intro η _ + exact mul_le_of_le_one_right (finiteFamilyWeight_nonneg Q J p η) (by split <;> norm_num) + +noncomputable def finiteJointDomain (Q : Finset E) (J₁ J₂ : Finset ℕ) : + Finset (JointSpliceState E) := Finset.univ.image (encodeFiniteJoint Q J₁ J₂) + +theorem finiteJointDomain_event_factor (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (P : Set E → Prop) (H₁ H₂ : Set E → (ℕ → Set E) → Prop) : + (∑ s ∈ (finiteJointDomain Q J₁ J₂).filter (fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2), + jointTupleWeight Q J₁ J₂ p s) = + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if P (finiteFieldSet Q ω) then + finiteFamilyEvent Q J₁ p (H₁ (finiteFieldSet Q ω)) * + finiteFamilyEvent Q J₂ p (H₂ (finiteFieldSet Q ω)) else 0) := by + rw [Finset.sum_filter,finiteJointDomain,Finset.sum_image (encodeFiniteJoint_injective Q J₁ J₂).injOn, + Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro ω _ + rw [Fintype.sum_prod_type] + by_cases hP : P (finiteFieldSet Q ω) + · simp only [encodeFiniteJoint, hP, true_and,ite_true] + have heq (η₁ : ↥J₁ → FiniteField Q) (η₂ : ↥J₂ → FiniteField Q) : + (if H₁ (finiteFieldSet Q ω) (finiteFieldFamily Q J₁ η₁) ∧ + H₂ (finiteFieldSet Q ω) (finiteFieldFamily Q J₂ η₂) then + jointTupleWeight Q J₁ J₂ p + (finiteFieldSet Q ω,finiteFieldFamily Q J₁ η₁,finiteFieldFamily Q J₂ η₂) else 0) = + finiteFieldWeight Q p ω * + (finiteFamilyWeight Q J₁ p η₁ * if H₁ (finiteFieldSet Q ω) (finiteFieldFamily Q J₁ η₁) then 1 else 0) * + (finiteFamilyWeight Q J₂ p η₂ * if H₂ (finiteFieldSet Q ω) (finiteFieldFamily Q J₂ η₂) then 1 else 0) := by + have hw := jointTupleWeight_encode Q J₁ J₂ p (ω,η₁,η₂) + change jointTupleWeight Q J₁ J₂ p (finiteFieldSet Q ω,finiteFieldFamily Q J₁ η₁,finiteFieldFamily Q J₂ η₂) = _ at hw + rw [hw] + split_ifs <;> simp_all + simp_rw [heq,← Finset.mul_sum,← Finset.sum_mul] + rw [← Finset.mul_sum,mul_assoc] + rfl + · simp [encodeFiniteJoint,hP] + + + +theorem mem_finiteJointDomain_of_support (Q : Finset E) (J₁ J₂ : Finset ℕ) + (s : JointSpliceState E) (hω : s.1 ⊆ (Q : Set E)) + (hη₁ : ∀ i, s.2.1 i ⊆ (Q : Set E)) (hη₂ : ∀ i, s.2.2 i ⊆ (Q : Set E)) + (hz₁ : ∀ i ∉ J₁, s.2.1 i = ∅) (hz₂ : ∀ i ∉ J₂, s.2.2 i = ∅) : + s ∈ finiteJointDomain Q J₁ J₂ := by + let desc (ω : Set E) : FiniteField Q := ⟨domainBits Q ω,Finset.mem_powerset.mpr (domainBits_subset Q ω)⟩ + have hdesc (ω : Set E) (h : ω ⊆ (Q : Set E)) : finiteFieldSet Q (desc ω) = ω := by + ext e + simp only [finiteFieldSet,desc,Finset.mem_coe,mem_domainBits] + exact ⟨fun hh => hh.2,fun hh => ⟨h hh,hh⟩⟩ + let a : FiniteJointData Q J₁ J₂ := (desc s.1,fun i => desc (s.2.1 i),fun i => desc (s.2.2 i)) + apply Finset.mem_image.mpr + refine ⟨a,Finset.mem_univ _,?_⟩ + apply Prod.ext (hdesc s.1 hω) + apply Prod.ext + · funext i + change (if hi : i ∈ J₁ then finiteFieldSet Q (desc (s.2.1 i)) else ∅) = s.2.1 i + by_cases hi : i ∈ J₁ + · simp only [hi,dite_true,hdesc _ (hη₁ i)] + · simp only [hi,dite_false,hz₁ i hi] + · funext i + change (if hi : i ∈ J₂ then finiteFieldSet Q (desc (s.2.2 i)) else ∅) = s.2.2 i + by_cases hi : i ∈ J₂ + · simp only [hi,dite_true,hdesc _ (hη₂ i)] + · simp only [hi,dite_false,hz₂ i hi] + +theorem exchangeOn_subset (M ω η Q : Set E) (hω : ω ⊆ Q) (hη : η ⊆ Q) : + exchangeOn M ω η ⊆ Q := by + rintro e (⟨he,_⟩ | ⟨he,_⟩) + · exact hω he + · exact hη he + +end FiniteReferenceFactor + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteSeparatedSecondMoment +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_separated_second_moment_le {I : Type*} [Fintype I] + (G : BondGraph V E) (x : V) (k n M : ℕ) (p : unitInterval) (Q : Finset E) + (η₁ η₂ : I → ℕ → Set E) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (success₁ success₂ : (ℕ → Set E) → Prop) + (choose₁ choose₂ : ℕ → Set E → E) + (ω₁ ω₂ ωf : I → Set E) (c₁ c₂ : I → List (ℕ × E)) + (hir : Function.Injective (fun a => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a), + c₁ a,c₂ a))) + (h₁ : ∀ a, SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a)) + (h₂ : ∀ a, SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a)) + (hc₁ : ∀ a, c₁ a ≠ []) (hc₂ : ∀ a, c₂ a ≠ []) + (hsep : ∀ a, GraphSeparated G (cluster G (ωf a) x \ cluster G (ω₁ a) x) + (cluster G (ωf a) x \ cluster G (ω₂ a) x)) + (hr₁ : ∀ a, FollowsContactRule G x (η₁ a) (y₁ (η₁ a)) choose₁ (c₁ a) (ω₁ a)) + (hr₂ : ∀ a, FollowsContactRule G x (η₂ a) (y₂ (η₂ a)) choose₂ (c₂ a) (ω₂ a)) + (hbin : ∀ a, (cluster G (ω₁ a) x).Finite ∧ n ≤ (cluster G (ω₁ a) x).ncard ∧ + (cluster G (ω₁ a) x).ncard < 2*n) + (hcap₂ : ∀ a i, 1 ≤ i → i ≤ k → (cluster G (η₂ a i) (y₂ (η₂ a) i)).Finite ∧ + (cluster G (η₂ a i) (y₂ (η₂ a) i)).ncard ≤ M) + (hsc₁ : ∀ a, success₁ (η₁ a)) (hsc₂ : ∀ a, success₂ (η₂ a)) + (hsω₁ : ∀ a, ω₁ a ⊆ (Q : Set E)) (hsω₂ : ∀ a, ω₂ a ⊆ (Q : Set E)) + (hsη₁ : ∀ a i, η₁ a i ⊆ (Q : Set E)) (hsη₂ : ∀ a i, η₂ a i ⊆ (Q : Set E)) + (hz₁ : ∀ a i, i ∉ Finset.Icc 1 k → η₁ a i = ∅) + (hz₂ : ∀ a i, i ∉ Finset.Icc 1 k → η₂ a i = ∅) : + (∑ a, jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a))) ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₁ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty) * + finiteFamilyEvent Q (Finset.Icc 1 k) p (fun η => success₂ η ∧ + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty) else 0) := by + let J := Finset.Icc 1 k + let P (ω : Set E) := (cluster G ω x).Finite ∧ n-k*M ≤ (cluster G ω x).ncard ∧ + (cluster G ω x).ncard < 2*n + let H₁ (ω : Set E) (η : ℕ → Set E) := success₁ η ∧ + (cluster G ω x ∩ trajectoryUnion G η (y₁ η) k).Nonempty + let H₂ (ω : Set E) (η : ℕ → Set E) := success₂ η ∧ + (cluster G ω x ∩ trajectoryUnion G η (y₂ η) k).Nonempty + let B := (finiteJointDomain Q J J).filter fun s => P s.1 ∧ H₁ s.1 s.2.1 ∧ H₂ s.1 s.2.2 + have hB (a : I) : jointRestored G x (η₁ a) (η₂ a) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (c₂ a) ∈ B := by + apply Finset.mem_filter.mpr + refine ⟨mem_finiteJointDomain_of_support Q J J _ + (exchangeOn_subset _ _ _ _ (hsω₁ a) (hsω₂ a)) (hsη₁ a) (hsη₂ a) (hz₁ a) (hz₂ a),?_⟩ + have hroot := (h₁ a).joint_restored_size G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + k 0 0 n M (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) + (hbin a).1 (hbin a).2.1 (hbin a).2.2 (hcap₂ a) + have hhits := (h₁ a).joint_trajectory_hits G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + k 0 0 (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) (h₂ a) (hc₁ a) (hc₂ a) (hsep a) + exact ⟨hroot,⟨hsc₁ a,hhits.1⟩,hsc₂ a,hhits.2⟩ + have h := finite_joint_mass_le G x k p Q η₁ η₂ y₁ y₂ choose₁ choose₂ ω₁ ω₂ ωf c₁ c₂ + hir h₁ h₂ hc₁ hc₂ hsep hr₁ hr₂ B hB + apply h.trans_eq + convert finiteJointDomain_event_factor Q J J p P H₁ H₂ using 1 <;> simp [B,J,P,H₁,H₂] + +end FiniteSeparatedSecondMoment + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SeededForward +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem exists_seeded_spliceTrace (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k M : ℕ) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M) + (choose : ℕ → Set E → E) + (hchoose : ∀ i K, K.Finite → K.Nonempty → choose i K ∈ K) + (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) + (N : ℕ) (hfin : (cluster G ω x).Finite) (hN : (cluster G ω x).ncard ≤ N) : + ∃ steps ωf, SpliceTrace G x η y k j ω steps ωf ∧ + FollowsContactRule G x η y choose steps ω ∧ steps.length ≤ k-j ∧ + y k ∈ cluster G ωf x ∧ (cluster G ωf x).Finite ∧ + (cluster G ωf x).ncard ≤ N+(k-j)*M := by + generalize hn : k-j = n + induction n using Nat.strong_induction_on generalizing j ω N with + | h n ih => + by_cases hz : y k ∈ cluster G ω x + · refine ⟨[],ω,SpliceTrace.stop j ω hz,?_,by simp,hz,hfin,?_⟩ + · exact List.Forall₂.nil + · exact hN.trans (Nat.le_add_right ..) + · obtain ⟨i,hiI,hmeet,hyi,hmax⟩ := + exists_maximal_splice_index G η y k j hj hchain (cluster G ω x) hyj hz + obtain ⟨hji,hik⟩ := Finset.mem_Icc.mp hiI + have hi1 : i ∈ Finset.Icc 1 k := Finset.mem_Icc.mpr ⟨by omega,hik⟩ + let B := cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i) + let K := contactSet G (η i) B + have hBC : B ⊆ cluster G (η i) (y i) := fun _ h => conn_mono G Set.inter_subset_left h + have hBK : K.Finite := contactSet_finite G hloc (η i) B ((hcaps i hi1).1.subset hBC) + have hK : K.Nonempty := by + obtain ⟨e,a,b,he,hab,ha,hb⟩ := exists_splice_contact G (η i) (cluster G ω x) (y i) hyi hmeet + exact ⟨e,he,b,a,hab.trans (Sym2.eq_swap ..),hb, + fun h => slit_cluster_subset G (cluster G ω x) (η i) (y i) hyi h ha⟩ + let e := choose i K + have heK : e ∈ contactSet G (η i) B := hchoose i K hBK hK + change e ∈ contactSet G (η i) + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) at heK + rw [contactSet_deleted_cluster G (η i) (cluster G ω x) (y i) hyi] at heK + obtain ⟨he,b,hb,a,ha,hba⟩ := heK + have hab : G e = s(a,b) := hba.trans (Sym2.eq_swap ..) + let ω' := spliceField G (cluster G ω x) B e ω (η i) + have hcap := splice_cluster_cap G ω (η i) x (y i) hyi e a b hab he ha hb N M hfin hN + (hcaps i hi1).1 (hcaps i hi1).2 + have hyt : y i ∈ cluster G ω' x := by + change y i ∈ cluster G (spliceField G (cluster G ω x) B e ω (η i)) x + rw [splice_cluster G ω (η i) x (y i) hyi e a b hab he ha hb] + exact Or.inr (mem_cluster_self G _ _) + obtain ⟨steps,ωf,htrace,hrule,hlen,hconn,hf,hs⟩ := + ih (k-i) (by omega) i hik ω' hyt (N+M) hcap.1 hcap.2 rfl + refine ⟨(i,e)::steps,ωf, + SpliceTrace.step j i ω e a b steps ωf hz (by omega) hik hmax hyi he hab ha hb htrace, + ?_,?_,hconn,hf,?_⟩ + · exact (followsContactRule_cons G x η y choose i e steps ω).mpr ⟨rfl,hrule⟩ + · simp only [List.length_cons] + omega + · have hm : (k-i+1)*M ≤ (k-j)*M := Nat.mul_le_mul_right M (by omega) + rw [Nat.add_mul,one_mul] at hm + calc + _ ≤ (N+M)+(k-i)*M := hs + _ ≤ N+(k-j)*M := by omega + _ = N+n*M := by rw [hn] + + + +theorem existsUnique_seeded_spliceTrace (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k M : ℕ) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M) + (choose : ℕ → Set E → E) + (hchoose : ∀ i K, K.Finite → K.Nonempty → choose i K ∈ K) + (j : ℕ) (hj : j ≤ k) (ω : Set E) (hyj : y j ∈ cluster G ω x) + (hfin : (cluster G ω x).Finite) : + ∃! out : List (ℕ × E) × Set E, + SpliceTrace G x η y k j ω out.1 out.2 ∧ + FollowsContactRule G x η y choose out.1 ω := by + obtain ⟨c,ωf,ht,hr,_⟩ := exists_seeded_spliceTrace G hloc x η y k M hchain hcaps + choose hchoose j hj ω hyj _ hfin (le_refl _) + refine ⟨(c,ωf),⟨ht,hr⟩,?_⟩ + rintro ⟨d,σf⟩ ⟨hs,hd⟩ + obtain ⟨hc,hf⟩ := hs.seeded_unique G x η y k j ω σf ωf d c ht choose hd hr + exact Prod.ext hc hf + +end SeededForward +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SpliceLocalSupport +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem reachBall_triangle (G : BondGraph V E) (x y : V) (n m : ℕ) + (hy : y ∈ reachBall G x n) : reachBall G y m ⊆ reachBall G x (n+m) := by + induction m with + | zero => simpa only [reachBall,Nat.add_zero,Set.singleton_subset_iff] using hy + | succ m ih => + intro z hz + rcases hz with hz | hz + · exact Or.inl (ih hz) + · apply Or.inr + simp only [Set.mem_iUnion,Set.mem_ofPred_eq] at hz ⊢ + obtain ⟨a,ha,haz⟩ := hz + exact ⟨a,ih ha,haz⟩ + + +theorem capped_cluster_ball_of_mem (G : BondGraph V E) (ω : Set E) (x y : V) + (hfin : (cluster G ω x).Finite) (M : ℕ) (hM : (cluster G ω x).ncard ≤ M) + (hy : y ∈ cluster G ω x) : cluster G ω x ⊆ reachBall G y M := by + have he := cluster_eq_of_conn G ω hy + rw [he] at hfin hM ⊢ + exact finite_cluster_subset_reachBall G ω y hfin M hM + + + +theorem oldChain_local_support (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k M N : ℕ) + (hstart : y 0 ∈ reachBall G x N) + (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : + (∀ i, i ≤ k → y i ∈ reachBall G x (N+i*M)) ∧ + trajectoryUnion G η y k ⊆ reachBall G x (N+k*M) := by + have hvertex : ∀ i, i ≤ k → y i ∈ reachBall G x (N+i*M) := by + intro i + induction i with + | zero => simpa using hstart + | succ i ih => + intro hik + obtain ⟨hf,hM⟩ := hcaps (i+1) (by omega) hik + have hc := capped_cluster_ball_of_mem G (η (i+1)) (y (i+1)) (y i) hf M hM + (by simpa only [Nat.add_sub_cancel,cluster,Set.mem_ofPred_eq] using hchain (i+1) (by omega) hik) + have hh := reachBall_triangle G x (y i) (N+i*M) M (ih (by omega)) + (hc (mem_cluster_self G _ _)) + convert hh using 1 + congr 1 + ring + refine ⟨hvertex,?_⟩ + intro v hv + obtain ⟨i,hi,hik,hv⟩ := (mem_trajectoryUnion G η y k v).mp hv + obtain ⟨hf,hM⟩ := hcaps i hi hik + have hc := capped_cluster_ball_of_mem G (η i) (y i) (y (i-1)) hf M hM (hchain i hi hik) + have hh := reachBall_triangle G x (y (i-1)) (N+(i-1)*M) M + (hvertex (i-1) (by omega)) (hc hv) + apply reachBall_mono_local G x _ hh + have hmul : i*M ≤ k*M := Nat.mul_le_mul_right M hik + have he : (i-1)*M+M = i*M := by + calc _ = (i-1+1)*M := by ring + _ = i*M := by rw [Nat.sub_add_cancel hi] + omega + + + +theorem SpliceTrace.masks_in_deterministic_ball (G : BondGraph V E) + (hloc : LocallyFinite G) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (k j M N : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) + (hstart : y 0 ∈ reachBall G x N) + (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) : + maskUnion (replayMasks G x η y c ω) ⊆ + (incidentSupport G hloc (finite_reachBall hloc x (N+k*M)).toFinset : Set E) := by + intro e he + obtain ⟨b,hb,hbe⟩ := h.masks_incident G x η y k j ω ωf c e he + have hbt := h.added_subset_trajectory G x η y k j ω ωf c hb + have hball := (oldChain_local_support G x η y k M N hstart hchain hcaps).2 hbt + exact (mem_incidentSupport G hloc _ e).mpr ⟨b,by simpa using hball,hbe⟩ + + + +theorem oldChain_query_support (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k M N R : ℕ) + (hstart : y 0 ∈ reachBall G x N) + (hchain : ∀ i, 1 ≤ i → i ≤ k → Conn G (η i) (y i) (y (i-1))) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M) + (i : ℕ) (hi : i ≤ k) : + reachBall G (y i) R ⊆ reachBall G x (N+k*M+R) := by + have hv := (oldChain_local_support G x η y k M N hstart hchain hcaps).1 i hi + intro z hz + have hh := reachBall_triangle G x (y i) (N+i*M) R hv hz + exact reachBall_mono_local G x (by nlinarith) hh + +end SpliceLocalSupport +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section UniformContactSelector +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def uniformRank (K : ℕ) (hK : 0 < K) (t : unitInterval) : Fin K := + ⟨min ⌊(K:ℝ)*(t:ℝ)⌋₊ (K-1), lt_of_le_of_lt (min_le_right ..) (by omega)⟩ + +theorem uniformRank_val_of_lt_one (K : ℕ) (hK : 0 < K) (t : unitInterval) + (ht : (t:ℝ) < 1) : (uniformRank K hK t).val = ⌊(K:ℝ)*(t:ℝ)⌋₊ := by + have hp : (0:ℝ) < K := by exact_mod_cast hK + have hf : ⌊(K:ℝ)*(t:ℝ)⌋₊ < K := (Nat.floor_lt (mul_nonneg (Nat.cast_nonneg _) t.property.1)).mpr (by nlinarith) + exact min_eq_left (by omega) + +theorem uniformRank_eq_iff (K : ℕ) (hK : 0 < K) (t : unitInterval) + (ht : (t:ℝ) < 1) (a : Fin K) : + uniformRank K hK t = a ↔ t ∈ contactInterval K a.val := by + rw [Fin.ext_iff,uniformRank_val_of_lt_one K hK t ht, + Nat.floor_eq_iff (mul_nonneg (Nat.cast_nonneg _) t.property.1)] + have hp : (0:ℝ) < K := by exact_mod_cast hK + simp only [contactInterval,Set.mem_ofPred_eq,Nat.cast_add,Nat.cast_one] + rw [div_le_iff₀ hp,lt_div_iff₀ hp] + simp only [mul_comm] + +theorem volume_uniformRank_fiber (K : ℕ) (hK : 0 < K) (a : Fin K) : + volume {t : unitInterval | uniformRank K hK t = a} = + ENNReal.ofReal ((K:ℝ)⁻¹) := by + rw [← volume_contactInterval K a.val a.isLt] + apply measure_congr + filter_upwards [(volume : Measure unitInterval).ae_ne 1] with t ht + exact propext (uniformRank_eq_iff K hK t (lt_of_le_of_ne t.property.2 + (fun he => ht (Subtype.ext he))) a) + + + +noncomputable def uniformContact (K : Finset E) (hK : K.Nonempty) + (t : unitInterval) : E := + ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).val + +theorem uniformContact_mem (K : Finset E) (hK : K.Nonempty) (t : unitInterval) : + uniformContact K hK t ∈ K := + ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).property + +theorem uniformContact_eq_iff (K : Finset E) (hK : K.Nonempty) (t : unitInterval) + (e : E) (he : e ∈ K) : + uniformContact K hK t = e ↔ + uniformRank K.card (Finset.card_pos.mpr hK) t = K.equivFin ⟨e,he⟩ := by + unfold uniformContact + change ((K.equivFin).symm (uniformRank K.card (Finset.card_pos.mpr hK) t)).val = + (⟨e,he⟩ : ↥K).val ↔ _ + rw [← Subtype.ext_iff] + exact K.equivFin.symm_apply_eq + +theorem volume_uniformContact_fiber (K : Finset E) (hK : K.Nonempty) + (e : E) (he : e ∈ K) : volume {t : unitInterval | uniformContact K hK t = e} = + ENNReal.ofReal ((K.card:ℝ)⁻¹) := by + simp_rw [uniformContact_eq_iff K hK _ e he] + exact volume_uniformRank_fiber K.card (Finset.card_pos.mpr hK) _ + + + +noncomputable def chooseContact [Nonempty E] (seed : ℕ → unitInterval) + (i : ℕ) (K : Set E) : E := + if hf : K.Finite then if hn : K.Nonempty then + uniformContact hf.toFinset (by simpa using hn) (seed i) + else Classical.arbitrary E else Classical.arbitrary E + +theorem chooseContact_mem [Nonempty E] (seed : ℕ → unitInterval) + (i : ℕ) (K : Set E) (hf : K.Finite) (hn : K.Nonempty) : + chooseContact seed i K ∈ K := by + simp only [chooseContact,dite_eq_left hf,dite_eq_left hn] + exact hf.mem_toFinset.mp (uniformContact_mem _ _ _) + +end UniformContactSelector +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section SeededTraceLaw +attribute [local instance] Classical.propDecidable Classical.decEq +variable [Nonempty E] + + +theorem chooseContact_congr (u v : ℕ → unitInterval) (i : ℕ) (K : Set E) + (h : u i = v i) : chooseContact u i K = chooseContact v i K := by + unfold chooseContact + split_ifs <;> simp only [h] + + +noncomputable def replaySeedFiber (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) : List (ℕ × E) → Set E → ℕ → Set unitInterval + | [], _, _ => Set.univ + | (j,e)::c, ω, i => + let S := cluster G ω x + let B := cluster G (η j ∩ internalEdges G Sᶜ) (y j) + if i = j then {t | chooseContact (fun _ => t) j (contactSet G (η j) B) = e} + else replaySeedFiber G x η y c (spliceField G S B e ω (η j)) i + +theorem replaySeedFiber_univ (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (i : ℕ) + (hi : ∀ q ∈ c, i ≠ q.1) : replaySeedFiber G x η y c ω i = Set.univ := by + induction c generalizing ω with + | nil => rfl + | cons q c ih => + obtain ⟨j,e⟩ := q + simp only [replaySeedFiber,ite_eq_right (hi (j,e) (by simp))] + exact ih _ (fun q hq => hi q (by simp [hq])) + +theorem SpliceTrace.follows_iff_seedFiber (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) + (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) + (seed : ℕ → unitInterval) : + FollowsContactRule G x η y (chooseContact seed) c ω ↔ + ∀ i, 1 ≤ i → i ≤ k → seed i ∈ replaySeedFiber G x η y c ω i := by + induction h with + | stop j ω hz => simp [FollowsContactRule,replayContacts,replaySeedFiber] + | @step j l ω e a b c ωf hn hjl hlk hm hy he hab ha hb ht ih => + rw [followsContactRule_cons,ih] + have htail : replaySeedFiber G x η y c + (spliceField G (cluster G ω x) + (cluster G (η l ∩ internalEdges G (cluster G ω x)ᶜ) (y l)) e ω (η l)) l = Set.univ := by + apply replaySeedFiber_univ + intro q hq + have hq' := ht.seam_data G x η y k l _ ωf c q hq + omega + constructor + · rintro ⟨hc,hr⟩ i hi hik + by_cases hil : i = l + · subst i + simp only [replaySeedFiber,ite_true,Set.mem_ofPred_eq] + exact (chooseContact_congr _ _ l _ rfl).trans hc + · simpa only [replaySeedFiber,ite_eq_right hil] using hr i hi hik + · intro hr + constructor + · have hh := hr l (by omega) hlk + simp only [replaySeedFiber,ite_true,Set.mem_ofPred_eq] at hh + exact (chooseContact_congr _ _ l _ rfl).trans hh + · intro i hi hik + by_cases hil : i = l + · subst i + rw [htail] + trivial + · simpa only [replaySeedFiber,ite_eq_right hil] using hr i hi hik + + + +def finiteContactSeeds (k : ℕ) (u : Fin k → unitInterval) (i : ℕ) : unitInterval := + if hi : 1 ≤ i ∧ i ≤ k then u ⟨i-1,by omega⟩ else 0 + +@[simp] theorem finiteContactSeeds_at (k : ℕ) (u : Fin k → unitInterval) (i : Fin k) : + finiteContactSeeds k u (i.val+1) = u i := by + have hi : 1 ≤ i.val+1 ∧ i.val+1 ≤ k := ⟨by omega,by omega⟩ + simp only [finiteContactSeeds,dite_eq_left hi,Nat.add_sub_cancel] + +theorem SpliceTrace.seed_event_eq_pi (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) + (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) : + {u : Fin k → unitInterval | FollowsContactRule G x η y + (chooseContact (finiteContactSeeds k u)) c ω} = + Set.pi Set.univ (fun i => replaySeedFiber G x η y c ω (i.val+1)) := by + ext u + rw [Set.mem_ofPred_eq,h.follows_iff_seedFiber G x η y k j ω ωf c] + simp only [Set.mem_pi,Set.mem_univ,true_implies] + constructor + · intro hu i + simpa only [finiteContactSeeds_at] using hu (i.val+1) (by omega) (by omega) + · intro hu i hi hik + have hh := hu ⟨i-1,by omega⟩ + have hii : 1 ≤ i ∧ i ≤ k := ⟨hi,hik⟩ + simpa only [finiteContactSeeds,dite_eq_left hii,Nat.sub_add_cancel hi] using hh + + + +theorem SpliceTrace.volume_seedFiber (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) + (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite) : + ∀ i, volume (replaySeedFiber G x η y c ω i) = + ENNReal.ofReal ((traceContactCount G η y ωf x c i : ℝ)⁻¹) := by + induction c generalizing j ω with + | nil => simp [replaySeedFiber,traceContactCount] + | cons q c ih => + obtain ⟨l,e⟩ := q + have hcut := h.head_cut G x η y k j l ω ωf e c + cases h with + | step j l ω e a b c ωf hn hjl hlk hm hy he hab ha hb ht => + intro i + by_cases hil : i = l + · subst i + simp only [replaySeedFiber,ite_true,traceContactCount,seamContactCount,hcut] + let B := cluster G (η l ∩ internalEdges G (cluster G ω x)ᶜ) (y l) + let K := contactSet G (η l) B + have hB : B.Finite := (hcaps l (by omega) hlk).subset (fun _ h => conn_mono G Set.inter_subset_left h) + have hK : K.Finite := contactSet_finite G hloc (η l) B hB + have heK : e ∈ K := ⟨he,b,a,hab.trans (Sym2.eq_swap ..),hb, + fun haB => slit_cluster_subset G (cluster G ω x) (η l) (y l) hy haB ha⟩ + have hnK : K.Nonempty := ⟨e,heK⟩ + change volume {t : unitInterval | chooseContact (fun _ => t) l K = e} = _ + simp only [chooseContact,dite_eq_left hK,dite_eq_left hnK] + rw [volume_uniformContact_fiber _ _ e (hK.mem_toFinset.mpr heK)] + rw [← Set.ncard_eq_toFinset_card K hK] + · simpa only [replaySeedFiber,traceContactCount,ite_eq_right hil] using ih l _ ht i + + +theorem SpliceTrace.seed_probability (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) + (c : List (ℕ × E)) (h : SpliceTrace G x η y k j ω c ωf) + (hcaps : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite) : + ((volume : Measure (Fin k → unitInterval)) + {u | FollowsContactRule G x η y (chooseContact (finiteContactSeeds k u)) c ω}).toReal = + ∏ i : Fin k, (traceContactCount G η y ωf x c (i.val+1):ℝ)⁻¹ := by + rw [h.seed_event_eq_pi G x η y k j ω ωf c,MeasureTheory.volume_pi,Measure.pi_pi,ENNReal.toReal_prod] + apply Finset.prod_congr rfl + intro i _ + rw [h.volume_seedFiber G hloc x η y k j ω ωf c hcaps,ENNReal.toReal_ofReal (by positivity)] + +end SeededTraceLaw +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Splicing/Replay.lean b/lean/OAI/Probability/UnimodularPercolation/Splicing/Replay.lean index 3a05cef2328613303a355e0a6d44ff021f08cde4..a206dd03529abf8e920845b276fda0b0f48c9177 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Splicing/Replay.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Splicing/Replay.lean @@ -1,1245 +1,1245 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.GapCodes - -namespace OAI - -/-! Replay for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SparseGapCode -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def ValidSparseGapCode (k M : ℕ) (c : List (ℕ × ℕ)) : Prop := - c.Pairwise (fun q r => q.1 < r.1) ∧ - ∀ q ∈ c, 1 ≤ q.1 ∧ q.1 ≤ k ∧ 1 ≤ q.2 ∧ q.2 ≤ M - -def sparseGapValue : List (ℕ × ℕ) → ℕ → ℕ - | [], _ => 0 - | (j,l)::c, i => if i = j then l else sparseGapValue c i - -theorem sparseGapValue_zero (c : List (ℕ × ℕ)) (i : ℕ) - (h : ∀ q ∈ c, i ≠ q.1) : sparseGapValue c i = 0 := by - induction c with - | nil => rfl - | cons q c ih => - obtain ⟨j,l⟩ := q - rw [sparseGapValue,ite_eq_right (h (j,l) (by simp))] - exact ih (fun q hq => h q (List.mem_cons_of_mem _ hq)) - -theorem sparseGapValue_bound (k M : ℕ) (c : List (ℕ × ℕ)) - (h : ValidSparseGapCode k M c) (i : ℕ) : sparseGapValue c i ≤ M := by - induction c with - | nil => exact Nat.zero_le _ - | cons q c ih => - obtain ⟨j,l⟩ := q - rw [sparseGapValue] - split_ifs - · exact (h.2 (j,l) (by simp)).2.2.2 - · exact ih ⟨(List.pairwise_cons.mp h.1).2,fun q hq => h.2 q (List.mem_cons_of_mem _ hq)⟩ - - -theorem sparseGapValue_injective (c d : List (ℕ × ℕ)) - (hc : c.Pairwise (fun q r => q.1 < r.1)) - (hd : d.Pairwise (fun q r => q.1 < r.1)) - (hpc : ∀ q ∈ c, 0 < q.2) (hpd : ∀ q ∈ d, 0 < q.2) - (heq : ∀ i, sparseGapValue c i = sparseGapValue d i) : c = d := by - induction c generalizing d with - | nil => - cases d with - | nil => rfl - | cons q d => - obtain ⟨j,l⟩ := q - have hh := heq j - simp [sparseGapValue] at hh - have := hpd (j,l) (by simp) - omega - | cons q c ih => - obtain ⟨i,l⟩ := q - cases d with - | nil => - have hh := heq i - simp [sparseGapValue] at hh - have := hpc (i,l) (by simp) - omega - | cons q d => - obtain ⟨j,m⟩ := q - obtain ⟨hc0,hc1⟩ := List.pairwise_cons.mp hc - obtain ⟨hd0,hd1⟩ := List.pairwise_cons.mp hd - have hij : i = j := by - by_contra hne - rcases Nat.lt_or_gt_of_ne hne with hij | hji - · have hz : sparseGapValue ((j,m)::d) i = 0 := by - apply sparseGapValue_zero - intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · exact hne - · have := hd0 q hq - change j < q.1 at this - omega - have hh := heq i - rw [hz] at hh - simp [sparseGapValue] at hh - have := hpc (i,l) (by simp) - omega - · have hz : sparseGapValue ((i,l)::c) j = 0 := by - apply sparseGapValue_zero - intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · exact Ne.symm hne - · have := hc0 q hq - change i < q.1 at this - omega - have hh := heq j - rw [hz] at hh - simp [sparseGapValue] at hh - have := hpd (j,m) (by simp) - omega - subst j - have hlm : l = m := by simpa [sparseGapValue] using heq i - subst m - congr 1 - apply ih d hc1 hd1 - (fun q hq => hpc q (List.mem_cons_of_mem _ hq)) - (fun q hq => hpd q (List.mem_cons_of_mem _ hq)) - intro r - by_cases hr : r = i - · subst r - rw [sparseGapValue_zero c i (fun q hq => (hc0 q hq).ne), - sparseGapValue_zero d i (fun q hq => (hd0 q hq).ne)] - · simpa only [sparseGapValue,ite_eq_right hr] using heq r - - -def sparseGapArray (k M : ℕ) (c : List (ℕ × ℕ)) (h : ValidSparseGapCode k M c) : - Fin k → Fin (M+1) := - fun i => ⟨sparseGapValue c (i.val+1),Nat.lt_succ_of_le (sparseGapValue_bound k M c h _)⟩ - -theorem sparseGapArray_injective (k M : ℕ) (c d : List (ℕ × ℕ)) - (hc : ValidSparseGapCode k M c) (hd : ValidSparseGapCode k M d) - (heq : sparseGapArray k M c hc = sparseGapArray k M d hd) : c = d := by - apply sparseGapValue_injective c d hc.1 hd.1 - (fun q hq => (hc.2 q hq).2.2.1) (fun q hq => (hd.2 q hq).2.2.1) - intro i - by_cases hi : 1 ≤ i ∧ i ≤ k - · have he := congrArg (fun f => (f ⟨i-1,by omega⟩).val) heq - simpa only [sparseGapArray,show i-1+1 = i by omega] using he - · rw [sparseGapValue_zero c i, sparseGapValue_zero d i] - · intro q hq he - have h := hd.2 q hq - omega - · intro q hq he - have h := hc.2 q hq - omega - - - -theorem SpliceTrace.valid_gap_code (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) - (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) - (hCf : (cluster G ωf x).Finite) (L : ℝ) - (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) : - ValidSparseGapCode k M (gapSpliceCode G ωf x (y k) steps) ∧ - ∀ q ∈ gapSpliceCode G ωf x (y k) steps, j < q.1 := by - induction steps generalizing j ω with - | nil => simp [ValidSparseGapCode,gapSpliceCode] - | cons q rest ih => - obtain ⟨i,e⟩ := q - have hs := h.seam_data G x η y k j ω ωf ((i,e)::rest) (i,e) (by simp) - have hi : 1 ≤ i := by omega - obtain ⟨hCi,hMi,hGi⟩ := hgood i hi hs.2.1 - have hg := h.head_gap_bounds G hloc x η y k j i M ω ωf e rest hCf hCi hMi L hGi - change 1 ≤ _ ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ - traceHeadGap G ωf x (y k) e rest ≤ M ∧ _ at hg - cases h with - | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => - obtain ⟨⟨hpair,hbounds⟩,hlater⟩ := ih i _ ht - simp only [gapSpliceCode] - refine ⟨⟨List.pairwise_cons.mpr ⟨?_,hpair⟩,?_⟩,?_⟩ - · exact hlater - · intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · exact ⟨hi,hs.2.1,hg.2.1,hg.2.2.1⟩ - · exact hbounds q hq - · intro q hq - rcases List.mem_cons.mp hq with rfl | hq - · exact hs.1 - · exact hs.1.trans (hlater q hq) - -end SparseGapCode - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TraceContactMass -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def seamContactCount (G : BondGraph V E) (η : ℕ → Set E) - (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : ℕ := - (contactSet G (η i) - (cluster G (η i ∩ internalEdges G (cluster G (ωf \ {e}) x)ᶜ) (y i))).ncard - - -noncomputable def traceContactCount (G : BondGraph V E) (η : ℕ → Set E) - (y : ℕ → V) (ωf : Set E) (x : V) : List (ℕ × E) → ℕ → ℕ - | [], _ => 1 - | (j,e)::c, i => if i = j then seamContactCount G η y ωf x j e - else traceContactCount G η y ωf x c i - - -theorem SpliceTrace.contact_weight_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) - (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) - (hCf : (cluster G ωf x).Finite) (L : ℝ) (hL : 1 ≤ L) - (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) : - ∀ i, 1 ≤ traceContactCount G η y ωf x steps i ∧ - (traceContactCount G η y ωf x steps i : ℝ)⁻¹ ≤ - gapLetterWeight L (sparseGapValue (gapSpliceCode G ωf x (y k) steps) i) := by - induction steps generalizing j ω with - | nil => simp [traceContactCount,gapSpliceCode,sparseGapValue,gapLetterWeight] - | cons q rest ih => - obtain ⟨i,e⟩ := q - have hs := h.seam_data G x η y k j ω ωf ((i,e)::rest) (i,e) (by simp) - have hi : 1 ≤ i := by omega - obtain ⟨hCi,hMi,hGi⟩ := hgood i hi hs.2.1 - have hg := h.head_gap_bounds G hloc x η y k j i M ω ωf e rest hCf hCi hMi L hGi - have hcut := h.head_cut G x η y k j i ω ωf e rest - change 1 ≤ _ ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ - traceHeadGap G ωf x (y k) e rest ≤ M ∧ _ at hg - have hk : seamContactCount G η y ωf x i e = - (contactSet G (η i) (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i))).ncard := by - unfold seamContactCount - rw [hcut] - rw [← hk] at hg - cases h with - | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => - intro r - by_cases hr : r = i - · subst r - simp only [traceContactCount,gapSpliceCode,sparseGapValue,ite_true] - refine ⟨hg.1,?_⟩ - rw [gapLetterWeight,ite_eq_right (by omega)] - exact inverse_contact_weight_le _ _ L hg.1 hg.2.1 hL hg.2.2.2 - · simpa only [traceContactCount,gapSpliceCode,sparseGapValue,ite_eq_right hr] using ih i _ ht r - - - -def contactChoiceSet (K a : ℕ) : Set unitInterval := - if K = 1 then Set.univ else contactInterval K a - -theorem volume_contactChoiceSet (K a : ℕ) (ha : a < K) : - volume (contactChoiceSet K a) = ENNReal.ofReal ((K:ℝ)⁻¹) := by - unfold contactChoiceSet - split_ifs with h - · simp [h] - · exact volume_contactInterval K a ha - -theorem real_volume_contact_choice_cube {I : Type*} [Fintype I] (K a : I → ℕ) - (ha : ∀ i, a i < K i) : - ((volume : Measure (I → unitInterval)) - (Set.pi Set.univ (fun i => contactChoiceSet (K i) (a i)))).toReal = - ∏ i, (K i:ℝ)⁻¹ := by - rw [MeasureTheory.volume_pi,Measure.pi_pi,ENNReal.toReal_prod] - apply Finset.prod_congr rfl - intro i _ - rw [volume_contactChoiceSet _ _ (ha i),ENNReal.toReal_ofReal (by positivity)] - - - -theorem SpliceTrace.contact_cube_le_code_weight (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) - (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) - (hCf : (cluster G ωf x).Finite) (L : ℝ) (hL : 1 ≤ L) - (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ - (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) - (a : Fin k → ℕ) (ha : ∀ i, a i < traceContactCount G η y ωf x steps (i.val+1)) : - ((volume : Measure (Fin k → unitInterval)) - (Set.pi Set.univ (fun i => contactChoiceSet - (traceContactCount G η y ωf x steps (i.val+1)) (a i)))).toReal ≤ - ∏ i : Fin k, gapLetterWeight L (sparseGapValue (gapSpliceCode G ωf x (y k) steps) (i.val+1)) := by - rw [real_volume_contact_choice_cube _ _ ha] - apply Finset.prod_le_prod₀ - · intros - positivity - · intro i _ - exact (h.contact_weight_bound G hloc x η y k j M ω ωf steps hCf L hL hgood (i.val+1)).2 - - -theorem SpliceTrace.code_unique_of_gapCode (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) - (c₁ c₂ : List (ℕ × E)) - (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) - (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) - (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) - (heq : gapSpliceCode G ωf x (y₁ k) c₁ = gapSpliceCode G ωf x (y₁ k) c₂) : c₁ = c₂ := by - apply ordinalSpliceCode_injective G ωf x (y₁ k) hC c₁ c₂ - (ht₁.seams_pivotal G x η₁ y₁ k j ω₁ ωf c₁) - (by simpa only [hz] using ht₂.seams_pivotal G x η₂ y₂ k j ω₂ ωf c₂) - rw [← ht₁.decode_gap_code G x η₁ y₁ k j ω₁ ωf c₁ hC,heq,hz, - ht₂.decode_gap_code G x η₂ y₂ k j ω₂ ωf c₂ hC] - -end TraceContactMass - -end Percolation - - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteInverseMass -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_inverse_contact_mass_le {I : Type*} [Fintype I] - (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) - (L : ℝ) (hL : 1 ≤ L) (p : unitInterval) (Q : Finset E) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (hir : Function.Injective (fun a => (inp a,steps a))) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) - (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ - (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) - (rank : I → Fin k → ℕ) - (hrank : ∀ a i, rank a i < traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1)) - (B : Finset (SpliceState E)) (hB : ∀ a, out a ∈ B) : - (∑ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) * - ((volume : Measure (Fin k → unitInterval)) - (Set.pi Set.univ (fun i => contactChoiceSet - (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1)) - (rank a i)))).toReal) ≤ - (∑ t ∈ B, spliceTupleWeight Q (Finset.Icc 1 k) p t) * inverseCodeMass M L ^ k := by - let c : I → List (ℕ × ℕ) := fun a => gapSpliceCode G (out a).1 x z (steps a) - have hvalid : ∀ a, ValidSparseGapCode k M (c a) := by - intro a - have hv := (htrace a).valid_gap_code G hloc x (inp a).2 (y a) k 0 M - (inp a).1 (out a).1 (steps a) (hfin a) L (hgood a) - simpa only [c,hz a] using hv.1 - let arr (a : I) : Fin k → Fin (M+1) := sparseGapArray k M (c a) (hvalid a) - let f (a : I) : SpliceState E × (Fin k → Fin (M+1)) := (out a,arr a) - have hinj : Function.Injective f := by - intro a b he - have ho : out a = out b := congrArg Prod.fst he - have hc : c a = c b := sparseGapArray_injective k M (c a) (c b) - (hvalid a) (hvalid b) (congrArg Prod.snd he) - have hze : y a k = y b k := (hz a).trans (hz b).symm - have htB : SpliceTrace G x (inp b).2 (y b) k 0 (inp b).1 (steps b) (out a).1 := by - rw [ho] - exact htrace b - have heB : SpliceExecution G x (inp b) (steps b) (out a) := ho.symm ▸ hex b - have hg : gapSpliceCode G (out a).1 x (y a k) (steps a) = - gapSpliceCode G (out a).1 x (y a k) (steps b) := by - simpa only [c,hz a,ho] using hc - have hs := (htrace a).code_unique_of_gapCode G x (inp a).2 (inp b).2 (y a) (y b) - k 0 (inp a).1 (inp b).1 (out a).1 (steps a) (steps b) htB hze (hfin a) hg - have hi := (htrace a).input_unique_of_gapCode G x (inp a).2 (inp b).2 (y a) (y b) - k 0 (inp a).1 (inp b).1 (out a).1 (steps a) (steps b) htB hze (hfin a) hg - (out a).2 (hex a) heB - exact hir (Prod.ext hi hs) - let w (t : SpliceState E × (Fin k → Fin (M+1))) : ℝ := - spliceTupleWeight Q (Finset.Icc 1 k) p t.1 * ∏ i, gapLetterWeight L (t.2 i).val - have hweight : ∀ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) = - spliceTupleWeight Q (Finset.Icc 1 k) p (out a) := by - intro a - apply ((hex a).weight G x (inp a) (out a) (steps a) Q (Finset.Icc 1 k) ?_ p).symm - intro q hq - have hq' := (htrace a).seam_data G x (inp a).2 (y a) k 0 (inp a).1 (out a).1 (steps a) q hq - exact Finset.mem_Icc.mpr ⟨hq'.1,hq'.2.1⟩ - calc - _ ≤ ∑ a, w (f a) := by - apply Finset.sum_le_sum - intro a _ - dsimp only [w,f,arr,sparseGapArray] - rw [← hweight a] - apply mul_le_mul_of_nonneg_left _ (spliceTupleWeight_nonneg _ _ p _) - have hh := (htrace a).contact_cube_le_code_weight G hloc x (inp a).2 (y a) - k 0 M (inp a).1 (out a).1 (steps a) (hfin a) L hL (hgood a) (rank a) (hrank a) - simpa only [c,hz a] using hh - _ = ∑ t ∈ Finset.univ.image f, w t := (Finset.sum_image hinj.injOn).symm - _ ≤ ∑ t ∈ B ×ˢ (Finset.univ : Finset (Fin k → Fin (M+1))), w t := by - apply Finset.sum_le_sum_of_subset_of_nonneg - · intro t ht - obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp ht - exact Finset.mem_product.mpr ⟨hB a,Finset.mem_univ _⟩ - · intro t _ _ - exact mul_nonneg (spliceTupleWeight_nonneg _ _ p _) - (Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L (by linarith) _)) - _ = _ := by - rw [Finset.sum_product] - simp only [w,← Finset.mul_sum,total_gap_code_mass,← Finset.sum_mul] - -end FiniteInverseMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RemoteSpliceGeometry -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def GraphSeparated (G : BondGraph V E) (A B : Set V) : Prop := - Disjoint A B ∧ ∀ a ∈ A, ∀ b ∈ B, ¬Adj G a b - -theorem GraphSeparated.symm (G : BondGraph V E) (A B : Set V) - (h : GraphSeparated G A B) : GraphSeparated G B A := by - refine ⟨h.1.symm,?_⟩ - intro b hb a ha hab - obtain ⟨e,he⟩ := hab - exact h.2 a ha b hb ⟨e,he.trans (Sym2.eq_swap ..)⟩ - -theorem GraphSeparated.mono (G : BondGraph V E) {A B C D : Set V} - (h : GraphSeparated G A B) (hC : C ⊆ A) (hD : D ⊆ B) : GraphSeparated G C D := by - exact ⟨h.1.mono hC hD,fun c hc d hd => h.2 c (hC hc) d (hD hd)⟩ - -theorem GraphSeparated.no_shared_incidence (G : BondGraph V E) (A B : Set V) - (h : GraphSeparated G A B) (e : E) (a b : V) (ha : a ∈ A) (hb : b ∈ B) - (hea : a ∈ G e) (heb : b ∈ G e) : False := by - have hne : a ≠ b := by - rintro rfl - exact Set.disjoint_left.mp h.1 ha hb - exact h.2 a ha b hb ⟨e,(Sym2.mem_and_mem_iff hne).mp ⟨hea,heb⟩⟩ - - - -theorem slit_cluster_remove_remote (G : BondGraph V E) (η : Set E) (S H : Set V) - (y : V) (hy : y ∉ S) - (hsep : GraphSeparated G (cluster G (η ∩ internalEdges G Sᶜ) y) H) : - cluster G (η ∩ internalEdges G (S \ H)ᶜ) y = cluster G (η ∩ internalEdges G Sᶜ) y := by - apply Set.Subset.antisymm - · intro v hv - induction hv with - | refl => exact conn_refl G _ y - | @tail a b hya hab ih => - obtain ⟨e,he,hab⟩ := hab - have hbH : b ∉ H := fun hb => hsep.2 a ih b hb ⟨e,hab⟩ - have hbS : b ∉ S := by - have hb := ((mem_internalEdges_of_ends G _ e a b hab).mp he.2).2 - exact fun h => hb ⟨h,hbH⟩ - have haS := slit_cluster_subset G S η y hy ih - exact ih.tail ⟨e,⟨he.1,(mem_internalEdges_of_ends G _ e a b hab).mpr ⟨haS,hbS⟩⟩,hab⟩ - · exact fun _ h => conn_mono G - (Set.inter_subset_inter_right _ (internalEdges_mono G (by - intro v hv hvS - exact hv hvS.1))) h - - - -theorem spliceMask_remove_remote (G : BondGraph V E) (S B H : Set V) (e : E) - (hsep : GraphSeparated G B H) : spliceMask G (S \ H) B e = spliceMask G S B e := by - ext f - simp only [spliceMask,Set.mem_insert_iff,Set.mem_ofPred_eq] - apply or_congr Iff.rfl - constructor - · rintro ⟨⟨b,hb,hbf⟩,hi⟩ - refine ⟨⟨b,hb,hbf⟩,?_⟩ - intro v hv hvS - have hvH : v ∉ H := fun hh => hsep.no_shared_incidence G B H f b v hb hh hbf hv - exact hi v hv ⟨hvS,hvH⟩ - · rintro ⟨hb,hi⟩ - exact ⟨hb,fun v hv h => hi v hv h.1⟩ - - -theorem spliceMask_incident (G : BondGraph V E) (S B : Set V) (e : E) - (b : V) (hb : b ∈ B) (heb : b ∈ G e) : - ∀ f ∈ spliceMask G S B e, ∃ v ∈ B, v ∈ G f := by - intro f hf - rcases Set.mem_insert_iff.mp hf with rfl | hf - · exact ⟨b,hb,heb⟩ - · exact hf.1 - - - -theorem disjoint_spliceMasks (G : BondGraph V E) (S₁ S₂ B₁ B₂ : Set V) (e₁ e₂ : E) - (b₁ b₂ : V) (hb₁ : b₁ ∈ B₁) (hb₂ : b₂ ∈ B₂) (he₁ : b₁ ∈ G e₁) (he₂ : b₂ ∈ G e₂) - (hsep : GraphSeparated G B₁ B₂) : - Disjoint (spliceMask G S₁ B₁ e₁) (spliceMask G S₂ B₂ e₂) := by - apply Set.disjoint_left.mpr - intro f hf₁ hf₂ - obtain ⟨a,ha,haf⟩ := spliceMask_incident G S₁ B₁ e₁ b₁ hb₁ he₁ f hf₁ - obtain ⟨b,hb,hbf⟩ := spliceMask_incident G S₂ B₂ e₂ b₂ hb₂ he₂ f hf₂ - exact hsep.no_shared_incidence G B₁ B₂ f a b ha hb haf hbf - -end RemoteSpliceGeometry - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section RemoteReplay -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def replaySplice (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : - List (ℕ × E) → Set E → Set E - | [], ω => ω - | (i,e)::rest, ω => - replaySplice G x η y rest (spliceField G (cluster G ω x) - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) - - -def replayMasks (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : - List (ℕ × E) → Set E → List (ℕ × Set E) - | [], _ => [] - | (i,e)::rest, ω => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - (i,spliceMask G S B e)::replayMasks G x η y rest (spliceField G S B e ω (η i)) - - -def replayContacts (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : - List (ℕ × E) → Set E → List (Set E) - | [], _ => [] - | (i,e)::rest, ω => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - contactSet G (η i) B::replayContacts G x η y rest (spliceField G S B e ω (η i)) - -theorem SpliceTrace.replay_eq (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : replaySplice G x η y steps ω = ωf := by - induction h with - | stop => rfl - | step => assumption - - - -theorem SpliceTrace.remote_replay (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) - (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) (H : Set V) (ω₀ : Set E) - (hroot : cluster G ω₀ x = cluster G ω x \ H) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω x) H) - (hzH : y k ∉ H) : - SpliceTrace G x η y k j ω₀ steps (replaySplice G x η y steps ω₀) ∧ - cluster G (replaySplice G x η y steps ω₀) x = cluster G ωf x \ H ∧ - replayMasks G x η y steps ω₀ = replayMasks G x η y steps ω ∧ - replayContacts G x η y steps ω₀ = replayContacts G x η y steps ω := by - induction h generalizing ω₀ with - | stop j ω hs => - refine ⟨SpliceTrace.stop j ω₀ ?_,hroot,rfl,rfl⟩ - rw [hroot] - exact ⟨hs,hzH⟩ - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - let S₀ := cluster G ω₀ x - let B₀ := cluster G (η i ∩ internalEdges G S₀ᶜ) (y i) - let ω₀' := spliceField G S₀ B₀ e ω₀ (η i) - have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb - have hBo : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy - have hretain : cluster G ω' x ⊆ cluster G ωf x := ht.cluster_subset G x η y k i ω' ωf rest - have hBT : B ⊆ cluster G ωf x \ S := by - intro v hv - refine ⟨hretain ?_,hBo hv⟩ - rw [hC] - exact Or.inr hv - have hsepB : GraphSeparated G B H := hsep.mono G hBT Set.Subset.rfl - have hBB : B₀ = B := by - dsimp only [B₀,S₀] - rw [hroot] - exact slit_cluster_remove_remote G (η i) S H (y i) hy hsepB - have haH : a ∉ H := fun hh => hsepB.2 b hb a hh ⟨e,hab.trans (Sym2.eq_swap ..)⟩ - have ha₀ : a ∈ S₀ := by rw [show S₀ = S \ H from hroot]; exact ⟨ha,haH⟩ - have hy₀ : y i ∉ S₀ := by rw [show S₀ = S \ H from hroot]; exact fun h => hy h.1 - have hb₀ : b ∈ B₀ := hBB.symm ▸ hb - have hC₀ : cluster G ω₀' x = S₀ ∪ B₀ := - splice_cluster G ω₀ (η i) x (y i) hy₀ e a b hab he ha₀ hb₀ - have hroot' : cluster G ω₀' x = cluster G ω' x \ H := by - rw [hC₀,hC,hBB,show S₀ = S \ H from hroot] - ext v - constructor - · rintro (⟨hv,hvH⟩ | hv) - · exact ⟨Or.inl hv,hvH⟩ - · exact ⟨Or.inr hv,fun hvH => Set.disjoint_left.mp hsepB.1 hv hvH⟩ - · rintro ⟨hv,hvH⟩ - exact hv.elim (fun h => Or.inl ⟨h,hvH⟩) Or.inr - have hsep' : GraphSeparated G (cluster G ωf x \ cluster G ω' x) H := by - apply hsep.mono G _ Set.Subset.rfl - intro v hv - refine ⟨hv.1,fun h => hv.2 ?_⟩ - rw [hC] - exact Or.inl h - obtain ⟨ht₀,hfinal,hmasks,hcontacts⟩ := ih ω₀' hroot' hsep' - have hn₀ : y k ∉ S₀ := by rw [show S₀ = S \ H from hroot]; exact fun h => hn h.1 - have hmax₀ : ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) S₀ := by - intro l hil hlk - apply (hmax l hil hlk).mono Set.Subset.rfl - rw [show S₀ = S \ H from hroot] - exact Set.sdiff_subset - have hmask : spliceMask G S₀ B₀ e = spliceMask G S B e := by - rw [hBB,show S₀ = S \ H from hroot,spliceMask_remove_remote G S B H e hsepB] - refine ⟨SpliceTrace.step j i ω₀ e a b rest _ hn₀ hji hik hmax₀ hy₀ he hab ha₀ hb₀ ht₀, - hfinal,?_,?_⟩ - · change (i,spliceMask G S₀ B₀ e)::replayMasks G x η y rest ω₀' = - (i,spliceMask G S B e)::replayMasks G x η y rest ω' - rw [hmask,hmasks] - · change contactSet G (η i) B₀::replayContacts G x η y rest ω₀' = - contactSet G (η i) B::replayContacts G x η y rest ω' - rw [hBB,hcontacts] - -end RemoteReplay - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section DeterministicReplay -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def FollowsContactRule (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (choose : ℕ → Set E → E) (steps : List (ℕ × E)) (ω : Set E) : Prop := - List.Forall₂ (fun q K => choose q.1 K = q.2) steps (replayContacts G x η y steps ω) - -theorem followsContactRule_cons (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (choose : ℕ → Set E → E) (i : ℕ) (e : E) - (rest : List (ℕ × E)) (ω : Set E) : - FollowsContactRule G x η y choose ((i,e)::rest) ω ↔ - choose i (contactSet G (η i) - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i))) = e ∧ - FollowsContactRule G x η y choose rest - (spliceField G (cluster G ω x) - (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) := by - simp only [FollowsContactRule,replayContacts,List.forall₂_cons] - - - -theorem SpliceTrace.remote_follows_contact_rule (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) (H : Set V) (ω₀ : Set E) - (hroot : cluster G ω₀ x = cluster G ω x \ H) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω x) H) (hzH : y k ∉ H) - (choose : ℕ → Set E → E) (hc : FollowsContactRule G x η y choose steps ω) : - FollowsContactRule G x η y choose steps ω₀ := by - unfold FollowsContactRule at hc ⊢ - rw [(h.remote_replay G x η y k j ω ωf steps H ω₀ hroot hsep hzH).2.2.2] - exact hc - - - -theorem SpliceTrace.seeded_unique (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ω₁ ω₂ : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η y k j ω c₁ ω₁) - (h₂ : SpliceTrace G x η y k j ω c₂ ω₂) (choose : ℕ → Set E → E) - (hc₁ : FollowsContactRule G x η y choose c₁ ω) - (hc₂ : FollowsContactRule G x η y choose c₂ ω) : c₁ = c₂ ∧ ω₁ = ω₂ := by - induction h₁ generalizing c₂ ω₂ with - | stop j ω hs => - cases h₂ with - | stop => exact ⟨rfl,rfl⟩ - | step _ _ _ _ _ _ _ _ hn => exact (hn hs).elim - | @step j i ω e a b rest ω₁ hn hji hik hmax hy he hab ha hb ht ih => - cases h₂ with - | stop _ _ hs => exact (hn hs).elim - | step _ l _ f c d tail ω₂ hn₂ hjl hlk hmax₂ hy₂ hf hcd hc hd ht₂ => - have haC : a ∈ cluster G (η i) (y i) := - (edge_cluster_sides G (η i) (y i) he hab).mpr (conn_mono G Set.inter_subset_left hb) - have hcC : c ∈ cluster G (η l) (y l) := - (edge_cluster_sides G (η l) (y l) hf hcd).mpr (conn_mono G Set.inter_subset_left hd) - have hil : i = l := by - rcases lt_trichotomy i l with hil | hil | hli - · exact (Set.disjoint_left.mp (hmax l hil hlk) hcC hc).elim - · exact hil - · exact (Set.disjoint_left.mp (hmax₂ i hli hik) haC ha).elim - subst l - obtain ⟨hec,hrest⟩ := (followsContactRule_cons G x η y choose i e rest ω).mp hc₁ - obtain ⟨hfc,htail⟩ := (followsContactRule_cons G x η y choose i f tail ω).mp hc₂ - have hef : e = f := hec.symm.trans hfc - rw [← hef] at ht₂ htail ⊢ - obtain ⟨hcodes,houts⟩ := ih ω₂ tail ht₂ hrest htail - exact ⟨congrArg (List.cons (i,e)) hcodes,houts⟩ - -end DeterministicReplay - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TraceMaskSupport -attribute [local instance] Classical.propDecidable Classical.decEq - - -def maskUnion (masks : List (ℕ × Set E)) : Set E := - {e | ∃ q ∈ masks, e ∈ q.2} - -@[simp] theorem maskUnion_nil : maskUnion ([] : List (ℕ × Set E)) = ∅ := by - ext e - simp [maskUnion] - -@[simp] theorem maskUnion_cons (i : ℕ) (M : Set E) (ms : List (ℕ × Set E)) : - maskUnion ((i,M)::ms) = M ∪ maskUnion ms := by - ext e - simp [maskUnion,or_and_right,exists_or] - - -theorem SpliceTrace.masks_incident (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : - ∀ f ∈ maskUnion (replayMasks G x η y steps ω), - ∃ b ∈ cluster G ωf x \ cluster G ω x, b ∈ G f := by - induction h with - | stop => simp [replayMasks] - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let ω' := spliceField G S B e ω (η i) - have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb - have hB : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy - have hretain := ht.cluster_subset G x η y k i ω' ωf rest - intro f hf - change f ∈ maskUnion ((i,spliceMask G S B e)::replayMasks G x η y rest ω') at hf - rw [maskUnion_cons] at hf - rcases hf with hf | hf - · obtain ⟨v,hv,hvf⟩ := spliceMask_incident G S B e b hb (by simp [hab]) f hf - refine ⟨v,⟨hretain ?_,hB hv⟩,hvf⟩ - rw [hC] - exact Or.inr hv - · obtain ⟨v,hv,hvf⟩ := ih f hf - refine ⟨v,⟨hv.1,fun h => hv.2 ?_⟩,hvf⟩ - rw [hC] - exact Or.inl h - - -theorem replaySplice_off_masks (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (steps : List (ℕ × E)) (ω : Set E) (f : E) - (hf : f ∉ maskUnion (replayMasks G x η y steps ω)) : - f ∈ replaySplice G x η y steps ω ↔ f ∈ ω := by - induction steps generalizing ω with - | nil => rfl - | cons q rest ih => - obtain ⟨i,e⟩ := q - simp only [replayMasks,maskUnion_cons,Set.mem_union,not_or] at hf - change f ∈ replaySplice G x η y rest _ ↔ f ∈ ω - rw [ih _ hf.2] - simp only [spliceField,mem_exchangeOn,ite_eq_right hf.1] - - -theorem SpliceTrace.masks_disjoint (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - Disjoint (maskUnion (replayMasks G x η₁ y₁ c₁ ω₁)) - (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) := by - apply Set.disjoint_left.mpr - intro f hf₁ hf₂ - obtain ⟨a,ha,hea⟩ := h₁.masks_incident G x η₁ y₁ k j₁ ω₁ ωf c₁ f hf₁ - obtain ⟨b,hb,heb⟩ := h₂.masks_incident G x η₂ y₂ k j₂ ω₂ ωf c₂ f hf₂ - exact hsep.no_shared_incidence G _ _ f a b ha hb hea heb - - - -theorem conn_delete_rootBridge (G : BondGraph V E) (ω η : Set E) (x z : V) - (hη : η ⊆ ω) (e : E) (a b : V) (hab : G e = s(a,b)) - (hb : b ∉ cluster G (ω \ {e}) x) (hz : z ∈ cluster G (ω \ {e}) x) - (hxz : Conn G η x z) : Conn G (η \ {e}) x z := by - have hc : Conn G (insert e (η \ {e})) x z := conn_mono G (by - intro f hf - by_cases hfe : f = e - · exact Or.inl hfe - · exact Or.inr ⟨hf,hfe⟩) hxz - have hs : η \ {e} ⊆ ω \ {e} := Set.sdiff_subset_sdiff_left hη - rw [conn_insert_iff G _ e a b x z hab] at hc - rcases hc with hc | ⟨_,hc⟩ | ⟨hc,_⟩ - · exact hc - · exact (hb (hz.trans (conn_symm G _ (conn_mono G hs hc)))).elim - · exact (hb (conn_mono G hs hc)).elim - - -theorem cluster_double_cut (G : BondGraph V E) (ω : Set E) (x : V) (e f : E) - (a b : V) (hab : G f = s(a,b)) (hb : b ∉ cluster G (ω \ {f}) x) : - cluster G ((ω \ {e}) \ {f}) x = cluster G (ω \ {e}) x ∩ cluster G (ω \ {f}) x := by - apply Set.Subset.antisymm - · intro v hv - exact ⟨conn_mono G Set.sdiff_subset hv, - conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) hv⟩ - · intro v hv - exact conn_delete_rootBridge G ω (ω \ {e}) x v Set.sdiff_subset f a b hab hb hv.2 hv.1 - -end TraceMaskSupport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section JointRoot -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem mask_not_crossing_remote (G : BondGraph V E) (U : Set E) (A B : Set V) - (hU : ∀ e ∈ U, ∃ v ∈ B, v ∈ G e) (hBA : B ⊆ A) - (e : E) (a b : V) (hab : G e = s(a,b)) (haB : a ∉ B) (hbA : b ∉ A) : e ∉ U := by - intro he - obtain ⟨v,hv,hve⟩ := hU e he - have hvab : v = a ∨ v = b := by simpa only [hab,Sym2.mem_iff] using hve - rcases hvab with rfl | rfl - · exact haB hv - · exact hbA (hBA hv) - - - -theorem exchange_patch_symm (U₁ U₂ ω₁ ω₂ ωf : Set E) - (hdis : Disjoint U₁ U₂) - (h₁ : ∀ e ∉ U₁, e ∈ ω₁ ↔ e ∈ ωf) - (h₂ : ∀ e ∉ U₂, e ∈ ω₂ ↔ e ∈ ωf) : - exchangeOn U₂ ω₁ ω₂ = exchangeOn U₁ ω₂ ω₁ := by - ext e - by_cases he₁ : e ∈ U₁ - · have he₂ : e ∉ U₂ := fun h => Set.disjoint_left.mp hdis he₁ h - simp only [mem_exchangeOn,ite_eq_right he₂,ite_eq_left he₁] - · by_cases he₂ : e ∈ U₂ - · simp only [mem_exchangeOn,ite_eq_left he₂,ite_eq_right he₁] - · simp only [mem_exchangeOn,ite_eq_right he₁,ite_eq_right he₂] - exact (h₁ e he₁).trans (h₂ e he₂).symm - - - -theorem SpliceTrace.joint_root (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ i₁ i₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (e₁ e₂ : E) (r₁ r₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ ((i₁,e₁)::r₁) ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ ((i₂,e₂)::r₂) ωf) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - cluster G (exchangeOn (maskUnion (replayMasks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂)) ω₁ ω₂) x = - cluster G ω₁ x ∩ cluster G ω₂ x := by - let A₁ := cluster G ω₁ x - let A₂ := cluster G ω₂ x - let B₁ := cluster G ωf x \ A₁ - let B₂ := cluster G ωf x \ A₂ - let U₁ := maskUnion (replayMasks G x η₁ y₁ ((i₁,e₁)::r₁) ω₁) - let U₂ := maskUnion (replayMasks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂) - let ω₀ := exchangeOn U₂ ω₁ ω₂ - have hsub₁ := h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁) - have hsub₂ := h₂.cluster_subset G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) - have hBA₁ : B₁ ⊆ A₂ := by - intro v hv - by_contra hn - exact Set.disjoint_left.mp hsep.1 hv ⟨hv.1,hn⟩ - have hBA₂ : B₂ ⊆ A₁ := by - intro v hv - by_contra hn - exact Set.disjoint_left.mp hsep.1 ⟨hv.1,hn⟩ hv - have hU₁ : ∀ e ∈ U₁, ∃ v ∈ B₁, v ∈ G e := - h₁.masks_incident G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁) - have hU₂ : ∀ e ∈ U₂, ∃ v ∈ B₂, v ∈ G e := - h₂.masks_incident G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) - have hdis : Disjoint U₁ U₂ := h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf - ((i₁,e₁)::r₁) ((i₂,e₂)::r₂) h₂ hsep - have hoff₁ : ∀ e ∉ U₁, e ∈ ω₁ ↔ e ∈ ωf := by - intro e he - rw [← h₁.replay_eq G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁)] - exact (replaySplice_off_masks G x η₁ y₁ ((i₁,e₁)::r₁) ω₁ e he).symm - have hoff₂ : ∀ e ∉ U₂, e ∈ ω₂ ↔ e ∈ ωf := by - intro e he - rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂)] - exact (replaySplice_off_masks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂ e he).symm - have hsym : ω₀ = exchangeOn U₁ ω₂ ω₁ := exchange_patch_symm U₁ U₂ ω₁ ω₂ ωf hdis hoff₁ hoff₂ - have hcut₁ := h₁.head_cut G x η₁ y₁ k j₁ i₁ ω₁ ωf e₁ r₁ - have hcut₂ := h₂.head_cut G x η₂ y₂ k j₂ i₂ ω₂ ωf e₂ r₂ - obtain ⟨a,b,hab,_,hb,_⟩ := openMarkedPivotal_oriented G ωf {y₂ k} x - (h₂.seams_pivotal G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) (i₂,e₂) (by simp)) - have hdouble : cluster G ((ωf \ {e₁}) \ {e₂}) x = A₁ ∩ A₂ := by - rw [cluster_double_cut G ωf x e₁ e₂ a b hab hb,hcut₁,hcut₂] - change cluster G ω₀ x = A₁ ∩ A₂ - apply Set.Subset.antisymm - · intro v hv - induction hv with - | refl => exact ⟨conn_refl G _ x,conn_refl G _ x⟩ - | @tail a b hxa hab ih => - obtain ⟨e,he,hab⟩ := hab - constructor - · by_contra hb - have hno := mask_not_crossing_remote G U₂ A₁ B₂ hU₂ hBA₂ e a b hab - (fun hh => hh.2 ih.2) hb - have he₁ : e ∈ ω₁ := by simpa only [ω₀,mem_exchangeOn,ite_eq_right hno] using he - exact hb ((edge_cluster_sides G ω₁ x he₁ hab).mp ih.1) - · by_contra hb - have hno := mask_not_crossing_remote G U₁ A₂ B₁ hU₁ hBA₁ e a b hab - (fun hh => hh.2 ih.1) hb - have he₂ : e ∈ ω₂ := by simpa only [hsym,mem_exchangeOn,ite_eq_right hno] using he - exact hb ((edge_cluster_sides G ω₂ x he₂ hab).mp ih.2) - · intro v hv - have hc : Conn G ((ωf \ {e₁}) \ {e₂}) x v := by - change v ∈ cluster G ((ωf \ {e₁}) \ {e₂}) x - rw [hdouble] - exact hv - have hr := conn_restrict_cluster G ((ωf \ {e₁}) \ {e₂}) x (mem_cluster_self G _ x) hc - apply conn_mono G _ hr - intro e he - have hi : e ∈ internalEdges G (A₁ ∩ A₂) := by - simpa only [hdouble] using he.2 - have hno : e ∉ U₂ := by - intro hu - obtain ⟨b,hb,heb⟩ := hU₂ e hu - exact hb.2 (hi b heb).2 - have he₁ : e ∈ ω₁ := (h₁.internal_agreement G x η₁ y₁ k j₁ ω₁ ωf - ((i₁,e₁)::r₁) e (fun a ha => (hi a ha).1)).mp he.1.1.1 - simpa only [ω₀,mem_exchangeOn,ite_eq_right hno] using he₁ - -end JointRoot - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section MaskExecution -attribute [local instance] Classical.propDecidable Classical.decEq - - -def runMasks : List (ℕ × Set E) → SpliceState E → SpliceState E - | [], s => s - | (i,M)::ms, s => runMasks ms (exchangeState M i s) - - -def patchFirst (U τ : Set E) (s : SpliceState E) : SpliceState E := - (exchangeOn U s.1 τ,s.2) - -theorem exchangeState_patchFirst (U τ M : Set E) (i : ℕ) (s : SpliceState E) - (hdis : Disjoint M U) : - exchangeState M i (patchFirst U τ s) = patchFirst U τ (exchangeState M i s) := by - apply Prod.ext - · ext e - by_cases heM : e ∈ M - · have heU : e ∉ U := fun he => Set.disjoint_left.mp hdis heM he - simp only [exchangeState,patchFirst,mem_exchangeOn,ite_eq_left heM,ite_eq_right heU] - · by_cases heU : e ∈ U <;> - simp only [exchangeState,patchFirst,mem_exchangeOn,ite_eq_right heM,heU,ite_true,ite_false] - · funext l - by_cases hli : l = i - · subst l - ext e - by_cases heM : e ∈ M - · have heU : e ∉ U := fun he => Set.disjoint_left.mp hdis heM he - simp only [exchangeState,patchFirst,Function.update_self,mem_exchangeOn,ite_eq_left heM,ite_eq_right heU] - · simp only [exchangeState,patchFirst,Function.update_self,mem_exchangeOn,ite_eq_right heM] - · simp only [exchangeState,patchFirst,Function.update_of_ne hli] - - - -theorem runMasks_patchFirst (ms : List (ℕ × Set E)) (U τ : Set E) (s : SpliceState E) - (hdis : Disjoint (maskUnion ms) U) : - runMasks ms (patchFirst U τ s) = patchFirst U τ (runMasks ms s) := by - induction ms generalizing s with - | nil => rfl - | cons q ms ih => - obtain ⟨i,M⟩ := q - rw [maskUnion_cons,Set.disjoint_union_left] at hdis - simp only [runMasks] - rw [exchangeState_patchFirst U τ M i s hdis.1,ih _ hdis.2] - - - -theorem SpliceTrace.runMasks_first (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω steps ωf) : - ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → - (runMasks (replayMasks G x η y steps ω) (ω,θ)).1 = ωf := by - induction h with - | stop => exact fun _ _ => rfl - | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => - intro θ hθ - have hθi := hθ i hji hik - let S := cluster G ω x - let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) - let M := spliceMask G S B e - let ω' := spliceField G S B e ω (η i) - let θ' := Function.update θ i (exchangeOn M (θ i) ω) - have hstep : exchangeState M i (ω,θ) = (ω',θ') := by - apply Prod.ext - · change exchangeOn M ω (θ i) = exchangeOn M ω (η i) - rw [hθi] - · rfl - change (runMasks (replayMasks G x η y rest ω') (exchangeState M i (ω,θ))).1 = ωf - rw [hstep] - apply ih θ' - intro l hil hlk - rw [show θ' l = θ l from Function.update_of_ne (by omega) _ _] - exact hθ l (hji.trans hil) hlk - - -theorem runMasks_weight (ms : List (ℕ × Set E)) (s : SpliceState E) - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (hJ : ∀ q ∈ ms, q.1 ∈ J) : - spliceTupleWeight Q J p (runMasks ms s) = spliceTupleWeight Q J p s := by - induction ms generalizing s with - | nil => rfl - | cons q ms ih => - obtain ⟨i,M⟩ := q - rw [runMasks,ih _ (fun q hq => hJ q (List.mem_cons_of_mem _ hq))] - exact spliceTupleWeight_exchange Q J p s M i (hJ (i,M) (List.mem_cons_self ..)) - - - -theorem SpliceTrace.joint_replay_state (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - let m₁ := replayMasks G x η₁ y₁ c₁ ω₁ - let m₂ := replayMasks G x η₂ y₂ c₂ ω₂ - let ω₀ := exchangeOn (maskUnion m₂) ω₁ ω₂ - runMasks m₁ (ω₀,η₁) = (ω₂,(runMasks m₁ (ω₁,η₁)).2) := by - intro m₁ m₂ ω₀ - have hdis := h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep - have hroot := h₁.runMasks_first G x η₁ y₁ k j₁ ω₁ ωf c₁ η₁ (by intros; rfl) - have hpatch : exchangeOn (maskUnion m₂) ωf ω₂ = ω₂ := by - ext e - by_cases he : e ∈ maskUnion m₂ - · simp only [mem_exchangeOn,ite_eq_left he] - · simp only [mem_exchangeOn,ite_eq_right he] - rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf c₂] - exact replaySplice_off_masks G x η₂ y₂ c₂ ω₂ e he - change runMasks m₁ (patchFirst (maskUnion m₂) ω₂ (ω₁,η₁)) = _ - rw [runMasks_patchFirst m₁ _ ω₂ _ hdis] - change (exchangeOn (maskUnion m₂) (runMasks m₁ (ω₁,η₁)).1 ω₂,_) = _ - rw [hroot,hpatch] - -end MaskExecution - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section JointReplay -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem SpliceTrace.endpoint_not_mem_of_ne_nil (G : BondGraph V E) (x : V) - (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω c ωf) (hc : c ≠ []) : y k ∉ cluster G ω x := by - cases h with - | stop => exact (hc rfl).elim - | step _ _ _ _ _ _ _ _ hn => exact hn - - - -theorem SpliceTrace.joint_virtual (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) : - let ω₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ - SpliceTrace G x η₁ y₁ k j₁ ω₀ c₁ ω₂ ∧ - replayMasks G x η₁ y₁ c₁ ω₀ = replayMasks G x η₁ y₁ c₁ ω₁ ∧ - replayContacts G x η₁ y₁ c₁ ω₀ = replayContacts G x η₁ y₁ c₁ ω₁ := by - intro ω₀ - have hroot' : cluster G ω₀ x = cluster G ω₁ x ∩ cluster G ω₂ x := by - cases c₁ with - | nil => exact (hc₁ rfl).elim - | cons q r₁ => - obtain ⟨i₁,e₁⟩ := q - cases c₂ with - | nil => exact (hc₂ rfl).elim - | cons q r₂ => - obtain ⟨i₂,e₂⟩ := q - exact h₁.joint_root G x η₁ η₂ y₁ y₂ k j₁ j₂ i₁ i₂ ω₁ ω₂ ωf e₁ e₂ r₁ r₂ h₂ hsep - let H := cluster G ωf x \ cluster G ω₂ x - have hroot : cluster G ω₀ x = cluster G ω₁ x \ H := by - rw [hroot'] - ext v - constructor - · rintro ⟨h1,h2⟩ - exact ⟨h1,fun hh => hh.2 h2⟩ - · rintro ⟨h1,h2⟩ - refine ⟨h1,?_⟩ - by_contra hn - exact h2 ⟨h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf c₁ h1,hn⟩ - have hz : y₁ k ∉ H := fun hz => Set.disjoint_left.mp hsep.1 - ⟨h₁.endpoint G x η₁ y₁ k j₁ ω₁ ωf c₁, - h₁.endpoint_not_mem_of_ne_nil G x η₁ y₁ k j₁ ω₁ ωf c₁ hc₁⟩ hz - obtain ⟨ht,hout,hm,hcontacts⟩ := h₁.remote_replay G x η₁ y₁ k j₁ ω₁ ωf c₁ H ω₀ hroot hsep hz - have hf := ht.runMasks_first G x η₁ y₁ k j₁ ω₀ (replaySplice G x η₁ y₁ c₁ ω₀) c₁ η₁ - (by intros; rfl) - rw [hm] at hf - have hs := h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep - have heq : replaySplice G x η₁ y₁ c₁ ω₀ = ω₂ := hf.symm.trans (congrArg Prod.fst hs) - rw [heq] at ht - exact ⟨ht,hm,hcontacts⟩ - - - -theorem joint_restore_seeded_unique (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (choose₁ choose₂ : ℕ → Set E → E) - (k j₁ j₂ : ℕ) (ω₁ ω₂ ωf σ₁ σ₂ σf : Set E) - (c₁ c₂ d₁ d₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (g₁ : SpliceTrace G x η₁ y₁ k j₁ σ₁ d₁ σf) - (g₂ : SpliceTrace G x η₂ y₂ k j₂ σ₂ d₂ σf) - (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) (hd₁ : d₁ ≠ []) (hd₂ : d₂ ≠ []) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) - (gsep : GraphSeparated G (cluster G σf x \ cluster G σ₁ x) - (cluster G σf x \ cluster G σ₂ x)) - (hr₁ : FollowsContactRule G x η₁ y₁ choose₁ c₁ ω₁) - (hr₂ : FollowsContactRule G x η₂ y₂ choose₂ c₂ ω₂) - (gr₁ : FollowsContactRule G x η₁ y₁ choose₁ d₁ σ₁) - (gr₂ : FollowsContactRule G x η₂ y₂ choose₂ d₂ σ₂) - (hrestore : exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ = - exchangeOn (maskUnion (replayMasks G x η₂ y₂ d₂ σ₂)) σ₁ σ₂) : - c₁ = d₁ ∧ c₂ = d₂ ∧ ωf = σf ∧ - (runMasks (replayMasks G x η₁ y₁ c₁ ω₁) (ω₁,η₁)).2 = - (runMasks (replayMasks G x η₁ y₁ d₁ σ₁) (σ₁,η₁)).2 ∧ - (runMasks (replayMasks G x η₂ y₂ c₂ ω₂) (ω₂,η₂)).2 = - (runMasks (replayMasks G x η₂ y₂ d₂ σ₂) (σ₂,η₂)).2 := by - let ω₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ - let σ₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ d₂ σ₂)) σ₁ σ₂ - obtain ⟨ht,hm,hcontact⟩ := h₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep - obtain ⟨gt,gm,gcontact⟩ := g₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ σ₁ σ₂ σf d₁ d₂ g₂ hd₁ hd₂ gsep - have hrc : FollowsContactRule G x η₁ y₁ choose₁ c₁ ω₀ := by - unfold FollowsContactRule at hr₁ ⊢ - rw [hcontact] - exact hr₁ - have grc : FollowsContactRule G x η₁ y₁ choose₁ d₁ σ₀ := by - unfold FollowsContactRule at gr₁ ⊢ - rw [gcontact] - exact gr₁ - change SpliceTrace G x η₁ y₁ k j₁ σ₀ d₁ σ₂ at gt - change replayMasks G x η₁ y₁ c₁ ω₀ = _ at hm - change replayMasks G x η₁ y₁ d₁ σ₀ = _ at gm - have h00 : ω₀ = σ₀ := hrestore - rw [← h00] at gt grc - obtain ⟨hcode₁,hω₂⟩ := ht.seeded_unique G x η₁ y₁ k j₁ ω₀ ω₂ σ₂ c₁ d₁ gt choose₁ hrc grc - rw [← hω₂] at g₂ gr₂ - obtain ⟨hcode₂,hout⟩ := h₂.seeded_unique G x η₂ y₂ k j₂ ω₂ ωf σf c₂ d₂ g₂ choose₂ hr₂ gr₂ - refine ⟨hcode₁,hcode₂,hout,?_,?_⟩ - · have hs := congrArg Prod.snd (h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep) - have gs := congrArg Prod.snd (g₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ σ₁ σ₂ σf d₁ d₂ - (hω₂ ▸ g₂) gsep) - change (runMasks _ (ω₀,η₁)).2 = _ at hs - change (runMasks _ (σ₀,η₁)).2 = _ at gs - rw [← hs,← gs,← hm,← gm,h00,hcode₁] - · rw [hcode₂,hω₂] - -end JointReplay - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section JointWeight -attribute [local instance] Classical.propDecidable Classical.decEq - - - -abbrev JointSpliceState (E : Type v) := Set E × (ℕ → Set E) × (ℕ → Set E) - -noncomputable def jointTupleWeight (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (s : JointSpliceState E) : ℝ := - bernoulliWeight Q (domainBits Q s.1) p * - (∏ i ∈ J₁, bernoulliWeight Q (domainBits Q (s.2.1 i)) p) * - ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (s.2.2 i)) p - -theorem jointTupleWeight_nonneg (Q : Finset E) (J₁ J₂ : Finset ℕ) - (p : unitInterval) (s : JointSpliceState E) : 0 ≤ jointTupleWeight Q J₁ J₂ p s := by - exact mul_nonneg (spliceTupleWeight_nonneg Q J₁ p (s.1,s.2.1)) - (Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p) - -theorem replayMasks_indices (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) : - (replayMasks G x η y c ω).map Prod.fst = c.map Prod.fst := by - induction c generalizing ω with - | nil => rfl - | cons q c ih => - obtain ⟨i,e⟩ := q - simp only [replayMasks,List.map_cons,ih] - -theorem replayMasks_indices_mem (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (J : Finset ℕ) - (hJ : ∀ q ∈ c, q.1 ∈ J) : ∀ q ∈ replayMasks G x η y c ω, q.1 ∈ J := by - intro q hq - have hq' : q.1 ∈ (replayMasks G x η y c ω).map Prod.fst := List.mem_map_of_mem hq - rw [replayMasks_indices G x η y c ω] at hq' - obtain ⟨r,hr,he⟩ := List.mem_map.mp hq' - exact he ▸ hJ r hr - - - -theorem SpliceTrace.joint_weight (G : BondGraph V E) (x : V) - (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) - (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) - (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) - (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) - (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) - (cluster G ωf x \ cluster G ω₂ x)) - (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) - (hJ₁ : ∀ q ∈ c₁, q.1 ∈ J₁) (hJ₂ : ∀ q ∈ c₂, q.1 ∈ J₂) : - let m₁ := replayMasks G x η₁ y₁ c₁ ω₁ - let m₂ := replayMasks G x η₂ y₂ c₂ ω₂ - let ω₀ := exchangeOn (maskUnion m₂) ω₁ ω₂ - jointTupleWeight Q J₁ J₂ p (ωf,(runMasks m₁ (ω₁,η₁)).2,(runMasks m₂ (ω₂,η₂)).2) = - jointTupleWeight Q J₁ J₂ p (ω₀,η₁,η₂) := by - intro m₁ m₂ ω₀ - have hw₁ := runMasks_weight m₁ (ω₀,η₁) Q J₁ p - (replayMasks_indices_mem G x η₁ y₁ c₁ ω₁ J₁ hJ₁) - rw [h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep] at hw₁ - have hw₂ := runMasks_weight m₂ (ω₂,η₂) Q J₂ p - (replayMasks_indices_mem G x η₂ y₂ c₂ ω₂ J₂ hJ₂) - unfold spliceTupleWeight at hw₁ hw₂ - rw [h₂.runMasks_first G x η₂ y₂ k j₂ ω₂ ωf c₂ η₂ (by intros; rfl)] at hw₂ - unfold jointTupleWeight - dsimp only at hw₁ hw₂ ⊢ - calc - _ = (bernoulliWeight Q (domainBits Q ωf) p * - ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q ((runMasks m₂ (ω₂,η₂)).2 i)) p) * - ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p := by ring - _ = (bernoulliWeight Q (domainBits Q ω₂) p * - ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (η₂ i)) p) * - ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p := by rw [hw₂] - _ = (bernoulliWeight Q (domainBits Q ω₂) p * - ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p) * - ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (η₂ i)) p := by ring - _ = _ := by rw [hw₁] - -end JointWeight - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.GapCodes + +namespace OAI + +/-! Replay for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SparseGapCode +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def ValidSparseGapCode (k M : ℕ) (c : List (ℕ × ℕ)) : Prop := + c.Pairwise (fun q r => q.1 < r.1) ∧ + ∀ q ∈ c, 1 ≤ q.1 ∧ q.1 ≤ k ∧ 1 ≤ q.2 ∧ q.2 ≤ M + +def sparseGapValue : List (ℕ × ℕ) → ℕ → ℕ + | [], _ => 0 + | (j,l)::c, i => if i = j then l else sparseGapValue c i + +theorem sparseGapValue_zero (c : List (ℕ × ℕ)) (i : ℕ) + (h : ∀ q ∈ c, i ≠ q.1) : sparseGapValue c i = 0 := by + induction c with + | nil => rfl + | cons q c ih => + obtain ⟨j,l⟩ := q + rw [sparseGapValue,ite_eq_right (h (j,l) (by simp))] + exact ih (fun q hq => h q (List.mem_cons_of_mem _ hq)) + +theorem sparseGapValue_bound (k M : ℕ) (c : List (ℕ × ℕ)) + (h : ValidSparseGapCode k M c) (i : ℕ) : sparseGapValue c i ≤ M := by + induction c with + | nil => exact Nat.zero_le _ + | cons q c ih => + obtain ⟨j,l⟩ := q + rw [sparseGapValue] + split_ifs + · exact (h.2 (j,l) (by simp)).2.2.2 + · exact ih ⟨(List.pairwise_cons.mp h.1).2,fun q hq => h.2 q (List.mem_cons_of_mem _ hq)⟩ + + +theorem sparseGapValue_injective (c d : List (ℕ × ℕ)) + (hc : c.Pairwise (fun q r => q.1 < r.1)) + (hd : d.Pairwise (fun q r => q.1 < r.1)) + (hpc : ∀ q ∈ c, 0 < q.2) (hpd : ∀ q ∈ d, 0 < q.2) + (heq : ∀ i, sparseGapValue c i = sparseGapValue d i) : c = d := by + induction c generalizing d with + | nil => + cases d with + | nil => rfl + | cons q d => + obtain ⟨j,l⟩ := q + have hh := heq j + simp [sparseGapValue] at hh + have := hpd (j,l) (by simp) + omega + | cons q c ih => + obtain ⟨i,l⟩ := q + cases d with + | nil => + have hh := heq i + simp [sparseGapValue] at hh + have := hpc (i,l) (by simp) + omega + | cons q d => + obtain ⟨j,m⟩ := q + obtain ⟨hc0,hc1⟩ := List.pairwise_cons.mp hc + obtain ⟨hd0,hd1⟩ := List.pairwise_cons.mp hd + have hij : i = j := by + by_contra hne + rcases Nat.lt_or_gt_of_ne hne with hij | hji + · have hz : sparseGapValue ((j,m)::d) i = 0 := by + apply sparseGapValue_zero + intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · exact hne + · have := hd0 q hq + change j < q.1 at this + omega + have hh := heq i + rw [hz] at hh + simp [sparseGapValue] at hh + have := hpc (i,l) (by simp) + omega + · have hz : sparseGapValue ((i,l)::c) j = 0 := by + apply sparseGapValue_zero + intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · exact Ne.symm hne + · have := hc0 q hq + change i < q.1 at this + omega + have hh := heq j + rw [hz] at hh + simp [sparseGapValue] at hh + have := hpd (j,m) (by simp) + omega + subst j + have hlm : l = m := by simpa [sparseGapValue] using heq i + subst m + congr 1 + apply ih d hc1 hd1 + (fun q hq => hpc q (List.mem_cons_of_mem _ hq)) + (fun q hq => hpd q (List.mem_cons_of_mem _ hq)) + intro r + by_cases hr : r = i + · subst r + rw [sparseGapValue_zero c i (fun q hq => (hc0 q hq).ne), + sparseGapValue_zero d i (fun q hq => (hd0 q hq).ne)] + · simpa only [sparseGapValue,ite_eq_right hr] using heq r + + +def sparseGapArray (k M : ℕ) (c : List (ℕ × ℕ)) (h : ValidSparseGapCode k M c) : + Fin k → Fin (M+1) := + fun i => ⟨sparseGapValue c (i.val+1),Nat.lt_succ_of_le (sparseGapValue_bound k M c h _)⟩ + +theorem sparseGapArray_injective (k M : ℕ) (c d : List (ℕ × ℕ)) + (hc : ValidSparseGapCode k M c) (hd : ValidSparseGapCode k M d) + (heq : sparseGapArray k M c hc = sparseGapArray k M d hd) : c = d := by + apply sparseGapValue_injective c d hc.1 hd.1 + (fun q hq => (hc.2 q hq).2.2.1) (fun q hq => (hd.2 q hq).2.2.1) + intro i + by_cases hi : 1 ≤ i ∧ i ≤ k + · have he := congrArg (fun f => (f ⟨i-1,by omega⟩).val) heq + simpa only [sparseGapArray,show i-1+1 = i by omega] using he + · rw [sparseGapValue_zero c i, sparseGapValue_zero d i] + · intro q hq he + have h := hd.2 q hq + omega + · intro q hq he + have h := hc.2 q hq + omega + + + +theorem SpliceTrace.valid_gap_code (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) + (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) + (hCf : (cluster G ωf x).Finite) (L : ℝ) + (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) : + ValidSparseGapCode k M (gapSpliceCode G ωf x (y k) steps) ∧ + ∀ q ∈ gapSpliceCode G ωf x (y k) steps, j < q.1 := by + induction steps generalizing j ω with + | nil => simp [ValidSparseGapCode,gapSpliceCode] + | cons q rest ih => + obtain ⟨i,e⟩ := q + have hs := h.seam_data G x η y k j ω ωf ((i,e)::rest) (i,e) (by simp) + have hi : 1 ≤ i := by omega + obtain ⟨hCi,hMi,hGi⟩ := hgood i hi hs.2.1 + have hg := h.head_gap_bounds G hloc x η y k j i M ω ωf e rest hCf hCi hMi L hGi + change 1 ≤ _ ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ + traceHeadGap G ωf x (y k) e rest ≤ M ∧ _ at hg + cases h with + | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => + obtain ⟨⟨hpair,hbounds⟩,hlater⟩ := ih i _ ht + simp only [gapSpliceCode] + refine ⟨⟨List.pairwise_cons.mpr ⟨?_,hpair⟩,?_⟩,?_⟩ + · exact hlater + · intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · exact ⟨hi,hs.2.1,hg.2.1,hg.2.2.1⟩ + · exact hbounds q hq + · intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · exact hs.1 + · exact hs.1.trans (hlater q hq) + +end SparseGapCode + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TraceContactMass +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def seamContactCount (G : BondGraph V E) (η : ℕ → Set E) + (y : ℕ → V) (ωf : Set E) (x : V) (i : ℕ) (e : E) : ℕ := + (contactSet G (η i) + (cluster G (η i ∩ internalEdges G (cluster G (ωf \ {e}) x)ᶜ) (y i))).ncard + + +noncomputable def traceContactCount (G : BondGraph V E) (η : ℕ → Set E) + (y : ℕ → V) (ωf : Set E) (x : V) : List (ℕ × E) → ℕ → ℕ + | [], _ => 1 + | (j,e)::c, i => if i = j then seamContactCount G η y ωf x j e + else traceContactCount G η y ωf x c i + + +theorem SpliceTrace.contact_weight_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) + (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) + (hCf : (cluster G ωf x).Finite) (L : ℝ) (hL : 1 ≤ L) + (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) : + ∀ i, 1 ≤ traceContactCount G η y ωf x steps i ∧ + (traceContactCount G η y ωf x steps i : ℝ)⁻¹ ≤ + gapLetterWeight L (sparseGapValue (gapSpliceCode G ωf x (y k) steps) i) := by + induction steps generalizing j ω with + | nil => simp [traceContactCount,gapSpliceCode,sparseGapValue,gapLetterWeight] + | cons q rest ih => + obtain ⟨i,e⟩ := q + have hs := h.seam_data G x η y k j ω ωf ((i,e)::rest) (i,e) (by simp) + have hi : 1 ≤ i := by omega + obtain ⟨hCi,hMi,hGi⟩ := hgood i hi hs.2.1 + have hg := h.head_gap_bounds G hloc x η y k j i M ω ωf e rest hCf hCi hMi L hGi + have hcut := h.head_cut G x η y k j i ω ωf e rest + change 1 ≤ _ ∧ 1 ≤ traceHeadGap G ωf x (y k) e rest ∧ + traceHeadGap G ωf x (y k) e rest ≤ M ∧ _ at hg + have hk : seamContactCount G η y ωf x i e = + (contactSet G (η i) (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i))).ncard := by + unfold seamContactCount + rw [hcut] + rw [← hk] at hg + cases h with + | step j i ω e a b rest ωf _ _ _ _ _ _ _ _ _ ht => + intro r + by_cases hr : r = i + · subst r + simp only [traceContactCount,gapSpliceCode,sparseGapValue,ite_true] + refine ⟨hg.1,?_⟩ + rw [gapLetterWeight,ite_eq_right (by omega)] + exact inverse_contact_weight_le _ _ L hg.1 hg.2.1 hL hg.2.2.2 + · simpa only [traceContactCount,gapSpliceCode,sparseGapValue,ite_eq_right hr] using ih i _ ht r + + + +def contactChoiceSet (K a : ℕ) : Set unitInterval := + if K = 1 then Set.univ else contactInterval K a + +theorem volume_contactChoiceSet (K a : ℕ) (ha : a < K) : + volume (contactChoiceSet K a) = ENNReal.ofReal ((K:ℝ)⁻¹) := by + unfold contactChoiceSet + split_ifs with h + · simp [h] + · exact volume_contactInterval K a ha + +theorem real_volume_contact_choice_cube {I : Type*} [Fintype I] (K a : I → ℕ) + (ha : ∀ i, a i < K i) : + ((volume : Measure (I → unitInterval)) + (Set.pi Set.univ (fun i => contactChoiceSet (K i) (a i)))).toReal = + ∏ i, (K i:ℝ)⁻¹ := by + rw [MeasureTheory.volume_pi,Measure.pi_pi,ENNReal.toReal_prod] + apply Finset.prod_congr rfl + intro i _ + rw [volume_contactChoiceSet _ _ (ha i),ENNReal.toReal_ofReal (by positivity)] + + + +theorem SpliceTrace.contact_cube_le_code_weight (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (η : ℕ → Set E) (y : ℕ → V) (k j M : ℕ) (ω ωf : Set E) + (steps : List (ℕ × E)) (h : SpliceTrace G x η y k j ω steps ωf) + (hCf : (cluster G ωf x).Finite) (L : ℝ) (hL : 1 ≤ L) + (hgood : ∀ i, 1 ≤ i → i ≤ k → (cluster G (η i) (y i)).Finite ∧ + (cluster G (η i) (y i)).ncard ≤ M ∧ GoodForScale G (η i) (y i) L) + (a : Fin k → ℕ) (ha : ∀ i, a i < traceContactCount G η y ωf x steps (i.val+1)) : + ((volume : Measure (Fin k → unitInterval)) + (Set.pi Set.univ (fun i => contactChoiceSet + (traceContactCount G η y ωf x steps (i.val+1)) (a i)))).toReal ≤ + ∏ i : Fin k, gapLetterWeight L (sparseGapValue (gapSpliceCode G ωf x (y k) steps) (i.val+1)) := by + rw [real_volume_contact_choice_cube _ _ ha] + apply Finset.prod_le_prod₀ + · intros + positivity + · intro i _ + exact (h.contact_weight_bound G hloc x η y k j M ω ωf steps hCf L hL hgood (i.val+1)).2 + + +theorem SpliceTrace.code_unique_of_gapCode (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j : ℕ) (ω₁ ω₂ ωf : Set E) + (c₁ c₂ : List (ℕ × E)) + (ht₁ : SpliceTrace G x η₁ y₁ k j ω₁ c₁ ωf) + (ht₂ : SpliceTrace G x η₂ y₂ k j ω₂ c₂ ωf) + (hz : y₁ k = y₂ k) (hC : (cluster G ωf x).Finite) + (heq : gapSpliceCode G ωf x (y₁ k) c₁ = gapSpliceCode G ωf x (y₁ k) c₂) : c₁ = c₂ := by + apply ordinalSpliceCode_injective G ωf x (y₁ k) hC c₁ c₂ + (ht₁.seams_pivotal G x η₁ y₁ k j ω₁ ωf c₁) + (by simpa only [hz] using ht₂.seams_pivotal G x η₂ y₂ k j ω₂ ωf c₂) + rw [← ht₁.decode_gap_code G x η₁ y₁ k j ω₁ ωf c₁ hC,heq,hz, + ht₂.decode_gap_code G x η₂ y₂ k j ω₂ ωf c₂ hC] + +end TraceContactMass + +end Percolation + + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteInverseMass +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_inverse_contact_mass_le {I : Type*} [Fintype I] + (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) + (L : ℝ) (hL : 1 ≤ L) (p : unitInterval) (Q : Finset E) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (hir : Function.Injective (fun a => (inp a,steps a))) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) + (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ + (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) + (rank : I → Fin k → ℕ) + (hrank : ∀ a i, rank a i < traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1)) + (B : Finset (SpliceState E)) (hB : ∀ a, out a ∈ B) : + (∑ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) * + ((volume : Measure (Fin k → unitInterval)) + (Set.pi Set.univ (fun i => contactChoiceSet + (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1)) + (rank a i)))).toReal) ≤ + (∑ t ∈ B, spliceTupleWeight Q (Finset.Icc 1 k) p t) * inverseCodeMass M L ^ k := by + let c : I → List (ℕ × ℕ) := fun a => gapSpliceCode G (out a).1 x z (steps a) + have hvalid : ∀ a, ValidSparseGapCode k M (c a) := by + intro a + have hv := (htrace a).valid_gap_code G hloc x (inp a).2 (y a) k 0 M + (inp a).1 (out a).1 (steps a) (hfin a) L (hgood a) + simpa only [c,hz a] using hv.1 + let arr (a : I) : Fin k → Fin (M+1) := sparseGapArray k M (c a) (hvalid a) + let f (a : I) : SpliceState E × (Fin k → Fin (M+1)) := (out a,arr a) + have hinj : Function.Injective f := by + intro a b he + have ho : out a = out b := congrArg Prod.fst he + have hc : c a = c b := sparseGapArray_injective k M (c a) (c b) + (hvalid a) (hvalid b) (congrArg Prod.snd he) + have hze : y a k = y b k := (hz a).trans (hz b).symm + have htB : SpliceTrace G x (inp b).2 (y b) k 0 (inp b).1 (steps b) (out a).1 := by + rw [ho] + exact htrace b + have heB : SpliceExecution G x (inp b) (steps b) (out a) := ho.symm ▸ hex b + have hg : gapSpliceCode G (out a).1 x (y a k) (steps a) = + gapSpliceCode G (out a).1 x (y a k) (steps b) := by + simpa only [c,hz a,ho] using hc + have hs := (htrace a).code_unique_of_gapCode G x (inp a).2 (inp b).2 (y a) (y b) + k 0 (inp a).1 (inp b).1 (out a).1 (steps a) (steps b) htB hze (hfin a) hg + have hi := (htrace a).input_unique_of_gapCode G x (inp a).2 (inp b).2 (y a) (y b) + k 0 (inp a).1 (inp b).1 (out a).1 (steps a) (steps b) htB hze (hfin a) hg + (out a).2 (hex a) heB + exact hir (Prod.ext hi hs) + let w (t : SpliceState E × (Fin k → Fin (M+1))) : ℝ := + spliceTupleWeight Q (Finset.Icc 1 k) p t.1 * ∏ i, gapLetterWeight L (t.2 i).val + have hweight : ∀ a, spliceTupleWeight Q (Finset.Icc 1 k) p (inp a) = + spliceTupleWeight Q (Finset.Icc 1 k) p (out a) := by + intro a + apply ((hex a).weight G x (inp a) (out a) (steps a) Q (Finset.Icc 1 k) ?_ p).symm + intro q hq + have hq' := (htrace a).seam_data G x (inp a).2 (y a) k 0 (inp a).1 (out a).1 (steps a) q hq + exact Finset.mem_Icc.mpr ⟨hq'.1,hq'.2.1⟩ + calc + _ ≤ ∑ a, w (f a) := by + apply Finset.sum_le_sum + intro a _ + dsimp only [w,f,arr,sparseGapArray] + rw [← hweight a] + apply mul_le_mul_of_nonneg_left _ (spliceTupleWeight_nonneg _ _ p _) + have hh := (htrace a).contact_cube_le_code_weight G hloc x (inp a).2 (y a) + k 0 M (inp a).1 (out a).1 (steps a) (hfin a) L hL (hgood a) (rank a) (hrank a) + simpa only [c,hz a] using hh + _ = ∑ t ∈ Finset.univ.image f, w t := (Finset.sum_image hinj.injOn).symm + _ ≤ ∑ t ∈ B ×ˢ (Finset.univ : Finset (Fin k → Fin (M+1))), w t := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro t ht + obtain ⟨a,_,rfl⟩ := Finset.mem_image.mp ht + exact Finset.mem_product.mpr ⟨hB a,Finset.mem_univ _⟩ + · intro t _ _ + exact mul_nonneg (spliceTupleWeight_nonneg _ _ p _) + (Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L (by linarith) _)) + _ = _ := by + rw [Finset.sum_product] + simp only [w,← Finset.mul_sum,total_gap_code_mass,← Finset.sum_mul] + +end FiniteInverseMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RemoteSpliceGeometry +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def GraphSeparated (G : BondGraph V E) (A B : Set V) : Prop := + Disjoint A B ∧ ∀ a ∈ A, ∀ b ∈ B, ¬Adj G a b + +theorem GraphSeparated.symm (G : BondGraph V E) (A B : Set V) + (h : GraphSeparated G A B) : GraphSeparated G B A := by + refine ⟨h.1.symm,?_⟩ + intro b hb a ha hab + obtain ⟨e,he⟩ := hab + exact h.2 a ha b hb ⟨e,he.trans (Sym2.eq_swap ..)⟩ + +theorem GraphSeparated.mono (G : BondGraph V E) {A B C D : Set V} + (h : GraphSeparated G A B) (hC : C ⊆ A) (hD : D ⊆ B) : GraphSeparated G C D := by + exact ⟨h.1.mono hC hD,fun c hc d hd => h.2 c (hC hc) d (hD hd)⟩ + +theorem GraphSeparated.no_shared_incidence (G : BondGraph V E) (A B : Set V) + (h : GraphSeparated G A B) (e : E) (a b : V) (ha : a ∈ A) (hb : b ∈ B) + (hea : a ∈ G e) (heb : b ∈ G e) : False := by + have hne : a ≠ b := by + rintro rfl + exact Set.disjoint_left.mp h.1 ha hb + exact h.2 a ha b hb ⟨e,(Sym2.mem_and_mem_iff hne).mp ⟨hea,heb⟩⟩ + + + +theorem slit_cluster_remove_remote (G : BondGraph V E) (η : Set E) (S H : Set V) + (y : V) (hy : y ∉ S) + (hsep : GraphSeparated G (cluster G (η ∩ internalEdges G Sᶜ) y) H) : + cluster G (η ∩ internalEdges G (S \ H)ᶜ) y = cluster G (η ∩ internalEdges G Sᶜ) y := by + apply Set.Subset.antisymm + · intro v hv + induction hv with + | refl => exact conn_refl G _ y + | @tail a b hya hab ih => + obtain ⟨e,he,hab⟩ := hab + have hbH : b ∉ H := fun hb => hsep.2 a ih b hb ⟨e,hab⟩ + have hbS : b ∉ S := by + have hb := ((mem_internalEdges_of_ends G _ e a b hab).mp he.2).2 + exact fun h => hb ⟨h,hbH⟩ + have haS := slit_cluster_subset G S η y hy ih + exact ih.tail ⟨e,⟨he.1,(mem_internalEdges_of_ends G _ e a b hab).mpr ⟨haS,hbS⟩⟩,hab⟩ + · exact fun _ h => conn_mono G + (Set.inter_subset_inter_right _ (internalEdges_mono G (by + intro v hv hvS + exact hv hvS.1))) h + + + +theorem spliceMask_remove_remote (G : BondGraph V E) (S B H : Set V) (e : E) + (hsep : GraphSeparated G B H) : spliceMask G (S \ H) B e = spliceMask G S B e := by + ext f + simp only [spliceMask,Set.mem_insert_iff,Set.mem_ofPred_eq] + apply or_congr Iff.rfl + constructor + · rintro ⟨⟨b,hb,hbf⟩,hi⟩ + refine ⟨⟨b,hb,hbf⟩,?_⟩ + intro v hv hvS + have hvH : v ∉ H := fun hh => hsep.no_shared_incidence G B H f b v hb hh hbf hv + exact hi v hv ⟨hvS,hvH⟩ + · rintro ⟨hb,hi⟩ + exact ⟨hb,fun v hv h => hi v hv h.1⟩ + + +theorem spliceMask_incident (G : BondGraph V E) (S B : Set V) (e : E) + (b : V) (hb : b ∈ B) (heb : b ∈ G e) : + ∀ f ∈ spliceMask G S B e, ∃ v ∈ B, v ∈ G f := by + intro f hf + rcases Set.mem_insert_iff.mp hf with rfl | hf + · exact ⟨b,hb,heb⟩ + · exact hf.1 + + + +theorem disjoint_spliceMasks (G : BondGraph V E) (S₁ S₂ B₁ B₂ : Set V) (e₁ e₂ : E) + (b₁ b₂ : V) (hb₁ : b₁ ∈ B₁) (hb₂ : b₂ ∈ B₂) (he₁ : b₁ ∈ G e₁) (he₂ : b₂ ∈ G e₂) + (hsep : GraphSeparated G B₁ B₂) : + Disjoint (spliceMask G S₁ B₁ e₁) (spliceMask G S₂ B₂ e₂) := by + apply Set.disjoint_left.mpr + intro f hf₁ hf₂ + obtain ⟨a,ha,haf⟩ := spliceMask_incident G S₁ B₁ e₁ b₁ hb₁ he₁ f hf₁ + obtain ⟨b,hb,hbf⟩ := spliceMask_incident G S₂ B₂ e₂ b₂ hb₂ he₂ f hf₂ + exact hsep.no_shared_incidence G B₁ B₂ f a b ha hb haf hbf + +end RemoteSpliceGeometry + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section RemoteReplay +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def replaySplice (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : + List (ℕ × E) → Set E → Set E + | [], ω => ω + | (i,e)::rest, ω => + replaySplice G x η y rest (spliceField G (cluster G ω x) + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) + + +def replayMasks (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : + List (ℕ × E) → Set E → List (ℕ × Set E) + | [], _ => [] + | (i,e)::rest, ω => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + (i,spliceMask G S B e)::replayMasks G x η y rest (spliceField G S B e ω (η i)) + + +def replayContacts (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) : + List (ℕ × E) → Set E → List (Set E) + | [], _ => [] + | (i,e)::rest, ω => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + contactSet G (η i) B::replayContacts G x η y rest (spliceField G S B e ω (η i)) + +theorem SpliceTrace.replay_eq (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : replaySplice G x η y steps ω = ωf := by + induction h with + | stop => rfl + | step => assumption + + + +theorem SpliceTrace.remote_replay (G : BondGraph V E) (x : V) (η : ℕ → Set E) (y : ℕ → V) + (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) (H : Set V) (ω₀ : Set E) + (hroot : cluster G ω₀ x = cluster G ω x \ H) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω x) H) + (hzH : y k ∉ H) : + SpliceTrace G x η y k j ω₀ steps (replaySplice G x η y steps ω₀) ∧ + cluster G (replaySplice G x η y steps ω₀) x = cluster G ωf x \ H ∧ + replayMasks G x η y steps ω₀ = replayMasks G x η y steps ω ∧ + replayContacts G x η y steps ω₀ = replayContacts G x η y steps ω := by + induction h generalizing ω₀ with + | stop j ω hs => + refine ⟨SpliceTrace.stop j ω₀ ?_,hroot,rfl,rfl⟩ + rw [hroot] + exact ⟨hs,hzH⟩ + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + let S₀ := cluster G ω₀ x + let B₀ := cluster G (η i ∩ internalEdges G S₀ᶜ) (y i) + let ω₀' := spliceField G S₀ B₀ e ω₀ (η i) + have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb + have hBo : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy + have hretain : cluster G ω' x ⊆ cluster G ωf x := ht.cluster_subset G x η y k i ω' ωf rest + have hBT : B ⊆ cluster G ωf x \ S := by + intro v hv + refine ⟨hretain ?_,hBo hv⟩ + rw [hC] + exact Or.inr hv + have hsepB : GraphSeparated G B H := hsep.mono G hBT Set.Subset.rfl + have hBB : B₀ = B := by + dsimp only [B₀,S₀] + rw [hroot] + exact slit_cluster_remove_remote G (η i) S H (y i) hy hsepB + have haH : a ∉ H := fun hh => hsepB.2 b hb a hh ⟨e,hab.trans (Sym2.eq_swap ..)⟩ + have ha₀ : a ∈ S₀ := by rw [show S₀ = S \ H from hroot]; exact ⟨ha,haH⟩ + have hy₀ : y i ∉ S₀ := by rw [show S₀ = S \ H from hroot]; exact fun h => hy h.1 + have hb₀ : b ∈ B₀ := hBB.symm ▸ hb + have hC₀ : cluster G ω₀' x = S₀ ∪ B₀ := + splice_cluster G ω₀ (η i) x (y i) hy₀ e a b hab he ha₀ hb₀ + have hroot' : cluster G ω₀' x = cluster G ω' x \ H := by + rw [hC₀,hC,hBB,show S₀ = S \ H from hroot] + ext v + constructor + · rintro (⟨hv,hvH⟩ | hv) + · exact ⟨Or.inl hv,hvH⟩ + · exact ⟨Or.inr hv,fun hvH => Set.disjoint_left.mp hsepB.1 hv hvH⟩ + · rintro ⟨hv,hvH⟩ + exact hv.elim (fun h => Or.inl ⟨h,hvH⟩) Or.inr + have hsep' : GraphSeparated G (cluster G ωf x \ cluster G ω' x) H := by + apply hsep.mono G _ Set.Subset.rfl + intro v hv + refine ⟨hv.1,fun h => hv.2 ?_⟩ + rw [hC] + exact Or.inl h + obtain ⟨ht₀,hfinal,hmasks,hcontacts⟩ := ih ω₀' hroot' hsep' + have hn₀ : y k ∉ S₀ := by rw [show S₀ = S \ H from hroot]; exact fun h => hn h.1 + have hmax₀ : ∀ l, i < l → l ≤ k → Disjoint (cluster G (η l) (y l)) S₀ := by + intro l hil hlk + apply (hmax l hil hlk).mono Set.Subset.rfl + rw [show S₀ = S \ H from hroot] + exact Set.sdiff_subset + have hmask : spliceMask G S₀ B₀ e = spliceMask G S B e := by + rw [hBB,show S₀ = S \ H from hroot,spliceMask_remove_remote G S B H e hsepB] + refine ⟨SpliceTrace.step j i ω₀ e a b rest _ hn₀ hji hik hmax₀ hy₀ he hab ha₀ hb₀ ht₀, + hfinal,?_,?_⟩ + · change (i,spliceMask G S₀ B₀ e)::replayMasks G x η y rest ω₀' = + (i,spliceMask G S B e)::replayMasks G x η y rest ω' + rw [hmask,hmasks] + · change contactSet G (η i) B₀::replayContacts G x η y rest ω₀' = + contactSet G (η i) B::replayContacts G x η y rest ω' + rw [hBB,hcontacts] + +end RemoteReplay + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section DeterministicReplay +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def FollowsContactRule (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (choose : ℕ → Set E → E) (steps : List (ℕ × E)) (ω : Set E) : Prop := + List.Forall₂ (fun q K => choose q.1 K = q.2) steps (replayContacts G x η y steps ω) + +theorem followsContactRule_cons (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (choose : ℕ → Set E → E) (i : ℕ) (e : E) + (rest : List (ℕ × E)) (ω : Set E) : + FollowsContactRule G x η y choose ((i,e)::rest) ω ↔ + choose i (contactSet G (η i) + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i))) = e ∧ + FollowsContactRule G x η y choose rest + (spliceField G (cluster G ω x) + (cluster G (η i ∩ internalEdges G (cluster G ω x)ᶜ) (y i)) e ω (η i)) := by + simp only [FollowsContactRule,replayContacts,List.forall₂_cons] + + + +theorem SpliceTrace.remote_follows_contact_rule (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) (H : Set V) (ω₀ : Set E) + (hroot : cluster G ω₀ x = cluster G ω x \ H) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω x) H) (hzH : y k ∉ H) + (choose : ℕ → Set E → E) (hc : FollowsContactRule G x η y choose steps ω) : + FollowsContactRule G x η y choose steps ω₀ := by + unfold FollowsContactRule at hc ⊢ + rw [(h.remote_replay G x η y k j ω ωf steps H ω₀ hroot hsep hzH).2.2.2] + exact hc + + + +theorem SpliceTrace.seeded_unique (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ω₁ ω₂ : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η y k j ω c₁ ω₁) + (h₂ : SpliceTrace G x η y k j ω c₂ ω₂) (choose : ℕ → Set E → E) + (hc₁ : FollowsContactRule G x η y choose c₁ ω) + (hc₂ : FollowsContactRule G x η y choose c₂ ω) : c₁ = c₂ ∧ ω₁ = ω₂ := by + induction h₁ generalizing c₂ ω₂ with + | stop j ω hs => + cases h₂ with + | stop => exact ⟨rfl,rfl⟩ + | step _ _ _ _ _ _ _ _ hn => exact (hn hs).elim + | @step j i ω e a b rest ω₁ hn hji hik hmax hy he hab ha hb ht ih => + cases h₂ with + | stop _ _ hs => exact (hn hs).elim + | step _ l _ f c d tail ω₂ hn₂ hjl hlk hmax₂ hy₂ hf hcd hc hd ht₂ => + have haC : a ∈ cluster G (η i) (y i) := + (edge_cluster_sides G (η i) (y i) he hab).mpr (conn_mono G Set.inter_subset_left hb) + have hcC : c ∈ cluster G (η l) (y l) := + (edge_cluster_sides G (η l) (y l) hf hcd).mpr (conn_mono G Set.inter_subset_left hd) + have hil : i = l := by + rcases lt_trichotomy i l with hil | hil | hli + · exact (Set.disjoint_left.mp (hmax l hil hlk) hcC hc).elim + · exact hil + · exact (Set.disjoint_left.mp (hmax₂ i hli hik) haC ha).elim + subst l + obtain ⟨hec,hrest⟩ := (followsContactRule_cons G x η y choose i e rest ω).mp hc₁ + obtain ⟨hfc,htail⟩ := (followsContactRule_cons G x η y choose i f tail ω).mp hc₂ + have hef : e = f := hec.symm.trans hfc + rw [← hef] at ht₂ htail ⊢ + obtain ⟨hcodes,houts⟩ := ih ω₂ tail ht₂ hrest htail + exact ⟨congrArg (List.cons (i,e)) hcodes,houts⟩ + +end DeterministicReplay + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TraceMaskSupport +attribute [local instance] Classical.propDecidable Classical.decEq + + +def maskUnion (masks : List (ℕ × Set E)) : Set E := + {e | ∃ q ∈ masks, e ∈ q.2} + +@[simp] theorem maskUnion_nil : maskUnion ([] : List (ℕ × Set E)) = ∅ := by + ext e + simp [maskUnion] + +@[simp] theorem maskUnion_cons (i : ℕ) (M : Set E) (ms : List (ℕ × Set E)) : + maskUnion ((i,M)::ms) = M ∪ maskUnion ms := by + ext e + simp [maskUnion,or_and_right,exists_or] + + +theorem SpliceTrace.masks_incident (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : + ∀ f ∈ maskUnion (replayMasks G x η y steps ω), + ∃ b ∈ cluster G ωf x \ cluster G ω x, b ∈ G f := by + induction h with + | stop => simp [replayMasks] + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let ω' := spliceField G S B e ω (η i) + have hC : cluster G ω' x = S ∪ B := splice_cluster G ω (η i) x (y i) hy e a b hab he ha hb + have hB : B ⊆ Sᶜ := slit_cluster_subset G S (η i) (y i) hy + have hretain := ht.cluster_subset G x η y k i ω' ωf rest + intro f hf + change f ∈ maskUnion ((i,spliceMask G S B e)::replayMasks G x η y rest ω') at hf + rw [maskUnion_cons] at hf + rcases hf with hf | hf + · obtain ⟨v,hv,hvf⟩ := spliceMask_incident G S B e b hb (by simp [hab]) f hf + refine ⟨v,⟨hretain ?_,hB hv⟩,hvf⟩ + rw [hC] + exact Or.inr hv + · obtain ⟨v,hv,hvf⟩ := ih f hf + refine ⟨v,⟨hv.1,fun h => hv.2 ?_⟩,hvf⟩ + rw [hC] + exact Or.inl h + + +theorem replaySplice_off_masks (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (steps : List (ℕ × E)) (ω : Set E) (f : E) + (hf : f ∉ maskUnion (replayMasks G x η y steps ω)) : + f ∈ replaySplice G x η y steps ω ↔ f ∈ ω := by + induction steps generalizing ω with + | nil => rfl + | cons q rest ih => + obtain ⟨i,e⟩ := q + simp only [replayMasks,maskUnion_cons,Set.mem_union,not_or] at hf + change f ∈ replaySplice G x η y rest _ ↔ f ∈ ω + rw [ih _ hf.2] + simp only [spliceField,mem_exchangeOn,ite_eq_right hf.1] + + +theorem SpliceTrace.masks_disjoint (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + Disjoint (maskUnion (replayMasks G x η₁ y₁ c₁ ω₁)) + (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) := by + apply Set.disjoint_left.mpr + intro f hf₁ hf₂ + obtain ⟨a,ha,hea⟩ := h₁.masks_incident G x η₁ y₁ k j₁ ω₁ ωf c₁ f hf₁ + obtain ⟨b,hb,heb⟩ := h₂.masks_incident G x η₂ y₂ k j₂ ω₂ ωf c₂ f hf₂ + exact hsep.no_shared_incidence G _ _ f a b ha hb hea heb + + + +theorem conn_delete_rootBridge (G : BondGraph V E) (ω η : Set E) (x z : V) + (hη : η ⊆ ω) (e : E) (a b : V) (hab : G e = s(a,b)) + (hb : b ∉ cluster G (ω \ {e}) x) (hz : z ∈ cluster G (ω \ {e}) x) + (hxz : Conn G η x z) : Conn G (η \ {e}) x z := by + have hc : Conn G (insert e (η \ {e})) x z := conn_mono G (by + intro f hf + by_cases hfe : f = e + · exact Or.inl hfe + · exact Or.inr ⟨hf,hfe⟩) hxz + have hs : η \ {e} ⊆ ω \ {e} := Set.sdiff_subset_sdiff_left hη + rw [conn_insert_iff G _ e a b x z hab] at hc + rcases hc with hc | ⟨_,hc⟩ | ⟨hc,_⟩ + · exact hc + · exact (hb (hz.trans (conn_symm G _ (conn_mono G hs hc)))).elim + · exact (hb (conn_mono G hs hc)).elim + + +theorem cluster_double_cut (G : BondGraph V E) (ω : Set E) (x : V) (e f : E) + (a b : V) (hab : G f = s(a,b)) (hb : b ∉ cluster G (ω \ {f}) x) : + cluster G ((ω \ {e}) \ {f}) x = cluster G (ω \ {e}) x ∩ cluster G (ω \ {f}) x := by + apply Set.Subset.antisymm + · intro v hv + exact ⟨conn_mono G Set.sdiff_subset hv, + conn_mono G (ω₁ := (ω \ {e}) \ {f}) (ω₂ := ω \ {f}) (fun _ h => ⟨h.1.1,h.2⟩) hv⟩ + · intro v hv + exact conn_delete_rootBridge G ω (ω \ {e}) x v Set.sdiff_subset f a b hab hb hv.2 hv.1 + +end TraceMaskSupport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section JointRoot +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem mask_not_crossing_remote (G : BondGraph V E) (U : Set E) (A B : Set V) + (hU : ∀ e ∈ U, ∃ v ∈ B, v ∈ G e) (hBA : B ⊆ A) + (e : E) (a b : V) (hab : G e = s(a,b)) (haB : a ∉ B) (hbA : b ∉ A) : e ∉ U := by + intro he + obtain ⟨v,hv,hve⟩ := hU e he + have hvab : v = a ∨ v = b := by simpa only [hab,Sym2.mem_iff] using hve + rcases hvab with rfl | rfl + · exact haB hv + · exact hbA (hBA hv) + + + +theorem exchange_patch_symm (U₁ U₂ ω₁ ω₂ ωf : Set E) + (hdis : Disjoint U₁ U₂) + (h₁ : ∀ e ∉ U₁, e ∈ ω₁ ↔ e ∈ ωf) + (h₂ : ∀ e ∉ U₂, e ∈ ω₂ ↔ e ∈ ωf) : + exchangeOn U₂ ω₁ ω₂ = exchangeOn U₁ ω₂ ω₁ := by + ext e + by_cases he₁ : e ∈ U₁ + · have he₂ : e ∉ U₂ := fun h => Set.disjoint_left.mp hdis he₁ h + simp only [mem_exchangeOn,ite_eq_right he₂,ite_eq_left he₁] + · by_cases he₂ : e ∈ U₂ + · simp only [mem_exchangeOn,ite_eq_left he₂,ite_eq_right he₁] + · simp only [mem_exchangeOn,ite_eq_right he₁,ite_eq_right he₂] + exact (h₁ e he₁).trans (h₂ e he₂).symm + + + +theorem SpliceTrace.joint_root (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ i₁ i₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (e₁ e₂ : E) (r₁ r₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ ((i₁,e₁)::r₁) ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ ((i₂,e₂)::r₂) ωf) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + cluster G (exchangeOn (maskUnion (replayMasks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂)) ω₁ ω₂) x = + cluster G ω₁ x ∩ cluster G ω₂ x := by + let A₁ := cluster G ω₁ x + let A₂ := cluster G ω₂ x + let B₁ := cluster G ωf x \ A₁ + let B₂ := cluster G ωf x \ A₂ + let U₁ := maskUnion (replayMasks G x η₁ y₁ ((i₁,e₁)::r₁) ω₁) + let U₂ := maskUnion (replayMasks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂) + let ω₀ := exchangeOn U₂ ω₁ ω₂ + have hsub₁ := h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁) + have hsub₂ := h₂.cluster_subset G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) + have hBA₁ : B₁ ⊆ A₂ := by + intro v hv + by_contra hn + exact Set.disjoint_left.mp hsep.1 hv ⟨hv.1,hn⟩ + have hBA₂ : B₂ ⊆ A₁ := by + intro v hv + by_contra hn + exact Set.disjoint_left.mp hsep.1 ⟨hv.1,hn⟩ hv + have hU₁ : ∀ e ∈ U₁, ∃ v ∈ B₁, v ∈ G e := + h₁.masks_incident G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁) + have hU₂ : ∀ e ∈ U₂, ∃ v ∈ B₂, v ∈ G e := + h₂.masks_incident G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) + have hdis : Disjoint U₁ U₂ := h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf + ((i₁,e₁)::r₁) ((i₂,e₂)::r₂) h₂ hsep + have hoff₁ : ∀ e ∉ U₁, e ∈ ω₁ ↔ e ∈ ωf := by + intro e he + rw [← h₁.replay_eq G x η₁ y₁ k j₁ ω₁ ωf ((i₁,e₁)::r₁)] + exact (replaySplice_off_masks G x η₁ y₁ ((i₁,e₁)::r₁) ω₁ e he).symm + have hoff₂ : ∀ e ∉ U₂, e ∈ ω₂ ↔ e ∈ ωf := by + intro e he + rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂)] + exact (replaySplice_off_masks G x η₂ y₂ ((i₂,e₂)::r₂) ω₂ e he).symm + have hsym : ω₀ = exchangeOn U₁ ω₂ ω₁ := exchange_patch_symm U₁ U₂ ω₁ ω₂ ωf hdis hoff₁ hoff₂ + have hcut₁ := h₁.head_cut G x η₁ y₁ k j₁ i₁ ω₁ ωf e₁ r₁ + have hcut₂ := h₂.head_cut G x η₂ y₂ k j₂ i₂ ω₂ ωf e₂ r₂ + obtain ⟨a,b,hab,_,hb,_⟩ := openMarkedPivotal_oriented G ωf {y₂ k} x + (h₂.seams_pivotal G x η₂ y₂ k j₂ ω₂ ωf ((i₂,e₂)::r₂) (i₂,e₂) (by simp)) + have hdouble : cluster G ((ωf \ {e₁}) \ {e₂}) x = A₁ ∩ A₂ := by + rw [cluster_double_cut G ωf x e₁ e₂ a b hab hb,hcut₁,hcut₂] + change cluster G ω₀ x = A₁ ∩ A₂ + apply Set.Subset.antisymm + · intro v hv + induction hv with + | refl => exact ⟨conn_refl G _ x,conn_refl G _ x⟩ + | @tail a b hxa hab ih => + obtain ⟨e,he,hab⟩ := hab + constructor + · by_contra hb + have hno := mask_not_crossing_remote G U₂ A₁ B₂ hU₂ hBA₂ e a b hab + (fun hh => hh.2 ih.2) hb + have he₁ : e ∈ ω₁ := by simpa only [ω₀,mem_exchangeOn,ite_eq_right hno] using he + exact hb ((edge_cluster_sides G ω₁ x he₁ hab).mp ih.1) + · by_contra hb + have hno := mask_not_crossing_remote G U₁ A₂ B₁ hU₁ hBA₁ e a b hab + (fun hh => hh.2 ih.1) hb + have he₂ : e ∈ ω₂ := by simpa only [hsym,mem_exchangeOn,ite_eq_right hno] using he + exact hb ((edge_cluster_sides G ω₂ x he₂ hab).mp ih.2) + · intro v hv + have hc : Conn G ((ωf \ {e₁}) \ {e₂}) x v := by + change v ∈ cluster G ((ωf \ {e₁}) \ {e₂}) x + rw [hdouble] + exact hv + have hr := conn_restrict_cluster G ((ωf \ {e₁}) \ {e₂}) x (mem_cluster_self G _ x) hc + apply conn_mono G _ hr + intro e he + have hi : e ∈ internalEdges G (A₁ ∩ A₂) := by + simpa only [hdouble] using he.2 + have hno : e ∉ U₂ := by + intro hu + obtain ⟨b,hb,heb⟩ := hU₂ e hu + exact hb.2 (hi b heb).2 + have he₁ : e ∈ ω₁ := (h₁.internal_agreement G x η₁ y₁ k j₁ ω₁ ωf + ((i₁,e₁)::r₁) e (fun a ha => (hi a ha).1)).mp he.1.1.1 + simpa only [ω₀,mem_exchangeOn,ite_eq_right hno] using he₁ + +end JointRoot + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section MaskExecution +attribute [local instance] Classical.propDecidable Classical.decEq + + +def runMasks : List (ℕ × Set E) → SpliceState E → SpliceState E + | [], s => s + | (i,M)::ms, s => runMasks ms (exchangeState M i s) + + +def patchFirst (U τ : Set E) (s : SpliceState E) : SpliceState E := + (exchangeOn U s.1 τ,s.2) + +theorem exchangeState_patchFirst (U τ M : Set E) (i : ℕ) (s : SpliceState E) + (hdis : Disjoint M U) : + exchangeState M i (patchFirst U τ s) = patchFirst U τ (exchangeState M i s) := by + apply Prod.ext + · ext e + by_cases heM : e ∈ M + · have heU : e ∉ U := fun he => Set.disjoint_left.mp hdis heM he + simp only [exchangeState,patchFirst,mem_exchangeOn,ite_eq_left heM,ite_eq_right heU] + · by_cases heU : e ∈ U <;> + simp only [exchangeState,patchFirst,mem_exchangeOn,ite_eq_right heM,heU,ite_true,ite_false] + · funext l + by_cases hli : l = i + · subst l + ext e + by_cases heM : e ∈ M + · have heU : e ∉ U := fun he => Set.disjoint_left.mp hdis heM he + simp only [exchangeState,patchFirst,Function.update_self,mem_exchangeOn,ite_eq_left heM,ite_eq_right heU] + · simp only [exchangeState,patchFirst,Function.update_self,mem_exchangeOn,ite_eq_right heM] + · simp only [exchangeState,patchFirst,Function.update_of_ne hli] + + + +theorem runMasks_patchFirst (ms : List (ℕ × Set E)) (U τ : Set E) (s : SpliceState E) + (hdis : Disjoint (maskUnion ms) U) : + runMasks ms (patchFirst U τ s) = patchFirst U τ (runMasks ms s) := by + induction ms generalizing s with + | nil => rfl + | cons q ms ih => + obtain ⟨i,M⟩ := q + rw [maskUnion_cons,Set.disjoint_union_left] at hdis + simp only [runMasks] + rw [exchangeState_patchFirst U τ M i s hdis.1,ih _ hdis.2] + + + +theorem SpliceTrace.runMasks_first (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (steps : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω steps ωf) : + ∀ θ : ℕ → Set E, (∀ l, j < l → l ≤ k → θ l = η l) → + (runMasks (replayMasks G x η y steps ω) (ω,θ)).1 = ωf := by + induction h with + | stop => exact fun _ _ => rfl + | @step j i ω e a b rest ωf hn hji hik hmax hy he hab ha hb ht ih => + intro θ hθ + have hθi := hθ i hji hik + let S := cluster G ω x + let B := cluster G (η i ∩ internalEdges G Sᶜ) (y i) + let M := spliceMask G S B e + let ω' := spliceField G S B e ω (η i) + let θ' := Function.update θ i (exchangeOn M (θ i) ω) + have hstep : exchangeState M i (ω,θ) = (ω',θ') := by + apply Prod.ext + · change exchangeOn M ω (θ i) = exchangeOn M ω (η i) + rw [hθi] + · rfl + change (runMasks (replayMasks G x η y rest ω') (exchangeState M i (ω,θ))).1 = ωf + rw [hstep] + apply ih θ' + intro l hil hlk + rw [show θ' l = θ l from Function.update_of_ne (by omega) _ _] + exact hθ l (hji.trans hil) hlk + + +theorem runMasks_weight (ms : List (ℕ × Set E)) (s : SpliceState E) + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (hJ : ∀ q ∈ ms, q.1 ∈ J) : + spliceTupleWeight Q J p (runMasks ms s) = spliceTupleWeight Q J p s := by + induction ms generalizing s with + | nil => rfl + | cons q ms ih => + obtain ⟨i,M⟩ := q + rw [runMasks,ih _ (fun q hq => hJ q (List.mem_cons_of_mem _ hq))] + exact spliceTupleWeight_exchange Q J p s M i (hJ (i,M) (List.mem_cons_self ..)) + + + +theorem SpliceTrace.joint_replay_state (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + let m₁ := replayMasks G x η₁ y₁ c₁ ω₁ + let m₂ := replayMasks G x η₂ y₂ c₂ ω₂ + let ω₀ := exchangeOn (maskUnion m₂) ω₁ ω₂ + runMasks m₁ (ω₀,η₁) = (ω₂,(runMasks m₁ (ω₁,η₁)).2) := by + intro m₁ m₂ ω₀ + have hdis := h₁.masks_disjoint G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep + have hroot := h₁.runMasks_first G x η₁ y₁ k j₁ ω₁ ωf c₁ η₁ (by intros; rfl) + have hpatch : exchangeOn (maskUnion m₂) ωf ω₂ = ω₂ := by + ext e + by_cases he : e ∈ maskUnion m₂ + · simp only [mem_exchangeOn,ite_eq_left he] + · simp only [mem_exchangeOn,ite_eq_right he] + rw [← h₂.replay_eq G x η₂ y₂ k j₂ ω₂ ωf c₂] + exact replaySplice_off_masks G x η₂ y₂ c₂ ω₂ e he + change runMasks m₁ (patchFirst (maskUnion m₂) ω₂ (ω₁,η₁)) = _ + rw [runMasks_patchFirst m₁ _ ω₂ _ hdis] + change (exchangeOn (maskUnion m₂) (runMasks m₁ (ω₁,η₁)).1 ω₂,_) = _ + rw [hroot,hpatch] + +end MaskExecution + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section JointReplay +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem SpliceTrace.endpoint_not_mem_of_ne_nil (G : BondGraph V E) (x : V) + (η : ℕ → Set E) (y : ℕ → V) (k j : ℕ) (ω ωf : Set E) (c : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω c ωf) (hc : c ≠ []) : y k ∉ cluster G ω x := by + cases h with + | stop => exact (hc rfl).elim + | step _ _ _ _ _ _ _ _ hn => exact hn + + + +theorem SpliceTrace.joint_virtual (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) : + let ω₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ + SpliceTrace G x η₁ y₁ k j₁ ω₀ c₁ ω₂ ∧ + replayMasks G x η₁ y₁ c₁ ω₀ = replayMasks G x η₁ y₁ c₁ ω₁ ∧ + replayContacts G x η₁ y₁ c₁ ω₀ = replayContacts G x η₁ y₁ c₁ ω₁ := by + intro ω₀ + have hroot' : cluster G ω₀ x = cluster G ω₁ x ∩ cluster G ω₂ x := by + cases c₁ with + | nil => exact (hc₁ rfl).elim + | cons q r₁ => + obtain ⟨i₁,e₁⟩ := q + cases c₂ with + | nil => exact (hc₂ rfl).elim + | cons q r₂ => + obtain ⟨i₂,e₂⟩ := q + exact h₁.joint_root G x η₁ η₂ y₁ y₂ k j₁ j₂ i₁ i₂ ω₁ ω₂ ωf e₁ e₂ r₁ r₂ h₂ hsep + let H := cluster G ωf x \ cluster G ω₂ x + have hroot : cluster G ω₀ x = cluster G ω₁ x \ H := by + rw [hroot'] + ext v + constructor + · rintro ⟨h1,h2⟩ + exact ⟨h1,fun hh => hh.2 h2⟩ + · rintro ⟨h1,h2⟩ + refine ⟨h1,?_⟩ + by_contra hn + exact h2 ⟨h₁.cluster_subset G x η₁ y₁ k j₁ ω₁ ωf c₁ h1,hn⟩ + have hz : y₁ k ∉ H := fun hz => Set.disjoint_left.mp hsep.1 + ⟨h₁.endpoint G x η₁ y₁ k j₁ ω₁ ωf c₁, + h₁.endpoint_not_mem_of_ne_nil G x η₁ y₁ k j₁ ω₁ ωf c₁ hc₁⟩ hz + obtain ⟨ht,hout,hm,hcontacts⟩ := h₁.remote_replay G x η₁ y₁ k j₁ ω₁ ωf c₁ H ω₀ hroot hsep hz + have hf := ht.runMasks_first G x η₁ y₁ k j₁ ω₀ (replaySplice G x η₁ y₁ c₁ ω₀) c₁ η₁ + (by intros; rfl) + rw [hm] at hf + have hs := h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep + have heq : replaySplice G x η₁ y₁ c₁ ω₀ = ω₂ := hf.symm.trans (congrArg Prod.fst hs) + rw [heq] at ht + exact ⟨ht,hm,hcontacts⟩ + + + +theorem joint_restore_seeded_unique (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (choose₁ choose₂ : ℕ → Set E → E) + (k j₁ j₂ : ℕ) (ω₁ ω₂ ωf σ₁ σ₂ σf : Set E) + (c₁ c₂ d₁ d₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (g₁ : SpliceTrace G x η₁ y₁ k j₁ σ₁ d₁ σf) + (g₂ : SpliceTrace G x η₂ y₂ k j₂ σ₂ d₂ σf) + (hc₁ : c₁ ≠ []) (hc₂ : c₂ ≠ []) (hd₁ : d₁ ≠ []) (hd₂ : d₂ ≠ []) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) + (gsep : GraphSeparated G (cluster G σf x \ cluster G σ₁ x) + (cluster G σf x \ cluster G σ₂ x)) + (hr₁ : FollowsContactRule G x η₁ y₁ choose₁ c₁ ω₁) + (hr₂ : FollowsContactRule G x η₂ y₂ choose₂ c₂ ω₂) + (gr₁ : FollowsContactRule G x η₁ y₁ choose₁ d₁ σ₁) + (gr₂ : FollowsContactRule G x η₂ y₂ choose₂ d₂ σ₂) + (hrestore : exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ = + exchangeOn (maskUnion (replayMasks G x η₂ y₂ d₂ σ₂)) σ₁ σ₂) : + c₁ = d₁ ∧ c₂ = d₂ ∧ ωf = σf ∧ + (runMasks (replayMasks G x η₁ y₁ c₁ ω₁) (ω₁,η₁)).2 = + (runMasks (replayMasks G x η₁ y₁ d₁ σ₁) (σ₁,η₁)).2 ∧ + (runMasks (replayMasks G x η₂ y₂ c₂ ω₂) (ω₂,η₂)).2 = + (runMasks (replayMasks G x η₂ y₂ d₂ σ₂) (σ₂,η₂)).2 := by + let ω₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ c₂ ω₂)) ω₁ ω₂ + let σ₀ := exchangeOn (maskUnion (replayMasks G x η₂ y₂ d₂ σ₂)) σ₁ σ₂ + obtain ⟨ht,hm,hcontact⟩ := h₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hc₁ hc₂ hsep + obtain ⟨gt,gm,gcontact⟩ := g₁.joint_virtual G x η₁ η₂ y₁ y₂ k j₁ j₂ σ₁ σ₂ σf d₁ d₂ g₂ hd₁ hd₂ gsep + have hrc : FollowsContactRule G x η₁ y₁ choose₁ c₁ ω₀ := by + unfold FollowsContactRule at hr₁ ⊢ + rw [hcontact] + exact hr₁ + have grc : FollowsContactRule G x η₁ y₁ choose₁ d₁ σ₀ := by + unfold FollowsContactRule at gr₁ ⊢ + rw [gcontact] + exact gr₁ + change SpliceTrace G x η₁ y₁ k j₁ σ₀ d₁ σ₂ at gt + change replayMasks G x η₁ y₁ c₁ ω₀ = _ at hm + change replayMasks G x η₁ y₁ d₁ σ₀ = _ at gm + have h00 : ω₀ = σ₀ := hrestore + rw [← h00] at gt grc + obtain ⟨hcode₁,hω₂⟩ := ht.seeded_unique G x η₁ y₁ k j₁ ω₀ ω₂ σ₂ c₁ d₁ gt choose₁ hrc grc + rw [← hω₂] at g₂ gr₂ + obtain ⟨hcode₂,hout⟩ := h₂.seeded_unique G x η₂ y₂ k j₂ ω₂ ωf σf c₂ d₂ g₂ choose₂ hr₂ gr₂ + refine ⟨hcode₁,hcode₂,hout,?_,?_⟩ + · have hs := congrArg Prod.snd (h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep) + have gs := congrArg Prod.snd (g₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ σ₁ σ₂ σf d₁ d₂ + (hω₂ ▸ g₂) gsep) + change (runMasks _ (ω₀,η₁)).2 = _ at hs + change (runMasks _ (σ₀,η₁)).2 = _ at gs + rw [← hs,← gs,← hm,← gm,h00,hcode₁] + · rw [hcode₂,hω₂] + +end JointReplay + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section JointWeight +attribute [local instance] Classical.propDecidable Classical.decEq + + + +abbrev JointSpliceState (E : Type v) := Set E × (ℕ → Set E) × (ℕ → Set E) + +noncomputable def jointTupleWeight (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (s : JointSpliceState E) : ℝ := + bernoulliWeight Q (domainBits Q s.1) p * + (∏ i ∈ J₁, bernoulliWeight Q (domainBits Q (s.2.1 i)) p) * + ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (s.2.2 i)) p + +theorem jointTupleWeight_nonneg (Q : Finset E) (J₁ J₂ : Finset ℕ) + (p : unitInterval) (s : JointSpliceState E) : 0 ≤ jointTupleWeight Q J₁ J₂ p s := by + exact mul_nonneg (spliceTupleWeight_nonneg Q J₁ p (s.1,s.2.1)) + (Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p) + +theorem replayMasks_indices (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) : + (replayMasks G x η y c ω).map Prod.fst = c.map Prod.fst := by + induction c generalizing ω with + | nil => rfl + | cons q c ih => + obtain ⟨i,e⟩ := q + simp only [replayMasks,List.map_cons,ih] + +theorem replayMasks_indices_mem (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (c : List (ℕ × E)) (ω : Set E) (J : Finset ℕ) + (hJ : ∀ q ∈ c, q.1 ∈ J) : ∀ q ∈ replayMasks G x η y c ω, q.1 ∈ J := by + intro q hq + have hq' : q.1 ∈ (replayMasks G x η y c ω).map Prod.fst := List.mem_map_of_mem hq + rw [replayMasks_indices G x η y c ω] at hq' + obtain ⟨r,hr,he⟩ := List.mem_map.mp hq' + exact he ▸ hJ r hr + + + +theorem SpliceTrace.joint_weight (G : BondGraph V E) (x : V) + (η₁ η₂ : ℕ → Set E) (y₁ y₂ : ℕ → V) (k j₁ j₂ : ℕ) + (ω₁ ω₂ ωf : Set E) (c₁ c₂ : List (ℕ × E)) + (h₁ : SpliceTrace G x η₁ y₁ k j₁ ω₁ c₁ ωf) + (h₂ : SpliceTrace G x η₂ y₂ k j₂ ω₂ c₂ ωf) + (hsep : GraphSeparated G (cluster G ωf x \ cluster G ω₁ x) + (cluster G ωf x \ cluster G ω₂ x)) + (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : ℝ) + (hJ₁ : ∀ q ∈ c₁, q.1 ∈ J₁) (hJ₂ : ∀ q ∈ c₂, q.1 ∈ J₂) : + let m₁ := replayMasks G x η₁ y₁ c₁ ω₁ + let m₂ := replayMasks G x η₂ y₂ c₂ ω₂ + let ω₀ := exchangeOn (maskUnion m₂) ω₁ ω₂ + jointTupleWeight Q J₁ J₂ p (ωf,(runMasks m₁ (ω₁,η₁)).2,(runMasks m₂ (ω₂,η₂)).2) = + jointTupleWeight Q J₁ J₂ p (ω₀,η₁,η₂) := by + intro m₁ m₂ ω₀ + have hw₁ := runMasks_weight m₁ (ω₀,η₁) Q J₁ p + (replayMasks_indices_mem G x η₁ y₁ c₁ ω₁ J₁ hJ₁) + rw [h₁.joint_replay_state G x η₁ η₂ y₁ y₂ k j₁ j₂ ω₁ ω₂ ωf c₁ c₂ h₂ hsep] at hw₁ + have hw₂ := runMasks_weight m₂ (ω₂,η₂) Q J₂ p + (replayMasks_indices_mem G x η₂ y₂ c₂ ω₂ J₂ hJ₂) + unfold spliceTupleWeight at hw₁ hw₂ + rw [h₂.runMasks_first G x η₂ y₂ k j₂ ω₂ ωf c₂ η₂ (by intros; rfl)] at hw₂ + unfold jointTupleWeight + dsimp only at hw₁ hw₂ ⊢ + calc + _ = (bernoulliWeight Q (domainBits Q ωf) p * + ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q ((runMasks m₂ (ω₂,η₂)).2 i)) p) * + ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p := by ring + _ = (bernoulliWeight Q (domainBits Q ω₂) p * + ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (η₂ i)) p) * + ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p := by rw [hw₂] + _ = (bernoulliWeight Q (domainBits Q ω₂) p * + ∏ i ∈ J₁, bernoulliWeight Q (domainBits Q ((runMasks m₁ (ω₁,η₁)).2 i)) p) * + ∏ i ∈ J₂, bernoulliWeight Q (domainBits Q (η₂ i)) p := by ring + _ = _ := by rw [hw₁] + +end JointWeight + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Coupling.lean b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Coupling.lean index f3a1d06702e7df1fd5fa6e852c128bcd3fdc6199..95c3d79c138c0a18a039987ee6320fd43a52c12e 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Coupling.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Coupling.lean @@ -1,347 +1,347 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Subdivision.Graph - -namespace OAI - -/-! Coupling percolation on a graph with percolation on its subdivision. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - - - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory ProbabilityTheory -open scoped ENNReal - -noncomputable def halfBit (G : BondGraph V E) : SubdivisionEdge G ↪ E × Bool := by - classical - refine ⟨fun ev => (ev.val.1,if ev.val.2 = (G ev.val.1).out.1 then false else true),?_⟩ - rintro ⟨⟨e,x⟩,hx⟩ ⟨⟨f,y⟩,hy⟩ h - have hef : e = f := congrArg Prod.fst h - subst f - have hb := congrArg Prod.snd h - dsimp only at hb - have he : G e = s((G e).out.1,(G e).out.2) := (G e).out_eq.symm - have hx' : x = (G e).out.1 ∨ x = (G e).out.2 := by - apply Sym2.mem_iff.mp - rw [←he] - exact hx - have hy' : y = (G e).out.1 ∨ y = (G e).out.2 := by - apply Sym2.mem_iff.mp - rw [←he] - exact hy - have hxy : x = y := by - by_cases h₁ : x = (G e).out.1 <;> by_cases h₂ : y = (G e).out.1 - · exact h₁.trans h₂.symm - · simp only [ite_eq_left h₁,ite_eq_right h₂,Bool.false_eq_true] at hb - · simp only [ite_eq_right h₁,ite_eq_left h₂,Bool.true_eq_false] at hb - · exact (hx'.resolve_left h₁).trans (hy'.resolve_left h₂).symm - subst y - rfl - -def seriesOpen (ν : Set (E × Bool)) : Set E := {e | ∀ b, (e,b) ∈ ν} - -noncomputable def subdivisionOpen (G : BondGraph V E) (ν : Set (E × Bool)) : - Set (SubdivisionEdge G) := halfBit G ⁻¹' ν - -@[simp] theorem halfBit_fst (G : BondGraph V E) (e : SubdivisionEdge G) : - (halfBit G e).1 = e.val.1 := rfl - - -theorem seriesOpen_of_two_incident (G : BondGraph V E) (ν : Set (E × Bool)) - (e : E) (x y : V) (hx : x ∈ G e) (hy : y ∈ G e) (hne : x ≠ y) - (hxo : (⟨(e,x),hx⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν) - (hyo : (⟨(e,y),hy⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν) : - e ∈ seriesOpen ν := by - have hbits : (halfBit G ⟨(e,x),hx⟩).2 ≠ (halfBit G ⟨(e,y),hy⟩).2 := by - intro h - have hh : halfBit G ⟨(e,x),hx⟩ = halfBit G ⟨(e,y),hy⟩ := Prod.ext rfl h - have he := (halfBit G).injective hh - exact hne (congrArg (fun z : SubdivisionEdge G => z.val.2) he) - intro b - have hb : b = (halfBit G ⟨(e,x),hx⟩).2 ∨ b = (halfBit G ⟨(e,y),hy⟩).2 := by - generalize (halfBit G ⟨(e,x),hx⟩).2 = c at * - generalize (halfBit G ⟨(e,y),hy⟩).2 = d at * - cases b <;> cases c <;> cases d <;> simp_all - rcases hb with rfl | rfl - · exact hxo - · exact hyo - - -theorem subdivision_open_adj_iff (G : BondGraph V E) (ν : Set (E × Bool)) (x : V) (e : E) : - (∃ d ∈ subdivisionOpen G ν, subdivision G d = s(Sum.inl x, Sum.inr e)) ↔ - ∃ hx : x ∈ G e, (⟨(e,x),hx⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := by - constructor - · rintro ⟨⟨⟨f,y⟩,hy⟩,ho,he⟩ - simp only [subdivision,Sym2.eq_iff] at he - rcases he with ⟨hyx,hfe⟩ | ⟨hbad,_⟩ - · have : y = x := Sum.inl.inj hyx - have : f = e := Sum.inr.inj hfe - subst y; subst f - exact ⟨hy,ho⟩ - · cases hbad - · rintro ⟨hx,ho⟩ - exact ⟨⟨(e,x),hx⟩,ho,rfl⟩ - - -theorem conn_subdivision_iff (G : BondGraph V E) (ν : Set (E × Bool)) (x y : V) : - Conn (subdivision G) (subdivisionOpen G ν) (.inl x) (.inl y) ↔ - Conn G (seriesOpen ν) x y := by - constructor - · intro hc - have reach (z : V ⊕ E) (h : Conn (subdivision G) (subdivisionOpen G ν) (.inl x) z) : - match z with - | .inl w => Conn G (seriesOpen ν) x w - | .inr e => ∃ w : V, ∃ hw : w ∈ G e, - (⟨(e,w),hw⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν ∧ Conn G (seriesOpen ν) x w := by - induction h with - | refl => exact conn_refl G _ x - | @tail u v huv hed ih => - cases u with - | inl a => - cases v with - | inl b => - obtain ⟨d,_,he⟩ := hed - exact (subdivision_adj_inl_inl G a b ⟨d,he⟩).elim - | inr e => - obtain ⟨ha,ho⟩ := (subdivision_open_adj_iff G ν a e).mp hed - exact ⟨a,ha,ho,ih⟩ - | inr e => - cases v with - | inl b => - have hed' : ∃ d ∈ subdivisionOpen G ν, subdivision G d = s(Sum.inl b, Sum.inr e) := by - obtain ⟨d,hd,he⟩ := hed - exact ⟨d,hd,he.trans (Sym2.eq_swap)⟩ - obtain ⟨hb,hbo⟩ := (subdivision_open_adj_iff G ν b e).mp hed' - obtain ⟨a,ha,hao,hxa⟩ := ih - by_cases hab : a = b - · simpa only [hab] using hxa - · exact hxa.tail ⟨e,seriesOpen_of_two_incident G ν e a b ha hb hab hao hbo, - (Sym2.mem_and_mem_iff hab).mp ⟨ha,hb⟩⟩ - | inr f => - obtain ⟨d,_,he⟩ := hed - exact (subdivision_adj_inr_inr G e f ⟨d,he⟩).elim - exact reach (.inl y) hc - · intro hc - induction hc with - | refl => exact conn_refl _ _ _ - | @tail a b hab hed ih => - obtain ⟨e,he,heq⟩ := hed - have ha : a ∈ G e := by simp [heq] - have hb : b ∈ G e := by simp [heq] - have hao : (⟨(e,a),ha⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := he _ - have hbo : (⟨(e,b),hb⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := he _ - exact (ih.tail ⟨⟨(e,a),ha⟩,hao,rfl⟩).tail ⟨⟨(e,b),hb⟩,hbo,Sym2.eq_swap⟩ - - -theorem map_bool_and (q : unitInterval) : - (Measure.infinitePi (fun _ : Bool => bitLaw q)).map - (fun f : Bool → Prop => ∀ b, f b) = bitLaw (q^2) := by - let μ := (Measure.infinitePi (fun _ : Bool => bitLaw q)).map - (fun f : Bool → Prop => ∀ b, f b) - have hm : Measurable (fun f : Bool → Prop => ∀ b, f b) := .of_discrete - have : IsProbabilityMeasure μ := inferInstance - have ht : μ.real {True} = (q:ℝ)^2 := by - change ((Measure.infinitePi _).map _).real _ = _ - rw [Measure.real,Measure.map_apply hm (measurableSet_singleton _)] - have he : (fun f : Bool → Prop => ∀ b, f b) ⁻¹' ({True} : Set Prop) = - ((Finset.univ : Finset Bool) : Set Bool).pi (fun _ => ({True} : Set Prop)) := by - ext f - simp [and_comm] - rw [he,Measure.infinitePi_pi _ (fun _ _ => measurableSet_singleton _)] - simp [bitLaw,ENNReal.toReal_mul,pow_two] - have hf : μ.real {False} = 1-(q:ℝ)^2 := by - have he : ({False} : Set Prop) = ({True} : Set Prop)ᶜ := by ext b; simp - rw [he,measureReal_compl (measurableSet_singleton _),probReal_univ,ht] - apply Measure.ext_of_singleton - intro b - apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp - change μ.real {b} = (bitLaw (q^2)).real {b} - by_cases hb : b - · have he : b = True := propext (iff_true_intro hb) - subst b - rw [ht] - simp [bitLaw,Measure.real] - · have he : b = False := propext (iff_false_intro hb) - subst b - rw [hf] - simp [bitLaw,Measure.real] - -theorem measurable_seriesOpen : Measurable (seriesOpen : Set (E × Bool) → Set E) := by - apply measurable_setOfPred.comp - apply Measurable.of_eval - intro e - apply measurableSet_setOfPred.mp - have he : {ν : Set (E × Bool) | ∀ b, (e,b) ∈ ν} = ⋂ b : Bool, {ν | (e,b) ∈ ν} := by - ext ν; simp - rw [he] - exact MeasurableSet.iInter fun b => measurableSet_setOfPred.mpr - ((measurable_pi_apply (e,b)).comp MeasurableEquiv.setOfPred.symm.measurable) - - -theorem law_map_seriesOpen (q : unitInterval) : - (law q : Measure (Set (E × Bool))).map seriesOpen = law (q^2) := by - let c := MeasurableEquiv.curry E Bool Prop - let b := fun f : E → Bool → Prop => fun e => ∀ j, f e j - have hb : Measurable b := Measurable.of_eval - (fun e => (Measurable.of_discrete : Measurable (fun f : Bool → Prop => ∀ j, f j)).comp - (measurable_pi_apply e)) - unfold law - rw [setBernoulli_eq_map,Measure.map_map measurable_seriesOpen measurable_setOfPred] - simp only [Set.mem_univ] - have he : seriesOpen ∘ (fun f : E × Bool → Prop => {e | f e}) = - (fun f : E → Prop => {e | f e}) ∘ b ∘ c := rfl - rw [he,←Measure.map_map measurable_setOfPred (hb.comp c.measurable), - ←Measure.map_map hb c.measurable] - change ((Measure.infinitePi (fun _ : E × Bool => bitLaw q)).map c |>.map b |>.map - (fun f : E → Prop => {e | f e})) = _ - rw [Measure.infinitePi_map_curry (fun (_ : E) (_ : Bool) => bitLaw q)] - dsimp only [b] - rw [Measure.infinitePi_map_pi _ (f := fun _ (g : Bool → Prop) => ∀ j, g j) - (fun _ => Measurable.of_discrete)] - rw [map_bool_and q,setBernoulli_eq_map] - rfl - -theorem measurable_subdivisionOpen (G : BondGraph V E) : Measurable (subdivisionOpen G) := - measurable_setOfPred.comp (Measurable.of_eval (fun e => - (measurable_pi_apply (halfBit G e)).comp MeasurableEquiv.setOfPred.symm.measurable)) - -theorem law_map_subdivisionOpen (G : BondGraph V E) (q : unitInterval) : - (law q : Measure (Set (E × Bool))).map (subdivisionOpen G) = law q := - law_map_preimage_embedding q (halfBit G) - - - -theorem twoPoint_subdivision [Countable V] [Countable E] - (G : BondGraph V E) (q : unitInterval) (x y : V) : - twoPoint (subdivision G) q (.inl x) (.inl y) = twoPoint G (q^2) x y := by - unfold twoPoint - congr 1 - rw [←law_map_subdivisionOpen G q,Measure.map_apply (measurable_subdivisionOpen G) - (measurableSet_conn (subdivision G) (.inl x) (.inl y))] - rw [←law_map_seriesOpen q,Measure.map_apply measurable_seriesOpen (measurableSet_conn G x y)] - congr 1 - ext ν - exact conn_subdivision_iff G ν x y - - -theorem conn_subdivision_inr (G : BondGraph V E) (ν : Set (E × Bool)) (x : V) (e : E) - (hc : Conn (subdivision G) (subdivisionOpen G ν) (.inl x) (.inr e)) : - ∃ y, Conn G (seriesOpen ν) x y ∧ y ∈ G e := by - rcases hc.cases_tail with h | ⟨z,hxz,hze⟩ - · cases h - · cases z with - | inl y => - obtain ⟨hy,_⟩ := (subdivision_open_adj_iff G ν y e).mp hze - exact ⟨y,(conn_subdivision_iff G ν x y).mp hxz,hy⟩ - | inr f => - obtain ⟨d,_,hd⟩ := hze - exact (subdivision_adj_inr_inr G f e ⟨d,hd⟩).elim - - - -theorem finite_cluster_subdivision_iff (G : BondGraph V E) (hloc : LocallyFinite G) - (ν : Set (E × Bool)) (x : V) : - (cluster (subdivision G) (subdivisionOpen G ν) (.inl x)).Finite ↔ - (cluster G (seriesOpen ν) x).Finite := by - constructor - · intro hf - apply Set.Finite.of_finite_image (f := (Sum.inl : V → V ⊕ E)) - · apply hf.subset - rintro z ⟨y,hy,rfl⟩ - exact (conn_subdivision_iff G ν x y).mpr hy - · exact Sum.inl_injective.injOn - · intro hf - have he : (⋃ y ∈ cluster G (seriesOpen ν) x, {e | y ∈ G e}).Finite := - hf.biUnion (fun y _ => hloc y) - apply ((hf.image (Sum.inl : V → V ⊕ E)).union - (he.image (Sum.inr : E → V ⊕ E))).subset - intro z hz - cases z with - | inl y => exact Or.inl ⟨y,(conn_subdivision_iff G ν x y).mp hz,rfl⟩ - | inr e => - obtain ⟨y,hxy,hy⟩ := conn_subdivision_inr G ν x e hz - exact Or.inr ⟨e,Set.mem_iUnion.mpr ⟨y,Set.mem_iUnion.mpr ⟨hxy,hy⟩⟩,rfl⟩ - - - -theorem exists_infinite_cluster_subdivision_iff (G : BondGraph V E) - (hloc : LocallyFinite G) (ν : Set (E × Bool)) : - (∃ z, (cluster (subdivision G) (subdivisionOpen G ν) z).Infinite) ↔ - ∃ x, (cluster G (seriesOpen ν) x).Infinite := by - have hi (x : V) : (cluster (subdivision G) (subdivisionOpen G ν) (.inl x)).Infinite ↔ - (cluster G (seriesOpen ν) x).Infinite := by - exact not_congr (finite_cluster_subdivision_iff G hloc ν x) - constructor - · rintro ⟨z,hz⟩ - cases z with - | inl x => exact ⟨x,(hi x).mp hz⟩ - | inr e => - obtain ⟨w,hw,hne⟩ := hz.exists_notMem_finset {Sum.inr e} - have hwne : w ≠ Sum.inr e := by simpa using hne - rcases (show Conn (subdivision G) (subdivisionOpen G ν) (.inr e) w from hw).cases_head - with h | ⟨z,hez,hzw⟩ - · exact (hwne h.symm).elim - · cases z with - | inl y => - have hconn : Conn (subdivision G) (subdivisionOpen G ν) (.inr e) (.inl y) := - .single hez - have heq := cluster_eq_of_conn (subdivision G) (subdivisionOpen G ν) hconn - exact ⟨y,(hi y).mp (heq ▸ hz)⟩ - | inr f => - obtain ⟨d,_,hd⟩ := hez - exact (subdivision_adj_inr_inr G e f ⟨d,hd⟩).elim - · rintro ⟨x,hx⟩ - exact ⟨.inl x,(hi x).mpr hx⟩ - -theorem infinite_cluster_probability_subdivision [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) : - law q {ω | (infiniteClusters (subdivision G) ω).Nonempty} = - law (q^2) {ω | (infiniteClusters G ω).Nonempty} := by - simp only [infiniteClusters_nonempty_iff] - rw [←law_map_subdivisionOpen G q,Measure.map_apply (measurable_subdivisionOpen G) - (measurableSet_exists_infinite_cluster _)] - rw [←law_map_seriesOpen q,Measure.map_apply measurable_seriesOpen - (measurableSet_exists_infinite_cluster _)] - congr 1 - ext ν - exact exists_infinite_cluster_subdivision_iff G hloc ν - - -noncomputable def squareParameter : unitInterval ≃o unitInterval where - toFun q := q^2 - invFun p := ⟨Real.sqrt p,Real.sqrt_nonneg _,Real.sqrt_le_one.mpr p.2.2⟩ - left_inv q := by - apply Subtype.ext - change Real.sqrt ((q:ℝ)^2) = (q:ℝ) - exact Real.sqrt_sq q.2.1 - right_inv p := by - apply Subtype.ext - change Real.sqrt (p:ℝ)^2 = (p:ℝ) - exact Real.sq_sqrt p.2.1 - map_rel_iff' := by - intro p q - change (p:ℝ)^2 ≤ (q:ℝ)^2 ↔ (p:ℝ) ≤ (q:ℝ) - exact sq_le_sq₀ p.2.1 q.2.1 - - - -theorem pc_subdivision_sq [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) : - pc (subdivision G)^2 = pc G := by - change squareParameter (sInf {q | 0 < law q {ω | (infiniteClusters (subdivision G) ω).Nonempty}}) = _ - rw [squareParameter.map_sInf] - change (⨅ q, ⨅ (_ : 0 < law q {ω | (infiniteClusters (subdivision G) ω).Nonempty}), q^2) = _ - simp only [infinite_cluster_probability_subdivision G hloc] - change (⨅ q, ⨅ (_ : 0 < law (squareParameter q) {ω | (infiniteClusters G ω).Nonempty}), - squareParameter q) = _ - simpa only [pc,sInf_eq_iInf,Set.mem_ofPred_eq] using squareParameter.surjective.iInf_comp - (g := fun p => ⨅ (_ : 0 < law p {ω | (infiniteClusters G ω).Nonempty}), p) - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Subdivision.Graph + +namespace OAI + +/-! Coupling percolation on a graph with percolation on its subdivision. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + + + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory ProbabilityTheory +open scoped ENNReal + +noncomputable def halfBit (G : BondGraph V E) : SubdivisionEdge G ↪ E × Bool := by + classical + refine ⟨fun ev => (ev.val.1,if ev.val.2 = (G ev.val.1).out.1 then false else true),?_⟩ + rintro ⟨⟨e,x⟩,hx⟩ ⟨⟨f,y⟩,hy⟩ h + have hef : e = f := congrArg Prod.fst h + subst f + have hb := congrArg Prod.snd h + dsimp only at hb + have he : G e = s((G e).out.1,(G e).out.2) := (G e).out_eq.symm + have hx' : x = (G e).out.1 ∨ x = (G e).out.2 := by + apply Sym2.mem_iff.mp + rw [←he] + exact hx + have hy' : y = (G e).out.1 ∨ y = (G e).out.2 := by + apply Sym2.mem_iff.mp + rw [←he] + exact hy + have hxy : x = y := by + by_cases h₁ : x = (G e).out.1 <;> by_cases h₂ : y = (G e).out.1 + · exact h₁.trans h₂.symm + · simp only [ite_eq_left h₁,ite_eq_right h₂,Bool.false_eq_true] at hb + · simp only [ite_eq_right h₁,ite_eq_left h₂,Bool.true_eq_false] at hb + · exact (hx'.resolve_left h₁).trans (hy'.resolve_left h₂).symm + subst y + rfl + +def seriesOpen (ν : Set (E × Bool)) : Set E := {e | ∀ b, (e,b) ∈ ν} + +noncomputable def subdivisionOpen (G : BondGraph V E) (ν : Set (E × Bool)) : + Set (SubdivisionEdge G) := halfBit G ⁻¹' ν + +@[simp] theorem halfBit_fst (G : BondGraph V E) (e : SubdivisionEdge G) : + (halfBit G e).1 = e.val.1 := rfl + + +theorem seriesOpen_of_two_incident (G : BondGraph V E) (ν : Set (E × Bool)) + (e : E) (x y : V) (hx : x ∈ G e) (hy : y ∈ G e) (hne : x ≠ y) + (hxo : (⟨(e,x),hx⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν) + (hyo : (⟨(e,y),hy⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν) : + e ∈ seriesOpen ν := by + have hbits : (halfBit G ⟨(e,x),hx⟩).2 ≠ (halfBit G ⟨(e,y),hy⟩).2 := by + intro h + have hh : halfBit G ⟨(e,x),hx⟩ = halfBit G ⟨(e,y),hy⟩ := Prod.ext rfl h + have he := (halfBit G).injective hh + exact hne (congrArg (fun z : SubdivisionEdge G => z.val.2) he) + intro b + have hb : b = (halfBit G ⟨(e,x),hx⟩).2 ∨ b = (halfBit G ⟨(e,y),hy⟩).2 := by + generalize (halfBit G ⟨(e,x),hx⟩).2 = c at * + generalize (halfBit G ⟨(e,y),hy⟩).2 = d at * + cases b <;> cases c <;> cases d <;> simp_all + rcases hb with rfl | rfl + · exact hxo + · exact hyo + + +theorem subdivision_open_adj_iff (G : BondGraph V E) (ν : Set (E × Bool)) (x : V) (e : E) : + (∃ d ∈ subdivisionOpen G ν, subdivision G d = s(Sum.inl x, Sum.inr e)) ↔ + ∃ hx : x ∈ G e, (⟨(e,x),hx⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := by + constructor + · rintro ⟨⟨⟨f,y⟩,hy⟩,ho,he⟩ + simp only [subdivision,Sym2.eq_iff] at he + rcases he with ⟨hyx,hfe⟩ | ⟨hbad,_⟩ + · have : y = x := Sum.inl.inj hyx + have : f = e := Sum.inr.inj hfe + subst y; subst f + exact ⟨hy,ho⟩ + · cases hbad + · rintro ⟨hx,ho⟩ + exact ⟨⟨(e,x),hx⟩,ho,rfl⟩ + + +theorem conn_subdivision_iff (G : BondGraph V E) (ν : Set (E × Bool)) (x y : V) : + Conn (subdivision G) (subdivisionOpen G ν) (.inl x) (.inl y) ↔ + Conn G (seriesOpen ν) x y := by + constructor + · intro hc + have reach (z : V ⊕ E) (h : Conn (subdivision G) (subdivisionOpen G ν) (.inl x) z) : + match z with + | .inl w => Conn G (seriesOpen ν) x w + | .inr e => ∃ w : V, ∃ hw : w ∈ G e, + (⟨(e,w),hw⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν ∧ Conn G (seriesOpen ν) x w := by + induction h with + | refl => exact conn_refl G _ x + | @tail u v huv hed ih => + cases u with + | inl a => + cases v with + | inl b => + obtain ⟨d,_,he⟩ := hed + exact (subdivision_adj_inl_inl G a b ⟨d,he⟩).elim + | inr e => + obtain ⟨ha,ho⟩ := (subdivision_open_adj_iff G ν a e).mp hed + exact ⟨a,ha,ho,ih⟩ + | inr e => + cases v with + | inl b => + have hed' : ∃ d ∈ subdivisionOpen G ν, subdivision G d = s(Sum.inl b, Sum.inr e) := by + obtain ⟨d,hd,he⟩ := hed + exact ⟨d,hd,he.trans (Sym2.eq_swap)⟩ + obtain ⟨hb,hbo⟩ := (subdivision_open_adj_iff G ν b e).mp hed' + obtain ⟨a,ha,hao,hxa⟩ := ih + by_cases hab : a = b + · simpa only [hab] using hxa + · exact hxa.tail ⟨e,seriesOpen_of_two_incident G ν e a b ha hb hab hao hbo, + (Sym2.mem_and_mem_iff hab).mp ⟨ha,hb⟩⟩ + | inr f => + obtain ⟨d,_,he⟩ := hed + exact (subdivision_adj_inr_inr G e f ⟨d,he⟩).elim + exact reach (.inl y) hc + · intro hc + induction hc with + | refl => exact conn_refl _ _ _ + | @tail a b hab hed ih => + obtain ⟨e,he,heq⟩ := hed + have ha : a ∈ G e := by simp [heq] + have hb : b ∈ G e := by simp [heq] + have hao : (⟨(e,a),ha⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := he _ + have hbo : (⟨(e,b),hb⟩ : SubdivisionEdge G) ∈ subdivisionOpen G ν := he _ + exact (ih.tail ⟨⟨(e,a),ha⟩,hao,rfl⟩).tail ⟨⟨(e,b),hb⟩,hbo,Sym2.eq_swap⟩ + + +theorem map_bool_and (q : unitInterval) : + (Measure.infinitePi (fun _ : Bool => bitLaw q)).map + (fun f : Bool → Prop => ∀ b, f b) = bitLaw (q^2) := by + let μ := (Measure.infinitePi (fun _ : Bool => bitLaw q)).map + (fun f : Bool → Prop => ∀ b, f b) + have hm : Measurable (fun f : Bool → Prop => ∀ b, f b) := .of_discrete + have : IsProbabilityMeasure μ := inferInstance + have ht : μ.real {True} = (q:ℝ)^2 := by + change ((Measure.infinitePi _).map _).real _ = _ + rw [Measure.real,Measure.map_apply hm (measurableSet_singleton _)] + have he : (fun f : Bool → Prop => ∀ b, f b) ⁻¹' ({True} : Set Prop) = + ((Finset.univ : Finset Bool) : Set Bool).pi (fun _ => ({True} : Set Prop)) := by + ext f + simp [and_comm] + rw [he,Measure.infinitePi_pi _ (fun _ _ => measurableSet_singleton _)] + simp [bitLaw,ENNReal.toReal_mul,pow_two] + have hf : μ.real {False} = 1-(q:ℝ)^2 := by + have he : ({False} : Set Prop) = ({True} : Set Prop)ᶜ := by ext b; simp + rw [he,measureReal_compl (measurableSet_singleton _),probReal_univ,ht] + apply Measure.ext_of_singleton + intro b + apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp + change μ.real {b} = (bitLaw (q^2)).real {b} + by_cases hb : b + · have he : b = True := propext (iff_true_intro hb) + subst b + rw [ht] + simp [bitLaw,Measure.real] + · have he : b = False := propext (iff_false_intro hb) + subst b + rw [hf] + simp [bitLaw,Measure.real] + +theorem measurable_seriesOpen : Measurable (seriesOpen : Set (E × Bool) → Set E) := by + apply measurable_setOfPred.comp + apply Measurable.of_eval + intro e + apply measurableSet_setOfPred.mp + have he : {ν : Set (E × Bool) | ∀ b, (e,b) ∈ ν} = ⋂ b : Bool, {ν | (e,b) ∈ ν} := by + ext ν; simp + rw [he] + exact MeasurableSet.iInter fun b => measurableSet_setOfPred.mpr + ((measurable_pi_apply (e,b)).comp MeasurableEquiv.setOfPred.symm.measurable) + + +theorem law_map_seriesOpen (q : unitInterval) : + (law q : Measure (Set (E × Bool))).map seriesOpen = law (q^2) := by + let c := MeasurableEquiv.curry E Bool Prop + let b := fun f : E → Bool → Prop => fun e => ∀ j, f e j + have hb : Measurable b := Measurable.of_eval + (fun e => (Measurable.of_discrete : Measurable (fun f : Bool → Prop => ∀ j, f j)).comp + (measurable_pi_apply e)) + unfold law + rw [setBernoulli_eq_map,Measure.map_map measurable_seriesOpen measurable_setOfPred] + simp only [Set.mem_univ] + have he : seriesOpen ∘ (fun f : E × Bool → Prop => {e | f e}) = + (fun f : E → Prop => {e | f e}) ∘ b ∘ c := rfl + rw [he,←Measure.map_map measurable_setOfPred (hb.comp c.measurable), + ←Measure.map_map hb c.measurable] + change ((Measure.infinitePi (fun _ : E × Bool => bitLaw q)).map c |>.map b |>.map + (fun f : E → Prop => {e | f e})) = _ + rw [Measure.infinitePi_map_curry (fun (_ : E) (_ : Bool) => bitLaw q)] + dsimp only [b] + rw [Measure.infinitePi_map_pi _ (f := fun _ (g : Bool → Prop) => ∀ j, g j) + (fun _ => Measurable.of_discrete)] + rw [map_bool_and q,setBernoulli_eq_map] + rfl + +theorem measurable_subdivisionOpen (G : BondGraph V E) : Measurable (subdivisionOpen G) := + measurable_setOfPred.comp (Measurable.of_eval (fun e => + (measurable_pi_apply (halfBit G e)).comp MeasurableEquiv.setOfPred.symm.measurable)) + +theorem law_map_subdivisionOpen (G : BondGraph V E) (q : unitInterval) : + (law q : Measure (Set (E × Bool))).map (subdivisionOpen G) = law q := + law_map_preimage_embedding q (halfBit G) + + + +theorem twoPoint_subdivision [Countable V] [Countable E] + (G : BondGraph V E) (q : unitInterval) (x y : V) : + twoPoint (subdivision G) q (.inl x) (.inl y) = twoPoint G (q^2) x y := by + unfold twoPoint + congr 1 + rw [←law_map_subdivisionOpen G q,Measure.map_apply (measurable_subdivisionOpen G) + (measurableSet_conn (subdivision G) (.inl x) (.inl y))] + rw [←law_map_seriesOpen q,Measure.map_apply measurable_seriesOpen (measurableSet_conn G x y)] + congr 1 + ext ν + exact conn_subdivision_iff G ν x y + + +theorem conn_subdivision_inr (G : BondGraph V E) (ν : Set (E × Bool)) (x : V) (e : E) + (hc : Conn (subdivision G) (subdivisionOpen G ν) (.inl x) (.inr e)) : + ∃ y, Conn G (seriesOpen ν) x y ∧ y ∈ G e := by + rcases hc.cases_tail with h | ⟨z,hxz,hze⟩ + · cases h + · cases z with + | inl y => + obtain ⟨hy,_⟩ := (subdivision_open_adj_iff G ν y e).mp hze + exact ⟨y,(conn_subdivision_iff G ν x y).mp hxz,hy⟩ + | inr f => + obtain ⟨d,_,hd⟩ := hze + exact (subdivision_adj_inr_inr G f e ⟨d,hd⟩).elim + + + +theorem finite_cluster_subdivision_iff (G : BondGraph V E) (hloc : LocallyFinite G) + (ν : Set (E × Bool)) (x : V) : + (cluster (subdivision G) (subdivisionOpen G ν) (.inl x)).Finite ↔ + (cluster G (seriesOpen ν) x).Finite := by + constructor + · intro hf + apply Set.Finite.of_finite_image (f := (Sum.inl : V → V ⊕ E)) + · apply hf.subset + rintro z ⟨y,hy,rfl⟩ + exact (conn_subdivision_iff G ν x y).mpr hy + · exact Sum.inl_injective.injOn + · intro hf + have he : (⋃ y ∈ cluster G (seriesOpen ν) x, {e | y ∈ G e}).Finite := + hf.biUnion (fun y _ => hloc y) + apply ((hf.image (Sum.inl : V → V ⊕ E)).union + (he.image (Sum.inr : E → V ⊕ E))).subset + intro z hz + cases z with + | inl y => exact Or.inl ⟨y,(conn_subdivision_iff G ν x y).mp hz,rfl⟩ + | inr e => + obtain ⟨y,hxy,hy⟩ := conn_subdivision_inr G ν x e hz + exact Or.inr ⟨e,Set.mem_iUnion.mpr ⟨y,Set.mem_iUnion.mpr ⟨hxy,hy⟩⟩,rfl⟩ + + + +theorem exists_infinite_cluster_subdivision_iff (G : BondGraph V E) + (hloc : LocallyFinite G) (ν : Set (E × Bool)) : + (∃ z, (cluster (subdivision G) (subdivisionOpen G ν) z).Infinite) ↔ + ∃ x, (cluster G (seriesOpen ν) x).Infinite := by + have hi (x : V) : (cluster (subdivision G) (subdivisionOpen G ν) (.inl x)).Infinite ↔ + (cluster G (seriesOpen ν) x).Infinite := by + exact not_congr (finite_cluster_subdivision_iff G hloc ν x) + constructor + · rintro ⟨z,hz⟩ + cases z with + | inl x => exact ⟨x,(hi x).mp hz⟩ + | inr e => + obtain ⟨w,hw,hne⟩ := hz.exists_notMem_finset {Sum.inr e} + have hwne : w ≠ Sum.inr e := by simpa using hne + rcases (show Conn (subdivision G) (subdivisionOpen G ν) (.inr e) w from hw).cases_head + with h | ⟨z,hez,hzw⟩ + · exact (hwne h.symm).elim + · cases z with + | inl y => + have hconn : Conn (subdivision G) (subdivisionOpen G ν) (.inr e) (.inl y) := + .single hez + have heq := cluster_eq_of_conn (subdivision G) (subdivisionOpen G ν) hconn + exact ⟨y,(hi y).mp (heq ▸ hz)⟩ + | inr f => + obtain ⟨d,_,hd⟩ := hez + exact (subdivision_adj_inr_inr G e f ⟨d,hd⟩).elim + · rintro ⟨x,hx⟩ + exact ⟨.inl x,(hi x).mpr hx⟩ + +theorem infinite_cluster_probability_subdivision [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (q : unitInterval) : + law q {ω | (infiniteClusters (subdivision G) ω).Nonempty} = + law (q^2) {ω | (infiniteClusters G ω).Nonempty} := by + simp only [infiniteClusters_nonempty_iff] + rw [←law_map_subdivisionOpen G q,Measure.map_apply (measurable_subdivisionOpen G) + (measurableSet_exists_infinite_cluster _)] + rw [←law_map_seriesOpen q,Measure.map_apply measurable_seriesOpen + (measurableSet_exists_infinite_cluster _)] + congr 1 + ext ν + exact exists_infinite_cluster_subdivision_iff G hloc ν + + +noncomputable def squareParameter : unitInterval ≃o unitInterval where + toFun q := q^2 + invFun p := ⟨Real.sqrt p,Real.sqrt_nonneg _,Real.sqrt_le_one.mpr p.2.2⟩ + left_inv q := by + apply Subtype.ext + change Real.sqrt ((q:ℝ)^2) = (q:ℝ) + exact Real.sqrt_sq q.2.1 + right_inv p := by + apply Subtype.ext + change Real.sqrt (p:ℝ)^2 = (p:ℝ) + exact Real.sq_sqrt p.2.1 + map_rel_iff' := by + intro p q + change (p:ℝ)^2 ≤ (q:ℝ)^2 ↔ (p:ℝ) ≤ (q:ℝ) + exact sq_le_sq₀ p.2.1 q.2.1 + + + +theorem pc_subdivision_sq [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) : + pc (subdivision G)^2 = pc G := by + change squareParameter (sInf {q | 0 < law q {ω | (infiniteClusters (subdivision G) ω).Nonempty}}) = _ + rw [squareParameter.map_sInf] + change (⨅ q, ⨅ (_ : 0 < law q {ω | (infiniteClusters (subdivision G) ω).Nonempty}), q^2) = _ + simp only [infinite_cluster_probability_subdivision G hloc] + change (⨅ q, ⨅ (_ : 0 < law (squareParameter q) {ω | (infiniteClusters G ω).Nonempty}), + squareParameter q) = _ + simpa only [pc,sInf_eq_iInf,Set.mem_ofPred_eq] using squareParameter.surjective.iInf_comp + (g := fun p => ⨅ (_ : 0 < law p {ω | (infiniteClusters G ω).Nonempty}), p) + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Graph.lean b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Graph.lean index 07865eca6891c32fe58837869fa9a72ef347f95c..4156665e13a3a1f938bbe4dc77677e9bcc26c75e 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Graph.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Graph.lean @@ -1,284 +1,284 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts - -namespace OAI - -/-! Subdivision of indexed bond graphs and its basic geometry. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - - - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory - -abbrev SubdivisionEdge (G : BondGraph V E) := {ev : E × V // ev.2 ∈ G ev.1} - -def subdivision (G : BondGraph V E) : BondGraph (V ⊕ E) (SubdivisionEdge G) := - fun ev => s(Sum.inl ev.val.2, Sum.inr ev.val.1) - -theorem subdivision_injective (G : BondGraph V E) : Function.Injective (subdivision G) := by - intro ⟨⟨e,x⟩,hx⟩ ⟨⟨f,y⟩,hy⟩ h - simp only [subdivision,Sym2.eq_iff] at h - rcases h with ⟨hxy,hef⟩ | ⟨hbad,_⟩ - · have h₁ : x = y := Sum.inl.inj hxy - have h₂ : e = f := Sum.inr.inj hef - subst y; subst f; rfl - · cases hbad - -@[simp] theorem subdivision_adj_inl_inr (G : BondGraph V E) (x : V) (e : E) : - Adj (subdivision G) (.inl x) (.inr e) ↔ x ∈ G e := by - constructor - · rintro ⟨⟨⟨f,y⟩,hy⟩,h⟩ - simp only [subdivision,Sym2.eq_iff] at h - rcases h with ⟨hyx,hfe⟩ | ⟨hbad,_⟩ - · have : y = x := Sum.inl.inj hyx - have : f = e := Sum.inr.inj hfe - subst y; subst f; exact hy - · cases hbad - · intro hx - exact ⟨⟨(e,x),hx⟩,rfl⟩ - -@[simp] theorem subdivision_adj_inl_inl (G : BondGraph V E) (x y : V) : - ¬ Adj (subdivision G) (.inl x) (.inl y) := by - rintro ⟨⟨⟨e,z⟩,hz⟩,h⟩ - simp [subdivision] at h - -@[simp] theorem subdivision_adj_inr_inr (G : BondGraph V E) (e f : E) : - ¬ Adj (subdivision G) (.inr e) (.inr f) := by - rintro ⟨⟨⟨d,z⟩,hz⟩,h⟩ - simp [subdivision] at h - -@[simp] theorem subdivision_adj_inr_inl (G : BondGraph V E) (e : E) (x : V) : - Adj (subdivision G) (.inr e) (.inl x) ↔ x ∈ G e := by - exact ⟨fun h => (subdivision_adj_inl_inr G x e).mp (adj_symm _ h), - fun h => adj_symm _ ((subdivision_adj_inl_inr G x e).mpr h)⟩ - -theorem subdivision_loopless (G : BondGraph V E) (x : V ⊕ E) : - ¬ Adj (subdivision G) x x := by cases x <;> simp - -theorem subdivision_locallyFinite (G : BondGraph V E) (hloc : LocallyFinite G) : - LocallyFinite (subdivision G) := by - classical - intro z - cases z with - | inl x => - apply Set.Finite.of_finite_image (f := fun e : SubdivisionEdge G => e.val.1) - · apply (hloc x).subset - rintro e ⟨⟨⟨f,y⟩,hy⟩,hz,rfl⟩ - have he : x = y := by simpa [subdivision] using hz - simpa [he] using hy - · intro e he f hf hef - apply Subtype.ext - apply Prod.ext hef - have hx : x = e.val.2 := by simpa [subdivision] using he - have hy : x = f.val.2 := by simpa [subdivision] using hf - exact hx.symm.trans hy - | inr e => - apply Set.Finite.of_finite_image (f := fun f : SubdivisionEdge G => f.val.2) - · apply (Sym2.toFinset (G e)).finite_toSet.subset - rintro x ⟨⟨⟨f,y⟩,hy⟩,hz,rfl⟩ - have he : e = f := by simpa [subdivision] using hz - simpa [he] using hy - · intro f hf g hg hfg - apply Subtype.ext - apply Prod.ext _ hfg - have h₁ : e = f.val.1 := by simpa [subdivision] using hf - have h₂ : e = g.val.1 := by simpa [subdivision] using hg - exact h₁.symm.trans h₂ - -theorem subdivision_connected (G : BondGraph V E) (hconn : Connected G) : - Connected (subdivision G) := by - have hold (x y : V) : Relation.ReflTransGen (Adj (subdivision G)) (.inl x) (.inl y) := by - induction hconn x y with - | refl => exact .refl - | @tail y z hxy hyz ih => - obtain ⟨e,he⟩ := hyz - exact (ih.tail ((subdivision_adj_inl_inr G y e).mpr (by simp [he]))).tail - ((subdivision_adj_inr_inl G e z).mpr (by simp [he])) - have attach (z : V ⊕ E) : ∃ x : V, Relation.ReflTransGen (Adj (subdivision G)) z (.inl x) := by - cases z with - | inl x => exact ⟨x,.refl⟩ - | inr e => - exact ⟨(G e).out.1,Relation.ReflTransGen.single - ((subdivision_adj_inr_inl G e _).mpr (G e).out_fst_mem)⟩ - have rev {a b : V ⊕ E} (h : Relation.ReflTransGen (Adj (subdivision G)) a b) : - Relation.ReflTransGen (Adj (subdivision G)) b a := by - induction h with - | refl => exact .refl - | tail _ hab ih => exact (Relation.ReflTransGen.single (adj_symm _ hab)).trans ih - intro z w - obtain ⟨x,hx⟩ := attach z - obtain ⟨y,hy⟩ := attach w - exact hx.trans ((hold x y).trans (rev hy)) - - -theorem incidence_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (e : E) (x : V) : a x ∈ G (b e) ↔ x ∈ G e := by - rw [hab e] - simp only [Sym2.mem_map,a.injective.eq_iff,exists_eq_right] - - -noncomputable def subdivisionAutEdges (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) : SubdivisionEdge G ≃ SubdivisionEdge G := - (b.prodCongr a).subtypeEquiv (fun p => (incidence_aut_iff G hab p.1 p.2).symm) - -theorem subdivision_isAut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) : - IsAut (subdivision G) (a.sumCongr b) (subdivisionAutEdges G hab) := by - intro e - rfl - - - -theorem finite_edge_roots (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) : - ∃ R : Finset E, ∀ e, ∃ f ∈ R, ∃ a : V ≃ V, ∃ b : E ≃ E, - IsAut G a b ∧ b f = e := by - classical - obtain ⟨S,hS⟩ := hqt - let R := S.biUnion (fun x => (hloc x).toFinset) - refine ⟨R,fun e => ?_⟩ - obtain ⟨x,hx,a,b,hab,hax⟩ := hS (G e).out.1 - refine ⟨b.symm e,Finset.mem_biUnion.mpr ⟨x,hx,?_⟩,a,b,hab,b.apply_symm_apply e⟩ - apply (hloc x).mem_toFinset.mpr - apply (incidence_aut_iff G hab _ _).mp - simpa only [Equiv.apply_symm_apply,hax] using (G e).out_fst_mem - -theorem subdivision_quasiTransitive (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) : QuasiTransitive (subdivision G) := by - classical - obtain ⟨S,hS⟩ := hqt - obtain ⟨R,hR⟩ := finite_edge_roots G hloc ⟨S,hS⟩ - refine ⟨S.image Sum.inl ∪ R.image Sum.inr,?_⟩ - intro z - cases z with - | inl x => - obtain ⟨o,ho,a,b,hab,hax⟩ := hS x - refine ⟨.inl o,Finset.mem_union_left _ (Finset.mem_image.mpr ⟨o,ho,rfl⟩), - a.sumCongr b,subdivisionAutEdges G hab,subdivision_isAut G hab,?_⟩ - exact congrArg Sum.inl hax - | inr e => - obtain ⟨f,hf,a,b,hab,hbe⟩ := hR e - refine ⟨.inr f,Finset.mem_union_right _ (Finset.mem_image.mpr ⟨f,hf,rfl⟩), - a.sumCongr b,subdivisionAutEdges G hab,subdivision_isAut G hab,?_⟩ - exact congrArg Sum.inr hbe - - - -theorem subdivision_old_boundary_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (A : Finset (V ⊕ E)) : - hV G * (A.toLeft.card : ℝ) ≤ - 2 * ((vertexBoundary (subdivision G) A).ncard : ℝ) := by - classical - let B := (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).toFinset - let C := (finite_vertexBoundary G hloc A.toLeft).toFinset - have hsub : C ⊆ B.toLeft ∪ B.toRight.biUnion (fun e => (G e).toFinset) := by - intro y hy - obtain ⟨hy,x,hx,e,he⟩ := (finite_vertexBoundary G hloc A.toLeft).mem_toFinset.mp hy - by_cases heA : Sum.inr e ∈ A - · apply Finset.mem_union_left - apply Finset.mem_toLeft.mpr - apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr - exact ⟨fun h => hy (Finset.mem_toLeft.mpr h),.inr e,heA, - (subdivision_adj_inr_inl G e y).mpr (by simp [he])⟩ - · apply Finset.mem_union_right - apply Finset.mem_biUnion.mpr - refine ⟨e,?_,Sym2.mem_toFinset.mpr (by simp [he])⟩ - apply Finset.mem_toRight.mpr - apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr - exact ⟨heA,.inl x,Finset.mem_toLeft.mp hx, - (subdivision_adj_inl_inr G x e).mpr (by simp [he])⟩ - have hcard : C.card ≤ B.toLeft.card + 2*B.toRight.card := by - calc - C.card ≤ (B.toLeft ∪ B.toRight.biUnion (fun e => (G e).toFinset)).card := Finset.card_le_card hsub - _ ≤ B.toLeft.card + (B.toRight.biUnion (fun e => (G e).toFinset)).card := Finset.card_union_le _ _ - _ ≤ B.toLeft.card + ∑ e ∈ B.toRight, (G e).toFinset.card := - Nat.add_le_add_left (Finset.card_biUnion_le) _ - _ ≤ B.toLeft.card + ∑ _e ∈ B.toRight, 2 := by - apply Nat.add_le_add_left - apply Finset.sum_le_sum - intro e _ - rw [Sym2.card_toFinset] - split_ifs <;> omega - _ = _ := by simp [Nat.mul_comm] - have hcard' : C.card ≤ 2*B.card := by - have hsum := B.card_toLeft_add_card_toRight - omega - have hh := hV_mul_card_le G A.toLeft - have hc : C.card = (vertexBoundary G A.toLeft).ncard := (Set.ncard_eq_toFinset_card _ _).symm - have hb : B.card = (vertexBoundary (subdivision G) A).ncard := (Set.ncard_eq_toFinset_card _ _).symm - rw [←hc] at hh - exact hh.trans (by exact_mod_cast (hcard'.trans_eq (by rw [hb]))) - - - -theorem subdivision_new_card_bound (G : BondGraph V E) (hloc : LocallyFinite G) - (d : ℕ) (hd : ∀ x, degree G x ≤ d) (A : Finset (V ⊕ E)) : - A.toRight.card ≤ d*(A.toLeft.card + (vertexBoundary (subdivision G) A).ncard) := by - classical - let B := (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).toFinset - let C := A.toLeft ∪ B.toLeft - have hsub : A.toRight ⊆ C.biUnion (fun x => (hloc x).toFinset) := by - intro e he - let x := (G e).out.1 - have hx : x ∈ G e := (G e).out_fst_mem - refine Finset.mem_biUnion.mpr ⟨x,?_,(hloc x).mem_toFinset.mpr hx⟩ - by_cases hxA : x ∈ A.toLeft - · exact Finset.mem_union_left _ hxA - · apply Finset.mem_union_right - apply Finset.mem_toLeft.mpr - apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr - exact ⟨fun h => hxA (Finset.mem_toLeft.mpr h),.inr e,Finset.mem_toRight.mp he, - (subdivision_adj_inr_inl G e x).mpr hx⟩ - have hc : C.card ≤ A.toLeft.card+B.card := - (Finset.card_union_le _ _).trans (Nat.add_le_add_left B.card_toLeft_le _) - have hb : B.card = (vertexBoundary (subdivision G) A).ncard := (Set.ncard_eq_toFinset_card _ _).symm - calc - A.toRight.card ≤ (C.biUnion (fun x => (hloc x).toFinset)).card := Finset.card_le_card hsub - _ ≤ ∑ x ∈ C, (hloc x).toFinset.card := Finset.card_biUnion_le - _ ≤ ∑ _x ∈ C, d := by - apply Finset.sum_le_sum - intro x _ - rw [←Set.ncard_eq_toFinset_card _ (hloc x)] - exact (incident_ncard_le_degree G hloc x).trans (hd x) - _ = d*C.card := by simp [Nat.mul_comm] - _ ≤ d*(A.toLeft.card+B.card) := Nat.mul_le_mul_left d hc - _ = _ := by rw [hb] - - - -theorem subdivision_hV_pos [Nonempty V] (G : BondGraph V E) (hloc : LocallyFinite G) - (hqt : QuasiTransitive G) (hh : 0 < hV G) : 0 < hV (subdivision G) := by - classical - obtain ⟨d,hd,hdg⟩ := exists_degree_bound G hqt - let c := hV G / (2*((d:ℝ)+1)+(d:ℝ)*hV G) - have hden : 0 < 2*((d:ℝ)+1)+(d:ℝ)*hV G := by positivity - have hc : 0 < c := div_pos hh hden - apply hc.trans_le - apply le_csInf - · exact ⟨_,{Sum.inl (Classical.arbitrary V)},Finset.singleton_nonempty _,rfl⟩ - · rintro r ⟨A,hA,rfl⟩ - have ho := subdivision_old_boundary_bound G hloc A - have hn : (A.toRight.card:ℝ) ≤ (d:ℝ)*((A.toLeft.card:ℝ)+ - ((vertexBoundary (subdivision G) A).ncard:ℝ)) := by - exact_mod_cast subdivision_new_card_bound G hloc d hdg A - have hs : (A.toLeft.card:ℝ)+(A.toRight.card:ℝ) = A.card := by - exact_mod_cast A.card_toLeft_add_card_toRight - have hcard : (0:ℝ) < A.card := Nat.cast_pos.mpr hA.card_pos - apply (le_div_iff₀ hcard).mpr - dsimp only [c] - rw [div_mul_eq_mul_div] - apply (div_le_iff₀ hden).mpr - have h₁ := mul_le_mul_of_nonneg_left ho (show 0 ≤ (d:ℝ)+1 by positivity) - have h₂ := mul_le_mul_of_nonneg_left hn hh.le - rw [←hs] - nlinarith only [h₁,h₂] - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts + +namespace OAI + +/-! Subdivision of indexed bond graphs and its basic geometry. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + + + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory + +abbrev SubdivisionEdge (G : BondGraph V E) := {ev : E × V // ev.2 ∈ G ev.1} + +def subdivision (G : BondGraph V E) : BondGraph (V ⊕ E) (SubdivisionEdge G) := + fun ev => s(Sum.inl ev.val.2, Sum.inr ev.val.1) + +theorem subdivision_injective (G : BondGraph V E) : Function.Injective (subdivision G) := by + intro ⟨⟨e,x⟩,hx⟩ ⟨⟨f,y⟩,hy⟩ h + simp only [subdivision,Sym2.eq_iff] at h + rcases h with ⟨hxy,hef⟩ | ⟨hbad,_⟩ + · have h₁ : x = y := Sum.inl.inj hxy + have h₂ : e = f := Sum.inr.inj hef + subst y; subst f; rfl + · cases hbad + +@[simp] theorem subdivision_adj_inl_inr (G : BondGraph V E) (x : V) (e : E) : + Adj (subdivision G) (.inl x) (.inr e) ↔ x ∈ G e := by + constructor + · rintro ⟨⟨⟨f,y⟩,hy⟩,h⟩ + simp only [subdivision,Sym2.eq_iff] at h + rcases h with ⟨hyx,hfe⟩ | ⟨hbad,_⟩ + · have : y = x := Sum.inl.inj hyx + have : f = e := Sum.inr.inj hfe + subst y; subst f; exact hy + · cases hbad + · intro hx + exact ⟨⟨(e,x),hx⟩,rfl⟩ + +@[simp] theorem subdivision_adj_inl_inl (G : BondGraph V E) (x y : V) : + ¬ Adj (subdivision G) (.inl x) (.inl y) := by + rintro ⟨⟨⟨e,z⟩,hz⟩,h⟩ + simp [subdivision] at h + +@[simp] theorem subdivision_adj_inr_inr (G : BondGraph V E) (e f : E) : + ¬ Adj (subdivision G) (.inr e) (.inr f) := by + rintro ⟨⟨⟨d,z⟩,hz⟩,h⟩ + simp [subdivision] at h + +@[simp] theorem subdivision_adj_inr_inl (G : BondGraph V E) (e : E) (x : V) : + Adj (subdivision G) (.inr e) (.inl x) ↔ x ∈ G e := by + exact ⟨fun h => (subdivision_adj_inl_inr G x e).mp (adj_symm _ h), + fun h => adj_symm _ ((subdivision_adj_inl_inr G x e).mpr h)⟩ + +theorem subdivision_loopless (G : BondGraph V E) (x : V ⊕ E) : + ¬ Adj (subdivision G) x x := by cases x <;> simp + +theorem subdivision_locallyFinite (G : BondGraph V E) (hloc : LocallyFinite G) : + LocallyFinite (subdivision G) := by + classical + intro z + cases z with + | inl x => + apply Set.Finite.of_finite_image (f := fun e : SubdivisionEdge G => e.val.1) + · apply (hloc x).subset + rintro e ⟨⟨⟨f,y⟩,hy⟩,hz,rfl⟩ + have he : x = y := by simpa [subdivision] using hz + simpa [he] using hy + · intro e he f hf hef + apply Subtype.ext + apply Prod.ext hef + have hx : x = e.val.2 := by simpa [subdivision] using he + have hy : x = f.val.2 := by simpa [subdivision] using hf + exact hx.symm.trans hy + | inr e => + apply Set.Finite.of_finite_image (f := fun f : SubdivisionEdge G => f.val.2) + · apply (Sym2.toFinset (G e)).finite_toSet.subset + rintro x ⟨⟨⟨f,y⟩,hy⟩,hz,rfl⟩ + have he : e = f := by simpa [subdivision] using hz + simpa [he] using hy + · intro f hf g hg hfg + apply Subtype.ext + apply Prod.ext _ hfg + have h₁ : e = f.val.1 := by simpa [subdivision] using hf + have h₂ : e = g.val.1 := by simpa [subdivision] using hg + exact h₁.symm.trans h₂ + +theorem subdivision_connected (G : BondGraph V E) (hconn : Connected G) : + Connected (subdivision G) := by + have hold (x y : V) : Relation.ReflTransGen (Adj (subdivision G)) (.inl x) (.inl y) := by + induction hconn x y with + | refl => exact .refl + | @tail y z hxy hyz ih => + obtain ⟨e,he⟩ := hyz + exact (ih.tail ((subdivision_adj_inl_inr G y e).mpr (by simp [he]))).tail + ((subdivision_adj_inr_inl G e z).mpr (by simp [he])) + have attach (z : V ⊕ E) : ∃ x : V, Relation.ReflTransGen (Adj (subdivision G)) z (.inl x) := by + cases z with + | inl x => exact ⟨x,.refl⟩ + | inr e => + exact ⟨(G e).out.1,Relation.ReflTransGen.single + ((subdivision_adj_inr_inl G e _).mpr (G e).out_fst_mem)⟩ + have rev {a b : V ⊕ E} (h : Relation.ReflTransGen (Adj (subdivision G)) a b) : + Relation.ReflTransGen (Adj (subdivision G)) b a := by + induction h with + | refl => exact .refl + | tail _ hab ih => exact (Relation.ReflTransGen.single (adj_symm _ hab)).trans ih + intro z w + obtain ⟨x,hx⟩ := attach z + obtain ⟨y,hy⟩ := attach w + exact hx.trans ((hold x y).trans (rev hy)) + + +theorem incidence_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (e : E) (x : V) : a x ∈ G (b e) ↔ x ∈ G e := by + rw [hab e] + simp only [Sym2.mem_map,a.injective.eq_iff,exists_eq_right] + + +noncomputable def subdivisionAutEdges (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) : SubdivisionEdge G ≃ SubdivisionEdge G := + (b.prodCongr a).subtypeEquiv (fun p => (incidence_aut_iff G hab p.1 p.2).symm) + +theorem subdivision_isAut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) : + IsAut (subdivision G) (a.sumCongr b) (subdivisionAutEdges G hab) := by + intro e + rfl + + + +theorem finite_edge_roots (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) : + ∃ R : Finset E, ∀ e, ∃ f ∈ R, ∃ a : V ≃ V, ∃ b : E ≃ E, + IsAut G a b ∧ b f = e := by + classical + obtain ⟨S,hS⟩ := hqt + let R := S.biUnion (fun x => (hloc x).toFinset) + refine ⟨R,fun e => ?_⟩ + obtain ⟨x,hx,a,b,hab,hax⟩ := hS (G e).out.1 + refine ⟨b.symm e,Finset.mem_biUnion.mpr ⟨x,hx,?_⟩,a,b,hab,b.apply_symm_apply e⟩ + apply (hloc x).mem_toFinset.mpr + apply (incidence_aut_iff G hab _ _).mp + simpa only [Equiv.apply_symm_apply,hax] using (G e).out_fst_mem + +theorem subdivision_quasiTransitive (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) : QuasiTransitive (subdivision G) := by + classical + obtain ⟨S,hS⟩ := hqt + obtain ⟨R,hR⟩ := finite_edge_roots G hloc ⟨S,hS⟩ + refine ⟨S.image Sum.inl ∪ R.image Sum.inr,?_⟩ + intro z + cases z with + | inl x => + obtain ⟨o,ho,a,b,hab,hax⟩ := hS x + refine ⟨.inl o,Finset.mem_union_left _ (Finset.mem_image.mpr ⟨o,ho,rfl⟩), + a.sumCongr b,subdivisionAutEdges G hab,subdivision_isAut G hab,?_⟩ + exact congrArg Sum.inl hax + | inr e => + obtain ⟨f,hf,a,b,hab,hbe⟩ := hR e + refine ⟨.inr f,Finset.mem_union_right _ (Finset.mem_image.mpr ⟨f,hf,rfl⟩), + a.sumCongr b,subdivisionAutEdges G hab,subdivision_isAut G hab,?_⟩ + exact congrArg Sum.inr hbe + + + +theorem subdivision_old_boundary_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (A : Finset (V ⊕ E)) : + hV G * (A.toLeft.card : ℝ) ≤ + 2 * ((vertexBoundary (subdivision G) A).ncard : ℝ) := by + classical + let B := (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).toFinset + let C := (finite_vertexBoundary G hloc A.toLeft).toFinset + have hsub : C ⊆ B.toLeft ∪ B.toRight.biUnion (fun e => (G e).toFinset) := by + intro y hy + obtain ⟨hy,x,hx,e,he⟩ := (finite_vertexBoundary G hloc A.toLeft).mem_toFinset.mp hy + by_cases heA : Sum.inr e ∈ A + · apply Finset.mem_union_left + apply Finset.mem_toLeft.mpr + apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr + exact ⟨fun h => hy (Finset.mem_toLeft.mpr h),.inr e,heA, + (subdivision_adj_inr_inl G e y).mpr (by simp [he])⟩ + · apply Finset.mem_union_right + apply Finset.mem_biUnion.mpr + refine ⟨e,?_,Sym2.mem_toFinset.mpr (by simp [he])⟩ + apply Finset.mem_toRight.mpr + apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr + exact ⟨heA,.inl x,Finset.mem_toLeft.mp hx, + (subdivision_adj_inl_inr G x e).mpr (by simp [he])⟩ + have hcard : C.card ≤ B.toLeft.card + 2*B.toRight.card := by + calc + C.card ≤ (B.toLeft ∪ B.toRight.biUnion (fun e => (G e).toFinset)).card := Finset.card_le_card hsub + _ ≤ B.toLeft.card + (B.toRight.biUnion (fun e => (G e).toFinset)).card := Finset.card_union_le _ _ + _ ≤ B.toLeft.card + ∑ e ∈ B.toRight, (G e).toFinset.card := + Nat.add_le_add_left (Finset.card_biUnion_le) _ + _ ≤ B.toLeft.card + ∑ _e ∈ B.toRight, 2 := by + apply Nat.add_le_add_left + apply Finset.sum_le_sum + intro e _ + rw [Sym2.card_toFinset] + split_ifs <;> omega + _ = _ := by simp [Nat.mul_comm] + have hcard' : C.card ≤ 2*B.card := by + have hsum := B.card_toLeft_add_card_toRight + omega + have hh := hV_mul_card_le G A.toLeft + have hc : C.card = (vertexBoundary G A.toLeft).ncard := (Set.ncard_eq_toFinset_card _ _).symm + have hb : B.card = (vertexBoundary (subdivision G) A).ncard := (Set.ncard_eq_toFinset_card _ _).symm + rw [←hc] at hh + exact hh.trans (by exact_mod_cast (hcard'.trans_eq (by rw [hb]))) + + + +theorem subdivision_new_card_bound (G : BondGraph V E) (hloc : LocallyFinite G) + (d : ℕ) (hd : ∀ x, degree G x ≤ d) (A : Finset (V ⊕ E)) : + A.toRight.card ≤ d*(A.toLeft.card + (vertexBoundary (subdivision G) A).ncard) := by + classical + let B := (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).toFinset + let C := A.toLeft ∪ B.toLeft + have hsub : A.toRight ⊆ C.biUnion (fun x => (hloc x).toFinset) := by + intro e he + let x := (G e).out.1 + have hx : x ∈ G e := (G e).out_fst_mem + refine Finset.mem_biUnion.mpr ⟨x,?_,(hloc x).mem_toFinset.mpr hx⟩ + by_cases hxA : x ∈ A.toLeft + · exact Finset.mem_union_left _ hxA + · apply Finset.mem_union_right + apply Finset.mem_toLeft.mpr + apply (finite_vertexBoundary (subdivision G) (subdivision_locallyFinite G hloc) A).mem_toFinset.mpr + exact ⟨fun h => hxA (Finset.mem_toLeft.mpr h),.inr e,Finset.mem_toRight.mp he, + (subdivision_adj_inr_inl G e x).mpr hx⟩ + have hc : C.card ≤ A.toLeft.card+B.card := + (Finset.card_union_le _ _).trans (Nat.add_le_add_left B.card_toLeft_le _) + have hb : B.card = (vertexBoundary (subdivision G) A).ncard := (Set.ncard_eq_toFinset_card _ _).symm + calc + A.toRight.card ≤ (C.biUnion (fun x => (hloc x).toFinset)).card := Finset.card_le_card hsub + _ ≤ ∑ x ∈ C, (hloc x).toFinset.card := Finset.card_biUnion_le + _ ≤ ∑ _x ∈ C, d := by + apply Finset.sum_le_sum + intro x _ + rw [←Set.ncard_eq_toFinset_card _ (hloc x)] + exact (incident_ncard_le_degree G hloc x).trans (hd x) + _ = d*C.card := by simp [Nat.mul_comm] + _ ≤ d*(A.toLeft.card+B.card) := Nat.mul_le_mul_left d hc + _ = _ := by rw [hb] + + + +theorem subdivision_hV_pos [Nonempty V] (G : BondGraph V E) (hloc : LocallyFinite G) + (hqt : QuasiTransitive G) (hh : 0 < hV G) : 0 < hV (subdivision G) := by + classical + obtain ⟨d,hd,hdg⟩ := exists_degree_bound G hqt + let c := hV G / (2*((d:ℝ)+1)+(d:ℝ)*hV G) + have hden : 0 < 2*((d:ℝ)+1)+(d:ℝ)*hV G := by positivity + have hc : 0 < c := div_pos hh hden + apply hc.trans_le + apply le_csInf + · exact ⟨_,{Sum.inl (Classical.arbitrary V)},Finset.singleton_nonempty _,rfl⟩ + · rintro r ⟨A,hA,rfl⟩ + have ho := subdivision_old_boundary_bound G hloc A + have hn : (A.toRight.card:ℝ) ≤ (d:ℝ)*((A.toLeft.card:ℝ)+ + ((vertexBoundary (subdivision G) A).ncard:ℝ)) := by + exact_mod_cast subdivision_new_card_bound G hloc d hdg A + have hs : (A.toLeft.card:ℝ)+(A.toRight.card:ℝ) = A.card := by + exact_mod_cast A.card_toLeft_add_card_toRight + have hcard : (0:ℝ) < A.card := Nat.cast_pos.mpr hA.card_pos + apply (le_div_iff₀ hcard).mpr + dsimp only [c] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hden).mpr + have h₁ := mul_le_mul_of_nonneg_left ho (show 0 ≤ (d:ℝ)+1 by positivity) + have h₂ := mul_le_mul_of_nonneg_left hn hh.le + rw [←hs] + nlinarith only [h₁,h₂] + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Operator.lean b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Operator.lean index 345380eb45a604cbf47658ec12d8e50ce717df12..45229bb3362607e977b02c331d9814158c53e7a1 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Subdivision/Operator.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Subdivision/Operator.lean @@ -1,115 +1,115 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Subdivision.Coupling - -namespace OAI - -/-! Operator bounds transferred through graph subdivision. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - - - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -open scoped ENNReal - -private theorem sum_inl_extend_le (f : Hilbert V) (s : Finset (V ⊕ E)) : - ∑ z ∈ s, ‖Sum.elim (fun x => f x) (fun _ : E => (0:ℂ)) z‖ ^ (2:ℝ≥0∞).toReal ≤ - ‖f‖ ^ (2:ℝ≥0∞).toReal := by - classical - rw [Finset.sum_sum_eq_sum_toLeft_add_sum_toRight] - simp only [Sum.elim_inl,Sum.elim_inr,norm_zero,ENNReal.toReal_ofNat,Real.zero_rpow (by norm_num : (2:ℝ) ≠ 0), - Finset.sum_const_zero,add_zero] - exact lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2:ℝ≥0∞).toReal) f s.toLeft - -noncomputable def hilbertInlValue (f : Hilbert V) : Hilbert (V ⊕ E) := - ⟨Sum.elim (fun x => f x) (fun _ => 0),memℓp_gen' (sum_inl_extend_le f)⟩ - -theorem norm_hilbertInlValue_le (f : Hilbert V) : ‖hilbertInlValue (E:=E) f‖ ≤ ‖f‖ := - lp.norm_le_of_forall_sum_le (by norm_num) (norm_nonneg f) (sum_inl_extend_le f) - -noncomputable def hilbertInl : Hilbert V →L[ℂ] Hilbert (V ⊕ E) := - LinearMap.mkContinuous - { toFun := hilbertInlValue - map_add' := by - intro f g - apply lp.ext - funext z - cases z with - | inl x => rfl - | inr e => change (0:ℂ) = 0+0; simp - map_smul' := by - intro c f - apply lp.ext - funext z - cases z with - | inl x => rfl - | inr e => change (0:ℂ) = c • 0; simp } - 1 (fun f => by simpa using norm_hilbertInlValue_le (E:=E) f) - -@[simp] theorem hilbertInl_apply_inl (f : Hilbert V) (x : V) : - hilbertInl (E:=E) f (.inl x) = f x := rfl -@[simp] theorem hilbertInl_apply_inr (f : Hilbert V) (e : E) : - hilbertInl (E:=E) f (.inr e) = 0 := rfl - -private theorem sum_inl_restrict_le (f : Hilbert (V ⊕ E)) (s : Finset V) : - ∑ x ∈ s, ‖f (.inl x)‖ ^ (2:ℝ≥0∞).toReal ≤ ‖f‖ ^ (2:ℝ≥0∞).toReal := by - classical - rw [←Finset.sum_image (f := fun z => ‖f z‖ ^ (2:ℝ≥0∞).toReal) Sum.inl_injective.injOn] - exact lp.sum_rpow_le_norm_rpow (by norm_num) f _ - -noncomputable def hilbertRestrictInlValue (f : Hilbert (V ⊕ E)) : Hilbert V := - ⟨fun x => f (.inl x),memℓp_gen' (sum_inl_restrict_le f)⟩ - -theorem norm_hilbertRestrictInlValue_le (f : Hilbert (V ⊕ E)) : - ‖hilbertRestrictInlValue f‖ ≤ ‖f‖ := - lp.norm_le_of_forall_sum_le (by norm_num) (norm_nonneg f) (sum_inl_restrict_le f) - -noncomputable def hilbertRestrictInl : Hilbert (V ⊕ E) →L[ℂ] Hilbert V := - LinearMap.mkContinuous - { toFun := hilbertRestrictInlValue - map_add' := by intro f g; apply lp.ext; rfl - map_smul' := by intro c f; apply lp.ext; rfl } - 1 (fun f => by simpa using norm_hilbertRestrictInlValue_le f) - -@[simp] theorem hilbertRestrictInl_apply (f : Hilbert (V ⊕ E)) (x : V) : - hilbertRestrictInl f x = f (.inl x) := rfl - -@[simp] theorem hilbertInl_single [DecidableEq V] [DecidableEq E] (x : V) (c : ℂ) : - hilbertInl (E:=E) (lp.single 2 x c) = lp.single 2 (.inl x) c := by - apply lp.ext - funext z - cases z <;> simp [lp.single_apply,Pi.single_apply] - - -theorem operatorBounded_of_subdivision [Countable V] [Countable E] - (G : BondGraph V E) (q : unitInterval) (h : OperatorBounded (subdivision G) q) : - OperatorBounded G (q^2) := by - classical - obtain ⟨A,hA⟩ := h - refine ⟨hilbertRestrictInl ∘L A ∘L hilbertInl,?_⟩ - intro x y - simp only [ContinuousLinearMap.comp_apply,hilbertInl_single,hilbertRestrictInl_apply] - convert (hA (.inl x) (.inl y)).trans (congrArg (fun r : ℝ => (r:ℂ)) - (twoPoint_subdivision G q x y)) using 1 - apply congrArg (fun f : Hilbert (V ⊕ E) => A f (.inl x)) - apply lp.ext - funext z - simp [lp.single_apply,Pi.single_apply] - - - -theorem critical_bounded_of_subdivision [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) - (h : OperatorBounded (subdivision G) (pc (subdivision G))) : - OperatorBounded G (pc G) := by - simpa only [pc_subdivision_sq G hloc] using - operatorBounded_of_subdivision G (pc (subdivision G)) h - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Subdivision.Coupling + +namespace OAI + +/-! Operator bounds transferred through graph subdivision. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + + + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +open scoped ENNReal + +private theorem sum_inl_extend_le (f : Hilbert V) (s : Finset (V ⊕ E)) : + ∑ z ∈ s, ‖Sum.elim (fun x => f x) (fun _ : E => (0:ℂ)) z‖ ^ (2:ℝ≥0∞).toReal ≤ + ‖f‖ ^ (2:ℝ≥0∞).toReal := by + classical + rw [Finset.sum_sum_eq_sum_toLeft_add_sum_toRight] + simp only [Sum.elim_inl,Sum.elim_inr,norm_zero,ENNReal.toReal_ofNat,Real.zero_rpow (by norm_num : (2:ℝ) ≠ 0), + Finset.sum_const_zero,add_zero] + exact lp.sum_rpow_le_norm_rpow (by norm_num : 0 < (2:ℝ≥0∞).toReal) f s.toLeft + +noncomputable def hilbertInlValue (f : Hilbert V) : Hilbert (V ⊕ E) := + ⟨Sum.elim (fun x => f x) (fun _ => 0),memℓp_gen' (sum_inl_extend_le f)⟩ + +theorem norm_hilbertInlValue_le (f : Hilbert V) : ‖hilbertInlValue (E:=E) f‖ ≤ ‖f‖ := + lp.norm_le_of_forall_sum_le (by norm_num) (norm_nonneg f) (sum_inl_extend_le f) + +noncomputable def hilbertInl : Hilbert V →L[ℂ] Hilbert (V ⊕ E) := + LinearMap.mkContinuous + { toFun := hilbertInlValue + map_add' := by + intro f g + apply lp.ext + funext z + cases z with + | inl x => rfl + | inr e => change (0:ℂ) = 0+0; simp + map_smul' := by + intro c f + apply lp.ext + funext z + cases z with + | inl x => rfl + | inr e => change (0:ℂ) = c • 0; simp } + 1 (fun f => by simpa using norm_hilbertInlValue_le (E:=E) f) + +@[simp] theorem hilbertInl_apply_inl (f : Hilbert V) (x : V) : + hilbertInl (E:=E) f (.inl x) = f x := rfl +@[simp] theorem hilbertInl_apply_inr (f : Hilbert V) (e : E) : + hilbertInl (E:=E) f (.inr e) = 0 := rfl + +private theorem sum_inl_restrict_le (f : Hilbert (V ⊕ E)) (s : Finset V) : + ∑ x ∈ s, ‖f (.inl x)‖ ^ (2:ℝ≥0∞).toReal ≤ ‖f‖ ^ (2:ℝ≥0∞).toReal := by + classical + rw [←Finset.sum_image (f := fun z => ‖f z‖ ^ (2:ℝ≥0∞).toReal) Sum.inl_injective.injOn] + exact lp.sum_rpow_le_norm_rpow (by norm_num) f _ + +noncomputable def hilbertRestrictInlValue (f : Hilbert (V ⊕ E)) : Hilbert V := + ⟨fun x => f (.inl x),memℓp_gen' (sum_inl_restrict_le f)⟩ + +theorem norm_hilbertRestrictInlValue_le (f : Hilbert (V ⊕ E)) : + ‖hilbertRestrictInlValue f‖ ≤ ‖f‖ := + lp.norm_le_of_forall_sum_le (by norm_num) (norm_nonneg f) (sum_inl_restrict_le f) + +noncomputable def hilbertRestrictInl : Hilbert (V ⊕ E) →L[ℂ] Hilbert V := + LinearMap.mkContinuous + { toFun := hilbertRestrictInlValue + map_add' := by intro f g; apply lp.ext; rfl + map_smul' := by intro c f; apply lp.ext; rfl } + 1 (fun f => by simpa using norm_hilbertRestrictInlValue_le f) + +@[simp] theorem hilbertRestrictInl_apply (f : Hilbert (V ⊕ E)) (x : V) : + hilbertRestrictInl f x = f (.inl x) := rfl + +@[simp] theorem hilbertInl_single [DecidableEq V] [DecidableEq E] (x : V) (c : ℂ) : + hilbertInl (E:=E) (lp.single 2 x c) = lp.single 2 (.inl x) c := by + apply lp.ext + funext z + cases z <;> simp [lp.single_apply,Pi.single_apply] + + +theorem operatorBounded_of_subdivision [Countable V] [Countable E] + (G : BondGraph V E) (q : unitInterval) (h : OperatorBounded (subdivision G) q) : + OperatorBounded G (q^2) := by + classical + obtain ⟨A,hA⟩ := h + refine ⟨hilbertRestrictInl ∘L A ∘L hilbertInl,?_⟩ + intro x y + simp only [ContinuousLinearMap.comp_apply,hilbertInl_single,hilbertRestrictInl_apply] + convert (hA (.inl x) (.inl y)).trans (congrArg (fun r : ℝ => (r:ℂ)) + (twoPoint_subdivision G q x y)) using 1 + apply congrArg (fun f : Hilbert (V ⊕ E) => A f (.inl x)) + apply lp.ext + funext z + simp [lp.single_apply,Pi.single_apply] + + + +theorem critical_bounded_of_subdivision [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) + (h : OperatorBounded (subdivision G) (pc (subdivision G))) : + OperatorBounded G (pc G) := by + simpa only [pc_subdivision_sq G hloc] using + operatorBounded_of_subdivision G (pc (subdivision G)) h + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Transport/EndpointKernels.lean b/lean/OAI/Probability/UnimodularPercolation/Transport/EndpointKernels.lean index ccd7cd64d3b5956e8e8f4ab959db8d15fed8966f..f322c2a670e2459cfb386ffef61107c8ac74f45a 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Transport/EndpointKernels.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Transport/EndpointKernels.lean @@ -1,1226 +1,1226 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Transport.TrajectoryMass - -namespace OAI - -/-! Endpoint Kernels for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section SeparatedTracePair -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_trace_pair_separated_le [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) - (Q : Finset E) (p : unitInterval) - (A₁ A₂ : Finset (SpliceState E)) (y₁ y₂ : (ℕ → Set E) → ℕ → V) - (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) - (hA₁ : A₁ ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hA₂ : A₂ ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hbin : ∀ s ∈ A₁, (cluster G s.1 x).Finite ∧ n ≤ (cluster G s.1 x).ncard ∧ - (cluster G s.1 x).ncard < 2*n) - (hcap₁ : ∀ s ∈ A₁, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y₁ s.2 i)).Finite) - (hcap₂ : ∀ s ∈ A₂, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y₂ s.2 i)).Finite ∧ - (cluster G (s.2 i) (y₂ s.2 i)).ncard ≤ M) : - (∑ a : FiniteTraceIndex G x k Q A₁ (fun s => y₁ s.2), - ∑ b : FiniteTraceIndex G x k Q A₂ (fun s => y₂ s.2), - if (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 = - (traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) b).1 ∧ - a.2.val ≠ [] ∧ b.2.val ≠ [] ∧ - GraphSeparated G - (cluster G (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 x \ cluster G a.1.val.1 x) - (cluster G (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 x \ cluster G b.1.val.1 x) - then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (pairSpliceOutput (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a) - (traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) b)) * - (m₁ a.1.val.2 * traceIndexMass G x k Q A₁ (fun s => y₁ s.2) a) * - (m₂ b.1.val.2 * traceIndexMass G x k Q A₂ (fun s => y₂ s.2) b) else 0) ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if - (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by - let T₁ := FiniteTraceIndex G x k Q A₁ (fun s => y₁ s.2) - let T₂ := FiniteTraceIndex G x k Q A₂ (fun s => y₂ s.2) - let out₁ := traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) - let out₂ := traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) - let P (a : T₁ × T₂) := (out₁ a.1).1 = (out₂ a.2).1 ∧ a.1.2.val ≠ [] ∧ a.2.2.val ≠ [] ∧ - GraphSeparated G (cluster G (out₁ a.1).1 x \ cluster G a.1.1.val.1 x) - (cluster G (out₁ a.1).1 x \ cluster G a.2.1.val.1 x) - let I := {a : T₁ × T₂ // P a} - let η₁ (a : I) := a.val.1.1.val.2 - let η₂ (a : I) := a.val.2.1.val.2 - let ω₁ (a : I) := a.val.1.1.val.1 - let ω₂ (a : I) := a.val.2.1.val.1 - let ωf (a : I) := (out₁ a.val.1).1 - let c₁ (a : I) := a.val.1.2.val - let c₂ (a : I) := a.val.2.2.val - have hout (a : I) : jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) - (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) = pairSpliceOutput (out₁ a.val.1) (out₂ a.val.2) := rfl - have hinj : Function.Injective (fun a : I => - (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a),c₁ a,c₂ a)) := by - intro a b he - dsimp only at he - rw [hout a,hout b] at he - have ho₁ : out₁ a.val.1 = out₁ b.val.1 := Prod.ext - (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.1) he) - (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.2.1) he) - have ho₂ : out₂ a.val.2 = out₂ b.val.2 := Prod.ext - (a.property.1.symm.trans ((congrArg Prod.fst ho₁).trans b.property.1)) - (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.2.2) he) - apply Subtype.ext - exact Prod.ext - (traceIndex_output_code_injective G x k Q A₁ (fun s => y₁ s.2) - (Prod.ext ho₁ (congrArg (fun z => z.2.1) he))) - (traceIndex_output_code_injective G x k Q A₂ (fun s => y₂ s.2) - (Prod.ext ho₂ (congrArg (fun z => z.2.2) he))) - have htr₁ (a : I) : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a) := - (traceIndex_valid G x k Q A₁ (fun s => y₁ s.2) a.val.1).1 - have htr₂ (a : I) : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a) := by - change SpliceTrace G x _ _ _ _ _ _ (out₁ a.val.1).1 - rw [a.property.1] - exact (traceIndex_valid G x k Q A₂ (fun s => y₂ s.2) a.val.2).1 - have hs₁ (a : I) := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp (hA₁ a.val.1.1.property) - have hs₂ (a : I) := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp (hA₂ a.val.2.1.property) - have hb := finite_separated_weighted_contact_second_moment_le G hloc x k n M p Q η₁ η₂ y₁ y₂ - (fun _ => True) (fun _ => True) m₁ m₂ hm₁ hm₂ ω₁ ω₂ ωf c₁ c₂ hinj htr₁ htr₂ - (fun a => a.property.2.1) (fun a => a.property.2.2.1) (fun a => a.property.2.2.2) - (fun a => hbin _ a.val.1.1.property) (fun a => hcap₁ _ a.val.1.1.property) - (fun a => hcap₂ _ a.val.2.1.property) (fun _ => trivial) (fun _ => trivial) - (fun a => (hs₁ a).1) (fun a => (hs₂ a).1) (fun a => (hs₁ a).2.1) - (fun a => (hs₂ a).2.1) (fun a => (hs₁ a).2.2) (fun a => (hs₂ a).2.2) - simp only [true_and] at hb - apply le_trans _ hb - let w (a : T₁ × T₂) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (pairSpliceOutput (out₁ a.1) (out₂ a.2)) * - (m₁ a.1.1.val.2 * traceIndexMass G x k Q A₁ (fun s => y₁ s.2) a.1) * - (m₂ a.2.1.val.2 * traceIndexMass G x k Q A₂ (fun s => y₂ s.2) a.2) - have he := Finset.sum_subtype (p := P) (F := inferInstance) (Finset.univ.filter P) - (by intro a; simp) w - rw [Finset.sum_filter,Fintype.sum_prod_type] at he - change (∑ a : T₁, ∑ b : T₂, if P (a,b) then w (a,b) else 0) ≤ _ - rw [he] - apply Finset.sum_le_sum - intro a _ - rw [hout a] - change w a.val ≤ _ - simp only [w,traceIndexMass,η₁,η₂,ωf,c₁,c₂,out₁,out₂] - rw [← a.property.1] - exact le_of_eq (by ring) - -end SeparatedTracePair - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ChoiceSeparatedMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable {P₁ P₂ : Type*} [Fintype P₁] [Fintype P₂] - - -noncomputable def finiteChoiceSeparatedPairMass - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) - (A₁ : P₁ → Finset (SpliceState E)) (A₂ : P₂ → Finset (SpliceState E)) - (y₁ : P₁ → (ℕ → Set E) → ℕ → V) (y₂ : P₂ → (ℕ → Set E) → ℕ → V) - (m₁ : P₁ → (ℕ → Set E) → ℝ) (m₂ : P₂ → (ℕ → Set E) → ℝ) : ℝ := - ∑ a : FiniteChoiceTraceIndex G x k Q A₁ (fun r s => y₁ r s.2), - ∑ b : FiniteChoiceTraceIndex G x k Q A₂ (fun r s => y₂ r s.2), - if (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 = - (choiceTraceOutput G x k Q A₂ (fun r s => y₂ r s.2) b).1 ∧ - choiceTraceCode G x k Q A₁ (fun r s => y₁ r s.2) a ≠ [] ∧ - choiceTraceCode G x k Q A₂ (fun r s => y₂ r s.2) b ≠ [] ∧ - GraphSeparated G - (cluster G (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x \ - cluster G (choiceTraceInput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x) - (cluster G (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x \ - cluster G (choiceTraceInput G x k Q A₂ (fun r s => y₂ r s.2) b).1 x) - then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p - (pairSpliceOutput (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a) - (choiceTraceOutput G x k Q A₂ (fun r s => y₂ r s.2) b)) * - choiceTraceMass G x k Q A₁ (fun r s => y₁ r s.2) (fun s r => m₁ r s.2) a * - choiceTraceMass G x k Q A₂ (fun r s => y₂ r s.2) (fun s r => m₂ r s.2) b else 0 - - -noncomputable def finiteChoiceHit (G : BondGraph V E) (k : ℕ) (Q : Finset E) (p : ℝ) - (y : P₁ → (ℕ → Set E) → ℕ → V) (m : P₁ → (ℕ → Set E) → ℝ) (B : Set V) : ℝ := - ∑ r, finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - if (B ∩ trajectoryUnion G η (y r η) k).Nonempty then m r η else 0) - - - -theorem finiteChoiceSeparatedPairMass_le [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) - (Q : Finset E) (p : unitInterval) - (A₁ : P₁ → Finset (SpliceState E)) (A₂ : P₂ → Finset (SpliceState E)) - (y₁ : P₁ → (ℕ → Set E) → ℕ → V) (y₂ : P₂ → (ℕ → Set E) → ℕ → V) - (m₁ : P₁ → (ℕ → Set E) → ℝ) (m₂ : P₂ → (ℕ → Set E) → ℝ) - (hm₁ : ∀ r η, 0 ≤ m₁ r η) (hm₂ : ∀ r η, 0 ≤ m₂ r η) - (hA₁ : ∀ r, A₁ r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hA₂ : ∀ r, A₂ r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hbin : ∀ r s, s ∈ A₁ r → (cluster G s.1 x).Finite ∧ n ≤ (cluster G s.1 x).ncard ∧ - (cluster G s.1 x).ncard < 2*n) - (hcap₁ : ∀ r s, s ∈ A₁ r → ∀ i, 1 ≤ i → i ≤ k → - (cluster G (s.2 i) (y₁ r s.2 i)).Finite) - (hcap₂ : ∀ r s, s ∈ A₂ r → ∀ i, 1 ≤ i → i ≤ k → - (cluster G (s.2 i) (y₂ r s.2 i)).Finite ∧ (cluster G (s.2 i) (y₂ r s.2 i)).ncard ≤ M) : - finiteChoiceSeparatedPairMass G x k Q p A₁ A₂ y₁ y₂ m₁ m₂ ≤ - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then - finiteChoiceHit G k Q p y₁ m₁ (cluster G (finiteFieldSet Q ω) x) * - finiteChoiceHit G k Q p y₂ m₂ (cluster G (finiteFieldSet Q ω) x) else 0) := by - let R (ω : FiniteField Q) := (cluster G (finiteFieldSet Q ω) x).Finite ∧ - n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ - (cluster G (finiteFieldSet Q ω) x).ncard < 2*n - let H₁ (r : P₁) (ω : FiniteField Q) := finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - if (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ r η) k).Nonempty then m₁ r η else 0) - let H₂ (r : P₂) (ω : FiniteField Q) := finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - if (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ r η) k).Nonempty then m₂ r η else 0) - have hb : finiteChoiceSeparatedPairMass G x k Q p A₁ A₂ y₁ y₂ m₁ m₂ ≤ - ∑ r : P₁, ∑ s : P₂, ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * - (if R ω then H₁ r ω * H₂ s ω else 0) := by - unfold finiteChoiceSeparatedPairMass - rw [Fintype.sum_sigma] - apply Finset.sum_le_sum - intro r _ - conv_lhs => arg 2; ext a; rw [Fintype.sum_sigma] - conv_lhs => rw [Finset.sum_comm] - simp only [choiceTraceOutput,choiceTraceInput,choiceTraceCode,choiceTraceMass, - traceIndexInput,traceIndexCode] - apply Finset.sum_le_sum - intro s _ - exact finite_trace_pair_separated_le G hloc x k n M Q p (A₁ r) (A₂ s) - (y₁ r) (y₂ s) (m₁ r) (m₂ s) (hm₁ r) (hm₂ s) (hA₁ r) (hA₂ s) - (hbin r) (hcap₁ r) (hcap₂ s) - apply hb.trans_eq - rw [Finset.sum_comm] - conv_lhs => arg 2; ext s; rw [Finset.sum_comm] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - change (∑ s : P₂, ∑ r : P₁, finiteFieldWeight Q p ω * (if R ω then H₁ r ω * H₂ s ω else 0)) = - finiteFieldWeight Q p ω * (if R ω then (∑ r : P₁, H₁ r ω) * (∑ s : P₂, H₂ s ω) else 0) - by_cases h : R ω - · simp only [ite_eq_left h,← Finset.mul_sum,← Finset.sum_mul] - · simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero] - -end ChoiceSeparatedMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LocalEndpointRule -attribute [local instance] Classical.propDecidable Classical.decEq - - - -structure LocalEndpointRule (G : BondGraph V E) (hloc : LocallyFinite G) - (O : Set V) (M : ℕ) (L : ℝ) where - mass : Set E → V → V → ℝ - radius : ℕ - nonneg : ∀ ω x y, 0 ≤ mass ω x y - row_le_one : ∀ ω x, (∑' y, mass ω x y) ≤ 1 - support : ∀ ω x y, mass ω x y ≠ 0 → x ∈ O ∧ y ∈ O ∧ Conn G ω x y ∧ - (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L - locality : ∀ ω x y, mass ω x y = - mass (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x radius).toFinset : Set E)) x y - covariance : ∀ (a : V ≃ V) (b : E ≃ E), IsAut G a b → ∀ ω x y, - mass (b ⁻¹' ω) x y = mass ω (a x) (a y) - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -theorem outside_ball_zero (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) - (hy : y ∉ reachBall G x M) : q.mass ω x y = 0 := by - by_contra h - obtain ⟨_,_,hc,hfin,hcap,_⟩ := q.support ω x y h - exact hy (finite_cluster_subset_reachBall G ω x hfin M hcap hc) - -theorem summable_mass (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : - Summable (q.mass ω x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - apply q.outside_ball_zero ω x y - simpa only [Set.Finite.mem_toFinset] using hy - -theorem mass_le_one (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) : - q.mass ω x y ≤ 1 := by - have h := (q.summable_mass ω x).sum_le_tsum ({y} : Finset V) (fun z _ => q.nonneg ω x z) - simpa only [Finset.sum_singleton] using h.trans (q.row_le_one ω x) - - -theorem measurable_mass (q : LocalEndpointRule G hloc O M L) (x y : V) : - Measurable (fun ω => q.mass ω x y) := by - let Q := incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset - let f : Set (Q : Set E) → ℝ := fun η => q.mass (Subtype.val '' η) x y - have hm : Measurable f := measurable_of_finite f - have he : (fun ω => q.mass ω x y) = f ∘ (fun ω : Set E => Subtype.val ⁻¹' ω : Set E → Set (Q : Set E)) := by - funext ω - rw [q.locality ω x y] - congr 1 - ext e - simp [Q,and_comm] - rw [he] - exact hm.comp (measurable_set_restrict (Q : Set E)) - -theorem integrable_mass (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : - Integrable (fun ω => q.mass ω x y) (law p) := by - apply Integrable.of_bound (q.measurable_mass x y).aestronglyMeasurable 1 - exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs,abs_of_nonneg (q.nonneg ω x y)] using q.mass_le_one ω x y - - - -noncomputable def kernel (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : ℝ := - ∫ ω, q.mass ω x y ∂law p - -theorem kernel_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : - 0 ≤ q.kernel p x y := integral_nonneg (fun ω => q.nonneg ω x y) - -theorem kernel_outside_ball_zero (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) - (hy : y ∉ reachBall G x M) : q.kernel p x y = 0 := by - simp only [kernel,q.outside_ball_zero _ x y hy,integral_zero] - -theorem summable_kernel (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - Summable (q.kernel p x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - apply q.kernel_outside_ball_zero p x y - simpa only [Set.Finite.mem_toFinset] using hy - - - -theorem kernel_row_integral (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - (∑' y, q.kernel p x y) = ∫ ω, (∑' y, q.mass ω x y) ∂law p := by - let B := (finite_reachBall hloc x M).toFinset - have h₁ : (∑' y, q.kernel p x y) = ∑ y ∈ B, q.kernel p x y := - tsum_eq_sum fun y hy => q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - have h₂ (ω : Set E) : (∑' y, q.mass ω x y) = ∑ y ∈ B, q.mass ω x y := - tsum_eq_sum fun y hy => q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - rw [h₁] - simp_rw [h₂] - exact (integral_finsetSum B (fun y _ => q.integrable_mass p x y)).symm - -theorem kernel_row_le_one (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - (∑' y, q.kernel p x y) ≤ 1 := by - rw [q.kernel_row_integral p x] - have hi : Integrable (fun ω => ∑' y, q.mass ω x y) (law p) := by - let B := (finite_reachBall hloc x M).toFinset - have he (ω : Set E) : (∑' y, q.mass ω x y) = ∑ y ∈ B, q.mass ω x y := - tsum_eq_sum fun y hy => q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) - simp_rw [he] - exact integrable_finsetSum B (fun y _ => q.integrable_mass p x y) - calc - _ ≤ ∫ _, (1:ℝ) ∂law p := integral_mono hi (integrable_const _) (q.row_le_one · x) - _ = 1 := by simp - -end LocalEndpointRule -end LocalEndpointRule - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section LocalEndpointKernel -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -theorem outside_reverse_ball_zero (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) - (hx : x ∉ reachBall G y M) : q.mass ω x y = 0 := by - by_contra h - obtain ⟨_,_,hc,hfin,hcap,_⟩ := q.support ω x y h - have he := cluster_eq_of_conn G ω hc - rw [he] at hfin hcap - exact hx (finite_cluster_subset_reachBall G ω y hfin M hcap (conn_symm G ω hc)) - -theorem kernel_outside_reverse_ball_zero (q : LocalEndpointRule G hloc O M L) - (p : unitInterval) (x y : V) (hx : x ∉ reachBall G y M) : q.kernel p x y = 0 := by - simp only [kernel,q.outside_reverse_ball_zero _ x y hx,integral_zero] - -theorem summable_kernel_column (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (y : V) : - Summable (fun x => q.kernel p x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y M).toFinset) - intro x hx - apply q.kernel_outside_reverse_ball_zero p x y - simpa only [Set.Finite.mem_toFinset] using hx - -theorem mass_zero_of_start_not_mem (q : LocalEndpointRule G hloc O M L) (ω : Set E) - (x y : V) (hx : x ∉ O) : q.mass ω x y = 0 := by - by_contra h - exact hx (q.support ω x y h).1 - -theorem mass_zero_of_end_not_mem (q : LocalEndpointRule G hloc O M L) (ω : Set E) - (x y : V) (hy : y ∉ O) : q.mass ω x y = 0 := by - by_contra h - exact hy (q.support ω x y h).2.1 - -theorem kernel_zero_of_start_not_mem (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (x y : V) (hx : x ∉ O) : q.kernel p x y = 0 := by - simp only [kernel,q.mass_zero_of_start_not_mem _ x y hx,integral_zero] - -theorem kernel_zero_of_end_not_mem (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (x y : V) (hy : y ∉ O) : q.kernel p x y = 0 := by - simp only [kernel,q.mass_zero_of_end_not_mem _ x y hy,integral_zero] - - - -theorem kernel_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x y : V) : - q.kernel p (a x) (a y) = q.kernel p x y := by - have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable - (q.measurable_mass x y).aestronglyMeasurable - rw [law_map_preimage_equiv p b] at h - simpa only [kernel,q.covariance a b ha] using h.symm - -noncomputable def successProbability (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : ℝ := - ∑' y, q.kernel p x y - -theorem successProbability_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - 0 ≤ q.successProbability p x := tsum_nonneg (q.kernel_nonneg p x) - -theorem successProbability_le_one (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : - q.successProbability p x ≤ 1 := q.kernel_row_le_one p x - -theorem successProbability_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x : V) : - q.successProbability p (a x) = q.successProbability p x := by - unfold successProbability - rw [← a.tsum_eq (fun y => q.kernel p (a x) y)] - exact tsum_congr (q.kernel_covariant p a b ha x) - -theorem successProbability_orbit (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (o x : V) (hx : x ∈ vertexOrbit G o) : q.successProbability p x = q.successProbability p o := by - obtain ⟨a,b,ha,rfl⟩ := hx - exact q.successProbability_covariant p a b ha o - -theorem kernel_column_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) - (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (y : V) : - (∑' x, q.kernel p x (a y)) = ∑' x, q.kernel p x y := by - rw [← a.tsum_eq (fun x => q.kernel p x (a y))] - exact tsum_congr (fun x => q.kernel_covariant p a b ha x y) - -end LocalEndpointRule -end LocalEndpointKernel - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EndpointTransport -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - - - -theorem kernel_column_orbit (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) - (p : unitInterval) (y : V) (hy : y ∈ vertexOrbit G o) : - (∑' x, q.kernel p x y) = ∑' x, q.kernel p x o := by - obtain ⟨a,b,ha,rfl⟩ := hy - exact q.kernel_column_covariant p a b ha o - - - -theorem kernel_column_eq_success {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (p : unitInterval) (y : V) (hy : y ∈ vertexOrbit G (root i₀)) : - (∑' x, q.kernel p x y) = q.successProbability p (root i₀) := by - let O := vertexOrbit G (root i₀) - let w : ι → ℝ := fun i => if root i ∈ O then weight i else 0 - have ho : root i₀ ∈ O := by - refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ - intro e - simp - have hw' (i : ι) : 0 ≤ w i := by - dsimp [w] - split_ifs - · exact hw i - · exact le_rfl - have hpos : 0 < ∑ i, w i := by - have hi : w i₀ ≤ ∑ i, w i := Finset.single_le_sum (fun i _ => hw' i) (Finset.mem_univ i₀) - have he : w i₀ = weight i₀ := ite_eq_left ho - rw [he] at hi - exact hw₀.trans_le hi - have ht := htr.real root weight Γ (q.kernel p) - (by intro a ha x z; obtain ⟨b,hb⟩ := hΓ a ha; exact q.kernel_covariant p a b hb x z) - (q.summable_kernel p) (q.summable_kernel_column p) - have hr (i : ι) : weight i * (∑' z, q.kernel p (root i) z) = - w i * q.successProbability p (root i₀) := by - by_cases hi : root i ∈ O - · have he := q.successProbability_orbit p (root i₀) (root i) hi - change weight i * q.successProbability p (root i) = _ - rw [he] - simp only [w,ite_eq_left hi] - · simp only [w,ite_eq_right hi,zero_mul] - have he : (∑' z, q.kernel p (root i) z) = 0 := by - simp only [q.kernel_zero_of_start_not_mem p _ _ hi,tsum_zero] - rw [he,mul_zero] - have hc (i : ι) : weight i * (∑' x, q.kernel p x (root i)) = - w i * (∑' x, q.kernel p x (root i₀)) := by - by_cases hi : root i ∈ O - · rw [q.kernel_column_orbit (root i₀) p (root i) hi] - simp only [w,ite_eq_left hi] - · simp only [w,ite_eq_right hi,zero_mul] - have he : (∑' x, q.kernel p x (root i)) = 0 := by - simp only [q.kernel_zero_of_end_not_mem p _ _ hi,tsum_zero] - rw [he,mul_zero] - simp_rw [hr,hc] at ht - rw [← Finset.sum_mul,← Finset.sum_mul] at ht - rw [q.kernel_column_orbit (root i₀) p y hy] - exact (mul_left_cancel₀ (ne_of_gt hpos) ht).symm - - -theorem kernel_column_le_success {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (p : unitInterval) (y : V) : - (∑' x, q.kernel p x y) ≤ q.successProbability p (root i₀) := by - by_cases hy : y ∈ vertexOrbit G (root i₀) - · exact (q.kernel_column_eq_success root weight Γ htr hΓ hw i₀ hw₀ p y hy).le - · simpa only [q.kernel_zero_of_end_not_mem p _ _ hy,tsum_zero] using - q.successProbability_nonneg p (root i₀) - -end LocalEndpointRule -end EndpointTransport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EndpointSchur -attribute [local instance] Classical.propDecidable Classical.decEq -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} - -theorem kernel_row_le_success (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) (x : V) : - (∑' y, q.kernel p x y) ≤ q.successProbability p o := by - by_cases hx : x ∈ vertexOrbit G o - · exact (q.successProbability_orbit p o x hx).le - · simpa only [q.kernel_zero_of_start_not_mem p _ _ hx,tsum_zero] using - q.successProbability_nonneg p o - - -noncomputable def normalizedKernel (o : V) - (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) (x y : V) : ℝ := - (q.successProbability p o)⁻¹ * q.kernel p x y - - - -theorem exists_normalized_operator {ι : Type*} [Fintype ι] - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) - (i₀ : ι) (hw₀ : 0 < weight i₀) - (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) - (p : unitInterval) (hu : 0 < q.successProbability p (root i₀)) : - ∃ A : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A‖ ∧ ‖A‖ ≤ 1 ∧ - ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ) := by - let u := q.successProbability p (root i₀) - have hu₀ : u ≠ 0 := ne_of_gt hu - have hn (x y : V) : 0 ≤ q.normalizedKernel (root i₀) p x y := - mul_nonneg (inv_nonneg.mpr hu.le) (q.kernel_nonneg p x y) - have hr (x : V) (S : Finset V) : (∑ y ∈ S, q.normalizedKernel (root i₀) p x y) ≤ 1 := by - change (∑ y ∈ S, u⁻¹ * q.kernel p x y) ≤ 1 - rw [← Finset.mul_sum] - calc - _ ≤ u⁻¹ * (∑' y, q.kernel p x y) := mul_le_mul_of_nonneg_left - ((q.summable_kernel p x).sum_le_tsum S (fun y _ => q.kernel_nonneg p x y)) (inv_nonneg.mpr hu.le) - _ ≤ u⁻¹ * u := mul_le_mul_of_nonneg_left - (q.kernel_row_le_success (root i₀) p x) (inv_nonneg.mpr hu.le) - _ = 1 := inv_mul_cancel₀ hu₀ - have hc (y : V) (S : Finset V) : (∑ x ∈ S, q.normalizedKernel (root i₀) p x y) ≤ 1 := by - change (∑ x ∈ S, u⁻¹ * q.kernel p x y) ≤ 1 - rw [← Finset.mul_sum] - calc - _ ≤ u⁻¹ * (∑' x, q.kernel p x y) := mul_le_mul_of_nonneg_left - ((q.summable_kernel_column p y).sum_le_tsum S (fun x _ => q.kernel_nonneg p x y)) (inv_nonneg.mpr hu.le) - _ ≤ u⁻¹ * u := mul_le_mul_of_nonneg_left - (q.kernel_column_le_success root weight Γ htr hΓ hw i₀ hw₀ p y) (inv_nonneg.mpr hu.le) - _ = 1 := inv_mul_cancel₀ hu₀ - obtain ⟨A,hA,hK⟩ := exists_operator_of_row_column_bound (q.normalizedKernel (root i₀) p) 1 (by norm_num) hn hr hc - refine ⟨A,?_,hA,hK⟩ - apply norm_pos_iff.mpr - intro ha - have hz (y : V) : q.kernel p (root i₀) y = 0 := by - have h := hK (root i₀) y - rw [ha] at h - have he : u⁻¹ * q.kernel p (root i₀) y = 0 := Complex.ofReal_eq_zero.mp h.symm - exact (mul_eq_zero.mp he).resolve_left (inv_ne_zero hu₀) - have he : u = 0 := by simp only [u,successProbability,hz,tsum_zero] - exact hu₀ he - -end LocalEndpointRule -end EndpointSchur - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory ProbabilityTheory -section FiniteLocalIntegral -attribute [local instance] Classical.propDecidable Classical.decEq - - - -noncomputable def finiteFieldEquiv (Q : Finset E) : FiniteField Q ≃ Set (Q : Set E) where - toFun ω := Subtype.val ⁻¹' finiteFieldSet Q ω - invFun η := ⟨η.toFinset.map ⟨Subtype.val,Subtype.val_injective⟩, by - apply Finset.mem_powerset.mpr - intro e he - obtain ⟨a,_,rfl⟩ := Finset.mem_map.mp he - exact a.property⟩ - left_inv ω := by - apply Subtype.ext - apply Finset.coe_injective - ext e - simp only [Finset.coe_map,Set.mem_image,finiteFieldSet,Function.Embedding.coeFn_mk] - constructor - · rintro ⟨a,ha,rfl⟩ - have ha' : a ∈ (Subtype.val ⁻¹' (ω.val : Set E) : Set (Q : Set E)) := Set.mem_toFinset.mp ha - exact ha' - · intro he - exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,Set.mem_toFinset.mpr he,rfl⟩ - right_inv η := by - ext e - simp only [Set.mem_preimage,finiteFieldSet,Finset.coe_map,Set.coe_toFinset, - Set.mem_image,Function.Embedding.coeFn_mk,Subtype.val_injective.eq_iff,exists_eq_right] - -@[simp] theorem finiteFieldEquiv_apply (Q : Finset E) (ω : FiniteField Q) : - finiteFieldEquiv Q ω = Subtype.val ⁻¹' finiteFieldSet Q ω := rfl - -@[simp] theorem finiteFieldEquiv_image (Q : Finset E) (ω : FiniteField Q) : - Subtype.val '' finiteFieldEquiv Q ω = finiteFieldSet Q ω := by - rw [finiteFieldEquiv_apply] - apply Set.image_preimage_eq_of_subset - intro e he - exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,rfl⟩ - - - -theorem finiteFieldWeight_eq_atom (Q : Finset E) (p : unitInterval) (ω : FiniteField Q) : - finiteFieldWeight Q p ω = (law p : Measure (Set (Q : Set E))).real {finiteFieldEquiv Q ω} := by - have hn : (finiteFieldEquiv Q ω).ncard = ω.val.card := by - rw [finiteFieldEquiv_apply,Set.ncard_preimage_of_injective_subset_range Subtype.val_injective] - · exact Set.ncard_coe_finset _ - · intro e he - exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,rfl⟩ - rw [law,setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ, - Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ,hn] - have hc : Fintype.card (Q : Set E) = Q.card := Fintype.card_coe Q - simp only [finiteFieldWeight,bernoulliWeight,Set.ncard_univ,Nat.card_eq_fintype_card,hc] - - - -theorem integral_finite_local (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : - (∫ ω, f ω ∂law p) = ∑ η : FiniteField Q, finiteFieldWeight Q p η * f (finiteFieldSet Q η) := by - let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) - have hmap := integral_map (μ := law p) (measurable_set_restrict (Q : Set E)).aemeasurable - (measurable_of_finite g).aestronglyMeasurable - rw [law_map_restrict p (Q : Set E)] at hmap - have he (ω : Set E) : g (Subtype.val ⁻¹' ω) = f ω := by - rw [hf ω] - dsimp [g] - congr 1 - ext e - simp [and_comm] - simp_rw [he] at hmap - rw [← hmap,integral_fintype Integrable.of_finite] - rw [← (finiteFieldEquiv Q).sum_comp] - apply Finset.sum_congr rfl - intro η _ - rw [← finiteFieldWeight_eq_atom] - simp only [g,finiteFieldEquiv_image,smul_eq_mul] - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - - - -theorem kernel_finite_sum (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : - let Q := incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset - q.kernel p x y = ∑ η : FiniteField Q, finiteFieldWeight Q p η * q.mass (finiteFieldSet Q η) x y := - integral_finite_local _ p (fun ω => q.mass ω x y) (fun ω => q.locality ω x y) - -theorem continuous_kernel (q : LocalEndpointRule G hloc O M L) (x y : V) : - Continuous (fun p : unitInterval => q.kernel p x y) := by - simp_rw [q.kernel_finite_sum] - apply continuous_finsetSum - intro η _ - unfold finiteFieldWeight bernoulliWeight - fun_prop - -theorem continuous_successProbability (q : LocalEndpointRule G hloc O M L) (x : V) : - Continuous (fun p : unitInterval => q.successProbability p x) := by - have he (p : unitInterval) : q.successProbability p x = - ∑ y ∈ (finite_reachBall hloc x M).toFinset, q.kernel p x y := by - apply tsum_eq_sum - intro y hy - exact q.kernel_outside_ball_zero p x y (by simpa only [Set.Finite.mem_toFinset] using hy) - simp_rw [he] - exact continuous_finsetSum _ (fun y _ => q.continuous_kernel x y) - -end LocalEndpointRule -end FiniteLocalIntegral - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section GoodnessCovariance -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem internalEdges_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (W : Set V) : - internalEdges G (a ⁻¹' W) = b ⁻¹' internalEdges G W := by - ext e - simp only [internalEdges,Set.mem_ofPred_eq,Set.mem_preimage,hab e,Sym2.mem_map] - constructor - · intro h y hy - obtain ⟨z,hz,rfl⟩ := hy - exact h z hz - · intro h z hz - exact h (a z) ⟨z,hz,rfl⟩ - -theorem cutExists_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (W : Set V) (e : E) : - CutExists G (a ⁻¹' W) e ↔ CutExists G W (b e) := by - constructor - · rintro ⟨u,v,he,hu,hv⟩ - exact ⟨a u,a v,by rw [hab e,he,Sym2.map_mk],hu,hv⟩ - · rintro ⟨u,v,he,hu,hv⟩ - refine ⟨a.symm u,a.symm v,?_,by simpa using hu,by simpa using hv⟩ - have h := congrArg (Sym2.map a.symm) he - simpa only [hab e,Sym2.map_map,Equiv.symm_comp_self,id_eq,Sym2.map_id',Sym2.map_mk] using h - -theorem contactSet_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (W : Set V) : - contactSet G (b ⁻¹' ω) (a ⁻¹' W) = b ⁻¹' contactSet G ω W := by - ext e - simp only [contactSet,Set.mem_ofPred_eq,Set.mem_preimage,cutExists_aut_preimage G hab] - -theorem openMarkedPivotal_pair_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) (e : E) : - OpenMarkedPivotal G (b ⁻¹' ω) {y} x e ↔ - OpenMarkedPivotal G ω {a y} (a x) (b e) := by - have he : (b ⁻¹' ω) \ {e} = b ⁻¹' (ω \ {b e}) := by - ext f - simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] - simp only [OpenMarkedPivotal,MarkedEvent,Set.mem_singleton_iff,exists_eq_left, - Set.mem_preimage,he,conn_aut_iff G hab] - -theorem pivotalDistance_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x y : V) : - pivotalDistance G (b ⁻¹' ω) x y = pivotalDistance G ω (a x) (a y) := by - have he : {e | OpenMarkedPivotal G (b ⁻¹' ω) {y} x e} = - b ⁻¹' {e | OpenMarkedPivotal G ω {a y} (a x) e} := by - ext e - exact openMarkedPivotal_pair_aut G hab ω x y e - rw [pivotalDistance,he,Set.ncard_preimage_of_injective_subset_range b.injective] - · rfl - · exact fun e _ => b.surjective e - -theorem goodForScale_aut_pullback (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) (L : ℝ) - (hg : GoodForScale G ω (a x) L) : GoodForScale G (b ⁻¹' ω) x L := by - intro W hW hconn hpos u hu v hv - let W' := W.map a.toEmbedding - have hpre : a ⁻¹' (W' : Set V) = (W : Set V) := by - ext z - simp [W'] - have hcfg : b ⁻¹' (ω ∩ internalEdges G (W' : Set V)) = - (b ⁻¹' ω) ∩ internalEdges G (W : Set V) := by - rw [Set.preimage_inter,← internalEdges_aut_preimage G hab,hpre] - have hcontact : (contactSet G (b ⁻¹' ω) (W : Set V)).ncard = - (contactSet G ω (W' : Set V)).ncard := by - rw [← hpre,contactSet_aut_preimage G hab, - Set.ncard_preimage_of_injective_subset_range b.injective] - exact fun e _ => b.surjective e - have hW' : (W' : Set V) ⊆ cluster G ω (a x) := by - intro z hz - obtain ⟨w,hw,rfl⟩ := Finset.mem_map.mp hz - exact (conn_aut_iff G hab ω x w).mp (hW hw) - have hc' : ∀ w ∈ W', ∀ z ∈ W', Conn G (ω ∩ internalEdges G (W' : Set V)) w z := by - intro w hw z hz - obtain ⟨u,hu,rfl⟩ := Finset.mem_map.mp hw - obtain ⟨v,hv,rfl⟩ := Finset.mem_map.mp hz - apply (conn_aut_iff G hab _ u v).mp - rw [hcfg] - exact hconn u hu v hv - have H := hg W' hW' hc' (by rwa [← hcontact]) (a u) - (Finset.mem_map.mpr ⟨u,hu,rfl⟩) (a v) (Finset.mem_map.mpr ⟨v,hv,rfl⟩) - rw [← pivotalDistance_aut_preimage G hab,hcfg,← hcontact] at H - exact H - -theorem goodForScale_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) (L : ℝ) : - GoodForScale G (b ⁻¹' ω) x L ↔ GoodForScale G ω (a x) L := by - constructor - · intro h - have H := goodForScale_aut_pullback G (isAut_symm G hab) (b ⁻¹' ω) (a x) L - (by simpa only [Equiv.symm_apply_apply] using h) - simpa only [← Set.preimage_comp,Equiv.self_comp_symm,Set.preimage_id_eq,id_eq] using H - · exact goodForScale_aut_pullback G hab ω x L - -end GoodnessCovariance - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CappedGoodLocality -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem measurable_finite_local (Q : Finset E) (f : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : Measurable f := by - let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) - have he : f = g ∘ (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) := by - funext ω - rw [hf ω] - congr 1 - ext e - simp [and_comm] - rw [he] - exact (measurable_of_finite g).comp (measurable_set_restrict (Q : Set E)) - -theorem integrable_finite_local (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : Integrable f (law p) := by - let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) - have he : f = g ∘ (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) := by - funext ω - rw [hf ω] - congr 1 - ext e - simp [and_comm] - have hi : Integrable g (Measure.map (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) (law p)) := by - rw [law_map_restrict] - exact Integrable.of_finite - rw [he] - exact hi.comp_measurable (measurable_set_restrict (Q : Set E)) - -def CappedGoodness (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : Prop := - (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L - -theorem cappedGoodness_local (G : BondGraph V E) (hloc : LocallyFinite G) - (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : - let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset - CappedGoodness G ω x M L ↔ CappedGoodness G (ω ∩ (Q : Set E)) x M L := by - have he (η : Set E) : CappedGoodness G η x M L ↔ - ((cluster G η x).Finite ∧ (cluster G η x).ncard ≤ M) ∧ ¬CappedBadGoodness G η x M L := by - constructor - · rintro ⟨hf,hM,hg⟩ - exact ⟨⟨hf,hM⟩,fun h => h.2.2 hg⟩ - · rintro ⟨⟨hf,hM⟩,hbad⟩ - refine ⟨hf,hM,?_⟩ - by_contra hn - exact hbad ⟨hf,hM,hn⟩ - dsimp only - have hbad := cappedBadGoodness_local G hloc x M L ω - have hcap := capped_cluster_local G hloc x M ω - dsimp only at hbad hcap - rw [he,he,hbad,hcap] - -theorem cappedGoodness_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : - CappedGoodness G (b ⁻¹' ω) x M L ↔ CappedGoodness G ω (a x) M L := by - have hf : (cluster G (b ⁻¹' ω) x).Finite ↔ (cluster G ω (a x)).Finite := by - rw [← cluster_aut G hab ω x] - exact (Set.finite_image_iff a.injective.injOn).symm - have hn : (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by - rw [← cluster_aut G hab ω x,Set.ncard_image_of_injective _ a.injective] - simp only [CappedGoodness,hf,hn,goodForScale_aut_iff G hab] - -theorem incidentSupport_ball_mono (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) {r R : ℕ} (h : r ≤ R) : - incidentSupport G hloc (finite_reachBall hloc x r).toFinset ⊆ - incidentSupport G hloc (finite_reachBall hloc x R).toFinset := by - apply incidentSupport_mono - intro z hz - simp only [Set.Finite.mem_toFinset] at hz ⊢ - exact reachBall_mono_local G x h hz - -theorem finite_local_of_subset (Q S : Finset E) (hQS : Q ⊆ S) (f : Set E → ℝ) - (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) (ω : Set E) : - f ω = f (ω ∩ (S : Set E)) := by - rw [hf ω,hf (ω ∩ (S : Set E))] - congr 1 - exact (Set.inter_assoc _ _ _).trans (congrArg (ω ∩ ·) (Set.inter_eq_right.mpr hQS)) |>.symm - -end CappedGoodLocality - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section CappedLocalLoad -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem finite_prop_local_of_subset (Q S : Finset E) (hQS : Q ⊆ S) (P : Set E → Prop) - (hf : ∀ ω, P ω ↔ P (ω ∩ (Q : Set E))) (ω : Set E) : - P ω ↔ P (ω ∩ (S : Set E)) := by - have he : (ω ∩ (S : Set E)) ∩ (Q : Set E) = ω ∩ (Q : Set E) := - (Set.inter_assoc _ _ _).trans (congrArg (ω ∩ ·) (Set.inter_eq_right.mpr hQS)) - exact (hf ω).trans ((he ▸ hf (ω ∩ (S : Set E))).symm) - - - -structure CappedLocalLoad (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (M : ℕ) where - mass : Set E → V → V → ℝ - radius : ℕ - nonneg : ∀ ω x y, 0 ≤ mass ω x y - support : ∀ ω x y, mass ω x y ≠ 0 → x ∈ O ∧ y ∈ O ∧ Conn G ω x y ∧ - (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M - locality : ∀ ω x y, mass ω x y = - mass (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x radius).toFinset : Set E)) x y - covariance : ∀ (a : V ≃ V) (b : E ≃ E), IsAut G a b → ∀ ω x y, - mass (b ⁻¹' ω) x y = mass ω (a x) (a y) - -namespace CappedLocalLoad -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} - -noncomputable def row (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : ℝ := - ∑' y, q.mass ω x y - -theorem row_nonneg (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : 0 ≤ q.row ω x := - tsum_nonneg (q.nonneg ω x) - -theorem outside_ball_zero (q : CappedLocalLoad G hloc O M) (ω : Set E) (x y : V) - (hy : y ∉ reachBall G x M) : q.mass ω x y = 0 := by - by_contra h - obtain ⟨_,_,hc,hfin,hcap⟩ := q.support ω x y h - exact hy (finite_cluster_subset_reachBall G ω x hfin M hcap hc) - -theorem summable_mass (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : - Summable (q.mass ω x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) - intro y hy - exact q.outside_ball_zero ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) - -theorem mass_le_row (q : CappedLocalLoad G hloc O M) (ω : Set E) (x y : V) : - q.mass ω x y ≤ q.row ω x := by - simpa only [Finset.sum_singleton,row] using - (q.summable_mass ω x).sum_le_tsum {y} (fun z _ => q.nonneg ω x z) - -theorem row_locality (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : - q.row ω x = q.row - (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset : Set E)) x := - tsum_congr (q.locality ω x) - -theorem row_covariance (q : CappedLocalLoad G hloc O M) (a : V ≃ V) (b : E ≃ E) - (hab : IsAut G a b) (ω : Set E) (x : V) : q.row (b ⁻¹' ω) x = q.row ω (a x) := by - unfold row - simp_rw [q.covariance a b hab] - exact a.tsum_eq _ - -theorem integrable_mass (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : - Integrable (fun ω => q.mass ω x y) (law p) := - integrable_finite_local _ p _ (q.locality · x y) - -theorem integrable_row (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x : V) : - Integrable (fun ω => q.row ω x) (law p) := - integrable_finite_local _ p _ (q.row_locality · x) - -theorem integrable_sq_row (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x : V) : - Integrable (fun ω => q.row ω x ^ 2) (law p) := - integrable_finite_local _ p _ (fun ω => congrArg (· ^ 2) (q.row_locality ω x)) - - - -noncomputable def truncate (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) (L : ℝ) : - LocalEndpointRule G hloc O M L where - mass ω x y := if q.row ω x ≤ b ∧ CappedGoodness G ω x M L then b⁻¹ * q.mass ω x y else 0 - radius := max q.radius M - nonneg ω x y := by split_ifs; exact mul_nonneg (inv_nonneg.mpr hb.le) (q.nonneg ω x y); rfl - row_le_one ω x := by - by_cases h : q.row ω x ≤ b ∧ CappedGoodness G ω x M L - · simp only [h,and_self,ite_true,tsum_mul_left] - exact (mul_le_mul_of_nonneg_left h.1 (inv_nonneg.mpr hb.le)).trans_eq (inv_mul_cancel₀ hb.ne') - · simp only [h,ite_false,tsum_zero,zero_le_one] - support ω x y h := by - split_ifs at h with hkeep - · have hm : q.mass ω x y ≠ 0 := fun he => h (by rw [he,mul_zero]) - obtain ⟨hx,hy,hc,_,_⟩ := q.support ω x y hm - exact ⟨hx,hy,hc,hkeep.2⟩ - · exact (h rfl).elim - locality ω x y := by - let S := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset - have hm := finite_local_of_subset _ S - (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) - (fun η => q.mass η x y) (q.locality · x y) ω - have hr := finite_local_of_subset _ S - (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) - (fun η => q.row η x) (q.row_locality · x) ω - have hg := finite_prop_local_of_subset _ S - (incidentSupport_ball_mono G hloc x (le_max_right q.radius M)) - (fun η => CappedGoodness G η x M L) (fun η => cappedGoodness_local G hloc η x M L) ω - simp only [hm,hr,hg] - rfl - covariance a c hac ω x y := by - simp only [q.row_covariance a c hac,q.covariance a c hac,cappedGoodness_aut_iff G hac] - -end CappedLocalLoad -end CappedLocalLoad - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -open MeasureTheory -section TruncationLoss -attribute [local instance] Classical.propDecidable Classical.decEq -namespace CappedLocalLoad -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} - -theorem cap_of_row_ne_zero (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) - (hr : q.row ω x ≠ 0) : (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M := by - obtain ⟨y,hy⟩ : ∃ y, q.mass ω x y ≠ 0 := by - by_contra hn - push Not at hn - exact hr (by simp only [row,hn,tsum_zero]) - exact (q.support ω x y hy).2.2.2 - -theorem truncate_scaled_row (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) - (L : ℝ) (ω : Set E) (x : V) : - b * (∑' y, (q.truncate b hb L).mass ω x y) = - if q.row ω x ≤ b ∧ CappedGoodness G ω x M L then q.row ω x else 0 := by - by_cases h : q.row ω x ≤ b ∧ CappedGoodness G ω x M L - · simp only [truncate,ite_eq_left h,tsum_mul_left,← mul_assoc,mul_inv_cancel₀ hb.ne',one_mul] - rfl - · simp only [truncate,ite_eq_right h,tsum_zero,mul_zero] - -theorem truncate_mass_le (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) - (L : ℝ) (ω : Set E) (x y : V) : - (q.truncate b hb L).mass ω x y ≤ b⁻¹ * q.mass ω x y := by - change (if _ then _ else _) ≤ _ - split_ifs - · rfl - · exact mul_nonneg (inv_nonneg.mpr hb.le) (q.nonneg ω x y) - - - -theorem truncate_pointwise_loss (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) - (L : ℝ) (ω : Set E) (x : V) : - q.row ω x ≤ b * (∑' y, (q.truncate b hb L).mass ω x y) + q.row ω x ^ 2 / b + - b * ({η | CappedBadGoodness G η x M L}.indicator (1 : Set E → ℝ) ω) := by - rw [q.truncate_scaled_row b hb L] - have hs : 0 ≤ q.row ω x ^ 2 / b := div_nonneg (sq_nonneg _) hb.le - have hi : 0 ≤ ({η | CappedBadGoodness G η x M L}.indicator (1 : Set E → ℝ) ω) := by - apply Set.indicator_nonneg - intro η _ - norm_num - by_cases hr : q.row ω x ≤ b - · by_cases hg : CappedGoodness G ω x M L - · simp only [hr,hg,and_self,ite_true] - nlinarith - · simp only [hg,and_false,ite_false,zero_add] - by_cases hz : q.row ω x = 0 - · rw [hz] - positivity - · have hc := q.cap_of_row_ne_zero ω x hz - have hbad : CappedBadGoodness G ω x M L := ⟨hc.1,hc.2,fun h => hg ⟨hc.1,hc.2,h⟩⟩ - rw [Set.indicator_of_mem (show ω ∈ {η | CappedBadGoodness G η x M L} from hbad)] - change q.row ω x ≤ q.row ω x ^ 2 / b + b * 1 - linarith - · simp only [hr,false_and,ite_false,zero_add] - have htail : q.row ω x ≤ q.row ω x ^ 2 / b := by - apply (le_div_iff₀ hb).mpr - have ht := mul_le_mul_of_nonneg_left (le_of_lt (lt_of_not_ge hr)) (q.row_nonneg ω x) - nlinarith - exact htail.trans (le_add_of_nonneg_right (mul_nonneg hb.le hi)) - - - -theorem truncate_mean_loss (q : CappedLocalLoad G hloc O M) (p : unitInterval) - (b : ℝ) (hb : 0 < b) (L : ℝ) (x : V) : - (∫ ω, q.row ω x ∂law p) ≤ b * (q.truncate b hb L).successProbability p x + - (∫ ω, q.row ω x ^ 2 ∂law p) / b + b * (law p).real {ω | CappedBadGoodness G ω x M L} := by - let t := q.truncate b hb L - have ht : Integrable (fun ω => ∑' y, t.mass ω x y) (law p) := by - apply integrable_finite_local - (incidentSupport G hloc (finite_reachBall hloc x t.radius).toFinset) p - intro ω - exact tsum_congr (t.locality ω x) - have hbad := measurableSet_cappedBadGoodness G hloc x M L - have hi : Integrable ({ω | CappedBadGoodness G ω x M L}.indicator (1 : Set E → ℝ)) (law p) := - (integrable_const (1:ℝ)).indicator hbad - have h := integral_mono (q.integrable_row p x) - (((ht.const_mul b).add ((q.integrable_sq_row p x).div_const b)).add (hi.const_mul b)) - (q.truncate_pointwise_loss b hb L · x) - dsimp only [Pi.add_apply] at h - have he₁ := integral_add ((ht.const_mul b).add ((q.integrable_sq_row p x).div_const b)) (hi.const_mul b) - have he₂ := integral_add (ht.const_mul b) ((q.integrable_sq_row p x).div_const b) - dsimp only [Pi.add_apply] at he₁ he₂ - rw [he₁,he₂,integral_const_mul,integral_div,integral_const_mul, - integral_indicator_one hbad] at h - rw [← t.kernel_row_integral p x] at h - exact h - -theorem truncate_success_lower (q : CappedLocalLoad G hloc O M) (p : unitInterval) - (b : ℝ) (hb : 0 < b) (L : ℝ) (x : V) (a : ℝ) - (hmean : a ≤ ∫ ω, q.row ω x ∂law p) - (hmoment : (∫ ω, q.row ω x ^ 2 ∂law p) / b ≤ a/4) - (hbad : b * (law p).real {ω | CappedBadGoodness G ω x M L} ≤ a/4) : - a / (2*b) ≤ (q.truncate b hb L).successProbability p x := by - have hh := q.truncate_mean_loss p b hb L x - apply (div_le_iff₀ (mul_pos (by norm_num) hb)).mpr - nlinarith - -end CappedLocalLoad -end TruncationLoss - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section CategoricalAmplificationInput -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def amplificationVertices (B : Finset V) (k : ℕ) (z : ↥B) (r : Fin k → ↥B) : ℕ → V := - fun i => (oldRunVertices k z r i).val - -namespace LocalEndpointRule -variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} - -noncomputable def amplificationWeight (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : ℝ := - oldRunWeight (fun i a b => q.mass (s.2 i) a.val b.val) k z r - -theorem amplificationWeight_eq (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : - q.amplificationWeight B k z s r = oldPathWeight k q.mass (amplificationVertices B k z r) s.2 := by - exact (oldPathWeight_oldRunVertices k (fun ω a b => q.mass ω a.val b.val) s.2 z r).symm - -theorem amplificationWeight_nonneg (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : - 0 ≤ q.amplificationWeight B k z s r := - oldRunWeight_nonneg (fun i (a b : ↥B) => q.mass (s.2 i) a.val b.val) - (fun i a b => q.nonneg (s.2 i) a.val b.val) k z r - -theorem amplificationWeight_row (q : LocalEndpointRule G hloc O M L) - (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) : - (∑ r, q.amplificationWeight B k z s r) ≤ 1 := by - have hr (i : ℕ) (a : ↥B) : (∑ b : ↥B, q.mass (s.2 i) a.val b.val) ≤ 1 := by - rw [Finset.sum_coe_sort B] - exact ((q.summable_mass _ _).sum_le_tsum B (fun y _ => q.nonneg _ _ y)).trans (q.row_le_one _ _) - simpa only [one_pow,amplificationWeight] using sum_oldRunWeight_le - (fun i (a b : ↥B) => q.mass (s.2 i) a.val b.val) - (fun _ a b => q.nonneg _ a.val b.val) 1 zero_le_one hr k z - - - -noncomputable def amplificationInputs (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) : Finset (SpliceState E) := - (finiteSpliceDomain Q (Finset.Icc 1 k)).filter fun s => - x ∈ O ∧ z.val ∈ O ∧ n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ - amplificationVertices B k z r 0 ∈ cluster G s.1 x ∧ q.amplificationWeight B k z s r ≠ 0 - -theorem mem_amplificationInputs (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) : - s ∈ q.amplificationInputs Q B x k n z r ↔ - s ∈ finiteSpliceDomain Q (Finset.Icc 1 k) ∧ - x ∈ O ∧ z.val ∈ O ∧ n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ - amplificationVertices B k z r 0 ∈ cluster G s.1 x ∧ q.amplificationWeight B k z s r ≠ 0 := - Finset.mem_filter - -theorem amplificationInputs_subset (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) : - q.amplificationInputs Q B x k n z r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k) := - Finset.filter_subset _ _ - -theorem amplificationInputs_chain (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) - (hs : s ∈ q.amplificationInputs Q B x k n z r) : - ∀ i, 1 ≤ i → i ≤ k → - Conn G (s.2 i) (amplificationVertices B k z r i) (amplificationVertices B k z r (i-1)) ∧ - (cluster G (s.2 i) (amplificationVertices B k z r i)).Finite ∧ - (cluster G (s.2 i) (amplificationVertices B k z r i)).ncard ≤ M ∧ - GoodForScale G (s.2 i) (amplificationVertices B k z r i) L := by - apply oldPathWeight_support G k M L q.mass - · intro ω a b h - exact (q.support ω a b h).2.2 - · exact (q.amplificationWeight_eq B k z s r) ▸ ((q.mem_amplificationInputs Q B x k n z r s).mp hs).2.2.2.2.2.2 - - - -theorem amplificationTrace_support (q : LocalEndpointRule G hloc O M L) - (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) - (hs : s ∈ q.amplificationInputs Q B x k n z r) (c : List (ℕ × E)) (ωf : Set E) - (ht : SpliceTrace G x s.2 (amplificationVertices B k z r) k 0 s.1 c ωf) : - x ∈ O ∧ z.val ∈ O ∧ Conn G ωf x z.val ∧ (cluster G ωf x).Finite ∧ - (cluster G ωf x).ncard ≤ 2*n+k*M := by - obtain ⟨hdom,hx,hz,_,hbin,_,_⟩ := (q.mem_amplificationInputs Q B x k n z r s).mp hs - have hc := q.amplificationInputs_chain Q B x k n z r s hs - have hroot : (cluster G s.1 x).Finite := - cluster_finite_of_finite_edges G (Q.finite_toSet.subset - ((mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s).mp hdom).1) x - obtain ⟨hf,hcap⟩ := trajectoryUnion_finite_cap G s.2 (amplificationVertices B k z r) k M - (fun i hi hik => ⟨(hc i hi hik).2.1,(hc i hi hik).2.2.1⟩) - have hsub : cluster G ωf x ⊆ cluster G s.1 x ∪ trajectoryUnion G s.2 (amplificationVertices B k z r) k := by - intro v hv - by_cases hv' : v ∈ cluster G s.1 x - · exact Or.inl hv' - · exact Or.inr (ht.added_subset_trajectory G x s.2 (amplificationVertices B k z r) k 0 s.1 ωf c ⟨hv,hv'⟩) - refine ⟨hx,hz,?_,(hroot.union hf).subset hsub,?_⟩ - · simpa only [amplificationVertices,oldRunVertices_last,cluster,Set.mem_ofPred_eq] using - ht.endpoint G x s.2 (amplificationVertices B k z r) k 0 s.1 ωf c - · exact (Set.ncard_le_ncard hsub (hroot.union hf)).trans - ((Set.ncard_union_le ..).trans (Nat.add_le_add (by omega) hcap)) - -end LocalEndpointRule -end CategoricalAmplificationInput - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Transport.TrajectoryMass + +namespace OAI + +/-! Endpoint Kernels for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section SeparatedTracePair +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_trace_pair_separated_le [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) + (Q : Finset E) (p : unitInterval) + (A₁ A₂ : Finset (SpliceState E)) (y₁ y₂ : (ℕ → Set E) → ℕ → V) + (m₁ m₂ : (ℕ → Set E) → ℝ) (hm₁ : ∀ η, 0 ≤ m₁ η) (hm₂ : ∀ η, 0 ≤ m₂ η) + (hA₁ : A₁ ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hA₂ : A₂ ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hbin : ∀ s ∈ A₁, (cluster G s.1 x).Finite ∧ n ≤ (cluster G s.1 x).ncard ∧ + (cluster G s.1 x).ncard < 2*n) + (hcap₁ : ∀ s ∈ A₁, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y₁ s.2 i)).Finite) + (hcap₂ : ∀ s ∈ A₂, ∀ i, 1 ≤ i → i ≤ k → (cluster G (s.2 i) (y₂ s.2 i)).Finite ∧ + (cluster G (s.2 i) (y₂ s.2 i)).ncard ≤ M) : + (∑ a : FiniteTraceIndex G x k Q A₁ (fun s => y₁ s.2), + ∑ b : FiniteTraceIndex G x k Q A₂ (fun s => y₂ s.2), + if (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 = + (traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) b).1 ∧ + a.2.val ≠ [] ∧ b.2.val ≠ [] ∧ + GraphSeparated G + (cluster G (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 x \ cluster G a.1.val.1 x) + (cluster G (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a).1 x \ cluster G b.1.val.1 x) + then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (pairSpliceOutput (traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) a) + (traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) b)) * + (m₁ a.1.val.2 * traceIndexMass G x k Q A₁ (fun s => y₁ s.2) a) * + (m₂ b.1.val.2 * traceIndexMass G x k Q A₂ (fun s => y₂ s.2) b) else 0) ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ η) k).Nonempty then m₁ η else 0) * + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => if + (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ η) k).Nonempty then m₂ η else 0) else 0) := by + let T₁ := FiniteTraceIndex G x k Q A₁ (fun s => y₁ s.2) + let T₂ := FiniteTraceIndex G x k Q A₂ (fun s => y₂ s.2) + let out₁ := traceIndexOutput G x k Q A₁ (fun s => y₁ s.2) + let out₂ := traceIndexOutput G x k Q A₂ (fun s => y₂ s.2) + let P (a : T₁ × T₂) := (out₁ a.1).1 = (out₂ a.2).1 ∧ a.1.2.val ≠ [] ∧ a.2.2.val ≠ [] ∧ + GraphSeparated G (cluster G (out₁ a.1).1 x \ cluster G a.1.1.val.1 x) + (cluster G (out₁ a.1).1 x \ cluster G a.2.1.val.1 x) + let I := {a : T₁ × T₂ // P a} + let η₁ (a : I) := a.val.1.1.val.2 + let η₂ (a : I) := a.val.2.1.val.2 + let ω₁ (a : I) := a.val.1.1.val.1 + let ω₂ (a : I) := a.val.2.1.val.1 + let ωf (a : I) := (out₁ a.val.1).1 + let c₁ (a : I) := a.val.1.2.val + let c₂ (a : I) := a.val.2.2.val + have hout (a : I) : jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) + (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a) = pairSpliceOutput (out₁ a.val.1) (out₂ a.val.2) := rfl + have hinj : Function.Injective (fun a : I => + (jointOutput G x (η₁ a) (η₂ a) (y₁ (η₁ a)) (y₂ (η₂ a)) (ω₁ a) (ω₂ a) (ωf a) (c₁ a) (c₂ a),c₁ a,c₂ a)) := by + intro a b he + dsimp only at he + rw [hout a,hout b] at he + have ho₁ : out₁ a.val.1 = out₁ b.val.1 := Prod.ext + (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.1) he) + (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.2.1) he) + have ho₂ : out₂ a.val.2 = out₂ b.val.2 := Prod.ext + (a.property.1.symm.trans ((congrArg Prod.fst ho₁).trans b.property.1)) + (congrArg (fun z : JointSpliceState E × List (ℕ × E) × List (ℕ × E) => z.1.2.2) he) + apply Subtype.ext + exact Prod.ext + (traceIndex_output_code_injective G x k Q A₁ (fun s => y₁ s.2) + (Prod.ext ho₁ (congrArg (fun z => z.2.1) he))) + (traceIndex_output_code_injective G x k Q A₂ (fun s => y₂ s.2) + (Prod.ext ho₂ (congrArg (fun z => z.2.2) he))) + have htr₁ (a : I) : SpliceTrace G x (η₁ a) (y₁ (η₁ a)) k 0 (ω₁ a) (c₁ a) (ωf a) := + (traceIndex_valid G x k Q A₁ (fun s => y₁ s.2) a.val.1).1 + have htr₂ (a : I) : SpliceTrace G x (η₂ a) (y₂ (η₂ a)) k 0 (ω₂ a) (c₂ a) (ωf a) := by + change SpliceTrace G x _ _ _ _ _ _ (out₁ a.val.1).1 + rw [a.property.1] + exact (traceIndex_valid G x k Q A₂ (fun s => y₂ s.2) a.val.2).1 + have hs₁ (a : I) := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp (hA₁ a.val.1.1.property) + have hs₂ (a : I) := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp (hA₂ a.val.2.1.property) + have hb := finite_separated_weighted_contact_second_moment_le G hloc x k n M p Q η₁ η₂ y₁ y₂ + (fun _ => True) (fun _ => True) m₁ m₂ hm₁ hm₂ ω₁ ω₂ ωf c₁ c₂ hinj htr₁ htr₂ + (fun a => a.property.2.1) (fun a => a.property.2.2.1) (fun a => a.property.2.2.2) + (fun a => hbin _ a.val.1.1.property) (fun a => hcap₁ _ a.val.1.1.property) + (fun a => hcap₂ _ a.val.2.1.property) (fun _ => trivial) (fun _ => trivial) + (fun a => (hs₁ a).1) (fun a => (hs₂ a).1) (fun a => (hs₁ a).2.1) + (fun a => (hs₂ a).2.1) (fun a => (hs₁ a).2.2) (fun a => (hs₂ a).2.2) + simp only [true_and] at hb + apply le_trans _ hb + let w (a : T₁ × T₂) := jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (pairSpliceOutput (out₁ a.1) (out₂ a.2)) * + (m₁ a.1.1.val.2 * traceIndexMass G x k Q A₁ (fun s => y₁ s.2) a.1) * + (m₂ a.2.1.val.2 * traceIndexMass G x k Q A₂ (fun s => y₂ s.2) a.2) + have he := Finset.sum_subtype (p := P) (F := inferInstance) (Finset.univ.filter P) + (by intro a; simp) w + rw [Finset.sum_filter,Fintype.sum_prod_type] at he + change (∑ a : T₁, ∑ b : T₂, if P (a,b) then w (a,b) else 0) ≤ _ + rw [he] + apply Finset.sum_le_sum + intro a _ + rw [hout a] + change w a.val ≤ _ + simp only [w,traceIndexMass,η₁,η₂,ωf,c₁,c₂,out₁,out₂] + rw [← a.property.1] + exact le_of_eq (by ring) + +end SeparatedTracePair + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ChoiceSeparatedMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable {P₁ P₂ : Type*} [Fintype P₁] [Fintype P₂] + + +noncomputable def finiteChoiceSeparatedPairMass + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) (p : ℝ) + (A₁ : P₁ → Finset (SpliceState E)) (A₂ : P₂ → Finset (SpliceState E)) + (y₁ : P₁ → (ℕ → Set E) → ℕ → V) (y₂ : P₂ → (ℕ → Set E) → ℕ → V) + (m₁ : P₁ → (ℕ → Set E) → ℝ) (m₂ : P₂ → (ℕ → Set E) → ℝ) : ℝ := + ∑ a : FiniteChoiceTraceIndex G x k Q A₁ (fun r s => y₁ r s.2), + ∑ b : FiniteChoiceTraceIndex G x k Q A₂ (fun r s => y₂ r s.2), + if (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 = + (choiceTraceOutput G x k Q A₂ (fun r s => y₂ r s.2) b).1 ∧ + choiceTraceCode G x k Q A₁ (fun r s => y₁ r s.2) a ≠ [] ∧ + choiceTraceCode G x k Q A₂ (fun r s => y₂ r s.2) b ≠ [] ∧ + GraphSeparated G + (cluster G (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x \ + cluster G (choiceTraceInput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x) + (cluster G (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a).1 x \ + cluster G (choiceTraceInput G x k Q A₂ (fun r s => y₂ r s.2) b).1 x) + then jointTupleWeight Q (Finset.Icc 1 k) (Finset.Icc 1 k) p + (pairSpliceOutput (choiceTraceOutput G x k Q A₁ (fun r s => y₁ r s.2) a) + (choiceTraceOutput G x k Q A₂ (fun r s => y₂ r s.2) b)) * + choiceTraceMass G x k Q A₁ (fun r s => y₁ r s.2) (fun s r => m₁ r s.2) a * + choiceTraceMass G x k Q A₂ (fun r s => y₂ r s.2) (fun s r => m₂ r s.2) b else 0 + + +noncomputable def finiteChoiceHit (G : BondGraph V E) (k : ℕ) (Q : Finset E) (p : ℝ) + (y : P₁ → (ℕ → Set E) → ℕ → V) (m : P₁ → (ℕ → Set E) → ℝ) (B : Set V) : ℝ := + ∑ r, finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + if (B ∩ trajectoryUnion G η (y r η) k).Nonempty then m r η else 0) + + + +theorem finiteChoiceSeparatedPairMass_le [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k n M : ℕ) + (Q : Finset E) (p : unitInterval) + (A₁ : P₁ → Finset (SpliceState E)) (A₂ : P₂ → Finset (SpliceState E)) + (y₁ : P₁ → (ℕ → Set E) → ℕ → V) (y₂ : P₂ → (ℕ → Set E) → ℕ → V) + (m₁ : P₁ → (ℕ → Set E) → ℝ) (m₂ : P₂ → (ℕ → Set E) → ℝ) + (hm₁ : ∀ r η, 0 ≤ m₁ r η) (hm₂ : ∀ r η, 0 ≤ m₂ r η) + (hA₁ : ∀ r, A₁ r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hA₂ : ∀ r, A₂ r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hbin : ∀ r s, s ∈ A₁ r → (cluster G s.1 x).Finite ∧ n ≤ (cluster G s.1 x).ncard ∧ + (cluster G s.1 x).ncard < 2*n) + (hcap₁ : ∀ r s, s ∈ A₁ r → ∀ i, 1 ≤ i → i ≤ k → + (cluster G (s.2 i) (y₁ r s.2 i)).Finite) + (hcap₂ : ∀ r s, s ∈ A₂ r → ∀ i, 1 ≤ i → i ≤ k → + (cluster G (s.2 i) (y₂ r s.2 i)).Finite ∧ (cluster G (s.2 i) (y₂ r s.2 i)).ncard ≤ M) : + finiteChoiceSeparatedPairMass G x k Q p A₁ A₂ y₁ y₂ m₁ m₂ ≤ + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n then + finiteChoiceHit G k Q p y₁ m₁ (cluster G (finiteFieldSet Q ω) x) * + finiteChoiceHit G k Q p y₂ m₂ (cluster G (finiteFieldSet Q ω) x) else 0) := by + let R (ω : FiniteField Q) := (cluster G (finiteFieldSet Q ω) x).Finite ∧ + n-k*M ≤ (cluster G (finiteFieldSet Q ω) x).ncard ∧ + (cluster G (finiteFieldSet Q ω) x).ncard < 2*n + let H₁ (r : P₁) (ω : FiniteField Q) := finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + if (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₁ r η) k).Nonempty then m₁ r η else 0) + let H₂ (r : P₂) (ω : FiniteField Q) := finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + if (cluster G (finiteFieldSet Q ω) x ∩ trajectoryUnion G η (y₂ r η) k).Nonempty then m₂ r η else 0) + have hb : finiteChoiceSeparatedPairMass G x k Q p A₁ A₂ y₁ y₂ m₁ m₂ ≤ + ∑ r : P₁, ∑ s : P₂, ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * + (if R ω then H₁ r ω * H₂ s ω else 0) := by + unfold finiteChoiceSeparatedPairMass + rw [Fintype.sum_sigma] + apply Finset.sum_le_sum + intro r _ + conv_lhs => arg 2; ext a; rw [Fintype.sum_sigma] + conv_lhs => rw [Finset.sum_comm] + simp only [choiceTraceOutput,choiceTraceInput,choiceTraceCode,choiceTraceMass, + traceIndexInput,traceIndexCode] + apply Finset.sum_le_sum + intro s _ + exact finite_trace_pair_separated_le G hloc x k n M Q p (A₁ r) (A₂ s) + (y₁ r) (y₂ s) (m₁ r) (m₂ s) (hm₁ r) (hm₂ s) (hA₁ r) (hA₂ s) + (hbin r) (hcap₁ r) (hcap₂ s) + apply hb.trans_eq + rw [Finset.sum_comm] + conv_lhs => arg 2; ext s; rw [Finset.sum_comm] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + change (∑ s : P₂, ∑ r : P₁, finiteFieldWeight Q p ω * (if R ω then H₁ r ω * H₂ s ω else 0)) = + finiteFieldWeight Q p ω * (if R ω then (∑ r : P₁, H₁ r ω) * (∑ s : P₂, H₂ s ω) else 0) + by_cases h : R ω + · simp only [ite_eq_left h,← Finset.mul_sum,← Finset.sum_mul] + · simp only [ite_eq_right h,mul_zero,Finset.sum_const_zero] + +end ChoiceSeparatedMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LocalEndpointRule +attribute [local instance] Classical.propDecidable Classical.decEq + + + +structure LocalEndpointRule (G : BondGraph V E) (hloc : LocallyFinite G) + (O : Set V) (M : ℕ) (L : ℝ) where + mass : Set E → V → V → ℝ + radius : ℕ + nonneg : ∀ ω x y, 0 ≤ mass ω x y + row_le_one : ∀ ω x, (∑' y, mass ω x y) ≤ 1 + support : ∀ ω x y, mass ω x y ≠ 0 → x ∈ O ∧ y ∈ O ∧ Conn G ω x y ∧ + (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L + locality : ∀ ω x y, mass ω x y = + mass (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x radius).toFinset : Set E)) x y + covariance : ∀ (a : V ≃ V) (b : E ≃ E), IsAut G a b → ∀ ω x y, + mass (b ⁻¹' ω) x y = mass ω (a x) (a y) + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +theorem outside_ball_zero (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) + (hy : y ∉ reachBall G x M) : q.mass ω x y = 0 := by + by_contra h + obtain ⟨_,_,hc,hfin,hcap,_⟩ := q.support ω x y h + exact hy (finite_cluster_subset_reachBall G ω x hfin M hcap hc) + +theorem summable_mass (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x : V) : + Summable (q.mass ω x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + apply q.outside_ball_zero ω x y + simpa only [Set.Finite.mem_toFinset] using hy + +theorem mass_le_one (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) : + q.mass ω x y ≤ 1 := by + have h := (q.summable_mass ω x).sum_le_tsum ({y} : Finset V) (fun z _ => q.nonneg ω x z) + simpa only [Finset.sum_singleton] using h.trans (q.row_le_one ω x) + + +theorem measurable_mass (q : LocalEndpointRule G hloc O M L) (x y : V) : + Measurable (fun ω => q.mass ω x y) := by + let Q := incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset + let f : Set (Q : Set E) → ℝ := fun η => q.mass (Subtype.val '' η) x y + have hm : Measurable f := measurable_of_finite f + have he : (fun ω => q.mass ω x y) = f ∘ (fun ω : Set E => Subtype.val ⁻¹' ω : Set E → Set (Q : Set E)) := by + funext ω + rw [q.locality ω x y] + congr 1 + ext e + simp [Q,and_comm] + rw [he] + exact hm.comp (measurable_set_restrict (Q : Set E)) + +theorem integrable_mass (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : + Integrable (fun ω => q.mass ω x y) (law p) := by + apply Integrable.of_bound (q.measurable_mass x y).aestronglyMeasurable 1 + exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs,abs_of_nonneg (q.nonneg ω x y)] using q.mass_le_one ω x y + + + +noncomputable def kernel (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : ℝ := + ∫ ω, q.mass ω x y ∂law p + +theorem kernel_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : + 0 ≤ q.kernel p x y := integral_nonneg (fun ω => q.nonneg ω x y) + +theorem kernel_outside_ball_zero (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) + (hy : y ∉ reachBall G x M) : q.kernel p x y = 0 := by + simp only [kernel,q.outside_ball_zero _ x y hy,integral_zero] + +theorem summable_kernel (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + Summable (q.kernel p x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + apply q.kernel_outside_ball_zero p x y + simpa only [Set.Finite.mem_toFinset] using hy + + + +theorem kernel_row_integral (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + (∑' y, q.kernel p x y) = ∫ ω, (∑' y, q.mass ω x y) ∂law p := by + let B := (finite_reachBall hloc x M).toFinset + have h₁ : (∑' y, q.kernel p x y) = ∑ y ∈ B, q.kernel p x y := + tsum_eq_sum fun y hy => q.kernel_outside_ball_zero p x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + have h₂ (ω : Set E) : (∑' y, q.mass ω x y) = ∑ y ∈ B, q.mass ω x y := + tsum_eq_sum fun y hy => q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + rw [h₁] + simp_rw [h₂] + exact (integral_finsetSum B (fun y _ => q.integrable_mass p x y)).symm + +theorem kernel_row_le_one (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + (∑' y, q.kernel p x y) ≤ 1 := by + rw [q.kernel_row_integral p x] + have hi : Integrable (fun ω => ∑' y, q.mass ω x y) (law p) := by + let B := (finite_reachBall hloc x M).toFinset + have he (ω : Set E) : (∑' y, q.mass ω x y) = ∑ y ∈ B, q.mass ω x y := + tsum_eq_sum fun y hy => q.outside_ball_zero ω x y (by simpa only [B,Set.Finite.mem_toFinset] using hy) + simp_rw [he] + exact integrable_finsetSum B (fun y _ => q.integrable_mass p x y) + calc + _ ≤ ∫ _, (1:ℝ) ∂law p := integral_mono hi (integrable_const _) (q.row_le_one · x) + _ = 1 := by simp + +end LocalEndpointRule +end LocalEndpointRule + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section LocalEndpointKernel +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +theorem outside_reverse_ball_zero (q : LocalEndpointRule G hloc O M L) (ω : Set E) (x y : V) + (hx : x ∉ reachBall G y M) : q.mass ω x y = 0 := by + by_contra h + obtain ⟨_,_,hc,hfin,hcap,_⟩ := q.support ω x y h + have he := cluster_eq_of_conn G ω hc + rw [he] at hfin hcap + exact hx (finite_cluster_subset_reachBall G ω y hfin M hcap (conn_symm G ω hc)) + +theorem kernel_outside_reverse_ball_zero (q : LocalEndpointRule G hloc O M L) + (p : unitInterval) (x y : V) (hx : x ∉ reachBall G y M) : q.kernel p x y = 0 := by + simp only [kernel,q.outside_reverse_ball_zero _ x y hx,integral_zero] + +theorem summable_kernel_column (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (y : V) : + Summable (fun x => q.kernel p x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y M).toFinset) + intro x hx + apply q.kernel_outside_reverse_ball_zero p x y + simpa only [Set.Finite.mem_toFinset] using hx + +theorem mass_zero_of_start_not_mem (q : LocalEndpointRule G hloc O M L) (ω : Set E) + (x y : V) (hx : x ∉ O) : q.mass ω x y = 0 := by + by_contra h + exact hx (q.support ω x y h).1 + +theorem mass_zero_of_end_not_mem (q : LocalEndpointRule G hloc O M L) (ω : Set E) + (x y : V) (hy : y ∉ O) : q.mass ω x y = 0 := by + by_contra h + exact hy (q.support ω x y h).2.1 + +theorem kernel_zero_of_start_not_mem (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (x y : V) (hx : x ∉ O) : q.kernel p x y = 0 := by + simp only [kernel,q.mass_zero_of_start_not_mem _ x y hx,integral_zero] + +theorem kernel_zero_of_end_not_mem (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (x y : V) (hy : y ∉ O) : q.kernel p x y = 0 := by + simp only [kernel,q.mass_zero_of_end_not_mem _ x y hy,integral_zero] + + + +theorem kernel_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x y : V) : + q.kernel p (a x) (a y) = q.kernel p x y := by + have h := integral_map (μ := law p) (measurable_set_preimage b).aemeasurable + (q.measurable_mass x y).aestronglyMeasurable + rw [law_map_preimage_equiv p b] at h + simpa only [kernel,q.covariance a b ha] using h.symm + +noncomputable def successProbability (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : ℝ := + ∑' y, q.kernel p x y + +theorem successProbability_nonneg (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + 0 ≤ q.successProbability p x := tsum_nonneg (q.kernel_nonneg p x) + +theorem successProbability_le_one (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x : V) : + q.successProbability p x ≤ 1 := q.kernel_row_le_one p x + +theorem successProbability_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (x : V) : + q.successProbability p (a x) = q.successProbability p x := by + unfold successProbability + rw [← a.tsum_eq (fun y => q.kernel p (a x) y)] + exact tsum_congr (q.kernel_covariant p a b ha x) + +theorem successProbability_orbit (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (o x : V) (hx : x ∈ vertexOrbit G o) : q.successProbability p x = q.successProbability p o := by + obtain ⟨a,b,ha,rfl⟩ := hx + exact q.successProbability_covariant p a b ha o + +theorem kernel_column_covariant (q : LocalEndpointRule G hloc O M L) (p : unitInterval) + (a : V ≃ V) (b : E ≃ E) (ha : IsAut G a b) (y : V) : + (∑' x, q.kernel p x (a y)) = ∑' x, q.kernel p x y := by + rw [← a.tsum_eq (fun x => q.kernel p x (a y))] + exact tsum_congr (fun x => q.kernel_covariant p a b ha x y) + +end LocalEndpointRule +end LocalEndpointKernel + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EndpointTransport +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + + + +theorem kernel_column_orbit (o : V) (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) + (p : unitInterval) (y : V) (hy : y ∈ vertexOrbit G o) : + (∑' x, q.kernel p x y) = ∑' x, q.kernel p x o := by + obtain ⟨a,b,ha,rfl⟩ := hy + exact q.kernel_column_covariant p a b ha o + + + +theorem kernel_column_eq_success {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (p : unitInterval) (y : V) (hy : y ∈ vertexOrbit G (root i₀)) : + (∑' x, q.kernel p x y) = q.successProbability p (root i₀) := by + let O := vertexOrbit G (root i₀) + let w : ι → ℝ := fun i => if root i ∈ O then weight i else 0 + have ho : root i₀ ∈ O := by + refine ⟨Equiv.refl V,Equiv.refl E,?_,rfl⟩ + intro e + simp + have hw' (i : ι) : 0 ≤ w i := by + dsimp [w] + split_ifs + · exact hw i + · exact le_rfl + have hpos : 0 < ∑ i, w i := by + have hi : w i₀ ≤ ∑ i, w i := Finset.single_le_sum (fun i _ => hw' i) (Finset.mem_univ i₀) + have he : w i₀ = weight i₀ := ite_eq_left ho + rw [he] at hi + exact hw₀.trans_le hi + have ht := htr.real root weight Γ (q.kernel p) + (by intro a ha x z; obtain ⟨b,hb⟩ := hΓ a ha; exact q.kernel_covariant p a b hb x z) + (q.summable_kernel p) (q.summable_kernel_column p) + have hr (i : ι) : weight i * (∑' z, q.kernel p (root i) z) = + w i * q.successProbability p (root i₀) := by + by_cases hi : root i ∈ O + · have he := q.successProbability_orbit p (root i₀) (root i) hi + change weight i * q.successProbability p (root i) = _ + rw [he] + simp only [w,ite_eq_left hi] + · simp only [w,ite_eq_right hi,zero_mul] + have he : (∑' z, q.kernel p (root i) z) = 0 := by + simp only [q.kernel_zero_of_start_not_mem p _ _ hi,tsum_zero] + rw [he,mul_zero] + have hc (i : ι) : weight i * (∑' x, q.kernel p x (root i)) = + w i * (∑' x, q.kernel p x (root i₀)) := by + by_cases hi : root i ∈ O + · rw [q.kernel_column_orbit (root i₀) p (root i) hi] + simp only [w,ite_eq_left hi] + · simp only [w,ite_eq_right hi,zero_mul] + have he : (∑' x, q.kernel p x (root i)) = 0 := by + simp only [q.kernel_zero_of_end_not_mem p _ _ hi,tsum_zero] + rw [he,mul_zero] + simp_rw [hr,hc] at ht + rw [← Finset.sum_mul,← Finset.sum_mul] at ht + rw [q.kernel_column_orbit (root i₀) p y hy] + exact (mul_left_cancel₀ (ne_of_gt hpos) ht).symm + + +theorem kernel_column_le_success {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (p : unitInterval) (y : V) : + (∑' x, q.kernel p x y) ≤ q.successProbability p (root i₀) := by + by_cases hy : y ∈ vertexOrbit G (root i₀) + · exact (q.kernel_column_eq_success root weight Γ htr hΓ hw i₀ hw₀ p y hy).le + · simpa only [q.kernel_zero_of_end_not_mem p _ _ hy,tsum_zero] using + q.successProbability_nonneg p (root i₀) + +end LocalEndpointRule +end EndpointTransport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EndpointSchur +attribute [local instance] Classical.propDecidable Classical.decEq +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {M : ℕ} {L : ℝ} + +theorem kernel_row_le_success (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) (x : V) : + (∑' y, q.kernel p x y) ≤ q.successProbability p o := by + by_cases hx : x ∈ vertexOrbit G o + · exact (q.successProbability_orbit p o x hx).le + · simpa only [q.kernel_zero_of_start_not_mem p _ _ hx,tsum_zero] using + q.successProbability_nonneg p o + + +noncomputable def normalizedKernel (o : V) + (q : LocalEndpointRule G hloc (vertexOrbit G o) M L) (p : unitInterval) (x y : V) : ℝ := + (q.successProbability p o)⁻¹ * q.kernel p x y + + + +theorem exists_normalized_operator {ι : Type*} [Fintype ι] + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hΓ : ∀ a ∈ Γ, ∃ b, IsAut G a b) (hw : ∀ i, 0 ≤ weight i) + (i₀ : ι) (hw₀ : 0 < weight i₀) + (q : LocalEndpointRule G hloc (vertexOrbit G (root i₀)) M L) + (p : unitInterval) (hu : 0 < q.successProbability p (root i₀)) : + ∃ A : Hilbert V →L[ℂ] Hilbert V, 0 < ‖A‖ ∧ ‖A‖ ≤ 1 ∧ + ∀ x y, A (lp.single 2 y (1:ℂ)) x = (q.normalizedKernel (root i₀) p x y : ℂ) := by + let u := q.successProbability p (root i₀) + have hu₀ : u ≠ 0 := ne_of_gt hu + have hn (x y : V) : 0 ≤ q.normalizedKernel (root i₀) p x y := + mul_nonneg (inv_nonneg.mpr hu.le) (q.kernel_nonneg p x y) + have hr (x : V) (S : Finset V) : (∑ y ∈ S, q.normalizedKernel (root i₀) p x y) ≤ 1 := by + change (∑ y ∈ S, u⁻¹ * q.kernel p x y) ≤ 1 + rw [← Finset.mul_sum] + calc + _ ≤ u⁻¹ * (∑' y, q.kernel p x y) := mul_le_mul_of_nonneg_left + ((q.summable_kernel p x).sum_le_tsum S (fun y _ => q.kernel_nonneg p x y)) (inv_nonneg.mpr hu.le) + _ ≤ u⁻¹ * u := mul_le_mul_of_nonneg_left + (q.kernel_row_le_success (root i₀) p x) (inv_nonneg.mpr hu.le) + _ = 1 := inv_mul_cancel₀ hu₀ + have hc (y : V) (S : Finset V) : (∑ x ∈ S, q.normalizedKernel (root i₀) p x y) ≤ 1 := by + change (∑ x ∈ S, u⁻¹ * q.kernel p x y) ≤ 1 + rw [← Finset.mul_sum] + calc + _ ≤ u⁻¹ * (∑' x, q.kernel p x y) := mul_le_mul_of_nonneg_left + ((q.summable_kernel_column p y).sum_le_tsum S (fun x _ => q.kernel_nonneg p x y)) (inv_nonneg.mpr hu.le) + _ ≤ u⁻¹ * u := mul_le_mul_of_nonneg_left + (q.kernel_column_le_success root weight Γ htr hΓ hw i₀ hw₀ p y) (inv_nonneg.mpr hu.le) + _ = 1 := inv_mul_cancel₀ hu₀ + obtain ⟨A,hA,hK⟩ := exists_operator_of_row_column_bound (q.normalizedKernel (root i₀) p) 1 (by norm_num) hn hr hc + refine ⟨A,?_,hA,hK⟩ + apply norm_pos_iff.mpr + intro ha + have hz (y : V) : q.kernel p (root i₀) y = 0 := by + have h := hK (root i₀) y + rw [ha] at h + have he : u⁻¹ * q.kernel p (root i₀) y = 0 := Complex.ofReal_eq_zero.mp h.symm + exact (mul_eq_zero.mp he).resolve_left (inv_ne_zero hu₀) + have he : u = 0 := by simp only [u,successProbability,hz,tsum_zero] + exact hu₀ he + +end LocalEndpointRule +end EndpointSchur + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory ProbabilityTheory +section FiniteLocalIntegral +attribute [local instance] Classical.propDecidable Classical.decEq + + + +noncomputable def finiteFieldEquiv (Q : Finset E) : FiniteField Q ≃ Set (Q : Set E) where + toFun ω := Subtype.val ⁻¹' finiteFieldSet Q ω + invFun η := ⟨η.toFinset.map ⟨Subtype.val,Subtype.val_injective⟩, by + apply Finset.mem_powerset.mpr + intro e he + obtain ⟨a,_,rfl⟩ := Finset.mem_map.mp he + exact a.property⟩ + left_inv ω := by + apply Subtype.ext + apply Finset.coe_injective + ext e + simp only [Finset.coe_map,Set.mem_image,finiteFieldSet,Function.Embedding.coeFn_mk] + constructor + · rintro ⟨a,ha,rfl⟩ + have ha' : a ∈ (Subtype.val ⁻¹' (ω.val : Set E) : Set (Q : Set E)) := Set.mem_toFinset.mp ha + exact ha' + · intro he + exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,Set.mem_toFinset.mpr he,rfl⟩ + right_inv η := by + ext e + simp only [Set.mem_preimage,finiteFieldSet,Finset.coe_map,Set.coe_toFinset, + Set.mem_image,Function.Embedding.coeFn_mk,Subtype.val_injective.eq_iff,exists_eq_right] + +@[simp] theorem finiteFieldEquiv_apply (Q : Finset E) (ω : FiniteField Q) : + finiteFieldEquiv Q ω = Subtype.val ⁻¹' finiteFieldSet Q ω := rfl + +@[simp] theorem finiteFieldEquiv_image (Q : Finset E) (ω : FiniteField Q) : + Subtype.val '' finiteFieldEquiv Q ω = finiteFieldSet Q ω := by + rw [finiteFieldEquiv_apply] + apply Set.image_preimage_eq_of_subset + intro e he + exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,rfl⟩ + + + +theorem finiteFieldWeight_eq_atom (Q : Finset E) (p : unitInterval) (ω : FiniteField Q) : + finiteFieldWeight Q p ω = (law p : Measure (Set (Q : Set E))).real {finiteFieldEquiv Q ω} := by + have hn : (finiteFieldEquiv Q ω).ncard = ω.val.card := by + rw [finiteFieldEquiv_apply,Set.ncard_preimage_of_injective_subset_range Subtype.val_injective] + · exact Set.ncard_coe_finset _ + · intro e he + exact ⟨⟨e,Finset.mem_powerset.mp ω.property he⟩,rfl⟩ + rw [law,setBernoulli_real_singleton p (Set.subset_univ _) Set.finite_univ, + Set.ncard_sdiff' (Set.subset_univ _) Set.finite_univ,hn] + have hc : Fintype.card (Q : Set E) = Q.card := Fintype.card_coe Q + simp only [finiteFieldWeight,bernoulliWeight,Set.ncard_univ,Nat.card_eq_fintype_card,hc] + + + +theorem integral_finite_local (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : + (∫ ω, f ω ∂law p) = ∑ η : FiniteField Q, finiteFieldWeight Q p η * f (finiteFieldSet Q η) := by + let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) + have hmap := integral_map (μ := law p) (measurable_set_restrict (Q : Set E)).aemeasurable + (measurable_of_finite g).aestronglyMeasurable + rw [law_map_restrict p (Q : Set E)] at hmap + have he (ω : Set E) : g (Subtype.val ⁻¹' ω) = f ω := by + rw [hf ω] + dsimp [g] + congr 1 + ext e + simp [and_comm] + simp_rw [he] at hmap + rw [← hmap,integral_fintype Integrable.of_finite] + rw [← (finiteFieldEquiv Q).sum_comp] + apply Finset.sum_congr rfl + intro η _ + rw [← finiteFieldWeight_eq_atom] + simp only [g,finiteFieldEquiv_image,smul_eq_mul] + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + + + +theorem kernel_finite_sum (q : LocalEndpointRule G hloc O M L) (p : unitInterval) (x y : V) : + let Q := incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset + q.kernel p x y = ∑ η : FiniteField Q, finiteFieldWeight Q p η * q.mass (finiteFieldSet Q η) x y := + integral_finite_local _ p (fun ω => q.mass ω x y) (fun ω => q.locality ω x y) + +theorem continuous_kernel (q : LocalEndpointRule G hloc O M L) (x y : V) : + Continuous (fun p : unitInterval => q.kernel p x y) := by + simp_rw [q.kernel_finite_sum] + apply continuous_finsetSum + intro η _ + unfold finiteFieldWeight bernoulliWeight + fun_prop + +theorem continuous_successProbability (q : LocalEndpointRule G hloc O M L) (x : V) : + Continuous (fun p : unitInterval => q.successProbability p x) := by + have he (p : unitInterval) : q.successProbability p x = + ∑ y ∈ (finite_reachBall hloc x M).toFinset, q.kernel p x y := by + apply tsum_eq_sum + intro y hy + exact q.kernel_outside_ball_zero p x y (by simpa only [Set.Finite.mem_toFinset] using hy) + simp_rw [he] + exact continuous_finsetSum _ (fun y _ => q.continuous_kernel x y) + +end LocalEndpointRule +end FiniteLocalIntegral + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section GoodnessCovariance +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem internalEdges_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (W : Set V) : + internalEdges G (a ⁻¹' W) = b ⁻¹' internalEdges G W := by + ext e + simp only [internalEdges,Set.mem_ofPred_eq,Set.mem_preimage,hab e,Sym2.mem_map] + constructor + · intro h y hy + obtain ⟨z,hz,rfl⟩ := hy + exact h z hz + · intro h z hz + exact h (a z) ⟨z,hz,rfl⟩ + +theorem cutExists_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (W : Set V) (e : E) : + CutExists G (a ⁻¹' W) e ↔ CutExists G W (b e) := by + constructor + · rintro ⟨u,v,he,hu,hv⟩ + exact ⟨a u,a v,by rw [hab e,he,Sym2.map_mk],hu,hv⟩ + · rintro ⟨u,v,he,hu,hv⟩ + refine ⟨a.symm u,a.symm v,?_,by simpa using hu,by simpa using hv⟩ + have h := congrArg (Sym2.map a.symm) he + simpa only [hab e,Sym2.map_map,Equiv.symm_comp_self,id_eq,Sym2.map_id',Sym2.map_mk] using h + +theorem contactSet_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (W : Set V) : + contactSet G (b ⁻¹' ω) (a ⁻¹' W) = b ⁻¹' contactSet G ω W := by + ext e + simp only [contactSet,Set.mem_ofPred_eq,Set.mem_preimage,cutExists_aut_preimage G hab] + +theorem openMarkedPivotal_pair_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) (e : E) : + OpenMarkedPivotal G (b ⁻¹' ω) {y} x e ↔ + OpenMarkedPivotal G ω {a y} (a x) (b e) := by + have he : (b ⁻¹' ω) \ {e} = b ⁻¹' (ω \ {b e}) := by + ext f + simp only [Set.mem_sdiff,Set.mem_preimage,Set.mem_singleton_iff,b.injective.eq_iff] + simp only [OpenMarkedPivotal,MarkedEvent,Set.mem_singleton_iff,exists_eq_left, + Set.mem_preimage,he,conn_aut_iff G hab] + +theorem pivotalDistance_aut_preimage (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x y : V) : + pivotalDistance G (b ⁻¹' ω) x y = pivotalDistance G ω (a x) (a y) := by + have he : {e | OpenMarkedPivotal G (b ⁻¹' ω) {y} x e} = + b ⁻¹' {e | OpenMarkedPivotal G ω {a y} (a x) e} := by + ext e + exact openMarkedPivotal_pair_aut G hab ω x y e + rw [pivotalDistance,he,Set.ncard_preimage_of_injective_subset_range b.injective] + · rfl + · exact fun e _ => b.surjective e + +theorem goodForScale_aut_pullback (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) (L : ℝ) + (hg : GoodForScale G ω (a x) L) : GoodForScale G (b ⁻¹' ω) x L := by + intro W hW hconn hpos u hu v hv + let W' := W.map a.toEmbedding + have hpre : a ⁻¹' (W' : Set V) = (W : Set V) := by + ext z + simp [W'] + have hcfg : b ⁻¹' (ω ∩ internalEdges G (W' : Set V)) = + (b ⁻¹' ω) ∩ internalEdges G (W : Set V) := by + rw [Set.preimage_inter,← internalEdges_aut_preimage G hab,hpre] + have hcontact : (contactSet G (b ⁻¹' ω) (W : Set V)).ncard = + (contactSet G ω (W' : Set V)).ncard := by + rw [← hpre,contactSet_aut_preimage G hab, + Set.ncard_preimage_of_injective_subset_range b.injective] + exact fun e _ => b.surjective e + have hW' : (W' : Set V) ⊆ cluster G ω (a x) := by + intro z hz + obtain ⟨w,hw,rfl⟩ := Finset.mem_map.mp hz + exact (conn_aut_iff G hab ω x w).mp (hW hw) + have hc' : ∀ w ∈ W', ∀ z ∈ W', Conn G (ω ∩ internalEdges G (W' : Set V)) w z := by + intro w hw z hz + obtain ⟨u,hu,rfl⟩ := Finset.mem_map.mp hw + obtain ⟨v,hv,rfl⟩ := Finset.mem_map.mp hz + apply (conn_aut_iff G hab _ u v).mp + rw [hcfg] + exact hconn u hu v hv + have H := hg W' hW' hc' (by rwa [← hcontact]) (a u) + (Finset.mem_map.mpr ⟨u,hu,rfl⟩) (a v) (Finset.mem_map.mpr ⟨v,hv,rfl⟩) + rw [← pivotalDistance_aut_preimage G hab,hcfg,← hcontact] at H + exact H + +theorem goodForScale_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) (L : ℝ) : + GoodForScale G (b ⁻¹' ω) x L ↔ GoodForScale G ω (a x) L := by + constructor + · intro h + have H := goodForScale_aut_pullback G (isAut_symm G hab) (b ⁻¹' ω) (a x) L + (by simpa only [Equiv.symm_apply_apply] using h) + simpa only [← Set.preimage_comp,Equiv.self_comp_symm,Set.preimage_id_eq,id_eq] using H + · exact goodForScale_aut_pullback G hab ω x L + +end GoodnessCovariance + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CappedGoodLocality +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem measurable_finite_local (Q : Finset E) (f : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : Measurable f := by + let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) + have he : f = g ∘ (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) := by + funext ω + rw [hf ω] + congr 1 + ext e + simp [and_comm] + rw [he] + exact (measurable_of_finite g).comp (measurable_set_restrict (Q : Set E)) + +theorem integrable_finite_local (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) : Integrable f (law p) := by + let g : Set (Q : Set E) → ℝ := fun η => f (Subtype.val '' η) + have he : f = g ∘ (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) := by + funext ω + rw [hf ω] + congr 1 + ext e + simp [and_comm] + have hi : Integrable g (Measure.map (fun ω : Set E => (Subtype.val ⁻¹' ω : Set (Q : Set E))) (law p)) := by + rw [law_map_restrict] + exact Integrable.of_finite + rw [he] + exact hi.comp_measurable (measurable_set_restrict (Q : Set E)) + +def CappedGoodness (G : BondGraph V E) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : Prop := + (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M ∧ GoodForScale G ω x L + +theorem cappedGoodness_local (G : BondGraph V E) (hloc : LocallyFinite G) + (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : + let Q := incidentSupport G hloc (finite_reachBall hloc x M).toFinset + CappedGoodness G ω x M L ↔ CappedGoodness G (ω ∩ (Q : Set E)) x M L := by + have he (η : Set E) : CappedGoodness G η x M L ↔ + ((cluster G η x).Finite ∧ (cluster G η x).ncard ≤ M) ∧ ¬CappedBadGoodness G η x M L := by + constructor + · rintro ⟨hf,hM,hg⟩ + exact ⟨⟨hf,hM⟩,fun h => h.2.2 hg⟩ + · rintro ⟨⟨hf,hM⟩,hbad⟩ + refine ⟨hf,hM,?_⟩ + by_contra hn + exact hbad ⟨hf,hM,hn⟩ + dsimp only + have hbad := cappedBadGoodness_local G hloc x M L ω + have hcap := capped_cluster_local G hloc x M ω + dsimp only at hbad hcap + rw [he,he,hbad,hcap] + +theorem cappedGoodness_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) (M : ℕ) (L : ℝ) : + CappedGoodness G (b ⁻¹' ω) x M L ↔ CappedGoodness G ω (a x) M L := by + have hf : (cluster G (b ⁻¹' ω) x).Finite ↔ (cluster G ω (a x)).Finite := by + rw [← cluster_aut G hab ω x] + exact (Set.finite_image_iff a.injective.injOn).symm + have hn : (cluster G (b ⁻¹' ω) x).ncard = (cluster G ω (a x)).ncard := by + rw [← cluster_aut G hab ω x,Set.ncard_image_of_injective _ a.injective] + simp only [CappedGoodness,hf,hn,goodForScale_aut_iff G hab] + +theorem incidentSupport_ball_mono (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) {r R : ℕ} (h : r ≤ R) : + incidentSupport G hloc (finite_reachBall hloc x r).toFinset ⊆ + incidentSupport G hloc (finite_reachBall hloc x R).toFinset := by + apply incidentSupport_mono + intro z hz + simp only [Set.Finite.mem_toFinset] at hz ⊢ + exact reachBall_mono_local G x h hz + +theorem finite_local_of_subset (Q S : Finset E) (hQS : Q ⊆ S) (f : Set E → ℝ) + (hf : ∀ ω, f ω = f (ω ∩ (Q : Set E))) (ω : Set E) : + f ω = f (ω ∩ (S : Set E)) := by + rw [hf ω,hf (ω ∩ (S : Set E))] + congr 1 + exact (Set.inter_assoc _ _ _).trans (congrArg (ω ∩ ·) (Set.inter_eq_right.mpr hQS)) |>.symm + +end CappedGoodLocality + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section CappedLocalLoad +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem finite_prop_local_of_subset (Q S : Finset E) (hQS : Q ⊆ S) (P : Set E → Prop) + (hf : ∀ ω, P ω ↔ P (ω ∩ (Q : Set E))) (ω : Set E) : + P ω ↔ P (ω ∩ (S : Set E)) := by + have he : (ω ∩ (S : Set E)) ∩ (Q : Set E) = ω ∩ (Q : Set E) := + (Set.inter_assoc _ _ _).trans (congrArg (ω ∩ ·) (Set.inter_eq_right.mpr hQS)) + exact (hf ω).trans ((he ▸ hf (ω ∩ (S : Set E))).symm) + + + +structure CappedLocalLoad (G : BondGraph V E) (hloc : LocallyFinite G) (O : Set V) (M : ℕ) where + mass : Set E → V → V → ℝ + radius : ℕ + nonneg : ∀ ω x y, 0 ≤ mass ω x y + support : ∀ ω x y, mass ω x y ≠ 0 → x ∈ O ∧ y ∈ O ∧ Conn G ω x y ∧ + (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M + locality : ∀ ω x y, mass ω x y = + mass (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x radius).toFinset : Set E)) x y + covariance : ∀ (a : V ≃ V) (b : E ≃ E), IsAut G a b → ∀ ω x y, + mass (b ⁻¹' ω) x y = mass ω (a x) (a y) + +namespace CappedLocalLoad +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} + +noncomputable def row (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : ℝ := + ∑' y, q.mass ω x y + +theorem row_nonneg (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : 0 ≤ q.row ω x := + tsum_nonneg (q.nonneg ω x) + +theorem outside_ball_zero (q : CappedLocalLoad G hloc O M) (ω : Set E) (x y : V) + (hy : y ∉ reachBall G x M) : q.mass ω x y = 0 := by + by_contra h + obtain ⟨_,_,hc,hfin,hcap⟩ := q.support ω x y h + exact hy (finite_cluster_subset_reachBall G ω x hfin M hcap hc) + +theorem summable_mass (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : + Summable (q.mass ω x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x M).toFinset) + intro y hy + exact q.outside_ball_zero ω x y (by simpa only [Set.Finite.mem_toFinset] using hy) + +theorem mass_le_row (q : CappedLocalLoad G hloc O M) (ω : Set E) (x y : V) : + q.mass ω x y ≤ q.row ω x := by + simpa only [Finset.sum_singleton,row] using + (q.summable_mass ω x).sum_le_tsum {y} (fun z _ => q.nonneg ω x z) + +theorem row_locality (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) : + q.row ω x = q.row + (ω ∩ (incidentSupport G hloc (finite_reachBall hloc x q.radius).toFinset : Set E)) x := + tsum_congr (q.locality ω x) + +theorem row_covariance (q : CappedLocalLoad G hloc O M) (a : V ≃ V) (b : E ≃ E) + (hab : IsAut G a b) (ω : Set E) (x : V) : q.row (b ⁻¹' ω) x = q.row ω (a x) := by + unfold row + simp_rw [q.covariance a b hab] + exact a.tsum_eq _ + +theorem integrable_mass (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x y : V) : + Integrable (fun ω => q.mass ω x y) (law p) := + integrable_finite_local _ p _ (q.locality · x y) + +theorem integrable_row (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x : V) : + Integrable (fun ω => q.row ω x) (law p) := + integrable_finite_local _ p _ (q.row_locality · x) + +theorem integrable_sq_row (q : CappedLocalLoad G hloc O M) (p : unitInterval) (x : V) : + Integrable (fun ω => q.row ω x ^ 2) (law p) := + integrable_finite_local _ p _ (fun ω => congrArg (· ^ 2) (q.row_locality ω x)) + + + +noncomputable def truncate (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) (L : ℝ) : + LocalEndpointRule G hloc O M L where + mass ω x y := if q.row ω x ≤ b ∧ CappedGoodness G ω x M L then b⁻¹ * q.mass ω x y else 0 + radius := max q.radius M + nonneg ω x y := by split_ifs; exact mul_nonneg (inv_nonneg.mpr hb.le) (q.nonneg ω x y); rfl + row_le_one ω x := by + by_cases h : q.row ω x ≤ b ∧ CappedGoodness G ω x M L + · simp only [h,and_self,ite_true,tsum_mul_left] + exact (mul_le_mul_of_nonneg_left h.1 (inv_nonneg.mpr hb.le)).trans_eq (inv_mul_cancel₀ hb.ne') + · simp only [h,ite_false,tsum_zero,zero_le_one] + support ω x y h := by + split_ifs at h with hkeep + · have hm : q.mass ω x y ≠ 0 := fun he => h (by rw [he,mul_zero]) + obtain ⟨hx,hy,hc,_,_⟩ := q.support ω x y hm + exact ⟨hx,hy,hc,hkeep.2⟩ + · exact (h rfl).elim + locality ω x y := by + let S := incidentSupport G hloc (finite_reachBall hloc x (max q.radius M)).toFinset + have hm := finite_local_of_subset _ S + (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) + (fun η => q.mass η x y) (q.locality · x y) ω + have hr := finite_local_of_subset _ S + (incidentSupport_ball_mono G hloc x (le_max_left q.radius M)) + (fun η => q.row η x) (q.row_locality · x) ω + have hg := finite_prop_local_of_subset _ S + (incidentSupport_ball_mono G hloc x (le_max_right q.radius M)) + (fun η => CappedGoodness G η x M L) (fun η => cappedGoodness_local G hloc η x M L) ω + simp only [hm,hr,hg] + rfl + covariance a c hac ω x y := by + simp only [q.row_covariance a c hac,q.covariance a c hac,cappedGoodness_aut_iff G hac] + +end CappedLocalLoad +end CappedLocalLoad + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +open MeasureTheory +section TruncationLoss +attribute [local instance] Classical.propDecidable Classical.decEq +namespace CappedLocalLoad +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} + +theorem cap_of_row_ne_zero (q : CappedLocalLoad G hloc O M) (ω : Set E) (x : V) + (hr : q.row ω x ≠ 0) : (cluster G ω x).Finite ∧ (cluster G ω x).ncard ≤ M := by + obtain ⟨y,hy⟩ : ∃ y, q.mass ω x y ≠ 0 := by + by_contra hn + push Not at hn + exact hr (by simp only [row,hn,tsum_zero]) + exact (q.support ω x y hy).2.2.2 + +theorem truncate_scaled_row (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) + (L : ℝ) (ω : Set E) (x : V) : + b * (∑' y, (q.truncate b hb L).mass ω x y) = + if q.row ω x ≤ b ∧ CappedGoodness G ω x M L then q.row ω x else 0 := by + by_cases h : q.row ω x ≤ b ∧ CappedGoodness G ω x M L + · simp only [truncate,ite_eq_left h,tsum_mul_left,← mul_assoc,mul_inv_cancel₀ hb.ne',one_mul] + rfl + · simp only [truncate,ite_eq_right h,tsum_zero,mul_zero] + +theorem truncate_mass_le (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) + (L : ℝ) (ω : Set E) (x y : V) : + (q.truncate b hb L).mass ω x y ≤ b⁻¹ * q.mass ω x y := by + change (if _ then _ else _) ≤ _ + split_ifs + · rfl + · exact mul_nonneg (inv_nonneg.mpr hb.le) (q.nonneg ω x y) + + + +theorem truncate_pointwise_loss (q : CappedLocalLoad G hloc O M) (b : ℝ) (hb : 0 < b) + (L : ℝ) (ω : Set E) (x : V) : + q.row ω x ≤ b * (∑' y, (q.truncate b hb L).mass ω x y) + q.row ω x ^ 2 / b + + b * ({η | CappedBadGoodness G η x M L}.indicator (1 : Set E → ℝ) ω) := by + rw [q.truncate_scaled_row b hb L] + have hs : 0 ≤ q.row ω x ^ 2 / b := div_nonneg (sq_nonneg _) hb.le + have hi : 0 ≤ ({η | CappedBadGoodness G η x M L}.indicator (1 : Set E → ℝ) ω) := by + apply Set.indicator_nonneg + intro η _ + norm_num + by_cases hr : q.row ω x ≤ b + · by_cases hg : CappedGoodness G ω x M L + · simp only [hr,hg,and_self,ite_true] + nlinarith + · simp only [hg,and_false,ite_false,zero_add] + by_cases hz : q.row ω x = 0 + · rw [hz] + positivity + · have hc := q.cap_of_row_ne_zero ω x hz + have hbad : CappedBadGoodness G ω x M L := ⟨hc.1,hc.2,fun h => hg ⟨hc.1,hc.2,h⟩⟩ + rw [Set.indicator_of_mem (show ω ∈ {η | CappedBadGoodness G η x M L} from hbad)] + change q.row ω x ≤ q.row ω x ^ 2 / b + b * 1 + linarith + · simp only [hr,false_and,ite_false,zero_add] + have htail : q.row ω x ≤ q.row ω x ^ 2 / b := by + apply (le_div_iff₀ hb).mpr + have ht := mul_le_mul_of_nonneg_left (le_of_lt (lt_of_not_ge hr)) (q.row_nonneg ω x) + nlinarith + exact htail.trans (le_add_of_nonneg_right (mul_nonneg hb.le hi)) + + + +theorem truncate_mean_loss (q : CappedLocalLoad G hloc O M) (p : unitInterval) + (b : ℝ) (hb : 0 < b) (L : ℝ) (x : V) : + (∫ ω, q.row ω x ∂law p) ≤ b * (q.truncate b hb L).successProbability p x + + (∫ ω, q.row ω x ^ 2 ∂law p) / b + b * (law p).real {ω | CappedBadGoodness G ω x M L} := by + let t := q.truncate b hb L + have ht : Integrable (fun ω => ∑' y, t.mass ω x y) (law p) := by + apply integrable_finite_local + (incidentSupport G hloc (finite_reachBall hloc x t.radius).toFinset) p + intro ω + exact tsum_congr (t.locality ω x) + have hbad := measurableSet_cappedBadGoodness G hloc x M L + have hi : Integrable ({ω | CappedBadGoodness G ω x M L}.indicator (1 : Set E → ℝ)) (law p) := + (integrable_const (1:ℝ)).indicator hbad + have h := integral_mono (q.integrable_row p x) + (((ht.const_mul b).add ((q.integrable_sq_row p x).div_const b)).add (hi.const_mul b)) + (q.truncate_pointwise_loss b hb L · x) + dsimp only [Pi.add_apply] at h + have he₁ := integral_add ((ht.const_mul b).add ((q.integrable_sq_row p x).div_const b)) (hi.const_mul b) + have he₂ := integral_add (ht.const_mul b) ((q.integrable_sq_row p x).div_const b) + dsimp only [Pi.add_apply] at he₁ he₂ + rw [he₁,he₂,integral_const_mul,integral_div,integral_const_mul, + integral_indicator_one hbad] at h + rw [← t.kernel_row_integral p x] at h + exact h + +theorem truncate_success_lower (q : CappedLocalLoad G hloc O M) (p : unitInterval) + (b : ℝ) (hb : 0 < b) (L : ℝ) (x : V) (a : ℝ) + (hmean : a ≤ ∫ ω, q.row ω x ∂law p) + (hmoment : (∫ ω, q.row ω x ^ 2 ∂law p) / b ≤ a/4) + (hbad : b * (law p).real {ω | CappedBadGoodness G ω x M L} ≤ a/4) : + a / (2*b) ≤ (q.truncate b hb L).successProbability p x := by + have hh := q.truncate_mean_loss p b hb L x + apply (div_le_iff₀ (mul_pos (by norm_num) hb)).mpr + nlinarith + +end CappedLocalLoad +end TruncationLoss + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section CategoricalAmplificationInput +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def amplificationVertices (B : Finset V) (k : ℕ) (z : ↥B) (r : Fin k → ↥B) : ℕ → V := + fun i => (oldRunVertices k z r i).val + +namespace LocalEndpointRule +variable {G : BondGraph V E} {hloc : LocallyFinite G} {O : Set V} {M : ℕ} {L : ℝ} + +noncomputable def amplificationWeight (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : ℝ := + oldRunWeight (fun i a b => q.mass (s.2 i) a.val b.val) k z r + +theorem amplificationWeight_eq (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : + q.amplificationWeight B k z s r = oldPathWeight k q.mass (amplificationVertices B k z r) s.2 := by + exact (oldPathWeight_oldRunVertices k (fun ω a b => q.mass ω a.val b.val) s.2 z r).symm + +theorem amplificationWeight_nonneg (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) (r : Fin k → ↥B) : + 0 ≤ q.amplificationWeight B k z s r := + oldRunWeight_nonneg (fun i (a b : ↥B) => q.mass (s.2 i) a.val b.val) + (fun i a b => q.nonneg (s.2 i) a.val b.val) k z r + +theorem amplificationWeight_row (q : LocalEndpointRule G hloc O M L) + (B : Finset V) (k : ℕ) (z : ↥B) (s : SpliceState E) : + (∑ r, q.amplificationWeight B k z s r) ≤ 1 := by + have hr (i : ℕ) (a : ↥B) : (∑ b : ↥B, q.mass (s.2 i) a.val b.val) ≤ 1 := by + rw [Finset.sum_coe_sort B] + exact ((q.summable_mass _ _).sum_le_tsum B (fun y _ => q.nonneg _ _ y)).trans (q.row_le_one _ _) + simpa only [one_pow,amplificationWeight] using sum_oldRunWeight_le + (fun i (a b : ↥B) => q.mass (s.2 i) a.val b.val) + (fun _ a b => q.nonneg _ a.val b.val) 1 zero_le_one hr k z + + + +noncomputable def amplificationInputs (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) : Finset (SpliceState E) := + (finiteSpliceDomain Q (Finset.Icc 1 k)).filter fun s => + x ∈ O ∧ z.val ∈ O ∧ n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ + amplificationVertices B k z r 0 ∈ cluster G s.1 x ∧ q.amplificationWeight B k z s r ≠ 0 + +theorem mem_amplificationInputs (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) : + s ∈ q.amplificationInputs Q B x k n z r ↔ + s ∈ finiteSpliceDomain Q (Finset.Icc 1 k) ∧ + x ∈ O ∧ z.val ∈ O ∧ n ≤ (cluster G s.1 x).ncard ∧ (cluster G s.1 x).ncard < 2*n ∧ + amplificationVertices B k z r 0 ∈ cluster G s.1 x ∧ q.amplificationWeight B k z s r ≠ 0 := + Finset.mem_filter + +theorem amplificationInputs_subset (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) : + q.amplificationInputs Q B x k n z r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k) := + Finset.filter_subset _ _ + +theorem amplificationInputs_chain (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) + (hs : s ∈ q.amplificationInputs Q B x k n z r) : + ∀ i, 1 ≤ i → i ≤ k → + Conn G (s.2 i) (amplificationVertices B k z r i) (amplificationVertices B k z r (i-1)) ∧ + (cluster G (s.2 i) (amplificationVertices B k z r i)).Finite ∧ + (cluster G (s.2 i) (amplificationVertices B k z r i)).ncard ≤ M ∧ + GoodForScale G (s.2 i) (amplificationVertices B k z r i) L := by + apply oldPathWeight_support G k M L q.mass + · intro ω a b h + exact (q.support ω a b h).2.2 + · exact (q.amplificationWeight_eq B k z s r) ▸ ((q.mem_amplificationInputs Q B x k n z r s).mp hs).2.2.2.2.2.2 + + + +theorem amplificationTrace_support (q : LocalEndpointRule G hloc O M L) + (Q : Finset E) (B : Finset V) (x : V) (k n : ℕ) (z : ↥B) (r : Fin k → ↥B) (s : SpliceState E) + (hs : s ∈ q.amplificationInputs Q B x k n z r) (c : List (ℕ × E)) (ωf : Set E) + (ht : SpliceTrace G x s.2 (amplificationVertices B k z r) k 0 s.1 c ωf) : + x ∈ O ∧ z.val ∈ O ∧ Conn G ωf x z.val ∧ (cluster G ωf x).Finite ∧ + (cluster G ωf x).ncard ≤ 2*n+k*M := by + obtain ⟨hdom,hx,hz,_,hbin,_,_⟩ := (q.mem_amplificationInputs Q B x k n z r s).mp hs + have hc := q.amplificationInputs_chain Q B x k n z r s hs + have hroot : (cluster G s.1 x).Finite := + cluster_finite_of_finite_edges G (Q.finite_toSet.subset + ((mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s).mp hdom).1) x + obtain ⟨hf,hcap⟩ := trajectoryUnion_finite_cap G s.2 (amplificationVertices B k z r) k M + (fun i hi hik => ⟨(hc i hi hik).2.1,(hc i hi hik).2.2.1⟩) + have hsub : cluster G ωf x ⊆ cluster G s.1 x ∪ trajectoryUnion G s.2 (amplificationVertices B k z r) k := by + intro v hv + by_cases hv' : v ∈ cluster G s.1 x + · exact Or.inl hv' + · exact Or.inr (ht.added_subset_trajectory G x s.2 (amplificationVertices B k z r) k 0 s.1 ωf c ⟨hv,hv'⟩) + refine ⟨hx,hz,?_,(hroot.union hf).subset hsub,?_⟩ + · simpa only [amplificationVertices,oldRunVertices_last,cluster,Set.mem_ofPred_eq] using + ht.endpoint G x s.2 (amplificationVertices B k z r) k 0 s.1 ωf c + · exact (Set.ncard_le_ncard hsub (hroot.union hf)).trans + ((Set.ncard_union_le ..).trans (Nat.add_le_add (by omega) hcap)) + +end LocalEndpointRule +end CategoricalAmplificationInput + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Transport/Haar.lean b/lean/OAI/Probability/UnimodularPercolation/Transport/Haar.lean index 31e7afe76157a2f77d09d21b1a4aa70ddb6ff961..1b642122b7b5e7ebb276b34eedbc572e92fd7629 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Transport/Haar.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Transport/Haar.lean @@ -1,229 +1,229 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Kernel.Spectral - -namespace OAI - -/-! Haar-measure transport for graph automorphism actions. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory -open scoped ENNReal -universe u v w - - - -theorem haar_invInvariant_of_rightInvariant - {H : Type w} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] - [MeasurableSpace H] [BorelSpace H] [LocallyCompactSpace H] - (μ : Measure H) [μ.IsHaarMeasure] [μ.Regular] [μ.IsMulRightInvariant] : - μ.IsInvInvariant := by - constructor - let c : ℝ≥0∞ := Measure.haarScalarFactor μ.inv μ - have hc : μ.inv = c • μ := Measure.isMulLeftInvariant_eq_smul_of_regular μ.inv μ - have he : Measure.map Inv.inv (Measure.map Inv.inv μ) = c ^ 2 • μ := by - rw [← Measure.inv_def μ, hc, Measure.map_smul c continuous_inv.measurable.aemeasurable, - ← Measure.inv_def μ, hc, - smul_smul, pow_two] - have μeq : μ = c ^ 2 • μ := by - rw [Measure.map_map continuous_inv.measurable continuous_inv.measurable] at he - simpa only [inv_involutive, Function.Involutive.comp_self, Measure.map_id] using he - let K : TopologicalSpace.PositiveCompacts H := Classical.arbitrary _ - have hpow : c ^ 2 * μ K = 1 ^ 2 * μ K := by - conv_rhs => rw [μeq] - simp - have hpow' : c ^ 2 = 1 ^ 2 := - (ENNReal.mul_left_inj - (Measure.measure_pos_of_nonempty_interior μ K.interior_nonempty).ne' - K.isCompact.measure_lt_top.ne).mp hpow - have hc1 : c = 1 := (ENNReal.pow_right_strictMono two_ne_zero).injective hpow' - rw [hc, hc1, one_smul] - -section HaarAction -attribute [local instance] Classical.propDecidable Classical.decEq -variable {H : Type w} [Group H] [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] -variable {V : Type u} [Countable V] [MeasurableSpace V] [MeasurableSingletonClass V] -variable [MulAction H V] - - -def actionStabilizer (x : V) : Set H := {g | g • x = x} - - -def actionOrbit (x : V) : Set V := {y | ∃ g : H, g • x = y} - -omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] - [MeasurableSpace V] [MeasurableSingletonClass V] in -theorem actionOrbit_self (x : V) : x ∈ actionOrbit (H := H) x := ⟨1,one_smul _ _⟩ - -omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] - [MeasurableSpace V] [MeasurableSingletonClass V] in -theorem actionOrbit_eq_of_mem {x y : V} (h : y ∈ actionOrbit (H := H) x) : - actionOrbit (H := H) y = actionOrbit (H := H) x := by - obtain ⟨g,rfl⟩ := h - ext z - constructor - · rintro ⟨k,hk⟩ - exact ⟨k*g,by simpa only [mul_smul] using hk⟩ - · rintro ⟨k,hk⟩ - exact ⟨k*g⁻¹,by simpa only [mul_smul, inv_smul_smul] using hk⟩ - - - -omit [MeasurableInv H] [Countable V] [MeasurableSingletonClass V] in -theorem orbit_fiber_measure (μ : Measure H) [μ.IsMulLeftInvariant] - (_hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x y : V) : - μ {g : H | g • x = y} = if y ∈ actionOrbit (H := H) x then μ (actionStabilizer (H := H) x) else 0 := by - classical - split_ifs with h - · obtain ⟨g,rfl⟩ := h - have he : {k : H | k • x = g • x} = (fun k : H => g⁻¹*k) ⁻¹' actionStabilizer (H := H) x := by - ext k - simp only [Set.mem_ofPred_eq,Set.mem_preimage,actionStabilizer,mul_smul] - exact ⟨fun hk => by rw [hk,inv_smul_smul],fun hk => by simpa using congrArg (fun z => g • z) hk⟩ - rw [he] - exact measure_preimage_mul μ g⁻¹ _ - · have he : {g : H | g • x = y} = ∅ := by - apply Set.eq_empty_iff_forall_notMem.mpr - intro g hg - exact h ⟨g,hg⟩ - simp only [he,measure_empty] - - - -omit [MeasurableInv H] in -theorem orbit_map_measure (μ : Measure H) [μ.IsMulLeftInvariant] - (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x : V) : - Measure.map (fun g : H => g • x) μ = - Measure.sum (fun y : V => (if y ∈ actionOrbit (H := H) x then μ (actionStabilizer (H := H) x) else 0) • Measure.dirac y) := by - classical - apply Measure.ext_of_singleton - intro y - rw [Measure.map_apply (hmeas x) (measurableSet_singleton y),Measure.sum_apply _ (measurableSet_singleton y)] - rw [tsum_eq_single y (fun z hz => by split_ifs <;> simp [Measure.smul_apply,Measure.dirac_apply',hz])] - simp only [Measure.smul_apply,Measure.dirac_apply_of_mem (Set.mem_singleton y),smul_eq_mul,mul_one] - exact orbit_fiber_measure μ hmeas x y - - - -omit [MeasurableInv H] in -theorem integral_orbit_sum (μ : Measure H) [μ.IsMulLeftInvariant] - (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x : V) - (hx : μ (actionStabilizer (H := H) x) ≠ ∞) (f : V → ℂ) : - (∫ g : H, f (g • x) ∂μ) = - (μ.real (actionStabilizer (H := H) x) : ℂ) * - ∑' y : V, if y ∈ actionOrbit (H := H) x then f y else 0 := by - classical - rw [←integral_map_of_stronglyMeasurable (hmeas x) (measurable_of_countable f).stronglyMeasurable, - orbit_map_measure μ hmeas x,integral_sum_dirac (fun y => by split_ifs <;> simp_all)] - rw [←tsum_mul_left] - apply tsum_congr - intro y - split_ifs <;> simp [Measure.real,Complex.real_smul] - - - -theorem orbit_mass_balance (μ : Measure H) [μ.IsMulLeftInvariant] [μ.IsInvInvariant] - (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x y : V) - (hx : μ (actionStabilizer (H := H) x) ≠ ∞) (hy : μ (actionStabilizer (H := H) y) ≠ ∞) - (m : V → V → ℂ) (hinv : ∀ g : H, ∀ x y : V, m (g • x) (g • y) = m x y) : - (μ.real (actionStabilizer (H := H) y) : ℂ) * (∑' z, if z ∈ actionOrbit (H := H) y then m x z else 0) = - (μ.real (actionStabilizer (H := H) x) : ℂ) * (∑' z, if z ∈ actionOrbit (H := H) x then m z y else 0) := by - rw [←integral_orbit_sum μ hmeas y hy (m x),←integral_orbit_sum μ hmeas x hx (fun z => m z y)] - calc - _ = ∫ g : H, m (g⁻¹ • x) y ∂μ := by - apply integral_congr_ae - filter_upwards [] with g - have h := hinv g⁻¹ x (g • y) - simpa only [inv_smul_smul] using h.symm - _ = _ := integral_inv_eq_self (fun g : H => m (g • x) y) μ - -variable {ι : Type*} [Fintype ι] - - - -noncomputable def inverseStabilizerWeight (μ : Measure H) (root : ι → V) (i : ι) : ℝ := - (μ.real (actionStabilizer (H := H) (root i)))⁻¹ / - ∑ j, (μ.real (actionStabilizer (H := H) (root j)))⁻¹ - -omit [MeasurableMul₂ H] [MeasurableInv H] [Countable V] [MeasurableSpace V] - [MeasurableSingletonClass V] in -theorem inverseStabilizerWeight_pos [Nonempty ι] (μ : Measure H) (root : ι → V) - (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) (i : ι) : - 0 < inverseStabilizerWeight μ root i := by - apply div_pos (inv_pos.mpr (hvol i)) - exact Finset.sum_pos (fun j _ => inv_pos.mpr (hvol j)) Finset.univ_nonempty - -omit [MeasurableMul₂ H] [MeasurableInv H] [Countable V] [MeasurableSpace V] - [MeasurableSingletonClass V] in -theorem inverseStabilizerWeight_sum [Nonempty ι] (μ : Measure H) (root : ι → V) - (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) : - ∑ i, inverseStabilizerWeight μ root i = 1 := by - unfold inverseStabilizerWeight - rw [←Finset.sum_div,div_self] - exact ne_of_gt (Finset.sum_pos (fun j _ => inv_pos.mpr (hvol j)) Finset.univ_nonempty) - - - -omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] - [MeasurableSpace V] [MeasurableSingletonClass V] in -theorem tsum_eq_sum_orbits (root : ι → V) - (hcov : ∀ x, ∃ i, x ∈ actionOrbit (H := H) (root i)) - (hsep : ∀ i j, root j ∈ actionOrbit (H := H) (root i) → i = j) - (f : V → ℂ) (hf : Summable f) : - ∑' x, f x = ∑ i, ∑' x, if x ∈ actionOrbit (H := H) (root i) then f x else 0 := by - have hi (i : ι) : Summable (fun x => if x ∈ actionOrbit (H := H) (root i) then f x else 0) := hf.indicator _ - rw [←Summable.tsum_finsetSum (s := Finset.univ) (fun i _ => hi i)] - apply tsum_congr - intro x - obtain ⟨i,hi⟩ := hcov x - symm - rw [Finset.sum_eq_single i] - · exact ite_eq_left hi - · intro j _ hji - have hj : x ∉ actionOrbit (H := H) (root j) := by - intro hj - apply hji - apply hsep j i - rw [←actionOrbit_eq_of_mem hj,actionOrbit_eq_of_mem hi] - exact actionOrbit_self _ - exact ite_eq_right hj - · simp - - - -theorem rootTransport_of_invariant_measure [Nonempty ι] - (μ : Measure H) [μ.IsMulLeftInvariant] [μ.IsInvInvariant] - (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) - (root : ι → V) (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) - (hfinite : ∀ i, μ (actionStabilizer (H := H) (root i)) ≠ ∞) - (hcov : ∀ x, ∃ i, x ∈ actionOrbit (H := H) (root i)) - (hsep : ∀ i j, root j ∈ actionOrbit (H := H) (root i) → i = j) - (Γ : Set (V ≃ V)) (hΓ : ∀ g : H, MulAction.toPerm g ∈ Γ) : - RootTransport root (inverseStabilizerWeight μ root) Γ := by - intro m hinv hrow hcol - have hm : ∀ g : H, ∀ x y : V, m (g • x) (g • y) = m x y := fun g => hinv _ (hΓ g) - have hp (i j : ι) : - (inverseStabilizerWeight μ root i : ℂ) * (∑' y, if y ∈ actionOrbit (H := H) (root j) then m (root i) y else 0) = - (inverseStabilizerWeight μ root j : ℂ) * (∑' x, if x ∈ actionOrbit (H := H) (root i) then m x (root j) else 0) := by - have hb := orbit_mass_balance μ hmeas (root i) (root j) (hfinite i) (hfinite j) m hm - have hi : (μ.real (actionStabilizer (H := H) (root i)) : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (hvol i).ne' - have hj : (μ.real (actionStabilizer (H := H) (root j)) : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (hvol j).ne' - have hZ : ((∑ k, (μ.real (actionStabilizer (H := H) (root k)))⁻¹ : ℝ) : ℂ) ≠ 0 := - Complex.ofReal_ne_zero.mpr (ne_of_gt (Finset.sum_pos (fun k _ => inv_pos.mpr (hvol k)) Finset.univ_nonempty)) - unfold inverseStabilizerWeight - push_cast - field_simp - simpa only [mul_comm,mul_left_comm,mul_assoc] using congrArg (fun z : ℂ => z / ∑ k, (1 : ℂ) / (μ.real (actionStabilizer (H := H) (root k)) : ℂ)) hb - conv_lhs => arg 2; ext i; rw [tsum_eq_sum_orbits root hcov hsep (m (root i)) (hrow (root i)),Finset.mul_sum] - simp_rw [hp] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro j _ - rw [←Finset.mul_sum,←tsum_eq_sum_orbits root hcov hsep (fun x => m x (root j)) (hcol (root j))] - -end HaarAction -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Kernel.Spectral + +namespace OAI + +/-! Haar-measure transport for graph automorphism actions. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory +open scoped ENNReal +universe u v w + + + +theorem haar_invInvariant_of_rightInvariant + {H : Type w} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] + [MeasurableSpace H] [BorelSpace H] [LocallyCompactSpace H] + (μ : Measure H) [μ.IsHaarMeasure] [μ.Regular] [μ.IsMulRightInvariant] : + μ.IsInvInvariant := by + constructor + let c : ℝ≥0∞ := Measure.haarScalarFactor μ.inv μ + have hc : μ.inv = c • μ := Measure.isMulLeftInvariant_eq_smul_of_regular μ.inv μ + have he : Measure.map Inv.inv (Measure.map Inv.inv μ) = c ^ 2 • μ := by + rw [← Measure.inv_def μ, hc, Measure.map_smul c continuous_inv.measurable.aemeasurable, + ← Measure.inv_def μ, hc, + smul_smul, pow_two] + have μeq : μ = c ^ 2 • μ := by + rw [Measure.map_map continuous_inv.measurable continuous_inv.measurable] at he + simpa only [inv_involutive, Function.Involutive.comp_self, Measure.map_id] using he + let K : TopologicalSpace.PositiveCompacts H := Classical.arbitrary _ + have hpow : c ^ 2 * μ K = 1 ^ 2 * μ K := by + conv_rhs => rw [μeq] + simp + have hpow' : c ^ 2 = 1 ^ 2 := + (ENNReal.mul_left_inj + (Measure.measure_pos_of_nonempty_interior μ K.interior_nonempty).ne' + K.isCompact.measure_lt_top.ne).mp hpow + have hc1 : c = 1 := (ENNReal.pow_right_strictMono two_ne_zero).injective hpow' + rw [hc, hc1, one_smul] + +section HaarAction +attribute [local instance] Classical.propDecidable Classical.decEq +variable {H : Type w} [Group H] [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] +variable {V : Type u} [Countable V] [MeasurableSpace V] [MeasurableSingletonClass V] +variable [MulAction H V] + + +def actionStabilizer (x : V) : Set H := {g | g • x = x} + + +def actionOrbit (x : V) : Set V := {y | ∃ g : H, g • x = y} + +omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] + [MeasurableSpace V] [MeasurableSingletonClass V] in +theorem actionOrbit_self (x : V) : x ∈ actionOrbit (H := H) x := ⟨1,one_smul _ _⟩ + +omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] + [MeasurableSpace V] [MeasurableSingletonClass V] in +theorem actionOrbit_eq_of_mem {x y : V} (h : y ∈ actionOrbit (H := H) x) : + actionOrbit (H := H) y = actionOrbit (H := H) x := by + obtain ⟨g,rfl⟩ := h + ext z + constructor + · rintro ⟨k,hk⟩ + exact ⟨k*g,by simpa only [mul_smul] using hk⟩ + · rintro ⟨k,hk⟩ + exact ⟨k*g⁻¹,by simpa only [mul_smul, inv_smul_smul] using hk⟩ + + + +omit [MeasurableInv H] [Countable V] [MeasurableSingletonClass V] in +theorem orbit_fiber_measure (μ : Measure H) [μ.IsMulLeftInvariant] + (_hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x y : V) : + μ {g : H | g • x = y} = if y ∈ actionOrbit (H := H) x then μ (actionStabilizer (H := H) x) else 0 := by + classical + split_ifs with h + · obtain ⟨g,rfl⟩ := h + have he : {k : H | k • x = g • x} = (fun k : H => g⁻¹*k) ⁻¹' actionStabilizer (H := H) x := by + ext k + simp only [Set.mem_ofPred_eq,Set.mem_preimage,actionStabilizer,mul_smul] + exact ⟨fun hk => by rw [hk,inv_smul_smul],fun hk => by simpa using congrArg (fun z => g • z) hk⟩ + rw [he] + exact measure_preimage_mul μ g⁻¹ _ + · have he : {g : H | g • x = y} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro g hg + exact h ⟨g,hg⟩ + simp only [he,measure_empty] + + + +omit [MeasurableInv H] in +theorem orbit_map_measure (μ : Measure H) [μ.IsMulLeftInvariant] + (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x : V) : + Measure.map (fun g : H => g • x) μ = + Measure.sum (fun y : V => (if y ∈ actionOrbit (H := H) x then μ (actionStabilizer (H := H) x) else 0) • Measure.dirac y) := by + classical + apply Measure.ext_of_singleton + intro y + rw [Measure.map_apply (hmeas x) (measurableSet_singleton y),Measure.sum_apply _ (measurableSet_singleton y)] + rw [tsum_eq_single y (fun z hz => by split_ifs <;> simp [Measure.smul_apply,Measure.dirac_apply',hz])] + simp only [Measure.smul_apply,Measure.dirac_apply_of_mem (Set.mem_singleton y),smul_eq_mul,mul_one] + exact orbit_fiber_measure μ hmeas x y + + + +omit [MeasurableInv H] in +theorem integral_orbit_sum (μ : Measure H) [μ.IsMulLeftInvariant] + (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x : V) + (hx : μ (actionStabilizer (H := H) x) ≠ ∞) (f : V → ℂ) : + (∫ g : H, f (g • x) ∂μ) = + (μ.real (actionStabilizer (H := H) x) : ℂ) * + ∑' y : V, if y ∈ actionOrbit (H := H) x then f y else 0 := by + classical + rw [←integral_map_of_stronglyMeasurable (hmeas x) (measurable_of_countable f).stronglyMeasurable, + orbit_map_measure μ hmeas x,integral_sum_dirac (fun y => by split_ifs <;> simp_all)] + rw [←tsum_mul_left] + apply tsum_congr + intro y + split_ifs <;> simp [Measure.real,Complex.real_smul] + + + +theorem orbit_mass_balance (μ : Measure H) [μ.IsMulLeftInvariant] [μ.IsInvInvariant] + (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) (x y : V) + (hx : μ (actionStabilizer (H := H) x) ≠ ∞) (hy : μ (actionStabilizer (H := H) y) ≠ ∞) + (m : V → V → ℂ) (hinv : ∀ g : H, ∀ x y : V, m (g • x) (g • y) = m x y) : + (μ.real (actionStabilizer (H := H) y) : ℂ) * (∑' z, if z ∈ actionOrbit (H := H) y then m x z else 0) = + (μ.real (actionStabilizer (H := H) x) : ℂ) * (∑' z, if z ∈ actionOrbit (H := H) x then m z y else 0) := by + rw [←integral_orbit_sum μ hmeas y hy (m x),←integral_orbit_sum μ hmeas x hx (fun z => m z y)] + calc + _ = ∫ g : H, m (g⁻¹ • x) y ∂μ := by + apply integral_congr_ae + filter_upwards [] with g + have h := hinv g⁻¹ x (g • y) + simpa only [inv_smul_smul] using h.symm + _ = _ := integral_inv_eq_self (fun g : H => m (g • x) y) μ + +variable {ι : Type*} [Fintype ι] + + + +noncomputable def inverseStabilizerWeight (μ : Measure H) (root : ι → V) (i : ι) : ℝ := + (μ.real (actionStabilizer (H := H) (root i)))⁻¹ / + ∑ j, (μ.real (actionStabilizer (H := H) (root j)))⁻¹ + +omit [MeasurableMul₂ H] [MeasurableInv H] [Countable V] [MeasurableSpace V] + [MeasurableSingletonClass V] in +theorem inverseStabilizerWeight_pos [Nonempty ι] (μ : Measure H) (root : ι → V) + (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) (i : ι) : + 0 < inverseStabilizerWeight μ root i := by + apply div_pos (inv_pos.mpr (hvol i)) + exact Finset.sum_pos (fun j _ => inv_pos.mpr (hvol j)) Finset.univ_nonempty + +omit [MeasurableMul₂ H] [MeasurableInv H] [Countable V] [MeasurableSpace V] + [MeasurableSingletonClass V] in +theorem inverseStabilizerWeight_sum [Nonempty ι] (μ : Measure H) (root : ι → V) + (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) : + ∑ i, inverseStabilizerWeight μ root i = 1 := by + unfold inverseStabilizerWeight + rw [←Finset.sum_div,div_self] + exact ne_of_gt (Finset.sum_pos (fun j _ => inv_pos.mpr (hvol j)) Finset.univ_nonempty) + + + +omit [MeasurableSpace H] [MeasurableMul₂ H] [MeasurableInv H] [Countable V] + [MeasurableSpace V] [MeasurableSingletonClass V] in +theorem tsum_eq_sum_orbits (root : ι → V) + (hcov : ∀ x, ∃ i, x ∈ actionOrbit (H := H) (root i)) + (hsep : ∀ i j, root j ∈ actionOrbit (H := H) (root i) → i = j) + (f : V → ℂ) (hf : Summable f) : + ∑' x, f x = ∑ i, ∑' x, if x ∈ actionOrbit (H := H) (root i) then f x else 0 := by + have hi (i : ι) : Summable (fun x => if x ∈ actionOrbit (H := H) (root i) then f x else 0) := hf.indicator _ + rw [←Summable.tsum_finsetSum (s := Finset.univ) (fun i _ => hi i)] + apply tsum_congr + intro x + obtain ⟨i,hi⟩ := hcov x + symm + rw [Finset.sum_eq_single i] + · exact ite_eq_left hi + · intro j _ hji + have hj : x ∉ actionOrbit (H := H) (root j) := by + intro hj + apply hji + apply hsep j i + rw [←actionOrbit_eq_of_mem hj,actionOrbit_eq_of_mem hi] + exact actionOrbit_self _ + exact ite_eq_right hj + · simp + + + +theorem rootTransport_of_invariant_measure [Nonempty ι] + (μ : Measure H) [μ.IsMulLeftInvariant] [μ.IsInvInvariant] + (hmeas : ∀ x : V, Measurable (fun g : H => g • x)) + (root : ι → V) (hvol : ∀ i, 0 < μ.real (actionStabilizer (H := H) (root i))) + (hfinite : ∀ i, μ (actionStabilizer (H := H) (root i)) ≠ ∞) + (hcov : ∀ x, ∃ i, x ∈ actionOrbit (H := H) (root i)) + (hsep : ∀ i j, root j ∈ actionOrbit (H := H) (root i) → i = j) + (Γ : Set (V ≃ V)) (hΓ : ∀ g : H, MulAction.toPerm g ∈ Γ) : + RootTransport root (inverseStabilizerWeight μ root) Γ := by + intro m hinv hrow hcol + have hm : ∀ g : H, ∀ x y : V, m (g • x) (g • y) = m x y := fun g => hinv _ (hΓ g) + have hp (i j : ι) : + (inverseStabilizerWeight μ root i : ℂ) * (∑' y, if y ∈ actionOrbit (H := H) (root j) then m (root i) y else 0) = + (inverseStabilizerWeight μ root j : ℂ) * (∑' x, if x ∈ actionOrbit (H := H) (root i) then m x (root j) else 0) := by + have hb := orbit_mass_balance μ hmeas (root i) (root j) (hfinite i) (hfinite j) m hm + have hi : (μ.real (actionStabilizer (H := H) (root i)) : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (hvol i).ne' + have hj : (μ.real (actionStabilizer (H := H) (root j)) : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (hvol j).ne' + have hZ : ((∑ k, (μ.real (actionStabilizer (H := H) (root k)))⁻¹ : ℝ) : ℂ) ≠ 0 := + Complex.ofReal_ne_zero.mpr (ne_of_gt (Finset.sum_pos (fun k _ => inv_pos.mpr (hvol k)) Finset.univ_nonempty)) + unfold inverseStabilizerWeight + push_cast + field_simp + simpa only [mul_comm,mul_left_comm,mul_assoc] using congrArg (fun z : ℂ => z / ∑ k, (1 : ℂ) / (μ.real (actionStabilizer (H := H) (root k)) : ℂ)) hb + conv_lhs => arg 2; ext i; rw [tsum_eq_sum_orbits root hcov hsep (m (root i)) (hrow (root i)),Finset.mul_sum] + simp_rw [hp] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + rw [←Finset.mul_sum,←tsum_eq_sum_orbits root hcov hsep (fun x => m x (root j)) (hcol (root j))] + +end HaarAction +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Transport/InvariantRoot.lean b/lean/OAI/Probability/UnimodularPercolation/Transport/InvariantRoot.lean index ecf3f246506e3d32f0243d015490ccb4e7cd55c3..a79472af9ed8cf6577df03dddbb4824ef2f64247 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Transport/InvariantRoot.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Transport/InvariantRoot.lean @@ -1,126 +1,126 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Main -import OAI.Probability.UnimodularPercolation.Graph.FullTopology - -namespace OAI - -/-! Haar measures and root transport for the full automorphism group. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -open MeasureTheory Topology -open scoped ENNReal -universe u v -variable {V : Type u} {E : Type v} -variable [TopologicalSpace V] [DiscreteTopology V] - -noncomputable instance fullGraphAutMeasurableSpace (G : BondGraph V E) : - MeasurableSpace (GraphAut G) := borel (GraphAut G) - -instance graphAutBorel (G : BondGraph V E) : BorelSpace (GraphAut G) := ⟨rfl⟩ - -noncomputable def graphAutHaar (G : BondGraph V E) (hinj : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : Measure (GraphAut G) := by - letI := locallyCompact_graphAut G hinj hloc hconn x - exact Measure.haar - -instance graphAutHaar_isHaar (G : BondGraph V E) (hinj : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : - (graphAutHaar G hinj hloc hconn x).IsHaarMeasure := by - let := locallyCompact_graphAut G hinj hloc hconn x - exact inferInstanceAs (Measure.IsHaarMeasure Measure.haar) - -omit [TopologicalSpace V] [DiscreteTopology V] in -theorem graphStabilizer_eq_action (G : BondGraph V E) (x : V) : - graphStabilizer G x = actionStabilizer (H := GraphAut G) x := rfl - -omit [TopologicalSpace V] [DiscreteTopology V] in -theorem graphStabilizer_inv (G : BondGraph V E) (x : V) : - (graphStabilizer G x)⁻¹ = graphStabilizer G x := by - ext g - change (graphAutPerm G g).symm x = x ↔ graphAutPerm G g x = x - rw [Equiv.symm_apply_eq,eq_comm] - -theorem graphAutHaar_stabilizer_pos (G : BondGraph V E) - (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x y : V) : - 0 < (graphAutHaar G hinj hloc hconn x).real (actionStabilizer (H := GraphAut G) y) := by - apply ENNReal.toReal_pos - · exact ((isOpen_graphStabilizer G y).measure_pos _ ⟨1,rfl⟩).ne' - · exact (isCompact_graphStabilizer G hinj hloc hconn y).measure_lt_top.ne - -theorem graphAutHaar_stabilizer_finite (G : BondGraph V E) - (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x y : V) : - graphAutHaar G hinj hloc hconn x (actionStabilizer (H := GraphAut G) y) ≠ ∞ := - (isCompact_graphStabilizer G hinj hloc hconn y).measure_lt_top.ne - -def GraphUnimodular (G : BondGraph V E) (hinj : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : Prop := - (graphAutHaar G hinj hloc hconn x).IsMulRightInvariant - -theorem graphAutHaar_invInvariant [Countable V] (G : BondGraph V E) - (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x : V) - (hu : GraphUnimodular G hinj hloc hconn x) : - (graphAutHaar G hinj hloc hconn x).IsInvInvariant := by - let := locallyCompact_graphAut G hinj hloc hconn x - let μ := graphAutHaar G hinj hloc hconn x - let : μ.IsMulRightInvariant := hu - constructor - have hc := Measure.isMulLeftInvariant_eq_smul_of_regular μ.inv μ - have hf : μ (graphStabilizer G x) ≠ ∞ := - (isCompact_graphStabilizer G hinj hloc hconn x).measure_lt_top.ne - have hp : μ (graphStabilizer G x) ≠ 0 := - ((isOpen_graphStabilizer G x).measure_pos μ ⟨1,rfl⟩).ne' - have he := congrArg (fun ν : Measure (GraphAut G) => ν (graphStabilizer G x)) hc - rw [Measure.inv_apply,graphStabilizer_inv,Measure.smul_apply] at he - have hz : (μ.inv.haarScalarFactor μ : ℝ≥0∞) = 1 := by - apply (ENNReal.mul_left_inj hp hf).mp - simpa only [ENNReal.smul_def,smul_eq_mul,one_mul] using he.symm - rw [hc,show μ.inv.haarScalarFactor μ = 1 from ENNReal.coe_eq_one.mp hz,one_smul] - -theorem exists_rootTransport_of_unimodular [Nonempty V] - (G : BondGraph V E) (hinj : Function.Injective G) - (hloc : LocallyFinite G) (hconn : Connected G) (hqt : QuasiTransitive G) (x₀ : V) - (hu : GraphUnimodular G hinj hloc hconn x₀) : - ∃ (n : ℕ) (root : Fin n → V) (weight : Fin n → ℝ), - weight = inverseStabilizerWeight (graphAutHaar G hinj hloc hconn x₀) root ∧ - (∀ i, 0 < weight i) ∧ (∑ i, weight i = 1) ∧ - RootTransport root weight (vertexAut G) ∧ - (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) := by - classical - let : Countable V := countable_vertices hloc hconn - let : MeasurableSpace V := borel V - let : BorelSpace V := ⟨rfl⟩ - let : Finite (GraphOrbit G) := finite_graphOrbit G hqt - let : Fintype (GraphOrbit G) := Fintype.ofFinite _ - let n := Fintype.card (GraphOrbit G) - let q : Fin n ≃ GraphOrbit G := (Fintype.equivFin _).symm - let root : Fin n → V := fun i => fullGraphOrbitRoot G (q i) - let μ := graphAutHaar G hinj hloc hconn x₀ - let : μ.IsInvInvariant := graphAutHaar_invInvariant G hinj hloc hconn x₀ hu - have hcov (x : V) : ∃ i : Fin n, x ∈ actionOrbit (H := GraphAut G) (root i) := by - obtain ⟨i,g,hg⟩ := graphOrbitRoot_covers G x - refine ⟨q.symm i,g,?_⟩ - simpa only [root,Equiv.apply_symm_apply] using hg - let : Nonempty (Fin n) := ⟨(hcov x₀).choose⟩ - have hsep (i j : Fin n) (h : root j ∈ actionOrbit (H := GraphAut G) (root i)) : i = j := - q.injective (graphOrbitRoot_separates G (q i) (q j) h) - have hvol (i : Fin n) : 0 < μ.real (actionStabilizer (H := GraphAut G) (root i)) := - graphAutHaar_stabilizer_pos G hinj hloc hconn x₀ (root i) - refine ⟨n,root,inverseStabilizerWeight μ root,rfl, - inverseStabilizerWeight_pos μ root hvol, - inverseStabilizerWeight_sum μ root hvol,?_,?_⟩ - · apply rootTransport_of_invariant_measure μ - (fun x => (continuous_aut_apply G x).measurable) root hvol - (fun i => graphAutHaar_stabilizer_finite G hinj hloc hconn x₀ (root i)) - hcov hsep (vertexAut G) - intro g - exact graphAutPerm_mem G g - · intro x - obtain ⟨i,g,hg⟩ := hcov x - exact ⟨i,graphAutPerm G g,graphAutPerm_mem G g,hg⟩ - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Main +import OAI.Probability.UnimodularPercolation.Graph.FullTopology + +namespace OAI + +/-! Haar measures and root transport for the full automorphism group. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +open MeasureTheory Topology +open scoped ENNReal +universe u v +variable {V : Type u} {E : Type v} +variable [TopologicalSpace V] [DiscreteTopology V] + +noncomputable instance fullGraphAutMeasurableSpace (G : BondGraph V E) : + MeasurableSpace (GraphAut G) := borel (GraphAut G) + +instance graphAutBorel (G : BondGraph V E) : BorelSpace (GraphAut G) := ⟨rfl⟩ + +noncomputable def graphAutHaar (G : BondGraph V E) (hinj : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : Measure (GraphAut G) := by + letI := locallyCompact_graphAut G hinj hloc hconn x + exact Measure.haar + +instance graphAutHaar_isHaar (G : BondGraph V E) (hinj : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : + (graphAutHaar G hinj hloc hconn x).IsHaarMeasure := by + let := locallyCompact_graphAut G hinj hloc hconn x + exact inferInstanceAs (Measure.IsHaarMeasure Measure.haar) + +omit [TopologicalSpace V] [DiscreteTopology V] in +theorem graphStabilizer_eq_action (G : BondGraph V E) (x : V) : + graphStabilizer G x = actionStabilizer (H := GraphAut G) x := rfl + +omit [TopologicalSpace V] [DiscreteTopology V] in +theorem graphStabilizer_inv (G : BondGraph V E) (x : V) : + (graphStabilizer G x)⁻¹ = graphStabilizer G x := by + ext g + change (graphAutPerm G g).symm x = x ↔ graphAutPerm G g x = x + rw [Equiv.symm_apply_eq,eq_comm] + +theorem graphAutHaar_stabilizer_pos (G : BondGraph V E) + (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x y : V) : + 0 < (graphAutHaar G hinj hloc hconn x).real (actionStabilizer (H := GraphAut G) y) := by + apply ENNReal.toReal_pos + · exact ((isOpen_graphStabilizer G y).measure_pos _ ⟨1,rfl⟩).ne' + · exact (isCompact_graphStabilizer G hinj hloc hconn y).measure_lt_top.ne + +theorem graphAutHaar_stabilizer_finite (G : BondGraph V E) + (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x y : V) : + graphAutHaar G hinj hloc hconn x (actionStabilizer (H := GraphAut G) y) ≠ ∞ := + (isCompact_graphStabilizer G hinj hloc hconn y).measure_lt_top.ne + +def GraphUnimodular (G : BondGraph V E) (hinj : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (x : V) : Prop := + (graphAutHaar G hinj hloc hconn x).IsMulRightInvariant + +theorem graphAutHaar_invInvariant [Countable V] (G : BondGraph V E) + (hinj : Function.Injective G) (hloc : LocallyFinite G) (hconn : Connected G) (x : V) + (hu : GraphUnimodular G hinj hloc hconn x) : + (graphAutHaar G hinj hloc hconn x).IsInvInvariant := by + let := locallyCompact_graphAut G hinj hloc hconn x + let μ := graphAutHaar G hinj hloc hconn x + let : μ.IsMulRightInvariant := hu + constructor + have hc := Measure.isMulLeftInvariant_eq_smul_of_regular μ.inv μ + have hf : μ (graphStabilizer G x) ≠ ∞ := + (isCompact_graphStabilizer G hinj hloc hconn x).measure_lt_top.ne + have hp : μ (graphStabilizer G x) ≠ 0 := + ((isOpen_graphStabilizer G x).measure_pos μ ⟨1,rfl⟩).ne' + have he := congrArg (fun ν : Measure (GraphAut G) => ν (graphStabilizer G x)) hc + rw [Measure.inv_apply,graphStabilizer_inv,Measure.smul_apply] at he + have hz : (μ.inv.haarScalarFactor μ : ℝ≥0∞) = 1 := by + apply (ENNReal.mul_left_inj hp hf).mp + simpa only [ENNReal.smul_def,smul_eq_mul,one_mul] using he.symm + rw [hc,show μ.inv.haarScalarFactor μ = 1 from ENNReal.coe_eq_one.mp hz,one_smul] + +theorem exists_rootTransport_of_unimodular [Nonempty V] + (G : BondGraph V E) (hinj : Function.Injective G) + (hloc : LocallyFinite G) (hconn : Connected G) (hqt : QuasiTransitive G) (x₀ : V) + (hu : GraphUnimodular G hinj hloc hconn x₀) : + ∃ (n : ℕ) (root : Fin n → V) (weight : Fin n → ℝ), + weight = inverseStabilizerWeight (graphAutHaar G hinj hloc hconn x₀) root ∧ + (∀ i, 0 < weight i) ∧ (∑ i, weight i = 1) ∧ + RootTransport root weight (vertexAut G) ∧ + (∀ x, ∃ i, ∃ g ∈ vertexAut G, g (root i) = x) := by + classical + let : Countable V := countable_vertices hloc hconn + let : MeasurableSpace V := borel V + let : BorelSpace V := ⟨rfl⟩ + let : Finite (GraphOrbit G) := finite_graphOrbit G hqt + let : Fintype (GraphOrbit G) := Fintype.ofFinite _ + let n := Fintype.card (GraphOrbit G) + let q : Fin n ≃ GraphOrbit G := (Fintype.equivFin _).symm + let root : Fin n → V := fun i => fullGraphOrbitRoot G (q i) + let μ := graphAutHaar G hinj hloc hconn x₀ + let : μ.IsInvInvariant := graphAutHaar_invInvariant G hinj hloc hconn x₀ hu + have hcov (x : V) : ∃ i : Fin n, x ∈ actionOrbit (H := GraphAut G) (root i) := by + obtain ⟨i,g,hg⟩ := graphOrbitRoot_covers G x + refine ⟨q.symm i,g,?_⟩ + simpa only [root,Equiv.apply_symm_apply] using hg + let : Nonempty (Fin n) := ⟨(hcov x₀).choose⟩ + have hsep (i j : Fin n) (h : root j ∈ actionOrbit (H := GraphAut G) (root i)) : i = j := + q.injective (graphOrbitRoot_separates G (q i) (q j) h) + have hvol (i : Fin n) : 0 < μ.real (actionStabilizer (H := GraphAut G) (root i)) := + graphAutHaar_stabilizer_pos G hinj hloc hconn x₀ (root i) + refine ⟨n,root,inverseStabilizerWeight μ root,rfl, + inverseStabilizerWeight_pos μ root hvol, + inverseStabilizerWeight_sum μ root hvol,?_,?_⟩ + · apply rootTransport_of_invariant_measure μ + (fun x => (continuous_aut_apply G x).measurable) root hvol + (fun i => graphAutHaar_stabilizer_finite G hinj hloc hconn x₀ (root i)) + hcov hsep (vertexAut G) + intro g + exact graphAutPerm_mem G g + · intro x + obtain ⟨i,g,hg⟩ := hcov x + exact ⟨i,graphAutPerm G g,graphAutPerm_mem G g,hg⟩ + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/Transport/TrajectoryMass.lean b/lean/OAI/Probability/UnimodularPercolation/Transport/TrajectoryMass.lean index 31734f0426dcc0a262469a0fb2ad9de7507f869b..12cf13436bb83ed040c30f915f3db097742cb93f 100644 --- a/lean/OAI/Probability/UnimodularPercolation/Transport/TrajectoryMass.lean +++ b/lean/OAI/Probability/UnimodularPercolation/Transport/TrajectoryMass.lean @@ -1,1323 +1,1323 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Splicing.MomentBounds - -namespace OAI - -/-! Trajectory Mass for bond percolation. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OldPathWeight -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def finiteFieldIntegral (Q : Finset E) (p : ℝ) (f : Set E → ℝ) : ℝ := - ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * f (finiteFieldSet Q ω) - -theorem finiteFieldIntegral_nonneg (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) - (hf : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteFieldIntegral Q p f := - Finset.sum_nonneg fun ω _ => mul_nonneg (finiteFieldWeight_nonneg Q p ω) (hf _) - -theorem finiteFieldIntegral_sum {I : Type*} (Q : Finset E) (p : ℝ) (S : Finset I) - (f : I → Set E → ℝ) : - finiteFieldIntegral Q p (fun ω => ∑ i ∈ S, f i ω) = - ∑ i ∈ S, finiteFieldIntegral Q p (f i) := by - simp only [finiteFieldIntegral, Finset.mul_sum] - exact Finset.sum_comm - - - -theorem finiteFamilyIntegral_prod (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (f : ↥J → Set E → ℝ) : - finiteFamilyIntegral Q J p (fun η => ∏ i : ↥J, f i (η i)) = - ∏ i : ↥J, finiteFieldIntegral Q p (f i) := by - simp only [finiteFamilyIntegral, finiteFamilyWeight, finiteFieldFamily_at, - ← Finset.prod_mul_distrib, finiteFieldIntegral] - exact (Fintype.prod_sum (fun (i : ↥J) (ω : FiniteField Q) => - finiteFieldWeight Q p ω * f i (finiteFieldSet Q ω))).symm - - - -noncomputable def oldPathWeight (k : ℕ) (q : Set E → V → V → ℝ) - (y : ℕ → V) (η : ℕ → Set E) : ℝ := - ∏ i : ↥(Finset.Icc 1 k), q (η i) (y i) (y (i.val-1)) - -theorem oldPathWeight_nonneg (k : ℕ) (q : Set E → V → V → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) (y : ℕ → V) (η : ℕ → Set E) : - 0 ≤ oldPathWeight k q y η := - Finset.prod_nonneg fun _ _ => hq _ _ _ - -theorem oldPathWeight_integral (Q : Finset E) (k : ℕ) (p : ℝ) - (q : Set E → V → V → ℝ) (y : ℕ → V) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p (oldPathWeight k q y) = - ∏ i : ↥(Finset.Icc 1 k), finiteFieldIntegral Q p (fun ω => q ω (y i) (y (i.val-1))) := by - unfold oldPathWeight - exact finiteFamilyIntegral_prod Q (Finset.Icc 1 k) p - (fun i ω => q ω (y i) (y (i.val-1))) - - - -theorem oldPathWeight_support (G : BondGraph V E) (k M : ℕ) (L : ℝ) - (q : Set E → V → V → ℝ) - (hs : ∀ ω a b, q ω a b ≠ 0 → b ∈ cluster G ω a ∧ - (cluster G ω a).Finite ∧ (cluster G ω a).ncard ≤ M ∧ GoodForScale G ω a L) - (y : ℕ → V) (η : ℕ → Set E) (hy : oldPathWeight k q y η ≠ 0) : - ∀ i, 1 ≤ i → i ≤ k → y (i-1) ∈ cluster G (η i) (y i) ∧ - (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M ∧ - GoodForScale G (η i) (y i) L := by - intro i hi hik - apply hs - have h := (Finset.prod_ne_zero_iff.mp hy) ⟨i, Finset.mem_Icc.mpr ⟨hi,hik⟩⟩ (Finset.mem_univ _) - exact h - -end OldPathWeight - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteOldRun -attribute [local instance] Classical.propDecidable Classical.decEq -variable {W : Type*} - - -def oldRunConsEquiv (k : ℕ) : (Fin (k+1) → W) ≃ W × (Fin k → W) where - toFun y := (y 0, Fin.tail y) - invFun y := Fin.cons y.1 y.2 - left_inv := Fin.cons_self_tail - right_inv y := by simp - - - -noncomputable def oldRunWeight (K : ℕ → W → W → ℝ) : (k : ℕ) → W → (Fin k → W) → ℝ - | 0, _, _ => 1 - | k+1, z, y => K (k+1) z (y 0) * oldRunWeight K k (y 0) (Fin.tail y) - -theorem oldRunWeight_nonneg (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) - (k : ℕ) (z : W) (y : Fin k → W) : 0 ≤ oldRunWeight K k z y := by - induction k generalizing z with - | zero => exact zero_le_one - | succ k ih => exact mul_nonneg (hK _ _ _) (ih _ _) - -theorem sum_oldRunWeight_succ [Fintype W] (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) : - (∑ y : Fin (k+1) → W, oldRunWeight K (k+1) z y) = - ∑ a : W, K (k+1) z a * ∑ y : Fin k → W, oldRunWeight K k a y := by - rw [Fintype.sum_equiv (oldRunConsEquiv k) _ - (fun y => K (k+1) z y.1 * oldRunWeight K k y.1 y.2) (by intro y; rfl), - Fintype.sum_prod_type] - simp only [Finset.mul_sum] - - - -theorem sum_oldRunWeight_le [Fintype W] (K : ℕ → W → W → ℝ) - (hK : ∀ i a b, 0 ≤ K i a b) (u : ℝ) (hu : 0 ≤ u) - (hrow : ∀ i a, ∑ b, K i a b ≤ u) (k : ℕ) (z : W) : - (∑ y : Fin k → W, oldRunWeight K k z y) ≤ u^k := by - induction k generalizing z with - | zero => simp [oldRunWeight] - | succ k ih => - rw [sum_oldRunWeight_succ] - calc - _ ≤ ∑ a : W, K (k+1) z a * u^k := Finset.sum_le_sum fun a _ => - mul_le_mul_of_nonneg_left (ih a) (hK _ _ _) - _ = (∑ a : W, K (k+1) z a) * u^k := (Finset.sum_mul _ _ _).symm - _ ≤ u * u^k := mul_le_mul_of_nonneg_right (hrow _ _) (pow_nonneg hu _) - _ = u^(k+1) := by ring - -theorem sum_oldRunWeight_eq [Fintype W] (K : ℕ → W → W → ℝ) - (u : ℝ) (hrow : ∀ i a, ∑ b, K i a b = u) (k : ℕ) (z : W) : - (∑ y : Fin k → W, oldRunWeight K k z y) = u^k := by - induction k generalizing z with - | zero => simp [oldRunWeight] - | succ k ih => - simp only [sum_oldRunWeight_succ, ih, ← Finset.sum_mul, hrow] - ring - - - -def oldRunVertices : (k : ℕ) → W → (Fin k → W) → ℕ → W - | 0, z, _ => fun _ => z - | k+1, z, y => fun i => if i ≤ k then oldRunVertices k (y 0) (Fin.tail y) i else z - -@[simp] theorem oldRunVertices_last (k : ℕ) (z : W) (y : Fin k → W) : - oldRunVertices k z y k = z := by - cases k <;> simp [oldRunVertices] - -theorem oldRunVertices_succ_of_le (k : ℕ) (z : W) (y : Fin (k+1) → W) - (i : ℕ) (hi : i ≤ k) : - oldRunVertices (k+1) z y i = oldRunVertices k (y 0) (Fin.tail y) i := by - simp only [oldRunVertices, ite_eq_left hi] - - - -theorem oldPathWeight_oldRunVertices (k : ℕ) (q : Set E → W → W → ℝ) - (η : ℕ → Set E) (z : W) (y : Fin k → W) : - oldPathWeight k q (oldRunVertices k z y) η = - oldRunWeight (fun i => q (η i)) k z y := by - induction k generalizing z with - | zero => - unfold oldPathWeight - rw [Finset.prod_coe_sort (Finset.Icc 1 0) - (fun i => q (η i) (oldRunVertices 0 z y i) (oldRunVertices 0 z y (i-1)))] - simp [oldRunWeight] - | succ k ih => - unfold oldPathWeight - rw [Finset.prod_coe_sort (Finset.Icc 1 (k+1)) - (fun i => q (η i) (oldRunVertices (k+1) z y i) (oldRunVertices (k+1) z y (i-1))), - Finset.prod_Icc_succ_top (by omega)] - have he : (∏ i ∈ Finset.Icc 1 k, - q (η i) (oldRunVertices (k+1) z y i) (oldRunVertices (k+1) z y (i-1))) = - oldPathWeight k q (oldRunVertices k (y 0) (Fin.tail y)) η := by - unfold oldPathWeight - rw [Finset.prod_coe_sort (Finset.Icc 1 k) - (fun i => q (η i) (oldRunVertices k (y 0) (Fin.tail y) i) - (oldRunVertices k (y 0) (Fin.tail y) (i-1)))] - apply Finset.prod_congr rfl - intro i hi - have hi' := Finset.mem_Icc.mp hi - rw [oldRunVertices_succ_of_le _ _ _ _ hi'.2, - oldRunVertices_succ_of_le _ _ _ _ (by omega)] - rw [he, ih, oldRunVertices_last, Nat.add_sub_cancel, - oldRunVertices_succ_of_le _ _ _ _ (le_refl _), oldRunVertices_last] - exact mul_comm _ _ - -end FiniteOldRun - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section IndependentOldRun -attribute [local instance] Classical.propDecidable Classical.decEq -variable {W : Type*} - - -noncomputable def finiteOldKernel (Q : Finset E) (p : ℝ) - (q : Set E → W → W → ℝ) (a b : W) : ℝ := - finiteFieldIntegral Q p (fun ω => q ω a b) - -theorem finiteOldKernel_nonneg (Q : Finset E) (p : unitInterval) - (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) (a b : W) : - 0 ≤ finiteOldKernel Q p q a b := - finiteFieldIntegral_nonneg Q p _ (fun _ => hq _ _ _) - - - -theorem oldRunWeight_integral (Q : Finset E) (p : ℝ) (k : ℕ) - (q : Set E → W → W → ℝ) (z : W) (y : Fin k → W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p - (fun η => oldRunWeight (fun i => q (η i)) k z y) = - oldRunWeight (fun _ => finiteOldKernel Q p q) k z y := by - calc - _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p - (fun η => oldPathWeight k q (oldRunVertices k z y) η) := by - apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) - funext η - exact (oldPathWeight_oldRunVertices k q η z y).symm - _ = ∏ i : ↥(Finset.Icc 1 k), finiteOldKernel Q p q - (oldRunVertices k z y i) (oldRunVertices k z y (i.val-1)) := - oldPathWeight_integral Q k p q _ - _ = oldRunWeight (fun _ => finiteOldKernel Q p q) k z y := - oldPathWeight_oldRunVertices k (fun (_ : Set E) => finiteOldKernel Q p q) - (fun _ => ∅) z y - - - -theorem independent_oldRun_success [Fintype W] (Q : Finset E) (p : ℝ) (k : ℕ) - (q : Set E → W → W → ℝ) (u : ℝ) - (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b = u) (z : W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p - (fun η => ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) = u^k := by - rw [finiteFamilyIntegral_sum] - simp only [oldRunWeight_integral] - exact sum_oldRunWeight_eq _ u (fun _ => hrow) k z - - - -theorem independent_oldRun_success_le [Fintype W] (Q : Finset E) (p : unitInterval) (k : ℕ) - (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) (u : ℝ) (hu : 0 ≤ u) - (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) (z : W) : - finiteFamilyIntegral Q (Finset.Icc 1 k) p - (fun η => ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) ≤ u^k := by - rw [finiteFamilyIntegral_sum] - simp only [oldRunWeight_integral] - exact sum_oldRunWeight_le _ (fun _ => finiteOldKernel_nonneg Q p q hq) u hu (fun _ => hrow) k z - -end IndependentOldRun - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WeightedCodeFiber -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem sum_comp_le_sum_of_injective {A B : Type*} [Fintype A] [Fintype B] - (f : A → B) (hf : Function.Injective f) (w : B → ℝ) (hw : ∀ b, 0 ≤ w b) : - (∑ a, w (f a)) ≤ ∑ b, w b := by - rw [← Finset.sum_image hf.injOn] - exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) - (fun b _ _ => hw b) - - -theorem finite_sum_group_weight {A B : Type*} [Fintype A] [Fintype B] - (f : A → B) (m : A → ℝ) (w : B → ℝ) : - (∑ a, m a * w (f a)) = ∑ b, w b * ∑ a, if f a = b then m a else 0 := by - simp only [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - simp only [mul_ite,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,ite_true] - exact mul_comm _ _ - - - -theorem finite_choice_fiber_le {A B C P : Type*} [Fintype A] [Fintype P] - (f : A → B) (ctx : A → C) (choice : A → P) - (hir : Function.Injective (fun a => (ctx a,choice a,f a))) - (hctx : ∀ a b, f a = f b → ctx a = ctx b) - (q : C → P → ℝ) (hq : ∀ c p, 0 ≤ q c p) - (hrow : ∀ c, ∑ p, q c p ≤ 1) (b : B) : - (∑ a, if f a = b then q (ctx a) (choice a) else 0) ≤ 1 := by - let J := {a : A // f a = b} - by_cases hne : Nonempty J - · let a₀ : J := Classical.choice hne - have hc (a : J) : ctx a.val = ctx a₀.val := hctx _ _ (a.property.trans a₀.property.symm) - have hi : Function.Injective (fun a : J => choice a.val) := by - intro a a' he - apply Subtype.ext - apply hir - exact Prod.ext (hctx _ _ (a.property.trans a'.property.symm)) - (Prod.ext he (a.property.trans a'.property.symm)) - have hb := sum_comp_le_sum_of_injective (fun a : J => choice a.val) hi - (q (ctx a₀.val)) (hq _) - have he : (∑ a, if f a = b then q (ctx a) (choice a) else 0) = - ∑ a : J, q (ctx a) (choice a) := by - rw [← Finset.sum_filter] - exact Finset.sum_subtype _ (by intro a; simp) _ - rw [he] - simpa only [hc] using hb.trans (hrow (ctx a₀.val)) - · have hn (a : A) : f a ≠ b := fun h => hne ⟨⟨a,h⟩⟩ - simp only [ite_eq_right (hn _),Finset.sum_const_zero,zero_le_one] - - - -theorem finite_weighted_code_mass_le {A B C P : Type*} [Fintype A] [Fintype B] [Fintype P] - (f : A → B) (ctx : A → C) (choice : A → P) - (hir : Function.Injective (fun a => (ctx a,choice a,f a))) - (hctx : ∀ a b, f a = f b → ctx a = ctx b) - (q : C → P → ℝ) (hq : ∀ c p, 0 ≤ q c p) (hrow : ∀ c, ∑ p, q c p ≤ 1) - (w : B → ℝ) (hw : ∀ b, 0 ≤ w b) : - (∑ a, q (ctx a) (choice a) * w (f a)) ≤ ∑ b, w b := by - rw [finite_sum_group_weight] - apply Finset.sum_le_sum - intro b _ - calc - _ ≤ w b * 1 := mul_le_mul_of_nonneg_left - (finite_choice_fiber_le f ctx choice hir hctx q hq hrow b) (hw b) - _ = w b := mul_one _ - -end WeightedCodeFiber -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section WeightedInverseLoad -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteInverseLoad_weighted_le {I P : Type*} [Fintype I] [Fintype P] - (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) - (L : ℝ) (hL : 1 ≤ L) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (choice : I → P) (hir : Function.Injective (fun a => (inp a,choice a,steps a))) - (q : SpliceState E → P → ℝ) (hq : ∀ s b, 0 ≤ q s b) - (hrow : ∀ s, ∑ b, q s b ≤ 1) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) - (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ - (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) - (t : SpliceState E) : - finiteInverseLoad out (fun a => q (inp a) (choice a) * ∏ i : Fin k, - (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ - inverseCodeMass M L ^ k := by - let J := {a : I // out a = t} - let c (a : J) := gapSpliceCode G (out a.val).1 x z (steps a.val) - have hvalid (a : J) : ValidSparseGapCode k M (c a) := by - have hv := (htrace a.val).valid_gap_code G hloc x (inp a.val).2 (y a.val) k 0 M - (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L (hgood a.val) - simpa only [c,hz a.val] using hv.1 - let arr (a : J) := sparseGapArray k M (c a) (hvalid a) - let ctx (a : J) := (inp a.val,steps a.val) - have hc (a b : J) (he : arr a = arr b) : ctx a = ctx b := by - have ho : out a.val = out b.val := a.property.trans b.property.symm - have hcode : c a = c b := sparseGapArray_injective k M (c a) (c b) - (hvalid a) (hvalid b) he - have htB : SpliceTrace G x (inp b.val).2 (y b.val) k 0 - (inp b.val).1 (steps b.val) (out a.val).1 := by - rw [ho] - exact htrace b.val - have heB : SpliceExecution G x (inp b.val) (steps b.val) (out a.val) := ho.symm ▸ hex b.val - have hg : gapSpliceCode G (out a.val).1 x (y a.val k) (steps a.val) = - gapSpliceCode G (out a.val).1 x (y a.val k) (steps b.val) := by - simpa only [c,hz a.val,ho] using hcode - have hze : y a.val k = y b.val k := (hz a.val).trans (hz b.val).symm - have hs := (htrace a.val).code_unique_of_gapCode G x (inp a.val).2 (inp b.val).2 - (y a.val) (y b.val) k 0 (inp a.val).1 (inp b.val).1 (out a.val).1 - (steps a.val) (steps b.val) htB hze (hfin a.val) hg - have hi := (htrace a.val).input_unique_of_gapCode G x (inp a.val).2 (inp b.val).2 - (y a.val) (y b.val) k 0 (inp a.val).1 (inp b.val).1 (out a.val).1 - (steps a.val) (steps b.val) htB hze (hfin a.val) hg (out a.val).2 (hex a.val) heB - exact Prod.ext hi hs - have hi : Function.Injective (fun a : J => (ctx a,choice a.val,arr a)) := by - intro a b he - apply Subtype.ext - apply hir - have hec := congrArg Prod.fst he - have hin : inp a.val = inp b.val := congrArg (fun s : SpliceState E × List (ℕ × E) => s.1) hec - have hst : steps a.val = steps b.val := congrArg (fun s : SpliceState E × List (ℕ × E) => s.2) hec - exact Prod.ext hin (Prod.ext (congrArg (fun z => z.2.1) he) hst) - let w (b : Fin k → Fin (M+1)) := ∏ i, gapLetterWeight L (b i).val - have hb := finite_weighted_code_mass_le arr ctx (fun a : J => choice a.val) hi hc - (fun s b => q s.1 b) (fun s => hq s.1) (fun s => hrow s.1) w - (fun b => Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L (by linarith) _)) - change (∑ a : J, q (inp a.val) (choice a.val) * w (arr a)) ≤ ∑ b, w b at hb - have he : finiteInverseLoad out (fun a => q (inp a) (choice a) * ∏ i : Fin k, - (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t = - ∑ a : J, q (inp a.val) (choice a.val) * ∏ i : Fin k, - (traceContactCount G (inp a.val).2 (y a.val) (out a.val).1 x (steps a.val) (i.val+1):ℝ)⁻¹ := by - rw [finiteInverseLoad,← Finset.sum_filter] - exact Finset.sum_subtype _ (by intro a; simp) _ - rw [he] - calc - _ ≤ ∑ a : J, q (inp a.val) (choice a.val) * w (arr a) := by - apply Finset.sum_le_sum - intro a _ - apply mul_le_mul_of_nonneg_left _ (hq _ _) - apply Finset.prod_le_prod₀ (fun _ _ => by positivity) - intro i _ - have h := ((htrace a.val).contact_weight_bound G hloc x (inp a.val).2 (y a.val) - k 0 M (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L hL - (hgood a.val) (i.val+1)).2 - simpa only [w,arr,sparseGapArray,c,hz a.val] using h - _ ≤ ∑ b, w b := hb - _ = _ := total_gap_code_mass k M L - -end WeightedInverseLoad -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OldRunInverseLoad -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finiteInverseLoad_oldRun_le {I W : Type*} [Fintype I] [Fintype W] - (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) - (L : ℝ) (hL : 1 ≤ L) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (start : W) (path : I → Fin k → W) - (hir : Function.Injective (fun a => (inp a,path a,steps a))) - (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) - (hrow : ∀ ω a, ∑ b, q ω a b ≤ 1) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) - (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ - (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) - (t : SpliceState E) : - finiteInverseLoad out (fun a => oldRunWeight (fun i => q ((inp a).2 i)) k start (path a) * - ∏ i : Fin k, (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ - inverseCodeMass M L ^ k := by - apply finiteInverseLoad_weighted_le G hloc x z k M L hL inp out steps y path hir - (fun s b => oldRunWeight (fun i => q (s.2 i)) k start b) - (fun s b => oldRunWeight_nonneg _ (fun _ => hq _) k start b) _ htrace hex hz hfin hgood t - intro s - simpa only [one_pow] using sum_oldRunWeight_le (fun i => q (s.2 i)) - (fun _ => hq _) 1 zero_le_one (fun _ => hrow _) k start - -end OldRunInverseLoad -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section ChoiceForwardDensity -attribute [local instance] Classical.propDecidable Classical.decEq -variable {P : Type*} - - - -abbrev FiniteChoiceTraceIndex (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) := - (r : P) × FiniteTraceIndex G x k Q (A r) (y r) - -def choiceTraceInput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (a : FiniteChoiceTraceIndex G x k Q A y) : SpliceState E := - traceIndexInput G x k Q (A a.1) (y a.1) a.2 - -def choiceTraceOutput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (a : FiniteChoiceTraceIndex G x k Q A y) : SpliceState E := - traceIndexOutput G x k Q (A a.1) (y a.1) a.2 - -def choiceTraceCode (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (a : FiniteChoiceTraceIndex G x k Q A y) : List (ℕ × E) := - traceIndexCode G x k Q (A a.1) (y a.1) a.2 - -noncomputable def choiceTraceMass (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (q : SpliceState E → P → ℝ) (a : FiniteChoiceTraceIndex G x k Q A y) : ℝ := - q (choiceTraceInput G x k Q A y a) a.1 * - traceIndexMass G x k Q (A a.1) (y a.1) a.2 - -theorem choiceTrace_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) : - Function.Injective (fun a : FiniteChoiceTraceIndex G x k Q A y => - (choiceTraceInput G x k Q A y a,a.1,choiceTraceCode G x k Q A y a)) := by - rintro ⟨r,a⟩ ⟨r',b⟩ he - have hr : r = r' := congrArg (fun z => z.2.1) he - subst r' - have hin : traceIndexInput G x k Q (A r) (y r) a = - traceIndexInput G x k Q (A r) (y r) b := - congrArg (fun z : SpliceState E × P × List (ℕ × E) => z.1) he - have hcode : traceIndexCode G x k Q (A r) (y r) a = - traceIndexCode G x k Q (A r) (y r) b := - congrArg (fun z : SpliceState E × P × List (ℕ × E) => z.2.2) he - have hab : a = b := traceIndex_injective G x k Q (A r) (y r) (Prod.ext hin hcode) - subst b - rfl - -noncomputable def finiteChoiceForwardLoad [Fintype P] - (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (q : SpliceState E → P → ℝ) : SpliceState E → ℝ := - finiteInverseLoad (choiceTraceOutput G x k Q A y) (choiceTraceMass G x k Q A y q) - - -theorem finiteChoiceForwardLoad_bounds [Fintype P] - (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) - (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (q : SpliceState E → P → ℝ) (hq : ∀ s r, 0 ≤ q s r) - (hrow : ∀ s, ∑ r, q s r ≤ 1) - (hA : ∀ r, A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hz : ∀ r s, s ∈ A r → y r s k = z) - (hgood : ∀ r s, s ∈ A r → ∀ i, 1 ≤ i → i ≤ k → - (cluster G (s.2 i) (y r s i)).Finite ∧ - (cluster G (s.2 i) (y r s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y r s i) L) - (t : SpliceState E) : - 0 ≤ finiteChoiceForwardLoad G x k Q A y q t ∧ - finiteChoiceForwardLoad G x k Q A y q t ≤ inverseCodeMass M L ^ k := by - constructor - · apply finiteInverseLoad_nonneg - intro a - exact mul_nonneg (hq _ _) (Finset.prod_nonneg (fun _ _ => by positivity)) - · apply finiteInverseLoad_weighted_le G hloc x z k M L hL - (choiceTraceInput G x k Q A y) (choiceTraceOutput G x k Q A y) - (choiceTraceCode G x k Q A y) (fun a => y a.1 a.2.1.val) Sigma.fst - (choiceTrace_injective G x k Q A y) q hq hrow - (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1) - (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).2) - (fun a => hz a.1 _ a.2.1.property) _ - (fun a => hgood a.1 _ a.2.1.property) t - intro a - have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp - (traceIndexOutput_mem G x k Q (A a.1) (y a.1) (hA a.1) a.2) - exact cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x - - - -theorem sum_traceIndexMass [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) - (x : V) (k M : ℕ) (Q : Finset E) (A : Finset (SpliceState E)) - (y : SpliceState E → ℕ → V) (s : ↥A) - (hs : s.val ∈ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hy : y s.val 0 ∈ cluster G s.val.1 x) - (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (s.val.2 i) (y s.val i) (y s.val (i-1))) - (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (s.val.2 i) (y s.val i)).Finite ∧ - (cluster G (s.val.2 i) (y s.val i)).ncard ≤ M) : - (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), - traceIndexMass G x k Q A y ⟨s,c⟩) = 1 := by - have hs' := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s.val).mp hs - have hn := sum_finite_trace_probabilities G hloc x s.val.2 (y s.val) k M Q - (fun i _ _ => hs'.2.1 i) hchain hcaps 0 (Nat.zero_le _) s.val.1 hy - (cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs'.1) x) - rw [← Finset.sum_coe_sort (finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q)] at hn - rw [← hn] - apply Finset.sum_congr rfl - intro c _ - have ht := ((mem_finiteTraceCodes_iff G x s.val.2 (y s.val) k 0 s.val.1 Q c.val).mp c.property).2 - have hf := ht.runMasks_first G x s.val.2 (y s.val) k 0 s.val.1 _ c.val s.val.2 (by intros; rfl) - simp only [traceIndexMass,traceIndexOutput,hf] - - -theorem finiteChoiceForwardLoad_mean [Fintype P] [Nonempty E] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) - (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) - (q : SpliceState E → P → ℝ) - (hA : ∀ r, A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) - (hy : ∀ r s, s ∈ A r → y r s 0 ∈ cluster G s.1 x) - (hchain : ∀ r s, s ∈ A r → ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y r s i) (y r s (i-1))) - (hcaps : ∀ r s, s ∈ A r → ∀ i ∈ Finset.Icc 1 k, - (cluster G (s.2 i) (y r s i)).Finite ∧ (cluster G (s.2 i) (y r s i)).ncard ≤ M) : - (∑ t ∈ finiteSpliceDomain Q (Finset.Icc 1 k), spliceTupleWeight Q (Finset.Icc 1 k) p t * - finiteChoiceForwardLoad G x k Q A y q t) = - ∑ r, ∑ s ∈ A r, spliceTupleWeight Q (Finset.Icc 1 k) p s * q s r := by - have hd := finiteInverseLoad_density G x k Q p - (choiceTraceInput G x k Q A y) (choiceTraceOutput G x k Q A y) - (choiceTraceCode G x k Q A y) (fun a => y a.1 a.2.1.val) - (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1) - (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).2) - (choiceTraceMass G x k Q A y q) (finiteSpliceDomain Q (Finset.Icc 1 k)) - (fun a => traceIndexOutput_mem G x k Q (A a.1) (y a.1) (hA a.1) a.2) (fun _ => 1) - simp only [mul_one] at hd - unfold finiteChoiceForwardLoad - rw [← hd,Fintype.sum_sigma] - apply Finset.sum_congr rfl - intro r _ - rw [Fintype.sum_sigma,← Finset.sum_coe_sort (A r) - (fun s => spliceTupleWeight Q (Finset.Icc 1 k) p s * q s r)] - apply Finset.sum_congr rfl - intro s _ - change (∑ c : ↥(finiteTraceCodes G x s.val.2 (y r s.val) k 0 s.val.1 Q), - spliceTupleWeight Q (Finset.Icc 1 k) p s.val * - (q s.val r * traceIndexMass G x k Q (A r) (y r) ⟨s,c⟩)) = _ - simp only [← mul_assoc,← Finset.mul_sum] - rw [sum_traceIndexMass G hloc x k M Q (A r) (y r) s (hA r s.property) - (hy r _ s.property) (hchain r _ s.property) (hcaps r _ s.property),mul_one] - -end ChoiceForwardDensity -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EndpointRootMass -attribute [local instance] Classical.propDecidable Classical.decEq - - -noncomputable def auxiliaryTupleWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) - (s : SpliceState E) : ℝ := ∏ i ∈ J, bernoulliWeight Q (domainBits Q (s.2 i)) p - -theorem auxiliaryTupleWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) - (s : SpliceState E) : 0 ≤ auxiliaryTupleWeight Q J p s := - Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p - - - -noncomputable def endpointRootMass {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) - (endpoint : I → V) (m : I → ℝ) (ω : Set E) (z : V) : ℝ := - ∑ a, if (out a).1 = ω ∧ endpoint a = z then auxiliaryTupleWeight Q J p (out a) * m a else 0 - -theorem endpointRootMass_nonneg {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) - (endpoint : I → V) (m : I → ℝ) (hm : ∀ a, 0 ≤ m a) (ω : Set E) (z : V) : - 0 ≤ endpointRootMass Q J p out endpoint m ω z := by - apply Finset.sum_nonneg - intro a _ - split_ifs - · exact mul_nonneg (auxiliaryTupleWeight_nonneg Q J p _) (hm a) - · exact le_refl 0 - - -theorem finiteRootLoad_eq_sum {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) (m : I → ℝ) - (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) (ω : FiniteField Q) : - finiteRootLoad Q J p (finiteInverseLoad out m) ω = - ∑ a, if (out a).1 = finiteFieldSet Q ω then auxiliaryTupleWeight Q J p (out a) * m a else 0 := by - simp only [finiteRootLoad,finiteInverseLoad,Finset.mul_sum,mul_ite,mul_zero] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - obtain ⟨⟨r,η⟩,_,ha⟩ := Finset.mem_image.mp (hs a) - change (finiteFieldSet Q r,finiteFieldFamily Q J η) = out a at ha - rw [← ha] - have he (θ : ↥J → FiniteField Q) : - (finiteFieldSet Q r,finiteFieldFamily Q J η) = (finiteFieldSet Q ω,finiteFieldFamily Q J θ) ↔ - r = ω ∧ η = θ := by - constructor - · intro h - exact ⟨finiteFieldSet_injective Q (congrArg Prod.fst h), - finiteFieldFamily_injective Q J (congrArg Prod.snd h)⟩ - · rintro ⟨rfl,rfl⟩; rfl - simp only [he] - by_cases hr : r = ω - · subst r - simp only [true_and,ite_true,Finset.sum_ite_eq,Finset.mem_univ] - rw [auxiliaryTupleWeight,prod_fieldFamilyWeight] - · have hr' : finiteFieldSet Q r ≠ finiteFieldSet Q ω := fun h => hr (finiteFieldSet_injective Q h) - simp [hr,hr'] - - - -theorem endpointRootMass_le {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) - (endpoint : I → V) (m : I → ℝ) (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) - (z : V) (C : ℝ) - (hC : ∀ t ∈ finiteSpliceDomain Q J, finiteInverseLoad out - (fun a => if endpoint a = z then m a else 0) t ≤ C) (ω : FiniteField Q) : - endpointRootMass Q J p out endpoint m (finiteFieldSet Q ω) z ≤ C := by - have hb := finiteRootLoad_le Q J p _ C hC ω - rw [finiteRootLoad_eq_sum Q J p out _ hs ω] at hb - convert hb using 1 - unfold endpointRootMass - apply Finset.sum_congr rfl - intro a _ - split_ifs <;> simp_all - - - -theorem sum_endpointRootMass {I : Type*} [Fintype I] - (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) - (endpoint : I → V) (m : I → ℝ) (ω : Set E) (S : Finset V) : - (∑ z ∈ S, endpointRootMass Q J p out endpoint m ω z) = - ∑ a, if (out a).1 = ω ∧ endpoint a ∈ S then auxiliaryTupleWeight Q J p (out a) * m a else 0 := by - simp only [endpointRootMass] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro a _ - by_cases hr : (out a).1 = ω - · simp only [hr,true_and,Finset.sum_ite_eq] - · simp [hr] - -end EndpointRootMass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NearPairMass -attribute [local instance] Classical.propDecidable Classical.decEq - - - -theorem finite_near_pair_mass_le_cover {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] - (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) - (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) - (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) - (endpoint : I₂ → V) (R : I₁ → I₂ → Prop) (S : I₁ → Finset V) - (hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → endpoint b ∈ S a) : - (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ R a b then - jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ - ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a * - ∑ z ∈ S a, endpointRootMass Q J₂ p out₂ endpoint m₂ (out₁ a).1 z := by - apply Finset.sum_le_sum - intro a _ - rw [sum_endpointRootMass,Finset.mul_sum] - apply Finset.sum_le_sum - intro b _ - by_cases h : (out₁ a).1 = (out₂ b).1 ∧ R a b - · have hh : (out₂ b).1 = (out₁ a).1 ∧ endpoint b ∈ S a := - ⟨h.1.symm,hS a b h.1 h.2⟩ - rw [ite_eq_left h,ite_eq_left hh] - change (spliceTupleWeight Q J₁ p (out₁ a) * auxiliaryTupleWeight Q J₂ p (out₂ b)) * - m₁ a * m₂ b ≤ _ - ring_nf - exact le_refl _ - · rw [ite_eq_right h] - apply mul_nonneg (mul_nonneg (spliceTupleWeight_nonneg Q J₁ p _) (hm₁ a)) - split_ifs - · exact mul_nonneg (auxiliaryTupleWeight_nonneg Q J₂ p _) (hm₂ b) - · exact le_refl 0 - - - -theorem finite_near_pair_mass_le {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] - (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) - (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) - (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) - (endpoint : I₂ → V) (R : I₁ → I₂ → Prop) (S : I₁ → Finset V) - (hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → endpoint b ∈ S a) - (N : ℕ) (hN : ∀ a, (S a).card ≤ N) (C : ℝ) (hC : 0 ≤ C) - (hb : ∀ a z, z ∈ S a → endpointRootMass Q J₂ p out₂ endpoint m₂ (out₁ a).1 z ≤ C) : - (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ R a b then - jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ - (N:ℝ) * C * ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a := by - apply (finite_near_pair_mass_le_cover Q J₁ J₂ p out₁ out₂ m₁ m₂ hm₁ hm₂ endpoint R S hS).trans - calc - _ ≤ ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a * ((N:ℝ)*C) := by - apply Finset.sum_le_sum - intro a _ - apply mul_le_mul_of_nonneg_left _ - (mul_nonneg (spliceTupleWeight_nonneg Q J₁ p _) (hm₁ a)) - calc - _ ≤ ∑ _z ∈ S a, C := Finset.sum_le_sum (fun z hz => hb a z hz) - _ = ((S a).card:ℝ) * C := by simp - _ ≤ (N:ℝ)*C := mul_le_mul_of_nonneg_right (by exact_mod_cast hN a) hC - _ = _ := by rw [← Finset.sum_mul]; ring - -end NearPairMass -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section EndpointInverseBound -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem finiteInverseLoad_subtype {I : Type*} [Fintype I] - (out : I → SpliceState E) (m : I → ℝ) (P : I → Prop) (t : SpliceState E) : - finiteInverseLoad out (fun a => if P a then m a else 0) t = - finiteInverseLoad (fun a : {a : I // P a} => out a.val) (fun a => m a.val) t := by - unfold finiteInverseLoad - have he : (∑ a, if out a = t then if P a then m a else 0 else 0) = - ∑ a, if P a then if out a = t then m a else 0 else 0 := by - apply Finset.sum_congr rfl - intro a _ - split_ifs <;> rfl - rw [he,← Finset.sum_filter] - exact Finset.sum_subtype _ (by intro a; simp) _ - - - -theorem endpointInverseLoad_le {I P : Type*} [Fintype I] [Fintype P] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) - (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) - (endpoint : I → V) (choice : I → P) - (hir : Function.Injective (fun a => (inp a,endpoint a,choice a,steps a))) - (q : V → SpliceState E → P → ℝ) (hq : ∀ z s b, 0 ≤ q z s b) - (hrow : ∀ z s, ∑ b, q z s b ≤ 1) - (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) - (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) - (hz : ∀ a, y a k = endpoint a) (hfin : ∀ a, (cluster G (out a).1 x).Finite) - (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ - (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) - (z : V) (t : SpliceState E) : - finiteInverseLoad out (fun a => if endpoint a = z then - q (endpoint a) (inp a) (choice a) * ∏ i : Fin k, - (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹ else 0) t ≤ - inverseCodeMass M L ^ k := by - rw [finiteInverseLoad_subtype] - let J := {a : I // endpoint a = z} - have hi : Function.Injective (fun a : J => (inp a.val,choice a.val,steps a.val)) := by - intro a b he - apply Subtype.ext - apply hir - have hin : inp a.val = inp b.val := congrArg (fun s : SpliceState E × P × List (ℕ × E) => s.1) he - exact Prod.ext hin (Prod.ext (a.property.trans b.property.symm) (congrArg (fun s : SpliceState E × P × List (ℕ × E) => s.2) he)) - have hb := finiteInverseLoad_weighted_le G hloc x z k M L hL - (fun a : J => inp a.val) (fun a : J => out a.val) (fun a : J => steps a.val) - (fun a : J => y a.val) (fun a : J => choice a.val) hi (q z) (hq z) (hrow z) - (fun a => htrace a.val) (fun a => hex a.val) (fun a => (hz a.val).trans a.property) - (fun a => hfin a.val) (fun a => hgood a.val) t - convert hb using 1 - apply congrArg (fun f : J → ℝ => finiteInverseLoad (fun a : J => out a.val) f t) - funext a - rw [a.property] - -end EndpointInverseBound -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NearHangingMass -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem SpliceTrace.head_hanging (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) : - hangingSide G ωf x e = cluster G ωf x \ cluster G ω x := by - rw [hangingSide,h.head_cut G x η y k j i ω ωf e rest] - -theorem SpliceTrace.head_hanging_cap (G : BondGraph V E) (x : V) (η : ℕ → Set E) - (y : ℕ → V) (k j i M : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) - (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) - (hcaps : ∀ l, 1 ≤ l → l ≤ k → - (cluster G (η l) (y l)).Finite ∧ (cluster G (η l) (y l)).ncard ≤ M) : - (hangingSide G ωf x e).ncard ≤ k*M := by - rw [h.head_hanging G x η y k j i ω ωf e rest] - exact (h.added_finite_cap G x η y k j M ω ωf ((i,e)::rest) hcaps).2 - - - -theorem finite_near_hanging_mass_le {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] - (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (v d : ℕ) - (hdeg : ∀ a, degree G a ≤ d) - (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) - (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) - (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) - (z₁ : I₁ → V) (z₂ : I₂ → V) (e₁ : I₁ → E) (e₂ : I₂ → E) - (hfin : ∀ a, (cluster G (out₁ a).1 x).Finite) - (hp₁ : ∀ a, OpenMarkedPivotal G (out₁ a).1 {z₁ a} x (e₁ a)) - (hp₂ : ∀ b, OpenMarkedPivotal G (out₂ b).1 {z₂ b} x (e₂ b)) - (hcap₁ : ∀ a, (hangingSide G (out₁ a).1 x (e₁ a)).ncard ≤ v) - (hcap₂ : ∀ b, (hangingSide G (out₂ b).1 x (e₂ b)).ncard ≤ v) - (C : ℝ) (hC : 0 ≤ C) - (hb : ∀ a z, endpointRootMass Q J₂ p out₂ z₂ m₂ (out₁ a).1 z ≤ C) : - (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ - ¬GraphSeparated G (hangingSide G (out₁ a).1 x (e₁ a)) - (hangingSide G (out₂ b).1 x (e₂ b)) then - jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ - ((v+v^2+d*v^3:ℕ):ℝ) * C * ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a := by - let R : I₁ → I₂ → Prop := fun a b => - ¬GraphSeparated G (hangingSide G (out₁ a).1 x (e₁ a)) (hangingSide G (out₂ b).1 x (e₂ b)) - let S := fun a => nearHangingEndpoints G hloc (out₁ a).1 x (z₁ a) (e₁ a) v (hfin a) - have hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → z₂ b ∈ S a := by - intro a b he hn - have hp := hp₂ b - have hc := hcap₂ b - change ¬GraphSeparated G _ _ at hn - rw [← he] at hp hc hn - exact mem_nearHangingEndpoints_of_not_separated G hloc (out₁ a).1 x (z₁ a) (z₂ b) - (e₁ a) (e₂ b) v (hfin a) (hp₁ a) hp hc hn - have hN : ∀ a, (S a).card ≤ v+v^2+d*v^3 := fun a => - nearHangingEndpoints_card_le G hloc (out₁ a).1 x (z₁ a) (e₁ a) v d - (hfin a) (hcap₁ a) hdeg - have ht := finite_near_pair_mass_le Q J₁ J₂ p out₁ out₂ m₁ m₂ hm₁ hm₂ z₂ R S hS - (v+v^2+d*v^3) hN C hC (fun a z _ => hb a z) - convert ht using 1 - apply Finset.sum_congr rfl - intro a _ - apply Finset.sum_congr rfl - intro b _ - by_cases h : (out₁ a).1 = (out₂ b).1 ∧ R a b - · rw [ite_eq_left h,ite_eq_left h] - · rw [ite_eq_right h,ite_eq_right h] - -end NearHangingMass - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section OldRunArrival -attribute [local instance] Classical.propDecidable Classical.decEq -variable {W : Type*} [Fintype W] - -noncomputable def oldRunArrival (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (A : Finset W) : ℝ := - ∑ y : Fin k → W, if oldRunVertices k z y 0 ∈ A then oldRunWeight K k z y else 0 - -theorem oldRunArrival_nonneg (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) - (k : ℕ) (z : W) (A : Finset W) : 0 ≤ oldRunArrival K k z A := by - apply Finset.sum_nonneg - intro y _ - split_ifs - · exact oldRunWeight_nonneg K hK k z y - · exact le_refl 0 - -theorem oldRunArrival_zero (K : ℕ → W → W → ℝ) (z : W) (A : Finset W) : - oldRunArrival K 0 z A = if z ∈ A then 1 else 0 := by - by_cases h : z ∈ A - · simp [oldRunArrival,oldRunVertices,oldRunWeight,h] - · simp [oldRunArrival,oldRunVertices,h] - -theorem oldRunArrival_succ (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (A : Finset W) : - oldRunArrival K (k+1) z A = ∑ a, K (k+1) z a * oldRunArrival K k a A := by - unfold oldRunArrival - rw [Fintype.sum_equiv (oldRunConsEquiv k) _ - (fun y => if oldRunVertices k y.1 y.2 0 ∈ A then - K (k+1) z y.1 * oldRunWeight K k y.1 y.2 else 0) - (by - intro y - by_cases h : oldRunVertices k (y 0) (Fin.tail y) 0 ∈ A - · simp [oldRunVertices_succ_of_le k z y 0 (Nat.zero_le k),oldRunConsEquiv,oldRunWeight,h] - · simp [oldRunVertices_succ_of_le k z y 0 (Nat.zero_le k),oldRunConsEquiv,h]), - Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro a _ - simp only [Finset.mul_sum,mul_ite,mul_zero] - - - -theorem sum_oldRunArrival_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) - (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) (k : ℕ) (A : Finset W) : - (∑ z, oldRunArrival K k z A) ≤ (A.card:ℝ) * u^k := by - induction k with - | zero => simp [oldRunArrival_zero] - | succ k ih => - simp only [oldRunArrival_succ] - rw [Finset.sum_comm] - calc - _ = ∑ a, (∑ z, K (k+1) z a) * oldRunArrival K k a A := by - simp only [Finset.sum_mul] - _ ≤ ∑ a, u * oldRunArrival K k a A := Finset.sum_le_sum fun a _ => - mul_le_mul_of_nonneg_right (hcol _ _) (oldRunArrival_nonneg K hK k a A) - _ = u * ∑ a, oldRunArrival K k a A := (Finset.mul_sum _ _ _).symm - _ ≤ u*((A.card:ℝ)*u^k) := mul_le_mul_of_nonneg_left ih hu - _ = (A.card:ℝ)*u^(k+1) := by ring - - -theorem sum_oldRunArrival_on_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) - (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) - (k : ℕ) (A Z : Finset W) : - (∑ z ∈ Z, oldRunArrival K k z A) ≤ (A.card:ℝ) * u^k := by - apply (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ Z) - (fun z _ _ => oldRunArrival_nonneg K hK k z A)).trans - exact sum_oldRunArrival_le K hK u hu hcol k A - - -theorem noSwitch_arrival_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) - (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) - (k n : ℕ) (hn : 0 < n) (A Z : Finset W) (hA : A.card ≤ 2*n) : - (n:ℝ)⁻¹ * ∑ z ∈ Z, oldRunArrival K k z A ≤ 2*u^k := by - have hn' : (0:ℝ) < n := by exact_mod_cast hn - calc - _ ≤ (n:ℝ)⁻¹ * ((A.card:ℝ)*u^k) := - mul_le_mul_of_nonneg_left (sum_oldRunArrival_on_le K hK u hu hcol k A Z) - (inv_nonneg.mpr hn'.le) - _ ≤ (n:ℝ)⁻¹ * ((2*(n:ℝ))*u^k) := mul_le_mul_of_nonneg_left - (mul_le_mul_of_nonneg_right (by exact_mod_cast hA) (pow_nonneg hu _)) (inv_nonneg.mpr hn'.le) - _ = 2*u^k := by field_simp - -end OldRunArrival - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section TrajectoryTransport -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - - - -theorem RootTransport.real (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) (m : V → V → ℝ) - (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) - (hr : ∀ x, Summable (m x)) (hc : ∀ y, Summable (fun x => m x y)) : - (∑ i, weight i * ∑' y, m (root i) y) = - (∑ i, weight i * ∑' x, m x (root i)) := by - have ht := htr (fun x y => (m x y:ℂ)) - (fun a ha x y => congrArg Complex.ofReal (hi a ha x y)) - (fun x => Complex.summable_ofReal.mpr (hr x)) - (fun y => Complex.summable_ofReal.mpr (hc y)) - apply Complex.ofReal_injective - simpa only [Complex.ofReal_sum,Complex.ofReal_mul,Complex.ofReal_tsum] using ht - - - -theorem transported_column_le (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) - (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) - (hr : ∀ x, Summable (m x)) (hcol : ∀ y, Summable (fun x => m x y)) - (B : ℝ) (hB : ∀ x, ∑' y, m x y ≤ B) (y : V) : - (∑' x, m x y) ≤ c*B := by - have ht := htr.real root weight Γ m hi hr hcol - have hb : (∑ i, weight i * ∑' x, m x (root i)) ≤ B := by - rw [← ht] - calc - _ ≤ ∑ i, weight i * B := Finset.sum_le_sum fun i _ => - mul_le_mul_of_nonneg_left (hB _) (hw i) - _ = B := by rw [← Finset.sum_mul,hw1,one_mul] - obtain ⟨i,a,ha,hay⟩ := hcov y - have he : (∑' x, m x y) = ∑' x, m x (root i) := by - rw [← hay,← a.tsum_eq (fun x => m x (a (root i)))] - exact tsum_congr (fun x => hi a ha x (root i)) - have hn : 0 ≤ ∑' x, m x (root i) := tsum_nonneg (fun x => hm x _) - have hs : weight i * ∑' x, m x (root i) ≤ ∑ j, weight j * ∑' x, m x (root j) := - Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (tsum_nonneg (fun x => hm x (root j)))) - (Finset.mem_univ i) - rw [he] - calc - _ ≤ (c*weight i) * ∑' x, m x (root i) := by - simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) hn - _ = c * (weight i * ∑' x, m x (root i)) := by ring - _ ≤ c * (∑ j, weight j * ∑' x, m x (root j)) := mul_le_mul_of_nonneg_left hs hc - _ ≤ c*B := mul_le_mul_of_nonneg_left hb hc - - - -theorem finite_trajectory_hit_le (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) - (hcol : ∀ y, Summable (fun x => m x y)) (B : ℝ) - (hb : ∀ y, ∑' x, m x y ≤ B) (h : V → ℝ) (A Z : Finset V) - (hh : ∀ x, h x ≤ ∑ y ∈ A, m x y) : - (∑ x ∈ Z, h x) ≤ (A.card:ℝ)*B := by - calc - _ ≤ ∑ x ∈ Z, ∑ y ∈ A, m x y := Finset.sum_le_sum fun x _ => hh x - _ = ∑ y ∈ A, ∑ x ∈ Z, m x y := Finset.sum_comm - _ ≤ ∑ y ∈ A, ∑' x, m x y := Finset.sum_le_sum fun y _ => - (hcol y).sum_le_tsum Z (fun x _ => hm x y) - _ ≤ ∑ _y ∈ A, B := Finset.sum_le_sum fun y _ => hb y - _ = (A.card:ℝ)*B := by simp - -end TrajectoryTransport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section NonnegativeTransport -attribute [local instance] Classical.propDecidable Classical.decEq -variable {ι : Type*} [Fintype ι] - -theorem mem_reachBall_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (ha : IsAut G a b) (x y : V) (n : ℕ) : - a y ∈ reachBall G (a x) n ↔ y ∈ reachBall G x n := by - constructor - · intro h - simpa only [Equiv.symm_apply_apply] using mem_reachBall_aut G (isAut_symm G ha) h - · exact mem_reachBall_aut G ha - - -def transportCut (G : BondGraph V E) (n : ℕ) (x y : V) : Prop := - y ∈ reachBall G x n ∧ x ∈ reachBall G y n - -theorem transportCut_mono (G : BondGraph V E) {n m : ℕ} (h : n ≤ m) - {x y : V} (hxy : transportCut G n x y) : transportCut G m x y := - ⟨reachBall_mono G x h hxy.1, reachBall_mono G y h hxy.2⟩ - -theorem transportCut_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} - (ha : IsAut G a b) (n : ℕ) (x y : V) : - transportCut G n (a x) (a y) ↔ transportCut G n x y := by - simp only [transportCut,mem_reachBall_aut_iff G ha] - -theorem exists_transportCut (G : BondGraph V E) (hconn : Connected G) - (y : V) (Z : Finset V) : ∃ n, ∀ x ∈ Z, transportCut G n x y := by - induction Z using Finset.induction_on with - | empty => exact ⟨0, by simp⟩ - | @insert x Z _ ih => - obtain ⟨n,hn⟩ := ih - obtain ⟨r,hr⟩ := exists_mem_reachBall (hconn x y) - obtain ⟨s,hs⟩ := exists_mem_reachBall (hconn y x) - refine ⟨max n (max r s), ?_⟩ - intro z hz - rcases Finset.mem_insert.mp hz with rfl | hz - · exact ⟨reachBall_mono G z (le_trans (le_max_left r s) (le_max_right n _)) hr, - reachBall_mono G y (le_trans (le_max_right r s) (le_max_right n _)) hs⟩ - · exact transportCut_mono G (le_max_left n _) (hn z hz) - - - -theorem transported_column_of_row_bound (G : BondGraph V E) - (hconn : Connected G) (hloc : LocallyFinite G) - (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) - (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) - (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) - (hr : ∀ x, Summable (m x)) (B : ℝ) (hB : ∀ x, ∑' y, m x y ≤ B) : - ∀ y, Summable (fun x => m x y) ∧ (∑' x, m x y) ≤ c*B := by - let cut (n : ℕ) (x y : V) : ℝ := if transportCut G n x y then m x y else 0 - have hn (n : ℕ) (x y : V) : 0 ≤ cut n x y := by - dsimp [cut]; split_ifs; exact hm x y; exact le_refl 0 - have hcRow (n : ℕ) (x : V) : Summable (cut n x) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x n).toFinset) - intro y hy - simp only [Set.Finite.mem_toFinset] at hy - exact ite_eq_right (fun h => hy h.1) - have hcCol (n : ℕ) (y : V) : Summable (fun x => cut n x y) := by - apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) - intro x hx - simp only [Set.Finite.mem_toFinset] at hx - exact ite_eq_right (fun h => hx h.2) - have hcInv (n : ℕ) : ∀ a ∈ Γ, ∀ x y, cut n (a x) (a y) = cut n x y := by - intro a ha x y - obtain ⟨b,hb⟩ := hΓ ha - simp only [cut,transportCut_aut G hb,hi a ha] - have hcBound (n : ℕ) (x : V) : (∑' y, cut n x y) ≤ B := by - apply le_trans ((hcRow n x).tsum_le_tsum (fun y => ?_) (hr x)) (hB x) - dsimp [cut]; split_ifs; exact le_refl _; exact hm x y - have hbound (y : V) (Z : Finset V) : (∑ x ∈ Z, m x y) ≤ c*B := by - obtain ⟨n,hnZ⟩ := exists_transportCut G hconn y Z - calc - _ = ∑ x ∈ Z, cut n x y := by - apply Finset.sum_congr rfl - intro x hx - exact (ite_eq_left (hnZ x hx)).symm - _ ≤ ∑' x, cut n x y := (hcCol n y).sum_le_tsum Z (fun x _ => hn n x y) - _ ≤ c*B := transported_column_le root weight Γ htr hcov hw hw1 c hc hmin - (cut n) (hn n) (hcInv n) (hcRow n) (hcCol n) B (hcBound n) y - intro y - exact ⟨summable_of_sum_le (fun x => hm x y) (hbound y), - Real.tsum_le_of_sum_le (fun x => hm x y) (hbound y)⟩ - - - -theorem trajectory_hit_tsum_le (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) - (hcol : ∀ y, Summable (fun x => m x y)) (B : ℝ) - (hb : ∀ y, ∑' x, m x y ≤ B) (h : V → ℝ) (hh0 : ∀ x, 0 ≤ h x) - (A : Finset V) (hh : ∀ x, h x ≤ ∑ y ∈ A, m x y) : - Summable h ∧ (∑' x, h x) ≤ (A.card:ℝ)*B := by - have hs := fun Z => finite_trajectory_hit_le m hm hcol B hb h A Z hh - exact ⟨summable_of_sum_le hh0 hs, Real.tsum_le_of_sum_le hh0 hs⟩ - -end NonnegativeTransport - -end Percolation - - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -section FiniteTrajectoryMass -attribute [local instance] Classical.propDecidable Classical.decEq -variable {W : Type*} [Fintype W] - -theorem finiteFamilyIntegral_mul_const (Q : Finset E) (J : Finset ℕ) (p c : ℝ) - (f : (ℕ → Set E) → ℝ) : - finiteFamilyIntegral Q J p (fun η => f η * c) = finiteFamilyIntegral Q J p f * c := by - simp only [finiteFamilyIntegral,Finset.sum_mul,mul_assoc] - -omit [Fintype W] in -theorem oldRunWeight_factor_ne_zero (q : Set E → W → W → ℝ) (k : ℕ) - (η : ℕ → Set E) (z : W) (y : Fin k → W) - (hy : oldRunWeight (fun i => q (η i)) k z y ≠ 0) (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : - q (η i) (oldRunVertices k z y i) (oldRunVertices k z y (i-1)) ≠ 0 := by - rw [← oldPathWeight_oldRunVertices] at hy - exact (Finset.prod_ne_zero_iff.mp hy) ⟨i,Finset.mem_Icc.mpr ⟨hi,hik⟩⟩ (Finset.mem_univ _) - - - -noncomputable def finiteTrajectoryMass (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (a : V) : ℝ := - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - ∑ y : Fin k → W, if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then - oldRunWeight (fun i => q (η i)) k z y else 0) - -noncomputable def finiteTrajectoryHit (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (A : Finset V) : ℝ := - finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - ∑ y : Fin k → W, if ((A:Set V) ∩ trajectoryUnion G η (e ∘ oldRunVertices k z y) k).Nonempty then - oldRunWeight (fun i => q (η i)) k z y else 0) - -theorem finiteTrajectoryMass_nonneg (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (a : V) : - 0 ≤ finiteTrajectoryMass G e Q p k q z a := by - apply finiteFamilyIntegral_nonneg - intro η - apply Finset.sum_nonneg - intro y _ - split_ifs - · exact oldRunWeight_nonneg _ (fun _ => hq _) k z y - · exact le_refl 0 - -theorem finiteTrajectoryHit_nonneg (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (A : Finset V) : - 0 ≤ finiteTrajectoryHit G e Q p k q z A := by - apply finiteFamilyIntegral_nonneg - intro η - apply Finset.sum_nonneg - intro y _ - split_ifs - · exact oldRunWeight_nonneg _ (fun _ => hq _) k z y - · exact le_refl 0 - -theorem finiteTrajectoryHit_le_sum (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (A : Finset V) : - finiteTrajectoryHit G e Q p k q z A ≤ ∑ a ∈ A, finiteTrajectoryMass G e Q p k q z a := by - unfold finiteTrajectoryHit finiteTrajectoryMass - rw [← finiteFamilyIntegral_sum] - apply finiteFamilyIntegral_mono - intro η - rw [Finset.sum_comm] - apply Finset.sum_le_sum - intro y _ - have hn := oldRunWeight_nonneg (fun i => q (η i)) (fun _ => hq _) k z y - by_cases h : ((A:Set V) ∩ trajectoryUnion G η (e ∘ oldRunVertices k z y) k).Nonempty - · rw [ite_eq_left h] - obtain ⟨a,ha,hat⟩ := h - have hs := Finset.single_le_sum (s := A) - (f := fun a => if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then - oldRunWeight (fun i => q (η i)) k z y else 0) - (fun a _ => by split_ifs; exact hn; exact le_refl 0) ha - simpa only [ite_eq_left hat] using hs - · rw [ite_eq_right h] - exact Finset.sum_nonneg fun a _ => by split_ifs; exact hn; exact le_refl 0 - - - -theorem finiteTrajectoryMass_finite_sum_le (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : unitInterval) (k M : ℕ) (q : Set E → W → W → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) - (hcap : ∀ ω a b, q ω a b ≠ 0 → - (cluster G ω (e a)).Finite ∧ (cluster G ω (e a)).ncard ≤ M) - (u : ℝ) (hu : 0 ≤ u) (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) - (z : W) (A : Finset V) : - (∑ a ∈ A, finiteTrajectoryMass G e Q p k q z a) ≤ (k*M:ℕ)*u^k := by - unfold finiteTrajectoryMass - rw [← finiteFamilyIntegral_sum] - have hb : ∀ η, (∑ a ∈ A, ∑ y : Fin k → W, - if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then - oldRunWeight (fun i => q (η i)) k z y else 0) ≤ - (∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ) := by - intro η - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_le_sum - intro y _ - by_cases hy : oldRunWeight (fun i => q (η i)) k z y = 0 - · simp [hy] - obtain ⟨hf,hc⟩ := trajectoryUnion_finite_cap G η (e ∘ oldRunVertices k z y) k M - (fun i hi hik => hcap _ _ _ (oldRunWeight_factor_ne_zero q k η z y hy i hi hik)) - have hsub : A.filter (fun a => a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k) ⊆ hf.toFinset := by - intro a ha - exact hf.mem_toFinset.mpr (Finset.mem_filter.mp ha).2 - have hcard : ((A.filter (fun a => a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k)).card:ℝ) ≤ (k*M:ℕ) := by - exact_mod_cast (Finset.card_le_card hsub).trans (by simpa only [← Set.ncard_eq_toFinset_card _ hf] using hc) - rw [← Finset.sum_filter] - simp only [Finset.sum_const, nsmul_eq_mul] - simpa only [mul_comm] using mul_le_mul_of_nonneg_left hcard - (oldRunWeight_nonneg _ (fun _ => hq _) k z y) - calc - _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - (∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ)) := - finiteFamilyIntegral_mono Q (Finset.Icc 1 k) p _ _ hb - _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => - ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ) := - finiteFamilyIntegral_mul_const Q (Finset.Icc 1 k) p _ _ - _ ≤ u^k * (k*M:ℕ) := mul_le_mul_of_nonneg_right - (independent_oldRun_success_le Q p k q hq u hu hrow z) (Nat.cast_nonneg _) - _ = (k*M:ℕ)*u^k := mul_comm _ _ - - - -theorem finiteTrajectoryMass_row_bound (G : BondGraph V E) (e : W → V) - (Q : Finset E) (p : unitInterval) (k M : ℕ) (q : Set E → W → W → ℝ) - (hq : ∀ ω a b, 0 ≤ q ω a b) - (hcap : ∀ ω a b, q ω a b ≠ 0 → - (cluster G ω (e a)).Finite ∧ (cluster G ω (e a)).ncard ≤ M) - (u : ℝ) (hu : 0 ≤ u) (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) (z : W) : - Summable (finiteTrajectoryMass G e Q p k q z) ∧ - (∑' a, finiteTrajectoryMass G e Q p k q z a) ≤ (k*M:ℕ)*u^k := by - have hn := finiteTrajectoryMass_nonneg G e Q p k q hq z - have hb := finiteTrajectoryMass_finite_sum_le G e Q p k M q hq hcap u hu hrow z - exact ⟨summable_of_sum_le hn hb,Real.tsum_le_of_sum_le hn hb⟩ - -end FiniteTrajectoryMass - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Splicing.MomentBounds + +namespace OAI + +/-! Trajectory Mass for bond percolation. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OldPathWeight +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def finiteFieldIntegral (Q : Finset E) (p : ℝ) (f : Set E → ℝ) : ℝ := + ∑ ω : FiniteField Q, finiteFieldWeight Q p ω * f (finiteFieldSet Q ω) + +theorem finiteFieldIntegral_nonneg (Q : Finset E) (p : unitInterval) (f : Set E → ℝ) + (hf : ∀ ω, 0 ≤ f ω) : 0 ≤ finiteFieldIntegral Q p f := + Finset.sum_nonneg fun ω _ => mul_nonneg (finiteFieldWeight_nonneg Q p ω) (hf _) + +theorem finiteFieldIntegral_sum {I : Type*} (Q : Finset E) (p : ℝ) (S : Finset I) + (f : I → Set E → ℝ) : + finiteFieldIntegral Q p (fun ω => ∑ i ∈ S, f i ω) = + ∑ i ∈ S, finiteFieldIntegral Q p (f i) := by + simp only [finiteFieldIntegral, Finset.mul_sum] + exact Finset.sum_comm + + + +theorem finiteFamilyIntegral_prod (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (f : ↥J → Set E → ℝ) : + finiteFamilyIntegral Q J p (fun η => ∏ i : ↥J, f i (η i)) = + ∏ i : ↥J, finiteFieldIntegral Q p (f i) := by + simp only [finiteFamilyIntegral, finiteFamilyWeight, finiteFieldFamily_at, + ← Finset.prod_mul_distrib, finiteFieldIntegral] + exact (Fintype.prod_sum (fun (i : ↥J) (ω : FiniteField Q) => + finiteFieldWeight Q p ω * f i (finiteFieldSet Q ω))).symm + + + +noncomputable def oldPathWeight (k : ℕ) (q : Set E → V → V → ℝ) + (y : ℕ → V) (η : ℕ → Set E) : ℝ := + ∏ i : ↥(Finset.Icc 1 k), q (η i) (y i) (y (i.val-1)) + +theorem oldPathWeight_nonneg (k : ℕ) (q : Set E → V → V → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) (y : ℕ → V) (η : ℕ → Set E) : + 0 ≤ oldPathWeight k q y η := + Finset.prod_nonneg fun _ _ => hq _ _ _ + +theorem oldPathWeight_integral (Q : Finset E) (k : ℕ) (p : ℝ) + (q : Set E → V → V → ℝ) (y : ℕ → V) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p (oldPathWeight k q y) = + ∏ i : ↥(Finset.Icc 1 k), finiteFieldIntegral Q p (fun ω => q ω (y i) (y (i.val-1))) := by + unfold oldPathWeight + exact finiteFamilyIntegral_prod Q (Finset.Icc 1 k) p + (fun i ω => q ω (y i) (y (i.val-1))) + + + +theorem oldPathWeight_support (G : BondGraph V E) (k M : ℕ) (L : ℝ) + (q : Set E → V → V → ℝ) + (hs : ∀ ω a b, q ω a b ≠ 0 → b ∈ cluster G ω a ∧ + (cluster G ω a).Finite ∧ (cluster G ω a).ncard ≤ M ∧ GoodForScale G ω a L) + (y : ℕ → V) (η : ℕ → Set E) (hy : oldPathWeight k q y η ≠ 0) : + ∀ i, 1 ≤ i → i ≤ k → y (i-1) ∈ cluster G (η i) (y i) ∧ + (cluster G (η i) (y i)).Finite ∧ (cluster G (η i) (y i)).ncard ≤ M ∧ + GoodForScale G (η i) (y i) L := by + intro i hi hik + apply hs + have h := (Finset.prod_ne_zero_iff.mp hy) ⟨i, Finset.mem_Icc.mpr ⟨hi,hik⟩⟩ (Finset.mem_univ _) + exact h + +end OldPathWeight + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteOldRun +attribute [local instance] Classical.propDecidable Classical.decEq +variable {W : Type*} + + +def oldRunConsEquiv (k : ℕ) : (Fin (k+1) → W) ≃ W × (Fin k → W) where + toFun y := (y 0, Fin.tail y) + invFun y := Fin.cons y.1 y.2 + left_inv := Fin.cons_self_tail + right_inv y := by simp + + + +noncomputable def oldRunWeight (K : ℕ → W → W → ℝ) : (k : ℕ) → W → (Fin k → W) → ℝ + | 0, _, _ => 1 + | k+1, z, y => K (k+1) z (y 0) * oldRunWeight K k (y 0) (Fin.tail y) + +theorem oldRunWeight_nonneg (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) + (k : ℕ) (z : W) (y : Fin k → W) : 0 ≤ oldRunWeight K k z y := by + induction k generalizing z with + | zero => exact zero_le_one + | succ k ih => exact mul_nonneg (hK _ _ _) (ih _ _) + +theorem sum_oldRunWeight_succ [Fintype W] (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) : + (∑ y : Fin (k+1) → W, oldRunWeight K (k+1) z y) = + ∑ a : W, K (k+1) z a * ∑ y : Fin k → W, oldRunWeight K k a y := by + rw [Fintype.sum_equiv (oldRunConsEquiv k) _ + (fun y => K (k+1) z y.1 * oldRunWeight K k y.1 y.2) (by intro y; rfl), + Fintype.sum_prod_type] + simp only [Finset.mul_sum] + + + +theorem sum_oldRunWeight_le [Fintype W] (K : ℕ → W → W → ℝ) + (hK : ∀ i a b, 0 ≤ K i a b) (u : ℝ) (hu : 0 ≤ u) + (hrow : ∀ i a, ∑ b, K i a b ≤ u) (k : ℕ) (z : W) : + (∑ y : Fin k → W, oldRunWeight K k z y) ≤ u^k := by + induction k generalizing z with + | zero => simp [oldRunWeight] + | succ k ih => + rw [sum_oldRunWeight_succ] + calc + _ ≤ ∑ a : W, K (k+1) z a * u^k := Finset.sum_le_sum fun a _ => + mul_le_mul_of_nonneg_left (ih a) (hK _ _ _) + _ = (∑ a : W, K (k+1) z a) * u^k := (Finset.sum_mul _ _ _).symm + _ ≤ u * u^k := mul_le_mul_of_nonneg_right (hrow _ _) (pow_nonneg hu _) + _ = u^(k+1) := by ring + +theorem sum_oldRunWeight_eq [Fintype W] (K : ℕ → W → W → ℝ) + (u : ℝ) (hrow : ∀ i a, ∑ b, K i a b = u) (k : ℕ) (z : W) : + (∑ y : Fin k → W, oldRunWeight K k z y) = u^k := by + induction k generalizing z with + | zero => simp [oldRunWeight] + | succ k ih => + simp only [sum_oldRunWeight_succ, ih, ← Finset.sum_mul, hrow] + ring + + + +def oldRunVertices : (k : ℕ) → W → (Fin k → W) → ℕ → W + | 0, z, _ => fun _ => z + | k+1, z, y => fun i => if i ≤ k then oldRunVertices k (y 0) (Fin.tail y) i else z + +@[simp] theorem oldRunVertices_last (k : ℕ) (z : W) (y : Fin k → W) : + oldRunVertices k z y k = z := by + cases k <;> simp [oldRunVertices] + +theorem oldRunVertices_succ_of_le (k : ℕ) (z : W) (y : Fin (k+1) → W) + (i : ℕ) (hi : i ≤ k) : + oldRunVertices (k+1) z y i = oldRunVertices k (y 0) (Fin.tail y) i := by + simp only [oldRunVertices, ite_eq_left hi] + + + +theorem oldPathWeight_oldRunVertices (k : ℕ) (q : Set E → W → W → ℝ) + (η : ℕ → Set E) (z : W) (y : Fin k → W) : + oldPathWeight k q (oldRunVertices k z y) η = + oldRunWeight (fun i => q (η i)) k z y := by + induction k generalizing z with + | zero => + unfold oldPathWeight + rw [Finset.prod_coe_sort (Finset.Icc 1 0) + (fun i => q (η i) (oldRunVertices 0 z y i) (oldRunVertices 0 z y (i-1)))] + simp [oldRunWeight] + | succ k ih => + unfold oldPathWeight + rw [Finset.prod_coe_sort (Finset.Icc 1 (k+1)) + (fun i => q (η i) (oldRunVertices (k+1) z y i) (oldRunVertices (k+1) z y (i-1))), + Finset.prod_Icc_succ_top (by omega)] + have he : (∏ i ∈ Finset.Icc 1 k, + q (η i) (oldRunVertices (k+1) z y i) (oldRunVertices (k+1) z y (i-1))) = + oldPathWeight k q (oldRunVertices k (y 0) (Fin.tail y)) η := by + unfold oldPathWeight + rw [Finset.prod_coe_sort (Finset.Icc 1 k) + (fun i => q (η i) (oldRunVertices k (y 0) (Fin.tail y) i) + (oldRunVertices k (y 0) (Fin.tail y) (i-1)))] + apply Finset.prod_congr rfl + intro i hi + have hi' := Finset.mem_Icc.mp hi + rw [oldRunVertices_succ_of_le _ _ _ _ hi'.2, + oldRunVertices_succ_of_le _ _ _ _ (by omega)] + rw [he, ih, oldRunVertices_last, Nat.add_sub_cancel, + oldRunVertices_succ_of_le _ _ _ _ (le_refl _), oldRunVertices_last] + exact mul_comm _ _ + +end FiniteOldRun + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section IndependentOldRun +attribute [local instance] Classical.propDecidable Classical.decEq +variable {W : Type*} + + +noncomputable def finiteOldKernel (Q : Finset E) (p : ℝ) + (q : Set E → W → W → ℝ) (a b : W) : ℝ := + finiteFieldIntegral Q p (fun ω => q ω a b) + +theorem finiteOldKernel_nonneg (Q : Finset E) (p : unitInterval) + (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) (a b : W) : + 0 ≤ finiteOldKernel Q p q a b := + finiteFieldIntegral_nonneg Q p _ (fun _ => hq _ _ _) + + + +theorem oldRunWeight_integral (Q : Finset E) (p : ℝ) (k : ℕ) + (q : Set E → W → W → ℝ) (z : W) (y : Fin k → W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p + (fun η => oldRunWeight (fun i => q (η i)) k z y) = + oldRunWeight (fun _ => finiteOldKernel Q p q) k z y := by + calc + _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p + (fun η => oldPathWeight k q (oldRunVertices k z y) η) := by + apply congrArg (finiteFamilyIntegral Q (Finset.Icc 1 k) p) + funext η + exact (oldPathWeight_oldRunVertices k q η z y).symm + _ = ∏ i : ↥(Finset.Icc 1 k), finiteOldKernel Q p q + (oldRunVertices k z y i) (oldRunVertices k z y (i.val-1)) := + oldPathWeight_integral Q k p q _ + _ = oldRunWeight (fun _ => finiteOldKernel Q p q) k z y := + oldPathWeight_oldRunVertices k (fun (_ : Set E) => finiteOldKernel Q p q) + (fun _ => ∅) z y + + + +theorem independent_oldRun_success [Fintype W] (Q : Finset E) (p : ℝ) (k : ℕ) + (q : Set E → W → W → ℝ) (u : ℝ) + (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b = u) (z : W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p + (fun η => ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) = u^k := by + rw [finiteFamilyIntegral_sum] + simp only [oldRunWeight_integral] + exact sum_oldRunWeight_eq _ u (fun _ => hrow) k z + + + +theorem independent_oldRun_success_le [Fintype W] (Q : Finset E) (p : unitInterval) (k : ℕ) + (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) (u : ℝ) (hu : 0 ≤ u) + (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) (z : W) : + finiteFamilyIntegral Q (Finset.Icc 1 k) p + (fun η => ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) ≤ u^k := by + rw [finiteFamilyIntegral_sum] + simp only [oldRunWeight_integral] + exact sum_oldRunWeight_le _ (fun _ => finiteOldKernel_nonneg Q p q hq) u hu (fun _ => hrow) k z + +end IndependentOldRun + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WeightedCodeFiber +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem sum_comp_le_sum_of_injective {A B : Type*} [Fintype A] [Fintype B] + (f : A → B) (hf : Function.Injective f) (w : B → ℝ) (hw : ∀ b, 0 ≤ w b) : + (∑ a, w (f a)) ≤ ∑ b, w b := by + rw [← Finset.sum_image hf.injOn] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun b _ _ => hw b) + + +theorem finite_sum_group_weight {A B : Type*} [Fintype A] [Fintype B] + (f : A → B) (m : A → ℝ) (w : B → ℝ) : + (∑ a, m a * w (f a)) = ∑ b, w b * ∑ a, if f a = b then m a else 0 := by + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp only [mul_ite,mul_zero,Finset.sum_ite_eq,Finset.mem_univ,ite_true] + exact mul_comm _ _ + + + +theorem finite_choice_fiber_le {A B C P : Type*} [Fintype A] [Fintype P] + (f : A → B) (ctx : A → C) (choice : A → P) + (hir : Function.Injective (fun a => (ctx a,choice a,f a))) + (hctx : ∀ a b, f a = f b → ctx a = ctx b) + (q : C → P → ℝ) (hq : ∀ c p, 0 ≤ q c p) + (hrow : ∀ c, ∑ p, q c p ≤ 1) (b : B) : + (∑ a, if f a = b then q (ctx a) (choice a) else 0) ≤ 1 := by + let J := {a : A // f a = b} + by_cases hne : Nonempty J + · let a₀ : J := Classical.choice hne + have hc (a : J) : ctx a.val = ctx a₀.val := hctx _ _ (a.property.trans a₀.property.symm) + have hi : Function.Injective (fun a : J => choice a.val) := by + intro a a' he + apply Subtype.ext + apply hir + exact Prod.ext (hctx _ _ (a.property.trans a'.property.symm)) + (Prod.ext he (a.property.trans a'.property.symm)) + have hb := sum_comp_le_sum_of_injective (fun a : J => choice a.val) hi + (q (ctx a₀.val)) (hq _) + have he : (∑ a, if f a = b then q (ctx a) (choice a) else 0) = + ∑ a : J, q (ctx a) (choice a) := by + rw [← Finset.sum_filter] + exact Finset.sum_subtype _ (by intro a; simp) _ + rw [he] + simpa only [hc] using hb.trans (hrow (ctx a₀.val)) + · have hn (a : A) : f a ≠ b := fun h => hne ⟨⟨a,h⟩⟩ + simp only [ite_eq_right (hn _),Finset.sum_const_zero,zero_le_one] + + + +theorem finite_weighted_code_mass_le {A B C P : Type*} [Fintype A] [Fintype B] [Fintype P] + (f : A → B) (ctx : A → C) (choice : A → P) + (hir : Function.Injective (fun a => (ctx a,choice a,f a))) + (hctx : ∀ a b, f a = f b → ctx a = ctx b) + (q : C → P → ℝ) (hq : ∀ c p, 0 ≤ q c p) (hrow : ∀ c, ∑ p, q c p ≤ 1) + (w : B → ℝ) (hw : ∀ b, 0 ≤ w b) : + (∑ a, q (ctx a) (choice a) * w (f a)) ≤ ∑ b, w b := by + rw [finite_sum_group_weight] + apply Finset.sum_le_sum + intro b _ + calc + _ ≤ w b * 1 := mul_le_mul_of_nonneg_left + (finite_choice_fiber_le f ctx choice hir hctx q hq hrow b) (hw b) + _ = w b := mul_one _ + +end WeightedCodeFiber +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section WeightedInverseLoad +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteInverseLoad_weighted_le {I P : Type*} [Fintype I] [Fintype P] + (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) + (L : ℝ) (hL : 1 ≤ L) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (choice : I → P) (hir : Function.Injective (fun a => (inp a,choice a,steps a))) + (q : SpliceState E → P → ℝ) (hq : ∀ s b, 0 ≤ q s b) + (hrow : ∀ s, ∑ b, q s b ≤ 1) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) + (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ + (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) + (t : SpliceState E) : + finiteInverseLoad out (fun a => q (inp a) (choice a) * ∏ i : Fin k, + (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ + inverseCodeMass M L ^ k := by + let J := {a : I // out a = t} + let c (a : J) := gapSpliceCode G (out a.val).1 x z (steps a.val) + have hvalid (a : J) : ValidSparseGapCode k M (c a) := by + have hv := (htrace a.val).valid_gap_code G hloc x (inp a.val).2 (y a.val) k 0 M + (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L (hgood a.val) + simpa only [c,hz a.val] using hv.1 + let arr (a : J) := sparseGapArray k M (c a) (hvalid a) + let ctx (a : J) := (inp a.val,steps a.val) + have hc (a b : J) (he : arr a = arr b) : ctx a = ctx b := by + have ho : out a.val = out b.val := a.property.trans b.property.symm + have hcode : c a = c b := sparseGapArray_injective k M (c a) (c b) + (hvalid a) (hvalid b) he + have htB : SpliceTrace G x (inp b.val).2 (y b.val) k 0 + (inp b.val).1 (steps b.val) (out a.val).1 := by + rw [ho] + exact htrace b.val + have heB : SpliceExecution G x (inp b.val) (steps b.val) (out a.val) := ho.symm ▸ hex b.val + have hg : gapSpliceCode G (out a.val).1 x (y a.val k) (steps a.val) = + gapSpliceCode G (out a.val).1 x (y a.val k) (steps b.val) := by + simpa only [c,hz a.val,ho] using hcode + have hze : y a.val k = y b.val k := (hz a.val).trans (hz b.val).symm + have hs := (htrace a.val).code_unique_of_gapCode G x (inp a.val).2 (inp b.val).2 + (y a.val) (y b.val) k 0 (inp a.val).1 (inp b.val).1 (out a.val).1 + (steps a.val) (steps b.val) htB hze (hfin a.val) hg + have hi := (htrace a.val).input_unique_of_gapCode G x (inp a.val).2 (inp b.val).2 + (y a.val) (y b.val) k 0 (inp a.val).1 (inp b.val).1 (out a.val).1 + (steps a.val) (steps b.val) htB hze (hfin a.val) hg (out a.val).2 (hex a.val) heB + exact Prod.ext hi hs + have hi : Function.Injective (fun a : J => (ctx a,choice a.val,arr a)) := by + intro a b he + apply Subtype.ext + apply hir + have hec := congrArg Prod.fst he + have hin : inp a.val = inp b.val := congrArg (fun s : SpliceState E × List (ℕ × E) => s.1) hec + have hst : steps a.val = steps b.val := congrArg (fun s : SpliceState E × List (ℕ × E) => s.2) hec + exact Prod.ext hin (Prod.ext (congrArg (fun z => z.2.1) he) hst) + let w (b : Fin k → Fin (M+1)) := ∏ i, gapLetterWeight L (b i).val + have hb := finite_weighted_code_mass_le arr ctx (fun a : J => choice a.val) hi hc + (fun s b => q s.1 b) (fun s => hq s.1) (fun s => hrow s.1) w + (fun b => Finset.prod_nonneg (fun i _ => gapLetterWeight_nonneg L (by linarith) _)) + change (∑ a : J, q (inp a.val) (choice a.val) * w (arr a)) ≤ ∑ b, w b at hb + have he : finiteInverseLoad out (fun a => q (inp a) (choice a) * ∏ i : Fin k, + (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t = + ∑ a : J, q (inp a.val) (choice a.val) * ∏ i : Fin k, + (traceContactCount G (inp a.val).2 (y a.val) (out a.val).1 x (steps a.val) (i.val+1):ℝ)⁻¹ := by + rw [finiteInverseLoad,← Finset.sum_filter] + exact Finset.sum_subtype _ (by intro a; simp) _ + rw [he] + calc + _ ≤ ∑ a : J, q (inp a.val) (choice a.val) * w (arr a) := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul_of_nonneg_left _ (hq _ _) + apply Finset.prod_le_prod₀ (fun _ _ => by positivity) + intro i _ + have h := ((htrace a.val).contact_weight_bound G hloc x (inp a.val).2 (y a.val) + k 0 M (inp a.val).1 (out a.val).1 (steps a.val) (hfin a.val) L hL + (hgood a.val) (i.val+1)).2 + simpa only [w,arr,sparseGapArray,c,hz a.val] using h + _ ≤ ∑ b, w b := hb + _ = _ := total_gap_code_mass k M L + +end WeightedInverseLoad +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OldRunInverseLoad +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finiteInverseLoad_oldRun_le {I W : Type*} [Fintype I] [Fintype W] + (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) + (L : ℝ) (hL : 1 ≤ L) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (start : W) (path : I → Fin k → W) + (hir : Function.Injective (fun a => (inp a,path a,steps a))) + (q : Set E → W → W → ℝ) (hq : ∀ ω a b, 0 ≤ q ω a b) + (hrow : ∀ ω a, ∑ b, q ω a b ≤ 1) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (hz : ∀ a, y a k = z) (hfin : ∀ a, (cluster G (out a).1 x).Finite) + (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ + (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) + (t : SpliceState E) : + finiteInverseLoad out (fun a => oldRunWeight (fun i => q ((inp a).2 i)) k start (path a) * + ∏ i : Fin k, (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹) t ≤ + inverseCodeMass M L ^ k := by + apply finiteInverseLoad_weighted_le G hloc x z k M L hL inp out steps y path hir + (fun s b => oldRunWeight (fun i => q (s.2 i)) k start b) + (fun s b => oldRunWeight_nonneg _ (fun _ => hq _) k start b) _ htrace hex hz hfin hgood t + intro s + simpa only [one_pow] using sum_oldRunWeight_le (fun i => q (s.2 i)) + (fun _ => hq _) 1 zero_le_one (fun _ => hrow _) k start + +end OldRunInverseLoad +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section ChoiceForwardDensity +attribute [local instance] Classical.propDecidable Classical.decEq +variable {P : Type*} + + + +abbrev FiniteChoiceTraceIndex (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) := + (r : P) × FiniteTraceIndex G x k Q (A r) (y r) + +def choiceTraceInput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (a : FiniteChoiceTraceIndex G x k Q A y) : SpliceState E := + traceIndexInput G x k Q (A a.1) (y a.1) a.2 + +def choiceTraceOutput (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (a : FiniteChoiceTraceIndex G x k Q A y) : SpliceState E := + traceIndexOutput G x k Q (A a.1) (y a.1) a.2 + +def choiceTraceCode (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (a : FiniteChoiceTraceIndex G x k Q A y) : List (ℕ × E) := + traceIndexCode G x k Q (A a.1) (y a.1) a.2 + +noncomputable def choiceTraceMass (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (q : SpliceState E → P → ℝ) (a : FiniteChoiceTraceIndex G x k Q A y) : ℝ := + q (choiceTraceInput G x k Q A y a) a.1 * + traceIndexMass G x k Q (A a.1) (y a.1) a.2 + +theorem choiceTrace_injective (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) : + Function.Injective (fun a : FiniteChoiceTraceIndex G x k Q A y => + (choiceTraceInput G x k Q A y a,a.1,choiceTraceCode G x k Q A y a)) := by + rintro ⟨r,a⟩ ⟨r',b⟩ he + have hr : r = r' := congrArg (fun z => z.2.1) he + subst r' + have hin : traceIndexInput G x k Q (A r) (y r) a = + traceIndexInput G x k Q (A r) (y r) b := + congrArg (fun z : SpliceState E × P × List (ℕ × E) => z.1) he + have hcode : traceIndexCode G x k Q (A r) (y r) a = + traceIndexCode G x k Q (A r) (y r) b := + congrArg (fun z : SpliceState E × P × List (ℕ × E) => z.2.2) he + have hab : a = b := traceIndex_injective G x k Q (A r) (y r) (Prod.ext hin hcode) + subst b + rfl + +noncomputable def finiteChoiceForwardLoad [Fintype P] + (G : BondGraph V E) (x : V) (k : ℕ) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (q : SpliceState E → P → ℝ) : SpliceState E → ℝ := + finiteInverseLoad (choiceTraceOutput G x k Q A y) (choiceTraceMass G x k Q A y q) + + +theorem finiteChoiceForwardLoad_bounds [Fintype P] + (G : BondGraph V E) (hloc : LocallyFinite G) (x z : V) (k M : ℕ) + (L : ℝ) (hL : 1 ≤ L) (Q : Finset E) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (q : SpliceState E → P → ℝ) (hq : ∀ s r, 0 ≤ q s r) + (hrow : ∀ s, ∑ r, q s r ≤ 1) + (hA : ∀ r, A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hz : ∀ r s, s ∈ A r → y r s k = z) + (hgood : ∀ r s, s ∈ A r → ∀ i, 1 ≤ i → i ≤ k → + (cluster G (s.2 i) (y r s i)).Finite ∧ + (cluster G (s.2 i) (y r s i)).ncard ≤ M ∧ GoodForScale G (s.2 i) (y r s i) L) + (t : SpliceState E) : + 0 ≤ finiteChoiceForwardLoad G x k Q A y q t ∧ + finiteChoiceForwardLoad G x k Q A y q t ≤ inverseCodeMass M L ^ k := by + constructor + · apply finiteInverseLoad_nonneg + intro a + exact mul_nonneg (hq _ _) (Finset.prod_nonneg (fun _ _ => by positivity)) + · apply finiteInverseLoad_weighted_le G hloc x z k M L hL + (choiceTraceInput G x k Q A y) (choiceTraceOutput G x k Q A y) + (choiceTraceCode G x k Q A y) (fun a => y a.1 a.2.1.val) Sigma.fst + (choiceTrace_injective G x k Q A y) q hq hrow + (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1) + (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).2) + (fun a => hz a.1 _ a.2.1.property) _ + (fun a => hgood a.1 _ a.2.1.property) t + intro a + have hs := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) _).mp + (traceIndexOutput_mem G x k Q (A a.1) (y a.1) (hA a.1) a.2) + exact cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs.1) x + + + +theorem sum_traceIndexMass [Nonempty E] (G : BondGraph V E) (hloc : LocallyFinite G) + (x : V) (k M : ℕ) (Q : Finset E) (A : Finset (SpliceState E)) + (y : SpliceState E → ℕ → V) (s : ↥A) + (hs : s.val ∈ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hy : y s.val 0 ∈ cluster G s.val.1 x) + (hchain : ∀ i ∈ Finset.Icc 1 k, Conn G (s.val.2 i) (y s.val i) (y s.val (i-1))) + (hcaps : ∀ i ∈ Finset.Icc 1 k, (cluster G (s.val.2 i) (y s.val i)).Finite ∧ + (cluster G (s.val.2 i) (y s.val i)).ncard ≤ M) : + (∑ c : ↥(finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q), + traceIndexMass G x k Q A y ⟨s,c⟩) = 1 := by + have hs' := (mem_finiteSpliceDomain_iff Q (Finset.Icc 1 k) s.val).mp hs + have hn := sum_finite_trace_probabilities G hloc x s.val.2 (y s.val) k M Q + (fun i _ _ => hs'.2.1 i) hchain hcaps 0 (Nat.zero_le _) s.val.1 hy + (cluster_finite_of_finite_edges G (Q.finite_toSet.subset hs'.1) x) + rw [← Finset.sum_coe_sort (finiteTraceCodes G x s.val.2 (y s.val) k 0 s.val.1 Q)] at hn + rw [← hn] + apply Finset.sum_congr rfl + intro c _ + have ht := ((mem_finiteTraceCodes_iff G x s.val.2 (y s.val) k 0 s.val.1 Q c.val).mp c.property).2 + have hf := ht.runMasks_first G x s.val.2 (y s.val) k 0 s.val.1 _ c.val s.val.2 (by intros; rfl) + simp only [traceIndexMass,traceIndexOutput,hf] + + +theorem finiteChoiceForwardLoad_mean [Fintype P] [Nonempty E] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k M : ℕ) (Q : Finset E) (p : ℝ) + (A : P → Finset (SpliceState E)) (y : P → SpliceState E → ℕ → V) + (q : SpliceState E → P → ℝ) + (hA : ∀ r, A r ⊆ finiteSpliceDomain Q (Finset.Icc 1 k)) + (hy : ∀ r s, s ∈ A r → y r s 0 ∈ cluster G s.1 x) + (hchain : ∀ r s, s ∈ A r → ∀ i ∈ Finset.Icc 1 k, Conn G (s.2 i) (y r s i) (y r s (i-1))) + (hcaps : ∀ r s, s ∈ A r → ∀ i ∈ Finset.Icc 1 k, + (cluster G (s.2 i) (y r s i)).Finite ∧ (cluster G (s.2 i) (y r s i)).ncard ≤ M) : + (∑ t ∈ finiteSpliceDomain Q (Finset.Icc 1 k), spliceTupleWeight Q (Finset.Icc 1 k) p t * + finiteChoiceForwardLoad G x k Q A y q t) = + ∑ r, ∑ s ∈ A r, spliceTupleWeight Q (Finset.Icc 1 k) p s * q s r := by + have hd := finiteInverseLoad_density G x k Q p + (choiceTraceInput G x k Q A y) (choiceTraceOutput G x k Q A y) + (choiceTraceCode G x k Q A y) (fun a => y a.1 a.2.1.val) + (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).1) + (fun a => (traceIndex_valid G x k Q (A a.1) (y a.1) a.2).2) + (choiceTraceMass G x k Q A y q) (finiteSpliceDomain Q (Finset.Icc 1 k)) + (fun a => traceIndexOutput_mem G x k Q (A a.1) (y a.1) (hA a.1) a.2) (fun _ => 1) + simp only [mul_one] at hd + unfold finiteChoiceForwardLoad + rw [← hd,Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro r _ + rw [Fintype.sum_sigma,← Finset.sum_coe_sort (A r) + (fun s => spliceTupleWeight Q (Finset.Icc 1 k) p s * q s r)] + apply Finset.sum_congr rfl + intro s _ + change (∑ c : ↥(finiteTraceCodes G x s.val.2 (y r s.val) k 0 s.val.1 Q), + spliceTupleWeight Q (Finset.Icc 1 k) p s.val * + (q s.val r * traceIndexMass G x k Q (A r) (y r) ⟨s,c⟩)) = _ + simp only [← mul_assoc,← Finset.mul_sum] + rw [sum_traceIndexMass G hloc x k M Q (A r) (y r) s (hA r s.property) + (hy r _ s.property) (hchain r _ s.property) (hcaps r _ s.property),mul_one] + +end ChoiceForwardDensity +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EndpointRootMass +attribute [local instance] Classical.propDecidable Classical.decEq + + +noncomputable def auxiliaryTupleWeight (Q : Finset E) (J : Finset ℕ) (p : ℝ) + (s : SpliceState E) : ℝ := ∏ i ∈ J, bernoulliWeight Q (domainBits Q (s.2 i)) p + +theorem auxiliaryTupleWeight_nonneg (Q : Finset E) (J : Finset ℕ) (p : unitInterval) + (s : SpliceState E) : 0 ≤ auxiliaryTupleWeight Q J p s := + Finset.prod_nonneg fun _ _ => bernoulliWeight_nonneg _ _ p + + + +noncomputable def endpointRootMass {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) + (endpoint : I → V) (m : I → ℝ) (ω : Set E) (z : V) : ℝ := + ∑ a, if (out a).1 = ω ∧ endpoint a = z then auxiliaryTupleWeight Q J p (out a) * m a else 0 + +theorem endpointRootMass_nonneg {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) + (endpoint : I → V) (m : I → ℝ) (hm : ∀ a, 0 ≤ m a) (ω : Set E) (z : V) : + 0 ≤ endpointRootMass Q J p out endpoint m ω z := by + apply Finset.sum_nonneg + intro a _ + split_ifs + · exact mul_nonneg (auxiliaryTupleWeight_nonneg Q J p _) (hm a) + · exact le_refl 0 + + +theorem finiteRootLoad_eq_sum {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) (m : I → ℝ) + (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) (ω : FiniteField Q) : + finiteRootLoad Q J p (finiteInverseLoad out m) ω = + ∑ a, if (out a).1 = finiteFieldSet Q ω then auxiliaryTupleWeight Q J p (out a) * m a else 0 := by + simp only [finiteRootLoad,finiteInverseLoad,Finset.mul_sum,mul_ite,mul_zero] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + obtain ⟨⟨r,η⟩,_,ha⟩ := Finset.mem_image.mp (hs a) + change (finiteFieldSet Q r,finiteFieldFamily Q J η) = out a at ha + rw [← ha] + have he (θ : ↥J → FiniteField Q) : + (finiteFieldSet Q r,finiteFieldFamily Q J η) = (finiteFieldSet Q ω,finiteFieldFamily Q J θ) ↔ + r = ω ∧ η = θ := by + constructor + · intro h + exact ⟨finiteFieldSet_injective Q (congrArg Prod.fst h), + finiteFieldFamily_injective Q J (congrArg Prod.snd h)⟩ + · rintro ⟨rfl,rfl⟩; rfl + simp only [he] + by_cases hr : r = ω + · subst r + simp only [true_and,ite_true,Finset.sum_ite_eq,Finset.mem_univ] + rw [auxiliaryTupleWeight,prod_fieldFamilyWeight] + · have hr' : finiteFieldSet Q r ≠ finiteFieldSet Q ω := fun h => hr (finiteFieldSet_injective Q h) + simp [hr,hr'] + + + +theorem endpointRootMass_le {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : unitInterval) (out : I → SpliceState E) + (endpoint : I → V) (m : I → ℝ) (hs : ∀ a, out a ∈ finiteSpliceDomain Q J) + (z : V) (C : ℝ) + (hC : ∀ t ∈ finiteSpliceDomain Q J, finiteInverseLoad out + (fun a => if endpoint a = z then m a else 0) t ≤ C) (ω : FiniteField Q) : + endpointRootMass Q J p out endpoint m (finiteFieldSet Q ω) z ≤ C := by + have hb := finiteRootLoad_le Q J p _ C hC ω + rw [finiteRootLoad_eq_sum Q J p out _ hs ω] at hb + convert hb using 1 + unfold endpointRootMass + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp_all + + + +theorem sum_endpointRootMass {I : Type*} [Fintype I] + (Q : Finset E) (J : Finset ℕ) (p : ℝ) (out : I → SpliceState E) + (endpoint : I → V) (m : I → ℝ) (ω : Set E) (S : Finset V) : + (∑ z ∈ S, endpointRootMass Q J p out endpoint m ω z) = + ∑ a, if (out a).1 = ω ∧ endpoint a ∈ S then auxiliaryTupleWeight Q J p (out a) * m a else 0 := by + simp only [endpointRootMass] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + by_cases hr : (out a).1 = ω + · simp only [hr,true_and,Finset.sum_ite_eq] + · simp [hr] + +end EndpointRootMass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NearPairMass +attribute [local instance] Classical.propDecidable Classical.decEq + + + +theorem finite_near_pair_mass_le_cover {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] + (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) + (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) + (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) + (endpoint : I₂ → V) (R : I₁ → I₂ → Prop) (S : I₁ → Finset V) + (hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → endpoint b ∈ S a) : + (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ R a b then + jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ + ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a * + ∑ z ∈ S a, endpointRootMass Q J₂ p out₂ endpoint m₂ (out₁ a).1 z := by + apply Finset.sum_le_sum + intro a _ + rw [sum_endpointRootMass,Finset.mul_sum] + apply Finset.sum_le_sum + intro b _ + by_cases h : (out₁ a).1 = (out₂ b).1 ∧ R a b + · have hh : (out₂ b).1 = (out₁ a).1 ∧ endpoint b ∈ S a := + ⟨h.1.symm,hS a b h.1 h.2⟩ + rw [ite_eq_left h,ite_eq_left hh] + change (spliceTupleWeight Q J₁ p (out₁ a) * auxiliaryTupleWeight Q J₂ p (out₂ b)) * + m₁ a * m₂ b ≤ _ + ring_nf + exact le_refl _ + · rw [ite_eq_right h] + apply mul_nonneg (mul_nonneg (spliceTupleWeight_nonneg Q J₁ p _) (hm₁ a)) + split_ifs + · exact mul_nonneg (auxiliaryTupleWeight_nonneg Q J₂ p _) (hm₂ b) + · exact le_refl 0 + + + +theorem finite_near_pair_mass_le {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] + (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) + (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) + (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) + (endpoint : I₂ → V) (R : I₁ → I₂ → Prop) (S : I₁ → Finset V) + (hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → endpoint b ∈ S a) + (N : ℕ) (hN : ∀ a, (S a).card ≤ N) (C : ℝ) (hC : 0 ≤ C) + (hb : ∀ a z, z ∈ S a → endpointRootMass Q J₂ p out₂ endpoint m₂ (out₁ a).1 z ≤ C) : + (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ R a b then + jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ + (N:ℝ) * C * ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a := by + apply (finite_near_pair_mass_le_cover Q J₁ J₂ p out₁ out₂ m₁ m₂ hm₁ hm₂ endpoint R S hS).trans + calc + _ ≤ ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a * ((N:ℝ)*C) := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul_of_nonneg_left _ + (mul_nonneg (spliceTupleWeight_nonneg Q J₁ p _) (hm₁ a)) + calc + _ ≤ ∑ _z ∈ S a, C := Finset.sum_le_sum (fun z hz => hb a z hz) + _ = ((S a).card:ℝ) * C := by simp + _ ≤ (N:ℝ)*C := mul_le_mul_of_nonneg_right (by exact_mod_cast hN a) hC + _ = _ := by rw [← Finset.sum_mul]; ring + +end NearPairMass +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section EndpointInverseBound +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem finiteInverseLoad_subtype {I : Type*} [Fintype I] + (out : I → SpliceState E) (m : I → ℝ) (P : I → Prop) (t : SpliceState E) : + finiteInverseLoad out (fun a => if P a then m a else 0) t = + finiteInverseLoad (fun a : {a : I // P a} => out a.val) (fun a => m a.val) t := by + unfold finiteInverseLoad + have he : (∑ a, if out a = t then if P a then m a else 0 else 0) = + ∑ a, if P a then if out a = t then m a else 0 else 0 := by + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> rfl + rw [he,← Finset.sum_filter] + exact Finset.sum_subtype _ (by intro a; simp) _ + + + +theorem endpointInverseLoad_le {I P : Type*} [Fintype I] [Fintype P] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (k M : ℕ) (L : ℝ) (hL : 1 ≤ L) + (inp out : I → SpliceState E) (steps : I → List (ℕ × E)) (y : I → ℕ → V) + (endpoint : I → V) (choice : I → P) + (hir : Function.Injective (fun a => (inp a,endpoint a,choice a,steps a))) + (q : V → SpliceState E → P → ℝ) (hq : ∀ z s b, 0 ≤ q z s b) + (hrow : ∀ z s, ∑ b, q z s b ≤ 1) + (htrace : ∀ a, SpliceTrace G x (inp a).2 (y a) k 0 (inp a).1 (steps a) (out a).1) + (hex : ∀ a, SpliceExecution G x (inp a) (steps a) (out a)) + (hz : ∀ a, y a k = endpoint a) (hfin : ∀ a, (cluster G (out a).1 x).Finite) + (hgood : ∀ a i, 1 ≤ i → i ≤ k → (cluster G ((inp a).2 i) (y a i)).Finite ∧ + (cluster G ((inp a).2 i) (y a i)).ncard ≤ M ∧ GoodForScale G ((inp a).2 i) (y a i) L) + (z : V) (t : SpliceState E) : + finiteInverseLoad out (fun a => if endpoint a = z then + q (endpoint a) (inp a) (choice a) * ∏ i : Fin k, + (traceContactCount G (inp a).2 (y a) (out a).1 x (steps a) (i.val+1):ℝ)⁻¹ else 0) t ≤ + inverseCodeMass M L ^ k := by + rw [finiteInverseLoad_subtype] + let J := {a : I // endpoint a = z} + have hi : Function.Injective (fun a : J => (inp a.val,choice a.val,steps a.val)) := by + intro a b he + apply Subtype.ext + apply hir + have hin : inp a.val = inp b.val := congrArg (fun s : SpliceState E × P × List (ℕ × E) => s.1) he + exact Prod.ext hin (Prod.ext (a.property.trans b.property.symm) (congrArg (fun s : SpliceState E × P × List (ℕ × E) => s.2) he)) + have hb := finiteInverseLoad_weighted_le G hloc x z k M L hL + (fun a : J => inp a.val) (fun a : J => out a.val) (fun a : J => steps a.val) + (fun a : J => y a.val) (fun a : J => choice a.val) hi (q z) (hq z) (hrow z) + (fun a => htrace a.val) (fun a => hex a.val) (fun a => (hz a.val).trans a.property) + (fun a => hfin a.val) (fun a => hgood a.val) t + convert hb using 1 + apply congrArg (fun f : J → ℝ => finiteInverseLoad (fun a : J => out a.val) f t) + funext a + rw [a.property] + +end EndpointInverseBound +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NearHangingMass +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem SpliceTrace.head_hanging (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j i : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) : + hangingSide G ωf x e = cluster G ωf x \ cluster G ω x := by + rw [hangingSide,h.head_cut G x η y k j i ω ωf e rest] + +theorem SpliceTrace.head_hanging_cap (G : BondGraph V E) (x : V) (η : ℕ → Set E) + (y : ℕ → V) (k j i M : ℕ) (ω ωf : Set E) (e : E) (rest : List (ℕ × E)) + (h : SpliceTrace G x η y k j ω ((i,e)::rest) ωf) + (hcaps : ∀ l, 1 ≤ l → l ≤ k → + (cluster G (η l) (y l)).Finite ∧ (cluster G (η l) (y l)).ncard ≤ M) : + (hangingSide G ωf x e).ncard ≤ k*M := by + rw [h.head_hanging G x η y k j i ω ωf e rest] + exact (h.added_finite_cap G x η y k j M ω ωf ((i,e)::rest) hcaps).2 + + + +theorem finite_near_hanging_mass_le {I₁ I₂ : Type*} [Fintype I₁] [Fintype I₂] + (G : BondGraph V E) (hloc : LocallyFinite G) (x : V) (v d : ℕ) + (hdeg : ∀ a, degree G a ≤ d) + (Q : Finset E) (J₁ J₂ : Finset ℕ) (p : unitInterval) + (out₁ : I₁ → SpliceState E) (out₂ : I₂ → SpliceState E) + (m₁ : I₁ → ℝ) (m₂ : I₂ → ℝ) (hm₁ : ∀ a, 0 ≤ m₁ a) (hm₂ : ∀ b, 0 ≤ m₂ b) + (z₁ : I₁ → V) (z₂ : I₂ → V) (e₁ : I₁ → E) (e₂ : I₂ → E) + (hfin : ∀ a, (cluster G (out₁ a).1 x).Finite) + (hp₁ : ∀ a, OpenMarkedPivotal G (out₁ a).1 {z₁ a} x (e₁ a)) + (hp₂ : ∀ b, OpenMarkedPivotal G (out₂ b).1 {z₂ b} x (e₂ b)) + (hcap₁ : ∀ a, (hangingSide G (out₁ a).1 x (e₁ a)).ncard ≤ v) + (hcap₂ : ∀ b, (hangingSide G (out₂ b).1 x (e₂ b)).ncard ≤ v) + (C : ℝ) (hC : 0 ≤ C) + (hb : ∀ a z, endpointRootMass Q J₂ p out₂ z₂ m₂ (out₁ a).1 z ≤ C) : + (∑ a, ∑ b, if (out₁ a).1 = (out₂ b).1 ∧ + ¬GraphSeparated G (hangingSide G (out₁ a).1 x (e₁ a)) + (hangingSide G (out₂ b).1 x (e₂ b)) then + jointTupleWeight Q J₁ J₂ p (pairSpliceOutput (out₁ a) (out₂ b)) * m₁ a * m₂ b else 0) ≤ + ((v+v^2+d*v^3:ℕ):ℝ) * C * ∑ a, spliceTupleWeight Q J₁ p (out₁ a) * m₁ a := by + let R : I₁ → I₂ → Prop := fun a b => + ¬GraphSeparated G (hangingSide G (out₁ a).1 x (e₁ a)) (hangingSide G (out₂ b).1 x (e₂ b)) + let S := fun a => nearHangingEndpoints G hloc (out₁ a).1 x (z₁ a) (e₁ a) v (hfin a) + have hS : ∀ a b, (out₁ a).1 = (out₂ b).1 → R a b → z₂ b ∈ S a := by + intro a b he hn + have hp := hp₂ b + have hc := hcap₂ b + change ¬GraphSeparated G _ _ at hn + rw [← he] at hp hc hn + exact mem_nearHangingEndpoints_of_not_separated G hloc (out₁ a).1 x (z₁ a) (z₂ b) + (e₁ a) (e₂ b) v (hfin a) (hp₁ a) hp hc hn + have hN : ∀ a, (S a).card ≤ v+v^2+d*v^3 := fun a => + nearHangingEndpoints_card_le G hloc (out₁ a).1 x (z₁ a) (e₁ a) v d + (hfin a) (hcap₁ a) hdeg + have ht := finite_near_pair_mass_le Q J₁ J₂ p out₁ out₂ m₁ m₂ hm₁ hm₂ z₂ R S hS + (v+v^2+d*v^3) hN C hC (fun a z _ => hb a z) + convert ht using 1 + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + by_cases h : (out₁ a).1 = (out₂ b).1 ∧ R a b + · rw [ite_eq_left h,ite_eq_left h] + · rw [ite_eq_right h,ite_eq_right h] + +end NearHangingMass + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section OldRunArrival +attribute [local instance] Classical.propDecidable Classical.decEq +variable {W : Type*} [Fintype W] + +noncomputable def oldRunArrival (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (A : Finset W) : ℝ := + ∑ y : Fin k → W, if oldRunVertices k z y 0 ∈ A then oldRunWeight K k z y else 0 + +theorem oldRunArrival_nonneg (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) + (k : ℕ) (z : W) (A : Finset W) : 0 ≤ oldRunArrival K k z A := by + apply Finset.sum_nonneg + intro y _ + split_ifs + · exact oldRunWeight_nonneg K hK k z y + · exact le_refl 0 + +theorem oldRunArrival_zero (K : ℕ → W → W → ℝ) (z : W) (A : Finset W) : + oldRunArrival K 0 z A = if z ∈ A then 1 else 0 := by + by_cases h : z ∈ A + · simp [oldRunArrival,oldRunVertices,oldRunWeight,h] + · simp [oldRunArrival,oldRunVertices,h] + +theorem oldRunArrival_succ (K : ℕ → W → W → ℝ) (k : ℕ) (z : W) (A : Finset W) : + oldRunArrival K (k+1) z A = ∑ a, K (k+1) z a * oldRunArrival K k a A := by + unfold oldRunArrival + rw [Fintype.sum_equiv (oldRunConsEquiv k) _ + (fun y => if oldRunVertices k y.1 y.2 0 ∈ A then + K (k+1) z y.1 * oldRunWeight K k y.1 y.2 else 0) + (by + intro y + by_cases h : oldRunVertices k (y 0) (Fin.tail y) 0 ∈ A + · simp [oldRunVertices_succ_of_le k z y 0 (Nat.zero_le k),oldRunConsEquiv,oldRunWeight,h] + · simp [oldRunVertices_succ_of_le k z y 0 (Nat.zero_le k),oldRunConsEquiv,h]), + Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + simp only [Finset.mul_sum,mul_ite,mul_zero] + + + +theorem sum_oldRunArrival_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) + (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) (k : ℕ) (A : Finset W) : + (∑ z, oldRunArrival K k z A) ≤ (A.card:ℝ) * u^k := by + induction k with + | zero => simp [oldRunArrival_zero] + | succ k ih => + simp only [oldRunArrival_succ] + rw [Finset.sum_comm] + calc + _ = ∑ a, (∑ z, K (k+1) z a) * oldRunArrival K k a A := by + simp only [Finset.sum_mul] + _ ≤ ∑ a, u * oldRunArrival K k a A := Finset.sum_le_sum fun a _ => + mul_le_mul_of_nonneg_right (hcol _ _) (oldRunArrival_nonneg K hK k a A) + _ = u * ∑ a, oldRunArrival K k a A := (Finset.mul_sum _ _ _).symm + _ ≤ u*((A.card:ℝ)*u^k) := mul_le_mul_of_nonneg_left ih hu + _ = (A.card:ℝ)*u^(k+1) := by ring + + +theorem sum_oldRunArrival_on_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) + (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) + (k : ℕ) (A Z : Finset W) : + (∑ z ∈ Z, oldRunArrival K k z A) ≤ (A.card:ℝ) * u^k := by + apply (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ Z) + (fun z _ _ => oldRunArrival_nonneg K hK k z A)).trans + exact sum_oldRunArrival_le K hK u hu hcol k A + + +theorem noSwitch_arrival_le (K : ℕ → W → W → ℝ) (hK : ∀ i a b, 0 ≤ K i a b) + (u : ℝ) (hu : 0 ≤ u) (hcol : ∀ i b, ∑ a, K i a b ≤ u) + (k n : ℕ) (hn : 0 < n) (A Z : Finset W) (hA : A.card ≤ 2*n) : + (n:ℝ)⁻¹ * ∑ z ∈ Z, oldRunArrival K k z A ≤ 2*u^k := by + have hn' : (0:ℝ) < n := by exact_mod_cast hn + calc + _ ≤ (n:ℝ)⁻¹ * ((A.card:ℝ)*u^k) := + mul_le_mul_of_nonneg_left (sum_oldRunArrival_on_le K hK u hu hcol k A Z) + (inv_nonneg.mpr hn'.le) + _ ≤ (n:ℝ)⁻¹ * ((2*(n:ℝ))*u^k) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right (by exact_mod_cast hA) (pow_nonneg hu _)) (inv_nonneg.mpr hn'.le) + _ = 2*u^k := by field_simp + +end OldRunArrival + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section TrajectoryTransport +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + + + +theorem RootTransport.real (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) (m : V → V → ℝ) + (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) + (hr : ∀ x, Summable (m x)) (hc : ∀ y, Summable (fun x => m x y)) : + (∑ i, weight i * ∑' y, m (root i) y) = + (∑ i, weight i * ∑' x, m x (root i)) := by + have ht := htr (fun x y => (m x y:ℂ)) + (fun a ha x y => congrArg Complex.ofReal (hi a ha x y)) + (fun x => Complex.summable_ofReal.mpr (hr x)) + (fun y => Complex.summable_ofReal.mpr (hc y)) + apply Complex.ofReal_injective + simpa only [Complex.ofReal_sum,Complex.ofReal_mul,Complex.ofReal_tsum] using ht + + + +theorem transported_column_le (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) + (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) + (hr : ∀ x, Summable (m x)) (hcol : ∀ y, Summable (fun x => m x y)) + (B : ℝ) (hB : ∀ x, ∑' y, m x y ≤ B) (y : V) : + (∑' x, m x y) ≤ c*B := by + have ht := htr.real root weight Γ m hi hr hcol + have hb : (∑ i, weight i * ∑' x, m x (root i)) ≤ B := by + rw [← ht] + calc + _ ≤ ∑ i, weight i * B := Finset.sum_le_sum fun i _ => + mul_le_mul_of_nonneg_left (hB _) (hw i) + _ = B := by rw [← Finset.sum_mul,hw1,one_mul] + obtain ⟨i,a,ha,hay⟩ := hcov y + have he : (∑' x, m x y) = ∑' x, m x (root i) := by + rw [← hay,← a.tsum_eq (fun x => m x (a (root i)))] + exact tsum_congr (fun x => hi a ha x (root i)) + have hn : 0 ≤ ∑' x, m x (root i) := tsum_nonneg (fun x => hm x _) + have hs : weight i * ∑' x, m x (root i) ≤ ∑ j, weight j * ∑' x, m x (root j) := + Finset.single_le_sum (fun j _ => mul_nonneg (hw j) (tsum_nonneg (fun x => hm x (root j)))) + (Finset.mem_univ i) + rw [he] + calc + _ ≤ (c*weight i) * ∑' x, m x (root i) := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hmin i) hn + _ = c * (weight i * ∑' x, m x (root i)) := by ring + _ ≤ c * (∑ j, weight j * ∑' x, m x (root j)) := mul_le_mul_of_nonneg_left hs hc + _ ≤ c*B := mul_le_mul_of_nonneg_left hb hc + + + +theorem finite_trajectory_hit_le (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) + (hcol : ∀ y, Summable (fun x => m x y)) (B : ℝ) + (hb : ∀ y, ∑' x, m x y ≤ B) (h : V → ℝ) (A Z : Finset V) + (hh : ∀ x, h x ≤ ∑ y ∈ A, m x y) : + (∑ x ∈ Z, h x) ≤ (A.card:ℝ)*B := by + calc + _ ≤ ∑ x ∈ Z, ∑ y ∈ A, m x y := Finset.sum_le_sum fun x _ => hh x + _ = ∑ y ∈ A, ∑ x ∈ Z, m x y := Finset.sum_comm + _ ≤ ∑ y ∈ A, ∑' x, m x y := Finset.sum_le_sum fun y _ => + (hcol y).sum_le_tsum Z (fun x _ => hm x y) + _ ≤ ∑ _y ∈ A, B := Finset.sum_le_sum fun y _ => hb y + _ = (A.card:ℝ)*B := by simp + +end TrajectoryTransport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section NonnegativeTransport +attribute [local instance] Classical.propDecidable Classical.decEq +variable {ι : Type*} [Fintype ι] + +theorem mem_reachBall_aut_iff (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (ha : IsAut G a b) (x y : V) (n : ℕ) : + a y ∈ reachBall G (a x) n ↔ y ∈ reachBall G x n := by + constructor + · intro h + simpa only [Equiv.symm_apply_apply] using mem_reachBall_aut G (isAut_symm G ha) h + · exact mem_reachBall_aut G ha + + +def transportCut (G : BondGraph V E) (n : ℕ) (x y : V) : Prop := + y ∈ reachBall G x n ∧ x ∈ reachBall G y n + +theorem transportCut_mono (G : BondGraph V E) {n m : ℕ} (h : n ≤ m) + {x y : V} (hxy : transportCut G n x y) : transportCut G m x y := + ⟨reachBall_mono G x h hxy.1, reachBall_mono G y h hxy.2⟩ + +theorem transportCut_aut (G : BondGraph V E) {a : V ≃ V} {b : E ≃ E} + (ha : IsAut G a b) (n : ℕ) (x y : V) : + transportCut G n (a x) (a y) ↔ transportCut G n x y := by + simp only [transportCut,mem_reachBall_aut_iff G ha] + +theorem exists_transportCut (G : BondGraph V E) (hconn : Connected G) + (y : V) (Z : Finset V) : ∃ n, ∀ x ∈ Z, transportCut G n x y := by + induction Z using Finset.induction_on with + | empty => exact ⟨0, by simp⟩ + | @insert x Z _ ih => + obtain ⟨n,hn⟩ := ih + obtain ⟨r,hr⟩ := exists_mem_reachBall (hconn x y) + obtain ⟨s,hs⟩ := exists_mem_reachBall (hconn y x) + refine ⟨max n (max r s), ?_⟩ + intro z hz + rcases Finset.mem_insert.mp hz with rfl | hz + · exact ⟨reachBall_mono G z (le_trans (le_max_left r s) (le_max_right n _)) hr, + reachBall_mono G y (le_trans (le_max_right r s) (le_max_right n _)) hs⟩ + · exact transportCut_mono G (le_max_left n _) (hn z hz) + + + +theorem transported_column_of_row_bound (G : BondGraph V E) + (hconn : Connected G) (hloc : LocallyFinite G) + (root : ι → V) (weight : ι → ℝ) (Γ : Set (V ≃ V)) + (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) + (hi : ∀ a ∈ Γ, ∀ x y, m (a x) (a y) = m x y) + (hr : ∀ x, Summable (m x)) (B : ℝ) (hB : ∀ x, ∑' y, m x y ≤ B) : + ∀ y, Summable (fun x => m x y) ∧ (∑' x, m x y) ≤ c*B := by + let cut (n : ℕ) (x y : V) : ℝ := if transportCut G n x y then m x y else 0 + have hn (n : ℕ) (x y : V) : 0 ≤ cut n x y := by + dsimp [cut]; split_ifs; exact hm x y; exact le_refl 0 + have hcRow (n : ℕ) (x : V) : Summable (cut n x) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc x n).toFinset) + intro y hy + simp only [Set.Finite.mem_toFinset] at hy + exact ite_eq_right (fun h => hy h.1) + have hcCol (n : ℕ) (y : V) : Summable (fun x => cut n x y) := by + apply summable_of_ne_finset_zero (s := (finite_reachBall hloc y n).toFinset) + intro x hx + simp only [Set.Finite.mem_toFinset] at hx + exact ite_eq_right (fun h => hx h.2) + have hcInv (n : ℕ) : ∀ a ∈ Γ, ∀ x y, cut n (a x) (a y) = cut n x y := by + intro a ha x y + obtain ⟨b,hb⟩ := hΓ ha + simp only [cut,transportCut_aut G hb,hi a ha] + have hcBound (n : ℕ) (x : V) : (∑' y, cut n x y) ≤ B := by + apply le_trans ((hcRow n x).tsum_le_tsum (fun y => ?_) (hr x)) (hB x) + dsimp [cut]; split_ifs; exact le_refl _; exact hm x y + have hbound (y : V) (Z : Finset V) : (∑ x ∈ Z, m x y) ≤ c*B := by + obtain ⟨n,hnZ⟩ := exists_transportCut G hconn y Z + calc + _ = ∑ x ∈ Z, cut n x y := by + apply Finset.sum_congr rfl + intro x hx + exact (ite_eq_left (hnZ x hx)).symm + _ ≤ ∑' x, cut n x y := (hcCol n y).sum_le_tsum Z (fun x _ => hn n x y) + _ ≤ c*B := transported_column_le root weight Γ htr hcov hw hw1 c hc hmin + (cut n) (hn n) (hcInv n) (hcRow n) (hcCol n) B (hcBound n) y + intro y + exact ⟨summable_of_sum_le (fun x => hm x y) (hbound y), + Real.tsum_le_of_sum_le (fun x => hm x y) (hbound y)⟩ + + + +theorem trajectory_hit_tsum_le (m : V → V → ℝ) (hm : ∀ x y, 0 ≤ m x y) + (hcol : ∀ y, Summable (fun x => m x y)) (B : ℝ) + (hb : ∀ y, ∑' x, m x y ≤ B) (h : V → ℝ) (hh0 : ∀ x, 0 ≤ h x) + (A : Finset V) (hh : ∀ x, h x ≤ ∑ y ∈ A, m x y) : + Summable h ∧ (∑' x, h x) ≤ (A.card:ℝ)*B := by + have hs := fun Z => finite_trajectory_hit_le m hm hcol B hb h A Z hh + exact ⟨summable_of_sum_le hh0 hs, Real.tsum_le_of_sum_le hh0 hs⟩ + +end NonnegativeTransport + +end Percolation + + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +section FiniteTrajectoryMass +attribute [local instance] Classical.propDecidable Classical.decEq +variable {W : Type*} [Fintype W] + +theorem finiteFamilyIntegral_mul_const (Q : Finset E) (J : Finset ℕ) (p c : ℝ) + (f : (ℕ → Set E) → ℝ) : + finiteFamilyIntegral Q J p (fun η => f η * c) = finiteFamilyIntegral Q J p f * c := by + simp only [finiteFamilyIntegral,Finset.sum_mul,mul_assoc] + +omit [Fintype W] in +theorem oldRunWeight_factor_ne_zero (q : Set E → W → W → ℝ) (k : ℕ) + (η : ℕ → Set E) (z : W) (y : Fin k → W) + (hy : oldRunWeight (fun i => q (η i)) k z y ≠ 0) (i : ℕ) (hi : 1 ≤ i) (hik : i ≤ k) : + q (η i) (oldRunVertices k z y i) (oldRunVertices k z y (i-1)) ≠ 0 := by + rw [← oldPathWeight_oldRunVertices] at hy + exact (Finset.prod_ne_zero_iff.mp hy) ⟨i,Finset.mem_Icc.mpr ⟨hi,hik⟩⟩ (Finset.mem_univ _) + + + +noncomputable def finiteTrajectoryMass (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (a : V) : ℝ := + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + ∑ y : Fin k → W, if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then + oldRunWeight (fun i => q (η i)) k z y else 0) + +noncomputable def finiteTrajectoryHit (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : ℝ) (k : ℕ) (q : Set E → W → W → ℝ) (z : W) (A : Finset V) : ℝ := + finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + ∑ y : Fin k → W, if ((A:Set V) ∩ trajectoryUnion G η (e ∘ oldRunVertices k z y) k).Nonempty then + oldRunWeight (fun i => q (η i)) k z y else 0) + +theorem finiteTrajectoryMass_nonneg (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (a : V) : + 0 ≤ finiteTrajectoryMass G e Q p k q z a := by + apply finiteFamilyIntegral_nonneg + intro η + apply Finset.sum_nonneg + intro y _ + split_ifs + · exact oldRunWeight_nonneg _ (fun _ => hq _) k z y + · exact le_refl 0 + +theorem finiteTrajectoryHit_nonneg (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (A : Finset V) : + 0 ≤ finiteTrajectoryHit G e Q p k q z A := by + apply finiteFamilyIntegral_nonneg + intro η + apply Finset.sum_nonneg + intro y _ + split_ifs + · exact oldRunWeight_nonneg _ (fun _ => hq _) k z y + · exact le_refl 0 + +theorem finiteTrajectoryHit_le_sum (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : unitInterval) (k : ℕ) (q : Set E → W → W → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) (z : W) (A : Finset V) : + finiteTrajectoryHit G e Q p k q z A ≤ ∑ a ∈ A, finiteTrajectoryMass G e Q p k q z a := by + unfold finiteTrajectoryHit finiteTrajectoryMass + rw [← finiteFamilyIntegral_sum] + apply finiteFamilyIntegral_mono + intro η + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro y _ + have hn := oldRunWeight_nonneg (fun i => q (η i)) (fun _ => hq _) k z y + by_cases h : ((A:Set V) ∩ trajectoryUnion G η (e ∘ oldRunVertices k z y) k).Nonempty + · rw [ite_eq_left h] + obtain ⟨a,ha,hat⟩ := h + have hs := Finset.single_le_sum (s := A) + (f := fun a => if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then + oldRunWeight (fun i => q (η i)) k z y else 0) + (fun a _ => by split_ifs; exact hn; exact le_refl 0) ha + simpa only [ite_eq_left hat] using hs + · rw [ite_eq_right h] + exact Finset.sum_nonneg fun a _ => by split_ifs; exact hn; exact le_refl 0 + + + +theorem finiteTrajectoryMass_finite_sum_le (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : unitInterval) (k M : ℕ) (q : Set E → W → W → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) + (hcap : ∀ ω a b, q ω a b ≠ 0 → + (cluster G ω (e a)).Finite ∧ (cluster G ω (e a)).ncard ≤ M) + (u : ℝ) (hu : 0 ≤ u) (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) + (z : W) (A : Finset V) : + (∑ a ∈ A, finiteTrajectoryMass G e Q p k q z a) ≤ (k*M:ℕ)*u^k := by + unfold finiteTrajectoryMass + rw [← finiteFamilyIntegral_sum] + have hb : ∀ η, (∑ a ∈ A, ∑ y : Fin k → W, + if a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k then + oldRunWeight (fun i => q (η i)) k z y else 0) ≤ + (∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ) := by + intro η + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_le_sum + intro y _ + by_cases hy : oldRunWeight (fun i => q (η i)) k z y = 0 + · simp [hy] + obtain ⟨hf,hc⟩ := trajectoryUnion_finite_cap G η (e ∘ oldRunVertices k z y) k M + (fun i hi hik => hcap _ _ _ (oldRunWeight_factor_ne_zero q k η z y hy i hi hik)) + have hsub : A.filter (fun a => a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k) ⊆ hf.toFinset := by + intro a ha + exact hf.mem_toFinset.mpr (Finset.mem_filter.mp ha).2 + have hcard : ((A.filter (fun a => a ∈ trajectoryUnion G η (e ∘ oldRunVertices k z y) k)).card:ℝ) ≤ (k*M:ℕ) := by + exact_mod_cast (Finset.card_le_card hsub).trans (by simpa only [← Set.ncard_eq_toFinset_card _ hf] using hc) + rw [← Finset.sum_filter] + simp only [Finset.sum_const, nsmul_eq_mul] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left hcard + (oldRunWeight_nonneg _ (fun _ => hq _) k z y) + calc + _ ≤ finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + (∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ)) := + finiteFamilyIntegral_mono Q (Finset.Icc 1 k) p _ _ hb + _ = finiteFamilyIntegral Q (Finset.Icc 1 k) p (fun η => + ∑ y : Fin k → W, oldRunWeight (fun i => q (η i)) k z y) * (k*M:ℕ) := + finiteFamilyIntegral_mul_const Q (Finset.Icc 1 k) p _ _ + _ ≤ u^k * (k*M:ℕ) := mul_le_mul_of_nonneg_right + (independent_oldRun_success_le Q p k q hq u hu hrow z) (Nat.cast_nonneg _) + _ = (k*M:ℕ)*u^k := mul_comm _ _ + + + +theorem finiteTrajectoryMass_row_bound (G : BondGraph V E) (e : W → V) + (Q : Finset E) (p : unitInterval) (k M : ℕ) (q : Set E → W → W → ℝ) + (hq : ∀ ω a b, 0 ≤ q ω a b) + (hcap : ∀ ω a b, q ω a b ≠ 0 → + (cluster G ω (e a)).Finite ∧ (cluster G ω (e a)).ncard ≤ M) + (u : ℝ) (hu : 0 ≤ u) (hrow : ∀ a, ∑ b, finiteOldKernel Q p q a b ≤ u) (z : W) : + Summable (finiteTrajectoryMass G e Q p k q z) ∧ + (∑' a, finiteTrajectoryMass G e Q p k q z a) ≤ (k*M:ℕ)*u^k := by + have hn := finiteTrajectoryMass_nonneg G e Q p k q hq z + have hb := finiteTrajectoryMass_finite_sum_le G e Q p k M q hq hcap u hu hrow z + exact ⟨summable_of_sum_le hn hb,Real.tsum_le_of_sum_le hn hb⟩ + +end FiniteTrajectoryMass + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Bounds.lean b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Bounds.lean index d33643a2f717efdb14caddc4db5c11fa3afd95a1..11ab0b9652c297b15f4c33cfe2e453c37e5c3439 100644 --- a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Bounds.lean +++ b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Bounds.lean @@ -1,258 +1,258 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.TwoCluster.Transport - -namespace OAI - -/-! Quantitative two-cluster probability bounds. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory Filter -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem localDensityLoss_integral_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) - (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (y : V) : - (∫⁻ ω, localDensityLoss G n ω y ∂law p) ≤ - ENNReal.ofReal (10*c*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by - obtain ⟨i,a,ha,hai⟩ := hcov y - obtain ⟨b,hab⟩ := hΓ ha - have he : (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) = - ∫⁻ ω, localDensityLoss G n ω y ∂law p := by - have ht := lintegral_map (μ := law p) (measurable_localDensityLoss G hloc n (root i)) - (measurable_set_preimage b) - rw [law_map_preimage_equiv] at ht - rw [ht] - apply lintegral_congr - intro ω - rw [localDensityLoss_aut G n hab,hai] - have hwi : (1:ℝ≥0∞) ≤ ENNReal.ofReal c * ENNReal.ofReal (weight i) := by - rw [←ENNReal.ofReal_mul hc] - exact_mod_cast ENNReal.ofReal_le_ofReal (hmin i) - have hsingle : ENNReal.ofReal (weight i) * (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) ≤ - ∑ j, ENNReal.ofReal (weight j) * ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p := - Finset.single_le_sum (f := fun j => ENNReal.ofReal (weight j) * - ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p) (fun j _ => zero_le) (Finset.mem_univ i) - calc - _ = 1 * (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) := by rw [he,one_mul] - _ ≤ ENNReal.ofReal c * (ENNReal.ofReal (weight i) * - ∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) := by - rw [←mul_assoc] - exact mul_le_mul_left hwi _ - _ ≤ ENNReal.ofReal c * (∑ j, ENNReal.ofReal (weight j) * - ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p) := mul_le_mul_right hsingle _ - _ ≤ ENNReal.ofReal c * (2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ))) := - mul_le_mul_right (weighted_localDensityLoss_bound G hconn hloc root weight Γ hΓ htr hw hw1 - d hd n hn p hp hfin) _ - _ = _ := by - rw [←ENNReal.ofReal_ofNat 2,←ENNReal.ofReal_mul (by norm_num),←ENNReal.ofReal_mul hc] - congr 1 - ring - - -theorem cluster_insert_left_eq_union (G : BondGraph V E) (ω : Set E) - (e : E) (a b : V) (he : G e = s(a,b)) : - cluster G (insert e ω) a = cluster G ω a ∪ cluster G ω b := by - ext y - change Conn G (insert e ω) a y ↔ Conn G ω a y ∨ Conn G ω b y - rw [conn_insert_iff G ω e a b a y he] - constructor - · rintro (h | ⟨_,h⟩ | ⟨_,h⟩) - · exact Or.inl h - · exact Or.inr h - · exact Or.inl h - · rintro (h | h) - · exact Or.inl h - · exact Or.inr (Or.inl ⟨conn_refl G ω a,h⟩) - -theorem endpoint_density_defect (G : BondGraph V E) (ω : Set E) - (e : E) (a b : V) (he : G e = s(a,b)) (hab : ¬Conn G ω a b) - (ha : (cluster G ω a).Finite) (hb : (cluster G ω b).Finite) - (n : ℕ) (hna : n ≤ (cluster G ω a).ncard) (hnb : n ≤ (cluster G ω b).ncard) : - ((cluster G ω a).ncard:ℝ)*densityInfluence G n a e ω + - ((cluster G ω b).ncard:ℝ)*densityInfluence G n b e ω = n := by - have hc : e ∉ ω := fun h => hab (.single ⟨e,h,he⟩) - have hdis : Disjoint (cluster G ω a) (cluster G ω b) := by - apply Set.disjoint_left.mpr - intro z hz hz' - exact hab (conn_trans G ω hz (conn_symm G ω hz')) - have hins : Conn G (insert e ω) a b := .single ⟨e,Set.mem_insert e ω,he⟩ - have hs : (cluster G (insert e ω) a).ncard = (cluster G ω a).ncard+(cluster G ω b).ncard := by - rw [cluster_insert_left_eq_union G ω e a b he,Set.ncard_union_eq hdis ha hb] - have hsa : 0 < ((cluster G ω a).ncard:ℝ) := by exact_mod_cast cluster_ncard_pos G ω a ha - have hsb : 0 < ((cluster G ω b).ncard:ℝ) := by exact_mod_cast cluster_ncard_pos G ω b hb - have hna' : (n:ℝ) ≤ (cluster G ω a).ncard := by exact_mod_cast hna - have hnb' : (n:ℝ) ≤ (cluster G ω b).ncard := by exact_mod_cast hnb - unfold densityInfluence clusterDensity cappedDensity - rw [ite_eq_right hc,ite_eq_right hc,←cluster_eq_of_conn G (insert e ω) hins,hs,Nat.cast_add, - min_eq_left hna',min_eq_left hnb',min_eq_left (by linarith : (n:ℝ) ≤ - (cluster G ω a).ncard+(cluster G ω b).ncard)] - field_simp - ring - -theorem localDensityLoss_ge_edge (G : BondGraph V E) (n : ℕ) (ω : Set E) - (e : E) (a : V) (ha : a ∈ G e) : - ((cluster G ω a).ncard:ℝ≥0∞)*ENNReal.ofReal (densityInfluence G n a e ω) ≤ - localDensityLoss G n ω a := by - apply mul_le_mul_right - exact (le_of_eq (ite_eq_left ha).symm).trans - (ENNReal.le_tsum (f := fun edge => - if a ∈ G edge then ENNReal.ofReal (densityInfluence G n a edge ω) else 0) e) - -theorem two_large_endpoint_loss (G : BondGraph V E) (ω : Set E) - (e : E) (a b : V) (he : G e = s(a,b)) (ha : (cluster G ω a).Finite) - (hb : (cluster G ω b).Finite) (n : ℕ) - (h : ¬Conn G ω a b ∧ ω ∈ clusterLarge G a n ∧ ω ∈ clusterLarge G b n) : - (n:ℝ≥0∞) ≤ localDensityLoss G n ω a + localDensityLoss G n ω b := by - have hsz (v : V) (hv : (cluster G ω v).Finite) (hh : ω ∈ clusterLarge G v n) : - n ≤ (cluster G ω v).ncard := by - obtain ⟨t,ht,hct⟩ := hh - exact ht.trans (by rw [←Set.ncard_coe_finset]; exact Set.ncard_le_ncard hct hv) - have hid := endpoint_density_defect G ω e a b he h.1 ha hb n (hsz a ha h.2.1) (hsz b hb h.2.2) - have hid' := congrArg ENNReal.ofReal hid - rw [ENNReal.ofReal_add (mul_nonneg (Nat.cast_nonneg _) (densityInfluence_nonneg ..)) - (mul_nonneg (Nat.cast_nonneg _) (densityInfluence_nonneg ..)), - ENNReal.ofReal_mul (Nat.cast_nonneg _),ENNReal.ofReal_mul (Nat.cast_nonneg _)] at hid' - simp only [ENNReal.ofReal_natCast] at hid' - rw [←hid'] - exact add_le_add (localDensityLoss_ge_edge G n ω e a (by rw [he]; simp)) - (localDensityLoss_ge_edge G n ω e b (by rw [he]; simp)) - -end Percolation - - - -open MeasureTheory ProbabilityTheory Filter Topology -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - - - -def twoLargeEvent (G : BondGraph V E) (a b : V) (n : ℕ) : Set (Set E) := - {ω | ¬Conn G ω a b ∧ ω ∈ clusterLarge G a n ∧ ω ∈ clusterLarge G b n} - -theorem measurableSet_twoLargeEvent [Countable V] [Countable E] (G : BondGraph V E) (a b : V) (n : ℕ) : - MeasurableSet (twoLargeEvent G a b n) := - (measurableSet_conn G a b).compl.inter - ((measurableSet_clusterLarge G a n).inter (measurableSet_clusterLarge G b n)) - -theorem twoLarge_probability_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) - (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) - (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) - (e : E) (a b : V) (he : G e = s(a,b)) : - (n:ℝ) * (law p).real (twoLargeEvent G a b n) ≤ - 20*c*Real.sqrt (d*n:ℕ)/(p:ℝ) := by - have hpoint : ∀ᵐ ω ∂law p, - (twoLargeEvent G a b n).indicator (fun _ => (n:ℝ≥0∞)) ω ≤ - localDensityLoss G n ω a + localDensityLoss G n ω b := by - filter_upwards [hfin a,hfin b] with ω ha hb - by_cases h : ω ∈ twoLargeEvent G a b n - · rw [Set.indicator_of_mem h] - exact two_large_endpoint_loss G ω e a b he ha hb n h - · rw [Set.indicator_of_notMem h] - exact zero_le - have hi := lintegral_mono_ae hpoint - rw [lintegral_indicator (measurableSet_twoLargeEvent G a b n),lintegral_const, - lintegral_add_left (measurable_localDensityLoss G hloc n a)] at hi - have hbnd (y : V) := localDensityLoss_integral_bound G hconn hloc root weight Γ hΓ htr - hcov hw hw1 c hc hmin d hd n hn p hp hfin y - have hi' := hi.trans (add_le_add (hbnd a) (hbnd b)) - rw [←ENNReal.ofReal_add (by positivity : 0 ≤ 10*c*Real.sqrt (d*n:ℕ)/(p:ℝ)) - (by positivity : 0 ≤ 10*c*Real.sqrt (d*n:ℕ)/(p:ℝ))] at hi' - have ht := ENNReal.toReal_mono ENNReal.ofReal_ne_top hi' - rw [ENNReal.toReal_mul,ENNReal.toReal_natCast,ENNReal.toReal_ofReal (by positivity)] at ht - simp only [Measure.restrict_apply_univ] at ht - dsimp [Measure.real] at ht ⊢ - convert ht using 1 - ring - - - -theorem finiteWitness_eventually_iff (A : Set (Set E)) (hu : IsUpperSet A) - (hf : FiniteWitness A) (ω : ℕ → Set E) (hm : Monotone ω) : - ∀ᶠ j in atTop, ω j ∈ A ↔ (⋃ k, ω k) ∈ A := by - by_cases h : (⋃ k, ω k) ∈ A - · obtain ⟨t,ht,htA⟩ := hf _ h - have ht' : ∀ e ∈ t, ∃ k, e ∈ ω k := by - intro e he - exact Set.mem_iUnion.mp (ht he) - choose k hk using fun e : t => ht' e e.property - let N := t.attach.sup k - have hN : (t : Set E) ⊆ ω N := by - intro e he - exact hm (Finset.le_sup (f := k) (Finset.mem_attach t ⟨e,he⟩)) (hk ⟨e,he⟩) - filter_upwards [eventually_ge_atTop N] with j hj - exact iff_of_true (hu (hN.trans (hm hj)) htA) h - · exact Eventually.of_forall (fun j => iff_of_false - (fun hj => h (hu (Set.subset_iUnion ω j) hj)) h) - -theorem twoLarge_probability_tendsto [Countable V] [Countable E] (G : BondGraph V E) - (p : ℕ → unitInterval) (hp : Monotone p) (q : unitInterval) - (hle : ∀ j, p j ≤ q) (hlim : Tendsto p atTop (𝓝 q)) (a b : V) (n : ℕ) : - Tendsto (fun j => (law (p j)).real (twoLargeEvent G a b n)) atTop - (𝓝 ((law q).real (twoLargeEvent G a b n))) := by - let A := twoLargeEvent G a b n - let f := fun r labels => A.indicator (fun _ => (1:ℝ)) (openEdges labels r) - have hfi (r : unitInterval) : Integrable (f r) labelLaw := by - have hi : Integrable (A.indicator (fun _ => (1:ℝ))) (law r) := - (integrable_const _).indicator (measurableSet_twoLargeEvent G a b n) - rw [←map_openEdges r] at hi - exact hi.comp_measurable (measurable_openEdges r) - have ht : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), - Tendsto (fun j => f (p j) labels) atTop (𝓝 (f q labels)) := by - filter_upwards [ae_labels_ne (E := E) q] with labels hlabels - have hm : Monotone (fun j => openEdges labels (p j)) := - fun j k hjk => openEdges_mono labels (hp hjk) - have he := openEdges_eq_iUnion_of_tendsto labels q hlabels p hle hlim - have hC := finiteWitness_eventually_iff {ω | Conn G ω a b} - (fun _ _ hω h => conn_mono G hω h) (finiteWitness_conn G a b) _ hm - have ha := finiteWitness_eventually_iff (clusterLarge G a n) - (clusterLarge_upper G a n) (finiteWitness_clusterLarge G a n) _ hm - have hb := finiteWitness_eventually_iff (clusterLarge G b n) - (clusterLarge_upper G b n) (finiteWitness_clusterLarge G b n) _ hm - rw [←he] at hC ha hb - apply tendsto_const_nhds.congr' - filter_upwards [hC,ha,hb] with j hC ha hb - have hi : openEdges labels (p j) ∈ A ↔ openEdges labels q ∈ A := by - exact and_congr (not_congr hC) (and_congr ha hb) - simp only [f,Set.indicator_apply] - rw [hi] - have ht' := tendsto_integral_of_dominated_convergence (fun _ : E → unitInterval => (1:ℝ)) - (fun j => (hfi (p j)).aestronglyMeasurable) (integrable_const _) - (fun j => Eventually.of_forall (fun labels => by - simp only [f,Set.indicator_apply] - split <;> norm_num)) ht - have heq (r : unitInterval) : (∫ labels, f r labels ∂labelLaw) = (law r).real A := by - calc - _ = ∫ ω, A.indicator (fun _ => (1:ℝ)) ω ∂law r := by - rw [←map_openEdges r] - exact (integral_map (measurable_openEdges r).aemeasurable - ((measurable_const.indicator (measurableSet_twoLargeEvent G a b n)).aestronglyMeasurable)).symm - _ = _ := by rw [integral_indicator_const _ (measurableSet_twoLargeEvent G a b n)]; simp [A] - simpa only [heq] using ht' - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.TwoCluster.Transport + +namespace OAI + +/-! Quantitative two-cluster probability bounds. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem localDensityLoss_integral_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) + (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (y : V) : + (∫⁻ ω, localDensityLoss G n ω y ∂law p) ≤ + ENNReal.ofReal (10*c*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by + obtain ⟨i,a,ha,hai⟩ := hcov y + obtain ⟨b,hab⟩ := hΓ ha + have he : (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) = + ∫⁻ ω, localDensityLoss G n ω y ∂law p := by + have ht := lintegral_map (μ := law p) (measurable_localDensityLoss G hloc n (root i)) + (measurable_set_preimage b) + rw [law_map_preimage_equiv] at ht + rw [ht] + apply lintegral_congr + intro ω + rw [localDensityLoss_aut G n hab,hai] + have hwi : (1:ℝ≥0∞) ≤ ENNReal.ofReal c * ENNReal.ofReal (weight i) := by + rw [←ENNReal.ofReal_mul hc] + exact_mod_cast ENNReal.ofReal_le_ofReal (hmin i) + have hsingle : ENNReal.ofReal (weight i) * (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) ≤ + ∑ j, ENNReal.ofReal (weight j) * ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p := + Finset.single_le_sum (f := fun j => ENNReal.ofReal (weight j) * + ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p) (fun j _ => zero_le) (Finset.mem_univ i) + calc + _ = 1 * (∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) := by rw [he,one_mul] + _ ≤ ENNReal.ofReal c * (ENNReal.ofReal (weight i) * + ∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) := by + rw [←mul_assoc] + exact mul_le_mul_left hwi _ + _ ≤ ENNReal.ofReal c * (∑ j, ENNReal.ofReal (weight j) * + ∫⁻ ω, localDensityLoss G n ω (root j) ∂law p) := mul_le_mul_right hsingle _ + _ ≤ ENNReal.ofReal c * (2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ))) := + mul_le_mul_right (weighted_localDensityLoss_bound G hconn hloc root weight Γ hΓ htr hw hw1 + d hd n hn p hp hfin) _ + _ = _ := by + rw [←ENNReal.ofReal_ofNat 2,←ENNReal.ofReal_mul (by norm_num),←ENNReal.ofReal_mul hc] + congr 1 + ring + + +theorem cluster_insert_left_eq_union (G : BondGraph V E) (ω : Set E) + (e : E) (a b : V) (he : G e = s(a,b)) : + cluster G (insert e ω) a = cluster G ω a ∪ cluster G ω b := by + ext y + change Conn G (insert e ω) a y ↔ Conn G ω a y ∨ Conn G ω b y + rw [conn_insert_iff G ω e a b a y he] + constructor + · rintro (h | ⟨_,h⟩ | ⟨_,h⟩) + · exact Or.inl h + · exact Or.inr h + · exact Or.inl h + · rintro (h | h) + · exact Or.inl h + · exact Or.inr (Or.inl ⟨conn_refl G ω a,h⟩) + +theorem endpoint_density_defect (G : BondGraph V E) (ω : Set E) + (e : E) (a b : V) (he : G e = s(a,b)) (hab : ¬Conn G ω a b) + (ha : (cluster G ω a).Finite) (hb : (cluster G ω b).Finite) + (n : ℕ) (hna : n ≤ (cluster G ω a).ncard) (hnb : n ≤ (cluster G ω b).ncard) : + ((cluster G ω a).ncard:ℝ)*densityInfluence G n a e ω + + ((cluster G ω b).ncard:ℝ)*densityInfluence G n b e ω = n := by + have hc : e ∉ ω := fun h => hab (.single ⟨e,h,he⟩) + have hdis : Disjoint (cluster G ω a) (cluster G ω b) := by + apply Set.disjoint_left.mpr + intro z hz hz' + exact hab (conn_trans G ω hz (conn_symm G ω hz')) + have hins : Conn G (insert e ω) a b := .single ⟨e,Set.mem_insert e ω,he⟩ + have hs : (cluster G (insert e ω) a).ncard = (cluster G ω a).ncard+(cluster G ω b).ncard := by + rw [cluster_insert_left_eq_union G ω e a b he,Set.ncard_union_eq hdis ha hb] + have hsa : 0 < ((cluster G ω a).ncard:ℝ) := by exact_mod_cast cluster_ncard_pos G ω a ha + have hsb : 0 < ((cluster G ω b).ncard:ℝ) := by exact_mod_cast cluster_ncard_pos G ω b hb + have hna' : (n:ℝ) ≤ (cluster G ω a).ncard := by exact_mod_cast hna + have hnb' : (n:ℝ) ≤ (cluster G ω b).ncard := by exact_mod_cast hnb + unfold densityInfluence clusterDensity cappedDensity + rw [ite_eq_right hc,ite_eq_right hc,←cluster_eq_of_conn G (insert e ω) hins,hs,Nat.cast_add, + min_eq_left hna',min_eq_left hnb',min_eq_left (by linarith : (n:ℝ) ≤ + (cluster G ω a).ncard+(cluster G ω b).ncard)] + field_simp + ring + +theorem localDensityLoss_ge_edge (G : BondGraph V E) (n : ℕ) (ω : Set E) + (e : E) (a : V) (ha : a ∈ G e) : + ((cluster G ω a).ncard:ℝ≥0∞)*ENNReal.ofReal (densityInfluence G n a e ω) ≤ + localDensityLoss G n ω a := by + apply mul_le_mul_right + exact (le_of_eq (ite_eq_left ha).symm).trans + (ENNReal.le_tsum (f := fun edge => + if a ∈ G edge then ENNReal.ofReal (densityInfluence G n a edge ω) else 0) e) + +theorem two_large_endpoint_loss (G : BondGraph V E) (ω : Set E) + (e : E) (a b : V) (he : G e = s(a,b)) (ha : (cluster G ω a).Finite) + (hb : (cluster G ω b).Finite) (n : ℕ) + (h : ¬Conn G ω a b ∧ ω ∈ clusterLarge G a n ∧ ω ∈ clusterLarge G b n) : + (n:ℝ≥0∞) ≤ localDensityLoss G n ω a + localDensityLoss G n ω b := by + have hsz (v : V) (hv : (cluster G ω v).Finite) (hh : ω ∈ clusterLarge G v n) : + n ≤ (cluster G ω v).ncard := by + obtain ⟨t,ht,hct⟩ := hh + exact ht.trans (by rw [←Set.ncard_coe_finset]; exact Set.ncard_le_ncard hct hv) + have hid := endpoint_density_defect G ω e a b he h.1 ha hb n (hsz a ha h.2.1) (hsz b hb h.2.2) + have hid' := congrArg ENNReal.ofReal hid + rw [ENNReal.ofReal_add (mul_nonneg (Nat.cast_nonneg _) (densityInfluence_nonneg ..)) + (mul_nonneg (Nat.cast_nonneg _) (densityInfluence_nonneg ..)), + ENNReal.ofReal_mul (Nat.cast_nonneg _),ENNReal.ofReal_mul (Nat.cast_nonneg _)] at hid' + simp only [ENNReal.ofReal_natCast] at hid' + rw [←hid'] + exact add_le_add (localDensityLoss_ge_edge G n ω e a (by rw [he]; simp)) + (localDensityLoss_ge_edge G n ω e b (by rw [he]; simp)) + +end Percolation + + + +open MeasureTheory ProbabilityTheory Filter Topology +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + + + +def twoLargeEvent (G : BondGraph V E) (a b : V) (n : ℕ) : Set (Set E) := + {ω | ¬Conn G ω a b ∧ ω ∈ clusterLarge G a n ∧ ω ∈ clusterLarge G b n} + +theorem measurableSet_twoLargeEvent [Countable V] [Countable E] (G : BondGraph V E) (a b : V) (n : ℕ) : + MeasurableSet (twoLargeEvent G a b n) := + (measurableSet_conn G a b).compl.inter + ((measurableSet_clusterLarge G a n).inter (measurableSet_clusterLarge G b n)) + +theorem twoLarge_probability_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hcov : ∀ x, ∃ i, ∃ a ∈ Γ, a (root i) = x) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (c : ℝ) (hc : 0 ≤ c) (hmin : ∀ i, 1 ≤ c*weight i) + (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) + (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) + (e : E) (a b : V) (he : G e = s(a,b)) : + (n:ℝ) * (law p).real (twoLargeEvent G a b n) ≤ + 20*c*Real.sqrt (d*n:ℕ)/(p:ℝ) := by + have hpoint : ∀ᵐ ω ∂law p, + (twoLargeEvent G a b n).indicator (fun _ => (n:ℝ≥0∞)) ω ≤ + localDensityLoss G n ω a + localDensityLoss G n ω b := by + filter_upwards [hfin a,hfin b] with ω ha hb + by_cases h : ω ∈ twoLargeEvent G a b n + · rw [Set.indicator_of_mem h] + exact two_large_endpoint_loss G ω e a b he ha hb n h + · rw [Set.indicator_of_notMem h] + exact zero_le + have hi := lintegral_mono_ae hpoint + rw [lintegral_indicator (measurableSet_twoLargeEvent G a b n),lintegral_const, + lintegral_add_left (measurable_localDensityLoss G hloc n a)] at hi + have hbnd (y : V) := localDensityLoss_integral_bound G hconn hloc root weight Γ hΓ htr + hcov hw hw1 c hc hmin d hd n hn p hp hfin y + have hi' := hi.trans (add_le_add (hbnd a) (hbnd b)) + rw [←ENNReal.ofReal_add (by positivity : 0 ≤ 10*c*Real.sqrt (d*n:ℕ)/(p:ℝ)) + (by positivity : 0 ≤ 10*c*Real.sqrt (d*n:ℕ)/(p:ℝ))] at hi' + have ht := ENNReal.toReal_mono ENNReal.ofReal_ne_top hi' + rw [ENNReal.toReal_mul,ENNReal.toReal_natCast,ENNReal.toReal_ofReal (by positivity)] at ht + simp only [Measure.restrict_apply_univ] at ht + dsimp [Measure.real] at ht ⊢ + convert ht using 1 + ring + + + +theorem finiteWitness_eventually_iff (A : Set (Set E)) (hu : IsUpperSet A) + (hf : FiniteWitness A) (ω : ℕ → Set E) (hm : Monotone ω) : + ∀ᶠ j in atTop, ω j ∈ A ↔ (⋃ k, ω k) ∈ A := by + by_cases h : (⋃ k, ω k) ∈ A + · obtain ⟨t,ht,htA⟩ := hf _ h + have ht' : ∀ e ∈ t, ∃ k, e ∈ ω k := by + intro e he + exact Set.mem_iUnion.mp (ht he) + choose k hk using fun e : t => ht' e e.property + let N := t.attach.sup k + have hN : (t : Set E) ⊆ ω N := by + intro e he + exact hm (Finset.le_sup (f := k) (Finset.mem_attach t ⟨e,he⟩)) (hk ⟨e,he⟩) + filter_upwards [eventually_ge_atTop N] with j hj + exact iff_of_true (hu (hN.trans (hm hj)) htA) h + · exact Eventually.of_forall (fun j => iff_of_false + (fun hj => h (hu (Set.subset_iUnion ω j) hj)) h) + +theorem twoLarge_probability_tendsto [Countable V] [Countable E] (G : BondGraph V E) + (p : ℕ → unitInterval) (hp : Monotone p) (q : unitInterval) + (hle : ∀ j, p j ≤ q) (hlim : Tendsto p atTop (𝓝 q)) (a b : V) (n : ℕ) : + Tendsto (fun j => (law (p j)).real (twoLargeEvent G a b n)) atTop + (𝓝 ((law q).real (twoLargeEvent G a b n))) := by + let A := twoLargeEvent G a b n + let f := fun r labels => A.indicator (fun _ => (1:ℝ)) (openEdges labels r) + have hfi (r : unitInterval) : Integrable (f r) labelLaw := by + have hi : Integrable (A.indicator (fun _ => (1:ℝ))) (law r) := + (integrable_const _).indicator (measurableSet_twoLargeEvent G a b n) + rw [←map_openEdges r] at hi + exact hi.comp_measurable (measurable_openEdges r) + have ht : ∀ᵐ labels ∂(labelLaw : Measure (E → unitInterval)), + Tendsto (fun j => f (p j) labels) atTop (𝓝 (f q labels)) := by + filter_upwards [ae_labels_ne (E := E) q] with labels hlabels + have hm : Monotone (fun j => openEdges labels (p j)) := + fun j k hjk => openEdges_mono labels (hp hjk) + have he := openEdges_eq_iUnion_of_tendsto labels q hlabels p hle hlim + have hC := finiteWitness_eventually_iff {ω | Conn G ω a b} + (fun _ _ hω h => conn_mono G hω h) (finiteWitness_conn G a b) _ hm + have ha := finiteWitness_eventually_iff (clusterLarge G a n) + (clusterLarge_upper G a n) (finiteWitness_clusterLarge G a n) _ hm + have hb := finiteWitness_eventually_iff (clusterLarge G b n) + (clusterLarge_upper G b n) (finiteWitness_clusterLarge G b n) _ hm + rw [←he] at hC ha hb + apply tendsto_const_nhds.congr' + filter_upwards [hC,ha,hb] with j hC ha hb + have hi : openEdges labels (p j) ∈ A ↔ openEdges labels q ∈ A := by + exact and_congr (not_congr hC) (and_congr ha hb) + simp only [f,Set.indicator_apply] + rw [hi] + have ht' := tendsto_integral_of_dominated_convergence (fun _ : E → unitInterval => (1:ℝ)) + (fun j => (hfi (p j)).aestronglyMeasurable) (integrable_const _) + (fun j => Eventually.of_forall (fun labels => by + simp only [f,Set.indicator_apply] + split <;> norm_num)) ht + have heq (r : unitInterval) : (∫ labels, f r labels ∂labelLaw) = (law r).real A := by + calc + _ = ∫ ω, A.indicator (fun _ => (1:ℝ)) ω ∂law r := by + rw [←map_openEdges r] + exact (integral_map (measurable_openEdges r).aemeasurable + ((measurable_const.indicator (measurableSet_twoLargeEvent G a b n)).aestronglyMeasurable)).symm + _ = _ := by rw [integral_indicator_const _ (measurableSet_twoLargeEvent G a b n)]; simp [A] + simpa only [heq] using ht' + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Score.lean b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Score.lean index d470235d8bd37fbefe9aa7ed558fceb67d13686d..0cee04e07d8842bee5ce02abbae9b242534baf7c 100644 --- a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Score.lean +++ b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Score.lean @@ -1,465 +1,465 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Exploration.TailBounds - -namespace OAI - -/-! Decision-tree scores and influences for two-cluster events. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -namespace ProbeTree - - -theorem score_mean_zero (p h : ℝ) (t : ProbeTree) : - ∑ l, weight p h t l * score p t l = 0 := by - induction t with - | done b => simp [weight,score] - | edge t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 0 - simp only [Fintype.sum_sum_type,weight,score] - have h₀ (l : t₀.Leaf) : (1-p)*weight p h t₀ l*(score p t₀ l-p) = - (1-p)*(weight p h t₀ l*score p t₀ l)-p*(1-p)*weight p h t₀ l := by ring - have h₁ (l : t₁.Leaf) : p*weight p h t₁ l*(score p t₁ l+(1-p)) = - p*(weight p h t₁ l*score p t₁ l)+p*(1-p)*weight p h t₁ l := by ring - simp_rw [h₀,h₁] - simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib,←Finset.mul_sum, - sum_weight,ih₀,ih₁] - ring - | mark t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 0 - simp only [Fintype.sum_sum_type,weight,score,mul_assoc,←Finset.mul_sum,ih₀,ih₁,mul_zero,add_zero] - - - -theorem score_second_moment (p h : ℝ) (t : ProbeTree) : - ∑ l, weight p h t l * score p t l ^ 2 = - p*(1-p) * ∑ l, weight p h t l * (queries t l : ℝ) := by - induction t with - | done b => simp [weight,score,queries] - | edge t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = p*(1-p)*(∑ l : t₀.Leaf ⊕ t₁.Leaf, _) - rw [Fintype.sum_sum_type,Fintype.sum_sum_type] - have h₀ : ∀ l : t₀.Leaf, weight p h (.edge t₀ t₁) (.inl l) * score p (.edge t₀ t₁) (.inl l)^2 = - (1-p)*(weight p h t₀ l*score p t₀ l^2) - - (2*p*(1-p))*(weight p h t₀ l*score p t₀ l) + p^2*(1-p)*weight p h t₀ l := by - intro l; simp only [weight,score]; ring - have h₁ : ∀ l : t₁.Leaf, weight p h (.edge t₀ t₁) (.inr l) * score p (.edge t₀ t₁) (.inr l)^2 = - p*(weight p h t₁ l*score p t₁ l^2) + - (2*p*(1-p))*(weight p h t₁ l*score p t₁ l) + p*(1-p)^2*weight p h t₁ l := by - intro l; simp only [weight,score]; ring - simp_rw [h₀,h₁] - simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib,←Finset.mul_sum, - score_mean_zero,sum_weight,mul_zero,mul_one,sub_zero,add_zero,ih₀,ih₁, - weight,queries,Nat.cast_add,Nat.cast_one] - simp only [mul_add,mul_one,Finset.sum_add_distrib,mul_assoc,←Finset.mul_sum,sum_weight] - ring - | mark t₀ t₁ ih₀ ih₁ => - change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = p*(1-p)*(∑ l : t₀.Leaf ⊕ t₁.Leaf, _) - simp only [Fintype.sum_sum_type,weight,score,queries,mul_assoc,←Finset.mul_sum,ih₀,ih₁] - ring - - -theorem score_abs_mean_le_sqrt (p h : unitInterval) (t : ProbeTree) - (N : ℝ) (hN0 : 0 ≤ N) - (hN : ∑ l, weight p h t l*(queries t l:ℝ) ≤ N) : - ∑ l, weight p h t l * |score p t l| ≤ Real.sqrt N := by - have hw := weight_nonneg p h t - have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ - (fun l => Real.sqrt (weight p h t l)) - (fun l => Real.sqrt (weight p h t l)*|score p t l|) - have he : (∑ l, weight p h t l * |score p t l|)^2 ≤ - ∑ l, weight p h t l * score p t l ^2 := by - simpa only [mul_pow,Real.sq_sqrt (hw _),sq_abs, - ←mul_assoc,Real.mul_self_sqrt (hw _),sum_weight,one_mul] using hc - have hp : 0 ≤ (p:ℝ)*(1-p) := mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2) - have hp1 : (p:ℝ)*(1-p) ≤ 1 := by nlinarith [p.2.1,p.2.2] - rw [score_second_moment] at he - have hnon : 0 ≤ ∑ l, weight p h t l*|score p t l| := - Finset.sum_nonneg fun l _ => mul_nonneg (hw l) (abs_nonneg _) - apply (Real.le_sqrt hnon hN0).mpr - exact he.trans ((mul_le_mul_of_nonneg_left hN hp).trans (by nlinarith [hN0])) - -end ProbeTree -namespace EdgeQueryTree -attribute [local instance] Classical.propDecidable Classical.decEq - - -theorem capped_score_abs_mean_le (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) - (p : unitInterval) (N : ℕ) (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : - bernoulliPolynomial Q (fun ω => |t.score p ω|) p ≤ Real.sqrt (N:ℝ) := by - have hq : ∑ l, ProbeTree.weight p 0 t.forget l*(ProbeTree.queries t.forget l:ℝ) ≤ N := by - rw [←t.leaf_expectation ht p (fun l => (ProbeTree.queries t.forget l:ℝ))] - calc - _ ≤ bernoulliPolynomial Q (fun _ => (N:ℝ)) p := by - apply bernoulliPolynomial_mono _ _ _ p p.2 - intro ω hω - exact_mod_cast hN ω hω - _ = N := bernoulliPolynomial_const Q (N:ℝ) p - change bernoulliPolynomial Q (fun ω => |ProbeTree.score p t.forget (t.leaf ω)|) p ≤ _ - rw [t.leaf_expectation ht p (fun l => |ProbeTree.score p t.forget l|)] - exact ProbeTree.score_abs_mean_le_sqrt p 0 t.forget N (Nat.cast_nonneg N) hq - -end EdgeQueryTree - -theorem incidenceSearch_abs_mean_le (G : BondGraph V E) (N : ℕ) (Q : Finset E) - (R : Finset V) (p : unitInterval) : - bernoulliPolynomial Q (fun ω => |(incidenceSearch G N Q R).score p ω|) p ≤ - Real.sqrt (N:ℝ) := by - classical - exact EdgeQueryTree.capped_score_abs_mean_le _ (incidenceSearch_valid ..) p N - (fun ω _ => incidenceSearch_cap G N Q R ω) - -end Percolation - -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def finiteClusterScore (G : BondGraph V E) (Q : Finset E) - (x : V) (p : ℝ) (ω : Finset E) : ℝ := - ∑ e ∈ incidentBonds G Q (finiteRootComponent G ω x), ((if e ∈ ω then 1 else 0)-p) - - -noncomputable def cappedDensity (n s : ℕ) : ℝ := min (n:ℝ) s / s - -theorem cappedDensity_nonneg (n s : ℕ) : 0 ≤ cappedDensity n s := by - unfold cappedDensity - positivity - -theorem cappedDensity_le_one (n s : ℕ) : cappedDensity n s ≤ 1 := by - unfold cappedDensity - by_cases hs : s = 0 - · simp [hs] - · exact (div_le_one (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hs))).mpr (min_le_right ..) - -private theorem exists_four_scale (n s K : ℕ) (hs : n < s) (hK : s ≤ n*4^K) : - ∃ j < K, n*4^j < s ∧ s ≤ n*4^(j+1) := by - induction K with - | zero => simp only [pow_zero,mul_one] at hK; omega - | succ K ih => - by_cases h : s ≤ n*4^K - · obtain ⟨j,hj,hj₁,hj₂⟩ := ih h - exact ⟨j,by omega,hj₁,hj₂⟩ - · exact ⟨K,by omega,by omega,hK⟩ - -private theorem nat_le_four_pow (k : ℕ) : k ≤ 4^k := by - induction k with - | zero => simp - | succ k ih => rw [pow_succ]; have := Nat.one_le_pow k 4 (by omega); omega - -private theorem cappedDensity_le_four_scale (n s j : ℕ) (hn : 0 < n) - (hs : n*4^j < s) : cappedDensity n s ≤ (1/4:ℝ)^j := by - have hpow : 1 ≤ 4^j := Nat.one_le_pow j 4 (by omega) - have hns : n ≤ s := le_trans (by nlinarith : n ≤ n*4^j) hs.le - have hs0 : 0 < (s:ℝ) := by exact_mod_cast (lt_of_lt_of_le hn hns) - have hden : 0 < (n:ℝ)*4^j := mul_pos (Nat.cast_pos.mpr hn) (pow_pos (by norm_num) _) - unfold cappedDensity - rw [min_eq_left (by exact_mod_cast hns)] - calc - (n:ℝ)/s ≤ n/(n*4^j) := div_le_div_of_nonneg_left (Nat.cast_nonneg _) hden (by exact_mod_cast hs.le) - _ = (1/4:ℝ)^j := by rw [div_pow,one_pow]; field_simp - - - -theorem cappedDensity_score_le_stopped (G : BondGraph V E) (Q : Finset E) - (x : V) (p : ℝ) (d n K : ℕ) (hn : 0 < n) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) - (ω : Finset E) (hω : ω ⊆ Q) - (hK : (finiteRootComponent G ω x).card ≤ n*4^K) : - cappedDensity n (finiteRootComponent G ω x).card * |finiteClusterScore G Q x p ω| ≤ - |(incidenceSearch G (d*n) Q {x}).score p ω| + - ∑ j ∈ Finset.range K, (1/4:ℝ)^j * - |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := by - let s := (finiteRootComponent G ω x).card - have hcomplete (N : ℕ) (hN : s ≤ N) : - (incidenceSearch G (d*N) Q {x}).score p ω = finiteClusterScore G Q x p ω := by - exact incidenceSearch_completed_score G (d*N) Q ω hω x p - ((incidentBonds_card_le G Q _ d hdeg).trans (Nat.mul_le_mul_left d hN)) - have hterms : ∀ j, 0 ≤ (1/4:ℝ)^j * - |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := fun j => by positivity - by_cases hs : s ≤ n - · have he := hcomplete n hs - rw [he] - exact (mul_le_of_le_one_left (abs_nonneg _) (cappedDensity_le_one n s)).trans - (le_add_of_nonneg_right (Finset.sum_nonneg fun j _ => hterms j)) - · obtain ⟨j,hj,hlo,hhi⟩ := exists_four_scale n s K (by omega) hK - have he := hcomplete (n*4^(j+1)) hhi - calc - _ ≤ (1/4:ℝ)^j * |finiteClusterScore G Q x p ω| := - mul_le_mul_of_nonneg_right (cappedDensity_le_four_scale n s j hn hlo) (abs_nonneg _) - _ = (1/4:ℝ)^j * |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := by rw [he] - _ ≤ ∑ j ∈ Finset.range K, (1/4:ℝ)^j * - |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := - Finset.single_le_sum (fun j _ => hterms j) (Finset.mem_range.mpr hj) - _ ≤ _ := le_add_of_nonneg_left (abs_nonneg _) - -private theorem sqrt_four_cap (d n j : ℕ) : - Real.sqrt (d*(n*4^(j+1)):ℕ) = (2:ℝ)^(j+1)*Real.sqrt (d*n:ℕ) := by - have he : (d*(n*4^(j+1)):ℕ) = (d*n)*4^(j+1) := by ring - rw [he,Nat.cast_mul,Real.sqrt_mul (Nat.cast_nonneg _)] - rw [Nat.cast_pow,Nat.cast_ofNat,show (4:ℝ) = 2^2 by norm_num,←pow_mul,pow_mul',Real.sqrt_sq_eq_abs, - abs_of_nonneg (pow_nonneg (by norm_num : (0:ℝ) ≤ 2) _)] - ring - -theorem cappedDensity_score_expectation_bound (G : BondGraph V E) (Q : Finset E) - (x : V) (p : unitInterval) (d n : ℕ) (hn : 0 < n) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : - bernoulliPolynomial Q (fun ω => cappedDensity n (finiteRootComponent G ω x).card * - |finiteClusterScore G Q x p ω|) p ≤ 5*Real.sqrt (d*n:ℕ) := by - let K := (insert x (searchVertices G Q)).card - have hK (ω : Finset E) (hω : ω ⊆ Q) : (finiteRootComponent G ω x).card ≤ n*4^K := by - have hs : (finiteRootComponent G ω x).card ≤ K := - Finset.card_le_card (finiteRootComponent_subset G Q _ x ω hω le_rfl) - exact hs.trans ((nat_le_four_pow K).trans (by nlinarith [Nat.one_le_pow K 4 (by omega)])) - have hp := bernoulliPolynomial_mono Q _ _ p p.2 (fun ω hω => - cappedDensity_score_le_stopped G Q x p d n K hn hdeg ω hω (hK ω hω)) - rw [bernoulliPolynomial_add,bernoulliPolynomial_sum] at hp - simp_rw [bernoulliPolynomial_const_mul] at hp - have hh := hp.trans (add_le_add (incidenceSearch_abs_mean_le G (d*n) Q {x} p) - (Finset.sum_le_sum fun j _ => mul_le_mul_of_nonneg_left - (incidenceSearch_abs_mean_le G (d*(n*4^(j+1))) Q {x} p) (by positivity))) - simp_rw [sqrt_four_cap] at hh - have he (j : ℕ) : (1/4:ℝ)^j*((2:ℝ)^(j+1)*Real.sqrt (d*n:ℕ)) = - 2*(1/2:ℝ)^j*Real.sqrt (d*n:ℕ) := by - rw [pow_succ] - calc - _ = 2*((1/4:ℝ)^j*2^j)*Real.sqrt (d*n:ℕ) := by ring - _ = _ := by rw [←mul_pow]; norm_num - simp_rw [he] at hh - rw [←Finset.sum_mul,←Finset.mul_sum] at hh - have hg : ∑ j ∈ Finset.range K, (1/2:ℝ)^j ≤ 2 := by - have hid : ∑ j ∈ Finset.range K, (1/2:ℝ)^j = 2-2*(1/2:ℝ)^K := by - induction K with - | zero => simp - | succ K ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring - rw [hid] - linarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 1/2) K] - exact hh.trans (by nlinarith [Real.sqrt_nonneg (d*n:ℕ)]) - -end Percolation - - - - - -open MeasureTheory ProbabilityTheory -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -theorem incident_cluster_insert_iff (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : - (∃ a, Conn G (insert e ω) x a ∧ a ∈ G e) ↔ - ∃ a, Conn G ω x a ∧ a ∈ G e := by - obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) - exact ⟨a,b,h.symm⟩ - constructor - · rintro ⟨z,hz,hze⟩ - rcases (conn_insert_iff G ω e a b x z hab).mp hz with hz | ⟨hxa,_⟩ | ⟨hxb,_⟩ - · exact ⟨z,hz,hze⟩ - · exact ⟨a,hxa,hab ▸ by simp⟩ - · exact ⟨b,hxb,hab ▸ by simp⟩ - · rintro ⟨z,hz,hze⟩ - exact ⟨z,conn_mono G (Set.subset_insert e ω) hz,hze⟩ - -theorem cluster_insert_eq_of_not_incident (G : BondGraph V E) (ω : Set E) (x : V) (e : E) - (hn : ¬∃ a, Conn G ω x a ∧ a ∈ G e) : - cluster G (insert e ω) x = cluster G ω x := by - obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) - exact ⟨a,b,h.symm⟩ - ext z - constructor - · intro hz - rcases (conn_insert_iff G ω e a b x z hab).mp hz with hz | ⟨hxa,_⟩ | ⟨hxb,_⟩ - · exact hz - · exact (hn ⟨a,hxa,hab ▸ by simp⟩).elim - · exact (hn ⟨b,hxb,hab ▸ by simp⟩).elim - · exact conn_mono G (Set.subset_insert e ω) - -theorem finite_incident_insert_iff (G : BondGraph V E) (Q ω : Finset E) (x : V) (e : E) : - e ∈ incidentBonds G Q (finiteRootComponent G (insert e ω) x) ↔ - e ∈ incidentBonds G Q (finiteRootComponent G ω x) := by - simp only [mem_incidentBonds] - have hc (η : Finset E) (a : V) : a ∈ finiteRootComponent G η x ↔ Conn G (η:Set E) x a := by - change a ∈ (finiteRootComponent G η x:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - simp only [hc,Finset.coe_insert,incident_cluster_insert_iff] - -theorem finiteRootComponent_insert_eq_of_not_incident (G : BondGraph V E) - (Q ω : Finset E) (x : V) (e : E) (he : e ∈ Q) - (hn : e ∉ incidentBonds G Q (finiteRootComponent G ω x)) : - finiteRootComponent G (insert e ω) x = finiteRootComponent G ω x := by - apply Finset.coe_injective - rw [coe_finiteRootComponent,coe_finiteRootComponent,Finset.coe_insert] - apply cluster_insert_eq_of_not_incident - rintro ⟨a,ha,hae⟩ - apply hn - apply (mem_incidentBonds G Q _ e).mpr - refine ⟨he,a,?_,hae⟩ - change a ∈ (finiteRootComponent G ω x:Set V) - rw [coe_finiteRootComponent] - exact ha - -theorem finiteRootComponent_card_pos (G : BondGraph V E) (ω : Finset E) (x : V) : - 0 < (finiteRootComponent G ω x).card := by - apply Finset.card_pos.mpr - refine ⟨x,?_⟩ - change x ∈ (finiteRootComponent G ω x:Set V) - rw [coe_finiteRootComponent] - exact mem_cluster_self G _ x - -theorem cappedDensity_antitone (n : ℕ) {s t : ℕ} (hs : 0 < s) (hst : s ≤ t) : - cappedDensity n t ≤ cappedDensity n s := by - by_cases hn : s ≤ n - · have he : cappedDensity n s = 1 := by - unfold cappedDensity - rw [min_eq_right (by exact_mod_cast hn),div_self (by exact_mod_cast Nat.ne_of_gt hs)] - rw [he] - exact cappedDensity_le_one n t - · have hs' : (n:ℝ) ≤ s := by exact_mod_cast (le_of_lt (Nat.lt_of_not_ge hn)) - have ht' : (n:ℝ) ≤ t := hs'.trans (by exact_mod_cast hst) - unfold cappedDensity - rw [min_eq_left ht',min_eq_left hs'] - exact div_le_div_of_nonneg_left (Nat.cast_nonneg n) (Nat.cast_pos.mpr hs) (by exact_mod_cast hst) - -noncomputable def finiteDensity (G : BondGraph V E) (n : ℕ) (x : V) (ω : Finset E) : ℝ := - cappedDensity n (finiteRootComponent G ω x).card - -noncomputable def finiteDensityInfluence (G : BondGraph V E) (n : ℕ) (x : V) - (e : E) (ω : Finset E) : ℝ := - if e ∈ ω then 0 else finiteDensity G n x ω - finiteDensity G n x (insert e ω) - -theorem finiteDensityInfluence_nonneg (G : BondGraph V E) (n : ℕ) (x : V) - (e : E) (ω : Finset E) : 0 ≤ finiteDensityInfluence G n x e ω := by - unfold finiteDensityInfluence - split_ifs - · rfl - · apply sub_nonneg.mpr - apply cappedDensity_antitone n (finiteRootComponent_card_pos G ω x) - apply Finset.card_le_card - intro y hy - have hm (η : Finset E) : y ∈ finiteRootComponent G η x ↔ Conn G (η:Set E) x y := by - change y ∈ (finiteRootComponent G η x:Set V) ↔ _ - rw [coe_finiteRootComponent] - rfl - rw [hm] at hy ⊢ - exact conn_mono G (by simp) hy - -theorem finiteDensityInfluence_le_one (G : BondGraph V E) (n : ℕ) (x : V) - (e : E) (ω : Finset E) : finiteDensityInfluence G n x e ω ≤ 1 := by - unfold finiteDensityInfluence finiteDensity - split_ifs - · norm_num - · exact (sub_le_self _ (cappedDensity_nonneg ..)).trans (cappedDensity_le_one ..) - - -theorem finiteDensity_score_one_bit (G : BondGraph V E) (Q : Finset E) (n : ℕ) - (x : V) (p : ℝ) (e : E) (he : e ∈ Q) : - bernoulliPolynomial Q (fun ω => if e ∈ incidentBonds G Q (finiteRootComponent G ω x) - then ((if e ∈ ω then 1 else 0)-p)*finiteDensity G n x ω else 0) p = - -p*bernoulliPolynomial Q (finiteDensityInfluence G n x e) p := by - let f := finiteDensity G n x - let I := fun ω : Finset E => e ∈ incidentBonds G Q (finiteRootComponent G ω x) - let R := Q.erase e - have heR : e ∉ R := Finset.notMem_erase e Q - have hQ : insert e R = Q := Finset.insert_erase he - rw [←hQ,bernoulliPolynomial_insert R e heR,bernoulliPolynomial_insert R e heR] - rw [hQ] - have hclosed (ω : Finset E) (hω : ω ⊆ R) : e ∉ ω := fun h => heR (hω h) - have hc : bernoulliPolynomial R (fun ω => if I ω then ((if e ∈ ω then 1 else 0)-p)*f ω else 0) p = - -p*bernoulliPolynomial R (fun ω => if I ω then f ω else 0) p := by - rw [←bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro ω hω - simp only [ite_eq_right (hclosed ω hω),zero_sub] - split_ifs <;> ring - have ho : bernoulliPolynomial R (fun ω => if I (insert e ω) then - ((if e ∈ insert e ω then 1 else 0)-p)*f (insert e ω) else 0) p = - (1-p)*bernoulliPolynomial R (fun ω => if I ω then f (insert e ω) else 0) p := by - rw [←bernoulliPolynomial_const_mul] - apply bernoulliPolynomial_congr - intro ω _ - simp only [I,finite_incident_insert_iff,Finset.mem_insert_self,ite_true] - split_ifs <;> ring - have hi : bernoulliPolynomial R (finiteDensityInfluence G n x e) p = - bernoulliPolynomial R (fun ω => if I ω then f ω else 0) p - - bernoulliPolynomial R (fun ω => if I ω then f (insert e ω) else 0) p := by - rw [←bernoulliPolynomial_sub] - apply bernoulliPolynomial_congr - intro ω hω - unfold finiteDensityInfluence - rw [ite_eq_right (hclosed ω hω)] - by_cases hi : I ω - · simp only [ite_eq_left hi,f] - · have heq : f (insert e ω) = f ω := by - unfold f finiteDensity - rw [finiteRootComponent_insert_eq_of_not_incident G Q ω x e he hi] - simp only [ite_eq_right hi,heq,sub_self,f] - have hz : bernoulliPolynomial R (fun ω => finiteDensityInfluence G n x e (insert e ω)) p = 0 := by - simp only [finiteDensityInfluence,Finset.mem_insert_self,ite_true,bernoulliPolynomial_zero] - change _ = -p*((1-p)*bernoulliPolynomial R (finiteDensityInfluence G n x e) p+ - p*bernoulliPolynomial R (fun ω => finiteDensityInfluence G n x e (insert e ω)) p) - rw [hc,ho,hi,hz] - ring - - -theorem finiteDensity_score_identity (G : BondGraph V E) (Q : Finset E) (n : ℕ) - (x : V) (p : ℝ) : - bernoulliPolynomial Q (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) p = - -p * ∑ e ∈ Q, bernoulliPolynomial Q (finiteDensityInfluence G n x e) p := by - have hf (ω : Finset E) : finiteDensity G n x ω * finiteClusterScore G Q x p ω = - ∑ e ∈ Q, if e ∈ incidentBonds G Q (finiteRootComponent G ω x) - then ((if e ∈ ω then 1 else 0)-p)*finiteDensity G n x ω else 0 := by - unfold finiteClusterScore - rw [Finset.mul_sum] - symm - rw [←Finset.sum_filter] - have hs : Q.filter (fun e => e ∈ incidentBonds G Q (finiteRootComponent G ω x)) = - incidentBonds G Q (finiteRootComponent G ω x) := by - ext e - simp only [Finset.mem_filter,mem_incidentBonds] - tauto - rw [hs] - apply Finset.sum_congr rfl - intro e _ - ring - simp_rw [hf] - rw [bernoulliPolynomial_sum,Finset.mul_sum] - exact Finset.sum_congr rfl fun e he => finiteDensity_score_one_bit G Q n x p e he - - - -theorem finiteDensityInfluence_sum_bound (G : BondGraph V E) (Q : Finset E) - (x : V) (p : unitInterval) (d n : ℕ) (hn : 0 < n) - (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : - (p:ℝ) * ∑ e ∈ Q, bernoulliPolynomial Q (finiteDensityInfluence G n x e) p ≤ - 5*Real.sqrt (d*n:ℕ) := by - have hid := finiteDensity_score_identity G Q n x p - have hle := bernoulliPolynomial_mono Q - (fun ω => -(finiteDensity G n x ω * finiteClusterScore G Q x p ω)) - (fun ω => cappedDensity n (finiteRootComponent G ω x).card * |finiteClusterScore G Q x p ω|) - p p.2 (fun ω _ => by - rw [←mul_neg] - exact mul_le_mul_of_nonneg_left (neg_le_abs _) (cappedDensity_nonneg ..)) - have hneg : bernoulliPolynomial Q - (fun ω => -(finiteDensity G n x ω * finiteClusterScore G Q x p ω)) p = - -bernoulliPolynomial Q (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) p := by - simpa using bernoulliPolynomial_const_mul Q - (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) (-1) (p:ℝ) - rw [hneg,hid] at hle - have hb := cappedDensity_score_expectation_bound G Q x p d n hn hdeg - linarith - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Exploration.TailBounds + +namespace OAI + +/-! Decision-tree scores and influences for two-cluster events. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +namespace ProbeTree + + +theorem score_mean_zero (p h : ℝ) (t : ProbeTree) : + ∑ l, weight p h t l * score p t l = 0 := by + induction t with + | done b => simp [weight,score] + | edge t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 0 + simp only [Fintype.sum_sum_type,weight,score] + have h₀ (l : t₀.Leaf) : (1-p)*weight p h t₀ l*(score p t₀ l-p) = + (1-p)*(weight p h t₀ l*score p t₀ l)-p*(1-p)*weight p h t₀ l := by ring + have h₁ (l : t₁.Leaf) : p*weight p h t₁ l*(score p t₁ l+(1-p)) = + p*(weight p h t₁ l*score p t₁ l)+p*(1-p)*weight p h t₁ l := by ring + simp_rw [h₀,h₁] + simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib,←Finset.mul_sum, + sum_weight,ih₀,ih₁] + ring + | mark t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = 0 + simp only [Fintype.sum_sum_type,weight,score,mul_assoc,←Finset.mul_sum,ih₀,ih₁,mul_zero,add_zero] + + + +theorem score_second_moment (p h : ℝ) (t : ProbeTree) : + ∑ l, weight p h t l * score p t l ^ 2 = + p*(1-p) * ∑ l, weight p h t l * (queries t l : ℝ) := by + induction t with + | done b => simp [weight,score,queries] + | edge t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = p*(1-p)*(∑ l : t₀.Leaf ⊕ t₁.Leaf, _) + rw [Fintype.sum_sum_type,Fintype.sum_sum_type] + have h₀ : ∀ l : t₀.Leaf, weight p h (.edge t₀ t₁) (.inl l) * score p (.edge t₀ t₁) (.inl l)^2 = + (1-p)*(weight p h t₀ l*score p t₀ l^2) - + (2*p*(1-p))*(weight p h t₀ l*score p t₀ l) + p^2*(1-p)*weight p h t₀ l := by + intro l; simp only [weight,score]; ring + have h₁ : ∀ l : t₁.Leaf, weight p h (.edge t₀ t₁) (.inr l) * score p (.edge t₀ t₁) (.inr l)^2 = + p*(weight p h t₁ l*score p t₁ l^2) + + (2*p*(1-p))*(weight p h t₁ l*score p t₁ l) + p*(1-p)^2*weight p h t₁ l := by + intro l; simp only [weight,score]; ring + simp_rw [h₀,h₁] + simp only [Finset.sum_add_distrib,Finset.sum_sub_distrib,←Finset.mul_sum, + score_mean_zero,sum_weight,mul_zero,mul_one,sub_zero,add_zero,ih₀,ih₁, + weight,queries,Nat.cast_add,Nat.cast_one] + simp only [mul_add,mul_one,Finset.sum_add_distrib,mul_assoc,←Finset.mul_sum,sum_weight] + ring + | mark t₀ t₁ ih₀ ih₁ => + change (∑ l : t₀.Leaf ⊕ t₁.Leaf, _) = p*(1-p)*(∑ l : t₀.Leaf ⊕ t₁.Leaf, _) + simp only [Fintype.sum_sum_type,weight,score,queries,mul_assoc,←Finset.mul_sum,ih₀,ih₁] + ring + + +theorem score_abs_mean_le_sqrt (p h : unitInterval) (t : ProbeTree) + (N : ℝ) (hN0 : 0 ≤ N) + (hN : ∑ l, weight p h t l*(queries t l:ℝ) ≤ N) : + ∑ l, weight p h t l * |score p t l| ≤ Real.sqrt N := by + have hw := weight_nonneg p h t + have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun l => Real.sqrt (weight p h t l)) + (fun l => Real.sqrt (weight p h t l)*|score p t l|) + have he : (∑ l, weight p h t l * |score p t l|)^2 ≤ + ∑ l, weight p h t l * score p t l ^2 := by + simpa only [mul_pow,Real.sq_sqrt (hw _),sq_abs, + ←mul_assoc,Real.mul_self_sqrt (hw _),sum_weight,one_mul] using hc + have hp : 0 ≤ (p:ℝ)*(1-p) := mul_nonneg p.2.1 (sub_nonneg.mpr p.2.2) + have hp1 : (p:ℝ)*(1-p) ≤ 1 := by nlinarith [p.2.1,p.2.2] + rw [score_second_moment] at he + have hnon : 0 ≤ ∑ l, weight p h t l*|score p t l| := + Finset.sum_nonneg fun l _ => mul_nonneg (hw l) (abs_nonneg _) + apply (Real.le_sqrt hnon hN0).mpr + exact he.trans ((mul_le_mul_of_nonneg_left hN hp).trans (by nlinarith [hN0])) + +end ProbeTree +namespace EdgeQueryTree +attribute [local instance] Classical.propDecidable Classical.decEq + + +theorem capped_score_abs_mean_le (t : EdgeQueryTree E) {Q : Finset E} (ht : t.Valid Q) + (p : unitInterval) (N : ℕ) (hN : ∀ ω ⊆ Q, t.queryCount ω ≤ N) : + bernoulliPolynomial Q (fun ω => |t.score p ω|) p ≤ Real.sqrt (N:ℝ) := by + have hq : ∑ l, ProbeTree.weight p 0 t.forget l*(ProbeTree.queries t.forget l:ℝ) ≤ N := by + rw [←t.leaf_expectation ht p (fun l => (ProbeTree.queries t.forget l:ℝ))] + calc + _ ≤ bernoulliPolynomial Q (fun _ => (N:ℝ)) p := by + apply bernoulliPolynomial_mono _ _ _ p p.2 + intro ω hω + exact_mod_cast hN ω hω + _ = N := bernoulliPolynomial_const Q (N:ℝ) p + change bernoulliPolynomial Q (fun ω => |ProbeTree.score p t.forget (t.leaf ω)|) p ≤ _ + rw [t.leaf_expectation ht p (fun l => |ProbeTree.score p t.forget l|)] + exact ProbeTree.score_abs_mean_le_sqrt p 0 t.forget N (Nat.cast_nonneg N) hq + +end EdgeQueryTree + +theorem incidenceSearch_abs_mean_le (G : BondGraph V E) (N : ℕ) (Q : Finset E) + (R : Finset V) (p : unitInterval) : + bernoulliPolynomial Q (fun ω => |(incidenceSearch G N Q R).score p ω|) p ≤ + Real.sqrt (N:ℝ) := by + classical + exact EdgeQueryTree.capped_score_abs_mean_le _ (incidenceSearch_valid ..) p N + (fun ω _ => incidenceSearch_cap G N Q R ω) + +end Percolation + +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def finiteClusterScore (G : BondGraph V E) (Q : Finset E) + (x : V) (p : ℝ) (ω : Finset E) : ℝ := + ∑ e ∈ incidentBonds G Q (finiteRootComponent G ω x), ((if e ∈ ω then 1 else 0)-p) + + +noncomputable def cappedDensity (n s : ℕ) : ℝ := min (n:ℝ) s / s + +theorem cappedDensity_nonneg (n s : ℕ) : 0 ≤ cappedDensity n s := by + unfold cappedDensity + positivity + +theorem cappedDensity_le_one (n s : ℕ) : cappedDensity n s ≤ 1 := by + unfold cappedDensity + by_cases hs : s = 0 + · simp [hs] + · exact (div_le_one (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hs))).mpr (min_le_right ..) + +private theorem exists_four_scale (n s K : ℕ) (hs : n < s) (hK : s ≤ n*4^K) : + ∃ j < K, n*4^j < s ∧ s ≤ n*4^(j+1) := by + induction K with + | zero => simp only [pow_zero,mul_one] at hK; omega + | succ K ih => + by_cases h : s ≤ n*4^K + · obtain ⟨j,hj,hj₁,hj₂⟩ := ih h + exact ⟨j,by omega,hj₁,hj₂⟩ + · exact ⟨K,by omega,by omega,hK⟩ + +private theorem nat_le_four_pow (k : ℕ) : k ≤ 4^k := by + induction k with + | zero => simp + | succ k ih => rw [pow_succ]; have := Nat.one_le_pow k 4 (by omega); omega + +private theorem cappedDensity_le_four_scale (n s j : ℕ) (hn : 0 < n) + (hs : n*4^j < s) : cappedDensity n s ≤ (1/4:ℝ)^j := by + have hpow : 1 ≤ 4^j := Nat.one_le_pow j 4 (by omega) + have hns : n ≤ s := le_trans (by nlinarith : n ≤ n*4^j) hs.le + have hs0 : 0 < (s:ℝ) := by exact_mod_cast (lt_of_lt_of_le hn hns) + have hden : 0 < (n:ℝ)*4^j := mul_pos (Nat.cast_pos.mpr hn) (pow_pos (by norm_num) _) + unfold cappedDensity + rw [min_eq_left (by exact_mod_cast hns)] + calc + (n:ℝ)/s ≤ n/(n*4^j) := div_le_div_of_nonneg_left (Nat.cast_nonneg _) hden (by exact_mod_cast hs.le) + _ = (1/4:ℝ)^j := by rw [div_pow,one_pow]; field_simp + + + +theorem cappedDensity_score_le_stopped (G : BondGraph V E) (Q : Finset E) + (x : V) (p : ℝ) (d n K : ℕ) (hn : 0 < n) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) + (ω : Finset E) (hω : ω ⊆ Q) + (hK : (finiteRootComponent G ω x).card ≤ n*4^K) : + cappedDensity n (finiteRootComponent G ω x).card * |finiteClusterScore G Q x p ω| ≤ + |(incidenceSearch G (d*n) Q {x}).score p ω| + + ∑ j ∈ Finset.range K, (1/4:ℝ)^j * + |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := by + let s := (finiteRootComponent G ω x).card + have hcomplete (N : ℕ) (hN : s ≤ N) : + (incidenceSearch G (d*N) Q {x}).score p ω = finiteClusterScore G Q x p ω := by + exact incidenceSearch_completed_score G (d*N) Q ω hω x p + ((incidentBonds_card_le G Q _ d hdeg).trans (Nat.mul_le_mul_left d hN)) + have hterms : ∀ j, 0 ≤ (1/4:ℝ)^j * + |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := fun j => by positivity + by_cases hs : s ≤ n + · have he := hcomplete n hs + rw [he] + exact (mul_le_of_le_one_left (abs_nonneg _) (cappedDensity_le_one n s)).trans + (le_add_of_nonneg_right (Finset.sum_nonneg fun j _ => hterms j)) + · obtain ⟨j,hj,hlo,hhi⟩ := exists_four_scale n s K (by omega) hK + have he := hcomplete (n*4^(j+1)) hhi + calc + _ ≤ (1/4:ℝ)^j * |finiteClusterScore G Q x p ω| := + mul_le_mul_of_nonneg_right (cappedDensity_le_four_scale n s j hn hlo) (abs_nonneg _) + _ = (1/4:ℝ)^j * |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := by rw [he] + _ ≤ ∑ j ∈ Finset.range K, (1/4:ℝ)^j * + |(incidenceSearch G (d*(n*4^(j+1))) Q {x}).score p ω| := + Finset.single_le_sum (fun j _ => hterms j) (Finset.mem_range.mpr hj) + _ ≤ _ := le_add_of_nonneg_left (abs_nonneg _) + +private theorem sqrt_four_cap (d n j : ℕ) : + Real.sqrt (d*(n*4^(j+1)):ℕ) = (2:ℝ)^(j+1)*Real.sqrt (d*n:ℕ) := by + have he : (d*(n*4^(j+1)):ℕ) = (d*n)*4^(j+1) := by ring + rw [he,Nat.cast_mul,Real.sqrt_mul (Nat.cast_nonneg _)] + rw [Nat.cast_pow,Nat.cast_ofNat,show (4:ℝ) = 2^2 by norm_num,←pow_mul,pow_mul',Real.sqrt_sq_eq_abs, + abs_of_nonneg (pow_nonneg (by norm_num : (0:ℝ) ≤ 2) _)] + ring + +theorem cappedDensity_score_expectation_bound (G : BondGraph V E) (Q : Finset E) + (x : V) (p : unitInterval) (d n : ℕ) (hn : 0 < n) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : + bernoulliPolynomial Q (fun ω => cappedDensity n (finiteRootComponent G ω x).card * + |finiteClusterScore G Q x p ω|) p ≤ 5*Real.sqrt (d*n:ℕ) := by + let K := (insert x (searchVertices G Q)).card + have hK (ω : Finset E) (hω : ω ⊆ Q) : (finiteRootComponent G ω x).card ≤ n*4^K := by + have hs : (finiteRootComponent G ω x).card ≤ K := + Finset.card_le_card (finiteRootComponent_subset G Q _ x ω hω le_rfl) + exact hs.trans ((nat_le_four_pow K).trans (by nlinarith [Nat.one_le_pow K 4 (by omega)])) + have hp := bernoulliPolynomial_mono Q _ _ p p.2 (fun ω hω => + cappedDensity_score_le_stopped G Q x p d n K hn hdeg ω hω (hK ω hω)) + rw [bernoulliPolynomial_add,bernoulliPolynomial_sum] at hp + simp_rw [bernoulliPolynomial_const_mul] at hp + have hh := hp.trans (add_le_add (incidenceSearch_abs_mean_le G (d*n) Q {x} p) + (Finset.sum_le_sum fun j _ => mul_le_mul_of_nonneg_left + (incidenceSearch_abs_mean_le G (d*(n*4^(j+1))) Q {x} p) (by positivity))) + simp_rw [sqrt_four_cap] at hh + have he (j : ℕ) : (1/4:ℝ)^j*((2:ℝ)^(j+1)*Real.sqrt (d*n:ℕ)) = + 2*(1/2:ℝ)^j*Real.sqrt (d*n:ℕ) := by + rw [pow_succ] + calc + _ = 2*((1/4:ℝ)^j*2^j)*Real.sqrt (d*n:ℕ) := by ring + _ = _ := by rw [←mul_pow]; norm_num + simp_rw [he] at hh + rw [←Finset.sum_mul,←Finset.mul_sum] at hh + have hg : ∑ j ∈ Finset.range K, (1/2:ℝ)^j ≤ 2 := by + have hid : ∑ j ∈ Finset.range K, (1/2:ℝ)^j = 2-2*(1/2:ℝ)^K := by + induction K with + | zero => simp + | succ K ih => rw [Finset.sum_range_succ,ih,pow_succ]; ring + rw [hid] + linarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 1/2) K] + exact hh.trans (by nlinarith [Real.sqrt_nonneg (d*n:ℕ)]) + +end Percolation + + + + + +open MeasureTheory ProbabilityTheory +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +theorem incident_cluster_insert_iff (G : BondGraph V E) (ω : Set E) (x : V) (e : E) : + (∃ a, Conn G (insert e ω) x a ∧ a ∈ G e) ↔ + ∃ a, Conn G ω x a ∧ a ∈ G e := by + obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) + exact ⟨a,b,h.symm⟩ + constructor + · rintro ⟨z,hz,hze⟩ + rcases (conn_insert_iff G ω e a b x z hab).mp hz with hz | ⟨hxa,_⟩ | ⟨hxb,_⟩ + · exact ⟨z,hz,hze⟩ + · exact ⟨a,hxa,hab ▸ by simp⟩ + · exact ⟨b,hxb,hab ▸ by simp⟩ + · rintro ⟨z,hz,hze⟩ + exact ⟨z,conn_mono G (Set.subset_insert e ω) hz,hze⟩ + +theorem cluster_insert_eq_of_not_incident (G : BondGraph V E) (ω : Set E) (x : V) (e : E) + (hn : ¬∃ a, Conn G ω x a ∧ a ∈ G e) : + cluster G (insert e ω) x = cluster G ω x := by + obtain ⟨a,b,hab⟩ : ∃ a b, G e = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) + exact ⟨a,b,h.symm⟩ + ext z + constructor + · intro hz + rcases (conn_insert_iff G ω e a b x z hab).mp hz with hz | ⟨hxa,_⟩ | ⟨hxb,_⟩ + · exact hz + · exact (hn ⟨a,hxa,hab ▸ by simp⟩).elim + · exact (hn ⟨b,hxb,hab ▸ by simp⟩).elim + · exact conn_mono G (Set.subset_insert e ω) + +theorem finite_incident_insert_iff (G : BondGraph V E) (Q ω : Finset E) (x : V) (e : E) : + e ∈ incidentBonds G Q (finiteRootComponent G (insert e ω) x) ↔ + e ∈ incidentBonds G Q (finiteRootComponent G ω x) := by + simp only [mem_incidentBonds] + have hc (η : Finset E) (a : V) : a ∈ finiteRootComponent G η x ↔ Conn G (η:Set E) x a := by + change a ∈ (finiteRootComponent G η x:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + simp only [hc,Finset.coe_insert,incident_cluster_insert_iff] + +theorem finiteRootComponent_insert_eq_of_not_incident (G : BondGraph V E) + (Q ω : Finset E) (x : V) (e : E) (he : e ∈ Q) + (hn : e ∉ incidentBonds G Q (finiteRootComponent G ω x)) : + finiteRootComponent G (insert e ω) x = finiteRootComponent G ω x := by + apply Finset.coe_injective + rw [coe_finiteRootComponent,coe_finiteRootComponent,Finset.coe_insert] + apply cluster_insert_eq_of_not_incident + rintro ⟨a,ha,hae⟩ + apply hn + apply (mem_incidentBonds G Q _ e).mpr + refine ⟨he,a,?_,hae⟩ + change a ∈ (finiteRootComponent G ω x:Set V) + rw [coe_finiteRootComponent] + exact ha + +theorem finiteRootComponent_card_pos (G : BondGraph V E) (ω : Finset E) (x : V) : + 0 < (finiteRootComponent G ω x).card := by + apply Finset.card_pos.mpr + refine ⟨x,?_⟩ + change x ∈ (finiteRootComponent G ω x:Set V) + rw [coe_finiteRootComponent] + exact mem_cluster_self G _ x + +theorem cappedDensity_antitone (n : ℕ) {s t : ℕ} (hs : 0 < s) (hst : s ≤ t) : + cappedDensity n t ≤ cappedDensity n s := by + by_cases hn : s ≤ n + · have he : cappedDensity n s = 1 := by + unfold cappedDensity + rw [min_eq_right (by exact_mod_cast hn),div_self (by exact_mod_cast Nat.ne_of_gt hs)] + rw [he] + exact cappedDensity_le_one n t + · have hs' : (n:ℝ) ≤ s := by exact_mod_cast (le_of_lt (Nat.lt_of_not_ge hn)) + have ht' : (n:ℝ) ≤ t := hs'.trans (by exact_mod_cast hst) + unfold cappedDensity + rw [min_eq_left ht',min_eq_left hs'] + exact div_le_div_of_nonneg_left (Nat.cast_nonneg n) (Nat.cast_pos.mpr hs) (by exact_mod_cast hst) + +noncomputable def finiteDensity (G : BondGraph V E) (n : ℕ) (x : V) (ω : Finset E) : ℝ := + cappedDensity n (finiteRootComponent G ω x).card + +noncomputable def finiteDensityInfluence (G : BondGraph V E) (n : ℕ) (x : V) + (e : E) (ω : Finset E) : ℝ := + if e ∈ ω then 0 else finiteDensity G n x ω - finiteDensity G n x (insert e ω) + +theorem finiteDensityInfluence_nonneg (G : BondGraph V E) (n : ℕ) (x : V) + (e : E) (ω : Finset E) : 0 ≤ finiteDensityInfluence G n x e ω := by + unfold finiteDensityInfluence + split_ifs + · rfl + · apply sub_nonneg.mpr + apply cappedDensity_antitone n (finiteRootComponent_card_pos G ω x) + apply Finset.card_le_card + intro y hy + have hm (η : Finset E) : y ∈ finiteRootComponent G η x ↔ Conn G (η:Set E) x y := by + change y ∈ (finiteRootComponent G η x:Set V) ↔ _ + rw [coe_finiteRootComponent] + rfl + rw [hm] at hy ⊢ + exact conn_mono G (by simp) hy + +theorem finiteDensityInfluence_le_one (G : BondGraph V E) (n : ℕ) (x : V) + (e : E) (ω : Finset E) : finiteDensityInfluence G n x e ω ≤ 1 := by + unfold finiteDensityInfluence finiteDensity + split_ifs + · norm_num + · exact (sub_le_self _ (cappedDensity_nonneg ..)).trans (cappedDensity_le_one ..) + + +theorem finiteDensity_score_one_bit (G : BondGraph V E) (Q : Finset E) (n : ℕ) + (x : V) (p : ℝ) (e : E) (he : e ∈ Q) : + bernoulliPolynomial Q (fun ω => if e ∈ incidentBonds G Q (finiteRootComponent G ω x) + then ((if e ∈ ω then 1 else 0)-p)*finiteDensity G n x ω else 0) p = + -p*bernoulliPolynomial Q (finiteDensityInfluence G n x e) p := by + let f := finiteDensity G n x + let I := fun ω : Finset E => e ∈ incidentBonds G Q (finiteRootComponent G ω x) + let R := Q.erase e + have heR : e ∉ R := Finset.notMem_erase e Q + have hQ : insert e R = Q := Finset.insert_erase he + rw [←hQ,bernoulliPolynomial_insert R e heR,bernoulliPolynomial_insert R e heR] + rw [hQ] + have hclosed (ω : Finset E) (hω : ω ⊆ R) : e ∉ ω := fun h => heR (hω h) + have hc : bernoulliPolynomial R (fun ω => if I ω then ((if e ∈ ω then 1 else 0)-p)*f ω else 0) p = + -p*bernoulliPolynomial R (fun ω => if I ω then f ω else 0) p := by + rw [←bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro ω hω + simp only [ite_eq_right (hclosed ω hω),zero_sub] + split_ifs <;> ring + have ho : bernoulliPolynomial R (fun ω => if I (insert e ω) then + ((if e ∈ insert e ω then 1 else 0)-p)*f (insert e ω) else 0) p = + (1-p)*bernoulliPolynomial R (fun ω => if I ω then f (insert e ω) else 0) p := by + rw [←bernoulliPolynomial_const_mul] + apply bernoulliPolynomial_congr + intro ω _ + simp only [I,finite_incident_insert_iff,Finset.mem_insert_self,ite_true] + split_ifs <;> ring + have hi : bernoulliPolynomial R (finiteDensityInfluence G n x e) p = + bernoulliPolynomial R (fun ω => if I ω then f ω else 0) p - + bernoulliPolynomial R (fun ω => if I ω then f (insert e ω) else 0) p := by + rw [←bernoulliPolynomial_sub] + apply bernoulliPolynomial_congr + intro ω hω + unfold finiteDensityInfluence + rw [ite_eq_right (hclosed ω hω)] + by_cases hi : I ω + · simp only [ite_eq_left hi,f] + · have heq : f (insert e ω) = f ω := by + unfold f finiteDensity + rw [finiteRootComponent_insert_eq_of_not_incident G Q ω x e he hi] + simp only [ite_eq_right hi,heq,sub_self,f] + have hz : bernoulliPolynomial R (fun ω => finiteDensityInfluence G n x e (insert e ω)) p = 0 := by + simp only [finiteDensityInfluence,Finset.mem_insert_self,ite_true,bernoulliPolynomial_zero] + change _ = -p*((1-p)*bernoulliPolynomial R (finiteDensityInfluence G n x e) p+ + p*bernoulliPolynomial R (fun ω => finiteDensityInfluence G n x e (insert e ω)) p) + rw [hc,ho,hi,hz] + ring + + +theorem finiteDensity_score_identity (G : BondGraph V E) (Q : Finset E) (n : ℕ) + (x : V) (p : ℝ) : + bernoulliPolynomial Q (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) p = + -p * ∑ e ∈ Q, bernoulliPolynomial Q (finiteDensityInfluence G n x e) p := by + have hf (ω : Finset E) : finiteDensity G n x ω * finiteClusterScore G Q x p ω = + ∑ e ∈ Q, if e ∈ incidentBonds G Q (finiteRootComponent G ω x) + then ((if e ∈ ω then 1 else 0)-p)*finiteDensity G n x ω else 0 := by + unfold finiteClusterScore + rw [Finset.mul_sum] + symm + rw [←Finset.sum_filter] + have hs : Q.filter (fun e => e ∈ incidentBonds G Q (finiteRootComponent G ω x)) = + incidentBonds G Q (finiteRootComponent G ω x) := by + ext e + simp only [Finset.mem_filter,mem_incidentBonds] + tauto + rw [hs] + apply Finset.sum_congr rfl + intro e _ + ring + simp_rw [hf] + rw [bernoulliPolynomial_sum,Finset.mul_sum] + exact Finset.sum_congr rfl fun e he => finiteDensity_score_one_bit G Q n x p e he + + + +theorem finiteDensityInfluence_sum_bound (G : BondGraph V E) (Q : Finset E) + (x : V) (p : unitInterval) (d n : ℕ) (hn : 0 < n) + (hdeg : ∀ v, (Q.filter fun e => v ∈ G e).card ≤ d) : + (p:ℝ) * ∑ e ∈ Q, bernoulliPolynomial Q (finiteDensityInfluence G n x e) p ≤ + 5*Real.sqrt (d*n:ℕ) := by + have hid := finiteDensity_score_identity G Q n x p + have hle := bernoulliPolynomial_mono Q + (fun ω => -(finiteDensity G n x ω * finiteClusterScore G Q x p ω)) + (fun ω => cappedDensity n (finiteRootComponent G ω x).card * |finiteClusterScore G Q x p ω|) + p p.2 (fun ω _ => by + rw [←mul_neg] + exact mul_le_mul_of_nonneg_left (neg_le_abs _) (cappedDensity_nonneg ..)) + have hneg : bernoulliPolynomial Q + (fun ω => -(finiteDensity G n x ω * finiteClusterScore G Q x p ω)) p = + -bernoulliPolynomial Q (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) p := by + simpa using bernoulliPolynomial_const_mul Q + (fun ω => finiteDensity G n x ω * finiteClusterScore G Q x p ω) (-1) (p:ℝ) + rw [hneg,hid] at hle + have hb := cappedDensity_score_expectation_bound G Q x p d n hn hdeg + linarith + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Transport.lean b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Transport.lean index 13af820ed9b8c6a278ff74d853a5d1d4a6afb6eb..80b36e24d29bc43f3c6a5a020684ee6870bcd5eb 100644 --- a/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Transport.lean +++ b/lean/OAI/Probability/UnimodularPercolation/TwoCluster/Transport.lean @@ -1,357 +1,357 @@ -import Mathlib -import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts -import OAI.Probability.UnimodularPercolation.TwoCluster.Score - -namespace OAI - -/-! Infinite-volume two-cluster limits and transport. -/ - -open MeasureTheory ProbabilityTheory -open scoped ENNReal NNReal - -open MeasureTheory ProbabilityTheory Filter -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def clusterDensity (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : ℝ := - cappedDensity n (cluster G ω x).ncard - -noncomputable def densityInfluence (G : BondGraph V E) (n : ℕ) (x : V) - (e : E) (ω : Set E) : ℝ := - if e ∈ ω then 0 else clusterDensity G n x ω - clusterDensity G n x (insert e ω) - -theorem clusterDensity_nonneg (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : - 0 ≤ clusterDensity G n x ω := cappedDensity_nonneg .. - -theorem clusterDensity_le_one (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : - clusterDensity G n x ω ≤ 1 := cappedDensity_le_one .. - -theorem clusterDensity_antitone (G : BondGraph V E) (n : ℕ) (x : V) - {ω η : Set E} (h : ω ⊆ η) : clusterDensity G n x η ≤ clusterDensity G n x ω := by - by_cases hη : (cluster G η x).Finite - · have hω : (cluster G ω x).Finite := hη.subset (fun y hy => conn_mono G h hy) - exact cappedDensity_antitone n ((Set.ncard_pos hω).mpr ⟨x,mem_cluster_self G ω x⟩) - (Set.ncard_le_ncard (fun y hy => conn_mono G h hy) hη) - · rw [clusterDensity,Set.Infinite.ncard hη] - simpa [cappedDensity] using clusterDensity_nonneg G n x ω - -theorem densityInfluence_nonneg (G : BondGraph V E) (n : ℕ) (x : V) (e : E) (ω : Set E) : - 0 ≤ densityInfluence G n x e ω := by - unfold densityInfluence - split_ifs - · exact le_rfl - · exact sub_nonneg.mpr (clusterDensity_antitone G n x (Set.subset_insert e ω)) - -theorem densityInfluence_le_one (G : BondGraph V E) (n : ℕ) (x : V) (e : E) (ω : Set E) : - densityInfluence G n x e ω ≤ 1 := by - unfold densityInfluence - split_ifs - · norm_num - · exact (sub_le_self _ (clusterDensity_nonneg ..)).trans (clusterDensity_le_one ..) - -theorem measurable_clusterDensity (G : BondGraph V E) (hloc : LocallyFinite G) (n : ℕ) (x : V) : - Measurable (clusterDensity G n x) := - (measurable_of_countable (cappedDensity n)).comp (measurable_cluster_ncard G hloc x) - -theorem measurable_densityInfluence (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (x : V) (e : E) : Measurable (densityInfluence G n x e) := by - exact measurable_const.ite (measurableSet_mem e) - ((measurable_clusterDensity G hloc n x).sub - ((measurable_clusterDensity G hloc n x).comp (measurable_set_insert e))) - -theorem integrable_densityInfluence (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (x : V) (e : E) (p : unitInterval) : - Integrable (densityInfluence G n x e) (law p) := by - apply Integrable.mono' (integrable_const (1:ℝ)) (measurable_densityInfluence G hloc n x e).aestronglyMeasurable - exact Eventually.of_forall fun ω => by - rw [Real.norm_eq_abs,abs_of_nonneg (densityInfluence_nonneg ..)] - exact densityInfluence_le_one .. - -theorem cluster_insert_finite (G : BondGraph V E) (ω : Set E) (e : E) (x a b : V) - (he : G e = s(a,b)) (hx : (cluster G ω x).Finite) - (ha : (cluster G ω a).Finite) (hb : (cluster G ω b).Finite) : - (cluster G (insert e ω) x).Finite := by - apply (hx.union (ha.union hb)).subset - intro y hy - rcases (conn_insert_iff G ω e a b x y he).mp hy with hy | ⟨_,hy⟩ | ⟨_,hy⟩ - · exact Or.inl hy - · exact Or.inr (Or.inr hy) - · exact Or.inr (Or.inl hy) - -theorem cluster_insert_finite_ae (G : BondGraph V E) (p : unitInterval) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (x : V) (e : E) : - ∀ᵐ ω ∂law p, (cluster G (insert e ω) x).Finite := by - obtain ⟨a,b,he⟩ : ∃ a b, G e = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) - exact ⟨a,b,h.symm⟩ - filter_upwards [hfin x,hfin a,hfin b] with ω hx ha hb - exact cluster_insert_finite G ω e x a b he hx ha hb - -theorem finiteDensity_eq_clusterDensity (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (x : V) (ω : Set E) (hx : (cluster G ω x).Finite) - (Q : Finset E) (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : - finiteDensity G n x (domainBits Q ω) = clusterDensity G n x ω := by - have hc : cluster G (domainBits Q ω:Set E) x = cluster G ω x := by - rw [coe_domainBits] - have hh := (cluster_restrict_incident_eq_iff G hloc hx.toFinset Q hQ ω x).mpr - (Set.Finite.coe_toFinset hx).symm - simpa only [Set.Finite.coe_toFinset] using hh - unfold finiteDensity clusterDensity - rw [←Set.ncard_coe_finset,coe_finiteRootComponent,hc] - -theorem domainBits_insert (Q : Finset E) (e : E) (he : e ∈ Q) (ω : Set E) : - domainBits Q (insert e ω) = insert e (domainBits Q ω) := by - ext f - simp only [mem_domainBits,Set.mem_insert_iff,Finset.mem_insert] - aesop - -theorem densityInfluence_tendsto_finite [Encodable E] (G : BondGraph V E) (hloc : LocallyFinite G) - (n : ℕ) (x : V) (e : E) (ω : Set E) (hx : (cluster G ω x).Finite) - (he : (cluster G (insert e ω) x).Finite) (F : Finset E) : - Tendsto (fun j => finiteDensityInfluence G n x e - (domainBits (F ∪ vertexExhaustion (V := E) j) ω)) atTop - (nhds (densityInfluence G n x e ω)) := by - obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hx.toFinset) - obtain ⟨je,hje⟩ := subset_vertexExhaustion (incidentSupport G hloc he.toFinset) - obtain ⟨j₀,hj₀'⟩ := subset_vertexExhaustion ({e}:Finset E) - have hj₀ : e ∈ vertexExhaustion (V := E) j₀ := hj₀' (by simp) - have hev : (fun j => finiteDensityInfluence G n x e - (domainBits (F ∪ vertexExhaustion (V := E) j) ω)) =ᶠ[atTop] - (fun _ => densityInfluence G n x e ω) := by - filter_upwards [eventually_ge_atTop (max jx (max je j₀))] with j hj - let Q := F ∪ vertexExhaustion (V := E) j - have hxQ : incidentSupport G hloc hx.toFinset ⊆ Q := fun z hz => - Finset.mem_union_right _ (vertexExhaustion_mono (by omega) (hjx hz)) - have heQ : incidentSupport G hloc he.toFinset ⊆ Q := fun z hz => - Finset.mem_union_right _ (vertexExhaustion_mono (by omega) (hje hz)) - have heQ' : e ∈ Q := Finset.mem_union_right _ (vertexExhaustion_mono (by omega) hj₀) - change finiteDensityInfluence G n x e (domainBits Q ω) = _ - unfold finiteDensityInfluence densityInfluence - simp only [mem_domainBits,heQ',true_and] - split_ifs - · rfl - · rw [finiteDensity_eq_clusterDensity G hloc n x ω hx Q hxQ, - ←domainBits_insert Q e heQ' ω,finiteDensity_eq_clusterDensity G hloc n x (insert e ω) he Q heQ] - exact tendsto_const_nhds.congr' hev.symm - -theorem densityInfluence_integral_tendsto [Encodable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (n : ℕ) (x : V) (e : E) (p : unitInterval) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (F : Finset E) : - Tendsto (fun j => bernoulliPolynomial (F ∪ vertexExhaustion (V := E) j) - (finiteDensityInfluence G n x e) p) atTop - (nhds (∫ ω, densityInfluence G n x e ω ∂law p)) := by - let Q := fun j => F ∪ vertexExhaustion (V := E) j - let f := fun j ω => finiteDensityInfluence G n x e (domainBits (Q j) ω) - have hfi (j : ℕ) : Integrable (f j) (law p) := - integrable_finite_local (Q j) p (f j) (fun ω => by dsimp [f]; rw [domainBits_local]) - have ht : ∀ᵐ ω ∂law p, Tendsto (fun j => f j ω) atTop (nhds (densityInfluence G n x e ω)) := by - filter_upwards [hfin x,cluster_insert_finite_ae G p hfin x e] with ω hx he - exact densityInfluence_tendsto_finite G hloc n x e ω hx he F - have hd := tendsto_integral_of_dominated_convergence (fun _ : Set E => (1:ℝ)) - (fun j => (hfi j).aestronglyMeasurable) (integrable_const _) - (fun j => Eventually.of_forall (fun ω => by - rw [Real.norm_eq_abs,abs_of_nonneg (finiteDensityInfluence_nonneg ..)] - exact finiteDensityInfluence_le_one ..)) ht - simpa only [f,integral_domainBits,Q] using hd - - -theorem densityInfluence_finite_sum_bound [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) - (n : ℕ) (hn : 0 < n) (x : V) (p : unitInterval) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (F : Finset E) : - (p:ℝ) * ∑ e ∈ F, (∫ ω, densityInfluence G n x e ω ∂law p) ≤ - 5*Real.sqrt (d*n:ℕ) := by - let : Encodable E := Encodable.ofCountable E - let Q := fun j => F ∪ vertexExhaustion (V := E) j - have ht := (tendsto_const_nhds (x := (p:ℝ)) (f := atTop)).mul (tendsto_finsetSum F - (fun e _ => densityInfluence_integral_tendsto G hloc n x e p hfin F)) - apply le_of_tendsto ht - apply Eventually.of_forall - intro j - have hdeg (y : V) : ((Q j).filter fun e => y ∈ G e).card ≤ d := by - calc - _ = (((Q j).filter fun e => y ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm - _ ≤ {e | y ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc y) - _ ≤ d := hd y - have hs : (∑ e ∈ F, bernoulliPolynomial (Q j) (finiteDensityInfluence G n x e) p) ≤ - ∑ e ∈ Q j, bernoulliPolynomial (Q j) (finiteDensityInfluence G n x e) p := by - exact Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_left - (fun e _ _ => bernoulliPolynomial_nonneg (Q j) _ p p.2 (fun ω _ => finiteDensityInfluence_nonneg ..)) - exact (mul_le_mul_of_nonneg_left hs p.2.1).trans - (finiteDensityInfluence_sum_bound G (Q j) x p d n hn hdeg) - - -theorem densityInfluence_lintegral_sum_bound [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) - (n : ℕ) (hn : 0 < n) (x : V) (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) : - (∑' e, ∫⁻ ω, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p) ≤ - ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by - rw [ENNReal.tsum_eq_iSup_sum] - apply iSup_le - intro F - simp_rw [←ofReal_integral_eq_lintegral_ofReal (integrable_densityInfluence G hloc n x _ p) - (Eventually.of_forall (densityInfluence_nonneg G n x _))] - rw [←ENNReal.ofReal_sum_of_nonneg (fun e _ => integral_nonneg (densityInfluence_nonneg G n x e))] - apply ENNReal.ofReal_le_ofReal - apply (le_div_iff₀ hp).mpr - simpa only [mul_comm] using densityInfluence_finite_sum_bound G hloc d hd n hn x p hfin F - -end Percolation - - - - - -open MeasureTheory ProbabilityTheory Filter -open scoped ENNReal -namespace Percolation -universe u v -variable {V : Type u} {E : Type v} -attribute [local instance] Classical.propDecidable Classical.decEq - -noncomputable def boundaryDensityInfluence (G : BondGraph V E) (n : ℕ) - (ω : Set E) (y : V) : ℝ≥0∞ := - ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n y e ω) else 0 - -noncomputable def localDensityLoss (G : BondGraph V E) (n : ℕ) - (ω : Set E) (y : V) : ℝ≥0∞ := - (cluster G ω y).ncard * boundaryDensityInfluence G n ω y - -theorem measurable_boundaryDensityInfluence [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (n : ℕ) (y : V) : - Measurable (fun ω => boundaryDensityInfluence G n ω y) := by - apply Measurable.tsum - intro e - by_cases h : y ∈ G e - · simpa only [ite_eq_left h] using (measurable_densityInfluence G hloc n y e).ennreal_ofReal - · simp only [ite_eq_right h]; exact measurable_const - -theorem measurable_localDensityLoss [Countable E] (G : BondGraph V E) - (hloc : LocallyFinite G) (n : ℕ) (y : V) : - Measurable (fun ω => localDensityLoss G n ω y) := by - exact ((measurable_of_countable (fun k : ℕ => (k:ℝ≥0∞))).comp - (measurable_cluster_ncard G hloc y)).mul (measurable_boundaryDensityInfluence G hloc n y) - -theorem densityInfluence_eq_of_conn (G : BondGraph V E) (n : ℕ) (ω : Set E) - (x y : V) (hxy : Conn G ω x y) (e : E) : - densityInfluence G n x e ω = densityInfluence G n y e ω := by - unfold densityInfluence clusterDensity - rw [cluster_eq_of_conn G ω hxy, - cluster_eq_of_conn G (insert e ω) (conn_mono G (Set.subset_insert e ω) hxy)] - -theorem densityInfluence_aut (G : BondGraph V E) (n : ℕ) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) (e : E) : - densityInfluence G n x e (b ⁻¹' ω) = densityInfluence G n (a x) (b e) ω := by - have hins : insert e (b ⁻¹' ω) = b ⁻¹' (insert (b e) ω) := by - ext f - simp only [Set.mem_insert_iff,Set.mem_preimage,b.injective.eq_iff] - simp only [densityInfluence,Set.mem_preimage,clusterDensity,hins, - cluster_ncard_covariant G hab] - -theorem localDensityLoss_aut (G : BondGraph V E) (n : ℕ) {a : V ≃ V} {b : E ≃ E} - (hab : IsAut G a b) (ω : Set E) (x : V) : - localDensityLoss G n (b ⁻¹' ω) x = localDensityLoss G n ω (a x) := by - unfold localDensityLoss boundaryDensityInfluence - rw [cluster_ncard_covariant G hab,←b.tsum_eq (fun e => - if a x ∈ G e then ENNReal.ofReal (densityInfluence G n (a x) e ω) else 0)] - congr 1 - apply tsum_congr - intro e - have hm : a x ∈ G (b e) ↔ x ∈ G e := by - rw [hab e,Sym2.mem_map] - constructor - · rintro ⟨z,hz,hzx⟩ - exact a.injective hzx ▸ hz - · intro h; exact ⟨x,h,rfl⟩ - simp only [hm,densityInfluence_aut G n hab] - - -theorem tsum_bond_endpoints_le_two (G : BondGraph V E) (e : E) (c : ℝ≥0∞) : - (∑' y, if y ∈ G e then c else 0) ≤ 2*c := by - obtain ⟨a,b,he⟩ : ∃ a b, G e = s(a,b) := by - obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) - exact ⟨a,b,h.symm⟩ - calc - _ ≤ ∑' y, ((if y = a then c else 0)+(if y = b then c else 0)) := by - apply ENNReal.tsum_le_tsum - intro y - by_cases h : y ∈ G e - · rw [ite_eq_left h] - rw [he,Sym2.mem_iff] at h - rcases h with rfl | rfl <;> simp - · rw [ite_eq_right h]; exact zero_le - _ = 2*c := by rw [ENNReal.tsum_add]; simp; ring - - - -theorem clusterAveraged_localDensityLoss_le (G : BondGraph V E) (n : ℕ) - (ω : Set E) (x : V) (hx : (cluster G ω x).Finite) : - (∑' y, clusterAveragingKernel G ω x y * localDensityLoss G n ω y) ≤ - 2 * ∑' e, ENNReal.ofReal (densityInfluence G n x e ω) := by - have hf (y : V) : clusterAveragingKernel G ω x y * localDensityLoss G n ω y ≤ - ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := by - by_cases hxy : Conn G ω x y - · have hc := cluster_eq_of_conn G ω hxy - have hpos : ((cluster G ω x).ncard:ℝ≥0∞) ≠ 0 := by - exact_mod_cast (cluster_ncard_pos G ω x hx).ne' - unfold clusterAveragingKernel localDensityLoss - rw [ite_eq_left hxy,←hc,←mul_assoc,ENNReal.inv_mul_cancel hpos (ENNReal.natCast_ne_top _),one_mul] - unfold boundaryDensityInfluence - simp_rw [densityInfluence_eq_of_conn G n ω x y hxy] - exact le_rfl - · simp only [clusterAveragingKernel,ite_eq_right hxy,zero_mul]; exact zero_le - calc - _ ≤ ∑' y, ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := - ENNReal.tsum_le_tsum hf - _ = ∑' e, ∑' y, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := - ENNReal.tsum_comm - _ ≤ ∑' e, 2*ENNReal.ofReal (densityInfluence G n x e ω) := - ENNReal.tsum_le_tsum (fun e => tsum_bond_endpoints_le_two G e _) - _ = _ := ENNReal.tsum_mul_left - -theorem clusterAveraged_localDensityLoss_integral_bound [Countable V] [Countable E] - (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) - (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) - (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (x : V) : - (∫⁻ ω, ∑' y, clusterAveragingKernel G ω x y * localDensityLoss G n ω y ∂law p) ≤ - 2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by - calc - _ ≤ ∫⁻ ω, 2 * ∑' e, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p := by - apply lintegral_mono_ae - filter_upwards [hfin x] with ω hω - exact clusterAveraged_localDensityLoss_le G n ω x hω - _ = 2 * ∑' e, ∫⁻ ω, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p := by - rw [lintegral_const_mul _ (Measurable.tsum (fun e => - (measurable_densityInfluence G hloc n x e).ennreal_ofReal)),lintegral_tsum] - exact fun e => (measurable_densityInfluence G hloc n x e).ennreal_ofReal.aemeasurable - _ ≤ _ := mul_le_mul_right (densityInfluence_lintegral_sum_bound G hloc d hd n hn x p hp hfin) 2 - - -theorem weighted_localDensityLoss_bound [Countable V] [Countable E] - (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) - {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) - (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) - (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) - (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) - (p : unitInterval) (hp : 0 < (p:ℝ)) - (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) : - (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) ≤ - 2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by - rw [←root_cluster_average G hconn hloc root weight Γ hΓ htr hw p hfin - (localDensityLoss G n) (measurable_localDensityLoss G hloc n) - (fun a ha b hab ω x => localDensityLoss_aut G n hab ω x)] - calc - _ ≤ ∑ i, ENNReal.ofReal (weight i) * (2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ))) := - Finset.sum_le_sum fun i _ => mul_le_mul_right - (clusterAveraged_localDensityLoss_integral_bound G hloc d hd n hn p hp hfin (root i)) _ - _ = _ := by - rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1] - simp - -end Percolation - -end OAI +import Mathlib +import OAI.Probability.UnimodularPercolation.Clusters.LargeContacts +import OAI.Probability.UnimodularPercolation.TwoCluster.Score + +namespace OAI + +/-! Infinite-volume two-cluster limits and transport. -/ + +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal + +open MeasureTheory ProbabilityTheory Filter +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def clusterDensity (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : ℝ := + cappedDensity n (cluster G ω x).ncard + +noncomputable def densityInfluence (G : BondGraph V E) (n : ℕ) (x : V) + (e : E) (ω : Set E) : ℝ := + if e ∈ ω then 0 else clusterDensity G n x ω - clusterDensity G n x (insert e ω) + +theorem clusterDensity_nonneg (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : + 0 ≤ clusterDensity G n x ω := cappedDensity_nonneg .. + +theorem clusterDensity_le_one (G : BondGraph V E) (n : ℕ) (x : V) (ω : Set E) : + clusterDensity G n x ω ≤ 1 := cappedDensity_le_one .. + +theorem clusterDensity_antitone (G : BondGraph V E) (n : ℕ) (x : V) + {ω η : Set E} (h : ω ⊆ η) : clusterDensity G n x η ≤ clusterDensity G n x ω := by + by_cases hη : (cluster G η x).Finite + · have hω : (cluster G ω x).Finite := hη.subset (fun y hy => conn_mono G h hy) + exact cappedDensity_antitone n ((Set.ncard_pos hω).mpr ⟨x,mem_cluster_self G ω x⟩) + (Set.ncard_le_ncard (fun y hy => conn_mono G h hy) hη) + · rw [clusterDensity,Set.Infinite.ncard hη] + simpa [cappedDensity] using clusterDensity_nonneg G n x ω + +theorem densityInfluence_nonneg (G : BondGraph V E) (n : ℕ) (x : V) (e : E) (ω : Set E) : + 0 ≤ densityInfluence G n x e ω := by + unfold densityInfluence + split_ifs + · exact le_rfl + · exact sub_nonneg.mpr (clusterDensity_antitone G n x (Set.subset_insert e ω)) + +theorem densityInfluence_le_one (G : BondGraph V E) (n : ℕ) (x : V) (e : E) (ω : Set E) : + densityInfluence G n x e ω ≤ 1 := by + unfold densityInfluence + split_ifs + · norm_num + · exact (sub_le_self _ (clusterDensity_nonneg ..)).trans (clusterDensity_le_one ..) + +theorem measurable_clusterDensity (G : BondGraph V E) (hloc : LocallyFinite G) (n : ℕ) (x : V) : + Measurable (clusterDensity G n x) := + (measurable_of_countable (cappedDensity n)).comp (measurable_cluster_ncard G hloc x) + +theorem measurable_densityInfluence (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (x : V) (e : E) : Measurable (densityInfluence G n x e) := by + exact measurable_const.ite (measurableSet_mem e) + ((measurable_clusterDensity G hloc n x).sub + ((measurable_clusterDensity G hloc n x).comp (measurable_set_insert e))) + +theorem integrable_densityInfluence (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (x : V) (e : E) (p : unitInterval) : + Integrable (densityInfluence G n x e) (law p) := by + apply Integrable.mono' (integrable_const (1:ℝ)) (measurable_densityInfluence G hloc n x e).aestronglyMeasurable + exact Eventually.of_forall fun ω => by + rw [Real.norm_eq_abs,abs_of_nonneg (densityInfluence_nonneg ..)] + exact densityInfluence_le_one .. + +theorem cluster_insert_finite (G : BondGraph V E) (ω : Set E) (e : E) (x a b : V) + (he : G e = s(a,b)) (hx : (cluster G ω x).Finite) + (ha : (cluster G ω a).Finite) (hb : (cluster G ω b).Finite) : + (cluster G (insert e ω) x).Finite := by + apply (hx.union (ha.union hb)).subset + intro y hy + rcases (conn_insert_iff G ω e a b x y he).mp hy with hy | ⟨_,hy⟩ | ⟨_,hy⟩ + · exact Or.inl hy + · exact Or.inr (Or.inr hy) + · exact Or.inr (Or.inl hy) + +theorem cluster_insert_finite_ae (G : BondGraph V E) (p : unitInterval) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (x : V) (e : E) : + ∀ᵐ ω ∂law p, (cluster G (insert e ω) x).Finite := by + obtain ⟨a,b,he⟩ : ∃ a b, G e = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) + exact ⟨a,b,h.symm⟩ + filter_upwards [hfin x,hfin a,hfin b] with ω hx ha hb + exact cluster_insert_finite G ω e x a b he hx ha hb + +theorem finiteDensity_eq_clusterDensity (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (x : V) (ω : Set E) (hx : (cluster G ω x).Finite) + (Q : Finset E) (hQ : incidentSupport G hloc hx.toFinset ⊆ Q) : + finiteDensity G n x (domainBits Q ω) = clusterDensity G n x ω := by + have hc : cluster G (domainBits Q ω:Set E) x = cluster G ω x := by + rw [coe_domainBits] + have hh := (cluster_restrict_incident_eq_iff G hloc hx.toFinset Q hQ ω x).mpr + (Set.Finite.coe_toFinset hx).symm + simpa only [Set.Finite.coe_toFinset] using hh + unfold finiteDensity clusterDensity + rw [←Set.ncard_coe_finset,coe_finiteRootComponent,hc] + +theorem domainBits_insert (Q : Finset E) (e : E) (he : e ∈ Q) (ω : Set E) : + domainBits Q (insert e ω) = insert e (domainBits Q ω) := by + ext f + simp only [mem_domainBits,Set.mem_insert_iff,Finset.mem_insert] + aesop + +theorem densityInfluence_tendsto_finite [Encodable E] (G : BondGraph V E) (hloc : LocallyFinite G) + (n : ℕ) (x : V) (e : E) (ω : Set E) (hx : (cluster G ω x).Finite) + (he : (cluster G (insert e ω) x).Finite) (F : Finset E) : + Tendsto (fun j => finiteDensityInfluence G n x e + (domainBits (F ∪ vertexExhaustion (V := E) j) ω)) atTop + (nhds (densityInfluence G n x e ω)) := by + obtain ⟨jx,hjx⟩ := subset_vertexExhaustion (incidentSupport G hloc hx.toFinset) + obtain ⟨je,hje⟩ := subset_vertexExhaustion (incidentSupport G hloc he.toFinset) + obtain ⟨j₀,hj₀'⟩ := subset_vertexExhaustion ({e}:Finset E) + have hj₀ : e ∈ vertexExhaustion (V := E) j₀ := hj₀' (by simp) + have hev : (fun j => finiteDensityInfluence G n x e + (domainBits (F ∪ vertexExhaustion (V := E) j) ω)) =ᶠ[atTop] + (fun _ => densityInfluence G n x e ω) := by + filter_upwards [eventually_ge_atTop (max jx (max je j₀))] with j hj + let Q := F ∪ vertexExhaustion (V := E) j + have hxQ : incidentSupport G hloc hx.toFinset ⊆ Q := fun z hz => + Finset.mem_union_right _ (vertexExhaustion_mono (by omega) (hjx hz)) + have heQ : incidentSupport G hloc he.toFinset ⊆ Q := fun z hz => + Finset.mem_union_right _ (vertexExhaustion_mono (by omega) (hje hz)) + have heQ' : e ∈ Q := Finset.mem_union_right _ (vertexExhaustion_mono (by omega) hj₀) + change finiteDensityInfluence G n x e (domainBits Q ω) = _ + unfold finiteDensityInfluence densityInfluence + simp only [mem_domainBits,heQ',true_and] + split_ifs + · rfl + · rw [finiteDensity_eq_clusterDensity G hloc n x ω hx Q hxQ, + ←domainBits_insert Q e heQ' ω,finiteDensity_eq_clusterDensity G hloc n x (insert e ω) he Q heQ] + exact tendsto_const_nhds.congr' hev.symm + +theorem densityInfluence_integral_tendsto [Encodable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (n : ℕ) (x : V) (e : E) (p : unitInterval) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (F : Finset E) : + Tendsto (fun j => bernoulliPolynomial (F ∪ vertexExhaustion (V := E) j) + (finiteDensityInfluence G n x e) p) atTop + (nhds (∫ ω, densityInfluence G n x e ω ∂law p)) := by + let Q := fun j => F ∪ vertexExhaustion (V := E) j + let f := fun j ω => finiteDensityInfluence G n x e (domainBits (Q j) ω) + have hfi (j : ℕ) : Integrable (f j) (law p) := + integrable_finite_local (Q j) p (f j) (fun ω => by dsimp [f]; rw [domainBits_local]) + have ht : ∀ᵐ ω ∂law p, Tendsto (fun j => f j ω) atTop (nhds (densityInfluence G n x e ω)) := by + filter_upwards [hfin x,cluster_insert_finite_ae G p hfin x e] with ω hx he + exact densityInfluence_tendsto_finite G hloc n x e ω hx he F + have hd := tendsto_integral_of_dominated_convergence (fun _ : Set E => (1:ℝ)) + (fun j => (hfi j).aestronglyMeasurable) (integrable_const _) + (fun j => Eventually.of_forall (fun ω => by + rw [Real.norm_eq_abs,abs_of_nonneg (finiteDensityInfluence_nonneg ..)] + exact finiteDensityInfluence_le_one ..)) ht + simpa only [f,integral_domainBits,Q] using hd + + +theorem densityInfluence_finite_sum_bound [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) + (n : ℕ) (hn : 0 < n) (x : V) (p : unitInterval) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (F : Finset E) : + (p:ℝ) * ∑ e ∈ F, (∫ ω, densityInfluence G n x e ω ∂law p) ≤ + 5*Real.sqrt (d*n:ℕ) := by + let : Encodable E := Encodable.ofCountable E + let Q := fun j => F ∪ vertexExhaustion (V := E) j + have ht := (tendsto_const_nhds (x := (p:ℝ)) (f := atTop)).mul (tendsto_finsetSum F + (fun e _ => densityInfluence_integral_tendsto G hloc n x e p hfin F)) + apply le_of_tendsto ht + apply Eventually.of_forall + intro j + have hdeg (y : V) : ((Q j).filter fun e => y ∈ G e).card ≤ d := by + calc + _ = (((Q j).filter fun e => y ∈ G e):Set E).ncard := (Set.ncard_coe_finset _).symm + _ ≤ {e | y ∈ G e}.ncard := Set.ncard_le_ncard (fun e he => (Finset.mem_filter.mp he).2) (hloc y) + _ ≤ d := hd y + have hs : (∑ e ∈ F, bernoulliPolynomial (Q j) (finiteDensityInfluence G n x e) p) ≤ + ∑ e ∈ Q j, bernoulliPolynomial (Q j) (finiteDensityInfluence G n x e) p := by + exact Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_left + (fun e _ _ => bernoulliPolynomial_nonneg (Q j) _ p p.2 (fun ω _ => finiteDensityInfluence_nonneg ..)) + exact (mul_le_mul_of_nonneg_left hs p.2.1).trans + (finiteDensityInfluence_sum_bound G (Q j) x p d n hn hdeg) + + +theorem densityInfluence_lintegral_sum_bound [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) + (n : ℕ) (hn : 0 < n) (x : V) (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) : + (∑' e, ∫⁻ ω, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p) ≤ + ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by + rw [ENNReal.tsum_eq_iSup_sum] + apply iSup_le + intro F + simp_rw [←ofReal_integral_eq_lintegral_ofReal (integrable_densityInfluence G hloc n x _ p) + (Eventually.of_forall (densityInfluence_nonneg G n x _))] + rw [←ENNReal.ofReal_sum_of_nonneg (fun e _ => integral_nonneg (densityInfluence_nonneg G n x e))] + apply ENNReal.ofReal_le_ofReal + apply (le_div_iff₀ hp).mpr + simpa only [mul_comm] using densityInfluence_finite_sum_bound G hloc d hd n hn x p hfin F + +end Percolation + + + + + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal +namespace Percolation +universe u v +variable {V : Type u} {E : Type v} +attribute [local instance] Classical.propDecidable Classical.decEq + +noncomputable def boundaryDensityInfluence (G : BondGraph V E) (n : ℕ) + (ω : Set E) (y : V) : ℝ≥0∞ := + ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n y e ω) else 0 + +noncomputable def localDensityLoss (G : BondGraph V E) (n : ℕ) + (ω : Set E) (y : V) : ℝ≥0∞ := + (cluster G ω y).ncard * boundaryDensityInfluence G n ω y + +theorem measurable_boundaryDensityInfluence [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (n : ℕ) (y : V) : + Measurable (fun ω => boundaryDensityInfluence G n ω y) := by + apply Measurable.tsum + intro e + by_cases h : y ∈ G e + · simpa only [ite_eq_left h] using (measurable_densityInfluence G hloc n y e).ennreal_ofReal + · simp only [ite_eq_right h]; exact measurable_const + +theorem measurable_localDensityLoss [Countable E] (G : BondGraph V E) + (hloc : LocallyFinite G) (n : ℕ) (y : V) : + Measurable (fun ω => localDensityLoss G n ω y) := by + exact ((measurable_of_countable (fun k : ℕ => (k:ℝ≥0∞))).comp + (measurable_cluster_ncard G hloc y)).mul (measurable_boundaryDensityInfluence G hloc n y) + +theorem densityInfluence_eq_of_conn (G : BondGraph V E) (n : ℕ) (ω : Set E) + (x y : V) (hxy : Conn G ω x y) (e : E) : + densityInfluence G n x e ω = densityInfluence G n y e ω := by + unfold densityInfluence clusterDensity + rw [cluster_eq_of_conn G ω hxy, + cluster_eq_of_conn G (insert e ω) (conn_mono G (Set.subset_insert e ω) hxy)] + +theorem densityInfluence_aut (G : BondGraph V E) (n : ℕ) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) (e : E) : + densityInfluence G n x e (b ⁻¹' ω) = densityInfluence G n (a x) (b e) ω := by + have hins : insert e (b ⁻¹' ω) = b ⁻¹' (insert (b e) ω) := by + ext f + simp only [Set.mem_insert_iff,Set.mem_preimage,b.injective.eq_iff] + simp only [densityInfluence,Set.mem_preimage,clusterDensity,hins, + cluster_ncard_covariant G hab] + +theorem localDensityLoss_aut (G : BondGraph V E) (n : ℕ) {a : V ≃ V} {b : E ≃ E} + (hab : IsAut G a b) (ω : Set E) (x : V) : + localDensityLoss G n (b ⁻¹' ω) x = localDensityLoss G n ω (a x) := by + unfold localDensityLoss boundaryDensityInfluence + rw [cluster_ncard_covariant G hab,←b.tsum_eq (fun e => + if a x ∈ G e then ENNReal.ofReal (densityInfluence G n (a x) e ω) else 0)] + congr 1 + apply tsum_congr + intro e + have hm : a x ∈ G (b e) ↔ x ∈ G e := by + rw [hab e,Sym2.mem_map] + constructor + · rintro ⟨z,hz,hzx⟩ + exact a.injective hzx ▸ hz + · intro h; exact ⟨x,h,rfl⟩ + simp only [hm,densityInfluence_aut G n hab] + + +theorem tsum_bond_endpoints_le_two (G : BondGraph V E) (e : E) (c : ℝ≥0∞) : + (∑' y, if y ∈ G e then c else 0) ≤ 2*c := by + obtain ⟨a,b,he⟩ : ∃ a b, G e = s(a,b) := by + obtain ⟨⟨a,b⟩,h⟩ := Quot.exists_rep (G e) + exact ⟨a,b,h.symm⟩ + calc + _ ≤ ∑' y, ((if y = a then c else 0)+(if y = b then c else 0)) := by + apply ENNReal.tsum_le_tsum + intro y + by_cases h : y ∈ G e + · rw [ite_eq_left h] + rw [he,Sym2.mem_iff] at h + rcases h with rfl | rfl <;> simp + · rw [ite_eq_right h]; exact zero_le + _ = 2*c := by rw [ENNReal.tsum_add]; simp; ring + + + +theorem clusterAveraged_localDensityLoss_le (G : BondGraph V E) (n : ℕ) + (ω : Set E) (x : V) (hx : (cluster G ω x).Finite) : + (∑' y, clusterAveragingKernel G ω x y * localDensityLoss G n ω y) ≤ + 2 * ∑' e, ENNReal.ofReal (densityInfluence G n x e ω) := by + have hf (y : V) : clusterAveragingKernel G ω x y * localDensityLoss G n ω y ≤ + ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := by + by_cases hxy : Conn G ω x y + · have hc := cluster_eq_of_conn G ω hxy + have hpos : ((cluster G ω x).ncard:ℝ≥0∞) ≠ 0 := by + exact_mod_cast (cluster_ncard_pos G ω x hx).ne' + unfold clusterAveragingKernel localDensityLoss + rw [ite_eq_left hxy,←hc,←mul_assoc,ENNReal.inv_mul_cancel hpos (ENNReal.natCast_ne_top _),one_mul] + unfold boundaryDensityInfluence + simp_rw [densityInfluence_eq_of_conn G n ω x y hxy] + exact le_rfl + · simp only [clusterAveragingKernel,ite_eq_right hxy,zero_mul]; exact zero_le + calc + _ ≤ ∑' y, ∑' e, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := + ENNReal.tsum_le_tsum hf + _ = ∑' e, ∑' y, if y ∈ G e then ENNReal.ofReal (densityInfluence G n x e ω) else 0 := + ENNReal.tsum_comm + _ ≤ ∑' e, 2*ENNReal.ofReal (densityInfluence G n x e ω) := + ENNReal.tsum_le_tsum (fun e => tsum_bond_endpoints_le_two G e _) + _ = _ := ENNReal.tsum_mul_left + +theorem clusterAveraged_localDensityLoss_integral_bound [Countable V] [Countable E] + (G : BondGraph V E) (hloc : LocallyFinite G) (d : ℕ) + (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) + (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) (x : V) : + (∫⁻ ω, ∑' y, clusterAveragingKernel G ω x y * localDensityLoss G n ω y ∂law p) ≤ + 2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by + calc + _ ≤ ∫⁻ ω, 2 * ∑' e, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p := by + apply lintegral_mono_ae + filter_upwards [hfin x] with ω hω + exact clusterAveraged_localDensityLoss_le G n ω x hω + _ = 2 * ∑' e, ∫⁻ ω, ENNReal.ofReal (densityInfluence G n x e ω) ∂law p := by + rw [lintegral_const_mul _ (Measurable.tsum (fun e => + (measurable_densityInfluence G hloc n x e).ennreal_ofReal)),lintegral_tsum] + exact fun e => (measurable_densityInfluence G hloc n x e).ennreal_ofReal.aemeasurable + _ ≤ _ := mul_le_mul_right (densityInfluence_lintegral_sum_bound G hloc d hd n hn x p hp hfin) 2 + + +theorem weighted_localDensityLoss_bound [Countable V] [Countable E] + (G : BondGraph V E) (hconn : Connected G) (hloc : LocallyFinite G) + {ι : Type*} [Fintype ι] (root : ι → V) (weight : ι → ℝ) + (Γ : Set (V ≃ V)) (hΓ : Γ ⊆ vertexAut G) (htr : RootTransport root weight Γ) + (hw : ∀ i, 0 ≤ weight i) (hw1 : ∑ i, weight i = 1) + (d : ℕ) (hd : ∀ y, {e | y ∈ G e}.ncard ≤ d) (n : ℕ) (hn : 0 < n) + (p : unitInterval) (hp : 0 < (p:ℝ)) + (hfin : ∀ y, ∀ᵐ ω ∂law p, (cluster G ω y).Finite) : + (∑ i, ENNReal.ofReal (weight i) * ∫⁻ ω, localDensityLoss G n ω (root i) ∂law p) ≤ + 2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ)) := by + rw [←root_cluster_average G hconn hloc root weight Γ hΓ htr hw p hfin + (localDensityLoss G n) (measurable_localDensityLoss G hloc n) + (fun a ha b hab ω x => localDensityLoss_aut G n hab ω x)] + calc + _ ≤ ∑ i, ENNReal.ofReal (weight i) * (2 * ENNReal.ofReal (5*Real.sqrt (d*n:ℕ)/(p:ℝ))) := + Finset.sum_le_sum fun i _ => mul_le_mul_right + (clusterAveraged_localDensityLoss_integral_bound G hloc d hd n hn p hp hfin (root i)) _ + _ = _ := by + rw [←Finset.sum_mul,←ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1] + simp + +end Percolation + +end OAI diff --git a/lean/OAI/Probability/UnimodularPercolation/UnimodularMain.lean b/lean/OAI/Probability/UnimodularPercolation/UnimodularMain.lean index a9d8170afe5ad281031a241dfd2d9b351fdbc6cf..47ba1946bd06b925c89c27d93524330063b8d248 100644 --- a/lean/OAI/Probability/UnimodularPercolation/UnimodularMain.lean +++ b/lean/OAI/Probability/UnimodularPercolation/UnimodularMain.lean @@ -1 +1 @@ -import OAI.Probability.UnimodularPercolation.Criticality.UnimodularMain +import OAI.Probability.UnimodularPercolation.Criticality.UnimodularMain diff --git a/lean/OAI/Probability/Voronoi/CardyFormula.lean b/lean/OAI/Probability/Voronoi/CardyFormula.lean index 22974dabb6449bbf46a5e888b19ca286593a6b6c..19178be1487c36a0c186d2a37a698e4f463791f3 100644 --- a/lean/OAI/Probability/Voronoi/CardyFormula.lean +++ b/lean/OAI/Probability/Voronoi/CardyFormula.lean @@ -1,530 +1,530 @@ -import Mathlib - -namespace OAI - -/-! Cardy integrals and hypergeometric formulas with Poisson-Voronoi crossing definitions. -/ - -noncomputable section - -open Set Filter MeasureTheory ProbabilityTheory -open scoped Topology NNReal ENNReal - -namespace Cardy - -def PositivelyOriented (D : Set ℂ) (γ : ℝ → ℂ) : Prop := - ∃ p ∈ D, ∃ H : ℝ × ℝ → ℂ, - ContinuousOn H (Icc 0 1 ×ˢ Icc 0 1) ∧ - (∀ t ∈ Icc (0 : ℝ) 1, H (0, t) = γ t) ∧ - (∀ t ∈ Icc (0 : ℝ) 1, - H (1, t) = p + Complex.exp ((2 * Real.pi * t : ℝ) * Complex.I)) ∧ - (∀ s ∈ Icc (0 : ℝ) 1, H (s, 0) = H (s, 1)) ∧ - (∀ s ∈ Icc (0 : ℝ) 1, ∀ t ∈ Icc (0 : ℝ) 1, H (s, t) ≠ p) - -structure JordanQuadrilateral where - domain : Set ℂ - domain_open : IsOpen domain - domain_connected : IsConnected domain - domain_bounded : Bornology.IsBounded domain - boundary : ℝ → ℂ - boundary_continuous : ContinuousOn boundary (Icc 0 1) - boundary_closed : boundary 0 = boundary 1 - boundary_injective : InjOn boundary (Ico 0 1) - boundary_image : boundary '' Icc 0 1 = frontier domain - boundary_positive : PositivelyOriented domain boundary - tb : ℝ - tc : ℝ - td : ℝ - zero_lt_tb : 0 < tb - tb_lt_tc : tb < tc - tc_lt_td : tc < td - td_lt_one : td < 1 - -namespace JordanQuadrilateral - -def a (Q : JordanQuadrilateral) : ℂ := Q.boundary 0 - -def b (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.tb - -def c (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.tc - -def d (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.td - -def arcAB (Q : JordanQuadrilateral) : Set ℂ := Q.boundary '' Icc 0 Q.tb - -def arcCD (Q : JordanQuadrilateral) : Set ℂ := Q.boundary '' Icc Q.tc Q.td - -end JordanQuadrilateral - -def upperHalfPlane : Set ℂ := {z | 0 < z.im} - -def IsConformalParameter (Q : JordanQuadrilateral) (x : ℝ) : Prop := - x ∈ Ioo 0 1 ∧ ∃ f g : ℂ → ℂ, - DifferentiableOn ℂ f Q.domain ∧ - DifferentiableOn ℂ g upperHalfPlane ∧ - MapsTo f Q.domain upperHalfPlane ∧ - MapsTo g upperHalfPlane Q.domain ∧ - (∀ z ∈ Q.domain, g (f z) = z) ∧ - (∀ w ∈ upperHalfPlane, f (g w) = w) ∧ - Tendsto f (𝓝[Q.domain] Q.a) (𝓝 0) ∧ - Tendsto f (𝓝[Q.domain] Q.b) (𝓝 (x : ℂ)) ∧ - Tendsto f (𝓝[Q.domain] Q.c) (𝓝 1) ∧ - Tendsto (fun z => ‖f z‖) (𝓝[Q.domain] Q.d) atTop - -abbrev Box := ℤ × ℤ -abbrev Slot := Box × ℕ -abbrev GeometrySample := (Box → ℕ) × (Slot → ℝ × ℝ) -abbrev Sample := GeometrySample × (Slot → Bool) - -def unitUniform : Measure ℝ := volume.restrict (Ico 0 1) - -instance : IsProbabilityMeasure unitUniform := by - constructor - simp [unitUniform] - -def fairColor : Measure Bool := (PMF.uniformOfFintype Bool).toMeasure - -instance : IsProbabilityMeasure fairColor := by - unfold fairColor - infer_instance - -def rate (ε : ℝ) : ℝ≥0 := Real.toNNReal ((ε⁻¹) ^ 2) - -def countLaw (ε : ℝ) : Measure (Box → ℕ) := - Measure.infinitePi (fun _ => poissonMeasure (rate ε)) - -def locationLaw : Measure (Slot → ℝ × ℝ) := - Measure.infinitePi (fun _ => unitUniform.prod unitUniform) - -def colorLaw : Measure (Slot → Bool) := - Measure.infinitePi (fun _ => fairColor) - -instance (ε : ℝ) : IsProbabilityMeasure (countLaw ε) := by - unfold countLaw - infer_instance - -instance : IsProbabilityMeasure locationLaw := by - unfold locationLaw - infer_instance - -instance : IsProbabilityMeasure colorLaw := by - unfold colorLaw - infer_instance - -def geometryLaw (ε : ℝ) : Measure GeometrySample := (countLaw ε).prod locationLaw - -instance (ε : ℝ) : IsProbabilityMeasure (geometryLaw ε) := by - unfold geometryLaw - infer_instance - -def sampleLaw (ε : ℝ) : Measure Sample := (geometryLaw ε).prod colorLaw - -instance (ε : ℝ) : IsProbabilityMeasure (sampleLaw ε) := by - unfold sampleLaw - infer_instance - -def Active (ω : Sample) (i : Slot) : Prop := i.2 < ω.1.1 i.1 - -def position (ω : Sample) (i : Slot) : ℂ := - (((i.1.1 : ℝ) + (ω.1.2 i).1 : ℝ) : ℂ) + - (((i.1.2 : ℝ) + (ω.1.2 i).2 : ℝ) : ℂ) * Complex.I - -def sites (ω : Sample) : Set ℂ := {v | ∃ i, Active ω i ∧ position ω i = v} - -def blackSites (ω : Sample) : Set ℂ := - {v | ∃ i, Active ω i ∧ ω.2 i = true ∧ position ω i = v} - -def voronoiCell (η : Set ℂ) (v : ℂ) : Set ℂ := - {z | ∀ u ∈ η, dist z v ≤ dist z u} - -def blackRegion (ω : Sample) : Set ℂ := - ⋃ v ∈ blackSites ω, voronoiCell (sites ω) v - -def Crosses (Q : JordanQuadrilateral) (B : Set ℂ) : Prop := - ∃ K : Set ℂ, IsConnected K ∧ K ⊆ B ∩ closure Q.domain ∧ - (K ∩ Q.arcAB).Nonempty ∧ (K ∩ Q.arcCD).Nonempty - -def crossingEvent (Q : JordanQuadrilateral) : Set Sample := - {ω | Crosses Q (blackRegion ω)} - -def crossingProbability (ε : ℝ) (Q : JordanQuadrilateral) : ℝ := - (sampleLaw ε (crossingEvent Q)).toReal - -def cardyWeight (u : ℝ) : ℝ := (u * (1 - u)) ^ (-(2 : ℝ) / 3) - -def cardyIntegral (x : ℝ) : ℝ := - (∫ u in 0..x, cardyWeight u) / (∫ u in 0..1, cardyWeight u) - -def cardyHypergeometric (x : ℝ) : ℝ := - (Real.Gamma (2 / 3) * x ^ ((1 : ℝ) / 3)) / - (Real.Gamma (1 / 3) * Real.Gamma (4 / 3)) * - ordinaryHypergeometric (1 / 3 : ℝ) (2 / 3) (4 / 3) x - -namespace JordanQuadrilateral - -lemma boundary_ne_of_lt (Q : JordanQuadrilateral) {s t : ℝ} - (hs : 0 ≤ s) (hst : s < t) (ht : t < 1) : Q.boundary s ≠ Q.boundary t := by - intro heq - exact hst.ne (Q.boundary_injective ⟨hs, hst.trans ht⟩ ⟨hs.trans hst.le, ht⟩ heq) - -theorem marks_distinct (Q : JordanQuadrilateral) : - Q.a ≠ Q.b ∧ Q.a ≠ Q.c ∧ Q.a ≠ Q.d ∧ Q.b ≠ Q.c ∧ Q.b ≠ Q.d ∧ Q.c ≠ Q.d := by - have h0b := Q.zero_lt_tb - have hbc := Q.tb_lt_tc - have hcd := Q.tc_lt_td - have hd1 := Q.td_lt_one - exact ⟨Q.boundary_ne_of_lt le_rfl h0b (by linarith), - Q.boundary_ne_of_lt le_rfl (by linarith) (by linarith), - Q.boundary_ne_of_lt le_rfl (by linarith) hd1, - Q.boundary_ne_of_lt h0b.le hbc (by linarith), - Q.boundary_ne_of_lt h0b.le (by linarith) hd1, - Q.boundary_ne_of_lt (by linarith) hcd hd1⟩ - -theorem arcAB_subset_frontier (Q : JordanQuadrilateral) : Q.arcAB ⊆ frontier Q.domain := by - rw [← Q.boundary_image] - apply image_mono - exact Icc_subset_Icc le_rfl (Q.tb_lt_tc.trans (Q.tc_lt_td.trans Q.td_lt_one)).le - -theorem arcCD_subset_frontier (Q : JordanQuadrilateral) : Q.arcCD ⊆ frontier Q.domain := by - rw [← Q.boundary_image] - apply image_mono - exact Icc_subset_Icc (Q.zero_lt_tb.trans Q.tb_lt_tc).le Q.td_lt_one.le - -theorem endpoints_mem_arcs (Q : JordanQuadrilateral) : - Q.a ∈ Q.arcAB ∧ Q.b ∈ Q.arcAB ∧ Q.c ∈ Q.arcCD ∧ Q.d ∈ Q.arcCD := by - exact ⟨mem_image_of_mem _ ⟨le_rfl, Q.zero_lt_tb.le⟩, - mem_image_of_mem _ ⟨Q.zero_lt_tb.le, le_rfl⟩, - mem_image_of_mem _ ⟨le_rfl, Q.tc_lt_td.le⟩, - mem_image_of_mem _ ⟨Q.tc_lt_td.le, le_rfl⟩⟩ - -end JordanQuadrilateral - -theorem voronoiCell_closed (η : Set ℂ) (v : ℂ) : IsClosed (voronoiCell η v) := by - have h : voronoiCell η v = ⋂ u ∈ η, {z : ℂ | dist z v ≤ dist z u} := by - ext z - simp [voronoiCell] - rw [h] - exact isClosed_biInter fun u _ => isClosed_le (by fun_prop) (by fun_prop) - -theorem site_mem_voronoiCell (η : Set ℂ) (v : ℂ) : v ∈ voronoiCell η v := by - intro u _ - simp - -theorem blackSites_subset_sites (ω : Sample) : blackSites ω ⊆ sites ω := by - rintro v ⟨i, hi, _, hv⟩ - exact ⟨i, hi, hv⟩ - -theorem blackSites_subset_blackRegion (ω : Sample) : blackSites ω ⊆ blackRegion ω := by - intro v hv - exact mem_iUnion₂.mpr ⟨v, hv, site_mem_voronoiCell _ _⟩ - -theorem crosses_mono {Q : JordanQuadrilateral} {B B' : Set ℂ} - (hBB' : B ⊆ B') (h : Crosses Q B) : Crosses Q B' := by - rcases h with ⟨K, hK, hKB, ha, hc⟩ - exact ⟨K, hK, fun z hz => ⟨hBB' (hKB hz).1, (hKB hz).2⟩, ha, hc⟩ - -theorem crossingProbability_nonneg (ε : ℝ) (Q : JordanQuadrilateral) : - 0 ≤ crossingProbability ε Q := ENNReal.toReal_nonneg - -theorem crossingProbability_le_one (ε : ℝ) (Q : JordanQuadrilateral) : - crossingProbability ε Q ≤ 1 := by - exact measureReal_le_one - -theorem countLaw_marginal (ε : ℝ) (j : Box) : - (countLaw ε).map (fun N => N j) = poissonMeasure (rate ε) := by - exact Measure.infinitePi_map_eval _ j - -theorem colorLaw_marginal (i : Slot) : - colorLaw.map (fun χ => χ i) = fairColor := by - exact Measure.infinitePi_map_eval _ i - -theorem rate_coe (ε : ℝ) : (rate ε : ℝ) = (ε⁻¹) ^ 2 := by - exact Real.coe_toNNReal _ (sq_nonneg _) - -theorem geometry_colors_independent (ε : ℝ) : - IndepFun (fun ω : Sample => ω.1) (fun ω : Sample => ω.2) (sampleLaw ε) := by - exact indepFun_prod (X := id) (Y := id) measurable_id measurable_id - -theorem sampleLaw_color_marginal (ε : ℝ) : - (sampleLaw ε).map (fun ω : Sample => ω.2) = colorLaw := by - exact measurePreserving_snd.map_eq - -theorem sampleLaw_geometry_marginal (ε : ℝ) : - (sampleLaw ε).map (fun ω : Sample => ω.1) = geometryLaw ε := by - exact measurePreserving_fst.map_eq - -theorem counts_independent (ε : ℝ) : - iIndepFun (fun j : Box => fun N : Box → ℕ => N j) (countLaw ε) := by - exact iIndepFun_infinitePi (fun _ => measurable_id) - -theorem colors_independent : - iIndepFun (fun i : Slot => fun χ : Slot → Bool => χ i) colorLaw := by - exact iIndepFun_infinitePi (fun _ => measurable_id) - -theorem fairColor_singleton (b : Bool) : fairColor {b} = (1 / 2 : ℝ≥0∞) := by - rw [fairColor, PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _), - PMF.uniformOfFintype_apply] - norm_num - -theorem colorLaw_singleton (i : Slot) (b : Bool) : - colorLaw {χ | χ i = b} = (1 / 2 : ℝ≥0∞) := by - rw [← fairColor_singleton b, ← colorLaw_marginal i] - exact (Measure.map_apply (by fun_prop) (measurableSet_singleton b)).symm - -lemma cardyWeight_complex {u : ℝ} (hu : u ∈ Icc 0 1) : - (cardyWeight u : ℂ) = - (u : ℂ) ^ ((1 / 3 : ℂ) - 1) * (1 - (u : ℂ)) ^ ((1 / 3 : ℂ) - 1) := by - have h₁ : (1 / 3 : ℂ) - 1 = ((-(2 : ℝ) / 3 : ℝ) : ℂ) := by - push_cast - ring - rw [cardyWeight, Real.mul_rpow hu.1 (sub_nonneg.mpr hu.2), - Complex.ofReal_mul, Complex.ofReal_cpow hu.1, - Complex.ofReal_cpow (sub_nonneg.mpr hu.2), h₁] - push_cast - rfl - -theorem cardyDenominator_eq_beta : - ((∫ u in 0..1, cardyWeight u : ℝ) : ℂ) = - Complex.betaIntegral (1 / 3) (1 / 3) := by - rw [Complex.betaIntegral, ← intervalIntegral.integral_ofReal] - apply intervalIntegral.integral_congr - intro u hu - exact cardyWeight_complex (by simpa only [uIcc_of_le zero_le_one] using hu) - -theorem cardyDenominator_eq_gamma : - (∫ u in 0..1, cardyWeight u) = - Real.Gamma (1 / 3) ^ 2 / Real.Gamma (2 / 3) := by - apply Complex.ofReal_injective - rw [cardyDenominator_eq_beta, - Complex.betaIntegral_eq_Gamma_mul_div _ _ (by norm_num) (by norm_num)] - have h : (1 / 3 : ℂ) + 1 / 3 = 2 / 3 := by norm_num - rw [h] - rw [show (1 / 3 : ℂ) = ((1 / 3 : ℝ) : ℂ) by norm_num, - show (2 / 3 : ℂ) = ((2 / 3 : ℝ) : ℂ) by norm_num, - Complex.Gamma_ofReal, Complex.Gamma_ofReal] - push_cast - ring - -theorem cardyDenominator_pos : 0 < ∫ u in 0..1, cardyWeight u := by - rw [cardyDenominator_eq_gamma] - exact div_pos (pow_pos (Real.Gamma_pos_of_pos (by norm_num)) _) - (Real.Gamma_pos_of_pos (by norm_num)) - -@[simp] theorem cardyIntegral_zero : cardyIntegral 0 = 0 := by - simp [cardyIntegral] - -@[simp] theorem cardyIntegral_one : cardyIntegral 1 = 1 := by - exact div_self (ne_of_gt cardyDenominator_pos) - -theorem cardyWeight_integrable : IntervalIntegrable cardyWeight volume 0 1 := by - have h := Complex.betaIntegral_convergent - (u := (1 / 3 : ℂ)) (v := (1 / 3 : ℂ)) (by norm_num) (by norm_num) - have h' : IntervalIntegrable (fun u : ℝ => - ((u : ℂ) ^ ((1 / 3 : ℂ) - 1) * - (1 - (u : ℂ)) ^ ((1 / 3 : ℂ) - 1)).re) volume 0 1 := ⟨h.1.re, h.2.re⟩ - refine IntervalIntegrable.congr ?_ h' - intro u hu - have hu' : u ∈ Icc (0 : ℝ) 1 := by - exact Ioc_subset_Icc_self (by simpa only [uIoc_of_le zero_le_one] using hu) - simpa only [Complex.ofReal_re] using congrArg Complex.re (cardyWeight_complex hu').symm - -theorem cardyWeight_integrable_subinterval {s t : ℝ} (hs : 0 ≤ s) - (ht : t ≤ 1) (hst : s ≤ t) : IntervalIntegrable cardyWeight volume s t := by - apply cardyWeight_integrable.mono_set - rw [uIcc_of_le hst, uIcc_of_le zero_le_one] - exact Icc_subset_Icc hs ht - -theorem cardyWeight_nonneg {u : ℝ} (hu : u ∈ Icc 0 1) : 0 ≤ cardyWeight u := by - exact Real.rpow_nonneg (mul_nonneg hu.1 (sub_nonneg.mpr hu.2)) _ - -theorem cardyWeight_pos {u : ℝ} (hu : u ∈ Ioo 0 1) : 0 < cardyWeight u := by - exact Real.rpow_pos_of_pos (mul_pos hu.1 (sub_pos.mpr hu.2)) _ - -lemma cardyWeight_symm (u : ℝ) : cardyWeight (1 - u) = cardyWeight u := by - unfold cardyWeight - congr 1 - ring - -theorem cardyIntegral_continuousOn : ContinuousOn cardyIntegral (Icc 0 1) := by - have h := intervalIntegral.continuousOn_primitive_interval - ((intervalIntegrable_iff' (by finiteness)).mp cardyWeight_integrable) - rw [uIcc_of_le zero_le_one] at h - exact h.div_const _ - -theorem cardyIntegral_strictMonoOn : StrictMonoOn cardyIntegral (Icc 0 1) := by - intro a ha b hb hab - have h0a := cardyWeight_integrable_subinterval (s := 0) le_rfl ha.2 ha.1 - have habi := cardyWeight_integrable_subinterval ha.1 hb.2 hab.le - have hp : 0 < ∫ u in a..b, cardyWeight u := by - apply intervalIntegral.intervalIntegral_pos_of_pos_on habi _ hab - intro u hu - exact cardyWeight_pos ⟨ha.1.trans_lt hu.1, hu.2.trans_le hb.2⟩ - have hadd := intervalIntegral.integral_add_adjacent_intervals h0a habi - apply (div_lt_div_iff_of_pos_right cardyDenominator_pos).mpr - linarith - -theorem cardyIntegral_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 1) : - cardyIntegral x ∈ Icc 0 1 := by - have h := cardyIntegral_strictMonoOn.monotoneOn - constructor - · simpa using h (show (0 : ℝ) ∈ Icc 0 1 by simp) hx hx.1 - · simpa using h hx (show (1 : ℝ) ∈ Icc 0 1 by simp) hx.2 - -theorem cardyIntegral_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 1) : - cardyIntegral x ∈ Ioo 0 1 := by - constructor - · simpa using cardyIntegral_strictMonoOn (show (0 : ℝ) ∈ Icc 0 1 by simp) - ⟨hx.1.le, hx.2.le⟩ hx.1 - · simpa using cardyIntegral_strictMonoOn ⟨hx.1.le, hx.2.le⟩ - (show (1 : ℝ) ∈ Icc 0 1 by simp) hx.2 - -theorem cardyIntegral_reflection {x : ℝ} (hx : x ∈ Icc 0 1) : - cardyIntegral (1 - x) = 1 - cardyIntegral x := by - have hx' : 1 - x ∈ Icc (0 : ℝ) 1 := ⟨by linarith [hx.2], by linarith [hx.1]⟩ - have h0 := cardyWeight_integrable_subinterval (s := 0) le_rfl hx'.2 hx'.1 - have h1 := cardyWeight_integrable_subinterval hx'.1 le_rfl hx'.2 - have hsub : (∫ u in 0..x, cardyWeight u) = ∫ u in (1 - x)..1, cardyWeight u := by - simpa only [cardyWeight_symm, sub_zero] using - intervalIntegral.integral_comp_sub_left (a := 0) (b := x) cardyWeight 1 - apply (eq_sub_iff_add_eq).mpr - unfold cardyIntegral - rw [← add_div, hsub, intervalIntegral.integral_add_adjacent_intervals h0 h1] - exact div_self (ne_of_gt cardyDenominator_pos) - -@[simp] theorem cardyIntegral_half : cardyIntegral (1 / 2) = 1 / 2 := by - have h := cardyIntegral_reflection (x := 1 / 2) (by norm_num) - norm_num only [show (1 : ℝ) - 1 / 2 = 1 / 2 by norm_num] at h - linarith - -def cardyBinomialCoefficient (n : ℕ) : ℝ := - (n.factorial : ℝ)⁻¹ * (ascPochhammer ℝ n).eval (2 / 3) - -lemma cardyBinomialCoefficient_pos (n : ℕ) : 0 < cardyBinomialCoefficient n := by - exact mul_pos (inv_pos.mpr (by positivity)) (ascPochhammer_pos n _ (by norm_num)) - -lemma cardyBinomialCoefficient_eq_choose (n : ℕ) : - cardyBinomialCoefficient n = Ring.choose ((2 / 3 : ℝ) + n - 1) n := by - rw [← Ring.multichoose_eq] - have h := Ring.factorial_nsmul_multichoose_eq_ascPochhammer (2 / 3 : ℝ) n - rw [nsmul_eq_mul, Polynomial.ascPochhammer_smeval_eq_eval] at h - rw [cardyBinomialCoefficient, ← h, ← mul_assoc, inv_mul_cancel₀, one_mul] - exact_mod_cast n.factorial_ne_zero - -lemma cardy_binomial_hasSum {u : ℝ} (hu : u ∈ Ioo 0 1) : - HasSum (fun n : ℕ => cardyBinomialCoefficient n * u ^ n) - ((1 - u) ^ (-(2 : ℝ) / 3)) := by - have h := (Real.one_div_one_sub_rpow_hasFPowerSeriesOnBall_zero (2 / 3)).hasSum - (y := u) (by - rw [← ENNReal.ofReal_one, Metric.eball_ofReal] - simpa [Real.dist_eq, abs_of_pos hu.1] using hu.2) - simpa only [FormalMultilinearSeries.ofScalars_apply_eq, smul_eq_mul, - ← cardyBinomialCoefficient_eq_choose, zero_add, one_div, neg_div, - Real.rpow_neg (sub_pos.mpr hu.2).le] - using h - -lemma cardyWeight_hasSum {u : ℝ} (hu : u ∈ Ioo 0 1) : - HasSum (fun n : ℕ => cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) - (cardyWeight u) := by - have h := (cardy_binomial_hasSum hu).mul_left (u ^ (-(2 : ℝ) / 3)) - have heq (n : ℕ) : cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3) = - u ^ (-(2 : ℝ) / 3) * (cardyBinomialCoefficient n * u ^ n) := by - rw [show (n : ℝ) - 2 / 3 = -(2 : ℝ) / 3 + n by ring, - Real.rpow_add hu.1, Real.rpow_natCast] - ring - simpa only [heq, cardyWeight, Real.mul_rpow hu.1.le (sub_pos.mpr hu.2).le] using h - -theorem cardyNumerator_hasSum {x : ℝ} (hx : x ∈ Ioo 0 1) : - HasSum (fun n : ℕ => ∫ u in 0..x, - cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) - (∫ u in 0..x, cardyWeight u) := by - let S : ℕ → ℝ → ℝ := fun n u => - cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3) - have hpoint {u : ℝ} (hu : u ∈ uIoc 0 x) : HasSum (fun n => S n u) (cardyWeight u) := by - rw [uIoc_of_le hx.1.le] at hu - exact cardyWeight_hasSum ⟨hu.1, hu.2.trans_lt hx.2⟩ - have hi (n : ℕ) : IntervalIntegrable (S n) volume 0 x := by - exact (intervalIntegral.intervalIntegrable_rpow' - (r := (n : ℝ) - 2 / 3) (by linarith [Nat.cast_nonneg (α := ℝ) n])).const_mul _ - have htotal : IntervalIntegrable (fun u => ∑' n, S n u) volume 0 x := by - apply IntervalIntegrable.congr (fun u hu => (hpoint hu).tsum_eq.symm) - exact cardyWeight_integrable_subinterval le_rfl hx.2.le hx.1.le - apply intervalIntegral.hasSum_integral_of_dominated_convergence S - (fun n => ((intervalIntegrable_iff).mp (hi n)).1) ?_ ?_ htotal ?_ - · intro n - refine Filter.Eventually.of_forall fun u hu => ?_ - rw [uIoc_of_le hx.1.le] at hu - have hpos : 0 ≤ S n u := - mul_nonneg (cardyBinomialCoefficient_pos n).le (Real.rpow_nonneg hu.1.le _) - exact (Real.norm_of_nonneg hpos).le - · exact Filter.Eventually.of_forall fun u hu => (hpoint hu).summable - · exact Filter.Eventually.of_forall fun u hu => hpoint hu - -lemma cardyBinomialTerm_integral (x : ℝ) (n : ℕ) : - (∫ u in 0..x, cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) = - cardyBinomialCoefficient n * x ^ ((n : ℝ) + 1 / 3) / ((n : ℝ) + 1 / 3) := by - rw [intervalIntegral.integral_const_mul, integral_rpow - (Or.inl (by linarith [Nat.cast_nonneg (α := ℝ) n]))] - rw [show (n : ℝ) - 2 / 3 + 1 = (n : ℝ) + 1 / 3 by ring, - Real.zero_rpow (by linarith [Nat.cast_nonneg (α := ℝ) n]), sub_zero] - ring - -lemma cardyHypergeometricCoefficient_eq (n : ℕ) : - cardyBinomialCoefficient n / ((n : ℝ) + 1 / 3) = - 3 * ordinaryHypergeometricCoefficient (1 / 3 : ℝ) (2 / 3) (4 / 3) n := by - have hc : (ascPochhammer ℝ n).eval (4 / 3) ≠ 0 := - ne_of_gt (ascPochhammer_pos n _ (by norm_num)) - have hn : (n : ℝ) + 1 / 3 ≠ 0 := by linarith [Nat.cast_nonneg (α := ℝ) n] - have hshift : (ascPochhammer ℝ n).eval (1 / 3) * ((1 / 3 : ℝ) + n) = - (1 / 3 : ℝ) * (ascPochhammer ℝ n).eval (4 / 3) := by - rw [← ascPochhammer_succ_eval, ascPochhammer_succ_left] - simp only [Polynomial.eval_mul, Polynomial.eval_X, Polynomial.eval_comp, - Polynomial.eval_add, Polynomial.eval_one] - norm_num - have hratio : ((ascPochhammer ℝ n).eval (1 / 3) / - (ascPochhammer ℝ n).eval (4 / 3)) * ((n : ℝ) + 1 / 3) = 1 / 3 := by - calc - _ = ((ascPochhammer ℝ n).eval (1 / 3) * ((1 / 3 : ℝ) + n)) / - (ascPochhammer ℝ n).eval (4 / 3) := by ring - _ = ((1 / 3 : ℝ) * (ascPochhammer ℝ n).eval (4 / 3)) / - (ascPochhammer ℝ n).eval (4 / 3) := by rw [hshift] - _ = 1 / 3 := mul_div_cancel_right₀ _ hc - symm - apply (eq_div_iff hn).mpr - calc - _ = (3 * (((ascPochhammer ℝ n).eval (1 / 3) / - (ascPochhammer ℝ n).eval (4 / 3)) * ((n : ℝ) + 1 / 3))) * - cardyBinomialCoefficient n := by - unfold ordinaryHypergeometricCoefficient cardyBinomialCoefficient - ring - _ = cardyBinomialCoefficient n := by rw [hratio]; ring - -theorem cardyNumerator_eq_hypergeometric {x : ℝ} (hx : x ∈ Ioo 0 1) : - (∫ u in 0..x, cardyWeight u) = - 3 * x ^ ((1 : ℝ) / 3) * - ordinaryHypergeometric (1 / 3 : ℝ) (2 / 3) (4 / 3) x := by - rw [← (cardyNumerator_hasSum hx).tsum_eq, ordinaryHypergeometric_eq_tsum] - simp only [smul_eq_mul] - rw [← tsum_mul_left] - apply tsum_congr - intro n - rw [cardyBinomialTerm_integral, Real.rpow_add hx.1, Real.rpow_natCast] - calc - _ = (cardyBinomialCoefficient n / ((n : ℝ) + 1 / 3)) * - (x ^ n * x ^ ((1 : ℝ) / 3)) := by ring - _ = _ := by rw [cardyHypergeometricCoefficient_eq]; ring - -theorem cardyIntegral_eq_hypergeometric {x : ℝ} (hx : x ∈ Ioo 0 1) : - cardyIntegral x = cardyHypergeometric x := by - have hγ : Real.Gamma (4 / 3) = (1 / 3 : ℝ) * Real.Gamma (1 / 3) := by - convert Real.Gamma_add_one (s := 1 / 3) (by norm_num) using 1 - norm_num - have h₁ : Real.Gamma (1 / 3) ≠ 0 := ne_of_gt (Real.Gamma_pos_of_pos (by norm_num)) - have h₂ : Real.Gamma (2 / 3) ≠ 0 := ne_of_gt (Real.Gamma_pos_of_pos (by norm_num)) - rw [cardyIntegral, cardyNumerator_eq_hypergeometric hx, - cardyDenominator_eq_gamma, cardyHypergeometric, hγ] - field_simp - -end Cardy - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Cardy integrals and hypergeometric formulas with Poisson-Voronoi crossing definitions. -/ + +noncomputable section + +open Set Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +namespace Cardy + +def PositivelyOriented (D : Set ℂ) (γ : ℝ → ℂ) : Prop := + ∃ p ∈ D, ∃ H : ℝ × ℝ → ℂ, + ContinuousOn H (Icc 0 1 ×ˢ Icc 0 1) ∧ + (∀ t ∈ Icc (0 : ℝ) 1, H (0, t) = γ t) ∧ + (∀ t ∈ Icc (0 : ℝ) 1, + H (1, t) = p + Complex.exp ((2 * Real.pi * t : ℝ) * Complex.I)) ∧ + (∀ s ∈ Icc (0 : ℝ) 1, H (s, 0) = H (s, 1)) ∧ + (∀ s ∈ Icc (0 : ℝ) 1, ∀ t ∈ Icc (0 : ℝ) 1, H (s, t) ≠ p) + +structure JordanQuadrilateral where + domain : Set ℂ + domain_open : IsOpen domain + domain_connected : IsConnected domain + domain_bounded : Bornology.IsBounded domain + boundary : ℝ → ℂ + boundary_continuous : ContinuousOn boundary (Icc 0 1) + boundary_closed : boundary 0 = boundary 1 + boundary_injective : InjOn boundary (Ico 0 1) + boundary_image : boundary '' Icc 0 1 = frontier domain + boundary_positive : PositivelyOriented domain boundary + tb : ℝ + tc : ℝ + td : ℝ + zero_lt_tb : 0 < tb + tb_lt_tc : tb < tc + tc_lt_td : tc < td + td_lt_one : td < 1 + +namespace JordanQuadrilateral + +def a (Q : JordanQuadrilateral) : ℂ := Q.boundary 0 + +def b (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.tb + +def c (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.tc + +def d (Q : JordanQuadrilateral) : ℂ := Q.boundary Q.td + +def arcAB (Q : JordanQuadrilateral) : Set ℂ := Q.boundary '' Icc 0 Q.tb + +def arcCD (Q : JordanQuadrilateral) : Set ℂ := Q.boundary '' Icc Q.tc Q.td + +end JordanQuadrilateral + +def upperHalfPlane : Set ℂ := {z | 0 < z.im} + +def IsConformalParameter (Q : JordanQuadrilateral) (x : ℝ) : Prop := + x ∈ Ioo 0 1 ∧ ∃ f g : ℂ → ℂ, + DifferentiableOn ℂ f Q.domain ∧ + DifferentiableOn ℂ g upperHalfPlane ∧ + MapsTo f Q.domain upperHalfPlane ∧ + MapsTo g upperHalfPlane Q.domain ∧ + (∀ z ∈ Q.domain, g (f z) = z) ∧ + (∀ w ∈ upperHalfPlane, f (g w) = w) ∧ + Tendsto f (𝓝[Q.domain] Q.a) (𝓝 0) ∧ + Tendsto f (𝓝[Q.domain] Q.b) (𝓝 (x : ℂ)) ∧ + Tendsto f (𝓝[Q.domain] Q.c) (𝓝 1) ∧ + Tendsto (fun z => ‖f z‖) (𝓝[Q.domain] Q.d) atTop + +abbrev Box := ℤ × ℤ +abbrev Slot := Box × ℕ +abbrev GeometrySample := (Box → ℕ) × (Slot → ℝ × ℝ) +abbrev Sample := GeometrySample × (Slot → Bool) + +def unitUniform : Measure ℝ := volume.restrict (Ico 0 1) + +instance : IsProbabilityMeasure unitUniform := by + constructor + simp [unitUniform] + +def fairColor : Measure Bool := (PMF.uniformOfFintype Bool).toMeasure + +instance : IsProbabilityMeasure fairColor := by + unfold fairColor + infer_instance + +def rate (ε : ℝ) : ℝ≥0 := Real.toNNReal ((ε⁻¹) ^ 2) + +def countLaw (ε : ℝ) : Measure (Box → ℕ) := + Measure.infinitePi (fun _ => poissonMeasure (rate ε)) + +def locationLaw : Measure (Slot → ℝ × ℝ) := + Measure.infinitePi (fun _ => unitUniform.prod unitUniform) + +def colorLaw : Measure (Slot → Bool) := + Measure.infinitePi (fun _ => fairColor) + +instance (ε : ℝ) : IsProbabilityMeasure (countLaw ε) := by + unfold countLaw + infer_instance + +instance : IsProbabilityMeasure locationLaw := by + unfold locationLaw + infer_instance + +instance : IsProbabilityMeasure colorLaw := by + unfold colorLaw + infer_instance + +def geometryLaw (ε : ℝ) : Measure GeometrySample := (countLaw ε).prod locationLaw + +instance (ε : ℝ) : IsProbabilityMeasure (geometryLaw ε) := by + unfold geometryLaw + infer_instance + +def sampleLaw (ε : ℝ) : Measure Sample := (geometryLaw ε).prod colorLaw + +instance (ε : ℝ) : IsProbabilityMeasure (sampleLaw ε) := by + unfold sampleLaw + infer_instance + +def Active (ω : Sample) (i : Slot) : Prop := i.2 < ω.1.1 i.1 + +def position (ω : Sample) (i : Slot) : ℂ := + (((i.1.1 : ℝ) + (ω.1.2 i).1 : ℝ) : ℂ) + + (((i.1.2 : ℝ) + (ω.1.2 i).2 : ℝ) : ℂ) * Complex.I + +def sites (ω : Sample) : Set ℂ := {v | ∃ i, Active ω i ∧ position ω i = v} + +def blackSites (ω : Sample) : Set ℂ := + {v | ∃ i, Active ω i ∧ ω.2 i = true ∧ position ω i = v} + +def voronoiCell (η : Set ℂ) (v : ℂ) : Set ℂ := + {z | ∀ u ∈ η, dist z v ≤ dist z u} + +def blackRegion (ω : Sample) : Set ℂ := + ⋃ v ∈ blackSites ω, voronoiCell (sites ω) v + +def Crosses (Q : JordanQuadrilateral) (B : Set ℂ) : Prop := + ∃ K : Set ℂ, IsConnected K ∧ K ⊆ B ∩ closure Q.domain ∧ + (K ∩ Q.arcAB).Nonempty ∧ (K ∩ Q.arcCD).Nonempty + +def crossingEvent (Q : JordanQuadrilateral) : Set Sample := + {ω | Crosses Q (blackRegion ω)} + +def crossingProbability (ε : ℝ) (Q : JordanQuadrilateral) : ℝ := + (sampleLaw ε (crossingEvent Q)).toReal + +def cardyWeight (u : ℝ) : ℝ := (u * (1 - u)) ^ (-(2 : ℝ) / 3) + +def cardyIntegral (x : ℝ) : ℝ := + (∫ u in 0..x, cardyWeight u) / (∫ u in 0..1, cardyWeight u) + +def cardyHypergeometric (x : ℝ) : ℝ := + (Real.Gamma (2 / 3) * x ^ ((1 : ℝ) / 3)) / + (Real.Gamma (1 / 3) * Real.Gamma (4 / 3)) * + ordinaryHypergeometric (1 / 3 : ℝ) (2 / 3) (4 / 3) x + +namespace JordanQuadrilateral + +lemma boundary_ne_of_lt (Q : JordanQuadrilateral) {s t : ℝ} + (hs : 0 ≤ s) (hst : s < t) (ht : t < 1) : Q.boundary s ≠ Q.boundary t := by + intro heq + exact hst.ne (Q.boundary_injective ⟨hs, hst.trans ht⟩ ⟨hs.trans hst.le, ht⟩ heq) + +theorem marks_distinct (Q : JordanQuadrilateral) : + Q.a ≠ Q.b ∧ Q.a ≠ Q.c ∧ Q.a ≠ Q.d ∧ Q.b ≠ Q.c ∧ Q.b ≠ Q.d ∧ Q.c ≠ Q.d := by + have h0b := Q.zero_lt_tb + have hbc := Q.tb_lt_tc + have hcd := Q.tc_lt_td + have hd1 := Q.td_lt_one + exact ⟨Q.boundary_ne_of_lt le_rfl h0b (by linarith), + Q.boundary_ne_of_lt le_rfl (by linarith) (by linarith), + Q.boundary_ne_of_lt le_rfl (by linarith) hd1, + Q.boundary_ne_of_lt h0b.le hbc (by linarith), + Q.boundary_ne_of_lt h0b.le (by linarith) hd1, + Q.boundary_ne_of_lt (by linarith) hcd hd1⟩ + +theorem arcAB_subset_frontier (Q : JordanQuadrilateral) : Q.arcAB ⊆ frontier Q.domain := by + rw [← Q.boundary_image] + apply image_mono + exact Icc_subset_Icc le_rfl (Q.tb_lt_tc.trans (Q.tc_lt_td.trans Q.td_lt_one)).le + +theorem arcCD_subset_frontier (Q : JordanQuadrilateral) : Q.arcCD ⊆ frontier Q.domain := by + rw [← Q.boundary_image] + apply image_mono + exact Icc_subset_Icc (Q.zero_lt_tb.trans Q.tb_lt_tc).le Q.td_lt_one.le + +theorem endpoints_mem_arcs (Q : JordanQuadrilateral) : + Q.a ∈ Q.arcAB ∧ Q.b ∈ Q.arcAB ∧ Q.c ∈ Q.arcCD ∧ Q.d ∈ Q.arcCD := by + exact ⟨mem_image_of_mem _ ⟨le_rfl, Q.zero_lt_tb.le⟩, + mem_image_of_mem _ ⟨Q.zero_lt_tb.le, le_rfl⟩, + mem_image_of_mem _ ⟨le_rfl, Q.tc_lt_td.le⟩, + mem_image_of_mem _ ⟨Q.tc_lt_td.le, le_rfl⟩⟩ + +end JordanQuadrilateral + +theorem voronoiCell_closed (η : Set ℂ) (v : ℂ) : IsClosed (voronoiCell η v) := by + have h : voronoiCell η v = ⋂ u ∈ η, {z : ℂ | dist z v ≤ dist z u} := by + ext z + simp [voronoiCell] + rw [h] + exact isClosed_biInter fun u _ => isClosed_le (by fun_prop) (by fun_prop) + +theorem site_mem_voronoiCell (η : Set ℂ) (v : ℂ) : v ∈ voronoiCell η v := by + intro u _ + simp + +theorem blackSites_subset_sites (ω : Sample) : blackSites ω ⊆ sites ω := by + rintro v ⟨i, hi, _, hv⟩ + exact ⟨i, hi, hv⟩ + +theorem blackSites_subset_blackRegion (ω : Sample) : blackSites ω ⊆ blackRegion ω := by + intro v hv + exact mem_iUnion₂.mpr ⟨v, hv, site_mem_voronoiCell _ _⟩ + +theorem crosses_mono {Q : JordanQuadrilateral} {B B' : Set ℂ} + (hBB' : B ⊆ B') (h : Crosses Q B) : Crosses Q B' := by + rcases h with ⟨K, hK, hKB, ha, hc⟩ + exact ⟨K, hK, fun z hz => ⟨hBB' (hKB hz).1, (hKB hz).2⟩, ha, hc⟩ + +theorem crossingProbability_nonneg (ε : ℝ) (Q : JordanQuadrilateral) : + 0 ≤ crossingProbability ε Q := ENNReal.toReal_nonneg + +theorem crossingProbability_le_one (ε : ℝ) (Q : JordanQuadrilateral) : + crossingProbability ε Q ≤ 1 := by + exact measureReal_le_one + +theorem countLaw_marginal (ε : ℝ) (j : Box) : + (countLaw ε).map (fun N => N j) = poissonMeasure (rate ε) := by + exact Measure.infinitePi_map_eval _ j + +theorem colorLaw_marginal (i : Slot) : + colorLaw.map (fun χ => χ i) = fairColor := by + exact Measure.infinitePi_map_eval _ i + +theorem rate_coe (ε : ℝ) : (rate ε : ℝ) = (ε⁻¹) ^ 2 := by + exact Real.coe_toNNReal _ (sq_nonneg _) + +theorem geometry_colors_independent (ε : ℝ) : + IndepFun (fun ω : Sample => ω.1) (fun ω : Sample => ω.2) (sampleLaw ε) := by + exact indepFun_prod (X := id) (Y := id) measurable_id measurable_id + +theorem sampleLaw_color_marginal (ε : ℝ) : + (sampleLaw ε).map (fun ω : Sample => ω.2) = colorLaw := by + exact measurePreserving_snd.map_eq + +theorem sampleLaw_geometry_marginal (ε : ℝ) : + (sampleLaw ε).map (fun ω : Sample => ω.1) = geometryLaw ε := by + exact measurePreserving_fst.map_eq + +theorem counts_independent (ε : ℝ) : + iIndepFun (fun j : Box => fun N : Box → ℕ => N j) (countLaw ε) := by + exact iIndepFun_infinitePi (fun _ => measurable_id) + +theorem colors_independent : + iIndepFun (fun i : Slot => fun χ : Slot → Bool => χ i) colorLaw := by + exact iIndepFun_infinitePi (fun _ => measurable_id) + +theorem fairColor_singleton (b : Bool) : fairColor {b} = (1 / 2 : ℝ≥0∞) := by + rw [fairColor, PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _), + PMF.uniformOfFintype_apply] + norm_num + +theorem colorLaw_singleton (i : Slot) (b : Bool) : + colorLaw {χ | χ i = b} = (1 / 2 : ℝ≥0∞) := by + rw [← fairColor_singleton b, ← colorLaw_marginal i] + exact (Measure.map_apply (by fun_prop) (measurableSet_singleton b)).symm + +lemma cardyWeight_complex {u : ℝ} (hu : u ∈ Icc 0 1) : + (cardyWeight u : ℂ) = + (u : ℂ) ^ ((1 / 3 : ℂ) - 1) * (1 - (u : ℂ)) ^ ((1 / 3 : ℂ) - 1) := by + have h₁ : (1 / 3 : ℂ) - 1 = ((-(2 : ℝ) / 3 : ℝ) : ℂ) := by + push_cast + ring + rw [cardyWeight, Real.mul_rpow hu.1 (sub_nonneg.mpr hu.2), + Complex.ofReal_mul, Complex.ofReal_cpow hu.1, + Complex.ofReal_cpow (sub_nonneg.mpr hu.2), h₁] + push_cast + rfl + +theorem cardyDenominator_eq_beta : + ((∫ u in 0..1, cardyWeight u : ℝ) : ℂ) = + Complex.betaIntegral (1 / 3) (1 / 3) := by + rw [Complex.betaIntegral, ← intervalIntegral.integral_ofReal] + apply intervalIntegral.integral_congr + intro u hu + exact cardyWeight_complex (by simpa only [uIcc_of_le zero_le_one] using hu) + +theorem cardyDenominator_eq_gamma : + (∫ u in 0..1, cardyWeight u) = + Real.Gamma (1 / 3) ^ 2 / Real.Gamma (2 / 3) := by + apply Complex.ofReal_injective + rw [cardyDenominator_eq_beta, + Complex.betaIntegral_eq_Gamma_mul_div _ _ (by norm_num) (by norm_num)] + have h : (1 / 3 : ℂ) + 1 / 3 = 2 / 3 := by norm_num + rw [h] + rw [show (1 / 3 : ℂ) = ((1 / 3 : ℝ) : ℂ) by norm_num, + show (2 / 3 : ℂ) = ((2 / 3 : ℝ) : ℂ) by norm_num, + Complex.Gamma_ofReal, Complex.Gamma_ofReal] + push_cast + ring + +theorem cardyDenominator_pos : 0 < ∫ u in 0..1, cardyWeight u := by + rw [cardyDenominator_eq_gamma] + exact div_pos (pow_pos (Real.Gamma_pos_of_pos (by norm_num)) _) + (Real.Gamma_pos_of_pos (by norm_num)) + +@[simp] theorem cardyIntegral_zero : cardyIntegral 0 = 0 := by + simp [cardyIntegral] + +@[simp] theorem cardyIntegral_one : cardyIntegral 1 = 1 := by + exact div_self (ne_of_gt cardyDenominator_pos) + +theorem cardyWeight_integrable : IntervalIntegrable cardyWeight volume 0 1 := by + have h := Complex.betaIntegral_convergent + (u := (1 / 3 : ℂ)) (v := (1 / 3 : ℂ)) (by norm_num) (by norm_num) + have h' : IntervalIntegrable (fun u : ℝ => + ((u : ℂ) ^ ((1 / 3 : ℂ) - 1) * + (1 - (u : ℂ)) ^ ((1 / 3 : ℂ) - 1)).re) volume 0 1 := ⟨h.1.re, h.2.re⟩ + refine IntervalIntegrable.congr ?_ h' + intro u hu + have hu' : u ∈ Icc (0 : ℝ) 1 := by + exact Ioc_subset_Icc_self (by simpa only [uIoc_of_le zero_le_one] using hu) + simpa only [Complex.ofReal_re] using congrArg Complex.re (cardyWeight_complex hu').symm + +theorem cardyWeight_integrable_subinterval {s t : ℝ} (hs : 0 ≤ s) + (ht : t ≤ 1) (hst : s ≤ t) : IntervalIntegrable cardyWeight volume s t := by + apply cardyWeight_integrable.mono_set + rw [uIcc_of_le hst, uIcc_of_le zero_le_one] + exact Icc_subset_Icc hs ht + +theorem cardyWeight_nonneg {u : ℝ} (hu : u ∈ Icc 0 1) : 0 ≤ cardyWeight u := by + exact Real.rpow_nonneg (mul_nonneg hu.1 (sub_nonneg.mpr hu.2)) _ + +theorem cardyWeight_pos {u : ℝ} (hu : u ∈ Ioo 0 1) : 0 < cardyWeight u := by + exact Real.rpow_pos_of_pos (mul_pos hu.1 (sub_pos.mpr hu.2)) _ + +lemma cardyWeight_symm (u : ℝ) : cardyWeight (1 - u) = cardyWeight u := by + unfold cardyWeight + congr 1 + ring + +theorem cardyIntegral_continuousOn : ContinuousOn cardyIntegral (Icc 0 1) := by + have h := intervalIntegral.continuousOn_primitive_interval + ((intervalIntegrable_iff' (by finiteness)).mp cardyWeight_integrable) + rw [uIcc_of_le zero_le_one] at h + exact h.div_const _ + +theorem cardyIntegral_strictMonoOn : StrictMonoOn cardyIntegral (Icc 0 1) := by + intro a ha b hb hab + have h0a := cardyWeight_integrable_subinterval (s := 0) le_rfl ha.2 ha.1 + have habi := cardyWeight_integrable_subinterval ha.1 hb.2 hab.le + have hp : 0 < ∫ u in a..b, cardyWeight u := by + apply intervalIntegral.intervalIntegral_pos_of_pos_on habi _ hab + intro u hu + exact cardyWeight_pos ⟨ha.1.trans_lt hu.1, hu.2.trans_le hb.2⟩ + have hadd := intervalIntegral.integral_add_adjacent_intervals h0a habi + apply (div_lt_div_iff_of_pos_right cardyDenominator_pos).mpr + linarith + +theorem cardyIntegral_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 1) : + cardyIntegral x ∈ Icc 0 1 := by + have h := cardyIntegral_strictMonoOn.monotoneOn + constructor + · simpa using h (show (0 : ℝ) ∈ Icc 0 1 by simp) hx hx.1 + · simpa using h hx (show (1 : ℝ) ∈ Icc 0 1 by simp) hx.2 + +theorem cardyIntegral_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 1) : + cardyIntegral x ∈ Ioo 0 1 := by + constructor + · simpa using cardyIntegral_strictMonoOn (show (0 : ℝ) ∈ Icc 0 1 by simp) + ⟨hx.1.le, hx.2.le⟩ hx.1 + · simpa using cardyIntegral_strictMonoOn ⟨hx.1.le, hx.2.le⟩ + (show (1 : ℝ) ∈ Icc 0 1 by simp) hx.2 + +theorem cardyIntegral_reflection {x : ℝ} (hx : x ∈ Icc 0 1) : + cardyIntegral (1 - x) = 1 - cardyIntegral x := by + have hx' : 1 - x ∈ Icc (0 : ℝ) 1 := ⟨by linarith [hx.2], by linarith [hx.1]⟩ + have h0 := cardyWeight_integrable_subinterval (s := 0) le_rfl hx'.2 hx'.1 + have h1 := cardyWeight_integrable_subinterval hx'.1 le_rfl hx'.2 + have hsub : (∫ u in 0..x, cardyWeight u) = ∫ u in (1 - x)..1, cardyWeight u := by + simpa only [cardyWeight_symm, sub_zero] using + intervalIntegral.integral_comp_sub_left (a := 0) (b := x) cardyWeight 1 + apply (eq_sub_iff_add_eq).mpr + unfold cardyIntegral + rw [← add_div, hsub, intervalIntegral.integral_add_adjacent_intervals h0 h1] + exact div_self (ne_of_gt cardyDenominator_pos) + +@[simp] theorem cardyIntegral_half : cardyIntegral (1 / 2) = 1 / 2 := by + have h := cardyIntegral_reflection (x := 1 / 2) (by norm_num) + norm_num only [show (1 : ℝ) - 1 / 2 = 1 / 2 by norm_num] at h + linarith + +def cardyBinomialCoefficient (n : ℕ) : ℝ := + (n.factorial : ℝ)⁻¹ * (ascPochhammer ℝ n).eval (2 / 3) + +lemma cardyBinomialCoefficient_pos (n : ℕ) : 0 < cardyBinomialCoefficient n := by + exact mul_pos (inv_pos.mpr (by positivity)) (ascPochhammer_pos n _ (by norm_num)) + +lemma cardyBinomialCoefficient_eq_choose (n : ℕ) : + cardyBinomialCoefficient n = Ring.choose ((2 / 3 : ℝ) + n - 1) n := by + rw [← Ring.multichoose_eq] + have h := Ring.factorial_nsmul_multichoose_eq_ascPochhammer (2 / 3 : ℝ) n + rw [nsmul_eq_mul, Polynomial.ascPochhammer_smeval_eq_eval] at h + rw [cardyBinomialCoefficient, ← h, ← mul_assoc, inv_mul_cancel₀, one_mul] + exact_mod_cast n.factorial_ne_zero + +lemma cardy_binomial_hasSum {u : ℝ} (hu : u ∈ Ioo 0 1) : + HasSum (fun n : ℕ => cardyBinomialCoefficient n * u ^ n) + ((1 - u) ^ (-(2 : ℝ) / 3)) := by + have h := (Real.one_div_one_sub_rpow_hasFPowerSeriesOnBall_zero (2 / 3)).hasSum + (y := u) (by + rw [← ENNReal.ofReal_one, Metric.eball_ofReal] + simpa [Real.dist_eq, abs_of_pos hu.1] using hu.2) + simpa only [FormalMultilinearSeries.ofScalars_apply_eq, smul_eq_mul, + ← cardyBinomialCoefficient_eq_choose, zero_add, one_div, neg_div, + Real.rpow_neg (sub_pos.mpr hu.2).le] + using h + +lemma cardyWeight_hasSum {u : ℝ} (hu : u ∈ Ioo 0 1) : + HasSum (fun n : ℕ => cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) + (cardyWeight u) := by + have h := (cardy_binomial_hasSum hu).mul_left (u ^ (-(2 : ℝ) / 3)) + have heq (n : ℕ) : cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3) = + u ^ (-(2 : ℝ) / 3) * (cardyBinomialCoefficient n * u ^ n) := by + rw [show (n : ℝ) - 2 / 3 = -(2 : ℝ) / 3 + n by ring, + Real.rpow_add hu.1, Real.rpow_natCast] + ring + simpa only [heq, cardyWeight, Real.mul_rpow hu.1.le (sub_pos.mpr hu.2).le] using h + +theorem cardyNumerator_hasSum {x : ℝ} (hx : x ∈ Ioo 0 1) : + HasSum (fun n : ℕ => ∫ u in 0..x, + cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) + (∫ u in 0..x, cardyWeight u) := by + let S : ℕ → ℝ → ℝ := fun n u => + cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3) + have hpoint {u : ℝ} (hu : u ∈ uIoc 0 x) : HasSum (fun n => S n u) (cardyWeight u) := by + rw [uIoc_of_le hx.1.le] at hu + exact cardyWeight_hasSum ⟨hu.1, hu.2.trans_lt hx.2⟩ + have hi (n : ℕ) : IntervalIntegrable (S n) volume 0 x := by + exact (intervalIntegral.intervalIntegrable_rpow' + (r := (n : ℝ) - 2 / 3) (by linarith [Nat.cast_nonneg (α := ℝ) n])).const_mul _ + have htotal : IntervalIntegrable (fun u => ∑' n, S n u) volume 0 x := by + apply IntervalIntegrable.congr (fun u hu => (hpoint hu).tsum_eq.symm) + exact cardyWeight_integrable_subinterval le_rfl hx.2.le hx.1.le + apply intervalIntegral.hasSum_integral_of_dominated_convergence S + (fun n => ((intervalIntegrable_iff).mp (hi n)).1) ?_ ?_ htotal ?_ + · intro n + refine Filter.Eventually.of_forall fun u hu => ?_ + rw [uIoc_of_le hx.1.le] at hu + have hpos : 0 ≤ S n u := + mul_nonneg (cardyBinomialCoefficient_pos n).le (Real.rpow_nonneg hu.1.le _) + exact (Real.norm_of_nonneg hpos).le + · exact Filter.Eventually.of_forall fun u hu => (hpoint hu).summable + · exact Filter.Eventually.of_forall fun u hu => hpoint hu + +lemma cardyBinomialTerm_integral (x : ℝ) (n : ℕ) : + (∫ u in 0..x, cardyBinomialCoefficient n * u ^ ((n : ℝ) - 2 / 3)) = + cardyBinomialCoefficient n * x ^ ((n : ℝ) + 1 / 3) / ((n : ℝ) + 1 / 3) := by + rw [intervalIntegral.integral_const_mul, integral_rpow + (Or.inl (by linarith [Nat.cast_nonneg (α := ℝ) n]))] + rw [show (n : ℝ) - 2 / 3 + 1 = (n : ℝ) + 1 / 3 by ring, + Real.zero_rpow (by linarith [Nat.cast_nonneg (α := ℝ) n]), sub_zero] + ring + +lemma cardyHypergeometricCoefficient_eq (n : ℕ) : + cardyBinomialCoefficient n / ((n : ℝ) + 1 / 3) = + 3 * ordinaryHypergeometricCoefficient (1 / 3 : ℝ) (2 / 3) (4 / 3) n := by + have hc : (ascPochhammer ℝ n).eval (4 / 3) ≠ 0 := + ne_of_gt (ascPochhammer_pos n _ (by norm_num)) + have hn : (n : ℝ) + 1 / 3 ≠ 0 := by linarith [Nat.cast_nonneg (α := ℝ) n] + have hshift : (ascPochhammer ℝ n).eval (1 / 3) * ((1 / 3 : ℝ) + n) = + (1 / 3 : ℝ) * (ascPochhammer ℝ n).eval (4 / 3) := by + rw [← ascPochhammer_succ_eval, ascPochhammer_succ_left] + simp only [Polynomial.eval_mul, Polynomial.eval_X, Polynomial.eval_comp, + Polynomial.eval_add, Polynomial.eval_one] + norm_num + have hratio : ((ascPochhammer ℝ n).eval (1 / 3) / + (ascPochhammer ℝ n).eval (4 / 3)) * ((n : ℝ) + 1 / 3) = 1 / 3 := by + calc + _ = ((ascPochhammer ℝ n).eval (1 / 3) * ((1 / 3 : ℝ) + n)) / + (ascPochhammer ℝ n).eval (4 / 3) := by ring + _ = ((1 / 3 : ℝ) * (ascPochhammer ℝ n).eval (4 / 3)) / + (ascPochhammer ℝ n).eval (4 / 3) := by rw [hshift] + _ = 1 / 3 := mul_div_cancel_right₀ _ hc + symm + apply (eq_div_iff hn).mpr + calc + _ = (3 * (((ascPochhammer ℝ n).eval (1 / 3) / + (ascPochhammer ℝ n).eval (4 / 3)) * ((n : ℝ) + 1 / 3))) * + cardyBinomialCoefficient n := by + unfold ordinaryHypergeometricCoefficient cardyBinomialCoefficient + ring + _ = cardyBinomialCoefficient n := by rw [hratio]; ring + +theorem cardyNumerator_eq_hypergeometric {x : ℝ} (hx : x ∈ Ioo 0 1) : + (∫ u in 0..x, cardyWeight u) = + 3 * x ^ ((1 : ℝ) / 3) * + ordinaryHypergeometric (1 / 3 : ℝ) (2 / 3) (4 / 3) x := by + rw [← (cardyNumerator_hasSum hx).tsum_eq, ordinaryHypergeometric_eq_tsum] + simp only [smul_eq_mul] + rw [← tsum_mul_left] + apply tsum_congr + intro n + rw [cardyBinomialTerm_integral, Real.rpow_add hx.1, Real.rpow_natCast] + calc + _ = (cardyBinomialCoefficient n / ((n : ℝ) + 1 / 3)) * + (x ^ n * x ^ ((1 : ℝ) / 3)) := by ring + _ = _ := by rw [cardyHypergeometricCoefficient_eq]; ring + +theorem cardyIntegral_eq_hypergeometric {x : ℝ} (hx : x ∈ Ioo 0 1) : + cardyIntegral x = cardyHypergeometric x := by + have hγ : Real.Gamma (4 / 3) = (1 / 3 : ℝ) * Real.Gamma (1 / 3) := by + convert Real.Gamma_add_one (s := 1 / 3) (by norm_num) using 1 + norm_num + have h₁ : Real.Gamma (1 / 3) ≠ 0 := ne_of_gt (Real.Gamma_pos_of_pos (by norm_num)) + have h₂ : Real.Gamma (2 / 3) ≠ 0 := ne_of_gt (Real.Gamma_pos_of_pos (by norm_num)) + rw [cardyIntegral, cardyNumerator_eq_hypergeometric hx, + cardyDenominator_eq_gamma, cardyHypergeometric, hγ] + field_simp + +end Cardy + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/AlperinWeights/Brauer.lean b/lean/OAI/RepresentationTheory/AlperinWeights/Brauer.lean index 67bc7a9dab8934b5db602829da65dfa3302f300a..12c99a8e3af19ccd9a9aeddf6c0698f09b684d16 100644 --- a/lean/OAI/RepresentationTheory/AlperinWeights/Brauer.lean +++ b/lean/OAI/RepresentationTheory/AlperinWeights/Brauer.lean @@ -1,560 +1,560 @@ -import Mathlib - -namespace OAI - -/-! Brauer projection and foundations for blockwise Alperin weights. -/ - -noncomputable section -namespace BlockwiseAW -abbrev AlgebraicIntegers := integralClosure ℤ ℂ - -lemma exists_integer_reduction (p : ℕ) [Fact p.Prime] - (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] : - Nonempty (AlgebraicIntegers →+* k) := by - let P : Ideal ℤ := RingHom.ker (Int.castRingHom (ZMod p)) - have hsur : Function.Surjective (Int.castRingHom (ZMod p)) := by - intro x - exact ⟨x.val, by simp⟩ - have : P.IsMaximal := RingHom.ker_isMaximal_of_surjective _ hsur - have hker : RingHom.ker (algebraMap ℤ AlgebraicIntegers) ≤ P := by - rw [(RingHom.injective_iff_ker_eq_bot _).mp - (FaithfulSMul.algebraMap_injective ℤ AlgebraicIntegers)] - exact bot_le - obtain ⟨Q, hQ, hQP⟩ := - Ideal.exists_ideal_over_maximal_of_isIntegral (S := AlgebraicIntegers) P hker - have : Q.IsMaximal := hQ - let P' := Q.comap (algebraMap ℤ AlgebraicIntegers) - have : P'.IsMaximal := by - change (Q.under ℤ).IsMaximal - rw [hQP] - infer_instance - let R := ℤ ⧸ P' - let S := AlgebraicIntegers ⧸ Q - let : Field R := Ideal.Quotient.field P' - let : Field S := Ideal.Quotient.field Q - let : Algebra R S := Ideal.quotientAlgebra - have : Algebra.IsIntegral R S := Algebra.IsIntegral.quotient - have : Algebra.IsAlgebraic R S := Algebra.IsIntegral.isAlgebraic - let f : R →+* k := Ideal.Quotient.lift P' (Int.castRingHom k) (by - intro x hx - change (x : k) = 0 - rw [CharP.intCast_eq_zero_iff k p] - have hx' : (x : ZMod p) = 0 := by - change x ∈ P - rw [← hQP] - exact hx - exact (CharP.intCast_eq_zero_iff (ZMod p) p x).mp hx') - let : Algebra R k := f.toAlgebra - let lift : S →ₐ[R] k := IsAlgClosed.lift - exact ⟨lift.toRingHom.comp (Ideal.Quotient.mk Q)⟩ - -def integerReduction (p : ℕ) [Fact p.Prime] - (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] : - AlgebraicIntegers →+* k := - Classical.choice (exists_integer_reduction p k) - -section OrbitCancellation -open scoped BigOperators -open MulAction - -theorem invariant_sum_eq_fixedPoint_sum - {p : ℕ} [Fact p.Prime] {P α R : Type*} [Group P] [MulAction P α] - [Fintype α] [Fintype (fixedPoints P α)] [CommSemiring R] [CharP R p] (hP : IsPGroup p P) - (f : α → R) (hf : ∀ (g : P) (x : α), f (g • x) = f x) : - (∑ x : α, f x) = ∑ x : fixedPoints P α, f x.val := by - classical - have key (x : α) : - (∑ y : { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x }, f y.val) = - (Fintype.card (orbit P x) : R) * f x := by - have hval (y : { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x }) : - f y.val = f x := by - obtain ⟨g, hg⟩ := mem_orbit_iff.mp (Quotient.exact' y.property) - rw [← hg] - exact hf g x - simp_rw [hval] - have hcard : Fintype.card { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x } = - Fintype.card (orbit P x) := by - simp only [Quotient.eq'']; congr - rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, hcard] - calc - (∑ x : α, f x) = ∑ a : Quotient (orbitRel P α), - ∑ y : {y // Quotient.mk'' y = a}, f y.val := by - rw [← Fintype.sum_sigma' (fun (a : Quotient (orbitRel P α)) (y : {y // Quotient.mk'' y = a}) => f y.val)] - exact (Fintype.sum_equiv (Equiv.sigmaFiberEquiv (@Quotient.mk'' _ (orbitRel P α))) _ _ - (fun _ => rfl)).symm - _ = ∑ x : fixedPoints P α, f x.val := by - symm - refine Finset.sum_bij_ne_zero (fun a _ _ => Quotient.mk'' a.val) - (fun _ _ _ => Finset.mem_univ _) - (fun a₁ _ _ a₂ _ _ h => - Subtype.ext (mem_fixedPoints'.mp a₂.property a₁.val (Quotient.exact' h))) - (fun b => Quotient.inductionOn' b fun b _ hb => by - obtain ⟨n, hn⟩ := hP.card_orbit b - rw [Nat.card_eq_fintype_card] at hn - have hn0 : n = 0 := by - by_contra hne - have hp : (p : R) = 0 := CharP.cast_eq_zero R p - apply hb - rw [key, hn, Nat.cast_pow, hp, zero_pow hne, zero_mul] - have hbfix : b ∈ fixedPoints P α := - mem_fixedPoints_iff_card_orbit_eq_one.mpr (by rw [hn, hn0, pow_zero]) - refine ⟨⟨b, hbfix⟩, Finset.mem_univ _, ?_, rfl⟩ - simpa [key, hn, hn0] using hb - ) (fun a _ _ => by - rw [key, mem_fixedPoints_iff_card_orbit_eq_one.mp a.property] - simp) - -end OrbitCancellation - -section GroupAlgebra -variable {R G : Type*} [CommSemiring R] [Group G] - -abbrev Center (R G : Type*) [CommSemiring R] [Group G] := - Subalgebra.center R (MonoidAlgebra R G) - -theorem mem_center_iff_coeff_conj (a : MonoidAlgebra R G) : - a ∈ Center R G ↔ ∀ g x : G, a.coeff (g * x * g⁻¹) = a.coeff x := by - rw [Subalgebra.mem_center_iff] - constructor - · intro h g x - have eq := congrArg (fun b : MonoidAlgebra R G => b.coeff (g * x)) - (h (MonoidAlgebra.single g 1)) - simpa using eq.symm - · intro h b - induction b using MonoidAlgebra.induction_on with - | of g => - ext x - simpa [MonoidAlgebra.of_apply, mul_assoc] using (h g (g⁻¹ * x)).symm - | add b c hb hc => simp only [add_mul, mul_add, hb, hc] - | smul r b hb => simp only [smul_mul_assoc, mul_smul_comm, hb] - -def coefficientRestriction (H : Subgroup G) : - MonoidAlgebra R G →ₗ[R] MonoidAlgebra R H where - toFun a := .ofCoeff (a.coeff.comapDomain Subtype.val Subtype.val_injective.injOn) - map_add' a b := by ext; rfl - map_smul' r a := by ext; rfl - -@[simp] theorem coefficientRestriction_coeff (H : Subgroup G) - (a : MonoidAlgebra R G) (h : H) : - (coefficientRestriction H a).coeff h = a.coeff h := rfl - -theorem coefficientRestriction_mem_center (H : Subgroup G) - (a : MonoidAlgebra R G) (ha : a ∈ Center R G) : - coefficientRestriction H a ∈ Center R H := by - rw [mem_center_iff_coeff_conj] at ha ⊢ - intro g x - exact ha g x - -def centerRestriction (H : Subgroup G) : Center R G →ₗ[R] Center R H where - toFun z := ⟨coefficientRestriction H z.val, - coefficientRestriction_mem_center H z.val z.property⟩ - map_add' _ _ := Subtype.ext (map_add (coefficientRestriction H) _ _) - map_smul' _ _ := Subtype.ext (map_smul (coefficientRestriction H) _ _) - -def classSum [Finite G] (g : G) : Center R G := by - classical - refine ⟨.ofCoeff (Finsupp.equivFunOnFinite.symm (fun x => if IsConj g x then 1 else 0)), ?_⟩ - rw [mem_center_iff_coeff_conj] - intro h x - change (if IsConj g (h * x * h⁻¹) then (1 : R) else 0) = - (if IsConj g x then (1 : R) else 0) - have hc : IsConj x (h * x * h⁻¹) := isConj_iff.mpr ⟨h, rfl⟩ - have hi : IsConj g (h * x * h⁻¹) ↔ IsConj g x := - ⟨fun t => t.trans hc.symm, fun t => t.trans hc⟩ - simp only [hi] - -end GroupAlgebra - -section BrauerProjection -open scoped BigOperators -variable {R G : Type*} [CommSemiring R] [Group G] - -def conjugationInvariants (R : Type*) [CommSemiring R] (Q : Subgroup G) : - Subalgebra R (MonoidAlgebra R G) := - Subalgebra.centralizer R (Set.range (fun q : Q => MonoidAlgebra.single (q : G) (1 : R))) - -theorem mem_conjugationInvariants_iff (Q : Subgroup G) (a : MonoidAlgebra R G) : - a ∈ conjugationInvariants R Q ↔ - ∀ (q : Q) (x : G), a.coeff ((q : G) * x * (q : G)⁻¹) = a.coeff x := by - rw [conjugationInvariants, Subalgebra.mem_centralizer_iff] - constructor - · intro h q x - have eq := congrArg (fun b : MonoidAlgebra R G => b.coeff ((q : G) * x)) - (h (MonoidAlgebra.single (q : G) 1) ⟨q, rfl⟩) - simpa using eq.symm - · rintro h _ ⟨q, rfl⟩ - ext x - simpa [mul_assoc] using (h q ((q : G)⁻¹ * x)).symm - -theorem coeff_mul_sum [Fintype G] (a b : MonoidAlgebra R G) (g : G) : - (a * b).coeff g = ∑ x : G, a.coeff x * b.coeff (x⁻¹ * g) := by - rw [MonoidAlgebra.coeff_mul_apply_left, Finsupp.sum_fintype] - intro x - exact zero_mul _ - -@[simp] theorem coefficientRestriction_one (H : Subgroup G) : - coefficientRestriction (R := R) H 1 = 1 := by - classical - ext x - simp [MonoidAlgebra.one_def, Finsupp.single_apply, eq_comm] - -variable [Finite G] - -theorem coefficientRestriction_mul_of_invariant - {p : ℕ} [Fact p.Prime] [CharP R p] (Q : Subgroup G) (hQ : IsPGroup p Q) - (a b : MonoidAlgebra R G) (ha : a ∈ conjugationInvariants R Q) - (hb : b ∈ conjugationInvariants R Q) : - coefficientRestriction (Subgroup.centralizer (Q : Set G)) (a * b) = - coefficientRestriction (Subgroup.centralizer (Q : Set G)) a * - coefficientRestriction (Subgroup.centralizer (Q : Set G)) b := by - classical - let : Fintype G := Fintype.ofFinite G - let : MulAction Q G := MulAction.compHom G (ConjAct.toConjAct.toMonoidHom.comp Q.subtype) - have hfixed : MulAction.fixedPoints Q G = (Subgroup.centralizer (Q : Set G) : Set G) := by - ext g - change (g ∈ MulAction.fixedPoints Q G) ↔ g ∈ Subgroup.centralizer (Q : Set G) - rw [MulAction.mem_fixedPoints, Subgroup.mem_centralizer_iff] - constructor - · intro h q hq - have hq' := h ⟨q, hq⟩ - change q * g * q⁻¹ = g at hq' - exact (mul_inv_eq_iff_eq_mul).mp hq' - · intro h q - change (q : G) * g * (q : G)⁻¹ = g - exact (mul_inv_eq_iff_eq_mul).mpr (h q q.property) - rw [mem_conjugationInvariants_iff] at ha hb - ext g - rw [coefficientRestriction_coeff, coeff_mul_sum, coeff_mul_sum] - simp only [coefficientRestriction_coeff] - let f : G → R := fun x => a.coeff x * b.coeff (x⁻¹ * (g : G)) - have hf : ∀ (q : Q) (x : G), f (q • x) = f x := by - intro q x - have hg : (q : G) * (g : G) * (q : G)⁻¹ = g := - (mul_inv_eq_iff_eq_mul).mpr (Subgroup.mem_centralizer_iff.mp g.property q q.property) - have he : ((q : G) * x * (q : G)⁻¹)⁻¹ * (g : G) = - (q : G) * (x⁻¹ * (g : G)) * (q : G)⁻¹ := by - calc - _ = ((q : G) * x * (q : G)⁻¹)⁻¹ * ((q : G) * (g : G) * (q : G)⁻¹) := by rw [hg] - _ = _ := by group - change a.coeff ((q : G) * x * (q : G)⁻¹) * - b.coeff (((q : G) * x * (q : G)⁻¹)⁻¹ * (g : G)) = f x - rw [ha q x, he, hb q (x⁻¹ * (g : G))] - have hs := invariant_sum_eq_fixedPoint_sum hQ f hf - change (∑ x : G, f x) = ∑ x : Subgroup.centralizer (Q : Set G), f x.val - rw [hs] - exact (Fintype.sum_equiv (Set.equivOfEq hfixed) _ _ (fun _ => rfl)) - -def brauerHom {p : ℕ} [Fact p.Prime] [CharP R p] - (Q : Subgroup G) (hQ : IsPGroup p Q) : - conjugationInvariants R Q →ₐ[R] MonoidAlgebra R (Subgroup.centralizer (Q : Set G)) where - toFun a := coefficientRestriction (Subgroup.centralizer (Q : Set G)) a.val - map_zero' := map_zero _ - map_one' := coefficientRestriction_one _ - map_add' a b := map_add _ a.val b.val - map_mul' a b := coefficientRestriction_mul_of_invariant Q hQ a.val b.val a.property b.property - commutes' r := by - change coefficientRestriction _ (algebraMap R (MonoidAlgebra R G) r) = _ - simp only [Algebra.algebraMap_eq_smul_one, map_smul, coefficientRestriction_one] - -end BrauerProjection - -theorem finite_simple_quotients {R M ι : Type*} [Ring R] - [AddCommGroup M] [Module R M] - (S : ι → Type*) [∀ i, AddCommGroup (S i)] [∀ i, Module R (S i)] - [∀ i, IsSimpleModule R (S i)] - (hS : ∀ i j, Nonempty (S i ≃ₗ[R] S j) → i = j) - (hM : IsFiniteLength R M) : - Set.Finite {i | ∃ f : M →ₗ[R] S i, f ≠ 0} := by - classical - induction hM with - | of_subsingleton => - convert Set.finite_empty (α := ι) using 1 - ext i - simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false, not_exists, not_not] - intro f - ext x - rw [Subsingleton.elim x 0, map_zero, LinearMap.zero_apply] - | @of_simple_quotient M _ _ N _ hN ih => - have hsimple : Set.Subsingleton {i | Nonempty ((M ⧸ N) ≃ₗ[R] S i)} := by - rintro i ⟨e⟩ j ⟨f⟩ - exact hS i j ⟨e.symm.trans f⟩ - refine (ih.union hsimple.finite).subset ?_ - rintro i ⟨f, hf⟩ - by_cases hn : f.comp N.subtype = 0 - · right - have hker : N ≤ LinearMap.ker f := by - intro x hx - have hh := congrArg (fun g : N →ₗ[R] S i => g ⟨x, hx⟩) hn - exact hh - let g : (M ⧸ N) →ₗ[R] S i := N.liftQ f hker - have hg : g ≠ 0 := by - intro hg0 - apply hf - ext x - exact congrArg (fun t : (M ⧸ N) →ₗ[R] S i => t (N.mkQ x)) hg0 - exact ⟨LinearEquiv.ofBijective g ((LinearMap.bijective_or_eq_zero g).resolve_right hg)⟩ - · exact Or.inl ⟨f.comp N.subtype, hn⟩ - -section Blocks -variable (k G : Type*) [Field k] [Group G] - -structure Block where - idempotent : Center k G - isIdempotent : idempotent * idempotent = idempotent - nonzero : idempotent ≠ 0 - primitive : ∀ c : Center k G, c * c = c → c * idempotent = c → - c = 0 ∨ c = idempotent - -structure SimpleRepresentation where - dim : ℕ - representation : Representation k G (Fin dim → k) - irreducible : representation.IsIrreducible - -variable {k G} - -theorem irreducible_moduleFinite {k G V : Type*} [Field k] [Group G] [Finite G] - [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsIrreducible] : - Module.Finite k V := by - have : Module.Finite (MonoidAlgebra k G) ρ.asModule := inferInstance - have : Module.Finite k ρ.asModule := Module.Finite.trans (MonoidAlgebra k G) ρ.asModule - exact Module.Finite.equiv ρ.asModuleEquiv - -theorem exists_coordinate_simple {k G V : Type*} [Field k] [Group G] [Finite G] - [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsIrreducible] : - ∃ S : SimpleRepresentation k G, Nonempty (Representation.Equiv ρ S.representation) := by - let : Module.Finite k V := irreducible_moduleFinite ρ - let n := Module.finrank k V - let e : V ≃ₗ[k] (Fin n → k) := (Module.finBasis k V).equivFun - let σ : Representation k G (Fin n → k) := e.conjRingEquiv.toMonoidHom.comp ρ - let E : Representation.Equiv ρ σ := Representation.Equiv.mk e (by - intro g - ext x - simp [σ, LinearEquiv.conjRingEquiv]) - let f : ρ.asModule →ₗ[MonoidAlgebra k G] σ.asModule := - Representation.IntertwiningMap.equivLinearMapAsModule ρ σ E.toIntertwiningMap - have hσ : σ.IsIrreducible := by - rw [Representation.irreducible_iff_isSimpleModule_asModule] - exact (f.isSimpleModule_iff_of_bijective e.bijective).mp inferInstance - exact ⟨⟨n, σ, hσ⟩, ⟨E⟩⟩ - -def SimpleRepresentation.BelongsTo (V : SimpleRepresentation k G) (B : Block k G) : Prop := - V.representation.asAlgebraHom B.idempotent.val = 1 - -def simpleModuleSetoid (B : Block k G) : - Setoid {V : SimpleRepresentation k G // V.BelongsTo B} where - r V W := Nonempty (Representation.Equiv V.val.representation W.val.representation) - iseqv := by - constructor - · intro V; exact ⟨Representation.Equiv.refl _⟩ - · rintro V W ⟨e⟩; exact ⟨e.symm⟩ - · rintro U V W ⟨e⟩ ⟨f⟩; exact ⟨e.trans f⟩ - -def SimpleModuleClasses (B : Block k G) := Quotient (simpleModuleSetoid B) - -instance finiteSimpleModuleClasses {k G : Type*} [Field k] [Group G] [Finite G] - (B : Block k G) : Finite (SimpleModuleClasses B) := by - classical - let R := MonoidAlgebra k G - let V (q : SimpleModuleClasses B) := (Quotient.out q).val - let S (q : SimpleModuleClasses B) := (V q).representation.asModule - let (q : SimpleModuleClasses B) : (V q).representation.IsIrreducible := (V q).irreducible - let (q : SimpleModuleClasses B) : IsSimpleModule R (S q) := inferInstance - have hS (q t : SimpleModuleClasses B) (h : Nonempty (S q ≃ₗ[R] S t)) : q = t := by - obtain ⟨e⟩ := h - let f := (Representation.IntertwiningMap.equivLinearMapAsModule - (V q).representation (V t).representation).symm e.toLinearMap - have hf : Function.Bijective f := e.bijective - have hrel : (simpleModuleSetoid B).r (Quotient.out q) (Quotient.out t) := - ⟨f.ofBijective hf⟩ - exact (Quotient.out_eq q).symm.trans ((Quotient.sound hrel).trans (Quotient.out_eq t)) - have hNoeth : IsNoetherian R R := isNoetherian_of_tower k (inferInstance : IsNoetherian k R) - have hArtin : IsArtinian R R := isArtinian_of_tower k (inferInstance : IsArtinian k R) - have hfinite := finite_simple_quotients S hS - (isFiniteLength_iff_isNoetherian_isArtinian.mpr ⟨hNoeth, hArtin⟩) - apply Finite.of_finite_univ - apply hfinite.subset - intro q _ - have : Nontrivial (S q) := IsSimpleModule.nontrivial R (S q) - obtain ⟨x, hx⟩ := exists_ne (0 : S q) - refine ⟨LinearMap.toSpanSingleton R (S q) x, ?_⟩ - intro hzero - apply hx - simpa using congrArg (fun f : R →ₗ[R] S q => f 1) hzero - -def l (B : Block k G) : ℕ := Nat.card (SimpleModuleClasses B) - -def IsCentralCharacter (B : Block k G) (lam : Center k G →ₐ[k] k) : Prop := - ∀ V : SimpleRepresentation k G, V.BelongsTo B → ∀ z : Center k G, - V.representation.asAlgebraHom z.val = - algebraMap k (Module.End k (Fin V.dim → k)) (lam z) - -end Blocks - -def OrdinaryCharacter (G : Type*) [Group G] := - {χ : G → ℂ // ∃ n : ℕ, ∃ ρ : Representation ℂ G (Fin n → ℂ), - ρ.IsIrreducible ∧ ρ.character = χ} - -namespace OrdinaryCharacter -variable {G : Type*} [Group G] - -def degree (χ : OrdinaryCharacter G) : ℕ := χ.property.choose - -def affording (χ : OrdinaryCharacter G) : Representation ℂ G (Fin χ.degree → ℂ) := - χ.property.choose_spec.choose - -instance affording_irreducible (χ : OrdinaryCharacter G) : χ.affording.IsIrreducible := - χ.property.choose_spec.choose_spec.left - -@[simp] theorem affording_character (χ : OrdinaryCharacter G) : χ.affording.character = χ.val := - χ.property.choose_spec.choose_spec.right - -theorem apply_conj (χ : OrdinaryCharacter G) (g x : G) : - χ.val (g * x * g⁻¹) = χ.val x := by - rw [← χ.affording_character] - exact Representation.char_conj χ.affording x g - -theorem degree_spec (χ : OrdinaryCharacter G) : χ.val 1 = (χ.degree : ℂ) := by - obtain ⟨ρ, -, hρ⟩ := χ.property.choose_spec - rw [← hρ, Representation.char_one] - simp [degree] - -theorem degree_pos (χ : OrdinaryCharacter G) : 0 < χ.degree := by - have : Nontrivial χ.affording.asModule := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) _ - have : Nontrivial (Fin χ.degree → ℂ) := χ.affording.asModuleEquiv.symm.toEquiv.nontrivial - simpa using Module.finrank_pos (R := ℂ) (M := Fin χ.degree → ℂ) - -open scoped Classical in - -theorem orthogonality [Fintype G] (χ ψ : OrdinaryCharacter G) : - (Nat.card G : ℂ)⁻¹ * ∑ g : G, χ.val g * ψ.val g⁻¹ = if χ = ψ then 1 else 0 := by - classical - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by exact_mod_cast Nat.card_pos.ne') - have he : Nonempty (Representation.Equiv ψ.affording χ.affording) ↔ χ = ψ := by - constructor - · rintro ⟨e⟩ - apply Subtype.ext - simpa using (Representation.char_iso e).symm - · rintro rfl - exact ⟨Representation.Equiv.refl _⟩ - simpa [he] using Representation.char_orthonormal χ.affording ψ.affording - -theorem linearIndependent [Finite G] : - LinearIndependent ℂ (fun χ : OrdinaryCharacter G => χ.val) := by - classical - let : Fintype G := Fintype.ofFinite G - let pair (ψ : OrdinaryCharacter G) : (G → ℂ) →ₗ[ℂ] ℂ := - { toFun := fun f => (Nat.card G : ℂ)⁻¹ * ∑ g : G, f g * ψ.val g⁻¹ - map_add' := fun f g => by simp [add_mul, Finset.sum_add_distrib, mul_add] - map_smul' := fun c f => by - simp [Finset.mul_sum, mul_left_comm, mul_assoc] } - have hpair (χ ψ : OrdinaryCharacter G) : pair ψ χ.val = if χ = ψ then 1 else 0 := - orthogonality χ ψ - refine linearIndependent_iff'.mpr ?_ - intro s c hs χ hχ - have h := congrArg (pair χ) hs - simpa [map_sum, map_smul, hpair, ← Finset.mul_sum, hχ] using h - -instance finite [Finite G] : Finite (OrdinaryCharacter G) := linearIndependent.finite - -end OrdinaryCharacter - -def pPart (p n : ℕ) : ℕ := p ^ n.factorization p - -abbrev Normalizer {G : Type*} [Group G] (Q : Subgroup G) : Subgroup G := - Subgroup.normalizer (Q : Set G) - -abbrev NormalizerQuotient {G : Type*} [Group G] (Q : Subgroup G) := - (Normalizer Q) ⧸ Q.subgroupOf (Normalizer Q) - -structure Weight (p : ℕ) (G : Type*) [Group G] where - subgroup : Subgroup G - isPSubgroup : IsPGroup p subgroup - character : OrdinaryCharacter (NormalizerQuotient subgroup) - defectZero : pPart p character.degree = pPart p (Nat.card (NormalizerQuotient subgroup)) - -namespace Weight -variable {p : ℕ} {G : Type*} [Group G] - -def inflatedCharacter (w : Weight p G) (h : (Normalizer w.subgroup)) : ℂ := - w.character.val (QuotientGroup.mk' (w.subgroup.subgroupOf (Normalizer w.subgroup)) h) - -def extendedCharacter (w : Weight p G) (g : G) : ℂ := by - classical - exact if h : g ∈ (Normalizer w.subgroup) then w.inflatedCharacter ⟨g, h⟩ else 0 - -def IsConjugate (w v : Weight p G) : Prop := - ∃ g : G, - (∀ x : G, x ∈ w.subgroup ↔ g * x * g⁻¹ ∈ v.subgroup) ∧ - (∀ x : G, w.extendedCharacter x = v.extendedCharacter (g * x * g⁻¹)) - -theorem isConjugate_refl (w : Weight p G) : w.IsConjugate w := by - refine ⟨1, ?_, ?_⟩ <;> simp - -theorem isConjugate_symm {w v : Weight p G} (hwv : w.IsConjugate v) : - v.IsConjugate w := by - obtain ⟨g, hQ, hχ⟩ := hwv - refine ⟨g⁻¹, ?_, ?_⟩ - · intro x - simpa [mul_assoc] using (hQ (g⁻¹ * x * g)).symm - · intro x - simpa [mul_assoc] using (hχ (g⁻¹ * x * g)).symm - -theorem isConjugate_trans {w v u : Weight p G} - (hwv : w.IsConjugate v) (hvu : v.IsConjugate u) : w.IsConjugate u := by - obtain ⟨g, hQ, hχ⟩ := hwv - obtain ⟨h, hR, hψ⟩ := hvu - refine ⟨h * g, ?_, ?_⟩ - · intro x - simpa [mul_assoc] using (hQ x).trans (hR (g * x * g⁻¹)) - · intro x - simpa [mul_assoc] using (hχ x).trans (hψ (g * x * g⁻¹)) - -instance finite [Finite G] : Finite (Weight p G) := by - let f : Weight p G → Σ Q : Subgroup G, OrdinaryCharacter (NormalizerQuotient Q) := - fun w => ⟨w.subgroup, w.character⟩ - apply Finite.of_injective f - rintro ⟨Q, hQ, χ, hχ⟩ ⟨Q', hQ', χ', hχ'⟩ h - obtain ⟨rfl, he⟩ := Sigma.mk.inj_iff.mp h - obtain rfl := eq_of_heq he - rfl - -def conjugacySetoid (p : ℕ) (G : Type*) [Group G] : Setoid (Weight p G) where - r := IsConjugate - iseqv := ⟨isConjugate_refl, isConjugate_symm, isConjugate_trans⟩ - -end Weight - -section BlockAssignment -variable {k G : Type*} [Field k] [Group G] [Finite G] - -def IsOrdinaryReduction (r : AlgebraicIntegers →+* k) (χ : G → ℂ) - (lam : Center k G →ₐ[k] k) : Prop := - ∀ g : G, ∃ a : AlgebraicIntegers, - (a : ℂ) = (Nat.card {x : G // IsConj g x} : ℂ) * χ g / χ 1 ∧ - lam (classSum g) = r a - -def AssignedTo (r : AlgebraicIntegers →+* k) {p : ℕ} - (w : Weight p G) (B : Block k G) : Prop := - ∃ b : Block k (Normalizer w.subgroup), - ∃ lam_b : Center k (Normalizer w.subgroup) →ₐ[k] k, - ∃ lam_B : Center k G →ₐ[k] k, - IsCentralCharacter b lam_b ∧ IsCentralCharacter B lam_B ∧ - IsOrdinaryReduction r w.inflatedCharacter lam_b ∧ - (∀ z : Center k G, lam_b (centerRestriction (Normalizer w.subgroup) z) = lam_B z) - -def W (p : ℕ) [Fact p.Prime] [IsAlgClosed k] [CharP k p] (B : Block k G) := - Quotient ((Weight.conjugacySetoid p G).comap - (fun w : {w : Weight p G // AssignedTo (integerReduction p k) w B} => w.val)) - -instance finiteW (p : ℕ) [Fact p.Prime] [IsAlgClosed k] [CharP k p] (B : Block k G) : - Finite (W p B) := by - unfold W - infer_instance - -end BlockAssignment - -end BlockwiseAW - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Brauer projection and foundations for blockwise Alperin weights. -/ + +noncomputable section +namespace BlockwiseAW +abbrev AlgebraicIntegers := integralClosure ℤ ℂ + +lemma exists_integer_reduction (p : ℕ) [Fact p.Prime] + (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] : + Nonempty (AlgebraicIntegers →+* k) := by + let P : Ideal ℤ := RingHom.ker (Int.castRingHom (ZMod p)) + have hsur : Function.Surjective (Int.castRingHom (ZMod p)) := by + intro x + exact ⟨x.val, by simp⟩ + have : P.IsMaximal := RingHom.ker_isMaximal_of_surjective _ hsur + have hker : RingHom.ker (algebraMap ℤ AlgebraicIntegers) ≤ P := by + rw [(RingHom.injective_iff_ker_eq_bot _).mp + (FaithfulSMul.algebraMap_injective ℤ AlgebraicIntegers)] + exact bot_le + obtain ⟨Q, hQ, hQP⟩ := + Ideal.exists_ideal_over_maximal_of_isIntegral (S := AlgebraicIntegers) P hker + have : Q.IsMaximal := hQ + let P' := Q.comap (algebraMap ℤ AlgebraicIntegers) + have : P'.IsMaximal := by + change (Q.under ℤ).IsMaximal + rw [hQP] + infer_instance + let R := ℤ ⧸ P' + let S := AlgebraicIntegers ⧸ Q + let : Field R := Ideal.Quotient.field P' + let : Field S := Ideal.Quotient.field Q + let : Algebra R S := Ideal.quotientAlgebra + have : Algebra.IsIntegral R S := Algebra.IsIntegral.quotient + have : Algebra.IsAlgebraic R S := Algebra.IsIntegral.isAlgebraic + let f : R →+* k := Ideal.Quotient.lift P' (Int.castRingHom k) (by + intro x hx + change (x : k) = 0 + rw [CharP.intCast_eq_zero_iff k p] + have hx' : (x : ZMod p) = 0 := by + change x ∈ P + rw [← hQP] + exact hx + exact (CharP.intCast_eq_zero_iff (ZMod p) p x).mp hx') + let : Algebra R k := f.toAlgebra + let lift : S →ₐ[R] k := IsAlgClosed.lift + exact ⟨lift.toRingHom.comp (Ideal.Quotient.mk Q)⟩ + +def integerReduction (p : ℕ) [Fact p.Prime] + (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] : + AlgebraicIntegers →+* k := + Classical.choice (exists_integer_reduction p k) + +section OrbitCancellation +open scoped BigOperators +open MulAction + +theorem invariant_sum_eq_fixedPoint_sum + {p : ℕ} [Fact p.Prime] {P α R : Type*} [Group P] [MulAction P α] + [Fintype α] [Fintype (fixedPoints P α)] [CommSemiring R] [CharP R p] (hP : IsPGroup p P) + (f : α → R) (hf : ∀ (g : P) (x : α), f (g • x) = f x) : + (∑ x : α, f x) = ∑ x : fixedPoints P α, f x.val := by + classical + have key (x : α) : + (∑ y : { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x }, f y.val) = + (Fintype.card (orbit P x) : R) * f x := by + have hval (y : { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x }) : + f y.val = f x := by + obtain ⟨g, hg⟩ := mem_orbit_iff.mp (Quotient.exact' y.property) + rw [← hg] + exact hf g x + simp_rw [hval] + have hcard : Fintype.card { y // (Quotient.mk'' y : Quotient (orbitRel P α)) = Quotient.mk'' x } = + Fintype.card (orbit P x) := by + simp only [Quotient.eq'']; congr + rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, hcard] + calc + (∑ x : α, f x) = ∑ a : Quotient (orbitRel P α), + ∑ y : {y // Quotient.mk'' y = a}, f y.val := by + rw [← Fintype.sum_sigma' (fun (a : Quotient (orbitRel P α)) (y : {y // Quotient.mk'' y = a}) => f y.val)] + exact (Fintype.sum_equiv (Equiv.sigmaFiberEquiv (@Quotient.mk'' _ (orbitRel P α))) _ _ + (fun _ => rfl)).symm + _ = ∑ x : fixedPoints P α, f x.val := by + symm + refine Finset.sum_bij_ne_zero (fun a _ _ => Quotient.mk'' a.val) + (fun _ _ _ => Finset.mem_univ _) + (fun a₁ _ _ a₂ _ _ h => + Subtype.ext (mem_fixedPoints'.mp a₂.property a₁.val (Quotient.exact' h))) + (fun b => Quotient.inductionOn' b fun b _ hb => by + obtain ⟨n, hn⟩ := hP.card_orbit b + rw [Nat.card_eq_fintype_card] at hn + have hn0 : n = 0 := by + by_contra hne + have hp : (p : R) = 0 := CharP.cast_eq_zero R p + apply hb + rw [key, hn, Nat.cast_pow, hp, zero_pow hne, zero_mul] + have hbfix : b ∈ fixedPoints P α := + mem_fixedPoints_iff_card_orbit_eq_one.mpr (by rw [hn, hn0, pow_zero]) + refine ⟨⟨b, hbfix⟩, Finset.mem_univ _, ?_, rfl⟩ + simpa [key, hn, hn0] using hb + ) (fun a _ _ => by + rw [key, mem_fixedPoints_iff_card_orbit_eq_one.mp a.property] + simp) + +end OrbitCancellation + +section GroupAlgebra +variable {R G : Type*} [CommSemiring R] [Group G] + +abbrev Center (R G : Type*) [CommSemiring R] [Group G] := + Subalgebra.center R (MonoidAlgebra R G) + +theorem mem_center_iff_coeff_conj (a : MonoidAlgebra R G) : + a ∈ Center R G ↔ ∀ g x : G, a.coeff (g * x * g⁻¹) = a.coeff x := by + rw [Subalgebra.mem_center_iff] + constructor + · intro h g x + have eq := congrArg (fun b : MonoidAlgebra R G => b.coeff (g * x)) + (h (MonoidAlgebra.single g 1)) + simpa using eq.symm + · intro h b + induction b using MonoidAlgebra.induction_on with + | of g => + ext x + simpa [MonoidAlgebra.of_apply, mul_assoc] using (h g (g⁻¹ * x)).symm + | add b c hb hc => simp only [add_mul, mul_add, hb, hc] + | smul r b hb => simp only [smul_mul_assoc, mul_smul_comm, hb] + +def coefficientRestriction (H : Subgroup G) : + MonoidAlgebra R G →ₗ[R] MonoidAlgebra R H where + toFun a := .ofCoeff (a.coeff.comapDomain Subtype.val Subtype.val_injective.injOn) + map_add' a b := by ext; rfl + map_smul' r a := by ext; rfl + +@[simp] theorem coefficientRestriction_coeff (H : Subgroup G) + (a : MonoidAlgebra R G) (h : H) : + (coefficientRestriction H a).coeff h = a.coeff h := rfl + +theorem coefficientRestriction_mem_center (H : Subgroup G) + (a : MonoidAlgebra R G) (ha : a ∈ Center R G) : + coefficientRestriction H a ∈ Center R H := by + rw [mem_center_iff_coeff_conj] at ha ⊢ + intro g x + exact ha g x + +def centerRestriction (H : Subgroup G) : Center R G →ₗ[R] Center R H where + toFun z := ⟨coefficientRestriction H z.val, + coefficientRestriction_mem_center H z.val z.property⟩ + map_add' _ _ := Subtype.ext (map_add (coefficientRestriction H) _ _) + map_smul' _ _ := Subtype.ext (map_smul (coefficientRestriction H) _ _) + +def classSum [Finite G] (g : G) : Center R G := by + classical + refine ⟨.ofCoeff (Finsupp.equivFunOnFinite.symm (fun x => if IsConj g x then 1 else 0)), ?_⟩ + rw [mem_center_iff_coeff_conj] + intro h x + change (if IsConj g (h * x * h⁻¹) then (1 : R) else 0) = + (if IsConj g x then (1 : R) else 0) + have hc : IsConj x (h * x * h⁻¹) := isConj_iff.mpr ⟨h, rfl⟩ + have hi : IsConj g (h * x * h⁻¹) ↔ IsConj g x := + ⟨fun t => t.trans hc.symm, fun t => t.trans hc⟩ + simp only [hi] + +end GroupAlgebra + +section BrauerProjection +open scoped BigOperators +variable {R G : Type*} [CommSemiring R] [Group G] + +def conjugationInvariants (R : Type*) [CommSemiring R] (Q : Subgroup G) : + Subalgebra R (MonoidAlgebra R G) := + Subalgebra.centralizer R (Set.range (fun q : Q => MonoidAlgebra.single (q : G) (1 : R))) + +theorem mem_conjugationInvariants_iff (Q : Subgroup G) (a : MonoidAlgebra R G) : + a ∈ conjugationInvariants R Q ↔ + ∀ (q : Q) (x : G), a.coeff ((q : G) * x * (q : G)⁻¹) = a.coeff x := by + rw [conjugationInvariants, Subalgebra.mem_centralizer_iff] + constructor + · intro h q x + have eq := congrArg (fun b : MonoidAlgebra R G => b.coeff ((q : G) * x)) + (h (MonoidAlgebra.single (q : G) 1) ⟨q, rfl⟩) + simpa using eq.symm + · rintro h _ ⟨q, rfl⟩ + ext x + simpa [mul_assoc] using (h q ((q : G)⁻¹ * x)).symm + +theorem coeff_mul_sum [Fintype G] (a b : MonoidAlgebra R G) (g : G) : + (a * b).coeff g = ∑ x : G, a.coeff x * b.coeff (x⁻¹ * g) := by + rw [MonoidAlgebra.coeff_mul_apply_left, Finsupp.sum_fintype] + intro x + exact zero_mul _ + +@[simp] theorem coefficientRestriction_one (H : Subgroup G) : + coefficientRestriction (R := R) H 1 = 1 := by + classical + ext x + simp [MonoidAlgebra.one_def, Finsupp.single_apply, eq_comm] + +variable [Finite G] + +theorem coefficientRestriction_mul_of_invariant + {p : ℕ} [Fact p.Prime] [CharP R p] (Q : Subgroup G) (hQ : IsPGroup p Q) + (a b : MonoidAlgebra R G) (ha : a ∈ conjugationInvariants R Q) + (hb : b ∈ conjugationInvariants R Q) : + coefficientRestriction (Subgroup.centralizer (Q : Set G)) (a * b) = + coefficientRestriction (Subgroup.centralizer (Q : Set G)) a * + coefficientRestriction (Subgroup.centralizer (Q : Set G)) b := by + classical + let : Fintype G := Fintype.ofFinite G + let : MulAction Q G := MulAction.compHom G (ConjAct.toConjAct.toMonoidHom.comp Q.subtype) + have hfixed : MulAction.fixedPoints Q G = (Subgroup.centralizer (Q : Set G) : Set G) := by + ext g + change (g ∈ MulAction.fixedPoints Q G) ↔ g ∈ Subgroup.centralizer (Q : Set G) + rw [MulAction.mem_fixedPoints, Subgroup.mem_centralizer_iff] + constructor + · intro h q hq + have hq' := h ⟨q, hq⟩ + change q * g * q⁻¹ = g at hq' + exact (mul_inv_eq_iff_eq_mul).mp hq' + · intro h q + change (q : G) * g * (q : G)⁻¹ = g + exact (mul_inv_eq_iff_eq_mul).mpr (h q q.property) + rw [mem_conjugationInvariants_iff] at ha hb + ext g + rw [coefficientRestriction_coeff, coeff_mul_sum, coeff_mul_sum] + simp only [coefficientRestriction_coeff] + let f : G → R := fun x => a.coeff x * b.coeff (x⁻¹ * (g : G)) + have hf : ∀ (q : Q) (x : G), f (q • x) = f x := by + intro q x + have hg : (q : G) * (g : G) * (q : G)⁻¹ = g := + (mul_inv_eq_iff_eq_mul).mpr (Subgroup.mem_centralizer_iff.mp g.property q q.property) + have he : ((q : G) * x * (q : G)⁻¹)⁻¹ * (g : G) = + (q : G) * (x⁻¹ * (g : G)) * (q : G)⁻¹ := by + calc + _ = ((q : G) * x * (q : G)⁻¹)⁻¹ * ((q : G) * (g : G) * (q : G)⁻¹) := by rw [hg] + _ = _ := by group + change a.coeff ((q : G) * x * (q : G)⁻¹) * + b.coeff (((q : G) * x * (q : G)⁻¹)⁻¹ * (g : G)) = f x + rw [ha q x, he, hb q (x⁻¹ * (g : G))] + have hs := invariant_sum_eq_fixedPoint_sum hQ f hf + change (∑ x : G, f x) = ∑ x : Subgroup.centralizer (Q : Set G), f x.val + rw [hs] + exact (Fintype.sum_equiv (Set.equivOfEq hfixed) _ _ (fun _ => rfl)) + +def brauerHom {p : ℕ} [Fact p.Prime] [CharP R p] + (Q : Subgroup G) (hQ : IsPGroup p Q) : + conjugationInvariants R Q →ₐ[R] MonoidAlgebra R (Subgroup.centralizer (Q : Set G)) where + toFun a := coefficientRestriction (Subgroup.centralizer (Q : Set G)) a.val + map_zero' := map_zero _ + map_one' := coefficientRestriction_one _ + map_add' a b := map_add _ a.val b.val + map_mul' a b := coefficientRestriction_mul_of_invariant Q hQ a.val b.val a.property b.property + commutes' r := by + change coefficientRestriction _ (algebraMap R (MonoidAlgebra R G) r) = _ + simp only [Algebra.algebraMap_eq_smul_one, map_smul, coefficientRestriction_one] + +end BrauerProjection + +theorem finite_simple_quotients {R M ι : Type*} [Ring R] + [AddCommGroup M] [Module R M] + (S : ι → Type*) [∀ i, AddCommGroup (S i)] [∀ i, Module R (S i)] + [∀ i, IsSimpleModule R (S i)] + (hS : ∀ i j, Nonempty (S i ≃ₗ[R] S j) → i = j) + (hM : IsFiniteLength R M) : + Set.Finite {i | ∃ f : M →ₗ[R] S i, f ≠ 0} := by + classical + induction hM with + | of_subsingleton => + convert Set.finite_empty (α := ι) using 1 + ext i + simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false, not_exists, not_not] + intro f + ext x + rw [Subsingleton.elim x 0, map_zero, LinearMap.zero_apply] + | @of_simple_quotient M _ _ N _ hN ih => + have hsimple : Set.Subsingleton {i | Nonempty ((M ⧸ N) ≃ₗ[R] S i)} := by + rintro i ⟨e⟩ j ⟨f⟩ + exact hS i j ⟨e.symm.trans f⟩ + refine (ih.union hsimple.finite).subset ?_ + rintro i ⟨f, hf⟩ + by_cases hn : f.comp N.subtype = 0 + · right + have hker : N ≤ LinearMap.ker f := by + intro x hx + have hh := congrArg (fun g : N →ₗ[R] S i => g ⟨x, hx⟩) hn + exact hh + let g : (M ⧸ N) →ₗ[R] S i := N.liftQ f hker + have hg : g ≠ 0 := by + intro hg0 + apply hf + ext x + exact congrArg (fun t : (M ⧸ N) →ₗ[R] S i => t (N.mkQ x)) hg0 + exact ⟨LinearEquiv.ofBijective g ((LinearMap.bijective_or_eq_zero g).resolve_right hg)⟩ + · exact Or.inl ⟨f.comp N.subtype, hn⟩ + +section Blocks +variable (k G : Type*) [Field k] [Group G] + +structure Block where + idempotent : Center k G + isIdempotent : idempotent * idempotent = idempotent + nonzero : idempotent ≠ 0 + primitive : ∀ c : Center k G, c * c = c → c * idempotent = c → + c = 0 ∨ c = idempotent + +structure SimpleRepresentation where + dim : ℕ + representation : Representation k G (Fin dim → k) + irreducible : representation.IsIrreducible + +variable {k G} + +theorem irreducible_moduleFinite {k G V : Type*} [Field k] [Group G] [Finite G] + [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsIrreducible] : + Module.Finite k V := by + have : Module.Finite (MonoidAlgebra k G) ρ.asModule := inferInstance + have : Module.Finite k ρ.asModule := Module.Finite.trans (MonoidAlgebra k G) ρ.asModule + exact Module.Finite.equiv ρ.asModuleEquiv + +theorem exists_coordinate_simple {k G V : Type*} [Field k] [Group G] [Finite G] + [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsIrreducible] : + ∃ S : SimpleRepresentation k G, Nonempty (Representation.Equiv ρ S.representation) := by + let : Module.Finite k V := irreducible_moduleFinite ρ + let n := Module.finrank k V + let e : V ≃ₗ[k] (Fin n → k) := (Module.finBasis k V).equivFun + let σ : Representation k G (Fin n → k) := e.conjRingEquiv.toMonoidHom.comp ρ + let E : Representation.Equiv ρ σ := Representation.Equiv.mk e (by + intro g + ext x + simp [σ, LinearEquiv.conjRingEquiv]) + let f : ρ.asModule →ₗ[MonoidAlgebra k G] σ.asModule := + Representation.IntertwiningMap.equivLinearMapAsModule ρ σ E.toIntertwiningMap + have hσ : σ.IsIrreducible := by + rw [Representation.irreducible_iff_isSimpleModule_asModule] + exact (f.isSimpleModule_iff_of_bijective e.bijective).mp inferInstance + exact ⟨⟨n, σ, hσ⟩, ⟨E⟩⟩ + +def SimpleRepresentation.BelongsTo (V : SimpleRepresentation k G) (B : Block k G) : Prop := + V.representation.asAlgebraHom B.idempotent.val = 1 + +def simpleModuleSetoid (B : Block k G) : + Setoid {V : SimpleRepresentation k G // V.BelongsTo B} where + r V W := Nonempty (Representation.Equiv V.val.representation W.val.representation) + iseqv := by + constructor + · intro V; exact ⟨Representation.Equiv.refl _⟩ + · rintro V W ⟨e⟩; exact ⟨e.symm⟩ + · rintro U V W ⟨e⟩ ⟨f⟩; exact ⟨e.trans f⟩ + +def SimpleModuleClasses (B : Block k G) := Quotient (simpleModuleSetoid B) + +instance finiteSimpleModuleClasses {k G : Type*} [Field k] [Group G] [Finite G] + (B : Block k G) : Finite (SimpleModuleClasses B) := by + classical + let R := MonoidAlgebra k G + let V (q : SimpleModuleClasses B) := (Quotient.out q).val + let S (q : SimpleModuleClasses B) := (V q).representation.asModule + let (q : SimpleModuleClasses B) : (V q).representation.IsIrreducible := (V q).irreducible + let (q : SimpleModuleClasses B) : IsSimpleModule R (S q) := inferInstance + have hS (q t : SimpleModuleClasses B) (h : Nonempty (S q ≃ₗ[R] S t)) : q = t := by + obtain ⟨e⟩ := h + let f := (Representation.IntertwiningMap.equivLinearMapAsModule + (V q).representation (V t).representation).symm e.toLinearMap + have hf : Function.Bijective f := e.bijective + have hrel : (simpleModuleSetoid B).r (Quotient.out q) (Quotient.out t) := + ⟨f.ofBijective hf⟩ + exact (Quotient.out_eq q).symm.trans ((Quotient.sound hrel).trans (Quotient.out_eq t)) + have hNoeth : IsNoetherian R R := isNoetherian_of_tower k (inferInstance : IsNoetherian k R) + have hArtin : IsArtinian R R := isArtinian_of_tower k (inferInstance : IsArtinian k R) + have hfinite := finite_simple_quotients S hS + (isFiniteLength_iff_isNoetherian_isArtinian.mpr ⟨hNoeth, hArtin⟩) + apply Finite.of_finite_univ + apply hfinite.subset + intro q _ + have : Nontrivial (S q) := IsSimpleModule.nontrivial R (S q) + obtain ⟨x, hx⟩ := exists_ne (0 : S q) + refine ⟨LinearMap.toSpanSingleton R (S q) x, ?_⟩ + intro hzero + apply hx + simpa using congrArg (fun f : R →ₗ[R] S q => f 1) hzero + +def l (B : Block k G) : ℕ := Nat.card (SimpleModuleClasses B) + +def IsCentralCharacter (B : Block k G) (lam : Center k G →ₐ[k] k) : Prop := + ∀ V : SimpleRepresentation k G, V.BelongsTo B → ∀ z : Center k G, + V.representation.asAlgebraHom z.val = + algebraMap k (Module.End k (Fin V.dim → k)) (lam z) + +end Blocks + +def OrdinaryCharacter (G : Type*) [Group G] := + {χ : G → ℂ // ∃ n : ℕ, ∃ ρ : Representation ℂ G (Fin n → ℂ), + ρ.IsIrreducible ∧ ρ.character = χ} + +namespace OrdinaryCharacter +variable {G : Type*} [Group G] + +def degree (χ : OrdinaryCharacter G) : ℕ := χ.property.choose + +def affording (χ : OrdinaryCharacter G) : Representation ℂ G (Fin χ.degree → ℂ) := + χ.property.choose_spec.choose + +instance affording_irreducible (χ : OrdinaryCharacter G) : χ.affording.IsIrreducible := + χ.property.choose_spec.choose_spec.left + +@[simp] theorem affording_character (χ : OrdinaryCharacter G) : χ.affording.character = χ.val := + χ.property.choose_spec.choose_spec.right + +theorem apply_conj (χ : OrdinaryCharacter G) (g x : G) : + χ.val (g * x * g⁻¹) = χ.val x := by + rw [← χ.affording_character] + exact Representation.char_conj χ.affording x g + +theorem degree_spec (χ : OrdinaryCharacter G) : χ.val 1 = (χ.degree : ℂ) := by + obtain ⟨ρ, -, hρ⟩ := χ.property.choose_spec + rw [← hρ, Representation.char_one] + simp [degree] + +theorem degree_pos (χ : OrdinaryCharacter G) : 0 < χ.degree := by + have : Nontrivial χ.affording.asModule := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) _ + have : Nontrivial (Fin χ.degree → ℂ) := χ.affording.asModuleEquiv.symm.toEquiv.nontrivial + simpa using Module.finrank_pos (R := ℂ) (M := Fin χ.degree → ℂ) + +open scoped Classical in + +theorem orthogonality [Fintype G] (χ ψ : OrdinaryCharacter G) : + (Nat.card G : ℂ)⁻¹ * ∑ g : G, χ.val g * ψ.val g⁻¹ = if χ = ψ then 1 else 0 := by + classical + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by exact_mod_cast Nat.card_pos.ne') + have he : Nonempty (Representation.Equiv ψ.affording χ.affording) ↔ χ = ψ := by + constructor + · rintro ⟨e⟩ + apply Subtype.ext + simpa using (Representation.char_iso e).symm + · rintro rfl + exact ⟨Representation.Equiv.refl _⟩ + simpa [he] using Representation.char_orthonormal χ.affording ψ.affording + +theorem linearIndependent [Finite G] : + LinearIndependent ℂ (fun χ : OrdinaryCharacter G => χ.val) := by + classical + let : Fintype G := Fintype.ofFinite G + let pair (ψ : OrdinaryCharacter G) : (G → ℂ) →ₗ[ℂ] ℂ := + { toFun := fun f => (Nat.card G : ℂ)⁻¹ * ∑ g : G, f g * ψ.val g⁻¹ + map_add' := fun f g => by simp [add_mul, Finset.sum_add_distrib, mul_add] + map_smul' := fun c f => by + simp [Finset.mul_sum, mul_left_comm, mul_assoc] } + have hpair (χ ψ : OrdinaryCharacter G) : pair ψ χ.val = if χ = ψ then 1 else 0 := + orthogonality χ ψ + refine linearIndependent_iff'.mpr ?_ + intro s c hs χ hχ + have h := congrArg (pair χ) hs + simpa [map_sum, map_smul, hpair, ← Finset.mul_sum, hχ] using h + +instance finite [Finite G] : Finite (OrdinaryCharacter G) := linearIndependent.finite + +end OrdinaryCharacter + +def pPart (p n : ℕ) : ℕ := p ^ n.factorization p + +abbrev Normalizer {G : Type*} [Group G] (Q : Subgroup G) : Subgroup G := + Subgroup.normalizer (Q : Set G) + +abbrev NormalizerQuotient {G : Type*} [Group G] (Q : Subgroup G) := + (Normalizer Q) ⧸ Q.subgroupOf (Normalizer Q) + +structure Weight (p : ℕ) (G : Type*) [Group G] where + subgroup : Subgroup G + isPSubgroup : IsPGroup p subgroup + character : OrdinaryCharacter (NormalizerQuotient subgroup) + defectZero : pPart p character.degree = pPart p (Nat.card (NormalizerQuotient subgroup)) + +namespace Weight +variable {p : ℕ} {G : Type*} [Group G] + +def inflatedCharacter (w : Weight p G) (h : (Normalizer w.subgroup)) : ℂ := + w.character.val (QuotientGroup.mk' (w.subgroup.subgroupOf (Normalizer w.subgroup)) h) + +def extendedCharacter (w : Weight p G) (g : G) : ℂ := by + classical + exact if h : g ∈ (Normalizer w.subgroup) then w.inflatedCharacter ⟨g, h⟩ else 0 + +def IsConjugate (w v : Weight p G) : Prop := + ∃ g : G, + (∀ x : G, x ∈ w.subgroup ↔ g * x * g⁻¹ ∈ v.subgroup) ∧ + (∀ x : G, w.extendedCharacter x = v.extendedCharacter (g * x * g⁻¹)) + +theorem isConjugate_refl (w : Weight p G) : w.IsConjugate w := by + refine ⟨1, ?_, ?_⟩ <;> simp + +theorem isConjugate_symm {w v : Weight p G} (hwv : w.IsConjugate v) : + v.IsConjugate w := by + obtain ⟨g, hQ, hχ⟩ := hwv + refine ⟨g⁻¹, ?_, ?_⟩ + · intro x + simpa [mul_assoc] using (hQ (g⁻¹ * x * g)).symm + · intro x + simpa [mul_assoc] using (hχ (g⁻¹ * x * g)).symm + +theorem isConjugate_trans {w v u : Weight p G} + (hwv : w.IsConjugate v) (hvu : v.IsConjugate u) : w.IsConjugate u := by + obtain ⟨g, hQ, hχ⟩ := hwv + obtain ⟨h, hR, hψ⟩ := hvu + refine ⟨h * g, ?_, ?_⟩ + · intro x + simpa [mul_assoc] using (hQ x).trans (hR (g * x * g⁻¹)) + · intro x + simpa [mul_assoc] using (hχ x).trans (hψ (g * x * g⁻¹)) + +instance finite [Finite G] : Finite (Weight p G) := by + let f : Weight p G → Σ Q : Subgroup G, OrdinaryCharacter (NormalizerQuotient Q) := + fun w => ⟨w.subgroup, w.character⟩ + apply Finite.of_injective f + rintro ⟨Q, hQ, χ, hχ⟩ ⟨Q', hQ', χ', hχ'⟩ h + obtain ⟨rfl, he⟩ := Sigma.mk.inj_iff.mp h + obtain rfl := eq_of_heq he + rfl + +def conjugacySetoid (p : ℕ) (G : Type*) [Group G] : Setoid (Weight p G) where + r := IsConjugate + iseqv := ⟨isConjugate_refl, isConjugate_symm, isConjugate_trans⟩ + +end Weight + +section BlockAssignment +variable {k G : Type*} [Field k] [Group G] [Finite G] + +def IsOrdinaryReduction (r : AlgebraicIntegers →+* k) (χ : G → ℂ) + (lam : Center k G →ₐ[k] k) : Prop := + ∀ g : G, ∃ a : AlgebraicIntegers, + (a : ℂ) = (Nat.card {x : G // IsConj g x} : ℂ) * χ g / χ 1 ∧ + lam (classSum g) = r a + +def AssignedTo (r : AlgebraicIntegers →+* k) {p : ℕ} + (w : Weight p G) (B : Block k G) : Prop := + ∃ b : Block k (Normalizer w.subgroup), + ∃ lam_b : Center k (Normalizer w.subgroup) →ₐ[k] k, + ∃ lam_B : Center k G →ₐ[k] k, + IsCentralCharacter b lam_b ∧ IsCentralCharacter B lam_B ∧ + IsOrdinaryReduction r w.inflatedCharacter lam_b ∧ + (∀ z : Center k G, lam_b (centerRestriction (Normalizer w.subgroup) z) = lam_B z) + +def W (p : ℕ) [Fact p.Prime] [IsAlgClosed k] [CharP k p] (B : Block k G) := + Quotient ((Weight.conjugacySetoid p G).comap + (fun w : {w : Weight p G // AssignedTo (integerReduction p k) w B} => w.val)) + +instance finiteW (p : ℕ) [Fact p.Prime] [IsAlgClosed k] [CharP k p] (B : Block k G) : + Finite (W p B) := by + unfold W + infer_instance + +end BlockAssignment + +end BlockwiseAW + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/Block/Defect.lean b/lean/OAI/RepresentationTheory/Block/Defect.lean index c0f7d79791056507d41f3bc5e73b70b7a38bb11e..3c7a42b98f55bc50ab623cb333af799abfe70f03 100644 --- a/lean/OAI/RepresentationTheory/Block/Defect.lean +++ b/lean/OAI/RepresentationTheory/Block/Defect.lean @@ -1,408 +1,408 @@ -import Mathlib - -namespace OAI - -/-! -# Blocks, defect groups, and the bounded-order formulation of Donovan's conjecture - -This file develops supporting results, not a proof of Donovan's conjecture. -The algebra of a block is the actual corner `b (KG) b = (KG) b`, with identity `b`. -Morita equivalence is Mathlib's equivalence of module categories by a linear functor. - -We prove finiteness of blocks for a fixed finite-dimensional algebra, existence of -defect groups, the conditional reduction from bounded-order to fixed-defect Morita -finiteness, and equality of defect subgroups for blocks corresponding under a -coefficient-field embedding. - -Uniform bounded-defect-order Morita finiteness across varying finite groups remains -unproved. Block-idempotent descent and bijectivity, preservation of primitivity, and -scalar extension of Morita equivalences are also not established here. --/ -noncomputable section - -universe u v w - -namespace Donovan - -section Blocks - -variable {A : Type u} [Ring A] - -/-- A block is a nonzero primitive idempotent in the center, not necessarily -a primitive idempotent of the whole ring. -/ -def IsBlockIdempotent (b : A) : Prop := - b ≠ 0 ∧ IsIdempotentElem b ∧ IsMulCentral b ∧ - ∀ e : A, IsIdempotentElem e → IsMulCentral e → e * b = e → e = 0 ∨ e = b - -/-- The block idempotents in a ring. -/ -def BlockIdempotent (A : Type u) [Ring A] := {b : A // IsBlockIdempotent b} - -namespace BlockIdempotent - -instance : Coe (BlockIdempotent A) A := ⟨Subtype.val⟩ - -@[ext] theorem ext {b c : BlockIdempotent A} (h : (b : A) = c) : b = c := - Subtype.ext h - -theorem ne_zero (b : BlockIdempotent A) : (b : A) ≠ 0 := b.property.1 - -theorem idempotent (b : BlockIdempotent A) : IsIdempotentElem (b : A) := - b.property.2.1 - -theorem central (b : BlockIdempotent A) : IsMulCentral (b : A) := - b.property.2.2.1 - -theorem primitive (b : BlockIdempotent A) (e : A) - (he : IsIdempotentElem e) (hc : IsMulCentral e) (heb : e * b = e) : - e = 0 ∨ e = b := - b.property.2.2.2 e he hc heb - -/-- The ring of the block: the corner has identity `b`, rather than the -identity of the ambient ring. -/ -abbrev Algebra (b : BlockIdempotent A) := b.idempotent.Corner - -/-- For a central idempotent the corner is exactly the summand `A b`. -/ -theorem mem_corner_iff (b : BlockIdempotent A) (x : A) : - x ∈ Subsemigroup.corner (b : A) ↔ ∃ a : A, a * b = x := - Subsemigroup.mem_corner_iff_mem_range_mul_right b.idempotent b.central - -variable (K : Type v) [CommRing K] [_root_.Algebra K A] - -/-- Scalars in the block are `k b`. In particular the identity is `b`. -/ -def scalarHom (b : BlockIdempotent A) : K →+* b.Algebra where - toFun k := ⟨k • (b : A), by - rw [Subsemigroup.mem_corner_iff b.idempotent] - constructor - · rw [mul_smul_comm, b.idempotent.eq] - · rw [smul_mul_assoc, b.idempotent.eq]⟩ - map_zero' := Subtype.ext (zero_smul K (b : A)) - map_one' := Subtype.ext (one_smul K (b : A)) - map_add' k l := Subtype.ext (add_smul k l (b : A)) - map_mul' k l := Subtype.ext (by - change (k * l) • (b : A) = (k • (b : A)) * (l • (b : A)) - rw [smul_mul_smul_comm, b.idempotent.eq]) - -instance algebra (b : BlockIdempotent A) : _root_.Algebra K b.Algebra := - (scalarHom K b).toAlgebra' fun k x => Subtype.ext (by - change (k • (b : A)) * (x.val : A) = (x.val : A) * (k • (b : A)) - rw [smul_mul_assoc, mul_smul_comm, - ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).1, - ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).2]) - -/-- Inclusion of the block into the ambient algebra is linear. It is not -generally a unital homomorphism of rings, since the identities differ. -/ -def inclusion (b : BlockIdempotent A) : b.Algebra →ₗ[K] A where - toFun x := x.val - map_add' _ _ := rfl - map_smul' k x := by - change (k • (b : A)) * x.val = k • x.val - rw [smul_mul_assoc, ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).1] - -theorem inclusion_injective (b : BlockIdempotent A) : - Function.Injective (inclusion K b) := Subtype.val_injective - -end BlockIdempotent -end Blocks - -section FinitelyManyBlocksOfOneAlgebra - -variable {A : Type u} [Ring A] - -namespace BlockIdempotent - -/-- Distinct primitive central idempotents are orthogonal. -/ -theorem mul_eq_zero {b c : BlockIdempotent A} (h : b ≠ c) : (b : A) * c = 0 := by - have he : IsIdempotentElem ((b : A) * c) := by - change ((b : A) * c) * ((b : A) * c) = (b : A) * c - calc - ((b : A) * c) * ((b : A) * c) = (b : A) * ((c : A) * b) * c := - by simp only [mul_assoc] - _ = (b : A) * ((b : A) * c) * c := by rw [(c.central.comm (b : A)).eq] - _ = ((b : A) * b) * ((c : A) * c) := by simp only [mul_assoc] - _ = (b : A) * c := by rw [b.idempotent.eq, c.idempotent.eq] - have hc : IsMulCentral ((b : A) * c) := Set.mul_mem_center b.central c.central - have hb : ((b : A) * c) * b = (b : A) * c := by - rw [mul_assoc, (c.central.comm (b : A)).eq, ← mul_assoc, b.idempotent.eq] - have hc' : ((b : A) * c) * c = (b : A) * c := by - rw [mul_assoc, c.idempotent.eq] - obtain hz | hb' := b.primitive _ he hc hb - · exact hz - obtain hz | hc'' := c.primitive _ he hc hc' - · exact hz - exact (h (ext (hb'.symm.trans hc''))).elim - -variable (K : Type v) [Field K] [_root_.Algebra K A] - -/-- Primitive central idempotents form a linearly independent family. -/ -theorem linearIndependent : LinearIndependent K (fun b : BlockIdempotent A => (b : A)) := by - classical - rw [linearIndependent_iff'] - intro s f hs i hi - have h := congrArg (fun x : A => x * (i : A)) hs - rw [Finset.sum_mul, zero_mul, Finset.sum_eq_single_of_mem i hi] at h - · rw [smul_mul_assoc, i.idempotent.eq] at h - exact (smul_eq_zero.mp h).resolve_right i.ne_zero - · intro j _ hji - rw [smul_mul_assoc, mul_eq_zero hji, smul_zero] - -/-- A single finite-dimensional algebra has only finitely many blocks. -This does not bound the number of Morita types as the algebra varies. -/ -theorem finite [Module.Finite K A] : Finite (BlockIdempotent A) := - (linearIndependent (A := A) K).finite - -/-- A block of a finite-dimensional algebra is itself finite-dimensional, -for its natural scalar structure. -/ -theorem finiteDimensional_corner [Module.Finite K A] (b : BlockIdempotent A) : - FiniteDimensional K b.Algebra := - FiniteDimensional.of_injective (inclusion K b) (inclusion_injective K b) - -end BlockIdempotent -end FinitelyManyBlocksOfOneAlgebra - -section DefectGroups - -variable {K : Type v} [Field K] {G : Type u} [Group G] - -/-- A block idempotent is fixed under conjugation by every group element. -Thus it belongs to the domain of each genuine Brauer map. -/ -theorem BlockIdempotent.conjugation_fixed (b : BlockIdempotent (MonoidAlgebra K G)) - (g : G) : - MonoidAlgebra.single g 1 * (b : MonoidAlgebra K G) * - MonoidAlgebra.single g⁻¹ 1 = (b : MonoidAlgebra K G) := by - rw [← (b.central.comm (MonoidAlgebra.single g 1)).eq, mul_assoc, - MonoidAlgebra.single_mul_single, mul_inv_cancel, one_mul, - ← MonoidAlgebra.one_def, mul_one] - -/-- Delete coefficients outside the centralizer of `D`. On the `D`-fixed group algebra -in characteristic `p`, for a `p`-subgroup `D`, this is the Brauer map. We only use it on -central idempotents; no multiplicativity on the entire group algebra is asserted. -/ -def brauerProjection (D : Subgroup G) (x : MonoidAlgebra K G) : - MonoidAlgebra K (Subgroup.centralizer (D : Set G)) := - MonoidAlgebra.ofCoeff (x.coeff.subtypeDomain - (fun g => g ∈ Subgroup.centralizer (D : Set G))) - -@[simp] theorem brauerProjection_coeff (D : Subgroup G) (x : MonoidAlgebra K G) - (g : Subgroup.centralizer (D : Set G)) : - (brauerProjection D x).coeff g = x.coeff g.val := rfl - -@[simp] theorem brauerProjection_zero (D : Subgroup G) : - brauerProjection D (0 : MonoidAlgebra K G) = 0 := rfl - -/-- Defect groups are maximal, under inclusion, among the `p`-subgroups -with nonzero Brauer image. This does not impose a commutativity condition. -/ -def IsDefectGroup (p : ℕ) (b : BlockIdempotent (MonoidAlgebra K G)) - (D : Subgroup G) : Prop := - Maximal (fun Q : Subgroup G => IsPGroup p Q ∧ brauerProjection Q (b : MonoidAlgebra K G) ≠ 0) D - -@[simp] theorem brauerProjection_bot_eq_zero_iff (x : MonoidAlgebra K G) : - brauerProjection (⊥ : Subgroup G) x = 0 ↔ x = 0 := by - change MonoidAlgebra.ofCoeff _ = 0 ↔ x = 0 - rw [MonoidAlgebra.ofCoeff_eq_zero, Finsupp.subtypeDomain_eq_zero_iff] - · exact MonoidAlgebra.coeff_eq_zero - · intro g _ - rw [Subgroup.mem_centralizer_iff] - intro h hh - have : h = 1 := Subgroup.mem_bot.mp hh - simp [this] - -/-- Any `p`-subgroup with nonzero Brauer image is contained in a defect -group. This uses finiteness of the subgroup poset. -/ -theorem exists_defectGroup_ge [Finite G] (p : ℕ) - (b : BlockIdempotent (MonoidAlgebra K G)) (Q : Subgroup G) - (hQ : IsPGroup p Q) (hbQ : brauerProjection Q (b : MonoidAlgebra K G) ≠ 0) : - ∃ D : Subgroup G, Q ≤ D ∧ IsDefectGroup p b D := - ({D : Subgroup G | IsPGroup p D ∧ - brauerProjection D (b : MonoidAlgebra K G) ≠ 0}).toFinite.exists_le_maximal ⟨hQ, hbQ⟩ - -/-- A finite-group block has at least one defect group as defined above. -/ -theorem exists_defectGroup [Finite G] (p : ℕ) - (b : BlockIdempotent (MonoidAlgebra K G)) : - ∃ D : Subgroup G, IsDefectGroup p b D := by - let s : Set (Subgroup G) := - {D | IsPGroup p D ∧ brauerProjection D (b : MonoidAlgebra K G) ≠ 0} - have hs : s.Nonempty := by - refine ⟨⊥, IsPGroup.of_bot, ?_⟩ - exact mt (brauerProjection_bot_eq_zero_iff (b : MonoidAlgebra K G)).mp b.ne_zero - exact s.toFinite.exists_maximal hs - -end DefectGroups - -section MoritaClasses - -/-- A block of a finite group algebra over `K`. The group is allowed to -vary over all finite group types in the specified universe. -/ -structure FiniteGroupBlock (K : Type v) [Field K] where - G : Type u - [group : Group G] - [finite : Finite G] - block : BlockIdempotent (MonoidAlgebra K G) - -attribute [instance] FiniteGroupBlock.group FiniteGroupBlock.finite - -namespace FiniteGroupBlock - -variable {K : Type v} [Field K] - -/-- The actual block algebra `KGb`. -/ -abbrev Algebra (B : FiniteGroupBlock.{u, v} K) := B.block.Algebra - -/-- The equivalence relation is linear Morita equivalence, not ring -isomorphism or equivalence of the underlying un-enriched categories. -/ -def moritaSetoid (K : Type v) [Field K] : Setoid (FiniteGroupBlock.{u, v} K) where - r B C := IsMoritaEquivalent K B.Algebra C.Algebra - iseqv := ⟨fun B => IsMoritaEquivalent.refl K B.Algebra, - fun h => IsMoritaEquivalent.symm K h, fun h h' => IsMoritaEquivalent.trans K h h'⟩ - -end FiniteGroupBlock - -/-- Morita classes of all finite-group blocks over the fixed field `K`. -/ -def MoritaClass (K : Type v) [Field K] := - Quotient (FiniteGroupBlock.moritaSetoid.{u, v} K) - -/-- The Morita class represented by a block. -/ -def moritaClass {K : Type v} [Field K] (B : FiniteGroupBlock.{u, v} K) : - MoritaClass.{u, v} K := Quotient.mk _ B - -/-- The block has a defect group whose order is at most `M`. -/ -def HasDefectAtMost {K : Type v} [Field K] (p M : ℕ) (B : FiniteGroupBlock.{u, v} K) : - Prop := - ∃ D : Subgroup B.G, IsDefectGroup p B.block D ∧ Nat.card D ≤ M - -/-- The block has a defect group isomorphic to the given group `P`. -/ -def HasDefectIsomorphic {K : Type v} [Field K] (p : ℕ) (P : Type w) [Group P] - (B : FiniteGroupBlock.{u, v} K) : Prop := - ∃ D : Subgroup B.G, IsDefectGroup p B.block D ∧ Nonempty (D ≃* P) - -/-- Morita classes represented by blocks with a defect group of order at most `M`. -/ -def boundedClasses (p : ℕ) (K : Type v) [Field K] (M : ℕ) : - Set (MoritaClass.{u, v} K) := - moritaClass '' {B | HasDefectAtMost p M B} - -/-- Morita classes represented by blocks with a defect group isomorphic to `P`. -/ -def fixedDefectClasses (p : ℕ) (K : Type v) [Field K] (P : Type w) [Group P] : - Set (MoritaClass.{u, v} K) := - moritaClass '' {B | HasDefectIsomorphic p P B} - -variable {p : ℕ} {K : Type v} [Field K] - -/-- Equality of classes means linear Morita equivalence of the actual block algebras. -/ -theorem moritaClass_eq_iff (B C : FiniteGroupBlock.{u, v} K) : - moritaClass B = moritaClass C ↔ IsMoritaEquivalent K B.Algebra C.Algebra := - Quotient.eq - -/-- The order of a defect group is positive. -/ -theorem HasDefectAtMost.pos {M : ℕ} {B : FiniteGroupBlock.{u, v} K} - (h : HasDefectAtMost p M B) : 0 < M := by - obtain ⟨D, _, hD⟩ := h - exact lt_of_lt_of_le (Nat.card_pos (α := D)) hD - -/-- Every block is covered by some positive bound; the bounded-order classes -are not made empty by the definition of a defect group. -/ -theorem exists_positive_defect_bound (p : ℕ) (B : FiniteGroupBlock.{u, v} K) : - ∃ M : ℕ, 0 < M ∧ HasDefectAtMost p M B := by - obtain ⟨D, hD⟩ := exists_defectGroup p B.block - exact ⟨Nat.card D, Nat.card_pos, D, hD, le_rfl⟩ - -/-- An isomorphism of defect groups gives equality of their orders. -/ -theorem HasDefectIsomorphic.hasDefectAtMost {P : Type w} [Group P] - {B : FiniteGroupBlock.{u, v} K} (h : HasDefectIsomorphic p P B) : - HasDefectAtMost p (Nat.card P) B := by - obtain ⟨D, hD, ⟨e⟩⟩ := h - exact ⟨D, hD, (Nat.card_congr e.toEquiv).le⟩ - -/-- The fixed-defect classes are a subset of the bounded-order classes. -/ -theorem fixedDefectClasses_subset (p : ℕ) (K : Type v) [Field K] - (P : Type w) [Group P] : - fixedDefectClasses.{u, v, w} p K P ⊆ boundedClasses p K (Nat.card P) := by - rintro _ ⟨B, hB, rfl⟩ - exact ⟨B, hB.hasDefectAtMost, rfl⟩ - -/-- The elementary fixed-defect reduction. Uniform bounded-order finiteness is -an assumption, not a result proved here. There is no abelian hypothesis on `P`. -/ -theorem finite_fixedDefectClasses_of_bounded - (h : ∀ M : ℕ, 0 < M → (boundedClasses.{u, v} p K M).Finite) - (P : Type w) [Group P] [Finite P] : - (fixedDefectClasses.{u, v, w} p K P).Finite := - (h (Nat.card P) Nat.card_pos).subset (fixedDefectClasses_subset p K P) - -namespace FiniteGroupBlock - -variable {G : Type u} [Group G] [Finite G] - -/-- Regard a block for one fixed ambient group as a member of the class of -all finite-group blocks. -/ -def ofBlock (b : BlockIdempotent (MonoidAlgebra K G)) : FiniteGroupBlock.{u, v} K where - G := G - block := b - -end FiniteGroupBlock - -/-- For a fixed finite group, its blocks give a finite collection of Morita -classes. This is only the fixed-ambient-group claim, not Donovan's theorem. -/ -theorem finite_classes_for_one_group (K : Type v) [Field K] - (G : Type u) [Group G] [Finite G] : - (Set.range (fun b : BlockIdempotent (MonoidAlgebra K G) => - moritaClass (FiniteGroupBlock.ofBlock b))).Finite := by - have : Finite (BlockIdempotent (MonoidAlgebra K G)) := BlockIdempotent.finite K - exact Set.finite_range _ - -end MoritaClasses - -section CoefficientExtension - -variable {K : Type v} [Field K] {L : Type w} [Field L] -variable {G : Type u} [Group G] - -/-- Applying a field embedding to group-ring coefficients is injective. -/ -theorem coefficientExtension_injective (f : K →+* L) : - Function.Injective (MonoidAlgebra.mapRingHom G f) := by - intro x y h - apply MonoidAlgebra.ext - ext g - apply f.injective - simpa only [MonoidAlgebra.coeff_mapRingHom] using - congrArg (fun z : MonoidAlgebra L G => z.coeff g) h - -/-- Deleting coefficients outside the centralizer commutes with applying a -field embedding. This is the coefficient calculation for the Brauer map. -/ -theorem brauerProjection_coefficientExtension (f : K →+* L) (D : Subgroup G) - (x : MonoidAlgebra K G) : - brauerProjection D (MonoidAlgebra.mapRingHom G f x) = - MonoidAlgebra.mapRingHom (Subgroup.centralizer (D : Set G)) f - (brauerProjection D x) := by - apply MonoidAlgebra.ext - ext g - simp only [brauerProjection_coeff, MonoidAlgebra.coeff_mapRingHom] - -/-- The vanishing criterion used to compute defects is unchanged by a -coefficient-field embedding. -/ -theorem brauerProjection_coefficientExtension_eq_zero_iff (f : K →+* L) - (D : Subgroup G) (x : MonoidAlgebra K G) : - brauerProjection D (MonoidAlgebra.mapRingHom G f x) = 0 ↔ - brauerProjection D x = 0 := by - rw [brauerProjection_coefficientExtension] - constructor - · intro h - apply coefficientExtension_injective f - simpa only [map_zero] using h - · intro h - simp only [h, map_zero] - -/-- If two actual block idempotents correspond by coefficient extension, -then their defect subgroups are identical. This lemma does not assert -that every block descends, or that primitivity is preserved. -/ -theorem isDefectGroup_coefficientExtension_iff (f : K →+* L) (p : ℕ) - (b : BlockIdempotent (MonoidAlgebra K G)) - (c : BlockIdempotent (MonoidAlgebra L G)) - (h : MonoidAlgebra.mapRingHom G f (b : MonoidAlgebra K G) = (c : MonoidAlgebra L G)) - (D : Subgroup G) : IsDefectGroup p c D ↔ IsDefectGroup p b D := by - unfold IsDefectGroup Maximal - simp only [← h, ne_eq, brauerProjection_coefficientExtension_eq_zero_iff] - -end CoefficientExtension - -end Donovan - -end - -end OAI +import Mathlib + +namespace OAI + +/-! +# Blocks, defect groups, and the bounded-order formulation of Donovan's conjecture + +This file develops supporting results, not a proof of Donovan's conjecture. +The algebra of a block is the actual corner `b (KG) b = (KG) b`, with identity `b`. +Morita equivalence is Mathlib's equivalence of module categories by a linear functor. + +We prove finiteness of blocks for a fixed finite-dimensional algebra, existence of +defect groups, the conditional reduction from bounded-order to fixed-defect Morita +finiteness, and equality of defect subgroups for blocks corresponding under a +coefficient-field embedding. + +Uniform bounded-defect-order Morita finiteness across varying finite groups remains +unproved. Block-idempotent descent and bijectivity, preservation of primitivity, and +scalar extension of Morita equivalences are also not established here. +-/ +noncomputable section + +universe u v w + +namespace Donovan + +section Blocks + +variable {A : Type u} [Ring A] + +/-- A block is a nonzero primitive idempotent in the center, not necessarily +a primitive idempotent of the whole ring. -/ +def IsBlockIdempotent (b : A) : Prop := + b ≠ 0 ∧ IsIdempotentElem b ∧ IsMulCentral b ∧ + ∀ e : A, IsIdempotentElem e → IsMulCentral e → e * b = e → e = 0 ∨ e = b + +/-- The block idempotents in a ring. -/ +def BlockIdempotent (A : Type u) [Ring A] := {b : A // IsBlockIdempotent b} + +namespace BlockIdempotent + +instance : Coe (BlockIdempotent A) A := ⟨Subtype.val⟩ + +@[ext] theorem ext {b c : BlockIdempotent A} (h : (b : A) = c) : b = c := + Subtype.ext h + +theorem ne_zero (b : BlockIdempotent A) : (b : A) ≠ 0 := b.property.1 + +theorem idempotent (b : BlockIdempotent A) : IsIdempotentElem (b : A) := + b.property.2.1 + +theorem central (b : BlockIdempotent A) : IsMulCentral (b : A) := + b.property.2.2.1 + +theorem primitive (b : BlockIdempotent A) (e : A) + (he : IsIdempotentElem e) (hc : IsMulCentral e) (heb : e * b = e) : + e = 0 ∨ e = b := + b.property.2.2.2 e he hc heb + +/-- The ring of the block: the corner has identity `b`, rather than the +identity of the ambient ring. -/ +abbrev Algebra (b : BlockIdempotent A) := b.idempotent.Corner + +/-- For a central idempotent the corner is exactly the summand `A b`. -/ +theorem mem_corner_iff (b : BlockIdempotent A) (x : A) : + x ∈ Subsemigroup.corner (b : A) ↔ ∃ a : A, a * b = x := + Subsemigroup.mem_corner_iff_mem_range_mul_right b.idempotent b.central + +variable (K : Type v) [CommRing K] [_root_.Algebra K A] + +/-- Scalars in the block are `k b`. In particular the identity is `b`. -/ +def scalarHom (b : BlockIdempotent A) : K →+* b.Algebra where + toFun k := ⟨k • (b : A), by + rw [Subsemigroup.mem_corner_iff b.idempotent] + constructor + · rw [mul_smul_comm, b.idempotent.eq] + · rw [smul_mul_assoc, b.idempotent.eq]⟩ + map_zero' := Subtype.ext (zero_smul K (b : A)) + map_one' := Subtype.ext (one_smul K (b : A)) + map_add' k l := Subtype.ext (add_smul k l (b : A)) + map_mul' k l := Subtype.ext (by + change (k * l) • (b : A) = (k • (b : A)) * (l • (b : A)) + rw [smul_mul_smul_comm, b.idempotent.eq]) + +instance algebra (b : BlockIdempotent A) : _root_.Algebra K b.Algebra := + (scalarHom K b).toAlgebra' fun k x => Subtype.ext (by + change (k • (b : A)) * (x.val : A) = (x.val : A) * (k • (b : A)) + rw [smul_mul_assoc, mul_smul_comm, + ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).1, + ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).2]) + +/-- Inclusion of the block into the ambient algebra is linear. It is not +generally a unital homomorphism of rings, since the identities differ. -/ +def inclusion (b : BlockIdempotent A) : b.Algebra →ₗ[K] A where + toFun x := x.val + map_add' _ _ := rfl + map_smul' k x := by + change (k • (b : A)) * x.val = k • x.val + rw [smul_mul_assoc, ((Subsemigroup.mem_corner_iff b.idempotent).mp x.property).1] + +theorem inclusion_injective (b : BlockIdempotent A) : + Function.Injective (inclusion K b) := Subtype.val_injective + +end BlockIdempotent +end Blocks + +section FinitelyManyBlocksOfOneAlgebra + +variable {A : Type u} [Ring A] + +namespace BlockIdempotent + +/-- Distinct primitive central idempotents are orthogonal. -/ +theorem mul_eq_zero {b c : BlockIdempotent A} (h : b ≠ c) : (b : A) * c = 0 := by + have he : IsIdempotentElem ((b : A) * c) := by + change ((b : A) * c) * ((b : A) * c) = (b : A) * c + calc + ((b : A) * c) * ((b : A) * c) = (b : A) * ((c : A) * b) * c := + by simp only [mul_assoc] + _ = (b : A) * ((b : A) * c) * c := by rw [(c.central.comm (b : A)).eq] + _ = ((b : A) * b) * ((c : A) * c) := by simp only [mul_assoc] + _ = (b : A) * c := by rw [b.idempotent.eq, c.idempotent.eq] + have hc : IsMulCentral ((b : A) * c) := Set.mul_mem_center b.central c.central + have hb : ((b : A) * c) * b = (b : A) * c := by + rw [mul_assoc, (c.central.comm (b : A)).eq, ← mul_assoc, b.idempotent.eq] + have hc' : ((b : A) * c) * c = (b : A) * c := by + rw [mul_assoc, c.idempotent.eq] + obtain hz | hb' := b.primitive _ he hc hb + · exact hz + obtain hz | hc'' := c.primitive _ he hc hc' + · exact hz + exact (h (ext (hb'.symm.trans hc''))).elim + +variable (K : Type v) [Field K] [_root_.Algebra K A] + +/-- Primitive central idempotents form a linearly independent family. -/ +theorem linearIndependent : LinearIndependent K (fun b : BlockIdempotent A => (b : A)) := by + classical + rw [linearIndependent_iff'] + intro s f hs i hi + have h := congrArg (fun x : A => x * (i : A)) hs + rw [Finset.sum_mul, zero_mul, Finset.sum_eq_single_of_mem i hi] at h + · rw [smul_mul_assoc, i.idempotent.eq] at h + exact (smul_eq_zero.mp h).resolve_right i.ne_zero + · intro j _ hji + rw [smul_mul_assoc, mul_eq_zero hji, smul_zero] + +/-- A single finite-dimensional algebra has only finitely many blocks. +This does not bound the number of Morita types as the algebra varies. -/ +theorem finite [Module.Finite K A] : Finite (BlockIdempotent A) := + (linearIndependent (A := A) K).finite + +/-- A block of a finite-dimensional algebra is itself finite-dimensional, +for its natural scalar structure. -/ +theorem finiteDimensional_corner [Module.Finite K A] (b : BlockIdempotent A) : + FiniteDimensional K b.Algebra := + FiniteDimensional.of_injective (inclusion K b) (inclusion_injective K b) + +end BlockIdempotent +end FinitelyManyBlocksOfOneAlgebra + +section DefectGroups + +variable {K : Type v} [Field K] {G : Type u} [Group G] + +/-- A block idempotent is fixed under conjugation by every group element. +Thus it belongs to the domain of each genuine Brauer map. -/ +theorem BlockIdempotent.conjugation_fixed (b : BlockIdempotent (MonoidAlgebra K G)) + (g : G) : + MonoidAlgebra.single g 1 * (b : MonoidAlgebra K G) * + MonoidAlgebra.single g⁻¹ 1 = (b : MonoidAlgebra K G) := by + rw [← (b.central.comm (MonoidAlgebra.single g 1)).eq, mul_assoc, + MonoidAlgebra.single_mul_single, mul_inv_cancel, one_mul, + ← MonoidAlgebra.one_def, mul_one] + +/-- Delete coefficients outside the centralizer of `D`. On the `D`-fixed group algebra +in characteristic `p`, for a `p`-subgroup `D`, this is the Brauer map. We only use it on +central idempotents; no multiplicativity on the entire group algebra is asserted. -/ +def brauerProjection (D : Subgroup G) (x : MonoidAlgebra K G) : + MonoidAlgebra K (Subgroup.centralizer (D : Set G)) := + MonoidAlgebra.ofCoeff (x.coeff.subtypeDomain + (fun g => g ∈ Subgroup.centralizer (D : Set G))) + +@[simp] theorem brauerProjection_coeff (D : Subgroup G) (x : MonoidAlgebra K G) + (g : Subgroup.centralizer (D : Set G)) : + (brauerProjection D x).coeff g = x.coeff g.val := rfl + +@[simp] theorem brauerProjection_zero (D : Subgroup G) : + brauerProjection D (0 : MonoidAlgebra K G) = 0 := rfl + +/-- Defect groups are maximal, under inclusion, among the `p`-subgroups +with nonzero Brauer image. This does not impose a commutativity condition. -/ +def IsDefectGroup (p : ℕ) (b : BlockIdempotent (MonoidAlgebra K G)) + (D : Subgroup G) : Prop := + Maximal (fun Q : Subgroup G => IsPGroup p Q ∧ brauerProjection Q (b : MonoidAlgebra K G) ≠ 0) D + +@[simp] theorem brauerProjection_bot_eq_zero_iff (x : MonoidAlgebra K G) : + brauerProjection (⊥ : Subgroup G) x = 0 ↔ x = 0 := by + change MonoidAlgebra.ofCoeff _ = 0 ↔ x = 0 + rw [MonoidAlgebra.ofCoeff_eq_zero, Finsupp.subtypeDomain_eq_zero_iff] + · exact MonoidAlgebra.coeff_eq_zero + · intro g _ + rw [Subgroup.mem_centralizer_iff] + intro h hh + have : h = 1 := Subgroup.mem_bot.mp hh + simp [this] + +/-- Any `p`-subgroup with nonzero Brauer image is contained in a defect +group. This uses finiteness of the subgroup poset. -/ +theorem exists_defectGroup_ge [Finite G] (p : ℕ) + (b : BlockIdempotent (MonoidAlgebra K G)) (Q : Subgroup G) + (hQ : IsPGroup p Q) (hbQ : brauerProjection Q (b : MonoidAlgebra K G) ≠ 0) : + ∃ D : Subgroup G, Q ≤ D ∧ IsDefectGroup p b D := + ({D : Subgroup G | IsPGroup p D ∧ + brauerProjection D (b : MonoidAlgebra K G) ≠ 0}).toFinite.exists_le_maximal ⟨hQ, hbQ⟩ + +/-- A finite-group block has at least one defect group as defined above. -/ +theorem exists_defectGroup [Finite G] (p : ℕ) + (b : BlockIdempotent (MonoidAlgebra K G)) : + ∃ D : Subgroup G, IsDefectGroup p b D := by + let s : Set (Subgroup G) := + {D | IsPGroup p D ∧ brauerProjection D (b : MonoidAlgebra K G) ≠ 0} + have hs : s.Nonempty := by + refine ⟨⊥, IsPGroup.of_bot, ?_⟩ + exact mt (brauerProjection_bot_eq_zero_iff (b : MonoidAlgebra K G)).mp b.ne_zero + exact s.toFinite.exists_maximal hs + +end DefectGroups + +section MoritaClasses + +/-- A block of a finite group algebra over `K`. The group is allowed to +vary over all finite group types in the specified universe. -/ +structure FiniteGroupBlock (K : Type v) [Field K] where + G : Type u + [group : Group G] + [finite : Finite G] + block : BlockIdempotent (MonoidAlgebra K G) + +attribute [instance] FiniteGroupBlock.group FiniteGroupBlock.finite + +namespace FiniteGroupBlock + +variable {K : Type v} [Field K] + +/-- The actual block algebra `KGb`. -/ +abbrev Algebra (B : FiniteGroupBlock.{u, v} K) := B.block.Algebra + +/-- The equivalence relation is linear Morita equivalence, not ring +isomorphism or equivalence of the underlying un-enriched categories. -/ +def moritaSetoid (K : Type v) [Field K] : Setoid (FiniteGroupBlock.{u, v} K) where + r B C := IsMoritaEquivalent K B.Algebra C.Algebra + iseqv := ⟨fun B => IsMoritaEquivalent.refl K B.Algebra, + fun h => IsMoritaEquivalent.symm K h, fun h h' => IsMoritaEquivalent.trans K h h'⟩ + +end FiniteGroupBlock + +/-- Morita classes of all finite-group blocks over the fixed field `K`. -/ +def MoritaClass (K : Type v) [Field K] := + Quotient (FiniteGroupBlock.moritaSetoid.{u, v} K) + +/-- The Morita class represented by a block. -/ +def moritaClass {K : Type v} [Field K] (B : FiniteGroupBlock.{u, v} K) : + MoritaClass.{u, v} K := Quotient.mk _ B + +/-- The block has a defect group whose order is at most `M`. -/ +def HasDefectAtMost {K : Type v} [Field K] (p M : ℕ) (B : FiniteGroupBlock.{u, v} K) : + Prop := + ∃ D : Subgroup B.G, IsDefectGroup p B.block D ∧ Nat.card D ≤ M + +/-- The block has a defect group isomorphic to the given group `P`. -/ +def HasDefectIsomorphic {K : Type v} [Field K] (p : ℕ) (P : Type w) [Group P] + (B : FiniteGroupBlock.{u, v} K) : Prop := + ∃ D : Subgroup B.G, IsDefectGroup p B.block D ∧ Nonempty (D ≃* P) + +/-- Morita classes represented by blocks with a defect group of order at most `M`. -/ +def boundedClasses (p : ℕ) (K : Type v) [Field K] (M : ℕ) : + Set (MoritaClass.{u, v} K) := + moritaClass '' {B | HasDefectAtMost p M B} + +/-- Morita classes represented by blocks with a defect group isomorphic to `P`. -/ +def fixedDefectClasses (p : ℕ) (K : Type v) [Field K] (P : Type w) [Group P] : + Set (MoritaClass.{u, v} K) := + moritaClass '' {B | HasDefectIsomorphic p P B} + +variable {p : ℕ} {K : Type v} [Field K] + +/-- Equality of classes means linear Morita equivalence of the actual block algebras. -/ +theorem moritaClass_eq_iff (B C : FiniteGroupBlock.{u, v} K) : + moritaClass B = moritaClass C ↔ IsMoritaEquivalent K B.Algebra C.Algebra := + Quotient.eq + +/-- The order of a defect group is positive. -/ +theorem HasDefectAtMost.pos {M : ℕ} {B : FiniteGroupBlock.{u, v} K} + (h : HasDefectAtMost p M B) : 0 < M := by + obtain ⟨D, _, hD⟩ := h + exact lt_of_lt_of_le (Nat.card_pos (α := D)) hD + +/-- Every block is covered by some positive bound; the bounded-order classes +are not made empty by the definition of a defect group. -/ +theorem exists_positive_defect_bound (p : ℕ) (B : FiniteGroupBlock.{u, v} K) : + ∃ M : ℕ, 0 < M ∧ HasDefectAtMost p M B := by + obtain ⟨D, hD⟩ := exists_defectGroup p B.block + exact ⟨Nat.card D, Nat.card_pos, D, hD, le_rfl⟩ + +/-- An isomorphism of defect groups gives equality of their orders. -/ +theorem HasDefectIsomorphic.hasDefectAtMost {P : Type w} [Group P] + {B : FiniteGroupBlock.{u, v} K} (h : HasDefectIsomorphic p P B) : + HasDefectAtMost p (Nat.card P) B := by + obtain ⟨D, hD, ⟨e⟩⟩ := h + exact ⟨D, hD, (Nat.card_congr e.toEquiv).le⟩ + +/-- The fixed-defect classes are a subset of the bounded-order classes. -/ +theorem fixedDefectClasses_subset (p : ℕ) (K : Type v) [Field K] + (P : Type w) [Group P] : + fixedDefectClasses.{u, v, w} p K P ⊆ boundedClasses p K (Nat.card P) := by + rintro _ ⟨B, hB, rfl⟩ + exact ⟨B, hB.hasDefectAtMost, rfl⟩ + +/-- The elementary fixed-defect reduction. Uniform bounded-order finiteness is +an assumption, not a result proved here. There is no abelian hypothesis on `P`. -/ +theorem finite_fixedDefectClasses_of_bounded + (h : ∀ M : ℕ, 0 < M → (boundedClasses.{u, v} p K M).Finite) + (P : Type w) [Group P] [Finite P] : + (fixedDefectClasses.{u, v, w} p K P).Finite := + (h (Nat.card P) Nat.card_pos).subset (fixedDefectClasses_subset p K P) + +namespace FiniteGroupBlock + +variable {G : Type u} [Group G] [Finite G] + +/-- Regard a block for one fixed ambient group as a member of the class of +all finite-group blocks. -/ +def ofBlock (b : BlockIdempotent (MonoidAlgebra K G)) : FiniteGroupBlock.{u, v} K where + G := G + block := b + +end FiniteGroupBlock + +/-- For a fixed finite group, its blocks give a finite collection of Morita +classes. This is only the fixed-ambient-group claim, not Donovan's theorem. -/ +theorem finite_classes_for_one_group (K : Type v) [Field K] + (G : Type u) [Group G] [Finite G] : + (Set.range (fun b : BlockIdempotent (MonoidAlgebra K G) => + moritaClass (FiniteGroupBlock.ofBlock b))).Finite := by + have : Finite (BlockIdempotent (MonoidAlgebra K G)) := BlockIdempotent.finite K + exact Set.finite_range _ + +end MoritaClasses + +section CoefficientExtension + +variable {K : Type v} [Field K] {L : Type w} [Field L] +variable {G : Type u} [Group G] + +/-- Applying a field embedding to group-ring coefficients is injective. -/ +theorem coefficientExtension_injective (f : K →+* L) : + Function.Injective (MonoidAlgebra.mapRingHom G f) := by + intro x y h + apply MonoidAlgebra.ext + ext g + apply f.injective + simpa only [MonoidAlgebra.coeff_mapRingHom] using + congrArg (fun z : MonoidAlgebra L G => z.coeff g) h + +/-- Deleting coefficients outside the centralizer commutes with applying a +field embedding. This is the coefficient calculation for the Brauer map. -/ +theorem brauerProjection_coefficientExtension (f : K →+* L) (D : Subgroup G) + (x : MonoidAlgebra K G) : + brauerProjection D (MonoidAlgebra.mapRingHom G f x) = + MonoidAlgebra.mapRingHom (Subgroup.centralizer (D : Set G)) f + (brauerProjection D x) := by + apply MonoidAlgebra.ext + ext g + simp only [brauerProjection_coeff, MonoidAlgebra.coeff_mapRingHom] + +/-- The vanishing criterion used to compute defects is unchanged by a +coefficient-field embedding. -/ +theorem brauerProjection_coefficientExtension_eq_zero_iff (f : K →+* L) + (D : Subgroup G) (x : MonoidAlgebra K G) : + brauerProjection D (MonoidAlgebra.mapRingHom G f x) = 0 ↔ + brauerProjection D x = 0 := by + rw [brauerProjection_coefficientExtension] + constructor + · intro h + apply coefficientExtension_injective f + simpa only [map_zero] using h + · intro h + simp only [h, map_zero] + +/-- If two actual block idempotents correspond by coefficient extension, +then their defect subgroups are identical. This lemma does not assert +that every block descends, or that primitivity is preserved. -/ +theorem isDefectGroup_coefficientExtension_iff (f : K →+* L) (p : ℕ) + (b : BlockIdempotent (MonoidAlgebra K G)) + (c : BlockIdempotent (MonoidAlgebra L G)) + (h : MonoidAlgebra.mapRingHom G f (b : MonoidAlgebra K G) = (c : MonoidAlgebra L G)) + (D : Subgroup G) : IsDefectGroup p c D ↔ IsDefectGroup p b D := by + unfold IsDefectGroup Maximal + simp only [← h, ne_eq, brauerProjection_coefficientExtension_eq_zero_iff] + +end CoefficientExtension + +end Donovan + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Action.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Action.lean index 901d035538555429eb1719d0c2358696af740e0a..473ddc216d436541c24f9cd5b719b0731e67c638 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Action.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Action.lean @@ -1,57 +1,57 @@ -import OAI.RepresentationTheory.FiniteUnitary.Coefficients - -namespace OAI - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators Classical - -variable {α ι : Type*} [Fintype α] [Fintype ι] - -def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where - toFun p := - { toFun := fun e => e.trans p.toEmbedding - invFun := fun e => e.trans p.symm.toEmbedding - left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) - right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } - map_one' := by ext e i; rfl - map_mul' p q := by ext e i; rfl - -omit [Fintype α] [Fintype ι] in -@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : - tupleAction p e i=p (e i) := rfl - -omit [Fintype α] in -lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by - obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective - exact ⟨p,Function.Embedding.ext hp⟩ - -omit [Fintype α] in -lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : - tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by - constructor - · intro h x hx - obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx - exact congrArg (fun f : ι ↪ α => f i) h - · intro h - ext i - exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) - -end CubeShuffle.UnitaryFinite -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators Classical - -lemma irreducible_of_equiv {G V W : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : - Representation.IsIrreducible σ := by - rw [Representation.irreducible_iff_isSimpleModule_asModule] - have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance - let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := - Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap - have hf : Function.Bijective f := e.toLinearEquiv.bijective - exact (f.isSimpleModule_iff_of_bijective hf).mp hi - -end CubeShuffle.UnitaryFinite - -end OAI +import OAI.RepresentationTheory.FiniteUnitary.Coefficients + +namespace OAI + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators Classical + +variable {α ι : Type*} [Fintype α] [Fintype ι] + +def tupleAction : Equiv.Perm α →* Equiv.Perm (ι ↪ α) where + toFun p := + { toFun := fun e => e.trans p.toEmbedding + invFun := fun e => e.trans p.symm.toEmbedding + left_inv := fun e => by ext i; exact p.symm_apply_apply (e i) + right_inv := fun e => by ext i; exact p.apply_symm_apply (e i) } + map_one' := by ext e i; rfl + map_mul' p q := by ext e i; rfl + +omit [Fintype α] [Fintype ι] in +@[simp] lemma tupleAction_apply (p : Equiv.Perm α) (e : ι ↪ α) (i : ι) : + tupleAction p e i=p (e i) := rfl + +omit [Fintype α] in +lemma tupleAction_transitive (e f : ι ↪ α) : ∃ p, tupleAction p e=f := by + obtain ⟨p,hp⟩ := Equiv.Perm.exists_extending_pair e f e.injective f.injective + exact ⟨p,Function.Embedding.ext hp⟩ + +omit [Fintype α] in +lemma tupleAction_fixed_iff [DecidableEq α] (e : ι ↪ α) (p : Equiv.Perm α) : + tupleAction p e=e ↔ ∀ x ∈ Finset.univ.image e, p x=x := by + constructor + · intro h x hx + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hx + exact congrArg (fun f : ι ↪ α => f i) h + · intro h + ext i + exact h (e i) (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + +end CubeShuffle.UnitaryFinite +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators Classical + +lemma irreducible_of_equiv {G V W : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (e : Representation.Equiv ρ σ) [Representation.IsIrreducible ρ] : + Representation.IsIrreducible σ := by + rw [Representation.irreducible_iff_isSimpleModule_asModule] + have hi := (Representation.irreducible_iff_isSimpleModule_asModule ρ).mp inferInstance + let f : ρ.asModule →ₗ[MonoidAlgebra ℂ G] σ.asModule := + Representation.IntertwiningMap.equivLinearMapAsModule ρ σ e.toIntertwiningMap + have hf : Function.Bijective f := e.toLinearEquiv.bijective + exact (f.isSimpleModule_iff_of_bijective hf).mp hi + +end CubeShuffle.UnitaryFinite + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Averaging.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Averaging.lean index d225ec656d1e4846ff1b83c7805941496c834db3..f2e3fd7415cb2f099a5d640a6f892c2a5a7b41f8 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Averaging.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Averaging.lean @@ -1,370 +1,370 @@ -import OAI.RepresentationTheory.FiniteUnitary.Coefficients - -namespace OAI - -namespace CubeShuffle.FiniteConvolution -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) -noncomputable def power (p : G → ℝ) : ℕ → G → ℝ - | 0 => fun g => if g=1 then 1 else 0 - | n+1 => conv p (power p n) - -lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : - ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) - -lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) - {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by - apply lt_of_lt_of_le (mul_pos ha hb) - have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) - (Finset.mem_univ a) - simpa [conv] using h - -lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by - unfold conv - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [←Finset.mul_sum] - congr 1 - exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) - -lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by - intro n - induction n with - | zero => intro g; simp only [power]; split_ifs <;> norm_num - | succ n ih => exact conv_nonneg hp ih - -lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by - intro n - induction n with - | zero => simp [power] - | succ n ih => rw [power,sum_conv,hp,ih,one_mul] - -lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) - (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by - induction l with - | nil => simp [power] - | cons a l ih => - simpa only [List.length_cons,List.prod_cons,power] using - conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) - (ih (fun g hg => hl g (by simp [hg]))) - -lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by - induction m, hnm using Nat.le_induction with - | base => exact hg - | succ m _ ih => - simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih - -/-- Finite generation and a positive holding probability produce a genuine -finite-time positive minorant, rather than a spectral-gap assumption. -/ -theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) - (hgen : Subgroup.closure {g | 0 < p g}=⊤) : - ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by - have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by - rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] - trivial - choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) - let n := Finset.univ.sup (fun g => (l g).length) - refine ⟨n,fun g => ?_⟩ - have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) - have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) - have hpos := power_list_pos hp (l g) (hl g) - rw [hprod g] at hpos - exact power_pos_mono hp h1 (hlen.trans hpow) hpos - -structure Minorant (p : G → ℝ) where - exponent : ℕ - mass : ℝ - mass_pos : 0 < mass - mass_le_one : mass ≤ 1 - lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g - -noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) - (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by - let n := Classical.choose (exists_positive_power hp h1 hgen) - have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) - let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) - have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) - have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) - have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos - have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) - simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' - refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ - have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp - rw [he] - exact hag g - -end CubeShuffle.FiniteConvolution -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where - toFun g := (ρ g).toContinuousLinearMap - map_one' := by ext v; simp - map_mul' g h := by ext v; simp - -omit [Fintype G] in -@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : - continuousRepresentation ρ g v=ρ g v := rfl - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : - ‖ρ g v‖=‖v‖ := by - rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] - -omit [Fintype G] in -lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - ‖continuousRepresentation ρ g‖≤1 := by - apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one - intro v - simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] - -omit [Fintype G] in -lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : - (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by - ext w - apply ext_inner_left ℂ - intro v - rw [ContinuousLinearMap.adjoint_inner_right] - exact (unitary_inner_inv ρ hρ g v w).symm - -noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := - ∑ g, (p g : ℂ) • continuousRepresentation ρ g - -lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by - apply (norm_sum_le _ _).trans - apply Finset.sum_le_sum - intro g _ - rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] - exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) - -lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by - change (weightedOperator ρ p).adjoint=weightedOperator ρ p - unfold weightedOperator - rw [map_sum] - simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] - apply Fintype.sum_equiv (Equiv.inv G) - intro g - simp [hp] - -noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := - weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) - -lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) - -lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : - continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,←map_mul] - exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) - -lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : - uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by - unfold uniformOperator weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,←map_mul] - exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) - -lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : - IsIdempotentElem (uniformOperator ρ) := by - change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ - nth_rw 1 [uniformOperator,weightedOperator] - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, - ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] - rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : - IsStarProjection (uniformOperator ρ) := - ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ - -lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : - weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.sum_mul] - simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : - uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by - unfold weightedOperator - rw [Finset.mul_sum] - simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] - rfl - -/-- A finite Doeblin minorant gives a dimension-free contraction off invariants; -no irreducible decomposition or unproved spectral-gap hypothesis is used. -/ -theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) - (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : - ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by - let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) - have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) - have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hsum : ∑ g,q g=1-ε := by - simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - field_simp - have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by - simp only [uniformOperator,weightedOperator] - rw [Finset.smul_sum,←Finset.sum_add_distrib] - apply Finset.sum_congr rfl - intro g _ - simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, - Complex.ofReal_inv,Complex.ofReal_natCast] - congr 1 - field_simp - ring - have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by - rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] - rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] - calc - _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ - _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) - ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) - (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) - _ = _ := mul_one _ - -end CubeShuffle.UnitaryFinite -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators Classical -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : - weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by - unfold weightedOperator FiniteConvolution.conv - simp only [Complex.ofReal_sum,Finset.sum_smul] - rw [Finset.sum_comm,Finset.sum_mul] - apply Finset.sum_congr rfl - intro h _ - rw [Finset.mul_sum] - simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp [Complex.ofReal_mul,mul_comm] - -lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : - weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by - induction n with - | zero => simp [FiniteConvolution.power,weightedOperator] - | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] - -lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) - (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : - (weightedOperator ρ p-uniformOperator ρ)^n= - (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by - have hAP := weighted_uniform_left ρ p - have hPA := weighted_uniform_right ρ p - rw [hp,one_smul] at hAP hPA - have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by - show _*_= _*_ - rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] - have he : weightedOperator ρ p-uniformOperator ρ= - weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] - rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] - -/-- Explicit gap from the finite-time minorant; its value depends only on the -finite group law, not on the dimension of any represented space. -/ -noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := - 1-c.mass/(2*(2:ℝ)^c.exponent) - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - unfold minorantGap - linarith - -omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in -lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by - unfold minorantGap - exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) - -/-- The one-block strict contraction follows from generation and the genuine -holding probability via Doeblin; this is uniform over ALL unitary representations. -/ -theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) - (c : FiniteConvolution.Minorant p) : - ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by - have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) - have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) - (FiniteConvolution.sum_power hp _) c.mass c.lower - rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), - hself.norm_pow_two_pow] at hbound - have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) - have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by - apply (div_le_iff₀ (by positivity)).mpr - nlinarith [c.mass_le_one] - have hbern := one_add_mul_le_pow - (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) - (2^c.exponent) - have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by - push_cast - field_simp - ring - rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern - by_contra h - have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h - have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) - linarith [c.mass_pos] - -end CubeShuffle.UnitaryFinite - -namespace CubeShuffle.FiniteAverage -open scoped BigOperators Classical -variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] - [Ring A] [Algebra ℂ A] - -noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := - MultilinearMap.domDomCongr (Fintype.equivFin I).symm - (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) - -lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : - orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by - unfold orderedProduct - rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] - let l := List.ofFn (Fintype.equivFin I).symm - have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective - have hu : l.toFinset=Finset.univ := by - ext i - simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] - exact (Fintype.equivFin I).symm.surjective i - have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl - rw [hu] at he - rw [he] - congr 1 - exact List.map_ofFn.symm - -lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : - F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by - rw [F.map_smul_univ,F.map_sum] - simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] - -/-- Exact independence factorization for commuting finite random factors. -/ -lemma ordered_average (x : I → Ω → A) - (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) - (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : - (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) - (fun _ _ _ _ hij => havg hij))= - (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, - Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by - rw [←orderedProduct_eq _ havg,multilinear_average] - simp only [orderedProduct_eq _ (hc _)] - -end CubeShuffle.FiniteAverage - -end OAI +import OAI.RepresentationTheory.FiniteUnitary.Coefficients + +namespace OAI + +namespace CubeShuffle.FiniteConvolution +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def conv (p q : G → ℝ) (g : G) : ℝ := ∑ h, p h*q (h⁻¹*g) +noncomputable def power (p : G → ℝ) : ℕ → G → ℝ + | 0 => fun g => if g=1 then 1 else 0 + | n+1 => conv p (power p n) + +lemma conv_nonneg {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) : + ∀ g, 0 ≤ conv p q g := fun _ => Finset.sum_nonneg (fun h _ => mul_nonneg (hp h) (hq _)) + +lemma conv_pos_of {p q : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hq : ∀ g, 0 ≤ q g) + {a b : G} (ha : 0 < p a) (hb : 0 < q b) : 0 < conv p q (a*b) := by + apply lt_of_lt_of_le (mul_pos ha hb) + have h := Finset.single_le_sum (fun g _ => mul_nonneg (hp g) (hq (g⁻¹*(a*b)))) + (Finset.mem_univ a) + simpa [conv] using h + +lemma sum_conv (p q : G → ℝ) : ∑ g, conv p q g=(∑ g,p g)*(∑ g,q g) := by + unfold conv + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [←Finset.mul_sum] + congr 1 + exact Fintype.sum_equiv (Equiv.mulLeft h⁻¹) _ _ (fun _ => rfl) + +lemma power_nonneg {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) : ∀ n g, 0 ≤ power p n g := by + intro n + induction n with + | zero => intro g; simp only [power]; split_ifs <;> norm_num + | succ n ih => exact conv_nonneg hp ih + +lemma sum_power {p : G → ℝ} (hp : ∑ g,p g=1) : ∀ n, ∑ g,power p n g=1 := by + intro n + induction n with + | zero => simp [power] + | succ n ih => rw [power,sum_conv,hp,ih,one_mul] + +lemma power_list_pos {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (l : List G) + (hl : ∀ g ∈ l, 0 < p g) : 0 < power p l.length l.prod := by + induction l with + | nil => simp [power] + | cons a l ih => + simpa only [List.length_cons,List.prod_cons,power] using + conv_pos_of hp (power_nonneg hp l.length) (hl a (by simp)) + (ih (fun g hg => hl g (by simp [hg]))) + +lemma power_pos_mono {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + {n m : ℕ} (hnm : n ≤ m) {g : G} (hg : 0 < power p n g) : 0 < power p m g := by + induction m, hnm using Nat.le_induction with + | base => exact hg + | succ m _ ih => + simpa only [one_mul,power] using conv_pos_of hp (power_nonneg hp m) h1 ih + +/-- Finite generation and a positive holding probability produce a genuine +finite-time positive minorant, rather than a spectral-gap assumption. -/ +theorem exists_positive_power {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (h1 : 0 < p 1) + (hgen : Subgroup.closure {g | 0 < p g}=⊤) : + ∃ n : ℕ, ∀ g, 0 < power p (2^n) g := by + have hx (g : G) : g ∈ Submonoid.closure {g | 0 < p g} := by + rw [←Subgroup.closure_toSubmonoid_of_finite,hgen] + trivial + choose l hl hprod using fun g => Submonoid.exists_list_of_mem_closure (hx g) + let n := Finset.univ.sup (fun g => (l g).length) + refine ⟨n,fun g => ?_⟩ + have hlen : (l g).length ≤ n := Finset.le_sup (f := fun g => (l g).length) (Finset.mem_univ g) + have hpow : n ≤ 2^n := Nat.le_of_lt (Nat.lt_two_pow_self) + have hpos := power_list_pos hp (l g) (hl g) + rw [hprod g] at hpos + exact power_pos_mono hp h1 (hlen.trans hpow) hpos + +structure Minorant (p : G → ℝ) where + exponent : ℕ + mass : ℝ + mass_pos : 0 < mass + mass_le_one : mass ≤ 1 + lower : ∀ g, mass/(Fintype.card G:ℝ) ≤ power p (2^exponent) g + +noncomputable def minorant {p : G → ℝ} (hp : ∀ g, 0 ≤ p g) (hsum : ∑ g,p g=1) + (h1 : 0 < p 1) (hgen : Subgroup.closure {g | 0 < p g}=⊤) : Minorant p := by + let n := Classical.choose (exists_positive_power hp h1 hgen) + have hn := Classical.choose_spec (exists_positive_power hp h1 hgen) + let a := Finset.univ.inf' Finset.univ_nonempty (power p (2^n)) + have ha : 0 < a := (Finset.lt_inf'_iff _).mpr (fun g _ => hn g) + have hag (g : G) : a ≤ power p (2^n) g := Finset.inf'_le _ (Finset.mem_univ g) + have hN : (0:ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos + have hsum' := Finset.sum_le_sum (s := Finset.univ) (fun g _ => hag g) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,sum_power hsum] at hsum' + refine ⟨n,(Fintype.card G:ℝ)*a,mul_pos hN ha,hsum',fun g => ?_⟩ + have he : (Fintype.card G:ℝ)*a/(Fintype.card G:ℝ)=a := by field_simp + rw [he] + exact hag g + +end CubeShuffle.FiniteConvolution +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def continuousRepresentation (ρ : Representation ℂ G V) : G →* (V →L[ℂ] V) where + toFun g := (ρ g).toContinuousLinearMap + map_one' := by ext v; simp + map_mul' g h := by ext v; simp + +omit [Fintype G] in +@[simp] lemma continuousRepresentation_apply (ρ : Representation ℂ G V) (g : G) (v : V) : + continuousRepresentation ρ g v=ρ g v := rfl + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_norm (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v : V) : + ‖ρ g v‖=‖v‖ := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),hρ,norm_eq_sqrt_re_inner (𝕜 := ℂ)] + +omit [Fintype G] in +lemma continuousRepresentation_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + ‖continuousRepresentation ρ g‖≤1 := by + apply ContinuousLinearMap.opNorm_le_bound _ zero_le_one + intro v + simp only [continuousRepresentation_apply,unitary_norm ρ hρ,one_mul,le_refl] + +omit [Fintype G] in +lemma continuousRepresentation_adjoint (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) : + (continuousRepresentation ρ g).adjoint=continuousRepresentation ρ g⁻¹ := by + ext w + apply ext_inner_left ℂ + intro v + rw [ContinuousLinearMap.adjoint_inner_right] + exact (unitary_inner_inv ρ hρ g v w).symm + +noncomputable def weightedOperator (ρ : Representation ℂ G V) (p : G → ℝ) : V →L[ℂ] V := + ∑ g, (p g : ℂ) • continuousRepresentation ρ g + +lemma weightedOperator_norm_le (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, 0≤p g) : ‖weightedOperator ρ p‖ ≤ ∑ g, p g := by + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro g _ + rw [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (hp g)] + exact mul_le_of_le_one_right (hp g) (continuousRepresentation_norm_le ρ hρ g) + +lemma weightedOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∀ g, p g⁻¹=p g) : IsSelfAdjoint (weightedOperator ρ p) := by + change (weightedOperator ρ p).adjoint=weightedOperator ρ p + unfold weightedOperator + rw [map_sum] + simp only [map_smulₛₗ,Complex.conj_ofReal,continuousRepresentation_adjoint ρ hρ] + apply Fintype.sum_equiv (Equiv.inv G) + intro g + simp [hp] + +noncomputable def uniformOperator (ρ : Representation ℂ G V) : V →L[ℂ] V := + weightedOperator ρ (fun _ => (Fintype.card G:ℝ)⁻¹) + +lemma uniformOperator_symmetric (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsSelfAdjoint (uniformOperator ρ) := weightedOperator_symmetric ρ hρ _ (fun _ => rfl) + +lemma uniformOperator_left (ρ : Representation ℂ G V) (g : G) : + continuousRepresentation ρ g * uniformOperator ρ=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,←map_mul] + exact Fintype.sum_equiv (Equiv.mulLeft g) _ _ (fun _ => rfl) + +lemma uniformOperator_right (ρ : Representation ℂ G V) (g : G) : + uniformOperator ρ * continuousRepresentation ρ g=uniformOperator ρ := by + unfold uniformOperator weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,←map_mul] + exact Fintype.sum_equiv (Equiv.mulRight g) _ _ (fun _ => rfl) + +lemma uniformOperator_idempotent (ρ : Representation ℂ G V) : + IsIdempotentElem (uniformOperator ρ) := by + change uniformOperator ρ * uniformOperator ρ=uniformOperator ρ + nth_rw 1 [uniformOperator,weightedOperator] + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,Finset.sum_const,Finset.card_univ, + ←Nat.cast_smul_eq_nsmul ℂ,smul_smul,Complex.ofReal_inv,Complex.ofReal_natCast] + rw [mul_inv_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma uniformOperator_projection (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) : + IsStarProjection (uniformOperator ρ) := + ⟨uniformOperator_idempotent ρ,uniformOperator_symmetric ρ hρ⟩ + +lemma weighted_uniform_left (ρ : Representation ℂ G V) (p : G → ℝ) : + weightedOperator ρ p * uniformOperator ρ=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.sum_mul] + simp only [smul_mul_assoc,uniformOperator_left,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +lemma weighted_uniform_right (ρ : Representation ℂ G V) (p : G → ℝ) : + uniformOperator ρ * weightedOperator ρ p=(∑ g,p g : ℝ) • uniformOperator ρ := by + unfold weightedOperator + rw [Finset.mul_sum] + simp only [mul_smul_comm,uniformOperator_right,←Finset.sum_smul,←Complex.ofReal_sum] + rfl + +/-- A finite Doeblin minorant gives a dimension-free contraction off invariants; +no irreducible decomposition or unproved spectral-gap hypothesis is used. -/ +theorem doeblin_off_invariants (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (ε : ℝ) + (hminor : ∀ g, ε/(Fintype.card G:ℝ)≤p g) : + ‖weightedOperator ρ p * (1-uniformOperator ρ)‖≤1-ε := by + let q : G → ℝ := fun g => p g-ε/(Fintype.card G:ℝ) + have hq : ∀ g, 0≤q g := fun g => sub_nonneg.mpr (hminor g) + have hcard : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hsum : ∑ g,q g=1-ε := by + simp only [q,Finset.sum_sub_distrib,hp,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + have he : weightedOperator ρ p=weightedOperator ρ q+(ε:ℂ) • uniformOperator ρ := by + simp only [uniformOperator,weightedOperator] + rw [Finset.smul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro g _ + simp only [q,Complex.ofReal_sub,Complex.ofReal_div,smul_smul,←add_smul, + Complex.ofReal_inv,Complex.ofReal_natCast] + congr 1 + field_simp + ring + have hz : uniformOperator ρ*(1-uniformOperator ρ)=0 := by + rw [mul_sub,mul_one,(uniformOperator_idempotent ρ).eq,sub_self] + rw [he,add_mul,smul_mul_assoc,hz,smul_zero,add_zero] + calc + _ ≤ ‖weightedOperator ρ q‖*‖1-uniformOperator ρ‖ := norm_mul_le _ _ + _ ≤ (1-ε)*1 := mul_le_mul (by rw [←hsum]; exact weightedOperator_norm_le ρ hρ q hq) + ((uniformOperator_projection ρ hρ).one_sub.norm_le _) (norm_nonneg _) + (by rw [←hsum]; exact Finset.sum_nonneg (fun g _ => hq g)) + _ = _ := mul_one _ + +end CubeShuffle.UnitaryFinite +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators Classical +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +lemma weightedOperator_conv (ρ : Representation ℂ G V) (p q : G → ℝ) : + weightedOperator ρ (FiniteConvolution.conv p q)=weightedOperator ρ p*weightedOperator ρ q := by + unfold weightedOperator FiniteConvolution.conv + simp only [Complex.ofReal_sum,Finset.sum_smul] + rw [Finset.sum_comm,Finset.sum_mul] + apply Finset.sum_congr rfl + intro h _ + rw [Finset.mul_sum] + simp only [smul_mul_assoc,mul_smul_comm,smul_smul,←map_mul] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp [Complex.ofReal_mul,mul_comm] + +lemma weightedOperator_power (ρ : Representation ℂ G V) (p : G → ℝ) (n : ℕ) : + weightedOperator ρ (FiniteConvolution.power p n)=(weightedOperator ρ p)^n := by + induction n with + | zero => simp [FiniteConvolution.power,weightedOperator] + | succ n ih => rw [FiniteConvolution.power,weightedOperator_conv,ih,pow_succ'] + +lemma off_invariants_pow (ρ : Representation ℂ G V) (p : G → ℝ) + (hp : ∑ g,p g=1) (n : ℕ) (hn : n≠0) : + (weightedOperator ρ p-uniformOperator ρ)^n= + (weightedOperator ρ p)^n*(1-uniformOperator ρ) := by + have hAP := weighted_uniform_left ρ p + have hPA := weighted_uniform_right ρ p + rw [hp,one_smul] at hAP hPA + have hc : Commute (weightedOperator ρ p) (1-uniformOperator ρ) := by + show _*_= _*_ + rw [mul_sub,sub_mul,mul_one,one_mul,hAP,hPA] + have he : weightedOperator ρ p-uniformOperator ρ= + weightedOperator ρ p*(1-uniformOperator ρ) := by rw [mul_sub,mul_one,hAP] + rw [he,hc.mul_pow,((uniformOperator_idempotent ρ).one_sub).pow_eq hn] + +/-- Explicit gap from the finite-time minorant; its value depends only on the +finite group law, not on the dimension of any represented space. -/ +noncomputable def minorantGap {p : G → ℝ} (c : FiniteConvolution.Minorant p) : ℝ := + 1-c.mass/(2*(2:ℝ)^c.exponent) + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_pos {p : G → ℝ} (c : FiniteConvolution.Minorant p) : 0 < minorantGap c := by + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + unfold minorantGap + linarith + +omit [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] in +lemma minorantGap_lt_one {p : G → ℝ} (c : FiniteConvolution.Minorant p) : minorantGap c < 1 := by + unfold minorantGap + exact sub_lt_self _ (div_pos c.mass_pos (by positivity)) + +/-- The one-block strict contraction follows from generation and the genuine +holding probability via Doeblin; this is uniform over ALL unitary representations. -/ +theorem norm_off_invariants_le_gap (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (p : G → ℝ) (hp : ∑ g,p g=1) (hsym : ∀ g,p g⁻¹=p g) + (c : FiniteConvolution.Minorant p) : + ‖weightedOperator ρ p-uniformOperator ρ‖ ≤ minorantGap c := by + have hself := (weightedOperator_symmetric ρ hρ p hsym).sub (uniformOperator_symmetric ρ hρ) + have hbound := doeblin_off_invariants ρ hρ (FiniteConvolution.power p (2^c.exponent)) + (FiniteConvolution.sum_power hp _) c.mass c.lower + rw [weightedOperator_power,←off_invariants_pow ρ p hp _ (by positivity), + hself.norm_pow_two_pow] at hbound + have hn : (1:ℝ) ≤ 2^c.exponent := one_le_pow₀ (by norm_num) + have hq : c.mass/(2*(2:ℝ)^c.exponent) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity)).mpr + nlinarith [c.mass_le_one] + have hbern := one_add_mul_le_pow + (a := -(c.mass/(2*(2:ℝ)^c.exponent))) (by linarith : (-2:ℝ) ≤ -(c.mass/(2*(2:ℝ)^c.exponent))) + (2^c.exponent) + have he : 1+(2^c.exponent:ℕ)*(-(c.mass/(2*(2:ℝ)^c.exponent)))=1-c.mass/2 := by + push_cast + field_simp + ring + rw [he,show 1+ -(c.mass/(2*(2:ℝ)^c.exponent))=minorantGap c by rfl] at hbern + by_contra h + have hlt : minorantGap c < ‖weightedOperator ρ p-uniformOperator ρ‖ := lt_of_not_ge h + have hpows := pow_lt_pow_left₀ hlt (minorantGap_pos c).le (by positivity : (2^c.exponent:ℕ)≠0) + linarith [c.mass_pos] + +end CubeShuffle.UnitaryFinite + +namespace CubeShuffle.FiniteAverage +open scoped BigOperators Classical +variable {I Ω A : Type*} [Fintype I] [DecidableEq I] [Fintype Ω] + [Ring A] [Algebra ℂ A] + +noncomputable def orderedProduct : MultilinearMap ℂ (fun _ : I => A) A := + MultilinearMap.domDomCongr (Fintype.equivFin I).symm + (MultilinearMap.mkPiAlgebraFin ℂ (Fintype.card I) A) + +lemma orderedProduct_eq (f : I → A) (hc : Pairwise fun i j => Commute (f i) (f j)) : + orderedProduct f=Finset.univ.noncommProd f (fun _ _ _ _ hij => hc hij) := by + unfold orderedProduct + rw [MultilinearMap.domDomCongr_apply,MultilinearMap.mkPiAlgebraFin_apply] + let l := List.ofFn (Fintype.equivFin I).symm + have hl : l.Nodup := List.nodup_ofFn.mpr (Fintype.equivFin I).symm.injective + have hu : l.toFinset=Finset.univ := by + ext i + simp only [List.mem_toFinset,List.mem_ofFn,Finset.mem_univ,iff_true,l] + exact (Fintype.equivFin I).symm.surjective i + have he := Finset.noncommProd_toFinset l f (by intro i hi j hj hij; exact hc hij) hl + rw [hu] at he + rw [he] + congr 1 + exact List.map_ofFn.symm + +lemma multilinear_average (F : MultilinearMap ℂ (fun _ : I => A) A) (x : I → Ω → A) : + F (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω)= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω,F (fun i => x i (ω i)) := by + rw [F.map_smul_univ,F.map_sum] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fun,Nat.cast_pow,inv_pow] + +/-- Exact independence factorization for commuting finite random factors. -/ +lemma ordered_average (x : I → Ω → A) + (hc : ∀ ω, Pairwise fun i j => Commute (x i (ω i)) (x j (ω j))) + (havg : Pairwise fun i j => Commute ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + ((Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x j ω)) : + (Finset.univ.noncommProd (fun i => (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,x i ω) + (fun _ _ _ _ hij => havg hij))= + (Fintype.card (I → Ω):ℂ)⁻¹ • ∑ ω : I → Ω, + Finset.univ.noncommProd (fun i => x i (ω i)) (fun _ _ _ _ hij => hc ω hij) := by + rw [←orderedProduct_eq _ havg,multilinear_average] + simp only [orderedProduct_eq _ (hc _)] + +end CubeShuffle.FiniteAverage + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Characters.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Characters.lean index 06a0aa30cccc8e4db7fdc12154256714255a6806..6b1f9ed68f9446ed4cccdba2dde3807b59317cfb 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Characters.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Characters.lean @@ -1,166 +1,166 @@ -import Mathlib - -namespace OAI - -namespace CubeShuffle.FiniteCharacters -open scoped BigOperators Classical - -section Group -variable {G : Type*} [Group G] [Fintype G] - -noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose -omit [Fintype G] in -lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := - (ConjClasses.exists_rep c).choose_spec - -variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := - fun c => ρ.character (classRep c) - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : - characterClass ρ (ConjClasses.mk g) = ρ.character g := by - have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) - obtain ⟨p,hp⟩ := isConj_iff.mp h - change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g - exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) - -noncomputable def characterDual (ρ : Representation ℂ G V) : - (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where - toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ - map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] - map_smul' a f := by - simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] - simp_rw [mul_assoc] - rw [←Finset.mul_sum] - ring - -lemma characterDual_characterClass (ρ : Representation ℂ G V) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : - characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by - let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by - exact_mod_cast (Nat.card_pos (α := G)).ne') - change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ - simp only [characterClass_mk] - exact Representation.char_orthonormal σ ρ - -end Group - -/-- A finite family of pairwise inequivalent irreducibles whose size is at -least the number of conjugacy classes is complete. This avoids assuming any -symmetric-group classification theorem. -/ -theorem complete_of_card_conjugacy_le - {G ι : Type*} [Group G] [Fintype G] [Fintype ι] - (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] - (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] - (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) - {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : - ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases hij : i=j - · subst j - simp only [ite_true] - exact ite_eq_left ⟨Representation.Equiv.refl _⟩ - · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij - exact (horth i j).trans (ite_eq_right hij) - · intro i - simpa using horth i i - have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - have hspan := hLI.span_eq_top_of_card_eq_finrank' heq - by_contra h - push Not at h - have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ - (characterDual σ).ker := by - apply Submodule.span_le.mpr - rintro f ⟨i,rfl⟩ - change characterDual σ (characterClass (ρ i)) = 0 - rw [characterDual_characterClass,ite_eq_right] - rintro ⟨T⟩ - exact (h i).false T.symm - rw [hspan] at hker - have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) - rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz - exact one_ne_zero hz - -end CubeShuffle.FiniteCharacters - -namespace CubeShuffle.FiniteCharacters -open Module -open scoped BigOperators Classical - -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) -include hneq hcard - -lemma character_expansion (f : ConjClasses G → ℂ) : - f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by - let : Fintype (ConjClasses G) := Fintype.ofFinite _ - have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by - rw [characterDual_characterClass] - by_cases h : i=j - · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] - · rw [ite_eq_right h,ite_eq_right (hneq i j h)] - have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by - apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) - · intro i j hij; exact (horth i j).trans (ite_eq_right hij) - · intro i; simpa using horth i i - have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by - apply Nat.le_antisymm hLI.fintype_card_le_finrank - simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, - smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard - let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) - have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ - have hd (i : ι) : b.coord i=characterDual (ρ i) := by - apply b.ext - intro j - rw [hb,horth] - simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] - split_ifs <;> simp_all - have h := b.sum_repr f - simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm - -/-- The sum of squared dimensions is derived from the actual character basis, -without a regular-module decomposition assumption. -/ -theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by - let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 - have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by - simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] - have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by - change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ - simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, - Representation.char_one,Nat.card_eq_fintype_card] - have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) - rw [hf,ite_eq_left rfl] at he - simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he - have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by - calc - _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * - (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - field_simp - _ = _ := by rw [←he,mul_one] - exact_mod_cast hs - -end CubeShuffle.FiniteCharacters - -end OAI +import Mathlib + +namespace OAI + +namespace CubeShuffle.FiniteCharacters +open scoped BigOperators Classical + +section Group +variable {G : Type*} [Group G] [Fintype G] + +noncomputable def classRep (c : ConjClasses G) : G := (ConjClasses.exists_rep c).choose +omit [Fintype G] in +lemma classRep_spec (c : ConjClasses G) : ConjClasses.mk (classRep c) = c := + (ConjClasses.exists_rep c).choose_spec + +variable {V : Type*} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +noncomputable def characterClass (ρ : Representation ℂ G V) : ConjClasses G → ℂ := + fun c => ρ.character (classRep c) + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma characterClass_mk (ρ : Representation ℂ G V) (g : G) : + characterClass ρ (ConjClasses.mk g) = ρ.character g := by + have h := ConjClasses.mk_eq_mk_iff_isConj.mp (classRep_spec (ConjClasses.mk g)) + obtain ⟨p,hp⟩ := isConj_iff.mp h + change ρ.character (classRep (ConjClasses.mk g)) = ρ.character g + exact (Representation.char_conj ρ _ p).symm.trans (congrArg ρ.character hp) + +noncomputable def characterDual (ρ : Representation ℂ G V) : + (ConjClasses G → ℂ) →ₗ[ℂ] ℂ where + toFun f := (Nat.card G : ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g) * ρ.character g⁻¹ + map_add' f h := by simp [Finset.sum_add_distrib,add_mul,mul_add] + map_smul' a f := by + simp only [Pi.smul_apply,smul_eq_mul,RingHom.id_apply] + simp_rw [mul_assoc] + rw [←Finset.mul_sum] + ring + +lemma characterDual_characterClass (ρ : Representation ℂ G V) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] : + characterDual ρ (characterClass σ) = if Nonempty (Representation.Equiv ρ σ) then 1 else 0 := by + let : Invertible (Nat.card G : ℂ) := invertibleOfNonzero (by + exact_mod_cast (Nat.card_pos (α := G)).ne') + change (Nat.card G : ℂ)⁻¹ * ∑ g, characterClass σ (ConjClasses.mk g) * ρ.character g⁻¹ = _ + simp only [characterClass_mk] + exact Representation.char_orthonormal σ ρ + +end Group + +/-- A finite family of pairwise inequivalent irreducibles whose size is at +least the number of conjugacy classes is complete. This avoids assuming any +symmetric-group classification theorem. -/ +theorem complete_of_card_conjugacy_le + {G ι : Type*} [Group G] [Fintype G] [Fintype ι] + (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] + (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] + (hneq : ∀ i j, i ≠ j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G) ≤ Fintype.card ι) + {W : Type*} [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (σ : Representation ℂ G W) [Representation.IsIrreducible σ] : + ∃ i, Nonempty (Representation.Equiv (ρ i) σ) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j)) = if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases hij : i=j + · subst j + simp only [ite_true] + exact ite_eq_left ⟨Representation.Equiv.refl _⟩ + · rw [ite_eq_right hij,ite_eq_right (hneq i j hij)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij + exact (horth i j).trans (ite_eq_right hij) + · intro i + simpa using horth i i + have heq : Fintype.card ι = Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + have hspan := hLI.span_eq_top_of_card_eq_finrank' heq + by_contra h + push Not at h + have hker : Submodule.span ℂ (Set.range (fun i => characterClass (ρ i))) ≤ + (characterDual σ).ker := by + apply Submodule.span_le.mpr + rintro f ⟨i,rfl⟩ + change characterDual σ (characterClass (ρ i)) = 0 + rw [characterDual_characterClass,ite_eq_right] + rintro ⟨T⟩ + exact (h i).false T.symm + rw [hspan] at hker + have hz : characterDual σ (characterClass σ) = 0 := hker (show characterClass σ ∈ ⊤ from trivial) + rw [characterDual_characterClass,ite_eq_left ⟨Representation.Equiv.refl σ⟩] at hz + exact one_ne_zero hz + +end CubeShuffle.FiniteCharacters + +namespace CubeShuffle.FiniteCharacters +open Module +open scoped BigOperators Classical + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, AddCommGroup (V i)] [∀ i, Module ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) +include hneq hcard + +lemma character_expansion (f : ConjClasses G → ℂ) : + f=∑ i, characterDual (ρ i) f • characterClass (ρ i) := by + let : Fintype (ConjClasses G) := Fintype.ofFinite _ + have horth (i j : ι) : characterDual (ρ i) (characterClass (ρ j))=if i=j then 1 else 0 := by + rw [characterDual_characterClass] + by_cases h : i=j + · subst j; rw [ite_eq_left ⟨Representation.Equiv.refl _⟩,ite_eq_left rfl] + · rw [ite_eq_right h,ite_eq_right (hneq i j h)] + have hLI : LinearIndependent ℂ (fun i => characterClass (ρ i)) := by + apply LinearIndependent.of_pairwise_dual_eq_zero_one _ (fun i => characterDual (ρ i)) + · intro i j hij; exact (horth i j).trans (ite_eq_right hij) + · intro i; simpa using horth i i + have heq : Fintype.card ι=Module.finrank ℂ (ConjClasses G → ℂ) := by + apply Nat.le_antisymm hLI.fintype_card_le_finrank + simpa only [Module.finrank_pi,Module.finrank_self,Finset.sum_const,Finset.card_univ, + smul_eq_mul,mul_one,Nat.card_eq_fintype_card] using hcard + let b := Basis.mk hLI (by rw [hLI.span_eq_top_of_card_eq_finrank' heq]) + have hb (i : ι) : b i=characterClass (ρ i) := Basis.mk_apply _ _ _ + have hd (i : ι) : b.coord i=characterDual (ρ i) := by + apply b.ext + intro j + rw [hb,horth] + simp only [←hb,Basis.coord_apply,Basis.repr_self,Finsupp.single_apply] + split_ifs <;> simp_all + have h := b.sum_repr f + simpa only [hb,show ∀ i,b.repr f i=characterDual (ρ i) f from fun i => congrArg (fun l => l f) (hd i)] using h.symm + +/-- The sum of squared dimensions is derived from the actual character basis, +without a regular-module decomposition assumption. -/ +theorem sum_dimension_sq : ∑ i, (Module.finrank ℂ (V i))^2=Fintype.card G := by + let f : ConjClasses G → ℂ := fun c => if c=ConjClasses.mk (1:G) then 1 else 0 + have hf (g : G) : f (ConjClasses.mk g)=if g=1 then 1 else 0 := by + simp only [f,ConjClasses.mk_eq_mk_iff_isConj,isConj_one_left] + have hd (i : ι) : characterDual (ρ i) f=(Fintype.card G:ℂ)⁻¹*(Module.finrank ℂ (V i):ℂ) := by + change (Nat.card G:ℂ)⁻¹ * ∑ g, f (ConjClasses.mk g)*(ρ i).character g⁻¹=_ + simp only [hf,ite_mul,one_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,inv_one, + Representation.char_one,Nat.card_eq_fintype_card] + have he := congrFun (character_expansion V ρ hneq hcard f) (ConjClasses.mk (1:G)) + rw [hf,ite_eq_left rfl] at he + simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul,hd,characterClass_mk,Representation.char_one] at he + have hN : (Fintype.card G:ℂ)≠0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (∑ i,(Module.finrank ℂ (V i):ℂ)^2)=(Fintype.card G:ℂ) := by + calc + _ = (Fintype.card G:ℂ) * ∑ i,(Fintype.card G:ℂ)⁻¹ * + (Module.finrank ℂ (V i):ℂ)*(Module.finrank ℂ (V i):ℂ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + field_simp + _ = _ := by rw [←he,mul_one] + exact_mod_cast hs + +end CubeShuffle.FiniteCharacters + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Coefficients.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Coefficients.lean index b2dc97472063274d0f6040488579aa0be6b27424..638056494edd6bb5d10608fce3c4717a648d402f 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Coefficients.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Coefficients.lean @@ -1,216 +1,216 @@ -import Mathlib - -namespace OAI - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -def IsUnitary (ρ : Representation ℂ G V) : Prop := - ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : - inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by - have h := hρ g v (ρ g⁻¹ w) - have he : ρ g (ρ g⁻¹ w) = w := by - change (ρ g * ρ g⁻¹) w = w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [he] at h - exact h.symm - -noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where - toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) - isIntertwining' h := by - ext v - simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] - apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) - intro g - simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] - have hh (w : W) : σ h (σ h⁻¹ w)=w := by - change (σ h*σ h⁻¹) w=w - rw [←map_mul,mul_inv_cancel,map_one] - rfl - rw [hh] - -omit [FiniteDimensional ℂ V] in -lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : - LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = - (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by - change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ - rw [map_sum] - have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by - rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] - simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - -lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (A : Module.End ℂ V) : - ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ - c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by - obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) - have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by - rw [←hc] - rfl - refine ⟨c,he,?_⟩ - rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] - -/-- Schur orthogonality in an actual unitary irreducible, obtained by -averaging a rank-one operator and applying the proved algebraic Schur lemma. -/ -theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (u v w z : V) : - (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = - (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by - obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap - rw [InnerProductSpace.trace_rankOne] at htrace - have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc - change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ - simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ - have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by - simpa only [mul_comm] using happ - rw [hsum] - calc - _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring - _ = _ := by rw [htrace] - -end CubeShuffle.UnitaryFinite -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -section Action -variable {G X : Type*} [Group G] [Fintype G] [Fintype X] - (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) - -noncomputable def representative (x : X) : G := Classical.choose (ha x) - -omit [Fintype G] [Fintype X] in -lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := - Classical.choose_spec (ha x) - -include ha in -lemma orbit_sum (F : X → ℂ) : - (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by - have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by - obtain ⟨t,rfl⟩ := ha x - symm - apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) - intro g - simp - calc - _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] - _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm - _ = ∑ g : G, ∑ x : X, F x := by - apply Finset.sum_congr rfl - intro g _ - exact Equiv.sum_comp (a g) F - _ = _ := by simp - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) - -def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w - -noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := - WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : - coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by - let r := representative a x₀ ha (a g x₀) - have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ - have hs : a (g⁻¹*r) x₀=x₀ := by - simp only [map_mul,Equiv.Perm.mul_apply] - rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] - rfl - have he := congrArg (ρ g) (hw (g⁻¹*r) hs) - have hh : ρ r w=ρ g w := by - simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, - mul_inv_cancel_left] using he - change inner ℂ (ρ r w) v= _ - rw [hh] - -lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = - (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by - have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) - simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs - simp only [←starRingEnd_apply,inner_conj_symm] at hs - simp only [starRingEnd_apply] at hs - have ho := coefficient_orthogonality ρ hρ v w z t - have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - apply mul_left_cancel₀ hcard - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,starRingEnd_apply] - have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = - ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by - apply Finset.sum_congr rfl - intro x _ - ring - rw [hsum] - calc - _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, - star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring - _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, - inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring - _ = _ := by rw [ho]; ring - -omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in -lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) - (v : V) (g : G) (x : X) : - coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by - obtain ⟨r,rfl⟩ := ha x - rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, - coefficient_at a x₀ ha ρ w hw] - simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] - -noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := - (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v - -lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : - inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = - inner ℂ z w*inner ℂ v t := by - let : Nonempty X := ⟨x₀⟩ - have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero - have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = - (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by - rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] - simp - simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] - simp only [Complex.conj_ofReal] - rw [←mul_assoc,←pow_two,hs] - have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t - field_simp - simpa only [mul_assoc] using hi - -lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) - (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : - Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by - rw [orthonormal_iff_ite] at hw ⊢ - intro i j - rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, - inner_self_eq_norm_sq_to_K,hv] - simp [eq_comm] - -lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) - (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : - ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by - have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v - rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he - simp only [inner_self_eq_norm_sq_to_K] at he - norm_num at he - have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he - nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] - -end Action -end CubeShuffle.UnitaryFinite - -end OAI +import Mathlib + +namespace OAI + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +def IsUnitary (ρ : Representation ℂ G V) : Prop := + ∀ g v w, inner ℂ (ρ g v) (ρ g w) = inner ℂ v w + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_inner_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (g : G) (v w : V) : + inner ℂ v (ρ g⁻¹ w) = inner ℂ (ρ g v) w := by + have h := hρ g v (ρ g⁻¹ w) + have he : ρ g (ρ g⁻¹ w) = w := by + change (ρ g * ρ g⁻¹) w = w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [he] at h + exact h.symm + +noncomputable def averageMap (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + (A : V →ₗ[ℂ] W) : Representation.IntertwiningMap ρ σ where + toLinearMap := ∑ g, (σ g).comp (A.comp (ρ g⁻¹)) + isIntertwining' h := by + ext v + simp only [LinearMap.comp_apply,LinearMap.sum_apply,map_sum] + apply Fintype.sum_equiv (Equiv.mulLeft h⁻¹) + intro g + simp only [Equiv.coe_mulLeft,mul_inv_rev,inv_inv,map_mul,Module.End.mul_apply] + have hh (w : W) : σ h (σ h⁻¹ w)=w := by + change (σ h*σ h⁻¹) w=w + rw [←map_mul,mul_inv_cancel,map_one] + rfl + rw [hh] + +omit [FiniteDimensional ℂ V] in +lemma averageMap_self_trace (ρ : Representation ℂ G V) (A : Module.End ℂ V) : + LinearMap.trace ℂ V (averageMap ρ ρ A).toLinearMap = + (Fintype.card G:ℂ) * LinearMap.trace ℂ V A := by + change LinearMap.trace ℂ V (∑ g, ρ g * A * ρ g⁻¹) = _ + rw [map_sum] + have hj (g : G) : LinearMap.trace ℂ V (ρ g*A*ρ g⁻¹) = LinearMap.trace ℂ V A := by + rw [LinearMap.trace_mul_cycle,←map_mul,inv_mul_cancel,map_one,one_mul] + simp only [hj,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + +lemma averageMap_scalar (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (A : Module.End ℂ V) : + ∃ c : ℂ, (averageMap ρ ρ A).toLinearMap = c • LinearMap.id ∧ + c * (Module.finrank ℂ V:ℂ) = (Fintype.card G:ℂ)*LinearMap.trace ℂ V A := by + obtain ⟨c,hc⟩ := (Representation.IsIrreducible.algebraMap_intertwiningMap_bijective_of_isAlgClosed (ρ := ρ)).surjective (averageMap ρ ρ A) + have he : (averageMap ρ ρ A).toLinearMap = c • LinearMap.id := by + rw [←hc] + rfl + refine ⟨c,he,?_⟩ + rw [←averageMap_self_trace ρ A,he,map_smul,LinearMap.trace_id,smul_eq_mul] + +/-- Schur orthogonality in an actual unitary irreducible, obtained by +averaging a rank-one operator and applying the proved algebraic Schur lemma. -/ +theorem coefficient_orthogonality (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (u v w z : V) : + (Module.finrank ℂ V:ℂ) * ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = + (Fintype.card G:ℂ) * inner ℂ w v * inner ℂ u z := by + obtain ⟨c,hc,htrace⟩ := averageMap_scalar ρ (InnerProductSpace.rankOne ℂ v w).toLinearMap + rw [InnerProductSpace.trace_rankOne] at htrace + have happ := congrArg (fun A : Module.End ℂ V => inner ℂ u (A z)) hc + change inner ℂ u ((∑ g, ρ g * (InnerProductSpace.rankOne ℂ v w).toLinearMap * ρ g⁻¹) z) = _ at happ + simp only [LinearMap.sum_apply,Module.End.mul_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,LinearMap.smul_apply,LinearMap.id_apply] at happ + have hsum : ∑ g, inner ℂ u (ρ g v) * inner ℂ (ρ g w) z = c * inner ℂ u z := by + simpa only [mul_comm] using happ + rw [hsum] + calc + _ = (c*(Module.finrank ℂ V:ℂ))*inner ℂ u z := by ring + _ = _ := by rw [htrace] + +end CubeShuffle.UnitaryFinite +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +section Action +variable {G X : Type*} [Group G] [Fintype G] [Fintype X] + (a : G →* Equiv.Perm X) (x₀ : X) (ha : ∀ x, ∃ g, a g x₀=x) + +noncomputable def representative (x : X) : G := Classical.choose (ha x) + +omit [Fintype G] [Fintype X] in +lemma representative_apply (x : X) : a (representative a x₀ ha x) x₀=x := + Classical.choose_spec (ha x) + +include ha in +lemma orbit_sum (F : X → ℂ) : + (Fintype.card X:ℂ)*∑ g, F (a g x₀) = (Fintype.card G:ℂ)*∑ x, F x := by + have ht (x : X) : ∑ g, F (a g x)=∑ g, F (a g x₀) := by + obtain ⟨t,rfl⟩ := ha x + symm + apply Fintype.sum_equiv (Equiv.mulRight t⁻¹) + intro g + simp + calc + _ = ∑ x : X, ∑ g : G, F (a g x) := by simp only [ht,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + _ = ∑ g : G, ∑ x : X, F (a g x) := Finset.sum_comm + _ = ∑ g : G, ∑ x : X, F x := by + apply Finset.sum_congr rfl + intro g _ + exact Equiv.sum_comp (a g) F + _ = _ := by simp + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + [FiniteDimensional ℂ V] (ρ : Representation ℂ G V) + +def IsFixed (w : V) : Prop := ∀ g, a g x₀=x₀ → ρ g w=w + +noncomputable def coefficient (w v : V) : EuclideanSpace ℂ X := + WithLp.toLp 2 (fun x => inner ℂ (ρ (representative a x₀ ha x) w) v) + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_at (w : V) (hw : IsFixed a x₀ ρ w) (v : V) (g : G) : + coefficient a x₀ ha ρ w v (a g x₀) = inner ℂ (ρ g w) v := by + let r := representative a x₀ ha (a g x₀) + have hr : a r x₀=a g x₀ := representative_apply a x₀ ha _ + have hs : a (g⁻¹*r) x₀=x₀ := by + simp only [map_mul,Equiv.Perm.mul_apply] + rw [hr,←Equiv.Perm.mul_apply,←map_mul,inv_mul_cancel,map_one] + rfl + have he := congrArg (ρ g) (hw (g⁻¹*r) hs) + have hh : ρ r w=ρ g w := by + simpa only [map_mul,Module.End.mul_apply,←Module.End.mul_apply,←map_mul, + mul_inv_cancel_left] using he + change inner ℂ (ρ r w) v= _ + rw [hh] + +lemma coefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + (Module.finrank ℂ V:ℂ)*inner ℂ (coefficient a x₀ ha ρ w v) (coefficient a x₀ ha ρ z t) = + (Fintype.card X:ℂ)*inner ℂ z w*inner ℂ v t := by + have hs := orbit_sum a x₀ ha (fun x => star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) + simp only [coefficient_at a x₀ ha ρ w hw,coefficient_at a x₀ ha ρ z hz] at hs + simp only [←starRingEnd_apply,inner_conj_symm] at hs + simp only [starRingEnd_apply] at hs + have ho := coefficient_orthogonality ρ hρ v w z t + have hcard : (Fintype.card G:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + apply mul_left_cancel₀ hcard + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,starRingEnd_apply] + have hsum : ∑ x, coefficient a x₀ ha ρ z t x * star (coefficient a x₀ ha ρ w v x) = + ∑ x, star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x := by + apply Finset.sum_congr rfl + intro x _ + ring + rw [hsum] + calc + _ = (Module.finrank ℂ V:ℂ)*((Fintype.card G:ℂ)*∑ x, + star (coefficient a x₀ ha ρ w v x)*coefficient a x₀ ha ρ z t x) := by ring + _ = (Fintype.card X:ℂ)*((Module.finrank ℂ V:ℂ)*∑ g, + inner ℂ v (ρ g w)*inner ℂ (ρ g z) t) := by rw [←hs]; ring + _ = _ := by rw [ho]; ring + +omit [Fintype G] [Fintype X] [FiniteDimensional ℂ V] in +lemma coefficient_action (hρ : IsUnitary ρ) (w : V) (hw : IsFixed a x₀ ρ w) + (v : V) (g : G) (x : X) : + coefficient a x₀ ha ρ w v (a g x) = coefficient a x₀ ha ρ w (ρ g⁻¹ v) x := by + obtain ⟨r,rfl⟩ := ha x + rw [←Equiv.Perm.mul_apply,←map_mul,coefficient_at a x₀ ha ρ w hw, + coefficient_at a x₀ ha ρ w hw] + simp only [map_mul,Module.End.mul_apply,unitary_inner_inv ρ hρ] + +noncomputable def normalizedCoefficient (w v : V) : EuclideanSpace ℂ X := + (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ) • coefficient a x₀ ha ρ w v + +lemma normalizedCoefficient_inner [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w z : V) (hw : IsFixed a x₀ ρ w) (hz : IsFixed a x₀ ρ z) (v t : V) : + inner ℂ (normalizedCoefficient a x₀ ha ρ w v) (normalizedCoefficient a x₀ ha ρ z t) = + inner ℂ z w*inner ℂ v t := by + let : Nonempty X := ⟨x₀⟩ + have hX : (Fintype.card X:ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hs : (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card X:ℝ)) : ℂ)^2 = + (Module.finrank ℂ V:ℂ)/(Fintype.card X:ℂ) := by + rw [←Complex.ofReal_pow,Real.sq_sqrt (by positivity)] + simp + simp only [normalizedCoefficient,inner_smul_left,inner_smul_right] + simp only [Complex.conj_ofReal] + rw [←mul_assoc,←pow_two,hs] + have hi := coefficient_inner a x₀ ha ρ hρ w z hw hz v t + field_simp + simpa only [mul_assoc] using hi + +lemma normalizedCoefficient_orthonormal [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + {I : Type*} (w : I → V) (hw : Orthonormal ℂ w) + (hfix : ∀ i, IsFixed a x₀ ρ (w i)) (v : V) (hv : ‖v‖=1) : + Orthonormal ℂ (fun i => normalizedCoefficient a x₀ ha ρ (w i) v) := by + rw [orthonormal_iff_ite] at hw ⊢ + intro i j + rw [normalizedCoefficient_inner a x₀ ha ρ hρ _ _ (hfix i) (hfix j),hw, + inner_self_eq_norm_sq_to_K,hv] + simp [eq_comm] + +lemma normalizedCoefficient_norm [Representation.IsIrreducible ρ] (hρ : IsUnitary ρ) + (w : V) (hw : IsFixed a x₀ ρ w) (hn : ‖w‖=1) (v : V) : + ‖normalizedCoefficient a x₀ ha ρ w v‖=‖v‖ := by + have he := normalizedCoefficient_inner a x₀ ha ρ hρ w w hw hw v v + rw [inner_self_eq_norm_sq_to_K,inner_self_eq_norm_sq_to_K,hn] at he + simp only [inner_self_eq_norm_sq_to_K] at he + norm_num at he + have hs : ‖normalizedCoefficient a x₀ ha ρ w v‖^2=‖v‖^2 := by exact_mod_cast he + nlinarith [norm_nonneg (normalizedCoefficient a x₀ ha ρ w v),norm_nonneg v] + +end Action +end CubeShuffle.UnitaryFinite + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/CommutingBlocks.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/CommutingBlocks.lean index 1c011df242a68cf70e45895c2216e0bba271b0f5..166b4afc3f46cc0728a4a051b5f1c4cf382b09f3 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/CommutingBlocks.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/CommutingBlocks.lean @@ -1,404 +1,404 @@ -import Mathlib - -namespace OAI - -namespace CubeShuffle.CommutingBlocks -open scoped BigOperators Classical -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable {ι : Type*} [Fintype ι] - -omit [CompleteSpace V] in -lemma orthogonal_sum_norm_sq (v : ι → V) (hv : ∀ i j, i≠j → inner ℂ (v i) (v j)=0) : - ‖∑ i,v i‖^2=∑ i,‖v i‖^2 := by - rw [norm_sq_eq_re_inner (𝕜 := ℂ),sum_inner] - simp only [inner_sum,map_sum] - apply Finset.sum_congr rfl - intro i _ - rw [Finset.sum_eq_single i] - · exact (norm_sq_eq_re_inner (𝕜 := ℂ) (v i)).symm - · intro j _ hji - rw [hv i j hji.symm] - rfl - · simp - -lemma projection_inner_zero (P Q : V →L[ℂ] V) (hP : IsStarProjection P) - (hPQ : P*Q=0) (v w : V) : inner ℂ (P v) (Q w)=0 := by - rw [←ContinuousLinearMap.adjoint_inner_right] - change inner ℂ v ((star P*Q) w)=0 - rw [hP.isSelfAdjoint.star_eq,hPQ] - simp - -lemma projection_sandwich_norm (P B : V →L[ℂ] V) (hP : IsStarProjection P) : - ‖B.adjoint*P*B‖=‖P*B‖^2 := by - have he : star (P*B)*(P*B)=B.adjoint*P*B := by - rw [star_mul,hP.isSelfAdjoint.star_eq] - change B.adjoint*P*(P*B)=_ - rw [←mul_assoc,mul_assoc B.adjoint P P,hP.isIdempotentElem.eq] - rw [←he,CStarRing.norm_star_mul_self] - ring - -/-- Orthogonal sector norm bound, without tensor-product classification. -/ -theorem resolution_norm_bound (P : ι → V →L[ℂ] V) - (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) - (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) - (c : ℝ) (hc : 0≤c) (hbound : ∀ i, ‖A*P i‖≤c) : ‖A‖≤c := by - apply ContinuousLinearMap.opNorm_le_bound _ hc - intro v - have hsplit (w : V) : ∑ i,P i w=w := by - rw [←sum_apply,hsum] - rfl - have hp := orthogonal_sum_norm_sq (fun i => P i v) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) - rw [hsplit] at hp - have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) - (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) - rw [hsplit] at ha - have he (i : ι) : P i (A v)=(A*P i) (P i v) := by - change (P i*A) v=(A*P i*P i) v - rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] - have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by - rw [he] - exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) - have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => - pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) - simp_rw [mul_pow] at hsq - rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq - exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq - -/-- Sandwich comparison for one orthogonal sector subordinate to a coarser -invariant projection. This proves the needed PSD comparison at the norm level. -/ -theorem sector_sandwich_le (T P A B : V →L[ℂ] V) - (hT : IsStarProjection T) (hP : IsStarProjection P) - (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : - ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by - have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by - change _=star (T*B)*A*(T*B) - rw [star_mul,hT.isSelfAdjoint.star_eq] - change _=B.adjoint*T*A*(T*B) - rw [mul_assoc B.adjoint T A,←hcomm.eq] - simp only [mul_assoc] - rw [←mul_assoc T T B,hT.isIdempotentElem.eq] - have hTB : ‖T*B‖≤‖P*B‖ := by - have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] - rw [he] - exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) - rw [he,projection_sandwich_norm P B hP] - calc - _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] - _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 - -omit [CompleteSpace V] [Fintype ι] in -lemma resolution_commute (P : ι → V →L[ℂ] V) - (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by - by_cases hij : i=j - · subst j; exact Commute.refl _ - · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm - -omit [Fintype ι] in -lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : - (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by - rw [Finset.sum_mul] - have he (i : ι) : P i*P j=if i=j then P j else 0 := by - split_ifs with h - · subst i; exact (hP j).isIdempotentElem.eq - · exact horth i j h - simp only [he,Finset.sum_ite_eq'] - -lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) - (hP : ∀ i, IsStarProjection (P i)) - (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) - (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : - ‖A*(∑ i∈S,P i)‖≤c := by - apply resolution_norm_bound P hP horth hsum _ _ c hc - · intro i - rw [mul_assoc,resolution_sum_mul P hP horth] - split_ifs with hi - · exact hbound i hi - · simp [hc] - · intro i - exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) - -/-- Exceptional-sector comparison, faithful to FAC's positive sandwich -argument but not requiring tensor-product representation machinery. -/ -theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) - (hT : ∀ i, IsStarProjection (T i)) - (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) - (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) - (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) - (hA : ‖A‖≤1) (hB : ‖B‖≤1) - (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : - ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by - have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm - Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) - have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by - rw [Finset.sum_compl_add_sum,hsum] - have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ - ∑ i∈S,B.adjoint*A*T i*B := by - rw [←Finset.sum_mul,←Finset.mul_sum] - rw [←add_mul] - simp only [mul_assoc] - rw [←mul_add,←mul_add,hsplit] - simp only [mul_one,mul_assoc] - rw [he] - apply (norm_add_le _ _).trans - apply add_le_add - · calc - _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := - (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) - _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) - hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) - _ = c := by ring - · apply (norm_sum_le _ _).trans - exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA - -section Sectors -variable [DecidableEq ι] -variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) - -noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := - if i∈E then 1-P i else P i - -include hcomm -omit [CompleteSpace V] [Fintype ι] in -lemma choice_commute (E F : Finset ι) (i j : ι) : - Commute (choice P E i) (choice P F j) := by - unfold choice - split_ifs - · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) - · exact (Commute.one_left _).sub_left (hcomm i j) - · exact (Commute.one_right _).sub_right (hcomm i j) - · exact hcomm i j - -noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := - s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : - sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by - exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : - sector P hcomm s E=sector P hcomm s F := by - apply Finset.noncommProd_congr rfl - intro i hi - simp only [choice,h i hi] - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_factor_commute (s E F : Finset ι) (i : ι) : - Commute (choice P E i) (sector P hcomm s F) := - Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) - -omit [Fintype ι] in -lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : - IsStarProjection (sector P hcomm s E) := by - induction s using Finset.induction_on with - | empty => exact IsStarProjection.one _ - | @insert a s ha ih => - rw [sector_insert P hcomm s E a ha] - have hc : IsStarProjection (choice P E a) := by - unfold choice - split_ifs - · exact (hP a).one_sub - · exact hP a - exact hc.mul ih (sector_factor_commute P hcomm s E E a) - -omit [CompleteSpace V] [Fintype ι] in -lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by - induction s using Finset.induction_on with - | empty => - simp only [Finset.powerset_empty,Finset.sum_singleton] - exact Finset.noncommProd_empty _ _ - | @insert a s ha ih => - rw [Finset.sum_powerset_insert ha] - have h₁ (E : Finset ι) (hE : E∈s.powerset) : - sector P hcomm (insert a s) E=P a*sector P hcomm s E := by - rw [sector_insert P hcomm s E a ha] - congr 1 - exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) - have h₂ (E : Finset ι) (_hE : E∈s.powerset) : - sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by - rw [sector_insert P hcomm s (insert a E) a ha] - simp only [choice,Finset.mem_insert_self,↓reduceIte] - congr 1 - apply sector_congr - intro i hi - simp [ne_of_mem_of_not_mem hi ha] - rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, - ←Finset.mul_sum,←Finset.mul_sum,ih] - simp - -omit [Fintype ι] in -lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) - (hP : ∀ i, IsStarProjection (P i)) : - choice P E i*sector P hcomm s E=sector P hcomm s E := by - have hc : IsIdempotentElem (choice P E i) := by - unfold choice - split_ifs - · exact (hP i).one_sub.isIdempotentElem - · exact (hP i).isIdempotentElem - have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) - (fun i _ j _ _ => choice_commute P hcomm E E i j) - change choice P E i*sector P hcomm s E=sector P hcomm s E - change _=sector P hcomm s E at hsplit - nth_rw 1 [←hsplit] - rw [←mul_assoc,hc.eq,hsplit] - -omit [Fintype ι] in -lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) - (hP : ∀ i, IsStarProjection (P i)) : - sector P hcomm s E*sector P hcomm s F=0 := by - have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by - by_contra h - push Not at h - exact hEF (Finset.ext fun i => by - by_cases hi : i∈s - · exact h i hi - · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) - obtain ⟨i,hi,hdiff⟩ := hdiff - have hz : choice P E i*choice P F i=0 := by - by_cases he : i∈E <;> by_cases hf : i∈F - · exact (hdiff (iff_of_true he hf)).elim - · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self - · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self - · exact (hdiff (iff_of_false he hf)).elim - have hEi := sector_absorb_factor P hcomm s E i hi hP - have hFi := sector_absorb_factor P hcomm s F i hi hP - calc - _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by - simp only [mul_assoc] - rw [hFi] - rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] - _ = 0 := by rw [hz,mul_zero,zero_mul] - -noncomputable def blockProduct (A : ι → V →L[ℂ] V) - (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := - s.noncommProd A (fun i _ j _ _ => hA i j) - -omit hcomm [Fintype ι] in -lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by - induction s using Finset.induction_on with - | empty => exact ContinuousLinearMap.norm_id_le - | @insert a s ha ih => - have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,Finset.prod_insert ha] - exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) - -noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := - blockProduct A hA Finset.univ - -omit hcomm in -lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := - (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) - -omit [CompleteSpace V] in -lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : - Commute (blocks A hA) (sector P hcomm Finset.univ E) := by - unfold blocks blockProduct - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm - intro i _ - unfold sector - apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm - intro j _ - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - -lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : - ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by - have hAC (i j : ι) : Commute (A i) (choice P E j) := by - unfold choice - split_ifs - · exact (Commute.one_right _).sub_right (hAP i j) - · exact hAP i j - have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) - (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) - (fun i _ j _ _ => (hAC j i).symm) - change _=blocks A hA*sector P hcomm Finset.univ E at hprod - rw [←hprod] - have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := - ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) - apply (norm_noncommProd_le _ hc Finset.univ).trans - calc - _ ≤ ∏ i : ι, if i∈E then θ else 1 := by - apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) - intro i _ - dsimp only [Pi.mul_apply] - unfold choice - split_ifs with hi - · exact hgap i - · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) - _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] - -noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := - Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) - -lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - IsStarProjection (coarse P hcomm E) := by - have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by - apply Finset.noncommProd_congr rfl - intro i _ - simp [choice] - rw [he] - exact sector_projection P hcomm hP _ _ - -lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : - sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by - have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by - have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP - rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h - simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h - have hp (s : Finset ι) (hs : ∀ i∈s, - sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : - sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by - induction s using Finset.induction_on with - | empty => exact mul_one _ - | @insert a s ha ih => - have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := - Finset.noncommProd_insert_of_notMem _ _ _ _ ha - rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] - exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) - exact hp Eᶜ hpi - -/-- Actual commuting-block exceptional estimate, with no tensor irreducible -hypothesis. The local gaps are for each represented finite block. -/ -theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) - (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) - (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) - (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) - (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : - ‖B.adjoint*blocks A hA*B‖≤θ^n+ - ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) - (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) - hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) - (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) - (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card P i v) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) v v) + rw [hsplit] at hp + have ha := orthogonal_sum_norm_sq (fun i => P i (A v)) + (fun i j hij => projection_inner_zero _ _ (hP i) (horth i j hij) (A v) (A v)) + rw [hsplit] at ha + have he (i : ι) : P i (A v)=(A*P i) (P i v) := by + change (P i*A) v=(A*P i*P i) v + rw [mul_assoc,(hP i).isIdempotentElem.eq,(hcomm i).eq] + have hh (i : ι) : ‖P i (A v)‖≤c*‖P i v‖ := by + rw [he] + exact ((A*P i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hbound i) (norm_nonneg _)) + have hsq := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + pow_le_pow_left₀ (norm_nonneg _) (hh i) 2) + simp_rw [mul_pow] at hsq + rw [←Finset.mul_sum,←hp,←ha,←mul_pow] at hsq + exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg hc (norm_nonneg _))).mp hsq + +/-- Sandwich comparison for one orthogonal sector subordinate to a coarser +invariant projection. This proves the needed PSD comparison at the norm level. -/ +theorem sector_sandwich_le (T P A B : V →L[ℂ] V) + (hT : IsStarProjection T) (hP : IsStarProjection P) + (hTP : T*P=T) (hcomm : Commute A T) (hA : ‖A‖≤1) : + ‖B.adjoint*A*T*B‖≤‖B.adjoint*P*B‖ := by + have he : B.adjoint*A*T*B=(T*B).adjoint*A*(T*B) := by + change _=star (T*B)*A*(T*B) + rw [star_mul,hT.isSelfAdjoint.star_eq] + change _=B.adjoint*T*A*(T*B) + rw [mul_assoc B.adjoint T A,←hcomm.eq] + simp only [mul_assoc] + rw [←mul_assoc T T B,hT.isIdempotentElem.eq] + have hTB : ‖T*B‖≤‖P*B‖ := by + have he : T*B=T*(P*B) := by rw [←mul_assoc,hTP] + rw [he] + exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_right (hT.norm_le _) (norm_nonneg _)).trans_eq (one_mul _)) + rw [he,projection_sandwich_norm P B hP] + calc + _ ≤ ‖(T*B).adjoint‖*‖A‖*‖T*B‖ := (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ ‖T*B‖^2 := by rw [ContinuousLinearMap.adjoint.norm_map]; nlinarith [norm_nonneg (T*B)] + _ ≤ _ := pow_le_pow_left₀ (norm_nonneg _) hTB 2 + +omit [CompleteSpace V] [Fintype ι] in +lemma resolution_commute (P : ι → V →L[ℂ] V) + (horth : ∀ i j, i≠j → P i*P j=0) (i j : ι) : Commute (P i) (P j) := by + by_cases hij : i=j + · subst j; exact Commute.refl _ + · exact (horth i j hij).trans (horth j i (Ne.symm hij)).symm + +omit [Fintype ι] in +lemma resolution_sum_mul (P : ι → V →L[ℂ] V) (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (S : Finset ι) (j : ι) : + (∑ i∈S,P i)*P j=if j∈S then P j else 0 := by + rw [Finset.sum_mul] + have he (i : ι) : P i*P j=if i=j then P j else 0 := by + split_ifs with h + · subst i; exact (hP j).isIdempotentElem.eq + · exact horth i j h + simp only [he,Finset.sum_ite_eq'] + +lemma resolution_truncated_norm (P : ι → V →L[ℂ] V) + (hP : ∀ i, IsStarProjection (P i)) + (horth : ∀ i j, i≠j → P i*P j=0) (hsum : ∑ i,P i=1) + (A : V →L[ℂ] V) (hcomm : ∀ i, Commute A (P i)) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∈S, ‖A*P i‖≤c) : + ‖A*(∑ i∈S,P i)‖≤c := by + apply resolution_norm_bound P hP horth hsum _ _ c hc + · intro i + rw [mul_assoc,resolution_sum_mul P hP horth] + split_ifs with hi + · exact hbound i hi + · simp [hc] + · intro i + exact (hcomm i).mul_left (Commute.sum_left S P (P i) fun j _ => resolution_commute P horth j i) + +/-- Exceptional-sector comparison, faithful to FAC's positive sandwich +argument but not requiring tensor-product representation machinery. -/ +theorem resolution_exception_bound (T Q : ι → V →L[ℂ] V) + (hT : ∀ i, IsStarProjection (T i)) + (horth : ∀ i j, i≠j → T i*T j=0) (hsum : ∑ i,T i=1) + (hQ : ∀ i, IsStarProjection (Q i)) (hTQ : ∀ i,T i*Q i=T i) + (A B : V →L[ℂ] V) (hcomm : ∀ i, Commute A (T i)) + (hA : ‖A‖≤1) (hB : ‖B‖≤1) + (S : Finset ι) (c : ℝ) (hc : 0≤c) (hbound : ∀ i∉S, ‖A*T i‖≤c) : + ‖B.adjoint*A*B‖≤c+∑ i∈S,‖B.adjoint*Q i*B‖ := by + have hhigh : ‖A*(∑ i∈Sᶜ,T i)‖≤c := resolution_truncated_norm T hT horth hsum A hcomm + Sᶜ c hc (fun i hi => hbound i (Finset.mem_compl.mp hi)) + have hsplit : (∑ i∈Sᶜ,T i)+(∑ i∈S,T i)=1 := by + rw [Finset.sum_compl_add_sum,hsum] + have he : B.adjoint*A*B=B.adjoint*(A*(∑ i∈Sᶜ,T i))*B+ + ∑ i∈S,B.adjoint*A*T i*B := by + rw [←Finset.sum_mul,←Finset.mul_sum] + rw [←add_mul] + simp only [mul_assoc] + rw [←mul_add,←mul_add,hsplit] + simp only [mul_one,mul_assoc] + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add + · calc + _ ≤ ‖B.adjoint‖*‖A*(∑ i∈Sᶜ,T i)‖*‖B‖ := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ 1*c*1 := mul_le_mul (mul_le_mul (by simpa only [ContinuousLinearMap.adjoint.norm_map] using hB) + hhigh (norm_nonneg _) zero_le_one) hB (norm_nonneg _) (by simpa using hc) + _ = c := by ring + · apply (norm_sum_le _ _).trans + exact Finset.sum_le_sum fun i _ => sector_sandwich_le _ _ _ _ (hT i) (hQ i) (hTQ i) (hcomm i) hA + +section Sectors +variable [DecidableEq ι] +variable (P : ι → V →L[ℂ] V) (hcomm : ∀ i j, Commute (P i) (P j)) + +noncomputable def choice (E : Finset ι) (i : ι) : V →L[ℂ] V := + if i∈E then 1-P i else P i + +include hcomm +omit [CompleteSpace V] [Fintype ι] in +lemma choice_commute (E F : Finset ι) (i j : ι) : + Commute (choice P E i) (choice P F j) := by + unfold choice + split_ifs + · exact (Commute.one_left _).sub_left ((Commute.one_right _).sub_right (hcomm i j)) + · exact (Commute.one_left _).sub_left (hcomm i j) + · exact (Commute.one_right _).sub_right (hcomm i j) + · exact hcomm i j + +noncomputable def sector (s E : Finset ι) : V →L[ℂ] V := + s.noncommProd (choice P E) (fun i _ j _ _ => choice_commute P hcomm E E i j) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_insert (s E : Finset ι) (a : ι) (ha : a∉s) : + sector P hcomm (insert a s) E=choice P E a*sector P hcomm s E := by + exact Finset.noncommProd_insert_of_notMem _ _ _ _ ha + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_congr (s E F : Finset ι) (h : ∀ i∈s, (i∈E ↔ i∈F)) : + sector P hcomm s E=sector P hcomm s F := by + apply Finset.noncommProd_congr rfl + intro i hi + simp only [choice,h i hi] + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_factor_commute (s E F : Finset ι) (i : ι) : + Commute (choice P E i) (sector P hcomm s F) := + Finset.noncommProd_commute _ _ _ _ (fun j _ => choice_commute P hcomm E F i j) + +omit [Fintype ι] in +lemma sector_projection (hP : ∀ i, IsStarProjection (P i)) (s E : Finset ι) : + IsStarProjection (sector P hcomm s E) := by + induction s using Finset.induction_on with + | empty => exact IsStarProjection.one _ + | @insert a s ha ih => + rw [sector_insert P hcomm s E a ha] + have hc : IsStarProjection (choice P E a) := by + unfold choice + split_ifs + · exact (hP a).one_sub + · exact hP a + exact hc.mul ih (sector_factor_commute P hcomm s E E a) + +omit [CompleteSpace V] [Fintype ι] in +lemma sector_sum (s : Finset ι) : ∑ E∈s.powerset, sector P hcomm s E=1 := by + induction s using Finset.induction_on with + | empty => + simp only [Finset.powerset_empty,Finset.sum_singleton] + exact Finset.noncommProd_empty _ _ + | @insert a s ha ih => + rw [Finset.sum_powerset_insert ha] + have h₁ (E : Finset ι) (hE : E∈s.powerset) : + sector P hcomm (insert a s) E=P a*sector P hcomm s E := by + rw [sector_insert P hcomm s E a ha] + congr 1 + exact ite_eq_right (fun h => ha ((Finset.mem_powerset.mp hE) h)) + have h₂ (E : Finset ι) (_hE : E∈s.powerset) : + sector P hcomm (insert a s) (insert a E)=(1-P a)*sector P hcomm s E := by + rw [sector_insert P hcomm s (insert a E) a ha] + simp only [choice,Finset.mem_insert_self,↓reduceIte] + congr 1 + apply sector_congr + intro i hi + simp [ne_of_mem_of_not_mem hi ha] + rw [Finset.sum_congr rfl h₁,Finset.sum_congr rfl h₂, + ←Finset.mul_sum,←Finset.mul_sum,ih] + simp + +omit [Fintype ι] in +lemma sector_absorb_factor (s E : Finset ι) (i : ι) (hi : i∈s) + (hP : ∀ i, IsStarProjection (P i)) : + choice P E i*sector P hcomm s E=sector P hcomm s E := by + have hc : IsIdempotentElem (choice P E i) := by + unfold choice + split_ifs + · exact (hP i).one_sub.isIdempotentElem + · exact (hP i).isIdempotentElem + have hsplit := Finset.mul_noncommProd_erase s hi (choice P E) + (fun i _ j _ _ => choice_commute P hcomm E E i j) + change choice P E i*sector P hcomm s E=sector P hcomm s E + change _=sector P hcomm s E at hsplit + nth_rw 1 [←hsplit] + rw [←mul_assoc,hc.eq,hsplit] + +omit [Fintype ι] in +lemma sector_orthogonal (s E F : Finset ι) (hE : E⊆s) (hF : F⊆s) (hEF : E≠F) + (hP : ∀ i, IsStarProjection (P i)) : + sector P hcomm s E*sector P hcomm s F=0 := by + have hdiff : ∃ i∈s, ¬(i∈E ↔ i∈F) := by + by_contra h + push Not at h + exact hEF (Finset.ext fun i => by + by_cases hi : i∈s + · exact h i hi + · exact iff_of_false (fun h => hi (hE h)) (fun h => hi (hF h))) + obtain ⟨i,hi,hdiff⟩ := hdiff + have hz : choice P E i*choice P F i=0 := by + by_cases he : i∈E <;> by_cases hf : i∈F + · exact (hdiff (iff_of_true he hf)).elim + · simpa only [choice,ite_eq_left he,ite_eq_right hf] using (hP i).one_sub_mul_self + · simpa only [choice,ite_eq_right he,ite_eq_left hf] using (hP i).mul_one_sub_self + · exact (hdiff (iff_of_false he hf)).elim + have hEi := sector_absorb_factor P hcomm s E i hi hP + have hFi := sector_absorb_factor P hcomm s F i hi hP + calc + _ = sector P hcomm s E*(choice P E i*choice P F i)*sector P hcomm s F := by + simp only [mul_assoc] + rw [hFi] + rw [←mul_assoc,(sector_factor_commute P hcomm s E E i).eq.symm,hEi] + _ = 0 := by rw [hz,mul_zero,zero_mul] + +noncomputable def blockProduct (A : ι → V →L[ℂ] V) + (hA : ∀ i j, Commute (A i) (A j)) (s : Finset ι) : V →L[ℂ] V := + s.noncommProd A (fun i _ j _ _ => hA i j) + +omit hcomm [Fintype ι] in +lemma norm_noncommProd_le (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (s : Finset ι) : ‖blockProduct A hA s‖≤∏ i∈s,‖A i‖ := by + induction s using Finset.induction_on with + | empty => exact ContinuousLinearMap.norm_id_le + | @insert a s ha ih => + have he : blockProduct A hA (insert a s)=A a*blockProduct A hA s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,Finset.prod_insert ha] + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ih (norm_nonneg _)) + +noncomputable def blocks (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) : V →L[ℂ] V := + blockProduct A hA Finset.univ + +omit hcomm in +lemma blocks_norm_le_one (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hn : ∀ i,‖A i‖≤1) : ‖blocks A hA‖≤1 := + (norm_noncommProd_le A hA Finset.univ).trans (Finset.prod_le_one₀ (fun _ _ => norm_nonneg _) (fun i _ => hn i)) + +omit [CompleteSpace V] in +lemma blocks_sector_commute (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (E : Finset ι) : + Commute (blocks A hA) (sector P hcomm Finset.univ E) := by + unfold blocks blockProduct + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => hA i j) _ _).symm + intro i _ + unfold sector + apply (Finset.noncommProd_commute _ _ (fun i _ j _ _ => choice_commute P hcomm E E i j) _ _).symm + intro j _ + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + +lemma blocks_sector_norm (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (_hθ : 0≤θ) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) (E : Finset ι) : + ‖blocks A hA*sector P hcomm Finset.univ E‖≤θ^E.card := by + have hAC (i j : ι) : Commute (A i) (choice P E j) := by + unfold choice + split_ifs + · exact (Commute.one_right _).sub_right (hAP i j) + · exact hAP i j + have hprod := Finset.noncommProd_mul_distrib (s := Finset.univ) A (choice P E) + (fun i _ j _ _ => hA i j) (fun i _ j _ _ => choice_commute P hcomm E E i j) + (fun i _ j _ _ => (hAC j i).symm) + change _=blocks A hA*sector P hcomm Finset.univ E at hprod + rw [←hprod] + have hc (i j : ι) : Commute ((A*choice P E) i) ((A*choice P E) j) := + ((hA i j).mul_right (hAC i j)).mul_left ((hAC j i).symm.mul_right (choice_commute P hcomm E E i j)) + apply (norm_noncommProd_le _ hc Finset.univ).trans + calc + _ ≤ ∏ i : ι, if i∈E then θ else 1 := by + apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) + intro i _ + dsimp only [Pi.mul_apply] + unfold choice + split_ifs with hi + · exact hgap i + · exact (norm_mul_le _ _).trans (by nlinarith [hn i,(hP i).norm_le (P i),norm_nonneg (A i),norm_nonneg (P i)]) + _ = _ := by rw [Fintype.prod_ite_mem,Finset.prod_const] + +noncomputable def coarse (E : Finset ι) : V →L[ℂ] V := + Eᶜ.noncommProd P (fun i _ j _ _ => hcomm i j) + +lemma coarse_projection (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + IsStarProjection (coarse P hcomm E) := by + have he : coarse P hcomm E=sector P hcomm Eᶜ ∅ := by + apply Finset.noncommProd_congr rfl + intro i _ + simp [choice] + rw [he] + exact sector_projection P hcomm hP _ _ + +lemma sector_coarse (hP : ∀ i, IsStarProjection (P i)) (E : Finset ι) : + sector P hcomm Finset.univ E*coarse P hcomm E=sector P hcomm Finset.univ E := by + have hpi (i : ι) (hi : i∈Eᶜ) : sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E := by + have h := sector_absorb_factor P hcomm Finset.univ E i (Finset.mem_univ i) hP + rw [(sector_factor_commute P hcomm Finset.univ E E i).eq] at h + simpa only [choice,ite_eq_right (Finset.mem_compl.mp hi)] using h + have hp (s : Finset ι) (hs : ∀ i∈s, + sector P hcomm Finset.univ E*P i=sector P hcomm Finset.univ E) : + sector P hcomm Finset.univ E*blockProduct P hcomm s=sector P hcomm Finset.univ E := by + induction s using Finset.induction_on with + | empty => exact mul_one _ + | @insert a s ha ih => + have he : blockProduct P hcomm (insert a s)=P a*blockProduct P hcomm s := + Finset.noncommProd_insert_of_notMem _ _ _ _ ha + rw [he,←mul_assoc,hs a (Finset.mem_insert_self _ _)] + exact ih (fun i hi => hs i (Finset.mem_insert_of_mem hi)) + exact hp Eᶜ hpi + +/-- Actual commuting-block exceptional estimate, with no tensor irreducible +hypothesis. The local gaps are for each represented finite block. -/ +theorem blocks_exception_bound (hP : ∀ i, IsStarProjection (P i)) + (A : ι → V →L[ℂ] V) (hA : ∀ i j, Commute (A i) (A j)) + (hAP : ∀ i j, Commute (A i) (P j)) (hn : ∀ i,‖A i‖≤1) + (θ : ℝ) (hθ : 0≤θ) (hθ1 : θ≤1) (hgap : ∀ i,‖A i*(1-P i)‖≤θ) + (B : V →L[ℂ] V) (hB : ‖B‖≤1) (n : ℕ) : + ‖B.adjoint*blocks A hA*B‖≤θ^n+ + ∑ E : Finset ι, if E.card sector_projection P hcomm hP _ E) + (fun E F hEF => sector_orthogonal P hcomm _ E F (Finset.subset_univ _) (Finset.subset_univ _) hEF hP) + hsum (coarse_projection P hcomm hP) (sector_coarse P hcomm hP) + (blocks A hA) B (blocks_sector_commute P hcomm A hA hAP) + (blocks_norm_le_one A hA hn) hB (Finset.univ.filter fun E : Finset ι => E.card by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] - · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] - rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] - -include ρ hneq hcard in -lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by - simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] - exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard - -noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := - OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) - (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' - (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) - -lemma coefficientBasis_apply (a : CoefficientIndex V) : - coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a - -include hρ hneq hcard in -/-- Finite-group Plancherel, produced from the actual complete irreducible -coefficient basis rather than postulated as a Fourier hypothesis. -/ -theorem parseval (f : EuclideanSpace ℂ G) : - ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by - simpa only [coefficientBasis_apply] using - (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f - -end CubeShuffle.FiniteFourier -namespace CubeShuffle.FiniteFourier -open scoped BigOperators ComplexConjugate Classical -open UnitaryFinite - -variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] -variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] - [∀ i, FiniteDimensional ℂ (V i)] -variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] -variable (hρ : ∀ i, IsUnitary (ρ i)) -variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) - (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) - -noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : - inner ℂ (coefficientFamily V ρ a) (realVector p)= - (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* - inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by - simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, - RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, - weightedOperator,sum_apply,smul_apply, - continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - -omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in -lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : - ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= - ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* - ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) - (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by - rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, - abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] - -include hρ hneq hcard in -lemma parseval_operator (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2= - ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←parseval V ρ hρ hneq hcard (realVector p)] - simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] - have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro i _ - have he (a : Fin (Module.finrank ℂ (V i))) : - (∑ b : Fin (Module.finrank ℂ (V i)), - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) - (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= - (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* - ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by - rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] - simp_rw [he] - rw [←Finset.mul_sum] - field_simp - -include hρ hneq hcard in -lemma realVector_bound (p : G → ℝ) : - (Fintype.card G:ℝ)*‖realVector p‖^2≤ - ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - rw [parseval_operator V ρ hρ hneq hcard] - apply Finset.sum_le_sum - intro i _ - calc - _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by - apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) - apply Finset.sum_le_sum - intro a _ - apply pow_le_pow_left₀ (norm_nonneg _) - simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using - (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) - _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring - -include hρ hneq hcard in -/-- The exact full-group Fourier upper bound, with no marginal replacement. -/ -theorem l1_fourier_bound (p : G → ℝ) : - (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by - apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) - have he : ‖realVector p‖^2=∑ g,|p g|^2 := by - rw [EuclideanSpace.norm_sq_eq] - simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] - rw [he] - simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) - -end CubeShuffle.FiniteFourier - -end OAI +import OAI.RepresentationTheory.FiniteUnitary.Characters +import OAI.RepresentationTheory.FiniteUnitary.Sampling + +namespace OAI + +namespace CubeShuffle.FiniteFourier +open scoped BigOperators ComplexConjugate Classical +open UnitaryFinite + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hρ : ∀ i, IsUnitary (ρ i)) +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) + +abbrev CoefficientIndex := Σ i,Fin (Module.finrank ℂ (V i)) × Fin (Module.finrank ℂ (V i)) + +noncomputable def coefficientFamily (a : CoefficientIndex V) : EuclideanSpace ℂ G := + regularCoefficient (ρ a.1) (stdOrthonormalBasis ℂ (V a.1) a.2.1) (stdOrthonormalBasis ℂ (V a.1) a.2.2) + +omit [Fintype ι] in +include hρ hneq in +lemma coefficientFamily_orthonormal : Orthonormal ℂ (coefficientFamily V ρ) := by + rw [orthonormal_iff_ite] + rintro ⟨i,a,b⟩ ⟨j,c,d⟩ + dsimp only [coefficientFamily] + by_cases hij : i=j + · subst j + rw [regularCoefficient_inner _ (hρ i)] + simp only [(stdOrthonormalBasis ℂ (V i)).inner_eq_ite] + by_cases hac : a=c <;> by_cases hbd : b=d <;> simp [hac,hbd,eq_comm] + · rw [regularCoefficient_cross _ _ (hρ j) (hneq j i (Ne.symm hij))] + rw [ite_eq_right (by intro h; exact hij (congrArg Sigma.fst h))] + +include ρ hneq hcard in +lemma coefficientIndex_card : Fintype.card (CoefficientIndex V)=Fintype.card G := by + simp only [CoefficientIndex,Fintype.card_sigma,Fintype.card_prod,Fintype.card_fin,←pow_two] + exact FiniteCharacters.sum_dimension_sq V ρ hneq hcard + +noncomputable def coefficientBasis : OrthonormalBasis (CoefficientIndex V) ℂ (EuclideanSpace ℂ G) := + OrthonormalBasis.mk (coefficientFamily_orthonormal V ρ hρ hneq) + (by rw [(coefficientFamily_orthonormal V ρ hρ hneq).linearIndependent.span_eq_top_of_card_eq_finrank' + (by rw [coefficientIndex_card V ρ hneq hcard,finrank_euclideanSpace])]) + +lemma coefficientBasis_apply (a : CoefficientIndex V) : + coefficientBasis V ρ hρ hneq hcard a=coefficientFamily V ρ a := congrFun (OrthonormalBasis.coe_mk _ _) a + +include hρ hneq hcard in +/-- Finite-group Plancherel, produced from the actual complete irreducible +coefficient basis rather than postulated as a Fourier hypothesis. -/ +theorem parseval (f : EuclideanSpace ℂ G) : + ∑ a : CoefficientIndex V, ‖inner ℂ (coefficientFamily V ρ a) f‖^2=‖f‖^2 := by + simpa only [coefficientBasis_apply] using + (coefficientBasis V ρ hρ hneq hcard).sum_sq_norm_inner_right f + +end CubeShuffle.FiniteFourier +namespace CubeShuffle.FiniteFourier +open scoped BigOperators ComplexConjugate Classical +open UnitaryFinite + +variable {G ι : Type*} [Group G] [Fintype G] [Fintype ι] +variable (V : ι → Type*) [∀ i, NormedAddCommGroup (V i)] [∀ i, InnerProductSpace ℂ (V i)] + [∀ i, FiniteDimensional ℂ (V i)] +variable (ρ : ∀ i, Representation ℂ G (V i)) [∀ i, Representation.IsIrreducible (ρ i)] +variable (hρ : ∀ i, IsUnitary (ρ i)) +variable (hneq : ∀ i j, i≠j → ¬Nonempty (Representation.Equiv (ρ i) (ρ j))) + (hcard : Nat.card (ConjClasses G)≤Fintype.card ι) + +noncomputable def realVector (p : G → ℝ) : EuclideanSpace ℂ G := WithLp.toLp 2 (fun g => (p g:ℂ)) + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector (p : G → ℝ) (a : CoefficientIndex V) : + inner ℂ (coefficientFamily V ρ a) (realVector p)= + (Real.sqrt ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ)):ℂ)* + inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1)) := by + simp only [PiLp.inner_apply,coefficientFamily,regularCoefficient_apply,realVector, + RCLike.inner_apply,map_mul,Complex.conj_ofReal,inner_conj_symm, + weightedOperator,sum_apply,smul_apply, + continuousRepresentation_apply,inner_sum,inner_smul_right,Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + +omit [Fintype ι] [∀ i, Representation.IsIrreducible (ρ i)] in +lemma coefficient_realVector_sq (p : G → ℝ) (a : CoefficientIndex V) : + ‖inner ℂ (coefficientFamily V ρ a) (realVector p)‖^2= + ((Module.finrank ℂ (V a.1):ℝ)/(Fintype.card G:ℝ))* + ‖inner ℂ (stdOrthonormalBasis ℂ (V a.1) a.2.2) + (weightedOperator (ρ a.1) p (stdOrthonormalBasis ℂ (V a.1) a.2.1))‖^2 := by + rw [coefficient_realVector,norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg _),mul_pow,Real.sq_sqrt (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))] + +include hρ hneq hcard in +lemma parseval_operator (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2= + ∑ i,(Module.finrank ℂ (V i):ℝ)*∑ a : Fin (Module.finrank ℂ (V i)), + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←parseval V ρ hρ hneq hcard (realVector p)] + simp only [Fintype.sum_sigma,Fintype.sum_prod_type,coefficient_realVector_sq] + have hN : (Fintype.card G:ℝ)≠0 := by exact_mod_cast Fintype.card_ne_zero + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + have he (a : Fin (Module.finrank ℂ (V i))) : + (∑ b : Fin (Module.finrank ℂ (V i)), + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖inner ℂ (stdOrthonormalBasis ℂ (V i) b) + (weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a))‖^2)= + (Module.finrank ℂ (V i):ℝ)/(Fintype.card G:ℝ)* + ‖weightedOperator (ρ i) p (stdOrthonormalBasis ℂ (V i) a)‖^2 := by + rw [←Finset.mul_sum,(stdOrthonormalBasis ℂ (V i)).sum_sq_norm_inner_right] + simp_rw [he] + rw [←Finset.mul_sum] + field_simp + +include hρ hneq hcard in +lemma realVector_bound (p : G → ℝ) : + (Fintype.card G:ℝ)*‖realVector p‖^2≤ + ∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + rw [parseval_operator V ρ hρ hneq hcard] + apply Finset.sum_le_sum + intro i _ + calc + _ ≤ (Module.finrank ℂ (V i):ℝ)*∑ _a : Fin (Module.finrank ℂ (V i)),‖weightedOperator (ρ i) p‖^2 := by + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro a _ + apply pow_le_pow_left₀ (norm_nonneg _) + simpa only [(stdOrthonormalBasis ℂ (V i)).norm_eq_one,mul_one] using + (weightedOperator (ρ i) p).le_opNorm (stdOrthonormalBasis ℂ (V i) a) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul]; ring + +include hρ hneq hcard in +/-- The exact full-group Fourier upper bound, with no marginal replacement. -/ +theorem l1_fourier_bound (p : G → ℝ) : + (∑ g,|p g|)^2≤∑ i,(Module.finrank ℂ (V i):ℝ)^2*‖weightedOperator (ρ i) p‖^2 := by + apply le_trans _ (realVector_bound V ρ hρ hneq hcard p) + have he : ‖realVector p‖^2=∑ g,|p g|^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [realVector,PiLp.toLp_apply,Complex.norm_real,Real.norm_eq_abs] + rw [he] + simpa only [Finset.card_univ] using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun g => |p g|) + +end CubeShuffle.FiniteFourier + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Frames.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Frames.lean index 66356b3ff0ea2fe4f34282397dac83e329496c37..703de26296cddf79aa970cfdb6a85f18905f93e1 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Frames.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Frames.lean @@ -1,560 +1,560 @@ -import Mathlib - -namespace OAI - -section -noncomputable section -open scoped BigOperators ComplexConjugate -namespace RowColumn.HilbertSchmidt -variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -/-- The algebraic Hilbert--Schmidt scalar product, irrespective of the operator -norm on the carrier. A core is used to avoid changing any source norm. -/ -def hsInner (T U : E →ₗ[ℂ] E) : ℂ := - LinearMap.trace ℂ E (LinearMap.adjoint T ∘ₗ U) - -lemma hsInner_basis (T U : E →ₗ[ℂ] E) : - hsInner T U = ∑ i, inner ℂ (T (stdOrthonormalBasis ℂ E i)) - (U (stdOrthonormalBasis ℂ E i)) := by - rw [hsInner, LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℂ E)] - simp only [LinearMap.comp_apply, LinearMap.adjoint_inner_right] - -@[instance_reducible] -def endCore : InnerProductSpace.Core ℂ (E →ₗ[ℂ] E) where - inner := hsInner - conj_inner_symm T U := by - simp only [hsInner_basis, map_sum, inner_conj_symm] - re_inner_nonneg T := by - rw [hsInner_basis, map_sum] - exact Finset.sum_nonneg fun _ _ => inner_self_nonneg - add_left T U V := by - simp only [hsInner_basis, LinearMap.add_apply, inner_add_left, Finset.sum_add_distrib] - smul_left T U z := by - simp only [hsInner_basis, LinearMap.smul_apply, inner_smul_left, Finset.mul_sum] - definite T h := by - have hh : ∑ i, ‖T (stdOrthonormalBasis ℂ E i)‖^2 = 0 := by - have he := congrArg (RCLike.re : ℂ → ℝ) h - simpa only [hsInner_basis, map_sum, map_zero, inner_self_eq_norm_sq] using he - have hz (i : Fin (Module.finrank ℂ E)) : T (stdOrthonormalBasis ℂ E i) = 0 := by - have hi := (Finset.sum_eq_zero_iff_of_nonneg (fun j (_ : j ∈ Finset.univ) => - sq_nonneg ‖T (stdOrthonormalBasis ℂ E j)‖)).mp hh i (Finset.mem_univ i) - exact norm_eq_zero.mp (sq_eq_zero_iff.mp hi) - apply (stdOrthonormalBasis ℂ E).toBasis.ext - intro i - simpa using hz i - -lemma adjoint_isometry (u : E ≃ₗᵢ[ℂ] E) : - LinearMap.adjoint u.toLinearEquiv.toLinearMap = u.symm.toLinearEquiv.toLinearMap := by - apply LinearMap.ext - intro x - apply ext_inner_right ℂ - intro y - rw [LinearMap.adjoint_inner_left] - change inner ℂ x (u y) = inner ℂ (u.symm x) y - simpa only [u.apply_symm_apply] using u.inner_map_map (u.symm x) y - -lemma hsInner_conj (u : E ≃ₗᵢ[ℂ] E) (T V : E →ₗ[ℂ] E) : - hsInner (u.toLinearEquiv.conj T) (u.toLinearEquiv.conj V) = hsInner T V := by - rw [hsInner_basis] - conv_rhs => rw [hsInner, LinearMap.trace_eq_sum_inner _ - ((stdOrthonormalBasis ℂ E).map u.symm)] - apply Finset.sum_congr rfl - intro i _ - simp only [LinearMap.comp_apply, LinearMap.adjoint_inner_right, - OrthonormalBasis.map_apply, LinearEquiv.conj_apply] - change inner ℂ (u (T (u.symm (stdOrthonormalBasis ℂ E i)))) - (u (V (u.symm (stdOrthonormalBasis ℂ E i)))) = _ - exact u.inner_map_map _ _ - -end RowColumn.HilbertSchmidt - -noncomputable section -open scoped RealInnerProductSpace -namespace RowColumn.UnitaryFrame -variable {E ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] - -omit [CompleteSpace E] in -lemma norm_minimizer_unique [CompleteSpace E] (K : Set E) (hK : Convex ℝ K) - {x y : E} (hx : x ∈ K) (hy : y ∈ K) - (hxm : ∀ z ∈ K, ‖x‖ ≤ ‖z‖) (hym : ∀ z ∈ K, ‖y‖ ≤ ‖z‖) : x = y := by - have he : ‖x‖ = ‖y‖ := le_antisymm (hxm y hy) (hym x hx) - have hm : (1/2 : ℝ) • x + (1/2 : ℝ) • y ∈ K := - hK hx hy (by norm_num) (by norm_num) (by norm_num) - have hl := hxm _ hm - have hn : ‖(1/2 : ℝ) • x + (1/2 : ℝ) • y‖ = (1/2 : ℝ)*‖x+y‖ := by - rw [← smul_add, norm_smul, Real.norm_eq_abs, abs_of_nonneg (by norm_num)] - rw [hn] at hl - have hsq := mul_self_le_mul_self (norm_nonneg x) hl - have hp := parallelogram_law_with_norm ℝ x y - rw [← he] at hp - have hd := sq_nonneg ‖x-y‖ - have hz : ‖x-y‖ = 0 := by - nlinarith [norm_nonneg (x-y)] - exact sub_eq_zero.mp (norm_eq_zero.mp hz) - -/-- Simultaneous fixed point obtained from the unique minimum-norm point of a -closed convex invariant set. Applied to rank-one unitary frames, this replaces -Haar integration by finite-dimensional convex averaging. -/ -theorem exists_fixed_minimum (K : Set E) (hne : K.Nonempty) (hclosed : IsClosed K) - (hconv : Convex ℝ K) (L : ι → E →ₗᵢ[ℝ] E) - (hL : ∀ i x, x ∈ K → L i x ∈ K) : - ∃ x ∈ K, ∀ i, L i x = x := by - obtain ⟨x,hx,hm⟩ := exists_norm_eq_iInf_of_complete_convex hne hclosed.isComplete hconv (0 : E) - have hmin (z : E) (hz : z ∈ K) : ‖x‖ ≤ ‖z‖ := by - have hh : (⨅ w : K, ‖(0 : E)-w‖) ≤ ‖(0 : E)-z‖ := - ciInf_le (f := fun w : K => ‖(0 : E) - (w : E)‖) - ⟨0, Set.forall_mem_range.mpr (fun _ => norm_nonneg _)⟩ (⟨z,hz⟩ : K) - rw [← hm] at hh - simpa using hh - refine ⟨x,hx,fun i => ?_⟩ - exact norm_minimizer_unique K hconv (hL i x hx) hx - (fun z hz => by rw [(L i).norm_map]; exact hmin z hz) hmin - -end RowColumn.UnitaryFrame - -noncomputable section -open scoped BigOperators ComplexConjugate -namespace RowColumn.UnitaryFrame -variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -def quadraticForm (T : E →ₗ[ℂ] E) (x : E) : ℝ := (inner ℂ x (T x)).re - -omit [FiniteDimensional ℂ E] in -lemma quadraticForm_real_smul [FiniteDimensional ℂ E] (T : E →ₗ[ℂ] E) (c : ℝ) (x : E) : - quadraticForm T (c • x) = c^2 * quadraticForm T x := by - simp only [quadraticForm, ← Complex.coe_smul, map_smul, inner_smul_left, - inner_smul_right, Complex.conj_ofReal] - simp [Complex.mul_re, pow_two, mul_assoc] - -lemma quadraticForm_continuous (T : E →ₗ[ℂ] E) : Continuous (quadraticForm T) := - Complex.continuous_re.comp (continuous_id.inner T.toContinuousLinearMap.continuous) - -/-- Strict positivity of a finite-dimensional frame is uniformly coercive. -/ -theorem positive_coercive (T : E →ₗ[ℂ] E) - (hT : ∀ x : E, x ≠ 0 → 0 < quadraticForm T x) : - ∃ ε : ℝ, 0 < ε ∧ ∀ x, ε * ‖x‖^2 ≤ quadraticForm T x := by - cases subsingleton_or_nontrivial E with - | inl h => - let := h - refine ⟨1, by norm_num, fun x => ?_⟩ - have he : x = 0 := Subsingleton.elim _ _ - simp [he, quadraticForm] - | inr h => - let := h - let : ProperSpace E := FiniteDimensional.proper ℂ E - have hn : (Metric.sphere (0 : E) 1).Nonempty := NormedSpace.sphere_nonempty.mpr (by norm_num) - obtain ⟨y,hy,hmin⟩ := (isCompact_sphere (0 : E) 1).exists_isMinOn hn - (quadraticForm_continuous T).continuousOn - have hny : ‖y‖ = 1 := by simpa using hy - have hpy : 0 < quadraticForm T y := hT y (by intro he; simp [he] at hny) - refine ⟨quadraticForm T y, hpy, fun x => ?_⟩ - by_cases hx : x = 0 - · simp [hx, quadraticForm] - · have hp : 0 < ‖x‖ := norm_pos_iff.mpr hx - have hu : ‖x‖⁻¹ • x ∈ Metric.sphere (0 : E) 1 := by - simp [norm_smul, ne_of_gt hp] - have hm : quadraticForm T y ≤ quadraticForm T (‖x‖⁻¹ • x) := hmin hu - rw [quadraticForm_real_smul] at hm - have hh := mul_le_mul_of_nonneg_right hm (sq_nonneg ‖x‖) - calc - _ ≤ (‖x‖⁻¹ ^ 2 * quadraticForm T x) * ‖x‖^2 := hh - _ = _ := by field_simp [ne_of_gt hp] - -end RowColumn.UnitaryFrame - -namespace RowColumn.UnitaryFrame -open scoped BigOperators ComplexOrder ComplexConjugate -variable {E G : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] [Group G] - -local instance : NormedAddCommGroup (E →ₗ[ℂ] E) := HilbertSchmidt.endCore.toNormedAddCommGroup -local instance : InnerProductSpace ℂ (E →ₗ[ℂ] E) := - InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := E) } -local instance : InnerProductSpace ℝ (E →ₗ[ℂ] E) := InnerProductSpace.complexToReal - -def conjugationIsometry (u : E ≃ₗᵢ[ℂ] E) : - (E →ₗ[ℂ] E) →ₗᵢ[ℂ] (E →ₗ[ℂ] E) := - u.toLinearEquiv.conj.toLinearMap.isometryOfInner (HilbertSchmidt.hsInner_conj u) - -def conjugationReal (u : E ≃ₗᵢ[ℂ] E) : - (E →ₗ[ℂ] E) →ₗᵢ[ℝ] (E →ₗ[ℂ] E) where - toLinearMap := (conjugationIsometry u).toLinearMap.restrictScalars ℝ - norm_map' := (conjugationIsometry u).norm_map - -lemma conjugation_apply (u : E ≃ₗᵢ[ℂ] E) (T : E →ₗ[ℂ] E) (x : E) : - conjugationReal u T x = u (T (u.symm x)) := rfl - -lemma conjugation_rankOne (u : E ≃ₗᵢ[ℂ] E) (x : E) : - conjugationReal u (InnerProductSpace.rankOne ℂ x x).toLinearMap = - (InnerProductSpace.rankOne ℂ (u x) (u x)).toLinearMap := by - ext y - change u (inner ℂ x (u.symm y) • x) = inner ℂ (u x) y • u x - rw [map_smul] - congr 1 - simpa only [u.apply_symm_apply] using (u.inner_map_map x (u.symm y)).symm - -def matrixEntry (x y : E) : (E →ₗ[ℂ] E) →ₗ[ℂ] ℂ where - toFun T := inner ℂ x (T y) - map_add' T V := by simp only [LinearMap.add_apply, inner_add_right] - map_smul' c T := by simp only [LinearMap.smul_apply, inner_smul_right, smul_eq_mul, RingHom.id_apply] - -def quadraticEval (x : E) : (E →ₗ[ℂ] E) →ₗ[ℝ] ℝ where - toFun T := quadraticForm T x - map_add' T V := by simp [quadraticForm] - map_smul' c T := by - simp only [quadraticForm, LinearMap.smul_apply, ← Complex.coe_smul, inner_smul_right] - simp [Complex.mul_re] - -def coerciveSet (ε : ℝ) : Set (E →ₗ[ℂ] E) := - {T | ∀ x, ε * ‖x‖^2 ≤ quadraticForm T x} - -lemma coerciveSet_closed (ε : ℝ) : IsClosed (coerciveSet (E := E) ε) := by - rw [coerciveSet, Set.ofPred_forall] - apply isClosed_iInter - intro x - exact isClosed_le continuous_const - (show Continuous (fun T : E →ₗ[ℂ] E => quadraticForm T x) from - (quadraticEval x).toContinuousLinearMap.continuous) - -omit [FiniteDimensional ℂ E] in -lemma coerciveSet_convex [FiniteDimensional ℂ E] (ε : ℝ) : - Convex ℝ (coerciveSet (E := E) ε) := by - intro T hT V hV a b ha hb hab x - have h₁ := mul_le_mul_of_nonneg_left (hT x) ha - have h₂ := mul_le_mul_of_nonneg_left (hV x) hb - change ε * ‖x‖^2 ≤ quadraticEval x (a • T + b • V) - rw [map_add, map_smul, map_smul] - change ε * ‖x‖^2 ≤ a * quadraticForm T x + b * quadraticForm V x - calc - ε * ‖x‖^2 = (a+b) * (ε * ‖x‖^2) := by rw [hab, one_mul] - _ = a * (ε * ‖x‖^2) + b * (ε * ‖x‖^2) := add_mul _ _ _ - _ ≤ _ := add_le_add h₁ h₂ - -lemma positiveSet_closed : IsClosed {T : E →ₗ[ℂ] E | T.IsPositive} := by - have hs : IsClosed {T : E →ₗ[ℂ] E | T.IsSymmetric} := by - have he : {T : E →ₗ[ℂ] E | T.IsSymmetric} = - ⋂ x : E, ⋂ y : E, - {T | starRingEnd ℂ (matrixEntry y x T) = matrixEntry x y T} := by - ext T - simp only [Set.mem_ofPred_eq, Set.mem_iInter, matrixEntry, LinearMap.coe_mk, - AddHom.coe_mk, inner_conj_symm, LinearMap.IsSymmetric] - rw [he] - exact isClosed_iInter fun x => isClosed_iInter fun y => isClosed_eq - (Complex.continuous_conj.comp (matrixEntry y x).toContinuousLinearMap.continuous) - (matrixEntry x y).toContinuousLinearMap.continuous - have hn : IsClosed {T : E →ₗ[ℂ] E | ∀ x, 0 ≤ quadraticForm T x} := by - rw [Set.ofPred_forall] - apply isClosed_iInter - intro x - exact isClosed_le continuous_const - (show Continuous (fun T : E →ₗ[ℂ] E => quadraticForm T x) from - (quadraticEval x).toContinuousLinearMap.continuous) - have he : {T : E →ₗ[ℂ] E | T.IsPositive} = - {T | T.IsSymmetric} ∩ {T | ∀ x, 0 ≤ quadraticForm T x} := by - ext T - constructor - · intro h; exact ⟨h.isSymmetric, fun x => h.re_inner_nonneg_right x⟩ - · rintro ⟨hs,hn⟩ - refine ⟨hs, fun x => ?_⟩ - rw [inner_re_symm] - exact hn x - rw [he] - exact hs.inter hn - -omit [FiniteDimensional ℂ E] in -lemma positiveSet_convex [FiniteDimensional ℂ E] : Convex ℝ {T : E →ₗ[ℂ] E | T.IsPositive} := by - intro T hT V hV a b ha hb hab - change (a • T + b • V).IsPositive - rw [← Complex.coe_smul a T, ← Complex.coe_smul b V] - exact (hT.smul_of_nonneg (by exact_mod_cast ha)).add - (hV.smul_of_nonneg (by exact_mod_cast hb)) - -def frameHull (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) : Set (E →ₗ[ℂ] E) := - closure (convexHull ℝ (Set.range fun g : G => - (InnerProductSpace.rankOne ℂ (π g x₀) (π g x₀)).toLinearMap)) - -lemma frameHull_invariant (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) (g : G) : - Set.MapsTo (conjugationReal (π g)) (frameHull π x₀) (frameHull π x₀) := by - apply Set.MapsTo.closure _ (conjugationReal (π g)).continuous - rw [Set.mapsTo_iff_image_subset] - rw [← LinearIsometry.coe_toLinearMap, (conjugationReal (π g)).toLinearMap.image_convexHull] - apply convexHull_mono - rintro _ ⟨_, ⟨h,rfl⟩, rfl⟩ - refine ⟨g*h, ?_⟩ - change (InnerProductSpace.rankOne ℂ (π (g*h) x₀) (π (g*h) x₀)).toLinearMap = - conjugationReal (π g) (InnerProductSpace.rankOne ℂ (π h x₀) (π h x₀)).toLinearMap - rw [conjugation_rankOne, map_mul] - rfl - -lemma quadraticForm_conj (u : E ≃ₗᵢ[ℂ] E) (T : E →ₗ[ℂ] E) (x : E) : - quadraticForm (conjugationReal u T) x = quadraticForm T (u.symm x) := by - unfold quadraticForm - rw [conjugation_apply] - have hi := u.inner_map_map (u.symm x) (T (u.symm x)) - rw [u.apply_symm_apply] at hi - exact congrArg Complex.re hi - -/-- A genuine invariant strictly positive frame is obtained by convex averaging; -no Haar measure or compact-group orthogonality is taken as a hypothesis. -/ -theorem exists_invariant_frame_of_coercive - (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) - (T₀ : E →ₗ[ℂ] E) (hT₀ : T₀ ∈ frameHull π x₀) (hp₀ : T₀.IsPositive) - (ε : ℝ) (_ : 0 < ε) (hε₀ : T₀ ∈ coerciveSet ε) : - ∃ T : E →ₗ[ℂ] E, T ∈ frameHull π x₀ ∧ T.IsPositive ∧ - T ∈ coerciveSet ε ∧ ∀ g, conjugationReal (π g) T = T := by - let K := frameHull π x₀ ∩ ({T | T.IsPositive} ∩ coerciveSet ε) - have hc : IsClosed K := isClosed_closure.inter (positiveSet_closed.inter (coerciveSet_closed ε)) - have hv : Convex ℝ K := (convex_convexHull ℝ _).closure.inter - (positiveSet_convex.inter (coerciveSet_convex ε)) - have hL (g : G) (V : E →ₗ[ℂ] E) (hV : V ∈ K) : - conjugationReal (π g) V ∈ K := by - refine ⟨frameHull_invariant π x₀ g hV.1, ?_, ?_⟩ - · exact (LinearMap.isPositive_linearIsometryEquiv_conj_iff (π g)).mpr hV.2.1 - · intro x - rw [quadraticForm_conj] - simpa only [(π g).symm.norm_map] using hV.2.2 ((π g).symm x) - obtain ⟨T,hT,hfix⟩ := exists_fixed_minimum K ⟨T₀,hT₀,hp₀,hε₀⟩ hc hv - (fun g => conjugationReal (π g)) hL - exact ⟨T,hT.1,hT.2.1,hT.2.2,hfix⟩ - -end RowColumn.UnitaryFrame -namespace RowColumn.UnitaryFrame -open scoped BigOperators ComplexOrder ComplexConjugate -variable {E G : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] [Group G] - -omit [FiniteDimensional ℂ E] in -lemma rankOne_quadratic [FiniteDimensional ℂ E] (v x : E) : - quadraticForm (InnerProductSpace.rankOne ℂ v v).toLinearMap x = - Complex.normSq (inner ℂ v x) := by - change (inner ℂ x (inner ℂ v x • v)).re = _ - rw [inner_smul_right, ← inner_conj_symm x v, Complex.mul_conj, Complex.ofReal_re] - -omit [FiniteDimensional ℂ E] in -lemma finite_frame_strict [FiniteDimensional ℂ E] (s : Finset E) - (hs : Submodule.span ℂ (s : Set E) = ⊤) - {x : E} (hx : x ≠ 0) : 0 < ∑ v ∈ s, Complex.normSq (inner ℂ v x) := by - have hn : 0 ≤ ∑ v ∈ s, Complex.normSq (inner ℂ v x) := - Finset.sum_nonneg fun _ _ => Complex.normSq_nonneg _ - by_contra h - have hz := le_antisymm (le_of_not_gt h) hn - have hi (v : E) (hv : v ∈ s) : inner ℂ v x = 0 := - Complex.normSq_eq_zero.mp ((Finset.sum_eq_zero_iff_of_nonneg - (fun _ _ => Complex.normSq_nonneg _)).mp hz v hv) - have hall (v : E) (hv : v ∈ Submodule.span ℂ (s : Set E)) : inner ℂ v x = 0 := by - induction hv using Submodule.span_induction with - | mem v hv => exact hi v hv - | zero => simp - | add u v hu hv heu hev => simp [heu, hev] - | smul c v hv hv' => simp [hv'] - exact hx ((inner_self_eq_zero (𝕜 := ℂ)).mp (hall x (by rw [hs]; trivial))) - -def finiteFrame (s : Finset E) : E →ₗ[ℂ] E := - s.centerMass (fun _ => (1 : ℝ)) - (fun v => (InnerProductSpace.rankOne ℂ v v).toLinearMap) - -lemma finiteFrame_quadratic (s : Finset E) (x : E) : - quadraticForm (finiteFrame s) x = (s.card : ℝ)⁻¹ * - ∑ v ∈ s, Complex.normSq (inner ℂ v x) := by - change quadraticEval x (finiteFrame s) = _ - simp only [finiteFrame, Finset.centerMass, one_smul, Finset.sum_const, - nsmul_eq_mul, mul_one, map_smul, map_sum, smul_eq_mul] - congr 1 - apply Finset.sum_congr rfl - intro v _ - exact rankOne_quadratic v x - -local instance : NormedAddCommGroup (E →ₗ[ℂ] E) := HilbertSchmidt.endCore.toNormedAddCommGroup -local instance : InnerProductSpace ℂ (E →ₗ[ℂ] E) := - InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := E) } -local instance : InnerProductSpace ℝ (E →ₗ[ℂ] E) := InnerProductSpace.complexToReal - -lemma finiteFrame_positive (s : Finset E) (hs : s.Nonempty) : (finiteFrame s).IsPositive := by - change s.centerMass (fun _ => (1 : ℝ)) - (fun v => (InnerProductSpace.rankOne ℂ v v).toLinearMap) ∈ - {T : E →ₗ[ℂ] E | T.IsPositive} - apply (positiveSet_convex (E := E)).centerMass_mem (fun _ _ => by norm_num) - · simpa only [Finset.sum_const, nsmul_eq_mul, mul_one] using - (show (0 : ℝ) < s.card from by exact_mod_cast hs.card_pos) - · intro v _ - exact (InnerProductSpace.isPositive_rankOne_self v).toLinearMap - -/-- Spanning unitary orbits have an invertible positive invariant frame, with -its approximation by finite probability mixtures of the original orbit. -/ -theorem exists_invariant_frame (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) - (hspan : Submodule.span ℂ (Set.range fun g : G => π g x₀) = ⊤) : - ∃ T : E →ₗ[ℂ] E, T ∈ frameHull π x₀ ∧ T.IsPositive ∧ - Function.Bijective T ∧ ∀ g, conjugationReal (π g) T = T := by - classical - obtain ⟨s,hs,hcard,hss,hindep⟩ := Submodule.exists_finset_span_eq_linearIndepOn ℂ - (Set.range fun g : G => π g x₀) - let t := insert x₀ s - have htn : t.Nonempty := Finset.insert_nonempty _ _ - have hts : (t : Set E) ⊆ Set.range fun g : G => π g x₀ := by - intro x hx - rcases Finset.mem_insert.mp hx with rfl | hx - · exact ⟨1, by simp⟩ - · exact hs hx - have htspan : Submodule.span ℂ (t : Set E) = ⊤ := by - apply top_unique - rw [← hspan, ← hss] - exact Submodule.span_mono (by intro x hx; exact Finset.mem_insert_of_mem hx) - have hmem : finiteFrame t ∈ frameHull π x₀ := by - apply subset_closure - apply t.centerMass_mem_convexHull (fun _ _ => by norm_num) - · simpa only [Finset.sum_const, nsmul_eq_mul, mul_one] using - (show (0 : ℝ) < t.card from by exact_mod_cast htn.card_pos) - · intro v hv - obtain ⟨g,rfl⟩ := hts hv - exact ⟨g,rfl⟩ - have hstrict (x : E) (hx : x ≠ 0) : 0 < quadraticForm (finiteFrame t) x := by - rw [finiteFrame_quadratic] - exact mul_pos (inv_pos.mpr (by exact_mod_cast htn.card_pos)) (finite_frame_strict t htspan hx) - obtain ⟨ε,hε,hε₀⟩ := positive_coercive (finiteFrame t) hstrict - obtain ⟨T,hT,hp,hc,hfix⟩ := exists_invariant_frame_of_coercive π x₀ (finiteFrame t) - hmem (finiteFrame_positive t htn) ε hε hε₀ - have hinj : Function.Injective T := by - apply LinearMap.ker_eq_bot.mp - apply LinearMap.ker_eq_bot'.mpr - intro x hx - have hh := hc x - change ε * ‖x‖^2 ≤ (inner ℂ x (T x)).re at hh - rw [hx, inner_zero_right, Complex.zero_re] at hh - have hn : ‖x‖^2 = 0 := le_antisymm (nonpos_of_mul_nonpos_right hh hε) (sq_nonneg _) - exact norm_eq_zero.mp (sq_eq_zero_iff.mp hn) - exact ⟨T,hT,hp,⟨hinj, (LinearMap.injective_iff_surjective).mp hinj⟩,hfix⟩ - -end RowColumn.UnitaryFrame - -end -end -end -end - - -section -noncomputable section -open scoped BigOperators ComplexConjugate ComplexOrder -namespace RowColumn.UnitaryFrame - -variable {A G : Type*} [Ring A] [Algebra ℂ A] [StarRing A] - [FiniteDimensional ℂ A] [Group G] - -/-- Algebraic and convex reconstruction from a spanning unitary group. The -trace is the physical trace, not the trace of the algebra's regular action. -/ -theorem exists_density (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) - (hinner : ∀ x y, core.inner x y = τ (star x * y)) - (u : G →* unitary A) - (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) : - ∃ D : A, τ D = (Module.finrank ℂ A : ℂ) ∧ - (∀ x : A, 0 ≤ τ (star x * x * D)) ∧ - (∀ (B : A) (ℓ : A →ₗ[ℂ] ℂ) (R : ℝ), - (∀ g, ‖τ (star (u g : A) * (B*D)) * ℓ (u g : A)‖ ≤ R) → ‖ℓ B‖ ≤ R) := by - let : NormedAddCommGroup A := core.toNormedAddCommGroup - let : InnerProductSpace ℂ A := InnerProductSpace.ofCore { __ := core } - change ∀ x y, inner ℂ x y = τ (star x*y) at hinner - let π : G →* A ≃ₗᵢ[ℂ] A := - { toFun := fun g => - (Units.mulLeftLinearEquiv ℂ A (Unitary.toUnits (u g))).isometryOfInner (by - intro x y - change inner ℂ ((u g : A)*x) ((u g : A)*y) = inner ℂ x y - simp only [hinner, star_mul, mul_assoc] - rw [← mul_assoc (star (u g : A)), Unitary.coe_star_mul_self, one_mul]) - map_one' := by ext x; simp - map_mul' := by intros g h; ext x; simp } - have hπ (g : G) (x : A) : π g x = (u g : A)*x := rfl - obtain ⟨T,hT,hpos,hbij,hfix⟩ := exists_invariant_frame π 1 (by simpa only [hπ, mul_one] using hspan) - have heq (g : G) (x : A) : T ((u g : A)*x) = (u g : A)*T x := by - have he := LinearMap.congr_fun (hfix g) (π g x) - change π g (T ((π g).symm (π g x))) = T (π g x) at he - rw [(π g).symm_apply_apply] at he - exact he.symm - let C := T 1 - have hTm (x : A) : T x = x*C := by - have hx : x ∈ Submodule.span ℂ (Set.range fun g : G => (u g : A)) := by rw [hspan]; trivial - induction hx using Submodule.span_induction with - | mem x hx => obtain ⟨g,rfl⟩ := hx; simpa only [mul_one] using heq g 1 - | zero => simp - | add x y hx hy hxt hyt => simp only [map_add, add_mul, hxt, hyt] - | smul c x hx hxt => simpa only [map_smul, smul_mul_assoc] using congrArg (c • ·) hxt - let e : A ≃ₗ[ℂ] A := LinearEquiv.ofBijective T hbij - let D : A := e.symm 1 - have hTD : T D = 1 := e.apply_symm_apply 1 - have hDC : D*C = 1 := (hTm D).symm.trans hTD - have hinv (x : A) : T (x*D) = x := by rw [hTm, mul_assoc, hDC, mul_one] - have heinv (x : A) : e.symm x = x*D := by - apply hbij.injective - exact (e.apply_symm_apply x).trans (hinv x).symm - have hip : e.symm.toLinearMap.IsPositive := hpos.toLinearMap_symm - have hDpos (x : A) : 0 ≤ τ (star x*x*D) := by - have hh := hip.inner_nonneg_right x - simpa only [LinearEquiv.coe_coe, heinv, hinner, mul_assoc] using hh - let f : (A →ₗ[ℂ] A) →ₗ[ℂ] ℂ := - { toFun S := LinearMap.trace ℂ A (S ∘ₗ LinearMap.mulRight ℂ D) - map_add' S V := by simp only [LinearMap.add_comp, map_add] - map_smul' c S := by simp only [LinearMap.smul_comp, map_smul, RingHom.id_apply] } - have hf (g : G) : f (InnerProductSpace.rankOne ℂ (π g 1) (π g 1)).toLinearMap = τ D := by - change LinearMap.trace ℂ A (_ ∘ₗ _) = _ - rw [LinearMap.trace_comp_comm'] - have he : LinearMap.mulRight ℂ D ∘ₗ - (InnerProductSpace.rankOne ℂ (π g 1) (π g 1)).toLinearMap = - (InnerProductSpace.rankOne ℂ ((π g 1)*D) (π g 1)).toLinearMap := by - ext x - simp only [LinearMap.comp_apply, LinearMap.mulRight_apply, - ContinuousLinearMap.coe_coe, InnerProductSpace.rankOne_apply, smul_mul_assoc] - rw [he] - change (InnerProductSpace.rankOne ℂ ((π g 1)*D) (π g 1)).trace ℂ A = _ - rw [InnerProductSpace.trace_rankOne, hinner, hπ, mul_one, - ← mul_assoc, Unitary.coe_star_mul_self, one_mul] - let : NormedAddCommGroup (A →ₗ[ℂ] A) := HilbertSchmidt.endCore.toNormedAddCommGroup - let : InnerProductSpace ℂ (A →ₗ[ℂ] A) := - InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := A) } - let : InnerProductSpace ℝ (A →ₗ[ℂ] A) := InnerProductSpace.complexToReal - have hfc : ∀ S ∈ frameHull π 1, f S = τ D := by - change closure (convexHull ℝ _) ⊆ {S | f S = τ D} - apply closure_minimal - · apply convexHull_min - · rintro _ ⟨g,rfl⟩; exact hf g - · intro S hS V hV a b ha hb hab - change f (a • S + b • V) = τ D - rw [map_add, ← Complex.coe_smul a S, ← Complex.coe_smul b V, map_smul, map_smul, hS, hV] - rw [← add_smul, ← Complex.ofReal_add, hab, Complex.ofReal_one, one_smul] - · exact isClosed_eq f.toContinuousLinearMap.continuous continuous_const - have hτD : τ D = (Module.finrank ℂ A : ℂ) := by - rw [← hfc T hT] - have hcomp : T ∘ₗ LinearMap.mulRight ℂ D = LinearMap.id := by ext x; exact hinv x - change LinearMap.trace ℂ A (_ ∘ₗ _) = _ - rw [hcomp, LinearMap.trace_id] - refine ⟨D,hτD,hDpos,?_⟩ - intro B ℓ R hR - let l : (A →ₗ[ℂ] A) →ₗ[ℂ] ℂ := - { toFun S := ℓ (S (B*D)) - map_add' S V := by simp only [LinearMap.add_apply, map_add] - map_smul' c S := by simp only [LinearMap.smul_apply, map_smul, RingHom.id_apply] } - have hl : ∀ S ∈ frameHull π 1, ‖l S‖ ≤ R := by - change closure (convexHull ℝ _) ⊆ {S | ‖l S‖ ≤ R} - apply closure_minimal - · apply convexHull_min - · rintro _ ⟨g,rfl⟩ - change ‖ℓ ((InnerProductSpace.rankOne ℂ (π g 1) (π g 1)) (B*D))‖ ≤ R - simpa only [l, LinearMap.coe_mk, AddHom.coe_mk, ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply, map_smul, hinner, hπ, mul_one, smul_eq_mul] using hR g - · intro S hS V hV a b ha hb hab - change ‖l (a • S + b • V)‖ ≤ R - rw [map_add, ← Complex.coe_smul a S, ← Complex.coe_smul b V, map_smul, map_smul] - calc - _ ≤ ‖(a : ℂ) • l S‖ + ‖(b : ℂ) • l V‖ := norm_add_le _ _ - _ = a * ‖l S‖ + b * ‖l V‖ := by simp only [norm_smul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb] - _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hS ha) (mul_le_mul_of_nonneg_left hV hb) - _ = R := by rw [← add_mul, hab, one_mul] - · exact isClosed_le l.toContinuousLinearMap.continuous.norm continuous_const - simpa only [l, LinearMap.coe_mk, AddHom.coe_mk, hinv] using hl T hT - -end RowColumn.UnitaryFrame - -end -end - -end OAI +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators ComplexConjugate +namespace RowColumn.HilbertSchmidt +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +/-- The algebraic Hilbert--Schmidt scalar product, irrespective of the operator +norm on the carrier. A core is used to avoid changing any source norm. -/ +def hsInner (T U : E →ₗ[ℂ] E) : ℂ := + LinearMap.trace ℂ E (LinearMap.adjoint T ∘ₗ U) + +lemma hsInner_basis (T U : E →ₗ[ℂ] E) : + hsInner T U = ∑ i, inner ℂ (T (stdOrthonormalBasis ℂ E i)) + (U (stdOrthonormalBasis ℂ E i)) := by + rw [hsInner, LinearMap.trace_eq_sum_inner _ (stdOrthonormalBasis ℂ E)] + simp only [LinearMap.comp_apply, LinearMap.adjoint_inner_right] + +@[instance_reducible] +def endCore : InnerProductSpace.Core ℂ (E →ₗ[ℂ] E) where + inner := hsInner + conj_inner_symm T U := by + simp only [hsInner_basis, map_sum, inner_conj_symm] + re_inner_nonneg T := by + rw [hsInner_basis, map_sum] + exact Finset.sum_nonneg fun _ _ => inner_self_nonneg + add_left T U V := by + simp only [hsInner_basis, LinearMap.add_apply, inner_add_left, Finset.sum_add_distrib] + smul_left T U z := by + simp only [hsInner_basis, LinearMap.smul_apply, inner_smul_left, Finset.mul_sum] + definite T h := by + have hh : ∑ i, ‖T (stdOrthonormalBasis ℂ E i)‖^2 = 0 := by + have he := congrArg (RCLike.re : ℂ → ℝ) h + simpa only [hsInner_basis, map_sum, map_zero, inner_self_eq_norm_sq] using he + have hz (i : Fin (Module.finrank ℂ E)) : T (stdOrthonormalBasis ℂ E i) = 0 := by + have hi := (Finset.sum_eq_zero_iff_of_nonneg (fun j (_ : j ∈ Finset.univ) => + sq_nonneg ‖T (stdOrthonormalBasis ℂ E j)‖)).mp hh i (Finset.mem_univ i) + exact norm_eq_zero.mp (sq_eq_zero_iff.mp hi) + apply (stdOrthonormalBasis ℂ E).toBasis.ext + intro i + simpa using hz i + +lemma adjoint_isometry (u : E ≃ₗᵢ[ℂ] E) : + LinearMap.adjoint u.toLinearEquiv.toLinearMap = u.symm.toLinearEquiv.toLinearMap := by + apply LinearMap.ext + intro x + apply ext_inner_right ℂ + intro y + rw [LinearMap.adjoint_inner_left] + change inner ℂ x (u y) = inner ℂ (u.symm x) y + simpa only [u.apply_symm_apply] using u.inner_map_map (u.symm x) y + +lemma hsInner_conj (u : E ≃ₗᵢ[ℂ] E) (T V : E →ₗ[ℂ] E) : + hsInner (u.toLinearEquiv.conj T) (u.toLinearEquiv.conj V) = hsInner T V := by + rw [hsInner_basis] + conv_rhs => rw [hsInner, LinearMap.trace_eq_sum_inner _ + ((stdOrthonormalBasis ℂ E).map u.symm)] + apply Finset.sum_congr rfl + intro i _ + simp only [LinearMap.comp_apply, LinearMap.adjoint_inner_right, + OrthonormalBasis.map_apply, LinearEquiv.conj_apply] + change inner ℂ (u (T (u.symm (stdOrthonormalBasis ℂ E i)))) + (u (V (u.symm (stdOrthonormalBasis ℂ E i)))) = _ + exact u.inner_map_map _ _ + +end RowColumn.HilbertSchmidt + +noncomputable section +open scoped RealInnerProductSpace +namespace RowColumn.UnitaryFrame +variable {E ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] + +omit [CompleteSpace E] in +lemma norm_minimizer_unique [CompleteSpace E] (K : Set E) (hK : Convex ℝ K) + {x y : E} (hx : x ∈ K) (hy : y ∈ K) + (hxm : ∀ z ∈ K, ‖x‖ ≤ ‖z‖) (hym : ∀ z ∈ K, ‖y‖ ≤ ‖z‖) : x = y := by + have he : ‖x‖ = ‖y‖ := le_antisymm (hxm y hy) (hym x hx) + have hm : (1/2 : ℝ) • x + (1/2 : ℝ) • y ∈ K := + hK hx hy (by norm_num) (by norm_num) (by norm_num) + have hl := hxm _ hm + have hn : ‖(1/2 : ℝ) • x + (1/2 : ℝ) • y‖ = (1/2 : ℝ)*‖x+y‖ := by + rw [← smul_add, norm_smul, Real.norm_eq_abs, abs_of_nonneg (by norm_num)] + rw [hn] at hl + have hsq := mul_self_le_mul_self (norm_nonneg x) hl + have hp := parallelogram_law_with_norm ℝ x y + rw [← he] at hp + have hd := sq_nonneg ‖x-y‖ + have hz : ‖x-y‖ = 0 := by + nlinarith [norm_nonneg (x-y)] + exact sub_eq_zero.mp (norm_eq_zero.mp hz) + +/-- Simultaneous fixed point obtained from the unique minimum-norm point of a +closed convex invariant set. Applied to rank-one unitary frames, this replaces +Haar integration by finite-dimensional convex averaging. -/ +theorem exists_fixed_minimum (K : Set E) (hne : K.Nonempty) (hclosed : IsClosed K) + (hconv : Convex ℝ K) (L : ι → E →ₗᵢ[ℝ] E) + (hL : ∀ i x, x ∈ K → L i x ∈ K) : + ∃ x ∈ K, ∀ i, L i x = x := by + obtain ⟨x,hx,hm⟩ := exists_norm_eq_iInf_of_complete_convex hne hclosed.isComplete hconv (0 : E) + have hmin (z : E) (hz : z ∈ K) : ‖x‖ ≤ ‖z‖ := by + have hh : (⨅ w : K, ‖(0 : E)-w‖) ≤ ‖(0 : E)-z‖ := + ciInf_le (f := fun w : K => ‖(0 : E) - (w : E)‖) + ⟨0, Set.forall_mem_range.mpr (fun _ => norm_nonneg _)⟩ (⟨z,hz⟩ : K) + rw [← hm] at hh + simpa using hh + refine ⟨x,hx,fun i => ?_⟩ + exact norm_minimizer_unique K hconv (hL i x hx) hx + (fun z hz => by rw [(L i).norm_map]; exact hmin z hz) hmin + +end RowColumn.UnitaryFrame + +noncomputable section +open scoped BigOperators ComplexConjugate +namespace RowColumn.UnitaryFrame +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +def quadraticForm (T : E →ₗ[ℂ] E) (x : E) : ℝ := (inner ℂ x (T x)).re + +omit [FiniteDimensional ℂ E] in +lemma quadraticForm_real_smul [FiniteDimensional ℂ E] (T : E →ₗ[ℂ] E) (c : ℝ) (x : E) : + quadraticForm T (c • x) = c^2 * quadraticForm T x := by + simp only [quadraticForm, ← Complex.coe_smul, map_smul, inner_smul_left, + inner_smul_right, Complex.conj_ofReal] + simp [Complex.mul_re, pow_two, mul_assoc] + +lemma quadraticForm_continuous (T : E →ₗ[ℂ] E) : Continuous (quadraticForm T) := + Complex.continuous_re.comp (continuous_id.inner T.toContinuousLinearMap.continuous) + +/-- Strict positivity of a finite-dimensional frame is uniformly coercive. -/ +theorem positive_coercive (T : E →ₗ[ℂ] E) + (hT : ∀ x : E, x ≠ 0 → 0 < quadraticForm T x) : + ∃ ε : ℝ, 0 < ε ∧ ∀ x, ε * ‖x‖^2 ≤ quadraticForm T x := by + cases subsingleton_or_nontrivial E with + | inl h => + let := h + refine ⟨1, by norm_num, fun x => ?_⟩ + have he : x = 0 := Subsingleton.elim _ _ + simp [he, quadraticForm] + | inr h => + let := h + let : ProperSpace E := FiniteDimensional.proper ℂ E + have hn : (Metric.sphere (0 : E) 1).Nonempty := NormedSpace.sphere_nonempty.mpr (by norm_num) + obtain ⟨y,hy,hmin⟩ := (isCompact_sphere (0 : E) 1).exists_isMinOn hn + (quadraticForm_continuous T).continuousOn + have hny : ‖y‖ = 1 := by simpa using hy + have hpy : 0 < quadraticForm T y := hT y (by intro he; simp [he] at hny) + refine ⟨quadraticForm T y, hpy, fun x => ?_⟩ + by_cases hx : x = 0 + · simp [hx, quadraticForm] + · have hp : 0 < ‖x‖ := norm_pos_iff.mpr hx + have hu : ‖x‖⁻¹ • x ∈ Metric.sphere (0 : E) 1 := by + simp [norm_smul, ne_of_gt hp] + have hm : quadraticForm T y ≤ quadraticForm T (‖x‖⁻¹ • x) := hmin hu + rw [quadraticForm_real_smul] at hm + have hh := mul_le_mul_of_nonneg_right hm (sq_nonneg ‖x‖) + calc + _ ≤ (‖x‖⁻¹ ^ 2 * quadraticForm T x) * ‖x‖^2 := hh + _ = _ := by field_simp [ne_of_gt hp] + +end RowColumn.UnitaryFrame + +namespace RowColumn.UnitaryFrame +open scoped BigOperators ComplexOrder ComplexConjugate +variable {E G : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [Group G] + +local instance : NormedAddCommGroup (E →ₗ[ℂ] E) := HilbertSchmidt.endCore.toNormedAddCommGroup +local instance : InnerProductSpace ℂ (E →ₗ[ℂ] E) := + InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := E) } +local instance : InnerProductSpace ℝ (E →ₗ[ℂ] E) := InnerProductSpace.complexToReal + +def conjugationIsometry (u : E ≃ₗᵢ[ℂ] E) : + (E →ₗ[ℂ] E) →ₗᵢ[ℂ] (E →ₗ[ℂ] E) := + u.toLinearEquiv.conj.toLinearMap.isometryOfInner (HilbertSchmidt.hsInner_conj u) + +def conjugationReal (u : E ≃ₗᵢ[ℂ] E) : + (E →ₗ[ℂ] E) →ₗᵢ[ℝ] (E →ₗ[ℂ] E) where + toLinearMap := (conjugationIsometry u).toLinearMap.restrictScalars ℝ + norm_map' := (conjugationIsometry u).norm_map + +lemma conjugation_apply (u : E ≃ₗᵢ[ℂ] E) (T : E →ₗ[ℂ] E) (x : E) : + conjugationReal u T x = u (T (u.symm x)) := rfl + +lemma conjugation_rankOne (u : E ≃ₗᵢ[ℂ] E) (x : E) : + conjugationReal u (InnerProductSpace.rankOne ℂ x x).toLinearMap = + (InnerProductSpace.rankOne ℂ (u x) (u x)).toLinearMap := by + ext y + change u (inner ℂ x (u.symm y) • x) = inner ℂ (u x) y • u x + rw [map_smul] + congr 1 + simpa only [u.apply_symm_apply] using (u.inner_map_map x (u.symm y)).symm + +def matrixEntry (x y : E) : (E →ₗ[ℂ] E) →ₗ[ℂ] ℂ where + toFun T := inner ℂ x (T y) + map_add' T V := by simp only [LinearMap.add_apply, inner_add_right] + map_smul' c T := by simp only [LinearMap.smul_apply, inner_smul_right, smul_eq_mul, RingHom.id_apply] + +def quadraticEval (x : E) : (E →ₗ[ℂ] E) →ₗ[ℝ] ℝ where + toFun T := quadraticForm T x + map_add' T V := by simp [quadraticForm] + map_smul' c T := by + simp only [quadraticForm, LinearMap.smul_apply, ← Complex.coe_smul, inner_smul_right] + simp [Complex.mul_re] + +def coerciveSet (ε : ℝ) : Set (E →ₗ[ℂ] E) := + {T | ∀ x, ε * ‖x‖^2 ≤ quadraticForm T x} + +lemma coerciveSet_closed (ε : ℝ) : IsClosed (coerciveSet (E := E) ε) := by + rw [coerciveSet, Set.ofPred_forall] + apply isClosed_iInter + intro x + exact isClosed_le continuous_const + (show Continuous (fun T : E →ₗ[ℂ] E => quadraticForm T x) from + (quadraticEval x).toContinuousLinearMap.continuous) + +omit [FiniteDimensional ℂ E] in +lemma coerciveSet_convex [FiniteDimensional ℂ E] (ε : ℝ) : + Convex ℝ (coerciveSet (E := E) ε) := by + intro T hT V hV a b ha hb hab x + have h₁ := mul_le_mul_of_nonneg_left (hT x) ha + have h₂ := mul_le_mul_of_nonneg_left (hV x) hb + change ε * ‖x‖^2 ≤ quadraticEval x (a • T + b • V) + rw [map_add, map_smul, map_smul] + change ε * ‖x‖^2 ≤ a * quadraticForm T x + b * quadraticForm V x + calc + ε * ‖x‖^2 = (a+b) * (ε * ‖x‖^2) := by rw [hab, one_mul] + _ = a * (ε * ‖x‖^2) + b * (ε * ‖x‖^2) := add_mul _ _ _ + _ ≤ _ := add_le_add h₁ h₂ + +lemma positiveSet_closed : IsClosed {T : E →ₗ[ℂ] E | T.IsPositive} := by + have hs : IsClosed {T : E →ₗ[ℂ] E | T.IsSymmetric} := by + have he : {T : E →ₗ[ℂ] E | T.IsSymmetric} = + ⋂ x : E, ⋂ y : E, + {T | starRingEnd ℂ (matrixEntry y x T) = matrixEntry x y T} := by + ext T + simp only [Set.mem_ofPred_eq, Set.mem_iInter, matrixEntry, LinearMap.coe_mk, + AddHom.coe_mk, inner_conj_symm, LinearMap.IsSymmetric] + rw [he] + exact isClosed_iInter fun x => isClosed_iInter fun y => isClosed_eq + (Complex.continuous_conj.comp (matrixEntry y x).toContinuousLinearMap.continuous) + (matrixEntry x y).toContinuousLinearMap.continuous + have hn : IsClosed {T : E →ₗ[ℂ] E | ∀ x, 0 ≤ quadraticForm T x} := by + rw [Set.ofPred_forall] + apply isClosed_iInter + intro x + exact isClosed_le continuous_const + (show Continuous (fun T : E →ₗ[ℂ] E => quadraticForm T x) from + (quadraticEval x).toContinuousLinearMap.continuous) + have he : {T : E →ₗ[ℂ] E | T.IsPositive} = + {T | T.IsSymmetric} ∩ {T | ∀ x, 0 ≤ quadraticForm T x} := by + ext T + constructor + · intro h; exact ⟨h.isSymmetric, fun x => h.re_inner_nonneg_right x⟩ + · rintro ⟨hs,hn⟩ + refine ⟨hs, fun x => ?_⟩ + rw [inner_re_symm] + exact hn x + rw [he] + exact hs.inter hn + +omit [FiniteDimensional ℂ E] in +lemma positiveSet_convex [FiniteDimensional ℂ E] : Convex ℝ {T : E →ₗ[ℂ] E | T.IsPositive} := by + intro T hT V hV a b ha hb hab + change (a • T + b • V).IsPositive + rw [← Complex.coe_smul a T, ← Complex.coe_smul b V] + exact (hT.smul_of_nonneg (by exact_mod_cast ha)).add + (hV.smul_of_nonneg (by exact_mod_cast hb)) + +def frameHull (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) : Set (E →ₗ[ℂ] E) := + closure (convexHull ℝ (Set.range fun g : G => + (InnerProductSpace.rankOne ℂ (π g x₀) (π g x₀)).toLinearMap)) + +lemma frameHull_invariant (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) (g : G) : + Set.MapsTo (conjugationReal (π g)) (frameHull π x₀) (frameHull π x₀) := by + apply Set.MapsTo.closure _ (conjugationReal (π g)).continuous + rw [Set.mapsTo_iff_image_subset] + rw [← LinearIsometry.coe_toLinearMap, (conjugationReal (π g)).toLinearMap.image_convexHull] + apply convexHull_mono + rintro _ ⟨_, ⟨h,rfl⟩, rfl⟩ + refine ⟨g*h, ?_⟩ + change (InnerProductSpace.rankOne ℂ (π (g*h) x₀) (π (g*h) x₀)).toLinearMap = + conjugationReal (π g) (InnerProductSpace.rankOne ℂ (π h x₀) (π h x₀)).toLinearMap + rw [conjugation_rankOne, map_mul] + rfl + +lemma quadraticForm_conj (u : E ≃ₗᵢ[ℂ] E) (T : E →ₗ[ℂ] E) (x : E) : + quadraticForm (conjugationReal u T) x = quadraticForm T (u.symm x) := by + unfold quadraticForm + rw [conjugation_apply] + have hi := u.inner_map_map (u.symm x) (T (u.symm x)) + rw [u.apply_symm_apply] at hi + exact congrArg Complex.re hi + +/-- A genuine invariant strictly positive frame is obtained by convex averaging; +no Haar measure or compact-group orthogonality is taken as a hypothesis. -/ +theorem exists_invariant_frame_of_coercive + (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) + (T₀ : E →ₗ[ℂ] E) (hT₀ : T₀ ∈ frameHull π x₀) (hp₀ : T₀.IsPositive) + (ε : ℝ) (_ : 0 < ε) (hε₀ : T₀ ∈ coerciveSet ε) : + ∃ T : E →ₗ[ℂ] E, T ∈ frameHull π x₀ ∧ T.IsPositive ∧ + T ∈ coerciveSet ε ∧ ∀ g, conjugationReal (π g) T = T := by + let K := frameHull π x₀ ∩ ({T | T.IsPositive} ∩ coerciveSet ε) + have hc : IsClosed K := isClosed_closure.inter (positiveSet_closed.inter (coerciveSet_closed ε)) + have hv : Convex ℝ K := (convex_convexHull ℝ _).closure.inter + (positiveSet_convex.inter (coerciveSet_convex ε)) + have hL (g : G) (V : E →ₗ[ℂ] E) (hV : V ∈ K) : + conjugationReal (π g) V ∈ K := by + refine ⟨frameHull_invariant π x₀ g hV.1, ?_, ?_⟩ + · exact (LinearMap.isPositive_linearIsometryEquiv_conj_iff (π g)).mpr hV.2.1 + · intro x + rw [quadraticForm_conj] + simpa only [(π g).symm.norm_map] using hV.2.2 ((π g).symm x) + obtain ⟨T,hT,hfix⟩ := exists_fixed_minimum K ⟨T₀,hT₀,hp₀,hε₀⟩ hc hv + (fun g => conjugationReal (π g)) hL + exact ⟨T,hT.1,hT.2.1,hT.2.2,hfix⟩ + +end RowColumn.UnitaryFrame +namespace RowColumn.UnitaryFrame +open scoped BigOperators ComplexOrder ComplexConjugate +variable {E G : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] [Group G] + +omit [FiniteDimensional ℂ E] in +lemma rankOne_quadratic [FiniteDimensional ℂ E] (v x : E) : + quadraticForm (InnerProductSpace.rankOne ℂ v v).toLinearMap x = + Complex.normSq (inner ℂ v x) := by + change (inner ℂ x (inner ℂ v x • v)).re = _ + rw [inner_smul_right, ← inner_conj_symm x v, Complex.mul_conj, Complex.ofReal_re] + +omit [FiniteDimensional ℂ E] in +lemma finite_frame_strict [FiniteDimensional ℂ E] (s : Finset E) + (hs : Submodule.span ℂ (s : Set E) = ⊤) + {x : E} (hx : x ≠ 0) : 0 < ∑ v ∈ s, Complex.normSq (inner ℂ v x) := by + have hn : 0 ≤ ∑ v ∈ s, Complex.normSq (inner ℂ v x) := + Finset.sum_nonneg fun _ _ => Complex.normSq_nonneg _ + by_contra h + have hz := le_antisymm (le_of_not_gt h) hn + have hi (v : E) (hv : v ∈ s) : inner ℂ v x = 0 := + Complex.normSq_eq_zero.mp ((Finset.sum_eq_zero_iff_of_nonneg + (fun _ _ => Complex.normSq_nonneg _)).mp hz v hv) + have hall (v : E) (hv : v ∈ Submodule.span ℂ (s : Set E)) : inner ℂ v x = 0 := by + induction hv using Submodule.span_induction with + | mem v hv => exact hi v hv + | zero => simp + | add u v hu hv heu hev => simp [heu, hev] + | smul c v hv hv' => simp [hv'] + exact hx ((inner_self_eq_zero (𝕜 := ℂ)).mp (hall x (by rw [hs]; trivial))) + +def finiteFrame (s : Finset E) : E →ₗ[ℂ] E := + s.centerMass (fun _ => (1 : ℝ)) + (fun v => (InnerProductSpace.rankOne ℂ v v).toLinearMap) + +lemma finiteFrame_quadratic (s : Finset E) (x : E) : + quadraticForm (finiteFrame s) x = (s.card : ℝ)⁻¹ * + ∑ v ∈ s, Complex.normSq (inner ℂ v x) := by + change quadraticEval x (finiteFrame s) = _ + simp only [finiteFrame, Finset.centerMass, one_smul, Finset.sum_const, + nsmul_eq_mul, mul_one, map_smul, map_sum, smul_eq_mul] + congr 1 + apply Finset.sum_congr rfl + intro v _ + exact rankOne_quadratic v x + +local instance : NormedAddCommGroup (E →ₗ[ℂ] E) := HilbertSchmidt.endCore.toNormedAddCommGroup +local instance : InnerProductSpace ℂ (E →ₗ[ℂ] E) := + InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := E) } +local instance : InnerProductSpace ℝ (E →ₗ[ℂ] E) := InnerProductSpace.complexToReal + +lemma finiteFrame_positive (s : Finset E) (hs : s.Nonempty) : (finiteFrame s).IsPositive := by + change s.centerMass (fun _ => (1 : ℝ)) + (fun v => (InnerProductSpace.rankOne ℂ v v).toLinearMap) ∈ + {T : E →ₗ[ℂ] E | T.IsPositive} + apply (positiveSet_convex (E := E)).centerMass_mem (fun _ _ => by norm_num) + · simpa only [Finset.sum_const, nsmul_eq_mul, mul_one] using + (show (0 : ℝ) < s.card from by exact_mod_cast hs.card_pos) + · intro v _ + exact (InnerProductSpace.isPositive_rankOne_self v).toLinearMap + +/-- Spanning unitary orbits have an invertible positive invariant frame, with +its approximation by finite probability mixtures of the original orbit. -/ +theorem exists_invariant_frame (π : G →* E ≃ₗᵢ[ℂ] E) (x₀ : E) + (hspan : Submodule.span ℂ (Set.range fun g : G => π g x₀) = ⊤) : + ∃ T : E →ₗ[ℂ] E, T ∈ frameHull π x₀ ∧ T.IsPositive ∧ + Function.Bijective T ∧ ∀ g, conjugationReal (π g) T = T := by + classical + obtain ⟨s,hs,hcard,hss,hindep⟩ := Submodule.exists_finset_span_eq_linearIndepOn ℂ + (Set.range fun g : G => π g x₀) + let t := insert x₀ s + have htn : t.Nonempty := Finset.insert_nonempty _ _ + have hts : (t : Set E) ⊆ Set.range fun g : G => π g x₀ := by + intro x hx + rcases Finset.mem_insert.mp hx with rfl | hx + · exact ⟨1, by simp⟩ + · exact hs hx + have htspan : Submodule.span ℂ (t : Set E) = ⊤ := by + apply top_unique + rw [← hspan, ← hss] + exact Submodule.span_mono (by intro x hx; exact Finset.mem_insert_of_mem hx) + have hmem : finiteFrame t ∈ frameHull π x₀ := by + apply subset_closure + apply t.centerMass_mem_convexHull (fun _ _ => by norm_num) + · simpa only [Finset.sum_const, nsmul_eq_mul, mul_one] using + (show (0 : ℝ) < t.card from by exact_mod_cast htn.card_pos) + · intro v hv + obtain ⟨g,rfl⟩ := hts hv + exact ⟨g,rfl⟩ + have hstrict (x : E) (hx : x ≠ 0) : 0 < quadraticForm (finiteFrame t) x := by + rw [finiteFrame_quadratic] + exact mul_pos (inv_pos.mpr (by exact_mod_cast htn.card_pos)) (finite_frame_strict t htspan hx) + obtain ⟨ε,hε,hε₀⟩ := positive_coercive (finiteFrame t) hstrict + obtain ⟨T,hT,hp,hc,hfix⟩ := exists_invariant_frame_of_coercive π x₀ (finiteFrame t) + hmem (finiteFrame_positive t htn) ε hε hε₀ + have hinj : Function.Injective T := by + apply LinearMap.ker_eq_bot.mp + apply LinearMap.ker_eq_bot'.mpr + intro x hx + have hh := hc x + change ε * ‖x‖^2 ≤ (inner ℂ x (T x)).re at hh + rw [hx, inner_zero_right, Complex.zero_re] at hh + have hn : ‖x‖^2 = 0 := le_antisymm (nonpos_of_mul_nonpos_right hh hε) (sq_nonneg _) + exact norm_eq_zero.mp (sq_eq_zero_iff.mp hn) + exact ⟨T,hT,hp,⟨hinj, (LinearMap.injective_iff_surjective).mp hinj⟩,hfix⟩ + +end RowColumn.UnitaryFrame + +end +end +end +end + + +section +noncomputable section +open scoped BigOperators ComplexConjugate ComplexOrder +namespace RowColumn.UnitaryFrame + +variable {A G : Type*} [Ring A] [Algebra ℂ A] [StarRing A] + [FiniteDimensional ℂ A] [Group G] + +/-- Algebraic and convex reconstruction from a spanning unitary group. The +trace is the physical trace, not the trace of the algebra's regular action. -/ +theorem exists_density (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) + (hinner : ∀ x y, core.inner x y = τ (star x * y)) + (u : G →* unitary A) + (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) : + ∃ D : A, τ D = (Module.finrank ℂ A : ℂ) ∧ + (∀ x : A, 0 ≤ τ (star x * x * D)) ∧ + (∀ (B : A) (ℓ : A →ₗ[ℂ] ℂ) (R : ℝ), + (∀ g, ‖τ (star (u g : A) * (B*D)) * ℓ (u g : A)‖ ≤ R) → ‖ℓ B‖ ≤ R) := by + let : NormedAddCommGroup A := core.toNormedAddCommGroup + let : InnerProductSpace ℂ A := InnerProductSpace.ofCore { __ := core } + change ∀ x y, inner ℂ x y = τ (star x*y) at hinner + let π : G →* A ≃ₗᵢ[ℂ] A := + { toFun := fun g => + (Units.mulLeftLinearEquiv ℂ A (Unitary.toUnits (u g))).isometryOfInner (by + intro x y + change inner ℂ ((u g : A)*x) ((u g : A)*y) = inner ℂ x y + simp only [hinner, star_mul, mul_assoc] + rw [← mul_assoc (star (u g : A)), Unitary.coe_star_mul_self, one_mul]) + map_one' := by ext x; simp + map_mul' := by intros g h; ext x; simp } + have hπ (g : G) (x : A) : π g x = (u g : A)*x := rfl + obtain ⟨T,hT,hpos,hbij,hfix⟩ := exists_invariant_frame π 1 (by simpa only [hπ, mul_one] using hspan) + have heq (g : G) (x : A) : T ((u g : A)*x) = (u g : A)*T x := by + have he := LinearMap.congr_fun (hfix g) (π g x) + change π g (T ((π g).symm (π g x))) = T (π g x) at he + rw [(π g).symm_apply_apply] at he + exact he.symm + let C := T 1 + have hTm (x : A) : T x = x*C := by + have hx : x ∈ Submodule.span ℂ (Set.range fun g : G => (u g : A)) := by rw [hspan]; trivial + induction hx using Submodule.span_induction with + | mem x hx => obtain ⟨g,rfl⟩ := hx; simpa only [mul_one] using heq g 1 + | zero => simp + | add x y hx hy hxt hyt => simp only [map_add, add_mul, hxt, hyt] + | smul c x hx hxt => simpa only [map_smul, smul_mul_assoc] using congrArg (c • ·) hxt + let e : A ≃ₗ[ℂ] A := LinearEquiv.ofBijective T hbij + let D : A := e.symm 1 + have hTD : T D = 1 := e.apply_symm_apply 1 + have hDC : D*C = 1 := (hTm D).symm.trans hTD + have hinv (x : A) : T (x*D) = x := by rw [hTm, mul_assoc, hDC, mul_one] + have heinv (x : A) : e.symm x = x*D := by + apply hbij.injective + exact (e.apply_symm_apply x).trans (hinv x).symm + have hip : e.symm.toLinearMap.IsPositive := hpos.toLinearMap_symm + have hDpos (x : A) : 0 ≤ τ (star x*x*D) := by + have hh := hip.inner_nonneg_right x + simpa only [LinearEquiv.coe_coe, heinv, hinner, mul_assoc] using hh + let f : (A →ₗ[ℂ] A) →ₗ[ℂ] ℂ := + { toFun S := LinearMap.trace ℂ A (S ∘ₗ LinearMap.mulRight ℂ D) + map_add' S V := by simp only [LinearMap.add_comp, map_add] + map_smul' c S := by simp only [LinearMap.smul_comp, map_smul, RingHom.id_apply] } + have hf (g : G) : f (InnerProductSpace.rankOne ℂ (π g 1) (π g 1)).toLinearMap = τ D := by + change LinearMap.trace ℂ A (_ ∘ₗ _) = _ + rw [LinearMap.trace_comp_comm'] + have he : LinearMap.mulRight ℂ D ∘ₗ + (InnerProductSpace.rankOne ℂ (π g 1) (π g 1)).toLinearMap = + (InnerProductSpace.rankOne ℂ ((π g 1)*D) (π g 1)).toLinearMap := by + ext x + simp only [LinearMap.comp_apply, LinearMap.mulRight_apply, + ContinuousLinearMap.coe_coe, InnerProductSpace.rankOne_apply, smul_mul_assoc] + rw [he] + change (InnerProductSpace.rankOne ℂ ((π g 1)*D) (π g 1)).trace ℂ A = _ + rw [InnerProductSpace.trace_rankOne, hinner, hπ, mul_one, + ← mul_assoc, Unitary.coe_star_mul_self, one_mul] + let : NormedAddCommGroup (A →ₗ[ℂ] A) := HilbertSchmidt.endCore.toNormedAddCommGroup + let : InnerProductSpace ℂ (A →ₗ[ℂ] A) := + InnerProductSpace.ofCore { __ := HilbertSchmidt.endCore (E := A) } + let : InnerProductSpace ℝ (A →ₗ[ℂ] A) := InnerProductSpace.complexToReal + have hfc : ∀ S ∈ frameHull π 1, f S = τ D := by + change closure (convexHull ℝ _) ⊆ {S | f S = τ D} + apply closure_minimal + · apply convexHull_min + · rintro _ ⟨g,rfl⟩; exact hf g + · intro S hS V hV a b ha hb hab + change f (a • S + b • V) = τ D + rw [map_add, ← Complex.coe_smul a S, ← Complex.coe_smul b V, map_smul, map_smul, hS, hV] + rw [← add_smul, ← Complex.ofReal_add, hab, Complex.ofReal_one, one_smul] + · exact isClosed_eq f.toContinuousLinearMap.continuous continuous_const + have hτD : τ D = (Module.finrank ℂ A : ℂ) := by + rw [← hfc T hT] + have hcomp : T ∘ₗ LinearMap.mulRight ℂ D = LinearMap.id := by ext x; exact hinv x + change LinearMap.trace ℂ A (_ ∘ₗ _) = _ + rw [hcomp, LinearMap.trace_id] + refine ⟨D,hτD,hDpos,?_⟩ + intro B ℓ R hR + let l : (A →ₗ[ℂ] A) →ₗ[ℂ] ℂ := + { toFun S := ℓ (S (B*D)) + map_add' S V := by simp only [LinearMap.add_apply, map_add] + map_smul' c S := by simp only [LinearMap.smul_apply, map_smul, RingHom.id_apply] } + have hl : ∀ S ∈ frameHull π 1, ‖l S‖ ≤ R := by + change closure (convexHull ℝ _) ⊆ {S | ‖l S‖ ≤ R} + apply closure_minimal + · apply convexHull_min + · rintro _ ⟨g,rfl⟩ + change ‖ℓ ((InnerProductSpace.rankOne ℂ (π g 1) (π g 1)) (B*D))‖ ≤ R + simpa only [l, LinearMap.coe_mk, AddHom.coe_mk, ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply, map_smul, hinner, hπ, mul_one, smul_eq_mul] using hR g + · intro S hS V hV a b ha hb hab + change ‖l (a • S + b • V)‖ ≤ R + rw [map_add, ← Complex.coe_smul a S, ← Complex.coe_smul b V, map_smul, map_smul] + calc + _ ≤ ‖(a : ℂ) • l S‖ + ‖(b : ℂ) • l V‖ := norm_add_le _ _ + _ = a * ‖l S‖ + b * ‖l V‖ := by simp only [norm_smul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb] + _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hS ha) (mul_le_mul_of_nonneg_left hV hb) + _ = R := by rw [← add_mul, hab, one_mul] + · exact isClosed_le l.toContinuousLinearMap.continuous.norm continuous_const + simpa only [l, LinearMap.coe_mk, AddHom.coe_mk, hinv] using hl T hT + +end RowColumn.UnitaryFrame + +end +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/KernelBounds.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/KernelBounds.lean index 6eedd88aab3b70d295a8e8594c70ff2d49bcb8d8..313fd809a15475ec72735757d577d62f4eff0998 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/KernelBounds.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/KernelBounds.lean @@ -1,145 +1,145 @@ -import OAI.Probability.CubeShuffle.FiniteKernel -import OAI.RepresentationTheory.FiniteUnitary.Sampling - -namespace OAI - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] - -noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := - finiteMean (fun ω => if a (P ω) x=y then 1 else 0) - -omit [Fintype G] in -lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) - (v : EuclideanSpace ℂ X) (x : X) : - DensityTransfer.applyKernel (actionKernel a P) v x = - (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by - simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, - Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] - rw [Finset.sum_comm] - calc - _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by - apply Finset.sum_congr rfl - intro ω _ - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro y _ - split_ifs <;> simp_all - _ = _ := by simp [Finset.mul_sum] - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) - (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : - DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = - normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by - ext x - rw [actionKernel_apply] - simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, - coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, - inner_smul_right,inner_sum] - apply Finset.sum_congr rfl - intro ω _ - have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x - change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = - inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h - rw [h] - ring - -noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : - Submodule ℂ V where - carrier := {w | IsFixed a x₀ ρ w} - zero_mem' := fun g hg => map_zero _ - add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] - smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] - -/-- Genuine multiplicity amplification: the family is produced from the -stabilizer-fixed space by unitary Schur orthogonality, not assumed. -/ -theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : - ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - let K := fixedSpace a x₀ ρ - let m := Module.finrank ℂ K - let : Nonempty X := ⟨x₀⟩ - let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ - let B := stdOrthonormalBasis ℂ K - let w : Fin m → V := fun i => (B i : V) - have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 - have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ - have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv - have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) - (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by - rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), - normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] - have h := DensityTransfer.multiplicity_amplification (actionKernel a P) - (fun x y => sampleLaw_nonneg (fun ω => a (P ω) x) y) hsym hrow - b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) - simpa only [Fintype.card_fin] using h - -end CubeShuffle.UnitaryFinite - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators Classical - -variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] in -lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : - sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by - simp only [sampleOperator,randomOperator,smul_apply, - sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] - -/-- FAC.7 as a genuine operator-norm bound for sample averages in an irrep. -/ -theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) - (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (P : Ω → G) - (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) - (hrow : ∀ x, ∑ y, actionKernel a P x y=1) - (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) - (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : - ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by - rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] - apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) - intro v hv - rw [sampleOperator_inv_apply] - exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : - Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where - toFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun g v hv => by - have h := U.apply_mem_toSubmodule (e.symm g) hv - change ρ (e (e.symm g)) v∈U.toSubmodule at h - simpa only [e.apply_symm_apply] using h } - invFun U := - { toSubmodule := U.toSubmodule - apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } - left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl - map_rel_iff' := Iff.rfl - -omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in -lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by - exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance - -end CubeShuffle.UnitaryFinite - -end OAI +import OAI.Probability.CubeShuffle.FiniteKernel +import OAI.RepresentationTheory.FiniteUnitary.Sampling + +namespace OAI + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G X Ω : Type*} [Group G] [Fintype G] [Fintype X] [Fintype Ω] + +noncomputable def actionKernel (a : G →* Equiv.Perm X) (P : Ω → G) (x y : X) : ℝ := + finiteMean (fun ω => if a (P ω) x=y then 1 else 0) + +omit [Fintype G] in +lemma actionKernel_apply (a : G →* Equiv.Perm X) (P : Ω → G) + (v : EuclideanSpace ℂ X) (x : X) : + DensityTransfer.applyKernel (actionKernel a P) v x = + (Fintype.card Ω:ℂ)⁻¹ * ∑ ω, v (a (P ω) x) := by + simp only [DensityTransfer.applyKernel_apply,actionKernel,finiteMean, + Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul] + rw [Finset.sum_comm] + calc + _ = ∑ ω, (Fintype.card Ω:ℂ)⁻¹ * ∑ y : X, if a (P ω) x=y then v y else 0 := by + apply Finset.sum_congr rfl + intro ω _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp_all + _ = _ := by simp [Finset.mul_sum] + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +noncomputable def randomOperator (ρ : Representation ℂ G V) (P : Ω → G) : Module.End ℂ V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω, ρ (P ω)⁻¹ + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma coefficient_random (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) + (P : Ω → G) (w : V) (hw : IsFixed a x₀ ρ w) (v : V) : + DensityTransfer.applyKernel (actionKernel a P) (normalizedCoefficient a x₀ ha ρ w v) = + normalizedCoefficient a x₀ ha ρ w (randomOperator ρ P v) := by + ext x + rw [actionKernel_apply] + simp only [normalizedCoefficient,PiLp.smul_apply,smul_eq_mul,Finset.mul_sum, + coefficient,randomOperator,LinearMap.smul_apply,LinearMap.sum_apply, + inner_smul_right,inner_sum] + apply Finset.sum_congr rfl + intro ω _ + have h := coefficient_action a x₀ ha ρ hρ w hw v (P ω) x + change inner ℂ (ρ (representative a x₀ ha (a (P ω) x)) w) v = + inner ℂ (ρ (representative a x₀ ha x) w) (ρ (P ω)⁻¹ v) at h + rw [h] + ring + +noncomputable def fixedSpace (a : G →* Equiv.Perm X) (x₀ : X) (ρ : Representation ℂ G V) : + Submodule ℂ V where + carrier := {w | IsFixed a x₀ ρ w} + zero_mem' := fun g hg => map_zero _ + add_mem' := fun hw hz g hg => by rw [map_add,hw g hg,hz g hg] + smul_mem' := fun c w hw g hg => by rw [map_smul,hw g hg] + +/-- Genuine multiplicity amplification: the family is produced from the +stabilizer-fixed space by unitary Schur orthogonality, not assumed. -/ +theorem operator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) (v : V) (hv : ‖v‖=1) : + ‖randomOperator ρ P v‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + let K := fixedSpace a x₀ ρ + let m := Module.finrank ℂ K + let : Nonempty X := ⟨x₀⟩ + let : Nonempty (Fin m) := ⟨⟨0,hm⟩⟩ + let B := stdOrthonormalBasis ℂ K + let w : Fin m → V := fun i => (B i : V) + have hfix (i : Fin m) : IsFixed a x₀ ρ (w i) := (B i).2 + have hw : Orthonormal ℂ w := B.orthonormal.comp_linearIsometry K.subtypeₗᵢ + have hc := normalizedCoefficient_orthonormal a x₀ ha ρ hρ w hw hfix v hv + have hn (i : Fin m) : ‖DensityTransfer.applyKernel (actionKernel a P) + (normalizedCoefficient a x₀ ha ρ (w i) v)‖ = ‖randomOperator ρ P v‖ := by + rw [coefficient_random a x₀ ha ρ hρ P (w i) (hfix i), + normalizedCoefficient_norm a x₀ ha ρ hρ (w i) (hfix i) (hw.norm_eq_one i)] + have h := DensityTransfer.multiplicity_amplification (actionKernel a P) + (fun x y => sampleLaw_nonneg (fun ω => a (P ω) x) y) hsym hrow + b z M hb hz hM0 hM _ hc (‖randomOperator ρ P v‖) (fun i => (hn i).ge) + simpa only [Fintype.card_fin] using h + +end CubeShuffle.UnitaryFinite + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators Classical + +variable {G H X Ω : Type*} [Group G] [Group H] [Fintype G] [Fintype X] [Fintype Ω] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] in +lemma sampleOperator_inv_apply (ρ : Representation ℂ G V) (P : Ω → G) (v : V) : + sampleOperator ρ (fun ω => (P ω)⁻¹) v=randomOperator ρ P v := by + simp only [sampleOperator,randomOperator,smul_apply, + sum_apply,continuousRepresentation_apply,LinearMap.smul_apply,LinearMap.sum_apply] + +/-- FAC.7 as a genuine operator-norm bound for sample averages in an irrep. -/ +theorem sampleOperator_amplification (a : G →* Equiv.Perm X) (x₀ : X) + (ha : ∀ x, ∃ g, a g x₀=x) (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (P : Ω → G) + (hsym : ∀ x y, actionKernel a P x y=actionKernel a P y x) + (hrow : ∀ x, ∑ y, actionKernel a P x y=1) + (b z M : ℝ) (hb : 0≤b) (hz : 0 ((Fintype.card X:ℝ)*actionKernel a P x y)^(1+b)) ≤ M) + (hm : 0 < Module.finrank ℂ (fixedSpace a x₀ ρ)) : + ‖sampleOperator ρ P‖ ≤ M*z^(-b)+Real.sqrt (z/(Module.finrank ℂ (fixedSpace a x₀ ρ):ℝ)) := by + rw [←ContinuousLinearMap.adjoint.norm_map (sampleOperator ρ P),←sampleOperator_inv ρ hρ] + apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) + intro v hv + rw [sampleOperator_inv_apply] + exact operator_amplification a x₀ ha ρ hρ P hsym hrow b z M hb hz hM0 hM hm v hv + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +noncomputable def subrepresentationEquiv (ρ : Representation ℂ G V) (e : H ≃* G) : + Subrepresentation (ρ.comp e.toMonoidHom) ≃o Subrepresentation ρ where + toFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun g v hv => by + have h := U.apply_mem_toSubmodule (e.symm g) hv + change ρ (e (e.symm g)) v∈U.toSubmodule at h + simpa only [e.apply_symm_apply] using h } + invFun U := + { toSubmodule := U.toSubmodule + apply_mem_toSubmodule := fun h _ hv => U.apply_mem_toSubmodule (e h) hv } + left_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + right_inv U := by apply Subrepresentation.toSubmodule_injective; rfl + map_rel_iff' := Iff.rfl + +omit [Fintype G] [Fintype X] [Fintype Ω] [FiniteDimensional ℂ V] in +lemma irreducible_comp_equiv (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (e : H ≃* G) : Representation.IsIrreducible (ρ.comp e.toMonoidHom) := by + exact (subrepresentationEquiv ρ e).isSimpleOrder_iff.mpr inferInstance + +end CubeShuffle.UnitaryFinite + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Reconstruction.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Reconstruction.lean index abd98b7251270e6238a74a4f05cbb455f967ab87..d7c21a4bbf897836b3487fa26c00654dae7d9654 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Reconstruction.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Reconstruction.lean @@ -1,699 +1,699 @@ -import OAI.RepresentationTheory.FiniteUnitary.Frames -import OAI.RepresentationTheory.RowColumn.Basic - -namespace OAI - -section -noncomputable section -open scoped BigOperators ComplexOrder -namespace RowColumn.UnitaryFrame -variable {A G : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] - [FiniteDimensional ℂ A] [Group G] - -omit [FiniteDimensional ℂ A] in -lemma positive_functional_bound (f : A →ₚ[ℂ] ℂ) (x : A) : - ‖f x‖ ≤ 4 * ‖f 1‖ * ‖x‖ := by - obtain ⟨y, hy_nonneg, hy_norm, hy⟩ := CStarAlgebra.exists_sum_four_nonneg x - conv_lhs => rw [hy] - simp only [map_sum, map_smul] - apply (norm_sum_le _ _).trans - simp only [norm_smul, norm_pow, Complex.norm_I, one_pow, one_mul] - apply (Finset.sum_le_sum (g := fun _ => ‖f 1‖ * ‖x‖) (fun i _ => ?_)).trans - · simp [mul_assoc] - · exact (f.norm_apply_le_of_nonneg _ (hy_nonneg i)).trans - (mul_le_mul_of_nonneg_left (hy_norm i) (norm_nonneg _)) - -/-- Finite-dimensional unitary reconstruction with polynomial Fourier cost. -Only the actual operator norm of B occurs; the auxiliary Hilbert norm is used -solely to construct the frame and does not alter that norm. -/ -theorem reconstruction_bound (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) - (hinner : ∀ x y, core.inner x y = τ (star x*y)) - (u : G →* unitary A) - (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) - (B : A) (ℓ : A →ₗ[ℂ] ℂ) (R : ℝ) (_ : 0 ≤ R) - (hU : ∀ g, ‖ℓ (u g : A)‖ ≤ R) : - ‖ℓ B‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ * R := by - obtain ⟨D,hD,hpos,hrec⟩ := exists_density τ core hinner u hspan - let φ : A →ₗ[ℂ] ℂ := τ.comp (LinearMap.mulRight ℂ D) - have hφpos (a : A) (ha : 0 ≤ a) : 0 ≤ φ a := by - have hh := hpos (CFC.sqrt a) - have hs : star (CFC.sqrt a) * CFC.sqrt a = a := by - rw [(IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg a)).star_eq] - exact CFC.sqrt_mul_sqrt_self a ha - change 0 ≤ τ (a*D) - simpa only [hs] using hh - let f : A →ₚ[ℂ] ℂ := PositiveLinearMap.mk₀ φ hφpos - have hf1 : ‖f 1‖ = (Module.finrank ℂ A : ℝ) := by - change ‖τ (1*D)‖ = _ - rw [one_mul, hD] - simp - apply hrec B ℓ - intro g - rw [← mul_assoc] - change ‖φ (star (u g : A)*B) * ℓ (u g : A)‖ ≤ _ - rw [norm_mul] - have hb : ‖φ (star (u g : A)*B)‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ := by - have hh := positive_functional_bound f (star (u g : A)*B) - rw [hf1] at hh - change ‖f (star (u g : A)*B)‖ ≤ _ - simpa only [← Unitary.coe_star, CStarRing.norm_coe_unitary_mul] using hh - exact mul_le_mul hb (hU g) (norm_nonneg _) (by positivity) - -end RowColumn.UnitaryFrame -noncomputable section -open scoped ComplexConjugate -namespace RowColumn.FiniteStarAlgebra -variable {A : Type*} [Ring A] [Module ℂ A] [StarRing A] [FiniteDimensional ℂ A] - -/-- A finite-dimensional two-sided star ideal has a central orthogonal unit. -The two inner-product identities hold for the actual Hilbert–Schmidt trace. -This constructs the central support used in the occupied-board filter. -/ -theorem complementary_central_projection (core : InnerProductSpace.Core ℂ A) (K : Submodule ℂ A) - (hL : ∀ a x, x ∈ K → a*x ∈ K) (hR : ∀ a x, x ∈ K → x*a ∈ K) - (hstar : ∀ x, x ∈ K → star x ∈ K) - (hadjL : ∀ a x y : A, core.inner (a*x) y = core.inner x (star a*y)) - (hadjR : ∀ a x y : A, core.inner (x*a) y = core.inner x (y*star a)) : - ∃ q : A, star q = q ∧ q*q = q ∧ (∀ a, q*a = a*q) ∧ - 1-q ∈ K ∧ (∀ x, x ∈ K → q*x = 0 ∧ x*q = 0) := by - let : NormedAddCommGroup A := core.toNormedAddCommGroup - let : InnerProductSpace ℂ A := InnerProductSpace.ofCore { __ := core } - change ∀ a x y : A, inner ℂ (a*x) y = inner ℂ x (star a*y) at hadjL - change ∀ a x y : A, inner ℂ (x*a) y = inner ℂ x (y*star a) at hadjR - have hoL (a x : A) (hx : x ∈ Kᗮ) : a*x ∈ Kᗮ := by - rw [Submodule.mem_orthogonal] at hx ⊢ - intro y hy - have hh := hx (star a*y) (hL (star a) y hy) - simpa only [hadjL, star_star] using hh - have hoR (a x : A) (hx : x ∈ Kᗮ) : x*a ∈ Kᗮ := by - rw [Submodule.mem_orthogonal] at hx ⊢ - intro y hy - have hh := hx (y*star a) (hR (star a) y hy) - simpa only [hadjR, star_star] using hh - have hz (x : A) (hk : x ∈ K) (ho : x ∈ Kᗮ) : x = 0 := - (inner_self_eq_zero (𝕜 := ℂ)).mp ((K.mem_orthogonal x).mp ho x hk) - let k : A := K.starProjection 1 - let q : A := 1-k - have hk : k ∈ K := (K.orthogonalProjectionOnto 1).property - have hq : q ∈ Kᗮ := K.sub_starProjection_mem_orthogonal 1 - have hqa (x : A) (hx : x ∈ K) : q*x = 0 := - hz _ (hL q x hx) (hoR x q hq) - have haq (x : A) (hx : x ∈ K) : x*q = 0 := - hz _ (hR q x hx) (hoL x q hq) - have hsk : star k = k := by - have e₁ : star k = k*star k := by - have he := hqa (star k) (hstar k hk) - change (1-k)*star k = 0 at he - simpa only [sub_mul, one_mul, sub_eq_zero] using he - have e₂ := congrArg star e₁ - simp only [star_star, star_mul] at e₂ - exact e₁.trans e₂.symm - refine ⟨q, ?_, ?_, ?_, ?_, fun x hx => ⟨hqa x hx, haq x hx⟩⟩ - · simp only [q, star_sub, star_one, hsk] - · change q*(1-k) = q - rw [mul_sub, mul_one, hqa k hk, sub_zero] - · intro a - have hka : k*a = k*a*k := by - have he := haq (k*a) (hR a k hk) - change (k*a)*(1-k) = 0 at he - simpa only [mul_sub, mul_one, sub_eq_zero] using he - have hak : a*k = k*a*k := by - have he := hqa (a*k) (hL a k hk) - change (1-k)*(a*k) = 0 at he - simpa only [sub_mul, one_mul, sub_eq_zero, ← mul_assoc] using he - change (1-k)*a = a*(1-k) - rw [sub_mul, one_mul, mul_sub, mul_one] - exact congrArg (fun z => a-z) (hka.trans hak.symm) - · simpa only [q, sub_sub_cancel] using hk - -end RowColumn.FiniteStarAlgebra - -namespace RowColumn.FiniteStarAlgebra -open scoped ComplexOrder -variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -abbrev Ambient := E →L[ℂ] E - -def algebraToEnd (A : StarSubalgebra ℂ (Ambient (E := E))) : A →ₗ[ℂ] (E →ₗ[ℂ] E) := - { toFun a := (a : Ambient (E := E)).toLinearMap - map_add' _ _ := rfl - map_smul' _ _ := rfl } - -lemma algebraToEnd_injective (A : StarSubalgebra ℂ (Ambient (E := E))) : - Function.Injective (algebraToEnd A) := by - intro a b h - apply Subtype.ext - apply ContinuousLinearMap.ext - intro x - exact LinearMap.congr_fun h x - -@[instance_reducible] -def algebraCore (A : StarSubalgebra ℂ (Ambient (E := E))) : InnerProductSpace.Core ℂ A where - inner a b := HilbertSchmidt.endCore.inner (algebraToEnd A a) (algebraToEnd A b) - conj_inner_symm a b := HilbertSchmidt.endCore.conj_inner_symm _ _ - re_inner_nonneg a := HilbertSchmidt.endCore.re_inner_nonneg _ - add_left a b c := by rw [map_add]; exact HilbertSchmidt.endCore.add_left _ _ _ - smul_left a b c := by rw [map_smul]; exact HilbertSchmidt.endCore.smul_left _ _ _ - definite a h := (algebraToEnd_injective A) (by simpa only [map_zero] using HilbertSchmidt.endCore.definite _ h) - -def physicalTrace (A : StarSubalgebra ℂ (Ambient (E := E))) : A →ₗ[ℂ] ℂ := - (LinearMap.trace ℂ E).comp (algebraToEnd A) - -lemma core_inner_trace (A : StarSubalgebra ℂ (Ambient (E := E))) (a b : A) : - (algebraCore A).inner a b = physicalTrace A (star a*b) := by - change LinearMap.trace ℂ E (LinearMap.adjoint (a : Ambient (E := E)).toLinearMap ∘ₗ - (b : Ambient (E := E)).toLinearMap) = LinearMap.trace ℂ E ((star (a : Ambient (E := E)) * (b : Ambient (E := E))).toLinearMap) - rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_toLinearMap] - rfl - -lemma physicalTrace_mul_comm (A : StarSubalgebra ℂ (Ambient (E := E))) (a b : A) : - physicalTrace A (a*b) = physicalTrace A (b*a) := - LinearMap.trace_comp_comm' (b : Ambient (E := E)).toLinearMap (a : Ambient (E := E)).toLinearMap - -/-- Restriction to a subspace preserved by the whole star algebra is a genuine -star homomorphism (both the subspace and its orthogonal complement are reducing). -/ -def restrictHom (A : StarSubalgebra ℂ (Ambient (E := E))) (F : Submodule ℂ E) - (hF : ∀ a : A, ∀ x ∈ F, (a : Ambient (E := E)) x ∈ F) : A →⋆ₐ[ℂ] (F →L[ℂ] F) where - toFun a := (a : Ambient (E := E)).restrict (hF a) - map_zero' := by ext x; rfl - map_add' a b := by ext x; rfl - map_one' := by ext x; rfl - map_mul' a b := by ext x; rfl - commutes' c := by ext x; rfl - map_star' a := by - apply ContinuousLinearMap.ext - intro x - apply ext_inner_right ℂ - intro y - rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_left] - change inner ℂ ((star (a : Ambient (E := E))) (x : E)) (y : E) = - inner ℂ (x : E) ((a : Ambient (E := E)) (y : E)) - rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_left] - -/-- Central support of a reducing physical subspace. Its algebraic kernel is -removed, so no other unsupported sector can inflate the Fourier norm. -/ -theorem exists_central_support (A : StarSubalgebra ℂ (Ambient (E := E))) (F : Submodule ℂ E) - (hF : ∀ a : A, ∀ x ∈ F, (a : Ambient (E := E)) x ∈ F) : - ∃ q : A, star q = q ∧ q*q=q ∧ (∀ a, q*a=a*q) ∧ - restrictHom A F hF q = 1 ∧ - (∀ a : A, restrictHom A F hF a = 0 → q*a=0) := by - let : FiniteDimensional ℂ A := FiniteDimensional.of_injective - (algebraToEnd A) (algebraToEnd_injective A) - let φ := restrictHom A F hF - let K := LinearMap.ker φ.toLinearMap - have hk (a : A) : a ∈ K ↔ φ a = 0 := Iff.rfl - obtain ⟨q,hs,hqq,hc,hkq,hkill⟩ := complementary_central_projection (algebraCore A) K - (fun a x hx => by rw [hk, map_mul, (hk x).mp hx, mul_zero]) - (fun a x hx => by rw [hk, map_mul, (hk x).mp hx, zero_mul]) - (fun x hx => by rw [hk, map_star, (hk x).mp hx]; exact star_zero (F →L[ℂ] F)) - (fun a x y => by simp only [core_inner_trace, star_mul, mul_assoc]) - (fun a x y => by - simp only [core_inner_trace, star_mul] - rw [mul_assoc, physicalTrace_mul_comm A (star a) _, mul_assoc]) - refine ⟨q,hs,hqq,hc,?_,fun a ha => (hkill a ((hk a).mpr ha)).1⟩ - have hh := (hk (1-q)).mp hkq - have he : 1-φ q=0 := by simpa only [map_sub, map_one] using hh - exact (sub_eq_zero.mp he).symm - -end RowColumn.FiniteStarAlgebra -noncomputable section -namespace RowColumn.FiniteStarAlgebra -variable {A B : Type*} [CStarAlgebra A] [CStarAlgebra B] - -def supportedAlgebra (q : A) (hs : star q = q) (hc : ∀ a, q*a=a*q) : - NonUnitalStarSubalgebra ℂ A where - carrier := {a | q*a=a} - zero_mem' := mul_zero q - add_mem' := by intro a b ha hb; change q*(a+b)=a+b; rw [mul_add, ha, hb] - mul_mem' := by intro a b ha hb; change q*(a*b)=a*b; rw [← mul_assoc, ha] - smul_mem' := by intro c a ha; change q*(c • a)=c • a; rw [mul_smul_comm, ha] - star_mem' := by - intro a ha - change q*star a=star a - rw [hc] - simpa only [star_mul, hs] using congrArg star ha - -lemma supportedAlgebra_closed (q : A) (hs : star q = q) (hc : ∀ a, q*a=a*q) : - IsClosed (supportedAlgebra q hs hc : Set A) := - isClosed_eq (continuous_const.mul continuous_id) continuous_id - -/-- Removing the kernel by its central support makes restriction isometric. -This avoids choosing irreducible compact-group carriers or using unproved -Schur--Weyl decompositions. -/ -theorem norm_supported_eq (φ : A →⋆ₐ[ℂ] B) (q : A) (hs : star q = q) - (hqq : q*q=q) (hc : ∀ a, q*a=a*q) (hq : φ q=1) - (hkill : ∀ a, φ a=0 → q*a=0) (a : A) : ‖q*a‖ = ‖φ a‖ := by - let J := supportedAlgebra q hs hc - let : IsClosed (J : Set A) := supportedAlgebra_closed q hs hc - let ψ : J →⋆ₙₐ[ℂ] B := φ.toNonUnitalStarAlgHom.comp (NonUnitalStarSubalgebraClass.subtype J) - have hinj : Function.Injective ψ := by - intro x y h - apply Subtype.ext - have he : φ ((x : A)-(y : A))=0 := by - rw [map_sub] - exact sub_eq_zero.mpr h - have hz := hkill _ he - change q*((x : A)-(y : A))=0 at hz - rw [mul_sub, x.property, y.property] at hz - exact sub_eq_zero.mp hz - let x : J := ⟨q*a, by change q*(q*a)=q*a; rw [← mul_assoc, hqq]⟩ - have hh := NonUnitalStarAlgHom.norm_map ψ hinj x - change ‖φ (q*a)‖ = ‖q*a‖ at hh - rw [map_mul, hq, one_mul] at hh - exact hh.symm - -end RowColumn.FiniteStarAlgebra -noncomputable section -open scoped BigOperators ComplexConjugate -namespace RowColumn.Isotypic -variable {G V E : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - (ρ : Representation ℂ G V) (τ : Representation ℂ G E) - -def carrier : Submodule ℂ E := Submodule.span ℂ - (Set.range fun p : Representation.IntertwiningMap ρ τ × V => p.1 p.2) - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in -lemma mem_carrier (f : Representation.IntertwiningMap ρ τ) (v : V) : f v ∈ carrier ρ τ := - Submodule.subset_span ⟨(f,v),rfl⟩ - -lemma projection_intertwines (F : Submodule ℂ E) - (hF : ∀ g x, x ∈ F → τ g x ∈ F) - (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) : - ∀ g x, F.starProjection (τ g x) = τ g (F.starProjection x) := by - intro g x - let e : E →ₗᵢ[ℂ] E := (τ g).isometryOfInner (hτ g) - have hmap : F.map e.toLinearMap = F := by - apply le_antisymm - · rintro _ ⟨y,hy,rfl⟩ - exact hF g y hy - · intro y hy - refine ⟨τ g⁻¹ y, hF g⁻¹ y hy, ?_⟩ - change (τ g * τ g⁻¹) y = y - rw [← map_mul, mul_inv_cancel, map_one] - rfl - have he := e.map_starProjection F x - simpa only [hmap, e, LinearMap.coe_isometryOfInner] using he.symm - -omit [FiniteDimensional ℂ V] in -/-- On an isotypic unitary representation, every eigenspace of an operator in -the group commutant has dimension at least that of the irreducible type. -/ -theorem eigenspace_finrank [Representation.IsIrreducible ρ] - (hspan : carrier ρ τ = ⊤) - (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) - (T : E →ₗ[ℂ] E) (hT : ∀ g x, T (τ g x) = τ g (T x)) - (μ : ℂ) (hμ : Module.End.HasEigenvalue T μ) : - Module.finrank ℂ V ≤ Module.finrank ℂ (Module.End.eigenspace T μ) := by - classical - let F := Module.End.eigenspace T μ - have hf (g : G) (x : E) (hx : x ∈ F) : τ g x ∈ F := by - rw [Module.End.mem_eigenspace_iff] at hx ⊢ - rw [hT, hx, map_smul] - let P : Representation.IntertwiningMap τ τ := - { toLinearMap := F.starProjection.toLinearMap - isIntertwining' g := by ext x; exact projection_intertwines τ F hf hτ g x } - have hex : ∃ f : Representation.IntertwiningMap ρ τ, P.comp f ≠ 0 := by - by_contra! h - have hz (x : E) (hx : x ∈ carrier ρ τ) : P x = 0 := by - induction hx using Submodule.span_induction with - | mem x hx => - obtain ⟨⟨f,v⟩,rfl⟩ := hx - exact congrArg (fun L : Representation.IntertwiningMap ρ τ => L v) (h f) - | zero => exact map_zero P - | add x y hx hy hpx hpy => simp only [map_add, hpx, hpy, add_zero] - | smul c x hx hpx => simp only [map_smul, hpx, smul_zero] - obtain ⟨x,hx,hxn⟩ := hμ.exists_hasEigenvector - have he := hz x (by rw [hspan]; trivial) - change F.starProjection x = 0 at he - rw [F.starProjection_eq_self_iff.mpr hx] at he - exact hxn he - obtain ⟨f,hfne⟩ := hex - have hi : Function.Injective (P.comp f) := - (Representation.IsIrreducible.injective_or_eq_zero (P.comp f)).resolve_right hfne - let L : V →ₗ[ℂ] F := (P.comp f).toLinearMap.codRestrict F (fun v => - (F.orthogonalProjectionOnto (f v)).property) - apply LinearMap.finrank_le_finrank_of_injective (f := L) - intro x y h - exact hi (congrArg Subtype.val h) - -end RowColumn.Isotypic -namespace RowColumn.Isotypic -variable {G V E : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - (ρ : Representation ℂ G V) (τ : Representation ℂ G E) - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in -lemma carrier_invariant (g : G) (x : E) (hx : x ∈ carrier ρ τ) : τ g x ∈ carrier ρ τ := by - induction hx using Submodule.span_induction with - | mem x hx => - obtain ⟨⟨f,v⟩,rfl⟩ := hx - rw [← Representation.IntertwiningMap.isIntertwining ρ τ f] - exact mem_carrier ρ τ f _ - | zero => simpa only [map_zero] using (carrier ρ τ).zero_mem - | add x y hx hy hx' hy' => simpa only [map_add] using (carrier ρ τ).add_mem hx' hy' - | smul c x hx hx' => simpa only [map_smul] using (carrier ρ τ).smul_mem c hx' - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in -lemma carrier_commutant (T : E →ₗ[ℂ] E) (hT : ∀ g x, T (τ g x) = τ g (T x)) - (x : E) (hx : x ∈ carrier ρ τ) : T x ∈ carrier ρ τ := by - let t : Representation.IntertwiningMap τ τ := - { toLinearMap := T - isIntertwining' g := by ext x; exact hT g x } - induction hx using Submodule.span_induction with - | mem x hx => - obtain ⟨⟨f,v⟩,rfl⟩ := hx - exact mem_carrier ρ τ (t.comp f) v - | zero => simpa only [map_zero] using (carrier ρ τ).zero_mem - | add x y hx hy hx' hy' => simpa only [map_add] using (carrier ρ τ).add_mem hx' hy' - | smul c x hx hx' => simpa only [map_smul] using (carrier ρ τ).smul_mem c hx' - -def restricted : Representation ℂ G (carrier ρ τ) where - toFun g := (τ g).restrict (carrier_invariant ρ τ g) - map_one' := by ext x; exact LinearMap.congr_fun (map_one τ) x - map_mul' g h := by ext x; exact LinearMap.congr_fun (map_mul τ g h) x - -def restrictIntertwiner (f : Representation.IntertwiningMap ρ τ) : - Representation.IntertwiningMap ρ (restricted ρ τ) where - toLinearMap := f.toLinearMap.codRestrict (carrier ρ τ) (mem_carrier ρ τ f) - isIntertwining' g := by - ext v - exact Representation.IntertwiningMap.isIntertwining ρ τ f g v - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in -lemma restricted_unitary (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) : - ∀ g (x y : carrier ρ τ), inner ℂ (restricted ρ τ g x) (restricted ρ τ g y) = inner ℂ x y := by - intro g x y - exact hτ g x y - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in -lemma restricted_isotypic : carrier ρ (restricted ρ τ) = ⊤ := by - let F := carrier ρ τ - let K := (carrier ρ (restricted ρ τ)).map F.subtype - have hFK : F ≤ K := by - apply Submodule.span_le.mpr - rintro _ ⟨⟨f,v⟩,rfl⟩ - exact ⟨restrictIntertwiner ρ τ f v, mem_carrier ρ (restricted ρ τ) - (restrictIntertwiner ρ τ f) v, rfl⟩ - apply top_unique - intro x _ - obtain ⟨y,hy,hxy⟩ := hFK x.property - have he : y=x := Subtype.ext hxy - exact he ▸ hy - -end RowColumn.Isotypic -noncomputable section -open scoped BigOperators ComplexOrder -namespace RowColumn.SpectralMultiplicity -variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -lemma positive_norm_le_of_eigenvalues (T : E →L[ℂ] E) (hT : T.IsPositive) - (c : ℝ) (hc : 0 ≤ c) - (hval : ∀ i, hT.toLinearMap.isSymmetric.eigenvalues rfl i ≤ c) : ‖T‖ ≤ c := by - let b := hT.toLinearMap.isSymmetric.eigenvectorBasis rfl - apply T.opNorm_le_bound hc - intro x - apply le_of_sq_le_sq _ (mul_nonneg hc (norm_nonneg _)) - rw [← b.repr.norm_map (T x), ← b.repr.norm_map x, mul_pow] - rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, Finset.mul_sum] - apply Finset.sum_le_sum - intro i _ - have hi := hT.toLinearMap.nonneg_eigenvalues rfl i - have he := hT.toLinearMap.isSymmetric.eigenvectorBasis_apply_self_apply rfl x i - change (b.repr (T x)) i = _ at he - change ‖(b.repr (T x)) i‖^2 ≤ _ - rw [he, norm_mul, RCLike.norm_ofReal, abs_of_nonneg hi, mul_pow] - exact mul_le_mul_of_nonneg_right (sq_le_sq₀ hi hc |>.mpr (hval i)) (sq_nonneg _) - -/-- An eigenvalue supported on at least d dimensions pays a trace factor d. -This is the precise spectral normalization needed for the global filter. -/ -theorem norm_le_trace_div (T : E →L[ℂ] E) (hT : T.IsPositive) (d : ℕ) (hd : 0 < d) - (hmult : ∀ μ : ℂ, Module.End.HasEigenvalue T.toLinearMap μ → - d ≤ Module.finrank ℂ (Module.End.eigenspace T.toLinearMap μ)) : - ‖T‖ ≤ (LinearMap.trace ℂ E T.toLinearMap).re / d := by - have htrace : 0 ≤ (LinearMap.trace ℂ E T.toLinearMap).re := - (Complex.nonneg_iff.mp hT.toLinearMap.trace_nonneg).1 - apply positive_norm_le_of_eigenvalues T hT _ (div_nonneg htrace (by positivity)) - intro i - let μ := hT.toLinearMap.isSymmetric.eigenvalues rfl i - have hμ : 0 ≤ μ := hT.toLinearMap.nonneg_eigenvalues rfl i - have hcount := hmult (μ : ℂ) (hT.toLinearMap.isSymmetric.hasEigenvalue_eigenvalues rfl i) - have hcard := hT.toLinearMap.isSymmetric.card_filter_eigenvalues_eq rfl (μ : ℂ) - rw [← hcard] at hcount - simp only [RCLike.ofReal_eq_complex_ofReal, Complex.ofReal_inj] at hcount - apply (le_div_iff₀ (by exact_mod_cast hd)).mpr - calc - μ * (d : ℝ) ≤ μ * ((Finset.univ.filter fun j => - hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ).card : ℕ) := - mul_le_mul_of_nonneg_left (by exact_mod_cast hcount) hμ - _ = ∑ j ∈ Finset.univ.filter (fun j => - hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ), - hT.toLinearMap.isSymmetric.eigenvalues rfl j := by - symm - calc - _ = ∑ j ∈ Finset.univ.filter (fun j => - hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ), μ := - Finset.sum_congr rfl (fun j hj => (Finset.mem_filter.mp hj).2) - _ = _ := by simp [nsmul_eq_mul, mul_comm] - _ ≤ ∑ j, hT.toLinearMap.isSymmetric.eigenvalues rfl j := - Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) - (fun j _ _ => hT.toLinearMap.nonneg_eigenvalues rfl j) - _ = _ := (hT.toLinearMap.isSymmetric.re_trace_eq_sum_eigenvalues rfl).symm - -end RowColumn.SpectralMultiplicity -noncomputable section -open scoped ComplexOrder -namespace RowColumn.SpectralMultiplicity -variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] - [FiniteDimensional ℂ E] - -lemma trace_compression (T : E →L[ℂ] E) (F : Submodule ℂ E) : - LinearMap.trace ℂ F (F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL).toLinearMap = - LinearMap.trace ℂ E (T ∘L F.starProjection).toLinearMap := by - have he := LinearMap.trace_comp_comm' (T.toLinearMap ∘ₗ F.subtype) - F.orthogonalProjectionOnto.toLinearMap - exact he - -lemma trace_compression_le (T : E →L[ℂ] E) (hT : T.IsPositive) - (F : Submodule ℂ E) : - (LinearMap.trace ℂ F (F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL).toLinearMap).re ≤ - (LinearMap.trace ℂ E T.toLinearMap).re := by - have hp := (hT.orthogonalProjectionOnto_comp Fᗮ).toLinearMap.trace_nonneg - have hn := (Complex.nonneg_iff.mp hp).1 - rw [trace_compression] at hn ⊢ - have he : F.starProjection + Fᗮ.starProjection = (1 : E →L[ℂ] E) := by - ext x - exact F.starProjection_add_starProjection_orthogonal x - have ht : T ∘L F.starProjection + T ∘L Fᗮ.starProjection = T := by - rw [← ContinuousLinearMap.comp_add, he] - rfl - have htr := congrArg (fun S : E →L[ℂ] E => (LinearMap.trace ℂ E S.toLinearMap).re) ht - simp only [ContinuousLinearMap.toLinearMap_add, map_add, Complex.add_re] at htr - linarith - -lemma restrict_positive (T : E →L[ℂ] E) (hT : T.IsPositive) - (F : Submodule ℂ E) (hF : ∀ x ∈ F, T x ∈ F) : (T.restrict hF).IsPositive := by - have he : T.restrict hF = F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL := by - ext x - change T x = F.starProjection (T x) - exact (F.starProjection_eq_self_iff.mpr (hF x x.property)).symm - rw [he] - exact hT.orthogonalProjectionOnto_comp F - -lemma trace_restrict_le (T : E →L[ℂ] E) (hT : T.IsPositive) - (F : Submodule ℂ E) (hF : ∀ x ∈ F, T x ∈ F) : - (LinearMap.trace ℂ F (T.restrict hF).toLinearMap).re ≤ - (LinearMap.trace ℂ E T.toLinearMap).re := by - have he : T.restrict hF = F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL := by - ext x - change T x = F.starProjection (T x) - exact (F.starProjection_eq_self_iff.mpr (hF x x.property)).symm - rw [he] - exact trace_compression_le T hT F - -end RowColumn.SpectralMultiplicity - -end -end -end -end -end -end -end - - -section -noncomputable section -open scoped ComplexOrder -namespace RowColumn.FiniteStarAlgebra -variable {G V E : Type*} [Group G] - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] - -instance algebraFiniteDimensional (A : StarSubalgebra ℂ (E →L[ℂ] E)) : FiniteDimensional ℂ A := - FiniteDimensional.of_injective (algebraToEnd A) (algebraToEnd_injective A) - -instance algebraIsClosed (A : StarSubalgebra ℂ (E →L[ℂ] E)) : IsClosed (A : Set (E →L[ℂ] E)) := - A.toSubalgebra.toSubmodule.closed_of_finiteDimensional - -lemma supported_restriction_norm (A : StarSubalgebra ℂ (E →L[ℂ] E)) (F : Submodule ℂ E) - (φ : A →⋆ₐ[ℂ] (F →L[ℂ] F)) - (q : A) (hs : star q=q) (hqq : q*q=q) (hc : ∀ a, q*a=a*q) - (hq : φ q=1) (hkill : ∀ a : A, φ a=0 → q*a=0) (a : A) : - ‖q*a‖ = ‖φ a‖ := by - let J : NonUnitalStarSubalgebra ℂ A := - { carrier := {x | q*x=x} - zero_mem' := mul_zero q - add_mem' := by intro x y hx hy; change q*(x+y)=x+y; rw [mul_add,hx,hy] - mul_mem' := by intro x y hx hy; change q*(x*y)=x*y; rw [← mul_assoc,hx] - smul_mem' := by intro c x hx; change q*(c • x)=c • x; rw [mul_smul_comm,hx] - star_mem' := by - intro x hx - change q*star x=star x - rw [hc] - simpa only [star_mul,hs] using congrArg star hx } - let : IsClosed (J : Set A) := isClosed_eq (continuous_const.mul continuous_id) continuous_id - let ψ : J →⋆ₙₐ[ℂ] (F →L[ℂ] F) := φ.toNonUnitalStarAlgHom.comp (NonUnitalStarSubalgebraClass.subtype J) - have hinj : Function.Injective ψ := by - intro x y h - apply Subtype.ext - have he : φ ((x : A)-(y : A))=0 := by - rw [map_sub] - exact sub_eq_zero.mpr h - have hz := hkill _ he - change q*((x : A)-(y : A))=0 at hz - rw [mul_sub,x.property,y.property] at hz - exact sub_eq_zero.mp hz - let x : J := ⟨q*a,by change q*(q*a)=q*a; rw [← mul_assoc,hqq]⟩ - have hh := NonUnitalStarAlgHom.norm_map ψ hinj x - change ‖φ (q*a)‖ = ‖q*a‖ at hh - rw [map_mul,hq,one_mul] at hh - exact hh.symm - -/-- The exact dimension normalization of the occupied-board global filter. -No highest-weight entropy or Schur--Weyl hypothesis is required: restriction -of the supported algebra is faithful, and every eigenspace contains the -irreducible carrier. -/ -theorem exists_isotypic_filter (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (τ : Representation ℂ G E) - (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) - (A : StarSubalgebra ℂ (E →L[ℂ] E)) - (hA : ∀ a : A, ∀ g x, (a : E →L[ℂ] E) (τ g x) = τ g ((a : E →L[ℂ] E) x)) : - ∃ q : A, star q = q ∧ q*q=q ∧ (∀ a, q*a=a*q) ∧ - (∀ x ∈ Isotypic.carrier ρ τ, (q : E →L[ℂ] E) x = x) ∧ - ∀ a : A, (a : E →L[ℂ] E).IsPositive → - ‖q*a‖ ≤ (physicalTrace A a).re / Module.finrank ℂ V := by - let : Nontrivial V := by - let := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) ρ.asModule - exact ρ.asModuleEquiv.symm.toEquiv.nontrivial - let F := Isotypic.carrier ρ τ - have hF : ∀ a : A, ∀ x ∈ F, (a : E →L[ℂ] E) x ∈ F := fun a => - Isotypic.carrier_commutant ρ τ (a : E →L[ℂ] E).toLinearMap (hA a) - let φ := restrictHom A F hF - obtain ⟨q,hqs,hqq,hqc,hq,hkill⟩ := exists_central_support A F hF - refine ⟨q,hqs,hqq,hqc,?_,?_⟩ - · intro x hx - exact congrArg Subtype.val (congrArg (fun T : F →L[ℂ] F => T ⟨x,hx⟩) hq) - · intro a ha - rw [supported_restriction_norm A F φ q hqs hqq hqc hq hkill a] - have hp : (φ a).IsPositive := SpectralMultiplicity.restrict_positive - (a : E →L[ℂ] E) ha F (hF a) - apply (SpectralMultiplicity.norm_le_trace_div (φ a) hp (Module.finrank ℂ V) - (Module.finrank_pos) ?_).trans - · apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) - exact SpectralMultiplicity.trace_restrict_le (a : E →L[ℂ] E) ha F (hF a) - · intro μ hμ - apply Isotypic.eigenspace_finrank ρ (Isotypic.restricted ρ τ) - (Isotypic.restricted_isotypic ρ τ) (Isotypic.restricted_unitary ρ τ hτ) - (φ a).toLinearMap _ μ hμ - intro g x - apply Subtype.ext - exact hA a g x - -end RowColumn.FiniteStarAlgebra -noncomputable section -open scoped BigOperators ComplexOrder -namespace RowColumn.UnitaryFrame -variable {A G E : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] - [FiniteDimensional ℂ A] [Group G] - [NormedAddCommGroup E] [InnerProductSpace ℂ E] - -/-- The finite Fourier reconstruction bound for arbitrary Hilbert-valued -linear maps, in particular weighted Hilbert–Schmidt sandwich maps. -/ -theorem reconstruction_hilbert_bound (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) - (hinner : ∀ x y, core.inner x y = τ (star x*y)) - (u : G →* unitary A) - (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) - (B : A) (F : A →ₗ[ℂ] E) (R : ℝ) (hR : 0 ≤ R) - (hU : ∀ g, ‖F (u g : A)‖ ≤ R) : - ‖F B‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ * R := by - let ℓ := (innerSL ℂ (F B)).toLinearMap.comp F - have hu (g : G) : ‖ℓ (u g : A)‖ ≤ ‖F B‖ * R := - (norm_inner_le_norm (F B) (F (u g : A))).trans - (mul_le_mul_of_nonneg_left (hU g) (norm_nonneg _)) - have hh := reconstruction_bound τ core hinner u hspan B ℓ (‖F B‖ * R) - (mul_nonneg (norm_nonneg _) hR) hu - change ‖inner ℂ (F B) (F B)‖ ≤ _ at hh - rw [inner_self_eq_norm_sq_to_K, norm_pow, RCLike.norm_ofReal, - abs_of_nonneg (norm_nonneg _)] at hh - by_cases hz : ‖F B‖=0 - · rw [hz] - positivity - · have hp : 0 < ‖F B‖ := lt_of_le_of_ne (norm_nonneg _) (Ne.symm hz) - apply (mul_le_mul_iff_right₀ hp).mp - nlinarith [hh] - -end RowColumn.UnitaryFrame -noncomputable section -namespace RowColumn -variable {A : Type*} [CStarAlgebra A] - -lemma supported_fourth (q F : A) (hq : q*q=q) (hc : Commute q F) : - (q*F)^4 = q*(F^4) := by - rw [hc.mul_pow] - have hq4 : q^4=q := by calc - q^4=(q*q)*(q*q) := by noncomm_ring - _=q := by rw [hq,hq] - rw [hq4] - -/-- The quarter-root estimate at the level of the genuine operator norm. -The two fourth-moment bounds imply the exact squared sandwich bound. -/ -theorem filterNorm_sq (q F G : A) (hsq : IsSelfAdjoint q) (hqq : q*q=q) - (hF : IsSelfAdjoint F) (hG : IsSelfAdjoint G) (hcF : Commute q F) (hcG : Commute q G) - (d : ℝ) (_ : 0 < d) (hFb : ‖q * F^4‖ ≤ 1/d) (hGb : ‖q * G^4‖ ≤ 1/d) : - ‖F*q*G‖^2 ≤ 1/d := by - have hsF : IsSelfAdjoint (q*F) := by - change star (q*F)=q*F - rw [star_mul,hsq.star_eq,hF.star_eq,hcF.eq] - have hsG : IsSelfAdjoint (q*G) := by - change star (q*G)=q*G - rw [star_mul,hsq.star_eq,hG.star_eq,hcG.eq] - have hnF : ‖q*F‖^4 ≤ 1/d := by - have hn : ‖(q*F)^4‖=‖q*F‖^4 := by simpa using hsF.norm_pow_two_pow 2 - rw [← hn,supported_fourth q F hqq hcF] - exact hFb - have hnG : ‖q*G‖^4 ≤ 1/d := by - have hn : ‖(q*G)^4‖=‖q*G‖^4 := by simpa using hsG.norm_pow_two_pow 2 - rw [← hn,supported_fourth q G hqq hcG] - exact hGb - have he : F*q*G=(q*F)*(q*G) := by - calc - _ = F*(q*q)*G := by rw [hqq] - _ = (F*q)*(q*G) := by noncomm_ring - _ = _ := by rw [hcF.eq] - have hn := norm_mul_le (q*F) (q*G) - rw [← he] at hn - have hp : (‖q*F‖*‖q*G‖)^2 ≤ 1/d := by - have ha := sq_nonneg (‖q*F‖^2-‖q*G‖^2) - nlinarith - exact (pow_le_pow_left₀ (norm_nonneg _) hn 2).trans hp -end RowColumn - -end -end -end -end - -end OAI +import OAI.RepresentationTheory.FiniteUnitary.Frames +import OAI.RepresentationTheory.RowColumn.Basic + +namespace OAI + +section +noncomputable section +open scoped BigOperators ComplexOrder +namespace RowColumn.UnitaryFrame +variable {A G : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + [FiniteDimensional ℂ A] [Group G] + +omit [FiniteDimensional ℂ A] in +lemma positive_functional_bound (f : A →ₚ[ℂ] ℂ) (x : A) : + ‖f x‖ ≤ 4 * ‖f 1‖ * ‖x‖ := by + obtain ⟨y, hy_nonneg, hy_norm, hy⟩ := CStarAlgebra.exists_sum_four_nonneg x + conv_lhs => rw [hy] + simp only [map_sum, map_smul] + apply (norm_sum_le _ _).trans + simp only [norm_smul, norm_pow, Complex.norm_I, one_pow, one_mul] + apply (Finset.sum_le_sum (g := fun _ => ‖f 1‖ * ‖x‖) (fun i _ => ?_)).trans + · simp [mul_assoc] + · exact (f.norm_apply_le_of_nonneg _ (hy_nonneg i)).trans + (mul_le_mul_of_nonneg_left (hy_norm i) (norm_nonneg _)) + +/-- Finite-dimensional unitary reconstruction with polynomial Fourier cost. +Only the actual operator norm of B occurs; the auxiliary Hilbert norm is used +solely to construct the frame and does not alter that norm. -/ +theorem reconstruction_bound (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) + (hinner : ∀ x y, core.inner x y = τ (star x*y)) + (u : G →* unitary A) + (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) + (B : A) (ℓ : A →ₗ[ℂ] ℂ) (R : ℝ) (_ : 0 ≤ R) + (hU : ∀ g, ‖ℓ (u g : A)‖ ≤ R) : + ‖ℓ B‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ * R := by + obtain ⟨D,hD,hpos,hrec⟩ := exists_density τ core hinner u hspan + let φ : A →ₗ[ℂ] ℂ := τ.comp (LinearMap.mulRight ℂ D) + have hφpos (a : A) (ha : 0 ≤ a) : 0 ≤ φ a := by + have hh := hpos (CFC.sqrt a) + have hs : star (CFC.sqrt a) * CFC.sqrt a = a := by + rw [(IsSelfAdjoint.of_nonneg (CFC.sqrt_nonneg a)).star_eq] + exact CFC.sqrt_mul_sqrt_self a ha + change 0 ≤ τ (a*D) + simpa only [hs] using hh + let f : A →ₚ[ℂ] ℂ := PositiveLinearMap.mk₀ φ hφpos + have hf1 : ‖f 1‖ = (Module.finrank ℂ A : ℝ) := by + change ‖τ (1*D)‖ = _ + rw [one_mul, hD] + simp + apply hrec B ℓ + intro g + rw [← mul_assoc] + change ‖φ (star (u g : A)*B) * ℓ (u g : A)‖ ≤ _ + rw [norm_mul] + have hb : ‖φ (star (u g : A)*B)‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ := by + have hh := positive_functional_bound f (star (u g : A)*B) + rw [hf1] at hh + change ‖f (star (u g : A)*B)‖ ≤ _ + simpa only [← Unitary.coe_star, CStarRing.norm_coe_unitary_mul] using hh + exact mul_le_mul hb (hU g) (norm_nonneg _) (by positivity) + +end RowColumn.UnitaryFrame +noncomputable section +open scoped ComplexConjugate +namespace RowColumn.FiniteStarAlgebra +variable {A : Type*} [Ring A] [Module ℂ A] [StarRing A] [FiniteDimensional ℂ A] + +/-- A finite-dimensional two-sided star ideal has a central orthogonal unit. +The two inner-product identities hold for the actual Hilbert–Schmidt trace. +This constructs the central support used in the occupied-board filter. -/ +theorem complementary_central_projection (core : InnerProductSpace.Core ℂ A) (K : Submodule ℂ A) + (hL : ∀ a x, x ∈ K → a*x ∈ K) (hR : ∀ a x, x ∈ K → x*a ∈ K) + (hstar : ∀ x, x ∈ K → star x ∈ K) + (hadjL : ∀ a x y : A, core.inner (a*x) y = core.inner x (star a*y)) + (hadjR : ∀ a x y : A, core.inner (x*a) y = core.inner x (y*star a)) : + ∃ q : A, star q = q ∧ q*q = q ∧ (∀ a, q*a = a*q) ∧ + 1-q ∈ K ∧ (∀ x, x ∈ K → q*x = 0 ∧ x*q = 0) := by + let : NormedAddCommGroup A := core.toNormedAddCommGroup + let : InnerProductSpace ℂ A := InnerProductSpace.ofCore { __ := core } + change ∀ a x y : A, inner ℂ (a*x) y = inner ℂ x (star a*y) at hadjL + change ∀ a x y : A, inner ℂ (x*a) y = inner ℂ x (y*star a) at hadjR + have hoL (a x : A) (hx : x ∈ Kᗮ) : a*x ∈ Kᗮ := by + rw [Submodule.mem_orthogonal] at hx ⊢ + intro y hy + have hh := hx (star a*y) (hL (star a) y hy) + simpa only [hadjL, star_star] using hh + have hoR (a x : A) (hx : x ∈ Kᗮ) : x*a ∈ Kᗮ := by + rw [Submodule.mem_orthogonal] at hx ⊢ + intro y hy + have hh := hx (y*star a) (hR (star a) y hy) + simpa only [hadjR, star_star] using hh + have hz (x : A) (hk : x ∈ K) (ho : x ∈ Kᗮ) : x = 0 := + (inner_self_eq_zero (𝕜 := ℂ)).mp ((K.mem_orthogonal x).mp ho x hk) + let k : A := K.starProjection 1 + let q : A := 1-k + have hk : k ∈ K := (K.orthogonalProjectionOnto 1).property + have hq : q ∈ Kᗮ := K.sub_starProjection_mem_orthogonal 1 + have hqa (x : A) (hx : x ∈ K) : q*x = 0 := + hz _ (hL q x hx) (hoR x q hq) + have haq (x : A) (hx : x ∈ K) : x*q = 0 := + hz _ (hR q x hx) (hoL x q hq) + have hsk : star k = k := by + have e₁ : star k = k*star k := by + have he := hqa (star k) (hstar k hk) + change (1-k)*star k = 0 at he + simpa only [sub_mul, one_mul, sub_eq_zero] using he + have e₂ := congrArg star e₁ + simp only [star_star, star_mul] at e₂ + exact e₁.trans e₂.symm + refine ⟨q, ?_, ?_, ?_, ?_, fun x hx => ⟨hqa x hx, haq x hx⟩⟩ + · simp only [q, star_sub, star_one, hsk] + · change q*(1-k) = q + rw [mul_sub, mul_one, hqa k hk, sub_zero] + · intro a + have hka : k*a = k*a*k := by + have he := haq (k*a) (hR a k hk) + change (k*a)*(1-k) = 0 at he + simpa only [mul_sub, mul_one, sub_eq_zero] using he + have hak : a*k = k*a*k := by + have he := hqa (a*k) (hL a k hk) + change (1-k)*(a*k) = 0 at he + simpa only [sub_mul, one_mul, sub_eq_zero, ← mul_assoc] using he + change (1-k)*a = a*(1-k) + rw [sub_mul, one_mul, mul_sub, mul_one] + exact congrArg (fun z => a-z) (hka.trans hak.symm) + · simpa only [q, sub_sub_cancel] using hk + +end RowColumn.FiniteStarAlgebra + +namespace RowColumn.FiniteStarAlgebra +open scoped ComplexOrder +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +abbrev Ambient := E →L[ℂ] E + +def algebraToEnd (A : StarSubalgebra ℂ (Ambient (E := E))) : A →ₗ[ℂ] (E →ₗ[ℂ] E) := + { toFun a := (a : Ambient (E := E)).toLinearMap + map_add' _ _ := rfl + map_smul' _ _ := rfl } + +lemma algebraToEnd_injective (A : StarSubalgebra ℂ (Ambient (E := E))) : + Function.Injective (algebraToEnd A) := by + intro a b h + apply Subtype.ext + apply ContinuousLinearMap.ext + intro x + exact LinearMap.congr_fun h x + +@[instance_reducible] +def algebraCore (A : StarSubalgebra ℂ (Ambient (E := E))) : InnerProductSpace.Core ℂ A where + inner a b := HilbertSchmidt.endCore.inner (algebraToEnd A a) (algebraToEnd A b) + conj_inner_symm a b := HilbertSchmidt.endCore.conj_inner_symm _ _ + re_inner_nonneg a := HilbertSchmidt.endCore.re_inner_nonneg _ + add_left a b c := by rw [map_add]; exact HilbertSchmidt.endCore.add_left _ _ _ + smul_left a b c := by rw [map_smul]; exact HilbertSchmidt.endCore.smul_left _ _ _ + definite a h := (algebraToEnd_injective A) (by simpa only [map_zero] using HilbertSchmidt.endCore.definite _ h) + +def physicalTrace (A : StarSubalgebra ℂ (Ambient (E := E))) : A →ₗ[ℂ] ℂ := + (LinearMap.trace ℂ E).comp (algebraToEnd A) + +lemma core_inner_trace (A : StarSubalgebra ℂ (Ambient (E := E))) (a b : A) : + (algebraCore A).inner a b = physicalTrace A (star a*b) := by + change LinearMap.trace ℂ E (LinearMap.adjoint (a : Ambient (E := E)).toLinearMap ∘ₗ + (b : Ambient (E := E)).toLinearMap) = LinearMap.trace ℂ E ((star (a : Ambient (E := E)) * (b : Ambient (E := E))).toLinearMap) + rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_toLinearMap] + rfl + +lemma physicalTrace_mul_comm (A : StarSubalgebra ℂ (Ambient (E := E))) (a b : A) : + physicalTrace A (a*b) = physicalTrace A (b*a) := + LinearMap.trace_comp_comm' (b : Ambient (E := E)).toLinearMap (a : Ambient (E := E)).toLinearMap + +/-- Restriction to a subspace preserved by the whole star algebra is a genuine +star homomorphism (both the subspace and its orthogonal complement are reducing). -/ +def restrictHom (A : StarSubalgebra ℂ (Ambient (E := E))) (F : Submodule ℂ E) + (hF : ∀ a : A, ∀ x ∈ F, (a : Ambient (E := E)) x ∈ F) : A →⋆ₐ[ℂ] (F →L[ℂ] F) where + toFun a := (a : Ambient (E := E)).restrict (hF a) + map_zero' := by ext x; rfl + map_add' a b := by ext x; rfl + map_one' := by ext x; rfl + map_mul' a b := by ext x; rfl + commutes' c := by ext x; rfl + map_star' a := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_right ℂ + intro y + rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_left] + change inner ℂ ((star (a : Ambient (E := E))) (x : E)) (y : E) = + inner ℂ (x : E) ((a : Ambient (E := E)) (y : E)) + rw [ContinuousLinearMap.star_eq_adjoint, ContinuousLinearMap.adjoint_inner_left] + +/-- Central support of a reducing physical subspace. Its algebraic kernel is +removed, so no other unsupported sector can inflate the Fourier norm. -/ +theorem exists_central_support (A : StarSubalgebra ℂ (Ambient (E := E))) (F : Submodule ℂ E) + (hF : ∀ a : A, ∀ x ∈ F, (a : Ambient (E := E)) x ∈ F) : + ∃ q : A, star q = q ∧ q*q=q ∧ (∀ a, q*a=a*q) ∧ + restrictHom A F hF q = 1 ∧ + (∀ a : A, restrictHom A F hF a = 0 → q*a=0) := by + let : FiniteDimensional ℂ A := FiniteDimensional.of_injective + (algebraToEnd A) (algebraToEnd_injective A) + let φ := restrictHom A F hF + let K := LinearMap.ker φ.toLinearMap + have hk (a : A) : a ∈ K ↔ φ a = 0 := Iff.rfl + obtain ⟨q,hs,hqq,hc,hkq,hkill⟩ := complementary_central_projection (algebraCore A) K + (fun a x hx => by rw [hk, map_mul, (hk x).mp hx, mul_zero]) + (fun a x hx => by rw [hk, map_mul, (hk x).mp hx, zero_mul]) + (fun x hx => by rw [hk, map_star, (hk x).mp hx]; exact star_zero (F →L[ℂ] F)) + (fun a x y => by simp only [core_inner_trace, star_mul, mul_assoc]) + (fun a x y => by + simp only [core_inner_trace, star_mul] + rw [mul_assoc, physicalTrace_mul_comm A (star a) _, mul_assoc]) + refine ⟨q,hs,hqq,hc,?_,fun a ha => (hkill a ((hk a).mpr ha)).1⟩ + have hh := (hk (1-q)).mp hkq + have he : 1-φ q=0 := by simpa only [map_sub, map_one] using hh + exact (sub_eq_zero.mp he).symm + +end RowColumn.FiniteStarAlgebra +noncomputable section +namespace RowColumn.FiniteStarAlgebra +variable {A B : Type*} [CStarAlgebra A] [CStarAlgebra B] + +def supportedAlgebra (q : A) (hs : star q = q) (hc : ∀ a, q*a=a*q) : + NonUnitalStarSubalgebra ℂ A where + carrier := {a | q*a=a} + zero_mem' := mul_zero q + add_mem' := by intro a b ha hb; change q*(a+b)=a+b; rw [mul_add, ha, hb] + mul_mem' := by intro a b ha hb; change q*(a*b)=a*b; rw [← mul_assoc, ha] + smul_mem' := by intro c a ha; change q*(c • a)=c • a; rw [mul_smul_comm, ha] + star_mem' := by + intro a ha + change q*star a=star a + rw [hc] + simpa only [star_mul, hs] using congrArg star ha + +lemma supportedAlgebra_closed (q : A) (hs : star q = q) (hc : ∀ a, q*a=a*q) : + IsClosed (supportedAlgebra q hs hc : Set A) := + isClosed_eq (continuous_const.mul continuous_id) continuous_id + +/-- Removing the kernel by its central support makes restriction isometric. +This avoids choosing irreducible compact-group carriers or using unproved +Schur--Weyl decompositions. -/ +theorem norm_supported_eq (φ : A →⋆ₐ[ℂ] B) (q : A) (hs : star q = q) + (hqq : q*q=q) (hc : ∀ a, q*a=a*q) (hq : φ q=1) + (hkill : ∀ a, φ a=0 → q*a=0) (a : A) : ‖q*a‖ = ‖φ a‖ := by + let J := supportedAlgebra q hs hc + let : IsClosed (J : Set A) := supportedAlgebra_closed q hs hc + let ψ : J →⋆ₙₐ[ℂ] B := φ.toNonUnitalStarAlgHom.comp (NonUnitalStarSubalgebraClass.subtype J) + have hinj : Function.Injective ψ := by + intro x y h + apply Subtype.ext + have he : φ ((x : A)-(y : A))=0 := by + rw [map_sub] + exact sub_eq_zero.mpr h + have hz := hkill _ he + change q*((x : A)-(y : A))=0 at hz + rw [mul_sub, x.property, y.property] at hz + exact sub_eq_zero.mp hz + let x : J := ⟨q*a, by change q*(q*a)=q*a; rw [← mul_assoc, hqq]⟩ + have hh := NonUnitalStarAlgHom.norm_map ψ hinj x + change ‖φ (q*a)‖ = ‖q*a‖ at hh + rw [map_mul, hq, one_mul] at hh + exact hh.symm + +end RowColumn.FiniteStarAlgebra +noncomputable section +open scoped BigOperators ComplexConjugate +namespace RowColumn.Isotypic +variable {G V E : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + (ρ : Representation ℂ G V) (τ : Representation ℂ G E) + +def carrier : Submodule ℂ E := Submodule.span ℂ + (Set.range fun p : Representation.IntertwiningMap ρ τ × V => p.1 p.2) + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in +lemma mem_carrier (f : Representation.IntertwiningMap ρ τ) (v : V) : f v ∈ carrier ρ τ := + Submodule.subset_span ⟨(f,v),rfl⟩ + +lemma projection_intertwines (F : Submodule ℂ E) + (hF : ∀ g x, x ∈ F → τ g x ∈ F) + (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) : + ∀ g x, F.starProjection (τ g x) = τ g (F.starProjection x) := by + intro g x + let e : E →ₗᵢ[ℂ] E := (τ g).isometryOfInner (hτ g) + have hmap : F.map e.toLinearMap = F := by + apply le_antisymm + · rintro _ ⟨y,hy,rfl⟩ + exact hF g y hy + · intro y hy + refine ⟨τ g⁻¹ y, hF g⁻¹ y hy, ?_⟩ + change (τ g * τ g⁻¹) y = y + rw [← map_mul, mul_inv_cancel, map_one] + rfl + have he := e.map_starProjection F x + simpa only [hmap, e, LinearMap.coe_isometryOfInner] using he.symm + +omit [FiniteDimensional ℂ V] in +/-- On an isotypic unitary representation, every eigenspace of an operator in +the group commutant has dimension at least that of the irreducible type. -/ +theorem eigenspace_finrank [Representation.IsIrreducible ρ] + (hspan : carrier ρ τ = ⊤) + (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) + (T : E →ₗ[ℂ] E) (hT : ∀ g x, T (τ g x) = τ g (T x)) + (μ : ℂ) (hμ : Module.End.HasEigenvalue T μ) : + Module.finrank ℂ V ≤ Module.finrank ℂ (Module.End.eigenspace T μ) := by + classical + let F := Module.End.eigenspace T μ + have hf (g : G) (x : E) (hx : x ∈ F) : τ g x ∈ F := by + rw [Module.End.mem_eigenspace_iff] at hx ⊢ + rw [hT, hx, map_smul] + let P : Representation.IntertwiningMap τ τ := + { toLinearMap := F.starProjection.toLinearMap + isIntertwining' g := by ext x; exact projection_intertwines τ F hf hτ g x } + have hex : ∃ f : Representation.IntertwiningMap ρ τ, P.comp f ≠ 0 := by + by_contra! h + have hz (x : E) (hx : x ∈ carrier ρ τ) : P x = 0 := by + induction hx using Submodule.span_induction with + | mem x hx => + obtain ⟨⟨f,v⟩,rfl⟩ := hx + exact congrArg (fun L : Representation.IntertwiningMap ρ τ => L v) (h f) + | zero => exact map_zero P + | add x y hx hy hpx hpy => simp only [map_add, hpx, hpy, add_zero] + | smul c x hx hpx => simp only [map_smul, hpx, smul_zero] + obtain ⟨x,hx,hxn⟩ := hμ.exists_hasEigenvector + have he := hz x (by rw [hspan]; trivial) + change F.starProjection x = 0 at he + rw [F.starProjection_eq_self_iff.mpr hx] at he + exact hxn he + obtain ⟨f,hfne⟩ := hex + have hi : Function.Injective (P.comp f) := + (Representation.IsIrreducible.injective_or_eq_zero (P.comp f)).resolve_right hfne + let L : V →ₗ[ℂ] F := (P.comp f).toLinearMap.codRestrict F (fun v => + (F.orthogonalProjectionOnto (f v)).property) + apply LinearMap.finrank_le_finrank_of_injective (f := L) + intro x y h + exact hi (congrArg Subtype.val h) + +end RowColumn.Isotypic +namespace RowColumn.Isotypic +variable {G V E : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + (ρ : Representation ℂ G V) (τ : Representation ℂ G E) + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in +lemma carrier_invariant (g : G) (x : E) (hx : x ∈ carrier ρ τ) : τ g x ∈ carrier ρ τ := by + induction hx using Submodule.span_induction with + | mem x hx => + obtain ⟨⟨f,v⟩,rfl⟩ := hx + rw [← Representation.IntertwiningMap.isIntertwining ρ τ f] + exact mem_carrier ρ τ f _ + | zero => simpa only [map_zero] using (carrier ρ τ).zero_mem + | add x y hx hy hx' hy' => simpa only [map_add] using (carrier ρ τ).add_mem hx' hy' + | smul c x hx hx' => simpa only [map_smul] using (carrier ρ τ).smul_mem c hx' + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in +lemma carrier_commutant (T : E →ₗ[ℂ] E) (hT : ∀ g x, T (τ g x) = τ g (T x)) + (x : E) (hx : x ∈ carrier ρ τ) : T x ∈ carrier ρ τ := by + let t : Representation.IntertwiningMap τ τ := + { toLinearMap := T + isIntertwining' g := by ext x; exact hT g x } + induction hx using Submodule.span_induction with + | mem x hx => + obtain ⟨⟨f,v⟩,rfl⟩ := hx + exact mem_carrier ρ τ (t.comp f) v + | zero => simpa only [map_zero] using (carrier ρ τ).zero_mem + | add x y hx hy hx' hy' => simpa only [map_add] using (carrier ρ τ).add_mem hx' hy' + | smul c x hx hx' => simpa only [map_smul] using (carrier ρ τ).smul_mem c hx' + +def restricted : Representation ℂ G (carrier ρ τ) where + toFun g := (τ g).restrict (carrier_invariant ρ τ g) + map_one' := by ext x; exact LinearMap.congr_fun (map_one τ) x + map_mul' g h := by ext x; exact LinearMap.congr_fun (map_mul τ g h) x + +def restrictIntertwiner (f : Representation.IntertwiningMap ρ τ) : + Representation.IntertwiningMap ρ (restricted ρ τ) where + toLinearMap := f.toLinearMap.codRestrict (carrier ρ τ) (mem_carrier ρ τ f) + isIntertwining' g := by + ext v + exact Representation.IntertwiningMap.isIntertwining ρ τ f g v + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in +lemma restricted_unitary (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) : + ∀ g (x y : carrier ρ τ), inner ℂ (restricted ρ τ g x) (restricted ρ τ g y) = inner ℂ x y := by + intro g x y + exact hτ g x y + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ E] in +lemma restricted_isotypic : carrier ρ (restricted ρ τ) = ⊤ := by + let F := carrier ρ τ + let K := (carrier ρ (restricted ρ τ)).map F.subtype + have hFK : F ≤ K := by + apply Submodule.span_le.mpr + rintro _ ⟨⟨f,v⟩,rfl⟩ + exact ⟨restrictIntertwiner ρ τ f v, mem_carrier ρ (restricted ρ τ) + (restrictIntertwiner ρ τ f) v, rfl⟩ + apply top_unique + intro x _ + obtain ⟨y,hy,hxy⟩ := hFK x.property + have he : y=x := Subtype.ext hxy + exact he ▸ hy + +end RowColumn.Isotypic +noncomputable section +open scoped BigOperators ComplexOrder +namespace RowColumn.SpectralMultiplicity +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +lemma positive_norm_le_of_eigenvalues (T : E →L[ℂ] E) (hT : T.IsPositive) + (c : ℝ) (hc : 0 ≤ c) + (hval : ∀ i, hT.toLinearMap.isSymmetric.eigenvalues rfl i ≤ c) : ‖T‖ ≤ c := by + let b := hT.toLinearMap.isSymmetric.eigenvectorBasis rfl + apply T.opNorm_le_bound hc + intro x + apply le_of_sq_le_sq _ (mul_nonneg hc (norm_nonneg _)) + rw [← b.repr.norm_map (T x), ← b.repr.norm_map x, mul_pow] + rw [EuclideanSpace.norm_sq_eq, EuclideanSpace.norm_sq_eq, Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have hi := hT.toLinearMap.nonneg_eigenvalues rfl i + have he := hT.toLinearMap.isSymmetric.eigenvectorBasis_apply_self_apply rfl x i + change (b.repr (T x)) i = _ at he + change ‖(b.repr (T x)) i‖^2 ≤ _ + rw [he, norm_mul, RCLike.norm_ofReal, abs_of_nonneg hi, mul_pow] + exact mul_le_mul_of_nonneg_right (sq_le_sq₀ hi hc |>.mpr (hval i)) (sq_nonneg _) + +/-- An eigenvalue supported on at least d dimensions pays a trace factor d. +This is the precise spectral normalization needed for the global filter. -/ +theorem norm_le_trace_div (T : E →L[ℂ] E) (hT : T.IsPositive) (d : ℕ) (hd : 0 < d) + (hmult : ∀ μ : ℂ, Module.End.HasEigenvalue T.toLinearMap μ → + d ≤ Module.finrank ℂ (Module.End.eigenspace T.toLinearMap μ)) : + ‖T‖ ≤ (LinearMap.trace ℂ E T.toLinearMap).re / d := by + have htrace : 0 ≤ (LinearMap.trace ℂ E T.toLinearMap).re := + (Complex.nonneg_iff.mp hT.toLinearMap.trace_nonneg).1 + apply positive_norm_le_of_eigenvalues T hT _ (div_nonneg htrace (by positivity)) + intro i + let μ := hT.toLinearMap.isSymmetric.eigenvalues rfl i + have hμ : 0 ≤ μ := hT.toLinearMap.nonneg_eigenvalues rfl i + have hcount := hmult (μ : ℂ) (hT.toLinearMap.isSymmetric.hasEigenvalue_eigenvalues rfl i) + have hcard := hT.toLinearMap.isSymmetric.card_filter_eigenvalues_eq rfl (μ : ℂ) + rw [← hcard] at hcount + simp only [RCLike.ofReal_eq_complex_ofReal, Complex.ofReal_inj] at hcount + apply (le_div_iff₀ (by exact_mod_cast hd)).mpr + calc + μ * (d : ℝ) ≤ μ * ((Finset.univ.filter fun j => + hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ).card : ℕ) := + mul_le_mul_of_nonneg_left (by exact_mod_cast hcount) hμ + _ = ∑ j ∈ Finset.univ.filter (fun j => + hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ), + hT.toLinearMap.isSymmetric.eigenvalues rfl j := by + symm + calc + _ = ∑ j ∈ Finset.univ.filter (fun j => + hT.toLinearMap.isSymmetric.eigenvalues rfl j = μ), μ := + Finset.sum_congr rfl (fun j hj => (Finset.mem_filter.mp hj).2) + _ = _ := by simp [nsmul_eq_mul, mul_comm] + _ ≤ ∑ j, hT.toLinearMap.isSymmetric.eigenvalues rfl j := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun j _ _ => hT.toLinearMap.nonneg_eigenvalues rfl j) + _ = _ := (hT.toLinearMap.isSymmetric.re_trace_eq_sum_eigenvalues rfl).symm + +end RowColumn.SpectralMultiplicity +noncomputable section +open scoped ComplexOrder +namespace RowColumn.SpectralMultiplicity +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [FiniteDimensional ℂ E] + +lemma trace_compression (T : E →L[ℂ] E) (F : Submodule ℂ E) : + LinearMap.trace ℂ F (F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL).toLinearMap = + LinearMap.trace ℂ E (T ∘L F.starProjection).toLinearMap := by + have he := LinearMap.trace_comp_comm' (T.toLinearMap ∘ₗ F.subtype) + F.orthogonalProjectionOnto.toLinearMap + exact he + +lemma trace_compression_le (T : E →L[ℂ] E) (hT : T.IsPositive) + (F : Submodule ℂ E) : + (LinearMap.trace ℂ F (F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL).toLinearMap).re ≤ + (LinearMap.trace ℂ E T.toLinearMap).re := by + have hp := (hT.orthogonalProjectionOnto_comp Fᗮ).toLinearMap.trace_nonneg + have hn := (Complex.nonneg_iff.mp hp).1 + rw [trace_compression] at hn ⊢ + have he : F.starProjection + Fᗮ.starProjection = (1 : E →L[ℂ] E) := by + ext x + exact F.starProjection_add_starProjection_orthogonal x + have ht : T ∘L F.starProjection + T ∘L Fᗮ.starProjection = T := by + rw [← ContinuousLinearMap.comp_add, he] + rfl + have htr := congrArg (fun S : E →L[ℂ] E => (LinearMap.trace ℂ E S.toLinearMap).re) ht + simp only [ContinuousLinearMap.toLinearMap_add, map_add, Complex.add_re] at htr + linarith + +lemma restrict_positive (T : E →L[ℂ] E) (hT : T.IsPositive) + (F : Submodule ℂ E) (hF : ∀ x ∈ F, T x ∈ F) : (T.restrict hF).IsPositive := by + have he : T.restrict hF = F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL := by + ext x + change T x = F.starProjection (T x) + exact (F.starProjection_eq_self_iff.mpr (hF x x.property)).symm + rw [he] + exact hT.orthogonalProjectionOnto_comp F + +lemma trace_restrict_le (T : E →L[ℂ] E) (hT : T.IsPositive) + (F : Submodule ℂ E) (hF : ∀ x ∈ F, T x ∈ F) : + (LinearMap.trace ℂ F (T.restrict hF).toLinearMap).re ≤ + (LinearMap.trace ℂ E T.toLinearMap).re := by + have he : T.restrict hF = F.orthogonalProjectionOnto ∘L T ∘L F.subtypeL := by + ext x + change T x = F.starProjection (T x) + exact (F.starProjection_eq_self_iff.mpr (hF x x.property)).symm + rw [he] + exact trace_compression_le T hT F + +end RowColumn.SpectralMultiplicity + +end +end +end +end +end +end +end + + +section +noncomputable section +open scoped ComplexOrder +namespace RowColumn.FiniteStarAlgebra +variable {G V E : Type*} [Group G] + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] [FiniteDimensional ℂ E] + +instance algebraFiniteDimensional (A : StarSubalgebra ℂ (E →L[ℂ] E)) : FiniteDimensional ℂ A := + FiniteDimensional.of_injective (algebraToEnd A) (algebraToEnd_injective A) + +instance algebraIsClosed (A : StarSubalgebra ℂ (E →L[ℂ] E)) : IsClosed (A : Set (E →L[ℂ] E)) := + A.toSubalgebra.toSubmodule.closed_of_finiteDimensional + +lemma supported_restriction_norm (A : StarSubalgebra ℂ (E →L[ℂ] E)) (F : Submodule ℂ E) + (φ : A →⋆ₐ[ℂ] (F →L[ℂ] F)) + (q : A) (hs : star q=q) (hqq : q*q=q) (hc : ∀ a, q*a=a*q) + (hq : φ q=1) (hkill : ∀ a : A, φ a=0 → q*a=0) (a : A) : + ‖q*a‖ = ‖φ a‖ := by + let J : NonUnitalStarSubalgebra ℂ A := + { carrier := {x | q*x=x} + zero_mem' := mul_zero q + add_mem' := by intro x y hx hy; change q*(x+y)=x+y; rw [mul_add,hx,hy] + mul_mem' := by intro x y hx hy; change q*(x*y)=x*y; rw [← mul_assoc,hx] + smul_mem' := by intro c x hx; change q*(c • x)=c • x; rw [mul_smul_comm,hx] + star_mem' := by + intro x hx + change q*star x=star x + rw [hc] + simpa only [star_mul,hs] using congrArg star hx } + let : IsClosed (J : Set A) := isClosed_eq (continuous_const.mul continuous_id) continuous_id + let ψ : J →⋆ₙₐ[ℂ] (F →L[ℂ] F) := φ.toNonUnitalStarAlgHom.comp (NonUnitalStarSubalgebraClass.subtype J) + have hinj : Function.Injective ψ := by + intro x y h + apply Subtype.ext + have he : φ ((x : A)-(y : A))=0 := by + rw [map_sub] + exact sub_eq_zero.mpr h + have hz := hkill _ he + change q*((x : A)-(y : A))=0 at hz + rw [mul_sub,x.property,y.property] at hz + exact sub_eq_zero.mp hz + let x : J := ⟨q*a,by change q*(q*a)=q*a; rw [← mul_assoc,hqq]⟩ + have hh := NonUnitalStarAlgHom.norm_map ψ hinj x + change ‖φ (q*a)‖ = ‖q*a‖ at hh + rw [map_mul,hq,one_mul] at hh + exact hh.symm + +/-- The exact dimension normalization of the occupied-board global filter. +No highest-weight entropy or Schur--Weyl hypothesis is required: restriction +of the supported algebra is faithful, and every eigenspace contains the +irreducible carrier. -/ +theorem exists_isotypic_filter (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (τ : Representation ℂ G E) + (hτ : ∀ g x y, inner ℂ (τ g x) (τ g y) = inner ℂ x y) + (A : StarSubalgebra ℂ (E →L[ℂ] E)) + (hA : ∀ a : A, ∀ g x, (a : E →L[ℂ] E) (τ g x) = τ g ((a : E →L[ℂ] E) x)) : + ∃ q : A, star q = q ∧ q*q=q ∧ (∀ a, q*a=a*q) ∧ + (∀ x ∈ Isotypic.carrier ρ τ, (q : E →L[ℂ] E) x = x) ∧ + ∀ a : A, (a : E →L[ℂ] E).IsPositive → + ‖q*a‖ ≤ (physicalTrace A a).re / Module.finrank ℂ V := by + let : Nontrivial V := by + let := IsSimpleModule.nontrivial (MonoidAlgebra ℂ G) ρ.asModule + exact ρ.asModuleEquiv.symm.toEquiv.nontrivial + let F := Isotypic.carrier ρ τ + have hF : ∀ a : A, ∀ x ∈ F, (a : E →L[ℂ] E) x ∈ F := fun a => + Isotypic.carrier_commutant ρ τ (a : E →L[ℂ] E).toLinearMap (hA a) + let φ := restrictHom A F hF + obtain ⟨q,hqs,hqq,hqc,hq,hkill⟩ := exists_central_support A F hF + refine ⟨q,hqs,hqq,hqc,?_,?_⟩ + · intro x hx + exact congrArg Subtype.val (congrArg (fun T : F →L[ℂ] F => T ⟨x,hx⟩) hq) + · intro a ha + rw [supported_restriction_norm A F φ q hqs hqq hqc hq hkill a] + have hp : (φ a).IsPositive := SpectralMultiplicity.restrict_positive + (a : E →L[ℂ] E) ha F (hF a) + apply (SpectralMultiplicity.norm_le_trace_div (φ a) hp (Module.finrank ℂ V) + (Module.finrank_pos) ?_).trans + · apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact SpectralMultiplicity.trace_restrict_le (a : E →L[ℂ] E) ha F (hF a) + · intro μ hμ + apply Isotypic.eigenspace_finrank ρ (Isotypic.restricted ρ τ) + (Isotypic.restricted_isotypic ρ τ) (Isotypic.restricted_unitary ρ τ hτ) + (φ a).toLinearMap _ μ hμ + intro g x + apply Subtype.ext + exact hA a g x + +end RowColumn.FiniteStarAlgebra +noncomputable section +open scoped BigOperators ComplexOrder +namespace RowColumn.UnitaryFrame +variable {A G E : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] + [FiniteDimensional ℂ A] [Group G] + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +/-- The finite Fourier reconstruction bound for arbitrary Hilbert-valued +linear maps, in particular weighted Hilbert–Schmidt sandwich maps. -/ +theorem reconstruction_hilbert_bound (τ : A →ₗ[ℂ] ℂ) (core : InnerProductSpace.Core ℂ A) + (hinner : ∀ x y, core.inner x y = τ (star x*y)) + (u : G →* unitary A) + (hspan : Submodule.span ℂ (Set.range fun g : G => (u g : A)) = ⊤) + (B : A) (F : A →ₗ[ℂ] E) (R : ℝ) (hR : 0 ≤ R) + (hU : ∀ g, ‖F (u g : A)‖ ≤ R) : + ‖F B‖ ≤ 4 * (Module.finrank ℂ A : ℝ) * ‖B‖ * R := by + let ℓ := (innerSL ℂ (F B)).toLinearMap.comp F + have hu (g : G) : ‖ℓ (u g : A)‖ ≤ ‖F B‖ * R := + (norm_inner_le_norm (F B) (F (u g : A))).trans + (mul_le_mul_of_nonneg_left (hU g) (norm_nonneg _)) + have hh := reconstruction_bound τ core hinner u hspan B ℓ (‖F B‖ * R) + (mul_nonneg (norm_nonneg _) hR) hu + change ‖inner ℂ (F B) (F B)‖ ≤ _ at hh + rw [inner_self_eq_norm_sq_to_K, norm_pow, RCLike.norm_ofReal, + abs_of_nonneg (norm_nonneg _)] at hh + by_cases hz : ‖F B‖=0 + · rw [hz] + positivity + · have hp : 0 < ‖F B‖ := lt_of_le_of_ne (norm_nonneg _) (Ne.symm hz) + apply (mul_le_mul_iff_right₀ hp).mp + nlinarith [hh] + +end RowColumn.UnitaryFrame +noncomputable section +namespace RowColumn +variable {A : Type*} [CStarAlgebra A] + +lemma supported_fourth (q F : A) (hq : q*q=q) (hc : Commute q F) : + (q*F)^4 = q*(F^4) := by + rw [hc.mul_pow] + have hq4 : q^4=q := by calc + q^4=(q*q)*(q*q) := by noncomm_ring + _=q := by rw [hq,hq] + rw [hq4] + +/-- The quarter-root estimate at the level of the genuine operator norm. +The two fourth-moment bounds imply the exact squared sandwich bound. -/ +theorem filterNorm_sq (q F G : A) (hsq : IsSelfAdjoint q) (hqq : q*q=q) + (hF : IsSelfAdjoint F) (hG : IsSelfAdjoint G) (hcF : Commute q F) (hcG : Commute q G) + (d : ℝ) (_ : 0 < d) (hFb : ‖q * F^4‖ ≤ 1/d) (hGb : ‖q * G^4‖ ≤ 1/d) : + ‖F*q*G‖^2 ≤ 1/d := by + have hsF : IsSelfAdjoint (q*F) := by + change star (q*F)=q*F + rw [star_mul,hsq.star_eq,hF.star_eq,hcF.eq] + have hsG : IsSelfAdjoint (q*G) := by + change star (q*G)=q*G + rw [star_mul,hsq.star_eq,hG.star_eq,hcG.eq] + have hnF : ‖q*F‖^4 ≤ 1/d := by + have hn : ‖(q*F)^4‖=‖q*F‖^4 := by simpa using hsF.norm_pow_two_pow 2 + rw [← hn,supported_fourth q F hqq hcF] + exact hFb + have hnG : ‖q*G‖^4 ≤ 1/d := by + have hn : ‖(q*G)^4‖=‖q*G‖^4 := by simpa using hsG.norm_pow_two_pow 2 + rw [← hn,supported_fourth q G hqq hcG] + exact hGb + have he : F*q*G=(q*F)*(q*G) := by + calc + _ = F*(q*q)*G := by rw [hqq] + _ = (F*q)*(q*G) := by noncomm_ring + _ = _ := by rw [hcF.eq] + have hn := norm_mul_le (q*F) (q*G) + rw [← he] at hn + have hp : (‖q*F‖*‖q*G‖)^2 ≤ 1/d := by + have ha := sq_nonneg (‖q*F‖^2-‖q*G‖^2) + nlinarith + exact (pow_le_pow_left₀ (norm_nonneg _) hn 2).trans hp +end RowColumn + +end +end +end +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Sampling.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Sampling.lean index 717e623dc9c3d292b7e354f70b7888d4fdb8db3c..3639c8ade4b115537808118b03eeaa17e55f48a1 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Sampling.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Sampling.lean @@ -1,256 +1,256 @@ -import OAI.Probability.CubeShuffle.Basic -import OAI.RepresentationTheory.FiniteUnitary.Averaging - -namespace OAI - -namespace CubeShuffle -open scoped BigOperators Classical -variable {Ω G : Type*} [Fintype Ω] [Fintype G] - -noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := - finiteMean (fun ω => if P ω=g then 1 else 0) - -omit [Fintype G] in -lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := - div_nonneg (Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num)) (Nat.cast_nonneg _) - -lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by - unfold sampleLaw - rw [←finiteMean_sum] - simp [finiteMean, Fintype.card_ne_zero] - -omit [Fintype G] in -lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : - 0 by split_ifs <;> norm_num)] - simp only [Finset.mem_univ,true_and] - apply exists_congr - intro ω - split_ifs <;> simp_all - -omit [Fintype G] in -lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : - sampleLaw (P ∘ e)=sampleLaw P := by - funext g - simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using - finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) - -variable [Group G] -omit [Fintype G] in -lemma sampleLaw_inverse (P : Ω → G) (g : G) : - sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by - apply finiteMean_congr - intro ω - rw [inv_eq_iff_eq_inv] - -omit [Fintype G] in -lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) - (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by - rw [←sampleLaw_inverse] - have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) - rw [hh,sampleLaw_equiv] - -end CubeShuffle - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] - -noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := - (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) - -omit [Fintype G] in -lemma continuousRepresentation_comp {H : Type*} [Group H] - (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : - continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl - -omit [Fintype G] in -lemma sampleOperator_comp {H : Type*} [Group H] - (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : - sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma unitary_comp {H : Type*} [Group H] - (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : - IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w - -omit [Fintype G] in -lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) - (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : - Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by - unfold sampleOperator - apply Commute.smul_left - apply Commute.smul_right - apply Commute.sum_left - intro ω _ - apply Commute.sum_right - intro ξ _ - exact (h ω ξ).map (continuousRepresentation ρ) - -lemma sampleOperator_weighted (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ P=weightedOperator ρ (sampleLaw P) := by - unfold sampleOperator weightedOperator sampleLaw finiteMean - simp only [Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul,Finset.sum_smul] - rw [Finset.sum_comm] - simp only [Finset.smul_sum] - apply Finset.sum_congr rfl - intro ω _ - calc - _ = ∑ g, if P ω=g then (Fintype.card Ω:ℂ)⁻¹ • continuousRepresentation ρ g else 0 := by - symm - simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] - _ = _ := by - apply Finset.sum_congr rfl - intro g _ - split_ifs <;> simp_all - -lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - ‖sampleOperator ρ P‖≤1 := by - rw [sampleOperator_weighted] - exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) - -omit [Fintype G] in -lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : - sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by - simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] - rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] - -omit [Fintype G] in -lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : - sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by - simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, - Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro ω _ - apply Finset.sum_congr rfl - intro ξ _ - rw [mul_comm] - -omit [Fintype G] in -lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : - sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by - simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, - continuousRepresentation_adjoint ρ hρ] - -omit [Fintype G] in -lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : - sampleOperator ρ (fun _ : Ω => 1)=1 := by - simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, - smul_smul] - rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] - -lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by - simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, - Finset.smul_sum,id_eq] - -lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : - sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by - rw [sampleOperator_prod] - have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by - rw [←sampleOperator_uniform] - exact sampleOperator_equiv ρ id (Equiv.inv G) - rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] - -end CubeShuffle.UnitaryFinite - -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] -variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] - [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] - [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : - averageMap ρ σ A=0 := by - rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h - · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim - · exact h - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) - (u z : W) (v w : V) : - ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by - have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap - have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he - change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv - simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, - InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, - inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv - -end CubeShuffle.UnitaryFinite -namespace CubeShuffle.UnitaryFinite -open scoped BigOperators ComplexConjugate Classical - -variable {G : Type*} [Group G] [Fintype G] - -def regularAction : G →* Equiv.Perm G where - toFun := Equiv.mulLeft - map_one' := by ext; simp - map_mul' _ _ := by ext; simp - -omit [Fintype G] in -lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] - -omit [Fintype G] [FiniteDimensional ℂ V] in -lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by - intro g hg - have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg - subst g - simp - -noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := - normalizedCoefficient regularAction 1 regular_transitive ρ w v - -omit [FiniteDimensional ℂ V] in -lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : - regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by - unfold regularCoefficient normalizedCoefficient - simp only [PiLp.smul_apply,smul_eq_mul] - congr 1 - have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g - simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he - -lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] - (hρ : IsUnitary ρ) (w z v t : V) : - inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := - normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z - (regular_fixed ρ w) (regular_fixed ρ z) v t - -variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] - -omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in -lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) - [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] - (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) - (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by - rw [PiLp.inner_apply] - simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, - inner_conj_symm] - have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z - calc - _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* - (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * - ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro g _ - ring - _ = 0 := by rw [he,mul_zero] - -end CubeShuffle.UnitaryFinite - -end OAI +import OAI.Probability.CubeShuffle.Basic +import OAI.RepresentationTheory.FiniteUnitary.Averaging + +namespace OAI + +namespace CubeShuffle +open scoped BigOperators Classical +variable {Ω G : Type*} [Fintype Ω] [Fintype G] + +noncomputable def sampleLaw (P : Ω → G) (g : G) : ℝ := + finiteMean (fun ω => if P ω=g then 1 else 0) + +omit [Fintype G] in +lemma sampleLaw_nonneg (P : Ω → G) (g : G) : 0 ≤ sampleLaw P g := + div_nonneg (Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num)) (Nat.cast_nonneg _) + +lemma sampleLaw_sum [Nonempty Ω] (P : Ω → G) : ∑ g,sampleLaw P g=1 := by + unfold sampleLaw + rw [←finiteMean_sum] + simp [finiteMean, Fintype.card_ne_zero] + +omit [Fintype G] in +lemma sampleLaw_pos_iff [Nonempty Ω] (P : Ω → G) (g : G) : + 0 by split_ifs <;> norm_num)] + simp only [Finset.mem_univ,true_and] + apply exists_congr + intro ω + split_ifs <;> simp_all + +omit [Fintype G] in +lemma sampleLaw_equiv {Ω' : Type*} [Fintype Ω'] (P : Ω → G) (e : Ω' ≃ Ω) : + sampleLaw (P ∘ e)=sampleLaw P := by + funext g + simpa only [sampleLaw,Function.comp_apply,Equiv.apply_symm_apply] using + finiteMean_equiv e (fun ω => if P (e ω)=g then (1:ℝ) else 0) + +variable [Group G] +omit [Fintype G] in +lemma sampleLaw_inverse (P : Ω → G) (g : G) : + sampleLaw (fun ω => (P ω)⁻¹) g=sampleLaw P g⁻¹ := by + apply finiteMean_congr + intro ω + rw [inv_eq_iff_eq_inv] + +omit [Fintype G] in +lemma sampleLaw_symmetric (P : Ω → G) (e : Equiv.Perm Ω) + (he : ∀ ω,P (e ω)=(P ω)⁻¹) (g : G) : sampleLaw P g⁻¹=sampleLaw P g := by + rw [←sampleLaw_inverse] + have hh : (fun ω => (P ω)⁻¹)=P ∘ e := funext (fun ω => (he ω).symm) + rw [hh,sampleLaw_equiv] + +end CubeShuffle + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + +noncomputable def sampleOperator (ρ : Representation ℂ G V) (P : Ω → G) : V →L[ℂ] V := + (Fintype.card Ω:ℂ)⁻¹ • ∑ ω,continuousRepresentation ρ (P ω) + +omit [Fintype G] in +lemma continuousRepresentation_comp {H : Type*} [Group H] + (ρ : Representation ℂ G V) (φ : H →* G) (h : H) : + continuousRepresentation (ρ.comp φ) h=continuousRepresentation ρ (φ h) := rfl + +omit [Fintype G] in +lemma sampleOperator_comp {H : Type*} [Group H] + (ρ : Representation ℂ G V) (φ : H →* G) (P : Ω → H) : + sampleOperator (ρ.comp φ) P=sampleOperator ρ (φ ∘ P) := rfl + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma unitary_comp {H : Type*} [Group H] + (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (φ : H →* G) : + IsUnitary (ρ.comp φ) := fun h v w => hρ (φ h) v w + +omit [Fintype G] in +lemma sampleOperator_commute (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) + (h : ∀ ω ξ, Commute (P ω) (Q ξ)) : + Commute (sampleOperator ρ P) (sampleOperator ρ Q) := by + unfold sampleOperator + apply Commute.smul_left + apply Commute.smul_right + apply Commute.sum_left + intro ω _ + apply Commute.sum_right + intro ξ _ + exact (h ω ξ).map (continuousRepresentation ρ) + +lemma sampleOperator_weighted (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ P=weightedOperator ρ (sampleLaw P) := by + unfold sampleOperator weightedOperator sampleLaw finiteMean + simp only [Complex.ofReal_sum,div_eq_mul_inv,Finset.sum_mul,Finset.sum_smul] + rw [Finset.sum_comm] + simp only [Finset.smul_sum] + apply Finset.sum_congr rfl + intro ω _ + calc + _ = ∑ g, if P ω=g then (Fintype.card Ω:ℂ)⁻¹ • continuousRepresentation ρ g else 0 := by + symm + simp only [Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte] + _ = _ := by + apply Finset.sum_congr rfl + intro g _ + split_ifs <;> simp_all + +lemma sampleOperator_norm_le [Nonempty Ω] (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + ‖sampleOperator ρ P‖≤1 := by + rw [sampleOperator_weighted] + exact (weightedOperator_norm_le ρ hρ _ (sampleLaw_nonneg _)).trans_eq (sampleLaw_sum P) + +omit [Fintype G] in +lemma sampleOperator_equiv (ρ : Representation ℂ G V) (P : Ω → G) (e : Ξ ≃ Ω) : + sampleOperator ρ (P ∘ e)=sampleOperator ρ P := by + simp only [sampleOperator,Fintype.card_congr e,Function.comp_apply] + rw [Equiv.sum_comp e (fun ω => continuousRepresentation ρ (P ω))] + +omit [Fintype G] in +lemma sampleOperator_prod (ρ : Representation ℂ G V) (P : Ω → G) (Q : Ξ → G) : + sampleOperator ρ (fun ω : Ω × Ξ => P ω.1*Q ω.2)=sampleOperator ρ P*sampleOperator ρ Q := by + simp only [sampleOperator,Fintype.card_prod,Nat.cast_mul,mul_inv_rev,map_mul,Fintype.sum_prod_type, + Finset.sum_mul,Finset.mul_sum,smul_mul_smul,Finset.smul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro ξ _ + rw [mul_comm] + +omit [Fintype G] in +lemma sampleOperator_inv (ρ : Representation ℂ G V) (hρ : IsUnitary ρ) (P : Ω → G) : + sampleOperator ρ (fun ω => (P ω)⁻¹)=(sampleOperator ρ P).adjoint := by + simp only [sampleOperator,map_smulₛₗ,map_sum,map_inv₀,map_natCast, + continuousRepresentation_adjoint ρ hρ] + +omit [Fintype G] in +lemma sampleOperator_one [Nonempty Ω] (ρ : Representation ℂ G V) : + sampleOperator ρ (fun _ : Ω => 1)=1 := by + simp only [sampleOperator,map_one,Finset.sum_const,Finset.card_univ,←Nat.cast_smul_eq_nsmul ℂ, + smul_smul] + rw [inv_mul_cancel₀ (by exact_mod_cast Fintype.card_ne_zero),one_smul] + +lemma sampleOperator_uniform (ρ : Representation ℂ G V) : sampleOperator ρ (id : G → G)=uniformOperator ρ := by + simp only [sampleOperator,uniformOperator,weightedOperator,Complex.ofReal_inv,Complex.ofReal_natCast, + Finset.smul_sum,id_eq] + +lemma sampleOperator_uniform_mul [Nonempty Ω] (ρ : Representation ℂ G V) (P : Ω → G) : + sampleOperator ρ (fun ω : Ω × G => P ω.1*ω.2⁻¹)=uniformOperator ρ := by + rw [sampleOperator_prod] + have he : sampleOperator ρ (fun g : G => g⁻¹)=uniformOperator ρ := by + rw [←sampleOperator_uniform] + exact sampleOperator_equiv ρ id (Equiv.inv G) + rw [he,sampleOperator_weighted,weighted_uniform_left,sampleLaw_sum,one_smul] + +end CubeShuffle.UnitaryFinite + +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] +variable {V W : Type*} [NormedAddCommGroup V] [NormedAddCommGroup W] + [InnerProductSpace ℂ V] [InnerProductSpace ℂ W] + [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma averageMap_zero (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hne : ¬Nonempty (Representation.Equiv ρ σ)) (A : V →ₗ[ℂ] W) : + averageMap ρ σ A=0 := by + rcases Representation.IsIrreducible.bijective_or_eq_zero (averageMap ρ σ A) with h|h + · exact (hne ⟨Representation.IntertwiningMap.ofBijective _ h⟩).elim + · exact h + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma coefficient_cross_orthogonality (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hρ : IsUnitary ρ) (hne : ¬Nonempty (Representation.Equiv ρ σ)) + (u z : W) (v w : V) : + ∑ g, inner ℂ u (σ g z)*inner ℂ (ρ g w) v=0 := by + have he := averageMap_zero ρ σ hne (InnerProductSpace.rankOne ℂ z w).toLinearMap + have hv := congrArg (fun T : Representation.IntertwiningMap ρ σ => inner ℂ u (T v)) he + change inner ℂ u ((∑ g, (σ g).comp ((InnerProductSpace.rankOne ℂ z w).toLinearMap.comp (ρ g⁻¹))) v)=_ at hv + simpa only [LinearMap.sum_apply,LinearMap.comp_apply,ContinuousLinearMap.coe_coe, + InnerProductSpace.rankOne_apply,map_smul,unitary_inner_inv ρ hρ,inner_sum, + inner_smul_right,Representation.IntertwiningMap.coe_zero,Pi.zero_apply,inner_zero_right,mul_comm] using hv + +end CubeShuffle.UnitaryFinite +namespace CubeShuffle.UnitaryFinite +open scoped BigOperators ComplexConjugate Classical + +variable {G : Type*} [Group G] [Fintype G] + +def regularAction : G →* Equiv.Perm G where + toFun := Equiv.mulLeft + map_one' := by ext; simp + map_mul' _ _ := by ext; simp + +omit [Fintype G] in +lemma regular_transitive (x : G) : ∃ g,regularAction g (1:G)=x := ⟨x,mul_one x⟩ + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] + +omit [Fintype G] [FiniteDimensional ℂ V] in +lemma regular_fixed (ρ : Representation ℂ G V) (w : V) : IsFixed regularAction (1:G) ρ w := by + intro g hg + have he : g=1 := by simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using hg + subst g + simp + +noncomputable def regularCoefficient (ρ : Representation ℂ G V) (w v : V) : EuclideanSpace ℂ G := + normalizedCoefficient regularAction 1 regular_transitive ρ w v + +omit [FiniteDimensional ℂ V] in +lemma regularCoefficient_apply (ρ : Representation ℂ G V) (w v : V) (g : G) : + regularCoefficient ρ w v g = (Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)*inner ℂ (ρ g w) v := by + unfold regularCoefficient normalizedCoefficient + simp only [PiLp.smul_apply,smul_eq_mul] + congr 1 + have he := coefficient_at regularAction 1 regular_transitive ρ w (regular_fixed ρ w) v g + simpa only [regularAction,MonoidHom.coe_mk,OneHom.coe_mk,Equiv.coe_mulLeft,mul_one] using he + +lemma regularCoefficient_inner (ρ : Representation ℂ G V) [Representation.IsIrreducible ρ] + (hρ : IsUnitary ρ) (w z v t : V) : + inner ℂ (regularCoefficient ρ w v) (regularCoefficient ρ z t)=inner ℂ z w*inner ℂ v t := + normalizedCoefficient_inner regularAction 1 regular_transitive ρ hρ w z + (regular_fixed ρ w) (regular_fixed ρ z) v t + +variable {W : Type*} [NormedAddCommGroup W] [InnerProductSpace ℂ W] [FiniteDimensional ℂ W] + +omit [FiniteDimensional ℂ V] [FiniteDimensional ℂ W] in +lemma regularCoefficient_cross (ρ : Representation ℂ G V) (σ : Representation ℂ G W) + [Representation.IsIrreducible ρ] [Representation.IsIrreducible σ] + (hσ : IsUnitary σ) (hne : ¬Nonempty (Representation.Equiv σ ρ)) + (w v : V) (z t : W) : inner ℂ (regularCoefficient ρ w v) (regularCoefficient σ z t)=0 := by + rw [PiLp.inner_apply] + simp only [RCLike.inner_apply,regularCoefficient_apply,map_mul,Complex.conj_ofReal, + inner_conj_symm] + have he := coefficient_cross_orthogonality σ ρ hσ hne v w t z + calc + _ = ((Real.sqrt ((Module.finrank ℂ V:ℝ)/(Fintype.card G:ℝ)):ℂ)* + (Real.sqrt ((Module.finrank ℂ W:ℝ)/(Fintype.card G:ℝ)):ℂ)) * + ∑ g,inner ℂ v (ρ g w)*inner ℂ (σ g z) t := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro g _ + ring + _ = 0 := by rw [he,mul_zero] + +end CubeShuffle.UnitaryFinite + +end OAI diff --git a/lean/OAI/RepresentationTheory/FiniteUnitary/Uncertainty.lean b/lean/OAI/RepresentationTheory/FiniteUnitary/Uncertainty.lean index 37d6fa90a58dfcebf2b983deafb89e5973f13c59..0ec94a5b2df201e4f687f2a23008cba9e6d467ff 100644 --- a/lean/OAI/RepresentationTheory/FiniteUnitary/Uncertainty.lean +++ b/lean/OAI/RepresentationTheory/FiniteUnitary/Uncertainty.lean @@ -1,139 +1,139 @@ -import Mathlib - -namespace OAI - -namespace CubeShuffle.PermutationHilbert -open scoped BigOperators ComplexConjugate Classical -open Complex - -variable {X : Type*} [Fintype X] -abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X - -noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := - LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p - -@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : - act p v x = v (p⁻¹ x) := rfl - -lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : - act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by - exact EuclideanSpace.piLpCongrLeft_single p x 1 - -lemma trace_projection (W : Submodule ℂ (H X)) : - ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by - classical - have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by - constructor - · intro x; exact (W.orthogonalProjectionOnto x).2 - · intro x hx; exact W.starProjection_eq_self_iff.mpr hx - have ht := hp.trace - rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht - simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, - EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, - OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht - -lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : - (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - classical - have hh := W.inner_starProjection_left_eq_right - (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) - have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := - W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 - rw [hf] at hh - rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh - simpa using hh.symm - -lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) - (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : - act p (W.starProjection v) = W.starProjection (act p v) := by - have hh := (act p).toLinearIsometry.map_starProjection W v - change act p (W.starProjection v) = - (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh - simpa only [hW] using hh - -/-- A transitive invariant subspace has constant diagonal orthogonal projection. -/ -lemma uniform_diagonal (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : - (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = - Module.finrank ℂ W := by - classical - have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = - (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by - obtain ⟨p,hp,hW⟩ := htrans x y - subst y - rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] - have ht := trace_projection W - simp_rw [hh] at ht - have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = - (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht - simpa using hhreal - -/-- The uncertainty bound, with no assumption of irreducibility. -/ -theorem uncertainty (W : Submodule ℂ (H X)) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (v : H X) (hv : v ∈ W) (x : X) : - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by - classical - have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by - rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, - EuclideanSpace.inner_single_left] - simp - have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v - rw [hh] at hc - have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by - nlinarith [norm_nonneg (v x),norm_nonneg v, - norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] - calc - (Fintype.card X:ℝ) * ‖v x‖^2 ≤ - (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := - mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) - _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] - -end CubeShuffle.PermutationHilbert -namespace CubeShuffle.PermutationHilbert -open scoped BigOperators Classical - -variable {X : Type*} [Fintype X] - -lemma trace_projection_real (W : Submodule ℂ (H X)) : - ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by - have hh := trace_projection W - simp_rw [projection_diagonal] at hh - exact_mod_cast hh - -/-- A coordinate footprint fixed by a subgroup supplies an unconditional -lower bound on invariant multiplicity. This is the trace form of the branching -estimate, valid for every transitive invariant submodule. -/ -theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) - (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ - W.map (act p).toLinearEquiv.toLinearMap = W) - (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : - (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ - (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by - have he (x : X) (hx : x ∈ S) : - K.starProjection (EuclideanSpace.single x (1:ℂ)) = - W.starProjection (EuclideanSpace.single x (1:ℂ)) := by - apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) - intro v hv - exact W.starProjection_inner_eq_zero _ v (hKW hv) - have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ - (Module.finrank ℂ K:ℝ) := by - rw [←trace_projection_real K] - calc - _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by - apply Finset.sum_congr rfl - intro x hx - rw [he x hx] - _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) - have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) - rw [Finset.mul_sum] at hmul - simp_rw [uniform_diagonal W htrans] at hmul - simpa using hmul - -end CubeShuffle.PermutationHilbert - -end OAI +import Mathlib + +namespace OAI + +namespace CubeShuffle.PermutationHilbert +open scoped BigOperators ComplexConjugate Classical +open Complex + +variable {X : Type*} [Fintype X] +abbrev H (X : Type*) [Fintype X] := EuclideanSpace ℂ X + +noncomputable def act (p : Equiv.Perm X) : H X ≃ₗᵢ[ℂ] H X := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ p + +@[simp] lemma act_apply (p : Equiv.Perm X) (v : H X) (x : X) : + act p v x = v (p⁻¹ x) := rfl + +lemma act_single [DecidableEq X] (p : Equiv.Perm X) (x : X) : + act p (EuclideanSpace.single x (1:ℂ)) = EuclideanSpace.single (p x) 1 := by + exact EuclideanSpace.piLpCongrLeft_single p x 1 + +lemma trace_projection (W : Submodule ℂ (H X)) : + ∑ x, (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = Module.finrank ℂ W := by + classical + have hp : LinearMap.IsProj W W.starProjection.toLinearMap := by + constructor + · intro x; exact (W.orthogonalProjectionOnto x).2 + · intro x hx; exact W.starProjection_eq_self_iff.mpr hx + have ht := hp.trace + rw [LinearMap.trace_eq_matrix_trace ℂ (EuclideanSpace.basisFun X ℂ).toBasis] at ht + simpa only [Matrix.trace,Matrix.diag_apply,LinearMap.toMatrix_apply,EuclideanSpace.basisFun_repr, + EuclideanSpace.basisFun_apply,OrthonormalBasis.coe_toBasis, + OrthonormalBasis.coe_toBasis_repr_apply,ContinuousLinearMap.coe_coe] using ht + +lemma projection_diagonal (W : Submodule ℂ (H X)) (x : X) : + (W.starProjection (EuclideanSpace.single x (1:ℂ))) x = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + classical + have hh := W.inner_starProjection_left_eq_right + (EuclideanSpace.single x (1:ℂ)) (W.starProjection (EuclideanSpace.single x (1:ℂ))) + have hf : W.starProjection (W.starProjection (EuclideanSpace.single x (1:ℂ))) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := + W.starProjection_eq_self_iff.mpr (W.orthogonalProjectionOnto _).2 + rw [hf] at hh + rw [inner_self_eq_norm_sq_to_K,EuclideanSpace.inner_single_left] at hh + simpa using hh.symm + +lemma projection_comm (W : Submodule ℂ (H X)) (p : Equiv.Perm X) + (hW : W.map (act p).toLinearEquiv.toLinearMap = W) (v : H X) : + act p (W.starProjection v) = W.starProjection (act p v) := by + have hh := (act p).toLinearIsometry.map_starProjection W v + change act p (W.starProjection v) = + (W.map (act p).toLinearEquiv.toLinearMap).starProjection (act p v) at hh + simpa only [hW] using hh + +/-- A transitive invariant subspace has constant diagonal orthogonal projection. -/ +lemma uniform_diagonal (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) (x : X) : + (Fintype.card X:ℝ) * ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = + Module.finrank ℂ W := by + classical + have hh (y : X) : (W.starProjection (EuclideanSpace.single y (1:ℂ))) y = + (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 : ℝ) := by + obtain ⟨p,hp,hW⟩ := htrans x y + subst y + rw [projection_diagonal,←act_single p x,←projection_comm W p hW,(act p).norm_map] + have ht := trace_projection W + simp_rw [hh] at ht + have hhreal : (∑ _y : X, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2) = + (Module.finrank ℂ W:ℝ) := by exact_mod_cast ht + simpa using hhreal + +/-- The uncertainty bound, with no assumption of irreducibility. -/ +theorem uncertainty (W : Submodule ℂ (H X)) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (v : H X) (hv : v ∈ W) (x : X) : + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ (Module.finrank ℂ W:ℝ) * ‖v‖^2 := by + classical + have hh : inner ℂ (W.starProjection (EuclideanSpace.single x (1:ℂ))) v = v x := by + rw [W.inner_starProjection_left_eq_right,W.starProjection_eq_self_iff.mpr hv, + EuclideanSpace.inner_single_left] + simp + have hc := norm_inner_le_norm (𝕜 := ℂ) (W.starProjection (EuclideanSpace.single x (1:ℂ))) v + rw [hh] at hc + have hs : ‖v x‖^2 ≤ ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2 := by + nlinarith [norm_nonneg (v x),norm_nonneg v, + norm_nonneg (W.starProjection (EuclideanSpace.single x (1:ℂ)))] + calc + (Fintype.card X:ℝ) * ‖v x‖^2 ≤ + (Fintype.card X:ℝ) * (‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 * ‖v‖^2) := + mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg _) + _ = _ := by rw [←mul_assoc,uniform_diagonal W htrans x] + +end CubeShuffle.PermutationHilbert +namespace CubeShuffle.PermutationHilbert +open scoped BigOperators Classical + +variable {X : Type*} [Fintype X] + +lemma trace_projection_real (W : Submodule ℂ (H X)) : + ∑ x, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 = (Module.finrank ℂ W:ℝ) := by + have hh := trace_projection W + simp_rw [projection_diagonal] at hh + exact_mod_cast hh + +/-- A coordinate footprint fixed by a subgroup supplies an unconditional +lower bound on invariant multiplicity. This is the trace form of the branching +estimate, valid for every transitive invariant submodule. -/ +theorem footprint_dimension (W K : Submodule ℂ (H X)) (hKW : K ≤ W) + (htrans : ∀ x y : X, ∃ p : Equiv.Perm X, p x = y ∧ + W.map (act p).toLinearEquiv.toLinearMap = W) + (S : Finset X) (hS : ∀ x ∈ S, W.starProjection (EuclideanSpace.single x (1:ℂ)) ∈ K) : + (S.card:ℝ) * (Module.finrank ℂ W:ℝ) ≤ + (Fintype.card X:ℝ) * (Module.finrank ℂ K:ℝ) := by + have he (x : X) (hx : x ∈ S) : + K.starProjection (EuclideanSpace.single x (1:ℂ)) = + W.starProjection (EuclideanSpace.single x (1:ℂ)) := by + apply K.eq_starProjection_of_mem_of_inner_eq_zero (hS x hx) + intro v hv + exact W.starProjection_inner_eq_zero _ v (hKW hv) + have hs : ∑ x ∈ S, ‖W.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 ≤ + (Module.finrank ℂ K:ℝ) := by + rw [←trace_projection_real K] + calc + _ = ∑ x ∈ S, ‖K.starProjection (EuclideanSpace.single x (1:ℂ))‖^2 := by + apply Finset.sum_congr rfl + intro x hx + rw [he x hx] + _ ≤ _ := Finset.sum_le_univ_sum_of_nonneg (fun x => sq_nonneg _) + have hmul := mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg (Fintype.card X): (0:ℝ) ≤ _) + rw [Finset.mul_sum] at hmul + simp_rw [uniform_diagonal W htrans] at hmul + simpa using hmul + +end CubeShuffle.PermutationHilbert + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe.lean b/lean/OAI/RepresentationTheory/FoulkesHowe.lean index c70a81904384a674745e725e3590583dc7463327..37ced73b16d442f9f0dc0f7df21874454c26f13d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe.lean @@ -1,77 +1,77 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model -import OAI.RepresentationTheory.FoulkesHowe.LinearCase -import OAI.RepresentationTheory.FoulkesHowe.Actions -import OAI.RepresentationTheory.FoulkesHowe.Annihilator -import OAI.RepresentationTheory.FoulkesHowe.BackwardCancellation -import OAI.RepresentationTheory.FoulkesHowe.BinaryFactorization -import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation -import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity -import OAI.RepresentationTheory.FoulkesHowe.ShiftSequence -import OAI.RepresentationTheory.FoulkesHowe.BlockWeight -import OAI.RepresentationTheory.FoulkesHowe.CanonicalMap -import OAI.RepresentationTheory.FoulkesHowe.Surjectivity -import OAI.RepresentationTheory.FoulkesHowe.DualComparison -import OAI.RepresentationTheory.FoulkesHowe.DegreeOne -import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity -import OAI.RepresentationTheory.FoulkesHowe.DiagonalCoefficient -import OAI.RepresentationTheory.FoulkesHowe.DiagonalPolarization -import OAI.RepresentationTheory.FoulkesHowe.DualEmbedding -import OAI.RepresentationTheory.FoulkesHowe.EncodedCancellation -import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous -import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension -import OAI.RepresentationTheory.FoulkesHowe.FirstCounts -import OAI.RepresentationTheory.FoulkesHowe.FirstLabels -import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial -import OAI.RepresentationTheory.FoulkesHowe.FirstTransfer -import OAI.RepresentationTheory.FoulkesHowe.TransferDerivative -import OAI.RepresentationTheory.FoulkesHowe.TransferEndpoints -import OAI.RepresentationTheory.FoulkesHowe.FixedSlot -import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm -import OAI.RepresentationTheory.FoulkesHowe.FlattenedSwap -import OAI.RepresentationTheory.FoulkesHowe.FoulkesDiagonal -import OAI.RepresentationTheory.FoulkesHowe.FoulkesMultilinear -import OAI.RepresentationTheory.FoulkesHowe.FoulkesSymmetries -import OAI.RepresentationTheory.FoulkesHowe.Functoriality -import OAI.RepresentationTheory.FoulkesHowe.GridCancellation -import OAI.RepresentationTheory.FoulkesHowe.MonomialCut -import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear -import OAI.RepresentationTheory.FoulkesHowe.MultilinearDescent -import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial -import OAI.RepresentationTheory.FoulkesHowe.Multiplication -import OAI.RepresentationTheory.FoulkesHowe.Naturality -import OAI.RepresentationTheory.FoulkesHowe.PairingConstruction -import OAI.RepresentationTheory.FoulkesHowe.PairingPerfection -import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing -import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual -import OAI.RepresentationTheory.FoulkesHowe.PolynomialShift -import OAI.RepresentationTheory.FoulkesHowe.PowerSpan -import OAI.RepresentationTheory.FoulkesHowe.Polarization -import OAI.RepresentationTheory.FoulkesHowe.RowSwap -import OAI.RepresentationTheory.FoulkesHowe.SecondTransfer -import OAI.RepresentationTheory.FoulkesHowe.SecondCounts -import OAI.RepresentationTheory.FoulkesHowe.SecondLabels -import OAI.RepresentationTheory.FoulkesHowe.SecondEndpoints -import OAI.RepresentationTheory.FoulkesHowe.SecondSwap -import OAI.RepresentationTheory.FoulkesHowe.ShiftHomogeneity -import OAI.RepresentationTheory.FoulkesHowe.ShiftInjectivity -import OAI.RepresentationTheory.FoulkesHowe.ShiftNilpotence -import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative -import OAI.RepresentationTheory.FoulkesHowe.Spanning -import OAI.RepresentationTheory.FoulkesHowe.SpanningAgreement -import OAI.RepresentationTheory.FoulkesHowe.StabilizationBounds -import OAI.RepresentationTheory.FoulkesHowe.SumShift -import OAI.RepresentationTheory.FoulkesHowe.AlgebraEvaluation -import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual -import OAI.RepresentationTheory.FoulkesHowe.DualEquivalence -import OAI.RepresentationTheory.FoulkesHowe.SymmetricPairing -import OAI.RepresentationTheory.FoulkesHowe.PairingLift -import OAI.RepresentationTheory.FoulkesHowe.GeneratorLift -import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift -import OAI.RepresentationTheory.FoulkesHowe.TensorPresentation -import OAI.RepresentationTheory.FoulkesHowe.Vanishing -import OAI.RepresentationTheory.FoulkesHowe.BinaryVanishing -import OAI.RepresentationTheory.FoulkesHowe.ProductVanishing -import OAI.RepresentationTheory.FoulkesHowe.VanishingFirst -import OAI.RepresentationTheory.FoulkesHowe.VanishingInduction -import OAI.RepresentationTheory.FoulkesHowe.VanishingOne -import OAI.RepresentationTheory.FoulkesHowe.Stabilization +import OAI.RepresentationTheory.FoulkesHowe.Model +import OAI.RepresentationTheory.FoulkesHowe.LinearCase +import OAI.RepresentationTheory.FoulkesHowe.Actions +import OAI.RepresentationTheory.FoulkesHowe.Annihilator +import OAI.RepresentationTheory.FoulkesHowe.BackwardCancellation +import OAI.RepresentationTheory.FoulkesHowe.BinaryFactorization +import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation +import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity +import OAI.RepresentationTheory.FoulkesHowe.ShiftSequence +import OAI.RepresentationTheory.FoulkesHowe.BlockWeight +import OAI.RepresentationTheory.FoulkesHowe.CanonicalMap +import OAI.RepresentationTheory.FoulkesHowe.Surjectivity +import OAI.RepresentationTheory.FoulkesHowe.DualComparison +import OAI.RepresentationTheory.FoulkesHowe.DegreeOne +import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity +import OAI.RepresentationTheory.FoulkesHowe.DiagonalCoefficient +import OAI.RepresentationTheory.FoulkesHowe.DiagonalPolarization +import OAI.RepresentationTheory.FoulkesHowe.DualEmbedding +import OAI.RepresentationTheory.FoulkesHowe.EncodedCancellation +import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous +import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension +import OAI.RepresentationTheory.FoulkesHowe.FirstCounts +import OAI.RepresentationTheory.FoulkesHowe.FirstLabels +import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial +import OAI.RepresentationTheory.FoulkesHowe.FirstTransfer +import OAI.RepresentationTheory.FoulkesHowe.TransferDerivative +import OAI.RepresentationTheory.FoulkesHowe.TransferEndpoints +import OAI.RepresentationTheory.FoulkesHowe.FixedSlot +import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm +import OAI.RepresentationTheory.FoulkesHowe.FlattenedSwap +import OAI.RepresentationTheory.FoulkesHowe.FoulkesDiagonal +import OAI.RepresentationTheory.FoulkesHowe.FoulkesMultilinear +import OAI.RepresentationTheory.FoulkesHowe.FoulkesSymmetries +import OAI.RepresentationTheory.FoulkesHowe.Functoriality +import OAI.RepresentationTheory.FoulkesHowe.GridCancellation +import OAI.RepresentationTheory.FoulkesHowe.MonomialCut +import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear +import OAI.RepresentationTheory.FoulkesHowe.MultilinearDescent +import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial +import OAI.RepresentationTheory.FoulkesHowe.Multiplication +import OAI.RepresentationTheory.FoulkesHowe.Naturality +import OAI.RepresentationTheory.FoulkesHowe.PairingConstruction +import OAI.RepresentationTheory.FoulkesHowe.PairingPerfection +import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing +import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual +import OAI.RepresentationTheory.FoulkesHowe.PolynomialShift +import OAI.RepresentationTheory.FoulkesHowe.PowerSpan +import OAI.RepresentationTheory.FoulkesHowe.Polarization +import OAI.RepresentationTheory.FoulkesHowe.RowSwap +import OAI.RepresentationTheory.FoulkesHowe.SecondTransfer +import OAI.RepresentationTheory.FoulkesHowe.SecondCounts +import OAI.RepresentationTheory.FoulkesHowe.SecondLabels +import OAI.RepresentationTheory.FoulkesHowe.SecondEndpoints +import OAI.RepresentationTheory.FoulkesHowe.SecondSwap +import OAI.RepresentationTheory.FoulkesHowe.ShiftHomogeneity +import OAI.RepresentationTheory.FoulkesHowe.ShiftInjectivity +import OAI.RepresentationTheory.FoulkesHowe.ShiftNilpotence +import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative +import OAI.RepresentationTheory.FoulkesHowe.Spanning +import OAI.RepresentationTheory.FoulkesHowe.SpanningAgreement +import OAI.RepresentationTheory.FoulkesHowe.StabilizationBounds +import OAI.RepresentationTheory.FoulkesHowe.SumShift +import OAI.RepresentationTheory.FoulkesHowe.AlgebraEvaluation +import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual +import OAI.RepresentationTheory.FoulkesHowe.DualEquivalence +import OAI.RepresentationTheory.FoulkesHowe.SymmetricPairing +import OAI.RepresentationTheory.FoulkesHowe.PairingLift +import OAI.RepresentationTheory.FoulkesHowe.GeneratorLift +import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift +import OAI.RepresentationTheory.FoulkesHowe.TensorPresentation +import OAI.RepresentationTheory.FoulkesHowe.Vanishing +import OAI.RepresentationTheory.FoulkesHowe.BinaryVanishing +import OAI.RepresentationTheory.FoulkesHowe.ProductVanishing +import OAI.RepresentationTheory.FoulkesHowe.VanishingFirst +import OAI.RepresentationTheory.FoulkesHowe.VanishingInduction +import OAI.RepresentationTheory.FoulkesHowe.VanishingOne +import OAI.RepresentationTheory.FoulkesHowe.Stabilization diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Actions.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Actions.lean index 455f67d02e967d0f123c62d67fef9fbc301d4e14..693fbbd750b5e57b36f38fc05117f9d03a32546a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Actions.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Actions.lean @@ -1,119 +1,119 @@ -import OAI.RepresentationTheory.FoulkesHowe.Functoriality - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u -namespace Problem346 - -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Any map with the prescribed plethysm action carries the Foulkes formula - to the formula on the transformed vector array. -/ -theorem map_foulkesFormula_of_isPlethysmAction - {a b : ℕ} {g : V ≃ₗ[ℂ] V} - {L : SymPow a (SymPow b V) →ₗ[ℂ] SymPow a (SymPow b V)} - (hL : IsPlethysmAction a b V g L) (v : Fin b → Fin a → V) : - L (foulkesFormula a b V v) = - foulkesFormula a b V (fun j i => g (v j i)) := by - classical - unfold foulkesFormula - rw [map_smul, map_sum] - congr 1 - apply Finset.sum_congr rfl - intro σ _ - exact hL (fun i j => v j ((σ j) i)) - -/-- The canonical action of a linear automorphism on a plethysm. -/ -def plethysmEquiv (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - SymPow outer (SymPow inner V) ≃ₗ[ℂ] SymPow outer (SymPow inner V) := - symPowEquiv outer (symPowEquiv inner g) - -/-- The underlying endomorphism of the canonical plethysm action. -/ -def plethysmAction (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - SymPow outer (SymPow inner V) →ₗ[ℂ] SymPow outer (SymPow inner V) := - (plethysmEquiv outer inner g).toLinearMap - -@[simp] theorem plethysmAction_symMonomial (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) - (x : Fin outer → Fin inner → V) : - plethysmAction outer inner g - (symMonomial outer (SymPow inner V) (fun i => symMonomial inner V (x i))) = - symMonomial outer (SymPow inner V) - (fun i => symMonomial inner V (fun j => g (x i j))) := by - simp [plethysmAction, plethysmEquiv] - -theorem plethysmAction_isPlethysmAction (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - IsPlethysmAction outer inner V g (plethysmAction outer inner g) := - plethysmAction_symMonomial outer inner g - -theorem plethysmAction_bijective (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - Function.Bijective (plethysmAction outer inner g) := - (plethysmEquiv outer inner g).bijective - -theorem isGLEquivariantEmbedding_of_commutes {a b : ℕ} - (ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V)) - (hinj : Function.Injective ι) - (hcomm : ∀ g : V ≃ₗ[ℂ] V, - (plethysmAction b a g).comp ι = ι.comp (plethysmAction a b g)) : - IsGLEquivariantEmbedding a b V ι := by - refine ⟨hinj, ?_⟩ - intro g - exact ⟨plethysmAction b a g, plethysmAction a b g, - plethysmAction_isPlethysmAction b a g, - plethysmAction_isPlethysmAction a b g, - plethysmAction_bijective b a g, plethysmAction_bijective a b g, hcomm g⟩ - -@[simp] theorem plethysmAction_refl (outer inner : ℕ) : - plethysmAction outer inner (LinearEquiv.refl ℂ V) = LinearMap.id := by - simp [plethysmAction, plethysmEquiv] - -@[simp] theorem plethysmAction_trans (outer inner : ℕ) (g h : V ≃ₗ[ℂ] V) : - plethysmAction outer inner (g.trans h) = - (plethysmAction outer inner h).comp (plethysmAction outer inner g) := by - change symPowMap outer (symPowMap inner (g.trans h).toLinearMap) = _ - change symPowMap outer (symPowMap inner (h.toLinearMap.comp g.toLinearMap)) = _ - rw [symPowMap_comp, symPowMap_comp] - rfl - -@[simp] theorem plethysmAction_symm_comp (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - (plethysmAction outer inner g.symm).comp (plethysmAction outer inner g) = - LinearMap.id := by - rw [← plethysmAction_trans] - simp - -@[simp] theorem plethysmAction_comp_symm (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - (plethysmAction outer inner g).comp (plethysmAction outer inner g.symm) = - LinearMap.id := by - rw [← plethysmAction_trans] - simp - -/-- Conjugating by the natural GL actions preserves the defining canonical formula. -/ -theorem isFoulkesMap_conjugate {a b : ℕ} - {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} - (hμ : IsFoulkesMap a b V μ) (g : V ≃ₗ[ℂ] V) : - IsFoulkesMap a b V - ((plethysmAction a b g.symm).comp (μ.comp (plethysmAction b a g))) := by - intro v - simp only [LinearMap.comp_apply, plethysmAction_symMonomial] - rw [hμ] - rw [map_foulkesFormula_of_isPlethysmAction (plethysmAction_isPlethysmAction a b g.symm)] - simp - -/-- Uniqueness of the canonical map implies its GL equivariance. -/ -theorem foulkesMap_commutes_of_unique {a b : ℕ} - {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} - (hμ : IsFoulkesMap a b V μ) - (huniq : ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), - IsFoulkesMap a b V ν → ν = μ) - (g : V ≃ₗ[ℂ] V) : - (plethysmAction a b g).comp μ = μ.comp (plethysmAction b a g) := by - have hc := huniq _ (isFoulkesMap_conjugate hμ g) - have he := congrArg (fun L => (plethysmAction a b g).comp L) hc - simpa only [← LinearMap.comp_assoc, plethysmAction_comp_symm, LinearMap.id_comp] using he.symm - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Functoriality + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u +namespace Problem346 + +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Any map with the prescribed plethysm action carries the Foulkes formula + to the formula on the transformed vector array. -/ +theorem map_foulkesFormula_of_isPlethysmAction + {a b : ℕ} {g : V ≃ₗ[ℂ] V} + {L : SymPow a (SymPow b V) →ₗ[ℂ] SymPow a (SymPow b V)} + (hL : IsPlethysmAction a b V g L) (v : Fin b → Fin a → V) : + L (foulkesFormula a b V v) = + foulkesFormula a b V (fun j i => g (v j i)) := by + classical + unfold foulkesFormula + rw [map_smul, map_sum] + congr 1 + apply Finset.sum_congr rfl + intro σ _ + exact hL (fun i j => v j ((σ j) i)) + +/-- The canonical action of a linear automorphism on a plethysm. -/ +def plethysmEquiv (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + SymPow outer (SymPow inner V) ≃ₗ[ℂ] SymPow outer (SymPow inner V) := + symPowEquiv outer (symPowEquiv inner g) + +/-- The underlying endomorphism of the canonical plethysm action. -/ +def plethysmAction (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + SymPow outer (SymPow inner V) →ₗ[ℂ] SymPow outer (SymPow inner V) := + (plethysmEquiv outer inner g).toLinearMap + +@[simp] theorem plethysmAction_symMonomial (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) + (x : Fin outer → Fin inner → V) : + plethysmAction outer inner g + (symMonomial outer (SymPow inner V) (fun i => symMonomial inner V (x i))) = + symMonomial outer (SymPow inner V) + (fun i => symMonomial inner V (fun j => g (x i j))) := by + simp [plethysmAction, plethysmEquiv] + +theorem plethysmAction_isPlethysmAction (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + IsPlethysmAction outer inner V g (plethysmAction outer inner g) := + plethysmAction_symMonomial outer inner g + +theorem plethysmAction_bijective (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + Function.Bijective (plethysmAction outer inner g) := + (plethysmEquiv outer inner g).bijective + +theorem isGLEquivariantEmbedding_of_commutes {a b : ℕ} + (ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V)) + (hinj : Function.Injective ι) + (hcomm : ∀ g : V ≃ₗ[ℂ] V, + (plethysmAction b a g).comp ι = ι.comp (plethysmAction a b g)) : + IsGLEquivariantEmbedding a b V ι := by + refine ⟨hinj, ?_⟩ + intro g + exact ⟨plethysmAction b a g, plethysmAction a b g, + plethysmAction_isPlethysmAction b a g, + plethysmAction_isPlethysmAction a b g, + plethysmAction_bijective b a g, plethysmAction_bijective a b g, hcomm g⟩ + +@[simp] theorem plethysmAction_refl (outer inner : ℕ) : + plethysmAction outer inner (LinearEquiv.refl ℂ V) = LinearMap.id := by + simp [plethysmAction, plethysmEquiv] + +@[simp] theorem plethysmAction_trans (outer inner : ℕ) (g h : V ≃ₗ[ℂ] V) : + plethysmAction outer inner (g.trans h) = + (plethysmAction outer inner h).comp (plethysmAction outer inner g) := by + change symPowMap outer (symPowMap inner (g.trans h).toLinearMap) = _ + change symPowMap outer (symPowMap inner (h.toLinearMap.comp g.toLinearMap)) = _ + rw [symPowMap_comp, symPowMap_comp] + rfl + +@[simp] theorem plethysmAction_symm_comp (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + (plethysmAction outer inner g.symm).comp (plethysmAction outer inner g) = + LinearMap.id := by + rw [← plethysmAction_trans] + simp + +@[simp] theorem plethysmAction_comp_symm (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + (plethysmAction outer inner g).comp (plethysmAction outer inner g.symm) = + LinearMap.id := by + rw [← plethysmAction_trans] + simp + +/-- Conjugating by the natural GL actions preserves the defining canonical formula. -/ +theorem isFoulkesMap_conjugate {a b : ℕ} + {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} + (hμ : IsFoulkesMap a b V μ) (g : V ≃ₗ[ℂ] V) : + IsFoulkesMap a b V + ((plethysmAction a b g.symm).comp (μ.comp (plethysmAction b a g))) := by + intro v + simp only [LinearMap.comp_apply, plethysmAction_symMonomial] + rw [hμ] + rw [map_foulkesFormula_of_isPlethysmAction (plethysmAction_isPlethysmAction a b g.symm)] + simp + +/-- Uniqueness of the canonical map implies its GL equivariance. -/ +theorem foulkesMap_commutes_of_unique {a b : ℕ} + {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} + (hμ : IsFoulkesMap a b V μ) + (huniq : ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), + IsFoulkesMap a b V ν → ν = μ) + (g : V ≃ₗ[ℂ] V) : + (plethysmAction a b g).comp μ = μ.comp (plethysmAction b a g) := by + have hc := huniq _ (isFoulkesMap_conjugate hμ g) + have he := congrArg (fun L => (plethysmAction a b g).comp L) hc + simpa only [← LinearMap.comp_assoc, plethysmAction_comp_symm, LinearMap.id_comp] using he.symm + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/AlgebraEvaluation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/AlgebraEvaluation.lean index e8ab5cbe96811b57424ec7db6683176d8936198a..9e5fcab2cbd95bcc50694dcef82bd1df4ce19675 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/AlgebraEvaluation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/AlgebraEvaluation.lean @@ -1,45 +1,45 @@ -import Mathlib - -namespace OAI - -noncomputable section - -universe u -namespace Problem346 - -variable (W : Type u) [AddCommGroup W] [Module ℂ W] - -/-- Linear functionals separate points of the symmetric algebra over an infinite field. -/ -theorem symAlg_eq_zero_of_lift_eq_zero (p : SymmetricAlgebra ℂ W) - (h : ∀ φ : Module.Dual ℂ W, SymmetricAlgebra.lift φ p = 0) : p = 0 := by - classical - let b := Module.Free.chooseBasis ℂ W - let e := SymmetricAlgebra.equivMvPolynomial b - apply e.injective - simp only [map_zero] - apply MvPolynomial.funext - intro x - have he : (MvPolynomial.aeval x).comp e.toAlgHom = - SymmetricAlgebra.lift (b.constr ℂ x) := by - apply SymmetricAlgebra.algHom_ext - apply b.ext - intro i - simp [e] - have hx := congrArg (fun f : SymmetricAlgebra ℂ W →ₐ[ℂ] ℂ => f p) he - simpa using hx.trans (h (b.constr ℂ x)) - -/-- Evaluation at vectors separates the symmetric algebra on the dual of a finite-dimensional -space. -/ -theorem symAlg_dual_eq_zero_of_eval_eq_zero [FiniteDimensional ℂ W] - (p : SymmetricAlgebra ℂ (Module.Dual ℂ W)) - (h : ∀ x : W, SymmetricAlgebra.lift (Module.Dual.eval ℂ W x) p = 0) : p = 0 := by - apply symAlg_eq_zero_of_lift_eq_zero - intro φ - obtain ⟨x, rfl⟩ := (Module.evalEquiv ℂ W).surjective φ - exact h x - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +universe u +namespace Problem346 + +variable (W : Type u) [AddCommGroup W] [Module ℂ W] + +/-- Linear functionals separate points of the symmetric algebra over an infinite field. -/ +theorem symAlg_eq_zero_of_lift_eq_zero (p : SymmetricAlgebra ℂ W) + (h : ∀ φ : Module.Dual ℂ W, SymmetricAlgebra.lift φ p = 0) : p = 0 := by + classical + let b := Module.Free.chooseBasis ℂ W + let e := SymmetricAlgebra.equivMvPolynomial b + apply e.injective + simp only [map_zero] + apply MvPolynomial.funext + intro x + have he : (MvPolynomial.aeval x).comp e.toAlgHom = + SymmetricAlgebra.lift (b.constr ℂ x) := by + apply SymmetricAlgebra.algHom_ext + apply b.ext + intro i + simp [e] + have hx := congrArg (fun f : SymmetricAlgebra ℂ W →ₐ[ℂ] ℂ => f p) he + simpa using hx.trans (h (b.constr ℂ x)) + +/-- Evaluation at vectors separates the symmetric algebra on the dual of a finite-dimensional +space. -/ +theorem symAlg_dual_eq_zero_of_eval_eq_zero [FiniteDimensional ℂ W] + (p : SymmetricAlgebra ℂ (Module.Dual ℂ W)) + (h : ∀ x : W, SymmetricAlgebra.lift (Module.Dual.eval ℂ W x) p = 0) : p = 0 := by + apply symAlg_eq_zero_of_lift_eq_zero + intro φ + obtain ⟨x, rfl⟩ := (Module.evalEquiv ℂ W).surjective φ + exact h x + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Annihilator.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Annihilator.lean index 66672592da800dc139ffabff576ff01b24439530..d823dbbab5386e986c4cca5a2943f99a5d73aa47 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Annihilator.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Annihilator.lean @@ -1,40 +1,40 @@ -import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear -import OAI.RepresentationTheory.FoulkesHowe.FoulkesDiagonal - -namespace OAI - -noncomputable section - -universe u - -namespace Problem346 - -/-- The diagonal vanishing criterion forces every canonical Foulkes map to be -surjective. This dual separation argument does not require finite dimension. -/ -theorem IsFoulkesMap.surjective_of_vanishing (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) - (hμ : IsFoulkesMap a b V μ) - (hvan : ∀ T : SymmetricMultilinearForm a b V, - IsSymmetricMultilinearForm a b V T → - (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0) : - Function.Surjective μ := by - apply LinearMap.dualMap_injective_iff.mp - rw [← LinearMap.ker_eq_bot] - apply le_antisymm ?_ bot_le - intro φ hφ - change φ = 0 - rw [LinearMap.mem_ker] at hφ - apply (monomialFunctional_eq_zero_iff a b V φ).mp - apply hvan _ (monomialFunctional_symmetric a b V φ) - intro u - rw [monomialFunctional_apply, ← hμ.map_diagonal a b V μ u] - have h := congrArg (fun L : SymPow b (SymPow a V) →ₗ[ℂ] ℂ => - L (symMonomial b (SymPow a V) (fun j => symMonomial a V (fun _ => u j)))) hφ - exact h - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear +import OAI.RepresentationTheory.FoulkesHowe.FoulkesDiagonal + +namespace OAI + +noncomputable section + +universe u + +namespace Problem346 + +/-- The diagonal vanishing criterion forces every canonical Foulkes map to be +surjective. This dual separation argument does not require finite dimension. -/ +theorem IsFoulkesMap.surjective_of_vanishing (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) + (hμ : IsFoulkesMap a b V μ) + (hvan : ∀ T : SymmetricMultilinearForm a b V, + IsSymmetricMultilinearForm a b V T → + (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0) : + Function.Surjective μ := by + apply LinearMap.dualMap_injective_iff.mp + rw [← LinearMap.ker_eq_bot] + apply le_antisymm ?_ bot_le + intro φ hφ + change φ = 0 + rw [LinearMap.mem_ker] at hφ + apply (monomialFunctional_eq_zero_iff a b V φ).mp + apply hvan _ (monomialFunctional_symmetric a b V φ) + intro u + rw [monomialFunctional_apply, ← hμ.map_diagonal a b V μ u] + have h := congrArg (fun L : SymPow b (SymPow a V) →ₗ[ℂ] ℂ => + L (symMonomial b (SymPow a V) (fun j => symMonomial a V (fun _ => u j)))) hφ + exact h + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BackwardCancellation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BackwardCancellation.lean index 3e8e21d048367f5ed0b01f3c01b6bd22c7490568..354073be8886727d27ae593c72eac8e500155f59 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BackwardCancellation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BackwardCancellation.lean @@ -1,31 +1,31 @@ -import Mathlib - -namespace OAI - -namespace Problem346 - -/-- A finite sequence of zero-reflecting transitions can be cancelled backwards. -/ -theorem eq_zero_of_backward_chain {M : Type*} [Zero M] - (P : ℕ → M) (m : ℕ) - (hstep : ∀ k < m, P (k+1) = 0 → P k = 0) - (hm : P m = 0) : P 0 = 0 := by - exact Nat.decreasingInduction (motive := fun k _ => P k = 0) - (fun k hk => hstep k (by omega)) hm (Nat.zero_le m) - -/-- Scalar factors in derivative-chain identities need not be divided out when -propagating a zero endpoint backwards. Only zero reflection of each derivative -on its current polynomial is required. -/ -theorem eq_zero_of_linear_chain {R M : Type*} [Semiring R] - [AddCommMonoid M] [Module R M] - (P : ℕ → M) (D : ℕ → Module.End R M) (c : ℕ → R) (m : ℕ) - (hchain : ∀ k < m, D k (P k) = c k • P (k+1)) - (hreflect : ∀ k < m, D k (P k) = 0 → P k = 0) - (hm : P m = 0) : P 0 = 0 := by - apply eq_zero_of_backward_chain P m _ hm - intro k hk hz - apply hreflect k hk - rw [hchain k hk, hz, smul_zero] - -end Problem346 - -end OAI +import Mathlib + +namespace OAI + +namespace Problem346 + +/-- A finite sequence of zero-reflecting transitions can be cancelled backwards. -/ +theorem eq_zero_of_backward_chain {M : Type*} [Zero M] + (P : ℕ → M) (m : ℕ) + (hstep : ∀ k < m, P (k+1) = 0 → P k = 0) + (hm : P m = 0) : P 0 = 0 := by + exact Nat.decreasingInduction (motive := fun k _ => P k = 0) + (fun k hk => hstep k (by omega)) hm (Nat.zero_le m) + +/-- Scalar factors in derivative-chain identities need not be divided out when +propagating a zero endpoint backwards. Only zero reflection of each derivative +on its current polynomial is required. -/ +theorem eq_zero_of_linear_chain {R M : Type*} [Semiring R] + [AddCommMonoid M] [Module R M] + (P : ℕ → M) (D : ℕ → Module.End R M) (c : ℕ → R) (m : ℕ) + (hchain : ∀ k < m, D k (P k) = c k • P (k+1)) + (hreflect : ∀ k < m, D k (P k) = 0 → P k = 0) + (hm : P m = 0) : P 0 = 0 := by + apply eq_zero_of_backward_chain P m _ hm + intro k hk hz + apply hreflect k hk + rw [hchain k hk, hz, smul_zero] + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryFactorization.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryFactorization.lean index 3ac67a36281f5ea3d97ddbaa380be0fa0df78554..494ee8b3c4a2f1796632306369e1dcffa1f36f3f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryFactorization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryFactorization.lean @@ -1,80 +1,80 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 - -/-- Binary forms used in the first step of the vanishing argument split into linear factors. -/ -theorem binary_power_factorization {A : Type*} [CommRing A] [Algebra ℂ A] - (r : ℕ) (hr : 0 < r) (x y : A) (c : ℂ) : - ∃ z : Fin r → ℂ, (∏ i : Fin r, (x - z i • y)) = x ^ r + c • y ^ r := by - classical - obtain ⟨α, hα⟩ := IsAlgClosed.exists_pow_nat_eq (-c) hr - let ζ : ℂ := Complex.exp (2 * Real.pi * Complex.I / r) - have hζ : IsPrimitiveRoot ζ r := Complex.isPrimitiveRoot_exp r hr.ne' - have hp : (Polynomial.X ^ r - Polynomial.C (-c) : Polynomial ℂ) = - ∏ i ∈ Finset.range r, (Polynomial.X - Polynomial.C (ζ ^ i * α)) := - X_pow_sub_C_eq_prod hζ hr hα - have hh := congrArg (fun p : Polynomial ℂ => p.homogenize r) hp - have hd : ∀ i ∈ Finset.range r, - (Polynomial.X - Polynomial.C (ζ ^ i * α)).natDegree ≤ 1 := by - intro i hi - rw [Polynomial.natDegree_X_sub_C] - have hprod := Polynomial.homogenize_finsetProd (n := fun _ : ℕ => 1) hd - simp only [Finset.sum_const, Finset.card_range, smul_eq_mul, mul_one] at hprod - rw [hprod] at hh - simp only [Polynomial.homogenize_sub, Polynomial.homogenize_X_pow le_rfl, - Nat.sub_self, pow_zero, mul_one, Polynomial.homogenize_C, - Polynomial.homogenize_X (by decide : (1 : ℕ) ≠ 0), Nat.sub_self, pow_one] at hh - have he := congrArg (MvPolynomial.aeval ![x, y]) hh - simp only [map_sub, map_pow, map_mul, map_prod, MvPolynomial.aeval_X, - Matrix.cons_val_zero, Matrix.cons_val_one, - MvPolynomial.aeval_C] at he - refine ⟨fun i => ζ ^ (i : ℕ) * α, ?_⟩ - change (∏ i : Fin r, (x - (ζ ^ (i : ℕ) * α) • y)) = _ - rw [Fin.prod_univ_eq_prod_range (fun i => x - (ζ ^ i * α) • y)] - simpa only [Algebra.smul_def, map_neg, neg_mul, sub_neg_eq_add, map_mul, map_pow] using he.symm - -/-- In the symmetric algebra, a binary sum of pure powers is a product of vectors. -/ -theorem symMonomialRaw_binary_power (V : Type*) [AddCommGroup V] [Module ℂ V] - (r : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) : - ∃ v : Fin r → V, symMonomialRaw r V v = - (SymmetricAlgebra.ι ℂ V x) ^ r + c • (SymmetricAlgebra.ι ℂ V y) ^ r := by - obtain ⟨z, hz⟩ := binary_power_factorization r hr - (SymmetricAlgebra.ι ℂ V x) (SymmetricAlgebra.ι ℂ V y) c - refine ⟨fun i => x - z i • y, ?_⟩ - simpa only [symMonomialRaw, map_sub, map_smul] using hz - -/-- Multiplying a split binary power by a product remains a product, with the exact degree. -/ -theorem symMonomialRaw_binary_power_mul (V : Type*) [AddCommGroup V] [Module ℂ V] - (r m : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) (u : Fin m → V) : - ∃ v : Fin (r + m) → V, symMonomialRaw (r + m) V v = - ((SymmetricAlgebra.ι ℂ V x) ^ r + c • (SymmetricAlgebra.ι ℂ V y) ^ r) * - symMonomialRaw m V u := by - obtain ⟨w, hw⟩ := symMonomialRaw_binary_power V r hr x y c - refine ⟨Fin.append w u, ?_⟩ - rw [← hw] - simp only [symMonomialRaw, Fin.prod_univ_add, Fin.append_left, Fin.append_right] - -/-- The split binary form is a genuine product in the prescribed symmetric-power subtype. -/ -theorem symMonomial_binary_power_mul (V : Type*) [AddCommGroup V] [Module ℂ V] - (r m : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) (u : Fin m → V) : - ∃ v : Fin (r + m) → V, symMonomial (r + m) V v = - symMonomial (r + m) V (Fin.append (fun _ : Fin r => x) u) + - c • symMonomial (r + m) V (Fin.append (fun _ : Fin r => y) u) := by - obtain ⟨v, hv⟩ := symMonomialRaw_binary_power_mul V r m hr x y c u - refine ⟨v, Subtype.ext ?_⟩ - change symMonomialRaw (r + m) V v = _ - rw [hv] - simp only [symMonomial, Submodule.coe_add, Submodule.coe_smul, symMonomialRaw, - Fin.prod_univ_add, Fin.append_left, Fin.append_right, - Finset.prod_const, Finset.card_univ, Fintype.card_fin, add_mul, smul_mul_assoc] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 + +/-- Binary forms used in the first step of the vanishing argument split into linear factors. -/ +theorem binary_power_factorization {A : Type*} [CommRing A] [Algebra ℂ A] + (r : ℕ) (hr : 0 < r) (x y : A) (c : ℂ) : + ∃ z : Fin r → ℂ, (∏ i : Fin r, (x - z i • y)) = x ^ r + c • y ^ r := by + classical + obtain ⟨α, hα⟩ := IsAlgClosed.exists_pow_nat_eq (-c) hr + let ζ : ℂ := Complex.exp (2 * Real.pi * Complex.I / r) + have hζ : IsPrimitiveRoot ζ r := Complex.isPrimitiveRoot_exp r hr.ne' + have hp : (Polynomial.X ^ r - Polynomial.C (-c) : Polynomial ℂ) = + ∏ i ∈ Finset.range r, (Polynomial.X - Polynomial.C (ζ ^ i * α)) := + X_pow_sub_C_eq_prod hζ hr hα + have hh := congrArg (fun p : Polynomial ℂ => p.homogenize r) hp + have hd : ∀ i ∈ Finset.range r, + (Polynomial.X - Polynomial.C (ζ ^ i * α)).natDegree ≤ 1 := by + intro i hi + rw [Polynomial.natDegree_X_sub_C] + have hprod := Polynomial.homogenize_finsetProd (n := fun _ : ℕ => 1) hd + simp only [Finset.sum_const, Finset.card_range, smul_eq_mul, mul_one] at hprod + rw [hprod] at hh + simp only [Polynomial.homogenize_sub, Polynomial.homogenize_X_pow le_rfl, + Nat.sub_self, pow_zero, mul_one, Polynomial.homogenize_C, + Polynomial.homogenize_X (by decide : (1 : ℕ) ≠ 0), Nat.sub_self, pow_one] at hh + have he := congrArg (MvPolynomial.aeval ![x, y]) hh + simp only [map_sub, map_pow, map_mul, map_prod, MvPolynomial.aeval_X, + Matrix.cons_val_zero, Matrix.cons_val_one, + MvPolynomial.aeval_C] at he + refine ⟨fun i => ζ ^ (i : ℕ) * α, ?_⟩ + change (∏ i : Fin r, (x - (ζ ^ (i : ℕ) * α) • y)) = _ + rw [Fin.prod_univ_eq_prod_range (fun i => x - (ζ ^ i * α) • y)] + simpa only [Algebra.smul_def, map_neg, neg_mul, sub_neg_eq_add, map_mul, map_pow] using he.symm + +/-- In the symmetric algebra, a binary sum of pure powers is a product of vectors. -/ +theorem symMonomialRaw_binary_power (V : Type*) [AddCommGroup V] [Module ℂ V] + (r : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) : + ∃ v : Fin r → V, symMonomialRaw r V v = + (SymmetricAlgebra.ι ℂ V x) ^ r + c • (SymmetricAlgebra.ι ℂ V y) ^ r := by + obtain ⟨z, hz⟩ := binary_power_factorization r hr + (SymmetricAlgebra.ι ℂ V x) (SymmetricAlgebra.ι ℂ V y) c + refine ⟨fun i => x - z i • y, ?_⟩ + simpa only [symMonomialRaw, map_sub, map_smul] using hz + +/-- Multiplying a split binary power by a product remains a product, with the exact degree. -/ +theorem symMonomialRaw_binary_power_mul (V : Type*) [AddCommGroup V] [Module ℂ V] + (r m : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) (u : Fin m → V) : + ∃ v : Fin (r + m) → V, symMonomialRaw (r + m) V v = + ((SymmetricAlgebra.ι ℂ V x) ^ r + c • (SymmetricAlgebra.ι ℂ V y) ^ r) * + symMonomialRaw m V u := by + obtain ⟨w, hw⟩ := symMonomialRaw_binary_power V r hr x y c + refine ⟨Fin.append w u, ?_⟩ + rw [← hw] + simp only [symMonomialRaw, Fin.prod_univ_add, Fin.append_left, Fin.append_right] + +/-- The split binary form is a genuine product in the prescribed symmetric-power subtype. -/ +theorem symMonomial_binary_power_mul (V : Type*) [AddCommGroup V] [Module ℂ V] + (r m : ℕ) (hr : 0 < r) (x y : V) (c : ℂ) (u : Fin m → V) : + ∃ v : Fin (r + m) → V, symMonomial (r + m) V v = + symMonomial (r + m) V (Fin.append (fun _ : Fin r => x) u) + + c • symMonomial (r + m) V (Fin.append (fun _ : Fin r => y) u) := by + obtain ⟨v, hv⟩ := symMonomialRaw_binary_power_mul V r m hr x y c u + refine ⟨v, Subtype.ext ?_⟩ + change symMonomialRaw (r + m) V v = _ + rw [hv] + simp only [symMonomial, Submodule.coe_add, Submodule.coe_smul, symMonomialRaw, + Fin.prod_univ_add, Fin.append_left, Fin.append_right, + Finset.prod_const, Finset.card_univ, Fintype.card_fin, add_mul, smul_mul_assoc] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryVanishing.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryVanishing.lean index f86465ff38cbf48bfa5e79cb4b230a210086acec..b62a3583a16912299ba8bcc52ba6e5a0fbe96c57 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryVanishing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BinaryVanishing.lean @@ -1,36 +1,36 @@ -import OAI.RepresentationTheory.FoulkesHowe.BinaryFactorization -import OAI.RepresentationTheory.FoulkesHowe.DiagonalCoefficient -import OAI.RepresentationTheory.FoulkesHowe.Multiplication - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- The split-pencil consequence of diagonal vanishing, expressed using the -graded multiplication and first-slot convention of the induction. -/ -theorem binary_diagonal_to_mixed_products (r m : ℕ) (hr : 0 < r) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) - (hdiag : ∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) - (x t : V) (y : Fin m → V) : - T (Fin.cons - (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) - (fun _ : Fin r => - symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by - apply symmetric_diagonal_cons_zero T hT - intro c - obtain ⟨v, hv⟩ := symMonomial_binary_power_mul V r m hr x t c y - simp only [symPowMul_symMonomial] - rw [← hv] - exact hdiag v - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.BinaryFactorization +import OAI.RepresentationTheory.FoulkesHowe.DiagonalCoefficient +import OAI.RepresentationTheory.FoulkesHowe.Multiplication + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- The split-pencil consequence of diagonal vanishing, expressed using the +graded multiplication and first-slot convention of the induction. -/ +theorem binary_diagonal_to_mixed_products (r m : ℕ) (hr : 0 < r) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) + (hdiag : ∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) + (x t : V) (y : Fin m → V) : + T (Fin.cons + (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) + (fun _ : Fin r => + symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by + apply symmetric_diagonal_cons_zero T hT + intro c + obtain ⟨v, hv⟩ := symMonomial_binary_power_mul V r m hr x t c y + simp only [symPowMul_symMonomial] + rw [← hv] + exact hdiag v + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockDerivation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockDerivation.lean index ef1960a7c35fd72f2b9acd187190a1861940963a..ffa208d81ae52636b7fb1e0e539649acf9a6bdc4 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockDerivation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockDerivation.lean @@ -1,102 +1,102 @@ -import Mathlib - -namespace OAI - -/-! Coordinate-block derivations used in the differential-shift argument. -/ - -noncomputable section - -namespace Problem346 - -open MvPolynomial -open scoped BigOperators - -variable (R : Type*) [CommRing R] -variable {ι κ : Type*} [DecidableEq ι] - -/-- Move one unit of polynomial degree from block `u` to block `v`. -The other coordinate blocks are spectators. -/ -def blockShift (u v : ι) : - Derivation R (MvPolynomial (ι × κ) R) (MvPolynomial (ι × κ) R) := - MvPolynomial.mkDerivation R (fun k => if k.1 = u then X (v, k.2) else 0) - -@[simp] theorem blockShift_X (u v k : ι) (l : κ) : - blockShift (κ := κ) R u v (X (k, l)) = if k = u then X (v, l) else 0 := - MvPolynomial.mkDerivation_X R _ _ - -/-- The commutator of opposite block shifts is the difference of the two -block Euler operators. This identity needs no finiteness assumption. -/ -theorem blockShift_commutator (u v : ι) : - ⁅blockShift (κ := κ) R v u, blockShift (κ := κ) R u v⁆ = - blockShift (κ := κ) R u u - blockShift (κ := κ) R v v := by - apply MvPolynomial.derivation_ext - rintro ⟨k, l⟩ - simp only [Derivation.commutator_apply, Derivation.sub_apply, blockShift_X] - by_cases huv : u = v - · subst v - simp - · by_cases hu : k = u <;> by_cases hv : k = v <;> - simp_all - -/-- The weight operator raises the weight of the reverse shift by two. -/ -theorem blockShift_weight_commutator (u v : ι) (huv : u ≠ v) : - ⁅blockShift (κ := κ) R u u - blockShift (κ := κ) R v v, blockShift (κ := κ) R v u⁆ = - (2 : R) • blockShift (κ := κ) R v u := by - apply MvPolynomial.derivation_ext - rintro ⟨k, l⟩ - simp only [Derivation.commutator_apply, Derivation.sub_apply, - Derivation.smul_apply, blockShift_X] - by_cases hu : k = u <;> by_cases hv : k = v <;> - simp [hu, hv, huv, Ne.symm huv, two_smul] - -/-- Pointwise version of the opposite-shift commutator. -/ -theorem blockShift_commutator_apply (u v : ι) (f : MvPolynomial (ι × κ) R) : - blockShift (κ := κ) R v u (blockShift (κ := κ) R u v f) - - blockShift (κ := κ) R u v (blockShift (κ := κ) R v u f) = - blockShift (κ := κ) R u u f - blockShift (κ := κ) R v v f := by - have h := congrArg (fun D : Derivation R (MvPolynomial (ι × κ) R) - (MvPolynomial (ι × κ) R) => D f) (blockShift_commutator R u v) - exact h - -/-- Pointwise version of the weight/raising commutator. -/ -theorem blockShift_weight_commutator_apply (u v : ι) (huv : u ≠ v) - (f : MvPolynomial (ι × κ) R) : - (blockShift (κ := κ) R u u - blockShift (κ := κ) R v v) (blockShift (κ := κ) R v u f) - - blockShift (κ := κ) R v u ((blockShift (κ := κ) R u u - blockShift (κ := κ) R v v) f) = - (2 : R) • blockShift (κ := κ) R v u f := by - have h := congrArg (fun D : Derivation R (MvPolynomial (ι × κ) R) - (MvPolynomial (ι × κ) R) => D f) (blockShift_weight_commutator R u v huv) - exact h - -/-- An off-diagonal block shift squares to zero on each coordinate generator. -/ -theorem blockShift_square_X (u v k : ι) (huv : u ≠ v) (l : κ) : - blockShift (κ := κ) R u v (blockShift R u v (X (k, l))) = 0 := by - by_cases h : k = u <;> simp [h, Ne.symm huv] - -/-- With finitely many coordinates, `blockShift` is the usual directional -partial derivative, written as a sum of coordinate derivations. -/ -theorem blockShift_eq_sum [Fintype κ] (u v : ι) : - blockShift (κ := κ) R u v = - ∑ l : κ, (X (v, l) : MvPolynomial (ι × κ) R) • pderiv (u, l) := by - classical - apply MvPolynomial.derivation_ext - rintro ⟨k, m⟩ - rw [blockShift_X] - have heval (ds : κ → Derivation R (MvPolynomial (ι × κ) R) - (MvPolynomial (ι × κ) R)) (f : MvPolynomial (ι × κ) R) : - (∑ l, ds l) f = ∑ l, ds l f := by - simpa only [Derivation.coeFnAddMonoidHom_apply, Finset.sum_apply] using - congrFun (map_sum Derivation.coeFnAddMonoidHom ds Finset.univ) f - rw [heval] - simp only [Derivation.smul_apply, smul_eq_mul, pderiv_X, Pi.single_apply, - Prod.mk.injEq] - by_cases h : k = u - · subst k - simp - · simp [h] - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +/-! Coordinate-block derivations used in the differential-shift argument. -/ + +noncomputable section + +namespace Problem346 + +open MvPolynomial +open scoped BigOperators + +variable (R : Type*) [CommRing R] +variable {ι κ : Type*} [DecidableEq ι] + +/-- Move one unit of polynomial degree from block `u` to block `v`. +The other coordinate blocks are spectators. -/ +def blockShift (u v : ι) : + Derivation R (MvPolynomial (ι × κ) R) (MvPolynomial (ι × κ) R) := + MvPolynomial.mkDerivation R (fun k => if k.1 = u then X (v, k.2) else 0) + +@[simp] theorem blockShift_X (u v k : ι) (l : κ) : + blockShift (κ := κ) R u v (X (k, l)) = if k = u then X (v, l) else 0 := + MvPolynomial.mkDerivation_X R _ _ + +/-- The commutator of opposite block shifts is the difference of the two +block Euler operators. This identity needs no finiteness assumption. -/ +theorem blockShift_commutator (u v : ι) : + ⁅blockShift (κ := κ) R v u, blockShift (κ := κ) R u v⁆ = + blockShift (κ := κ) R u u - blockShift (κ := κ) R v v := by + apply MvPolynomial.derivation_ext + rintro ⟨k, l⟩ + simp only [Derivation.commutator_apply, Derivation.sub_apply, blockShift_X] + by_cases huv : u = v + · subst v + simp + · by_cases hu : k = u <;> by_cases hv : k = v <;> + simp_all + +/-- The weight operator raises the weight of the reverse shift by two. -/ +theorem blockShift_weight_commutator (u v : ι) (huv : u ≠ v) : + ⁅blockShift (κ := κ) R u u - blockShift (κ := κ) R v v, blockShift (κ := κ) R v u⁆ = + (2 : R) • blockShift (κ := κ) R v u := by + apply MvPolynomial.derivation_ext + rintro ⟨k, l⟩ + simp only [Derivation.commutator_apply, Derivation.sub_apply, + Derivation.smul_apply, blockShift_X] + by_cases hu : k = u <;> by_cases hv : k = v <;> + simp [hu, hv, huv, Ne.symm huv, two_smul] + +/-- Pointwise version of the opposite-shift commutator. -/ +theorem blockShift_commutator_apply (u v : ι) (f : MvPolynomial (ι × κ) R) : + blockShift (κ := κ) R v u (blockShift (κ := κ) R u v f) - + blockShift (κ := κ) R u v (blockShift (κ := κ) R v u f) = + blockShift (κ := κ) R u u f - blockShift (κ := κ) R v v f := by + have h := congrArg (fun D : Derivation R (MvPolynomial (ι × κ) R) + (MvPolynomial (ι × κ) R) => D f) (blockShift_commutator R u v) + exact h + +/-- Pointwise version of the weight/raising commutator. -/ +theorem blockShift_weight_commutator_apply (u v : ι) (huv : u ≠ v) + (f : MvPolynomial (ι × κ) R) : + (blockShift (κ := κ) R u u - blockShift (κ := κ) R v v) (blockShift (κ := κ) R v u f) - + blockShift (κ := κ) R v u ((blockShift (κ := κ) R u u - blockShift (κ := κ) R v v) f) = + (2 : R) • blockShift (κ := κ) R v u f := by + have h := congrArg (fun D : Derivation R (MvPolynomial (ι × κ) R) + (MvPolynomial (ι × κ) R) => D f) (blockShift_weight_commutator R u v huv) + exact h + +/-- An off-diagonal block shift squares to zero on each coordinate generator. -/ +theorem blockShift_square_X (u v k : ι) (huv : u ≠ v) (l : κ) : + blockShift (κ := κ) R u v (blockShift R u v (X (k, l))) = 0 := by + by_cases h : k = u <;> simp [h, Ne.symm huv] + +/-- With finitely many coordinates, `blockShift` is the usual directional +partial derivative, written as a sum of coordinate derivations. -/ +theorem blockShift_eq_sum [Fintype κ] (u v : ι) : + blockShift (κ := κ) R u v = + ∑ l : κ, (X (v, l) : MvPolynomial (ι × κ) R) • pderiv (u, l) := by + classical + apply MvPolynomial.derivation_ext + rintro ⟨k, m⟩ + rw [blockShift_X] + have heval (ds : κ → Derivation R (MvPolynomial (ι × κ) R) + (MvPolynomial (ι × κ) R)) (f : MvPolynomial (ι × κ) R) : + (∑ l, ds l) f = ∑ l, ds l f := by + simpa only [Derivation.coeFnAddMonoidHom_apply, Finset.sum_apply] using + congrFun (map_sum Derivation.coeFnAddMonoidHom ds Finset.univ) f + rw [heval] + simp only [Derivation.smul_apply, smul_eq_mul, pderiv_X, Pi.single_apply, + Prod.mk.injEq] + by_cases h : k = u + · subst k + simp + · simp [h] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockInjectivity.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockInjectivity.lean index a04017f990477ce7fb396d051a3c214cae626bed..f348516a1b9a3e08a355c6d6e78396dc08de0b0b 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockInjectivity.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockInjectivity.lean @@ -1,58 +1,58 @@ -import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity -import OAI.RepresentationTheory.FoulkesHowe.PolynomialShift -import OAI.RepresentationTheory.FoulkesHowe.BlockWeight - -namespace OAI - -noncomputable section - -namespace Problem346 -namespace PolynomialShift - -open MvPolynomial PolynomialWeights - -variable {B I : Type*} [Fintype B] [Fintype I] [DecidableEq B] - -/-- A polynomial block shift is injective in strictly positive source-minus-destination -weight. All other variable blocks are arbitrary spectators. -/ -theorem eq_zero_of_shift_eq_zero (src dst : B) (hsd : src ≠ dst) - {f : MvPolynomial (B × I) ℂ} {p q : ℕ} (hpq : q < p) - (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) - (hDf : shift src dst f = 0) : f = 0 := by - refine derivation_eq_zero_of_positive_weight - (derivation src dst) (derivation dst src) - (derivation src src - derivation dst dst) - (commutator src dst hsd) (weight_commutator src dst hsd) ?_ - f p q hpq ?_ hDf - · rintro ⟨b, i⟩ - by_cases hb : b = dst - · subst b - simp [hsd] - · simp [hb] - · apply block_difference_eigenvalue src dst _ _ _ _ hp hq - · intro b i - by_cases hb : b = src - · subst b; simp - · simp [hb] - · intro b i - by_cases hb : b = dst - · subst b; simp - · simp [hb] - -/-- Injectivity on the intersection of two specified block-homogeneous pieces. -/ -theorem shift_injOn (src dst : B) (hsd : src ≠ dst) (p q : ℕ) (hpq : q < p) : - Set.InjOn (shift (K := ℂ) (I := I) src dst) - {f | IsBlockHomogeneous src f p ∧ IsBlockHomogeneous dst f q} := by - intro f hf g hg hfg - apply sub_eq_zero.mp - apply eq_zero_of_shift_eq_zero src dst hsd hpq - · exact (weightedHomogeneousSubmodule ℂ (blockWeight src) p).sub_mem hf.1 hg.1 - · exact (weightedHomogeneousSubmodule ℂ (blockWeight dst) q).sub_mem hf.2 hg.2 - · rw [map_sub, hfg, sub_self] - -end PolynomialShift -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity +import OAI.RepresentationTheory.FoulkesHowe.PolynomialShift +import OAI.RepresentationTheory.FoulkesHowe.BlockWeight + +namespace OAI + +noncomputable section + +namespace Problem346 +namespace PolynomialShift + +open MvPolynomial PolynomialWeights + +variable {B I : Type*} [Fintype B] [Fintype I] [DecidableEq B] + +/-- A polynomial block shift is injective in strictly positive source-minus-destination +weight. All other variable blocks are arbitrary spectators. -/ +theorem eq_zero_of_shift_eq_zero (src dst : B) (hsd : src ≠ dst) + {f : MvPolynomial (B × I) ℂ} {p q : ℕ} (hpq : q < p) + (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) + (hDf : shift src dst f = 0) : f = 0 := by + refine derivation_eq_zero_of_positive_weight + (derivation src dst) (derivation dst src) + (derivation src src - derivation dst dst) + (commutator src dst hsd) (weight_commutator src dst hsd) ?_ + f p q hpq ?_ hDf + · rintro ⟨b, i⟩ + by_cases hb : b = dst + · subst b + simp [hsd] + · simp [hb] + · apply block_difference_eigenvalue src dst _ _ _ _ hp hq + · intro b i + by_cases hb : b = src + · subst b; simp + · simp [hb] + · intro b i + by_cases hb : b = dst + · subst b; simp + · simp [hb] + +/-- Injectivity on the intersection of two specified block-homogeneous pieces. -/ +theorem shift_injOn (src dst : B) (hsd : src ≠ dst) (p q : ℕ) (hpq : q < p) : + Set.InjOn (shift (K := ℂ) (I := I) src dst) + {f | IsBlockHomogeneous src f p ∧ IsBlockHomogeneous dst f q} := by + intro f hf g hg hfg + apply sub_eq_zero.mp + apply eq_zero_of_shift_eq_zero src dst hsd hpq + · exact (weightedHomogeneousSubmodule ℂ (blockWeight src) p).sub_mem hf.1 hg.1 + · exact (weightedHomogeneousSubmodule ℂ (blockWeight dst) q).sub_mem hf.2 hg.2 + · rw [map_sub, hfg, sub_self] + +end PolynomialShift +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockWeight.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockWeight.lean index 673495439c60607f91a7d1c5f6fb89690ba59e64..7c6138151aba05b012f6e017fe8573860def7cd4 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/BlockWeight.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/BlockWeight.lean @@ -1,169 +1,169 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 -namespace PolynomialWeights - -open MvPolynomial - -variable {R σ : Type*} [CommSemiring R] [Fintype σ] - -/-- The Euler derivation associated with natural-number weights. -/ -def weightedEuler (w : σ → ℕ) : - Derivation R (MvPolynomial σ R) (MvPolynomial σ R) := - ∑ i : σ, (w i) • ((X i : MvPolynomial σ R) • pderiv i) - -@[simp] theorem weightedEuler_apply (w : σ → ℕ) (f : MvPolynomial σ R) : - weightedEuler w f = ∑ i : σ, w i • (X i * pderiv i f) := by - classical - unfold weightedEuler - induction (Finset.univ : Finset σ) using Finset.induction_on with - | empty => simp - | @insert a s ha ih => simp [Finset.sum_insert ha, Derivation.smul_apply, ih, smul_eq_mul] - -@[simp] theorem weightedEuler_X (w : σ → ℕ) (i : σ) : - weightedEuler (R := R) w (X i) = w i • X i := by - classical - simp [weightedEuler_apply, Pi.single_apply] - -/-- Euler's identity, expressed using a bundled derivation. -/ -theorem weightedEuler_of_homogeneous (w : σ → ℕ) {n : ℕ} - {f : MvPolynomial σ R} (hf : f.IsWeightedHomogeneous w n) : - weightedEuler w f = n • f := by - rw [weightedEuler_apply] - exact hf.sum_weight_X_mul_pderiv - -/-- Any derivation with the prescribed diagonal action on generators is Euler. -/ -theorem derivation_eq_weightedEuler (w : σ → ℕ) - (N : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) - (hN : ∀ i, N (X i) = w i • X i) : N = weightedEuler w := by - apply MvPolynomial.derivation_ext - intro i - rw [hN, weightedEuler_X] - -/-- A homogeneous polynomial is an eigenvector for its weighted Euler derivation. -/ -theorem derivation_homogeneous_eigenvalue (w : σ → ℕ) - (N : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) - (hN : ∀ i, N (X i) = w i • X i) - {n : ℕ} {f : MvPolynomial σ R} (hf : f.IsWeightedHomogeneous w n) : - N f = n • f := by - rw [derivation_eq_weightedEuler w N hN] - exact weightedEuler_of_homogeneous w hf - -section Blocks - -variable {β ι : Type*} [Fintype β] [Fintype ι] [DecidableEq β] - -/-- Weight one on one coordinate block, and zero on all spectator blocks. -/ -def blockWeight (u : β) (ki : β × ι) : ℕ := if ki.1 = u then 1 else 0 - -/-- A polynomial is homogeneous of the specified degree in one block. -/ -def IsBlockHomogeneous (u : β) (f : MvPolynomial (β × ι) R) (n : ℕ) : Prop := - f.IsWeightedHomogeneous (blockWeight u) n - -omit [Fintype β] [Fintype ι] in -@[simp] theorem blockWeight_apply (u k : β) (i : ι) : - blockWeight u (k, i) = if k = u then 1 else 0 := rfl - -theorem block_euler_eigenvalue (u : β) - (N : Derivation R (MvPolynomial (β × ι) R) (MvPolynomial (β × ι) R)) - (hN : ∀ k i, N (X (k, i)) = if k = u then X (k, i) else 0) - {n : ℕ} {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) : - N f = n • f := by - apply derivation_homogeneous_eigenvalue (blockWeight u) N _ hf - rintro ⟨k, i⟩ - simp only [hN, blockWeight_apply] - split_ifs <;> simp - -/-- The difference of block counting operators has the difference of the block degrees -as eigenvalue. This is the weight used by the positive-weight shift lemma. -/ -theorem block_difference_eigenvalue (u v : β) - (Nu Nv : Derivation ℂ (MvPolynomial (β × ι) ℂ) (MvPolynomial (β × ι) ℂ)) - (hu : ∀ k i, Nu (X (k, i)) = if k = u then X (k, i) else 0) - (hv : ∀ k i, Nv (X (k, i)) = if k = v then X (k, i) else 0) - {p q : ℕ} {f : MvPolynomial (β × ι) ℂ} - (hp : IsBlockHomogeneous u f p) (hq : IsBlockHomogeneous v f q) : - (Nu - Nv) f = ((p : ℂ) - (q : ℂ)) • f := by - change Nu f - Nv f = _ - rw [block_euler_eigenvalue u Nu hu hp, block_euler_eigenvalue v Nv hv hq] - rw [sub_smul] - simp only [Nat.cast_smul_eq_nsmul] - -theorem block_difference_nat_eigenvalue (u v : β) - (Nu Nv : Derivation ℂ (MvPolynomial (β × ι) ℂ) (MvPolynomial (β × ι) ℂ)) - (hu : ∀ k i, Nu (X (k, i)) = if k = u then X (k, i) else 0) - (hv : ∀ k i, Nv (X (k, i)) = if k = v then X (k, i) else 0) - {p q : ℕ} (hpq : q ≤ p) {f : MvPolynomial (β × ι) ℂ} - (hp : IsBlockHomogeneous u f p) (hq : IsBlockHomogeneous v f q) : - (Nu - Nv) f = ((p - q : ℕ) : ℂ) • f := by - rw [Nat.cast_sub hpq] - exact block_difference_eigenvalue u v Nu Nv hu hv hp hq - -omit [Fintype β] [Fintype ι] in -/-- Differentiating in a block lowers its degree by one, provided that degree is positive. -/ -theorem block_pderiv_source {u : β} {n : ℕ} {f : MvPolynomial (β × ι) R} - (hf : IsBlockHomogeneous u f n) (hn : 0 < n) (i : ι) : - IsBlockHomogeneous u (pderiv (u, i) f) (n - 1) := by - apply IsWeightedHomogeneous.pderiv hf - simp only [blockWeight_apply] - exact Nat.sub_add_cancel hn - -omit [Fintype β] [Fintype ι] in -/-- Differentiating in another block leaves the indicated block degree unchanged. -/ -theorem block_pderiv_other {u k : β} (hku : k ≠ u) {n : ℕ} - {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) (i : ι) : - IsBlockHomogeneous u (pderiv (k, i) f) n := by - apply IsWeightedHomogeneous.pderiv hf - simp [blockWeight_apply, hku] - -omit [Fintype β] in -/-- A directional shift lowers its source block degree by one. -/ -theorem block_shift_degree_source {u v : β} (huv : u ≠ v) {n : ℕ} - {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) (hn : 0 < n) : - IsBlockHomogeneous u (∑ i : ι, X (v, i) * pderiv (u, i) f) (n - 1) := by - apply (weightedHomogeneousSubmodule R (blockWeight u) (n - 1)).sum_mem - intro i hi - have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous - (blockWeight u) 0 := by - simpa [blockWeight_apply, Ne.symm huv] using - (isWeightedHomogeneous_X (R := R) (blockWeight u) (v, i)) - simpa using hx.mul (block_pderiv_source hf hn i) - -omit [Fintype β] in -/-- A directional shift raises its destination block degree by one. -/ -theorem block_shift_degree_destination {u v : β} (huv : u ≠ v) {n : ℕ} - {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous v f n) : - IsBlockHomogeneous v (∑ i : ι, X (v, i) * pderiv (u, i) f) (n + 1) := by - apply (weightedHomogeneousSubmodule R (blockWeight v) (n + 1)).sum_mem - intro i hi - have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous - (blockWeight v) 1 := by - simpa [blockWeight_apply] using - (isWeightedHomogeneous_X (R := R) (blockWeight v) (v, i)) - simpa [Nat.add_comm] using hx.mul (block_pderiv_other huv hf i) - -omit [Fintype β] in -/-- A directional shift leaves every spectator block degree unchanged. -/ -theorem block_shift_degree_spectator {u v k : β} (huk : u ≠ k) (hvk : v ≠ k) - {n : ℕ} {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous k f n) : - IsBlockHomogeneous k (∑ i : ι, X (v, i) * pderiv (u, i) f) n := by - apply (weightedHomogeneousSubmodule R (blockWeight k) n).sum_mem - intro i hi - have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous - (blockWeight k) 0 := by - simpa [blockWeight_apply, hvk] using - (isWeightedHomogeneous_X (R := R) (blockWeight k) (v, i)) - simpa using hx.mul (block_pderiv_other huk hf i) - -end Blocks - -end PolynomialWeights -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 +namespace PolynomialWeights + +open MvPolynomial + +variable {R σ : Type*} [CommSemiring R] [Fintype σ] + +/-- The Euler derivation associated with natural-number weights. -/ +def weightedEuler (w : σ → ℕ) : + Derivation R (MvPolynomial σ R) (MvPolynomial σ R) := + ∑ i : σ, (w i) • ((X i : MvPolynomial σ R) • pderiv i) + +@[simp] theorem weightedEuler_apply (w : σ → ℕ) (f : MvPolynomial σ R) : + weightedEuler w f = ∑ i : σ, w i • (X i * pderiv i f) := by + classical + unfold weightedEuler + induction (Finset.univ : Finset σ) using Finset.induction_on with + | empty => simp + | @insert a s ha ih => simp [Finset.sum_insert ha, Derivation.smul_apply, ih, smul_eq_mul] + +@[simp] theorem weightedEuler_X (w : σ → ℕ) (i : σ) : + weightedEuler (R := R) w (X i) = w i • X i := by + classical + simp [weightedEuler_apply, Pi.single_apply] + +/-- Euler's identity, expressed using a bundled derivation. -/ +theorem weightedEuler_of_homogeneous (w : σ → ℕ) {n : ℕ} + {f : MvPolynomial σ R} (hf : f.IsWeightedHomogeneous w n) : + weightedEuler w f = n • f := by + rw [weightedEuler_apply] + exact hf.sum_weight_X_mul_pderiv + +/-- Any derivation with the prescribed diagonal action on generators is Euler. -/ +theorem derivation_eq_weightedEuler (w : σ → ℕ) + (N : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) + (hN : ∀ i, N (X i) = w i • X i) : N = weightedEuler w := by + apply MvPolynomial.derivation_ext + intro i + rw [hN, weightedEuler_X] + +/-- A homogeneous polynomial is an eigenvector for its weighted Euler derivation. -/ +theorem derivation_homogeneous_eigenvalue (w : σ → ℕ) + (N : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) + (hN : ∀ i, N (X i) = w i • X i) + {n : ℕ} {f : MvPolynomial σ R} (hf : f.IsWeightedHomogeneous w n) : + N f = n • f := by + rw [derivation_eq_weightedEuler w N hN] + exact weightedEuler_of_homogeneous w hf + +section Blocks + +variable {β ι : Type*} [Fintype β] [Fintype ι] [DecidableEq β] + +/-- Weight one on one coordinate block, and zero on all spectator blocks. -/ +def blockWeight (u : β) (ki : β × ι) : ℕ := if ki.1 = u then 1 else 0 + +/-- A polynomial is homogeneous of the specified degree in one block. -/ +def IsBlockHomogeneous (u : β) (f : MvPolynomial (β × ι) R) (n : ℕ) : Prop := + f.IsWeightedHomogeneous (blockWeight u) n + +omit [Fintype β] [Fintype ι] in +@[simp] theorem blockWeight_apply (u k : β) (i : ι) : + blockWeight u (k, i) = if k = u then 1 else 0 := rfl + +theorem block_euler_eigenvalue (u : β) + (N : Derivation R (MvPolynomial (β × ι) R) (MvPolynomial (β × ι) R)) + (hN : ∀ k i, N (X (k, i)) = if k = u then X (k, i) else 0) + {n : ℕ} {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) : + N f = n • f := by + apply derivation_homogeneous_eigenvalue (blockWeight u) N _ hf + rintro ⟨k, i⟩ + simp only [hN, blockWeight_apply] + split_ifs <;> simp + +/-- The difference of block counting operators has the difference of the block degrees +as eigenvalue. This is the weight used by the positive-weight shift lemma. -/ +theorem block_difference_eigenvalue (u v : β) + (Nu Nv : Derivation ℂ (MvPolynomial (β × ι) ℂ) (MvPolynomial (β × ι) ℂ)) + (hu : ∀ k i, Nu (X (k, i)) = if k = u then X (k, i) else 0) + (hv : ∀ k i, Nv (X (k, i)) = if k = v then X (k, i) else 0) + {p q : ℕ} {f : MvPolynomial (β × ι) ℂ} + (hp : IsBlockHomogeneous u f p) (hq : IsBlockHomogeneous v f q) : + (Nu - Nv) f = ((p : ℂ) - (q : ℂ)) • f := by + change Nu f - Nv f = _ + rw [block_euler_eigenvalue u Nu hu hp, block_euler_eigenvalue v Nv hv hq] + rw [sub_smul] + simp only [Nat.cast_smul_eq_nsmul] + +theorem block_difference_nat_eigenvalue (u v : β) + (Nu Nv : Derivation ℂ (MvPolynomial (β × ι) ℂ) (MvPolynomial (β × ι) ℂ)) + (hu : ∀ k i, Nu (X (k, i)) = if k = u then X (k, i) else 0) + (hv : ∀ k i, Nv (X (k, i)) = if k = v then X (k, i) else 0) + {p q : ℕ} (hpq : q ≤ p) {f : MvPolynomial (β × ι) ℂ} + (hp : IsBlockHomogeneous u f p) (hq : IsBlockHomogeneous v f q) : + (Nu - Nv) f = ((p - q : ℕ) : ℂ) • f := by + rw [Nat.cast_sub hpq] + exact block_difference_eigenvalue u v Nu Nv hu hv hp hq + +omit [Fintype β] [Fintype ι] in +/-- Differentiating in a block lowers its degree by one, provided that degree is positive. -/ +theorem block_pderiv_source {u : β} {n : ℕ} {f : MvPolynomial (β × ι) R} + (hf : IsBlockHomogeneous u f n) (hn : 0 < n) (i : ι) : + IsBlockHomogeneous u (pderiv (u, i) f) (n - 1) := by + apply IsWeightedHomogeneous.pderiv hf + simp only [blockWeight_apply] + exact Nat.sub_add_cancel hn + +omit [Fintype β] [Fintype ι] in +/-- Differentiating in another block leaves the indicated block degree unchanged. -/ +theorem block_pderiv_other {u k : β} (hku : k ≠ u) {n : ℕ} + {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) (i : ι) : + IsBlockHomogeneous u (pderiv (k, i) f) n := by + apply IsWeightedHomogeneous.pderiv hf + simp [blockWeight_apply, hku] + +omit [Fintype β] in +/-- A directional shift lowers its source block degree by one. -/ +theorem block_shift_degree_source {u v : β} (huv : u ≠ v) {n : ℕ} + {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous u f n) (hn : 0 < n) : + IsBlockHomogeneous u (∑ i : ι, X (v, i) * pderiv (u, i) f) (n - 1) := by + apply (weightedHomogeneousSubmodule R (blockWeight u) (n - 1)).sum_mem + intro i hi + have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous + (blockWeight u) 0 := by + simpa [blockWeight_apply, Ne.symm huv] using + (isWeightedHomogeneous_X (R := R) (blockWeight u) (v, i)) + simpa using hx.mul (block_pderiv_source hf hn i) + +omit [Fintype β] in +/-- A directional shift raises its destination block degree by one. -/ +theorem block_shift_degree_destination {u v : β} (huv : u ≠ v) {n : ℕ} + {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous v f n) : + IsBlockHomogeneous v (∑ i : ι, X (v, i) * pderiv (u, i) f) (n + 1) := by + apply (weightedHomogeneousSubmodule R (blockWeight v) (n + 1)).sum_mem + intro i hi + have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous + (blockWeight v) 1 := by + simpa [blockWeight_apply] using + (isWeightedHomogeneous_X (R := R) (blockWeight v) (v, i)) + simpa [Nat.add_comm] using hx.mul (block_pderiv_other huv hf i) + +omit [Fintype β] in +/-- A directional shift leaves every spectator block degree unchanged. -/ +theorem block_shift_degree_spectator {u v k : β} (huk : u ≠ k) (hvk : v ≠ k) + {n : ℕ} {f : MvPolynomial (β × ι) R} (hf : IsBlockHomogeneous k f n) : + IsBlockHomogeneous k (∑ i : ι, X (v, i) * pderiv (u, i) f) n := by + apply (weightedHomogeneousSubmodule R (blockWeight k) n).sum_mem + intro i hi + have hx : (X (v, i) : MvPolynomial (β × ι) R).IsWeightedHomogeneous + (blockWeight k) 0 := by + simpa [blockWeight_apply, hvk] using + (isWeightedHomogeneous_X (R := R) (blockWeight k) (v, i)) + simpa using hx.mul (block_pderiv_other huk hf i) + +end Blocks + +end PolynomialWeights +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/CanonicalMap.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/CanonicalMap.lean index 26deb0de1138b7c8e08c67f368b05d91714b36c8..b46bddd45d438c70e90ce02257f63d7b0200b9b9 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/CanonicalMap.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/CanonicalMap.lean @@ -1,82 +1,82 @@ -import OAI.RepresentationTheory.FoulkesHowe.GeneratorLift -import OAI.RepresentationTheory.FoulkesHowe.FoulkesMultilinear -import OAI.RepresentationTheory.FoulkesHowe.FoulkesSymmetries - -namespace OAI - -noncomputable section -namespace Problem346 - -private def rowIndexEquiv {I J : Type*} (i : I) : - {p : I × J // p.1 = i} ≃ J where - toFun p := p.1.2 - invFun j := ⟨(i, j), rfl⟩ - left_inv := by - rintro ⟨⟨i', j⟩, h⟩ - simp only at h - subst i' - rfl - right_inv _ := rfl - -/-- Hold all but a single input row of the Foulkes formula fixed. -/ -def foulkesRowFormSpanning (a b : ℕ) (V : Type*) [AddCommGroup V] [Module ℂ V] - (v : Fin b → Fin a → V) (j : Fin b) : - MultilinearMap ℂ (fun _ : Fin a => V) (SymPow a (SymPow b V)) := by - classical - exact ((foulkesMultilinear a b V).domDomRestrict - (fun p : Fin b × Fin a => p.1 = j) (fun p => v p.1.1 p.1.2)).domDomCongr - (rowIndexEquiv j) - -@[simp] theorem foulkesRowFormSpanning_apply (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) (j : Fin b) - (u : Fin a → V) : - foulkesRowFormSpanning a b V v j u = - foulkesFormula a b V (Function.update v j u) := by - classical - change foulkesMultilinear a b V - (fun p => if h : p.1 = j then u p.2 else v p.1 p.2) = _ - rw [foulkesMultilinear_apply] - congr 1 - funext k i - by_cases h : k = j - · subst k - simp - · simp [h] - -theorem foulkesRowFormSpanning_symmetric (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) (j : Fin b) - (σ : Equiv.Perm (Fin a)) (u : Fin a → V) : - foulkesRowFormSpanning a b V v j (fun i => u (σ i)) = - foulkesRowFormSpanning a b V v j u := by - classical - rw [foulkesRowFormSpanning_apply, foulkesRowFormSpanning_apply] - have h := foulkesFormula_inner_permute a b V (Function.update v j u) - (Function.update (fun _ => Equiv.refl (Fin a)) j σ) - convert h using 1 - congr 1 - funext k i - by_cases hkj : k = j - · subst k - simp - · simp [Function.update_of_ne hkj] - -/-- The specified canonical formula defines a linear map in every bidegree. -/ -theorem exists_foulkesMap_from_spanning (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] : - ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), - IsFoulkesMap a b V μ := by - classical - apply exists_symPow_lift_on_spanning (symMonomial a V) (span_symMonomial a V) - (foulkesFormula a b V) - · intro v j - obtain ⟨L, hL⟩ := exists_symPow_lift (foulkesRowFormSpanning a b V v j) - (foulkesRowFormSpanning_symmetric a b V v j) - exact ⟨L, fun u => (hL u).trans (foulkesRowFormSpanning_apply a b V v j u)⟩ - · intro σ v - exact foulkesFormula_outer_permute a b V v σ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.GeneratorLift +import OAI.RepresentationTheory.FoulkesHowe.FoulkesMultilinear +import OAI.RepresentationTheory.FoulkesHowe.FoulkesSymmetries + +namespace OAI + +noncomputable section +namespace Problem346 + +private def rowIndexEquiv {I J : Type*} (i : I) : + {p : I × J // p.1 = i} ≃ J where + toFun p := p.1.2 + invFun j := ⟨(i, j), rfl⟩ + left_inv := by + rintro ⟨⟨i', j⟩, h⟩ + simp only at h + subst i' + rfl + right_inv _ := rfl + +/-- Hold all but a single input row of the Foulkes formula fixed. -/ +def foulkesRowFormSpanning (a b : ℕ) (V : Type*) [AddCommGroup V] [Module ℂ V] + (v : Fin b → Fin a → V) (j : Fin b) : + MultilinearMap ℂ (fun _ : Fin a => V) (SymPow a (SymPow b V)) := by + classical + exact ((foulkesMultilinear a b V).domDomRestrict + (fun p : Fin b × Fin a => p.1 = j) (fun p => v p.1.1 p.1.2)).domDomCongr + (rowIndexEquiv j) + +@[simp] theorem foulkesRowFormSpanning_apply (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) (j : Fin b) + (u : Fin a → V) : + foulkesRowFormSpanning a b V v j u = + foulkesFormula a b V (Function.update v j u) := by + classical + change foulkesMultilinear a b V + (fun p => if h : p.1 = j then u p.2 else v p.1 p.2) = _ + rw [foulkesMultilinear_apply] + congr 1 + funext k i + by_cases h : k = j + · subst k + simp + · simp [h] + +theorem foulkesRowFormSpanning_symmetric (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) (j : Fin b) + (σ : Equiv.Perm (Fin a)) (u : Fin a → V) : + foulkesRowFormSpanning a b V v j (fun i => u (σ i)) = + foulkesRowFormSpanning a b V v j u := by + classical + rw [foulkesRowFormSpanning_apply, foulkesRowFormSpanning_apply] + have h := foulkesFormula_inner_permute a b V (Function.update v j u) + (Function.update (fun _ => Equiv.refl (Fin a)) j σ) + convert h using 1 + congr 1 + funext k i + by_cases hkj : k = j + · subst k + simp + · simp [Function.update_of_ne hkj] + +/-- The specified canonical formula defines a linear map in every bidegree. -/ +theorem exists_foulkesMap_from_spanning (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] : + ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), + IsFoulkesMap a b V μ := by + classical + apply exists_symPow_lift_on_spanning (symMonomial a V) (span_symMonomial a V) + (foulkesFormula a b V) + · intro v j + obtain ⟨L, hL⟩ := exists_symPow_lift (foulkesRowFormSpanning a b V v j) + (foulkesRowFormSpanning_symmetric a b V v j) + exact ⟨L, fun u => (hL u).trans (foulkesRowFormSpanning_apply a b V v j u)⟩ + · intro σ v + exact foulkesFormula_outer_permute a b V v σ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DegreeOne.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DegreeOne.lean index a8ae6889954f2b144b7e650818026cca8b632828..25ba9aa3885f5f6e9e72ae587bc05d25881342f8 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DegreeOne.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DegreeOne.lean @@ -1,79 +1,79 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -universe u -namespace Problem346 - -variable (V : Type u) [AddCommGroup V] [Module ℂ V] - -lemma symmetricAlgebra_ι_injective : - Function.Injective (SymmetricAlgebra.ι ℂ V) := by - let : Module ℂᵐᵒᵖ V := Module.compHom _ ((RingHom.id ℂ).fromOpposite mul_comm) - have : IsCentralScalar ℂ V := ⟨fun _ _ => rfl⟩ - intro x y h - have h' := congrArg (SymmetricAlgebra.lift (TrivSqZeroExt.inrHom ℂ V)) h - apply TrivSqZeroExt.inr_injective (R := ℂ) - simpa using h' - -@[simp] lemma symMonomialRaw_one (v : Fin 1 → V) : - symMonomialRaw 1 V v = SymmetricAlgebra.ι ℂ V (v 0) := by - simp [symMonomialRaw] - -lemma symPowSubmodule_one : - symPowSubmodule 1 V = LinearMap.range (SymmetricAlgebra.ι ℂ V) := by - have h : Set.range (symMonomialRaw 1 V) = - Set.range (SymmetricAlgebra.ι ℂ V) := by - ext x - constructor - · rintro ⟨v, rfl⟩ - exact ⟨v 0, (symMonomialRaw_one V v).symm⟩ - · rintro ⟨v, rfl⟩ - exact ⟨fun _ => v, symMonomialRaw_one V (fun _ => v)⟩ - rw [symPowSubmodule, h] - exact Submodule.span_eq (LinearMap.range (SymmetricAlgebra.ι ℂ V)) - -/-- The canonical inclusion of a vector into the degree-one symmetric power. -/ -def symPowOneIntro : V →ₗ[ℂ] SymPow 1 V := - (SymmetricAlgebra.ι ℂ V).codRestrict (symPowSubmodule 1 V) (by - intro v - rw [symPowSubmodule_one] - exact ⟨v, rfl⟩) - -@[simp] lemma symPowOneIntro_coe (v : V) : - (symPowOneIntro V v : SymmetricAlgebra ℂ V) = SymmetricAlgebra.ι ℂ V v := rfl - -lemma symPowOneIntro_bijective : Function.Bijective (symPowOneIntro V) := by - constructor - · intro x y h - apply symmetricAlgebra_ι_injective V - exact congrArg Subtype.val h - · intro x - have hx := x.property - have hx' : (x : SymmetricAlgebra ℂ V) ∈ LinearMap.range (SymmetricAlgebra.ι ℂ V) := by - simpa only [symPowSubmodule_one] using hx - rcases hx' with ⟨v, hv⟩ - exact ⟨v, Subtype.ext hv⟩ - -/-- The degree-one symmetric power is canonically the original vector space. -/ -def symPowOneEquiv : SymPow 1 V ≃ₗ[ℂ] V := - (LinearEquiv.ofBijective (symPowOneIntro V) (symPowOneIntro_bijective V)).symm - -@[simp] lemma symPowOneEquiv_symm_apply (v : V) : - (symPowOneEquiv V).symm v = symMonomial 1 V (fun _ => v) := by - apply Subtype.ext - exact (symMonomialRaw_one V (fun _ => v)).symm - -@[simp] lemma symPowOneEquiv_symMonomial (v : Fin 1 → V) : - symPowOneEquiv V (symMonomial 1 V v) = v 0 := by - apply (symPowOneEquiv V).symm.injective - simp only [LinearEquiv.symm_apply_apply, symPowOneEquiv_symm_apply] - apply Subtype.ext - simp only [symMonomial, symMonomialRaw_one] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +universe u +namespace Problem346 + +variable (V : Type u) [AddCommGroup V] [Module ℂ V] + +lemma symmetricAlgebra_ι_injective : + Function.Injective (SymmetricAlgebra.ι ℂ V) := by + let : Module ℂᵐᵒᵖ V := Module.compHom _ ((RingHom.id ℂ).fromOpposite mul_comm) + have : IsCentralScalar ℂ V := ⟨fun _ _ => rfl⟩ + intro x y h + have h' := congrArg (SymmetricAlgebra.lift (TrivSqZeroExt.inrHom ℂ V)) h + apply TrivSqZeroExt.inr_injective (R := ℂ) + simpa using h' + +@[simp] lemma symMonomialRaw_one (v : Fin 1 → V) : + symMonomialRaw 1 V v = SymmetricAlgebra.ι ℂ V (v 0) := by + simp [symMonomialRaw] + +lemma symPowSubmodule_one : + symPowSubmodule 1 V = LinearMap.range (SymmetricAlgebra.ι ℂ V) := by + have h : Set.range (symMonomialRaw 1 V) = + Set.range (SymmetricAlgebra.ι ℂ V) := by + ext x + constructor + · rintro ⟨v, rfl⟩ + exact ⟨v 0, (symMonomialRaw_one V v).symm⟩ + · rintro ⟨v, rfl⟩ + exact ⟨fun _ => v, symMonomialRaw_one V (fun _ => v)⟩ + rw [symPowSubmodule, h] + exact Submodule.span_eq (LinearMap.range (SymmetricAlgebra.ι ℂ V)) + +/-- The canonical inclusion of a vector into the degree-one symmetric power. -/ +def symPowOneIntro : V →ₗ[ℂ] SymPow 1 V := + (SymmetricAlgebra.ι ℂ V).codRestrict (symPowSubmodule 1 V) (by + intro v + rw [symPowSubmodule_one] + exact ⟨v, rfl⟩) + +@[simp] lemma symPowOneIntro_coe (v : V) : + (symPowOneIntro V v : SymmetricAlgebra ℂ V) = SymmetricAlgebra.ι ℂ V v := rfl + +lemma symPowOneIntro_bijective : Function.Bijective (symPowOneIntro V) := by + constructor + · intro x y h + apply symmetricAlgebra_ι_injective V + exact congrArg Subtype.val h + · intro x + have hx := x.property + have hx' : (x : SymmetricAlgebra ℂ V) ∈ LinearMap.range (SymmetricAlgebra.ι ℂ V) := by + simpa only [symPowSubmodule_one] using hx + rcases hx' with ⟨v, hv⟩ + exact ⟨v, Subtype.ext hv⟩ + +/-- The degree-one symmetric power is canonically the original vector space. -/ +def symPowOneEquiv : SymPow 1 V ≃ₗ[ℂ] V := + (LinearEquiv.ofBijective (symPowOneIntro V) (symPowOneIntro_bijective V)).symm + +@[simp] lemma symPowOneEquiv_symm_apply (v : V) : + (symPowOneEquiv V).symm v = symMonomial 1 V (fun _ => v) := by + apply Subtype.ext + exact (symMonomialRaw_one V (fun _ => v)).symm + +@[simp] lemma symPowOneEquiv_symMonomial (v : Fin 1 → V) : + symPowOneEquiv V (symMonomial 1 V v) = v 0 := by + apply (symPowOneEquiv V).symm.injective + simp only [LinearEquiv.symm_apply_apply, symPowOneEquiv_symm_apply] + apply Subtype.ext + simp only [symMonomial, symMonomialRaw_one] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DerivationInjectivity.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DerivationInjectivity.lean index 6071eb01ef5a4901e95f4f87ab24a8d4745c714a..8203658e3c941f965d12c78d129af57a5e8879de 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DerivationInjectivity.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DerivationInjectivity.lean @@ -1,44 +1,44 @@ -import OAI.RepresentationTheory.FoulkesHowe.ShiftInjectivity -import OAI.RepresentationTheory.FoulkesHowe.ShiftNilpotence - -namespace OAI - -noncomputable section - -namespace Problem346 - -open MvPolynomial - -variable {K σ : Type*} [Field K] [CharZero K] - -/-- An algebraic form of the positive-weight injectivity criterion for polynomial -derivations. The generator condition admits arbitrary spectator variables. -/ -theorem derivation_eq_zero_of_positive_weight - (D E H : Derivation K (MvPolynomial σ K) (MvPolynomial σ K)) - (hED : ⁅E, D⁆ = H) (hHE : ⁅H, E⁆ = (2 : K) • E) - (hEX : ∀ i : σ, E (E (X i)) = 0) - (f : MvPolynomial σ K) (p q : ℕ) (hpq : q < p) - (hf : H f = ((p : K) - q) • f) (hDf : D f = 0) : f = 0 := by - refine ShiftInjectivity.eq_zero_of_positive_weight D.toLinearMap E.toLinearMap - H.toLinearMap ?_ ?_ f (p - q) (Nat.sub_pos_of_lt hpq) ?_ hDf ?_ - · intro z - have hz := congrArg (fun F : Derivation K (MvPolynomial σ K) - (MvPolynomial σ K) => F z) hED - simp only [Derivation.commutator_apply] at hz - change D (E z) = E (D z) - H z - linear_combination -hz - · intro z - have hz := congrArg (fun F : Derivation K (MvPolynomial σ K) - (MvPolynomial σ K) => F z) hHE - simp only [Derivation.commutator_apply, Derivation.smul_apply] at hz - change H (E z) = E (H z) + (2 : K) • E z - linear_combination hz - · change H f = ((p - q : ℕ) : K) • f - simpa only [Nat.cast_sub (Nat.le_of_lt hpq)] using hf - · exact mvPolynomial_derivation_locally_nilpotent_of_square_zero_X E hEX f - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.ShiftInjectivity +import OAI.RepresentationTheory.FoulkesHowe.ShiftNilpotence + +namespace OAI + +noncomputable section + +namespace Problem346 + +open MvPolynomial + +variable {K σ : Type*} [Field K] [CharZero K] + +/-- An algebraic form of the positive-weight injectivity criterion for polynomial +derivations. The generator condition admits arbitrary spectator variables. -/ +theorem derivation_eq_zero_of_positive_weight + (D E H : Derivation K (MvPolynomial σ K) (MvPolynomial σ K)) + (hED : ⁅E, D⁆ = H) (hHE : ⁅H, E⁆ = (2 : K) • E) + (hEX : ∀ i : σ, E (E (X i)) = 0) + (f : MvPolynomial σ K) (p q : ℕ) (hpq : q < p) + (hf : H f = ((p : K) - q) • f) (hDf : D f = 0) : f = 0 := by + refine ShiftInjectivity.eq_zero_of_positive_weight D.toLinearMap E.toLinearMap + H.toLinearMap ?_ ?_ f (p - q) (Nat.sub_pos_of_lt hpq) ?_ hDf ?_ + · intro z + have hz := congrArg (fun F : Derivation K (MvPolynomial σ K) + (MvPolynomial σ K) => F z) hED + simp only [Derivation.commutator_apply] at hz + change D (E z) = E (D z) - H z + linear_combination -hz + · intro z + have hz := congrArg (fun F : Derivation K (MvPolynomial σ K) + (MvPolynomial σ K) => F z) hHE + simp only [Derivation.commutator_apply, Derivation.smul_apply] at hz + change H (E z) = E (H z) + (2 : K) • E z + linear_combination hz + · change H f = ((p - q : ℕ) : K) • f + simpa only [Nat.cast_sub (Nat.le_of_lt hpq)] using hf + · exact mvPolynomial_derivation_locally_nilpotent_of_square_zero_X E hEX f + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalCoefficient.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalCoefficient.lean index 890b4e1bb314dcba9c52405254f208c01916eac2..69a7570eed6c9aa3265c0a1ddaa78f017f998240 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalCoefficient.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalCoefficient.lean @@ -1,126 +1,126 @@ -import Mathlib - -namespace OAI - -noncomputable section - -open scoped BigOperators - -namespace Problem346 - -universe u - -variable {E : Type u} [AddCommGroup E] [Module ℂ E] - -/-- The one-variable polynomial obtained by restricting a multilinear form to an affine diagonal. -/ -def diagonalPolynomial {a : ℕ} (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) - (x y : E) : Polynomial ℂ := - ∑ s : Finset (Fin a), - Polynomial.C (T (s.piecewise (fun _ => y) (fun _ => x))) * Polynomial.X ^ s.card - -lemma diagonalPolynomial_eval {a : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) (c : ℂ) : - (diagonalPolynomial T x y).eval c = T (fun _ => x + c • y) := by - classical - unfold diagonalPolynomial - simp only [Polynomial.eval_finsetSum, Polynomial.eval_mul, Polynomial.eval_C, - Polynomial.eval_pow, Polynomial.eval_X] - rw [show (fun _ : Fin a => x + c • y) = - (fun _ => c • y) + (fun _ => x) by ext; simp [add_comm]] - rw [T.map_add_univ] - apply Finset.sum_congr rfl - intro s hs - have h := T.map_piecewise_smul (fun _ => c) - (s.piecewise (fun _ => y) (fun _ => x)) s - have heq : s.piecewise (fun i => c • s.piecewise (fun _ => y) (fun _ => x) i) - (s.piecewise (fun _ => y) (fun _ => x)) = - s.piecewise (fun _ => c • y) (fun _ => x) := by - ext i - by_cases hi : i ∈ s <;> simp [Finset.piecewise, hi] - rw [heq] at h - simpa [smul_eq_mul, mul_comm] using h.symm - -lemma diagonalPolynomial_coeff_one {a : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) : - (diagonalPolynomial T x y).coeff 1 = - ∑ i : Fin a, T (Function.update (fun _ => x) i y) := by - classical - unfold diagonalPolynomial - simp only [Polynomial.finsetSum_coeff, Polynomial.coeff_C_mul_X_pow] - simp only [eq_comm (a := 1)] - rw [← Finset.sum_filter] - rw [← Finset.powerset_univ, ← Finset.powersetCard_eq_filter] - simp [Finset.powersetCard_one, Finset.piecewise_singleton] - -/-- If a multilinear form vanishes on an affine diagonal line, its linear diagonal -coefficient vanishes. This statement does not require symmetry. -/ -theorem diagonal_linear_coefficient_zero {a : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) - (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : - (∑ i : Fin a, T (Function.update (fun _ => x) i y)) = 0 := by - have hp : diagonalPolynomial T x y = 0 := - Polynomial.zero_of_eval_zero _ (fun c => by rw [diagonalPolynomial_eval, h]) - rw [← diagonalPolynomial_coeff_one, hp] - simp - -/-- Symmetry identifies the terms of the linear diagonal coefficient. -/ -lemma symmetric_update_eq {a : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) - (hsym : ∀ (σ : Equiv.Perm (Fin a)) (v : Fin a → E), - T (fun k => v (σ k)) = T v) - (x y : E) (i j : Fin a) : - T (Function.update (fun _ => x) j y) = - T (Function.update (fun _ => x) i y) := by - have h := hsym (Equiv.swap i j) (Function.update (fun _ => x) i y) - convert h using 1 - congr 1 - ext k - by_cases hi : k = i - · subst k - by_cases hij : i = j - · subst j - rw [Equiv.swap_apply_left, Function.update_self] - · simp [hij, Ne.symm hij] - · by_cases hj : k = j - · subst k; simp - · simp [Equiv.swap_apply_of_ne_of_ne hi hj, Function.update_of_ne, hi, hj] - -/-- Coefficient extraction for a symmetric multilinear form along an affine diagonal. -This is the coefficient-of-c argument in the split binary form step. -/ -theorem symmetric_diagonal_mixed_zero {a : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) - (hsym : ∀ (σ : Equiv.Perm (Fin a)) (v : Fin a → E), - T (fun k => v (σ k)) = T v) - (x y : E) (i : Fin a) - (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : - T (Function.update (fun _ => x) i y) = 0 := by - have hz := diagonal_linear_coefficient_zero T x y h - have heq : (∑ j : Fin a, T (Function.update (fun _ => x) j y)) = - (a : ℂ) * T (Function.update (fun _ => x) i y) := by - calc - _ = ∑ _j : Fin a, T (Function.update (fun _ => x) i y) := by - apply Finset.sum_congr rfl - intro j hj - exact symmetric_update_eq T hsym x y i j - _ = _ := by simp [nsmul_eq_mul] - rw [heq] at hz - exact (mul_eq_zero.mp hz).resolve_left (by exact_mod_cast Nat.ne_of_gt (Nat.zero_lt_of_lt i.isLt)) - -/-- The same coefficient extraction with the distinguished slot placed first. -/ -theorem symmetric_diagonal_cons_zero {r : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin (r + 1) => E) ℂ) - (hsym : ∀ (σ : Equiv.Perm (Fin (r + 1))) (v : Fin (r + 1) → E), - T (fun k => v (σ k)) = T v) - (x y : E) (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : - T (Fin.cons y (fun _ : Fin r => x)) = 0 := by - have hz := symmetric_diagonal_mixed_zero T hsym x y 0 h - convert hz using 1 - congr 1 - ext i - refine Fin.cases ?_ (fun j => ?_) i <;> simp - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +open scoped BigOperators + +namespace Problem346 + +universe u + +variable {E : Type u} [AddCommGroup E] [Module ℂ E] + +/-- The one-variable polynomial obtained by restricting a multilinear form to an affine diagonal. -/ +def diagonalPolynomial {a : ℕ} (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) + (x y : E) : Polynomial ℂ := + ∑ s : Finset (Fin a), + Polynomial.C (T (s.piecewise (fun _ => y) (fun _ => x))) * Polynomial.X ^ s.card + +lemma diagonalPolynomial_eval {a : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) (c : ℂ) : + (diagonalPolynomial T x y).eval c = T (fun _ => x + c • y) := by + classical + unfold diagonalPolynomial + simp only [Polynomial.eval_finsetSum, Polynomial.eval_mul, Polynomial.eval_C, + Polynomial.eval_pow, Polynomial.eval_X] + rw [show (fun _ : Fin a => x + c • y) = + (fun _ => c • y) + (fun _ => x) by ext; simp [add_comm]] + rw [T.map_add_univ] + apply Finset.sum_congr rfl + intro s hs + have h := T.map_piecewise_smul (fun _ => c) + (s.piecewise (fun _ => y) (fun _ => x)) s + have heq : s.piecewise (fun i => c • s.piecewise (fun _ => y) (fun _ => x) i) + (s.piecewise (fun _ => y) (fun _ => x)) = + s.piecewise (fun _ => c • y) (fun _ => x) := by + ext i + by_cases hi : i ∈ s <;> simp [Finset.piecewise, hi] + rw [heq] at h + simpa [smul_eq_mul, mul_comm] using h.symm + +lemma diagonalPolynomial_coeff_one {a : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) : + (diagonalPolynomial T x y).coeff 1 = + ∑ i : Fin a, T (Function.update (fun _ => x) i y) := by + classical + unfold diagonalPolynomial + simp only [Polynomial.finsetSum_coeff, Polynomial.coeff_C_mul_X_pow] + simp only [eq_comm (a := 1)] + rw [← Finset.sum_filter] + rw [← Finset.powerset_univ, ← Finset.powersetCard_eq_filter] + simp [Finset.powersetCard_one, Finset.piecewise_singleton] + +/-- If a multilinear form vanishes on an affine diagonal line, its linear diagonal +coefficient vanishes. This statement does not require symmetry. -/ +theorem diagonal_linear_coefficient_zero {a : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) (x y : E) + (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : + (∑ i : Fin a, T (Function.update (fun _ => x) i y)) = 0 := by + have hp : diagonalPolynomial T x y = 0 := + Polynomial.zero_of_eval_zero _ (fun c => by rw [diagonalPolynomial_eval, h]) + rw [← diagonalPolynomial_coeff_one, hp] + simp + +/-- Symmetry identifies the terms of the linear diagonal coefficient. -/ +lemma symmetric_update_eq {a : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) + (hsym : ∀ (σ : Equiv.Perm (Fin a)) (v : Fin a → E), + T (fun k => v (σ k)) = T v) + (x y : E) (i j : Fin a) : + T (Function.update (fun _ => x) j y) = + T (Function.update (fun _ => x) i y) := by + have h := hsym (Equiv.swap i j) (Function.update (fun _ => x) i y) + convert h using 1 + congr 1 + ext k + by_cases hi : k = i + · subst k + by_cases hij : i = j + · subst j + rw [Equiv.swap_apply_left, Function.update_self] + · simp [hij, Ne.symm hij] + · by_cases hj : k = j + · subst k; simp + · simp [Equiv.swap_apply_of_ne_of_ne hi hj, Function.update_of_ne, hi, hj] + +/-- Coefficient extraction for a symmetric multilinear form along an affine diagonal. +This is the coefficient-of-c argument in the split binary form step. -/ +theorem symmetric_diagonal_mixed_zero {a : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin a => E) ℂ) + (hsym : ∀ (σ : Equiv.Perm (Fin a)) (v : Fin a → E), + T (fun k => v (σ k)) = T v) + (x y : E) (i : Fin a) + (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : + T (Function.update (fun _ => x) i y) = 0 := by + have hz := diagonal_linear_coefficient_zero T x y h + have heq : (∑ j : Fin a, T (Function.update (fun _ => x) j y)) = + (a : ℂ) * T (Function.update (fun _ => x) i y) := by + calc + _ = ∑ _j : Fin a, T (Function.update (fun _ => x) i y) := by + apply Finset.sum_congr rfl + intro j hj + exact symmetric_update_eq T hsym x y i j + _ = _ := by simp [nsmul_eq_mul] + rw [heq] at hz + exact (mul_eq_zero.mp hz).resolve_left (by exact_mod_cast Nat.ne_of_gt (Nat.zero_lt_of_lt i.isLt)) + +/-- The same coefficient extraction with the distinguished slot placed first. -/ +theorem symmetric_diagonal_cons_zero {r : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin (r + 1) => E) ℂ) + (hsym : ∀ (σ : Equiv.Perm (Fin (r + 1))) (v : Fin (r + 1) → E), + T (fun k => v (σ k)) = T v) + (x y : E) (h : ∀ c : ℂ, T (fun _ => x + c • y) = 0) : + T (Fin.cons y (fun _ : Fin r => x)) = 0 := by + have hz := symmetric_diagonal_mixed_zero T hsym x y 0 h + convert hz using 1 + congr 1 + ext i + refine Fin.cases ?_ (fun j => ?_) i <;> simp + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalPolarization.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalPolarization.lean index 29d8147faf2667d793401f75c0b749c8f91ce96d..0573d16d1ed903c0dbb742f459a77cb2d927b351 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalPolarization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DiagonalPolarization.lean @@ -1,62 +1,62 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 - -/-- A symmetric continuous multilinear form is determined by its diagonal. -/ -theorem continuous_symmetric_multilinear_eq_zero_of_diagonal - {W : Type*} [NormedAddCommGroup W] [NormedSpace ℂ W] {n : ℕ} - (T : ContinuousMultilinearMap ℂ (fun _ : Fin n => W) ℂ) - (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → W), - T (fun i => x (σ i)) = T x) - (hdiag : ∀ x : W, T (fun _ => x) = 0) : T = 0 := by - ext x - have h := T.iteratedFDeriv_comp_diagonal (0 : W) x - have hz : (fun x : W => T (fun _ => x)) = fun _ => 0 := funext hdiag - rw [hz] at h - simp only [iteratedFDeriv_fun_zero, Pi.zero_apply, zero_apply] at h - simp only [hsym, Finset.sum_const, Finset.card_univ, Fintype.card_perm, - Fintype.card_fin, nsmul_eq_mul] at h - exact (mul_eq_zero.mp h.symm).resolve_left (by exact_mod_cast Nat.factorial_ne_zero n) - -/-- Algebraic polarization, without a topology on the source vector space. -/ -theorem symmetric_multilinear_eq_zero_of_diagonal - {W : Type*} [AddCommGroup W] [Module ℂ W] {n : ℕ} - (T : MultilinearMap ℂ (fun _ : Fin n => W) ℂ) - (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → W), - T (fun i => x (σ i)) = T x) - (hdiag : ∀ x : W, T (fun _ => x) = 0) : T = 0 := by - classical - ext x - let L : (Fin n → ℂ) →ₗ[ℂ] W := - ∑ i : Fin n, (LinearMap.proj i).smulRight (x i) - let S := T.compLinearMap (fun _ => L) - have hL (z : Fin n → ℂ) : L z = ∑ i, z i • x i := by simp [L] - have hS (z : Fin n → Fin n → ℂ) : - S z = ∑ r : Fin n → Fin n, (∏ i, z i (r i)) • T (fun i => x (r i)) := by - simp only [S, MultilinearMap.compLinearMap_apply, hL] - rw [T.map_sum] - simp only [T.map_smul_univ] - have hc : Continuous S := by - have heq : (fun z => S z) = fun z => - ∑ r : Fin n → Fin n, (∏ i, z i (r i)) • T (fun i => x (r i)) := funext hS - rw [show (S : (Fin n → Fin n → ℂ) → ℂ) = _ from heq] - fun_prop - let C : ContinuousMultilinearMap ℂ (fun _ : Fin n => Fin n → ℂ) ℂ := ⟨S, hc⟩ - have hC : C = 0 := continuous_symmetric_multilinear_eq_zero_of_diagonal C - (by intro σ z; exact hsym σ (fun i => L (z i))) - (by intro z; exact hdiag (L z)) - have hh := congrArg (fun f : ContinuousMultilinearMap ℂ - (fun _ : Fin n => Fin n → ℂ) ℂ => f (fun i => Pi.single i 1)) hC - change T (fun i => L (Pi.single i 1)) = 0 at hh - simpa [hL] using hh - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 + +/-- A symmetric continuous multilinear form is determined by its diagonal. -/ +theorem continuous_symmetric_multilinear_eq_zero_of_diagonal + {W : Type*} [NormedAddCommGroup W] [NormedSpace ℂ W] {n : ℕ} + (T : ContinuousMultilinearMap ℂ (fun _ : Fin n => W) ℂ) + (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → W), + T (fun i => x (σ i)) = T x) + (hdiag : ∀ x : W, T (fun _ => x) = 0) : T = 0 := by + ext x + have h := T.iteratedFDeriv_comp_diagonal (0 : W) x + have hz : (fun x : W => T (fun _ => x)) = fun _ => 0 := funext hdiag + rw [hz] at h + simp only [iteratedFDeriv_fun_zero, Pi.zero_apply, zero_apply] at h + simp only [hsym, Finset.sum_const, Finset.card_univ, Fintype.card_perm, + Fintype.card_fin, nsmul_eq_mul] at h + exact (mul_eq_zero.mp h.symm).resolve_left (by exact_mod_cast Nat.factorial_ne_zero n) + +/-- Algebraic polarization, without a topology on the source vector space. -/ +theorem symmetric_multilinear_eq_zero_of_diagonal + {W : Type*} [AddCommGroup W] [Module ℂ W] {n : ℕ} + (T : MultilinearMap ℂ (fun _ : Fin n => W) ℂ) + (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → W), + T (fun i => x (σ i)) = T x) + (hdiag : ∀ x : W, T (fun _ => x) = 0) : T = 0 := by + classical + ext x + let L : (Fin n → ℂ) →ₗ[ℂ] W := + ∑ i : Fin n, (LinearMap.proj i).smulRight (x i) + let S := T.compLinearMap (fun _ => L) + have hL (z : Fin n → ℂ) : L z = ∑ i, z i • x i := by simp [L] + have hS (z : Fin n → Fin n → ℂ) : + S z = ∑ r : Fin n → Fin n, (∏ i, z i (r i)) • T (fun i => x (r i)) := by + simp only [S, MultilinearMap.compLinearMap_apply, hL] + rw [T.map_sum] + simp only [T.map_smul_univ] + have hc : Continuous S := by + have heq : (fun z => S z) = fun z => + ∑ r : Fin n → Fin n, (∏ i, z i (r i)) • T (fun i => x (r i)) := funext hS + rw [show (S : (Fin n → Fin n → ℂ) → ℂ) = _ from heq] + fun_prop + let C : ContinuousMultilinearMap ℂ (fun _ : Fin n => Fin n → ℂ) ℂ := ⟨S, hc⟩ + have hC : C = 0 := continuous_symmetric_multilinear_eq_zero_of_diagonal C + (by intro σ z; exact hsym σ (fun i => L (z i))) + (by intro z; exact hdiag (L z)) + have hh := congrArg (fun f : ContinuousMultilinearMap ℂ + (fun _ : Fin n => Fin n → ℂ) ℂ => f (fun i => Pi.single i 1)) hC + change T (fun i => L (Pi.single i 1)) = 0 at hh + simpa [hL] using hh + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DualComparison.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DualComparison.lean index 0090e6c57644653c40c4484fc9ff6ed78cc54bac..f3ba63dfdb6a504453d44f01901fc01c9c3b246d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DualComparison.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DualComparison.lean @@ -1,76 +1,76 @@ -import OAI.RepresentationTheory.FoulkesHowe.DualEquivalence -import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual - -namespace OAI - -noncomputable section -namespace Problem346 - -/-- The canonical symmetric-power pairing is natural for arbitrary linear maps. -/ -theorem canonicalSymPowDualMap_adjoint (n : ℕ) {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (A : V →ₗ[ℂ] W) (p : SymPow n (Module.Dual ℂ W)) (q : SymPow n V) : - symPowDualMap n V (symPowMap n A.dualMap p) q = - symPowDualMap n W p (symPowMap n A q) := by - have h : (symPowDualMap n V).comp (symPowMap n A.dualMap) = - (symPowMap n A).dualMap.comp (symPowDualMap n W) := by - apply symPow_linearMap_ext n (Module.Dual ℂ W) - intro φ - apply symPow_linearMap_ext n V - intro x - simp only [LinearMap.comp_apply, LinearMap.dualMap_apply, - symPowMap_symMonomial, symPowDualMap_monomial] - rfl - exact congrArg (fun f : Module.Dual ℂ (SymPow n V) => f q) - (LinearMap.congr_fun h p) - -/-- The perfect-pairing equivalence has the same adjointness identity. -/ -theorem canonicalSymPowDualEquiv_adjoint (n : ℕ) {V W : Type*} - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] - (A : V →ₗ[ℂ] W) (p : SymPow n (Module.Dual ℂ W)) (q : SymPow n V) : - symPowDualEquiv n V (symPowMap n A.dualMap p) q = - symPowDualEquiv n W p (symPowMap n A q) := - canonicalSymPowDualMap_adjoint n A p q - -/-- Canonical duality on a nested symmetric power. -/ -def concretePlethysmDualEquiv (outer inner : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : - SymPow outer (SymPow inner (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow outer (SymPow inner V)) := - PlethysmDual.plethysmDualEquivOf outer inner - (symPowDualEquiv inner V) (symPowDualEquiv outer (SymPow inner V)) - -theorem concretePlethysmDualEquiv_adjoint (outer inner : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (g : V ≃ₗ[ℂ] V) - (p : SymPow outer (SymPow inner (Module.Dual ℂ V))) - (q : SymPow outer (SymPow inner V)) : - concretePlethysmDualEquiv outer inner V - (plethysmAction outer inner g.dualMap p) q = - concretePlethysmDualEquiv outer inner V p (plethysmAction outer inner g q) := by - apply PlethysmDual.plethysmDualEquivOf_adjoint - · intro x y - exact canonicalSymPowDualEquiv_adjoint inner g.toLinearMap x y - · intro x y - exact canonicalSymPowDualEquiv_adjoint outer (symPowMap inner g.toLinearMap) x y - -/-- A canonical surjection at the dual vector space supplies the required -GL-equivariant comparison embedding, using the concrete perfect pairings. -/ -theorem comparison_embedding_of_dual_foulkes_surjection (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] - SymPow a (SymPow b (Module.Dual ℂ V)), - IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : - ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), - IsGLEquivariantEmbedding a b V ι := - PlethysmDual.comparison_of_dual_charts a b - (concretePlethysmDualEquiv b a V) (concretePlethysmDualEquiv a b V) - (concretePlethysmDualEquiv_adjoint b a V) - (concretePlethysmDualEquiv_adjoint a b V) hsurj - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.DualEquivalence +import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual + +namespace OAI + +noncomputable section +namespace Problem346 + +/-- The canonical symmetric-power pairing is natural for arbitrary linear maps. -/ +theorem canonicalSymPowDualMap_adjoint (n : ℕ) {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (A : V →ₗ[ℂ] W) (p : SymPow n (Module.Dual ℂ W)) (q : SymPow n V) : + symPowDualMap n V (symPowMap n A.dualMap p) q = + symPowDualMap n W p (symPowMap n A q) := by + have h : (symPowDualMap n V).comp (symPowMap n A.dualMap) = + (symPowMap n A).dualMap.comp (symPowDualMap n W) := by + apply symPow_linearMap_ext n (Module.Dual ℂ W) + intro φ + apply symPow_linearMap_ext n V + intro x + simp only [LinearMap.comp_apply, LinearMap.dualMap_apply, + symPowMap_symMonomial, symPowDualMap_monomial] + rfl + exact congrArg (fun f : Module.Dual ℂ (SymPow n V) => f q) + (LinearMap.congr_fun h p) + +/-- The perfect-pairing equivalence has the same adjointness identity. -/ +theorem canonicalSymPowDualEquiv_adjoint (n : ℕ) {V W : Type*} + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + [AddCommGroup W] [Module ℂ W] [FiniteDimensional ℂ W] + (A : V →ₗ[ℂ] W) (p : SymPow n (Module.Dual ℂ W)) (q : SymPow n V) : + symPowDualEquiv n V (symPowMap n A.dualMap p) q = + symPowDualEquiv n W p (symPowMap n A q) := + canonicalSymPowDualMap_adjoint n A p q + +/-- Canonical duality on a nested symmetric power. -/ +def concretePlethysmDualEquiv (outer inner : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : + SymPow outer (SymPow inner (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow outer (SymPow inner V)) := + PlethysmDual.plethysmDualEquivOf outer inner + (symPowDualEquiv inner V) (symPowDualEquiv outer (SymPow inner V)) + +theorem concretePlethysmDualEquiv_adjoint (outer inner : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (g : V ≃ₗ[ℂ] V) + (p : SymPow outer (SymPow inner (Module.Dual ℂ V))) + (q : SymPow outer (SymPow inner V)) : + concretePlethysmDualEquiv outer inner V + (plethysmAction outer inner g.dualMap p) q = + concretePlethysmDualEquiv outer inner V p (plethysmAction outer inner g q) := by + apply PlethysmDual.plethysmDualEquivOf_adjoint + · intro x y + exact canonicalSymPowDualEquiv_adjoint inner g.toLinearMap x y + · intro x y + exact canonicalSymPowDualEquiv_adjoint outer (symPowMap inner g.toLinearMap) x y + +/-- A canonical surjection at the dual vector space supplies the required +GL-equivariant comparison embedding, using the concrete perfect pairings. -/ +theorem comparison_embedding_of_dual_foulkes_surjection (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] + SymPow a (SymPow b (Module.Dual ℂ V)), + IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : + ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), + IsGLEquivariantEmbedding a b V ι := + PlethysmDual.comparison_of_dual_charts a b + (concretePlethysmDualEquiv b a V) (concretePlethysmDualEquiv a b V) + (concretePlethysmDualEquiv_adjoint b a V) + (concretePlethysmDualEquiv_adjoint a b V) hsurj + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DualEmbedding.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DualEmbedding.lean index 6d33ba034b8353a022426e6de37640fb91eb6add..556c789abf50d87f9fa921cb9525dbaed1453d26 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DualEmbedding.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DualEmbedding.lean @@ -1,91 +1,91 @@ -import Mathlib - -namespace OAI - -/-! -# Transposed embeddings - -A surjective intertwiner yields an injective intertwiner in the opposite - direction when both modules carry compatible perfect pairings. This is an - algebraic alternative to splitting a representation by complete reducibility. --/ - -noncomputable section - -namespace Problem346 -namespace DualEmbedding - -variable {R E F E' F' : Type*} [CommSemiring R] - [AddCommMonoid E] [Module R E] [AddCommMonoid F] [Module R F] - [AddCommMonoid E'] [Module R E'] [AddCommMonoid F'] [Module R F'] - -/-- Reverse a perfect pairing when the first module is reflexive. This turns - the usual chart `E' ≃ Dual E` into the orientation needed by `transpose`. -/ -def flipPairing [Module.IsReflexive R E] (e : E' ≃ₗ[R] Module.Dual R E) : - E ≃ₗ[R] Module.Dual R E' := - (Module.evalEquiv R E).trans e.dualMap - -@[simp] -theorem flipPairing_apply [Module.IsReflexive R E] - (e : E' ≃ₗ[R] Module.Dual R E) (x : E) (y : E') : - flipPairing e x y = e y x := rfl - -/-- Transport the dual of a linear map along two perfect pairings. -/ -def transpose (e : E ≃ₗ[R] Module.Dual R E') - (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') : F →ₗ[R] E := - e.symm.toLinearMap.comp (μ.dualMap.comp f.toLinearMap) - -@[simp] -theorem pairing_transpose (e : E ≃ₗ[R] Module.Dual R E') - (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') (y : F) (x : E') : - e (transpose e f μ y) x = f y (μ x) := by - simp [transpose] - -/-- Surjectivity of a map implies injectivity of its transported transpose. -/ -theorem transpose_injective (e : E ≃ₗ[R] Module.Dual R E') - (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') - (hμ : Function.Surjective μ) : Function.Injective (transpose e f μ) := by - exact e.symm.injective.comp ((LinearMap.dualMap_injective_of_surjective hμ).comp - f.injective) - -/-- Transposition reverses an intertwining identity, with the two adjoint - identities expressed directly as evaluations of the perfect pairings. -/ -theorem transpose_intertwines - (e : E ≃ₗ[R] Module.Dual R E') (f : F ≃ₗ[R] Module.Dual R F') - (μ : E' →ₗ[R] F') (A : E →ₗ[R] E) (A' : E' →ₗ[R] E') - (B : F →ₗ[R] F) (B' : F' →ₗ[R] F') - (he : ∀ x z, e (A x) z = e x (A' z)) - (hf : ∀ y w, f (B y) w = f y (B' w)) - (hμ : μ.comp A' = B'.comp μ) : - A.comp (transpose e f μ) = (transpose e f μ).comp B := by - ext y - apply e.injective - ext x - change e (A (transpose e f μ y)) x = e (transpose e f μ (B y)) x - rw [he, pairing_transpose, pairing_transpose, hf] - exact congrArg (f y) (LinearMap.congr_fun hμ x) - -/-- A family of compatible adjoint actions transports a surjective - equivariant map into an injective equivariant map in the reverse direction. - No group structure or finite-dimensionality is needed by this argument. -/ -theorem exists_intertwining_injection_of_surjective {G : Type*} - (e : E ≃ₗ[R] Module.Dual R E') (f : F ≃ₗ[R] Module.Dual R F') - (A : G → E →ₗ[R] E) (B : G → F →ₗ[R] F) - (A' : G → E' →ₗ[R] E') (B' : G → F' →ₗ[R] F') - (he : ∀ g x z, e (A g x) z = e x (A' g z)) - (hf : ∀ g y w, f (B g y) w = f y (B' g w)) - (μ : E' →ₗ[R] F') (hμ : Function.Surjective μ) - (hcomm : ∀ g, μ.comp (A' g) = (B' g).comp μ) : - ∃ ι : F →ₗ[R] E, Function.Injective ι ∧ - ∀ g, (A g).comp ι = ι.comp (B g) := by - refine ⟨transpose e f μ, transpose_injective e f μ hμ, ?_⟩ - intro g - exact transpose_intertwines e f μ (A g) (A' g) (B g) (B' g) - (he g) (hf g) (hcomm g) - -end DualEmbedding -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +/-! +# Transposed embeddings + +A surjective intertwiner yields an injective intertwiner in the opposite + direction when both modules carry compatible perfect pairings. This is an + algebraic alternative to splitting a representation by complete reducibility. +-/ + +noncomputable section + +namespace Problem346 +namespace DualEmbedding + +variable {R E F E' F' : Type*} [CommSemiring R] + [AddCommMonoid E] [Module R E] [AddCommMonoid F] [Module R F] + [AddCommMonoid E'] [Module R E'] [AddCommMonoid F'] [Module R F'] + +/-- Reverse a perfect pairing when the first module is reflexive. This turns + the usual chart `E' ≃ Dual E` into the orientation needed by `transpose`. -/ +def flipPairing [Module.IsReflexive R E] (e : E' ≃ₗ[R] Module.Dual R E) : + E ≃ₗ[R] Module.Dual R E' := + (Module.evalEquiv R E).trans e.dualMap + +@[simp] +theorem flipPairing_apply [Module.IsReflexive R E] + (e : E' ≃ₗ[R] Module.Dual R E) (x : E) (y : E') : + flipPairing e x y = e y x := rfl + +/-- Transport the dual of a linear map along two perfect pairings. -/ +def transpose (e : E ≃ₗ[R] Module.Dual R E') + (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') : F →ₗ[R] E := + e.symm.toLinearMap.comp (μ.dualMap.comp f.toLinearMap) + +@[simp] +theorem pairing_transpose (e : E ≃ₗ[R] Module.Dual R E') + (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') (y : F) (x : E') : + e (transpose e f μ y) x = f y (μ x) := by + simp [transpose] + +/-- Surjectivity of a map implies injectivity of its transported transpose. -/ +theorem transpose_injective (e : E ≃ₗ[R] Module.Dual R E') + (f : F ≃ₗ[R] Module.Dual R F') (μ : E' →ₗ[R] F') + (hμ : Function.Surjective μ) : Function.Injective (transpose e f μ) := by + exact e.symm.injective.comp ((LinearMap.dualMap_injective_of_surjective hμ).comp + f.injective) + +/-- Transposition reverses an intertwining identity, with the two adjoint + identities expressed directly as evaluations of the perfect pairings. -/ +theorem transpose_intertwines + (e : E ≃ₗ[R] Module.Dual R E') (f : F ≃ₗ[R] Module.Dual R F') + (μ : E' →ₗ[R] F') (A : E →ₗ[R] E) (A' : E' →ₗ[R] E') + (B : F →ₗ[R] F) (B' : F' →ₗ[R] F') + (he : ∀ x z, e (A x) z = e x (A' z)) + (hf : ∀ y w, f (B y) w = f y (B' w)) + (hμ : μ.comp A' = B'.comp μ) : + A.comp (transpose e f μ) = (transpose e f μ).comp B := by + ext y + apply e.injective + ext x + change e (A (transpose e f μ y)) x = e (transpose e f μ (B y)) x + rw [he, pairing_transpose, pairing_transpose, hf] + exact congrArg (f y) (LinearMap.congr_fun hμ x) + +/-- A family of compatible adjoint actions transports a surjective + equivariant map into an injective equivariant map in the reverse direction. + No group structure or finite-dimensionality is needed by this argument. -/ +theorem exists_intertwining_injection_of_surjective {G : Type*} + (e : E ≃ₗ[R] Module.Dual R E') (f : F ≃ₗ[R] Module.Dual R F') + (A : G → E →ₗ[R] E) (B : G → F →ₗ[R] F) + (A' : G → E' →ₗ[R] E') (B' : G → F' →ₗ[R] F') + (he : ∀ g x z, e (A g x) z = e x (A' g z)) + (hf : ∀ g y w, f (B g y) w = f y (B' g w)) + (μ : E' →ₗ[R] F') (hμ : Function.Surjective μ) + (hcomm : ∀ g, μ.comp (A' g) = (B' g).comp μ) : + ∃ ι : F →ₗ[R] E, Function.Injective ι ∧ + ∀ g, (A g).comp ι = ι.comp (B g) := by + refine ⟨transpose e f μ, transpose_injective e f μ hμ, ?_⟩ + intro g + exact transpose_intertwines e f μ (A g) (A' g) (B g) (B' g) + (he g) (hf g) (hcomm g) + +end DualEmbedding +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/DualEquivalence.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/DualEquivalence.lean index d243012450225cee4cf411bb94eeeb3d57251a92..51a694842eda938b51e5d699c6fd24fbe817ebde 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/DualEquivalence.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/DualEquivalence.lean @@ -1,39 +1,39 @@ -import OAI.RepresentationTheory.FoulkesHowe.SymmetricPairing -import OAI.RepresentationTheory.FoulkesHowe.PairingPerfection - -namespace OAI - -noncomputable section -universe u -namespace Problem346 - -variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - [FiniteDimensional ℂ V] - -/-- The canonical symmetric-power pairing is perfect in finite dimension. -/ -instance symPowDualMap_isPerfPair : (symPowDualMap n V).IsPerfPair := - symPowDual_isPerfPair_of_pure_evaluation V n (symPowDualMap n V) - (symPowDualMap_pure_right n V) (symPowDualMap_pure_left n V) - -/-- Symmetric powers commute with algebraic duality in finite dimension. -/ -def symPowDualEquiv : - SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := - (symPowDualMap n V).toPerfPair - -@[simp] theorem symPowDualEquiv_toLinearMap : - (symPowDualEquiv n V).toLinearMap = symPowDualMap n V := rfl - -@[simp] theorem symPowDualEquiv_apply (p : SymPow n (Module.Dual ℂ V)) - (q : SymPow n V) : symPowDualEquiv n V p q = symPowDualMap n V p q := rfl - -@[simp] theorem symPowDualEquiv_monomial (φ : Fin n → Module.Dual ℂ V) - (x : Fin n → V) : - symPowDualEquiv n V (symMonomial n (Module.Dual ℂ V) φ) (symMonomial n V x) = - permanentPairing n (fun φ x => φ x) φ x := - symPowDualMap_monomial n V φ x - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SymmetricPairing +import OAI.RepresentationTheory.FoulkesHowe.PairingPerfection + +namespace OAI + +noncomputable section +universe u +namespace Problem346 + +variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + [FiniteDimensional ℂ V] + +/-- The canonical symmetric-power pairing is perfect in finite dimension. -/ +instance symPowDualMap_isPerfPair : (symPowDualMap n V).IsPerfPair := + symPowDual_isPerfPair_of_pure_evaluation V n (symPowDualMap n V) + (symPowDualMap_pure_right n V) (symPowDualMap_pure_left n V) + +/-- Symmetric powers commute with algebraic duality in finite dimension. -/ +def symPowDualEquiv : + SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := + (symPowDualMap n V).toPerfPair + +@[simp] theorem symPowDualEquiv_toLinearMap : + (symPowDualEquiv n V).toLinearMap = symPowDualMap n V := rfl + +@[simp] theorem symPowDualEquiv_apply (p : SymPow n (Module.Dual ℂ V)) + (q : SymPow n V) : symPowDualEquiv n V p q = symPowDualMap n V p q := rfl + +@[simp] theorem symPowDualEquiv_monomial (φ : Fin n → Module.Dual ℂ V) + (x : Fin n → V) : + symPowDualEquiv n V (symMonomial n (Module.Dual ℂ V) φ) (symMonomial n V x) = + permanentPairing n (fun φ x => φ x) φ x := + symPowDualMap_monomial n V φ x + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/EncodedCancellation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/EncodedCancellation.lean index a604b6dd0033f57fe0c1c728779784917057c7d6..014bff158227dd76d1d6c35b6a369354f47bbad3 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/EncodedCancellation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/EncodedCancellation.lean @@ -1,58 +1,58 @@ -import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial -import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative -import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous -import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 - -/-- Cancel one directional derivative of a repeated-block multilinear polynomial. -It suffices that every single source-slot replacement vanishes; no normalization -or nonvanishing factorial is needed. -/ -theorem multilinearPolynomial_eq_zero_of_replacements - {V S I B : Type*} [AddCommGroup V] [Module ℂ V] - [Fintype S] [Fintype I] [Fintype B] [hS : DecidableEq S] [hB : DecidableEq B] - (L : MultilinearMap ℂ (fun _ : S => V) ℂ) (e : I → V) - (blocks : S → B) (src dst : B) (hsd : src ≠ dst) - (hdegree : (Finset.univ.filter (fun s => blocks s = dst)).card < - (Finset.univ.filter (fun s => blocks s = src)).card) - (hzero : ∀ s, blocks s = src → - multilinearPolynomial L e (Function.update blocks s dst) = 0) : - multilinearPolynomial L e blocks = 0 := by - classical - have hS_eq : hS = Classical.decEq S := Subsingleton.elim _ _ - cases hS_eq - have hB_eq : hB = Classical.decEq B := Subsingleton.elim _ _ - cases hB_eq - apply PolynomialShift.eq_zero_of_shift_eq_zero src dst hsd hdegree - · unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight - simpa only [multilinearPolynomial] using - EncodingDegree.blockHomogeneous_expansion - (fun k => L (fun s => e (k s))) blocks src - · unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight - simpa only [multilinearPolynomial] using - EncodingDegree.blockHomogeneous_expansion - (fun k => L (fun s => e (k s))) blocks dst - · have hd := SlotPolynomial.derivation_polynomial - (fun k => L (fun s => e (k s))) blocks src dst - (PolynomialShift.derivation src dst) (by intro b i; simp) - have hz : (∑ s ∈ Finset.univ.filter (fun s => blocks s = src), - SlotPolynomial.polynomial (fun k => L (fun s => e (k s))) - (Function.update blocks s dst)) = 0 := by - apply Finset.sum_eq_zero - intro s hs - simpa only [SlotPolynomial.polynomial, multilinearPolynomial] using - hzero s (Finset.mem_filter.mp hs).2 - rw [hz] at hd - simpa only [PolynomialShift.shift_apply, SlotPolynomial.polynomial, - multilinearPolynomial] using hd - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial +import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative +import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous +import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 + +/-- Cancel one directional derivative of a repeated-block multilinear polynomial. +It suffices that every single source-slot replacement vanishes; no normalization +or nonvanishing factorial is needed. -/ +theorem multilinearPolynomial_eq_zero_of_replacements + {V S I B : Type*} [AddCommGroup V] [Module ℂ V] + [Fintype S] [Fintype I] [Fintype B] [hS : DecidableEq S] [hB : DecidableEq B] + (L : MultilinearMap ℂ (fun _ : S => V) ℂ) (e : I → V) + (blocks : S → B) (src dst : B) (hsd : src ≠ dst) + (hdegree : (Finset.univ.filter (fun s => blocks s = dst)).card < + (Finset.univ.filter (fun s => blocks s = src)).card) + (hzero : ∀ s, blocks s = src → + multilinearPolynomial L e (Function.update blocks s dst) = 0) : + multilinearPolynomial L e blocks = 0 := by + classical + have hS_eq : hS = Classical.decEq S := Subsingleton.elim _ _ + cases hS_eq + have hB_eq : hB = Classical.decEq B := Subsingleton.elim _ _ + cases hB_eq + apply PolynomialShift.eq_zero_of_shift_eq_zero src dst hsd hdegree + · unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight + simpa only [multilinearPolynomial] using + EncodingDegree.blockHomogeneous_expansion + (fun k => L (fun s => e (k s))) blocks src + · unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight + simpa only [multilinearPolynomial] using + EncodingDegree.blockHomogeneous_expansion + (fun k => L (fun s => e (k s))) blocks dst + · have hd := SlotPolynomial.derivation_polynomial + (fun k => L (fun s => e (k s))) blocks src dst + (PolynomialShift.derivation src dst) (by intro b i; simp) + have hz : (∑ s ∈ Finset.univ.filter (fun s => blocks s = src), + SlotPolynomial.polynomial (fun k => L (fun s => e (k s))) + (Function.update blocks s dst)) = 0 := by + apply Finset.sum_eq_zero + intro s hs + simpa only [SlotPolynomial.polynomial, multilinearPolynomial] using + hzero s (Finset.mem_filter.mp hs).2 + rw [hz] at hd + simpa only [PolynomialShift.shift_apply, SlotPolynomial.polynomial, + multilinearPolynomial] using hd + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/EncodingHomogeneous.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/EncodingHomogeneous.lean index a21af5f9b1508f1066eabbe8ca844dff20470fab..31dee8a4471f1da9a10c895fe086e164e0a8207e 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/EncodingHomogeneous.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/EncodingHomogeneous.lean @@ -1,61 +1,61 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346.EncodingDegree - -variable {R : Type*} [CommSemiring R] -variable {S K B : Type*} [Fintype S] [DecidableEq S] [Fintype K] - -/-- A coefficient expansion has weighted degree given by the sum of the weights -of its assigned vector blocks. The coefficients can be arbitrary. -/ -theorem weightedHomogeneous_expansion (c : (S → K) → R) (blocks : S → B) - (w : B → ℕ) : - MvPolynomial.IsWeightedHomogeneous (fun x : B × K => w x.1) - (∑ k : S → K, MvPolynomial.C (c k) * - ∏ i : S, MvPolynomial.X (blocks i, k i)) - (∑ i : S, w (blocks i)) := by - classical - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - apply MvPolynomial.IsWeightedHomogeneous.C_mul - apply MvPolynomial.IsWeightedHomogeneous.prod - intro i _ - exact MvPolynomial.isWeightedHomogeneous_X _ _ _ - -/-- The degree in one block is exactly the number of occurrences of that block. -/ -theorem blockHomogeneous_expansion [DecidableEq B] - (c : (S → K) → R) (blocks : S → B) (b : B) : - MvPolynomial.IsWeightedHomogeneous - (fun x : B × K => if x.1 = b then 1 else 0) - (∑ k : S → K, MvPolynomial.C (c k) * - ∏ i : S, MvPolynomial.X (blocks i, k i)) - (Finset.univ.filter (fun i => blocks i = b)).card := by - simpa only [Finset.sum_boole, Nat.cast_id] using - (weightedHomogeneous_expansion c blocks (fun x => if x = b then 1 else 0)) - -/-- Changing a single assigned block changes the weight by exactly the -corresponding source/destination contribution. This form avoids truncated subtraction. -/ -theorem sum_weight_update (blocks : S → B) (w : B → ℕ) - (i : S) (b : B) : - (∑ j : S, w ((Function.update blocks i b) j)) + w (blocks i) = - (∑ j : S, w (blocks j)) + w b := by - classical - have h1 := Finset.sum_erase_add (s := Finset.univ) (f := fun j => w ((Function.update blocks i b) j)) (Finset.mem_univ i) - have h2 := Finset.sum_erase_add (s := Finset.univ) (f := fun j => w (blocks j)) (Finset.mem_univ i) - have h : (∑ j ∈ Finset.univ.erase i, w ((Function.update blocks i b) j)) = - ∑ j ∈ Finset.univ.erase i, w (blocks j) := by - apply Finset.sum_congr rfl - intro j hj - rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] - simp only [Function.update_self] at h1 - omega - -end Problem346.EncodingDegree - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346.EncodingDegree + +variable {R : Type*} [CommSemiring R] +variable {S K B : Type*} [Fintype S] [DecidableEq S] [Fintype K] + +/-- A coefficient expansion has weighted degree given by the sum of the weights +of its assigned vector blocks. The coefficients can be arbitrary. -/ +theorem weightedHomogeneous_expansion (c : (S → K) → R) (blocks : S → B) + (w : B → ℕ) : + MvPolynomial.IsWeightedHomogeneous (fun x : B × K => w x.1) + (∑ k : S → K, MvPolynomial.C (c k) * + ∏ i : S, MvPolynomial.X (blocks i, k i)) + (∑ i : S, w (blocks i)) := by + classical + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + apply MvPolynomial.IsWeightedHomogeneous.C_mul + apply MvPolynomial.IsWeightedHomogeneous.prod + intro i _ + exact MvPolynomial.isWeightedHomogeneous_X _ _ _ + +/-- The degree in one block is exactly the number of occurrences of that block. -/ +theorem blockHomogeneous_expansion [DecidableEq B] + (c : (S → K) → R) (blocks : S → B) (b : B) : + MvPolynomial.IsWeightedHomogeneous + (fun x : B × K => if x.1 = b then 1 else 0) + (∑ k : S → K, MvPolynomial.C (c k) * + ∏ i : S, MvPolynomial.X (blocks i, k i)) + (Finset.univ.filter (fun i => blocks i = b)).card := by + simpa only [Finset.sum_boole, Nat.cast_id] using + (weightedHomogeneous_expansion c blocks (fun x => if x = b then 1 else 0)) + +/-- Changing a single assigned block changes the weight by exactly the +corresponding source/destination contribution. This form avoids truncated subtraction. -/ +theorem sum_weight_update (blocks : S → B) (w : B → ℕ) + (i : S) (b : B) : + (∑ j : S, w ((Function.update blocks i b) j)) + w (blocks i) = + (∑ j : S, w (blocks j)) + w b := by + classical + have h1 := Finset.sum_erase_add (s := Finset.univ) (f := fun j => w ((Function.update blocks i b) j)) (Finset.mem_univ i) + have h2 := Finset.sum_erase_add (s := Finset.univ) (f := fun j => w (blocks j)) (Finset.mem_univ i) + have h : (∑ j ∈ Finset.univ.erase i, w ((Function.update blocks i b) j)) = + ∑ j ∈ Finset.univ.erase i, w (blocks j) := by + apply Finset.sum_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] + simp only [Function.update_self] at h1 + omega + +end Problem346.EncodingDegree + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FiniteDimension.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FiniteDimension.lean index 62a7a5a50fd46e1cf877b55e6a4495704031b918..a9e1cae105e19ad160240ba8f20858c2581f04ff 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FiniteDimension.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FiniteDimension.lean @@ -1,20 +1,20 @@ -import OAI.RepresentationTheory.FoulkesHowe.TensorPresentation - -namespace OAI - -noncomputable section -universe u - -namespace Problem346 - -/-- Every homogeneous symmetric power of a finite-dimensional complex space is -finite dimensional. The proof uses its tensor-power presentation. -/ -instance finiteDimensional_symPow (n : ℕ) (V : Type u) [AddCommGroup V] - [Module ℂ V] [FiniteDimensional ℂ V] : FiniteDimensional ℂ (SymPow n V) := - Module.Finite.of_surjective (tensorToSymPow n V) (tensorToSymPow_surjective n V) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.TensorPresentation + +namespace OAI + +noncomputable section +universe u + +namespace Problem346 + +/-- Every homogeneous symmetric power of a finite-dimensional complex space is +finite dimensional. The proof uses its tensor-power presentation. -/ +instance finiteDimensional_symPow (n : ℕ) (V : Type u) [AddCommGroup V] + [Module ℂ V] [FiniteDimensional ℂ V] : FiniteDimensional ℂ (SymPow n V) := + Module.Finite.of_surjective (tensorToSymPow n V) (tensorToSymPow_surjective n V) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstCounts.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstCounts.lean index 3a1af1626fd7b0ea1bd7839c938497c01876739c..ddd058c8797a6ccc2f863023281d42b06ae0f6d0 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstCounts.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstCounts.lean @@ -1,160 +1,160 @@ -import OAI.RepresentationTheory.FoulkesHowe.FirstLabels - -namespace OAI - -open scoped BigOperators - -namespace Problem346 - -@[simp] theorem firstLabel_zero (r m k : ℕ) (j : Fin (r + m)) : - firstLabel r m k (0, j) = - if h : j.val < k ∧ j.val < m then some (some ⟨j.val, h.2⟩) else some none := by - simp [firstLabel] - -@[simp] theorem firstLabel_succ (r m k : ℕ) (i : Fin r) (j : Fin (r + m)) : - firstLabel r m k (i.succ, j) = - Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j := by - simp [firstLabel] - -@[simp] theorem firstLabel_zero_ne_x (r m k : ℕ) (j : Fin (r + m)) : - firstLabel r m k (0, j) ≠ none := by - simp only [firstLabel_zero] - split <;> simp - -theorem firstLabel_zero_eq_t_iff (r m k : ℕ) (hk : k ≤ m) (j : Fin (r + m)) : - firstLabel r m k (0, j) = some none ↔ k ≤ j.val := by - simp only [firstLabel_zero] - split <;> simp_all - omega - -theorem firstLabel_zero_eq_y_iff (r m k : ℕ) (_hk : k ≤ m) - (j : Fin (r + m)) (y : Fin m) : - firstLabel r m k (0, j) = some (some y) ↔ j.val = y.val ∧ y.val < k := by - simp only [firstLabel_zero] - split - · simp only [Option.some.injEq, Fin.ext_iff] - rename_i h - constructor - · intro h' - exact ⟨h', h' ▸ h.1⟩ - · exact fun h' => h'.1 - · rename_i h - simp only [Option.some.injEq, reduceCtorEq, false_iff] - omega - -/-- Number of individual factors labelled by a given vector block. -/ -def firstLabelCount (r m k : ℕ) (c : FirstBlock m) : ℕ := - ∑ p : Fin (r + 1) × Fin (r + m), if firstLabel r m k p = c then 1 else 0 - - -theorem firstLabelCount_x (r m k : ℕ) : firstLabelCount r m k none = r * r := by - classical - simp only [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ, - firstLabel_zero_ne_x, ite_false, Finset.sum_const_zero, zero_add, firstLabel_succ] - have hrow : (∑ j : Fin (r + m), - if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = - (none : FirstBlock m) then 1 else 0) = r := by - rw [Fin.sum_univ_add] - simp - simp only [hrow, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Nat.cast_id] - - theorem firstLabelCount_t (r m k : ℕ) (hk : k ≤ m) : - firstLabelCount r m k (some none) = r + m - k := by - classical - rw [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ] - have hrow : (∑ j : Fin (r + m), - if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = - (some none : FirstBlock m) then 1 else 0) = 0 := by - rw [Fin.sum_univ_add] - simp - simp only [firstLabel_succ, hrow, Finset.sum_const_zero, add_zero, - firstLabel_zero_eq_t_iff r m k hk] - rw [← Finset.card_filter] - have hc := Finset.card_filter_add_card_filter_not - (s := (Finset.univ : Finset (Fin (r + m)))) (fun j => j.val < k) - rw [Fin.card_filter_val_lt, Nat.min_eq_right (by omega)] at hc - simp only [not_lt, Finset.card_univ, Fintype.card_fin] at hc - omega - - -theorem firstLabelCount_y (r m k : ℕ) (hk : k ≤ m) (y : Fin m) : - firstLabelCount r m k (some (some y)) = r + if y.val < k then 1 else 0 := by - classical - rw [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ] - have hrow : (∑ j : Fin (r + m), - if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = - (some (some y) : FirstBlock m) then 1 else 0) = 1 := by - rw [Fin.sum_univ_add] - simp - simp only [firstLabel_succ, hrow, Finset.sum_const, Finset.card_univ, - Fintype.card_fin, smul_eq_mul, mul_one] - let y' : Fin (r + m) := ⟨y.val, by omega⟩ - have hj : ∀ j : Fin (r + m), j.val = y.val ↔ j = y' := by - intro j - change j.val = y'.val ↔ j = y' - exact Fin.ext_iff.symm - simp only [firstLabel_zero_eq_y_iff r m k hk, hj] - by_cases hy : y.val < k <;> simp [hy, add_comm] - - -theorem firstLabel_step (r m k : ℕ) (hk : k < m) : - firstLabel r m (k + 1) = Function.update (firstLabel r m k) - (0, ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩) (some (some ⟨k, hk⟩)) := by - classical - funext p - rcases p with ⟨i, j⟩ - by_cases hi : i = 0 - · subst i - by_cases hj : j.val = k - · have hjeq : j = (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m)) := Fin.ext hj - rw [hjeq] - simp [firstLabel, hk] - · have hp : ((0 : Fin (r + 1)), j) ≠ (0, (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m))) := by - intro h - exact hj (congrArg (fun p : Fin (r + 1) × Fin (r + m) => p.2.val) h) - rw [Function.update_of_ne hp] - have hlt : j.val < k + 1 ↔ j.val < k := by omega - simp only [firstLabel_zero, hlt] - · have hp : (i, j) ≠ (0, (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m))) := by - intro h - exact hi (congrArg Prod.fst h) - rw [Function.update_of_ne hp] - simp [firstLabel, hi] - - -/-- The sum-of-indicators count agrees with the cardinality used by polynomial -block-degree statements. -/ -theorem firstLabel_card (r m k : ℕ) (c : FirstBlock m) : - (Finset.univ.filter (fun p => firstLabel r m k p = c)).card = - firstLabelCount r m k c := by - classical - exact Finset.card_filter _ _ - -theorem firstLabel_card_t (r m k : ℕ) (hk : k ≤ m) : - (Finset.univ.filter (fun p => firstLabel r m k p = some none)).card = r + m - k := by - rw [firstLabel_card, firstLabelCount_t r m k hk] - -theorem firstLabel_card_y (r m k : ℕ) (hk : k ≤ m) (y : Fin m) : - (Finset.univ.filter (fun p => firstLabel r m k p = some (some y))).card = - r + if y.val < k then 1 else 0 := by - rw [firstLabel_card, firstLabelCount_y r m k hk] - -theorem firstLabel_card_y_next (r m k : ℕ) (hk : k < m) : - (Finset.univ.filter (fun p => firstLabel r m k p = some (some ⟨k, hk⟩))).card = r := by - rw [firstLabel_card_y r m k (Nat.le_of_lt hk)] - simp - -/-- Only unreplaced positions of the distinguished row carry the source label. -/ -theorem firstLabel_eq_t_iff (r m k : ℕ) (hk : k ≤ m) - (p : Fin (r + 1) × Fin (r + m)) : - firstLabel r m k p = some none ↔ p.1 = 0 ∧ k ≤ p.2.val := by - rcases p with ⟨i, j⟩ - by_cases hi : i = 0 - · subst i - simpa using firstLabel_zero_eq_t_iff r m k hk j - · simp only [firstLabel, hi, ite_false, false_and, iff_false] - refine Fin.addCases (fun x => ?_) (fun y => ?_) j <;> simp - -end Problem346 - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FirstLabels + +namespace OAI + +open scoped BigOperators + +namespace Problem346 + +@[simp] theorem firstLabel_zero (r m k : ℕ) (j : Fin (r + m)) : + firstLabel r m k (0, j) = + if h : j.val < k ∧ j.val < m then some (some ⟨j.val, h.2⟩) else some none := by + simp [firstLabel] + +@[simp] theorem firstLabel_succ (r m k : ℕ) (i : Fin r) (j : Fin (r + m)) : + firstLabel r m k (i.succ, j) = + Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j := by + simp [firstLabel] + +@[simp] theorem firstLabel_zero_ne_x (r m k : ℕ) (j : Fin (r + m)) : + firstLabel r m k (0, j) ≠ none := by + simp only [firstLabel_zero] + split <;> simp + +theorem firstLabel_zero_eq_t_iff (r m k : ℕ) (hk : k ≤ m) (j : Fin (r + m)) : + firstLabel r m k (0, j) = some none ↔ k ≤ j.val := by + simp only [firstLabel_zero] + split <;> simp_all + omega + +theorem firstLabel_zero_eq_y_iff (r m k : ℕ) (_hk : k ≤ m) + (j : Fin (r + m)) (y : Fin m) : + firstLabel r m k (0, j) = some (some y) ↔ j.val = y.val ∧ y.val < k := by + simp only [firstLabel_zero] + split + · simp only [Option.some.injEq, Fin.ext_iff] + rename_i h + constructor + · intro h' + exact ⟨h', h' ▸ h.1⟩ + · exact fun h' => h'.1 + · rename_i h + simp only [Option.some.injEq, reduceCtorEq, false_iff] + omega + +/-- Number of individual factors labelled by a given vector block. -/ +def firstLabelCount (r m k : ℕ) (c : FirstBlock m) : ℕ := + ∑ p : Fin (r + 1) × Fin (r + m), if firstLabel r m k p = c then 1 else 0 + + +theorem firstLabelCount_x (r m k : ℕ) : firstLabelCount r m k none = r * r := by + classical + simp only [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ, + firstLabel_zero_ne_x, ite_false, Finset.sum_const_zero, zero_add, firstLabel_succ] + have hrow : (∑ j : Fin (r + m), + if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = + (none : FirstBlock m) then 1 else 0) = r := by + rw [Fin.sum_univ_add] + simp + simp only [hrow, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Nat.cast_id] + + theorem firstLabelCount_t (r m k : ℕ) (hk : k ≤ m) : + firstLabelCount r m k (some none) = r + m - k := by + classical + rw [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ] + have hrow : (∑ j : Fin (r + m), + if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = + (some none : FirstBlock m) then 1 else 0) = 0 := by + rw [Fin.sum_univ_add] + simp + simp only [firstLabel_succ, hrow, Finset.sum_const_zero, add_zero, + firstLabel_zero_eq_t_iff r m k hk] + rw [← Finset.card_filter] + have hc := Finset.card_filter_add_card_filter_not + (s := (Finset.univ : Finset (Fin (r + m)))) (fun j => j.val < k) + rw [Fin.card_filter_val_lt, Nat.min_eq_right (by omega)] at hc + simp only [not_lt, Finset.card_univ, Fintype.card_fin] at hc + omega + + +theorem firstLabelCount_y (r m k : ℕ) (hk : k ≤ m) (y : Fin m) : + firstLabelCount r m k (some (some y)) = r + if y.val < k then 1 else 0 := by + classical + rw [firstLabelCount, Fintype.sum_prod_type, Fin.sum_univ_succ] + have hrow : (∑ j : Fin (r + m), + if Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j = + (some (some y) : FirstBlock m) then 1 else 0) = 1 := by + rw [Fin.sum_univ_add] + simp + simp only [firstLabel_succ, hrow, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, smul_eq_mul, mul_one] + let y' : Fin (r + m) := ⟨y.val, by omega⟩ + have hj : ∀ j : Fin (r + m), j.val = y.val ↔ j = y' := by + intro j + change j.val = y'.val ↔ j = y' + exact Fin.ext_iff.symm + simp only [firstLabel_zero_eq_y_iff r m k hk, hj] + by_cases hy : y.val < k <;> simp [hy, add_comm] + + +theorem firstLabel_step (r m k : ℕ) (hk : k < m) : + firstLabel r m (k + 1) = Function.update (firstLabel r m k) + (0, ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩) (some (some ⟨k, hk⟩)) := by + classical + funext p + rcases p with ⟨i, j⟩ + by_cases hi : i = 0 + · subst i + by_cases hj : j.val = k + · have hjeq : j = (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m)) := Fin.ext hj + rw [hjeq] + simp [firstLabel, hk] + · have hp : ((0 : Fin (r + 1)), j) ≠ (0, (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m))) := by + intro h + exact hj (congrArg (fun p : Fin (r + 1) × Fin (r + m) => p.2.val) h) + rw [Function.update_of_ne hp] + have hlt : j.val < k + 1 ↔ j.val < k := by omega + simp only [firstLabel_zero, hlt] + · have hp : (i, j) ≠ (0, (⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ : Fin (r + m))) := by + intro h + exact hi (congrArg Prod.fst h) + rw [Function.update_of_ne hp] + simp [firstLabel, hi] + + +/-- The sum-of-indicators count agrees with the cardinality used by polynomial +block-degree statements. -/ +theorem firstLabel_card (r m k : ℕ) (c : FirstBlock m) : + (Finset.univ.filter (fun p => firstLabel r m k p = c)).card = + firstLabelCount r m k c := by + classical + exact Finset.card_filter _ _ + +theorem firstLabel_card_t (r m k : ℕ) (hk : k ≤ m) : + (Finset.univ.filter (fun p => firstLabel r m k p = some none)).card = r + m - k := by + rw [firstLabel_card, firstLabelCount_t r m k hk] + +theorem firstLabel_card_y (r m k : ℕ) (hk : k ≤ m) (y : Fin m) : + (Finset.univ.filter (fun p => firstLabel r m k p = some (some y))).card = + r + if y.val < k then 1 else 0 := by + rw [firstLabel_card, firstLabelCount_y r m k hk] + +theorem firstLabel_card_y_next (r m k : ℕ) (hk : k < m) : + (Finset.univ.filter (fun p => firstLabel r m k p = some (some ⟨k, hk⟩))).card = r := by + rw [firstLabel_card_y r m k (Nat.le_of_lt hk)] + simp + +/-- Only unreplaced positions of the distinguished row carry the source label. -/ +theorem firstLabel_eq_t_iff (r m k : ℕ) (hk : k ≤ m) + (p : Fin (r + 1) × Fin (r + m)) : + firstLabel r m k p = some none ↔ p.1 = 0 ∧ k ≤ p.2.val := by + rcases p with ⟨i, j⟩ + by_cases hi : i = 0 + · subst i + simpa using firstLabel_zero_eq_t_iff r m k hk j + · simp only [firstLabel, hi, ite_false, false_and, iff_false] + refine Fin.addCases (fun x => ?_) (fun y => ?_) j <;> simp + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstLabels.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstLabels.lean index f35011ab3dd59ef3ee3909c7729ffd5f5da69682..8924c13ef524852c4102925fa446ae0859c00914 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstLabels.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstLabels.lean @@ -1,34 +1,34 @@ -import Mathlib - -namespace OAI - -namespace Problem346 - -/-- Blocks for the first transfer: `none` is x, `some none` is t, -and `some (some j)` is the j-th common product factor. -/ -abbrev FirstBlock (m : ℕ) := Option (Option (Fin m)) - -/-- The slot labels after transferring the first k factors out of the t block. -/ -def firstLabel (r m k : ℕ) (p : Fin (r+1) × Fin (r+m)) : FirstBlock m := - if p.1 = 0 then - if h : p.2.val < k ∧ p.2.val < m then some (some ⟨p.2.val, h.2⟩) - else some none - else Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) p.2 - -@[simp] theorem firstLabel_zero_row (r m k : ℕ) (j : Fin (r+m)) : - firstLabel r m k (0,j) = - if h : j.val < k ∧ j.val < m then some (some ⟨j.val,h.2⟩) else some none := by - simp [firstLabel] - -@[simp] theorem firstLabel_succ_row (r m k : ℕ) (i : Fin r) (j : Fin (r+m)) : - firstLabel r m k (i.succ,j) = - Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j := by - simp [firstLabel] - -@[simp] theorem firstLabel_initial_zero_row (r m : ℕ) (j : Fin (r+m)) : - firstLabel r m 0 (0,j) = some none := by - simp - -end Problem346 - -end OAI +import Mathlib + +namespace OAI + +namespace Problem346 + +/-- Blocks for the first transfer: `none` is x, `some none` is t, +and `some (some j)` is the j-th common product factor. -/ +abbrev FirstBlock (m : ℕ) := Option (Option (Fin m)) + +/-- The slot labels after transferring the first k factors out of the t block. -/ +def firstLabel (r m k : ℕ) (p : Fin (r+1) × Fin (r+m)) : FirstBlock m := + if p.1 = 0 then + if h : p.2.val < k ∧ p.2.val < m then some (some ⟨p.2.val, h.2⟩) + else some none + else Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) p.2 + +@[simp] theorem firstLabel_zero_row (r m k : ℕ) (j : Fin (r+m)) : + firstLabel r m k (0,j) = + if h : j.val < k ∧ j.val < m then some (some ⟨j.val,h.2⟩) else some none := by + simp [firstLabel] + +@[simp] theorem firstLabel_succ_row (r m k : ℕ) (i : Fin r) (j : Fin (r+m)) : + firstLabel r m k (i.succ,j) = + Fin.addCases (fun _ : Fin r => none) (fun j : Fin m => some (some j)) j := by + simp [firstLabel] + +@[simp] theorem firstLabel_initial_zero_row (r m : ℕ) (j : Fin (r+m)) : + firstLabel r m 0 (0,j) = some none := by + simp + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstPolynomial.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstPolynomial.lean index 9a2dd697ae41c48b5bbd48882a18b828ad898c1e..805e28ca1d568ff4b07149b9eebe9d3065b277da 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstPolynomial.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstPolynomial.lean @@ -1,39 +1,39 @@ -import OAI.RepresentationTheory.FoulkesHowe.FirstLabels -import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm -import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial -import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous -import OAI.RepresentationTheory.FoulkesHowe.BlockWeight - -namespace OAI - -noncomputable section -open scoped BigOperators -namespace Problem346 -universe u v -variable {V : Type u} [AddCommGroup V] [Module ℂ V] -variable {κ : Type v} [Fintype κ] - -/-- The scalar polynomial at the k-th stage of the first transfer sequence. -/ -def firstPolynomial {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) (k : ℕ) : - MvPolynomial (FirstBlock m × κ) ℂ := - multilinearPolynomial (flattenedForm T) e (firstLabel r m k) - -/-- Direct block degrees of every intermediate polynomial, by counting its labels. -/ -theorem firstPolynomial_blockHomogeneous {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) - (k : ℕ) (u : FirstBlock m) : - PolynomialWeights.IsBlockHomogeneous u (firstPolynomial T e k) - (Finset.univ.filter (fun p => firstLabel r m k p = u)).card := by - classical - let : DecidableEq (Fin (r+1) × Fin (r+m)) := Classical.decEq _ - unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight - simpa only [firstPolynomial, multilinearPolynomial] using - (EncodingDegree.blockHomogeneous_expansion - (fun z => flattenedForm T (fun p => e (z p))) (firstLabel r m k) u) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FirstLabels +import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm +import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial +import OAI.RepresentationTheory.FoulkesHowe.EncodingHomogeneous +import OAI.RepresentationTheory.FoulkesHowe.BlockWeight + +namespace OAI + +noncomputable section +open scoped BigOperators +namespace Problem346 +universe u v +variable {V : Type u} [AddCommGroup V] [Module ℂ V] +variable {κ : Type v} [Fintype κ] + +/-- The scalar polynomial at the k-th stage of the first transfer sequence. -/ +def firstPolynomial {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) (k : ℕ) : + MvPolynomial (FirstBlock m × κ) ℂ := + multilinearPolynomial (flattenedForm T) e (firstLabel r m k) + +/-- Direct block degrees of every intermediate polynomial, by counting its labels. -/ +theorem firstPolynomial_blockHomogeneous {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) + (k : ℕ) (u : FirstBlock m) : + PolynomialWeights.IsBlockHomogeneous u (firstPolynomial T e k) + (Finset.univ.filter (fun p => firstLabel r m k p = u)).card := by + classical + let : DecidableEq (Fin (r+1) × Fin (r+m)) := Classical.decEq _ + unfold PolynomialWeights.IsBlockHomogeneous PolynomialWeights.blockWeight + simpa only [firstPolynomial, multilinearPolynomial] using + (EncodingDegree.blockHomogeneous_expansion + (fun z => flattenedForm T (fun p => e (z p))) (firstLabel r m k) u) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstTransfer.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstTransfer.lean index 80947af41fd137b6e218cfe2bf04457f4c3eaba6..03d091a3b866ea35c26fba438b1efa936684a40f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FirstTransfer.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FirstTransfer.lean @@ -1,76 +1,76 @@ -import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial -import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity -import OAI.RepresentationTheory.FoulkesHowe.BackwardCancellation -import OAI.RepresentationTheory.FoulkesHowe.TransferDerivative -import OAI.RepresentationTheory.FoulkesHowe.TransferEndpoints - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u v -variable {V : Type u} [AddCommGroup V] [Module ℂ V] -variable {κ : Type v} [Fintype κ] - -/-- Cancel the first transfer sequence from its zero endpoint. The homogeneous -and derivative identities are kept separate from this zero-reflection argument. -/ -theorem firstPolynomial_zero_of_chain {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) - (ht : ∀ k < m, PolynomialWeights.IsBlockHomogeneous (some none) - (firstPolynomial T e k) (r+m-k)) - (hy : ∀ (k : ℕ) (hk : k < m), PolynomialWeights.IsBlockHomogeneous - (some (some (⟨k,hk⟩ : Fin m))) (firstPolynomial T e k) r) - (hD : ∀ (k : ℕ) (hk : k < m), - PolynomialShift.shift (some none) (some (some (⟨k,hk⟩ : Fin m))) - (firstPolynomial T e k) = ((r+m-k : ℕ) : ℂ) • firstPolynomial T e (k+1)) - (hm : firstPolynomial T e m = 0) : firstPolynomial T e 0 = 0 := by - classical - apply eq_zero_of_backward_chain (firstPolynomial T e) m _ hm - intro k hk hz - apply PolynomialShift.eq_zero_of_shift_eq_zero - (some none) (some (some (⟨k,hk⟩ : Fin m))) (by simp) - (show r < r+m-k by omega) (ht k hk) (hy k hk) - rw [hD k hk, hz, smul_zero] - -/-- Every terminal-zero polynomial in the concrete first-transfer family is zero -at the initial stage. All degree counts and derivative identities are discharged. -/ -theorem firstPolynomial_zero_of_final {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) - (hm : firstPolynomial T e m = 0) : firstPolynomial T e 0 = 0 := by - classical - apply firstPolynomial_zero_of_chain T e _ _ _ hm - · intro k hk - simpa only [firstLabel_card_t r m k (Nat.le_of_lt hk)] using - firstPolynomial_blockHomogeneous T e k (some none) - · intro k hk - simpa only [firstLabel_card_y_next r m k hk] using - firstPolynomial_blockHomogeneous T e k (some (some (⟨k,hk⟩ : Fin m))) - · intro k hk - simpa only [firstPolynomial, PolynomialShift.shift_apply] using - (firstLabel_derivative r m k hk V κ T e - (PolynomialShift.derivation (some none) (some (some (⟨k,hk⟩ : Fin m)))) - (fun q j => by simp)) - -/-- The first transfer in the stabilization argument: the common product can be -removed from the distinguished argument, while the other arguments remain fixed. -No outer symmetry or positive-degree assumptions are needed for this step. -/ -theorem first_transfer [FiniteDimensional ℂ V] {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (h : ∀ (x t : V) (y : Fin m → V), - T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0) : - ∀ (x t : V) (y : Fin m → V), - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by - let e := Module.finBasis ℂ V - have hm := firstPolynomial_final_eq_zero T e h - have hzero := firstPolynomial_zero_of_final T e hm - exact firstPolynomial_initial_vanishing T e hzero - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial +import OAI.RepresentationTheory.FoulkesHowe.BlockInjectivity +import OAI.RepresentationTheory.FoulkesHowe.BackwardCancellation +import OAI.RepresentationTheory.FoulkesHowe.TransferDerivative +import OAI.RepresentationTheory.FoulkesHowe.TransferEndpoints + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u v +variable {V : Type u} [AddCommGroup V] [Module ℂ V] +variable {κ : Type v} [Fintype κ] + +/-- Cancel the first transfer sequence from its zero endpoint. The homogeneous +and derivative identities are kept separate from this zero-reflection argument. -/ +theorem firstPolynomial_zero_of_chain {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) + (ht : ∀ k < m, PolynomialWeights.IsBlockHomogeneous (some none) + (firstPolynomial T e k) (r+m-k)) + (hy : ∀ (k : ℕ) (hk : k < m), PolynomialWeights.IsBlockHomogeneous + (some (some (⟨k,hk⟩ : Fin m))) (firstPolynomial T e k) r) + (hD : ∀ (k : ℕ) (hk : k < m), + PolynomialShift.shift (some none) (some (some (⟨k,hk⟩ : Fin m))) + (firstPolynomial T e k) = ((r+m-k : ℕ) : ℂ) • firstPolynomial T e (k+1)) + (hm : firstPolynomial T e m = 0) : firstPolynomial T e 0 = 0 := by + classical + apply eq_zero_of_backward_chain (firstPolynomial T e) m _ hm + intro k hk hz + apply PolynomialShift.eq_zero_of_shift_eq_zero + (some none) (some (some (⟨k,hk⟩ : Fin m))) (by simp) + (show r < r+m-k by omega) (ht k hk) (hy k hk) + rw [hD k hk, hz, smul_zero] + +/-- Every terminal-zero polynomial in the concrete first-transfer family is zero +at the initial stage. All degree counts and derivative identities are discharged. -/ +theorem firstPolynomial_zero_of_final {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) + (hm : firstPolynomial T e m = 0) : firstPolynomial T e 0 = 0 := by + classical + apply firstPolynomial_zero_of_chain T e _ _ _ hm + · intro k hk + simpa only [firstLabel_card_t r m k (Nat.le_of_lt hk)] using + firstPolynomial_blockHomogeneous T e k (some none) + · intro k hk + simpa only [firstLabel_card_y_next r m k hk] using + firstPolynomial_blockHomogeneous T e k (some (some (⟨k,hk⟩ : Fin m))) + · intro k hk + simpa only [firstPolynomial, PolynomialShift.shift_apply] using + (firstLabel_derivative r m k hk V κ T e + (PolynomialShift.derivation (some none) (some (some (⟨k,hk⟩ : Fin m)))) + (fun q j => by simp)) + +/-- The first transfer in the stabilization argument: the common product can be +removed from the distinguished argument, while the other arguments remain fixed. +No outer symmetry or positive-degree assumptions are needed for this step. -/ +theorem first_transfer [FiniteDimensional ℂ V] {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (h : ∀ (x t : V) (y : Fin m → V), + T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0) : + ∀ (x t : V) (y : Fin m → V), + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by + let e := Module.finBasis ℂ V + have hm := firstPolynomial_final_eq_zero T e h + have hzero := firstPolynomial_zero_of_final T e hm + exact firstPolynomial_initial_vanishing T e hzero + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FixedSlot.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FixedSlot.lean index d8809a17eded4f52a1f3a7d88f047e5593bc198c..e68953572f18c12addede3006634c3465a43c0f1 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FixedSlot.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FixedSlot.lean @@ -1,74 +1,74 @@ -import OAI.RepresentationTheory.FoulkesHowe.FlattenedSwap -import OAI.RepresentationTheory.FoulkesHowe.Multiplication - -namespace OAI - -noncomputable section -namespace Problem346 -universe u -variable {r b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Flatten the remaining rows after fixing the first slot to a pure power. -/ -def fixedSlotFlatten (T : SymmetricMultilinearForm (r+1) b V) (t : V) : - MultilinearMap ℂ (fun _ : Fin r × Fin b => V) ℂ := - flattenedSymmetricForm (T.curryLeft (symMonomial b V (fun _ => t))) - -@[simp] theorem fixedSlotFlatten_apply - (T : SymmetricMultilinearForm (r+1) b V) (t : V) (v : Fin r × Fin b → V) : - fixedSlotFlatten T t v = - T (Fin.cons (symMonomial b V (fun _ => t)) - (fun i => symMonomial b V (fun j => v (i,j)))) := rfl - -/-- Every row remains symmetric in its factors after fixing the first slot. -/ -theorem fixedSlotFlatten_inner_permute - (T : SymmetricMultilinearForm (r+1) b V) (t : V) - (σ : Fin r → Equiv.Perm (Fin b)) (v : Fin r × Fin b → V) : - fixedSlotFlatten T t (fun p => v (p.1, σ p.1 p.2)) = fixedSlotFlatten T t v := - flattenedSymmetricForm_inner_permute _ σ v - -/-- Repeated vectors in the remaining rows are literal pure powers. -/ -@[simp] theorem fixedSlotFlatten_constant_rows - (T : SymmetricMultilinearForm (r+1) b V) (t : V) (v : Fin r → V) : - fixedSlotFlatten T t (fun p => v p.1) = - T (Fin.cons (symMonomial b V (fun _ => t)) - (fun i => symMonomial b V (fun _ => v i))) := rfl - -/-- Concatenating factors in every unfixed row computes graded multiplication. -/ -theorem fixedSlotFlatten_append {m n : ℕ} - (T : SymmetricMultilinearForm (r+1) (m+n) V) (t : V) - (v : Fin r → Fin m → V) (w : Fin r → Fin n → V) : - fixedSlotFlatten T t (fun p => Fin.append (v p.1) (w p.1) p.2) = - T (Fin.cons (symMonomial (m+n) V (fun _ => t)) - (fun i => symPowMul m n (symMonomial m V (v i)) (symMonomial n V (w i)))) := by - simp only [fixedSlotFlatten_apply, symPowMul_symMonomial] - -/-- The endpoint of the second shift chain has a common power factor in every row. -/ -theorem fixedSlotFlatten_common_power {m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (v : Fin r → V) : - fixedSlotFlatten T t - (fun p => Fin.append (fun _ : Fin r => x) (fun _ : Fin m => v p.1) p.2) = - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) - (symMonomial m V (fun _ => v i)))) := by - simp only [fixedSlotFlatten_apply, symPowMul_symMonomial] - -/-- Swapping two factor slots in the same unfixed row changes no value. -/ -theorem fixedSlotFlatten_swap_same_row - (T : SymmetricMultilinearForm (r+1) b V) (t : V) - (p q : Fin r × Fin b) (hpq : p.1=q.1) (v : Fin r × Fin b → V) : - fixedSlotFlatten T t (v ∘ Equiv.swap p q) = fixedSlotFlatten T t v := - flattenedSymmetricForm_swap_same_row - (T.curryLeft (symMonomial b V (fun _ => t))) p q hpq v - -/-- The fixed-slot coefficient array meets the row-swap hypothesis of shift recurrence. -/ -theorem fixedSlotFlatten_coeff_swap_same_row {I : Type*} - (T : SymmetricMultilinearForm (r+1) b V) (t : V) (e : I → V) - (p q : Fin r × Fin b) (hpq : p.1=q.1) (k : Fin r × Fin b → I) : - fixedSlotFlatten T t (e ∘ (k ∘ Equiv.swap p q)) = fixedSlotFlatten T t (e ∘ k) := - fixedSlotFlatten_swap_same_row T t p q hpq (e ∘ k) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FlattenedSwap +import OAI.RepresentationTheory.FoulkesHowe.Multiplication + +namespace OAI + +noncomputable section +namespace Problem346 +universe u +variable {r b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Flatten the remaining rows after fixing the first slot to a pure power. -/ +def fixedSlotFlatten (T : SymmetricMultilinearForm (r+1) b V) (t : V) : + MultilinearMap ℂ (fun _ : Fin r × Fin b => V) ℂ := + flattenedSymmetricForm (T.curryLeft (symMonomial b V (fun _ => t))) + +@[simp] theorem fixedSlotFlatten_apply + (T : SymmetricMultilinearForm (r+1) b V) (t : V) (v : Fin r × Fin b → V) : + fixedSlotFlatten T t v = + T (Fin.cons (symMonomial b V (fun _ => t)) + (fun i => symMonomial b V (fun j => v (i,j)))) := rfl + +/-- Every row remains symmetric in its factors after fixing the first slot. -/ +theorem fixedSlotFlatten_inner_permute + (T : SymmetricMultilinearForm (r+1) b V) (t : V) + (σ : Fin r → Equiv.Perm (Fin b)) (v : Fin r × Fin b → V) : + fixedSlotFlatten T t (fun p => v (p.1, σ p.1 p.2)) = fixedSlotFlatten T t v := + flattenedSymmetricForm_inner_permute _ σ v + +/-- Repeated vectors in the remaining rows are literal pure powers. -/ +@[simp] theorem fixedSlotFlatten_constant_rows + (T : SymmetricMultilinearForm (r+1) b V) (t : V) (v : Fin r → V) : + fixedSlotFlatten T t (fun p => v p.1) = + T (Fin.cons (symMonomial b V (fun _ => t)) + (fun i => symMonomial b V (fun _ => v i))) := rfl + +/-- Concatenating factors in every unfixed row computes graded multiplication. -/ +theorem fixedSlotFlatten_append {m n : ℕ} + (T : SymmetricMultilinearForm (r+1) (m+n) V) (t : V) + (v : Fin r → Fin m → V) (w : Fin r → Fin n → V) : + fixedSlotFlatten T t (fun p => Fin.append (v p.1) (w p.1) p.2) = + T (Fin.cons (symMonomial (m+n) V (fun _ => t)) + (fun i => symPowMul m n (symMonomial m V (v i)) (symMonomial n V (w i)))) := by + simp only [fixedSlotFlatten_apply, symPowMul_symMonomial] + +/-- The endpoint of the second shift chain has a common power factor in every row. -/ +theorem fixedSlotFlatten_common_power {m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (v : Fin r → V) : + fixedSlotFlatten T t + (fun p => Fin.append (fun _ : Fin r => x) (fun _ : Fin m => v p.1) p.2) = + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) + (symMonomial m V (fun _ => v i)))) := by + simp only [fixedSlotFlatten_apply, symPowMul_symMonomial] + +/-- Swapping two factor slots in the same unfixed row changes no value. -/ +theorem fixedSlotFlatten_swap_same_row + (T : SymmetricMultilinearForm (r+1) b V) (t : V) + (p q : Fin r × Fin b) (hpq : p.1=q.1) (v : Fin r × Fin b → V) : + fixedSlotFlatten T t (v ∘ Equiv.swap p q) = fixedSlotFlatten T t v := + flattenedSymmetricForm_swap_same_row + (T.curryLeft (symMonomial b V (fun _ => t))) p q hpq v + +/-- The fixed-slot coefficient array meets the row-swap hypothesis of shift recurrence. -/ +theorem fixedSlotFlatten_coeff_swap_same_row {I : Type*} + (T : SymmetricMultilinearForm (r+1) b V) (t : V) (e : I → V) + (p q : Fin r × Fin b) (hpq : p.1=q.1) (k : Fin r × Fin b → I) : + fixedSlotFlatten T t (e ∘ (k ∘ Equiv.swap p q)) = fixedSlotFlatten T t (e ∘ k) := + fixedSlotFlatten_swap_same_row T t p q hpq (e ∘ k) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedForm.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedForm.lean index 855d740171ecf08df5fbbb177896b562bd41b066..7b3b24a3755b347963591b0b367f4a177eaaf4f2 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedForm.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedForm.lean @@ -1,109 +1,109 @@ -import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u - -variable {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- A form on symmetric powers, evaluated on products, is multilinear in all -of the underlying vector factors. -/ -def flattenedSymmetricForm (T : SymmetricMultilinearForm a b V) : - MultilinearMap ℂ (fun _ : Fin a × Fin b => V) ℂ := - (T.compMultilinearMap (fun _ => symMonomialMultilinear b V)).domDomCongr - (Equiv.sigmaEquivProd (Fin a) (Fin b)) - -@[simp] -theorem flattenedSymmetricForm_apply (T : SymmetricMultilinearForm a b V) - (v : Fin a × Fin b → V) : - flattenedSymmetricForm T v = - T (fun i => symMonomial b V (fun j => v (i, j))) := rfl - -/-- Independent permutations within the rows preserve the flattened form. -/ -theorem flattenedSymmetricForm_inner_permute - (T : SymmetricMultilinearForm a b V) - (σ : Fin a → Equiv.Perm (Fin b)) (v : Fin a × Fin b → V) : - flattenedSymmetricForm T (fun p => v (p.1, σ p.1 p.2)) = - flattenedSymmetricForm T v := by - apply congrArg T - funext i - exact symMonomial_permute b V (σ i) (fun j => v (i, j)) - -/-- Symmetry of the original form permits permutation of the rows. -/ -theorem flattenedSymmetricForm_outer_permute - (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) - (σ : Equiv.Perm (Fin a)) (v : Fin a × Fin b → V) : - flattenedSymmetricForm T (fun p => v (σ p.1, p.2)) = - flattenedSymmetricForm T v := by - exact hT σ (fun i => symMonomial b V (fun j => v (i, j))) - -/-- Compatibility API for the same flattened form, with inferred degrees. -/ -abbrev flattenedForm {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] - (T : SymmetricMultilinearForm a b V) : - MultilinearMap ℂ (fun _ : Fin a × Fin b => V) ℂ := - flattenedSymmetricForm T - -@[simp] -theorem flattenedForm_apply {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] - (T : SymmetricMultilinearForm a b V) (x : Fin a × Fin b → V) : - flattenedForm T x = T (fun i => symMonomial b V (fun j => x (i, j))) := rfl - -theorem flattenedForm_permute_factors (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (σ : Fin a → Equiv.Perm (Fin b)) (x : Fin a × Fin b → V) : - flattenedForm T (fun p => x (p.1, σ p.1 p.2)) = - flattenedForm T x := - flattenedSymmetricForm_inner_permute T σ x - -theorem flattenedForm_permute_slots (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) - (σ : Equiv.Perm (Fin a)) (x : Fin a × Fin b → V) : - flattenedForm T (fun p => x (σ p.1, p.2)) = - flattenedForm T x := - flattenedSymmetricForm_outer_permute T hT σ x - -/-- Simultaneous row and independent within-row permutation invariance. -/ -theorem flattenedForm_permute (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) - (σ : Equiv.Perm (Fin a)) (τ : Fin a → Equiv.Perm (Fin b)) - (x : Fin a × Fin b → V) : - flattenedForm T (fun p => x (σ p.1, τ p.1 p.2)) = - flattenedForm T x := - (flattenedForm_permute_factors a b V T τ (fun p => x (σ p.1, p.2))).trans - (flattenedForm_permute_slots a b V T hT σ x) - -/-- Implicit-parameter factor symmetry used by the transfer sequences. -/ -theorem flattenedForm_factor_perm (T : SymmetricMultilinearForm a b V) - (σ : Fin a → Equiv.Perm (Fin b)) (v : Fin a × Fin b → V) : - flattenedForm T (fun p => v (p.1, σ p.1 p.2)) = flattenedForm T v := - flattenedSymmetricForm_inner_permute T σ v - -/-- Implicit-parameter row symmetry used by the transfer sequences. -/ -theorem flattenedForm_row_perm (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) (σ : Equiv.Perm (Fin a)) - (v : Fin a × Fin b → V) : - flattenedForm T (fun p => v (σ p.1, p.2)) = flattenedForm T v := - flattenedSymmetricForm_outer_permute T hT σ v - -@[simp] theorem flattenedForm_constant_rows (T : SymmetricMultilinearForm a b V) - (v : Fin a → V) : - flattenedForm T (fun p => v p.1) = - T (fun i => symMonomial b V (fun _ => v i)) := rfl - -@[simp] theorem flattenedForm_constant_columns (T : SymmetricMultilinearForm a b V) - (v : Fin b → V) : - flattenedForm T (fun p => v p.2) = - T (fun _ => symMonomial b V v) := rfl - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u + +variable {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- A form on symmetric powers, evaluated on products, is multilinear in all +of the underlying vector factors. -/ +def flattenedSymmetricForm (T : SymmetricMultilinearForm a b V) : + MultilinearMap ℂ (fun _ : Fin a × Fin b => V) ℂ := + (T.compMultilinearMap (fun _ => symMonomialMultilinear b V)).domDomCongr + (Equiv.sigmaEquivProd (Fin a) (Fin b)) + +@[simp] +theorem flattenedSymmetricForm_apply (T : SymmetricMultilinearForm a b V) + (v : Fin a × Fin b → V) : + flattenedSymmetricForm T v = + T (fun i => symMonomial b V (fun j => v (i, j))) := rfl + +/-- Independent permutations within the rows preserve the flattened form. -/ +theorem flattenedSymmetricForm_inner_permute + (T : SymmetricMultilinearForm a b V) + (σ : Fin a → Equiv.Perm (Fin b)) (v : Fin a × Fin b → V) : + flattenedSymmetricForm T (fun p => v (p.1, σ p.1 p.2)) = + flattenedSymmetricForm T v := by + apply congrArg T + funext i + exact symMonomial_permute b V (σ i) (fun j => v (i, j)) + +/-- Symmetry of the original form permits permutation of the rows. -/ +theorem flattenedSymmetricForm_outer_permute + (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) + (σ : Equiv.Perm (Fin a)) (v : Fin a × Fin b → V) : + flattenedSymmetricForm T (fun p => v (σ p.1, p.2)) = + flattenedSymmetricForm T v := by + exact hT σ (fun i => symMonomial b V (fun j => v (i, j))) + +/-- Compatibility API for the same flattened form, with inferred degrees. -/ +abbrev flattenedForm {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] + (T : SymmetricMultilinearForm a b V) : + MultilinearMap ℂ (fun _ : Fin a × Fin b => V) ℂ := + flattenedSymmetricForm T + +@[simp] +theorem flattenedForm_apply {a b : ℕ} {V : Type u} [AddCommGroup V] [Module ℂ V] + (T : SymmetricMultilinearForm a b V) (x : Fin a × Fin b → V) : + flattenedForm T x = T (fun i => symMonomial b V (fun j => x (i, j))) := rfl + +theorem flattenedForm_permute_factors (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (σ : Fin a → Equiv.Perm (Fin b)) (x : Fin a × Fin b → V) : + flattenedForm T (fun p => x (p.1, σ p.1 p.2)) = + flattenedForm T x := + flattenedSymmetricForm_inner_permute T σ x + +theorem flattenedForm_permute_slots (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) + (σ : Equiv.Perm (Fin a)) (x : Fin a × Fin b → V) : + flattenedForm T (fun p => x (σ p.1, p.2)) = + flattenedForm T x := + flattenedSymmetricForm_outer_permute T hT σ x + +/-- Simultaneous row and independent within-row permutation invariance. -/ +theorem flattenedForm_permute (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) + (σ : Equiv.Perm (Fin a)) (τ : Fin a → Equiv.Perm (Fin b)) + (x : Fin a × Fin b → V) : + flattenedForm T (fun p => x (σ p.1, τ p.1 p.2)) = + flattenedForm T x := + (flattenedForm_permute_factors a b V T τ (fun p => x (σ p.1, p.2))).trans + (flattenedForm_permute_slots a b V T hT σ x) + +/-- Implicit-parameter factor symmetry used by the transfer sequences. -/ +theorem flattenedForm_factor_perm (T : SymmetricMultilinearForm a b V) + (σ : Fin a → Equiv.Perm (Fin b)) (v : Fin a × Fin b → V) : + flattenedForm T (fun p => v (p.1, σ p.1 p.2)) = flattenedForm T v := + flattenedSymmetricForm_inner_permute T σ v + +/-- Implicit-parameter row symmetry used by the transfer sequences. -/ +theorem flattenedForm_row_perm (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) (σ : Equiv.Perm (Fin a)) + (v : Fin a × Fin b → V) : + flattenedForm T (fun p => v (σ p.1, p.2)) = flattenedForm T v := + flattenedSymmetricForm_outer_permute T hT σ v + +@[simp] theorem flattenedForm_constant_rows (T : SymmetricMultilinearForm a b V) + (v : Fin a → V) : + flattenedForm T (fun p => v p.1) = + T (fun i => symMonomial b V (fun _ => v i)) := rfl + +@[simp] theorem flattenedForm_constant_columns (T : SymmetricMultilinearForm a b V) + (v : Fin b → V) : + flattenedForm T (fun p => v p.2) = + T (fun _ => symMonomial b V v) := rfl + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedSwap.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedSwap.lean index e8c5bf731edef51df9eacfa107b0b389fc36e8a8..7348bc09b2e568d5d8443b19fd4f41cb7dca3e60 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedSwap.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FlattenedSwap.lean @@ -1,36 +1,36 @@ -import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm -import OAI.RepresentationTheory.FoulkesHowe.RowSwap - -namespace OAI - -noncomputable section - -namespace Problem346 - -/-- Flattened monomial forms are invariant under any transposition whose slots have the same row. -/ -theorem flattenedSymmetricForm_swap_same_row {a b : ℕ} {V : Type*} - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (p q : Fin a × Fin b) (hpq : p.1 = q.1) (v : Fin a × Fin b → V) : - flattenedSymmetricForm T (v ∘ Equiv.swap p q) = flattenedSymmetricForm T v := by - rcases p with ⟨i, j⟩ - rcases q with ⟨i', k⟩ - dsimp at hpq - subst i' - exact rowwise_invariant_swap (flattenedSymmetricForm T) - (flattenedSymmetricForm_inner_permute T) i j k v - -/-- Coefficient arrays of flattened forms satisfy exactly the row-swap condition -required to collapse a directional derivative to a multiplicity times one term. -/ -theorem flattenedSymmetricForm_coeff_swap_same_row {a b : ℕ} {V I : Type*} - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (e : I → V) (p q : Fin a × Fin b) (hpq : p.1 = q.1) - (k : Fin a × Fin b → I) : - flattenedSymmetricForm T (e ∘ (k ∘ Equiv.swap p q)) = - flattenedSymmetricForm T (e ∘ k) := by - exact flattenedSymmetricForm_swap_same_row T p q hpq (e ∘ k) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm +import OAI.RepresentationTheory.FoulkesHowe.RowSwap + +namespace OAI + +noncomputable section + +namespace Problem346 + +/-- Flattened monomial forms are invariant under any transposition whose slots have the same row. -/ +theorem flattenedSymmetricForm_swap_same_row {a b : ℕ} {V : Type*} + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (p q : Fin a × Fin b) (hpq : p.1 = q.1) (v : Fin a × Fin b → V) : + flattenedSymmetricForm T (v ∘ Equiv.swap p q) = flattenedSymmetricForm T v := by + rcases p with ⟨i, j⟩ + rcases q with ⟨i', k⟩ + dsimp at hpq + subst i' + exact rowwise_invariant_swap (flattenedSymmetricForm T) + (flattenedSymmetricForm_inner_permute T) i j k v + +/-- Coefficient arrays of flattened forms satisfy exactly the row-swap condition +required to collapse a directional derivative to a multiplicity times one term. -/ +theorem flattenedSymmetricForm_coeff_swap_same_row {a b : ℕ} {V I : Type*} + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (e : I → V) (p q : Fin a × Fin b) (hpq : p.1 = q.1) + (k : Fin a × Fin b → I) : + flattenedSymmetricForm T (e ∘ (k ∘ Equiv.swap p q)) = + flattenedSymmetricForm T (e ∘ k) := by + exact flattenedSymmetricForm_swap_same_row T p q hpq (e ∘ k) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesDiagonal.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesDiagonal.lean index 0c767c3b7fe4f04e4e8ed1423e9aef16d335444c..0de7f1e0664b54cf7aed752a222430540e7be3b9 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesDiagonal.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesDiagonal.lean @@ -1,30 +1,30 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u -namespace Problem346 - -variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - - theorem foulkesFormula_diagonal (u : Fin b → V) : - foulkesFormula a b V (fun j _ => u j) = - symMonomial a (SymPow b V) (fun _ => symMonomial b V u) := by - classical - simp [foulkesFormula, Fintype.card_perm, ← Nat.cast_smul_eq_nsmul ℂ, smul_smul, - Nat.factorial_ne_zero] - - theorem IsFoulkesMap.map_diagonal - (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) - (hμ : IsFoulkesMap a b V μ) (u : Fin b → V) : - μ (symMonomial b (SymPow a V) (fun j => symMonomial a V (fun _ => u j))) = - symMonomial a (SymPow b V) (fun _ => symMonomial b V u) := by - rw [hμ, foulkesFormula_diagonal] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u +namespace Problem346 + +variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + + theorem foulkesFormula_diagonal (u : Fin b → V) : + foulkesFormula a b V (fun j _ => u j) = + symMonomial a (SymPow b V) (fun _ => symMonomial b V u) := by + classical + simp [foulkesFormula, Fintype.card_perm, ← Nat.cast_smul_eq_nsmul ℂ, smul_smul, + Nat.factorial_ne_zero] + + theorem IsFoulkesMap.map_diagonal + (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) + (hμ : IsFoulkesMap a b V μ) (u : Fin b → V) : + μ (symMonomial b (SymPow a V) (fun j => symMonomial a V (fun _ => u j))) = + symMonomial a (SymPow b V) (fun _ => symMonomial b V u) := by + rw [hμ, foulkesFormula_diagonal] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesMultilinear.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesMultilinear.lean index cc637cb15b4c6eac16eeadd64e2f7fb17d7929a7..b3460ae4b55da9dece179fb724ce8d5f4769d8b9 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesMultilinear.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesMultilinear.lean @@ -1,66 +1,66 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section - -open scoped BigOperators -universe u - -namespace Problem346 - -private def monomialMultilinearAux (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - MultilinearMap ℂ (fun _ : Fin n => V) (SymPow n V) := - ((MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap - (fun _ => SymmetricAlgebra.ι ℂ V)).codRestrict (symPowSubmodule n V) - (fun v => Submodule.subset_span (Set.mem_range_self v)) - -private theorem monomialMultilinearAux_apply (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin n → V) : - monomialMultilinearAux n V v = symMonomial n V v := rfl - -/-- Reindex the slots in a transposed grid, allowing an independent permutation -in each original row. -/ -def foulkesIndexEquiv (a b : ℕ) (σ : Fin b → Equiv.Perm (Fin a)) : - (Σ _ : Fin a, Fin b) ≃ (Fin b × Fin a) where - toFun p := (p.2, σ p.2 p.1) - invFun p := ⟨(σ p.1).symm p.2, p.1⟩ - left_inv p := by cases p; simp - right_inv p := by cases p; simp - -/-- A summand of the Foulkes--Howe formula, viewed as a multilinear map in -all entries of the input grid. -/ -def foulkesSummandMultilinear (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (σ : Fin b → Equiv.Perm (Fin a)) : - MultilinearMap ℂ (fun _ : Fin b × Fin a => V) (SymPow a (SymPow b V)) := - ((monomialMultilinearAux a (SymPow b V)).compMultilinearMap - (fun _ => monomialMultilinearAux b V)).domDomCongr (foulkesIndexEquiv a b σ) - -@[simp] theorem foulkesSummandMultilinear_apply (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (σ : Fin b → Equiv.Perm (Fin a)) - (v : Fin b × Fin a → V) : - foulkesSummandMultilinear a b V σ v = - symMonomial a (SymPow b V) - (fun i => symMonomial b V (fun j => v (j, σ j i))) := rfl - -/-- The canonical Foulkes--Howe expression is multilinear in its `a * b` -individual vector arguments. -/ -def foulkesMultilinear (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - MultilinearMap ℂ (fun _ : Fin b × Fin a => V) (SymPow a (SymPow b V)) := by - classical - exact ((a.factorial : ℂ) ^ b)⁻¹ • - ∑ σ : Fin b → Equiv.Perm (Fin a), foulkesSummandMultilinear a b V σ - -@[simp] theorem foulkesMultilinear_apply (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin b × Fin a → V) : - foulkesMultilinear a b V v = foulkesFormula a b V (fun j i => v (j, i)) := by - classical - simp [foulkesMultilinear, foulkesFormula] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section + +open scoped BigOperators +universe u + +namespace Problem346 + +private def monomialMultilinearAux (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + MultilinearMap ℂ (fun _ : Fin n => V) (SymPow n V) := + ((MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap + (fun _ => SymmetricAlgebra.ι ℂ V)).codRestrict (symPowSubmodule n V) + (fun v => Submodule.subset_span (Set.mem_range_self v)) + +private theorem monomialMultilinearAux_apply (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin n → V) : + monomialMultilinearAux n V v = symMonomial n V v := rfl + +/-- Reindex the slots in a transposed grid, allowing an independent permutation +in each original row. -/ +def foulkesIndexEquiv (a b : ℕ) (σ : Fin b → Equiv.Perm (Fin a)) : + (Σ _ : Fin a, Fin b) ≃ (Fin b × Fin a) where + toFun p := (p.2, σ p.2 p.1) + invFun p := ⟨(σ p.1).symm p.2, p.1⟩ + left_inv p := by cases p; simp + right_inv p := by cases p; simp + +/-- A summand of the Foulkes--Howe formula, viewed as a multilinear map in +all entries of the input grid. -/ +def foulkesSummandMultilinear (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (σ : Fin b → Equiv.Perm (Fin a)) : + MultilinearMap ℂ (fun _ : Fin b × Fin a => V) (SymPow a (SymPow b V)) := + ((monomialMultilinearAux a (SymPow b V)).compMultilinearMap + (fun _ => monomialMultilinearAux b V)).domDomCongr (foulkesIndexEquiv a b σ) + +@[simp] theorem foulkesSummandMultilinear_apply (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (σ : Fin b → Equiv.Perm (Fin a)) + (v : Fin b × Fin a → V) : + foulkesSummandMultilinear a b V σ v = + symMonomial a (SymPow b V) + (fun i => symMonomial b V (fun j => v (j, σ j i))) := rfl + +/-- The canonical Foulkes--Howe expression is multilinear in its `a * b` +individual vector arguments. -/ +def foulkesMultilinear (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + MultilinearMap ℂ (fun _ : Fin b × Fin a => V) (SymPow a (SymPow b V)) := by + classical + exact ((a.factorial : ℂ) ^ b)⁻¹ • + ∑ σ : Fin b → Equiv.Perm (Fin a), foulkesSummandMultilinear a b V σ + +@[simp] theorem foulkesMultilinear_apply (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin b × Fin a → V) : + foulkesMultilinear a b V v = foulkesFormula a b V (fun j i => v (j, i)) := by + classical + simp [foulkesMultilinear, foulkesFormula] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesSymmetries.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesSymmetries.lean index 559cc3862d9b1a307b4cd376b4aca4f5dd26d0da..c9a23af70cc10c02e719f33e2b6d36b04873da66 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesSymmetries.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/FoulkesSymmetries.lean @@ -1,53 +1,53 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section - -open scoped BigOperators -universe u - -namespace Problem346 - -/-- Reindexing the factors of a symmetric monomial does not change it. -/ -theorem symMonomial_perm_reindex (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin n → V) - (τ : Equiv.Perm (Fin n)) : - symMonomial n V (fun i => v (τ i)) = symMonomial n V v := by - apply Subtype.ext - exact Equiv.prod_comp τ (fun i => SymmetricAlgebra.ι ℂ V (v i)) - -/-- The canonical averaging formula is invariant under independent permutations -of the entries in each row. -/ -theorem foulkesFormula_inner_permute (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) - (τ : Fin b → Equiv.Perm (Fin a)) : - foulkesFormula a b V (fun j i => v j (τ j i)) = - foulkesFormula a b V v := by - classical - unfold foulkesFormula - congr 1 - exact Fintype.sum_equiv - (Equiv.piCongrRight (fun j => Equiv.mulLeft (τ j))) _ _ (fun σ => rfl) - -/-- The canonical averaging formula is invariant under permutation of rows. -/ -theorem foulkesFormula_outer_permute (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) - (τ : Equiv.Perm (Fin b)) : - foulkesFormula a b V (fun j i => v (τ j) i) = - foulkesFormula a b V v := by - classical - unfold foulkesFormula - congr 1 - apply Fintype.sum_equiv (Equiv.arrowCongr τ (Equiv.refl (Equiv.Perm (Fin a)))) - intro σ - congr 1 - funext i - simpa using symMonomial_perm_reindex b V - (fun j => v j (σ (τ.symm j) i)) τ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section + +open scoped BigOperators +universe u + +namespace Problem346 + +/-- Reindexing the factors of a symmetric monomial does not change it. -/ +theorem symMonomial_perm_reindex (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin n → V) + (τ : Equiv.Perm (Fin n)) : + symMonomial n V (fun i => v (τ i)) = symMonomial n V v := by + apply Subtype.ext + exact Equiv.prod_comp τ (fun i => SymmetricAlgebra.ι ℂ V (v i)) + +/-- The canonical averaging formula is invariant under independent permutations +of the entries in each row. -/ +theorem foulkesFormula_inner_permute (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) + (τ : Fin b → Equiv.Perm (Fin a)) : + foulkesFormula a b V (fun j i => v j (τ j i)) = + foulkesFormula a b V v := by + classical + unfold foulkesFormula + congr 1 + exact Fintype.sum_equiv + (Equiv.piCongrRight (fun j => Equiv.mulLeft (τ j))) _ _ (fun σ => rfl) + +/-- The canonical averaging formula is invariant under permutation of rows. -/ +theorem foulkesFormula_outer_permute (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin a → V) + (τ : Equiv.Perm (Fin b)) : + foulkesFormula a b V (fun j i => v (τ j) i) = + foulkesFormula a b V v := by + classical + unfold foulkesFormula + congr 1 + apply Fintype.sum_equiv (Equiv.arrowCongr τ (Equiv.refl (Equiv.Perm (Fin a)))) + intro σ + congr 1 + funext i + simpa using symMonomial_perm_reindex b V + (fun j => v j (σ (τ.symm j) i)) τ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Functoriality.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Functoriality.lean index 59e3082f32ed35d3a8e71cb42712d3b8fec4fa2d..df3f57cf51fdf9ec8f6056c0bf0df39baf984f33 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Functoriality.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Functoriality.lean @@ -1,128 +1,128 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u v w -namespace Problem346 - -variable {V : Type u} {W : Type v} {U : Type w} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - [AddCommGroup U] [Module ℂ U] - -/-- The algebra map induced by a complex-linear map. -/ -def symAlgMap (f : V →ₗ[ℂ] W) : SymmetricAlgebra ℂ V →ₐ[ℂ] SymmetricAlgebra ℂ W := - SymmetricAlgebra.lift ((SymmetricAlgebra.ι ℂ W).comp f) - -@[simp] theorem symAlgMap_ι (f : V →ₗ[ℂ] W) (x : V) : - symAlgMap f (SymmetricAlgebra.ι ℂ V x) = SymmetricAlgebra.ι ℂ W (f x) := by - simp [symAlgMap] - -@[simp] theorem symAlgMap_symMonomialRaw (n : ℕ) (f : V →ₗ[ℂ] W) (x : Fin n → V) : - symAlgMap f (symMonomialRaw n V x) = symMonomialRaw n W (fun i => f (x i)) := by - simp [symMonomialRaw] - -/-- Symmetric powers act covariantly on linear maps. -/ -def symPowMap (n : ℕ) (f : V →ₗ[ℂ] W) : SymPow n V →ₗ[ℂ] SymPow n W := - ((symAlgMap f).toLinearMap.comp (symPowSubmodule n V).subtype).codRestrict - (symPowSubmodule n W) (by - have hle : symPowSubmodule n V ≤ - (symPowSubmodule n W).comap (symAlgMap f).toLinearMap := by - apply Submodule.span_le.mpr - rintro x ⟨v, rfl⟩ - change symAlgMap f (symMonomialRaw n V v) ∈ symPowSubmodule n W - rw [symAlgMap_symMonomialRaw] - exact Submodule.subset_span (Set.mem_range_self _) - intro x - exact hle x.property) - -@[simp] theorem symPowMap_symMonomial (n : ℕ) (f : V →ₗ[ℂ] W) (x : Fin n → V) : - symPowMap n f (symMonomial n V x) = symMonomial n W (fun i => f (x i)) := by - apply Subtype.ext - exact symAlgMap_symMonomialRaw n f x - -@[simp] theorem symAlgMap_id : - symAlgMap (LinearMap.id : V →ₗ[ℂ] V) = AlgHom.id ℂ (SymmetricAlgebra ℂ V) := by - ext x - simp - -@[simp] theorem symAlgMap_comp (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : - symAlgMap (g.comp f) = (symAlgMap g).comp (symAlgMap f) := by - ext x - simp - -@[simp] theorem symPowMap_coe (n : ℕ) (f : V →ₗ[ℂ] W) (x : SymPow n V) : - (symPowMap n f x : SymmetricAlgebra ℂ W) = symAlgMap f x := rfl - -@[simp] theorem symPowMap_id (n : ℕ) : - symPowMap n (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by - apply LinearMap.ext - intro x - apply Subtype.ext - simp - -@[simp] theorem symPowMap_comp (n : ℕ) (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : - symPowMap n (g.comp f) = (symPowMap n g).comp (symPowMap n f) := by - apply LinearMap.ext - intro x - apply Subtype.ext - simp - -/-- A linear equivalence induces an equivalence on each symmetric power. -/ -def symPowEquiv (n : ℕ) (e : V ≃ₗ[ℂ] W) : SymPow n V ≃ₗ[ℂ] SymPow n W where - toLinearMap := symPowMap n e.toLinearMap - invFun := symPowMap n e.symm.toLinearMap - left_inv x := by - change ((symPowMap n e.symm.toLinearMap).comp (symPowMap n e.toLinearMap)) x = x - rw [← symPowMap_comp] - simp - right_inv x := by - change ((symPowMap n e.toLinearMap).comp (symPowMap n e.symm.toLinearMap)) x = x - rw [← symPowMap_comp] - simp - -@[simp] theorem symPowEquiv_symMonomial (n : ℕ) (e : V ≃ₗ[ℂ] W) (x : Fin n → V) : - symPowEquiv n e (symMonomial n V x) = symMonomial n W (fun i => e (x i)) := - symPowMap_symMonomial n e.toLinearMap x - -@[simp] theorem symPowEquiv_toLinearMap (n : ℕ) (e : V ≃ₗ[ℂ] W) : - (symPowEquiv n e).toLinearMap = symPowMap n e.toLinearMap := rfl - -@[simp] theorem symPowEquiv_refl (n : ℕ) : - symPowEquiv n (LinearEquiv.refl ℂ V) = LinearEquiv.refl ℂ (SymPow n V) := by - apply LinearEquiv.toLinearMap_injective - exact symPowMap_id n - -@[simp] theorem symPowEquiv_trans (n : ℕ) (e : V ≃ₗ[ℂ] W) (f : W ≃ₗ[ℂ] U) : - symPowEquiv n (e.trans f) = (symPowEquiv n e).trans (symPowEquiv n f) := by - apply LinearEquiv.toLinearMap_injective - exact symPowMap_comp n f.toLinearMap e.toLinearMap - -@[simp] theorem symPowEquiv_symm (n : ℕ) (e : V ≃ₗ[ℂ] W) : - symPowEquiv n e.symm = (symPowEquiv n e).symm := by - rfl - -theorem symPowMap_injective (n : ℕ) (f : V →ₗ[ℂ] W) (hf : Function.Injective f) : - Function.Injective (symPowMap n f) := by - obtain ⟨g, hg⟩ := f.exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hf) - have hgf : (symPowMap n g).comp (symPowMap n f) = LinearMap.id := by - rw [← symPowMap_comp, hg, symPowMap_id] - have hleft : Function.LeftInverse (symPowMap n g) (symPowMap n f) := - fun x => LinearMap.congr_fun hgf x - exact hleft.injective - -theorem symPowMap_surjective (n : ℕ) (f : V →ₗ[ℂ] W) (hf : Function.Surjective f) : - Function.Surjective (symPowMap n f) := by - obtain ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (LinearMap.range_eq_top.mpr hf) - have hfg : (symPowMap n f).comp (symPowMap n g) = LinearMap.id := by - rw [← symPowMap_comp, hg, symPowMap_id] - have hright : Function.RightInverse (symPowMap n g) (symPowMap n f) := - fun x => LinearMap.congr_fun hfg x - exact hright.surjective - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u v w +namespace Problem346 + +variable {V : Type u} {W : Type v} {U : Type w} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + [AddCommGroup U] [Module ℂ U] + +/-- The algebra map induced by a complex-linear map. -/ +def symAlgMap (f : V →ₗ[ℂ] W) : SymmetricAlgebra ℂ V →ₐ[ℂ] SymmetricAlgebra ℂ W := + SymmetricAlgebra.lift ((SymmetricAlgebra.ι ℂ W).comp f) + +@[simp] theorem symAlgMap_ι (f : V →ₗ[ℂ] W) (x : V) : + symAlgMap f (SymmetricAlgebra.ι ℂ V x) = SymmetricAlgebra.ι ℂ W (f x) := by + simp [symAlgMap] + +@[simp] theorem symAlgMap_symMonomialRaw (n : ℕ) (f : V →ₗ[ℂ] W) (x : Fin n → V) : + symAlgMap f (symMonomialRaw n V x) = symMonomialRaw n W (fun i => f (x i)) := by + simp [symMonomialRaw] + +/-- Symmetric powers act covariantly on linear maps. -/ +def symPowMap (n : ℕ) (f : V →ₗ[ℂ] W) : SymPow n V →ₗ[ℂ] SymPow n W := + ((symAlgMap f).toLinearMap.comp (symPowSubmodule n V).subtype).codRestrict + (symPowSubmodule n W) (by + have hle : symPowSubmodule n V ≤ + (symPowSubmodule n W).comap (symAlgMap f).toLinearMap := by + apply Submodule.span_le.mpr + rintro x ⟨v, rfl⟩ + change symAlgMap f (symMonomialRaw n V v) ∈ symPowSubmodule n W + rw [symAlgMap_symMonomialRaw] + exact Submodule.subset_span (Set.mem_range_self _) + intro x + exact hle x.property) + +@[simp] theorem symPowMap_symMonomial (n : ℕ) (f : V →ₗ[ℂ] W) (x : Fin n → V) : + symPowMap n f (symMonomial n V x) = symMonomial n W (fun i => f (x i)) := by + apply Subtype.ext + exact symAlgMap_symMonomialRaw n f x + +@[simp] theorem symAlgMap_id : + symAlgMap (LinearMap.id : V →ₗ[ℂ] V) = AlgHom.id ℂ (SymmetricAlgebra ℂ V) := by + ext x + simp + +@[simp] theorem symAlgMap_comp (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : + symAlgMap (g.comp f) = (symAlgMap g).comp (symAlgMap f) := by + ext x + simp + +@[simp] theorem symPowMap_coe (n : ℕ) (f : V →ₗ[ℂ] W) (x : SymPow n V) : + (symPowMap n f x : SymmetricAlgebra ℂ W) = symAlgMap f x := rfl + +@[simp] theorem symPowMap_id (n : ℕ) : + symPowMap n (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by + apply LinearMap.ext + intro x + apply Subtype.ext + simp + +@[simp] theorem symPowMap_comp (n : ℕ) (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : + symPowMap n (g.comp f) = (symPowMap n g).comp (symPowMap n f) := by + apply LinearMap.ext + intro x + apply Subtype.ext + simp + +/-- A linear equivalence induces an equivalence on each symmetric power. -/ +def symPowEquiv (n : ℕ) (e : V ≃ₗ[ℂ] W) : SymPow n V ≃ₗ[ℂ] SymPow n W where + toLinearMap := symPowMap n e.toLinearMap + invFun := symPowMap n e.symm.toLinearMap + left_inv x := by + change ((symPowMap n e.symm.toLinearMap).comp (symPowMap n e.toLinearMap)) x = x + rw [← symPowMap_comp] + simp + right_inv x := by + change ((symPowMap n e.toLinearMap).comp (symPowMap n e.symm.toLinearMap)) x = x + rw [← symPowMap_comp] + simp + +@[simp] theorem symPowEquiv_symMonomial (n : ℕ) (e : V ≃ₗ[ℂ] W) (x : Fin n → V) : + symPowEquiv n e (symMonomial n V x) = symMonomial n W (fun i => e (x i)) := + symPowMap_symMonomial n e.toLinearMap x + +@[simp] theorem symPowEquiv_toLinearMap (n : ℕ) (e : V ≃ₗ[ℂ] W) : + (symPowEquiv n e).toLinearMap = symPowMap n e.toLinearMap := rfl + +@[simp] theorem symPowEquiv_refl (n : ℕ) : + symPowEquiv n (LinearEquiv.refl ℂ V) = LinearEquiv.refl ℂ (SymPow n V) := by + apply LinearEquiv.toLinearMap_injective + exact symPowMap_id n + +@[simp] theorem symPowEquiv_trans (n : ℕ) (e : V ≃ₗ[ℂ] W) (f : W ≃ₗ[ℂ] U) : + symPowEquiv n (e.trans f) = (symPowEquiv n e).trans (symPowEquiv n f) := by + apply LinearEquiv.toLinearMap_injective + exact symPowMap_comp n f.toLinearMap e.toLinearMap + +@[simp] theorem symPowEquiv_symm (n : ℕ) (e : V ≃ₗ[ℂ] W) : + symPowEquiv n e.symm = (symPowEquiv n e).symm := by + rfl + +theorem symPowMap_injective (n : ℕ) (f : V →ₗ[ℂ] W) (hf : Function.Injective f) : + Function.Injective (symPowMap n f) := by + obtain ⟨g, hg⟩ := f.exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hf) + have hgf : (symPowMap n g).comp (symPowMap n f) = LinearMap.id := by + rw [← symPowMap_comp, hg, symPowMap_id] + have hleft : Function.LeftInverse (symPowMap n g) (symPowMap n f) := + fun x => LinearMap.congr_fun hgf x + exact hleft.injective + +theorem symPowMap_surjective (n : ℕ) (f : V →ₗ[ℂ] W) (hf : Function.Surjective f) : + Function.Surjective (symPowMap n f) := by + obtain ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (LinearMap.range_eq_top.mpr hf) + have hfg : (symPowMap n f).comp (symPowMap n g) = LinearMap.id := by + rw [← symPowMap_comp, hg, symPowMap_id] + have hright : Function.RightInverse (symPowMap n g) (symPowMap n f) := + fun x => LinearMap.congr_fun hfg x + exact hright.surjective + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/GeneratorLift.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/GeneratorLift.lean index 2d7a142c3a99b5d4c85ff7ac129ca17649fa3436..b0a7a47a70d4fc5a94f62600ee9396eb1d258eef 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/GeneratorLift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/GeneratorLift.lean @@ -1,46 +1,46 @@ -import OAI.RepresentationTheory.FoulkesHowe.SpanningAgreement -import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift -import OAI.RepresentationTheory.FoulkesHowe.Spanning - -namespace OAI - -noncomputable section -namespace Problem346 - -/-- A separately linearly extendible symmetric formula on spanning generators -induces a linear map out of the homogeneous symmetric power. -/ -theorem exists_symPow_lift_on_spanning - {n : ℕ} {X V W : Type*} [AddCommGroup V] [Module ℂ V] - [AddCommGroup W] [Module ℂ W] - (s : X → V) (hs : Submodule.span ℂ (Set.range s) = ⊤) - (F : (Fin n → X) → W) - (hlinear : ∀ x : Fin n → X, ∀ i : Fin n, - ∃ L : V →ₗ[ℂ] W, ∀ y, L (s y) = F (Function.update x i y)) - (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → X), - F (fun i => x (σ i)) = F x) : - ∃ L : SymPow n V →ₗ[ℂ] W, ∀ x : Fin n → X, - L (symMonomial n V (fun i => s (x i))) = F x := by - classical - obtain ⟨G, hG⟩ := exists_multilinear_extension_of_spanning - (fun _ : Fin n => s) (fun _ => hs) F hlinear - have hGs : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), - G (fun i => v (σ i)) = G v := by - intro σ - have h : G.domDomCongr σ = G := by - apply multilinear_ext_of_span hs n - intro v hv - choose x hx using hv - have he : v = fun i => s (x i) := funext (fun i => (hx i).symm) - subst v - change G (fun i => s (x (σ i))) = G (fun i => s (x i)) - rw [← hG, ← hG, hsym] - intro v - exact congrArg (fun G : MultilinearMap ℂ (fun _ : Fin n => V) W => G v) h - obtain ⟨L, hL⟩ := exists_symPow_lift G hGs - exact ⟨L, fun x => (hL _).trans (hG x).symm⟩ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SpanningAgreement +import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift +import OAI.RepresentationTheory.FoulkesHowe.Spanning + +namespace OAI + +noncomputable section +namespace Problem346 + +/-- A separately linearly extendible symmetric formula on spanning generators +induces a linear map out of the homogeneous symmetric power. -/ +theorem exists_symPow_lift_on_spanning + {n : ℕ} {X V W : Type*} [AddCommGroup V] [Module ℂ V] + [AddCommGroup W] [Module ℂ W] + (s : X → V) (hs : Submodule.span ℂ (Set.range s) = ⊤) + (F : (Fin n → X) → W) + (hlinear : ∀ x : Fin n → X, ∀ i : Fin n, + ∃ L : V →ₗ[ℂ] W, ∀ y, L (s y) = F (Function.update x i y)) + (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → X), + F (fun i => x (σ i)) = F x) : + ∃ L : SymPow n V →ₗ[ℂ] W, ∀ x : Fin n → X, + L (symMonomial n V (fun i => s (x i))) = F x := by + classical + obtain ⟨G, hG⟩ := exists_multilinear_extension_of_spanning + (fun _ : Fin n => s) (fun _ => hs) F hlinear + have hGs : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), + G (fun i => v (σ i)) = G v := by + intro σ + have h : G.domDomCongr σ = G := by + apply multilinear_ext_of_span hs n + intro v hv + choose x hx using hv + have he : v = fun i => s (x i) := funext (fun i => (hx i).symm) + subst v + change G (fun i => s (x (σ i))) = G (fun i => s (x i)) + rw [← hG, ← hG, hsym] + intro v + exact congrArg (fun G : MultilinearMap ℂ (fun _ : Fin n => V) W => G v) h + obtain ⟨L, hL⟩ := exists_symPow_lift G hGs + exact ⟨L, fun x => (hL _).trans (hG x).symm⟩ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/GridCancellation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/GridCancellation.lean index f56d73df128d097764e171ecd46ca84609b061ed..a06b4ae5b0a5b108fd83a3710809982e79965eb4 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/GridCancellation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/GridCancellation.lean @@ -1,56 +1,56 @@ -import Mathlib - -namespace OAI - -open scoped BigOperators - -namespace Problem346 - -/-- Reverse induction over a finite rectangular grid. A zero at its upper corner -propagates to every point when a one-coordinate upward step can be cancelled. -/ -theorem zero_of_upward_grid {ι M : Type*} [Fintype ι] [DecidableEq ι] [Zero M] - (r : ℕ) (F : (ι → ℕ) → M) - (hend : F (fun _ => r) = 0) - (hstep : ∀ (c : ι → ℕ), (∀ i, c i ≤ r) → ∀ i, c i < r → - F (Function.update c i (c i + 1)) = 0 → F c = 0) - (c : ι → ℕ) (hc : ∀ i, c i ≤ r) : F c = 0 := by - classical - have aux : ∀ n : ℕ, ∀ c : ι → ℕ, (∀ i, c i ≤ r) → - (∑ i, (r - c i)) = n → F c = 0 := by - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro c hc hn - by_cases htop : ∀ i, c i = r - · have heq : c = fun _ => r := funext htop - simpa only [heq] using hend - · push Not at htop - obtain ⟨i, hi⟩ := htop - have hir : c i < r := lt_of_le_of_ne (hc i) hi - apply hstep c hc i hir - let c' := Function.update c i (c i + 1) - have hc' : ∀ j, c' j ≤ r := by - intro j - by_cases hji : j = i - · subst j - simp only [c', Function.update_self] - omega - · simpa only [c', Function.update_of_ne hji] using hc j - have hlt : (∑ j, (r - c' j)) < n := by - rw [← hn] - apply Finset.sum_lt_sum - · intro j hj - by_cases hji : j = i - · subst j - simp only [c', Function.update_self] - omega - · simp only [c', Function.update_of_ne hji, le_refl] - · refine ⟨i, Finset.mem_univ i, ?_⟩ - simp only [c', Function.update_self] - omega - exact ih _ hlt c' hc' rfl - exact aux _ c hc rfl - -end Problem346 - -end OAI +import Mathlib + +namespace OAI + +open scoped BigOperators + +namespace Problem346 + +/-- Reverse induction over a finite rectangular grid. A zero at its upper corner +propagates to every point when a one-coordinate upward step can be cancelled. -/ +theorem zero_of_upward_grid {ι M : Type*} [Fintype ι] [DecidableEq ι] [Zero M] + (r : ℕ) (F : (ι → ℕ) → M) + (hend : F (fun _ => r) = 0) + (hstep : ∀ (c : ι → ℕ), (∀ i, c i ≤ r) → ∀ i, c i < r → + F (Function.update c i (c i + 1)) = 0 → F c = 0) + (c : ι → ℕ) (hc : ∀ i, c i ≤ r) : F c = 0 := by + classical + have aux : ∀ n : ℕ, ∀ c : ι → ℕ, (∀ i, c i ≤ r) → + (∑ i, (r - c i)) = n → F c = 0 := by + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro c hc hn + by_cases htop : ∀ i, c i = r + · have heq : c = fun _ => r := funext htop + simpa only [heq] using hend + · push Not at htop + obtain ⟨i, hi⟩ := htop + have hir : c i < r := lt_of_le_of_ne (hc i) hi + apply hstep c hc i hir + let c' := Function.update c i (c i + 1) + have hc' : ∀ j, c' j ≤ r := by + intro j + by_cases hji : j = i + · subst j + simp only [c', Function.update_self] + omega + · simpa only [c', Function.update_of_ne hji] using hc j + have hlt : (∑ j, (r - c' j)) < n := by + rw [← hn] + apply Finset.sum_lt_sum + · intro j hj + by_cases hji : j = i + · subst j + simp only [c', Function.update_self] + omega + · simp only [c', Function.update_of_ne hji, le_refl] + · refine ⟨i, Finset.mem_univ i, ?_⟩ + simp only [c', Function.update_self] + omega + exact ih _ hlt c' hc' rfl + exact aux _ c hc rfl + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/LinearCase.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/LinearCase.lean index 69ad043e4e78339c2b4ab62862a138e2e2eb7170..a3641ddffba2f9cac31fe1d2233dd010871ad91a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/LinearCase.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/LinearCase.lean @@ -1,52 +1,52 @@ -import OAI.RepresentationTheory.FoulkesHowe.DegreeOne -import OAI.RepresentationTheory.FoulkesHowe.Functoriality - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u -namespace Problem346 - -@[simp] theorem foulkesFormula_one (b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin 1 → V) : - foulkesFormula 1 b V v = - symMonomial 1 (SymPow b V) (fun _ => symMonomial b V (fun j => v j 0)) := by - classical - simp [foulkesFormula, Fin.eq_zero] - -/-- The canonical Foulkes--Howe equivalence when the inner degree is one. -/ -def foulkesOneEquiv (b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - SymPow b (SymPow 1 V) ≃ₗ[ℂ] SymPow 1 (SymPow b V) := - (symPowEquiv b (symPowOneEquiv V)).trans (symPowOneEquiv (SymPow b V)).symm - -theorem foulkesOneEquiv_isFoulkesMap (b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - IsFoulkesMap 1 b V (foulkesOneEquiv b V).toLinearMap := by - intro v - simp [foulkesOneEquiv] - -/-- Degree-one stabilization, with no finite-dimensionality requirement. -/ -theorem canonical_foulkes_howe_a_one_aux (V : Type u) - [AddCommGroup V] [Module ℂ V] (b : ℕ) : - ∃ μ : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), - IsFoulkesMap 1 b V μ ∧ Function.Bijective μ ∧ - ∀ ν : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), - IsFoulkesMap 1 b V ν → ν = μ := by - refine ⟨(foulkesOneEquiv b V).toLinearMap, foulkesOneEquiv_isFoulkesMap b V, - (foulkesOneEquiv b V).bijective, ?_⟩ - intro ν hν - have hspan : Submodule.span ℂ (Set.range (symMonomial b (SymPow 1 V))) = ⊤ := by - exact (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule b (SymPow 1 V)) - (fun v => Submodule.subset_span (Set.mem_range_self v))).mpr rfl - apply LinearMap.ext_on_range hspan - intro v - have h := (hν (fun j _ => symPowOneEquiv V (v j))).trans - ((foulkesOneEquiv_isFoulkesMap b V (fun j _ => symPowOneEquiv V (v j))).symm) - simpa only [← symPowOneEquiv_symm_apply, LinearEquiv.symm_apply_apply] using h - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.DegreeOne +import OAI.RepresentationTheory.FoulkesHowe.Functoriality + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u +namespace Problem346 + +@[simp] theorem foulkesFormula_one (b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (v : Fin b → Fin 1 → V) : + foulkesFormula 1 b V v = + symMonomial 1 (SymPow b V) (fun _ => symMonomial b V (fun j => v j 0)) := by + classical + simp [foulkesFormula, Fin.eq_zero] + +/-- The canonical Foulkes--Howe equivalence when the inner degree is one. -/ +def foulkesOneEquiv (b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + SymPow b (SymPow 1 V) ≃ₗ[ℂ] SymPow 1 (SymPow b V) := + (symPowEquiv b (symPowOneEquiv V)).trans (symPowOneEquiv (SymPow b V)).symm + +theorem foulkesOneEquiv_isFoulkesMap (b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + IsFoulkesMap 1 b V (foulkesOneEquiv b V).toLinearMap := by + intro v + simp [foulkesOneEquiv] + +/-- Degree-one stabilization, with no finite-dimensionality requirement. -/ +theorem canonical_foulkes_howe_a_one_aux (V : Type u) + [AddCommGroup V] [Module ℂ V] (b : ℕ) : + ∃ μ : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), + IsFoulkesMap 1 b V μ ∧ Function.Bijective μ ∧ + ∀ ν : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), + IsFoulkesMap 1 b V ν → ν = μ := by + refine ⟨(foulkesOneEquiv b V).toLinearMap, foulkesOneEquiv_isFoulkesMap b V, + (foulkesOneEquiv b V).bijective, ?_⟩ + intro ν hν + have hspan : Submodule.span ℂ (Set.range (symMonomial b (SymPow 1 V))) = ⊤ := by + exact (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule b (SymPow 1 V)) + (fun v => Submodule.subset_span (Set.mem_range_self v))).mpr rfl + apply LinearMap.ext_on_range hspan + intro v + have h := (hν (fun j _ => symPowOneEquiv V (v j))).trans + ((foulkesOneEquiv_isFoulkesMap b V (fun j _ => symPowOneEquiv V (v j))).symm) + simpa only [← symPowOneEquiv_symm_apply, LinearEquiv.symm_apply_apply] using h + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Model.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Model.lean index b6c17cabc8f6df5a26cbe7257731a7403fdb37d3..b221a3b4d50c9ac4bea70c805700082495af0551 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Model.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Model.lean @@ -1,79 +1,79 @@ -import Mathlib - -namespace OAI - -noncomputable section - -open scoped BigOperators -universe u - -namespace Problem346 - -def symMonomialRaw (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - (v : Fin n → V) : SymmetricAlgebra ℂ V := - ∏ i : Fin n, SymmetricAlgebra.ι ℂ V (v i) - -def symPowSubmodule (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - Submodule ℂ (SymmetricAlgebra ℂ V) := - Submodule.span ℂ (Set.range (symMonomialRaw n V)) - -abbrev SymPow (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] := - ↥(symPowSubmodule n V) - -def symMonomial (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - (v : Fin n → V) : SymPow n V := - ⟨symMonomialRaw n V v, Submodule.subset_span (Set.mem_range_self v)⟩ - -def foulkesFormula (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - (v : Fin b → Fin a → V) : SymPow a (SymPow b V) := by - classical - exact - ((a.factorial : ℂ) ^ b)⁻¹ • - ∑ σ : Fin b → Equiv.Perm (Fin a), - symMonomial a (SymPow b V) - (fun i => symMonomial b V (fun j => v j ((σ j) i))) - -def IsFoulkesMap (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) : Prop := - ∀ v : Fin b → Fin a → V, - μ (symMonomial b (SymPow a V) (fun j => symMonomial a V (v j))) = - foulkesFormula a b V v - -def IsPlethysmAction (outer inner : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (g : V ≃ₗ[ℂ] V) - (L : SymPow outer (SymPow inner V) →ₗ[ℂ] - SymPow outer (SymPow inner V)) : Prop := - ∀ v : Fin outer → Fin inner → V, - L (symMonomial outer (SymPow inner V) - (fun i => symMonomial inner V (v i))) = - symMonomial outer (SymPow inner V) - (fun i => symMonomial inner V (fun j => g (v i j))) - -def IsGLEquivariantEmbedding (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V)) : Prop := - Function.Injective ι ∧ - ∀ g : V ≃ₗ[ℂ] V, - ∃ Lsource : SymPow b (SymPow a V) →ₗ[ℂ] SymPow b (SymPow a V), - ∃ Ltarget : SymPow a (SymPow b V) →ₗ[ℂ] SymPow a (SymPow b V), - IsPlethysmAction b a V g Lsource ∧ - IsPlethysmAction a b V g Ltarget ∧ - Function.Bijective Lsource ∧ - Function.Bijective Ltarget ∧ - Lsource.comp ι = ι.comp Ltarget - -abbrev SymmetricMultilinearForm (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] := - MultilinearMap ℂ (fun _ : Fin a => SymPow b V) ℂ - -def IsSymmetricMultilinearForm (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (T : SymmetricMultilinearForm a b V) : Prop := - ∀ (σ : Equiv.Perm (Fin a)) (x : Fin a → SymPow b V), - T (fun i => x (σ i)) = T x - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +open scoped BigOperators +universe u + +namespace Problem346 + +def symMonomialRaw (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + (v : Fin n → V) : SymmetricAlgebra ℂ V := + ∏ i : Fin n, SymmetricAlgebra.ι ℂ V (v i) + +def symPowSubmodule (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + Submodule ℂ (SymmetricAlgebra ℂ V) := + Submodule.span ℂ (Set.range (symMonomialRaw n V)) + +abbrev SymPow (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] := + ↥(symPowSubmodule n V) + +def symMonomial (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + (v : Fin n → V) : SymPow n V := + ⟨symMonomialRaw n V v, Submodule.subset_span (Set.mem_range_self v)⟩ + +def foulkesFormula (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + (v : Fin b → Fin a → V) : SymPow a (SymPow b V) := by + classical + exact + ((a.factorial : ℂ) ^ b)⁻¹ • + ∑ σ : Fin b → Equiv.Perm (Fin a), + symMonomial a (SymPow b V) + (fun i => symMonomial b V (fun j => v j ((σ j) i))) + +def IsFoulkesMap (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + (μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)) : Prop := + ∀ v : Fin b → Fin a → V, + μ (symMonomial b (SymPow a V) (fun j => symMonomial a V (v j))) = + foulkesFormula a b V v + +def IsPlethysmAction (outer inner : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (g : V ≃ₗ[ℂ] V) + (L : SymPow outer (SymPow inner V) →ₗ[ℂ] + SymPow outer (SymPow inner V)) : Prop := + ∀ v : Fin outer → Fin inner → V, + L (symMonomial outer (SymPow inner V) + (fun i => symMonomial inner V (v i))) = + symMonomial outer (SymPow inner V) + (fun i => symMonomial inner V (fun j => g (v i j))) + +def IsGLEquivariantEmbedding (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V)) : Prop := + Function.Injective ι ∧ + ∀ g : V ≃ₗ[ℂ] V, + ∃ Lsource : SymPow b (SymPow a V) →ₗ[ℂ] SymPow b (SymPow a V), + ∃ Ltarget : SymPow a (SymPow b V) →ₗ[ℂ] SymPow a (SymPow b V), + IsPlethysmAction b a V g Lsource ∧ + IsPlethysmAction a b V g Ltarget ∧ + Function.Bijective Lsource ∧ + Function.Bijective Ltarget ∧ + Lsource.comp ι = ι.comp Ltarget + +abbrev SymmetricMultilinearForm (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] := + MultilinearMap ℂ (fun _ : Fin a => SymPow b V) ℂ + +def IsSymmetricMultilinearForm (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (T : SymmetricMultilinearForm a b V) : Prop := + ∀ (σ : Equiv.Perm (Fin a)) (x : Fin a → SymPow b V), + T (fun i => x (σ i)) = T x + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialCut.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialCut.lean index fb5ddf2fc7e90dcb2d8856bc5eb1c6383bb74635..8b9f7460614d3a4118c74e6315f08c6fe2b19d3e 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialCut.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialCut.lean @@ -1,59 +1,59 @@ -import OAI.RepresentationTheory.FoulkesHowe.Multiplication - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Splitting a list of equal factors at a cutoff is graded multiplication of two pure powers. -/ -theorem symMonomial_cut (r m : ℕ) (x y : V) : - symMonomial (r+m) V (fun j => if j.val < r then x else y) = - symPowMul r m (symMonomial r V (fun _ => x)) - (symMonomial m V (fun _ => y)) := by - rw [symPowMul_symMonomial] - congr 1 - ext j - refine Fin.addCases (fun i => ?_) (fun i => ?_) j - · simp - · simp - -/-- Cast-free raw form of the cutoff identity. -/ -theorem symMonomialRaw_cut (r m : ℕ) (x y : V) : - symMonomialRaw (r+m) V (fun j => if j.val < r then x else y) = - SymmetricAlgebra.ι ℂ V x ^ r * SymmetricAlgebra.ι ℂ V y ^ m := by - have h := congrArg (fun z : SymPow (r+m) V => (z : SymmetricAlgebra ℂ V)) - (symMonomial_cut r m x y) - simpa [symMonomial, symPowMul_coe, symMonomialRaw_const] using h - -/-- The all-row terminal cutoff in the second transfer matches its common-power product form. -/ -theorem multilinear_cut_endpoint (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (x t : V) (v : Fin r → V) : - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symMonomial (r+m) V (fun j => if j.val < r then x else v i))) = - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) - (symMonomial m V (fun _ => v i)))) := by - simp only [symMonomial_cut] - -/-- Vanishing on arbitrary residual products gives vanishing on the terminal cutoff. -/ -theorem multilinear_cut_endpoint_zero (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) - (x t : V) (v : Fin r → V) : - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symMonomial (r+m) V (fun j => if j.val < r then x else v i))) = 0 := by - rw [multilinear_cut_endpoint] - exact h x t (fun i => symMonomial m V (fun _ => v i)) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Multiplication + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Splitting a list of equal factors at a cutoff is graded multiplication of two pure powers. -/ +theorem symMonomial_cut (r m : ℕ) (x y : V) : + symMonomial (r+m) V (fun j => if j.val < r then x else y) = + symPowMul r m (symMonomial r V (fun _ => x)) + (symMonomial m V (fun _ => y)) := by + rw [symPowMul_symMonomial] + congr 1 + ext j + refine Fin.addCases (fun i => ?_) (fun i => ?_) j + · simp + · simp + +/-- Cast-free raw form of the cutoff identity. -/ +theorem symMonomialRaw_cut (r m : ℕ) (x y : V) : + symMonomialRaw (r+m) V (fun j => if j.val < r then x else y) = + SymmetricAlgebra.ι ℂ V x ^ r * SymmetricAlgebra.ι ℂ V y ^ m := by + have h := congrArg (fun z : SymPow (r+m) V => (z : SymmetricAlgebra ℂ V)) + (symMonomial_cut r m x y) + simpa [symMonomial, symPowMul_coe, symMonomialRaw_const] using h + +/-- The all-row terminal cutoff in the second transfer matches its common-power product form. -/ +theorem multilinear_cut_endpoint (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (x t : V) (v : Fin r → V) : + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symMonomial (r+m) V (fun j => if j.val < r then x else v i))) = + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) + (symMonomial m V (fun _ => v i)))) := by + simp only [symMonomial_cut] + +/-- Vanishing on arbitrary residual products gives vanishing on the terminal cutoff. -/ +theorem multilinear_cut_endpoint_zero (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) + (x t : V) (v : Fin r → V) : + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symMonomial (r+m) V (fun j => if j.val < r then x else v i))) = 0 := by + rw [multilinear_cut_endpoint] + exact h x t (fun i => symMonomial m V (fun _ => v i)) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialMultilinear.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialMultilinear.lean index fd15ab38d55b87a8092663d5e9d7ddf0f2f27a1c..ade61821a9a8a167d751e989ee3c4f599407c372 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialMultilinear.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/MonomialMultilinear.lean @@ -1,117 +1,117 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section - -open scoped BigOperators - -universe u v - -namespace Problem346 - -/-- The product of degree-one generators, with its multilinearity bundled. -/ -def symMonomialMultilinear (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - MultilinearMap ℂ (fun _ : Fin n => V) (SymPow n V) := - ((MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap - (fun _ => SymmetricAlgebra.ι ℂ V)).codRestrict (symPowSubmodule n V) - (fun x => Submodule.subset_span (Set.mem_range_self x)) - -@[simp] -theorem symMonomialMultilinear_apply (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (x : Fin n → V) : - symMonomialMultilinear n V x = symMonomial n V x := rfl - -theorem symMonomial_permute (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (σ : Equiv.Perm (Fin n)) (x : Fin n → V) : - symMonomial n V (fun i => x (σ i)) = symMonomial n V x := by - apply Subtype.ext - exact Equiv.prod_comp σ (fun i => SymmetricAlgebra.ι ℂ V (x i)) - -/-- A functional on a symmetric power induces a symmetric multilinear form. -/ -def monomialFunctional (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : SymmetricMultilinearForm a b V := - φ.compMultilinearMap (symMonomialMultilinear a (SymPow b V)) - -@[simp] -theorem monomialFunctional_apply (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) (x : Fin a → SymPow b V) : - monomialFunctional a b V φ x = φ (symMonomial a (SymPow b V) x) := rfl - -theorem monomialFunctional_symmetric (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : - IsSymmetricMultilinearForm a b V (monomialFunctional a b V φ) := by - intro σ x - simp only [monomialFunctional_apply, symMonomial_permute] - -/-- Monomial values determine every linear map out of a symmetric power. -/ -theorem linearMap_eq_zero_of_symMonomial (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] {W : Type v} [AddCommGroup W] [Module ℂ W] - (φ : SymPow n V →ₗ[ℂ] W) - (hφ : ∀ x : Fin n → V, φ (symMonomial n V x) = 0) : φ = 0 := by - ext x - change φ x = 0 - obtain ⟨x, hx⟩ := x - induction hx using Submodule.span_induction with - | mem y hy => - obtain ⟨v, rfl⟩ := hy - exact hφ v - | zero => exact map_zero φ - | add x y hx hy ihx ihy => - change φ (⟨x, hx⟩ + ⟨y, hy⟩) = 0 - rw [map_add, ihx, ihy, add_zero] - | smul c x hx ih => - change φ (c • (⟨x, hx⟩ : SymPow n V)) = 0 - rw [map_smul, ih, smul_zero] - -theorem monomialFunctional_eq_zero_iff (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : - monomialFunctional a b V φ = 0 ↔ φ = 0 := by - constructor - · intro h - apply linearMap_eq_zero_of_symMonomial - intro x - exact congrArg (fun T : SymmetricMultilinearForm a b V => T x) h - · rintro rfl - rfl - -/-- Flatten the `a` rows of `b` vector arguments of a form on `SymPow b V`. -/ -def plethysmFormMultilinear (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) : - MultilinearMap ℂ (fun _ : Σ _ : Fin a, Fin b => V) ℂ := - T.compMultilinearMap (fun _ => symMonomialMultilinear b V) - -@[simp] -theorem plethysmFormMultilinear_apply (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (x : (Σ _ : Fin a, Fin b) → V) : - plethysmFormMultilinear a b V T x = - T (fun i => symMonomial b V (fun j => x ⟨i,j⟩)) := rfl - -theorem plethysmFormMultilinear_inner_permute (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (σ : Fin a → Equiv.Perm (Fin b)) (x : (Σ _ : Fin a, Fin b) → V) : - plethysmFormMultilinear a b V T (fun ij => x ⟨ij.1, σ ij.1 ij.2⟩) = - plethysmFormMultilinear a b V T x := by - apply congrArg T - funext i - exact symMonomial_permute b V (σ i) (fun j => x ⟨i,j⟩) - -theorem plethysmFormMultilinear_outer_permute (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) - (σ : Equiv.Perm (Fin a)) (x : (Σ _ : Fin a, Fin b) → V) : - plethysmFormMultilinear a b V T (fun ij => x ⟨σ ij.1, ij.2⟩) = - plethysmFormMultilinear a b V T x := by - exact hT σ (fun i => symMonomial b V (fun j => x ⟨i,j⟩)) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section + +open scoped BigOperators + +universe u v + +namespace Problem346 + +/-- The product of degree-one generators, with its multilinearity bundled. -/ +def symMonomialMultilinear (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + MultilinearMap ℂ (fun _ : Fin n => V) (SymPow n V) := + ((MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap + (fun _ => SymmetricAlgebra.ι ℂ V)).codRestrict (symPowSubmodule n V) + (fun x => Submodule.subset_span (Set.mem_range_self x)) + +@[simp] +theorem symMonomialMultilinear_apply (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (x : Fin n → V) : + symMonomialMultilinear n V x = symMonomial n V x := rfl + +theorem symMonomial_permute (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (σ : Equiv.Perm (Fin n)) (x : Fin n → V) : + symMonomial n V (fun i => x (σ i)) = symMonomial n V x := by + apply Subtype.ext + exact Equiv.prod_comp σ (fun i => SymmetricAlgebra.ι ℂ V (x i)) + +/-- A functional on a symmetric power induces a symmetric multilinear form. -/ +def monomialFunctional (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : SymmetricMultilinearForm a b V := + φ.compMultilinearMap (symMonomialMultilinear a (SymPow b V)) + +@[simp] +theorem monomialFunctional_apply (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) (x : Fin a → SymPow b V) : + monomialFunctional a b V φ x = φ (symMonomial a (SymPow b V) x) := rfl + +theorem monomialFunctional_symmetric (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : + IsSymmetricMultilinearForm a b V (monomialFunctional a b V φ) := by + intro σ x + simp only [monomialFunctional_apply, symMonomial_permute] + +/-- Monomial values determine every linear map out of a symmetric power. -/ +theorem linearMap_eq_zero_of_symMonomial (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] {W : Type v} [AddCommGroup W] [Module ℂ W] + (φ : SymPow n V →ₗ[ℂ] W) + (hφ : ∀ x : Fin n → V, φ (symMonomial n V x) = 0) : φ = 0 := by + ext x + change φ x = 0 + obtain ⟨x, hx⟩ := x + induction hx using Submodule.span_induction with + | mem y hy => + obtain ⟨v, rfl⟩ := hy + exact hφ v + | zero => exact map_zero φ + | add x y hx hy ihx ihy => + change φ (⟨x, hx⟩ + ⟨y, hy⟩) = 0 + rw [map_add, ihx, ihy, add_zero] + | smul c x hx ih => + change φ (c • (⟨x, hx⟩ : SymPow n V)) = 0 + rw [map_smul, ih, smul_zero] + +theorem monomialFunctional_eq_zero_iff (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : SymPow a (SymPow b V) →ₗ[ℂ] ℂ) : + monomialFunctional a b V φ = 0 ↔ φ = 0 := by + constructor + · intro h + apply linearMap_eq_zero_of_symMonomial + intro x + exact congrArg (fun T : SymmetricMultilinearForm a b V => T x) h + · rintro rfl + rfl + +/-- Flatten the `a` rows of `b` vector arguments of a form on `SymPow b V`. -/ +def plethysmFormMultilinear (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) : + MultilinearMap ℂ (fun _ : Σ _ : Fin a, Fin b => V) ℂ := + T.compMultilinearMap (fun _ => symMonomialMultilinear b V) + +@[simp] +theorem plethysmFormMultilinear_apply (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (x : (Σ _ : Fin a, Fin b) → V) : + plethysmFormMultilinear a b V T x = + T (fun i => symMonomial b V (fun j => x ⟨i,j⟩)) := rfl + +theorem plethysmFormMultilinear_inner_permute (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (σ : Fin a → Equiv.Perm (Fin b)) (x : (Σ _ : Fin a, Fin b) → V) : + plethysmFormMultilinear a b V T (fun ij => x ⟨ij.1, σ ij.1 ij.2⟩) = + plethysmFormMultilinear a b V T x := by + apply congrArg T + funext i + exact symMonomial_permute b V (σ i) (fun j => x ⟨i,j⟩) + +theorem plethysmFormMultilinear_outer_permute (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) + (σ : Equiv.Perm (Fin a)) (x : (Σ _ : Fin a, Fin b) → V) : + plethysmFormMultilinear a b V T (fun ij => x ⟨σ ij.1, ij.2⟩) = + plethysmFormMultilinear a b V T x := by + exact hT σ (fun i => symMonomial b V (fun j => x ⟨i,j⟩)) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearDescent.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearDescent.lean index fa55dc6e4bc160e2d11eb00639e5a8db3ba2d29d..601913643f31af27fa55855edc6aed1a48f85cb7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearDescent.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearDescent.lean @@ -1,95 +1,95 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Problem346 - -open Function - -universe uR uI uM uN uW - -variable {R : Type uR} [Semiring R] {I : Type uI} - {M : I → Type uM} {N : I → Type uN} {W : Type uW} - [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] - [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] - [AddCommMonoid W] [Module R W] - -/-- A multilinear map constant on the fibers of coordinatewise surjections descends. -/ -def multilinearDescend - (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) - (f : MultilinearMap R M W) - (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) : - MultilinearMap R N W where - toFun y := f (fun i => surjInv (hq i) (y i)) - map_update_add' y i x z := by - let s : ∀ i, N i → M i := fun i => surjInv (hq i) - have hs : ∀ i x, q i (s i x) = x := fun i x => surjInv_eq (hq i) x - have h (t : N i) : - f (fun j => s j (update y i t j)) = f (update (fun j => s j (y j)) i (s i t)) := by - apply hf - intro j - by_cases hji : j = i - · subst j; simp [hs] - · simp [hji, hs] - change f (fun j => s j (update y i (x + z) j)) = - f (fun j => s j (update y i x j)) + f (fun j => s j (update y i z j)) - rw [h, h, h] - have hadd : - f (update (fun j => s j (y j)) i (s i (x + z))) = - f (update (fun j => s j (y j)) i (s i x + s i z)) := by - apply hf - intro j - by_cases hji : j = i - · subst j; simp [hs] - · simp [hji] - rw [hadd, f.map_update_add] - map_update_smul' y i c x := by - let s : ∀ i, N i → M i := fun i => surjInv (hq i) - have hs : ∀ i x, q i (s i x) = x := fun i x => surjInv_eq (hq i) x - have h (t : N i) : - f (fun j => s j (update y i t j)) = f (update (fun j => s j (y j)) i (s i t)) := by - apply hf - intro j - by_cases hji : j = i - · subst j; simp [hs] - · simp [hji, hs] - change f (fun j => s j (update y i (c • x) j)) = - c • f (fun j => s j (update y i x j)) - rw [h, h] - have hsmul : - f (update (fun j => s j (y j)) i (s i (c • x))) = - f (update (fun j => s j (y j)) i (c • s i x)) := by - apply hf - intro j - by_cases hji : j = i - · subst j; simp [hs] - · simp [hji] - rw [hsmul, f.map_update_smul] - -@[simp] -theorem multilinearDescend_apply_image - (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) - (f : MultilinearMap R M W) - (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) - (x : ∀ i, M i) : - multilinearDescend q hq f hf (fun i => q i (x i)) = f x := by - apply hf - intro i - exact surjInv_eq (hq i) _ - -@[simp] -theorem multilinearDescend_compLinearMap - (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) - (f : MultilinearMap R M W) - (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) : - (multilinearDescend q hq f hf).compLinearMap q = f := by - ext x - exact multilinearDescend_apply_image q hq f hf x - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Problem346 + +open Function + +universe uR uI uM uN uW + +variable {R : Type uR} [Semiring R] {I : Type uI} + {M : I → Type uM} {N : I → Type uN} {W : Type uW} + [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] + [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] + [AddCommMonoid W] [Module R W] + +/-- A multilinear map constant on the fibers of coordinatewise surjections descends. -/ +def multilinearDescend + (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) + (f : MultilinearMap R M W) + (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) : + MultilinearMap R N W where + toFun y := f (fun i => surjInv (hq i) (y i)) + map_update_add' y i x z := by + let s : ∀ i, N i → M i := fun i => surjInv (hq i) + have hs : ∀ i x, q i (s i x) = x := fun i x => surjInv_eq (hq i) x + have h (t : N i) : + f (fun j => s j (update y i t j)) = f (update (fun j => s j (y j)) i (s i t)) := by + apply hf + intro j + by_cases hji : j = i + · subst j; simp [hs] + · simp [hji, hs] + change f (fun j => s j (update y i (x + z) j)) = + f (fun j => s j (update y i x j)) + f (fun j => s j (update y i z j)) + rw [h, h, h] + have hadd : + f (update (fun j => s j (y j)) i (s i (x + z))) = + f (update (fun j => s j (y j)) i (s i x + s i z)) := by + apply hf + intro j + by_cases hji : j = i + · subst j; simp [hs] + · simp [hji] + rw [hadd, f.map_update_add] + map_update_smul' y i c x := by + let s : ∀ i, N i → M i := fun i => surjInv (hq i) + have hs : ∀ i x, q i (s i x) = x := fun i x => surjInv_eq (hq i) x + have h (t : N i) : + f (fun j => s j (update y i t j)) = f (update (fun j => s j (y j)) i (s i t)) := by + apply hf + intro j + by_cases hji : j = i + · subst j; simp [hs] + · simp [hji, hs] + change f (fun j => s j (update y i (c • x) j)) = + c • f (fun j => s j (update y i x j)) + rw [h, h] + have hsmul : + f (update (fun j => s j (y j)) i (s i (c • x))) = + f (update (fun j => s j (y j)) i (c • s i x)) := by + apply hf + intro j + by_cases hji : j = i + · subst j; simp [hs] + · simp [hji] + rw [hsmul, f.map_update_smul] + +@[simp] +theorem multilinearDescend_apply_image + (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) + (f : MultilinearMap R M W) + (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) + (x : ∀ i, M i) : + multilinearDescend q hq f hf (fun i => q i (x i)) = f x := by + apply hf + intro i + exact surjInv_eq (hq i) _ + +@[simp] +theorem multilinearDescend_compLinearMap + (q : ∀ i, M i →ₗ[R] N i) (hq : ∀ i, Surjective (q i)) + (f : MultilinearMap R M W) + (hf : ∀ x y, (∀ i, q i (x i) = q i (y i)) → f x = f y) : + (multilinearDescend q hq f hf).compLinearMap q = f := by + ext x + exact multilinearDescend_apply_image q hq f hf x + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearPolynomial.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearPolynomial.lean index 54aa7d5100ae801575af0401ceda7c8c5704b58c..ad97de6b5550866f3a3a48c01cdd0fca0f00785a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearPolynomial.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/MultilinearPolynomial.lean @@ -1,132 +1,132 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 - -universe uι uκ uβ uV -variable {ι : Type uι} {κ : Type uκ} {β : Type uβ} {V : Type uV} -variable [Fintype ι] [Fintype κ] [AddCommGroup V] [Module ℂ V] - -/-- The scalar polynomial obtained by feeding a multilinear form vector variables, -with `block i` specifying which vector variable occurs in its `i`th argument. -/ -def multilinearPolynomial (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) : MvPolynomial (β × κ) ℂ := by - classical - exact ∑ k : ι → κ, - MvPolynomial.C (L (fun i => e (k i))) * - ∏ i, MvPolynomial.X (block i, k i) - -/-- Evaluation of the multilinear polynomial on arbitrary coordinate assignments. -/ -theorem eval_multilinearPolynomial - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) (z : β × κ → ℂ) : - MvPolynomial.eval z (multilinearPolynomial L e block) = - L (fun i => ∑ k, z (block i, k) • e k) := by - classical - simp only [multilinearPolynomial, map_sum, map_mul, MvPolynomial.eval_C, - map_prod, MvPolynomial.eval_X] - rw [L.map_sum] - apply Finset.sum_congr rfl - intro k hk - rw [L.map_smul_univ] - simp only [smul_eq_mul] - exact mul_comm _ _ - -/-- With basis coordinates, evaluation is literal evaluation on the chosen vector blocks. -/ -theorem eval_multilinearPolynomial_basis - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : Module.Basis κ ℂ V) (block : ι → β) (v : β → V) : - MvPolynomial.eval (fun z : β × κ => e.repr (v z.1) z.2) - (multilinearPolynomial L e block) = L (fun i => v (block i)) := by - rw [eval_multilinearPolynomial] - simp only [e.sum_repr] - -/-- Pointwise vanishing on vector blocks implies the corresponding polynomial identity. -/ -theorem multilinearPolynomial_eq_zero - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) - (h : ∀ v : β → V, L (fun i => v (block i)) = 0) : - multilinearPolynomial L e block = 0 := by - apply MvPolynomial.funext - intro z - rw [eval_multilinearPolynomial, map_zero] - exact h (fun j => ∑ k, z (j, k) • e k) - -/-- Conversely, a polynomial identity gives the vector-valued identity by basis evaluation. -/ -theorem multilinearPolynomial_eq_zero_iff - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : Module.Basis κ ℂ V) (block : ι → β) : - multilinearPolynomial L e block = 0 ↔ - ∀ v : β → V, L (fun i => v (block i)) = 0 := by - constructor - · intro h v - rw [← eval_multilinearPolynomial_basis L e block v, h, map_zero] - · exact multilinearPolynomial_eq_zero L e block - -/-- Reindexing the labels by a symmetry of the multilinear form leaves its polynomial unchanged. -/ -theorem multilinearPolynomial_perm - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) (σ : Equiv.Perm ι) - (hσ : ∀ x : ι → V, L (fun i => x (σ i)) = L x) : - multilinearPolynomial L e (fun i => block (σ i)) = - multilinearPolynomial L e block := by - apply MvPolynomial.funext - intro z - rw [eval_multilinearPolynomial, eval_multilinearPolynomial] - exact hσ (fun i => ∑ k, z (block i, k) • e k) - -/-- Equal labels make replacing either of two symmetric slots give the same polynomial. -/ -theorem multilinearPolynomial_update_eq [DecidableEq ι] - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) (i j : ι) (dst : β) - (hij : block i = block j) - (hsym : ∀ x : ι → V, L (fun k => x (Equiv.swap i j k)) = L x) : - multilinearPolynomial L e (Function.update block i dst) = - multilinearPolynomial L e (Function.update block j dst) := by - classical - have hp := multilinearPolynomial_perm L e (Function.update block i dst) - (Equiv.swap i j) hsym - have hlabels : - (fun k => Function.update block i dst (Equiv.swap i j k)) = - Function.update block j dst := by - funext k - by_cases hi : k = i - · subst k - by_cases heq : i = j - · subst j - rw [Equiv.swap_apply_left, Function.update_self] - · simp [heq, Ne.symm heq, hij] - · by_cases hj : k = j - · subst k - simp - · simp [Equiv.swap_apply_of_ne_of_ne hi hj, hi, hj] - rw [hlabels] at hp - exact hp.symm - -/-- The derivative's sum over interchangeable source slots is a scalar multiple of one term. -/ -theorem multilinearPolynomial_sum_updates [DecidableEq ι] - (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (e : κ → V) (block : ι → β) (s : Finset ι) (j : ι) (dst : β) - (hlabel : ∀ i ∈ s, block i = block j) - (hsym : ∀ i ∈ s, ∀ x : ι → V, - L (fun k => x (Equiv.swap i j k)) = L x) : - (∑ i ∈ s, multilinearPolynomial L e (Function.update block i dst)) = - (s.card : ℂ) • multilinearPolynomial L e (Function.update block j dst) := by - calc - (∑ i ∈ s, multilinearPolynomial L e (Function.update block i dst)) = - ∑ _i ∈ s, multilinearPolynomial L e (Function.update block j dst) := by - apply Finset.sum_congr rfl - intro i hi - exact multilinearPolynomial_update_eq L e block i j dst (hlabel i hi) (hsym i hi) - _ = _ := by - rw [Finset.sum_const, Nat.cast_smul_eq_nsmul] - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 + +universe uι uκ uβ uV +variable {ι : Type uι} {κ : Type uκ} {β : Type uβ} {V : Type uV} +variable [Fintype ι] [Fintype κ] [AddCommGroup V] [Module ℂ V] + +/-- The scalar polynomial obtained by feeding a multilinear form vector variables, +with `block i` specifying which vector variable occurs in its `i`th argument. -/ +def multilinearPolynomial (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) : MvPolynomial (β × κ) ℂ := by + classical + exact ∑ k : ι → κ, + MvPolynomial.C (L (fun i => e (k i))) * + ∏ i, MvPolynomial.X (block i, k i) + +/-- Evaluation of the multilinear polynomial on arbitrary coordinate assignments. -/ +theorem eval_multilinearPolynomial + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) (z : β × κ → ℂ) : + MvPolynomial.eval z (multilinearPolynomial L e block) = + L (fun i => ∑ k, z (block i, k) • e k) := by + classical + simp only [multilinearPolynomial, map_sum, map_mul, MvPolynomial.eval_C, + map_prod, MvPolynomial.eval_X] + rw [L.map_sum] + apply Finset.sum_congr rfl + intro k hk + rw [L.map_smul_univ] + simp only [smul_eq_mul] + exact mul_comm _ _ + +/-- With basis coordinates, evaluation is literal evaluation on the chosen vector blocks. -/ +theorem eval_multilinearPolynomial_basis + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : Module.Basis κ ℂ V) (block : ι → β) (v : β → V) : + MvPolynomial.eval (fun z : β × κ => e.repr (v z.1) z.2) + (multilinearPolynomial L e block) = L (fun i => v (block i)) := by + rw [eval_multilinearPolynomial] + simp only [e.sum_repr] + +/-- Pointwise vanishing on vector blocks implies the corresponding polynomial identity. -/ +theorem multilinearPolynomial_eq_zero + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) + (h : ∀ v : β → V, L (fun i => v (block i)) = 0) : + multilinearPolynomial L e block = 0 := by + apply MvPolynomial.funext + intro z + rw [eval_multilinearPolynomial, map_zero] + exact h (fun j => ∑ k, z (j, k) • e k) + +/-- Conversely, a polynomial identity gives the vector-valued identity by basis evaluation. -/ +theorem multilinearPolynomial_eq_zero_iff + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : Module.Basis κ ℂ V) (block : ι → β) : + multilinearPolynomial L e block = 0 ↔ + ∀ v : β → V, L (fun i => v (block i)) = 0 := by + constructor + · intro h v + rw [← eval_multilinearPolynomial_basis L e block v, h, map_zero] + · exact multilinearPolynomial_eq_zero L e block + +/-- Reindexing the labels by a symmetry of the multilinear form leaves its polynomial unchanged. -/ +theorem multilinearPolynomial_perm + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) (σ : Equiv.Perm ι) + (hσ : ∀ x : ι → V, L (fun i => x (σ i)) = L x) : + multilinearPolynomial L e (fun i => block (σ i)) = + multilinearPolynomial L e block := by + apply MvPolynomial.funext + intro z + rw [eval_multilinearPolynomial, eval_multilinearPolynomial] + exact hσ (fun i => ∑ k, z (block i, k) • e k) + +/-- Equal labels make replacing either of two symmetric slots give the same polynomial. -/ +theorem multilinearPolynomial_update_eq [DecidableEq ι] + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) (i j : ι) (dst : β) + (hij : block i = block j) + (hsym : ∀ x : ι → V, L (fun k => x (Equiv.swap i j k)) = L x) : + multilinearPolynomial L e (Function.update block i dst) = + multilinearPolynomial L e (Function.update block j dst) := by + classical + have hp := multilinearPolynomial_perm L e (Function.update block i dst) + (Equiv.swap i j) hsym + have hlabels : + (fun k => Function.update block i dst (Equiv.swap i j k)) = + Function.update block j dst := by + funext k + by_cases hi : k = i + · subst k + by_cases heq : i = j + · subst j + rw [Equiv.swap_apply_left, Function.update_self] + · simp [heq, Ne.symm heq, hij] + · by_cases hj : k = j + · subst k + simp + · simp [Equiv.swap_apply_of_ne_of_ne hi hj, hi, hj] + rw [hlabels] at hp + exact hp.symm + +/-- The derivative's sum over interchangeable source slots is a scalar multiple of one term. -/ +theorem multilinearPolynomial_sum_updates [DecidableEq ι] + (L : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (e : κ → V) (block : ι → β) (s : Finset ι) (j : ι) (dst : β) + (hlabel : ∀ i ∈ s, block i = block j) + (hsym : ∀ i ∈ s, ∀ x : ι → V, + L (fun k => x (Equiv.swap i j k)) = L x) : + (∑ i ∈ s, multilinearPolynomial L e (Function.update block i dst)) = + (s.card : ℂ) • multilinearPolynomial L e (Function.update block j dst) := by + calc + (∑ i ∈ s, multilinearPolynomial L e (Function.update block i dst)) = + ∑ _i ∈ s, multilinearPolynomial L e (Function.update block j dst) := by + apply Finset.sum_congr rfl + intro i hi + exact multilinearPolynomial_update_eq L e block i j dst (hlabel i hi) (hsym i hi) + _ = _ := by + rw [Finset.sum_const, Nat.cast_smul_eq_nsmul] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Multiplication.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Multiplication.lean index 5e8ccdb61389b4c80bd5f44a95cdf8b78a92f080..55cad99f85699b865fbadb990d786949d2d942c8 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Multiplication.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Multiplication.lean @@ -1,95 +1,95 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators Pointwise -universe u - -namespace Problem346 - -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Concatenating two lists of factors multiplies their symmetric monomials. -/ -theorem symMonomialRaw_append (m n : ℕ) (v : Fin m → V) (w : Fin n → V) : - symMonomialRaw (m + n) V (Fin.append v w) = - symMonomialRaw m V v * symMonomialRaw n V w := by - simp [symMonomialRaw, Fin.prod_univ_add] - -/-- Products of homogeneous spans have the sum of their degrees. -/ -theorem symPowSubmodule_mul (m n : ℕ) : - symPowSubmodule m V * symPowSubmodule n V = symPowSubmodule (m + n) V := by - unfold symPowSubmodule - rw [Submodule.span_mul_span] - apply congrArg (Submodule.span ℂ) - ext z - constructor - · rintro ⟨x, ⟨v, rfl⟩, y, ⟨w, rfl⟩, rfl⟩ - exact ⟨Fin.append v w, symMonomialRaw_append m n v w⟩ - · rintro ⟨v, rfl⟩ - refine ⟨symMonomialRaw m V (fun i => v (Fin.castAdd n i)), - ⟨_, rfl⟩, symMonomialRaw n V (fun i => v (Fin.natAdd m i)), ⟨_, rfl⟩, ?_⟩ - simp [symMonomialRaw, Fin.prod_univ_add] - -/-- The product of two elements of the indicated homogeneous pieces. -/ -theorem symPow_mul_mem (m n : ℕ) (x : SymPow m V) (y : SymPow n V) : - (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) ∈ - symPowSubmodule (m+n) V := by - rw [← symPowSubmodule_mul] - exact Submodule.mul_mem_mul x.property y.property - -/-- Graded multiplication in the symmetric algebra, as a bilinear map. -/ -def symPowMul (m n : ℕ) : - SymPow m V →ₗ[ℂ] SymPow n V →ₗ[ℂ] SymPow (m+n) V := - LinearMap.mk₂ ℂ - (fun x y => ⟨(x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V), - symPow_mul_mem m n x y⟩) - (by intros; apply Subtype.ext; exact add_mul _ _ _) - (by intros; apply Subtype.ext; exact smul_mul_assoc _ _ _) - (by intros; apply Subtype.ext; exact mul_add _ _ _) - (by intros; apply Subtype.ext; exact mul_smul_comm _ _ _) - -@[simp] theorem symPowMul_coe (m n : ℕ) (x : SymPow m V) (y : SymPow n V) : - (symPowMul m n x y : SymmetricAlgebra ℂ V) = - (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) := rfl - -@[simp] theorem symPowMul_symMonomial (m n : ℕ) (v : Fin m → V) (w : Fin n → V) : - symPowMul m n (symMonomial m V v) (symMonomial n V w) = - symMonomial (m+n) V (Fin.append v w) := by - apply Subtype.ext - exact (symMonomialRaw_append m n v w).symm - -/-- Transport a homogeneous element across an equality of degrees. -/ -def symPowCast {m n : ℕ} (h : m = n) : SymPow m V ≃ₗ[ℂ] SymPow n V := - LinearEquiv.ofEq _ _ (congrArg (fun k => symPowSubmodule k V) h) - -@[simp] theorem symPowCast_coe {m n : ℕ} (h : m = n) (x : SymPow m V) : - (symPowCast h x : SymmetricAlgebra ℂ V) = x := rfl - -@[simp] theorem symPowCast_symMonomial {m n : ℕ} (h : m = n) (v : Fin m → V) : - symPowCast h (symMonomial m V v) = - symMonomial n V (fun i => v (Fin.cast h.symm i)) := by - subst h - rfl - -/-- Multiplication followed by transport to a specified total degree. -/ -def symPowMulCast (m n b : ℕ) (h : m+n=b) : - SymPow m V →ₗ[ℂ] SymPow n V →ₗ[ℂ] SymPow b V := - (LinearMap.llcomp ℂ (SymPow n V) (SymPow (m+n) V) (SymPow b V) - (symPowCast h).toLinearMap).comp (symPowMul m n) - -@[simp] theorem symPowMulCast_coe (m n b : ℕ) (h : m+n=b) - (x : SymPow m V) (y : SymPow n V) : - (symPowMulCast m n b h x y : SymmetricAlgebra ℂ V) = - (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) := rfl - -/-- The raw monomial of a constant tuple is a power. -/ -theorem symMonomialRaw_const (n : ℕ) (v : V) : - symMonomialRaw n V (fun _ => v) = SymmetricAlgebra.ι ℂ V v ^ n := by - simp [symMonomialRaw] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators Pointwise +universe u + +namespace Problem346 + +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Concatenating two lists of factors multiplies their symmetric monomials. -/ +theorem symMonomialRaw_append (m n : ℕ) (v : Fin m → V) (w : Fin n → V) : + symMonomialRaw (m + n) V (Fin.append v w) = + symMonomialRaw m V v * symMonomialRaw n V w := by + simp [symMonomialRaw, Fin.prod_univ_add] + +/-- Products of homogeneous spans have the sum of their degrees. -/ +theorem symPowSubmodule_mul (m n : ℕ) : + symPowSubmodule m V * symPowSubmodule n V = symPowSubmodule (m + n) V := by + unfold symPowSubmodule + rw [Submodule.span_mul_span] + apply congrArg (Submodule.span ℂ) + ext z + constructor + · rintro ⟨x, ⟨v, rfl⟩, y, ⟨w, rfl⟩, rfl⟩ + exact ⟨Fin.append v w, symMonomialRaw_append m n v w⟩ + · rintro ⟨v, rfl⟩ + refine ⟨symMonomialRaw m V (fun i => v (Fin.castAdd n i)), + ⟨_, rfl⟩, symMonomialRaw n V (fun i => v (Fin.natAdd m i)), ⟨_, rfl⟩, ?_⟩ + simp [symMonomialRaw, Fin.prod_univ_add] + +/-- The product of two elements of the indicated homogeneous pieces. -/ +theorem symPow_mul_mem (m n : ℕ) (x : SymPow m V) (y : SymPow n V) : + (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) ∈ + symPowSubmodule (m+n) V := by + rw [← symPowSubmodule_mul] + exact Submodule.mul_mem_mul x.property y.property + +/-- Graded multiplication in the symmetric algebra, as a bilinear map. -/ +def symPowMul (m n : ℕ) : + SymPow m V →ₗ[ℂ] SymPow n V →ₗ[ℂ] SymPow (m+n) V := + LinearMap.mk₂ ℂ + (fun x y => ⟨(x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V), + symPow_mul_mem m n x y⟩) + (by intros; apply Subtype.ext; exact add_mul _ _ _) + (by intros; apply Subtype.ext; exact smul_mul_assoc _ _ _) + (by intros; apply Subtype.ext; exact mul_add _ _ _) + (by intros; apply Subtype.ext; exact mul_smul_comm _ _ _) + +@[simp] theorem symPowMul_coe (m n : ℕ) (x : SymPow m V) (y : SymPow n V) : + (symPowMul m n x y : SymmetricAlgebra ℂ V) = + (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) := rfl + +@[simp] theorem symPowMul_symMonomial (m n : ℕ) (v : Fin m → V) (w : Fin n → V) : + symPowMul m n (symMonomial m V v) (symMonomial n V w) = + symMonomial (m+n) V (Fin.append v w) := by + apply Subtype.ext + exact (symMonomialRaw_append m n v w).symm + +/-- Transport a homogeneous element across an equality of degrees. -/ +def symPowCast {m n : ℕ} (h : m = n) : SymPow m V ≃ₗ[ℂ] SymPow n V := + LinearEquiv.ofEq _ _ (congrArg (fun k => symPowSubmodule k V) h) + +@[simp] theorem symPowCast_coe {m n : ℕ} (h : m = n) (x : SymPow m V) : + (symPowCast h x : SymmetricAlgebra ℂ V) = x := rfl + +@[simp] theorem symPowCast_symMonomial {m n : ℕ} (h : m = n) (v : Fin m → V) : + symPowCast h (symMonomial m V v) = + symMonomial n V (fun i => v (Fin.cast h.symm i)) := by + subst h + rfl + +/-- Multiplication followed by transport to a specified total degree. -/ +def symPowMulCast (m n b : ℕ) (h : m+n=b) : + SymPow m V →ₗ[ℂ] SymPow n V →ₗ[ℂ] SymPow b V := + (LinearMap.llcomp ℂ (SymPow n V) (SymPow (m+n) V) (SymPow b V) + (symPowCast h).toLinearMap).comp (symPowMul m n) + +@[simp] theorem symPowMulCast_coe (m n b : ℕ) (h : m+n=b) + (x : SymPow m V) (y : SymPow n V) : + (symPowMulCast m n b h x y : SymmetricAlgebra ℂ V) = + (x : SymmetricAlgebra ℂ V) * (y : SymmetricAlgebra ℂ V) := rfl + +/-- The raw monomial of a constant tuple is a power. -/ +theorem symMonomialRaw_const (n : ℕ) (v : V) : + symMonomialRaw n V (fun _ => v) = SymmetricAlgebra.ι ℂ V v ^ n := by + simp [symMonomialRaw] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Naturality.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Naturality.lean index bb04f2848d7f43eb7a25e2f3ee5001630a0def3e..d6e22e8f8c5456c03ddb163f70a79d065d42a6ab 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Naturality.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Naturality.lean @@ -1,76 +1,76 @@ -import OAI.RepresentationTheory.FoulkesHowe.Actions -import OAI.RepresentationTheory.FoulkesHowe.Spanning - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u v w -namespace Problem346 - -variable {V : Type u} {W : Type v} {U : Type w} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - [AddCommGroup U] [Module ℂ U] - -/-- The map on a plethysm induced by a linear map on the original space. -/ -def plethysmMap (outer inner : ℕ) (f : V →ₗ[ℂ] W) : - SymPow outer (SymPow inner V) →ₗ[ℂ] SymPow outer (SymPow inner W) := - symPowMap outer (symPowMap inner f) - -@[simp] theorem plethysmMap_symMonomial (outer inner : ℕ) (f : V →ₗ[ℂ] W) - (x : Fin outer → Fin inner → V) : - plethysmMap outer inner f - (symMonomial outer (SymPow inner V) (fun i => symMonomial inner V (x i))) = - symMonomial outer (SymPow inner W) - (fun i => symMonomial inner W (fun j => f (x i j))) := by - simp [plethysmMap] - -@[simp] theorem plethysmMap_id (outer inner : ℕ) : - plethysmMap outer inner (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by - simp [plethysmMap] - -@[simp] theorem plethysmMap_comp (outer inner : ℕ) (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : - plethysmMap outer inner (g.comp f) = - (plethysmMap outer inner g).comp (plethysmMap outer inner f) := by - simp [plethysmMap] - -@[simp] theorem plethysmMap_equiv (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : - plethysmMap outer inner g.toLinearMap = plethysmAction outer inner g := rfl - -/-- The explicitly normalized Foulkes formula is natural in the vector space. -/ -theorem plethysmMap_foulkesFormula (a b : ℕ) (f : V →ₗ[ℂ] W) - (x : Fin b → Fin a → V) : - plethysmMap a b f (foulkesFormula a b V x) = - foulkesFormula a b W (fun j i => f (x j i)) := by - classical - unfold foulkesFormula - rw [map_smul, map_sum] - congr 1 - apply Finset.sum_congr rfl - intro σ _ - exact plethysmMap_symMonomial a b f (fun i j => x j ((σ j) i)) - -/-- Any two maps satisfying the canonical formula form a natural square. -/ -theorem IsFoulkesMap.natural {a b : ℕ} - {μV : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} - {μW : SymPow b (SymPow a W) →ₗ[ℂ] SymPow a (SymPow b W)} - (hV : IsFoulkesMap a b V μV) (hW : IsFoulkesMap a b W μW) - (f : V →ₗ[ℂ] W) : - (plethysmMap a b f).comp μV = μW.comp (plethysmMap b a f) := by - apply plethysm_linearMap_ext a b V - intro x - simp only [LinearMap.comp_apply, plethysmMap_symMonomial] - rw [hV, hW, plethysmMap_foulkesFormula] - -/-- Every canonical Foulkes map is GL-equivariant. -/ -theorem IsFoulkesMap.commutes {a b : ℕ} - {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} - (hμ : IsFoulkesMap a b V μ) (g : V ≃ₗ[ℂ] V) : - (plethysmAction a b g).comp μ = μ.comp (plethysmAction b a g) := - hμ.natural hμ g.toLinearMap - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Actions +import OAI.RepresentationTheory.FoulkesHowe.Spanning + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u v w +namespace Problem346 + +variable {V : Type u} {W : Type v} {U : Type w} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + [AddCommGroup U] [Module ℂ U] + +/-- The map on a plethysm induced by a linear map on the original space. -/ +def plethysmMap (outer inner : ℕ) (f : V →ₗ[ℂ] W) : + SymPow outer (SymPow inner V) →ₗ[ℂ] SymPow outer (SymPow inner W) := + symPowMap outer (symPowMap inner f) + +@[simp] theorem plethysmMap_symMonomial (outer inner : ℕ) (f : V →ₗ[ℂ] W) + (x : Fin outer → Fin inner → V) : + plethysmMap outer inner f + (symMonomial outer (SymPow inner V) (fun i => symMonomial inner V (x i))) = + symMonomial outer (SymPow inner W) + (fun i => symMonomial inner W (fun j => f (x i j))) := by + simp [plethysmMap] + +@[simp] theorem plethysmMap_id (outer inner : ℕ) : + plethysmMap outer inner (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by + simp [plethysmMap] + +@[simp] theorem plethysmMap_comp (outer inner : ℕ) (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : + plethysmMap outer inner (g.comp f) = + (plethysmMap outer inner g).comp (plethysmMap outer inner f) := by + simp [plethysmMap] + +@[simp] theorem plethysmMap_equiv (outer inner : ℕ) (g : V ≃ₗ[ℂ] V) : + plethysmMap outer inner g.toLinearMap = plethysmAction outer inner g := rfl + +/-- The explicitly normalized Foulkes formula is natural in the vector space. -/ +theorem plethysmMap_foulkesFormula (a b : ℕ) (f : V →ₗ[ℂ] W) + (x : Fin b → Fin a → V) : + plethysmMap a b f (foulkesFormula a b V x) = + foulkesFormula a b W (fun j i => f (x j i)) := by + classical + unfold foulkesFormula + rw [map_smul, map_sum] + congr 1 + apply Finset.sum_congr rfl + intro σ _ + exact plethysmMap_symMonomial a b f (fun i j => x j ((σ j) i)) + +/-- Any two maps satisfying the canonical formula form a natural square. -/ +theorem IsFoulkesMap.natural {a b : ℕ} + {μV : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} + {μW : SymPow b (SymPow a W) →ₗ[ℂ] SymPow a (SymPow b W)} + (hV : IsFoulkesMap a b V μV) (hW : IsFoulkesMap a b W μW) + (f : V →ₗ[ℂ] W) : + (plethysmMap a b f).comp μV = μW.comp (plethysmMap b a f) := by + apply plethysm_linearMap_ext a b V + intro x + simp only [LinearMap.comp_apply, plethysmMap_symMonomial] + rw [hV, hW, plethysmMap_foulkesFormula] + +/-- Every canonical Foulkes map is GL-equivariant. -/ +theorem IsFoulkesMap.commutes {a b : ℕ} + {μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} + (hμ : IsFoulkesMap a b V μ) (g : V ≃ₗ[ℂ] V) : + (plethysmAction a b g).comp μ = μ.comp (plethysmAction b a g) := + hμ.natural hμ g.toLinearMap + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingConstruction.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingConstruction.lean index a06fe05b9f5ff97ce0ed05d6b71a63b12f319ddd..05696ba3b3d6dfc565952903a8bd6cb88b22f5ae 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingConstruction.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingConstruction.lean @@ -1,149 +1,149 @@ -import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing -import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift -import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual -import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension -import OAI.RepresentationTheory.FoulkesHowe.Functoriality -import OAI.RepresentationTheory.FoulkesHowe.Spanning -import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual - -namespace OAI - -noncomputable section -open scoped BigOperators -namespace Problem346.PairingConstruction - -universe u v -variable {X : Type u} {Y : Type v} - [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] - -/-- Descend the right-hand family of the normalized permanent. -/ -def leftMultilinear (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : - MultilinearMap ℂ (fun _ : Fin n => X) (Module.Dual ℂ (SymPow n Y)) := - (symPowLiftLinear n Y ℂ).compMultilinearMap - ((permanentPairingMultilinear n B).codRestrict - (symmetricMultilinearSubmodule n Y ℂ) (by - intro x σ y - exact permanentPairingMultilinear_perm_right n B x y σ)) - -@[simp] theorem leftMultilinear_apply_monomial (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : - leftMultilinear n B x (symMonomial n Y y) = - permanentPairing n (fun x y => B x y) x y := by - simp only [leftMultilinear, LinearMap.compMultilinearMap_apply, - symPowLiftLinear_symMonomial] - exact permanentPairingMultilinear_apply n B x y - -theorem leftMultilinear_symmetric (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) - (σ : Equiv.Perm (Fin n)) (x : Fin n → X) : - leftMultilinear n B (fun i => x (σ i)) = leftMultilinear n B x := by - apply symPow_linearMap_ext n Y - intro y - simp only [leftMultilinear_apply_monomial] - exact permanentPairing_perm_left n (fun x y => B x y) x y σ - -/-- The canonical bilinear pairing induced on homogeneous symmetric powers. -/ -def pairing (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : - SymPow n X →ₗ[ℂ] Module.Dual ℂ (SymPow n Y) := - symPowLift (leftMultilinear n B) (leftMultilinear_symmetric n B) - -@[simp] theorem pairing_monomials (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) - (x : Fin n → X) (y : Fin n → Y) : - pairing n B (symMonomial n X x) (symMonomial n Y y) = - permanentPairing n (fun x y => B x y) x y := by - simp [pairing] - -variable (V : Type u) [AddCommGroup V] [Module ℂ V] - -/-- The evaluation pairing of a symmetric power and the symmetric power of its dual. -/ -def dualMap (n : ℕ) : - SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V) := - pairing n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) - -@[simp] theorem dualMap_monomials (n : ℕ) - (x : Fin n → Module.Dual ℂ V) (y : Fin n → V) : - dualMap V n (symMonomial n (Module.Dual ℂ V) x) (symMonomial n V y) = - permanentPairing n (fun f v => f v) x y := by - exact pairing_monomials n LinearMap.id x y - -theorem dualMap_pure (n : ℕ) (p : SymPow n (Module.Dual ℂ V)) (x : V) : - dualMap V n p (symMonomial n V (fun _ => x)) = - SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val := by - have h : (LinearMap.applyₗ (symMonomial n V (fun _ => x))).comp (dualMap V n) = - (SymmetricAlgebra.lift (Module.Dual.eval ℂ V x)).toLinearMap.domRestrict - (symPowSubmodule n (Module.Dual ℂ V)) := by - apply symPow_linearMap_ext n (Module.Dual ℂ V) - intro f - change dualMap V n (symMonomial n (Module.Dual ℂ V) f) - (symMonomial n V (fun _ => x)) = _ - rw [dualMap_monomials, permanentPairing_const_right] - simp [symMonomial, symMonomialRaw] - exact LinearMap.congr_fun h p - -theorem dualMap_injective [FiniteDimensional ℂ V] (n : ℕ) : - Function.Injective (dualMap V n) := - symPowDual_injective_of_pure_evaluation V n (dualMap V n) (dualMap_pure V n) - -theorem dual_finrank (n : ℕ) [FiniteDimensional ℂ V] : - Module.finrank ℂ (SymPow n (Module.Dual ℂ V)) = - Module.finrank ℂ (Module.Dual ℂ (SymPow n V)) := by - rw [Subspace.dual_finrank_eq] - let e : Module.Dual ℂ V ≃ₗ[ℂ] V := - LinearEquiv.ofFinrankEq _ _ Subspace.dual_finrank_eq - exact (symPowEquiv n e).finrank_eq - -/-- Perfect duality for homogeneous symmetric powers in finite dimension. -/ -def dualEquiv [FiniteDimensional ℂ V] (n : ℕ) : - SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := - (dualMap V n).linearEquivOfInjective (dualMap_injective V n) (dual_finrank V n) - -@[simp] theorem dualEquiv_apply [FiniteDimensional ℂ V] (n : ℕ) - (p : SymPow n (Module.Dual ℂ V)) : dualEquiv V n p = dualMap V n p := rfl - -theorem dualMap_natural (n : ℕ) (f : V →ₗ[ℂ] V) - (p : SymPow n (Module.Dual ℂ V)) (q : SymPow n V) : - dualMap V n (symPowMap n f.dualMap p) q = - dualMap V n p (symPowMap n f q) := by - have h : (dualMap V n).comp (symPowMap n f.dualMap) = - (symPowMap n f).dualMap.comp (dualMap V n) := by - apply symPow_linearMap_ext n (Module.Dual ℂ V) - intro x - apply symPow_linearMap_ext n V - intro y - simp only [LinearMap.comp_apply, symPowMap_symMonomial, - LinearMap.dualMap_apply, dualMap_monomials] - rfl - exact LinearMap.congr_fun (LinearMap.congr_fun h p) q - -theorem dualEquiv_natural [FiniteDimensional ℂ V] (n : ℕ) (f : V →ₗ[ℂ] V) - (p : SymPow n (Module.Dual ℂ V)) (q : SymPow n V) : - dualEquiv V n (symPowMap n f.dualMap p) q = - dualEquiv V n p (symPowMap n f q) := - dualMap_natural V n f p q - -/-- Canonical surjectivity on the dual space gives the equivariant comparison. -/ -theorem comparison_of_surjection [FiniteDimensional ℂ V] (a b : ℕ) - (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] - SymPow a (SymPow b (Module.Dual ℂ V)), - IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : - ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), - IsGLEquivariantEmbedding a b V ι := by - apply PlethysmDual.comparison_of_dual_charts a b - (PlethysmDual.plethysmDualEquivOf b a (dualEquiv V a) (dualEquiv (SymPow a V) b)) - (PlethysmDual.plethysmDualEquivOf a b (dualEquiv V b) (dualEquiv (SymPow b V) a)) - · intro g - exact PlethysmDual.plethysmDualEquivOf_adjoint b a - (dualEquiv V a) (dualEquiv (SymPow a V) b) g - (dualEquiv_natural V a g.toLinearMap) - (dualEquiv_natural (SymPow a V) b (symPowMap a g.toLinearMap)) - · intro g - exact PlethysmDual.plethysmDualEquivOf_adjoint a b - (dualEquiv V b) (dualEquiv (SymPow b V) a) g - (dualEquiv_natural V b g.toLinearMap) - (dualEquiv_natural (SymPow b V) a (symPowMap b g.toLinearMap)) - · exact hsurj - -end Problem346.PairingConstruction - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing +import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift +import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual +import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension +import OAI.RepresentationTheory.FoulkesHowe.Functoriality +import OAI.RepresentationTheory.FoulkesHowe.Spanning +import OAI.RepresentationTheory.FoulkesHowe.PlethysmDual + +namespace OAI + +noncomputable section +open scoped BigOperators +namespace Problem346.PairingConstruction + +universe u v +variable {X : Type u} {Y : Type v} + [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] + +/-- Descend the right-hand family of the normalized permanent. -/ +def leftMultilinear (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : + MultilinearMap ℂ (fun _ : Fin n => X) (Module.Dual ℂ (SymPow n Y)) := + (symPowLiftLinear n Y ℂ).compMultilinearMap + ((permanentPairingMultilinear n B).codRestrict + (symmetricMultilinearSubmodule n Y ℂ) (by + intro x σ y + exact permanentPairingMultilinear_perm_right n B x y σ)) + +@[simp] theorem leftMultilinear_apply_monomial (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : + leftMultilinear n B x (symMonomial n Y y) = + permanentPairing n (fun x y => B x y) x y := by + simp only [leftMultilinear, LinearMap.compMultilinearMap_apply, + symPowLiftLinear_symMonomial] + exact permanentPairingMultilinear_apply n B x y + +theorem leftMultilinear_symmetric (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) + (σ : Equiv.Perm (Fin n)) (x : Fin n → X) : + leftMultilinear n B (fun i => x (σ i)) = leftMultilinear n B x := by + apply symPow_linearMap_ext n Y + intro y + simp only [leftMultilinear_apply_monomial] + exact permanentPairing_perm_left n (fun x y => B x y) x y σ + +/-- The canonical bilinear pairing induced on homogeneous symmetric powers. -/ +def pairing (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : + SymPow n X →ₗ[ℂ] Module.Dual ℂ (SymPow n Y) := + symPowLift (leftMultilinear n B) (leftMultilinear_symmetric n B) + +@[simp] theorem pairing_monomials (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) + (x : Fin n → X) (y : Fin n → Y) : + pairing n B (symMonomial n X x) (symMonomial n Y y) = + permanentPairing n (fun x y => B x y) x y := by + simp [pairing] + +variable (V : Type u) [AddCommGroup V] [Module ℂ V] + +/-- The evaluation pairing of a symmetric power and the symmetric power of its dual. -/ +def dualMap (n : ℕ) : + SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V) := + pairing n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) + +@[simp] theorem dualMap_monomials (n : ℕ) + (x : Fin n → Module.Dual ℂ V) (y : Fin n → V) : + dualMap V n (symMonomial n (Module.Dual ℂ V) x) (symMonomial n V y) = + permanentPairing n (fun f v => f v) x y := by + exact pairing_monomials n LinearMap.id x y + +theorem dualMap_pure (n : ℕ) (p : SymPow n (Module.Dual ℂ V)) (x : V) : + dualMap V n p (symMonomial n V (fun _ => x)) = + SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val := by + have h : (LinearMap.applyₗ (symMonomial n V (fun _ => x))).comp (dualMap V n) = + (SymmetricAlgebra.lift (Module.Dual.eval ℂ V x)).toLinearMap.domRestrict + (symPowSubmodule n (Module.Dual ℂ V)) := by + apply symPow_linearMap_ext n (Module.Dual ℂ V) + intro f + change dualMap V n (symMonomial n (Module.Dual ℂ V) f) + (symMonomial n V (fun _ => x)) = _ + rw [dualMap_monomials, permanentPairing_const_right] + simp [symMonomial, symMonomialRaw] + exact LinearMap.congr_fun h p + +theorem dualMap_injective [FiniteDimensional ℂ V] (n : ℕ) : + Function.Injective (dualMap V n) := + symPowDual_injective_of_pure_evaluation V n (dualMap V n) (dualMap_pure V n) + +theorem dual_finrank (n : ℕ) [FiniteDimensional ℂ V] : + Module.finrank ℂ (SymPow n (Module.Dual ℂ V)) = + Module.finrank ℂ (Module.Dual ℂ (SymPow n V)) := by + rw [Subspace.dual_finrank_eq] + let e : Module.Dual ℂ V ≃ₗ[ℂ] V := + LinearEquiv.ofFinrankEq _ _ Subspace.dual_finrank_eq + exact (symPowEquiv n e).finrank_eq + +/-- Perfect duality for homogeneous symmetric powers in finite dimension. -/ +def dualEquiv [FiniteDimensional ℂ V] (n : ℕ) : + SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := + (dualMap V n).linearEquivOfInjective (dualMap_injective V n) (dual_finrank V n) + +@[simp] theorem dualEquiv_apply [FiniteDimensional ℂ V] (n : ℕ) + (p : SymPow n (Module.Dual ℂ V)) : dualEquiv V n p = dualMap V n p := rfl + +theorem dualMap_natural (n : ℕ) (f : V →ₗ[ℂ] V) + (p : SymPow n (Module.Dual ℂ V)) (q : SymPow n V) : + dualMap V n (symPowMap n f.dualMap p) q = + dualMap V n p (symPowMap n f q) := by + have h : (dualMap V n).comp (symPowMap n f.dualMap) = + (symPowMap n f).dualMap.comp (dualMap V n) := by + apply symPow_linearMap_ext n (Module.Dual ℂ V) + intro x + apply symPow_linearMap_ext n V + intro y + simp only [LinearMap.comp_apply, symPowMap_symMonomial, + LinearMap.dualMap_apply, dualMap_monomials] + rfl + exact LinearMap.congr_fun (LinearMap.congr_fun h p) q + +theorem dualEquiv_natural [FiniteDimensional ℂ V] (n : ℕ) (f : V →ₗ[ℂ] V) + (p : SymPow n (Module.Dual ℂ V)) (q : SymPow n V) : + dualEquiv V n (symPowMap n f.dualMap p) q = + dualEquiv V n p (symPowMap n f q) := + dualMap_natural V n f p q + +/-- Canonical surjectivity on the dual space gives the equivariant comparison. -/ +theorem comparison_of_surjection [FiniteDimensional ℂ V] (a b : ℕ) + (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] + SymPow a (SymPow b (Module.Dual ℂ V)), + IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : + ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), + IsGLEquivariantEmbedding a b V ι := by + apply PlethysmDual.comparison_of_dual_charts a b + (PlethysmDual.plethysmDualEquivOf b a (dualEquiv V a) (dualEquiv (SymPow a V) b)) + (PlethysmDual.plethysmDualEquivOf a b (dualEquiv V b) (dualEquiv (SymPow b V) a)) + · intro g + exact PlethysmDual.plethysmDualEquivOf_adjoint b a + (dualEquiv V a) (dualEquiv (SymPow a V) b) g + (dualEquiv_natural V a g.toLinearMap) + (dualEquiv_natural (SymPow a V) b (symPowMap a g.toLinearMap)) + · intro g + exact PlethysmDual.plethysmDualEquivOf_adjoint a b + (dualEquiv V b) (dualEquiv (SymPow b V) a) g + (dualEquiv_natural V b g.toLinearMap) + (dualEquiv_natural (SymPow b V) a (symPowMap b g.toLinearMap)) + · exact hsurj + +end Problem346.PairingConstruction + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingLift.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingLift.lean index e0f4c89b9fb2729905ba020e4d9a8b2c4e6cdb46..5879df7252210e2b539d2a8f785d9bc514676fee 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingLift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingLift.lean @@ -1,54 +1,54 @@ -import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift - -namespace OAI - -noncomputable section -universe u v w -namespace Problem346 - -/-- Descend a separately symmetric multilinear pairing in both blocks. -/ -theorem exists_symPow_bilinear_lift (n m : ℕ) (V : Type u) (W : Type v) - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (Q : MultilinearMap ℂ (fun _ : Fin n => V) - (MultilinearMap ℂ (fun _ : Fin m => W) ℂ)) - (hleft : ∀ (σ : Equiv.Perm (Fin n)) x, - Q (fun i => x (σ i)) = Q x) - (hright : ∀ x (σ : Equiv.Perm (Fin m)) y, - Q x (fun i => y (σ i)) = Q x y) : - ∃ B : SymPow n V →ₗ[ℂ] Module.Dual ℂ (SymPow m W), - ∀ x y, B (symMonomial n V x) (symMonomial m W y) = Q x y := by - classical - choose G hG using fun x => exists_symPow_lift (Q x) (hright x) - let F : MultilinearMap ℂ (fun _ : Fin n => V) (Module.Dual ℂ (SymPow m W)) := - { toFun := G - map_update_add' := by - intro _ x i a b - apply SymmetricLift.linearMap_ext - intro y - simp only [LinearMap.add_apply, hG] - exact congrArg (fun T : MultilinearMap ℂ (fun _ : Fin m => W) ℂ => T y) - (Q.map_update_add x i a b) - map_update_smul' := by - intro _ x i c a - apply SymmetricLift.linearMap_ext - intro y - simp only [LinearMap.smul_apply, hG] - exact congrArg (fun T : MultilinearMap ℂ (fun _ : Fin m => W) ℂ => T y) - (Q.map_update_smul x i c a) } - have hF : ∀ (σ : Equiv.Perm (Fin n)) x, F (fun i => x (σ i)) = F x := by - intro σ x - apply SymmetricLift.linearMap_ext - intro y - change G (fun i => x (σ i)) (symMonomial m W y) = G x (symMonomial m W y) - rw [hG, hG, hleft] - obtain ⟨B, hB⟩ := exists_symPow_lift F hF - refine ⟨B, ?_⟩ - intro x y - rw [hB] - exact hG x y - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SymmetricLift + +namespace OAI + +noncomputable section +universe u v w +namespace Problem346 + +/-- Descend a separately symmetric multilinear pairing in both blocks. -/ +theorem exists_symPow_bilinear_lift (n m : ℕ) (V : Type u) (W : Type v) + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (Q : MultilinearMap ℂ (fun _ : Fin n => V) + (MultilinearMap ℂ (fun _ : Fin m => W) ℂ)) + (hleft : ∀ (σ : Equiv.Perm (Fin n)) x, + Q (fun i => x (σ i)) = Q x) + (hright : ∀ x (σ : Equiv.Perm (Fin m)) y, + Q x (fun i => y (σ i)) = Q x y) : + ∃ B : SymPow n V →ₗ[ℂ] Module.Dual ℂ (SymPow m W), + ∀ x y, B (symMonomial n V x) (symMonomial m W y) = Q x y := by + classical + choose G hG using fun x => exists_symPow_lift (Q x) (hright x) + let F : MultilinearMap ℂ (fun _ : Fin n => V) (Module.Dual ℂ (SymPow m W)) := + { toFun := G + map_update_add' := by + intro _ x i a b + apply SymmetricLift.linearMap_ext + intro y + simp only [LinearMap.add_apply, hG] + exact congrArg (fun T : MultilinearMap ℂ (fun _ : Fin m => W) ℂ => T y) + (Q.map_update_add x i a b) + map_update_smul' := by + intro _ x i c a + apply SymmetricLift.linearMap_ext + intro y + simp only [LinearMap.smul_apply, hG] + exact congrArg (fun T : MultilinearMap ℂ (fun _ : Fin m => W) ℂ => T y) + (Q.map_update_smul x i c a) } + have hF : ∀ (σ : Equiv.Perm (Fin n)) x, F (fun i => x (σ i)) = F x := by + intro σ x + apply SymmetricLift.linearMap_ext + intro y + change G (fun i => x (σ i)) (symMonomial m W y) = G x (symMonomial m W y) + rw [hG, hG, hleft] + obtain ⟨B, hB⟩ := exists_symPow_lift F hF + refine ⟨B, ?_⟩ + intro x y + rw [hB] + exact hG x y + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingPerfection.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingPerfection.lean index ff55cd523a953dc33ece8e1a35e59904a3643e9b..8ff2cc8e89b631f54fe3db0ef25e9a0601149f6f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PairingPerfection.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PairingPerfection.lean @@ -1,47 +1,47 @@ -import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual -import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension - -namespace OAI - -noncomputable section -universe u -namespace Problem346 - -variable (V : Type u) [AddCommGroup V] [Module ℂ V] - -/-- Evaluation on pure dual powers detects the second variable of a pairing. -/ -theorem symPowDual_flip_injective_of_pure_evaluation (n : ℕ) - (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) - (hB : ∀ (φ : Module.Dual ℂ V) (p : SymPow n V), - B (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = - SymmetricAlgebra.lift φ p.val) : - Function.Injective B.flip := by - intro p q hpq - apply Subtype.ext - apply sub_eq_zero.mp - apply symAlg_eq_zero_of_lift_eq_zero V - intro φ - rw [map_sub, ← hB φ p, ← hB φ q] - have h := congrArg - (fun f : Module.Dual ℂ (SymPow n (Module.Dual ℂ V)) => - f (symMonomial n (Module.Dual ℂ V) (fun _ => φ))) hpq - exact sub_eq_zero.mpr h - -/-- Pure-power evaluation identities characterize a perfect symmetric-power pairing. -/ -theorem symPowDual_isPerfPair_of_pure_evaluation [FiniteDimensional ℂ V] (n : ℕ) - (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) - (hRight : ∀ (p : SymPow n (Module.Dual ℂ V)) (x : V), - B p (symMonomial n V (fun _ => x)) = - SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val) - (hLeft : ∀ (φ : Module.Dual ℂ V) (p : SymPow n V), - B (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = - SymmetricAlgebra.lift φ p.val) : B.IsPerfPair := - LinearMap.IsPerfPair.of_injective' - (symPowDual_injective_of_pure_evaluation V n B hRight) - (symPowDual_flip_injective_of_pure_evaluation V n B hLeft) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SymmetricDual +import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension + +namespace OAI + +noncomputable section +universe u +namespace Problem346 + +variable (V : Type u) [AddCommGroup V] [Module ℂ V] + +/-- Evaluation on pure dual powers detects the second variable of a pairing. -/ +theorem symPowDual_flip_injective_of_pure_evaluation (n : ℕ) + (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) + (hB : ∀ (φ : Module.Dual ℂ V) (p : SymPow n V), + B (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = + SymmetricAlgebra.lift φ p.val) : + Function.Injective B.flip := by + intro p q hpq + apply Subtype.ext + apply sub_eq_zero.mp + apply symAlg_eq_zero_of_lift_eq_zero V + intro φ + rw [map_sub, ← hB φ p, ← hB φ q] + have h := congrArg + (fun f : Module.Dual ℂ (SymPow n (Module.Dual ℂ V)) => + f (symMonomial n (Module.Dual ℂ V) (fun _ => φ))) hpq + exact sub_eq_zero.mpr h + +/-- Pure-power evaluation identities characterize a perfect symmetric-power pairing. -/ +theorem symPowDual_isPerfPair_of_pure_evaluation [FiniteDimensional ℂ V] (n : ℕ) + (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) + (hRight : ∀ (p : SymPow n (Module.Dual ℂ V)) (x : V), + B p (symMonomial n V (fun _ => x)) = + SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val) + (hLeft : ∀ (φ : Module.Dual ℂ V) (p : SymPow n V), + B (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = + SymmetricAlgebra.lift φ p.val) : B.IsPerfPair := + LinearMap.IsPerfPair.of_injective' + (symPowDual_injective_of_pure_evaluation V n B hRight) + (symPowDual_flip_injective_of_pure_evaluation V n B hLeft) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PermanentPairing.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PermanentPairing.lean index b82db84e5d3767398296108886999b3b3211d9b1..78f1b1f905bf9756dc18d4326b5ee59711176c9f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PermanentPairing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PermanentPairing.lean @@ -1,167 +1,167 @@ -import Mathlib - -namespace OAI - -noncomputable section - -open scoped BigOperators - -namespace Problem346 - -universe u v w z - -/-- The normalized permanent of a pairing on two indexed families. -/ -def permanentPairing {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) : ℂ := - (n.factorial : ℂ)⁻¹ * ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) - -theorem permanentPairing_perm_right {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) - (τ : Equiv.Perm (Fin n)) : - permanentPairing n B x (fun i => y (τ i)) = permanentPairing n B x y := by - classical - unfold permanentPairing - congr 1 - simpa only [Equiv.coe_mulLeft, Equiv.Perm.mul_apply] using - (Equiv.sum_comp (Equiv.mulLeft τ) - (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i)))) - -theorem permanentPairing_perm_left {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) - (τ : Equiv.Perm (Fin n)) : - permanentPairing n B (fun i => x (τ i)) y = permanentPairing n B x y := by - classical - unfold permanentPairing - congr 1 - calc - (∑ σ : Equiv.Perm (Fin n), ∏ i, B (x (τ i)) (y (σ i))) = - ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y ((σ * τ⁻¹) i)) := by - apply Finset.sum_congr rfl - intro σ _ - simpa only [Equiv.Perm.mul_apply, Equiv.Perm.inv_def, Equiv.symm_apply_apply] using - (Equiv.prod_comp τ (fun i => B (x i) (y ((σ * τ⁻¹) i)))) - _ = ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) := by - simpa only [Equiv.coe_mulRight] using - (Equiv.sum_comp (Equiv.mulRight τ⁻¹) - (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i)))) - -/-- Transposing the underlying pairing transposes the two families. -/ -theorem permanentPairing_flip {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) : - permanentPairing n (fun y x => B x y) y x = permanentPairing n B x y := by - classical - unfold permanentPairing - congr 1 - calc - (∑ σ : Equiv.Perm (Fin n), ∏ i, B (x (σ i)) (y i)) = - ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ⁻¹ i)) := by - apply Finset.sum_congr rfl - intro σ _ - simpa only [Equiv.Perm.inv_def, Equiv.symm_apply_apply] using - (Equiv.prod_comp σ (fun i => B (x i) (y (σ⁻¹ i)))) - _ = ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) := by - exact Equiv.sum_comp (Equiv.inv (Equiv.Perm (Fin n))) - (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i))) - -@[simp] theorem permanentPairing_const_right {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : Fin n → X) (y : Y) : - permanentPairing n B x (fun _ => y) = ∏ i, B (x i) y := by - classical - have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n - simp [permanentPairing, Fintype.card_perm, hn] - -@[simp] theorem permanentPairing_const_left {X : Type u} {Y : Type v} (n : ℕ) - (B : X → Y → ℂ) (x : X) (y : Fin n → Y) : - permanentPairing n B (fun _ => x) y = ∏ i, B x (y i) := by - rw [← permanentPairing_flip n B] - exact permanentPairing_const_right n (fun y x => B x y) y x - -/-- Moving a map across each scalar pairing moves it across the normalized permanent. -/ -theorem permanentPairing_natural {X : Type u} {Y : Type v} - {X' : Type w} {Y' : Type z} (n : ℕ) - (B : X → Y → ℂ) (B' : X' → Y' → ℂ) - (f : X → X') (g : Y' → Y) - (h : ∀ x y, B' (f x) y = B x (g y)) - (x : Fin n → X) (y : Fin n → Y') : - permanentPairing n B' (fun i => f (x i)) y = - permanentPairing n B x (fun i => g (y i)) := by - classical - simp only [permanentPairing, h] - -section Multilinear - -variable {X : Type u} {Y : Type v} - [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] - -/-- The permanent pairing as a multilinear map in its right family. -/ -def permanentPairingRight (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) - (x : Fin n → X) : MultilinearMap ℂ (fun _ : Fin n => Y) ℂ := - (n.factorial : ℂ)⁻¹ • - ∑ σ : Equiv.Perm (Fin n), - ((MultilinearMap.mkPiAlgebra ℂ (Fin n) ℂ).compLinearMap (fun i => B (x i))).domDomCongr σ - -@[simp] theorem permanentPairingRight_apply (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : - permanentPairingRight n B x y = permanentPairing n (fun x y => B x y) x y := by - classical - simp [permanentPairingRight, permanentPairing] - -/-- The permanent pairing as a multilinear map in its left family. -/ -def permanentPairingLeft (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) - (y : Fin n → Y) : MultilinearMap ℂ (fun _ : Fin n => X) ℂ := - (n.factorial : ℂ)⁻¹ • - ∑ σ : Equiv.Perm (Fin n), - (MultilinearMap.mkPiAlgebra ℂ (Fin n) ℂ).compLinearMap - (fun i => B.flip (y (σ i))) - -@[simp] theorem permanentPairingLeft_apply (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : - permanentPairingLeft n B y x = permanentPairing n (fun x y => B x y) x y := by - classical - simp [permanentPairingLeft, permanentPairing] - -/-- Both families of the permanent pairing are multilinear. -/ -def permanentPairingMultilinear (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : - MultilinearMap ℂ (fun _ : Fin n => X) - (MultilinearMap ℂ (fun _ : Fin n => Y) ℂ) where - toFun := permanentPairingRight n B - map_update_add' x i a b := by - ext y - simpa only [add_apply, permanentPairingRight_apply, - ← permanentPairingLeft_apply] using - (permanentPairingLeft n B y).map_update_add x i a b - map_update_smul' x i c a := by - ext y - simpa only [smul_apply, permanentPairingRight_apply, - ← permanentPairingLeft_apply] using - (permanentPairingLeft n B y).map_update_smul x i c a - -@[simp] theorem permanentPairingMultilinear_apply (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : - permanentPairingMultilinear n B x y = - permanentPairing n (fun x y => B x y) x y := - permanentPairingRight_apply n B x y - -theorem permanentPairingMultilinear_perm_left (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (τ : Equiv.Perm (Fin n)) : - permanentPairingMultilinear n B (fun i => x (τ i)) = - permanentPairingMultilinear n B x := by - ext y - simpa only [permanentPairingMultilinear_apply] using - permanentPairing_perm_left n (fun x y => B x y) x y τ - -theorem permanentPairingMultilinear_perm_right (n : ℕ) - (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) - (τ : Equiv.Perm (Fin n)) : - permanentPairingMultilinear n B x (fun i => y (τ i)) = - permanentPairingMultilinear n B x y := by - simpa only [permanentPairingMultilinear_apply] using - permanentPairing_perm_right n (fun x y => B x y) x y τ - -end Multilinear - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +open scoped BigOperators + +namespace Problem346 + +universe u v w z + +/-- The normalized permanent of a pairing on two indexed families. -/ +def permanentPairing {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) : ℂ := + (n.factorial : ℂ)⁻¹ * ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) + +theorem permanentPairing_perm_right {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) + (τ : Equiv.Perm (Fin n)) : + permanentPairing n B x (fun i => y (τ i)) = permanentPairing n B x y := by + classical + unfold permanentPairing + congr 1 + simpa only [Equiv.coe_mulLeft, Equiv.Perm.mul_apply] using + (Equiv.sum_comp (Equiv.mulLeft τ) + (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i)))) + +theorem permanentPairing_perm_left {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) + (τ : Equiv.Perm (Fin n)) : + permanentPairing n B (fun i => x (τ i)) y = permanentPairing n B x y := by + classical + unfold permanentPairing + congr 1 + calc + (∑ σ : Equiv.Perm (Fin n), ∏ i, B (x (τ i)) (y (σ i))) = + ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y ((σ * τ⁻¹) i)) := by + apply Finset.sum_congr rfl + intro σ _ + simpa only [Equiv.Perm.mul_apply, Equiv.Perm.inv_def, Equiv.symm_apply_apply] using + (Equiv.prod_comp τ (fun i => B (x i) (y ((σ * τ⁻¹) i)))) + _ = ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) := by + simpa only [Equiv.coe_mulRight] using + (Equiv.sum_comp (Equiv.mulRight τ⁻¹) + (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i)))) + +/-- Transposing the underlying pairing transposes the two families. -/ +theorem permanentPairing_flip {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : Fin n → X) (y : Fin n → Y) : + permanentPairing n (fun y x => B x y) y x = permanentPairing n B x y := by + classical + unfold permanentPairing + congr 1 + calc + (∑ σ : Equiv.Perm (Fin n), ∏ i, B (x (σ i)) (y i)) = + ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ⁻¹ i)) := by + apply Finset.sum_congr rfl + intro σ _ + simpa only [Equiv.Perm.inv_def, Equiv.symm_apply_apply] using + (Equiv.prod_comp σ (fun i => B (x i) (y (σ⁻¹ i)))) + _ = ∑ σ : Equiv.Perm (Fin n), ∏ i, B (x i) (y (σ i)) := by + exact Equiv.sum_comp (Equiv.inv (Equiv.Perm (Fin n))) + (fun σ : Equiv.Perm (Fin n) => ∏ i, B (x i) (y (σ i))) + +@[simp] theorem permanentPairing_const_right {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : Fin n → X) (y : Y) : + permanentPairing n B x (fun _ => y) = ∏ i, B (x i) y := by + classical + have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + simp [permanentPairing, Fintype.card_perm, hn] + +@[simp] theorem permanentPairing_const_left {X : Type u} {Y : Type v} (n : ℕ) + (B : X → Y → ℂ) (x : X) (y : Fin n → Y) : + permanentPairing n B (fun _ => x) y = ∏ i, B x (y i) := by + rw [← permanentPairing_flip n B] + exact permanentPairing_const_right n (fun y x => B x y) y x + +/-- Moving a map across each scalar pairing moves it across the normalized permanent. -/ +theorem permanentPairing_natural {X : Type u} {Y : Type v} + {X' : Type w} {Y' : Type z} (n : ℕ) + (B : X → Y → ℂ) (B' : X' → Y' → ℂ) + (f : X → X') (g : Y' → Y) + (h : ∀ x y, B' (f x) y = B x (g y)) + (x : Fin n → X) (y : Fin n → Y') : + permanentPairing n B' (fun i => f (x i)) y = + permanentPairing n B x (fun i => g (y i)) := by + classical + simp only [permanentPairing, h] + +section Multilinear + +variable {X : Type u} {Y : Type v} + [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] + +/-- The permanent pairing as a multilinear map in its right family. -/ +def permanentPairingRight (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) + (x : Fin n → X) : MultilinearMap ℂ (fun _ : Fin n => Y) ℂ := + (n.factorial : ℂ)⁻¹ • + ∑ σ : Equiv.Perm (Fin n), + ((MultilinearMap.mkPiAlgebra ℂ (Fin n) ℂ).compLinearMap (fun i => B (x i))).domDomCongr σ + +@[simp] theorem permanentPairingRight_apply (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : + permanentPairingRight n B x y = permanentPairing n (fun x y => B x y) x y := by + classical + simp [permanentPairingRight, permanentPairing] + +/-- The permanent pairing as a multilinear map in its left family. -/ +def permanentPairingLeft (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) + (y : Fin n → Y) : MultilinearMap ℂ (fun _ : Fin n => X) ℂ := + (n.factorial : ℂ)⁻¹ • + ∑ σ : Equiv.Perm (Fin n), + (MultilinearMap.mkPiAlgebra ℂ (Fin n) ℂ).compLinearMap + (fun i => B.flip (y (σ i))) + +@[simp] theorem permanentPairingLeft_apply (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : + permanentPairingLeft n B y x = permanentPairing n (fun x y => B x y) x y := by + classical + simp [permanentPairingLeft, permanentPairing] + +/-- Both families of the permanent pairing are multilinear. -/ +def permanentPairingMultilinear (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : + MultilinearMap ℂ (fun _ : Fin n => X) + (MultilinearMap ℂ (fun _ : Fin n => Y) ℂ) where + toFun := permanentPairingRight n B + map_update_add' x i a b := by + ext y + simpa only [add_apply, permanentPairingRight_apply, + ← permanentPairingLeft_apply] using + (permanentPairingLeft n B y).map_update_add x i a b + map_update_smul' x i c a := by + ext y + simpa only [smul_apply, permanentPairingRight_apply, + ← permanentPairingLeft_apply] using + (permanentPairingLeft n B y).map_update_smul x i c a + +@[simp] theorem permanentPairingMultilinear_apply (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) : + permanentPairingMultilinear n B x y = + permanentPairing n (fun x y => B x y) x y := + permanentPairingRight_apply n B x y + +theorem permanentPairingMultilinear_perm_left (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (τ : Equiv.Perm (Fin n)) : + permanentPairingMultilinear n B (fun i => x (τ i)) = + permanentPairingMultilinear n B x := by + ext y + simpa only [permanentPairingMultilinear_apply] using + permanentPairing_perm_left n (fun x y => B x y) x y τ + +theorem permanentPairingMultilinear_perm_right (n : ℕ) + (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) (x : Fin n → X) (y : Fin n → Y) + (τ : Equiv.Perm (Fin n)) : + permanentPairingMultilinear n B x (fun i => y (τ i)) = + permanentPairingMultilinear n B x y := by + simpa only [permanentPairingMultilinear_apply] using + permanentPairing_perm_right n (fun x y => B x y) x y τ + +end Multilinear + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PlethysmDual.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PlethysmDual.lean index c6d36a6219bfcd1e0f1f951d0f2ceeded8ebb6d5..f08d574c4904b0df0e30269d0e5b78eef34d32be 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PlethysmDual.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PlethysmDual.lean @@ -1,148 +1,148 @@ -import OAI.RepresentationTheory.FoulkesHowe.Naturality -import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension -import OAI.RepresentationTheory.FoulkesHowe.DualEmbedding - -namespace OAI - -/-! -# Lifting perfect duality through a symmetric power - -Composition of perfect pairings is separate from construction of the one-level pairing. Supplying the one-level duality -charts and their naturality gives the duality and adjoint-action identities for -nested symmetric powers. --/ - -noncomputable section - -namespace Problem346 -namespace PlethysmDual - -universe u v -variable {V : Type u} {W : Type v} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - -/-- Lift a perfect-duality chart through a symmetric power using the canonical - duality chart for that symmetric power. -/ -def liftDualEquiv (n : ℕ) (e : W ≃ₗ[ℂ] Module.Dual ℂ V) - (d : SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V)) : - SymPow n W ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := - (symPowEquiv n e).trans d - -/-- Adjointness is preserved when a perfect pairing is lifted through a - symmetric power whose duality chart is natural for the given map. -/ -theorem liftDualEquiv_adjoint (n : ℕ) (e : W ≃ₗ[ℂ] Module.Dual ℂ V) - (d : SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V)) - (A : V →ₗ[ℂ] V) (A' : W →ₗ[ℂ] W) - (he : ∀ x y, e (A' x) y = e x (A y)) - (hd : ∀ x y, d (symPowMap n A.dualMap x) y = d x (symPowMap n A y)) - (x : SymPow n W) (y : SymPow n V) : - liftDualEquiv n e d (symPowMap n A' x) y = - liftDualEquiv n e d x (symPowMap n A y) := by - have heq : e.toLinearMap.comp A' = A.dualMap.comp e.toLinearMap := by - ext x y - exact he x y - have hlift : (symPowMap n e.toLinearMap).comp (symPowMap n A') = - (symPowMap n A.dualMap).comp (symPowMap n e.toLinearMap) := by - rw [← symPowMap_comp, ← symPowMap_comp, heq] - change d (symPowMap n e.toLinearMap (symPowMap n A' x)) y = - d (symPowMap n e.toLinearMap x) (symPowMap n A y) - have hpoint := LinearMap.congr_fun hlift x - simp only [LinearMap.comp_apply] at hpoint - rw [hpoint] - exact hd _ _ - -/-- The duality chart for a plethysm is the composite of its inner and outer - one-level duality charts. -/ -def plethysmDualEquivOf (outer inner : ℕ) - (e : SymPow inner (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow inner V)) - (d : SymPow outer (Module.Dual ℂ (SymPow inner V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow outer (SymPow inner V))) : - SymPow outer (SymPow inner (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow outer (SymPow inner V)) := - liftDualEquiv outer e d - -/-- Naturality of each level gives the adjoint-action identity for the - plethysm pairing. The dual automorphism here is the ordinary dual map, - not the inverse contragredient; this is precisely the adjoint identity. -/ -theorem plethysmDualEquivOf_adjoint (outer inner : ℕ) - (e : SymPow inner (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow inner V)) - (d : SymPow outer (Module.Dual ℂ (SymPow inner V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow outer (SymPow inner V))) - (g : V ≃ₗ[ℂ] V) - (he : ∀ x y, e (symPowMap inner g.dualMap.toLinearMap x) y = - e x (symPowMap inner g.toLinearMap y)) - (hd : ∀ x y, - d (symPowMap outer (symPowMap inner g.toLinearMap).dualMap x) y = - d x (symPowMap outer (symPowMap inner g.toLinearMap) y)) - (x : SymPow outer (SymPow inner (Module.Dual ℂ V))) - (y : SymPow outer (SymPow inner V)) : - plethysmDualEquivOf outer inner e d - (plethysmAction outer inner g.dualMap x) y = - plethysmDualEquivOf outer inner e d x (plethysmAction outer inner g y) := by - exact liftDualEquiv_adjoint outer e d - (symPowMap inner g.toLinearMap) (symPowMap inner g.dualMap.toLinearMap) - he hd x y - -/-- The comparison embedding follows formally from a surjection on the dual - vector space and compatible perfect pairings on the two plethysms. -/ -theorem exists_embedding_of_dual_surjection (a b : ℕ) - [Module.IsReflexive ℂ (SymPow b (SymPow a V))] - [Module.IsReflexive ℂ (SymPow a (SymPow b V))] - (e : SymPow b (SymPow a (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow b (SymPow a V))) - (f : SymPow a (SymPow b (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow a (SymPow b V))) - (he : ∀ (g : V ≃ₗ[ℂ] V) x y, - e (plethysmAction b a g.dualMap x) y = e x (plethysmAction b a g y)) - (hf : ∀ (g : V ≃ₗ[ℂ] V) x y, - f (plethysmAction a b g.dualMap x) y = f x (plethysmAction a b g y)) - (μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] - SymPow a (SymPow b (Module.Dual ℂ V))) - (hμ : Function.Surjective μ) - (hcomm : ∀ g : V ≃ₗ[ℂ] V, - μ.comp (plethysmAction b a g.dualMap) = - (plethysmAction a b g.dualMap).comp μ) : - ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), - IsGLEquivariantEmbedding a b V ι := by - let e' := DualEmbedding.flipPairing e - let f' := DualEmbedding.flipPairing f - let ι := DualEmbedding.transpose e' f' μ - refine ⟨ι, isGLEquivariantEmbedding_of_commutes ι - (DualEmbedding.transpose_injective e' f' μ hμ) ?_⟩ - intro g - apply DualEmbedding.transpose_intertwines e' f' μ - (plethysmAction b a g) (plethysmAction b a g.dualMap) - (plethysmAction a b g) (plethysmAction a b g.dualMap) - · intro x z - exact (he g z x).symm - · intro y w - exact (hf g w y).symm - · exact hcomm g - -/-- With finite-dimensionality and canonical-map naturality available, only the - two perfect-duality charts and their adjointness remain to construct the - comparison embedding from canonical surjectivity on the dual space. -/ -theorem comparison_of_dual_charts (a b : ℕ) [FiniteDimensional ℂ V] - (e : SymPow b (SymPow a (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow b (SymPow a V))) - (f : SymPow a (SymPow b (Module.Dual ℂ V)) ≃ₗ[ℂ] - Module.Dual ℂ (SymPow a (SymPow b V))) - (he : ∀ (g : V ≃ₗ[ℂ] V) x y, - e (plethysmAction b a g.dualMap x) y = e x (plethysmAction b a g y)) - (hf : ∀ (g : V ≃ₗ[ℂ] V) x y, - f (plethysmAction a b g.dualMap x) y = f x (plethysmAction a b g y)) - (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] - SymPow a (SymPow b (Module.Dual ℂ V)), - IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : - ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), - IsGLEquivariantEmbedding a b V ι := by - obtain ⟨μ, hformula, hsurj⟩ := hsurj - exact exists_embedding_of_dual_surjection a b e f he hf μ hsurj - (fun g => (hformula.commutes g.dualMap).symm) - -end PlethysmDual -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Naturality +import OAI.RepresentationTheory.FoulkesHowe.FiniteDimension +import OAI.RepresentationTheory.FoulkesHowe.DualEmbedding + +namespace OAI + +/-! +# Lifting perfect duality through a symmetric power + +Composition of perfect pairings is separate from construction of the one-level pairing. Supplying the one-level duality +charts and their naturality gives the duality and adjoint-action identities for +nested symmetric powers. +-/ + +noncomputable section + +namespace Problem346 +namespace PlethysmDual + +universe u v +variable {V : Type u} {W : Type v} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + +/-- Lift a perfect-duality chart through a symmetric power using the canonical + duality chart for that symmetric power. -/ +def liftDualEquiv (n : ℕ) (e : W ≃ₗ[ℂ] Module.Dual ℂ V) + (d : SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V)) : + SymPow n W ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V) := + (symPowEquiv n e).trans d + +/-- Adjointness is preserved when a perfect pairing is lifted through a + symmetric power whose duality chart is natural for the given map. -/ +theorem liftDualEquiv_adjoint (n : ℕ) (e : W ≃ₗ[ℂ] Module.Dual ℂ V) + (d : SymPow n (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow n V)) + (A : V →ₗ[ℂ] V) (A' : W →ₗ[ℂ] W) + (he : ∀ x y, e (A' x) y = e x (A y)) + (hd : ∀ x y, d (symPowMap n A.dualMap x) y = d x (symPowMap n A y)) + (x : SymPow n W) (y : SymPow n V) : + liftDualEquiv n e d (symPowMap n A' x) y = + liftDualEquiv n e d x (symPowMap n A y) := by + have heq : e.toLinearMap.comp A' = A.dualMap.comp e.toLinearMap := by + ext x y + exact he x y + have hlift : (symPowMap n e.toLinearMap).comp (symPowMap n A') = + (symPowMap n A.dualMap).comp (symPowMap n e.toLinearMap) := by + rw [← symPowMap_comp, ← symPowMap_comp, heq] + change d (symPowMap n e.toLinearMap (symPowMap n A' x)) y = + d (symPowMap n e.toLinearMap x) (symPowMap n A y) + have hpoint := LinearMap.congr_fun hlift x + simp only [LinearMap.comp_apply] at hpoint + rw [hpoint] + exact hd _ _ + +/-- The duality chart for a plethysm is the composite of its inner and outer + one-level duality charts. -/ +def plethysmDualEquivOf (outer inner : ℕ) + (e : SymPow inner (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow inner V)) + (d : SymPow outer (Module.Dual ℂ (SymPow inner V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow outer (SymPow inner V))) : + SymPow outer (SymPow inner (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow outer (SymPow inner V)) := + liftDualEquiv outer e d + +/-- Naturality of each level gives the adjoint-action identity for the + plethysm pairing. The dual automorphism here is the ordinary dual map, + not the inverse contragredient; this is precisely the adjoint identity. -/ +theorem plethysmDualEquivOf_adjoint (outer inner : ℕ) + (e : SymPow inner (Module.Dual ℂ V) ≃ₗ[ℂ] Module.Dual ℂ (SymPow inner V)) + (d : SymPow outer (Module.Dual ℂ (SymPow inner V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow outer (SymPow inner V))) + (g : V ≃ₗ[ℂ] V) + (he : ∀ x y, e (symPowMap inner g.dualMap.toLinearMap x) y = + e x (symPowMap inner g.toLinearMap y)) + (hd : ∀ x y, + d (symPowMap outer (symPowMap inner g.toLinearMap).dualMap x) y = + d x (symPowMap outer (symPowMap inner g.toLinearMap) y)) + (x : SymPow outer (SymPow inner (Module.Dual ℂ V))) + (y : SymPow outer (SymPow inner V)) : + plethysmDualEquivOf outer inner e d + (plethysmAction outer inner g.dualMap x) y = + plethysmDualEquivOf outer inner e d x (plethysmAction outer inner g y) := by + exact liftDualEquiv_adjoint outer e d + (symPowMap inner g.toLinearMap) (symPowMap inner g.dualMap.toLinearMap) + he hd x y + +/-- The comparison embedding follows formally from a surjection on the dual + vector space and compatible perfect pairings on the two plethysms. -/ +theorem exists_embedding_of_dual_surjection (a b : ℕ) + [Module.IsReflexive ℂ (SymPow b (SymPow a V))] + [Module.IsReflexive ℂ (SymPow a (SymPow b V))] + (e : SymPow b (SymPow a (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow b (SymPow a V))) + (f : SymPow a (SymPow b (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow a (SymPow b V))) + (he : ∀ (g : V ≃ₗ[ℂ] V) x y, + e (plethysmAction b a g.dualMap x) y = e x (plethysmAction b a g y)) + (hf : ∀ (g : V ≃ₗ[ℂ] V) x y, + f (plethysmAction a b g.dualMap x) y = f x (plethysmAction a b g y)) + (μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] + SymPow a (SymPow b (Module.Dual ℂ V))) + (hμ : Function.Surjective μ) + (hcomm : ∀ g : V ≃ₗ[ℂ] V, + μ.comp (plethysmAction b a g.dualMap) = + (plethysmAction a b g.dualMap).comp μ) : + ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), + IsGLEquivariantEmbedding a b V ι := by + let e' := DualEmbedding.flipPairing e + let f' := DualEmbedding.flipPairing f + let ι := DualEmbedding.transpose e' f' μ + refine ⟨ι, isGLEquivariantEmbedding_of_commutes ι + (DualEmbedding.transpose_injective e' f' μ hμ) ?_⟩ + intro g + apply DualEmbedding.transpose_intertwines e' f' μ + (plethysmAction b a g) (plethysmAction b a g.dualMap) + (plethysmAction a b g) (plethysmAction a b g.dualMap) + · intro x z + exact (he g z x).symm + · intro y w + exact (hf g w y).symm + · exact hcomm g + +/-- With finite-dimensionality and canonical-map naturality available, only the + two perfect-duality charts and their adjointness remain to construct the + comparison embedding from canonical surjectivity on the dual space. -/ +theorem comparison_of_dual_charts (a b : ℕ) [FiniteDimensional ℂ V] + (e : SymPow b (SymPow a (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow b (SymPow a V))) + (f : SymPow a (SymPow b (Module.Dual ℂ V)) ≃ₗ[ℂ] + Module.Dual ℂ (SymPow a (SymPow b V))) + (he : ∀ (g : V ≃ₗ[ℂ] V) x y, + e (plethysmAction b a g.dualMap x) y = e x (plethysmAction b a g y)) + (hf : ∀ (g : V ≃ₗ[ℂ] V) x y, + f (plethysmAction a b g.dualMap x) y = f x (plethysmAction a b g y)) + (hsurj : ∃ μ : SymPow b (SymPow a (Module.Dual ℂ V)) →ₗ[ℂ] + SymPow a (SymPow b (Module.Dual ℂ V)), + IsFoulkesMap a b (Module.Dual ℂ V) μ ∧ Function.Surjective μ) : + ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), + IsGLEquivariantEmbedding a b V ι := by + obtain ⟨μ, hformula, hsurj⟩ := hsurj + exact exists_embedding_of_dual_surjection a b e f he hf μ hsurj + (fun g => (hformula.commutes g.dualMap).symm) + +end PlethysmDual +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Polarization.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Polarization.lean index d39b65da9c33a986ad8a8e34be4168af28b1a139..aad4b7bceedd1d84e5ef2c3ffe1eb7b368a48635 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Polarization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Polarization.lean @@ -1,46 +1,46 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u v - -/-- A scalar-valued diagonal-detection principle upgrades to a spanning identity -for the diagonal values of any symmetric multilinear map. -/ -theorem span_diagonal_eq_span_range_of_detection - {V : Type u} {W : Type v} [AddCommGroup V] [Module ℂ V] - [AddCommGroup W] [Module ℂ W] (n : ℕ) - (detect : ∀ T : MultilinearMap ℂ (fun _ : Fin n => V) ℂ, - (∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → V), T (fun i => x (σ i)) = T x) → - (∀ x : V, T (fun _ => x) = 0) → T = 0) - (m : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → V), - m (fun i => x (σ i)) = m x) : - Submodule.span ℂ (Set.range (fun x : V => m (fun _ => x))) = - Submodule.span ℂ (Set.range m) := by - apply le_antisymm - · apply Submodule.span_mono - rintro _ ⟨x, rfl⟩ - exact ⟨fun _ => x, rfl⟩ - · apply Submodule.span_le.mpr - rintro _ ⟨x, rfl⟩ - apply (Subspace.forall_mem_dualAnnihilator_apply_eq_zero_iff _ _).mp - intro f hf - have hz : f.compMultilinearMap m = 0 := by - apply detect - · intro σ y - change f (m (fun i => y (σ i))) = f (m y) - rw [hsym] - · intro y - exact (Submodule.mem_dualAnnihilator f).mp hf _ - (Submodule.subset_span ⟨y, rfl⟩) - exact DFunLike.congr_fun hz x - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u v + +/-- A scalar-valued diagonal-detection principle upgrades to a spanning identity +for the diagonal values of any symmetric multilinear map. -/ +theorem span_diagonal_eq_span_range_of_detection + {V : Type u} {W : Type v} [AddCommGroup V] [Module ℂ V] + [AddCommGroup W] [Module ℂ W] (n : ℕ) + (detect : ∀ T : MultilinearMap ℂ (fun _ : Fin n => V) ℂ, + (∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → V), T (fun i => x (σ i)) = T x) → + (∀ x : V, T (fun _ => x) = 0) → T = 0) + (m : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hsym : ∀ (σ : Equiv.Perm (Fin n)) (x : Fin n → V), + m (fun i => x (σ i)) = m x) : + Submodule.span ℂ (Set.range (fun x : V => m (fun _ => x))) = + Submodule.span ℂ (Set.range m) := by + apply le_antisymm + · apply Submodule.span_mono + rintro _ ⟨x, rfl⟩ + exact ⟨fun _ => x, rfl⟩ + · apply Submodule.span_le.mpr + rintro _ ⟨x, rfl⟩ + apply (Subspace.forall_mem_dualAnnihilator_apply_eq_zero_iff _ _).mp + intro f hf + have hz : f.compMultilinearMap m = 0 := by + apply detect + · intro σ y + change f (m (fun i => y (σ i))) = f (m y) + rw [hsym] + · intro y + exact (Submodule.mem_dualAnnihilator f).mp hf _ + (Submodule.subset_span ⟨y, rfl⟩) + exact DFunLike.congr_fun hz x + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PolynomialShift.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PolynomialShift.lean index bb5e82b522185d47eea10b395961364b8dbea889..d0f7126649159c348b0ab3241c21b0fc3f3df684 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PolynomialShift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PolynomialShift.lean @@ -1,74 +1,74 @@ -import Mathlib - -namespace OAI - -noncomputable section - -open scoped BigOperators - -namespace Problem346 -namespace PolynomialShift - -variable {K B I : Type*} [CommRing K] - -attribute [local instance] Classical.propDecidable - -/-- Transfer one unit of polynomial degree from `src` to `dst`. Other blocks -are spectator variables. -/ -def derivation (src dst : B) : - Derivation K (MvPolynomial (B × I) K) (MvPolynomial (B × I) K) := by - classical - exact MvPolynomial.mkDerivation K - (fun v => if v.1 = src then MvPolynomial.X (dst, v.2) else 0) - -@[simp] -theorem derivation_X (src dst block : B) (i : I) : - derivation (K := K) src dst (MvPolynomial.X (block, i)) = - if block = src then MvPolynomial.X (dst, i) else 0 := by - classical - simp [derivation] - -/-- The directional shift as a linear endomorphism. -/ -def shift (src dst : B) : Module.End K (MvPolynomial (B × I) K) := - (derivation src dst).toLinearMap - -@[simp] -theorem shift_apply (src dst : B) (p : MvPolynomial (B × I) K) : - shift src dst p = derivation src dst p := rfl - -/-- Euler's operator for one block. -/ -def euler (block : B) : Module.End K (MvPolynomial (B × I) K) := - shift block block - -theorem commutator (src dst : B) (h : src ≠ dst) : - ⁅derivation (K := K) (I := I) dst src, derivation (K := K) (I := I) src dst⁆ = - derivation (K := K) (I := I) src src - derivation (K := K) (I := I) dst dst := by - classical - apply MvPolynomial.derivation_ext - rintro ⟨block, i⟩ - by_cases hs : block = src <;> by_cases hd : block = dst <;> - simp_all [Derivation.commutator_apply] - -theorem commutator_apply (src dst : B) (h : src ≠ dst) - (p : MvPolynomial (B × I) K) : - shift dst src (shift src dst p) - shift src dst (shift dst src p) = - euler src p - euler dst p := by - have h' := congrArg (fun d : Derivation K (MvPolynomial (B × I) K) - (MvPolynomial (B × I) K) => d p) (commutator (K := K) (I := I) src dst h) - simpa [Derivation.commutator_apply, euler] using h' - -theorem weight_commutator (src dst : B) (h : src ≠ dst) : - ⁅derivation (K := K) (I := I) src src - derivation (K := K) (I := I) dst dst, - derivation (K := K) (I := I) dst src⁆ = (2 : K) • derivation (K := K) (I := I) dst src := by - classical - apply MvPolynomial.derivation_ext - rintro ⟨block, i⟩ - by_cases hs : block = src <;> by_cases hd : block = dst <;> - simp_all [Derivation.commutator_apply, two_smul] - -end PolynomialShift -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +open scoped BigOperators + +namespace Problem346 +namespace PolynomialShift + +variable {K B I : Type*} [CommRing K] + +attribute [local instance] Classical.propDecidable + +/-- Transfer one unit of polynomial degree from `src` to `dst`. Other blocks +are spectator variables. -/ +def derivation (src dst : B) : + Derivation K (MvPolynomial (B × I) K) (MvPolynomial (B × I) K) := by + classical + exact MvPolynomial.mkDerivation K + (fun v => if v.1 = src then MvPolynomial.X (dst, v.2) else 0) + +@[simp] +theorem derivation_X (src dst block : B) (i : I) : + derivation (K := K) src dst (MvPolynomial.X (block, i)) = + if block = src then MvPolynomial.X (dst, i) else 0 := by + classical + simp [derivation] + +/-- The directional shift as a linear endomorphism. -/ +def shift (src dst : B) : Module.End K (MvPolynomial (B × I) K) := + (derivation src dst).toLinearMap + +@[simp] +theorem shift_apply (src dst : B) (p : MvPolynomial (B × I) K) : + shift src dst p = derivation src dst p := rfl + +/-- Euler's operator for one block. -/ +def euler (block : B) : Module.End K (MvPolynomial (B × I) K) := + shift block block + +theorem commutator (src dst : B) (h : src ≠ dst) : + ⁅derivation (K := K) (I := I) dst src, derivation (K := K) (I := I) src dst⁆ = + derivation (K := K) (I := I) src src - derivation (K := K) (I := I) dst dst := by + classical + apply MvPolynomial.derivation_ext + rintro ⟨block, i⟩ + by_cases hs : block = src <;> by_cases hd : block = dst <;> + simp_all [Derivation.commutator_apply] + +theorem commutator_apply (src dst : B) (h : src ≠ dst) + (p : MvPolynomial (B × I) K) : + shift dst src (shift src dst p) - shift src dst (shift dst src p) = + euler src p - euler dst p := by + have h' := congrArg (fun d : Derivation K (MvPolynomial (B × I) K) + (MvPolynomial (B × I) K) => d p) (commutator (K := K) (I := I) src dst h) + simpa [Derivation.commutator_apply, euler] using h' + +theorem weight_commutator (src dst : B) (h : src ≠ dst) : + ⁅derivation (K := K) (I := I) src src - derivation (K := K) (I := I) dst dst, + derivation (K := K) (I := I) dst src⁆ = (2 : K) • derivation (K := K) (I := I) dst src := by + classical + apply MvPolynomial.derivation_ext + rintro ⟨block, i⟩ + by_cases hs : block = src <;> by_cases hd : block = dst <;> + simp_all [Derivation.commutator_apply, two_smul] + +end PolynomialShift +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/PowerSpan.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/PowerSpan.lean index 846073b42f498a28ff3062dfc80ce9da99d0ed1a..7f61a7ae145a2b3bfd5e0885b4f9fde605d8b0b1 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/PowerSpan.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/PowerSpan.lean @@ -1,57 +1,57 @@ -import OAI.RepresentationTheory.FoulkesHowe.DiagonalPolarization -import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear -import OAI.RepresentationTheory.FoulkesHowe.Polarization - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u v - -/-- Pure powers span each symmetric power, including degree zero. -/ -theorem span_purePowers_eq_top (b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - Submodule.span ℂ (Set.range (fun x : V => symMonomial b V (fun _ => x))) = ⊤ := by - apply Submodule.dualAnnihilator_eq_bot_iff.mp - apply le_antisymm - · intro f hf - change f = 0 - apply linearMap_eq_zero_of_symMonomial b V f - have hz : f.compMultilinearMap (symMonomialMultilinear b V) = 0 := by - apply symmetric_multilinear_eq_zero_of_diagonal - · intro σ x - change f (symMonomial b V (fun i => x (σ i))) = f (symMonomial b V x) - rw [symMonomial_permute] - · intro x - exact (Submodule.mem_dualAnnihilator f).mp hf _ - (Submodule.subset_span ⟨x, rfl⟩) - intro x - exact DFunLike.congr_fun hz x - · exact bot_le - -/-- Multilinearity extends vanishing on independent pure powers to vanishing everywhere. -/ -theorem multilinear_eq_zero_of_pure_powers (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] {W : Type v} [AddCommGroup W] [Module ℂ W] - (T : MultilinearMap ℂ (fun _ : Fin a => SymPow b V) W) - (hT : ∀ x : Fin a → V, T (fun i => symMonomial b V (fun _ => x i)) = 0) : - T = 0 := by - apply MultilinearMap.ext_of_span_eq_top - (g := fun {_ : Fin a} (x : V) => symMonomial b V (fun _ => x)) - (fun _ => span_purePowers_eq_top b V) - exact hT - -/-- Independent pure powers detect a symmetric multilinear form. -/ -theorem symmetricMultilinearForm_eq_zero_of_pure_powers (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (T : SymmetricMultilinearForm a b V) - (hT : ∀ x : Fin a → V, T (fun i => symMonomial b V (fun _ => x i)) = 0) : - T = 0 := - multilinear_eq_zero_of_pure_powers a b V T hT - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.DiagonalPolarization +import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear +import OAI.RepresentationTheory.FoulkesHowe.Polarization + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u v + +/-- Pure powers span each symmetric power, including degree zero. -/ +theorem span_purePowers_eq_top (b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + Submodule.span ℂ (Set.range (fun x : V => symMonomial b V (fun _ => x))) = ⊤ := by + apply Submodule.dualAnnihilator_eq_bot_iff.mp + apply le_antisymm + · intro f hf + change f = 0 + apply linearMap_eq_zero_of_symMonomial b V f + have hz : f.compMultilinearMap (symMonomialMultilinear b V) = 0 := by + apply symmetric_multilinear_eq_zero_of_diagonal + · intro σ x + change f (symMonomial b V (fun i => x (σ i))) = f (symMonomial b V x) + rw [symMonomial_permute] + · intro x + exact (Submodule.mem_dualAnnihilator f).mp hf _ + (Submodule.subset_span ⟨x, rfl⟩) + intro x + exact DFunLike.congr_fun hz x + · exact bot_le + +/-- Multilinearity extends vanishing on independent pure powers to vanishing everywhere. -/ +theorem multilinear_eq_zero_of_pure_powers (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] {W : Type v} [AddCommGroup W] [Module ℂ W] + (T : MultilinearMap ℂ (fun _ : Fin a => SymPow b V) W) + (hT : ∀ x : Fin a → V, T (fun i => symMonomial b V (fun _ => x i)) = 0) : + T = 0 := by + apply MultilinearMap.ext_of_span_eq_top + (g := fun {_ : Fin a} (x : V) => symMonomial b V (fun _ => x)) + (fun _ => span_purePowers_eq_top b V) + exact hT + +/-- Independent pure powers detect a symmetric multilinear form. -/ +theorem symmetricMultilinearForm_eq_zero_of_pure_powers (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (T : SymmetricMultilinearForm a b V) + (hT : ∀ x : Fin a → V, T (fun i => symMonomial b V (fun _ => x i)) = 0) : + T = 0 := + multilinear_eq_zero_of_pure_powers a b V T hT + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/ProductVanishing.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/ProductVanishing.lean index 7d10505a990d5671982d1f5f322dc02d16941367..bb245da0531a4c7c949178dce6369cefab35dd6d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/ProductVanishing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/ProductVanishing.lean @@ -1,28 +1,28 @@ -import OAI.RepresentationTheory.FoulkesHowe.VanishingFirst -import OAI.RepresentationTheory.FoulkesHowe.SecondTransfer - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u - -/-- Quadratic stabilization of diagonal vanishing on products. Both differential -transfers and all of the induction hypotheses are discharged in this theorem. -/ -theorem vanishing_on_products_aux (V : Type u) - [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - (a b : ℕ) (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a*(a-1) ≤ b) - (T : SymmetricMultilinearForm a b V) - (hT : IsSymmetricMultilinearForm a b V T) - (hdiag : ∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) : T = 0 := by - refine vanishing_on_products_of_second_transfer (V := V) ?_ a b ha hb hab T hT hdiag - intro r m _ _ hbound S _ hrest - exact SecondTransfer.second_transfer r m (by simpa only [Nat.mul_comm] using hbound) S hrest - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.VanishingFirst +import OAI.RepresentationTheory.FoulkesHowe.SecondTransfer + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u + +/-- Quadratic stabilization of diagonal vanishing on products. Both differential +transfers and all of the induction hypotheses are discharged in this theorem. -/ +theorem vanishing_on_products_aux (V : Type u) + [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + (a b : ℕ) (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a*(a-1) ≤ b) + (T : SymmetricMultilinearForm a b V) + (hT : IsSymmetricMultilinearForm a b V T) + (hdiag : ∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) : T = 0 := by + refine vanishing_on_products_of_second_transfer (V := V) ?_ a b ha hb hab T hT hdiag + intro r m _ _ hbound S _ hrest + exact SecondTransfer.second_transfer r m (by simpa only [Nat.mul_comm] using hbound) S hrest + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/RowSwap.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/RowSwap.lean index 882754184a5b6197c2f768f436775124ea0ab7b3..f491d51c86d20186762dee417d771c84ea6fcaed 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/RowSwap.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/RowSwap.lean @@ -1,67 +1,67 @@ -import Mathlib - -namespace OAI - -/-! -# From rowwise permutation invariance to individual slot swaps - -The flattened plethysm forms are invariant under independent permutations -inside each row. The polynomial derivative formulas instead ask for -invariance under a swap of two individual slots. These lemmas provide that -conversion for any realization of symmetric powers. --/ - -namespace Problem346 - -variable {α β V W : Type*} - -/-- A transposition within one row acts by the transposition on that row -and by the identity on every other row. -/ -theorem swap_same_row_apply [DecidableEq α] [DecidableEq β] - (r : α) (j k : β) (p : α × β) : - Equiv.swap (r, j) (r, k) p = - (p.1, if p.1 = r then Equiv.swap j k p.2 else p.2) := by - rcases p with ⟨i, l⟩ - by_cases hi : i = r - · subst i - by_cases hj : l = j - · subst l - simp - by_cases hk : l = k - · subst l - simp - · simp [Equiv.swap_apply_of_ne_of_ne, hj, hk] - · have hj : (i, l) ≠ (r, j) := fun h => hi (congrArg Prod.fst h) - have hk : (i, l) ≠ (r, k) := fun h => hi (congrArg Prod.fst h) - simp [Equiv.swap_apply_of_ne_of_ne hj hk, hi] - -/-- Independent rowwise permutation invariance implies invariance under a -swap of any two slots in a fixed row. -/ -theorem rowwise_invariant_swap [DecidableEq α] [DecidableEq β] - (F : (α × β → V) → W) - (hF : ∀ (σ : α → Equiv.Perm β) (x : α × β → V), - F (fun p => x (p.1, σ p.1 p.2)) = F x) - (r : α) (j k : β) (x : α × β → V) : - F (fun p => x (Equiv.swap (r, j) (r, k) p)) = F x := by - have h := hF (fun i => if i = r then Equiv.swap j k else Equiv.refl β) x - convert h using 1 - congr 1 - funext p - rw [swap_same_row_apply] - by_cases hp : p.1 = r <;> simp [hp] - -/-- Coefficient-array version of the preceding lemma. This is the swap -invariance hypothesis required by the grouped polynomial derivative rule. -/ -theorem rowwise_coefficients_swap {κ : Type*} - [DecidableEq α] [DecidableEq β] - (F : (α × β → V) → W) - (hF : ∀ (σ : α → Equiv.Perm β) (x : α × β → V), - F (fun p => x (p.1, σ p.1 p.2)) = F x) - (e : κ → V) (r : α) (j k : β) (c : α × β → κ) : - F (fun p => e ((c ∘ Equiv.swap (r, j) (r, k)) p)) = - F (fun p => e (c p)) := by - exact rowwise_invariant_swap F hF r j k (fun p => e (c p)) - -end Problem346 - -end OAI +import Mathlib + +namespace OAI + +/-! +# From rowwise permutation invariance to individual slot swaps + +The flattened plethysm forms are invariant under independent permutations +inside each row. The polynomial derivative formulas instead ask for +invariance under a swap of two individual slots. These lemmas provide that +conversion for any realization of symmetric powers. +-/ + +namespace Problem346 + +variable {α β V W : Type*} + +/-- A transposition within one row acts by the transposition on that row +and by the identity on every other row. -/ +theorem swap_same_row_apply [DecidableEq α] [DecidableEq β] + (r : α) (j k : β) (p : α × β) : + Equiv.swap (r, j) (r, k) p = + (p.1, if p.1 = r then Equiv.swap j k p.2 else p.2) := by + rcases p with ⟨i, l⟩ + by_cases hi : i = r + · subst i + by_cases hj : l = j + · subst l + simp + by_cases hk : l = k + · subst l + simp + · simp [Equiv.swap_apply_of_ne_of_ne, hj, hk] + · have hj : (i, l) ≠ (r, j) := fun h => hi (congrArg Prod.fst h) + have hk : (i, l) ≠ (r, k) := fun h => hi (congrArg Prod.fst h) + simp [Equiv.swap_apply_of_ne_of_ne hj hk, hi] + +/-- Independent rowwise permutation invariance implies invariance under a +swap of any two slots in a fixed row. -/ +theorem rowwise_invariant_swap [DecidableEq α] [DecidableEq β] + (F : (α × β → V) → W) + (hF : ∀ (σ : α → Equiv.Perm β) (x : α × β → V), + F (fun p => x (p.1, σ p.1 p.2)) = F x) + (r : α) (j k : β) (x : α × β → V) : + F (fun p => x (Equiv.swap (r, j) (r, k) p)) = F x := by + have h := hF (fun i => if i = r then Equiv.swap j k else Equiv.refl β) x + convert h using 1 + congr 1 + funext p + rw [swap_same_row_apply] + by_cases hp : p.1 = r <;> simp [hp] + +/-- Coefficient-array version of the preceding lemma. This is the swap +invariance hypothesis required by the grouped polynomial derivative rule. -/ +theorem rowwise_coefficients_swap {κ : Type*} + [DecidableEq α] [DecidableEq β] + (F : (α × β → V) → W) + (hF : ∀ (σ : α → Equiv.Perm β) (x : α × β → V), + F (fun p => x (p.1, σ p.1 p.2)) = F x) + (e : κ → V) (r : α) (j k : β) (c : α × β → κ) : + F (fun p => e ((c ∘ Equiv.swap (r, j) (r, k)) p)) = + F (fun p => e (c p)) := by + exact rowwise_invariant_swap F hF r j k (fun p => e (c p)) + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondCounts.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondCounts.lean index 491879030eae3d8d153451495408620b91eacb93..47417d9e6e8ebe139ffb0442815abfb5fd13fc76 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondCounts.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondCounts.lean @@ -1,134 +1,134 @@ -import OAI.RepresentationTheory.FoulkesHowe.SecondLabels - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346.SecondTransfer - -/-- A source occurrence lies in exactly one nonzero row and beyond its -already-transferred prefix. -/ -theorem label_eq_source_iff {r b : ℕ} (k : Fin r → ℕ) - (i : Fin r) (p : Fin (r+1) × Fin b) : - label k p = some i.succ ↔ p.1 = i.succ ∧ k i ≤ p.2.val := by - rcases p with ⟨l,j⟩ - refine Fin.cases ?_ (fun l => ?_) l - · simp [Ne.symm (Fin.succ_ne_zero i)] - · by_cases h : l = i - · subst l - simp [not_lt] - · simp [label_succ_row, Fin.succ_inj, h] - -private theorem sum_fin_ite_lt (b k : ℕ) (hk : k ≤ b) : - (∑ j : Fin b, if j.val < k then 1 else 0) = k := by - classical - by_cases h : k < b - · let c : Fin b := ⟨k,h⟩ - have hs : Finset.univ.filter (fun j : Fin b => j.val < k) = Finset.Iio c := by - ext j - simp [c, Fin.lt_def] - rw [← Finset.card_filter, hs, Fin.card_Iio] - · have hkb : k = b := by omega - subst k - simp - -private theorem sum_fin_ite_le (b k : ℕ) (hk : k ≤ b) : - (∑ j : Fin b, if k ≤ j.val then 1 else 0) = b-k := by - classical - have h := sum_fin_ite_lt b k hk - have hs : (∑ j : Fin b, if j.val < k then 1 else 0) + - (∑ j : Fin b, if k ≤ j.val then 1 else 0) = b := by - rw [← Finset.sum_add_distrib] - have : ∀ j : Fin b, (if j.val < k then 1 else 0) + - (if k ≤ j.val then 1 else 0) = (1 : ℕ) := by - intro j - split_ifs <;> omega - simp_rw [this] - simp - omega - -/-- Number of occurrences of the still-independent vector in row `i`. -/ -theorem source_occurrences {r b : ℕ} (k : Fin r → ℕ) - (hk : ∀ i, k i ≤ b) (i : Fin r) : - (∑ p : Fin (r+1) × Fin b, if label k p = some i.succ then 1 else 0) = b-k i := by - classical - simp_rw [label_eq_source_iff] - rw [Fintype.sum_prod_type] - dsimp only - simp only [ite_and] - rw [Finset.sum_comm] - calc - _ = ∑ j : Fin b, if k i ≤ j.val then 1 else 0 := by - apply Finset.sum_congr rfl - intro j hj - rw [Finset.sum_eq_single i.succ] - · simp - · intro l hl hli - simp [hli] - · simp - _ = b-k i := sum_fin_ite_le b (k i) (hk i) - -/-- Number of occurrences of the shared destination vector. -/ -theorem destination_occurrences {r b : ℕ} (k : Fin r → ℕ) - (hk : ∀ i, k i ≤ b) : - (∑ p : Fin (r+1) × Fin b, if label k p = none then 1 else 0) = ∑ i, k i := by - classical - rw [Fintype.sum_prod_type, Fin.sum_univ_succ] - simp only [label_zero_row, reduceCtorEq, ite_false, Finset.sum_const_zero, zero_add, - label_succ_row] - apply Finset.sum_congr rfl - intro i hi - convert sum_fin_ite_lt b (k i) (hk i) using 1 - apply Finset.sum_congr rfl - intro j hj - split_ifs <;> simp_all - -/-- Cardinality version of the source occurrence formula. -/ -theorem source_card {r b : ℕ} (k : Fin r → ℕ) - (hk : ∀ i, k i ≤ b) (i : Fin r) : - (Finset.univ.filter (fun p : Fin (r+1) × Fin b => label k p = some i.succ)).card = - b-k i := by - classical - rw [Finset.card_filter] - exact source_occurrences k hk i - -/-- Cardinality version of the destination occurrence formula. -/ -theorem destination_card {r b : ℕ} (k : Fin r → ℕ) - (hk : ∀ i, k i ≤ b) : - (Finset.univ.filter (fun p : Fin (r+1) × Fin b => label k p = none)).card = - ∑ i, k i := by - classical - rw [Finset.card_filter] - exact destination_occurrences k hk - -/-- At every unfinished row, the quadratic threshold makes the source degree -strictly larger than the accumulated shared-destination degree. -/ -theorem source_degree_gt_destination {r b : ℕ} (k : Fin r → ℕ) - (hb : r * (r+1) ≤ b) (hk : ∀ j, k j ≤ r) - (i : Fin r) (hi : k i < r) : - (∑ j, k j) < b - k i := by - have hsum : (∑ j, k j) ≤ r*r := by - calc - _ ≤ ∑ _ : Fin r, r := Finset.sum_le_sum (fun j _ => hk j) - _ = r*r := by simp - have hquad : r*r+r ≤ b := by nlinarith - omega - -/-- The actual occurrence counts satisfy the positive-weight hypothesis -used to cancel a shift at any unfinished row. -/ -theorem destination_occurrences_lt_source {r b : ℕ} (k : Fin r → ℕ) - (hb : r * (r+1) ≤ b) (hk : ∀ j, k j ≤ r) - (i : Fin r) (hi : k i < r) : - (∑ p : Fin (r+1) × Fin b, if label k p = none then 1 else 0) < - ∑ p : Fin (r+1) × Fin b, if label k p = some i.succ then 1 else 0 := by - have hrb : r ≤ b := by nlinarith - have hkb : ∀ j, k j ≤ b := fun j => (hk j).trans hrb - rw [destination_occurrences k hkb, source_occurrences k hkb] - exact source_degree_gt_destination k hb hk i hi - -end Problem346.SecondTransfer - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SecondLabels + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346.SecondTransfer + +/-- A source occurrence lies in exactly one nonzero row and beyond its +already-transferred prefix. -/ +theorem label_eq_source_iff {r b : ℕ} (k : Fin r → ℕ) + (i : Fin r) (p : Fin (r+1) × Fin b) : + label k p = some i.succ ↔ p.1 = i.succ ∧ k i ≤ p.2.val := by + rcases p with ⟨l,j⟩ + refine Fin.cases ?_ (fun l => ?_) l + · simp [Ne.symm (Fin.succ_ne_zero i)] + · by_cases h : l = i + · subst l + simp [not_lt] + · simp [label_succ_row, Fin.succ_inj, h] + +private theorem sum_fin_ite_lt (b k : ℕ) (hk : k ≤ b) : + (∑ j : Fin b, if j.val < k then 1 else 0) = k := by + classical + by_cases h : k < b + · let c : Fin b := ⟨k,h⟩ + have hs : Finset.univ.filter (fun j : Fin b => j.val < k) = Finset.Iio c := by + ext j + simp [c, Fin.lt_def] + rw [← Finset.card_filter, hs, Fin.card_Iio] + · have hkb : k = b := by omega + subst k + simp + +private theorem sum_fin_ite_le (b k : ℕ) (hk : k ≤ b) : + (∑ j : Fin b, if k ≤ j.val then 1 else 0) = b-k := by + classical + have h := sum_fin_ite_lt b k hk + have hs : (∑ j : Fin b, if j.val < k then 1 else 0) + + (∑ j : Fin b, if k ≤ j.val then 1 else 0) = b := by + rw [← Finset.sum_add_distrib] + have : ∀ j : Fin b, (if j.val < k then 1 else 0) + + (if k ≤ j.val then 1 else 0) = (1 : ℕ) := by + intro j + split_ifs <;> omega + simp_rw [this] + simp + omega + +/-- Number of occurrences of the still-independent vector in row `i`. -/ +theorem source_occurrences {r b : ℕ} (k : Fin r → ℕ) + (hk : ∀ i, k i ≤ b) (i : Fin r) : + (∑ p : Fin (r+1) × Fin b, if label k p = some i.succ then 1 else 0) = b-k i := by + classical + simp_rw [label_eq_source_iff] + rw [Fintype.sum_prod_type] + dsimp only + simp only [ite_and] + rw [Finset.sum_comm] + calc + _ = ∑ j : Fin b, if k i ≤ j.val then 1 else 0 := by + apply Finset.sum_congr rfl + intro j hj + rw [Finset.sum_eq_single i.succ] + · simp + · intro l hl hli + simp [hli] + · simp + _ = b-k i := sum_fin_ite_le b (k i) (hk i) + +/-- Number of occurrences of the shared destination vector. -/ +theorem destination_occurrences {r b : ℕ} (k : Fin r → ℕ) + (hk : ∀ i, k i ≤ b) : + (∑ p : Fin (r+1) × Fin b, if label k p = none then 1 else 0) = ∑ i, k i := by + classical + rw [Fintype.sum_prod_type, Fin.sum_univ_succ] + simp only [label_zero_row, reduceCtorEq, ite_false, Finset.sum_const_zero, zero_add, + label_succ_row] + apply Finset.sum_congr rfl + intro i hi + convert sum_fin_ite_lt b (k i) (hk i) using 1 + apply Finset.sum_congr rfl + intro j hj + split_ifs <;> simp_all + +/-- Cardinality version of the source occurrence formula. -/ +theorem source_card {r b : ℕ} (k : Fin r → ℕ) + (hk : ∀ i, k i ≤ b) (i : Fin r) : + (Finset.univ.filter (fun p : Fin (r+1) × Fin b => label k p = some i.succ)).card = + b-k i := by + classical + rw [Finset.card_filter] + exact source_occurrences k hk i + +/-- Cardinality version of the destination occurrence formula. -/ +theorem destination_card {r b : ℕ} (k : Fin r → ℕ) + (hk : ∀ i, k i ≤ b) : + (Finset.univ.filter (fun p : Fin (r+1) × Fin b => label k p = none)).card = + ∑ i, k i := by + classical + rw [Finset.card_filter] + exact destination_occurrences k hk + +/-- At every unfinished row, the quadratic threshold makes the source degree +strictly larger than the accumulated shared-destination degree. -/ +theorem source_degree_gt_destination {r b : ℕ} (k : Fin r → ℕ) + (hb : r * (r+1) ≤ b) (hk : ∀ j, k j ≤ r) + (i : Fin r) (hi : k i < r) : + (∑ j, k j) < b - k i := by + have hsum : (∑ j, k j) ≤ r*r := by + calc + _ ≤ ∑ _ : Fin r, r := Finset.sum_le_sum (fun j _ => hk j) + _ = r*r := by simp + have hquad : r*r+r ≤ b := by nlinarith + omega + +/-- The actual occurrence counts satisfy the positive-weight hypothesis +used to cancel a shift at any unfinished row. -/ +theorem destination_occurrences_lt_source {r b : ℕ} (k : Fin r → ℕ) + (hb : r * (r+1) ≤ b) (hk : ∀ j, k j ≤ r) + (i : Fin r) (hi : k i < r) : + (∑ p : Fin (r+1) × Fin b, if label k p = none then 1 else 0) < + ∑ p : Fin (r+1) × Fin b, if label k p = some i.succ then 1 else 0 := by + have hrb : r ≤ b := by nlinarith + have hkb : ∀ j, k j ≤ b := fun j => (hk j).trans hrb + rw [destination_occurrences k hkb, source_occurrences k hkb] + exact source_degree_gt_destination k hb hk i hi + +end Problem346.SecondTransfer + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondEndpoints.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondEndpoints.lean index 2de5ac1f9ac4d54aa7a224c6417264ab1727d9ff..c62f9a73c3247a24f510b9406e0c5b0a92db447d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondEndpoints.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondEndpoints.lean @@ -1,75 +1,75 @@ -import OAI.RepresentationTheory.FoulkesHowe.SecondLabels -import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm -import OAI.RepresentationTheory.FoulkesHowe.MonomialCut -import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial - -namespace OAI - -noncomputable section - -namespace Problem346.SecondTransfer - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- At the zero count vector, every row consists entirely of its independent vector. -/ -theorem initial_eval {r b : ℕ} (T : SymmetricMultilinearForm (r+1) b V) - (v : Block r → V) : - flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => 0) p)) = - T (fun i => symMonomial b V (fun _ => v (some i))) := by - simp only [flattenedSymmetricForm_apply, label_zero] - -/-- At the terminal count vector, the first `r` factors in every moving row -are the common vector. This is precisely the product form in the induction hypothesis. -/ -theorem terminal_eval (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) (v : Block r → V) : - flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => r) p)) = - T (Fin.cons (symMonomial (r+m) V (fun _ => v (some 0))) - (fun i => symPowMul r m (symMonomial r V (fun _ => v none)) - (symMonomial m V (fun _ => v (some i.succ))))) := by - rw [flattenedSymmetricForm_apply] - apply congrArg T - funext i - refine Fin.cases ?_ (fun i => ?_) i - · simp only [label_zero_row, Fin.cons_zero] - · simp only [label_succ_row, Fin.cons_succ, apply_ite] - exact symMonomial_cut r m (v none) (v (some i.succ)) - -/-- The known common-power vanishing implies the terminal labelled expression vanishes. -/ -theorem terminal_eval_zero (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) - (v : Block r → V) : - flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => r) p)) = 0 := by - rw [terminal_eval] - exact h (v none) (v (some 0)) (fun i => symMonomial m V (fun _ => v (some i.succ))) - -/-- The terminal labelled polynomial is zero, before any degree-shift cancellation. -/ -theorem terminal_polynomial_zero {κ : Type*} [Fintype κ] (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) - (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) : - multilinearPolynomial (flattenedSymmetricForm T) e (label (fun _ : Fin r => r)) = 0 := by - apply multilinearPolynomial_eq_zero - exact terminal_eval_zero r m T h - -/-- After cancelling all shifts, the initial polynomial identity evaluates to -vanishing on independent pure powers in every slot. -/ -theorem independent_powers_zero_of_initial_polynomial_zero - {κ : Type*} [Fintype κ] {r b : ℕ} - (T : SymmetricMultilinearForm (r+1) b V) (e : Module.Basis κ ℂ V) - (h : multilinearPolynomial (flattenedSymmetricForm T) e - (label (fun _ : Fin r => 0)) = 0) (v : Fin (r+1) → V) : - T (fun i => symMonomial b V (fun _ => v i)) = 0 := by - have hv := (multilinearPolynomial_eq_zero_iff (flattenedSymmetricForm T) e - (label (fun _ : Fin r => 0))).mp h (fun o => o.elim 0 v) - simpa only [flattenedSymmetricForm_apply, label_zero, Option.elim_some] using hv - -end Problem346.SecondTransfer - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SecondLabels +import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm +import OAI.RepresentationTheory.FoulkesHowe.MonomialCut +import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial + +namespace OAI + +noncomputable section + +namespace Problem346.SecondTransfer + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- At the zero count vector, every row consists entirely of its independent vector. -/ +theorem initial_eval {r b : ℕ} (T : SymmetricMultilinearForm (r+1) b V) + (v : Block r → V) : + flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => 0) p)) = + T (fun i => symMonomial b V (fun _ => v (some i))) := by + simp only [flattenedSymmetricForm_apply, label_zero] + +/-- At the terminal count vector, the first `r` factors in every moving row +are the common vector. This is precisely the product form in the induction hypothesis. -/ +theorem terminal_eval (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) (v : Block r → V) : + flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => r) p)) = + T (Fin.cons (symMonomial (r+m) V (fun _ => v (some 0))) + (fun i => symPowMul r m (symMonomial r V (fun _ => v none)) + (symMonomial m V (fun _ => v (some i.succ))))) := by + rw [flattenedSymmetricForm_apply] + apply congrArg T + funext i + refine Fin.cases ?_ (fun i => ?_) i + · simp only [label_zero_row, Fin.cons_zero] + · simp only [label_succ_row, Fin.cons_succ, apply_ite] + exact symMonomial_cut r m (v none) (v (some i.succ)) + +/-- The known common-power vanishing implies the terminal labelled expression vanishes. -/ +theorem terminal_eval_zero (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) + (v : Block r → V) : + flattenedSymmetricForm T (fun p => v (label (fun _ : Fin r => r) p)) = 0 := by + rw [terminal_eval] + exact h (v none) (v (some 0)) (fun i => symMonomial m V (fun _ => v (some i.succ))) + +/-- The terminal labelled polynomial is zero, before any degree-shift cancellation. -/ +theorem terminal_polynomial_zero {κ : Type*} [Fintype κ] (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) + (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) : + multilinearPolynomial (flattenedSymmetricForm T) e (label (fun _ : Fin r => r)) = 0 := by + apply multilinearPolynomial_eq_zero + exact terminal_eval_zero r m T h + +/-- After cancelling all shifts, the initial polynomial identity evaluates to +vanishing on independent pure powers in every slot. -/ +theorem independent_powers_zero_of_initial_polynomial_zero + {κ : Type*} [Fintype κ] {r b : ℕ} + (T : SymmetricMultilinearForm (r+1) b V) (e : Module.Basis κ ℂ V) + (h : multilinearPolynomial (flattenedSymmetricForm T) e + (label (fun _ : Fin r => 0)) = 0) (v : Fin (r+1) → V) : + T (fun i => symMonomial b V (fun _ => v i)) = 0 := by + have hv := (multilinearPolynomial_eq_zero_iff (flattenedSymmetricForm T) e + (label (fun _ : Fin r => 0))).mp h (fun o => o.elim 0 v) + simpa only [flattenedSymmetricForm_apply, label_zero, Option.elim_some] using hv + +end Problem346.SecondTransfer + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondLabels.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondLabels.lean index 5acfc25f706a3113bd236bc83592657004a25b90..e11fff64d071c6d1a6a5bfbc8d1690c456cd0d8a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondLabels.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondLabels.lean @@ -1,34 +1,34 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346.SecondTransfer - -/-- Blocks: `none` is the common vector, `some 0` is the fixed first row, -and `some i.succ` is the independent vector in row `i`. -/ -abbrev Block (r : ℕ) := Option (Fin (r+1)) - -/-- In each nonzero row, its first `k i` factors use the common block. -/ -def label {r b : ℕ} (k : Fin r → ℕ) (p : Fin (r+1) × Fin b) : Block r := - Fin.cases (some 0) (fun i => if p.2.val < k i then none else some i.succ) p.1 - -@[simp] theorem label_zero_row {r b : ℕ} (k : Fin r → ℕ) (j : Fin b) : - label k (0,j) = some 0 := rfl - -@[simp] theorem label_succ_row {r b : ℕ} (k : Fin r → ℕ) - (i : Fin r) (j : Fin b) : - label k (i.succ,j) = if j.val < k i then none else some i.succ := rfl - -@[simp] theorem label_zero {r b : ℕ} (p : Fin (r+1) × Fin b) : - label (fun _ : Fin r => 0) p = some p.1 := by - rcases p with ⟨i,j⟩ - refine Fin.cases ?_ (fun i => ?_) i <;> simp - -end Problem346.SecondTransfer - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346.SecondTransfer + +/-- Blocks: `none` is the common vector, `some 0` is the fixed first row, +and `some i.succ` is the independent vector in row `i`. -/ +abbrev Block (r : ℕ) := Option (Fin (r+1)) + +/-- In each nonzero row, its first `k i` factors use the common block. -/ +def label {r b : ℕ} (k : Fin r → ℕ) (p : Fin (r+1) × Fin b) : Block r := + Fin.cases (some 0) (fun i => if p.2.val < k i then none else some i.succ) p.1 + +@[simp] theorem label_zero_row {r b : ℕ} (k : Fin r → ℕ) (j : Fin b) : + label k (0,j) = some 0 := rfl + +@[simp] theorem label_succ_row {r b : ℕ} (k : Fin r → ℕ) + (i : Fin r) (j : Fin b) : + label k (i.succ,j) = if j.val < k i then none else some i.succ := rfl + +@[simp] theorem label_zero {r b : ℕ} (p : Fin (r+1) × Fin b) : + label (fun _ : Fin r => 0) p = some p.1 := by + rcases p with ⟨i,j⟩ + refine Fin.cases ?_ (fun i => ?_) i <;> simp + +end Problem346.SecondTransfer + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondSwap.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondSwap.lean index 206506bce4cfdf797f25dae6c293f282ba836fba..ad1f4dd29d4745d488a261726800a3dbfede4c75 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondSwap.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondSwap.lean @@ -1,75 +1,75 @@ -import OAI.RepresentationTheory.FoulkesHowe.SecondLabels - -namespace OAI - -noncomputable section -namespace Problem346.SecondTransfer - -/-- Swap two factor positions in one nonzero row, leaving all other rows fixed. -/ -def rowFactorSwap {r b : ℕ} (i : Fin r) (j l : Fin b) : - Fin (r+1) → Equiv.Perm (Fin b) := - fun a => if a = i.succ then Equiv.swap j l else Equiv.refl _ - -/-- Changing any remaining source factor to the common block agrees with progressing -the prefix count, after a permutation internal to that row. -/ -theorem update_label_eq_progress_rowSwap - {r b : ℕ} (k : Fin r → ℕ) (i : Fin r) (hi : k i < b) - (j : Fin b) (hj : k i ≤ j.val) (p : Fin (r+1) × Fin b) : - Function.update (label k) (i.succ, j) none p = - label (Function.update k i (k i+1)) - (p.1, rowFactorSwap i j ⟨k i, hi⟩ p.1 p.2) := by - classical - rcases p with ⟨a,l⟩ - refine Fin.cases ?_ (fun a => ?_) a - · simp [Function.update, rowFactorSwap, label] - intro h - have hv := congrArg Fin.val h - simp at hv - · by_cases hai : a = i - · subst a - by_cases hlj : l = j - · subst l - simp [rowFactorSwap, label] - · by_cases hlk : l = (⟨k i, hi⟩ : Fin b) - · subst l - have hjval : k i < j.val := by - have hne : j.val ≠ k i := by - intro he - apply hlj - exact Fin.ext he.symm - omega - simp [rowFactorSwap, label, hlj, Nat.not_lt.mpr (by omega : k i+1 ≤ j.val)] - · have hval : l.val ≠ k i := by - intro he - apply hlk - exact Fin.ext he - have hlt : l.val < k i+1 ↔ l.val < k i := by omega - simp [rowFactorSwap, label, hlj, hlt, - Equiv.swap_apply_of_ne_of_ne hlj hlk] - · simp [rowFactorSwap, label, hai] - -/-- Any expression invariant under permutations of factors within each row takes the -same value on a derivative label update and the progressed prefix labels. -/ -theorem invariant_update_label_eq_progress - {r b : ℕ} {A : Type*} - (F : ((Fin (r+1) × Fin b) → Block r) → A) - (hF : ∀ (l : (Fin (r+1) × Fin b) → Block r) - (σ : Fin (r+1) → Equiv.Perm (Fin b)), - F (fun p => l (p.1, σ p.1 p.2)) = F l) - (k : Fin r → ℕ) (i : Fin r) (hi : k i < b) - (j : Fin b) (hj : k i ≤ j.val) : - F (Function.update (label k) (i.succ,j) none) = - F (label (Function.update k i (k i+1))) := by - have heq : Function.update (label k) (i.succ,j) none = - fun p => label (Function.update k i (k i+1)) - (p.1, rowFactorSwap i j ⟨k i, hi⟩ p.1 p.2) := by - funext p - exact update_label_eq_progress_rowSwap k i hi j hj p - rw [heq] - exact hF _ _ - -end Problem346.SecondTransfer - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.SecondLabels + +namespace OAI + +noncomputable section +namespace Problem346.SecondTransfer + +/-- Swap two factor positions in one nonzero row, leaving all other rows fixed. -/ +def rowFactorSwap {r b : ℕ} (i : Fin r) (j l : Fin b) : + Fin (r+1) → Equiv.Perm (Fin b) := + fun a => if a = i.succ then Equiv.swap j l else Equiv.refl _ + +/-- Changing any remaining source factor to the common block agrees with progressing +the prefix count, after a permutation internal to that row. -/ +theorem update_label_eq_progress_rowSwap + {r b : ℕ} (k : Fin r → ℕ) (i : Fin r) (hi : k i < b) + (j : Fin b) (hj : k i ≤ j.val) (p : Fin (r+1) × Fin b) : + Function.update (label k) (i.succ, j) none p = + label (Function.update k i (k i+1)) + (p.1, rowFactorSwap i j ⟨k i, hi⟩ p.1 p.2) := by + classical + rcases p with ⟨a,l⟩ + refine Fin.cases ?_ (fun a => ?_) a + · simp [Function.update, rowFactorSwap, label] + intro h + have hv := congrArg Fin.val h + simp at hv + · by_cases hai : a = i + · subst a + by_cases hlj : l = j + · subst l + simp [rowFactorSwap, label] + · by_cases hlk : l = (⟨k i, hi⟩ : Fin b) + · subst l + have hjval : k i < j.val := by + have hne : j.val ≠ k i := by + intro he + apply hlj + exact Fin.ext he.symm + omega + simp [rowFactorSwap, label, hlj, Nat.not_lt.mpr (by omega : k i+1 ≤ j.val)] + · have hval : l.val ≠ k i := by + intro he + apply hlk + exact Fin.ext he + have hlt : l.val < k i+1 ↔ l.val < k i := by omega + simp [rowFactorSwap, label, hlj, hlt, + Equiv.swap_apply_of_ne_of_ne hlj hlk] + · simp [rowFactorSwap, label, hai] + +/-- Any expression invariant under permutations of factors within each row takes the +same value on a derivative label update and the progressed prefix labels. -/ +theorem invariant_update_label_eq_progress + {r b : ℕ} {A : Type*} + (F : ((Fin (r+1) × Fin b) → Block r) → A) + (hF : ∀ (l : (Fin (r+1) × Fin b) → Block r) + (σ : Fin (r+1) → Equiv.Perm (Fin b)), + F (fun p => l (p.1, σ p.1 p.2)) = F l) + (k : Fin r → ℕ) (i : Fin r) (hi : k i < b) + (j : Fin b) (hj : k i ≤ j.val) : + F (Function.update (label k) (i.succ,j) none) = + F (label (Function.update k i (k i+1))) := by + have heq : Function.update (label k) (i.succ,j) none = + fun p => label (Function.update k i (k i+1)) + (p.1, rowFactorSwap i j ⟨k i, hi⟩ p.1 p.2) := by + funext p + exact update_label_eq_progress_rowSwap k i hi j hj p + rw [heq] + exact hF _ _ + +end Problem346.SecondTransfer + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondTransfer.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondTransfer.lean index 321cbf1ebba28c67af8aa7f73af899d3735e7133..cc7bc93d8df0edf2b19447fceea6440ebb5fc7c5 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SecondTransfer.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SecondTransfer.lean @@ -1,83 +1,83 @@ -import OAI.RepresentationTheory.FoulkesHowe.EncodedCancellation -import OAI.RepresentationTheory.FoulkesHowe.SecondCounts -import OAI.RepresentationTheory.FoulkesHowe.SecondSwap -import OAI.RepresentationTheory.FoulkesHowe.SecondEndpoints -import OAI.RepresentationTheory.FoulkesHowe.GridCancellation - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346.SecondTransfer - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Polynomial encoding preserves the independent factor permutations of each row. -/ -theorem polynomial_row_permute {κ : Type*} [Fintype κ] {r b : ℕ} - (T : SymmetricMultilinearForm (r+1) b V) (e : κ → V) - (l : Fin (r+1) × Fin b → Block r) - (σ : Fin (r+1) → Equiv.Perm (Fin b)) : - multilinearPolynomial (flattenedSymmetricForm T) e - (fun p => l (p.1, σ p.1 p.2)) = - multilinearPolynomial (flattenedSymmetricForm T) e l := by - apply MvPolynomial.funext - intro z - simp only [eval_multilinearPolynomial] - exact flattenedSymmetricForm_inner_permute T σ - (fun p => ∑ j : κ, z (l p,j) • e j) - -/-- A single unfinished row can be recovered from its one-step progressed state. -/ -theorem polynomial_step {κ : Type*} [Fintype κ] {r b : ℕ} - (T : SymmetricMultilinearForm (r+1) b V) (e : κ → V) - (hb : r * (r+1) ≤ b) (k : Fin r → ℕ) (hk : ∀ j, k j ≤ r) - (i : Fin r) (hi : k i < r) - (hnext : multilinearPolynomial (flattenedSymmetricForm T) e - (label (Function.update k i (k i+1))) = 0) : - multilinearPolynomial (flattenedSymmetricForm T) e (label k) = 0 := by - classical - apply multilinearPolynomial_eq_zero_of_replacements - (flattenedSymmetricForm T) e (label k) (some i.succ) none (by simp) - · have hd := destination_occurrences_lt_source (b := b) k hb hk i hi - simpa only [Finset.card_filter] using hd - · rintro ⟨row,j⟩ hp - obtain ⟨hrow,hj⟩ := (label_eq_source_iff k i (row,j)).mp hp - change row = i.succ at hrow - change k i ≤ j.val at hj - subst row - have hrb : r ≤ b := by nlinarith - have hki : k i < b := lt_of_lt_of_le hi hrb - have heq := invariant_update_label_eq_progress - (fun l => multilinearPolynomial (flattenedSymmetricForm T) e l) - (polynomial_row_permute T e) k i hki j hj - exact heq.trans hnext - -/-- The second differential transfer: remove the common degree-`r` power from -all `r` moving arguments. Count-vector induction allows the shifts in any order. -/ -theorem second_transfer [FiniteDimensional ℂ V] (r m : ℕ) - (hb : r * (r+1) ≤ r+m) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) : - ∀ v : Fin (r+1) → V, - T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0 := by - classical - let e := Module.finBasis ℂ V - let P (k : Fin r → ℕ) := - multilinearPolynomial (flattenedSymmetricForm T) e (label k) - have hend : P (fun _ => r) = 0 := terminal_polynomial_zero r m T e h - have hzero : P (fun _ => 0) = 0 := by - apply zero_of_upward_grid r P hend - · intro k hk i hi hnext - exact polynomial_step T e hb k hk i hi hnext - · intro i - exact Nat.zero_le r - exact independent_powers_zero_of_initial_polynomial_zero T e hzero - -end Problem346.SecondTransfer - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.EncodedCancellation +import OAI.RepresentationTheory.FoulkesHowe.SecondCounts +import OAI.RepresentationTheory.FoulkesHowe.SecondSwap +import OAI.RepresentationTheory.FoulkesHowe.SecondEndpoints +import OAI.RepresentationTheory.FoulkesHowe.GridCancellation + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346.SecondTransfer + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Polynomial encoding preserves the independent factor permutations of each row. -/ +theorem polynomial_row_permute {κ : Type*} [Fintype κ] {r b : ℕ} + (T : SymmetricMultilinearForm (r+1) b V) (e : κ → V) + (l : Fin (r+1) × Fin b → Block r) + (σ : Fin (r+1) → Equiv.Perm (Fin b)) : + multilinearPolynomial (flattenedSymmetricForm T) e + (fun p => l (p.1, σ p.1 p.2)) = + multilinearPolynomial (flattenedSymmetricForm T) e l := by + apply MvPolynomial.funext + intro z + simp only [eval_multilinearPolynomial] + exact flattenedSymmetricForm_inner_permute T σ + (fun p => ∑ j : κ, z (l p,j) • e j) + +/-- A single unfinished row can be recovered from its one-step progressed state. -/ +theorem polynomial_step {κ : Type*} [Fintype κ] {r b : ℕ} + (T : SymmetricMultilinearForm (r+1) b V) (e : κ → V) + (hb : r * (r+1) ≤ b) (k : Fin r → ℕ) (hk : ∀ j, k j ≤ r) + (i : Fin r) (hi : k i < r) + (hnext : multilinearPolynomial (flattenedSymmetricForm T) e + (label (Function.update k i (k i+1))) = 0) : + multilinearPolynomial (flattenedSymmetricForm T) e (label k) = 0 := by + classical + apply multilinearPolynomial_eq_zero_of_replacements + (flattenedSymmetricForm T) e (label k) (some i.succ) none (by simp) + · have hd := destination_occurrences_lt_source (b := b) k hb hk i hi + simpa only [Finset.card_filter] using hd + · rintro ⟨row,j⟩ hp + obtain ⟨hrow,hj⟩ := (label_eq_source_iff k i (row,j)).mp hp + change row = i.succ at hrow + change k i ≤ j.val at hj + subst row + have hrb : r ≤ b := by nlinarith + have hki : k i < b := lt_of_lt_of_le hi hrb + have heq := invariant_update_label_eq_progress + (fun l => multilinearPolynomial (flattenedSymmetricForm T) e l) + (polynomial_row_permute T e) k i hki j hj + exact heq.trans hnext + +/-- The second differential transfer: remove the common degree-`r` power from +all `r` moving arguments. Count-vector induction allows the shifts in any order. -/ +theorem second_transfer [FiniteDimensional ℂ V] (r m : ℕ) + (hb : r * (r+1) ≤ r+m) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (h : ∀ x t : V, ∀ Q : Fin r → SymPow m V, + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) = 0) : + ∀ v : Fin (r+1) → V, + T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0 := by + classical + let e := Module.finBasis ℂ V + let P (k : Fin r → ℕ) := + multilinearPolynomial (flattenedSymmetricForm T) e (label k) + have hend : P (fun _ => r) = 0 := terminal_polynomial_zero r m T e h + have hzero : P (fun _ => 0) = 0 := by + apply zero_of_upward_grid r P hend + · intro k hk i hi hnext + exact polynomial_step T e hb k hk i hi hnext + · intro i + exact Nat.zero_le r + exact independent_powers_zero_of_initial_polynomial_zero T e hzero + +end Problem346.SecondTransfer + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftHomogeneity.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftHomogeneity.lean index 52608db123a73d7bc68944e91438361a04670076..8bd48b0ac21cffeb381dc177bcb1aa0ecaefcc78 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftHomogeneity.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftHomogeneity.lean @@ -1,158 +1,158 @@ -import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation - -namespace OAI - -noncomputable section - -open scoped BigOperators -open MvPolynomial - -namespace Problem346 - -/-- Differentiating a weighted homogeneous polynomial lowers its weighted degree -by the weight of the differentiated variable. The statement also covers degree -zero, since a zero derivative is homogeneous in every degree. -/ -theorem weightedHomogeneous_pderiv - {σ R : Type*} [CommSemiring R] {w : σ → ℕ} - {f : MvPolynomial σ R} {m : ℕ} - (hf : IsWeightedHomogeneous w f m) (i : σ) : - IsWeightedHomogeneous w (pderiv i f) (m - w i) := by - classical - intro d hd - rw [coeff_pderiv] at hd - have h := hf (left_ne_zero_of_mul hd) - rw [map_add, Finsupp.weight_single, one_smul] at h - omega - -/-- A weighted directional derivative has the expected homogeneous degree -when all source variables and all destination variables have common weights. -/ -theorem weightedHomogeneous_directional - {σ κ R : Type*} [Fintype κ] [CommSemiring R] - {w : σ → ℕ} {f : MvPolynomial σ R} {m a b : ℕ} - (hf : IsWeightedHomogeneous w f m) (s t : κ → σ) - (hs : ∀ i, w (s i) = a) (ht : ∀ i, w (t i) = b) : - IsWeightedHomogeneous w (∑ i, X (t i) * pderiv (s i) f) (b + (m - a)) := by - apply IsWeightedHomogeneous.sum - intro i hi - simpa [hs i, ht i] using - (isWeightedHomogeneous_X R w (t i)).mul (weightedHomogeneous_pderiv hf (s i)) - -private theorem derivation_sum_apply - {σ κ R : Type*} [CommRing R] (s : Finset κ) - (D : κ → Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) - (f : MvPolynomial σ R) : (∑ i ∈ s, D i) f = ∑ i ∈ s, D i f := by - change Derivation.coeFnAddMonoidHom (∑ i ∈ s, D i) f = _ - rw [map_sum] - simp - -/-- The generator-defined block shift agrees with the usual sum of partial - derivatives over its coordinate block. -/ -theorem blockShift_eq_sum_pderiv - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] (u v : ι) : - blockShift (κ := κ) R u v = - ∑ i : κ, (X (v, i) : MvPolynomial (ι × κ) R) • pderiv (u, i) := by - classical - apply MvPolynomial.derivation_ext - rintro ⟨k, l⟩ - simp only [blockShift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] - by_cases h : k = u - · subst k - simp [Pi.single_apply, Prod.mk.injEq] - · simp [Prod.mk.injEq, h] - -@[simp] theorem blockShift_apply_eq_sum - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v : ι) (f : MvPolynomial (ι × κ) R) : - blockShift R u v f = ∑ i : κ, X (v, i) * pderiv (u, i) f := by - rw [blockShift_eq_sum_pderiv] - simp only [derivation_sum_apply, Derivation.smul_apply, smul_eq_mul] - -/-- A block shift changes the degree in an observed block by adding one for -the destination and subtracting one for the source. -/ -theorem blockShift_isWeightedHomogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v k : ι) {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) - (blockShift R u v f) - ((if v = k then 1 else 0) + (m - (if u = k then 1 else 0))) := by - rw [blockShift_apply_eq_sum] - exact weightedHomogeneous_directional hf (fun i => (u, i)) (fun i => (v, i)) - (fun _ => rfl) (fun _ => rfl) - -/-- The source block loses one unit of degree under a directional shift. -/ -theorem blockShift_source_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) f m) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) - (blockShift R u v f) (m - 1) := by - simpa [huv, Ne.symm huv] using blockShift_isWeightedHomogeneous u v u hf - -/-- The destination block gains one unit of degree under a directional shift. -/ -theorem blockShift_destination_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) f m) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) - (blockShift R u v f) (m + 1) := by - simpa [huv, Nat.add_comm] using blockShift_isWeightedHomogeneous u v v hf - -/-- Spectator block degrees are unchanged by a directional shift. -/ -theorem blockShift_spectator_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v k : ι) (hu : u ≠ k) (hv : v ≠ k) - {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) - (blockShift R u v f) m := by - simpa [hu, hv] using blockShift_isWeightedHomogeneous u v k hf - -/-- Repeated shifts lower the source degree by the number of operations. -/ -theorem blockShift_pow_source_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) f m) - (n : ℕ) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) - (((blockShift R u v).toLinearMap ^ n) f) (m - n) := by - induction n with - | zero => simpa using hf - | succ n ih => - rw [pow_succ', Module.End.mul_apply] - simpa [Nat.sub_sub] using blockShift_source_homogeneous u v huv ih - -/-- Repeated shifts increase the destination degree by the number of operations. -/ -theorem blockShift_pow_destination_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) f m) - (n : ℕ) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) - (((blockShift R u v).toLinearMap ^ n) f) (m + n) := by - induction n with - | zero => simpa using hf - | succ n ih => - rw [pow_succ', Module.End.mul_apply] - simpa [Nat.add_assoc] using blockShift_destination_homogeneous u v huv ih - -/-- Repeated shifts leave all spectator block degrees unchanged. -/ -theorem blockShift_pow_spectator_homogeneous - {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] - (u v k : ι) (hu : u ≠ k) (hv : v ≠ k) - {f : MvPolynomial (ι × κ) R} {m : ℕ} - (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) - (n : ℕ) : - IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) - (((blockShift R u v).toLinearMap ^ n) f) m := by - induction n with - | zero => simpa using hf - | succ n ih => - rw [pow_succ', Module.End.mul_apply] - exact blockShift_spectator_homogeneous u v k hu hv ih - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation + +namespace OAI + +noncomputable section + +open scoped BigOperators +open MvPolynomial + +namespace Problem346 + +/-- Differentiating a weighted homogeneous polynomial lowers its weighted degree +by the weight of the differentiated variable. The statement also covers degree +zero, since a zero derivative is homogeneous in every degree. -/ +theorem weightedHomogeneous_pderiv + {σ R : Type*} [CommSemiring R] {w : σ → ℕ} + {f : MvPolynomial σ R} {m : ℕ} + (hf : IsWeightedHomogeneous w f m) (i : σ) : + IsWeightedHomogeneous w (pderiv i f) (m - w i) := by + classical + intro d hd + rw [coeff_pderiv] at hd + have h := hf (left_ne_zero_of_mul hd) + rw [map_add, Finsupp.weight_single, one_smul] at h + omega + +/-- A weighted directional derivative has the expected homogeneous degree +when all source variables and all destination variables have common weights. -/ +theorem weightedHomogeneous_directional + {σ κ R : Type*} [Fintype κ] [CommSemiring R] + {w : σ → ℕ} {f : MvPolynomial σ R} {m a b : ℕ} + (hf : IsWeightedHomogeneous w f m) (s t : κ → σ) + (hs : ∀ i, w (s i) = a) (ht : ∀ i, w (t i) = b) : + IsWeightedHomogeneous w (∑ i, X (t i) * pderiv (s i) f) (b + (m - a)) := by + apply IsWeightedHomogeneous.sum + intro i hi + simpa [hs i, ht i] using + (isWeightedHomogeneous_X R w (t i)).mul (weightedHomogeneous_pderiv hf (s i)) + +private theorem derivation_sum_apply + {σ κ R : Type*} [CommRing R] (s : Finset κ) + (D : κ → Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) + (f : MvPolynomial σ R) : (∑ i ∈ s, D i) f = ∑ i ∈ s, D i f := by + change Derivation.coeFnAddMonoidHom (∑ i ∈ s, D i) f = _ + rw [map_sum] + simp + +/-- The generator-defined block shift agrees with the usual sum of partial + derivatives over its coordinate block. -/ +theorem blockShift_eq_sum_pderiv + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] (u v : ι) : + blockShift (κ := κ) R u v = + ∑ i : κ, (X (v, i) : MvPolynomial (ι × κ) R) • pderiv (u, i) := by + classical + apply MvPolynomial.derivation_ext + rintro ⟨k, l⟩ + simp only [blockShift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] + by_cases h : k = u + · subst k + simp [Pi.single_apply, Prod.mk.injEq] + · simp [Prod.mk.injEq, h] + +@[simp] theorem blockShift_apply_eq_sum + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v : ι) (f : MvPolynomial (ι × κ) R) : + blockShift R u v f = ∑ i : κ, X (v, i) * pderiv (u, i) f := by + rw [blockShift_eq_sum_pderiv] + simp only [derivation_sum_apply, Derivation.smul_apply, smul_eq_mul] + +/-- A block shift changes the degree in an observed block by adding one for +the destination and subtracting one for the source. -/ +theorem blockShift_isWeightedHomogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v k : ι) {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) + (blockShift R u v f) + ((if v = k then 1 else 0) + (m - (if u = k then 1 else 0))) := by + rw [blockShift_apply_eq_sum] + exact weightedHomogeneous_directional hf (fun i => (u, i)) (fun i => (v, i)) + (fun _ => rfl) (fun _ => rfl) + +/-- The source block loses one unit of degree under a directional shift. -/ +theorem blockShift_source_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) f m) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) + (blockShift R u v f) (m - 1) := by + simpa [huv, Ne.symm huv] using blockShift_isWeightedHomogeneous u v u hf + +/-- The destination block gains one unit of degree under a directional shift. -/ +theorem blockShift_destination_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) f m) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) + (blockShift R u v f) (m + 1) := by + simpa [huv, Nat.add_comm] using blockShift_isWeightedHomogeneous u v v hf + +/-- Spectator block degrees are unchanged by a directional shift. -/ +theorem blockShift_spectator_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v k : ι) (hu : u ≠ k) (hv : v ≠ k) + {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) + (blockShift R u v f) m := by + simpa [hu, hv] using blockShift_isWeightedHomogeneous u v k hf + +/-- Repeated shifts lower the source degree by the number of operations. -/ +theorem blockShift_pow_source_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) f m) + (n : ℕ) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = u then 1 else 0) + (((blockShift R u v).toLinearMap ^ n) f) (m - n) := by + induction n with + | zero => simpa using hf + | succ n ih => + rw [pow_succ', Module.End.mul_apply] + simpa [Nat.sub_sub] using blockShift_source_homogeneous u v huv ih + +/-- Repeated shifts increase the destination degree by the number of operations. -/ +theorem blockShift_pow_destination_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v : ι) (huv : u ≠ v) {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) f m) + (n : ℕ) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = v then 1 else 0) + (((blockShift R u v).toLinearMap ^ n) f) (m + n) := by + induction n with + | zero => simpa using hf + | succ n ih => + rw [pow_succ', Module.End.mul_apply] + simpa [Nat.add_assoc] using blockShift_destination_homogeneous u v huv ih + +/-- Repeated shifts leave all spectator block degrees unchanged. -/ +theorem blockShift_pow_spectator_homogeneous + {ι κ R : Type*} [DecidableEq ι] [Fintype κ] [CommRing R] + (u v k : ι) (hu : u ≠ k) (hv : v ≠ k) + {f : MvPolynomial (ι × κ) R} {m : ℕ} + (hf : IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) f m) + (n : ℕ) : + IsWeightedHomogeneous (fun z : ι × κ => if z.1 = k then 1 else 0) + (((blockShift R u v).toLinearMap ^ n) f) m := by + induction n with + | zero => simpa using hf + | succ n ih => + rw [pow_succ', Module.End.mul_apply] + exact blockShift_spectator_homogeneous u v k hu hv ih + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftInjectivity.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftInjectivity.lean index 792094fc925d001ff4017f863128eb7ceb7a738c..a5937b898b3c450f1ff4c9854fc5bac50d1abb08 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftInjectivity.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftInjectivity.lean @@ -1,73 +1,73 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Problem346 -namespace ShiftInjectivity - -variable {K M : Type*} [Field K] [CharZero K] - [AddCommGroup M] [Module K M] - -/-- A weight-raising operator increases the weight of its iterates by two. -/ -theorem weight_pow (E H : Module.End K M) - (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) - (x : M) (w : K) (hx : H x = w • x) (n : ℕ) : - H ((E ^ n) x) = (w + 2 * (n : K)) • (E ^ n) x := by - induction n with - | zero => simpa using hx - | succ n ih => - rw [pow_succ', Module.End.mul_apply, hHE, ih, map_smul, - ← add_smul] - congr 1 - push_cast - ring - -/-- The lowering operator on a string generated from a vector in its kernel. -/ -theorem lowering_pow (D E H : Module.End K M) - (hDE : ∀ z, D (E z) = E (D z) - H z) - (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) - (x : M) (w : K) (hx : H x = w • x) (hDx : D x = 0) (n : ℕ) : - D ((E ^ (n + 1)) x) = - (-((n + 1 : K) * (w + n))) • (E ^ n) x := by - induction n with - | zero => - simp [hDE, hDx, hx] - | succ n ih => - rw [pow_succ', Module.End.mul_apply, hDE, ih, - weight_pow E H hHE x w hx (n + 1), map_smul] - rw [← Module.End.mul_apply, ← pow_succ', ← sub_smul] - congr 1 - push_cast - ring - -/-- Positive-weight vectors killed by a lowering operator vanish provided that the -opposite operator acts nilpotently on that vector. This is the algebraic form of -positive-weight differential injectivity and requires no inner product. -/ -theorem eq_zero_of_positive_weight (D E H : Module.End K M) - (hDE : ∀ z, D (E z) = E (D z) - H z) - (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) - (x : M) (w : ℕ) (hw : 0 < w) (hx : H x = (w : K) • x) - (hDx : D x = 0) (hnil : ∃ N : ℕ, (E ^ N) x = 0) : x = 0 := by - obtain ⟨N, hN⟩ := hnil - induction N with - | zero => simpa using hN - | succ n ih => - apply ih - have h := lowering_pow D E H hDE hHE x (w : K) hx hDx n - rw [hN, map_zero] at h - have hc : (-((n + 1 : K) * ((w : K) + n))) ≠ 0 := by - apply neg_ne_zero.mpr - apply mul_ne_zero - · exact_mod_cast (Nat.succ_ne_zero n) - · have : w + n ≠ 0 := by omega - exact_mod_cast this - exact (smul_eq_zero.mp h.symm).resolve_left hc - -end ShiftInjectivity -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Problem346 +namespace ShiftInjectivity + +variable {K M : Type*} [Field K] [CharZero K] + [AddCommGroup M] [Module K M] + +/-- A weight-raising operator increases the weight of its iterates by two. -/ +theorem weight_pow (E H : Module.End K M) + (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) + (x : M) (w : K) (hx : H x = w • x) (n : ℕ) : + H ((E ^ n) x) = (w + 2 * (n : K)) • (E ^ n) x := by + induction n with + | zero => simpa using hx + | succ n ih => + rw [pow_succ', Module.End.mul_apply, hHE, ih, map_smul, + ← add_smul] + congr 1 + push_cast + ring + +/-- The lowering operator on a string generated from a vector in its kernel. -/ +theorem lowering_pow (D E H : Module.End K M) + (hDE : ∀ z, D (E z) = E (D z) - H z) + (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) + (x : M) (w : K) (hx : H x = w • x) (hDx : D x = 0) (n : ℕ) : + D ((E ^ (n + 1)) x) = + (-((n + 1 : K) * (w + n))) • (E ^ n) x := by + induction n with + | zero => + simp [hDE, hDx, hx] + | succ n ih => + rw [pow_succ', Module.End.mul_apply, hDE, ih, + weight_pow E H hHE x w hx (n + 1), map_smul] + rw [← Module.End.mul_apply, ← pow_succ', ← sub_smul] + congr 1 + push_cast + ring + +/-- Positive-weight vectors killed by a lowering operator vanish provided that the +opposite operator acts nilpotently on that vector. This is the algebraic form of +positive-weight differential injectivity and requires no inner product. -/ +theorem eq_zero_of_positive_weight (D E H : Module.End K M) + (hDE : ∀ z, D (E z) = E (D z) - H z) + (hHE : ∀ z, H (E z) = E (H z) + (2 : K) • E z) + (x : M) (w : ℕ) (hw : 0 < w) (hx : H x = (w : K) • x) + (hDx : D x = 0) (hnil : ∃ N : ℕ, (E ^ N) x = 0) : x = 0 := by + obtain ⟨N, hN⟩ := hnil + induction N with + | zero => simpa using hN + | succ n ih => + apply ih + have h := lowering_pow D E H hDE hHE x (w : K) hx hDx n + rw [hN, map_zero] at h + have hc : (-((n + 1 : K) * ((w : K) + n))) ≠ 0 := by + apply neg_ne_zero.mpr + apply mul_ne_zero + · exact_mod_cast (Nat.succ_ne_zero n) + · have : w + n ≠ 0 := by omega + exact_mod_cast this + exact (smul_eq_zero.mp h.symm).resolve_left hc + +end ShiftInjectivity +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftNilpotence.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftNilpotence.lean index 2ac784ad743999c1c566b4280251caacff68385b..5eca41b66b46733799fc12e776c873a36226eca6 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftNilpotence.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftNilpotence.lean @@ -1,109 +1,109 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Problem346 - -section Derivation - -variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] - -/-- A derivation is locally nilpotent at a product when it is locally nilpotent -at each factor. The deliberately loose exponent avoids binomial coefficients. -/ -theorem derivation_pow_mul_eq_zero (D : Derivation R A A) - (m n : ℕ) (a b : A) - (ha : (D.toLinearMap ^ m) a = 0) - (hb : (D.toLinearMap ^ n) b = 0) : - (D.toLinearMap ^ (m + n)) (a * b) = 0 := by - induction m generalizing n a b with - | zero => - simp only [pow_zero, Module.End.one_apply] at ha - simp [ha] - | succ m hm => - induction n generalizing a b with - | zero => - simp only [pow_zero, Module.End.one_apply] at hb - simp [hb] - | succ n hn => - have hDa : (D.toLinearMap ^ m) (D a) = 0 := by - rw [pow_succ, Module.End.mul_apply] at ha - exact ha - have hDb : (D.toLinearMap ^ n) (D b) = 0 := by - rw [pow_succ, Module.End.mul_apply] at hb - exact hb - have hp := hm (n + 1) (D a) b hDa hb - have hq := hn a (D b) ha hDb - have he : m + 1 + (n + 1) = (m + (n + 1)) + 1 := by omega - rw [he, pow_succ, Module.End.mul_apply] - change (D.toLinearMap ^ (m + (n + 1))) (D (a * b)) = 0 - rw [D.leibniz, map_add] - have hp' : (D.toLinearMap ^ (m + (n + 1))) (b * D a) = 0 := by - simpa only [mul_comm] using hp - have hq' : (D.toLinearMap ^ (m + (n + 1))) (a * D b) = 0 := by - simpa only [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hq - simp only [smul_eq_mul, hp', hq', add_zero] - - -/-- Pointwise local nilpotence of a derivation is closed under addition. -/ -theorem derivation_exists_pow_add_eq_zero (D : Derivation R A A) (a b : A) - (ha : ∃ m : ℕ, (D.toLinearMap ^ m) a = 0) - (hb : ∃ n : ℕ, (D.toLinearMap ^ n) b = 0) : - ∃ n : ℕ, (D.toLinearMap ^ n) (a + b) = 0 := by - obtain ⟨m, hm⟩ := ha - obtain ⟨n, hn⟩ := hb - refine ⟨m + n, ?_⟩ - rw [map_add, Module.End.pow_map_zero_of_le (Nat.le_add_right m n) hm, - Module.End.pow_map_zero_of_le (Nat.le_add_left n m) hn, add_zero] - -/-- Pointwise local nilpotence of a derivation is closed under multiplication. -/ -theorem derivation_exists_pow_mul_eq_zero (D : Derivation R A A) (a b : A) - (ha : ∃ m : ℕ, (D.toLinearMap ^ m) a = 0) - (hb : ∃ n : ℕ, (D.toLinearMap ^ n) b = 0) : - ∃ n : ℕ, (D.toLinearMap ^ n) (a * b) = 0 := by - obtain ⟨m, hm⟩ := ha - obtain ⟨n, hn⟩ := hb - exact ⟨m + n, derivation_pow_mul_eq_zero D m n a b hm hn⟩ - -end Derivation - -section MvPolynomial - -variable {R σ : Type*} [CommRing R] - -/-- Local nilpotence on polynomial generators implies local nilpotence everywhere. -No finiteness assumption on the variable type is needed, so spectator variables -can be retained without changing the argument. -/ -theorem mvPolynomial_derivation_locally_nilpotent - (D : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) - (hX : ∀ i : σ, ∃ n : ℕ, (D.toLinearMap ^ n) (MvPolynomial.X i) = 0) - (f : MvPolynomial σ R) : ∃ n : ℕ, (D.toLinearMap ^ n) f = 0 := by - induction f using MvPolynomial.induction_on with - | C r => - refine ⟨1, ?_⟩ - rw [pow_one] - exact MvPolynomial.derivation_C D r - | add p q hp hq => - exact derivation_exists_pow_add_eq_zero D p q hp hq - | mul_X p i hp => - exact derivation_exists_pow_mul_eq_zero D p (MvPolynomial.X i) hp (hX i) - -/-- The square-zero-on-generators criterion used for directional shifts. -/ -theorem mvPolynomial_derivation_locally_nilpotent_of_square_zero_X - (D : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) - (hX : ∀ i : σ, D (D (MvPolynomial.X i)) = 0) - (f : MvPolynomial σ R) : ∃ n : ℕ, (D.toLinearMap ^ n) f = 0 := by - apply mvPolynomial_derivation_locally_nilpotent D _ f - intro i - refine ⟨2, ?_⟩ - rw [pow_two, Module.End.mul_apply] - exact hX i - -end MvPolynomial - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Problem346 + +section Derivation + +variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] + +/-- A derivation is locally nilpotent at a product when it is locally nilpotent +at each factor. The deliberately loose exponent avoids binomial coefficients. -/ +theorem derivation_pow_mul_eq_zero (D : Derivation R A A) + (m n : ℕ) (a b : A) + (ha : (D.toLinearMap ^ m) a = 0) + (hb : (D.toLinearMap ^ n) b = 0) : + (D.toLinearMap ^ (m + n)) (a * b) = 0 := by + induction m generalizing n a b with + | zero => + simp only [pow_zero, Module.End.one_apply] at ha + simp [ha] + | succ m hm => + induction n generalizing a b with + | zero => + simp only [pow_zero, Module.End.one_apply] at hb + simp [hb] + | succ n hn => + have hDa : (D.toLinearMap ^ m) (D a) = 0 := by + rw [pow_succ, Module.End.mul_apply] at ha + exact ha + have hDb : (D.toLinearMap ^ n) (D b) = 0 := by + rw [pow_succ, Module.End.mul_apply] at hb + exact hb + have hp := hm (n + 1) (D a) b hDa hb + have hq := hn a (D b) ha hDb + have he : m + 1 + (n + 1) = (m + (n + 1)) + 1 := by omega + rw [he, pow_succ, Module.End.mul_apply] + change (D.toLinearMap ^ (m + (n + 1))) (D (a * b)) = 0 + rw [D.leibniz, map_add] + have hp' : (D.toLinearMap ^ (m + (n + 1))) (b * D a) = 0 := by + simpa only [mul_comm] using hp + have hq' : (D.toLinearMap ^ (m + (n + 1))) (a * D b) = 0 := by + simpa only [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hq + simp only [smul_eq_mul, hp', hq', add_zero] + + +/-- Pointwise local nilpotence of a derivation is closed under addition. -/ +theorem derivation_exists_pow_add_eq_zero (D : Derivation R A A) (a b : A) + (ha : ∃ m : ℕ, (D.toLinearMap ^ m) a = 0) + (hb : ∃ n : ℕ, (D.toLinearMap ^ n) b = 0) : + ∃ n : ℕ, (D.toLinearMap ^ n) (a + b) = 0 := by + obtain ⟨m, hm⟩ := ha + obtain ⟨n, hn⟩ := hb + refine ⟨m + n, ?_⟩ + rw [map_add, Module.End.pow_map_zero_of_le (Nat.le_add_right m n) hm, + Module.End.pow_map_zero_of_le (Nat.le_add_left n m) hn, add_zero] + +/-- Pointwise local nilpotence of a derivation is closed under multiplication. -/ +theorem derivation_exists_pow_mul_eq_zero (D : Derivation R A A) (a b : A) + (ha : ∃ m : ℕ, (D.toLinearMap ^ m) a = 0) + (hb : ∃ n : ℕ, (D.toLinearMap ^ n) b = 0) : + ∃ n : ℕ, (D.toLinearMap ^ n) (a * b) = 0 := by + obtain ⟨m, hm⟩ := ha + obtain ⟨n, hn⟩ := hb + exact ⟨m + n, derivation_pow_mul_eq_zero D m n a b hm hn⟩ + +end Derivation + +section MvPolynomial + +variable {R σ : Type*} [CommRing R] + +/-- Local nilpotence on polynomial generators implies local nilpotence everywhere. +No finiteness assumption on the variable type is needed, so spectator variables +can be retained without changing the argument. -/ +theorem mvPolynomial_derivation_locally_nilpotent + (D : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) + (hX : ∀ i : σ, ∃ n : ℕ, (D.toLinearMap ^ n) (MvPolynomial.X i) = 0) + (f : MvPolynomial σ R) : ∃ n : ℕ, (D.toLinearMap ^ n) f = 0 := by + induction f using MvPolynomial.induction_on with + | C r => + refine ⟨1, ?_⟩ + rw [pow_one] + exact MvPolynomial.derivation_C D r + | add p q hp hq => + exact derivation_exists_pow_add_eq_zero D p q hp hq + | mul_X p i hp => + exact derivation_exists_pow_mul_eq_zero D p (MvPolynomial.X i) hp (hX i) + +/-- The square-zero-on-generators criterion used for directional shifts. -/ +theorem mvPolynomial_derivation_locally_nilpotent_of_square_zero_X + (D : Derivation R (MvPolynomial σ R) (MvPolynomial σ R)) + (hX : ∀ i : σ, D (D (MvPolynomial.X i)) = 0) + (f : MvPolynomial σ R) : ∃ n : ℕ, (D.toLinearMap ^ n) f = 0 := by + apply mvPolynomial_derivation_locally_nilpotent D _ f + intro i + refine ⟨2, ?_⟩ + rw [pow_two, Module.End.mul_apply] + exact hX i + +end MvPolynomial + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftSequence.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftSequence.lean index a1ada5ce1e85bf463819b6893be22c351a94b93b..2364c04efa412cbc44d66a2a3e291d734c0912b0 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftSequence.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/ShiftSequence.lean @@ -1,65 +1,65 @@ -import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity -import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation -import OAI.RepresentationTheory.FoulkesHowe.BlockWeight -import OAI.RepresentationTheory.FoulkesHowe.ShiftHomogeneity - -namespace OAI - -noncomputable section - -namespace Problem346 - -open MvPolynomial PolynomialWeights - -variable {B I : Type*} [Fintype B] [Fintype I] [DecidableEq B] - -/-- Positive-weight injectivity for the shared `blockShift` derivation API. -/ -theorem blockShift_eq_zero_of_pos_weight (src dst : B) (hsd : src ≠ dst) - {f : MvPolynomial (B × I) ℂ} {p q : ℕ} (hpq : q < p) - (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) - (hDf : blockShift ℂ src dst f = 0) : f = 0 := by - refine derivation_eq_zero_of_positive_weight - (blockShift ℂ src dst) (blockShift ℂ dst src) - (blockShift ℂ src src - blockShift ℂ dst dst) - (blockShift_commutator ℂ src dst) (blockShift_weight_commutator ℂ src dst hsd) - ?_ f p q hpq ?_ hDf - · rintro ⟨b, i⟩ - exact blockShift_square_X ℂ dst src b hsd.symm i - · apply block_difference_eigenvalue src dst _ _ _ _ hp hq - · intro b i - by_cases hb : b = src - · subst b; simp only [blockShift_X] - · simp only [blockShift_X, ite_eq_right hb] - · intro b i - by_cases hb : b = dst - · subst b; simp only [blockShift_X] - · simp only [blockShift_X, ite_eq_right hb] - -/-- A chain of repeated shifts can be cancelled as long as its least intermediate -source-minus-destination weight is positive. The convenient sufficient bound -`q + 2*n ≤ p` is exactly what is used for each block in the quadratic argument. -/ -theorem blockShift_pow_eq_zero_of_degree_bound (src dst : B) (hsd : src ≠ dst) - {f : MvPolynomial (B × I) ℂ} {p q : ℕ} - (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) - (n : ℕ) : q + 2 * n ≤ p → - (((blockShift ℂ src dst).toLinearMap ^ n) f = 0) → f = 0 := by - induction n with - | zero => - intro _ hz - simpa using hz - | succ n ih => - intro hbound hz - apply ih (by omega) - apply blockShift_eq_zero_of_pos_weight src dst hsd (p := p - n) (q := q + n) - (by omega) - · exact blockShift_pow_source_homogeneous src dst hsd hp n - · exact blockShift_pow_destination_homogeneous src dst hsd hq n - · change (blockShift ℂ src dst).toLinearMap - (((blockShift ℂ src dst).toLinearMap ^ n) f) = 0 - simpa only [pow_succ', Module.End.mul_apply] using hz - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.DerivationInjectivity +import OAI.RepresentationTheory.FoulkesHowe.BlockDerivation +import OAI.RepresentationTheory.FoulkesHowe.BlockWeight +import OAI.RepresentationTheory.FoulkesHowe.ShiftHomogeneity + +namespace OAI + +noncomputable section + +namespace Problem346 + +open MvPolynomial PolynomialWeights + +variable {B I : Type*} [Fintype B] [Fintype I] [DecidableEq B] + +/-- Positive-weight injectivity for the shared `blockShift` derivation API. -/ +theorem blockShift_eq_zero_of_pos_weight (src dst : B) (hsd : src ≠ dst) + {f : MvPolynomial (B × I) ℂ} {p q : ℕ} (hpq : q < p) + (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) + (hDf : blockShift ℂ src dst f = 0) : f = 0 := by + refine derivation_eq_zero_of_positive_weight + (blockShift ℂ src dst) (blockShift ℂ dst src) + (blockShift ℂ src src - blockShift ℂ dst dst) + (blockShift_commutator ℂ src dst) (blockShift_weight_commutator ℂ src dst hsd) + ?_ f p q hpq ?_ hDf + · rintro ⟨b, i⟩ + exact blockShift_square_X ℂ dst src b hsd.symm i + · apply block_difference_eigenvalue src dst _ _ _ _ hp hq + · intro b i + by_cases hb : b = src + · subst b; simp only [blockShift_X] + · simp only [blockShift_X, ite_eq_right hb] + · intro b i + by_cases hb : b = dst + · subst b; simp only [blockShift_X] + · simp only [blockShift_X, ite_eq_right hb] + +/-- A chain of repeated shifts can be cancelled as long as its least intermediate +source-minus-destination weight is positive. The convenient sufficient bound +`q + 2*n ≤ p` is exactly what is used for each block in the quadratic argument. -/ +theorem blockShift_pow_eq_zero_of_degree_bound (src dst : B) (hsd : src ≠ dst) + {f : MvPolynomial (B × I) ℂ} {p q : ℕ} + (hp : IsBlockHomogeneous src f p) (hq : IsBlockHomogeneous dst f q) + (n : ℕ) : q + 2 * n ≤ p → + (((blockShift ℂ src dst).toLinearMap ^ n) f = 0) → f = 0 := by + induction n with + | zero => + intro _ hz + simpa using hz + | succ n ih => + intro hbound hz + apply ih (by omega) + apply blockShift_eq_zero_of_pos_weight src dst hsd (p := p - n) (q := q + n) + (by omega) + · exact blockShift_pow_source_homogeneous src dst hsd hp n + · exact blockShift_pow_destination_homogeneous src dst hsd hq n + · change (blockShift ℂ src dst).toLinearMap + (((blockShift ℂ src dst).toLinearMap ^ n) f) = 0 + simpa only [pow_succ', Module.End.mul_apply] using hz + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SlotDerivative.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SlotDerivative.lean index eeaa7a6195de24c0a67b2d32cf2211845c043439..31ded81881d254178c7ce369978e22eb6d3b45d8 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SlotDerivative.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SlotDerivative.lean @@ -1,150 +1,150 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346.SlotPolynomial - -variable {R A S I B : Type*} [CommRing R] [CommRing A] [Algebra R A] [DecidableEq S] - -/-- Leibniz rule for a finite product, expressed by replacing one factor. -/ -theorem derivation_prod (D : Derivation R A A) (s : Finset S) (f : S → A) : - D (∏ i ∈ s, f i) = - ∑ i ∈ s, ∏ j ∈ s, Function.update f i (D (f i)) j := by - classical - induction s using Finset.induction_on with - | empty => simp - | @insert a s ha ih => - rw [Finset.prod_insert ha, D.leibniz, ih, Finset.sum_insert ha] - simp only [Finset.prod_insert ha, Function.update_self, smul_eq_mul] - have h₁ : (∏ j ∈ s, Function.update f a (D (f a)) j) = ∏ j ∈ s, f j := - Finset.prod_update_of_notMem ha _ _ - rw [h₁, Finset.mul_sum] - have h₂ : (∑ i ∈ s, Function.update f i (D (f i)) a * - ∏ j ∈ s, Function.update f i (D (f i)) j) = - ∑ i ∈ s, f a * ∏ j ∈ s, Function.update f i (D (f i)) j := by - apply Finset.sum_congr rfl - intro i hi - have hai : a ≠ i := by - intro h - subst i - exact ha hi - rw [Function.update_of_ne hai] - rw [h₂] - ring - -variable [Fintype S] [Fintype I] - -/-- Coordinate polynomial of a coefficient array and an assignment of slots to blocks. -/ -def polynomial (c : (S → I) → R) (l : S → B) : MvPolynomial (B × I) R := - ∑ k : S → I, MvPolynomial.C (c k) * ∏ s : S, MvPolynomial.X (l s, k s) - -/-- A directional block derivation replaces each occurrence of the source block in turn. -/ -theorem derivation_polynomial [DecidableEq B] - (c : (S → I) → R) (l : S → B) (src dst : B) - (D : Derivation R (MvPolynomial (B × I) R) (MvPolynomial (B × I) R)) - (hD : ∀ b i, D (MvPolynomial.X (b, i)) = - if b = src then MvPolynomial.X (dst, i) else 0) : - D (polynomial c l) = - ∑ s ∈ Finset.univ.filter (fun s => l s = src), - polynomial c (Function.update l s dst) := by - classical - unfold polynomial - rw [map_sum] - simp_rw [D.leibniz, MvPolynomial.derivation_C, smul_zero, add_zero, - smul_eq_mul, derivation_prod] - simp_rw [Finset.mul_sum] - rw [Finset.sum_comm] - rw [Finset.sum_filter] - apply Finset.sum_congr rfl - intro s hs - by_cases h : l s = src - · simp only [h, ite_true] - apply Finset.sum_congr rfl - intro k hk - congr 1 - apply Finset.prod_congr rfl - intro j hj - by_cases hjs : j = s - · subst j - simp [hD] - · simp [Function.update_of_ne hjs] - · simp only [h, ite_false] - apply Finset.sum_eq_zero - intro k hk - have hz : (∏ j : S, Function.update (fun s => MvPolynomial.X (l s, k s)) - s (D (MvPolynomial.X (l s, k s))) j) = 0 := by - apply Finset.prod_eq_zero (Finset.mem_univ s) - simp [hD, h] - rw [hz, mul_zero] - -/-- Reindexing slots moves the same permutation onto the coefficient array. -/ -theorem polynomial_reindex (c : (S → I) → R) (l : S → B) (e : Equiv.Perm S) : - polynomial c (l ∘ e) = polynomial (fun k => c (k ∘ e)) l := by - classical - unfold polynomial - apply Fintype.sum_equiv (Equiv.arrowCongr e (Equiv.refl I)) - intro k - congr 1 - · congr 1 - change c k = c _ - congr 1 - funext s - simp - · apply Fintype.prod_equiv e - intro s - simp - -/-- Symmetry of coefficients induces invariance under the same permutation of slot labels. -/ -theorem polynomial_reindex_of_invariant (c : (S → I) → R) (l : S → B) - (e : Equiv.Perm S) (hc : ∀ k, c (k ∘ e) = c k) : - polynomial c (l ∘ e) = polynomial c l := by - rw [polynomial_reindex] - congr 1 - funext k - exact hc k - -/-- Swapping two equal-labelled slots shows that replacing either label gives the same polynomial. -/ -theorem polynomial_update_eq (c : (S → I) → R) (l : S → B) (s t : S) (dst : B) - (hl : l s = l t) - (hc : ∀ k, c (k ∘ Equiv.swap s t) = c k) : - polynomial c (Function.update l s dst) = polynomial c (Function.update l t dst) := by - classical - have hlabels : Function.update l s dst = - Function.update l t dst ∘ Equiv.swap s t := by - funext j - by_cases hjs : j = s - · subst j - simp - by_cases hjt : j = t - · subst j - simp [hjs, Ne.symm hjs, hl] - · simp [Equiv.swap_apply_of_ne_of_ne hjs hjt, hjs, hjt] - rw [hlabels] - exact polynomial_reindex_of_invariant c _ _ hc - -/-- If all source-labelled slots are interchangeable, the derivative is a single replacement -multiplied by their number. -/ -theorem derivation_polynomial_eq_card_smul [DecidableEq B] - (c : (S → I) → R) (l : S → B) (src dst : B) (t : S) (ht : l t = src) - (D : Derivation R (MvPolynomial (B × I) R) (MvPolynomial (B × I) R)) - (hD : ∀ b i, D (MvPolynomial.X (b, i)) = - if b = src then MvPolynomial.X (dst, i) else 0) - (hc : ∀ s, l s = src → ∀ k, c (k ∘ Equiv.swap s t) = c k) : - D (polynomial c l) = - (Finset.univ.filter (fun s => l s = src)).card • - polynomial c (Function.update l t dst) := by - classical - rw [derivation_polynomial c l src dst D hD, ← Finset.sum_const] - apply Finset.sum_congr rfl - intro s hs - have hs' := (Finset.mem_filter.mp hs).2 - exact polynomial_update_eq c l s t dst (hs'.trans ht.symm) (hc s hs') - -end Problem346.SlotPolynomial - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346.SlotPolynomial + +variable {R A S I B : Type*} [CommRing R] [CommRing A] [Algebra R A] [DecidableEq S] + +/-- Leibniz rule for a finite product, expressed by replacing one factor. -/ +theorem derivation_prod (D : Derivation R A A) (s : Finset S) (f : S → A) : + D (∏ i ∈ s, f i) = + ∑ i ∈ s, ∏ j ∈ s, Function.update f i (D (f i)) j := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + rw [Finset.prod_insert ha, D.leibniz, ih, Finset.sum_insert ha] + simp only [Finset.prod_insert ha, Function.update_self, smul_eq_mul] + have h₁ : (∏ j ∈ s, Function.update f a (D (f a)) j) = ∏ j ∈ s, f j := + Finset.prod_update_of_notMem ha _ _ + rw [h₁, Finset.mul_sum] + have h₂ : (∑ i ∈ s, Function.update f i (D (f i)) a * + ∏ j ∈ s, Function.update f i (D (f i)) j) = + ∑ i ∈ s, f a * ∏ j ∈ s, Function.update f i (D (f i)) j := by + apply Finset.sum_congr rfl + intro i hi + have hai : a ≠ i := by + intro h + subst i + exact ha hi + rw [Function.update_of_ne hai] + rw [h₂] + ring + +variable [Fintype S] [Fintype I] + +/-- Coordinate polynomial of a coefficient array and an assignment of slots to blocks. -/ +def polynomial (c : (S → I) → R) (l : S → B) : MvPolynomial (B × I) R := + ∑ k : S → I, MvPolynomial.C (c k) * ∏ s : S, MvPolynomial.X (l s, k s) + +/-- A directional block derivation replaces each occurrence of the source block in turn. -/ +theorem derivation_polynomial [DecidableEq B] + (c : (S → I) → R) (l : S → B) (src dst : B) + (D : Derivation R (MvPolynomial (B × I) R) (MvPolynomial (B × I) R)) + (hD : ∀ b i, D (MvPolynomial.X (b, i)) = + if b = src then MvPolynomial.X (dst, i) else 0) : + D (polynomial c l) = + ∑ s ∈ Finset.univ.filter (fun s => l s = src), + polynomial c (Function.update l s dst) := by + classical + unfold polynomial + rw [map_sum] + simp_rw [D.leibniz, MvPolynomial.derivation_C, smul_zero, add_zero, + smul_eq_mul, derivation_prod] + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro s hs + by_cases h : l s = src + · simp only [h, ite_true] + apply Finset.sum_congr rfl + intro k hk + congr 1 + apply Finset.prod_congr rfl + intro j hj + by_cases hjs : j = s + · subst j + simp [hD] + · simp [Function.update_of_ne hjs] + · simp only [h, ite_false] + apply Finset.sum_eq_zero + intro k hk + have hz : (∏ j : S, Function.update (fun s => MvPolynomial.X (l s, k s)) + s (D (MvPolynomial.X (l s, k s))) j) = 0 := by + apply Finset.prod_eq_zero (Finset.mem_univ s) + simp [hD, h] + rw [hz, mul_zero] + +/-- Reindexing slots moves the same permutation onto the coefficient array. -/ +theorem polynomial_reindex (c : (S → I) → R) (l : S → B) (e : Equiv.Perm S) : + polynomial c (l ∘ e) = polynomial (fun k => c (k ∘ e)) l := by + classical + unfold polynomial + apply Fintype.sum_equiv (Equiv.arrowCongr e (Equiv.refl I)) + intro k + congr 1 + · congr 1 + change c k = c _ + congr 1 + funext s + simp + · apply Fintype.prod_equiv e + intro s + simp + +/-- Symmetry of coefficients induces invariance under the same permutation of slot labels. -/ +theorem polynomial_reindex_of_invariant (c : (S → I) → R) (l : S → B) + (e : Equiv.Perm S) (hc : ∀ k, c (k ∘ e) = c k) : + polynomial c (l ∘ e) = polynomial c l := by + rw [polynomial_reindex] + congr 1 + funext k + exact hc k + +/-- Swapping two equal-labelled slots shows that replacing either label gives the same polynomial. -/ +theorem polynomial_update_eq (c : (S → I) → R) (l : S → B) (s t : S) (dst : B) + (hl : l s = l t) + (hc : ∀ k, c (k ∘ Equiv.swap s t) = c k) : + polynomial c (Function.update l s dst) = polynomial c (Function.update l t dst) := by + classical + have hlabels : Function.update l s dst = + Function.update l t dst ∘ Equiv.swap s t := by + funext j + by_cases hjs : j = s + · subst j + simp + by_cases hjt : j = t + · subst j + simp [hjs, Ne.symm hjs, hl] + · simp [Equiv.swap_apply_of_ne_of_ne hjs hjt, hjs, hjt] + rw [hlabels] + exact polynomial_reindex_of_invariant c _ _ hc + +/-- If all source-labelled slots are interchangeable, the derivative is a single replacement +multiplied by their number. -/ +theorem derivation_polynomial_eq_card_smul [DecidableEq B] + (c : (S → I) → R) (l : S → B) (src dst : B) (t : S) (ht : l t = src) + (D : Derivation R (MvPolynomial (B × I) R) (MvPolynomial (B × I) R)) + (hD : ∀ b i, D (MvPolynomial.X (b, i)) = + if b = src then MvPolynomial.X (dst, i) else 0) + (hc : ∀ s, l s = src → ∀ k, c (k ∘ Equiv.swap s t) = c k) : + D (polynomial c l) = + (Finset.univ.filter (fun s => l s = src)).card • + polynomial c (Function.update l t dst) := by + classical + rw [derivation_polynomial c l src dst D hD, ← Finset.sum_const] + apply Finset.sum_congr rfl + intro s hs + have hs' := (Finset.mem_filter.mp hs).2 + exact polynomial_update_eq c l s t dst (hs'.trans ht.symm) (hc s hs') + +end Problem346.SlotPolynomial + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Spanning.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Spanning.lean index 6f042a72082ec8ddb081a29d8898fb597b223c31..5fe81e917178777099b97815b353cb60d8b2e141 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Spanning.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Spanning.lean @@ -1,113 +1,113 @@ -import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u v -namespace Problem346 - -/-- Monomials span the symmetric power, in its subtype realization. -/ -theorem span_symMonomial (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - Submodule.span ℂ (Set.range (symMonomial n V)) = ⊤ := by - apply (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule n V) - (fun x => Submodule.subset_span (Set.mem_range_self x))).2 - rfl - -/-- Maps out of a symmetric power are determined by monomials. -/ -theorem symPow_linearMap_ext (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - {W : Type v} [AddCommGroup W] [Module ℂ W] - (f g : SymPow n V →ₗ[ℂ] W) - (h : ∀ x : Fin n → V, f (symMonomial n V x) = g (symMonomial n V x)) : f = g := by - apply (Submodule.linearMap_eq_iff_of_span_eq_top f g (span_symMonomial n V)).2 - rintro ⟨_, x, rfl⟩ - exact h x - -/-- A multilinear map vanishing on tuples from a spanning set is zero. -/ -theorem multilinear_eq_zero_of_span - {M : Type u} [AddCommGroup M] [Module ℂ M] - {N : Type v} [AddCommGroup N] [Module ℂ N] - {s : Set M} (hs : Submodule.span ℂ s = ⊤) (n : ℕ) : - ∀ F : MultilinearMap ℂ (fun _ : Fin n => M) N, - (∀ x, (∀ i, x i ∈ s) → F x = 0) → F = 0 := by - induction n with - | zero => - intro F hF - ext x - exact hF x (fun i => Fin.elim0 i) - | succ n ih => - intro F hF - have hc : F.curryLeft = 0 := by - apply (Submodule.linearMap_eq_zero_iff_of_span_eq_top F.curryLeft hs).2 - intro x - apply ih - intro y hy - apply hF - exact Fin.cases x.property hy - ext x - have h := congrArg (fun f : M →ₗ[ℂ] MultilinearMap ℂ (fun _ : Fin n => M) N => - f (x 0) (Fin.tail x)) hc - simpa using h - -/-- Multilinear maps agree if they agree on tuples from a spanning set. -/ -theorem multilinear_ext_of_span - {M : Type u} [AddCommGroup M] [Module ℂ M] - {N : Type v} [AddCommGroup N] [Module ℂ N] - {s : Set M} (hs : Submodule.span ℂ s = ⊤) (n : ℕ) - (F G : MultilinearMap ℂ (fun _ : Fin n => M) N) - (h : ∀ x, (∀ i, x i ∈ s) → F x = G x) : F = G := by - apply sub_eq_zero.mp - apply multilinear_eq_zero_of_span hs n - intro x hx - simp only [sub_apply, h x hx, sub_self] - -/-- Linear maps out of a plethysm are determined by double monomials. -/ -theorem plethysm_linearMap_ext (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - {W : Type v} [AddCommGroup W] [Module ℂ W] - (f g : SymPow b (SymPow a V) →ₗ[ℂ] W) - (h : ∀ x : Fin b → Fin a → V, - f (symMonomial b (SymPow a V) (fun j => symMonomial a V (x j))) = - g (symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) : f = g := by - classical - apply symPow_linearMap_ext b (SymPow a V) - have hm : f.compMultilinearMap (symMonomialMultilinear b (SymPow a V)) = - g.compMultilinearMap (symMonomialMultilinear b (SymPow a V)) := by - apply multilinear_ext_of_span (span_symMonomial a V) b - intro x hx - choose v hv using hx - have hx' : x = fun j => symMonomial a V (v j) := funext (fun j => (hv j).symm) - subst x - exact h v - intro x - exact congrArg (fun F => F x) hm - -/-- Double monomials span the plethysm. -/ -theorem span_plethysmMonomial (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] : - Submodule.span ℂ (Set.range (fun x : Fin b → Fin a → V => - symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) = ⊤ := by - let p := Submodule.span ℂ (Set.range (fun x : Fin b → Fin a → V => - symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) - change p = ⊤ - have hp : p.mkQ = 0 := by - apply plethysm_linearMap_ext a b V - intro x - apply (Submodule.Quotient.mk_eq_zero p).mpr - exact Submodule.subset_span (Set.mem_range_self x) - rw [← Submodule.ker_mkQ p, hp, LinearMap.ker_zero] - -/-- The defining formula determines a Foulkes map uniquely. -/ -theorem IsFoulkesMap.unique (a b : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - {f g : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} - (hf : IsFoulkesMap a b V f) (hg : IsFoulkesMap a b V g) : f = g := by - apply plethysm_linearMap_ext a b V - intro x - exact (hf x).trans (hg x).symm - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.MonomialMultilinear + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u v +namespace Problem346 + +/-- Monomials span the symmetric power, in its subtype realization. -/ +theorem span_symMonomial (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + Submodule.span ℂ (Set.range (symMonomial n V)) = ⊤ := by + apply (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule n V) + (fun x => Submodule.subset_span (Set.mem_range_self x))).2 + rfl + +/-- Maps out of a symmetric power are determined by monomials. -/ +theorem symPow_linearMap_ext (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + {W : Type v} [AddCommGroup W] [Module ℂ W] + (f g : SymPow n V →ₗ[ℂ] W) + (h : ∀ x : Fin n → V, f (symMonomial n V x) = g (symMonomial n V x)) : f = g := by + apply (Submodule.linearMap_eq_iff_of_span_eq_top f g (span_symMonomial n V)).2 + rintro ⟨_, x, rfl⟩ + exact h x + +/-- A multilinear map vanishing on tuples from a spanning set is zero. -/ +theorem multilinear_eq_zero_of_span + {M : Type u} [AddCommGroup M] [Module ℂ M] + {N : Type v} [AddCommGroup N] [Module ℂ N] + {s : Set M} (hs : Submodule.span ℂ s = ⊤) (n : ℕ) : + ∀ F : MultilinearMap ℂ (fun _ : Fin n => M) N, + (∀ x, (∀ i, x i ∈ s) → F x = 0) → F = 0 := by + induction n with + | zero => + intro F hF + ext x + exact hF x (fun i => Fin.elim0 i) + | succ n ih => + intro F hF + have hc : F.curryLeft = 0 := by + apply (Submodule.linearMap_eq_zero_iff_of_span_eq_top F.curryLeft hs).2 + intro x + apply ih + intro y hy + apply hF + exact Fin.cases x.property hy + ext x + have h := congrArg (fun f : M →ₗ[ℂ] MultilinearMap ℂ (fun _ : Fin n => M) N => + f (x 0) (Fin.tail x)) hc + simpa using h + +/-- Multilinear maps agree if they agree on tuples from a spanning set. -/ +theorem multilinear_ext_of_span + {M : Type u} [AddCommGroup M] [Module ℂ M] + {N : Type v} [AddCommGroup N] [Module ℂ N] + {s : Set M} (hs : Submodule.span ℂ s = ⊤) (n : ℕ) + (F G : MultilinearMap ℂ (fun _ : Fin n => M) N) + (h : ∀ x, (∀ i, x i ∈ s) → F x = G x) : F = G := by + apply sub_eq_zero.mp + apply multilinear_eq_zero_of_span hs n + intro x hx + simp only [sub_apply, h x hx, sub_self] + +/-- Linear maps out of a plethysm are determined by double monomials. -/ +theorem plethysm_linearMap_ext (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + {W : Type v} [AddCommGroup W] [Module ℂ W] + (f g : SymPow b (SymPow a V) →ₗ[ℂ] W) + (h : ∀ x : Fin b → Fin a → V, + f (symMonomial b (SymPow a V) (fun j => symMonomial a V (x j))) = + g (symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) : f = g := by + classical + apply symPow_linearMap_ext b (SymPow a V) + have hm : f.compMultilinearMap (symMonomialMultilinear b (SymPow a V)) = + g.compMultilinearMap (symMonomialMultilinear b (SymPow a V)) := by + apply multilinear_ext_of_span (span_symMonomial a V) b + intro x hx + choose v hv using hx + have hx' : x = fun j => symMonomial a V (v j) := funext (fun j => (hv j).symm) + subst x + exact h v + intro x + exact congrArg (fun F => F x) hm + +/-- Double monomials span the plethysm. -/ +theorem span_plethysmMonomial (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] : + Submodule.span ℂ (Set.range (fun x : Fin b → Fin a → V => + symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) = ⊤ := by + let p := Submodule.span ℂ (Set.range (fun x : Fin b → Fin a → V => + symMonomial b (SymPow a V) (fun j => symMonomial a V (x j)))) + change p = ⊤ + have hp : p.mkQ = 0 := by + apply plethysm_linearMap_ext a b V + intro x + apply (Submodule.Quotient.mk_eq_zero p).mpr + exact Submodule.subset_span (Set.mem_range_self x) + rw [← Submodule.ker_mkQ p, hp, LinearMap.ker_zero] + +/-- The defining formula determines a Foulkes map uniquely. -/ +theorem IsFoulkesMap.unique (a b : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + {f g : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V)} + (hf : IsFoulkesMap a b V f) (hg : IsFoulkesMap a b V g) : f = g := by + apply plethysm_linearMap_ext a b V + intro x + exact (hf x).trans (hg x).symm + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SpanningAgreement.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SpanningAgreement.lean index c5ae50a0f4dbc411ac34edff71972a5ab4643d4b..4422f0fa5a44005389f1ac8a39b5a19c9a4b545e 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SpanningAgreement.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SpanningAgreement.lean @@ -1,106 +1,106 @@ -import Mathlib - -namespace OAI - -noncomputable section -open scoped BigOperators -open Module - -namespace Problem346 - -/-- Equality on chosen basis generators extends to all generator tuples when each -coordinate of the generator function has a linear extension. -/ -theorem multilinear_agreement_of_basis - {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] - {M X K : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] - [AddCommGroup W] [Module R W] - (s : ∀ i, X i → M i) (B : ∀ i, Basis (K i) R (M i)) - (t : ∀ i, K i → X i) (ht : ∀ i k, s i (t i k) = B i k) - (F : (∀ i, X i) → W) (G : MultilinearMap R M W) - (hlinear : ∀ x : ∀ i, X i, ∀ i, - ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) - (hbase : ∀ k : ∀ i, K i, F (fun i => t i (k i)) = G (fun i => B i (k i))) : - ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by - classical - have aux : ∀ (S : Finset I) (x : ∀ i, X i), - (∀ i, i ∉ S → ∃ k, x i = t i k) → F x = G (fun i => s i (x i)) := by - intro S - induction S using Finset.induction_on with - | empty => - intro x hx - choose k hk using fun i => hx i (Finset.notMem_empty i) - have he : x = fun i => t i (k i) := funext hk - rw [he, hbase] - simp only [ht] - | @insert i S hi ih => - intro x hx - obtain ⟨L, hL⟩ := hlinear x i - have heq : L = G.toLinearMap (fun j => s j (x j)) i := by - apply (B i).ext - intro k - rw [← ht i k, hL] - rw [ih (Function.update x i (t i k))] - · simp only [MultilinearMap.toLinearMap_apply] - congr 1 - funext j - by_cases hji : j = i - · subst j - simp [ht] - · simp [Function.update_of_ne hji] - · intro j hj - by_cases hji : j = i - · subst j - exact ⟨k, by simp⟩ - · obtain ⟨l, hl⟩ := hx j (by simp [hji, hj]) - exact ⟨l, by simpa [Function.update_of_ne hji] using hl⟩ - have h := congrArg (fun L : M i →ₗ[R] W => L (s i (x i))) heq - simpa only [hL, Function.update_eq_self, MultilinearMap.toLinearMap_apply] using h - intro x - exact aux Finset.univ x (by simp) - -/-- Construct the extension when a basis consists of specified generators. -/ -theorem exists_multilinear_extension_of_basis - {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] - {M X K : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] - [AddCommGroup W] [Module R W] - (s : ∀ i, X i → M i) (B : ∀ i, Basis (K i) R (M i)) - (t : ∀ i, K i → X i) (ht : ∀ i k, s i (t i k) = B i k) - (F : (∀ i, X i) → W) - (hlinear : ∀ x : ∀ i, X i, ∀ i, - ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) : - ∃ G : MultilinearMap R M W, ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by - let L : (PiTensorProduct R M) →ₗ[R] W := - (Basis.piTensorProduct B).constr R (fun k => F (fun i => t i (k i))) - let G : MultilinearMap R M W := L.compMultilinearMap (PiTensorProduct.tprod R) - refine ⟨G, multilinear_agreement_of_basis s B t ht F G hlinear ?_⟩ - intro k - change F (fun i => t i (k i)) = L (PiTensorProduct.tprod R (fun i => B i (k i))) - rw [← Basis.piTensorProduct_apply] - dsimp only [L] - rw [Basis.constr_basis] - -/-- Separate linear extendibility on spanning generators gives a multilinear extension. -/ -theorem exists_multilinear_extension_of_spanning - {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] - {M X : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] - [AddCommGroup W] [Module R W] - (s : ∀ i, X i → M i) - (hspan : ∀ i, Submodule.span R (Set.range (s i)) = ⊤) - (F : (∀ i, X i) → W) - (hlinear : ∀ x : ∀ i, X i, ∀ i, - ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) : - ∃ G : MultilinearMap R M W, ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by - classical - have hs (i : I) : ⊤ ≤ Submodule.span R (Set.range (s i)) := by rw [hspan i] - let B := fun i => Basis.ofSpan (hs i) - have hpre : ∀ i k, ∃ x, s i x = B i k := by - intro i k - exact Basis.ofSpan_subset (hs i) (Set.mem_range_self k) - choose t ht using hpre - exact exists_multilinear_extension_of_basis s B t ht F hlinear - -end Problem346 - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators +open Module + +namespace Problem346 + +/-- Equality on chosen basis generators extends to all generator tuples when each +coordinate of the generator function has a linear extension. -/ +theorem multilinear_agreement_of_basis + {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] + {M X K : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] + [AddCommGroup W] [Module R W] + (s : ∀ i, X i → M i) (B : ∀ i, Basis (K i) R (M i)) + (t : ∀ i, K i → X i) (ht : ∀ i k, s i (t i k) = B i k) + (F : (∀ i, X i) → W) (G : MultilinearMap R M W) + (hlinear : ∀ x : ∀ i, X i, ∀ i, + ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) + (hbase : ∀ k : ∀ i, K i, F (fun i => t i (k i)) = G (fun i => B i (k i))) : + ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by + classical + have aux : ∀ (S : Finset I) (x : ∀ i, X i), + (∀ i, i ∉ S → ∃ k, x i = t i k) → F x = G (fun i => s i (x i)) := by + intro S + induction S using Finset.induction_on with + | empty => + intro x hx + choose k hk using fun i => hx i (Finset.notMem_empty i) + have he : x = fun i => t i (k i) := funext hk + rw [he, hbase] + simp only [ht] + | @insert i S hi ih => + intro x hx + obtain ⟨L, hL⟩ := hlinear x i + have heq : L = G.toLinearMap (fun j => s j (x j)) i := by + apply (B i).ext + intro k + rw [← ht i k, hL] + rw [ih (Function.update x i (t i k))] + · simp only [MultilinearMap.toLinearMap_apply] + congr 1 + funext j + by_cases hji : j = i + · subst j + simp [ht] + · simp [Function.update_of_ne hji] + · intro j hj + by_cases hji : j = i + · subst j + exact ⟨k, by simp⟩ + · obtain ⟨l, hl⟩ := hx j (by simp [hji, hj]) + exact ⟨l, by simpa [Function.update_of_ne hji] using hl⟩ + have h := congrArg (fun L : M i →ₗ[R] W => L (s i (x i))) heq + simpa only [hL, Function.update_eq_self, MultilinearMap.toLinearMap_apply] using h + intro x + exact aux Finset.univ x (by simp) + +/-- Construct the extension when a basis consists of specified generators. -/ +theorem exists_multilinear_extension_of_basis + {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] + {M X K : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] + [AddCommGroup W] [Module R W] + (s : ∀ i, X i → M i) (B : ∀ i, Basis (K i) R (M i)) + (t : ∀ i, K i → X i) (ht : ∀ i k, s i (t i k) = B i k) + (F : (∀ i, X i) → W) + (hlinear : ∀ x : ∀ i, X i, ∀ i, + ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) : + ∃ G : MultilinearMap R M W, ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by + let L : (PiTensorProduct R M) →ₗ[R] W := + (Basis.piTensorProduct B).constr R (fun k => F (fun i => t i (k i))) + let G : MultilinearMap R M W := L.compMultilinearMap (PiTensorProduct.tprod R) + refine ⟨G, multilinear_agreement_of_basis s B t ht F G hlinear ?_⟩ + intro k + change F (fun i => t i (k i)) = L (PiTensorProduct.tprod R (fun i => B i (k i))) + rw [← Basis.piTensorProduct_apply] + dsimp only [L] + rw [Basis.constr_basis] + +/-- Separate linear extendibility on spanning generators gives a multilinear extension. -/ +theorem exists_multilinear_extension_of_spanning + {R I W : Type*} [Field R] [Fintype I] [DecidableEq I] + {M X : I → Type*} [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] + [AddCommGroup W] [Module R W] + (s : ∀ i, X i → M i) + (hspan : ∀ i, Submodule.span R (Set.range (s i)) = ⊤) + (F : (∀ i, X i) → W) + (hlinear : ∀ x : ∀ i, X i, ∀ i, + ∃ L : M i →ₗ[R] W, ∀ y, L (s i y) = F (Function.update x i y)) : + ∃ G : MultilinearMap R M W, ∀ x : ∀ i, X i, F x = G (fun i => s i (x i)) := by + classical + have hs (i : I) : ⊤ ≤ Submodule.span R (Set.range (s i)) := by rw [hspan i] + let B := fun i => Basis.ofSpan (hs i) + have hpre : ∀ i k, ∃ x, s i x = B i k := by + intro i k + exact Basis.ofSpan_subset (hs i) (Set.mem_range_self k) + choose t ht using hpre + exact exists_multilinear_extension_of_basis s B t ht F hlinear + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Stabilization.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Stabilization.lean index 108d8167d0698a771d64969578b8a5b81e14afce..6846928c65adf7c450d4b50d57d75625c1bb1d2d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Stabilization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Stabilization.lean @@ -1,51 +1,51 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model -import OAI.RepresentationTheory.FoulkesHowe.LinearCase -import OAI.RepresentationTheory.FoulkesHowe.PairingConstruction -import OAI.RepresentationTheory.FoulkesHowe.Surjectivity -import OAI.RepresentationTheory.FoulkesHowe.ProductVanishing - -namespace OAI - -noncomputable section - -universe u - -namespace Problem346 - -theorem canonical_foulkes_howe_surjective : - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 2 ≤ a → a * (a - 1) ≤ b → ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), IsFoulkesMap a b V μ ∧ Function.Surjective μ ∧ ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), IsFoulkesMap a b V ν → ν = μ := by - intro V _ _ _ a b ha hab - apply canonical_surjective_unique_of_vanishing a b V - have hb : 1 ≤ b := by - have hpred : 1 ≤ a - 1 := by omega - have hprod := Nat.mul_le_mul ha hpred - omega - exact vanishing_on_products_aux V a b (by omega) hb hab - -theorem canonical_foulkes_howe_a_one : - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (b : ℕ), ∃ μ : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), IsFoulkesMap 1 b V μ ∧ Function.Bijective μ ∧ ∀ ν : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), IsFoulkesMap 1 b V ν → ν = μ := by - intro V _ _ _ b - exact canonical_foulkes_howe_a_one_aux V b - -theorem vanishing_on_products : - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 1 ≤ a → 1 ≤ b → a * (a - 1) ≤ b → ∀ T : SymmetricMultilinearForm a b V, IsSymmetricMultilinearForm a b V T → (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0 := by - intro V _ _ _ a b ha hb hab T hT hdiag - exact vanishing_on_products_aux V a b ha hb hab T hT hdiag - -theorem foulkes_comparison_embedding : - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 2 ≤ a → a * (a - 1) ≤ b → ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), IsGLEquivariantEmbedding a b V ι := by - intro V _ _ _ a b ha hab - obtain ⟨μ, hμ, hsurj, _⟩ := - canonical_foulkes_howe_surjective (Module.Dual ℂ V) a b ha hab - exact PairingConstruction.comparison_of_surjection V a b ⟨μ, hμ, hsurj⟩ - -theorem sixth_symmetric_power_comparison : - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (b : ℕ), 30 ≤ b → ∃ ι : SymPow 6 (SymPow b V) →ₗ[ℂ] SymPow b (SymPow 6 V), IsGLEquivariantEmbedding 6 b V ι := by - intro V _ _ _ b hb - exact foulkes_comparison_embedding V 6 b (by norm_num) (by simpa using hb) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model +import OAI.RepresentationTheory.FoulkesHowe.LinearCase +import OAI.RepresentationTheory.FoulkesHowe.PairingConstruction +import OAI.RepresentationTheory.FoulkesHowe.Surjectivity +import OAI.RepresentationTheory.FoulkesHowe.ProductVanishing + +namespace OAI + +noncomputable section + +universe u + +namespace Problem346 + +theorem canonical_foulkes_howe_surjective : + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 2 ≤ a → a * (a - 1) ≤ b → ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), IsFoulkesMap a b V μ ∧ Function.Surjective μ ∧ ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), IsFoulkesMap a b V ν → ν = μ := by + intro V _ _ _ a b ha hab + apply canonical_surjective_unique_of_vanishing a b V + have hb : 1 ≤ b := by + have hpred : 1 ≤ a - 1 := by omega + have hprod := Nat.mul_le_mul ha hpred + omega + exact vanishing_on_products_aux V a b (by omega) hb hab + +theorem canonical_foulkes_howe_a_one : + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (b : ℕ), ∃ μ : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), IsFoulkesMap 1 b V μ ∧ Function.Bijective μ ∧ ∀ ν : SymPow b (SymPow 1 V) →ₗ[ℂ] SymPow 1 (SymPow b V), IsFoulkesMap 1 b V ν → ν = μ := by + intro V _ _ _ b + exact canonical_foulkes_howe_a_one_aux V b + +theorem vanishing_on_products : + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 1 ≤ a → 1 ≤ b → a * (a - 1) ≤ b → ∀ T : SymmetricMultilinearForm a b V, IsSymmetricMultilinearForm a b V T → (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0 := by + intro V _ _ _ a b ha hb hab T hT hdiag + exact vanishing_on_products_aux V a b ha hb hab T hT hdiag + +theorem foulkes_comparison_embedding : + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (a b : ℕ), 2 ≤ a → a * (a - 1) ≤ b → ∃ ι : SymPow a (SymPow b V) →ₗ[ℂ] SymPow b (SymPow a V), IsGLEquivariantEmbedding a b V ι := by + intro V _ _ _ a b ha hab + obtain ⟨μ, hμ, hsurj, _⟩ := + canonical_foulkes_howe_surjective (Module.Dual ℂ V) a b ha hab + exact PairingConstruction.comparison_of_surjection V a b ⟨μ, hμ, hsurj⟩ + +theorem sixth_symmetric_power_comparison : + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] (b : ℕ), 30 ≤ b → ∃ ι : SymPow 6 (SymPow b V) →ₗ[ℂ] SymPow b (SymPow 6 V), IsGLEquivariantEmbedding 6 b V ι := by + intro V _ _ _ b hb + exact foulkes_comparison_embedding V 6 b (by norm_num) (by simpa using hb) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/StabilizationBounds.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/StabilizationBounds.lean index cbde88b8b963563fe94b62c41b241f89d1b61148..e349a0fcc5cbaf6fc3c2d2adcaade9254418add8 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/StabilizationBounds.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/StabilizationBounds.lean @@ -1,70 +1,70 @@ -import Mathlib - -namespace OAI - -namespace Problem346 - -open scoped BigOperators - -/-- The parameter reduction in the induction on the outer symmetric degree. -/ -theorem stabilization_reduction {a b : ℕ} (ha : 2 ≤ a) - (hab : a * (a - 1) ≤ b) : - let r := a - 1 - let m := b - r - 1 ≤ r ∧ r * (r + 1) ≤ b ∧ r * r ≤ m ∧ - 1 ≤ m ∧ r * (r - 1) ≤ m := by - dsimp - have ha' : a - 1 + 1 = a := Nat.sub_add_cancel (by omega) - have hr : 1 ≤ a - 1 := by omega - have hb : (a - 1) * ((a - 1) + 1) ≤ b := by - rw [ha', Nat.mul_comm] - exact hab - have hm : (a - 1) * (a - 1) ≤ b - (a - 1) := by - apply Nat.le_sub_of_add_le - nlinarith - have hmpos : 1 ≤ b - (a - 1) := by nlinarith - refine ⟨hr, hb, hm, hmpos, ?_⟩ - exact (Nat.mul_le_mul_left (a - 1) (Nat.sub_le (a - 1) 1)).trans hm - -/-- The first sequence of shifts has positive source-minus-destination weight. -/ -theorem first_shift_weight {b r i : ℕ} (hir : i ≤ b - r) - (hi : 1 ≤ i) : r < b - i + 1 := by - omega - -/-- The shared destination variable remains at least two degrees below the source. -/ -theorem second_shift_weight_gap {b r i j : ℕ} - (hr : 1 ≤ r) (hb : r * (r + 1) ≤ b) - (hi : 1 ≤ i) (hir : i ≤ r) (hj : j < r) : - (i - 1) * r + j + 2 ≤ b - j := by - have hi' : i - 1 ≤ r - 1 := by omega - have hmul : (i - 1) * r ≤ (r - 1) * r := Nat.mul_le_mul_right r hi' - have hr' : r - 1 + 1 = r := Nat.sub_add_cancel hr - have hj' : j ≤ r - 1 := by omega - have hbound : (i - 1) * r + j + 2 + j ≤ b := by nlinarith - exact Nat.le_sub_of_add_le hbound - -/-- The second sequence of shifts satisfies the strict injectivity inequality. -/ -theorem second_shift_weight {b r i j : ℕ} - (hr : 1 ≤ r) (hb : r * (r + 1) ≤ b) - (hi : 1 ≤ i) (hir : i ≤ r) (hj : j < r) : - (i - 1) * r + j < b - j := by - have h := second_shift_weight_gap hr hb hi hir hj - omega - -/-- Arbitrary progress vectors, rather than only lexicographic schedules, satisfy the -positive-weight inequality at every unfinished slot. -/ -theorem grid_shift_weight {b r : ℕ} (hb : r * (r + 1) ≤ b) - (counts : Fin r → ℕ) (hcounts : ∀ j, counts j ≤ r) - (i : Fin r) (hi : counts i < r) : - (∑ j, counts j) < b - counts i := by - have hsum : (∑ j, counts j) ≤ r * r := by - calc - (∑ j, counts j) ≤ ∑ _j : Fin r, r := - Finset.sum_le_sum (fun j _ => hcounts j) - _ = r * r := by simp - have hbound : (∑ j, counts j) + counts i < b := by nlinarith - omega - -end Problem346 - -end OAI +import Mathlib + +namespace OAI + +namespace Problem346 + +open scoped BigOperators + +/-- The parameter reduction in the induction on the outer symmetric degree. -/ +theorem stabilization_reduction {a b : ℕ} (ha : 2 ≤ a) + (hab : a * (a - 1) ≤ b) : + let r := a - 1 + let m := b - r + 1 ≤ r ∧ r * (r + 1) ≤ b ∧ r * r ≤ m ∧ + 1 ≤ m ∧ r * (r - 1) ≤ m := by + dsimp + have ha' : a - 1 + 1 = a := Nat.sub_add_cancel (by omega) + have hr : 1 ≤ a - 1 := by omega + have hb : (a - 1) * ((a - 1) + 1) ≤ b := by + rw [ha', Nat.mul_comm] + exact hab + have hm : (a - 1) * (a - 1) ≤ b - (a - 1) := by + apply Nat.le_sub_of_add_le + nlinarith + have hmpos : 1 ≤ b - (a - 1) := by nlinarith + refine ⟨hr, hb, hm, hmpos, ?_⟩ + exact (Nat.mul_le_mul_left (a - 1) (Nat.sub_le (a - 1) 1)).trans hm + +/-- The first sequence of shifts has positive source-minus-destination weight. -/ +theorem first_shift_weight {b r i : ℕ} (hir : i ≤ b - r) + (hi : 1 ≤ i) : r < b - i + 1 := by + omega + +/-- The shared destination variable remains at least two degrees below the source. -/ +theorem second_shift_weight_gap {b r i j : ℕ} + (hr : 1 ≤ r) (hb : r * (r + 1) ≤ b) + (hi : 1 ≤ i) (hir : i ≤ r) (hj : j < r) : + (i - 1) * r + j + 2 ≤ b - j := by + have hi' : i - 1 ≤ r - 1 := by omega + have hmul : (i - 1) * r ≤ (r - 1) * r := Nat.mul_le_mul_right r hi' + have hr' : r - 1 + 1 = r := Nat.sub_add_cancel hr + have hj' : j ≤ r - 1 := by omega + have hbound : (i - 1) * r + j + 2 + j ≤ b := by nlinarith + exact Nat.le_sub_of_add_le hbound + +/-- The second sequence of shifts satisfies the strict injectivity inequality. -/ +theorem second_shift_weight {b r i j : ℕ} + (hr : 1 ≤ r) (hb : r * (r + 1) ≤ b) + (hi : 1 ≤ i) (hir : i ≤ r) (hj : j < r) : + (i - 1) * r + j < b - j := by + have h := second_shift_weight_gap hr hb hi hir hj + omega + +/-- Arbitrary progress vectors, rather than only lexicographic schedules, satisfy the +positive-weight inequality at every unfinished slot. -/ +theorem grid_shift_weight {b r : ℕ} (hb : r * (r + 1) ≤ b) + (counts : Fin r → ℕ) (hcounts : ∀ j, counts j ≤ r) + (i : Fin r) (hi : counts i < r) : + (∑ j, counts j) < b - counts i := by + have hsum : (∑ j, counts j) ≤ r * r := by + calc + (∑ j, counts j) ≤ ∑ _j : Fin r, r := + Finset.sum_le_sum (fun j _ => hcounts j) + _ = r * r := by simp + have hbound : (∑ j, counts j) + counts i < b := by nlinarith + omega + +end Problem346 + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SumShift.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SumShift.lean index ac6bf3dd60dad9c77897710ddb5d66453864ad34..f4d19ab441be39ec1c40914e6e821d03aaeb96bb 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SumShift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SumShift.lean @@ -1,105 +1,105 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Problem346.PolynomialShift - -open MvPolynomial - -universe u v w - -abbrev Vars (ι : Type u) (σ : Type v) := ι ⊕ (ι ⊕ σ) -abbrev Poly (R : Type w) (ι : Type u) (σ : Type v) [CommRing R] := - MvPolynomial (Vars ι σ) R - -variable (R : Type w) (ι : Type u) (σ : Type v) [CommRing R] - -/-- Shift one unit of degree from the first coordinate block to the second. -/ -def down : Derivation R (Poly R ι σ) (Poly R ι σ) := - mkDerivation R (Sum.elim (fun i => X (Sum.inr (Sum.inl i))) (fun _ => 0)) - -/-- The opposite shift. -/ -def up : Derivation R (Poly R ι σ) (Poly R ι σ) := - mkDerivation R (Sum.elim (fun _ => 0) - (Sum.elim (fun i => X (Sum.inl i)) (fun _ => 0))) - -/-- Euler operator of the first coordinate block. -/ -def sourceEuler : Derivation R (Poly R ι σ) (Poly R ι σ) := - mkDerivation R (Sum.elim (fun i => X (Sum.inl i)) (fun _ => 0)) - -/-- Euler operator of the second coordinate block. -/ -def targetEuler : Derivation R (Poly R ι σ) (Poly R ι σ) := - mkDerivation R (Sum.elim (fun _ => 0) - (Sum.elim (fun i => X (Sum.inr (Sum.inl i))) (fun _ => 0))) - -/-- Source degree minus destination degree. -/ -def weight : Derivation R (Poly R ι σ) (Poly R ι σ) := - sourceEuler R ι σ - targetEuler R ι σ - -@[simp] theorem down_source (i : ι) : - down R ι σ (X (Sum.inl i)) = X (Sum.inr (Sum.inl i)) := by - simp [down] - -@[simp] theorem down_target (i : ι) : - down R ι σ (X (Sum.inr (Sum.inl i))) = 0 := by - simp [down] - -@[simp] theorem down_spectator (i : σ) : - down R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by - simp [down] - -@[simp] theorem up_source (i : ι) : - up R ι σ (X (Sum.inl i)) = 0 := by - simp [up] - -@[simp] theorem up_target (i : ι) : - up R ι σ (X (Sum.inr (Sum.inl i))) = X (Sum.inl i) := by - simp [up] - -@[simp] theorem up_spectator (i : σ) : - up R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by - simp [up] - -@[simp] theorem weight_source (i : ι) : - weight R ι σ (X (Sum.inl i)) = X (Sum.inl i) := by - simp [weight, sourceEuler, targetEuler] - -@[simp] theorem weight_target (i : ι) : - weight R ι σ (X (Sum.inr (Sum.inl i))) = -X (Sum.inr (Sum.inl i)) := by - simp [weight, sourceEuler, targetEuler] - -@[simp] theorem weight_spectator (i : σ) : - weight R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by - simp [weight, sourceEuler, targetEuler] - -/-- The fundamental commutator, with arbitrary spectator variables. -/ -theorem up_down_commutator : - ⁅up R ι σ, down R ι σ⁆ = weight R ι σ := by - apply MvPolynomial.derivation_ext - intro i - rcases i with i | (i | i) <;> simp [Derivation.commutator_apply] - -/-- The opposite shift raises the source-minus-destination weight by two. -/ -theorem weight_up_commutator : - ⁅weight R ι σ, up R ι σ⁆ = (2 : R) • up R ι σ := by - apply MvPolynomial.derivation_ext - intro i - rcases i with i | (i | i) <;> - simp [Derivation.commutator_apply, two_smul] - -/-- The forward shift lowers the source-minus-destination weight by two. -/ -theorem weight_down_commutator : - ⁅weight R ι σ, down R ι σ⁆ = -(2 : R) • down R ι σ := by - apply MvPolynomial.derivation_ext - intro i - rcases i with i | (i | i) <;> - simp [Derivation.commutator_apply, two_smul] - abel - -end Problem346.PolynomialShift - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Problem346.PolynomialShift + +open MvPolynomial + +universe u v w + +abbrev Vars (ι : Type u) (σ : Type v) := ι ⊕ (ι ⊕ σ) +abbrev Poly (R : Type w) (ι : Type u) (σ : Type v) [CommRing R] := + MvPolynomial (Vars ι σ) R + +variable (R : Type w) (ι : Type u) (σ : Type v) [CommRing R] + +/-- Shift one unit of degree from the first coordinate block to the second. -/ +def down : Derivation R (Poly R ι σ) (Poly R ι σ) := + mkDerivation R (Sum.elim (fun i => X (Sum.inr (Sum.inl i))) (fun _ => 0)) + +/-- The opposite shift. -/ +def up : Derivation R (Poly R ι σ) (Poly R ι σ) := + mkDerivation R (Sum.elim (fun _ => 0) + (Sum.elim (fun i => X (Sum.inl i)) (fun _ => 0))) + +/-- Euler operator of the first coordinate block. -/ +def sourceEuler : Derivation R (Poly R ι σ) (Poly R ι σ) := + mkDerivation R (Sum.elim (fun i => X (Sum.inl i)) (fun _ => 0)) + +/-- Euler operator of the second coordinate block. -/ +def targetEuler : Derivation R (Poly R ι σ) (Poly R ι σ) := + mkDerivation R (Sum.elim (fun _ => 0) + (Sum.elim (fun i => X (Sum.inr (Sum.inl i))) (fun _ => 0))) + +/-- Source degree minus destination degree. -/ +def weight : Derivation R (Poly R ι σ) (Poly R ι σ) := + sourceEuler R ι σ - targetEuler R ι σ + +@[simp] theorem down_source (i : ι) : + down R ι σ (X (Sum.inl i)) = X (Sum.inr (Sum.inl i)) := by + simp [down] + +@[simp] theorem down_target (i : ι) : + down R ι σ (X (Sum.inr (Sum.inl i))) = 0 := by + simp [down] + +@[simp] theorem down_spectator (i : σ) : + down R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by + simp [down] + +@[simp] theorem up_source (i : ι) : + up R ι σ (X (Sum.inl i)) = 0 := by + simp [up] + +@[simp] theorem up_target (i : ι) : + up R ι σ (X (Sum.inr (Sum.inl i))) = X (Sum.inl i) := by + simp [up] + +@[simp] theorem up_spectator (i : σ) : + up R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by + simp [up] + +@[simp] theorem weight_source (i : ι) : + weight R ι σ (X (Sum.inl i)) = X (Sum.inl i) := by + simp [weight, sourceEuler, targetEuler] + +@[simp] theorem weight_target (i : ι) : + weight R ι σ (X (Sum.inr (Sum.inl i))) = -X (Sum.inr (Sum.inl i)) := by + simp [weight, sourceEuler, targetEuler] + +@[simp] theorem weight_spectator (i : σ) : + weight R ι σ (X (Sum.inr (Sum.inr i))) = 0 := by + simp [weight, sourceEuler, targetEuler] + +/-- The fundamental commutator, with arbitrary spectator variables. -/ +theorem up_down_commutator : + ⁅up R ι σ, down R ι σ⁆ = weight R ι σ := by + apply MvPolynomial.derivation_ext + intro i + rcases i with i | (i | i) <;> simp [Derivation.commutator_apply] + +/-- The opposite shift raises the source-minus-destination weight by two. -/ +theorem weight_up_commutator : + ⁅weight R ι σ, up R ι σ⁆ = (2 : R) • up R ι σ := by + apply MvPolynomial.derivation_ext + intro i + rcases i with i | (i | i) <;> + simp [Derivation.commutator_apply, two_smul] + +/-- The forward shift lowers the source-minus-destination weight by two. -/ +theorem weight_down_commutator : + ⁅weight R ι σ, down R ι σ⁆ = -(2 : R) • down R ι σ := by + apply MvPolynomial.derivation_ext + intro i + rcases i with i | (i | i) <;> + simp [Derivation.commutator_apply, two_smul] + abel + +end Problem346.PolynomialShift + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Surjectivity.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Surjectivity.lean index 4e64c2e8765ff1abd323e279047ac3a36bb1684d..0ee873722e7078bd9a231282cd5fab30baeed959 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Surjectivity.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Surjectivity.lean @@ -1,27 +1,27 @@ -import OAI.RepresentationTheory.FoulkesHowe.CanonicalMap -import OAI.RepresentationTheory.FoulkesHowe.Annihilator - -namespace OAI - -noncomputable section -namespace Problem346 - -/-- Existence, surjectivity, and uniqueness reduce entirely to the vanishing theorem. -/ -theorem canonical_surjective_unique_of_vanishing (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] - (hvan : ∀ T : SymmetricMultilinearForm a b V, - IsSymmetricMultilinearForm a b V T → - (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0) : - ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), - IsFoulkesMap a b V μ ∧ Function.Surjective μ ∧ - ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), - IsFoulkesMap a b V ν → ν = μ := by - obtain ⟨μ, hμ⟩ := exists_foulkesMap_from_spanning a b V - exact ⟨μ, hμ, IsFoulkesMap.surjective_of_vanishing a b V μ hμ hvan, - fun ν hν => IsFoulkesMap.unique a b V hν hμ⟩ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.CanonicalMap +import OAI.RepresentationTheory.FoulkesHowe.Annihilator + +namespace OAI + +noncomputable section +namespace Problem346 + +/-- Existence, surjectivity, and uniqueness reduce entirely to the vanishing theorem. -/ +theorem canonical_surjective_unique_of_vanishing (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] + (hvan : ∀ T : SymmetricMultilinearForm a b V, + IsSymmetricMultilinearForm a b V T → + (∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) → T = 0) : + ∃ μ : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), + IsFoulkesMap a b V μ ∧ Function.Surjective μ ∧ + ∀ ν : SymPow b (SymPow a V) →ₗ[ℂ] SymPow a (SymPow b V), + IsFoulkesMap a b V ν → ν = μ := by + obtain ⟨μ, hμ⟩ := exists_foulkesMap_from_spanning a b V + exact ⟨μ, hμ, IsFoulkesMap.surjective_of_vanishing a b V μ hμ hvan, + fun ν hν => IsFoulkesMap.unique a b V hν hμ⟩ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricDual.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricDual.lean index 23aba7ac4546cd6801831781e3b243369fa694eb..fb85ee43f05ee8ca914d02a475d5d4b1957c5b95 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricDual.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricDual.lean @@ -1,31 +1,31 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model -import OAI.RepresentationTheory.FoulkesHowe.AlgebraEvaluation - -namespace OAI - -noncomputable section -universe u -namespace Problem346 - -variable (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -/-- A symmetric-power duality map is injective as soon as evaluation on pure powers agrees -with evaluation in the symmetric algebra. -/ -theorem symPowDual_injective_of_pure_evaluation (n : ℕ) - (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) - (hB : ∀ (p : SymPow n (Module.Dual ℂ V)) (x : V), - B p (symMonomial n V (fun _ => x)) = - SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val) : - Function.Injective B := by - intro p q hpq - apply Subtype.ext - apply sub_eq_zero.mp - apply symAlg_dual_eq_zero_of_eval_eq_zero V - intro x - rw [map_sub, ← hB p x, ← hB q x, hpq, sub_self] - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model +import OAI.RepresentationTheory.FoulkesHowe.AlgebraEvaluation + +namespace OAI + +noncomputable section +universe u +namespace Problem346 + +variable (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +/-- A symmetric-power duality map is injective as soon as evaluation on pure powers agrees +with evaluation in the symmetric algebra. -/ +theorem symPowDual_injective_of_pure_evaluation (n : ℕ) + (B : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V)) + (hB : ∀ (p : SymPow n (Module.Dual ℂ V)) (x : V), + B p (symMonomial n V (fun _ => x)) = + SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val) : + Function.Injective B := by + intro p q hpq + apply Subtype.ext + apply sub_eq_zero.mp + apply symAlg_dual_eq_zero_of_eval_eq_zero V + intro x + rw [map_sub, ← hB p x, ← hB q x, hpq, sub_self] + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricLift.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricLift.lean index cdf386a6bbe9463210b4ab02f3dc2c4714e468ad..55b58094f973bfb363548be780147812522645d3 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricLift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricLift.lean @@ -1,173 +1,173 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators Classical -open Module - -namespace Problem346 -namespace SymmetricLift - -variable {κ : Type*} {n : ℕ} - -private def tupleExponent (f : Fin n → κ) : κ →₀ ℕ := - ∑ i, Finsupp.single (f i) 1 - -private lemma tupleExponent_apply (f : Fin n → κ) (k : κ) : - tupleExponent f k = Fintype.card {i // f i = k} := by - classical - rw [Fintype.card_subtype] - simp only [tupleExponent, Finsupp.coe_finsetSum, Finset.sum_apply, Finsupp.single_apply, Finset.sum_boole, Nat.cast_id] - -private lemma exists_perm_of_exponent_eq (f g : Fin n → κ) - (h : tupleExponent f = tupleExponent g) : - ∃ σ : Equiv.Perm (Fin n), ∀ i, g (σ i) = f i := by - classical - have hc (k : κ) : Fintype.card {i // f i = k} = Fintype.card {i // g i = k} := by - simpa only [tupleExponent_apply] using congrArg (fun d : κ →₀ ℕ => d k) h - let e (k : κ) : {i // f i = k} ≃ {i // g i = k} := - Fintype.equivOfCardEq (hc k) - exact ⟨Equiv.ofFiberEquiv e, Equiv.ofFiberEquiv_map e⟩ - -variable {V W : Type*} [AddCommGroup V] [Module ℂ V] - [AddCommGroup W] [Module ℂ W] - -private def liftValues (b : Basis κ ℂ V) - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) (d : κ →₀ ℕ) : W := - if h : ∃ f : Fin n → κ, tupleExponent f = d then - T (fun i => b (Classical.choose h i)) else 0 - -private lemma liftValues_tuple (b : Basis κ ℂ V) - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) - (f : Fin n → κ) : liftValues b T (tupleExponent f) = T (fun i => b (f i)) := by - let h : ∃ g : Fin n → κ, tupleExponent g = tupleExponent f := ⟨f, rfl⟩ - rw [liftValues, dite_eq_left h] - obtain ⟨σ, hσ⟩ := exists_perm_of_exponent_eq (Classical.choose h) f (Classical.choose_spec h) - convert hT σ (fun i => b (f i)) using 1 - congr 1 - funext i - rw [hσ] - -private def liftOnAlgebra (b : Basis κ ℂ V) - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) : - SymmetricAlgebra ℂ V →ₗ[ℂ] W := - ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)).comp - (SymmetricAlgebra.equivMvPolynomial b).toLinearMap - -private lemma liftOnAlgebra_basis (b : Basis κ ℂ V) - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) - (f : Fin n → κ) : - liftOnAlgebra b T (symMonomialRaw n V (fun i => b (f i))) = T (fun i => b (f i)) := by - have hp : (∏ i, MvPolynomial.X (f i) : MvPolynomial κ ℂ) = - MvPolynomial.monomial (tupleExponent f) 1 := by - simp only [tupleExponent, MvPolynomial.monomial_sum_one, MvPolynomial.X] - change ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)) - ((SymmetricAlgebra.equivMvPolynomial b) (∏ i, SymmetricAlgebra.ι ℂ V (b (f i)))) = _ - rw [map_prod] - simp only [SymmetricAlgebra.equivMvPolynomial_ι_apply] - rw [hp] - change ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)) - ((MvPolynomial.basisMonomials κ ℂ) (tupleExponent f)) = _ - rw [Basis.constr_basis, liftValues_tuple b T hT] - -private lemma liftOnAlgebra_monomial (b : Basis κ ℂ V) - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) - (v : Fin n → V) : - liftOnAlgebra b T (symMonomialRaw n V v) = T v := by - let M : MultilinearMap ℂ (fun _ : Fin n => V) (SymmetricAlgebra ℂ V) := - (MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap - (fun _ => SymmetricAlgebra.ι ℂ V) - have h : (liftOnAlgebra b T).compMultilinearMap M = T := by - apply Basis.ext_multilinear (fun _ => b) - intro f - exact liftOnAlgebra_basis b T hT f - exact congrArg (fun S : MultilinearMap ℂ (fun _ : Fin n => V) W => S v) h - -end SymmetricLift - -/-- A symmetric multilinear map descends to the homogeneous symmetric-power submodule. -/ -theorem exists_symPow_lift {n : ℕ} {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) : - ∃ L : SymPow n V →ₗ[ℂ] W, ∀ v, L (symMonomial n V v) = T v := by - let b := Module.Free.chooseBasis ℂ V - refine ⟨(SymmetricLift.liftOnAlgebra b T).domRestrict (symPowSubmodule n V), ?_⟩ - intro v - exact SymmetricLift.liftOnAlgebra_monomial b T hT v - -/-- A chosen linear descent of a symmetric multilinear map. -/ -def symPowLift {n : ℕ} {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) : - SymPow n V →ₗ[ℂ] W := - Classical.choose (exists_symPow_lift T hT) - -@[simp] theorem symPowLift_symMonomial {n : ℕ} {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (T : MultilinearMap ℂ (fun _ : Fin n => V) W) - (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) - (v : Fin n → V) : symPowLift T hT (symMonomial n V v) = T v := - Classical.choose_spec (exists_symPow_lift T hT) v - -namespace SymmetricLift - -/-- Linear maps out of a symmetric power are determined by products. -/ -theorem linearMap_ext {n : ℕ} {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - {f g : SymPow n V →ₗ[ℂ] W} - (h : ∀ v, f (symMonomial n V v) = g (symMonomial n V v)) : f = g := by - apply (Submodule.linearMap_eq_iff_of_eq_span f g rfl).2 - rintro ⟨x, ⟨v, rfl⟩⟩ - exact h v - -end SymmetricLift - -/-- The submodule of multilinear maps invariant under permutations of their arguments. -/ -def symmetricMultilinearSubmodule (n : ℕ) (V W : Type*) - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] : - Submodule ℂ (MultilinearMap ℂ (fun _ : Fin n => V) W) where - carrier := {T | ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), - T (fun i => v (σ i)) = T v} - zero_mem' := by simp - add_mem' := by - intro T U hT hU σ v - simp only [add_apply, hT σ v, hU σ v] - smul_mem' := by - intro c T hT σ v - simp only [smul_apply, hT σ v] - -/-- Descent from symmetric multilinear maps is linear in the map being descended. -/ -def symPowLiftLinear (n : ℕ) (V W : Type*) - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] : - symmetricMultilinearSubmodule n V W →ₗ[ℂ] (SymPow n V →ₗ[ℂ] W) where - toFun T := symPowLift T.val T.property - map_add' T U := by - apply SymmetricLift.linearMap_ext - intro v - exact (symPowLift_symMonomial (T + U).val (T + U).property v).trans - (congrArg₂ (fun left right : W => left + right) - (symPowLift_symMonomial T.val T.property v).symm - (symPowLift_symMonomial U.val U.property v).symm) - map_smul' c T := by - apply SymmetricLift.linearMap_ext - intro v - exact (symPowLift_symMonomial (c • T).val (c • T).property v).trans - (congrArg (c • ·) (symPowLift_symMonomial T.val T.property v).symm) - -@[simp] theorem symPowLiftLinear_symMonomial {n : ℕ} {V W : Type*} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (T : symmetricMultilinearSubmodule n V W) (v : Fin n → V) : - symPowLiftLinear n V W T (symMonomial n V v) = T.val v := - symPowLift_symMonomial T.val T.property v - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators Classical +open Module + +namespace Problem346 +namespace SymmetricLift + +variable {κ : Type*} {n : ℕ} + +private def tupleExponent (f : Fin n → κ) : κ →₀ ℕ := + ∑ i, Finsupp.single (f i) 1 + +private lemma tupleExponent_apply (f : Fin n → κ) (k : κ) : + tupleExponent f k = Fintype.card {i // f i = k} := by + classical + rw [Fintype.card_subtype] + simp only [tupleExponent, Finsupp.coe_finsetSum, Finset.sum_apply, Finsupp.single_apply, Finset.sum_boole, Nat.cast_id] + +private lemma exists_perm_of_exponent_eq (f g : Fin n → κ) + (h : tupleExponent f = tupleExponent g) : + ∃ σ : Equiv.Perm (Fin n), ∀ i, g (σ i) = f i := by + classical + have hc (k : κ) : Fintype.card {i // f i = k} = Fintype.card {i // g i = k} := by + simpa only [tupleExponent_apply] using congrArg (fun d : κ →₀ ℕ => d k) h + let e (k : κ) : {i // f i = k} ≃ {i // g i = k} := + Fintype.equivOfCardEq (hc k) + exact ⟨Equiv.ofFiberEquiv e, Equiv.ofFiberEquiv_map e⟩ + +variable {V W : Type*} [AddCommGroup V] [Module ℂ V] + [AddCommGroup W] [Module ℂ W] + +private def liftValues (b : Basis κ ℂ V) + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) (d : κ →₀ ℕ) : W := + if h : ∃ f : Fin n → κ, tupleExponent f = d then + T (fun i => b (Classical.choose h i)) else 0 + +private lemma liftValues_tuple (b : Basis κ ℂ V) + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) + (f : Fin n → κ) : liftValues b T (tupleExponent f) = T (fun i => b (f i)) := by + let h : ∃ g : Fin n → κ, tupleExponent g = tupleExponent f := ⟨f, rfl⟩ + rw [liftValues, dite_eq_left h] + obtain ⟨σ, hσ⟩ := exists_perm_of_exponent_eq (Classical.choose h) f (Classical.choose_spec h) + convert hT σ (fun i => b (f i)) using 1 + congr 1 + funext i + rw [hσ] + +private def liftOnAlgebra (b : Basis κ ℂ V) + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) : + SymmetricAlgebra ℂ V →ₗ[ℂ] W := + ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)).comp + (SymmetricAlgebra.equivMvPolynomial b).toLinearMap + +private lemma liftOnAlgebra_basis (b : Basis κ ℂ V) + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) + (f : Fin n → κ) : + liftOnAlgebra b T (symMonomialRaw n V (fun i => b (f i))) = T (fun i => b (f i)) := by + have hp : (∏ i, MvPolynomial.X (f i) : MvPolynomial κ ℂ) = + MvPolynomial.monomial (tupleExponent f) 1 := by + simp only [tupleExponent, MvPolynomial.monomial_sum_one, MvPolynomial.X] + change ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)) + ((SymmetricAlgebra.equivMvPolynomial b) (∏ i, SymmetricAlgebra.ι ℂ V (b (f i)))) = _ + rw [map_prod] + simp only [SymmetricAlgebra.equivMvPolynomial_ι_apply] + rw [hp] + change ((MvPolynomial.basisMonomials κ ℂ).constr ℂ (liftValues b T)) + ((MvPolynomial.basisMonomials κ ℂ) (tupleExponent f)) = _ + rw [Basis.constr_basis, liftValues_tuple b T hT] + +private lemma liftOnAlgebra_monomial (b : Basis κ ℂ V) + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) + (v : Fin n → V) : + liftOnAlgebra b T (symMonomialRaw n V v) = T v := by + let M : MultilinearMap ℂ (fun _ : Fin n => V) (SymmetricAlgebra ℂ V) := + (MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap + (fun _ => SymmetricAlgebra.ι ℂ V) + have h : (liftOnAlgebra b T).compMultilinearMap M = T := by + apply Basis.ext_multilinear (fun _ => b) + intro f + exact liftOnAlgebra_basis b T hT f + exact congrArg (fun S : MultilinearMap ℂ (fun _ : Fin n => V) W => S v) h + +end SymmetricLift + +/-- A symmetric multilinear map descends to the homogeneous symmetric-power submodule. -/ +theorem exists_symPow_lift {n : ℕ} {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) : + ∃ L : SymPow n V →ₗ[ℂ] W, ∀ v, L (symMonomial n V v) = T v := by + let b := Module.Free.chooseBasis ℂ V + refine ⟨(SymmetricLift.liftOnAlgebra b T).domRestrict (symPowSubmodule n V), ?_⟩ + intro v + exact SymmetricLift.liftOnAlgebra_monomial b T hT v + +/-- A chosen linear descent of a symmetric multilinear map. -/ +def symPowLift {n : ℕ} {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) : + SymPow n V →ₗ[ℂ] W := + Classical.choose (exists_symPow_lift T hT) + +@[simp] theorem symPowLift_symMonomial {n : ℕ} {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (T : MultilinearMap ℂ (fun _ : Fin n => V) W) + (hT : ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), T (fun i => v (σ i)) = T v) + (v : Fin n → V) : symPowLift T hT (symMonomial n V v) = T v := + Classical.choose_spec (exists_symPow_lift T hT) v + +namespace SymmetricLift + +/-- Linear maps out of a symmetric power are determined by products. -/ +theorem linearMap_ext {n : ℕ} {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + {f g : SymPow n V →ₗ[ℂ] W} + (h : ∀ v, f (symMonomial n V v) = g (symMonomial n V v)) : f = g := by + apply (Submodule.linearMap_eq_iff_of_eq_span f g rfl).2 + rintro ⟨x, ⟨v, rfl⟩⟩ + exact h v + +end SymmetricLift + +/-- The submodule of multilinear maps invariant under permutations of their arguments. -/ +def symmetricMultilinearSubmodule (n : ℕ) (V W : Type*) + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] : + Submodule ℂ (MultilinearMap ℂ (fun _ : Fin n => V) W) where + carrier := {T | ∀ (σ : Equiv.Perm (Fin n)) (v : Fin n → V), + T (fun i => v (σ i)) = T v} + zero_mem' := by simp + add_mem' := by + intro T U hT hU σ v + simp only [add_apply, hT σ v, hU σ v] + smul_mem' := by + intro c T hT σ v + simp only [smul_apply, hT σ v] + +/-- Descent from symmetric multilinear maps is linear in the map being descended. -/ +def symPowLiftLinear (n : ℕ) (V W : Type*) + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] : + symmetricMultilinearSubmodule n V W →ₗ[ℂ] (SymPow n V →ₗ[ℂ] W) where + toFun T := symPowLift T.val T.property + map_add' T U := by + apply SymmetricLift.linearMap_ext + intro v + exact (symPowLift_symMonomial (T + U).val (T + U).property v).trans + (congrArg₂ (fun left right : W => left + right) + (symPowLift_symMonomial T.val T.property v).symm + (symPowLift_symMonomial U.val U.property v).symm) + map_smul' c T := by + apply SymmetricLift.linearMap_ext + intro v + exact (symPowLift_symMonomial (c • T).val (c • T).property v).trans + (congrArg (c • ·) (symPowLift_symMonomial T.val T.property v).symm) + +@[simp] theorem symPowLiftLinear_symMonomial {n : ℕ} {V W : Type*} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (T : symmetricMultilinearSubmodule n V W) (v : Fin n → V) : + symPowLiftLinear n V W T (symMonomial n V v) = T.val v := + symPowLift_symMonomial T.val T.property v + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricPairing.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricPairing.lean index 5906c02c7363fe5f520b90f5974fc8029cb90e8a..67de70c4bdf4a55198a4b6c108304907c8909b28 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricPairing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/SymmetricPairing.lean @@ -1,78 +1,78 @@ -import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing -import OAI.RepresentationTheory.FoulkesHowe.PairingLift - -namespace OAI - -noncomputable section -universe u v -namespace Problem346 - -variable {X : Type u} {Y : Type v} - [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] - -/-- The normalized symmetric-power pairing induced by a bilinear pairing. -/ -def symPowPairing (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : - SymPow n X →ₗ[ℂ] Module.Dual ℂ (SymPow n Y) := - Classical.choose (exists_symPow_bilinear_lift n n X Y - (permanentPairingMultilinear n B) - (fun σ x => permanentPairingMultilinear_perm_left n B x σ) - (fun x σ y => permanentPairingMultilinear_perm_right n B x y σ)) - -@[simp] theorem symPowPairing_monomial (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) - (x : Fin n → X) (y : Fin n → Y) : - symPowPairing n B (symMonomial n X x) (symMonomial n Y y) = - permanentPairing n (fun x y => B x y) x y := by - simpa only [symPowPairing, permanentPairingMultilinear_apply] using - Classical.choose_spec (exists_symPow_bilinear_lift n n X Y - (permanentPairingMultilinear n B) - (fun σ x => permanentPairingMultilinear_perm_left n B x σ) - (fun x σ y => permanentPairingMultilinear_perm_right n B x y σ)) x y - -/-- The canonical pairing from the symmetric power of the dual space. -/ -def symPowDualMap (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V) := - symPowPairing n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) - -@[simp] theorem symPowDualMap_monomial (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : Fin n → Module.Dual ℂ V) (x : Fin n → V) : - symPowDualMap n V (symMonomial n (Module.Dual ℂ V) φ) (symMonomial n V x) = - permanentPairing n (fun φ x => φ x) φ x := - symPowPairing_monomial n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) φ x - -/-- On pure powers, the pairing is ordinary algebra evaluation. -/ -theorem symPowDualMap_pure_right (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (p : SymPow n (Module.Dual ℂ V)) (x : V) : - symPowDualMap n V p (symMonomial n V (fun _ => x)) = - SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val := by - have h : (symPowDualMap n V).flip (symMonomial n V (fun _ => x)) = - (SymmetricAlgebra.lift (Module.Dual.eval ℂ V x)).toLinearMap.domRestrict - (symPowSubmodule n (Module.Dual ℂ V)) := by - apply SymmetricLift.linearMap_ext - intro φ - change symPowDualMap n V (symMonomial n (Module.Dual ℂ V) φ) - (symMonomial n V (fun _ => x)) = _ - rw [symPowDualMap_monomial] - simp [symMonomial, symMonomialRaw] - exact congrArg (fun L : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] ℂ => L p) h - -/-- The analogous pure-power evaluation in the dual variables. -/ -theorem symPowDualMap_pure_left (n : ℕ) (V : Type u) - [AddCommGroup V] [Module ℂ V] - (φ : Module.Dual ℂ V) (p : SymPow n V) : - symPowDualMap n V (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = - SymmetricAlgebra.lift φ p.val := by - have h : symPowDualMap n V (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) = - (SymmetricAlgebra.lift φ).toLinearMap.domRestrict (symPowSubmodule n V) := by - apply SymmetricLift.linearMap_ext - intro x - rw [symPowDualMap_monomial] - simp [symMonomial, symMonomialRaw] - exact congrArg (fun L : SymPow n V →ₗ[ℂ] ℂ => L p) h - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.PermanentPairing +import OAI.RepresentationTheory.FoulkesHowe.PairingLift + +namespace OAI + +noncomputable section +universe u v +namespace Problem346 + +variable {X : Type u} {Y : Type v} + [AddCommGroup X] [Module ℂ X] [AddCommGroup Y] [Module ℂ Y] + +/-- The normalized symmetric-power pairing induced by a bilinear pairing. -/ +def symPowPairing (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) : + SymPow n X →ₗ[ℂ] Module.Dual ℂ (SymPow n Y) := + Classical.choose (exists_symPow_bilinear_lift n n X Y + (permanentPairingMultilinear n B) + (fun σ x => permanentPairingMultilinear_perm_left n B x σ) + (fun x σ y => permanentPairingMultilinear_perm_right n B x y σ)) + +@[simp] theorem symPowPairing_monomial (n : ℕ) (B : X →ₗ[ℂ] Y →ₗ[ℂ] ℂ) + (x : Fin n → X) (y : Fin n → Y) : + symPowPairing n B (symMonomial n X x) (symMonomial n Y y) = + permanentPairing n (fun x y => B x y) x y := by + simpa only [symPowPairing, permanentPairingMultilinear_apply] using + Classical.choose_spec (exists_symPow_bilinear_lift n n X Y + (permanentPairingMultilinear n B) + (fun σ x => permanentPairingMultilinear_perm_left n B x σ) + (fun x σ y => permanentPairingMultilinear_perm_right n B x y σ)) x y + +/-- The canonical pairing from the symmetric power of the dual space. -/ +def symPowDualMap (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + SymPow n (Module.Dual ℂ V) →ₗ[ℂ] Module.Dual ℂ (SymPow n V) := + symPowPairing n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) + +@[simp] theorem symPowDualMap_monomial (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : Fin n → Module.Dual ℂ V) (x : Fin n → V) : + symPowDualMap n V (symMonomial n (Module.Dual ℂ V) φ) (symMonomial n V x) = + permanentPairing n (fun φ x => φ x) φ x := + symPowPairing_monomial n (LinearMap.id : Module.Dual ℂ V →ₗ[ℂ] Module.Dual ℂ V) φ x + +/-- On pure powers, the pairing is ordinary algebra evaluation. -/ +theorem symPowDualMap_pure_right (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (p : SymPow n (Module.Dual ℂ V)) (x : V) : + symPowDualMap n V p (symMonomial n V (fun _ => x)) = + SymmetricAlgebra.lift (Module.Dual.eval ℂ V x) p.val := by + have h : (symPowDualMap n V).flip (symMonomial n V (fun _ => x)) = + (SymmetricAlgebra.lift (Module.Dual.eval ℂ V x)).toLinearMap.domRestrict + (symPowSubmodule n (Module.Dual ℂ V)) := by + apply SymmetricLift.linearMap_ext + intro φ + change symPowDualMap n V (symMonomial n (Module.Dual ℂ V) φ) + (symMonomial n V (fun _ => x)) = _ + rw [symPowDualMap_monomial] + simp [symMonomial, symMonomialRaw] + exact congrArg (fun L : SymPow n (Module.Dual ℂ V) →ₗ[ℂ] ℂ => L p) h + +/-- The analogous pure-power evaluation in the dual variables. -/ +theorem symPowDualMap_pure_left (n : ℕ) (V : Type u) + [AddCommGroup V] [Module ℂ V] + (φ : Module.Dual ℂ V) (p : SymPow n V) : + symPowDualMap n V (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) p = + SymmetricAlgebra.lift φ p.val := by + have h : symPowDualMap n V (symMonomial n (Module.Dual ℂ V) (fun _ => φ)) = + (SymmetricAlgebra.lift φ).toLinearMap.domRestrict (symPowSubmodule n V) := by + apply SymmetricLift.linearMap_ext + intro x + rw [symPowDualMap_monomial] + simp [symMonomial, symMonomialRaw] + exact congrArg (fun L : SymPow n V →ₗ[ℂ] ℂ => L p) h + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/TensorPresentation.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/TensorPresentation.lean index 886483f8e475216841472b0a427b1eee0ae98e5a..2fc796556b7634212311926c8ce2bda3122bc500 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/TensorPresentation.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/TensorPresentation.lean @@ -1,61 +1,61 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -open scoped BigOperators TensorProduct - -universe u - -namespace Problem346 - -variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - -/-- Multiplication of degree-one generators as a multilinear map. -/ -def symMonomialMultilinearRaw : - MultilinearMap ℂ (fun _ : Fin n => V) (SymmetricAlgebra ℂ V) := - (MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap - (fun _ => SymmetricAlgebra.ι ℂ V) - -@[simp] theorem symMonomialMultilinearRaw_apply (v : Fin n → V) : - symMonomialMultilinearRaw n V v = symMonomialRaw n V v := rfl - -/-- The tensor-power presentation of the homogeneous symmetric power. -/ -def tensorToSymPowRaw : - (⨂[ℂ] _ : Fin n, V) →ₗ[ℂ] SymmetricAlgebra ℂ V := - PiTensorProduct.lift (symMonomialMultilinearRaw n V) - -@[simp] theorem tensorToSymPowRaw_tprod (v : Fin n → V) : - tensorToSymPowRaw n V (PiTensorProduct.tprod ℂ v) = symMonomialRaw n V v := - PiTensorProduct.lift.tprod _ - -theorem tensorToSymPowRaw_range : - LinearMap.range (tensorToSymPowRaw n V) = symPowSubmodule n V := by - rw [← Submodule.map_top, ← PiTensorProduct.span_tprod_eq_top, - Submodule.map_span, ← Set.range_comp] - simp only [Function.comp_def, tensorToSymPowRaw_tprod, symPowSubmodule] - -/-- Multiplication of tensors, with codomain restricted to degree `n`. -/ -def tensorToSymPow : (⨂[ℂ] _ : Fin n, V) →ₗ[ℂ] SymPow n V := - (tensorToSymPowRaw n V).codRestrict (symPowSubmodule n V) (fun x => by - rw [← tensorToSymPowRaw_range] - exact LinearMap.mem_range_self _ x) - -@[simp] theorem tensorToSymPow_tprod (v : Fin n → V) : - tensorToSymPow n V (PiTensorProduct.tprod ℂ v) = symMonomial n V v := by - apply Subtype.ext - exact tensorToSymPowRaw_tprod n V v - -theorem tensorToSymPow_surjective : Function.Surjective (tensorToSymPow n V) := by - intro x - have hx : x.val ∈ LinearMap.range (tensorToSymPowRaw n V) := by - rw [tensorToSymPowRaw_range] - exact x.property - obtain ⟨y, hy⟩ := hx - exact ⟨y, Subtype.ext hy⟩ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +open scoped BigOperators TensorProduct + +universe u + +namespace Problem346 + +variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + +/-- Multiplication of degree-one generators as a multilinear map. -/ +def symMonomialMultilinearRaw : + MultilinearMap ℂ (fun _ : Fin n => V) (SymmetricAlgebra ℂ V) := + (MultilinearMap.mkPiAlgebra ℂ (Fin n) (SymmetricAlgebra ℂ V)).compLinearMap + (fun _ => SymmetricAlgebra.ι ℂ V) + +@[simp] theorem symMonomialMultilinearRaw_apply (v : Fin n → V) : + symMonomialMultilinearRaw n V v = symMonomialRaw n V v := rfl + +/-- The tensor-power presentation of the homogeneous symmetric power. -/ +def tensorToSymPowRaw : + (⨂[ℂ] _ : Fin n, V) →ₗ[ℂ] SymmetricAlgebra ℂ V := + PiTensorProduct.lift (symMonomialMultilinearRaw n V) + +@[simp] theorem tensorToSymPowRaw_tprod (v : Fin n → V) : + tensorToSymPowRaw n V (PiTensorProduct.tprod ℂ v) = symMonomialRaw n V v := + PiTensorProduct.lift.tprod _ + +theorem tensorToSymPowRaw_range : + LinearMap.range (tensorToSymPowRaw n V) = symPowSubmodule n V := by + rw [← Submodule.map_top, ← PiTensorProduct.span_tprod_eq_top, + Submodule.map_span, ← Set.range_comp] + simp only [Function.comp_def, tensorToSymPowRaw_tprod, symPowSubmodule] + +/-- Multiplication of tensors, with codomain restricted to degree `n`. -/ +def tensorToSymPow : (⨂[ℂ] _ : Fin n, V) →ₗ[ℂ] SymPow n V := + (tensorToSymPowRaw n V).codRestrict (symPowSubmodule n V) (fun x => by + rw [← tensorToSymPowRaw_range] + exact LinearMap.mem_range_self _ x) + +@[simp] theorem tensorToSymPow_tprod (v : Fin n → V) : + tensorToSymPow n V (PiTensorProduct.tprod ℂ v) = symMonomial n V v := by + apply Subtype.ext + exact tensorToSymPowRaw_tprod n V v + +theorem tensorToSymPow_surjective : Function.Surjective (tensorToSymPow n V) := by + intro x + have hx : x.val ∈ LinearMap.range (tensorToSymPowRaw n V) := by + rw [tensorToSymPowRaw_range] + exact x.property + obtain ⟨y, hy⟩ := hx + exact ⟨y, Subtype.ext hy⟩ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/TransferDerivative.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/TransferDerivative.lean index a67a8506a8d68514bf20ea1c4f7533d016640dec..6ee6d471e26ff2942bce6cac9d15270a286c6c67 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/TransferDerivative.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/TransferDerivative.lean @@ -1,121 +1,121 @@ -import OAI.RepresentationTheory.FoulkesHowe.FirstCounts -import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm -import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial -import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative - -namespace OAI - -noncomputable section -open scoped BigOperators - -namespace Problem346 - -theorem multilinearPolynomial_eq_slotPolynomial - {S K B V : Type*} [Fintype S] [DecidableEq S] [Fintype K] - [AddCommGroup V] [Module ℂ V] - (T : MultilinearMap ℂ (fun _ : S => V) ℂ) (e : K → V) (l : S → B) : - multilinearPolynomial T e l = - SlotPolynomial.polynomial (fun k => T (fun s => e (k s))) l := by - classical - unfold multilinearPolynomial SlotPolynomial.polynomial - congr 1 - ext k - simp - -private theorem swap_pair_same_row {A B : Type*} [DecidableEq A] [DecidableEq B] - (i : A) (j k : B) (p : A × B) : - Equiv.swap (i, j) (i, k) p = - (p.1, if p.1 = i then Equiv.swap j k p.2 else p.2) := by - rcases p with ⟨q, t⟩ - by_cases hq : q = i - · subst q - by_cases htj : t = j - · subst t - simp - · by_cases htk : t = k - · subst t - simp - · simp [Equiv.swap_apply_of_ne_of_ne, htj, htk] - · have h1 : (q,t) ≠ (i,j) := by intro h; exact hq (congrArg Prod.fst h) - have h2 : (q,t) ≠ (i,k) := by intro h; exact hq (congrArg Prod.fst h) - simp [Equiv.swap_apply_of_ne_of_ne h1 h2, hq] - -/-- The flattened form is invariant under swapping two factors in a single row. -/ -theorem flattenedForm_swap_row (a b : ℕ) (V : Type*) - [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) - (i : Fin a) (j k : Fin b) (x : Fin a × Fin b → V) : - flattenedForm T (x ∘ Equiv.swap (i,j) (i,k)) = - flattenedForm T x := by - classical - have h := flattenedForm_factor_perm T - (fun q => if q = i then Equiv.swap j k else Equiv.refl _) x - convert h using 1 - congr 1 - funext p - rw [Function.comp_apply, swap_pair_same_row] - by_cases hp : p.1 = i <;> simp [hp] - -/-- If the source label occurs only in one row, every occurrence gives the same -coordinate-polynomial derivative term, by symmetry of factors in that row. -/ -theorem flattened_derivative_eq_card_smul - (a b : ℕ) (V K B : Type*) [AddCommGroup V] [Module ℂ V] - [Fintype K] [DecidableEq B] - (T : SymmetricMultilinearForm a b V) (e : K → V) - (l : Fin a × Fin b → B) (src dst : B) (i : Fin a) (j : Fin b) - (hj : l (i,j) = src) - (hrow : ∀ p, l p = src → p.1 = i) - (D : Derivation ℂ (MvPolynomial (B × K) ℂ) (MvPolynomial (B × K) ℂ)) - (hD : ∀ q k, D (MvPolynomial.X (q,k)) = - if q = src then MvPolynomial.X (dst,k) else 0) : - D (multilinearPolynomial (flattenedForm T) e l) = - (Finset.univ.filter (fun p => l p = src)).card • - multilinearPolynomial (flattenedForm T) e - (Function.update l (i,j) dst) := by - classical - let c : ((Fin a × Fin b) → K) → ℂ := - fun k => flattenedForm T (fun p => e (k p)) - have hc : ∀ p, l p = src → ∀ k, c (k ∘ Equiv.swap p (i,j)) = c k := by - intro p hp k - rcases p with ⟨q,t⟩ - have hq := hrow (q,t) hp - dsimp at hq - subst q - exact flattenedForm_swap_row a b V T i t j (fun p => e (k p)) - have h := SlotPolynomial.derivation_polynomial_eq_card_smul - c l src dst (i,j) hj D hD hc - rw [multilinearPolynomial_eq_slotPolynomial, multilinearPolynomial_eq_slotPolynomial] - exact h - -/-- The concrete one-step identity in the first transfer. The source is the -`t` block; its remaining occurrences all lie in the distinguished row. -/ -theorem firstLabel_derivative - (r m k : ℕ) (hk : k < m) (V K : Type*) - [AddCommGroup V] [Module ℂ V] [Fintype K] - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : K → V) - (D : Derivation ℂ (MvPolynomial (FirstBlock m × K) ℂ) - (MvPolynomial (FirstBlock m × K) ℂ)) - (hD : ∀ q j, D (MvPolynomial.X (q,j)) = - if q = some none then MvPolynomial.X (some (some ⟨k,hk⟩),j) else 0) : - D (multilinearPolynomial (flattenedForm T) e - (firstLabel r m k)) = - ((r+m-k : ℕ) : ℂ) • - multilinearPolynomial (flattenedForm T) e - (firstLabel r m (k+1)) := by - classical - have hj : firstLabel r m k - (0, ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩) = some none := by - simp [firstLabel] - have hrow : ∀ p, firstLabel r m k p = some none → p.1 = 0 := by - intro p hp - exact ((firstLabel_eq_t_iff r m k (Nat.le_of_lt hk) p).mp hp).1 - have h := flattened_derivative_eq_card_smul (r+1) (r+m) V K (FirstBlock m) - T e (firstLabel r m k) (some none) (some (some ⟨k,hk⟩)) - 0 ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ hj hrow D hD - rw [firstLabel_card_t r m k (Nat.le_of_lt hk), ← firstLabel_step r m k hk] at h - simpa only [Nat.cast_smul_eq_nsmul] using h - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FirstCounts +import OAI.RepresentationTheory.FoulkesHowe.FlattenedForm +import OAI.RepresentationTheory.FoulkesHowe.MultilinearPolynomial +import OAI.RepresentationTheory.FoulkesHowe.SlotDerivative + +namespace OAI + +noncomputable section +open scoped BigOperators + +namespace Problem346 + +theorem multilinearPolynomial_eq_slotPolynomial + {S K B V : Type*} [Fintype S] [DecidableEq S] [Fintype K] + [AddCommGroup V] [Module ℂ V] + (T : MultilinearMap ℂ (fun _ : S => V) ℂ) (e : K → V) (l : S → B) : + multilinearPolynomial T e l = + SlotPolynomial.polynomial (fun k => T (fun s => e (k s))) l := by + classical + unfold multilinearPolynomial SlotPolynomial.polynomial + congr 1 + ext k + simp + +private theorem swap_pair_same_row {A B : Type*} [DecidableEq A] [DecidableEq B] + (i : A) (j k : B) (p : A × B) : + Equiv.swap (i, j) (i, k) p = + (p.1, if p.1 = i then Equiv.swap j k p.2 else p.2) := by + rcases p with ⟨q, t⟩ + by_cases hq : q = i + · subst q + by_cases htj : t = j + · subst t + simp + · by_cases htk : t = k + · subst t + simp + · simp [Equiv.swap_apply_of_ne_of_ne, htj, htk] + · have h1 : (q,t) ≠ (i,j) := by intro h; exact hq (congrArg Prod.fst h) + have h2 : (q,t) ≠ (i,k) := by intro h; exact hq (congrArg Prod.fst h) + simp [Equiv.swap_apply_of_ne_of_ne h1 h2, hq] + +/-- The flattened form is invariant under swapping two factors in a single row. -/ +theorem flattenedForm_swap_row (a b : ℕ) (V : Type*) + [AddCommGroup V] [Module ℂ V] (T : SymmetricMultilinearForm a b V) + (i : Fin a) (j k : Fin b) (x : Fin a × Fin b → V) : + flattenedForm T (x ∘ Equiv.swap (i,j) (i,k)) = + flattenedForm T x := by + classical + have h := flattenedForm_factor_perm T + (fun q => if q = i then Equiv.swap j k else Equiv.refl _) x + convert h using 1 + congr 1 + funext p + rw [Function.comp_apply, swap_pair_same_row] + by_cases hp : p.1 = i <;> simp [hp] + +/-- If the source label occurs only in one row, every occurrence gives the same +coordinate-polynomial derivative term, by symmetry of factors in that row. -/ +theorem flattened_derivative_eq_card_smul + (a b : ℕ) (V K B : Type*) [AddCommGroup V] [Module ℂ V] + [Fintype K] [DecidableEq B] + (T : SymmetricMultilinearForm a b V) (e : K → V) + (l : Fin a × Fin b → B) (src dst : B) (i : Fin a) (j : Fin b) + (hj : l (i,j) = src) + (hrow : ∀ p, l p = src → p.1 = i) + (D : Derivation ℂ (MvPolynomial (B × K) ℂ) (MvPolynomial (B × K) ℂ)) + (hD : ∀ q k, D (MvPolynomial.X (q,k)) = + if q = src then MvPolynomial.X (dst,k) else 0) : + D (multilinearPolynomial (flattenedForm T) e l) = + (Finset.univ.filter (fun p => l p = src)).card • + multilinearPolynomial (flattenedForm T) e + (Function.update l (i,j) dst) := by + classical + let c : ((Fin a × Fin b) → K) → ℂ := + fun k => flattenedForm T (fun p => e (k p)) + have hc : ∀ p, l p = src → ∀ k, c (k ∘ Equiv.swap p (i,j)) = c k := by + intro p hp k + rcases p with ⟨q,t⟩ + have hq := hrow (q,t) hp + dsimp at hq + subst q + exact flattenedForm_swap_row a b V T i t j (fun p => e (k p)) + have h := SlotPolynomial.derivation_polynomial_eq_card_smul + c l src dst (i,j) hj D hD hc + rw [multilinearPolynomial_eq_slotPolynomial, multilinearPolynomial_eq_slotPolynomial] + exact h + +/-- The concrete one-step identity in the first transfer. The source is the +`t` block; its remaining occurrences all lie in the distinguished row. -/ +theorem firstLabel_derivative + (r m k : ℕ) (hk : k < m) (V K : Type*) + [AddCommGroup V] [Module ℂ V] [Fintype K] + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : K → V) + (D : Derivation ℂ (MvPolynomial (FirstBlock m × K) ℂ) + (MvPolynomial (FirstBlock m × K) ℂ)) + (hD : ∀ q j, D (MvPolynomial.X (q,j)) = + if q = some none then MvPolynomial.X (some (some ⟨k,hk⟩),j) else 0) : + D (multilinearPolynomial (flattenedForm T) e + (firstLabel r m k)) = + ((r+m-k : ℕ) : ℂ) • + multilinearPolynomial (flattenedForm T) e + (firstLabel r m (k+1)) := by + classical + have hj : firstLabel r m k + (0, ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩) = some none := by + simp [firstLabel] + have hrow : ∀ p, firstLabel r m k p = some none → p.1 = 0 := by + intro p hp + exact ((firstLabel_eq_t_iff r m k (Nat.le_of_lt hk) p).mp hp).1 + have h := flattened_derivative_eq_card_smul (r+1) (r+m) V K (FirstBlock m) + T e (firstLabel r m k) (some none) (some (some ⟨k,hk⟩)) + 0 ⟨k, Nat.lt_of_lt_of_le hk (Nat.le_add_left m r)⟩ hj hrow D hD + rw [firstLabel_card_t r m k (Nat.le_of_lt hk), ← firstLabel_step r m k hk] at h + simpa only [Nat.cast_smul_eq_nsmul] using h + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/TransferEndpoints.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/TransferEndpoints.lean index 26eff67b7595405ef46a4436fa236efaf7309df6..4173211c5df01a9451018ddded9136807c833837 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/TransferEndpoints.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/TransferEndpoints.lean @@ -1,133 +1,133 @@ -import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial -import OAI.RepresentationTheory.FoulkesHowe.Multiplication - -namespace OAI - -noncomputable section -open scoped BigOperators -namespace Problem346 -universe u v -variable {V : Type u} [AddCommGroup V] [Module ℂ V] -variable {κ : Type v} [Fintype κ] - -/-- Assign vector values to the three kinds of blocks in the first transfer. -/ -def firstVectors {m : ℕ} (x t : V) (y : Fin m → V) : FirstBlock m → V - | none => x - | some none => t - | some (some j) => y j - -omit [AddCommGroup V] [Module ℂ V] in -@[simp] theorem firstVectors_x {m : ℕ} (x t : V) (y : Fin m → V) : - firstVectors x t y none = x := rfl -omit [AddCommGroup V] [Module ℂ V] in -@[simp] theorem firstVectors_t {m : ℕ} (x t : V) (y : Fin m → V) : - firstVectors x t y (some none) = t := rfl -omit [AddCommGroup V] [Module ℂ V] in -@[simp] theorem firstVectors_y {m : ℕ} (x t : V) (y : Fin m → V) (j : Fin m) : - firstVectors x t y (some (some j)) = y j := rfl - -@[simp] theorem firstLabel_initial_monomial (r m : ℕ) (x t : V) (y : Fin m → V) : - symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m 0 (0,j))) = - symMonomial (r+m) V (fun _ => t) := by - simp - -@[simp] theorem firstLabel_other_monomial (r m k : ℕ) (x t : V) - (y : Fin m → V) (i : Fin r) : - symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m k (i.succ,j))) = - symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y) := by - rw [symPowMul_symMonomial] - congr 1 - funext j - refine Fin.addCases ?_ ?_ j - · intro j - simp [Fin.append] - · intro j - simp [Fin.append] - -@[simp] theorem firstLabel_final_monomial (r m : ℕ) (x t : V) (y : Fin m → V) : - symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m m (0,j))) = - symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y) := by - apply Subtype.ext - change (∏ j : Fin (r+m), SymmetricAlgebra.ι ℂ V - (firstVectors x t y (firstLabel r m m (0,j)))) = - (∏ _ : Fin r, SymmetricAlgebra.ι ℂ V t) * ∏ j : Fin m, SymmetricAlgebra.ι ℂ V (y j) - rw [← (finCongr (Nat.add_comm m r)).prod_comp - (fun j : Fin (r+m) => SymmetricAlgebra.ι ℂ V - (firstVectors x t y (firstLabel r m m (0,j))))] - rw [Fin.prod_univ_add] - have hleft : (∏ j : Fin m, SymmetricAlgebra.ι ℂ V - (firstVectors x t y (firstLabel r m m - (0, (finCongr (Nat.add_comm m r)) (Fin.castAdd r j))))) = - ∏ j : Fin m, SymmetricAlgebra.ι ℂ V (y j) := by - apply Finset.prod_congr rfl - intro j _ - simp [firstLabel] - have hright : (∏ j : Fin r, SymmetricAlgebra.ι ℂ V - (firstVectors x t y (firstLabel r m m - (0, (finCongr (Nat.add_comm m r)) (Fin.natAdd m j))))) = - ∏ _ : Fin r, SymmetricAlgebra.ι ℂ V t := by - apply Finset.prod_congr rfl - intro j _ - simp [firstLabel] - rw [hleft, hright, mul_comm] - -/-- Evaluation of the initial label configuration. -/ -theorem firstLabel_initial_form {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (y : Fin m → V) : - flattenedForm T (fun p => firstVectors x t y (firstLabel r m 0 p)) = - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) := by - rw [flattenedForm_apply] - congr 1 - funext i - cases i using Fin.cases with - | zero => exact firstLabel_initial_monomial r m x t y - | succ i => exact firstLabel_other_monomial r m 0 x t y i - -/-- Evaluation of the terminal label configuration, with t^r times the common product. -/ -theorem firstLabel_final_form {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (y : Fin m → V) : - flattenedForm T (fun p => firstVectors x t y (firstLabel r m m p)) = - T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) := by - rw [flattenedForm_apply] - congr 1 - funext i - cases i using Fin.cases with - | zero => exact firstLabel_final_monomial r m x t y - | succ i => exact firstLabel_other_monomial r m m x t y i - -/-- The binary identity makes the terminal polynomial zero. -/ -theorem firstPolynomial_final_eq_zero {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) - (h : ∀ (x t : V) (y : Fin m → V), - T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0) : - firstPolynomial T e m = 0 := by - apply multilinearPolynomial_eq_zero - intro v - have hv : firstVectors (v none) (v (some none)) (fun j => v (some (some j))) = v := by - funext b - cases b with - | none => rfl - | some b => cases b <;> rfl - rw [← hv] - rw [firstLabel_final_form] - exact h _ _ _ - -/-- A zero initial polynomial gives the freed-last-slot identity. -/ -theorem firstPolynomial_initial_vanishing {r m : ℕ} - (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : Module.Basis κ ℂ V) - (h : firstPolynomial T e 0 = 0) (x t : V) (y : Fin m → V) : - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by - rw [← firstLabel_initial_form] - have hp := (multilinearPolynomial_eq_zero_iff (flattenedForm T) e - (firstLabel r m 0)).mp h - exact hp (firstVectors x t y) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.FirstPolynomial +import OAI.RepresentationTheory.FoulkesHowe.Multiplication + +namespace OAI + +noncomputable section +open scoped BigOperators +namespace Problem346 +universe u v +variable {V : Type u} [AddCommGroup V] [Module ℂ V] +variable {κ : Type v} [Fintype κ] + +/-- Assign vector values to the three kinds of blocks in the first transfer. -/ +def firstVectors {m : ℕ} (x t : V) (y : Fin m → V) : FirstBlock m → V + | none => x + | some none => t + | some (some j) => y j + +omit [AddCommGroup V] [Module ℂ V] in +@[simp] theorem firstVectors_x {m : ℕ} (x t : V) (y : Fin m → V) : + firstVectors x t y none = x := rfl +omit [AddCommGroup V] [Module ℂ V] in +@[simp] theorem firstVectors_t {m : ℕ} (x t : V) (y : Fin m → V) : + firstVectors x t y (some none) = t := rfl +omit [AddCommGroup V] [Module ℂ V] in +@[simp] theorem firstVectors_y {m : ℕ} (x t : V) (y : Fin m → V) (j : Fin m) : + firstVectors x t y (some (some j)) = y j := rfl + +@[simp] theorem firstLabel_initial_monomial (r m : ℕ) (x t : V) (y : Fin m → V) : + symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m 0 (0,j))) = + symMonomial (r+m) V (fun _ => t) := by + simp + +@[simp] theorem firstLabel_other_monomial (r m k : ℕ) (x t : V) + (y : Fin m → V) (i : Fin r) : + symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m k (i.succ,j))) = + symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y) := by + rw [symPowMul_symMonomial] + congr 1 + funext j + refine Fin.addCases ?_ ?_ j + · intro j + simp [Fin.append] + · intro j + simp [Fin.append] + +@[simp] theorem firstLabel_final_monomial (r m : ℕ) (x t : V) (y : Fin m → V) : + symMonomial (r+m) V (fun j => firstVectors x t y (firstLabel r m m (0,j))) = + symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y) := by + apply Subtype.ext + change (∏ j : Fin (r+m), SymmetricAlgebra.ι ℂ V + (firstVectors x t y (firstLabel r m m (0,j)))) = + (∏ _ : Fin r, SymmetricAlgebra.ι ℂ V t) * ∏ j : Fin m, SymmetricAlgebra.ι ℂ V (y j) + rw [← (finCongr (Nat.add_comm m r)).prod_comp + (fun j : Fin (r+m) => SymmetricAlgebra.ι ℂ V + (firstVectors x t y (firstLabel r m m (0,j))))] + rw [Fin.prod_univ_add] + have hleft : (∏ j : Fin m, SymmetricAlgebra.ι ℂ V + (firstVectors x t y (firstLabel r m m + (0, (finCongr (Nat.add_comm m r)) (Fin.castAdd r j))))) = + ∏ j : Fin m, SymmetricAlgebra.ι ℂ V (y j) := by + apply Finset.prod_congr rfl + intro j _ + simp [firstLabel] + have hright : (∏ j : Fin r, SymmetricAlgebra.ι ℂ V + (firstVectors x t y (firstLabel r m m + (0, (finCongr (Nat.add_comm m r)) (Fin.natAdd m j))))) = + ∏ _ : Fin r, SymmetricAlgebra.ι ℂ V t := by + apply Finset.prod_congr rfl + intro j _ + simp [firstLabel] + rw [hleft, hright, mul_comm] + +/-- Evaluation of the initial label configuration. -/ +theorem firstLabel_initial_form {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (y : Fin m → V) : + flattenedForm T (fun p => firstVectors x t y (firstLabel r m 0 p)) = + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) := by + rw [flattenedForm_apply] + congr 1 + funext i + cases i using Fin.cases with + | zero => exact firstLabel_initial_monomial r m x t y + | succ i => exact firstLabel_other_monomial r m 0 x t y i + +/-- Evaluation of the terminal label configuration, with t^r times the common product. -/ +theorem firstLabel_final_form {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) (y : Fin m → V) : + flattenedForm T (fun p => firstVectors x t y (firstLabel r m m p)) = + T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) := by + rw [flattenedForm_apply] + congr 1 + funext i + cases i using Fin.cases with + | zero => exact firstLabel_final_monomial r m x t y + | succ i => exact firstLabel_other_monomial r m m x t y i + +/-- The binary identity makes the terminal polynomial zero. -/ +theorem firstPolynomial_final_eq_zero {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : κ → V) + (h : ∀ (x t : V) (y : Fin m → V), + T (Fin.cons (symPowMul r m (symMonomial r V (fun _ => t)) (symMonomial m V y)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0) : + firstPolynomial T e m = 0 := by + apply multilinearPolynomial_eq_zero + intro v + have hv : firstVectors (v none) (v (some none)) (fun j => v (some (some j))) = v := by + funext b + cases b with + | none => rfl + | some b => cases b <;> rfl + rw [← hv] + rw [firstLabel_final_form] + exact h _ _ _ + +/-- A zero initial polynomial gives the freed-last-slot identity. -/ +theorem firstPolynomial_initial_vanishing {r m : ℕ} + (T : SymmetricMultilinearForm (r+1) (r+m) V) (e : Module.Basis κ ℂ V) + (h : firstPolynomial T e 0 = 0) (x t : V) (y : Fin m → V) : + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun _ => symPowMul r m (symMonomial r V (fun _ => x)) (symMonomial m V y))) = 0 := by + rw [← firstLabel_initial_form] + have hp := (multilinearPolynomial_eq_zero_iff (flattenedForm T) e + (firstLabel r m 0)).mp h + exact hp (firstVectors x t y) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/Vanishing.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/Vanishing.lean index d13b653542df17b5d9c3c1edde4a65ac8b58e787..a4182db3245e778bf573a73bf9472e5c9d81adbb 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/Vanishing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/Vanishing.lean @@ -1,72 +1,72 @@ -import OAI.RepresentationTheory.FoulkesHowe.VanishingOne -import OAI.RepresentationTheory.FoulkesHowe.VanishingInduction - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- The induction on the number of slots, isolated from the two polynomial -transfer arguments. The first argument packages the binary-pencil identity and -the first transfer; the second is the common-power-removal transfer. -/ -theorem vanishing_induction_from_transfer_steps - (firstTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → - ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, - IsSymmetricMultilinearForm (r+1) (r+m) V T → - (∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) → - ∀ x t : V, ∀ y : Fin m → V, - lowerProductForm r m T x t (fun _ => symMonomial m V y) = 0) - (secondTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → - ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, - IsSymmetricMultilinearForm (r+1) (r+m) V T → - (∀ x t : V, ∀ Q : Fin r → SymPow m V, lowerProductForm r m T x t Q = 0) → - ∀ v : Fin (r+1) → V, - T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0) - (purePowerExt : ∀ a b : ℕ, ∀ T : SymmetricMultilinearForm a b V, - (∀ v : Fin a → V, T (fun i => symMonomial b V (fun _ => v i)) = 0) → T = 0) : - ∀ a b : ℕ, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → - ∀ T : SymmetricMultilinearForm a b V, - IsSymmetricMultilinearForm a b V T → - (∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) → T = 0 := by - intro a - induction a with - | zero => - intro b ha - omega - | succ r ih => - intro b ha hb hab T hT hdiag - by_cases hr : r = 0 - · subst r - exact vanishing_on_products_one V b T hdiag - have hrpos : 0 < r := Nat.pos_of_ne_zero hr - have hrb : r ≤ b := by - have hmul : r ≤ (r+1)*r := by nlinarith - simpa only [Nat.succ_eq_add_one, Nat.add_sub_cancel] using hmul.trans hab - obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb - have hbound : (r+1)*r ≤ r+m := by simpa only [Nat.succ_eq_add_one, - Nat.add_sub_cancel] using hab - have hm : 0 < m := by nlinarith - have hmrange : r*(r-1) ≤ m := by - have hsub : r-1 ≤ r := Nat.sub_le .. - have hmul : r*(r-1) ≤ r*r := Nat.mul_le_mul_left r hsub - nlinarith - have hrestricted : ∀ x t : V, lowerProductForm r m T x t = 0 := by - intro x t - exact ih m hrpos hm hmrange (lowerProductForm r m T x t) - (lowerProductForm_symmetric r m T hT x t) - (firstTransfer r m hrpos hm hbound T hT hdiag x t) - apply purePowerExt (r+1) (r+m) T - apply secondTransfer r m hrpos hm hbound T hT - intro x t Q - rw [hrestricted x t] - rfl - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.VanishingOne +import OAI.RepresentationTheory.FoulkesHowe.VanishingInduction + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- The induction on the number of slots, isolated from the two polynomial +transfer arguments. The first argument packages the binary-pencil identity and +the first transfer; the second is the common-power-removal transfer. -/ +theorem vanishing_induction_from_transfer_steps + (firstTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → + ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, + IsSymmetricMultilinearForm (r+1) (r+m) V T → + (∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) → + ∀ x t : V, ∀ y : Fin m → V, + lowerProductForm r m T x t (fun _ => symMonomial m V y) = 0) + (secondTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → + ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, + IsSymmetricMultilinearForm (r+1) (r+m) V T → + (∀ x t : V, ∀ Q : Fin r → SymPow m V, lowerProductForm r m T x t Q = 0) → + ∀ v : Fin (r+1) → V, + T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0) + (purePowerExt : ∀ a b : ℕ, ∀ T : SymmetricMultilinearForm a b V, + (∀ v : Fin a → V, T (fun i => symMonomial b V (fun _ => v i)) = 0) → T = 0) : + ∀ a b : ℕ, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → + ∀ T : SymmetricMultilinearForm a b V, + IsSymmetricMultilinearForm a b V T → + (∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) → T = 0 := by + intro a + induction a with + | zero => + intro b ha + omega + | succ r ih => + intro b ha hb hab T hT hdiag + by_cases hr : r = 0 + · subst r + exact vanishing_on_products_one V b T hdiag + have hrpos : 0 < r := Nat.pos_of_ne_zero hr + have hrb : r ≤ b := by + have hmul : r ≤ (r+1)*r := by nlinarith + simpa only [Nat.succ_eq_add_one, Nat.add_sub_cancel] using hmul.trans hab + obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb + have hbound : (r+1)*r ≤ r+m := by simpa only [Nat.succ_eq_add_one, + Nat.add_sub_cancel] using hab + have hm : 0 < m := by nlinarith + have hmrange : r*(r-1) ≤ m := by + have hsub : r-1 ≤ r := Nat.sub_le .. + have hmul : r*(r-1) ≤ r*r := Nat.mul_le_mul_left r hsub + nlinarith + have hrestricted : ∀ x t : V, lowerProductForm r m T x t = 0 := by + intro x t + exact ih m hrpos hm hmrange (lowerProductForm r m T x t) + (lowerProductForm_symmetric r m T hT x t) + (firstTransfer r m hrpos hm hbound T hT hdiag x t) + apply purePowerExt (r+1) (r+m) T + apply secondTransfer r m hrpos hm hbound T hT + intro x t Q + rw [hrestricted x t] + rfl + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingFirst.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingFirst.lean index 3b107a0b5a748e3c7e47e1391af9b1bbf4ce3cdb..cd8d1b0c0754f1b68913b2f713aaac63e0ef067d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingFirst.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingFirst.lean @@ -1,49 +1,49 @@ -import OAI.RepresentationTheory.FoulkesHowe.Vanishing -import OAI.RepresentationTheory.FoulkesHowe.BinaryVanishing -import OAI.RepresentationTheory.FoulkesHowe.FirstTransfer -import OAI.RepresentationTheory.FoulkesHowe.PowerSpan - -namespace OAI - -noncomputable section - -namespace Problem346 - -universe u -variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -/-- Diagonal vanishing gives the diagonal vanishing of the lower-arity form. -This combines binary splitting, coefficient extraction, and the first transfer. -/ -theorem lowerProductForm_diagonal_zero (r m : ℕ) (hr : 0 < r) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) - (hdiag : ∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) - (x t : V) (y : Fin m → V) : - lowerProductForm r m T x t (fun _ => symMonomial m V y) = 0 := by - exact first_transfer T (binary_diagonal_to_mixed_products r m hr T hT hdiag) x t y - -/-- With the first transfer and pure-power detection established, the common-power -removal transfer is the sole remaining input to the vanishing induction. -/ -theorem vanishing_on_products_of_second_transfer - (secondTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → - ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, - IsSymmetricMultilinearForm (r+1) (r+m) V T → - (∀ x t : V, ∀ Q : Fin r → SymPow m V, lowerProductForm r m T x t Q = 0) → - ∀ v : Fin (r+1) → V, - T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0) : - ∀ a b : ℕ, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → - ∀ T : SymmetricMultilinearForm a b V, - IsSymmetricMultilinearForm a b V T → - (∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) → T = 0 := by - apply vanishing_induction_from_transfer_steps - · intro r m hr _ _ T hT hdiag - exact lowerProductForm_diagonal_zero r m hr T hT hdiag - · exact secondTransfer - · intro a b T hT - exact symmetricMultilinearForm_eq_zero_of_pure_powers a b V T hT - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Vanishing +import OAI.RepresentationTheory.FoulkesHowe.BinaryVanishing +import OAI.RepresentationTheory.FoulkesHowe.FirstTransfer +import OAI.RepresentationTheory.FoulkesHowe.PowerSpan + +namespace OAI + +noncomputable section + +namespace Problem346 + +universe u +variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +/-- Diagonal vanishing gives the diagonal vanishing of the lower-arity form. +This combines binary splitting, coefficient extraction, and the first transfer. -/ +theorem lowerProductForm_diagonal_zero (r m : ℕ) (hr : 0 < r) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) + (hdiag : ∀ y : Fin (r+m) → V, T (fun _ => symMonomial (r+m) V y) = 0) + (x t : V) (y : Fin m → V) : + lowerProductForm r m T x t (fun _ => symMonomial m V y) = 0 := by + exact first_transfer T (binary_diagonal_to_mixed_products r m hr T hT hdiag) x t y + +/-- With the first transfer and pure-power detection established, the common-power +removal transfer is the sole remaining input to the vanishing induction. -/ +theorem vanishing_on_products_of_second_transfer + (secondTransfer : ∀ r m : ℕ, 0 < r → 0 < m → (r+1)*r ≤ r+m → + ∀ T : SymmetricMultilinearForm (r+1) (r+m) V, + IsSymmetricMultilinearForm (r+1) (r+m) V T → + (∀ x t : V, ∀ Q : Fin r → SymPow m V, lowerProductForm r m T x t Q = 0) → + ∀ v : Fin (r+1) → V, + T (fun i => symMonomial (r+m) V (fun _ => v i)) = 0) : + ∀ a b : ℕ, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → + ∀ T : SymmetricMultilinearForm a b V, + IsSymmetricMultilinearForm a b V T → + (∀ y : Fin b → V, T (fun _ => symMonomial b V y) = 0) → T = 0 := by + apply vanishing_induction_from_transfer_steps + · intro r m hr _ _ T hT hdiag + exact lowerProductForm_diagonal_zero r m hr T hT hdiag + · exact secondTransfer + · intro a b T hT + exact symmetricMultilinearForm_eq_zero_of_pure_powers a b V T hT + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingInduction.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingInduction.lean index 809632ac43d5b20a9f906f898417aadea286b4f7..cb076328c3bc665bd93fda862357b684ccdb79ed 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingInduction.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingInduction.lean @@ -1,53 +1,53 @@ -import OAI.RepresentationTheory.FoulkesHowe.Multiplication - -namespace OAI - -noncomputable section -open scoped BigOperators -universe u -namespace Problem346 - -variable {V : Type u} [AddCommGroup V] [Module ℂ V] - -/-- Fixing the first argument and pulling back all other arguments preserves symmetry. -/ -theorem symmetric_form_curry_comp {r b m : ℕ} - (T : SymmetricMultilinearForm (r+1) b V) - (hT : IsSymmetricMultilinearForm (r+1) b V T) - (z : SymPow b V) (L : SymPow m V →ₗ[ℂ] SymPow b V) : - IsSymmetricMultilinearForm r m V ((T.curryLeft z).compLinearMap (fun _ => L)) := by - intro σ x - let τ : Equiv.Perm (Fin (r+1)) := - (finSuccEquiv r).trans ((Equiv.optionCongr σ).trans (finSuccEquiv r).symm) - have heq : (fun i : Fin (r+1) => (Fin.cons z (fun j => L (x j)) : - Fin (r+1) → SymPow b V) (τ i)) = - (Fin.cons z (fun i => L (x (σ i))) : Fin (r+1) → SymPow b V) := by - funext i - cases i using Fin.cases <;> simp [τ] - simpa only [MultilinearMap.compLinearMap_apply, MultilinearMap.curryLeft_apply, heq] - using hT τ (Fin.cons z (fun i => L (x i))) - -/-- The lower-arity form used in the stabilization induction. -/ -def lowerProductForm (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) : - SymmetricMultilinearForm r m V := - (T.curryLeft (symMonomial (r+m) V (fun _ => t))).compLinearMap - (fun _ => symPowMul r m (symMonomial r V (fun _ => x))) - -@[simp] theorem lowerProductForm_apply (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) - (Q : Fin r → SymPow m V) : - lowerProductForm r m T x t Q = - T (Fin.cons (symMonomial (r+m) V (fun _ => t)) - (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) := rfl - -theorem lowerProductForm_symmetric (r m : ℕ) - (T : SymmetricMultilinearForm (r+1) (r+m) V) - (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) (x t : V) : - IsSymmetricMultilinearForm r m V (lowerProductForm r m T x t) := - symmetric_form_curry_comp T hT _ _ - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Multiplication + +namespace OAI + +noncomputable section +open scoped BigOperators +universe u +namespace Problem346 + +variable {V : Type u} [AddCommGroup V] [Module ℂ V] + +/-- Fixing the first argument and pulling back all other arguments preserves symmetry. -/ +theorem symmetric_form_curry_comp {r b m : ℕ} + (T : SymmetricMultilinearForm (r+1) b V) + (hT : IsSymmetricMultilinearForm (r+1) b V T) + (z : SymPow b V) (L : SymPow m V →ₗ[ℂ] SymPow b V) : + IsSymmetricMultilinearForm r m V ((T.curryLeft z).compLinearMap (fun _ => L)) := by + intro σ x + let τ : Equiv.Perm (Fin (r+1)) := + (finSuccEquiv r).trans ((Equiv.optionCongr σ).trans (finSuccEquiv r).symm) + have heq : (fun i : Fin (r+1) => (Fin.cons z (fun j => L (x j)) : + Fin (r+1) → SymPow b V) (τ i)) = + (Fin.cons z (fun i => L (x (σ i))) : Fin (r+1) → SymPow b V) := by + funext i + cases i using Fin.cases <;> simp [τ] + simpa only [MultilinearMap.compLinearMap_apply, MultilinearMap.curryLeft_apply, heq] + using hT τ (Fin.cons z (fun i => L (x i))) + +/-- The lower-arity form used in the stabilization induction. -/ +def lowerProductForm (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) : + SymmetricMultilinearForm r m V := + (T.curryLeft (symMonomial (r+m) V (fun _ => t))).compLinearMap + (fun _ => symPowMul r m (symMonomial r V (fun _ => x))) + +@[simp] theorem lowerProductForm_apply (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) (x t : V) + (Q : Fin r → SymPow m V) : + lowerProductForm r m T x t Q = + T (Fin.cons (symMonomial (r+m) V (fun _ => t)) + (fun i => symPowMul r m (symMonomial r V (fun _ => x)) (Q i))) := rfl + +theorem lowerProductForm_symmetric (r m : ℕ) + (T : SymmetricMultilinearForm (r+1) (r+m) V) + (hT : IsSymmetricMultilinearForm (r+1) (r+m) V T) (x t : V) : + IsSymmetricMultilinearForm r m V (lowerProductForm r m T x t) := + symmetric_form_curry_comp T hT _ _ + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingOne.lean b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingOne.lean index 4e7b8e9599d779f1de2c539d3de03ffcc4a2efa5..2d6ffd54f83fd8dbbb4a88d5475be6ce79378882 100644 --- a/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingOne.lean +++ b/lean/OAI/RepresentationTheory/FoulkesHowe/VanishingOne.lean @@ -1,29 +1,29 @@ -import OAI.RepresentationTheory.FoulkesHowe.Model - -namespace OAI - -noncomputable section -universe u -namespace Problem346 - -theorem vanishing_on_products_one (V : Type u) [AddCommGroup V] [Module ℂ V] - (b : ℕ) (T : SymmetricMultilinearForm 1 b V) - (h : ∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) : T = 0 := by - have hspan : Submodule.span ℂ (Set.range (symMonomial b V)) = ⊤ := by - exact (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule b V) - (fun v => Submodule.subset_span (Set.mem_range_self v))).mpr rfl - apply MultilinearMap.ext_of_span_eq_top (g := fun (_ : Fin 1) => symMonomial b V) - (fun _ => hspan) - intro v - have hv : (fun i : Fin 1 => symMonomial b V (v i)) = - (fun _ : Fin 1 => symMonomial b V (v 0)) := by - funext i - rw [Fin.eq_zero i] - rw [hv] - exact h (v 0) - -end Problem346 - -end - -end OAI +import OAI.RepresentationTheory.FoulkesHowe.Model + +namespace OAI + +noncomputable section +universe u +namespace Problem346 + +theorem vanishing_on_products_one (V : Type u) [AddCommGroup V] [Module ℂ V] + (b : ℕ) (T : SymmetricMultilinearForm 1 b V) + (h : ∀ u : Fin b → V, T (fun _ => symMonomial b V u) = 0) : T = 0 := by + have hspan : Submodule.span ℂ (Set.range (symMonomial b V)) = ⊤ := by + exact (Submodule.span_range_subtype_eq_top_iff (symPowSubmodule b V) + (fun v => Submodule.subset_span (Set.mem_range_self v))).mpr rfl + apply MultilinearMap.ext_of_span_eq_top (g := fun (_ : Fin 1) => symMonomial b V) + (fun _ => hspan) + intro v + have hv : (fun i : Fin 1 => symMonomial b V (v i)) = + (fun _ : Fin 1 => symMonomial b V (v 0)) := by + funext i + rw [Fin.eq_zero i] + rw [hv] + exact h (v 0) + +end Problem346 + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/AlternantExpansion.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/AlternantExpansion.lean index e75465a9b57a54ece9cd239eec48aed99f9b7021..237c95b43a72fb35ba8acd893a276ef328357484 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/AlternantExpansion.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/AlternantExpansion.lean @@ -1,149 +1,149 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.LookupExtraction - -namespace OAI - -noncomputable section - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -lemma sorted_dominance {n : ℕ} (l w : Fin n → ℕ) (hl : Antitone l) - (hw : ∀ j, w j ≤ l j) (j : Fin n) : w (sortDesc w j) ≤ l j := by - classical - by_contra h - let e : Fin (j.val+1) → Fin n := fun c => ⟨c.val, by omega⟩ - have hrow (c : Fin (j.val+1)) : (sortDesc w (e c)).val < j.val := by - by_contra hh - have hw' : w (sortDesc w j) ≤ w (sortDesc w (e c)) := - sortDesc_antitone w (by change c.val ≤ j.val; omega) - have hl' : l (sortDesc w (e c)) ≤ l j := hl (by change j.val ≤ _; omega) - have hc := hw (sortDesc w (e c)) - omega - let f : Fin (j.val+1) → Fin j.val := fun c => ⟨(sortDesc w (e c)).val, hrow c⟩ - have hf : Function.Injective f := by - intro c d hcd - have hv := congrArg (fun z : Fin j.val => z.val) hcd - have hh : sortDesc w (e c) = sortDesc w (e d) := Fin.ext hv - exact Fin.ext (congrArg (fun z : Fin n => z.val) ((sortDesc w).injective hh)) - have hn := Fintype.card_le_of_injective f hf - simp only [Fintype.card_fin] at hn - omega - -theorem previous_partition_le {n : ℕ} (mu : Fin n → ℕ) (hm : Antitone mu) - (i : ℕ) (d : Fin n →₀ ℕ) - (_hn : ∀ j, 0 ≤ (shifted mu j : ℤ) - (i : ℤ)*d j) : - ∀ j, sortedPartition (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d j).toNat) j ≤ mu j := by - intro j - let w := fun j => ((shifted mu j : ℤ) - (i : ℤ)*d j).toNat - have hw : ∀ j, w j ≤ shifted mu j := by - intro j - dsimp [w] - exact Int.toNat_le.mpr (sub_le_self _ (by positivity)) - have hh := sorted_dominance (shifted mu) w (shifted_antitone hm) hw j - change w (sortDesc w j) - staircase n j ≤ mu j - change w (sortDesc w j) ≤ mu j + staircase n j at hh - omega - -lemma shifted_strictAnti {n : ℕ} {mu : Fin n → ℕ} (hm : Antitone mu) : - StrictAnti (shifted mu) := by - intro j k hjk - have hh := hm (le_of_lt hjk) - have hjn := j.isLt - have hkn := k.isLt - change mu k + (n-1-k.val) < mu j + (n-1-j.val) - change j.val < k.val at hjk - omega - -lemma eq_of_strict_coefficients {n : ℕ} {p q : MvPolynomial (Fin n) ℤ} - (hp : Alternating p) (hq : Alternating q) - (h : ∀ v : Fin n → ℕ, StrictAnti v → p.coeff (expVector v) = q.coeff (expVector v)) : p = q := by - classical - ext d - let v : Fin n → ℕ := fun j => d j - have hd : expVector v = d := by ext j; rfl - rw [← hd] - by_cases hv : Function.Injective v - · rw [coeff_eq_sign_mul_comp hp v (sortDesc v), coeff_eq_sign_mul_comp hq v (sortDesc v), - h (v ∘ sortDesc v) (sortDesc_strict v hv)] - · obtain ⟨j,k,hjk,he⟩ : ∃ j k, j ≠ k ∧ v j = v k := by - simpa only [Function.Injective, not_forall, exists_prop, Classical.not_imp, ne_eq, - and_comm] using hv - rw [coeff_repeated hp v hjk he, coeff_repeated hq v hjk he] - -lemma coeff_alternant_strict {n : ℕ} (m v : Fin n → ℕ) - (hm : StrictAnti m) (hv : StrictAnti v) : - (alternant m).coeff (expVector v) = if m = v then 1 else 0 := by - classical - have hper (σ : Equiv.Perm (Fin n)) : - expVector (m ∘ σ.symm) = expVector v ↔ m = v ∧ σ = 1 := by - constructor - · intro he - have he' : m ∘ σ.symm = v := Finsupp.equivFunOnFinite.symm.injective he - have hs : m ∘ σ.symm = m := Tuple.unique_antitone - (he'.symm ▸ hv.antitone) (show Antitone (m ∘ (1 : Equiv.Perm (Fin n))) from hm.antitone) - have hid : σ.symm = 1 := by - apply Equiv.ext - intro j - exact hm.injective (congrFun hs j) - have hσ : σ = 1 := by - change σ⁻¹ = 1 at hid - exact inv_eq_one.mp hid - exact ⟨hs.symm.trans he',hσ⟩ - · rintro ⟨rfl,rfl⟩; rfl - have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), - Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := - Matrix.det_apply _ - rw [ha, coeff_sum] - simp_rw [coeff_smul, perm_prod_monomial] - change (∑ σ : Equiv.Perm (Fin n), (Equiv.Perm.sign σ) • - (monomial (expVector (m ∘ σ.symm)) (1 : ℤ)).coeff (expVector v)) = _ - simp_rw [coeff_monomial, hper] - by_cases he : m = v - · simp [he] - · simp [he] - -lemma alternating_sum {α : Type*} {n : ℕ} (s : Finset α) - (p : α → MvPolynomial (Fin n) ℤ) (hp : ∀ a ∈ s, Alternating (p a)) : - Alternating (∑ a ∈ s, p a) := by - intro σ - simp only [map_sum, Finset.smul_sum] - exact Finset.sum_congr rfl (fun a ha => hp a ha σ) - -lemma alternating_smul {n : ℕ} (z : ℤ) {p : MvPolynomial (Fin n) ℤ} - (hp : Alternating p) : Alternating (z • p) := by - intro σ - rw [map_smul, hp σ, smul_comm] - -theorem alternant_expansion {n : ℕ} (p : MvPolynomial (Fin n) ℤ) (hp : Alternating p) : - p = ∑ d ∈ p.support.filter (fun d => StrictAnti (fun j => d j)), - p.coeff d • alternant (fun j => d j) := by - classical - let s := p.support.filter (fun d => StrictAnti (fun j => d j)) - apply eq_of_strict_coefficients hp - (alternating_sum s _ (fun _ _ => alternating_smul _ (alternant_alternating _))) - intro v hv - rw [coeff_sum] - have hd (d : Fin n →₀ ℕ) (hd : d ∈ s) : - (p.coeff d • alternant (fun j => d j)).coeff (expVector v) = - if d = expVector v then p.coeff d else 0 := by - rw [coeff_smul, coeff_alternant_strict _ _ (mem_filter.mp hd).2 hv] - have he : (fun j => d j) = v ↔ d = expVector v := by - constructor - · intro h; ext j; exact congrFun h j - · intro h; subst d; rfl - simp [he] - change p.coeff (expVector v) = ∑ d ∈ s, _ - rw [Finset.sum_congr rfl hd] - by_cases hmem : expVector v ∈ s - · simp [hmem] - · have hc : p.coeff (expVector v) = 0 := by - have hh : expVector v ∉ p.support := fun hh => hmem (by exact mem_filter.mpr ⟨hh,hv⟩) - exact notMem_support_iff.mp hh - simp [hmem,hc] - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.LookupExtraction + +namespace OAI + +noncomputable section + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +lemma sorted_dominance {n : ℕ} (l w : Fin n → ℕ) (hl : Antitone l) + (hw : ∀ j, w j ≤ l j) (j : Fin n) : w (sortDesc w j) ≤ l j := by + classical + by_contra h + let e : Fin (j.val+1) → Fin n := fun c => ⟨c.val, by omega⟩ + have hrow (c : Fin (j.val+1)) : (sortDesc w (e c)).val < j.val := by + by_contra hh + have hw' : w (sortDesc w j) ≤ w (sortDesc w (e c)) := + sortDesc_antitone w (by change c.val ≤ j.val; omega) + have hl' : l (sortDesc w (e c)) ≤ l j := hl (by change j.val ≤ _; omega) + have hc := hw (sortDesc w (e c)) + omega + let f : Fin (j.val+1) → Fin j.val := fun c => ⟨(sortDesc w (e c)).val, hrow c⟩ + have hf : Function.Injective f := by + intro c d hcd + have hv := congrArg (fun z : Fin j.val => z.val) hcd + have hh : sortDesc w (e c) = sortDesc w (e d) := Fin.ext hv + exact Fin.ext (congrArg (fun z : Fin n => z.val) ((sortDesc w).injective hh)) + have hn := Fintype.card_le_of_injective f hf + simp only [Fintype.card_fin] at hn + omega + +theorem previous_partition_le {n : ℕ} (mu : Fin n → ℕ) (hm : Antitone mu) + (i : ℕ) (d : Fin n →₀ ℕ) + (_hn : ∀ j, 0 ≤ (shifted mu j : ℤ) - (i : ℤ)*d j) : + ∀ j, sortedPartition (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d j).toNat) j ≤ mu j := by + intro j + let w := fun j => ((shifted mu j : ℤ) - (i : ℤ)*d j).toNat + have hw : ∀ j, w j ≤ shifted mu j := by + intro j + dsimp [w] + exact Int.toNat_le.mpr (sub_le_self _ (by positivity)) + have hh := sorted_dominance (shifted mu) w (shifted_antitone hm) hw j + change w (sortDesc w j) - staircase n j ≤ mu j + change w (sortDesc w j) ≤ mu j + staircase n j at hh + omega + +lemma shifted_strictAnti {n : ℕ} {mu : Fin n → ℕ} (hm : Antitone mu) : + StrictAnti (shifted mu) := by + intro j k hjk + have hh := hm (le_of_lt hjk) + have hjn := j.isLt + have hkn := k.isLt + change mu k + (n-1-k.val) < mu j + (n-1-j.val) + change j.val < k.val at hjk + omega + +lemma eq_of_strict_coefficients {n : ℕ} {p q : MvPolynomial (Fin n) ℤ} + (hp : Alternating p) (hq : Alternating q) + (h : ∀ v : Fin n → ℕ, StrictAnti v → p.coeff (expVector v) = q.coeff (expVector v)) : p = q := by + classical + ext d + let v : Fin n → ℕ := fun j => d j + have hd : expVector v = d := by ext j; rfl + rw [← hd] + by_cases hv : Function.Injective v + · rw [coeff_eq_sign_mul_comp hp v (sortDesc v), coeff_eq_sign_mul_comp hq v (sortDesc v), + h (v ∘ sortDesc v) (sortDesc_strict v hv)] + · obtain ⟨j,k,hjk,he⟩ : ∃ j k, j ≠ k ∧ v j = v k := by + simpa only [Function.Injective, not_forall, exists_prop, Classical.not_imp, ne_eq, + and_comm] using hv + rw [coeff_repeated hp v hjk he, coeff_repeated hq v hjk he] + +lemma coeff_alternant_strict {n : ℕ} (m v : Fin n → ℕ) + (hm : StrictAnti m) (hv : StrictAnti v) : + (alternant m).coeff (expVector v) = if m = v then 1 else 0 := by + classical + have hper (σ : Equiv.Perm (Fin n)) : + expVector (m ∘ σ.symm) = expVector v ↔ m = v ∧ σ = 1 := by + constructor + · intro he + have he' : m ∘ σ.symm = v := Finsupp.equivFunOnFinite.symm.injective he + have hs : m ∘ σ.symm = m := Tuple.unique_antitone + (he'.symm ▸ hv.antitone) (show Antitone (m ∘ (1 : Equiv.Perm (Fin n))) from hm.antitone) + have hid : σ.symm = 1 := by + apply Equiv.ext + intro j + exact hm.injective (congrFun hs j) + have hσ : σ = 1 := by + change σ⁻¹ = 1 at hid + exact inv_eq_one.mp hid + exact ⟨hs.symm.trans he',hσ⟩ + · rintro ⟨rfl,rfl⟩; rfl + have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), + Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := + Matrix.det_apply _ + rw [ha, coeff_sum] + simp_rw [coeff_smul, perm_prod_monomial] + change (∑ σ : Equiv.Perm (Fin n), (Equiv.Perm.sign σ) • + (monomial (expVector (m ∘ σ.symm)) (1 : ℤ)).coeff (expVector v)) = _ + simp_rw [coeff_monomial, hper] + by_cases he : m = v + · simp [he] + · simp [he] + +lemma alternating_sum {α : Type*} {n : ℕ} (s : Finset α) + (p : α → MvPolynomial (Fin n) ℤ) (hp : ∀ a ∈ s, Alternating (p a)) : + Alternating (∑ a ∈ s, p a) := by + intro σ + simp only [map_sum, Finset.smul_sum] + exact Finset.sum_congr rfl (fun a ha => hp a ha σ) + +lemma alternating_smul {n : ℕ} (z : ℤ) {p : MvPolynomial (Fin n) ℤ} + (hp : Alternating p) : Alternating (z • p) := by + intro σ + rw [map_smul, hp σ, smul_comm] + +theorem alternant_expansion {n : ℕ} (p : MvPolynomial (Fin n) ℤ) (hp : Alternating p) : + p = ∑ d ∈ p.support.filter (fun d => StrictAnti (fun j => d j)), + p.coeff d • alternant (fun j => d j) := by + classical + let s := p.support.filter (fun d => StrictAnti (fun j => d j)) + apply eq_of_strict_coefficients hp + (alternating_sum s _ (fun _ _ => alternating_smul _ (alternant_alternating _))) + intro v hv + rw [coeff_sum] + have hd (d : Fin n →₀ ℕ) (hd : d ∈ s) : + (p.coeff d • alternant (fun j => d j)).coeff (expVector v) = + if d = expVector v then p.coeff d else 0 := by + rw [coeff_smul, coeff_alternant_strict _ _ (mem_filter.mp hd).2 hv] + have he : (fun j => d j) = v ↔ d = expVector v := by + constructor + · intro h; ext j; exact congrFun h j + · intro h; subst d; rfl + simp [he] + change p.coeff (expVector v) = ∑ d ∈ s, _ + rw [Finset.sum_congr rfl hd] + by_cases hmem : expVector v ∈ s + · simp [hmem] + · have hc : p.coeff (expVector v) = 0 := by + have hh : expVector v ∉ p.support := fun hh => hmem (by exact mem_filter.mpr ⟨hh,hv⟩) + exact notMem_support_iff.mp hh + simp [hmem,hc] + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/BlockInjection.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/BlockInjection.lean index 8eb1f4898843bc9b73b7650cfe7d4fefa5e39146..5b09770c876e0939bd7f38bb1508f2d64a1314a9 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/BlockInjection.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/BlockInjection.lean @@ -1,78 +1,78 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.QuadraticInjection -import OAI.RepresentationTheory.FoulkesSixth.BlockVanishing - -namespace OAI - -noncomputable section - -namespace Foulkes.Canonical -universe u -open Module MvPolynomial SymmetricTensor Polarization -variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] -variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) -theorem productPolynomial_range_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : - (productPolynomial B a b).range = R a n b := by - classical - apply le_antisymm - · rintro _ ⟨x, rfl⟩ - exact productPolynomial_mem B a b x - · intro p hp - by_contra hnot - obtain ⟨l, hlp, hlrange⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance - have hkill (f : P a n) (hf : f ∈ (productPolynomial B a b).range) : l f = 0 := by - have hh : l f ∈ ((productPolynomial B a b).range).map l := Submodule.mem_map.mpr ⟨f,hf,rfl⟩ - rwa [hlrange, Submodule.mem_bot] at hh - let lav := l.comp (Polarization.average a n) - have hs : Vanishing.Symmetric lav := by - intro σ f - change l (Polarization.average a n (renameRow σ f)) = l (Polarization.average a n f) - rw [Vanishing.average_renameRow] - have hz : Vanishing.ProductsVanish lav b := by - intro y - change l (Polarization.average a n (∏ j, z (y j))) = 0 - rw [Polarization.average_eq (show (∏ j, z (a := a) (y j)) ∈ rowInvariants a n from by - intro σ; simp)] - exact hkill _ (products_in_range B a b y) - have hh := Vanishing.block_vanishing a ha hb hs hz p hp.1 - change l (Polarization.average a n p) = 0 at hh - rw [Polarization.average_eq hp.2] at hh - exact hlp hh - -theorem surjective_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : - Function.Surjective (map B a b) := by - intro x - have hp : Rows.invariantMap B a b x ∈ (productPolynomial B a b).range := by - rw [productPolynomial_range_block B a b ha hb] - exact (Rows.equiv B a b x).property - obtain ⟨y, hy⟩ := hp - refine ⟨y, (Rows.invariantMap_injective B a b) ?_⟩ - rw [map_polynomial, hy] - -end Foulkes.Canonical - -namespace Foulkes.Injection -universe u -open Module -variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -lemma injective_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : - Function.Injective (map a b V) := - (PlethDual.flipEquiv b a V).symm.injective.comp - ((LinearMap.dualMap_injective_of_surjective - (Canonical.surjective_block (Module.finBasis ℂ (Dual ℂ V)) a b ha hb)).comp - (PlethDual.flipEquiv a b V).injective) - -theorem sixth_from_25 (b : ℕ) (hb : 25 ≤ b) - (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : - ∃ i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V), Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), - i (symMap 6 (symMap b g.toLinearMap) x) = symMap b (symMap 6 g.toLinearMap) (i x) := - ⟨map 6 b V, injective_block 6 b V (by omega) (by simpa using hb), - fun g x => natural 6 b V g.toLinearMap x⟩ - -end Foulkes.Injection - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.QuadraticInjection +import OAI.RepresentationTheory.FoulkesSixth.BlockVanishing + +namespace OAI + +noncomputable section + +namespace Foulkes.Canonical +universe u +open Module MvPolynomial SymmetricTensor Polarization +variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] +variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) +theorem productPolynomial_range_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : + (productPolynomial B a b).range = R a n b := by + classical + apply le_antisymm + · rintro _ ⟨x, rfl⟩ + exact productPolynomial_mem B a b x + · intro p hp + by_contra hnot + obtain ⟨l, hlp, hlrange⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance + have hkill (f : P a n) (hf : f ∈ (productPolynomial B a b).range) : l f = 0 := by + have hh : l f ∈ ((productPolynomial B a b).range).map l := Submodule.mem_map.mpr ⟨f,hf,rfl⟩ + rwa [hlrange, Submodule.mem_bot] at hh + let lav := l.comp (Polarization.average a n) + have hs : Vanishing.Symmetric lav := by + intro σ f + change l (Polarization.average a n (renameRow σ f)) = l (Polarization.average a n f) + rw [Vanishing.average_renameRow] + have hz : Vanishing.ProductsVanish lav b := by + intro y + change l (Polarization.average a n (∏ j, z (y j))) = 0 + rw [Polarization.average_eq (show (∏ j, z (a := a) (y j)) ∈ rowInvariants a n from by + intro σ; simp)] + exact hkill _ (products_in_range B a b y) + have hh := Vanishing.block_vanishing a ha hb hs hz p hp.1 + change l (Polarization.average a n p) = 0 at hh + rw [Polarization.average_eq hp.2] at hh + exact hlp hh + +theorem surjective_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : + Function.Surjective (map B a b) := by + intro x + have hp : Rows.invariantMap B a b x ∈ (productPolynomial B a b).range := by + rw [productPolynomial_range_block B a b ha hb] + exact (Rows.equiv B a b x).property + obtain ⟨y, hy⟩ := hp + refine ⟨y, (Rows.invariantMap_injective B a b) ?_⟩ + rw [map_polynomial, hy] + +end Foulkes.Canonical + +namespace Foulkes.Injection +universe u +open Module +variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +lemma injective_block (ha : 1 ≤ a) (hb : (a-1)^2 ≤ b) : + Function.Injective (map a b V) := + (PlethDual.flipEquiv b a V).symm.injective.comp + ((LinearMap.dualMap_injective_of_surjective + (Canonical.surjective_block (Module.finBasis ℂ (Dual ℂ V)) a b ha hb)).comp + (PlethDual.flipEquiv a b V).injective) + +theorem sixth_from_25 (b : ℕ) (hb : 25 ≤ b) + (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : + ∃ i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V), Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), + i (symMap 6 (symMap b g.toLinearMap) x) = symMap b (symMap 6 g.toLinearMap) (i x) := + ⟨map 6 b V, injective_block 6 b V (by omega) (by simpa using hb), + fun g x => natural 6 b V g.toLinearMap x⟩ + +end Foulkes.Injection + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/BlockVanishing.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/BlockVanishing.lean index 73be636e329c9f5cf44bed5467bec898c6a415f6..0c72e1c70fc8050910227618989c2657d682db24 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/BlockVanishing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/BlockVanishing.lean @@ -1,64 +1,64 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.Vanishing - -namespace OAI - -noncomputable section - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan - -lemma vanishing_zero {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hz : ProductsVanish l 0) - {f : P a n} (hf : f ∈ W a n 0) : l f = 0 := by - have h1 : l 1 = 0 := by simpa using hz (fun i => Fin.elim0 i) - have hW : W a n 0 ≤ LinearMap.ker l := by - rw [W_eq_span_pureRows] - apply Submodule.span_le.mpr - rintro _ ⟨v, rfl⟩ - simpa [pureRows] using h1 - exact hW hf - -theorem block_vanishing (a : ℕ) : ∀ {n b : ℕ}, 1 ≤ a → (a-1)^2 ≤ b → - ∀ {l : P a n →ₗ[ℂ] ℂ}, Symmetric l → ProductsVanish l b → - ∀ f : P a n, f ∈ W a n b → l f = 0 := by - induction a with - | zero => intro n b ha; omega - | succ r ih => - intro n b ha hb l hs hz f hf - have hpure : ∀ v : Fin (r+1) → Fin n → ℂ, l (pureRows b v) = 0 := by - intro v - by_cases hr : r = 0 - · subst r - have hh := hz (fun _ => v 0) - simpa [pureRows, z, Fin.prod_univ_one] using hh - · have hrpos : 0 < r := Nat.pos_of_ne_zero hr - have hrb : r ≤ b := by - simp only [Nat.add_sub_cancel] at hb - nlinarith - obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb - have hb' : r*r ≤ r+m := by simpa [pow_two] using hb - have hrestrict (x t : Fin n → ℂ) (g : P r n) (hg : g ∈ W r n m) : - restrictionFunctional l x t (r+m) g = 0 := by - by_cases hm : m = 0 - · subst m - exact vanishing_zero (restriction_products hrpos hs hz x t) hg - · apply ih (by omega) ?_ (restriction_symmetric hs x t) - (restriction_products hrpos hs hz x t) g hg - have he : (r-1)+1 = r := by omega - nlinarith - have hh := remove_common_power hb' - (v (Fin.last r)) (fun x g hg => hrestrict x (v (Fin.last r)) g hg) - (fun i => v i.castSucc) - simpa only [pureRows, Fin.prod_univ_castSucc] using hh - have hW : W (r+1) n b ≤ LinearMap.ker l := by - rw [W_eq_span_pureRows] - apply Submodule.span_le.mpr - rintro _ ⟨v,rfl⟩ - exact hpure v - exact hW hf - -end Foulkes.Vanishing - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.Vanishing + +namespace OAI + +noncomputable section + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan + +lemma vanishing_zero {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hz : ProductsVanish l 0) + {f : P a n} (hf : f ∈ W a n 0) : l f = 0 := by + have h1 : l 1 = 0 := by simpa using hz (fun i => Fin.elim0 i) + have hW : W a n 0 ≤ LinearMap.ker l := by + rw [W_eq_span_pureRows] + apply Submodule.span_le.mpr + rintro _ ⟨v, rfl⟩ + simpa [pureRows] using h1 + exact hW hf + +theorem block_vanishing (a : ℕ) : ∀ {n b : ℕ}, 1 ≤ a → (a-1)^2 ≤ b → + ∀ {l : P a n →ₗ[ℂ] ℂ}, Symmetric l → ProductsVanish l b → + ∀ f : P a n, f ∈ W a n b → l f = 0 := by + induction a with + | zero => intro n b ha; omega + | succ r ih => + intro n b ha hb l hs hz f hf + have hpure : ∀ v : Fin (r+1) → Fin n → ℂ, l (pureRows b v) = 0 := by + intro v + by_cases hr : r = 0 + · subst r + have hh := hz (fun _ => v 0) + simpa [pureRows, z, Fin.prod_univ_one] using hh + · have hrpos : 0 < r := Nat.pos_of_ne_zero hr + have hrb : r ≤ b := by + simp only [Nat.add_sub_cancel] at hb + nlinarith + obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb + have hb' : r*r ≤ r+m := by simpa [pow_two] using hb + have hrestrict (x t : Fin n → ℂ) (g : P r n) (hg : g ∈ W r n m) : + restrictionFunctional l x t (r+m) g = 0 := by + by_cases hm : m = 0 + · subst m + exact vanishing_zero (restriction_products hrpos hs hz x t) hg + · apply ih (by omega) ?_ (restriction_symmetric hs x t) + (restriction_products hrpos hs hz x t) g hg + have he : (r-1)+1 = r := by omega + nlinarith + have hh := remove_common_power hb' + (v (Fin.last r)) (fun x g hg => hrestrict x (v (Fin.last r)) g hg) + (fun i => v i.castSucc) + simpa only [pureRows, Fin.prod_univ_castSucc] using hh + have hW : W (r+1) n b ≤ LinearMap.ker l := by + rw [W_eq_span_pureRows] + apply Submodule.span_le.mpr + rintro _ ⟨v,rfl⟩ + exact hpure v + exact hW hf + +end Foulkes.Vanishing + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Collision.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Collision.lean index 50dd39d09f78570cb335816bd395f2f84a852605..ee6ea4ec767f4172419012a6afd0198e93fcaa62 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Collision.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Collision.lean @@ -1,105 +1,105 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Collision -open Finset -open scoped Classical -variable {A B α : Type*} [CommRing A] [CommRing B] [Algebra ℂ A] [Algebra ℂ B] - [Fintype α] - -def distinctSum (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) : B := - ∑ e : Fin h ↪ α, ∏ j : Fin h, φ (e j) (q j) - -omit [Fintype α] in -lemma prod_update (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) - (q₀ : A) (e : Fin h ↪ α) (r : Fin h) : - (∏ j : Fin h, φ (e j) (Function.update q r (q₀ * q r) j)) = - φ (e r) q₀ * ∏ j : Fin h, φ (e j) (q j) := by - classical - have heq (j : Fin h) : φ (e j) (Function.update q r (q₀ * q r) j) = - (if j = r then φ (e j) q₀ else 1) * φ (e j) (q j) := by - by_cases hj : j = r - · subst j; simp - · simp [hj] - simp_rw [heq] - rw [Finset.prod_mul_distrib] - simp - -lemma distinctSum_cons (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) (q₀ : A) : - distinctSum φ (Fin.cons q₀ q) = - ∑ e : Fin h ↪ α, ∑ i : {i // i ∉ Set.range e}, - φ i q₀ * ∏ j : Fin h, φ (e j) (q j) := by - classical - rw [distinctSum, ← Equiv.sum_comp (Equiv.embeddingFinSucc h α).symm, - Fintype.sum_sigma] - apply Finset.sum_congr rfl - intro e _ - apply Finset.sum_congr rfl - intro i _ - simp [Equiv.coe_embeddingFinSucc_symm, Fin.prod_univ_succ] - -lemma recurrence (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) (q₀ : A) : - distinctSum φ (Fin.cons q₀ q) = - (∑ i : α, φ i q₀) * distinctSum φ q - - ∑ r : Fin h, distinctSum φ (Function.update q r (q₀ * q r)) := by - classical - have hsplit (e : Fin h ↪ α) : - (∑ i : α, φ i q₀) = - (∑ i : {i // i ∉ Set.range e}, φ i q₀) + ∑ r : Fin h, φ (e r) q₀ := by - have hh := Fintype.sum_subtype_add_sum_subtype (fun i : α => i ∉ Set.range e) - (fun i => φ i q₀) - rw [← hh] - congr 1 - calc - _ = ∑ i : Set.range e, φ i q₀ := - Equiv.sum_comp (Equiv.subtypeEquivRight (fun _ => not_not)) - (fun i : Set.range e => φ i q₀) - _ = _ := (Equiv.sum_comp (Equiv.ofInjective e e.injective) - (fun i : Set.range e => φ i q₀)).symm - rw [eq_sub_iff_add_eq, distinctSum_cons] - simp only [distinctSum, prod_update] - rw [Finset.sum_comm (f := fun (r : Fin h) (e : Fin h ↪ α) => - φ (e r) q₀ * ∏ j : Fin h, φ (e j) (q j)), ← Finset.sum_add_distrib, - Finset.mul_sum] - apply Finset.sum_congr rfl - intro e _ - rw [hsplit e, add_mul, Finset.sum_mul, Finset.sum_mul] - -end Foulkes.Collision - - -noncomputable section - -open scoped Classical - -example : ((Tuple.sort (α := ℕᵒᵈ) ![1,7,4]) 0).val = 1 := by - rw [← show Equiv.swap (0 : Fin 3) 2 * Equiv.swap 0 1 = - Tuple.sort (α := ℕᵒᵈ) ![1,7,4] from Tuple.eq_sort_iff.mpr (by decide +kernel)] - rfl -example : (Equiv.Perm.sign (Tuple.sort (α := ℕᵒᵈ) ![1,7,4]) : ℤ) = 1 := by - rw [← show Equiv.swap (0 : Fin 3) 2 * Equiv.swap 0 1 = - Tuple.sort (α := ℕᵒᵈ) ![1,7,4] from Tuple.eq_sort_iff.mpr (by decide +kernel)] - norm_num [map_mul, Equiv.Perm.sign_swap] - - -noncomputable section - -example (i b : ℕ) : i ∈ List.range' 1 b ↔ 1 ≤ i ∧ i ≤ b := by - simp only [List.mem_range', Nat.one_mul] - constructor - · rintro ⟨index, hindex, rfl⟩ - omega - · rintro ⟨hlower, hupper⟩ - exact ⟨i - 1, by omega, by omega⟩ -example {B : Type*} [Fintype B] (nu : B → ℕ) (b : B) : - (Finsupp.equivFunOnFinite.symm nu) b = nu b := by - rfl - -end -end -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Collision +open Finset +open scoped Classical +variable {A B α : Type*} [CommRing A] [CommRing B] [Algebra ℂ A] [Algebra ℂ B] + [Fintype α] + +def distinctSum (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) : B := + ∑ e : Fin h ↪ α, ∏ j : Fin h, φ (e j) (q j) + +omit [Fintype α] in +lemma prod_update (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) + (q₀ : A) (e : Fin h ↪ α) (r : Fin h) : + (∏ j : Fin h, φ (e j) (Function.update q r (q₀ * q r) j)) = + φ (e r) q₀ * ∏ j : Fin h, φ (e j) (q j) := by + classical + have heq (j : Fin h) : φ (e j) (Function.update q r (q₀ * q r) j) = + (if j = r then φ (e j) q₀ else 1) * φ (e j) (q j) := by + by_cases hj : j = r + · subst j; simp + · simp [hj] + simp_rw [heq] + rw [Finset.prod_mul_distrib] + simp + +lemma distinctSum_cons (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) (q₀ : A) : + distinctSum φ (Fin.cons q₀ q) = + ∑ e : Fin h ↪ α, ∑ i : {i // i ∉ Set.range e}, + φ i q₀ * ∏ j : Fin h, φ (e j) (q j) := by + classical + rw [distinctSum, ← Equiv.sum_comp (Equiv.embeddingFinSucc h α).symm, + Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro e _ + apply Finset.sum_congr rfl + intro i _ + simp [Equiv.coe_embeddingFinSucc_symm, Fin.prod_univ_succ] + +lemma recurrence (φ : α → A →ₐ[ℂ] B) {h : ℕ} (q : Fin h → A) (q₀ : A) : + distinctSum φ (Fin.cons q₀ q) = + (∑ i : α, φ i q₀) * distinctSum φ q - + ∑ r : Fin h, distinctSum φ (Function.update q r (q₀ * q r)) := by + classical + have hsplit (e : Fin h ↪ α) : + (∑ i : α, φ i q₀) = + (∑ i : {i // i ∉ Set.range e}, φ i q₀) + ∑ r : Fin h, φ (e r) q₀ := by + have hh := Fintype.sum_subtype_add_sum_subtype (fun i : α => i ∉ Set.range e) + (fun i => φ i q₀) + rw [← hh] + congr 1 + calc + _ = ∑ i : Set.range e, φ i q₀ := + Equiv.sum_comp (Equiv.subtypeEquivRight (fun _ => not_not)) + (fun i : Set.range e => φ i q₀) + _ = _ := (Equiv.sum_comp (Equiv.ofInjective e e.injective) + (fun i : Set.range e => φ i q₀)).symm + rw [eq_sub_iff_add_eq, distinctSum_cons] + simp only [distinctSum, prod_update] + rw [Finset.sum_comm (f := fun (r : Fin h) (e : Fin h ↪ α) => + φ (e r) q₀ * ∏ j : Fin h, φ (e j) (q j)), ← Finset.sum_add_distrib, + Finset.mul_sum] + apply Finset.sum_congr rfl + intro e _ + rw [hsplit e, add_mul, Finset.sum_mul, Finset.sum_mul] + +end Foulkes.Collision + + +noncomputable section + +open scoped Classical + +example : ((Tuple.sort (α := ℕᵒᵈ) ![1,7,4]) 0).val = 1 := by + rw [← show Equiv.swap (0 : Fin 3) 2 * Equiv.swap 0 1 = + Tuple.sort (α := ℕᵒᵈ) ![1,7,4] from Tuple.eq_sort_iff.mpr (by decide +kernel)] + rfl +example : (Equiv.Perm.sign (Tuple.sort (α := ℕᵒᵈ) ![1,7,4]) : ℤ) = 1 := by + rw [← show Equiv.swap (0 : Fin 3) 2 * Equiv.swap 0 1 = + Tuple.sort (α := ℕᵒᵈ) ![1,7,4] from Tuple.eq_sort_iff.mpr (by decide +kernel)] + norm_num [map_mul, Equiv.Perm.sign_swap] + + +noncomputable section + +example (i b : ℕ) : i ∈ List.range' 1 b ↔ 1 ≤ i ∧ i ≤ b := by + simp only [List.mem_range', Nat.one_mul] + constructor + · rintro ⟨index, hindex, rfl⟩ + omega + · rintro ⟨hlower, hupper⟩ + exact ⟨i - 1, by omega, by omega⟩ +example {B : Type*} [Fintype B] (nu : B → ℕ) (b : B) : + (Finsupp.equivFunOnFinite.symm nu) b = nu b := by + rfl + +end +end +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/ColorOrbits.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/ColorOrbits.lean index cb5845d6ee5afc586e7699cff557c64624264eaa..03de4afabb3bd9128adcdb51084e1b30932cf64a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/ColorOrbits.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/ColorOrbits.lean @@ -1,193 +1,193 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.YoungModules - -namespace OAI - -noncomputable section - -namespace Foulkes.Young -open Finset - -section Counts -variable {D A B : Type*} [Fintype D] [Fintype A] [Fintype B] - -def counts (f : D → A) (a : A) : ℕ := Nat.card {i // f i = a} - -omit [Fintype D] [Fintype A] in -lemma counts_reindex (f : D → A) (σ : Equiv.Perm D) : counts (f ∘ σ) = counts f := by - funext a - exact Nat.card_congr (Equiv.subtypeEquiv σ (fun i => Iff.rfl)) - -omit [Fintype A] in -lemma exists_perm_of_counts_eq (f g : D → A) (h : counts f = counts g) : - ∃ σ : Equiv.Perm D, f ∘ σ = g := by - classical - let e (a : A) : {i // g i = a} ≃ {i // f i = a} := - Fintype.equivOfCardEq (by simpa [counts, Nat.card_eq_fintype_card] using (congrFun h a).symm) - let σ : Equiv.Perm D := (Equiv.sigmaFiberEquiv g).symm.trans - ((Equiv.sigmaCongrRight e).trans (Equiv.sigmaFiberEquiv f)) - refine ⟨σ, ?_⟩ - funext i - exact (e (g i) ⟨i,rfl⟩).property - -lemma counts_total (f : D → A) : ∑ a, counts f a = Fintype.card D := by - classical - simp only [counts, Nat.card_eq_fintype_card] - rw [← Fintype.card_sigma] - exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) - -omit [Fintype A] in -lemma counts_pair_fst (f : D → A) (g : D → B) (a : A) : - ∑ b, counts (fun i => (f i,g i)) (a,b) = counts f a := by - classical - let he (b : B) : {z : {i // f i = a} // g z.val = b} ≃ - {i // (f i,g i) = (a,b)} := { - toFun z := ⟨z.val.val, Prod.ext z.val.property z.property⟩ - invFun z := ⟨⟨z.val, congrArg Prod.fst z.property⟩, congrArg Prod.snd z.property⟩ - left_inv z := rfl - right_inv z := rfl } - have hh := counts_total (fun z : {i // f i = a} => g z.val) - simp only [counts, Nat.card_eq_fintype_card] at hh ⊢ - rw [← hh] - exact Finset.sum_congr rfl (fun b hb => (Fintype.card_congr (he b)).symm) - -omit [Fintype B] in -lemma counts_pair_snd (f : D → A) (g : D → B) (b : B) : - ∑ a, counts (fun i => (f i,g i)) (a,b) = counts g b := by - classical - let he (a : A) : {z : {i // g i = b} // f z.val = a} ≃ - {i // (f i,g i) = (a,b)} := { - toFun z := ⟨z.val.val, Prod.ext z.property z.val.property⟩ - invFun z := ⟨⟨z.val, congrArg Prod.snd z.property⟩, congrArg Prod.fst z.property⟩ - left_inv z := rfl - right_inv z := rfl } - have hh := counts_total (fun z : {i // g i = b} => f z.val) - simp only [counts, Nat.card_eq_fintype_card] at hh ⊢ - rw [← hh] - exact Finset.sum_congr rfl (fun a ha => (Fintype.card_congr (he a)).symm) - -lemma exists_coloring (mu : A → ℕ) (hmu : ∑ a, mu a = Fintype.card D) : - ∃ f : D → A, counts f = mu := by - classical - let e : D ≃ (Σ a, Fin (mu a)) := Fintype.equivOfCardEq (by simp [hmu]) - let f : D → A := fun i => (e i).1 - let ea (a : A) : {t : (Σ a, Fin (mu a)) // t.1 = a} ≃ Fin (mu a) := { - toFun t := t.property ▸ t.val.2 - invFun j := ⟨⟨a,j⟩,rfl⟩ - left_inv t := by rcases t with ⟨⟨b,j⟩,h⟩; dsimp at h; subst b; rfl - right_inv j := rfl } - refine ⟨f, funext fun a => ?_⟩ - have hcard := Nat.card_congr ((Equiv.subtypeEquiv e (fun i => Iff.rfl)).trans (ea a)) - simpa [counts, f] using hcard - -end Counts - -def Coloring (D A : Type*) [Fintype D] (mu : A → ℕ) := - {f : D → A // counts f = mu} - -instance {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) : - Fintype (Coloring D A mu) := by - classical - unfold Coloring - infer_instance - -instance coloringAction {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) : - MulAction (Equiv.Perm D) (Coloring D A mu) where - smul σ f := ⟨f.val ∘ σ.symm, (counts_reindex f.val σ.symm).trans f.property⟩ - one_smul f := by apply Subtype.ext; rfl - mul_smul σ τ f := by apply Subtype.ext; rfl - -@[simp] lemma coloring_smul_apply {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) - (σ : Equiv.Perm D) (f : Coloring D A mu) (i : D) : - (σ • f).val i = f.val (σ.symm i) := rfl - -def Contingency {A B : Type*} [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) := - {M : Matrix A B ℕ // (∀ a, ∑ b, M a b = mu a) ∧ (∀ b, ∑ a, M a b = nu b)} - -section ColorPairs -variable {D A B : Type*} [Fintype D] [Fintype A] [Fintype B] - (mu : A → ℕ) (nu : B → ℕ) - -def intersectionCounts (p : Coloring D A mu × Coloring D B nu) : Contingency mu nu := - ⟨fun a b => counts (fun i => (p.1.val i,p.2.val i)) (a,b), - (fun a => (counts_pair_fst p.1.val p.2.val a).trans (congrFun p.1.property a)), - fun b => (counts_pair_snd p.1.val p.2.val b).trans (congrFun p.2.property b)⟩ - -lemma intersectionCounts_smul (σ : Equiv.Perm D) - (p : Coloring D A mu × Coloring D B nu) : - intersectionCounts mu nu (σ • p) = intersectionCounts mu nu p := by - apply Subtype.ext - ext a b - exact congrFun (counts_reindex (fun i => (p.1.val i,p.2.val i)) σ.symm) (a,b) - -lemma orbit_iff_intersectionCounts (p q : Coloring D A mu × Coloring D B nu) : - MulAction.orbitRel (Equiv.Perm D) _ p q ↔ - intersectionCounts mu nu p = intersectionCounts mu nu q := by - constructor - · rintro ⟨σ,rfl⟩ - exact intersectionCounts_smul mu nu σ q - · intro h - have he : counts (fun i => (q.1.val i,q.2.val i)) = - counts (fun i => (p.1.val i,p.2.val i)) := by - funext ab - exact (congrFun (congrFun (congrArg Subtype.val h) ab.1) ab.2).symm - obtain ⟨σ,hσ⟩ := exists_perm_of_counts_eq _ _ he - refine ⟨σ.symm, ?_⟩ - apply Prod.ext - · apply Subtype.ext; funext i; exact congrArg Prod.fst (congrFun hσ i) - · apply Subtype.ext; funext i; exact congrArg Prod.snd (congrFun hσ i) - -lemma intersectionCounts_surjective (hmu : ∑ a, mu a = Fintype.card D) : - Function.Surjective (intersectionCounts (D := D) mu nu) := by - intro M - have ht : ∑ ab : A × B, M.val ab.1 ab.2 = Fintype.card D := by - rw [Fintype.sum_prod_type] - simp only [M.property.1] - exact hmu - obtain ⟨f,hf⟩ := exists_coloring (D := D) (fun ab : A × B => M.val ab.1 ab.2) ht - have ha : counts (fun i => (f i).1) = mu := by - funext a - rw [← counts_pair_fst (fun i => (f i).1) (fun i => (f i).2) a] - simpa only [Prod.eta, hf] using M.property.1 a - have hb : counts (fun i => (f i).2) = nu := by - funext b - rw [← counts_pair_snd (fun i => (f i).1) (fun i => (f i).2) b] - simpa only [Prod.eta, hf] using M.property.2 b - refine ⟨(⟨fun i => (f i).1,ha⟩,⟨fun i => (f i).2,hb⟩), ?_⟩ - apply Subtype.ext - ext a b - exact congrFun hf (a,b) - -def orbitContingencyEquiv (hmu : ∑ a, mu a = Fintype.card D) : - MulAction.orbitRel.Quotient (Equiv.Perm D) (Coloring D A mu × Coloring D B nu) ≃ - Contingency mu nu := by - let f := Quotient.lift (intersectionCounts (D := D) mu nu) - (fun p q h => (orbit_iff_intersectionCounts mu nu p q).mp h) - apply Equiv.ofBijective f - constructor - · intro p q h - induction p using Quotient.inductionOn with | _ p => - induction q using Quotient.inductionOn with | _ q => - exact Quotient.sound ((orbit_iff_intersectionCounts mu nu p q).mpr h) - · intro M - obtain ⟨p,hp⟩ := intersectionCounts_surjective mu nu hmu M - exact ⟨Quotient.mk _ p,hp⟩ - -end ColorPairs -end Foulkes.Young - -namespace Foulkes.Young -open Module Finset - -theorem young_hom_finrank {K D A B : Type*} [Field K] - [Fintype D] [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) - (hnu : ∑ b, nu b = Fintype.card D) : - finrank K ((permRep K (Equiv.Perm D) (Coloring D A mu)).IntertwiningMap - (permRep K (Equiv.Perm D) (Coloring D B nu))) = Nat.card (Contingency nu mu) := by - rw [perm_hom_finrank] - exact Nat.card_congr (orbitContingencyEquiv nu mu hnu) -end Foulkes.Young - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.YoungModules + +namespace OAI + +noncomputable section + +namespace Foulkes.Young +open Finset + +section Counts +variable {D A B : Type*} [Fintype D] [Fintype A] [Fintype B] + +def counts (f : D → A) (a : A) : ℕ := Nat.card {i // f i = a} + +omit [Fintype D] [Fintype A] in +lemma counts_reindex (f : D → A) (σ : Equiv.Perm D) : counts (f ∘ σ) = counts f := by + funext a + exact Nat.card_congr (Equiv.subtypeEquiv σ (fun i => Iff.rfl)) + +omit [Fintype A] in +lemma exists_perm_of_counts_eq (f g : D → A) (h : counts f = counts g) : + ∃ σ : Equiv.Perm D, f ∘ σ = g := by + classical + let e (a : A) : {i // g i = a} ≃ {i // f i = a} := + Fintype.equivOfCardEq (by simpa [counts, Nat.card_eq_fintype_card] using (congrFun h a).symm) + let σ : Equiv.Perm D := (Equiv.sigmaFiberEquiv g).symm.trans + ((Equiv.sigmaCongrRight e).trans (Equiv.sigmaFiberEquiv f)) + refine ⟨σ, ?_⟩ + funext i + exact (e (g i) ⟨i,rfl⟩).property + +lemma counts_total (f : D → A) : ∑ a, counts f a = Fintype.card D := by + classical + simp only [counts, Nat.card_eq_fintype_card] + rw [← Fintype.card_sigma] + exact Fintype.card_congr (Equiv.sigmaFiberEquiv f) + +omit [Fintype A] in +lemma counts_pair_fst (f : D → A) (g : D → B) (a : A) : + ∑ b, counts (fun i => (f i,g i)) (a,b) = counts f a := by + classical + let he (b : B) : {z : {i // f i = a} // g z.val = b} ≃ + {i // (f i,g i) = (a,b)} := { + toFun z := ⟨z.val.val, Prod.ext z.val.property z.property⟩ + invFun z := ⟨⟨z.val, congrArg Prod.fst z.property⟩, congrArg Prod.snd z.property⟩ + left_inv z := rfl + right_inv z := rfl } + have hh := counts_total (fun z : {i // f i = a} => g z.val) + simp only [counts, Nat.card_eq_fintype_card] at hh ⊢ + rw [← hh] + exact Finset.sum_congr rfl (fun b hb => (Fintype.card_congr (he b)).symm) + +omit [Fintype B] in +lemma counts_pair_snd (f : D → A) (g : D → B) (b : B) : + ∑ a, counts (fun i => (f i,g i)) (a,b) = counts g b := by + classical + let he (a : A) : {z : {i // g i = b} // f z.val = a} ≃ + {i // (f i,g i) = (a,b)} := { + toFun z := ⟨z.val.val, Prod.ext z.property z.val.property⟩ + invFun z := ⟨⟨z.val, congrArg Prod.snd z.property⟩, congrArg Prod.fst z.property⟩ + left_inv z := rfl + right_inv z := rfl } + have hh := counts_total (fun z : {i // g i = b} => f z.val) + simp only [counts, Nat.card_eq_fintype_card] at hh ⊢ + rw [← hh] + exact Finset.sum_congr rfl (fun a ha => (Fintype.card_congr (he a)).symm) + +lemma exists_coloring (mu : A → ℕ) (hmu : ∑ a, mu a = Fintype.card D) : + ∃ f : D → A, counts f = mu := by + classical + let e : D ≃ (Σ a, Fin (mu a)) := Fintype.equivOfCardEq (by simp [hmu]) + let f : D → A := fun i => (e i).1 + let ea (a : A) : {t : (Σ a, Fin (mu a)) // t.1 = a} ≃ Fin (mu a) := { + toFun t := t.property ▸ t.val.2 + invFun j := ⟨⟨a,j⟩,rfl⟩ + left_inv t := by rcases t with ⟨⟨b,j⟩,h⟩; dsimp at h; subst b; rfl + right_inv j := rfl } + refine ⟨f, funext fun a => ?_⟩ + have hcard := Nat.card_congr ((Equiv.subtypeEquiv e (fun i => Iff.rfl)).trans (ea a)) + simpa [counts, f] using hcard + +end Counts + +def Coloring (D A : Type*) [Fintype D] (mu : A → ℕ) := + {f : D → A // counts f = mu} + +instance {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) : + Fintype (Coloring D A mu) := by + classical + unfold Coloring + infer_instance + +instance coloringAction {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) : + MulAction (Equiv.Perm D) (Coloring D A mu) where + smul σ f := ⟨f.val ∘ σ.symm, (counts_reindex f.val σ.symm).trans f.property⟩ + one_smul f := by apply Subtype.ext; rfl + mul_smul σ τ f := by apply Subtype.ext; rfl + +@[simp] lemma coloring_smul_apply {D A : Type*} [Fintype D] [Fintype A] (mu : A → ℕ) + (σ : Equiv.Perm D) (f : Coloring D A mu) (i : D) : + (σ • f).val i = f.val (σ.symm i) := rfl + +def Contingency {A B : Type*} [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) := + {M : Matrix A B ℕ // (∀ a, ∑ b, M a b = mu a) ∧ (∀ b, ∑ a, M a b = nu b)} + +section ColorPairs +variable {D A B : Type*} [Fintype D] [Fintype A] [Fintype B] + (mu : A → ℕ) (nu : B → ℕ) + +def intersectionCounts (p : Coloring D A mu × Coloring D B nu) : Contingency mu nu := + ⟨fun a b => counts (fun i => (p.1.val i,p.2.val i)) (a,b), + (fun a => (counts_pair_fst p.1.val p.2.val a).trans (congrFun p.1.property a)), + fun b => (counts_pair_snd p.1.val p.2.val b).trans (congrFun p.2.property b)⟩ + +lemma intersectionCounts_smul (σ : Equiv.Perm D) + (p : Coloring D A mu × Coloring D B nu) : + intersectionCounts mu nu (σ • p) = intersectionCounts mu nu p := by + apply Subtype.ext + ext a b + exact congrFun (counts_reindex (fun i => (p.1.val i,p.2.val i)) σ.symm) (a,b) + +lemma orbit_iff_intersectionCounts (p q : Coloring D A mu × Coloring D B nu) : + MulAction.orbitRel (Equiv.Perm D) _ p q ↔ + intersectionCounts mu nu p = intersectionCounts mu nu q := by + constructor + · rintro ⟨σ,rfl⟩ + exact intersectionCounts_smul mu nu σ q + · intro h + have he : counts (fun i => (q.1.val i,q.2.val i)) = + counts (fun i => (p.1.val i,p.2.val i)) := by + funext ab + exact (congrFun (congrFun (congrArg Subtype.val h) ab.1) ab.2).symm + obtain ⟨σ,hσ⟩ := exists_perm_of_counts_eq _ _ he + refine ⟨σ.symm, ?_⟩ + apply Prod.ext + · apply Subtype.ext; funext i; exact congrArg Prod.fst (congrFun hσ i) + · apply Subtype.ext; funext i; exact congrArg Prod.snd (congrFun hσ i) + +lemma intersectionCounts_surjective (hmu : ∑ a, mu a = Fintype.card D) : + Function.Surjective (intersectionCounts (D := D) mu nu) := by + intro M + have ht : ∑ ab : A × B, M.val ab.1 ab.2 = Fintype.card D := by + rw [Fintype.sum_prod_type] + simp only [M.property.1] + exact hmu + obtain ⟨f,hf⟩ := exists_coloring (D := D) (fun ab : A × B => M.val ab.1 ab.2) ht + have ha : counts (fun i => (f i).1) = mu := by + funext a + rw [← counts_pair_fst (fun i => (f i).1) (fun i => (f i).2) a] + simpa only [Prod.eta, hf] using M.property.1 a + have hb : counts (fun i => (f i).2) = nu := by + funext b + rw [← counts_pair_snd (fun i => (f i).1) (fun i => (f i).2) b] + simpa only [Prod.eta, hf] using M.property.2 b + refine ⟨(⟨fun i => (f i).1,ha⟩,⟨fun i => (f i).2,hb⟩), ?_⟩ + apply Subtype.ext + ext a b + exact congrFun hf (a,b) + +def orbitContingencyEquiv (hmu : ∑ a, mu a = Fintype.card D) : + MulAction.orbitRel.Quotient (Equiv.Perm D) (Coloring D A mu × Coloring D B nu) ≃ + Contingency mu nu := by + let f := Quotient.lift (intersectionCounts (D := D) mu nu) + (fun p q h => (orbit_iff_intersectionCounts mu nu p q).mp h) + apply Equiv.ofBijective f + constructor + · intro p q h + induction p using Quotient.inductionOn with | _ p => + induction q using Quotient.inductionOn with | _ q => + exact Quotient.sound ((orbit_iff_intersectionCounts mu nu p q).mpr h) + · intro M + obtain ⟨p,hp⟩ := intersectionCounts_surjective mu nu hmu M + exact ⟨Quotient.mk _ p,hp⟩ + +end ColorPairs +end Foulkes.Young + +namespace Foulkes.Young +open Module Finset + +theorem young_hom_finrank {K D A B : Type*} [Field K] + [Fintype D] [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) + (hnu : ∑ b, nu b = Fintype.card D) : + finrank K ((permRep K (Equiv.Perm D) (Coloring D A mu)).IntertwiningMap + (permRep K (Equiv.Perm D) (Coloring D B nu))) = Nat.card (Contingency nu mu) := by + rw [perm_hom_finrank] + exact Nat.card_congr (orbitContingencyEquiv nu mu hnu) +end Foulkes.Young + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/CompleteNewton.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/CompleteNewton.lean index ff937372e167adec1756a8515935cbf0eb914629..549c230f043a9a89fd1635ea9d9414a205b97c67 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/CompleteNewton.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/CompleteNewton.lean @@ -1,130 +1,130 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Complete -open MvPolynomial Finset - -abbrev Degree (α : Type*) (b : ℕ) := {d : α →₀ ℕ // d.degree = b} -instance {α : Type*} [Finite α] (b : ℕ) : Fintype (Degree α b) := - (Finsupp.finite_of_degree_eq (σ := α) b).fintype - -def h (α : Type*) [Finite α] (b : ℕ) : MvPolynomial α ℤ := - ∑ d : Degree α b, monomial d.val 1 - -@[simp] theorem coeff_h {α : Type*} [Finite α] (b : ℕ) (d : α →₀ ℕ) : - (h α b).coeff d = if d.degree = b then 1 else 0 := by - classical - simp only [h, coeff_sum, coeff_monomial] - by_cases hd : d.degree = b - · rw [ite_eq_left hd, Finset.sum_eq_single (⟨d,hd⟩ : Degree α b)] - · simp - · intro e he hne - have hneq : e.val ≠ d := fun hh => hne (Subtype.ext hh) - simp [hneq] - · simp - · rw [ite_eq_right hd] - apply Finset.sum_eq_zero - intro e he - have hneq : e.val ≠ d := fun hh => hd (hh ▸ e.property) - simp [hneq] - -@[simp] theorem h_zero (α : Type*) [Finite α] : h α 0 = 1 := by - classical - ext d - rw [coeff_h] - by_cases hd : d = 0 - · simp [hd] - · have hh : d.degree ≠ 0 := by - intro hh - apply hd - ext j - have hj := Finsupp.le_degree j d - simp only [hh, Nat.le_zero] at hj - simpa using hj - simp [hh, coeff_one, Ne.symm hd] - -lemma coeff_X_pow_h {α : Type*} [Finite α] (b k : ℕ) (hkb : k ≤ b) - (j : α) (d : α →₀ ℕ) : - ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = - if d.degree = b ∧ k ≤ d j then 1 else 0 := by - classical - rw [X_pow_eq_monomial, coeff_monomial_mul', coeff_h] - simp only [one_mul, Finsupp.single_le_iff] - by_cases hk : k ≤ d j - · rw [ite_eq_left hk] - have hs : Finsupp.single j k ≤ d := Finsupp.single_le_iff.mpr hk - have he : (d - Finsupp.single j k).degree + k = d.degree := by - have he := congrArg Finsupp.degree (tsub_add_cancel_of_le hs) - simpa using he - have hd : (d - Finsupp.single j k).degree = b-k ↔ d.degree = b := by omega - simp only [hd, hk, and_true] - · simp [hk] - -theorem newton {α : Type*} [Fintype α] (b : ℕ) : - (b : ℤ) • h α b = - ∑ k ∈ Finset.Icc 1 b, (∑ j : α, (X j : MvPolynomial α ℤ)^k) * h α (b-k) := by - classical - ext d - simp only [coeff_smul, coeff_h, coeff_sum, Finset.sum_mul] - rw [Finset.sum_comm] - by_cases hd : d.degree = b - · have hterm (j : α) : - ∑ k ∈ Finset.Icc 1 b, ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = (d j : ℤ) := by - have hj : d j ≤ b := by simpa [hd] using Finsupp.le_degree j d - have he : (Finset.Icc 1 b).filter (fun k => k ≤ d j) = Finset.Icc 1 (d j) := by - ext k - simp only [mem_filter, mem_Icc] - omega - calc - _ = ∑ k ∈ Finset.Icc 1 b, if k ≤ d j then (1 : ℤ) else 0 := by - apply Finset.sum_congr rfl - intro k hk - rw [coeff_X_pow_h b k (mem_Icc.mp hk).2] - simp only [hd, true_and] - _ = ((Finset.Icc 1 (d j)).card : ℤ) := by - rw [← Finset.sum_filter, he] - simp - _ = (d j : ℤ) := by simp - simp only [hterm, ite_eq_left hd, zsmul_eq_mul, mul_one] - simpa using - congrArg (fun z : ℕ => (z : ℤ)) (hd.symm.trans (Finsupp.degree_eq_sum d)) - · have hterm (j : α) : - ∑ k ∈ Finset.Icc 1 b, ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = 0 := by - apply Finset.sum_eq_zero - intro k hk - rw [coeff_X_pow_h b k (mem_Icc.mp hk).2] - simp [hd] - simp [hterm, hd] - -def alphabetH {α σ : Type*} [Finite α] (x : α → MvPolynomial σ ℤ) (b : ℕ) : MvPolynomial σ ℤ := - eval₂Hom (Int.castRingHom _) x (h α b) - -@[simp] theorem alphabetH_zero {α σ : Type*} [Finite α] (x : α → MvPolynomial σ ℤ) : - alphabetH x 0 = 1 := by simp [alphabetH] - -theorem alphabet_newton {α σ : Type*} [Fintype α] (x : α → MvPolynomial σ ℤ) (b : ℕ) : - (b : ℤ) • alphabetH x b = - ∑ k ∈ Finset.Icc 1 b, (∑ j : α, x j ^ k) * alphabetH x (b-k) := by - have hh := congrArg (eval₂Hom (Int.castRingHom (MvPolynomial σ ℤ)) x) (newton (α := α) b) - simpa [alphabetH] using hh - -def pleth (n b a : ℕ) : MvPolynomial (Fin n) ℤ := - alphabetH (fun d : Degree (Fin n) a => monomial d.val 1) b - -@[simp] theorem pleth_zero (n a : ℕ) : pleth n 0 a = 1 := alphabetH_zero _ - -theorem pleth_newton (n b a : ℕ) : - (b : ℤ) • pleth n b a = - ∑ k ∈ Finset.Icc 1 b, - (∑ d : Degree (Fin n) a, monomial (k • d.val) (1 : ℤ)) * pleth n (b-k) a := by - simpa [pleth, monomial_pow] using - (alphabet_newton (fun d : Degree (Fin n) a => monomial d.val (1 : ℤ)) b) - -end Foulkes.Complete - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Complete +open MvPolynomial Finset + +abbrev Degree (α : Type*) (b : ℕ) := {d : α →₀ ℕ // d.degree = b} +instance {α : Type*} [Finite α] (b : ℕ) : Fintype (Degree α b) := + (Finsupp.finite_of_degree_eq (σ := α) b).fintype + +def h (α : Type*) [Finite α] (b : ℕ) : MvPolynomial α ℤ := + ∑ d : Degree α b, monomial d.val 1 + +@[simp] theorem coeff_h {α : Type*} [Finite α] (b : ℕ) (d : α →₀ ℕ) : + (h α b).coeff d = if d.degree = b then 1 else 0 := by + classical + simp only [h, coeff_sum, coeff_monomial] + by_cases hd : d.degree = b + · rw [ite_eq_left hd, Finset.sum_eq_single (⟨d,hd⟩ : Degree α b)] + · simp + · intro e he hne + have hneq : e.val ≠ d := fun hh => hne (Subtype.ext hh) + simp [hneq] + · simp + · rw [ite_eq_right hd] + apply Finset.sum_eq_zero + intro e he + have hneq : e.val ≠ d := fun hh => hd (hh ▸ e.property) + simp [hneq] + +@[simp] theorem h_zero (α : Type*) [Finite α] : h α 0 = 1 := by + classical + ext d + rw [coeff_h] + by_cases hd : d = 0 + · simp [hd] + · have hh : d.degree ≠ 0 := by + intro hh + apply hd + ext j + have hj := Finsupp.le_degree j d + simp only [hh, Nat.le_zero] at hj + simpa using hj + simp [hh, coeff_one, Ne.symm hd] + +lemma coeff_X_pow_h {α : Type*} [Finite α] (b k : ℕ) (hkb : k ≤ b) + (j : α) (d : α →₀ ℕ) : + ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = + if d.degree = b ∧ k ≤ d j then 1 else 0 := by + classical + rw [X_pow_eq_monomial, coeff_monomial_mul', coeff_h] + simp only [one_mul, Finsupp.single_le_iff] + by_cases hk : k ≤ d j + · rw [ite_eq_left hk] + have hs : Finsupp.single j k ≤ d := Finsupp.single_le_iff.mpr hk + have he : (d - Finsupp.single j k).degree + k = d.degree := by + have he := congrArg Finsupp.degree (tsub_add_cancel_of_le hs) + simpa using he + have hd : (d - Finsupp.single j k).degree = b-k ↔ d.degree = b := by omega + simp only [hd, hk, and_true] + · simp [hk] + +theorem newton {α : Type*} [Fintype α] (b : ℕ) : + (b : ℤ) • h α b = + ∑ k ∈ Finset.Icc 1 b, (∑ j : α, (X j : MvPolynomial α ℤ)^k) * h α (b-k) := by + classical + ext d + simp only [coeff_smul, coeff_h, coeff_sum, Finset.sum_mul] + rw [Finset.sum_comm] + by_cases hd : d.degree = b + · have hterm (j : α) : + ∑ k ∈ Finset.Icc 1 b, ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = (d j : ℤ) := by + have hj : d j ≤ b := by simpa [hd] using Finsupp.le_degree j d + have he : (Finset.Icc 1 b).filter (fun k => k ≤ d j) = Finset.Icc 1 (d j) := by + ext k + simp only [mem_filter, mem_Icc] + omega + calc + _ = ∑ k ∈ Finset.Icc 1 b, if k ≤ d j then (1 : ℤ) else 0 := by + apply Finset.sum_congr rfl + intro k hk + rw [coeff_X_pow_h b k (mem_Icc.mp hk).2] + simp only [hd, true_and] + _ = ((Finset.Icc 1 (d j)).card : ℤ) := by + rw [← Finset.sum_filter, he] + simp + _ = (d j : ℤ) := by simp + simp only [hterm, ite_eq_left hd, zsmul_eq_mul, mul_one] + simpa using + congrArg (fun z : ℕ => (z : ℤ)) (hd.symm.trans (Finsupp.degree_eq_sum d)) + · have hterm (j : α) : + ∑ k ∈ Finset.Icc 1 b, ((X j : MvPolynomial α ℤ)^k * h α (b-k)).coeff d = 0 := by + apply Finset.sum_eq_zero + intro k hk + rw [coeff_X_pow_h b k (mem_Icc.mp hk).2] + simp [hd] + simp [hterm, hd] + +def alphabetH {α σ : Type*} [Finite α] (x : α → MvPolynomial σ ℤ) (b : ℕ) : MvPolynomial σ ℤ := + eval₂Hom (Int.castRingHom _) x (h α b) + +@[simp] theorem alphabetH_zero {α σ : Type*} [Finite α] (x : α → MvPolynomial σ ℤ) : + alphabetH x 0 = 1 := by simp [alphabetH] + +theorem alphabet_newton {α σ : Type*} [Fintype α] (x : α → MvPolynomial σ ℤ) (b : ℕ) : + (b : ℤ) • alphabetH x b = + ∑ k ∈ Finset.Icc 1 b, (∑ j : α, x j ^ k) * alphabetH x (b-k) := by + have hh := congrArg (eval₂Hom (Int.castRingHom (MvPolynomial σ ℤ)) x) (newton (α := α) b) + simpa [alphabetH] using hh + +def pleth (n b a : ℕ) : MvPolynomial (Fin n) ℤ := + alphabetH (fun d : Degree (Fin n) a => monomial d.val 1) b + +@[simp] theorem pleth_zero (n a : ℕ) : pleth n 0 a = 1 := alphabetH_zero _ + +theorem pleth_newton (n b a : ℕ) : + (b : ℤ) • pleth n b a = + ∑ k ∈ Finset.Icc 1 b, + (∑ d : Degree (Fin n) a, monomial (k • d.val) (1 : ℤ)) * pleth n (b-k) a := by + simpa [pleth, monomial_pow] using + (alphabet_newton (fun d : Degree (Fin n) a => monomial d.val (1 : ℤ)) b) + +end Foulkes.Complete + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/CompositionEnumeration.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/CompositionEnumeration.lean index ef732617b7df4f6b550e7418639137729d419c69..dd4bbe182d130686d9ead11d0307949a454ced16 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/CompositionEnumeration.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/CompositionEnumeration.lean @@ -1,80 +1,80 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.FastLookup - -namespace OAI - -noncomputable section - -namespace Foulkes.Enumeration -open Finset - -def compositions : (n d : ℕ) → List (Fin n → ℕ) - | 0, d => if d = 0 then [Fin.elim0] else [] - | n+1, d => (List.range (d+1)).flatMap fun k => - (compositions n (d-k)).map (Fin.cons k) - -lemma mem_compositions (n d : ℕ) (v : Fin n → ℕ) : - v ∈ compositions n d ↔ ∑ j, v j = d := by - induction n generalizing d with - | zero => - have hv : v = Fin.elim0 := by funext j; exact Fin.elim0 j - subst v - by_cases hd : d = 0 - · simp [compositions, hd] - · simp [compositions, hd, Ne.symm hd] - | succ n ih => - rw [compositions, List.mem_flatMap] - constructor - · rintro ⟨k,hk,hv⟩ - obtain ⟨w,hw,rfl⟩ := List.mem_map.mp hv - have hw' := (ih (d-k) w).mp hw - have hk' : k ≤ d := by simpa using List.mem_range.mp hk - rw [Fin.sum_univ_succ] - simp only [Fin.cons_zero, Fin.cons_succ] - omega - · intro hv - refine ⟨v 0, List.mem_range.mpr ?_, List.mem_map.mpr ⟨Fin.tail v, ?_, ?_⟩⟩ - · rw [Fin.sum_univ_succ] at hv - omega - · apply (ih (d-v 0) (Fin.tail v)).mpr - rw [Fin.sum_univ_succ] at hv - dsimp [Fin.tail] - omega - · exact Fin.cons_self_tail v - -lemma nodup_compositions (n d : ℕ) : (compositions n d).Nodup := by - induction n generalizing d with - | zero => unfold compositions; split_ifs <;> simp - | succ n ih => - rw [compositions, List.nodup_flatMap] - refine ⟨fun k hk => (ih _).map ?_, (List.nodup_range (n := d+1)).imp ?_⟩ - · intro v w h - funext j - exact congrFun h j.succ - · intro x y hxy v hx hy - obtain ⟨vx,hvx,hex⟩ := List.mem_map.mp hx - obtain ⟨vy,hvy,hey⟩ := List.mem_map.mp hy - have hh := congrFun (hex.trans hey.symm) 0 - exact hxy hh - -def compositionSet (n d : ℕ) : Finset (Fin n → ℕ) := (compositions n d).toFinset - -@[simp] lemma mem_compositionSet (n d : ℕ) (v : Fin n → ℕ) : - v ∈ compositionSet n d ↔ ∑ j, v j = d := by - simp [compositionSet, mem_compositions] - -def degreeComposition (n d : ℕ) : Foulkes.Complete.Degree (Fin n) d ≃ - {v : Fin n → ℕ // v ∈ compositionSet n d} where - toFun a := ⟨fun j => a.val j, (mem_compositionSet n d _).mpr (by - rw [← Finsupp.degree_eq_sum]; exact a.property)⟩ - invFun v := ⟨Foulkes.Strips.expVector v.val, by - rw [Foulkes.Lookup.degree_expVector] - exact (mem_compositionSet n d _).mp v.property⟩ - left_inv a := by apply Subtype.ext; ext j; rfl - right_inv v := rfl - -end Foulkes.Enumeration - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.FastLookup + +namespace OAI + +noncomputable section + +namespace Foulkes.Enumeration +open Finset + +def compositions : (n d : ℕ) → List (Fin n → ℕ) + | 0, d => if d = 0 then [Fin.elim0] else [] + | n+1, d => (List.range (d+1)).flatMap fun k => + (compositions n (d-k)).map (Fin.cons k) + +lemma mem_compositions (n d : ℕ) (v : Fin n → ℕ) : + v ∈ compositions n d ↔ ∑ j, v j = d := by + induction n generalizing d with + | zero => + have hv : v = Fin.elim0 := by funext j; exact Fin.elim0 j + subst v + by_cases hd : d = 0 + · simp [compositions, hd] + · simp [compositions, hd, Ne.symm hd] + | succ n ih => + rw [compositions, List.mem_flatMap] + constructor + · rintro ⟨k,hk,hv⟩ + obtain ⟨w,hw,rfl⟩ := List.mem_map.mp hv + have hw' := (ih (d-k) w).mp hw + have hk' : k ≤ d := by simpa using List.mem_range.mp hk + rw [Fin.sum_univ_succ] + simp only [Fin.cons_zero, Fin.cons_succ] + omega + · intro hv + refine ⟨v 0, List.mem_range.mpr ?_, List.mem_map.mpr ⟨Fin.tail v, ?_, ?_⟩⟩ + · rw [Fin.sum_univ_succ] at hv + omega + · apply (ih (d-v 0) (Fin.tail v)).mpr + rw [Fin.sum_univ_succ] at hv + dsimp [Fin.tail] + omega + · exact Fin.cons_self_tail v + +lemma nodup_compositions (n d : ℕ) : (compositions n d).Nodup := by + induction n generalizing d with + | zero => unfold compositions; split_ifs <;> simp + | succ n ih => + rw [compositions, List.nodup_flatMap] + refine ⟨fun k hk => (ih _).map ?_, (List.nodup_range (n := d+1)).imp ?_⟩ + · intro v w h + funext j + exact congrFun h j.succ + · intro x y hxy v hx hy + obtain ⟨vx,hvx,hex⟩ := List.mem_map.mp hx + obtain ⟨vy,hvy,hey⟩ := List.mem_map.mp hy + have hh := congrFun (hex.trans hey.symm) 0 + exact hxy hh + +def compositionSet (n d : ℕ) : Finset (Fin n → ℕ) := (compositions n d).toFinset + +@[simp] lemma mem_compositionSet (n d : ℕ) (v : Fin n → ℕ) : + v ∈ compositionSet n d ↔ ∑ j, v j = d := by + simp [compositionSet, mem_compositions] + +def degreeComposition (n d : ℕ) : Foulkes.Complete.Degree (Fin n) d ≃ + {v : Fin n → ℕ // v ∈ compositionSet n d} where + toFun a := ⟨fun j => a.val j, (mem_compositionSet n d _).mpr (by + rw [← Finsupp.degree_eq_sum]; exact a.property)⟩ + invFun v := ⟨Foulkes.Strips.expVector v.val, by + rw [Foulkes.Lookup.degree_expVector] + exact (mem_compositionSet n d _).mp v.property⟩ + left_inv a := by apply Subtype.ext; ext j; rfl + right_inv v := rfl + +end Foulkes.Enumeration + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Diagonal.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Diagonal.lean index 57155511b3fb6a133a703f734519764094aad476..2c9ad915f8171f2ed620f4db23045bcb2ac4e9a7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Diagonal.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Diagonal.lean @@ -1,89 +1,89 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Diagonal -open MvPolynomial - -variable {ι V : Type*} [Fintype ι] [AddCommGroup V] [Module ℂ V] - -def exponent (f : ι → ι) : ι →₀ ℕ := ∑ i, Finsupp.single (f i) 1 - -lemma exponent_id : exponent (id : ι → ι) = ∑ i, Finsupp.single i 1 := rfl - -lemma bijective_of_exponent_eq (f : ι → ι) - (h : exponent f = exponent (id : ι → ι)) : Function.Bijective f := by - classical - apply (Fintype.bijective_iff_surjective_and_card _).mpr - constructor - · intro k - by_contra hk - have hn : ∀ i, f i ≠ k := by simpa using hk - have hh := congrArg (fun d : ι →₀ ℕ => d k) h - have hz : exponent f k = 0 := by - simp [exponent, hn] - have ho : exponent (id : ι → ι) k = 1 := by - simp [exponent, Finsupp.single_apply] - rw [hz, ho] at hh - omega - · rfl - -def expansion (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) (v : ι → V) : - MvPolynomial ι ℂ := by - classical - exact ∑ f : ι → ι, monomial (exponent f) (T (fun i => v (f i))) - -lemma eval_expansion (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (v : ι → V) (x : ι → ℂ) : - eval x (expansion T v) = T (fun _ => ∑ j, x j • v j) := by - classical - rw [T.map_sum] - simp only [expansion, map_sum] - apply Finset.sum_congr rfl - intro f hf - rw [T.map_smul_univ] - have hm : (monomial (exponent f) 1 : MvPolynomial ι ℂ) = ∏ i, X (f i) := by - simpa only [exponent, X] using - (monomial_sum_one (R := ℂ) Finset.univ (fun i => Finsupp.single (f i) 1)) - calc - eval x (monomial (exponent f) (T (fun i => v (f i)))) = - T (fun i => v (f i)) * eval x (monomial (exponent f) 1) := by - simp [eval_monomial] - _ = (∏ i, x (f i)) • T (fun i => v (f i)) := by - rw [hm] - simp [mul_comm] - -theorem eq_zero_of_symmetric_of_diagonal - (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) - (hs : ∀ (σ : Equiv.Perm ι) (v : ι → V), T (fun i => v (σ i)) = T v) - (hd : ∀ v : V, T (fun _ => v) = 0) : T = 0 := by - classical - ext v - have hp : expansion T v = 0 := by - apply MvPolynomial.funext - intro x - rw [eval_expansion, hd, map_zero] - let G : Finset (ι → ι) := Finset.univ.filter (fun f => exponent f = exponent (id : ι → ι)) - have hG : G.Nonempty := ⟨id, by simp [G]⟩ - have hn : (G.card : ℂ) ≠ 0 := by exact_mod_cast hG.card_pos.ne' - have hc := congrArg (fun polynomial => polynomial.coeff (exponent (id : ι → ι))) hp - have he : (expansion T v).coeff (exponent (id : ι → ι)) = (G.card : ℂ) * T v := by - simp only [expansion, coeff_sum, coeff_monomial] - rw [← Finset.sum_filter] - change (∑ f ∈ G, T (fun i => v (f i))) = _ - calc - _ = ∑ _f ∈ G, T v := by - apply Finset.sum_congr rfl - intro f hf - exact hs (Equiv.ofBijective f (bijective_of_exponent_eq f (Finset.mem_filter.mp hf).2)) v - _ = (G.card : ℂ) * T v := by simp - rw [he, AddMonoidAlgebra.coeff_zero, Finsupp.zero_apply] at hc - exact (mul_eq_zero.mp hc).resolve_left hn - -end Foulkes.Diagonal - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Diagonal +open MvPolynomial + +variable {ι V : Type*} [Fintype ι] [AddCommGroup V] [Module ℂ V] + +def exponent (f : ι → ι) : ι →₀ ℕ := ∑ i, Finsupp.single (f i) 1 + +lemma exponent_id : exponent (id : ι → ι) = ∑ i, Finsupp.single i 1 := rfl + +lemma bijective_of_exponent_eq (f : ι → ι) + (h : exponent f = exponent (id : ι → ι)) : Function.Bijective f := by + classical + apply (Fintype.bijective_iff_surjective_and_card _).mpr + constructor + · intro k + by_contra hk + have hn : ∀ i, f i ≠ k := by simpa using hk + have hh := congrArg (fun d : ι →₀ ℕ => d k) h + have hz : exponent f k = 0 := by + simp [exponent, hn] + have ho : exponent (id : ι → ι) k = 1 := by + simp [exponent, Finsupp.single_apply] + rw [hz, ho] at hh + omega + · rfl + +def expansion (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) (v : ι → V) : + MvPolynomial ι ℂ := by + classical + exact ∑ f : ι → ι, monomial (exponent f) (T (fun i => v (f i))) + +lemma eval_expansion (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (v : ι → V) (x : ι → ℂ) : + eval x (expansion T v) = T (fun _ => ∑ j, x j • v j) := by + classical + rw [T.map_sum] + simp only [expansion, map_sum] + apply Finset.sum_congr rfl + intro f hf + rw [T.map_smul_univ] + have hm : (monomial (exponent f) 1 : MvPolynomial ι ℂ) = ∏ i, X (f i) := by + simpa only [exponent, X] using + (monomial_sum_one (R := ℂ) Finset.univ (fun i => Finsupp.single (f i) 1)) + calc + eval x (monomial (exponent f) (T (fun i => v (f i)))) = + T (fun i => v (f i)) * eval x (monomial (exponent f) 1) := by + simp [eval_monomial] + _ = (∏ i, x (f i)) • T (fun i => v (f i)) := by + rw [hm] + simp [mul_comm] + +theorem eq_zero_of_symmetric_of_diagonal + (T : MultilinearMap ℂ (fun _ : ι => V) ℂ) + (hs : ∀ (σ : Equiv.Perm ι) (v : ι → V), T (fun i => v (σ i)) = T v) + (hd : ∀ v : V, T (fun _ => v) = 0) : T = 0 := by + classical + ext v + have hp : expansion T v = 0 := by + apply MvPolynomial.funext + intro x + rw [eval_expansion, hd, map_zero] + let G : Finset (ι → ι) := Finset.univ.filter (fun f => exponent f = exponent (id : ι → ι)) + have hG : G.Nonempty := ⟨id, by simp [G]⟩ + have hn : (G.card : ℂ) ≠ 0 := by exact_mod_cast hG.card_pos.ne' + have hc := congrArg (fun polynomial => polynomial.coeff (exponent (id : ι → ι))) hp + have he : (expansion T v).coeff (exponent (id : ι → ι)) = (G.card : ℂ) * T v := by + simp only [expansion, coeff_sum, coeff_monomial] + rw [← Finset.sum_filter] + change (∑ f ∈ G, T (fun i => v (f i))) = _ + calc + _ = ∑ _f ∈ G, T v := by + apply Finset.sum_congr rfl + intro f hf + exact hs (Equiv.ofBijective f (bijective_of_exponent_eq f (Finset.mem_filter.mp hf).2)) v + _ = (G.card : ℂ) * T v := by simp + rw [he, AddMonoidAlgebra.coeff_zero, Finsupp.zero_apply] at hc + exact (mul_eq_zero.mp hc).resolve_left hn + +end Foulkes.Diagonal + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Differential.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Differential.lean index af65c39e5f579c84f1aabb371246ebdde72db256..d53d84d271cc903586715bf71d979d381c67957f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Differential.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Differential.lean @@ -1,330 +1,330 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Differential -open MvPolynomial - -abbrev Poly (m n : ℕ) := MvPolynomial (Fin m × Fin n) ℂ - -def shift {m n : ℕ} (u v : Fin m) : Derivation ℂ (Poly m n) (Poly m n) := - MvPolynomial.mkDerivation ℂ fun ij => if ij.1 = u then X (v, ij.2) else 0 - -@[simp] theorem shift_X {m n : ℕ} (u v : Fin m) (ij : Fin m × Fin n) : - shift (n := n) u v (X ij) = if ij.1 = u then X (v, ij.2) else 0 := by - simp [shift] - -@[simp] theorem derivation_sum_apply {m n : ℕ} {ι : Type*} - (s : Finset ι) (D : ι → Derivation ℂ (Poly m n) (Poly m n)) (f : Poly m n) : - (∑ k ∈ s, D k) f = ∑ k ∈ s, D k f := by - classical - induction s using Finset.induction_on with - | empty => simp - | insert x s hx ih => simp [Finset.sum_insert hx, ih] - -theorem shift_eq_sum {m n : ℕ} (u v : Fin m) : - shift (n := n) u v = ∑ k : Fin n, (X (v, k) : Poly m n) • - (pderiv (u, k) : Derivation ℂ (Poly m n) (Poly m n)) := by - apply MvPolynomial.derivation_ext - rintro ⟨r, k⟩ - simp only [shift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] - by_cases h : r = u - · subst r - simp [Pi.single_apply, Prod.mk.injEq] - · simp [Prod.mk.injEq, h] - -theorem shift_commutator {m n : ℕ} {u v : Fin m} (_hne : u ≠ v) : - ⁅shift (n := n) v u, shift (n := n) u v⁆ = - shift (n := n) u u - shift (n := n) v v := by - apply MvPolynomial.derivation_ext - rintro ⟨r, k⟩ - simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X] - split_ifs <;> simp_all [sub_eq_add_neg] - -def rowWeight {m n : ℕ} (u : Fin m) (ij : Fin m × Fin n) : ℕ := - if ij.1 = u then 1 else 0 - -theorem euler {m n : ℕ} (u : Fin m) {f : Poly m n} {p : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight u) p) : - shift (n := n) u u f = (p : ℂ) • f := by - have h := hf.sum_weight_X_mul_pderiv - rw [shift_eq_sum] - simp only [derivation_sum_apply, Derivation.smul_apply, smul_eq_mul] - have hs : (∑ i : Fin m × Fin n, rowWeight u i • (X i * pderiv i f)) = - ∑ k : Fin n, X (u, k) * pderiv (u, k) f := by - rw [Fintype.sum_prod_type, Finset.sum_comm] - simp [rowWeight] - rw [hs] at h - simpa only [Nat.cast_smul_eq_nsmul] using h - -theorem shift_lowers {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {p : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight u) (p + 1)) : - (shift u v f).IsWeightedHomogeneous (rowWeight u) p := by - rw [shift_eq_sum, derivation_sum_apply] - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - simp only [Derivation.smul_apply, smul_eq_mul] - have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight u) p := - hf.pderiv (by simp [rowWeight]) - have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight u) 0 := by - simpa [rowWeight, Ne.symm huv] using - (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight u) (v, k)) - simpa using hx.mul hd - -theorem pderiv_zero_degree {m n : ℕ} {u : Fin m} {f : Poly m n} - (hf : f.IsWeightedHomogeneous (rowWeight u) 0) (k : Fin n) : - pderiv (u, k) f = 0 := by - ext d - rw [coeff_pderiv, AddMonoidAlgebra.coeff_zero] - have hc : f.coeff (d + Finsupp.single (u, k) 1) = 0 := - hf.coeff_eq_zero _ (by simp [map_add, Finsupp.weight_single, rowWeight]) - simp [hc] - -theorem shift_zero_degree {m n : ℕ} {u v : Fin m} {f : Poly m n} - (hf : f.IsWeightedHomogeneous (rowWeight u) 0) : shift u v f = 0 := by - rw [shift_eq_sum, derivation_sum_apply] - simp [pderiv_zero_degree hf] - -theorem shift_nilpotent {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {p : ℕ} (hf : f.IsWeightedHomogeneous (rowWeight u) p) : - ((shift u v).toLinearMap ^ (p + 1)) f = 0 := by - induction p generalizing f with - | zero => simpa using shift_zero_degree (v := v) hf - | succ p ih => - rw [pow_succ, Module.End.mul_apply] - exact ih (shift_lowers huv hf) - -theorem shift_triple {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - (hH : shift (n := n) v v - shift (n := n) u u ≠ 0) : - IsSl2Triple (shift (n := n) v v - shift (n := n) u u) - (shift (n := n) u v) (shift (n := n) v u) where - h_ne_zero := hH - lie_e_f := shift_commutator (Ne.symm huv) - lie_h_e_nsmul := by - have hvu := Ne.symm huv - apply MvPolynomial.derivation_ext - rintro ⟨r, k⟩ - simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X, map_sub, - two_nsmul, Derivation.add_apply] - split_ifs <;> simp_all [sub_eq_add_neg] - lie_h_f_nsmul := by - have hvu := Ne.symm huv - apply MvPolynomial.derivation_ext - rintro ⟨r, k⟩ - simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X, map_sub, - two_nsmul, Derivation.add_apply, Derivation.neg_apply] - split_ifs <;> simp_all [sub_eq_add_neg] - -theorem shift_kernel_zero {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {p q : ℕ} - (hp : f.IsWeightedHomogeneous (rowWeight u) p) - (hq : f.IsWeightedHomogeneous (rowWeight v) q) - (hpq : q < p) (hDf : shift u v f = 0) : f = 0 := by - by_contra hne - have hweight : (shift (n := n) v v - shift (n := n) u u) f = - ((q : ℂ) - p) • f := by - rw [Derivation.sub_apply, euler v hq, euler u hp, sub_smul] - have hH : shift (n := n) v v - shift (n := n) u u ≠ 0 := by - intro hzero - have hscalar : (q : ℂ) - p ≠ 0 := by - rw [sub_ne_zero] - exact_mod_cast (Nat.ne_of_lt hpq) - rw [hzero, Derivation.zero_apply] at hweight - exact (smul_ne_zero hscalar hne) hweight.symm - let t := shift_triple huv hH - have hprimitive : t.HasPrimitiveVectorWith f ((q : ℂ) - p) := - { ne_zero := hne, lie_h := hweight, lie_e := hDf } - let E := LieModule.toEnd ℂ (Derivation ℂ (Poly m n) (Poly m n)) (Poly m n) - (shift (n := n) v u) - have hnil : ∃ k : ℕ, (E ^ k) f = 0 := - ⟨q + 1, shift_nilpotent (Ne.symm huv) hq⟩ - obtain ⟨k, hk₁, hk₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists hne hnil - have hrec := hprimitive.lie_e_pow_succ_toEnd_f k - change shift u v ((E ^ (k + 1)) f) = - ((k + 1 : ℂ) * ((q : ℂ) - p - k)) • ((E ^ k) f) at hrec - rw [hk₂, map_zero, eq_comm, smul_eq_zero_iff_left hk₁, mul_eq_zero, - sub_eq_zero] at hrec - have heq : (q : ℂ) - p = k := hrec.resolve_left (Nat.cast_add_one_ne_zero k) - have heq' : q = k + p := by exact_mod_cast (sub_eq_iff_eq_add.mp heq) - omega - -theorem shift_injOn {m n : ℕ} {u v : Fin m} (huv : u ≠ v) {p q : ℕ} - (hpq : q < p) : - Set.InjOn (shift (n := n) u v) - {f | f.IsWeightedHomogeneous (rowWeight u) p ∧ - f.IsWeightedHomogeneous (rowWeight v) q} := by - intro f hf g hg hfg - apply sub_eq_zero.mp - exact shift_kernel_zero huv (hf.1.sub hg.1) (hf.2.sub hg.2) hpq - (by rw [map_sub, hfg, sub_self]) - -theorem nilpotence_raise {M : Type*} [AddCommGroup M] [Module ℂ M] - (D E H : Module.End ℂ M) - (hDE : ∀ x, D (E x) = E (D x) - H x) - (hHD : ∀ x, H (D x) = D (H x) - (2 : ℂ) • D x) - {x : M} {μ : ℂ} (hx : H x = μ • x) {L : ℕ} - (hL : (D ^ L) x = 0) : (D ^ (L + 1)) (E x) = 0 := by - induction L generalizing x μ with - | zero => - simp only [pow_zero, Module.End.one_apply] at hL - simp [hL] - | succ L ih => - have hxD : H (D x) = (μ - 2) • D x := by - rw [hHD, hx, map_smul, sub_smul] - have hLD : (D ^ L) (D x) = 0 := by - simpa only [pow_succ, Module.End.mul_apply] using hL - have hED := ih hxD hLD - rw [pow_succ, Module.End.mul_apply, hDE, map_sub, hx, map_smul] - change (D ^ (L + 1)) (E (D x)) - μ • (D ^ (L + 1)) x = 0 - rw [hED, hL, smul_zero, sub_self] - -theorem shift_power_kernel_zero {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {p q L : ℕ} - (hp : f.IsWeightedHomogeneous (rowWeight u) p) - (hq : f.IsWeightedHomogeneous (rowWeight v) q) - (hpq : q + L ≤ p) (hDf : ((shift u v).toLinearMap ^ L) f = 0) : f = 0 := by - by_cases hL : L = 0 - · simpa [hL] using hDf - by_contra hne - have hpq' : q < p := by omega - have hweight : (shift (n := n) u u - shift (n := n) v v) f = - ((p - q : ℕ) : ℂ) • f := by - rw [Derivation.sub_apply, euler u hp, euler v hq, - Nat.cast_sub (Nat.le_of_lt hpq'), sub_smul] - have hH : shift (n := n) u u - shift (n := n) v v ≠ 0 := by - intro hzero - have hscalar : ((p - q : ℕ) : ℂ) ≠ 0 := by - exact_mod_cast (Nat.sub_ne_zero_of_lt hpq') - rw [hzero, Derivation.zero_apply] at hweight - exact (smul_ne_zero hscalar hne) hweight.symm - let t := shift_triple (Ne.symm huv) hH - let E := (shift (n := n) v u).toLinearMap - let D := (shift (n := n) u v).toLinearMap - let H := (shift (n := n) u u - shift (n := n) v v).toLinearMap - have hDE (g : Poly m n) : D (E g) = E (D g) - H g := by - have hh := DFunLike.congr_fun t.lie_e_f g - change E (D g) - D (E g) = H g at hh - apply eq_sub_iff_add_eq.mpr - rw [← hh] - abel - have hHD (g : Poly m n) : H (D g) = D (H g) - (2 : ℂ) • D g := by - have hh := DFunLike.congr_fun t.lie_h_f_nsmul g - simp only [Derivation.commutator_apply, Derivation.neg_apply, two_nsmul, - Derivation.add_apply] at hh - change H (D g) - D (H g) = -(D g + D g) at hh - rw [sub_eq_iff_eq_add] at hh - rw [hh] - module - have hnil : ∃ k : ℕ, (E ^ k) f = 0 := - ⟨q + 1, shift_nilpotent (Ne.symm huv) hq⟩ - obtain ⟨k, hk₁, hk₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists hne hnil - have hweights (j : ℕ) : H ((E ^ j) f) = - (((p - q : ℕ) : ℂ) + 2 * j) • ((E ^ j) f) := - t.lie_h_pow_toEnd_e hweight j - have hkernel (j : ℕ) : (D ^ (L + j)) ((E ^ j) f) = 0 := by - induction j with - | zero => simpa using hDf - | succ j ih => - have h := nilpotence_raise D E H hDE hHD (hweights j) ih - simpa only [pow_succ', Module.End.mul_apply, ← Nat.add_assoc] using h - have hprimitive : t.HasPrimitiveVectorWith ((E ^ k) f) - (((p - q + 2 * k : ℕ)) : ℂ) := by - refine ⟨hk₁, ?_, ?_⟩ - · change H ((E ^ k) f) = (((p - q + 2 * k : ℕ)) : ℂ) • ((E ^ k) f) - simpa only [Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat] using hweights k - · change E ((E ^ k) f) = 0 - simpa only [pow_succ', Module.End.mul_apply] using hk₂ - have hbound : L + k ≤ p - q + 2 * k := by omega - exact (hprimitive.pow_toEnd_f_ne_zero_of_eq_nat rfl hbound) (hkernel k) - -theorem shift_raises {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {q : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight v) q) : - (shift u v f).IsWeightedHomogeneous (rowWeight v) (q + 1) := by - rw [shift_eq_sum, derivation_sum_apply] - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - simp only [Derivation.smul_apply, smul_eq_mul] - have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight v) q := - hf.pderiv (by simp [rowWeight, huv]) - have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight v) 1 := by - simpa [rowWeight] using - (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight v) (v, k)) - simpa [add_comm] using hx.mul hd - -theorem shift_spectator {m n : ℕ} {u v w : Fin m} - (huw : u ≠ w) (hvw : v ≠ w) {f : Poly m n} {q : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight w) q) : - (shift u v f).IsWeightedHomogeneous (rowWeight w) q := by - rw [shift_eq_sum, derivation_sum_apply] - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - simp only [Derivation.smul_apply, smul_eq_mul] - have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight w) q := - hf.pderiv (by simp [rowWeight, huw]) - have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight w) 0 := by - simpa [rowWeight, hvw] using - (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight w) (v, k)) - simpa using hx.mul hd - -theorem shift_pow_raises {m n : ℕ} {u v : Fin m} (huv : u ≠ v) - {f : Poly m n} {q : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight v) q) (L : ℕ) : - (((shift u v).toLinearMap ^ L) f).IsWeightedHomogeneous (rowWeight v) (q + L) := by - induction L with - | zero => simpa using hf - | succ L ih => - rw [pow_succ', Module.End.mul_apply] - simpa [Nat.add_assoc] using shift_raises huv ih - -theorem shift_pow_spectator {m n : ℕ} {u v w : Fin m} - (huw : u ≠ w) (hvw : v ≠ w) {f : Poly m n} {q : ℕ} - (hf : f.IsWeightedHomogeneous (rowWeight w) q) (L : ℕ) : - (((shift u v).toLinearMap ^ L) f).IsWeightedHomogeneous (rowWeight w) q := by - induction L with - | zero => simpa using hf - | succ L ih => - rw [pow_succ', Module.End.mul_apply] - exact shift_spectator huw hvw ih - -def shiftSequence {m n : ℕ} (v : Fin m) (L : ℕ) (us : List (Fin m)) : - Poly m n →ₗ[ℂ] Poly m n := - match us with - | [] => LinearMap.id - | u :: us => (shiftSequence v L us).comp ((shift u v).toLinearMap ^ L) - -theorem shiftSequence_kernel_zero {m n : ℕ} {us : List (Fin m)} {v : Fin m} - (hnd : us.Nodup) (hv : v ∉ us) {L j q : ℕ} {f : Poly m n} - (hp : ∀ u ∈ us, f.IsWeightedHomogeneous (rowWeight u) j) - (hq : f.IsWeightedHomogeneous (rowWeight v) q) - (hbound : q + L * us.length ≤ j) - (hz : shiftSequence v L us f = 0) : f = 0 := by - induction us generalizing f q with - | nil => simpa [shiftSequence] using hz - | cons u us ih => - have huv : u ≠ v := by - intro h - exact hv (by simp [h]) - have hnd' := List.nodup_cons.mp hnd - have hv' : v ∉ us := fun h => hv (List.mem_cons_of_mem u h) - have hs : ((shift u v).toLinearMap ^ L) f = 0 := by - apply ih hnd'.2 hv' (q := q + L) - · intro w hw - apply shift_pow_spectator (u := u) (v := v) (w := w) (fun h => hnd'.1 (h.symm ▸ hw)) - (fun h => hv' (h.symm ▸ hw)) (hp w (List.mem_cons_of_mem u hw)) L - · exact shift_pow_raises huv hq L - · simp only [List.length_cons, Nat.mul_succ] at hbound - omega - · exact hz - apply shift_power_kernel_zero huv (hp u (by simp)) hq _ hs - simp only [List.length_cons, Nat.mul_succ] at hbound - omega - -end Foulkes.Differential - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Differential +open MvPolynomial + +abbrev Poly (m n : ℕ) := MvPolynomial (Fin m × Fin n) ℂ + +def shift {m n : ℕ} (u v : Fin m) : Derivation ℂ (Poly m n) (Poly m n) := + MvPolynomial.mkDerivation ℂ fun ij => if ij.1 = u then X (v, ij.2) else 0 + +@[simp] theorem shift_X {m n : ℕ} (u v : Fin m) (ij : Fin m × Fin n) : + shift (n := n) u v (X ij) = if ij.1 = u then X (v, ij.2) else 0 := by + simp [shift] + +@[simp] theorem derivation_sum_apply {m n : ℕ} {ι : Type*} + (s : Finset ι) (D : ι → Derivation ℂ (Poly m n) (Poly m n)) (f : Poly m n) : + (∑ k ∈ s, D k) f = ∑ k ∈ s, D k f := by + classical + induction s using Finset.induction_on with + | empty => simp + | insert x s hx ih => simp [Finset.sum_insert hx, ih] + +theorem shift_eq_sum {m n : ℕ} (u v : Fin m) : + shift (n := n) u v = ∑ k : Fin n, (X (v, k) : Poly m n) • + (pderiv (u, k) : Derivation ℂ (Poly m n) (Poly m n)) := by + apply MvPolynomial.derivation_ext + rintro ⟨r, k⟩ + simp only [shift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] + by_cases h : r = u + · subst r + simp [Pi.single_apply, Prod.mk.injEq] + · simp [Prod.mk.injEq, h] + +theorem shift_commutator {m n : ℕ} {u v : Fin m} (_hne : u ≠ v) : + ⁅shift (n := n) v u, shift (n := n) u v⁆ = + shift (n := n) u u - shift (n := n) v v := by + apply MvPolynomial.derivation_ext + rintro ⟨r, k⟩ + simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X] + split_ifs <;> simp_all [sub_eq_add_neg] + +def rowWeight {m n : ℕ} (u : Fin m) (ij : Fin m × Fin n) : ℕ := + if ij.1 = u then 1 else 0 + +theorem euler {m n : ℕ} (u : Fin m) {f : Poly m n} {p : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight u) p) : + shift (n := n) u u f = (p : ℂ) • f := by + have h := hf.sum_weight_X_mul_pderiv + rw [shift_eq_sum] + simp only [derivation_sum_apply, Derivation.smul_apply, smul_eq_mul] + have hs : (∑ i : Fin m × Fin n, rowWeight u i • (X i * pderiv i f)) = + ∑ k : Fin n, X (u, k) * pderiv (u, k) f := by + rw [Fintype.sum_prod_type, Finset.sum_comm] + simp [rowWeight] + rw [hs] at h + simpa only [Nat.cast_smul_eq_nsmul] using h + +theorem shift_lowers {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {p : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight u) (p + 1)) : + (shift u v f).IsWeightedHomogeneous (rowWeight u) p := by + rw [shift_eq_sum, derivation_sum_apply] + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + simp only [Derivation.smul_apply, smul_eq_mul] + have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight u) p := + hf.pderiv (by simp [rowWeight]) + have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight u) 0 := by + simpa [rowWeight, Ne.symm huv] using + (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight u) (v, k)) + simpa using hx.mul hd + +theorem pderiv_zero_degree {m n : ℕ} {u : Fin m} {f : Poly m n} + (hf : f.IsWeightedHomogeneous (rowWeight u) 0) (k : Fin n) : + pderiv (u, k) f = 0 := by + ext d + rw [coeff_pderiv, AddMonoidAlgebra.coeff_zero] + have hc : f.coeff (d + Finsupp.single (u, k) 1) = 0 := + hf.coeff_eq_zero _ (by simp [map_add, Finsupp.weight_single, rowWeight]) + simp [hc] + +theorem shift_zero_degree {m n : ℕ} {u v : Fin m} {f : Poly m n} + (hf : f.IsWeightedHomogeneous (rowWeight u) 0) : shift u v f = 0 := by + rw [shift_eq_sum, derivation_sum_apply] + simp [pderiv_zero_degree hf] + +theorem shift_nilpotent {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {p : ℕ} (hf : f.IsWeightedHomogeneous (rowWeight u) p) : + ((shift u v).toLinearMap ^ (p + 1)) f = 0 := by + induction p generalizing f with + | zero => simpa using shift_zero_degree (v := v) hf + | succ p ih => + rw [pow_succ, Module.End.mul_apply] + exact ih (shift_lowers huv hf) + +theorem shift_triple {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + (hH : shift (n := n) v v - shift (n := n) u u ≠ 0) : + IsSl2Triple (shift (n := n) v v - shift (n := n) u u) + (shift (n := n) u v) (shift (n := n) v u) where + h_ne_zero := hH + lie_e_f := shift_commutator (Ne.symm huv) + lie_h_e_nsmul := by + have hvu := Ne.symm huv + apply MvPolynomial.derivation_ext + rintro ⟨r, k⟩ + simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X, map_sub, + two_nsmul, Derivation.add_apply] + split_ifs <;> simp_all [sub_eq_add_neg] + lie_h_f_nsmul := by + have hvu := Ne.symm huv + apply MvPolynomial.derivation_ext + rintro ⟨r, k⟩ + simp only [Derivation.commutator_apply, Derivation.sub_apply, shift_X, map_sub, + two_nsmul, Derivation.add_apply, Derivation.neg_apply] + split_ifs <;> simp_all [sub_eq_add_neg] + +theorem shift_kernel_zero {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {p q : ℕ} + (hp : f.IsWeightedHomogeneous (rowWeight u) p) + (hq : f.IsWeightedHomogeneous (rowWeight v) q) + (hpq : q < p) (hDf : shift u v f = 0) : f = 0 := by + by_contra hne + have hweight : (shift (n := n) v v - shift (n := n) u u) f = + ((q : ℂ) - p) • f := by + rw [Derivation.sub_apply, euler v hq, euler u hp, sub_smul] + have hH : shift (n := n) v v - shift (n := n) u u ≠ 0 := by + intro hzero + have hscalar : (q : ℂ) - p ≠ 0 := by + rw [sub_ne_zero] + exact_mod_cast (Nat.ne_of_lt hpq) + rw [hzero, Derivation.zero_apply] at hweight + exact (smul_ne_zero hscalar hne) hweight.symm + let t := shift_triple huv hH + have hprimitive : t.HasPrimitiveVectorWith f ((q : ℂ) - p) := + { ne_zero := hne, lie_h := hweight, lie_e := hDf } + let E := LieModule.toEnd ℂ (Derivation ℂ (Poly m n) (Poly m n)) (Poly m n) + (shift (n := n) v u) + have hnil : ∃ k : ℕ, (E ^ k) f = 0 := + ⟨q + 1, shift_nilpotent (Ne.symm huv) hq⟩ + obtain ⟨k, hk₁, hk₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists hne hnil + have hrec := hprimitive.lie_e_pow_succ_toEnd_f k + change shift u v ((E ^ (k + 1)) f) = + ((k + 1 : ℂ) * ((q : ℂ) - p - k)) • ((E ^ k) f) at hrec + rw [hk₂, map_zero, eq_comm, smul_eq_zero_iff_left hk₁, mul_eq_zero, + sub_eq_zero] at hrec + have heq : (q : ℂ) - p = k := hrec.resolve_left (Nat.cast_add_one_ne_zero k) + have heq' : q = k + p := by exact_mod_cast (sub_eq_iff_eq_add.mp heq) + omega + +theorem shift_injOn {m n : ℕ} {u v : Fin m} (huv : u ≠ v) {p q : ℕ} + (hpq : q < p) : + Set.InjOn (shift (n := n) u v) + {f | f.IsWeightedHomogeneous (rowWeight u) p ∧ + f.IsWeightedHomogeneous (rowWeight v) q} := by + intro f hf g hg hfg + apply sub_eq_zero.mp + exact shift_kernel_zero huv (hf.1.sub hg.1) (hf.2.sub hg.2) hpq + (by rw [map_sub, hfg, sub_self]) + +theorem nilpotence_raise {M : Type*} [AddCommGroup M] [Module ℂ M] + (D E H : Module.End ℂ M) + (hDE : ∀ x, D (E x) = E (D x) - H x) + (hHD : ∀ x, H (D x) = D (H x) - (2 : ℂ) • D x) + {x : M} {μ : ℂ} (hx : H x = μ • x) {L : ℕ} + (hL : (D ^ L) x = 0) : (D ^ (L + 1)) (E x) = 0 := by + induction L generalizing x μ with + | zero => + simp only [pow_zero, Module.End.one_apply] at hL + simp [hL] + | succ L ih => + have hxD : H (D x) = (μ - 2) • D x := by + rw [hHD, hx, map_smul, sub_smul] + have hLD : (D ^ L) (D x) = 0 := by + simpa only [pow_succ, Module.End.mul_apply] using hL + have hED := ih hxD hLD + rw [pow_succ, Module.End.mul_apply, hDE, map_sub, hx, map_smul] + change (D ^ (L + 1)) (E (D x)) - μ • (D ^ (L + 1)) x = 0 + rw [hED, hL, smul_zero, sub_self] + +theorem shift_power_kernel_zero {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {p q L : ℕ} + (hp : f.IsWeightedHomogeneous (rowWeight u) p) + (hq : f.IsWeightedHomogeneous (rowWeight v) q) + (hpq : q + L ≤ p) (hDf : ((shift u v).toLinearMap ^ L) f = 0) : f = 0 := by + by_cases hL : L = 0 + · simpa [hL] using hDf + by_contra hne + have hpq' : q < p := by omega + have hweight : (shift (n := n) u u - shift (n := n) v v) f = + ((p - q : ℕ) : ℂ) • f := by + rw [Derivation.sub_apply, euler u hp, euler v hq, + Nat.cast_sub (Nat.le_of_lt hpq'), sub_smul] + have hH : shift (n := n) u u - shift (n := n) v v ≠ 0 := by + intro hzero + have hscalar : ((p - q : ℕ) : ℂ) ≠ 0 := by + exact_mod_cast (Nat.sub_ne_zero_of_lt hpq') + rw [hzero, Derivation.zero_apply] at hweight + exact (smul_ne_zero hscalar hne) hweight.symm + let t := shift_triple (Ne.symm huv) hH + let E := (shift (n := n) v u).toLinearMap + let D := (shift (n := n) u v).toLinearMap + let H := (shift (n := n) u u - shift (n := n) v v).toLinearMap + have hDE (g : Poly m n) : D (E g) = E (D g) - H g := by + have hh := DFunLike.congr_fun t.lie_e_f g + change E (D g) - D (E g) = H g at hh + apply eq_sub_iff_add_eq.mpr + rw [← hh] + abel + have hHD (g : Poly m n) : H (D g) = D (H g) - (2 : ℂ) • D g := by + have hh := DFunLike.congr_fun t.lie_h_f_nsmul g + simp only [Derivation.commutator_apply, Derivation.neg_apply, two_nsmul, + Derivation.add_apply] at hh + change H (D g) - D (H g) = -(D g + D g) at hh + rw [sub_eq_iff_eq_add] at hh + rw [hh] + module + have hnil : ∃ k : ℕ, (E ^ k) f = 0 := + ⟨q + 1, shift_nilpotent (Ne.symm huv) hq⟩ + obtain ⟨k, hk₁, hk₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists hne hnil + have hweights (j : ℕ) : H ((E ^ j) f) = + (((p - q : ℕ) : ℂ) + 2 * j) • ((E ^ j) f) := + t.lie_h_pow_toEnd_e hweight j + have hkernel (j : ℕ) : (D ^ (L + j)) ((E ^ j) f) = 0 := by + induction j with + | zero => simpa using hDf + | succ j ih => + have h := nilpotence_raise D E H hDE hHD (hweights j) ih + simpa only [pow_succ', Module.End.mul_apply, ← Nat.add_assoc] using h + have hprimitive : t.HasPrimitiveVectorWith ((E ^ k) f) + (((p - q + 2 * k : ℕ)) : ℂ) := by + refine ⟨hk₁, ?_, ?_⟩ + · change H ((E ^ k) f) = (((p - q + 2 * k : ℕ)) : ℂ) • ((E ^ k) f) + simpa only [Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat] using hweights k + · change E ((E ^ k) f) = 0 + simpa only [pow_succ', Module.End.mul_apply] using hk₂ + have hbound : L + k ≤ p - q + 2 * k := by omega + exact (hprimitive.pow_toEnd_f_ne_zero_of_eq_nat rfl hbound) (hkernel k) + +theorem shift_raises {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {q : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight v) q) : + (shift u v f).IsWeightedHomogeneous (rowWeight v) (q + 1) := by + rw [shift_eq_sum, derivation_sum_apply] + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + simp only [Derivation.smul_apply, smul_eq_mul] + have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight v) q := + hf.pderiv (by simp [rowWeight, huv]) + have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight v) 1 := by + simpa [rowWeight] using + (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight v) (v, k)) + simpa [add_comm] using hx.mul hd + +theorem shift_spectator {m n : ℕ} {u v w : Fin m} + (huw : u ≠ w) (hvw : v ≠ w) {f : Poly m n} {q : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight w) q) : + (shift u v f).IsWeightedHomogeneous (rowWeight w) q := by + rw [shift_eq_sum, derivation_sum_apply] + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + simp only [Derivation.smul_apply, smul_eq_mul] + have hd : (pderiv (u, k) f).IsWeightedHomogeneous (rowWeight w) q := + hf.pderiv (by simp [rowWeight, huw]) + have hx : (X (v, k) : Poly m n).IsWeightedHomogeneous (rowWeight w) 0 := by + simpa [rowWeight, hvw] using + (MvPolynomial.isWeightedHomogeneous_X (R := ℂ) (rowWeight w) (v, k)) + simpa using hx.mul hd + +theorem shift_pow_raises {m n : ℕ} {u v : Fin m} (huv : u ≠ v) + {f : Poly m n} {q : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight v) q) (L : ℕ) : + (((shift u v).toLinearMap ^ L) f).IsWeightedHomogeneous (rowWeight v) (q + L) := by + induction L with + | zero => simpa using hf + | succ L ih => + rw [pow_succ', Module.End.mul_apply] + simpa [Nat.add_assoc] using shift_raises huv ih + +theorem shift_pow_spectator {m n : ℕ} {u v w : Fin m} + (huw : u ≠ w) (hvw : v ≠ w) {f : Poly m n} {q : ℕ} + (hf : f.IsWeightedHomogeneous (rowWeight w) q) (L : ℕ) : + (((shift u v).toLinearMap ^ L) f).IsWeightedHomogeneous (rowWeight w) q := by + induction L with + | zero => simpa using hf + | succ L ih => + rw [pow_succ', Module.End.mul_apply] + exact shift_spectator huw hvw ih + +def shiftSequence {m n : ℕ} (v : Fin m) (L : ℕ) (us : List (Fin m)) : + Poly m n →ₗ[ℂ] Poly m n := + match us with + | [] => LinearMap.id + | u :: us => (shiftSequence v L us).comp ((shift u v).toLinearMap ^ L) + +theorem shiftSequence_kernel_zero {m n : ℕ} {us : List (Fin m)} {v : Fin m} + (hnd : us.Nodup) (hv : v ∉ us) {L j q : ℕ} {f : Poly m n} + (hp : ∀ u ∈ us, f.IsWeightedHomogeneous (rowWeight u) j) + (hq : f.IsWeightedHomogeneous (rowWeight v) q) + (hbound : q + L * us.length ≤ j) + (hz : shiftSequence v L us f = 0) : f = 0 := by + induction us generalizing f q with + | nil => simpa [shiftSequence] using hz + | cons u us ih => + have huv : u ≠ v := by + intro h + exact hv (by simp [h]) + have hnd' := List.nodup_cons.mp hnd + have hv' : v ∉ us := fun h => hv (List.mem_cons_of_mem u h) + have hs : ((shift u v).toLinearMap ^ L) f = 0 := by + apply ih hnd'.2 hv' (q := q + L) + · intro w hw + apply shift_pow_spectator (u := u) (v := v) (w := w) (fun h => hnd'.1 (h.symm ▸ hw)) + (fun h => hv' (h.symm ▸ hw)) (hp w (List.mem_cons_of_mem u hw)) L + · exact shift_pow_raises huv hq L + · simp only [List.length_cons, Nat.mul_succ] at hbound + omega + · exact hz + apply shift_power_kernel_zero huv (hp u (by simp)) hq _ hs + simp only [List.length_cons, Nat.mul_succ] at hbound + omega + +end Foulkes.Differential + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookup.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookup.lean index 37705eca435acc547db430a70eeea91980f0cf34..e076e43cb403e86093bf1f53515c3f7d9b2433e7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookup.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookup.lean @@ -1,124 +1,124 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm - -namespace OAI - -noncomputable section - -namespace Foulkes.FastLookup -open MvPolynomial Foulkes.Strips Foulkes.Lookup - -lemma coeffZ_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (v : Fin n → ℤ) (σ : Equiv.Perm (Fin n)) : - coeffZ (v ∘ σ) p = (Equiv.Perm.sign σ : ℤ) * coeffZ v p := by - classical - have hh : (∀ j, 0 ≤ v (σ j)) ↔ ∀ j, 0 ≤ v j := - ⟨fun h j => by simpa using h (σ.symm j), fun h j => h (σ j)⟩ - by_cases hn : ∀ j, 0 ≤ v j - · simp only [coeffZ, Function.comp_apply, ite_eq_left hn, ite_eq_left (hh.mpr hn)] - exact coeff_comp hp (fun j => (v j).toNat) σ - · simp only [coeffZ, Function.comp_apply, ite_eq_right hn, ite_eq_right (mt hh.mp hn), mul_zero] - -abbrev State (n : ℕ) := ℤ × (Fin n → ℤ) - -def compareStep {n : ℕ} (ij : Fin n × Fin n) (s : State n) : State n := - if s.2 ij.1 < s.2 ij.2 then (-s.1, s.2 ∘ Equiv.swap ij.1 ij.2) else s - -lemma compareStep_sound {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (ij : Fin n × Fin n) (s : State n) : - (compareStep ij s).1 * coeffZ (compareStep ij s).2 p = s.1 * coeffZ s.2 p := by - unfold compareStep - split_ifs with h - · have hij : ij.1 ≠ ij.2 := fun heq => by simp [heq] at h - dsimp only - rw [coeffZ_comp hp, Equiv.Perm.sign_swap hij] - simp - · rfl - -def run {n : ℕ} (steps : List (Fin n × Fin n)) (s : State n) : State n := - steps.foldl (fun s ij => compareStep ij s) s - -lemma run_sound {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (steps : List (Fin n × Fin n)) (s : State n) : - (run steps s).1 * coeffZ (run steps s).2 p = s.1 * coeffZ s.2 p := by - induction steps generalizing s with - | nil => rfl - | cons ij steps ih => - exact (ih (compareStep ij s)).trans (compareStep_sound hp ij s) - -def network (n : ℕ) : List (Fin n × Fin n) := - (List.finRange n).flatMap fun i => - ((List.finRange n).filter (fun j => i < j)).map fun j => (i,j) - -def finish {n : ℕ} (f : (Fin n → ℕ) → ℤ) (s : State n) : Option ℤ := - if ∀ j, 0 ≤ s.2 j then - if ∀ i j, i < j → (s.2 j).toNat < (s.2 i).toNat then - some (s.1 * f (fun j => (s.2 j).toNat - staircase n j)) - else if ∃ i j, i ≠ j ∧ s.2 i = s.2 j then some 0 else none - else some 0 - -lemma finish_sound {n : ℕ} (p : MvPolynomial (Fin n) ℤ) - (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) - (f : (Fin n → ℕ) → ℤ) - (hf : ∀ mu, Antitone mu → f mu = schurCoeff p mu) - (s : State n) (z : ℤ) (hz : finish f s = some z) : - z = s.1 * coeffZ s.2 (p * alternant (staircase n)) := by - classical - unfold finish at hz - split_ifs at hz with hn hs hr - · have hstrict : StrictAnti (fun j => (s.2 j).toNat) := hs - have ha := unshift_antitone hstrict - have he := shifted_unshift hstrict - have hval : f (fun j => (s.2 j).toNat - staircase n j) = - (p * alternant (staircase n)).coeff (expVector (fun j => (s.2 j).toNat)) := by - change f (unshift (fun j => (s.2 j).toNat)) = _ - rw [hf _ ha] - unfold schurCoeff - rw [he] - have hz' := Option.some.inj hz - rw [← hz', hval] - simp only [coeffZ, ite_eq_left hn] - · have hz' := Option.some.inj hz - obtain ⟨i,j,hij,he⟩ := hr - have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) - have hc := coeff_repeated ha (fun j => (s.2 j).toNat) hij (congrArg Int.toNat he) - rw [← hz'] - simp only [coeffZ, ite_eq_left hn, hc, mul_zero] - · have hz' := Option.some.inj hz - rw [← hz'] - simp only [coeffZ, ite_eq_right hn, mul_zero] - -def checkedLookup {n : ℕ} (f : (Fin n → ℕ) → ℤ) (v : Fin n → ℤ) : Option ℤ := - finish f (run (network n) (1,v)) - -theorem checkedLookup_sound {n : ℕ} (p : MvPolynomial (Fin n) ℤ) - (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) - (f : (Fin n → ℕ) → ℤ) - (hf : ∀ mu, Antitone mu → f mu = schurCoeff p mu) - (v : Fin n → ℤ) (z : ℤ) (hz : checkedLookup f v = some z) : - z = signedLookup (schurCoeff p) v := by - rw [signedLookup_eq_coeffZ p hp] - have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) - calc - z = _ := finish_sound p hp f hf _ z hz - _ = _ := by simpa only [one_mul] using run_sound ha (network n) (1,v) - -end Foulkes.FastLookup - - -noncomputable section - -namespace Foulkes.FastLookup - -example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,3,2,10] = some (-7) := by - decide +kernel -example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,3,2,1] = some 0 := by - decide +kernel -example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,-3,2,10] = some 0 := by - decide +kernel -end Foulkes.FastLookup - -end -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm + +namespace OAI + +noncomputable section + +namespace Foulkes.FastLookup +open MvPolynomial Foulkes.Strips Foulkes.Lookup + +lemma coeffZ_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (v : Fin n → ℤ) (σ : Equiv.Perm (Fin n)) : + coeffZ (v ∘ σ) p = (Equiv.Perm.sign σ : ℤ) * coeffZ v p := by + classical + have hh : (∀ j, 0 ≤ v (σ j)) ↔ ∀ j, 0 ≤ v j := + ⟨fun h j => by simpa using h (σ.symm j), fun h j => h (σ j)⟩ + by_cases hn : ∀ j, 0 ≤ v j + · simp only [coeffZ, Function.comp_apply, ite_eq_left hn, ite_eq_left (hh.mpr hn)] + exact coeff_comp hp (fun j => (v j).toNat) σ + · simp only [coeffZ, Function.comp_apply, ite_eq_right hn, ite_eq_right (mt hh.mp hn), mul_zero] + +abbrev State (n : ℕ) := ℤ × (Fin n → ℤ) + +def compareStep {n : ℕ} (ij : Fin n × Fin n) (s : State n) : State n := + if s.2 ij.1 < s.2 ij.2 then (-s.1, s.2 ∘ Equiv.swap ij.1 ij.2) else s + +lemma compareStep_sound {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (ij : Fin n × Fin n) (s : State n) : + (compareStep ij s).1 * coeffZ (compareStep ij s).2 p = s.1 * coeffZ s.2 p := by + unfold compareStep + split_ifs with h + · have hij : ij.1 ≠ ij.2 := fun heq => by simp [heq] at h + dsimp only + rw [coeffZ_comp hp, Equiv.Perm.sign_swap hij] + simp + · rfl + +def run {n : ℕ} (steps : List (Fin n × Fin n)) (s : State n) : State n := + steps.foldl (fun s ij => compareStep ij s) s + +lemma run_sound {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (steps : List (Fin n × Fin n)) (s : State n) : + (run steps s).1 * coeffZ (run steps s).2 p = s.1 * coeffZ s.2 p := by + induction steps generalizing s with + | nil => rfl + | cons ij steps ih => + exact (ih (compareStep ij s)).trans (compareStep_sound hp ij s) + +def network (n : ℕ) : List (Fin n × Fin n) := + (List.finRange n).flatMap fun i => + ((List.finRange n).filter (fun j => i < j)).map fun j => (i,j) + +def finish {n : ℕ} (f : (Fin n → ℕ) → ℤ) (s : State n) : Option ℤ := + if ∀ j, 0 ≤ s.2 j then + if ∀ i j, i < j → (s.2 j).toNat < (s.2 i).toNat then + some (s.1 * f (fun j => (s.2 j).toNat - staircase n j)) + else if ∃ i j, i ≠ j ∧ s.2 i = s.2 j then some 0 else none + else some 0 + +lemma finish_sound {n : ℕ} (p : MvPolynomial (Fin n) ℤ) + (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) + (f : (Fin n → ℕ) → ℤ) + (hf : ∀ mu, Antitone mu → f mu = schurCoeff p mu) + (s : State n) (z : ℤ) (hz : finish f s = some z) : + z = s.1 * coeffZ s.2 (p * alternant (staircase n)) := by + classical + unfold finish at hz + split_ifs at hz with hn hs hr + · have hstrict : StrictAnti (fun j => (s.2 j).toNat) := hs + have ha := unshift_antitone hstrict + have he := shifted_unshift hstrict + have hval : f (fun j => (s.2 j).toNat - staircase n j) = + (p * alternant (staircase n)).coeff (expVector (fun j => (s.2 j).toNat)) := by + change f (unshift (fun j => (s.2 j).toNat)) = _ + rw [hf _ ha] + unfold schurCoeff + rw [he] + have hz' := Option.some.inj hz + rw [← hz', hval] + simp only [coeffZ, ite_eq_left hn] + · have hz' := Option.some.inj hz + obtain ⟨i,j,hij,he⟩ := hr + have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) + have hc := coeff_repeated ha (fun j => (s.2 j).toNat) hij (congrArg Int.toNat he) + rw [← hz'] + simp only [coeffZ, ite_eq_left hn, hc, mul_zero] + · have hz' := Option.some.inj hz + rw [← hz'] + simp only [coeffZ, ite_eq_right hn, mul_zero] + +def checkedLookup {n : ℕ} (f : (Fin n → ℕ) → ℤ) (v : Fin n → ℤ) : Option ℤ := + finish f (run (network n) (1,v)) + +theorem checkedLookup_sound {n : ℕ} (p : MvPolynomial (Fin n) ℤ) + (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) + (f : (Fin n → ℕ) → ℤ) + (hf : ∀ mu, Antitone mu → f mu = schurCoeff p mu) + (v : Fin n → ℤ) (z : ℤ) (hz : checkedLookup f v = some z) : + z = signedLookup (schurCoeff p) v := by + rw [signedLookup_eq_coeffZ p hp] + have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) + calc + z = _ := finish_sound p hp f hf _ z hz + _ = _ := by simpa only [one_mul] using run_sound ha (network n) (1,v) + +end Foulkes.FastLookup + + +noncomputable section + +namespace Foulkes.FastLookup + +example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,3,2,10] = some (-7) := by + decide +kernel +example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,3,2,1] = some 0 := by + decide +kernel +example : checkedLookup (fun (_ : Fin 6 → ℕ) => (7 : ℤ)) ![1,8,5,-3,2,10] = some 0 := by + decide +kernel +end Foulkes.FastLookup + +end +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookupExact.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookupExact.lean index ce4ef96fb75593d7b7bbca367579cebc25842163..92fa562aee729f30fd9cd2df4d806562a818f159 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookupExact.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/FastLookupExact.lean @@ -1,87 +1,87 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.FastLookup - -namespace OAI - -noncomputable section - -namespace Foulkes.FastLookup -open MvPolynomial Foulkes.Strips Foulkes.Lookup - -lemma compareStep_perm {n : ℕ} (ij : Fin n × Fin n) (s : State n) : - ∃ σ : Equiv.Perm (Fin n), compareStep ij s = - (s.1 * (Equiv.Perm.sign σ : ℤ), s.2 ∘ σ) := by - unfold compareStep - split_ifs with h - · refine ⟨Equiv.swap ij.1 ij.2, ?_⟩ - have hij : ij.1 ≠ ij.2 := fun heq => by simp [heq] at h - simp [Equiv.Perm.sign_swap hij] - · refine ⟨1, ?_⟩ - simp - -lemma run_perm {n : ℕ} (steps : List (Fin n × Fin n)) (s : State n) : - ∃ σ : Equiv.Perm (Fin n), run steps s = - (s.1 * (Equiv.Perm.sign σ : ℤ), s.2 ∘ σ) := by - induction steps generalizing s with - | nil => exact ⟨1, by simp [run]⟩ - | cons ij steps ih => - obtain ⟨τ,hτ⟩ := compareStep_perm ij s - obtain ⟨σ,hσ⟩ := ih (compareStep ij s) - refine ⟨τ * σ, ?_⟩ - change run steps (compareStep ij s) = _ - rw [hσ, hτ] - simp only [map_mul, Units.val_mul, mul_assoc, Equiv.Perm.coe_mul] - rfl - -lemma finish_perm_exact {n : ℕ} (f : (Fin n → ℕ) → ℤ) - (v : Fin n → ℤ) (σ : Equiv.Perm (Fin n)) (z : ℤ) - (hz : finish f ((Equiv.Perm.sign σ : ℤ), v ∘ σ) = some z) : - z = signedLookup f v := by - classical - have hnon : (∀ j, 0 ≤ v (σ j)) ↔ ∀ j, 0 ≤ v j := - ⟨fun h j => by simpa using h (σ.symm j), fun h j => h (σ j)⟩ - unfold finish at hz - dsimp only [Function.comp_apply] at hz - split_ifs at hz with hn hs hr - · let w : Fin n → ℕ := fun j => (v j).toNat - have hstrict : StrictAnti (w ∘ σ) := hs - have hw : Function.Injective w := by - intro i j hij - have hh : σ.symm i = σ.symm j := hstrict.injective (by simpa using hij) - exact σ.symm.injective hh - have he : w ∘ σ = w ∘ sortDesc w := - Tuple.unique_antitone hstrict.antitone (sortDesc_antitone w) - have hσ : σ = sortDesc w := Equiv.ext fun j => hw (congrFun he j) - have hv : (fun j => (v (σ j)).toNat - staircase n j) = sortedPartition w := by - rw [hσ] - rfl - have hz' := Option.some.inj hz - rw [← hz', hv, hσ] - simp only [signedLookup, dite_eq_left (hnon.mp hn)] - change _ = if Function.Injective w then (Equiv.Perm.sign (sortDesc w) : ℤ) * f (sortedPartition w) else 0 - rw [ite_eq_left hw] - · have hz' := Option.some.inj hz - obtain ⟨i,j,hij,he⟩ := hr - have hw : ¬Function.Injective (fun j => (v j).toNat) := by - intro hw - exact hij (σ.injective (hw (congrArg Int.toNat he))) - rw [← hz'] - simp only [signedLookup, dite_eq_left (hnon.mp hn), ite_eq_right hw] - · have hz' := Option.some.inj hz - rw [← hz'] - simp only [signedLookup, dite_eq_right (mt hnon.mpr hn)] - -theorem checkedLookup_exact {n : ℕ} (f : (Fin n → ℕ) → ℤ) - (v : Fin n → ℤ) (z : ℤ) (hz : checkedLookup f v = some z) : - z = signedLookup f v := by - obtain ⟨σ,hσ⟩ := run_perm (network n) (1,v) - unfold checkedLookup at hz - rw [hσ] at hz - simp only [one_mul] at hz - exact finish_perm_exact f v σ z hz - -end Foulkes.FastLookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.FastLookup + +namespace OAI + +noncomputable section + +namespace Foulkes.FastLookup +open MvPolynomial Foulkes.Strips Foulkes.Lookup + +lemma compareStep_perm {n : ℕ} (ij : Fin n × Fin n) (s : State n) : + ∃ σ : Equiv.Perm (Fin n), compareStep ij s = + (s.1 * (Equiv.Perm.sign σ : ℤ), s.2 ∘ σ) := by + unfold compareStep + split_ifs with h + · refine ⟨Equiv.swap ij.1 ij.2, ?_⟩ + have hij : ij.1 ≠ ij.2 := fun heq => by simp [heq] at h + simp [Equiv.Perm.sign_swap hij] + · refine ⟨1, ?_⟩ + simp + +lemma run_perm {n : ℕ} (steps : List (Fin n × Fin n)) (s : State n) : + ∃ σ : Equiv.Perm (Fin n), run steps s = + (s.1 * (Equiv.Perm.sign σ : ℤ), s.2 ∘ σ) := by + induction steps generalizing s with + | nil => exact ⟨1, by simp [run]⟩ + | cons ij steps ih => + obtain ⟨τ,hτ⟩ := compareStep_perm ij s + obtain ⟨σ,hσ⟩ := ih (compareStep ij s) + refine ⟨τ * σ, ?_⟩ + change run steps (compareStep ij s) = _ + rw [hσ, hτ] + simp only [map_mul, Units.val_mul, mul_assoc, Equiv.Perm.coe_mul] + rfl + +lemma finish_perm_exact {n : ℕ} (f : (Fin n → ℕ) → ℤ) + (v : Fin n → ℤ) (σ : Equiv.Perm (Fin n)) (z : ℤ) + (hz : finish f ((Equiv.Perm.sign σ : ℤ), v ∘ σ) = some z) : + z = signedLookup f v := by + classical + have hnon : (∀ j, 0 ≤ v (σ j)) ↔ ∀ j, 0 ≤ v j := + ⟨fun h j => by simpa using h (σ.symm j), fun h j => h (σ j)⟩ + unfold finish at hz + dsimp only [Function.comp_apply] at hz + split_ifs at hz with hn hs hr + · let w : Fin n → ℕ := fun j => (v j).toNat + have hstrict : StrictAnti (w ∘ σ) := hs + have hw : Function.Injective w := by + intro i j hij + have hh : σ.symm i = σ.symm j := hstrict.injective (by simpa using hij) + exact σ.symm.injective hh + have he : w ∘ σ = w ∘ sortDesc w := + Tuple.unique_antitone hstrict.antitone (sortDesc_antitone w) + have hσ : σ = sortDesc w := Equiv.ext fun j => hw (congrFun he j) + have hv : (fun j => (v (σ j)).toNat - staircase n j) = sortedPartition w := by + rw [hσ] + rfl + have hz' := Option.some.inj hz + rw [← hz', hv, hσ] + simp only [signedLookup, dite_eq_left (hnon.mp hn)] + change _ = if Function.Injective w then (Equiv.Perm.sign (sortDesc w) : ℤ) * f (sortedPartition w) else 0 + rw [ite_eq_left hw] + · have hz' := Option.some.inj hz + obtain ⟨i,j,hij,he⟩ := hr + have hw : ¬Function.Injective (fun j => (v j).toNat) := by + intro hw + exact hij (σ.injective (hw (congrArg Int.toNat he))) + rw [← hz'] + simp only [signedLookup, dite_eq_left (hnon.mp hn), ite_eq_right hw] + · have hz' := Option.some.inj hz + rw [← hz'] + simp only [signedLookup, dite_eq_right (mt hnon.mpr hn)] + +theorem checkedLookup_exact {n : ℕ} (f : (Fin n → ℕ) → ℤ) + (v : Fin n → ℤ) (z : ℤ) (hz : checkedLookup f v = some z) : + z = signedLookup f v := by + obtain ⟨σ,hσ⟩ := run_perm (network n) (1,v) + unfold checkedLookup at hz + rw [hσ] at hz + simp only [one_mul] at hz + exact finish_perm_exact f v σ z hz + +end Foulkes.FastLookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/GenericShift.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/GenericShift.lean index 255b6dc3380451acab6d52b9550c4dc5b66ec8a0..a9d40dd0d1237c5e23ec0480090001caa3b78c31 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/GenericShift.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/GenericShift.lean @@ -1,214 +1,214 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan - -namespace OAI - -noncomputable section - -namespace Foulkes.GenericShift -open MvPolynomial -open Foulkes.PolynomialSpan - -variable {A : Type*} [CommRing A] - -abbrev Poly (A : Type*) [CommRing A] (m n : ℕ) := MvPolynomial (Fin m × Fin n) A - -def shift {m n : ℕ} (u v : Fin m) : Derivation A (Poly A m n) (Poly A m n) := - mkDerivation A fun ij => if ij.1 = u then X (v, ij.2) else 0 - -@[simp] lemma shift_X {m n : ℕ} (u v : Fin m) (ij : Fin m × Fin n) : - shift (A := A) u v (X ij) = if ij.1 = u then X (v, ij.2) else 0 := by - simp [shift] - -lemma derivation_sum_apply {ι : Type*} {m n : ℕ} - (s : Finset ι) (D : ι → Derivation A (Poly A m n) (Poly A m n)) (f : Poly A m n) : - (∑ k ∈ s, D k) f = ∑ k ∈ s, D k f := by - classical - induction s using Finset.induction_on with - | empty => simp - | insert x s hx ih => simp [Finset.sum_insert hx, ih] - -lemma shift_eq_sum {m n : ℕ} (u v : Fin m) : - shift (A := A) (n := n) u v = ∑ k : Fin n, (X (v, k) : Poly A m n) • - (pderiv (u, k) : Derivation A (Poly A m n) (Poly A m n)) := by - apply MvPolynomial.derivation_ext - rintro ⟨r, k⟩ - simp only [shift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] - by_cases h : r = u - · subst r - simp [Pi.single_apply, Prod.mk.injEq] - · simp [Prod.mk.injEq, h] - -lemma mapCoeffs_shift [Algebra ℂ A] {m n : ℕ} - (l : A →ₗ[ℂ] ℂ) (u v : Fin m) (f : Poly A m n) : - mapCoeffs l (shift u v f) = shift u v (mapCoeffs l f) := by - simp only [shift_eq_sum, derivation_sum_apply, Derivation.smul_apply, - smul_eq_mul, mapCoeffs_sum, mapCoeffs_X_mul, mapCoeffs_pderiv] - -lemma mapCoeffs_shift_pow [Algebra ℂ A] {m n : ℕ} - (l : A →ₗ[ℂ] ℂ) (u v : Fin m) (f : Poly A m n) (L : ℕ) : - mapCoeffs l (((shift u v).toLinearMap ^ L) f) = - ((shift u v).toLinearMap ^ L) (mapCoeffs l f) := by - induction L with - | zero => rfl - | succ L ih => - simpa only [pow_succ', Module.End.mul_apply, Derivation.coeFn_coe, mapCoeffs_shift] using - congrArg (shift u v) ih - -def rowLinear {m n : ℕ} (u : Fin m) (c : Fin n → A) : Poly A m n := - ∑ k, c k • X (u, k) - -@[simp] lemma shift_rowLinear {m n : ℕ} (u v w : Fin m) (c : Fin n → A) : - shift u v (rowLinear w c) = if w = u then rowLinear v c else 0 := by - simp [rowLinear, map_sum, shift_X] - -lemma pow_apply_mul_of_left_zero {B : Type*} [CommRing B] [Algebra A B] - (D : Derivation A B B) {g : B} (hg : D g = 0) (f : B) (L : ℕ) : - (D.toLinearMap ^ L) (g * f) = g * (D.toLinearMap ^ L) f := by - induction L with - | zero => rfl - | succ L ih => - simp only [pow_succ', Module.End.mul_apply, ih, Derivation.coeFn_coe, D.leibniz, hg, - smul_eq_mul, mul_zero, add_zero] - -lemma pow_apply_pow {B : Type*} [CommRing B] [Algebra A B] - (D : Derivation A B B) {f g : B} (hf : D f = g) (hg : D g = 0) - (j L : ℕ) (hL : L ≤ j) : - (D.toLinearMap ^ L) (f ^ j) = j.descFactorial L • (g ^ L * f ^ (j - L)) := by - induction L with - | zero => simp - | succ L ih => - have hLj : L ≤ j := Nat.le_trans (Nat.le_succ L) hL - rw [pow_succ', Module.End.mul_apply, ih hLj, Derivation.coeFn_coe, map_nsmul] - have hkill : D (g ^ L) = 0 := by simp [D.leibniz_pow, hg] - rw [D.leibniz, hkill, smul_zero, add_zero, D.leibniz_pow, hf] - simp only [smul_eq_mul, nsmul_eq_mul] - rw [Nat.descFactorial_succ] - have hsub : j - L - 1 = j - (L + 1) := by omega - rw [hsub, pow_succ] - push_cast - ring - -lemma derivation_prod_zero {B ι : Type*} [CommRing B] [Algebra A B] - (D : Derivation A B B) (s : Finset ι) (f : ι → B) - (h : ∀ i ∈ s, D (f i) = 0) : D (∏ i ∈ s, f i) = 0 := by - classical - induction s using Finset.induction_on with - | empty => simp - | insert i s hi ih => - rw [Finset.prod_insert hi, D.leibniz, h i (by simp), - ih (fun k hk => h k (Finset.mem_insert_of_mem hk))] - simp - -def mixedProduct {B ι : Type*} [CommRing B] [Fintype ι] [DecidableEq ι] - (x y : ι → B) (j L : ℕ) (s : Finset ι) : B := - ∏ i, if i ∈ s then y i ^ L * x i ^ (j - L) else x i ^ j - -lemma pow_apply_mixedProduct {B ι : Type*} [CommRing B] [Algebra A B] [Fintype ι] [DecidableEq ι] - (D : Derivation A B B) (x y : ι → B) (j L : ℕ) (s : Finset ι) (u : ι) - (hu : u ∉ s) (hL : L ≤ j) - (hx : ∀ i, D (x i) = if i = u then y i else 0) - (hy : ∀ i, D (y i) = 0) : - (D.toLinearMap ^ L) (mixedProduct x y j L s) = - j.descFactorial L • mixedProduct x y j L (insert u s) := by - classical - let F (i : ι) := if i ∈ s then y i ^ L * x i ^ (j - L) else x i ^ j - let H : B := ∏ i ∈ Finset.univ.erase u, F i - have hH : D H = 0 := by - apply derivation_prod_zero - intro i hi - have hne : i ≠ u := (Finset.mem_erase.mp hi).1 - dsimp [F] - split_ifs <;> simp [D.leibniz, D.leibniz_pow, hx, hy, hne] - have he : mixedProduct x y j L s = H * (x u) ^ j := by - rw [mixedProduct, ← Finset.mul_prod_erase Finset.univ F (a := u) (by simp)] - simp [F, hu, H, mul_comm] - have hf : mixedProduct x y j L (insert u s) = H * ((y u) ^ L * (x u) ^ (j - L)) := by - let G (i : ι) := if i ∈ insert u s then y i ^ L * x i ^ (j - L) else x i ^ j - rw [mixedProduct, ← Finset.mul_prod_erase Finset.univ G (a := u) (by simp)] - have hge : (∏ i ∈ Finset.univ.erase u, G i) = H := by - apply Finset.prod_congr rfl - intro i hi - have hne : i ≠ u := (Finset.mem_erase.mp hi).1 - simp [F, G, hne] - rw [hge] - simp [G, mul_comm] - rw [he, pow_apply_mul_of_left_zero D hH, - pow_apply_pow D (f := x u) (g := y u) (by simp [hx]) (hy u) j L hL, hf] - simp only [nsmul_eq_mul] - ring - -def rowWeight {m n : ℕ} (u : Fin m) (ij : Fin m × Fin n) : ℕ := - if ij.1 = u then 1 else 0 - -lemma rowLinear_homogeneous {m n : ℕ} (u w : Fin m) (c : Fin n → A) : - (rowLinear u c).IsWeightedHomogeneous (rowWeight w) (if u = w then 1 else 0) := by - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - exact (weightedHomogeneousSubmodule A (rowWeight w) _).smul_mem _ - (isWeightedHomogeneous_X (R := A) (rowWeight w) (u, k)) - -def family {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) (s : Finset (Fin a)) : - Poly A (a + 1) n := - mixedProduct (fun i => rowLinear i.castSucc (c i)) - (fun i => rowLinear (Fin.last a) (c i)) j L s - -lemma shift_family {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) - (s : Finset (Fin a)) (u : Fin a) (hu : u ∉ s) (hL : L ≤ j) : - ((shift (A := A) u.castSucc (Fin.last a)).toLinearMap ^ L) (family c j L s) = - j.descFactorial L • family c j L (insert u s) := by - apply pow_apply_mixedProduct _ _ _ _ _ _ _ hu hL - · intro i - simp - · intro i - simp [ne_comm] - -lemma family_degree_dest {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) - (s : Finset (Fin a)) : - (family c j L s).IsWeightedHomogeneous (rowWeight (Fin.last a)) (s.card * L) := by - have hX (i : Fin a) : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous - (rowWeight (Fin.last a)) 0 := by simpa using rowLinear_homogeneous i.castSucc (Fin.last a) (c i) - have hY (i : Fin a) : (rowLinear (Fin.last a) (c i)).IsWeightedHomogeneous - (rowWeight (Fin.last a)) 1 := by simpa using rowLinear_homogeneous (Fin.last a) (Fin.last a) (c i) - have hF (i : Fin a) : (if i ∈ s then rowLinear (Fin.last a) (c i) ^ L * - rowLinear i.castSucc (c i) ^ (j - L) else rowLinear i.castSucc (c i) ^ j).IsWeightedHomogeneous (rowWeight (Fin.last a)) (if i ∈ s then L else 0) := by - split_ifs - · simpa using ((hY i).pow L).mul ((hX i).pow (j - L)) - · simpa using (hX i).pow j - have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hF i) - simpa [family, mixedProduct] using hh - -lemma family_degree_source {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) - (s : Finset (Fin a)) (u : Fin a) (hu : u ∉ s) : - (family c j L s).IsWeightedHomogeneous (rowWeight u.castSucc) j := by - have hX (i : Fin a) : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous - (rowWeight u.castSucc) (if i = u then 1 else 0) := by - simpa using rowLinear_homogeneous i.castSucc u.castSucc (c i) - have hY (i : Fin a) : (rowLinear (Fin.last a) (c i)).IsWeightedHomogeneous - (rowWeight u.castSucc) 0 := by - simpa [Ne.symm (Fin.castSucc_ne_last u)] using - rowLinear_homogeneous (Fin.last a) u.castSucc (c i) - have hF (i : Fin a) : (if i ∈ s then rowLinear (Fin.last a) (c i) ^ L * - rowLinear i.castSucc (c i) ^ (j - L) else rowLinear i.castSucc (c i) ^ j).IsWeightedHomogeneous (rowWeight u.castSucc) (if i = u then j else 0) := by - by_cases hi : i = u - · subst i - simp only [hu, ↓reduceIte] - simpa using (hX u).pow j - · have hX' : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous - (rowWeight u.castSucc) 0 := by simpa [hi] using hX i - by_cases his : i ∈ s - · simpa [his, hi] using ((hY i).pow L).mul (hX'.pow (j - L)) - · simpa [his, hi] using hX'.pow j - have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hF i) - simpa [family, mixedProduct] using hh - -lemma eval_rowLinear [Algebra ℂ A] {m n : ℕ} (u : Fin m) (c : Fin n → A) - (x : Fin m × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ A (x ij)) (rowLinear u c) = ∑ k, x (u, k) • c k := by - simp [rowLinear, Algebra.smul_def, mul_comm] - -end Foulkes.GenericShift - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan + +namespace OAI + +noncomputable section + +namespace Foulkes.GenericShift +open MvPolynomial +open Foulkes.PolynomialSpan + +variable {A : Type*} [CommRing A] + +abbrev Poly (A : Type*) [CommRing A] (m n : ℕ) := MvPolynomial (Fin m × Fin n) A + +def shift {m n : ℕ} (u v : Fin m) : Derivation A (Poly A m n) (Poly A m n) := + mkDerivation A fun ij => if ij.1 = u then X (v, ij.2) else 0 + +@[simp] lemma shift_X {m n : ℕ} (u v : Fin m) (ij : Fin m × Fin n) : + shift (A := A) u v (X ij) = if ij.1 = u then X (v, ij.2) else 0 := by + simp [shift] + +lemma derivation_sum_apply {ι : Type*} {m n : ℕ} + (s : Finset ι) (D : ι → Derivation A (Poly A m n) (Poly A m n)) (f : Poly A m n) : + (∑ k ∈ s, D k) f = ∑ k ∈ s, D k f := by + classical + induction s using Finset.induction_on with + | empty => simp + | insert x s hx ih => simp [Finset.sum_insert hx, ih] + +lemma shift_eq_sum {m n : ℕ} (u v : Fin m) : + shift (A := A) (n := n) u v = ∑ k : Fin n, (X (v, k) : Poly A m n) • + (pderiv (u, k) : Derivation A (Poly A m n) (Poly A m n)) := by + apply MvPolynomial.derivation_ext + rintro ⟨r, k⟩ + simp only [shift_X, derivation_sum_apply, Derivation.smul_apply, pderiv_X] + by_cases h : r = u + · subst r + simp [Pi.single_apply, Prod.mk.injEq] + · simp [Prod.mk.injEq, h] + +lemma mapCoeffs_shift [Algebra ℂ A] {m n : ℕ} + (l : A →ₗ[ℂ] ℂ) (u v : Fin m) (f : Poly A m n) : + mapCoeffs l (shift u v f) = shift u v (mapCoeffs l f) := by + simp only [shift_eq_sum, derivation_sum_apply, Derivation.smul_apply, + smul_eq_mul, mapCoeffs_sum, mapCoeffs_X_mul, mapCoeffs_pderiv] + +lemma mapCoeffs_shift_pow [Algebra ℂ A] {m n : ℕ} + (l : A →ₗ[ℂ] ℂ) (u v : Fin m) (f : Poly A m n) (L : ℕ) : + mapCoeffs l (((shift u v).toLinearMap ^ L) f) = + ((shift u v).toLinearMap ^ L) (mapCoeffs l f) := by + induction L with + | zero => rfl + | succ L ih => + simpa only [pow_succ', Module.End.mul_apply, Derivation.coeFn_coe, mapCoeffs_shift] using + congrArg (shift u v) ih + +def rowLinear {m n : ℕ} (u : Fin m) (c : Fin n → A) : Poly A m n := + ∑ k, c k • X (u, k) + +@[simp] lemma shift_rowLinear {m n : ℕ} (u v w : Fin m) (c : Fin n → A) : + shift u v (rowLinear w c) = if w = u then rowLinear v c else 0 := by + simp [rowLinear, map_sum, shift_X] + +lemma pow_apply_mul_of_left_zero {B : Type*} [CommRing B] [Algebra A B] + (D : Derivation A B B) {g : B} (hg : D g = 0) (f : B) (L : ℕ) : + (D.toLinearMap ^ L) (g * f) = g * (D.toLinearMap ^ L) f := by + induction L with + | zero => rfl + | succ L ih => + simp only [pow_succ', Module.End.mul_apply, ih, Derivation.coeFn_coe, D.leibniz, hg, + smul_eq_mul, mul_zero, add_zero] + +lemma pow_apply_pow {B : Type*} [CommRing B] [Algebra A B] + (D : Derivation A B B) {f g : B} (hf : D f = g) (hg : D g = 0) + (j L : ℕ) (hL : L ≤ j) : + (D.toLinearMap ^ L) (f ^ j) = j.descFactorial L • (g ^ L * f ^ (j - L)) := by + induction L with + | zero => simp + | succ L ih => + have hLj : L ≤ j := Nat.le_trans (Nat.le_succ L) hL + rw [pow_succ', Module.End.mul_apply, ih hLj, Derivation.coeFn_coe, map_nsmul] + have hkill : D (g ^ L) = 0 := by simp [D.leibniz_pow, hg] + rw [D.leibniz, hkill, smul_zero, add_zero, D.leibniz_pow, hf] + simp only [smul_eq_mul, nsmul_eq_mul] + rw [Nat.descFactorial_succ] + have hsub : j - L - 1 = j - (L + 1) := by omega + rw [hsub, pow_succ] + push_cast + ring + +lemma derivation_prod_zero {B ι : Type*} [CommRing B] [Algebra A B] + (D : Derivation A B B) (s : Finset ι) (f : ι → B) + (h : ∀ i ∈ s, D (f i) = 0) : D (∏ i ∈ s, f i) = 0 := by + classical + induction s using Finset.induction_on with + | empty => simp + | insert i s hi ih => + rw [Finset.prod_insert hi, D.leibniz, h i (by simp), + ih (fun k hk => h k (Finset.mem_insert_of_mem hk))] + simp + +def mixedProduct {B ι : Type*} [CommRing B] [Fintype ι] [DecidableEq ι] + (x y : ι → B) (j L : ℕ) (s : Finset ι) : B := + ∏ i, if i ∈ s then y i ^ L * x i ^ (j - L) else x i ^ j + +lemma pow_apply_mixedProduct {B ι : Type*} [CommRing B] [Algebra A B] [Fintype ι] [DecidableEq ι] + (D : Derivation A B B) (x y : ι → B) (j L : ℕ) (s : Finset ι) (u : ι) + (hu : u ∉ s) (hL : L ≤ j) + (hx : ∀ i, D (x i) = if i = u then y i else 0) + (hy : ∀ i, D (y i) = 0) : + (D.toLinearMap ^ L) (mixedProduct x y j L s) = + j.descFactorial L • mixedProduct x y j L (insert u s) := by + classical + let F (i : ι) := if i ∈ s then y i ^ L * x i ^ (j - L) else x i ^ j + let H : B := ∏ i ∈ Finset.univ.erase u, F i + have hH : D H = 0 := by + apply derivation_prod_zero + intro i hi + have hne : i ≠ u := (Finset.mem_erase.mp hi).1 + dsimp [F] + split_ifs <;> simp [D.leibniz, D.leibniz_pow, hx, hy, hne] + have he : mixedProduct x y j L s = H * (x u) ^ j := by + rw [mixedProduct, ← Finset.mul_prod_erase Finset.univ F (a := u) (by simp)] + simp [F, hu, H, mul_comm] + have hf : mixedProduct x y j L (insert u s) = H * ((y u) ^ L * (x u) ^ (j - L)) := by + let G (i : ι) := if i ∈ insert u s then y i ^ L * x i ^ (j - L) else x i ^ j + rw [mixedProduct, ← Finset.mul_prod_erase Finset.univ G (a := u) (by simp)] + have hge : (∏ i ∈ Finset.univ.erase u, G i) = H := by + apply Finset.prod_congr rfl + intro i hi + have hne : i ≠ u := (Finset.mem_erase.mp hi).1 + simp [F, G, hne] + rw [hge] + simp [G, mul_comm] + rw [he, pow_apply_mul_of_left_zero D hH, + pow_apply_pow D (f := x u) (g := y u) (by simp [hx]) (hy u) j L hL, hf] + simp only [nsmul_eq_mul] + ring + +def rowWeight {m n : ℕ} (u : Fin m) (ij : Fin m × Fin n) : ℕ := + if ij.1 = u then 1 else 0 + +lemma rowLinear_homogeneous {m n : ℕ} (u w : Fin m) (c : Fin n → A) : + (rowLinear u c).IsWeightedHomogeneous (rowWeight w) (if u = w then 1 else 0) := by + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + exact (weightedHomogeneousSubmodule A (rowWeight w) _).smul_mem _ + (isWeightedHomogeneous_X (R := A) (rowWeight w) (u, k)) + +def family {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) (s : Finset (Fin a)) : + Poly A (a + 1) n := + mixedProduct (fun i => rowLinear i.castSucc (c i)) + (fun i => rowLinear (Fin.last a) (c i)) j L s + +lemma shift_family {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) + (s : Finset (Fin a)) (u : Fin a) (hu : u ∉ s) (hL : L ≤ j) : + ((shift (A := A) u.castSucc (Fin.last a)).toLinearMap ^ L) (family c j L s) = + j.descFactorial L • family c j L (insert u s) := by + apply pow_apply_mixedProduct _ _ _ _ _ _ _ hu hL + · intro i + simp + · intro i + simp [ne_comm] + +lemma family_degree_dest {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) + (s : Finset (Fin a)) : + (family c j L s).IsWeightedHomogeneous (rowWeight (Fin.last a)) (s.card * L) := by + have hX (i : Fin a) : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous + (rowWeight (Fin.last a)) 0 := by simpa using rowLinear_homogeneous i.castSucc (Fin.last a) (c i) + have hY (i : Fin a) : (rowLinear (Fin.last a) (c i)).IsWeightedHomogeneous + (rowWeight (Fin.last a)) 1 := by simpa using rowLinear_homogeneous (Fin.last a) (Fin.last a) (c i) + have hF (i : Fin a) : (if i ∈ s then rowLinear (Fin.last a) (c i) ^ L * + rowLinear i.castSucc (c i) ^ (j - L) else rowLinear i.castSucc (c i) ^ j).IsWeightedHomogeneous (rowWeight (Fin.last a)) (if i ∈ s then L else 0) := by + split_ifs + · simpa using ((hY i).pow L).mul ((hX i).pow (j - L)) + · simpa using (hX i).pow j + have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hF i) + simpa [family, mixedProduct] using hh + +lemma family_degree_source {a n : ℕ} (c : Fin a → Fin n → A) (j L : ℕ) + (s : Finset (Fin a)) (u : Fin a) (hu : u ∉ s) : + (family c j L s).IsWeightedHomogeneous (rowWeight u.castSucc) j := by + have hX (i : Fin a) : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous + (rowWeight u.castSucc) (if i = u then 1 else 0) := by + simpa using rowLinear_homogeneous i.castSucc u.castSucc (c i) + have hY (i : Fin a) : (rowLinear (Fin.last a) (c i)).IsWeightedHomogeneous + (rowWeight u.castSucc) 0 := by + simpa [Ne.symm (Fin.castSucc_ne_last u)] using + rowLinear_homogeneous (Fin.last a) u.castSucc (c i) + have hF (i : Fin a) : (if i ∈ s then rowLinear (Fin.last a) (c i) ^ L * + rowLinear i.castSucc (c i) ^ (j - L) else rowLinear i.castSucc (c i) ^ j).IsWeightedHomogeneous (rowWeight u.castSucc) (if i = u then j else 0) := by + by_cases hi : i = u + · subst i + simp only [hu, ↓reduceIte] + simpa using (hX u).pow j + · have hX' : (rowLinear i.castSucc (c i)).IsWeightedHomogeneous + (rowWeight u.castSucc) 0 := by simpa [hi] using hX i + by_cases his : i ∈ s + · simpa [his, hi] using ((hY i).pow L).mul (hX'.pow (j - L)) + · simpa [his, hi] using hX'.pow j + have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hF i) + simpa [family, mixedProduct] using hh + +lemma eval_rowLinear [Algebra ℂ A] {m n : ℕ} (u : Fin m) (c : Fin n → A) + (x : Fin m × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ A (x ij)) (rowLinear u c) = ∑ k, x (u, k) • c k := by + simp [rowLinear, Algebra.smul_def, mul_comm] + +end Foulkes.GenericShift + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/HomogeneousPlethysm.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/HomogeneousPlethysm.lean index 0cb1eeca245bcc2206ababd5fa769e5a00b5590f..b8b98bd4a3d3ce0e1b883ef68b4604d7596fbd78 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/HomogeneousPlethysm.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/HomogeneousPlethysm.lean @@ -1,148 +1,148 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.AlternantExpansion - -namespace OAI - -noncomputable section - -namespace Foulkes.Complete -open MvPolynomial Finset - -lemma homogeneous_h {α : Type*} [Finite α] (b : ℕ) : (h α b).IsHomogeneous b := by - classical - apply IsHomogeneous.sum - intro d hd - exact isHomogeneous_monomial 1 d.property - -lemma homogeneous_pleth (n b a : ℕ) : (pleth n b a).IsHomogeneous (a*b) := by - unfold pleth alphabetH - apply (homogeneous_h b).eval₂ - · intro r - change (C r : MvPolynomial (Fin n) ℤ).IsHomogeneous 0 - exact isHomogeneous_C _ _ - · intro d - exact isHomogeneous_monomial 1 d.property - -end Foulkes.Complete - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -lemma degree_expVector {n : ℕ} (v : Fin n → ℕ) : - (expVector v).degree = ∑ j, v j := by - simpa using Finsupp.degree_eq_sum (expVector v) - -lemma homogeneous_alternant {n : ℕ} (m : Fin n → ℕ) : - (alternant m).IsHomogeneous (∑ j, m j) := by - classical - have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), - Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := - Matrix.det_apply _ - rw [ha] - apply IsHomogeneous.sum - intro σ hσ - rw [perm_prod_monomial] - change ((Equiv.Perm.sign σ : ℤ) • monomial (expVector (fun r => m (σ.symm r))) 1).IsHomogeneous _ - rw [smul_monomial] - apply isHomogeneous_monomial - rw [degree_expVector, Equiv.sum_comp σ.symm m] - -abbrev Partition (n d : ℕ) := - {e : Complete.Degree (Fin n) d // Antitone (fun j => e.val j)} - -instance (n d : ℕ) : Fintype (Partition n d) := by - classical - infer_instance - -def partVec {n d : ℕ} (mu : Partition n d) (j : Fin n) : ℕ := mu.val.val j - -lemma partVec_antitone {n d : ℕ} (mu : Partition n d) : Antitone (partVec mu) := mu.property - -lemma partVec_sum {n d : ℕ} (mu : Partition n d) : ∑ j, partVec mu j = d := by - change (∑ j, mu.val.val j) = d - rw [← Finsupp.degree_eq_sum] - exact mu.val.property - -def unshift {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : ℕ := v j - staircase n j - -lemma unshift_antitone {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) : - Antitone (unshift v) := by - intro j k hjk - have hg := strictAnti_gap hv j k hjk - have hj := staircase_le_of_strictAnti hv j - have hk := staircase_le_of_strictAnti hv k - simp only [unshift, staircase] at * - have hjn := j.isLt - have hkn := k.isLt - omega - -lemma shifted_unshift {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) : - shifted (unshift v) = v := by - funext j - exact Nat.sub_add_cancel (staircase_le_of_strictAnti hv j) - -lemma unshift_sum {n d : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) - (hd : ∑ j, v j = d + ∑ j, staircase n j) : ∑ j, unshift v j = d := by - have hh : (∑ j, unshift v j) + ∑ j, staircase n j = ∑ j, v j := by - rw [← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun j _ => congrFun (shifted_unshift hv) j) - omega - -def unshiftPartition {n d : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) - (hd : ∑ j, v j = d + ∑ j, staircase n j) : Partition n d := - ⟨⟨expVector (unshift v), by rw [degree_expVector]; exact unshift_sum hv hd⟩, - unshift_antitone hv⟩ - -lemma partVec_injective {n d : ℕ} : Function.Injective (@partVec n d) := by - intro v w h - apply Subtype.ext - apply Subtype.ext - ext j - exact congrFun h j - -lemma shifted_injective {n : ℕ} : Function.Injective (@shifted n) := by - intro v w h - funext j - exact Nat.add_right_cancel (congrFun h j) - -theorem homogeneous_schur_expansion {n d : ℕ} (p : MvPolynomial (Fin n) ℤ) - (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (hd : p.IsHomogeneous d) : - p * alternant (staircase n) = - ∑ mu : Partition n d, schurCoeff p (partVec mu) • alternant (shifted (partVec mu)) := by - classical - apply eq_of_strict_coefficients - (alternating_mul_symmetric hp (alternant_alternating _)) - (alternating_sum _ _ (fun _ _ => alternating_smul _ (alternant_alternating _))) - intro v hv - simp only [coeff_sum, coeff_smul] - by_cases hsize : ∑ j, v j = d + ∑ j, staircase n j - · let mu : Partition n d := unshiftPartition hv hsize - have he : shifted (partVec mu) = v := shifted_unshift hv - rw [Finset.sum_eq_single mu] - · rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone mu)) hv, ite_eq_left he] - simp only [smul_eq_mul, mul_one, schurCoeff, he] - · intro nu hnu hne - rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone nu)) hv] - have hn : shifted (partVec nu) ≠ v := by - intro hh - exact hne (partVec_injective (shifted_injective (hh.trans he.symm))) - simp [hn] - · simp - · have hgrad := hd.mul (homogeneous_alternant (staircase n)) - rw [hgrad.coeff_eq_zero (by simpa [degree_expVector] using hsize)] - apply Eq.symm - apply Finset.sum_eq_zero - intro mu hmu - rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone mu)) hv] - have hn : shifted (partVec mu) ≠ v := by - intro hh - apply hsize - rw [← hh] - simp only [shifted, Finset.sum_add_distrib, partVec_sum] - simp [hn] - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.AlternantExpansion + +namespace OAI + +noncomputable section + +namespace Foulkes.Complete +open MvPolynomial Finset + +lemma homogeneous_h {α : Type*} [Finite α] (b : ℕ) : (h α b).IsHomogeneous b := by + classical + apply IsHomogeneous.sum + intro d hd + exact isHomogeneous_monomial 1 d.property + +lemma homogeneous_pleth (n b a : ℕ) : (pleth n b a).IsHomogeneous (a*b) := by + unfold pleth alphabetH + apply (homogeneous_h b).eval₂ + · intro r + change (C r : MvPolynomial (Fin n) ℤ).IsHomogeneous 0 + exact isHomogeneous_C _ _ + · intro d + exact isHomogeneous_monomial 1 d.property + +end Foulkes.Complete + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +lemma degree_expVector {n : ℕ} (v : Fin n → ℕ) : + (expVector v).degree = ∑ j, v j := by + simpa using Finsupp.degree_eq_sum (expVector v) + +lemma homogeneous_alternant {n : ℕ} (m : Fin n → ℕ) : + (alternant m).IsHomogeneous (∑ j, m j) := by + classical + have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), + Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := + Matrix.det_apply _ + rw [ha] + apply IsHomogeneous.sum + intro σ hσ + rw [perm_prod_monomial] + change ((Equiv.Perm.sign σ : ℤ) • monomial (expVector (fun r => m (σ.symm r))) 1).IsHomogeneous _ + rw [smul_monomial] + apply isHomogeneous_monomial + rw [degree_expVector, Equiv.sum_comp σ.symm m] + +abbrev Partition (n d : ℕ) := + {e : Complete.Degree (Fin n) d // Antitone (fun j => e.val j)} + +instance (n d : ℕ) : Fintype (Partition n d) := by + classical + infer_instance + +def partVec {n d : ℕ} (mu : Partition n d) (j : Fin n) : ℕ := mu.val.val j + +lemma partVec_antitone {n d : ℕ} (mu : Partition n d) : Antitone (partVec mu) := mu.property + +lemma partVec_sum {n d : ℕ} (mu : Partition n d) : ∑ j, partVec mu j = d := by + change (∑ j, mu.val.val j) = d + rw [← Finsupp.degree_eq_sum] + exact mu.val.property + +def unshift {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : ℕ := v j - staircase n j + +lemma unshift_antitone {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) : + Antitone (unshift v) := by + intro j k hjk + have hg := strictAnti_gap hv j k hjk + have hj := staircase_le_of_strictAnti hv j + have hk := staircase_le_of_strictAnti hv k + simp only [unshift, staircase] at * + have hjn := j.isLt + have hkn := k.isLt + omega + +lemma shifted_unshift {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) : + shifted (unshift v) = v := by + funext j + exact Nat.sub_add_cancel (staircase_le_of_strictAnti hv j) + +lemma unshift_sum {n d : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) + (hd : ∑ j, v j = d + ∑ j, staircase n j) : ∑ j, unshift v j = d := by + have hh : (∑ j, unshift v j) + ∑ j, staircase n j = ∑ j, v j := by + rw [← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun j _ => congrFun (shifted_unshift hv) j) + omega + +def unshiftPartition {n d : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) + (hd : ∑ j, v j = d + ∑ j, staircase n j) : Partition n d := + ⟨⟨expVector (unshift v), by rw [degree_expVector]; exact unshift_sum hv hd⟩, + unshift_antitone hv⟩ + +lemma partVec_injective {n d : ℕ} : Function.Injective (@partVec n d) := by + intro v w h + apply Subtype.ext + apply Subtype.ext + ext j + exact congrFun h j + +lemma shifted_injective {n : ℕ} : Function.Injective (@shifted n) := by + intro v w h + funext j + exact Nat.add_right_cancel (congrFun h j) + +theorem homogeneous_schur_expansion {n d : ℕ} (p : MvPolynomial (Fin n) ℤ) + (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (hd : p.IsHomogeneous d) : + p * alternant (staircase n) = + ∑ mu : Partition n d, schurCoeff p (partVec mu) • alternant (shifted (partVec mu)) := by + classical + apply eq_of_strict_coefficients + (alternating_mul_symmetric hp (alternant_alternating _)) + (alternating_sum _ _ (fun _ _ => alternating_smul _ (alternant_alternating _))) + intro v hv + simp only [coeff_sum, coeff_smul] + by_cases hsize : ∑ j, v j = d + ∑ j, staircase n j + · let mu : Partition n d := unshiftPartition hv hsize + have he : shifted (partVec mu) = v := shifted_unshift hv + rw [Finset.sum_eq_single mu] + · rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone mu)) hv, ite_eq_left he] + simp only [smul_eq_mul, mul_one, schurCoeff, he] + · intro nu hnu hne + rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone nu)) hv] + have hn : shifted (partVec nu) ≠ v := by + intro hh + exact hne (partVec_injective (shifted_injective (hh.trans he.symm))) + simp [hn] + · simp + · have hgrad := hd.mul (homogeneous_alternant (staircase n)) + rw [hgrad.coeff_eq_zero (by simpa [degree_expVector] using hsize)] + apply Eq.symm + apply Finset.sum_eq_zero + intro mu hmu + rw [coeff_alternant_strict _ _ (shifted_strictAnti (partVec_antitone mu)) hv] + have hn : shifted (partVec mu) ≠ v := by + intro hh + apply hsize + rw [← hh] + simp only [shifted, Finset.sum_add_distrib, partVec_sum] + simp [hn] + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/IndependentChart.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/IndependentChart.lean index f9c83eb127d6aeb6c70b5e9899b7acfed5633667..8b85524e8c1b16376aaabe62470619ca9d61ca47 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/IndependentChart.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/IndependentChart.lean @@ -1,521 +1,521 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization -import OAI.RepresentationTheory.FoulkesSixth.Collision - -namespace OAI - -noncomputable section - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan - -def dehom (a n : ℕ) : P a (n + 1) →ₐ[ℂ] P a n := - aeval (fun ij : Fin a × Fin (n + 1) => Fin.cases 1 (fun k => X (ij.1, k)) ij.2) - -@[simp] lemma dehom_X_zero {a n : ℕ} (i : Fin a) : - dehom a n (X (i, 0)) = 1 := by simp [dehom] -@[simp] lemma dehom_X_succ {a n : ℕ} (i : Fin a) (k : Fin n) : - dehom a n (X (i, k.succ)) = X (i, k) := by simp [dehom] - -lemma dehom_rowForm {a n : ℕ} (i : Fin a) (v : Fin (n + 1) → ℂ) : - dehom a n (rowForm i v) = algebraMap ℂ (P a n) (v 0) + rowForm i (fun k => v k.succ) := by - simp [rowForm, Fin.sum_univ_succ, Algebra.smul_def] - -lemma dehom_z_cons {a n : ℕ} (s : ℂ) (u : Fin n → ℂ) : - dehom a n (z (Fin.cons s u)) = ∏ i : Fin a, (algebraMap ℂ (P a n) s + rowForm i u) := by - simp [z, dehom_rowForm] - -lemma dehom_renameRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) (f : P a (n+1)) : - dehom a n (renameRow σ f) = renameRow σ (dehom a n f) := by - have hh : (dehom a n).comp (renameRow σ) = (renameRow σ).comp (dehom a n) := by - ext ij - rcases ij with ⟨i, k⟩ - refine Fin.cases ?_ (fun k => ?_) k <;> simp [renameRow] - exact DFunLike.congr_fun hh f - -def E (a n : ℕ) : Submodule ℂ (P a n) := (R a (n+1) 1).map (dehom a n).toLinearMap - -lemma dehom_z_mem_E {a n : ℕ} (v : Fin (n+1) → ℂ) : - dehom a n (z v) ∈ E a n := Submodule.mem_map.mpr ⟨z v, z_mem_R v, rfl⟩ - -lemma one_mem_E (a n : ℕ) : (1 : P a n) ∈ E a n := by - have hh := dehom_z_mem_E (a := a) (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) - simpa [dehom_z_cons, rowForm] using hh - -lemma pow_mono {a n k l : ℕ} (h : k ≤ l) : E a n ^ k ≤ E a n ^ l := by - exact pow_le_pow_right₀ (Submodule.one_le.mpr (one_mem_E a n)) h - -lemma elementary_mem_E {a n : ℕ} (u : Fin n → ℂ) (h : ℕ) : - aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ h) ∈ E a n := by - classical - let G : MvPolynomial Unit (P a n) := ∏ i : Fin a, (X () * C (rowForm i u) + 1) - have heval (s : Unit → ℂ) : eval (fun i => algebraMap ℂ (P a n) (s i)) G ∈ E a n := by - have hh := dehom_z_mem_E (a := a) (Fin.cons (1 : ℂ) (fun k => s () * u k)) - convert hh using 1 - simp only [G, eval_prod, eval_add, eval_mul, eval_X, eval_C, map_one, - dehom_z_cons, map_one, rowForm, - Algebra.smul_def] - apply Finset.prod_congr rfl - intro i _ - simp [map_mul, Finset.mul_sum, mul_assoc, add_comm] - have hc := coeff_mem_of_evaluations G (E a n) heval (Finsupp.single () h) - have hg : G = ∑ s ∈ (Finset.univ : Finset (Fin a)).powerset, - (X () : MvPolynomial Unit (P a n)) ^ s.card * C (∏ i ∈ s, rowForm i u) := by - simp only [G, Finset.prod_add, Finset.prod_const_one, mul_one, Finset.prod_mul_distrib, - Finset.prod_const, ← map_prod] - rw [hg] at hc - have hcoeff (s : Finset (Fin a)) : - (X () ^ s.card * C (∏ i ∈ s, rowForm i u)).coeff (Finsupp.single () h) = - if s.card = h then ∏ i ∈ s, rowForm i u else 0 := by - rw [mul_comm, coeff_C_mul, X_pow_eq_monomial] - simp only [coeff_monomial] - simp [eq_comm] - simp only [coeff_sum, hcoeff] at hc - simpa only [esymm, map_sum, map_prod, aeval_X, Finset.powersetCard_eq_filter, - Finset.sum_filter, apply_ite, map_prod, aeval_X, map_zero] using hc - -lemma powersum_mem {a n : ℕ} (u : Fin n → ℂ) (d : ℕ) : - (∑ i : Fin a, rowForm i u ^ d) ∈ E a n ^ d := by - classical - induction d using Nat.strong_induction_on with - | h d ih => - by_cases hd : d = 0 - · subst d - simpa using (Submodule.sum_mem (1 : Submodule ℂ (P a n)) - (fun (i : Fin a) (_ : i ∈ Finset.univ) => (Submodule.one_le.mp le_rfl))) - have hdpos : 0 < d := Nat.pos_of_ne_zero hd - have hn := congrArg (aeval (fun i : Fin a => rowForm i u)) - (MvPolynomial.psum_eq_mul_esymm_sub_sum (Fin a) ℂ d hdpos) - simp only [psum, map_sum, map_pow, aeval_X, map_sub, map_mul, map_neg, - map_one, map_natCast] at hn - rw [hn] - apply Submodule.sub_mem - · have hh := (pow_mono (a := a) (n := n) hdpos) - (show aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ d) ∈ E a n ^ 1 by - simpa using elementary_mem_E u d) - convert (E a n ^ d).smul_mem (((-1 : ℂ) ^ (d+1)) * (d : ℂ)) hh using 1 - simp [Algebra.smul_def, mul_assoc] - · apply Submodule.sum_mem - intro ij hij - obtain ⟨hij, hi⟩ := Finset.mem_filter.mp hij - have hsum : ij.1 + ij.2 = d := Finset.HasAntidiagonal.mem_antidiagonal.mp hij - have hi' : 0 < ij.1 ∧ ij.1 < d := hi - have hj : ij.2 < d := by omega - have he := (pow_mono (a := a) (n := n) hi'.1) - (show aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ ij.1) ∈ E a n ^ 1 by - simpa using elementary_mem_E u ij.1) - have hp := Submodule.mul_mem_mul he (ih ij.2 hj) - rw [← pow_add, hsum] at hp - convert (E a n ^ d).smul_mem ((-1 : ℂ) ^ ij.1) hp using 1 - simp [Algebra.smul_def, mul_assoc] - -def inRow {a n : ℕ} (i : Fin a) : MvPolynomial (Fin n) ℂ →ₐ[ℂ] P a n := - rename (fun k => (i, k)) - -def pSum {a n : ℕ} : MvPolynomial (Fin n) ℂ →ₗ[ℂ] P a n := - ∑ i : Fin a, (inRow i).toLinearMap - -lemma pSum_apply {a n : ℕ} (f : MvPolynomial (Fin n) ℂ) : - pSum (a := a) f = ∑ i : Fin a, inRow i f := by - simp [pSum, LinearMap.sum_apply] - -lemma pSum_homogeneous_mem {a n d : ℕ} {f : MvPolynomial (Fin n) ℂ} - (hf : f.IsHomogeneous d) : pSum (a := a) f ∈ E a n ^ d := by - have hle : homogeneousSubmodule (Fin n) ℂ d ≤ (E a n ^ d).comap pSum := by - rw [homogeneous_eq_span_powers] - apply Submodule.span_le.mpr - rintro _ ⟨u, rfl⟩ - change pSum (a := a) ((∑ k : Fin n, u k • X k) ^ d) ∈ E a n ^ d - simpa [pSum_apply, inRow, rowForm] using powersum_mem (a := a) u d - exact hle hf - -end Foulkes.Chart - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization Foulkes.Collision - -lemma distinctSum_homogeneous_mem {a n h : ℕ} (q : Fin h → MvPolynomial (Fin n) ℂ) - (d : Fin h → ℕ) (hq : ∀ r, (q r).IsHomogeneous (d r)) : - distinctSum (fun i : Fin a => inRow i) q ∈ E a n ^ (∑ r, d r) := by - classical - induction h with - | zero => - simp only [distinctSum, Fin.prod_univ_zero, Fintype.sum_unique, Fin.sum_univ_zero, pow_zero] - exact Submodule.one_le.mp le_rfl - | succ h ih => - rw [← Fin.cons_self_tail q, recurrence, Fin.sum_univ_succ] - apply Submodule.sub_mem - · have hh := Submodule.mul_mem_mul (pSum_homogeneous_mem (a := a) (hq 0)) - (ih (Fin.tail q) (Fin.tail d) (fun r => hq r.succ)) - rw [← pow_add] at hh - simpa only [pSum_apply, Fin.tail] using hh - · apply Submodule.sum_mem - intro r _ - have hh := ih (Function.update (Fin.tail q) r (q 0 * q r.succ)) - (Function.update (Fin.tail d) r (d 0 + d r.succ)) (by - intro j - by_cases hj : j = r - · subst j; simpa using (hq 0).mul (hq r.succ) - · simpa [hj, Fin.tail] using hq j.succ) - have hsum : (∑ j : Fin h, Function.update (Fin.tail d) r (d 0 + d r.succ) j) = - d 0 + ∑ j : Fin h, d j.succ := by - rw [Finset.sum_update_of_mem (Finset.mem_univ r)] - change d 0 + Fin.tail d r + ∑ j ∈ Finset.univ \ {r}, Fin.tail d j = - d 0 + ∑ j, Fin.tail d j - rw [Finset.sdiff_singleton_eq_erase, add_assoc, - Finset.add_sum_erase Finset.univ (Fin.tail d) (Finset.mem_univ r)] - rw [hsum] at hh - exact hh - -def rowExp {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) : Fin n →₀ ℕ := - Finsupp.equivFunOnFinite.symm (fun k => d (i,k)) - -@[simp] lemma rowExp_apply {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) (k : Fin n) : - rowExp d i k = d (i,k) := by simp [rowExp] - -lemma monomial_eq_prod_rows {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) : - (monomial d 1 : P a n) = ∏ i : Fin a, inRow i (monomial (rowExp d i) 1) := by - classical - simp [inRow, monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _), - Fintype.prod_prod_type, rowExp] - -lemma renameRow_inRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) (i : Fin a) - (f : MvPolynomial (Fin n) ℂ) : renameRow σ (inRow i f) = inRow (σ i) f := by - simp [renameRow, inRow, rename_rename, Function.comp_def] - -lemma permSum_monomial {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) : - (∑ σ : Equiv.Perm (Fin a), renameRow σ (monomial d 1 : P a n)) = - distinctSum (fun i : Fin a => inRow i) (fun i => monomial (rowExp d i) 1) := by - classical - simp only [monomial_eq_prod_rows, map_prod, renameRow_inRow, distinctSum] - exact (Equiv.sum_comp (Equiv.embeddingEquivOfFinite (Fin a)) - (fun σ => ∏ i : Fin a, inRow (σ i) (monomial (rowExp d i) 1))).symm - -lemma average_monomial_mem {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (c : ℂ) : - average a n (monomial d c) ∈ E a n ^ (∑ ij, d ij) := by - classical - have hhom (i : Fin a) : (monomial (rowExp d i) (1 : ℂ)).IsHomogeneous (∑ k, d (i,k)) := by - apply isWeightedHomogeneous_monomial - simp [Finsupp.weight_apply, Finsupp.sum_fintype, rowExp] - have hh := distinctSum_homogeneous_mem (a := a) - (fun i => (monomial (rowExp d i) (1 : ℂ))) (fun i => ∑ k, d (i,k)) hhom - rw [← Fintype.sum_prod_type, ← permSum_monomial] at hh - have hs : (monomial d c : P a n) = c • monomial d 1 := by simp [smul_monomial] - rw [hs, map_smul, average_apply] - apply Submodule.smul_mem - exact Submodule.smul_mem _ _ hh - -end Foulkes.Chart - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization - -def tailExp {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) : (Fin a × Fin n) →₀ ℕ := - Finsupp.equivFunOnFinite.symm (fun ij => d (ij.1, ij.2.succ)) - -@[simp] lemma tailExp_apply {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) (ij : Fin a × Fin n) : - tailExp d ij = d (ij.1, ij.2.succ) := by simp [tailExp] - -def rehomExp {a n : ℕ} (k : ℕ) (d : (Fin a × Fin n) →₀ ℕ) : - (Fin a × Fin (n+1)) →₀ ℕ := - Finsupp.equivFunOnFinite.symm (fun ij => - Fin.cases (k - ∑ r : Fin n, d (ij.1, r)) (fun r => d (ij.1, r)) ij.2) - -lemma rehomExp_tailExp {a n k : ℕ} {d : (Fin a × Fin (n+1)) →₀ ℕ} - (hd : Finsupp.weight (weight a (n+1)) d = fun _ => k) : rehomExp k (tailExp d) = d := by - ext ij - rcases ij with ⟨i,r⟩ - have hi := congrFun hd i - rw [weight_apply_row, Fin.sum_univ_succ] at hi - refine Fin.cases ?_ (fun r => ?_) r - · simp only [rehomExp, Finsupp.equivFunOnFinite_symm_apply_apply, Fin.cases_zero, tailExp_apply] - omega - · simp [rehomExp] - -lemma dehom_monomial {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) (c : ℂ) : - dehom a n (monomial d c) = monomial (tailExp d) c := by - classical - simp only [monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _), - Fintype.prod_prod_type, map_mul, map_prod, map_pow] - rw [show (dehom a n) (C c) = C c from (dehom a n).commutes c] - congr 1 - apply Finset.prod_congr rfl - intro i _ - simp only [Fin.prod_univ_succ, dehom_X_zero, dehom_X_succ, one_pow, one_mul, tailExp_apply] - -def rehom (a n k : ℕ) : P a n →ₗ[ℂ] P a (n+1) := - AddMonoidAlgebra.mapDomainLinearMap ℂ ℂ (rehomExp k) - -@[simp] lemma rehom_monomial {a n k : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (c : ℂ) : - rehom a n k (monomial d c) = monomial (rehomExp k d) c := by - exact AddMonoidAlgebra.mapDomainLinearMap_single _ _ _ - -lemma rehom_dehom {a n k : ℕ} {f : P a (n+1)} (hf : f ∈ W a (n+1) k) : - rehom a n k (dehom a n f) = f := by - induction hf using MvPolynomial.IsWeightedHomogeneous.induction_on with - | zero => simp - | add f g hf hg ihf ihg => simp [ihf, ihg] - | monomial d c hd => rw [dehom_monomial, rehom_monomial, rehomExp_tailExp hd] - -lemma dehom_injective_W {a n k : ℕ} {f g : P a (n+1)} (hf : f ∈ W a (n+1) k) - (hg : g ∈ W a (n+1) k) (hfg : dehom a n f = dehom a n g) : f = g := by - rw [← rehom_dehom hf, ← rehom_dehom hg, hfg] - -end Foulkes.Chart - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization Foulkes.Collision - -lemma mul_mem_W {a n j k : ℕ} {f g : P a n} (hf : f ∈ W a n j) (hg : g ∈ W a n k) : - f * g ∈ W a n (j+k) := by - exact MvPolynomial.IsWeightedHomogeneous.mul hf hg - -lemma one_mem_W (a n : ℕ) : (1 : P a n) ∈ W a n 0 := - MvPolynomial.isWeightedHomogeneous_one ℂ (weight a n) - -theorem invariant_mem_E_pow {a n t : ℕ} {f : P a n} (hf : f ∈ rowInvariants a n) - (ht : f.totalDegree ≤ t) : f ∈ E a n ^ t := by - classical - rw [← average_eq hf, f.as_sum] - simp only [map_sum] - apply Submodule.sum_mem - intro d hd - apply pow_mono _ (average_monomial_mem d _) - have hh := (MvPolynomial.le_totalDegree hd).trans ht - rw [Finsupp.sum_fintype _ _ (fun _ => rfl)] at hh - exact hh - -lemma dehom_average {a n : ℕ} (f : P a (n+1)) : - dehom a n (average a (n+1) f) = average a n (dehom a n f) := by - simp only [average_apply, map_smul, map_sum, dehom_renameRow] - -lemma dehom_R_mem_E_pow {a n k : ℕ} {f : P a (n+1)} (hf : f ∈ R a (n+1) k) : - dehom a n f ∈ E a n ^ (a*k) := by - classical - have haux {g : P a (n+1)} (hg : g ∈ W a (n+1) k) : - dehom a n (average a (n+1) g) ∈ E a n ^ (a*k) := by - induction hg using MvPolynomial.IsWeightedHomogeneous.induction_on with - | zero => simp - | add f g hf hg ihf ihg => simpa using (E a n ^ (a*k)).add_mem ihf ihg - | monomial d c hd => - rw [dehom_average, dehom_monomial] - apply pow_mono _ (average_monomial_mem (tailExp d) c) - rw [Fintype.sum_prod_type] - calc - ∑ i : Fin a, ∑ r : Fin n, tailExp d (i,r) ≤ ∑ _i : Fin a, k := by - apply Finset.sum_le_sum - intro i _ - have hi := congrFun hd i - rw [weight_apply_row, Fin.sum_univ_succ] at hi - simp only [tailExp_apply] - omega - _ = a*k := by simp - simpa only [average_eq hf.2] using haux hf.1 - -def component (a n k : ℕ) : Submodule ℂ (P a n) := W a n k ⊓ (A a n).toSubmodule - -lemma E_pow_le_component_image (a n m : ℕ) : - E a n ^ m ≤ (component a (n+1) m).map (dehom a n).toLinearMap := by - induction m with - | zero => - rw [pow_zero, Submodule.one_le] - exact Submodule.mem_map.mpr ⟨1, ⟨one_mem_W _ _, (A _ _).one_mem⟩, map_one (dehom a n)⟩ - | succ m ih => - intro f hf - rw [pow_succ] at hf - refine Submodule.mul_induction_on hf ?_ ?_ - · intro x hx y hy - obtain ⟨g, hg, rfl⟩ := Submodule.mem_map.mp (ih hx) - obtain ⟨h, hh, rfl⟩ := Submodule.mem_map.mp hy - exact Submodule.mem_map.mpr ⟨g*h, - ⟨mul_mem_W hg.1 hh.1, (A _ _).mul_mem hg.2 (Algebra.subset_adjoin hh)⟩, - map_mul (dehom a n) g h⟩ - · intro x y hx hy - exact Submodule.add_mem _ hx hy - -theorem chart_standard {a n k L : ℕ} {f : P a (n+1)} (hf : f ∈ R a (n+1) k) - (hL : a*k ≤ k+L) : z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f ∈ A a (n+1) := by - have hd := pow_mono hL (dehom_R_mem_E_pow hf) - obtain ⟨g, hg, hgeq⟩ := Submodule.mem_map.mp (E_pow_le_component_image a n (k+L) hd) - have hzW : z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f ∈ W a (n+1) (k+L) := by - simpa only [add_comm] using mul_mem_W (z_pow_mem _) hf.1 - have heq : g = z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f := by - apply dehom_injective_W hg.1 hzW - simpa [dehom_z_cons, rowForm] using hgeq - rw [← heq] - exact hg.2 - -end Foulkes.Chart - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization - -def columns {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) : P a n →ₐ[ℂ] P a m := - aeval (fun ij : Fin a × Fin n => rowForm ij.1 (g (Pi.single ij.2 1))) - -def rowLinear {a n : ℕ} (i : Fin a) : (Fin n → ℂ) →ₗ[ℂ] P a n where - toFun := rowForm i - map_add' u v := by simp [rowForm, add_smul, Finset.sum_add_distrib] - map_smul' c u := by simp [rowForm, mul_smul, Finset.smul_sum] - -@[simp] lemma rowLinear_apply {a n : ℕ} (i : Fin a) (v : Fin n → ℂ) : - rowLinear i v = rowForm i v := rfl - -@[simp] lemma columns_X {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - (ij : Fin a × Fin n) : columns g (X ij) = rowForm ij.1 (g (Pi.single ij.2 1)) := by - simp [columns] - -lemma rowForm_single {a n : ℕ} (i : Fin a) (k : Fin n) : - rowForm i (Pi.single k 1) = (X (i,k) : P a n) := by - classical - simp [rowForm, Pi.single_apply] - -lemma columns_rowForm {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - (i : Fin a) (v : Fin n → ℂ) : columns g (rowForm i v) = rowForm i (g v) := by - classical - have hv : ∑ k : Fin n, v k • (Pi.single k (1 : ℂ) : Fin n → ℂ) = v := by - ext k - simp [Pi.single_apply] - calc - columns g (rowForm i v) = ∑ k : Fin n, v k • rowLinear i (g (Pi.single k 1)) := by - simp only [rowForm, map_sum, map_smul, columns_X, rowLinear_apply] - _ = rowLinear i (g (∑ k : Fin n, v k • Pi.single k 1)) := by simp - _ = rowForm i (g v) := by rw [hv]; rfl - -lemma columns_pureRows {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - (v : Fin a → Fin n → ℂ) : columns g (pureRows j v) = pureRows j (fun i => g (v i)) := by - simp only [pureRows, map_prod, map_pow, columns_rowForm] - -lemma columns_mem_W {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - {f : P a n} (hf : f ∈ W a n j) : columns g f ∈ W a m j := by - have hh : W a n j ≤ (W a m j).comap (columns g).toLinearMap := by - rw [W_eq_span_pureRows] - apply Submodule.span_le.mpr - rintro _ ⟨v, rfl⟩ - change columns g (pureRows j v) ∈ W a m j - rw [columns_pureRows] - exact pureRows_mem _ - exact hh hf - -lemma columns_renameRow {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - (σ : Equiv.Perm (Fin a)) (f : P a n) : - columns g (renameRow σ f) = renameRow σ (columns g f) := by - have hh : (columns g).comp (renameRow σ) = (renameRow σ).comp (columns g) := by - ext ij - simp [columns, renameRow, rowForm] - exact DFunLike.congr_fun hh f - -lemma columns_mem_R {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - {f : P a n} (hf : f ∈ R a n j) : columns g f ∈ R a m j := by - refine ⟨columns_mem_W g hf.1, fun σ => ?_⟩ - rw [← columns_renameRow, hf.2 σ] - -lemma columns_mem_A {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) - {f : P a n} (hf : f ∈ A a n) : columns g f ∈ A a m := by - have hh : A a n ≤ (A a m).comap (columns g) := by - apply Algebra.adjoin_le - intro h hh - exact Algebra.subset_adjoin (columns_mem_R g hh) - exact hh hf - -lemma columns_z {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) (v : Fin n → ℂ) : - columns (a := a) g (z v) = z (g v) := by simp [z, columns_rowForm] - -lemma columns_inverse {a n : ℕ} (g : (Fin n → ℂ) ≃ₗ[ℂ] (Fin n → ℂ)) (f : P a n) : - columns g.toLinearMap (columns g.symm.toLinearMap f) = f := by - have hh : (columns (a := a) g.toLinearMap).comp (columns g.symm.toLinearMap) = - AlgHom.id ℂ (P a n) := by - apply MvPolynomial.algHom_ext - intro ij - simp only [AlgHom.comp_apply, columns_X, columns_rowForm, LinearEquiv.coe_coe, - LinearEquiv.apply_symm_apply, AlgHom.id_apply, rowForm_single] - exact DFunLike.congr_fun hh f - -lemma exists_linearEquiv_send {n : ℕ} {v w : Fin n → ℂ} (hv : v ≠ 0) (hw : w ≠ 0) : - ∃ g : (Fin n → ℂ) ≃ₗ[ℂ] (Fin n → ℂ), g v = w := by - let ev := LinearEquiv.toSpanNonzeroSingleton ℂ (Fin n → ℂ) v hv - let ew := LinearEquiv.toSpanNonzeroSingleton ℂ (Fin n → ℂ) w hw - obtain ⟨g, hg⟩ := Submodule.exists_linearEquiv_restrict_eq (ev.symm.trans ew) - refine ⟨g, ?_⟩ - have hh := hg (ev 1) - change (ew (ev.symm (ev 1)) : Fin n → ℂ) = g (ev 1) at hh - rw [ev.symm_apply_apply] at hh - have hev : (ev 1 : Fin n → ℂ) = v := by simp [ev] - have hew : (ew 1 : Fin n → ℂ) = w := by simp [ew] - rw [hev, hew] at hh - exact hh.symm - -theorem chart {a n k L : ℕ} {f : P a n} (hf : f ∈ R a n k) - (v : Fin n → ℂ) (hv : v ≠ 0) (hL : a*k ≤ k+L) : z v ^ L * f ∈ A a n := by - cases n with - | zero => - exfalso - apply hv - ext i - exact Fin.elim0 i - | succ n => - let e : Fin (n+1) → ℂ := Fin.cons 1 (fun _ => 0) - have he : e ≠ 0 := by - intro hh - have := congrFun hh 0 - simp [e] at this - obtain ⟨g, hg⟩ := exists_linearEquiv_send he hv - have hsource := chart_standard (columns_mem_R g.symm.toLinearMap hf) hL - have htarget := columns_mem_A g.toLinearMap hsource - change g (Fin.cons 1 (fun _ : Fin n => 0)) = v at hg - simpa only [map_mul, map_pow, columns_z, columns_inverse, LinearEquiv.coe_coe, hg] using htarget - -end Foulkes.Chart - -namespace Foulkes.Chart -open MvPolynomial Foulkes.Polarization - -lemma z_zero {a n : ℕ} (ha : 0 < a) : z (a := a) (0 : Fin n → ℂ) = 0 := by - simp [z, rowForm, zero_pow ha.ne'] - -theorem independent_chart_bound (a n b : ℕ) (ha : 2 ≤ a) (hb : a*(a-1)^2 ≤ b) : - R a n b = component a n b := by - classical - let L := (a-1)^2 - have ha1 : 1 ≤ a := by omega - have hapos : 0 < a := by omega - have hLpos : 0 < L := by - have hs : 0 < a-1 := by omega - exact pow_pos hs 2 - have hlow (v : Fin n → ℂ) (k : ℕ) (hk : k < a) {f : P a n} (hf : f ∈ R a n k) : - z v ^ L * f ∈ A a n := by - by_cases hv : v = 0 - · simp only [hv, z_zero hapos, zero_pow hLpos.ne', zero_mul] - exact (A a n).zero_mem - · apply chart hf v hv - have hka : k ≤ a-1 := by omega - have hm := Nat.mul_le_mul_left (a-1) hka - have hs : a-1+1 = a := Nat.sub_add_cancel ha1 - dsimp [L] - nlinarith - have hmodule (v : Fin n → ℂ) {f : P a n} (hf : f ∈ lowDegreeModule a n) : - z v ^ L * f ∈ A a n := by - induction hf using Submodule.span_induction with - | mem f hf => - obtain ⟨k,hk,hf⟩ := hf - exact hlow v k hk hf - | zero => simp - | add f g hf hg ihf ihg => simpa [mul_add] using (A a n).add_mem ihf ihg - | smul c f hf ih => - change z v ^ L * ((c : P a n) * f) ∈ A a n - simpa [mul_left_comm, mul_assoc] using (A a n).mul_mem c.property ih - have hspan : invariantPolarizedSpan a n b L ≤ (A a n).toSubmodule := by - apply Submodule.span_le.mpr - rintro _ ⟨v, f, hf, rfl⟩ - exact hmodule v (module_generation ha1 _ hf) - apply le_antisymm - · intro f hf - refine ⟨hf.1, ?_⟩ - exact hspan ((R_polarization ha1 hb).le hf) - · exact AComponent_le_R a n b - -end Foulkes.Chart - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization +import OAI.RepresentationTheory.FoulkesSixth.Collision + +namespace OAI + +noncomputable section + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan + +def dehom (a n : ℕ) : P a (n + 1) →ₐ[ℂ] P a n := + aeval (fun ij : Fin a × Fin (n + 1) => Fin.cases 1 (fun k => X (ij.1, k)) ij.2) + +@[simp] lemma dehom_X_zero {a n : ℕ} (i : Fin a) : + dehom a n (X (i, 0)) = 1 := by simp [dehom] +@[simp] lemma dehom_X_succ {a n : ℕ} (i : Fin a) (k : Fin n) : + dehom a n (X (i, k.succ)) = X (i, k) := by simp [dehom] + +lemma dehom_rowForm {a n : ℕ} (i : Fin a) (v : Fin (n + 1) → ℂ) : + dehom a n (rowForm i v) = algebraMap ℂ (P a n) (v 0) + rowForm i (fun k => v k.succ) := by + simp [rowForm, Fin.sum_univ_succ, Algebra.smul_def] + +lemma dehom_z_cons {a n : ℕ} (s : ℂ) (u : Fin n → ℂ) : + dehom a n (z (Fin.cons s u)) = ∏ i : Fin a, (algebraMap ℂ (P a n) s + rowForm i u) := by + simp [z, dehom_rowForm] + +lemma dehom_renameRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) (f : P a (n+1)) : + dehom a n (renameRow σ f) = renameRow σ (dehom a n f) := by + have hh : (dehom a n).comp (renameRow σ) = (renameRow σ).comp (dehom a n) := by + ext ij + rcases ij with ⟨i, k⟩ + refine Fin.cases ?_ (fun k => ?_) k <;> simp [renameRow] + exact DFunLike.congr_fun hh f + +def E (a n : ℕ) : Submodule ℂ (P a n) := (R a (n+1) 1).map (dehom a n).toLinearMap + +lemma dehom_z_mem_E {a n : ℕ} (v : Fin (n+1) → ℂ) : + dehom a n (z v) ∈ E a n := Submodule.mem_map.mpr ⟨z v, z_mem_R v, rfl⟩ + +lemma one_mem_E (a n : ℕ) : (1 : P a n) ∈ E a n := by + have hh := dehom_z_mem_E (a := a) (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) + simpa [dehom_z_cons, rowForm] using hh + +lemma pow_mono {a n k l : ℕ} (h : k ≤ l) : E a n ^ k ≤ E a n ^ l := by + exact pow_le_pow_right₀ (Submodule.one_le.mpr (one_mem_E a n)) h + +lemma elementary_mem_E {a n : ℕ} (u : Fin n → ℂ) (h : ℕ) : + aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ h) ∈ E a n := by + classical + let G : MvPolynomial Unit (P a n) := ∏ i : Fin a, (X () * C (rowForm i u) + 1) + have heval (s : Unit → ℂ) : eval (fun i => algebraMap ℂ (P a n) (s i)) G ∈ E a n := by + have hh := dehom_z_mem_E (a := a) (Fin.cons (1 : ℂ) (fun k => s () * u k)) + convert hh using 1 + simp only [G, eval_prod, eval_add, eval_mul, eval_X, eval_C, map_one, + dehom_z_cons, map_one, rowForm, + Algebra.smul_def] + apply Finset.prod_congr rfl + intro i _ + simp [map_mul, Finset.mul_sum, mul_assoc, add_comm] + have hc := coeff_mem_of_evaluations G (E a n) heval (Finsupp.single () h) + have hg : G = ∑ s ∈ (Finset.univ : Finset (Fin a)).powerset, + (X () : MvPolynomial Unit (P a n)) ^ s.card * C (∏ i ∈ s, rowForm i u) := by + simp only [G, Finset.prod_add, Finset.prod_const_one, mul_one, Finset.prod_mul_distrib, + Finset.prod_const, ← map_prod] + rw [hg] at hc + have hcoeff (s : Finset (Fin a)) : + (X () ^ s.card * C (∏ i ∈ s, rowForm i u)).coeff (Finsupp.single () h) = + if s.card = h then ∏ i ∈ s, rowForm i u else 0 := by + rw [mul_comm, coeff_C_mul, X_pow_eq_monomial] + simp only [coeff_monomial] + simp [eq_comm] + simp only [coeff_sum, hcoeff] at hc + simpa only [esymm, map_sum, map_prod, aeval_X, Finset.powersetCard_eq_filter, + Finset.sum_filter, apply_ite, map_prod, aeval_X, map_zero] using hc + +lemma powersum_mem {a n : ℕ} (u : Fin n → ℂ) (d : ℕ) : + (∑ i : Fin a, rowForm i u ^ d) ∈ E a n ^ d := by + classical + induction d using Nat.strong_induction_on with + | h d ih => + by_cases hd : d = 0 + · subst d + simpa using (Submodule.sum_mem (1 : Submodule ℂ (P a n)) + (fun (i : Fin a) (_ : i ∈ Finset.univ) => (Submodule.one_le.mp le_rfl))) + have hdpos : 0 < d := Nat.pos_of_ne_zero hd + have hn := congrArg (aeval (fun i : Fin a => rowForm i u)) + (MvPolynomial.psum_eq_mul_esymm_sub_sum (Fin a) ℂ d hdpos) + simp only [psum, map_sum, map_pow, aeval_X, map_sub, map_mul, map_neg, + map_one, map_natCast] at hn + rw [hn] + apply Submodule.sub_mem + · have hh := (pow_mono (a := a) (n := n) hdpos) + (show aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ d) ∈ E a n ^ 1 by + simpa using elementary_mem_E u d) + convert (E a n ^ d).smul_mem (((-1 : ℂ) ^ (d+1)) * (d : ℂ)) hh using 1 + simp [Algebra.smul_def, mul_assoc] + · apply Submodule.sum_mem + intro ij hij + obtain ⟨hij, hi⟩ := Finset.mem_filter.mp hij + have hsum : ij.1 + ij.2 = d := Finset.HasAntidiagonal.mem_antidiagonal.mp hij + have hi' : 0 < ij.1 ∧ ij.1 < d := hi + have hj : ij.2 < d := by omega + have he := (pow_mono (a := a) (n := n) hi'.1) + (show aeval (fun i : Fin a => rowForm i u) (esymm (Fin a) ℂ ij.1) ∈ E a n ^ 1 by + simpa using elementary_mem_E u ij.1) + have hp := Submodule.mul_mem_mul he (ih ij.2 hj) + rw [← pow_add, hsum] at hp + convert (E a n ^ d).smul_mem ((-1 : ℂ) ^ ij.1) hp using 1 + simp [Algebra.smul_def, mul_assoc] + +def inRow {a n : ℕ} (i : Fin a) : MvPolynomial (Fin n) ℂ →ₐ[ℂ] P a n := + rename (fun k => (i, k)) + +def pSum {a n : ℕ} : MvPolynomial (Fin n) ℂ →ₗ[ℂ] P a n := + ∑ i : Fin a, (inRow i).toLinearMap + +lemma pSum_apply {a n : ℕ} (f : MvPolynomial (Fin n) ℂ) : + pSum (a := a) f = ∑ i : Fin a, inRow i f := by + simp [pSum, LinearMap.sum_apply] + +lemma pSum_homogeneous_mem {a n d : ℕ} {f : MvPolynomial (Fin n) ℂ} + (hf : f.IsHomogeneous d) : pSum (a := a) f ∈ E a n ^ d := by + have hle : homogeneousSubmodule (Fin n) ℂ d ≤ (E a n ^ d).comap pSum := by + rw [homogeneous_eq_span_powers] + apply Submodule.span_le.mpr + rintro _ ⟨u, rfl⟩ + change pSum (a := a) ((∑ k : Fin n, u k • X k) ^ d) ∈ E a n ^ d + simpa [pSum_apply, inRow, rowForm] using powersum_mem (a := a) u d + exact hle hf + +end Foulkes.Chart + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization Foulkes.Collision + +lemma distinctSum_homogeneous_mem {a n h : ℕ} (q : Fin h → MvPolynomial (Fin n) ℂ) + (d : Fin h → ℕ) (hq : ∀ r, (q r).IsHomogeneous (d r)) : + distinctSum (fun i : Fin a => inRow i) q ∈ E a n ^ (∑ r, d r) := by + classical + induction h with + | zero => + simp only [distinctSum, Fin.prod_univ_zero, Fintype.sum_unique, Fin.sum_univ_zero, pow_zero] + exact Submodule.one_le.mp le_rfl + | succ h ih => + rw [← Fin.cons_self_tail q, recurrence, Fin.sum_univ_succ] + apply Submodule.sub_mem + · have hh := Submodule.mul_mem_mul (pSum_homogeneous_mem (a := a) (hq 0)) + (ih (Fin.tail q) (Fin.tail d) (fun r => hq r.succ)) + rw [← pow_add] at hh + simpa only [pSum_apply, Fin.tail] using hh + · apply Submodule.sum_mem + intro r _ + have hh := ih (Function.update (Fin.tail q) r (q 0 * q r.succ)) + (Function.update (Fin.tail d) r (d 0 + d r.succ)) (by + intro j + by_cases hj : j = r + · subst j; simpa using (hq 0).mul (hq r.succ) + · simpa [hj, Fin.tail] using hq j.succ) + have hsum : (∑ j : Fin h, Function.update (Fin.tail d) r (d 0 + d r.succ) j) = + d 0 + ∑ j : Fin h, d j.succ := by + rw [Finset.sum_update_of_mem (Finset.mem_univ r)] + change d 0 + Fin.tail d r + ∑ j ∈ Finset.univ \ {r}, Fin.tail d j = + d 0 + ∑ j, Fin.tail d j + rw [Finset.sdiff_singleton_eq_erase, add_assoc, + Finset.add_sum_erase Finset.univ (Fin.tail d) (Finset.mem_univ r)] + rw [hsum] at hh + exact hh + +def rowExp {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) : Fin n →₀ ℕ := + Finsupp.equivFunOnFinite.symm (fun k => d (i,k)) + +@[simp] lemma rowExp_apply {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) (k : Fin n) : + rowExp d i k = d (i,k) := by simp [rowExp] + +lemma monomial_eq_prod_rows {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) : + (monomial d 1 : P a n) = ∏ i : Fin a, inRow i (monomial (rowExp d i) 1) := by + classical + simp [inRow, monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _), + Fintype.prod_prod_type, rowExp] + +lemma renameRow_inRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) (i : Fin a) + (f : MvPolynomial (Fin n) ℂ) : renameRow σ (inRow i f) = inRow (σ i) f := by + simp [renameRow, inRow, rename_rename, Function.comp_def] + +lemma permSum_monomial {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) : + (∑ σ : Equiv.Perm (Fin a), renameRow σ (monomial d 1 : P a n)) = + distinctSum (fun i : Fin a => inRow i) (fun i => monomial (rowExp d i) 1) := by + classical + simp only [monomial_eq_prod_rows, map_prod, renameRow_inRow, distinctSum] + exact (Equiv.sum_comp (Equiv.embeddingEquivOfFinite (Fin a)) + (fun σ => ∏ i : Fin a, inRow (σ i) (monomial (rowExp d i) 1))).symm + +lemma average_monomial_mem {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (c : ℂ) : + average a n (monomial d c) ∈ E a n ^ (∑ ij, d ij) := by + classical + have hhom (i : Fin a) : (monomial (rowExp d i) (1 : ℂ)).IsHomogeneous (∑ k, d (i,k)) := by + apply isWeightedHomogeneous_monomial + simp [Finsupp.weight_apply, Finsupp.sum_fintype, rowExp] + have hh := distinctSum_homogeneous_mem (a := a) + (fun i => (monomial (rowExp d i) (1 : ℂ))) (fun i => ∑ k, d (i,k)) hhom + rw [← Fintype.sum_prod_type, ← permSum_monomial] at hh + have hs : (monomial d c : P a n) = c • monomial d 1 := by simp [smul_monomial] + rw [hs, map_smul, average_apply] + apply Submodule.smul_mem + exact Submodule.smul_mem _ _ hh + +end Foulkes.Chart + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization + +def tailExp {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) : (Fin a × Fin n) →₀ ℕ := + Finsupp.equivFunOnFinite.symm (fun ij => d (ij.1, ij.2.succ)) + +@[simp] lemma tailExp_apply {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) (ij : Fin a × Fin n) : + tailExp d ij = d (ij.1, ij.2.succ) := by simp [tailExp] + +def rehomExp {a n : ℕ} (k : ℕ) (d : (Fin a × Fin n) →₀ ℕ) : + (Fin a × Fin (n+1)) →₀ ℕ := + Finsupp.equivFunOnFinite.symm (fun ij => + Fin.cases (k - ∑ r : Fin n, d (ij.1, r)) (fun r => d (ij.1, r)) ij.2) + +lemma rehomExp_tailExp {a n k : ℕ} {d : (Fin a × Fin (n+1)) →₀ ℕ} + (hd : Finsupp.weight (weight a (n+1)) d = fun _ => k) : rehomExp k (tailExp d) = d := by + ext ij + rcases ij with ⟨i,r⟩ + have hi := congrFun hd i + rw [weight_apply_row, Fin.sum_univ_succ] at hi + refine Fin.cases ?_ (fun r => ?_) r + · simp only [rehomExp, Finsupp.equivFunOnFinite_symm_apply_apply, Fin.cases_zero, tailExp_apply] + omega + · simp [rehomExp] + +lemma dehom_monomial {a n : ℕ} (d : (Fin a × Fin (n+1)) →₀ ℕ) (c : ℂ) : + dehom a n (monomial d c) = monomial (tailExp d) c := by + classical + simp only [monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _), + Fintype.prod_prod_type, map_mul, map_prod, map_pow] + rw [show (dehom a n) (C c) = C c from (dehom a n).commutes c] + congr 1 + apply Finset.prod_congr rfl + intro i _ + simp only [Fin.prod_univ_succ, dehom_X_zero, dehom_X_succ, one_pow, one_mul, tailExp_apply] + +def rehom (a n k : ℕ) : P a n →ₗ[ℂ] P a (n+1) := + AddMonoidAlgebra.mapDomainLinearMap ℂ ℂ (rehomExp k) + +@[simp] lemma rehom_monomial {a n k : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (c : ℂ) : + rehom a n k (monomial d c) = monomial (rehomExp k d) c := by + exact AddMonoidAlgebra.mapDomainLinearMap_single _ _ _ + +lemma rehom_dehom {a n k : ℕ} {f : P a (n+1)} (hf : f ∈ W a (n+1) k) : + rehom a n k (dehom a n f) = f := by + induction hf using MvPolynomial.IsWeightedHomogeneous.induction_on with + | zero => simp + | add f g hf hg ihf ihg => simp [ihf, ihg] + | monomial d c hd => rw [dehom_monomial, rehom_monomial, rehomExp_tailExp hd] + +lemma dehom_injective_W {a n k : ℕ} {f g : P a (n+1)} (hf : f ∈ W a (n+1) k) + (hg : g ∈ W a (n+1) k) (hfg : dehom a n f = dehom a n g) : f = g := by + rw [← rehom_dehom hf, ← rehom_dehom hg, hfg] + +end Foulkes.Chart + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization Foulkes.Collision + +lemma mul_mem_W {a n j k : ℕ} {f g : P a n} (hf : f ∈ W a n j) (hg : g ∈ W a n k) : + f * g ∈ W a n (j+k) := by + exact MvPolynomial.IsWeightedHomogeneous.mul hf hg + +lemma one_mem_W (a n : ℕ) : (1 : P a n) ∈ W a n 0 := + MvPolynomial.isWeightedHomogeneous_one ℂ (weight a n) + +theorem invariant_mem_E_pow {a n t : ℕ} {f : P a n} (hf : f ∈ rowInvariants a n) + (ht : f.totalDegree ≤ t) : f ∈ E a n ^ t := by + classical + rw [← average_eq hf, f.as_sum] + simp only [map_sum] + apply Submodule.sum_mem + intro d hd + apply pow_mono _ (average_monomial_mem d _) + have hh := (MvPolynomial.le_totalDegree hd).trans ht + rw [Finsupp.sum_fintype _ _ (fun _ => rfl)] at hh + exact hh + +lemma dehom_average {a n : ℕ} (f : P a (n+1)) : + dehom a n (average a (n+1) f) = average a n (dehom a n f) := by + simp only [average_apply, map_smul, map_sum, dehom_renameRow] + +lemma dehom_R_mem_E_pow {a n k : ℕ} {f : P a (n+1)} (hf : f ∈ R a (n+1) k) : + dehom a n f ∈ E a n ^ (a*k) := by + classical + have haux {g : P a (n+1)} (hg : g ∈ W a (n+1) k) : + dehom a n (average a (n+1) g) ∈ E a n ^ (a*k) := by + induction hg using MvPolynomial.IsWeightedHomogeneous.induction_on with + | zero => simp + | add f g hf hg ihf ihg => simpa using (E a n ^ (a*k)).add_mem ihf ihg + | monomial d c hd => + rw [dehom_average, dehom_monomial] + apply pow_mono _ (average_monomial_mem (tailExp d) c) + rw [Fintype.sum_prod_type] + calc + ∑ i : Fin a, ∑ r : Fin n, tailExp d (i,r) ≤ ∑ _i : Fin a, k := by + apply Finset.sum_le_sum + intro i _ + have hi := congrFun hd i + rw [weight_apply_row, Fin.sum_univ_succ] at hi + simp only [tailExp_apply] + omega + _ = a*k := by simp + simpa only [average_eq hf.2] using haux hf.1 + +def component (a n k : ℕ) : Submodule ℂ (P a n) := W a n k ⊓ (A a n).toSubmodule + +lemma E_pow_le_component_image (a n m : ℕ) : + E a n ^ m ≤ (component a (n+1) m).map (dehom a n).toLinearMap := by + induction m with + | zero => + rw [pow_zero, Submodule.one_le] + exact Submodule.mem_map.mpr ⟨1, ⟨one_mem_W _ _, (A _ _).one_mem⟩, map_one (dehom a n)⟩ + | succ m ih => + intro f hf + rw [pow_succ] at hf + refine Submodule.mul_induction_on hf ?_ ?_ + · intro x hx y hy + obtain ⟨g, hg, rfl⟩ := Submodule.mem_map.mp (ih hx) + obtain ⟨h, hh, rfl⟩ := Submodule.mem_map.mp hy + exact Submodule.mem_map.mpr ⟨g*h, + ⟨mul_mem_W hg.1 hh.1, (A _ _).mul_mem hg.2 (Algebra.subset_adjoin hh)⟩, + map_mul (dehom a n) g h⟩ + · intro x y hx hy + exact Submodule.add_mem _ hx hy + +theorem chart_standard {a n k L : ℕ} {f : P a (n+1)} (hf : f ∈ R a (n+1) k) + (hL : a*k ≤ k+L) : z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f ∈ A a (n+1) := by + have hd := pow_mono hL (dehom_R_mem_E_pow hf) + obtain ⟨g, hg, hgeq⟩ := Submodule.mem_map.mp (E_pow_le_component_image a n (k+L) hd) + have hzW : z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f ∈ W a (n+1) (k+L) := by + simpa only [add_comm] using mul_mem_W (z_pow_mem _) hf.1 + have heq : g = z (Fin.cons (1 : ℂ) (fun _ : Fin n => 0)) ^ L * f := by + apply dehom_injective_W hg.1 hzW + simpa [dehom_z_cons, rowForm] using hgeq + rw [← heq] + exact hg.2 + +end Foulkes.Chart + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization + +def columns {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) : P a n →ₐ[ℂ] P a m := + aeval (fun ij : Fin a × Fin n => rowForm ij.1 (g (Pi.single ij.2 1))) + +def rowLinear {a n : ℕ} (i : Fin a) : (Fin n → ℂ) →ₗ[ℂ] P a n where + toFun := rowForm i + map_add' u v := by simp [rowForm, add_smul, Finset.sum_add_distrib] + map_smul' c u := by simp [rowForm, mul_smul, Finset.smul_sum] + +@[simp] lemma rowLinear_apply {a n : ℕ} (i : Fin a) (v : Fin n → ℂ) : + rowLinear i v = rowForm i v := rfl + +@[simp] lemma columns_X {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + (ij : Fin a × Fin n) : columns g (X ij) = rowForm ij.1 (g (Pi.single ij.2 1)) := by + simp [columns] + +lemma rowForm_single {a n : ℕ} (i : Fin a) (k : Fin n) : + rowForm i (Pi.single k 1) = (X (i,k) : P a n) := by + classical + simp [rowForm, Pi.single_apply] + +lemma columns_rowForm {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + (i : Fin a) (v : Fin n → ℂ) : columns g (rowForm i v) = rowForm i (g v) := by + classical + have hv : ∑ k : Fin n, v k • (Pi.single k (1 : ℂ) : Fin n → ℂ) = v := by + ext k + simp [Pi.single_apply] + calc + columns g (rowForm i v) = ∑ k : Fin n, v k • rowLinear i (g (Pi.single k 1)) := by + simp only [rowForm, map_sum, map_smul, columns_X, rowLinear_apply] + _ = rowLinear i (g (∑ k : Fin n, v k • Pi.single k 1)) := by simp + _ = rowForm i (g v) := by rw [hv]; rfl + +lemma columns_pureRows {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + (v : Fin a → Fin n → ℂ) : columns g (pureRows j v) = pureRows j (fun i => g (v i)) := by + simp only [pureRows, map_prod, map_pow, columns_rowForm] + +lemma columns_mem_W {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + {f : P a n} (hf : f ∈ W a n j) : columns g f ∈ W a m j := by + have hh : W a n j ≤ (W a m j).comap (columns g).toLinearMap := by + rw [W_eq_span_pureRows] + apply Submodule.span_le.mpr + rintro _ ⟨v, rfl⟩ + change columns g (pureRows j v) ∈ W a m j + rw [columns_pureRows] + exact pureRows_mem _ + exact hh hf + +lemma columns_renameRow {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + (σ : Equiv.Perm (Fin a)) (f : P a n) : + columns g (renameRow σ f) = renameRow σ (columns g f) := by + have hh : (columns g).comp (renameRow σ) = (renameRow σ).comp (columns g) := by + ext ij + simp [columns, renameRow, rowForm] + exact DFunLike.congr_fun hh f + +lemma columns_mem_R {a n m j : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + {f : P a n} (hf : f ∈ R a n j) : columns g f ∈ R a m j := by + refine ⟨columns_mem_W g hf.1, fun σ => ?_⟩ + rw [← columns_renameRow, hf.2 σ] + +lemma columns_mem_A {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) + {f : P a n} (hf : f ∈ A a n) : columns g f ∈ A a m := by + have hh : A a n ≤ (A a m).comap (columns g) := by + apply Algebra.adjoin_le + intro h hh + exact Algebra.subset_adjoin (columns_mem_R g hh) + exact hh hf + +lemma columns_z {a n m : ℕ} (g : (Fin n → ℂ) →ₗ[ℂ] (Fin m → ℂ)) (v : Fin n → ℂ) : + columns (a := a) g (z v) = z (g v) := by simp [z, columns_rowForm] + +lemma columns_inverse {a n : ℕ} (g : (Fin n → ℂ) ≃ₗ[ℂ] (Fin n → ℂ)) (f : P a n) : + columns g.toLinearMap (columns g.symm.toLinearMap f) = f := by + have hh : (columns (a := a) g.toLinearMap).comp (columns g.symm.toLinearMap) = + AlgHom.id ℂ (P a n) := by + apply MvPolynomial.algHom_ext + intro ij + simp only [AlgHom.comp_apply, columns_X, columns_rowForm, LinearEquiv.coe_coe, + LinearEquiv.apply_symm_apply, AlgHom.id_apply, rowForm_single] + exact DFunLike.congr_fun hh f + +lemma exists_linearEquiv_send {n : ℕ} {v w : Fin n → ℂ} (hv : v ≠ 0) (hw : w ≠ 0) : + ∃ g : (Fin n → ℂ) ≃ₗ[ℂ] (Fin n → ℂ), g v = w := by + let ev := LinearEquiv.toSpanNonzeroSingleton ℂ (Fin n → ℂ) v hv + let ew := LinearEquiv.toSpanNonzeroSingleton ℂ (Fin n → ℂ) w hw + obtain ⟨g, hg⟩ := Submodule.exists_linearEquiv_restrict_eq (ev.symm.trans ew) + refine ⟨g, ?_⟩ + have hh := hg (ev 1) + change (ew (ev.symm (ev 1)) : Fin n → ℂ) = g (ev 1) at hh + rw [ev.symm_apply_apply] at hh + have hev : (ev 1 : Fin n → ℂ) = v := by simp [ev] + have hew : (ew 1 : Fin n → ℂ) = w := by simp [ew] + rw [hev, hew] at hh + exact hh.symm + +theorem chart {a n k L : ℕ} {f : P a n} (hf : f ∈ R a n k) + (v : Fin n → ℂ) (hv : v ≠ 0) (hL : a*k ≤ k+L) : z v ^ L * f ∈ A a n := by + cases n with + | zero => + exfalso + apply hv + ext i + exact Fin.elim0 i + | succ n => + let e : Fin (n+1) → ℂ := Fin.cons 1 (fun _ => 0) + have he : e ≠ 0 := by + intro hh + have := congrFun hh 0 + simp [e] at this + obtain ⟨g, hg⟩ := exists_linearEquiv_send he hv + have hsource := chart_standard (columns_mem_R g.symm.toLinearMap hf) hL + have htarget := columns_mem_A g.toLinearMap hsource + change g (Fin.cons 1 (fun _ : Fin n => 0)) = v at hg + simpa only [map_mul, map_pow, columns_z, columns_inverse, LinearEquiv.coe_coe, hg] using htarget + +end Foulkes.Chart + +namespace Foulkes.Chart +open MvPolynomial Foulkes.Polarization + +lemma z_zero {a n : ℕ} (ha : 0 < a) : z (a := a) (0 : Fin n → ℂ) = 0 := by + simp [z, rowForm, zero_pow ha.ne'] + +theorem independent_chart_bound (a n b : ℕ) (ha : 2 ≤ a) (hb : a*(a-1)^2 ≤ b) : + R a n b = component a n b := by + classical + let L := (a-1)^2 + have ha1 : 1 ≤ a := by omega + have hapos : 0 < a := by omega + have hLpos : 0 < L := by + have hs : 0 < a-1 := by omega + exact pow_pos hs 2 + have hlow (v : Fin n → ℂ) (k : ℕ) (hk : k < a) {f : P a n} (hf : f ∈ R a n k) : + z v ^ L * f ∈ A a n := by + by_cases hv : v = 0 + · simp only [hv, z_zero hapos, zero_pow hLpos.ne', zero_mul] + exact (A a n).zero_mem + · apply chart hf v hv + have hka : k ≤ a-1 := by omega + have hm := Nat.mul_le_mul_left (a-1) hka + have hs : a-1+1 = a := Nat.sub_add_cancel ha1 + dsimp [L] + nlinarith + have hmodule (v : Fin n → ℂ) {f : P a n} (hf : f ∈ lowDegreeModule a n) : + z v ^ L * f ∈ A a n := by + induction hf using Submodule.span_induction with + | mem f hf => + obtain ⟨k,hk,hf⟩ := hf + exact hlow v k hk hf + | zero => simp + | add f g hf hg ihf ihg => simpa [mul_add] using (A a n).add_mem ihf ihg + | smul c f hf ih => + change z v ^ L * ((c : P a n) * f) ∈ A a n + simpa [mul_left_comm, mul_assoc] using (A a n).mul_mem c.property ih + have hspan : invariantPolarizedSpan a n b L ≤ (A a n).toSubmodule := by + apply Submodule.span_le.mpr + rintro _ ⟨v, f, hf, rfl⟩ + exact hmodule v (module_generation ha1 _ hf) + apply le_antisymm + · intro f hf + refine ⟨hf.1, ?_⟩ + exact hspan ((R_polarization ha1 hb).le hf) + · exact AComponent_le_R a n b + +end Foulkes.Chart + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/InvariantPolarization.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/InvariantPolarization.lean index e1edb67f0b0469fc02a9e72406288e3220167e2a..939ddb321145157ba4e19fa1876ec638cf5c1f92 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/InvariantPolarization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/InvariantPolarization.lean @@ -1,164 +1,164 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.TensorPolarization - -namespace OAI - -noncomputable section - -namespace Foulkes.Polarization -open MvPolynomial - -def renameRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) : P a n →ₐ[ℂ] P a n := - MvPolynomial.rename (fun ij : Fin a × Fin n => (σ ij.1, ij.2)) - -@[simp] lemma renameRow_comp {a n : ℕ} (σ τ : Equiv.Perm (Fin a)) (f : P a n) : - renameRow σ (renameRow τ f) = renameRow (σ * τ) f := by - simp [renameRow, rename_rename, Function.comp_def, Equiv.Perm.mul_apply] - -@[simp] lemma renameRow_rowForm {a n : ℕ} (σ : Equiv.Perm (Fin a)) (i : Fin a) - (v : Fin n → ℂ) : renameRow σ (rowForm i v) = rowForm (σ i) v := by - simp [renameRow, rowForm] - -lemma renameRow_pureRows {a n j : ℕ} (σ : Equiv.Perm (Fin a)) (v : Fin a → Fin n → ℂ) : - renameRow σ (pureRows j v) = pureRows j (fun i => v (σ.symm i)) := by - simp only [pureRows, map_prod, map_pow, renameRow_rowForm] - apply Fintype.prod_equiv σ - intro i - simp - -lemma renameRow_mem_W {a n j : ℕ} (σ : Equiv.Perm (Fin a)) {f : P a n} - (hf : f ∈ W a n j) : renameRow σ f ∈ W a n j := by - have hle : Submodule.span ℂ (Set.range (pureRows (a := a) (n := n) j)) ≤ - (W a n j).comap (renameRow σ).toLinearMap := by - apply Submodule.span_le.mpr - rintro _ ⟨v, rfl⟩ - change renameRow σ (pureRows j v) ∈ W a n j - rw [renameRow_pureRows] - exact pureRows_mem _ - apply hle - rwa [← W_eq_span_pureRows] - -@[simp] lemma renameRow_z {a n : ℕ} (σ : Equiv.Perm (Fin a)) (v : Fin n → ℂ) : - renameRow σ (z (a := a) v) = z v := by - simp only [z, map_prod, renameRow_rowForm] - exact Equiv.prod_comp σ (fun i => rowForm i v) - -def rowInvariants (a n : ℕ) : Subalgebra ℂ (P a n) where - carrier := {f | ∀ σ : Equiv.Perm (Fin a), renameRow σ f = f} - zero_mem' := by intro σ; simp - add_mem' := by intro f g hf hg σ; simp only [map_add, hf σ, hg σ] - one_mem' := by intro σ; simp - mul_mem' := by intro f g hf hg σ; simp only [map_mul, hf σ, hg σ] - algebraMap_mem' := by intro c σ; simp - -def R (a n j : ℕ) : Submodule ℂ (P a n) := W a n j ⊓ (rowInvariants a n).toSubmodule - -def A (a n : ℕ) : Subalgebra ℂ (P a n) := Algebra.adjoin ℂ (R a n 1 : Set (P a n)) - -def average (a n : ℕ) : P a n →ₗ[ℂ] P a n := - (a.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin a), (renameRow σ).toLinearMap - -lemma average_apply {a n : ℕ} (f : P a n) : - average a n f = (a.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin a), renameRow σ f := by - simp [average, LinearMap.sum_apply] - -lemma average_invariant {a n : ℕ} (f : P a n) (τ : Equiv.Perm (Fin a)) : - renameRow τ (average a n f) = average a n f := by - simp only [average_apply, map_smul, map_sum, renameRow_comp] - congr 1 - exact Equiv.sum_comp (Equiv.mulLeft τ) (fun σ => renameRow σ f) - -lemma average_mem_R {a n j : ℕ} {f : P a n} (hf : f ∈ W a n j) : - average a n f ∈ R a n j := by - constructor - · rw [average_apply] - apply Submodule.smul_mem - apply Submodule.sum_mem - intro σ _ - exact renameRow_mem_W σ hf - · exact average_invariant f - -lemma average_eq {a n : ℕ} {f : P a n} - (hf : f ∈ rowInvariants a n) : average a n f = f := by - change ∀ σ : Equiv.Perm (Fin a), renameRow σ f = f at hf - have ha : (a.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero a - simp only [average_apply, hf, Finset.sum_const, Finset.card_univ, - Fintype.card_perm, Fintype.card_fin] - rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ ha, one_smul] - -lemma average_zpow_mul {a n L : ℕ} (v : Fin n → ℂ) (f : P a n) : - average a n (z v ^ L * f) = z v ^ L * average a n f := by - simp only [average_apply, map_mul, map_pow, renameRow_z, ← Finset.mul_sum] - rw [mul_smul_comm] - -lemma z_mem_R {a n : ℕ} (v : Fin n → ℂ) : z (a := a) v ∈ R a n 1 := by - constructor - · simpa using z_pow_mem (a := a) (L := 1) v - · exact fun σ => renameRow_z σ v - -lemma z_mem_A {a n : ℕ} (v : Fin n → ℂ) : z (a := a) v ∈ A a n := - Algebra.subset_adjoin (z_mem_R v) - -def invariantPolarizedSpan (a n j L : ℕ) : Submodule ℂ (P a n) := - Submodule.span ℂ {p | ∃ (v : Fin n → ℂ) (f : P a n), - f ∈ R a n (j - L) ∧ z v ^ L * f = p} - -theorem R_polarization {a n j L : ℕ} (ha : 1 ≤ a) (hj : a * L ≤ j) : - R a n j = invariantPolarizedSpan a n j L := by - classical - apply le_antisymm - · intro f hf - have hle : polarizedSpan a n j L ≤ - (invariantPolarizedSpan a n j L).comap (average a n) := by - apply Submodule.span_le.mpr - rintro _ ⟨v, g, hg, rfl⟩ - change average a n (z v ^ L * g) ∈ invariantPolarizedSpan a n j L - rw [average_zpow_mul] - exact Submodule.subset_span ⟨v, average a n g, average_mem_R hg, rfl⟩ - have hmem := hle ((W_polarization ha hj).le hf.1) - change average a n f ∈ invariantPolarizedSpan a n j L at hmem - rwa [average_eq hf.2] at hmem - · apply Submodule.span_le.mpr - rintro _ ⟨v, f, hf, rfl⟩ - constructor - · apply (W_polarization ha hj).ge - exact Submodule.subset_span ⟨v, f, hf.1, rfl⟩ - · intro σ - simp only [map_mul, map_pow, renameRow_z, hf.2 σ] - -def lowDegreeModule (a n : ℕ) : Submodule (A a n) (P a n) := - Submodule.span (A a n) {f | ∃ k : ℕ, k < a ∧ f ∈ R a n k} - -theorem module_generation {a n : ℕ} (ha : 1 ≤ a) (j : ℕ) {f : P a n} - (hf : f ∈ R a n j) : f ∈ lowDegreeModule a n := by - classical - induction j using Nat.strong_induction_on generalizing f with - | h j ih => - by_cases hj : j < a - · exact Submodule.subset_span ⟨j, hj, hf⟩ - have hja : a ≤ j := Nat.le_of_not_lt hj - have hsub : j - 1 < j := by omega - have hle : invariantPolarizedSpan a n j 1 ≤ (lowDegreeModule a n).restrictScalars ℂ := by - apply Submodule.span_le.mpr - rintro _ ⟨v, g, hg, rfl⟩ - change z v ^ 1 * g ∈ lowDegreeModule a n - rw [pow_one] - exact (lowDegreeModule a n).smul_mem (⟨z v, z_mem_A v⟩ : A a n) (ih (j - 1) hsub hg) - apply hle - apply (R_polarization ha (by simpa using hja)).le hf - -lemma A_le_rowInvariants (a n : ℕ) : A a n ≤ rowInvariants a n := by - apply Algebra.adjoin_le - intro f hf - exact hf.2 - -lemma AComponent_le_R (a n j : ℕ) : - W a n j ⊓ (A a n).toSubmodule ≤ R a n j := by - intro f hf - exact ⟨hf.1, A_le_rowInvariants a n hf.2⟩ - -end Foulkes.Polarization - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.TensorPolarization + +namespace OAI + +noncomputable section + +namespace Foulkes.Polarization +open MvPolynomial + +def renameRow {a n : ℕ} (σ : Equiv.Perm (Fin a)) : P a n →ₐ[ℂ] P a n := + MvPolynomial.rename (fun ij : Fin a × Fin n => (σ ij.1, ij.2)) + +@[simp] lemma renameRow_comp {a n : ℕ} (σ τ : Equiv.Perm (Fin a)) (f : P a n) : + renameRow σ (renameRow τ f) = renameRow (σ * τ) f := by + simp [renameRow, rename_rename, Function.comp_def, Equiv.Perm.mul_apply] + +@[simp] lemma renameRow_rowForm {a n : ℕ} (σ : Equiv.Perm (Fin a)) (i : Fin a) + (v : Fin n → ℂ) : renameRow σ (rowForm i v) = rowForm (σ i) v := by + simp [renameRow, rowForm] + +lemma renameRow_pureRows {a n j : ℕ} (σ : Equiv.Perm (Fin a)) (v : Fin a → Fin n → ℂ) : + renameRow σ (pureRows j v) = pureRows j (fun i => v (σ.symm i)) := by + simp only [pureRows, map_prod, map_pow, renameRow_rowForm] + apply Fintype.prod_equiv σ + intro i + simp + +lemma renameRow_mem_W {a n j : ℕ} (σ : Equiv.Perm (Fin a)) {f : P a n} + (hf : f ∈ W a n j) : renameRow σ f ∈ W a n j := by + have hle : Submodule.span ℂ (Set.range (pureRows (a := a) (n := n) j)) ≤ + (W a n j).comap (renameRow σ).toLinearMap := by + apply Submodule.span_le.mpr + rintro _ ⟨v, rfl⟩ + change renameRow σ (pureRows j v) ∈ W a n j + rw [renameRow_pureRows] + exact pureRows_mem _ + apply hle + rwa [← W_eq_span_pureRows] + +@[simp] lemma renameRow_z {a n : ℕ} (σ : Equiv.Perm (Fin a)) (v : Fin n → ℂ) : + renameRow σ (z (a := a) v) = z v := by + simp only [z, map_prod, renameRow_rowForm] + exact Equiv.prod_comp σ (fun i => rowForm i v) + +def rowInvariants (a n : ℕ) : Subalgebra ℂ (P a n) where + carrier := {f | ∀ σ : Equiv.Perm (Fin a), renameRow σ f = f} + zero_mem' := by intro σ; simp + add_mem' := by intro f g hf hg σ; simp only [map_add, hf σ, hg σ] + one_mem' := by intro σ; simp + mul_mem' := by intro f g hf hg σ; simp only [map_mul, hf σ, hg σ] + algebraMap_mem' := by intro c σ; simp + +def R (a n j : ℕ) : Submodule ℂ (P a n) := W a n j ⊓ (rowInvariants a n).toSubmodule + +def A (a n : ℕ) : Subalgebra ℂ (P a n) := Algebra.adjoin ℂ (R a n 1 : Set (P a n)) + +def average (a n : ℕ) : P a n →ₗ[ℂ] P a n := + (a.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin a), (renameRow σ).toLinearMap + +lemma average_apply {a n : ℕ} (f : P a n) : + average a n f = (a.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin a), renameRow σ f := by + simp [average, LinearMap.sum_apply] + +lemma average_invariant {a n : ℕ} (f : P a n) (τ : Equiv.Perm (Fin a)) : + renameRow τ (average a n f) = average a n f := by + simp only [average_apply, map_smul, map_sum, renameRow_comp] + congr 1 + exact Equiv.sum_comp (Equiv.mulLeft τ) (fun σ => renameRow σ f) + +lemma average_mem_R {a n j : ℕ} {f : P a n} (hf : f ∈ W a n j) : + average a n f ∈ R a n j := by + constructor + · rw [average_apply] + apply Submodule.smul_mem + apply Submodule.sum_mem + intro σ _ + exact renameRow_mem_W σ hf + · exact average_invariant f + +lemma average_eq {a n : ℕ} {f : P a n} + (hf : f ∈ rowInvariants a n) : average a n f = f := by + change ∀ σ : Equiv.Perm (Fin a), renameRow σ f = f at hf + have ha : (a.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero a + simp only [average_apply, hf, Finset.sum_const, Finset.card_univ, + Fintype.card_perm, Fintype.card_fin] + rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ ha, one_smul] + +lemma average_zpow_mul {a n L : ℕ} (v : Fin n → ℂ) (f : P a n) : + average a n (z v ^ L * f) = z v ^ L * average a n f := by + simp only [average_apply, map_mul, map_pow, renameRow_z, ← Finset.mul_sum] + rw [mul_smul_comm] + +lemma z_mem_R {a n : ℕ} (v : Fin n → ℂ) : z (a := a) v ∈ R a n 1 := by + constructor + · simpa using z_pow_mem (a := a) (L := 1) v + · exact fun σ => renameRow_z σ v + +lemma z_mem_A {a n : ℕ} (v : Fin n → ℂ) : z (a := a) v ∈ A a n := + Algebra.subset_adjoin (z_mem_R v) + +def invariantPolarizedSpan (a n j L : ℕ) : Submodule ℂ (P a n) := + Submodule.span ℂ {p | ∃ (v : Fin n → ℂ) (f : P a n), + f ∈ R a n (j - L) ∧ z v ^ L * f = p} + +theorem R_polarization {a n j L : ℕ} (ha : 1 ≤ a) (hj : a * L ≤ j) : + R a n j = invariantPolarizedSpan a n j L := by + classical + apply le_antisymm + · intro f hf + have hle : polarizedSpan a n j L ≤ + (invariantPolarizedSpan a n j L).comap (average a n) := by + apply Submodule.span_le.mpr + rintro _ ⟨v, g, hg, rfl⟩ + change average a n (z v ^ L * g) ∈ invariantPolarizedSpan a n j L + rw [average_zpow_mul] + exact Submodule.subset_span ⟨v, average a n g, average_mem_R hg, rfl⟩ + have hmem := hle ((W_polarization ha hj).le hf.1) + change average a n f ∈ invariantPolarizedSpan a n j L at hmem + rwa [average_eq hf.2] at hmem + · apply Submodule.span_le.mpr + rintro _ ⟨v, f, hf, rfl⟩ + constructor + · apply (W_polarization ha hj).ge + exact Submodule.subset_span ⟨v, f, hf.1, rfl⟩ + · intro σ + simp only [map_mul, map_pow, renameRow_z, hf.2 σ] + +def lowDegreeModule (a n : ℕ) : Submodule (A a n) (P a n) := + Submodule.span (A a n) {f | ∃ k : ℕ, k < a ∧ f ∈ R a n k} + +theorem module_generation {a n : ℕ} (ha : 1 ≤ a) (j : ℕ) {f : P a n} + (hf : f ∈ R a n j) : f ∈ lowDegreeModule a n := by + classical + induction j using Nat.strong_induction_on generalizing f with + | h j ih => + by_cases hj : j < a + · exact Submodule.subset_span ⟨j, hj, hf⟩ + have hja : a ≤ j := Nat.le_of_not_lt hj + have hsub : j - 1 < j := by omega + have hle : invariantPolarizedSpan a n j 1 ≤ (lowDegreeModule a n).restrictScalars ℂ := by + apply Submodule.span_le.mpr + rintro _ ⟨v, g, hg, rfl⟩ + change z v ^ 1 * g ∈ lowDegreeModule a n + rw [pow_one] + exact (lowDegreeModule a n).smul_mem (⟨z v, z_mem_A v⟩ : A a n) (ih (j - 1) hsub hg) + apply hle + apply (R_polarization ha (by simpa using hja)).le hf + +lemma A_le_rowInvariants (a n : ℕ) : A a n ≤ rowInvariants a n := by + apply Algebra.adjoin_le + intro f hf + exact hf.2 + +lemma AComponent_le_R (a n j : ℕ) : + W a n j ⊓ (A a n).toSubmodule ≤ R a n j := by + intro f hf + exact ⟨hf.1, A_le_rowInvariants a n hf.2⟩ + +end Foulkes.Polarization + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Lookup.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Lookup.lean index 1d96cb750613bb0032a1d3281286762509aff043..766d99e10841257d00b5215c471f515daa24234d 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Lookup.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Lookup.lean @@ -1,138 +1,138 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.CompleteNewton -import OAI.RepresentationTheory.FoulkesSixth.SignedStrips - -namespace OAI - -noncomputable section - -namespace Foulkes.Complete -open MvPolynomial Finset - -def degreeEquiv {α β : Type*} (e : α ≃ β) (b : ℕ) : Degree α b ≃ Degree β b where - toFun d := ⟨d.val.mapDomain e, by simpa using d.property⟩ - invFun d := ⟨d.val.mapDomain e.symm, by simpa using d.property⟩ - left_inv d := by - apply Subtype.ext - ext j - simp [Finsupp.mapDomain_equiv_apply] - right_inv d := by - apply Subtype.ext - ext j - simp [Finsupp.mapDomain_equiv_apply] - -theorem rename_h {α β : Type*} [Finite α] [Finite β] (e : α ≃ β) (b : ℕ) : - rename e (h α b) = h β b := by - simp only [h, map_sum, rename_monomial] - exact Equiv.sum_comp (degreeEquiv e b) (fun d => monomial d.val 1) - -theorem alphabetH_reindex {α β σ : Type*} [Finite α] [Finite β] - (e : α ≃ β) (x : β → MvPolynomial σ ℤ) (b : ℕ) : - alphabetH (x ∘ e) b = alphabetH x b := by - have hh := congrArg (eval₂Hom (Int.castRingHom (MvPolynomial σ ℤ)) x) (rename_h e b) - simpa only [eval₂Hom_rename, alphabetH] using hh - -theorem rename_pleth (n b a : ℕ) (σ : Equiv.Perm (Fin n)) : - rename σ (pleth n b a) = pleth n b a := by - unfold pleth alphabetH - change (rename σ).toRingHom _ = _ - rw [MvPolynomial.map_eval₂Hom] - have hh : (rename σ).toRingHom.comp (Int.castRingHom (MvPolynomial (Fin n) ℤ)) = - Int.castRingHom (MvPolynomial (Fin n) ℤ) := by ext; simp - rw [hh] - simpa only [alphabetH, Function.comp_def, degreeEquiv, Equiv.coe_fn_mk, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_monomial] using - alphabetH_reindex (degreeEquiv σ a) (fun d => monomial d.val (1 : ℤ)) b - -end Foulkes.Complete - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -def Alternating {n : ℕ} (p : MvPolynomial (Fin n) ℤ) : Prop := - ∀ σ : Equiv.Perm (Fin n), rename σ p = (Equiv.Perm.sign σ : ℤ) • p - -lemma alternant_alternating {n : ℕ} (m : Fin n → ℕ) : Alternating (alternant m) := by - intro σ - let M : Matrix (Fin n) (Fin n) (MvPolynomial (Fin n) ℤ) := Matrix.of (fun r c => X r ^ m c) - have hm : (rename σ).toRingHom.mapMatrix M = M.submatrix σ id := by - ext r c - simp [M, RingHom.mapMatrix_apply] - have hh := (rename σ).toRingHom.map_det M - rw [hm, Matrix.det_permute] at hh - change rename σ (alternant m) = _ at hh - have he : M.det = alternant m := rfl - rw [he] at hh - simpa only [zsmul_eq_mul] using hh - -lemma alternating_mul_symmetric {n : ℕ} {p q : MvPolynomial (Fin n) ℤ} - (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (hq : Alternating q) : - Alternating (p*q) := by - intro σ - simp only [map_mul, hp σ, hq σ, mul_smul_comm] - -lemma mapDomain_expVector {n : ℕ} (σ : Equiv.Perm (Fin n)) (v : Fin n → ℕ) : - (expVector v).mapDomain σ = expVector (v ∘ σ.symm) := by - ext j - simp [Finsupp.mapDomain_equiv_apply, Function.comp_def] - -lemma coeff_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (v : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : - p.coeff (expVector (v ∘ σ)) = (Equiv.Perm.sign σ : ℤ) * p.coeff (expVector v) := by - have hm : (expVector (v ∘ σ)).mapDomain σ = expVector v := by - rw [mapDomain_expVector] - congr 1 - funext j - simp - have hh := coeff_rename_mapDomain σ σ.injective p (expVector (v ∘ σ)) - rw [hm, hp σ, coeff_smul] at hh - simpa [zsmul_eq_mul] using hh.symm - -lemma coeff_eq_sign_mul_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (v : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : - p.coeff (expVector v) = (Equiv.Perm.sign σ : ℤ) * p.coeff (expVector (v ∘ σ)) := by - have hh := coeff_comp hp (v ∘ σ) σ.symm - have he : (v ∘ σ) ∘ σ.symm = v := by funext j; simp - simpa only [he, Equiv.Perm.sign_symm] using hh - -lemma coeff_repeated {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) - (v : Fin n → ℕ) {j k : Fin n} (hjk : j ≠ k) (he : v j = v k) : - p.coeff (expVector v) = 0 := by - classical - have hs : v ∘ Equiv.swap j k = v := by - funext r - by_cases hrj : r = j - · subst r; simp [he] - by_cases hrk : r = k - · subst r; simp [he] - simp [Equiv.swap_apply_of_ne_of_ne hrj hrk] - have hh := coeff_comp hp v (Equiv.swap j k) - rw [hs, Equiv.Perm.sign_swap hjk] at hh - simp only [Units.val_neg, Units.val_one, neg_one_mul] at hh - omega - -def sortDesc {n : ℕ} (v : Fin n → ℕ) : Equiv.Perm (Fin n) := - Tuple.sort (α := ℕᵒᵈ) (fun j => v j) - -lemma sortDesc_antitone {n : ℕ} (v : Fin n → ℕ) : Antitone (v ∘ sortDesc v) := -by - intro j k hjk - exact Tuple.monotone_sort (α := ℕᵒᵈ) (fun j => v j) hjk - -lemma sortDesc_strict {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : - StrictAnti (v ∘ sortDesc v) := - (sortDesc_antitone v).strictAnti_of_injective (hv.comp (sortDesc v).injective) - -def sortedPartition {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : ℕ := - v (sortDesc v j) - staircase n j - -def schurCoeff {n : ℕ} (p : MvPolynomial (Fin n) ℤ) (mu : Fin n → ℕ) : ℤ := - (p * alternant (staircase n)).coeff (expVector (shifted mu)) - -def Q (n b : ℕ) (mu : Fin n → ℕ) : ℤ := schurCoeff (Complete.pleth n b 6) mu -def F (n b : ℕ) (mu : Fin n → ℕ) : ℤ := schurCoeff (Complete.pleth n 6 b) mu - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.CompleteNewton +import OAI.RepresentationTheory.FoulkesSixth.SignedStrips + +namespace OAI + +noncomputable section + +namespace Foulkes.Complete +open MvPolynomial Finset + +def degreeEquiv {α β : Type*} (e : α ≃ β) (b : ℕ) : Degree α b ≃ Degree β b where + toFun d := ⟨d.val.mapDomain e, by simpa using d.property⟩ + invFun d := ⟨d.val.mapDomain e.symm, by simpa using d.property⟩ + left_inv d := by + apply Subtype.ext + ext j + simp [Finsupp.mapDomain_equiv_apply] + right_inv d := by + apply Subtype.ext + ext j + simp [Finsupp.mapDomain_equiv_apply] + +theorem rename_h {α β : Type*} [Finite α] [Finite β] (e : α ≃ β) (b : ℕ) : + rename e (h α b) = h β b := by + simp only [h, map_sum, rename_monomial] + exact Equiv.sum_comp (degreeEquiv e b) (fun d => monomial d.val 1) + +theorem alphabetH_reindex {α β σ : Type*} [Finite α] [Finite β] + (e : α ≃ β) (x : β → MvPolynomial σ ℤ) (b : ℕ) : + alphabetH (x ∘ e) b = alphabetH x b := by + have hh := congrArg (eval₂Hom (Int.castRingHom (MvPolynomial σ ℤ)) x) (rename_h e b) + simpa only [eval₂Hom_rename, alphabetH] using hh + +theorem rename_pleth (n b a : ℕ) (σ : Equiv.Perm (Fin n)) : + rename σ (pleth n b a) = pleth n b a := by + unfold pleth alphabetH + change (rename σ).toRingHom _ = _ + rw [MvPolynomial.map_eval₂Hom] + have hh : (rename σ).toRingHom.comp (Int.castRingHom (MvPolynomial (Fin n) ℤ)) = + Int.castRingHom (MvPolynomial (Fin n) ℤ) := by ext; simp + rw [hh] + simpa only [alphabetH, Function.comp_def, degreeEquiv, Equiv.coe_fn_mk, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_monomial] using + alphabetH_reindex (degreeEquiv σ a) (fun d => monomial d.val (1 : ℤ)) b + +end Foulkes.Complete + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +def Alternating {n : ℕ} (p : MvPolynomial (Fin n) ℤ) : Prop := + ∀ σ : Equiv.Perm (Fin n), rename σ p = (Equiv.Perm.sign σ : ℤ) • p + +lemma alternant_alternating {n : ℕ} (m : Fin n → ℕ) : Alternating (alternant m) := by + intro σ + let M : Matrix (Fin n) (Fin n) (MvPolynomial (Fin n) ℤ) := Matrix.of (fun r c => X r ^ m c) + have hm : (rename σ).toRingHom.mapMatrix M = M.submatrix σ id := by + ext r c + simp [M, RingHom.mapMatrix_apply] + have hh := (rename σ).toRingHom.map_det M + rw [hm, Matrix.det_permute] at hh + change rename σ (alternant m) = _ at hh + have he : M.det = alternant m := rfl + rw [he] at hh + simpa only [zsmul_eq_mul] using hh + +lemma alternating_mul_symmetric {n : ℕ} {p q : MvPolynomial (Fin n) ℤ} + (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (hq : Alternating q) : + Alternating (p*q) := by + intro σ + simp only [map_mul, hp σ, hq σ, mul_smul_comm] + +lemma mapDomain_expVector {n : ℕ} (σ : Equiv.Perm (Fin n)) (v : Fin n → ℕ) : + (expVector v).mapDomain σ = expVector (v ∘ σ.symm) := by + ext j + simp [Finsupp.mapDomain_equiv_apply, Function.comp_def] + +lemma coeff_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (v : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : + p.coeff (expVector (v ∘ σ)) = (Equiv.Perm.sign σ : ℤ) * p.coeff (expVector v) := by + have hm : (expVector (v ∘ σ)).mapDomain σ = expVector v := by + rw [mapDomain_expVector] + congr 1 + funext j + simp + have hh := coeff_rename_mapDomain σ σ.injective p (expVector (v ∘ σ)) + rw [hm, hp σ, coeff_smul] at hh + simpa [zsmul_eq_mul] using hh.symm + +lemma coeff_eq_sign_mul_comp {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (v : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : + p.coeff (expVector v) = (Equiv.Perm.sign σ : ℤ) * p.coeff (expVector (v ∘ σ)) := by + have hh := coeff_comp hp (v ∘ σ) σ.symm + have he : (v ∘ σ) ∘ σ.symm = v := by funext j; simp + simpa only [he, Equiv.Perm.sign_symm] using hh + +lemma coeff_repeated {n : ℕ} {p : MvPolynomial (Fin n) ℤ} (hp : Alternating p) + (v : Fin n → ℕ) {j k : Fin n} (hjk : j ≠ k) (he : v j = v k) : + p.coeff (expVector v) = 0 := by + classical + have hs : v ∘ Equiv.swap j k = v := by + funext r + by_cases hrj : r = j + · subst r; simp [he] + by_cases hrk : r = k + · subst r; simp [he] + simp [Equiv.swap_apply_of_ne_of_ne hrj hrk] + have hh := coeff_comp hp v (Equiv.swap j k) + rw [hs, Equiv.Perm.sign_swap hjk] at hh + simp only [Units.val_neg, Units.val_one, neg_one_mul] at hh + omega + +def sortDesc {n : ℕ} (v : Fin n → ℕ) : Equiv.Perm (Fin n) := + Tuple.sort (α := ℕᵒᵈ) (fun j => v j) + +lemma sortDesc_antitone {n : ℕ} (v : Fin n → ℕ) : Antitone (v ∘ sortDesc v) := +by + intro j k hjk + exact Tuple.monotone_sort (α := ℕᵒᵈ) (fun j => v j) hjk + +lemma sortDesc_strict {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : + StrictAnti (v ∘ sortDesc v) := + (sortDesc_antitone v).strictAnti_of_injective (hv.comp (sortDesc v).injective) + +def sortedPartition {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : ℕ := + v (sortDesc v j) - staircase n j + +def schurCoeff {n : ℕ} (p : MvPolynomial (Fin n) ℤ) (mu : Fin n → ℕ) : ℤ := + (p * alternant (staircase n)).coeff (expVector (shifted mu)) + +def Q (n b : ℕ) (mu : Fin n → ℕ) : ℤ := schurCoeff (Complete.pleth n b 6) mu +def F (n b : ℕ) (mu : Fin n → ℕ) : ℤ := schurCoeff (Complete.pleth n 6 b) mu + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/LookupExtraction.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/LookupExtraction.lean index c743e4e4dadaa9fb2c7c0e802f60b0bcf45f7cd7..3d99719fb1e37553274a3b66414588da73f0e0ba 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/LookupExtraction.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/LookupExtraction.lean @@ -1,132 +1,132 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.Lookup - -namespace OAI - -noncomputable section - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -lemma strictAnti_gap {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) - (j k : Fin n) (hjk : j ≤ k) : v k + k.val ≤ v j + j.val := by - have hh : ∀ t, j.val ≤ t → ∀ ht : t < n, v ⟨t,ht⟩ + t ≤ v j + j.val := by - intro t hjt - induction t, hjt using Nat.le_induction with - | base => intro ht; simp - | succ t hjt ih => - intro ht - have ht' : t < n := by omega - have hstep := hv (show (⟨t,ht'⟩ : Fin n) < ⟨t+1,ht⟩ from by simp) - have hprev := ih ht' - omega - exact hh k.val hjk k.isLt - -lemma staircase_le_of_strictAnti {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) - (j : Fin n) : staircase n j ≤ v j := by - have hn : 0 < n := Nat.zero_lt_of_lt j.isLt - let k : Fin n := ⟨n-1, by omega⟩ - have hjk : j ≤ k := by change j.val ≤ n-1; omega - have hh := strictAnti_gap hv j k hjk - simp only [k, staircase] at * - omega - -lemma sortedPartition_antitone {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : - Antitone (sortedPartition v) := by - intro j k hjk - have hs := sortDesc_strict v hv - have hg := strictAnti_gap hs j k hjk - have hj := staircase_le_of_strictAnti hs j - have hk := staircase_le_of_strictAnti hs k - simp only [sortedPartition, staircase, Function.comp_apply] at * - have hjn := j.isLt - have hkn := k.isLt - omega - -lemma shifted_sortedPartition {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : - shifted (sortedPartition v) = v ∘ sortDesc v := by - funext j - exact Nat.sub_add_cancel (staircase_le_of_strictAnti (sortDesc_strict v hv) j) - -def signedLookup {n : ℕ} (f : (Fin n → ℕ) → ℤ) (v : Fin n → ℤ) : ℤ := by - classical - exact if hn : ∀ j, 0 ≤ v j then - let w := fun j => (v j).toNat - if Function.Injective w then - (Equiv.Perm.sign (sortDesc w) : ℤ) * f (sortedPartition w) - else 0 - else 0 - -def coeffZ {n : ℕ} (v : Fin n → ℤ) (p : MvPolynomial (Fin n) ℤ) : ℤ := by - classical - exact if ∀ j, 0 ≤ v j then p.coeff (expVector (fun j => (v j).toNat)) else 0 - -theorem signedLookup_eq_coeffZ {n : ℕ} (p : MvPolynomial (Fin n) ℤ) - (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (v : Fin n → ℤ) : - signedLookup (schurCoeff p) v = coeffZ v (p * alternant (staircase n)) := by - classical - unfold signedLookup coeffZ - by_cases hn : ∀ j, 0 ≤ v j - · simp only [dite_eq_left hn, ite_eq_left hn] - let w := fun j => (v j).toNat - change (if Function.Injective w then _ else _) = _ - have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) - by_cases hw : Function.Injective w - · rw [ite_eq_left hw] - unfold schurCoeff - rw [shifted_sortedPartition w hw] - exact (coeff_eq_sign_mul_comp ha w (sortDesc w)).symm - · rw [ite_eq_right hw] - obtain ⟨j,k,he,hjk⟩ := Function.not_injective_iff.mp hw - exact (coeff_repeated ha w hjk he).symm - · simp only [dite_eq_right hn, ite_eq_right hn] - -lemma coeffZ_monomial_mul {n : ℕ} (l : Fin n → ℕ) (d : Fin n →₀ ℕ) - (p : MvPolynomial (Fin n) ℤ) : - (monomial d 1 * p).coeff (expVector l) = - coeffZ (fun j => (l j : ℤ) - d j) p := by - classical - rw [coeff_monomial_mul'] - unfold coeffZ - have hiff : d ≤ expVector l ↔ ∀ j, 0 ≤ (l j : ℤ) - d j := by - simp [Finsupp.le_def, expVector] - by_cases hd : d ≤ expVector l - · rw [ite_eq_left hd, ite_eq_left (hiff.mp hd), one_mul] - congr 1 - ext j - simp [expVector] - · rw [ite_eq_right hd, ite_eq_right (mt hiff.mpr hd)] - -theorem target_newton (n b : ℕ) (mu : Fin n → ℕ) : - (b : ℤ) * Q n b mu = - ∑ i ∈ Finset.Icc 1 b, ∑ d : Complete.Degree (Fin n) 6, - signedLookup (Q n (b-i)) - (fun j => (shifted mu j : ℤ) - (i : ℤ) * d.val j) := by - have hh := congrArg - (fun p : MvPolynomial (Fin n) ℤ => - (p * alternant (staircase n)).coeff (expVector (shifted mu))) - (Complete.pleth_newton n b 6) - change (((b : ℤ) • Complete.pleth n b 6) * alternant (staircase n)).coeff - (expVector (shifted mu)) = _ at hh - rw [smul_mul_assoc, coeff_smul] at hh - simp only [Finset.sum_mul, coeff_sum, zsmul_eq_mul] at hh - change (b : ℤ) * Q n b mu = _ at hh - rw [hh] - apply Finset.sum_congr rfl - intro i hi - apply Finset.sum_congr rfl - intro d hd - rw [mul_assoc, coeffZ_monomial_mul] - have he : (fun j : Fin n => (shifted mu j : ℤ) - ((i • d.val) j : ℕ)) = - (fun j => (shifted mu j : ℤ) - (i : ℤ) * d.val j) := by - funext j - simp - rw [he] - exact (signedLookup_eq_coeffZ (Complete.pleth n (b-i) 6) - (Complete.rename_pleth n (b-i) 6) _).symm - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.Lookup + +namespace OAI + +noncomputable section + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +lemma strictAnti_gap {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) + (j k : Fin n) (hjk : j ≤ k) : v k + k.val ≤ v j + j.val := by + have hh : ∀ t, j.val ≤ t → ∀ ht : t < n, v ⟨t,ht⟩ + t ≤ v j + j.val := by + intro t hjt + induction t, hjt using Nat.le_induction with + | base => intro ht; simp + | succ t hjt ih => + intro ht + have ht' : t < n := by omega + have hstep := hv (show (⟨t,ht'⟩ : Fin n) < ⟨t+1,ht⟩ from by simp) + have hprev := ih ht' + omega + exact hh k.val hjk k.isLt + +lemma staircase_le_of_strictAnti {n : ℕ} {v : Fin n → ℕ} (hv : StrictAnti v) + (j : Fin n) : staircase n j ≤ v j := by + have hn : 0 < n := Nat.zero_lt_of_lt j.isLt + let k : Fin n := ⟨n-1, by omega⟩ + have hjk : j ≤ k := by change j.val ≤ n-1; omega + have hh := strictAnti_gap hv j k hjk + simp only [k, staircase] at * + omega + +lemma sortedPartition_antitone {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : + Antitone (sortedPartition v) := by + intro j k hjk + have hs := sortDesc_strict v hv + have hg := strictAnti_gap hs j k hjk + have hj := staircase_le_of_strictAnti hs j + have hk := staircase_le_of_strictAnti hs k + simp only [sortedPartition, staircase, Function.comp_apply] at * + have hjn := j.isLt + have hkn := k.isLt + omega + +lemma shifted_sortedPartition {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : + shifted (sortedPartition v) = v ∘ sortDesc v := by + funext j + exact Nat.sub_add_cancel (staircase_le_of_strictAnti (sortDesc_strict v hv) j) + +def signedLookup {n : ℕ} (f : (Fin n → ℕ) → ℤ) (v : Fin n → ℤ) : ℤ := by + classical + exact if hn : ∀ j, 0 ≤ v j then + let w := fun j => (v j).toNat + if Function.Injective w then + (Equiv.Perm.sign (sortDesc w) : ℤ) * f (sortedPartition w) + else 0 + else 0 + +def coeffZ {n : ℕ} (v : Fin n → ℤ) (p : MvPolynomial (Fin n) ℤ) : ℤ := by + classical + exact if ∀ j, 0 ≤ v j then p.coeff (expVector (fun j => (v j).toNat)) else 0 + +theorem signedLookup_eq_coeffZ {n : ℕ} (p : MvPolynomial (Fin n) ℤ) + (hp : ∀ σ : Equiv.Perm (Fin n), rename σ p = p) (v : Fin n → ℤ) : + signedLookup (schurCoeff p) v = coeffZ v (p * alternant (staircase n)) := by + classical + unfold signedLookup coeffZ + by_cases hn : ∀ j, 0 ≤ v j + · simp only [dite_eq_left hn, ite_eq_left hn] + let w := fun j => (v j).toNat + change (if Function.Injective w then _ else _) = _ + have ha := alternating_mul_symmetric hp (alternant_alternating (staircase n)) + by_cases hw : Function.Injective w + · rw [ite_eq_left hw] + unfold schurCoeff + rw [shifted_sortedPartition w hw] + exact (coeff_eq_sign_mul_comp ha w (sortDesc w)).symm + · rw [ite_eq_right hw] + obtain ⟨j,k,he,hjk⟩ := Function.not_injective_iff.mp hw + exact (coeff_repeated ha w hjk he).symm + · simp only [dite_eq_right hn, ite_eq_right hn] + +lemma coeffZ_monomial_mul {n : ℕ} (l : Fin n → ℕ) (d : Fin n →₀ ℕ) + (p : MvPolynomial (Fin n) ℤ) : + (monomial d 1 * p).coeff (expVector l) = + coeffZ (fun j => (l j : ℤ) - d j) p := by + classical + rw [coeff_monomial_mul'] + unfold coeffZ + have hiff : d ≤ expVector l ↔ ∀ j, 0 ≤ (l j : ℤ) - d j := by + simp [Finsupp.le_def, expVector] + by_cases hd : d ≤ expVector l + · rw [ite_eq_left hd, ite_eq_left (hiff.mp hd), one_mul] + congr 1 + ext j + simp [expVector] + · rw [ite_eq_right hd, ite_eq_right (mt hiff.mpr hd)] + +theorem target_newton (n b : ℕ) (mu : Fin n → ℕ) : + (b : ℤ) * Q n b mu = + ∑ i ∈ Finset.Icc 1 b, ∑ d : Complete.Degree (Fin n) 6, + signedLookup (Q n (b-i)) + (fun j => (shifted mu j : ℤ) - (i : ℤ) * d.val j) := by + have hh := congrArg + (fun p : MvPolynomial (Fin n) ℤ => + (p * alternant (staircase n)).coeff (expVector (shifted mu))) + (Complete.pleth_newton n b 6) + change (((b : ℤ) • Complete.pleth n b 6) * alternant (staircase n)).coeff + (expVector (shifted mu)) = _ at hh + rw [smul_mul_assoc, coeff_smul] at hh + simp only [Finset.sum_mul, coeff_sum, zsmul_eq_mul] at hh + change (b : ℤ) * Q n b mu = _ at hh + rw [hh] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro d hd + rw [mul_assoc, coeffZ_monomial_mul] + have he : (fun j : Fin n => (shifted mu j : ℤ) - ((i • d.val) j : ℕ)) = + (fun j => (shifted mu j : ℤ) - (i : ℤ) * d.val j) := by + funext j + simp + rw [he] + exact (signedLookup_eq_coeffZ (Complete.pleth n (b-i) 6) + (Complete.rename_pleth n (b-i) 6) _).symm + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Main.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Main.lean index b1344cb77010993963d9f688060b3fab4127ae3a..c843368fa1c0d5f4fc9238b5bbf796fd7bb770a7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Main.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Main.lean @@ -1,40 +1,40 @@ -import OAI.RepresentationTheory.FoulkesSixth.Collision -import OAI.RepresentationTheory.FoulkesSixth.Diagonal -import OAI.RepresentationTheory.FoulkesSixth.StripSupport -import OAI.RepresentationTheory.FoulkesSixth.CompleteNewton -import OAI.RepresentationTheory.FoulkesSixth.YoungModules -import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan -import OAI.RepresentationTheory.FoulkesSixth.SymTensors -import OAI.RepresentationTheory.FoulkesSixth.StripCoefficient -import OAI.RepresentationTheory.FoulkesSixth.SemisimpleBridge -import OAI.RepresentationTheory.FoulkesSixth.ColorOrbits -import OAI.RepresentationTheory.FoulkesSixth.SymDual -import OAI.RepresentationTheory.FoulkesSixth.Differential -import OAI.RepresentationTheory.FoulkesSixth.StripInterlace -import OAI.RepresentationTheory.FoulkesSixth.GenericShift -import OAI.RepresentationTheory.FoulkesSixth.SymOperations -import OAI.RepresentationTheory.FoulkesSixth.SignedStrips -import OAI.RepresentationTheory.FoulkesSixth.PlethDual -import OAI.RepresentationTheory.FoulkesSixth.SymPolynomial -import OAI.RepresentationTheory.FoulkesSixth.Lookup -import OAI.RepresentationTheory.FoulkesSixth.LookupExtraction -import OAI.RepresentationTheory.FoulkesSixth.AlternantExpansion -import OAI.RepresentationTheory.FoulkesSixth.TensorPolarization -import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm -import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization -import OAI.RepresentationTheory.FoulkesSixth.SourceNewton -import OAI.RepresentationTheory.FoulkesSixth.FastLookup -import OAI.RepresentationTheory.FoulkesSixth.SixCycles -import OAI.RepresentationTheory.FoulkesSixth.CompositionEnumeration -import OAI.RepresentationTheory.FoulkesSixth.FastLookupExact -import OAI.RepresentationTheory.FoulkesSixth.NewtonUniqueness -import OAI.RepresentationTheory.FoulkesSixth.YoungGram -import OAI.RepresentationTheory.FoulkesSixth.Recurrence -import OAI.RepresentationTheory.FoulkesSixth.VanishingSteps -import OAI.RepresentationTheory.FoulkesSixth.Rows -import OAI.RepresentationTheory.FoulkesSixth.IndependentChart -import OAI.RepresentationTheory.FoulkesSixth.Vanishing -import OAI.RepresentationTheory.FoulkesSixth.BlockVanishing -import OAI.RepresentationTheory.FoulkesSixth.QuadraticInjection -import OAI.RepresentationTheory.FoulkesSixth.BlockInjection -import OAI.RepresentationTheory.FoulkesSixth.RangeReduction +import OAI.RepresentationTheory.FoulkesSixth.Collision +import OAI.RepresentationTheory.FoulkesSixth.Diagonal +import OAI.RepresentationTheory.FoulkesSixth.StripSupport +import OAI.RepresentationTheory.FoulkesSixth.CompleteNewton +import OAI.RepresentationTheory.FoulkesSixth.YoungModules +import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan +import OAI.RepresentationTheory.FoulkesSixth.SymTensors +import OAI.RepresentationTheory.FoulkesSixth.StripCoefficient +import OAI.RepresentationTheory.FoulkesSixth.SemisimpleBridge +import OAI.RepresentationTheory.FoulkesSixth.ColorOrbits +import OAI.RepresentationTheory.FoulkesSixth.SymDual +import OAI.RepresentationTheory.FoulkesSixth.Differential +import OAI.RepresentationTheory.FoulkesSixth.StripInterlace +import OAI.RepresentationTheory.FoulkesSixth.GenericShift +import OAI.RepresentationTheory.FoulkesSixth.SymOperations +import OAI.RepresentationTheory.FoulkesSixth.SignedStrips +import OAI.RepresentationTheory.FoulkesSixth.PlethDual +import OAI.RepresentationTheory.FoulkesSixth.SymPolynomial +import OAI.RepresentationTheory.FoulkesSixth.Lookup +import OAI.RepresentationTheory.FoulkesSixth.LookupExtraction +import OAI.RepresentationTheory.FoulkesSixth.AlternantExpansion +import OAI.RepresentationTheory.FoulkesSixth.TensorPolarization +import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm +import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization +import OAI.RepresentationTheory.FoulkesSixth.SourceNewton +import OAI.RepresentationTheory.FoulkesSixth.FastLookup +import OAI.RepresentationTheory.FoulkesSixth.SixCycles +import OAI.RepresentationTheory.FoulkesSixth.CompositionEnumeration +import OAI.RepresentationTheory.FoulkesSixth.FastLookupExact +import OAI.RepresentationTheory.FoulkesSixth.NewtonUniqueness +import OAI.RepresentationTheory.FoulkesSixth.YoungGram +import OAI.RepresentationTheory.FoulkesSixth.Recurrence +import OAI.RepresentationTheory.FoulkesSixth.VanishingSteps +import OAI.RepresentationTheory.FoulkesSixth.Rows +import OAI.RepresentationTheory.FoulkesSixth.IndependentChart +import OAI.RepresentationTheory.FoulkesSixth.Vanishing +import OAI.RepresentationTheory.FoulkesSixth.BlockVanishing +import OAI.RepresentationTheory.FoulkesSixth.QuadraticInjection +import OAI.RepresentationTheory.FoulkesSixth.BlockInjection +import OAI.RepresentationTheory.FoulkesSixth.RangeReduction diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/NewtonUniqueness.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/NewtonUniqueness.lean index 858a7c76e325c00b292311cc1ff0554cc8487dd6..a9717a6741aeca45d08cc422ada55a708c896b20 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/NewtonUniqueness.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/NewtonUniqueness.lean @@ -1,96 +1,96 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.SixCycles - -namespace OAI - -noncomputable section - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -lemma sortedPartition_sum {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : - (∑ j, sortedPartition v j) + ∑ j, staircase n j = ∑ j, v j := by - rw [← Finset.sum_add_distrib] - calc - _ = ∑ j, v (sortDesc v j) := by - apply Finset.sum_congr rfl - intro j hj - exact congrFun (shifted_sortedPartition v hv) j - _ = _ := Equiv.sum_comp (sortDesc v) v - -lemma previous_partition_sum {n b : ℕ} (mu : Fin n → ℕ) - (hmu : ∑ j, mu j = 6*b) (i : ℕ) (hi : i ≤ b) - (d : Complete.Degree (Fin n) 6) - (hn : ∀ j, 0 ≤ (shifted mu j : ℤ) - (i : ℤ)*d.val j) - (hw : Function.Injective (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat)) : - ∑ j, sortedPartition (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat) j = 6*(b-i) := by - have hd : ∑ j, d.val j = 6 := (Finsupp.degree_eq_sum d.val).symm.trans d.property - have hs := sortedPartition_sum _ hw - have hh : (∑ j, (((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat : ℕ) : ℤ) = - (6*b : ℕ) + (∑ j, staircase n j : ℕ) - (i : ℤ)*6 := by - push_cast - simp only [Int.toNat_of_nonneg (hn _), Finset.sum_sub_distrib, ← Finset.mul_sum] - simp only [shifted, Nat.cast_add, Finset.sum_add_distrib] - simp only [← Nat.cast_sum, hmu, hd] - norm_num - have hs' := congrArg (fun z : ℕ => (z : ℤ)) hs - rw [← Nat.cast_sum] at hh - rw [hh] at hs' - simp only [Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat] at hs' - omega - -lemma Q_zero_of_partition {n : ℕ} (mu : Fin n → ℕ) (hmu : ∑ j, mu j = 0) : - Q n 0 mu = 1 := by - have hm : mu = 0 := by - funext j - have hj := Finset.single_le_sum (f := mu) (fun k _ => Nat.zero_le _) (Finset.mem_univ j) - simpa [hmu] using hj - subst mu - unfold Q schurCoeff - rw [Complete.pleth_zero, one_mul] - have hstrict : StrictAnti (staircase n) := by - intro j k hjk - have hj := j.isLt - have hk := k.isLt - simp only [staircase] - change j.val < k.val at hjk - omega - have he : shifted (0 : Fin n → ℕ) = staircase n := by ext j; simp [shifted] - rw [he, coeff_alternant_strict _ _ hstrict hstrict, ite_eq_left rfl] - -theorem target_table_unique (n B : ℕ) (T : ℕ → (Fin n → ℕ) → ℤ) - (hzero : ∀ mu, Antitone mu → (∑ j, mu j = 0) → T 0 mu = 1) - (hstep : ∀ b, 1 ≤ b → b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → - (b : ℤ)*T b mu = ∑ i ∈ Finset.Icc 1 b, ∑ d : Complete.Degree (Fin n) 6, - signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j)) : - ∀ b, b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → T b mu = Q n b mu := by - classical - intro b - induction b using Nat.strong_induction_on with - | h b ih => - intro hb mu hm hs - by_cases h0 : b = 0 - · subst b - rw [hzero mu hm (by simpa using hs), Q_zero_of_partition mu (by simpa using hs)] - have hbpos : 1 ≤ b := by omega - apply (mul_left_cancel₀ (show (b : ℤ) ≠ 0 by exact_mod_cast h0)) - rw [hstep b hbpos hb mu hm hs, target_newton] - apply Finset.sum_congr rfl - intro i hi - apply Finset.sum_congr rfl - intro d hd - unfold signedLookup - dsimp only - split_ifs with hn hw - · congr 1 - exact ih (b-i) (by have := (Finset.mem_Icc.mp hi).1; omega) - (by omega) _ (sortedPartition_antitone _ hw) - (previous_partition_sum mu hs i (Finset.mem_Icc.mp hi).2 d hn hw) - · rfl - · rfl - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.SixCycles + +namespace OAI + +noncomputable section + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +lemma sortedPartition_sum {n : ℕ} (v : Fin n → ℕ) (hv : Function.Injective v) : + (∑ j, sortedPartition v j) + ∑ j, staircase n j = ∑ j, v j := by + rw [← Finset.sum_add_distrib] + calc + _ = ∑ j, v (sortDesc v j) := by + apply Finset.sum_congr rfl + intro j hj + exact congrFun (shifted_sortedPartition v hv) j + _ = _ := Equiv.sum_comp (sortDesc v) v + +lemma previous_partition_sum {n b : ℕ} (mu : Fin n → ℕ) + (hmu : ∑ j, mu j = 6*b) (i : ℕ) (hi : i ≤ b) + (d : Complete.Degree (Fin n) 6) + (hn : ∀ j, 0 ≤ (shifted mu j : ℤ) - (i : ℤ)*d.val j) + (hw : Function.Injective (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat)) : + ∑ j, sortedPartition (fun j => ((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat) j = 6*(b-i) := by + have hd : ∑ j, d.val j = 6 := (Finsupp.degree_eq_sum d.val).symm.trans d.property + have hs := sortedPartition_sum _ hw + have hh : (∑ j, (((shifted mu j : ℤ) - (i : ℤ)*d.val j).toNat : ℕ) : ℤ) = + (6*b : ℕ) + (∑ j, staircase n j : ℕ) - (i : ℤ)*6 := by + push_cast + simp only [Int.toNat_of_nonneg (hn _), Finset.sum_sub_distrib, ← Finset.mul_sum] + simp only [shifted, Nat.cast_add, Finset.sum_add_distrib] + simp only [← Nat.cast_sum, hmu, hd] + norm_num + have hs' := congrArg (fun z : ℕ => (z : ℤ)) hs + rw [← Nat.cast_sum] at hh + rw [hh] at hs' + simp only [Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat] at hs' + omega + +lemma Q_zero_of_partition {n : ℕ} (mu : Fin n → ℕ) (hmu : ∑ j, mu j = 0) : + Q n 0 mu = 1 := by + have hm : mu = 0 := by + funext j + have hj := Finset.single_le_sum (f := mu) (fun k _ => Nat.zero_le _) (Finset.mem_univ j) + simpa [hmu] using hj + subst mu + unfold Q schurCoeff + rw [Complete.pleth_zero, one_mul] + have hstrict : StrictAnti (staircase n) := by + intro j k hjk + have hj := j.isLt + have hk := k.isLt + simp only [staircase] + change j.val < k.val at hjk + omega + have he : shifted (0 : Fin n → ℕ) = staircase n := by ext j; simp [shifted] + rw [he, coeff_alternant_strict _ _ hstrict hstrict, ite_eq_left rfl] + +theorem target_table_unique (n B : ℕ) (T : ℕ → (Fin n → ℕ) → ℤ) + (hzero : ∀ mu, Antitone mu → (∑ j, mu j = 0) → T 0 mu = 1) + (hstep : ∀ b, 1 ≤ b → b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → + (b : ℤ)*T b mu = ∑ i ∈ Finset.Icc 1 b, ∑ d : Complete.Degree (Fin n) 6, + signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j)) : + ∀ b, b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → T b mu = Q n b mu := by + classical + intro b + induction b using Nat.strong_induction_on with + | h b ih => + intro hb mu hm hs + by_cases h0 : b = 0 + · subst b + rw [hzero mu hm (by simpa using hs), Q_zero_of_partition mu (by simpa using hs)] + have hbpos : 1 ≤ b := by omega + apply (mul_left_cancel₀ (show (b : ℤ) ≠ 0 by exact_mod_cast h0)) + rw [hstep b hbpos hb mu hm hs, target_newton] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro d hd + unfold signedLookup + dsimp only + split_ifs with hn hw + · congr 1 + exact ih (b-i) (by have := (Finset.mem_Icc.mp hi).1; omega) + (by omega) _ (sortedPartition_antitone _ hw) + (previous_partition_sum mu hs i (Finset.mem_Icc.mp hi).2 d hn hw) + · rfl + · rfl + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/PlethDual.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/PlethDual.lean index 9b1591a6530dcc0518274ca03859e2f7efee115f..4e85b9d8bde20aac9d99808ae32947c8df8f94d7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/PlethDual.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/PlethDual.lean @@ -1,54 +1,54 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.SymOperations - -namespace OAI - -noncomputable section - -namespace Foulkes.PlethDual -universe u -open Module SymmetricTensor -variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -local instance plethDualSymAddCommGroup (degree : ℕ) (space : Type u) - [AddCommGroup space] [Module ℂ space] : AddCommGroup (Sym degree space) := - (Sym degree space).addCommGroup - -def equiv : Sym a (Sym b (Dual ℂ V)) ≃ₗ[ℂ] Dual ℂ (Sym a (Sym b V)) := - (symEquiv a (dualEquiv b (V := V))).trans (dualEquiv a (V := Sym b V)) - -def flipEquiv : Sym a (Sym b V) ≃ₗ[ℂ] Dual ℂ (Sym a (Sym b (Dual ℂ V))) := - (Module.evalEquiv ℂ (Sym a (Sym b V))).trans (equiv a b V).dualMap - -@[simp] lemma flipEquiv_apply (x : Sym a (Sym b V)) (d : Sym a (Sym b (Dual ℂ V))) : - flipEquiv a b V x d = equiv a b V d x := rfl - -@[simp] lemma equiv_apply (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : - equiv a b V d x = pairing a (symMap a (dualEquiv b (V := V)).toLinearMap d) x := rfl - -lemma natural (g : V →ₗ[ℂ] V) (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : - equiv a b V (symMap a (symMap b g.dualMap) d) x = - equiv a b V d (symMap a (symMap b g) x) := by - have hi : (dualEquiv b (V := V)).toLinearMap.comp (symMap b g.dualMap) = - (symMap b g).dualMap.comp (dualEquiv b (V := V)).toLinearMap := by - apply LinearMap.ext - intro q - apply LinearMap.ext - intro v - exact pairing_map b g q v - have hs : symMap a (dualEquiv b (V := V)).toLinearMap - (symMap a (V := Sym b (Dual ℂ V)) (W := Sym b (Dual ℂ V)) (symMap b g.dualMap) d) = - symMap a (symMap b g).dualMap (symMap a (dualEquiv b (V := V)).toLinearMap d) := by - change ((symMap a (dualEquiv b (V := V)).toLinearMap).comp - (symMap a (symMap b g.dualMap))) d = - ((symMap a (symMap b g).dualMap).comp - (symMap a (dualEquiv b (V := V)).toLinearMap)) d - rw [← symMap_comp, hi, symMap_comp] - simp only [equiv_apply, hs] - exact pairing_map a (symMap b g) _ x - -end Foulkes.PlethDual - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.SymOperations + +namespace OAI + +noncomputable section + +namespace Foulkes.PlethDual +universe u +open Module SymmetricTensor +variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +local instance plethDualSymAddCommGroup (degree : ℕ) (space : Type u) + [AddCommGroup space] [Module ℂ space] : AddCommGroup (Sym degree space) := + (Sym degree space).addCommGroup + +def equiv : Sym a (Sym b (Dual ℂ V)) ≃ₗ[ℂ] Dual ℂ (Sym a (Sym b V)) := + (symEquiv a (dualEquiv b (V := V))).trans (dualEquiv a (V := Sym b V)) + +def flipEquiv : Sym a (Sym b V) ≃ₗ[ℂ] Dual ℂ (Sym a (Sym b (Dual ℂ V))) := + (Module.evalEquiv ℂ (Sym a (Sym b V))).trans (equiv a b V).dualMap + +@[simp] lemma flipEquiv_apply (x : Sym a (Sym b V)) (d : Sym a (Sym b (Dual ℂ V))) : + flipEquiv a b V x d = equiv a b V d x := rfl + +@[simp] lemma equiv_apply (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : + equiv a b V d x = pairing a (symMap a (dualEquiv b (V := V)).toLinearMap d) x := rfl + +lemma natural (g : V →ₗ[ℂ] V) (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : + equiv a b V (symMap a (symMap b g.dualMap) d) x = + equiv a b V d (symMap a (symMap b g) x) := by + have hi : (dualEquiv b (V := V)).toLinearMap.comp (symMap b g.dualMap) = + (symMap b g).dualMap.comp (dualEquiv b (V := V)).toLinearMap := by + apply LinearMap.ext + intro q + apply LinearMap.ext + intro v + exact pairing_map b g q v + have hs : symMap a (dualEquiv b (V := V)).toLinearMap + (symMap a (V := Sym b (Dual ℂ V)) (W := Sym b (Dual ℂ V)) (symMap b g.dualMap) d) = + symMap a (symMap b g).dualMap (symMap a (dualEquiv b (V := V)).toLinearMap d) := by + change ((symMap a (dualEquiv b (V := V)).toLinearMap).comp + (symMap a (symMap b g.dualMap))) d = + ((symMap a (symMap b g).dualMap).comp + (symMap a (dualEquiv b (V := V)).toLinearMap)) d + rw [← symMap_comp, hi, symMap_comp] + simp only [equiv_apply, hs] + exact pairing_map a (symMap b g) _ x + +end Foulkes.PlethDual + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/PolynomialSpan.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/PolynomialSpan.lean index 0fcc7cced85c9f51e8e08d9a136d9b1dcf5ded70..c307590dbb64e6029e2ef9c71a8ab07d7ef9e391 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/PolynomialSpan.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/PolynomialSpan.lean @@ -1,181 +1,181 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.PolynomialSpan -open MvPolynomial - -variable {σ A : Type*} [CommRing A] [Algebra ℂ A] - -def mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) : MvPolynomial σ ℂ := - ∑ d ∈ p.support, monomial d (l (p.coeff d)) - -@[simp] lemma coeff_mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) (d : σ →₀ ℕ) : - (mapCoeffs l p).coeff d = l (p.coeff d) := by - classical - by_cases hd : d ∈ p.support - · simp [mapCoeffs, coeff_monomial, hd] - · simp [mapCoeffs, coeff_monomial, hd, notMem_support_iff.mp hd] - -@[simp] lemma mapCoeffs_monomial (l : A →ₗ[ℂ] ℂ) (d : σ →₀ ℕ) (a : A) : - mapCoeffs l (monomial d a) = monomial d (l a) := by - classical - ext e - simp only [coeff_mapCoeffs, coeff_monomial] - split_ifs <;> simp - -@[simp] lemma mapCoeffs_add (l : A →ₗ[ℂ] ℂ) (p q : MvPolynomial σ A) : - mapCoeffs l (p + q) = mapCoeffs l p + mapCoeffs l q := by - ext d - simp - -lemma eval_mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) (x : σ → ℂ) : - eval x (mapCoeffs l p) = l (eval (fun i => algebraMap ℂ A (x i)) p) := by - classical - induction p using MvPolynomial.induction_on' with - | add p q hp hq => simp [hp, hq] - | monomial d a => - simp only [mapCoeffs_monomial, eval_monomial] - have hh : d.prod (fun i k => (algebraMap ℂ A) (x i) ^ k) = - algebraMap ℂ A (d.prod (fun i k => x i ^ k)) := by - simp [Finsupp.prod, map_prod, map_pow] - rw [hh, mul_comm a, ← Algebra.smul_def, map_smul] - simp [mul_comm] - -@[simp] lemma mapCoeffs_zero (l : A →ₗ[ℂ] ℂ) : - mapCoeffs l (0 : MvPolynomial σ A) = 0 := by - ext d - simp - -@[simp] lemma mapCoeffs_smul (l : A →ₗ[ℂ] ℂ) (c : ℂ) (p : MvPolynomial σ A) : - mapCoeffs l (c • p) = c • mapCoeffs l p := by - ext d - simp - -def mapCoeffsLM (l : A →ₗ[ℂ] ℂ) : MvPolynomial σ A →ₗ[ℂ] MvPolynomial σ ℂ where - toFun := mapCoeffs l - map_add' := mapCoeffs_add l - map_smul' := mapCoeffs_smul l - -@[simp] lemma mapCoeffs_sum {ι : Type*} (l : A →ₗ[ℂ] ℂ) - (s : Finset ι) (p : ι → MvPolynomial σ A) : - mapCoeffs l (∑ i ∈ s, p i) = ∑ i ∈ s, mapCoeffs l (p i) := - map_sum (mapCoeffsLM l) _ _ - -@[simp] lemma mapCoeffs_pderiv (l : A →ₗ[ℂ] ℂ) (i : σ) (p : MvPolynomial σ A) : - mapCoeffs l (pderiv i p) = pderiv i (mapCoeffs l p) := by - ext d - simp only [coeff_mapCoeffs, coeff_pderiv] - simpa [Algebra.smul_def, Nat.cast_add, mul_comm] using - l.map_smul ((d i + 1 : ℕ) : ℂ) (p.coeff (d + Finsupp.single i 1)) - -@[simp] lemma mapCoeffs_X_mul (l : A →ₗ[ℂ] ℂ) (i : σ) (p : MvPolynomial σ A) : - mapCoeffs l (X i * p) = X i * mapCoeffs l p := by - induction p using MvPolynomial.induction_on' with - | add p q hp hq => simp [mul_add, hp, hq] - | monomial d a => - simp [X] - -lemma homogeneous_mapCoeffs {M : Type*} [AddCommMonoid M] - (l : A →ₗ[ℂ] ℂ) (w : σ → M) {p : MvPolynomial σ A} {d : M} - (hp : p.IsWeightedHomogeneous w d) : (mapCoeffs l p).IsWeightedHomogeneous w d := by - intro m hm - exact hp (fun h => hm (by simp [h])) - -theorem coeff_mem_of_evaluations (p : MvPolynomial σ A) (S : Submodule ℂ A) - (h : ∀ x : σ → ℂ, eval (fun i => algebraMap ℂ A (x i)) p ∈ S) - (d : σ →₀ ℕ) : p.coeff d ∈ S := by - by_contra hd - obtain ⟨l, hld, hlS⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hd inferInstance - have hl (a : A) (ha : a ∈ S) : l a = 0 := by - have hh : l a ∈ S.map l := Submodule.mem_map.mpr ⟨a, ha, rfl⟩ - rwa [hlS, Submodule.mem_bot] at hh - have hz : mapCoeffs l p = 0 := by - apply MvPolynomial.funext - intro x - rw [eval_mapCoeffs, hl _ (h x), map_zero] - have hc := congrArg (fun polynomial => polynomial.coeff d) hz - exact hld (by simpa using hc) - -theorem prod_pow_mem_span_powers [Fintype σ] (a : σ → A) (d : σ →₀ ℕ) - (n : ℕ) (hd : d.sum (fun _ k => k) = n) : - d.prod (fun i k => a i ^ k) ∈ - Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • a i) ^ n) := by - classical - let S := Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • a i) ^ n) - let G : MvPolynomial σ A := (∑ i, a i • X i) ^ n - have heval (x : σ → ℂ) : eval (fun i => algebraMap ℂ A (x i)) G = - (∑ i, x i • a i) ^ n := by - simp [G, Algebra.smul_def, mul_comm] - have hcoeff : G.coeff d ∈ S := coeff_mem_of_evaluations G S (fun x => by - rw [heval] - exact Submodule.subset_span ⟨x, rfl⟩) d - change ((∑ i, a i • X i : MvPolynomial σ A) ^ n).coeff d ∈ S at hcoeff - rw [coeff_linearCombination_X_pow_of_fintype, ite_eq_left hd] at hcoeff - have hn : (d.multinomial : ℂ) ≠ 0 := by - exact_mod_cast (Nat.ne_of_gt (Nat.multinomial_pos (s := d.support) (f := d))) - apply (Submodule.smul_mem_iff S hn).mp - simpa only [Algebra.smul_def, map_natCast] using hcoeff - -theorem homogeneous_eq_span_powers [Fintype σ] (n : ℕ) : - homogeneousSubmodule σ ℂ n = - Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • X i) ^ n) := by - classical - apply le_antisymm - · intro p hp - induction hp using MvPolynomial.IsWeightedHomogeneous.induction_on with - | zero => exact Submodule.zero_mem _ - | add p q hp hq ihp ihq => exact Submodule.add_mem _ ihp ihq - | monomial d c hd => - rw [monomial_eq, ← MvPolynomial.smul_eq_C_mul] - apply Submodule.smul_mem - apply prod_pow_mem_span_powers - simpa [Finsupp.weight_apply, Finsupp.sum, smul_eq_mul] using hd - · apply Submodule.span_le.mpr - rintro _ ⟨x, rfl⟩ - have hh : (∑ i, x i • (X i : MvPolynomial σ ℂ)).IsHomogeneous 1 := by - apply MvPolynomial.IsWeightedHomogeneous.sum - intro i _ - exact (homogeneousSubmodule σ ℂ 1).smul_mem _ (isHomogeneous_X ℂ i) - simpa using hh.pow n - -theorem prod_mem_span_products {ι : Type*} [Fintype ι] - {S : ι → Set A} {x : ι → A} - (hx : ∀ i, x i ∈ Submodule.span ℂ (S i)) : - (∏ i, x i) ∈ Submodule.span ℂ - {p | ∃ y : ι → A, (∀ i, y i ∈ S i) ∧ ∏ i, y i = p} := by - classical - let T := Submodule.span ℂ - {p | ∃ y : ι → A, (∀ i, y i ∈ S i) ∧ ∏ i, y i = p} - have hspan : (∏ i, Submodule.span ℂ (S i)) ≤ T := by - rw [Submodule.prod_span] - apply Submodule.span_le.mpr - intro p hp - obtain ⟨y, hy, he⟩ := (Set.mem_fintype_prod S p).mp hp - exact Submodule.subset_span ⟨y, hy, he⟩ - apply hspan - have hprod (s : Finset ι) : (∏ i ∈ s, x i) ∈ ∏ i ∈ s, Submodule.span ℂ (S i) := by - induction s using Finset.induction_on with - | empty => simpa using (Submodule.algebraMap_mem (R := ℂ) (A := A) 1) - | insert i s hi ih => - simp only [Finset.prod_insert hi] - exact Submodule.mul_mem_mul (hx i) ih - exact hprod Finset.univ - -theorem prod_mem_span_range {ι : Type*} [Fintype ι] {β : ι → Type*} - (f : ∀ i, β i → A) {x : ι → A} - (hx : ∀ i, x i ∈ Submodule.span ℂ (Set.range (f i))) : - (∏ i, x i) ∈ Submodule.span ℂ (Set.range fun y : ∀ i, β i => ∏ i, f i (y i)) := by - apply (Submodule.span_mono (t := Set.range fun y : ∀ i, β i => ∏ i, f i (y i)) - (by - rintro p ⟨y, hy, rfl⟩ - choose z hz using hy - exact ⟨z, by simp [hz]⟩)) (prod_mem_span_products hx) - -end Foulkes.PolynomialSpan - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.PolynomialSpan +open MvPolynomial + +variable {σ A : Type*} [CommRing A] [Algebra ℂ A] + +def mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) : MvPolynomial σ ℂ := + ∑ d ∈ p.support, monomial d (l (p.coeff d)) + +@[simp] lemma coeff_mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) (d : σ →₀ ℕ) : + (mapCoeffs l p).coeff d = l (p.coeff d) := by + classical + by_cases hd : d ∈ p.support + · simp [mapCoeffs, coeff_monomial, hd] + · simp [mapCoeffs, coeff_monomial, hd, notMem_support_iff.mp hd] + +@[simp] lemma mapCoeffs_monomial (l : A →ₗ[ℂ] ℂ) (d : σ →₀ ℕ) (a : A) : + mapCoeffs l (monomial d a) = monomial d (l a) := by + classical + ext e + simp only [coeff_mapCoeffs, coeff_monomial] + split_ifs <;> simp + +@[simp] lemma mapCoeffs_add (l : A →ₗ[ℂ] ℂ) (p q : MvPolynomial σ A) : + mapCoeffs l (p + q) = mapCoeffs l p + mapCoeffs l q := by + ext d + simp + +lemma eval_mapCoeffs (l : A →ₗ[ℂ] ℂ) (p : MvPolynomial σ A) (x : σ → ℂ) : + eval x (mapCoeffs l p) = l (eval (fun i => algebraMap ℂ A (x i)) p) := by + classical + induction p using MvPolynomial.induction_on' with + | add p q hp hq => simp [hp, hq] + | monomial d a => + simp only [mapCoeffs_monomial, eval_monomial] + have hh : d.prod (fun i k => (algebraMap ℂ A) (x i) ^ k) = + algebraMap ℂ A (d.prod (fun i k => x i ^ k)) := by + simp [Finsupp.prod, map_prod, map_pow] + rw [hh, mul_comm a, ← Algebra.smul_def, map_smul] + simp [mul_comm] + +@[simp] lemma mapCoeffs_zero (l : A →ₗ[ℂ] ℂ) : + mapCoeffs l (0 : MvPolynomial σ A) = 0 := by + ext d + simp + +@[simp] lemma mapCoeffs_smul (l : A →ₗ[ℂ] ℂ) (c : ℂ) (p : MvPolynomial σ A) : + mapCoeffs l (c • p) = c • mapCoeffs l p := by + ext d + simp + +def mapCoeffsLM (l : A →ₗ[ℂ] ℂ) : MvPolynomial σ A →ₗ[ℂ] MvPolynomial σ ℂ where + toFun := mapCoeffs l + map_add' := mapCoeffs_add l + map_smul' := mapCoeffs_smul l + +@[simp] lemma mapCoeffs_sum {ι : Type*} (l : A →ₗ[ℂ] ℂ) + (s : Finset ι) (p : ι → MvPolynomial σ A) : + mapCoeffs l (∑ i ∈ s, p i) = ∑ i ∈ s, mapCoeffs l (p i) := + map_sum (mapCoeffsLM l) _ _ + +@[simp] lemma mapCoeffs_pderiv (l : A →ₗ[ℂ] ℂ) (i : σ) (p : MvPolynomial σ A) : + mapCoeffs l (pderiv i p) = pderiv i (mapCoeffs l p) := by + ext d + simp only [coeff_mapCoeffs, coeff_pderiv] + simpa [Algebra.smul_def, Nat.cast_add, mul_comm] using + l.map_smul ((d i + 1 : ℕ) : ℂ) (p.coeff (d + Finsupp.single i 1)) + +@[simp] lemma mapCoeffs_X_mul (l : A →ₗ[ℂ] ℂ) (i : σ) (p : MvPolynomial σ A) : + mapCoeffs l (X i * p) = X i * mapCoeffs l p := by + induction p using MvPolynomial.induction_on' with + | add p q hp hq => simp [mul_add, hp, hq] + | monomial d a => + simp [X] + +lemma homogeneous_mapCoeffs {M : Type*} [AddCommMonoid M] + (l : A →ₗ[ℂ] ℂ) (w : σ → M) {p : MvPolynomial σ A} {d : M} + (hp : p.IsWeightedHomogeneous w d) : (mapCoeffs l p).IsWeightedHomogeneous w d := by + intro m hm + exact hp (fun h => hm (by simp [h])) + +theorem coeff_mem_of_evaluations (p : MvPolynomial σ A) (S : Submodule ℂ A) + (h : ∀ x : σ → ℂ, eval (fun i => algebraMap ℂ A (x i)) p ∈ S) + (d : σ →₀ ℕ) : p.coeff d ∈ S := by + by_contra hd + obtain ⟨l, hld, hlS⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hd inferInstance + have hl (a : A) (ha : a ∈ S) : l a = 0 := by + have hh : l a ∈ S.map l := Submodule.mem_map.mpr ⟨a, ha, rfl⟩ + rwa [hlS, Submodule.mem_bot] at hh + have hz : mapCoeffs l p = 0 := by + apply MvPolynomial.funext + intro x + rw [eval_mapCoeffs, hl _ (h x), map_zero] + have hc := congrArg (fun polynomial => polynomial.coeff d) hz + exact hld (by simpa using hc) + +theorem prod_pow_mem_span_powers [Fintype σ] (a : σ → A) (d : σ →₀ ℕ) + (n : ℕ) (hd : d.sum (fun _ k => k) = n) : + d.prod (fun i k => a i ^ k) ∈ + Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • a i) ^ n) := by + classical + let S := Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • a i) ^ n) + let G : MvPolynomial σ A := (∑ i, a i • X i) ^ n + have heval (x : σ → ℂ) : eval (fun i => algebraMap ℂ A (x i)) G = + (∑ i, x i • a i) ^ n := by + simp [G, Algebra.smul_def, mul_comm] + have hcoeff : G.coeff d ∈ S := coeff_mem_of_evaluations G S (fun x => by + rw [heval] + exact Submodule.subset_span ⟨x, rfl⟩) d + change ((∑ i, a i • X i : MvPolynomial σ A) ^ n).coeff d ∈ S at hcoeff + rw [coeff_linearCombination_X_pow_of_fintype, ite_eq_left hd] at hcoeff + have hn : (d.multinomial : ℂ) ≠ 0 := by + exact_mod_cast (Nat.ne_of_gt (Nat.multinomial_pos (s := d.support) (f := d))) + apply (Submodule.smul_mem_iff S hn).mp + simpa only [Algebra.smul_def, map_natCast] using hcoeff + +theorem homogeneous_eq_span_powers [Fintype σ] (n : ℕ) : + homogeneousSubmodule σ ℂ n = + Submodule.span ℂ (Set.range fun x : σ → ℂ => (∑ i, x i • X i) ^ n) := by + classical + apply le_antisymm + · intro p hp + induction hp using MvPolynomial.IsWeightedHomogeneous.induction_on with + | zero => exact Submodule.zero_mem _ + | add p q hp hq ihp ihq => exact Submodule.add_mem _ ihp ihq + | monomial d c hd => + rw [monomial_eq, ← MvPolynomial.smul_eq_C_mul] + apply Submodule.smul_mem + apply prod_pow_mem_span_powers + simpa [Finsupp.weight_apply, Finsupp.sum, smul_eq_mul] using hd + · apply Submodule.span_le.mpr + rintro _ ⟨x, rfl⟩ + have hh : (∑ i, x i • (X i : MvPolynomial σ ℂ)).IsHomogeneous 1 := by + apply MvPolynomial.IsWeightedHomogeneous.sum + intro i _ + exact (homogeneousSubmodule σ ℂ 1).smul_mem _ (isHomogeneous_X ℂ i) + simpa using hh.pow n + +theorem prod_mem_span_products {ι : Type*} [Fintype ι] + {S : ι → Set A} {x : ι → A} + (hx : ∀ i, x i ∈ Submodule.span ℂ (S i)) : + (∏ i, x i) ∈ Submodule.span ℂ + {p | ∃ y : ι → A, (∀ i, y i ∈ S i) ∧ ∏ i, y i = p} := by + classical + let T := Submodule.span ℂ + {p | ∃ y : ι → A, (∀ i, y i ∈ S i) ∧ ∏ i, y i = p} + have hspan : (∏ i, Submodule.span ℂ (S i)) ≤ T := by + rw [Submodule.prod_span] + apply Submodule.span_le.mpr + intro p hp + obtain ⟨y, hy, he⟩ := (Set.mem_fintype_prod S p).mp hp + exact Submodule.subset_span ⟨y, hy, he⟩ + apply hspan + have hprod (s : Finset ι) : (∏ i ∈ s, x i) ∈ ∏ i ∈ s, Submodule.span ℂ (S i) := by + induction s using Finset.induction_on with + | empty => simpa using (Submodule.algebraMap_mem (R := ℂ) (A := A) 1) + | insert i s hi ih => + simp only [Finset.prod_insert hi] + exact Submodule.mul_mem_mul (hx i) ih + exact hprod Finset.univ + +theorem prod_mem_span_range {ι : Type*} [Fintype ι] {β : ι → Type*} + (f : ∀ i, β i → A) {x : ι → A} + (hx : ∀ i, x i ∈ Submodule.span ℂ (Set.range (f i))) : + (∏ i, x i) ∈ Submodule.span ℂ (Set.range fun y : ∀ i, β i => ∏ i, f i (y i)) := by + apply (Submodule.span_mono (t := Set.range fun y : ∀ i, β i => ∏ i, f i (y i)) + (by + rintro p ⟨y, hy, rfl⟩ + choose z hz using hy + exact ⟨z, by simp [hz]⟩)) (prod_mem_span_products hx) + +end Foulkes.PolynomialSpan + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/QuadraticInjection.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/QuadraticInjection.lean index 8ffcb44e87f0f23bc39a4144f018d3813e266b72..22743788044931c310cee3bf56806835545f9530 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/QuadraticInjection.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/QuadraticInjection.lean @@ -1,316 +1,316 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.PlethDual -import OAI.RepresentationTheory.FoulkesSixth.Vanishing -import OAI.RepresentationTheory.FoulkesSixth.Rows - -namespace OAI - -noncomputable section - -namespace Foulkes -universe u -variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - -instance symAddCommGroup : AddCommGroup (Sym n V) := (Sym n V).addCommGroup -instance symModule : Module ℂ (Sym n V) := (Sym n V).module -instance symFinite [FiniteDimensional ℂ V] : FiniteDimensional ℂ (Sym n V) := - inferInstance -instance symFree : Module.Free ℂ (Sym n V) := inferInstance - -end Foulkes - -namespace Foulkes.Canonical -universe u -open Module MvPolynomial SymmetricTensor Polarization -variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] -variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) - -def firstEquiv : Sym a V ≃ₗ[ℂ] R a n 1 := - (symEquiv a (oneEquiv V).symm).trans (Rows.equiv B a 1) - -def firstMap : Sym a V →ₗ[ℂ] P a n := - (R a n 1).subtype.comp (firstEquiv B a).toLinearMap - -lemma firstMap_mem (x : Sym a V) : firstMap B a x ∈ R a n 1 := - (firstEquiv B a x).property - -@[simp] lemma firstMap_power (v : V) : firstMap B a (power a V v) = z (a := a) (B.equivFun v) := by - change Rows.invariantMap B a 1 - (symMap a (oneEquiv V).symm.toLinearMap (power a V v)) = _ - rw [symMap_power, LinearEquiv.coe_coe, oneEquiv_symm] - change Rows.tensorMap B a 1 - (PiTensorProduct.tprod ℂ (fun _ : Fin a => power 1 V v)) = _ - rw [Rows.tensorMap_powers] - simp only [pureRows, pow_one, z] - -def productPolynomial : Sym b (Sym a V) →ₗ[ℂ] P a n := - SymAlgebra.multiply b (firstMap B a) - -@[simp] lemma productPolynomial_power (q : Sym a V) : - productPolynomial B a b (power b (Sym a V) q) = firstMap B a q ^ b := - SymAlgebra.multiply_power b (firstMap B a) q - -lemma productPolynomial_mem (x : Sym b (Sym a V)) : productPolynomial B a b x ∈ R a n b := by - have h : Submodule.span ℂ (Set.range (power b (Sym a V))) ≤ - (R a n b).comap (productPolynomial B a b) := by - apply Submodule.span_le.mpr - rintro _ ⟨q, rfl⟩ - change productPolynomial B a b (power b (Sym a V) q) ∈ R a n b - rw [productPolynomial_power] - constructor - · have hq := (firstMap_mem B a q).1.pow b - simpa [W, Pi.smul_def] using hq - · intro σ - rw [map_pow, (firstMap_mem B a q).2 σ] - rw [span_power] at h - exact h (Submodule.mem_top : x ∈ ⊤) - -lemma productPolynomial_project (q : Fin b → Sym a V) : - productPolynomial B a b (project b (Sym a V) (PiTensorProduct.tprod ℂ q)) = - ∏ i, firstMap B a (q i) := by - exact (SymAlgebra.multiply_project b (firstMap B a) _).trans - (SymAlgebra.tensorMul_tprod b (firstMap B a) q) - -lemma products_in_range (y : Fin b → Fin n → ℂ) : - (∏ j, z (a := a) (y j)) ∈ (productPolynomial B a b).range := by - refine ⟨project b (Sym a V) (PiTensorProduct.tprod ℂ - (fun j => power a V (B.equivFun.symm (y j)))), ?_⟩ - rw [productPolynomial_project] - simp only [firstMap_power, LinearEquiv.apply_symm_apply] - -theorem productPolynomial_range (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : - (productPolynomial B a b).range = R a n b := by - classical - apply le_antisymm - · rintro _ ⟨x, rfl⟩ - exact productPolynomial_mem B a b x - · intro p hp - by_contra hnot - obtain ⟨l, hlp, hlrange⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance - have hkill (f : P a n) (hf : f ∈ (productPolynomial B a b).range) : l f = 0 := by - have hh : l f ∈ ((productPolynomial B a b).range).map l := Submodule.mem_map.mpr ⟨f,hf,rfl⟩ - rwa [hlrange, Submodule.mem_bot] at hh - let lav := l.comp (Polarization.average a n) - have hs : Vanishing.Symmetric lav := by - intro σ f - change l (Polarization.average a n (renameRow σ f)) = l (Polarization.average a n f) - rw [Vanishing.average_renameRow] - have hz : Vanishing.ProductsVanish lav b := by - intro y - change l (Polarization.average a n (∏ j, z (y j))) = 0 - rw [Polarization.average_eq (show (∏ j, z (a := a) (y j)) ∈ rowInvariants a n from by - intro σ; simp)] - exact hkill _ (products_in_range B a b y) - have hh := Vanishing.vanishing a ha hb0 hb hs hz p hp.1 - change l (Polarization.average a n p) = 0 at hh - rw [Polarization.average_eq hp.2] at hh - exact hlp hh - -def map : Sym b (Sym a V) →ₗ[ℂ] Sym a (Sym b V) := - (Rows.equiv B a b).symm.toLinearMap.comp - ((productPolynomial B a b).codRestrict (R a n b) (productPolynomial_mem B a b)) - -@[simp] lemma map_polynomial (x : Sym b (Sym a V)) : - Rows.invariantMap B a b (map B a b x) = productPolynomial B a b x := by - change (Rows.equiv B a b - ((Rows.equiv B a b).symm ⟨productPolynomial B a b x, productPolynomial_mem B a b x⟩) : P a n) = _ - rw [LinearEquiv.apply_symm_apply] - -theorem surjective (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : - Function.Surjective (map B a b) := by - intro x - have hp : Rows.invariantMap B a b x ∈ (productPolynomial B a b).range := by - rw [productPolynomial_range B a b ha hb0 hb] - exact (Rows.equiv B a b x).property - obtain ⟨y, hy⟩ := hp - refine ⟨y, (Rows.invariantMap_injective B a b) ?_⟩ - rw [map_polynomial, hy] - -end Foulkes.Canonical - -namespace Foulkes.Canonical -universe u -open Module MvPolynomial SymmetricTensor Polarization -variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] -variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) - -omit [FiniteDimensional ℂ V] in -section - -def substitution (g : V →ₗ[ℂ] V) : P a n →ₐ[ℂ] P a n := - aeval (fun ik : Fin a × Fin n => - Rows.row ik.1 (SymPolynomial.linearPolynomial B (g (B ik.2)))) - -lemma linearPolynomial_basis (k : Fin n) : SymPolynomial.linearPolynomial B (B k) = X k := by - classical - simp only [SymPolynomial.linearPolynomial_apply, B.equivFun_self] - simp - -lemma substitution_row_linear (g : V →ₗ[ℂ] V) (i : Fin a) (v : V) : - substitution B a g (Rows.row i (SymPolynomial.linearPolynomial B v)) = - Rows.row i (SymPolynomial.linearPolynomial B (g v)) := by - have hh : (substitution B a g).toLinearMap.comp - ((Rows.row i).toLinearMap.comp (SymPolynomial.linearPolynomial B)) = - (Rows.row i).toLinearMap.comp ((SymPolynomial.linearPolynomial B).comp g) := by - apply B.ext - intro k - simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, linearPolynomial_basis] - simp [Rows.row, substitution] - exact DFunLike.congr_fun hh v - -lemma substitution_rowForm (g : V →ₗ[ℂ] V) (i : Fin a) (v : V) : - substitution B a g (rowForm i (B.equivFun v)) = rowForm i (B.equivFun (g v)) := by - simpa only [Rows.row_linear] using substitution_row_linear B a g i v - -lemma substitution_z (g : V →ₗ[ℂ] V) (v : V) : - substitution B a g (z (a := a) (B.equivFun v)) = z (a := a) (B.equivFun (g v)) := by - simp only [z, map_prod, substitution_rowForm] - -lemma row_polynomial_natural (g : V →ₗ[ℂ] V) (i : Fin a) (q : Sym b V) : - Rows.row i (SymPolynomial.polynomial B b (symMap b g q)) = - substitution B a g (Rows.row i (SymPolynomial.polynomial B b q)) := by - have hh : (Rows.row i).toLinearMap.comp ((SymPolynomial.polynomial B b).comp (symMap b g)) = - (substitution B a g).toLinearMap.comp - ((Rows.row i).toLinearMap.comp (SymPolynomial.polynomial B b)) := by - apply symMap_ext - intro v - simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, - SymPolynomial.polynomial_power, map_pow, substitution_row_linear] - exact DFunLike.congr_fun hh q - -lemma tensorMap_natural (g : V →ₗ[ℂ] V) (x : T a (Sym b V)) : - Rows.tensorMap B a b (PiTensorProduct.map (fun _ : Fin a => symMap b g) x) = - substitution B a g (Rows.tensorMap B a b x) := by - have hh : (Rows.tensorMap B a b).comp (PiTensorProduct.map (fun _ : Fin a => symMap b g)) = - (substitution B a g).toLinearMap.comp (Rows.tensorMap B a b) := by - apply PiTensorProduct.ext - apply MultilinearMap.ext - intro v - simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, PiTensorProduct.map_tprod, - Rows.tensorMap_tprod, AlgHom.toLinearMap_apply, map_prod, row_polynomial_natural] - exact DFunLike.congr_fun hh x - -lemma invariantMap_natural (g : V →ₗ[ℂ] V) (x : Sym a (Sym b V)) : - Rows.invariantMap B a b (symMap a (symMap b g) x) = - substitution B a g (Rows.invariantMap B a b x) := - tensorMap_natural B a b g x - -end - -lemma firstMap_natural (g : V →ₗ[ℂ] V) (q : Sym a V) : - firstMap B a (symMap a g q) = substitution B a g (firstMap B a q) := by - have hh : (firstMap B a).comp (symMap a g) = - (substitution B a g).toLinearMap.comp (firstMap B a) := by - apply symMap_ext - intro v - simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, - firstMap_power, substitution_z] - exact DFunLike.congr_fun hh q - -lemma productPolynomial_natural (g : V →ₗ[ℂ] V) (x : Sym b (Sym a V)) : - productPolynomial B a b (symMap b (symMap a g) x) = - substitution B a g (productPolynomial B a b x) := by - have hh : (productPolynomial B a b).comp (symMap b (symMap a g)) = - (substitution B a g).toLinearMap.comp (productPolynomial B a b) := by - apply symMap_ext - intro q - simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, - productPolynomial_power, firstMap_natural, map_pow] - exact DFunLike.congr_fun hh x - -theorem natural (g : V →ₗ[ℂ] V) (x : Sym b (Sym a V)) : - map B a b (symMap b (symMap a g) x) = symMap a (symMap b g) (map B a b x) := by - apply Rows.invariantMap_injective B a b - rw [map_polynomial, invariantMap_natural, map_polynomial, productPolynomial_natural] - -end Foulkes.Canonical - -namespace Foulkes.PlethDual -universe u -open Module SymmetricTensor -variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -lemma natural_congr (g : V →ₗ[ℂ] V) (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : - equiv a b V (symMap a (symMap b g.dualMap) d) x = - equiv a b V d (symMap a (symMap b g) x) := by - have hi : (dualEquiv b (V := V)).toLinearMap.comp (symMap b g.dualMap) = - (symMap b g).dualMap.comp (dualEquiv b (V := V)).toLinearMap := by - apply LinearMap.ext - intro q - apply LinearMap.ext - intro v - exact pairing_map b g q v - have hs := congrArg (fun (f : Sym b (Dual ℂ V) →ₗ[ℂ] Dual ℂ (Sym b V)) => - symMap a f d) hi - simp only [symMap_comp, LinearMap.comp_apply] at hs - simp only [equiv_apply, hs] - exact pairing_map a (symMap b g) _ x - -end Foulkes.PlethDual - -namespace Foulkes.Injection -universe u -open Module -variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] - -def map : Sym a (Sym b V) →ₗ[ℂ] Sym b (Sym a V) := - (PlethDual.flipEquiv b a V).symm.toLinearMap.comp - ((Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b).dualMap.comp - (PlethDual.flipEquiv a b V).toLinearMap) - -lemma adjoint (x : Sym a (Sym b V)) (d : Sym b (Sym a (Dual ℂ V))) : - PlethDual.equiv b a V d (map a b V x) = - PlethDual.equiv a b V (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d) x := by - change PlethDual.flipEquiv b a V - ((PlethDual.flipEquiv b a V).symm - ((Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b).dualMap - (PlethDual.flipEquiv a b V x))) d = _ - rw [LinearEquiv.apply_symm_apply] - rfl - -lemma injective (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : - Function.Injective (map a b V) := - (PlethDual.flipEquiv b a V).symm.injective.comp - ((LinearMap.dualMap_injective_of_surjective - (Canonical.surjective (Module.finBasis ℂ (Dual ℂ V)) a b ha hb0 hb)).comp - (PlethDual.flipEquiv a b V).injective) - -theorem natural (g : V →ₗ[ℂ] V) (x : Sym a (Sym b V)) : - map a b V (symMap a (symMap b g) x) = symMap b (symMap a g) (map a b V x) := by - apply (PlethDual.flipEquiv b a V).injective - apply LinearMap.ext - intro d - change PlethDual.equiv b a V d (map a b V (symMap a (symMap b g) x)) = - PlethDual.equiv b a V d (symMap b (symMap a g) (map a b V x)) - calc - _ = PlethDual.equiv a b V (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d) - (symMap a (symMap b g) x) := adjoint a b V _ d - _ = PlethDual.equiv a b V - (symMap a (symMap b g.dualMap) (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d)) x := - (PlethDual.natural a b V g _ x).symm - _ = PlethDual.equiv a b V - (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b (symMap b (symMap a g.dualMap) d)) x := by - rw [Canonical.natural] - _ = PlethDual.equiv b a V (symMap b (symMap a g.dualMap) d) (map a b V x) := - (adjoint a b V x _).symm - _ = _ := PlethDual.natural b a V g d (map a b V x) - -theorem quadratic_comparison (ha : 2 ≤ a) (hb : a*(a-1) ≤ b) : - ∃ i : Sym a (Sym b V) →ₗ[ℂ] Sym b (Sym a V), Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym a (Sym b V)), - i (symMap a (symMap b g.toLinearMap) x) = symMap b (symMap a g.toLinearMap) (i x) := by - have hb0 : 1 ≤ b := le_trans (Nat.mul_pos (by omega) (by omega)) hb - exact ⟨map a b V, injective a b V (by omega) hb0 hb, fun g x => natural a b V g.toLinearMap x⟩ - -theorem sixth_large (b : ℕ) (hb : 30 ≤ b) - (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : - ∃ i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V), Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), - i (symMap 6 (symMap b g.toLinearMap) x) = symMap b (symMap 6 g.toLinearMap) (i x) := - quadratic_comparison 6 b V (by omega) (by omega) - -end Foulkes.Injection - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.PlethDual +import OAI.RepresentationTheory.FoulkesSixth.Vanishing +import OAI.RepresentationTheory.FoulkesSixth.Rows + +namespace OAI + +noncomputable section + +namespace Foulkes +universe u +variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + +instance symAddCommGroup : AddCommGroup (Sym n V) := (Sym n V).addCommGroup +instance symModule : Module ℂ (Sym n V) := (Sym n V).module +instance symFinite [FiniteDimensional ℂ V] : FiniteDimensional ℂ (Sym n V) := + inferInstance +instance symFree : Module.Free ℂ (Sym n V) := inferInstance + +end Foulkes + +namespace Foulkes.Canonical +universe u +open Module MvPolynomial SymmetricTensor Polarization +variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] +variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) + +def firstEquiv : Sym a V ≃ₗ[ℂ] R a n 1 := + (symEquiv a (oneEquiv V).symm).trans (Rows.equiv B a 1) + +def firstMap : Sym a V →ₗ[ℂ] P a n := + (R a n 1).subtype.comp (firstEquiv B a).toLinearMap + +lemma firstMap_mem (x : Sym a V) : firstMap B a x ∈ R a n 1 := + (firstEquiv B a x).property + +@[simp] lemma firstMap_power (v : V) : firstMap B a (power a V v) = z (a := a) (B.equivFun v) := by + change Rows.invariantMap B a 1 + (symMap a (oneEquiv V).symm.toLinearMap (power a V v)) = _ + rw [symMap_power, LinearEquiv.coe_coe, oneEquiv_symm] + change Rows.tensorMap B a 1 + (PiTensorProduct.tprod ℂ (fun _ : Fin a => power 1 V v)) = _ + rw [Rows.tensorMap_powers] + simp only [pureRows, pow_one, z] + +def productPolynomial : Sym b (Sym a V) →ₗ[ℂ] P a n := + SymAlgebra.multiply b (firstMap B a) + +@[simp] lemma productPolynomial_power (q : Sym a V) : + productPolynomial B a b (power b (Sym a V) q) = firstMap B a q ^ b := + SymAlgebra.multiply_power b (firstMap B a) q + +lemma productPolynomial_mem (x : Sym b (Sym a V)) : productPolynomial B a b x ∈ R a n b := by + have h : Submodule.span ℂ (Set.range (power b (Sym a V))) ≤ + (R a n b).comap (productPolynomial B a b) := by + apply Submodule.span_le.mpr + rintro _ ⟨q, rfl⟩ + change productPolynomial B a b (power b (Sym a V) q) ∈ R a n b + rw [productPolynomial_power] + constructor + · have hq := (firstMap_mem B a q).1.pow b + simpa [W, Pi.smul_def] using hq + · intro σ + rw [map_pow, (firstMap_mem B a q).2 σ] + rw [span_power] at h + exact h (Submodule.mem_top : x ∈ ⊤) + +lemma productPolynomial_project (q : Fin b → Sym a V) : + productPolynomial B a b (project b (Sym a V) (PiTensorProduct.tprod ℂ q)) = + ∏ i, firstMap B a (q i) := by + exact (SymAlgebra.multiply_project b (firstMap B a) _).trans + (SymAlgebra.tensorMul_tprod b (firstMap B a) q) + +lemma products_in_range (y : Fin b → Fin n → ℂ) : + (∏ j, z (a := a) (y j)) ∈ (productPolynomial B a b).range := by + refine ⟨project b (Sym a V) (PiTensorProduct.tprod ℂ + (fun j => power a V (B.equivFun.symm (y j)))), ?_⟩ + rw [productPolynomial_project] + simp only [firstMap_power, LinearEquiv.apply_symm_apply] + +theorem productPolynomial_range (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : + (productPolynomial B a b).range = R a n b := by + classical + apply le_antisymm + · rintro _ ⟨x, rfl⟩ + exact productPolynomial_mem B a b x + · intro p hp + by_contra hnot + obtain ⟨l, hlp, hlrange⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance + have hkill (f : P a n) (hf : f ∈ (productPolynomial B a b).range) : l f = 0 := by + have hh : l f ∈ ((productPolynomial B a b).range).map l := Submodule.mem_map.mpr ⟨f,hf,rfl⟩ + rwa [hlrange, Submodule.mem_bot] at hh + let lav := l.comp (Polarization.average a n) + have hs : Vanishing.Symmetric lav := by + intro σ f + change l (Polarization.average a n (renameRow σ f)) = l (Polarization.average a n f) + rw [Vanishing.average_renameRow] + have hz : Vanishing.ProductsVanish lav b := by + intro y + change l (Polarization.average a n (∏ j, z (y j))) = 0 + rw [Polarization.average_eq (show (∏ j, z (a := a) (y j)) ∈ rowInvariants a n from by + intro σ; simp)] + exact hkill _ (products_in_range B a b y) + have hh := Vanishing.vanishing a ha hb0 hb hs hz p hp.1 + change l (Polarization.average a n p) = 0 at hh + rw [Polarization.average_eq hp.2] at hh + exact hlp hh + +def map : Sym b (Sym a V) →ₗ[ℂ] Sym a (Sym b V) := + (Rows.equiv B a b).symm.toLinearMap.comp + ((productPolynomial B a b).codRestrict (R a n b) (productPolynomial_mem B a b)) + +@[simp] lemma map_polynomial (x : Sym b (Sym a V)) : + Rows.invariantMap B a b (map B a b x) = productPolynomial B a b x := by + change (Rows.equiv B a b + ((Rows.equiv B a b).symm ⟨productPolynomial B a b x, productPolynomial_mem B a b x⟩) : P a n) = _ + rw [LinearEquiv.apply_symm_apply] + +theorem surjective (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : + Function.Surjective (map B a b) := by + intro x + have hp : Rows.invariantMap B a b x ∈ (productPolynomial B a b).range := by + rw [productPolynomial_range B a b ha hb0 hb] + exact (Rows.equiv B a b x).property + obtain ⟨y, hy⟩ := hp + refine ⟨y, (Rows.invariantMap_injective B a b) ?_⟩ + rw [map_polynomial, hy] + +end Foulkes.Canonical + +namespace Foulkes.Canonical +universe u +open Module MvPolynomial SymmetricTensor Polarization +variable {V : Type u} [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] +variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) + +omit [FiniteDimensional ℂ V] in +section + +def substitution (g : V →ₗ[ℂ] V) : P a n →ₐ[ℂ] P a n := + aeval (fun ik : Fin a × Fin n => + Rows.row ik.1 (SymPolynomial.linearPolynomial B (g (B ik.2)))) + +lemma linearPolynomial_basis (k : Fin n) : SymPolynomial.linearPolynomial B (B k) = X k := by + classical + simp only [SymPolynomial.linearPolynomial_apply, B.equivFun_self] + simp + +lemma substitution_row_linear (g : V →ₗ[ℂ] V) (i : Fin a) (v : V) : + substitution B a g (Rows.row i (SymPolynomial.linearPolynomial B v)) = + Rows.row i (SymPolynomial.linearPolynomial B (g v)) := by + have hh : (substitution B a g).toLinearMap.comp + ((Rows.row i).toLinearMap.comp (SymPolynomial.linearPolynomial B)) = + (Rows.row i).toLinearMap.comp ((SymPolynomial.linearPolynomial B).comp g) := by + apply B.ext + intro k + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, linearPolynomial_basis] + simp [Rows.row, substitution] + exact DFunLike.congr_fun hh v + +lemma substitution_rowForm (g : V →ₗ[ℂ] V) (i : Fin a) (v : V) : + substitution B a g (rowForm i (B.equivFun v)) = rowForm i (B.equivFun (g v)) := by + simpa only [Rows.row_linear] using substitution_row_linear B a g i v + +lemma substitution_z (g : V →ₗ[ℂ] V) (v : V) : + substitution B a g (z (a := a) (B.equivFun v)) = z (a := a) (B.equivFun (g v)) := by + simp only [z, map_prod, substitution_rowForm] + +lemma row_polynomial_natural (g : V →ₗ[ℂ] V) (i : Fin a) (q : Sym b V) : + Rows.row i (SymPolynomial.polynomial B b (symMap b g q)) = + substitution B a g (Rows.row i (SymPolynomial.polynomial B b q)) := by + have hh : (Rows.row i).toLinearMap.comp ((SymPolynomial.polynomial B b).comp (symMap b g)) = + (substitution B a g).toLinearMap.comp + ((Rows.row i).toLinearMap.comp (SymPolynomial.polynomial B b)) := by + apply symMap_ext + intro v + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, + SymPolynomial.polynomial_power, map_pow, substitution_row_linear] + exact DFunLike.congr_fun hh q + +lemma tensorMap_natural (g : V →ₗ[ℂ] V) (x : T a (Sym b V)) : + Rows.tensorMap B a b (PiTensorProduct.map (fun _ : Fin a => symMap b g) x) = + substitution B a g (Rows.tensorMap B a b x) := by + have hh : (Rows.tensorMap B a b).comp (PiTensorProduct.map (fun _ : Fin a => symMap b g)) = + (substitution B a g).toLinearMap.comp (Rows.tensorMap B a b) := by + apply PiTensorProduct.ext + apply MultilinearMap.ext + intro v + simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, PiTensorProduct.map_tprod, + Rows.tensorMap_tprod, AlgHom.toLinearMap_apply, map_prod, row_polynomial_natural] + exact DFunLike.congr_fun hh x + +lemma invariantMap_natural (g : V →ₗ[ℂ] V) (x : Sym a (Sym b V)) : + Rows.invariantMap B a b (symMap a (symMap b g) x) = + substitution B a g (Rows.invariantMap B a b x) := + tensorMap_natural B a b g x + +end + +lemma firstMap_natural (g : V →ₗ[ℂ] V) (q : Sym a V) : + firstMap B a (symMap a g q) = substitution B a g (firstMap B a q) := by + have hh : (firstMap B a).comp (symMap a g) = + (substitution B a g).toLinearMap.comp (firstMap B a) := by + apply symMap_ext + intro v + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, + firstMap_power, substitution_z] + exact DFunLike.congr_fun hh q + +lemma productPolynomial_natural (g : V →ₗ[ℂ] V) (x : Sym b (Sym a V)) : + productPolynomial B a b (symMap b (symMap a g) x) = + substitution B a g (productPolynomial B a b x) := by + have hh : (productPolynomial B a b).comp (symMap b (symMap a g)) = + (substitution B a g).toLinearMap.comp (productPolynomial B a b) := by + apply symMap_ext + intro q + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, symMap_power, + productPolynomial_power, firstMap_natural, map_pow] + exact DFunLike.congr_fun hh x + +theorem natural (g : V →ₗ[ℂ] V) (x : Sym b (Sym a V)) : + map B a b (symMap b (symMap a g) x) = symMap a (symMap b g) (map B a b x) := by + apply Rows.invariantMap_injective B a b + rw [map_polynomial, invariantMap_natural, map_polynomial, productPolynomial_natural] + +end Foulkes.Canonical + +namespace Foulkes.PlethDual +universe u +open Module SymmetricTensor +variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +lemma natural_congr (g : V →ₗ[ℂ] V) (d : Sym a (Sym b (Dual ℂ V))) (x : Sym a (Sym b V)) : + equiv a b V (symMap a (symMap b g.dualMap) d) x = + equiv a b V d (symMap a (symMap b g) x) := by + have hi : (dualEquiv b (V := V)).toLinearMap.comp (symMap b g.dualMap) = + (symMap b g).dualMap.comp (dualEquiv b (V := V)).toLinearMap := by + apply LinearMap.ext + intro q + apply LinearMap.ext + intro v + exact pairing_map b g q v + have hs := congrArg (fun (f : Sym b (Dual ℂ V) →ₗ[ℂ] Dual ℂ (Sym b V)) => + symMap a f d) hi + simp only [symMap_comp, LinearMap.comp_apply] at hs + simp only [equiv_apply, hs] + exact pairing_map a (symMap b g) _ x + +end Foulkes.PlethDual + +namespace Foulkes.Injection +universe u +open Module +variable (a b : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] + +def map : Sym a (Sym b V) →ₗ[ℂ] Sym b (Sym a V) := + (PlethDual.flipEquiv b a V).symm.toLinearMap.comp + ((Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b).dualMap.comp + (PlethDual.flipEquiv a b V).toLinearMap) + +lemma adjoint (x : Sym a (Sym b V)) (d : Sym b (Sym a (Dual ℂ V))) : + PlethDual.equiv b a V d (map a b V x) = + PlethDual.equiv a b V (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d) x := by + change PlethDual.flipEquiv b a V + ((PlethDual.flipEquiv b a V).symm + ((Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b).dualMap + (PlethDual.flipEquiv a b V x))) d = _ + rw [LinearEquiv.apply_symm_apply] + rfl + +lemma injective (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : + Function.Injective (map a b V) := + (PlethDual.flipEquiv b a V).symm.injective.comp + ((LinearMap.dualMap_injective_of_surjective + (Canonical.surjective (Module.finBasis ℂ (Dual ℂ V)) a b ha hb0 hb)).comp + (PlethDual.flipEquiv a b V).injective) + +theorem natural (g : V →ₗ[ℂ] V) (x : Sym a (Sym b V)) : + map a b V (symMap a (symMap b g) x) = symMap b (symMap a g) (map a b V x) := by + apply (PlethDual.flipEquiv b a V).injective + apply LinearMap.ext + intro d + change PlethDual.equiv b a V d (map a b V (symMap a (symMap b g) x)) = + PlethDual.equiv b a V d (symMap b (symMap a g) (map a b V x)) + calc + _ = PlethDual.equiv a b V (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d) + (symMap a (symMap b g) x) := adjoint a b V _ d + _ = PlethDual.equiv a b V + (symMap a (symMap b g.dualMap) (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b d)) x := + (PlethDual.natural a b V g _ x).symm + _ = PlethDual.equiv a b V + (Canonical.map (Module.finBasis ℂ (Dual ℂ V)) a b (symMap b (symMap a g.dualMap) d)) x := by + rw [Canonical.natural] + _ = PlethDual.equiv b a V (symMap b (symMap a g.dualMap) d) (map a b V x) := + (adjoint a b V x _).symm + _ = _ := PlethDual.natural b a V g d (map a b V x) + +theorem quadratic_comparison (ha : 2 ≤ a) (hb : a*(a-1) ≤ b) : + ∃ i : Sym a (Sym b V) →ₗ[ℂ] Sym b (Sym a V), Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym a (Sym b V)), + i (symMap a (symMap b g.toLinearMap) x) = symMap b (symMap a g.toLinearMap) (i x) := by + have hb0 : 1 ≤ b := le_trans (Nat.mul_pos (by omega) (by omega)) hb + exact ⟨map a b V, injective a b V (by omega) hb0 hb, fun g x => natural a b V g.toLinearMap x⟩ + +theorem sixth_large (b : ℕ) (hb : 30 ≤ b) + (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : + ∃ i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V), Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), + i (symMap 6 (symMap b g.toLinearMap) x) = symMap b (symMap 6 g.toLinearMap) (i x) := + quadratic_comparison 6 b V (by omega) (by omega) + +end Foulkes.Injection + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/RangeReduction.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/RangeReduction.lean index 6814a543d01f73f6ff157f524f94ba07b2165661..08450db41dd5dddb12668fb2fc408ff853806ee1 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/RangeReduction.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/RangeReduction.lean @@ -1,116 +1,116 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.IndependentChart -import OAI.RepresentationTheory.FoulkesSixth.BlockInjection - -namespace OAI - -noncomputable section - -namespace Foulkes -universe u - -open scoped TensorProduct - -def SixthPowerComparison : Prop := - ∀ (b : ℕ), 6 ≤ b → - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], - ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), - Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), - i (symMap 6 (symMap b g.toLinearMap) x) = - symMap b (symMap 6 g.toLinearMap) (i x) - -def normalizedAverage (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - (⨂[ℂ] (_ : Fin n), V) →ₗ[ℂ] (⨂[ℂ] (_ : Fin n), V) := - (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), - (PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ).toLinearMap - -namespace PolynomialModel - -abbrev P (a n : ℕ) := MvPolynomial (Fin a × Fin n) ℂ - -def rowWeight (a n : ℕ) : Fin a × Fin n → (Fin a → ℕ) := - fun ij => Pi.single ij.1 1 - -def W (a n j : ℕ) : Submodule ℂ (P a n) := - MvPolynomial.weightedHomogeneousSubmodule ℂ (rowWeight a n) (fun _ => j) - -def rowInvariants (a n : ℕ) : Subalgebra ℂ (P a n) where - carrier := {f | ∀ σ : Equiv.Perm (Fin a), - MvPolynomial.rename (fun ij : Fin a × Fin n => (σ ij.1, ij.2)) f = f} - zero_mem' := by intro σ; simp - add_mem' := by intro f g hf hg σ; simp only [map_add, hf σ, hg σ] - one_mem' := by intro σ; simp - mul_mem' := by intro f g hf hg σ; simp only [map_mul, hf σ, hg σ] - algebraMap_mem' := by intro c σ; simp - -def R (a n j : ℕ) : Submodule ℂ (P a n) := - W a n j ⊓ (rowInvariants a n).toSubmodule - -def A (a n : ℕ) : Subalgebra ℂ (P a n) := - Algebra.adjoin ℂ (R a n 1 : Set (P a n)) - -def AComponent (a n b : ℕ) : Submodule ℂ (P a n) := - W a n b ⊓ (A a n).toSubmodule - -def IndependentChartBound : Prop := - ∀ (a n b : ℕ), 2 ≤ a → a * (a - 1)^2 ≤ b → R a n b = AComponent a n b - -end PolynomialModel -theorem independent_chart : PolynomialModel.IndependentChartBound := by - intro a n b ha hb - exact Chart.independent_chart_bound a n b ha hb - -theorem sixth_equal (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : - ∃ i : Sym 6 (Sym 6 V) →ₗ[ℂ] Sym 6 (Sym 6 V), Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym 6 V)), - i (symMap 6 (symMap 6 g.toLinearMap) x) = symMap 6 (symMap 6 g.toLinearMap) (i x) := - ⟨LinearMap.id, fun _ _ h => h, fun _ _ => rfl⟩ - -def FiniteSixthPowerComparison : Prop := - ∀ (b : ℕ), 7 ≤ b → b ≤ 29 → - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], - ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), - Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), - i (symMap 6 (symMap b g.toLinearMap) x) = - symMap b (symMap 6 g.toLinearMap) (i x) - -theorem full_iff_finite : SixthPowerComparison.{u} ↔ FiniteSixthPowerComparison.{u} := by - constructor - · intro h b hb _ V _ _ _ - exact h b (by omega) V - · intro h b hb V _ _ _ - by_cases he : b = 6 - · subst b - exact sixth_equal V - · by_cases hbig : 30 ≤ b - · exact Injection.sixth_large b hbig V - · exact h b (by omega) (by omega) V - -def BaseSixthPowerComparison : Prop := - ∀ (b : ℕ), 7 ≤ b → b ≤ 24 → - ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], - ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), - Function.Injective i ∧ - ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), - i (symMap 6 (symMap b g.toLinearMap) x) = - symMap b (symMap 6 g.toLinearMap) (i x) - -theorem full_iff_base : SixthPowerComparison.{u} ↔ BaseSixthPowerComparison.{u} := by - constructor - · intro h b hb _ V _ _ _ - exact h b (by omega) V - · intro h b hb V _ _ _ - by_cases he : b = 6 - · subst b - exact sixth_equal V - · by_cases hbig : 25 ≤ b - · exact Injection.sixth_from_25 b hbig V - · exact h b (by omega) (by omega) V - -end Foulkes - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.IndependentChart +import OAI.RepresentationTheory.FoulkesSixth.BlockInjection + +namespace OAI + +noncomputable section + +namespace Foulkes +universe u + +open scoped TensorProduct + +def SixthPowerComparison : Prop := + ∀ (b : ℕ), 6 ≤ b → + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], + ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), + Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), + i (symMap 6 (symMap b g.toLinearMap) x) = + symMap b (symMap 6 g.toLinearMap) (i x) + +def normalizedAverage (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + (⨂[ℂ] (_ : Fin n), V) →ₗ[ℂ] (⨂[ℂ] (_ : Fin n), V) := + (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), + (PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ).toLinearMap + +namespace PolynomialModel + +abbrev P (a n : ℕ) := MvPolynomial (Fin a × Fin n) ℂ + +def rowWeight (a n : ℕ) : Fin a × Fin n → (Fin a → ℕ) := + fun ij => Pi.single ij.1 1 + +def W (a n j : ℕ) : Submodule ℂ (P a n) := + MvPolynomial.weightedHomogeneousSubmodule ℂ (rowWeight a n) (fun _ => j) + +def rowInvariants (a n : ℕ) : Subalgebra ℂ (P a n) where + carrier := {f | ∀ σ : Equiv.Perm (Fin a), + MvPolynomial.rename (fun ij : Fin a × Fin n => (σ ij.1, ij.2)) f = f} + zero_mem' := by intro σ; simp + add_mem' := by intro f g hf hg σ; simp only [map_add, hf σ, hg σ] + one_mem' := by intro σ; simp + mul_mem' := by intro f g hf hg σ; simp only [map_mul, hf σ, hg σ] + algebraMap_mem' := by intro c σ; simp + +def R (a n j : ℕ) : Submodule ℂ (P a n) := + W a n j ⊓ (rowInvariants a n).toSubmodule + +def A (a n : ℕ) : Subalgebra ℂ (P a n) := + Algebra.adjoin ℂ (R a n 1 : Set (P a n)) + +def AComponent (a n b : ℕ) : Submodule ℂ (P a n) := + W a n b ⊓ (A a n).toSubmodule + +def IndependentChartBound : Prop := + ∀ (a n b : ℕ), 2 ≤ a → a * (a - 1)^2 ≤ b → R a n b = AComponent a n b + +end PolynomialModel +theorem independent_chart : PolynomialModel.IndependentChartBound := by + intro a n b ha hb + exact Chart.independent_chart_bound a n b ha hb + +theorem sixth_equal (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V] : + ∃ i : Sym 6 (Sym 6 V) →ₗ[ℂ] Sym 6 (Sym 6 V), Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym 6 V)), + i (symMap 6 (symMap 6 g.toLinearMap) x) = symMap 6 (symMap 6 g.toLinearMap) (i x) := + ⟨LinearMap.id, fun _ _ h => h, fun _ _ => rfl⟩ + +def FiniteSixthPowerComparison : Prop := + ∀ (b : ℕ), 7 ≤ b → b ≤ 29 → + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], + ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), + Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), + i (symMap 6 (symMap b g.toLinearMap) x) = + symMap b (symMap 6 g.toLinearMap) (i x) + +theorem full_iff_finite : SixthPowerComparison.{u} ↔ FiniteSixthPowerComparison.{u} := by + constructor + · intro h b hb _ V _ _ _ + exact h b (by omega) V + · intro h b hb V _ _ _ + by_cases he : b = 6 + · subst b + exact sixth_equal V + · by_cases hbig : 30 ≤ b + · exact Injection.sixth_large b hbig V + · exact h b (by omega) (by omega) V + +def BaseSixthPowerComparison : Prop := + ∀ (b : ℕ), 7 ≤ b → b ≤ 24 → + ∀ (V : Type u) [AddCommGroup V] [Module ℂ V] [FiniteDimensional ℂ V], + ∃ (i : Sym 6 (Sym b V) →ₗ[ℂ] Sym b (Sym 6 V)), + Function.Injective i ∧ + ∀ (g : V ≃ₗ[ℂ] V) (x : Sym 6 (Sym b V)), + i (symMap 6 (symMap b g.toLinearMap) x) = + symMap b (symMap 6 g.toLinearMap) (i x) + +theorem full_iff_base : SixthPowerComparison.{u} ↔ BaseSixthPowerComparison.{u} := by + constructor + · intro h b hb _ V _ _ _ + exact h b (by omega) V + · intro h b hb V _ _ _ + by_cases he : b = 6 + · subst b + exact sixth_equal V + · by_cases hbig : 25 ≤ b + · exact Injection.sixth_from_25 b hbig V + · exact h b (by omega) (by omega) V + +end Foulkes + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Recurrence.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Recurrence.lean index 8e98dd5f6ca56ff6142d419e0d8437d42b14fce6..6b4e484b2b36b0ff004d3299dc8962483556d406 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Recurrence.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Recurrence.lean @@ -1,101 +1,101 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.NewtonUniqueness -import OAI.RepresentationTheory.FoulkesSixth.FastLookupExact -import OAI.RepresentationTheory.FoulkesSixth.CompositionEnumeration - -namespace OAI - -noncomputable section - -namespace Foulkes.Checker -open Finset Foulkes.Enumeration Foulkes.FastLookup Foulkes.Lookup Foulkes.Strips - -def checkedSum {α : Type*} (f : α → Option ℤ) : List α → Option ℤ - | [] => some 0 - | a::l => do - let x ← f a - let y ← checkedSum f l - some (x+y) - -lemma checkedSum_sound {α : Type*} (f : α → Option ℤ) (g : α → ℤ) - (l : List α) (h : ∀ a ∈ l, ∀ z, f a = some z → z = g a) - (z : ℤ) (hz : checkedSum f l = some z) : z = (l.map g).sum := by - induction l generalizing z with - | nil => simpa [checkedSum] using hz.symm - | cons a l ih => - cases hx : f a with - | none => simp [checkedSum, hx] at hz - | some x => - cases hy : checkedSum f l with - | none => simp [checkedSum, hx, hy] at hz - | some y => - have hh := ih (fun b hb => h b (List.mem_cons_of_mem a hb)) y hy - have ha := h a (List.mem_cons_self ..) x hx - simpa [checkedSum, hx, hy, hh, ha] using hz.symm - -lemma sum_compositions (n d : ℕ) (f : (Fin n → ℕ) → ℤ) : - ((compositions n d).map f).sum = ∑ a : Foulkes.Complete.Degree (Fin n) d, - f (fun j => a.val j) := by - classical - rw [← List.sum_toFinset f (nodup_compositions n d)] - change (∑ v ∈ compositionSet n d, f v) = _ - rw [← Finset.sum_attach (compositionSet n d) f] - exact (Equiv.sum_comp (degreeComposition n d) (fun v => f v.val)).symm - -def numerator {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) (b : ℕ) (mu : Fin n → ℕ) : Option ℤ := - checkedSum (fun i => checkedSum (fun v => checkedLookup (T (b-i)) - (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j)) (compositions n 6)) (List.range' 1 b) - -lemma numerator_sound {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) - (b : ℕ) (mu : Fin n → ℕ) (z : ℤ) (hz : numerator T b mu = some z) : - z = ∑ i ∈ Finset.Icc 1 b, ∑ d : Foulkes.Complete.Degree (Fin n) 6, - signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by - have hinner (i : ℕ) (w : ℤ) - (hw : checkedSum (fun v => checkedLookup (T (b-i)) - (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j)) (compositions n 6) = some w) : - w = ∑ d : Foulkes.Complete.Degree (Fin n) 6, - signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by - calc - w = ((compositions n 6).map (fun v => signedLookup (T (b-i)) - (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j))).sum := - checkedSum_sound _ _ _ (fun v hv w hw => checkedLookup_exact _ _ w hw) w hw - _ = _ := sum_compositions n 6 _ - have hh := checkedSum_sound _ _ (List.range' 1 b) (fun i hi => hinner i) z hz - rw [← List.sum_toFinset _ (List.nodup_range' (s := 1) (n := b))] at hh - have hr : (List.range' 1 b).toFinset = Finset.Icc 1 b := by - ext i - simp only [List.mem_toFinset, List.mem_range'_1, Finset.mem_Icc] - omega - rw [hr] at hh - exact hh - -def checkEntry {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) (b : ℕ) (mu : Fin n → ℕ) : Bool := - match numerator T b mu with - | none => false - | some z => decide ((b : ℤ)*T b mu = z) - -lemma checkEntry_sound {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) - (b : ℕ) (mu : Fin n → ℕ) (h : checkEntry T b mu = true) : - (b : ℤ)*T b mu = ∑ i ∈ Finset.Icc 1 b, ∑ d : Foulkes.Complete.Degree (Fin n) 6, - signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by - unfold checkEntry at h - cases hn : numerator T b mu with - | none => simp [hn] at h - | some z => - rw [hn, decide_eq_true_eq] at h - exact h.trans (numerator_sound T b mu z hn) - -theorem checked_table_unique (n B : ℕ) (T : ℕ → (Fin n → ℕ) → ℤ) - (hzero : ∀ mu, Antitone mu → (∑ j, mu j = 0) → T 0 mu = 1) - (hcheck : ∀ b, 1 ≤ b → b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → - checkEntry T b mu = true) : - ∀ b, b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → T b mu = Q n b mu := by - apply target_table_unique n B T hzero - intro b hb hB mu hm hs - exact checkEntry_sound T b mu (hcheck b hb hB mu hm hs) - -end Foulkes.Checker - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.NewtonUniqueness +import OAI.RepresentationTheory.FoulkesSixth.FastLookupExact +import OAI.RepresentationTheory.FoulkesSixth.CompositionEnumeration + +namespace OAI + +noncomputable section + +namespace Foulkes.Checker +open Finset Foulkes.Enumeration Foulkes.FastLookup Foulkes.Lookup Foulkes.Strips + +def checkedSum {α : Type*} (f : α → Option ℤ) : List α → Option ℤ + | [] => some 0 + | a::l => do + let x ← f a + let y ← checkedSum f l + some (x+y) + +lemma checkedSum_sound {α : Type*} (f : α → Option ℤ) (g : α → ℤ) + (l : List α) (h : ∀ a ∈ l, ∀ z, f a = some z → z = g a) + (z : ℤ) (hz : checkedSum f l = some z) : z = (l.map g).sum := by + induction l generalizing z with + | nil => simpa [checkedSum] using hz.symm + | cons a l ih => + cases hx : f a with + | none => simp [checkedSum, hx] at hz + | some x => + cases hy : checkedSum f l with + | none => simp [checkedSum, hx, hy] at hz + | some y => + have hh := ih (fun b hb => h b (List.mem_cons_of_mem a hb)) y hy + have ha := h a (List.mem_cons_self ..) x hx + simpa [checkedSum, hx, hy, hh, ha] using hz.symm + +lemma sum_compositions (n d : ℕ) (f : (Fin n → ℕ) → ℤ) : + ((compositions n d).map f).sum = ∑ a : Foulkes.Complete.Degree (Fin n) d, + f (fun j => a.val j) := by + classical + rw [← List.sum_toFinset f (nodup_compositions n d)] + change (∑ v ∈ compositionSet n d, f v) = _ + rw [← Finset.sum_attach (compositionSet n d) f] + exact (Equiv.sum_comp (degreeComposition n d) (fun v => f v.val)).symm + +def numerator {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) (b : ℕ) (mu : Fin n → ℕ) : Option ℤ := + checkedSum (fun i => checkedSum (fun v => checkedLookup (T (b-i)) + (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j)) (compositions n 6)) (List.range' 1 b) + +lemma numerator_sound {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) + (b : ℕ) (mu : Fin n → ℕ) (z : ℤ) (hz : numerator T b mu = some z) : + z = ∑ i ∈ Finset.Icc 1 b, ∑ d : Foulkes.Complete.Degree (Fin n) 6, + signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by + have hinner (i : ℕ) (w : ℤ) + (hw : checkedSum (fun v => checkedLookup (T (b-i)) + (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j)) (compositions n 6) = some w) : + w = ∑ d : Foulkes.Complete.Degree (Fin n) 6, + signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by + calc + w = ((compositions n 6).map (fun v => signedLookup (T (b-i)) + (fun j => (shifted mu j : ℤ) - (i : ℤ)*v j))).sum := + checkedSum_sound _ _ _ (fun v hv w hw => checkedLookup_exact _ _ w hw) w hw + _ = _ := sum_compositions n 6 _ + have hh := checkedSum_sound _ _ (List.range' 1 b) (fun i hi => hinner i) z hz + rw [← List.sum_toFinset _ (List.nodup_range' (s := 1) (n := b))] at hh + have hr : (List.range' 1 b).toFinset = Finset.Icc 1 b := by + ext i + simp only [List.mem_toFinset, List.mem_range'_1, Finset.mem_Icc] + omega + rw [hr] at hh + exact hh + +def checkEntry {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) (b : ℕ) (mu : Fin n → ℕ) : Bool := + match numerator T b mu with + | none => false + | some z => decide ((b : ℤ)*T b mu = z) + +lemma checkEntry_sound {n : ℕ} (T : ℕ → (Fin n → ℕ) → ℤ) + (b : ℕ) (mu : Fin n → ℕ) (h : checkEntry T b mu = true) : + (b : ℤ)*T b mu = ∑ i ∈ Finset.Icc 1 b, ∑ d : Foulkes.Complete.Degree (Fin n) 6, + signedLookup (T (b-i)) (fun j => (shifted mu j : ℤ) - (i : ℤ)*d.val j) := by + unfold checkEntry at h + cases hn : numerator T b mu with + | none => simp [hn] at h + | some z => + rw [hn, decide_eq_true_eq] at h + exact h.trans (numerator_sound T b mu z hn) + +theorem checked_table_unique (n B : ℕ) (T : ℕ → (Fin n → ℕ) → ℤ) + (hzero : ∀ mu, Antitone mu → (∑ j, mu j = 0) → T 0 mu = 1) + (hcheck : ∀ b, 1 ≤ b → b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → + checkEntry T b mu = true) : + ∀ b, b ≤ B → ∀ mu, Antitone mu → (∑ j, mu j = 6*b) → T b mu = Q n b mu := by + apply target_table_unique n B T hzero + intro b hb hB mu hm hs + exact checkEntry_sound T b mu (hcheck b hb hB mu hm hs) + +end Foulkes.Checker + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Rows.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Rows.lean index bfc79d2350b770cfc42d0df70f44de311cedbe15..1975bcc149038a3d56f4ce33e0e6b7c581bf6914 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Rows.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Rows.lean @@ -1,165 +1,165 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization -import OAI.RepresentationTheory.FoulkesSixth.SymPolynomial - -namespace OAI - -noncomputable section - -namespace Foulkes.Rows -universe u -open Module MvPolynomial SymmetricTensor Polarization -variable {V : Type u} [AddCommGroup V] [Module ℂ V] -variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) - -def row {a n : ℕ} (i : Fin a) : SymPolynomial.Poly n →ₐ[ℂ] P a n := - rename (fun k => (i,k)) - -@[simp] lemma row_linear (i : Fin a) (v : V) : - row i (SymPolynomial.linearPolynomial B v) = rowForm i (B.equivFun v) := by - simp [row, SymPolynomial.linearPolynomial, rowForm] - -@[simp] lemma renameRow_row (σ : Equiv.Perm (Fin a)) (i : Fin a) (p : SymPolynomial.Poly n) : - renameRow σ (row i p) = row (σ i) p := by - simp [row, renameRow, rename_rename, Function.comp_def] - -def tensorMap : T a (Sym b V) →ₗ[ℂ] P a n := - PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin a) (P a n)).compLinearMap - (fun i => (row i).toLinearMap.comp (SymPolynomial.polynomial B b))) - -@[simp] lemma tensorMap_tprod (v : Fin a → Sym b V) : - tensorMap B a b (PiTensorProduct.tprod ℂ v) = - ∏ i, row i (SymPolynomial.polynomial B b (v i)) := by - simp [tensorMap] - -@[simp] lemma tensorMap_powers (v : Fin a → V) : - tensorMap B a b (PiTensorProduct.tprod ℂ (fun i => power b V (v i))) = - pureRows b (fun i => B.equivFun (v i)) := by - simp only [tensorMap_tprod, SymPolynomial.polynomial_power, map_pow, row_linear, pureRows] - -def evaluation (w : Fin n → ℂ) : Dual ℂ (Sym b V) := - (aeval w).toLinearMap.comp (SymPolynomial.polynomial B b) - -@[simp] lemma evaluation_apply (w : Fin n → ℂ) (v : Sym b V) : - evaluation B b w v = eval w (SymPolynomial.polynomial B b v) := rfl - -variable [FiniteDimensional ℂ V] - -lemma evaluation_span : Submodule.span ℂ (Set.range (evaluation B b)) = ⊤ := by - apply Submodule.span_eq_top_of_ne_zero - intro v hv - by_contra! h - have hp : SymPolynomial.polynomial B b v = 0 := by - apply MvPolynomial.funext - intro w - simpa using h (evaluation B b w) ⟨w, rfl⟩ - exact hv ((SymPolynomial.polynomial_injective B b) (hp.trans (map_zero _).symm)) - -omit [FiniteDimensional ℂ V] in -lemma eval_tensorMap (w : Fin a × Fin n → ℂ) (x : T a (Sym b V)) : - eval w (tensorMap B a b x) = - PiTensorProduct.dualDistrib - (PiTensorProduct.tprod ℂ (fun i : Fin a => evaluation B b (fun k => w (i,k)))) x := by - have h : (aeval w).toLinearMap.comp (tensorMap B a b) = - PiTensorProduct.dualDistrib - (PiTensorProduct.tprod ℂ (fun i : Fin a => evaluation B b (fun k => w (i,k)))) := by - ext v - simp [row, MvPolynomial.eval_rename, Function.comp_def] - exact DFunLike.congr_fun h x - -lemma tensorMap_injective : Function.Injective (tensorMap B a b) := by - refine (LinearMap.ker_eq_bot (R := ℂ) (R₂ := ℂ) (M := T a (Sym b V)) (M₂ := P a n) - (f := tensorMap B a b)).mp ?_ - refine (LinearMap.ker_eq_bot' (R := ℂ) (R₂ := ℂ) (M := T a (Sym b V)) (M₂ := P a n) - (f := tensorMap B a b)).mpr ?_ - intro x hx - have hzero : (LinearMap.applyₗ x).comp - (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin a => Sym b V)) = 0 := by - apply PiTensorProduct.ext_of_span_eq_top - (g := fun {_ : Fin a} w => evaluation B b w) (fun _ => evaluation_span B b) - intro w - change PiTensorProduct.dualDistrib (PiTensorProduct.tprod ℂ - (fun i => evaluation B b (w i))) x = 0 - rw [← eval_tensorMap B a b (fun ik => w ik.1 ik.2), hx, map_zero] - let : Module.Free ℂ (T a (Sym b V)) := Module.Free.of_basis - (Basis.piTensorProduct (fun _ : Fin a => Module.Free.chooseBasis ℂ (Sym b V))) - refine (Module.forall_dual_apply_eq_zero_iff ℂ x).mp ?_ - intro l - obtain ⟨d, hd⟩ := (PiTensorProduct.dualDistribEquiv (R := ℂ) - (M := fun _ : Fin a => Sym b V)).surjective l - have hh := DFunLike.congr_fun hzero d - change (PiTensorProduct.dualDistribEquiv d) x = 0 at hh - rwa [hd] at hh - -omit [FiniteDimensional ℂ V] in -lemma tensorMap_range : (tensorMap B a b).range = W a n b := by - have hspan : Submodule.span ℂ (Set.range (fun v : Fin a → V => - PiTensorProduct.tprod ℂ (fun i => power b V (v i)))) = ⊤ := - PiTensorProduct.submodule_span_eq_top (g := fun {_ : Fin a} v => power b V v) - (fun _ => span_power b V) - rw [← Submodule.map_top, ← hspan, LinearMap.map_span, W_eq_span_pureRows] - congr 1 - ext p - constructor - · rintro ⟨_, ⟨v, rfl⟩, rfl⟩ - exact ⟨fun i => B.equivFun (v i), (tensorMap_powers B a b v).symm⟩ - · rintro ⟨v, rfl⟩ - refine ⟨PiTensorProduct.tprod ℂ (fun i => power b V (B.equivFun.symm (v i))), - ⟨fun i => B.equivFun.symm (v i), rfl⟩, ?_⟩ - simp only [tensorMap_powers, LinearEquiv.apply_symm_apply] - -omit [FiniteDimensional ℂ V] in -lemma tensorMap_perm (σ : Equiv.Perm (Fin a)) (x : T a (Sym b V)) : - tensorMap B a b (perm a (Sym b V) σ x) = renameRow σ (tensorMap B a b x) := by - have h : (tensorMap B a b).comp (perm a (Sym b V) σ).toLinearMap = - (renameRow σ).toLinearMap.comp (tensorMap B a b) := by - apply PiTensorProduct.ext - apply MultilinearMap.ext - intro v - simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, - perm, PiTensorProduct.reindex_tprod, tensorMap_tprod, AlgHom.toLinearMap_apply, - map_prod, renameRow_row] - apply Fintype.prod_equiv σ.symm - intro i - simp - exact DFunLike.congr_fun h x - -def invariantMap : Sym a (Sym b V) →ₗ[ℂ] P a n := - (tensorMap B a b).comp (symmetricTensors a (Sym b V)).subtype - -lemma invariantMap_injective : Function.Injective (invariantMap B a b) := - (tensorMap_injective B a b).comp Subtype.val_injective - -lemma invariantMap_range : (invariantMap B a b).range = R a n b := by - apply le_antisymm - · rintro p ⟨x, rfl⟩ - constructor - · rw [← tensorMap_range B a b] - exact ⟨x, rfl⟩ - · intro σ - change renameRow σ (tensorMap B a b x) = tensorMap B a b x - rw [← tensorMap_perm] - exact congrArg (tensorMap B a b) (x.property σ) - · intro p hp - have hW : p ∈ (tensorMap B a b).range := by rw [tensorMap_range]; exact hp.1 - obtain ⟨x, hx⟩ := hW - have hs : x ∈ Sym a (Sym b V) := by - intro σ - apply tensorMap_injective B a b - change tensorMap B a b (perm a (Sym b V) σ x) = tensorMap B a b x - rw [tensorMap_perm, hx] - exact hp.2 σ - exact ⟨⟨x, hs⟩, hx⟩ - -def equiv : Sym a (Sym b V) ≃ₗ[ℂ] R a n b := - (LinearEquiv.ofInjective (invariantMap B a b) (invariantMap_injective B a b)).trans - (LinearEquiv.ofEq _ _ (invariantMap_range B a b)) - -@[simp] lemma equiv_coe (x : Sym a (Sym b V)) : - (equiv B a b x : P a n) = invariantMap B a b x := rfl - -end Foulkes.Rows - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization +import OAI.RepresentationTheory.FoulkesSixth.SymPolynomial + +namespace OAI + +noncomputable section + +namespace Foulkes.Rows +universe u +open Module MvPolynomial SymmetricTensor Polarization +variable {V : Type u} [AddCommGroup V] [Module ℂ V] +variable {n : ℕ} (B : Basis (Fin n) ℂ V) (a b : ℕ) + +def row {a n : ℕ} (i : Fin a) : SymPolynomial.Poly n →ₐ[ℂ] P a n := + rename (fun k => (i,k)) + +@[simp] lemma row_linear (i : Fin a) (v : V) : + row i (SymPolynomial.linearPolynomial B v) = rowForm i (B.equivFun v) := by + simp [row, SymPolynomial.linearPolynomial, rowForm] + +@[simp] lemma renameRow_row (σ : Equiv.Perm (Fin a)) (i : Fin a) (p : SymPolynomial.Poly n) : + renameRow σ (row i p) = row (σ i) p := by + simp [row, renameRow, rename_rename, Function.comp_def] + +def tensorMap : T a (Sym b V) →ₗ[ℂ] P a n := + PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin a) (P a n)).compLinearMap + (fun i => (row i).toLinearMap.comp (SymPolynomial.polynomial B b))) + +@[simp] lemma tensorMap_tprod (v : Fin a → Sym b V) : + tensorMap B a b (PiTensorProduct.tprod ℂ v) = + ∏ i, row i (SymPolynomial.polynomial B b (v i)) := by + simp [tensorMap] + +@[simp] lemma tensorMap_powers (v : Fin a → V) : + tensorMap B a b (PiTensorProduct.tprod ℂ (fun i => power b V (v i))) = + pureRows b (fun i => B.equivFun (v i)) := by + simp only [tensorMap_tprod, SymPolynomial.polynomial_power, map_pow, row_linear, pureRows] + +def evaluation (w : Fin n → ℂ) : Dual ℂ (Sym b V) := + (aeval w).toLinearMap.comp (SymPolynomial.polynomial B b) + +@[simp] lemma evaluation_apply (w : Fin n → ℂ) (v : Sym b V) : + evaluation B b w v = eval w (SymPolynomial.polynomial B b v) := rfl + +variable [FiniteDimensional ℂ V] + +lemma evaluation_span : Submodule.span ℂ (Set.range (evaluation B b)) = ⊤ := by + apply Submodule.span_eq_top_of_ne_zero + intro v hv + by_contra! h + have hp : SymPolynomial.polynomial B b v = 0 := by + apply MvPolynomial.funext + intro w + simpa using h (evaluation B b w) ⟨w, rfl⟩ + exact hv ((SymPolynomial.polynomial_injective B b) (hp.trans (map_zero _).symm)) + +omit [FiniteDimensional ℂ V] in +lemma eval_tensorMap (w : Fin a × Fin n → ℂ) (x : T a (Sym b V)) : + eval w (tensorMap B a b x) = + PiTensorProduct.dualDistrib + (PiTensorProduct.tprod ℂ (fun i : Fin a => evaluation B b (fun k => w (i,k)))) x := by + have h : (aeval w).toLinearMap.comp (tensorMap B a b) = + PiTensorProduct.dualDistrib + (PiTensorProduct.tprod ℂ (fun i : Fin a => evaluation B b (fun k => w (i,k)))) := by + ext v + simp [row, MvPolynomial.eval_rename, Function.comp_def] + exact DFunLike.congr_fun h x + +lemma tensorMap_injective : Function.Injective (tensorMap B a b) := by + refine (LinearMap.ker_eq_bot (R := ℂ) (R₂ := ℂ) (M := T a (Sym b V)) (M₂ := P a n) + (f := tensorMap B a b)).mp ?_ + refine (LinearMap.ker_eq_bot' (R := ℂ) (R₂ := ℂ) (M := T a (Sym b V)) (M₂ := P a n) + (f := tensorMap B a b)).mpr ?_ + intro x hx + have hzero : (LinearMap.applyₗ x).comp + (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin a => Sym b V)) = 0 := by + apply PiTensorProduct.ext_of_span_eq_top + (g := fun {_ : Fin a} w => evaluation B b w) (fun _ => evaluation_span B b) + intro w + change PiTensorProduct.dualDistrib (PiTensorProduct.tprod ℂ + (fun i => evaluation B b (w i))) x = 0 + rw [← eval_tensorMap B a b (fun ik => w ik.1 ik.2), hx, map_zero] + let : Module.Free ℂ (T a (Sym b V)) := Module.Free.of_basis + (Basis.piTensorProduct (fun _ : Fin a => Module.Free.chooseBasis ℂ (Sym b V))) + refine (Module.forall_dual_apply_eq_zero_iff ℂ x).mp ?_ + intro l + obtain ⟨d, hd⟩ := (PiTensorProduct.dualDistribEquiv (R := ℂ) + (M := fun _ : Fin a => Sym b V)).surjective l + have hh := DFunLike.congr_fun hzero d + change (PiTensorProduct.dualDistribEquiv d) x = 0 at hh + rwa [hd] at hh + +omit [FiniteDimensional ℂ V] in +lemma tensorMap_range : (tensorMap B a b).range = W a n b := by + have hspan : Submodule.span ℂ (Set.range (fun v : Fin a → V => + PiTensorProduct.tprod ℂ (fun i => power b V (v i)))) = ⊤ := + PiTensorProduct.submodule_span_eq_top (g := fun {_ : Fin a} v => power b V v) + (fun _ => span_power b V) + rw [← Submodule.map_top, ← hspan, LinearMap.map_span, W_eq_span_pureRows] + congr 1 + ext p + constructor + · rintro ⟨_, ⟨v, rfl⟩, rfl⟩ + exact ⟨fun i => B.equivFun (v i), (tensorMap_powers B a b v).symm⟩ + · rintro ⟨v, rfl⟩ + refine ⟨PiTensorProduct.tprod ℂ (fun i => power b V (B.equivFun.symm (v i))), + ⟨fun i => B.equivFun.symm (v i), rfl⟩, ?_⟩ + simp only [tensorMap_powers, LinearEquiv.apply_symm_apply] + +omit [FiniteDimensional ℂ V] in +lemma tensorMap_perm (σ : Equiv.Perm (Fin a)) (x : T a (Sym b V)) : + tensorMap B a b (perm a (Sym b V) σ x) = renameRow σ (tensorMap B a b x) := by + have h : (tensorMap B a b).comp (perm a (Sym b V) σ).toLinearMap = + (renameRow σ).toLinearMap.comp (tensorMap B a b) := by + apply PiTensorProduct.ext + apply MultilinearMap.ext + intro v + simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, + perm, PiTensorProduct.reindex_tprod, tensorMap_tprod, AlgHom.toLinearMap_apply, + map_prod, renameRow_row] + apply Fintype.prod_equiv σ.symm + intro i + simp + exact DFunLike.congr_fun h x + +def invariantMap : Sym a (Sym b V) →ₗ[ℂ] P a n := + (tensorMap B a b).comp (symmetricTensors a (Sym b V)).subtype + +lemma invariantMap_injective : Function.Injective (invariantMap B a b) := + (tensorMap_injective B a b).comp Subtype.val_injective + +lemma invariantMap_range : (invariantMap B a b).range = R a n b := by + apply le_antisymm + · rintro p ⟨x, rfl⟩ + constructor + · rw [← tensorMap_range B a b] + exact ⟨x, rfl⟩ + · intro σ + change renameRow σ (tensorMap B a b x) = tensorMap B a b x + rw [← tensorMap_perm] + exact congrArg (tensorMap B a b) (x.property σ) + · intro p hp + have hW : p ∈ (tensorMap B a b).range := by rw [tensorMap_range]; exact hp.1 + obtain ⟨x, hx⟩ := hW + have hs : x ∈ Sym a (Sym b V) := by + intro σ + apply tensorMap_injective B a b + change tensorMap B a b (perm a (Sym b V) σ x) = tensorMap B a b x + rw [tensorMap_perm, hx] + exact hp.2 σ + exact ⟨⟨x, hs⟩, hx⟩ + +def equiv : Sym a (Sym b V) ≃ₗ[ℂ] R a n b := + (LinearEquiv.ofInjective (invariantMap B a b) (invariantMap_injective B a b)).trans + (LinearEquiv.ofEq _ _ (invariantMap_range B a b)) + +@[simp] lemma equiv_coe (x : Sym a (Sym b V)) : + (equiv B a b x : P a n) = invariantMap B a b x := rfl + +end Foulkes.Rows + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SemisimpleBridge.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SemisimpleBridge.lean index 777ebe156fcb3b64f7b179c995c395c76b0df029..1fced9968f494669e43f1168f9389d0fe4836243 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SemisimpleBridge.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SemisimpleBridge.lean @@ -1,232 +1,232 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.SemisimpleBridge -open Module -open scoped Classical - -section Algebra -variable {K R A B C : Type*} [Field K] [Ring R] [Algebra K R] - [AddCommGroup A] [Module K A] [Module R A] [IsScalarTower K R A] - [AddCommGroup B] [Module K B] [Module R B] [IsScalarTower K R B] - [AddCommGroup C] [Module K C] [Module R C] [IsScalarTower K R C] - -def homCongrRight (e : B ≃ₗ[R] C) : (A →ₗ[R] B) ≃ₗ[K] (A →ₗ[R] C) where - toFun f := e.toLinearMap.comp f - invFun f := e.symm.toLinearMap.comp f - left_inv f := by ext x; simp - right_inv f := by ext x; simp - map_add' f g := by ext x; simp - map_smul' k f := by - ext x - exact e.toLinearMap.map_smul_of_tower k (f x) - -lemma finite_hom [FiniteDimensional K A] [FiniteDimensional K B] : - FiniteDimensional K (A →ₗ[R] B) := - Module.Finite.of_injective (LinearMap.restrictScalarsₗ K R A B K) - (LinearMap.restrictScalars_injective K) - -lemma simple_hom_finrank [IsAlgClosed K] [FiniteDimensional K A] - [FiniteDimensional K B] [IsSimpleModule R A] [IsSimpleModule R B] : - finrank K (A →ₗ[R] B) = if Nonempty (A ≃ₗ[R] B) then 1 else 0 := by - classical - by_cases h : Nonempty (A ≃ₗ[R] B) - · rw [ite_eq_left h] - have he := homCongrRight (K := K) (A := A) h.some.symm - rw [he.finrank_eq] - have hb := IsSimpleModule.algebraMap_end_bijective_of_isAlgClosed (A := R) (V := A) K - have hh := (LinearEquiv.ofBijective (Algebra.linearMap K (Module.End R A)) hb).finrank_eq - simpa using hh.symm - · rw [ite_eq_right h] - have hz (f : A →ₗ[R] B) : f = 0 := by - rcases LinearMap.bijective_or_eq_zero f with hbij | hzero - · exact (h ⟨LinearEquiv.ofBijective f hbij⟩).elim - · exact hzero - let : Subsingleton (A →ₗ[R] B) := ⟨fun f g => (hz f).trans (hz g).symm⟩ - exact finrank_zero_of_subsingleton - -end Algebra -end Foulkes.SemisimpleBridge - -namespace Foulkes.SemisimpleBridge -open scoped Classical -open Module Finset - -def fibreEmbedding {ι κ C : Type*} [Fintype ι] [Fintype κ] - (f : ι → C) (g : κ → C) - (hc : ∀ c, Fintype.card {i // f i = c} ≤ Fintype.card {j // g j = c}) : ι ↪ κ := by - let e (c : C) : {i // f i = c} ↪ {j // g j = c} := - (Fintype.equivFin _).toEmbedding.trans - ((Fin.castLEEmb (hc c)).trans (Fintype.equivFin _).symm.toEmbedding) - exact (Equiv.sigmaFiberEquiv f).symm.toEmbedding.trans - ((Function.Embedding.sigmaMap (Function.Embedding.refl C) e).trans - (Equiv.sigmaFiberEquiv g).toEmbedding) - -lemma fibreEmbedding_label {ι κ C : Type*} [Fintype ι] [Fintype κ] - (f : ι → C) (g : κ → C) - (hc : ∀ c, Fintype.card {i // f i = c} ≤ Fintype.card {j // g j = c}) (i : ι) : - g (fibreEmbedding f g hc i) = f i := by - exact (show {j // g j = f i} from - ((Fintype.equivFin {i' // f i' = f i}).toEmbedding.trans - ((Fin.castLEEmb (hc (f i))).trans - (Fintype.equivFin {j // g j = f i}).symm.toEmbedding)) ⟨i,rfl⟩).property - -section PiHom -variable {K R A : Type*} [Field K] [Ring R] [Algebra K R] - [IsAlgClosed K] [AddCommGroup A] [Module K A] [Module R A] - [IsScalarTower K R A] [FiniteDimensional K A] [IsSimpleModule R A] - {ι : Type*} [Fintype ι] (P : ι → Type*) [∀ i, AddCommGroup (P i)] - [∀ i, Module K (P i)] [∀ i, Module R (P i)] [∀ i, IsScalarTower K R (P i)] - [∀ i, FiniteDimensional K (P i)] [∀ i, IsSimpleModule R (P i)] - -lemma hom_pi_finrank : - finrank K (A →ₗ[R] Π i, P i) = Fintype.card {i // Nonempty (A ≃ₗ[R] P i)} := by - let (i : ι) : FiniteDimensional K (A →ₗ[R] P i) := finite_hom - rw [← (LinearEquiv.linearMapPi (R := R) (M₂ := A) (φ := P) K).finrank_eq] - rw [Module.finrank_pi_fintype] - simp only [simple_hom_finrank] - simp [Fintype.card_subtype] - -end PiHom - -section PiEmbedding -variable {R : Type*} [Ring R] {ι κ : Type*} [Fintype ι] [Fintype κ] - (A : ι → Type*) (B : κ → Type*) [∀ i, AddCommGroup (A i)] - [∀ j, AddCommGroup (B j)] [∀ i, Module R (A i)] [∀ j, Module R (B j)] - -def piMapOfMatching (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) : - (Π i, A i) →ₗ[R] (Π j, B j) := - ∑ i, (LinearMap.single _ _ (f i)).comp - ((e i).toLinearMap.comp (LinearMap.proj i)) - -omit [Fintype κ] in -lemma piMapOfMatching_apply (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) - (x : Π i, A i) (i : ι) : piMapOfMatching A B f e x (f i) = e i (x i) := by - classical - simp only [piMapOfMatching, LinearMap.sum_apply, Finset.sum_apply, LinearMap.comp_apply, - LinearEquiv.coe_coe, LinearMap.proj_apply] - rw [Finset.sum_eq_single i] - · simp - · intro j hj hji - have hf : f j ≠ f i := fun hh => hji (f.injective hh) - simp [LinearMap.single_apply, Pi.single_eq_of_ne (Ne.symm hf)] - · simp - -omit [Fintype κ] in -lemma piMapOfMatching_injective (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) : - Function.Injective (piMapOfMatching A B f e) := by - intro x y h - funext i - apply (e i).injective - simpa only [piMapOfMatching_apply] using congrFun h (f i) - -end PiEmbedding -end Foulkes.SemisimpleBridge - -namespace Foulkes.SemisimpleBridge -universe v -open scoped Classical - -private def classSet {X : Type*} (s : Setoid X) (x : X) : Set X := {y | s.r x y} - -private lemma classSet_eq_iff {X : Type*} (s : Setoid X) (x y : X) : - classSet s x = classSet s y ↔ s.r x y := by - constructor - · intro h - have hy : y ∈ classSet s y := s.refl y - rw [← h] at hy - exact hy - · intro h - ext z - exact ⟨fun hz => s.trans (s.symm h) hz, fun hz => s.trans h hz⟩ - -theorem matching_of_equivalence_counts {ι κ X : Type*} [Fintype ι] [Fintype κ] - (s : Setoid X) (a : ι → X) (b : κ → X) - (hc : ∀ i, Fintype.card {i' // s.r (a i) (a i')} ≤ - Fintype.card {j // s.r (a i) (b j)}) : - ∃ f : ι ↪ κ, ∀ i, s.r (a i) (b (f i)) := by - classical - let fa := classSet s ∘ a - let fb := classSet s ∘ b - have hcard : ∀ c, Fintype.card {i // fa i = c} ≤ Fintype.card {j // fb j = c} := by - intro c - by_cases hc' : ∃ i, fa i = c - · obtain ⟨i,rfl⟩ := hc' - have equivA : {i' // fa i' = fa i} ≃ {i' // s.r (a i) (a i')} := - Equiv.subtypeEquivRight fun i' => - (classSet_eq_iff s (a i') (a i)).trans ⟨fun h => s.symm h, fun h => s.symm h⟩ - have equivB : {j // fb j = fa i} ≃ {j // s.r (a i) (b j)} := - Equiv.subtypeEquivRight fun j => - (classSet_eq_iff s (b j) (a i)).trans ⟨fun h => s.symm h, fun h => s.symm h⟩ - rw [Fintype.card_congr equivA, Fintype.card_congr equivB] - exact hc i - · have : IsEmpty {i // fa i = c} := ⟨fun i => hc' ⟨i.val,i.property⟩⟩ - simp - refine ⟨fibreEmbedding fa fb hcard, fun i => ?_⟩ - exact s.symm ((classSet_eq_iff s _ _).mp (fibreEmbedding_label fa fb hcard i)) - -private def moduleIsoSetoid (R : Type*) [Ring R] : Setoid (ModuleCat R) where - r M N := Nonempty (M ≃ₗ[R] N) - iseqv := ⟨fun M => ⟨LinearEquiv.refl R M⟩, - fun h => ⟨h.some.symm⟩, fun h h' => ⟨h.some.trans h'.some⟩⟩ - -theorem pi_embedding_of_iso_counts {R : Type*} [Ring R] - {ι κ : Type*} [Fintype ι] [Fintype κ] - (A : ι → Type v) (B : κ → Type v) [∀ i, AddCommGroup (A i)] - [∀ j, AddCommGroup (B j)] [∀ i, Module R (A i)] [∀ j, Module R (B j)] - (hc : ∀ i, Fintype.card {i' // Nonempty (A i ≃ₗ[R] A i')} ≤ - Fintype.card {j // Nonempty (A i ≃ₗ[R] B j)}) : - ∃ f : (Π i, A i) →ₗ[R] (Π j, B j), Function.Injective f := by - obtain ⟨f,hf⟩ := matching_of_equivalence_counts (moduleIsoSetoid R) - (fun i => ModuleCat.of R (A i)) (fun j => ModuleCat.of R (B j)) hc - let e (i : ι) : A i ≃ₗ[R] B (f i) := (hf i).some - exact ⟨piMapOfMatching A B f e, piMapOfMatching_injective A B f e⟩ - -end Foulkes.SemisimpleBridge - -namespace Foulkes.SemisimpleBridge -universe u -open Module - -theorem embedding_of_simple_hom_le {K R : Type*} [Field K] [IsAlgClosed K] - [Ring R] [Algebra K R] (A B : Type u) - [AddCommGroup A] [Module K A] [Module R A] [IsScalarTower K R A] - [AddCommGroup B] [Module K B] [Module R B] [IsScalarTower K R B] - [FiniteDimensional K A] [FiniteDimensional K B] - [IsSemisimpleModule R A] [IsSemisimpleModule R B] - (h : ∀ (T : Type u) [AddCommGroup T] [Module K T] [Module R T] - [IsScalarTower K R T] [FiniteDimensional K T] [IsSimpleModule R T], - finrank K (T →ₗ[R] A) ≤ finrank K (T →ₗ[R] B)) : - ∃ f : A →ₗ[R] B, Function.Injective f := by - classical - let : Module.Finite R A := Module.Finite.of_restrictScalars_finite K R A - let : Module.Finite R B := Module.Finite.of_restrictScalars_finite K R B - obtain ⟨n,S,eA,hS⟩ := IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp R A - obtain ⟨m,T,eB,hT⟩ := IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp R B - let (i : Fin n) : IsSimpleModule R (S i) := hS i - let (j : Fin m) : IsSimpleModule R (T j) := hT j - let (i : Fin n) : FiniteDimensional K (S i) := - Module.Finite.of_injective ((S i).subtype.restrictScalars K) (S i).subtype_injective - let (j : Fin m) : FiniteDimensional K (T j) := - Module.Finite.of_injective ((T j).subtype.restrictScalars K) (T j).subtype_injective - let eA' : A ≃ₗ[R] Π i, S i := eA.trans DFinsupp.linearEquivFunOnFintype - let eB' : B ≃ₗ[R] Π j, T j := eB.trans DFinsupp.linearEquivFunOnFintype - have hc (i : Fin n) : Fintype.card {i' // Nonempty (S i ≃ₗ[R] S i')} ≤ - Fintype.card {j // Nonempty (S i ≃ₗ[R] T j)} := by - rw [← hom_pi_finrank (K := K) (R := R) (A := S i) (fun i' => S i'), - ← hom_pi_finrank (K := K) (R := R) (A := S i) (fun j => T j)] - rw [← (homCongrRight (K := K) (A := S i) eA').finrank_eq, - ← (homCongrRight (K := K) (A := S i) eB').finrank_eq] - exact h (S i) - obtain ⟨f,hf⟩ := pi_embedding_of_iso_counts (R := R) (fun i => S i) (fun j => T j) hc - refine ⟨eB'.symm.toLinearMap.comp (f.comp eA'.toLinearMap), ?_⟩ - exact eB'.symm.injective.comp (hf.comp eA'.injective) - -end Foulkes.SemisimpleBridge - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.SemisimpleBridge +open Module +open scoped Classical + +section Algebra +variable {K R A B C : Type*} [Field K] [Ring R] [Algebra K R] + [AddCommGroup A] [Module K A] [Module R A] [IsScalarTower K R A] + [AddCommGroup B] [Module K B] [Module R B] [IsScalarTower K R B] + [AddCommGroup C] [Module K C] [Module R C] [IsScalarTower K R C] + +def homCongrRight (e : B ≃ₗ[R] C) : (A →ₗ[R] B) ≃ₗ[K] (A →ₗ[R] C) where + toFun f := e.toLinearMap.comp f + invFun f := e.symm.toLinearMap.comp f + left_inv f := by ext x; simp + right_inv f := by ext x; simp + map_add' f g := by ext x; simp + map_smul' k f := by + ext x + exact e.toLinearMap.map_smul_of_tower k (f x) + +lemma finite_hom [FiniteDimensional K A] [FiniteDimensional K B] : + FiniteDimensional K (A →ₗ[R] B) := + Module.Finite.of_injective (LinearMap.restrictScalarsₗ K R A B K) + (LinearMap.restrictScalars_injective K) + +lemma simple_hom_finrank [IsAlgClosed K] [FiniteDimensional K A] + [FiniteDimensional K B] [IsSimpleModule R A] [IsSimpleModule R B] : + finrank K (A →ₗ[R] B) = if Nonempty (A ≃ₗ[R] B) then 1 else 0 := by + classical + by_cases h : Nonempty (A ≃ₗ[R] B) + · rw [ite_eq_left h] + have he := homCongrRight (K := K) (A := A) h.some.symm + rw [he.finrank_eq] + have hb := IsSimpleModule.algebraMap_end_bijective_of_isAlgClosed (A := R) (V := A) K + have hh := (LinearEquiv.ofBijective (Algebra.linearMap K (Module.End R A)) hb).finrank_eq + simpa using hh.symm + · rw [ite_eq_right h] + have hz (f : A →ₗ[R] B) : f = 0 := by + rcases LinearMap.bijective_or_eq_zero f with hbij | hzero + · exact (h ⟨LinearEquiv.ofBijective f hbij⟩).elim + · exact hzero + let : Subsingleton (A →ₗ[R] B) := ⟨fun f g => (hz f).trans (hz g).symm⟩ + exact finrank_zero_of_subsingleton + +end Algebra +end Foulkes.SemisimpleBridge + +namespace Foulkes.SemisimpleBridge +open scoped Classical +open Module Finset + +def fibreEmbedding {ι κ C : Type*} [Fintype ι] [Fintype κ] + (f : ι → C) (g : κ → C) + (hc : ∀ c, Fintype.card {i // f i = c} ≤ Fintype.card {j // g j = c}) : ι ↪ κ := by + let e (c : C) : {i // f i = c} ↪ {j // g j = c} := + (Fintype.equivFin _).toEmbedding.trans + ((Fin.castLEEmb (hc c)).trans (Fintype.equivFin _).symm.toEmbedding) + exact (Equiv.sigmaFiberEquiv f).symm.toEmbedding.trans + ((Function.Embedding.sigmaMap (Function.Embedding.refl C) e).trans + (Equiv.sigmaFiberEquiv g).toEmbedding) + +lemma fibreEmbedding_label {ι κ C : Type*} [Fintype ι] [Fintype κ] + (f : ι → C) (g : κ → C) + (hc : ∀ c, Fintype.card {i // f i = c} ≤ Fintype.card {j // g j = c}) (i : ι) : + g (fibreEmbedding f g hc i) = f i := by + exact (show {j // g j = f i} from + ((Fintype.equivFin {i' // f i' = f i}).toEmbedding.trans + ((Fin.castLEEmb (hc (f i))).trans + (Fintype.equivFin {j // g j = f i}).symm.toEmbedding)) ⟨i,rfl⟩).property + +section PiHom +variable {K R A : Type*} [Field K] [Ring R] [Algebra K R] + [IsAlgClosed K] [AddCommGroup A] [Module K A] [Module R A] + [IsScalarTower K R A] [FiniteDimensional K A] [IsSimpleModule R A] + {ι : Type*} [Fintype ι] (P : ι → Type*) [∀ i, AddCommGroup (P i)] + [∀ i, Module K (P i)] [∀ i, Module R (P i)] [∀ i, IsScalarTower K R (P i)] + [∀ i, FiniteDimensional K (P i)] [∀ i, IsSimpleModule R (P i)] + +lemma hom_pi_finrank : + finrank K (A →ₗ[R] Π i, P i) = Fintype.card {i // Nonempty (A ≃ₗ[R] P i)} := by + let (i : ι) : FiniteDimensional K (A →ₗ[R] P i) := finite_hom + rw [← (LinearEquiv.linearMapPi (R := R) (M₂ := A) (φ := P) K).finrank_eq] + rw [Module.finrank_pi_fintype] + simp only [simple_hom_finrank] + simp [Fintype.card_subtype] + +end PiHom + +section PiEmbedding +variable {R : Type*} [Ring R] {ι κ : Type*} [Fintype ι] [Fintype κ] + (A : ι → Type*) (B : κ → Type*) [∀ i, AddCommGroup (A i)] + [∀ j, AddCommGroup (B j)] [∀ i, Module R (A i)] [∀ j, Module R (B j)] + +def piMapOfMatching (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) : + (Π i, A i) →ₗ[R] (Π j, B j) := + ∑ i, (LinearMap.single _ _ (f i)).comp + ((e i).toLinearMap.comp (LinearMap.proj i)) + +omit [Fintype κ] in +lemma piMapOfMatching_apply (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) + (x : Π i, A i) (i : ι) : piMapOfMatching A B f e x (f i) = e i (x i) := by + classical + simp only [piMapOfMatching, LinearMap.sum_apply, Finset.sum_apply, LinearMap.comp_apply, + LinearEquiv.coe_coe, LinearMap.proj_apply] + rw [Finset.sum_eq_single i] + · simp + · intro j hj hji + have hf : f j ≠ f i := fun hh => hji (f.injective hh) + simp [LinearMap.single_apply, Pi.single_eq_of_ne (Ne.symm hf)] + · simp + +omit [Fintype κ] in +lemma piMapOfMatching_injective (f : ι ↪ κ) (e : ∀ i, A i ≃ₗ[R] B (f i)) : + Function.Injective (piMapOfMatching A B f e) := by + intro x y h + funext i + apply (e i).injective + simpa only [piMapOfMatching_apply] using congrFun h (f i) + +end PiEmbedding +end Foulkes.SemisimpleBridge + +namespace Foulkes.SemisimpleBridge +universe v +open scoped Classical + +private def classSet {X : Type*} (s : Setoid X) (x : X) : Set X := {y | s.r x y} + +private lemma classSet_eq_iff {X : Type*} (s : Setoid X) (x y : X) : + classSet s x = classSet s y ↔ s.r x y := by + constructor + · intro h + have hy : y ∈ classSet s y := s.refl y + rw [← h] at hy + exact hy + · intro h + ext z + exact ⟨fun hz => s.trans (s.symm h) hz, fun hz => s.trans h hz⟩ + +theorem matching_of_equivalence_counts {ι κ X : Type*} [Fintype ι] [Fintype κ] + (s : Setoid X) (a : ι → X) (b : κ → X) + (hc : ∀ i, Fintype.card {i' // s.r (a i) (a i')} ≤ + Fintype.card {j // s.r (a i) (b j)}) : + ∃ f : ι ↪ κ, ∀ i, s.r (a i) (b (f i)) := by + classical + let fa := classSet s ∘ a + let fb := classSet s ∘ b + have hcard : ∀ c, Fintype.card {i // fa i = c} ≤ Fintype.card {j // fb j = c} := by + intro c + by_cases hc' : ∃ i, fa i = c + · obtain ⟨i,rfl⟩ := hc' + have equivA : {i' // fa i' = fa i} ≃ {i' // s.r (a i) (a i')} := + Equiv.subtypeEquivRight fun i' => + (classSet_eq_iff s (a i') (a i)).trans ⟨fun h => s.symm h, fun h => s.symm h⟩ + have equivB : {j // fb j = fa i} ≃ {j // s.r (a i) (b j)} := + Equiv.subtypeEquivRight fun j => + (classSet_eq_iff s (b j) (a i)).trans ⟨fun h => s.symm h, fun h => s.symm h⟩ + rw [Fintype.card_congr equivA, Fintype.card_congr equivB] + exact hc i + · have : IsEmpty {i // fa i = c} := ⟨fun i => hc' ⟨i.val,i.property⟩⟩ + simp + refine ⟨fibreEmbedding fa fb hcard, fun i => ?_⟩ + exact s.symm ((classSet_eq_iff s _ _).mp (fibreEmbedding_label fa fb hcard i)) + +private def moduleIsoSetoid (R : Type*) [Ring R] : Setoid (ModuleCat R) where + r M N := Nonempty (M ≃ₗ[R] N) + iseqv := ⟨fun M => ⟨LinearEquiv.refl R M⟩, + fun h => ⟨h.some.symm⟩, fun h h' => ⟨h.some.trans h'.some⟩⟩ + +theorem pi_embedding_of_iso_counts {R : Type*} [Ring R] + {ι κ : Type*} [Fintype ι] [Fintype κ] + (A : ι → Type v) (B : κ → Type v) [∀ i, AddCommGroup (A i)] + [∀ j, AddCommGroup (B j)] [∀ i, Module R (A i)] [∀ j, Module R (B j)] + (hc : ∀ i, Fintype.card {i' // Nonempty (A i ≃ₗ[R] A i')} ≤ + Fintype.card {j // Nonempty (A i ≃ₗ[R] B j)}) : + ∃ f : (Π i, A i) →ₗ[R] (Π j, B j), Function.Injective f := by + obtain ⟨f,hf⟩ := matching_of_equivalence_counts (moduleIsoSetoid R) + (fun i => ModuleCat.of R (A i)) (fun j => ModuleCat.of R (B j)) hc + let e (i : ι) : A i ≃ₗ[R] B (f i) := (hf i).some + exact ⟨piMapOfMatching A B f e, piMapOfMatching_injective A B f e⟩ + +end Foulkes.SemisimpleBridge + +namespace Foulkes.SemisimpleBridge +universe u +open Module + +theorem embedding_of_simple_hom_le {K R : Type*} [Field K] [IsAlgClosed K] + [Ring R] [Algebra K R] (A B : Type u) + [AddCommGroup A] [Module K A] [Module R A] [IsScalarTower K R A] + [AddCommGroup B] [Module K B] [Module R B] [IsScalarTower K R B] + [FiniteDimensional K A] [FiniteDimensional K B] + [IsSemisimpleModule R A] [IsSemisimpleModule R B] + (h : ∀ (T : Type u) [AddCommGroup T] [Module K T] [Module R T] + [IsScalarTower K R T] [FiniteDimensional K T] [IsSimpleModule R T], + finrank K (T →ₗ[R] A) ≤ finrank K (T →ₗ[R] B)) : + ∃ f : A →ₗ[R] B, Function.Injective f := by + classical + let : Module.Finite R A := Module.Finite.of_restrictScalars_finite K R A + let : Module.Finite R B := Module.Finite.of_restrictScalars_finite K R B + obtain ⟨n,S,eA,hS⟩ := IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp R A + obtain ⟨m,T,eB,hT⟩ := IsSemisimpleModule.exists_linearEquiv_fin_dfinsupp R B + let (i : Fin n) : IsSimpleModule R (S i) := hS i + let (j : Fin m) : IsSimpleModule R (T j) := hT j + let (i : Fin n) : FiniteDimensional K (S i) := + Module.Finite.of_injective ((S i).subtype.restrictScalars K) (S i).subtype_injective + let (j : Fin m) : FiniteDimensional K (T j) := + Module.Finite.of_injective ((T j).subtype.restrictScalars K) (T j).subtype_injective + let eA' : A ≃ₗ[R] Π i, S i := eA.trans DFinsupp.linearEquivFunOnFintype + let eB' : B ≃ₗ[R] Π j, T j := eB.trans DFinsupp.linearEquivFunOnFintype + have hc (i : Fin n) : Fintype.card {i' // Nonempty (S i ≃ₗ[R] S i')} ≤ + Fintype.card {j // Nonempty (S i ≃ₗ[R] T j)} := by + rw [← hom_pi_finrank (K := K) (R := R) (A := S i) (fun i' => S i'), + ← hom_pi_finrank (K := K) (R := R) (A := S i) (fun j => T j)] + rw [← (homCongrRight (K := K) (A := S i) eA').finrank_eq, + ← (homCongrRight (K := K) (A := S i) eB').finrank_eq] + exact h (S i) + obtain ⟨f,hf⟩ := pi_embedding_of_iso_counts (R := R) (fun i => S i) (fun j => T j) hc + refine ⟨eB'.symm.toLinearMap.comp (f.comp eA'.toLinearMap), ?_⟩ + exact eB'.symm.injective.comp (hf.comp eA'.injective) + +end Foulkes.SemisimpleBridge + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SignedStrips.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SignedStrips.lean index e8e0a696465ad769c84a6d00ae8310e49651a2d8..098bab7ac92c45a4db90a07f250f10d0e10a30a7 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SignedStrips.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SignedStrips.lean @@ -1,67 +1,67 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.StripInterlace - -namespace OAI - -noncomputable section - -namespace Foulkes.Strips -open MvPolynomial Finset - -def staircase (n : ℕ) (j : Fin n) : ℕ := n-1-j.val - -def shifted {n : ℕ} (γ : Fin n → ℕ) (j : Fin n) : ℕ := γ j + staircase n j - -lemma staircase_antitone (n : ℕ) : Antitone (staircase n) := by - intro j k hjk - simp only [staircase] - exact Nat.sub_le_sub_left hjk (n-1) - -lemma shifted_antitone {n : ℕ} {γ : Fin n → ℕ} (hγ : Antitone γ) : Antitone (shifted γ) := by - intro j k hjk - exact add_le_add (hγ hjk) (staircase_antitone n hjk) - -lemma shifted_sum {n i b : ℕ} (γ μ : Fin n → ℕ) - (hs : ∑ j, γ j = (∑ j, μ j) + i*b) : - ∑ j, shifted γ j = (∑ j, shifted μ j) + i*b := by - simp only [shifted, Finset.sum_add_distrib] - omega - -def stripCoeff {n : ℕ} (i b : ℕ) (γ μ : Fin n → ℕ) : ℤ := - (completePowers n i b * alternant (shifted μ)).coeff (expVector (shifted γ)) - -theorem signed_strips {n i b : ℕ} (hi : 1 ≤ i) (hb : 1 ≤ b) - (γ μ : Fin n → ℕ) (hγ : Antitone γ) (hμ : Antitone μ) - (hsize : (∑ j, γ j) - (∑ j, μ j) = i*b) : - (stripCoeff i b γ μ = 0 ∨ stripCoeff i b γ μ = 1 ∨ stripCoeff i b γ μ = -1) ∧ - (stripCoeff i b γ μ ≠ 0 → ∀ j : Fin n, μ j ≤ γ j ∧ - ∀ hji : j.val+i < n, γ ⟨j.val+i,hji⟩ ≤ μ j) := by - have hip : 0 < i := by omega - have hbp : 0 < b := by omega - have hprod : 0 < i*b := Nat.mul_pos hip hbp - have hs : ∑ j, γ j = (∑ j, μ j) + i*b := by omega - have hbound := signed_strip_abs_le_one hip (shifted γ) (shifted μ) (shifted_sum γ μ hs) - change Int.natAbs (stripCoeff i b γ μ) ≤ 1 at hbound - constructor - · omega - · intro hnon j - have heq := coefficient_eq_assignment_det hip (shifted γ) (shifted μ) (shifted_sum γ μ hs) - change stripCoeff i b γ μ = _ at heq - have hd : (incidence (assignments i (shifted γ) (shifted μ))).det ≠ 0 := by - rwa [← heq] - constructor - · have hc := containment_of_det_ne_zero (shifted γ) (shifted μ) - (shifted_antitone hγ) (shifted_antitone hμ) hd j - simpa only [shifted, Nat.add_le_add_iff_right] using hc - · intro hji - have hc := shifted_containment_of_det_ne_zero hip (shifted γ) (shifted μ) - (shifted_antitone hγ) (shifted_antitone hμ) hd j hji - simp only [shifted, staircase] at hc - have hjn := j.isLt - omega - -end Foulkes.Strips - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.StripInterlace + +namespace OAI + +noncomputable section + +namespace Foulkes.Strips +open MvPolynomial Finset + +def staircase (n : ℕ) (j : Fin n) : ℕ := n-1-j.val + +def shifted {n : ℕ} (γ : Fin n → ℕ) (j : Fin n) : ℕ := γ j + staircase n j + +lemma staircase_antitone (n : ℕ) : Antitone (staircase n) := by + intro j k hjk + simp only [staircase] + exact Nat.sub_le_sub_left hjk (n-1) + +lemma shifted_antitone {n : ℕ} {γ : Fin n → ℕ} (hγ : Antitone γ) : Antitone (shifted γ) := by + intro j k hjk + exact add_le_add (hγ hjk) (staircase_antitone n hjk) + +lemma shifted_sum {n i b : ℕ} (γ μ : Fin n → ℕ) + (hs : ∑ j, γ j = (∑ j, μ j) + i*b) : + ∑ j, shifted γ j = (∑ j, shifted μ j) + i*b := by + simp only [shifted, Finset.sum_add_distrib] + omega + +def stripCoeff {n : ℕ} (i b : ℕ) (γ μ : Fin n → ℕ) : ℤ := + (completePowers n i b * alternant (shifted μ)).coeff (expVector (shifted γ)) + +theorem signed_strips {n i b : ℕ} (hi : 1 ≤ i) (hb : 1 ≤ b) + (γ μ : Fin n → ℕ) (hγ : Antitone γ) (hμ : Antitone μ) + (hsize : (∑ j, γ j) - (∑ j, μ j) = i*b) : + (stripCoeff i b γ μ = 0 ∨ stripCoeff i b γ μ = 1 ∨ stripCoeff i b γ μ = -1) ∧ + (stripCoeff i b γ μ ≠ 0 → ∀ j : Fin n, μ j ≤ γ j ∧ + ∀ hji : j.val+i < n, γ ⟨j.val+i,hji⟩ ≤ μ j) := by + have hip : 0 < i := by omega + have hbp : 0 < b := by omega + have hprod : 0 < i*b := Nat.mul_pos hip hbp + have hs : ∑ j, γ j = (∑ j, μ j) + i*b := by omega + have hbound := signed_strip_abs_le_one hip (shifted γ) (shifted μ) (shifted_sum γ μ hs) + change Int.natAbs (stripCoeff i b γ μ) ≤ 1 at hbound + constructor + · omega + · intro hnon j + have heq := coefficient_eq_assignment_det hip (shifted γ) (shifted μ) (shifted_sum γ μ hs) + change stripCoeff i b γ μ = _ at heq + have hd : (incidence (assignments i (shifted γ) (shifted μ))).det ≠ 0 := by + rwa [← heq] + constructor + · have hc := containment_of_det_ne_zero (shifted γ) (shifted μ) + (shifted_antitone hγ) (shifted_antitone hμ) hd j + simpa only [shifted, Nat.add_le_add_iff_right] using hc + · intro hji + have hc := shifted_containment_of_det_ne_zero hip (shifted γ) (shifted μ) + (shifted_antitone hγ) (shifted_antitone hμ) hd j hji + simp only [shifted, staircase] at hc + have hjn := j.isLt + omega + +end Foulkes.Strips + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SixCycles.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SixCycles.lean index aeee4a63317b44509b2fc73c872c069ab3c0fa2d..b314e0b44caa7864ead42bc9d2e8b6fe8fa9cf78 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SixCycles.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SixCycles.lean @@ -1,52 +1,52 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.SourceNewton - -namespace OAI - -noncomputable section - -namespace Foulkes.Complete -open MvPolynomial Finset - -def cycleSix {R : Type*} [CommRing R] (p : ℕ → R) : R := - p 1 ^ 6 + 15*p 1^4*p 2 + 45*p 1^2*p 2^2 + 15*p 2^3 + - 40*p 1^3*p 3 + 120*p 1*p 2*p 3 + 40*p 3^2 + - 90*p 1^2*p 4 + 90*p 2*p 4 + 144*p 1*p 5 + 120*p 6 - -theorem cycleSix_of_newton {R : Type*} [CommRing R] (h p : ℕ → R) - (h0 : h 0 = 1) - (hn : ∀ j : ℕ, (j : R)*h j = ∑ i ∈ Finset.Icc 1 j, p i*h (j-i)) : - 720*h 6 = cycleSix p := by - have n1 := hn 1 - have n2 := hn 2 - have n3 := hn 3 - have n4 := hn 4 - have n5 := hn 5 - have n6 := hn 6 - norm_num [Finset.sum_Icc_succ_top, h0] at n1 n2 n3 n4 n5 n6 - have e2 : 2*h 2 = p 1^2+p 2 := by - linear_combination n2 + p 1*n1 - have e3 : 6*h 3 = p 1^3+3*p 1*p 2+2*p 3 := by - linear_combination 2*n3 + p 1*e2 + 2*p 2*n1 - have e4 : 24*h 4 = p 1^4+6*p 1^2*p 2+3*p 2^2+8*p 1*p 3+6*p 4 := by - linear_combination 6*n4 + p 1*e3 + 3*p 2*e2 + 6*p 3*n1 - have e5 : 120*h 5 = p 1^5+10*p 1^3*p 2+15*p 1*p 2^2+ - 20*p 1^2*p 3+20*p 2*p 3+30*p 1*p 4+24*p 5 := by - linear_combination 24*n5 + p 1*e4 + 4*p 2*e3 + 12*p 3*e2 + 24*p 4*n1 - unfold cycleSix - linear_combination 120*n6 + p 1*e5 + 5*p 2*e4 + 20*p 3*e3 + 60*p 4*e2 + 120*p 5*n1 - -theorem pleth_cycleSix (n b : ℕ) : - (720 : ℤ) • pleth n 6 b = - cycleSix (fun i => Foulkes.Strips.completePowers n i b) := by - norm_num only [zsmul_eq_mul, Int.cast_ofNat] - apply cycleSix_of_newton (h := fun j => pleth n j b) - · exact pleth_zero n b - · intro j - simpa only [zsmul_eq_mul, Int.cast_natCast] using pleth_newton_powers n j b - -end Foulkes.Complete - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.SourceNewton + +namespace OAI + +noncomputable section + +namespace Foulkes.Complete +open MvPolynomial Finset + +def cycleSix {R : Type*} [CommRing R] (p : ℕ → R) : R := + p 1 ^ 6 + 15*p 1^4*p 2 + 45*p 1^2*p 2^2 + 15*p 2^3 + + 40*p 1^3*p 3 + 120*p 1*p 2*p 3 + 40*p 3^2 + + 90*p 1^2*p 4 + 90*p 2*p 4 + 144*p 1*p 5 + 120*p 6 + +theorem cycleSix_of_newton {R : Type*} [CommRing R] (h p : ℕ → R) + (h0 : h 0 = 1) + (hn : ∀ j : ℕ, (j : R)*h j = ∑ i ∈ Finset.Icc 1 j, p i*h (j-i)) : + 720*h 6 = cycleSix p := by + have n1 := hn 1 + have n2 := hn 2 + have n3 := hn 3 + have n4 := hn 4 + have n5 := hn 5 + have n6 := hn 6 + norm_num [Finset.sum_Icc_succ_top, h0] at n1 n2 n3 n4 n5 n6 + have e2 : 2*h 2 = p 1^2+p 2 := by + linear_combination n2 + p 1*n1 + have e3 : 6*h 3 = p 1^3+3*p 1*p 2+2*p 3 := by + linear_combination 2*n3 + p 1*e2 + 2*p 2*n1 + have e4 : 24*h 4 = p 1^4+6*p 1^2*p 2+3*p 2^2+8*p 1*p 3+6*p 4 := by + linear_combination 6*n4 + p 1*e3 + 3*p 2*e2 + 6*p 3*n1 + have e5 : 120*h 5 = p 1^5+10*p 1^3*p 2+15*p 1*p 2^2+ + 20*p 1^2*p 3+20*p 2*p 3+30*p 1*p 4+24*p 5 := by + linear_combination 24*n5 + p 1*e4 + 4*p 2*e3 + 12*p 3*e2 + 24*p 4*n1 + unfold cycleSix + linear_combination 120*n6 + p 1*e5 + 5*p 2*e4 + 20*p 3*e3 + 60*p 4*e2 + 120*p 5*n1 + +theorem pleth_cycleSix (n b : ℕ) : + (720 : ℤ) • pleth n 6 b = + cycleSix (fun i => Foulkes.Strips.completePowers n i b) := by + norm_num only [zsmul_eq_mul, Int.cast_ofNat] + apply cycleSix_of_newton (h := fun j => pleth n j b) + · exact pleth_zero n b + · intro j + simpa only [zsmul_eq_mul, Int.cast_natCast] using pleth_newton_powers n j b + +end Foulkes.Complete + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SourceNewton.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SourceNewton.lean index 2c70d24717646b094a3ab11081ff1ae76fc7616c..93aa65b5fa2bcb36baf4928aff7f052c9bad7c98 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SourceNewton.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SourceNewton.lean @@ -1,82 +1,82 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm - -namespace OAI - -noncomputable section - -namespace Foulkes.Complete -open MvPolynomial Finset Foulkes.Strips - -def degreeCompositionEquiv (n b : ℕ) : Degree (Fin n) b ≃ Composition n b where - toFun d := ⟨fun j => ⟨d.val j, by - have hj := Finsupp.le_degree j d.val - omega⟩, by simpa using (Finsupp.degree_eq_sum d.val).symm.trans d.property⟩ - invFun v := ⟨expVector (fun j => (v.val j).val), by - rw [Lookup.degree_expVector] - exact v.property⟩ - left_inv d := by apply Subtype.ext; ext j; rfl - right_inv v := by apply Subtype.ext; funext j; apply Fin.ext; rfl - -lemma powerAlphabet_eq_completePowers (n i b : ℕ) : - (∑ d : Degree (Fin n) b, - monomial (i • d.val) (1 : ℤ)) = completePowers n i b := by - classical - unfold completePowers - apply Fintype.sum_equiv (degreeCompositionEquiv n b) - intro d - have he : i • d.val = Finsupp.equivFunOnFinite.symm - (fun j => i*((degreeCompositionEquiv n b d).val j).val) := by - ext j - change i * d.val j = i * d.val j - rfl - rw [he] - -lemma pleth_newton_powers (n j b : ℕ) : - (j : ℤ) • pleth n j b = - ∑ i ∈ Finset.Icc 1 j, completePowers n i b * pleth n (j-i) b := by - simpa only [powerAlphabet_eq_completePowers] using pleth_newton n j b - -end Foulkes.Complete - -namespace Foulkes.Lookup -open MvPolynomial Finset Foulkes.Strips - -def stripCoeff {n : ℕ} (b i : ℕ) (gamma mu : Fin n → ℕ) : ℤ := - (completePowers n i b * alternant (shifted mu)).coeff (expVector (shifted gamma)) - -theorem source_newton (n j b : ℕ) (gamma : Fin n → ℕ) : - (j : ℤ) * schurCoeff (Complete.pleth n j b) gamma = - ∑ i ∈ Finset.Icc 1 j, - ∑ mu : Partition n ((j-i)*b), - stripCoeff b i gamma (partVec mu) * - schurCoeff (Complete.pleth n (j-i) b) (partVec mu) := by - classical - have hh := congrArg (fun p : MvPolynomial (Fin n) ℤ => - (p * alternant (staircase n)).coeff (expVector (shifted gamma))) - (Complete.pleth_newton_powers n j b) - change (((j : ℤ) • Complete.pleth n j b) * alternant (staircase n)).coeff - (expVector (shifted gamma)) = _ at hh - rw [smul_mul_assoc, coeff_smul] at hh - simp only [zsmul_eq_mul, Finset.sum_mul, coeff_sum] at hh - change (j : ℤ) * schurCoeff (Complete.pleth n j b) gamma = _ at hh - rw [hh] - apply Finset.sum_congr rfl - intro i hi - rw [mul_assoc] - rw [homogeneous_schur_expansion (d := (j-i)*b) _ (Complete.rename_pleth n (j-i) b) - (by simpa [Nat.mul_comm] using Complete.homogeneous_pleth n (j-i) b)] - simp only [Finset.mul_sum, coeff_sum] - apply Finset.sum_congr rfl - intro mu hmu - change (completePowers n i b * - (schurCoeff (Complete.pleth n (j-i) b) (partVec mu) • - alternant (shifted (partVec mu)))).coeff _ = _ - rw [mul_smul_comm, coeff_smul] - exact mul_comm _ _ - -end Foulkes.Lookup - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm + +namespace OAI + +noncomputable section + +namespace Foulkes.Complete +open MvPolynomial Finset Foulkes.Strips + +def degreeCompositionEquiv (n b : ℕ) : Degree (Fin n) b ≃ Composition n b where + toFun d := ⟨fun j => ⟨d.val j, by + have hj := Finsupp.le_degree j d.val + omega⟩, by simpa using (Finsupp.degree_eq_sum d.val).symm.trans d.property⟩ + invFun v := ⟨expVector (fun j => (v.val j).val), by + rw [Lookup.degree_expVector] + exact v.property⟩ + left_inv d := by apply Subtype.ext; ext j; rfl + right_inv v := by apply Subtype.ext; funext j; apply Fin.ext; rfl + +lemma powerAlphabet_eq_completePowers (n i b : ℕ) : + (∑ d : Degree (Fin n) b, + monomial (i • d.val) (1 : ℤ)) = completePowers n i b := by + classical + unfold completePowers + apply Fintype.sum_equiv (degreeCompositionEquiv n b) + intro d + have he : i • d.val = Finsupp.equivFunOnFinite.symm + (fun j => i*((degreeCompositionEquiv n b d).val j).val) := by + ext j + change i * d.val j = i * d.val j + rfl + rw [he] + +lemma pleth_newton_powers (n j b : ℕ) : + (j : ℤ) • pleth n j b = + ∑ i ∈ Finset.Icc 1 j, completePowers n i b * pleth n (j-i) b := by + simpa only [powerAlphabet_eq_completePowers] using pleth_newton n j b + +end Foulkes.Complete + +namespace Foulkes.Lookup +open MvPolynomial Finset Foulkes.Strips + +def stripCoeff {n : ℕ} (b i : ℕ) (gamma mu : Fin n → ℕ) : ℤ := + (completePowers n i b * alternant (shifted mu)).coeff (expVector (shifted gamma)) + +theorem source_newton (n j b : ℕ) (gamma : Fin n → ℕ) : + (j : ℤ) * schurCoeff (Complete.pleth n j b) gamma = + ∑ i ∈ Finset.Icc 1 j, + ∑ mu : Partition n ((j-i)*b), + stripCoeff b i gamma (partVec mu) * + schurCoeff (Complete.pleth n (j-i) b) (partVec mu) := by + classical + have hh := congrArg (fun p : MvPolynomial (Fin n) ℤ => + (p * alternant (staircase n)).coeff (expVector (shifted gamma))) + (Complete.pleth_newton_powers n j b) + change (((j : ℤ) • Complete.pleth n j b) * alternant (staircase n)).coeff + (expVector (shifted gamma)) = _ at hh + rw [smul_mul_assoc, coeff_smul] at hh + simp only [zsmul_eq_mul, Finset.sum_mul, coeff_sum] at hh + change (j : ℤ) * schurCoeff (Complete.pleth n j b) gamma = _ at hh + rw [hh] + apply Finset.sum_congr rfl + intro i hi + rw [mul_assoc] + rw [homogeneous_schur_expansion (d := (j-i)*b) _ (Complete.rename_pleth n (j-i) b) + (by simpa [Nat.mul_comm] using Complete.homogeneous_pleth n (j-i) b)] + simp only [Finset.mul_sum, coeff_sum] + apply Finset.sum_congr rfl + intro mu hmu + change (completePowers n i b * + (schurCoeff (Complete.pleth n (j-i) b) (partVec mu) • + alternant (shifted (partVec mu)))).coeff _ = _ + rw [mul_smul_comm, coeff_smul] + exact mul_comm _ _ + +end Foulkes.Lookup + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/StripCoefficient.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/StripCoefficient.lean index 4b6cc136e8b2932876fd169797a9aa6fdfef81f9..85db034b4b6dbcd8510bb61214b0e7fb57315d66 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/StripCoefficient.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/StripCoefficient.lean @@ -1,141 +1,141 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.StripSupport - -namespace OAI - -noncomputable section - -namespace Foulkes.Strips -open MvPolynomial Finset Matrix - -def Composition (n b : ℕ) := {v : Fin n → Fin (b+1) // ∑ j, (v j).val = b} -instance (n b : ℕ) : Fintype (Composition n b) := - inferInstanceAs (Fintype {_composition : Fin n → Fin (b+1) // _}) - -def completePowers (n i b : ℕ) : MvPolynomial (Fin n) ℤ := - ∑ v : Composition n b, - monomial (Finsupp.equivFunOnFinite.symm (fun j => i*(v.val j).val)) 1 - -def alternant {n : ℕ} (m : Fin n → ℕ) : MvPolynomial (Fin n) ℤ := - Matrix.det fun r c => (X r : MvPolynomial (Fin n) ℤ) ^ m c - -abbrev expVector {n : ℕ} (v : Fin n → ℕ) : Fin n →₀ ℕ := Finsupp.equivFunOnFinite.symm v - -@[simp] lemma expVector_apply {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : expVector v j = v j := by - simp [expVector] - -lemma exponent_injective {n b i : ℕ} (hi : 0 < i) (d : Fin n → ℕ) : - Function.Injective (fun v : Composition n b => expVector (fun j => i*(v.val j).val) + expVector d) := by - intro v w h - apply Subtype.ext - funext j - apply Fin.ext - have hj := DFunLike.congr_fun h j - simp only [Finsupp.add_apply, expVector_apply] at hj - exact Nat.eq_of_mul_eq_mul_left hi (Nat.add_right_cancel hj) - -lemma coeff_complete_monomial {n b i : ℕ} (hi : 0 < i) (l d : Fin n → ℕ) : - (completePowers n i b * monomial (expVector d) 1).coeff (expVector l) = - if ∃ v : Composition n b, expVector (fun j => i*(v.val j).val) + expVector d = expVector l - then 1 else 0 := by - classical - simp only [completePowers, Finset.sum_mul, coeff_sum, monomial_mul_monomial, one_mul, coeff_monomial] - split_ifs with h - · obtain ⟨v,hv⟩ := h - rw [Finset.sum_eq_single v] - · simp [hv] - · intro w hw hne - have hh : expVector (fun j => i*(w.val j).val) + expVector d ≠ expVector l := by - intro hw - exact hne (exponent_injective hi d (hw.trans hv.symm)) - simp [hh] - · simp - · apply Finset.sum_eq_zero - intro v hv - simp only [ite_eq_right (fun hh => h ⟨v,hh⟩)] - -lemma perm_prod_monomial {n : ℕ} (m : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : - (∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c) = - monomial (expVector (fun r => m (σ.symm r))) 1 := by - rw [monic_monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] - simpa using Equiv.prod_comp σ (fun r => (X r : MvPolynomial (Fin n) ℤ) ^ m (σ.symm r)) - -lemma exists_composition_iff {n b i : ℕ} (hi : 0 < i) (l d : Fin n → ℕ) - (htotal : ∑ r, l r = (∑ r, d r) + i*b) : - (∃ v : Composition n b, expVector (fun j => i*(v.val j).val) + expVector d = expVector l) ↔ - ∀ r, d r ≤ l r ∧ d r % i = l r % i := by - classical - constructor - · rintro ⟨v,hv⟩ r - have hr := DFunLike.congr_fun hv r - simp only [Finsupp.add_apply, expVector_apply] at hr - refine ⟨by omega, ?_⟩ - rw [← hr] - simp - · intro h - let q : Fin n → ℕ := fun r => (l r - d r) / i - have hq (r : Fin n) : i*q r + d r = l r := by - have hdvd : i ∣ l r-d r := (Nat.modEq_iff_dvd' (h r).1).mp (h r).2 - dsimp [q] - rw [Nat.mul_div_cancel' hdvd, Nat.sub_add_cancel (h r).1] - have hsum : ∑ r, q r = b := by - have hs : i*(∑ r, q r) + ∑ r, d r = ∑ r, l r := by - rw [Finset.mul_sum, ← Finset.sum_add_distrib] - exact Finset.sum_congr rfl (fun r hr => hq r) - have he : i*(∑ r, q r) = i*b := by omega - exact Nat.eq_of_mul_eq_mul_left hi he - have hb (r : Fin n) : q r < b+1 := by - have hh : q r ≤ ∑ j, q j := Finset.single_le_sum (fun j hj => Nat.zero_le _) (mem_univ r) - omega - let v : Composition n b := ⟨fun r => ⟨q r, hb r⟩, hsum⟩ - refine ⟨v, ?_⟩ - ext r - exact hq r - -lemma assignment_product {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : - (∏ c, incidence (assignments i l m) (σ c) c) = - if ∀ r, m (σ.symm r) ≤ l r ∧ m (σ.symm r) % i = l r % i then 1 else 0 := by - classical - by_cases h : ∀ r, m (σ.symm r) ≤ l r ∧ m (σ.symm r) % i = l r % i - · rw [ite_eq_left h] - apply Finset.prod_eq_one - intro c hc - have hh := h (σ c) - simp only [incidence, assignments, mem_filter, mem_univ, true_and] - rw [ite_eq_left (by simpa using hh)] - · rw [ite_eq_right h] - push Not at h - obtain ⟨r,hr⟩ := h - apply Finset.prod_eq_zero (mem_univ (σ.symm r)) - simp only [incidence, assignments, mem_filter, mem_univ, true_and, Equiv.apply_symm_apply] - exact ite_eq_right (fun hh => hr hh.1 hh.2) - -theorem coefficient_eq_assignment_det {n b i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) - (htotal : ∑ r, l r = (∑ r, m r) + i*b) : - (completePowers n i b * alternant m).coeff (expVector l) = - (incidence (assignments i l m)).det := by - classical - have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), - Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := - Matrix.det_apply _ - rw [ha, Matrix.det_apply, Finset.mul_sum, coeff_sum] - apply Finset.sum_congr rfl - intro σ hσ - rw [mul_smul_comm, coeff_smul, perm_prod_monomial, coeff_complete_monomial hi, - assignment_product] - have ht : ∑ r, l r = (∑ r, m (σ.symm r)) + i*b := by - rw [Equiv.sum_comp σ.symm m] - exact htotal - simp only [exists_composition_iff hi l _ ht] - -theorem signed_strip_abs_le_one {n b i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) - (htotal : ∑ r, l r = (∑ r, m r) + i*b) : - Int.natAbs ((completePowers n i b * alternant m).coeff (expVector l)) ≤ 1 := by - rw [coefficient_eq_assignment_det hi l m htotal] - exact assignment_det_bound i l m - -end Foulkes.Strips - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.StripSupport + +namespace OAI + +noncomputable section + +namespace Foulkes.Strips +open MvPolynomial Finset Matrix + +def Composition (n b : ℕ) := {v : Fin n → Fin (b+1) // ∑ j, (v j).val = b} +instance (n b : ℕ) : Fintype (Composition n b) := + inferInstanceAs (Fintype {_composition : Fin n → Fin (b+1) // _}) + +def completePowers (n i b : ℕ) : MvPolynomial (Fin n) ℤ := + ∑ v : Composition n b, + monomial (Finsupp.equivFunOnFinite.symm (fun j => i*(v.val j).val)) 1 + +def alternant {n : ℕ} (m : Fin n → ℕ) : MvPolynomial (Fin n) ℤ := + Matrix.det fun r c => (X r : MvPolynomial (Fin n) ℤ) ^ m c + +abbrev expVector {n : ℕ} (v : Fin n → ℕ) : Fin n →₀ ℕ := Finsupp.equivFunOnFinite.symm v + +@[simp] lemma expVector_apply {n : ℕ} (v : Fin n → ℕ) (j : Fin n) : expVector v j = v j := by + simp [expVector] + +lemma exponent_injective {n b i : ℕ} (hi : 0 < i) (d : Fin n → ℕ) : + Function.Injective (fun v : Composition n b => expVector (fun j => i*(v.val j).val) + expVector d) := by + intro v w h + apply Subtype.ext + funext j + apply Fin.ext + have hj := DFunLike.congr_fun h j + simp only [Finsupp.add_apply, expVector_apply] at hj + exact Nat.eq_of_mul_eq_mul_left hi (Nat.add_right_cancel hj) + +lemma coeff_complete_monomial {n b i : ℕ} (hi : 0 < i) (l d : Fin n → ℕ) : + (completePowers n i b * monomial (expVector d) 1).coeff (expVector l) = + if ∃ v : Composition n b, expVector (fun j => i*(v.val j).val) + expVector d = expVector l + then 1 else 0 := by + classical + simp only [completePowers, Finset.sum_mul, coeff_sum, monomial_mul_monomial, one_mul, coeff_monomial] + split_ifs with h + · obtain ⟨v,hv⟩ := h + rw [Finset.sum_eq_single v] + · simp [hv] + · intro w hw hne + have hh : expVector (fun j => i*(w.val j).val) + expVector d ≠ expVector l := by + intro hw + exact hne (exponent_injective hi d (hw.trans hv.symm)) + simp [hh] + · simp + · apply Finset.sum_eq_zero + intro v hv + simp only [ite_eq_right (fun hh => h ⟨v,hh⟩)] + +lemma perm_prod_monomial {n : ℕ} (m : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : + (∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c) = + monomial (expVector (fun r => m (σ.symm r))) 1 := by + rw [monic_monomial_eq, Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] + simpa using Equiv.prod_comp σ (fun r => (X r : MvPolynomial (Fin n) ℤ) ^ m (σ.symm r)) + +lemma exists_composition_iff {n b i : ℕ} (hi : 0 < i) (l d : Fin n → ℕ) + (htotal : ∑ r, l r = (∑ r, d r) + i*b) : + (∃ v : Composition n b, expVector (fun j => i*(v.val j).val) + expVector d = expVector l) ↔ + ∀ r, d r ≤ l r ∧ d r % i = l r % i := by + classical + constructor + · rintro ⟨v,hv⟩ r + have hr := DFunLike.congr_fun hv r + simp only [Finsupp.add_apply, expVector_apply] at hr + refine ⟨by omega, ?_⟩ + rw [← hr] + simp + · intro h + let q : Fin n → ℕ := fun r => (l r - d r) / i + have hq (r : Fin n) : i*q r + d r = l r := by + have hdvd : i ∣ l r-d r := (Nat.modEq_iff_dvd' (h r).1).mp (h r).2 + dsimp [q] + rw [Nat.mul_div_cancel' hdvd, Nat.sub_add_cancel (h r).1] + have hsum : ∑ r, q r = b := by + have hs : i*(∑ r, q r) + ∑ r, d r = ∑ r, l r := by + rw [Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun r hr => hq r) + have he : i*(∑ r, q r) = i*b := by omega + exact Nat.eq_of_mul_eq_mul_left hi he + have hb (r : Fin n) : q r < b+1 := by + have hh : q r ≤ ∑ j, q j := Finset.single_le_sum (fun j hj => Nat.zero_le _) (mem_univ r) + omega + let v : Composition n b := ⟨fun r => ⟨q r, hb r⟩, hsum⟩ + refine ⟨v, ?_⟩ + ext r + exact hq r + +lemma assignment_product {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) (σ : Equiv.Perm (Fin n)) : + (∏ c, incidence (assignments i l m) (σ c) c) = + if ∀ r, m (σ.symm r) ≤ l r ∧ m (σ.symm r) % i = l r % i then 1 else 0 := by + classical + by_cases h : ∀ r, m (σ.symm r) ≤ l r ∧ m (σ.symm r) % i = l r % i + · rw [ite_eq_left h] + apply Finset.prod_eq_one + intro c hc + have hh := h (σ c) + simp only [incidence, assignments, mem_filter, mem_univ, true_and] + rw [ite_eq_left (by simpa using hh)] + · rw [ite_eq_right h] + push Not at h + obtain ⟨r,hr⟩ := h + apply Finset.prod_eq_zero (mem_univ (σ.symm r)) + simp only [incidence, assignments, mem_filter, mem_univ, true_and, Equiv.apply_symm_apply] + exact ite_eq_right (fun hh => hr hh.1 hh.2) + +theorem coefficient_eq_assignment_det {n b i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) + (htotal : ∑ r, l r = (∑ r, m r) + i*b) : + (completePowers n i b * alternant m).coeff (expVector l) = + (incidence (assignments i l m)).det := by + classical + have ha : alternant m = ∑ σ : Equiv.Perm (Fin n), + Equiv.Perm.sign σ • ∏ c, (X (σ c) : MvPolynomial (Fin n) ℤ) ^ m c := + Matrix.det_apply _ + rw [ha, Matrix.det_apply, Finset.mul_sum, coeff_sum] + apply Finset.sum_congr rfl + intro σ hσ + rw [mul_smul_comm, coeff_smul, perm_prod_monomial, coeff_complete_monomial hi, + assignment_product] + have ht : ∑ r, l r = (∑ r, m (σ.symm r)) + i*b := by + rw [Equiv.sum_comp σ.symm m] + exact htotal + simp only [exists_composition_iff hi l _ ht] + +theorem signed_strip_abs_le_one {n b i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) + (htotal : ∑ r, l r = (∑ r, m r) + i*b) : + Int.natAbs ((completePowers n i b * alternant m).coeff (expVector l)) ≤ 1 := by + rw [coefficient_eq_assignment_det hi l m htotal] + exact assignment_det_bound i l m + +end Foulkes.Strips + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/StripInterlace.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/StripInterlace.lean index cf00b266cf9e4b1fe13838ae4fb09a44ece676ed..738329a27ec23696305f0a3f47f4a0a2917dd03b 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/StripInterlace.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/StripInterlace.lean @@ -1,141 +1,141 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.StripCoefficient - -namespace OAI - -noncomputable section - -namespace Foulkes.Strips -open Matrix Finset Submodule - -lemma matching_of_det_ne_zero {n i : ℕ} (l m : Fin n → ℕ) - (hd : (incidence (assignments i l m)).det ≠ 0) : - ∃ σ : Equiv.Perm (Fin n), ∀ c, m c ≤ l (σ c) ∧ m c % i = l (σ c) % i := by - classical - rw [Matrix.det_apply] at hd - obtain ⟨σ, hσ, ht⟩ := Finset.exists_ne_zero_of_sum_ne_zero hd - have hp : (∏ c, incidence (assignments i l m) (σ c) c) ≠ 0 := by - intro hh - exact ht (by rw [hh, smul_zero]) - refine ⟨σ, fun c => ?_⟩ - have hc := (Finset.prod_ne_zero_iff.mp hp) c (mem_univ c) - simpa only [incidence, assignments, mem_filter, mem_univ, true_and, - ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hc - -lemma containment_of_det_ne_zero {n i : ℕ} (l m : Fin n → ℕ) - (hl : Antitone l) (hm : Antitone m) - (hd : (incidence (assignments i l m)).det ≠ 0) (j : Fin n) : m j ≤ l j := by - classical - obtain ⟨σ,hσ⟩ := matching_of_det_ne_zero l m hd - by_contra h - let e : Fin (j.val+1) → Fin n := fun c => ⟨c.val, by omega⟩ - have hrow (c : Fin (j.val+1)) : (σ (e c)).val < j.val := by - by_contra hh - have hm' : m j ≤ m (e c) := hm (by change c.val ≤ j.val; omega) - have hl' : l (σ (e c)) ≤ l j := hl (by change j.val ≤ (σ (e c)).val; omega) - have hc := (hσ (e c)).1 - omega - let f : Fin (j.val+1) → Fin j.val := fun c => ⟨(σ (e c)).val, hrow c⟩ - have hf : Function.Injective f := by - intro c d hcd - have hv : (σ (e c)).val = (σ (e d)).val := congrArg (fun z : Fin j.val => z.val) hcd - have hh : σ (e c) = σ (e d) := Fin.ext hv - have hc : c.val = d.val := congrArg (fun z : Fin n => z.val) (σ.injective hh) - exact Fin.ext hc - have hn := Fintype.card_le_of_injective f hf - simp only [Fintype.card_fin] at hn - omega - -lemma le_of_residue_eq_of_lt_add {i x y : ℕ} (_hi : 0 < i) - (hres : x % i = y % i) (hxy : x < y+i) : x ≤ y := by - by_contra h - have hyx : y < x := Nat.lt_of_not_ge h - have hd : i ∣ x-y := (Nat.modEq_iff_dvd' (Nat.le_of_lt hyx)).mp hres.symm - have hh := Nat.le_of_dvd (Nat.sub_pos_of_lt hyx) hd - omega - -lemma shifted_containment_of_det_ne_zero {n i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) - (hl : Antitone l) (hm : Antitone m) - (hd : (incidence (assignments i l m)).det ≠ 0) - (j : Fin n) (hji : j.val+i < n) : l ⟨j.val+i,hji⟩ + i ≤ m j := by - classical - by_contra h - have hjm : m j < l ⟨j.val+i,hji⟩ + i := Nat.lt_of_not_ge h - let A : Matrix (Fin n) (Fin n) ℚ := (incidence (assignments i l m)).map Int.cast - have hA : A.det ≠ 0 := by - rw [show A = (incidence (assignments i l m)).map Int.cast from rfl, ← Int.cast_det] - exact_mod_cast hd - have hind := Matrix.linearIndependent_rows_of_det_ne_zero hA - let embed : Fin (j.val+i+1) → Fin n := fun r => ⟨r.val, by omega⟩ - have hembed : Function.Injective embed := by - intro r s hrs - exact Fin.ext (congrArg (fun z : Fin n => z.val) hrs) - have hlin : LinearIndependent ℚ (fun r : Fin (j.val+i+1) => A (embed r)) := - hind.comp embed hembed - let gen : Fin j.val ⊕ Fin i → Fin n → ℚ := Sum.elim - (fun c => Pi.single (⟨c.val, by omega⟩ : Fin n) 1) - (fun u c => if j.val ≤ c.val ∧ m c % i = u.val then 1 else 0) - let U : Submodule ℚ (Fin n → ℚ) := Submodule.span ℚ (Set.range gen) - have hgen (q : Fin j.val ⊕ Fin i) : gen q ∈ U := - Submodule.subset_span ⟨q,rfl⟩ - have hrow (r : Fin (j.val+i+1)) : A (embed r) ∈ U := by - let u : Fin i := ⟨l (embed r) % i, Nat.mod_lt _ hi⟩ - have he : A (embed r) = - (∑ c : Fin j.val, A (embed r) ⟨c.val, by omega⟩ • gen (Sum.inl c)) + gen (Sum.inr u) := by - funext c - have hlr : l ⟨j.val+i,hji⟩ ≤ l (embed r) := hl (show embed r ≤ ⟨j.val+i,hji⟩ by - exact Nat.le_of_lt_succ r.isLt) - by_cases hc : c.val < j.val - · have hcc : (⟨c.val,hc⟩ : Fin j.val).val = c.val := rfl - simp only [Pi.add_apply, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] - have hsum : (∑ d : Fin j.val, A (embed r) ⟨d.val, by omega⟩ * gen (Sum.inl d) c) = - A (embed r) c := by - rw [Finset.sum_eq_single ⟨c.val,hc⟩] - · simp [gen] - · intro d hd hne - have hdc : (⟨d.val, by omega⟩ : Fin n) ≠ c := by - intro he - apply hne - exact Fin.ext (congrArg (fun z : Fin n => z.val) he) - simp [gen, Ne.symm hdc] - · simp - rw [hsum] - have hnc : ¬j ≤ c := by change ¬j.val ≤ c.val; omega - simp [gen, u, hnc] - · have hsum : (∑ d : Fin j.val, A (embed r) ⟨d.val, by omega⟩ • gen (Sum.inl d)) c = 0 := by - simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] - apply Finset.sum_eq_zero - intro d hd - have hdc : (⟨d.val, by omega⟩ : Fin n) ≠ c := by - intro he - have hv : d.val = c.val := congrArg (fun z : Fin n => z.val) he - have hdlt := d.isLt - omega - simp [gen, Ne.symm hdc] - rw [Pi.add_apply, hsum, zero_add] - have hmj : m c ≤ m j := hm (show j ≤ c by exact Nat.le_of_not_gt hc) - have hlt : m c < l (embed r)+i := by omega - have iffcond : (m c ≤ l (embed r) ∧ m c % i = l (embed r) % i) ↔ - m c % i = l (embed r) % i := - ⟨And.right, fun hr => ⟨le_of_residue_eq_of_lt_add hi hr hlt, hr⟩⟩ - simp only [A, Matrix.map_apply, incidence, assignments, mem_filter, mem_univ, true_and, - gen, Sum.elim_inr, u, Nat.le_of_not_gt hc, true_and] - simp only [iffcond, Int.cast_ite, Int.cast_one, Int.cast_zero] - rw [he] - exact U.add_mem (U.sum_mem (fun c hc => U.smul_mem _ (hgen (Sum.inl c)))) (hgen (Sum.inr u)) - have hsub : Submodule.span ℚ (Set.range (fun r : Fin (j.val+i+1) => A (embed r))) ≤ U := by - apply Submodule.span_le.mpr - rintro _ ⟨r,rfl⟩ - exact hrow r - have hdim := Submodule.finrank_mono hsub - have heq := finrank_span_eq_card hlin - have hbound : Module.finrank ℚ U ≤ j.val+i := by - simpa [U, Set.finrank] using (finrank_range_le_card (R := ℚ) gen) - rw [heq, Fintype.card_fin] at hdim - omega - -end Foulkes.Strips - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.StripCoefficient + +namespace OAI + +noncomputable section + +namespace Foulkes.Strips +open Matrix Finset Submodule + +lemma matching_of_det_ne_zero {n i : ℕ} (l m : Fin n → ℕ) + (hd : (incidence (assignments i l m)).det ≠ 0) : + ∃ σ : Equiv.Perm (Fin n), ∀ c, m c ≤ l (σ c) ∧ m c % i = l (σ c) % i := by + classical + rw [Matrix.det_apply] at hd + obtain ⟨σ, hσ, ht⟩ := Finset.exists_ne_zero_of_sum_ne_zero hd + have hp : (∏ c, incidence (assignments i l m) (σ c) c) ≠ 0 := by + intro hh + exact ht (by rw [hh, smul_zero]) + refine ⟨σ, fun c => ?_⟩ + have hc := (Finset.prod_ne_zero_iff.mp hp) c (mem_univ c) + simpa only [incidence, assignments, mem_filter, mem_univ, true_and, + ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hc + +lemma containment_of_det_ne_zero {n i : ℕ} (l m : Fin n → ℕ) + (hl : Antitone l) (hm : Antitone m) + (hd : (incidence (assignments i l m)).det ≠ 0) (j : Fin n) : m j ≤ l j := by + classical + obtain ⟨σ,hσ⟩ := matching_of_det_ne_zero l m hd + by_contra h + let e : Fin (j.val+1) → Fin n := fun c => ⟨c.val, by omega⟩ + have hrow (c : Fin (j.val+1)) : (σ (e c)).val < j.val := by + by_contra hh + have hm' : m j ≤ m (e c) := hm (by change c.val ≤ j.val; omega) + have hl' : l (σ (e c)) ≤ l j := hl (by change j.val ≤ (σ (e c)).val; omega) + have hc := (hσ (e c)).1 + omega + let f : Fin (j.val+1) → Fin j.val := fun c => ⟨(σ (e c)).val, hrow c⟩ + have hf : Function.Injective f := by + intro c d hcd + have hv : (σ (e c)).val = (σ (e d)).val := congrArg (fun z : Fin j.val => z.val) hcd + have hh : σ (e c) = σ (e d) := Fin.ext hv + have hc : c.val = d.val := congrArg (fun z : Fin n => z.val) (σ.injective hh) + exact Fin.ext hc + have hn := Fintype.card_le_of_injective f hf + simp only [Fintype.card_fin] at hn + omega + +lemma le_of_residue_eq_of_lt_add {i x y : ℕ} (_hi : 0 < i) + (hres : x % i = y % i) (hxy : x < y+i) : x ≤ y := by + by_contra h + have hyx : y < x := Nat.lt_of_not_ge h + have hd : i ∣ x-y := (Nat.modEq_iff_dvd' (Nat.le_of_lt hyx)).mp hres.symm + have hh := Nat.le_of_dvd (Nat.sub_pos_of_lt hyx) hd + omega + +lemma shifted_containment_of_det_ne_zero {n i : ℕ} (hi : 0 < i) (l m : Fin n → ℕ) + (hl : Antitone l) (hm : Antitone m) + (hd : (incidence (assignments i l m)).det ≠ 0) + (j : Fin n) (hji : j.val+i < n) : l ⟨j.val+i,hji⟩ + i ≤ m j := by + classical + by_contra h + have hjm : m j < l ⟨j.val+i,hji⟩ + i := Nat.lt_of_not_ge h + let A : Matrix (Fin n) (Fin n) ℚ := (incidence (assignments i l m)).map Int.cast + have hA : A.det ≠ 0 := by + rw [show A = (incidence (assignments i l m)).map Int.cast from rfl, ← Int.cast_det] + exact_mod_cast hd + have hind := Matrix.linearIndependent_rows_of_det_ne_zero hA + let embed : Fin (j.val+i+1) → Fin n := fun r => ⟨r.val, by omega⟩ + have hembed : Function.Injective embed := by + intro r s hrs + exact Fin.ext (congrArg (fun z : Fin n => z.val) hrs) + have hlin : LinearIndependent ℚ (fun r : Fin (j.val+i+1) => A (embed r)) := + hind.comp embed hembed + let gen : Fin j.val ⊕ Fin i → Fin n → ℚ := Sum.elim + (fun c => Pi.single (⟨c.val, by omega⟩ : Fin n) 1) + (fun u c => if j.val ≤ c.val ∧ m c % i = u.val then 1 else 0) + let U : Submodule ℚ (Fin n → ℚ) := Submodule.span ℚ (Set.range gen) + have hgen (q : Fin j.val ⊕ Fin i) : gen q ∈ U := + Submodule.subset_span ⟨q,rfl⟩ + have hrow (r : Fin (j.val+i+1)) : A (embed r) ∈ U := by + let u : Fin i := ⟨l (embed r) % i, Nat.mod_lt _ hi⟩ + have he : A (embed r) = + (∑ c : Fin j.val, A (embed r) ⟨c.val, by omega⟩ • gen (Sum.inl c)) + gen (Sum.inr u) := by + funext c + have hlr : l ⟨j.val+i,hji⟩ ≤ l (embed r) := hl (show embed r ≤ ⟨j.val+i,hji⟩ by + exact Nat.le_of_lt_succ r.isLt) + by_cases hc : c.val < j.val + · have hcc : (⟨c.val,hc⟩ : Fin j.val).val = c.val := rfl + simp only [Pi.add_apply, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + have hsum : (∑ d : Fin j.val, A (embed r) ⟨d.val, by omega⟩ * gen (Sum.inl d) c) = + A (embed r) c := by + rw [Finset.sum_eq_single ⟨c.val,hc⟩] + · simp [gen] + · intro d hd hne + have hdc : (⟨d.val, by omega⟩ : Fin n) ≠ c := by + intro he + apply hne + exact Fin.ext (congrArg (fun z : Fin n => z.val) he) + simp [gen, Ne.symm hdc] + · simp + rw [hsum] + have hnc : ¬j ≤ c := by change ¬j.val ≤ c.val; omega + simp [gen, u, hnc] + · have hsum : (∑ d : Fin j.val, A (embed r) ⟨d.val, by omega⟩ • gen (Sum.inl d)) c = 0 := by + simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + apply Finset.sum_eq_zero + intro d hd + have hdc : (⟨d.val, by omega⟩ : Fin n) ≠ c := by + intro he + have hv : d.val = c.val := congrArg (fun z : Fin n => z.val) he + have hdlt := d.isLt + omega + simp [gen, Ne.symm hdc] + rw [Pi.add_apply, hsum, zero_add] + have hmj : m c ≤ m j := hm (show j ≤ c by exact Nat.le_of_not_gt hc) + have hlt : m c < l (embed r)+i := by omega + have iffcond : (m c ≤ l (embed r) ∧ m c % i = l (embed r) % i) ↔ + m c % i = l (embed r) % i := + ⟨And.right, fun hr => ⟨le_of_residue_eq_of_lt_add hi hr hlt, hr⟩⟩ + simp only [A, Matrix.map_apply, incidence, assignments, mem_filter, mem_univ, true_and, + gen, Sum.elim_inr, u, Nat.le_of_not_gt hc, true_and] + simp only [iffcond, Int.cast_ite, Int.cast_one, Int.cast_zero] + rw [he] + exact U.add_mem (U.sum_mem (fun c hc => U.smul_mem _ (hgen (Sum.inl c)))) (hgen (Sum.inr u)) + have hsub : Submodule.span ℚ (Set.range (fun r : Fin (j.val+i+1) => A (embed r))) ≤ U := by + apply Submodule.span_le.mpr + rintro _ ⟨r,rfl⟩ + exact hrow r + have hdim := Submodule.finrank_mono hsub + have heq := finrank_span_eq_card hlin + have hbound : Module.finrank ℚ U ≤ j.val+i := by + simpa [U, Set.finrank] using (finrank_range_le_card (R := ℚ) gen) + rw [heq, Fintype.card_fin] at hdim + omega + +end Foulkes.Strips + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/StripSupport.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/StripSupport.lean index 78667767daa8da45f9a0eae40ea7e3f0d388125c..6e6ef61c8769d3a3c02c8a9b3f3cd8a93dbaa56b 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/StripSupport.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/StripSupport.lean @@ -1,106 +1,106 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Strips -open Finset Matrix - -def incidence {n : ℕ} (S : Fin n → Finset (Fin n)) : Matrix (Fin n) (Fin n) ℤ := - fun r c => if c ∈ S r then 1 else 0 - -def Laminar {n : ℕ} (S : Fin n → Finset (Fin n)) : Prop := - ∀ r s, S r ⊆ S s ∨ S s ⊆ S r ∨ Disjoint (S r) (S s) - -theorem incidence_det_bound (n : ℕ) (S : Fin n → Finset (Fin n)) (hS : Laminar S) : - Int.natAbs (incidence S).det ≤ 1 := by - classical - induction n with - | zero => simp - | succ n ih => - by_cases hd : (incidence S).det = 0 - · simp [hd] - have hnon (r : Fin (n+1)) : (S r).Nonempty := by - by_contra h - have he : S r = ∅ := Finset.not_nonempty_iff_eq_empty.mp h - apply hd - apply Matrix.det_eq_zero_of_row_eq_zero r - intro c - simp [incidence, he] - obtain ⟨r, hr, hmin⟩ := Finset.exists_min_image univ (fun r : Fin (n+1) => (S r).card) - (Finset.univ_nonempty) - have hcols {j k : Fin (n+1)} (hj : j ∈ S r) (hk : k ∈ S r) : j = k := by - by_contra hjk - apply hd - apply Matrix.det_zero_of_column_eq hjk - intro s - rcases hS r s with hrs | hsr | hdj - · simp [incidence, hrs hj, hrs hk] - · have he : S s = S r := Finset.eq_of_subset_of_card_le hsr (hmin s (mem_univ s)) - simp [incidence, he, hj, hk] - · have hj' : j ∉ S s := fun hs => Finset.disjoint_left.mp hdj hj hs - have hk' : k ∉ S s := fun hs => Finset.disjoint_left.mp hdj hk hs - simp [incidence, hj', hk'] - obtain ⟨c, hc⟩ := hnon r - have hrow : S r = {c} := by - ext j - simp only [mem_singleton] - exact ⟨fun hj => hcols hj hc, fun h => h ▸ hc⟩ - let S' : Fin n → Finset (Fin n) := fun i => univ.filter fun j => c.succAbove j ∈ S (r.succAbove i) - have hlam : Laminar S' := by - intro i j - rcases hS (r.succAbove i) (r.succAbove j) with hij | hji | hdj - · left - intro k hk - simpa [S'] using hij (by simpa [S'] using hk) - · right; left - intro k hk - simpa [S'] using hji (by simpa [S'] using hk) - · right; right - apply Finset.disjoint_left.mpr - intro k hi hj - exact Finset.disjoint_left.mp hdj (by simpa [S'] using hi) (by simpa [S'] using hj) - have hminor : (incidence S).submatrix r.succAbove c.succAbove = incidence S' := by - ext i j - simp [incidence, S'] - have he : (incidence S).det = (-1 : ℤ) ^ (r.val+c.val) * (incidence S').det := by - rw [Matrix.det_succ_row _ r] - simp only [incidence, hrow, mem_singleton] - simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul] - rw [Finset.sum_ite_eq' univ c] - simp only [mem_univ, ite_true, hminor] - rw [he, Int.natAbs_mul, Int.natAbs_pow] - simpa using ih S' hlam - -def assignments {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : Fin n → Finset (Fin n) := - fun r => univ.filter fun c => m c ≤ l r ∧ m c % i = l r % i - -lemma assignments_laminar {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : - Laminar (assignments i l m) := by - intro r s - by_cases he : l r % i = l s % i - · rcases le_total (l r) (l s) with hrs | hsr - · left - intro c hc - simp only [assignments, mem_filter, mem_univ, true_and] at hc ⊢ - exact ⟨hc.1.trans hrs, hc.2.trans he⟩ - · right; left - intro c hc - simp only [assignments, mem_filter, mem_univ, true_and] at hc ⊢ - exact ⟨hc.1.trans hsr, hc.2.trans he.symm⟩ - · right; right - apply Finset.disjoint_left.mpr - intro c hr hs - simp only [assignments, mem_filter, mem_univ, true_and] at hr hs - exact he (hr.2.symm.trans hs.2) - -theorem assignment_det_bound {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : - Int.natAbs (incidence (assignments i l m)).det ≤ 1 := - incidence_det_bound n _ (assignments_laminar i l m) - -end Foulkes.Strips - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Strips +open Finset Matrix + +def incidence {n : ℕ} (S : Fin n → Finset (Fin n)) : Matrix (Fin n) (Fin n) ℤ := + fun r c => if c ∈ S r then 1 else 0 + +def Laminar {n : ℕ} (S : Fin n → Finset (Fin n)) : Prop := + ∀ r s, S r ⊆ S s ∨ S s ⊆ S r ∨ Disjoint (S r) (S s) + +theorem incidence_det_bound (n : ℕ) (S : Fin n → Finset (Fin n)) (hS : Laminar S) : + Int.natAbs (incidence S).det ≤ 1 := by + classical + induction n with + | zero => simp + | succ n ih => + by_cases hd : (incidence S).det = 0 + · simp [hd] + have hnon (r : Fin (n+1)) : (S r).Nonempty := by + by_contra h + have he : S r = ∅ := Finset.not_nonempty_iff_eq_empty.mp h + apply hd + apply Matrix.det_eq_zero_of_row_eq_zero r + intro c + simp [incidence, he] + obtain ⟨r, hr, hmin⟩ := Finset.exists_min_image univ (fun r : Fin (n+1) => (S r).card) + (Finset.univ_nonempty) + have hcols {j k : Fin (n+1)} (hj : j ∈ S r) (hk : k ∈ S r) : j = k := by + by_contra hjk + apply hd + apply Matrix.det_zero_of_column_eq hjk + intro s + rcases hS r s with hrs | hsr | hdj + · simp [incidence, hrs hj, hrs hk] + · have he : S s = S r := Finset.eq_of_subset_of_card_le hsr (hmin s (mem_univ s)) + simp [incidence, he, hj, hk] + · have hj' : j ∉ S s := fun hs => Finset.disjoint_left.mp hdj hj hs + have hk' : k ∉ S s := fun hs => Finset.disjoint_left.mp hdj hk hs + simp [incidence, hj', hk'] + obtain ⟨c, hc⟩ := hnon r + have hrow : S r = {c} := by + ext j + simp only [mem_singleton] + exact ⟨fun hj => hcols hj hc, fun h => h ▸ hc⟩ + let S' : Fin n → Finset (Fin n) := fun i => univ.filter fun j => c.succAbove j ∈ S (r.succAbove i) + have hlam : Laminar S' := by + intro i j + rcases hS (r.succAbove i) (r.succAbove j) with hij | hji | hdj + · left + intro k hk + simpa [S'] using hij (by simpa [S'] using hk) + · right; left + intro k hk + simpa [S'] using hji (by simpa [S'] using hk) + · right; right + apply Finset.disjoint_left.mpr + intro k hi hj + exact Finset.disjoint_left.mp hdj (by simpa [S'] using hi) (by simpa [S'] using hj) + have hminor : (incidence S).submatrix r.succAbove c.succAbove = incidence S' := by + ext i j + simp [incidence, S'] + have he : (incidence S).det = (-1 : ℤ) ^ (r.val+c.val) * (incidence S').det := by + rw [Matrix.det_succ_row _ r] + simp only [incidence, hrow, mem_singleton] + simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul] + rw [Finset.sum_ite_eq' univ c] + simp only [mem_univ, ite_true, hminor] + rw [he, Int.natAbs_mul, Int.natAbs_pow] + simpa using ih S' hlam + +def assignments {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : Fin n → Finset (Fin n) := + fun r => univ.filter fun c => m c ≤ l r ∧ m c % i = l r % i + +lemma assignments_laminar {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : + Laminar (assignments i l m) := by + intro r s + by_cases he : l r % i = l s % i + · rcases le_total (l r) (l s) with hrs | hsr + · left + intro c hc + simp only [assignments, mem_filter, mem_univ, true_and] at hc ⊢ + exact ⟨hc.1.trans hrs, hc.2.trans he⟩ + · right; left + intro c hc + simp only [assignments, mem_filter, mem_univ, true_and] at hc ⊢ + exact ⟨hc.1.trans hsr, hc.2.trans he.symm⟩ + · right; right + apply Finset.disjoint_left.mpr + intro c hr hs + simp only [assignments, mem_filter, mem_univ, true_and] at hr hs + exact he (hr.2.symm.trans hs.2) + +theorem assignment_det_bound {n : ℕ} (i : ℕ) (l m : Fin n → ℕ) : + Int.natAbs (incidence (assignments i l m)).det ≤ 1 := + incidence_det_bound n _ (assignments_laminar i l m) + +end Foulkes.Strips + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SymDual.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SymDual.lean index bb480a22ac7375ab6f4470d28f14e5e7ab8dcec3..84e8642e5b5ec37514d52994f6ca3dac98aa16fc 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SymDual.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SymDual.lean @@ -1,120 +1,120 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.SymTensors - -namespace OAI - -noncomputable section - -namespace Foulkes.SymmetricTensor -universe u v -open scoped TensorProduct -open Module -variable (n : ℕ) {V : Type u} {W : Type v} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - -lemma pair_perm (σ : Equiv.Perm (Fin n)) (d : T n (Dual ℂ V)) (x : T n V) : - PiTensorProduct.dualDistrib (perm n (Dual ℂ V) σ d) x = - PiTensorProduct.dualDistrib d (perm n V σ.symm x) := by - have h : (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin n => V)).comp - (perm n (Dual ℂ V) σ).toLinearMap = - (perm n V σ.symm).toLinearMap.dualMap.comp PiTensorProduct.dualDistrib := by - ext f x - simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, perm, - PiTensorProduct.reindex_tprod, PiTensorProduct.dualDistrib_apply, - LinearMap.dualMap_apply, Equiv.symm_symm] - have hp := Equiv.prod_comp σ.symm (fun i => f i (x (σ i))) - convert hp using 1 - apply Finset.prod_congr rfl - intro i hi - rw [σ.apply_symm_apply] - exact DFunLike.congr_fun (DFunLike.congr_fun h d) x - -lemma pair_map (f : V →ₗ[ℂ] W) (d : T n (Dual ℂ W)) (x : T n V) : - PiTensorProduct.dualDistrib (PiTensorProduct.map (fun _ : Fin n => f.dualMap) d) x = - PiTensorProduct.dualDistrib d (PiTensorProduct.map (fun _ : Fin n => f) x) := by - have h : (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin n => V)).comp - (PiTensorProduct.map (fun _ : Fin n => f.dualMap)) = - (PiTensorProduct.map (fun _ : Fin n => f)).dualMap.comp PiTensorProduct.dualDistrib := by - ext d x - simp - exact DFunLike.congr_fun (DFunLike.congr_fun h d) x - -def pairing : Sym n (Dual ℂ V) →ₗ[ℂ] Dual ℂ (Sym n V) := - (symmetricTensors n V).subtype.dualMap.comp - (PiTensorProduct.dualDistrib.comp (symmetricTensors n (Dual ℂ V)).subtype) - -@[simp] lemma pairing_apply (d : Sym n (Dual ℂ V)) (x : Sym n V) : - pairing n d x = PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (x : T n V) := rfl - -@[simp] lemma pairing_power (d : Dual ℂ V) (v : V) : - pairing n (power n (Dual ℂ V) d) (power n V v) = d v ^ n := by - simp [pairing_apply, PiTensorProduct.dualDistrib_apply] - -lemma pairing_map (f : V →ₗ[ℂ] W) (d : Sym n (Dual ℂ W)) (x : Sym n V) : - pairing n (symMap n f.dualMap d) x = pairing n d (symMap n f x) := - pair_map n f d x - -variable [FiniteDimensional ℂ V] - -def pairingInv (l : Dual ℂ (Sym n V)) : Sym n (Dual ℂ V) := - ⟨PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V)), by - intro σ - apply PiTensorProduct.dualDistribEquiv.injective - apply LinearMap.ext - intro x - change PiTensorProduct.dualDistrib - (perm n (Dual ℂ V) σ (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V)))) x = - PiTensorProduct.dualDistrib - (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) x - rw [pair_perm] - change PiTensorProduct.dualDistribEquiv - (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) (perm n V σ.symm x) = - PiTensorProduct.dualDistribEquiv - (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) x - simp only [LinearEquiv.apply_symm_apply, LinearMap.comp_apply, project_perm]⟩ - -lemma pairing_pairingInv (l : Dual ℂ (Sym n V)) : pairing n (pairingInv n l) = l := by - ext x - change PiTensorProduct.dualDistribEquiv - (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) (x : T n V) = l x - rw [LinearEquiv.apply_symm_apply] - exact congrArg l (project_coe n V x) - -omit [FiniteDimensional ℂ V] in -lemma pair_project (d : Sym n (Dual ℂ V)) (x : T n V) : - pairing n d (project n V x) = PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x := by - have hinv (σ : Equiv.Perm (Fin n)) : - PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (perm n V σ x) = - PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x := by - have hh := pair_perm n σ.symm (d : T n (Dual ℂ V)) x - rw [show perm n (Dual ℂ V) σ.symm d = d from d.property σ.symm] at hh - simpa using hh.symm - change PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (average n V x) = _ - rw [average_apply, map_smul, map_sum] - simp only [hinv, Finset.sum_const, Finset.card_univ, Fintype.card_perm, Fintype.card_fin] - have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n - rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hn, one_smul] - -lemma pairing_injective : Function.Injective (pairing n (V := V)) := by - intro d e h - apply Subtype.ext - apply PiTensorProduct.dualDistribEquiv.injective - apply LinearMap.ext - intro x - have hh := DFunLike.congr_fun h (project n V x) - change PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x = - PiTensorProduct.dualDistrib (e : T n (Dual ℂ V)) x - simpa only [pair_project] using hh - -def dualEquiv : Sym n (Dual ℂ V) ≃ₗ[ℂ] Dual ℂ (Sym n V) := - LinearEquiv.ofBijective (pairing n) ⟨pairing_injective n, - fun l => ⟨pairingInv n l, pairing_pairingInv n l⟩⟩ - -@[simp] lemma dualEquiv_apply (d : Sym n (Dual ℂ V)) (x : Sym n V) : - dualEquiv n d x = pairing n d x := rfl - -end Foulkes.SymmetricTensor - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.SymTensors + +namespace OAI + +noncomputable section + +namespace Foulkes.SymmetricTensor +universe u v +open scoped TensorProduct +open Module +variable (n : ℕ) {V : Type u} {W : Type v} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + +lemma pair_perm (σ : Equiv.Perm (Fin n)) (d : T n (Dual ℂ V)) (x : T n V) : + PiTensorProduct.dualDistrib (perm n (Dual ℂ V) σ d) x = + PiTensorProduct.dualDistrib d (perm n V σ.symm x) := by + have h : (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin n => V)).comp + (perm n (Dual ℂ V) σ).toLinearMap = + (perm n V σ.symm).toLinearMap.dualMap.comp PiTensorProduct.dualDistrib := by + ext f x + simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, perm, + PiTensorProduct.reindex_tprod, PiTensorProduct.dualDistrib_apply, + LinearMap.dualMap_apply, Equiv.symm_symm] + have hp := Equiv.prod_comp σ.symm (fun i => f i (x (σ i))) + convert hp using 1 + apply Finset.prod_congr rfl + intro i hi + rw [σ.apply_symm_apply] + exact DFunLike.congr_fun (DFunLike.congr_fun h d) x + +lemma pair_map (f : V →ₗ[ℂ] W) (d : T n (Dual ℂ W)) (x : T n V) : + PiTensorProduct.dualDistrib (PiTensorProduct.map (fun _ : Fin n => f.dualMap) d) x = + PiTensorProduct.dualDistrib d (PiTensorProduct.map (fun _ : Fin n => f) x) := by + have h : (PiTensorProduct.dualDistrib (R := ℂ) (M := fun _ : Fin n => V)).comp + (PiTensorProduct.map (fun _ : Fin n => f.dualMap)) = + (PiTensorProduct.map (fun _ : Fin n => f)).dualMap.comp PiTensorProduct.dualDistrib := by + ext d x + simp + exact DFunLike.congr_fun (DFunLike.congr_fun h d) x + +def pairing : Sym n (Dual ℂ V) →ₗ[ℂ] Dual ℂ (Sym n V) := + (symmetricTensors n V).subtype.dualMap.comp + (PiTensorProduct.dualDistrib.comp (symmetricTensors n (Dual ℂ V)).subtype) + +@[simp] lemma pairing_apply (d : Sym n (Dual ℂ V)) (x : Sym n V) : + pairing n d x = PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (x : T n V) := rfl + +@[simp] lemma pairing_power (d : Dual ℂ V) (v : V) : + pairing n (power n (Dual ℂ V) d) (power n V v) = d v ^ n := by + simp [pairing_apply, PiTensorProduct.dualDistrib_apply] + +lemma pairing_map (f : V →ₗ[ℂ] W) (d : Sym n (Dual ℂ W)) (x : Sym n V) : + pairing n (symMap n f.dualMap d) x = pairing n d (symMap n f x) := + pair_map n f d x + +variable [FiniteDimensional ℂ V] + +def pairingInv (l : Dual ℂ (Sym n V)) : Sym n (Dual ℂ V) := + ⟨PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V)), by + intro σ + apply PiTensorProduct.dualDistribEquiv.injective + apply LinearMap.ext + intro x + change PiTensorProduct.dualDistrib + (perm n (Dual ℂ V) σ (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V)))) x = + PiTensorProduct.dualDistrib + (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) x + rw [pair_perm] + change PiTensorProduct.dualDistribEquiv + (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) (perm n V σ.symm x) = + PiTensorProduct.dualDistribEquiv + (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) x + simp only [LinearEquiv.apply_symm_apply, LinearMap.comp_apply, project_perm]⟩ + +lemma pairing_pairingInv (l : Dual ℂ (Sym n V)) : pairing n (pairingInv n l) = l := by + ext x + change PiTensorProduct.dualDistribEquiv + (PiTensorProduct.dualDistribEquiv.symm (l.comp (project n V))) (x : T n V) = l x + rw [LinearEquiv.apply_symm_apply] + exact congrArg l (project_coe n V x) + +omit [FiniteDimensional ℂ V] in +lemma pair_project (d : Sym n (Dual ℂ V)) (x : T n V) : + pairing n d (project n V x) = PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x := by + have hinv (σ : Equiv.Perm (Fin n)) : + PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (perm n V σ x) = + PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x := by + have hh := pair_perm n σ.symm (d : T n (Dual ℂ V)) x + rw [show perm n (Dual ℂ V) σ.symm d = d from d.property σ.symm] at hh + simpa using hh.symm + change PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) (average n V x) = _ + rw [average_apply, map_smul, map_sum] + simp only [hinv, Finset.sum_const, Finset.card_univ, Fintype.card_perm, Fintype.card_fin] + have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hn, one_smul] + +lemma pairing_injective : Function.Injective (pairing n (V := V)) := by + intro d e h + apply Subtype.ext + apply PiTensorProduct.dualDistribEquiv.injective + apply LinearMap.ext + intro x + have hh := DFunLike.congr_fun h (project n V x) + change PiTensorProduct.dualDistrib (d : T n (Dual ℂ V)) x = + PiTensorProduct.dualDistrib (e : T n (Dual ℂ V)) x + simpa only [pair_project] using hh + +def dualEquiv : Sym n (Dual ℂ V) ≃ₗ[ℂ] Dual ℂ (Sym n V) := + LinearEquiv.ofBijective (pairing n) ⟨pairing_injective n, + fun l => ⟨pairingInv n l, pairing_pairingInv n l⟩⟩ + +@[simp] lemma dualEquiv_apply (d : Sym n (Dual ℂ V)) (x : Sym n V) : + dualEquiv n d x = pairing n d x := rfl + +end Foulkes.SymmetricTensor + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SymOperations.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SymOperations.lean index 04566fbdd66060810ee0a8c50b28dac0bc11645e..db222369f20021b0b1ef3d6abd14cd6984583200 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SymOperations.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SymOperations.lean @@ -1,86 +1,86 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.SymDual - -namespace OAI - -noncomputable section - -namespace Foulkes -universe u v -open scoped TensorProduct -open SymmetricTensor - -variable {V : Type u} {W : Type v} [AddCommGroup V] [Module ℂ V] - [AddCommGroup W] [Module ℂ W] - -def symEquiv (n : ℕ) (e : V ≃ₗ[ℂ] W) : Sym n V ≃ₗ[ℂ] Sym n W := - LinearEquiv.ofLinearMap (symMap n e.toLinearMap) (symMap n e.symm.toLinearMap) - (by apply symMap_ext; intro v; simp) - (by apply symMap_ext; intro v; simp) - -@[simp] lemma symEquiv_apply (n : ℕ) (e : V ≃ₗ[ℂ] W) (x : Sym n V) : - symEquiv n e x = symMap n e.toLinearMap x := rfl - -namespace SymmetricTensor - -def oneEquiv (V : Type u) [AddCommGroup V] [Module ℂ V] : Sym 1 V ≃ₗ[ℂ] V := - LinearEquiv.ofBijective - ((PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0).toLinearMap.comp - (symmetricTensors 1 V).subtype) - ⟨(PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0).injective.comp - Subtype.val_injective, - fun v => ⟨power 1 V v, by simp [power]⟩⟩ - -@[simp] lemma oneEquiv_power (v : V) : oneEquiv V (power 1 V v) = v := by - change PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0 - (PiTensorProduct.tprod ℂ (fun _ : Fin 1 => v)) = v - simp - -@[simp] lemma oneEquiv_symm (v : V) : (oneEquiv V).symm v = power 1 V v := by - apply (oneEquiv V).injective - simp - -end SymmetricTensor - -namespace SymAlgebra -variable {A : Type*} [CommRing A] [Algebra ℂ A] - -def tensorMul (b : ℕ) (q : V →ₗ[ℂ] A) : T b V →ₗ[ℂ] A := - PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin b) A).compLinearMap (fun _ => q)) - -@[simp] lemma tensorMul_tprod (b : ℕ) (q : V →ₗ[ℂ] A) (v : Fin b → V) : - tensorMul b q (PiTensorProduct.tprod ℂ v) = ∏ i, q (v i) := by - simp [tensorMul] - -lemma tensorMul_perm (b : ℕ) (q : V →ₗ[ℂ] A) (σ : Equiv.Perm (Fin b)) (x : T b V) : - tensorMul b q (perm b V σ x) = tensorMul b q x := by - have h : (tensorMul b q).comp (perm b V σ).toLinearMap = tensorMul b q := by - apply PiTensorProduct.ext - apply MultilinearMap.ext - intro v - simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, - perm, PiTensorProduct.reindex_tprod, tensorMul_tprod] - exact Equiv.prod_comp σ.symm (fun i => q (v i)) - exact DFunLike.congr_fun h x - -def multiply (b : ℕ) (q : V →ₗ[ℂ] A) : Sym b V →ₗ[ℂ] A := - (tensorMul b q).comp (symmetricTensors b V).subtype - -@[simp] lemma multiply_power (b : ℕ) (q : V →ₗ[ℂ] A) (v : V) : - multiply b q (power b V v) = q v ^ b := by - simp [multiply, power] - -lemma multiply_project (b : ℕ) (q : V →ₗ[ℂ] A) (x : T b V) : - multiply b q (project b V x) = tensorMul b q x := by - change tensorMul b q (average b V x) = _ - simp only [average_apply, map_smul, map_sum, tensorMul_perm, Finset.sum_const, - Finset.card_univ, Fintype.card_perm, Fintype.card_fin] - have hb : (b.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero b - rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hb, one_smul] - -end SymAlgebra -end Foulkes - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.SymDual + +namespace OAI + +noncomputable section + +namespace Foulkes +universe u v +open scoped TensorProduct +open SymmetricTensor + +variable {V : Type u} {W : Type v} [AddCommGroup V] [Module ℂ V] + [AddCommGroup W] [Module ℂ W] + +def symEquiv (n : ℕ) (e : V ≃ₗ[ℂ] W) : Sym n V ≃ₗ[ℂ] Sym n W := + LinearEquiv.ofLinearMap (symMap n e.toLinearMap) (symMap n e.symm.toLinearMap) + (by apply symMap_ext; intro v; simp) + (by apply symMap_ext; intro v; simp) + +@[simp] lemma symEquiv_apply (n : ℕ) (e : V ≃ₗ[ℂ] W) (x : Sym n V) : + symEquiv n e x = symMap n e.toLinearMap x := rfl + +namespace SymmetricTensor + +def oneEquiv (V : Type u) [AddCommGroup V] [Module ℂ V] : Sym 1 V ≃ₗ[ℂ] V := + LinearEquiv.ofBijective + ((PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0).toLinearMap.comp + (symmetricTensors 1 V).subtype) + ⟨(PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0).injective.comp + Subtype.val_injective, + fun v => ⟨power 1 V v, by simp [power]⟩⟩ + +@[simp] lemma oneEquiv_power (v : V) : oneEquiv V (power 1 V v) = v := by + change PiTensorProduct.subsingletonEquiv (R := ℂ) (s := fun _ : Fin 1 => V) 0 + (PiTensorProduct.tprod ℂ (fun _ : Fin 1 => v)) = v + simp + +@[simp] lemma oneEquiv_symm (v : V) : (oneEquiv V).symm v = power 1 V v := by + apply (oneEquiv V).injective + simp + +end SymmetricTensor + +namespace SymAlgebra +variable {A : Type*} [CommRing A] [Algebra ℂ A] + +def tensorMul (b : ℕ) (q : V →ₗ[ℂ] A) : T b V →ₗ[ℂ] A := + PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin b) A).compLinearMap (fun _ => q)) + +@[simp] lemma tensorMul_tprod (b : ℕ) (q : V →ₗ[ℂ] A) (v : Fin b → V) : + tensorMul b q (PiTensorProduct.tprod ℂ v) = ∏ i, q (v i) := by + simp [tensorMul] + +lemma tensorMul_perm (b : ℕ) (q : V →ₗ[ℂ] A) (σ : Equiv.Perm (Fin b)) (x : T b V) : + tensorMul b q (perm b V σ x) = tensorMul b q x := by + have h : (tensorMul b q).comp (perm b V σ).toLinearMap = tensorMul b q := by + apply PiTensorProduct.ext + apply MultilinearMap.ext + intro v + simp only [LinearMap.compMultilinearMap_apply, LinearMap.comp_apply, LinearEquiv.coe_coe, + perm, PiTensorProduct.reindex_tprod, tensorMul_tprod] + exact Equiv.prod_comp σ.symm (fun i => q (v i)) + exact DFunLike.congr_fun h x + +def multiply (b : ℕ) (q : V →ₗ[ℂ] A) : Sym b V →ₗ[ℂ] A := + (tensorMul b q).comp (symmetricTensors b V).subtype + +@[simp] lemma multiply_power (b : ℕ) (q : V →ₗ[ℂ] A) (v : V) : + multiply b q (power b V v) = q v ^ b := by + simp [multiply, power] + +lemma multiply_project (b : ℕ) (q : V →ₗ[ℂ] A) (x : T b V) : + multiply b q (project b V x) = tensorMul b q x := by + change tensorMul b q (average b V x) = _ + simp only [average_apply, map_smul, map_sum, tensorMul_perm, Finset.sum_const, + Finset.card_univ, Fintype.card_perm, Fintype.card_fin] + have hb : (b.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero b + rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hb, one_smul] + +end SymAlgebra +end Foulkes + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SymPolynomial.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SymPolynomial.lean index 93369db7622ba32769790e3f3e2d744f472bbaa4..77a053dff71eb07bde0394a0b9819ddda6c57760 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SymPolynomial.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SymPolynomial.lean @@ -1,101 +1,101 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan -import OAI.RepresentationTheory.FoulkesSixth.SymDual - -namespace OAI - -noncomputable section - -namespace Foulkes.SymPolynomial -universe u -open Module MvPolynomial SymmetricTensor -variable {V : Type u} [AddCommGroup V] [Module ℂ V] -variable {n : ℕ} (B : Basis (Fin n) ℂ V) (b : ℕ) - -abbrev Poly (n : ℕ) := MvPolynomial (Fin n) ℂ -abbrev H (n b : ℕ) := homogeneousSubmodule (Fin n) ℂ b - -def linearPolynomial : V →ₗ[ℂ] Poly n where - toFun v := ∑ i, B.equivFun v i • X i - map_add' v w := by simp [add_smul, Finset.sum_add_distrib] - map_smul' c v := by simp [smul_smul, Finset.smul_sum] - -@[simp] lemma linearPolynomial_apply (v : V) : - linearPolynomial B v = ∑ i, B.equivFun v i • X i := rfl - -lemma eval_linearPolynomial (x : Fin n → ℂ) (v : V) : - eval x (linearPolynomial B v) = B.constr ℂ x v := by - have h : B.constr ℂ x v = ∑ i, B.equivFun v i * x i := by - conv_lhs => rw [← B.sum_equivFun v] - simp - rw [h] - simp [linearPolynomial, MvPolynomial.smul_eq_C_mul] - -def tensorPolynomial : T b V →ₗ[ℂ] Poly n := - PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin b) (Poly n)).compLinearMap - (fun _ => linearPolynomial B)) - -@[simp] lemma tensorPolynomial_tprod (v : Fin b → V) : - tensorPolynomial B b (PiTensorProduct.tprod ℂ v) = ∏ i, linearPolynomial B (v i) := by - simp [tensorPolynomial] - -def polynomial : Sym b V →ₗ[ℂ] Poly n := - (tensorPolynomial B b).comp (symmetricTensors b V).subtype - -@[simp] lemma polynomial_power (v : V) : - polynomial B b (power b V v) = linearPolynomial B v ^ b := by - simp [polynomial, power] - -lemma polynomial_eval (x : Fin n → ℂ) (v : Sym b V) : - eval x (polynomial B b v) = pairing b (power b (Dual ℂ V) (B.constr ℂ x)) v := by - have hh : (aeval x).toLinearMap.comp (polynomial B b) = - pairing b (power b (Dual ℂ V) (B.constr ℂ x)) := by - apply symMap_ext - intro v - change eval x (polynomial B b (power b V v)) = _ - rw [polynomial_power, eval_pow, eval_linearPolynomial, pairing_power] - exact DFunLike.congr_fun hh v - -variable [FiniteDimensional ℂ V] - -lemma polynomial_injective : Function.Injective (polynomial B b) := by - apply (LinearMap.ker_eq_bot).mp - apply (LinearMap.ker_eq_bot').mpr - intro v hv - apply (Module.forall_dual_apply_eq_zero_iff ℂ v).mp - intro l - have hp : (pairing b (V := V)).flip v = 0 := by - apply symMap_ext - intro d - obtain ⟨x, rfl⟩ := (B.constr ℂ).surjective d - change pairing b (power b (Dual ℂ V) (B.constr ℂ x)) v = 0 - rw [← polynomial_eval, hv, map_zero] - have hh := DFunLike.congr_fun hp ((dualEquiv b (V := V)).symm l) - change dualEquiv b ((dualEquiv b (V := V)).symm l) v = 0 at hh - rwa [LinearEquiv.apply_symm_apply] at hh - -omit [FiniteDimensional ℂ V] in -lemma polynomial_range : (polynomial B b).range = H n b := by - change (polynomial B b).range = homogeneousSubmodule (Fin n) ℂ b - rw [← Submodule.map_top, ← span_power b V, LinearMap.map_span, - PolynomialSpan.homogeneous_eq_span_powers] - congr 1 - ext p - constructor - · rintro ⟨_, ⟨v, rfl⟩, rfl⟩ - exact ⟨B.equivFun v, (polynomial_power B b v).symm⟩ - · rintro ⟨x, rfl⟩ - refine ⟨power b V (B.equivFun.symm x), ⟨_, rfl⟩, ?_⟩ - simp - -def equiv : Sym b V ≃ₗ[ℂ] H n b := - (LinearEquiv.ofInjective (polynomial B b) (polynomial_injective B b)).trans - (LinearEquiv.ofEq _ _ (polynomial_range B b)) - -@[simp] lemma equiv_coe (v : Sym b V) : (equiv B b v : Poly n) = polynomial B b v := rfl - -end Foulkes.SymPolynomial - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.PolynomialSpan +import OAI.RepresentationTheory.FoulkesSixth.SymDual + +namespace OAI + +noncomputable section + +namespace Foulkes.SymPolynomial +universe u +open Module MvPolynomial SymmetricTensor +variable {V : Type u} [AddCommGroup V] [Module ℂ V] +variable {n : ℕ} (B : Basis (Fin n) ℂ V) (b : ℕ) + +abbrev Poly (n : ℕ) := MvPolynomial (Fin n) ℂ +abbrev H (n b : ℕ) := homogeneousSubmodule (Fin n) ℂ b + +def linearPolynomial : V →ₗ[ℂ] Poly n where + toFun v := ∑ i, B.equivFun v i • X i + map_add' v w := by simp [add_smul, Finset.sum_add_distrib] + map_smul' c v := by simp [smul_smul, Finset.smul_sum] + +@[simp] lemma linearPolynomial_apply (v : V) : + linearPolynomial B v = ∑ i, B.equivFun v i • X i := rfl + +lemma eval_linearPolynomial (x : Fin n → ℂ) (v : V) : + eval x (linearPolynomial B v) = B.constr ℂ x v := by + have h : B.constr ℂ x v = ∑ i, B.equivFun v i * x i := by + conv_lhs => rw [← B.sum_equivFun v] + simp + rw [h] + simp [linearPolynomial, MvPolynomial.smul_eq_C_mul] + +def tensorPolynomial : T b V →ₗ[ℂ] Poly n := + PiTensorProduct.lift ((MultilinearMap.mkPiAlgebra ℂ (Fin b) (Poly n)).compLinearMap + (fun _ => linearPolynomial B)) + +@[simp] lemma tensorPolynomial_tprod (v : Fin b → V) : + tensorPolynomial B b (PiTensorProduct.tprod ℂ v) = ∏ i, linearPolynomial B (v i) := by + simp [tensorPolynomial] + +def polynomial : Sym b V →ₗ[ℂ] Poly n := + (tensorPolynomial B b).comp (symmetricTensors b V).subtype + +@[simp] lemma polynomial_power (v : V) : + polynomial B b (power b V v) = linearPolynomial B v ^ b := by + simp [polynomial, power] + +lemma polynomial_eval (x : Fin n → ℂ) (v : Sym b V) : + eval x (polynomial B b v) = pairing b (power b (Dual ℂ V) (B.constr ℂ x)) v := by + have hh : (aeval x).toLinearMap.comp (polynomial B b) = + pairing b (power b (Dual ℂ V) (B.constr ℂ x)) := by + apply symMap_ext + intro v + change eval x (polynomial B b (power b V v)) = _ + rw [polynomial_power, eval_pow, eval_linearPolynomial, pairing_power] + exact DFunLike.congr_fun hh v + +variable [FiniteDimensional ℂ V] + +lemma polynomial_injective : Function.Injective (polynomial B b) := by + apply (LinearMap.ker_eq_bot).mp + apply (LinearMap.ker_eq_bot').mpr + intro v hv + apply (Module.forall_dual_apply_eq_zero_iff ℂ v).mp + intro l + have hp : (pairing b (V := V)).flip v = 0 := by + apply symMap_ext + intro d + obtain ⟨x, rfl⟩ := (B.constr ℂ).surjective d + change pairing b (power b (Dual ℂ V) (B.constr ℂ x)) v = 0 + rw [← polynomial_eval, hv, map_zero] + have hh := DFunLike.congr_fun hp ((dualEquiv b (V := V)).symm l) + change dualEquiv b ((dualEquiv b (V := V)).symm l) v = 0 at hh + rwa [LinearEquiv.apply_symm_apply] at hh + +omit [FiniteDimensional ℂ V] in +lemma polynomial_range : (polynomial B b).range = H n b := by + change (polynomial B b).range = homogeneousSubmodule (Fin n) ℂ b + rw [← Submodule.map_top, ← span_power b V, LinearMap.map_span, + PolynomialSpan.homogeneous_eq_span_powers] + congr 1 + ext p + constructor + · rintro ⟨_, ⟨v, rfl⟩, rfl⟩ + exact ⟨B.equivFun v, (polynomial_power B b v).symm⟩ + · rintro ⟨x, rfl⟩ + refine ⟨power b V (B.equivFun.symm x), ⟨_, rfl⟩, ?_⟩ + simp + +def equiv : Sym b V ≃ₗ[ℂ] H n b := + (LinearEquiv.ofInjective (polynomial B b) (polynomial_injective B b)).trans + (LinearEquiv.ofEq _ _ (polynomial_range B b)) + +@[simp] lemma equiv_coe (v : Sym b V) : (equiv B b v : Poly n) = polynomial B b v := rfl + +end Foulkes.SymPolynomial + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/SymTensors.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/SymTensors.lean index c0ffb69f50c1d45322f57a5e48d6c2a95b009a70..4102c7a1dc48ca9e8d4f33182a7943f123a0b5a8 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/SymTensors.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/SymTensors.lean @@ -1,153 +1,153 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.Diagonal - -namespace OAI - -noncomputable section - -open scoped TensorProduct -namespace Foulkes -universe u v w - -def symmetricTensors (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - Submodule ℂ (⨂[ℂ] (_ : Fin n), V) where - carrier := {x | ∀ σ : Equiv.Perm (Fin n), - PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ x = x} - zero_mem' := by intro σ; simp - add_mem' := by intro x y hx hy σ; simp only [map_add, hx σ, hy σ] - smul_mem' := by intro c x hx σ; simp only [map_smul, hx σ] - -abbrev Sym (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] := - symmetricTensors n V - -def symMap (n : ℕ) {V : Type u} {W : Type v} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (f : V →ₗ[ℂ] W) : Sym n V →ₗ[ℂ] Sym n W := - (PiTensorProduct.map (fun _ : Fin n => f)).restrict fun x hx σ => by - rw [← PiTensorProduct.map_reindex] - rw [hx σ] - -namespace SymmetricTensor - -variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] - -abbrev T := ⨂[ℂ] (_ : Fin n), V - -def perm (σ : Equiv.Perm (Fin n)) : T n V ≃ₗ[ℂ] T n V := - PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ - -lemma perm_mul (σ τ : Equiv.Perm (Fin n)) (x : T n V) : - perm n V σ (perm n V τ x) = perm n V (σ * τ) x := by - exact PiTensorProduct.reindex_reindex _ _ _ - -def average : T n V →ₗ[ℂ] T n V := - (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), (perm n V σ).toLinearMap - -lemma average_apply (x : T n V) : - average n V x = (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), perm n V σ x := by - simp [average] - -lemma average_invariant (x : T n V) : average n V x ∈ Sym n V := by - intro τ - change perm n V τ (average n V x) = average n V x - simp only [average_apply, map_smul, map_sum, perm_mul] - congr 1 - exact Equiv.sum_comp (Equiv.mulLeft τ) (fun σ => perm n V σ x) - -lemma average_perm (σ : Equiv.Perm (Fin n)) (x : T n V) : - average n V (perm n V σ x) = average n V x := by - simp only [average_apply, perm_mul] - congr 1 - exact Equiv.sum_comp (Equiv.mulRight σ) (fun τ => perm n V τ x) - -lemma average_eq {x : T n V} (hx : x ∈ Sym n V) : average n V x = x := by - change ∀ σ : Equiv.Perm (Fin n), perm n V σ x = x at hx - have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n - simp only [average_apply, hx, Finset.sum_const, Finset.card_univ, - Fintype.card_perm, Fintype.card_fin] - rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hn, one_smul] - -def project : T n V →ₗ[ℂ] Sym n V := - (average n V).codRestrict _ (average_invariant n V) - -@[simp] lemma project_coe (x : Sym n V) : project n V x = x := by - apply Subtype.ext - exact average_eq n V x.property - -@[simp] lemma project_perm (σ : Equiv.Perm (Fin n)) (x : T n V) : - project n V (perm n V σ x) = project n V x := by - apply Subtype.ext - exact average_perm n V σ x - -def power (v : V) : Sym n V := - ⟨PiTensorProduct.tprod ℂ (fun _ : Fin n => v), by intro σ; simp⟩ - -@[simp] lemma coe_power (v : V) : - (power n V v : T n V) = PiTensorProduct.tprod ℂ (fun _ : Fin n => v) := rfl - -@[simp] lemma project_power (v : V) : - project n V (PiTensorProduct.tprod ℂ (fun _ : Fin n => v)) = power n V v := - project_coe n V (power n V v) - -theorem span_power : Submodule.span ℂ (Set.range (power n V)) = ⊤ := by - apply top_unique - intro x hx - by_contra hnot - obtain ⟨l, hne, hl⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance - have hlpower (v : V) : l (power n V v) = 0 := by - have hh : l (power n V v) ∈ (Submodule.span ℂ (Set.range (power n V))).map l := - Submodule.mem_map.mpr ⟨_, Submodule.subset_span ⟨v, rfl⟩, rfl⟩ - rwa [hl, Submodule.mem_bot] at hh - let F : MultilinearMap ℂ (fun _ : Fin n => V) ℂ := - (l.comp (project n V)).compMultilinearMap (PiTensorProduct.tprod ℂ) - have hF : F = 0 := by - apply Diagonal.eq_zero_of_symmetric_of_diagonal - · intro σ v - change l (project n V (PiTensorProduct.tprod ℂ (fun i => v (σ i)))) = - l (project n V (PiTensorProduct.tprod ℂ v)) - simpa [perm] using congrArg l - (project_perm n V σ.symm (PiTensorProduct.tprod ℂ v)) - · intro v - change l (project n V (PiTensorProduct.tprod ℂ (fun _ : Fin n => v))) = 0 - rw [project_power, hlpower] - have hlin : l.comp (project n V) = 0 := by - apply PiTensorProduct.ext - exact hF - exact hne (by have hh := DFunLike.congr_fun hlin (x : T n V); simpa using hh) - -end SymmetricTensor - -@[simp] lemma symMap_power (n : ℕ) {V : Type u} {W : Type v} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - (f : V →ₗ[ℂ] W) (v : V) : - symMap n f (SymmetricTensor.power n V v) = SymmetricTensor.power n W (f v) := by - apply Subtype.ext - exact PiTensorProduct.map_tprod _ _ - -lemma symMap_ext (n : ℕ) {V : Type u} {W : Type v} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - {f g : Sym n V →ₗ[ℂ] W} - (h : ∀ v : V, f (SymmetricTensor.power n V v) = g (SymmetricTensor.power n V v)) : f = g := by - apply (Submodule.linearMap_eq_iff_of_span_eq_top _ _ (SymmetricTensor.span_power n V)).mpr - rintro ⟨_, ⟨v, rfl⟩⟩ - exact h v - -@[simp] lemma symMap_comp (n : ℕ) {V : Type u} {W : Type v} {U : Type w} - [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] - [AddCommGroup U] [Module ℂ U] (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : - symMap n (g.comp f) = (symMap n g).comp (symMap n f) := by - apply symMap_ext - intro v - simp - -@[simp] lemma symMap_id (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : - symMap n (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by - apply symMap_ext - intro v - simp - -end Foulkes - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.Diagonal + +namespace OAI + +noncomputable section + +open scoped TensorProduct +namespace Foulkes +universe u v w + +def symmetricTensors (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + Submodule ℂ (⨂[ℂ] (_ : Fin n), V) where + carrier := {x | ∀ σ : Equiv.Perm (Fin n), + PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ x = x} + zero_mem' := by intro σ; simp + add_mem' := by intro x y hx hy σ; simp only [map_add, hx σ, hy σ] + smul_mem' := by intro c x hx σ; simp only [map_smul, hx σ] + +abbrev Sym (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] := + symmetricTensors n V + +def symMap (n : ℕ) {V : Type u} {W : Type v} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (f : V →ₗ[ℂ] W) : Sym n V →ₗ[ℂ] Sym n W := + (PiTensorProduct.map (fun _ : Fin n => f)).restrict fun x hx σ => by + rw [← PiTensorProduct.map_reindex] + rw [hx σ] + +namespace SymmetricTensor + +variable (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] + +abbrev T := ⨂[ℂ] (_ : Fin n), V + +def perm (σ : Equiv.Perm (Fin n)) : T n V ≃ₗ[ℂ] T n V := + PiTensorProduct.reindex ℂ (fun _ : Fin n => V) σ + +lemma perm_mul (σ τ : Equiv.Perm (Fin n)) (x : T n V) : + perm n V σ (perm n V τ x) = perm n V (σ * τ) x := by + exact PiTensorProduct.reindex_reindex _ _ _ + +def average : T n V →ₗ[ℂ] T n V := + (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), (perm n V σ).toLinearMap + +lemma average_apply (x : T n V) : + average n V x = (n.factorial : ℂ)⁻¹ • ∑ σ : Equiv.Perm (Fin n), perm n V σ x := by + simp [average] + +lemma average_invariant (x : T n V) : average n V x ∈ Sym n V := by + intro τ + change perm n V τ (average n V x) = average n V x + simp only [average_apply, map_smul, map_sum, perm_mul] + congr 1 + exact Equiv.sum_comp (Equiv.mulLeft τ) (fun σ => perm n V σ x) + +lemma average_perm (σ : Equiv.Perm (Fin n)) (x : T n V) : + average n V (perm n V σ x) = average n V x := by + simp only [average_apply, perm_mul] + congr 1 + exact Equiv.sum_comp (Equiv.mulRight σ) (fun τ => perm n V τ x) + +lemma average_eq {x : T n V} (hx : x ∈ Sym n V) : average n V x = x := by + change ∀ σ : Equiv.Perm (Fin n), perm n V σ x = x at hx + have hn : (n.factorial : ℂ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + simp only [average_apply, hx, Finset.sum_const, Finset.card_univ, + Fintype.card_perm, Fintype.card_fin] + rw [← Nat.cast_smul_eq_nsmul ℂ, smul_smul, inv_mul_cancel₀ hn, one_smul] + +def project : T n V →ₗ[ℂ] Sym n V := + (average n V).codRestrict _ (average_invariant n V) + +@[simp] lemma project_coe (x : Sym n V) : project n V x = x := by + apply Subtype.ext + exact average_eq n V x.property + +@[simp] lemma project_perm (σ : Equiv.Perm (Fin n)) (x : T n V) : + project n V (perm n V σ x) = project n V x := by + apply Subtype.ext + exact average_perm n V σ x + +def power (v : V) : Sym n V := + ⟨PiTensorProduct.tprod ℂ (fun _ : Fin n => v), by intro σ; simp⟩ + +@[simp] lemma coe_power (v : V) : + (power n V v : T n V) = PiTensorProduct.tprod ℂ (fun _ : Fin n => v) := rfl + +@[simp] lemma project_power (v : V) : + project n V (PiTensorProduct.tprod ℂ (fun _ : Fin n => v)) = power n V v := + project_coe n V (power n V v) + +theorem span_power : Submodule.span ℂ (Set.range (power n V)) = ⊤ := by + apply top_unique + intro x hx + by_contra hnot + obtain ⟨l, hne, hl⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance + have hlpower (v : V) : l (power n V v) = 0 := by + have hh : l (power n V v) ∈ (Submodule.span ℂ (Set.range (power n V))).map l := + Submodule.mem_map.mpr ⟨_, Submodule.subset_span ⟨v, rfl⟩, rfl⟩ + rwa [hl, Submodule.mem_bot] at hh + let F : MultilinearMap ℂ (fun _ : Fin n => V) ℂ := + (l.comp (project n V)).compMultilinearMap (PiTensorProduct.tprod ℂ) + have hF : F = 0 := by + apply Diagonal.eq_zero_of_symmetric_of_diagonal + · intro σ v + change l (project n V (PiTensorProduct.tprod ℂ (fun i => v (σ i)))) = + l (project n V (PiTensorProduct.tprod ℂ v)) + simpa [perm] using congrArg l + (project_perm n V σ.symm (PiTensorProduct.tprod ℂ v)) + · intro v + change l (project n V (PiTensorProduct.tprod ℂ (fun _ : Fin n => v))) = 0 + rw [project_power, hlpower] + have hlin : l.comp (project n V) = 0 := by + apply PiTensorProduct.ext + exact hF + exact hne (by have hh := DFunLike.congr_fun hlin (x : T n V); simpa using hh) + +end SymmetricTensor + +@[simp] lemma symMap_power (n : ℕ) {V : Type u} {W : Type v} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + (f : V →ₗ[ℂ] W) (v : V) : + symMap n f (SymmetricTensor.power n V v) = SymmetricTensor.power n W (f v) := by + apply Subtype.ext + exact PiTensorProduct.map_tprod _ _ + +lemma symMap_ext (n : ℕ) {V : Type u} {W : Type v} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + {f g : Sym n V →ₗ[ℂ] W} + (h : ∀ v : V, f (SymmetricTensor.power n V v) = g (SymmetricTensor.power n V v)) : f = g := by + apply (Submodule.linearMap_eq_iff_of_span_eq_top _ _ (SymmetricTensor.span_power n V)).mpr + rintro ⟨_, ⟨v, rfl⟩⟩ + exact h v + +@[simp] lemma symMap_comp (n : ℕ) {V : Type u} {W : Type v} {U : Type w} + [AddCommGroup V] [Module ℂ V] [AddCommGroup W] [Module ℂ W] + [AddCommGroup U] [Module ℂ U] (g : W →ₗ[ℂ] U) (f : V →ₗ[ℂ] W) : + symMap n (g.comp f) = (symMap n g).comp (symMap n f) := by + apply symMap_ext + intro v + simp + +@[simp] lemma symMap_id (n : ℕ) (V : Type u) [AddCommGroup V] [Module ℂ V] : + symMap n (LinearMap.id : V →ₗ[ℂ] V) = LinearMap.id := by + apply symMap_ext + intro v + simp + +end Foulkes + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/TensorPolarization.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/TensorPolarization.lean index b5b5ebd062dffdc5011effd2a65a8020645e52e2..68bd0ad75eb8bec768c97bdca91f4fba59928e35 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/TensorPolarization.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/TensorPolarization.lean @@ -1,201 +1,201 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.Differential -import OAI.RepresentationTheory.FoulkesSixth.GenericShift - -namespace OAI - -noncomputable section - -namespace Foulkes.Polarization -open MvPolynomial -open Foulkes.PolynomialSpan - -abbrev P (a n : ℕ) := MvPolynomial (Fin a × Fin n) ℂ - -def weight (a n : ℕ) (ij : Fin a × Fin n) : Fin a → ℕ := Pi.single ij.1 1 - -def W (a n j : ℕ) : Submodule ℂ (P a n) := - weightedHomogeneousSubmodule ℂ (weight a n) (fun _ => j) - -def rowForm {a n : ℕ} (i : Fin a) (x : Fin n → ℂ) : P a n := - ∑ k, x k • X (i, k) - -def pureRows {a n : ℕ} (j : ℕ) (x : Fin a → Fin n → ℂ) : P a n := - ∏ i, (rowForm i (x i)) ^ j - -lemma weight_apply_row {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) : - Finsupp.weight (weight a n) d i = ∑ k, d (i, k) := by - classical - rw [Finsupp.weight_eq_sum] - simp only [weight, Finset.sum_apply, Fintype.sum_prod_type, Pi.smul_apply, - Pi.single_apply, smul_eq_mul, mul_ite, mul_one, mul_zero] - rw [Finset.sum_comm] - simp - -lemma pureRows_mem {a n j : ℕ} (x : Fin a → Fin n → ℂ) : - pureRows j x ∈ W a n j := by - classical - have hrow (i : Fin a) : (rowForm i (x i)).IsWeightedHomogeneous - (weight a n) (Pi.single i 1) := by - apply MvPolynomial.IsWeightedHomogeneous.sum - intro k _ - exact (weightedHomogeneousSubmodule ℂ (weight a n) (Pi.single i 1)).smul_mem _ - (isWeightedHomogeneous_X (R := ℂ) (weight a n) (i, k)) - have hprod := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ - (fun i => (rowForm i (x i)) ^ j) (fun i => j • Pi.single i 1) - (fun i _ => (hrow i).pow j) - have hdeg : (∑ i : Fin a, j • (Pi.single i 1 : Fin a → ℕ)) = fun _ => j := by - ext r - simp [Pi.single_apply] - rw [hdeg] at hprod - exact hprod - -theorem W_eq_span_pureRows (a n j : ℕ) : - W a n j = Submodule.span ℂ (Set.range (pureRows (a := a) (n := n) j)) := by - classical - apply le_antisymm - · intro p hp - induction hp using MvPolynomial.IsWeightedHomogeneous.induction_on with - | zero => exact Submodule.zero_mem _ - | add p q hp hq ihp ihq => exact Submodule.add_mem _ ihp ihq - | monomial d c hd => - have hdrow (i : Fin a) : ∑ k, d (i, k) = j := by - simpa [weight_apply_row] using congrFun hd i - have hx (i : Fin a) : (∏ k : Fin n, (X (i, k) : P a n) ^ d (i, k)) ∈ - Submodule.span ℂ (Set.range fun x : Fin n → ℂ => (rowForm i x) ^ j) := by - let e : Fin n →₀ ℕ := Finsupp.equivFunOnFinite.symm (fun k => d (i, k)) - have he : e.sum (fun _ v => v) = j := by - rw [Finsupp.sum_fintype _ _ (by simp)] - exact hdrow i - have hh := prod_pow_mem_span_powers (fun k => (X (i, k) : P a n)) e j he - rw [Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] at hh - simpa [e, rowForm] using hh - have hprod := prod_mem_span_range (fun i (x : Fin n → ℂ) => (rowForm i x) ^ j) hx - have hm : (monomial d c : P a n) = c • ∏ i : Fin a, ∏ k : Fin n, - (X (i, k) : P a n) ^ d (i, k) := by - rw [monomial_eq, ← MvPolynomial.smul_eq_C_mul, - Finsupp.prod_fintype _ _ (fun _ => pow_zero _), Fintype.prod_prod_type] - rw [hm] - exact Submodule.smul_mem _ _ hprod - · apply Submodule.span_le.mpr - rintro _ ⟨x, rfl⟩ - exact pureRows_mem x - -lemma family_zero_of_all_shifted {A : Type*} [CommRing A] [Algebra ℂ A] - {a n j L : ℕ} (c : Fin a → Fin n → A) (l : A →ₗ[ℂ] ℂ) - (hj : a * L ≤ j) - (hz : mapCoeffs l (GenericShift.family c j L Finset.univ) = 0) : - mapCoeffs l (GenericShift.family c j L ∅) = 0 := by - classical - have hc (t : Finset (Fin a)) : - mapCoeffs l (GenericShift.family c j L (Finset.univ \ t)) = 0 := by - induction t using Finset.induction_on with - | empty => simpa using hz - | insert u t hu ih => - let s : Finset (Fin a) := Finset.univ \ insert u t - have hus : u ∉ s := by simp [s] - have hse : insert u s = Finset.univ \ t := by - ext i - by_cases hi : i = u <;> simp [s, hi, hu] - have hcard : s.card + 1 ≤ a := by - calc - s.card + 1 = (insert u s).card := (Finset.card_insert_of_notMem hus).symm - _ ≤ (Finset.univ : Finset (Fin a)).card := Finset.card_le_card (Finset.subset_univ _) - _ = a := by simp - have hbound : s.card * L + L ≤ j := by - have := Nat.mul_le_mul_right L hcard - nlinarith - have hL : L ≤ j := by omega - change mapCoeffs l (GenericShift.family c j L s) = 0 - apply Differential.shift_power_kernel_zero (u := u.castSucc) (v := Fin.last a) - (by simp) - (homogeneous_mapCoeffs l _ (GenericShift.family_degree_source c j L s u hus)) - (homogeneous_mapCoeffs l _ (GenericShift.family_degree_dest c j L s)) hbound - change ((GenericShift.shift u.castSucc (Fin.last a)).toLinearMap ^ L) - (mapCoeffs l (GenericShift.family c j L s)) = 0 - rw [← GenericShift.mapCoeffs_shift_pow, GenericShift.shift_family c j L s u hus hL, hse] - change (mapCoeffsLM l) (j.descFactorial L • GenericShift.family c j L (Finset.univ \ t)) = 0 - rw [map_nsmul] - change j.descFactorial L • mapCoeffs l (GenericShift.family c j L (Finset.univ \ t)) = 0 - rw [ih, smul_zero] - simpa using hc Finset.univ - -def z {a n : ℕ} (v : Fin n → ℂ) : P a n := ∏ i, rowForm i v - -def polarizedSpan (a n j L : ℕ) : Submodule ℂ (P a n) := - Submodule.span ℂ {p | ∃ (v : Fin n → ℂ) (f : P a n), - f ∈ W a n (j - L) ∧ z v ^ L * f = p} - -lemma eval_original_rowLinear {a n : ℕ} (u : Fin (a + 1)) (i : Fin a) - (x : Fin (a + 1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P a n) (x ij)) - (GenericShift.rowLinear u (fun k => (X (i, k) : P a n))) = - rowForm i (fun k => x (u, k)) := - GenericShift.eval_rowLinear u (fun k => (X (i, k) : P a n)) x - -lemma eval_family_empty {a n j L : ℕ} (x : Fin (a + 1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P a n) (x ij)) - (GenericShift.family (fun i k => (X (i, k) : P a n)) j L ∅) = - pureRows j (fun i k => x (i.castSucc, k)) := by - simp only [GenericShift.family, GenericShift.mixedProduct, Finset.notMem_empty, - ite_false, map_prod, map_pow, eval_original_rowLinear, pureRows] - -lemma eval_family_univ {a n j L : ℕ} (x : Fin (a + 1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P a n) (x ij)) - (GenericShift.family (fun i k => (X (i, k) : P a n)) j L Finset.univ) = - z (fun k => x (Fin.last a, k)) ^ L * - pureRows (j - L) (fun i k => x (i.castSucc, k)) := by - simp only [GenericShift.family, GenericShift.mixedProduct, Finset.mem_univ, - ite_true, map_prod, map_mul, map_pow, eval_original_rowLinear, pureRows, z] - rw [Finset.prod_mul_distrib, Finset.prod_pow] - -lemma z_pow_mem {a n L : ℕ} (v : Fin n → ℂ) : z (a := a) v ^ L ∈ W a n L := by - have h : (z (a := a) v).IsWeightedHomogeneous (weight a n) (fun _ => 1) := by - simpa [W, z, pureRows] using pureRows_mem (j := 1) (fun _ => v) - have hp := h.pow L - simpa [W, Pi.smul_def] using hp - -theorem W_polarization {a n j L : ℕ} (ha : 1 ≤ a) (hj : a * L ≤ j) : - W a n j = polarizedSpan a n j L := by - classical - apply le_antisymm - · intro f hf - by_contra hnot - obtain ⟨l, hlf, hlS⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance - have hl (p : P a n) (hp : p ∈ polarizedSpan a n j L) : l p = 0 := by - have hmem : l p ∈ (polarizedSpan a n j L).map l := Submodule.mem_map.mpr ⟨p, hp, rfl⟩ - rwa [hlS, Submodule.mem_bot] at hmem - have hfull : mapCoeffs l (GenericShift.family - (fun i k => (X (i, k) : P a n)) j L Finset.univ) = 0 := by - apply MvPolynomial.funext - intro x - rw [eval_mapCoeffs, eval_family_univ, map_zero] - apply hl - exact Submodule.subset_span ⟨_, _, pureRows_mem _, rfl⟩ - have hzero := family_zero_of_all_shifted (fun i k => (X (i, k) : P a n)) l hj hfull - have hpure (v : Fin a → Fin n → ℂ) : l (pureRows j v) = 0 := by - let x : Fin (a + 1) × Fin n → ℂ := - fun ij => Fin.lastCases 0 (fun i => v i ij.2) ij.1 - have he := congrArg (eval x) hzero - rw [eval_mapCoeffs, eval_family_empty, map_zero] at he - simpa [x] using he - have hW : W a n j ≤ LinearMap.ker l := by - rw [W_eq_span_pureRows] - apply Submodule.span_le.mpr - rintro _ ⟨v, rfl⟩ - exact hpure v - exact hlf (hW hf) - · apply Submodule.span_le.mpr - rintro _ ⟨v, f, hf, rfl⟩ - have hL : L ≤ j := le_trans (Nat.le_mul_of_pos_left L ha) hj - have hzm := z_pow_mem (a := a) (L := L) v - change (z v ^ L).IsWeightedHomogeneous (weight a n) (fun _ => L) at hzm - change f.IsWeightedHomogeneous (weight a n) (fun _ => j - L) at hf - have hprod := hzm.mul hf - simpa [W, Pi.add_def, Nat.add_sub_of_le hL] using hprod - -end Foulkes.Polarization - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.Differential +import OAI.RepresentationTheory.FoulkesSixth.GenericShift + +namespace OAI + +noncomputable section + +namespace Foulkes.Polarization +open MvPolynomial +open Foulkes.PolynomialSpan + +abbrev P (a n : ℕ) := MvPolynomial (Fin a × Fin n) ℂ + +def weight (a n : ℕ) (ij : Fin a × Fin n) : Fin a → ℕ := Pi.single ij.1 1 + +def W (a n j : ℕ) : Submodule ℂ (P a n) := + weightedHomogeneousSubmodule ℂ (weight a n) (fun _ => j) + +def rowForm {a n : ℕ} (i : Fin a) (x : Fin n → ℂ) : P a n := + ∑ k, x k • X (i, k) + +def pureRows {a n : ℕ} (j : ℕ) (x : Fin a → Fin n → ℂ) : P a n := + ∏ i, (rowForm i (x i)) ^ j + +lemma weight_apply_row {a n : ℕ} (d : (Fin a × Fin n) →₀ ℕ) (i : Fin a) : + Finsupp.weight (weight a n) d i = ∑ k, d (i, k) := by + classical + rw [Finsupp.weight_eq_sum] + simp only [weight, Finset.sum_apply, Fintype.sum_prod_type, Pi.smul_apply, + Pi.single_apply, smul_eq_mul, mul_ite, mul_one, mul_zero] + rw [Finset.sum_comm] + simp + +lemma pureRows_mem {a n j : ℕ} (x : Fin a → Fin n → ℂ) : + pureRows j x ∈ W a n j := by + classical + have hrow (i : Fin a) : (rowForm i (x i)).IsWeightedHomogeneous + (weight a n) (Pi.single i 1) := by + apply MvPolynomial.IsWeightedHomogeneous.sum + intro k _ + exact (weightedHomogeneousSubmodule ℂ (weight a n) (Pi.single i 1)).smul_mem _ + (isWeightedHomogeneous_X (R := ℂ) (weight a n) (i, k)) + have hprod := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ + (fun i => (rowForm i (x i)) ^ j) (fun i => j • Pi.single i 1) + (fun i _ => (hrow i).pow j) + have hdeg : (∑ i : Fin a, j • (Pi.single i 1 : Fin a → ℕ)) = fun _ => j := by + ext r + simp [Pi.single_apply] + rw [hdeg] at hprod + exact hprod + +theorem W_eq_span_pureRows (a n j : ℕ) : + W a n j = Submodule.span ℂ (Set.range (pureRows (a := a) (n := n) j)) := by + classical + apply le_antisymm + · intro p hp + induction hp using MvPolynomial.IsWeightedHomogeneous.induction_on with + | zero => exact Submodule.zero_mem _ + | add p q hp hq ihp ihq => exact Submodule.add_mem _ ihp ihq + | monomial d c hd => + have hdrow (i : Fin a) : ∑ k, d (i, k) = j := by + simpa [weight_apply_row] using congrFun hd i + have hx (i : Fin a) : (∏ k : Fin n, (X (i, k) : P a n) ^ d (i, k)) ∈ + Submodule.span ℂ (Set.range fun x : Fin n → ℂ => (rowForm i x) ^ j) := by + let e : Fin n →₀ ℕ := Finsupp.equivFunOnFinite.symm (fun k => d (i, k)) + have he : e.sum (fun _ v => v) = j := by + rw [Finsupp.sum_fintype _ _ (by simp)] + exact hdrow i + have hh := prod_pow_mem_span_powers (fun k => (X (i, k) : P a n)) e j he + rw [Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] at hh + simpa [e, rowForm] using hh + have hprod := prod_mem_span_range (fun i (x : Fin n → ℂ) => (rowForm i x) ^ j) hx + have hm : (monomial d c : P a n) = c • ∏ i : Fin a, ∏ k : Fin n, + (X (i, k) : P a n) ^ d (i, k) := by + rw [monomial_eq, ← MvPolynomial.smul_eq_C_mul, + Finsupp.prod_fintype _ _ (fun _ => pow_zero _), Fintype.prod_prod_type] + rw [hm] + exact Submodule.smul_mem _ _ hprod + · apply Submodule.span_le.mpr + rintro _ ⟨x, rfl⟩ + exact pureRows_mem x + +lemma family_zero_of_all_shifted {A : Type*} [CommRing A] [Algebra ℂ A] + {a n j L : ℕ} (c : Fin a → Fin n → A) (l : A →ₗ[ℂ] ℂ) + (hj : a * L ≤ j) + (hz : mapCoeffs l (GenericShift.family c j L Finset.univ) = 0) : + mapCoeffs l (GenericShift.family c j L ∅) = 0 := by + classical + have hc (t : Finset (Fin a)) : + mapCoeffs l (GenericShift.family c j L (Finset.univ \ t)) = 0 := by + induction t using Finset.induction_on with + | empty => simpa using hz + | insert u t hu ih => + let s : Finset (Fin a) := Finset.univ \ insert u t + have hus : u ∉ s := by simp [s] + have hse : insert u s = Finset.univ \ t := by + ext i + by_cases hi : i = u <;> simp [s, hi, hu] + have hcard : s.card + 1 ≤ a := by + calc + s.card + 1 = (insert u s).card := (Finset.card_insert_of_notMem hus).symm + _ ≤ (Finset.univ : Finset (Fin a)).card := Finset.card_le_card (Finset.subset_univ _) + _ = a := by simp + have hbound : s.card * L + L ≤ j := by + have := Nat.mul_le_mul_right L hcard + nlinarith + have hL : L ≤ j := by omega + change mapCoeffs l (GenericShift.family c j L s) = 0 + apply Differential.shift_power_kernel_zero (u := u.castSucc) (v := Fin.last a) + (by simp) + (homogeneous_mapCoeffs l _ (GenericShift.family_degree_source c j L s u hus)) + (homogeneous_mapCoeffs l _ (GenericShift.family_degree_dest c j L s)) hbound + change ((GenericShift.shift u.castSucc (Fin.last a)).toLinearMap ^ L) + (mapCoeffs l (GenericShift.family c j L s)) = 0 + rw [← GenericShift.mapCoeffs_shift_pow, GenericShift.shift_family c j L s u hus hL, hse] + change (mapCoeffsLM l) (j.descFactorial L • GenericShift.family c j L (Finset.univ \ t)) = 0 + rw [map_nsmul] + change j.descFactorial L • mapCoeffs l (GenericShift.family c j L (Finset.univ \ t)) = 0 + rw [ih, smul_zero] + simpa using hc Finset.univ + +def z {a n : ℕ} (v : Fin n → ℂ) : P a n := ∏ i, rowForm i v + +def polarizedSpan (a n j L : ℕ) : Submodule ℂ (P a n) := + Submodule.span ℂ {p | ∃ (v : Fin n → ℂ) (f : P a n), + f ∈ W a n (j - L) ∧ z v ^ L * f = p} + +lemma eval_original_rowLinear {a n : ℕ} (u : Fin (a + 1)) (i : Fin a) + (x : Fin (a + 1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P a n) (x ij)) + (GenericShift.rowLinear u (fun k => (X (i, k) : P a n))) = + rowForm i (fun k => x (u, k)) := + GenericShift.eval_rowLinear u (fun k => (X (i, k) : P a n)) x + +lemma eval_family_empty {a n j L : ℕ} (x : Fin (a + 1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P a n) (x ij)) + (GenericShift.family (fun i k => (X (i, k) : P a n)) j L ∅) = + pureRows j (fun i k => x (i.castSucc, k)) := by + simp only [GenericShift.family, GenericShift.mixedProduct, Finset.notMem_empty, + ite_false, map_prod, map_pow, eval_original_rowLinear, pureRows] + +lemma eval_family_univ {a n j L : ℕ} (x : Fin (a + 1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P a n) (x ij)) + (GenericShift.family (fun i k => (X (i, k) : P a n)) j L Finset.univ) = + z (fun k => x (Fin.last a, k)) ^ L * + pureRows (j - L) (fun i k => x (i.castSucc, k)) := by + simp only [GenericShift.family, GenericShift.mixedProduct, Finset.mem_univ, + ite_true, map_prod, map_mul, map_pow, eval_original_rowLinear, pureRows, z] + rw [Finset.prod_mul_distrib, Finset.prod_pow] + +lemma z_pow_mem {a n L : ℕ} (v : Fin n → ℂ) : z (a := a) v ^ L ∈ W a n L := by + have h : (z (a := a) v).IsWeightedHomogeneous (weight a n) (fun _ => 1) := by + simpa [W, z, pureRows] using pureRows_mem (j := 1) (fun _ => v) + have hp := h.pow L + simpa [W, Pi.smul_def] using hp + +theorem W_polarization {a n j L : ℕ} (ha : 1 ≤ a) (hj : a * L ≤ j) : + W a n j = polarizedSpan a n j L := by + classical + apply le_antisymm + · intro f hf + by_contra hnot + obtain ⟨l, hlf, hlS⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance + have hl (p : P a n) (hp : p ∈ polarizedSpan a n j L) : l p = 0 := by + have hmem : l p ∈ (polarizedSpan a n j L).map l := Submodule.mem_map.mpr ⟨p, hp, rfl⟩ + rwa [hlS, Submodule.mem_bot] at hmem + have hfull : mapCoeffs l (GenericShift.family + (fun i k => (X (i, k) : P a n)) j L Finset.univ) = 0 := by + apply MvPolynomial.funext + intro x + rw [eval_mapCoeffs, eval_family_univ, map_zero] + apply hl + exact Submodule.subset_span ⟨_, _, pureRows_mem _, rfl⟩ + have hzero := family_zero_of_all_shifted (fun i k => (X (i, k) : P a n)) l hj hfull + have hpure (v : Fin a → Fin n → ℂ) : l (pureRows j v) = 0 := by + let x : Fin (a + 1) × Fin n → ℂ := + fun ij => Fin.lastCases 0 (fun i => v i ij.2) ij.1 + have he := congrArg (eval x) hzero + rw [eval_mapCoeffs, eval_family_empty, map_zero] at he + simpa [x] using he + have hW : W a n j ≤ LinearMap.ker l := by + rw [W_eq_span_pureRows] + apply Submodule.span_le.mpr + rintro _ ⟨v, rfl⟩ + exact hpure v + exact hlf (hW hf) + · apply Submodule.span_le.mpr + rintro _ ⟨v, f, hf, rfl⟩ + have hL : L ≤ j := le_trans (Nat.le_mul_of_pos_left L ha) hj + have hzm := z_pow_mem (a := a) (L := L) v + change (z v ^ L).IsWeightedHomogeneous (weight a n) (fun _ => L) at hzm + change f.IsWeightedHomogeneous (weight a n) (fun _ => j - L) at hf + have hprod := hzm.mul hf + simpa [W, Pi.add_def, Nat.add_sub_of_le hL] using hprod + +end Foulkes.Polarization + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/Vanishing.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/Vanishing.lean index 2711ce3f4808c594f0cfc1f378826e9be819d858..c5b44c72ee304797d496129d8cf209d82938287f 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/Vanishing.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/Vanishing.lean @@ -1,215 +1,215 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.VanishingSteps - -namespace OAI - -noncomputable section - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan - -def extendPerm {r : ℕ} (σ : Equiv.Perm (Fin r)) : Equiv.Perm (Fin (r+1)) where - toFun := Fin.lastCases (Fin.last r) (fun i => (σ i).castSucc) - invFun := Fin.lastCases (Fin.last r) (fun i => (σ.symm i).castSucc) - left_inv := by intro i; refine Fin.lastCases ?_ (fun j => ?_) i <;> simp - right_inv := by intro i; refine Fin.lastCases ?_ (fun j => ?_) i <;> simp - -@[simp] lemma extendPerm_castSucc {r : ℕ} (σ : Equiv.Perm (Fin r)) (i : Fin r) : - extendPerm σ i.castSucc = (σ i).castSucc := by simp [extendPerm] - -@[simp] lemma extendPerm_last {r : ℕ} (σ : Equiv.Perm (Fin r)) : - extendPerm σ (Fin.last r) = Fin.last r := by simp [extendPerm] - -def embedRows {r n : ℕ} : P r n →ₐ[ℂ] P (r+1) n := - rename (fun ij : Fin r × Fin n => (ij.1.castSucc,ij.2)) - -lemma embedRows_rowLift {r n : ℕ} (i : Fin r) (p : S n) : - embedRows (rowLift i p) = rowLift i.castSucc p := by - simp [embedRows, rowLift, rename_rename, Function.comp_def] - -@[simp] lemma embedRows_rowForm {r n : ℕ} (i : Fin r) (v : Fin n → ℂ) : - embedRows (rowForm i v) = rowForm i.castSucc v := by simp [embedRows, rowForm] - -lemma embedRows_pureRows {r n b : ℕ} (v : Fin r → Fin n → ℂ) : - embedRows (pureRows b v) = ∏ i, rowForm i.castSucc (v i) ^ b := by - simp only [pureRows, map_prod, map_pow, embedRows_rowForm] - -lemma embedRows_tensorRows {r n : ℕ} (p : Fin r → S n) : - embedRows (tensorRows p) = ∏ i, rowLift i.castSucc (p i) := by - simp only [tensorRows, map_prod, embedRows_rowLift] - -lemma renameRow_embedRows {r n : ℕ} (σ : Equiv.Perm (Fin r)) (f : P r n) : - renameRow (extendPerm σ) (embedRows f) = embedRows (renameRow σ f) := by - simp [renameRow, embedRows, rename_rename, Function.comp_def] - -lemma renameRow_commonPower {r n : ℕ} (σ : Equiv.Perm (Fin r)) (x : Fin n → ℂ) : - renameRow (extendPerm σ) (commonPower x) = commonPower x := by - simp only [commonPower, map_prod, map_pow, renameRow_rowForm, extendPerm_castSucc] - exact Equiv.prod_comp σ (fun i => rowForm i.castSucc x ^ r) - -def restrictionFunctional {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) - (x t : Fin n → ℂ) (b : ℕ) : P r n →ₗ[ℂ] ℂ := - (l.comp (LinearMap.mulLeft ℂ (commonPower x * rowForm (Fin.last r) t ^ b))).comp embedRows.toLinearMap - -@[simp] lemma restrictionFunctional_apply {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) - (x t : Fin n → ℂ) (b : ℕ) (f : P r n) : - restrictionFunctional l x t b f = - l ((commonPower x * rowForm (Fin.last r) t ^ b) * embedRows f) := rfl - -lemma restriction_symmetric {r n b : ℕ} {l : P (r+1) n →ₗ[ℂ] ℂ} - (hs : Symmetric l) (x t : Fin n → ℂ) : Symmetric (restrictionFunctional l x t b) := by - intro σ f - simp only [restrictionFunctional_apply, ← renameRow_embedRows] - have hh := hs (extendPerm σ) ((commonPower x * rowForm (Fin.last r) t ^ b) * embedRows f) - simpa only [map_mul, map_pow, renameRow_commonPower, renameRow_rowForm, extendPerm_last] using hh - -lemma restriction_products {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} - (hs : Symmetric l) (hz : ProductsVanish l (r+m)) (x t : Fin n → ℂ) : - ProductsVanish (restrictionFunctional l x t (r+m)) m := by - intro y - rw [← tensorRows_diag_product, restrictionFunctional_apply, embedRows_tensorRows] - have hh := free_last_slot hr hs hz x t y - simp only [map_mul, map_pow, rowLift_lin, Finset.prod_mul_distrib] at hh - simpa only [commonPower, mul_assoc, mul_left_comm, mul_comm] using hh - -lemma eval_cast_rowLinear {r n : ℕ} (u : Fin (r+1)) (i : Fin r) - (w : Fin (r+1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) - (GenericShift.rowLinear u (fun k => (X (i.castSucc,k) : P (r+1) n))) = - rowForm i.castSucc (fun k => w (u,k)) := - GenericShift.eval_rowLinear u _ w - -lemma eval_induction_family_univ {r n j : ℕ} (w : Fin (r+1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) - (GenericShift.family (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) - j r Finset.univ) = - commonPower (fun k => w (Fin.last r,k)) * - embedRows (pureRows (j-r) (fun i k => w (i.castSucc,k))) := by - simp only [GenericShift.family, GenericShift.mixedProduct, Finset.mem_univ, ite_true, - map_prod, map_mul, map_pow, eval_cast_rowLinear, embedRows_pureRows, commonPower] - exact Finset.prod_mul_distrib - -lemma eval_induction_family_empty {r n j : ℕ} (w : Fin (r+1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) - (GenericShift.family (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) - j r ∅) = embedRows (pureRows j (fun i k => w (i.castSucc,k))) := by - simp only [GenericShift.family, GenericShift.mixedProduct, Finset.notMem_empty, ite_false, - map_prod, map_pow, eval_cast_rowLinear, embedRows_pureRows] - -lemma remove_common_power {r m n : ℕ} (hb : r*r ≤ r+m) - {l : P (r+1) n →ₗ[ℂ] ℂ} (t : Fin n → ℂ) - (hz : ∀ (x : Fin n → ℂ) (f : P r n), f ∈ W r n m → - restrictionFunctional l x t (r+m) f = 0) - (v : Fin r → Fin n → ℂ) : - l ((∏ i : Fin r, rowForm i.castSucc (v i) ^ (r+m)) * - rowForm (Fin.last r) t ^ (r+m)) = 0 := by - let c := fun i : Fin r => fun k : Fin n => (X (i.castSucc,k) : P (r+1) n) - let lt : P (r+1) n →ₗ[ℂ] ℂ := - l.comp (LinearMap.mulLeft ℂ (rowForm (Fin.last r) t ^ (r+m))) - have hfull : mapCoeffs lt (GenericShift.family c (r+m) r Finset.univ) = 0 := by - apply MvPolynomial.funext - intro w - rw [eval_mapCoeffs, eval_induction_family_univ, Nat.add_sub_cancel_left, map_zero] - have hh := hz (fun k => w (Fin.last r,k)) - (pureRows m (fun i k => w (i.castSucc,k))) (pureRows_mem _) - change l ((commonPower (fun k => w (Fin.last r,k)) * rowForm (Fin.last r) t ^ (r+m)) * - embedRows (pureRows m (fun i k => w (i.castSucc,k)))) = 0 at hh - change l (rowForm (Fin.last r) t ^ (r+m) * (commonPower (fun k => w (Fin.last r,k)) * - embedRows (pureRows m (fun i k => w (i.castSucc,k))))) = 0 - rw [← mul_assoc, mul_comm (rowForm (Fin.last r) t ^ (r+m))] - exact hh - have hzero := family_zero_of_all_shifted c lt hb hfull - let w : Fin (r+1) × Fin n → ℂ := fun ij => Fin.lastCases 0 (fun i => v i ij.2) ij.1 - have hh := congrArg (eval w) hzero - rw [eval_mapCoeffs, eval_induction_family_empty, map_zero] at hh - change l (rowForm (Fin.last r) t ^ (r+m) * embedRows (pureRows (r+m) _)) = 0 at hh - rw [embedRows_pureRows, mul_comm] at hh - simpa only [w, Fin.lastCases_castSucc] using hh - -theorem vanishing (a : ℕ) : ∀ {n b : ℕ}, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → - ∀ {l : P a n →ₗ[ℂ] ℂ}, Symmetric l → ProductsVanish l b → - ∀ f : P a n, f ∈ W a n b → l f = 0 := by - induction a with - | zero => intro n b ha; omega - | succ r ih => - intro n b ha hb0 hb l hs hz f hf - have hpure : ∀ v : Fin (r+1) → Fin n → ℂ, l (pureRows b v) = 0 := by - intro v - by_cases hr : r = 0 - · subst r - have hh := hz (fun _ => v 0) - simpa [pureRows, z, Fin.prod_univ_one] using hh - · have hrpos : 0 < r := Nat.pos_of_ne_zero hr - have hrb : r ≤ b := by - simp only [Nat.add_sub_cancel] at hb - nlinarith - obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb - have hm : r*r ≤ m := by - simp only [Nat.add_sub_cancel] at hb - nlinarith - have hrestrict (x t : Fin n → ℂ) (g : P r n) (hg : g ∈ W r n m) : - restrictionFunctional l x t (r+m) g = 0 := by - apply ih (by omega) (by nlinarith) ?_ (restriction_symmetric hs x t) - (restriction_products hrpos hs hz x t) g hg - have hpred : r-1 ≤ r := Nat.sub_le _ _ - exact (Nat.mul_le_mul_left r hpred).trans hm - have hh := remove_common_power (by nlinarith : r*r ≤ r+m) - (v (Fin.last r)) (fun x g hg => hrestrict x (v (Fin.last r)) g hg) - (fun i => v i.castSucc) - simpa only [pureRows, Fin.prod_univ_castSucc] using hh - have hW : W (r+1) n b ≤ LinearMap.ker l := by - rw [W_eq_span_pureRows] - apply Submodule.span_le.mpr - rintro _ ⟨v,rfl⟩ - exact hpure v - exact hW hf - -end Foulkes.Vanishing - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.Polarization - -lemma average_renameRow {a n : ℕ} (τ : Equiv.Perm (Fin a)) (f : P a n) : - average a n (renameRow τ f) = average a n f := by - simp only [average_apply, renameRow_comp] - congr 1 - exact Equiv.sum_comp (Equiv.mulRight τ) (fun σ => renameRow σ f) - -theorem quadratic_bound (a n b : ℕ) (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : - R a n b = W a n b ⊓ (A a n).toSubmodule := by - classical - apply le_antisymm - · intro f hf - refine ⟨hf.1, ?_⟩ - by_contra hnot - obtain ⟨l, hlf, hlA⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance - have hkill (p : P a n) (hp : p ∈ A a n) : l p = 0 := by - have hh : l p ∈ (A a n).toSubmodule.map l := Submodule.mem_map.mpr ⟨p,hp,rfl⟩ - rwa [hlA, Submodule.mem_bot] at hh - let lav := l.comp (average a n) - have hs : Symmetric lav := by - intro σ p - change l (average a n (renameRow σ p)) = l (average a n p) - rw [average_renameRow] - have hz : ProductsVanish lav b := by - intro y - have hp : (∏ j : Fin b, z (y j)) ∈ A a n := - (A a n).prod_mem (fun j _ => z_mem_A (y j)) - change l (average a n (∏ j, z (y j))) = 0 - rw [average_eq (A_le_rowInvariants a n hp)] - exact hkill _ hp - have hh := vanishing a ha hb0 hb hs hz f hf.1 - change l (average a n f) = 0 at hh - rw [average_eq hf.2] at hh - exact hlf hh - · exact AComponent_le_R a n b - -theorem sixth_quadratic_bound (n b : ℕ) (hb : 30 ≤ b) : - R 6 n b = W 6 n b ⊓ (A 6 n).toSubmodule := - quadratic_bound 6 n b (by omega) (by omega) (by omega) - -end Foulkes.Vanishing - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.VanishingSteps + +namespace OAI + +noncomputable section + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan + +def extendPerm {r : ℕ} (σ : Equiv.Perm (Fin r)) : Equiv.Perm (Fin (r+1)) where + toFun := Fin.lastCases (Fin.last r) (fun i => (σ i).castSucc) + invFun := Fin.lastCases (Fin.last r) (fun i => (σ.symm i).castSucc) + left_inv := by intro i; refine Fin.lastCases ?_ (fun j => ?_) i <;> simp + right_inv := by intro i; refine Fin.lastCases ?_ (fun j => ?_) i <;> simp + +@[simp] lemma extendPerm_castSucc {r : ℕ} (σ : Equiv.Perm (Fin r)) (i : Fin r) : + extendPerm σ i.castSucc = (σ i).castSucc := by simp [extendPerm] + +@[simp] lemma extendPerm_last {r : ℕ} (σ : Equiv.Perm (Fin r)) : + extendPerm σ (Fin.last r) = Fin.last r := by simp [extendPerm] + +def embedRows {r n : ℕ} : P r n →ₐ[ℂ] P (r+1) n := + rename (fun ij : Fin r × Fin n => (ij.1.castSucc,ij.2)) + +lemma embedRows_rowLift {r n : ℕ} (i : Fin r) (p : S n) : + embedRows (rowLift i p) = rowLift i.castSucc p := by + simp [embedRows, rowLift, rename_rename, Function.comp_def] + +@[simp] lemma embedRows_rowForm {r n : ℕ} (i : Fin r) (v : Fin n → ℂ) : + embedRows (rowForm i v) = rowForm i.castSucc v := by simp [embedRows, rowForm] + +lemma embedRows_pureRows {r n b : ℕ} (v : Fin r → Fin n → ℂ) : + embedRows (pureRows b v) = ∏ i, rowForm i.castSucc (v i) ^ b := by + simp only [pureRows, map_prod, map_pow, embedRows_rowForm] + +lemma embedRows_tensorRows {r n : ℕ} (p : Fin r → S n) : + embedRows (tensorRows p) = ∏ i, rowLift i.castSucc (p i) := by + simp only [tensorRows, map_prod, embedRows_rowLift] + +lemma renameRow_embedRows {r n : ℕ} (σ : Equiv.Perm (Fin r)) (f : P r n) : + renameRow (extendPerm σ) (embedRows f) = embedRows (renameRow σ f) := by + simp [renameRow, embedRows, rename_rename, Function.comp_def] + +lemma renameRow_commonPower {r n : ℕ} (σ : Equiv.Perm (Fin r)) (x : Fin n → ℂ) : + renameRow (extendPerm σ) (commonPower x) = commonPower x := by + simp only [commonPower, map_prod, map_pow, renameRow_rowForm, extendPerm_castSucc] + exact Equiv.prod_comp σ (fun i => rowForm i.castSucc x ^ r) + +def restrictionFunctional {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) + (x t : Fin n → ℂ) (b : ℕ) : P r n →ₗ[ℂ] ℂ := + (l.comp (LinearMap.mulLeft ℂ (commonPower x * rowForm (Fin.last r) t ^ b))).comp embedRows.toLinearMap + +@[simp] lemma restrictionFunctional_apply {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) + (x t : Fin n → ℂ) (b : ℕ) (f : P r n) : + restrictionFunctional l x t b f = + l ((commonPower x * rowForm (Fin.last r) t ^ b) * embedRows f) := rfl + +lemma restriction_symmetric {r n b : ℕ} {l : P (r+1) n →ₗ[ℂ] ℂ} + (hs : Symmetric l) (x t : Fin n → ℂ) : Symmetric (restrictionFunctional l x t b) := by + intro σ f + simp only [restrictionFunctional_apply, ← renameRow_embedRows] + have hh := hs (extendPerm σ) ((commonPower x * rowForm (Fin.last r) t ^ b) * embedRows f) + simpa only [map_mul, map_pow, renameRow_commonPower, renameRow_rowForm, extendPerm_last] using hh + +lemma restriction_products {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} + (hs : Symmetric l) (hz : ProductsVanish l (r+m)) (x t : Fin n → ℂ) : + ProductsVanish (restrictionFunctional l x t (r+m)) m := by + intro y + rw [← tensorRows_diag_product, restrictionFunctional_apply, embedRows_tensorRows] + have hh := free_last_slot hr hs hz x t y + simp only [map_mul, map_pow, rowLift_lin, Finset.prod_mul_distrib] at hh + simpa only [commonPower, mul_assoc, mul_left_comm, mul_comm] using hh + +lemma eval_cast_rowLinear {r n : ℕ} (u : Fin (r+1)) (i : Fin r) + (w : Fin (r+1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) + (GenericShift.rowLinear u (fun k => (X (i.castSucc,k) : P (r+1) n))) = + rowForm i.castSucc (fun k => w (u,k)) := + GenericShift.eval_rowLinear u _ w + +lemma eval_induction_family_univ {r n j : ℕ} (w : Fin (r+1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) + (GenericShift.family (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) + j r Finset.univ) = + commonPower (fun k => w (Fin.last r,k)) * + embedRows (pureRows (j-r) (fun i k => w (i.castSucc,k))) := by + simp only [GenericShift.family, GenericShift.mixedProduct, Finset.mem_univ, ite_true, + map_prod, map_mul, map_pow, eval_cast_rowLinear, embedRows_pureRows, commonPower] + exact Finset.prod_mul_distrib + +lemma eval_induction_family_empty {r n j : ℕ} (w : Fin (r+1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) + (GenericShift.family (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) + j r ∅) = embedRows (pureRows j (fun i k => w (i.castSucc,k))) := by + simp only [GenericShift.family, GenericShift.mixedProduct, Finset.notMem_empty, ite_false, + map_prod, map_pow, eval_cast_rowLinear, embedRows_pureRows] + +lemma remove_common_power {r m n : ℕ} (hb : r*r ≤ r+m) + {l : P (r+1) n →ₗ[ℂ] ℂ} (t : Fin n → ℂ) + (hz : ∀ (x : Fin n → ℂ) (f : P r n), f ∈ W r n m → + restrictionFunctional l x t (r+m) f = 0) + (v : Fin r → Fin n → ℂ) : + l ((∏ i : Fin r, rowForm i.castSucc (v i) ^ (r+m)) * + rowForm (Fin.last r) t ^ (r+m)) = 0 := by + let c := fun i : Fin r => fun k : Fin n => (X (i.castSucc,k) : P (r+1) n) + let lt : P (r+1) n →ₗ[ℂ] ℂ := + l.comp (LinearMap.mulLeft ℂ (rowForm (Fin.last r) t ^ (r+m))) + have hfull : mapCoeffs lt (GenericShift.family c (r+m) r Finset.univ) = 0 := by + apply MvPolynomial.funext + intro w + rw [eval_mapCoeffs, eval_induction_family_univ, Nat.add_sub_cancel_left, map_zero] + have hh := hz (fun k => w (Fin.last r,k)) + (pureRows m (fun i k => w (i.castSucc,k))) (pureRows_mem _) + change l ((commonPower (fun k => w (Fin.last r,k)) * rowForm (Fin.last r) t ^ (r+m)) * + embedRows (pureRows m (fun i k => w (i.castSucc,k)))) = 0 at hh + change l (rowForm (Fin.last r) t ^ (r+m) * (commonPower (fun k => w (Fin.last r,k)) * + embedRows (pureRows m (fun i k => w (i.castSucc,k))))) = 0 + rw [← mul_assoc, mul_comm (rowForm (Fin.last r) t ^ (r+m))] + exact hh + have hzero := family_zero_of_all_shifted c lt hb hfull + let w : Fin (r+1) × Fin n → ℂ := fun ij => Fin.lastCases 0 (fun i => v i ij.2) ij.1 + have hh := congrArg (eval w) hzero + rw [eval_mapCoeffs, eval_induction_family_empty, map_zero] at hh + change l (rowForm (Fin.last r) t ^ (r+m) * embedRows (pureRows (r+m) _)) = 0 at hh + rw [embedRows_pureRows, mul_comm] at hh + simpa only [w, Fin.lastCases_castSucc] using hh + +theorem vanishing (a : ℕ) : ∀ {n b : ℕ}, 1 ≤ a → 1 ≤ b → a*(a-1) ≤ b → + ∀ {l : P a n →ₗ[ℂ] ℂ}, Symmetric l → ProductsVanish l b → + ∀ f : P a n, f ∈ W a n b → l f = 0 := by + induction a with + | zero => intro n b ha; omega + | succ r ih => + intro n b ha hb0 hb l hs hz f hf + have hpure : ∀ v : Fin (r+1) → Fin n → ℂ, l (pureRows b v) = 0 := by + intro v + by_cases hr : r = 0 + · subst r + have hh := hz (fun _ => v 0) + simpa [pureRows, z, Fin.prod_univ_one] using hh + · have hrpos : 0 < r := Nat.pos_of_ne_zero hr + have hrb : r ≤ b := by + simp only [Nat.add_sub_cancel] at hb + nlinarith + obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le hrb + have hm : r*r ≤ m := by + simp only [Nat.add_sub_cancel] at hb + nlinarith + have hrestrict (x t : Fin n → ℂ) (g : P r n) (hg : g ∈ W r n m) : + restrictionFunctional l x t (r+m) g = 0 := by + apply ih (by omega) (by nlinarith) ?_ (restriction_symmetric hs x t) + (restriction_products hrpos hs hz x t) g hg + have hpred : r-1 ≤ r := Nat.sub_le _ _ + exact (Nat.mul_le_mul_left r hpred).trans hm + have hh := remove_common_power (by nlinarith : r*r ≤ r+m) + (v (Fin.last r)) (fun x g hg => hrestrict x (v (Fin.last r)) g hg) + (fun i => v i.castSucc) + simpa only [pureRows, Fin.prod_univ_castSucc] using hh + have hW : W (r+1) n b ≤ LinearMap.ker l := by + rw [W_eq_span_pureRows] + apply Submodule.span_le.mpr + rintro _ ⟨v,rfl⟩ + exact hpure v + exact hW hf + +end Foulkes.Vanishing + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.Polarization + +lemma average_renameRow {a n : ℕ} (τ : Equiv.Perm (Fin a)) (f : P a n) : + average a n (renameRow τ f) = average a n f := by + simp only [average_apply, renameRow_comp] + congr 1 + exact Equiv.sum_comp (Equiv.mulRight τ) (fun σ => renameRow σ f) + +theorem quadratic_bound (a n b : ℕ) (ha : 1 ≤ a) (hb0 : 1 ≤ b) (hb : a*(a-1) ≤ b) : + R a n b = W a n b ⊓ (A a n).toSubmodule := by + classical + apply le_antisymm + · intro f hf + refine ⟨hf.1, ?_⟩ + by_contra hnot + obtain ⟨l, hlf, hlA⟩ := Submodule.exists_dual_map_eq_bot_of_notMem hnot inferInstance + have hkill (p : P a n) (hp : p ∈ A a n) : l p = 0 := by + have hh : l p ∈ (A a n).toSubmodule.map l := Submodule.mem_map.mpr ⟨p,hp,rfl⟩ + rwa [hlA, Submodule.mem_bot] at hh + let lav := l.comp (average a n) + have hs : Symmetric lav := by + intro σ p + change l (average a n (renameRow σ p)) = l (average a n p) + rw [average_renameRow] + have hz : ProductsVanish lav b := by + intro y + have hp : (∏ j : Fin b, z (y j)) ∈ A a n := + (A a n).prod_mem (fun j _ => z_mem_A (y j)) + change l (average a n (∏ j, z (y j))) = 0 + rw [average_eq (A_le_rowInvariants a n hp)] + exact hkill _ hp + have hh := vanishing a ha hb0 hb hs hz f hf.1 + change l (average a n f) = 0 at hh + rw [average_eq hf.2] at hh + exact hlf hh + · exact AComponent_le_R a n b + +theorem sixth_quadratic_bound (n b : ℕ) (hb : 30 ≤ b) : + R 6 n b = W 6 n b ⊓ (A 6 n).toSubmodule := + quadratic_bound 6 n b (by omega) (by omega) (by omega) + +end Foulkes.Vanishing + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/VanishingSteps.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/VanishingSteps.lean index 09b9f87a6f9c2a203ab5ea97ad000b65d6a13b31..67cc68f8ca4200b0b36de497f54d530d6ecbe01a 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/VanishingSteps.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/VanishingSteps.lean @@ -1,401 +1,401 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization - -namespace OAI - -noncomputable section - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan - -lemma binary_split {a n r : ℕ} (hr : 0 < r) (c : ℂ) (x t : Fin n → ℂ) : - ∃ v : Fin r → Fin n → ℂ, ∀ i : Fin a, - rowForm i x ^ r + c • rowForm i t ^ r = ∏ j, rowForm i (v j) := by - classical - obtain ⟨α, hα⟩ := IsAlgClosed.exists_pow_nat_eq (-c) hr - let ζ := Complex.exp (2 * Real.pi * Complex.I / r) - have hζ : IsPrimitiveRoot ζ r := Complex.isPrimitiveRoot_exp r hr.ne' - let S := Polynomial.nthRootsFinset r (1 : ℂ) - have hS : Fintype.card S = r := by - rw [Fintype.card_coe] - exact hζ.card_nthRootsFinset - let e : Fin r ≃ S := (Fintype.equivFinOfCardEq hS).symm - refine ⟨fun j k => x k - (α * (e j : ℂ)) * t k, ?_⟩ - intro i - apply MvPolynomial.funext - intro w - let X₀ := ∑ k, x k * w (i,k) - let Y₀ := ∑ k, t k * w (i,k) - have heval (j : Fin r) : - eval w (rowForm i (fun k => x k - α * (e j : ℂ) * t k)) = - X₀ - (e j : ℂ) * (α * Y₀) := by - simp only [rowForm, eval_sum, MvPolynomial.smul_eq_C_mul, eval_mul, eval_C, eval_X] - simp only [sub_mul, Finset.sum_sub_distrib] - dsimp [X₀, Y₀] - simp only [Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro k _ - ring - have hprod : (∏ j : Fin r, (X₀ - (e j : ℂ) * (α * Y₀))) = - ∏ z ∈ S, (X₀ - z * (α * Y₀)) := by - calc - _ = ∏ z : S, (X₀ - (z : ℂ) * (α * Y₀)) := - Fintype.prod_equiv e _ _ (fun _ => rfl) - _ = _ := Finset.prod_coe_sort S (fun z : ℂ => X₀ - z * (α * Y₀)) - simp only [eval_add, eval_pow, MvPolynomial.smul_eq_C_mul, eval_mul, eval_C, eval_prod, heval] - have hx : eval w (rowForm i x) = X₀ := by simp [rowForm, X₀, MvPolynomial.smul_eq_C_mul] - have hy : eval w (rowForm i t) = Y₀ := by simp [rowForm, Y₀, MvPolynomial.smul_eq_C_mul] - rw [hx, hy] - rw [hprod, ← hζ.pow_sub_pow_eq_prod_sub_mul X₀ (α * Y₀) hr, mul_pow, hα] - ring - -abbrev S (n : ℕ) := MvPolynomial (Fin n) ℂ - -def rowLift {a n : ℕ} (i : Fin a) : S n →ₐ[ℂ] P a n := - rename (fun k => (i,k)) - -def tensorRows {a n : ℕ} (p : Fin a → S n) : P a n := ∏ i, rowLift i (p i) - -def lin {n : ℕ} (x : Fin n → ℂ) : S n := ∑ k, x k • X k - -@[simp] lemma rowLift_lin {a n : ℕ} (i : Fin a) (x : Fin n → ℂ) : - rowLift i (lin x) = rowForm i x := by simp [rowLift, lin, rowForm] - -@[simp] lemma renameRow_rowLift {a n : ℕ} (σ : Equiv.Perm (Fin a)) - (i : Fin a) (p : S n) : renameRow σ (rowLift i p) = rowLift (σ i) p := by - simp [rowLift, renameRow, rename_rename, Function.comp_def] - -lemma renameRow_tensorRows {a n : ℕ} (σ : Equiv.Perm (Fin a)) (p : Fin a → S n) : - renameRow σ (tensorRows p) = tensorRows (fun i => p (σ.symm i)) := by - simp only [tensorRows, map_prod, renameRow_rowLift] - apply Fintype.prod_equiv σ - intro i - simp - -def Symmetric {a n : ℕ} (l : P a n →ₗ[ℂ] ℂ) : Prop := - ∀ (σ : Equiv.Perm (Fin a)) (f : P a n), l (renameRow σ f) = l f - -lemma symmetric_tensorRows {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hl : Symmetric l) - (σ : Equiv.Perm (Fin a)) (p : Fin a → S n) : - l (tensorRows (fun i => p (σ.symm i))) = l (tensorRows p) := by - rw [← renameRow_tensorRows, hl] - -def oneSlot {a n : ℕ} (p q : S n) (i : Fin a) : P a n := - tensorRows (fun j => if j = i then q else p) - -lemma oneSlot_eq {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hl : Symmetric l) - (p q : S n) (i j : Fin a) : l (oneSlot p q i) = l (oneSlot p q j) := by - classical - have hh := symmetric_tensorRows hl (Equiv.swap i j) (fun k => if k = j then q else p) - have he : (fun k => if (Equiv.swap i j).symm k = j then q else p) = - (fun k => if k = i then q else p) := by - funext k - simp [Equiv.swap_apply_eq_iff] - rw [he] at hh - exact hh - -lemma eval_pderiv_prod {A ι σ : Type*} [CommRing A] [Fintype ι] [DecidableEq ι] - (v : σ) (w : σ → A) (f : ι → MvPolynomial σ A) : - eval w (pderiv v (∏ i, f i)) = - ∑ i, eval w (pderiv v (f i)) * ∏ j ∈ Finset.univ.erase i, eval w (f j) := by - classical - have hs (s : Finset ι) : eval w (pderiv v (∏ i ∈ s, f i)) = - ∑ i ∈ s, eval w (pderiv v (f i)) * ∏ j ∈ s.erase i, eval w (f j) := by - induction s using Finset.induction_on with - | empty => simp - | insert u s hu ih => - rw [Finset.prod_insert hu, pderiv_mul, eval_add, eval_mul, eval_mul, ih, - Finset.sum_insert hu] - rw [Finset.erase_insert hu] - simp only [eval_prod, Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro i hi - have hne : i ≠ u := ne_of_mem_of_not_mem hi hu - rw [Finset.erase_insert_of_ne hne.symm, Finset.prod_insert (by simp [hu])] - ring - exact hs Finset.univ - -lemma binary_coefficient {a n : ℕ} (ha : 0 < a) {l : P a n →ₗ[ℂ] ℂ} - (hl : Symmetric l) (p q : S n) - (hz : ∀ c : ℂ, l (tensorRows (fun _ => p + c • q)) = 0) (i : Fin a) : - l (oneSlot p q i) = 0 := by - classical - let F : MvPolynomial Unit (P a n) := - ∏ j, (C (rowLift j p) + X () * C (rowLift j q)) - have heval (c : ℂ) : eval (fun _ : Unit => algebraMap ℂ (P a n) c) F = - tensorRows (fun _ => p + c • q) := by - simp [F, tensorRows, rowLift, Algebra.smul_def] - have hF : mapCoeffs l F = 0 := by - apply MvPolynomial.funext - intro c - rw [eval_mapCoeffs] - have hc : c = fun _ : Unit => c () := funext (fun u => by cases u; rfl) - rw [hc, heval, hz, map_zero] - have hd := congrArg (eval (fun _ : Unit => (0 : ℂ))) - (congrArg (pderiv ()) hF) - rw [← mapCoeffs_pderiv, eval_mapCoeffs] at hd - have hD : eval (fun _ : Unit => algebraMap ℂ (P a n) 0) (pderiv () F) = - ∑ j, oneSlot p q j := by - dsimp only [F] - rw [eval_pderiv_prod] - apply Finset.sum_congr rfl - intro j _ - simp only [map_add, pderiv_C, pderiv_mul, pderiv_X_self, mul_zero, - add_zero, zero_add, eval_C, eval_mul, eval_X, map_zero, zero_mul] - rw [oneSlot, tensorRows, ← Finset.mul_prod_erase Finset.univ _ (a := j) (by simp)] - simp only [ite_true, map_one, one_mul] - congr 1 - apply Finset.prod_congr rfl - intro k hk - rw [ite_eq_right (Finset.mem_erase.mp hk).1] - rw [hD, map_sum] at hd - have hsum : (∑ j : Fin a, l (oneSlot p q j)) = (a : ℂ) * l (oneSlot p q i) := by - simp_rw [fun j => oneSlot_eq hl p q j i] - simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] - rw [hsum] at hd - have haC : (a : ℂ) ≠ 0 := by exact_mod_cast ha.ne' - exact (mul_eq_zero.mp (by simpa using hd)).resolve_left haC - -end Foulkes.Vanishing - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.PolynomialSpan Foulkes.GenericShift - -variable {A : Type*} [CommRing A] - -def freeBase {r m n : ℕ} (c : Fin r → Fin n → A) : Poly A (m+1) n := - ∏ j : Fin m, ∏ i : Fin r, rowLinear j.castSucc (c i) - -def freeFamily {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) - (b : ℕ) (s : Finset (Fin m)) : Poly A (m+1) n := - (freeBase c * ∏ j ∈ s, rowLinear j.castSucc d) * rowLinear (Fin.last m) d ^ (b-s.card) - -lemma shift_freeBase {r m n : ℕ} (c : Fin r → Fin n → A) (u : Fin m) : - shift (Fin.last m) u.castSucc (freeBase c) = 0 := by - apply derivation_prod_zero - intro j _ - apply derivation_prod_zero - intro i _ - simp - -lemma freeBase_degree_last {r m n : ℕ} (c : Fin r → Fin n → A) : - (freeBase (m := m) c).IsWeightedHomogeneous (rowWeight (Fin.last m)) 0 := by - have hi (j : Fin m) (i : Fin r) : (rowLinear j.castSucc (c i)).IsWeightedHomogeneous - (rowWeight (Fin.last m)) 0 := by simpa using rowLinear_homogeneous j.castSucc (Fin.last m) (c i) - have hj (j : Fin m) : (∏ i : Fin r, rowLinear j.castSucc (c i)).IsWeightedHomogeneous - (rowWeight (Fin.last m)) 0 := by - simpa using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hi j i) - simpa [freeBase] using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun j _ => hj j) - -lemma freeBase_degree_cast {r m n : ℕ} (c : Fin r → Fin n → A) (u : Fin m) : - (freeBase c).IsWeightedHomogeneous (rowWeight u.castSucc) r := by - classical - have hi (j : Fin m) (i : Fin r) : (rowLinear j.castSucc (c i)).IsWeightedHomogeneous - (rowWeight u.castSucc) (if j = u then 1 else 0) := by - simpa using rowLinear_homogeneous j.castSucc u.castSucc (c i) - have hj (j : Fin m) : (∏ i : Fin r, rowLinear j.castSucc (c i)).IsWeightedHomogeneous - (rowWeight u.castSucc) (if j = u then r else 0) := by - have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hi j i) - split_ifs at hh ⊢ <;> simpa using hh - simpa [freeBase] using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun j _ => hj j) - -lemma freeFamily_degree_last {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) - (b : ℕ) (s : Finset (Fin m)) : - (freeFamily c d b s).IsWeightedHomogeneous (rowWeight (Fin.last m)) (b-s.card) := by - have hi (j : Fin m) : (rowLinear j.castSucc d).IsWeightedHomogeneous - (rowWeight (Fin.last m)) 0 := by simpa using rowLinear_homogeneous j.castSucc (Fin.last m) d - have hs : (∏ j ∈ s, rowLinear j.castSucc d).IsWeightedHomogeneous (rowWeight (Fin.last m)) 0 := by - simpa using MvPolynomial.IsWeightedHomogeneous.prod s _ _ (fun j _ => hi j) - have ht : (rowLinear (Fin.last m) d).IsWeightedHomogeneous (rowWeight (Fin.last m)) 1 := by - simpa using rowLinear_homogeneous (Fin.last m) (Fin.last m) d - simpa [freeFamily] using ((freeBase_degree_last c).mul hs).mul (ht.pow (b-s.card)) - -lemma freeFamily_degree_cast {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) - (b : ℕ) (s : Finset (Fin m)) (u : Fin m) (hu : u ∉ s) : - (freeFamily c d b s).IsWeightedHomogeneous (rowWeight u.castSucc) r := by - have hi (j : Fin m) (hj : j ∈ s) : (rowLinear j.castSucc d).IsWeightedHomogeneous - (rowWeight u.castSucc) 0 := by - have hne : j ≠ u := ne_of_mem_of_not_mem hj hu - simpa [hne] using rowLinear_homogeneous j.castSucc u.castSucc d - have hs : (∏ j ∈ s, rowLinear j.castSucc d).IsWeightedHomogeneous (rowWeight u.castSucc) 0 := by - simpa using MvPolynomial.IsWeightedHomogeneous.prod s _ _ hi - have ht : (rowLinear (Fin.last m) d).IsWeightedHomogeneous (rowWeight u.castSucc) 0 := by - simpa [Ne.symm (Fin.castSucc_ne_last u)] using rowLinear_homogeneous (Fin.last m) u.castSucc d - simpa [freeFamily] using ((freeBase_degree_cast c u).mul hs).mul (ht.pow (b-s.card)) - -lemma shift_freeFamily {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) - (b : ℕ) (s : Finset (Fin m)) (u : Fin m) (hu : u ∉ s) (hs : s.card < b) : - shift (Fin.last m) u.castSucc (freeFamily c d b s) = - (b-s.card) • freeFamily c d b (insert u s) := by - classical - let D := shift (A := A) (n := n) (Fin.last m) u.castSucc - have hG : D (freeBase c * ∏ j ∈ s, rowLinear j.castSucc d) = 0 := by - rw [D.leibniz, shift_freeBase] - have hz : D (∏ j ∈ s, rowLinear j.castSucc d) = 0 := by - apply derivation_prod_zero - intro j _ - simp [D] - rw [hz] - simp - have hder := pow_apply_pow D (f := rowLinear (Fin.last m) d) - (g := rowLinear u.castSucc d) (by simp [D]) (by simp [D]) (b-s.card) 1 (by omega) - simp only [pow_one, Derivation.coeFn_coe, Nat.descFactorial_one] at hder - change D (_ * _) = _ - rw [D.leibniz, hG, smul_zero, add_zero, hder] - simp only [freeFamily, Finset.prod_insert hu, Finset.card_insert_of_notMem hu, - smul_eq_mul, nsmul_eq_mul] - have he : b-s.card-1 = b-(s.card+1) := by omega - rw [he] - ring - -theorem freeFamily_zero [Algebra ℂ A] {r m n b : ℕ} - (c : Fin r → Fin n → A) (d : Fin n → A) (l : A →ₗ[ℂ] ℂ) - (hb : m+r ≤ b) (hz : mapCoeffs l (freeFamily (m := m) c d b Finset.univ) = 0) : - mapCoeffs l (freeFamily (m := m) c d b ∅) = 0 := by - classical - have ht (t : Finset (Fin m)) : - mapCoeffs l (freeFamily c d b (Finset.univ \ t)) = 0 := by - induction t using Finset.induction_on with - | empty => simpa using hz - | insert u t hu ih => - let s : Finset (Fin m) := Finset.univ \ insert u t - have hus : u ∉ s := by simp [s] - have hse : insert u s = Finset.univ \ t := by - ext i - by_cases hi : i = u <;> simp [s, hi, hu] - have hcard : s.card + 1 ≤ m := by - calc - s.card + 1 = (insert u s).card := (Finset.card_insert_of_notMem hus).symm - _ ≤ (Finset.univ : Finset (Fin m)).card := Finset.card_le_card (Finset.subset_univ _) - _ = m := by simp - change mapCoeffs l (freeFamily c d b s) = 0 - apply Differential.shift_kernel_zero (u := Fin.last m) (v := u.castSucc) (Ne.symm (Fin.castSucc_ne_last u)) - (homogeneous_mapCoeffs l _ (freeFamily_degree_last c d b s)) - (homogeneous_mapCoeffs l _ (freeFamily_degree_cast c d b s u hus)) (by omega) - change shift (Fin.last m) u.castSucc (mapCoeffs l (freeFamily c d b s)) = 0 - rw [← mapCoeffs_shift, shift_freeFamily c d b s u hus (by omega), hse] - change (mapCoeffsLM l) ((b-s.card) • freeFamily c d b (Finset.univ \ t)) = 0 - rw [map_nsmul] - change (b-s.card) • mapCoeffs l (freeFamily c d b (Finset.univ \ t)) = 0 - rw [ih, smul_zero] - simpa using ht Finset.univ - -end Foulkes.Vanishing - -namespace Foulkes.Vanishing -open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan - -lemma lin_binary_split {n r : ℕ} (hr : 0 < r) (c : ℂ) (x t : Fin n → ℂ) : - ∃ v : Fin r → Fin n → ℂ, lin x ^ r + c • lin t ^ r = ∏ j, lin (v j) := by - obtain ⟨v,hv⟩ := binary_split (a := 1) hr c x t - refine ⟨v, ?_⟩ - have hh := congrArg (rename (Prod.snd : Fin 1 × Fin n → Fin n)) (hv 0) - simpa [rowForm, lin] using hh - -def vecProduct {m n : ℕ} (y : Fin m → Fin n → ℂ) : S n := ∏ j, lin (y j) - -def ProductsVanish {a n : ℕ} (l : P a n →ₗ[ℂ] ℂ) (b : ℕ) : Prop := - ∀ y : Fin b → Fin n → ℂ, l (∏ j, z (y j)) = 0 - -lemma tensorRows_diag_product {a m n : ℕ} (y : Fin m → Fin n → ℂ) : - tensorRows (a := a) (fun _ => vecProduct y) = ∏ j, z (y j) := by - simp only [tensorRows, vecProduct, map_prod, rowLift_lin, z] - exact Finset.prod_comm - -lemma productsVanish_mul {a n r m : ℕ} {l : P a n →ₗ[ℂ] ℂ} - (hl : ProductsVanish l (r+m)) (u : Fin r → Fin n → ℂ) (v : Fin m → Fin n → ℂ) : - l (tensorRows (fun _ => vecProduct u * vecProduct v)) = 0 := by - have hh := hl (Fin.addCases u v) - rw [Fin.prod_univ_add] at hh - simp only [Fin.addCases_left, Fin.addCases_right] at hh - have he : tensorRows (a := a) (fun _ => vecProduct u * vecProduct v) = - (∏ i, z (u i)) * ∏ j, z (v j) := by - simp only [tensorRows, map_mul, Finset.prod_mul_distrib] - rw [← tensorRows, ← tensorRows, tensorRows_diag_product, tensorRows_diag_product] - rwa [he] - -lemma binary_step {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} - (hs : Symmetric l) (hz : ProductsVanish l (r+m)) - (x t : Fin n → ℂ) (y : Fin m → Fin n → ℂ) : - l (oneSlot (lin x ^ r * vecProduct y) (lin t ^ r * vecProduct y) (Fin.last r)) = 0 := by - apply binary_coefficient (by omega) hs - intro c - obtain ⟨u, hu⟩ := lin_binary_split hr c x t - have he : lin x ^ r * vecProduct y + c • (lin t ^ r * vecProduct y) = - vecProduct u * vecProduct y := by - rw [← smul_mul_assoc, ← add_mul, hu] - rfl - rw [he] - exact productsVanish_mul hz u y - -lemma oneSlot_last {r n : ℕ} (p q : S n) : - oneSlot p q (Fin.last r) = (∏ i : Fin r, rowLift i.castSucc p) * rowLift (Fin.last r) q := by - rw [oneSlot, tensorRows, Fin.prod_univ_castSucc] - simp only [Fin.castSucc_ne_last, ite_false, ite_true] - -def commonPower {r n : ℕ} (x : Fin n → ℂ) : P (r+1) n := - ∏ i : Fin r, rowForm i.castSucc x ^ r - -def fixedFunctional {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) (x : Fin n → ℂ) : - P (r+1) n →ₗ[ℂ] ℂ := l.comp (LinearMap.mulLeft ℂ (commonPower x)) - -@[simp] lemma fixedFunctional_apply {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) - (x : Fin n → ℂ) (f : P (r+1) n) : - fixedFunctional l x f = l (commonPower x * f) := rfl - -lemma eval_freeFamily {r m n b : ℕ} (s : Finset (Fin m)) - (w : Fin (m+1) × Fin n → ℂ) : - eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) - (freeFamily (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) - (fun k => X (Fin.last r,k)) b s) = - ((∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (fun k => w (j.castSucc,k))) * - ∏ j ∈ s, rowForm (Fin.last r) (fun k => w (j.castSucc,k))) * - rowForm (Fin.last r) (fun k => w (Fin.last m,k)) ^ (b-s.card) := by - simp only [freeFamily, freeBase, map_mul, map_prod, map_pow, GenericShift.eval_rowLinear, rowForm] - -lemma free_last_slot {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} - (hs : Symmetric l) (hz : ProductsVanish l (r+m)) - (x t : Fin n → ℂ) (y : Fin m → Fin n → ℂ) : - l ((∏ i : Fin r, rowLift i.castSucc (lin x ^ r * vecProduct y)) * - rowForm (Fin.last r) t ^ (r+m)) = 0 := by - let c := fun i : Fin r => fun k : Fin n => (X (i.castSucc,k) : P (r+1) n) - let d := fun k : Fin n => (X (Fin.last r,k) : P (r+1) n) - have hfull : mapCoeffs (fixedFunctional l x) - (freeFamily (m := m) c d (r+m) Finset.univ) = 0 := by - apply MvPolynomial.funext - intro w - rw [eval_mapCoeffs] - simp only [c, d, eval_freeFamily, Finset.card_univ, Fintype.card_fin, - Nat.add_sub_cancel_right, fixedFunctional_apply, map_zero] - have hh := binary_step hr hs hz x (fun k => w (Fin.last m,k)) - (fun j k => w (j.castSucc,k)) - rw [oneSlot_last] at hh - simp only [map_mul, map_pow, rowLift_lin, vecProduct, map_prod, - Finset.prod_mul_distrib] at hh - have hcomm : (∏ i : Fin r, ∏ j : Fin m, rowForm i.castSucc (fun k => w (j.castSucc,k))) = - ∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (fun k => w (j.castSucc,k)) := Finset.prod_comm - rw [hcomm] at hh - convert hh using 1 - dsimp only [commonPower] - congr 1 - ring - have hzero := freeFamily_zero c d (fixedFunctional l x) (by omega : m+r ≤ r+m) hfull - let w : Fin (m+1) × Fin n → ℂ := fun ij => Fin.lastCases (t ij.2) (fun j => y j ij.2) ij.1 - have hh := congrArg (eval w) hzero - rw [eval_mapCoeffs] at hh - simp only [c, d, eval_freeFamily, Finset.prod_empty, Finset.card_empty, Nat.sub_zero, - mul_one, fixedFunctional_apply, map_zero, w, Fin.lastCases_castSucc, Fin.lastCases_last] at hh - simp only [commonPower] at hh - simp only [map_mul, map_pow, rowLift_lin, vecProduct, map_prod, Finset.prod_mul_distrib] - have hcomm : (∏ i : Fin r, ∏ j : Fin m, rowForm i.castSucc (y j)) = - ∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (y j) := Finset.prod_comm - rw [hcomm] - simpa only [mul_assoc] using hh - -end Foulkes.Vanishing - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.InvariantPolarization + +namespace OAI + +noncomputable section + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan + +lemma binary_split {a n r : ℕ} (hr : 0 < r) (c : ℂ) (x t : Fin n → ℂ) : + ∃ v : Fin r → Fin n → ℂ, ∀ i : Fin a, + rowForm i x ^ r + c • rowForm i t ^ r = ∏ j, rowForm i (v j) := by + classical + obtain ⟨α, hα⟩ := IsAlgClosed.exists_pow_nat_eq (-c) hr + let ζ := Complex.exp (2 * Real.pi * Complex.I / r) + have hζ : IsPrimitiveRoot ζ r := Complex.isPrimitiveRoot_exp r hr.ne' + let S := Polynomial.nthRootsFinset r (1 : ℂ) + have hS : Fintype.card S = r := by + rw [Fintype.card_coe] + exact hζ.card_nthRootsFinset + let e : Fin r ≃ S := (Fintype.equivFinOfCardEq hS).symm + refine ⟨fun j k => x k - (α * (e j : ℂ)) * t k, ?_⟩ + intro i + apply MvPolynomial.funext + intro w + let X₀ := ∑ k, x k * w (i,k) + let Y₀ := ∑ k, t k * w (i,k) + have heval (j : Fin r) : + eval w (rowForm i (fun k => x k - α * (e j : ℂ) * t k)) = + X₀ - (e j : ℂ) * (α * Y₀) := by + simp only [rowForm, eval_sum, MvPolynomial.smul_eq_C_mul, eval_mul, eval_C, eval_X] + simp only [sub_mul, Finset.sum_sub_distrib] + dsimp [X₀, Y₀] + simp only [Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro k _ + ring + have hprod : (∏ j : Fin r, (X₀ - (e j : ℂ) * (α * Y₀))) = + ∏ z ∈ S, (X₀ - z * (α * Y₀)) := by + calc + _ = ∏ z : S, (X₀ - (z : ℂ) * (α * Y₀)) := + Fintype.prod_equiv e _ _ (fun _ => rfl) + _ = _ := Finset.prod_coe_sort S (fun z : ℂ => X₀ - z * (α * Y₀)) + simp only [eval_add, eval_pow, MvPolynomial.smul_eq_C_mul, eval_mul, eval_C, eval_prod, heval] + have hx : eval w (rowForm i x) = X₀ := by simp [rowForm, X₀, MvPolynomial.smul_eq_C_mul] + have hy : eval w (rowForm i t) = Y₀ := by simp [rowForm, Y₀, MvPolynomial.smul_eq_C_mul] + rw [hx, hy] + rw [hprod, ← hζ.pow_sub_pow_eq_prod_sub_mul X₀ (α * Y₀) hr, mul_pow, hα] + ring + +abbrev S (n : ℕ) := MvPolynomial (Fin n) ℂ + +def rowLift {a n : ℕ} (i : Fin a) : S n →ₐ[ℂ] P a n := + rename (fun k => (i,k)) + +def tensorRows {a n : ℕ} (p : Fin a → S n) : P a n := ∏ i, rowLift i (p i) + +def lin {n : ℕ} (x : Fin n → ℂ) : S n := ∑ k, x k • X k + +@[simp] lemma rowLift_lin {a n : ℕ} (i : Fin a) (x : Fin n → ℂ) : + rowLift i (lin x) = rowForm i x := by simp [rowLift, lin, rowForm] + +@[simp] lemma renameRow_rowLift {a n : ℕ} (σ : Equiv.Perm (Fin a)) + (i : Fin a) (p : S n) : renameRow σ (rowLift i p) = rowLift (σ i) p := by + simp [rowLift, renameRow, rename_rename, Function.comp_def] + +lemma renameRow_tensorRows {a n : ℕ} (σ : Equiv.Perm (Fin a)) (p : Fin a → S n) : + renameRow σ (tensorRows p) = tensorRows (fun i => p (σ.symm i)) := by + simp only [tensorRows, map_prod, renameRow_rowLift] + apply Fintype.prod_equiv σ + intro i + simp + +def Symmetric {a n : ℕ} (l : P a n →ₗ[ℂ] ℂ) : Prop := + ∀ (σ : Equiv.Perm (Fin a)) (f : P a n), l (renameRow σ f) = l f + +lemma symmetric_tensorRows {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hl : Symmetric l) + (σ : Equiv.Perm (Fin a)) (p : Fin a → S n) : + l (tensorRows (fun i => p (σ.symm i))) = l (tensorRows p) := by + rw [← renameRow_tensorRows, hl] + +def oneSlot {a n : ℕ} (p q : S n) (i : Fin a) : P a n := + tensorRows (fun j => if j = i then q else p) + +lemma oneSlot_eq {a n : ℕ} {l : P a n →ₗ[ℂ] ℂ} (hl : Symmetric l) + (p q : S n) (i j : Fin a) : l (oneSlot p q i) = l (oneSlot p q j) := by + classical + have hh := symmetric_tensorRows hl (Equiv.swap i j) (fun k => if k = j then q else p) + have he : (fun k => if (Equiv.swap i j).symm k = j then q else p) = + (fun k => if k = i then q else p) := by + funext k + simp [Equiv.swap_apply_eq_iff] + rw [he] at hh + exact hh + +lemma eval_pderiv_prod {A ι σ : Type*} [CommRing A] [Fintype ι] [DecidableEq ι] + (v : σ) (w : σ → A) (f : ι → MvPolynomial σ A) : + eval w (pderiv v (∏ i, f i)) = + ∑ i, eval w (pderiv v (f i)) * ∏ j ∈ Finset.univ.erase i, eval w (f j) := by + classical + have hs (s : Finset ι) : eval w (pderiv v (∏ i ∈ s, f i)) = + ∑ i ∈ s, eval w (pderiv v (f i)) * ∏ j ∈ s.erase i, eval w (f j) := by + induction s using Finset.induction_on with + | empty => simp + | insert u s hu ih => + rw [Finset.prod_insert hu, pderiv_mul, eval_add, eval_mul, eval_mul, ih, + Finset.sum_insert hu] + rw [Finset.erase_insert hu] + simp only [eval_prod, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro i hi + have hne : i ≠ u := ne_of_mem_of_not_mem hi hu + rw [Finset.erase_insert_of_ne hne.symm, Finset.prod_insert (by simp [hu])] + ring + exact hs Finset.univ + +lemma binary_coefficient {a n : ℕ} (ha : 0 < a) {l : P a n →ₗ[ℂ] ℂ} + (hl : Symmetric l) (p q : S n) + (hz : ∀ c : ℂ, l (tensorRows (fun _ => p + c • q)) = 0) (i : Fin a) : + l (oneSlot p q i) = 0 := by + classical + let F : MvPolynomial Unit (P a n) := + ∏ j, (C (rowLift j p) + X () * C (rowLift j q)) + have heval (c : ℂ) : eval (fun _ : Unit => algebraMap ℂ (P a n) c) F = + tensorRows (fun _ => p + c • q) := by + simp [F, tensorRows, rowLift, Algebra.smul_def] + have hF : mapCoeffs l F = 0 := by + apply MvPolynomial.funext + intro c + rw [eval_mapCoeffs] + have hc : c = fun _ : Unit => c () := funext (fun u => by cases u; rfl) + rw [hc, heval, hz, map_zero] + have hd := congrArg (eval (fun _ : Unit => (0 : ℂ))) + (congrArg (pderiv ()) hF) + rw [← mapCoeffs_pderiv, eval_mapCoeffs] at hd + have hD : eval (fun _ : Unit => algebraMap ℂ (P a n) 0) (pderiv () F) = + ∑ j, oneSlot p q j := by + dsimp only [F] + rw [eval_pderiv_prod] + apply Finset.sum_congr rfl + intro j _ + simp only [map_add, pderiv_C, pderiv_mul, pderiv_X_self, mul_zero, + add_zero, zero_add, eval_C, eval_mul, eval_X, map_zero, zero_mul] + rw [oneSlot, tensorRows, ← Finset.mul_prod_erase Finset.univ _ (a := j) (by simp)] + simp only [ite_true, map_one, one_mul] + congr 1 + apply Finset.prod_congr rfl + intro k hk + rw [ite_eq_right (Finset.mem_erase.mp hk).1] + rw [hD, map_sum] at hd + have hsum : (∑ j : Fin a, l (oneSlot p q j)) = (a : ℂ) * l (oneSlot p q i) := by + simp_rw [fun j => oneSlot_eq hl p q j i] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + rw [hsum] at hd + have haC : (a : ℂ) ≠ 0 := by exact_mod_cast ha.ne' + exact (mul_eq_zero.mp (by simpa using hd)).resolve_left haC + +end Foulkes.Vanishing + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.PolynomialSpan Foulkes.GenericShift + +variable {A : Type*} [CommRing A] + +def freeBase {r m n : ℕ} (c : Fin r → Fin n → A) : Poly A (m+1) n := + ∏ j : Fin m, ∏ i : Fin r, rowLinear j.castSucc (c i) + +def freeFamily {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) + (b : ℕ) (s : Finset (Fin m)) : Poly A (m+1) n := + (freeBase c * ∏ j ∈ s, rowLinear j.castSucc d) * rowLinear (Fin.last m) d ^ (b-s.card) + +lemma shift_freeBase {r m n : ℕ} (c : Fin r → Fin n → A) (u : Fin m) : + shift (Fin.last m) u.castSucc (freeBase c) = 0 := by + apply derivation_prod_zero + intro j _ + apply derivation_prod_zero + intro i _ + simp + +lemma freeBase_degree_last {r m n : ℕ} (c : Fin r → Fin n → A) : + (freeBase (m := m) c).IsWeightedHomogeneous (rowWeight (Fin.last m)) 0 := by + have hi (j : Fin m) (i : Fin r) : (rowLinear j.castSucc (c i)).IsWeightedHomogeneous + (rowWeight (Fin.last m)) 0 := by simpa using rowLinear_homogeneous j.castSucc (Fin.last m) (c i) + have hj (j : Fin m) : (∏ i : Fin r, rowLinear j.castSucc (c i)).IsWeightedHomogeneous + (rowWeight (Fin.last m)) 0 := by + simpa using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hi j i) + simpa [freeBase] using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun j _ => hj j) + +lemma freeBase_degree_cast {r m n : ℕ} (c : Fin r → Fin n → A) (u : Fin m) : + (freeBase c).IsWeightedHomogeneous (rowWeight u.castSucc) r := by + classical + have hi (j : Fin m) (i : Fin r) : (rowLinear j.castSucc (c i)).IsWeightedHomogeneous + (rowWeight u.castSucc) (if j = u then 1 else 0) := by + simpa using rowLinear_homogeneous j.castSucc u.castSucc (c i) + have hj (j : Fin m) : (∏ i : Fin r, rowLinear j.castSucc (c i)).IsWeightedHomogeneous + (rowWeight u.castSucc) (if j = u then r else 0) := by + have hh := MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun i _ => hi j i) + split_ifs at hh ⊢ <;> simpa using hh + simpa [freeBase] using MvPolynomial.IsWeightedHomogeneous.prod Finset.univ _ _ (fun j _ => hj j) + +lemma freeFamily_degree_last {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) + (b : ℕ) (s : Finset (Fin m)) : + (freeFamily c d b s).IsWeightedHomogeneous (rowWeight (Fin.last m)) (b-s.card) := by + have hi (j : Fin m) : (rowLinear j.castSucc d).IsWeightedHomogeneous + (rowWeight (Fin.last m)) 0 := by simpa using rowLinear_homogeneous j.castSucc (Fin.last m) d + have hs : (∏ j ∈ s, rowLinear j.castSucc d).IsWeightedHomogeneous (rowWeight (Fin.last m)) 0 := by + simpa using MvPolynomial.IsWeightedHomogeneous.prod s _ _ (fun j _ => hi j) + have ht : (rowLinear (Fin.last m) d).IsWeightedHomogeneous (rowWeight (Fin.last m)) 1 := by + simpa using rowLinear_homogeneous (Fin.last m) (Fin.last m) d + simpa [freeFamily] using ((freeBase_degree_last c).mul hs).mul (ht.pow (b-s.card)) + +lemma freeFamily_degree_cast {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) + (b : ℕ) (s : Finset (Fin m)) (u : Fin m) (hu : u ∉ s) : + (freeFamily c d b s).IsWeightedHomogeneous (rowWeight u.castSucc) r := by + have hi (j : Fin m) (hj : j ∈ s) : (rowLinear j.castSucc d).IsWeightedHomogeneous + (rowWeight u.castSucc) 0 := by + have hne : j ≠ u := ne_of_mem_of_not_mem hj hu + simpa [hne] using rowLinear_homogeneous j.castSucc u.castSucc d + have hs : (∏ j ∈ s, rowLinear j.castSucc d).IsWeightedHomogeneous (rowWeight u.castSucc) 0 := by + simpa using MvPolynomial.IsWeightedHomogeneous.prod s _ _ hi + have ht : (rowLinear (Fin.last m) d).IsWeightedHomogeneous (rowWeight u.castSucc) 0 := by + simpa [Ne.symm (Fin.castSucc_ne_last u)] using rowLinear_homogeneous (Fin.last m) u.castSucc d + simpa [freeFamily] using ((freeBase_degree_cast c u).mul hs).mul (ht.pow (b-s.card)) + +lemma shift_freeFamily {r m n : ℕ} (c : Fin r → Fin n → A) (d : Fin n → A) + (b : ℕ) (s : Finset (Fin m)) (u : Fin m) (hu : u ∉ s) (hs : s.card < b) : + shift (Fin.last m) u.castSucc (freeFamily c d b s) = + (b-s.card) • freeFamily c d b (insert u s) := by + classical + let D := shift (A := A) (n := n) (Fin.last m) u.castSucc + have hG : D (freeBase c * ∏ j ∈ s, rowLinear j.castSucc d) = 0 := by + rw [D.leibniz, shift_freeBase] + have hz : D (∏ j ∈ s, rowLinear j.castSucc d) = 0 := by + apply derivation_prod_zero + intro j _ + simp [D] + rw [hz] + simp + have hder := pow_apply_pow D (f := rowLinear (Fin.last m) d) + (g := rowLinear u.castSucc d) (by simp [D]) (by simp [D]) (b-s.card) 1 (by omega) + simp only [pow_one, Derivation.coeFn_coe, Nat.descFactorial_one] at hder + change D (_ * _) = _ + rw [D.leibniz, hG, smul_zero, add_zero, hder] + simp only [freeFamily, Finset.prod_insert hu, Finset.card_insert_of_notMem hu, + smul_eq_mul, nsmul_eq_mul] + have he : b-s.card-1 = b-(s.card+1) := by omega + rw [he] + ring + +theorem freeFamily_zero [Algebra ℂ A] {r m n b : ℕ} + (c : Fin r → Fin n → A) (d : Fin n → A) (l : A →ₗ[ℂ] ℂ) + (hb : m+r ≤ b) (hz : mapCoeffs l (freeFamily (m := m) c d b Finset.univ) = 0) : + mapCoeffs l (freeFamily (m := m) c d b ∅) = 0 := by + classical + have ht (t : Finset (Fin m)) : + mapCoeffs l (freeFamily c d b (Finset.univ \ t)) = 0 := by + induction t using Finset.induction_on with + | empty => simpa using hz + | insert u t hu ih => + let s : Finset (Fin m) := Finset.univ \ insert u t + have hus : u ∉ s := by simp [s] + have hse : insert u s = Finset.univ \ t := by + ext i + by_cases hi : i = u <;> simp [s, hi, hu] + have hcard : s.card + 1 ≤ m := by + calc + s.card + 1 = (insert u s).card := (Finset.card_insert_of_notMem hus).symm + _ ≤ (Finset.univ : Finset (Fin m)).card := Finset.card_le_card (Finset.subset_univ _) + _ = m := by simp + change mapCoeffs l (freeFamily c d b s) = 0 + apply Differential.shift_kernel_zero (u := Fin.last m) (v := u.castSucc) (Ne.symm (Fin.castSucc_ne_last u)) + (homogeneous_mapCoeffs l _ (freeFamily_degree_last c d b s)) + (homogeneous_mapCoeffs l _ (freeFamily_degree_cast c d b s u hus)) (by omega) + change shift (Fin.last m) u.castSucc (mapCoeffs l (freeFamily c d b s)) = 0 + rw [← mapCoeffs_shift, shift_freeFamily c d b s u hus (by omega), hse] + change (mapCoeffsLM l) ((b-s.card) • freeFamily c d b (Finset.univ \ t)) = 0 + rw [map_nsmul] + change (b-s.card) • mapCoeffs l (freeFamily c d b (Finset.univ \ t)) = 0 + rw [ih, smul_zero] + simpa using ht Finset.univ + +end Foulkes.Vanishing + +namespace Foulkes.Vanishing +open MvPolynomial Foulkes.Polarization Foulkes.PolynomialSpan + +lemma lin_binary_split {n r : ℕ} (hr : 0 < r) (c : ℂ) (x t : Fin n → ℂ) : + ∃ v : Fin r → Fin n → ℂ, lin x ^ r + c • lin t ^ r = ∏ j, lin (v j) := by + obtain ⟨v,hv⟩ := binary_split (a := 1) hr c x t + refine ⟨v, ?_⟩ + have hh := congrArg (rename (Prod.snd : Fin 1 × Fin n → Fin n)) (hv 0) + simpa [rowForm, lin] using hh + +def vecProduct {m n : ℕ} (y : Fin m → Fin n → ℂ) : S n := ∏ j, lin (y j) + +def ProductsVanish {a n : ℕ} (l : P a n →ₗ[ℂ] ℂ) (b : ℕ) : Prop := + ∀ y : Fin b → Fin n → ℂ, l (∏ j, z (y j)) = 0 + +lemma tensorRows_diag_product {a m n : ℕ} (y : Fin m → Fin n → ℂ) : + tensorRows (a := a) (fun _ => vecProduct y) = ∏ j, z (y j) := by + simp only [tensorRows, vecProduct, map_prod, rowLift_lin, z] + exact Finset.prod_comm + +lemma productsVanish_mul {a n r m : ℕ} {l : P a n →ₗ[ℂ] ℂ} + (hl : ProductsVanish l (r+m)) (u : Fin r → Fin n → ℂ) (v : Fin m → Fin n → ℂ) : + l (tensorRows (fun _ => vecProduct u * vecProduct v)) = 0 := by + have hh := hl (Fin.addCases u v) + rw [Fin.prod_univ_add] at hh + simp only [Fin.addCases_left, Fin.addCases_right] at hh + have he : tensorRows (a := a) (fun _ => vecProduct u * vecProduct v) = + (∏ i, z (u i)) * ∏ j, z (v j) := by + simp only [tensorRows, map_mul, Finset.prod_mul_distrib] + rw [← tensorRows, ← tensorRows, tensorRows_diag_product, tensorRows_diag_product] + rwa [he] + +lemma binary_step {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} + (hs : Symmetric l) (hz : ProductsVanish l (r+m)) + (x t : Fin n → ℂ) (y : Fin m → Fin n → ℂ) : + l (oneSlot (lin x ^ r * vecProduct y) (lin t ^ r * vecProduct y) (Fin.last r)) = 0 := by + apply binary_coefficient (by omega) hs + intro c + obtain ⟨u, hu⟩ := lin_binary_split hr c x t + have he : lin x ^ r * vecProduct y + c • (lin t ^ r * vecProduct y) = + vecProduct u * vecProduct y := by + rw [← smul_mul_assoc, ← add_mul, hu] + rfl + rw [he] + exact productsVanish_mul hz u y + +lemma oneSlot_last {r n : ℕ} (p q : S n) : + oneSlot p q (Fin.last r) = (∏ i : Fin r, rowLift i.castSucc p) * rowLift (Fin.last r) q := by + rw [oneSlot, tensorRows, Fin.prod_univ_castSucc] + simp only [Fin.castSucc_ne_last, ite_false, ite_true] + +def commonPower {r n : ℕ} (x : Fin n → ℂ) : P (r+1) n := + ∏ i : Fin r, rowForm i.castSucc x ^ r + +def fixedFunctional {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) (x : Fin n → ℂ) : + P (r+1) n →ₗ[ℂ] ℂ := l.comp (LinearMap.mulLeft ℂ (commonPower x)) + +@[simp] lemma fixedFunctional_apply {r n : ℕ} (l : P (r+1) n →ₗ[ℂ] ℂ) + (x : Fin n → ℂ) (f : P (r+1) n) : + fixedFunctional l x f = l (commonPower x * f) := rfl + +lemma eval_freeFamily {r m n b : ℕ} (s : Finset (Fin m)) + (w : Fin (m+1) × Fin n → ℂ) : + eval (fun ij => algebraMap ℂ (P (r+1) n) (w ij)) + (freeFamily (fun i : Fin r => fun k => (X (i.castSucc,k) : P (r+1) n)) + (fun k => X (Fin.last r,k)) b s) = + ((∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (fun k => w (j.castSucc,k))) * + ∏ j ∈ s, rowForm (Fin.last r) (fun k => w (j.castSucc,k))) * + rowForm (Fin.last r) (fun k => w (Fin.last m,k)) ^ (b-s.card) := by + simp only [freeFamily, freeBase, map_mul, map_prod, map_pow, GenericShift.eval_rowLinear, rowForm] + +lemma free_last_slot {r m n : ℕ} (hr : 0 < r) {l : P (r+1) n →ₗ[ℂ] ℂ} + (hs : Symmetric l) (hz : ProductsVanish l (r+m)) + (x t : Fin n → ℂ) (y : Fin m → Fin n → ℂ) : + l ((∏ i : Fin r, rowLift i.castSucc (lin x ^ r * vecProduct y)) * + rowForm (Fin.last r) t ^ (r+m)) = 0 := by + let c := fun i : Fin r => fun k : Fin n => (X (i.castSucc,k) : P (r+1) n) + let d := fun k : Fin n => (X (Fin.last r,k) : P (r+1) n) + have hfull : mapCoeffs (fixedFunctional l x) + (freeFamily (m := m) c d (r+m) Finset.univ) = 0 := by + apply MvPolynomial.funext + intro w + rw [eval_mapCoeffs] + simp only [c, d, eval_freeFamily, Finset.card_univ, Fintype.card_fin, + Nat.add_sub_cancel_right, fixedFunctional_apply, map_zero] + have hh := binary_step hr hs hz x (fun k => w (Fin.last m,k)) + (fun j k => w (j.castSucc,k)) + rw [oneSlot_last] at hh + simp only [map_mul, map_pow, rowLift_lin, vecProduct, map_prod, + Finset.prod_mul_distrib] at hh + have hcomm : (∏ i : Fin r, ∏ j : Fin m, rowForm i.castSucc (fun k => w (j.castSucc,k))) = + ∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (fun k => w (j.castSucc,k)) := Finset.prod_comm + rw [hcomm] at hh + convert hh using 1 + dsimp only [commonPower] + congr 1 + ring + have hzero := freeFamily_zero c d (fixedFunctional l x) (by omega : m+r ≤ r+m) hfull + let w : Fin (m+1) × Fin n → ℂ := fun ij => Fin.lastCases (t ij.2) (fun j => y j ij.2) ij.1 + have hh := congrArg (eval w) hzero + rw [eval_mapCoeffs] at hh + simp only [c, d, eval_freeFamily, Finset.prod_empty, Finset.card_empty, Nat.sub_zero, + mul_one, fixedFunctional_apply, map_zero, w, Fin.lastCases_castSucc, Fin.lastCases_last] at hh + simp only [commonPower] at hh + simp only [map_mul, map_pow, rowLift_lin, vecProduct, map_prod, Finset.prod_mul_distrib] + have hcomm : (∏ i : Fin r, ∏ j : Fin m, rowForm i.castSucc (y j)) = + ∏ j : Fin m, ∏ i : Fin r, rowForm i.castSucc (y j) := Finset.prod_comm + rw [hcomm] + simpa only [mul_assoc] using hh + +end Foulkes.Vanishing + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/YoungGram.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/YoungGram.lean index 4c6ce0249a92cbbf18fe7180dfc0b57d57ba54e2..ed7d689d197c46ec3affb8292e497236eb1826c0 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/YoungGram.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/YoungGram.lean @@ -1,72 +1,72 @@ -import Mathlib -import OAI.RepresentationTheory.FoulkesSixth.ColorOrbits -import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm - -namespace OAI - -noncomputable section - -namespace Foulkes.Young -open MvPolynomial Foulkes.Complete Finset Module - -instance finiteContingency {A B : Type*} [Fintype A] [Fintype B] - (mu : A → ℕ) (nu : B → ℕ) : Finite (Contingency mu nu) := by - classical - let f : Contingency mu nu → (∀ a : A, B → Fin (mu a + 1)) := fun M a b => - ⟨M.val a b, by - have hh := Finset.single_le_sum (f := M.val a) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) - rw [M.property.1 a] at hh - omega⟩ - apply Finite.of_injective f - intro M N h - apply Subtype.ext - ext a b - exact congrArg Fin.val (congrFun (congrFun h a) b) - -def rowChoicesEquiv {A B : Type*} [Fintype A] [Fintype B] - (mu : A → ℕ) (nu : B → ℕ) : - {r : ∀ a, Degree B (mu a) // (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu} ≃ - Contingency mu nu where - toFun r := ⟨fun a b => (r.val a).val b, - (fun a => (Finsupp.degree_eq_sum _).symm.trans (r.val a).property), - fun b => by simpa only [Finsupp.coe_finsetSum, Finset.sum_apply, Finsupp.coe_equivFunOnFinite_symm] - using congrArg (fun f : B →₀ ℕ => f b) r.property⟩ - invFun M := ⟨fun a => ⟨Finsupp.equivFunOnFinite.symm (M.val a), by - rw [Finsupp.degree_eq_sum] - exact M.property.1 a⟩, by - ext b - rw [Finsupp.finsetSum_apply] - exact M.property.2 b⟩ - left_inv r := by apply Subtype.ext; funext a; apply Subtype.ext; ext b; rfl - right_inv M := rfl - -theorem coeff_product_h {A B : Type*} [Fintype A] [Fintype B] - (mu : A → ℕ) (nu : B → ℕ) : - (∏ a, h B (mu a)).coeff (Finsupp.equivFunOnFinite.symm nu) = - (Nat.card (Contingency mu nu) : ℤ) := by - classical - have he : (∏ a, h B (mu a)) = ∑ r : ∀ a, Degree B (mu a), - monomial (∑ a, (r a).val) (1 : ℤ) := by - simp only [h, Fintype.prod_sum, ← monomial_sum_one] - rw [he, coeff_sum] - simp only [coeff_monomial] - have hh : (∑ r : ∀ a, Degree B (mu a), - if (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu then (1 : ℤ) else 0) = - (Nat.card {r : ∀ a, Degree B (mu a) // - (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu} : ℤ) := by - simp [Nat.card_eq_fintype_card, Fintype.card_subtype] - rw [hh, Nat.card_congr (rowChoicesEquiv mu nu)] - -theorem young_hom_as_coefficient {K D A B : Type*} [Field K] - [Fintype D] [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) - (hnu : ∑ b, nu b = Fintype.card D) : - (finrank K ((permRep K (Equiv.Perm D) (Coloring D A mu)).IntertwiningMap - (permRep K (Equiv.Perm D) (Coloring D B nu))) : ℤ) = - (∏ b, h A (nu b)).coeff (Finsupp.equivFunOnFinite.symm mu) := by - rw [young_hom_finrank mu nu hnu, coeff_product_h] - -end Foulkes.Young - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.FoulkesSixth.ColorOrbits +import OAI.RepresentationTheory.FoulkesSixth.HomogeneousPlethysm + +namespace OAI + +noncomputable section + +namespace Foulkes.Young +open MvPolynomial Foulkes.Complete Finset Module + +instance finiteContingency {A B : Type*} [Fintype A] [Fintype B] + (mu : A → ℕ) (nu : B → ℕ) : Finite (Contingency mu nu) := by + classical + let f : Contingency mu nu → (∀ a : A, B → Fin (mu a + 1)) := fun M a b => + ⟨M.val a b, by + have hh := Finset.single_le_sum (f := M.val a) (fun _ _ => Nat.zero_le _) (Finset.mem_univ b) + rw [M.property.1 a] at hh + omega⟩ + apply Finite.of_injective f + intro M N h + apply Subtype.ext + ext a b + exact congrArg Fin.val (congrFun (congrFun h a) b) + +def rowChoicesEquiv {A B : Type*} [Fintype A] [Fintype B] + (mu : A → ℕ) (nu : B → ℕ) : + {r : ∀ a, Degree B (mu a) // (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu} ≃ + Contingency mu nu where + toFun r := ⟨fun a b => (r.val a).val b, + (fun a => (Finsupp.degree_eq_sum _).symm.trans (r.val a).property), + fun b => by simpa only [Finsupp.coe_finsetSum, Finset.sum_apply, Finsupp.coe_equivFunOnFinite_symm] + using congrArg (fun f : B →₀ ℕ => f b) r.property⟩ + invFun M := ⟨fun a => ⟨Finsupp.equivFunOnFinite.symm (M.val a), by + rw [Finsupp.degree_eq_sum] + exact M.property.1 a⟩, by + ext b + rw [Finsupp.finsetSum_apply] + exact M.property.2 b⟩ + left_inv r := by apply Subtype.ext; funext a; apply Subtype.ext; ext b; rfl + right_inv M := rfl + +theorem coeff_product_h {A B : Type*} [Fintype A] [Fintype B] + (mu : A → ℕ) (nu : B → ℕ) : + (∏ a, h B (mu a)).coeff (Finsupp.equivFunOnFinite.symm nu) = + (Nat.card (Contingency mu nu) : ℤ) := by + classical + have he : (∏ a, h B (mu a)) = ∑ r : ∀ a, Degree B (mu a), + monomial (∑ a, (r a).val) (1 : ℤ) := by + simp only [h, Fintype.prod_sum, ← monomial_sum_one] + rw [he, coeff_sum] + simp only [coeff_monomial] + have hh : (∑ r : ∀ a, Degree B (mu a), + if (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu then (1 : ℤ) else 0) = + (Nat.card {r : ∀ a, Degree B (mu a) // + (∑ a, (r a).val) = Finsupp.equivFunOnFinite.symm nu} : ℤ) := by + simp [Nat.card_eq_fintype_card, Fintype.card_subtype] + rw [hh, Nat.card_congr (rowChoicesEquiv mu nu)] + +theorem young_hom_as_coefficient {K D A B : Type*} [Field K] + [Fintype D] [Fintype A] [Fintype B] (mu : A → ℕ) (nu : B → ℕ) + (hnu : ∑ b, nu b = Fintype.card D) : + (finrank K ((permRep K (Equiv.Perm D) (Coloring D A mu)).IntertwiningMap + (permRep K (Equiv.Perm D) (Coloring D B nu))) : ℤ) = + (∏ b, h A (nu b)).coeff (Finsupp.equivFunOnFinite.symm mu) := by + rw [young_hom_finrank mu nu hnu, coeff_product_h] + +end Foulkes.Young + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/FoulkesSixth/YoungModules.lean b/lean/OAI/RepresentationTheory/FoulkesSixth/YoungModules.lean index 3861e577b3d2a8de2bbe4256354ff2b5794f9a2e..e10f5cde7537d6822df78c62f76b353fc1b99613 100644 --- a/lean/OAI/RepresentationTheory/FoulkesSixth/YoungModules.lean +++ b/lean/OAI/RepresentationTheory/FoulkesSixth/YoungModules.lean @@ -1,129 +1,129 @@ -import Mathlib - -namespace OAI - -noncomputable section - -namespace Foulkes.Young -open Module Representation Finset - -section Permutation -variable {K G X Y : Type*} [Field K] [Group G] - [Fintype X] [Fintype Y] [MulAction G X] [MulAction G Y] - -def permRep (K G X : Type*) [Field K] [Group G] [MulAction G X] : - Representation K G (X → K) where - toFun g := LinearMap.pi fun x => LinearMap.proj (g⁻¹ • x) - map_one' := by ext f x; simp - map_mul' g h := by ext f x; simp [mul_smul] - -omit [Fintype X] in -@[simp] lemma permRep_apply (g : G) (f : X → K) (x : X) : - permRep K G X g f x = f (g⁻¹ • x) := rfl - -omit [Fintype X] in -@[simp] lemma permRep_single [DecidableEq X] (g : G) (x : X) (r : K) : - permRep K G X g (Pi.single x r) = Pi.single (g • x) r := by - ext y - by_cases h : y = g • x - · subst y - simp - · have h' : g⁻¹ • y ≠ x := by - intro he - apply h - have hh := congrArg (fun z => g • z) he - simpa using hh - simp [Pi.single_eq_of_ne h, Pi.single_eq_of_ne h'] - -def matrixInvariants (K G X Y : Type*) [Field K] [Group G] - [MulAction G X] [MulAction G Y] : Submodule K (Matrix Y X K) where - carrier := {M | ∀ g : G, ∀ y x, M (g • y) (g • x) = M y x} - zero_mem' := by intro g y x; rfl - add_mem' := by intro M N hM hN g y x; exact congrArg₂ (· + ·) (hM g y x) (hN g y x) - smul_mem' := by intro r M hM g y x; exact congrArg (r * ·) (hM g y x) - -omit [Fintype Y] in -lemma matrix_intertwining_iff [DecidableEq X] [DecidableEq Y] (M : Matrix Y X K) : - (∀ g : G, (Matrix.toLin' M).comp (permRep K G X g) = - (permRep K G Y g).comp (Matrix.toLin' M)) ↔ M ∈ matrixInvariants K G X Y := by - constructor - · intro h g y x - have hh := congrFun (LinearMap.congr_fun (h g) (Pi.single x 1)) (g • y) - simpa [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, Pi.single_apply, mul_ite] using hh - · intro h g - apply LinearMap.toMatrix'.injective - ext y x - simp only [LinearMap.toMatrix'_apply, LinearMap.comp_apply, permRep_single, - permRep_apply, Matrix.toLin'_apply, Matrix.mulVec, dotProduct] - simp only [Pi.single_apply, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', - Finset.mem_univ, ite_true] - simpa using h g (g⁻¹ • y) x - -def intertwinerMatrix [DecidableEq X] [DecidableEq Y] : - (permRep K G X).IntertwiningMap (permRep K G Y) ≃ₗ[K] matrixInvariants K G X Y where - toFun f := ⟨LinearMap.toMatrix' f.toLinearMap, - (matrix_intertwining_iff (LinearMap.toMatrix' f.toLinearMap)).mp (by - simpa using f.isIntertwining')⟩ - invFun M := ⟨Matrix.toLin' M.val, (matrix_intertwining_iff M.val).mpr M.property⟩ - left_inv f := by ext x; simp - right_inv M := by apply Subtype.ext; simp - map_add' f g := by apply Subtype.ext; simp - map_smul' r f := by apply Subtype.ext; simp - -end Permutation - -section Quotient -variable {K G Z : Type*} [Field K] [Group G] [MulAction G Z] - -def orbitFunctions (K G Z : Type*) [Field K] [Group G] [MulAction G Z] : - Submodule K (Z → K) where - carrier := {f | ∀ g : G, ∀ z, f (g • z) = f z} - zero_mem' := by intro g z; rfl - add_mem' := by intro f h hf hh g z; exact congrArg₂ (· + ·) (hf g z) (hh g z) - smul_mem' := by intro r f hf g z; exact congrArg (r * ·) (hf g z) - -def orbitFunctionsEquiv : orbitFunctions K G Z ≃ₗ[K] (MulAction.orbitRel.Quotient G Z → K) where - toFun f := Quotient.lift f.val (by - intro x y h - obtain ⟨g,hg⟩ := h - rw [← hg] - exact f.property g y) - invFun f := ⟨fun z => f (Quotient.mk (MulAction.orbitRel G Z) z), by - intro g z - apply congrArg f - exact Quotient.sound (show MulAction.orbitRel G Z (g • z) z from ⟨g,rfl⟩)⟩ - left_inv f := rfl - right_inv f := by funext q; induction q using Quotient.inductionOn; rfl - map_add' f h := by funext q; induction q using Quotient.inductionOn; rfl - map_smul' r f := by funext q; induction q using Quotient.inductionOn; rfl - -end Quotient - -section OrbitGram -variable {K G X Y : Type*} [Field K] [Group G] - [Fintype X] [Fintype Y] [MulAction G X] [MulAction G Y] - -def matrixOrbitEquiv : matrixInvariants K G X Y ≃ₗ[K] orbitFunctions K G (Y × X) where - toFun M := ⟨fun z => M.val z.1 z.2, fun g z => M.property g z.1 z.2⟩ - invFun f := ⟨fun y x => f.val (y,x), fun g y x => f.property g (y,x)⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -theorem perm_hom_finrank : - finrank K ((permRep K G X).IntertwiningMap (permRep K G Y)) = - Nat.card (MulAction.orbitRel.Quotient G (Y × X)) := by - classical - let e := (intertwinerMatrix (K := K) (G := G) (X := X) (Y := Y)).trans - (matrixOrbitEquiv.trans orbitFunctionsEquiv) - rw [e.finrank_eq] - let := Fintype.ofFinite (MulAction.orbitRel.Quotient G (Y × X)) - simp [Nat.card_eq_fintype_card] - -end OrbitGram -end Foulkes.Young - -end - -end OAI +import Mathlib + +namespace OAI + +noncomputable section + +namespace Foulkes.Young +open Module Representation Finset + +section Permutation +variable {K G X Y : Type*} [Field K] [Group G] + [Fintype X] [Fintype Y] [MulAction G X] [MulAction G Y] + +def permRep (K G X : Type*) [Field K] [Group G] [MulAction G X] : + Representation K G (X → K) where + toFun g := LinearMap.pi fun x => LinearMap.proj (g⁻¹ • x) + map_one' := by ext f x; simp + map_mul' g h := by ext f x; simp [mul_smul] + +omit [Fintype X] in +@[simp] lemma permRep_apply (g : G) (f : X → K) (x : X) : + permRep K G X g f x = f (g⁻¹ • x) := rfl + +omit [Fintype X] in +@[simp] lemma permRep_single [DecidableEq X] (g : G) (x : X) (r : K) : + permRep K G X g (Pi.single x r) = Pi.single (g • x) r := by + ext y + by_cases h : y = g • x + · subst y + simp + · have h' : g⁻¹ • y ≠ x := by + intro he + apply h + have hh := congrArg (fun z => g • z) he + simpa using hh + simp [Pi.single_eq_of_ne h, Pi.single_eq_of_ne h'] + +def matrixInvariants (K G X Y : Type*) [Field K] [Group G] + [MulAction G X] [MulAction G Y] : Submodule K (Matrix Y X K) where + carrier := {M | ∀ g : G, ∀ y x, M (g • y) (g • x) = M y x} + zero_mem' := by intro g y x; rfl + add_mem' := by intro M N hM hN g y x; exact congrArg₂ (· + ·) (hM g y x) (hN g y x) + smul_mem' := by intro r M hM g y x; exact congrArg (r * ·) (hM g y x) + +omit [Fintype Y] in +lemma matrix_intertwining_iff [DecidableEq X] [DecidableEq Y] (M : Matrix Y X K) : + (∀ g : G, (Matrix.toLin' M).comp (permRep K G X g) = + (permRep K G Y g).comp (Matrix.toLin' M)) ↔ M ∈ matrixInvariants K G X Y := by + constructor + · intro h g y x + have hh := congrFun (LinearMap.congr_fun (h g) (Pi.single x 1)) (g • y) + simpa [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, Pi.single_apply, mul_ite] using hh + · intro h g + apply LinearMap.toMatrix'.injective + ext y x + simp only [LinearMap.toMatrix'_apply, LinearMap.comp_apply, permRep_single, + permRep_apply, Matrix.toLin'_apply, Matrix.mulVec, dotProduct] + simp only [Pi.single_apply, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', + Finset.mem_univ, ite_true] + simpa using h g (g⁻¹ • y) x + +def intertwinerMatrix [DecidableEq X] [DecidableEq Y] : + (permRep K G X).IntertwiningMap (permRep K G Y) ≃ₗ[K] matrixInvariants K G X Y where + toFun f := ⟨LinearMap.toMatrix' f.toLinearMap, + (matrix_intertwining_iff (LinearMap.toMatrix' f.toLinearMap)).mp (by + simpa using f.isIntertwining')⟩ + invFun M := ⟨Matrix.toLin' M.val, (matrix_intertwining_iff M.val).mpr M.property⟩ + left_inv f := by ext x; simp + right_inv M := by apply Subtype.ext; simp + map_add' f g := by apply Subtype.ext; simp + map_smul' r f := by apply Subtype.ext; simp + +end Permutation + +section Quotient +variable {K G Z : Type*} [Field K] [Group G] [MulAction G Z] + +def orbitFunctions (K G Z : Type*) [Field K] [Group G] [MulAction G Z] : + Submodule K (Z → K) where + carrier := {f | ∀ g : G, ∀ z, f (g • z) = f z} + zero_mem' := by intro g z; rfl + add_mem' := by intro f h hf hh g z; exact congrArg₂ (· + ·) (hf g z) (hh g z) + smul_mem' := by intro r f hf g z; exact congrArg (r * ·) (hf g z) + +def orbitFunctionsEquiv : orbitFunctions K G Z ≃ₗ[K] (MulAction.orbitRel.Quotient G Z → K) where + toFun f := Quotient.lift f.val (by + intro x y h + obtain ⟨g,hg⟩ := h + rw [← hg] + exact f.property g y) + invFun f := ⟨fun z => f (Quotient.mk (MulAction.orbitRel G Z) z), by + intro g z + apply congrArg f + exact Quotient.sound (show MulAction.orbitRel G Z (g • z) z from ⟨g,rfl⟩)⟩ + left_inv f := rfl + right_inv f := by funext q; induction q using Quotient.inductionOn; rfl + map_add' f h := by funext q; induction q using Quotient.inductionOn; rfl + map_smul' r f := by funext q; induction q using Quotient.inductionOn; rfl + +end Quotient + +section OrbitGram +variable {K G X Y : Type*} [Field K] [Group G] + [Fintype X] [Fintype Y] [MulAction G X] [MulAction G Y] + +def matrixOrbitEquiv : matrixInvariants K G X Y ≃ₗ[K] orbitFunctions K G (Y × X) where + toFun M := ⟨fun z => M.val z.1 z.2, fun g z => M.property g z.1 z.2⟩ + invFun f := ⟨fun y x => f.val (y,x), fun g y x => f.property g (y,x)⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +theorem perm_hom_finrank : + finrank K ((permRep K G X).IntertwiningMap (permRep K G Y)) = + Nat.card (MulAction.orbitRel.Quotient G (Y × X)) := by + classical + let e := (intertwinerMatrix (K := K) (G := G) (X := X) (Y := Y)).trans + (matrixOrbitEquiv.trans orbitFunctionsEquiv) + rw [e.finrank_eq] + let := Fintype.ofFinite (MulAction.orbitRel.Quotient G (Y × X)) + simp [Nat.card_eq_fintype_card] + +end OrbitGram +end Foulkes.Young + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/GraphModels/Bundles.lean b/lean/OAI/RepresentationTheory/GraphModels/Bundles.lean index 0f9520c8dc947b3ce8c80b74cdd0c5c6167cf290..e25182c4438d43cb0d8bd2961cb7160dcead69f0 100644 --- a/lean/OAI/RepresentationTheory/GraphModels/Bundles.lean +++ b/lean/OAI/RepresentationTheory/GraphModels/Bundles.lean @@ -1,477 +1,477 @@ -import Mathlib -import OAI.GroupTheory.ArithmeticGerms.Basic - -namespace OAI - -/-! Projective Hilbert bundles and exact induction. -/ - -namespace GermBundles -attribute [local instance] Classical.propDecidable -open scoped BigOperators InnerProductSpace - -structure ScalarCocycle (K : Type*) [Group K] where - val : K → K → Circle - mul_assoc : ∀ g h j, val g h * val (g * h) j = val h j * val g (h * j) - one_left : ∀ g, val 1 g = 1 - one_right : ∀ g, val g 1 = 1 - -section Bundles - -variable {K X : Type*} [Group K] [MulAction K X] -variable (α : ScalarCocycle K) (E : X → Type*) -variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] - -attribute [local instance] Classical.propDecidable - -structure ProjectiveBundle where - action : K → lp E 2 ≃ₗᵢ[ℂ] lp E 2 - fibre : ∀ (k : K) (x y : X), k • x = y → E x ≃ₗᵢ[ℂ] E y - action_single : ∀ (k : K) (x y : X) (h : k • x = y) (v : E x), - action k (lp.single 2 x v) = lp.single 2 y (fibre k x y h v) - action_one : ∀ v, action 1 v = v - action_mul : ∀ g h v, action g (action h v) = - (α.val g h : ℂ) • action (g * h) v - -variable {α E} - -variable {F : X → Type*} -variable [∀ x, NormedAddCommGroup (F x)] [∀ x, InnerProductSpace ℂ (F x)] - -def Intertwines (B : ProjectiveBundle α E) (C : ProjectiveBundle α F) - (T : lp E 2 →L[ℂ] lp F 2) : Prop := - ∀ k v, T (B.action k v) = C.action k (T v) - -end Bundles - -section BuildBundle - -variable {X : Type*} {E F : X → Type*} -variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] -variable [∀ x, NormedAddCommGroup (F x)] [∀ x, InnerProductSpace ℂ (F x)] - -private theorem relabel_pi_apply (e : X ≃ X) - (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) (f : ∀ x, E x) (x : X) : - u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (f (e.symm (e x))) = - u x (e x) rfl (f x) := by - have haux (z : X) (hz : z = x) (he : e z = e x) : - u z (e x) he (f z) = u x (e x) rfl (f x) := by - subst z - rfl - exact haux (e.symm (e x)) (e.symm_apply_apply x) (e.apply_symm_apply (e x)) - -private theorem relabel_pi_right (e : X ≃ X) - (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) (f : ∀ x, F x) (y : X) : - u (e.symm y) y (e.apply_symm_apply y) - ((u (e.symm y) (e (e.symm y)) rfl).symm (f (e (e.symm y)))) = f y := by - have haux (x y : X) (he : e x = y) : - u x y he ((u x (e x) rfl).symm (f (e x))) = f y := by - subst y - exact (u x (e x) rfl).apply_symm_apply _ - exact haux (e.symm y) y (e.apply_symm_apply y) - -noncomputable def relabel (e : X ≃ X) - (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) : lp E 2 ≃ₗᵢ[ℂ] lp F 2 where - toLinearEquiv := - { toFun := fun v => ⟨fun y => u (e.symm y) y (e.apply_symm_apply y) (v (e.symm y)), by - apply memℓp_gen - convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.symm.injective using 1 - all_goals first | rfl | (simp only [LinearIsometryEquiv.norm_map]; rfl)⟩ - invFun := fun v => ⟨fun x => (u x (e x) rfl).symm (v (e x)), by - apply memℓp_gen - convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.injective using 1 - all_goals first | rfl | (simp only [LinearIsometryEquiv.norm_map]; rfl)⟩ - left_inv := by - intro v - apply lp.ext - funext x - change (u x (e x) rfl).symm - (u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (v.val (e.symm (e x)))) = v.val x - exact (congrArg (u x (e x) rfl).symm (relabel_pi_apply e u (fun i => v i) x)).trans - ((u x (e x) rfl).symm_apply_apply (v x)) - right_inv := by - intro v - apply lp.ext - funext y - exact relabel_pi_right e u (fun i => v i) y - map_add' := by - intro v w - apply lp.ext - funext y - change u _ _ _ (v _ + w _) = u _ _ _ (v _) + u _ _ _ (w _) - exact map_add _ _ _ - map_smul' := by - intro a v - apply lp.ext - funext y - change u _ _ _ (a • v _) = a • u _ _ _ (v _) - exact map_smul _ _ _ } - norm_map' := by - intro v - rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] - congr 1 - change (∑' y, ‖u (e.symm y) y (e.apply_symm_apply y) (v (e.symm y))‖ ^ (2 : ENNReal).toReal) = _ - simp only [LinearIsometryEquiv.norm_map] - convert! e.symm.tsum_eq (fun x => ‖v x‖ ^ (2 : ENNReal).toReal) using 1 - -theorem relabel_apply (e : X ≃ X) (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) - (v : lp E 2) (x y : X) (h : e x = y) : relabel e u v y = u x y h (v x) := by - subst y - change u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (v.val (e.symm (e x))) = u x (e x) rfl (v.val x) - exact relabel_pi_apply e u (fun i => v i) x - -theorem relabel_single (e : X ≃ X) (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) - (x y : X) (h : e x = y) (v : E x) : - relabel e u (lp.single 2 x v) = lp.single 2 y (u x y h v) := by - apply lp.ext - funext z - by_cases hz : z = y - · subst z - rw [relabel_apply e u _ x y h, lp.single_apply_self, lp.single_apply_self] - · have hn : e.symm z ≠ x := by - intro he - apply hz - rw [← h, ← he, e.apply_symm_apply] - change u (e.symm z) z (e.apply_symm_apply z) ((lp.single 2 x v) (e.symm z)) = _ - rw [lp.single_apply_ne 2 x v hn, map_zero, lp.single_apply_ne 2 y _ hz] - -end BuildBundle - -section FibreSystem - -variable {K X : Type*} [Group K] [MulAction K X] -variable (α : ScalarCocycle K) (E : X → Type*) -variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] - -structure FibreSystem where - unitary : ∀ (k : K) (x y : X), k • x = y → E x ≃ₗᵢ[ℂ] E y - one : ∀ x v, unitary 1 x x (one_smul K x) v = v - mul : ∀ g h x y z (hy : h • x = y) (hz : g • y = z) (hgh : (g * h) • x = z) v, - unitary g y z hz (unitary h x y hy v) = (α.val g h : ℂ) • unitary (g * h) x z hgh v - -variable {α E} - -noncomputable def FibreSystem.toBundle (U : FibreSystem α E) : ProjectiveBundle α E where - action k := relabel (MulAction.toPerm k) (U.unitary k) - fibre := U.unitary - action_single k x y h v := relabel_single (MulAction.toPerm k) (U.unitary k) x y h v - action_one := by - intro v - have he : (relabel (MulAction.toPerm (1 : K)) (U.unitary 1)).toContinuousLinearEquiv.toContinuousLinearMap = - ContinuousLinearMap.id ℂ (lp E 2) := by - apply lp.ext_continuousLinearMap (by norm_num) - intro x - apply ContinuousLinearMap.ext - intro w - change relabel (MulAction.toPerm (1 : K)) (U.unitary 1) (lp.single 2 x w) = lp.single 2 x w - rw [relabel_single (MulAction.toPerm (1 : K)) (U.unitary 1) x x (one_smul K x), U.one] - exact DFunLike.congr_fun he v - action_mul := by - intro g h v - have he : - (relabel (MulAction.toPerm g) (U.unitary g)).toContinuousLinearEquiv.toContinuousLinearMap.comp - (relabel (MulAction.toPerm h) (U.unitary h)).toContinuousLinearEquiv.toContinuousLinearMap = - (α.val g h : ℂ) • (relabel (MulAction.toPerm (g * h)) (U.unitary (g * h))).toContinuousLinearEquiv.toContinuousLinearMap := by - apply lp.ext_continuousLinearMap (by norm_num) - intro x - apply ContinuousLinearMap.ext - intro w - change relabel (MulAction.toPerm g) (U.unitary g) - (relabel (MulAction.toPerm h) (U.unitary h) (lp.single 2 x w)) = - (α.val g h : ℂ) • relabel (MulAction.toPerm (g * h)) (U.unitary (g * h)) (lp.single 2 x w) - rw [relabel_single (MulAction.toPerm h) (U.unitary h) x (h • x) rfl, - relabel_single (MulAction.toPerm g) (U.unitary g) (h • x) ((g * h) • x) (mul_smul g h x).symm, - relabel_single (MulAction.toPerm (g * h)) (U.unitary (g * h)) x ((g * h) • x) rfl] - erw [U.mul g h x (h • x) ((g * h) • x) rfl (mul_smul g h x).symm rfl w, - lp.single_smul] - exact DFunLike.congr_fun he v - -end FibreSystem - -noncomputable section ExactInduction - -attribute [local instance] Classical.propDecidable - -variable {K : Type*} [Group K] - -def ScalarCocycle.restrict (α : ScalarCocycle K) (C : Subgroup K) : ScalarCocycle C where - val g h := α.val g h - mul_assoc g h j := α.mul_assoc g h j - one_left g := α.one_left g - one_right g := α.one_right g - -structure ProjectiveRepresentation (α : ScalarCocycle K) (V : Type*) - [NormedAddCommGroup V] [InnerProductSpace ℂ V] where - unitary : K → V ≃ₗᵢ[ℂ] V - one : ∀ v, unitary 1 v = v - mul : ∀ g h v, unitary g (unitary h v) = (α.val g h : ℂ) • unitary (g * h) v - -variable (C : Subgroup K) - -structure CosetSection where - repr : K ⧸ C → K - repr_spec : ∀ x, QuotientGroup.mk (repr x) = x - repr_one : repr (QuotientGroup.mk 1) = 1 - -noncomputable def chooseCosetSection : CosetSection C where - repr x := if x = QuotientGroup.mk 1 then 1 else x.out - repr_spec x := by - split_ifs with h - · exact h.symm - · exact QuotientGroup.out_eq' x - repr_one := by simp - -variable {C} - -def CosetSection.correction (r : CosetSection C) (s : K) (x : K ⧸ C) : C := - ⟨(r.repr (s • x))⁻¹ * s * r.repr x, by - rw [mul_assoc] - apply QuotientGroup.eq.mp - rw [r.repr_spec, ← smul_eq_mul, ← MulAction.Quotient.smul_mk, r.repr_spec]⟩ - -@[simp] theorem CosetSection.correction_val (r : CosetSection C) (s : K) (x : K ⧸ C) : - (r.correction s x : K) = (r.repr (s • x))⁻¹ * s * r.repr x := rfl - -@[simp] theorem CosetSection.repr_mul_correction (r : CosetSection C) (s : K) (x : K ⧸ C) : - r.repr (s • x) * (r.correction s x : K) = s * r.repr x := by - rw [correction_val] - group - -@[simp] theorem CosetSection.correction_one (r : CosetSection C) (x : K ⧸ C) : - r.correction 1 x = 1 := by - apply Subtype.ext - simp [correction] - -@[simp] theorem CosetSection.correction_mul (r : CosetSection C) (s t : K) (x : K ⧸ C) : - r.correction s (t • x) * r.correction t x = r.correction (s * t) x := by - apply Subtype.ext - simp only [Subgroup.coe_mul, correction_val, mul_smul] - group - -def CosetSection.phase (r : CosetSection C) (α : ScalarCocycle K) (s : K) (x : K ⧸ C) : Circle := - α.val s (r.repr x) / α.val (r.repr (s • x)) (r.correction s x) - -@[simp] theorem CosetSection.phase_one (r : CosetSection C) (α : ScalarCocycle K) (x : K ⧸ C) : - r.phase α 1 x = 1 := by - simp [phase, α.one_left, α.one_right] - -theorem cocycle_transport_phase (α : ScalarCocycle K) (s t x y z a b : K) - (ha : z * a = s * y) (hb : y * b = t * x) : - (α.val s y / α.val z a) * (α.val t x / α.val y b) * α.val a b = - α.val s t * (α.val (s * t) x / α.val z (a * b)) := by - have hid : α.val s y * α.val t x * α.val a b * α.val z (a * b) = - α.val s t * α.val (s * t) x * (α.val z a * α.val y b) := by - calc - _ = α.val t x * α.val s y * (α.val a b * α.val z (a * b)) := by ac_rfl - _ = α.val t x * α.val s y * (α.val z a * α.val (z * a) b) := by - rw [α.mul_assoc z a b] - _ = α.val z a * α.val t x * (α.val s y * α.val (s * y) b) := by - rw [ha] - ac_rfl - _ = α.val z a * α.val t x * (α.val y b * α.val s (y * b)) := by - rw [α.mul_assoc s y b] - _ = (α.val t x * α.val s (t * x)) * (α.val z a * α.val y b) := by - rw [hb] - ac_rfl - _ = _ := by rw [← α.mul_assoc s t x] - rw [div_mul_div_comm, div_mul_eq_mul_div, mul_div_assoc] - simpa only [mul_div_assoc] using div_eq_div_iff_mul_eq_mul.mpr hid - -theorem CosetSection.phase_mul (r : CosetSection C) (α : ScalarCocycle K) (s t : K) - (x : K ⧸ C) : - r.phase α s (t • x) * r.phase α t x * α.val (r.correction s (t • x)) (r.correction t x) = - α.val s t * r.phase α (s * t) x := by - unfold phase - have h := cocycle_transport_phase α s t (r.repr x) (r.repr (t • x)) - (r.repr (s • t • x)) (r.correction s (t • x)) (r.correction t x) - (r.repr_mul_correction s (t • x)) (r.repr_mul_correction t x) - simpa only [← Subgroup.coe_mul, correction_mul, mul_smul] using h - -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - -def circleUnitary (z : Circle) : V ≃ₗᵢ[ℂ] V where - toLinearEquiv := - { toFun := fun v => (z : ℂ) • v - invFun := fun v => ((z⁻¹ : Circle) : ℂ) • v - left_inv := by intro v; simp [smul_smul] - right_inv := by intro v; simp [smul_smul] - map_add' := by intro v w; exact smul_add _ _ _ - map_smul' := by intro a v; exact smul_comm _ _ _ } - norm_map' := by intro v; simp [norm_smul, Circle.norm_coe] - -@[simp] theorem circleUnitary_apply (z : Circle) (v : V) : circleUnitary z v = (z : ℂ) • v := rfl - -def CosetSection.inducedUnitary (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) : V ≃ₗᵢ[ℂ] V := - (γ.unitary (r.correction s x)).trans (circleUnitary (r.phase α s x)) - -@[simp] theorem CosetSection.inducedUnitary_apply (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : - r.inducedUnitary α γ s x v = (r.phase α s x : ℂ) • γ.unitary (r.correction s x) v := rfl - -@[simp] theorem CosetSection.inducedUnitary_one (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : - r.inducedUnitary α γ 1 x v = v := by - simp [γ.one] - -theorem CosetSection.inducedUnitary_mul (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (s t : K) (x : K ⧸ C) (v : V) : - r.inducedUnitary α γ s (t • x) (r.inducedUnitary α γ t x v) = - (α.val s t : ℂ) • r.inducedUnitary α γ (s * t) x v := by - simp only [inducedUnitary_apply, map_smul, γ.mul, smul_smul] - rw [correction_mul] - congr 1 - have hp := congrArg (fun z : Circle => (z : ℂ)) (r.phase_mul α s t x) - simpa only [Circle.coe_mul, ScalarCocycle.restrict, mul_assoc, mul_left_comm] using hp - -def CosetSection.change (r r' : CosetSection C) (x : K ⧸ C) : C := - ⟨(r.repr x)⁻¹ * r'.repr x, QuotientGroup.eq.mp ((r.repr_spec x).trans (r'.repr_spec x).symm)⟩ - -@[simp] theorem CosetSection.repr_mul_change (r r' : CosetSection C) (x : K ⧸ C) : - r.repr x * (r.change r' x : K) = r'.repr x := by - simp [change] - -theorem CosetSection.change_correction (r r' : CosetSection C) (s : K) (x : K ⧸ C) : - r.change r' (s • x) * r'.correction s x = r.correction s x * r.change r' x := by - apply Subtype.ext - simp only [Subgroup.coe_mul, change, correction] - group - -theorem cocycle_change_phase (α : ScalarCocycle K) (s x y c k l c' : K) - (hc : y * c = s * x) (hk : l * c' = c * k) : - (α.val y l)⁻¹ * (α.val s (x * k) / α.val (y * l) c') * α.val l c' = - (α.val s x / α.val y c) * (α.val x k)⁻¹ * α.val c k := by - have hid : α.val s (x * k) * α.val l c' * (α.val y c * α.val x k) = - α.val s x * α.val c k * (α.val (y * l) c' * α.val y l) := by - calc - _ = α.val l c' * α.val y c * (α.val x k * α.val s (x * k)) := by ac_rfl - _ = α.val l c' * α.val y c * (α.val s x * α.val (s * x) k) := by - rw [α.mul_assoc s x k] - _ = α.val s x * α.val l c' * (α.val y c * α.val (y * c) k) := by - rw [← hc] - ac_rfl - _ = α.val s x * α.val l c' * (α.val c k * α.val y (c * k)) := by - rw [α.mul_assoc y c k] - _ = α.val s x * α.val c k * (α.val l c' * α.val y (l * c')) := by - rw [← hk] - ac_rfl - _ = _ := by rw [← α.mul_assoc y l c']; ac_rfl - have hr := div_eq_div_iff_mul_eq_mul.mpr hid - convert hr using 1 <;> simp only [div_eq_mul_inv, mul_inv_rev, mul_comm, mul_left_comm, mul_assoc] - -def CosetSection.changeUnitary (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) : V ≃ₗᵢ[ℂ] V := - (γ.unitary (r.change r' x)).trans - (circleUnitary (α.val (r.repr x) (r.change r' x))⁻¹) - -@[simp] theorem CosetSection.changeUnitary_apply (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : - r.changeUnitary r' α γ x v = ((α.val (r.repr x) (r.change r' x))⁻¹ : Circle) • - γ.unitary (r.change r' x) v := rfl - -theorem CosetSection.change_phase (r r' : CosetSection C) (α : ScalarCocycle K) - (s : K) (x : K ⧸ C) : - (α.val (r.repr (s • x)) (r.change r' (s • x)))⁻¹ * r'.phase α s x * - α.val (r.change r' (s • x)) (r'.correction s x) = - r.phase α s x * (α.val (r.repr x) (r.change r' x))⁻¹ * - α.val (r.correction s x) (r.change r' x) := by - have h := cocycle_change_phase α s (r.repr x) (r.repr (s • x)) - (r.correction s x) (r.change r' x) (r.change r' (s • x)) (r'.correction s x) - (r.repr_mul_correction s x) (congrArg Subtype.val (r.change_correction r' s x)) - simpa only [phase, repr_mul_change] using h - -theorem CosetSection.changeUnitary_intertwines (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : - r.changeUnitary r' α γ (s • x) (r'.inducedUnitary α γ s x v) = - r.inducedUnitary α γ s x (r.changeUnitary r' α γ x v) := by - change ((α.val (r.repr (s • x)) (r.change r' (s • x)))⁻¹ : Circle) • - γ.unitary (r.change r' (s • x)) ((r'.phase α s x : ℂ) • γ.unitary (r'.correction s x) v) = - (r.phase α s x : ℂ) • γ.unitary (r.correction s x) - (((α.val (r.repr x) (r.change r' x))⁻¹ : Circle) • γ.unitary (r.change r' x) v) - simp only [Circle.smul_def, map_smul, γ.mul, smul_smul] - rw [change_correction] - congr 1 - have hp := congrArg (fun z : Circle => (z : ℂ)) (r.change_phase r' α s x) - simpa only [Circle.coe_mul, ScalarCocycle.restrict, mul_assoc] using hp - -end ExactInduction - -noncomputable section InducedBundle - -attribute [local instance] Classical.propDecidable - -variable {K : Type*} [Group K] {C : Subgroup K} -variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] - -local instance : DecidableEq (K ⧸ C) := Classical.decEq _ - -def CosetSection.inducedFibreSystem (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) : - FibreSystem α (fun _ : K ⧸ C => V) where - unitary s x _ _ := r.inducedUnitary α γ s x - one x v := r.inducedUnitary_one α γ x v - mul s t x y z hy hz hst v := by - subst y - exact r.inducedUnitary_mul α γ s t x v - -def CosetSection.inducedBundle (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) : - ProjectiveBundle α (fun _ : K ⧸ C => V) := - (r.inducedFibreSystem α γ).toBundle - -theorem CosetSection.inducedBundle_single (r : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : - (r.inducedBundle α γ).action s (lp.single 2 x v) = - lp.single 2 (s • x) ((r.phase α s x : ℂ) • γ.unitary (r.correction s x) v) := by - exact (r.inducedBundle α γ).action_single s x (s • x) rfl v - -def CosetSection.changeBundleUnitary (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) : - lp (fun _ : K ⧸ C => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : K ⧸ C => V) 2 := - relabel (Equiv.refl _) (fun x _ _ => r.changeUnitary r' α γ x) - -@[simp] theorem CosetSection.changeBundleUnitary_single (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : - r.changeBundleUnitary r' α γ (lp.single 2 x v) = - lp.single 2 x (r.changeUnitary r' α γ x v) := by - exact relabel_single (Equiv.refl _) (fun x _ _ => r.changeUnitary r' α γ x) x x rfl v - -theorem CosetSection.changeBundleUnitary_intertwines (r r' : CosetSection C) (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) : - Intertwines (r'.inducedBundle α γ) (r.inducedBundle α γ) - (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by - intro s v - have he : - (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap.comp - ((r'.inducedBundle α γ).action s).toContinuousLinearEquiv.toContinuousLinearMap = - ((r.inducedBundle α γ).action s).toContinuousLinearEquiv.toContinuousLinearMap.comp - (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by - apply lp.ext_continuousLinearMap (by norm_num) - intro x - apply ContinuousLinearMap.ext - intro w - change r.changeBundleUnitary r' α γ ((r'.inducedBundle α γ).action s (lp.single 2 x w)) = - (r.inducedBundle α γ).action s (r.changeBundleUnitary r' α γ (lp.single 2 x w)) - rw [(r'.inducedBundle α γ).action_single s x (s • x) rfl, - changeBundleUnitary_single, changeBundleUnitary_single, - (r.inducedBundle α γ).action_single s x (s • x) rfl] - exact congrArg (lp.single 2 (s • x)) (r.changeUnitary_intertwines r' α γ s x w) - exact DFunLike.congr_fun he v - -theorem exact_projective_induction (α : ScalarCocycle K) - (γ : ProjectiveRepresentation (α.restrict C) V) : - (∃ B : ProjectiveBundle α (fun _ : K ⧸ C => V), - ∀ s x v, B.action s (lp.single 2 x v) = - lp.single 2 (s • x) (((chooseCosetSection C).phase α s x : ℂ) • - γ.unitary ((chooseCosetSection C).correction s x) v)) ∧ - ∀ r r' : CosetSection C, - Intertwines (r'.inducedBundle α γ) (r.inducedBundle α γ) - (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by - refine ⟨⟨(chooseCosetSection C).inducedBundle α γ, ?_⟩, ?_⟩ - · exact (chooseCosetSection C).inducedBundle_single α γ - · exact fun r r' => r.changeBundleUnitary_intertwines r' α γ - -end InducedBundle - -end GermBundles - -end OAI +import Mathlib +import OAI.GroupTheory.ArithmeticGerms.Basic + +namespace OAI + +/-! Projective Hilbert bundles and exact induction. -/ + +namespace GermBundles +attribute [local instance] Classical.propDecidable +open scoped BigOperators InnerProductSpace + +structure ScalarCocycle (K : Type*) [Group K] where + val : K → K → Circle + mul_assoc : ∀ g h j, val g h * val (g * h) j = val h j * val g (h * j) + one_left : ∀ g, val 1 g = 1 + one_right : ∀ g, val g 1 = 1 + +section Bundles + +variable {K X : Type*} [Group K] [MulAction K X] +variable (α : ScalarCocycle K) (E : X → Type*) +variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] + +attribute [local instance] Classical.propDecidable + +structure ProjectiveBundle where + action : K → lp E 2 ≃ₗᵢ[ℂ] lp E 2 + fibre : ∀ (k : K) (x y : X), k • x = y → E x ≃ₗᵢ[ℂ] E y + action_single : ∀ (k : K) (x y : X) (h : k • x = y) (v : E x), + action k (lp.single 2 x v) = lp.single 2 y (fibre k x y h v) + action_one : ∀ v, action 1 v = v + action_mul : ∀ g h v, action g (action h v) = + (α.val g h : ℂ) • action (g * h) v + +variable {α E} + +variable {F : X → Type*} +variable [∀ x, NormedAddCommGroup (F x)] [∀ x, InnerProductSpace ℂ (F x)] + +def Intertwines (B : ProjectiveBundle α E) (C : ProjectiveBundle α F) + (T : lp E 2 →L[ℂ] lp F 2) : Prop := + ∀ k v, T (B.action k v) = C.action k (T v) + +end Bundles + +section BuildBundle + +variable {X : Type*} {E F : X → Type*} +variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] +variable [∀ x, NormedAddCommGroup (F x)] [∀ x, InnerProductSpace ℂ (F x)] + +private theorem relabel_pi_apply (e : X ≃ X) + (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) (f : ∀ x, E x) (x : X) : + u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (f (e.symm (e x))) = + u x (e x) rfl (f x) := by + have haux (z : X) (hz : z = x) (he : e z = e x) : + u z (e x) he (f z) = u x (e x) rfl (f x) := by + subst z + rfl + exact haux (e.symm (e x)) (e.symm_apply_apply x) (e.apply_symm_apply (e x)) + +private theorem relabel_pi_right (e : X ≃ X) + (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) (f : ∀ x, F x) (y : X) : + u (e.symm y) y (e.apply_symm_apply y) + ((u (e.symm y) (e (e.symm y)) rfl).symm (f (e (e.symm y)))) = f y := by + have haux (x y : X) (he : e x = y) : + u x y he ((u x (e x) rfl).symm (f (e x))) = f y := by + subst y + exact (u x (e x) rfl).apply_symm_apply _ + exact haux (e.symm y) y (e.apply_symm_apply y) + +noncomputable def relabel (e : X ≃ X) + (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) : lp E 2 ≃ₗᵢ[ℂ] lp F 2 where + toLinearEquiv := + { toFun := fun v => ⟨fun y => u (e.symm y) y (e.apply_symm_apply y) (v (e.symm y)), by + apply memℓp_gen + convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.symm.injective using 1 + all_goals first | rfl | (simp only [LinearIsometryEquiv.norm_map]; rfl)⟩ + invFun := fun v => ⟨fun x => (u x (e x) rfl).symm (v (e x)), by + apply memℓp_gen + convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.injective using 1 + all_goals first | rfl | (simp only [LinearIsometryEquiv.norm_map]; rfl)⟩ + left_inv := by + intro v + apply lp.ext + funext x + change (u x (e x) rfl).symm + (u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (v.val (e.symm (e x)))) = v.val x + exact (congrArg (u x (e x) rfl).symm (relabel_pi_apply e u (fun i => v i) x)).trans + ((u x (e x) rfl).symm_apply_apply (v x)) + right_inv := by + intro v + apply lp.ext + funext y + exact relabel_pi_right e u (fun i => v i) y + map_add' := by + intro v w + apply lp.ext + funext y + change u _ _ _ (v _ + w _) = u _ _ _ (v _) + u _ _ _ (w _) + exact map_add _ _ _ + map_smul' := by + intro a v + apply lp.ext + funext y + change u _ _ _ (a • v _) = a • u _ _ _ (v _) + exact map_smul _ _ _ } + norm_map' := by + intro v + rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] + congr 1 + change (∑' y, ‖u (e.symm y) y (e.apply_symm_apply y) (v (e.symm y))‖ ^ (2 : ENNReal).toReal) = _ + simp only [LinearIsometryEquiv.norm_map] + convert! e.symm.tsum_eq (fun x => ‖v x‖ ^ (2 : ENNReal).toReal) using 1 + +theorem relabel_apply (e : X ≃ X) (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) + (v : lp E 2) (x y : X) (h : e x = y) : relabel e u v y = u x y h (v x) := by + subst y + change u (e.symm (e x)) (e x) (e.apply_symm_apply (e x)) (v.val (e.symm (e x))) = u x (e x) rfl (v.val x) + exact relabel_pi_apply e u (fun i => v i) x + +theorem relabel_single (e : X ≃ X) (u : ∀ x y, e x = y → E x ≃ₗᵢ[ℂ] F y) + (x y : X) (h : e x = y) (v : E x) : + relabel e u (lp.single 2 x v) = lp.single 2 y (u x y h v) := by + apply lp.ext + funext z + by_cases hz : z = y + · subst z + rw [relabel_apply e u _ x y h, lp.single_apply_self, lp.single_apply_self] + · have hn : e.symm z ≠ x := by + intro he + apply hz + rw [← h, ← he, e.apply_symm_apply] + change u (e.symm z) z (e.apply_symm_apply z) ((lp.single 2 x v) (e.symm z)) = _ + rw [lp.single_apply_ne 2 x v hn, map_zero, lp.single_apply_ne 2 y _ hz] + +end BuildBundle + +section FibreSystem + +variable {K X : Type*} [Group K] [MulAction K X] +variable (α : ScalarCocycle K) (E : X → Type*) +variable [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℂ (E x)] + +structure FibreSystem where + unitary : ∀ (k : K) (x y : X), k • x = y → E x ≃ₗᵢ[ℂ] E y + one : ∀ x v, unitary 1 x x (one_smul K x) v = v + mul : ∀ g h x y z (hy : h • x = y) (hz : g • y = z) (hgh : (g * h) • x = z) v, + unitary g y z hz (unitary h x y hy v) = (α.val g h : ℂ) • unitary (g * h) x z hgh v + +variable {α E} + +noncomputable def FibreSystem.toBundle (U : FibreSystem α E) : ProjectiveBundle α E where + action k := relabel (MulAction.toPerm k) (U.unitary k) + fibre := U.unitary + action_single k x y h v := relabel_single (MulAction.toPerm k) (U.unitary k) x y h v + action_one := by + intro v + have he : (relabel (MulAction.toPerm (1 : K)) (U.unitary 1)).toContinuousLinearEquiv.toContinuousLinearMap = + ContinuousLinearMap.id ℂ (lp E 2) := by + apply lp.ext_continuousLinearMap (by norm_num) + intro x + apply ContinuousLinearMap.ext + intro w + change relabel (MulAction.toPerm (1 : K)) (U.unitary 1) (lp.single 2 x w) = lp.single 2 x w + rw [relabel_single (MulAction.toPerm (1 : K)) (U.unitary 1) x x (one_smul K x), U.one] + exact DFunLike.congr_fun he v + action_mul := by + intro g h v + have he : + (relabel (MulAction.toPerm g) (U.unitary g)).toContinuousLinearEquiv.toContinuousLinearMap.comp + (relabel (MulAction.toPerm h) (U.unitary h)).toContinuousLinearEquiv.toContinuousLinearMap = + (α.val g h : ℂ) • (relabel (MulAction.toPerm (g * h)) (U.unitary (g * h))).toContinuousLinearEquiv.toContinuousLinearMap := by + apply lp.ext_continuousLinearMap (by norm_num) + intro x + apply ContinuousLinearMap.ext + intro w + change relabel (MulAction.toPerm g) (U.unitary g) + (relabel (MulAction.toPerm h) (U.unitary h) (lp.single 2 x w)) = + (α.val g h : ℂ) • relabel (MulAction.toPerm (g * h)) (U.unitary (g * h)) (lp.single 2 x w) + rw [relabel_single (MulAction.toPerm h) (U.unitary h) x (h • x) rfl, + relabel_single (MulAction.toPerm g) (U.unitary g) (h • x) ((g * h) • x) (mul_smul g h x).symm, + relabel_single (MulAction.toPerm (g * h)) (U.unitary (g * h)) x ((g * h) • x) rfl] + erw [U.mul g h x (h • x) ((g * h) • x) rfl (mul_smul g h x).symm rfl w, + lp.single_smul] + exact DFunLike.congr_fun he v + +end FibreSystem + +noncomputable section ExactInduction + +attribute [local instance] Classical.propDecidable + +variable {K : Type*} [Group K] + +def ScalarCocycle.restrict (α : ScalarCocycle K) (C : Subgroup K) : ScalarCocycle C where + val g h := α.val g h + mul_assoc g h j := α.mul_assoc g h j + one_left g := α.one_left g + one_right g := α.one_right g + +structure ProjectiveRepresentation (α : ScalarCocycle K) (V : Type*) + [NormedAddCommGroup V] [InnerProductSpace ℂ V] where + unitary : K → V ≃ₗᵢ[ℂ] V + one : ∀ v, unitary 1 v = v + mul : ∀ g h v, unitary g (unitary h v) = (α.val g h : ℂ) • unitary (g * h) v + +variable (C : Subgroup K) + +structure CosetSection where + repr : K ⧸ C → K + repr_spec : ∀ x, QuotientGroup.mk (repr x) = x + repr_one : repr (QuotientGroup.mk 1) = 1 + +noncomputable def chooseCosetSection : CosetSection C where + repr x := if x = QuotientGroup.mk 1 then 1 else x.out + repr_spec x := by + split_ifs with h + · exact h.symm + · exact QuotientGroup.out_eq' x + repr_one := by simp + +variable {C} + +def CosetSection.correction (r : CosetSection C) (s : K) (x : K ⧸ C) : C := + ⟨(r.repr (s • x))⁻¹ * s * r.repr x, by + rw [mul_assoc] + apply QuotientGroup.eq.mp + rw [r.repr_spec, ← smul_eq_mul, ← MulAction.Quotient.smul_mk, r.repr_spec]⟩ + +@[simp] theorem CosetSection.correction_val (r : CosetSection C) (s : K) (x : K ⧸ C) : + (r.correction s x : K) = (r.repr (s • x))⁻¹ * s * r.repr x := rfl + +@[simp] theorem CosetSection.repr_mul_correction (r : CosetSection C) (s : K) (x : K ⧸ C) : + r.repr (s • x) * (r.correction s x : K) = s * r.repr x := by + rw [correction_val] + group + +@[simp] theorem CosetSection.correction_one (r : CosetSection C) (x : K ⧸ C) : + r.correction 1 x = 1 := by + apply Subtype.ext + simp [correction] + +@[simp] theorem CosetSection.correction_mul (r : CosetSection C) (s t : K) (x : K ⧸ C) : + r.correction s (t • x) * r.correction t x = r.correction (s * t) x := by + apply Subtype.ext + simp only [Subgroup.coe_mul, correction_val, mul_smul] + group + +def CosetSection.phase (r : CosetSection C) (α : ScalarCocycle K) (s : K) (x : K ⧸ C) : Circle := + α.val s (r.repr x) / α.val (r.repr (s • x)) (r.correction s x) + +@[simp] theorem CosetSection.phase_one (r : CosetSection C) (α : ScalarCocycle K) (x : K ⧸ C) : + r.phase α 1 x = 1 := by + simp [phase, α.one_left, α.one_right] + +theorem cocycle_transport_phase (α : ScalarCocycle K) (s t x y z a b : K) + (ha : z * a = s * y) (hb : y * b = t * x) : + (α.val s y / α.val z a) * (α.val t x / α.val y b) * α.val a b = + α.val s t * (α.val (s * t) x / α.val z (a * b)) := by + have hid : α.val s y * α.val t x * α.val a b * α.val z (a * b) = + α.val s t * α.val (s * t) x * (α.val z a * α.val y b) := by + calc + _ = α.val t x * α.val s y * (α.val a b * α.val z (a * b)) := by ac_rfl + _ = α.val t x * α.val s y * (α.val z a * α.val (z * a) b) := by + rw [α.mul_assoc z a b] + _ = α.val z a * α.val t x * (α.val s y * α.val (s * y) b) := by + rw [ha] + ac_rfl + _ = α.val z a * α.val t x * (α.val y b * α.val s (y * b)) := by + rw [α.mul_assoc s y b] + _ = (α.val t x * α.val s (t * x)) * (α.val z a * α.val y b) := by + rw [hb] + ac_rfl + _ = _ := by rw [← α.mul_assoc s t x] + rw [div_mul_div_comm, div_mul_eq_mul_div, mul_div_assoc] + simpa only [mul_div_assoc] using div_eq_div_iff_mul_eq_mul.mpr hid + +theorem CosetSection.phase_mul (r : CosetSection C) (α : ScalarCocycle K) (s t : K) + (x : K ⧸ C) : + r.phase α s (t • x) * r.phase α t x * α.val (r.correction s (t • x)) (r.correction t x) = + α.val s t * r.phase α (s * t) x := by + unfold phase + have h := cocycle_transport_phase α s t (r.repr x) (r.repr (t • x)) + (r.repr (s • t • x)) (r.correction s (t • x)) (r.correction t x) + (r.repr_mul_correction s (t • x)) (r.repr_mul_correction t x) + simpa only [← Subgroup.coe_mul, correction_mul, mul_smul] using h + +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + +def circleUnitary (z : Circle) : V ≃ₗᵢ[ℂ] V where + toLinearEquiv := + { toFun := fun v => (z : ℂ) • v + invFun := fun v => ((z⁻¹ : Circle) : ℂ) • v + left_inv := by intro v; simp [smul_smul] + right_inv := by intro v; simp [smul_smul] + map_add' := by intro v w; exact smul_add _ _ _ + map_smul' := by intro a v; exact smul_comm _ _ _ } + norm_map' := by intro v; simp [norm_smul, Circle.norm_coe] + +@[simp] theorem circleUnitary_apply (z : Circle) (v : V) : circleUnitary z v = (z : ℂ) • v := rfl + +def CosetSection.inducedUnitary (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) : V ≃ₗᵢ[ℂ] V := + (γ.unitary (r.correction s x)).trans (circleUnitary (r.phase α s x)) + +@[simp] theorem CosetSection.inducedUnitary_apply (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : + r.inducedUnitary α γ s x v = (r.phase α s x : ℂ) • γ.unitary (r.correction s x) v := rfl + +@[simp] theorem CosetSection.inducedUnitary_one (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : + r.inducedUnitary α γ 1 x v = v := by + simp [γ.one] + +theorem CosetSection.inducedUnitary_mul (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (s t : K) (x : K ⧸ C) (v : V) : + r.inducedUnitary α γ s (t • x) (r.inducedUnitary α γ t x v) = + (α.val s t : ℂ) • r.inducedUnitary α γ (s * t) x v := by + simp only [inducedUnitary_apply, map_smul, γ.mul, smul_smul] + rw [correction_mul] + congr 1 + have hp := congrArg (fun z : Circle => (z : ℂ)) (r.phase_mul α s t x) + simpa only [Circle.coe_mul, ScalarCocycle.restrict, mul_assoc, mul_left_comm] using hp + +def CosetSection.change (r r' : CosetSection C) (x : K ⧸ C) : C := + ⟨(r.repr x)⁻¹ * r'.repr x, QuotientGroup.eq.mp ((r.repr_spec x).trans (r'.repr_spec x).symm)⟩ + +@[simp] theorem CosetSection.repr_mul_change (r r' : CosetSection C) (x : K ⧸ C) : + r.repr x * (r.change r' x : K) = r'.repr x := by + simp [change] + +theorem CosetSection.change_correction (r r' : CosetSection C) (s : K) (x : K ⧸ C) : + r.change r' (s • x) * r'.correction s x = r.correction s x * r.change r' x := by + apply Subtype.ext + simp only [Subgroup.coe_mul, change, correction] + group + +theorem cocycle_change_phase (α : ScalarCocycle K) (s x y c k l c' : K) + (hc : y * c = s * x) (hk : l * c' = c * k) : + (α.val y l)⁻¹ * (α.val s (x * k) / α.val (y * l) c') * α.val l c' = + (α.val s x / α.val y c) * (α.val x k)⁻¹ * α.val c k := by + have hid : α.val s (x * k) * α.val l c' * (α.val y c * α.val x k) = + α.val s x * α.val c k * (α.val (y * l) c' * α.val y l) := by + calc + _ = α.val l c' * α.val y c * (α.val x k * α.val s (x * k)) := by ac_rfl + _ = α.val l c' * α.val y c * (α.val s x * α.val (s * x) k) := by + rw [α.mul_assoc s x k] + _ = α.val s x * α.val l c' * (α.val y c * α.val (y * c) k) := by + rw [← hc] + ac_rfl + _ = α.val s x * α.val l c' * (α.val c k * α.val y (c * k)) := by + rw [α.mul_assoc y c k] + _ = α.val s x * α.val c k * (α.val l c' * α.val y (l * c')) := by + rw [← hk] + ac_rfl + _ = _ := by rw [← α.mul_assoc y l c']; ac_rfl + have hr := div_eq_div_iff_mul_eq_mul.mpr hid + convert hr using 1 <;> simp only [div_eq_mul_inv, mul_inv_rev, mul_comm, mul_left_comm, mul_assoc] + +def CosetSection.changeUnitary (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) : V ≃ₗᵢ[ℂ] V := + (γ.unitary (r.change r' x)).trans + (circleUnitary (α.val (r.repr x) (r.change r' x))⁻¹) + +@[simp] theorem CosetSection.changeUnitary_apply (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : + r.changeUnitary r' α γ x v = ((α.val (r.repr x) (r.change r' x))⁻¹ : Circle) • + γ.unitary (r.change r' x) v := rfl + +theorem CosetSection.change_phase (r r' : CosetSection C) (α : ScalarCocycle K) + (s : K) (x : K ⧸ C) : + (α.val (r.repr (s • x)) (r.change r' (s • x)))⁻¹ * r'.phase α s x * + α.val (r.change r' (s • x)) (r'.correction s x) = + r.phase α s x * (α.val (r.repr x) (r.change r' x))⁻¹ * + α.val (r.correction s x) (r.change r' x) := by + have h := cocycle_change_phase α s (r.repr x) (r.repr (s • x)) + (r.correction s x) (r.change r' x) (r.change r' (s • x)) (r'.correction s x) + (r.repr_mul_correction s x) (congrArg Subtype.val (r.change_correction r' s x)) + simpa only [phase, repr_mul_change] using h + +theorem CosetSection.changeUnitary_intertwines (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : + r.changeUnitary r' α γ (s • x) (r'.inducedUnitary α γ s x v) = + r.inducedUnitary α γ s x (r.changeUnitary r' α γ x v) := by + change ((α.val (r.repr (s • x)) (r.change r' (s • x)))⁻¹ : Circle) • + γ.unitary (r.change r' (s • x)) ((r'.phase α s x : ℂ) • γ.unitary (r'.correction s x) v) = + (r.phase α s x : ℂ) • γ.unitary (r.correction s x) + (((α.val (r.repr x) (r.change r' x))⁻¹ : Circle) • γ.unitary (r.change r' x) v) + simp only [Circle.smul_def, map_smul, γ.mul, smul_smul] + rw [change_correction] + congr 1 + have hp := congrArg (fun z : Circle => (z : ℂ)) (r.change_phase r' α s x) + simpa only [Circle.coe_mul, ScalarCocycle.restrict, mul_assoc] using hp + +end ExactInduction + +noncomputable section InducedBundle + +attribute [local instance] Classical.propDecidable + +variable {K : Type*} [Group K] {C : Subgroup K} +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] + +local instance : DecidableEq (K ⧸ C) := Classical.decEq _ + +def CosetSection.inducedFibreSystem (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) : + FibreSystem α (fun _ : K ⧸ C => V) where + unitary s x _ _ := r.inducedUnitary α γ s x + one x v := r.inducedUnitary_one α γ x v + mul s t x y z hy hz hst v := by + subst y + exact r.inducedUnitary_mul α γ s t x v + +def CosetSection.inducedBundle (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) : + ProjectiveBundle α (fun _ : K ⧸ C => V) := + (r.inducedFibreSystem α γ).toBundle + +theorem CosetSection.inducedBundle_single (r : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (s : K) (x : K ⧸ C) (v : V) : + (r.inducedBundle α γ).action s (lp.single 2 x v) = + lp.single 2 (s • x) ((r.phase α s x : ℂ) • γ.unitary (r.correction s x) v) := by + exact (r.inducedBundle α γ).action_single s x (s • x) rfl v + +def CosetSection.changeBundleUnitary (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) : + lp (fun _ : K ⧸ C => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : K ⧸ C => V) 2 := + relabel (Equiv.refl _) (fun x _ _ => r.changeUnitary r' α γ x) + +@[simp] theorem CosetSection.changeBundleUnitary_single (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) (x : K ⧸ C) (v : V) : + r.changeBundleUnitary r' α γ (lp.single 2 x v) = + lp.single 2 x (r.changeUnitary r' α γ x v) := by + exact relabel_single (Equiv.refl _) (fun x _ _ => r.changeUnitary r' α γ x) x x rfl v + +theorem CosetSection.changeBundleUnitary_intertwines (r r' : CosetSection C) (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) : + Intertwines (r'.inducedBundle α γ) (r.inducedBundle α γ) + (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by + intro s v + have he : + (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap.comp + ((r'.inducedBundle α γ).action s).toContinuousLinearEquiv.toContinuousLinearMap = + ((r.inducedBundle α γ).action s).toContinuousLinearEquiv.toContinuousLinearMap.comp + (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by + apply lp.ext_continuousLinearMap (by norm_num) + intro x + apply ContinuousLinearMap.ext + intro w + change r.changeBundleUnitary r' α γ ((r'.inducedBundle α γ).action s (lp.single 2 x w)) = + (r.inducedBundle α γ).action s (r.changeBundleUnitary r' α γ (lp.single 2 x w)) + rw [(r'.inducedBundle α γ).action_single s x (s • x) rfl, + changeBundleUnitary_single, changeBundleUnitary_single, + (r.inducedBundle α γ).action_single s x (s • x) rfl] + exact congrArg (lp.single 2 (s • x)) (r.changeUnitary_intertwines r' α γ s x w) + exact DFunLike.congr_fun he v + +theorem exact_projective_induction (α : ScalarCocycle K) + (γ : ProjectiveRepresentation (α.restrict C) V) : + (∃ B : ProjectiveBundle α (fun _ : K ⧸ C => V), + ∀ s x v, B.action s (lp.single 2 x v) = + lp.single 2 (s • x) (((chooseCosetSection C).phase α s x : ℂ) • + γ.unitary ((chooseCosetSection C).correction s x) v)) ∧ + ∀ r r' : CosetSection C, + Intertwines (r'.inducedBundle α γ) (r.inducedBundle α γ) + (r.changeBundleUnitary r' α γ).toContinuousLinearEquiv.toContinuousLinearMap := by + refine ⟨⟨(chooseCosetSection C).inducedBundle α γ, ?_⟩, ?_⟩ + · exact (chooseCosetSection C).inducedBundle_single α γ + · exact fun r r' => r.changeBundleUnitary_intertwines r' α γ + +end InducedBundle + +end GermBundles + +end OAI diff --git a/lean/OAI/RepresentationTheory/GraphModels/NormalActions.lean b/lean/OAI/RepresentationTheory/GraphModels/NormalActions.lean index 85aeb26eead74b3ce91fbbcd23fe508df6eb5bb4..9afd4c91f68d8fa2808d25862931ca8b58cbac7f 100644 --- a/lean/OAI/RepresentationTheory/GraphModels/NormalActions.lean +++ b/lean/OAI/RepresentationTheory/GraphModels/NormalActions.lean @@ -1,598 +1,598 @@ -import Mathlib -import OAI.RepresentationTheory.GraphModels.Regular - -namespace OAI - -noncomputable section - -/-! Commuting normal actions and regular multiplicities. -/ - -namespace GraphNormality -section -open ArithmeticGerms GermBundles -open scoped InnerProductSpace -section WeakOperatorAlgebras -variable {L W : Type*} -variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] -variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] [CompleteSpace W] - -def wotLift (F : (L →L[ℂ] L) →⋆ₐ[ℂ] (W →L[ℂ] W)) : - (L →WOT[ℂ] L) →⋆ₐ[ℂ] (W →WOT[ℂ] W) where - toFun T := ContinuousLinearMapWOT.ofCLM (F T.toCLM) - map_one' := congrArg ContinuousLinearMapWOT.ofCLM (map_one F) - map_mul' T S := congrArg ContinuousLinearMapWOT.ofCLM (map_mul F T.toCLM S.toCLM) - map_add' T S := congrArg ContinuousLinearMapWOT.ofCLM (map_add F T.toCLM S.toCLM) - map_zero' := congrArg ContinuousLinearMapWOT.ofCLM (map_zero F) - commutes' z := congrArg ContinuousLinearMapWOT.ofCLM (F.commutes z) - map_star' T := congrArg ContinuousLinearMapWOT.ofCLM (map_star F T.toCLM) - -theorem closed_generated_commute (s t : Set (W →WOT[ℂ] W)) - (hst : s ⊆ StarSubalgebra.centralizer ℂ t) - {x y : W →WOT[ℂ] W} - (hx : x ∈ (StarAlgebra.adjoin ℂ s).topologicalClosure) - (hy : y ∈ (StarAlgebra.adjoin ℂ t).topologicalClosure) : x * y = y * x := by - have hs : (StarAlgebra.adjoin ℂ s).topologicalClosure ≤ - StarSubalgebra.centralizer ℂ t := - StarSubalgebra.topologicalClosure_minimal (StarAlgebra.adjoin_le hst) - (Set.isClosed_centralizer _) - have ht := StarSubalgebra.topologicalClosure_adjoin_le_centralizer_centralizer ℂ t hy - exact ((StarSubalgebra.mem_centralizer_iff ℂ).mp ht x (hs hx)).1 - -theorem map_mem_closed_generated (F : (L →WOT[ℂ] L) →⋆ₐ[ℂ] (W →WOT[ℂ] W)) - (hF : Continuous F) (s : Set (L →WOT[ℂ] L)) {x : L →WOT[ℂ] L} - (hx : x ∈ (StarAlgebra.adjoin ℂ s).topologicalClosure) : - F x ∈ (StarAlgebra.adjoin ℂ (F '' s)).topologicalClosure := by - have h := StarSubalgebra.map_topologicalClosure_le (StarAlgebra.adjoin ℂ s) F hF - rw [StarAlgHom.map_adjoin] at h - exact h ⟨x, hx, rfl⟩ - -theorem isometries_commute_star_right (U V : W ≃ₗᵢ[ℂ] W) - (h : ∀ x, U (V x) = V (U x)) : - U.toContinuousLinearEquiv.toContinuousLinearMap * - star V.toContinuousLinearEquiv.toContinuousLinearMap = - star V.toContinuousLinearEquiv.toContinuousLinearMap * - U.toContinuousLinearEquiv.toContinuousLinearMap := by - rw [LinearIsometryEquiv.star_eq_symm] - apply ContinuousLinearMap.ext - intro x - change U (V.symm x) = V.symm (U x) - apply V.injective - rw [← h, V.apply_symm_apply, V.apply_symm_apply] - -end WeakOperatorAlgebras - -variable {G : Type*} [Group G] - -def regularGenerator (μ : ScalarCocycle G) (g : G) : - lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 := - ContinuousLinearMapWOT.ofCLM (scalarRegular μ g).toContinuousLinearEquiv.toContinuousLinearMap - -def twistedGroupAlgebra (μ : ScalarCocycle G) : - StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) := - (StarAlgebra.adjoin ℂ (Set.range (regularGenerator μ))).topologicalClosure - -theorem regularGenerator_mem (μ : ScalarCocycle G) (g : G) : - regularGenerator μ g ∈ twistedGroupAlgebra μ := - StarSubalgebra.le_topologicalClosure _ (StarAlgebra.subset_adjoin ℂ _ (Set.mem_range_self g)) - -end - -section -open ArithmeticGerms GermBundles -variable {G H V J : Type*} [Group G] [Group H] [Fintype J] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (C : VirtualGraph G H) -local instance normalActionDomainFintype : Fintype (G ⧸ C.domain) := - Subgroup.fintypeQuotientOfFiniteIndex -local instance normalActionCodomainFintype : Fintype (H ⧸ C.codomain) := - Subgroup.fintypeQuotientOfFiniteIndex -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) -variable (b : OrthonormalBasis J ℂ V) - -def coordinateOperator (s : G × H) : lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2 := - ContinuousLinearMapWOT.ofCLM (B.action s).toContinuousLinearEquiv.toContinuousLinearMap - -theorem coordinateOperator_centralizer : - Set.range (fun g : G => coordinateOperator C μ ω B (g,1)) ⊆ - StarSubalgebra.centralizer ℂ - (Set.range (fun h : H => coordinateOperator C μ ω B (1,h))) := by - rintro _ ⟨g,rfl⟩ - apply (StarSubalgebra.mem_centralizer_iff ℂ).mpr - rintro _ ⟨h,rfl⟩ - constructor - · apply ContinuousLinearMapWOT.ext - intro v - exact (coordinate_actions_commute C μ ω B g h v).symm - · exact congrArg ContinuousLinearMapWOT.ofCLM - (isometries_commute_star_right (B.action (g,1)) (B.action (1,h)) - (coordinate_actions_commute C μ ω B g h)).symm - -theorem firstExtension_generating_image : - (wotLift (firstExtension C μ ω B b)) '' Set.range (regularGenerator μ) = - Set.range (fun g : G => coordinateOperator C μ ω B (g,1)) := by - rw [← Set.range_comp'] - congr 1 - funext g - exact congrArg ContinuousLinearMapWOT.ofCLM (firstExtension_generator C μ ω B b g) - -theorem secondExtension_generating_image : - (wotLift (secondExtension C μ ω B b)) '' Set.range (regularGenerator (inverseCocycle ω)) = - Set.range (fun h : H => coordinateOperator C μ ω B (1,h)) := by - rw [← Set.range_comp'] - congr 1 - funext h - exact congrArg ContinuousLinearMapWOT.ofCLM (secondExtension_generator C μ ω B b h) - -def leftNormalAction : twistedGroupAlgebra μ →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2) := - (wotLift (firstExtension C μ ω B b)).comp (twistedGroupAlgebra μ).subtype - -def rightAdjointNormalAction : twistedGroupAlgebra (inverseCocycle ω) →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2) := - (wotLift (secondExtension C μ ω B b)).comp (twistedGroupAlgebra (inverseCocycle ω)).subtype - -theorem leftNormalAction_continuous : Continuous (leftNormalAction C μ ω B b) := - (firstExtension_wot_continuous C μ ω B b).comp continuous_subtype_val - -theorem rightAdjointNormalAction_continuous : Continuous (rightAdjointNormalAction C μ ω B b) := - (secondExtension_wot_continuous C μ ω B b).comp continuous_subtype_val - -theorem leftNormalAction_generator (g : G) : - leftNormalAction C μ ω B b ⟨regularGenerator μ g, regularGenerator_mem μ g⟩ = - coordinateOperator C μ ω B (g,1) := - congrArg ContinuousLinearMapWOT.ofCLM (firstExtension_generator C μ ω B b g) - -theorem rightAdjointNormalAction_generator (h : H) : - rightAdjointNormalAction C μ ω B b - ⟨regularGenerator (inverseCocycle ω) h, regularGenerator_mem (inverseCocycle ω) h⟩ = - coordinateOperator C μ ω B (1,h) := - congrArg ContinuousLinearMapWOT.ofCLM (secondExtension_generator C μ ω B b h) - -theorem normalActions_commute (T : twistedGroupAlgebra μ) - (S : twistedGroupAlgebra (inverseCocycle ω)) : - leftNormalAction C μ ω B b T * rightAdjointNormalAction C μ ω B b S = - rightAdjointNormalAction C μ ω B b S * leftNormalAction C μ ω B b T := by - have hT := map_mem_closed_generated (wotLift (firstExtension C μ ω B b)) - (firstExtension_wot_continuous C μ ω B b) (Set.range (regularGenerator μ)) T.property - have hS := map_mem_closed_generated (wotLift (secondExtension C μ ω B b)) - (secondExtension_wot_continuous C μ ω B b) - (Set.range (regularGenerator (inverseCocycle ω))) S.property - rw [firstExtension_generating_image] at hT - rw [secondExtension_generating_image] at hS - exact closed_generated_commute _ _ (coordinateOperator_centralizer C μ ω B) hT hS - -end - -section -open scoped InnerProductSpace -variable {I : Type*} - -lemma scalarLp_inner_star_star (x y : lp (fun _ : I => ℂ) 2) : - ⟪star x, star y⟫_ℂ = ⟪y, x⟫_ℂ := by - rw [lp.inner_eq_tsum, lp.inner_eq_tsum] - apply tsum_congr - intro i - simp [RCLike.inner_apply, mul_comm] - -lemma scalarLp_inner_star_comm (x y : lp (fun _ : I => ℂ) 2) : - ⟪x, star y⟫_ℂ = ⟪y, star x⟫_ℂ := by - simpa only [star_star] using scalarLp_inner_star_star (star x) y - -def operatorTranspose (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2 where - toFun x := star ((star T) (star x)) - map_add' x y := by simp - map_smul' z x := by simp - cont := continuous_star.comp ((star T).continuous.comp continuous_star) - -lemma operatorTranspose_inner (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) - (x y : lp (fun _ : I => ℂ) 2) : - ⟪y, operatorTranspose T x⟫_ℂ = ⟪star x, T (star y)⟫_ℂ := by - change ⟪y, star ((star T) (star x))⟫_ℂ = _ - rw [scalarLp_inner_star_comm, ContinuousLinearMap.star_eq_adjoint, - ContinuousLinearMap.adjoint_inner_left] - -lemma operatorTranspose_add (T S : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - operatorTranspose (T + S) = operatorTranspose T + operatorTranspose S := by - apply ContinuousLinearMap.ext - intro x - simp [operatorTranspose, ContinuousLinearMap.star_eq_adjoint] - -lemma operatorTranspose_smul (z : ℂ) - (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - operatorTranspose (z • T) = z • operatorTranspose T := by - apply ContinuousLinearMap.ext - intro x - simp [operatorTranspose] - -lemma operatorTranspose_mul (T S : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - operatorTranspose (T * S) = operatorTranspose S * operatorTranspose T := by - apply ContinuousLinearMap.ext - intro x - simp [operatorTranspose] - -lemma operatorTranspose_star (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - operatorTranspose (star T) = star (operatorTranspose T) := by - rw [ContinuousLinearMap.star_eq_adjoint (operatorTranspose T)] - apply (ContinuousLinearMap.eq_adjoint_iff _ _).mpr - intro x y - rw [← inner_conj_symm, operatorTranspose_inner, ContinuousLinearMap.star_eq_adjoint, - ContinuousLinearMap.adjoint_inner_right, inner_conj_symm, operatorTranspose_inner] - -lemma operatorTranspose_involutive - (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : - operatorTranspose (operatorTranspose T) = T := by - apply ContinuousLinearMap.ext - intro x - apply ext_inner_left ℂ - intro y - rw [operatorTranspose_inner, operatorTranspose_inner, star_star, star_star] - -lemma operatorTranspose_one : - operatorTranspose (1 : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) = 1 := by - apply ContinuousLinearMap.ext - intro x - simp [operatorTranspose] - -def operatorOppositeEquiv : - (lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2)ᵐᵒᵖ ≃⋆ₐ[ℂ] - (lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) where - toFun T := operatorTranspose T.unop - invFun T := MulOpposite.op (operatorTranspose T) - left_inv T := by simp [operatorTranspose_involutive] - right_inv T := operatorTranspose_involutive T - map_mul' T S := operatorTranspose_mul S.unop T.unop - map_add' T S := operatorTranspose_add T.unop S.unop - map_smul' z T := operatorTranspose_smul z T.unop - map_star' T := operatorTranspose_star T.unop - -lemma operatorTranspose_wot_continuous : - Continuous (fun T : lp (fun _ : I => ℂ) 2 →WOT[ℂ] lp (fun _ : I => ℂ) 2 => - ContinuousLinearMapWOT.ofCLM (operatorTranspose T.toCLM)) := by - apply ContinuousLinearMapWOT.continuous_iff.mpr - intro x y - change Continuous (fun T : lp (fun _ : I => ℂ) 2 →WOT[ℂ] lp (fun _ : I => ℂ) 2 => - ⟪y, operatorTranspose T.toCLM x⟫_ℂ) - simp_rw [operatorTranspose_inner] - exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (star y) (star x) - -end - -section -open GermBundles -variable {G : Type*} - -def wotTranspose (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 := - ContinuousLinearMapWOT.ofCLM (operatorTranspose T.toCLM) - -lemma wotTranspose_continuous : Continuous (wotTranspose (G := G)) := - operatorTranspose_wot_continuous - -lemma wotTranspose_add (T S : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - wotTranspose (T + S) = wotTranspose T + wotTranspose S := - congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_add T.toCLM S.toCLM) - -lemma wotTranspose_mul (T S : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - wotTranspose (T * S) = wotTranspose S * wotTranspose T := - congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_mul T.toCLM S.toCLM) - -lemma wotTranspose_smul (z : ℂ) - (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - wotTranspose (z • T) = z • wotTranspose T := - congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_smul z T.toCLM) - -lemma wotTranspose_star (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - wotTranspose (star T) = star (wotTranspose T) := - congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_star T.toCLM) - -lemma wotTranspose_one : - wotTranspose (1 : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) = 1 := - congrArg ContinuousLinearMapWOT.ofCLM operatorTranspose_one - -lemma wotTranspose_involutive - (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : - wotTranspose (wotTranspose T) = T := - congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_involutive T.toCLM) - -lemma wotTranspose_zero : - wotTranspose (0 : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) = 0 := by - apply ContinuousLinearMapWOT.ext - intro x - change star ((star (0 : lp (fun _ : G => ℂ) 2 →L[ℂ] lp (fun _ : G => ℂ) 2)) (star x)) = 0 - simp [ContinuousLinearMap.star_eq_adjoint] - -variable [Group G] - -lemma wotTranspose_star_regularGenerator (ω : ScalarCocycle G) (g : G) : - wotTranspose (star (regularGenerator ω g)) = regularGenerator (inverseCocycle ω) g := by - apply ContinuousLinearMapWOT.ext - intro x - apply lp.ext - funext k - obtain ⟨h,rfl⟩ := (Equiv.mulLeft g).surjective k - change (star ((star (star (scalarRegular ω g).toContinuousLinearEquiv.toContinuousLinearMap)) - (star x))) (g*h) = scalarRegular (inverseCocycle ω) g x (g*h) - rw [star_star] - change star (scalarRegular ω g (star x) (g*h)) = _ - rw [scalarRegular_apply, scalarRegular_apply] - simp only [inverseCocycle, star_mul, lp.star_apply, star_star] - rw [Circle.coe_inv_eq_conj] - exact mul_comm _ _ - -lemma wotTranspose_regularGenerator (ω : ScalarCocycle G) (g : G) : - wotTranspose (regularGenerator ω g) = star (regularGenerator (inverseCocycle ω) g) := by - rw [← wotTranspose_star_regularGenerator, wotTranspose_star, star_star] - -def transposePreimage - (S : StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2)) : - StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) where - carrier := {T | wotTranspose T ∈ S} - zero_mem' := by - change wotTranspose 0 ∈ S - rw [wotTranspose_zero] - exact zero_mem S - one_mem' := by - change wotTranspose 1 ∈ S - rw [wotTranspose_one] - exact one_mem S - add_mem' hT hU := by - change wotTranspose _ ∈ S - rw [wotTranspose_add] - exact add_mem hT hU - mul_mem' hT hU := by - change wotTranspose _ ∈ S - rw [wotTranspose_mul] - exact mul_mem hU hT - algebraMap_mem' z := by - change wotTranspose (algebraMap ℂ _ z) ∈ S - rw [Algebra.algebraMap_eq_smul_one, wotTranspose_smul, wotTranspose_one] - exact S.smul_mem S.one_mem z - star_mem' hT := by - change wotTranspose _ ∈ S - rw [wotTranspose_star] - exact star_mem hT - -lemma wotTranspose_mem_twistedGroupAlgebra (ω : ScalarCocycle G) - {T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2} - (hT : T ∈ twistedGroupAlgebra ω) : - wotTranspose T ∈ twistedGroupAlgebra (inverseCocycle ω) := by - have hgen : Set.range (regularGenerator ω) ⊆ - transposePreimage (twistedGroupAlgebra (inverseCocycle ω)) := by - rintro _ ⟨g,rfl⟩ - change wotTranspose (regularGenerator ω g) ∈ twistedGroupAlgebra (inverseCocycle ω) - rw [wotTranspose_regularGenerator] - exact star_mem (regularGenerator_mem _ g) - have hclosed : IsClosed (transposePreimage (twistedGroupAlgebra (inverseCocycle ω)) : - Set (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2)) := by - change IsClosed (wotTranspose ⁻¹' (twistedGroupAlgebra (inverseCocycle ω)).carrier) - exact (StarSubalgebra.isClosed_topologicalClosure _).preimage wotTranspose_continuous - exact StarSubalgebra.topologicalClosure_minimal (StarAlgebra.adjoin_le hgen) hclosed hT - -def opTransposeOnTwisted (ω : ScalarCocycle G) : - (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] twistedGroupAlgebra (inverseCocycle ω) where - toFun T := ⟨wotTranspose T.unop.val, wotTranspose_mem_twistedGroupAlgebra ω T.unop.property⟩ - map_one' := Subtype.ext wotTranspose_one - map_mul' T S := Subtype.ext (wotTranspose_mul S.unop.val T.unop.val) - map_add' T S := Subtype.ext (wotTranspose_add T.unop.val S.unop.val) - map_zero' := Subtype.ext wotTranspose_zero - commutes' z := by - apply Subtype.ext - change wotTranspose (algebraMap ℂ _ z) = algebraMap ℂ _ z - rw [Algebra.algebraMap_eq_smul_one, wotTranspose_smul, wotTranspose_one] - map_star' T := Subtype.ext (wotTranspose_star T.unop.val) - -lemma opTransposeOnTwisted_continuous (ω : ScalarCocycle G) : - Continuous (opTransposeOnTwisted ω) := - (wotTranspose_continuous.comp (continuous_subtype_val.comp - MulOpposite.continuous_unop)).subtype_mk _ - -end - -section -open ArithmeticGerms GermBundles -section RightAction -variable {G H V J : Type*} [Group G] [Group H] [Fintype J] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (C : VirtualGraph G H) -local instance rightNormalActionDomainFintype : Fintype (G ⧸ C.domain) := - Subgroup.fintypeQuotientOfFiniteIndex -local instance rightNormalActionCodomainFintype : Fintype (H ⧸ C.codomain) := - Subgroup.fintypeQuotientOfFiniteIndex -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) -variable (b : OrthonormalBasis J ℂ V) - -def rightNormalAction : (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2) := - (rightAdjointNormalAction C μ ω B b).comp (opTransposeOnTwisted ω) - -theorem rightNormalAction_continuous : Continuous (rightNormalAction C μ ω B b) := - (rightAdjointNormalAction_continuous C μ ω B b).comp - (opTransposeOnTwisted_continuous ω) - -theorem rightNormalAction_adjoint_generator (h : H) : - rightNormalAction C μ ω B b - (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : - twistedGroupAlgebra ω))) = coordinateOperator C μ ω B (1,h) := by - have ht : opTransposeOnTwisted ω - (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : - twistedGroupAlgebra ω))) = - ⟨regularGenerator (inverseCocycle ω) h, regularGenerator_mem (inverseCocycle ω) h⟩ := - Subtype.ext (wotTranspose_star_regularGenerator ω h) - exact (congrArg (rightAdjointNormalAction C μ ω B b) ht).trans - (rightAdjointNormalAction_generator C μ ω B b h) - -theorem left_rightNormalActions_commute (T : twistedGroupAlgebra μ) - (S : (twistedGroupAlgebra ω)ᵐᵒᵖ) : - leftNormalAction C μ ω B b T * rightNormalAction C μ ω B b S = - rightNormalAction C μ ω B b S * leftNormalAction C μ ω B b T := - normalActions_commute C μ ω B b T (opTransposeOnTwisted ω S) - -end RightAction - -variable {G H V : Type*} [Group G] [Group H] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable (C : VirtualGraph G H) -local instance inducedGraphDomainFintype : Fintype (G ⧸ C.domain) := - Subgroup.fintypeQuotientOfFiniteIndex -local instance inducedGraphCodomainFintype : Fintype (H ⧸ C.codomain) := - Subgroup.fintypeQuotientOfFiniteIndex -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (r : CosetSection C.graph) -variable (γ : ProjectiveRepresentation ((prodRatio μ ω).restrict C.graph) V) - -theorem induced_graph_normal_actions : - let B := r.inducedBundle (prodRatio μ ω) γ - ∃ (L : twistedGroupAlgebra μ →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2)) - (R : (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2)) - (UL : PiLp 2 (fun _ : (H ⧸ C.codomain) × Fin (Module.finrank ℂ V) => - lp (fun _ : G => ℂ) 2) ≃ₗᵢ[ℂ] lp (fun _ : (G × H) ⧸ C.graph => V) 2) - (UR : PiLp 2 (fun _ : (G ⧸ C.domain) × Fin (Module.finrank ℂ V) => - lp (fun _ : H => ℂ) 2) ≃ₗᵢ[ℂ] lp (fun _ : (G × H) ⧸ C.graph => V) 2), - Continuous L ∧ Continuous R ∧ - (∀ T S, L T * R S = R S * L T) ∧ - (∀ g, L ⟨regularGenerator μ g, regularGenerator_mem μ g⟩ = - coordinateOperator C μ ω B (g,1)) ∧ - (∀ h, R (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : - twistedGroupAlgebra ω))) = coordinateOperator C μ ω B (1,h)) ∧ - (∀ g v, B.action (g,1) (UL v) = UL - (amplify (scalarRegular μ g).toContinuousLinearEquiv.toContinuousLinearMap v)) ∧ - (∀ h v, B.action (1,h) (UR v) = UR - (amplify (scalarRegular (inverseCocycle ω) h).toContinuousLinearEquiv.toContinuousLinearMap v)) := by - let B := r.inducedBundle (prodRatio μ ω) γ - let b := stdOrthonormalBasis ℂ V - refine ⟨leftNormalAction C μ ω B b, rightNormalAction C μ ω B b, - firstFiniteRegularUnitary C μ ω B b, secondFiniteRegularUnitary C μ ω B b, - leftNormalAction_continuous C μ ω B b, rightNormalAction_continuous C μ ω B b, ?_⟩ - exact ⟨left_rightNormalActions_commute C μ ω B b, - leftNormalAction_generator C μ ω B b, rightNormalAction_adjoint_generator C μ ω B b, - firstFiniteRegularUnitary_intertwines C μ ω B b, - secondFiniteRegularUnitary_intertwines C μ ω B b⟩ - -end - -section -open GermBundles -variable {G : Type*} [Group G] - -def standardRightRegular (ω : ScalarCocycle G) (h : G) : - lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := - transportLp (Equiv.mulRight h) (fun g => circleUnitary (ω.val g h)) - -lemma standardRightRegular_apply (ω : ScalarCocycle G) (h : G) - (x : lp (fun _ : G => ℂ) 2) (g : G) : - standardRightRegular ω h x (g*h) = (ω.val g h : ℂ) * x g := - transportLp_apply (Equiv.mulRight h) (fun g => circleUnitary (ω.val g h)) x g - -def oppositeToStandard (ω : ScalarCocycle G) : - lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := - transportLp (Equiv.inv G) (fun g => circleUnitary ((ω.val g⁻¹ g)⁻¹)) - -lemma oppositeToStandard_apply (ω : ScalarCocycle G) - (x : lp (fun _ : G => ℂ) 2) (g : G) : - oppositeToStandard ω x g⁻¹ = ((ω.val g⁻¹ g)⁻¹ : Circle) * x g := by - exact transportLp_apply (Equiv.inv G) (fun g => circleUnitary ((ω.val g⁻¹ g)⁻¹)) x g - -lemma rightStandard_phase (ω : ScalarCocycle G) (h g : G) : - ω.val (h*g)⁻¹ h * (ω.val h g)⁻¹ * (ω.val (h*g)⁻¹ (h*g))⁻¹ = - (ω.val g⁻¹ g)⁻¹ := by - have hh := ω.mul_assoc (h*g)⁻¹ h g - have hg : (h*g)⁻¹ * h = g⁻¹ := by group - rw [hg] at hh - have he : ω.val (h*g)⁻¹ h = - (ω.val h g * ω.val (h*g)⁻¹ (h*g)) * (ω.val g⁻¹ g)⁻¹ := - (eq_mul_inv_iff_mul_eq).mpr hh - rw [he] - simp [mul_comm, mul_left_comm, mul_assoc] - -lemma oppositeToStandard_intertwines (ω : ScalarCocycle G) (h : G) - (x : lp (fun _ : G => ℂ) 2) : - oppositeToStandard ω (scalarRegular (inverseCocycle ω) h x) = - (standardRightRegular ω h).symm (oppositeToStandard ω x) := by - apply (standardRightRegular ω h).injective - rw [LinearIsometryEquiv.apply_symm_apply] - apply lp.ext - funext k - obtain ⟨g,rfl⟩ := (Equiv.inv G).surjective k - change standardRightRegular ω h (oppositeToStandard ω (scalarRegular (inverseCocycle ω) h x)) g⁻¹ = - oppositeToStandard ω x g⁻¹ - have hi : (h*g)⁻¹ * h = g⁻¹ := by group - rw [← hi, standardRightRegular_apply, oppositeToStandard_apply, scalarRegular_apply, - hi, oppositeToStandard_apply] - change (ω.val (h*g)⁻¹ h : ℂ) * - (((ω.val (h*g)⁻¹ (h*g))⁻¹ : Circle) * (((ω.val h g)⁻¹ : Circle) * x g)) = - ((ω.val g⁻¹ g)⁻¹ : Circle) * x g - have hp := congrArg (fun z : Circle => (z : ℂ)) (rightStandard_phase ω h g) - simp only [Circle.coe_mul] at hp - calc - _ = ((ω.val (h*g)⁻¹ h : ℂ) * ((ω.val h g)⁻¹ : Circle) * - ((ω.val (h*g)⁻¹ (h*g))⁻¹ : Circle)) * x g := by ring - _ = _ := congrArg (fun z : ℂ => z * x g) hp - -end - -open ArithmeticGerms GermBundles -section EntireRegularActions -variable {G H V J : Type*} [Group G] [Group H] [Fintype J] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (C : VirtualGraph G H) -local instance regularActionDomainFintype : Fintype (G ⧸ C.domain) := - Subgroup.fintypeQuotientOfFiniteIndex -local instance regularActionCodomainFintype : Fintype (H ⧸ C.codomain) := - Subgroup.fintypeQuotientOfFiniteIndex -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) -variable (b : OrthonormalBasis J ℂ V) - -lemma leftNormalAction_finite_regular (T : twistedGroupAlgebra μ) - (v : PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2)) : - leftNormalAction C μ ω B b T (firstFiniteRegularUnitary C μ ω B b v) = - firstFiniteRegularUnitary C μ ω B b (amplify T.val.toCLM v) := by - change firstFiniteRegularUnitary C μ ω B b - (amplify T.val.toCLM ((firstFiniteRegularUnitary C μ ω B b).symm - (firstFiniteRegularUnitary C μ ω B b v))) = _ - rw [LinearIsometryEquiv.symm_apply_apply] - -lemma rightNormalAction_finite_regular (S : (twistedGroupAlgebra ω)ᵐᵒᵖ) - (v : PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2)) : - rightNormalAction C μ ω B b S (secondFiniteRegularUnitary C μ ω B b v) = - secondFiniteRegularUnitary C μ ω B b (amplify - (wotTranspose S.unop.val).toCLM v) := by - change secondFiniteRegularUnitary C μ ω B b - (amplify (wotTranspose S.unop.val).toCLM ((secondFiniteRegularUnitary C μ ω B b).symm - (secondFiniteRegularUnitary C μ ω B b v))) = _ - rw [LinearIsometryEquiv.symm_apply_apply] - -end EntireRegularActions - -variable {G H V : Type*} [Group G] [Group H] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] -variable (C : VirtualGraph G H) -local instance multiplicityDomainFintype : Fintype (G ⧸ C.domain) := - Subgroup.fintypeQuotientOfFiniteIndex -local instance multiplicityCodomainFintype : Fintype (H ⧸ C.codomain) := - Subgroup.fintypeQuotientOfFiniteIndex - -omit [FiniteDimensional ℂ V] in -lemma graph_regular_multiplicities : - Fintype.card ((H ⧸ C.codomain) × Fin (Module.finrank ℂ V)) = - Module.finrank ℂ V * C.codomain.index ∧ - Fintype.card ((G ⧸ C.domain) × Fin (Module.finrank ℂ V)) = - Module.finrank ℂ V * C.domain.index := by - simp [Fintype.card_prod, Subgroup.index_eq_card, Nat.card_eq_fintype_card, mul_comm] - -end GraphNormality - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.GraphModels.Regular + +namespace OAI + +noncomputable section + +/-! Commuting normal actions and regular multiplicities. -/ + +namespace GraphNormality +section +open ArithmeticGerms GermBundles +open scoped InnerProductSpace +section WeakOperatorAlgebras +variable {L W : Type*} +variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] +variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] [CompleteSpace W] + +def wotLift (F : (L →L[ℂ] L) →⋆ₐ[ℂ] (W →L[ℂ] W)) : + (L →WOT[ℂ] L) →⋆ₐ[ℂ] (W →WOT[ℂ] W) where + toFun T := ContinuousLinearMapWOT.ofCLM (F T.toCLM) + map_one' := congrArg ContinuousLinearMapWOT.ofCLM (map_one F) + map_mul' T S := congrArg ContinuousLinearMapWOT.ofCLM (map_mul F T.toCLM S.toCLM) + map_add' T S := congrArg ContinuousLinearMapWOT.ofCLM (map_add F T.toCLM S.toCLM) + map_zero' := congrArg ContinuousLinearMapWOT.ofCLM (map_zero F) + commutes' z := congrArg ContinuousLinearMapWOT.ofCLM (F.commutes z) + map_star' T := congrArg ContinuousLinearMapWOT.ofCLM (map_star F T.toCLM) + +theorem closed_generated_commute (s t : Set (W →WOT[ℂ] W)) + (hst : s ⊆ StarSubalgebra.centralizer ℂ t) + {x y : W →WOT[ℂ] W} + (hx : x ∈ (StarAlgebra.adjoin ℂ s).topologicalClosure) + (hy : y ∈ (StarAlgebra.adjoin ℂ t).topologicalClosure) : x * y = y * x := by + have hs : (StarAlgebra.adjoin ℂ s).topologicalClosure ≤ + StarSubalgebra.centralizer ℂ t := + StarSubalgebra.topologicalClosure_minimal (StarAlgebra.adjoin_le hst) + (Set.isClosed_centralizer _) + have ht := StarSubalgebra.topologicalClosure_adjoin_le_centralizer_centralizer ℂ t hy + exact ((StarSubalgebra.mem_centralizer_iff ℂ).mp ht x (hs hx)).1 + +theorem map_mem_closed_generated (F : (L →WOT[ℂ] L) →⋆ₐ[ℂ] (W →WOT[ℂ] W)) + (hF : Continuous F) (s : Set (L →WOT[ℂ] L)) {x : L →WOT[ℂ] L} + (hx : x ∈ (StarAlgebra.adjoin ℂ s).topologicalClosure) : + F x ∈ (StarAlgebra.adjoin ℂ (F '' s)).topologicalClosure := by + have h := StarSubalgebra.map_topologicalClosure_le (StarAlgebra.adjoin ℂ s) F hF + rw [StarAlgHom.map_adjoin] at h + exact h ⟨x, hx, rfl⟩ + +theorem isometries_commute_star_right (U V : W ≃ₗᵢ[ℂ] W) + (h : ∀ x, U (V x) = V (U x)) : + U.toContinuousLinearEquiv.toContinuousLinearMap * + star V.toContinuousLinearEquiv.toContinuousLinearMap = + star V.toContinuousLinearEquiv.toContinuousLinearMap * + U.toContinuousLinearEquiv.toContinuousLinearMap := by + rw [LinearIsometryEquiv.star_eq_symm] + apply ContinuousLinearMap.ext + intro x + change U (V.symm x) = V.symm (U x) + apply V.injective + rw [← h, V.apply_symm_apply, V.apply_symm_apply] + +end WeakOperatorAlgebras + +variable {G : Type*} [Group G] + +def regularGenerator (μ : ScalarCocycle G) (g : G) : + lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 := + ContinuousLinearMapWOT.ofCLM (scalarRegular μ g).toContinuousLinearEquiv.toContinuousLinearMap + +def twistedGroupAlgebra (μ : ScalarCocycle G) : + StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) := + (StarAlgebra.adjoin ℂ (Set.range (regularGenerator μ))).topologicalClosure + +theorem regularGenerator_mem (μ : ScalarCocycle G) (g : G) : + regularGenerator μ g ∈ twistedGroupAlgebra μ := + StarSubalgebra.le_topologicalClosure _ (StarAlgebra.subset_adjoin ℂ _ (Set.mem_range_self g)) + +end + +section +open ArithmeticGerms GermBundles +variable {G H V J : Type*} [Group G] [Group H] [Fintype J] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (C : VirtualGraph G H) +local instance normalActionDomainFintype : Fintype (G ⧸ C.domain) := + Subgroup.fintypeQuotientOfFiniteIndex +local instance normalActionCodomainFintype : Fintype (H ⧸ C.codomain) := + Subgroup.fintypeQuotientOfFiniteIndex +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) +variable (b : OrthonormalBasis J ℂ V) + +def coordinateOperator (s : G × H) : lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2 := + ContinuousLinearMapWOT.ofCLM (B.action s).toContinuousLinearEquiv.toContinuousLinearMap + +theorem coordinateOperator_centralizer : + Set.range (fun g : G => coordinateOperator C μ ω B (g,1)) ⊆ + StarSubalgebra.centralizer ℂ + (Set.range (fun h : H => coordinateOperator C μ ω B (1,h))) := by + rintro _ ⟨g,rfl⟩ + apply (StarSubalgebra.mem_centralizer_iff ℂ).mpr + rintro _ ⟨h,rfl⟩ + constructor + · apply ContinuousLinearMapWOT.ext + intro v + exact (coordinate_actions_commute C μ ω B g h v).symm + · exact congrArg ContinuousLinearMapWOT.ofCLM + (isometries_commute_star_right (B.action (g,1)) (B.action (1,h)) + (coordinate_actions_commute C μ ω B g h)).symm + +theorem firstExtension_generating_image : + (wotLift (firstExtension C μ ω B b)) '' Set.range (regularGenerator μ) = + Set.range (fun g : G => coordinateOperator C μ ω B (g,1)) := by + rw [← Set.range_comp'] + congr 1 + funext g + exact congrArg ContinuousLinearMapWOT.ofCLM (firstExtension_generator C μ ω B b g) + +theorem secondExtension_generating_image : + (wotLift (secondExtension C μ ω B b)) '' Set.range (regularGenerator (inverseCocycle ω)) = + Set.range (fun h : H => coordinateOperator C μ ω B (1,h)) := by + rw [← Set.range_comp'] + congr 1 + funext h + exact congrArg ContinuousLinearMapWOT.ofCLM (secondExtension_generator C μ ω B b h) + +def leftNormalAction : twistedGroupAlgebra μ →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2) := + (wotLift (firstExtension C μ ω B b)).comp (twistedGroupAlgebra μ).subtype + +def rightAdjointNormalAction : twistedGroupAlgebra (inverseCocycle ω) →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2) := + (wotLift (secondExtension C μ ω B b)).comp (twistedGroupAlgebra (inverseCocycle ω)).subtype + +theorem leftNormalAction_continuous : Continuous (leftNormalAction C μ ω B b) := + (firstExtension_wot_continuous C μ ω B b).comp continuous_subtype_val + +theorem rightAdjointNormalAction_continuous : Continuous (rightAdjointNormalAction C μ ω B b) := + (secondExtension_wot_continuous C μ ω B b).comp continuous_subtype_val + +theorem leftNormalAction_generator (g : G) : + leftNormalAction C μ ω B b ⟨regularGenerator μ g, regularGenerator_mem μ g⟩ = + coordinateOperator C μ ω B (g,1) := + congrArg ContinuousLinearMapWOT.ofCLM (firstExtension_generator C μ ω B b g) + +theorem rightAdjointNormalAction_generator (h : H) : + rightAdjointNormalAction C μ ω B b + ⟨regularGenerator (inverseCocycle ω) h, regularGenerator_mem (inverseCocycle ω) h⟩ = + coordinateOperator C μ ω B (1,h) := + congrArg ContinuousLinearMapWOT.ofCLM (secondExtension_generator C μ ω B b h) + +theorem normalActions_commute (T : twistedGroupAlgebra μ) + (S : twistedGroupAlgebra (inverseCocycle ω)) : + leftNormalAction C μ ω B b T * rightAdjointNormalAction C μ ω B b S = + rightAdjointNormalAction C μ ω B b S * leftNormalAction C μ ω B b T := by + have hT := map_mem_closed_generated (wotLift (firstExtension C μ ω B b)) + (firstExtension_wot_continuous C μ ω B b) (Set.range (regularGenerator μ)) T.property + have hS := map_mem_closed_generated (wotLift (secondExtension C μ ω B b)) + (secondExtension_wot_continuous C μ ω B b) + (Set.range (regularGenerator (inverseCocycle ω))) S.property + rw [firstExtension_generating_image] at hT + rw [secondExtension_generating_image] at hS + exact closed_generated_commute _ _ (coordinateOperator_centralizer C μ ω B) hT hS + +end + +section +open scoped InnerProductSpace +variable {I : Type*} + +lemma scalarLp_inner_star_star (x y : lp (fun _ : I => ℂ) 2) : + ⟪star x, star y⟫_ℂ = ⟪y, x⟫_ℂ := by + rw [lp.inner_eq_tsum, lp.inner_eq_tsum] + apply tsum_congr + intro i + simp [RCLike.inner_apply, mul_comm] + +lemma scalarLp_inner_star_comm (x y : lp (fun _ : I => ℂ) 2) : + ⟪x, star y⟫_ℂ = ⟪y, star x⟫_ℂ := by + simpa only [star_star] using scalarLp_inner_star_star (star x) y + +def operatorTranspose (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2 where + toFun x := star ((star T) (star x)) + map_add' x y := by simp + map_smul' z x := by simp + cont := continuous_star.comp ((star T).continuous.comp continuous_star) + +lemma operatorTranspose_inner (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) + (x y : lp (fun _ : I => ℂ) 2) : + ⟪y, operatorTranspose T x⟫_ℂ = ⟪star x, T (star y)⟫_ℂ := by + change ⟪y, star ((star T) (star x))⟫_ℂ = _ + rw [scalarLp_inner_star_comm, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_inner_left] + +lemma operatorTranspose_add (T S : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + operatorTranspose (T + S) = operatorTranspose T + operatorTranspose S := by + apply ContinuousLinearMap.ext + intro x + simp [operatorTranspose, ContinuousLinearMap.star_eq_adjoint] + +lemma operatorTranspose_smul (z : ℂ) + (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + operatorTranspose (z • T) = z • operatorTranspose T := by + apply ContinuousLinearMap.ext + intro x + simp [operatorTranspose] + +lemma operatorTranspose_mul (T S : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + operatorTranspose (T * S) = operatorTranspose S * operatorTranspose T := by + apply ContinuousLinearMap.ext + intro x + simp [operatorTranspose] + +lemma operatorTranspose_star (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + operatorTranspose (star T) = star (operatorTranspose T) := by + rw [ContinuousLinearMap.star_eq_adjoint (operatorTranspose T)] + apply (ContinuousLinearMap.eq_adjoint_iff _ _).mpr + intro x y + rw [← inner_conj_symm, operatorTranspose_inner, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_inner_right, inner_conj_symm, operatorTranspose_inner] + +lemma operatorTranspose_involutive + (T : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) : + operatorTranspose (operatorTranspose T) = T := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_left ℂ + intro y + rw [operatorTranspose_inner, operatorTranspose_inner, star_star, star_star] + +lemma operatorTranspose_one : + operatorTranspose (1 : lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) = 1 := by + apply ContinuousLinearMap.ext + intro x + simp [operatorTranspose] + +def operatorOppositeEquiv : + (lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2)ᵐᵒᵖ ≃⋆ₐ[ℂ] + (lp (fun _ : I => ℂ) 2 →L[ℂ] lp (fun _ : I => ℂ) 2) where + toFun T := operatorTranspose T.unop + invFun T := MulOpposite.op (operatorTranspose T) + left_inv T := by simp [operatorTranspose_involutive] + right_inv T := operatorTranspose_involutive T + map_mul' T S := operatorTranspose_mul S.unop T.unop + map_add' T S := operatorTranspose_add T.unop S.unop + map_smul' z T := operatorTranspose_smul z T.unop + map_star' T := operatorTranspose_star T.unop + +lemma operatorTranspose_wot_continuous : + Continuous (fun T : lp (fun _ : I => ℂ) 2 →WOT[ℂ] lp (fun _ : I => ℂ) 2 => + ContinuousLinearMapWOT.ofCLM (operatorTranspose T.toCLM)) := by + apply ContinuousLinearMapWOT.continuous_iff.mpr + intro x y + change Continuous (fun T : lp (fun _ : I => ℂ) 2 →WOT[ℂ] lp (fun _ : I => ℂ) 2 => + ⟪y, operatorTranspose T.toCLM x⟫_ℂ) + simp_rw [operatorTranspose_inner] + exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (star y) (star x) + +end + +section +open GermBundles +variable {G : Type*} + +def wotTranspose (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 := + ContinuousLinearMapWOT.ofCLM (operatorTranspose T.toCLM) + +lemma wotTranspose_continuous : Continuous (wotTranspose (G := G)) := + operatorTranspose_wot_continuous + +lemma wotTranspose_add (T S : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + wotTranspose (T + S) = wotTranspose T + wotTranspose S := + congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_add T.toCLM S.toCLM) + +lemma wotTranspose_mul (T S : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + wotTranspose (T * S) = wotTranspose S * wotTranspose T := + congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_mul T.toCLM S.toCLM) + +lemma wotTranspose_smul (z : ℂ) + (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + wotTranspose (z • T) = z • wotTranspose T := + congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_smul z T.toCLM) + +lemma wotTranspose_star (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + wotTranspose (star T) = star (wotTranspose T) := + congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_star T.toCLM) + +lemma wotTranspose_one : + wotTranspose (1 : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) = 1 := + congrArg ContinuousLinearMapWOT.ofCLM operatorTranspose_one + +lemma wotTranspose_involutive + (T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) : + wotTranspose (wotTranspose T) = T := + congrArg ContinuousLinearMapWOT.ofCLM (operatorTranspose_involutive T.toCLM) + +lemma wotTranspose_zero : + wotTranspose (0 : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) = 0 := by + apply ContinuousLinearMapWOT.ext + intro x + change star ((star (0 : lp (fun _ : G => ℂ) 2 →L[ℂ] lp (fun _ : G => ℂ) 2)) (star x)) = 0 + simp [ContinuousLinearMap.star_eq_adjoint] + +variable [Group G] + +lemma wotTranspose_star_regularGenerator (ω : ScalarCocycle G) (g : G) : + wotTranspose (star (regularGenerator ω g)) = regularGenerator (inverseCocycle ω) g := by + apply ContinuousLinearMapWOT.ext + intro x + apply lp.ext + funext k + obtain ⟨h,rfl⟩ := (Equiv.mulLeft g).surjective k + change (star ((star (star (scalarRegular ω g).toContinuousLinearEquiv.toContinuousLinearMap)) + (star x))) (g*h) = scalarRegular (inverseCocycle ω) g x (g*h) + rw [star_star] + change star (scalarRegular ω g (star x) (g*h)) = _ + rw [scalarRegular_apply, scalarRegular_apply] + simp only [inverseCocycle, star_mul, lp.star_apply, star_star] + rw [Circle.coe_inv_eq_conj] + exact mul_comm _ _ + +lemma wotTranspose_regularGenerator (ω : ScalarCocycle G) (g : G) : + wotTranspose (regularGenerator ω g) = star (regularGenerator (inverseCocycle ω) g) := by + rw [← wotTranspose_star_regularGenerator, wotTranspose_star, star_star] + +def transposePreimage + (S : StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2)) : + StarSubalgebra ℂ (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2) where + carrier := {T | wotTranspose T ∈ S} + zero_mem' := by + change wotTranspose 0 ∈ S + rw [wotTranspose_zero] + exact zero_mem S + one_mem' := by + change wotTranspose 1 ∈ S + rw [wotTranspose_one] + exact one_mem S + add_mem' hT hU := by + change wotTranspose _ ∈ S + rw [wotTranspose_add] + exact add_mem hT hU + mul_mem' hT hU := by + change wotTranspose _ ∈ S + rw [wotTranspose_mul] + exact mul_mem hU hT + algebraMap_mem' z := by + change wotTranspose (algebraMap ℂ _ z) ∈ S + rw [Algebra.algebraMap_eq_smul_one, wotTranspose_smul, wotTranspose_one] + exact S.smul_mem S.one_mem z + star_mem' hT := by + change wotTranspose _ ∈ S + rw [wotTranspose_star] + exact star_mem hT + +lemma wotTranspose_mem_twistedGroupAlgebra (ω : ScalarCocycle G) + {T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2} + (hT : T ∈ twistedGroupAlgebra ω) : + wotTranspose T ∈ twistedGroupAlgebra (inverseCocycle ω) := by + have hgen : Set.range (regularGenerator ω) ⊆ + transposePreimage (twistedGroupAlgebra (inverseCocycle ω)) := by + rintro _ ⟨g,rfl⟩ + change wotTranspose (regularGenerator ω g) ∈ twistedGroupAlgebra (inverseCocycle ω) + rw [wotTranspose_regularGenerator] + exact star_mem (regularGenerator_mem _ g) + have hclosed : IsClosed (transposePreimage (twistedGroupAlgebra (inverseCocycle ω)) : + Set (lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2)) := by + change IsClosed (wotTranspose ⁻¹' (twistedGroupAlgebra (inverseCocycle ω)).carrier) + exact (StarSubalgebra.isClosed_topologicalClosure _).preimage wotTranspose_continuous + exact StarSubalgebra.topologicalClosure_minimal (StarAlgebra.adjoin_le hgen) hclosed hT + +def opTransposeOnTwisted (ω : ScalarCocycle G) : + (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] twistedGroupAlgebra (inverseCocycle ω) where + toFun T := ⟨wotTranspose T.unop.val, wotTranspose_mem_twistedGroupAlgebra ω T.unop.property⟩ + map_one' := Subtype.ext wotTranspose_one + map_mul' T S := Subtype.ext (wotTranspose_mul S.unop.val T.unop.val) + map_add' T S := Subtype.ext (wotTranspose_add T.unop.val S.unop.val) + map_zero' := Subtype.ext wotTranspose_zero + commutes' z := by + apply Subtype.ext + change wotTranspose (algebraMap ℂ _ z) = algebraMap ℂ _ z + rw [Algebra.algebraMap_eq_smul_one, wotTranspose_smul, wotTranspose_one] + map_star' T := Subtype.ext (wotTranspose_star T.unop.val) + +lemma opTransposeOnTwisted_continuous (ω : ScalarCocycle G) : + Continuous (opTransposeOnTwisted ω) := + (wotTranspose_continuous.comp (continuous_subtype_val.comp + MulOpposite.continuous_unop)).subtype_mk _ + +end + +section +open ArithmeticGerms GermBundles +section RightAction +variable {G H V J : Type*} [Group G] [Group H] [Fintype J] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (C : VirtualGraph G H) +local instance rightNormalActionDomainFintype : Fintype (G ⧸ C.domain) := + Subgroup.fintypeQuotientOfFiniteIndex +local instance rightNormalActionCodomainFintype : Fintype (H ⧸ C.codomain) := + Subgroup.fintypeQuotientOfFiniteIndex +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) +variable (b : OrthonormalBasis J ℂ V) + +def rightNormalAction : (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2) := + (rightAdjointNormalAction C μ ω B b).comp (opTransposeOnTwisted ω) + +theorem rightNormalAction_continuous : Continuous (rightNormalAction C μ ω B b) := + (rightAdjointNormalAction_continuous C μ ω B b).comp + (opTransposeOnTwisted_continuous ω) + +theorem rightNormalAction_adjoint_generator (h : H) : + rightNormalAction C μ ω B b + (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : + twistedGroupAlgebra ω))) = coordinateOperator C μ ω B (1,h) := by + have ht : opTransposeOnTwisted ω + (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : + twistedGroupAlgebra ω))) = + ⟨regularGenerator (inverseCocycle ω) h, regularGenerator_mem (inverseCocycle ω) h⟩ := + Subtype.ext (wotTranspose_star_regularGenerator ω h) + exact (congrArg (rightAdjointNormalAction C μ ω B b) ht).trans + (rightAdjointNormalAction_generator C μ ω B b h) + +theorem left_rightNormalActions_commute (T : twistedGroupAlgebra μ) + (S : (twistedGroupAlgebra ω)ᵐᵒᵖ) : + leftNormalAction C μ ω B b T * rightNormalAction C μ ω B b S = + rightNormalAction C μ ω B b S * leftNormalAction C μ ω B b T := + normalActions_commute C μ ω B b T (opTransposeOnTwisted ω S) + +end RightAction + +variable {G H V : Type*} [Group G] [Group H] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable (C : VirtualGraph G H) +local instance inducedGraphDomainFintype : Fintype (G ⧸ C.domain) := + Subgroup.fintypeQuotientOfFiniteIndex +local instance inducedGraphCodomainFintype : Fintype (H ⧸ C.codomain) := + Subgroup.fintypeQuotientOfFiniteIndex +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (r : CosetSection C.graph) +variable (γ : ProjectiveRepresentation ((prodRatio μ ω).restrict C.graph) V) + +theorem induced_graph_normal_actions : + let B := r.inducedBundle (prodRatio μ ω) γ + ∃ (L : twistedGroupAlgebra μ →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2)) + (R : (twistedGroupAlgebra ω)ᵐᵒᵖ →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →WOT[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2)) + (UL : PiLp 2 (fun _ : (H ⧸ C.codomain) × Fin (Module.finrank ℂ V) => + lp (fun _ : G => ℂ) 2) ≃ₗᵢ[ℂ] lp (fun _ : (G × H) ⧸ C.graph => V) 2) + (UR : PiLp 2 (fun _ : (G ⧸ C.domain) × Fin (Module.finrank ℂ V) => + lp (fun _ : H => ℂ) 2) ≃ₗᵢ[ℂ] lp (fun _ : (G × H) ⧸ C.graph => V) 2), + Continuous L ∧ Continuous R ∧ + (∀ T S, L T * R S = R S * L T) ∧ + (∀ g, L ⟨regularGenerator μ g, regularGenerator_mem μ g⟩ = + coordinateOperator C μ ω B (g,1)) ∧ + (∀ h, R (MulOpposite.op (star (⟨regularGenerator ω h, regularGenerator_mem ω h⟩ : + twistedGroupAlgebra ω))) = coordinateOperator C μ ω B (1,h)) ∧ + (∀ g v, B.action (g,1) (UL v) = UL + (amplify (scalarRegular μ g).toContinuousLinearEquiv.toContinuousLinearMap v)) ∧ + (∀ h v, B.action (1,h) (UR v) = UR + (amplify (scalarRegular (inverseCocycle ω) h).toContinuousLinearEquiv.toContinuousLinearMap v)) := by + let B := r.inducedBundle (prodRatio μ ω) γ + let b := stdOrthonormalBasis ℂ V + refine ⟨leftNormalAction C μ ω B b, rightNormalAction C μ ω B b, + firstFiniteRegularUnitary C μ ω B b, secondFiniteRegularUnitary C μ ω B b, + leftNormalAction_continuous C μ ω B b, rightNormalAction_continuous C μ ω B b, ?_⟩ + exact ⟨left_rightNormalActions_commute C μ ω B b, + leftNormalAction_generator C μ ω B b, rightNormalAction_adjoint_generator C μ ω B b, + firstFiniteRegularUnitary_intertwines C μ ω B b, + secondFiniteRegularUnitary_intertwines C μ ω B b⟩ + +end + +section +open GermBundles +variable {G : Type*} [Group G] + +def standardRightRegular (ω : ScalarCocycle G) (h : G) : + lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := + transportLp (Equiv.mulRight h) (fun g => circleUnitary (ω.val g h)) + +lemma standardRightRegular_apply (ω : ScalarCocycle G) (h : G) + (x : lp (fun _ : G => ℂ) 2) (g : G) : + standardRightRegular ω h x (g*h) = (ω.val g h : ℂ) * x g := + transportLp_apply (Equiv.mulRight h) (fun g => circleUnitary (ω.val g h)) x g + +def oppositeToStandard (ω : ScalarCocycle G) : + lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := + transportLp (Equiv.inv G) (fun g => circleUnitary ((ω.val g⁻¹ g)⁻¹)) + +lemma oppositeToStandard_apply (ω : ScalarCocycle G) + (x : lp (fun _ : G => ℂ) 2) (g : G) : + oppositeToStandard ω x g⁻¹ = ((ω.val g⁻¹ g)⁻¹ : Circle) * x g := by + exact transportLp_apply (Equiv.inv G) (fun g => circleUnitary ((ω.val g⁻¹ g)⁻¹)) x g + +lemma rightStandard_phase (ω : ScalarCocycle G) (h g : G) : + ω.val (h*g)⁻¹ h * (ω.val h g)⁻¹ * (ω.val (h*g)⁻¹ (h*g))⁻¹ = + (ω.val g⁻¹ g)⁻¹ := by + have hh := ω.mul_assoc (h*g)⁻¹ h g + have hg : (h*g)⁻¹ * h = g⁻¹ := by group + rw [hg] at hh + have he : ω.val (h*g)⁻¹ h = + (ω.val h g * ω.val (h*g)⁻¹ (h*g)) * (ω.val g⁻¹ g)⁻¹ := + (eq_mul_inv_iff_mul_eq).mpr hh + rw [he] + simp [mul_comm, mul_left_comm, mul_assoc] + +lemma oppositeToStandard_intertwines (ω : ScalarCocycle G) (h : G) + (x : lp (fun _ : G => ℂ) 2) : + oppositeToStandard ω (scalarRegular (inverseCocycle ω) h x) = + (standardRightRegular ω h).symm (oppositeToStandard ω x) := by + apply (standardRightRegular ω h).injective + rw [LinearIsometryEquiv.apply_symm_apply] + apply lp.ext + funext k + obtain ⟨g,rfl⟩ := (Equiv.inv G).surjective k + change standardRightRegular ω h (oppositeToStandard ω (scalarRegular (inverseCocycle ω) h x)) g⁻¹ = + oppositeToStandard ω x g⁻¹ + have hi : (h*g)⁻¹ * h = g⁻¹ := by group + rw [← hi, standardRightRegular_apply, oppositeToStandard_apply, scalarRegular_apply, + hi, oppositeToStandard_apply] + change (ω.val (h*g)⁻¹ h : ℂ) * + (((ω.val (h*g)⁻¹ (h*g))⁻¹ : Circle) * (((ω.val h g)⁻¹ : Circle) * x g)) = + ((ω.val g⁻¹ g)⁻¹ : Circle) * x g + have hp := congrArg (fun z : Circle => (z : ℂ)) (rightStandard_phase ω h g) + simp only [Circle.coe_mul] at hp + calc + _ = ((ω.val (h*g)⁻¹ h : ℂ) * ((ω.val h g)⁻¹ : Circle) * + ((ω.val (h*g)⁻¹ (h*g))⁻¹ : Circle)) * x g := by ring + _ = _ := congrArg (fun z : ℂ => z * x g) hp + +end + +open ArithmeticGerms GermBundles +section EntireRegularActions +variable {G H V J : Type*} [Group G] [Group H] [Fintype J] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (C : VirtualGraph G H) +local instance regularActionDomainFintype : Fintype (G ⧸ C.domain) := + Subgroup.fintypeQuotientOfFiniteIndex +local instance regularActionCodomainFintype : Fintype (H ⧸ C.codomain) := + Subgroup.fintypeQuotientOfFiniteIndex +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) +variable (b : OrthonormalBasis J ℂ V) + +lemma leftNormalAction_finite_regular (T : twistedGroupAlgebra μ) + (v : PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2)) : + leftNormalAction C μ ω B b T (firstFiniteRegularUnitary C μ ω B b v) = + firstFiniteRegularUnitary C μ ω B b (amplify T.val.toCLM v) := by + change firstFiniteRegularUnitary C μ ω B b + (amplify T.val.toCLM ((firstFiniteRegularUnitary C μ ω B b).symm + (firstFiniteRegularUnitary C μ ω B b v))) = _ + rw [LinearIsometryEquiv.symm_apply_apply] + +lemma rightNormalAction_finite_regular (S : (twistedGroupAlgebra ω)ᵐᵒᵖ) + (v : PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2)) : + rightNormalAction C μ ω B b S (secondFiniteRegularUnitary C μ ω B b v) = + secondFiniteRegularUnitary C μ ω B b (amplify + (wotTranspose S.unop.val).toCLM v) := by + change secondFiniteRegularUnitary C μ ω B b + (amplify (wotTranspose S.unop.val).toCLM ((secondFiniteRegularUnitary C μ ω B b).symm + (secondFiniteRegularUnitary C μ ω B b v))) = _ + rw [LinearIsometryEquiv.symm_apply_apply] + +end EntireRegularActions + +variable {G H V : Type*} [Group G] [Group H] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [FiniteDimensional ℂ V] +variable (C : VirtualGraph G H) +local instance multiplicityDomainFintype : Fintype (G ⧸ C.domain) := + Subgroup.fintypeQuotientOfFiniteIndex +local instance multiplicityCodomainFintype : Fintype (H ⧸ C.codomain) := + Subgroup.fintypeQuotientOfFiniteIndex + +omit [FiniteDimensional ℂ V] in +lemma graph_regular_multiplicities : + Fintype.card ((H ⧸ C.codomain) × Fin (Module.finrank ℂ V)) = + Module.finrank ℂ V * C.codomain.index ∧ + Fintype.card ((G ⧸ C.domain) × Fin (Module.finrank ℂ V)) = + Module.finrank ℂ V * C.domain.index := by + simp [Fintype.card_prod, Subgroup.index_eq_card, Nat.card_eq_fintype_card, mul_comm] + +end GraphNormality + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/GraphModels/Regular.lean b/lean/OAI/RepresentationTheory/GraphModels/Regular.lean index 8557b869ed7783be4d0d31f31e912b54fff1c3eb..87aa8bc38581282ba1936a0b8eb54dab16717fa5 100644 --- a/lean/OAI/RepresentationTheory/GraphModels/Regular.lean +++ b/lean/OAI/RepresentationTheory/GraphModels/Regular.lean @@ -1,679 +1,679 @@ -import Mathlib -import OAI.RepresentationTheory.GraphModels.Bundles - -namespace OAI - -noncomputable section - -/-! Regular coordinates and finite amplification of graph models. -/ - -namespace GraphNormality -section -open ArithmeticGerms GermBundles -variable {G H : Type*} [Group G] [Group H] -variable (C : VirtualGraph G H) (r : CosetSection C.codomain) - -def firstCoordinateMap (x : (H ⧸ C.codomain) × G) : (G × H) ⧸ C.graph := - QuotientGroup.mk (x.2, r.repr x.1) - -theorem firstCoordinateMap_injective : Function.Injective (firstCoordinateMap C r) := by - rintro ⟨i, g⟩ ⟨j, g'⟩ he - have hm : (g⁻¹ * g', (r.repr i)⁻¹ * r.repr j) ∈ C.graph := - QuotientGroup.eq.mp he - have hb : (r.repr i)⁻¹ * r.repr j ∈ C.codomain := - ⟨_, hm, rfl⟩ - have hij : i = j := by - rw [← r.repr_spec i, ← r.repr_spec j] - exact QuotientGroup.eq.mpr hb - subst j - have hg : g⁻¹ * g' = 1 := by - have h := C.snd_injective (a₁ := ⟨_, hm⟩) (a₂ := 1) (by simp) - exact congrArg (fun x : C.graph => x.val.1) h - exact Prod.ext rfl (inv_mul_eq_one.mp hg) - -theorem firstCoordinateMap_surjective : Function.Surjective (firstCoordinateMap C r) := by - intro x - induction x using QuotientGroup.induction_on with - | H x => - let q : H ⧸ C.codomain := QuotientGroup.mk x.2 - have hb : (r.repr q)⁻¹ * x.2 ∈ C.codomain := - QuotientGroup.eq.mp (r.repr_spec q) - obtain ⟨c, hc, he⟩ := hb - refine ⟨(q, x.1 * c.1⁻¹), ?_⟩ - apply QuotientGroup.eq.mpr - change (((x.1 * c.1⁻¹)⁻¹ * x.1), (r.repr q)⁻¹ * x.2) ∈ C.graph - have hf : (x.1 * c.1⁻¹)⁻¹ * x.1 = c.1 := by group - rw [hf, ← he] - exact hc - -def firstCoordinates : ((H ⧸ C.codomain) × G) ≃ ((G × H) ⧸ C.graph) := - Equiv.ofBijective (firstCoordinateMap C r) - ⟨firstCoordinateMap_injective C r, firstCoordinateMap_surjective C r⟩ - -theorem firstCoordinates_smul (a : G) (x : (H ⧸ C.codomain) × G) : - (a, (1 : H)) • firstCoordinates C r x = firstCoordinates C r (x.1, a * x.2) := by - change QuotientGroup.mk ((a, (1 : H)) * (x.2, r.repr x.1)) = - QuotientGroup.mk (a * x.2, r.repr x.1) - simp - -end - -section -section -attribute [local instance] Classical.propDecidable - -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -section Reindex -variable {X Y V W : Type*} -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] -variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] - -def transportLp (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) : - lp (fun _ : X => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : Y => W) 2 where - toLinearEquiv := - { toFun := fun v => ⟨fun y => u (e.symm y) (v (e.symm y)), by - apply memℓp_gen - convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.symm.injective using 1 - simp only [LinearIsometryEquiv.norm_map]; rfl⟩ - invFun := fun v => ⟨fun x => (u x).symm (v (e x)), by - apply memℓp_gen - convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.injective using 1 - simp only [LinearIsometryEquiv.norm_map]; rfl⟩ - left_inv := by - intro v - apply lp.ext - funext x - change (u x).symm (u (e.symm (e x)) (v (e.symm (e x)))) = _ - simp - right_inv := by - intro v - apply lp.ext - funext y - change u (e.symm y) ((u (e.symm y)).symm (v (e (e.symm y)))) = _ - simp - map_add' := by - intro v w - apply lp.ext - funext y - exact map_add _ _ _ - map_smul' := by - intro a v - apply lp.ext - funext y - exact map_smul _ _ _ } - norm_map' := by - intro v - rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] - congr 1 - change (∑' y, ‖u (e.symm y) (v (e.symm y))‖ ^ (2 : ENNReal).toReal) = _ - simp only [LinearIsometryEquiv.norm_map] - exact e.symm.tsum_eq (fun x => ‖v x‖ ^ (2 : ENNReal).toReal) - -theorem transportLp_apply (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) - (v : lp (fun _ : X => V) 2) (x : X) : - transportLp e u v (e x) = u x (v x) := by - change u (e.symm (e x)) (v (e.symm (e x))) = _ - simp - -theorem transportLp_single (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) - (x : X) (v : V) : - transportLp e u (lp.single 2 x v) = lp.single 2 (e x) (u x v) := by - apply lp.ext - funext y - by_cases hy : y = e x - · subst y - rw [transportLp_apply, lp.single_apply_self, lp.single_apply_self] - · have hxy : e.symm y ≠ x := by - intro h - exact hy ((e.apply_symm_apply y).symm.trans (congrArg e h)) - change u (e.symm y) ((lp.single 2 x v : lp (fun _ : X => V) 2) (e.symm y)) = _ - rw [lp.single_apply_ne (E := fun _ : X => V) 2 x v hxy, map_zero, - lp.single_apply_ne (E := fun _ : Y => W) 2 (e x) _ hy] -end Reindex - -open ArithmeticGerms GermBundles -variable {G H I V : Type*} [Group G] [Group H] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] - -def prodRatio (μ : ScalarCocycle G) (ω : ScalarCocycle H) : ScalarCocycle (G × H) where - val g h := μ.val g.1 h.1 / ω.val g.2 h.2 - mul_assoc g h j := by - dsimp - rw [div_mul_div_comm, div_mul_div_comm, μ.mul_assoc, ω.mul_assoc] - one_left g := by simp [μ.one_left, ω.one_left] - one_right g := by simp [μ.one_right, ω.one_right] - -def regularPerm (a : G) : I × G ≃ I × G where - toFun x := (x.1, a * x.2) - invFun x := (x.1, a⁻¹ * x.2) - left_inv x := by simp - right_inv x := by simp - -def regularAction (μ : ScalarCocycle G) (a : G) : - lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : I × G => V) 2 := - transportLp (regularPerm a) (fun x => circleUnitary (μ.val a x.2)) - -theorem regularAction_single (μ : ScalarCocycle G) (a : G) (i : I) (g : G) (v : V) : - regularAction μ a (lp.single 2 (i,g) v) = - lp.single 2 (i,a*g) ((μ.val a g : ℂ) • v) := by - exact transportLp_single (regularPerm (I := I) a) - (fun x => circleUnitary (V := V) (μ.val a x.2)) (i, g) v - -variable (C : VirtualGraph G H) (r : CosetSection C.codomain) -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) - -def firstRegularUnitary : - lp (fun _ : (H ⧸ C.codomain) × G => V) 2 ≃ₗᵢ[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2 := - transportLp (firstCoordinates C r) (fun x => - B.fibre (x.2, 1) (firstCoordinates C r (x.1, 1)) (firstCoordinates C r x) (by - simpa using firstCoordinates_smul C r x.2 (x.1, 1))) - -theorem firstRegularUnitary_single (i : H ⧸ C.codomain) (g : G) (v : V) : - firstRegularUnitary C r μ ω B (lp.single 2 (i,g) v) = - B.action (g,1) (lp.single 2 (firstCoordinates C r (i,1)) v) := by - rw [firstRegularUnitary, transportLp_single] - exact (B.action_single (g,1) _ _ _ v).symm - -theorem firstRegularUnitary_intertwines (a : G) - (v : lp (fun _ : (H ⧸ C.codomain) × G => V) 2) : - B.action (a,1) (firstRegularUnitary C r μ ω B v) = - firstRegularUnitary C r μ ω B (regularAction μ a v) := by - have he : - (B.action (a,1)).toContinuousLinearEquiv.toContinuousLinearMap.comp - (firstRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap = - (firstRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap.comp - (regularAction μ a).toContinuousLinearEquiv.toContinuousLinearMap := by - apply lp.ext_continuousLinearMap (by norm_num) - rintro ⟨i,g⟩ - apply ContinuousLinearMap.ext - intro w - change B.action (a,1) (firstRegularUnitary C r μ ω B (lp.single 2 (i,g) w)) = - firstRegularUnitary C r μ ω B (regularAction μ a (lp.single 2 (i,g) w)) - rw [firstRegularUnitary_single, B.action_mul, regularAction_single, - firstRegularUnitary_single, lp.single_smul, map_smul] - simp [prodRatio, ω.one_left] - exact DFunLike.congr_fun he v - -end - -open ArithmeticGerms GermBundles -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -variable {G H V : Type*} [Group G] [Group H] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] -variable (C : VirtualGraph G H) (r : CosetSection C.domain) - -def secondCoordinateMap (x : (G ⧸ C.domain) × H) : (G × H) ⧸ C.graph := - QuotientGroup.mk (r.repr x.1, x.2) - -theorem secondCoordinateMap_injective : Function.Injective (secondCoordinateMap C r) := by - rintro ⟨i, h⟩ ⟨j, h'⟩ he - have hm : ((r.repr i)⁻¹ * r.repr j, h⁻¹ * h') ∈ C.graph := - QuotientGroup.eq.mp he - have hb : (r.repr i)⁻¹ * r.repr j ∈ C.domain := ⟨_, hm, rfl⟩ - have hij : i = j := by - rw [← r.repr_spec i, ← r.repr_spec j] - exact QuotientGroup.eq.mpr hb - subst j - have hh : h⁻¹ * h' = 1 := by - have hh := C.fst_injective (a₁ := ⟨_, hm⟩) (a₂ := 1) (by simp) - exact congrArg (fun x : C.graph => x.val.2) hh - exact Prod.ext rfl (inv_mul_eq_one.mp hh) - -theorem secondCoordinateMap_surjective : Function.Surjective (secondCoordinateMap C r) := by - intro x - induction x using QuotientGroup.induction_on with - | H x => - let q : G ⧸ C.domain := QuotientGroup.mk x.1 - have hb : (r.repr q)⁻¹ * x.1 ∈ C.domain := - QuotientGroup.eq.mp (r.repr_spec q) - obtain ⟨c, hc, he⟩ := hb - refine ⟨(q, x.2 * c.2⁻¹), ?_⟩ - apply QuotientGroup.eq.mpr - change ((r.repr q)⁻¹ * x.1, ((x.2 * c.2⁻¹)⁻¹ * x.2)) ∈ C.graph - have hf : (x.2 * c.2⁻¹)⁻¹ * x.2 = c.2 := by group - rw [hf, ← he] - exact hc - -def secondCoordinates : ((G ⧸ C.domain) × H) ≃ ((G × H) ⧸ C.graph) := - Equiv.ofBijective (secondCoordinateMap C r) - ⟨secondCoordinateMap_injective C r, secondCoordinateMap_surjective C r⟩ - -theorem secondCoordinates_smul (a : H) (x : (G ⧸ C.domain) × H) : - ((1 : G), a) • secondCoordinates C r x = secondCoordinates C r (x.1, a * x.2) := by - change QuotientGroup.mk (((1 : G), a) * (r.repr x.1, x.2)) = - QuotientGroup.mk (r.repr x.1, a * x.2) - simp - -def inverseCocycle (ω : ScalarCocycle H) : ScalarCocycle H where - val h k := (ω.val h k)⁻¹ - mul_assoc h k l := by - simpa only [mul_inv] using congrArg Inv.inv (ω.mul_assoc h k l) - one_left h := by simp [ω.one_left] - one_right h := by simp [ω.one_right] - -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) - -def secondRegularUnitary : - lp (fun _ : (G ⧸ C.domain) × H => V) 2 ≃ₗᵢ[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2 := - transportLp (secondCoordinates C r) (fun x => - B.fibre (1, x.2) (secondCoordinates C r (x.1, 1)) (secondCoordinates C r x) (by - simpa using secondCoordinates_smul C r x.2 (x.1, 1))) - -theorem secondRegularUnitary_single (i : G ⧸ C.domain) (h : H) (v : V) : - secondRegularUnitary C r μ ω B (lp.single 2 (i,h) v) = - B.action (1,h) (lp.single 2 (secondCoordinates C r (i,1)) v) := by - rw [secondRegularUnitary, transportLp_single] - exact (B.action_single (1,h) _ _ _ v).symm - -theorem secondRegularUnitary_intertwines (a : H) - (v : lp (fun _ : (G ⧸ C.domain) × H => V) 2) : - B.action (1,a) (secondRegularUnitary C r μ ω B v) = - secondRegularUnitary C r μ ω B (regularAction (inverseCocycle ω) a v) := by - have he : - (B.action (1,a)).toContinuousLinearEquiv.toContinuousLinearMap.comp - (secondRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap = - (secondRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap.comp - (regularAction (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap := by - apply lp.ext_continuousLinearMap (by norm_num) - rintro ⟨i,h⟩ - apply ContinuousLinearMap.ext - intro w - change B.action (1,a) (secondRegularUnitary C r μ ω B (lp.single 2 (i,h) w)) = - secondRegularUnitary C r μ ω B (regularAction (inverseCocycle ω) a (lp.single 2 (i,h) w)) - rw [secondRegularUnitary_single, B.action_mul, regularAction_single, - secondRegularUnitary_single, lp.single_smul, map_smul] - simp [prodRatio, inverseCocycle, μ.one_left] - exact DFunLike.congr_fun he v - -theorem coordinate_actions_commute (g : G) (h : H) - (v : lp (fun _ : (G × H) ⧸ C.graph => V) 2) : - B.action (g,1) (B.action (1,h) v) = B.action (1,h) (B.action (g,1) v) := by - rw [B.action_mul, B.action_mul] - simp [prodRatio, μ.one_left, μ.one_right, ω.one_left, ω.one_right] - -end - -section -open GermBundles -open scoped InnerProductSpace -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -section ScalarMultiplicity -variable {I J G V : Type*} [Fintype J] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (b : OrthonormalBasis J ℂ V) - -def bundleBasisVector (x : (I × J) × G) : lp (fun _ : I × G => V) 2 := - lp.single 2 (x.1.1, x.2) (b x.1.2) - -omit [CompleteSpace V] in -theorem bundleBasisVector_orthonormal : Orthonormal ℂ (bundleBasisVector (I := I) (G := G) b) := by - rw [orthonormal_iff_ite] - rintro ⟨⟨i,j⟩,g⟩ ⟨⟨k,l⟩,h⟩ - change ⟪lp.single (E := fun _ : I × G => V) 2 (i,g) (b j), - lp.single (E := fun _ : I × G => V) 2 (k,h) (b l)⟫_ℂ = _ - rw [lp.inner_single_left] - by_cases hi : i = k - · subst k - by_cases hg : g = h - · subst h - rw [lp.single_apply_self] - simpa only [Prod.mk.injEq, true_and, and_true] using - (orthonormal_iff_ite.mp b.orthonormal j l) - · rw [lp.single_apply_ne (E := fun _ : I × G => V) 2 (i,h) (b l) - (fun hh => hg (congrArg Prod.snd hh))] - simp [hg] - · rw [lp.single_apply_ne (E := fun _ : I × G => V) 2 (k,h) (b l) - (fun hh => hi (congrArg Prod.fst hh))] - simp [hi] - -omit [CompleteSpace V] in -theorem bundleBasisVector_total : - (Submodule.span ℂ (Set.range (bundleBasisVector (I := I) (G := G) b)))ᗮ = ⊥ := by - apply le_antisymm _ bot_le - intro v hv - change v = 0 - apply lp.ext - funext x - change v x = 0 - apply b.repr.injective - ext j - rw [b.repr_apply_apply, map_zero] - have h := Submodule.inner_right_of_mem_orthogonal - (Submodule.subset_span (Set.mem_range_self ((x.1,j),x.2))) hv - simpa only [bundleBasisVector, Prod.eta, lp.inner_single_left, PiLp.zero_apply] using h - -def regularHilbertBasis : HilbertBasis ((I × J) × G) ℂ (lp (fun _ : I × G => V) 2) := - HilbertBasis.mkOfOrthogonalEqBot (bundleBasisVector_orthonormal b) (bundleBasisVector_total b) - -@[simp] theorem regularHilbertBasis_apply (x : (I × J) × G) : - regularHilbertBasis b x = bundleBasisVector b x := by - exact congrFun (HilbertBasis.coe_mkOfOrthogonalEqBot _ _) x - -def scalarization : lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : (I × J) × G => ℂ) 2 := - (regularHilbertBasis b).repr - -theorem scalarization_apply (v : lp (fun _ : I × G => V) 2) (i : I) (j : J) (g : G) : - scalarization b v ((i,j),g) = ⟪b j, v (i,g)⟫_ℂ := by - change (regularHilbertBasis b).repr v ((i,j),g) = _ - rw [HilbertBasis.repr_apply_apply, regularHilbertBasis_apply] - exact lp.inner_single_left _ _ _ - -end ScalarMultiplicity - -section ScalarRegular -variable {I G V : Type*} [Group G] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] - -theorem regularAction_apply (μ : ScalarCocycle G) (a : G) - (v : lp (fun _ : I × G => V) 2) (i : I) (g : G) : - regularAction μ a v (i,a*g) = (μ.val a g : ℂ) • v (i,g) := by - exact transportLp_apply (regularPerm a) (fun x => circleUnitary (μ.val a x.2)) v (i,g) - -end ScalarRegular - -variable {I J G V : Type*} [Fintype J] [Group G] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (b : OrthonormalBasis J ℂ V) - -theorem scalarization_intertwines (μ : ScalarCocycle G) (a : G) - (v : lp (fun _ : I × G => V) 2) : - scalarization b (regularAction μ a v) = regularAction μ a (scalarization b v) := by - apply lp.ext - funext x - obtain ⟨y,rfl⟩ := (regularPerm (I := I × J) a).surjective x - rcases y with ⟨⟨i,j⟩,g⟩ - change scalarization b (regularAction μ a v) ((i,j),a*g) = - regularAction μ a (scalarization b v) ((i,j),a*g) - rw [scalarization_apply, regularAction_apply, inner_smul_right, - regularAction_apply, scalarization_apply] - rfl - -end - -section -open scoped InnerProductSpace -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -variable {K G : Type*} [Fintype K] - -def finiteSumBasisVector (x : K × G) : PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2) := - PiLp.single 2 x.1 (lp.single 2 x.2 1) - -theorem finiteSumBasisVector_inner (x : K × G) - (v : PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2)) : - ⟪finiteSumBasisVector x, v⟫_ℂ = v x.1 x.2 := by - rw [PiLp.inner_apply, Finset.sum_eq_single x.1] - · simp [finiteSumBasisVector, lp.inner_single_left] - · intro i hi hix - simp [finiteSumBasisVector, hix] - · simp - -theorem finiteSumBasisVector_orthonormal : - Orthonormal ℂ (finiteSumBasisVector (K := K) (G := G)) := by - rw [orthonormal_iff_ite] - rintro ⟨i,g⟩ ⟨j,h⟩ - rw [finiteSumBasisVector_inner] - by_cases hi : i = j - · subst j - simp [finiteSumBasisVector, lp.single_apply, Pi.single_apply] - · simp [finiteSumBasisVector, hi] - -theorem finiteSumBasisVector_total : - (Submodule.span ℂ (Set.range (finiteSumBasisVector (K := K) (G := G))))ᗮ = ⊥ := by - apply le_antisymm _ bot_le - intro v hv - change v = 0 - ext i g - change v i g = 0 - have h := Submodule.inner_right_of_mem_orthogonal - (Submodule.subset_span (Set.mem_range_self (i,g))) hv - simpa only [finiteSumBasisVector_inner] using h - -def finiteSumHilbertBasis : - HilbertBasis (K × G) ℂ (PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2)) := - HilbertBasis.mkOfOrthogonalEqBot finiteSumBasisVector_orthonormal finiteSumBasisVector_total - -@[simp] theorem finiteSumHilbertBasis_apply (x : K × G) : - finiteSumHilbertBasis x = finiteSumBasisVector x := by - exact congrFun (HilbertBasis.coe_mkOfOrthogonalEqBot _ _) x - -def finiteRegrouping : lp (fun _ : K × G => ℂ) 2 ≃ₗᵢ[ℂ] - PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2) := - finiteSumHilbertBasis.repr.symm - -theorem finiteRegrouping_apply (v : lp (fun _ : K × G => ℂ) 2) (i : K) (g : G) : - finiteRegrouping v i g = v (i,g) := by - have h := congrArg (fun f : lp (fun _ : K × G => ℂ) 2 => f (i,g)) - (finiteSumHilbertBasis.repr.apply_symm_apply v) - rw [HilbertBasis.repr_apply_apply, finiteSumHilbertBasis_apply, - finiteSumBasisVector_inner] at h - exact h - -end - -section -open scoped InnerProductSpace -variable {K L : Type*} [Fintype K] -variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] - -def amplify (T : L →L[ℂ] L) : - PiLp 2 (fun _ : K => L) →L[ℂ] PiLp 2 (fun _ : K => L) := - (PiLp.continuousLinearEquiv 2 ℂ (fun _ : K => L)).symm.toContinuousLinearMap.comp - ((ContinuousLinearMap.pi (fun i : K => T.comp (ContinuousLinearMap.proj i))).comp - (PiLp.continuousLinearEquiv 2 ℂ (fun _ : K => L)).toContinuousLinearMap) - -omit [Fintype K] [CompleteSpace L] in -@[simp] theorem amplify_apply (T : L →L[ℂ] L) (v : PiLp 2 (fun _ : K => L)) (i : K) : - amplify T v i = T (v i) := rfl - -def amplification : (L →L[ℂ] L) →⋆ₐ[ℂ] - (PiLp 2 (fun _ : K => L) →L[ℂ] PiLp 2 (fun _ : K => L)) where - toFun := amplify - map_one' := by ext v i; rfl - map_mul' T S := by ext v i; rfl - map_add' T S := by ext v i; rfl - map_zero' := by ext v i; rfl - commutes' z := by ext v i; rfl - map_star' T := by - change amplify (K := K) (ContinuousLinearMap.adjoint T) = - ContinuousLinearMap.adjoint (amplify (K := K) T) - apply (ContinuousLinearMap.eq_adjoint_iff _ _).mpr - intro v w - simp only [PiLp.inner_apply, amplify_apply, ContinuousLinearMap.adjoint_inner_left] - -theorem amplification_wot_continuous : - Continuous (fun T : L →WOT[ℂ] L => - ContinuousLinearMapWOT.ofCLM (amplification (K := K) (L := L) (ContinuousLinearMapWOT.toCLM T))) := by - apply ContinuousLinearMapWOT.continuous_iff.mpr - intro v w - change Continuous (fun T : L →WOT[ℂ] L => ∑ i : K, ⟪w i, T (v i)⟫_ℂ) - apply continuous_finsetSum - intro i hi - exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (v i) (w i) - -end - -section -open scoped InnerProductSpace -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -open GermBundles - -section ScalarTwistedRegular -variable {G K : Type*} [Group G] [Fintype K] - -def scalarRegular (μ : ScalarCocycle G) (a : G) : - lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := - transportLp (Equiv.mulLeft a) (fun g => circleUnitary (μ.val a g)) - -theorem scalarRegular_apply (μ : ScalarCocycle G) (a : G) - (v : lp (fun _ : G => ℂ) 2) (g : G) : - scalarRegular μ a v (a*g) = (μ.val a g : ℂ) * v g := by - exact transportLp_apply (Equiv.mulLeft a) (fun g => circleUnitary (μ.val a g)) v g - -theorem finiteRegrouping_intertwines (μ : ScalarCocycle G) (a : G) - (v : lp (fun _ : K × G => ℂ) 2) : - finiteRegrouping (regularAction μ a v) = - amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap - (finiteRegrouping v) := by - ext i g - obtain ⟨h,rfl⟩ := (Equiv.mulLeft a).surjective g - change finiteRegrouping (regularAction μ a v) i (a*h) = - scalarRegular μ a (finiteRegrouping v i) (a*h) - rw [finiteRegrouping_apply, regularAction_apply, scalarRegular_apply, - finiteRegrouping_apply] - rfl - -end ScalarTwistedRegular - -variable {L W : Type*} -variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] -variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] [CompleteSpace W] - -theorem unitaryConjugation_wot_continuous (U : L ≃ₗᵢ[ℂ] W) : - Continuous (fun T : L →WOT[ℂ] L => - ContinuousLinearMapWOT.ofCLM (U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T))) := by - apply ContinuousLinearMapWOT.continuous_iff.mpr - intro v w - have h : (fun T : L →WOT[ℂ] L => - ⟪w, U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T) v⟫_ℂ) = - (fun T : L →WOT[ℂ] L => ⟪U.symm w, T (U.symm v)⟫_ℂ) := by - funext T - rw [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply] - conv_lhs => lhs; rw [← U.apply_symm_apply w] - exact U.inner_map_map _ _ - change Continuous (fun T : L →WOT[ℂ] L => - ⟪w, U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T) v⟫_ℂ) - rw [h] - exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (U.symm v) (U.symm w) - -end - -open ArithmeticGerms GermBundles -local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X - -section FiniteRegularModules -variable {I J G V : Type*} [Fintype I] [Fintype J] [Group G] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (b : OrthonormalBasis J ℂ V) - -def regularToFinite : lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] - PiLp 2 (fun _ : I × J => lp (fun _ : G => ℂ) 2) := - (scalarization b).trans finiteRegrouping - -theorem regularToFinite_intertwines (μ : ScalarCocycle G) (a : G) - (v : lp (fun _ : I × G => V) 2) : - regularToFinite b (regularAction μ a v) = - amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap - (regularToFinite b v) := by - change finiteRegrouping (scalarization b (regularAction μ a v)) = _ - rw [scalarization_intertwines, finiteRegrouping_intertwines] - rfl - -end FiniteRegularModules - -variable {G H V J : Type*} [Group G] [Group H] [Fintype J] -variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] -variable (C : VirtualGraph G H) -local instance : Fintype (G ⧸ C.domain) := Subgroup.fintypeQuotientOfFiniteIndex -local instance : Fintype (H ⧸ C.codomain) := Subgroup.fintypeQuotientOfFiniteIndex - -variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) -variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) -variable (b : OrthonormalBasis J ℂ V) - -def firstFiniteRegularUnitary : - PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2) ≃ₗᵢ[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2 := - (regularToFinite b).symm.trans - (firstRegularUnitary C (chooseCosetSection C.codomain) μ ω B) - -theorem firstFiniteRegularUnitary_intertwines (a : G) - (v : PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2)) : - B.action (a,1) (firstFiniteRegularUnitary C μ ω B b v) = - firstFiniteRegularUnitary C μ ω B b - (amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap v) := by - change B.action (a,1) (firstRegularUnitary C _ μ ω B ((regularToFinite b).symm v)) = - firstRegularUnitary C _ μ ω B ((regularToFinite b).symm _) - rw [firstRegularUnitary_intertwines] - congr 1 - apply (regularToFinite b).injective - rw [LinearIsometryEquiv.apply_symm_apply] - simpa only [LinearIsometryEquiv.apply_symm_apply] using - regularToFinite_intertwines b μ a ((regularToFinite b).symm v) - -def secondFiniteRegularUnitary : - PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2) ≃ₗᵢ[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2 := - (regularToFinite b).symm.trans - (secondRegularUnitary C (chooseCosetSection C.domain) μ ω B) - -theorem secondFiniteRegularUnitary_intertwines (a : H) - (v : PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2)) : - B.action (1,a) (secondFiniteRegularUnitary C μ ω B b v) = - secondFiniteRegularUnitary C μ ω B b - (amplify (scalarRegular (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap v) := by - change B.action (1,a) (secondRegularUnitary C _ μ ω B ((regularToFinite b).symm v)) = - secondRegularUnitary C _ μ ω B ((regularToFinite b).symm _) - rw [secondRegularUnitary_intertwines] - congr 1 - apply (regularToFinite b).injective - rw [LinearIsometryEquiv.apply_symm_apply] - simpa only [LinearIsometryEquiv.apply_symm_apply] using - regularToFinite_intertwines b (inverseCocycle ω) a ((regularToFinite b).symm v) - -def firstExtension : (lp (fun _ : G => ℂ) 2 →L[ℂ] lp (fun _ : G => ℂ) 2) →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →L[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2) := - (firstFiniteRegularUnitary C μ ω B b).conjStarAlgEquiv.toStarAlgHom.comp - (amplification (K := (H ⧸ C.codomain) × J)) - -def secondExtension : (lp (fun _ : H => ℂ) 2 →L[ℂ] lp (fun _ : H => ℂ) 2) →⋆ₐ[ℂ] - (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →L[ℂ] - lp (fun _ : (G × H) ⧸ C.graph => V) 2) := - (secondFiniteRegularUnitary C μ ω B b).conjStarAlgEquiv.toStarAlgHom.comp - (amplification (K := (G ⧸ C.domain) × J)) - -theorem firstExtension_generator (a : G) : - firstExtension C μ ω B b (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap = - (B.action (a,1)).toContinuousLinearEquiv.toContinuousLinearMap := by - apply ContinuousLinearMap.ext - intro v - change firstFiniteRegularUnitary C μ ω B b - (amplify _ ((firstFiniteRegularUnitary C μ ω B b).symm v)) = B.action (a,1) v - rw [← firstFiniteRegularUnitary_intertwines, LinearIsometryEquiv.apply_symm_apply] - -theorem secondExtension_generator (a : H) : - secondExtension C μ ω B b - (scalarRegular (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap = - (B.action (1,a)).toContinuousLinearEquiv.toContinuousLinearMap := by - apply ContinuousLinearMap.ext - intro v - change secondFiniteRegularUnitary C μ ω B b - (amplify _ ((secondFiniteRegularUnitary C μ ω B b).symm v)) = B.action (1,a) v - rw [← secondFiniteRegularUnitary_intertwines, LinearIsometryEquiv.apply_symm_apply] - -theorem firstExtension_wot_continuous : - Continuous (fun T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 => - ContinuousLinearMapWOT.ofCLM (firstExtension C μ ω B b T.toCLM)) := - (unitaryConjugation_wot_continuous (firstFiniteRegularUnitary C μ ω B b)).comp - (amplification_wot_continuous (K := (H ⧸ C.codomain) × J)) - -theorem secondExtension_wot_continuous : - Continuous (fun T : lp (fun _ : H => ℂ) 2 →WOT[ℂ] lp (fun _ : H => ℂ) 2 => - ContinuousLinearMapWOT.ofCLM (secondExtension C μ ω B b T.toCLM)) := - (unitaryConjugation_wot_continuous (secondFiniteRegularUnitary C μ ω B b)).comp - (amplification_wot_continuous (K := (G ⧸ C.domain) × J)) - -end GraphNormality - -end - -end OAI +import Mathlib +import OAI.RepresentationTheory.GraphModels.Bundles + +namespace OAI + +noncomputable section + +/-! Regular coordinates and finite amplification of graph models. -/ + +namespace GraphNormality +section +open ArithmeticGerms GermBundles +variable {G H : Type*} [Group G] [Group H] +variable (C : VirtualGraph G H) (r : CosetSection C.codomain) + +def firstCoordinateMap (x : (H ⧸ C.codomain) × G) : (G × H) ⧸ C.graph := + QuotientGroup.mk (x.2, r.repr x.1) + +theorem firstCoordinateMap_injective : Function.Injective (firstCoordinateMap C r) := by + rintro ⟨i, g⟩ ⟨j, g'⟩ he + have hm : (g⁻¹ * g', (r.repr i)⁻¹ * r.repr j) ∈ C.graph := + QuotientGroup.eq.mp he + have hb : (r.repr i)⁻¹ * r.repr j ∈ C.codomain := + ⟨_, hm, rfl⟩ + have hij : i = j := by + rw [← r.repr_spec i, ← r.repr_spec j] + exact QuotientGroup.eq.mpr hb + subst j + have hg : g⁻¹ * g' = 1 := by + have h := C.snd_injective (a₁ := ⟨_, hm⟩) (a₂ := 1) (by simp) + exact congrArg (fun x : C.graph => x.val.1) h + exact Prod.ext rfl (inv_mul_eq_one.mp hg) + +theorem firstCoordinateMap_surjective : Function.Surjective (firstCoordinateMap C r) := by + intro x + induction x using QuotientGroup.induction_on with + | H x => + let q : H ⧸ C.codomain := QuotientGroup.mk x.2 + have hb : (r.repr q)⁻¹ * x.2 ∈ C.codomain := + QuotientGroup.eq.mp (r.repr_spec q) + obtain ⟨c, hc, he⟩ := hb + refine ⟨(q, x.1 * c.1⁻¹), ?_⟩ + apply QuotientGroup.eq.mpr + change (((x.1 * c.1⁻¹)⁻¹ * x.1), (r.repr q)⁻¹ * x.2) ∈ C.graph + have hf : (x.1 * c.1⁻¹)⁻¹ * x.1 = c.1 := by group + rw [hf, ← he] + exact hc + +def firstCoordinates : ((H ⧸ C.codomain) × G) ≃ ((G × H) ⧸ C.graph) := + Equiv.ofBijective (firstCoordinateMap C r) + ⟨firstCoordinateMap_injective C r, firstCoordinateMap_surjective C r⟩ + +theorem firstCoordinates_smul (a : G) (x : (H ⧸ C.codomain) × G) : + (a, (1 : H)) • firstCoordinates C r x = firstCoordinates C r (x.1, a * x.2) := by + change QuotientGroup.mk ((a, (1 : H)) * (x.2, r.repr x.1)) = + QuotientGroup.mk (a * x.2, r.repr x.1) + simp + +end + +section +section +attribute [local instance] Classical.propDecidable + +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +section Reindex +variable {X Y V W : Type*} +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] +variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] + +def transportLp (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) : + lp (fun _ : X => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : Y => W) 2 where + toLinearEquiv := + { toFun := fun v => ⟨fun y => u (e.symm y) (v (e.symm y)), by + apply memℓp_gen + convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.symm.injective using 1 + simp only [LinearIsometryEquiv.norm_map]; rfl⟩ + invFun := fun v => ⟨fun x => (u x).symm (v (e x)), by + apply memℓp_gen + convert! ((lp.memℓp v).summable (by norm_num)).comp_injective e.injective using 1 + simp only [LinearIsometryEquiv.norm_map]; rfl⟩ + left_inv := by + intro v + apply lp.ext + funext x + change (u x).symm (u (e.symm (e x)) (v (e.symm (e x)))) = _ + simp + right_inv := by + intro v + apply lp.ext + funext y + change u (e.symm y) ((u (e.symm y)).symm (v (e (e.symm y)))) = _ + simp + map_add' := by + intro v w + apply lp.ext + funext y + exact map_add _ _ _ + map_smul' := by + intro a v + apply lp.ext + funext y + exact map_smul _ _ _ } + norm_map' := by + intro v + rw [lp.norm_eq_tsum_rpow (by norm_num), lp.norm_eq_tsum_rpow (by norm_num)] + congr 1 + change (∑' y, ‖u (e.symm y) (v (e.symm y))‖ ^ (2 : ENNReal).toReal) = _ + simp only [LinearIsometryEquiv.norm_map] + exact e.symm.tsum_eq (fun x => ‖v x‖ ^ (2 : ENNReal).toReal) + +theorem transportLp_apply (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) + (v : lp (fun _ : X => V) 2) (x : X) : + transportLp e u v (e x) = u x (v x) := by + change u (e.symm (e x)) (v (e.symm (e x))) = _ + simp + +theorem transportLp_single (e : X ≃ Y) (u : X → V ≃ₗᵢ[ℂ] W) + (x : X) (v : V) : + transportLp e u (lp.single 2 x v) = lp.single 2 (e x) (u x v) := by + apply lp.ext + funext y + by_cases hy : y = e x + · subst y + rw [transportLp_apply, lp.single_apply_self, lp.single_apply_self] + · have hxy : e.symm y ≠ x := by + intro h + exact hy ((e.apply_symm_apply y).symm.trans (congrArg e h)) + change u (e.symm y) ((lp.single 2 x v : lp (fun _ : X => V) 2) (e.symm y)) = _ + rw [lp.single_apply_ne (E := fun _ : X => V) 2 x v hxy, map_zero, + lp.single_apply_ne (E := fun _ : Y => W) 2 (e x) _ hy] +end Reindex + +open ArithmeticGerms GermBundles +variable {G H I V : Type*} [Group G] [Group H] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] + +def prodRatio (μ : ScalarCocycle G) (ω : ScalarCocycle H) : ScalarCocycle (G × H) where + val g h := μ.val g.1 h.1 / ω.val g.2 h.2 + mul_assoc g h j := by + dsimp + rw [div_mul_div_comm, div_mul_div_comm, μ.mul_assoc, ω.mul_assoc] + one_left g := by simp [μ.one_left, ω.one_left] + one_right g := by simp [μ.one_right, ω.one_right] + +def regularPerm (a : G) : I × G ≃ I × G where + toFun x := (x.1, a * x.2) + invFun x := (x.1, a⁻¹ * x.2) + left_inv x := by simp + right_inv x := by simp + +def regularAction (μ : ScalarCocycle G) (a : G) : + lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : I × G => V) 2 := + transportLp (regularPerm a) (fun x => circleUnitary (μ.val a x.2)) + +theorem regularAction_single (μ : ScalarCocycle G) (a : G) (i : I) (g : G) (v : V) : + regularAction μ a (lp.single 2 (i,g) v) = + lp.single 2 (i,a*g) ((μ.val a g : ℂ) • v) := by + exact transportLp_single (regularPerm (I := I) a) + (fun x => circleUnitary (V := V) (μ.val a x.2)) (i, g) v + +variable (C : VirtualGraph G H) (r : CosetSection C.codomain) +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) + +def firstRegularUnitary : + lp (fun _ : (H ⧸ C.codomain) × G => V) 2 ≃ₗᵢ[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2 := + transportLp (firstCoordinates C r) (fun x => + B.fibre (x.2, 1) (firstCoordinates C r (x.1, 1)) (firstCoordinates C r x) (by + simpa using firstCoordinates_smul C r x.2 (x.1, 1))) + +theorem firstRegularUnitary_single (i : H ⧸ C.codomain) (g : G) (v : V) : + firstRegularUnitary C r μ ω B (lp.single 2 (i,g) v) = + B.action (g,1) (lp.single 2 (firstCoordinates C r (i,1)) v) := by + rw [firstRegularUnitary, transportLp_single] + exact (B.action_single (g,1) _ _ _ v).symm + +theorem firstRegularUnitary_intertwines (a : G) + (v : lp (fun _ : (H ⧸ C.codomain) × G => V) 2) : + B.action (a,1) (firstRegularUnitary C r μ ω B v) = + firstRegularUnitary C r μ ω B (regularAction μ a v) := by + have he : + (B.action (a,1)).toContinuousLinearEquiv.toContinuousLinearMap.comp + (firstRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap = + (firstRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap.comp + (regularAction μ a).toContinuousLinearEquiv.toContinuousLinearMap := by + apply lp.ext_continuousLinearMap (by norm_num) + rintro ⟨i,g⟩ + apply ContinuousLinearMap.ext + intro w + change B.action (a,1) (firstRegularUnitary C r μ ω B (lp.single 2 (i,g) w)) = + firstRegularUnitary C r μ ω B (regularAction μ a (lp.single 2 (i,g) w)) + rw [firstRegularUnitary_single, B.action_mul, regularAction_single, + firstRegularUnitary_single, lp.single_smul, map_smul] + simp [prodRatio, ω.one_left] + exact DFunLike.congr_fun he v + +end + +open ArithmeticGerms GermBundles +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +variable {G H V : Type*} [Group G] [Group H] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] +variable (C : VirtualGraph G H) (r : CosetSection C.domain) + +def secondCoordinateMap (x : (G ⧸ C.domain) × H) : (G × H) ⧸ C.graph := + QuotientGroup.mk (r.repr x.1, x.2) + +theorem secondCoordinateMap_injective : Function.Injective (secondCoordinateMap C r) := by + rintro ⟨i, h⟩ ⟨j, h'⟩ he + have hm : ((r.repr i)⁻¹ * r.repr j, h⁻¹ * h') ∈ C.graph := + QuotientGroup.eq.mp he + have hb : (r.repr i)⁻¹ * r.repr j ∈ C.domain := ⟨_, hm, rfl⟩ + have hij : i = j := by + rw [← r.repr_spec i, ← r.repr_spec j] + exact QuotientGroup.eq.mpr hb + subst j + have hh : h⁻¹ * h' = 1 := by + have hh := C.fst_injective (a₁ := ⟨_, hm⟩) (a₂ := 1) (by simp) + exact congrArg (fun x : C.graph => x.val.2) hh + exact Prod.ext rfl (inv_mul_eq_one.mp hh) + +theorem secondCoordinateMap_surjective : Function.Surjective (secondCoordinateMap C r) := by + intro x + induction x using QuotientGroup.induction_on with + | H x => + let q : G ⧸ C.domain := QuotientGroup.mk x.1 + have hb : (r.repr q)⁻¹ * x.1 ∈ C.domain := + QuotientGroup.eq.mp (r.repr_spec q) + obtain ⟨c, hc, he⟩ := hb + refine ⟨(q, x.2 * c.2⁻¹), ?_⟩ + apply QuotientGroup.eq.mpr + change ((r.repr q)⁻¹ * x.1, ((x.2 * c.2⁻¹)⁻¹ * x.2)) ∈ C.graph + have hf : (x.2 * c.2⁻¹)⁻¹ * x.2 = c.2 := by group + rw [hf, ← he] + exact hc + +def secondCoordinates : ((G ⧸ C.domain) × H) ≃ ((G × H) ⧸ C.graph) := + Equiv.ofBijective (secondCoordinateMap C r) + ⟨secondCoordinateMap_injective C r, secondCoordinateMap_surjective C r⟩ + +theorem secondCoordinates_smul (a : H) (x : (G ⧸ C.domain) × H) : + ((1 : G), a) • secondCoordinates C r x = secondCoordinates C r (x.1, a * x.2) := by + change QuotientGroup.mk (((1 : G), a) * (r.repr x.1, x.2)) = + QuotientGroup.mk (r.repr x.1, a * x.2) + simp + +def inverseCocycle (ω : ScalarCocycle H) : ScalarCocycle H where + val h k := (ω.val h k)⁻¹ + mul_assoc h k l := by + simpa only [mul_inv] using congrArg Inv.inv (ω.mul_assoc h k l) + one_left h := by simp [ω.one_left] + one_right h := by simp [ω.one_right] + +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) + +def secondRegularUnitary : + lp (fun _ : (G ⧸ C.domain) × H => V) 2 ≃ₗᵢ[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2 := + transportLp (secondCoordinates C r) (fun x => + B.fibre (1, x.2) (secondCoordinates C r (x.1, 1)) (secondCoordinates C r x) (by + simpa using secondCoordinates_smul C r x.2 (x.1, 1))) + +theorem secondRegularUnitary_single (i : G ⧸ C.domain) (h : H) (v : V) : + secondRegularUnitary C r μ ω B (lp.single 2 (i,h) v) = + B.action (1,h) (lp.single 2 (secondCoordinates C r (i,1)) v) := by + rw [secondRegularUnitary, transportLp_single] + exact (B.action_single (1,h) _ _ _ v).symm + +theorem secondRegularUnitary_intertwines (a : H) + (v : lp (fun _ : (G ⧸ C.domain) × H => V) 2) : + B.action (1,a) (secondRegularUnitary C r μ ω B v) = + secondRegularUnitary C r μ ω B (regularAction (inverseCocycle ω) a v) := by + have he : + (B.action (1,a)).toContinuousLinearEquiv.toContinuousLinearMap.comp + (secondRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap = + (secondRegularUnitary C r μ ω B).toContinuousLinearEquiv.toContinuousLinearMap.comp + (regularAction (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap := by + apply lp.ext_continuousLinearMap (by norm_num) + rintro ⟨i,h⟩ + apply ContinuousLinearMap.ext + intro w + change B.action (1,a) (secondRegularUnitary C r μ ω B (lp.single 2 (i,h) w)) = + secondRegularUnitary C r μ ω B (regularAction (inverseCocycle ω) a (lp.single 2 (i,h) w)) + rw [secondRegularUnitary_single, B.action_mul, regularAction_single, + secondRegularUnitary_single, lp.single_smul, map_smul] + simp [prodRatio, inverseCocycle, μ.one_left] + exact DFunLike.congr_fun he v + +theorem coordinate_actions_commute (g : G) (h : H) + (v : lp (fun _ : (G × H) ⧸ C.graph => V) 2) : + B.action (g,1) (B.action (1,h) v) = B.action (1,h) (B.action (g,1) v) := by + rw [B.action_mul, B.action_mul] + simp [prodRatio, μ.one_left, μ.one_right, ω.one_left, ω.one_right] + +end + +section +open GermBundles +open scoped InnerProductSpace +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +section ScalarMultiplicity +variable {I J G V : Type*} [Fintype J] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (b : OrthonormalBasis J ℂ V) + +def bundleBasisVector (x : (I × J) × G) : lp (fun _ : I × G => V) 2 := + lp.single 2 (x.1.1, x.2) (b x.1.2) + +omit [CompleteSpace V] in +theorem bundleBasisVector_orthonormal : Orthonormal ℂ (bundleBasisVector (I := I) (G := G) b) := by + rw [orthonormal_iff_ite] + rintro ⟨⟨i,j⟩,g⟩ ⟨⟨k,l⟩,h⟩ + change ⟪lp.single (E := fun _ : I × G => V) 2 (i,g) (b j), + lp.single (E := fun _ : I × G => V) 2 (k,h) (b l)⟫_ℂ = _ + rw [lp.inner_single_left] + by_cases hi : i = k + · subst k + by_cases hg : g = h + · subst h + rw [lp.single_apply_self] + simpa only [Prod.mk.injEq, true_and, and_true] using + (orthonormal_iff_ite.mp b.orthonormal j l) + · rw [lp.single_apply_ne (E := fun _ : I × G => V) 2 (i,h) (b l) + (fun hh => hg (congrArg Prod.snd hh))] + simp [hg] + · rw [lp.single_apply_ne (E := fun _ : I × G => V) 2 (k,h) (b l) + (fun hh => hi (congrArg Prod.fst hh))] + simp [hi] + +omit [CompleteSpace V] in +theorem bundleBasisVector_total : + (Submodule.span ℂ (Set.range (bundleBasisVector (I := I) (G := G) b)))ᗮ = ⊥ := by + apply le_antisymm _ bot_le + intro v hv + change v = 0 + apply lp.ext + funext x + change v x = 0 + apply b.repr.injective + ext j + rw [b.repr_apply_apply, map_zero] + have h := Submodule.inner_right_of_mem_orthogonal + (Submodule.subset_span (Set.mem_range_self ((x.1,j),x.2))) hv + simpa only [bundleBasisVector, Prod.eta, lp.inner_single_left, PiLp.zero_apply] using h + +def regularHilbertBasis : HilbertBasis ((I × J) × G) ℂ (lp (fun _ : I × G => V) 2) := + HilbertBasis.mkOfOrthogonalEqBot (bundleBasisVector_orthonormal b) (bundleBasisVector_total b) + +@[simp] theorem regularHilbertBasis_apply (x : (I × J) × G) : + regularHilbertBasis b x = bundleBasisVector b x := by + exact congrFun (HilbertBasis.coe_mkOfOrthogonalEqBot _ _) x + +def scalarization : lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] lp (fun _ : (I × J) × G => ℂ) 2 := + (regularHilbertBasis b).repr + +theorem scalarization_apply (v : lp (fun _ : I × G => V) 2) (i : I) (j : J) (g : G) : + scalarization b v ((i,j),g) = ⟪b j, v (i,g)⟫_ℂ := by + change (regularHilbertBasis b).repr v ((i,j),g) = _ + rw [HilbertBasis.repr_apply_apply, regularHilbertBasis_apply] + exact lp.inner_single_left _ _ _ + +end ScalarMultiplicity + +section ScalarRegular +variable {I G V : Type*} [Group G] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] + +theorem regularAction_apply (μ : ScalarCocycle G) (a : G) + (v : lp (fun _ : I × G => V) 2) (i : I) (g : G) : + regularAction μ a v (i,a*g) = (μ.val a g : ℂ) • v (i,g) := by + exact transportLp_apply (regularPerm a) (fun x => circleUnitary (μ.val a x.2)) v (i,g) + +end ScalarRegular + +variable {I J G V : Type*} [Fintype J] [Group G] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (b : OrthonormalBasis J ℂ V) + +theorem scalarization_intertwines (μ : ScalarCocycle G) (a : G) + (v : lp (fun _ : I × G => V) 2) : + scalarization b (regularAction μ a v) = regularAction μ a (scalarization b v) := by + apply lp.ext + funext x + obtain ⟨y,rfl⟩ := (regularPerm (I := I × J) a).surjective x + rcases y with ⟨⟨i,j⟩,g⟩ + change scalarization b (regularAction μ a v) ((i,j),a*g) = + regularAction μ a (scalarization b v) ((i,j),a*g) + rw [scalarization_apply, regularAction_apply, inner_smul_right, + regularAction_apply, scalarization_apply] + rfl + +end + +section +open scoped InnerProductSpace +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +variable {K G : Type*} [Fintype K] + +def finiteSumBasisVector (x : K × G) : PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2) := + PiLp.single 2 x.1 (lp.single 2 x.2 1) + +theorem finiteSumBasisVector_inner (x : K × G) + (v : PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2)) : + ⟪finiteSumBasisVector x, v⟫_ℂ = v x.1 x.2 := by + rw [PiLp.inner_apply, Finset.sum_eq_single x.1] + · simp [finiteSumBasisVector, lp.inner_single_left] + · intro i hi hix + simp [finiteSumBasisVector, hix] + · simp + +theorem finiteSumBasisVector_orthonormal : + Orthonormal ℂ (finiteSumBasisVector (K := K) (G := G)) := by + rw [orthonormal_iff_ite] + rintro ⟨i,g⟩ ⟨j,h⟩ + rw [finiteSumBasisVector_inner] + by_cases hi : i = j + · subst j + simp [finiteSumBasisVector, lp.single_apply, Pi.single_apply] + · simp [finiteSumBasisVector, hi] + +theorem finiteSumBasisVector_total : + (Submodule.span ℂ (Set.range (finiteSumBasisVector (K := K) (G := G))))ᗮ = ⊥ := by + apply le_antisymm _ bot_le + intro v hv + change v = 0 + ext i g + change v i g = 0 + have h := Submodule.inner_right_of_mem_orthogonal + (Submodule.subset_span (Set.mem_range_self (i,g))) hv + simpa only [finiteSumBasisVector_inner] using h + +def finiteSumHilbertBasis : + HilbertBasis (K × G) ℂ (PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2)) := + HilbertBasis.mkOfOrthogonalEqBot finiteSumBasisVector_orthonormal finiteSumBasisVector_total + +@[simp] theorem finiteSumHilbertBasis_apply (x : K × G) : + finiteSumHilbertBasis x = finiteSumBasisVector x := by + exact congrFun (HilbertBasis.coe_mkOfOrthogonalEqBot _ _) x + +def finiteRegrouping : lp (fun _ : K × G => ℂ) 2 ≃ₗᵢ[ℂ] + PiLp 2 (fun _ : K => lp (fun _ : G => ℂ) 2) := + finiteSumHilbertBasis.repr.symm + +theorem finiteRegrouping_apply (v : lp (fun _ : K × G => ℂ) 2) (i : K) (g : G) : + finiteRegrouping v i g = v (i,g) := by + have h := congrArg (fun f : lp (fun _ : K × G => ℂ) 2 => f (i,g)) + (finiteSumHilbertBasis.repr.apply_symm_apply v) + rw [HilbertBasis.repr_apply_apply, finiteSumHilbertBasis_apply, + finiteSumBasisVector_inner] at h + exact h + +end + +section +open scoped InnerProductSpace +variable {K L : Type*} [Fintype K] +variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] + +def amplify (T : L →L[ℂ] L) : + PiLp 2 (fun _ : K => L) →L[ℂ] PiLp 2 (fun _ : K => L) := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : K => L)).symm.toContinuousLinearMap.comp + ((ContinuousLinearMap.pi (fun i : K => T.comp (ContinuousLinearMap.proj i))).comp + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : K => L)).toContinuousLinearMap) + +omit [Fintype K] [CompleteSpace L] in +@[simp] theorem amplify_apply (T : L →L[ℂ] L) (v : PiLp 2 (fun _ : K => L)) (i : K) : + amplify T v i = T (v i) := rfl + +def amplification : (L →L[ℂ] L) →⋆ₐ[ℂ] + (PiLp 2 (fun _ : K => L) →L[ℂ] PiLp 2 (fun _ : K => L)) where + toFun := amplify + map_one' := by ext v i; rfl + map_mul' T S := by ext v i; rfl + map_add' T S := by ext v i; rfl + map_zero' := by ext v i; rfl + commutes' z := by ext v i; rfl + map_star' T := by + change amplify (K := K) (ContinuousLinearMap.adjoint T) = + ContinuousLinearMap.adjoint (amplify (K := K) T) + apply (ContinuousLinearMap.eq_adjoint_iff _ _).mpr + intro v w + simp only [PiLp.inner_apply, amplify_apply, ContinuousLinearMap.adjoint_inner_left] + +theorem amplification_wot_continuous : + Continuous (fun T : L →WOT[ℂ] L => + ContinuousLinearMapWOT.ofCLM (amplification (K := K) (L := L) (ContinuousLinearMapWOT.toCLM T))) := by + apply ContinuousLinearMapWOT.continuous_iff.mpr + intro v w + change Continuous (fun T : L →WOT[ℂ] L => ∑ i : K, ⟪w i, T (v i)⟫_ℂ) + apply continuous_finsetSum + intro i hi + exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (v i) (w i) + +end + +section +open scoped InnerProductSpace +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +open GermBundles + +section ScalarTwistedRegular +variable {G K : Type*} [Group G] [Fintype K] + +def scalarRegular (μ : ScalarCocycle G) (a : G) : + lp (fun _ : G => ℂ) 2 ≃ₗᵢ[ℂ] lp (fun _ : G => ℂ) 2 := + transportLp (Equiv.mulLeft a) (fun g => circleUnitary (μ.val a g)) + +theorem scalarRegular_apply (μ : ScalarCocycle G) (a : G) + (v : lp (fun _ : G => ℂ) 2) (g : G) : + scalarRegular μ a v (a*g) = (μ.val a g : ℂ) * v g := by + exact transportLp_apply (Equiv.mulLeft a) (fun g => circleUnitary (μ.val a g)) v g + +theorem finiteRegrouping_intertwines (μ : ScalarCocycle G) (a : G) + (v : lp (fun _ : K × G => ℂ) 2) : + finiteRegrouping (regularAction μ a v) = + amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap + (finiteRegrouping v) := by + ext i g + obtain ⟨h,rfl⟩ := (Equiv.mulLeft a).surjective g + change finiteRegrouping (regularAction μ a v) i (a*h) = + scalarRegular μ a (finiteRegrouping v i) (a*h) + rw [finiteRegrouping_apply, regularAction_apply, scalarRegular_apply, + finiteRegrouping_apply] + rfl + +end ScalarTwistedRegular + +variable {L W : Type*} +variable [NormedAddCommGroup L] [InnerProductSpace ℂ L] [CompleteSpace L] +variable [NormedAddCommGroup W] [InnerProductSpace ℂ W] [CompleteSpace W] + +theorem unitaryConjugation_wot_continuous (U : L ≃ₗᵢ[ℂ] W) : + Continuous (fun T : L →WOT[ℂ] L => + ContinuousLinearMapWOT.ofCLM (U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T))) := by + apply ContinuousLinearMapWOT.continuous_iff.mpr + intro v w + have h : (fun T : L →WOT[ℂ] L => + ⟪w, U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T) v⟫_ℂ) = + (fun T : L →WOT[ℂ] L => ⟪U.symm w, T (U.symm v)⟫_ℂ) := by + funext T + rw [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply] + conv_lhs => lhs; rw [← U.apply_symm_apply w] + exact U.inner_map_map _ _ + change Continuous (fun T : L →WOT[ℂ] L => + ⟪w, U.conjStarAlgEquiv (ContinuousLinearMapWOT.toCLM T) v⟫_ℂ) + rw [h] + exact ContinuousLinearMapWOT.continuous_iff.mp continuous_id (U.symm v) (U.symm w) + +end + +open ArithmeticGerms GermBundles +local instance (priority := 2000) (X : Type*) : DecidableEq X := Classical.decEq X + +section FiniteRegularModules +variable {I J G V : Type*} [Fintype I] [Fintype J] [Group G] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (b : OrthonormalBasis J ℂ V) + +def regularToFinite : lp (fun _ : I × G => V) 2 ≃ₗᵢ[ℂ] + PiLp 2 (fun _ : I × J => lp (fun _ : G => ℂ) 2) := + (scalarization b).trans finiteRegrouping + +theorem regularToFinite_intertwines (μ : ScalarCocycle G) (a : G) + (v : lp (fun _ : I × G => V) 2) : + regularToFinite b (regularAction μ a v) = + amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap + (regularToFinite b v) := by + change finiteRegrouping (scalarization b (regularAction μ a v)) = _ + rw [scalarization_intertwines, finiteRegrouping_intertwines] + rfl + +end FiniteRegularModules + +variable {G H V J : Type*} [Group G] [Group H] [Fintype J] +variable [NormedAddCommGroup V] [InnerProductSpace ℂ V] [CompleteSpace V] +variable (C : VirtualGraph G H) +local instance : Fintype (G ⧸ C.domain) := Subgroup.fintypeQuotientOfFiniteIndex +local instance : Fintype (H ⧸ C.codomain) := Subgroup.fintypeQuotientOfFiniteIndex + +variable (μ : ScalarCocycle G) (ω : ScalarCocycle H) +variable (B : ProjectiveBundle (prodRatio μ ω) (fun _ : (G × H) ⧸ C.graph => V)) +variable (b : OrthonormalBasis J ℂ V) + +def firstFiniteRegularUnitary : + PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2) ≃ₗᵢ[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2 := + (regularToFinite b).symm.trans + (firstRegularUnitary C (chooseCosetSection C.codomain) μ ω B) + +theorem firstFiniteRegularUnitary_intertwines (a : G) + (v : PiLp 2 (fun _ : (H ⧸ C.codomain) × J => lp (fun _ : G => ℂ) 2)) : + B.action (a,1) (firstFiniteRegularUnitary C μ ω B b v) = + firstFiniteRegularUnitary C μ ω B b + (amplify (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap v) := by + change B.action (a,1) (firstRegularUnitary C _ μ ω B ((regularToFinite b).symm v)) = + firstRegularUnitary C _ μ ω B ((regularToFinite b).symm _) + rw [firstRegularUnitary_intertwines] + congr 1 + apply (regularToFinite b).injective + rw [LinearIsometryEquiv.apply_symm_apply] + simpa only [LinearIsometryEquiv.apply_symm_apply] using + regularToFinite_intertwines b μ a ((regularToFinite b).symm v) + +def secondFiniteRegularUnitary : + PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2) ≃ₗᵢ[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2 := + (regularToFinite b).symm.trans + (secondRegularUnitary C (chooseCosetSection C.domain) μ ω B) + +theorem secondFiniteRegularUnitary_intertwines (a : H) + (v : PiLp 2 (fun _ : (G ⧸ C.domain) × J => lp (fun _ : H => ℂ) 2)) : + B.action (1,a) (secondFiniteRegularUnitary C μ ω B b v) = + secondFiniteRegularUnitary C μ ω B b + (amplify (scalarRegular (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap v) := by + change B.action (1,a) (secondRegularUnitary C _ μ ω B ((regularToFinite b).symm v)) = + secondRegularUnitary C _ μ ω B ((regularToFinite b).symm _) + rw [secondRegularUnitary_intertwines] + congr 1 + apply (regularToFinite b).injective + rw [LinearIsometryEquiv.apply_symm_apply] + simpa only [LinearIsometryEquiv.apply_symm_apply] using + regularToFinite_intertwines b (inverseCocycle ω) a ((regularToFinite b).symm v) + +def firstExtension : (lp (fun _ : G => ℂ) 2 →L[ℂ] lp (fun _ : G => ℂ) 2) →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →L[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2) := + (firstFiniteRegularUnitary C μ ω B b).conjStarAlgEquiv.toStarAlgHom.comp + (amplification (K := (H ⧸ C.codomain) × J)) + +def secondExtension : (lp (fun _ : H => ℂ) 2 →L[ℂ] lp (fun _ : H => ℂ) 2) →⋆ₐ[ℂ] + (lp (fun _ : (G × H) ⧸ C.graph => V) 2 →L[ℂ] + lp (fun _ : (G × H) ⧸ C.graph => V) 2) := + (secondFiniteRegularUnitary C μ ω B b).conjStarAlgEquiv.toStarAlgHom.comp + (amplification (K := (G ⧸ C.domain) × J)) + +theorem firstExtension_generator (a : G) : + firstExtension C μ ω B b (scalarRegular μ a).toContinuousLinearEquiv.toContinuousLinearMap = + (B.action (a,1)).toContinuousLinearEquiv.toContinuousLinearMap := by + apply ContinuousLinearMap.ext + intro v + change firstFiniteRegularUnitary C μ ω B b + (amplify _ ((firstFiniteRegularUnitary C μ ω B b).symm v)) = B.action (a,1) v + rw [← firstFiniteRegularUnitary_intertwines, LinearIsometryEquiv.apply_symm_apply] + +theorem secondExtension_generator (a : H) : + secondExtension C μ ω B b + (scalarRegular (inverseCocycle ω) a).toContinuousLinearEquiv.toContinuousLinearMap = + (B.action (1,a)).toContinuousLinearEquiv.toContinuousLinearMap := by + apply ContinuousLinearMap.ext + intro v + change secondFiniteRegularUnitary C μ ω B b + (amplify _ ((secondFiniteRegularUnitary C μ ω B b).symm v)) = B.action (1,a) v + rw [← secondFiniteRegularUnitary_intertwines, LinearIsometryEquiv.apply_symm_apply] + +theorem firstExtension_wot_continuous : + Continuous (fun T : lp (fun _ : G => ℂ) 2 →WOT[ℂ] lp (fun _ : G => ℂ) 2 => + ContinuousLinearMapWOT.ofCLM (firstExtension C μ ω B b T.toCLM)) := + (unitaryConjugation_wot_continuous (firstFiniteRegularUnitary C μ ω B b)).comp + (amplification_wot_continuous (K := (H ⧸ C.codomain) × J)) + +theorem secondExtension_wot_continuous : + Continuous (fun T : lp (fun _ : H => ℂ) 2 →WOT[ℂ] lp (fun _ : H => ℂ) 2 => + ContinuousLinearMapWOT.ofCLM (secondExtension C μ ω B b T.toCLM)) := + (unitaryConjugation_wot_continuous (secondFiniteRegularUnitary C μ ω B b)).comp + (amplification_wot_continuous (K := (G ⧸ C.domain) × J)) + +end GraphNormality + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/BalancedPairings.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/BalancedPairings.lean index 5c4d1d17ead09a398407e08a45911b1eae863489..ca248c00dc3ac5cf84b6311cfa4bd36a46da04d4 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/BalancedPairings.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/BalancedPairings.lean @@ -1,2111 +1,2111 @@ -import OAI.RepresentationTheory.KazhdanLusztig.IntegralPairings - -namespace OAI - -/-! -Graded stalk duality, integral perfect balanced all-sections pairings, recognition and top grading. --/ - -section - -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottPairing_dualToSupport (l : List I) (x : W) - (lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (m : BottSamelsonModule cs l) : - bottSamelsonDuality cs l (bottStalkDualToSupport cs l x lam).val m = - lam (bottStalkProjection cs l x m) := by - change bottSamelsonDuality cs l - ((bottSamelsonDuality cs l).symm ((bottStalkProjection cs l x).dualMap lam)) m = _ - rw [LinearEquiv.apply_symm_apply] - rfl - - theorem bottStalkDuality_apply_projection (l : List I) (x : W) - (s : bottWeightSupported cs l x) (m : BottSamelsonModule cs l) : - bottStalkDuality cs l x s (bottStalkProjection cs l x m) = - bottSamelsonDuality cs l s.val m := by - have he : bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)=s := - (LinearEquiv.ofBijective (bottStalkDualToSupport cs l x) - (bottStalkDualToSupport_bijective cs l x)).apply_symm_apply s - calc - _ = bottSamelsonDuality cs l - (bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)).val m := - (bottPairing_dualToSupport cs l x _ m).symm - _ = _ := by rw [he] - - theorem bottStalkDuality_homogeneous (l : List I) (x : W) (n : ℤ) - (s : bottWeightSupported cs l x) (hs : s ∈ bottSupportPiece cs basis l x n) - (j : ℤ) (v : bottStalk cs l x) (hv : v ∈ bottStalkPiece cs basis l x j) : - bottStalkDuality cs l x s v ∈ symmetricGrading basis (n+j-l.length) := by - obtain ⟨m,hm,rfl⟩ := bottStalk_homogeneous_lift cs basis l x j v hv - rw [bottStalkDuality_apply_projection] - exact bottDuality_homogeneous cs basis l hs hm - - theorem bottDualToSupport_homogeneous (l : List I) (x : W) (r : ℤ) - (lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (hlam : ∀ j v, v ∈ bottStalkPiece cs basis l x j → - lam v ∈ symmetricGrading basis (j+r)) : - bottStalkDualToSupport cs l x lam ∈ bottSupportPiece cs basis l x (r+l.length) := by - change (bottSamelsonDuality cs l).symm ((bottStalkProjection cs l x).dualMap lam) ∈ - bottPiece cs basis l (r+l.length) - apply perfect_inverse_of_homogeneous_functional (symmetricGrading basis) (bottPiece cs basis l) - (bottSamelsonDuality cs l) l.length - (fun _ _ _ _ hm hn => bottDuality_homogeneous cs basis l hm hn) r - intro j m hm - exact hlam j _ (bottStalkProjection_homogeneous cs basis l x j m hm) - - theorem bottStalkDuality_homogeneous_iff (l : List I) (x : W) (n : ℤ) - (s : bottWeightSupported cs l x) : - (∀ j v, v ∈ bottStalkPiece cs basis l x j → - bottStalkDuality cs l x s v ∈ symmetricGrading basis (n+j-l.length)) ↔ - s ∈ bottSupportPiece cs basis l x n := by - constructor - · intro h - have hh := bottDualToSupport_homogeneous cs basis l x (n-l.length) - (bottStalkDuality cs l x s) (by - intro j v hv - have he : n+j-(l.length:ℤ) = j+(n-l.length) := by omega - rw [← he] - exact h j v hv) - have he : bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)=s := - (LinearEquiv.ofBijective (bottStalkDualToSupport cs l x) - (bottStalkDualToSupport_bijective cs l x)).apply_symm_apply s - simpa only [he,sub_add_cancel] using hh - · intro h - exact bottStalkDuality_homogeneous cs basis l x n s h - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The actual word adjoint preserves homogeneity. Projection kernels are -annihilators of the actual supported lattices, integrally, with no localization -or freeness assumption on the projection lattice. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - theorem bott_projection_zero_iff_annihilates_support (l : List I) (x : W) - (m : BottSamelsonModule cs l) : - bottStalkProjection cs l x m=0 ↔ ∀ s : bottWeightSupported cs l x, - bottSamelsonDuality cs l s.val m=0 := by - constructor - · intro hm s - exact bott_supported_annihilates cs l x s.property m - ((bottStalkProjection_eq_zero cs l x m).mp hm) - · intro h - apply Subtype.ext - funext e - let lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x) := - (LinearMap.proj e).comp (bottStalk cs l x).subtype - have he := h (bottStalkDualToSupport cs l x lam) - rw [bottPairing_dualToSupport] at he - exact he - - def bottAdjoint (l : List I) (f : End (SymmetricCoefficient (M := M)) - (BottSamelsonModule cs l)) := PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f - - theorem bottAdjoint_preserves_kernel (l : List I) (x : W) - (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) - (hf : ∀ s, s ∈ bottWeightSupported cs l x → f s ∈ bottWeightSupported cs l x) - (m : BottSamelsonModule cs l) (hm : bottStalkProjection cs l x m=0) : - bottStalkProjection cs l x (bottAdjoint cs l f m)=0 := by - apply (bott_projection_zero_iff_annihilates_support cs l x _).mpr - intro s - change bottSamelsonDuality cs l s.val (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f m)=0 - rw [PerfectAdjoint.symmetric_pairing (bottSamelsonDuality cs l) - (bottSamelson_symmetric cs l)] - exact (bott_projection_zero_iff_annihilates_support cs l x m).mp hm ⟨f s.val,hf s.val s.property⟩ - - theorem bottAdjoint_preserves_support (l : List I) (x : W) - (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) - (hf : ∀ m, bottStalkProjection cs l x m=0 → bottStalkProjection cs l x (f m)=0) - (m : BottSamelsonModule cs l) (hm : m ∈ bottWeightSupported cs l x) : - bottAdjoint cs l f m ∈ bottWeightSupported cs l x := by - apply bott_annihilates_supported cs l x - intro n hn - change bottSamelsonDuality cs l (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f m) n=0 - rw [PerfectAdjoint.pairing] - apply bott_supported_annihilates cs l x hm - exact (bottStalkProjection_eq_zero cs l x (f n)).mp - (hf n ((bottStalkProjection_eq_zero cs l x n).mpr hn)) - - theorem bottAdjoint_homogeneous - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) - (hf : ∀ n m, m ∈ bottPiece cs basis l n → f m ∈ bottPiece cs basis l n) - (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : - bottAdjoint cs l f m ∈ bottPiece cs basis l n := - adjoint_homogeneous (symmetricGrading basis) (bottPiece cs basis l) - (bottSamelsonDuality cs l) l.length - (fun _ _ _ _ h1 h2 => bottDuality_homogeneous cs basis l h1 h2) f hf n m hm - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Integral realization of tensor words as ALL sections of their actual -pair-projection sheaf. This assertion alone is not a BMP summand theorem, -flabbiness/standard-filtration theorem, or EW character theorem. -/ -namespace KLInvariance.TitsSpace -open Module MomentGraph BruhatGraph FiniteCharacterLocalization -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - def bottVertexProjection (l : List I) (u b : W) : BottSamelsonModule cs l →ₗ[ - SymmetricCoefficient (M := M)] - (∀ x : Interval cs u b, bottStalk cs l x.val) := - LinearMap.pi (fun x => bottStalkProjection cs l x.val) - - theorem bottVertexProjection_injective (l : List I) (hl : cs.IsReduced l) : - Function.Injective (bottVertexProjection cs l 1 (cs.wordProd l)) := by - intro m n h - apply bottSection_injective cs l hl - exact Subtype.ext h - - theorem bottVertexProjection_stable (l : List I) (u b : W) - (a : SymmetricCoefficient (M := M)) : - (fun x : Interval cs u b => coefficientAction cs x.val a) ∈ - stabilizer (LinearMap.range (bottVertexProjection cs l u b)) := by - rintro z ⟨m,rfl⟩ - refine ⟨bottSamelsonRight cs l a m,?_⟩ - funext x - exact bottStalkProjection_right cs l x.val a m - - theorem bottVertexProjection_scaled (l : List I) (hl : cs.IsReduced l) - (z : ∀ x : Interval cs 1 (cs.wordProd l), bottStalk cs l x.val) : - bottCoordinateDenominator cs l • z ∈ - LinearMap.range (bottVertexProjection cs l 1 (cs.wordProd l)) := by - let c (e : BottIndex l) : SymmetricCoefficient (M := M) := - (z ⟨bottWeight cs l e,one_bruhat cs _,bottWeight_bruhat cs l hl e⟩).val ⟨e,rfl⟩ - obtain ⟨m,hm⟩ := bottEvaluation_contains_scaled_coordinates cs l c - refine ⟨m,?_⟩ - funext x - apply Subtype.ext - funext e - rcases x with ⟨x,hx⟩ - rcases e with ⟨e,he⟩ - change bottWeight cs l e=x at he - subst x - exact hm e - - - theorem bottSection_pair_lift (l : List I) (u b : W) - (s : (bottProjectionSheaf cs l u b).sections Set.univ) - (x y : Interval cs u b) (t : W) (ht : cs.IsReflection t) (he : t*x.val=y.val) : - ∃ m : BottSamelsonModule cs l, - bottStalkProjection cs l x.val m=s.val x ∧ bottStalkProjection cs l y.val m=s.val y := by - have he' : t*y.val=x.val := by - rw [← he,← mul_assoc,ht.mul_self,one_mul] - have hne : cs.length y.val ≠ cs.length x.val := by - rw [← he] - exact ht.length_mul_right_ne x.val - rcases lt_or_gt_of_ne hne with hlt | hlt - · let e : Edge cs u b := ⟨(y,x),hlt,⟨t,ht,he'.symm⟩⟩ - have hs := s.property e (Set.mem_univ _) (Set.mem_univ _) - obtain ⟨m,hm,hn⟩ := (PairProjection.compatible_iff _ _ _ _).mp hs - exact ⟨m,hn,hm⟩ - · let e : Edge cs u b := ⟨(x,y),hlt,⟨t,ht,he.symm⟩⟩ - have hs := s.property e (Set.mem_univ _) (Set.mem_univ _) - exact (PairProjection.compatible_iff _ _ _ _).mp hs - - theorem bottSection_prime_lift (l : List I) (u b : W) - (s : (bottProjectionSheaf cs l u b).sections Set.univ) - (p : SymmetricCoefficient (M := M)) (hp : Prime p) (x : Interval cs u b) : - ∃ m : BottSamelsonModule cs l, ∀ y : Interval cs u b, - (∀ a, p ∣ coefficientAction cs x.val a-coefficientAction cs y.val a) → - bottStalkProjection cs l y.val m=s.val y := by - classical - by_cases hx : ∃ y : Interval cs u b, x ≠ y ∧ - ∀ a, p ∣ coefficientAction cs x.val a-coefficientAction cs y.val a - · obtain ⟨y,hxy,hcon⟩ := hx - obtain ⟨t,ht,he,hclass⟩ := prime_character_class cs p hp - (fun h => hxy (Subtype.ext h)) hcon - obtain ⟨m,hm,hn⟩ := bottSection_pair_lift cs l u b s x y t ht he.symm - refine ⟨m,?_⟩ - intro z hz - rcases (hclass z.val).mp hz with hxz | hzy - · have h : z=x := Subtype.ext hxz.symm - subst z - exact hm - · have h : z=y := Subtype.ext (hzy.trans he.symm) - subst z - exact hn - · obtain ⟨m,hm⟩ := bottStalkProjection_surjective cs l x.val (s.val x) - refine ⟨m,?_⟩ - intro y hy - have h : y=x := by - by_contra h - exact hx ⟨y,Ne.symm h,hy⟩ - subst y - exact hm - - theorem bottSection_local_denominator (l : List I) (u b : W) - (s : (bottProjectionSheaf cs l u b).sections Set.univ) - (p : SymmetricCoefficient (M := M)) (hp : Prime p) : - ∃ a : SymmetricCoefficient (M := M), ¬ p ∣ a ∧ a • s.val ∈ - LinearMap.range (bottVertexProjection cs l u b) := by - classical - let : Finite (Interval cs u b) := interval_finite cs u b - let : Fintype (Interval cs u b) := Fintype.ofFinite _ - apply character_local_denominator (E := fun x : Interval cs u b => bottStalk cs l x.val) - (LinearMap.range (bottVertexProjection cs l u b)) p hp - (fun a x => coefficientAction cs x.val a) (fun a => bottVertexProjection_stable cs l u b a) s.val - intro x - obtain ⟨m,hm⟩ := bottSection_prime_lift cs l u b s p hp x - exact ⟨bottVertexProjection cs l u b m,⟨m,rfl⟩,hm⟩ - - theorem bottSection_surjective (l : List I) (hl : cs.IsReduced l) : - Function.Surjective (bottSection cs l 1 (cs.wordProd l)) := by - intro s - let L := LinearMap.range (bottVertexProjection cs l 1 (cs.wordProd l)) - let : Module.Free (SymmetricCoefficient (M := M)) L := - Module.Free.of_equiv (LinearEquiv.ofInjective _ (bottVertexProjection_injective cs l hl)) - let : UniqueFactorizationMonoid (SymmetricCoefficient (M := M)) := - (SymmetricAlgebra.equivMvPolynomial (Module.Free.chooseBasis ℝ (Extended M))).symm.toRingEquiv.toMulEquiv.uniqueFactorizationMonoid inferInstance - have h : s.val ∈ L := EdgeLattice.mem_of_prime_local_membership L s.val - ⟨bottCoordinateDenominator cs l,bottCoordinateDenominator_ne_zero cs l, - bottVertexProjection_scaled cs l hl s.val⟩ - (fun p hp => bottSection_local_denominator cs l 1 (cs.wordProd l) s p hp) - obtain ⟨m,hm⟩ := h - exact ⟨m,Subtype.ext hm⟩ - - def bottSectionEquiv (l : List I) (hl : cs.IsReduced l) : - BottSamelsonModule cs l ≃ₗ[SymmetricCoefficient (M := M)] - (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ := - LinearEquiv.ofBijective (bottSection cs l 1 (cs.wordProd l)) - ⟨bottSection_injective cs l hl,bottSection_surjective cs l hl⟩ - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace TransportPerfectPairing -open Module -variable {A M N : Type*} [CommRing A] [AddCommGroup M] [Module A M] - [AddCommGroup N] [Module A N] - -theorem balanced (e : M ≃ₗ[A] N) (D : M ≃ₗ[A] Dual A M) (a : End A M) - (h : ∀ x y, D (a x) y = D x (a y)) (s z : N) : - (e.symm.trans (D.trans e.symm.dualMap)) - ((e.toLinearMap.comp (a.comp e.symm.toLinearMap)) s) z = - (e.symm.trans (D.trans e.symm.dualMap)) s - ((e.toLinearMap.comp (a.comp e.symm.toLinearMap)) z) := by - change D (e.symm (e (a (e.symm s)))) (e.symm z) = - D (e.symm s) (e.symm (e (a (e.symm z)))) - simp only [LinearEquiv.symm_apply_apply] - exact h _ _ - -theorem symmetric (e : M ≃ₗ[A] N) (D : M ≃ₗ[A] Dual A M) - (h : ∀ x y, D x y = D y x) (s z : N) : - (e.symm.trans (D.trans e.symm.dualMap)) s z = - (e.symm.trans (D.trans e.symm.dualMap)) z s := - h (e.symm s) (e.symm z) - -end TransportPerfectPairing - -end - - -section - -/-! Integral perfect balanced self-duality on all sections of the genuine -word projection sheaf. This is the word object, NOT the indecomposable BMP -object. Selection of a BMP summand with the required normalization is not -made or assumed here. -/ -namespace KLInvariance.TitsSpace -open Module MomentGraph BruhatGraph -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - def bottSectionDuality (l : List I) (hl : cs.IsReduced l) : - (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ ≃ₗ[ - SymmetricCoefficient (M := M)] - Dual (SymmetricCoefficient (M := M)) - ((bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) := - (bottSectionEquiv cs l hl).symm.trans - ((bottSamelsonDuality cs l).trans (bottSectionEquiv cs l hl).symm.dualMap) - - theorem bottSectionDuality_apply (l : List I) (hl : cs.IsReduced l) - (m n : BottSamelsonModule cs l) : - bottSectionDuality cs l hl (bottSection cs l 1 (cs.wordProd l) m) - (bottSection cs l 1 (cs.wordProd l) n) = bottSamelsonDuality cs l m n := by - change bottSamelsonDuality cs l - ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) m)) - ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) n))= _ - simp only [LinearEquiv.symm_apply_apply] - - def bottSectionRight (l : List I) (hl : cs.IsReduced l) - (a : SymmetricCoefficient (M := M)) : - End (SymmetricCoefficient (M := M)) - ((bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) := - (bottSectionEquiv cs l hl).toLinearMap.comp - ((bottSamelsonRight cs l a).comp (bottSectionEquiv cs l hl).symm.toLinearMap) - - theorem bottSectionRight_apply (l : List I) (hl : cs.IsReduced l) - (a : SymmetricCoefficient (M := M)) (m : BottSamelsonModule cs l) : - bottSectionRight cs l hl a (bottSection cs l 1 (cs.wordProd l) m) = - bottSection cs l 1 (cs.wordProd l) (bottSamelsonRight cs l a m) := by - change (bottSectionEquiv cs l hl) (bottSamelsonRight cs l a - ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) m))) = _ - rw [LinearEquiv.symm_apply_apply] - rfl - - theorem bottSectionRight_coordinates (l : List I) (hl : cs.IsReduced l) - (a : SymmetricCoefficient (M := M)) - (s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) - (x : Interval cs 1 (cs.wordProd l)) : - (bottSectionRight cs l hl a s).val x=coefficientAction cs x.val a • s.val x := by - obtain ⟨m,rfl⟩ := bottSection_surjective cs l hl s - rw [bottSectionRight_apply] - exact bottStalkProjection_right cs l x.val a m - - theorem bottSection_balanced (l : List I) (hl : cs.IsReduced l) - (a : SymmetricCoefficient (M := M)) - (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) : - bottSectionDuality cs l hl (bottSectionRight cs l hl a s) z = - bottSectionDuality cs l hl s (bottSectionRight cs l hl a z) := by - exact TransportPerfectPairing.balanced (bottSectionEquiv cs l hl) - (bottSamelsonDuality cs l) (bottSamelsonRight cs l a) - (bottSamelson_balanced cs l a) s z - - theorem bottSection_symmetric (l : List I) (hl : cs.IsReduced l) - (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) : - bottSectionDuality cs l hl s z=bottSectionDuality cs l hl z s := by - exact TransportPerfectPairing.symmetric (bottSectionEquiv cs l hl) - (bottSamelsonDuality cs l) (bottSamelson_symmetric cs l) s z - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The word SECTION pairing has precisely the word-length shift in the -actual coordinatewise sheaf grading. It is not an asserted pairing on the -indecomposable BMP boundary sheaf. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottPiece_iff_stalks (l : List I) (hl : cs.IsReduced l) (n : ℤ) - (m : BottSamelsonModule cs l) : m ∈ bottPiece cs basis l n ↔ - ∀ x : Interval cs 1 (cs.wordProd l), - bottStalkProjection cs l x.val m ∈ bottStalkPiece cs basis l x.val n := by - constructor - · intro hm x - exact bottStalkProjection_homogeneous cs basis l x.val n m hm - · intro hm - have he : component (bottPiece cs basis l) n m=m := by - apply bottVertexProjection_injective cs l hl - funext x - have hh := map_component (bottPiece cs basis l) (bottStalkPiece cs basis l x.val) - (bottStalkProjection cs l x.val) 0 (by - simpa only [add_zero] using bottStalkProjection_homogeneous cs basis l x.val) n m - rw [sub_zero,show component (bottStalkPiece cs basis l x.val) n - (bottStalkProjection cs l x.val m)=bottStalkProjection cs l x.val m from - DirectSum.decompose_of_mem_same _ (hm x)] at hh - exact hh.symm - rw [← he] - exact (DirectSum.decompose (bottPiece cs basis l) m n).property - - theorem bottSectionDuality_homogeneous (l : List I) (hl : cs.IsReduced l) - (i j : ℤ) - (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) - (hs : ∀ x, s.val x ∈ bottStalkPiece cs basis l x.val i) - (hz : ∀ x, z.val x ∈ bottStalkPiece cs basis l x.val j) : - bottSectionDuality cs l hl s z ∈ symmetricGrading basis (i+j-l.length) := by - obtain ⟨m,rfl⟩ := bottSection_surjective cs l hl s - obtain ⟨n,rfl⟩ := bottSection_surjective cs l hl z - rw [bottSectionDuality_apply] - exact bottDuality_homogeneous cs basis l ((bottPiece_iff_stalks cs basis l hl i m).mpr hs) - ((bottPiece_iff_stalks cs basis l hl j n).mpr hz) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Section maps for the actual graded sheaf morphisms. A sheaf splitting -really gives an integral graded section splitting; it is not replaced by a -generic-fibre splitting. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] - {G : OrderedGraph V E} {B C : GradedSheaf (𝓐 := 𝓐) G} -noncomputable section - - def Hom.assignmentMap (h : Hom B C) : B.forget.Assignment →ₗ[A] C.forget.Assignment where - toFun f x := (h.vertex x).map (f x) - map_add' f g := by funext x; exact map_add (h.vertex x).map (f x) (g x) - map_smul' r f := by funext x; exact map_smul (h.vertex x).map r (f x) - - theorem Hom.assignmentMap_compatible (h : Hom B C) (Ω : Set V) - (f : B.forget.Assignment) (hf : B.forget.CompatibleOn Ω f) : - C.forget.CompatibleOn Ω (h.assignmentMap f) := by - intro e hs ht - change (C.lower e).map ((h.vertex _).map (f _)) = - (C.upper e).map ((h.vertex _).map (f _)) - exact (h.lower e (f (G.source e))).symm.trans - ((congrArg (h.edge e).map (hf e hs ht)).trans (h.upper e (f (G.target e)))) - - def Hom.sectionMap (h : Hom B C) (Ω : Set V) : - B.forget.sections Ω →ₗ[A] C.forget.sections Ω := - (h.assignmentMap.domRestrict (B.forget.sections Ω)).codRestrict (C.forget.sections Ω) - (fun f => h.assignmentMap_compatible Ω f.val f.property) - - theorem Hom.sectionMap_apply (h : Hom B C) (Ω : Set V) - (f : B.forget.sections Ω) (x : V) : - (h.sectionMap Ω f).val x=(h.vertex x).map (f.val x) := rfl - - variable [Fintype V] [Fintype E] [IsNoetherianRing A] - - def Hom.gradedSectionMap (h : Hom B C) (Ω : Set V) : - ModuleData.Hom (B.sections Ω) (C.sections Ω) where - map := h.sectionMap Ω - graded := by - intro n f hf x hx - exact (h.vertex x).graded n (f.val x) (hf x hx) - -omit [Fintype V] [Fintype E] [IsNoetherianRing A] in - theorem SplitIn.sections_split (s : SplitIn B C) (Ω : Set V) - (f : B.forget.sections Ω) : - s.projection.sectionMap Ω (s.inclusion.sectionMap Ω f)=f := by - apply Subtype.ext - funext x - exact s.vertex_split x (f.val x) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! Endomorphisms of the ACTUAL graded word sheaf act on its integral tensor -module and preserve every stalk kernel and single-weight support lattice. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) -noncomputable section - - def bottEndOfSheaf (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l) := - (bottSectionEquiv cs l hl).symm.toLinearMap.comp - ((h.sectionMap Set.univ).comp (bottSectionEquiv cs l hl).toLinearMap) - - theorem bottEndOfSheaf_coordinates (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (m : BottSamelsonModule cs l) (x : Interval cs 1 (cs.wordProd l)) : - bottStalkProjection cs l x.val (bottEndOfSheaf cs basis l hl h m)= - (h.vertex x).map (bottStalkProjection cs l x.val m) := by - have he := congrArg (fun s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ => - s.val x) ((bottSectionEquiv cs l hl).apply_symm_apply - (h.sectionMap Set.univ ((bottSectionEquiv cs l hl) m))) - exact he - - theorem bottEndOfSheaf_homogeneous (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : - bottEndOfSheaf cs basis l hl h m ∈ bottPiece cs basis l n := by - apply (bottPiece_iff_stalks cs basis l hl n _).mpr - intro x - rw [bottEndOfSheaf_coordinates] - exact (h.vertex x).graded n _ (bottStalkProjection_homogeneous cs basis l x.val n m hm) - - theorem bottEndOfSheaf_preserves_kernel (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) - (hm : bottStalkProjection cs l x.val m=0) : - bottStalkProjection cs l x.val (bottEndOfSheaf cs basis l hl h m)=0 := by - rw [bottEndOfSheaf_coordinates,hm] - exact (h.vertex x).map.map_zero - - theorem bottEndOfSheaf_preserves_support (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) - (hm : m ∈ bottWeightSupported cs l x.val) : - bottEndOfSheaf cs basis l hl h m ∈ bottWeightSupported cs l x.val := by - intro e he - let y : Interval cs 1 (cs.wordProd l) := - ⟨bottWeight cs l e,one_bruhat cs _,bottWeight_bruhat cs l hl e⟩ - have hmy : bottStalkProjection cs l y.val m=0 := by - apply Subtype.ext - funext f - exact hm f.val (fun hx => he (f.property.symm.trans hx)) - have hfy := bottEndOfSheaf_preserves_kernel cs basis l hl h y m hmy - exact congrFun (congrArg Subtype.val hfy) ⟨e,rfl⟩ - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace LinearDescent -universe ur um ux -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - {X : Type ux} [AddCommGroup X] [Module R X] - (f : M →ₗ[R] X) (hf : Function.Surjective f) (e : Module.End R M) - (he : ∀ m, f m=0 → f (e m)=0) -noncomputable section - - def descend : Module.End R X := - ((LinearMap.ker f).liftQ (f.comp e) he).comp - (f.quotKerEquivOfSurjective hf).symm.toLinearMap - - theorem descend_apply (m : M) : descend f hf e he (f m)=f (e m) := by - change (LinearMap.ker f).liftQ (f.comp e) he - ((f.quotKerEquivOfSurjective hf).symm (f m))=f (e m) - rw [LinearMap.quotKerEquivOfSurjective_symm_apply] - rfl - - theorem descend_idempotent (hee : ∀ m, e (e m)=e m) (x : X) : - descend f hf e he (descend f hf e he x)=descend f hf e he x := by - obtain ⟨m,rfl⟩ := hf x - rw [descend_apply,descend_apply,hee] - -end -end LinearDescent - -end - - -section - -namespace KLInvariance.Graded.ModuleData -open PairProjection LinearDescent -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {M X Y : ModuleData.{uk,ua,um} 𝓐} - (e : Hom M M) (f : Hom M X) (g : Hom M Y) - (hf : Function.Surjective f.map) (hg : Function.Surjective g.map) - (hef : ∀ m, f.map m=0 → f.map (e.map m)=0) - (heg : ∀ m, g.map m=0 → g.map (e.map m)=0) -noncomputable section - - def descended : Hom X X where - map := descend f.map hf e.map hef - graded := by - intro n x hx - obtain ⟨m,hm,rfl⟩ := f.homogeneous_lift hf n x hx - rw [descend_apply] - exact f.graded n _ (e.graded n m hm) - -include heg in - theorem lower_kernel_preserved (x : X) (hx : lower f.map g.map x=0) : - lower f.map g.map ((descended e f hf hef).map x)=0 := by - obtain ⟨m,hm,hn⟩ := (kernel_lower f.map g.map x).mp hx - apply (kernel_lower f.map g.map _).mpr - refine ⟨e.map m,?_,heg m hn⟩ - rw [← hm] - exact (descend_apply f.map hf e.map hef m).symm - - def descendedEdge : Hom (pairEdge f g hg) (pairEdge f g hg) where - map := descend (lower f.map g.map) (lower_surjective f.map g.map hg) - (descended e f hf hef).map (lower_kernel_preserved e f g hf hef heg) - graded := by - intro n z hz - obtain ⟨x,hx,rfl⟩ := hz - refine ⟨(descended e f hf hef).map x,(descended e f hf hef).graded n x hx,?_⟩ - exact (descend_apply (lower f.map g.map) (lower_surjective f.map g.map hg) - (descended e f hf hef).map (lower_kernel_preserved e f g hf hef heg) x).symm - - theorem descendedEdge_lower (x : X) : - (descendedEdge e f g hf hg hef heg).map (lower f.map g.map x)= - lower f.map g.map ((descended e f hf hef).map x) := - descend_apply _ _ _ _ x - - theorem descendedEdge_upper (y : Y) : - (descendedEdge e f g hf hg hef heg).map (upper f.map g.map y)= - upper f.map g.map ((descended e g hg heg).map y) := by - obtain ⟨m,rfl⟩ := hg y - rw [← compatible f.map g.map m,descendedEdge_lower] - change lower f.map g.map (descend f.map hf e.map hef (f.map m)) = - upper f.map g.map (descend g.map hg e.map heg (g.map m)) - rw [descend_apply,descend_apply] - exact compatible f.map g.map (e.map m) - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -/-! The adjoint of an actual graded word-sheaf endomorphism is again an -integral graded word-sheaf endomorphism. No stalk freeness or BMP character -is used or asserted. This supplies the correct adjoint route for a future -BMP summand, instead of restricting a form to an arbitrary summand. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) -noncomputable section - - def bottAdjointWordHom (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - ModuleData.Hom (bottWordData cs basis l) (bottWordData cs basis l) where - map := bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) - graded := bottAdjoint_homogeneous cs basis l _ - (bottEndOfSheaf_homogeneous cs basis l hl h) - - theorem bottAdjointWordHom_kernel (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) - (hm : bottStalkProjection cs l x.val m=0) : - bottStalkProjection cs l x.val ((bottAdjointWordHom cs basis l hl h).map m)=0 := - bottAdjoint_preserves_kernel cs l x.val _ - (bottEndOfSheaf_preserves_support cs basis l hl h x) m hm - - def bottAdjointSheaf (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) where - vertex x := ModuleData.descended (bottAdjointWordHom cs basis l hl h) - (bottStalkHom cs basis l x.val) (bottStalkHom_surjective cs basis l x.val) - (bottAdjointWordHom_kernel cs basis l hl h x) - edge e := ModuleData.descendedEdge (bottAdjointWordHom cs basis l hl h) - (bottStalkHom cs basis l (source cs 1 (cs.wordProd l) e).val) - (bottStalkHom cs basis l (target cs 1 (cs.wordProd l) e).val) - (bottStalkHom_surjective cs basis l _) - (bottStalkHom_surjective cs basis l _) - (bottAdjointWordHom_kernel cs basis l hl h _) - (bottAdjointWordHom_kernel cs basis l hl h _) - lower _ x := ModuleData.descendedEdge_lower _ _ _ _ _ _ _ x - upper _ y := ModuleData.descendedEdge_upper _ _ _ _ _ _ _ y - - theorem bottAdjointSheaf_vertex (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) : - ((bottAdjointSheaf cs basis l hl h).vertex x).map (bottStalkProjection cs l x.val m)= - bottStalkProjection cs l x.val (bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) m) := - LinearDescent.descend_apply _ _ _ _ m - - theorem bottEndOfAdjointSheaf (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - bottEndOfSheaf cs basis l hl (bottAdjointSheaf cs basis l hl h)= - bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) := by - apply LinearMap.ext - intro m - apply bottVertexProjection_injective cs l hl - funext x - exact (bottEndOfSheaf_coordinates cs basis l hl _ m x).trans - (bottAdjointSheaf_vertex cs basis l hl h x m) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Integral graded adjoint WORD projectors. The assumption below is only -that the GIVEN endomorphism is a projector; no existence of a BMP projector -or identification of its image with its adjoint is asserted. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - theorem bottEndOfSheaf_idempotent - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (m : BottSamelsonModule cs l) : - bottEndOfSheaf cs basis l hl h (bottEndOfSheaf cs basis l hl h m)= - bottEndOfSheaf cs basis l hl h m := by - apply bottVertexProjection_injective cs l hl - funext x - change bottStalkProjection cs l x.val _=bottStalkProjection cs l x.val _ - simp only [bottEndOfSheaf_coordinates] - exact hh x _ - - theorem bottAdjointSheaf_vertex_idempotent - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (x : Interval cs 1 (cs.wordProd l)) - (v : bottStalk cs l x.val) : - ((bottAdjointSheaf cs basis l hl h).vertex x).map - (((bottAdjointSheaf cs basis l hl h).vertex x).map v)= - ((bottAdjointSheaf cs basis l hl h).vertex x).map v := by - obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v - simp only [bottAdjointSheaf_vertex] - exact congrArg (bottStalkProjection cs l x.val) - (PerfectAdjoint.adjoint_idempotent (bottSamelsonDuality cs l) _ - (bottEndOfSheaf_idempotent cs basis l hl h hh) m) - - theorem bottAdjointSheaf_edge_idempotent - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (e : Edge cs 1 (cs.wordProd l)) - (v : (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).edge e) : - ((bottAdjointSheaf cs basis l hl h).edge e).map - (((bottAdjointSheaf cs basis l hl h).edge e).map v)= - ((bottAdjointSheaf cs basis l hl h).edge e).map v := by - have hs : Function.Surjective - ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).lower e).map := - bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e - obtain ⟨m,rfl⟩ := hs v - simp only [(bottAdjointSheaf cs basis l hl h).lower] - exact congrArg ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).lower e).map - (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh _ m) - - theorem bottAdjointSheaf_twice_vertex (x : Interval cs 1 (cs.wordProd l)) - (v : bottStalk cs l x.val) : - ((bottAdjointSheaf cs basis l hl (bottAdjointSheaf cs basis l hl h)).vertex x).map v= - (h.vertex x).map v := by - obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v - rw [bottAdjointSheaf_vertex,bottEndOfAdjointSheaf] - change bottStalkProjection cs l x.val - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl h)) m)=_ - rw [PerfectAdjoint.adjoint_adjoint _ (bottSamelson_symmetric cs l)] - exact bottEndOfSheaf_coordinates cs basis l hl h m x - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The literal integral image sheaf of a graded projector, with its actual -splitting. Used for word-adjoint projectors; no BMP summand is assumed. -/ -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] - {M N : ModuleData.{uk,ua,um} 𝓐} -noncomputable section - - def rangeMap (e : Hom M M) (f : Hom N N) (g : Hom M N) - (h : ∀ m, f.map (g.map m)=g.map (e.map m)) : Hom (range e) (range f) where - map := (g.map.domRestrict e.map.range).codRestrict f.map.range (by - rintro ⟨_,m,rfl⟩ - exact ⟨g.map m,h m⟩) - graded n m hm := g.graded n m.val hm - - def rangeInclusion (e : Hom M M) : Hom (range e) M where - map := e.map.range.subtype - graded _ _ hm := hm - - def rangeProjection (e : Hom M M) : Hom M (range e) where - map := e.map.rangeRestrict - graded n m hm := e.graded n m hm - -end -end KLInvariance.Graded.ModuleData - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B : GradedSheaf (𝓐 := 𝓐) G} -noncomputable section - - def Hom.image (h : Hom B B) : GradedSheaf (𝓐 := 𝓐) G where - vertex x := ModuleData.range (h.vertex x) - edge e := ModuleData.range (h.edge e) - lower e := ModuleData.rangeMap (h.vertex (G.source e)) (h.edge e) (B.lower e) (h.lower e) - upper e := ModuleData.rangeMap (h.vertex (G.target e)) (h.edge e) (B.upper e) (h.upper e) - - def Hom.imageInclusion (h : Hom B B) : Hom h.image B where - vertex x := ModuleData.rangeInclusion (h.vertex x) - edge e := ModuleData.rangeInclusion (h.edge e) - lower _ _ := rfl - upper _ _ := rfl - - def Hom.imageProjection (h : Hom B B) : Hom B h.image where - vertex x := ModuleData.rangeProjection (h.vertex x) - edge e := ModuleData.rangeProjection (h.edge e) - lower e v := Subtype.ext (h.lower e v) - upper e v := Subtype.ext (h.upper e v) - - def Hom.imageSplit (h : Hom B B) - (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (he : ∀ e v, (h.edge e).map ((h.edge e).map v)=(h.edge e).map v) : SplitIn h.image B where - inclusion := h.imageInclusion - projection := h.imageProjection - vertex_split x v := by - obtain ⟨m,hm⟩ := v.property - apply Subtype.ext - change (h.vertex x).map v.val=v.val - rw [← hm,hv] - edge_split e v := by - obtain ⟨m,hm⟩ := v.property - apply Subtype.ext - change (h.edge e).map v.val=v.val - rw [← hm,he] - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! All integral sections of an idempotent image sheaf are the image of the -actual section projector; this is stronger than equality over the fraction -field and requires the actual idempotence, not merely pointwise surjectivity. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B : GradedSheaf (𝓐 := 𝓐) G} -noncomputable section - - theorem Hom.imageSection_fixed (h : Hom B B) - (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (Ω : Set V) (f : h.image.forget.sections Ω) : - h.sectionMap Ω (h.imageInclusion.sectionMap Ω f)=h.imageInclusion.sectionMap Ω f := by - apply Subtype.ext - funext x - obtain ⟨v,hv'⟩ := (f.val x).property - change (h.vertex x).map (f.val x).val=(f.val x).val - rw [← hv',hv] - - def Hom.imageSectionMap (h : Hom B B) - (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (Ω : Set V) : h.image.forget.sections Ω →ₗ[A] LinearMap.range (h.sectionMap Ω) := - (h.imageInclusion.sectionMap Ω).codRestrict _ (fun f => - ⟨h.imageInclusion.sectionMap Ω f,h.imageSection_fixed hv Ω f⟩) - - theorem Hom.imageSectionMap_bijective (h : Hom B B) - (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (Ω : Set V) : Function.Bijective (h.imageSectionMap hv Ω) := by - constructor - · intro f g hfg - apply Subtype.ext - funext x - apply Subtype.ext - exact congrFun (congrArg Subtype.val (congrArg Subtype.val hfg)) x - · rintro ⟨s,m,rfl⟩ - refine ⟨h.imageProjection.sectionMap Ω m,?_⟩ - apply Subtype.ext - apply Subtype.ext - rfl - - def Hom.imageSectionEquiv (h : Hom B B) - (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (Ω : Set V) : h.image.forget.sections Ω ≃ₗ[A] LinearMap.range (h.sectionMap Ω) := - LinearEquiv.ofBijective (h.imageSectionMap hv Ω) (h.imageSectionMap_bijective hv Ω) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace ConjugateRange -open Module -universe ur um un -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - {N : Type un} [AddCommGroup N] [Module R N] - (e : M ≃ₗ[R] N) (f : End R N) -noncomputable section - - def conjugate : End R M := e.symm.toLinearMap.comp (f.comp e.toLinearMap) - - def map : LinearMap.range f →ₗ[R] LinearMap.range (conjugate e f) := - (e.symm.toLinearMap.domRestrict f.range).codRestrict _ (by - rintro ⟨_,n,rfl⟩ - refine ⟨e.symm n,?_⟩ - change e.symm (f (e (e.symm n)))=e.symm (f n) - rw [LinearEquiv.apply_symm_apply]) - - theorem map_bijective : Function.Bijective (map e f) := by - constructor - · intro m n h - apply Subtype.ext - apply e.symm.injective - exact congrArg Subtype.val h - · rintro ⟨_,m,rfl⟩ - refine ⟨⟨f (e m),e m,rfl⟩,?_⟩ - rfl - - def equiv : LinearMap.range f ≃ₗ[R] LinearMap.range (conjugate e f) := - LinearEquiv.ofBijective (map e f) (map_bijective e f) - - theorem equiv_apply (n : LinearMap.range f) : (equiv e f n).val=e.symm n.val := rfl - -end -end ConjugateRange - -end - - -section - -/-! The correct integral summand duality. A chosen summand of a perfectly -paired module is paired with its ADJOINT summand, not with itself by fiat. -This is the algebraic connector for the unresolved BMP summand recognition. -No existence of a BMP summand, or isomorphism with its adjoint, is asserted. -/ -namespace AdjointSummandDuality -universe ur um un -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - {N : Type un} [AddCommGroup N] [Module R N] - (d : M ≃ₗ[R] Module.Dual R M) (i : N →ₗ[R] M) (p : M →ₗ[R] N) - (hpi : ∀ n, p (i n)=n) -noncomputable section - - def dualSection : Module.Dual R N →ₗ[R] M := - d.symm.toLinearMap.comp p.dualMap - - def dualProjection : M →ₗ[R] Module.Dual R N := i.dualMap.comp d.toLinearMap - -include hpi in - theorem projection_section (lam : Module.Dual R N) : - dualProjection d i (dualSection d p lam)=lam := by - apply LinearMap.ext - intro n - change d (d.symm (p.dualMap lam)) (i n)=lam n - rw [LinearEquiv.apply_symm_apply] - change lam (p (i n))=lam n - rw [hpi] - - def adjointProjector : Module.End R M := (dualSection d p).comp (dualProjection d i) - -include hpi in - theorem adjointProjector_idempotent (m : M) : - adjointProjector d i p (adjointProjector d i p m)=adjointProjector d i p m := by - change dualSection d p (dualProjection d i (dualSection d p (dualProjection d i m))) = _ - rw [projection_section d i p hpi] - rfl - - def adjointSummand : Submodule R M := LinearMap.range (dualSection d p) - -include hpi in - theorem dualProjection_injective_on_adjoint : - Function.Injective ((dualProjection d i).domRestrict (adjointSummand d p)) := by - rintro ⟨m,lam,rfl⟩ ⟨n,mu,rfl⟩ h - apply Subtype.ext - change dualSection d p lam=dualSection d p mu - change dualProjection d i (dualSection d p lam)=dualProjection d i (dualSection d p mu) at h - rw [projection_section d i p hpi,projection_section d i p hpi] at h - rw [h] - -include hpi in - theorem dualProjection_surjective_on_adjoint : - Function.Surjective ((dualProjection d i).domRestrict (adjointSummand d p)) := by - intro lam - exact ⟨⟨dualSection d p lam,lam,rfl⟩,projection_section d i p hpi lam⟩ - - def adjointEquivDual : adjointSummand d p ≃ₗ[R] Module.Dual R N := - LinearEquiv.ofBijective ((dualProjection d i).domRestrict (adjointSummand d p)) - ⟨dualProjection_injective_on_adjoint d i p hpi,dualProjection_surjective_on_adjoint d i p hpi⟩ - - theorem adjointEquivDual_apply (m : adjointSummand d p) (n : N) : - adjointEquivDual d i p hpi m n=d m.val (i n) := rfl - -include hpi in - theorem adjointProjector_range : - LinearMap.range (adjointProjector d i p)=adjointSummand d p := by - apply le_antisymm - · rintro m ⟨n,rfl⟩ - exact ⟨dualProjection d i n,rfl⟩ - · rintro m ⟨lam,rfl⟩ - refine ⟨dualSection d p lam,?_⟩ - change dualSection d p (dualProjection d i (dualSection d p lam))=dualSection d p lam - rw [projection_section d i p hpi] - -variable (f : Module.End R M) (g : Module.End R N) - (hbal : ∀ m n, d (f m) n=d m (f n)) - (hi : ∀ n, f (i n)=i (g n)) (hp : ∀ m, p (f m)=g (p m)) - -include hbal hi in - theorem projection_intertwines (m : M) : - dualProjection d i (f m)=g.dualMap (dualProjection d i m) := by - apply LinearMap.ext - intro n - change d (f m) (i n)=d m (i (g n)) - rw [hbal,hi] - -include hbal hp in - theorem section_intertwines (lam : Module.Dual R N) : - f (dualSection d p lam)=dualSection d p (g.dualMap lam) := by - apply d.injective - apply LinearMap.ext - intro n - change d (f (d.symm (p.dualMap lam))) n= - d (d.symm (p.dualMap (g.dualMap lam))) n - rw [hbal,LinearEquiv.apply_symm_apply,LinearEquiv.apply_symm_apply] - change lam (p (f n))=lam (g (p n)) - rw [hp] - -include hbal hi hp in - theorem adjointProjector_commutes (m : M) : - f (adjointProjector d i p m)=adjointProjector d i p (f m) := by - change f (dualSection d p (dualProjection d i m)) = - dualSection d p (dualProjection d i (f m)) - rw [section_intertwines d p f g hbal hp,projection_intertwines d i f g hbal hi] - -end -end AdjointSummandDuality - -end - - -section - -/-! The range of the genuine adjoint projector is integrally the dual of -the original summand, with no assumed self-duality of that summand. -/ -namespace PerfectAdjoint -open Module -universe ur um un -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - {N : Type un} [AddCommGroup N] [Module R N] - (d : M ≃ₗ[R] Dual R M) (i : N →ₗ[R] M) (p : M →ₗ[R] N) - (hpi : ∀ n, p (i n)=n) -noncomputable section - - theorem adjoint_projector_eq : adjoint d (i.comp p)= - AdjointSummandDuality.adjointProjector d i p := by - apply LinearMap.ext - intro m - rfl - - def rangeAdjointEquivDual : LinearMap.range (adjoint d (i.comp p)) ≃ₗ[R] Dual R N := - (LinearEquiv.ofEq _ _ (by - rw [adjoint_projector_eq,AdjointSummandDuality.adjointProjector_range d i p hpi])).trans - (AdjointSummandDuality.adjointEquivDual d i p hpi) - - theorem rangeAdjointEquivDual_apply (m : LinearMap.range (adjoint d (i.comp p))) (n : N) : - rangeAdjointEquivDual d i p hpi m n=d m.val (i n) := rfl - -end -end PerfectAdjoint - -end - - -section - -namespace PerfectAdjoint -open Module -universe ur um -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - (d : M ≃ₗ[R] Dual R M) (f : End R M) (hf : ∀ m, f (f m)=f m) -noncomputable section - -include hf in - theorem range_projector_split (m : f.range) : f.rangeRestrict (f.range.subtype m)=m := by - apply Subtype.ext - obtain ⟨n,hn⟩ := m.property - change f m.val=m.val - rw [← hn,hf] - - def rangeAdjointEquivDualRange : LinearMap.range (adjoint d f) ≃ₗ[R] Dual R f.range := - rangeAdjointEquivDual d f.range.subtype f.rangeRestrict (range_projector_split f hf) - - theorem rangeAdjointEquivDualRange_apply (m : LinearMap.range (adjoint d f)) (n : f.range) : - rangeAdjointEquivDualRange d f hf m n=d m.val n.val := rfl - -end -end PerfectAdjoint - -end - - -section - -namespace KLInvariance.TitsSpace -open Module -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - -include basis in - theorem symmetricCoefficientNoetherian : IsNoetherianRing (SymmetricCoefficient (M := M)) := - isNoetherianRing_of_surjective (MvPolynomial σ ℝ) (SymmetricCoefficient (M := M)) - (SymmetricAlgebra.equivMvPolynomial basis).symm.toRingHom - (SymmetricAlgebra.equivMvPolynomial basis).symm.surjective - -end KLInvariance.TitsSpace - -end - - -section - -/-! The actual adjoint IMAGE sheaf has all integral sections dual to those -of the original projector image. This does not identify those two image -sheaves or assert that the word sheaf satisfies the BMP axioms. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - def bottImageSheaf : GradedSheaf (𝓐 := symmetricGrading basis) - (graph cs 1 (cs.wordProd l)) := by - letI := symmetricCoefficientNoetherian basis - exact h.image - - def bottImageSectionWordEquiv - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) : - (bottImageSheaf cs basis l h).forget.sections Set.univ ≃ₗ[ - SymmetricCoefficient (M := M)] LinearMap.range (bottEndOfSheaf cs basis l hl h) := by - letI := symmetricCoefficientNoetherian basis - exact (h.imageSectionEquiv hh Set.univ).trans - (ConjugateRange.equiv (bottSectionEquiv cs l hl) (h.sectionMap Set.univ)) - - def bottAdjointImageEquivDual - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) : - (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ ≃ₗ[ - SymmetricCoefficient (M := M)] - Dual (SymmetricCoefficient (M := M)) - ((bottImageSheaf cs basis l h).forget.sections Set.univ) := - (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl h) - (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh)).trans - ((LinearEquiv.ofEq _ _ (congrArg LinearMap.range - (bottEndOfAdjointSheaf cs basis l hl h))).trans - ((PerfectAdjoint.rangeAdjointEquivDualRange (bottSamelsonDuality cs l) - (bottEndOfSheaf cs basis l hl h) - (bottEndOfSheaf_idempotent cs basis l hl h hh)).trans - (bottImageSectionWordEquiv cs basis l hl h hh).dualMap)) - - theorem bottImageSectionWordEquiv_coordinates - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (m : (bottImageSheaf cs basis l h).forget.sections Set.univ) - (x : Interval cs 1 (cs.wordProd l)) : - bottStalkProjection cs l x.val ((bottImageSectionWordEquiv cs basis l hl h hh m).val)= - (m.val x).val := by - let := symmetricCoefficientNoetherian basis - exact congrArg (fun s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ => - s.val x) ((bottSectionEquiv cs l hl).apply_symm_apply - (h.imageInclusion.sectionMap Set.univ m)) - - theorem bottImageSectionWordEquiv_homogeneous - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (n : ℤ) (m : (bottImageSheaf cs basis l h).forget.sections Set.univ) - (hm : ∀ x, m.val x ∈ ((bottImageSheaf cs basis l h).vertex x).piece n) : - (bottImageSectionWordEquiv cs basis l hl h hh m).val ∈ bottPiece cs basis l n := by - apply (bottPiece_iff_stalks cs basis l hl n _).mpr - intro x - rw [bottImageSectionWordEquiv_coordinates] - exact hm x - - theorem bottAdjointImageEquivDual_apply - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (m : (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ) - (n : (bottImageSheaf cs basis l h).forget.sections Set.univ) : - bottAdjointImageEquivDual cs basis l hl h hh m n=bottSamelsonDuality cs l - (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl h) - (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh) m).val - (bottImageSectionWordEquiv cs basis l hl h hh n).val := rfl - - theorem bottAdjointImagePairing_homogeneous - (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) - (i j : ℤ) - (m : (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ) - (n : (bottImageSheaf cs basis l h).forget.sections Set.univ) - (hm : ∀ x, m.val x ∈ - ((bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).vertex x).piece i) - (hn : ∀ x, n.val x ∈ ((bottImageSheaf cs basis l h).vertex x).piece j) : - bottAdjointImageEquivDual cs basis l hl h hh m n ∈ symmetricGrading basis (i+j-(l.length : ℤ)) := by - rw [bottAdjointImageEquivDual_apply] - exact bottDuality_homogeneous cs basis l - (bottImageSectionWordEquiv_homogeneous cs basis l hl _ - (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh) i m hm) - (bottImageSectionWordEquiv_homogeneous cs basis l hl h hh j n hn) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! A specified integral graded sheaf splitting identifies its source with -its literal projector image. No existence of a word/BMP splitting is assumed -outside each explicitly parametric helper. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} (s : SplitIn B C) -noncomputable section - - def SplitIn.projector : Hom C C := s.inclusion.comp s.projection - -omit [IsNoetherianRing A] in - theorem SplitIn.projector_vertex (x : V) (v : C.vertex x) : - (s.projector.vertex x).map ((s.projector.vertex x).map v)=(s.projector.vertex x).map v := by - change (s.inclusion.vertex x).map ((s.projection.vertex x).map - ((s.inclusion.vertex x).map ((s.projection.vertex x).map v)))=_ - rw [s.vertex_split] - rfl - -omit [IsNoetherianRing A] in - theorem SplitIn.projector_edge (e : E) (v : C.edge e) : - (s.projector.edge e).map ((s.projector.edge e).map v)=(s.projector.edge e).map v := by - change (s.inclusion.edge e).map ((s.projection.edge e).map - ((s.inclusion.edge e).map ((s.projection.edge e).map v)))=_ - rw [s.edge_split] - rfl - - def SplitIn.imageTo : Hom s.projector.image B := s.projection.comp s.projector.imageInclusion - def SplitIn.toImage : Hom B s.projector.image := s.projector.imageProjection.comp s.inclusion - - theorem SplitIn.imageTo_toImage_vertex (x : V) (v : B.vertex x) : - (s.imageTo.vertex x).map ((s.toImage.vertex x).map v)=v := by - change (s.projection.vertex x).map ((s.inclusion.vertex x).map - ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))=v - rw [s.vertex_split,s.vertex_split] - - theorem SplitIn.toImage_imageTo_vertex (x : V) (v : s.projector.image.vertex x) : - (s.toImage.vertex x).map ((s.imageTo.vertex x).map v)=v := by - apply Subtype.ext - obtain ⟨m,hm⟩ := v.property - change (s.projector.vertex x).map ((s.projector.vertex x).map v.val)=v.val - rw [s.projector_vertex,← hm,s.projector_vertex] - - theorem SplitIn.imageTo_toImage_edge (e : E) (v : B.edge e) : - (s.imageTo.edge e).map ((s.toImage.edge e).map v)=v := by - change (s.projection.edge e).map ((s.inclusion.edge e).map - ((s.projection.edge e).map ((s.inclusion.edge e).map v)))=v - rw [s.edge_split,s.edge_split] - - theorem SplitIn.toImage_imageTo_edge (e : E) (v : s.projector.image.edge e) : - (s.toImage.edge e).map ((s.imageTo.edge e).map v)=v := by - apply Subtype.ext - obtain ⟨m,hm⟩ := v.property - change (s.projector.edge e).map ((s.projector.edge e).map v.val)=v.val - rw [s.projector_edge,← hm,s.projector_edge] - - theorem SplitIn.imageSection_bijective (Ω : Set V) : - Function.Bijective (s.imageTo.sectionMap Ω) := by - constructor - · intro m n he - apply Subtype.ext - funext x - have hx := congrFun (congrArg Subtype.val he) x - have hy := congrArg (s.toImage.vertex x).map hx - exact (s.toImage_imageTo_vertex x (m.val x)).symm.trans - (hy.trans (s.toImage_imageTo_vertex x (n.val x))) - · intro m - refine ⟨s.toImage.sectionMap Ω m,?_⟩ - apply Subtype.ext - funext x - exact s.imageTo_toImage_vertex x (m.val x) - - def SplitIn.imageSectionEquiv (Ω : Set V) : - s.projector.image.forget.sections Ω ≃ₗ[A] B.forget.sections Ω := - LinearEquiv.ofBijective (s.imageTo.sectionMap Ω) (s.imageSection_bijective Ω) - - theorem SplitIn.imageSectionEquiv_symm_apply (Ω : Set V) (m : B.forget.sections Ω) : - (s.imageSectionEquiv Ω).symm m=s.toImage.sectionMap Ω m := by - apply (s.imageSectionEquiv Ω).injective - rw [LinearEquiv.apply_symm_apply] - apply Subtype.ext - funext x - exact (s.imageTo_toImage_vertex x (m.val x)).symm - - theorem SplitIn.imageSectionEquiv_symm_homogeneous (Ω : Set V) (n : ℤ) - (m : B.forget.sections Ω) (hm : ∀ x, m.val x ∈ (B.vertex x).piece n) (x : V) : - ((s.imageSectionEquiv Ω).symm m).val x ∈ (s.projector.image.vertex x).piece n := by - rw [s.imageSectionEquiv_symm_apply] - exact (s.toImage.vertex x).graded n (m.val x) (hm x) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! Correct integral graded duality for a GIVEN word-sheaf summand: the dual -is realized by its ADJOINT image, not identified with the original summand. -The existence and BMP recognition of that summand remain separate. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) - (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - def bottSplitAdjointSheaf : GradedSheaf (𝓐 := symmetricGrading basis) - (graph cs 1 (cs.wordProd l)) := - bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl s.projector) - - def bottSplitAdjointEquivDual : - (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ ≃ₗ[ - SymmetricCoefficient (M := M)] - Dual (SymmetricCoefficient (M := M)) (B.forget.sections Set.univ) := by - letI := symmetricCoefficientNoetherian basis - exact (bottAdjointImageEquivDual cs basis l hl s.projector s.projector_vertex).trans - (s.imageSectionEquiv Set.univ).symm.dualMap - - theorem bottSplitAdjointPairing_homogeneous - (i j : ℤ) - (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) - (n : B.forget.sections Set.univ) - (hm : ∀ x, m.val x ∈ ((bottSplitAdjointSheaf cs basis l hl B s).vertex x).piece i) - (hn : ∀ x, n.val x ∈ (B.vertex x).piece j) : - bottSplitAdjointEquivDual cs basis l hl B s m n ∈ - symmetricGrading basis (i+j-(l.length : ℤ)) := by - let := symmetricCoefficientNoetherian basis - exact bottAdjointImagePairing_homogeneous cs basis l hl s.projector s.projector_vertex i j m - ((s.imageSectionEquiv Set.univ).symm n) hm - (s.imageSectionEquiv_symm_homogeneous Set.univ j n hn) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! An actual word-sheaf endomorphism that is the identity at one stalk has -adjoint equal to the identity at that same stalk. In particular, an identity -TOP projector stays normalized on taking the adjoint. This alone does not -supply free stalks, flabbiness, or the BMP character. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (h : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - theorem bottEndOfSheaf_fixed_support (x : Interval cs 1 (cs.wordProd l)) - (hx : ∀ v, (h.vertex x).map v=v) - (m : BottSamelsonModule cs l) (hm : m ∈ bottWeightSupported cs l x.val) : - bottEndOfSheaf cs basis l hl h m=m := by - apply bottEvaluation_injective cs l - funext e - by_cases he : bottWeight cs l e=x.val - · have ho := bottEndOfSheaf_coordinates cs basis l hl h m x - exact congrFun (congrArg Subtype.val (ho.trans (hx _))) ⟨e,he⟩ - · exact (bottEndOfSheaf_preserves_support cs basis l hl h x m hm e he).trans - (hm e he).symm - - theorem bottAdjointSheaf_fixed_stalk (x : Interval cs 1 (cs.wordProd l)) - (hx : ∀ v, (h.vertex x).map v=v) (v : bottStalk cs l x.val) : - ((bottAdjointSheaf cs basis l hl h).vertex x).map v=v := by - obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v - rw [bottAdjointSheaf_vertex] - have hz : bottStalkProjection cs l x.val - (bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) m-m)=0 := by - apply (bott_projection_zero_iff_annihilates_support cs l x.val _).mpr - intro z - change bottSamelsonDuality cs l z.val - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) - (bottEndOfSheaf cs basis l hl h) m-m)=0 - rw [map_sub,PerfectAdjoint.symmetric_pairing _ (bottSamelson_symmetric cs l)] - rw [bottEndOfSheaf_fixed_support cs basis l hl h x hx z.val z.property,sub_self] - rw [map_sub] at hz - exact sub_eq_zero.mp hz - - theorem bottAdjointSheaf_fixed_stalk_iff (x : Interval cs 1 (cs.wordProd l)) : - (∀ v, ((bottAdjointSheaf cs basis l hl h).vertex x).map v=v) ↔ - (∀ v, (h.vertex x).map v=v) := by - constructor - · intro hx v - have h' := bottAdjointSheaf_fixed_stalk cs basis l hl - (bottAdjointSheaf cs basis l hl h) x hx v - exact (bottAdjointSheaf_twice_vertex cs basis l hl h x v).symm.trans h' - · exact fun hx v => bottAdjointSheaf_fixed_stalk cs basis l hl h x hx v - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {M N : ModuleData.{uk,ua,um} 𝓐} - theorem Hom.eq_of_map_eq (f g : Hom M N) (h : f.map=g.map) : f=g := by - cases f - cases g - cases h - rfl -end KLInvariance.Graded.ModuleData - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} - - theorem Hom.eq_of_maps (f g : Hom B C) - (hv : ∀ x v, (f.vertex x).map v=(g.vertex x).map v) - (he : ∀ e v, (f.edge e).map v=(g.edge e).map v) : f=g := by - have hv' : f.vertex=g.vertex := funext (fun x => - ModuleData.Hom.eq_of_map_eq _ _ (LinearMap.ext (hv x))) - have he' : f.edge=g.edge := funext (fun e => - ModuleData.Hom.eq_of_map_eq _ _ (LinearMap.ext (he e))) - cases f - cases g - cases hv' - cases he' - rfl - - theorem Hom.eq_of_vertex (f g : Hom B C) - (hs : ∀ e, Function.Surjective (B.lower e).map) - (hv : ∀ x v, (f.vertex x).map v=(g.vertex x).map v) : f=g := by - apply f.eq_of_maps g hv - intro e v - obtain ⟨w,rfl⟩ := hs e v - rw [f.lower,g.lower,hv] - -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! Integral anti-involution on the actual graded word-sheaf endomorphisms. -This is the algebra required to compare an indecomposable BMP summand to -its adjoint, not an assertion that such a summand is already recognized. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) -noncomputable section - - theorem bottEndOfSheaf_comp - (h g : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - bottEndOfSheaf cs basis l hl (h.comp g)= - (bottEndOfSheaf cs basis l hl h).comp (bottEndOfSheaf cs basis l hl g) := by - apply LinearMap.ext - intro m - apply bottVertexProjection_injective cs l hl - funext x - exact (bottEndOfSheaf_coordinates cs basis l hl (h.comp g) m x).trans - ((congrArg (h.vertex x).map (bottEndOfSheaf_coordinates cs basis l hl g m x)).symm.trans - (bottEndOfSheaf_coordinates cs basis l hl h (bottEndOfSheaf cs basis l hl g m) x).symm) - - theorem bottAdjointSheaf_comp - (h g : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - bottAdjointSheaf cs basis l hl (h.comp g)= - (bottAdjointSheaf cs basis l hl g).comp (bottAdjointSheaf cs basis l hl h) := by - apply GradedSheaf.Hom.eq_of_vertex - · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e - · intro x v - have hs : Function.Surjective (bottStalkProjection cs l x.val) := - bottStalkProjection_surjective cs l x.val - obtain ⟨m,rfl⟩ := hs v - change ((bottAdjointSheaf cs basis l hl (h.comp g)).vertex x).map - (bottStalkProjection cs l x.val m)= - ((bottAdjointSheaf cs basis l hl g).vertex x).map - (((bottAdjointSheaf cs basis l hl h).vertex x).map (bottStalkProjection cs l x.val m)) - simp only [bottAdjointSheaf_vertex] - change bottStalkProjection cs l x.val - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl (h.comp g)) m)= - bottStalkProjection cs l x.val - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl g) - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl h) m)) - rw [bottEndOfSheaf_comp,PerfectAdjoint.adjoint_comp] - rfl - - theorem bottAdjointSheaf_involutive : Function.Involutive (bottAdjointSheaf cs basis l hl) := by - intro h - apply GradedSheaf.Hom.eq_of_vertex - · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e - · exact bottAdjointSheaf_twice_vertex cs basis l hl h - - theorem bottAdjointSheaf_injective : Function.Injective (bottAdjointSheaf cs basis l hl) := - (bottAdjointSheaf_involutive cs basis l hl).injective - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The endomorphism-corner formulation of a primitive graded sheaf -projector. This is a criterion, not an assertion of a BMP splitting. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} - - def Hom.zero : Hom B C where - vertex x := ⟨0,fun n _ _ => (C.vertex x).piece n |>.zero_mem⟩ - edge e := ⟨0,fun n _ _ => (C.edge e).piece n |>.zero_mem⟩ - lower e v := by simp - upper e v := by simp - - def Hom.id (B : GradedSheaf (𝓐 := 𝓐) G) : Hom B B where - vertex x := ModuleData.Hom.id (B.vertex x) - edge e := ModuleData.Hom.id (B.edge e) - lower _ _ := rfl - upper _ _ := rfl - - def Hom.PrimitiveProjector (p : Hom B B) : Prop := - p.comp p=p ∧ ∀ f : Hom B B, f.comp f=f → f.comp p=f → p.comp f=f → - f=Hom.zero ∨ f=p - - theorem Hom.primitive_of_antiInvolution - (a : Hom B B → Hom B B) - (ha : Function.Involutive a) - (hac : ∀ f g, a (f.comp g)=(a g).comp (a f)) - (haz : a Hom.zero=Hom.zero) - (p : Hom B B) (hp : p.PrimitiveProjector) : - (a p).PrimitiveProjector := by - constructor - · exact (hac p p).symm.trans (congrArg a hp.1) - · intro f hf hfp hpf - have hi : (a f).comp (a f)=a f := (hac f f).symm.trans (congrArg a hf) - have hleft : (a f).comp p=a f := by - have hh := congrArg a hpf - rw [hac,ha] at hh - exact hh - have hright : p.comp (a f)=a f := by - have hh := congrArg a hfp - rw [hac,ha] at hh - exact hh - rcases hp.2 (a f) hi hleft hright with hz | he - · left - have hh := congrArg a hz - rw [ha,haz] at hh - exact hh - · right - exact (ha f).symm.trans (congrArg a he) - -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - - -namespace PerfectAdjoint -open Module -universe ur um -variable {R : Type ur} [CommRing R] {N : Type um} [AddCommGroup N] [Module R N] - theorem adjoint_zero (d : N ≃ₗ[R] Dual R N) : adjoint d (0 : End R N)=0 := by - apply LinearMap.ext - intro m - apply d.injective - apply LinearMap.ext - intro n - rw [pairing] - simp -end PerfectAdjoint - -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) -noncomputable section - - theorem bottEndOfSheaf_zero : - bottEndOfSheaf cs basis l hl GradedSheaf.Hom.zero=0 := by - apply LinearMap.ext - intro m - apply bottVertexProjection_injective cs l hl - funext x - change bottStalkProjection cs l x.val _=bottStalkProjection cs l x.val 0 - rw [map_zero] - exact bottEndOfSheaf_coordinates cs basis l hl GradedSheaf.Hom.zero m x - - theorem bottAdjointSheaf_zero : - bottAdjointSheaf cs basis l hl GradedSheaf.Hom.zero=GradedSheaf.Hom.zero := by - apply GradedSheaf.Hom.eq_of_vertex - · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e - · intro x v - have hs : Function.Surjective (bottStalkProjection cs l x.val) := - bottStalkProjection_surjective cs l x.val - obtain ⟨m,rfl⟩ := hs v - change ((bottAdjointSheaf cs basis l hl GradedSheaf.Hom.zero).vertex x).map - (bottStalkProjection cs l x.val m)=0 - rw [bottAdjointSheaf_vertex,bottEndOfSheaf_zero] - change bottStalkProjection cs l x.val - (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) 0 m)=0 - rw [PerfectAdjoint.adjoint_zero] - exact map_zero _ - - theorem bottAdjointSheaf_primitive - (p : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (hp : p.PrimitiveProjector) : - (bottAdjointSheaf cs basis l hl p).PrimitiveProjector := - GradedSheaf.Hom.primitive_of_antiInvolution _ - (bottAdjointSheaf_involutive cs basis l hl) - (bottAdjointSheaf_comp cs basis l hl) - (bottAdjointSheaf_zero cs basis l hl) p hp - - theorem bottAdjointSheaf_primitive_iff - (p : GradedSheaf.Hom - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : - (bottAdjointSheaf cs basis l hl p).PrimitiveProjector ↔ p.PrimitiveProjector := by - constructor - · intro hp - have hh := bottAdjointSheaf_primitive cs basis l hl _ hp - rw [bottAdjointSheaf_involutive cs basis l hl p] at hh - exact hh - · exact bottAdjointSheaf_primitive cs basis l hl p - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Primitive-corner recognition for genuine graded sheaf splittings. -This supplies the algebraic recognition step for a prospective BMP summand; -it neither postulates the splitting nor the word/BMP character. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} -noncomputable section - - def SplitIn.liftEnd (s : SplitIn B C) (f : Hom B B) : Hom C C := - s.inclusion.comp (f.comp s.projection) - - theorem SplitIn.liftEnd_injective (s : SplitIn B C) : Function.Injective s.liftEnd := by - intro f g h - apply Hom.eq_of_maps - · intro x v - have hh := congrArg (fun q : Hom C C => (s.projection.vertex x).map - ((q.vertex x).map ((s.inclusion.vertex x).map v))) h - change (s.projection.vertex x).map ((s.inclusion.vertex x).map - ((f.vertex x).map ((s.projection.vertex x).map ((s.inclusion.vertex x).map v))))= - (s.projection.vertex x).map ((s.inclusion.vertex x).map - ((g.vertex x).map ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))) at hh - simpa only [s.vertex_split] using hh - · intro e v - have hh := congrArg (fun q : Hom C C => (s.projection.edge e).map - ((q.edge e).map ((s.inclusion.edge e).map v))) h - change (s.projection.edge e).map ((s.inclusion.edge e).map - ((f.edge e).map ((s.projection.edge e).map ((s.inclusion.edge e).map v))))= - (s.projection.edge e).map ((s.inclusion.edge e).map - ((g.edge e).map ((s.projection.edge e).map ((s.inclusion.edge e).map v)))) at hh - simpa only [s.edge_split] using hh - - theorem SplitIn.liftEnd_comp (s : SplitIn B C) (f g : Hom B B) : - s.liftEnd (f.comp g)=(s.liftEnd f).comp (s.liftEnd g) := by - apply Hom.eq_of_maps - · intro x v - change (s.inclusion.vertex x).map ((f.vertex x).map ((g.vertex x).map - ((s.projection.vertex x).map v)))= - (s.inclusion.vertex x).map ((f.vertex x).map ((s.projection.vertex x).map - ((s.inclusion.vertex x).map ((g.vertex x).map ((s.projection.vertex x).map v))))) - rw [s.vertex_split] - · intro e v - change (s.inclusion.edge e).map ((f.edge e).map ((g.edge e).map - ((s.projection.edge e).map v)))= - (s.inclusion.edge e).map ((f.edge e).map ((s.projection.edge e).map - ((s.inclusion.edge e).map ((g.edge e).map ((s.projection.edge e).map v))))) - rw [s.edge_split] - - theorem SplitIn.liftEnd_zero (s : SplitIn B C) : s.liftEnd Hom.zero=Hom.zero := by - apply Hom.eq_of_maps - · intro x v - change (s.inclusion.vertex x).map 0=0 - exact map_zero _ - · intro e v - change (s.inclusion.edge e).map 0=0 - exact map_zero _ - - theorem SplitIn.primitive_id_of_projector (s : SplitIn B C) - (h : s.projector.PrimitiveProjector) : (Hom.id B).PrimitiveProjector := by - constructor - · apply Hom.eq_of_maps <;> intros <;> rfl - · intro f hf _ _ - have hc : (s.liftEnd f).comp (s.liftEnd f)=s.liftEnd f := - (s.liftEnd_comp f f).symm.trans (congrArg s.liftEnd hf) - have hi : s.liftEnd (Hom.id B)=s.projector := by - apply Hom.eq_of_maps <;> intros <;> rfl - have hleft : (s.liftEnd f).comp s.projector=s.liftEnd f := by - rw [← hi,← s.liftEnd_comp] - congr 1 - have hright : s.projector.comp (s.liftEnd f)=s.liftEnd f := by - rw [← hi,← s.liftEnd_comp] - congr 1 - rcases h.2 (s.liftEnd f) hc hleft hright with hz | he - · exact Or.inl (s.liftEnd_injective (hz.trans s.liftEnd_zero.symm)) - · exact Or.inr (s.liftEnd_injective (he.trans hi.symm)) - - theorem SplitIn.projector_eq_id_of_primitive (s : SplitIn B C) - (h : (Hom.id C).PrimitiveProjector) - (x : V) [Nontrivial (B.vertex x)] : s.projector=Hom.id C := by - have hi : s.projector.comp s.projector=s.projector := by - apply Hom.eq_of_maps - · exact s.projector_vertex - · exact s.projector_edge - have hl : s.projector.comp (Hom.id C)=s.projector := by - apply Hom.eq_of_maps <;> intros <;> rfl - have hr : (Hom.id C).comp s.projector=s.projector := by - apply Hom.eq_of_maps <;> intros <;> rfl - rcases h.2 s.projector hi hl hr with hz | he - · obtain ⟨v,hv⟩ := exists_ne (0 : B.vertex x) - exfalso - apply hv - have hh := congrArg (fun q : Hom C C => (s.projection.vertex x).map - ((q.vertex x).map ((s.inclusion.vertex x).map v))) hz - change (s.projection.vertex x).map ((s.inclusion.vertex x).map - ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))= - (s.projection.vertex x).map 0 at hh - simpa only [s.vertex_split,map_zero] using hh - · exact he - - def SplitIn.isoOfProjectorEqId (s : SplitIn B C) (h : s.projector=Hom.id C) : Iso B C where - vertex x := - { toLinearMap := (s.inclusion.vertex x).map - invFun := (s.projection.vertex x).map - left_inv := s.vertex_split x - right_inv := fun v => congrArg (fun q : Hom C C => (q.vertex x).map v) h } - edge e := - { toLinearMap := (s.inclusion.edge e).map - invFun := (s.projection.edge e).map - left_inv := s.edge_split e - right_inv := fun v => congrArg (fun q : Hom C C => (q.edge e).map v) h } - lower e v := s.inclusion.lower e v - upper e v := s.inclusion.upper e v - vertex_graded x := (s.inclusion.vertex x).graded - edge_graded e := (s.inclusion.edge e).graded - - def SplitIn.isoOfPrimitive (s : SplitIn B C) - (h : (Hom.id C).PrimitiveProjector) - (x : V) [Nontrivial (B.vertex x)] : Iso B C := - s.isoOfProjectorEqId (s.projector_eq_id_of_primitive h x) - - variable [IsNoetherianRing A] - - theorem Hom.primitive_image (p : Hom B B) (hp : p.PrimitiveProjector) : - (Hom.id p.image).PrimitiveProjector := by - have hv : ∀ x v, (p.vertex x).map ((p.vertex x).map v)=(p.vertex x).map v := by - intro x v - exact congrArg (fun q : Hom B B => (q.vertex x).map v) hp.1 - have he : ∀ e v, (p.edge e).map ((p.edge e).map v)=(p.edge e).map v := by - intro e v - exact congrArg (fun q : Hom B B => (q.edge e).map v) hp.1 - let s := p.imageSplit hv he - have hs : s.projector=p := by - apply Hom.eq_of_maps <;> intros <;> rfl - apply s.primitive_id_of_projector - rw [hs] - exact hp - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! A normalized minimal boundary sheaf is primitive, and that property -passes to its projector in every ACTUAL graded splitting. No word splitting -is asserted here. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} -noncomputable section - - def SplitIn.downEnd (s : SplitIn B C) (f : Hom C C) : Hom B B := - s.projection.comp (f.comp s.inclusion) - - theorem SplitIn.lift_down (s : SplitIn B C) (f : Hom C C) - (hf : f.comp s.projector=f) (hf' : s.projector.comp f=f) : - s.liftEnd (s.downEnd f)=f := by - have heq : s.liftEnd (s.downEnd f)=s.projector.comp (f.comp s.projector) := by - apply Hom.eq_of_maps <;> intros <;> rfl - rw [heq,hf,hf'] - - theorem SplitIn.downEnd_idempotent (s : SplitIn B C) (f : Hom C C) - (hf : f.comp f=f) (hf' : s.projector.comp f=f) : - (s.downEnd f).comp (s.downEnd f)=s.downEnd f := by - have heq : (s.downEnd f).comp (s.downEnd f)=s.downEnd (f.comp (s.projector.comp f)) := by - apply Hom.eq_of_maps <;> intros <;> rfl - rw [heq,hf',hf] - - theorem SplitIn.primitive_projector_of_id (s : SplitIn B C) - (h : (Hom.id B).PrimitiveProjector) : s.projector.PrimitiveProjector := by - constructor - · apply Hom.eq_of_maps - · exact s.projector_vertex - · exact s.projector_edge - · intro f hf hfp hpf - have hg := s.downEnd_idempotent f hf hpf - have hl : (s.downEnd f).comp (Hom.id B)=s.downEnd f := by - apply Hom.eq_of_maps <;> intros <;> rfl - have hr : (Hom.id B).comp (s.downEnd f)=s.downEnd f := by - apply Hom.eq_of_maps <;> intros <;> rfl - rcases h.2 (s.downEnd f) hg hl hr with hz | he - · left - exact (s.lift_down f hfp hpf).symm.trans ((congrArg s.liftEnd hz).trans s.liftEnd_zero) - · right - have hi : s.liftEnd (Hom.id B)=s.projector := by - apply Hom.eq_of_maps <;> intros <;> rfl - exact (s.lift_down f hfp hpf).symm.trans ((congrArg s.liftEnd he).trans hi) - -end -end KLInvariance.MomentGraph.GradedSheaf - -namespace KLInvariance.MomentGraph.BoundarySheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] - {hneg : ∀ n < 0, 𝓐 n=⊥} {V E : Type um} [PartialOrder V] [Finite V] - {G : OrderedGraph V E} {α : E → A} {b : V} [IsDomain A] - (B : BoundarySheaf hneg G α b) - - theorem primitive_identity : (GradedSheaf.Hom.id B.sheaf).PrimitiveProjector := by - constructor - · apply GradedSheaf.Hom.eq_of_maps <;> intros <;> rfl - · intro f hf _ _ - have hi : ∀ x v, (f.toEndomorphism.vertex x).map ((f.toEndomorphism.vertex x).map v)= - (f.toEndomorphism.vertex x).map v := by - intro x v - exact congrArg (fun q : GradedSheaf.Hom B.sheaf B.sheaf => (q.vertex x).map v) hf - rcases B.idempotent_trivial f.toEndomorphism hi with hz | hi - · left - apply GradedSheaf.Hom.eq_of_maps - · intro x v - exact LinearMap.congr_fun (hz.1 x) v - · intro e v - exact LinearMap.congr_fun (hz.2 e) v - · right - apply GradedSheaf.Hom.eq_of_maps - · intro x v - exact LinearMap.congr_fun (hi.1 x) v - · intro e v - exact LinearMap.congr_fun (hi.2 e) v - - theorem split_projector_primitive - {C : GradedSheaf (𝓐 := 𝓐) G} (s : GradedSheaf.SplitIn B.sheaf C) : - s.projector.PrimitiveProjector := - s.primitive_projector_of_id B.primitive_identity - -end KLInvariance.MomentGraph.BoundarySheaf - -end - - -section - -/-! For a supplied normalized boundary sheaf and an ACTUAL word splitting, -the adjoint image is primitively indecomposable. The splitting's existence -and the BMP axioms on that image still require word recognition. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (α : Edge cs 1 (cs.wordProd l) → SymmetricCoefficient (M := M)) - (B : BoundarySheaf (symmetricGrading_negative basis) - (graph cs 1 (cs.wordProd l)) α - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) - (s : GradedSheaf.SplitIn B.sheaf (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - theorem bottBoundarySplitAdjoint_primitive : - (GradedSheaf.Hom.id (bottSplitAdjointSheaf cs basis l hl B.sheaf s)).PrimitiveProjector := by - let := symmetricCoefficientNoetherian basis - let := interval_finite cs 1 (cs.wordProd l) - exact GradedSheaf.Hom.primitive_image _ (bottAdjointSheaf_primitive cs basis l hl - s.projector (B.split_projector_primitive s)) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The actual reduced word's top stalk is A in degree zero, integrally and -in BOTH grading directions. This is the normalization needed to start a BMP -summand construction, not a claim about the other stalks. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) -noncomputable section - -omit [Fintype σ] in - theorem bottTopStalkEquiv_homogeneous_iff (n : ℤ) - (s : bottStalk cs l (cs.wordProd l)) : - bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis n ↔ - s ∈ bottStalkPiece cs basis l (cs.wordProd l) n := by - constructor - · intro hs e _ - have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := - Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) - subst e - exact hs - · intro hs - exact hs ⟨bottFullIndex l,bottWeight_full cs l⟩ (Set.mem_univ _) - - def bottTopHom : ModuleData.Hom (bottStalkData cs basis l (cs.wordProd l)) - (ModuleData.unit (symmetricGrading_negative basis)) where - map := LinearMap.pi (fun _ => (bottTopStalkEquiv cs l hl).toLinearMap) - graded := by - intro n s hs j - change bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis (n-0) - simpa only [sub_zero] using - (bottTopStalkEquiv_homogeneous_iff cs basis l hl n s).mpr hs - - def bottTopInvHom : ModuleData.Hom (ModuleData.unit (symmetricGrading_negative basis)) - (bottStalkData cs basis l (cs.wordProd l)) where - map := (bottTopStalkEquiv cs l hl).symm.toLinearMap.comp (LinearMap.proj PUnit.unit) - graded := by - intro n a ha - apply (bottTopStalkEquiv_homogeneous_iff cs basis l hl n _).mp - change bottTopStalkEquiv cs l hl ((bottTopStalkEquiv cs l hl).symm (a PUnit.unit)) ∈ _ - rw [LinearEquiv.apply_symm_apply] - have h := ha PUnit.unit - change a PUnit.unit ∈ symmetricGrading basis (n-0) at h - simpa only [sub_zero] using h - - theorem bottTopHom_inv (a : ModuleData.unit (symmetricGrading_negative basis)) : - (bottTopHom cs basis l hl).map ((bottTopInvHom cs basis l hl).map a)=a := by - funext j - change bottTopStalkEquiv cs l hl ((bottTopStalkEquiv cs l hl).symm (a PUnit.unit))=a j - rw [LinearEquiv.apply_symm_apply] - - theorem bottTopInvHom_top (s : bottStalk cs l (cs.wordProd l)) : - (bottTopInvHom cs basis l hl).map ((bottTopHom cs basis l hl).map s)=s := - (bottTopStalkEquiv cs l hl).symm_apply_apply s - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! A split pair between rank-one normalized degree-zero modules reverses. -This uses commutativity of the genuine coefficient ring, not finite-dimensional -vector-space reasoning or a restricted perfect form. -/ - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.IntegralPairings + +namespace OAI + +/-! +Graded stalk duality, integral perfect balanced all-sections pairings, recognition and top grading. +-/ + +section + +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottPairing_dualToSupport (l : List I) (x : W) + (lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (m : BottSamelsonModule cs l) : + bottSamelsonDuality cs l (bottStalkDualToSupport cs l x lam).val m = + lam (bottStalkProjection cs l x m) := by + change bottSamelsonDuality cs l + ((bottSamelsonDuality cs l).symm ((bottStalkProjection cs l x).dualMap lam)) m = _ + rw [LinearEquiv.apply_symm_apply] + rfl + + theorem bottStalkDuality_apply_projection (l : List I) (x : W) + (s : bottWeightSupported cs l x) (m : BottSamelsonModule cs l) : + bottStalkDuality cs l x s (bottStalkProjection cs l x m) = + bottSamelsonDuality cs l s.val m := by + have he : bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)=s := + (LinearEquiv.ofBijective (bottStalkDualToSupport cs l x) + (bottStalkDualToSupport_bijective cs l x)).apply_symm_apply s + calc + _ = bottSamelsonDuality cs l + (bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)).val m := + (bottPairing_dualToSupport cs l x _ m).symm + _ = _ := by rw [he] + + theorem bottStalkDuality_homogeneous (l : List I) (x : W) (n : ℤ) + (s : bottWeightSupported cs l x) (hs : s ∈ bottSupportPiece cs basis l x n) + (j : ℤ) (v : bottStalk cs l x) (hv : v ∈ bottStalkPiece cs basis l x j) : + bottStalkDuality cs l x s v ∈ symmetricGrading basis (n+j-l.length) := by + obtain ⟨m,hm,rfl⟩ := bottStalk_homogeneous_lift cs basis l x j v hv + rw [bottStalkDuality_apply_projection] + exact bottDuality_homogeneous cs basis l hs hm + + theorem bottDualToSupport_homogeneous (l : List I) (x : W) (r : ℤ) + (lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (hlam : ∀ j v, v ∈ bottStalkPiece cs basis l x j → + lam v ∈ symmetricGrading basis (j+r)) : + bottStalkDualToSupport cs l x lam ∈ bottSupportPiece cs basis l x (r+l.length) := by + change (bottSamelsonDuality cs l).symm ((bottStalkProjection cs l x).dualMap lam) ∈ + bottPiece cs basis l (r+l.length) + apply perfect_inverse_of_homogeneous_functional (symmetricGrading basis) (bottPiece cs basis l) + (bottSamelsonDuality cs l) l.length + (fun _ _ _ _ hm hn => bottDuality_homogeneous cs basis l hm hn) r + intro j m hm + exact hlam j _ (bottStalkProjection_homogeneous cs basis l x j m hm) + + theorem bottStalkDuality_homogeneous_iff (l : List I) (x : W) (n : ℤ) + (s : bottWeightSupported cs l x) : + (∀ j v, v ∈ bottStalkPiece cs basis l x j → + bottStalkDuality cs l x s v ∈ symmetricGrading basis (n+j-l.length)) ↔ + s ∈ bottSupportPiece cs basis l x n := by + constructor + · intro h + have hh := bottDualToSupport_homogeneous cs basis l x (n-l.length) + (bottStalkDuality cs l x s) (by + intro j v hv + have he : n+j-(l.length:ℤ) = j+(n-l.length) := by omega + rw [← he] + exact h j v hv) + have he : bottStalkDualToSupport cs l x (bottStalkDuality cs l x s)=s := + (LinearEquiv.ofBijective (bottStalkDualToSupport cs l x) + (bottStalkDualToSupport_bijective cs l x)).apply_symm_apply s + simpa only [he,sub_add_cancel] using hh + · intro h + exact bottStalkDuality_homogeneous cs basis l x n s h + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The actual word adjoint preserves homogeneity. Projection kernels are +annihilators of the actual supported lattices, integrally, with no localization +or freeness assumption on the projection lattice. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + theorem bott_projection_zero_iff_annihilates_support (l : List I) (x : W) + (m : BottSamelsonModule cs l) : + bottStalkProjection cs l x m=0 ↔ ∀ s : bottWeightSupported cs l x, + bottSamelsonDuality cs l s.val m=0 := by + constructor + · intro hm s + exact bott_supported_annihilates cs l x s.property m + ((bottStalkProjection_eq_zero cs l x m).mp hm) + · intro h + apply Subtype.ext + funext e + let lam : Dual (SymmetricCoefficient (M := M)) (bottStalk cs l x) := + (LinearMap.proj e).comp (bottStalk cs l x).subtype + have he := h (bottStalkDualToSupport cs l x lam) + rw [bottPairing_dualToSupport] at he + exact he + + def bottAdjoint (l : List I) (f : End (SymmetricCoefficient (M := M)) + (BottSamelsonModule cs l)) := PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f + + theorem bottAdjoint_preserves_kernel (l : List I) (x : W) + (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) + (hf : ∀ s, s ∈ bottWeightSupported cs l x → f s ∈ bottWeightSupported cs l x) + (m : BottSamelsonModule cs l) (hm : bottStalkProjection cs l x m=0) : + bottStalkProjection cs l x (bottAdjoint cs l f m)=0 := by + apply (bott_projection_zero_iff_annihilates_support cs l x _).mpr + intro s + change bottSamelsonDuality cs l s.val (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f m)=0 + rw [PerfectAdjoint.symmetric_pairing (bottSamelsonDuality cs l) + (bottSamelson_symmetric cs l)] + exact (bott_projection_zero_iff_annihilates_support cs l x m).mp hm ⟨f s.val,hf s.val s.property⟩ + + theorem bottAdjoint_preserves_support (l : List I) (x : W) + (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) + (hf : ∀ m, bottStalkProjection cs l x m=0 → bottStalkProjection cs l x (f m)=0) + (m : BottSamelsonModule cs l) (hm : m ∈ bottWeightSupported cs l x) : + bottAdjoint cs l f m ∈ bottWeightSupported cs l x := by + apply bott_annihilates_supported cs l x + intro n hn + change bottSamelsonDuality cs l (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) f m) n=0 + rw [PerfectAdjoint.pairing] + apply bott_supported_annihilates cs l x hm + exact (bottStalkProjection_eq_zero cs l x (f n)).mp + (hf n ((bottStalkProjection_eq_zero cs l x n).mpr hn)) + + theorem bottAdjoint_homogeneous + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (f : End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l)) + (hf : ∀ n m, m ∈ bottPiece cs basis l n → f m ∈ bottPiece cs basis l n) + (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : + bottAdjoint cs l f m ∈ bottPiece cs basis l n := + adjoint_homogeneous (symmetricGrading basis) (bottPiece cs basis l) + (bottSamelsonDuality cs l) l.length + (fun _ _ _ _ h1 h2 => bottDuality_homogeneous cs basis l h1 h2) f hf n m hm + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Integral realization of tensor words as ALL sections of their actual +pair-projection sheaf. This assertion alone is not a BMP summand theorem, +flabbiness/standard-filtration theorem, or EW character theorem. -/ +namespace KLInvariance.TitsSpace +open Module MomentGraph BruhatGraph FiniteCharacterLocalization +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + def bottVertexProjection (l : List I) (u b : W) : BottSamelsonModule cs l →ₗ[ + SymmetricCoefficient (M := M)] + (∀ x : Interval cs u b, bottStalk cs l x.val) := + LinearMap.pi (fun x => bottStalkProjection cs l x.val) + + theorem bottVertexProjection_injective (l : List I) (hl : cs.IsReduced l) : + Function.Injective (bottVertexProjection cs l 1 (cs.wordProd l)) := by + intro m n h + apply bottSection_injective cs l hl + exact Subtype.ext h + + theorem bottVertexProjection_stable (l : List I) (u b : W) + (a : SymmetricCoefficient (M := M)) : + (fun x : Interval cs u b => coefficientAction cs x.val a) ∈ + stabilizer (LinearMap.range (bottVertexProjection cs l u b)) := by + rintro z ⟨m,rfl⟩ + refine ⟨bottSamelsonRight cs l a m,?_⟩ + funext x + exact bottStalkProjection_right cs l x.val a m + + theorem bottVertexProjection_scaled (l : List I) (hl : cs.IsReduced l) + (z : ∀ x : Interval cs 1 (cs.wordProd l), bottStalk cs l x.val) : + bottCoordinateDenominator cs l • z ∈ + LinearMap.range (bottVertexProjection cs l 1 (cs.wordProd l)) := by + let c (e : BottIndex l) : SymmetricCoefficient (M := M) := + (z ⟨bottWeight cs l e,one_bruhat cs _,bottWeight_bruhat cs l hl e⟩).val ⟨e,rfl⟩ + obtain ⟨m,hm⟩ := bottEvaluation_contains_scaled_coordinates cs l c + refine ⟨m,?_⟩ + funext x + apply Subtype.ext + funext e + rcases x with ⟨x,hx⟩ + rcases e with ⟨e,he⟩ + change bottWeight cs l e=x at he + subst x + exact hm e + + + theorem bottSection_pair_lift (l : List I) (u b : W) + (s : (bottProjectionSheaf cs l u b).sections Set.univ) + (x y : Interval cs u b) (t : W) (ht : cs.IsReflection t) (he : t*x.val=y.val) : + ∃ m : BottSamelsonModule cs l, + bottStalkProjection cs l x.val m=s.val x ∧ bottStalkProjection cs l y.val m=s.val y := by + have he' : t*y.val=x.val := by + rw [← he,← mul_assoc,ht.mul_self,one_mul] + have hne : cs.length y.val ≠ cs.length x.val := by + rw [← he] + exact ht.length_mul_right_ne x.val + rcases lt_or_gt_of_ne hne with hlt | hlt + · let e : Edge cs u b := ⟨(y,x),hlt,⟨t,ht,he'.symm⟩⟩ + have hs := s.property e (Set.mem_univ _) (Set.mem_univ _) + obtain ⟨m,hm,hn⟩ := (PairProjection.compatible_iff _ _ _ _).mp hs + exact ⟨m,hn,hm⟩ + · let e : Edge cs u b := ⟨(x,y),hlt,⟨t,ht,he.symm⟩⟩ + have hs := s.property e (Set.mem_univ _) (Set.mem_univ _) + exact (PairProjection.compatible_iff _ _ _ _).mp hs + + theorem bottSection_prime_lift (l : List I) (u b : W) + (s : (bottProjectionSheaf cs l u b).sections Set.univ) + (p : SymmetricCoefficient (M := M)) (hp : Prime p) (x : Interval cs u b) : + ∃ m : BottSamelsonModule cs l, ∀ y : Interval cs u b, + (∀ a, p ∣ coefficientAction cs x.val a-coefficientAction cs y.val a) → + bottStalkProjection cs l y.val m=s.val y := by + classical + by_cases hx : ∃ y : Interval cs u b, x ≠ y ∧ + ∀ a, p ∣ coefficientAction cs x.val a-coefficientAction cs y.val a + · obtain ⟨y,hxy,hcon⟩ := hx + obtain ⟨t,ht,he,hclass⟩ := prime_character_class cs p hp + (fun h => hxy (Subtype.ext h)) hcon + obtain ⟨m,hm,hn⟩ := bottSection_pair_lift cs l u b s x y t ht he.symm + refine ⟨m,?_⟩ + intro z hz + rcases (hclass z.val).mp hz with hxz | hzy + · have h : z=x := Subtype.ext hxz.symm + subst z + exact hm + · have h : z=y := Subtype.ext (hzy.trans he.symm) + subst z + exact hn + · obtain ⟨m,hm⟩ := bottStalkProjection_surjective cs l x.val (s.val x) + refine ⟨m,?_⟩ + intro y hy + have h : y=x := by + by_contra h + exact hx ⟨y,Ne.symm h,hy⟩ + subst y + exact hm + + theorem bottSection_local_denominator (l : List I) (u b : W) + (s : (bottProjectionSheaf cs l u b).sections Set.univ) + (p : SymmetricCoefficient (M := M)) (hp : Prime p) : + ∃ a : SymmetricCoefficient (M := M), ¬ p ∣ a ∧ a • s.val ∈ + LinearMap.range (bottVertexProjection cs l u b) := by + classical + let : Finite (Interval cs u b) := interval_finite cs u b + let : Fintype (Interval cs u b) := Fintype.ofFinite _ + apply character_local_denominator (E := fun x : Interval cs u b => bottStalk cs l x.val) + (LinearMap.range (bottVertexProjection cs l u b)) p hp + (fun a x => coefficientAction cs x.val a) (fun a => bottVertexProjection_stable cs l u b a) s.val + intro x + obtain ⟨m,hm⟩ := bottSection_prime_lift cs l u b s p hp x + exact ⟨bottVertexProjection cs l u b m,⟨m,rfl⟩,hm⟩ + + theorem bottSection_surjective (l : List I) (hl : cs.IsReduced l) : + Function.Surjective (bottSection cs l 1 (cs.wordProd l)) := by + intro s + let L := LinearMap.range (bottVertexProjection cs l 1 (cs.wordProd l)) + let : Module.Free (SymmetricCoefficient (M := M)) L := + Module.Free.of_equiv (LinearEquiv.ofInjective _ (bottVertexProjection_injective cs l hl)) + let : UniqueFactorizationMonoid (SymmetricCoefficient (M := M)) := + (SymmetricAlgebra.equivMvPolynomial (Module.Free.chooseBasis ℝ (Extended M))).symm.toRingEquiv.toMulEquiv.uniqueFactorizationMonoid inferInstance + have h : s.val ∈ L := EdgeLattice.mem_of_prime_local_membership L s.val + ⟨bottCoordinateDenominator cs l,bottCoordinateDenominator_ne_zero cs l, + bottVertexProjection_scaled cs l hl s.val⟩ + (fun p hp => bottSection_local_denominator cs l 1 (cs.wordProd l) s p hp) + obtain ⟨m,hm⟩ := h + exact ⟨m,Subtype.ext hm⟩ + + def bottSectionEquiv (l : List I) (hl : cs.IsReduced l) : + BottSamelsonModule cs l ≃ₗ[SymmetricCoefficient (M := M)] + (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ := + LinearEquiv.ofBijective (bottSection cs l 1 (cs.wordProd l)) + ⟨bottSection_injective cs l hl,bottSection_surjective cs l hl⟩ + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace TransportPerfectPairing +open Module +variable {A M N : Type*} [CommRing A] [AddCommGroup M] [Module A M] + [AddCommGroup N] [Module A N] + +theorem balanced (e : M ≃ₗ[A] N) (D : M ≃ₗ[A] Dual A M) (a : End A M) + (h : ∀ x y, D (a x) y = D x (a y)) (s z : N) : + (e.symm.trans (D.trans e.symm.dualMap)) + ((e.toLinearMap.comp (a.comp e.symm.toLinearMap)) s) z = + (e.symm.trans (D.trans e.symm.dualMap)) s + ((e.toLinearMap.comp (a.comp e.symm.toLinearMap)) z) := by + change D (e.symm (e (a (e.symm s)))) (e.symm z) = + D (e.symm s) (e.symm (e (a (e.symm z)))) + simp only [LinearEquiv.symm_apply_apply] + exact h _ _ + +theorem symmetric (e : M ≃ₗ[A] N) (D : M ≃ₗ[A] Dual A M) + (h : ∀ x y, D x y = D y x) (s z : N) : + (e.symm.trans (D.trans e.symm.dualMap)) s z = + (e.symm.trans (D.trans e.symm.dualMap)) z s := + h (e.symm s) (e.symm z) + +end TransportPerfectPairing + +end + + +section + +/-! Integral perfect balanced self-duality on all sections of the genuine +word projection sheaf. This is the word object, NOT the indecomposable BMP +object. Selection of a BMP summand with the required normalization is not +made or assumed here. -/ +namespace KLInvariance.TitsSpace +open Module MomentGraph BruhatGraph +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + def bottSectionDuality (l : List I) (hl : cs.IsReduced l) : + (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ ≃ₗ[ + SymmetricCoefficient (M := M)] + Dual (SymmetricCoefficient (M := M)) + ((bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) := + (bottSectionEquiv cs l hl).symm.trans + ((bottSamelsonDuality cs l).trans (bottSectionEquiv cs l hl).symm.dualMap) + + theorem bottSectionDuality_apply (l : List I) (hl : cs.IsReduced l) + (m n : BottSamelsonModule cs l) : + bottSectionDuality cs l hl (bottSection cs l 1 (cs.wordProd l) m) + (bottSection cs l 1 (cs.wordProd l) n) = bottSamelsonDuality cs l m n := by + change bottSamelsonDuality cs l + ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) m)) + ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) n))= _ + simp only [LinearEquiv.symm_apply_apply] + + def bottSectionRight (l : List I) (hl : cs.IsReduced l) + (a : SymmetricCoefficient (M := M)) : + End (SymmetricCoefficient (M := M)) + ((bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) := + (bottSectionEquiv cs l hl).toLinearMap.comp + ((bottSamelsonRight cs l a).comp (bottSectionEquiv cs l hl).symm.toLinearMap) + + theorem bottSectionRight_apply (l : List I) (hl : cs.IsReduced l) + (a : SymmetricCoefficient (M := M)) (m : BottSamelsonModule cs l) : + bottSectionRight cs l hl a (bottSection cs l 1 (cs.wordProd l) m) = + bottSection cs l 1 (cs.wordProd l) (bottSamelsonRight cs l a m) := by + change (bottSectionEquiv cs l hl) (bottSamelsonRight cs l a + ((bottSectionEquiv cs l hl).symm ((bottSectionEquiv cs l hl) m))) = _ + rw [LinearEquiv.symm_apply_apply] + rfl + + theorem bottSectionRight_coordinates (l : List I) (hl : cs.IsReduced l) + (a : SymmetricCoefficient (M := M)) + (s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) + (x : Interval cs 1 (cs.wordProd l)) : + (bottSectionRight cs l hl a s).val x=coefficientAction cs x.val a • s.val x := by + obtain ⟨m,rfl⟩ := bottSection_surjective cs l hl s + rw [bottSectionRight_apply] + exact bottStalkProjection_right cs l x.val a m + + theorem bottSection_balanced (l : List I) (hl : cs.IsReduced l) + (a : SymmetricCoefficient (M := M)) + (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) : + bottSectionDuality cs l hl (bottSectionRight cs l hl a s) z = + bottSectionDuality cs l hl s (bottSectionRight cs l hl a z) := by + exact TransportPerfectPairing.balanced (bottSectionEquiv cs l hl) + (bottSamelsonDuality cs l) (bottSamelsonRight cs l a) + (bottSamelson_balanced cs l a) s z + + theorem bottSection_symmetric (l : List I) (hl : cs.IsReduced l) + (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) : + bottSectionDuality cs l hl s z=bottSectionDuality cs l hl z s := by + exact TransportPerfectPairing.symmetric (bottSectionEquiv cs l hl) + (bottSamelsonDuality cs l) (bottSamelson_symmetric cs l) s z + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The word SECTION pairing has precisely the word-length shift in the +actual coordinatewise sheaf grading. It is not an asserted pairing on the +indecomposable BMP boundary sheaf. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottPiece_iff_stalks (l : List I) (hl : cs.IsReduced l) (n : ℤ) + (m : BottSamelsonModule cs l) : m ∈ bottPiece cs basis l n ↔ + ∀ x : Interval cs 1 (cs.wordProd l), + bottStalkProjection cs l x.val m ∈ bottStalkPiece cs basis l x.val n := by + constructor + · intro hm x + exact bottStalkProjection_homogeneous cs basis l x.val n m hm + · intro hm + have he : component (bottPiece cs basis l) n m=m := by + apply bottVertexProjection_injective cs l hl + funext x + have hh := map_component (bottPiece cs basis l) (bottStalkPiece cs basis l x.val) + (bottStalkProjection cs l x.val) 0 (by + simpa only [add_zero] using bottStalkProjection_homogeneous cs basis l x.val) n m + rw [sub_zero,show component (bottStalkPiece cs basis l x.val) n + (bottStalkProjection cs l x.val m)=bottStalkProjection cs l x.val m from + DirectSum.decompose_of_mem_same _ (hm x)] at hh + exact hh.symm + rw [← he] + exact (DirectSum.decompose (bottPiece cs basis l) m n).property + + theorem bottSectionDuality_homogeneous (l : List I) (hl : cs.IsReduced l) + (i j : ℤ) + (s z : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) + (hs : ∀ x, s.val x ∈ bottStalkPiece cs basis l x.val i) + (hz : ∀ x, z.val x ∈ bottStalkPiece cs basis l x.val j) : + bottSectionDuality cs l hl s z ∈ symmetricGrading basis (i+j-l.length) := by + obtain ⟨m,rfl⟩ := bottSection_surjective cs l hl s + obtain ⟨n,rfl⟩ := bottSection_surjective cs l hl z + rw [bottSectionDuality_apply] + exact bottDuality_homogeneous cs basis l ((bottPiece_iff_stalks cs basis l hl i m).mpr hs) + ((bottPiece_iff_stalks cs basis l hl j n).mpr hz) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Section maps for the actual graded sheaf morphisms. A sheaf splitting +really gives an integral graded section splitting; it is not replaced by a +generic-fibre splitting. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] + {G : OrderedGraph V E} {B C : GradedSheaf (𝓐 := 𝓐) G} +noncomputable section + + def Hom.assignmentMap (h : Hom B C) : B.forget.Assignment →ₗ[A] C.forget.Assignment where + toFun f x := (h.vertex x).map (f x) + map_add' f g := by funext x; exact map_add (h.vertex x).map (f x) (g x) + map_smul' r f := by funext x; exact map_smul (h.vertex x).map r (f x) + + theorem Hom.assignmentMap_compatible (h : Hom B C) (Ω : Set V) + (f : B.forget.Assignment) (hf : B.forget.CompatibleOn Ω f) : + C.forget.CompatibleOn Ω (h.assignmentMap f) := by + intro e hs ht + change (C.lower e).map ((h.vertex _).map (f _)) = + (C.upper e).map ((h.vertex _).map (f _)) + exact (h.lower e (f (G.source e))).symm.trans + ((congrArg (h.edge e).map (hf e hs ht)).trans (h.upper e (f (G.target e)))) + + def Hom.sectionMap (h : Hom B C) (Ω : Set V) : + B.forget.sections Ω →ₗ[A] C.forget.sections Ω := + (h.assignmentMap.domRestrict (B.forget.sections Ω)).codRestrict (C.forget.sections Ω) + (fun f => h.assignmentMap_compatible Ω f.val f.property) + + theorem Hom.sectionMap_apply (h : Hom B C) (Ω : Set V) + (f : B.forget.sections Ω) (x : V) : + (h.sectionMap Ω f).val x=(h.vertex x).map (f.val x) := rfl + + variable [Fintype V] [Fintype E] [IsNoetherianRing A] + + def Hom.gradedSectionMap (h : Hom B C) (Ω : Set V) : + ModuleData.Hom (B.sections Ω) (C.sections Ω) where + map := h.sectionMap Ω + graded := by + intro n f hf x hx + exact (h.vertex x).graded n (f.val x) (hf x hx) + +omit [Fintype V] [Fintype E] [IsNoetherianRing A] in + theorem SplitIn.sections_split (s : SplitIn B C) (Ω : Set V) + (f : B.forget.sections Ω) : + s.projection.sectionMap Ω (s.inclusion.sectionMap Ω f)=f := by + apply Subtype.ext + funext x + exact s.vertex_split x (f.val x) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! Endomorphisms of the ACTUAL graded word sheaf act on its integral tensor +module and preserve every stalk kernel and single-weight support lattice. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) +noncomputable section + + def bottEndOfSheaf (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + End (SymmetricCoefficient (M := M)) (BottSamelsonModule cs l) := + (bottSectionEquiv cs l hl).symm.toLinearMap.comp + ((h.sectionMap Set.univ).comp (bottSectionEquiv cs l hl).toLinearMap) + + theorem bottEndOfSheaf_coordinates (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (m : BottSamelsonModule cs l) (x : Interval cs 1 (cs.wordProd l)) : + bottStalkProjection cs l x.val (bottEndOfSheaf cs basis l hl h m)= + (h.vertex x).map (bottStalkProjection cs l x.val m) := by + have he := congrArg (fun s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ => + s.val x) ((bottSectionEquiv cs l hl).apply_symm_apply + (h.sectionMap Set.univ ((bottSectionEquiv cs l hl) m))) + exact he + + theorem bottEndOfSheaf_homogeneous (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : + bottEndOfSheaf cs basis l hl h m ∈ bottPiece cs basis l n := by + apply (bottPiece_iff_stalks cs basis l hl n _).mpr + intro x + rw [bottEndOfSheaf_coordinates] + exact (h.vertex x).graded n _ (bottStalkProjection_homogeneous cs basis l x.val n m hm) + + theorem bottEndOfSheaf_preserves_kernel (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) + (hm : bottStalkProjection cs l x.val m=0) : + bottStalkProjection cs l x.val (bottEndOfSheaf cs basis l hl h m)=0 := by + rw [bottEndOfSheaf_coordinates,hm] + exact (h.vertex x).map.map_zero + + theorem bottEndOfSheaf_preserves_support (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) + (hm : m ∈ bottWeightSupported cs l x.val) : + bottEndOfSheaf cs basis l hl h m ∈ bottWeightSupported cs l x.val := by + intro e he + let y : Interval cs 1 (cs.wordProd l) := + ⟨bottWeight cs l e,one_bruhat cs _,bottWeight_bruhat cs l hl e⟩ + have hmy : bottStalkProjection cs l y.val m=0 := by + apply Subtype.ext + funext f + exact hm f.val (fun hx => he (f.property.symm.trans hx)) + have hfy := bottEndOfSheaf_preserves_kernel cs basis l hl h y m hmy + exact congrFun (congrArg Subtype.val hfy) ⟨e,rfl⟩ + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace LinearDescent +universe ur um ux +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + {X : Type ux} [AddCommGroup X] [Module R X] + (f : M →ₗ[R] X) (hf : Function.Surjective f) (e : Module.End R M) + (he : ∀ m, f m=0 → f (e m)=0) +noncomputable section + + def descend : Module.End R X := + ((LinearMap.ker f).liftQ (f.comp e) he).comp + (f.quotKerEquivOfSurjective hf).symm.toLinearMap + + theorem descend_apply (m : M) : descend f hf e he (f m)=f (e m) := by + change (LinearMap.ker f).liftQ (f.comp e) he + ((f.quotKerEquivOfSurjective hf).symm (f m))=f (e m) + rw [LinearMap.quotKerEquivOfSurjective_symm_apply] + rfl + + theorem descend_idempotent (hee : ∀ m, e (e m)=e m) (x : X) : + descend f hf e he (descend f hf e he x)=descend f hf e he x := by + obtain ⟨m,rfl⟩ := hf x + rw [descend_apply,descend_apply,hee] + +end +end LinearDescent + +end + + +section + +namespace KLInvariance.Graded.ModuleData +open PairProjection LinearDescent +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {M X Y : ModuleData.{uk,ua,um} 𝓐} + (e : Hom M M) (f : Hom M X) (g : Hom M Y) + (hf : Function.Surjective f.map) (hg : Function.Surjective g.map) + (hef : ∀ m, f.map m=0 → f.map (e.map m)=0) + (heg : ∀ m, g.map m=0 → g.map (e.map m)=0) +noncomputable section + + def descended : Hom X X where + map := descend f.map hf e.map hef + graded := by + intro n x hx + obtain ⟨m,hm,rfl⟩ := f.homogeneous_lift hf n x hx + rw [descend_apply] + exact f.graded n _ (e.graded n m hm) + +include heg in + theorem lower_kernel_preserved (x : X) (hx : lower f.map g.map x=0) : + lower f.map g.map ((descended e f hf hef).map x)=0 := by + obtain ⟨m,hm,hn⟩ := (kernel_lower f.map g.map x).mp hx + apply (kernel_lower f.map g.map _).mpr + refine ⟨e.map m,?_,heg m hn⟩ + rw [← hm] + exact (descend_apply f.map hf e.map hef m).symm + + def descendedEdge : Hom (pairEdge f g hg) (pairEdge f g hg) where + map := descend (lower f.map g.map) (lower_surjective f.map g.map hg) + (descended e f hf hef).map (lower_kernel_preserved e f g hf hef heg) + graded := by + intro n z hz + obtain ⟨x,hx,rfl⟩ := hz + refine ⟨(descended e f hf hef).map x,(descended e f hf hef).graded n x hx,?_⟩ + exact (descend_apply (lower f.map g.map) (lower_surjective f.map g.map hg) + (descended e f hf hef).map (lower_kernel_preserved e f g hf hef heg) x).symm + + theorem descendedEdge_lower (x : X) : + (descendedEdge e f g hf hg hef heg).map (lower f.map g.map x)= + lower f.map g.map ((descended e f hf hef).map x) := + descend_apply _ _ _ _ x + + theorem descendedEdge_upper (y : Y) : + (descendedEdge e f g hf hg hef heg).map (upper f.map g.map y)= + upper f.map g.map ((descended e g hg heg).map y) := by + obtain ⟨m,rfl⟩ := hg y + rw [← compatible f.map g.map m,descendedEdge_lower] + change lower f.map g.map (descend f.map hf e.map hef (f.map m)) = + upper f.map g.map (descend g.map hg e.map heg (g.map m)) + rw [descend_apply,descend_apply] + exact compatible f.map g.map (e.map m) + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +/-! The adjoint of an actual graded word-sheaf endomorphism is again an +integral graded word-sheaf endomorphism. No stalk freeness or BMP character +is used or asserted. This supplies the correct adjoint route for a future +BMP summand, instead of restricting a form to an arbitrary summand. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) +noncomputable section + + def bottAdjointWordHom (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + ModuleData.Hom (bottWordData cs basis l) (bottWordData cs basis l) where + map := bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) + graded := bottAdjoint_homogeneous cs basis l _ + (bottEndOfSheaf_homogeneous cs basis l hl h) + + theorem bottAdjointWordHom_kernel (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) + (hm : bottStalkProjection cs l x.val m=0) : + bottStalkProjection cs l x.val ((bottAdjointWordHom cs basis l hl h).map m)=0 := + bottAdjoint_preserves_kernel cs l x.val _ + (bottEndOfSheaf_preserves_support cs basis l hl h x) m hm + + def bottAdjointSheaf (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) where + vertex x := ModuleData.descended (bottAdjointWordHom cs basis l hl h) + (bottStalkHom cs basis l x.val) (bottStalkHom_surjective cs basis l x.val) + (bottAdjointWordHom_kernel cs basis l hl h x) + edge e := ModuleData.descendedEdge (bottAdjointWordHom cs basis l hl h) + (bottStalkHom cs basis l (source cs 1 (cs.wordProd l) e).val) + (bottStalkHom cs basis l (target cs 1 (cs.wordProd l) e).val) + (bottStalkHom_surjective cs basis l _) + (bottStalkHom_surjective cs basis l _) + (bottAdjointWordHom_kernel cs basis l hl h _) + (bottAdjointWordHom_kernel cs basis l hl h _) + lower _ x := ModuleData.descendedEdge_lower _ _ _ _ _ _ _ x + upper _ y := ModuleData.descendedEdge_upper _ _ _ _ _ _ _ y + + theorem bottAdjointSheaf_vertex (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (x : Interval cs 1 (cs.wordProd l)) (m : BottSamelsonModule cs l) : + ((bottAdjointSheaf cs basis l hl h).vertex x).map (bottStalkProjection cs l x.val m)= + bottStalkProjection cs l x.val (bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) m) := + LinearDescent.descend_apply _ _ _ _ m + + theorem bottEndOfAdjointSheaf (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + bottEndOfSheaf cs basis l hl (bottAdjointSheaf cs basis l hl h)= + bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) := by + apply LinearMap.ext + intro m + apply bottVertexProjection_injective cs l hl + funext x + exact (bottEndOfSheaf_coordinates cs basis l hl _ m x).trans + (bottAdjointSheaf_vertex cs basis l hl h x m) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Integral graded adjoint WORD projectors. The assumption below is only +that the GIVEN endomorphism is a projector; no existence of a BMP projector +or identification of its image with its adjoint is asserted. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + theorem bottEndOfSheaf_idempotent + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (m : BottSamelsonModule cs l) : + bottEndOfSheaf cs basis l hl h (bottEndOfSheaf cs basis l hl h m)= + bottEndOfSheaf cs basis l hl h m := by + apply bottVertexProjection_injective cs l hl + funext x + change bottStalkProjection cs l x.val _=bottStalkProjection cs l x.val _ + simp only [bottEndOfSheaf_coordinates] + exact hh x _ + + theorem bottAdjointSheaf_vertex_idempotent + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (x : Interval cs 1 (cs.wordProd l)) + (v : bottStalk cs l x.val) : + ((bottAdjointSheaf cs basis l hl h).vertex x).map + (((bottAdjointSheaf cs basis l hl h).vertex x).map v)= + ((bottAdjointSheaf cs basis l hl h).vertex x).map v := by + obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v + simp only [bottAdjointSheaf_vertex] + exact congrArg (bottStalkProjection cs l x.val) + (PerfectAdjoint.adjoint_idempotent (bottSamelsonDuality cs l) _ + (bottEndOfSheaf_idempotent cs basis l hl h hh) m) + + theorem bottAdjointSheaf_edge_idempotent + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (e : Edge cs 1 (cs.wordProd l)) + (v : (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).edge e) : + ((bottAdjointSheaf cs basis l hl h).edge e).map + (((bottAdjointSheaf cs basis l hl h).edge e).map v)= + ((bottAdjointSheaf cs basis l hl h).edge e).map v := by + have hs : Function.Surjective + ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).lower e).map := + bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e + obtain ⟨m,rfl⟩ := hs v + simp only [(bottAdjointSheaf cs basis l hl h).lower] + exact congrArg ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).lower e).map + (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh _ m) + + theorem bottAdjointSheaf_twice_vertex (x : Interval cs 1 (cs.wordProd l)) + (v : bottStalk cs l x.val) : + ((bottAdjointSheaf cs basis l hl (bottAdjointSheaf cs basis l hl h)).vertex x).map v= + (h.vertex x).map v := by + obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v + rw [bottAdjointSheaf_vertex,bottEndOfAdjointSheaf] + change bottStalkProjection cs l x.val + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl h)) m)=_ + rw [PerfectAdjoint.adjoint_adjoint _ (bottSamelson_symmetric cs l)] + exact bottEndOfSheaf_coordinates cs basis l hl h m x + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The literal integral image sheaf of a graded projector, with its actual +splitting. Used for word-adjoint projectors; no BMP summand is assumed. -/ +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] + {M N : ModuleData.{uk,ua,um} 𝓐} +noncomputable section + + def rangeMap (e : Hom M M) (f : Hom N N) (g : Hom M N) + (h : ∀ m, f.map (g.map m)=g.map (e.map m)) : Hom (range e) (range f) where + map := (g.map.domRestrict e.map.range).codRestrict f.map.range (by + rintro ⟨_,m,rfl⟩ + exact ⟨g.map m,h m⟩) + graded n m hm := g.graded n m.val hm + + def rangeInclusion (e : Hom M M) : Hom (range e) M where + map := e.map.range.subtype + graded _ _ hm := hm + + def rangeProjection (e : Hom M M) : Hom M (range e) where + map := e.map.rangeRestrict + graded n m hm := e.graded n m hm + +end +end KLInvariance.Graded.ModuleData + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B : GradedSheaf (𝓐 := 𝓐) G} +noncomputable section + + def Hom.image (h : Hom B B) : GradedSheaf (𝓐 := 𝓐) G where + vertex x := ModuleData.range (h.vertex x) + edge e := ModuleData.range (h.edge e) + lower e := ModuleData.rangeMap (h.vertex (G.source e)) (h.edge e) (B.lower e) (h.lower e) + upper e := ModuleData.rangeMap (h.vertex (G.target e)) (h.edge e) (B.upper e) (h.upper e) + + def Hom.imageInclusion (h : Hom B B) : Hom h.image B where + vertex x := ModuleData.rangeInclusion (h.vertex x) + edge e := ModuleData.rangeInclusion (h.edge e) + lower _ _ := rfl + upper _ _ := rfl + + def Hom.imageProjection (h : Hom B B) : Hom B h.image where + vertex x := ModuleData.rangeProjection (h.vertex x) + edge e := ModuleData.rangeProjection (h.edge e) + lower e v := Subtype.ext (h.lower e v) + upper e v := Subtype.ext (h.upper e v) + + def Hom.imageSplit (h : Hom B B) + (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (he : ∀ e v, (h.edge e).map ((h.edge e).map v)=(h.edge e).map v) : SplitIn h.image B where + inclusion := h.imageInclusion + projection := h.imageProjection + vertex_split x v := by + obtain ⟨m,hm⟩ := v.property + apply Subtype.ext + change (h.vertex x).map v.val=v.val + rw [← hm,hv] + edge_split e v := by + obtain ⟨m,hm⟩ := v.property + apply Subtype.ext + change (h.edge e).map v.val=v.val + rw [← hm,he] + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! All integral sections of an idempotent image sheaf are the image of the +actual section projector; this is stronger than equality over the fraction +field and requires the actual idempotence, not merely pointwise surjectivity. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B : GradedSheaf (𝓐 := 𝓐) G} +noncomputable section + + theorem Hom.imageSection_fixed (h : Hom B B) + (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (Ω : Set V) (f : h.image.forget.sections Ω) : + h.sectionMap Ω (h.imageInclusion.sectionMap Ω f)=h.imageInclusion.sectionMap Ω f := by + apply Subtype.ext + funext x + obtain ⟨v,hv'⟩ := (f.val x).property + change (h.vertex x).map (f.val x).val=(f.val x).val + rw [← hv',hv] + + def Hom.imageSectionMap (h : Hom B B) + (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (Ω : Set V) : h.image.forget.sections Ω →ₗ[A] LinearMap.range (h.sectionMap Ω) := + (h.imageInclusion.sectionMap Ω).codRestrict _ (fun f => + ⟨h.imageInclusion.sectionMap Ω f,h.imageSection_fixed hv Ω f⟩) + + theorem Hom.imageSectionMap_bijective (h : Hom B B) + (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (Ω : Set V) : Function.Bijective (h.imageSectionMap hv Ω) := by + constructor + · intro f g hfg + apply Subtype.ext + funext x + apply Subtype.ext + exact congrFun (congrArg Subtype.val (congrArg Subtype.val hfg)) x + · rintro ⟨s,m,rfl⟩ + refine ⟨h.imageProjection.sectionMap Ω m,?_⟩ + apply Subtype.ext + apply Subtype.ext + rfl + + def Hom.imageSectionEquiv (h : Hom B B) + (hv : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (Ω : Set V) : h.image.forget.sections Ω ≃ₗ[A] LinearMap.range (h.sectionMap Ω) := + LinearEquiv.ofBijective (h.imageSectionMap hv Ω) (h.imageSectionMap_bijective hv Ω) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace ConjugateRange +open Module +universe ur um un +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + {N : Type un} [AddCommGroup N] [Module R N] + (e : M ≃ₗ[R] N) (f : End R N) +noncomputable section + + def conjugate : End R M := e.symm.toLinearMap.comp (f.comp e.toLinearMap) + + def map : LinearMap.range f →ₗ[R] LinearMap.range (conjugate e f) := + (e.symm.toLinearMap.domRestrict f.range).codRestrict _ (by + rintro ⟨_,n,rfl⟩ + refine ⟨e.symm n,?_⟩ + change e.symm (f (e (e.symm n)))=e.symm (f n) + rw [LinearEquiv.apply_symm_apply]) + + theorem map_bijective : Function.Bijective (map e f) := by + constructor + · intro m n h + apply Subtype.ext + apply e.symm.injective + exact congrArg Subtype.val h + · rintro ⟨_,m,rfl⟩ + refine ⟨⟨f (e m),e m,rfl⟩,?_⟩ + rfl + + def equiv : LinearMap.range f ≃ₗ[R] LinearMap.range (conjugate e f) := + LinearEquiv.ofBijective (map e f) (map_bijective e f) + + theorem equiv_apply (n : LinearMap.range f) : (equiv e f n).val=e.symm n.val := rfl + +end +end ConjugateRange + +end + + +section + +/-! The correct integral summand duality. A chosen summand of a perfectly +paired module is paired with its ADJOINT summand, not with itself by fiat. +This is the algebraic connector for the unresolved BMP summand recognition. +No existence of a BMP summand, or isomorphism with its adjoint, is asserted. -/ +namespace AdjointSummandDuality +universe ur um un +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + {N : Type un} [AddCommGroup N] [Module R N] + (d : M ≃ₗ[R] Module.Dual R M) (i : N →ₗ[R] M) (p : M →ₗ[R] N) + (hpi : ∀ n, p (i n)=n) +noncomputable section + + def dualSection : Module.Dual R N →ₗ[R] M := + d.symm.toLinearMap.comp p.dualMap + + def dualProjection : M →ₗ[R] Module.Dual R N := i.dualMap.comp d.toLinearMap + +include hpi in + theorem projection_section (lam : Module.Dual R N) : + dualProjection d i (dualSection d p lam)=lam := by + apply LinearMap.ext + intro n + change d (d.symm (p.dualMap lam)) (i n)=lam n + rw [LinearEquiv.apply_symm_apply] + change lam (p (i n))=lam n + rw [hpi] + + def adjointProjector : Module.End R M := (dualSection d p).comp (dualProjection d i) + +include hpi in + theorem adjointProjector_idempotent (m : M) : + adjointProjector d i p (adjointProjector d i p m)=adjointProjector d i p m := by + change dualSection d p (dualProjection d i (dualSection d p (dualProjection d i m))) = _ + rw [projection_section d i p hpi] + rfl + + def adjointSummand : Submodule R M := LinearMap.range (dualSection d p) + +include hpi in + theorem dualProjection_injective_on_adjoint : + Function.Injective ((dualProjection d i).domRestrict (adjointSummand d p)) := by + rintro ⟨m,lam,rfl⟩ ⟨n,mu,rfl⟩ h + apply Subtype.ext + change dualSection d p lam=dualSection d p mu + change dualProjection d i (dualSection d p lam)=dualProjection d i (dualSection d p mu) at h + rw [projection_section d i p hpi,projection_section d i p hpi] at h + rw [h] + +include hpi in + theorem dualProjection_surjective_on_adjoint : + Function.Surjective ((dualProjection d i).domRestrict (adjointSummand d p)) := by + intro lam + exact ⟨⟨dualSection d p lam,lam,rfl⟩,projection_section d i p hpi lam⟩ + + def adjointEquivDual : adjointSummand d p ≃ₗ[R] Module.Dual R N := + LinearEquiv.ofBijective ((dualProjection d i).domRestrict (adjointSummand d p)) + ⟨dualProjection_injective_on_adjoint d i p hpi,dualProjection_surjective_on_adjoint d i p hpi⟩ + + theorem adjointEquivDual_apply (m : adjointSummand d p) (n : N) : + adjointEquivDual d i p hpi m n=d m.val (i n) := rfl + +include hpi in + theorem adjointProjector_range : + LinearMap.range (adjointProjector d i p)=adjointSummand d p := by + apply le_antisymm + · rintro m ⟨n,rfl⟩ + exact ⟨dualProjection d i n,rfl⟩ + · rintro m ⟨lam,rfl⟩ + refine ⟨dualSection d p lam,?_⟩ + change dualSection d p (dualProjection d i (dualSection d p lam))=dualSection d p lam + rw [projection_section d i p hpi] + +variable (f : Module.End R M) (g : Module.End R N) + (hbal : ∀ m n, d (f m) n=d m (f n)) + (hi : ∀ n, f (i n)=i (g n)) (hp : ∀ m, p (f m)=g (p m)) + +include hbal hi in + theorem projection_intertwines (m : M) : + dualProjection d i (f m)=g.dualMap (dualProjection d i m) := by + apply LinearMap.ext + intro n + change d (f m) (i n)=d m (i (g n)) + rw [hbal,hi] + +include hbal hp in + theorem section_intertwines (lam : Module.Dual R N) : + f (dualSection d p lam)=dualSection d p (g.dualMap lam) := by + apply d.injective + apply LinearMap.ext + intro n + change d (f (d.symm (p.dualMap lam))) n= + d (d.symm (p.dualMap (g.dualMap lam))) n + rw [hbal,LinearEquiv.apply_symm_apply,LinearEquiv.apply_symm_apply] + change lam (p (f n))=lam (g (p n)) + rw [hp] + +include hbal hi hp in + theorem adjointProjector_commutes (m : M) : + f (adjointProjector d i p m)=adjointProjector d i p (f m) := by + change f (dualSection d p (dualProjection d i m)) = + dualSection d p (dualProjection d i (f m)) + rw [section_intertwines d p f g hbal hp,projection_intertwines d i f g hbal hi] + +end +end AdjointSummandDuality + +end + + +section + +/-! The range of the genuine adjoint projector is integrally the dual of +the original summand, with no assumed self-duality of that summand. -/ +namespace PerfectAdjoint +open Module +universe ur um un +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + {N : Type un} [AddCommGroup N] [Module R N] + (d : M ≃ₗ[R] Dual R M) (i : N →ₗ[R] M) (p : M →ₗ[R] N) + (hpi : ∀ n, p (i n)=n) +noncomputable section + + theorem adjoint_projector_eq : adjoint d (i.comp p)= + AdjointSummandDuality.adjointProjector d i p := by + apply LinearMap.ext + intro m + rfl + + def rangeAdjointEquivDual : LinearMap.range (adjoint d (i.comp p)) ≃ₗ[R] Dual R N := + (LinearEquiv.ofEq _ _ (by + rw [adjoint_projector_eq,AdjointSummandDuality.adjointProjector_range d i p hpi])).trans + (AdjointSummandDuality.adjointEquivDual d i p hpi) + + theorem rangeAdjointEquivDual_apply (m : LinearMap.range (adjoint d (i.comp p))) (n : N) : + rangeAdjointEquivDual d i p hpi m n=d m.val (i n) := rfl + +end +end PerfectAdjoint + +end + + +section + +namespace PerfectAdjoint +open Module +universe ur um +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + (d : M ≃ₗ[R] Dual R M) (f : End R M) (hf : ∀ m, f (f m)=f m) +noncomputable section + +include hf in + theorem range_projector_split (m : f.range) : f.rangeRestrict (f.range.subtype m)=m := by + apply Subtype.ext + obtain ⟨n,hn⟩ := m.property + change f m.val=m.val + rw [← hn,hf] + + def rangeAdjointEquivDualRange : LinearMap.range (adjoint d f) ≃ₗ[R] Dual R f.range := + rangeAdjointEquivDual d f.range.subtype f.rangeRestrict (range_projector_split f hf) + + theorem rangeAdjointEquivDualRange_apply (m : LinearMap.range (adjoint d f)) (n : f.range) : + rangeAdjointEquivDualRange d f hf m n=d m.val n.val := rfl + +end +end PerfectAdjoint + +end + + +section + +namespace KLInvariance.TitsSpace +open Module +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + +include basis in + theorem symmetricCoefficientNoetherian : IsNoetherianRing (SymmetricCoefficient (M := M)) := + isNoetherianRing_of_surjective (MvPolynomial σ ℝ) (SymmetricCoefficient (M := M)) + (SymmetricAlgebra.equivMvPolynomial basis).symm.toRingHom + (SymmetricAlgebra.equivMvPolynomial basis).symm.surjective + +end KLInvariance.TitsSpace + +end + + +section + +/-! The actual adjoint IMAGE sheaf has all integral sections dual to those +of the original projector image. This does not identify those two image +sheaves or assert that the word sheaf satisfies the BMP axioms. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + def bottImageSheaf : GradedSheaf (𝓐 := symmetricGrading basis) + (graph cs 1 (cs.wordProd l)) := by + letI := symmetricCoefficientNoetherian basis + exact h.image + + def bottImageSectionWordEquiv + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) : + (bottImageSheaf cs basis l h).forget.sections Set.univ ≃ₗ[ + SymmetricCoefficient (M := M)] LinearMap.range (bottEndOfSheaf cs basis l hl h) := by + letI := symmetricCoefficientNoetherian basis + exact (h.imageSectionEquiv hh Set.univ).trans + (ConjugateRange.equiv (bottSectionEquiv cs l hl) (h.sectionMap Set.univ)) + + def bottAdjointImageEquivDual + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) : + (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ ≃ₗ[ + SymmetricCoefficient (M := M)] + Dual (SymmetricCoefficient (M := M)) + ((bottImageSheaf cs basis l h).forget.sections Set.univ) := + (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl h) + (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh)).trans + ((LinearEquiv.ofEq _ _ (congrArg LinearMap.range + (bottEndOfAdjointSheaf cs basis l hl h))).trans + ((PerfectAdjoint.rangeAdjointEquivDualRange (bottSamelsonDuality cs l) + (bottEndOfSheaf cs basis l hl h) + (bottEndOfSheaf_idempotent cs basis l hl h hh)).trans + (bottImageSectionWordEquiv cs basis l hl h hh).dualMap)) + + theorem bottImageSectionWordEquiv_coordinates + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (m : (bottImageSheaf cs basis l h).forget.sections Set.univ) + (x : Interval cs 1 (cs.wordProd l)) : + bottStalkProjection cs l x.val ((bottImageSectionWordEquiv cs basis l hl h hh m).val)= + (m.val x).val := by + let := symmetricCoefficientNoetherian basis + exact congrArg (fun s : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ => + s.val x) ((bottSectionEquiv cs l hl).apply_symm_apply + (h.imageInclusion.sectionMap Set.univ m)) + + theorem bottImageSectionWordEquiv_homogeneous + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (n : ℤ) (m : (bottImageSheaf cs basis l h).forget.sections Set.univ) + (hm : ∀ x, m.val x ∈ ((bottImageSheaf cs basis l h).vertex x).piece n) : + (bottImageSectionWordEquiv cs basis l hl h hh m).val ∈ bottPiece cs basis l n := by + apply (bottPiece_iff_stalks cs basis l hl n _).mpr + intro x + rw [bottImageSectionWordEquiv_coordinates] + exact hm x + + theorem bottAdjointImageEquivDual_apply + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (m : (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ) + (n : (bottImageSheaf cs basis l h).forget.sections Set.univ) : + bottAdjointImageEquivDual cs basis l hl h hh m n=bottSamelsonDuality cs l + (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl h) + (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh) m).val + (bottImageSectionWordEquiv cs basis l hl h hh n).val := rfl + + theorem bottAdjointImagePairing_homogeneous + (hh : ∀ x v, (h.vertex x).map ((h.vertex x).map v)=(h.vertex x).map v) + (i j : ℤ) + (m : (bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).forget.sections Set.univ) + (n : (bottImageSheaf cs basis l h).forget.sections Set.univ) + (hm : ∀ x, m.val x ∈ + ((bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl h)).vertex x).piece i) + (hn : ∀ x, n.val x ∈ ((bottImageSheaf cs basis l h).vertex x).piece j) : + bottAdjointImageEquivDual cs basis l hl h hh m n ∈ symmetricGrading basis (i+j-(l.length : ℤ)) := by + rw [bottAdjointImageEquivDual_apply] + exact bottDuality_homogeneous cs basis l + (bottImageSectionWordEquiv_homogeneous cs basis l hl _ + (bottAdjointSheaf_vertex_idempotent cs basis l hl h hh) i m hm) + (bottImageSectionWordEquiv_homogeneous cs basis l hl h hh j n hn) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! A specified integral graded sheaf splitting identifies its source with +its literal projector image. No existence of a word/BMP splitting is assumed +outside each explicitly parametric helper. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} (s : SplitIn B C) +noncomputable section + + def SplitIn.projector : Hom C C := s.inclusion.comp s.projection + +omit [IsNoetherianRing A] in + theorem SplitIn.projector_vertex (x : V) (v : C.vertex x) : + (s.projector.vertex x).map ((s.projector.vertex x).map v)=(s.projector.vertex x).map v := by + change (s.inclusion.vertex x).map ((s.projection.vertex x).map + ((s.inclusion.vertex x).map ((s.projection.vertex x).map v)))=_ + rw [s.vertex_split] + rfl + +omit [IsNoetherianRing A] in + theorem SplitIn.projector_edge (e : E) (v : C.edge e) : + (s.projector.edge e).map ((s.projector.edge e).map v)=(s.projector.edge e).map v := by + change (s.inclusion.edge e).map ((s.projection.edge e).map + ((s.inclusion.edge e).map ((s.projection.edge e).map v)))=_ + rw [s.edge_split] + rfl + + def SplitIn.imageTo : Hom s.projector.image B := s.projection.comp s.projector.imageInclusion + def SplitIn.toImage : Hom B s.projector.image := s.projector.imageProjection.comp s.inclusion + + theorem SplitIn.imageTo_toImage_vertex (x : V) (v : B.vertex x) : + (s.imageTo.vertex x).map ((s.toImage.vertex x).map v)=v := by + change (s.projection.vertex x).map ((s.inclusion.vertex x).map + ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))=v + rw [s.vertex_split,s.vertex_split] + + theorem SplitIn.toImage_imageTo_vertex (x : V) (v : s.projector.image.vertex x) : + (s.toImage.vertex x).map ((s.imageTo.vertex x).map v)=v := by + apply Subtype.ext + obtain ⟨m,hm⟩ := v.property + change (s.projector.vertex x).map ((s.projector.vertex x).map v.val)=v.val + rw [s.projector_vertex,← hm,s.projector_vertex] + + theorem SplitIn.imageTo_toImage_edge (e : E) (v : B.edge e) : + (s.imageTo.edge e).map ((s.toImage.edge e).map v)=v := by + change (s.projection.edge e).map ((s.inclusion.edge e).map + ((s.projection.edge e).map ((s.inclusion.edge e).map v)))=v + rw [s.edge_split,s.edge_split] + + theorem SplitIn.toImage_imageTo_edge (e : E) (v : s.projector.image.edge e) : + (s.toImage.edge e).map ((s.imageTo.edge e).map v)=v := by + apply Subtype.ext + obtain ⟨m,hm⟩ := v.property + change (s.projector.edge e).map ((s.projector.edge e).map v.val)=v.val + rw [s.projector_edge,← hm,s.projector_edge] + + theorem SplitIn.imageSection_bijective (Ω : Set V) : + Function.Bijective (s.imageTo.sectionMap Ω) := by + constructor + · intro m n he + apply Subtype.ext + funext x + have hx := congrFun (congrArg Subtype.val he) x + have hy := congrArg (s.toImage.vertex x).map hx + exact (s.toImage_imageTo_vertex x (m.val x)).symm.trans + (hy.trans (s.toImage_imageTo_vertex x (n.val x))) + · intro m + refine ⟨s.toImage.sectionMap Ω m,?_⟩ + apply Subtype.ext + funext x + exact s.imageTo_toImage_vertex x (m.val x) + + def SplitIn.imageSectionEquiv (Ω : Set V) : + s.projector.image.forget.sections Ω ≃ₗ[A] B.forget.sections Ω := + LinearEquiv.ofBijective (s.imageTo.sectionMap Ω) (s.imageSection_bijective Ω) + + theorem SplitIn.imageSectionEquiv_symm_apply (Ω : Set V) (m : B.forget.sections Ω) : + (s.imageSectionEquiv Ω).symm m=s.toImage.sectionMap Ω m := by + apply (s.imageSectionEquiv Ω).injective + rw [LinearEquiv.apply_symm_apply] + apply Subtype.ext + funext x + exact (s.imageTo_toImage_vertex x (m.val x)).symm + + theorem SplitIn.imageSectionEquiv_symm_homogeneous (Ω : Set V) (n : ℤ) + (m : B.forget.sections Ω) (hm : ∀ x, m.val x ∈ (B.vertex x).piece n) (x : V) : + ((s.imageSectionEquiv Ω).symm m).val x ∈ (s.projector.image.vertex x).piece n := by + rw [s.imageSectionEquiv_symm_apply] + exact (s.toImage.vertex x).graded n (m.val x) (hm x) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! Correct integral graded duality for a GIVEN word-sheaf summand: the dual +is realized by its ADJOINT image, not identified with the original summand. +The existence and BMP recognition of that summand remain separate. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) + (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + def bottSplitAdjointSheaf : GradedSheaf (𝓐 := symmetricGrading basis) + (graph cs 1 (cs.wordProd l)) := + bottImageSheaf cs basis l (bottAdjointSheaf cs basis l hl s.projector) + + def bottSplitAdjointEquivDual : + (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ ≃ₗ[ + SymmetricCoefficient (M := M)] + Dual (SymmetricCoefficient (M := M)) (B.forget.sections Set.univ) := by + letI := symmetricCoefficientNoetherian basis + exact (bottAdjointImageEquivDual cs basis l hl s.projector s.projector_vertex).trans + (s.imageSectionEquiv Set.univ).symm.dualMap + + theorem bottSplitAdjointPairing_homogeneous + (i j : ℤ) + (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) + (n : B.forget.sections Set.univ) + (hm : ∀ x, m.val x ∈ ((bottSplitAdjointSheaf cs basis l hl B s).vertex x).piece i) + (hn : ∀ x, n.val x ∈ (B.vertex x).piece j) : + bottSplitAdjointEquivDual cs basis l hl B s m n ∈ + symmetricGrading basis (i+j-(l.length : ℤ)) := by + let := symmetricCoefficientNoetherian basis + exact bottAdjointImagePairing_homogeneous cs basis l hl s.projector s.projector_vertex i j m + ((s.imageSectionEquiv Set.univ).symm n) hm + (s.imageSectionEquiv_symm_homogeneous Set.univ j n hn) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! An actual word-sheaf endomorphism that is the identity at one stalk has +adjoint equal to the identity at that same stalk. In particular, an identity +TOP projector stays normalized on taking the adjoint. This alone does not +supply free stalks, flabbiness, or the BMP character. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (h : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + theorem bottEndOfSheaf_fixed_support (x : Interval cs 1 (cs.wordProd l)) + (hx : ∀ v, (h.vertex x).map v=v) + (m : BottSamelsonModule cs l) (hm : m ∈ bottWeightSupported cs l x.val) : + bottEndOfSheaf cs basis l hl h m=m := by + apply bottEvaluation_injective cs l + funext e + by_cases he : bottWeight cs l e=x.val + · have ho := bottEndOfSheaf_coordinates cs basis l hl h m x + exact congrFun (congrArg Subtype.val (ho.trans (hx _))) ⟨e,he⟩ + · exact (bottEndOfSheaf_preserves_support cs basis l hl h x m hm e he).trans + (hm e he).symm + + theorem bottAdjointSheaf_fixed_stalk (x : Interval cs 1 (cs.wordProd l)) + (hx : ∀ v, (h.vertex x).map v=v) (v : bottStalk cs l x.val) : + ((bottAdjointSheaf cs basis l hl h).vertex x).map v=v := by + obtain ⟨m,rfl⟩ := bottStalkProjection_surjective cs l x.val v + rw [bottAdjointSheaf_vertex] + have hz : bottStalkProjection cs l x.val + (bottAdjoint cs l (bottEndOfSheaf cs basis l hl h) m-m)=0 := by + apply (bott_projection_zero_iff_annihilates_support cs l x.val _).mpr + intro z + change bottSamelsonDuality cs l z.val + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) + (bottEndOfSheaf cs basis l hl h) m-m)=0 + rw [map_sub,PerfectAdjoint.symmetric_pairing _ (bottSamelson_symmetric cs l)] + rw [bottEndOfSheaf_fixed_support cs basis l hl h x hx z.val z.property,sub_self] + rw [map_sub] at hz + exact sub_eq_zero.mp hz + + theorem bottAdjointSheaf_fixed_stalk_iff (x : Interval cs 1 (cs.wordProd l)) : + (∀ v, ((bottAdjointSheaf cs basis l hl h).vertex x).map v=v) ↔ + (∀ v, (h.vertex x).map v=v) := by + constructor + · intro hx v + have h' := bottAdjointSheaf_fixed_stalk cs basis l hl + (bottAdjointSheaf cs basis l hl h) x hx v + exact (bottAdjointSheaf_twice_vertex cs basis l hl h x v).symm.trans h' + · exact fun hx v => bottAdjointSheaf_fixed_stalk cs basis l hl h x hx v + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {M N : ModuleData.{uk,ua,um} 𝓐} + theorem Hom.eq_of_map_eq (f g : Hom M N) (h : f.map=g.map) : f=g := by + cases f + cases g + cases h + rfl +end KLInvariance.Graded.ModuleData + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} + + theorem Hom.eq_of_maps (f g : Hom B C) + (hv : ∀ x v, (f.vertex x).map v=(g.vertex x).map v) + (he : ∀ e v, (f.edge e).map v=(g.edge e).map v) : f=g := by + have hv' : f.vertex=g.vertex := funext (fun x => + ModuleData.Hom.eq_of_map_eq _ _ (LinearMap.ext (hv x))) + have he' : f.edge=g.edge := funext (fun e => + ModuleData.Hom.eq_of_map_eq _ _ (LinearMap.ext (he e))) + cases f + cases g + cases hv' + cases he' + rfl + + theorem Hom.eq_of_vertex (f g : Hom B C) + (hs : ∀ e, Function.Surjective (B.lower e).map) + (hv : ∀ x v, (f.vertex x).map v=(g.vertex x).map v) : f=g := by + apply f.eq_of_maps g hv + intro e v + obtain ⟨w,rfl⟩ := hs e v + rw [f.lower,g.lower,hv] + +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! Integral anti-involution on the actual graded word-sheaf endomorphisms. +This is the algebra required to compare an indecomposable BMP summand to +its adjoint, not an assertion that such a summand is already recognized. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) +noncomputable section + + theorem bottEndOfSheaf_comp + (h g : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + bottEndOfSheaf cs basis l hl (h.comp g)= + (bottEndOfSheaf cs basis l hl h).comp (bottEndOfSheaf cs basis l hl g) := by + apply LinearMap.ext + intro m + apply bottVertexProjection_injective cs l hl + funext x + exact (bottEndOfSheaf_coordinates cs basis l hl (h.comp g) m x).trans + ((congrArg (h.vertex x).map (bottEndOfSheaf_coordinates cs basis l hl g m x)).symm.trans + (bottEndOfSheaf_coordinates cs basis l hl h (bottEndOfSheaf cs basis l hl g m) x).symm) + + theorem bottAdjointSheaf_comp + (h g : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + bottAdjointSheaf cs basis l hl (h.comp g)= + (bottAdjointSheaf cs basis l hl g).comp (bottAdjointSheaf cs basis l hl h) := by + apply GradedSheaf.Hom.eq_of_vertex + · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e + · intro x v + have hs : Function.Surjective (bottStalkProjection cs l x.val) := + bottStalkProjection_surjective cs l x.val + obtain ⟨m,rfl⟩ := hs v + change ((bottAdjointSheaf cs basis l hl (h.comp g)).vertex x).map + (bottStalkProjection cs l x.val m)= + ((bottAdjointSheaf cs basis l hl g).vertex x).map + (((bottAdjointSheaf cs basis l hl h).vertex x).map (bottStalkProjection cs l x.val m)) + simp only [bottAdjointSheaf_vertex] + change bottStalkProjection cs l x.val + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl (h.comp g)) m)= + bottStalkProjection cs l x.val + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl g) + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) (bottEndOfSheaf cs basis l hl h) m)) + rw [bottEndOfSheaf_comp,PerfectAdjoint.adjoint_comp] + rfl + + theorem bottAdjointSheaf_involutive : Function.Involutive (bottAdjointSheaf cs basis l hl) := by + intro h + apply GradedSheaf.Hom.eq_of_vertex + · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e + · exact bottAdjointSheaf_twice_vertex cs basis l hl h + + theorem bottAdjointSheaf_injective : Function.Injective (bottAdjointSheaf cs basis l hl) := + (bottAdjointSheaf_involutive cs basis l hl).injective + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The endomorphism-corner formulation of a primitive graded sheaf +projector. This is a criterion, not an assertion of a BMP splitting. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} + + def Hom.zero : Hom B C where + vertex x := ⟨0,fun n _ _ => (C.vertex x).piece n |>.zero_mem⟩ + edge e := ⟨0,fun n _ _ => (C.edge e).piece n |>.zero_mem⟩ + lower e v := by simp + upper e v := by simp + + def Hom.id (B : GradedSheaf (𝓐 := 𝓐) G) : Hom B B where + vertex x := ModuleData.Hom.id (B.vertex x) + edge e := ModuleData.Hom.id (B.edge e) + lower _ _ := rfl + upper _ _ := rfl + + def Hom.PrimitiveProjector (p : Hom B B) : Prop := + p.comp p=p ∧ ∀ f : Hom B B, f.comp f=f → f.comp p=f → p.comp f=f → + f=Hom.zero ∨ f=p + + theorem Hom.primitive_of_antiInvolution + (a : Hom B B → Hom B B) + (ha : Function.Involutive a) + (hac : ∀ f g, a (f.comp g)=(a g).comp (a f)) + (haz : a Hom.zero=Hom.zero) + (p : Hom B B) (hp : p.PrimitiveProjector) : + (a p).PrimitiveProjector := by + constructor + · exact (hac p p).symm.trans (congrArg a hp.1) + · intro f hf hfp hpf + have hi : (a f).comp (a f)=a f := (hac f f).symm.trans (congrArg a hf) + have hleft : (a f).comp p=a f := by + have hh := congrArg a hpf + rw [hac,ha] at hh + exact hh + have hright : p.comp (a f)=a f := by + have hh := congrArg a hfp + rw [hac,ha] at hh + exact hh + rcases hp.2 (a f) hi hleft hright with hz | he + · left + have hh := congrArg a hz + rw [ha,haz] at hh + exact hh + · right + exact (ha f).symm.trans (congrArg a he) + +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + + +namespace PerfectAdjoint +open Module +universe ur um +variable {R : Type ur} [CommRing R] {N : Type um} [AddCommGroup N] [Module R N] + theorem adjoint_zero (d : N ≃ₗ[R] Dual R N) : adjoint d (0 : End R N)=0 := by + apply LinearMap.ext + intro m + apply d.injective + apply LinearMap.ext + intro n + rw [pairing] + simp +end PerfectAdjoint + +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) +noncomputable section + + theorem bottEndOfSheaf_zero : + bottEndOfSheaf cs basis l hl GradedSheaf.Hom.zero=0 := by + apply LinearMap.ext + intro m + apply bottVertexProjection_injective cs l hl + funext x + change bottStalkProjection cs l x.val _=bottStalkProjection cs l x.val 0 + rw [map_zero] + exact bottEndOfSheaf_coordinates cs basis l hl GradedSheaf.Hom.zero m x + + theorem bottAdjointSheaf_zero : + bottAdjointSheaf cs basis l hl GradedSheaf.Hom.zero=GradedSheaf.Hom.zero := by + apply GradedSheaf.Hom.eq_of_vertex + · exact fun e => bottProjectionSheaf_lower_surjective cs l 1 (cs.wordProd l) e + · intro x v + have hs : Function.Surjective (bottStalkProjection cs l x.val) := + bottStalkProjection_surjective cs l x.val + obtain ⟨m,rfl⟩ := hs v + change ((bottAdjointSheaf cs basis l hl GradedSheaf.Hom.zero).vertex x).map + (bottStalkProjection cs l x.val m)=0 + rw [bottAdjointSheaf_vertex,bottEndOfSheaf_zero] + change bottStalkProjection cs l x.val + (PerfectAdjoint.adjoint (bottSamelsonDuality cs l) 0 m)=0 + rw [PerfectAdjoint.adjoint_zero] + exact map_zero _ + + theorem bottAdjointSheaf_primitive + (p : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (hp : p.PrimitiveProjector) : + (bottAdjointSheaf cs basis l hl p).PrimitiveProjector := + GradedSheaf.Hom.primitive_of_antiInvolution _ + (bottAdjointSheaf_involutive cs basis l hl) + (bottAdjointSheaf_comp cs basis l hl) + (bottAdjointSheaf_zero cs basis l hl) p hp + + theorem bottAdjointSheaf_primitive_iff + (p : GradedSheaf.Hom + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) : + (bottAdjointSheaf cs basis l hl p).PrimitiveProjector ↔ p.PrimitiveProjector := by + constructor + · intro hp + have hh := bottAdjointSheaf_primitive cs basis l hl _ hp + rw [bottAdjointSheaf_involutive cs basis l hl p] at hh + exact hh + · exact bottAdjointSheaf_primitive cs basis l hl p + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Primitive-corner recognition for genuine graded sheaf splittings. +This supplies the algebraic recognition step for a prospective BMP summand; +it neither postulates the splitting nor the word/BMP character. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} +noncomputable section + + def SplitIn.liftEnd (s : SplitIn B C) (f : Hom B B) : Hom C C := + s.inclusion.comp (f.comp s.projection) + + theorem SplitIn.liftEnd_injective (s : SplitIn B C) : Function.Injective s.liftEnd := by + intro f g h + apply Hom.eq_of_maps + · intro x v + have hh := congrArg (fun q : Hom C C => (s.projection.vertex x).map + ((q.vertex x).map ((s.inclusion.vertex x).map v))) h + change (s.projection.vertex x).map ((s.inclusion.vertex x).map + ((f.vertex x).map ((s.projection.vertex x).map ((s.inclusion.vertex x).map v))))= + (s.projection.vertex x).map ((s.inclusion.vertex x).map + ((g.vertex x).map ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))) at hh + simpa only [s.vertex_split] using hh + · intro e v + have hh := congrArg (fun q : Hom C C => (s.projection.edge e).map + ((q.edge e).map ((s.inclusion.edge e).map v))) h + change (s.projection.edge e).map ((s.inclusion.edge e).map + ((f.edge e).map ((s.projection.edge e).map ((s.inclusion.edge e).map v))))= + (s.projection.edge e).map ((s.inclusion.edge e).map + ((g.edge e).map ((s.projection.edge e).map ((s.inclusion.edge e).map v)))) at hh + simpa only [s.edge_split] using hh + + theorem SplitIn.liftEnd_comp (s : SplitIn B C) (f g : Hom B B) : + s.liftEnd (f.comp g)=(s.liftEnd f).comp (s.liftEnd g) := by + apply Hom.eq_of_maps + · intro x v + change (s.inclusion.vertex x).map ((f.vertex x).map ((g.vertex x).map + ((s.projection.vertex x).map v)))= + (s.inclusion.vertex x).map ((f.vertex x).map ((s.projection.vertex x).map + ((s.inclusion.vertex x).map ((g.vertex x).map ((s.projection.vertex x).map v))))) + rw [s.vertex_split] + · intro e v + change (s.inclusion.edge e).map ((f.edge e).map ((g.edge e).map + ((s.projection.edge e).map v)))= + (s.inclusion.edge e).map ((f.edge e).map ((s.projection.edge e).map + ((s.inclusion.edge e).map ((g.edge e).map ((s.projection.edge e).map v))))) + rw [s.edge_split] + + theorem SplitIn.liftEnd_zero (s : SplitIn B C) : s.liftEnd Hom.zero=Hom.zero := by + apply Hom.eq_of_maps + · intro x v + change (s.inclusion.vertex x).map 0=0 + exact map_zero _ + · intro e v + change (s.inclusion.edge e).map 0=0 + exact map_zero _ + + theorem SplitIn.primitive_id_of_projector (s : SplitIn B C) + (h : s.projector.PrimitiveProjector) : (Hom.id B).PrimitiveProjector := by + constructor + · apply Hom.eq_of_maps <;> intros <;> rfl + · intro f hf _ _ + have hc : (s.liftEnd f).comp (s.liftEnd f)=s.liftEnd f := + (s.liftEnd_comp f f).symm.trans (congrArg s.liftEnd hf) + have hi : s.liftEnd (Hom.id B)=s.projector := by + apply Hom.eq_of_maps <;> intros <;> rfl + have hleft : (s.liftEnd f).comp s.projector=s.liftEnd f := by + rw [← hi,← s.liftEnd_comp] + congr 1 + have hright : s.projector.comp (s.liftEnd f)=s.liftEnd f := by + rw [← hi,← s.liftEnd_comp] + congr 1 + rcases h.2 (s.liftEnd f) hc hleft hright with hz | he + · exact Or.inl (s.liftEnd_injective (hz.trans s.liftEnd_zero.symm)) + · exact Or.inr (s.liftEnd_injective (he.trans hi.symm)) + + theorem SplitIn.projector_eq_id_of_primitive (s : SplitIn B C) + (h : (Hom.id C).PrimitiveProjector) + (x : V) [Nontrivial (B.vertex x)] : s.projector=Hom.id C := by + have hi : s.projector.comp s.projector=s.projector := by + apply Hom.eq_of_maps + · exact s.projector_vertex + · exact s.projector_edge + have hl : s.projector.comp (Hom.id C)=s.projector := by + apply Hom.eq_of_maps <;> intros <;> rfl + have hr : (Hom.id C).comp s.projector=s.projector := by + apply Hom.eq_of_maps <;> intros <;> rfl + rcases h.2 s.projector hi hl hr with hz | he + · obtain ⟨v,hv⟩ := exists_ne (0 : B.vertex x) + exfalso + apply hv + have hh := congrArg (fun q : Hom C C => (s.projection.vertex x).map + ((q.vertex x).map ((s.inclusion.vertex x).map v))) hz + change (s.projection.vertex x).map ((s.inclusion.vertex x).map + ((s.projection.vertex x).map ((s.inclusion.vertex x).map v)))= + (s.projection.vertex x).map 0 at hh + simpa only [s.vertex_split,map_zero] using hh + · exact he + + def SplitIn.isoOfProjectorEqId (s : SplitIn B C) (h : s.projector=Hom.id C) : Iso B C where + vertex x := + { toLinearMap := (s.inclusion.vertex x).map + invFun := (s.projection.vertex x).map + left_inv := s.vertex_split x + right_inv := fun v => congrArg (fun q : Hom C C => (q.vertex x).map v) h } + edge e := + { toLinearMap := (s.inclusion.edge e).map + invFun := (s.projection.edge e).map + left_inv := s.edge_split e + right_inv := fun v => congrArg (fun q : Hom C C => (q.edge e).map v) h } + lower e v := s.inclusion.lower e v + upper e v := s.inclusion.upper e v + vertex_graded x := (s.inclusion.vertex x).graded + edge_graded e := (s.inclusion.edge e).graded + + def SplitIn.isoOfPrimitive (s : SplitIn B C) + (h : (Hom.id C).PrimitiveProjector) + (x : V) [Nontrivial (B.vertex x)] : Iso B C := + s.isoOfProjectorEqId (s.projector_eq_id_of_primitive h x) + + variable [IsNoetherianRing A] + + theorem Hom.primitive_image (p : Hom B B) (hp : p.PrimitiveProjector) : + (Hom.id p.image).PrimitiveProjector := by + have hv : ∀ x v, (p.vertex x).map ((p.vertex x).map v)=(p.vertex x).map v := by + intro x v + exact congrArg (fun q : Hom B B => (q.vertex x).map v) hp.1 + have he : ∀ e v, (p.edge e).map ((p.edge e).map v)=(p.edge e).map v := by + intro e v + exact congrArg (fun q : Hom B B => (q.edge e).map v) hp.1 + let s := p.imageSplit hv he + have hs : s.projector=p := by + apply Hom.eq_of_maps <;> intros <;> rfl + apply s.primitive_id_of_projector + rw [hs] + exact hp + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! A normalized minimal boundary sheaf is primitive, and that property +passes to its projector in every ACTUAL graded splitting. No word splitting +is asserted here. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} +noncomputable section + + def SplitIn.downEnd (s : SplitIn B C) (f : Hom C C) : Hom B B := + s.projection.comp (f.comp s.inclusion) + + theorem SplitIn.lift_down (s : SplitIn B C) (f : Hom C C) + (hf : f.comp s.projector=f) (hf' : s.projector.comp f=f) : + s.liftEnd (s.downEnd f)=f := by + have heq : s.liftEnd (s.downEnd f)=s.projector.comp (f.comp s.projector) := by + apply Hom.eq_of_maps <;> intros <;> rfl + rw [heq,hf,hf'] + + theorem SplitIn.downEnd_idempotent (s : SplitIn B C) (f : Hom C C) + (hf : f.comp f=f) (hf' : s.projector.comp f=f) : + (s.downEnd f).comp (s.downEnd f)=s.downEnd f := by + have heq : (s.downEnd f).comp (s.downEnd f)=s.downEnd (f.comp (s.projector.comp f)) := by + apply Hom.eq_of_maps <;> intros <;> rfl + rw [heq,hf',hf] + + theorem SplitIn.primitive_projector_of_id (s : SplitIn B C) + (h : (Hom.id B).PrimitiveProjector) : s.projector.PrimitiveProjector := by + constructor + · apply Hom.eq_of_maps + · exact s.projector_vertex + · exact s.projector_edge + · intro f hf hfp hpf + have hg := s.downEnd_idempotent f hf hpf + have hl : (s.downEnd f).comp (Hom.id B)=s.downEnd f := by + apply Hom.eq_of_maps <;> intros <;> rfl + have hr : (Hom.id B).comp (s.downEnd f)=s.downEnd f := by + apply Hom.eq_of_maps <;> intros <;> rfl + rcases h.2 (s.downEnd f) hg hl hr with hz | he + · left + exact (s.lift_down f hfp hpf).symm.trans ((congrArg s.liftEnd hz).trans s.liftEnd_zero) + · right + have hi : s.liftEnd (Hom.id B)=s.projector := by + apply Hom.eq_of_maps <;> intros <;> rfl + exact (s.lift_down f hfp hpf).symm.trans ((congrArg s.liftEnd he).trans hi) + +end +end KLInvariance.MomentGraph.GradedSheaf + +namespace KLInvariance.MomentGraph.BoundarySheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] + {hneg : ∀ n < 0, 𝓐 n=⊥} {V E : Type um} [PartialOrder V] [Finite V] + {G : OrderedGraph V E} {α : E → A} {b : V} [IsDomain A] + (B : BoundarySheaf hneg G α b) + + theorem primitive_identity : (GradedSheaf.Hom.id B.sheaf).PrimitiveProjector := by + constructor + · apply GradedSheaf.Hom.eq_of_maps <;> intros <;> rfl + · intro f hf _ _ + have hi : ∀ x v, (f.toEndomorphism.vertex x).map ((f.toEndomorphism.vertex x).map v)= + (f.toEndomorphism.vertex x).map v := by + intro x v + exact congrArg (fun q : GradedSheaf.Hom B.sheaf B.sheaf => (q.vertex x).map v) hf + rcases B.idempotent_trivial f.toEndomorphism hi with hz | hi + · left + apply GradedSheaf.Hom.eq_of_maps + · intro x v + exact LinearMap.congr_fun (hz.1 x) v + · intro e v + exact LinearMap.congr_fun (hz.2 e) v + · right + apply GradedSheaf.Hom.eq_of_maps + · intro x v + exact LinearMap.congr_fun (hi.1 x) v + · intro e v + exact LinearMap.congr_fun (hi.2 e) v + + theorem split_projector_primitive + {C : GradedSheaf (𝓐 := 𝓐) G} (s : GradedSheaf.SplitIn B.sheaf C) : + s.projector.PrimitiveProjector := + s.primitive_projector_of_id B.primitive_identity + +end KLInvariance.MomentGraph.BoundarySheaf + +end + + +section + +/-! For a supplied normalized boundary sheaf and an ACTUAL word splitting, +the adjoint image is primitively indecomposable. The splitting's existence +and the BMP axioms on that image still require word recognition. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (α : Edge cs 1 (cs.wordProd l) → SymmetricCoefficient (M := M)) + (B : BoundarySheaf (symmetricGrading_negative basis) + (graph cs 1 (cs.wordProd l)) α + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) + (s : GradedSheaf.SplitIn B.sheaf (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + theorem bottBoundarySplitAdjoint_primitive : + (GradedSheaf.Hom.id (bottSplitAdjointSheaf cs basis l hl B.sheaf s)).PrimitiveProjector := by + let := symmetricCoefficientNoetherian basis + let := interval_finite cs 1 (cs.wordProd l) + exact GradedSheaf.Hom.primitive_image _ (bottAdjointSheaf_primitive cs basis l hl + s.projector (B.split_projector_primitive s)) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The actual reduced word's top stalk is A in degree zero, integrally and +in BOTH grading directions. This is the normalization needed to start a BMP +summand construction, not a claim about the other stalks. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) +noncomputable section + +omit [Fintype σ] in + theorem bottTopStalkEquiv_homogeneous_iff (n : ℤ) + (s : bottStalk cs l (cs.wordProd l)) : + bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis n ↔ + s ∈ bottStalkPiece cs basis l (cs.wordProd l) n := by + constructor + · intro hs e _ + have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := + Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) + subst e + exact hs + · intro hs + exact hs ⟨bottFullIndex l,bottWeight_full cs l⟩ (Set.mem_univ _) + + def bottTopHom : ModuleData.Hom (bottStalkData cs basis l (cs.wordProd l)) + (ModuleData.unit (symmetricGrading_negative basis)) where + map := LinearMap.pi (fun _ => (bottTopStalkEquiv cs l hl).toLinearMap) + graded := by + intro n s hs j + change bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis (n-0) + simpa only [sub_zero] using + (bottTopStalkEquiv_homogeneous_iff cs basis l hl n s).mpr hs + + def bottTopInvHom : ModuleData.Hom (ModuleData.unit (symmetricGrading_negative basis)) + (bottStalkData cs basis l (cs.wordProd l)) where + map := (bottTopStalkEquiv cs l hl).symm.toLinearMap.comp (LinearMap.proj PUnit.unit) + graded := by + intro n a ha + apply (bottTopStalkEquiv_homogeneous_iff cs basis l hl n _).mp + change bottTopStalkEquiv cs l hl ((bottTopStalkEquiv cs l hl).symm (a PUnit.unit)) ∈ _ + rw [LinearEquiv.apply_symm_apply] + have h := ha PUnit.unit + change a PUnit.unit ∈ symmetricGrading basis (n-0) at h + simpa only [sub_zero] using h + + theorem bottTopHom_inv (a : ModuleData.unit (symmetricGrading_negative basis)) : + (bottTopHom cs basis l hl).map ((bottTopInvHom cs basis l hl).map a)=a := by + funext j + change bottTopStalkEquiv cs l hl ((bottTopStalkEquiv cs l hl).symm (a PUnit.unit))=a j + rw [LinearEquiv.apply_symm_apply] + + theorem bottTopInvHom_top (s : bottStalk cs l (cs.wordProd l)) : + (bottTopInvHom cs basis l hl).map ((bottTopHom cs basis l hl).map s)=s := + (bottTopStalkEquiv cs l hl).symm_apply_apply s + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! A split pair between rank-one normalized degree-zero modules reverses. +This uses commutativity of the genuine coefficient ring, not finite-dimensional +vector-space reasoning or a restricted perfect form. -/ + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/BottSamelson.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/BottSamelson.lean index cfd6f6480758e4d8c10e5cdc48954415f133335a..7eedc87f3ca659a09e7ad60ce3df1a497d04aae2 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/BottSamelson.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/BottSamelson.lean @@ -1,2111 +1,2111 @@ -import OAI.RepresentationTheory.KazhdanLusztig.Frobenius - -namespace OAI - -/-! -Bott-Samelson tensor ranges, actual sections, grading and right kernels. --/ - -section - -namespace KLInvariance -open TensorProduct -universe uc ua un uv up -variable {C : Type uc} [CommRing C] {A : Type ua} [CommRing A] [Algebra C A] - {N : Type un} [AddCommGroup N] [Module C N] - {V : Type uv} [AddCommGroup V] [Module A V] - {P : Type up} [AddCommGroup P] [Module A P] - theorem tensor_range_le_of_one_tmul (F : (A ⊗[C] N) →ₗ[A] V) (G : P →ₗ[A] V) - (h : ∀ n : N, F ((1 : A) ⊗ₜ[C] n) ∈ LinearMap.range G) : - LinearMap.range F ≤ LinearMap.range G := by - rintro _ ⟨m,rfl⟩ - induction m using TensorProduct.inductionOn with - | add m n hm hn => rw [map_add]; exact (LinearMap.range G).add_mem hm hn - | tmul a n => - have he : a ⊗ₜ[C] n = a • ((1 : A) ⊗ₜ[C] n) := by - rw [TensorProduct.smul_tmul', smul_eq_mul,mul_one] - rw [he,map_smul] - exact (LinearMap.range G).smul_mem a (h n) - theorem tensor_maps_eq_of_one_tmul (F G : (A ⊗[C] N) →ₗ[A] V) - (h : ∀ n : N, F ((1 : A) ⊗ₜ[C] n)=G ((1 : A) ⊗ₜ[C] n)) : F=G := by - apply LinearMap.ext - intro m - induction m using TensorProduct.inductionOn with - | add m n hm hn => rw [map_add,map_add,hm,hn] - | tmul a n => - have he : a ⊗ₜ[C] n = a • ((1 : A) ⊗ₜ[C] n) := by - rw [TensorProduct.smul_tmul',smul_eq_mul,mul_one] - rw [he,map_smul,map_smul,h n] - - theorem codRestrict_surjective_of_range_le (G : P →ₗ[A] V) (S : Submodule A V) - (hG : ∀ p, G p ∈ S) (hS : S ≤ LinearMap.range G) : - Function.Surjective (LinearMap.codRestrict S G hG) := by - intro z - obtain ⟨p,hp⟩ := hS z.property - exact ⟨p,Subtype.ext hp⟩ -end KLInvariance - -end - - -section - -namespace KLInvariance.TitsSpace -open Module TensorProduct FrobeniusDuality ReflectionFrobenius -universe u v up -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section -attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite - theorem bottWeightProjection_range_le (i : I) (l : List I) (x : W) - {P : Type up} [AddCommGroup P] [Module (SymmetricCoefficient (M := M)) P] - (G : P →ₗ[SymmetricCoefficient (M := M)] - ({e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M))) - (h : ∀ n : BottSamelsonModule cs l, - bottWeightProjection cs (i::l) x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n) ∈ LinearMap.range G) : - LinearMap.range (bottWeightProjection cs (i::l) x) ≤ LinearMap.range G := by - exact tensor_range_le_of_one_tmul (C := simpleFixed cs i) - (A := SymmetricCoefficient (M := M)) (N := BottSamelsonModule cs l) - (bottWeightProjection cs (i::l) x) G h - theorem bottTensor_maps_eq (i : I) (l : List I) - {P : Type up} [AddCommGroup P] [Module (SymmetricCoefficient (M := M)) P] - (F G : BottSamelsonModule cs (i::l) →ₗ[SymmetricCoefficient (M := M)] P) - (h : ∀ n : BottSamelsonModule cs l, - F ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)= - G ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)) : F=G := - tensor_maps_eq_of_one_tmul (C := simpleFixed cs i) - (A := SymmetricCoefficient (M := M)) (N := BottSamelsonModule cs l) F G h - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The genuine head-word stalk is an integral reflected pair lattice of the -tail word. This supplies the stalk-freeness step once tail edge exactness is -proved; it does not assume the desired main conclusion. -/ -namespace KLInvariance.TitsSpace -open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section -attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite - - omit [Fintype I] in - theorem bottWeight_tail_zero (i : I) (l : List I) (x : W) - (e : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x}) (h : e.val.1=0) : - bottWeight cs l e.val.2=x := by - simpa only [bottWeight,ite_eq_left h] using e.property - - omit [Fintype I] in - theorem bottWeight_tail_one (i : I) (l : List I) (x : W) - (e : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x}) (h : e.val.1≠0) : - bottWeight cs l e.val.2=cs.simple i*x := by - have he : cs.simple i*bottWeight cs l e.val.2=x := by - simpa only [bottWeight,ite_eq_right h] using e.property - simpa only [cs.simple_mul_simple_cancel_left] using (congrArg (cs.simple i * ·) he) - - def bottHeadPairCoordinates (i : I) (l : List I) (x : W) : - (bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*x))) →ₗ[SymmetricCoefficient (M := M)] - ({e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M)) where - toFun p e := if h : e.val.1=0 then - p.1.val ⟨e.val.2,bottWeight_tail_zero cs i l x e h⟩ - else coefficientAction cs (cs.simple i) - (p.2.val.val ⟨e.val.2,bottWeight_tail_one cs i l x e h⟩) - map_add' p q := by - funext e - by_cases h : e.val.1=0 - · simp only [Pi.add_apply,dite_eq_left h]; rfl - · simp only [Pi.add_apply,dite_eq_right h] - exact map_add (coefficientAction cs (cs.simple i)) _ _ - map_smul' r p := by - funext e - dsimp - split_ifs with h - · rfl - · change coefficientAction cs (cs.simple i) - (coefficientAction cs (cs.simple i) r * _) = r * coefficientAction cs (cs.simple i) _ - rw [map_mul,simple_involutive]; rfl - - theorem bottHeadPairCoordinates_injective (i : I) (l : List I) (x : W) : - Function.Injective (bottHeadPairCoordinates cs i l x) := by - rintro ⟨p,q⟩ ⟨p',q'⟩ h - apply Prod.ext - · apply Subtype.ext - funext e - have hh := congrFun h ⟨(0,e.val),by simpa only [bottWeight,ite_true] using e.property⟩ - simpa only [bottHeadPairCoordinates,LinearMap.coe_mk,AddHom.coe_mk,dite_eq_left rfl,dite_true] using hh - · apply Twist.ext - apply Subtype.ext - funext e - have he : bottWeight cs (i::l) (1,e.val)=x := by - change (if (1 : Fin 2)=0 then _ else cs.simple i*bottWeight cs l e.val)=x - rw [ite_eq_right (by decide),e.property,cs.simple_mul_simple_cancel_left] - have hh := congrFun h ⟨(1,e.val),he⟩ - have hh' : coefficientAction cs (cs.simple i) (q.val.val e) = - coefficientAction cs (cs.simple i) (q'.val.val e) := by - simpa only [bottHeadPairCoordinates,LinearMap.coe_mk,AddHom.coe_mk, - dite_eq_right (show (1 : Fin 2)≠0 by decide)] using hh - exact (coefficientAction cs (cs.simple i)).injective hh' - - theorem simpleReverseDivisibility (i : I) (a : SymmetricCoefficient (M := M)) : - simpleRootPolynomial (M := M) i ∣ coefficientAction cs (cs.simple i) a-a := - (dvd_sub_comm).mpr (simple_divisible cs i a) - - variable (i : I) (l : List I) (x : W) - - def bottHeadPairLattice := lattice (bottStalkProjection cs l x) - (bottStalkProjection cs l (cs.simple i*x)) (coefficientAction cs (cs.simple i)).toRingEquiv - (simpleRootPolynomial (M := M) i) (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) - - instance bottHeadPairAddCommGroup : AddCommGroup (bottHeadPairLattice cs i l x) := - Submodule.addCommGroup (bottHeadPairLattice cs i l x) - - instance bottHeadPairModule : Module (SymmetricCoefficient (M := M)) (bottHeadPairLattice cs i l x) := - Submodule.module (bottHeadPairLattice cs i l x) - - theorem bottHeadPairCoordinates_seed (n : BottSamelsonModule cs l) : - bottHeadPairCoordinates cs i l x - (bottStalkProjection cs l x n,⟨bottStalkProjection cs l (cs.simple i*x) n⟩) = - bottWeightProjection cs (i::l) x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n) := by - funext e - change (if h : e.val.1=0 then _ else _) = (1 : SymmetricCoefficient (M := M))*(if e.val.1=0 then _ else _) - rw [one_mul] - split_ifs <;> rfl - - def bottHeadPairToStalk : bottHeadPairLattice cs i l x →ₗ[ - SymmetricCoefficient (M := M)] bottStalk cs (i::l) x := - LinearMap.codRestrict (bottStalk cs (i::l) x) - ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) (by - rintro ⟨⟨p,q⟩,n,hn,hn'⟩ - refine ⟨(1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n,?_⟩ - change bottWeightProjection cs (i::l) x _=bottHeadPairCoordinates cs i l x (p,q) - rw [← bottHeadPairCoordinates_seed] - congr 1 - exact Prod.ext hn (Twist.ext hn')) - - theorem bottHeadPairToStalk_injective : Function.Injective (bottHeadPairToStalk cs i l x) := by - intro p q h - apply Subtype.ext - exact bottHeadPairCoordinates_injective cs i l x (congrArg Subtype.val h) - - theorem bottHeadPair_range : - LinearMap.range (bottWeightProjection cs (i::l) x) ≤ - LinearMap.range ((bottHeadPairCoordinates cs i l x).comp - (bottHeadPairLattice cs i l x).subtype) := by - refine bottWeightProjection_range_le cs i l x (P := bottHeadPairLattice cs i l x) - ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) ?_ - intro n - refine ⟨⟨(bottStalkProjection cs l x n,⟨bottStalkProjection cs l (cs.simple i*x) n⟩),n,rfl,rfl⟩,?_⟩ - exact bottHeadPairCoordinates_seed cs i l x n - - theorem bottHeadPairToStalk_surjective : Function.Surjective (bottHeadPairToStalk cs i l x) := by - exact codRestrict_surjective_of_range_le (A := SymmetricCoefficient (M := M)) - (P := bottHeadPairLattice cs i l x) - (V := {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M)) - ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) - (bottStalk cs (i::l) x) _ (bottHeadPair_range cs i l x) - - def bottHeadPairEquiv : bottHeadPairLattice cs i l x ≃ₗ[ - SymmetricCoefficient (M := M)] bottStalk cs (i::l) x := - LinearEquiv.ofBijective (bottHeadPairToStalk cs i l x) - ⟨bottHeadPairToStalk_injective cs i l x,bottHeadPairToStalk_surjective cs i l x⟩ - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The top projection lattice of a reduced actual tensor word is exactly A. -This verifies the genuine rank-one top used in the BMP summand construction; -it does not assert that the other projection lattices form a flabby sheaf. -/ -namespace KLInvariance.TitsSpace -open Module TensorProduct -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - def bottFullIndex : (l : List I) → BottIndex l - | [] => PUnit.unit - | _::l => (1,bottFullIndex l) - -omit [Fintype I] in - theorem bottWeight_full (l : List I) : - bottWeight cs l (bottFullIndex l)=cs.wordProd l := by - induction l with - | nil => exact cs.wordProd_nil.symm - | cons i l ih => - simp only [bottFullIndex,bottWeight,show (1:Fin 2) ≠ 0 by decide,ite_false, - cs.wordProd_cons,ih] - -omit [Fintype I] in - theorem bottSubword_length_eq_full (l : List I) (e : BottIndex l) - (h : (bottSubword l e).length=l.length) : e=bottFullIndex l := by - induction l with - | nil => - change PUnit at e - change e=(PUnit.unit : PUnit) - exact Subsingleton.elim _ _ - | cons i l ih => - change Fin 2 × BottIndex l at e - by_cases he : e.1=0 - · simp only [bottSubword,ite_eq_left he,List.length_cons] at h - have hn := (bottSubword_sublist l e.2).length_le - omega - · have he1 : e.1=1 := by omega - simp only [bottSubword,ite_eq_right he,List.length_cons] at h - exact Prod.ext he1 (ih e.2 (Nat.succ.inj h)) - -omit [Fintype I] in - theorem bottWeight_eq_top (l : List I) (hl : cs.IsReduced l) (e : BottIndex l) - (he : bottWeight cs l e=cs.wordProd l) : e=bottFullIndex l := by - apply bottSubword_length_eq_full - apply Nat.le_antisymm (bottSubword_sublist l e).length_le - have hh := cs.length_wordProd_le (bottSubword l e) - rwa [bottSubword_wordProd,he,hl.eq] at hh - - def bottUnit : (l : List I) → BottSamelsonModule cs l - | [] => (1 : SymmetricCoefficient (M := M)) - | i::l => 1 ⊗ₜ[simpleFixed cs i] bottUnit l - - theorem bottEvaluation_unit (l : List I) (e : BottIndex l) : - bottEvaluation cs l e (bottUnit cs l)=1 := by - induction l with - | nil => rfl - | cons i l ih => - change bottEvaluation cs (i::l) e (1 ⊗ₜ[simpleFixed cs i] bottUnit cs l)=1 - rw [bottEvaluation_tmul,ih] - split_ifs <;> simp only [map_one,mul_one] - - theorem bottEvaluation_surjective (l : List I) (e : BottIndex l) : - Function.Surjective (bottEvaluation cs l e) := by - intro a - refine ⟨a • bottUnit cs l,?_⟩ - rw [map_smul,bottEvaluation_unit,smul_eq_mul,mul_one] - - def bottTopCoordinate (l : List I) : bottStalk cs l (cs.wordProd l) →ₗ[ - SymmetricCoefficient (M := M)] SymmetricCoefficient (M := M) := - (LinearMap.proj ⟨bottFullIndex l,bottWeight_full cs l⟩).comp - (bottStalk cs l (cs.wordProd l)).subtype - - theorem bottTopCoordinate_bijective (l : List I) (hl : cs.IsReduced l) : - Function.Bijective (bottTopCoordinate cs l) := by - constructor - · intro a b hab - apply Subtype.ext - funext e - have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := - Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) - subst e - exact hab - · intro a - obtain ⟨m,hm⟩ := bottEvaluation_surjective cs l (bottFullIndex l) a - exact ⟨bottStalkProjection cs l (cs.wordProd l) m,hm⟩ - - def bottTopStalkEquiv (l : List I) (hl : cs.IsReduced l) : - bottStalk cs l (cs.wordProd l) ≃ₗ[SymmetricCoefficient (M := M)] - SymmetricCoefficient (M := M) := - LinearEquiv.ofBijective (bottTopCoordinate cs l) (bottTopCoordinate_bijective cs l hl) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The genuine subexpression projections preserve the actual word grading. -In particular the top projection of a reduced tensor word is a graded copy of -A, rather than just an ungraded rank-one lattice. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottEvaluation_basis_homogeneous (l : List I) (e f : BottIndex l) : - bottEvaluationMatrix cs l e f ∈ symmetricGrading basis (bottDegree l f) := by - induction l with - | nil => - change PUnit at e f - change (Basis.singleton PUnit (SymmetricCoefficient (M := M)) f) ∈ - symmetricGrading basis 0 - simp only [Basis.singleton_apply] - exact SetLike.one_mem_graded _ - | cons i l ih => - change Fin 2 × BottIndex l at e f - rcases e with ⟨r,j⟩ - rcases f with ⟨c,k⟩ - rw [bottEvaluationMatrix_cons] - by_cases hc : c=0 - · subst c - simp only [ite_true,bottDegree,Fin.val_zero,Nat.cast_zero,zero_add] - split_ifs - · exact ih j k - · exact coefficientAction_homogeneous cs basis _ _ _ (ih j k) - · have hc1 : c=1 := by omega - subst c - simp only [show (1:Fin 2) ≠ 0 by decide,ite_false,bottDegree,Fin.val_one,Nat.cast_one] - split_ifs - · exact SetLike.GradedMul.mul_mem (simpleRoot_homogeneous basis i) (ih j k) - · exact SetLike.GradedMul.mul_mem ((symmetricGrading basis 1).neg_mem - (simpleRoot_homogeneous basis i)) - (coefficientAction_homogeneous cs basis _ _ _ (ih j k)) - - theorem bottEvaluation_homogeneous (l : List I) (e : BottIndex l) - (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : - bottEvaluation cs l e m ∈ symmetricGrading basis n := by - classical - have hexp : bottEvaluation cs l e m = ∑ f : BottIndex l, - (bottBasis cs l).repr m f * bottEvaluationMatrix cs l e f := by - conv_lhs => rw [← (bottBasis cs l).sum_repr m] - simp only [map_sum,map_smul,smul_eq_mul,bottEvaluationMatrix] - rw [hexp] - apply Submodule.sum_mem - intro f _ - change ∀ f, (bottBasis cs l).repr m f ∈ - symmetricGrading basis (n-bottDegree l f) at hm - have h := SetLike.GradedMul.mul_mem (hm f) - (bottEvaluation_basis_homogeneous cs basis l e f) - simpa only [sub_add_cancel] using h - - theorem bottEvaluation_component (l : List I) (e : BottIndex l) - (n : ℤ) (m : BottSamelsonModule cs l) : - component (symmetricGrading basis) n (bottEvaluation cs l e m) = - bottEvaluation cs l e (component (bottPiece cs basis l) n m) := by - simpa only [sub_zero] using map_component (bottPiece cs basis l) (symmetricGrading basis) - (bottEvaluation cs l e) 0 (by simpa only [add_zero] using bottEvaluation_homogeneous cs basis l e) n m - - theorem bottUnit_homogeneous (l : List I) : bottUnit cs l ∈ bottPiece cs basis l 0 := by - have he : component (bottPiece cs basis l) 0 (bottUnit cs l)=bottUnit cs l := by - apply bottEvaluation_injective cs l - funext e - change bottEvaluation cs l e (component (bottPiece cs basis l) 0 (bottUnit cs l)) = - bottEvaluation cs l e (bottUnit cs l) - rw [← bottEvaluation_component,bottEvaluation_unit] - exact DirectSum.decompose_of_mem_same (symmetricGrading basis) (SetLike.one_mem_graded _) - rw [← he] - exact (DirectSum.decompose (bottPiece cs basis l) (bottUnit cs l) 0).property - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Actual integral projection and support lattices inherit their grading from -the genuine tensor word. In particular a homogeneous stalk vector has a -homogeneous tensor lift. No freeness/character claim is assumed. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def bottCoordinatePiece (l : List I) (x : W) : ℤ → Submodule ℝ - ({e : BottIndex l // bottWeight cs l e=x} → SymmetricCoefficient (M := M)) := - piPiece (fun _ => symmetricGrading basis) - - instance bottCoordinatePiece_decomposition (l : List I) (x : W) : - DirectSum.Decomposition (bottCoordinatePiece cs basis l x) := by - classical - exact (pi_isInternal (fun _ : {e : BottIndex l // bottWeight cs l e=x} => - symmetricGrading basis)).chooseDecomposition - - instance bottCoordinatePiece_graded (l : List I) (x : W) : - SetLike.GradedSMul (symmetricGrading basis) (bottCoordinatePiece cs basis l x) := - inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) - (piPiece (fun _ : {e : BottIndex l // bottWeight cs l e=x} => symmetricGrading basis))) - - theorem bottWeightProjection_homogeneous (l : List I) (x : W) (n : ℤ) - (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : - bottWeightProjection cs l x m ∈ bottCoordinatePiece cs basis l x n := by - intro e _ - exact bottEvaluation_homogeneous cs basis l e.val n m hm - - theorem bottStalk_homogeneous (l : List I) (x : W) : - ∀ n f, f ∈ bottStalk cs l x → - component (bottCoordinatePiece cs basis l x) n f ∈ bottStalk cs l x := by - exact range_homogeneous (bottPiece cs basis l) (bottCoordinatePiece cs basis l x) - (bottWeightProjection cs l x) 0 (by - simpa only [add_zero] using bottWeightProjection_homogeneous cs basis l x) - - def bottStalkPiece (l : List I) (x : W) : ℤ → Submodule ℝ (bottStalk cs l x) := - subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x) - - instance bottStalkPiece_decomposition (l : List I) (x : W) : - DirectSum.Decomposition (bottStalkPiece cs basis l x) := - (sub_isInternal (bottCoordinatePiece cs basis l x) (bottStalk cs l x) - (bottStalk_homogeneous cs basis l x)).chooseDecomposition - - instance bottStalkPiece_graded (l : List I) (x : W) : - SetLike.GradedSMul (symmetricGrading basis) (bottStalkPiece cs basis l x) := - inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) - (subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x))) - - theorem bottStalkProjection_homogeneous (l : List I) (x : W) (n : ℤ) - (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : - bottStalkProjection cs l x m ∈ bottStalkPiece cs basis l x n := - bottWeightProjection_homogeneous cs basis l x n m hm - - theorem bottStalk_homogeneous_lift (l : List I) (x : W) (n : ℤ) - (s : bottStalk cs l x) (hs : s ∈ bottStalkPiece cs basis l x n) : - ∃ m : BottSamelsonModule cs l, m ∈ bottPiece cs basis l n ∧ - bottStalkProjection cs l x m=s := by - obtain ⟨m,hm⟩ := bottStalkProjection_surjective cs l x s - refine ⟨component (bottPiece cs basis l) n m, - (DirectSum.decompose (bottPiece cs basis l) m n).property,?_⟩ - have he := map_component (bottPiece cs basis l) (bottStalkPiece cs basis l x) - (bottStalkProjection cs l x) 0 (by - simpa only [add_zero] using bottStalkProjection_homogeneous cs basis l x) n m - rw [sub_zero,hm,show component (bottStalkPiece cs basis l x) n s=s from - DirectSum.decompose_of_mem_same _ hs] at he - exact he.symm - - theorem bottWeightSupported_homogeneous (l : List I) (x : W) : - ∀ n m, m ∈ bottWeightSupported cs l x → - component (bottPiece cs basis l) n m ∈ bottWeightSupported cs l x := by - intro n m hm e he - rw [← bottEvaluation_component,hm e he,map_zero] - - def bottSupportPiece (l : List I) (x : W) : - ℤ → Submodule ℝ (bottWeightSupported cs l x) := - subPiece (bottPiece cs basis l) (bottWeightSupported cs l x) - - instance bottSupportPiece_decomposition (l : List I) (x : W) : - DirectSum.Decomposition (bottSupportPiece cs basis l x) := - (sub_isInternal (bottPiece cs basis l) (bottWeightSupported cs l x) - (bottWeightSupported_homogeneous cs basis l x)).chooseDecomposition - - instance bottSupportPiece_graded (l : List I) (x : W) : - SetLike.GradedSMul (symmetricGrading basis) (bottSupportPiece cs basis l x) := - inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) - (subPiece (bottPiece cs basis l) (bottWeightSupported cs l x))) - -omit [Fintype σ] in - theorem bottTopStalkEquiv_homogeneous (l : List I) (hl : cs.IsReduced l) - (n : ℤ) (s : bottStalk cs l (cs.wordProd l)) : - bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis n ↔ - s ∈ bottStalkPiece cs basis l (cs.wordProd l) n := by - constructor - · intro h e _ - have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := - Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) - subst e - exact h - · intro h - exact h ⟨bottFullIndex l,bottWeight_full cs l⟩ (Set.mem_univ _) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Restriction of the honest reflection-twisted module to the fixed base field. -The automorphism fixes the base field, so no scalar information is discarded. -/ -namespace KLInvariance.ReflectionPairTranslation.Twist -universe uk ur uy -variable {k : Type uk} [Field k] {R : Type ur} [CommRing R] [Algebra k R] - (τ : R ≃ₐ[k] R) (Y : Type uy) [AddCommGroup Y] [Module R Y] [Module k Y] - [IsScalarTower k R Y] - -instance scalarModule : Module k (Twist τ.toRingEquiv Y) := - ({ equivVal τ.toRingEquiv Y with map_add' := fun _ _ => rfl } : - Twist τ.toRingEquiv Y ≃+ Y).module k - -instance scalarTower : IsScalarTower k R (Twist τ.toRingEquiv Y) where - smul_assoc c r y := by - apply Twist.ext - change τ (c • r) • y.val=c • (τ r • y.val) - rw [map_smul,smul_assoc] - -def scalarEquiv : Twist τ.toRingEquiv Y ≃ₗ[k] Y where - toFun := val - invFun := mk - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -end KLInvariance.ReflectionPairTranslation.Twist - -end - - -section - -/-! Homogeneous perfect pairings on the actual integral free modules. The -inverse grading is proved, not inferred merely after fraction-field extension. -/ -namespace KLInvariance.Graded -open Module -universe uk ua um un ui -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {N : Type um} [AddCommGroup N] [Module A N] [Module k N] [IsScalarTower k A N] - {P : Type un} [AddCommGroup P] [Module A P] [Module k P] [IsScalarTower k A P] -noncomputable section - -omit [Algebra k A] [IsScalarTower k A N] [IsScalarTower k A P] in - theorem equiv_inverse_homogeneous - (𝓝 : ℤ → Submodule k N) (𝓟 : ℤ → Submodule k P) - [DirectSum.Decomposition 𝓝] [DirectSum.Decomposition 𝓟] - (e : N ≃ₗ[A] P) (d : ℤ) - (he : ∀ n x, x ∈ 𝓝 n → e x ∈ 𝓟 (n+d)) - (n : ℤ) (y : P) (hy : y ∈ 𝓟 n) : e.symm y ∈ 𝓝 (n-d) := by - have hc : component 𝓝 (n-d) (e.symm y) = e.symm y := by - apply e.injective - change e.toLinearMap (component 𝓝 (n-d) (e.symm y)) = e.toLinearMap (e.symm y) - rw [← map_component 𝓝 𝓟 e.toLinearMap d he n (e.symm y)] - simp only [LinearEquiv.coe_coe,LinearEquiv.apply_symm_apply] - exact DirectSum.decompose_of_mem_same 𝓟 hy - rw [← hc] - exact (DirectSum.decompose 𝓝 (e.symm y) (n-d)).property - -variable (𝓐 : ℤ → Submodule k A) [DirectSum.Decomposition 𝓐] - [SetLike.GradedMonoid 𝓐] {ι : Type ui} [Fintype ι] [DecidableEq ι] - (b : Basis ι A N) (d : ι → ℤ) - -omit [DirectSum.Decomposition 𝓐] in - theorem pairing_to_dual_homogeneous (p : N →ₗ[A] Dual A N) (l : ℤ) - (hp : ∀ i j, p (b i) (b j) ∈ 𝓐 (d i+d j-l)) - {n : ℤ} {x : N} (hx : x ∈ basisPiece 𝓐 b d n) : - p x ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) (n-l) := by - rw [mem_basisPiece] - intro i - rw [Basis.dualBasis_repr] - have h := pairing_homogeneous 𝓐 b d p l hp hx (basis_mem_piece 𝓐 b d i) - convert h using 1 - congr 1 - omega - - theorem perfectPairing_inverse_homogeneous (p : N ≃ₗ[A] Dual A N) (l : ℤ) - (hp : ∀ i j, p (b i) (b j) ∈ 𝓐 (d i+d j-l)) - {n : ℤ} {y : Dual A N} - (hy : y ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) n) : - p.symm y ∈ basisPiece 𝓐 b d (n+l) := by - have he : ∀ m x, x ∈ basisPiece 𝓐 b d m → - p x ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) (m+(-l)) := by - intro m x hx - exact pairing_to_dual_homogeneous 𝓐 b d p.toLinearMap l hp hx - simpa only [sub_neg_eq_add] using equiv_inverse_homogeneous - (basisPiece 𝓐 b d) (basisPiece 𝓐 b.dualBasis (fun i => -d i)) p (-l) he n y hy - -end -end KLInvariance.Graded - -end - - -section - -/-! The genuine head-word projection maps, on the fixed real field, preserve -homogeneous degrees. These maps are not abstract character operators. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def bottHeadLeft (i : I) (l : List I) (x : W) : - bottStalk cs (i::l) x →ₗ[SymmetricCoefficient (M := M)] bottStalk cs l x := - (ReflectionPairTranslation.left (bottStalkProjection cs l x) - (bottStalkProjection cs l (cs.simple i*x)) (coefficientAction cs (cs.simple i)).toRingEquiv - (simpleRootPolynomial (M := M) i) (simpleReverseDivisibility cs i) - (bottSimpleEdge_kernel_inclusion cs i l x)).comp (bottHeadPairEquiv cs i l x).symm.toLinearMap - - def bottHeadRight (i : I) (l : List I) (x : W) : - bottStalk cs (i::l) x →ₗ[ℝ] bottStalk cs l (cs.simple i*x) := - (Twist.scalarEquiv (coefficientAction cs (cs.simple i)) _).toLinearMap.comp - (((LinearMap.snd (SymmetricCoefficient (M := M)) (bottStalk cs l x) - (Twist (coefficientAction cs (cs.simple i)).toRingEquiv (bottStalk cs l (cs.simple i*x)))).comp - ((bottHeadPairLattice cs i l x).subtype.comp - (bottHeadPairEquiv cs i l x).symm.toLinearMap)).restrictScalars ℝ) - - theorem bottHeadLeft_surjective (i : I) (l : List I) (x : W) : - Function.Surjective (bottHeadLeft cs i l x) := - (left_surjective _ _ _ _ _ _ (bottStalkProjection_surjective cs l x)).comp - (bottHeadPairEquiv cs i l x).symm.surjective - - theorem bottHeadPairEquiv_coordinates (i : I) (l : List I) (x : W) - (m : bottStalk cs (i::l) x) : - bottHeadPairCoordinates cs i l x ((bottHeadPairEquiv cs i l x).symm m).val=m.val := - congrArg Subtype.val ((bottHeadPairEquiv cs i l x).apply_symm_apply m) - -omit [Fintype σ] in - theorem bottHeadLeft_homogeneous (i : I) (l : List I) (x : W) (n : ℤ) - (m : bottStalk cs (i::l) x) (hm : m ∈ bottStalkPiece cs basis (i::l) x n) : - bottHeadLeft cs i l x m ∈ bottStalkPiece cs basis l x n := by - intro e _ - change (bottHeadLeft cs i l x m).val e ∈ symmetricGrading basis n - let E : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} := - ⟨(0,e.val),by simpa only [bottWeight,ite_true] using e.property⟩ - have he := congrFun (bottHeadPairEquiv_coordinates cs i l x m) E - have hh : (bottHeadLeft cs i l x m).val e=m.val E := by - change ((bottHeadPairEquiv cs i l x).symm m).val.1.val e=m.val E at he - exact he - rw [hh] - exact hm E (Set.mem_univ E) - - theorem bottHeadRight_homogeneous (i : I) (l : List I) (x : W) (n : ℤ) - (m : bottStalk cs (i::l) x) (hm : m ∈ bottStalkPiece cs basis (i::l) x n) : - bottHeadRight cs i l x m ∈ bottStalkPiece cs basis l (cs.simple i*x) n := by - intro e _ - change (bottHeadRight cs i l x m).val e ∈ symmetricGrading basis n - let E : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} := - ⟨(1,e.val),by simp only [bottWeight,ite_eq_right (show (1:Fin 2)≠0 by decide), - e.property,cs.simple_mul_simple_cancel_left]⟩ - have he := congrFun (bottHeadPairEquiv_coordinates cs i l x m) E - have hh : coefficientAction cs (cs.simple i) ((bottHeadRight cs i l x m).val e)=m.val E := by - change coefficientAction cs (cs.simple i) - (((bottHeadPairEquiv cs i l x).symm m).val.2.val.val e)=m.val E at he - exact he - have h := coefficientAction_homogeneous cs basis (cs.simple i) n (m.val E) - (hm E (Set.mem_univ E)) - rw [← hh,simple_involutive] at h - exact h - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The two common tail components of a reflected tensor. They are defined -on the actual tensor, so divisibility assertions at different weights use the -same tail vectors rather than unrelated existential lifts. -/ -namespace KLInvariance.ReflectionPairTranslation -open TensorProduct -universe uc ua un -variable {C : Type uc} [CommRing C] {A : Type ua} [CommRing A] [Algebra C A] - {N : Type un} [AddCommGroup N] [Module A N] [Module C N] [IsScalarTower C A N] - (τ : A ≃+* A) (hfix : ∀ c : C, τ (algebraMap C A c)=algebraMap C A c) -noncomputable section - - def tensorFirst : (A ⊗[C] N) →ₗ[A] N := - AlgebraTensorModule.lift ((LinearMap.id : A →ₗ[A] A).smulRight - (LinearMap.id : N →ₗ[C] N)) - - @[simp] theorem tensorFirst_tmul (a : A) (n : N) : - tensorFirst (C := C) (a ⊗ₜ[C] n)=a • n := rfl - - def tensorSecond : (A ⊗[C] N) →ₗ[A] Twist τ N := by - letI : Module C (Twist τ N) := Module.compHom _ (algebraMap C A) - letI : IsScalarTower C A (Twist τ N) := - IsScalarTower.of_algebraMap_smul fun _ _ => rfl - let F : N →ₗ[C] Twist τ N := { - toFun := Twist.mk - map_add' := fun _ _ => rfl - map_smul' := fun c n => by - apply Twist.ext - change c • n=τ (algebraMap C A c) • n - rw [hfix,algebraMap_smul] } - exact AlgebraTensorModule.lift ((LinearMap.id : A →ₗ[A] A).smulRight F) - - @[simp] theorem tensorSecond_tmul (a : A) (n : N) : - tensorSecond τ hfix (a ⊗ₜ[C] n)=Twist.mk (τ a • n) := rfl - - def twistMap {P : Type*} [AddCommGroup P] [Module A P] (f : N →ₗ[A] P) : - Twist τ N →ₗ[A] Twist τ P where - toFun m := ⟨f m.val⟩ - map_add' m n := Twist.ext (map_add f m.val n.val) - map_smul' a m := Twist.ext (map_smul f (τ a) m.val) -end -end KLInvariance.ReflectionPairTranslation - -end - - -section - -namespace KLInvariance.TitsSpace -open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section -attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite - - def bottHeadTail (i : I) (l : List I) : BottSamelsonModule cs (i::l) →ₗ[ - SymmetricCoefficient (M := M)] BottSamelsonModule cs l := - tensorFirst (C := simpleFixed cs i) - - def bottHeadReflectedTail (i : I) (l : List I) : BottSamelsonModule cs (i::l) →ₗ[ - SymmetricCoefficient (M := M)] Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (BottSamelsonModule cs l) := - tensorSecond (C := simpleFixed cs i) (coefficientAction cs (cs.simple i)).toRingEquiv - (fun c => c.property) - - theorem bottHeadTail_seed (i : I) (l : List I) (n : BottSamelsonModule cs l) : - bottHeadTail cs i l ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)=n := by - exact one_smul _ n - - theorem bottHeadReflectedTail_seed (i : I) (l : List I) (n : BottSamelsonModule cs l) : - bottHeadReflectedTail cs i l ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)=Twist.mk n := by - change Twist.mk ((coefficientAction cs (cs.simple i)) 1 • n)=Twist.mk n - rw [map_one,one_smul] - - def bottHeadLocalPair (i : I) (l : List I) (x : W) : BottSamelsonModule cs (i::l) →ₗ[ - SymmetricCoefficient (M := M)] - (bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*x))) := - ((bottStalkProjection cs l x).comp (bottHeadTail cs i l)).prod - ((twistMap (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalkProjection cs l (cs.simple i*x))).comp (bottHeadReflectedTail cs i l)) - - theorem bottHeadLocalPair_seed (i : I) (l : List I) (x : W) (n : BottSamelsonModule cs l) : - bottHeadLocalPair cs i l x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)= - (bottStalkProjection cs l x n,Twist.mk (bottStalkProjection cs l (cs.simple i*x) n)) := by - change ((bottStalkProjection cs l x) (bottHeadTail cs i l _), - (twistMap (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalkProjection cs l (cs.simple i*x))) (bottHeadReflectedTail cs i l _)) = _ - rw [bottHeadTail_seed,bottHeadReflectedTail_seed] - rfl -end -end KLInvariance.TitsSpace - -end - - -section -namespace KLInvariance -universe ua up uv un -variable {A : Type ua} [CommRing A] - {P : Type up} [AddCommGroup P] [Module A P] - {V : Type uv} [AddCommGroup V] [Module A V] - {N : Type un} [AddCommGroup N] [Module A N] - theorem linearMap_mem_of_coordinates (S : Submodule A P) - (F : P →ₗ[A] V) (G : N →ₗ[A] P) (E : N →ₗ[A] V) - (hF : Function.Injective F) (heq : F.comp G = E) - (hrange : LinearMap.range E ≤ LinearMap.range (F.comp S.subtype)) (n : N) : G n ∈ S := by - obtain ⟨p,hp⟩ := hrange (show E n ∈ LinearMap.range E from ⟨n,rfl⟩) - have he : (p : P) = G n := hF (hp.trans (LinearMap.congr_fun heq n).symm) - exact he ▸ p.property -end KLInvariance - -end - - -section - -namespace KLInvariance.TitsSpace -open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section -attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite - - theorem bottHeadLocalPair_coordinates (i : I) (l : List I) (x : W) : - (bottHeadPairCoordinates cs i l x).comp (bottHeadLocalPair cs i l x) = - bottWeightProjection cs (i::l) x := by - apply bottTensor_maps_eq cs i l - intro n - change bottHeadPairCoordinates cs i l x (bottHeadLocalPair cs i l x _) = _ - rw [bottHeadLocalPair_seed,bottHeadPairCoordinates_seed] - - theorem bottHeadLocalPair_mem (i : I) (l : List I) (x : W) - (m : BottSamelsonModule cs (i::l)) : - bottHeadLocalPair cs i l x m ∈ bottHeadPairLattice cs i l x := by - exact linearMap_mem_of_coordinates (bottHeadPairLattice cs i l x) - (bottHeadPairCoordinates cs i l x) (bottHeadLocalPair cs i l x) - (bottWeightProjection cs (i::l) x) (bottHeadPairCoordinates_injective cs i l x) - (bottHeadLocalPair_coordinates cs i l x) (bottHeadPair_range cs i l x) m - - theorem bottHeadLocalPair_zero_iff (i : I) (l : List I) (x : W) - (m : BottSamelsonModule cs (i::l)) : - bottStalkProjection cs (i::l) x m=0 ↔ bottHeadLocalPair cs i l x m=0 := by - constructor - · intro h - apply bottHeadPairCoordinates_injective cs i l x - rw [map_zero] - have hh := congrArg Subtype.val h - change bottWeightProjection cs (i::l) x m=0 at hh - exact (LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m).trans hh - · intro h - apply Subtype.ext - change bottWeightProjection cs (i::l) x m=0 - rw [← LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m] - change bottHeadPairCoordinates cs i l x (bottHeadLocalPair cs i l x m)=0 - rw [h,map_zero] - - theorem bottHeadLocalPair_value (i : I) (l : List I) (x : W) - (m : BottSamelsonModule cs (i::l)) : - bottHeadLocalPair cs i l x m = - (bottStalkProjection cs l x (bottHeadTail cs i l m), - Twist.mk (bottStalkProjection cs l (cs.simple i*x) (bottHeadReflectedTail cs i l m).val)) := rfl - - theorem bottHeadLocalPair_toStalk (i : I) (l : List I) (x : W) - (m : BottSamelsonModule cs (i::l)) : - bottHeadPairToStalk cs i l x ⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ = - bottStalkProjection cs (i::l) x m := by - apply Subtype.ext - exact LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m - - theorem bottHeadStalk_divisible_of_pair (i : I) (l : List I) (x : W) - (m : BottSamelsonModule cs (i::l)) (β : SymmetricCoefficient (M := M)) - (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*x))) - (hm : bottHeadLocalPair cs i l x m=β • p) (hp : p ∈ bottHeadPairLattice cs i l x) : - ∃ z : bottStalk cs (i::l) x, bottStalkProjection cs (i::l) x m=β • z := by - let z : bottHeadPairLattice cs i l x := ⟨p,hp⟩ - refine ⟨bottHeadPairToStalk cs i l x z,?_⟩ - have he : (⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ : - bottHeadPairLattice cs i l x) = β • z := Subtype.ext hm - calc - bottStalkProjection cs (i::l) x m = - bottHeadPairToStalk cs i l x ⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ := - (bottHeadLocalPair_toStalk cs i l x m).symm - _ = bottHeadPairToStalk cs i l x (β • z) := congrArg (bottHeadPairToStalk cs i l x) he - _ = β • bottHeadPairToStalk cs i l x z := map_smul _ _ _ - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.FiniteFreeScalar -universe ur um un ui -variable {R : Type ur} [CommRing R] - {M : Type um} [AddCommGroup M] [Module R M] - {ι : Type ui} [Fintype ι] (b : Module.Basis ι R M) - - - theorem exists_smul_iff (r : R) (m : M) : - (∃ n, r • n = m) ↔ ∀ i, r ∣ b.equivFun m i := by - classical - constructor - · rintro ⟨n,rfl⟩ i - exact ⟨b.equivFun n i, by simp⟩ - · intro h - choose n hn using h - refine ⟨b.equivFun.symm n,b.equivFun.injective ?_⟩ - ext i - simp only [map_smul,LinearEquiv.apply_symm_apply,Pi.smul_apply,smul_eq_mul] - exact (hn i).symm - -include b in - theorem exists_prod_smul [DecompositionMonoid R] {J : Type*} (s : Finset J) (r : J → R) - (hrel : (s : Set J).Pairwise (Function.onFun IsRelPrime r)) (m : M) - (h : ∀ j ∈ s, ∃ n, r j • n = m) : ∃ n, (∏ j ∈ s, r j) • n = m := by - apply (exists_smul_iff b _ m).mpr - intro i - apply Finset.prod_dvd_of_isRelPrime hrel - intro j hj - exact (exists_smul_iff b _ _).mp (h j hj) i - -include b in - - - theorem scalar_quotient_regular - {N : Type un} [AddCommGroup N] [Module R N] - (q : M →ₗ[R] N) (hq : Function.Surjective q) - (a r : R) (ha : Prime a) (hr : ¬ a ∣ r) - (hker : ∀ m, q m = 0 ↔ ∃ n, m=a • n) : - Function.Injective (fun v : N => r • v) := by - suffices hh : ∀ v : N, r • v = 0 → v = 0 by - intro v w hvw - change r • v = r • w at hvw - have hv : r • (v-w) = 0 := by rw [smul_sub,hvw,sub_self] - exact sub_eq_zero.mp (hh _ hv) - intro v hv - obtain ⟨m,rfl⟩ := hq v - have h0 : q (r • m) = 0 := by simpa only [map_smul] using hv - obtain ⟨n,hn⟩ := (hker _).mp h0 - have hdiv : ∀ i, a ∣ b.equivFun m i := by - intro i - have hc := congrArg (fun z => b.equivFun z i) hn - simp only [map_smul,Pi.smul_apply,smul_eq_mul] at hc - apply (ha.dvd_mul.mp ?_).resolve_left hr - exact ⟨b.equivFun n i,hc⟩ - obtain ⟨z,hz⟩ := (exists_smul_iff b a m).mpr hdiv - exact (hker m).mpr ⟨z,hz.symm⟩ - -end KLInvariance.FiniteFreeScalar - -end - - -section - -/-! Intermediate standard-filtration predicates on the genuine tensor word. -These are proved by word induction; they are not main-theorem assumptions. -/ -namespace KLInvariance.TitsSpace -open Module ReflectionFrobenius -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - def BottKernelExact (l : List I) : Prop := - ∀ (x t : W) (a : I → ℝ), Represents M cs t a → - cs.length x < cs.length (t*x) → - ∀ m : BottSamelsonModule cs l, bottStalkProjection cs l x m=0 → - ∃ z : bottStalk cs l (t*x), bottStalkProjection cs l (t*x) m= - SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z - - theorem simple_represents (i : I) : Represents M cs (cs.simple i) (root i) := by - refine ⟨1,i,?_,?_⟩ - · simp - · simp - - theorem represents_polynomial_prime {t : W} {a : I → ℝ} (ha : Represents M cs t a) : - Prime (SymmetricAlgebra.ι ℝ (Extended M) (embed M a)) := by - apply EdgeAlgebra.symmetric_ι_prime - intro h - exact ha.isRoot.ne_zero (congrArg Prod.fst h) - - theorem represents_polynomial_not_dvd {t s : W} {a b : I → ℝ} - (ha : Represents M cs t a) (hb : Represents M cs s b) (hne : t≠s) : - ¬ SymmetricAlgebra.ι ℝ (Extended M) (embed M a) ∣ - SymmetricAlgebra.ι ℝ (Extended M) (embed M b) := by - rw [EdgeAlgebra.symmetric_ι_dvd_iff] - intro h - have hi := hb.extended_independent_of_ne ha (Ne.symm hne) - obtain ⟨r,hr⟩ := Submodule.mem_span_singleton.mp h - exact (linearIndependent_fin2.mp hi).2 r hr - - theorem bottStalk_smul_injective (l : List I) (x : W) - {r : SymmetricCoefficient (M := M)} (hr : r≠0) : - Function.Injective (fun z : bottStalk cs l x => r • z) := - smul_right_injective (bottStalk cs l x) hr - - instance bottStalkFinite (l : List I) (x : W) : - Module.Finite (SymmetricCoefficient (M := M)) (bottStalk cs l x) := - Module.Finite.of_surjective (bottStalkProjection cs l x) (bottStalkProjection_surjective cs l x) - - theorem bottReflectionEdge_annihilated (l : List I) (x t : W) {a : I → ℝ} - (ha : Represents M cs t a) - (z : PairProjection.Edge (bottStalkProjection cs l x) (bottStalkProjection cs l (t*x))) : - SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z=0 := by - obtain ⟨p,hp⟩ := reflectionCoefficient_difference cs ha x - rw [← hp] - exact PairProjection.difference_annihilates _ _ - (bottStalkProjection_surjective cs _ _) (bottStalkProjection_surjective cs _ _) - (bottSamelsonRight cs l p) _ _ - (bottStalkProjection_right cs _ _ p) (bottStalkProjection_right cs _ _ p) z - - theorem BottKernelExact.upper_kernel {l : List I} (H : BottKernelExact cs l) - (x t : W) {a : I → ℝ} (ha : Represents M cs t a) - (hlt : cs.length x < cs.length (t*x)) (z : bottStalk cs l (t*x)) : - PairProjection.upper (bottStalkProjection cs l x) (bottStalkProjection cs l (t*x)) z=0 ↔ - ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := - PairProjection.upper_kernel_of_divisibility _ _ _ (H x t a ha hlt) - (bottReflectionEdge_annihilated cs l x t ha) z - - theorem BottKernelExact.kernel_iff {l : List I} (H : BottKernelExact cs l) - (x t : W) {a : I → ℝ} (ha : Represents M cs t a) - (hlt : cs.length x < cs.length (t*x)) (z : bottStalk cs l (t*x)) : - (∃ m, bottStalkProjection cs l x m=0 ∧ bottStalkProjection cs l (t*x) m=z) ↔ - ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by - rw [← PairProjection.kernel_upper] - exact H.upper_kernel cs x t ha hlt z - - theorem BottKernelExact.kernel_iff_of_mul {l : List I} (H : BottKernelExact cs l) - (x y t : W) {a : I → ℝ} (ha : Represents M cs t a) (hxy : t*x=y) - (hlt : cs.length x < cs.length y) (z : bottStalk cs l y) : - (∃ m, bottStalkProjection cs l x m=0 ∧ bottStalkProjection cs l y m=z) ↔ - ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by - subst y - exact H.kernel_iff cs x t ha hlt z - - theorem BottKernelExact.projection_of_mul {l : List I} (H : BottKernelExact cs l) - (x y t : W) {a : I → ℝ} (ha : Represents M cs t a) (hxy : t*x=y) - (hlt : cs.length x < cs.length y) (m : BottSamelsonModule cs l) - (hm : bottStalkProjection cs l x m=0) : - ∃ z : bottStalk cs l y, bottStalkProjection cs l y m= - SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z := by - subst y - exact H x t a ha hlt m hm - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.TitsSpace -open Module ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - theorem bottSimpleEdge_regular (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (x : W) (β : SymmetricCoefficient (M := M)) (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) : - Function.Injective (fun e : PairProjection.Edge (bottStalkProjection cs l x) - (bottStalkProjection cs l (cs.simple i*x)) => β • e) := by - have hα : Prime (simpleRootPolynomial (M := M) i) := - represents_polynomial_prime cs (simple_represents cs i) - rcases lt_or_gt_of_ne (cs.length_simple_mul_ne x i) with hdesc | hasc - · let := F x - apply FiniteFreeScalar.scalar_quotient_regular - (Module.Free.chooseBasis (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (PairProjection.lower (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x))) - (PairProjection.lower_surjective _ _ (bottStalkProjection_surjective cs l (cs.simple i*x))) - (simpleRootPolynomial (M := M) i) β hα hβ - intro z - rw [PairProjection.kernel_lower] - have hh := H.kernel_iff_of_mul cs (cs.simple i*x) x (cs.simple i) - (simple_represents cs i) (cs.simple_mul_simple_cancel_left i) hdesc z - simpa only [and_comm,simpleRootPolynomial,extendedRoot] using hh - · let := F (cs.simple i*x) - exact FiniteFreeScalar.scalar_quotient_regular - (Module.Free.chooseBasis (SymmetricCoefficient (M := M)) (bottStalk cs l (cs.simple i*x))) - (PairProjection.upper (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x))) - (PairProjection.upper_surjective _ _ (bottStalkProjection_surjective cs l x)) - (simpleRootPolynomial (M := M) i) β hα hβ - (H.upper_kernel cs x (cs.simple i) (simple_represents cs i) hasc) - - theorem bottHeadPairLattice_saturated (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (x : W) (β : SymmetricCoefficient (M := M)) (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) - (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*x))) : - β • p ∈ bottHeadPairLattice cs i l x ↔ p ∈ bottHeadPairLattice cs i l x := - lattice_saturated (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) - (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) - (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) - β (bottSimpleEdge_annihilated cs i l x) (bottSimpleEdge_regular cs i l H F x β hβ) p - -end -end KLInvariance.TitsSpace - -end - - -section - - -namespace KLInvariance.TitsSpace -open Module ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - theorem bottHeadStalk_divisible (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (x : W) (m : BottSamelsonModule cs (i::l)) (β : SymmetricCoefficient (M := M)) - (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) - (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*x))) - (hm : bottHeadLocalPair cs i l x m=β • p) : - ∃ z : bottStalk cs (i::l) x, bottStalkProjection cs (i::l) x m=β • z := by - have hp := bottHeadLocalPair_mem cs i l x m - have hp' : β • p ∈ bottHeadPairLattice cs i l x := hm ▸ hp - exact bottHeadStalk_divisible_of_pair cs i l x m β p hm - ((bottHeadPairLattice_saturated cs i l H F x β hβ p).mp hp') - - theorem bottKernelExact_cons_nonhead (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (x t : W) (a : I → ℝ) (ha : Represents M cs t a) - (hlt : cs.length x < cs.length (t*x)) (hts : t≠cs.simple i) - (m : BottSamelsonModule cs (i::l)) (hm : bottStalkProjection cs (i::l) x m=0) : - ∃ z : bottStalk cs (i::l) (t*x), bottStalkProjection cs (i::l) (t*x) m= - SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z := by - have he : t*x≠cs.simple i*x := fun h => hts (mul_right_cancel h) - have hstep : BruhatStep cs x (t*x) := ⟨hlt,t,ha.isReflection,rfl⟩ - have hstep' := bruhatStep_simple_mul cs hstep i he - have hconj : (cs.simple i*t*(cs.simple i)⁻¹)*(cs.simple i*x)=cs.simple i*(t*x) := by group - have hzero := (bottHeadLocalPair_zero_iff cs i l x m).mp hm - have hμ : bottStalkProjection cs l x (bottHeadTail cs i l m)=0 := congrArg Prod.fst hzero - have hν : bottStalkProjection cs l (cs.simple i*x) (bottHeadReflectedTail cs i l m).val=0 := - congrArg (fun p => p.2.val) hzero - obtain ⟨p,hp⟩ := H x t a ha hlt (bottHeadTail cs i l m) hμ - obtain ⟨q,hq⟩ := H.projection_of_mul cs (cs.simple i*x) (cs.simple i*(t*x)) - (cs.simple i*t*(cs.simple i)⁻¹) (ha.act (cs.simple i)) hconj hstep'.1 - (bottHeadReflectedTail cs i l m).val hν - let β : SymmetricCoefficient (M := M) := SymmetricAlgebra.ι ℝ (Extended M) (embed M a) - let p' : bottStalk cs l (t*x) × Twist (coefficientAction cs (cs.simple i)).toRingEquiv - (bottStalk cs l (cs.simple i*(t*x))) := (p,⟨q⟩) - have hβ' : coefficientAction cs (cs.simple i) β = - SymmetricAlgebra.ι ℝ (Extended M) (embed M (action M cs (cs.simple i) a)) := by - rw [coefficientAction_ι,extendedAction_restrict] - have heq : bottHeadLocalPair cs i l (t*x) m=β • p' := by - apply Prod.ext - · exact hp - · apply Twist.ext - change bottStalkProjection cs l (cs.simple i*(t*x)) - (bottHeadReflectedTail cs i l m).val = coefficientAction cs (cs.simple i) β • q - rw [hβ'] - exact hq - have hn : ¬simpleRootPolynomial (M := M) i ∣ β := - represents_polynomial_not_dvd cs (simple_represents cs i) ha (Ne.symm hts) - exact bottHeadStalk_divisible cs i l H F (t*x) m β hn p' heq - - theorem bottKernelExact_cons (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) : - BottKernelExact cs (i::l) := by - intro x t a ha hlt m hm - by_cases hts : t=cs.simple i - · subst t - obtain ⟨z,hz⟩ := bottSimpleWall_kernel_projection cs i l x hm - rcases ha.unique_up_to_sign (simple_represents cs i) with h|h - · subst a - exact ⟨z,hz⟩ - · subst a - refine ⟨-z,?_⟩ - rw [hz] - change simpleRootPolynomial (M := M) i • z = - SymmetricAlgebra.ι ℝ (Extended M) (embed M (-root i)) • (-z) - have he : embed M (-root i) = -embed M (root i) := by simp [embed] - have hn : SymmetricAlgebra.ι ℝ (Extended M) (embed M (-root i)) = - -simpleRootPolynomial (M := M) i := by - rw [he] - exact (SymmetricAlgebra.ι ℝ (Extended M)).map_neg _ - rw [hn] - exact (neg_smul_neg _ z).symm - · exact bottKernelExact_cons_nonhead cs i l H F x t a ha hlt hts m hm - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.ReflectionPairTranslation -universe u v w z -variable {R : Type u} [CommRing R] - {N : Type v} [AddCommGroup N] [Module R N] - {X : Type w} [AddCommGroup X] [Module R X] - {Y : Type z} [AddCommGroup Y] [Module R Y] - (f : N →ₗ[R] X) (g : N →ₗ[R] Y) (τ : R ≃+* R) (α : R) - (hdiv : ∀ r : R, α ∣ τ r-r) - (hinc : ∀ y : Y, ∃ n : N, f n=0 ∧ g n=α • y) - (hker : ∀ x : X, (∃ n : N, f n=x ∧ g n=0) ↔ ∃ z : X, x=α • z) - - def right : lattice f g τ α hdiv hinc →ₗ[R] Twist τ Y := - (LinearMap.snd R X (Twist τ Y)).comp (lattice f g τ α hdiv hinc).subtype - - theorem right_surjective (hg : Function.Surjective g) : - Function.Surjective (right f g τ α hdiv hinc) := by - intro y - obtain ⟨n,hn⟩ := hg y.val - exact ⟨⟨(f n,y),n,rfl,hn⟩,rfl⟩ - - def rightKernelMap : X →ₗ[R] LinearMap.ker (right f g τ α hdiv hinc) where - toFun x := ⟨⟨(α • x,⟨0⟩),(hker (α • x)).mpr ⟨x,rfl⟩⟩,rfl⟩ - map_add' x y := by - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · exact smul_add α x y - · apply Twist.ext - exact (zero_add (0 : Y)).symm - map_smul' r x := by - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · exact smul_comm α r x - · apply Twist.ext - exact (smul_zero _).symm - - theorem rightKernelMap_surjective : - Function.Surjective (rightKernelMap f g τ α hdiv hinc hker) := by - rintro ⟨⟨⟨x,y⟩,n,hn,hn'⟩,hy⟩ - have hy' : y.val=0 := congrArg Twist.val hy - obtain ⟨z,hz⟩ := (hker x).mp ⟨n,hn,hn'.trans hy'⟩ - refine ⟨z,?_⟩ - apply Subtype.ext - apply Subtype.ext - exact Prod.ext hz.symm (Twist.ext hy'.symm) - - theorem rightKernelMap_injective (hinj : Function.Injective (fun x : X => α • x)) : - Function.Injective (rightKernelMap f g τ α hdiv hinc hker) := by - intro x y h - exact hinj (congrArg (fun p => p.val.val.1) h) - - noncomputable def rightKernelEquiv (hinj : Function.Injective (fun x : X => α • x)) : - X ≃ₗ[R] LinearMap.ker (right f g τ α hdiv hinc) := - LinearEquiv.ofBijective (rightKernelMap f g τ α hdiv hinc hker) - ⟨rightKernelMap_injective f g τ α hdiv hinc hker hinj, - rightKernelMap_surjective f g τ α hdiv hinc hker⟩ - - include hker in - theorem lattice_free_right (hg : Function.Surjective g) - (hinj : Function.Injective (fun x : X => α • x)) - [Module.Free R X] [Module.Free R Y] : - Module.Free R (lattice f g τ α hdiv hinc) := by - let : Module.Free R (LinearMap.ker (right f g τ α hdiv hinc)) := - Module.Free.of_equiv (rightKernelEquiv f g τ α hdiv hinc hker hinj) - exact free_of_surjective_of_ker_free (right f g τ α hdiv hinc) - (right_surjective f g τ α hdiv hinc hg) -end KLInvariance.ReflectionPairTranslation - -end - - -section - -namespace KLInvariance.TitsSpace -open Module ReflectionFrobenius ReflectionPairTranslation -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - theorem bottStalk_free_cons (i : I) (l : List I) - (H : BottKernelExact cs l) - (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) - (x : W) : Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs (i::l) x) := by - let := F x - let := F (cs.simple i*x) - have hα : simpleRootPolynomial (M := M) i ≠ 0 := - (represents_polynomial_prime cs (simple_represents cs i)).ne_zero - have hlattice : Module.Free (SymmetricCoefficient (M := M)) (bottHeadPairLattice cs i l x) := by - rcases lt_or_gt_of_ne (cs.length_simple_mul_ne x i) with hdesc | hasc - · apply lattice_free_right - (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) - (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) - (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) - · intro z - have hh := H.kernel_iff_of_mul cs (cs.simple i*x) x (cs.simple i) - (simple_represents cs i) (cs.simple_mul_simple_cancel_left i) hdesc z - simpa only [and_comm,simpleRootPolynomial,extendedRoot] using hh - · exact bottStalkProjection_surjective cs l (cs.simple i*x) - · exact bottStalk_smul_injective cs l x hα - · exact lattice_free (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) - (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) - (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) - (H.kernel_iff cs x (cs.simple i) (simple_represents cs i) hasc) - (bottStalkProjection_surjective cs l x) - (bottStalk_smul_injective cs l (cs.simple i*x) hα) - let := hlattice - exact Module.Free.of_equiv (bottHeadPairEquiv cs i l x) - - theorem bottStalk_nil_subsingleton (x : W) (hx : x≠1) : Subsingleton (bottStalk cs [] x) := by - constructor - intro p q - apply Subtype.ext - funext e - exact False.elim (hx e.property.symm) - - theorem bottStalk_nil_free (x : W) : - Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs [] x) := by - by_cases hx : x=1 - · subst x - exact Module.Free.of_equiv (bottTopStalkEquiv cs [] (by simp [CoxeterSystem.IsReduced])).symm - · let := bottStalk_nil_subsingleton cs x hx - infer_instance - - theorem bottKernelExact_nil : BottKernelExact cs [] := by - intro x t a ha hlt m hm - have hx : t*x≠1 := by - intro h - rw [h] at hlt - rw [cs.length_one] at hlt - exact Nat.not_lt_zero _ hlt - let := bottStalk_nil_subsingleton cs (t*x) hx - exact ⟨0,Subsingleton.elim _ _⟩ - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Pair-projection edges of actual finite graded modules. The hypotheses say -only that the two actual weight projections are homogeneous and surjective. -/ -namespace KLInvariance.Graded.ModuleData -open PairProjection -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {M X Y : ModuleData.{uk,ua,um} 𝓐} - (f : Hom M X) (g : Hom M Y) -noncomputable section - - theorem pairLower_kernel_homogeneous (n : ℤ) (z : X) - (hz : lower f.map g.map z=0) : - lower f.map g.map (component X.piece n z)=0 := by - obtain ⟨m,hm,hy⟩ := (kernel_lower f.map g.map z).mp hz - apply (kernel_lower f.map g.map _).mpr - refine ⟨component M.piece n m,?_,?_⟩ - · rw [← f.component,hm] - · rw [← g.component,hy,map_zero] - - def pairEdgePiece (n : ℤ) : Submodule k (Edge f.map g.map) := - (X.piece n).map ((lower f.map g.map).restrictScalars k) - - def pairEdge (hg : Function.Surjective g.map) : ModuleData.{uk,ua,um} 𝓐 where - obj := ModuleCat.of A (Edge f.map g.map) - kModule := inferInstance - tower := inferInstance - piece := pairEdgePiece f g - decomposition := (image_isInternal X.piece ((lower f.map g.map).restrictScalars k) - (lower_surjective f.map g.map hg) (pairLower_kernel_homogeneous f g)).chooseDecomposition - graded := ⟨by - rintro i j a z ha ⟨w,hw,rfl⟩ - exact ⟨a • w,SetLike.GradedSMul.smul_mem ha hw,map_smul (lower f.map g.map) a w⟩⟩ - nonneg := by - intro n hn - unfold pairEdgePiece - rw [X.nonneg n hn,Submodule.map_bot] - finite := Module.Finite.of_surjective (lower f.map g.map) (lower_surjective f.map g.map hg) - - def pairLower (hg : Function.Surjective g.map) : Hom X (pairEdge f g hg) where - map := lower f.map g.map - graded := fun _ z hz => ⟨z,hz,rfl⟩ - - theorem Hom.homogeneous_lift (hg : Function.Surjective g.map) (n : ℤ) - (y : Y) (hy : y ∈ Y.piece n) : ∃ m : M, m ∈ M.piece n ∧ g.map m=y := by - obtain ⟨m,hm⟩ := hg y - refine ⟨Graded.component M.piece n m,(DirectSum.decompose M.piece m n).property,?_⟩ - rw [← g.component,hm] - exact DirectSum.decompose_of_mem_same Y.piece hy - - def pairUpper (hg : Function.Surjective g.map) : Hom Y (pairEdge f g hg) where - map := upper f.map g.map - graded := by - intro n y hy - obtain ⟨m,hm,rfl⟩ := g.homogeneous_lift hg n y hy - exact ⟨f.map m,f.graded n m hm,compatible f.map g.map m⟩ - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -/-! The genuine projection WORD sheaf with its nonnegative grading and finite -integral stalk/edge modules. No free-stalk, flabbiness, or KL character claim -is smuggled into the grading. The universe here contains both the finite -Coxeter matrix and its standard Coxeter group, as needed by the main reduction. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - -omit [Fintype σ] in - theorem bottStalkPiece_negative (l : List I) (x : W) (n : ℤ) (hn : n<0) : - bottStalkPiece cs basis l x n=⊥ := by - apply subPiece_eq_bot - exact piPiece_eq_bot (fun _ => symmetricGrading basis) n - (fun _ => symmetricGrading_negative basis n hn) - - def bottStalkData (l : List I) (x : W) : ModuleData.{0,u,u} (symmetricGrading basis) where - obj := ModuleCat.of _ (bottStalk cs l x) - kModule := inferInstance - tower := inferInstance - piece := bottStalkPiece cs basis l x - decomposition := inferInstance - graded := inferInstance - nonneg := bottStalkPiece_negative cs basis l x - finite := Module.Finite.of_surjective (bottStalkProjection cs l x) - (bottStalkProjection_surjective cs l x) - - theorem bottPiece_negative (l : List I) (n : ℤ) (hn : n<0) : - bottPiece cs basis l n=⊥ := by - apply bot_unique - intro m hm - change m=0 - apply bottEvaluation_injective cs l - funext e - have h := bottEvaluation_homogeneous cs basis l e n m hm - rw [symmetricGrading_negative basis n hn,Submodule.mem_bot] at h - exact h.trans (map_zero (bottEvaluation cs l e)).symm - - def bottWordData (l : List I) : ModuleData.{0,u,u} (symmetricGrading basis) where - obj := ModuleCat.of _ (BottSamelsonModule cs l) - kModule := inferInstance - tower := inferInstance - piece := bottPiece cs basis l - decomposition := inferInstance - graded := inferInstance - nonneg := bottPiece_negative cs basis l - finite := inferInstance - - def bottStalkHom (l : List I) (x : W) : - ModuleData.Hom (bottWordData cs basis l) (bottStalkData cs basis l x) where - map := bottStalkProjection cs l x - graded := bottStalkProjection_homogeneous cs basis l x - - theorem bottStalkHom_surjective (l : List I) (x : W) : - Function.Surjective (bottStalkHom cs basis l x).map := - bottStalkProjection_surjective cs l x - - def bottEdgeData (l : List I) (x y : W) : ModuleData.{0,u,u} (symmetricGrading basis) := - ModuleData.pairEdge (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) - (bottStalkHom_surjective cs basis l y) - - def bottLowerHom (l : List I) (x y : W) : - ModuleData.Hom (bottStalkData cs basis l x) (bottEdgeData cs basis l x y) := - ModuleData.pairLower (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) - (bottStalkHom_surjective cs basis l y) - - def bottUpperHom (l : List I) (x y : W) : - ModuleData.Hom (bottStalkData cs basis l y) (bottEdgeData cs basis l x y) := - ModuleData.pairUpper (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) - (bottStalkHom_surjective cs basis l y) - - def bottGradedProjectionSheaf (l : List I) (u b : W) : - GradedSheaf (𝓐 := symmetricGrading basis) (graph cs u b) where - vertex x := bottStalkData cs basis l x.val - edge e := bottEdgeData cs basis l (source cs u b e).val (target cs u b e).val - lower e := bottLowerHom cs basis l (source cs u b e).val (target cs u b e).val - upper e := bottUpperHom cs basis l (source cs u b e).val (target cs u b e).val - - theorem bottGradedProjectionSheaf_forget (l : List I) (u b : W) : - (bottGradedProjectionSheaf cs basis l u b).forget=bottProjectionSheaf cs l u b := rfl - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Unconditional integral free stalks and exact oriented edge kernels for -all tensor words. These are the local parts of BMP recognition; flabbiness -and the KL character are not asserted here. -/ -namespace KLInvariance.TitsSpace -open Module MomentGraph BruhatGraph -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) -noncomputable section - - theorem bottStandardStalks (l : List I) : - BottKernelExact cs l ∧ ∀ x : W, - Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x) := by - induction l with - | nil => exact ⟨bottKernelExact_nil cs,bottStalk_nil_free cs⟩ - | cons i l h => exact ⟨bottKernelExact_cons cs i l h.1 h.2, - bottStalk_free_cons cs i l h.1 h.2⟩ - - theorem bottKernelExact (l : List I) : BottKernelExact cs l := (bottStandardStalks cs l).1 - - instance bottStalkFree (l : List I) (x : W) : - Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x) := - (bottStandardStalks cs l).2 x - - theorem bottProjectionSheaf_upper_kernel (l : List I) (u b : W) (e : Edge cs u b) - {a : I → ℝ} (ha : Represents M cs (label cs u b e) a) - (z : (bottProjectionSheaf cs l u b).vertex (target cs u b e)) : - (bottProjectionSheaf cs l u b).upper e z=0 ↔ - ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by - change PairProjection.upper (bottStalkProjection cs l (source cs u b e).val) - (bottStalkProjection cs l (target cs u b e).val) z=0 ↔ _ - exact (PairProjection.kernel_upper _ _ z).trans - ((bottKernelExact cs l).kernel_iff_of_mul cs _ _ _ ha - (label_mul_source cs u b e) e.property.1 z) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Transport of actual linear-map kernels along a source isomorphism. -/ -namespace KLInvariance -universe ur um un up -variable {R : Type ur} [Ring R] - {M : Type um} [AddCommGroup M] [Module R M] - {N : Type un} [AddCommGroup N] [Module R N] - {P : Type up} [AddCommGroup P] [Module R P] - -def kernelSourceEquiv (f : M →ₗ[R] P) (e : M ≃ₗ[R] N) : - LinearMap.ker f ≃ₗ[R] LinearMap.ker (f.comp e.symm.toLinearMap) where - toFun x := ⟨e x.val,by simpa only [LinearMap.mem_ker,LinearMap.comp_apply, - LinearEquiv.coe_coe,LinearEquiv.symm_apply_apply] using x.property⟩ - invFun y := ⟨e.symm y.val,y.property⟩ - left_inv x := Subtype.ext (e.symm_apply_apply x.val) - right_inv y := Subtype.ext (e.apply_symm_apply y.val) - map_add' x y := Subtype.ext (map_add e x.val y.val) - map_smul' r x := Subtype.ext (map_smul e r x.val) - -end KLInvariance - -end - - -section - -/-! The actual ascent short exact sequence of word stalks has kernel the -upper tail stalk shifted by one. This is the degree-one Hecke normalization. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def bottHeadKernelEquiv (i : I) (l : List I) (x : W) - (h : cs.length x ⟨v.val.val,v.property⟩ - map_add' := fun _ _ => rfl - map_smul' := fun _ _ => rfl } - apply Module.Finite.of_injective f - intro v w h - apply Subtype.ext - apply Subtype.ext - exact congrArg (fun z : 𝓜 n => z.val) h - - variable {ι : Type ui} [Finite ι] {P : ι → Type um} - [∀ i, AddCommGroup (P i)] [∀ i, Module k (P i)] - - instance piPiece_finite (𝓟 : ∀ i, ℤ → Submodule k (P i)) (n : ℤ) - [∀ i, Module.Finite k (𝓟 i n)] : Module.Finite k (piPiece 𝓟 n) := by - let f : piPiece 𝓟 n →ₗ[k] (∀ i, 𝓟 i n) := - { toFun := fun v i => ⟨v.val i,v.property i (Set.mem_univ i)⟩ - map_add' := fun _ _ => rfl - map_smul' := fun _ _ => rfl } - apply Module.Finite.of_injective f - intro v w h - apply Subtype.ext - funext i - exact congrArg Subtype.val (congrFun h i) - -end KLInvariance.Graded - -end - - -section - -/-! The genuine Bott--Samelson stalk Hilbert coefficients satisfy the simple -reflection ascent recurrence. Both exactness and the degree-one kernel shift -were constructed integrally above; no KL character theorem is assumed. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - instance symmetricGrading_finite (n : ℤ) : Module.Finite ℝ (symmetricGrading basis n) := - inferInstanceAs (Module.Finite ℝ ((polynomialGrading ℝ σ n).map - (SymmetricAlgebra.equivMvPolynomial basis).symm.toLinearMap)) - - instance bottCoordinatePiece_finite (l : List I) (x : W) (n : ℤ) : - Module.Finite ℝ (bottCoordinatePiece cs basis l x n) := by - classical - exact piPiece_finite _ n - - instance bottStalkPiece_finite (l : List I) (x : W) (n : ℤ) : - Module.Finite ℝ (bottStalkPiece cs basis l x n) := - inferInstanceAs (Module.Finite ℝ (subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x) n)) - - theorem bottStalk_finrank_ascent (i : I) (l : List I) (x : W) - (h : cs.length x rfl } : CoefficientChange e M ≃+ M).module B - instance : Module k (CoefficientChange e M) := - ({ equivVal e M with map_add' := fun _ _ => rfl } : CoefficientChange e M ≃+ M).module k - instance : IsScalarTower k B (CoefficientChange e M) where - smul_assoc c b m := by - apply CoefficientChange.ext - change e.symm (c • b) • m.val=c • (e.symm b • m.val) - rw [map_smul,smul_assoc] - - local instance : RingHomInvPair e.symm.toRingHom e.toRingHom := RingHomInvPair.of_ringEquiv_symm e.toRingEquiv - local instance : RingHomInvPair e.toRingHom e.symm.toRingHom := RingHomInvPair.of_ringEquiv e.toRingEquiv - - def equiv : M ≃ₛₗ[e.toRingHom] CoefficientChange e M where - toFun := mk - invFun := val - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' a m := by - change mk (a • m)=mk (e.symm (e a) • m) - rw [e.symm_apply_apply] - - def kEquiv : M ≃ₗ[k] CoefficientChange e M where - toFun := mk - invFun := val - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - - instance [Module.Free A M] : Module.Free B (CoefficientChange e M) := - Module.Free.of_equiv (equiv e M) - instance [Module.Finite A M] : Module.Finite B (CoefficientChange e M) := - Module.Finite.of_surjective (equiv e M).toLinearMap (equiv e M).surjective - - variable {M} {N : Type un} [AddCommGroup N] [Module A N] [Module k N] [IsScalarTower k A N] - def map (f : M →ₗ[A] N) : CoefficientChange e M →ₗ[B] CoefficientChange e N where - toFun m := mk (f m.val) - map_add' m n := CoefficientChange.ext (map_add f m.val n.val) - map_smul' b m := CoefficientChange.ext (map_smul f (e.symm b) m.val) - - omit [Module k M] [IsScalarTower k A M] [Module k N] [IsScalarTower k A N] in - theorem map_injective (f : M →ₗ[A] N) (hf : Function.Injective f) : - Function.Injective (map e f) := fun _m _n h => CoefficientChange.ext (hf (congrArg val h)) - omit [Module k M] [IsScalarTower k A M] [Module k N] [IsScalarTower k A N] in - theorem map_surjective (f : M →ₗ[A] N) (hf : Function.Surjective f) : - Function.Surjective (map e f) := by - intro n - obtain ⟨m,hm⟩ := hf n.val - exact ⟨mk m,CoefficientChange.ext hm⟩ - -end CoefficientChange -end KLInvariance - -end - - -section - -/-! Grading-preserving coefficient change on the actual finite modules. -/ -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) -noncomputable section - - def changePiece (M : ModuleData.{uk,ua,um} 𝓐) : ℤ → Submodule k (CoefficientChange e M) := - fun n => (M.piece n).map (CoefficientChange.kEquiv e M).toLinearMap - - theorem mem_changePiece (M : ModuleData.{uk,ua,um} 𝓐) (n : ℤ) (m : CoefficientChange e M) : - m ∈ changePiece e M n ↔ m.val ∈ M.piece n := by - constructor - · rintro ⟨x,hx,hxm⟩ - change CoefficientChange.mk x=m at hxm - exact (congrArg CoefficientChange.val hxm) ▸ hx - · intro hm - exact ⟨m.val,hm,rfl⟩ - - def change (M : ModuleData.{uk,ua,um} 𝓐) : ModuleData.{uk,ua,um} 𝓑 where - obj := ModuleCat.of B (CoefficientChange e M) - kModule := inferInstance - tower := inferInstance - piece := changePiece e M - decomposition := by - apply DirectSum.IsInternal.chooseDecomposition - apply image_isInternal M.piece (CoefficientChange.kEquiv e M).toLinearMap - (CoefficientChange.kEquiv e M).surjective - intro n m hm - have hz : m=0 := congrArg CoefficientChange.val hm - subst m - simp only [map_zero] - graded := by - constructor - intro i j b m hb hm - apply (mem_changePiece e M (i+j) _).mpr - change e.symm b • m.val ∈ M.piece (i+j) - have ha : e.symm b ∈ 𝓐 i := (he i _).mpr (by simpa using hb) - exact SetLike.GradedSMul.smul_mem ha ((mem_changePiece e M j m).mp hm) - nonneg n hn := by simp only [changePiece,M.nonneg n hn,Submodule.map_bot] - finite := inferInstance - - def changeHom {M N : ModuleData.{uk,ua,um} 𝓐} (f : Hom M N) : - Hom (change e he M) (change e he N) where - map := CoefficientChange.map e f.map - graded n m hm := (mem_changePiece e N n _).mpr - (f.graded n m.val ((mem_changePiece e M n m).mp hm)) - - theorem change_free (M : ModuleData.{uk,ua,um} 𝓐) [Module.Free A M] : - Module.Free B (change e he M) := inferInstanceAs (Module.Free B (CoefficientChange e M)) - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -/-! The genuine nonnegative polynomial generator character of word stalks, -with its convergent Hilbert-series interpretation. No KL identification is -asserted or included in the definition. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def bottPolynomialStalkData (l : List I) (x : W) : - ModuleData.{0,u,u} (polynomialGrading ℝ σ) := - ModuleData.change (SymmetricAlgebra.equivMvPolynomial basis) (mem_symmetricGrading basis) - (bottStalkData cs basis l x) - - instance bottPolynomialStalkFree (l : List I) (x : W) : - Module.Free (MvPolynomial σ ℝ) (bottPolynomialStalkData cs basis l x) := - inferInstanceAs (Module.Free (MvPolynomial σ ℝ) - (CoefficientChange (SymmetricAlgebra.equivMvPolynomial basis) (bottStalk cs l x))) - - def bottStalkCharacter (l : List I) (x : W) : Polynomial ℤ := - Graded.character (σ := σ) (bottPolynomialStalkData cs basis l x).piece - (bottPolynomialStalkData cs basis l x).nonneg - - theorem bottPolynomialStalk_finrank (l : List I) (x : W) (n : ℤ) : - Module.finrank ℝ ((bottPolynomialStalkData cs basis l x).piece n)= - Module.finrank ℝ (bottStalkPiece cs basis l x n) := - LinearEquiv.finrank_map_eq - (CoefficientChange.kEquiv (SymmetricAlgebra.equivMvPolynomial basis) - (bottStalkData cs basis l x)) _ - - theorem bottStalkCharacter_hasSum (l : List I) (x : W) {q : ℝ} - (hq : 0 (Module.finrank ℝ (bottStalkPiece cs basis l x n) : ℝ)*q^n) - (Polynomial.eval₂ (Int.castRingHom ℝ) q (bottStalkCharacter cs basis l x) * - (1-q)⁻¹ ^ Fintype.card σ) := by - have hh := (exists_nonnegativeBasis (k := ℝ) (σ := σ) (𝓜 := (bottPolynomialStalkData cs basis l x).piece) - (bottPolynomialStalkData cs basis l x).nonneg).some.hasSum hq hq1 - apply hh.congr_fun - intro n - rw [bottPolynomialStalk_finrank] - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance -universe ur um un up -variable {R : Type ur} [Ring R] - {M : Type um} [AddCommGroup M] [Module R M] - {N : Type un} [AddCommGroup N] [Module R N] - {P : Type up} [AddCommGroup P] [Module R P] - -def kernelTargetEquiv (f : M →ₗ[R] N) (e : N ≃ₗ[R] P) : - LinearMap.ker f ≃ₗ[R] LinearMap.ker (e.toLinearMap.comp f) where - toFun x := ⟨x.val, by - change e (f x.val)=0 - rw [LinearMap.mem_ker.mp x.property,map_zero]⟩ - invFun y := ⟨y.val, by - apply e.injective - simpa only [LinearMap.comp_apply,LinearEquiv.coe_coe,map_zero] using (LinearMap.mem_ker.mp y.property)⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - -end KLInvariance - -end - - -section - -namespace KLInvariance -universe uk ua um un up uq -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {M : Type um} [AddCommGroup M] [Module k M] [Module A M] [IsScalarTower k A M] - {N : Type un} [AddCommGroup N] [Module k N] [Module A N] [IsScalarTower k A N] - {P : Type up} [AddCommGroup P] [Module k P] [Module A P] [IsScalarTower k A P] - {Q : Type uq} [AddCommGroup Q] [Module k Q] - -def kernelMixedEquiv (f : M →ₗ[A] P) (e : M ≃ₗ[A] N) (g : P ≃ₗ[k] Q) : - LinearMap.ker f ≃ₗ[k] LinearMap.ker - (g.toLinearMap.comp ((f.comp e.symm.toLinearMap).restrictScalars k)) where - toFun x := ⟨e x.val, by - change g (f (e.symm (e x.val)))=0 - rw [e.symm_apply_apply,LinearMap.mem_ker.mp x.property,map_zero]⟩ - invFun y := ⟨e.symm y.val, by - apply g.injective - have hy : g (f (e.symm y.val))=0 := y.property - simpa only [map_zero] using hy⟩ - left_inv x := Subtype.ext (e.symm_apply_apply x.val) - right_inv y := Subtype.ext (e.apply_symm_apply y.val) - map_add' x y := Subtype.ext (map_add e x.val y.val) - map_smul' c x := Subtype.ext (map_smul (e.restrictScalars k) c x.val) - -end KLInvariance - -end - - -section - -/-! The descent short exact sequence for the actual word projection lattice. -Its kernel has the genuine degree-one shift, over the unchanged realization. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottHeadRight_surjective (i : I) (l : List I) (x : W) : - Function.Surjective (bottHeadRight cs i l x) := - (Twist.scalarEquiv (coefficientAction cs (cs.simple i)) _).surjective.comp - ((right_surjective _ _ _ _ _ _ (bottStalkProjection_surjective cs l (cs.simple i*x))).comp - (bottHeadPairEquiv cs i l x).symm.surjective) - - theorem bottDescentKernel (i : I) (l : List I) (x : W) - (h : cs.length (cs.simple i*x) rw [map_add]; exact (LinearMap.range G).add_mem hm hn + | tmul a n => + have he : a ⊗ₜ[C] n = a • ((1 : A) ⊗ₜ[C] n) := by + rw [TensorProduct.smul_tmul', smul_eq_mul,mul_one] + rw [he,map_smul] + exact (LinearMap.range G).smul_mem a (h n) + theorem tensor_maps_eq_of_one_tmul (F G : (A ⊗[C] N) →ₗ[A] V) + (h : ∀ n : N, F ((1 : A) ⊗ₜ[C] n)=G ((1 : A) ⊗ₜ[C] n)) : F=G := by + apply LinearMap.ext + intro m + induction m using TensorProduct.inductionOn with + | add m n hm hn => rw [map_add,map_add,hm,hn] + | tmul a n => + have he : a ⊗ₜ[C] n = a • ((1 : A) ⊗ₜ[C] n) := by + rw [TensorProduct.smul_tmul',smul_eq_mul,mul_one] + rw [he,map_smul,map_smul,h n] + + theorem codRestrict_surjective_of_range_le (G : P →ₗ[A] V) (S : Submodule A V) + (hG : ∀ p, G p ∈ S) (hS : S ≤ LinearMap.range G) : + Function.Surjective (LinearMap.codRestrict S G hG) := by + intro z + obtain ⟨p,hp⟩ := hS z.property + exact ⟨p,Subtype.ext hp⟩ +end KLInvariance + +end + + +section + +namespace KLInvariance.TitsSpace +open Module TensorProduct FrobeniusDuality ReflectionFrobenius +universe u v up +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section +attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite + theorem bottWeightProjection_range_le (i : I) (l : List I) (x : W) + {P : Type up} [AddCommGroup P] [Module (SymmetricCoefficient (M := M)) P] + (G : P →ₗ[SymmetricCoefficient (M := M)] + ({e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M))) + (h : ∀ n : BottSamelsonModule cs l, + bottWeightProjection cs (i::l) x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n) ∈ LinearMap.range G) : + LinearMap.range (bottWeightProjection cs (i::l) x) ≤ LinearMap.range G := by + exact tensor_range_le_of_one_tmul (C := simpleFixed cs i) + (A := SymmetricCoefficient (M := M)) (N := BottSamelsonModule cs l) + (bottWeightProjection cs (i::l) x) G h + theorem bottTensor_maps_eq (i : I) (l : List I) + {P : Type up} [AddCommGroup P] [Module (SymmetricCoefficient (M := M)) P] + (F G : BottSamelsonModule cs (i::l) →ₗ[SymmetricCoefficient (M := M)] P) + (h : ∀ n : BottSamelsonModule cs l, + F ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)= + G ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)) : F=G := + tensor_maps_eq_of_one_tmul (C := simpleFixed cs i) + (A := SymmetricCoefficient (M := M)) (N := BottSamelsonModule cs l) F G h + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The genuine head-word stalk is an integral reflected pair lattice of the +tail word. This supplies the stalk-freeness step once tail edge exactness is +proved; it does not assume the desired main conclusion. -/ +namespace KLInvariance.TitsSpace +open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section +attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite + + omit [Fintype I] in + theorem bottWeight_tail_zero (i : I) (l : List I) (x : W) + (e : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x}) (h : e.val.1=0) : + bottWeight cs l e.val.2=x := by + simpa only [bottWeight,ite_eq_left h] using e.property + + omit [Fintype I] in + theorem bottWeight_tail_one (i : I) (l : List I) (x : W) + (e : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x}) (h : e.val.1≠0) : + bottWeight cs l e.val.2=cs.simple i*x := by + have he : cs.simple i*bottWeight cs l e.val.2=x := by + simpa only [bottWeight,ite_eq_right h] using e.property + simpa only [cs.simple_mul_simple_cancel_left] using (congrArg (cs.simple i * ·) he) + + def bottHeadPairCoordinates (i : I) (l : List I) (x : W) : + (bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*x))) →ₗ[SymmetricCoefficient (M := M)] + ({e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M)) where + toFun p e := if h : e.val.1=0 then + p.1.val ⟨e.val.2,bottWeight_tail_zero cs i l x e h⟩ + else coefficientAction cs (cs.simple i) + (p.2.val.val ⟨e.val.2,bottWeight_tail_one cs i l x e h⟩) + map_add' p q := by + funext e + by_cases h : e.val.1=0 + · simp only [Pi.add_apply,dite_eq_left h]; rfl + · simp only [Pi.add_apply,dite_eq_right h] + exact map_add (coefficientAction cs (cs.simple i)) _ _ + map_smul' r p := by + funext e + dsimp + split_ifs with h + · rfl + · change coefficientAction cs (cs.simple i) + (coefficientAction cs (cs.simple i) r * _) = r * coefficientAction cs (cs.simple i) _ + rw [map_mul,simple_involutive]; rfl + + theorem bottHeadPairCoordinates_injective (i : I) (l : List I) (x : W) : + Function.Injective (bottHeadPairCoordinates cs i l x) := by + rintro ⟨p,q⟩ ⟨p',q'⟩ h + apply Prod.ext + · apply Subtype.ext + funext e + have hh := congrFun h ⟨(0,e.val),by simpa only [bottWeight,ite_true] using e.property⟩ + simpa only [bottHeadPairCoordinates,LinearMap.coe_mk,AddHom.coe_mk,dite_eq_left rfl,dite_true] using hh + · apply Twist.ext + apply Subtype.ext + funext e + have he : bottWeight cs (i::l) (1,e.val)=x := by + change (if (1 : Fin 2)=0 then _ else cs.simple i*bottWeight cs l e.val)=x + rw [ite_eq_right (by decide),e.property,cs.simple_mul_simple_cancel_left] + have hh := congrFun h ⟨(1,e.val),he⟩ + have hh' : coefficientAction cs (cs.simple i) (q.val.val e) = + coefficientAction cs (cs.simple i) (q'.val.val e) := by + simpa only [bottHeadPairCoordinates,LinearMap.coe_mk,AddHom.coe_mk, + dite_eq_right (show (1 : Fin 2)≠0 by decide)] using hh + exact (coefficientAction cs (cs.simple i)).injective hh' + + theorem simpleReverseDivisibility (i : I) (a : SymmetricCoefficient (M := M)) : + simpleRootPolynomial (M := M) i ∣ coefficientAction cs (cs.simple i) a-a := + (dvd_sub_comm).mpr (simple_divisible cs i a) + + variable (i : I) (l : List I) (x : W) + + def bottHeadPairLattice := lattice (bottStalkProjection cs l x) + (bottStalkProjection cs l (cs.simple i*x)) (coefficientAction cs (cs.simple i)).toRingEquiv + (simpleRootPolynomial (M := M) i) (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) + + instance bottHeadPairAddCommGroup : AddCommGroup (bottHeadPairLattice cs i l x) := + Submodule.addCommGroup (bottHeadPairLattice cs i l x) + + instance bottHeadPairModule : Module (SymmetricCoefficient (M := M)) (bottHeadPairLattice cs i l x) := + Submodule.module (bottHeadPairLattice cs i l x) + + theorem bottHeadPairCoordinates_seed (n : BottSamelsonModule cs l) : + bottHeadPairCoordinates cs i l x + (bottStalkProjection cs l x n,⟨bottStalkProjection cs l (cs.simple i*x) n⟩) = + bottWeightProjection cs (i::l) x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n) := by + funext e + change (if h : e.val.1=0 then _ else _) = (1 : SymmetricCoefficient (M := M))*(if e.val.1=0 then _ else _) + rw [one_mul] + split_ifs <;> rfl + + def bottHeadPairToStalk : bottHeadPairLattice cs i l x →ₗ[ + SymmetricCoefficient (M := M)] bottStalk cs (i::l) x := + LinearMap.codRestrict (bottStalk cs (i::l) x) + ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) (by + rintro ⟨⟨p,q⟩,n,hn,hn'⟩ + refine ⟨(1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n,?_⟩ + change bottWeightProjection cs (i::l) x _=bottHeadPairCoordinates cs i l x (p,q) + rw [← bottHeadPairCoordinates_seed] + congr 1 + exact Prod.ext hn (Twist.ext hn')) + + theorem bottHeadPairToStalk_injective : Function.Injective (bottHeadPairToStalk cs i l x) := by + intro p q h + apply Subtype.ext + exact bottHeadPairCoordinates_injective cs i l x (congrArg Subtype.val h) + + theorem bottHeadPair_range : + LinearMap.range (bottWeightProjection cs (i::l) x) ≤ + LinearMap.range ((bottHeadPairCoordinates cs i l x).comp + (bottHeadPairLattice cs i l x).subtype) := by + refine bottWeightProjection_range_le cs i l x (P := bottHeadPairLattice cs i l x) + ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) ?_ + intro n + refine ⟨⟨(bottStalkProjection cs l x n,⟨bottStalkProjection cs l (cs.simple i*x) n⟩),n,rfl,rfl⟩,?_⟩ + exact bottHeadPairCoordinates_seed cs i l x n + + theorem bottHeadPairToStalk_surjective : Function.Surjective (bottHeadPairToStalk cs i l x) := by + exact codRestrict_surjective_of_range_le (A := SymmetricCoefficient (M := M)) + (P := bottHeadPairLattice cs i l x) + (V := {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} → SymmetricCoefficient (M := M)) + ((bottHeadPairCoordinates cs i l x).comp (bottHeadPairLattice cs i l x).subtype) + (bottStalk cs (i::l) x) _ (bottHeadPair_range cs i l x) + + def bottHeadPairEquiv : bottHeadPairLattice cs i l x ≃ₗ[ + SymmetricCoefficient (M := M)] bottStalk cs (i::l) x := + LinearEquiv.ofBijective (bottHeadPairToStalk cs i l x) + ⟨bottHeadPairToStalk_injective cs i l x,bottHeadPairToStalk_surjective cs i l x⟩ + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The top projection lattice of a reduced actual tensor word is exactly A. +This verifies the genuine rank-one top used in the BMP summand construction; +it does not assert that the other projection lattices form a flabby sheaf. -/ +namespace KLInvariance.TitsSpace +open Module TensorProduct +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + def bottFullIndex : (l : List I) → BottIndex l + | [] => PUnit.unit + | _::l => (1,bottFullIndex l) + +omit [Fintype I] in + theorem bottWeight_full (l : List I) : + bottWeight cs l (bottFullIndex l)=cs.wordProd l := by + induction l with + | nil => exact cs.wordProd_nil.symm + | cons i l ih => + simp only [bottFullIndex,bottWeight,show (1:Fin 2) ≠ 0 by decide,ite_false, + cs.wordProd_cons,ih] + +omit [Fintype I] in + theorem bottSubword_length_eq_full (l : List I) (e : BottIndex l) + (h : (bottSubword l e).length=l.length) : e=bottFullIndex l := by + induction l with + | nil => + change PUnit at e + change e=(PUnit.unit : PUnit) + exact Subsingleton.elim _ _ + | cons i l ih => + change Fin 2 × BottIndex l at e + by_cases he : e.1=0 + · simp only [bottSubword,ite_eq_left he,List.length_cons] at h + have hn := (bottSubword_sublist l e.2).length_le + omega + · have he1 : e.1=1 := by omega + simp only [bottSubword,ite_eq_right he,List.length_cons] at h + exact Prod.ext he1 (ih e.2 (Nat.succ.inj h)) + +omit [Fintype I] in + theorem bottWeight_eq_top (l : List I) (hl : cs.IsReduced l) (e : BottIndex l) + (he : bottWeight cs l e=cs.wordProd l) : e=bottFullIndex l := by + apply bottSubword_length_eq_full + apply Nat.le_antisymm (bottSubword_sublist l e).length_le + have hh := cs.length_wordProd_le (bottSubword l e) + rwa [bottSubword_wordProd,he,hl.eq] at hh + + def bottUnit : (l : List I) → BottSamelsonModule cs l + | [] => (1 : SymmetricCoefficient (M := M)) + | i::l => 1 ⊗ₜ[simpleFixed cs i] bottUnit l + + theorem bottEvaluation_unit (l : List I) (e : BottIndex l) : + bottEvaluation cs l e (bottUnit cs l)=1 := by + induction l with + | nil => rfl + | cons i l ih => + change bottEvaluation cs (i::l) e (1 ⊗ₜ[simpleFixed cs i] bottUnit cs l)=1 + rw [bottEvaluation_tmul,ih] + split_ifs <;> simp only [map_one,mul_one] + + theorem bottEvaluation_surjective (l : List I) (e : BottIndex l) : + Function.Surjective (bottEvaluation cs l e) := by + intro a + refine ⟨a • bottUnit cs l,?_⟩ + rw [map_smul,bottEvaluation_unit,smul_eq_mul,mul_one] + + def bottTopCoordinate (l : List I) : bottStalk cs l (cs.wordProd l) →ₗ[ + SymmetricCoefficient (M := M)] SymmetricCoefficient (M := M) := + (LinearMap.proj ⟨bottFullIndex l,bottWeight_full cs l⟩).comp + (bottStalk cs l (cs.wordProd l)).subtype + + theorem bottTopCoordinate_bijective (l : List I) (hl : cs.IsReduced l) : + Function.Bijective (bottTopCoordinate cs l) := by + constructor + · intro a b hab + apply Subtype.ext + funext e + have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := + Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) + subst e + exact hab + · intro a + obtain ⟨m,hm⟩ := bottEvaluation_surjective cs l (bottFullIndex l) a + exact ⟨bottStalkProjection cs l (cs.wordProd l) m,hm⟩ + + def bottTopStalkEquiv (l : List I) (hl : cs.IsReduced l) : + bottStalk cs l (cs.wordProd l) ≃ₗ[SymmetricCoefficient (M := M)] + SymmetricCoefficient (M := M) := + LinearEquiv.ofBijective (bottTopCoordinate cs l) (bottTopCoordinate_bijective cs l hl) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The genuine subexpression projections preserve the actual word grading. +In particular the top projection of a reduced tensor word is a graded copy of +A, rather than just an ungraded rank-one lattice. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottEvaluation_basis_homogeneous (l : List I) (e f : BottIndex l) : + bottEvaluationMatrix cs l e f ∈ symmetricGrading basis (bottDegree l f) := by + induction l with + | nil => + change PUnit at e f + change (Basis.singleton PUnit (SymmetricCoefficient (M := M)) f) ∈ + symmetricGrading basis 0 + simp only [Basis.singleton_apply] + exact SetLike.one_mem_graded _ + | cons i l ih => + change Fin 2 × BottIndex l at e f + rcases e with ⟨r,j⟩ + rcases f with ⟨c,k⟩ + rw [bottEvaluationMatrix_cons] + by_cases hc : c=0 + · subst c + simp only [ite_true,bottDegree,Fin.val_zero,Nat.cast_zero,zero_add] + split_ifs + · exact ih j k + · exact coefficientAction_homogeneous cs basis _ _ _ (ih j k) + · have hc1 : c=1 := by omega + subst c + simp only [show (1:Fin 2) ≠ 0 by decide,ite_false,bottDegree,Fin.val_one,Nat.cast_one] + split_ifs + · exact SetLike.GradedMul.mul_mem (simpleRoot_homogeneous basis i) (ih j k) + · exact SetLike.GradedMul.mul_mem ((symmetricGrading basis 1).neg_mem + (simpleRoot_homogeneous basis i)) + (coefficientAction_homogeneous cs basis _ _ _ (ih j k)) + + theorem bottEvaluation_homogeneous (l : List I) (e : BottIndex l) + (n : ℤ) (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : + bottEvaluation cs l e m ∈ symmetricGrading basis n := by + classical + have hexp : bottEvaluation cs l e m = ∑ f : BottIndex l, + (bottBasis cs l).repr m f * bottEvaluationMatrix cs l e f := by + conv_lhs => rw [← (bottBasis cs l).sum_repr m] + simp only [map_sum,map_smul,smul_eq_mul,bottEvaluationMatrix] + rw [hexp] + apply Submodule.sum_mem + intro f _ + change ∀ f, (bottBasis cs l).repr m f ∈ + symmetricGrading basis (n-bottDegree l f) at hm + have h := SetLike.GradedMul.mul_mem (hm f) + (bottEvaluation_basis_homogeneous cs basis l e f) + simpa only [sub_add_cancel] using h + + theorem bottEvaluation_component (l : List I) (e : BottIndex l) + (n : ℤ) (m : BottSamelsonModule cs l) : + component (symmetricGrading basis) n (bottEvaluation cs l e m) = + bottEvaluation cs l e (component (bottPiece cs basis l) n m) := by + simpa only [sub_zero] using map_component (bottPiece cs basis l) (symmetricGrading basis) + (bottEvaluation cs l e) 0 (by simpa only [add_zero] using bottEvaluation_homogeneous cs basis l e) n m + + theorem bottUnit_homogeneous (l : List I) : bottUnit cs l ∈ bottPiece cs basis l 0 := by + have he : component (bottPiece cs basis l) 0 (bottUnit cs l)=bottUnit cs l := by + apply bottEvaluation_injective cs l + funext e + change bottEvaluation cs l e (component (bottPiece cs basis l) 0 (bottUnit cs l)) = + bottEvaluation cs l e (bottUnit cs l) + rw [← bottEvaluation_component,bottEvaluation_unit] + exact DirectSum.decompose_of_mem_same (symmetricGrading basis) (SetLike.one_mem_graded _) + rw [← he] + exact (DirectSum.decompose (bottPiece cs basis l) (bottUnit cs l) 0).property + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Actual integral projection and support lattices inherit their grading from +the genuine tensor word. In particular a homogeneous stalk vector has a +homogeneous tensor lift. No freeness/character claim is assumed. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def bottCoordinatePiece (l : List I) (x : W) : ℤ → Submodule ℝ + ({e : BottIndex l // bottWeight cs l e=x} → SymmetricCoefficient (M := M)) := + piPiece (fun _ => symmetricGrading basis) + + instance bottCoordinatePiece_decomposition (l : List I) (x : W) : + DirectSum.Decomposition (bottCoordinatePiece cs basis l x) := by + classical + exact (pi_isInternal (fun _ : {e : BottIndex l // bottWeight cs l e=x} => + symmetricGrading basis)).chooseDecomposition + + instance bottCoordinatePiece_graded (l : List I) (x : W) : + SetLike.GradedSMul (symmetricGrading basis) (bottCoordinatePiece cs basis l x) := + inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) + (piPiece (fun _ : {e : BottIndex l // bottWeight cs l e=x} => symmetricGrading basis))) + + theorem bottWeightProjection_homogeneous (l : List I) (x : W) (n : ℤ) + (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : + bottWeightProjection cs l x m ∈ bottCoordinatePiece cs basis l x n := by + intro e _ + exact bottEvaluation_homogeneous cs basis l e.val n m hm + + theorem bottStalk_homogeneous (l : List I) (x : W) : + ∀ n f, f ∈ bottStalk cs l x → + component (bottCoordinatePiece cs basis l x) n f ∈ bottStalk cs l x := by + exact range_homogeneous (bottPiece cs basis l) (bottCoordinatePiece cs basis l x) + (bottWeightProjection cs l x) 0 (by + simpa only [add_zero] using bottWeightProjection_homogeneous cs basis l x) + + def bottStalkPiece (l : List I) (x : W) : ℤ → Submodule ℝ (bottStalk cs l x) := + subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x) + + instance bottStalkPiece_decomposition (l : List I) (x : W) : + DirectSum.Decomposition (bottStalkPiece cs basis l x) := + (sub_isInternal (bottCoordinatePiece cs basis l x) (bottStalk cs l x) + (bottStalk_homogeneous cs basis l x)).chooseDecomposition + + instance bottStalkPiece_graded (l : List I) (x : W) : + SetLike.GradedSMul (symmetricGrading basis) (bottStalkPiece cs basis l x) := + inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) + (subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x))) + + theorem bottStalkProjection_homogeneous (l : List I) (x : W) (n : ℤ) + (m : BottSamelsonModule cs l) (hm : m ∈ bottPiece cs basis l n) : + bottStalkProjection cs l x m ∈ bottStalkPiece cs basis l x n := + bottWeightProjection_homogeneous cs basis l x n m hm + + theorem bottStalk_homogeneous_lift (l : List I) (x : W) (n : ℤ) + (s : bottStalk cs l x) (hs : s ∈ bottStalkPiece cs basis l x n) : + ∃ m : BottSamelsonModule cs l, m ∈ bottPiece cs basis l n ∧ + bottStalkProjection cs l x m=s := by + obtain ⟨m,hm⟩ := bottStalkProjection_surjective cs l x s + refine ⟨component (bottPiece cs basis l) n m, + (DirectSum.decompose (bottPiece cs basis l) m n).property,?_⟩ + have he := map_component (bottPiece cs basis l) (bottStalkPiece cs basis l x) + (bottStalkProjection cs l x) 0 (by + simpa only [add_zero] using bottStalkProjection_homogeneous cs basis l x) n m + rw [sub_zero,hm,show component (bottStalkPiece cs basis l x) n s=s from + DirectSum.decompose_of_mem_same _ hs] at he + exact he.symm + + theorem bottWeightSupported_homogeneous (l : List I) (x : W) : + ∀ n m, m ∈ bottWeightSupported cs l x → + component (bottPiece cs basis l) n m ∈ bottWeightSupported cs l x := by + intro n m hm e he + rw [← bottEvaluation_component,hm e he,map_zero] + + def bottSupportPiece (l : List I) (x : W) : + ℤ → Submodule ℝ (bottWeightSupported cs l x) := + subPiece (bottPiece cs basis l) (bottWeightSupported cs l x) + + instance bottSupportPiece_decomposition (l : List I) (x : W) : + DirectSum.Decomposition (bottSupportPiece cs basis l x) := + (sub_isInternal (bottPiece cs basis l) (bottWeightSupported cs l x) + (bottWeightSupported_homogeneous cs basis l x)).chooseDecomposition + + instance bottSupportPiece_graded (l : List I) (x : W) : + SetLike.GradedSMul (symmetricGrading basis) (bottSupportPiece cs basis l x) := + inferInstanceAs (SetLike.GradedSMul (symmetricGrading basis) + (subPiece (bottPiece cs basis l) (bottWeightSupported cs l x))) + +omit [Fintype σ] in + theorem bottTopStalkEquiv_homogeneous (l : List I) (hl : cs.IsReduced l) + (n : ℤ) (s : bottStalk cs l (cs.wordProd l)) : + bottTopStalkEquiv cs l hl s ∈ symmetricGrading basis n ↔ + s ∈ bottStalkPiece cs basis l (cs.wordProd l) n := by + constructor + · intro h e _ + have he : e=⟨bottFullIndex l,bottWeight_full cs l⟩ := + Subtype.ext (bottWeight_eq_top cs l hl e.val e.property) + subst e + exact h + · intro h + exact h ⟨bottFullIndex l,bottWeight_full cs l⟩ (Set.mem_univ _) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Restriction of the honest reflection-twisted module to the fixed base field. +The automorphism fixes the base field, so no scalar information is discarded. -/ +namespace KLInvariance.ReflectionPairTranslation.Twist +universe uk ur uy +variable {k : Type uk} [Field k] {R : Type ur} [CommRing R] [Algebra k R] + (τ : R ≃ₐ[k] R) (Y : Type uy) [AddCommGroup Y] [Module R Y] [Module k Y] + [IsScalarTower k R Y] + +instance scalarModule : Module k (Twist τ.toRingEquiv Y) := + ({ equivVal τ.toRingEquiv Y with map_add' := fun _ _ => rfl } : + Twist τ.toRingEquiv Y ≃+ Y).module k + +instance scalarTower : IsScalarTower k R (Twist τ.toRingEquiv Y) where + smul_assoc c r y := by + apply Twist.ext + change τ (c • r) • y.val=c • (τ r • y.val) + rw [map_smul,smul_assoc] + +def scalarEquiv : Twist τ.toRingEquiv Y ≃ₗ[k] Y where + toFun := val + invFun := mk + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +end KLInvariance.ReflectionPairTranslation.Twist + +end + + +section + +/-! Homogeneous perfect pairings on the actual integral free modules. The +inverse grading is proved, not inferred merely after fraction-field extension. -/ +namespace KLInvariance.Graded +open Module +universe uk ua um un ui +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {N : Type um} [AddCommGroup N] [Module A N] [Module k N] [IsScalarTower k A N] + {P : Type un} [AddCommGroup P] [Module A P] [Module k P] [IsScalarTower k A P] +noncomputable section + +omit [Algebra k A] [IsScalarTower k A N] [IsScalarTower k A P] in + theorem equiv_inverse_homogeneous + (𝓝 : ℤ → Submodule k N) (𝓟 : ℤ → Submodule k P) + [DirectSum.Decomposition 𝓝] [DirectSum.Decomposition 𝓟] + (e : N ≃ₗ[A] P) (d : ℤ) + (he : ∀ n x, x ∈ 𝓝 n → e x ∈ 𝓟 (n+d)) + (n : ℤ) (y : P) (hy : y ∈ 𝓟 n) : e.symm y ∈ 𝓝 (n-d) := by + have hc : component 𝓝 (n-d) (e.symm y) = e.symm y := by + apply e.injective + change e.toLinearMap (component 𝓝 (n-d) (e.symm y)) = e.toLinearMap (e.symm y) + rw [← map_component 𝓝 𝓟 e.toLinearMap d he n (e.symm y)] + simp only [LinearEquiv.coe_coe,LinearEquiv.apply_symm_apply] + exact DirectSum.decompose_of_mem_same 𝓟 hy + rw [← hc] + exact (DirectSum.decompose 𝓝 (e.symm y) (n-d)).property + +variable (𝓐 : ℤ → Submodule k A) [DirectSum.Decomposition 𝓐] + [SetLike.GradedMonoid 𝓐] {ι : Type ui} [Fintype ι] [DecidableEq ι] + (b : Basis ι A N) (d : ι → ℤ) + +omit [DirectSum.Decomposition 𝓐] in + theorem pairing_to_dual_homogeneous (p : N →ₗ[A] Dual A N) (l : ℤ) + (hp : ∀ i j, p (b i) (b j) ∈ 𝓐 (d i+d j-l)) + {n : ℤ} {x : N} (hx : x ∈ basisPiece 𝓐 b d n) : + p x ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) (n-l) := by + rw [mem_basisPiece] + intro i + rw [Basis.dualBasis_repr] + have h := pairing_homogeneous 𝓐 b d p l hp hx (basis_mem_piece 𝓐 b d i) + convert h using 1 + congr 1 + omega + + theorem perfectPairing_inverse_homogeneous (p : N ≃ₗ[A] Dual A N) (l : ℤ) + (hp : ∀ i j, p (b i) (b j) ∈ 𝓐 (d i+d j-l)) + {n : ℤ} {y : Dual A N} + (hy : y ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) n) : + p.symm y ∈ basisPiece 𝓐 b d (n+l) := by + have he : ∀ m x, x ∈ basisPiece 𝓐 b d m → + p x ∈ basisPiece 𝓐 b.dualBasis (fun i => -d i) (m+(-l)) := by + intro m x hx + exact pairing_to_dual_homogeneous 𝓐 b d p.toLinearMap l hp hx + simpa only [sub_neg_eq_add] using equiv_inverse_homogeneous + (basisPiece 𝓐 b d) (basisPiece 𝓐 b.dualBasis (fun i => -d i)) p (-l) he n y hy + +end +end KLInvariance.Graded + +end + + +section + +/-! The genuine head-word projection maps, on the fixed real field, preserve +homogeneous degrees. These maps are not abstract character operators. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def bottHeadLeft (i : I) (l : List I) (x : W) : + bottStalk cs (i::l) x →ₗ[SymmetricCoefficient (M := M)] bottStalk cs l x := + (ReflectionPairTranslation.left (bottStalkProjection cs l x) + (bottStalkProjection cs l (cs.simple i*x)) (coefficientAction cs (cs.simple i)).toRingEquiv + (simpleRootPolynomial (M := M) i) (simpleReverseDivisibility cs i) + (bottSimpleEdge_kernel_inclusion cs i l x)).comp (bottHeadPairEquiv cs i l x).symm.toLinearMap + + def bottHeadRight (i : I) (l : List I) (x : W) : + bottStalk cs (i::l) x →ₗ[ℝ] bottStalk cs l (cs.simple i*x) := + (Twist.scalarEquiv (coefficientAction cs (cs.simple i)) _).toLinearMap.comp + (((LinearMap.snd (SymmetricCoefficient (M := M)) (bottStalk cs l x) + (Twist (coefficientAction cs (cs.simple i)).toRingEquiv (bottStalk cs l (cs.simple i*x)))).comp + ((bottHeadPairLattice cs i l x).subtype.comp + (bottHeadPairEquiv cs i l x).symm.toLinearMap)).restrictScalars ℝ) + + theorem bottHeadLeft_surjective (i : I) (l : List I) (x : W) : + Function.Surjective (bottHeadLeft cs i l x) := + (left_surjective _ _ _ _ _ _ (bottStalkProjection_surjective cs l x)).comp + (bottHeadPairEquiv cs i l x).symm.surjective + + theorem bottHeadPairEquiv_coordinates (i : I) (l : List I) (x : W) + (m : bottStalk cs (i::l) x) : + bottHeadPairCoordinates cs i l x ((bottHeadPairEquiv cs i l x).symm m).val=m.val := + congrArg Subtype.val ((bottHeadPairEquiv cs i l x).apply_symm_apply m) + +omit [Fintype σ] in + theorem bottHeadLeft_homogeneous (i : I) (l : List I) (x : W) (n : ℤ) + (m : bottStalk cs (i::l) x) (hm : m ∈ bottStalkPiece cs basis (i::l) x n) : + bottHeadLeft cs i l x m ∈ bottStalkPiece cs basis l x n := by + intro e _ + change (bottHeadLeft cs i l x m).val e ∈ symmetricGrading basis n + let E : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} := + ⟨(0,e.val),by simpa only [bottWeight,ite_true] using e.property⟩ + have he := congrFun (bottHeadPairEquiv_coordinates cs i l x m) E + have hh : (bottHeadLeft cs i l x m).val e=m.val E := by + change ((bottHeadPairEquiv cs i l x).symm m).val.1.val e=m.val E at he + exact he + rw [hh] + exact hm E (Set.mem_univ E) + + theorem bottHeadRight_homogeneous (i : I) (l : List I) (x : W) (n : ℤ) + (m : bottStalk cs (i::l) x) (hm : m ∈ bottStalkPiece cs basis (i::l) x n) : + bottHeadRight cs i l x m ∈ bottStalkPiece cs basis l (cs.simple i*x) n := by + intro e _ + change (bottHeadRight cs i l x m).val e ∈ symmetricGrading basis n + let E : {e : BottIndex (i::l) // bottWeight cs (i::l) e=x} := + ⟨(1,e.val),by simp only [bottWeight,ite_eq_right (show (1:Fin 2)≠0 by decide), + e.property,cs.simple_mul_simple_cancel_left]⟩ + have he := congrFun (bottHeadPairEquiv_coordinates cs i l x m) E + have hh : coefficientAction cs (cs.simple i) ((bottHeadRight cs i l x m).val e)=m.val E := by + change coefficientAction cs (cs.simple i) + (((bottHeadPairEquiv cs i l x).symm m).val.2.val.val e)=m.val E at he + exact he + have h := coefficientAction_homogeneous cs basis (cs.simple i) n (m.val E) + (hm E (Set.mem_univ E)) + rw [← hh,simple_involutive] at h + exact h + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The two common tail components of a reflected tensor. They are defined +on the actual tensor, so divisibility assertions at different weights use the +same tail vectors rather than unrelated existential lifts. -/ +namespace KLInvariance.ReflectionPairTranslation +open TensorProduct +universe uc ua un +variable {C : Type uc} [CommRing C] {A : Type ua} [CommRing A] [Algebra C A] + {N : Type un} [AddCommGroup N] [Module A N] [Module C N] [IsScalarTower C A N] + (τ : A ≃+* A) (hfix : ∀ c : C, τ (algebraMap C A c)=algebraMap C A c) +noncomputable section + + def tensorFirst : (A ⊗[C] N) →ₗ[A] N := + AlgebraTensorModule.lift ((LinearMap.id : A →ₗ[A] A).smulRight + (LinearMap.id : N →ₗ[C] N)) + + @[simp] theorem tensorFirst_tmul (a : A) (n : N) : + tensorFirst (C := C) (a ⊗ₜ[C] n)=a • n := rfl + + def tensorSecond : (A ⊗[C] N) →ₗ[A] Twist τ N := by + letI : Module C (Twist τ N) := Module.compHom _ (algebraMap C A) + letI : IsScalarTower C A (Twist τ N) := + IsScalarTower.of_algebraMap_smul fun _ _ => rfl + let F : N →ₗ[C] Twist τ N := { + toFun := Twist.mk + map_add' := fun _ _ => rfl + map_smul' := fun c n => by + apply Twist.ext + change c • n=τ (algebraMap C A c) • n + rw [hfix,algebraMap_smul] } + exact AlgebraTensorModule.lift ((LinearMap.id : A →ₗ[A] A).smulRight F) + + @[simp] theorem tensorSecond_tmul (a : A) (n : N) : + tensorSecond τ hfix (a ⊗ₜ[C] n)=Twist.mk (τ a • n) := rfl + + def twistMap {P : Type*} [AddCommGroup P] [Module A P] (f : N →ₗ[A] P) : + Twist τ N →ₗ[A] Twist τ P where + toFun m := ⟨f m.val⟩ + map_add' m n := Twist.ext (map_add f m.val n.val) + map_smul' a m := Twist.ext (map_smul f (τ a) m.val) +end +end KLInvariance.ReflectionPairTranslation + +end + + +section + +namespace KLInvariance.TitsSpace +open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section +attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite + + def bottHeadTail (i : I) (l : List I) : BottSamelsonModule cs (i::l) →ₗ[ + SymmetricCoefficient (M := M)] BottSamelsonModule cs l := + tensorFirst (C := simpleFixed cs i) + + def bottHeadReflectedTail (i : I) (l : List I) : BottSamelsonModule cs (i::l) →ₗ[ + SymmetricCoefficient (M := M)] Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (BottSamelsonModule cs l) := + tensorSecond (C := simpleFixed cs i) (coefficientAction cs (cs.simple i)).toRingEquiv + (fun c => c.property) + + theorem bottHeadTail_seed (i : I) (l : List I) (n : BottSamelsonModule cs l) : + bottHeadTail cs i l ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)=n := by + exact one_smul _ n + + theorem bottHeadReflectedTail_seed (i : I) (l : List I) (n : BottSamelsonModule cs l) : + bottHeadReflectedTail cs i l ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)=Twist.mk n := by + change Twist.mk ((coefficientAction cs (cs.simple i)) 1 • n)=Twist.mk n + rw [map_one,one_smul] + + def bottHeadLocalPair (i : I) (l : List I) (x : W) : BottSamelsonModule cs (i::l) →ₗ[ + SymmetricCoefficient (M := M)] + (bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*x))) := + ((bottStalkProjection cs l x).comp (bottHeadTail cs i l)).prod + ((twistMap (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalkProjection cs l (cs.simple i*x))).comp (bottHeadReflectedTail cs i l)) + + theorem bottHeadLocalPair_seed (i : I) (l : List I) (x : W) (n : BottSamelsonModule cs l) : + bottHeadLocalPair cs i l x ((1 : SymmetricCoefficient (M := M)) ⊗ₜ[simpleFixed cs i] n)= + (bottStalkProjection cs l x n,Twist.mk (bottStalkProjection cs l (cs.simple i*x) n)) := by + change ((bottStalkProjection cs l x) (bottHeadTail cs i l _), + (twistMap (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalkProjection cs l (cs.simple i*x))) (bottHeadReflectedTail cs i l _)) = _ + rw [bottHeadTail_seed,bottHeadReflectedTail_seed] + rfl +end +end KLInvariance.TitsSpace + +end + + +section +namespace KLInvariance +universe ua up uv un +variable {A : Type ua} [CommRing A] + {P : Type up} [AddCommGroup P] [Module A P] + {V : Type uv} [AddCommGroup V] [Module A V] + {N : Type un} [AddCommGroup N] [Module A N] + theorem linearMap_mem_of_coordinates (S : Submodule A P) + (F : P →ₗ[A] V) (G : N →ₗ[A] P) (E : N →ₗ[A] V) + (hF : Function.Injective F) (heq : F.comp G = E) + (hrange : LinearMap.range E ≤ LinearMap.range (F.comp S.subtype)) (n : N) : G n ∈ S := by + obtain ⟨p,hp⟩ := hrange (show E n ∈ LinearMap.range E from ⟨n,rfl⟩) + have he : (p : P) = G n := hF (hp.trans (LinearMap.congr_fun heq n).symm) + exact he ▸ p.property +end KLInvariance + +end + + +section + +namespace KLInvariance.TitsSpace +open Module TensorProduct FrobeniusDuality ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section +attribute [local instance] restrictedModule restrictedTower restrictedFree restrictedFinite + + theorem bottHeadLocalPair_coordinates (i : I) (l : List I) (x : W) : + (bottHeadPairCoordinates cs i l x).comp (bottHeadLocalPair cs i l x) = + bottWeightProjection cs (i::l) x := by + apply bottTensor_maps_eq cs i l + intro n + change bottHeadPairCoordinates cs i l x (bottHeadLocalPair cs i l x _) = _ + rw [bottHeadLocalPair_seed,bottHeadPairCoordinates_seed] + + theorem bottHeadLocalPair_mem (i : I) (l : List I) (x : W) + (m : BottSamelsonModule cs (i::l)) : + bottHeadLocalPair cs i l x m ∈ bottHeadPairLattice cs i l x := by + exact linearMap_mem_of_coordinates (bottHeadPairLattice cs i l x) + (bottHeadPairCoordinates cs i l x) (bottHeadLocalPair cs i l x) + (bottWeightProjection cs (i::l) x) (bottHeadPairCoordinates_injective cs i l x) + (bottHeadLocalPair_coordinates cs i l x) (bottHeadPair_range cs i l x) m + + theorem bottHeadLocalPair_zero_iff (i : I) (l : List I) (x : W) + (m : BottSamelsonModule cs (i::l)) : + bottStalkProjection cs (i::l) x m=0 ↔ bottHeadLocalPair cs i l x m=0 := by + constructor + · intro h + apply bottHeadPairCoordinates_injective cs i l x + rw [map_zero] + have hh := congrArg Subtype.val h + change bottWeightProjection cs (i::l) x m=0 at hh + exact (LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m).trans hh + · intro h + apply Subtype.ext + change bottWeightProjection cs (i::l) x m=0 + rw [← LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m] + change bottHeadPairCoordinates cs i l x (bottHeadLocalPair cs i l x m)=0 + rw [h,map_zero] + + theorem bottHeadLocalPair_value (i : I) (l : List I) (x : W) + (m : BottSamelsonModule cs (i::l)) : + bottHeadLocalPair cs i l x m = + (bottStalkProjection cs l x (bottHeadTail cs i l m), + Twist.mk (bottStalkProjection cs l (cs.simple i*x) (bottHeadReflectedTail cs i l m).val)) := rfl + + theorem bottHeadLocalPair_toStalk (i : I) (l : List I) (x : W) + (m : BottSamelsonModule cs (i::l)) : + bottHeadPairToStalk cs i l x ⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ = + bottStalkProjection cs (i::l) x m := by + apply Subtype.ext + exact LinearMap.congr_fun (bottHeadLocalPair_coordinates cs i l x) m + + theorem bottHeadStalk_divisible_of_pair (i : I) (l : List I) (x : W) + (m : BottSamelsonModule cs (i::l)) (β : SymmetricCoefficient (M := M)) + (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*x))) + (hm : bottHeadLocalPair cs i l x m=β • p) (hp : p ∈ bottHeadPairLattice cs i l x) : + ∃ z : bottStalk cs (i::l) x, bottStalkProjection cs (i::l) x m=β • z := by + let z : bottHeadPairLattice cs i l x := ⟨p,hp⟩ + refine ⟨bottHeadPairToStalk cs i l x z,?_⟩ + have he : (⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ : + bottHeadPairLattice cs i l x) = β • z := Subtype.ext hm + calc + bottStalkProjection cs (i::l) x m = + bottHeadPairToStalk cs i l x ⟨bottHeadLocalPair cs i l x m,bottHeadLocalPair_mem cs i l x m⟩ := + (bottHeadLocalPair_toStalk cs i l x m).symm + _ = bottHeadPairToStalk cs i l x (β • z) := congrArg (bottHeadPairToStalk cs i l x) he + _ = β • bottHeadPairToStalk cs i l x z := map_smul _ _ _ + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.FiniteFreeScalar +universe ur um un ui +variable {R : Type ur} [CommRing R] + {M : Type um} [AddCommGroup M] [Module R M] + {ι : Type ui} [Fintype ι] (b : Module.Basis ι R M) + + + theorem exists_smul_iff (r : R) (m : M) : + (∃ n, r • n = m) ↔ ∀ i, r ∣ b.equivFun m i := by + classical + constructor + · rintro ⟨n,rfl⟩ i + exact ⟨b.equivFun n i, by simp⟩ + · intro h + choose n hn using h + refine ⟨b.equivFun.symm n,b.equivFun.injective ?_⟩ + ext i + simp only [map_smul,LinearEquiv.apply_symm_apply,Pi.smul_apply,smul_eq_mul] + exact (hn i).symm + +include b in + theorem exists_prod_smul [DecompositionMonoid R] {J : Type*} (s : Finset J) (r : J → R) + (hrel : (s : Set J).Pairwise (Function.onFun IsRelPrime r)) (m : M) + (h : ∀ j ∈ s, ∃ n, r j • n = m) : ∃ n, (∏ j ∈ s, r j) • n = m := by + apply (exists_smul_iff b _ m).mpr + intro i + apply Finset.prod_dvd_of_isRelPrime hrel + intro j hj + exact (exists_smul_iff b _ _).mp (h j hj) i + +include b in + + + theorem scalar_quotient_regular + {N : Type un} [AddCommGroup N] [Module R N] + (q : M →ₗ[R] N) (hq : Function.Surjective q) + (a r : R) (ha : Prime a) (hr : ¬ a ∣ r) + (hker : ∀ m, q m = 0 ↔ ∃ n, m=a • n) : + Function.Injective (fun v : N => r • v) := by + suffices hh : ∀ v : N, r • v = 0 → v = 0 by + intro v w hvw + change r • v = r • w at hvw + have hv : r • (v-w) = 0 := by rw [smul_sub,hvw,sub_self] + exact sub_eq_zero.mp (hh _ hv) + intro v hv + obtain ⟨m,rfl⟩ := hq v + have h0 : q (r • m) = 0 := by simpa only [map_smul] using hv + obtain ⟨n,hn⟩ := (hker _).mp h0 + have hdiv : ∀ i, a ∣ b.equivFun m i := by + intro i + have hc := congrArg (fun z => b.equivFun z i) hn + simp only [map_smul,Pi.smul_apply,smul_eq_mul] at hc + apply (ha.dvd_mul.mp ?_).resolve_left hr + exact ⟨b.equivFun n i,hc⟩ + obtain ⟨z,hz⟩ := (exists_smul_iff b a m).mpr hdiv + exact (hker m).mpr ⟨z,hz.symm⟩ + +end KLInvariance.FiniteFreeScalar + +end + + +section + +/-! Intermediate standard-filtration predicates on the genuine tensor word. +These are proved by word induction; they are not main-theorem assumptions. -/ +namespace KLInvariance.TitsSpace +open Module ReflectionFrobenius +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + def BottKernelExact (l : List I) : Prop := + ∀ (x t : W) (a : I → ℝ), Represents M cs t a → + cs.length x < cs.length (t*x) → + ∀ m : BottSamelsonModule cs l, bottStalkProjection cs l x m=0 → + ∃ z : bottStalk cs l (t*x), bottStalkProjection cs l (t*x) m= + SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z + + theorem simple_represents (i : I) : Represents M cs (cs.simple i) (root i) := by + refine ⟨1,i,?_,?_⟩ + · simp + · simp + + theorem represents_polynomial_prime {t : W} {a : I → ℝ} (ha : Represents M cs t a) : + Prime (SymmetricAlgebra.ι ℝ (Extended M) (embed M a)) := by + apply EdgeAlgebra.symmetric_ι_prime + intro h + exact ha.isRoot.ne_zero (congrArg Prod.fst h) + + theorem represents_polynomial_not_dvd {t s : W} {a b : I → ℝ} + (ha : Represents M cs t a) (hb : Represents M cs s b) (hne : t≠s) : + ¬ SymmetricAlgebra.ι ℝ (Extended M) (embed M a) ∣ + SymmetricAlgebra.ι ℝ (Extended M) (embed M b) := by + rw [EdgeAlgebra.symmetric_ι_dvd_iff] + intro h + have hi := hb.extended_independent_of_ne ha (Ne.symm hne) + obtain ⟨r,hr⟩ := Submodule.mem_span_singleton.mp h + exact (linearIndependent_fin2.mp hi).2 r hr + + theorem bottStalk_smul_injective (l : List I) (x : W) + {r : SymmetricCoefficient (M := M)} (hr : r≠0) : + Function.Injective (fun z : bottStalk cs l x => r • z) := + smul_right_injective (bottStalk cs l x) hr + + instance bottStalkFinite (l : List I) (x : W) : + Module.Finite (SymmetricCoefficient (M := M)) (bottStalk cs l x) := + Module.Finite.of_surjective (bottStalkProjection cs l x) (bottStalkProjection_surjective cs l x) + + theorem bottReflectionEdge_annihilated (l : List I) (x t : W) {a : I → ℝ} + (ha : Represents M cs t a) + (z : PairProjection.Edge (bottStalkProjection cs l x) (bottStalkProjection cs l (t*x))) : + SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z=0 := by + obtain ⟨p,hp⟩ := reflectionCoefficient_difference cs ha x + rw [← hp] + exact PairProjection.difference_annihilates _ _ + (bottStalkProjection_surjective cs _ _) (bottStalkProjection_surjective cs _ _) + (bottSamelsonRight cs l p) _ _ + (bottStalkProjection_right cs _ _ p) (bottStalkProjection_right cs _ _ p) z + + theorem BottKernelExact.upper_kernel {l : List I} (H : BottKernelExact cs l) + (x t : W) {a : I → ℝ} (ha : Represents M cs t a) + (hlt : cs.length x < cs.length (t*x)) (z : bottStalk cs l (t*x)) : + PairProjection.upper (bottStalkProjection cs l x) (bottStalkProjection cs l (t*x)) z=0 ↔ + ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := + PairProjection.upper_kernel_of_divisibility _ _ _ (H x t a ha hlt) + (bottReflectionEdge_annihilated cs l x t ha) z + + theorem BottKernelExact.kernel_iff {l : List I} (H : BottKernelExact cs l) + (x t : W) {a : I → ℝ} (ha : Represents M cs t a) + (hlt : cs.length x < cs.length (t*x)) (z : bottStalk cs l (t*x)) : + (∃ m, bottStalkProjection cs l x m=0 ∧ bottStalkProjection cs l (t*x) m=z) ↔ + ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by + rw [← PairProjection.kernel_upper] + exact H.upper_kernel cs x t ha hlt z + + theorem BottKernelExact.kernel_iff_of_mul {l : List I} (H : BottKernelExact cs l) + (x y t : W) {a : I → ℝ} (ha : Represents M cs t a) (hxy : t*x=y) + (hlt : cs.length x < cs.length y) (z : bottStalk cs l y) : + (∃ m, bottStalkProjection cs l x m=0 ∧ bottStalkProjection cs l y m=z) ↔ + ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by + subst y + exact H.kernel_iff cs x t ha hlt z + + theorem BottKernelExact.projection_of_mul {l : List I} (H : BottKernelExact cs l) + (x y t : W) {a : I → ℝ} (ha : Represents M cs t a) (hxy : t*x=y) + (hlt : cs.length x < cs.length y) (m : BottSamelsonModule cs l) + (hm : bottStalkProjection cs l x m=0) : + ∃ z : bottStalk cs l y, bottStalkProjection cs l y m= + SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z := by + subst y + exact H x t a ha hlt m hm + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.TitsSpace +open Module ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + theorem bottSimpleEdge_regular (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (x : W) (β : SymmetricCoefficient (M := M)) (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) : + Function.Injective (fun e : PairProjection.Edge (bottStalkProjection cs l x) + (bottStalkProjection cs l (cs.simple i*x)) => β • e) := by + have hα : Prime (simpleRootPolynomial (M := M) i) := + represents_polynomial_prime cs (simple_represents cs i) + rcases lt_or_gt_of_ne (cs.length_simple_mul_ne x i) with hdesc | hasc + · let := F x + apply FiniteFreeScalar.scalar_quotient_regular + (Module.Free.chooseBasis (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (PairProjection.lower (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x))) + (PairProjection.lower_surjective _ _ (bottStalkProjection_surjective cs l (cs.simple i*x))) + (simpleRootPolynomial (M := M) i) β hα hβ + intro z + rw [PairProjection.kernel_lower] + have hh := H.kernel_iff_of_mul cs (cs.simple i*x) x (cs.simple i) + (simple_represents cs i) (cs.simple_mul_simple_cancel_left i) hdesc z + simpa only [and_comm,simpleRootPolynomial,extendedRoot] using hh + · let := F (cs.simple i*x) + exact FiniteFreeScalar.scalar_quotient_regular + (Module.Free.chooseBasis (SymmetricCoefficient (M := M)) (bottStalk cs l (cs.simple i*x))) + (PairProjection.upper (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x))) + (PairProjection.upper_surjective _ _ (bottStalkProjection_surjective cs l x)) + (simpleRootPolynomial (M := M) i) β hα hβ + (H.upper_kernel cs x (cs.simple i) (simple_represents cs i) hasc) + + theorem bottHeadPairLattice_saturated (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (x : W) (β : SymmetricCoefficient (M := M)) (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) + (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*x))) : + β • p ∈ bottHeadPairLattice cs i l x ↔ p ∈ bottHeadPairLattice cs i l x := + lattice_saturated (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) + (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) + (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) + β (bottSimpleEdge_annihilated cs i l x) (bottSimpleEdge_regular cs i l H F x β hβ) p + +end +end KLInvariance.TitsSpace + +end + + +section + + +namespace KLInvariance.TitsSpace +open Module ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + theorem bottHeadStalk_divisible (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (x : W) (m : BottSamelsonModule cs (i::l)) (β : SymmetricCoefficient (M := M)) + (hβ : ¬simpleRootPolynomial (M := M) i ∣ β) + (p : bottStalk cs l x × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*x))) + (hm : bottHeadLocalPair cs i l x m=β • p) : + ∃ z : bottStalk cs (i::l) x, bottStalkProjection cs (i::l) x m=β • z := by + have hp := bottHeadLocalPair_mem cs i l x m + have hp' : β • p ∈ bottHeadPairLattice cs i l x := hm ▸ hp + exact bottHeadStalk_divisible_of_pair cs i l x m β p hm + ((bottHeadPairLattice_saturated cs i l H F x β hβ p).mp hp') + + theorem bottKernelExact_cons_nonhead (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (x t : W) (a : I → ℝ) (ha : Represents M cs t a) + (hlt : cs.length x < cs.length (t*x)) (hts : t≠cs.simple i) + (m : BottSamelsonModule cs (i::l)) (hm : bottStalkProjection cs (i::l) x m=0) : + ∃ z : bottStalk cs (i::l) (t*x), bottStalkProjection cs (i::l) (t*x) m= + SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • z := by + have he : t*x≠cs.simple i*x := fun h => hts (mul_right_cancel h) + have hstep : BruhatStep cs x (t*x) := ⟨hlt,t,ha.isReflection,rfl⟩ + have hstep' := bruhatStep_simple_mul cs hstep i he + have hconj : (cs.simple i*t*(cs.simple i)⁻¹)*(cs.simple i*x)=cs.simple i*(t*x) := by group + have hzero := (bottHeadLocalPair_zero_iff cs i l x m).mp hm + have hμ : bottStalkProjection cs l x (bottHeadTail cs i l m)=0 := congrArg Prod.fst hzero + have hν : bottStalkProjection cs l (cs.simple i*x) (bottHeadReflectedTail cs i l m).val=0 := + congrArg (fun p => p.2.val) hzero + obtain ⟨p,hp⟩ := H x t a ha hlt (bottHeadTail cs i l m) hμ + obtain ⟨q,hq⟩ := H.projection_of_mul cs (cs.simple i*x) (cs.simple i*(t*x)) + (cs.simple i*t*(cs.simple i)⁻¹) (ha.act (cs.simple i)) hconj hstep'.1 + (bottHeadReflectedTail cs i l m).val hν + let β : SymmetricCoefficient (M := M) := SymmetricAlgebra.ι ℝ (Extended M) (embed M a) + let p' : bottStalk cs l (t*x) × Twist (coefficientAction cs (cs.simple i)).toRingEquiv + (bottStalk cs l (cs.simple i*(t*x))) := (p,⟨q⟩) + have hβ' : coefficientAction cs (cs.simple i) β = + SymmetricAlgebra.ι ℝ (Extended M) (embed M (action M cs (cs.simple i) a)) := by + rw [coefficientAction_ι,extendedAction_restrict] + have heq : bottHeadLocalPair cs i l (t*x) m=β • p' := by + apply Prod.ext + · exact hp + · apply Twist.ext + change bottStalkProjection cs l (cs.simple i*(t*x)) + (bottHeadReflectedTail cs i l m).val = coefficientAction cs (cs.simple i) β • q + rw [hβ'] + exact hq + have hn : ¬simpleRootPolynomial (M := M) i ∣ β := + represents_polynomial_not_dvd cs (simple_represents cs i) ha (Ne.symm hts) + exact bottHeadStalk_divisible cs i l H F (t*x) m β hn p' heq + + theorem bottKernelExact_cons (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) : + BottKernelExact cs (i::l) := by + intro x t a ha hlt m hm + by_cases hts : t=cs.simple i + · subst t + obtain ⟨z,hz⟩ := bottSimpleWall_kernel_projection cs i l x hm + rcases ha.unique_up_to_sign (simple_represents cs i) with h|h + · subst a + exact ⟨z,hz⟩ + · subst a + refine ⟨-z,?_⟩ + rw [hz] + change simpleRootPolynomial (M := M) i • z = + SymmetricAlgebra.ι ℝ (Extended M) (embed M (-root i)) • (-z) + have he : embed M (-root i) = -embed M (root i) := by simp [embed] + have hn : SymmetricAlgebra.ι ℝ (Extended M) (embed M (-root i)) = + -simpleRootPolynomial (M := M) i := by + rw [he] + exact (SymmetricAlgebra.ι ℝ (Extended M)).map_neg _ + rw [hn] + exact (neg_smul_neg _ z).symm + · exact bottKernelExact_cons_nonhead cs i l H F x t a ha hlt hts m hm + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.ReflectionPairTranslation +universe u v w z +variable {R : Type u} [CommRing R] + {N : Type v} [AddCommGroup N] [Module R N] + {X : Type w} [AddCommGroup X] [Module R X] + {Y : Type z} [AddCommGroup Y] [Module R Y] + (f : N →ₗ[R] X) (g : N →ₗ[R] Y) (τ : R ≃+* R) (α : R) + (hdiv : ∀ r : R, α ∣ τ r-r) + (hinc : ∀ y : Y, ∃ n : N, f n=0 ∧ g n=α • y) + (hker : ∀ x : X, (∃ n : N, f n=x ∧ g n=0) ↔ ∃ z : X, x=α • z) + + def right : lattice f g τ α hdiv hinc →ₗ[R] Twist τ Y := + (LinearMap.snd R X (Twist τ Y)).comp (lattice f g τ α hdiv hinc).subtype + + theorem right_surjective (hg : Function.Surjective g) : + Function.Surjective (right f g τ α hdiv hinc) := by + intro y + obtain ⟨n,hn⟩ := hg y.val + exact ⟨⟨(f n,y),n,rfl,hn⟩,rfl⟩ + + def rightKernelMap : X →ₗ[R] LinearMap.ker (right f g τ α hdiv hinc) where + toFun x := ⟨⟨(α • x,⟨0⟩),(hker (α • x)).mpr ⟨x,rfl⟩⟩,rfl⟩ + map_add' x y := by + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · exact smul_add α x y + · apply Twist.ext + exact (zero_add (0 : Y)).symm + map_smul' r x := by + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · exact smul_comm α r x + · apply Twist.ext + exact (smul_zero _).symm + + theorem rightKernelMap_surjective : + Function.Surjective (rightKernelMap f g τ α hdiv hinc hker) := by + rintro ⟨⟨⟨x,y⟩,n,hn,hn'⟩,hy⟩ + have hy' : y.val=0 := congrArg Twist.val hy + obtain ⟨z,hz⟩ := (hker x).mp ⟨n,hn,hn'.trans hy'⟩ + refine ⟨z,?_⟩ + apply Subtype.ext + apply Subtype.ext + exact Prod.ext hz.symm (Twist.ext hy'.symm) + + theorem rightKernelMap_injective (hinj : Function.Injective (fun x : X => α • x)) : + Function.Injective (rightKernelMap f g τ α hdiv hinc hker) := by + intro x y h + exact hinj (congrArg (fun p => p.val.val.1) h) + + noncomputable def rightKernelEquiv (hinj : Function.Injective (fun x : X => α • x)) : + X ≃ₗ[R] LinearMap.ker (right f g τ α hdiv hinc) := + LinearEquiv.ofBijective (rightKernelMap f g τ α hdiv hinc hker) + ⟨rightKernelMap_injective f g τ α hdiv hinc hker hinj, + rightKernelMap_surjective f g τ α hdiv hinc hker⟩ + + include hker in + theorem lattice_free_right (hg : Function.Surjective g) + (hinj : Function.Injective (fun x : X => α • x)) + [Module.Free R X] [Module.Free R Y] : + Module.Free R (lattice f g τ α hdiv hinc) := by + let : Module.Free R (LinearMap.ker (right f g τ α hdiv hinc)) := + Module.Free.of_equiv (rightKernelEquiv f g τ α hdiv hinc hker hinj) + exact free_of_surjective_of_ker_free (right f g τ α hdiv hinc) + (right_surjective f g τ α hdiv hinc hg) +end KLInvariance.ReflectionPairTranslation + +end + + +section + +namespace KLInvariance.TitsSpace +open Module ReflectionFrobenius ReflectionPairTranslation +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + theorem bottStalk_free_cons (i : I) (l : List I) + (H : BottKernelExact cs l) + (F : ∀ x : W, Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x)) + (x : W) : Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs (i::l) x) := by + let := F x + let := F (cs.simple i*x) + have hα : simpleRootPolynomial (M := M) i ≠ 0 := + (represents_polynomial_prime cs (simple_represents cs i)).ne_zero + have hlattice : Module.Free (SymmetricCoefficient (M := M)) (bottHeadPairLattice cs i l x) := by + rcases lt_or_gt_of_ne (cs.length_simple_mul_ne x i) with hdesc | hasc + · apply lattice_free_right + (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) + (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) + (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) + · intro z + have hh := H.kernel_iff_of_mul cs (cs.simple i*x) x (cs.simple i) + (simple_represents cs i) (cs.simple_mul_simple_cancel_left i) hdesc z + simpa only [and_comm,simpleRootPolynomial,extendedRoot] using hh + · exact bottStalkProjection_surjective cs l (cs.simple i*x) + · exact bottStalk_smul_injective cs l x hα + · exact lattice_free (bottStalkProjection cs l x) (bottStalkProjection cs l (cs.simple i*x)) + (coefficientAction cs (cs.simple i)).toRingEquiv (simpleRootPolynomial (M := M) i) + (simpleReverseDivisibility cs i) (bottSimpleEdge_kernel_inclusion cs i l x) + (H.kernel_iff cs x (cs.simple i) (simple_represents cs i) hasc) + (bottStalkProjection_surjective cs l x) + (bottStalk_smul_injective cs l (cs.simple i*x) hα) + let := hlattice + exact Module.Free.of_equiv (bottHeadPairEquiv cs i l x) + + theorem bottStalk_nil_subsingleton (x : W) (hx : x≠1) : Subsingleton (bottStalk cs [] x) := by + constructor + intro p q + apply Subtype.ext + funext e + exact False.elim (hx e.property.symm) + + theorem bottStalk_nil_free (x : W) : + Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs [] x) := by + by_cases hx : x=1 + · subst x + exact Module.Free.of_equiv (bottTopStalkEquiv cs [] (by simp [CoxeterSystem.IsReduced])).symm + · let := bottStalk_nil_subsingleton cs x hx + infer_instance + + theorem bottKernelExact_nil : BottKernelExact cs [] := by + intro x t a ha hlt m hm + have hx : t*x≠1 := by + intro h + rw [h] at hlt + rw [cs.length_one] at hlt + exact Nat.not_lt_zero _ hlt + let := bottStalk_nil_subsingleton cs (t*x) hx + exact ⟨0,Subsingleton.elim _ _⟩ + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Pair-projection edges of actual finite graded modules. The hypotheses say +only that the two actual weight projections are homogeneous and surjective. -/ +namespace KLInvariance.Graded.ModuleData +open PairProjection +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {M X Y : ModuleData.{uk,ua,um} 𝓐} + (f : Hom M X) (g : Hom M Y) +noncomputable section + + theorem pairLower_kernel_homogeneous (n : ℤ) (z : X) + (hz : lower f.map g.map z=0) : + lower f.map g.map (component X.piece n z)=0 := by + obtain ⟨m,hm,hy⟩ := (kernel_lower f.map g.map z).mp hz + apply (kernel_lower f.map g.map _).mpr + refine ⟨component M.piece n m,?_,?_⟩ + · rw [← f.component,hm] + · rw [← g.component,hy,map_zero] + + def pairEdgePiece (n : ℤ) : Submodule k (Edge f.map g.map) := + (X.piece n).map ((lower f.map g.map).restrictScalars k) + + def pairEdge (hg : Function.Surjective g.map) : ModuleData.{uk,ua,um} 𝓐 where + obj := ModuleCat.of A (Edge f.map g.map) + kModule := inferInstance + tower := inferInstance + piece := pairEdgePiece f g + decomposition := (image_isInternal X.piece ((lower f.map g.map).restrictScalars k) + (lower_surjective f.map g.map hg) (pairLower_kernel_homogeneous f g)).chooseDecomposition + graded := ⟨by + rintro i j a z ha ⟨w,hw,rfl⟩ + exact ⟨a • w,SetLike.GradedSMul.smul_mem ha hw,map_smul (lower f.map g.map) a w⟩⟩ + nonneg := by + intro n hn + unfold pairEdgePiece + rw [X.nonneg n hn,Submodule.map_bot] + finite := Module.Finite.of_surjective (lower f.map g.map) (lower_surjective f.map g.map hg) + + def pairLower (hg : Function.Surjective g.map) : Hom X (pairEdge f g hg) where + map := lower f.map g.map + graded := fun _ z hz => ⟨z,hz,rfl⟩ + + theorem Hom.homogeneous_lift (hg : Function.Surjective g.map) (n : ℤ) + (y : Y) (hy : y ∈ Y.piece n) : ∃ m : M, m ∈ M.piece n ∧ g.map m=y := by + obtain ⟨m,hm⟩ := hg y + refine ⟨Graded.component M.piece n m,(DirectSum.decompose M.piece m n).property,?_⟩ + rw [← g.component,hm] + exact DirectSum.decompose_of_mem_same Y.piece hy + + def pairUpper (hg : Function.Surjective g.map) : Hom Y (pairEdge f g hg) where + map := upper f.map g.map + graded := by + intro n y hy + obtain ⟨m,hm,rfl⟩ := g.homogeneous_lift hg n y hy + exact ⟨f.map m,f.graded n m hm,compatible f.map g.map m⟩ + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +/-! The genuine projection WORD sheaf with its nonnegative grading and finite +integral stalk/edge modules. No free-stalk, flabbiness, or KL character claim +is smuggled into the grading. The universe here contains both the finite +Coxeter matrix and its standard Coxeter group, as needed by the main reduction. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + +omit [Fintype σ] in + theorem bottStalkPiece_negative (l : List I) (x : W) (n : ℤ) (hn : n<0) : + bottStalkPiece cs basis l x n=⊥ := by + apply subPiece_eq_bot + exact piPiece_eq_bot (fun _ => symmetricGrading basis) n + (fun _ => symmetricGrading_negative basis n hn) + + def bottStalkData (l : List I) (x : W) : ModuleData.{0,u,u} (symmetricGrading basis) where + obj := ModuleCat.of _ (bottStalk cs l x) + kModule := inferInstance + tower := inferInstance + piece := bottStalkPiece cs basis l x + decomposition := inferInstance + graded := inferInstance + nonneg := bottStalkPiece_negative cs basis l x + finite := Module.Finite.of_surjective (bottStalkProjection cs l x) + (bottStalkProjection_surjective cs l x) + + theorem bottPiece_negative (l : List I) (n : ℤ) (hn : n<0) : + bottPiece cs basis l n=⊥ := by + apply bot_unique + intro m hm + change m=0 + apply bottEvaluation_injective cs l + funext e + have h := bottEvaluation_homogeneous cs basis l e n m hm + rw [symmetricGrading_negative basis n hn,Submodule.mem_bot] at h + exact h.trans (map_zero (bottEvaluation cs l e)).symm + + def bottWordData (l : List I) : ModuleData.{0,u,u} (symmetricGrading basis) where + obj := ModuleCat.of _ (BottSamelsonModule cs l) + kModule := inferInstance + tower := inferInstance + piece := bottPiece cs basis l + decomposition := inferInstance + graded := inferInstance + nonneg := bottPiece_negative cs basis l + finite := inferInstance + + def bottStalkHom (l : List I) (x : W) : + ModuleData.Hom (bottWordData cs basis l) (bottStalkData cs basis l x) where + map := bottStalkProjection cs l x + graded := bottStalkProjection_homogeneous cs basis l x + + theorem bottStalkHom_surjective (l : List I) (x : W) : + Function.Surjective (bottStalkHom cs basis l x).map := + bottStalkProjection_surjective cs l x + + def bottEdgeData (l : List I) (x y : W) : ModuleData.{0,u,u} (symmetricGrading basis) := + ModuleData.pairEdge (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) + (bottStalkHom_surjective cs basis l y) + + def bottLowerHom (l : List I) (x y : W) : + ModuleData.Hom (bottStalkData cs basis l x) (bottEdgeData cs basis l x y) := + ModuleData.pairLower (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) + (bottStalkHom_surjective cs basis l y) + + def bottUpperHom (l : List I) (x y : W) : + ModuleData.Hom (bottStalkData cs basis l y) (bottEdgeData cs basis l x y) := + ModuleData.pairUpper (bottStalkHom cs basis l x) (bottStalkHom cs basis l y) + (bottStalkHom_surjective cs basis l y) + + def bottGradedProjectionSheaf (l : List I) (u b : W) : + GradedSheaf (𝓐 := symmetricGrading basis) (graph cs u b) where + vertex x := bottStalkData cs basis l x.val + edge e := bottEdgeData cs basis l (source cs u b e).val (target cs u b e).val + lower e := bottLowerHom cs basis l (source cs u b e).val (target cs u b e).val + upper e := bottUpperHom cs basis l (source cs u b e).val (target cs u b e).val + + theorem bottGradedProjectionSheaf_forget (l : List I) (u b : W) : + (bottGradedProjectionSheaf cs basis l u b).forget=bottProjectionSheaf cs l u b := rfl + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Unconditional integral free stalks and exact oriented edge kernels for +all tensor words. These are the local parts of BMP recognition; flabbiness +and the KL character are not asserted here. -/ +namespace KLInvariance.TitsSpace +open Module MomentGraph BruhatGraph +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) +noncomputable section + + theorem bottStandardStalks (l : List I) : + BottKernelExact cs l ∧ ∀ x : W, + Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x) := by + induction l with + | nil => exact ⟨bottKernelExact_nil cs,bottStalk_nil_free cs⟩ + | cons i l h => exact ⟨bottKernelExact_cons cs i l h.1 h.2, + bottStalk_free_cons cs i l h.1 h.2⟩ + + theorem bottKernelExact (l : List I) : BottKernelExact cs l := (bottStandardStalks cs l).1 + + instance bottStalkFree (l : List I) (x : W) : + Module.Free (SymmetricCoefficient (M := M)) (bottStalk cs l x) := + (bottStandardStalks cs l).2 x + + theorem bottProjectionSheaf_upper_kernel (l : List I) (u b : W) (e : Edge cs u b) + {a : I → ℝ} (ha : Represents M cs (label cs u b e) a) + (z : (bottProjectionSheaf cs l u b).vertex (target cs u b e)) : + (bottProjectionSheaf cs l u b).upper e z=0 ↔ + ∃ w, z=SymmetricAlgebra.ι ℝ (Extended M) (embed M a) • w := by + change PairProjection.upper (bottStalkProjection cs l (source cs u b e).val) + (bottStalkProjection cs l (target cs u b e).val) z=0 ↔ _ + exact (PairProjection.kernel_upper _ _ z).trans + ((bottKernelExact cs l).kernel_iff_of_mul cs _ _ _ ha + (label_mul_source cs u b e) e.property.1 z) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Transport of actual linear-map kernels along a source isomorphism. -/ +namespace KLInvariance +universe ur um un up +variable {R : Type ur} [Ring R] + {M : Type um} [AddCommGroup M] [Module R M] + {N : Type un} [AddCommGroup N] [Module R N] + {P : Type up} [AddCommGroup P] [Module R P] + +def kernelSourceEquiv (f : M →ₗ[R] P) (e : M ≃ₗ[R] N) : + LinearMap.ker f ≃ₗ[R] LinearMap.ker (f.comp e.symm.toLinearMap) where + toFun x := ⟨e x.val,by simpa only [LinearMap.mem_ker,LinearMap.comp_apply, + LinearEquiv.coe_coe,LinearEquiv.symm_apply_apply] using x.property⟩ + invFun y := ⟨e.symm y.val,y.property⟩ + left_inv x := Subtype.ext (e.symm_apply_apply x.val) + right_inv y := Subtype.ext (e.apply_symm_apply y.val) + map_add' x y := Subtype.ext (map_add e x.val y.val) + map_smul' r x := Subtype.ext (map_smul e r x.val) + +end KLInvariance + +end + + +section + +/-! The actual ascent short exact sequence of word stalks has kernel the +upper tail stalk shifted by one. This is the degree-one Hecke normalization. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def bottHeadKernelEquiv (i : I) (l : List I) (x : W) + (h : cs.length x ⟨v.val.val,v.property⟩ + map_add' := fun _ _ => rfl + map_smul' := fun _ _ => rfl } + apply Module.Finite.of_injective f + intro v w h + apply Subtype.ext + apply Subtype.ext + exact congrArg (fun z : 𝓜 n => z.val) h + + variable {ι : Type ui} [Finite ι] {P : ι → Type um} + [∀ i, AddCommGroup (P i)] [∀ i, Module k (P i)] + + instance piPiece_finite (𝓟 : ∀ i, ℤ → Submodule k (P i)) (n : ℤ) + [∀ i, Module.Finite k (𝓟 i n)] : Module.Finite k (piPiece 𝓟 n) := by + let f : piPiece 𝓟 n →ₗ[k] (∀ i, 𝓟 i n) := + { toFun := fun v i => ⟨v.val i,v.property i (Set.mem_univ i)⟩ + map_add' := fun _ _ => rfl + map_smul' := fun _ _ => rfl } + apply Module.Finite.of_injective f + intro v w h + apply Subtype.ext + funext i + exact congrArg Subtype.val (congrFun h i) + +end KLInvariance.Graded + +end + + +section + +/-! The genuine Bott--Samelson stalk Hilbert coefficients satisfy the simple +reflection ascent recurrence. Both exactness and the degree-one kernel shift +were constructed integrally above; no KL character theorem is assumed. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + instance symmetricGrading_finite (n : ℤ) : Module.Finite ℝ (symmetricGrading basis n) := + inferInstanceAs (Module.Finite ℝ ((polynomialGrading ℝ σ n).map + (SymmetricAlgebra.equivMvPolynomial basis).symm.toLinearMap)) + + instance bottCoordinatePiece_finite (l : List I) (x : W) (n : ℤ) : + Module.Finite ℝ (bottCoordinatePiece cs basis l x n) := by + classical + exact piPiece_finite _ n + + instance bottStalkPiece_finite (l : List I) (x : W) (n : ℤ) : + Module.Finite ℝ (bottStalkPiece cs basis l x n) := + inferInstanceAs (Module.Finite ℝ (subPiece (bottCoordinatePiece cs basis l x) (bottStalk cs l x) n)) + + theorem bottStalk_finrank_ascent (i : I) (l : List I) (x : W) + (h : cs.length x rfl } : CoefficientChange e M ≃+ M).module B + instance : Module k (CoefficientChange e M) := + ({ equivVal e M with map_add' := fun _ _ => rfl } : CoefficientChange e M ≃+ M).module k + instance : IsScalarTower k B (CoefficientChange e M) where + smul_assoc c b m := by + apply CoefficientChange.ext + change e.symm (c • b) • m.val=c • (e.symm b • m.val) + rw [map_smul,smul_assoc] + + local instance : RingHomInvPair e.symm.toRingHom e.toRingHom := RingHomInvPair.of_ringEquiv_symm e.toRingEquiv + local instance : RingHomInvPair e.toRingHom e.symm.toRingHom := RingHomInvPair.of_ringEquiv e.toRingEquiv + + def equiv : M ≃ₛₗ[e.toRingHom] CoefficientChange e M where + toFun := mk + invFun := val + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' a m := by + change mk (a • m)=mk (e.symm (e a) • m) + rw [e.symm_apply_apply] + + def kEquiv : M ≃ₗ[k] CoefficientChange e M where + toFun := mk + invFun := val + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + + instance [Module.Free A M] : Module.Free B (CoefficientChange e M) := + Module.Free.of_equiv (equiv e M) + instance [Module.Finite A M] : Module.Finite B (CoefficientChange e M) := + Module.Finite.of_surjective (equiv e M).toLinearMap (equiv e M).surjective + + variable {M} {N : Type un} [AddCommGroup N] [Module A N] [Module k N] [IsScalarTower k A N] + def map (f : M →ₗ[A] N) : CoefficientChange e M →ₗ[B] CoefficientChange e N where + toFun m := mk (f m.val) + map_add' m n := CoefficientChange.ext (map_add f m.val n.val) + map_smul' b m := CoefficientChange.ext (map_smul f (e.symm b) m.val) + + omit [Module k M] [IsScalarTower k A M] [Module k N] [IsScalarTower k A N] in + theorem map_injective (f : M →ₗ[A] N) (hf : Function.Injective f) : + Function.Injective (map e f) := fun _m _n h => CoefficientChange.ext (hf (congrArg val h)) + omit [Module k M] [IsScalarTower k A M] [Module k N] [IsScalarTower k A N] in + theorem map_surjective (f : M →ₗ[A] N) (hf : Function.Surjective f) : + Function.Surjective (map e f) := by + intro n + obtain ⟨m,hm⟩ := hf n.val + exact ⟨mk m,CoefficientChange.ext hm⟩ + +end CoefficientChange +end KLInvariance + +end + + +section + +/-! Grading-preserving coefficient change on the actual finite modules. -/ +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) +noncomputable section + + def changePiece (M : ModuleData.{uk,ua,um} 𝓐) : ℤ → Submodule k (CoefficientChange e M) := + fun n => (M.piece n).map (CoefficientChange.kEquiv e M).toLinearMap + + theorem mem_changePiece (M : ModuleData.{uk,ua,um} 𝓐) (n : ℤ) (m : CoefficientChange e M) : + m ∈ changePiece e M n ↔ m.val ∈ M.piece n := by + constructor + · rintro ⟨x,hx,hxm⟩ + change CoefficientChange.mk x=m at hxm + exact (congrArg CoefficientChange.val hxm) ▸ hx + · intro hm + exact ⟨m.val,hm,rfl⟩ + + def change (M : ModuleData.{uk,ua,um} 𝓐) : ModuleData.{uk,ua,um} 𝓑 where + obj := ModuleCat.of B (CoefficientChange e M) + kModule := inferInstance + tower := inferInstance + piece := changePiece e M + decomposition := by + apply DirectSum.IsInternal.chooseDecomposition + apply image_isInternal M.piece (CoefficientChange.kEquiv e M).toLinearMap + (CoefficientChange.kEquiv e M).surjective + intro n m hm + have hz : m=0 := congrArg CoefficientChange.val hm + subst m + simp only [map_zero] + graded := by + constructor + intro i j b m hb hm + apply (mem_changePiece e M (i+j) _).mpr + change e.symm b • m.val ∈ M.piece (i+j) + have ha : e.symm b ∈ 𝓐 i := (he i _).mpr (by simpa using hb) + exact SetLike.GradedSMul.smul_mem ha ((mem_changePiece e M j m).mp hm) + nonneg n hn := by simp only [changePiece,M.nonneg n hn,Submodule.map_bot] + finite := inferInstance + + def changeHom {M N : ModuleData.{uk,ua,um} 𝓐} (f : Hom M N) : + Hom (change e he M) (change e he N) where + map := CoefficientChange.map e f.map + graded n m hm := (mem_changePiece e N n _).mpr + (f.graded n m.val ((mem_changePiece e M n m).mp hm)) + + theorem change_free (M : ModuleData.{uk,ua,um} 𝓐) [Module.Free A M] : + Module.Free B (change e he M) := inferInstanceAs (Module.Free B (CoefficientChange e M)) + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +/-! The genuine nonnegative polynomial generator character of word stalks, +with its convergent Hilbert-series interpretation. No KL identification is +asserted or included in the definition. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def bottPolynomialStalkData (l : List I) (x : W) : + ModuleData.{0,u,u} (polynomialGrading ℝ σ) := + ModuleData.change (SymmetricAlgebra.equivMvPolynomial basis) (mem_symmetricGrading basis) + (bottStalkData cs basis l x) + + instance bottPolynomialStalkFree (l : List I) (x : W) : + Module.Free (MvPolynomial σ ℝ) (bottPolynomialStalkData cs basis l x) := + inferInstanceAs (Module.Free (MvPolynomial σ ℝ) + (CoefficientChange (SymmetricAlgebra.equivMvPolynomial basis) (bottStalk cs l x))) + + def bottStalkCharacter (l : List I) (x : W) : Polynomial ℤ := + Graded.character (σ := σ) (bottPolynomialStalkData cs basis l x).piece + (bottPolynomialStalkData cs basis l x).nonneg + + theorem bottPolynomialStalk_finrank (l : List I) (x : W) (n : ℤ) : + Module.finrank ℝ ((bottPolynomialStalkData cs basis l x).piece n)= + Module.finrank ℝ (bottStalkPiece cs basis l x n) := + LinearEquiv.finrank_map_eq + (CoefficientChange.kEquiv (SymmetricAlgebra.equivMvPolynomial basis) + (bottStalkData cs basis l x)) _ + + theorem bottStalkCharacter_hasSum (l : List I) (x : W) {q : ℝ} + (hq : 0 (Module.finrank ℝ (bottStalkPiece cs basis l x n) : ℝ)*q^n) + (Polynomial.eval₂ (Int.castRingHom ℝ) q (bottStalkCharacter cs basis l x) * + (1-q)⁻¹ ^ Fintype.card σ) := by + have hh := (exists_nonnegativeBasis (k := ℝ) (σ := σ) (𝓜 := (bottPolynomialStalkData cs basis l x).piece) + (bottPolynomialStalkData cs basis l x).nonneg).some.hasSum hq hq1 + apply hh.congr_fun + intro n + rw [bottPolynomialStalk_finrank] + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance +universe ur um un up +variable {R : Type ur} [Ring R] + {M : Type um} [AddCommGroup M] [Module R M] + {N : Type un} [AddCommGroup N] [Module R N] + {P : Type up} [AddCommGroup P] [Module R P] + +def kernelTargetEquiv (f : M →ₗ[R] N) (e : N ≃ₗ[R] P) : + LinearMap.ker f ≃ₗ[R] LinearMap.ker (e.toLinearMap.comp f) where + toFun x := ⟨x.val, by + change e (f x.val)=0 + rw [LinearMap.mem_ker.mp x.property,map_zero]⟩ + invFun y := ⟨y.val, by + apply e.injective + simpa only [LinearMap.comp_apply,LinearEquiv.coe_coe,map_zero] using (LinearMap.mem_ker.mp y.property)⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + +end KLInvariance + +end + + +section + +namespace KLInvariance +universe uk ua um un up uq +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {M : Type um} [AddCommGroup M] [Module k M] [Module A M] [IsScalarTower k A M] + {N : Type un} [AddCommGroup N] [Module k N] [Module A N] [IsScalarTower k A N] + {P : Type up} [AddCommGroup P] [Module k P] [Module A P] [IsScalarTower k A P] + {Q : Type uq} [AddCommGroup Q] [Module k Q] + +def kernelMixedEquiv (f : M →ₗ[A] P) (e : M ≃ₗ[A] N) (g : P ≃ₗ[k] Q) : + LinearMap.ker f ≃ₗ[k] LinearMap.ker + (g.toLinearMap.comp ((f.comp e.symm.toLinearMap).restrictScalars k)) where + toFun x := ⟨e x.val, by + change g (f (e.symm (e x.val)))=0 + rw [e.symm_apply_apply,LinearMap.mem_ker.mp x.property,map_zero]⟩ + invFun y := ⟨e.symm y.val, by + apply g.injective + have hy : g (f (e.symm y.val))=0 := y.property + simpa only [map_zero] using hy⟩ + left_inv x := Subtype.ext (e.symm_apply_apply x.val) + right_inv y := Subtype.ext (e.apply_symm_apply y.val) + map_add' x y := Subtype.ext (map_add e x.val y.val) + map_smul' c x := Subtype.ext (map_smul (e.restrictScalars k) c x.val) + +end KLInvariance + +end + + +section + +/-! The descent short exact sequence for the actual word projection lattice. +Its kernel has the genuine degree-one shift, over the unchanged realization. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded ReflectionPairTranslation +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottHeadRight_surjective (i : I) (l : List I) (x : W) : + Function.Surjective (bottHeadRight cs i l x) := + (Twist.scalarEquiv (coefficientAction cs (cs.simple i)) _).surjective.comp + ((right_surjective _ _ _ _ _ _ (bottStalkProjection_surjective cs l (cs.simple i*x))).comp + (bottHeadPairEquiv cs i l x).symm.surjective) + + theorem bottDescentKernel (i : I) (l : List I) (x : W) + (h : cs.length (cs.simple i*x) exact le_rfl - | head hstep _ ih => exact le_trans hstep.1.le ih - -theorem length_lt_of_bruhat_ne (cs : CoxeterSystem M W) {x y : W} - (h : BruhatLE cs x y) (hne : x ≠ y) : cs.length x < cs.length y := by - rcases h.cases_head with heq | ⟨z, hxz, hzy⟩ - · exact (hne heq).elim - · exact lt_of_lt_of_le hxz.1 (length_le_of_bruhat cs hzy) - -theorem bruhat_antisymm (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatLE cs x y) (hyx : BruhatLE cs y x) : x = y := by - by_contra hne - exact (not_lt_of_ge (length_le_of_bruhat cs hyx)) (length_lt_of_bruhat_ne cs hxy hne) - -end KLInvariance - -namespace KLInvariance - -open Polynomial - -universe u v u' v' - -variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} - - -noncomputable def rPolynomial (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := - (klFamilies cs).1 x y - -end KLInvariance - -section - - -namespace KLInvariance - -open Polynomial - -universe u v u' v' - -variable {B : Type u} {W : Type v} [klPreservedInstance1 : Group W] {M : CoxeterMatrix B} - - -/-- A vertex has only finitely many incoming strong Bruhat edges, using -strong exchange proved from the Coxeter presentation above. -/ -theorem finite_bruhat_predecessors (cs : CoxeterSystem M W) (b : W) : - {x : W | BruhatStep cs x b}.Finite := by - classical - obtain ⟨ω, hω, heq⟩ := cs.exists_isReduced b - refine ((cs.leftInvSeq ω).finite_toSet.image (fun t => t * b)).subset ?_ - rintro x ⟨hlen, t, href, hb⟩ - have hx : t * b = x := by - rw [hb, ← mul_assoc, href.mul_self, one_mul] - refine ⟨t, ?_, hx⟩ - apply CoxeterSupport.mem_leftInvSeq_of_inversion cs hω - exact ⟨href, by rw [← heq, hx]; exact hlen⟩ - -/-- Finiteness of all lower Bruhat ideals, with no finite-rank assumption. -/ -theorem finite_bruhat_lower (cs : CoxeterSystem M W) (b : W) : - {x : W | BruhatLE cs x b}.Finite := by - classical - suffices ∀ n : ℕ, ∀ b : W, cs.length b = n → {x : W | BruhatLE cs x b}.Finite by - exact this (cs.length b) b rfl - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro b hb - have hfinite : ({b} ∪ ⋃ z ∈ {z : W | BruhatStep cs z b}, - {x : W | BruhatLE cs x z}).Finite := - (Set.finite_singleton b).union ((finite_bruhat_predecessors cs b).biUnion - (fun z hz => ih (cs.length z) (hb ▸ hz.1) z rfl)) - apply hfinite.subset - intro x hx - rcases hx.cases_tail with h | ⟨z, hxz, hzb⟩ - · exact Or.inl (h.symm) - · exact Or.inr (Set.mem_iUnion.mpr ⟨z, Set.mem_iUnion.mpr ⟨hzb, hxz⟩⟩) - -/-- The finite-interval obligation in the faithful trusted main target. -/ -theorem interval_finite (cs : CoxeterSystem M W) (u b : W) : - Finite (Interval cs u b) := - ((finite_bruhat_lower cs b).subset (fun _ hx => hx.2)).to_subtype - -/-- The exact R recursion determines at most one R family. -/ -theorem normalized_R_unique (cs : CoxeterSystem M W) - {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : - RP.1 = SQ.1 := by - classical - suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, RP.1 x y = SQ.1 x y by - funext x y - exact this (cs.length y) y rfl x - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro y hy x - by_cases h1 : y = 1 - · subst y - by_cases hx : x = 1 - · subst x - rw [hRP.R_diagonal, hSQ.R_diagonal] - · have hn : ¬ BruhatLE cs x 1 := by - intro h - have hl := length_le_of_bruhat cs h - have hx0 : cs.length x = 0 := by simpa using hl - exact hx (cs.length_eq_zero_iff.mp hx0) - rw [hRP.R_zero _ _ hn, hSQ.R_zero _ _ hn] - · obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one h1 - have hlt : cs.length (cs.simple i * y) < n := hy ▸ hi - rw [hRP.R_recursion x y i hi, hSQ.R_recursion x y i hi] - rw [ih _ hlt _ rfl x, ih _ hlt _ rfl (cs.simple i * x)] - -/-- The degree/reciprocity rigidity used both by normalization uniqueness and -by the final main-theorem induction: no polynomial supported strictly below -the midpoint can be self-reciprocal about that midpoint. -/ -theorem low_degree_reflect_eq_self (f : ℤ[X]) (d : ℕ) - (hd : 2 * f.natDegree < d) (hself : reflect d f = f) : f = 0 := by - by_contra hn - have hc := congrArg (fun p : ℤ[X] => p.coeff f.natDegree) hself - rw [coeff_reflect, revAt_le (by omega)] at hc - rw [coeff_eq_zero_of_natDegree_lt (by omega), coeff_natDegree] at hc - exact (leadingCoeff_ne_zero.mpr hn) hc.symm - -/-- The polynomial part of the manuscript's normalization is unique; the -proof uses the actual finite strong-Bruhat intervals, not extra assumptions. -/ -theorem normalized_P_unique (cs : CoxeterSystem M W) - {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : - RP.2 = SQ.2 := by - classical - have hR := normalized_R_unique cs hRP hSQ - suffices ∀ n : ℕ, ∀ x y : W, rankDifference cs x y = n → RP.2 x y = SQ.2 x y by - funext x y - exact this (rankDifference cs x y) x y rfl - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro x y hxy - by_cases hcomp : BruhatLE cs x y - · by_cases heq : x = y - · subst y - rw [hRP.P_diagonal, hSQ.P_diagonal] - · let : Finite (Interval cs x y) := interval_finite cs x y - let : Fintype (Interval cs x y) := Fintype.ofFinite _ - let bottom : Interval cs x y := ⟨x, bruhat_refl cs x, hcomp⟩ - have hsum : (∑ z : Interval cs x y, - RP.1 x z.val * (RP.2 z.val y - SQ.2 z.val y)) = RP.2 x y - SQ.2 x y := by - rw [Finset.sum_eq_single bottom] - · simp [bottom, hRP.R_diagonal] - · intro z _ hz - have hxz : x ≠ z.val := by - intro hc - apply hz - exact Subtype.ext hc.symm - have hlt := length_lt_of_bruhat_ne cs z.property.1 hxz - have hle := length_le_of_bruhat cs z.property.2 - have hdiff : rankDifference cs z.val y < n := by - dsimp [rankDifference] at hxy ⊢ - omega - rw [ih _ hdiff z.val y rfl, sub_self, mul_zero] - · simp - have href : reflect (rankDifference cs x y) (RP.2 x y - SQ.2 x y) = - RP.2 x y - SQ.2 x y := by - rw [reflect_sub, hRP.reciprocity x y hcomp, hSQ.reciprocity x y hcomp, - finsum_eq_sum_of_fintype, finsum_eq_sum_of_fintype, ← Finset.sum_sub_distrib] - rw [← hsum] - apply Finset.sum_congr rfl - intro z _ - rw [← hR, mul_sub] - have hd1 := hRP.P_degree x y hcomp heq - have hd2 := hSQ.P_degree x y hcomp heq - have hdeg := natDegree_sub_le (RP.2 x y) (SQ.2 x y) - have hzero := low_degree_reflect_eq_self (RP.2 x y - SQ.2 x y) - (rankDifference cs x y) (by omega) href - exact sub_eq_zero.mp hzero - · rw [hRP.P_zero _ _ hcomp, hSQ.P_zero _ _ hcomp] - -/-- Unique existence is still a separate obligation: this proves its -uniqueness half only, without postulating a normalized family. -/ -theorem normalizedKL_unique (cs : CoxeterSystem M W) - {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : - RP = SQ := - Prod.ext (normalized_R_unique cs hRP hSQ) (normalized_P_unique cs hRP hSQ) - - -/-! Exchange consequences required for the source's finite-rank reduction -and for consistency of the equal-parameter Hecke recursion. -/ - -/-- Every word contains a reduced subword with the same product. -/ -theorem exists_reduced_subword (cs : CoxeterSystem M W) (ω : List B) : - ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = cs.wordProd ω := by - induction ω with - | nil => exact ⟨[], .refl _, by simp [CoxeterSystem.IsReduced], rfl⟩ - | cons i ω ih => - obtain ⟨ν, hsub, hν, heq⟩ := ih - rcases cs.length_simple_mul (cs.wordProd ν) i with hasc | hdesc - · refine ⟨i :: ν, hsub.cons_cons i, ?_, ?_⟩ - · simpa [CoxeterSystem.IsReduced, cs.wordProd_cons, hν.eq] using hasc - · simp [cs.wordProd_cons, heq] - · obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hν - ⟨cs.isReflection_simple i, by omega⟩ - refine ⟨ν.eraseIdx j, ((ν.eraseIdx_sublist j).trans hsub).cons i, ?_, ?_⟩ - · dsimp [CoxeterSystem.IsReduced] - rw [← hdel, List.length_eraseIdx, ite_eq_left hj] - have := hν.eq - omega - · rw [← hdel, heq, cs.wordProd_cons] - -/-- A single downward reflection step can be realized inside any reduced word. -/ -theorem subword_of_bruhat_step (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatStep cs x y) {ω : List B} (hω : cs.IsReduced ω) - (hy : cs.wordProd ω = y) : - ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by - obtain ⟨hlen, t, ht, rfl⟩ := hxy - have hx : t * cs.wordProd ω = x := by simp [hy, ← mul_assoc, ht.mul_self] - obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hω - ⟨ht, by - rw [hx, hy] - exact hlen⟩ - obtain ⟨ν, hsub, hν, heq⟩ := exists_reduced_subword cs (ω.eraseIdx j) - exact ⟨ν, hsub.trans (ω.eraseIdx_sublist j), hν, heq.trans (hdel.symm.trans hx)⟩ - -/-- Forward subword property, for every chosen reduced expression of the top. -/ -theorem reduced_subword_of_bruhat (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatLE cs x y) {ω : List B} (hω : cs.IsReduced ω) - (hy : cs.wordProd ω = y) : - ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by - induction hxy using Relation.ReflTransGen.head_induction_on generalizing ω with - | refl => exact ⟨ω, .refl _, hω, hy⟩ - | head hstep _ ih => - obtain ⟨ν, hsub, hν, heq⟩ := ih hω hy - obtain ⟨μ, hμsub, hμ, hμeq⟩ := subword_of_bruhat_step cs hstep hν heq - exact ⟨μ, hμsub.trans hsub, hμ, hμeq⟩ - - -/-- Simple left multiplication preserves the orientation of every reflection -edge except the edge carrying that simple reflection itself. -/ -theorem bruhatStep_simple_mul (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatStep cs x y) (i : B) (hne : y ≠ cs.simple i * x) : - BruhatStep cs (cs.simple i * x) (cs.simple i * y) := by - obtain ⟨hlen, t, ht, heq⟩ := hxy - refine ⟨?_, cs.simple i * t * cs.simple i, by simpa using ht.conj (cs.simple i), ?_⟩ - · rcases cs.length_simple_mul y i with hasc | hdesc - · have hx := cs.length_simple_mul x i - omega - · obtain ⟨ω, hω, hωeq⟩ := cs.exists_isReduced (cs.simple i * y) - have hprod : cs.wordProd (i :: ω) = y := by - rw [cs.wordProd_cons, ← hωeq, cs.simple_mul_simple_cancel_left] - have hr : cs.IsReduced (i :: ω) := by - dsimp [CoxeterSystem.IsReduced] - rw [hprod, ← hω.eq, ← hωeq] - exact hdesc.symm - have htx : t * cs.wordProd (i :: ω) = x := by - rw [hprod, heq, ← mul_assoc, ht.mul_self, one_mul] - obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hr - ⟨ht, by rw [htx, hprod]; exact hlen⟩ - cases j with - | zero => - have hx : x = cs.wordProd ω := by simpa [htx] using hdel - exact (hne (by rw [hx, ← cs.wordProd_cons, hprod])).elim - | succ j => - have hx : x = cs.simple i * cs.wordProd (ω.eraseIdx j) := by - rw [htx, List.eraseIdx_cons_succ, cs.wordProd_cons] at hdel - exact hdel - have hsx : cs.simple i * x = cs.wordProd (ω.eraseIdx j) := by simp [hx] - have hj' : j < ω.length := by simpa using hj - have hlen' := cs.length_wordProd_le (ω.eraseIdx j) - rw [List.length_eraseIdx, ite_eq_left hj'] at hlen' - rw [hsx, hωeq, hω.eq] - omega - · rw [heq] - simp [mul_assoc] - -/-- The smaller of `x` and `s*x` in Bruhat order. -/ -noncomputable def lowerSimple (cs : CoxeterSystem M W) (i : B) (x : W) : W := - if cs.length (cs.simple i * x) < cs.length x then cs.simple i * x else x - -/-- The larger of `x` and `s*x` in Bruhat order. -/ -noncomputable def upperSimple (cs : CoxeterSystem M W) (i : B) (x : W) : W := - if cs.length (cs.simple i * x) < cs.length x then x else cs.simple i * x - -theorem lowerSimple_le (cs : CoxeterSystem M W) (i : B) (x : W) : - BruhatLE cs (lowerSimple cs i x) x := by - classical - unfold lowerSimple - split_ifs with h - · exact .single ⟨h, cs.simple i, cs.isReflection_simple i, by simp⟩ - · exact .refl - -theorem le_upperSimple (cs : CoxeterSystem M W) (i : B) (x : W) : - BruhatLE cs x (upperSimple cs i x) := by - classical - unfold upperSimple - split_ifs with h - · exact .refl - · exact .single ⟨by have := cs.length_simple_mul x i; omega, - cs.simple i, cs.isReflection_simple i, rfl⟩ - -@[simp] theorem lowerSimple_mul (cs : CoxeterSystem M W) (i : B) (x : W) : - lowerSimple cs i (cs.simple i * x) = lowerSimple cs i x := by - classical - unfold lowerSimple - rw [cs.simple_mul_simple_cancel_left] - have := cs.length_simple_mul x i - split_ifs <;> first | rfl | omega - -@[simp] theorem upperSimple_mul (cs : CoxeterSystem M W) (i : B) (x : W) : - upperSimple cs i (cs.simple i * x) = upperSimple cs i x := by - classical - unfold upperSimple - rw [cs.simple_mul_simple_cancel_left] - have := cs.length_simple_mul x i - split_ifs <;> first | rfl | omega - -theorem lowerSimple_step_mono (cs : CoxeterSystem M W) (i : B) {x y : W} - (hxy : BruhatStep cs x y) : - BruhatLE cs (lowerSimple cs i x) (lowerSimple cs i y) := by - classical - by_cases heq : y = cs.simple i * x - · rw [heq, lowerSimple_mul] - exact .refl - · have hs := bruhatStep_simple_mul cs hxy i heq - by_cases hx : cs.length (cs.simple i * x) < cs.length x - · by_cases hy : cs.length (cs.simple i * y) < cs.length y - · simp only [lowerSimple, ite_eq_left hx, ite_eq_left hy] - exact .single hs - · simp only [lowerSimple, ite_eq_left hx, ite_eq_right hy] - have hlow := lowerSimple_le cs i x - simp only [lowerSimple, ite_eq_left hx] at hlow - exact hlow.trans (.single hxy) - · by_cases hy : cs.length (cs.simple i * y) < cs.length y - · simp only [lowerSimple, ite_eq_right hx, ite_eq_left hy] - have hupp := le_upperSimple cs i x - simp only [upperSimple, ite_eq_right hx] at hupp - exact hupp.trans (.single hs) - · simp only [lowerSimple, ite_eq_right hx, ite_eq_right hy] - exact .single hxy - -theorem upperSimple_step_mono (cs : CoxeterSystem M W) (i : B) {x y : W} - (hxy : BruhatStep cs x y) : - BruhatLE cs (upperSimple cs i x) (upperSimple cs i y) := by - classical - by_cases heq : y = cs.simple i * x - · rw [heq, upperSimple_mul] - exact .refl - · have hs := bruhatStep_simple_mul cs hxy i heq - by_cases hx : cs.length (cs.simple i * x) < cs.length x - · by_cases hy : cs.length (cs.simple i * y) < cs.length y - · simp only [upperSimple, ite_eq_left hx, ite_eq_left hy] - exact .single hxy - · simp only [upperSimple, ite_eq_left hx, ite_eq_right hy] - have hupp := le_upperSimple cs i y - simp only [upperSimple, ite_eq_right hy] at hupp - exact (Relation.ReflTransGen.single hxy).trans hupp - · by_cases hy : cs.length (cs.simple i * y) < cs.length y - · simp only [upperSimple, ite_eq_right hx, ite_eq_left hy] - have hlow := lowerSimple_le cs i y - simp only [lowerSimple, ite_eq_left hy] at hlow - exact (Relation.ReflTransGen.single hs).trans hlow - · simp only [upperSimple, ite_eq_right hx, ite_eq_right hy] - exact .single hs - -theorem lowerSimple_mono (cs : CoxeterSystem M W) (i : B) {x y : W} - (hxy : BruhatLE cs x y) : - BruhatLE cs (lowerSimple cs i x) (lowerSimple cs i y) := by - induction hxy using Relation.ReflTransGen.head_induction_on with - | refl => exact .refl - | head hstep _ ih => exact (lowerSimple_step_mono cs i hstep).trans ih - -theorem upperSimple_mono (cs : CoxeterSystem M W) (i : B) {x y : W} - (hxy : BruhatLE cs x y) : - BruhatLE cs (upperSimple cs i x) (upperSimple cs i y) := by - induction hxy using Relation.ReflTransGen.head_induction_on with - | refl => exact .refl - | head hstep _ ih => exact (upperSimple_step_mono cs i hstep).trans ih - - -/-- The standard lifting property, now for the actual strong order. -/ -theorem bruhat_lifting (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatLE cs x y) (i : B) - (hx : cs.length x < cs.length (cs.simple i * x)) - (hy : cs.length (cs.simple i * y) < cs.length y) : - BruhatLE cs x (cs.simple i * y) ∧ BruhatLE cs (cs.simple i * x) y := by - have hx' : ¬cs.length (cs.simple i * x) < cs.length x := by omega - constructor - · simpa only [lowerSimple, ite_eq_right hx', ite_eq_left hy] using lowerSimple_mono cs i hxy - · simpa only [upperSimple, ite_eq_right hx', ite_eq_left hy] using upperSimple_mono cs i hxy - -/-- Converse subword property; no labels are added to Bruhat intervals. -/ -theorem bruhat_of_subword (cs : CoxeterSystem M W) {ν ω : List B} - (hsub : ν.Sublist ω) (hω : cs.IsReduced ω) : - BruhatLE cs (cs.wordProd ν) (cs.wordProd ω) := by - induction ω generalizing ν with - | nil => - have : ν = [] := List.sublist_nil.mp hsub - subst ν - exact .refl - | cons i ω ih => - have hω' : cs.IsReduced ω := by simpa using hω.drop 1 - have hasc : cs.length (cs.simple i * cs.wordProd ω) = cs.length (cs.wordProd ω) + 1 := by - simpa [CoxeterSystem.IsReduced, cs.wordProd_cons, hω'.eq] using hω.eq - have htop : upperSimple cs i (cs.wordProd ω) = cs.wordProd (i :: ω) := by - simp [upperSimple, show ¬cs.length (cs.simple i * cs.wordProd ω) < - cs.length (cs.wordProd ω) by omega, cs.wordProd_cons] - rcases List.sublist_cons_iff.mp hsub with hsub' | ⟨μ, rfl, hμsub⟩ - · exact (ih hsub' hω').trans (htop ▸ le_upperSimple cs i (cs.wordProd ω)) - · have hle := upperSimple_mono cs i (ih hμsub hω') - rw [htop] at hle - have hx := le_upperSimple cs i (cs.simple i * cs.wordProd μ) - rw [upperSimple_mul] at hx - rw [cs.wordProd_cons] - exact hx.trans hle - -/-- The subword criterion with an arbitrary fixed reduced word for the top. -/ -theorem bruhat_iff_reduced_subword (cs : CoxeterSystem M W) {x : W} {ω : List B} - (hω : cs.IsReduced ω) : - BruhatLE cs x (cs.wordProd ω) ↔ - ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by - constructor - · intro hx - exact reduced_subword_of_bruhat cs hx hω rfl - · rintro ⟨ν, hsub, _, rfl⟩ - exact bruhat_of_subword cs hsub hω - -/-- Precisely the finite-support part used by the manuscript's finite-rank -reduction: all lower elements are words in the generators of any reduced top -word. Equality of parabolic polynomial normalizations remains a later step. -/ -theorem lower_ideal_finite_generator_support (cs : CoxeterSystem M W) (b : W) : - ∃ J : Set B, J.Finite ∧ ∀ x, BruhatLE cs x b → - ∃ ν : List B, (∀ i ∈ ν, i ∈ J) ∧ cs.wordProd ν = x := by - obtain ⟨ω, hω, heq⟩ := cs.exists_isReduced b - refine ⟨{i | i ∈ ω}, ω.finite_toSet, ?_⟩ - intro x hx - obtain ⟨ν, hsub, _, hprod⟩ := reduced_subword_of_bruhat cs hx hω heq.symm - exact ⟨ν, fun i hi => hsub.subset hi, hprod⟩ - - -/-- Inversion preserves the actual strong Bruhat graph. -/ -theorem bruhatStep_inv (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatStep cs x y) : BruhatStep cs x⁻¹ y⁻¹ := by - obtain ⟨hlen, t, ht, heq⟩ := hxy - refine ⟨by simpa using hlen, x⁻¹ * t * x, by simpa using ht.conj x⁻¹, ?_⟩ - rw [heq, mul_inv_rev, ht.inv] - group - -theorem bruhatStep_mul_simple (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatStep cs x y) (i : B) (hne : y ≠ x * cs.simple i) : - BruhatStep cs (x * cs.simple i) (y * cs.simple i) := by - have hinv := bruhatStep_inv cs hxy - have hne' : y⁻¹ ≠ cs.simple i * x⁻¹ := by - intro heq - apply hne - have := congrArg Inv.inv heq - simpa [mul_inv_rev] using this - have h := bruhatStep_inv cs (bruhatStep_simple_mul cs hinv i hne') - simpa [mul_inv_rev] using h - -/-- The noncollapsed left/right simple square has consistent orientations. -/ -theorem left_descent_mul_simple_iff (cs : CoxeterSystem M W) (i j : B) (x : W) - (hne : cs.simple i * x ≠ x * cs.simple j) : - cs.length (cs.simple i * (x * cs.simple j)) < cs.length (x * cs.simple j) ↔ - cs.length (cs.simple i * x) < cs.length x := by - by_cases hx : cs.length (cs.simple i * x) < cs.length x - · have hedge : BruhatStep cs (cs.simple i * x) x := - ⟨hx, cs.simple i, cs.isReflection_simple i, by simp⟩ - have hne' : x ≠ cs.simple i * x * cs.simple j := by - intro heq - apply hne - have := congrArg (fun z => z * cs.simple j) heq - simpa using this.symm - have h := (bruhatStep_mul_simple cs hedge j hne').1 - simpa only [mul_assoc, hx, iff_true] using h - · have hedge : BruhatStep cs x (cs.simple i * x) := - ⟨by have := cs.length_simple_mul x i; omega, cs.simple i, - cs.isReflection_simple i, rfl⟩ - have h := (bruhatStep_mul_simple cs hedge j hne).1 - rw [mul_assoc] at h - exact iff_of_false (by omega) hx - -theorem right_descent_simple_mul_iff (cs : CoxeterSystem M W) (i j : B) (x : W) - (hne : cs.simple i * x ≠ x * cs.simple j) : - cs.length (cs.simple i * x * cs.simple j) < cs.length (cs.simple i * x) ↔ - cs.length (x * cs.simple j) < cs.length x := by - have hne' : cs.simple j * x⁻¹ ≠ x⁻¹ * cs.simple i := by - intro heq - apply hne - have h := congrArg Inv.inv heq - simpa [mul_inv_rev] using h.symm - have h := left_descent_mul_simple_iff cs j i x⁻¹ hne' - have h1 : cs.length (cs.simple i * x * cs.simple j) = - cs.length (cs.simple j * (x⁻¹ * cs.simple i)) := by - rw [← cs.length_inv (cs.simple i * x * cs.simple j)] - simp [mul_inv_rev] - have h2 : cs.length (cs.simple i * x) = cs.length (x⁻¹ * cs.simple i) := by - rw [← cs.length_inv (cs.simple i * x)] - simp [mul_inv_rev] - have h3 : cs.length (x * cs.simple j) = cs.length (cs.simple j * x⁻¹) := by - rw [← cs.length_inv (x * cs.simple j)] - simp [mul_inv_rev] - rw [h1, h2, h3] - simpa using h - - -end KLInvariance -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.Model +import OAI.RepresentationTheory.KazhdanLusztig.Coxeter + +namespace OAI + +/-! +Strong Bruhat order, subwords, length, finite lower ideals and arbitrary finite intervals; the selected R family. +-/ + +namespace KLInvariance + +open Polynomial + +universe u v u' v' + +variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} + + +theorem bruhat_refl (cs : CoxeterSystem M W) (x : W) : BruhatLE cs x x := + Relation.ReflTransGen.refl + +theorem bruhat_trans (cs : CoxeterSystem M W) {x y z : W} + (hxy : BruhatLE cs x y) (hyz : BruhatLE cs y z) : BruhatLE cs x z := + hxy.trans hyz + +theorem length_le_of_bruhat (cs : CoxeterSystem M W) {x y : W} + (h : BruhatLE cs x y) : cs.length x ≤ cs.length y := by + induction h using Relation.ReflTransGen.head_induction_on with + | refl => exact le_rfl + | head hstep _ ih => exact le_trans hstep.1.le ih + +theorem length_lt_of_bruhat_ne (cs : CoxeterSystem M W) {x y : W} + (h : BruhatLE cs x y) (hne : x ≠ y) : cs.length x < cs.length y := by + rcases h.cases_head with heq | ⟨z, hxz, hzy⟩ + · exact (hne heq).elim + · exact lt_of_lt_of_le hxz.1 (length_le_of_bruhat cs hzy) + +theorem bruhat_antisymm (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatLE cs x y) (hyx : BruhatLE cs y x) : x = y := by + by_contra hne + exact (not_lt_of_ge (length_le_of_bruhat cs hyx)) (length_lt_of_bruhat_ne cs hxy hne) + +end KLInvariance + +namespace KLInvariance + +open Polynomial + +universe u v u' v' + +variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} + + +noncomputable def rPolynomial (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := + (klFamilies cs).1 x y + +end KLInvariance + +section + + +namespace KLInvariance + +open Polynomial + +universe u v u' v' + +variable {B : Type u} {W : Type v} [klPreservedInstance1 : Group W] {M : CoxeterMatrix B} + + +/-- A vertex has only finitely many incoming strong Bruhat edges, using +strong exchange proved from the Coxeter presentation above. -/ +theorem finite_bruhat_predecessors (cs : CoxeterSystem M W) (b : W) : + {x : W | BruhatStep cs x b}.Finite := by + classical + obtain ⟨ω, hω, heq⟩ := cs.exists_isReduced b + refine ((cs.leftInvSeq ω).finite_toSet.image (fun t => t * b)).subset ?_ + rintro x ⟨hlen, t, href, hb⟩ + have hx : t * b = x := by + rw [hb, ← mul_assoc, href.mul_self, one_mul] + refine ⟨t, ?_, hx⟩ + apply CoxeterSupport.mem_leftInvSeq_of_inversion cs hω + exact ⟨href, by rw [← heq, hx]; exact hlen⟩ + +/-- Finiteness of all lower Bruhat ideals, with no finite-rank assumption. -/ +theorem finite_bruhat_lower (cs : CoxeterSystem M W) (b : W) : + {x : W | BruhatLE cs x b}.Finite := by + classical + suffices ∀ n : ℕ, ∀ b : W, cs.length b = n → {x : W | BruhatLE cs x b}.Finite by + exact this (cs.length b) b rfl + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro b hb + have hfinite : ({b} ∪ ⋃ z ∈ {z : W | BruhatStep cs z b}, + {x : W | BruhatLE cs x z}).Finite := + (Set.finite_singleton b).union ((finite_bruhat_predecessors cs b).biUnion + (fun z hz => ih (cs.length z) (hb ▸ hz.1) z rfl)) + apply hfinite.subset + intro x hx + rcases hx.cases_tail with h | ⟨z, hxz, hzb⟩ + · exact Or.inl (h.symm) + · exact Or.inr (Set.mem_iUnion.mpr ⟨z, Set.mem_iUnion.mpr ⟨hzb, hxz⟩⟩) + +/-- The finite-interval obligation in the faithful trusted main target. -/ +theorem interval_finite (cs : CoxeterSystem M W) (u b : W) : + Finite (Interval cs u b) := + ((finite_bruhat_lower cs b).subset (fun _ hx => hx.2)).to_subtype + +/-- The exact R recursion determines at most one R family. -/ +theorem normalized_R_unique (cs : CoxeterSystem M W) + {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : + RP.1 = SQ.1 := by + classical + suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, RP.1 x y = SQ.1 x y by + funext x y + exact this (cs.length y) y rfl x + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro y hy x + by_cases h1 : y = 1 + · subst y + by_cases hx : x = 1 + · subst x + rw [hRP.R_diagonal, hSQ.R_diagonal] + · have hn : ¬ BruhatLE cs x 1 := by + intro h + have hl := length_le_of_bruhat cs h + have hx0 : cs.length x = 0 := by simpa using hl + exact hx (cs.length_eq_zero_iff.mp hx0) + rw [hRP.R_zero _ _ hn, hSQ.R_zero _ _ hn] + · obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one h1 + have hlt : cs.length (cs.simple i * y) < n := hy ▸ hi + rw [hRP.R_recursion x y i hi, hSQ.R_recursion x y i hi] + rw [ih _ hlt _ rfl x, ih _ hlt _ rfl (cs.simple i * x)] + +/-- The degree/reciprocity rigidity used both by normalization uniqueness and +by the final main-theorem induction: no polynomial supported strictly below +the midpoint can be self-reciprocal about that midpoint. -/ +theorem low_degree_reflect_eq_self (f : ℤ[X]) (d : ℕ) + (hd : 2 * f.natDegree < d) (hself : reflect d f = f) : f = 0 := by + by_contra hn + have hc := congrArg (fun p : ℤ[X] => p.coeff f.natDegree) hself + rw [coeff_reflect, revAt_le (by omega)] at hc + rw [coeff_eq_zero_of_natDegree_lt (by omega), coeff_natDegree] at hc + exact (leadingCoeff_ne_zero.mpr hn) hc.symm + +/-- The polynomial part of the manuscript's normalization is unique; the +proof uses the actual finite strong-Bruhat intervals, not extra assumptions. -/ +theorem normalized_P_unique (cs : CoxeterSystem M W) + {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : + RP.2 = SQ.2 := by + classical + have hR := normalized_R_unique cs hRP hSQ + suffices ∀ n : ℕ, ∀ x y : W, rankDifference cs x y = n → RP.2 x y = SQ.2 x y by + funext x y + exact this (rankDifference cs x y) x y rfl + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro x y hxy + by_cases hcomp : BruhatLE cs x y + · by_cases heq : x = y + · subst y + rw [hRP.P_diagonal, hSQ.P_diagonal] + · let : Finite (Interval cs x y) := interval_finite cs x y + let : Fintype (Interval cs x y) := Fintype.ofFinite _ + let bottom : Interval cs x y := ⟨x, bruhat_refl cs x, hcomp⟩ + have hsum : (∑ z : Interval cs x y, + RP.1 x z.val * (RP.2 z.val y - SQ.2 z.val y)) = RP.2 x y - SQ.2 x y := by + rw [Finset.sum_eq_single bottom] + · simp [bottom, hRP.R_diagonal] + · intro z _ hz + have hxz : x ≠ z.val := by + intro hc + apply hz + exact Subtype.ext hc.symm + have hlt := length_lt_of_bruhat_ne cs z.property.1 hxz + have hle := length_le_of_bruhat cs z.property.2 + have hdiff : rankDifference cs z.val y < n := by + dsimp [rankDifference] at hxy ⊢ + omega + rw [ih _ hdiff z.val y rfl, sub_self, mul_zero] + · simp + have href : reflect (rankDifference cs x y) (RP.2 x y - SQ.2 x y) = + RP.2 x y - SQ.2 x y := by + rw [reflect_sub, hRP.reciprocity x y hcomp, hSQ.reciprocity x y hcomp, + finsum_eq_sum_of_fintype, finsum_eq_sum_of_fintype, ← Finset.sum_sub_distrib] + rw [← hsum] + apply Finset.sum_congr rfl + intro z _ + rw [← hR, mul_sub] + have hd1 := hRP.P_degree x y hcomp heq + have hd2 := hSQ.P_degree x y hcomp heq + have hdeg := natDegree_sub_le (RP.2 x y) (SQ.2 x y) + have hzero := low_degree_reflect_eq_self (RP.2 x y - SQ.2 x y) + (rankDifference cs x y) (by omega) href + exact sub_eq_zero.mp hzero + · rw [hRP.P_zero _ _ hcomp, hSQ.P_zero _ _ hcomp] + +/-- Unique existence is still a separate obligation: this proves its +uniqueness half only, without postulating a normalized family. -/ +theorem normalizedKL_unique (cs : CoxeterSystem M W) + {RP SQ : PolynomialFamilies W} (hRP : NormalizedKL cs RP) (hSQ : NormalizedKL cs SQ) : + RP = SQ := + Prod.ext (normalized_R_unique cs hRP hSQ) (normalized_P_unique cs hRP hSQ) + + +/-! Exchange consequences required for the source's finite-rank reduction +and for consistency of the equal-parameter Hecke recursion. -/ + +/-- Every word contains a reduced subword with the same product. -/ +theorem exists_reduced_subword (cs : CoxeterSystem M W) (ω : List B) : + ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = cs.wordProd ω := by + induction ω with + | nil => exact ⟨[], .refl _, by simp [CoxeterSystem.IsReduced], rfl⟩ + | cons i ω ih => + obtain ⟨ν, hsub, hν, heq⟩ := ih + rcases cs.length_simple_mul (cs.wordProd ν) i with hasc | hdesc + · refine ⟨i :: ν, hsub.cons_cons i, ?_, ?_⟩ + · simpa [CoxeterSystem.IsReduced, cs.wordProd_cons, hν.eq] using hasc + · simp [cs.wordProd_cons, heq] + · obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hν + ⟨cs.isReflection_simple i, by omega⟩ + refine ⟨ν.eraseIdx j, ((ν.eraseIdx_sublist j).trans hsub).cons i, ?_, ?_⟩ + · dsimp [CoxeterSystem.IsReduced] + rw [← hdel, List.length_eraseIdx, ite_eq_left hj] + have := hν.eq + omega + · rw [← hdel, heq, cs.wordProd_cons] + +/-- A single downward reflection step can be realized inside any reduced word. -/ +theorem subword_of_bruhat_step (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatStep cs x y) {ω : List B} (hω : cs.IsReduced ω) + (hy : cs.wordProd ω = y) : + ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by + obtain ⟨hlen, t, ht, rfl⟩ := hxy + have hx : t * cs.wordProd ω = x := by simp [hy, ← mul_assoc, ht.mul_self] + obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hω + ⟨ht, by + rw [hx, hy] + exact hlen⟩ + obtain ⟨ν, hsub, hν, heq⟩ := exists_reduced_subword cs (ω.eraseIdx j) + exact ⟨ν, hsub.trans (ω.eraseIdx_sublist j), hν, heq.trans (hdel.symm.trans hx)⟩ + +/-- Forward subword property, for every chosen reduced expression of the top. -/ +theorem reduced_subword_of_bruhat (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatLE cs x y) {ω : List B} (hω : cs.IsReduced ω) + (hy : cs.wordProd ω = y) : + ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by + induction hxy using Relation.ReflTransGen.head_induction_on generalizing ω with + | refl => exact ⟨ω, .refl _, hω, hy⟩ + | head hstep _ ih => + obtain ⟨ν, hsub, hν, heq⟩ := ih hω hy + obtain ⟨μ, hμsub, hμ, hμeq⟩ := subword_of_bruhat_step cs hstep hν heq + exact ⟨μ, hμsub.trans hsub, hμ, hμeq⟩ + + +/-- Simple left multiplication preserves the orientation of every reflection +edge except the edge carrying that simple reflection itself. -/ +theorem bruhatStep_simple_mul (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatStep cs x y) (i : B) (hne : y ≠ cs.simple i * x) : + BruhatStep cs (cs.simple i * x) (cs.simple i * y) := by + obtain ⟨hlen, t, ht, heq⟩ := hxy + refine ⟨?_, cs.simple i * t * cs.simple i, by simpa using ht.conj (cs.simple i), ?_⟩ + · rcases cs.length_simple_mul y i with hasc | hdesc + · have hx := cs.length_simple_mul x i + omega + · obtain ⟨ω, hω, hωeq⟩ := cs.exists_isReduced (cs.simple i * y) + have hprod : cs.wordProd (i :: ω) = y := by + rw [cs.wordProd_cons, ← hωeq, cs.simple_mul_simple_cancel_left] + have hr : cs.IsReduced (i :: ω) := by + dsimp [CoxeterSystem.IsReduced] + rw [hprod, ← hω.eq, ← hωeq] + exact hdesc.symm + have htx : t * cs.wordProd (i :: ω) = x := by + rw [hprod, heq, ← mul_assoc, ht.mul_self, one_mul] + obtain ⟨j, hj, hdel⟩ := CoxeterSupport.strong_exchange cs hr + ⟨ht, by rw [htx, hprod]; exact hlen⟩ + cases j with + | zero => + have hx : x = cs.wordProd ω := by simpa [htx] using hdel + exact (hne (by rw [hx, ← cs.wordProd_cons, hprod])).elim + | succ j => + have hx : x = cs.simple i * cs.wordProd (ω.eraseIdx j) := by + rw [htx, List.eraseIdx_cons_succ, cs.wordProd_cons] at hdel + exact hdel + have hsx : cs.simple i * x = cs.wordProd (ω.eraseIdx j) := by simp [hx] + have hj' : j < ω.length := by simpa using hj + have hlen' := cs.length_wordProd_le (ω.eraseIdx j) + rw [List.length_eraseIdx, ite_eq_left hj'] at hlen' + rw [hsx, hωeq, hω.eq] + omega + · rw [heq] + simp [mul_assoc] + +/-- The smaller of `x` and `s*x` in Bruhat order. -/ +noncomputable def lowerSimple (cs : CoxeterSystem M W) (i : B) (x : W) : W := + if cs.length (cs.simple i * x) < cs.length x then cs.simple i * x else x + +/-- The larger of `x` and `s*x` in Bruhat order. -/ +noncomputable def upperSimple (cs : CoxeterSystem M W) (i : B) (x : W) : W := + if cs.length (cs.simple i * x) < cs.length x then x else cs.simple i * x + +theorem lowerSimple_le (cs : CoxeterSystem M W) (i : B) (x : W) : + BruhatLE cs (lowerSimple cs i x) x := by + classical + unfold lowerSimple + split_ifs with h + · exact .single ⟨h, cs.simple i, cs.isReflection_simple i, by simp⟩ + · exact .refl + +theorem le_upperSimple (cs : CoxeterSystem M W) (i : B) (x : W) : + BruhatLE cs x (upperSimple cs i x) := by + classical + unfold upperSimple + split_ifs with h + · exact .refl + · exact .single ⟨by have := cs.length_simple_mul x i; omega, + cs.simple i, cs.isReflection_simple i, rfl⟩ + +@[simp] theorem lowerSimple_mul (cs : CoxeterSystem M W) (i : B) (x : W) : + lowerSimple cs i (cs.simple i * x) = lowerSimple cs i x := by + classical + unfold lowerSimple + rw [cs.simple_mul_simple_cancel_left] + have := cs.length_simple_mul x i + split_ifs <;> first | rfl | omega + +@[simp] theorem upperSimple_mul (cs : CoxeterSystem M W) (i : B) (x : W) : + upperSimple cs i (cs.simple i * x) = upperSimple cs i x := by + classical + unfold upperSimple + rw [cs.simple_mul_simple_cancel_left] + have := cs.length_simple_mul x i + split_ifs <;> first | rfl | omega + +theorem lowerSimple_step_mono (cs : CoxeterSystem M W) (i : B) {x y : W} + (hxy : BruhatStep cs x y) : + BruhatLE cs (lowerSimple cs i x) (lowerSimple cs i y) := by + classical + by_cases heq : y = cs.simple i * x + · rw [heq, lowerSimple_mul] + exact .refl + · have hs := bruhatStep_simple_mul cs hxy i heq + by_cases hx : cs.length (cs.simple i * x) < cs.length x + · by_cases hy : cs.length (cs.simple i * y) < cs.length y + · simp only [lowerSimple, ite_eq_left hx, ite_eq_left hy] + exact .single hs + · simp only [lowerSimple, ite_eq_left hx, ite_eq_right hy] + have hlow := lowerSimple_le cs i x + simp only [lowerSimple, ite_eq_left hx] at hlow + exact hlow.trans (.single hxy) + · by_cases hy : cs.length (cs.simple i * y) < cs.length y + · simp only [lowerSimple, ite_eq_right hx, ite_eq_left hy] + have hupp := le_upperSimple cs i x + simp only [upperSimple, ite_eq_right hx] at hupp + exact hupp.trans (.single hs) + · simp only [lowerSimple, ite_eq_right hx, ite_eq_right hy] + exact .single hxy + +theorem upperSimple_step_mono (cs : CoxeterSystem M W) (i : B) {x y : W} + (hxy : BruhatStep cs x y) : + BruhatLE cs (upperSimple cs i x) (upperSimple cs i y) := by + classical + by_cases heq : y = cs.simple i * x + · rw [heq, upperSimple_mul] + exact .refl + · have hs := bruhatStep_simple_mul cs hxy i heq + by_cases hx : cs.length (cs.simple i * x) < cs.length x + · by_cases hy : cs.length (cs.simple i * y) < cs.length y + · simp only [upperSimple, ite_eq_left hx, ite_eq_left hy] + exact .single hxy + · simp only [upperSimple, ite_eq_left hx, ite_eq_right hy] + have hupp := le_upperSimple cs i y + simp only [upperSimple, ite_eq_right hy] at hupp + exact (Relation.ReflTransGen.single hxy).trans hupp + · by_cases hy : cs.length (cs.simple i * y) < cs.length y + · simp only [upperSimple, ite_eq_right hx, ite_eq_left hy] + have hlow := lowerSimple_le cs i y + simp only [lowerSimple, ite_eq_left hy] at hlow + exact (Relation.ReflTransGen.single hs).trans hlow + · simp only [upperSimple, ite_eq_right hx, ite_eq_right hy] + exact .single hs + +theorem lowerSimple_mono (cs : CoxeterSystem M W) (i : B) {x y : W} + (hxy : BruhatLE cs x y) : + BruhatLE cs (lowerSimple cs i x) (lowerSimple cs i y) := by + induction hxy using Relation.ReflTransGen.head_induction_on with + | refl => exact .refl + | head hstep _ ih => exact (lowerSimple_step_mono cs i hstep).trans ih + +theorem upperSimple_mono (cs : CoxeterSystem M W) (i : B) {x y : W} + (hxy : BruhatLE cs x y) : + BruhatLE cs (upperSimple cs i x) (upperSimple cs i y) := by + induction hxy using Relation.ReflTransGen.head_induction_on with + | refl => exact .refl + | head hstep _ ih => exact (upperSimple_step_mono cs i hstep).trans ih + + +/-- The standard lifting property, now for the actual strong order. -/ +theorem bruhat_lifting (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatLE cs x y) (i : B) + (hx : cs.length x < cs.length (cs.simple i * x)) + (hy : cs.length (cs.simple i * y) < cs.length y) : + BruhatLE cs x (cs.simple i * y) ∧ BruhatLE cs (cs.simple i * x) y := by + have hx' : ¬cs.length (cs.simple i * x) < cs.length x := by omega + constructor + · simpa only [lowerSimple, ite_eq_right hx', ite_eq_left hy] using lowerSimple_mono cs i hxy + · simpa only [upperSimple, ite_eq_right hx', ite_eq_left hy] using upperSimple_mono cs i hxy + +/-- Converse subword property; no labels are added to Bruhat intervals. -/ +theorem bruhat_of_subword (cs : CoxeterSystem M W) {ν ω : List B} + (hsub : ν.Sublist ω) (hω : cs.IsReduced ω) : + BruhatLE cs (cs.wordProd ν) (cs.wordProd ω) := by + induction ω generalizing ν with + | nil => + have : ν = [] := List.sublist_nil.mp hsub + subst ν + exact .refl + | cons i ω ih => + have hω' : cs.IsReduced ω := by simpa using hω.drop 1 + have hasc : cs.length (cs.simple i * cs.wordProd ω) = cs.length (cs.wordProd ω) + 1 := by + simpa [CoxeterSystem.IsReduced, cs.wordProd_cons, hω'.eq] using hω.eq + have htop : upperSimple cs i (cs.wordProd ω) = cs.wordProd (i :: ω) := by + simp [upperSimple, show ¬cs.length (cs.simple i * cs.wordProd ω) < + cs.length (cs.wordProd ω) by omega, cs.wordProd_cons] + rcases List.sublist_cons_iff.mp hsub with hsub' | ⟨μ, rfl, hμsub⟩ + · exact (ih hsub' hω').trans (htop ▸ le_upperSimple cs i (cs.wordProd ω)) + · have hle := upperSimple_mono cs i (ih hμsub hω') + rw [htop] at hle + have hx := le_upperSimple cs i (cs.simple i * cs.wordProd μ) + rw [upperSimple_mul] at hx + rw [cs.wordProd_cons] + exact hx.trans hle + +/-- The subword criterion with an arbitrary fixed reduced word for the top. -/ +theorem bruhat_iff_reduced_subword (cs : CoxeterSystem M W) {x : W} {ω : List B} + (hω : cs.IsReduced ω) : + BruhatLE cs x (cs.wordProd ω) ↔ + ∃ ν : List B, ν.Sublist ω ∧ cs.IsReduced ν ∧ cs.wordProd ν = x := by + constructor + · intro hx + exact reduced_subword_of_bruhat cs hx hω rfl + · rintro ⟨ν, hsub, _, rfl⟩ + exact bruhat_of_subword cs hsub hω + +/-- Precisely the finite-support part used by the manuscript's finite-rank +reduction: all lower elements are words in the generators of any reduced top +word. Equality of parabolic polynomial normalizations remains a later step. -/ +theorem lower_ideal_finite_generator_support (cs : CoxeterSystem M W) (b : W) : + ∃ J : Set B, J.Finite ∧ ∀ x, BruhatLE cs x b → + ∃ ν : List B, (∀ i ∈ ν, i ∈ J) ∧ cs.wordProd ν = x := by + obtain ⟨ω, hω, heq⟩ := cs.exists_isReduced b + refine ⟨{i | i ∈ ω}, ω.finite_toSet, ?_⟩ + intro x hx + obtain ⟨ν, hsub, _, hprod⟩ := reduced_subword_of_bruhat cs hx hω heq.symm + exact ⟨ν, fun i hi => hsub.subset hi, hprod⟩ + + +/-- Inversion preserves the actual strong Bruhat graph. -/ +theorem bruhatStep_inv (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatStep cs x y) : BruhatStep cs x⁻¹ y⁻¹ := by + obtain ⟨hlen, t, ht, heq⟩ := hxy + refine ⟨by simpa using hlen, x⁻¹ * t * x, by simpa using ht.conj x⁻¹, ?_⟩ + rw [heq, mul_inv_rev, ht.inv] + group + +theorem bruhatStep_mul_simple (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatStep cs x y) (i : B) (hne : y ≠ x * cs.simple i) : + BruhatStep cs (x * cs.simple i) (y * cs.simple i) := by + have hinv := bruhatStep_inv cs hxy + have hne' : y⁻¹ ≠ cs.simple i * x⁻¹ := by + intro heq + apply hne + have := congrArg Inv.inv heq + simpa [mul_inv_rev] using this + have h := bruhatStep_inv cs (bruhatStep_simple_mul cs hinv i hne') + simpa [mul_inv_rev] using h + +/-- The noncollapsed left/right simple square has consistent orientations. -/ +theorem left_descent_mul_simple_iff (cs : CoxeterSystem M W) (i j : B) (x : W) + (hne : cs.simple i * x ≠ x * cs.simple j) : + cs.length (cs.simple i * (x * cs.simple j)) < cs.length (x * cs.simple j) ↔ + cs.length (cs.simple i * x) < cs.length x := by + by_cases hx : cs.length (cs.simple i * x) < cs.length x + · have hedge : BruhatStep cs (cs.simple i * x) x := + ⟨hx, cs.simple i, cs.isReflection_simple i, by simp⟩ + have hne' : x ≠ cs.simple i * x * cs.simple j := by + intro heq + apply hne + have := congrArg (fun z => z * cs.simple j) heq + simpa using this.symm + have h := (bruhatStep_mul_simple cs hedge j hne').1 + simpa only [mul_assoc, hx, iff_true] using h + · have hedge : BruhatStep cs x (cs.simple i * x) := + ⟨by have := cs.length_simple_mul x i; omega, cs.simple i, + cs.isReflection_simple i, rfl⟩ + have h := (bruhatStep_mul_simple cs hedge j hne).1 + rw [mul_assoc] at h + exact iff_of_false (by omega) hx + +theorem right_descent_simple_mul_iff (cs : CoxeterSystem M W) (i j : B) (x : W) + (hne : cs.simple i * x ≠ x * cs.simple j) : + cs.length (cs.simple i * x * cs.simple j) < cs.length (cs.simple i * x) ↔ + cs.length (x * cs.simple j) < cs.length x := by + have hne' : cs.simple j * x⁻¹ ≠ x⁻¹ * cs.simple i := by + intro heq + apply hne + have h := congrArg Inv.inv heq + simpa [mul_inv_rev] using h.symm + have h := left_descent_mul_simple_iff cs j i x⁻¹ hne' + have h1 : cs.length (cs.simple i * x * cs.simple j) = + cs.length (cs.simple j * (x⁻¹ * cs.simple i)) := by + rw [← cs.length_inv (cs.simple i * x * cs.simple j)] + simp [mul_inv_rev] + have h2 : cs.length (cs.simple i * x) = cs.length (x⁻¹ * cs.simple i) := by + rw [← cs.length_inv (cs.simple i * x)] + simp [mul_inv_rev] + have h3 : cs.length (x * cs.simple j) = cs.length (cs.simple j * x⁻¹) := by + rw [← cs.length_inv (x * cs.simple j)] + simp [mul_inv_rev] + rw [h1, h2, h3] + simpa using h + + +end KLInvariance +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/CanonicalKL.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/CanonicalKL.lean index 1366e659787a636a42e5db7a24f2aa1eacb4f5cf..fa4df51c96f6884a9b1edb02a4b9246713536478 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/CanonicalKL.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/CanonicalKL.lean @@ -1,473 +1,473 @@ -import OAI.RepresentationTheory.KazhdanLusztig.OrdinaryR - -namespace OAI - -/-! -Canonical low-part construction, strict halfdegree, reciprocity and uniqueness; certification of the selected polynomials and interval ranks. --/ - -section -namespace KLInvariance - -open Polynomial - -universe u v u' v' - -variable {B : Type u} {W : Type v} [klPreservedInstance1 : Group W] {M : CoxeterMatrix B} - -noncomputable local instance : DecidableEq W := Classical.decEq W - -namespace CanonicalP - -/-- The strict lower half of a polynomial, used in the KL recursion. -/ -noncomputable def lowPart (d : ℕ) (p : ℤ[X]) : ℤ[X] := - ∑ n ∈ Finset.range ((d + 1) / 2), Polynomial.monomial n (p.coeff n) - -@[simp] theorem coeff_lowPart (d : ℕ) (p : ℤ[X]) (n : ℕ) : - (lowPart d p).coeff n = if 2 * n < d then p.coeff n else 0 := by - classical - simp only [lowPart, Polynomial.finsetSum_coeff, Polynomial.coeff_monomial] - rw [Finset.sum_ite_eq'] - have he : n < (d + 1) / 2 ↔ 2 * n < d := by omega - simp only [Finset.mem_range, he] - -theorem lowPart_degree (d : ℕ) (p : ℤ[X]) (hd : 0 < d) : - 2 * (lowPart d p).natDegree < d := by - have h : (lowPart d p).natDegree ≤ (d - 1) / 2 := by - apply Polynomial.natDegree_le_iff_coeff_eq_zero.mpr - intro n hn - rw [coeff_lowPart, ite_eq_right (by omega)] - omega - -/-- Solve the anti-reciprocal defect with the required strict degree bound. -/ -theorem lowPart_solution (d : ℕ) (p : ℤ[X]) (hanti : reflect d p = -p) : - reflect d (-lowPart d p) = -lowPart d p + p := by - apply Polynomial.ext - intro n - have hc := congrArg (fun f : ℤ[X] => f.coeff n) hanti - simp only [Polynomial.coeff_reflect, Polynomial.coeff_neg] at hc - simp only [Polynomial.coeff_reflect, Polynomial.coeff_neg, Polynomial.coeff_add, - coeff_lowPart] - by_cases hn : n ≤ d - · rw [Polynomial.revAt_le hn] at hc ⊢ - by_cases hlow : 2 * n < d - · rw [ite_eq_left hlow, ite_eq_right (by omega)] - ring - · rw [ite_eq_right hlow] - by_cases hmid : 2 * n = d - · have hm : d - n = n := by omega - rw [hm, ite_eq_right hlow] - rw [hm] at hc - linarith - · rw [ite_eq_left (by omega)] - linarith - · rw [Polynomial.revAt_eq_self_of_lt (by omega)] at hc ⊢ - rw [ite_eq_right (by omega)] - linarith - -/-- The standard lower-half KL recursion, on the actual Bruhat interval. -Its reciprocity will be proved from the genuine R-kernel, not stipulated. -/ -noncomputable def polynomial (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := by - classical - exact if BruhatLE cs x y then - if x = y then 1 else - -lowPart (rankDifference cs x y) - (∑ z ∈ (properIntervalFinset cs x y).attach, - OrdinaryR.polynomial cs x z.val * polynomial cs z.val y) - else 0 -termination_by rankDifference cs x y -decreasing_by - have hz := (mem_properIntervalFinset cs x y z.val).mp z.property - have hlt := length_lt_of_bruhat_ne cs hz.2.1 hz.2.2 - have hle := length_le_of_bruhat cs hz.1 - dsimp [rankDifference] - omega - -@[simp] theorem polynomial_diagonal (cs : CoxeterSystem M W) (x : W) : - polynomial cs x x = 1 := by - rw [polynomial] - simp [bruhat_refl] - -theorem polynomial_zero (cs : CoxeterSystem M W) (x y : W) - (hxy : ¬BruhatLE cs x y) : polynomial cs x y = 0 := by - rw [polynomial, ite_eq_right hxy] - -noncomputable def defect (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := - ∑ z ∈ properIntervalFinset cs x y, OrdinaryR.polynomial cs x z * polynomial cs z y - -theorem polynomial_recursion (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) (hne : x ≠ y) : - polynomial cs x y = -lowPart (rankDifference cs x y) (defect cs x y) := by - rw [polynomial, ite_eq_left hxy, ite_eq_right hne] - rw [Finset.sum_attach _ (fun z => OrdinaryR.polynomial cs x z * polynomial cs z y), defect] - -theorem polynomial_strict_degree (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) (hne : x ≠ y) : - 2 * (polynomial cs x y).natDegree < rankDifference cs x y := by - rw [polynomial_recursion cs x y hxy hne, Polynomial.natDegree_neg] - apply lowPart_degree - have := length_lt_of_bruhat_ne cs hxy hne - dsimp [rankDifference] - omega - -theorem polynomial_degree (cs : CoxeterSystem M W) (x y : W) : - (polynomial cs x y).natDegree ≤ rankDifference cs x y := by - by_cases hxy : BruhatLE cs x y - · by_cases hne : x = y - · subst y - simp - · have := polynomial_strict_degree cs x y hxy hne - omega - · rw [polynomial_zero cs x y hxy] - simp - -theorem defect_full_sum (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) : - defect cs x y = (∑ z ∈ lowerFinset cs y, - OrdinaryR.polynomial cs x z * polynomial cs z y) - polynomial cs x y := by - rw [defect, sum_proper_eq_sub cs x y hxy] - · simp - · intro z hz - rw [OrdinaryR.polynomial_zero cs x z hz, zero_mul] - -theorem reversed_kernel_on_lower (cs : CoxeterSystem M W) (x y t : W) - (hty : BruhatLE cs t y) : - ∑ z ∈ lowerFinset cs y, - reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * - OrdinaryR.polynomial cs z t = if x = t then 1 else 0 := by - classical - rw [← OrdinaryR.polynomial_kernel_reverse cs x t] - symm - apply Finset.sum_subset - · intro z hz - exact (mem_lowerFinset cs y z).mpr - (bruhat_trans cs ((mem_lowerFinset cs t z).mp hz) hty) - · intro z hz hnt - have hzt : ¬BruhatLE cs z t := fun h => hnt ((mem_lowerFinset cs t z).mpr h) - rw [OrdinaryR.polynomial_zero cs z t hzt, mul_zero] - -theorem reversed_kernel_on_proper (cs : CoxeterSystem M W) (x y t : W) - (hxy : BruhatLE cs x y) (hty : BruhatLE cs t y) : - ∑ z ∈ properIntervalFinset cs x y, - reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * - OrdinaryR.polynomial cs z t = - (if x = t then 1 else 0) - OrdinaryR.polynomial cs x t := by - rw [sum_proper_eq_sub cs x y hxy] - · rw [reversed_kernel_on_lower cs x y t hty] - simp [rankDifference] - · intro z hz - rw [OrdinaryR.polynomial_zero cs x z hz, reflect_zero, zero_mul] - -/-- The reciprocity equation is a theorem of the lower-half construction. -/ -theorem polynomial_reciprocity (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) : - reflect (rankDifference cs x y) (polynomial cs x y) = - ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z * polynomial cs z y := by - classical - suffices ∀ n : ℕ, ∀ x y : W, rankDifference cs x y = n → BruhatLE cs x y → - reflect (rankDifference cs x y) (polynomial cs x y) = - ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z * polynomial cs z y by - exact this _ x y rfl hxy - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro x y hn hxy - by_cases hne : x = y - · subst y - rw [polynomial_diagonal] - simp only [rankDifference, Nat.sub_self, Polynomial.reflect_one, pow_zero] - symm - rw [Finset.sum_eq_single x] - · simp - · intro z hz hzx - have hnxz : ¬BruhatLE cs x z := fun hxz => - hzx (bruhat_antisymm cs ((mem_lowerFinset cs x z).mp hz) hxz) - rw [OrdinaryR.polynomial_zero cs x z hnxz, zero_mul] - · intro hmiss - exact (hmiss ((mem_lowerFinset cs x x).mpr (bruhat_refl cs x))).elim - · have hanti : reflect (rankDifference cs x y) (defect cs x y) = -defect cs x y := by - rw [defect, reflect_finset_sum] - have heq : ∀ z ∈ properIntervalFinset cs x y, - reflect (rankDifference cs x y) - (OrdinaryR.polynomial cs x z * polynomial cs z y) = - reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * - (∑ t ∈ lowerFinset cs y, OrdinaryR.polynomial cs z t * polynomial cs t y) := by - intro z hz - have hz := (mem_properIntervalFinset cs x y z).mp hz - have hlt : rankDifference cs z y < n := by - have := length_lt_of_bruhat_ne cs hz.2.1 hz.2.2 - have := length_le_of_bruhat cs hz.1 - dsimp [rankDifference] at hn ⊢ - omega - rw [rankDifference_add cs hz.2.1 hz.1, - reflect_mul _ _ (OrdinaryR.polynomial_degree cs x z) (polynomial_degree cs z y), - ih _ hlt z y rfl hz.1] - rw [Finset.sum_congr rfl heq] - simp_rw [Finset.mul_sum, ← mul_assoc] - rw [Finset.sum_comm] - simp_rw [← Finset.sum_mul] - have hkernel : ∀ t ∈ lowerFinset cs y, - (∑ z ∈ properIntervalFinset cs x y, - reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * - OrdinaryR.polynomial cs z t) * polynomial cs t y = - ((if x = t then 1 else 0) - OrdinaryR.polynomial cs x t) * polynomial cs t y := by - intro t ht - rw [reversed_kernel_on_proper cs x y t hxy ((mem_lowerFinset cs y t).mp ht)] - rw [Finset.sum_congr rfl hkernel] - simp_rw [sub_mul, Finset.sum_sub_distrib] - have hdelta : (∑ t ∈ lowerFinset cs y, - (if x = t then (1 : ℤ[X]) else 0) * polynomial cs t y) = polynomial cs x y := by - rw [Finset.sum_eq_single x] - · simp - · intro t ht htx - simp [Ne.symm htx] - · intro hmiss - exact (hmiss ((mem_lowerFinset cs y x).mpr hxy)).elim - rw [hdelta] - change polynomial cs x y - (∑ z ∈ lowerFinset cs y, - OrdinaryR.polynomial cs x z * polynomial cs z y) = -defect cs x y - rw [defect_full_sum cs x y hxy] - ring - rw [polynomial_recursion cs x y hxy hne, lowPart_solution _ _ hanti] - rw [← polynomial_recursion cs x y hxy hne, defect_full_sum cs x y hxy] - ring - -end CanonicalP - -/-- Finitely supported interval sums agree with the lower-ideal sums used in -our construction; all incomparable summands are literally zero. -/ -theorem normalized_interval_sum (cs : CoxeterSystem M W) (x y : W) : - (∑ᶠ z : Interval cs x y, - OrdinaryR.polynomial cs x z.val * CanonicalP.polynomial cs z.val y) = - ∑ z ∈ lowerFinset cs y, - OrdinaryR.polynomial cs x z * CanonicalP.polynomial cs z y := by - classical - let := interval_finite cs x y - let : Fintype (Interval cs x y) := Fintype.ofFinite _ - rw [finsum_eq_sum_of_fintype] - have hsum := Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs x y))) - ((lowerFinset cs y).filter (fun z => BruhatLE cs x z)) - (fun z => by simp only [Finset.mem_filter, mem_lowerFinset]; exact and_comm) - (fun z => OrdinaryR.polynomial cs x z * CanonicalP.polynomial cs z y) - refine hsum.symm.trans ?_ - apply Finset.sum_subset (Finset.filter_subset _ _) - intro z hz hnot - have hnxz : ¬BruhatLE cs x z := fun hxz => hnot (Finset.mem_filter.mpr ⟨hz, hxz⟩) - rw [OrdinaryR.polynomial_zero cs x z hnxz, zero_mul] - -/-- The selected polynomials really exist with the classical equal-parameter -normalization. This is a construction, not an extra hypothesis. -/ -theorem constructed_normalizedKL (cs : CoxeterSystem M W) : - NormalizedKL cs (OrdinaryR.polynomial cs, CanonicalP.polynomial cs) where - R_diagonal := OrdinaryR.polynomial_diagonal cs - R_zero := OrdinaryR.polynomial_zero cs - R_recursion := OrdinaryR.polynomial_recursion cs - P_diagonal := CanonicalP.polynomial_diagonal cs - P_zero := CanonicalP.polynomial_zero cs - P_degree := CanonicalP.polynomial_strict_degree cs - reciprocity := by - intro x y hxy - rw [normalized_interval_sum] - exact CanonicalP.polynomial_reciprocity cs x y hxy - -theorem normalizedKL_existsUnique (cs : CoxeterSystem M W) : - ∃! RP : PolynomialFamilies W, NormalizedKL cs RP := by - refine ⟨(OrdinaryR.polynomial cs, CanonicalP.polynomial cs), constructed_normalizedKL cs, ?_⟩ - intro RP hRP - exact normalizedKL_unique cs hRP (constructed_normalizedKL cs) - -theorem klFamilies_spec (cs : CoxeterSystem M W) : NormalizedKL cs (klFamilies cs) := by - exact Classical.epsilon_spec (normalizedKL_existsUnique cs).exists - -theorem klFamilies_eq_constructed (cs : CoxeterSystem M W) : - klFamilies cs = (OrdinaryR.polynomial cs, CanonicalP.polynomial cs) := - normalizedKL_unique cs (klFamilies_spec cs) (constructed_normalizedKL cs) - -theorem klPolynomial_eq_constructed (cs : CoxeterSystem M W) (x y : W) : - klPolynomial cs x y = CanonicalP.polynomial cs x y := by - simp only [klPolynomial, klFamilies_eq_constructed] - -theorem rPolynomial_eq_constructed (cs : CoxeterSystem M W) (x y : W) : - rPolynomial cs x y = OrdinaryR.polynomial cs x y := by - simp only [rPolynomial, klFamilies_eq_constructed] - - -/-- Every nontrivial Bruhat interval contains a first step of length one. -This is the grading fact needed to transport rank differences without labels. -/ -theorem exists_bruhat_successor (cs : CoxeterSystem M W) {x y : W} - (hxy : BruhatLE cs x y) (hne : x ≠ y) : - ∃ z, BruhatLE cs x z ∧ BruhatLE cs z y ∧ cs.length z = cs.length x + 1 := by - classical - suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x : W, - BruhatLE cs x y → x ≠ y → - ∃ z, BruhatLE cs x z ∧ BruhatLE cs z y ∧ cs.length z = cs.length x + 1 by - exact this _ y rfl x hxy hne - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro y hyn x hxy hne - have hy1 : y ≠ 1 := by - intro hy - subst y - have hlen := length_le_of_bruhat cs hxy - have hx : cs.length x = 0 := by simpa using hlen - exact hne (cs.length_eq_zero_iff.mp hx) - obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one hy1 - change cs.length (cs.simple i * y) < cs.length y at hi - have hylen : cs.length y = cs.length (cs.simple i * y) + 1 := by - have := cs.length_simple_mul y i - omega - have hsyn : cs.length (cs.simple i * y) < n := by omega - have hsyy : BruhatLE cs (cs.simple i * y) y := by - simpa only [lowerSimple, ite_eq_left hi] using lowerSimple_le cs i y - by_cases hxsy : BruhatLE cs x (cs.simple i * y) - · by_cases hxeq : x = cs.simple i * y - · exact ⟨y, hxy, bruhat_refl cs y, by simpa [hxeq] using hylen⟩ - · obtain ⟨z, hxz, hzsy, hzlen⟩ := ih _ hsyn _ rfl x hxsy hxeq - exact ⟨z, hxz, bruhat_trans cs hzsy hsyy, hzlen⟩ - · have hxi : cs.length (cs.simple i * x) < cs.length x := by - by_contra hnxi - have hxim : cs.length x < cs.length (cs.simple i * x) := by - have := cs.length_simple_mul x i - omega - exact hxsy (bruhat_lifting cs hxy i hxim hi).1 - have hxlen : cs.length x = cs.length (cs.simple i * x) + 1 := by - have := cs.length_simple_mul x i - omega - have hsxsy : BruhatLE cs (cs.simple i * x) (cs.simple i * y) := by - simpa only [lowerSimple, ite_eq_left hxi, ite_eq_left hi] using lowerSimple_mono cs i hxy - have hne' : cs.simple i * x ≠ cs.simple i * y := fun he => hne (mul_left_cancel he) - obtain ⟨w, hsxw, hwsy, hwlen⟩ := ih _ hsyn _ rfl _ hsxsy hne' - have hux : upperSimple cs i (cs.simple i * x) = x := by - rw [upperSimple_mul] - simp only [upperSimple, ite_eq_left hxi] - have huy : upperSimple cs i (cs.simple i * y) = y := by - rw [upperSimple_mul] - simp only [upperSimple, ite_eq_left hi] - have hxz := upperSimple_mono cs i hsxw - have hzy := upperSimple_mono cs i hwsy - rw [hux] at hxz - rw [huy] at hzy - have hwlen' : cs.length w = cs.length x := by omega - have hwi : ¬cs.length (cs.simple i * w) < cs.length w := by - intro hwi - simp only [upperSimple, ite_eq_left hwi] at hxz - have hxw : x = w := by - by_contra hnxw - have := length_lt_of_bruhat_ne cs hxz hnxw - omega - exact hxsy (hxw ▸ hwsy) - refine ⟨upperSimple cs i w, hxz, hzy, ?_⟩ - simp only [upperSimple, ite_eq_right hwi] - have := cs.length_simple_mul w i - omega - - -/-- An order embedding between Bruhat intervals cannot shorten rank. -/ -theorem rankDifference_le_of_strictMono - {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} - (f : Interval cs u b → Interval cs' u' b') (hf : StrictMono f) - {x y : Interval cs u b} (hxy : x ≤ y) : - rankDifference cs x.val y.val ≤ rankDifference cs' (f x).val (f y).val := by - suffices ∀ n : ℕ, ∀ x y : Interval cs u b, - rankDifference cs x.val y.val = n → x ≤ y → - rankDifference cs x.val y.val ≤ rankDifference cs' (f x).val (f y).val by - exact this _ x y rfl hxy - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro x y hn hxy - by_cases heq : x = y - · subst y - simp [rankDifference] - · have hne : x.val ≠ y.val := fun hv => heq (Subtype.ext hv) - obtain ⟨z, hxz, hzy, hzlen⟩ := exists_bruhat_successor cs hxy hne - let zI : Interval cs u b := ⟨z, bruhat_trans cs x.property.1 hxz, - bruhat_trans cs hzy y.property.2⟩ - have hxylen := length_le_of_bruhat cs hxy - have hzylen := length_le_of_bruhat cs hzy - have hsmall : rankDifference cs zI.val y.val < n := by - dsimp [zI, rankDifference] at hn ⊢ - omega - have hsub := ih _ hsmall zI y rfl hzy - have hxz' : x < zI := by - refine (lt_iff_le_and_ne).mpr ⟨hxz, ?_⟩ - intro hx - have hv : x.val = z := congrArg Subtype.val hx - have := congrArg cs.length hv - omega - have hfxz := hf hxz' - have hfxzlen : cs'.length (f x).val < cs'.length (f zI).val := by - apply length_lt_of_bruhat_ne cs' hfxz.le - intro hv - exact hfxz.ne (Subtype.ext hv) - have hfzyle := length_le_of_bruhat cs' (hf.monotone (show zI ≤ y from hzy)) - change cs.length y.val - cs.length z ≤ - cs'.length (f y).val - cs'.length (f zI).val at hsub - change cs.length y.val - cs.length x.val ≤ - cs'.length (f y).val - cs'.length (f x).val - omega - -/-- Rank is intrinsic to the abstract interval poset, with neither root -labels nor simple generators preserved by the isomorphism. -/ -theorem intervalIso_rankDifference - {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} - (ι : Interval cs u b ≃o Interval cs' u' b') - {x y : Interval cs u b} (hxy : x ≤ y) : - rankDifference cs x.val y.val = rankDifference cs' (ι x).val (ι y).val := by - apply Nat.le_antisymm - · exact rankDifference_le_of_strictMono cs cs' ι ι.strictMono hxy - · have h := rankDifference_le_of_strictMono cs' cs ι.symm ι.symm.strictMono (ι.monotone hxy) - simpa only [OrderIso.symm_apply_apply] using h - -/-- Named endpoints for an actual nonempty interval. -/ -def intervalBottom (cs : CoxeterSystem M W) {u b : W} (hub : BruhatLE cs u b) : - Interval cs u b := ⟨u, bruhat_refl cs u, hub⟩ - -def intervalTop (cs : CoxeterSystem M W) {u b : W} (hub : BruhatLE cs u b) : - Interval cs u b := ⟨b, hub, bruhat_refl cs b⟩ - -theorem intervalIso_bottom - {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') - (ι : Interval cs u b ≃o Interval cs' u' b') : - ι (intervalBottom cs hub) = intervalBottom cs' hub' := by - apply le_antisymm - · have h : intervalBottom cs hub ≤ ι.symm (intervalBottom cs' hub') := - (ι.symm (intervalBottom cs' hub')).property.1 - simpa only [OrderIso.apply_symm_apply] using ι.monotone h - · exact (ι (intervalBottom cs hub)).property.1 - -theorem intervalIso_top - {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') - (ι : Interval cs u b ≃o Interval cs' u' b') : - ι (intervalTop cs hub) = intervalTop cs' hub' := by - apply le_antisymm - · exact (ι (intervalTop cs hub)).property.2 - · have h : ι.symm (intervalTop cs' hub') ≤ intervalTop cs hub := - (ι.symm (intervalTop cs' hub')).property.2 - simpa only [OrderIso.apply_symm_apply] using ι.monotone h - -theorem intervalIso_full_rankDifference - {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') - (ι : Interval cs u b ≃o Interval cs' u' b') : - rankDifference cs u b = rankDifference cs' u' b' := by - have h := intervalIso_rankDifference cs cs' ι - (show intervalBottom cs hub ≤ intervalTop cs hub from hub) - rw [intervalIso_bottom cs cs' hub hub' ι, intervalIso_top cs cs' hub hub' ι] at h - exact h - -end KLInvariance - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.OrdinaryR + +namespace OAI + +/-! +Canonical low-part construction, strict halfdegree, reciprocity and uniqueness; certification of the selected polynomials and interval ranks. +-/ + +section +namespace KLInvariance + +open Polynomial + +universe u v u' v' + +variable {B : Type u} {W : Type v} [klPreservedInstance1 : Group W] {M : CoxeterMatrix B} + +noncomputable local instance : DecidableEq W := Classical.decEq W + +namespace CanonicalP + +/-- The strict lower half of a polynomial, used in the KL recursion. -/ +noncomputable def lowPart (d : ℕ) (p : ℤ[X]) : ℤ[X] := + ∑ n ∈ Finset.range ((d + 1) / 2), Polynomial.monomial n (p.coeff n) + +@[simp] theorem coeff_lowPart (d : ℕ) (p : ℤ[X]) (n : ℕ) : + (lowPart d p).coeff n = if 2 * n < d then p.coeff n else 0 := by + classical + simp only [lowPart, Polynomial.finsetSum_coeff, Polynomial.coeff_monomial] + rw [Finset.sum_ite_eq'] + have he : n < (d + 1) / 2 ↔ 2 * n < d := by omega + simp only [Finset.mem_range, he] + +theorem lowPart_degree (d : ℕ) (p : ℤ[X]) (hd : 0 < d) : + 2 * (lowPart d p).natDegree < d := by + have h : (lowPart d p).natDegree ≤ (d - 1) / 2 := by + apply Polynomial.natDegree_le_iff_coeff_eq_zero.mpr + intro n hn + rw [coeff_lowPart, ite_eq_right (by omega)] + omega + +/-- Solve the anti-reciprocal defect with the required strict degree bound. -/ +theorem lowPart_solution (d : ℕ) (p : ℤ[X]) (hanti : reflect d p = -p) : + reflect d (-lowPart d p) = -lowPart d p + p := by + apply Polynomial.ext + intro n + have hc := congrArg (fun f : ℤ[X] => f.coeff n) hanti + simp only [Polynomial.coeff_reflect, Polynomial.coeff_neg] at hc + simp only [Polynomial.coeff_reflect, Polynomial.coeff_neg, Polynomial.coeff_add, + coeff_lowPart] + by_cases hn : n ≤ d + · rw [Polynomial.revAt_le hn] at hc ⊢ + by_cases hlow : 2 * n < d + · rw [ite_eq_left hlow, ite_eq_right (by omega)] + ring + · rw [ite_eq_right hlow] + by_cases hmid : 2 * n = d + · have hm : d - n = n := by omega + rw [hm, ite_eq_right hlow] + rw [hm] at hc + linarith + · rw [ite_eq_left (by omega)] + linarith + · rw [Polynomial.revAt_eq_self_of_lt (by omega)] at hc ⊢ + rw [ite_eq_right (by omega)] + linarith + +/-- The standard lower-half KL recursion, on the actual Bruhat interval. +Its reciprocity will be proved from the genuine R-kernel, not stipulated. -/ +noncomputable def polynomial (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := by + classical + exact if BruhatLE cs x y then + if x = y then 1 else + -lowPart (rankDifference cs x y) + (∑ z ∈ (properIntervalFinset cs x y).attach, + OrdinaryR.polynomial cs x z.val * polynomial cs z.val y) + else 0 +termination_by rankDifference cs x y +decreasing_by + have hz := (mem_properIntervalFinset cs x y z.val).mp z.property + have hlt := length_lt_of_bruhat_ne cs hz.2.1 hz.2.2 + have hle := length_le_of_bruhat cs hz.1 + dsimp [rankDifference] + omega + +@[simp] theorem polynomial_diagonal (cs : CoxeterSystem M W) (x : W) : + polynomial cs x x = 1 := by + rw [polynomial] + simp [bruhat_refl] + +theorem polynomial_zero (cs : CoxeterSystem M W) (x y : W) + (hxy : ¬BruhatLE cs x y) : polynomial cs x y = 0 := by + rw [polynomial, ite_eq_right hxy] + +noncomputable def defect (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := + ∑ z ∈ properIntervalFinset cs x y, OrdinaryR.polynomial cs x z * polynomial cs z y + +theorem polynomial_recursion (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) (hne : x ≠ y) : + polynomial cs x y = -lowPart (rankDifference cs x y) (defect cs x y) := by + rw [polynomial, ite_eq_left hxy, ite_eq_right hne] + rw [Finset.sum_attach _ (fun z => OrdinaryR.polynomial cs x z * polynomial cs z y), defect] + +theorem polynomial_strict_degree (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) (hne : x ≠ y) : + 2 * (polynomial cs x y).natDegree < rankDifference cs x y := by + rw [polynomial_recursion cs x y hxy hne, Polynomial.natDegree_neg] + apply lowPart_degree + have := length_lt_of_bruhat_ne cs hxy hne + dsimp [rankDifference] + omega + +theorem polynomial_degree (cs : CoxeterSystem M W) (x y : W) : + (polynomial cs x y).natDegree ≤ rankDifference cs x y := by + by_cases hxy : BruhatLE cs x y + · by_cases hne : x = y + · subst y + simp + · have := polynomial_strict_degree cs x y hxy hne + omega + · rw [polynomial_zero cs x y hxy] + simp + +theorem defect_full_sum (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) : + defect cs x y = (∑ z ∈ lowerFinset cs y, + OrdinaryR.polynomial cs x z * polynomial cs z y) - polynomial cs x y := by + rw [defect, sum_proper_eq_sub cs x y hxy] + · simp + · intro z hz + rw [OrdinaryR.polynomial_zero cs x z hz, zero_mul] + +theorem reversed_kernel_on_lower (cs : CoxeterSystem M W) (x y t : W) + (hty : BruhatLE cs t y) : + ∑ z ∈ lowerFinset cs y, + reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * + OrdinaryR.polynomial cs z t = if x = t then 1 else 0 := by + classical + rw [← OrdinaryR.polynomial_kernel_reverse cs x t] + symm + apply Finset.sum_subset + · intro z hz + exact (mem_lowerFinset cs y z).mpr + (bruhat_trans cs ((mem_lowerFinset cs t z).mp hz) hty) + · intro z hz hnt + have hzt : ¬BruhatLE cs z t := fun h => hnt ((mem_lowerFinset cs t z).mpr h) + rw [OrdinaryR.polynomial_zero cs z t hzt, mul_zero] + +theorem reversed_kernel_on_proper (cs : CoxeterSystem M W) (x y t : W) + (hxy : BruhatLE cs x y) (hty : BruhatLE cs t y) : + ∑ z ∈ properIntervalFinset cs x y, + reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * + OrdinaryR.polynomial cs z t = + (if x = t then 1 else 0) - OrdinaryR.polynomial cs x t := by + rw [sum_proper_eq_sub cs x y hxy] + · rw [reversed_kernel_on_lower cs x y t hty] + simp [rankDifference] + · intro z hz + rw [OrdinaryR.polynomial_zero cs x z hz, reflect_zero, zero_mul] + +/-- The reciprocity equation is a theorem of the lower-half construction. -/ +theorem polynomial_reciprocity (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) : + reflect (rankDifference cs x y) (polynomial cs x y) = + ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z * polynomial cs z y := by + classical + suffices ∀ n : ℕ, ∀ x y : W, rankDifference cs x y = n → BruhatLE cs x y → + reflect (rankDifference cs x y) (polynomial cs x y) = + ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z * polynomial cs z y by + exact this _ x y rfl hxy + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro x y hn hxy + by_cases hne : x = y + · subst y + rw [polynomial_diagonal] + simp only [rankDifference, Nat.sub_self, Polynomial.reflect_one, pow_zero] + symm + rw [Finset.sum_eq_single x] + · simp + · intro z hz hzx + have hnxz : ¬BruhatLE cs x z := fun hxz => + hzx (bruhat_antisymm cs ((mem_lowerFinset cs x z).mp hz) hxz) + rw [OrdinaryR.polynomial_zero cs x z hnxz, zero_mul] + · intro hmiss + exact (hmiss ((mem_lowerFinset cs x x).mpr (bruhat_refl cs x))).elim + · have hanti : reflect (rankDifference cs x y) (defect cs x y) = -defect cs x y := by + rw [defect, reflect_finset_sum] + have heq : ∀ z ∈ properIntervalFinset cs x y, + reflect (rankDifference cs x y) + (OrdinaryR.polynomial cs x z * polynomial cs z y) = + reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * + (∑ t ∈ lowerFinset cs y, OrdinaryR.polynomial cs z t * polynomial cs t y) := by + intro z hz + have hz := (mem_properIntervalFinset cs x y z).mp hz + have hlt : rankDifference cs z y < n := by + have := length_lt_of_bruhat_ne cs hz.2.1 hz.2.2 + have := length_le_of_bruhat cs hz.1 + dsimp [rankDifference] at hn ⊢ + omega + rw [rankDifference_add cs hz.2.1 hz.1, + reflect_mul _ _ (OrdinaryR.polynomial_degree cs x z) (polynomial_degree cs z y), + ih _ hlt z y rfl hz.1] + rw [Finset.sum_congr rfl heq] + simp_rw [Finset.mul_sum, ← mul_assoc] + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul] + have hkernel : ∀ t ∈ lowerFinset cs y, + (∑ z ∈ properIntervalFinset cs x y, + reflect (rankDifference cs x z) (OrdinaryR.polynomial cs x z) * + OrdinaryR.polynomial cs z t) * polynomial cs t y = + ((if x = t then 1 else 0) - OrdinaryR.polynomial cs x t) * polynomial cs t y := by + intro t ht + rw [reversed_kernel_on_proper cs x y t hxy ((mem_lowerFinset cs y t).mp ht)] + rw [Finset.sum_congr rfl hkernel] + simp_rw [sub_mul, Finset.sum_sub_distrib] + have hdelta : (∑ t ∈ lowerFinset cs y, + (if x = t then (1 : ℤ[X]) else 0) * polynomial cs t y) = polynomial cs x y := by + rw [Finset.sum_eq_single x] + · simp + · intro t ht htx + simp [Ne.symm htx] + · intro hmiss + exact (hmiss ((mem_lowerFinset cs y x).mpr hxy)).elim + rw [hdelta] + change polynomial cs x y - (∑ z ∈ lowerFinset cs y, + OrdinaryR.polynomial cs x z * polynomial cs z y) = -defect cs x y + rw [defect_full_sum cs x y hxy] + ring + rw [polynomial_recursion cs x y hxy hne, lowPart_solution _ _ hanti] + rw [← polynomial_recursion cs x y hxy hne, defect_full_sum cs x y hxy] + ring + +end CanonicalP + +/-- Finitely supported interval sums agree with the lower-ideal sums used in +our construction; all incomparable summands are literally zero. -/ +theorem normalized_interval_sum (cs : CoxeterSystem M W) (x y : W) : + (∑ᶠ z : Interval cs x y, + OrdinaryR.polynomial cs x z.val * CanonicalP.polynomial cs z.val y) = + ∑ z ∈ lowerFinset cs y, + OrdinaryR.polynomial cs x z * CanonicalP.polynomial cs z y := by + classical + let := interval_finite cs x y + let : Fintype (Interval cs x y) := Fintype.ofFinite _ + rw [finsum_eq_sum_of_fintype] + have hsum := Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs x y))) + ((lowerFinset cs y).filter (fun z => BruhatLE cs x z)) + (fun z => by simp only [Finset.mem_filter, mem_lowerFinset]; exact and_comm) + (fun z => OrdinaryR.polynomial cs x z * CanonicalP.polynomial cs z y) + refine hsum.symm.trans ?_ + apply Finset.sum_subset (Finset.filter_subset _ _) + intro z hz hnot + have hnxz : ¬BruhatLE cs x z := fun hxz => hnot (Finset.mem_filter.mpr ⟨hz, hxz⟩) + rw [OrdinaryR.polynomial_zero cs x z hnxz, zero_mul] + +/-- The selected polynomials really exist with the classical equal-parameter +normalization. This is a construction, not an extra hypothesis. -/ +theorem constructed_normalizedKL (cs : CoxeterSystem M W) : + NormalizedKL cs (OrdinaryR.polynomial cs, CanonicalP.polynomial cs) where + R_diagonal := OrdinaryR.polynomial_diagonal cs + R_zero := OrdinaryR.polynomial_zero cs + R_recursion := OrdinaryR.polynomial_recursion cs + P_diagonal := CanonicalP.polynomial_diagonal cs + P_zero := CanonicalP.polynomial_zero cs + P_degree := CanonicalP.polynomial_strict_degree cs + reciprocity := by + intro x y hxy + rw [normalized_interval_sum] + exact CanonicalP.polynomial_reciprocity cs x y hxy + +theorem normalizedKL_existsUnique (cs : CoxeterSystem M W) : + ∃! RP : PolynomialFamilies W, NormalizedKL cs RP := by + refine ⟨(OrdinaryR.polynomial cs, CanonicalP.polynomial cs), constructed_normalizedKL cs, ?_⟩ + intro RP hRP + exact normalizedKL_unique cs hRP (constructed_normalizedKL cs) + +theorem klFamilies_spec (cs : CoxeterSystem M W) : NormalizedKL cs (klFamilies cs) := by + exact Classical.epsilon_spec (normalizedKL_existsUnique cs).exists + +theorem klFamilies_eq_constructed (cs : CoxeterSystem M W) : + klFamilies cs = (OrdinaryR.polynomial cs, CanonicalP.polynomial cs) := + normalizedKL_unique cs (klFamilies_spec cs) (constructed_normalizedKL cs) + +theorem klPolynomial_eq_constructed (cs : CoxeterSystem M W) (x y : W) : + klPolynomial cs x y = CanonicalP.polynomial cs x y := by + simp only [klPolynomial, klFamilies_eq_constructed] + +theorem rPolynomial_eq_constructed (cs : CoxeterSystem M W) (x y : W) : + rPolynomial cs x y = OrdinaryR.polynomial cs x y := by + simp only [rPolynomial, klFamilies_eq_constructed] + + +/-- Every nontrivial Bruhat interval contains a first step of length one. +This is the grading fact needed to transport rank differences without labels. -/ +theorem exists_bruhat_successor (cs : CoxeterSystem M W) {x y : W} + (hxy : BruhatLE cs x y) (hne : x ≠ y) : + ∃ z, BruhatLE cs x z ∧ BruhatLE cs z y ∧ cs.length z = cs.length x + 1 := by + classical + suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x : W, + BruhatLE cs x y → x ≠ y → + ∃ z, BruhatLE cs x z ∧ BruhatLE cs z y ∧ cs.length z = cs.length x + 1 by + exact this _ y rfl x hxy hne + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro y hyn x hxy hne + have hy1 : y ≠ 1 := by + intro hy + subst y + have hlen := length_le_of_bruhat cs hxy + have hx : cs.length x = 0 := by simpa using hlen + exact hne (cs.length_eq_zero_iff.mp hx) + obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one hy1 + change cs.length (cs.simple i * y) < cs.length y at hi + have hylen : cs.length y = cs.length (cs.simple i * y) + 1 := by + have := cs.length_simple_mul y i + omega + have hsyn : cs.length (cs.simple i * y) < n := by omega + have hsyy : BruhatLE cs (cs.simple i * y) y := by + simpa only [lowerSimple, ite_eq_left hi] using lowerSimple_le cs i y + by_cases hxsy : BruhatLE cs x (cs.simple i * y) + · by_cases hxeq : x = cs.simple i * y + · exact ⟨y, hxy, bruhat_refl cs y, by simpa [hxeq] using hylen⟩ + · obtain ⟨z, hxz, hzsy, hzlen⟩ := ih _ hsyn _ rfl x hxsy hxeq + exact ⟨z, hxz, bruhat_trans cs hzsy hsyy, hzlen⟩ + · have hxi : cs.length (cs.simple i * x) < cs.length x := by + by_contra hnxi + have hxim : cs.length x < cs.length (cs.simple i * x) := by + have := cs.length_simple_mul x i + omega + exact hxsy (bruhat_lifting cs hxy i hxim hi).1 + have hxlen : cs.length x = cs.length (cs.simple i * x) + 1 := by + have := cs.length_simple_mul x i + omega + have hsxsy : BruhatLE cs (cs.simple i * x) (cs.simple i * y) := by + simpa only [lowerSimple, ite_eq_left hxi, ite_eq_left hi] using lowerSimple_mono cs i hxy + have hne' : cs.simple i * x ≠ cs.simple i * y := fun he => hne (mul_left_cancel he) + obtain ⟨w, hsxw, hwsy, hwlen⟩ := ih _ hsyn _ rfl _ hsxsy hne' + have hux : upperSimple cs i (cs.simple i * x) = x := by + rw [upperSimple_mul] + simp only [upperSimple, ite_eq_left hxi] + have huy : upperSimple cs i (cs.simple i * y) = y := by + rw [upperSimple_mul] + simp only [upperSimple, ite_eq_left hi] + have hxz := upperSimple_mono cs i hsxw + have hzy := upperSimple_mono cs i hwsy + rw [hux] at hxz + rw [huy] at hzy + have hwlen' : cs.length w = cs.length x := by omega + have hwi : ¬cs.length (cs.simple i * w) < cs.length w := by + intro hwi + simp only [upperSimple, ite_eq_left hwi] at hxz + have hxw : x = w := by + by_contra hnxw + have := length_lt_of_bruhat_ne cs hxz hnxw + omega + exact hxsy (hxw ▸ hwsy) + refine ⟨upperSimple cs i w, hxz, hzy, ?_⟩ + simp only [upperSimple, ite_eq_right hwi] + have := cs.length_simple_mul w i + omega + + +/-- An order embedding between Bruhat intervals cannot shorten rank. -/ +theorem rankDifference_le_of_strictMono + {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} + (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} + (f : Interval cs u b → Interval cs' u' b') (hf : StrictMono f) + {x y : Interval cs u b} (hxy : x ≤ y) : + rankDifference cs x.val y.val ≤ rankDifference cs' (f x).val (f y).val := by + suffices ∀ n : ℕ, ∀ x y : Interval cs u b, + rankDifference cs x.val y.val = n → x ≤ y → + rankDifference cs x.val y.val ≤ rankDifference cs' (f x).val (f y).val by + exact this _ x y rfl hxy + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro x y hn hxy + by_cases heq : x = y + · subst y + simp [rankDifference] + · have hne : x.val ≠ y.val := fun hv => heq (Subtype.ext hv) + obtain ⟨z, hxz, hzy, hzlen⟩ := exists_bruhat_successor cs hxy hne + let zI : Interval cs u b := ⟨z, bruhat_trans cs x.property.1 hxz, + bruhat_trans cs hzy y.property.2⟩ + have hxylen := length_le_of_bruhat cs hxy + have hzylen := length_le_of_bruhat cs hzy + have hsmall : rankDifference cs zI.val y.val < n := by + dsimp [zI, rankDifference] at hn ⊢ + omega + have hsub := ih _ hsmall zI y rfl hzy + have hxz' : x < zI := by + refine (lt_iff_le_and_ne).mpr ⟨hxz, ?_⟩ + intro hx + have hv : x.val = z := congrArg Subtype.val hx + have := congrArg cs.length hv + omega + have hfxz := hf hxz' + have hfxzlen : cs'.length (f x).val < cs'.length (f zI).val := by + apply length_lt_of_bruhat_ne cs' hfxz.le + intro hv + exact hfxz.ne (Subtype.ext hv) + have hfzyle := length_le_of_bruhat cs' (hf.monotone (show zI ≤ y from hzy)) + change cs.length y.val - cs.length z ≤ + cs'.length (f y).val - cs'.length (f zI).val at hsub + change cs.length y.val - cs.length x.val ≤ + cs'.length (f y).val - cs'.length (f x).val + omega + +/-- Rank is intrinsic to the abstract interval poset, with neither root +labels nor simple generators preserved by the isomorphism. -/ +theorem intervalIso_rankDifference + {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} + (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} + (ι : Interval cs u b ≃o Interval cs' u' b') + {x y : Interval cs u b} (hxy : x ≤ y) : + rankDifference cs x.val y.val = rankDifference cs' (ι x).val (ι y).val := by + apply Nat.le_antisymm + · exact rankDifference_le_of_strictMono cs cs' ι ι.strictMono hxy + · have h := rankDifference_le_of_strictMono cs' cs ι.symm ι.symm.strictMono (ι.monotone hxy) + simpa only [OrderIso.symm_apply_apply] using h + +/-- Named endpoints for an actual nonempty interval. -/ +def intervalBottom (cs : CoxeterSystem M W) {u b : W} (hub : BruhatLE cs u b) : + Interval cs u b := ⟨u, bruhat_refl cs u, hub⟩ + +def intervalTop (cs : CoxeterSystem M W) {u b : W} (hub : BruhatLE cs u b) : + Interval cs u b := ⟨b, hub, bruhat_refl cs b⟩ + +theorem intervalIso_bottom + {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} + (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') + (ι : Interval cs u b ≃o Interval cs' u' b') : + ι (intervalBottom cs hub) = intervalBottom cs' hub' := by + apply le_antisymm + · have h : intervalBottom cs hub ≤ ι.symm (intervalBottom cs' hub') := + (ι.symm (intervalBottom cs' hub')).property.1 + simpa only [OrderIso.apply_symm_apply] using ι.monotone h + · exact (ι (intervalBottom cs hub)).property.1 + +theorem intervalIso_top + {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} + (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') + (ι : Interval cs u b ≃o Interval cs' u' b') : + ι (intervalTop cs hub) = intervalTop cs' hub' := by + apply le_antisymm + · exact (ι (intervalTop cs hub)).property.2 + · have h : ι.symm (intervalTop cs' hub') ≤ intervalTop cs hub := + (ι.symm (intervalTop cs' hub')).property.2 + simpa only [OrderIso.apply_symm_apply] using ι.monotone h + +theorem intervalIso_full_rankDifference + {B' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix B'} + (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} (hub : BruhatLE cs u b) (hub' : BruhatLE cs' u' b') + (ι : Interval cs u b ≃o Interval cs' u' b') : + rankDifference cs u b = rankDifference cs' u' b' := by + have h := intervalIso_rankDifference cs cs' ι + (show intervalBottom cs hub ≤ intervalTop cs hub from hub) + rw [intervalIso_bottom cs cs' hub hub' ι, intervalIso_top cs cs' hub hub' ι] at h + exact h + +end KLInvariance + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/CharacterReciprocity.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/CharacterReciprocity.lean index 112306998161484603bdfcdf051194305e1d4f2c..df5761f4de7f4a728c53da39d21853242748c33e 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/CharacterReciprocity.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/CharacterReciprocity.lean @@ -1,2201 +1,2201 @@ -import OAI.RepresentationTheory.KazhdanLusztig.Support - -namespace OAI - -/-! -Conditional boundary-sheaf duality and stalk-character propositions, free sheaves, actual R-reciprocity and lower convolution. StalkCharacterObligation remains a Prop, not an unconditional character theorem or a premise of the R-first route. --/ - -section - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -variable [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] -noncomputable section - -def SectionDualityObligation : Prop := - ∃ d : SectionDuality cs 1 b basis (one_bruhat cs b) - (boundarySheaf cs 1 b basis (one_bruhat cs b)), - ∀ i j (m n : (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ), - m ∈ ((boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ).piece i → - n ∈ ((boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ).piece j → - d.pairing m n ∈ polynomialGrading ℝ σ (i+j-(cs.length b : ℤ)) - -end -end KLInvariance.BruhatGraph - -end - - -section - -/-! Balance of a two-sided perfect pairing needs orthogonality on both -sides, not equality of its two integral embeddings into an ambient form. -/ -namespace BalancedCuts -universe ur um ua -variable {R : Type ur} [CommRing R] [IsDomain R] - {M : Type um} [AddCommGroup M] [Module R M] - {A : Type ua} [AddCommGroup A] [Module R A] - (d : M →ₗ[R] Module.Dual R M) (π : M →ₗ[R] A) (c : M →ₗ[R] M) - (p : R) (hp : p≠0) (hπ : ∀ m, π (c m)=p • π m) - (hleft : ∀ m n, π n=0 → d (c m) n=0) - (hright : ∀ m n, π m=0 → d m (c n)=0) - -include hp hπ hleft hright in - theorem balanced_two (m n : M) : d (c m) n=d m (c n) := by - have hn : π (p • n-c n)=0 := by rw [map_sub,map_smul,hπ,sub_self] - have hm : π (p • m-c m)=0 := by rw [map_sub,map_smul,hπ,sub_self] - have en := hleft m _ hn - have em := hright _ n hm - simp only [map_sub,map_smul,LinearMap.sub_apply,LinearMap.smul_apply,smul_eq_mul,sub_eq_zero] at en em - exact mul_left_cancel₀ hp (en.trans em.symm) - -end BalancedCuts - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded Module -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] - {G : OrderedGraph V E} [IsDomain A] [DecidableEq V] - {S : GradedSheaf (𝓐 := 𝓐) G} {d : ℤ} (p : PerfectPairing S d) - (a : A) (ha : a≠0) - (hcut : ∀ x (m : S.forget.sections Set.univ), a • Pi.single x (m.val x)∈S.forget.sections Set.univ) -noncomputable section - - include ha in - theorem PerfectPairing.cut_balanced (x : V) (m n : S.forget.sections Set.univ) : - p.pairing (IntegralSupport.cut _ a hcut x m) n = - p.pairing m (IntegralSupport.cut _ a hcut x n) := by - apply BalancedCuts.balanced_two p.pairing.toLinearMap - (IntegralSupport.projection (S.forget.sections Set.univ) x) - (IntegralSupport.cut _ a hcut x) a ha - (IntegralSupport.cut_self _ a hcut x) - · intro v w hw - exact p.left_orthogonal x _ w (fun y hy => IntegralSupport.cut_other _ a hcut x y hy v) hw - · intro v w hv - exact p.right_orthogonal x v _ hv (fun y hy => IntegralSupport.cut_other _ a hcut x y hy w) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] -noncomputable section - - theorem sectionDualityObligation_of_perfectPairing - (p : GradedSheaf.PerfectPairing - (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf (cs.length b : ℤ)) : - SectionDualityObligation cs b basis := by - let B := boundarySheaf cs 1 b basis (one_bruhat cs b) - refine ⟨⟨p.pairing,?_⟩,?_⟩ - · intro x m n - exact p.cut_balanced (Sheaf.labelProduct (polynomialLabel cs 1 b basis)) - (Sheaf.labelProduct_ne_zero _ (polynomialLabel_ne_zero cs 1 b basis)) - (B.sheaf.forget.scaled_single_section - (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs 1 b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x m n - · intro i j m n hm hn - exact p.homogeneous i j m n (fun x => hm x (Set.mem_univ x)) - (fun x => hn x (Set.mem_univ x)) - -end -end KLInvariance.BruhatGraph - -end - - -section - -/-! Integral costalk duality only uses free stalks, the genuine edge quotients, -generation and a perfect support-orthogonal section form. No top/minimality or -KL character assumption is needed. This extension applies to genuine words. -/ -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) (u b : W) - {σ : Type us} (basis : Basis σ ℝ (Extended M)) - -structure FreeSheaf where - sheaf : GradedSheaf (𝓐 := polynomialGrading ℝ σ) (graph cs u b) - free : sheaf.FreeStalks - quotient : sheaf.UpperQuotient (polynomialLabel cs u b basis) - generated : sheaf.forget.Generated - -namespace FreeSheaf -variable (B : FreeSheaf cs u b basis) - [Fintype (Edge cs u b)] [DecidableEq (Interval cs u b)] -noncomputable section - def kernelEquivSingleSupport (x : Interval cs u b) : - LinearMap.ker (B.sheaf.forget.stalkMap x) ≃ₗ[Coefficient (σ := σ)] - IntegralSupport.supported (B.sheaf.forget.sections Set.univ) x := by - let _ (x : Interval cs u b) : Module.Free (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := B.free x - let _ (x : Interval cs u b) : Module.Finite (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := - (B.sheaf.vertex x).finite - let _ (x : Interval cs u b) : Fintype (Module.Free.ChooseBasisIndex - (Coefficient (σ := σ)) (B.sheaf.forget.vertex x)) := Fintype.ofFinite _ - let bs := fun x : Interval cs u b => - Module.Free.chooseBasis (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) - exact (B.sheaf.forget.kernelEquivSingleStalk (polynomialLabel cs u b basis) - (polynomialLabel_prime cs u b basis) (fun e => (B.quotient e).2) bs x - (incoming_pairwise_relPrime cs u b basis x) - (B.sheaf.forget.outgoing_product_regular (polynomialLabel cs u b basis) - (polynomialLabel_prime cs u b basis) (fun e => (B.quotient e).1) - (fun e => (B.quotient e).2) bs x - (outgoing_incoming_not_dvd cs u b basis x))).trans - (B.sheaf.forget.singleStalkEquivSupport x) - - -structure SectionDuality where - pairing : B.sheaf.forget.sections Set.univ ≃ₗ[Coefficient (σ := σ)] - Dual (Coefficient (σ := σ)) (B.sheaf.forget.sections Set.univ) - balanced : ∀ x m n, - pairing (IntegralSupport.cut (B.sheaf.forget.sections Set.univ) - (Sheaf.labelProduct (polynomialLabel cs u b basis)) - (B.sheaf.forget.scaled_single_section - (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x m) n = - pairing m (IntegralSupport.cut (B.sheaf.forget.sections Set.univ) - (Sheaf.labelProduct (polynomialLabel cs u b basis)) - (B.sheaf.forget.scaled_single_section - (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x n) - - def costalkEquivDual (d : SectionDuality cs u b basis B) (x : Interval cs u b) : - LinearMap.ker (B.sheaf.forget.stalkMap x) ≃ₗ[Coefficient (σ := σ)] - Dual (Coefficient (σ := σ)) (B.sheaf.vertex x) := by - let _ (x : Interval cs u b) : Module.Free (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := B.free x - let _ (y : Interval cs u b) : Module.IsTorsionFree (Coefficient (σ := σ)) - (B.sheaf.forget.vertex y) := inferInstance - exact (kernelEquivSingleSupport cs u b basis B x).trans - (B.sheaf.forget.singleSupportEquivDual (polynomialLabel cs u b basis) - (polynomialLabel_ne_zero cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) - d.pairing d.balanced B.generated x) - - theorem costalk_free_of_duality (d : SectionDuality cs u b basis B) - (x : Interval cs u b) : - Module.Free (Coefficient (σ := σ)) (LinearMap.ker (B.sheaf.forget.stalkMap x)) := by - let _ := B.free x - exact Module.Free.of_equiv (costalkEquivDual cs u b basis B d x).symm - - variable [Fintype σ] [Fintype (Interval cs u b)] - -omit [Fintype σ] [Fintype (Interval cs u b)] in - theorem kernelEquivSingleSupport_apply (x : Interval cs u b) - (v : LinearMap.ker (B.sheaf.forget.stalkMap x)) : - ((kernelEquivSingleSupport cs u b basis B x) v).val.val x = - Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • v.val := by - change (Pi.single x - (Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • v.val) : - B.sheaf.forget.Assignment) x = _ - exact Pi.single_eq_same _ _ - - theorem costalkEquivDual_inverse_homogeneous - (d : SectionDuality cs u b basis B) (l : ℤ) - (hd : ∀ i j (m n : B.sheaf.sections Set.univ), - m ∈ (B.sheaf.sections Set.univ).piece i → n ∈ (B.sheaf.sections Set.univ).piece j → - d.pairing m n ∈ polynomialGrading ℝ σ (i+j-l)) - (x : Interval cs u b) (r : ℤ) (lam : Dual (Coefficient (σ := σ)) (B.sheaf.vertex x)) - (hlam : ∀ j (v : B.sheaf.vertex x), v ∈ (B.sheaf.vertex x).piece j → - lam v ∈ polynomialGrading ℝ σ (j+r)) : - ((costalkEquivDual cs u b basis B d x).symm lam).val ∈ - (B.sheaf.vertex x).piece - (r+l-(Sheaf.incoming (G := graph cs u b) x).card) := by - let _ (y : Interval cs u b) : Module.Free (Coefficient (σ := σ)) - (B.sheaf.forget.vertex y) := B.free y - let _ (y : Interval cs u b) : Module.IsTorsionFree (Coefficient (σ := σ)) - (B.sheaf.forget.vertex y) := inferInstance - let S := B.sheaf.forget.singleSupportEquivDual (polynomialLabel cs u b basis) - (polynomialLabel_ne_zero cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) - d.pairing d.balanced B.generated x - have hs : (S.symm lam).val ∈ (B.sheaf.sections Set.univ).piece (r+l) := by - exact B.sheaf.dualToSupport_homogeneous (polynomialLabel cs u b basis) - (polynomialLabel_ne_zero cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) - d.pairing d.balanced l hd x r lam hlam - have hv := hs x (Set.mem_univ x) - have he : (S.symm lam).val.val x = - Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • - ((costalkEquivDual cs u b basis B d x).symm lam).val := by - rw [← kernelEquivSingleSupport_apply cs u b basis B x] - change (S.symm lam).val.val x = - ((kernelEquivSingleSupport cs u b basis B x) - ((kernelEquivSingleSupport cs u b basis B x).symm (S.symm lam))).val.val x - rw [LinearEquiv.apply_symm_apply] - change (S.symm lam).val.val x ∈ (B.sheaf.vertex x).piece (r+l) at hv - rw [he] at hv - apply mem_of_homogeneous_smul (polynomialGrading ℝ σ) (B.sheaf.vertex x).piece - ((Sheaf.incoming (G := graph cs u b) x).card : ℤ) - (Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x) - (incomingProduct_homogeneous cs u b basis x) _ (r+l) _ hv - let _ := B.free x - exact smul_right_injective _ (Sheaf.incomingProduct_ne_zero - (polynomialLabel cs u b basis) (polynomialLabel_prime cs u b basis) x) - - def fullSubmodule (x : Interval cs u b) : Submodule (Coefficient (σ := σ)) (B.sheaf.vertex x) := - LinearMap.ker (B.sheaf.forget.stalkMap x) - -omit [Fintype σ] [Fintype (Edge cs u b)] [Fintype (Interval cs u b)] - [DecidableEq (Interval cs u b)] in - theorem fullKernel_eq (x : Interval cs u b) : - B.sheaf.upwardSubmodule x Set.univ = fullSubmodule cs u b basis B x := by - ext m - change (∀ e ∈ Set.univ, B.sheaf.forget.stalkMap x m e = 0) ↔ B.sheaf.forget.stalkMap x m = 0 - simp only [Set.mem_univ,forall_const] - exact funext_iff.symm - - def fullKernel (x : Interval cs u b) : ModuleData (polynomialGrading ℝ σ) := - ModuleData.sub (B.sheaf.vertex x) (fullSubmodule cs u b basis B x) (by - simpa only [fullKernel_eq cs u b basis B x] using - B.sheaf.upwardKernel_homogeneous x Set.univ) - - theorem costalk_hilbert_of_duality - (d : SectionDuality cs u b basis B) (l : ℤ) - (hd : ∀ i j (m n : B.sheaf.sections Set.univ), - m ∈ (B.sheaf.sections Set.univ).piece i → n ∈ (B.sheaf.sections Set.univ).piece j → - d.pairing m n ∈ polynomialGrading ℝ σ (i+j-l)) - (x : Interval cs u b) (c : NonnegativeBasis (σ := σ) (B.sheaf.vertex x).piece) - {q : ℝ} (hq : 0 < q) (hq1 : q < 1) : - Hilbert.value (B.sheaf.vertex x).piece - ((fullSubmodule cs u b basis B x).restrictScalars ℝ) q = - q^(l-(Sheaf.incoming (G := graph cs u b) x).card) * - Polynomial.eval₂ (Int.castRingHom ℝ) q⁻¹ c.polynomial * - (1-q)⁻¹ ^ Fintype.card σ := by - classical - let K := fullKernel cs u b basis B x - let cb : Basis c.index (Coefficient (σ := σ)) K := - c.basis.dualBasis.map (costalkEquivDual cs u b basis B d x).symm - have hcb (i : c.index) : cb i ∈ K.piece - (l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ)) := by - change ((costalkEquivDual cs u b basis B d x).symm (c.basis.dualBasis i)).val ∈ - (B.sheaf.vertex x).piece _ - have h := costalkEquivDual_inverse_homogeneous cs u b basis B d l hd x - (-(c.degree i : ℤ)) (c.basis.dualBasis i) - (dualBasis_homogeneous (polynomialGrading ℝ σ) (B.sheaf.vertex x).piece - c.basis (fun i => (c.degree i : ℤ)) c.homogeneous i) - simpa only [show -(c.degree i : ℤ)+l-(Sheaf.incoming (G := graph cs u b) x).card = - l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ) by omega] using h - have hs := Hilbert.hasSum_homogeneous_basis K.piece cb - (fun i => l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ)) hcb hq hq1 - have hv : Hilbert.value K.piece ⊤ q = - (∑ i, q^(l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ))) * - (1-q)⁻¹ ^ Fintype.card σ := by - simpa only [Hilbert.value,Hilbert.term_top] using hs.tsum_eq - change Hilbert.value (B.sheaf.vertex x).piece - ((fullSubmodule cs u b basis B x).restrictScalars ℝ) q = _ - rw [← Hilbert.value_subPiece] - change Hilbert.value K.piece ⊤ q = _ - rw [hv,c.eval₂_eq,Finset.mul_sum] - congr 1 - apply Finset.sum_congr rfl - intro i _ - rw [zpow_sub₀ hq.ne',zpow_natCast,div_eq_mul_inv,inv_pow] - - - def dualityOfPairing {l : ℤ} (p : GradedSheaf.PerfectPairing B.sheaf l) : - SectionDuality cs u b basis B where - pairing := p.pairing - balanced := p.cut_balanced - (Sheaf.labelProduct (polynomialLabel cs u b basis)) - (Sheaf.labelProduct_ne_zero _ (polynomialLabel_ne_zero cs u b basis)) - (B.sheaf.forget.scaled_single_section - (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) - (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) - -end -end FreeSheaf -end KLInvariance.BruhatGraph - -end - - -section - -/-! The finite sums used by the actual local decomposition. The model criteria -are kept explicit here; they are not asserted for the constructed BMP object -or inserted into the main KL theorem. -/ -namespace KLInvariance.MomentGraph.Sheaf -universe u v w z -variable {R : Type u} [CommRing R] [IsLocalRing R] - {V : Type v} [PartialOrder V] {E : Type w} {G : OrderedGraph V E} - - -instance zeroVertex_subsingleton (x : V) : Subsingleton ((zero (R := R) (G := G)).vertex x) := - inferInstanceAs (Subsingleton PUnit) - -instance zeroEdge_subsingleton (e : E) : Subsingleton ((zero (R := R) (G := G)).edge e) := - inferInstanceAs (Subsingleton PUnit) - -structure LocalModels (α : E → R) where - sheaf : V → Sheaf.{u,v,w,z} (R := R) G - free : ∀ c x, Module.Free R ((sheaf c).vertex x) - finite : ∀ c x, Module.Finite R ((sheaf c).vertex x) - quotient : ∀ c, (sheaf c).UpperQuotient α - generated : ∀ c, (sheaf c).Generated - flabby : ∀ c, (sheaf c).Flabby - support : ∀ c x, ¬x ≤ c → Subsingleton ((sheaf c).vertex x) - top : ∀ c, (sheaf c).vertex c ≃ₗ[R] R - minimal : ∀ c x, x ≠ c → LinearMap.ker ((sheaf c).stalkMap x) ≤ - IsLocalRing.maximalIdeal R • (⊤ : Submodule R ((sheaf c).vertex x)) - -inductive ModelSum (O : V → Sheaf.{u,v,w,z} (R := R) G) (U : Set V) : - Sheaf.{u,v,w,z} (R := R) G → Prop where - | zero : ModelSum O U zero - | add {B} : ModelSum O U B → ∀ c ∈ U, ∀ n : ℕ, - ModelSum O U (prod B (pi (fun _ : Fin n => O c))) - -namespace ModelSum -variable {α : E → R} (O : LocalModels.{u,v,w,z} (G := G) α) - {U : Set V} {B : Sheaf.{u,v,w,z} (R := R) G} - -omit [IsLocalRing R] in -lemma mono {O : V → Sheaf.{u,v,w,z} (R := R) G} (h : ModelSum O U B) - {T : Set V} (hUT : U ⊆ T) : ModelSum O T B := by - induction h with - | zero => exact .zero - | add _ c hc n ih => exact .add ih c (hUT hc) n - -lemma free (h : ModelSum O.sheaf U B) (x : V) : Module.Free R (B.vertex x) := by - induction h with - | zero => exact inferInstanceAs (Module.Free R PUnit.{z+1}) - | @add C _ c _ n ih => - let _ : Module.Free R (C.vertex x) := ih - let _ := O.free c x - change Module.Free R (C.vertex x × (Fin n → (O.sheaf c).vertex x)) - infer_instance - -lemma finite (h : ModelSum O.sheaf U B) (x : V) : Module.Finite R (B.vertex x) := by - induction h with - | zero => exact inferInstanceAs (Module.Finite R PUnit.{z+1}) - | @add C _ c _ n ih => - let _ : Module.Finite R (C.vertex x) := ih - let _ := O.finite c x - change Module.Finite R (C.vertex x × (Fin n → (O.sheaf c).vertex x)) - infer_instance - -lemma quotient (h : ModelSum O.sheaf U B) : B.UpperQuotient α := by - induction h with - | zero => - intro e - exact ⟨fun v => ⟨0,Subsingleton.elim _ _⟩,fun v => ⟨fun _ => ⟨0,Subsingleton.elim _ _⟩,fun _ => Subsingleton.elim _ _⟩⟩ - | add _ c _ n ih => exact prod_upperQuotient _ _ α ih (pi_upperQuotient _ α (fun _ => O.quotient c)) - -lemma generated (h : ModelSum O.sheaf U B) : B.Generated := by - induction h with - | zero => exact fun x v => ⟨0,fun _ _ _ => rfl,Subsingleton.elim _ _⟩ - | add _ c _ n ih => exact prod_generated _ _ ih (pi_generated _ (fun _ => O.generated c)) - -lemma flabby (h : ModelSum O.sheaf U B) : B.Flabby := by - induction h with - | zero => exact fun U _ f _ => ⟨f,fun _ _ _ => rfl,fun _ _ => rfl⟩ - | add _ c _ n ih => exact prod_flabby _ _ ih (pi_flabby _ (fun _ => O.flabby c)) - -lemma minimal (h : ModelSum O.sheaf U B) (x : V) (hx : x ∉ U) : - LinearMap.ker (B.stalkMap x) ≤ - IsLocalRing.maximalIdeal R • (⊤ : Submodule R (B.vertex x)) := by - induction h with - | zero => - intro v _ - rw [Subsingleton.elim v 0] - exact Submodule.zero_mem _ - | add _ c hc n ih => - exact prod_minimal _ _ x _ ih (pi_minimal _ x _ - (fun _ => O.minimal c x (fun he => hx (he ▸ hc)))) - -end ModelSum -end KLInvariance.MomentGraph.Sheaf - -end - - -section - -namespace KLInvariance.MomentGraph.Sheaf -open scoped Pointwise -universe ur uv ue uz -variable {R : Type ur} [CommRing R] {V : Type uv} [PartialOrder V] - {E : Type ue} {G : OrderedGraph V E} - -/-- Equality of embedded images with a scalar on the upper image. -/ -def ScaledImages (B : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) - (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) : Prop := - ∀ z : B.edge e, - (∃ v ∈ B.upwardKernel (G.source e) F, B.lower e v=z) ↔ - ∃ w ∈ B.upwardKernel (G.target e) H, r • B.upper e w=z - -theorem scaledImages_iff (B : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) - (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) : - B.ScaledImages e F H r ↔ - (B.upwardKernel (G.source e) F).map (B.lower e) = - r • (B.upwardKernel (G.target e) H).map (B.upper e) := by - constructor - · intro h - ext z - rw [Submodule.mem_smul_pointwise_iff_exists] - change (∃ v, v ∈ B.upwardKernel (G.source e) F ∧ B.lower e v=z) ↔ _ - rw [h z] - constructor - · rintro ⟨w,hw,he⟩ - exact ⟨B.upper e w,⟨w,hw,rfl⟩,he⟩ - · rintro ⟨t,⟨w,hw,rfl⟩,he⟩ - exact ⟨w,hw,he⟩ - · intro h z - constructor - · rintro ⟨v,hv,rfl⟩ - have hv' : B.lower e v ∈ r • (B.upwardKernel (G.target e) H).map (B.upper e) := - h ▸ (show B.lower e v ∈ (B.upwardKernel (G.source e) F).map (B.lower e) from ⟨v,hv,rfl⟩) - obtain ⟨t,⟨w,hw,rfl⟩,he⟩ := (Submodule.mem_smul_pointwise_iff_exists _ _ _).mp hv' - exact ⟨w,hw,he⟩ - · rintro ⟨w,hw,rfl⟩ - have hw' : r • B.upper e w ∈ r • (B.upwardKernel (G.target e) H).map (B.upper e) := - (Submodule.mem_smul_pointwise_iff_exists _ _ _).mpr ⟨B.upper e w,⟨w,hw,rfl⟩,rfl⟩ - rw [← h] at hw' - exact hw' - -theorem prod_upwardKernel_iff (B C : Sheaf.{ur,uv,ue,uz} (R := R) G) - (x : V) (F : Set (Outgoing (G := G) x)) (v : (prod B C).vertex x) : - v ∈ (prod B C).upwardKernel x F ↔ - v.1 ∈ B.upwardKernel x F ∧ v.2 ∈ C.upwardKernel x F := by - constructor - · intro h - constructor - · rintro ⟨e,heq⟩ he - subst x - exact congrArg Prod.fst (h ⟨e,rfl⟩ he) - · rintro ⟨e,heq⟩ he - subst x - exact congrArg Prod.snd (h ⟨e,rfl⟩ he) - · rintro ⟨hB,hC⟩ ⟨e,heq⟩ he - subst x - exact Prod.ext (hB ⟨e,rfl⟩ he) (hC ⟨e,rfl⟩ he) - -theorem pi_upwardKernel_iff {ι : Type*} (B : ι → Sheaf.{ur,uv,ue,uz} (R := R) G) - (x : V) (F : Set (Outgoing (G := G) x)) (v : (pi B).vertex x) : - v ∈ (pi B).upwardKernel x F ↔ ∀ i, v i ∈ (B i).upwardKernel x F := by - constructor - · rintro h i ⟨e,heq⟩ he - subst x - exact congrFun (h ⟨e,rfl⟩ he) i - · rintro h ⟨e,heq⟩ he - subst x - exact funext (fun i => h i ⟨e,rfl⟩ he) - -theorem prod_scaledImages (B C : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) - (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) - (hB : B.ScaledImages e F H r) (hC : C.ScaledImages e F H r) : - (prod B C).ScaledImages e F H r := by - intro z - constructor - · rintro ⟨v,hv,he⟩ - have hv' := (prod_upwardKernel_iff B C _ F v).mp hv - obtain ⟨b,hb,hbe⟩ := (hB z.1).mp ⟨v.1,hv'.1,congrArg Prod.fst he⟩ - obtain ⟨c,hc,hce⟩ := (hC z.2).mp ⟨v.2,hv'.2,congrArg Prod.snd he⟩ - exact ⟨(b,c),(prod_upwardKernel_iff B C _ H _).mpr ⟨hb,hc⟩,Prod.ext hbe hce⟩ - · rintro ⟨v,hv,he⟩ - have hv' := (prod_upwardKernel_iff B C _ H v).mp hv - obtain ⟨b,hb,hbe⟩ := (hB z.1).mpr ⟨v.1,hv'.1,congrArg Prod.fst he⟩ - obtain ⟨c,hc,hce⟩ := (hC z.2).mpr ⟨v.2,hv'.2,congrArg Prod.snd he⟩ - exact ⟨(b,c),(prod_upwardKernel_iff B C _ F _).mpr ⟨hb,hc⟩,Prod.ext hbe hce⟩ - -theorem pi_scaledImages {ι : Type*} (B : ι → Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) - (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) - (hB : ∀ i, (B i).ScaledImages e F H r) : (pi B).ScaledImages e F H r := by - classical - intro z - constructor - · rintro ⟨v,hv,he⟩ - have hv' := (pi_upwardKernel_iff B _ F v).mp hv - choose w hw hwe using fun i => (hB i (z i)).mp ⟨v i,hv' i,congrFun he i⟩ - exact ⟨w,(pi_upwardKernel_iff B _ H _).mpr hw,funext hwe⟩ - · rintro ⟨v,hv,he⟩ - have hv' := (pi_upwardKernel_iff B _ H v).mp hv - choose w hw hwe using fun i => (hB i (z i)).mpr ⟨v i,hv' i,congrFun he i⟩ - exact ⟨w,(pi_upwardKernel_iff B _ F _).mpr hw,funext hwe⟩ - -theorem zero_scaledImages (e : E) (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) : - (zero : Sheaf.{ur,uv,ue,uz} (R := R) G).ScaledImages e F H r := by - intro z - constructor <;> intro _ <;> exact ⟨0,Submodule.zero_mem _,Subsingleton.elim _ _⟩ - -theorem ModelSum.scaledImages {O : V → Sheaf.{ur,uv,ue,uz} (R := R) G} - {U : Set V} {B : Sheaf.{ur,uv,ue,uz} (R := R) G} (h : ModelSum O U B) - (e : E) (F : Set (Outgoing (G := G) (G.source e))) - (H : Set (Outgoing (G := G) (G.target e))) (r : R) - (hO : ∀ c ∈ U, (O c).ScaledImages e F H r) : B.ScaledImages e F H r := by - induction h with - | zero => exact zero_scaledImages e F H r - | add _ c hc n ih => - exact prod_scaledImages _ _ e F H r ih - (pi_scaledImages (fun _ : Fin n => O c) e F H r (fun _ => hO c hc)) - -end KLInvariance.MomentGraph.Sheaf - -end - - -section - -/-! Actual full upward kernels commute with finite graded sums, shifts and -sheaf isomorphisms. No freeness is inferred without a free model. -/ -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - - abbrev kernelData (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) := - B.upwardKernel x Set.univ - - def kernelProdEquiv (B C : GradedSheaf (𝓐 := 𝓐) G) (x : V) : - kernelData (prod B C) x ≃ₗ[A] ((kernelData B x).prod (kernelData C x)) where - toFun m := ⟨⟨m.val.1,((Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ m.val).mp m.property).1⟩, - ⟨m.val.2,((Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ m.val).mp m.property).2⟩⟩ - invFun m := ⟨⟨m.1.val,m.2.val⟩,(Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ _).mpr - ⟨m.1.property,m.2.property⟩⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - - theorem kernelProdEquiv_graded (B C : GradedSheaf (𝓐 := 𝓐) G) (x : V) - (n : ℤ) (v : kernelData (prod B C) x) (hv : v∈(kernelData (prod B C) x).piece n) : - kernelProdEquiv B C x v∈((kernelData B x).prod (kernelData C x)).piece n := hv - - def kernelPiEquiv {ι : Type um} [Fintype ι] (B : ι → GradedSheaf (𝓐 := 𝓐) G) (x : V) : - kernelData (pi B) x ≃ₗ[A] ModuleData.pi (fun i => kernelData (B i) x) where - toFun m i := ⟨m.val i,(Sheaf.pi_upwardKernel_iff (fun i => (B i).forget) x Set.univ m.val).mp m.property i⟩ - invFun m := ⟨(fun i => (m i).val),(Sheaf.pi_upwardKernel_iff (fun i => (B i).forget) x Set.univ _).mpr - (fun i => (m i).property)⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - - theorem kernelPiEquiv_graded {ι : Type um} [Fintype ι] (B : ι → GradedSheaf (𝓐 := 𝓐) G) (x : V) - (n : ℤ) (v : kernelData (pi B) x) (hv : v∈(kernelData (pi B) x).piece n) : - kernelPiEquiv B x v∈(ModuleData.pi (fun i => kernelData (B i) x)).piece n := hv - - def kernelShiftEquiv (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) (d : ℕ) : - kernelData (B.shift d) x ≃ₗ[A] (kernelData B x).shift d := LinearEquiv.refl A _ - - theorem kernelShiftEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) (d : ℕ) - (n : ℤ) (v : kernelData (B.shift d) x) (hv : v∈(kernelData (B.shift d) x).piece n) : - kernelShiftEquiv B x d v∈((kernelData B x).shift d).piece n := hv - - def Iso.kernelEquiv {B C : GradedSheaf (𝓐 := 𝓐) G} (j : Iso B C) (x : V) : - kernelData B x ≃ₗ[A] kernelData C x where - toFun m := ⟨j.vertex x m.val,(j.toIso.upwardKernel_iff x Set.univ m.val).mpr m.property⟩ - invFun m := ⟨(j.vertex x).symm m.val,(j.toIso.symm.upwardKernel_iff x Set.univ m.val).mpr m.property⟩ - left_inv m := Subtype.ext ((j.vertex x).symm_apply_apply m.val) - right_inv m := Subtype.ext ((j.vertex x).apply_symm_apply m.val) - map_add' m n := Subtype.ext (map_add (j.vertex x) m.val n.val) - map_smul' a m := Subtype.ext (map_smul (j.vertex x) a m.val) - - theorem Iso.kernelEquiv_graded {B C : GradedSheaf (𝓐 := 𝓐) G} (j : Iso B C) (x : V) - (n : ℤ) (v : kernelData B x) (hv : v∈(kernelData B x).piece n) : - j.kernelEquiv x v∈(kernelData C x).piece n := j.vertex_graded x n v.val hv - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded Polynomial -universe uk us um -variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - - instance kernelShiftFree (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) (d : ℕ) - [Module.Free (MvPolynomial σ k) (kernelData B x)] : - Module.Free (MvPolynomial σ k) (kernelData (B.shift d) x) := - Module.Free.of_equiv (kernelShiftEquiv B x d).symm - - instance kernelProdFree (B C : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) - [Module.Free (MvPolynomial σ k) (kernelData B x)] - [Module.Free (MvPolynomial σ k) (kernelData C x)] : - Module.Free (MvPolynomial σ k) (kernelData (prod B C) x) := - Module.Free.of_equiv (kernelProdEquiv B C x).symm - - instance kernelPiFree {ι : Type um} [Fintype ι] - (B : ι → GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) - [∀ i, Module.Free (MvPolynomial σ k) (kernelData (B i) x)] : - Module.Free (MvPolynomial σ k) (kernelData (pi B) x) := - Module.Free.of_equiv (kernelPiEquiv B x).symm - - instance kernelZeroFree (x : V) : - Module.Free (MvPolynomial σ k) (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := by - let : Subsingleton (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := - ⟨fun x y => Subtype.ext (Subsingleton.elim _ _)⟩ - infer_instance - - theorem kernelChar_shift (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) (d : ℕ) - [Module.Free (MvPolynomial σ k) (kernelData B x)] : - (kernelData (B.shift d) x).char=X^d*(kernelData B x).char := by - rw [← ModuleData.char_shift _ d] - exact ModuleData.character_eq_of_gradedEquiv (kernelShiftEquiv B x d) - (kernelShiftEquiv_graded B x d) - - theorem kernelChar_prod (B C : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) - [Module.Free (MvPolynomial σ k) (kernelData B x)] - [Module.Free (MvPolynomial σ k) (kernelData C x)] : - (kernelData (prod B C) x).char=(kernelData B x).char+(kernelData C x).char := by - rw [← ModuleData.char_prod] - exact ModuleData.character_eq_of_gradedEquiv (kernelProdEquiv B C x) - (kernelProdEquiv_graded B C x) - - theorem kernelChar_pi {ι : Type um} [Fintype ι] - (B : ι → GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) - [∀ i, Module.Free (MvPolynomial σ k) (kernelData (B i) x)] : - (kernelData (pi B) x).char=∑ i, (kernelData (B i) x).char := by - rw [← ModuleData.char_pi] - exact ModuleData.character_eq_of_gradedEquiv (kernelPiEquiv B x) (kernelPiEquiv_graded B x) - - theorem kernelChar_zero (x : V) : - (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x).char=0 := by - let : Subsingleton (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := - ⟨fun x y => Subtype.ext (Subsingleton.elim _ _)⟩ - exact ModuleData.char_zero _ - - theorem ModelSum.kernelFree {O : V → GradedSheaf (𝓐 := polynomialGrading k σ) G} - (hf : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O y) x)) - {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} - (h : ModelSum O U B) (x : V) : Module.Free (MvPolynomial σ k) (kernelData B x) := by - induction h with - | zero => infer_instance - | @add C _ c _ n d ih => - let _ := ih - let _ := hf c x - infer_instance - - def freeKernelChar (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) - (hf : ∀ x, Module.Free (MvPolynomial σ k) (kernelData B x)) (x : V) : Polynomial ℤ := by - let := hf x - exact (kernelData B x).char - - theorem ModelSum.character_both [Fintype V] {α : E → MvPolynomial σ k} - (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) - (hk : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O.sheaf y) x)) - {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} - (h : ModelSum O.sheaf U B) : - ∃ m : V → Polynomial ℤ, (∀ y n, 0≤(m y).coeff n) ∧ - (∀ x, freeStalkChar B (h.free O) x = - ∑ y, m y*freeStalkChar (O.sheaf y) (O.free y) x) ∧ - (∀ x, freeKernelChar B (h.kernelFree hk) x = - ∑ y, m y*freeKernelChar (O.sheaf y) (hk y) x) := by - classical - induction h with - | zero => - refine ⟨0,by simp,?_,?_⟩ - · intro x - change ((GradedSheaf.zero (𝓐 := polynomialGrading k σ) (G := G)).vertex x).char = _ - simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] - exact ModuleData.char_zero _ - · intro x - change (kernelData (GradedSheaf.zero (𝓐 := polynomialGrading k σ) (G := G)) x).char = _ - simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] - exact kernelChar_zero (σ := σ) (G := G) x - | @add B h c hc n d ih => - obtain ⟨m,hm,heq,hkeq⟩ := ih - let a : Polynomial ℤ := ∑ i, X^(d i) - have ha (r : ℕ) : 0 ≤ a.coeff r := by - simp only [a,Polynomial.finsetSum_coeff,Polynomial.coeff_X_pow] - exact Finset.sum_nonneg (fun i _ => by split <;> norm_num) - refine ⟨fun y => m y+if y=c then a else 0,?_,?_,?_⟩ - · intro y r - rw [Polynomial.coeff_add] - apply add_nonneg (hm y r) - split - · exact ha r - · simp - · intro x - let _ := h.free O x - let _ := O.free c x - change ((B.vertex x).prod (ModuleData.pi (fun i => ((O.sheaf c).vertex x).shift (d i)))).char = _ - rw [ModuleData.char_prod,ModuleData.char_pi] - simp only [ModuleData.char_shift] - change freeStalkChar B (h.free O) x + _ = _ - rw [heq x] - simp only [add_mul,Finset.sum_add_distrib] - congr 1 - rw [← Finset.sum_mul] - simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] - rfl - · intro x - let _ := h.kernelFree hk x - let _ := hk c x - change (kernelData (prod B (pi (fun i => (O.sheaf c).shift (d i)))) x).char = _ - rw [kernelChar_prod,kernelChar_pi] - simp only [kernelChar_shift] - change freeKernelChar B (h.kernelFree hk) x + _ = _ - rw [hkeq x] - simp only [add_mul,Finset.sum_add_distrib] - congr 1 - rw [← Finset.sum_mul] - simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] - rfl - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - def kernelEquivFull (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) : - kernelData B x ≃ₗ[A] LinearMap.ker (B.forget.stalkMap x) where - toFun m := ⟨m.val,funext (fun e => m.property e (Set.mem_univ e))⟩ - invFun m := ⟨m.val,fun e _ => congrFun m.property e⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl -end -end KLInvariance.MomentGraph.GradedSheaf - -namespace KLInvariance.BruhatGraph.FreeSheaf -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (B : FreeSheaf cs 1 b basis) - [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] -noncomputable section - - def kernelDual (d : SectionDuality cs 1 b basis B) (x : Interval cs 1 b) : - Dual (Coefficient (σ := σ)) (B.sheaf.vertex x) ≃ₗ[Coefficient (σ := σ)] - GradedSheaf.kernelData B.sheaf x := - (costalkEquivDual cs 1 b basis B d x).symm.trans (B.sheaf.kernelEquivFull x).symm - -omit [Fintype (Interval cs 1 b)] in - theorem kernel_free (d : SectionDuality cs 1 b basis B) (x : Interval cs 1 b) : - Module.Free (Coefficient (σ := σ)) (GradedSheaf.kernelData B.sheaf x) := by - let := B.free x - exact Module.Free.of_equiv (kernelDual cs b basis B d x) - - theorem kernelDual_homogeneous (d : SectionDuality cs 1 b basis B) (n : ℕ) - (hd : ∀ i j (m a : B.sheaf.sections Set.univ), - m∈(B.sheaf.sections Set.univ).piece i → a∈(B.sheaf.sections Set.univ).piece j → - d.pairing m a∈polynomialGrading ℝ σ (i+j-(n:ℤ))) - (x : Interval cs 1 b) (hn : cs.length x.val≤n) (r : ℤ) - (lam : Dual (Coefficient (σ := σ)) (B.sheaf.vertex x)) - (hlam : ∀ j (v : B.sheaf.vertex x), v∈(B.sheaf.vertex x).piece j → - lam v∈polynomialGrading ℝ σ (j+r)) : - kernelDual cs b basis B d x lam∈(GradedSheaf.kernelData B.sheaf x).piece - (r+(n-cs.length x.val : ℕ)) := by - have h := costalkEquivDual_inverse_homogeneous cs 1 b basis B d n hd x r lam hlam - rw [incoming_card] at h - change ((costalkEquivDual cs 1 b basis B d x).symm lam).val∈ - (B.sheaf.vertex x).piece (r+↑(n-cs.length x.val)) - have he : r+(n:ℤ)-cs.length x.val=r+↑(n-cs.length x.val) := by omega - rwa [he] at h - - theorem kernel_character (d : SectionDuality cs 1 b basis B) (n : ℕ) - (hd : ∀ i j (m a : B.sheaf.sections Set.univ), - m∈(B.sheaf.sections Set.univ).piece i → a∈(B.sheaf.sections Set.univ).piece j → - d.pairing m a∈polynomialGrading ℝ σ (i+j-(n:ℤ))) - (hn : cs.length b≤n) (x : Interval cs 1 b) : - GradedSheaf.freeKernelChar B.sheaf (kernel_free cs b basis B d) x= - Polynomial.reflect (n-cs.length x.val) (GradedSheaf.freeStalkChar B.sheaf B.free x) := by - let := B.free x - let := kernel_free cs b basis B d x - exact ModuleData.char_of_dual_equiv _ _ (kernelDual cs b basis B d x) _ - (kernelDual_homogeneous cs b basis B d n hd x ((length_le_of_bruhat cs x.property.2).trans hn)) - -end -end KLInvariance.BruhatGraph.FreeSheaf - -end - - -section - -/-! Genuine word costalk character from the integral word pairing, transported -along the fixed symmetric-algebra coordinate isomorphism. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottSection_left_orthogonal (l : List I) (hl : cs.IsReduced l) - (x : Interval cs 1 (cs.wordProd l)) - (m n : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) - (hm : ∀ y, y≠x → m.val y=0) (hn : n.val x=0) : - bottSectionDuality cs l hl m n=0 := by - obtain ⟨a,rfl⟩ := bottSection_surjective cs l hl m - obtain ⟨b,rfl⟩ := bottSection_surjective cs l hl n - rw [bottSectionDuality_apply] - exact bottStalk_supported_annihilates cs l hl x a b hm hn - - theorem bottSection_right_orthogonal (l : List I) (hl : cs.IsReduced l) - (x : Interval cs 1 (cs.wordProd l)) - (m n : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) - (hm : m.val x=0) (hn : ∀ y, y≠x → n.val y=0) : - bottSectionDuality cs l hl m n=0 := by - rw [bottSection_symmetric] - exact bottSection_left_orthogonal cs l hl x n m hn hm - - def bottWordPerfectPairing (l : List I) (hl : cs.IsReduced l) : - GradedSheaf.PerfectPairing (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) - (l.length : ℤ) where - pairing := bottSectionDuality cs l hl - homogeneous := bottSectionDuality_homogeneous cs basis l hl - left_orthogonal := bottSection_left_orthogonal cs l hl - right_orthogonal := bottSection_right_orthogonal cs l hl - - def bottPolynomialPerfectPairing (l : List I) (hl : cs.IsReduced l) : - GradedSheaf.PerfectPairing (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) (l.length : ℤ) := - (bottWordPerfectPairing cs basis l hl).coefficientChange (SymmetricAlgebra.equivMvPolynomial basis) - (mem_symmetricGrading basis) - - def bottFreeSheaf (l : List I) : FreeSheaf cs 1 (cs.wordProd l) basis where - sheaf := bottPolynomialSheaf cs basis l 1 (cs.wordProd l) - free := bottPolynomialSheaf_free cs basis l 1 (cs.wordProd l) - quotient := bottPolynomialSheaf_quotient cs basis l 1 (cs.wordProd l) - generated := bottPolynomialSheaf_generated cs basis l 1 (cs.wordProd l) - -local instance finiteEdges (l : List I) : Fintype (Edge cs 1 (cs.wordProd l)) := Fintype.ofFinite _ -local instance (a : Type*) : DecidableEq a := Classical.decEq a - - def bottFreeDuality (l : List I) (hl : cs.IsReduced l) : - FreeSheaf.SectionDuality cs 1 (cs.wordProd l) basis (bottFreeSheaf cs basis l) := - FreeSheaf.dualityOfPairing cs 1 (cs.wordProd l) basis _ (bottPolynomialPerfectPairing cs basis l hl) - - theorem bottKernelFree (l : List I) (hl : cs.IsReduced l) (x : Interval cs 1 (cs.wordProd l)) : - Module.Free (Coefficient (σ := σ)) - (GradedSheaf.kernelData (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) x) := - FreeSheaf.kernel_free cs (cs.wordProd l) basis _ (bottFreeDuality cs basis l hl) x - - theorem bottKernelCharacter (l : List I) (hl : cs.IsReduced l) - [Fintype (Interval cs 1 (cs.wordProd l))] (x : Interval cs 1 (cs.wordProd l)) : - GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) - (bottKernelFree cs basis l hl) x=Polynomial.reflect (rankDifference cs x.val (cs.wordProd l)) - (bottStalkCharacter cs basis l x.val) := by - have he : cs.length (cs.wordProd l)=l.length := hl - change _=Polynomial.reflect (cs.length (cs.wordProd l)-cs.length x.val) _ - rw [he] - apply FreeSheaf.kernel_character cs (cs.wordProd l) basis _ (bottFreeDuality cs basis l hl) - l.length _ he.le x - intro i j m a hm ha - exact (bottPolynomialPerfectPairing cs basis l hl).homogeneous i j m a - (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Bar and the exact R-convolution for genuine positive Hecke words. -No KL character or degree estimate is assumed. -/ -namespace KLInvariance.HeckeQ -open Hecke (Space basis) -variable {I W C : Type*} [Group W] {M : CoxeterMatrix I} [CommRing C] -noncomputable section - - theorem one_add_leftInv (cs : CoxeterSystem M W) (q : Cˣ) (i : I) (v : Space W C) : - v+leftInv cs q i v=(↑q⁻¹:C) • (v+left cs (q:C) i v) := by - rw [leftInv_apply,smul_sub,smul_smul,smul_add] - have h : (↑q⁻¹:C)*((q:C)-1)=1-(↑q⁻¹:C) := by rw [mul_sub,q.inv_mul,mul_one] - rw [h,sub_smul,one_smul] - module - - theorem barLinear_positiveWord (cs : CoxeterSystem M W) (q : Cˣ) (l : List I) : - barLinear cs q (positiveWord cs (↑q⁻¹:C) l)= - (↑q⁻¹:C)^l.length • positiveWord cs (q:C) l := by - induction l with - | nil => simp [barBasis_one] - | cons i l ih => - simp only [positiveWord,map_add] - have h := congrArg (fun f : Module.End C (Space W C) => f (positiveWord cs (↑q⁻¹:C) l)) - (barLinear_left cs q i) - simp only [Module.End.mul_apply] at h - rw [h,ih,map_smul,← smul_add,one_add_leftInv,smul_smul,List.length_cons,pow_succ] - - theorem positiveWord_support (cs : CoxeterSystem M W) (q : C) (l : List I) - (hl : cs.IsReduced l) : (positiveWord cs q l).support ⊆ lowerFinset cs (cs.wordProd l) := by - classical - induction l with - | nil => simpa [positiveWord,Hecke.basis,lowerFinset] using - (show (Finsupp.single 1 (1:C)).support ⊆ lowerFinset cs 1 by - intro x hx - by_cases h : x=1 - · subst x; exact (mem_lowerFinset cs 1 1).mpr .refl - · simp [Finsupp.mem_support_iff,Ne.symm h] at hx) - | cons i l ih => - have ht : cs.IsReduced l := by simpa using hl.drop 1 - have ha : ¬cs.length (cs.simple i*cs.wordProd l) simp_all - rcases h with h|h - · exact (le_upperSimple cs i x).trans - (step x ((mem_lowerFinset cs _ _).mp (ih ht (Finsupp.mem_support_iff.mpr h)))) - · have hh := step (cs.simple i*x) - ((mem_lowerFinset cs _ _).mp (ih ht (Finsupp.mem_support_iff.mpr h))) - rw [upperSimple_mul] at hh - exact (le_upperSimple cs i x).trans hh - - theorem positiveWord_rValue (cs : CoxeterSystem M W) (q : Cˣ) (l : List I) - (hl : cs.IsReduced l) (x : W) : - ∑ z ∈ lowerFinset cs (cs.wordProd l), rValue cs q x z * positiveWord cs (q:C) l z= - (↑q⁻¹:C)^cs.length x * (q:C)^l.length * positiveWord cs (↑q⁻¹:C) l x := by - classical - have h := congrArg (fun v : Space W C => v x) (barLinear_positiveWord cs q⁻¹ l) - simp only [inv_inv] at h - rw [barLinear,Finsupp.linearCombination_apply,Finsupp.sum_apply, - Finsupp.sum_of_support_subset _ (positiveWord_support cs (q:C) l hl) _ (by simp)] at h - simp only [Finsupp.smul_apply,smul_eq_mul] at h - have hr (z : W) : rValue cs q x z=(↑q⁻¹:C)^cs.length x * barBasis cs q⁻¹ z x := by - simpa using rValue_inverse_eq_barBasis cs q⁻¹ x z - simp only [hr,mul_assoc,←Finset.mul_sum] - rw [show (∑ z ∈ lowerFinset cs (cs.wordProd l), barBasis cs q⁻¹ z x * positiveWord cs (q:C) l z)= - (q:C)^l.length * positiveWord cs (↑q⁻¹:C) l x by - simpa only [mul_comm] using h] - -end -end KLInvariance.HeckeQ - -end - - -section - -namespace KLInvariance.HeckeQ -open Hecke (Space basis) -variable {I W C : Type*} [Group W] {M : CoxeterMatrix I} [CommRing C] -noncomputable section - - theorem eval_positiveWord (cs : CoxeterSystem M W) (q : C) (l : List I) (x : W) : - Polynomial.eval₂ (Int.castRingHom C) q - (positiveWord cs (Polynomial.X : Polynomial ℤ) l x)=positiveWord cs q l x := by - classical - induction l generalizing x with - | nil => simp only [positiveWord_nil,Hecke.basis,Finsupp.single_apply]; split_ifs <;> simp - | cons i l ih => - rw [positiveWord_cons_coeff,positiveWord_cons_coeff] - split_ifs <;> simp only [Polynomial.eval₂_add,Polynomial.eval₂_mul, - Polynomial.eval₂_X,ih] - -end -end KLInvariance.HeckeQ - -end - - -section - -namespace KLInvariance.Graded.ModuleData -open Polynomial Module -universe uk us um -variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] - (M N : ModuleData.{uk,max uk us,um} (polynomialGrading k σ)) -noncomputable section - - theorem char_natDegree_le_of_dual_equiv [Module.Free (MvPolynomial σ k) M] - (e : Dual (MvPolynomial σ k) M ≃ₗ[MvPolynomial σ k] N) (l : ℕ) - (he : ∀ r lam, (∀ j (v : M), v∈M.piece j → - lam v∈polynomialGrading k σ (j+r)) → e lam∈N.piece (r+l)) : - M.char.natDegree≤l := by - classical - let c := (exists_nonnegativeBasis (σ := σ) M.piece M.nonneg).some - rw [char,character_eq _ _ c] - apply Polynomial.natDegree_sum_le_of_forall_le - intro i _ - simpa only [Polynomial.natDegree_X_pow] using M.degree_le_of_dual_equiv N e l he c i - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -/-! Genuine word stalk-to-costalk R-convolution, derived from the Hecke bar -and the constructed integral perfect word pairing. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (a : Type*) : DecidableEq a := Classical.decEq a -local instance rWordEdges (l : List I) : Fintype (Edge cs 1 (cs.wordProd l)) := Fintype.ofFinite _ -local instance rWordInterval (l : List I) : Fintype (Interval cs 1 (cs.wordProd l)) := by - let := interval_finite cs 1 (cs.wordProd l) - exact Fintype.ofFinite _ - - theorem bottStalkCharacter_natDegree_le (l : List I) (hl : cs.IsReduced l) - (x : Interval cs 1 (cs.wordProd l)) : - (bottStalkCharacter cs basis l x.val).natDegree≤rankDifference cs x.val (cs.wordProd l) := by - let B := bottFreeSheaf cs basis l - let := B.free x - change (B.sheaf.vertex x).char.natDegree≤rankDifference cs x.val (cs.wordProd l) - apply ModuleData.char_natDegree_le_of_dual_equiv _ _ - (FreeSheaf.kernelDual cs (cs.wordProd l) basis B (bottFreeDuality cs basis l hl) x) - (rankDifference cs x.val (cs.wordProd l)) - have hd := (bottPolynomialPerfectPairing cs basis l hl).homogeneous - have he : cs.length (cs.wordProd l)=l.length := hl - apply FreeSheaf.kernelDual_homogeneous cs (cs.wordProd l) basis B (bottFreeDuality cs basis l hl) - (cs.length (cs.wordProd l)) _ x (length_le_of_bruhat cs x.property.2) - intro i j m a hm ha - rw [he] - exact hd i j m a (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) - - theorem bottStalkCharacter_reciprocity (l : List I) (hl : cs.IsReduced l) - (x : Interval cs 1 (cs.wordProd l)) : - Polynomial.reflect (rankDifference cs x.val (cs.wordProd l)) (bottStalkCharacter cs basis l x.val)= - ∑ z ∈ lowerFinset cs (cs.wordProd l), - OrdinaryR.polynomial cs x.val z*bottStalkCharacter cs basis l z := by - apply Polynomial.toLaurent_injective - let q := OrdinaryR.variableUnit - have h := HeckeQ.positiveWord_rValue cs q l hl x.val - have hlen : cs.length x.val≤l.length := hl ▸ length_le_of_bruhat cs x.property.2 - have hp : (↑q⁻¹ : LaurentPolynomial ℤ)^cs.length x.val * (q:LaurentPolynomial ℤ)^l.length= - (q:LaurentPolynomial ℤ)^(rankDifference cs x.val (cs.wordProd l)) := by - have he : cs.length (cs.wordProd l)=l.length := hl - rw [rankDifference,he,← Nat.sub_add_cancel hlen,pow_add] - calc - _ = ((↑q⁻¹:LaurentPolynomial ℤ)*(q:LaurentPolynomial ℤ))^cs.length x.val * - (q:LaurentPolynomial ℤ)^(l.length-cs.length x.val) := by rw [mul_pow]; ring - _ = _ := by rw [q.inv_mul]; simp - rw [hp] at h - have hv (p : Polynomial ℤ) : Polynomial.toLaurent p= - Polynomial.eval₂ (Int.castRingHom (LaurentPolynomial ℤ)) (q:LaurentPolynomial ℤ) p := by - induction p using Polynomial.induction_on' with - | add p r hp hr => simp only [map_add,Polynomial.eval₂_add,hp,hr] - | monomial n a => simp [q,Polynomial.toLaurent_C_mul_T] - rw [hv,eval₂_reflect_unit q _ _ (bottStalkCharacter_natDegree_le cs basis l hl x)] - rw [hv] - simp only [Polynomial.eval₂_finsetSum,Polynomial.eval₂_mul,OrdinaryR.polynomial_eval, - bottStalkCharacter_eq_heckeWord,HeckeQ.eval_positiveWord] - exact h.symm - - theorem bottKernelCharacter_rConvolution (l : List I) (hl : cs.IsReduced l) - (x : Interval cs 1 (cs.wordProd l)) : - GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) - (bottKernelFree cs basis l hl) x= - ∑ z : Interval cs 1 (cs.wordProd l), - OrdinaryR.polynomial cs x.val z.val*bottStalkCharacter cs basis l z.val := by - rw [bottKernelCharacter cs basis l hl x,bottStalkCharacter_reciprocity cs basis l hl x] - exact Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs 1 (cs.wordProd l)))) - (lowerFinset cs (cs.wordProd l)) - (fun z => by simp only [mem_lowerFinset]; exact ⟨fun h => ⟨one_bruhat cs z,h⟩,And.right⟩) - (fun z => OrdinaryR.polynomial cs x.val z*bottStalkCharacter cs basis l z) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Recognition by the actual minimal-boundary object, not by an asserted -character or by restricting a perfect form to an arbitrary summand. -/ -namespace KLInvariance.MomentGraph.BoundarySheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] - [IsDomain A] {hneg : ∀ n < 0, 𝓐 n=⊥} - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} {α : E → A} {b : V} - (B : BoundarySheaf hneg G α b) -noncomputable section - - theorem top_nontrivial : Nontrivial (B.sheaf.vertex b) := by - let e := ModuleData.equivOfEq B.top - let z : ModuleData.unit.{uk,ua,um} hneg := fun _ => (0 : A) - let o : ModuleData.unit.{uk,ua,um} hneg := fun _ => (1 : A) - refine ⟨⟨e.symm z,e.symm o,?_⟩⟩ - intro h - exact zero_ne_one (congrFun (e.symm.injective h) PUnit.unit) - - variable [IsNoetherianRing A] [Fintype V] [Fintype E] - - theorem iso_of_primitive_top_split - (hzero : ∀ a ∈ 𝓐 0, ∃ c : k, algebraMap k A c=a) - (hb : ∀ x, x≤b) (C : GradedSheaf (𝓐 := 𝓐) G) - (hCq : C.UpperQuotient α) (hCfree : ∀ x, Module.Free A (C.vertex x)) - (hCf : C.forget.Flabby) (hCg : C.forget.Generated) - (hCp : (GradedSheaf.Hom.id C).PrimitiveProjector) - (i : ModuleData.Hom (B.sheaf.vertex b) (C.vertex b)) - (p : ModuleData.Hom (C.vertex b) (B.sheaf.vertex b)) - (hpi : ∀ v, p.map (i.map v)=v) : Nonempty (GradedSheaf.Iso B.sheaf C) := by - let := B.top_nontrivial - obtain ⟨s⟩ := B.splitIn_of_top_split hzero hb C hCq hCfree hCf hCg i p hpi - exact ⟨s.isoOfPrimitive hCp b⟩ - -end -end KLInvariance.MomentGraph.BoundarySheaf - -end - - -section - -/-! The actual symmetric-coefficient BMP boundary sheaf is isomorphic to -its integral adjoint image. The splitting is constructed from the word's -proved free-stalk, exact-edge and flabbiness properties. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (B : BoundarySheaf (symmetricGrading_negative basis) - (graph cs 1 (cs.wordProd l)) (symmetricLabel cs 1 (cs.wordProd l)) - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) - (s : GradedSheaf.SplitIn B.sheaf (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - def bottSplitAdjointSplit : GradedSheaf.SplitIn - (bottSplitAdjointSheaf cs basis l hl B.sheaf s) - (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) := by - let := symmetricCoefficientNoetherian basis - exact (bottAdjointSheaf cs basis l hl s.projector).imageSplit - (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) - (bottAdjointSheaf_edge_idempotent cs basis l hl s.projector s.projector_vertex) - - theorem bottSplitAdjoint_free (x : Interval cs 1 (cs.wordProd l)) : - Module.Free (SymmetricCoefficient (M := M)) - ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex x) := by - let := symmetricCoefficientNoetherian basis - let : Module.Free (SymmetricCoefficient (M := M)) - ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).vertex x) := - bottStalkFree cs l x.val - exact (bottSplitAdjointSplit cs basis l hl B s).vertex_free - (symmetricGrading_negative basis) (symmetricGrading_zero basis) x - - def bottSplitAdjointTopInclusion : ModuleData.Hom - (B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) - ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) := - ((bottSplitAdjointSplit cs basis l hl B s).projection.vertex _).comp - (bottBoundarySheafTopInclusion cs basis l hl B) - - def bottSplitAdjointTopProjection : ModuleData.Hom - ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) - (B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) := - (bottBoundarySheafTopProjection cs basis l hl B).comp - ((bottSplitAdjointSplit cs basis l hl B s).inclusion.vertex _) - - theorem bottSplitAdjointTop_split - (v : B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) : - (bottSplitAdjointTopProjection cs basis l hl B s).map - ((bottSplitAdjointTopInclusion cs basis l hl B s).map v)=v := by - change (bottBoundarySheafTopProjection cs basis l hl B).map - (((bottAdjointSheaf cs basis l hl s.projector).vertex - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩).map - ((bottBoundarySheafTopInclusion cs basis l hl B).map v))=v - exact (congrArg (bottBoundarySheafTopProjection cs basis l hl B).map - (bottBoundarySplitAdjoint_top_fixed cs basis l hl _ B s - ((bottBoundarySheafTopInclusion cs basis l hl B).map v))).trans - (bottBoundarySheafTop_split cs basis l hl B v) - - theorem bottBoundarySheaf_iso_adjoint : Nonempty - (GradedSheaf.Iso B.sheaf (bottSplitAdjointSheaf cs basis l hl B.sheaf s)) := by - classical - let := symmetricCoefficientNoetherian basis - let := interval_finite cs 1 (cs.wordProd l) - let := Fintype.ofFinite (Interval cs 1 (cs.wordProd l)) - let := Fintype.ofFinite (Edge cs 1 (cs.wordProd l)) - let t := bottSplitAdjointSplit cs basis l hl B s - exact B.iso_of_primitive_top_split (symmetricGrading_zero basis) (fun x => x.property.2) - (bottSplitAdjointSheaf cs basis l hl B.sheaf s) - (t.upperQuotient (bottGradedProjectionSheaf_upperQuotient cs basis l 1 (cs.wordProd l))) - (bottSplitAdjoint_free cs basis l hl B s) - (t.flabby (bottProjectionSheaf_flabby cs l hl)) - (t.generated (bottProjectionSheaf_generated cs l 1 (cs.wordProd l))) - (bottBoundarySplitAdjoint_primitive cs basis l hl _ B s) - (bottSplitAdjointTopInclusion cs basis l hl B s) - (bottSplitAdjointTopProjection cs basis l hl B s) - (bottSplitAdjointTop_split cs basis l hl B s) - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} - {B C : GradedSheaf (𝓐 := 𝓐) G} (s : SplitIn B C) -noncomputable section - - theorem SplitIn.imageSectionEquiv_symm_coordinates (U : Set V) - (n : B.forget.sections U) (x : V) : - (((s.imageSectionEquiv U).symm n).val x).val=(s.inclusion.vertex x).map (n.val x) := by - rw [s.imageSectionEquiv_symm_apply] - change (s.inclusion.vertex x).map ((s.projection.vertex x).map - ((s.inclusion.vertex x).map (n.val x)))=(s.inclusion.vertex x).map (n.val x) - exact congrArg (s.inclusion.vertex x).map (s.vertex_split x (n.val x)) - - theorem SplitIn.imageSectionEquiv_symm_inclusion (U : Set V) - (n : B.forget.sections U) : - s.projector.imageInclusion.sectionMap U ((s.imageSectionEquiv U).symm n)= - s.inclusion.sectionMap U n := by - apply Subtype.ext - funext x - exact s.imageSectionEquiv_symm_coordinates U n x - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -/-! The adjoint-summand pairing is the ambient word pairing on its two -honest (generally different) integral sheaf embeddings. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) - (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) -noncomputable section - - def bottSplitRightWord (n : B.forget.sections Set.univ) : BottSamelsonModule cs l := by - let := symmetricCoefficientNoetherian basis - exact (bottImageSectionWordEquiv cs basis l hl s.projector s.projector_vertex - ((s.imageSectionEquiv Set.univ).symm n)).val - - def bottSplitLeftWord - (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) : - BottSamelsonModule cs l := by - let := symmetricCoefficientNoetherian basis - exact (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl s.projector) - (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) m).val - - theorem bottSplitRightWord_coordinates (n : B.forget.sections Set.univ) - (x : Interval cs 1 (cs.wordProd l)) : - bottStalkProjection cs l x.val (bottSplitRightWord cs basis l hl B s n)= - (s.inclusion.vertex x).map (n.val x) := by - let := symmetricCoefficientNoetherian basis - exact (bottImageSectionWordEquiv_coordinates cs basis l hl s.projector s.projector_vertex - ((s.imageSectionEquiv Set.univ).symm n) x).trans - (s.imageSectionEquiv_symm_coordinates Set.univ n x) - - theorem bottSplitLeftWord_coordinates - (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) - (x : Interval cs 1 (cs.wordProd l)) : - bottStalkProjection cs l x.val (bottSplitLeftWord cs basis l hl B s m)=(m.val x).val := by - let := symmetricCoefficientNoetherian basis - exact bottImageSectionWordEquiv_coordinates cs basis l hl - (bottAdjointSheaf cs basis l hl s.projector) - (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) m x - - theorem bottSplitAdjointWord_apply - (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) - (n : B.forget.sections Set.univ) : - bottSplitAdjointEquivDual cs basis l hl B s m n= - bottSamelsonDuality cs l (bottSplitLeftWord cs basis l hl B s m) - (bottSplitRightWord cs basis l hl B s n) := by - let := symmetricCoefficientNoetherian basis - exact bottAdjointImageEquivDual_apply cs basis l hl s.projector s.projector_vertex m - ((s.imageSectionEquiv Set.univ).symm n) - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! An actual recognition isomorphism to the adjoint image gives the required -perfect pairing. The two ambient embeddings remain distinct. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) - (l : List I) (hl : cs.IsReduced l) - (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) - (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) - (j : GradedSheaf.Iso B (bottSplitAdjointSheaf cs basis l hl B s)) -noncomputable section - - def bottRecognizedPerfectPairing : GradedSheaf.PerfectPairing B (l.length : ℤ) where - pairing := (j.toIso.sections Set.univ).trans (bottSplitAdjointEquivDual cs basis l hl B s) - homogeneous i q m n hm hn := bottSplitAdjointPairing_homogeneous cs basis l hl B s i q - (j.toIso.sections Set.univ m) n (fun x => j.vertex_graded x i _ (hm x)) hn - left_orthogonal x m n hm hn := by - change bottSplitAdjointEquivDual cs basis l hl B s (j.toIso.sections Set.univ m) n=0 - rw [bottSplitAdjointWord_apply] - apply bottStalk_supported_annihilates cs l hl x - · intro y hy - rw [bottSplitLeftWord_coordinates] - change ((j.vertex y (m.val y)).val)=0 - rw [hm y hy,map_zero] - rfl - · rw [bottSplitRightWord_coordinates] - change (s.inclusion.vertex x).map (n.val x)=0 - rw [hn] - exact (s.inclusion.vertex x).map.map_zero - right_orthogonal x m n hm hn := by - change bottSplitAdjointEquivDual cs basis l hl B s (j.toIso.sections Set.univ m) n=0 - rw [bottSplitAdjointWord_apply,bottSamelson_symmetric] - apply bottStalk_supported_annihilates cs l hl x - · intro y hy - rw [bottSplitRightWord_coordinates] - change (s.inclusion.vertex y).map (n.val y)=0 - rw [hn y hy] - exact (s.inclusion.vertex y).map.map_zero - · rw [bottSplitLeftWord_coordinates] - change ((j.vertex x (m.val x)).val)=0 - rw [hm,map_zero] - rfl - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! The same genuine minimal boundary construction over the symmetric -coefficient algebra. Its polynomial-coordinate comparison is proved separately. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - omit [Fintype σ] in - theorem symmetric_scalar_mod_positive (a : SymmetricCoefficient (M := M)) : - ∃ c : ℝ, a-algebraMap ℝ (SymmetricCoefficient (M := M)) c ∈ positiveIdeal (symmetricGrading basis) := by - obtain ⟨c,hc⟩ := symmetricGrading_zero basis _ - (DirectSum.decompose (symmetricGrading basis) a 0).property - refine ⟨c,?_⟩ - rw [positiveIdeal_eq_augmentation_ker _ (symmetricGrading_negative basis)] - change component (symmetricGrading basis) 0 (a-algebraMap ℝ (SymmetricCoefficient (M := M)) c)=0 - rw [map_sub,hc] - rw [show component (symmetricGrading basis) 0 - (DirectSum.decompose (symmetricGrading basis) a 0 : SymmetricCoefficient (M := M)) = - (DirectSum.decompose (symmetricGrading basis) a 0 : SymmetricCoefficient (M := M)) from - DirectSum.decompose_of_mem_same _ (DirectSum.decompose (symmetricGrading basis) a 0).property] - exact sub_self _ - - theorem symmetricLabel_homogeneous (u b : W) (e : Edge cs u b) : - symmetricLabel cs u b e ∈ symmetricGrading basis 1 := - (mem_symmetricGrading basis 1 _).mpr (polynomialLabel_homogeneous cs u b basis e) - - theorem exists_symmetricBoundarySheaf (b : W) : - Nonempty (BoundarySheaf (symmetricGrading_negative basis) - (graph cs 1 b) (symmetricLabel cs 1 b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩) := by - classical - let := symmetricCoefficientNoetherian basis - let := interval_finite cs 1 b - let := Fintype.ofFinite (Interval cs 1 b) - let := Fintype.ofFinite (Edge cs 1 b) - exact MomentGraph.exists_boundarySheaf (symmetricGrading_negative basis) - (graph cs 1 b) (symmetric_scalar_mod_positive basis) - ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ (fun x => x.property.2) - (symmetricLabel cs 1 b) (symmetricLabel_homogeneous cs basis 1 b) - - def symmetricBoundarySheaf (b : W) : - BoundarySheaf (symmetricGrading_negative basis) - (graph cs 1 b) (symmetricLabel cs 1 b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ := - (exists_symmetricBoundarySheaf cs basis b).some - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Unconditional integral graded support-orthogonal duality for the actual -normalized minimal-boundary sheaf over the symmetric coefficient algebra. -/ -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph -universe u us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem symmetricBoundarySheaf_perfectPairing_word (l : List I) (hl : cs.IsReduced l) - (B : BoundarySheaf (symmetricGrading_negative basis) - (graph cs 1 (cs.wordProd l)) (symmetricLabel cs 1 (cs.wordProd l)) - ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) : - Nonempty (GradedSheaf.PerfectPairing B.sheaf (cs.length (cs.wordProd l) : ℤ)) := by - obtain ⟨s⟩ := bottBoundarySheaf_splitIn cs basis l hl B - obtain ⟨j⟩ := bottBoundarySheaf_iso_adjoint cs basis l hl B s - have hd : cs.length (cs.wordProd l)=l.length := hl - rw [hd] - exact ⟨bottRecognizedPerfectPairing cs basis l hl B.sheaf s j⟩ - - theorem symmetricBoundarySheaf_perfectPairing (b : W) : - Nonempty (GradedSheaf.PerfectPairing (symmetricBoundarySheaf cs basis b).sheaf (cs.length b : ℤ)) := by - obtain ⟨l,hl,he⟩ := cs.exists_isReduced b - subst b - exact symmetricBoundarySheaf_perfectPairing_word cs basis l hl _ - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] - [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) - (hA : ∀ n<0,𝓐 n=⊥) (hB : ∀ n<0,𝓑 n=⊥) -noncomputable section - - def changeUnitHom : Hom (change e he (unit.{uk,ua,um} hA)) (unit hB) where - map := - { toFun m j := e (m.val j) - map_add' m n := funext fun j => map_add e (m.val j) (n.val j) - map_smul' b m := by - funext j - change e (e.symm b * m.val j)=b * e (m.val j) - rw [map_mul,e.apply_symm_apply] } - graded := by - intro n m hm j - exact (he (n-0) _).mp ((mem_changePiece e (unit hA) n m).mp hm j) - - def changeUnitInvHom : Hom (unit.{uk,ua,um} hB) (change e he (unit hA)) where - map := - { toFun m := CoefficientChange.mk (fun j => e.symm (m j)) - map_add' m n := CoefficientChange.ext (funext fun j => map_add e.symm (m j) (n j)) - map_smul' b m := by - apply CoefficientChange.ext - funext j - exact map_mul e.symm b (m j) } - graded := by - intro n m hm - apply (mem_changePiece e (unit hA) n _).mpr - intro j - apply (he (n-0) _).mpr - change e (e.symm (m j)) ∈ 𝓑 (n-0) - rw [e.apply_symm_apply] - exact hm j - - theorem changeUnitHom_inv (m : unit.{uk,ua,um} hB) : - (changeUnitHom e he hA hB).map ((changeUnitInvHom e he hA hB).map m)=m := - funext fun j => e.apply_symm_apply (m j) - - theorem changeUnitInvHom_hom (m : change e he (unit.{uk,ua,um} hA)) : - (changeUnitInvHom e he hA hB).map ((changeUnitHom e he hA hB).map m)=m := - CoefficientChange.ext (funext fun j => e.symm_apply_apply (m.val j)) - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) -noncomputable section - - def unchangeHom {M N : ModuleData.{uk,ua,um} 𝓐} (f : Hom (change e he M) (change e he N)) : - Hom M N where - map := - { toFun m := (f.map (CoefficientChange.mk m)).val - map_add' m n := congrArg CoefficientChange.val (map_add f.map (CoefficientChange.mk m) (CoefficientChange.mk n)) - map_smul' a m := by - have hh := congrArg CoefficientChange.val (map_smul f.map (e a) (CoefficientChange.mk m)) - change (f.map (CoefficientChange.mk (e.symm (e a) • m))).val= - e.symm (e a) • (f.map (CoefficientChange.mk m)).val at hh - simpa only [e.symm_apply_apply, RingHom.id_apply] using hh } - graded n m hm := (mem_changePiece e N n _).mp - (f.graded n (CoefficientChange.mk m) ((mem_changePiece e M n _).mpr hm)) - -end -end KLInvariance.Graded.ModuleData - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - - def Hom.coefficientUnchange {S T : GradedSheaf (𝓐 := 𝓐) G} - (g : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he T)) : Hom S T where - vertex x := ModuleData.unchangeHom e he (g.vertex x) - edge f := ModuleData.unchangeHom e he (g.edge f) - lower f m := congrArg CoefficientChange.val (g.lower f (CoefficientChange.mk m)) - upper f m := congrArg CoefficientChange.val (g.upper f (CoefficientChange.mk m)) - - theorem coefficientChange_primitive (S : GradedSheaf (𝓐 := 𝓐) G) - (hS : (Hom.id S).PrimitiveProjector) : - (Hom.id (GradedSheaf.coefficientChange e he S)).PrimitiveProjector := by - constructor - · apply Hom.eq_of_maps <;> intros <;> rfl - · intro f hf _ _ - let g : Hom S S := f.coefficientUnchange e he - have hg : g.comp g=g := by - apply Hom.eq_of_maps - · intro x m - exact congrArg (fun q : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he S) => - ((q.vertex x).map (CoefficientChange.mk m)).val) hf - · intro x m - exact congrArg (fun q : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he S) => - ((q.edge x).map (CoefficientChange.mk m)).val) hf - have hgL : g.comp (Hom.id S)=g := by apply Hom.eq_of_maps <;> intros <;> rfl - have hgR : (Hom.id S).comp g=g := by apply Hom.eq_of_maps <;> intros <;> rfl - rcases hS.2 g hg hgL hgR with hz | hi - · left - apply Hom.eq_of_maps - · intro x m - apply CoefficientChange.ext - exact congrArg (fun q : Hom S S => (q.vertex x).map m.val) hz - · intro x m - apply CoefficientChange.ext - exact congrArg (fun q : Hom S S => (q.edge x).map m.val) hz - · right - apply Hom.eq_of_maps - · intro x m - apply CoefficientChange.ext - exact congrArg (fun q : Hom S S => (q.vertex x).map m.val) hi - · intro x m - apply CoefficientChange.ext - exact congrArg (fun q : Hom S S => (q.edge x).map m.val) hi - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.Graded.ModuleData -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] - [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) - {hA : ∀ n<0,𝓐 n=⊥} {hB : ∀ n<0,𝓑 n=⊥} - {M : ModuleData.{uk,ua,um} 𝓐} (hM : M=unit hA) - {N : ModuleData.{uk,ua,um} 𝓑} (hN : N=unit hB) -noncomputable section - - def changeTopInclusion : Hom N (change e he M) := - (changeHom e he (homOfEq hM.symm)).comp - ((changeUnitInvHom e he hA hB).comp (homOfEq hN)) - - def changeTopProjection : Hom (change e he M) N := - (homOfEq hN.symm).comp - ((changeUnitHom e he hA hB).comp (changeHom e he (homOfEq hM))) - - theorem changeTop_split (n : N) : - (changeTopProjection e he hM hN).map ((changeTopInclusion e he hM hN).map n)=n := by - subst M - subst N - change (changeUnitHom e he hA hB).map ((changeUnitInvHom e he hA hB).map n)=n - exact changeUnitHom_inv e he hA hB n - -end -end KLInvariance.Graded.ModuleData - -namespace KLInvariance.MomentGraph.BoundarySheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] - [Algebra k A] [Algebra k B] - {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} - [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] - [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] - [IsDomain A] [IsDomain B] [IsNoetherianRing B] - (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) - {hA : ∀ n<0,𝓐 n=⊥} {hB : ∀ n<0,𝓑 n=⊥} - {V E : Type um} [PartialOrder V] [Fintype V] [Fintype E] - {G : OrderedGraph V E} {α : E → A} {b : V} - (S : BoundarySheaf hA G α b) (T : BoundarySheaf hB G (fun q => e (α q)) b) -noncomputable section - - theorem iso_coefficientChange - (hzero : ∀ a ∈ 𝓑 0, ∃ c : k, algebraMap k B c=a) - (hb : ∀ x, x≤b) : Nonempty - (GradedSheaf.Iso T.sheaf (GradedSheaf.coefficientChange e he S.sheaf)) := by - exact T.iso_of_primitive_top_split hzero hb (GradedSheaf.coefficientChange e he S.sheaf) - (GradedSheaf.coefficientChange_upperQuotient e he S.sheaf α S.quotient) - (GradedSheaf.coefficientChange_free e he S.sheaf S.free) - (GradedSheaf.coefficientChange_flabby e he S.sheaf S.flabby.flabby) - (GradedSheaf.coefficientChange_generated e he S.sheaf S.generated) - (GradedSheaf.coefficientChange_primitive e he S.sheaf S.primitive_identity) - (ModuleData.changeTopInclusion e he S.top T.top) - (ModuleData.changeTopProjection e he S.top T.top) - (ModuleData.changeTop_split e he S.top T.top) - -end -end KLInvariance.MomentGraph.BoundarySheaf - -end - - -section - - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem boundarySheaf_perfectPairing : - Nonempty (GradedSheaf.PerfectPairing - (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf (cs.length b : ℤ)) := by - classical - let := interval_finite cs 1 b - let := Fintype.ofFinite (Interval cs 1 b) - let := Fintype.ofFinite (Edge cs 1 b) - let S := symmetricBoundarySheaf cs basis b - let T := boundarySheaf cs 1 b basis (one_bruhat cs b) - let e := SymmetricAlgebra.equivMvPolynomial basis - have he : ∀ n a, a∈symmetricGrading basis n ↔ e a∈polynomialGrading ℝ σ n := - mem_symmetricGrading basis - obtain ⟨p⟩ := symmetricBoundarySheaf_perfectPairing cs basis b - obtain ⟨j⟩ := BoundarySheaf.iso_coefficientChange e he S T - (polynomialGrading_zero ℝ σ) (fun x => x.property.2) - exact ⟨(p.coefficientChange e he).pullback j⟩ - - variable [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] - - theorem sectionDualityObligation : SectionDualityObligation cs b basis := by - obtain ⟨p⟩ := boundarySheaf_perfectPairing cs b basis - exact sectionDualityObligation_of_perfectPairing cs b basis p - -end -end KLInvariance.BruhatGraph - -end - - -section - - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - -local instance finiteInterval : Fintype (Interval cs 1 b) := by - let := interval_finite cs 1 b - exact Fintype.ofFinite _ -local instance finiteEdges : Fintype (Edge cs 1 b) := Fintype.ofFinite _ -local instance (a : Type*) : DecidableEq a := Classical.decEq a - - def boundaryFreeSheaf : FreeSheaf cs 1 b basis where - sheaf := (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf - free := (boundarySheaf cs 1 b basis (one_bruhat cs b)).free - quotient := (boundarySheaf cs 1 b basis (one_bruhat cs b)).quotient - generated := (boundarySheaf cs 1 b basis (one_bruhat cs b)).generated - - def boundaryPerfectPairing : GradedSheaf.PerfectPairing - (boundaryFreeSheaf cs b basis).sheaf (cs.length b : ℤ) := - (boundarySheaf_perfectPairing cs b basis).some - - def boundaryFreeDuality : FreeSheaf.SectionDuality cs 1 b basis (boundaryFreeSheaf cs b basis) := - FreeSheaf.dualityOfPairing cs 1 b basis _ (boundaryPerfectPairing cs b basis) - - theorem boundaryKernelFree (x : Interval cs 1 b) : - Module.Free (Coefficient (σ := σ)) - (GradedSheaf.kernelData (boundaryFreeSheaf cs b basis).sheaf x) := - FreeSheaf.kernel_free cs b basis _ (boundaryFreeDuality cs b basis) x - - def costalkCharacter (x : Interval cs 1 b) : Polynomial ℤ := - GradedSheaf.freeKernelChar (boundaryFreeSheaf cs b basis).sheaf (boundaryKernelFree cs b basis) x - - theorem costalkCharacter_reflect (x : Interval cs 1 b) : - costalkCharacter cs b basis x=Polynomial.reflect (rankDifference cs x.val b) - (stalkCharacter cs 1 b basis (one_bruhat cs b) x) := by - apply FreeSheaf.kernel_character cs b basis _ (boundaryFreeDuality cs b basis) (cs.length b) _ le_rfl x - intro i j m a hm ha - exact (boundaryPerfectPairing cs b basis).homogeneous i j m a - (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) - - theorem stalkBasis_degree_le (x : Interval cs 1 b) - (c : NonnegativeBasis (σ := σ) - ((boundaryFreeSheaf cs b basis).sheaf.vertex x).piece) (i : c.index) : - c.degree i≤rankDifference cs x.val b := by - apply ModuleData.degree_le_of_dual_equiv _ _ - (FreeSheaf.kernelDual cs b basis _ (boundaryFreeDuality cs b basis) x) - (rankDifference cs x.val b) _ c i - exact FreeSheaf.kernelDual_homogeneous cs b basis _ (boundaryFreeDuality cs b basis) - (cs.length b) (fun i j m a hm ha => (boundaryPerfectPairing cs b basis).homogeneous i j m a - (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x))) - x (length_le_of_bruhat cs x.property.2) - -end -end KLInvariance.BruhatGraph - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded -universe uk ua um -variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] - [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} - {V E W F : Type um} [PartialOrder V] [PartialOrder W] - {G : OrderedGraph V E} {H : OrderedGraph W F} -noncomputable section -attribute [local instance] Classical.propDecidable -variable {K : Set V} {hK : IsLowerSet K} - -omit [IsNoetherianRing A] in - theorem lowerExtend_kernel_iff (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) - (x : K) (m : B.lowerExtend.vertex x.val) : - m∈B.lowerExtend.upwardSubmodule x.val Set.univ ↔ - B.lowerExtendVertex x m∈B.upwardSubmodule x Set.univ := by - constructor - · intro hm e _ - rcases e with ⟨⟨e,he⟩,hx⟩ - cases hx - have hh := hm ⟨e,rfl⟩ (Set.mem_univ _) - exact congrFun hh ⟨⟨he⟩⟩ - · intro hm e _ - rcases x with ⟨x,hx⟩ - rcases e with ⟨e,he⟩ - change G.source e=x at he - subst x - apply funext - intro h - have hh := hm ⟨⟨e,h.down.down⟩,rfl⟩ (Set.mem_univ _) - exact hh - - def lowerExtendKernelEquiv (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) - (x : K) : kernelData B.lowerExtend x.val ≃ₗ[A] kernelData B x where - toFun m := ⟨B.lowerExtendVertex x m.val,(lowerExtend_kernel_iff B x m.val).mp m.property⟩ - invFun m := ⟨(B.lowerExtendVertex x).symm m.val,(lowerExtend_kernel_iff B x _).mpr (by - simpa only [LinearEquiv.apply_symm_apply] using m.property)⟩ - left_inv m := Subtype.ext ((B.lowerExtendVertex x).symm_apply_apply m.val) - right_inv m := Subtype.ext ((B.lowerExtendVertex x).apply_symm_apply m.val) - map_add' m n := Subtype.ext (map_add (B.lowerExtendVertex x) m.val n.val) - map_smul' a m := Subtype.ext (map_smul (B.lowerExtendVertex x) a m.val) - - theorem lowerExtendKernelEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) - (x : K) (n : ℤ) (m : kernelData B.lowerExtend x.val) - (hm : m∈(kernelData B.lowerExtend x.val).piece n) : - B.lowerExtendKernelEquiv x m∈(kernelData B x).piece n := - B.lowerExtendVertex_graded x n m.val hm - -omit [IsNoetherianRing A] in - theorem fullKernel_pullback (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) - (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) : - (B.pullback f).upwardSubmodule x Set.univ=B.upwardSubmodule (f.vertex x) Set.univ := by - exact B.forget.pullback_kernel f x Set.univ Set.univ - (fun e he => (he (Set.mem_univ e)).elim) (fun e _ he => hlift e x he) - - def pullbackKernelEquiv (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) - (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) : - kernelData (B.pullback f) x ≃ₗ[A] kernelData B (f.vertex x) where - toFun m := ⟨m.val,fullKernel_pullback B f hlift x ▸ m.property⟩ - invFun m := ⟨m.val,(fullKernel_pullback B f hlift x).symm ▸ m.property⟩ - left_inv _ := rfl - right_inv _ := rfl - map_add' _ _ := rfl - map_smul' _ _ := rfl - - theorem pullbackKernelEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) - (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) - (n : ℤ) (m : kernelData (B.pullback f) x) (hm : m∈(kernelData (B.pullback f) x).piece n) : - B.pullbackKernelEquiv f hlift x m∈(kernelData B (f.vertex x)).piece n := hm - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - - def lowerKernelEquiv (c x : Interval cs 1 b) (hx : x≤c) : - GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x ≃ₗ[Coefficient (σ := σ)] - GradedSheaf.kernelData (boundaryFreeSheaf cs c.val basis).sheaf ⟨x.val,x.property.1,hx⟩ := - ((lowerIntervalBoundary cs b basis c).sheaf.lowerExtendKernelEquiv ⟨x,hx⟩).trans - ((boundaryFreeSheaf cs c.val basis).sheaf.pullbackKernelEquiv - (lowerIntervalMap cs b c) (lowerIntervalMap_outgoing cs b c) ⟨x,hx⟩) - - theorem lowerKernelEquiv_graded (c x : Interval cs 1 b) (hx : x≤c) - (n : ℤ) (v : GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) - (hv : v∈(GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x).piece n) : - lowerKernelEquiv cs b basis c x hx v∈(GradedSheaf.kernelData - (boundaryFreeSheaf cs c.val basis).sheaf ⟨x.val,x.property.1,hx⟩).piece n := - (lowerIntervalBoundary cs b basis c).sheaf.lowerExtendKernelEquiv_graded ⟨x,hx⟩ n v hv - - theorem boundaryModels_kernelFree (c x : Interval cs 1 b) : - Module.Free (Coefficient (σ := σ)) - (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := by - by_cases hx : x≤c - · let := boundaryKernelFree cs c.val basis ⟨x.val,x.property.1,hx⟩ - exact Module.Free.of_equiv (lowerKernelEquiv cs b basis c x hx).symm - · let := (boundaryModels cs b basis).support c x hx - let : Subsingleton (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := - ⟨fun v w => Subtype.ext (Subsingleton.elim _ _)⟩ - infer_instance - - theorem boundaryModels_kernelCharacter (c x : Interval cs 1 b) : - GradedSheaf.freeKernelChar ((boundaryModels cs b basis).sheaf c) - (boundaryModels_kernelFree cs b basis c) x= - Polynomial.reflect (rankDifference cs x.val c.val) (lowerCharacter cs b basis c x) := by - let := boundaryModels_kernelFree cs b basis c x - by_cases hx : x≤c - · rw [lowerCharacter,dite_eq_left hx,← costalkCharacter_reflect cs c.val basis ⟨x.val,x.property.1,hx⟩] - let := boundaryKernelFree cs c.val basis ⟨x.val,x.property.1,hx⟩ - exact ModuleData.character_eq_of_gradedEquiv (lowerKernelEquiv cs b basis c x hx) - (lowerKernelEquiv_graded cs b basis c x hx) - · rw [lowerCharacter,dite_eq_right hx,Polynomial.reflect_zero] - let := (boundaryModels cs b basis).support c x hx - let : Subsingleton (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := - ⟨fun v w => Subtype.ext (Subsingleton.elim _ _)⟩ - exact ModuleData.char_zero _ - -end -end KLInvariance.BruhatGraph - -end - - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded Polynomial -universe uk us um -variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - - theorem exists_character_decomposition [Fintype V] [Fintype E] - {α : E → MvPolynomial σ k} - (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) - (hk : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O.sheaf y) x)) - (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) - (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) - (hkb : ∀ x, Module.Free (MvPolynomial σ k) (kernelData B x)) - (hq : B.UpperQuotient α) (hfl : B.forget.Flabby) (hg : B.forget.Generated) : - ∃ m : V → Polynomial ℤ, (∀ y n, 0≤(m y).coeff n) ∧ - (∀ x, freeStalkChar B hf x = - ∑ y, m y*freeStalkChar (O.sheaf y) (O.free y) x) ∧ - (∀ x, freeKernelChar B hkb x = - ∑ y, m y*freeKernelChar (O.sheaf y) (hk y) x) := by - obtain ⟨C,hC,⟨j⟩⟩ := exists_modelSumIso (polynomialGrading_zero k σ) O B hf hq hfl hg - obtain ⟨m,hm,heq,hkeq⟩ := hC.character_both O hk - refine ⟨m,hm,fun x => ?_,fun x => ?_⟩ - · rw [← heq x] - let _ := hf x - let _ := hC.free O x - exact ModuleData.character_eq_of_gradedEquiv (j.vertex x) (j.vertex_graded x) - · rw [← hkeq x] - let _ := hkb x - let _ := hC.kernelFree hk x - exact ModuleData.character_eq_of_gradedEquiv (j.kernelEquiv x) (j.kernelEquiv_graded x) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.TitsSpace -open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem bottCharacter_decomposition_both (l : List I) (hl : cs.IsReduced l) - [Fintype (Interval cs 1 (cs.wordProd l))] : - ∃ m : Interval cs 1 (cs.wordProd l) → Polynomial ℤ, - (∀ y n, 0≤(m y).coeff n) ∧ - (∀ x, bottStalkCharacter cs basis l x.val= - ∑ y, m y*lowerCharacter cs (cs.wordProd l) basis y x) ∧ - (∀ x, GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) - (bottKernelFree cs basis l hl) x= - ∑ y, m y*Polynomial.reflect (rankDifference cs x.val y.val) - (lowerCharacter cs (cs.wordProd l) basis y x)) := by - classical - let := Fintype.ofFinite (Edge cs 1 (cs.wordProd l)) - obtain ⟨m,hm,he,hk⟩ := GradedSheaf.exists_character_decomposition - (boundaryModels cs (cs.wordProd l) basis) (boundaryModels_kernelFree cs (cs.wordProd l) basis) - (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) - (bottPolynomialSheaf_free cs basis l 1 (cs.wordProd l)) (bottKernelFree cs basis l hl) - (bottPolynomialSheaf_quotient cs basis l 1 (cs.wordProd l)) - (bottPolynomialSheaf_flabby cs basis l hl) (bottPolynomialSheaf_generated cs basis l 1 (cs.wordProd l)) - refine ⟨m,hm,fun x => ?_,fun x => ?_⟩ - · simpa only [bottPolynomialSheaf_character,boundaryModels_character] using he x - · simpa only [boundaryModels_kernelCharacter] using hk x - -end -end KLInvariance.TitsSpace - -end - - -section - -namespace KLInvariance.Graded.ModuleData -open Polynomial Module -universe uk us um -variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] -noncomputable section - - def unitPolynomialBasis : NonnegativeBasis (σ := σ) - (unit.{uk,max uk us,um} (polynomialGrading_negative k σ)).piece where - index := PUnit.{max uk us um + 1} - finite := inferInstance - basis := Pi.basisFun (MvPolynomial σ k) _ - degree _ := 0 - homogeneous i := by - intro j - change (Pi.basisFun (MvPolynomial σ k) _ i) j ∈ polynomialGrading k σ (0-0) - cases i - cases j - simpa using SetLike.one_mem_graded (polynomialGrading k σ) - - theorem char_unit : - (unit.{uk,max uk us,um} (polynomialGrading_negative k σ)).char=1 := by - rw [char,character_eq _ _ (unitPolynomialBasis (k := k) (σ := σ))] - change (∑ i : PUnit.{max uk us um + 1}, (X : Polynomial ℤ)^0)=1 - simp - -end -end KLInvariance.Graded.ModuleData - -end - - -section - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - - theorem stalkCharacter_top : - stalkCharacter cs 1 b basis (one_bruhat cs b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩=1 := by - let B := boundarySheaf cs 1 b basis (one_bruhat cs b) - let := B.free ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ - change (B.sheaf.vertex ⟨b,one_bruhat cs b,bruhat_refl cs b⟩).char=1 - exact (ModuleData.character_eq_of_gradedEquiv (ModuleData.equivOfEq B.top) - (ModuleData.equivOfEq_graded B.top)).trans ModuleData.char_unit - - theorem lowerCharacter_diagonal (c : Interval cs 1 b) : lowerCharacter cs b basis c c=1 := by - rw [lowerCharacter,dite_eq_left le_rfl] - exact stalkCharacter_top cs c.val basis - - theorem lowerCharacter_at_top (c : Interval cs 1 b) : - lowerCharacter cs b basis c ⟨b,one_bruhat cs b,bruhat_refl cs b⟩= - if c.val=b then 1 else 0 := by - by_cases hc : c.val=b - · have he : c=⟨b,one_bruhat cs b,bruhat_refl cs b⟩ := Subtype.ext hc - rw [ite_eq_left hc,←he,lowerCharacter_diagonal] - · rw [ite_eq_right hc] - apply lowerCharacter_zero - intro h - exact hc (bruhat_antisymm cs c.property.2 h) - -end -end KLInvariance.BruhatGraph - -end - - -section - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p -local instance lowerConvInterval (c : W) : Fintype (Interval cs 1 c) := by - let := interval_finite cs 1 c - exact Fintype.ofFinite _ - - def lowerIntervalEquiv (c : Interval cs 1 b) : Set.Iic c ≃ Interval cs 1 c.val where - toFun := (lowerIntervalMap cs b c).vertex - invFun z := ⟨⟨z.val,z.property.1,bruhat_trans cs z.property.2 c.property.2⟩,z.property.2⟩ - left_inv _ := rfl - right_inv _ := rfl - - theorem lowerCharacter_convolution (c x : Interval cs 1 b) : - (∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z)= - ∑ z : Interval cs 1 c.val, OrdinaryR.polynomial cs x.val z.val* - stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z := by - classical - let f (z : Interval cs 1 b) := OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z - have hf : ∀ z : Interval cs 1 b, ¬z≤c → f z=0 := by - intro z hz - simp only [f,lowerCharacter_zero cs b basis c z hz,mul_zero] - have he : (∑ z : Interval cs 1 b, f z) = ∑ z ∈ Finset.univ.filter (fun z => z≤c), f z := by - symm - apply Finset.sum_subset (Finset.filter_subset _ _) - intro z _ hz - exact hf z (by simpa using hz) - change (∑ z, f z)=_ - rw [he,Finset.sum_subtype (p := fun z : Interval cs 1 b => z≤c) _ (by simp)] - calc - _ = ∑ z : Set.Iic c, OrdinaryR.polynomial cs x.val z.val.val* - stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) ((lowerIntervalEquiv cs b c) z) := by - apply Finset.sum_congr rfl - intro z _ - simp only [f,lowerCharacter,dite_eq_left z.property] - rfl - _ = _ := Equiv.sum_comp (lowerIntervalEquiv cs b c) (fun z => OrdinaryR.polynomial cs x.val z.val* - stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z) - - theorem lowerCharacter_convolution_zero (c x : Interval cs 1 b) (hx : ¬x≤c) : - (∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z)=0 := by - apply Finset.sum_eq_zero - intro z _ - by_cases hz : z≤c - · rw [OrdinaryR.polynomial_zero cs x.val z.val (fun h => hx (bruhat_trans cs h hz)),zero_mul] - · rw [lowerCharacter_zero cs b basis c z hz,mul_zero] - - theorem lowerCharacter_reciprocity_lift (c : Interval cs 1 b) - (h : ∀ x : Interval cs 1 c.val, - reflect (rankDifference cs x.val c.val) (stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) x)= - ∑ z : Interval cs 1 c.val, OrdinaryR.polynomial cs x.val z.val* - stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z) - (x : Interval cs 1 b) : - reflect (rankDifference cs x.val c.val) (lowerCharacter cs b basis c x)= - ∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z := by - by_cases hx : x≤c - · rw [lowerCharacter_convolution,lowerCharacter,dite_eq_left hx] - exact h ⟨x.val,x.property.1,hx⟩ - · rw [lowerCharacter_zero cs b basis c x hx,reflect_zero,lowerCharacter_convolution_zero cs b basis c x hx] - -end -end KLInvariance.BruhatGraph - -end - - -section - -/-! Finite unipotent character cancellation. The transition data is actually -constructed for word/BMP sheaves; this lemma assumes only the displayed -linear identities and cannot supply the KL degree bound. -/ - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.Support + +namespace OAI + +/-! +Conditional boundary-sheaf duality and stalk-character propositions, free sheaves, actual R-reciprocity and lower convolution. StalkCharacterObligation remains a Prop, not an unconditional character theorem or a premise of the R-first route. +-/ + +section + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +variable [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] +noncomputable section + +def SectionDualityObligation : Prop := + ∃ d : SectionDuality cs 1 b basis (one_bruhat cs b) + (boundarySheaf cs 1 b basis (one_bruhat cs b)), + ∀ i j (m n : (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ), + m ∈ ((boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ).piece i → + n ∈ ((boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf.sections Set.univ).piece j → + d.pairing m n ∈ polynomialGrading ℝ σ (i+j-(cs.length b : ℤ)) + +end +end KLInvariance.BruhatGraph + +end + + +section + +/-! Balance of a two-sided perfect pairing needs orthogonality on both +sides, not equality of its two integral embeddings into an ambient form. -/ +namespace BalancedCuts +universe ur um ua +variable {R : Type ur} [CommRing R] [IsDomain R] + {M : Type um} [AddCommGroup M] [Module R M] + {A : Type ua} [AddCommGroup A] [Module R A] + (d : M →ₗ[R] Module.Dual R M) (π : M →ₗ[R] A) (c : M →ₗ[R] M) + (p : R) (hp : p≠0) (hπ : ∀ m, π (c m)=p • π m) + (hleft : ∀ m n, π n=0 → d (c m) n=0) + (hright : ∀ m n, π m=0 → d m (c n)=0) + +include hp hπ hleft hright in + theorem balanced_two (m n : M) : d (c m) n=d m (c n) := by + have hn : π (p • n-c n)=0 := by rw [map_sub,map_smul,hπ,sub_self] + have hm : π (p • m-c m)=0 := by rw [map_sub,map_smul,hπ,sub_self] + have en := hleft m _ hn + have em := hright _ n hm + simp only [map_sub,map_smul,LinearMap.sub_apply,LinearMap.smul_apply,smul_eq_mul,sub_eq_zero] at en em + exact mul_left_cancel₀ hp (en.trans em.symm) + +end BalancedCuts + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded Module +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} {V E : Type um} [PartialOrder V] + {G : OrderedGraph V E} [IsDomain A] [DecidableEq V] + {S : GradedSheaf (𝓐 := 𝓐) G} {d : ℤ} (p : PerfectPairing S d) + (a : A) (ha : a≠0) + (hcut : ∀ x (m : S.forget.sections Set.univ), a • Pi.single x (m.val x)∈S.forget.sections Set.univ) +noncomputable section + + include ha in + theorem PerfectPairing.cut_balanced (x : V) (m n : S.forget.sections Set.univ) : + p.pairing (IntegralSupport.cut _ a hcut x m) n = + p.pairing m (IntegralSupport.cut _ a hcut x n) := by + apply BalancedCuts.balanced_two p.pairing.toLinearMap + (IntegralSupport.projection (S.forget.sections Set.univ) x) + (IntegralSupport.cut _ a hcut x) a ha + (IntegralSupport.cut_self _ a hcut x) + · intro v w hw + exact p.left_orthogonal x _ w (fun y hy => IntegralSupport.cut_other _ a hcut x y hy v) hw + · intro v w hv + exact p.right_orthogonal x v _ hv (fun y hy => IntegralSupport.cut_other _ a hcut x y hy w) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] +noncomputable section + + theorem sectionDualityObligation_of_perfectPairing + (p : GradedSheaf.PerfectPairing + (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf (cs.length b : ℤ)) : + SectionDualityObligation cs b basis := by + let B := boundarySheaf cs 1 b basis (one_bruhat cs b) + refine ⟨⟨p.pairing,?_⟩,?_⟩ + · intro x m n + exact p.cut_balanced (Sheaf.labelProduct (polynomialLabel cs 1 b basis)) + (Sheaf.labelProduct_ne_zero _ (polynomialLabel_ne_zero cs 1 b basis)) + (B.sheaf.forget.scaled_single_section + (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs 1 b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x m n + · intro i j m n hm hn + exact p.homogeneous i j m n (fun x => hm x (Set.mem_univ x)) + (fun x => hn x (Set.mem_univ x)) + +end +end KLInvariance.BruhatGraph + +end + + +section + +/-! Integral costalk duality only uses free stalks, the genuine edge quotients, +generation and a perfect support-orthogonal section form. No top/minimality or +KL character assumption is needed. This extension applies to genuine words. -/ +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) (u b : W) + {σ : Type us} (basis : Basis σ ℝ (Extended M)) + +structure FreeSheaf where + sheaf : GradedSheaf (𝓐 := polynomialGrading ℝ σ) (graph cs u b) + free : sheaf.FreeStalks + quotient : sheaf.UpperQuotient (polynomialLabel cs u b basis) + generated : sheaf.forget.Generated + +namespace FreeSheaf +variable (B : FreeSheaf cs u b basis) + [Fintype (Edge cs u b)] [DecidableEq (Interval cs u b)] +noncomputable section + def kernelEquivSingleSupport (x : Interval cs u b) : + LinearMap.ker (B.sheaf.forget.stalkMap x) ≃ₗ[Coefficient (σ := σ)] + IntegralSupport.supported (B.sheaf.forget.sections Set.univ) x := by + let _ (x : Interval cs u b) : Module.Free (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := B.free x + let _ (x : Interval cs u b) : Module.Finite (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := + (B.sheaf.vertex x).finite + let _ (x : Interval cs u b) : Fintype (Module.Free.ChooseBasisIndex + (Coefficient (σ := σ)) (B.sheaf.forget.vertex x)) := Fintype.ofFinite _ + let bs := fun x : Interval cs u b => + Module.Free.chooseBasis (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) + exact (B.sheaf.forget.kernelEquivSingleStalk (polynomialLabel cs u b basis) + (polynomialLabel_prime cs u b basis) (fun e => (B.quotient e).2) bs x + (incoming_pairwise_relPrime cs u b basis x) + (B.sheaf.forget.outgoing_product_regular (polynomialLabel cs u b basis) + (polynomialLabel_prime cs u b basis) (fun e => (B.quotient e).1) + (fun e => (B.quotient e).2) bs x + (outgoing_incoming_not_dvd cs u b basis x))).trans + (B.sheaf.forget.singleStalkEquivSupport x) + + +structure SectionDuality where + pairing : B.sheaf.forget.sections Set.univ ≃ₗ[Coefficient (σ := σ)] + Dual (Coefficient (σ := σ)) (B.sheaf.forget.sections Set.univ) + balanced : ∀ x m n, + pairing (IntegralSupport.cut (B.sheaf.forget.sections Set.univ) + (Sheaf.labelProduct (polynomialLabel cs u b basis)) + (B.sheaf.forget.scaled_single_section + (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x m) n = + pairing m (IntegralSupport.cut (B.sheaf.forget.sections Set.univ) + (Sheaf.labelProduct (polynomialLabel cs u b basis)) + (B.sheaf.forget.scaled_single_section + (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) x n) + + def costalkEquivDual (d : SectionDuality cs u b basis B) (x : Interval cs u b) : + LinearMap.ker (B.sheaf.forget.stalkMap x) ≃ₗ[Coefficient (σ := σ)] + Dual (Coefficient (σ := σ)) (B.sheaf.vertex x) := by + let _ (x : Interval cs u b) : Module.Free (Coefficient (σ := σ)) (B.sheaf.forget.vertex x) := B.free x + let _ (y : Interval cs u b) : Module.IsTorsionFree (Coefficient (σ := σ)) + (B.sheaf.forget.vertex y) := inferInstance + exact (kernelEquivSingleSupport cs u b basis B x).trans + (B.sheaf.forget.singleSupportEquivDual (polynomialLabel cs u b basis) + (polynomialLabel_ne_zero cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) + d.pairing d.balanced B.generated x) + + theorem costalk_free_of_duality (d : SectionDuality cs u b basis B) + (x : Interval cs u b) : + Module.Free (Coefficient (σ := σ)) (LinearMap.ker (B.sheaf.forget.stalkMap x)) := by + let _ := B.free x + exact Module.Free.of_equiv (costalkEquivDual cs u b basis B d x).symm + + variable [Fintype σ] [Fintype (Interval cs u b)] + +omit [Fintype σ] [Fintype (Interval cs u b)] in + theorem kernelEquivSingleSupport_apply (x : Interval cs u b) + (v : LinearMap.ker (B.sheaf.forget.stalkMap x)) : + ((kernelEquivSingleSupport cs u b basis B x) v).val.val x = + Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • v.val := by + change (Pi.single x + (Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • v.val) : + B.sheaf.forget.Assignment) x = _ + exact Pi.single_eq_same _ _ + + theorem costalkEquivDual_inverse_homogeneous + (d : SectionDuality cs u b basis B) (l : ℤ) + (hd : ∀ i j (m n : B.sheaf.sections Set.univ), + m ∈ (B.sheaf.sections Set.univ).piece i → n ∈ (B.sheaf.sections Set.univ).piece j → + d.pairing m n ∈ polynomialGrading ℝ σ (i+j-l)) + (x : Interval cs u b) (r : ℤ) (lam : Dual (Coefficient (σ := σ)) (B.sheaf.vertex x)) + (hlam : ∀ j (v : B.sheaf.vertex x), v ∈ (B.sheaf.vertex x).piece j → + lam v ∈ polynomialGrading ℝ σ (j+r)) : + ((costalkEquivDual cs u b basis B d x).symm lam).val ∈ + (B.sheaf.vertex x).piece + (r+l-(Sheaf.incoming (G := graph cs u b) x).card) := by + let _ (y : Interval cs u b) : Module.Free (Coefficient (σ := σ)) + (B.sheaf.forget.vertex y) := B.free y + let _ (y : Interval cs u b) : Module.IsTorsionFree (Coefficient (σ := σ)) + (B.sheaf.forget.vertex y) := inferInstance + let S := B.sheaf.forget.singleSupportEquivDual (polynomialLabel cs u b basis) + (polynomialLabel_ne_zero cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) + d.pairing d.balanced B.generated x + have hs : (S.symm lam).val ∈ (B.sheaf.sections Set.univ).piece (r+l) := by + exact B.sheaf.dualToSupport_homogeneous (polynomialLabel cs u b basis) + (polynomialLabel_ne_zero cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient) + d.pairing d.balanced l hd x r lam hlam + have hv := hs x (Set.mem_univ x) + have he : (S.symm lam).val.val x = + Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x • + ((costalkEquivDual cs u b basis B d x).symm lam).val := by + rw [← kernelEquivSingleSupport_apply cs u b basis B x] + change (S.symm lam).val.val x = + ((kernelEquivSingleSupport cs u b basis B x) + ((kernelEquivSingleSupport cs u b basis B x).symm (S.symm lam))).val.val x + rw [LinearEquiv.apply_symm_apply] + change (S.symm lam).val.val x ∈ (B.sheaf.vertex x).piece (r+l) at hv + rw [he] at hv + apply mem_of_homogeneous_smul (polynomialGrading ℝ σ) (B.sheaf.vertex x).piece + ((Sheaf.incoming (G := graph cs u b) x).card : ℤ) + (Sheaf.incomingProduct (G := graph cs u b) (polynomialLabel cs u b basis) x) + (incomingProduct_homogeneous cs u b basis x) _ (r+l) _ hv + let _ := B.free x + exact smul_right_injective _ (Sheaf.incomingProduct_ne_zero + (polynomialLabel cs u b basis) (polynomialLabel_prime cs u b basis) x) + + def fullSubmodule (x : Interval cs u b) : Submodule (Coefficient (σ := σ)) (B.sheaf.vertex x) := + LinearMap.ker (B.sheaf.forget.stalkMap x) + +omit [Fintype σ] [Fintype (Edge cs u b)] [Fintype (Interval cs u b)] + [DecidableEq (Interval cs u b)] in + theorem fullKernel_eq (x : Interval cs u b) : + B.sheaf.upwardSubmodule x Set.univ = fullSubmodule cs u b basis B x := by + ext m + change (∀ e ∈ Set.univ, B.sheaf.forget.stalkMap x m e = 0) ↔ B.sheaf.forget.stalkMap x m = 0 + simp only [Set.mem_univ,forall_const] + exact funext_iff.symm + + def fullKernel (x : Interval cs u b) : ModuleData (polynomialGrading ℝ σ) := + ModuleData.sub (B.sheaf.vertex x) (fullSubmodule cs u b basis B x) (by + simpa only [fullKernel_eq cs u b basis B x] using + B.sheaf.upwardKernel_homogeneous x Set.univ) + + theorem costalk_hilbert_of_duality + (d : SectionDuality cs u b basis B) (l : ℤ) + (hd : ∀ i j (m n : B.sheaf.sections Set.univ), + m ∈ (B.sheaf.sections Set.univ).piece i → n ∈ (B.sheaf.sections Set.univ).piece j → + d.pairing m n ∈ polynomialGrading ℝ σ (i+j-l)) + (x : Interval cs u b) (c : NonnegativeBasis (σ := σ) (B.sheaf.vertex x).piece) + {q : ℝ} (hq : 0 < q) (hq1 : q < 1) : + Hilbert.value (B.sheaf.vertex x).piece + ((fullSubmodule cs u b basis B x).restrictScalars ℝ) q = + q^(l-(Sheaf.incoming (G := graph cs u b) x).card) * + Polynomial.eval₂ (Int.castRingHom ℝ) q⁻¹ c.polynomial * + (1-q)⁻¹ ^ Fintype.card σ := by + classical + let K := fullKernel cs u b basis B x + let cb : Basis c.index (Coefficient (σ := σ)) K := + c.basis.dualBasis.map (costalkEquivDual cs u b basis B d x).symm + have hcb (i : c.index) : cb i ∈ K.piece + (l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ)) := by + change ((costalkEquivDual cs u b basis B d x).symm (c.basis.dualBasis i)).val ∈ + (B.sheaf.vertex x).piece _ + have h := costalkEquivDual_inverse_homogeneous cs u b basis B d l hd x + (-(c.degree i : ℤ)) (c.basis.dualBasis i) + (dualBasis_homogeneous (polynomialGrading ℝ σ) (B.sheaf.vertex x).piece + c.basis (fun i => (c.degree i : ℤ)) c.homogeneous i) + simpa only [show -(c.degree i : ℤ)+l-(Sheaf.incoming (G := graph cs u b) x).card = + l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ) by omega] using h + have hs := Hilbert.hasSum_homogeneous_basis K.piece cb + (fun i => l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ)) hcb hq hq1 + have hv : Hilbert.value K.piece ⊤ q = + (∑ i, q^(l-(Sheaf.incoming (G := graph cs u b) x).card-(c.degree i : ℤ))) * + (1-q)⁻¹ ^ Fintype.card σ := by + simpa only [Hilbert.value,Hilbert.term_top] using hs.tsum_eq + change Hilbert.value (B.sheaf.vertex x).piece + ((fullSubmodule cs u b basis B x).restrictScalars ℝ) q = _ + rw [← Hilbert.value_subPiece] + change Hilbert.value K.piece ⊤ q = _ + rw [hv,c.eval₂_eq,Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro i _ + rw [zpow_sub₀ hq.ne',zpow_natCast,div_eq_mul_inv,inv_pow] + + + def dualityOfPairing {l : ℤ} (p : GradedSheaf.PerfectPairing B.sheaf l) : + SectionDuality cs u b basis B where + pairing := p.pairing + balanced := p.cut_balanced + (Sheaf.labelProduct (polynomialLabel cs u b basis)) + (Sheaf.labelProduct_ne_zero _ (polynomialLabel_ne_zero cs u b basis)) + (B.sheaf.forget.scaled_single_section + (B.sheaf.forget.labelProduct_annihilates (polynomialLabel cs u b basis) + (GradedSheaf.UpperQuotient.annihilates B.sheaf B.quotient))) + +end +end FreeSheaf +end KLInvariance.BruhatGraph + +end + + +section + +/-! The finite sums used by the actual local decomposition. The model criteria +are kept explicit here; they are not asserted for the constructed BMP object +or inserted into the main KL theorem. -/ +namespace KLInvariance.MomentGraph.Sheaf +universe u v w z +variable {R : Type u} [CommRing R] [IsLocalRing R] + {V : Type v} [PartialOrder V] {E : Type w} {G : OrderedGraph V E} + + +instance zeroVertex_subsingleton (x : V) : Subsingleton ((zero (R := R) (G := G)).vertex x) := + inferInstanceAs (Subsingleton PUnit) + +instance zeroEdge_subsingleton (e : E) : Subsingleton ((zero (R := R) (G := G)).edge e) := + inferInstanceAs (Subsingleton PUnit) + +structure LocalModels (α : E → R) where + sheaf : V → Sheaf.{u,v,w,z} (R := R) G + free : ∀ c x, Module.Free R ((sheaf c).vertex x) + finite : ∀ c x, Module.Finite R ((sheaf c).vertex x) + quotient : ∀ c, (sheaf c).UpperQuotient α + generated : ∀ c, (sheaf c).Generated + flabby : ∀ c, (sheaf c).Flabby + support : ∀ c x, ¬x ≤ c → Subsingleton ((sheaf c).vertex x) + top : ∀ c, (sheaf c).vertex c ≃ₗ[R] R + minimal : ∀ c x, x ≠ c → LinearMap.ker ((sheaf c).stalkMap x) ≤ + IsLocalRing.maximalIdeal R • (⊤ : Submodule R ((sheaf c).vertex x)) + +inductive ModelSum (O : V → Sheaf.{u,v,w,z} (R := R) G) (U : Set V) : + Sheaf.{u,v,w,z} (R := R) G → Prop where + | zero : ModelSum O U zero + | add {B} : ModelSum O U B → ∀ c ∈ U, ∀ n : ℕ, + ModelSum O U (prod B (pi (fun _ : Fin n => O c))) + +namespace ModelSum +variable {α : E → R} (O : LocalModels.{u,v,w,z} (G := G) α) + {U : Set V} {B : Sheaf.{u,v,w,z} (R := R) G} + +omit [IsLocalRing R] in +lemma mono {O : V → Sheaf.{u,v,w,z} (R := R) G} (h : ModelSum O U B) + {T : Set V} (hUT : U ⊆ T) : ModelSum O T B := by + induction h with + | zero => exact .zero + | add _ c hc n ih => exact .add ih c (hUT hc) n + +lemma free (h : ModelSum O.sheaf U B) (x : V) : Module.Free R (B.vertex x) := by + induction h with + | zero => exact inferInstanceAs (Module.Free R PUnit.{z+1}) + | @add C _ c _ n ih => + let _ : Module.Free R (C.vertex x) := ih + let _ := O.free c x + change Module.Free R (C.vertex x × (Fin n → (O.sheaf c).vertex x)) + infer_instance + +lemma finite (h : ModelSum O.sheaf U B) (x : V) : Module.Finite R (B.vertex x) := by + induction h with + | zero => exact inferInstanceAs (Module.Finite R PUnit.{z+1}) + | @add C _ c _ n ih => + let _ : Module.Finite R (C.vertex x) := ih + let _ := O.finite c x + change Module.Finite R (C.vertex x × (Fin n → (O.sheaf c).vertex x)) + infer_instance + +lemma quotient (h : ModelSum O.sheaf U B) : B.UpperQuotient α := by + induction h with + | zero => + intro e + exact ⟨fun v => ⟨0,Subsingleton.elim _ _⟩,fun v => ⟨fun _ => ⟨0,Subsingleton.elim _ _⟩,fun _ => Subsingleton.elim _ _⟩⟩ + | add _ c _ n ih => exact prod_upperQuotient _ _ α ih (pi_upperQuotient _ α (fun _ => O.quotient c)) + +lemma generated (h : ModelSum O.sheaf U B) : B.Generated := by + induction h with + | zero => exact fun x v => ⟨0,fun _ _ _ => rfl,Subsingleton.elim _ _⟩ + | add _ c _ n ih => exact prod_generated _ _ ih (pi_generated _ (fun _ => O.generated c)) + +lemma flabby (h : ModelSum O.sheaf U B) : B.Flabby := by + induction h with + | zero => exact fun U _ f _ => ⟨f,fun _ _ _ => rfl,fun _ _ => rfl⟩ + | add _ c _ n ih => exact prod_flabby _ _ ih (pi_flabby _ (fun _ => O.flabby c)) + +lemma minimal (h : ModelSum O.sheaf U B) (x : V) (hx : x ∉ U) : + LinearMap.ker (B.stalkMap x) ≤ + IsLocalRing.maximalIdeal R • (⊤ : Submodule R (B.vertex x)) := by + induction h with + | zero => + intro v _ + rw [Subsingleton.elim v 0] + exact Submodule.zero_mem _ + | add _ c hc n ih => + exact prod_minimal _ _ x _ ih (pi_minimal _ x _ + (fun _ => O.minimal c x (fun he => hx (he ▸ hc)))) + +end ModelSum +end KLInvariance.MomentGraph.Sheaf + +end + + +section + +namespace KLInvariance.MomentGraph.Sheaf +open scoped Pointwise +universe ur uv ue uz +variable {R : Type ur} [CommRing R] {V : Type uv} [PartialOrder V] + {E : Type ue} {G : OrderedGraph V E} + +/-- Equality of embedded images with a scalar on the upper image. -/ +def ScaledImages (B : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) + (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) : Prop := + ∀ z : B.edge e, + (∃ v ∈ B.upwardKernel (G.source e) F, B.lower e v=z) ↔ + ∃ w ∈ B.upwardKernel (G.target e) H, r • B.upper e w=z + +theorem scaledImages_iff (B : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) + (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) : + B.ScaledImages e F H r ↔ + (B.upwardKernel (G.source e) F).map (B.lower e) = + r • (B.upwardKernel (G.target e) H).map (B.upper e) := by + constructor + · intro h + ext z + rw [Submodule.mem_smul_pointwise_iff_exists] + change (∃ v, v ∈ B.upwardKernel (G.source e) F ∧ B.lower e v=z) ↔ _ + rw [h z] + constructor + · rintro ⟨w,hw,he⟩ + exact ⟨B.upper e w,⟨w,hw,rfl⟩,he⟩ + · rintro ⟨t,⟨w,hw,rfl⟩,he⟩ + exact ⟨w,hw,he⟩ + · intro h z + constructor + · rintro ⟨v,hv,rfl⟩ + have hv' : B.lower e v ∈ r • (B.upwardKernel (G.target e) H).map (B.upper e) := + h ▸ (show B.lower e v ∈ (B.upwardKernel (G.source e) F).map (B.lower e) from ⟨v,hv,rfl⟩) + obtain ⟨t,⟨w,hw,rfl⟩,he⟩ := (Submodule.mem_smul_pointwise_iff_exists _ _ _).mp hv' + exact ⟨w,hw,he⟩ + · rintro ⟨w,hw,rfl⟩ + have hw' : r • B.upper e w ∈ r • (B.upwardKernel (G.target e) H).map (B.upper e) := + (Submodule.mem_smul_pointwise_iff_exists _ _ _).mpr ⟨B.upper e w,⟨w,hw,rfl⟩,rfl⟩ + rw [← h] at hw' + exact hw' + +theorem prod_upwardKernel_iff (B C : Sheaf.{ur,uv,ue,uz} (R := R) G) + (x : V) (F : Set (Outgoing (G := G) x)) (v : (prod B C).vertex x) : + v ∈ (prod B C).upwardKernel x F ↔ + v.1 ∈ B.upwardKernel x F ∧ v.2 ∈ C.upwardKernel x F := by + constructor + · intro h + constructor + · rintro ⟨e,heq⟩ he + subst x + exact congrArg Prod.fst (h ⟨e,rfl⟩ he) + · rintro ⟨e,heq⟩ he + subst x + exact congrArg Prod.snd (h ⟨e,rfl⟩ he) + · rintro ⟨hB,hC⟩ ⟨e,heq⟩ he + subst x + exact Prod.ext (hB ⟨e,rfl⟩ he) (hC ⟨e,rfl⟩ he) + +theorem pi_upwardKernel_iff {ι : Type*} (B : ι → Sheaf.{ur,uv,ue,uz} (R := R) G) + (x : V) (F : Set (Outgoing (G := G) x)) (v : (pi B).vertex x) : + v ∈ (pi B).upwardKernel x F ↔ ∀ i, v i ∈ (B i).upwardKernel x F := by + constructor + · rintro h i ⟨e,heq⟩ he + subst x + exact congrFun (h ⟨e,rfl⟩ he) i + · rintro h ⟨e,heq⟩ he + subst x + exact funext (fun i => h i ⟨e,rfl⟩ he) + +theorem prod_scaledImages (B C : Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) + (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) + (hB : B.ScaledImages e F H r) (hC : C.ScaledImages e F H r) : + (prod B C).ScaledImages e F H r := by + intro z + constructor + · rintro ⟨v,hv,he⟩ + have hv' := (prod_upwardKernel_iff B C _ F v).mp hv + obtain ⟨b,hb,hbe⟩ := (hB z.1).mp ⟨v.1,hv'.1,congrArg Prod.fst he⟩ + obtain ⟨c,hc,hce⟩ := (hC z.2).mp ⟨v.2,hv'.2,congrArg Prod.snd he⟩ + exact ⟨(b,c),(prod_upwardKernel_iff B C _ H _).mpr ⟨hb,hc⟩,Prod.ext hbe hce⟩ + · rintro ⟨v,hv,he⟩ + have hv' := (prod_upwardKernel_iff B C _ H v).mp hv + obtain ⟨b,hb,hbe⟩ := (hB z.1).mpr ⟨v.1,hv'.1,congrArg Prod.fst he⟩ + obtain ⟨c,hc,hce⟩ := (hC z.2).mpr ⟨v.2,hv'.2,congrArg Prod.snd he⟩ + exact ⟨(b,c),(prod_upwardKernel_iff B C _ F _).mpr ⟨hb,hc⟩,Prod.ext hbe hce⟩ + +theorem pi_scaledImages {ι : Type*} (B : ι → Sheaf.{ur,uv,ue,uz} (R := R) G) (e : E) + (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) + (hB : ∀ i, (B i).ScaledImages e F H r) : (pi B).ScaledImages e F H r := by + classical + intro z + constructor + · rintro ⟨v,hv,he⟩ + have hv' := (pi_upwardKernel_iff B _ F v).mp hv + choose w hw hwe using fun i => (hB i (z i)).mp ⟨v i,hv' i,congrFun he i⟩ + exact ⟨w,(pi_upwardKernel_iff B _ H _).mpr hw,funext hwe⟩ + · rintro ⟨v,hv,he⟩ + have hv' := (pi_upwardKernel_iff B _ H v).mp hv + choose w hw hwe using fun i => (hB i (z i)).mpr ⟨v i,hv' i,congrFun he i⟩ + exact ⟨w,(pi_upwardKernel_iff B _ F _).mpr hw,funext hwe⟩ + +theorem zero_scaledImages (e : E) (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) : + (zero : Sheaf.{ur,uv,ue,uz} (R := R) G).ScaledImages e F H r := by + intro z + constructor <;> intro _ <;> exact ⟨0,Submodule.zero_mem _,Subsingleton.elim _ _⟩ + +theorem ModelSum.scaledImages {O : V → Sheaf.{ur,uv,ue,uz} (R := R) G} + {U : Set V} {B : Sheaf.{ur,uv,ue,uz} (R := R) G} (h : ModelSum O U B) + (e : E) (F : Set (Outgoing (G := G) (G.source e))) + (H : Set (Outgoing (G := G) (G.target e))) (r : R) + (hO : ∀ c ∈ U, (O c).ScaledImages e F H r) : B.ScaledImages e F H r := by + induction h with + | zero => exact zero_scaledImages e F H r + | add _ c hc n ih => + exact prod_scaledImages _ _ e F H r ih + (pi_scaledImages (fun _ : Fin n => O c) e F H r (fun _ => hO c hc)) + +end KLInvariance.MomentGraph.Sheaf + +end + + +section + +/-! Actual full upward kernels commute with finite graded sums, shifts and +sheaf isomorphisms. No freeness is inferred without a free model. -/ +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + + abbrev kernelData (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) := + B.upwardKernel x Set.univ + + def kernelProdEquiv (B C : GradedSheaf (𝓐 := 𝓐) G) (x : V) : + kernelData (prod B C) x ≃ₗ[A] ((kernelData B x).prod (kernelData C x)) where + toFun m := ⟨⟨m.val.1,((Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ m.val).mp m.property).1⟩, + ⟨m.val.2,((Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ m.val).mp m.property).2⟩⟩ + invFun m := ⟨⟨m.1.val,m.2.val⟩,(Sheaf.prod_upwardKernel_iff B.forget C.forget x Set.univ _).mpr + ⟨m.1.property,m.2.property⟩⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + + theorem kernelProdEquiv_graded (B C : GradedSheaf (𝓐 := 𝓐) G) (x : V) + (n : ℤ) (v : kernelData (prod B C) x) (hv : v∈(kernelData (prod B C) x).piece n) : + kernelProdEquiv B C x v∈((kernelData B x).prod (kernelData C x)).piece n := hv + + def kernelPiEquiv {ι : Type um} [Fintype ι] (B : ι → GradedSheaf (𝓐 := 𝓐) G) (x : V) : + kernelData (pi B) x ≃ₗ[A] ModuleData.pi (fun i => kernelData (B i) x) where + toFun m i := ⟨m.val i,(Sheaf.pi_upwardKernel_iff (fun i => (B i).forget) x Set.univ m.val).mp m.property i⟩ + invFun m := ⟨(fun i => (m i).val),(Sheaf.pi_upwardKernel_iff (fun i => (B i).forget) x Set.univ _).mpr + (fun i => (m i).property)⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + + theorem kernelPiEquiv_graded {ι : Type um} [Fintype ι] (B : ι → GradedSheaf (𝓐 := 𝓐) G) (x : V) + (n : ℤ) (v : kernelData (pi B) x) (hv : v∈(kernelData (pi B) x).piece n) : + kernelPiEquiv B x v∈(ModuleData.pi (fun i => kernelData (B i) x)).piece n := hv + + def kernelShiftEquiv (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) (d : ℕ) : + kernelData (B.shift d) x ≃ₗ[A] (kernelData B x).shift d := LinearEquiv.refl A _ + + theorem kernelShiftEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) (d : ℕ) + (n : ℤ) (v : kernelData (B.shift d) x) (hv : v∈(kernelData (B.shift d) x).piece n) : + kernelShiftEquiv B x d v∈((kernelData B x).shift d).piece n := hv + + def Iso.kernelEquiv {B C : GradedSheaf (𝓐 := 𝓐) G} (j : Iso B C) (x : V) : + kernelData B x ≃ₗ[A] kernelData C x where + toFun m := ⟨j.vertex x m.val,(j.toIso.upwardKernel_iff x Set.univ m.val).mpr m.property⟩ + invFun m := ⟨(j.vertex x).symm m.val,(j.toIso.symm.upwardKernel_iff x Set.univ m.val).mpr m.property⟩ + left_inv m := Subtype.ext ((j.vertex x).symm_apply_apply m.val) + right_inv m := Subtype.ext ((j.vertex x).apply_symm_apply m.val) + map_add' m n := Subtype.ext (map_add (j.vertex x) m.val n.val) + map_smul' a m := Subtype.ext (map_smul (j.vertex x) a m.val) + + theorem Iso.kernelEquiv_graded {B C : GradedSheaf (𝓐 := 𝓐) G} (j : Iso B C) (x : V) + (n : ℤ) (v : kernelData B x) (hv : v∈(kernelData B x).piece n) : + j.kernelEquiv x v∈(kernelData C x).piece n := j.vertex_graded x n v.val hv + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded Polynomial +universe uk us um +variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + + instance kernelShiftFree (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) (d : ℕ) + [Module.Free (MvPolynomial σ k) (kernelData B x)] : + Module.Free (MvPolynomial σ k) (kernelData (B.shift d) x) := + Module.Free.of_equiv (kernelShiftEquiv B x d).symm + + instance kernelProdFree (B C : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) + [Module.Free (MvPolynomial σ k) (kernelData B x)] + [Module.Free (MvPolynomial σ k) (kernelData C x)] : + Module.Free (MvPolynomial σ k) (kernelData (prod B C) x) := + Module.Free.of_equiv (kernelProdEquiv B C x).symm + + instance kernelPiFree {ι : Type um} [Fintype ι] + (B : ι → GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) + [∀ i, Module.Free (MvPolynomial σ k) (kernelData (B i) x)] : + Module.Free (MvPolynomial σ k) (kernelData (pi B) x) := + Module.Free.of_equiv (kernelPiEquiv B x).symm + + instance kernelZeroFree (x : V) : + Module.Free (MvPolynomial σ k) (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := by + let : Subsingleton (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := + ⟨fun x y => Subtype.ext (Subsingleton.elim _ _)⟩ + infer_instance + + theorem kernelChar_shift (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) (d : ℕ) + [Module.Free (MvPolynomial σ k) (kernelData B x)] : + (kernelData (B.shift d) x).char=X^d*(kernelData B x).char := by + rw [← ModuleData.char_shift _ d] + exact ModuleData.character_eq_of_gradedEquiv (kernelShiftEquiv B x d) + (kernelShiftEquiv_graded B x d) + + theorem kernelChar_prod (B C : GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) + [Module.Free (MvPolynomial σ k) (kernelData B x)] + [Module.Free (MvPolynomial σ k) (kernelData C x)] : + (kernelData (prod B C) x).char=(kernelData B x).char+(kernelData C x).char := by + rw [← ModuleData.char_prod] + exact ModuleData.character_eq_of_gradedEquiv (kernelProdEquiv B C x) + (kernelProdEquiv_graded B C x) + + theorem kernelChar_pi {ι : Type um} [Fintype ι] + (B : ι → GradedSheaf (𝓐 := polynomialGrading k σ) G) (x : V) + [∀ i, Module.Free (MvPolynomial σ k) (kernelData (B i) x)] : + (kernelData (pi B) x).char=∑ i, (kernelData (B i) x).char := by + rw [← ModuleData.char_pi] + exact ModuleData.character_eq_of_gradedEquiv (kernelPiEquiv B x) (kernelPiEquiv_graded B x) + + theorem kernelChar_zero (x : V) : + (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x).char=0 := by + let : Subsingleton (kernelData (zero (𝓐 := polynomialGrading k σ) (G := G)) x) := + ⟨fun x y => Subtype.ext (Subsingleton.elim _ _)⟩ + exact ModuleData.char_zero _ + + theorem ModelSum.kernelFree {O : V → GradedSheaf (𝓐 := polynomialGrading k σ) G} + (hf : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O y) x)) + {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} + (h : ModelSum O U B) (x : V) : Module.Free (MvPolynomial σ k) (kernelData B x) := by + induction h with + | zero => infer_instance + | @add C _ c _ n d ih => + let _ := ih + let _ := hf c x + infer_instance + + def freeKernelChar (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) + (hf : ∀ x, Module.Free (MvPolynomial σ k) (kernelData B x)) (x : V) : Polynomial ℤ := by + let := hf x + exact (kernelData B x).char + + theorem ModelSum.character_both [Fintype V] {α : E → MvPolynomial σ k} + (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) + (hk : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O.sheaf y) x)) + {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} + (h : ModelSum O.sheaf U B) : + ∃ m : V → Polynomial ℤ, (∀ y n, 0≤(m y).coeff n) ∧ + (∀ x, freeStalkChar B (h.free O) x = + ∑ y, m y*freeStalkChar (O.sheaf y) (O.free y) x) ∧ + (∀ x, freeKernelChar B (h.kernelFree hk) x = + ∑ y, m y*freeKernelChar (O.sheaf y) (hk y) x) := by + classical + induction h with + | zero => + refine ⟨0,by simp,?_,?_⟩ + · intro x + change ((GradedSheaf.zero (𝓐 := polynomialGrading k σ) (G := G)).vertex x).char = _ + simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] + exact ModuleData.char_zero _ + · intro x + change (kernelData (GradedSheaf.zero (𝓐 := polynomialGrading k σ) (G := G)) x).char = _ + simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] + exact kernelChar_zero (σ := σ) (G := G) x + | @add B h c hc n d ih => + obtain ⟨m,hm,heq,hkeq⟩ := ih + let a : Polynomial ℤ := ∑ i, X^(d i) + have ha (r : ℕ) : 0 ≤ a.coeff r := by + simp only [a,Polynomial.finsetSum_coeff,Polynomial.coeff_X_pow] + exact Finset.sum_nonneg (fun i _ => by split <;> norm_num) + refine ⟨fun y => m y+if y=c then a else 0,?_,?_,?_⟩ + · intro y r + rw [Polynomial.coeff_add] + apply add_nonneg (hm y r) + split + · exact ha r + · simp + · intro x + let _ := h.free O x + let _ := O.free c x + change ((B.vertex x).prod (ModuleData.pi (fun i => ((O.sheaf c).vertex x).shift (d i)))).char = _ + rw [ModuleData.char_prod,ModuleData.char_pi] + simp only [ModuleData.char_shift] + change freeStalkChar B (h.free O) x + _ = _ + rw [heq x] + simp only [add_mul,Finset.sum_add_distrib] + congr 1 + rw [← Finset.sum_mul] + simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + rfl + · intro x + let _ := h.kernelFree hk x + let _ := hk c x + change (kernelData (prod B (pi (fun i => (O.sheaf c).shift (d i)))) x).char = _ + rw [kernelChar_prod,kernelChar_pi] + simp only [kernelChar_shift] + change freeKernelChar B (h.kernelFree hk) x + _ = _ + rw [hkeq x] + simp only [add_mul,Finset.sum_add_distrib] + congr 1 + rw [← Finset.sum_mul] + simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + rfl + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + def kernelEquivFull (B : GradedSheaf (𝓐 := 𝓐) G) (x : V) : + kernelData B x ≃ₗ[A] LinearMap.ker (B.forget.stalkMap x) where + toFun m := ⟨m.val,funext (fun e => m.property e (Set.mem_univ e))⟩ + invFun m := ⟨m.val,fun e _ => congrFun m.property e⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl +end +end KLInvariance.MomentGraph.GradedSheaf + +namespace KLInvariance.BruhatGraph.FreeSheaf +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (B : FreeSheaf cs 1 b basis) + [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] +noncomputable section + + def kernelDual (d : SectionDuality cs 1 b basis B) (x : Interval cs 1 b) : + Dual (Coefficient (σ := σ)) (B.sheaf.vertex x) ≃ₗ[Coefficient (σ := σ)] + GradedSheaf.kernelData B.sheaf x := + (costalkEquivDual cs 1 b basis B d x).symm.trans (B.sheaf.kernelEquivFull x).symm + +omit [Fintype (Interval cs 1 b)] in + theorem kernel_free (d : SectionDuality cs 1 b basis B) (x : Interval cs 1 b) : + Module.Free (Coefficient (σ := σ)) (GradedSheaf.kernelData B.sheaf x) := by + let := B.free x + exact Module.Free.of_equiv (kernelDual cs b basis B d x) + + theorem kernelDual_homogeneous (d : SectionDuality cs 1 b basis B) (n : ℕ) + (hd : ∀ i j (m a : B.sheaf.sections Set.univ), + m∈(B.sheaf.sections Set.univ).piece i → a∈(B.sheaf.sections Set.univ).piece j → + d.pairing m a∈polynomialGrading ℝ σ (i+j-(n:ℤ))) + (x : Interval cs 1 b) (hn : cs.length x.val≤n) (r : ℤ) + (lam : Dual (Coefficient (σ := σ)) (B.sheaf.vertex x)) + (hlam : ∀ j (v : B.sheaf.vertex x), v∈(B.sheaf.vertex x).piece j → + lam v∈polynomialGrading ℝ σ (j+r)) : + kernelDual cs b basis B d x lam∈(GradedSheaf.kernelData B.sheaf x).piece + (r+(n-cs.length x.val : ℕ)) := by + have h := costalkEquivDual_inverse_homogeneous cs 1 b basis B d n hd x r lam hlam + rw [incoming_card] at h + change ((costalkEquivDual cs 1 b basis B d x).symm lam).val∈ + (B.sheaf.vertex x).piece (r+↑(n-cs.length x.val)) + have he : r+(n:ℤ)-cs.length x.val=r+↑(n-cs.length x.val) := by omega + rwa [he] at h + + theorem kernel_character (d : SectionDuality cs 1 b basis B) (n : ℕ) + (hd : ∀ i j (m a : B.sheaf.sections Set.univ), + m∈(B.sheaf.sections Set.univ).piece i → a∈(B.sheaf.sections Set.univ).piece j → + d.pairing m a∈polynomialGrading ℝ σ (i+j-(n:ℤ))) + (hn : cs.length b≤n) (x : Interval cs 1 b) : + GradedSheaf.freeKernelChar B.sheaf (kernel_free cs b basis B d) x= + Polynomial.reflect (n-cs.length x.val) (GradedSheaf.freeStalkChar B.sheaf B.free x) := by + let := B.free x + let := kernel_free cs b basis B d x + exact ModuleData.char_of_dual_equiv _ _ (kernelDual cs b basis B d x) _ + (kernelDual_homogeneous cs b basis B d n hd x ((length_le_of_bruhat cs x.property.2).trans hn)) + +end +end KLInvariance.BruhatGraph.FreeSheaf + +end + + +section + +/-! Genuine word costalk character from the integral word pairing, transported +along the fixed symmetric-algebra coordinate isomorphism. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottSection_left_orthogonal (l : List I) (hl : cs.IsReduced l) + (x : Interval cs 1 (cs.wordProd l)) + (m n : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) + (hm : ∀ y, y≠x → m.val y=0) (hn : n.val x=0) : + bottSectionDuality cs l hl m n=0 := by + obtain ⟨a,rfl⟩ := bottSection_surjective cs l hl m + obtain ⟨b,rfl⟩ := bottSection_surjective cs l hl n + rw [bottSectionDuality_apply] + exact bottStalk_supported_annihilates cs l hl x a b hm hn + + theorem bottSection_right_orthogonal (l : List I) (hl : cs.IsReduced l) + (x : Interval cs 1 (cs.wordProd l)) + (m n : (bottProjectionSheaf cs l 1 (cs.wordProd l)).sections Set.univ) + (hm : m.val x=0) (hn : ∀ y, y≠x → n.val y=0) : + bottSectionDuality cs l hl m n=0 := by + rw [bottSection_symmetric] + exact bottSection_left_orthogonal cs l hl x n m hn hm + + def bottWordPerfectPairing (l : List I) (hl : cs.IsReduced l) : + GradedSheaf.PerfectPairing (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) + (l.length : ℤ) where + pairing := bottSectionDuality cs l hl + homogeneous := bottSectionDuality_homogeneous cs basis l hl + left_orthogonal := bottSection_left_orthogonal cs l hl + right_orthogonal := bottSection_right_orthogonal cs l hl + + def bottPolynomialPerfectPairing (l : List I) (hl : cs.IsReduced l) : + GradedSheaf.PerfectPairing (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) (l.length : ℤ) := + (bottWordPerfectPairing cs basis l hl).coefficientChange (SymmetricAlgebra.equivMvPolynomial basis) + (mem_symmetricGrading basis) + + def bottFreeSheaf (l : List I) : FreeSheaf cs 1 (cs.wordProd l) basis where + sheaf := bottPolynomialSheaf cs basis l 1 (cs.wordProd l) + free := bottPolynomialSheaf_free cs basis l 1 (cs.wordProd l) + quotient := bottPolynomialSheaf_quotient cs basis l 1 (cs.wordProd l) + generated := bottPolynomialSheaf_generated cs basis l 1 (cs.wordProd l) + +local instance finiteEdges (l : List I) : Fintype (Edge cs 1 (cs.wordProd l)) := Fintype.ofFinite _ +local instance (a : Type*) : DecidableEq a := Classical.decEq a + + def bottFreeDuality (l : List I) (hl : cs.IsReduced l) : + FreeSheaf.SectionDuality cs 1 (cs.wordProd l) basis (bottFreeSheaf cs basis l) := + FreeSheaf.dualityOfPairing cs 1 (cs.wordProd l) basis _ (bottPolynomialPerfectPairing cs basis l hl) + + theorem bottKernelFree (l : List I) (hl : cs.IsReduced l) (x : Interval cs 1 (cs.wordProd l)) : + Module.Free (Coefficient (σ := σ)) + (GradedSheaf.kernelData (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) x) := + FreeSheaf.kernel_free cs (cs.wordProd l) basis _ (bottFreeDuality cs basis l hl) x + + theorem bottKernelCharacter (l : List I) (hl : cs.IsReduced l) + [Fintype (Interval cs 1 (cs.wordProd l))] (x : Interval cs 1 (cs.wordProd l)) : + GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) + (bottKernelFree cs basis l hl) x=Polynomial.reflect (rankDifference cs x.val (cs.wordProd l)) + (bottStalkCharacter cs basis l x.val) := by + have he : cs.length (cs.wordProd l)=l.length := hl + change _=Polynomial.reflect (cs.length (cs.wordProd l)-cs.length x.val) _ + rw [he] + apply FreeSheaf.kernel_character cs (cs.wordProd l) basis _ (bottFreeDuality cs basis l hl) + l.length _ he.le x + intro i j m a hm ha + exact (bottPolynomialPerfectPairing cs basis l hl).homogeneous i j m a + (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Bar and the exact R-convolution for genuine positive Hecke words. +No KL character or degree estimate is assumed. -/ +namespace KLInvariance.HeckeQ +open Hecke (Space basis) +variable {I W C : Type*} [Group W] {M : CoxeterMatrix I} [CommRing C] +noncomputable section + + theorem one_add_leftInv (cs : CoxeterSystem M W) (q : Cˣ) (i : I) (v : Space W C) : + v+leftInv cs q i v=(↑q⁻¹:C) • (v+left cs (q:C) i v) := by + rw [leftInv_apply,smul_sub,smul_smul,smul_add] + have h : (↑q⁻¹:C)*((q:C)-1)=1-(↑q⁻¹:C) := by rw [mul_sub,q.inv_mul,mul_one] + rw [h,sub_smul,one_smul] + module + + theorem barLinear_positiveWord (cs : CoxeterSystem M W) (q : Cˣ) (l : List I) : + barLinear cs q (positiveWord cs (↑q⁻¹:C) l)= + (↑q⁻¹:C)^l.length • positiveWord cs (q:C) l := by + induction l with + | nil => simp [barBasis_one] + | cons i l ih => + simp only [positiveWord,map_add] + have h := congrArg (fun f : Module.End C (Space W C) => f (positiveWord cs (↑q⁻¹:C) l)) + (barLinear_left cs q i) + simp only [Module.End.mul_apply] at h + rw [h,ih,map_smul,← smul_add,one_add_leftInv,smul_smul,List.length_cons,pow_succ] + + theorem positiveWord_support (cs : CoxeterSystem M W) (q : C) (l : List I) + (hl : cs.IsReduced l) : (positiveWord cs q l).support ⊆ lowerFinset cs (cs.wordProd l) := by + classical + induction l with + | nil => simpa [positiveWord,Hecke.basis,lowerFinset] using + (show (Finsupp.single 1 (1:C)).support ⊆ lowerFinset cs 1 by + intro x hx + by_cases h : x=1 + · subst x; exact (mem_lowerFinset cs 1 1).mpr .refl + · simp [Finsupp.mem_support_iff,Ne.symm h] at hx) + | cons i l ih => + have ht : cs.IsReduced l := by simpa using hl.drop 1 + have ha : ¬cs.length (cs.simple i*cs.wordProd l) simp_all + rcases h with h|h + · exact (le_upperSimple cs i x).trans + (step x ((mem_lowerFinset cs _ _).mp (ih ht (Finsupp.mem_support_iff.mpr h)))) + · have hh := step (cs.simple i*x) + ((mem_lowerFinset cs _ _).mp (ih ht (Finsupp.mem_support_iff.mpr h))) + rw [upperSimple_mul] at hh + exact (le_upperSimple cs i x).trans hh + + theorem positiveWord_rValue (cs : CoxeterSystem M W) (q : Cˣ) (l : List I) + (hl : cs.IsReduced l) (x : W) : + ∑ z ∈ lowerFinset cs (cs.wordProd l), rValue cs q x z * positiveWord cs (q:C) l z= + (↑q⁻¹:C)^cs.length x * (q:C)^l.length * positiveWord cs (↑q⁻¹:C) l x := by + classical + have h := congrArg (fun v : Space W C => v x) (barLinear_positiveWord cs q⁻¹ l) + simp only [inv_inv] at h + rw [barLinear,Finsupp.linearCombination_apply,Finsupp.sum_apply, + Finsupp.sum_of_support_subset _ (positiveWord_support cs (q:C) l hl) _ (by simp)] at h + simp only [Finsupp.smul_apply,smul_eq_mul] at h + have hr (z : W) : rValue cs q x z=(↑q⁻¹:C)^cs.length x * barBasis cs q⁻¹ z x := by + simpa using rValue_inverse_eq_barBasis cs q⁻¹ x z + simp only [hr,mul_assoc,←Finset.mul_sum] + rw [show (∑ z ∈ lowerFinset cs (cs.wordProd l), barBasis cs q⁻¹ z x * positiveWord cs (q:C) l z)= + (q:C)^l.length * positiveWord cs (↑q⁻¹:C) l x by + simpa only [mul_comm] using h] + +end +end KLInvariance.HeckeQ + +end + + +section + +namespace KLInvariance.HeckeQ +open Hecke (Space basis) +variable {I W C : Type*} [Group W] {M : CoxeterMatrix I} [CommRing C] +noncomputable section + + theorem eval_positiveWord (cs : CoxeterSystem M W) (q : C) (l : List I) (x : W) : + Polynomial.eval₂ (Int.castRingHom C) q + (positiveWord cs (Polynomial.X : Polynomial ℤ) l x)=positiveWord cs q l x := by + classical + induction l generalizing x with + | nil => simp only [positiveWord_nil,Hecke.basis,Finsupp.single_apply]; split_ifs <;> simp + | cons i l ih => + rw [positiveWord_cons_coeff,positiveWord_cons_coeff] + split_ifs <;> simp only [Polynomial.eval₂_add,Polynomial.eval₂_mul, + Polynomial.eval₂_X,ih] + +end +end KLInvariance.HeckeQ + +end + + +section + +namespace KLInvariance.Graded.ModuleData +open Polynomial Module +universe uk us um +variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] + (M N : ModuleData.{uk,max uk us,um} (polynomialGrading k σ)) +noncomputable section + + theorem char_natDegree_le_of_dual_equiv [Module.Free (MvPolynomial σ k) M] + (e : Dual (MvPolynomial σ k) M ≃ₗ[MvPolynomial σ k] N) (l : ℕ) + (he : ∀ r lam, (∀ j (v : M), v∈M.piece j → + lam v∈polynomialGrading k σ (j+r)) → e lam∈N.piece (r+l)) : + M.char.natDegree≤l := by + classical + let c := (exists_nonnegativeBasis (σ := σ) M.piece M.nonneg).some + rw [char,character_eq _ _ c] + apply Polynomial.natDegree_sum_le_of_forall_le + intro i _ + simpa only [Polynomial.natDegree_X_pow] using M.degree_le_of_dual_equiv N e l he c i + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +/-! Genuine word stalk-to-costalk R-convolution, derived from the Hecke bar +and the constructed integral perfect word pairing. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section +local instance (a : Type*) : DecidableEq a := Classical.decEq a +local instance rWordEdges (l : List I) : Fintype (Edge cs 1 (cs.wordProd l)) := Fintype.ofFinite _ +local instance rWordInterval (l : List I) : Fintype (Interval cs 1 (cs.wordProd l)) := by + let := interval_finite cs 1 (cs.wordProd l) + exact Fintype.ofFinite _ + + theorem bottStalkCharacter_natDegree_le (l : List I) (hl : cs.IsReduced l) + (x : Interval cs 1 (cs.wordProd l)) : + (bottStalkCharacter cs basis l x.val).natDegree≤rankDifference cs x.val (cs.wordProd l) := by + let B := bottFreeSheaf cs basis l + let := B.free x + change (B.sheaf.vertex x).char.natDegree≤rankDifference cs x.val (cs.wordProd l) + apply ModuleData.char_natDegree_le_of_dual_equiv _ _ + (FreeSheaf.kernelDual cs (cs.wordProd l) basis B (bottFreeDuality cs basis l hl) x) + (rankDifference cs x.val (cs.wordProd l)) + have hd := (bottPolynomialPerfectPairing cs basis l hl).homogeneous + have he : cs.length (cs.wordProd l)=l.length := hl + apply FreeSheaf.kernelDual_homogeneous cs (cs.wordProd l) basis B (bottFreeDuality cs basis l hl) + (cs.length (cs.wordProd l)) _ x (length_le_of_bruhat cs x.property.2) + intro i j m a hm ha + rw [he] + exact hd i j m a (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) + + theorem bottStalkCharacter_reciprocity (l : List I) (hl : cs.IsReduced l) + (x : Interval cs 1 (cs.wordProd l)) : + Polynomial.reflect (rankDifference cs x.val (cs.wordProd l)) (bottStalkCharacter cs basis l x.val)= + ∑ z ∈ lowerFinset cs (cs.wordProd l), + OrdinaryR.polynomial cs x.val z*bottStalkCharacter cs basis l z := by + apply Polynomial.toLaurent_injective + let q := OrdinaryR.variableUnit + have h := HeckeQ.positiveWord_rValue cs q l hl x.val + have hlen : cs.length x.val≤l.length := hl ▸ length_le_of_bruhat cs x.property.2 + have hp : (↑q⁻¹ : LaurentPolynomial ℤ)^cs.length x.val * (q:LaurentPolynomial ℤ)^l.length= + (q:LaurentPolynomial ℤ)^(rankDifference cs x.val (cs.wordProd l)) := by + have he : cs.length (cs.wordProd l)=l.length := hl + rw [rankDifference,he,← Nat.sub_add_cancel hlen,pow_add] + calc + _ = ((↑q⁻¹:LaurentPolynomial ℤ)*(q:LaurentPolynomial ℤ))^cs.length x.val * + (q:LaurentPolynomial ℤ)^(l.length-cs.length x.val) := by rw [mul_pow]; ring + _ = _ := by rw [q.inv_mul]; simp + rw [hp] at h + have hv (p : Polynomial ℤ) : Polynomial.toLaurent p= + Polynomial.eval₂ (Int.castRingHom (LaurentPolynomial ℤ)) (q:LaurentPolynomial ℤ) p := by + induction p using Polynomial.induction_on' with + | add p r hp hr => simp only [map_add,Polynomial.eval₂_add,hp,hr] + | monomial n a => simp [q,Polynomial.toLaurent_C_mul_T] + rw [hv,eval₂_reflect_unit q _ _ (bottStalkCharacter_natDegree_le cs basis l hl x)] + rw [hv] + simp only [Polynomial.eval₂_finsetSum,Polynomial.eval₂_mul,OrdinaryR.polynomial_eval, + bottStalkCharacter_eq_heckeWord,HeckeQ.eval_positiveWord] + exact h.symm + + theorem bottKernelCharacter_rConvolution (l : List I) (hl : cs.IsReduced l) + (x : Interval cs 1 (cs.wordProd l)) : + GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) + (bottKernelFree cs basis l hl) x= + ∑ z : Interval cs 1 (cs.wordProd l), + OrdinaryR.polynomial cs x.val z.val*bottStalkCharacter cs basis l z.val := by + rw [bottKernelCharacter cs basis l hl x,bottStalkCharacter_reciprocity cs basis l hl x] + exact Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs 1 (cs.wordProd l)))) + (lowerFinset cs (cs.wordProd l)) + (fun z => by simp only [mem_lowerFinset]; exact ⟨fun h => ⟨one_bruhat cs z,h⟩,And.right⟩) + (fun z => OrdinaryR.polynomial cs x.val z*bottStalkCharacter cs basis l z) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Recognition by the actual minimal-boundary object, not by an asserted +character or by restricting a perfect form to an arbitrary summand. -/ +namespace KLInvariance.MomentGraph.BoundarySheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] + [IsDomain A] {hneg : ∀ n < 0, 𝓐 n=⊥} + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} {α : E → A} {b : V} + (B : BoundarySheaf hneg G α b) +noncomputable section + + theorem top_nontrivial : Nontrivial (B.sheaf.vertex b) := by + let e := ModuleData.equivOfEq B.top + let z : ModuleData.unit.{uk,ua,um} hneg := fun _ => (0 : A) + let o : ModuleData.unit.{uk,ua,um} hneg := fun _ => (1 : A) + refine ⟨⟨e.symm z,e.symm o,?_⟩⟩ + intro h + exact zero_ne_one (congrFun (e.symm.injective h) PUnit.unit) + + variable [IsNoetherianRing A] [Fintype V] [Fintype E] + + theorem iso_of_primitive_top_split + (hzero : ∀ a ∈ 𝓐 0, ∃ c : k, algebraMap k A c=a) + (hb : ∀ x, x≤b) (C : GradedSheaf (𝓐 := 𝓐) G) + (hCq : C.UpperQuotient α) (hCfree : ∀ x, Module.Free A (C.vertex x)) + (hCf : C.forget.Flabby) (hCg : C.forget.Generated) + (hCp : (GradedSheaf.Hom.id C).PrimitiveProjector) + (i : ModuleData.Hom (B.sheaf.vertex b) (C.vertex b)) + (p : ModuleData.Hom (C.vertex b) (B.sheaf.vertex b)) + (hpi : ∀ v, p.map (i.map v)=v) : Nonempty (GradedSheaf.Iso B.sheaf C) := by + let := B.top_nontrivial + obtain ⟨s⟩ := B.splitIn_of_top_split hzero hb C hCq hCfree hCf hCg i p hpi + exact ⟨s.isoOfPrimitive hCp b⟩ + +end +end KLInvariance.MomentGraph.BoundarySheaf + +end + + +section + +/-! The actual symmetric-coefficient BMP boundary sheaf is isomorphic to +its integral adjoint image. The splitting is constructed from the word's +proved free-stalk, exact-edge and flabbiness properties. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (B : BoundarySheaf (symmetricGrading_negative basis) + (graph cs 1 (cs.wordProd l)) (symmetricLabel cs 1 (cs.wordProd l)) + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) + (s : GradedSheaf.SplitIn B.sheaf (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + def bottSplitAdjointSplit : GradedSheaf.SplitIn + (bottSplitAdjointSheaf cs basis l hl B.sheaf s) + (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)) := by + let := symmetricCoefficientNoetherian basis + exact (bottAdjointSheaf cs basis l hl s.projector).imageSplit + (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) + (bottAdjointSheaf_edge_idempotent cs basis l hl s.projector s.projector_vertex) + + theorem bottSplitAdjoint_free (x : Interval cs 1 (cs.wordProd l)) : + Module.Free (SymmetricCoefficient (M := M)) + ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex x) := by + let := symmetricCoefficientNoetherian basis + let : Module.Free (SymmetricCoefficient (M := M)) + ((bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l)).vertex x) := + bottStalkFree cs l x.val + exact (bottSplitAdjointSplit cs basis l hl B s).vertex_free + (symmetricGrading_negative basis) (symmetricGrading_zero basis) x + + def bottSplitAdjointTopInclusion : ModuleData.Hom + (B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) + ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) := + ((bottSplitAdjointSplit cs basis l hl B s).projection.vertex _).comp + (bottBoundarySheafTopInclusion cs basis l hl B) + + def bottSplitAdjointTopProjection : ModuleData.Hom + ((bottSplitAdjointSheaf cs basis l hl B.sheaf s).vertex + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) + (B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) := + (bottBoundarySheafTopProjection cs basis l hl B).comp + ((bottSplitAdjointSplit cs basis l hl B s).inclusion.vertex _) + + theorem bottSplitAdjointTop_split + (v : B.sheaf.vertex ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) : + (bottSplitAdjointTopProjection cs basis l hl B s).map + ((bottSplitAdjointTopInclusion cs basis l hl B s).map v)=v := by + change (bottBoundarySheafTopProjection cs basis l hl B).map + (((bottAdjointSheaf cs basis l hl s.projector).vertex + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩).map + ((bottBoundarySheafTopInclusion cs basis l hl B).map v))=v + exact (congrArg (bottBoundarySheafTopProjection cs basis l hl B).map + (bottBoundarySplitAdjoint_top_fixed cs basis l hl _ B s + ((bottBoundarySheafTopInclusion cs basis l hl B).map v))).trans + (bottBoundarySheafTop_split cs basis l hl B v) + + theorem bottBoundarySheaf_iso_adjoint : Nonempty + (GradedSheaf.Iso B.sheaf (bottSplitAdjointSheaf cs basis l hl B.sheaf s)) := by + classical + let := symmetricCoefficientNoetherian basis + let := interval_finite cs 1 (cs.wordProd l) + let := Fintype.ofFinite (Interval cs 1 (cs.wordProd l)) + let := Fintype.ofFinite (Edge cs 1 (cs.wordProd l)) + let t := bottSplitAdjointSplit cs basis l hl B s + exact B.iso_of_primitive_top_split (symmetricGrading_zero basis) (fun x => x.property.2) + (bottSplitAdjointSheaf cs basis l hl B.sheaf s) + (t.upperQuotient (bottGradedProjectionSheaf_upperQuotient cs basis l 1 (cs.wordProd l))) + (bottSplitAdjoint_free cs basis l hl B s) + (t.flabby (bottProjectionSheaf_flabby cs l hl)) + (t.generated (bottProjectionSheaf_generated cs l 1 (cs.wordProd l))) + (bottBoundarySplitAdjoint_primitive cs basis l hl _ B s) + (bottSplitAdjointTopInclusion cs basis l hl B s) + (bottSplitAdjointTopProjection cs basis l hl B s) + (bottSplitAdjointTop_split cs basis l hl B s) + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + {𝓐 : ℤ → Submodule k A} [IsNoetherianRing A] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} + {B C : GradedSheaf (𝓐 := 𝓐) G} (s : SplitIn B C) +noncomputable section + + theorem SplitIn.imageSectionEquiv_symm_coordinates (U : Set V) + (n : B.forget.sections U) (x : V) : + (((s.imageSectionEquiv U).symm n).val x).val=(s.inclusion.vertex x).map (n.val x) := by + rw [s.imageSectionEquiv_symm_apply] + change (s.inclusion.vertex x).map ((s.projection.vertex x).map + ((s.inclusion.vertex x).map (n.val x)))=(s.inclusion.vertex x).map (n.val x) + exact congrArg (s.inclusion.vertex x).map (s.vertex_split x (n.val x)) + + theorem SplitIn.imageSectionEquiv_symm_inclusion (U : Set V) + (n : B.forget.sections U) : + s.projector.imageInclusion.sectionMap U ((s.imageSectionEquiv U).symm n)= + s.inclusion.sectionMap U n := by + apply Subtype.ext + funext x + exact s.imageSectionEquiv_symm_coordinates U n x + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +/-! The adjoint-summand pairing is the ambient word pairing on its two +honest (generally different) integral sheaf embeddings. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) + (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) +noncomputable section + + def bottSplitRightWord (n : B.forget.sections Set.univ) : BottSamelsonModule cs l := by + let := symmetricCoefficientNoetherian basis + exact (bottImageSectionWordEquiv cs basis l hl s.projector s.projector_vertex + ((s.imageSectionEquiv Set.univ).symm n)).val + + def bottSplitLeftWord + (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) : + BottSamelsonModule cs l := by + let := symmetricCoefficientNoetherian basis + exact (bottImageSectionWordEquiv cs basis l hl (bottAdjointSheaf cs basis l hl s.projector) + (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) m).val + + theorem bottSplitRightWord_coordinates (n : B.forget.sections Set.univ) + (x : Interval cs 1 (cs.wordProd l)) : + bottStalkProjection cs l x.val (bottSplitRightWord cs basis l hl B s n)= + (s.inclusion.vertex x).map (n.val x) := by + let := symmetricCoefficientNoetherian basis + exact (bottImageSectionWordEquiv_coordinates cs basis l hl s.projector s.projector_vertex + ((s.imageSectionEquiv Set.univ).symm n) x).trans + (s.imageSectionEquiv_symm_coordinates Set.univ n x) + + theorem bottSplitLeftWord_coordinates + (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) + (x : Interval cs 1 (cs.wordProd l)) : + bottStalkProjection cs l x.val (bottSplitLeftWord cs basis l hl B s m)=(m.val x).val := by + let := symmetricCoefficientNoetherian basis + exact bottImageSectionWordEquiv_coordinates cs basis l hl + (bottAdjointSheaf cs basis l hl s.projector) + (bottAdjointSheaf_vertex_idempotent cs basis l hl s.projector s.projector_vertex) m x + + theorem bottSplitAdjointWord_apply + (m : (bottSplitAdjointSheaf cs basis l hl B s).forget.sections Set.univ) + (n : B.forget.sections Set.univ) : + bottSplitAdjointEquivDual cs basis l hl B s m n= + bottSamelsonDuality cs l (bottSplitLeftWord cs basis l hl B s m) + (bottSplitRightWord cs basis l hl B s n) := by + let := symmetricCoefficientNoetherian basis + exact bottAdjointImageEquivDual_apply cs basis l hl s.projector s.projector_vertex m + ((s.imageSectionEquiv Set.univ).symm n) + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! An actual recognition isomorphism to the adjoint image gives the required +perfect pairing. The two ambient embeddings remain distinct. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) + (l : List I) (hl : cs.IsReduced l) + (B : GradedSheaf (𝓐 := symmetricGrading basis) (graph cs 1 (cs.wordProd l))) + (s : GradedSheaf.SplitIn B (bottGradedProjectionSheaf cs basis l 1 (cs.wordProd l))) + (j : GradedSheaf.Iso B (bottSplitAdjointSheaf cs basis l hl B s)) +noncomputable section + + def bottRecognizedPerfectPairing : GradedSheaf.PerfectPairing B (l.length : ℤ) where + pairing := (j.toIso.sections Set.univ).trans (bottSplitAdjointEquivDual cs basis l hl B s) + homogeneous i q m n hm hn := bottSplitAdjointPairing_homogeneous cs basis l hl B s i q + (j.toIso.sections Set.univ m) n (fun x => j.vertex_graded x i _ (hm x)) hn + left_orthogonal x m n hm hn := by + change bottSplitAdjointEquivDual cs basis l hl B s (j.toIso.sections Set.univ m) n=0 + rw [bottSplitAdjointWord_apply] + apply bottStalk_supported_annihilates cs l hl x + · intro y hy + rw [bottSplitLeftWord_coordinates] + change ((j.vertex y (m.val y)).val)=0 + rw [hm y hy,map_zero] + rfl + · rw [bottSplitRightWord_coordinates] + change (s.inclusion.vertex x).map (n.val x)=0 + rw [hn] + exact (s.inclusion.vertex x).map.map_zero + right_orthogonal x m n hm hn := by + change bottSplitAdjointEquivDual cs basis l hl B s (j.toIso.sections Set.univ m) n=0 + rw [bottSplitAdjointWord_apply,bottSamelson_symmetric] + apply bottStalk_supported_annihilates cs l hl x + · intro y hy + rw [bottSplitRightWord_coordinates] + change (s.inclusion.vertex y).map (n.val y)=0 + rw [hn y hy] + exact (s.inclusion.vertex y).map.map_zero + · rw [bottSplitLeftWord_coordinates] + change ((j.vertex x (m.val x)).val)=0 + rw [hm,map_zero] + rfl + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! The same genuine minimal boundary construction over the symmetric +coefficient algebra. Its polynomial-coordinate comparison is proved separately. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + omit [Fintype σ] in + theorem symmetric_scalar_mod_positive (a : SymmetricCoefficient (M := M)) : + ∃ c : ℝ, a-algebraMap ℝ (SymmetricCoefficient (M := M)) c ∈ positiveIdeal (symmetricGrading basis) := by + obtain ⟨c,hc⟩ := symmetricGrading_zero basis _ + (DirectSum.decompose (symmetricGrading basis) a 0).property + refine ⟨c,?_⟩ + rw [positiveIdeal_eq_augmentation_ker _ (symmetricGrading_negative basis)] + change component (symmetricGrading basis) 0 (a-algebraMap ℝ (SymmetricCoefficient (M := M)) c)=0 + rw [map_sub,hc] + rw [show component (symmetricGrading basis) 0 + (DirectSum.decompose (symmetricGrading basis) a 0 : SymmetricCoefficient (M := M)) = + (DirectSum.decompose (symmetricGrading basis) a 0 : SymmetricCoefficient (M := M)) from + DirectSum.decompose_of_mem_same _ (DirectSum.decompose (symmetricGrading basis) a 0).property] + exact sub_self _ + + theorem symmetricLabel_homogeneous (u b : W) (e : Edge cs u b) : + symmetricLabel cs u b e ∈ symmetricGrading basis 1 := + (mem_symmetricGrading basis 1 _).mpr (polynomialLabel_homogeneous cs u b basis e) + + theorem exists_symmetricBoundarySheaf (b : W) : + Nonempty (BoundarySheaf (symmetricGrading_negative basis) + (graph cs 1 b) (symmetricLabel cs 1 b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩) := by + classical + let := symmetricCoefficientNoetherian basis + let := interval_finite cs 1 b + let := Fintype.ofFinite (Interval cs 1 b) + let := Fintype.ofFinite (Edge cs 1 b) + exact MomentGraph.exists_boundarySheaf (symmetricGrading_negative basis) + (graph cs 1 b) (symmetric_scalar_mod_positive basis) + ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ (fun x => x.property.2) + (symmetricLabel cs 1 b) (symmetricLabel_homogeneous cs basis 1 b) + + def symmetricBoundarySheaf (b : W) : + BoundarySheaf (symmetricGrading_negative basis) + (graph cs 1 b) (symmetricLabel cs 1 b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ := + (exists_symmetricBoundarySheaf cs basis b).some + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Unconditional integral graded support-orthogonal duality for the actual +normalized minimal-boundary sheaf over the symmetric coefficient algebra. -/ +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph +universe u us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem symmetricBoundarySheaf_perfectPairing_word (l : List I) (hl : cs.IsReduced l) + (B : BoundarySheaf (symmetricGrading_negative basis) + (graph cs 1 (cs.wordProd l)) (symmetricLabel cs 1 (cs.wordProd l)) + ⟨cs.wordProd l,one_bruhat cs _,bruhat_refl cs _⟩) : + Nonempty (GradedSheaf.PerfectPairing B.sheaf (cs.length (cs.wordProd l) : ℤ)) := by + obtain ⟨s⟩ := bottBoundarySheaf_splitIn cs basis l hl B + obtain ⟨j⟩ := bottBoundarySheaf_iso_adjoint cs basis l hl B s + have hd : cs.length (cs.wordProd l)=l.length := hl + rw [hd] + exact ⟨bottRecognizedPerfectPairing cs basis l hl B.sheaf s j⟩ + + theorem symmetricBoundarySheaf_perfectPairing (b : W) : + Nonempty (GradedSheaf.PerfectPairing (symmetricBoundarySheaf cs basis b).sheaf (cs.length b : ℤ)) := by + obtain ⟨l,hl,he⟩ := cs.exists_isReduced b + subst b + exact symmetricBoundarySheaf_perfectPairing_word cs basis l hl _ + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] + [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) + (hA : ∀ n<0,𝓐 n=⊥) (hB : ∀ n<0,𝓑 n=⊥) +noncomputable section + + def changeUnitHom : Hom (change e he (unit.{uk,ua,um} hA)) (unit hB) where + map := + { toFun m j := e (m.val j) + map_add' m n := funext fun j => map_add e (m.val j) (n.val j) + map_smul' b m := by + funext j + change e (e.symm b * m.val j)=b * e (m.val j) + rw [map_mul,e.apply_symm_apply] } + graded := by + intro n m hm j + exact (he (n-0) _).mp ((mem_changePiece e (unit hA) n m).mp hm j) + + def changeUnitInvHom : Hom (unit.{uk,ua,um} hB) (change e he (unit hA)) where + map := + { toFun m := CoefficientChange.mk (fun j => e.symm (m j)) + map_add' m n := CoefficientChange.ext (funext fun j => map_add e.symm (m j) (n j)) + map_smul' b m := by + apply CoefficientChange.ext + funext j + exact map_mul e.symm b (m j) } + graded := by + intro n m hm + apply (mem_changePiece e (unit hA) n _).mpr + intro j + apply (he (n-0) _).mpr + change e (e.symm (m j)) ∈ 𝓑 (n-0) + rw [e.apply_symm_apply] + exact hm j + + theorem changeUnitHom_inv (m : unit.{uk,ua,um} hB) : + (changeUnitHom e he hA hB).map ((changeUnitInvHom e he hA hB).map m)=m := + funext fun j => e.apply_symm_apply (m j) + + theorem changeUnitInvHom_hom (m : change e he (unit.{uk,ua,um} hA)) : + (changeUnitInvHom e he hA hB).map ((changeUnitHom e he hA hB).map m)=m := + CoefficientChange.ext (funext fun j => e.symm_apply_apply (m.val j)) + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) +noncomputable section + + def unchangeHom {M N : ModuleData.{uk,ua,um} 𝓐} (f : Hom (change e he M) (change e he N)) : + Hom M N where + map := + { toFun m := (f.map (CoefficientChange.mk m)).val + map_add' m n := congrArg CoefficientChange.val (map_add f.map (CoefficientChange.mk m) (CoefficientChange.mk n)) + map_smul' a m := by + have hh := congrArg CoefficientChange.val (map_smul f.map (e a) (CoefficientChange.mk m)) + change (f.map (CoefficientChange.mk (e.symm (e a) • m))).val= + e.symm (e a) • (f.map (CoefficientChange.mk m)).val at hh + simpa only [e.symm_apply_apply, RingHom.id_apply] using hh } + graded n m hm := (mem_changePiece e N n _).mp + (f.graded n (CoefficientChange.mk m) ((mem_changePiece e M n _).mpr hm)) + +end +end KLInvariance.Graded.ModuleData + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + + def Hom.coefficientUnchange {S T : GradedSheaf (𝓐 := 𝓐) G} + (g : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he T)) : Hom S T where + vertex x := ModuleData.unchangeHom e he (g.vertex x) + edge f := ModuleData.unchangeHom e he (g.edge f) + lower f m := congrArg CoefficientChange.val (g.lower f (CoefficientChange.mk m)) + upper f m := congrArg CoefficientChange.val (g.upper f (CoefficientChange.mk m)) + + theorem coefficientChange_primitive (S : GradedSheaf (𝓐 := 𝓐) G) + (hS : (Hom.id S).PrimitiveProjector) : + (Hom.id (GradedSheaf.coefficientChange e he S)).PrimitiveProjector := by + constructor + · apply Hom.eq_of_maps <;> intros <;> rfl + · intro f hf _ _ + let g : Hom S S := f.coefficientUnchange e he + have hg : g.comp g=g := by + apply Hom.eq_of_maps + · intro x m + exact congrArg (fun q : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he S) => + ((q.vertex x).map (CoefficientChange.mk m)).val) hf + · intro x m + exact congrArg (fun q : Hom (GradedSheaf.coefficientChange e he S) (GradedSheaf.coefficientChange e he S) => + ((q.edge x).map (CoefficientChange.mk m)).val) hf + have hgL : g.comp (Hom.id S)=g := by apply Hom.eq_of_maps <;> intros <;> rfl + have hgR : (Hom.id S).comp g=g := by apply Hom.eq_of_maps <;> intros <;> rfl + rcases hS.2 g hg hgL hgR with hz | hi + · left + apply Hom.eq_of_maps + · intro x m + apply CoefficientChange.ext + exact congrArg (fun q : Hom S S => (q.vertex x).map m.val) hz + · intro x m + apply CoefficientChange.ext + exact congrArg (fun q : Hom S S => (q.edge x).map m.val) hz + · right + apply Hom.eq_of_maps + · intro x m + apply CoefficientChange.ext + exact congrArg (fun q : Hom S S => (q.vertex x).map m.val) hi + · intro x m + apply CoefficientChange.ext + exact congrArg (fun q : Hom S S => (q.edge x).map m.val) hi + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.Graded.ModuleData +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] + [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) + {hA : ∀ n<0,𝓐 n=⊥} {hB : ∀ n<0,𝓑 n=⊥} + {M : ModuleData.{uk,ua,um} 𝓐} (hM : M=unit hA) + {N : ModuleData.{uk,ua,um} 𝓑} (hN : N=unit hB) +noncomputable section + + def changeTopInclusion : Hom N (change e he M) := + (changeHom e he (homOfEq hM.symm)).comp + ((changeUnitInvHom e he hA hB).comp (homOfEq hN)) + + def changeTopProjection : Hom (change e he M) N := + (homOfEq hN.symm).comp + ((changeUnitHom e he hA hB).comp (changeHom e he (homOfEq hM))) + + theorem changeTop_split (n : N) : + (changeTopProjection e he hM hN).map ((changeTopInclusion e he hM hN).map n)=n := by + subst M + subst N + change (changeUnitHom e he hA hB).map ((changeUnitInvHom e he hA hB).map n)=n + exact changeUnitHom_inv e he hA hB n + +end +end KLInvariance.Graded.ModuleData + +namespace KLInvariance.MomentGraph.BoundarySheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A B : Type ua} [CommRing A] [CommRing B] + [Algebra k A] [Algebra k B] + {𝓐 : ℤ → Submodule k A} {𝓑 : ℤ → Submodule k B} + [DirectSum.Decomposition 𝓐] [SetLike.GradedMonoid 𝓐] + [DirectSum.Decomposition 𝓑] [SetLike.GradedMonoid 𝓑] + [IsDomain A] [IsDomain B] [IsNoetherianRing B] + (e : A ≃ₐ[k] B) (he : ∀ n a, a∈𝓐 n ↔ e a∈𝓑 n) + {hA : ∀ n<0,𝓐 n=⊥} {hB : ∀ n<0,𝓑 n=⊥} + {V E : Type um} [PartialOrder V] [Fintype V] [Fintype E] + {G : OrderedGraph V E} {α : E → A} {b : V} + (S : BoundarySheaf hA G α b) (T : BoundarySheaf hB G (fun q => e (α q)) b) +noncomputable section + + theorem iso_coefficientChange + (hzero : ∀ a ∈ 𝓑 0, ∃ c : k, algebraMap k B c=a) + (hb : ∀ x, x≤b) : Nonempty + (GradedSheaf.Iso T.sheaf (GradedSheaf.coefficientChange e he S.sheaf)) := by + exact T.iso_of_primitive_top_split hzero hb (GradedSheaf.coefficientChange e he S.sheaf) + (GradedSheaf.coefficientChange_upperQuotient e he S.sheaf α S.quotient) + (GradedSheaf.coefficientChange_free e he S.sheaf S.free) + (GradedSheaf.coefficientChange_flabby e he S.sheaf S.flabby.flabby) + (GradedSheaf.coefficientChange_generated e he S.sheaf S.generated) + (GradedSheaf.coefficientChange_primitive e he S.sheaf S.primitive_identity) + (ModuleData.changeTopInclusion e he S.top T.top) + (ModuleData.changeTopProjection e he S.top T.top) + (ModuleData.changeTop_split e he S.top T.top) + +end +end KLInvariance.MomentGraph.BoundarySheaf + +end + + +section + + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem boundarySheaf_perfectPairing : + Nonempty (GradedSheaf.PerfectPairing + (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf (cs.length b : ℤ)) := by + classical + let := interval_finite cs 1 b + let := Fintype.ofFinite (Interval cs 1 b) + let := Fintype.ofFinite (Edge cs 1 b) + let S := symmetricBoundarySheaf cs basis b + let T := boundarySheaf cs 1 b basis (one_bruhat cs b) + let e := SymmetricAlgebra.equivMvPolynomial basis + have he : ∀ n a, a∈symmetricGrading basis n ↔ e a∈polynomialGrading ℝ σ n := + mem_symmetricGrading basis + obtain ⟨p⟩ := symmetricBoundarySheaf_perfectPairing cs basis b + obtain ⟨j⟩ := BoundarySheaf.iso_coefficientChange e he S T + (polynomialGrading_zero ℝ σ) (fun x => x.property.2) + exact ⟨(p.coefficientChange e he).pullback j⟩ + + variable [Fintype (Edge cs 1 b)] [Fintype (Interval cs 1 b)] [DecidableEq (Interval cs 1 b)] + + theorem sectionDualityObligation : SectionDualityObligation cs b basis := by + obtain ⟨p⟩ := boundarySheaf_perfectPairing cs b basis + exact sectionDualityObligation_of_perfectPairing cs b basis p + +end +end KLInvariance.BruhatGraph + +end + + +section + + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + +local instance finiteInterval : Fintype (Interval cs 1 b) := by + let := interval_finite cs 1 b + exact Fintype.ofFinite _ +local instance finiteEdges : Fintype (Edge cs 1 b) := Fintype.ofFinite _ +local instance (a : Type*) : DecidableEq a := Classical.decEq a + + def boundaryFreeSheaf : FreeSheaf cs 1 b basis where + sheaf := (boundarySheaf cs 1 b basis (one_bruhat cs b)).sheaf + free := (boundarySheaf cs 1 b basis (one_bruhat cs b)).free + quotient := (boundarySheaf cs 1 b basis (one_bruhat cs b)).quotient + generated := (boundarySheaf cs 1 b basis (one_bruhat cs b)).generated + + def boundaryPerfectPairing : GradedSheaf.PerfectPairing + (boundaryFreeSheaf cs b basis).sheaf (cs.length b : ℤ) := + (boundarySheaf_perfectPairing cs b basis).some + + def boundaryFreeDuality : FreeSheaf.SectionDuality cs 1 b basis (boundaryFreeSheaf cs b basis) := + FreeSheaf.dualityOfPairing cs 1 b basis _ (boundaryPerfectPairing cs b basis) + + theorem boundaryKernelFree (x : Interval cs 1 b) : + Module.Free (Coefficient (σ := σ)) + (GradedSheaf.kernelData (boundaryFreeSheaf cs b basis).sheaf x) := + FreeSheaf.kernel_free cs b basis _ (boundaryFreeDuality cs b basis) x + + def costalkCharacter (x : Interval cs 1 b) : Polynomial ℤ := + GradedSheaf.freeKernelChar (boundaryFreeSheaf cs b basis).sheaf (boundaryKernelFree cs b basis) x + + theorem costalkCharacter_reflect (x : Interval cs 1 b) : + costalkCharacter cs b basis x=Polynomial.reflect (rankDifference cs x.val b) + (stalkCharacter cs 1 b basis (one_bruhat cs b) x) := by + apply FreeSheaf.kernel_character cs b basis _ (boundaryFreeDuality cs b basis) (cs.length b) _ le_rfl x + intro i j m a hm ha + exact (boundaryPerfectPairing cs b basis).homogeneous i j m a + (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x)) + + theorem stalkBasis_degree_le (x : Interval cs 1 b) + (c : NonnegativeBasis (σ := σ) + ((boundaryFreeSheaf cs b basis).sheaf.vertex x).piece) (i : c.index) : + c.degree i≤rankDifference cs x.val b := by + apply ModuleData.degree_le_of_dual_equiv _ _ + (FreeSheaf.kernelDual cs b basis _ (boundaryFreeDuality cs b basis) x) + (rankDifference cs x.val b) _ c i + exact FreeSheaf.kernelDual_homogeneous cs b basis _ (boundaryFreeDuality cs b basis) + (cs.length b) (fun i j m a hm ha => (boundaryPerfectPairing cs b basis).homogeneous i j m a + (fun x => hm x (Set.mem_univ x)) (fun x => ha x (Set.mem_univ x))) + x (length_le_of_bruhat cs x.property.2) + +end +end KLInvariance.BruhatGraph + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded +universe uk ua um +variable {k : Type uk} [Field k] {A : Type ua} [CommRing A] [Algebra k A] + [IsNoetherianRing A] {𝓐 : ℤ → Submodule k A} + {V E W F : Type um} [PartialOrder V] [PartialOrder W] + {G : OrderedGraph V E} {H : OrderedGraph W F} +noncomputable section +attribute [local instance] Classical.propDecidable +variable {K : Set V} {hK : IsLowerSet K} + +omit [IsNoetherianRing A] in + theorem lowerExtend_kernel_iff (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) + (x : K) (m : B.lowerExtend.vertex x.val) : + m∈B.lowerExtend.upwardSubmodule x.val Set.univ ↔ + B.lowerExtendVertex x m∈B.upwardSubmodule x Set.univ := by + constructor + · intro hm e _ + rcases e with ⟨⟨e,he⟩,hx⟩ + cases hx + have hh := hm ⟨e,rfl⟩ (Set.mem_univ _) + exact congrFun hh ⟨⟨he⟩⟩ + · intro hm e _ + rcases x with ⟨x,hx⟩ + rcases e with ⟨e,he⟩ + change G.source e=x at he + subst x + apply funext + intro h + have hh := hm ⟨⟨e,h.down.down⟩,rfl⟩ (Set.mem_univ _) + exact hh + + def lowerExtendKernelEquiv (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) + (x : K) : kernelData B.lowerExtend x.val ≃ₗ[A] kernelData B x where + toFun m := ⟨B.lowerExtendVertex x m.val,(lowerExtend_kernel_iff B x m.val).mp m.property⟩ + invFun m := ⟨(B.lowerExtendVertex x).symm m.val,(lowerExtend_kernel_iff B x _).mpr (by + simpa only [LinearEquiv.apply_symm_apply] using m.property)⟩ + left_inv m := Subtype.ext ((B.lowerExtendVertex x).symm_apply_apply m.val) + right_inv m := Subtype.ext ((B.lowerExtendVertex x).apply_symm_apply m.val) + map_add' m n := Subtype.ext (map_add (B.lowerExtendVertex x) m.val n.val) + map_smul' a m := Subtype.ext (map_smul (B.lowerExtendVertex x) a m.val) + + theorem lowerExtendKernelEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) (lowerGraph G K hK)) + (x : K) (n : ℤ) (m : kernelData B.lowerExtend x.val) + (hm : m∈(kernelData B.lowerExtend x.val).piece n) : + B.lowerExtendKernelEquiv x m∈(kernelData B x).piece n := + B.lowerExtendVertex_graded x n m.val hm + +omit [IsNoetherianRing A] in + theorem fullKernel_pullback (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) + (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) : + (B.pullback f).upwardSubmodule x Set.univ=B.upwardSubmodule (f.vertex x) Set.univ := by + exact B.forget.pullback_kernel f x Set.univ Set.univ + (fun e he => (he (Set.mem_univ e)).elim) (fun e _ he => hlift e x he) + + def pullbackKernelEquiv (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) + (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) : + kernelData (B.pullback f) x ≃ₗ[A] kernelData B (f.vertex x) where + toFun m := ⟨m.val,fullKernel_pullback B f hlift x ▸ m.property⟩ + invFun m := ⟨m.val,(fullKernel_pullback B f hlift x).symm ▸ m.property⟩ + left_inv _ := rfl + right_inv _ := rfl + map_add' _ _ := rfl + map_smul' _ _ := rfl + + theorem pullbackKernelEquiv_graded (B : GradedSheaf (𝓐 := 𝓐) H) (f : GraphMap G H) + (hlift : ∀ e x, f.vertex x=H.source e → ∃ a, f.edge a=e ∧ G.source a=x) (x : V) + (n : ℤ) (m : kernelData (B.pullback f) x) (hm : m∈(kernelData (B.pullback f) x).piece n) : + B.pullbackKernelEquiv f hlift x m∈(kernelData B (f.vertex x)).piece n := hm + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section +local instance (p : Prop) : Decidable p := Classical.propDecidable p + + def lowerKernelEquiv (c x : Interval cs 1 b) (hx : x≤c) : + GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x ≃ₗ[Coefficient (σ := σ)] + GradedSheaf.kernelData (boundaryFreeSheaf cs c.val basis).sheaf ⟨x.val,x.property.1,hx⟩ := + ((lowerIntervalBoundary cs b basis c).sheaf.lowerExtendKernelEquiv ⟨x,hx⟩).trans + ((boundaryFreeSheaf cs c.val basis).sheaf.pullbackKernelEquiv + (lowerIntervalMap cs b c) (lowerIntervalMap_outgoing cs b c) ⟨x,hx⟩) + + theorem lowerKernelEquiv_graded (c x : Interval cs 1 b) (hx : x≤c) + (n : ℤ) (v : GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) + (hv : v∈(GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x).piece n) : + lowerKernelEquiv cs b basis c x hx v∈(GradedSheaf.kernelData + (boundaryFreeSheaf cs c.val basis).sheaf ⟨x.val,x.property.1,hx⟩).piece n := + (lowerIntervalBoundary cs b basis c).sheaf.lowerExtendKernelEquiv_graded ⟨x,hx⟩ n v hv + + theorem boundaryModels_kernelFree (c x : Interval cs 1 b) : + Module.Free (Coefficient (σ := σ)) + (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := by + by_cases hx : x≤c + · let := boundaryKernelFree cs c.val basis ⟨x.val,x.property.1,hx⟩ + exact Module.Free.of_equiv (lowerKernelEquiv cs b basis c x hx).symm + · let := (boundaryModels cs b basis).support c x hx + let : Subsingleton (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := + ⟨fun v w => Subtype.ext (Subsingleton.elim _ _)⟩ + infer_instance + + theorem boundaryModels_kernelCharacter (c x : Interval cs 1 b) : + GradedSheaf.freeKernelChar ((boundaryModels cs b basis).sheaf c) + (boundaryModels_kernelFree cs b basis c) x= + Polynomial.reflect (rankDifference cs x.val c.val) (lowerCharacter cs b basis c x) := by + let := boundaryModels_kernelFree cs b basis c x + by_cases hx : x≤c + · rw [lowerCharacter,dite_eq_left hx,← costalkCharacter_reflect cs c.val basis ⟨x.val,x.property.1,hx⟩] + let := boundaryKernelFree cs c.val basis ⟨x.val,x.property.1,hx⟩ + exact ModuleData.character_eq_of_gradedEquiv (lowerKernelEquiv cs b basis c x hx) + (lowerKernelEquiv_graded cs b basis c x hx) + · rw [lowerCharacter,dite_eq_right hx,Polynomial.reflect_zero] + let := (boundaryModels cs b basis).support c x hx + let : Subsingleton (GradedSheaf.kernelData ((boundaryModels cs b basis).sheaf c) x) := + ⟨fun v w => Subtype.ext (Subsingleton.elim _ _)⟩ + exact ModuleData.char_zero _ + +end +end KLInvariance.BruhatGraph + +end + + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded Polynomial +universe uk us um +variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + + theorem exists_character_decomposition [Fintype V] [Fintype E] + {α : E → MvPolynomial σ k} + (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) + (hk : ∀ y x, Module.Free (MvPolynomial σ k) (kernelData (O.sheaf y) x)) + (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) + (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) + (hkb : ∀ x, Module.Free (MvPolynomial σ k) (kernelData B x)) + (hq : B.UpperQuotient α) (hfl : B.forget.Flabby) (hg : B.forget.Generated) : + ∃ m : V → Polynomial ℤ, (∀ y n, 0≤(m y).coeff n) ∧ + (∀ x, freeStalkChar B hf x = + ∑ y, m y*freeStalkChar (O.sheaf y) (O.free y) x) ∧ + (∀ x, freeKernelChar B hkb x = + ∑ y, m y*freeKernelChar (O.sheaf y) (hk y) x) := by + obtain ⟨C,hC,⟨j⟩⟩ := exists_modelSumIso (polynomialGrading_zero k σ) O B hf hq hfl hg + obtain ⟨m,hm,heq,hkeq⟩ := hC.character_both O hk + refine ⟨m,hm,fun x => ?_,fun x => ?_⟩ + · rw [← heq x] + let _ := hf x + let _ := hC.free O x + exact ModuleData.character_eq_of_gradedEquiv (j.vertex x) (j.vertex_graded x) + · rw [← hkeq x] + let _ := hkb x + let _ := hC.kernelFree hk x + exact ModuleData.character_eq_of_gradedEquiv (j.kernelEquiv x) (j.kernelEquiv_graded x) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.TitsSpace +open Module _root_.OAI.KLInvariance.Graded MomentGraph BruhatGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem bottCharacter_decomposition_both (l : List I) (hl : cs.IsReduced l) + [Fintype (Interval cs 1 (cs.wordProd l))] : + ∃ m : Interval cs 1 (cs.wordProd l) → Polynomial ℤ, + (∀ y n, 0≤(m y).coeff n) ∧ + (∀ x, bottStalkCharacter cs basis l x.val= + ∑ y, m y*lowerCharacter cs (cs.wordProd l) basis y x) ∧ + (∀ x, GradedSheaf.freeKernelChar (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) + (bottKernelFree cs basis l hl) x= + ∑ y, m y*Polynomial.reflect (rankDifference cs x.val y.val) + (lowerCharacter cs (cs.wordProd l) basis y x)) := by + classical + let := Fintype.ofFinite (Edge cs 1 (cs.wordProd l)) + obtain ⟨m,hm,he,hk⟩ := GradedSheaf.exists_character_decomposition + (boundaryModels cs (cs.wordProd l) basis) (boundaryModels_kernelFree cs (cs.wordProd l) basis) + (bottPolynomialSheaf cs basis l 1 (cs.wordProd l)) + (bottPolynomialSheaf_free cs basis l 1 (cs.wordProd l)) (bottKernelFree cs basis l hl) + (bottPolynomialSheaf_quotient cs basis l 1 (cs.wordProd l)) + (bottPolynomialSheaf_flabby cs basis l hl) (bottPolynomialSheaf_generated cs basis l 1 (cs.wordProd l)) + refine ⟨m,hm,fun x => ?_,fun x => ?_⟩ + · simpa only [bottPolynomialSheaf_character,boundaryModels_character] using he x + · simpa only [boundaryModels_kernelCharacter] using hk x + +end +end KLInvariance.TitsSpace + +end + + +section + +namespace KLInvariance.Graded.ModuleData +open Polynomial Module +universe uk us um +variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] +noncomputable section + + def unitPolynomialBasis : NonnegativeBasis (σ := σ) + (unit.{uk,max uk us,um} (polynomialGrading_negative k σ)).piece where + index := PUnit.{max uk us um + 1} + finite := inferInstance + basis := Pi.basisFun (MvPolynomial σ k) _ + degree _ := 0 + homogeneous i := by + intro j + change (Pi.basisFun (MvPolynomial σ k) _ i) j ∈ polynomialGrading k σ (0-0) + cases i + cases j + simpa using SetLike.one_mem_graded (polynomialGrading k σ) + + theorem char_unit : + (unit.{uk,max uk us,um} (polynomialGrading_negative k σ)).char=1 := by + rw [char,character_eq _ _ (unitPolynomialBasis (k := k) (σ := σ))] + change (∑ i : PUnit.{max uk us um + 1}, (X : Polynomial ℤ)^0)=1 + simp + +end +end KLInvariance.Graded.ModuleData + +end + + +section + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section +local instance (p : Prop) : Decidable p := Classical.propDecidable p + + theorem stalkCharacter_top : + stalkCharacter cs 1 b basis (one_bruhat cs b) ⟨b,one_bruhat cs b,bruhat_refl cs b⟩=1 := by + let B := boundarySheaf cs 1 b basis (one_bruhat cs b) + let := B.free ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ + change (B.sheaf.vertex ⟨b,one_bruhat cs b,bruhat_refl cs b⟩).char=1 + exact (ModuleData.character_eq_of_gradedEquiv (ModuleData.equivOfEq B.top) + (ModuleData.equivOfEq_graded B.top)).trans ModuleData.char_unit + + theorem lowerCharacter_diagonal (c : Interval cs 1 b) : lowerCharacter cs b basis c c=1 := by + rw [lowerCharacter,dite_eq_left le_rfl] + exact stalkCharacter_top cs c.val basis + + theorem lowerCharacter_at_top (c : Interval cs 1 b) : + lowerCharacter cs b basis c ⟨b,one_bruhat cs b,bruhat_refl cs b⟩= + if c.val=b then 1 else 0 := by + by_cases hc : c.val=b + · have he : c=⟨b,one_bruhat cs b,bruhat_refl cs b⟩ := Subtype.ext hc + rw [ite_eq_left hc,←he,lowerCharacter_diagonal] + · rw [ite_eq_right hc] + apply lowerCharacter_zero + intro h + exact hc (bruhat_antisymm cs c.property.2 h) + +end +end KLInvariance.BruhatGraph + +end + + +section + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section +local instance (p : Prop) : Decidable p := Classical.propDecidable p +local instance lowerConvInterval (c : W) : Fintype (Interval cs 1 c) := by + let := interval_finite cs 1 c + exact Fintype.ofFinite _ + + def lowerIntervalEquiv (c : Interval cs 1 b) : Set.Iic c ≃ Interval cs 1 c.val where + toFun := (lowerIntervalMap cs b c).vertex + invFun z := ⟨⟨z.val,z.property.1,bruhat_trans cs z.property.2 c.property.2⟩,z.property.2⟩ + left_inv _ := rfl + right_inv _ := rfl + + theorem lowerCharacter_convolution (c x : Interval cs 1 b) : + (∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z)= + ∑ z : Interval cs 1 c.val, OrdinaryR.polynomial cs x.val z.val* + stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z := by + classical + let f (z : Interval cs 1 b) := OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z + have hf : ∀ z : Interval cs 1 b, ¬z≤c → f z=0 := by + intro z hz + simp only [f,lowerCharacter_zero cs b basis c z hz,mul_zero] + have he : (∑ z : Interval cs 1 b, f z) = ∑ z ∈ Finset.univ.filter (fun z => z≤c), f z := by + symm + apply Finset.sum_subset (Finset.filter_subset _ _) + intro z _ hz + exact hf z (by simpa using hz) + change (∑ z, f z)=_ + rw [he,Finset.sum_subtype (p := fun z : Interval cs 1 b => z≤c) _ (by simp)] + calc + _ = ∑ z : Set.Iic c, OrdinaryR.polynomial cs x.val z.val.val* + stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) ((lowerIntervalEquiv cs b c) z) := by + apply Finset.sum_congr rfl + intro z _ + simp only [f,lowerCharacter,dite_eq_left z.property] + rfl + _ = _ := Equiv.sum_comp (lowerIntervalEquiv cs b c) (fun z => OrdinaryR.polynomial cs x.val z.val* + stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z) + + theorem lowerCharacter_convolution_zero (c x : Interval cs 1 b) (hx : ¬x≤c) : + (∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z)=0 := by + apply Finset.sum_eq_zero + intro z _ + by_cases hz : z≤c + · rw [OrdinaryR.polynomial_zero cs x.val z.val (fun h => hx (bruhat_trans cs h hz)),zero_mul] + · rw [lowerCharacter_zero cs b basis c z hz,mul_zero] + + theorem lowerCharacter_reciprocity_lift (c : Interval cs 1 b) + (h : ∀ x : Interval cs 1 c.val, + reflect (rankDifference cs x.val c.val) (stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) x)= + ∑ z : Interval cs 1 c.val, OrdinaryR.polynomial cs x.val z.val* + stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) z) + (x : Interval cs 1 b) : + reflect (rankDifference cs x.val c.val) (lowerCharacter cs b basis c x)= + ∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val*lowerCharacter cs b basis c z := by + by_cases hx : x≤c + · rw [lowerCharacter_convolution,lowerCharacter,dite_eq_left hx] + exact h ⟨x.val,x.property.1,hx⟩ + · rw [lowerCharacter_zero cs b basis c x hx,reflect_zero,lowerCharacter_convolution_zero cs b basis c x hx] + +end +end KLInvariance.BruhatGraph + +end + + +section + +/-! Finite unipotent character cancellation. The transition data is actually +constructed for word/BMP sheaves; this lemma assumes only the displayed +linear identities and cannot supply the KL degree bound. -/ + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/Comparison.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/Comparison.lean index 850ffe6d19b5bee99dec3cdee4122485ee14a6f0..37eb39d0f0e9033a1e7d978138a1edbc77208c20 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/Comparison.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/Comparison.lean @@ -1,149 +1,149 @@ -import Mathlib - -namespace OAI - -/-! -Reciprocal low-degree rigidity and positive elementary sheaf-transfer inequalities. --/ - -section - - -/-! The closing algebra of the admitted main proof, source §6. These are -necessary dependencies, not a substitute (conditional or special-case) main -invariance theorem. The sheaf edge-image comparison is NOT assumed as an -instance or asserted here. -/ - -namespace KLInvariance.Comparison - -open Polynomial - -/-- A polynomial supported strictly below the middle cannot equal its -reciprocal on an open real interval. This discharges the final rigidity -step after the source's two comparison inequalities have been combined. -/ -theorem low_degree_zero_of_eval_reciprocal (p : ℝ[X]) (d : ℕ) - (hp : 2 * p.natDegree < d) - (h : ∀ q : ℝ, 0 < q → q < 1 → p.eval q = q ^ d * p.eval q⁻¹) : p = 0 := by - have heq : p = reflect d p := by - apply p.eq_of_infinite_eval_eq - apply (Set.Ioo_infinite (show (0 : ℝ) < 1 by norm_num)).mono - intro q hq - change p.eval q = (reflect d p).eval q - let : Invertible q⁻¹ := invertibleOfNonzero (inv_ne_zero (ne_of_gt hq.1)) - have hr := eval₂_reflect_mul_pow (RingHom.id ℝ) q⁻¹ d p (by omega) - simp only [eval₂_id, invOf_eq_inv, inv_inv] at hr - have hr' := congrArg (fun z : ℝ => z * q ^ d) hr - have hq0 : q ≠ 0 := ne_of_gt hq.1 - simp only [mul_assoc, ← mul_pow, inv_mul_cancel₀ hq0, one_pow, mul_one] at hr' - calc - p.eval q = q ^ d * p.eval q⁻¹ := h q hq.1 hq.2 - _ = (reflect d p).eval q := by - simpa only [mul_comm] using hr'.symm - by_contra hp0 - have hc := congrArg (fun f : ℝ[X] => f.coeff p.natDegree) heq.symm - rw [coeff_reflect, revAt_le (by omega), coeff_eq_zero_of_natDegree_lt (by omega), - coeff_natDegree] at hc - exact (leadingCoeff_ne_zero.mpr hp0) hc.symm - -/-- The exact polynomial conclusion from reciprocal difference equality, -without assuming positivity of KL coefficients. -/ -theorem eq_of_eval_difference_reciprocal (p p' : ℤ[X]) (d : ℕ) - (hp : 2 * p.natDegree < d) (hp' : 2 * p'.natDegree < d) - (h : ∀ q : ℝ, 0 < q → q < 1 → - p.eval₂ (Int.castRingHom ℝ) q - p'.eval₂ (Int.castRingHom ℝ) q = - q ^ d * (p.eval₂ (Int.castRingHom ℝ) q⁻¹ - - p'.eval₂ (Int.castRingHom ℝ) q⁻¹)) : p = p' := by - apply sub_eq_zero.mp - apply Polynomial.map_injective (f := Int.castRingHom ℝ) Int.cast_injective - rw [Polynomial.map_zero] - apply low_degree_zero_of_eval_reciprocal ((p - p').map (Int.castRingHom ℝ)) d - · have hdeg := Polynomial.natDegree_map_le (f := Int.castRingHom ℝ) (p := p - p') - have hsub := Polynomial.natDegree_sub_le p p' - omega - · intro q hq hq' - simpa only [eval_map, eval₂_sub] using h q hq hq' - -section Schedule - -variable {V : Type*} - -noncomputable local instance : DecidableEq V := Classical.decEq V - -/-- The genuine elementary transfer `id + T E_xy` from the source's edge -schedule, expressed on vectors rather than with a choice of enumeration. -/ -noncomputable def transfer (T : ℝ) (x y : V) (v : V → ℝ) : V → ℝ := - fun z => v z + if z = x then T * v y else 0 - -theorem transfer_monotone (T : ℝ) (hT : 0 ≤ T) (x y : V) : - Monotone (transfer T x y) := by - intro v w hv z - dsimp [transfer] - split_ifs - · exact add_le_add (hv z) (mul_le_mul_of_nonneg_left (hv y) hT) - · simpa using hv z - -theorem transfer_injective (T : ℝ) (x y : V) (hxy : x ≠ y) : - Function.Injective (transfer T x y) := by - intro v w h - have hy := congrFun h y - simp only [transfer, Ne.symm hxy, ite_false, add_zero] at hy - funext z - have hz := congrFun h z - dsimp [transfer] at hz - split_ifs at hz with hz' - · rw [hy] at hz - exact add_right_cancel hz - · exact add_right_cancel hz - -noncomputable def idealState (T : ℝ) (edges : ℕ → V × V) (initial : V → ℝ) : - ℕ → V → ℝ - | 0 => initial - | n + 1 => transfer T (edges n).1 (edges n).2 (idealState T edges initial n) - -/-- Propagation of the actual Hilbert-series bound through all earlier edges. -No freeness or positivity of the *vectors* is needed for this part. -/ -theorem state_le_ideal (T : ℝ) (hT : 0 ≤ T) (edges : ℕ → V × V) - (D : ℕ → V → ℝ) (n : ℕ) - (hstep : ∀ k < n, D (k + 1) ≤ transfer T (edges k).1 (edges k).2 (D k)) : - D n ≤ idealState T edges (D 0) n := by - induction n with - | zero => exact le_rfl - | succ n ih => - exact (hstep n (Nat.lt_succ_self n)).trans - (transfer_monotone T hT _ _ (ih (fun k hk => hstep k (Nat.lt_succ_of_lt hk)))) - -/-- Endpoint equality forces every edge-image deficit to vanish, including -those invisible in codimension one. This uses actual inequalities and the -injectivity of elementary edge transfers; it does not assume image equality. -It is the no-deficit conclusion of source (6.8). -/ -theorem every_step_eq_of_endpoint_eq (T : ℝ) (hT : 0 ≤ T) - (edges : ℕ → V × V) (D : ℕ → V → ℝ) (n : ℕ) - (hedges : ∀ k < n, (edges k).1 ≠ (edges k).2) - (hstep : ∀ k < n, D (k + 1) ≤ transfer T (edges k).1 (edges k).2 (D k)) - (hend : D n = idealState T edges (D 0) n) : - ∀ k < n, D (k + 1) = transfer T (edges k).1 (edges k).2 (D k) := by - induction n with - | zero => omega - | succ n ih => - have hD : D n ≤ idealState T edges (D 0) n := - state_le_ideal T hT edges D n (fun k hk => hstep k (Nat.lt_succ_of_lt hk)) - have ht := transfer_monotone T hT (edges n).1 (edges n).2 hD - have hlast : D (n + 1) = transfer T (edges n).1 (edges n).2 (D n) := by - apply le_antisymm (hstep n (Nat.lt_succ_self n)) - exact ht.trans_eq hend.symm - have heqn : D n = idealState T edges (D 0) n := by - apply transfer_injective T (edges n).1 (edges n).2 - (hedges n (Nat.lt_succ_self n)) - exact hlast.symm.trans hend - intro k hk - rcases Nat.lt_succ_iff_lt_or_eq.mp hk with hk | rfl - · exact ih (fun j hj => hedges j (Nat.lt_succ_of_lt hj)) - (fun j hj => hstep j (Nat.lt_succ_of_lt hj)) heqn k hk - · exact hlast - -end Schedule -end KLInvariance.Comparison - -end - -end OAI +import Mathlib + +namespace OAI + +/-! +Reciprocal low-degree rigidity and positive elementary sheaf-transfer inequalities. +-/ + +section + + +/-! The closing algebra of the admitted main proof, source §6. These are +necessary dependencies, not a substitute (conditional or special-case) main +invariance theorem. The sheaf edge-image comparison is NOT assumed as an +instance or asserted here. -/ + +namespace KLInvariance.Comparison + +open Polynomial + +/-- A polynomial supported strictly below the middle cannot equal its +reciprocal on an open real interval. This discharges the final rigidity +step after the source's two comparison inequalities have been combined. -/ +theorem low_degree_zero_of_eval_reciprocal (p : ℝ[X]) (d : ℕ) + (hp : 2 * p.natDegree < d) + (h : ∀ q : ℝ, 0 < q → q < 1 → p.eval q = q ^ d * p.eval q⁻¹) : p = 0 := by + have heq : p = reflect d p := by + apply p.eq_of_infinite_eval_eq + apply (Set.Ioo_infinite (show (0 : ℝ) < 1 by norm_num)).mono + intro q hq + change p.eval q = (reflect d p).eval q + let : Invertible q⁻¹ := invertibleOfNonzero (inv_ne_zero (ne_of_gt hq.1)) + have hr := eval₂_reflect_mul_pow (RingHom.id ℝ) q⁻¹ d p (by omega) + simp only [eval₂_id, invOf_eq_inv, inv_inv] at hr + have hr' := congrArg (fun z : ℝ => z * q ^ d) hr + have hq0 : q ≠ 0 := ne_of_gt hq.1 + simp only [mul_assoc, ← mul_pow, inv_mul_cancel₀ hq0, one_pow, mul_one] at hr' + calc + p.eval q = q ^ d * p.eval q⁻¹ := h q hq.1 hq.2 + _ = (reflect d p).eval q := by + simpa only [mul_comm] using hr'.symm + by_contra hp0 + have hc := congrArg (fun f : ℝ[X] => f.coeff p.natDegree) heq.symm + rw [coeff_reflect, revAt_le (by omega), coeff_eq_zero_of_natDegree_lt (by omega), + coeff_natDegree] at hc + exact (leadingCoeff_ne_zero.mpr hp0) hc.symm + +/-- The exact polynomial conclusion from reciprocal difference equality, +without assuming positivity of KL coefficients. -/ +theorem eq_of_eval_difference_reciprocal (p p' : ℤ[X]) (d : ℕ) + (hp : 2 * p.natDegree < d) (hp' : 2 * p'.natDegree < d) + (h : ∀ q : ℝ, 0 < q → q < 1 → + p.eval₂ (Int.castRingHom ℝ) q - p'.eval₂ (Int.castRingHom ℝ) q = + q ^ d * (p.eval₂ (Int.castRingHom ℝ) q⁻¹ - + p'.eval₂ (Int.castRingHom ℝ) q⁻¹)) : p = p' := by + apply sub_eq_zero.mp + apply Polynomial.map_injective (f := Int.castRingHom ℝ) Int.cast_injective + rw [Polynomial.map_zero] + apply low_degree_zero_of_eval_reciprocal ((p - p').map (Int.castRingHom ℝ)) d + · have hdeg := Polynomial.natDegree_map_le (f := Int.castRingHom ℝ) (p := p - p') + have hsub := Polynomial.natDegree_sub_le p p' + omega + · intro q hq hq' + simpa only [eval_map, eval₂_sub] using h q hq hq' + +section Schedule + +variable {V : Type*} + +noncomputable local instance : DecidableEq V := Classical.decEq V + +/-- The genuine elementary transfer `id + T E_xy` from the source's edge +schedule, expressed on vectors rather than with a choice of enumeration. -/ +noncomputable def transfer (T : ℝ) (x y : V) (v : V → ℝ) : V → ℝ := + fun z => v z + if z = x then T * v y else 0 + +theorem transfer_monotone (T : ℝ) (hT : 0 ≤ T) (x y : V) : + Monotone (transfer T x y) := by + intro v w hv z + dsimp [transfer] + split_ifs + · exact add_le_add (hv z) (mul_le_mul_of_nonneg_left (hv y) hT) + · simpa using hv z + +theorem transfer_injective (T : ℝ) (x y : V) (hxy : x ≠ y) : + Function.Injective (transfer T x y) := by + intro v w h + have hy := congrFun h y + simp only [transfer, Ne.symm hxy, ite_false, add_zero] at hy + funext z + have hz := congrFun h z + dsimp [transfer] at hz + split_ifs at hz with hz' + · rw [hy] at hz + exact add_right_cancel hz + · exact add_right_cancel hz + +noncomputable def idealState (T : ℝ) (edges : ℕ → V × V) (initial : V → ℝ) : + ℕ → V → ℝ + | 0 => initial + | n + 1 => transfer T (edges n).1 (edges n).2 (idealState T edges initial n) + +/-- Propagation of the actual Hilbert-series bound through all earlier edges. +No freeness or positivity of the *vectors* is needed for this part. -/ +theorem state_le_ideal (T : ℝ) (hT : 0 ≤ T) (edges : ℕ → V × V) + (D : ℕ → V → ℝ) (n : ℕ) + (hstep : ∀ k < n, D (k + 1) ≤ transfer T (edges k).1 (edges k).2 (D k)) : + D n ≤ idealState T edges (D 0) n := by + induction n with + | zero => exact le_rfl + | succ n ih => + exact (hstep n (Nat.lt_succ_self n)).trans + (transfer_monotone T hT _ _ (ih (fun k hk => hstep k (Nat.lt_succ_of_lt hk)))) + +/-- Endpoint equality forces every edge-image deficit to vanish, including +those invisible in codimension one. This uses actual inequalities and the +injectivity of elementary edge transfers; it does not assume image equality. +It is the no-deficit conclusion of source (6.8). -/ +theorem every_step_eq_of_endpoint_eq (T : ℝ) (hT : 0 ≤ T) + (edges : ℕ → V × V) (D : ℕ → V → ℝ) (n : ℕ) + (hedges : ∀ k < n, (edges k).1 ≠ (edges k).2) + (hstep : ∀ k < n, D (k + 1) ≤ transfer T (edges k).1 (edges k).2 (D k)) + (hend : D n = idealState T edges (D 0) n) : + ∀ k < n, D (k + 1) = transfer T (edges k).1 (edges k).2 (D k) := by + induction n with + | zero => omega + | succ n ih => + have hD : D n ≤ idealState T edges (D 0) n := + state_le_ideal T hT edges D n (fun k hk => hstep k (Nat.lt_succ_of_lt hk)) + have ht := transfer_monotone T hT (edges n).1 (edges n).2 hD + have hlast : D (n + 1) = transfer T (edges n).1 (edges n).2 (D n) := by + apply le_antisymm (hstep n (Nat.lt_succ_self n)) + exact ht.trans_eq hend.symm + have heqn : D n = idealState T edges (D 0) n := by + apply transfer_injective T (edges n).1 (edges n).2 + (hedges n (Nat.lt_succ_self n)) + exact hlast.symm.trans hend + intro k hk + rcases Nat.lt_succ_iff_lt_or_eq.mp hk with hk | rfl + · exact ih (fun j hj => hedges j (Nat.lt_succ_of_lt hj)) + (fun j hj => hstep j (Nat.lt_succ_of_lt hj)) heqn k hk + · exact hlast + +end Schedule +end KLInvariance.Comparison + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/Coxeter.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/Coxeter.lean index 329fcd62caccfb9830cb1ca8e7d368fb7d8f4a30..4c72d9fe50e00af5e3eec787e01d1798613d334c 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/Coxeter.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/Coxeter.lean @@ -1,242 +1,242 @@ -import Mathlib - -namespace OAI - -/-! -Signed reflection permutations and strong exchange for arbitrary Coxeter systems. --/ - -section - - -namespace KLInvariance.CoxeterSupport - -open CoxeterSystem - -universe u v -variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} -variable (cs : CoxeterSystem M W) - -noncomputable local instance : DecidableEq W := Classical.decEq W - -noncomputable def simpleAction (i : B) : Equiv.Perm (W × ZMod 2) := by - classical - let f : W × ZMod 2 → W × ZMod 2 := fun p => - (cs.simple i * p.1 * cs.simple i, p.2 + if p.1 = cs.simple i then 1 else 0) - have hf : Function.Involutive f := by - rintro ⟨t, a⟩ - dsimp [f] - have heq : cs.simple i * t * cs.simple i = cs.simple i ↔ t = cs.simple i := by - constructor - · intro h - have := congrArg (fun z => cs.simple i * z * cs.simple i) h - simpa [mul_assoc] using this - · rintro rfl - simp - simp only [heq] - ext - · simp [mul_assoc] - · split_ifs - · simp only [add_assoc, ZModModule.add_self, add_zero] - · simp - exact ⟨f, f, hf, hf⟩ - -@[simp] theorem simpleAction_apply (i : B) (t : W) (a : ZMod 2) : - simpleAction cs i (t, a) = - (cs.simple i * t * cs.simple i, a + if t = cs.simple i then 1 else 0) := by - classical - rfl - -noncomputable def wordAction (ω : List B) : Equiv.Perm (W × ZMod 2) := - (ω.map (simpleAction cs)).prod - -@[simp] theorem wordAction_nil : wordAction cs [] = 1 := rfl - -theorem wordAction_concat (ω : List B) (i : B) : - wordAction cs (ω.concat i) = wordAction cs ω * simpleAction cs i := by - simp [wordAction] - -/-- Signed action records the parity of the genuine left inversion sequence. -/ -theorem wordAction_record (ω : List B) (t : W) (a : ZMod 2) : - wordAction cs ω ((cs.wordProd ω)⁻¹ * t * cs.wordProd ω, a) = - (t, a + ((cs.leftInvSeq ω).count t : ZMod 2)) := by - classical - induction ω using List.reverseRecOn generalizing a with - | nil => simp [wordAction] - | append_singleton ω i ih => - rw [← List.concat_eq_append, wordAction_concat, Equiv.Perm.mul_apply, - cs.wordProd_concat, mul_inv_rev, cs.inv_simple, simpleAction_apply] - have hc : cs.simple i * ((cs.simple i * (cs.wordProd ω)⁻¹) * t * - (cs.wordProd ω * cs.simple i)) * cs.simple i = - (cs.wordProd ω)⁻¹ * t * cs.wordProd ω := by - simp [mul_assoc] - rw [hc, ih] - rw [cs.leftInvSeq_concat] - have heq : (cs.simple i * (cs.wordProd ω)⁻¹) * t * - (cs.wordProd ω * cs.simple i) = cs.simple i ↔ - t = cs.wordProd ω * cs.simple i * (cs.wordProd ω)⁻¹ := by - constructor - · intro h - have := congrArg (fun z => cs.wordProd ω * cs.simple i * z * - cs.simple i * (cs.wordProd ω)⁻¹) h - simpa [mul_assoc] using this - · rintro rfl - simp [mul_assoc] - simp only [List.concat_eq_append, List.count_append, List.count_singleton, - Nat.cast_add, heq] - congr 1 - split_ifs <;> simp_all [add_comm, add_left_comm] - -/-- The presentation relation has a doubled inversion sequence, so its -signed action is trivial, including for no-relation entries `M i j = 0`. -/ -theorem leftInvSeq_alternating_formula (i j : B) (p : ℕ) : - cs.leftInvSeq (alternatingWord i j (2 * p)) = - (List.range (2 * p)).map (fun k => cs.simple i * (cs.simple j * cs.simple i) ^ k) := by - apply List.ext_getElem (by simp) - intro k hk hk' - have hk0 : k < 2 * p := by simpa using hk - rw [cs.getElem_leftInvSeq_alternatingWord i j p k hk0, - List.getElem_map, List.getElem_range] - rw [cs.prod_alternatingWord_eq_mul_pow] - simp only [Nat.not_even_iff_odd.mpr (show Odd (2 * k + 1) from ⟨k, rfl⟩), - ↓reduceIte] - congr 2 - omega - -theorem leftInvSeq_relation_doubled (i j : B) : - ∃ l : List W, cs.leftInvSeq (alternatingWord i j (2 * M i j)) = l ++ l := by - let f : ℕ → W := fun k => cs.simple i * (cs.simple j * cs.simple i) ^ k - refine ⟨(List.range (M i j)).map f, ?_⟩ - rw [leftInvSeq_alternating_formula, two_mul, List.range_add, List.map_append, List.map_map] - congr 1 - apply List.map_congr_left - intro k _ - dsimp [f] - rw [pow_add, cs.simple_mul_simple_pow'] - simp - -theorem wordAction_alternating (i j : B) (p : ℕ) : - wordAction cs (alternatingWord i j (2 * p)) = - (simpleAction cs i * simpleAction cs j) ^ p := by - induction p with - | zero => simp [alternatingWord] - | succ p ih => - rw [show 2 * (p + 1) = (2 * p + 1) + 1 by omega, - alternatingWord_succ', alternatingWord_succ'] - simp only [Nat.not_even_iff_odd.mpr (show Odd (2 * p + 1) from ⟨p, rfl⟩), - ↓reduceIte, even_two, Even.mul_right] - change simpleAction cs i * (simpleAction cs j * - wordAction cs (alternatingWord i j (2 * p))) = _ - rw [ih, ← mul_assoc, pow_succ'] - -theorem simpleAction_liftable : M.IsLiftable (simpleAction cs) := by - intro i j - rw [← wordAction_alternating] - apply Equiv.ext - rintro ⟨t, a⟩ - have h := wordAction_record cs (alternatingWord i j (2 * M i j)) t a - have hw : cs.wordProd (alternatingWord i j (2 * M i j)) = 1 := by - rw [cs.prod_alternatingWord_eq_mul_pow] - simp - obtain ⟨l, hl⟩ := leftInvSeq_relation_doubled cs i j - simpa [hw, hl, List.count_append, Nat.cast_add, ZModModule.add_self] using h - -noncomputable def reflectionAction : W →* Equiv.Perm (W × ZMod 2) := - cs.lift ⟨simpleAction cs, simpleAction_liftable cs⟩ - -@[simp] theorem reflectionAction_simple (i : B) : - reflectionAction cs (cs.simple i) = simpleAction cs i := - cs.lift_apply_simple (simpleAction_liftable cs) i - -theorem reflectionAction_wordProd (ω : List B) : - reflectionAction cs (cs.wordProd ω) = wordAction cs ω := by - induction ω with - | nil => simp - | cons i ω ih => - rw [cs.wordProd_cons, map_mul, reflectionAction_simple, ih] - rfl - -/-- The signed action is conjugation on labels and a translation on signs. -/ -theorem reflectionAction_translation (w t : W) : - ∃ δ : ZMod 2, ∀ a : ZMod 2, - reflectionAction cs w (t, a) = (w * t * w⁻¹, a + δ) := by - classical - obtain ⟨ω, rfl⟩ := cs.wordProd_surjective w - refine ⟨((cs.leftInvSeq ω).count (cs.wordProd ω * t * (cs.wordProd ω)⁻¹) : ZMod 2), ?_⟩ - intro a - rw [reflectionAction_wordProd] - have h := wordAction_record cs ω (cs.wordProd ω * t * (cs.wordProd ω)⁻¹) a - simpa [mul_assoc] using h - -/-- A reflection changes the sign of its own label. This is the critical -conjugation step making the representation yield *strong* exchange. -/ -theorem reflectionAction_reflection {t : W} (ht : cs.IsReflection t) (a : ZMod 2) : - reflectionAction cs t (t, a) = (t, a + 1) := by - obtain ⟨w, i, rfl⟩ := ht - obtain ⟨δ, hδ⟩ := reflectionAction_translation cs w⁻¹ - (w * cs.simple i * w⁻¹) - obtain ⟨ε, hε⟩ := reflectionAction_translation cs w (cs.simple i) - have hδ' (a : ZMod 2) : reflectionAction cs w⁻¹ - (w * cs.simple i * w⁻¹, a) = (cs.simple i, a + δ) := by - simpa [mul_assoc] using hδ a - have hz : δ + ε = 0 := by - have h := congrArg (fun p : W × ZMod 2 => p.2) - (Equiv.apply_symm_apply (reflectionAction cs w) (w * cs.simple i * w⁻¹, 0)) - change ((reflectionAction cs w) ((reflectionAction cs w)⁻¹ - (w * cs.simple i * w⁻¹, 0))).2 = 0 at h - rw [← map_inv, hδ', hε] at h - simpa using h - rw [map_mul, map_mul, reflectionAction_simple, Equiv.Perm.mul_apply, - Equiv.Perm.mul_apply, hδ', simpleAction_apply] - simp only [cs.simple_mul_simple_self, one_mul, ↓reduceIte] - rw [hε] - congr 1 - calc - (a + δ + 1) + ε = (a + 1) + (δ + ε) := by ring - _ = a + 1 := by rw [hz, add_zero] - - -theorem mem_leftInvSeq_of_inversion {ω : List B} (_hω : cs.IsReduced ω) - {t : W} (ht : cs.IsLeftInversion (cs.wordProd ω) t) : - t ∈ cs.leftInvSeq ω := by - classical - by_contra hnot - obtain ⟨ν, hν, heq⟩ := cs.exists_isReduced (t * cs.wordProd ω) - have hw := wordAction_record cs ω t (0 : ZMod 2) - rw [← reflectionAction_wordProd] at hw - simp only [List.count_eq_zero.mpr hnot, Nat.cast_zero, add_zero] at hw - have hv := wordAction_record cs ν t (0 : ZMod 2) - rw [← reflectionAction_wordProd, ← heq] at hv - have hin : (t * cs.wordProd ω)⁻¹ * t * (t * cs.wordProd ω) = - (cs.wordProd ω)⁻¹ * t * cs.wordProd ω := by - rw [mul_inv_rev, ht.1.inv] - simp [mul_assoc, ht.1.mul_self] - rw [hin, map_mul, Equiv.Perm.mul_apply, hw, - reflectionAction_reflection cs ht.1] at hv - have hmem : t ∈ cs.leftInvSeq ν := by - by_contra hnone - have h := congrArg Prod.snd hv - simp [List.count_eq_zero.mpr hnone] at h - have hlt := (cs.isLeftInversion_of_mem_leftInvSeq hν hmem).2 - rw [← heq] at hlt - have hcancel : t * (t * cs.wordProd ω) = cs.wordProd ω := by - rw [← mul_assoc, ht.1.mul_self, one_mul] - rw [hcancel] at hlt - exact (not_lt_of_ge hlt.le) ht.2 - -/-- Full strong exchange, with the deletion index in the supplied reduced word. -/ -theorem strong_exchange {ω : List B} (hω : cs.IsReduced ω) {t : W} - (ht : cs.IsLeftInversion (cs.wordProd ω) t) : - ∃ j : ℕ, j < ω.length ∧ t * cs.wordProd ω = cs.wordProd (ω.eraseIdx j) := by - obtain ⟨j, hj, heq⟩ := List.mem_iff_getElem.mp - (mem_leftInvSeq_of_inversion cs hω ht) - refine ⟨j, by simpa using hj, ?_⟩ - rw [← heq, ← List.getD_eq_getElem _ 1 hj] - exact cs.getD_leftInvSeq_mul_wordProd ω j - -end KLInvariance.CoxeterSupport - - -end - -end OAI +import Mathlib + +namespace OAI + +/-! +Signed reflection permutations and strong exchange for arbitrary Coxeter systems. +-/ + +section + + +namespace KLInvariance.CoxeterSupport + +open CoxeterSystem + +universe u v +variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} +variable (cs : CoxeterSystem M W) + +noncomputable local instance : DecidableEq W := Classical.decEq W + +noncomputable def simpleAction (i : B) : Equiv.Perm (W × ZMod 2) := by + classical + let f : W × ZMod 2 → W × ZMod 2 := fun p => + (cs.simple i * p.1 * cs.simple i, p.2 + if p.1 = cs.simple i then 1 else 0) + have hf : Function.Involutive f := by + rintro ⟨t, a⟩ + dsimp [f] + have heq : cs.simple i * t * cs.simple i = cs.simple i ↔ t = cs.simple i := by + constructor + · intro h + have := congrArg (fun z => cs.simple i * z * cs.simple i) h + simpa [mul_assoc] using this + · rintro rfl + simp + simp only [heq] + ext + · simp [mul_assoc] + · split_ifs + · simp only [add_assoc, ZModModule.add_self, add_zero] + · simp + exact ⟨f, f, hf, hf⟩ + +@[simp] theorem simpleAction_apply (i : B) (t : W) (a : ZMod 2) : + simpleAction cs i (t, a) = + (cs.simple i * t * cs.simple i, a + if t = cs.simple i then 1 else 0) := by + classical + rfl + +noncomputable def wordAction (ω : List B) : Equiv.Perm (W × ZMod 2) := + (ω.map (simpleAction cs)).prod + +@[simp] theorem wordAction_nil : wordAction cs [] = 1 := rfl + +theorem wordAction_concat (ω : List B) (i : B) : + wordAction cs (ω.concat i) = wordAction cs ω * simpleAction cs i := by + simp [wordAction] + +/-- Signed action records the parity of the genuine left inversion sequence. -/ +theorem wordAction_record (ω : List B) (t : W) (a : ZMod 2) : + wordAction cs ω ((cs.wordProd ω)⁻¹ * t * cs.wordProd ω, a) = + (t, a + ((cs.leftInvSeq ω).count t : ZMod 2)) := by + classical + induction ω using List.reverseRecOn generalizing a with + | nil => simp [wordAction] + | append_singleton ω i ih => + rw [← List.concat_eq_append, wordAction_concat, Equiv.Perm.mul_apply, + cs.wordProd_concat, mul_inv_rev, cs.inv_simple, simpleAction_apply] + have hc : cs.simple i * ((cs.simple i * (cs.wordProd ω)⁻¹) * t * + (cs.wordProd ω * cs.simple i)) * cs.simple i = + (cs.wordProd ω)⁻¹ * t * cs.wordProd ω := by + simp [mul_assoc] + rw [hc, ih] + rw [cs.leftInvSeq_concat] + have heq : (cs.simple i * (cs.wordProd ω)⁻¹) * t * + (cs.wordProd ω * cs.simple i) = cs.simple i ↔ + t = cs.wordProd ω * cs.simple i * (cs.wordProd ω)⁻¹ := by + constructor + · intro h + have := congrArg (fun z => cs.wordProd ω * cs.simple i * z * + cs.simple i * (cs.wordProd ω)⁻¹) h + simpa [mul_assoc] using this + · rintro rfl + simp [mul_assoc] + simp only [List.concat_eq_append, List.count_append, List.count_singleton, + Nat.cast_add, heq] + congr 1 + split_ifs <;> simp_all [add_comm, add_left_comm] + +/-- The presentation relation has a doubled inversion sequence, so its +signed action is trivial, including for no-relation entries `M i j = 0`. -/ +theorem leftInvSeq_alternating_formula (i j : B) (p : ℕ) : + cs.leftInvSeq (alternatingWord i j (2 * p)) = + (List.range (2 * p)).map (fun k => cs.simple i * (cs.simple j * cs.simple i) ^ k) := by + apply List.ext_getElem (by simp) + intro k hk hk' + have hk0 : k < 2 * p := by simpa using hk + rw [cs.getElem_leftInvSeq_alternatingWord i j p k hk0, + List.getElem_map, List.getElem_range] + rw [cs.prod_alternatingWord_eq_mul_pow] + simp only [Nat.not_even_iff_odd.mpr (show Odd (2 * k + 1) from ⟨k, rfl⟩), + ↓reduceIte] + congr 2 + omega + +theorem leftInvSeq_relation_doubled (i j : B) : + ∃ l : List W, cs.leftInvSeq (alternatingWord i j (2 * M i j)) = l ++ l := by + let f : ℕ → W := fun k => cs.simple i * (cs.simple j * cs.simple i) ^ k + refine ⟨(List.range (M i j)).map f, ?_⟩ + rw [leftInvSeq_alternating_formula, two_mul, List.range_add, List.map_append, List.map_map] + congr 1 + apply List.map_congr_left + intro k _ + dsimp [f] + rw [pow_add, cs.simple_mul_simple_pow'] + simp + +theorem wordAction_alternating (i j : B) (p : ℕ) : + wordAction cs (alternatingWord i j (2 * p)) = + (simpleAction cs i * simpleAction cs j) ^ p := by + induction p with + | zero => simp [alternatingWord] + | succ p ih => + rw [show 2 * (p + 1) = (2 * p + 1) + 1 by omega, + alternatingWord_succ', alternatingWord_succ'] + simp only [Nat.not_even_iff_odd.mpr (show Odd (2 * p + 1) from ⟨p, rfl⟩), + ↓reduceIte, even_two, Even.mul_right] + change simpleAction cs i * (simpleAction cs j * + wordAction cs (alternatingWord i j (2 * p))) = _ + rw [ih, ← mul_assoc, pow_succ'] + +theorem simpleAction_liftable : M.IsLiftable (simpleAction cs) := by + intro i j + rw [← wordAction_alternating] + apply Equiv.ext + rintro ⟨t, a⟩ + have h := wordAction_record cs (alternatingWord i j (2 * M i j)) t a + have hw : cs.wordProd (alternatingWord i j (2 * M i j)) = 1 := by + rw [cs.prod_alternatingWord_eq_mul_pow] + simp + obtain ⟨l, hl⟩ := leftInvSeq_relation_doubled cs i j + simpa [hw, hl, List.count_append, Nat.cast_add, ZModModule.add_self] using h + +noncomputable def reflectionAction : W →* Equiv.Perm (W × ZMod 2) := + cs.lift ⟨simpleAction cs, simpleAction_liftable cs⟩ + +@[simp] theorem reflectionAction_simple (i : B) : + reflectionAction cs (cs.simple i) = simpleAction cs i := + cs.lift_apply_simple (simpleAction_liftable cs) i + +theorem reflectionAction_wordProd (ω : List B) : + reflectionAction cs (cs.wordProd ω) = wordAction cs ω := by + induction ω with + | nil => simp + | cons i ω ih => + rw [cs.wordProd_cons, map_mul, reflectionAction_simple, ih] + rfl + +/-- The signed action is conjugation on labels and a translation on signs. -/ +theorem reflectionAction_translation (w t : W) : + ∃ δ : ZMod 2, ∀ a : ZMod 2, + reflectionAction cs w (t, a) = (w * t * w⁻¹, a + δ) := by + classical + obtain ⟨ω, rfl⟩ := cs.wordProd_surjective w + refine ⟨((cs.leftInvSeq ω).count (cs.wordProd ω * t * (cs.wordProd ω)⁻¹) : ZMod 2), ?_⟩ + intro a + rw [reflectionAction_wordProd] + have h := wordAction_record cs ω (cs.wordProd ω * t * (cs.wordProd ω)⁻¹) a + simpa [mul_assoc] using h + +/-- A reflection changes the sign of its own label. This is the critical +conjugation step making the representation yield *strong* exchange. -/ +theorem reflectionAction_reflection {t : W} (ht : cs.IsReflection t) (a : ZMod 2) : + reflectionAction cs t (t, a) = (t, a + 1) := by + obtain ⟨w, i, rfl⟩ := ht + obtain ⟨δ, hδ⟩ := reflectionAction_translation cs w⁻¹ + (w * cs.simple i * w⁻¹) + obtain ⟨ε, hε⟩ := reflectionAction_translation cs w (cs.simple i) + have hδ' (a : ZMod 2) : reflectionAction cs w⁻¹ + (w * cs.simple i * w⁻¹, a) = (cs.simple i, a + δ) := by + simpa [mul_assoc] using hδ a + have hz : δ + ε = 0 := by + have h := congrArg (fun p : W × ZMod 2 => p.2) + (Equiv.apply_symm_apply (reflectionAction cs w) (w * cs.simple i * w⁻¹, 0)) + change ((reflectionAction cs w) ((reflectionAction cs w)⁻¹ + (w * cs.simple i * w⁻¹, 0))).2 = 0 at h + rw [← map_inv, hδ', hε] at h + simpa using h + rw [map_mul, map_mul, reflectionAction_simple, Equiv.Perm.mul_apply, + Equiv.Perm.mul_apply, hδ', simpleAction_apply] + simp only [cs.simple_mul_simple_self, one_mul, ↓reduceIte] + rw [hε] + congr 1 + calc + (a + δ + 1) + ε = (a + 1) + (δ + ε) := by ring + _ = a + 1 := by rw [hz, add_zero] + + +theorem mem_leftInvSeq_of_inversion {ω : List B} (_hω : cs.IsReduced ω) + {t : W} (ht : cs.IsLeftInversion (cs.wordProd ω) t) : + t ∈ cs.leftInvSeq ω := by + classical + by_contra hnot + obtain ⟨ν, hν, heq⟩ := cs.exists_isReduced (t * cs.wordProd ω) + have hw := wordAction_record cs ω t (0 : ZMod 2) + rw [← reflectionAction_wordProd] at hw + simp only [List.count_eq_zero.mpr hnot, Nat.cast_zero, add_zero] at hw + have hv := wordAction_record cs ν t (0 : ZMod 2) + rw [← reflectionAction_wordProd, ← heq] at hv + have hin : (t * cs.wordProd ω)⁻¹ * t * (t * cs.wordProd ω) = + (cs.wordProd ω)⁻¹ * t * cs.wordProd ω := by + rw [mul_inv_rev, ht.1.inv] + simp [mul_assoc, ht.1.mul_self] + rw [hin, map_mul, Equiv.Perm.mul_apply, hw, + reflectionAction_reflection cs ht.1] at hv + have hmem : t ∈ cs.leftInvSeq ν := by + by_contra hnone + have h := congrArg Prod.snd hv + simp [List.count_eq_zero.mpr hnone] at h + have hlt := (cs.isLeftInversion_of_mem_leftInvSeq hν hmem).2 + rw [← heq] at hlt + have hcancel : t * (t * cs.wordProd ω) = cs.wordProd ω := by + rw [← mul_assoc, ht.1.mul_self, one_mul] + rw [hcancel] at hlt + exact (not_lt_of_ge hlt.le) ht.2 + +/-- Full strong exchange, with the deletion index in the supplied reduced word. -/ +theorem strong_exchange {ω : List B} (hω : cs.IsReduced ω) {t : W} + (ht : cs.IsLeftInversion (cs.wordProd ω) t) : + ∃ j : ℕ, j < ω.length ∧ t * cs.wordProd ω = cs.wordProd (ω.eraseIdx j) := by + obtain ⟨j, hj, heq⟩ := List.mem_iff_getElem.mp + (mem_leftInvSeq_of_inversion cs hω ht) + refine ⟨j, by simpa using hj, ?_⟩ + rw [← heq, ← List.getD_eq_getElem _ 1 hj] + exact cs.getD_leftInvSeq_mul_wordProd ω j + +end KLInvariance.CoxeterSupport + + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/Decomposition.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/Decomposition.lean index a69ad79d112dd911ec81590ae5f5b35470617216..c2dda4b37cefe2177a31347e0d4e80c91946cf91 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/Decomposition.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/Decomposition.lean @@ -1,1709 +1,1709 @@ -import OAI.RepresentationTheory.KazhdanLusztig.SheafMorphisms - -namespace OAI - -/-! -Graded decomposition characters, reflection-plane algebras and reflection Frobenius structures. --/ - -section - -namespace KLInvariance.MomentGraph.GradedSheaf -open _root_.OAI.KLInvariance.Graded Polynomial -universe uk us um -variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] - {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} -noncomputable section - - def freeStalkChar (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) - (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) (x : V) : Polynomial ℤ := by - let := hf x - exact (B.vertex x).char - - theorem ModelSum.character {α : E → MvPolynomial σ k} - (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) - [Fintype V] {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} - (h : ModelSum O.sheaf U B) : - ∃ hmul : V → Polynomial ℤ, - (∀ y n, 0 ≤ (hmul y).coeff n) ∧ - (∀ y, y ∉ U → hmul y=0) ∧ - ∀ x, freeStalkChar B (h.free O) x = - ∑ y, hmul y*freeStalkChar (O.sheaf y) (O.free y) x := by - classical - induction h with - | zero => - refine ⟨0,by simp,by simp,?_⟩ - intro x - simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] - exact ModuleData.char_zero _ - | @add B h c hc n d ih => - obtain ⟨m,hm,hsupp,heq⟩ := ih - let a : Polynomial ℤ := ∑ i, X^(d i) - have ha (r : ℕ) : 0 ≤ a.coeff r := by - simp only [a,Polynomial.finsetSum_coeff,Polynomial.coeff_X_pow] - exact Finset.sum_nonneg (fun i _ => by split <;> norm_num) - refine ⟨fun y => m y+if y=c then a else 0,?_,?_,?_⟩ - · intro y r - rw [Polynomial.coeff_add] - apply add_nonneg (hm y r) - split - · exact ha r - · simp - · intro y hy - have hne : y≠c := fun hh => hy (hh ▸ hc) - simp [hsupp y hy,hne] - · intro x - let _ := h.free O x - let _ := O.free c x - change ((B.vertex x).prod (ModuleData.pi (fun i => ((O.sheaf c).vertex x).shift (d i)))).char = _ - rw [ModuleData.char_prod,ModuleData.char_pi] - simp only [ModuleData.char_shift] - change freeStalkChar B (h.free O) x + _ = _ - rw [heq x] - simp only [add_mul,Finset.sum_add_distrib] - congr 1 - rw [← Finset.sum_mul] - simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] - rfl - - theorem exists_stalkCharacter_decomposition [Fintype V] [Fintype E] - {α : E → MvPolynomial σ k} - (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) - (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) - (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) - (hq : B.UpperQuotient α) (hfl : B.forget.Flabby) (hg : B.forget.Generated) : - ∃ hmul : V → Polynomial ℤ, (∀ y n, 0 ≤ (hmul y).coeff n) ∧ - ∀ x, freeStalkChar B hf x = - ∑ y, hmul y*freeStalkChar (O.sheaf y) (O.free y) x := by - obtain ⟨C,hC,⟨j⟩⟩ := exists_modelSumIso (polynomialGrading_zero k σ) O B hf hq hfl hg - obtain ⟨m,hm,_,heq⟩ := hC.character O - refine ⟨m,hm,fun x => ?_⟩ - rw [← heq x] - let _ := hf x - let _ := hC.free O x - exact ModuleData.character_eq_of_gradedEquiv (j.vertex x) - (j.vertex_graded x) - -end -end KLInvariance.MomentGraph.GradedSheaf - -end - - -section - -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - - def lowerCharacter (c x : Interval cs 1 b) : Polynomial ℤ := - if h : x≤c then stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) - ⟨x.val,x.property.1,h⟩ else 0 - - theorem boundaryModels_character (c x : Interval cs 1 b) : - GradedSheaf.freeStalkChar ((boundaryModels cs b basis).sheaf c) - ((boundaryModels cs b basis).free c) x=lowerCharacter cs b basis c x := by - let _ := (boundaryModels cs b basis).free c x - by_cases hx : x≤c - · rw [lowerCharacter,dite_eq_left hx] - let B := lowerIntervalBoundary cs b basis c - let _ := B.sheaf.lowerExtend_free B.free x - let _ := (boundarySheaf cs 1 c.val basis (one_bruhat cs c.val)).free ⟨x.val,x.property.1,hx⟩ - exact ModuleData.character_eq_of_gradedEquiv (B.sheaf.lowerExtendVertex ⟨x,hx⟩) - (B.sheaf.lowerExtendVertex_graded ⟨x,hx⟩) - · rw [lowerCharacter,dite_eq_right hx] - let _ := (boundaryModels cs b basis).support c x hx - exact ModuleData.char_zero _ - - theorem lowerCharacter_zero (c x : Interval cs 1 b) (hx : ¬x≤c) : - lowerCharacter cs b basis c x=0 := dite_eq_right hx - - theorem lowerCharacter_nonneg (c x : Interval cs 1 b) (n : ℕ) : - 0≤(lowerCharacter cs b basis c x).coeff n := by - unfold lowerCharacter - split - · exact stalkCharacter_coeff_nonneg cs 1 c.val basis (one_bruhat cs c.val) _ n - · simp - -end -end KLInvariance.BruhatGraph - -end - - -section - -/-! Integral pair-projection quotients. The purpose is the actual localization -functor from a tensor bimodule to a moment-graph sheaf; no flabbiness, stalk -freeness, BMP identification or character theorem is assumed or asserted. -/ -namespace KLInvariance.PairProjection -universe u v w z -variable {R : Type u} [CommRing R] - {M : Type v} [AddCommGroup M] [Module R M] - {X : Type w} [AddCommGroup X] [Module R X] - {Y : Type z} [AddCommGroup Y] [Module R Y] - (f : M →ₗ[R] X) (g : M →ₗ[R] Y) -noncomputable section - -def relation : Submodule R (X × Y) := LinearMap.range (f.prod g) -abbrev Edge := (X × Y) ⧸ relation f g - -def lower : X →ₗ[R] Edge f g := (relation f g).mkQ.comp (LinearMap.inl R X Y) -def upper : Y →ₗ[R] Edge f g := -((relation f g).mkQ.comp (LinearMap.inr R X Y)) - -theorem diagonal_zero (m : M) : (relation f g).mkQ (f m,g m)=0 := by - exact (Submodule.Quotient.mk_eq_zero _).mpr ⟨m,rfl⟩ - -theorem compatible (m : M) : lower f g (f m)=upper f g (g m) := by - have h := diagonal_zero f g m - have hp : (f m,g m)=(f m,0)+(0,g m) := by simp - rw [hp,map_add] at h - exact eq_neg_of_add_eq_zero_left h - -theorem compatible_iff (x : X) (y : Y) : - lower f g x=upper f g y ↔ ∃ m : M, f m=x ∧ g m=y := by - change (relation f g).mkQ (x,0) = -((relation f g).mkQ (0,y)) ↔ _ - rw [eq_neg_iff_add_eq_zero,← map_add] - rw [show ((x,0)+(0,y) : X × Y)=(x,y) by simp] - change (Submodule.Quotient.mk (x,y) : Edge f g)=0 ↔ _ - rw [Submodule.Quotient.mk_eq_zero] - constructor - · rintro ⟨m,hm⟩ - exact ⟨m,congrArg Prod.fst hm,congrArg Prod.snd hm⟩ - · rintro ⟨m,hm,hn⟩ - exact ⟨m,Prod.ext hm hn⟩ - -theorem kernel_lower (x : X) : lower f g x=0 ↔ ∃ m : M, f m=x ∧ g m=0 := by - change (relation f g).mkQ (x,0)=0 ↔ _ - change Submodule.Quotient.mk (x,0) = 0 ↔ _ - rw [Submodule.Quotient.mk_eq_zero] - constructor - · rintro ⟨m,hm⟩ - exact ⟨m,congrArg Prod.fst hm,congrArg Prod.snd hm⟩ - · rintro ⟨m,hm,hn⟩ - exact ⟨m,Prod.ext hm hn⟩ - -theorem lower_surjective (hg : Function.Surjective g) : - Function.Surjective (lower f g) := by - intro v - obtain ⟨⟨x,y⟩,rfl⟩ := (relation f g).mkQ_surjective v - obtain ⟨m,rfl⟩ := hg y - refine ⟨x-f m,?_⟩ - change (relation f g).mkQ (x-f m,0) = (relation f g).mkQ (x,g m) - have hp : (x-f m,0)=(x,g m)-(f m,g m) := by simp - rw [hp,map_sub,diagonal_zero,sub_zero] - -theorem upper_surjective (hf : Function.Surjective f) : - Function.Surjective (upper f g) := by - intro v - obtain ⟨⟨x,y⟩,rfl⟩ := (relation f g).mkQ_surjective v - obtain ⟨m,rfl⟩ := hf x - refine ⟨g m-y,?_⟩ - change -((relation f g).mkQ (0,g m-y)) = (relation f g).mkQ (f m,y) - have hp : (0,g m-y)=(f m,g m)-(f m,y) := by simp - rw [hp,map_sub,diagonal_zero,zero_sub,neg_neg] - -/-- A genuine right-action eigenvalue difference annihilates the edge -quotient. This uses only the integral module, not a fraction-field equality. -/ -theorem difference_annihilates (hf : Function.Surjective f) - (hg : Function.Surjective g) (T : M →ₗ[R] M) (r s : R) - (hr : ∀ m, f (T m)=r • f m) (hs : ∀ m, g (T m)=s • g m) - (v : Edge f g) : (r-s) • v=0 := by - obtain ⟨x,rfl⟩ := lower_surjective f g hg v - rw [← map_smul] - apply (kernel_lower f g _).mpr - obtain ⟨m,rfl⟩ := hf x - refine ⟨T m-s • m,?_,?_⟩ - · rw [map_sub,map_smul,hr,sub_smul] - · rw [map_sub,map_smul,hs,sub_self] - -end -end KLInvariance.PairProjection - -end - - -section - - -namespace KLInvariance.Dihedral -noncomputable section - -variable {G : Type*} [Group G] - -/-- The matrix of a pair of distinct involutions. -/ -def pairMatrix (s t : G) (hs : s * s = 1) (hst : s ≠ t) : CoxeterMatrix Bool where - M i j := if i = j then 1 else orderOf (s * t) - isSymm := by - ext i j - change (if j = i then 1 else orderOf (s*t)) = if i = j then 1 else orderOf (s*t) - cases i <;> cases j <;> rfl - diagonal i := ite_eq_left rfl - off_diagonal i j hij := by - rw [ite_eq_right hij] - intro h - have he := orderOf_eq_one_iff.mp h - apply hst - calc - s = s * (s * t) := by rw [he, mul_one] - _ = t := by rw [← mul_assoc, hs, one_mul] - -/-- Alternating even words are powers of the product of the two generators. -/ -theorem wordProd_alt_even {N : CoxeterMatrix Bool} {H : Type*} [Group H] - (cs : CoxeterSystem N H) (i : Bool) (n : ℕ) : - cs.wordProd (alt i (2 * n)) = (cs.simple i * cs.simple (!i)) ^ n := by - induction n with - | zero => simp - | succ n ih => - rw [show 2 * (n + 1) = 2 * n + 2 by omega, alt_add_two] - rw [cs.wordProd_cons, cs.wordProd_cons, ih, pow_succ'] - exact (mul_assoc _ _ _).symm - -/-- Homomorphisms out of a rank-two Coxeter group that do not lower -its product order and do not kill either generator are injective. -/ -theorem injective_of_simple_order {N : CoxeterMatrix Bool} {H : Type*} [Group H] - (cs : CoxeterSystem N H) (f : H →* G) - (hne : ∀ i, f (cs.simple i) ≠ 1) - (horder : ∀ i, orderOf (f (cs.simple i) * f (cs.simple (!i))) = N i (!i)) : - Function.Injective f := by - apply (injective_iff_map_eq_one f).mpr - intro w hw - rcases Nat.even_or_odd (cs.length w) with he | ho - · obtain ⟨n, hn⟩ := he - have hn' : cs.length w = 2 * n := by omega - obtain ⟨i, hi⟩ := exists_alt cs w - rw [hn', wordProd_alt_even] at hi - have hpow : (f (cs.simple i) * f (cs.simple (!i))) ^ n = 1 := by - simpa only [hi, map_pow, map_mul] using hw - have hdiv := orderOf_dvd_of_pow_eq_one hpow - rw [horder i] at hdiv - obtain ⟨k, hk⟩ := hdiv - rw [hi, hk, pow_mul, cs.simple_mul_simple_pow, one_pow] - · obtain ⟨a, i, ha⟩ := (reflection_iff_odd cs w).mpr ho - have h := hw - rw [ha, map_mul, map_mul, map_inv] at h - apply False.elim - apply hne i - have h' := congrArg (fun z => (f a)⁻¹ * z * f a) h - simpa only [mul_assoc, inv_mul_cancel_left, inv_mul_cancel, mul_one, - one_mul, mul_inv_cancel_left] using h' - -variable (s t : G) (hs : s * s = 1) (ht : t * t = 1) (hst : s ≠ t) - -/-- The map from the genuine presented rank-two Coxeter group. -/ -def pairLift : (pairMatrix s t hs hst).Group →* G := - (pairMatrix s t hs hst).toCoxeterSystem.lift - ⟨(fun i => if i then t else s), by - intro i j - cases i <;> cases j - · simpa [pairMatrix] using hs - · simp only [pairMatrix, Bool.false_eq_true, ↓reduceIte] - exact pow_orderOf_eq_one (s*t) - · simp only [pairMatrix, Bool.true_eq_false, Bool.false_eq_true, ↓reduceIte] - have hinv : (s*t)⁻¹ = t*s := by - rw [mul_inv_rev, (inv_eq_of_mul_eq_one_right ht), (inv_eq_of_mul_eq_one_right hs)] - rw [← hinv, inv_pow, pow_orderOf_eq_one, inv_one] - · simpa [pairMatrix] using ht⟩ - -@[simp] theorem pairLift_simple (i : Bool) : - pairLift s t hs ht hst ((pairMatrix s t hs hst).toCoxeterSystem.simple i) = - if i then t else s := by - apply CoxeterSystem.lift_apply_simple - -/-- No relation other than the Coxeter relations is introduced by the pair. -/ -theorem pairLift_injective (hs1 : s ≠ 1) (ht1 : t ≠ 1) : - Function.Injective (pairLift s t hs ht hst) := by - apply injective_of_simple_order (pairMatrix s t hs hst).toCoxeterSystem - · intro i - rw [pairLift_simple] - cases i <;> simp_all - · intro i - simp only [pairLift_simple] - cases i - · simp [pairMatrix] - · simp only [Bool.not_true, ↓reduceIte, pairMatrix, Bool.true_eq_false, Bool.false_eq_true] - have hinv : (s*t)⁻¹ = t*s := by - rw [mul_inv_rev, (inv_eq_of_mul_eq_one_right ht), (inv_eq_of_mul_eq_one_right hs)] - rw [← hinv, orderOf_inv] - -/-- The presented pair generates exactly the subgroup generated by its images. -/ -theorem pairLift_range : - (pairLift s t hs ht hst).range = Subgroup.closure {s, t} := by - apply le_antisymm - · rintro x ⟨w, rfl⟩ - apply (pairMatrix s t hs hst).toCoxeterSystem.simple_induction w - · intro i - rw [pairLift_simple] - cases i <;> apply Subgroup.subset_closure <;> simp - · simp only [map_one, Subgroup.one_mem] - · intro a b ha hb - rw [map_mul] - exact Subgroup.mul_mem _ ha hb - · apply (Subgroup.closure_le _).mpr - intro x hx - rcases Set.mem_insert_iff.mp hx with hx | hx - · rw [hx] - exact ⟨(pairMatrix s t hs hst).toCoxeterSystem.simple false, pairLift_simple _ _ _ _ _ _⟩ - · have : x = t := Set.mem_singleton_iff.mp hx - subst x - exact ⟨(pairMatrix s t hs hst).toCoxeterSystem.simple true, pairLift_simple _ _ _ _ _ _⟩ - -/-- An actual Coxeter system on the generated subgroup, not an extra assumption. -/ -def pairSystem (hs1 : s ≠ 1) (ht1 : t ≠ 1) : - CoxeterSystem (pairMatrix s t hs hst) (Subgroup.closure {s, t}) := - (pairMatrix s t hs hst).toCoxeterSystem.map - ((MulEquiv.ofBijective (pairLift s t hs ht hst).rangeRestrict - ⟨MonoidHom.rangeRestrict_injective_iff.mpr - (pairLift_injective s t hs ht hst hs1 ht1), - (pairLift s t hs ht hst).rangeRestrict_surjective⟩).trans - (MulEquiv.subgroupCongr (pairLift_range s t hs ht hst))) - -@[simp] theorem pairSystem_simple (hs1 : s ≠ 1) (ht1 : t ≠ 1) (i : Bool) : - ((pairSystem s t hs ht hst hs1 ht1).simple i : G) = if i then t else s := by - exact pairLift_simple s t hs ht hst i - -end -end KLInvariance.Dihedral - - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section - -/-- Any two distinct positive roots in a two-dimensional root plane span it. -/ -theorem rootPlane_eq_of_mem (a b l r : PositiveRoot M cs) (hab : a ≠ b) - (hl : l.val ∈ rootPlane a b) (hr : r.val ∈ rootPlane a b) (hlr : l ≠ r) : - rootPlane l r = rootPlane a b := by - apply Submodule.eq_of_le_of_finrank_eq - · apply Submodule.span_le.mpr - intro z hz - change z ∈ rootPlane a b - rcases Set.mem_insert_iff.mp hz with hz | hz - · rw [hz]; exact hl - · rw [Set.mem_singleton_iff.mp hz]; exact hr - · rw [rootPlane_finrank _ _ hlr, rootPlane_finrank _ _ hab] - -/-- Slope betweenness detects the actual positive cone, not only one implication. -/ -theorem positive_combination_of_slope_between (a b c : PositiveRoot M cs) - (hc : c.val ∈ rootPlane a b) - (hac : geometricSlope a < geometricSlope c) - (hcb : geometricSlope c < geometricSlope b) : - ∃ r s : ℝ, 0 < r ∧ 0 < s ∧ c.val = r • a.val + s • b.val := by - let f := geometricFunctional (M := M) (cs := cs) - obtain ⟨r, s, he⟩ := Submodule.mem_span_pair.mp hc - refine ⟨r, s, ?_, ?_, he.symm⟩ - all_goals - have ha := a.height_pos - have hb := b.height_pos - have hh := c.height_pos - have hfc := congrArg f he - have hhc := congrArg (height (I := I)) he - simp only [map_add, map_smul, smul_eq_mul] at hfc hhc - change f a.val / height a.val < - f c.val / height c.val at hac - change f c.val / height c.val < - f b.val / height b.val at hcb - have hab := lt_trans hac hcb - rw [div_lt_div_iff₀ ha hb] at hab - rw [div_lt_div_iff₀ ha hh] at hac - rw [div_lt_div_iff₀ hh hb] at hcb - · have heq : r * (f b.val * height a.val - - f a.val * height b.val) = - f b.val * height c.val - - f c.val * height b.val := by rw [← hfc, ← hhc]; ring - have hp : 0 < r * (f b.val * height a.val - - f a.val * height b.val) := by rw [heq]; linarith - exact (mul_pos_iff.mp hp).resolve_right (by intro h; linarith [h.2]) |>.1 - · have heq : s * (f b.val * height a.val - - f a.val * height b.val) = - f c.val * height a.val - - f a.val * height c.val := by rw [← hfc, ← hhc]; ring - have hp : 0 < s * (f b.val * height a.val - - f a.val * height b.val) := by rw [heq]; linarith - exact (mul_pos_iff.mp hp).resolve_right (by intro h; linarith [h.2]) |>.1 - -/-- Positivity is convex in the root cone. -/ -theorem noninverted_of_positive_combination (w : W) (a b c : PositiveRoot M cs) - {r s : ℝ} (hr : 0 ≤ r) (hs : 0 ≤ s) - (hc : c.val = r • a.val + s • b.val) - (ha : ¬ rootInverted w a) (hb : ¬ rootInverted w b) : - ¬ rootInverted w c := by - rw [not_rootInverted_iff] at ha hb ⊢ - intro i - rw [hc, map_add, map_smul, map_smul] - exact add_nonneg (mul_nonneg hr (ha i)) (mul_nonneg hs (hb i)) - -@[simp] theorem not_rootInverted_one (a : PositiveRoot M cs) : - ¬ rootInverted (1 : W) a := by - rw [not_rootInverted_iff] - simp only [inv_one, map_one] - exact a.property.2 - -@[simp] theorem rootInverted_ref_self (a : PositiveRoot M cs) : - rootInverted (rootRef a) a := by - simpa only [mul_one] using (rootInverted_mul_self 1 a).mpr (not_rootInverted_one a) - -/-- A root plane has an extreme positive root. Finiteness of inversion sets -replaces the false assertion that the (real-valued) root heights are discrete. -/ -theorem exists_plane_extreme_inverted (a b : PositiveRoot M cs) (hab : a ≠ b) : - ∃ p : PositiveRoot M cs, p.val ∈ rootPlane a b ∧ rootInverted (rootRef a) p ∧ - ((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope p ≤ geometricSlope r) ∨ - (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope r ≤ geometricSlope p)) := by - classical - let S := (finite_rootInverted (M := M) (cs := cs) (rootRef a)).toFinset.filter - (fun r => r.val ∈ rootPlane a b) - have hS (r : PositiveRoot M cs) : r ∈ S ↔ - rootInverted (rootRef a) r ∧ r.val ∈ rootPlane a b := by - simp only [S, Finset.mem_filter, Set.Finite.mem_toFinset, Set.mem_ofPred_eq] - have haP : a.val ∈ rootPlane a b := Submodule.subset_span (Set.mem_insert _ _) - have haS : a ∈ S := (hS a).mpr ⟨rootInverted_ref_self a, haP⟩ - obtain ⟨p, hp, hmin⟩ := S.exists_min_image geometricSlope ⟨a, haS⟩ - obtain ⟨q, hq, hmax⟩ := S.exists_max_image geometricSlope ⟨a, haS⟩ - by_cases hleft : ∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope p ≤ geometricSlope r - · exact ⟨p, (hS p).mp hp |>.2, (hS p).mp hp |>.1, Or.inl hleft⟩ - by_cases hright : ∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope r ≤ geometricSlope q - · exact ⟨q, (hS q).mp hq |>.2, (hS q).mp hq |>.1, Or.inr hright⟩ - push Not at hleft hright - obtain ⟨l, hlP, hlp⟩ := hleft - obtain ⟨r, hrP, hqr⟩ := hright - have hla := lt_of_lt_of_le hlp (hmin a haS) - have har := lt_of_le_of_lt (hmax a haS) hqr - have hlr : l ≠ r := fun h => (lt_trans hla har).ne (congrArg geometricSlope h) - have hplane := rootPlane_eq_of_mem a b l r hab hlP hrP hlr - have hlam : ¬ rootInverted (rootRef a) l := by - intro hi - exact (not_le_of_gt hlp) (hmin l ((hS l).mpr ⟨hi, hlP⟩)) - have hram : ¬ rootInverted (rootRef a) r := by - intro hi - exact (not_le_of_gt hqr) (hmax r ((hS r).mpr ⟨hi, hrP⟩)) - obtain ⟨c, d, hc, hd, he⟩ := positive_combination_of_slope_between l r a - (hplane.symm ▸ haP) hla har - exact False.elim ((noninverted_of_positive_combination (rootRef a) l r a - hc.le hd.le he hlam hram) (rootInverted_ref_self a)) - -/-- The canonical simple-root criterion stated on the actual ambient roots. -/ -def PlaneSimple (P : Submodule ℝ (I → ℝ)) (a : PositiveRoot M cs) : Prop := - a.val ∈ P ∧ ∀ b : PositiveRoot M cs, b.val ∈ P → - (rootInverted (rootRef a) b ↔ b = a) - -theorem rootInverted_ref_iff_flipped (a b : PositiveRoot M cs) : - rootInverted (rootRef a) b ↔ flipped a b := by - unfold rootInverted flipped - rw [(rootReflection M cs a).property.inv] - -/-- An angular extreme inverts exactly its own positive root. -/ -theorem planeSimple_of_extreme {P : Submodule ℝ (I → ℝ)} - (a : PositiveRoot M cs) (ha : a.val ∈ P) - (hext : (∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope a ≤ geometricSlope r) ∨ - (∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope r ≤ geometricSlope a)) : - PlaneSimple P a := by - refine ⟨ha, fun b hb => ⟨?_, ?_⟩⟩ - · intro hinv - by_contra hba - have hn := (rootInverted_ref_iff_flipped a b).mp hinv - have hp := partner_mem a b ha hb - have hs := negative_pair_sum a b hn - have hc := negative_pair_coefficient_pos a b hn - have he : a.val = (form M a.val b.val)⁻¹ • b.val + - (form M a.val b.val)⁻¹ • (partner a b).val := by - calc - a.val = (form M a.val b.val)⁻¹ • (form M a.val b.val • a.val) := by - rw [smul_smul, inv_mul_cancel₀ hc.ne', one_smul] - _ = _ := by rw [← hs, smul_add] - have hne : geometricSlope b ≠ geometricSlope (partner a b) := by - intro h - exact hba (negative_partner_fixed a b hn (geometricSlope_injective h).symm) - rcases lt_or_gt_of_ne hne with hlt | hlt - · have hh := geometricSlope_between b (partner a b) a - (inv_pos.mpr hc) (inv_pos.mpr hc) he hlt - rcases hext with hmin | hmax - · exact (not_lt_of_ge (hmin b hb)) hh.1 - · exact (not_lt_of_ge (hmax (partner a b) hp)) hh.2 - · have he' : a.val = (form M a.val b.val)⁻¹ • (partner a b).val + - (form M a.val b.val)⁻¹ • b.val := by rw [add_comm]; exact he - have hh := geometricSlope_between (partner a b) b a - (inv_pos.mpr hc) (inv_pos.mpr hc) he' hlt - rcases hext with hmin | hmax - · exact (not_lt_of_ge (hmin (partner a b) hp)) hh.1 - · exact (not_lt_of_ge (hmax b hb)) hh.2 - · intro h - rw [h] - exact rootInverted_ref_self a - -theorem PlaneSimple.partner_val {P : Submodule ℝ (I → ℝ)} - {a : PositiveRoot M cs} (ha : PlaneSimple P a) - {b : PositiveRoot M cs} (hb : b.val ∈ P) (hba : b ≠ a) : - (partner a b).val = action M cs (rootRef a) b.val := by - have hn : ¬ rootInverted (rootRef a) b := fun h => hba ((ha.2 b hb).mp h) - have hp := (not_rootInverted_iff (rootRef a) b).mp hn - rw [(rootReflection M cs a).property.inv] at hp - exact positiveAction_eq_of_nonneg _ _ hp - -theorem PlaneSimple.exists_nonpositive_pair {P : Submodule ℝ (I → ℝ)} - {a : PositiveRoot M cs} (ha : PlaneSimple P a) - {b : PositiveRoot M cs} (hb : b.val ∈ P) (hba : b ≠ a) : - ∃ c : PositiveRoot M cs, c.val ∈ P ∧ c ≠ a ∧ form M a.val c.val ≤ 0 := by - by_cases hn : form M a.val b.val ≤ 0 - · exact ⟨b, hb, hba, hn⟩ - · refine ⟨partner a b, partner_mem a b ha.1 hb, - fun h => hba ((partner_eq_self_of_eq a b).mp h), ?_⟩ - rw [ha.partner_val hb hba, (rootReflection_represents M cs a).action_formula] - simp only [map_sub, map_smul, smul_eq_mul, a.property.1.norm] - linarith - -theorem noninverted_ref_of_pairing_nonpos (a b : PositiveRoot M cs) - (hab : form M a.val b.val ≤ 0) : ¬ rootInverted (rootRef b) a := by - rw [not_rootInverted_iff, (rootReflection M cs b).property.inv, - (rootReflection_represents M cs b).action_formula] - have hba : form M b.val a.val ≤ 0 := by rwa [(form_symm M).eq] - intro i - exact sub_nonneg.mpr ((mul_nonpos_of_nonpos_of_nonneg hba (b.property.2 i)).trans - (a.property.2 i)) - -/-- The other endpoint exists even in an infinite or degenerate plane. -/ -theorem exists_opposite_plane_extreme (a b p : PositiveRoot M cs) (hab : a ≠ b) - (hp : p.val ∈ rootPlane a b) - (hext : (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope p ≤ geometricSlope r) ∨ - (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope r ≤ geometricSlope p)) : - ∃ q : PositiveRoot M cs, q.val ∈ rootPlane a b ∧ q ≠ p ∧ - (((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope p ≤ geometricSlope r) ∧ - (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope r ≤ geometricSlope q)) ∨ - ((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope q ≤ geometricSlope r) ∧ - (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → - geometricSlope r ≤ geometricSlope p))) := by - have hs := planeSimple_of_extreme p hp hext - have hother : ∃ r : PositiveRoot M cs, r.val ∈ rootPlane a b ∧ r ≠ p := by - by_cases hap : a = p - · refine ⟨b, Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)), ?_⟩ - exact fun h => hab (hap.trans h.symm) - · exact ⟨a, Submodule.subset_span (Set.mem_insert _ _), hap⟩ - obtain ⟨r, hrP, hrp⟩ := hother - obtain ⟨c, hcP, hcp, hcpair⟩ := hs.exists_nonpositive_pair hrP hrp - have hn := noninverted_ref_of_pairing_nonpos p c hcpair - have hplane := rootPlane_eq_of_mem a b c p hab hcP hp hcp - obtain ⟨q, hqP, hqinv, hqext⟩ := exists_plane_extreme_inverted c p hcp - rw [hplane] at hqP hqext - have hqp : q ≠ p := fun h => hn (h ▸ hqinv) - refine ⟨q, hqP, hqp, ?_⟩ - rcases hext with hmin | hmax - · refine Or.inl ⟨hmin, ?_⟩ - rcases hqext with hqmin | hqmax - · exact False.elim (hqp (geometricSlope_injective (le_antisymm - (hqmin p hp) (hmin q hqP)))) - · exact hqmax - · refine Or.inr ⟨?_, hmax⟩ - rcases hqext with hqmin | hqmax - · exact hqmin - · exact False.elim (hqp (geometricSlope_injective (le_antisymm - (hmax q hqP) (hqmax p hp)))) - -/-- Canonical angular endpoints of a plane; no Coxeter-system assertion is -built into this data. The latter will be proved from the inversion criterion. -/ -structure PlaneBasis (P : Submodule ℝ (I → ℝ)) where - left : PositiveRoot M cs - right : PositiveRoot M cs - distinct : left ≠ right - plane_eq : rootPlane left right = P - left_min : ∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope left ≤ geometricSlope r - right_max : ∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope r ≤ geometricSlope right - -theorem nonempty_planeBasis (a b : PositiveRoot M cs) (hab : a ≠ b) : - Nonempty (PlaneBasis (M := M) (cs := cs) (rootPlane a b)) := by - obtain ⟨p, hp, _, hext⟩ := exists_plane_extreme_inverted a b hab - obtain ⟨q, hq, hqp, hpair⟩ := exists_opposite_plane_extreme a b p hab hp hext - rcases hpair with ⟨hl, hr⟩ | ⟨hl, hr⟩ - · exact ⟨⟨p, q, hqp.symm, rootPlane_eq_of_mem a b p q hab hp hq hqp.symm, hl, hr⟩⟩ - · exact ⟨⟨q, p, hqp, rootPlane_eq_of_mem a b q p hab hq hp hqp, hl, hr⟩⟩ - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -theorem left_mem : B.left.val ∈ P := by - apply B.plane_eq.le - exact Submodule.subset_span (Set.mem_insert _ _) - -theorem right_mem : B.right.val ∈ P := by - apply B.plane_eq.le - exact Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)) - -theorem left_simple : PlaneSimple P B.left := - planeSimple_of_extreme B.left B.left_mem (.inl B.left_min) - -theorem right_simple : PlaneSimple P B.right := - planeSimple_of_extreme B.right B.right_mem (.inr B.right_max) - -/-- Every positive root in the plane is in its canonical nonnegative cone. -/ -theorem positive_cone (r : PositiveRoot M cs) (hr : r.val ∈ P) : - ∃ c d : ℝ, 0 ≤ c ∧ 0 ≤ d ∧ r.val = c • B.left.val + d • B.right.val := by - by_cases hl : r = B.left - · exact ⟨1, 0, zero_le_one, le_refl 0, by rw [hl]; simp⟩ - by_cases hh : r = B.right - · exact ⟨0, 1, le_refl 0, zero_le_one, by rw [hh]; simp⟩ - have hlr : geometricSlope B.left < geometricSlope r := - lt_of_le_of_ne (B.left_min r hr) (fun h => hl (geometricSlope_injective h).symm) - have hrr : geometricSlope r < geometricSlope B.right := - lt_of_le_of_ne (B.right_max r hr) (fun h => hh (geometricSlope_injective h)) - obtain ⟨c, d, hc, hd, he⟩ := positive_combination_of_slope_between B.left B.right r - (B.plane_eq.ge hr) hlr hrr - exact ⟨c, d, hc.le, hd.le, he⟩ - -end PlaneBasis - - -/-- Canonical-simple reflections have no extra root pair in their own plane. -/ -theorem PlaneSimple.planeWeight_eq_zero {P : Submodule ℝ (I → ℝ)} - {a : PositiveRoot M cs} (ha : PlaneSimple P a) (x : W) : - planeWeight x a P = 0 := by - classical - rw [planeWeight, Finsupp.mapDomain, Finsupp.sum_apply] - apply Finset.sum_eq_zero - intro b _ - change (Finsupp.single (rootPlane a b) (halfVector x a b)) P = 0 - rw [Finsupp.single_apply] - by_cases hP : rootPlane a b = P - · rw [ite_eq_left hP] - simp only [halfVector, rootIndicator_apply] - apply ite_eq_right - intro hh - have hbP : b.val ∈ P := hP.le - (Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _))) - exact hh.1.1 ((ha.2 b hbP).mp ((rootInverted_ref_iff_flipped a b).mpr hh.1.2.1)) - · exact ite_eq_right hP - -/-- The relative inversion count has the genuine simple-reflection step. -/ -theorem PlaneSimple.planeLength_step {P : Submodule ℝ (I → ℝ)} - {a b : PositiveRoot M cs} (ha : PlaneSimple P a) - (hab : a ≠ b) (hP : rootPlane a b = P) (x : W) - (hx : ¬ rootInverted x a) : - planeLength (M := M) (cs := cs) P (rootRef a * x) = - planeLength (M := M) (cs := cs) P x + 1 := by - have hh := planeWeight_relative_degree x a b hab hx - rw [hP, ha.planeWeight_eq_zero] at hh - linarith - -theorem PlaneSimple.planeLength_step_down {P : Submodule ℝ (I → ℝ)} - {a b : PositiveRoot M cs} (ha : PlaneSimple P a) - (hab : a ≠ b) (hP : rootPlane a b = P) (x : W) - (hx : rootInverted x a) : - planeLength (M := M) (cs := cs) P (rootRef a * x) = - planeLength (M := M) (cs := cs) P x - 1 := by - have hy : ¬ rootInverted (rootRef a * x) a := - fun h => (rootInverted_mul_self x a).mp h hx - have hh := ha.planeLength_step hab hP (rootRef a * x) hy - rw [← mul_assoc, (rootReflection M cs a).property.mul_self, one_mul] at hh - linarith - -/-- The usual inversion bijection, proved on the actual positive roots. -/ -theorem rootInverted_inverse_action (w : W) (a : PositiveRoot M cs) : - rootInverted w⁻¹ (positiveAction w⁻¹ a) ↔ rootInverted w a := by - have hw : action M cs w (action M cs w⁻¹ a.val) = a.val := by - rw [← LinearEquiv.mul_apply, ← map_mul, mul_inv_cancel, map_one] - rfl - by_cases hi : rootInverted w a - · apply iff_of_true ?_ hi - unfold rootInverted - rw [inv_inv, positiveAction_eq_of_nonpos _ _ hi, map_neg, hw] - exact fun i => neg_nonpos.mpr (a.property.2 i) - · apply iff_of_false ?_ hi - rw [not_rootInverted_iff, inv_inv, - positiveAction_eq_of_nonneg _ _ ((not_rootInverted_iff w a).mp hi), hw] - exact a.property.2 - -/-- Reindexing the inversion indicator by the inverse root action. -/ -theorem inversionVector_inverse (w : W) : - inversionVector (M := M) (cs := cs) w⁻¹ = - Finsupp.mapDomain (positiveActionEquiv w⁻¹) (inversionVector w) := by - classical - apply (Finsupp.ext_iff).mpr - intro b - obtain ⟨a, rfl⟩ := (positiveActionEquiv (M := M) (cs := cs) w⁻¹).surjective b - rw [Finsupp.mapDomain_equiv_apply, Equiv.symm_apply_apply] - simp only [inversionVector_apply] - change (if rootInverted w⁻¹ (positiveAction w⁻¹ a) then 1 else 0) = _ - rw [rootInverted_inverse_action] - -theorem positiveAction_mem_plane {P : Submodule ℝ (I → ℝ)} - {w : W} (hw : w ∈ planeSubgroup M cs P) (a : PositiveRoot M cs) - (ha : a.val ∈ P) : (positiveAction w a).val ∈ P := by - have hp := planeSubgroup_preserves hw ha - rcases (a.property.1.act w).sign with hs | hs - · exact (positiveAction_eq_of_nonneg w a hs).symm ▸ hp - · exact (positiveAction_eq_of_nonpos w a hs).symm ▸ P.neg_mem hp - -theorem positiveAction_mem_plane_iff {P : Submodule ℝ (I → ℝ)} - {w : W} (hw : w ∈ planeSubgroup M cs P) (a : PositiveRoot M cs) : - (positiveAction w a).val ∈ P ↔ a.val ∈ P := by - refine ⟨fun h => ?_, positiveAction_mem_plane hw a⟩ - have hh := positiveAction_mem_plane ((planeSubgroup M cs P).inv_mem hw) - (positiveAction w a) h - rwa [← positiveAction_mul, inv_mul_cancel, positiveAction_one] at hh - -/-- Relative inversion count is invariant under inverse on the actual plane subgroup. -/ -theorem planeLength_inv {P : Submodule ℝ (I → ℝ)} {w : W} - (hw : w ∈ planeSubgroup M cs P) : - planeLength (M := M) (cs := cs) P w⁻¹ = planeLength (M := M) (cs := cs) P w := by - classical - rw [planeLength, inversionVector_inverse, - Finsupp.sum_mapDomain_index (by intros; split_ifs <;> rfl) - (by intros; split_ifs <;> simp)] - apply Finsupp.sum_congr - intro a _ - change (if (positiveAction w⁻¹ a).val ∈ P then _ else _) = _ - rw [positiveAction_mem_plane_iff ((planeSubgroup M cs P).inv_mem hw)] - -theorem planeLength_nonneg (P : Submodule ℝ (I → ℝ)) (w : W) : - 0 ≤ planeLength (M := M) (cs := cs) P w := by - classical - apply Finset.sum_nonneg - intro a _ - simp only [inversionVector_apply] - split_ifs <;> norm_num - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -/-- A plane reflection must invert at least one of the canonical endpoints. -This uses convex positivity, not any assumed Coxeter structure on the subgroup. -/ -theorem reflection_inverts_endpoint (r : PositiveRoot M cs) (hr : r.val ∈ P) : - rootInverted (rootRef r) B.left ∨ rootInverted (rootRef r) B.right := by - by_contra h - push Not at h - obtain ⟨c, d, hc, hd, he⟩ := B.positive_cone r hr - exact (noninverted_of_positive_combination (rootRef r) B.left B.right r - hc hd he h.1 h.2) (rootInverted_ref_self r) - -end PlaneBasis - - -/-- The second descent in a simple conjugation of a nonsimple reflection. -/ -theorem PlaneSimple.inverted_after_mul {P : Submodule ℝ (I → ℝ)} - {a r : PositiveRoot M cs} (ha : PlaneSimple P a) (hr : r.val ∈ P) - (hra : r ≠ a) (hi : rootInverted (rootRef r) a) : - rootInverted (rootRef r * rootRef a) a := by - have hn := (rootInverted_ref_iff_flipped r a).mp hi - apply (rootInverted_mul_of_nonpos (rootRef a) r a hn).mpr - intro hinv - have he : partner r a = a := (ha.2 (partner r a) (partner_mem r a hr ha.1)).mp hinv - exact hra (negative_partner_fixed r a hn he).symm - -/-- The honest relative length drops by two under the chosen simple conjugation. -/ -theorem PlaneSimple.planeLength_conj_drop {P : Submodule ℝ (I → ℝ)} - {a b r : PositiveRoot M cs} (ha : PlaneSimple P a) - (hab : a ≠ b) (hP : rootPlane a b = P) (hr : r.val ∈ P) - (hra : r ≠ a) (hi : rootInverted (rootRef r) a) : - planeLength (M := M) (cs := cs) P (rootRef (partner a r)) = - planeLength (M := M) (cs := cs) P (rootRef r) - 2 := by - have har : rootRef a ∈ planeSubgroup M cs P := - ((rootReflection_represents M cs a).planeSubgroup_mem_iff M cs).mpr ha.1 - have hrr : rootRef r ∈ planeSubgroup M cs P := - ((rootReflection_represents M cs r).planeSubgroup_mem_iff M cs).mpr hr - have hmul := (planeSubgroup M cs P).mul_mem har hrr - have hd := ha.planeLength_step_down hab hP (rootRef r) hi - have hd' := ha.planeLength_step_down hab hP (rootRef r * rootRef a) - (ha.inverted_after_mul hr hra hi) - have hli := planeLength_inv hmul - rw [mul_inv_rev, (rootReflection M cs r).property.inv, - (rootReflection M cs a).property.inv] at hli - change planeLength (M := M) (cs := cs) P - (rootReflection M cs (positiveAction (rootRef a) r)).val = _ - rw [rootReflection_positiveAction, (rootReflection M cs a).property.inv, mul_assoc] - linarith - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -/-- The canonical endpoint reflections generate every ambient reflection in the plane. -/ -theorem rootRef_mem_pairClosure (r : PositiveRoot M cs) (hr : r.val ∈ P) : - rootRef r ∈ Subgroup.closure {rootRef B.left, rootRef B.right} := by - classical - generalize hn : (planeLength (M := M) (cs := cs) P (rootRef r)).toNat = n - induction n using Nat.strong_induction_on generalizing r with - | h n ih => - by_cases hl : r = B.left - · rw [hl]; exact Subgroup.subset_closure (Set.mem_insert _ _) - by_cases hh : r = B.right - · rw [hh]; exact Subgroup.subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _)) - have step (a b : PositiveRoot M cs) (ha : PlaneSimple P a) - (hab : a ≠ b) (hP : rootPlane a b = P) (hra : r ≠ a) - (hgen : rootRef a ∈ Subgroup.closure {rootRef B.left, rootRef B.right}) - (hi : rootInverted (rootRef r) a) : - rootRef r ∈ Subgroup.closure {rootRef B.left, rootRef B.right} := by - have hp : (partner a r).val ∈ P := partner_mem a r ha.1 hr - have hdrop := ha.planeLength_conj_drop hab hP hr hra hi - have hless : (planeLength (M := M) (cs := cs) P (rootRef (partner a r))).toNat < n := by - have hnonneg := planeLength_nonneg (M := M) (cs := cs) P (rootRef (partner a r)) - omega - have hind := ih _ hless (partner a r) hp rfl - have hlen := (Subgroup.closure {rootRef B.left, rootRef B.right}).mul_mem - ((Subgroup.closure {rootRef B.left, rootRef B.right}).mul_mem hgen hind) hgen - change rootRef a * (rootReflection M cs (positiveAction (rootRef a) r)).val * rootRef a ∈ _ at hlen - rw [rootReflection_positiveAction, (rootReflection M cs a).property.inv] at hlen - rw [← mul_assoc, ← mul_assoc, (rootReflection M cs a).property.mul_self, - one_mul, mul_assoc, (rootReflection M cs a).property.mul_self, mul_one] at hlen - exact hlen - rcases B.reflection_inverts_endpoint r hr with hi | hi - · exact step B.left B.right B.left_simple B.distinct B.plane_eq hl - (Subgroup.subset_closure (Set.mem_insert _ _)) hi - · exact step B.right B.left B.right_simple B.distinct.symm - (by rw [rootPlane, Set.pair_comm]; exact B.plane_eq) hh - (Subgroup.subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _))) hi - -/-- Exact identification with the manuscript's maximal root-plane subgroup. -/ -theorem pairClosure_eq_planeSubgroup : - Subgroup.closure {rootRef B.left, rootRef B.right} = planeSubgroup M cs P := by - apply le_antisymm - · apply (Subgroup.closure_le _).mpr - intro t ht - rcases Set.mem_insert_iff.mp ht with he | he - · rw [he] - exact ((rootReflection_represents M cs B.left).planeSubgroup_mem_iff M cs).mpr B.left_mem - · rw [Set.mem_singleton_iff.mp he] - exact ((rootReflection_represents M cs B.right).planeSubgroup_mem_iff M cs).mpr B.right_mem - · apply (Subgroup.closure_le _).mpr - rintro t ⟨a, ha, haP⟩ - let r := positiveRoot M cs ⟨t, ha.isReflection⟩ - have hre : rootRef r = t := (rootReflection_represents M cs r).reflection_unique - (positiveRoot_represents M cs ⟨t, ha.isReflection⟩) - have hrP : r.val ∈ P := ((positiveRoot_represents M cs - ⟨t, ha.isReflection⟩).planeSubgroup_mem_iff M cs).mp (Subgroup.subset_closure ⟨a, ha, haP⟩) - rw [← hre] - exact B.rootRef_mem_pairClosure r hrP - -/-- Distinct positive roots give distinct actual reflections. -/ -theorem rootRef_distinct : rootRef B.left ≠ rootRef B.right := by - intro he - apply B.distinct - apply (positiveRootEquiv M cs).symm.injective - exact Subtype.ext he - -theorem rootRef_ne_one (a : PositiveRoot M cs) : rootRef a ≠ 1 := by - intro h - exact (not_rootInverted_one a) (h ▸ rootInverted_ref_self a) - -/-- The genuine dihedral matrix attached to the canonical plane endpoints. -/ -def matrix : CoxeterMatrix Bool := - Dihedral.pairMatrix (rootRef B.left) (rootRef B.right) - (rootReflection M cs B.left).property.mul_self B.rootRef_distinct - -/-- A proved Coxeter system on the *actual maximal plane subgroup*. -/ -def system : CoxeterSystem B.matrix (planeSubgroup M cs P) := - (Dihedral.pairSystem (rootRef B.left) (rootRef B.right) - (rootReflection M cs B.left).property.mul_self - (rootReflection M cs B.right).property.mul_self B.rootRef_distinct - (rootRef_ne_one B.left) - (rootRef_ne_one B.right)).map - (MulEquiv.subgroupCongr B.pairClosure_eq_planeSubgroup) - -/-- Canonical simple positive roots, indexed by Bool just like the system. -/ -def simpleRoot (i : Bool) : PositiveRoot M cs := if i then B.right else B.left - -theorem simpleRoot_mem (i : Bool) : (B.simpleRoot i).val ∈ P := by - cases i - · exact B.left_mem - · exact B.right_mem - -theorem simpleRoot_simple (i : Bool) : PlaneSimple P (B.simpleRoot i) := by - cases i - · exact B.left_simple - · exact B.right_simple - -@[simp] theorem system_simple (i : Bool) : - (B.system.simple i : W) = rootRef (B.simpleRoot i) := by - change ((Dihedral.pairSystem (rootRef B.left) (rootRef B.right) - (rootReflection M cs B.left).property.mul_self - (rootReflection M cs B.right).property.mul_self B.rootRef_distinct - (rootRef_ne_one B.left) (rootRef_ne_one B.right)).simple i : W) = _ - rw [Dihedral.pairSystem_simple] - cases i <;> rfl - -/-- The positive simple-sign criterion for the induced plane root system. -/ -theorem simple_sign {t : planeSubgroup M cs P} {a : I → ℝ} - (ha : Represents M cs t.val a) (haP : a ∈ P) (hp : ∀ k, 0 ≤ a k) (i : Bool) : - ((∀ k, action M cs (B.system.simple i : W) a k ≤ 0) ↔ t = B.system.simple i) ∧ - ((∀ k, 0 ≤ action M cs (B.system.simple i : W) a k) ↔ t ≠ B.system.simple i) := by - let r : PositiveRoot M cs := ⟨a, ha.isRoot, hp⟩ - have hneg : (∀ k, action M cs (B.system.simple i : W) a k ≤ 0) ↔ t = B.system.simple i := by - rw [B.system_simple] - change flipped (B.simpleRoot i) r ↔ _ - rw [← rootInverted_ref_iff_flipped, (B.simpleRoot_simple i).2 r haP] - constructor - · intro he - apply Subtype.ext - rw [B.system_simple] - exact ha.reflection_unique (he ▸ rootReflection_represents M cs r) - · intro he - apply Subtype.ext - have hr : Represents M cs (rootRef (B.simpleRoot i)) a := by - simpa only [he, B.system_simple] using ha - exact hr.unique_positive (rootReflection_represents M cs _) hp (B.simpleRoot i).property.2 - refine ⟨hneg, ?_⟩ - constructor - · intro h he - exact (ha.isRoot.act (B.system.simple i : W)).not_both h (hneg.mpr he) - · intro h - exact (ha.isRoot.act (B.system.simple i : W)).sign.resolve_right (fun hn => h (hneg.mp hn)) - -/-- Signed roots for the induced system. The vectors are the original ambient -roots, and membership in the actual plane is part of the relation. -/ -structure InducedSigned (p : planeSubgroup M cs P × ZMod 2) (a : I → ℝ) : Prop where - represents : Represents M cs p.1.val a - plane_mem : a ∈ P - sign : (p.2 = 0 ∧ ∀ i, 0 ≤ a i) ∨ (p.2 = 1 ∧ ∀ i, a i ≤ 0) - -theorem InducedSigned.simple {p : planeSubgroup M cs P × ZMod 2} {a : I → ℝ} - (ha : InducedSigned p a) (i : Bool) : - InducedSigned (CoxeterSupport.simpleAction B.system i p) - (action M cs (B.system.simple i : W) a) := by - rcases p with ⟨t,z⟩ - rw [CoxeterSupport.simpleAction_apply] - refine ⟨?_, planeSubgroup_preserves (B.system.simple i).property ha.plane_mem, ?_⟩ - · have h := ha.represents.act (B.system.simple i : W) - have he : (B.system.simple i : W)⁻¹ = (B.system.simple i : W) := - congrArg Subtype.val (B.system.inv_simple i) - simpa only [he, Subgroup.coe_mul] using h - · rcases ha.sign with ⟨rfl,hp⟩ | ⟨rfl,hn⟩ - · by_cases heq : t = B.system.simple i - · exact Or.inr ⟨by simp [heq], - (B.simple_sign ha.represents ha.plane_mem hp i).1.mpr heq⟩ - · exact Or.inl ⟨by simp [heq, ZModModule.add_self], - (B.simple_sign ha.represents ha.plane_mem hp i).2.mpr heq⟩ - · have hp : ∀ k, 0 ≤ (-a) k := fun k => neg_nonneg.mpr (hn k) - by_cases heq : t = B.system.simple i - · refine Or.inl ⟨by simp [heq, ZModModule.add_self], ?_⟩ - have h := (B.simple_sign ha.represents.neg (P.neg_mem ha.plane_mem) hp i).1.mpr heq - simpa only [map_neg, Pi.neg_apply, neg_nonpos] using h - · refine Or.inr ⟨by simp [heq], ?_⟩ - have h := (B.simple_sign ha.represents.neg (P.neg_mem ha.plane_mem) hp i).2.mpr heq - simpa only [map_neg, Pi.neg_apply, neg_nonneg] using h - -theorem InducedSigned.act {p : planeSubgroup M cs P × ZMod 2} {a : I → ℝ} - (ha : InducedSigned p a) (w : planeSubgroup M cs P) : - InducedSigned (CoxeterSupport.reflectionAction B.system w p) - (action M cs (w : W) a) := by - obtain ⟨ω,rfl⟩ := B.system.wordProd_surjective w - induction ω with - | nil => simpa using ha - | cons i ω ih => - simpa only [B.system.wordProd_cons, map_mul, Equiv.Perm.mul_apply, - CoxeterSupport.reflectionAction_simple, Subgroup.coe_mul, - LinearEquiv.mul_apply] using ih.simple B i - -/-- The induced positive roots have precisely the intrinsic Coxeter inversion -signs. No change of realization or extra canonical-system assumption is used. -/ -theorem inversion_iff {t : planeSubgroup M cs P} {a : I → ℝ} - (ha : Represents M cs t.val a) (haP : a ∈ P) (hp : ∀ i, 0 ≤ a i) - (w : planeSubgroup M cs P) : - (∀ i, action M cs (w : W)⁻¹ a i ≤ 0) ↔ B.system.IsLeftInversion w t := by - classical - let : BEq (planeSubgroup M cs P) := @instBEqOfDecidableEq _ (Classical.decEq _) - obtain ⟨ω,hω,heq⟩ := B.system.exists_isReduced w - rw [heq] - let c : ZMod 2 := if t ∈ B.system.leftInvSeq ω then 1 else 0 - have hrec := CoxeterSupport.wordAction_record B.system ω t c - rw [← CoxeterSupport.reflectionAction_wordProd] at hrec - have hrec' : CoxeterSupport.reflectionAction B.system (B.system.wordProd ω) - ((B.system.wordProd ω)⁻¹ * t * B.system.wordProd ω, c) = (t,0) := by - by_cases hm : t ∈ B.system.leftInvSeq ω - · have hc : c = 1 := ite_eq_left hm - simpa only [hc, List.count_eq_one_of_mem hω.nodup_leftInvSeq hm, - Nat.cast_one, ZModModule.add_self] using hrec - · have hc : c = 0 := ite_eq_right hm - simpa only [hc, List.count_eq_zero.mpr hm, Nat.cast_zero, add_zero] using hrec - have hinv : CoxeterSupport.reflectionAction B.system (B.system.wordProd ω)⁻¹ (t,0) = - ((B.system.wordProd ω)⁻¹ * t * B.system.wordProd ω,c) := by - rw [map_inv, ← hrec'] - exact Equiv.symm_apply_apply _ _ - have hs : InducedSigned (t,0) a := ⟨ha,haP,Or.inl ⟨rfl,hp⟩⟩ - have hsi := hs.act B (B.system.wordProd ω)⁻¹ - rw [hinv] at hsi - have hcount : c = if t ∈ B.system.leftInvSeq ω then 1 else 0 := rfl - have hmem : (∀ i, action M cs (B.system.wordProd ω : W)⁻¹ a i ≤ 0) ↔ - t ∈ B.system.leftInvSeq ω := by - by_cases hm : t ∈ B.system.leftInvSeq ω - · have hc1 : c=1 := by simpa [hm] using hcount - have hh := hsi.sign - simp only [hc1] at hh - rcases hh with ⟨hbad,_⟩ | ⟨_,hn⟩ - · norm_num at hbad - · exact iff_of_true hn hm - · have hc0 : c=0 := by simpa [hm] using hcount - have hh := hsi.sign - simp only [hc0] at hh - rcases hh with ⟨_,hpos⟩ | ⟨hbad,_⟩ - · exact iff_of_false (fun hn => (ha.isRoot.act _).not_both hpos hn) hm - · norm_num at hbad - rw [hmem] - exact ⟨B.system.isLeftInversion_of_mem_leftInvSeq hω, - CoxeterSupport.mem_leftInvSeq_of_inversion B.system hω⟩ - -/-- The intrinsic reflections are exactly the ambient reflections in the -actual maximal plane subgroup. -/ -theorem reflection_iff (t : planeSubgroup M cs P) : - B.system.IsReflection t ↔ cs.IsReflection (t : W) := by - constructor - · rintro ⟨w,i,he⟩ - obtain ⟨z,j,hz⟩ := (rootReflection M cs (B.simpleRoot i)).property - refine ⟨(w : W) * z,j,?_⟩ - have he' := congrArg Subtype.val he - simp only [Subgroup.coe_mul, Subgroup.coe_inv, B.system_simple] at he' - change rootRef (B.simpleRoot i) = _ at hz - rw [he', hz] - group - · intro ht - let a := positiveRoot M cs ⟨(t:W),ht⟩ - have ha := positiveRoot_represents M cs ⟨(t:W),ht⟩ - have haP : a.val ∈ P := (ha.planeSubgroup_mem_iff M cs).mp t.property - have hinv := (B.inversion_iff ha haP a.property.2 t).mp - ((ha.inversion_iff a.property.2 (t:W)).mpr - ⟨ht, by - rw [ht.mul_self, cs.length_one] - obtain ⟨k,hk⟩ := ht.odd_length - omega⟩) - exact hinv.1 - -/-- The true ambient plane inversions are in bijection with the inversions -of the canonical induced system. -/ -def inversionEquiv (w : planeSubgroup M cs P) : - {a : PositiveRoot M cs // a.val ∈ P ∧ rootInverted (w:W) a} ≃ - {t : planeSubgroup M cs P // B.system.IsLeftInversion w t} where - toFun a := ⟨⟨rootRef a.val, - ((rootReflection_represents M cs a.val).planeSubgroup_mem_iff M cs).mpr a.property.1⟩, - (B.inversion_iff (rootReflection_represents M cs a.val) a.property.1 - a.val.property.2 w).mp a.property.2⟩ - invFun t := - let a := positiveRoot M cs ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩ - let ha := positiveRoot_represents M cs - ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩ - let haP := (ha.planeSubgroup_mem_iff M cs).mp t.val.property - ⟨a,haP,(B.inversion_iff ha haP a.property.2 w).mpr t.property⟩ - left_inv a := by - apply Subtype.ext - exact (positiveRootEquiv M cs).apply_symm_apply a.val - right_inv t := by - apply Subtype.ext - apply Subtype.ext - exact congrArg (fun r : {r : W // cs.IsReflection r} => r.val) - ((positiveRootEquiv M cs).symm_apply_apply - ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩) - -/-- Relative inversion count is the actual Coxeter length, completing the -length identification, not merely a rank-two presentation. -/ -theorem length_eq (w : planeSubgroup M cs P) : - planeLength (M := M) (cs := cs) P (w:W) = (B.system.length w : ℤ) := by - classical - let f := inversionVector (M := M) (cs := cs) (w:W) - let F := f.support.filter (fun a => a.val ∈ P) - have hF : (F : Set (PositiveRoot M cs)) = - {a | a.val ∈ P ∧ rootInverted (w:W) a} := by - ext a - simp only [F, Finset.mem_coe, Finset.mem_filter, Finsupp.mem_support_iff, - f, inversionVector_apply, ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not, - Set.mem_ofPred_eq, and_comm] - have hcard : F.card = B.system.length w := by - rw [← Set.ncard_coe_finset, hF, ← Nat.card_coe_set_eq] - change Nat.card {a : PositiveRoot M cs // a.val ∈ P ∧ rootInverted (w:W) a} = _ - rw [Nat.card_congr (B.inversionEquiv w)] - obtain ⟨ω,hω,he⟩ := B.system.exists_isReduced w - rw [he, Nat.card_congr (leftInversionListEquiv B.matrix B.system hω), - ← Nat.card_congr (List.Nodup.getEquiv (B.system.leftInvSeq ω) hω.nodup_leftInvSeq), - Nat.card_fin, B.system.length_leftInvSeq, hω.eq] - change f.sum (fun a n => if a.val ∈ P then n else 0) = _ - rw [Finsupp.sum, ← Finset.sum_filter] - calc - ∑ a ∈ F, f a = ∑ _a ∈ F, (1:ℤ) := by - apply Finset.sum_congr rfl - intro a ha - have hm : rootInverted (w:W) a := by - have hm := (Finset.mem_filter.mp ha).1 - simpa only [Finsupp.mem_support_iff, f, inversionVector_apply, - ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hm - simp [f,hm] - _ = _ := by simp [hcard] - -/-- Intrinsic and ambient left inversions coincide on the plane subgroup. -/ -theorem leftInversion_iff (w t : planeSubgroup M cs P) : - B.system.IsLeftInversion w t ↔ cs.IsLeftInversion (w:W) (t:W) := by - by_cases ht : cs.IsReflection (t:W) - · let a := positiveRoot M cs ⟨(t:W),ht⟩ - have ha := positiveRoot_represents M cs ⟨(t:W),ht⟩ - have haP := (ha.planeSubgroup_mem_iff M cs).mp t.property - exact (B.inversion_iff ha haP a.property.2 w).symm.trans - (ha.inversion_iff a.property.2 (w:W)) - · exact iff_of_false (fun h => ht ((B.reflection_iff t).mp h.1)) (fun h => ht h.1) - -/-- The intrinsic directed dihedral graph is the actual ambient graph -restricted to the maximal plane subgroup. -/ -theorem bruhatStep_iff (g h : planeSubgroup M cs P) : - BruhatStep cs (g:W) (h:W) ↔ BruhatStep B.system g h := by - constructor - · rintro ⟨hlen,t,ht,he⟩ - have htP : t ∈ planeSubgroup M cs P := by - have he' : t = (h:W) * (g:W)⁻¹ := by rw [he]; group - rw [he'] - exact (planeSubgroup M cs P).mul_mem h.property - ((planeSubgroup M cs P).inv_mem g.property) - let tr : planeSubgroup M cs P := ⟨t,htP⟩ - have htr : B.system.IsReflection tr := (B.reflection_iff tr).mpr ht - have het : h=tr*g := Subtype.ext he - have htg : t*(h:W)=(g:W) := by rw [he, ← mul_assoc, ht.mul_self, one_mul] - have hi := (B.leftInversion_iff h tr).mpr ⟨ht,by - change cs.length (t*(h:W)) < cs.length (h:W) - simpa only [htg] using hlen⟩ - have htg' : tr*h=g := by rw [het, ← mul_assoc, htr.mul_self, one_mul] - exact ⟨by simpa only [htg'] using hi.2,tr,htr,het⟩ - · rintro ⟨hlen,t,ht,he⟩ - have het : t*h=g := by rw [he, ← mul_assoc, ht.mul_self, one_mul] - have hi := (B.leftInversion_iff h t).mp ⟨ht,by simpa only [het] using hlen⟩ - refine ⟨?_,(t:W),(B.reflection_iff t).mp ht,congrArg Subtype.val he⟩ - simpa only [← Subgroup.coe_mul, het] using hi.2 - -/-- The exact canonical coset graph theorem needed by the reconstruction. -/ -theorem coset_step_iff {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - (g h : planeSubgroup M cs P) : - BruhatStep cs ((g:W)*a₀) ((h:W)*a₀) ↔ BruhatStep B.system g h := - (bruhatStep_coset_iff hmin g.property h.property).trans (B.bruhatStep_iff g h) - -/-- Relative dihedral paths give actual ambient Bruhat paths in the coset. -/ -theorem coset_bruhat {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {g h : planeSubgroup M cs P} (hgh : BruhatLE B.system g h) : - BruhatLE cs ((g:W)*a₀) ((h:W)*a₀) := by - induction hgh with - | refl => exact Relation.ReflTransGen.refl - | @tail y z _ hyz ih => - exact ih.tail ((B.coset_step_iff hmin y z).mpr hyz) - -/-- The source inversion-count characterization holds on every minimal -representative coset, with its actual induced length. -/ -theorem coset_length_eq {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - (w : planeSubgroup M cs P) : - planeLength (M := M) (cs := cs) P ((w:W)*a₀) = (B.system.length w : ℤ) := by - classical - rw [← B.length_eq w] - let f := inversionVector (M := M) (cs := cs) ((w:W)*a₀) - let g := inversionVector (M := M) (cs := cs) (w:W) - change f.sum (fun a n => if a.val ∈ P then n else 0) = - g.sum (fun a n => if a.val ∈ P then n else 0) - rw [Finsupp.sum_of_support_subset f Finset.subset_union_left _ (by intro a; simp), - Finsupp.sum_of_support_subset g Finset.subset_union_right _ (by intro a; simp)] - apply Finset.sum_congr rfl - intro a _ - by_cases haP : a.val ∈ P - · simp only [ite_eq_left haP, f, g, inversionVector_apply] - congr 1 - exact propext (root_inversion_coset_iff hmin w.property a.property.1 haP) - · simp [haP] - -end PlaneBasis - -/-- Every nonsaturated reflection edge has a genuine rank-two contribution -whose induced relative edge gap is at least three. -/ -theorem exists_positive_plane (x : W) (a : PositiveRoot M cs) - (hx : ¬ rootInverted x a) - (hlen : cs.length x + 1 < cs.length (rootRef a*x)) : - ∃ b : PositiveRoot M cs, a ≠ b ∧ 0 < planeWeight x a (rootPlane a b) := by - classical - have hsum := sum_planeWeight x a hx - have hp : 0 < (planeWeight x a).sum (fun _ n => n) := by omega - obtain ⟨P,hP,hpos⟩ := (Finset.sum_pos_iff_of_nonneg - (fun P _ => planeWeight_nonneg x a P)).mp hp - obtain ⟨b,hb,hbP⟩ := Finset.mem_image.mp (Finsupp.mapDomain_support hP) - have hb' : halfRoot x a b := by - simpa only [Finsupp.mem_support_iff, halfVector, rootIndicator_apply, - ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hb - exact ⟨b,hb'.1.1.symm,hbP ▸ hpos⟩ - - -end -end KLInvariance.TitsSpace - -namespace KLInvariance.Dihedral -variable {G : Type*} [Group G] {N : CoxeterMatrix Bool} - -/-- Every nonsaturated dihedral edge contains a full eight-edge rectangle. -/ -theorem edge_diamond (ds : CoxeterSystem N G) {x y : G} - (hxy : BruhatStep ds x y) (hlen : ds.length x + 1 < ds.length y) : - ∃ a b c d : G, a ≠ b ∧ c ≠ d ∧ - BruhatStep ds x a ∧ BruhatStep ds x b ∧ - BruhatStep ds a c ∧ BruhatStep ds a d ∧ - BruhatStep ds b c ∧ BruhatStep ds b d ∧ - BruhatStep ds c y ∧ BruhatStep ds d y := by - have hodd := ((step_iff_odd ds x y).mp hxy).2 - have hthree : ds.length x+2 < ds.length y := by - rw [Nat.odd_iff] at hodd - omega - obtain ⟨a,b,hab,hlev₁⟩ := two_elements_length ds - (by omega : 0 < ds.length x+1) hlen - obtain ⟨c,d,hcd,hlev₂⟩ := two_elements_length ds - (by omega : 0 < ds.length x+2) hthree - have ha := (hlev₁ a).mpr (Or.inl rfl) - have hb := (hlev₁ b).mpr (Or.inr rfl) - have hc := (hlev₂ c).mpr (Or.inl rfl) - have hd := (hlev₂ d).mpr (Or.inr rfl) - have hsucc (p q : G) (h : ds.length q=ds.length p+1) : BruhatStep ds p q := by - rw [step_iff_odd, Nat.odd_iff] - constructor <;> omega - have htop (p : G) (hp : ds.length p=ds.length x+2) : BruhatStep ds p y := by - rw [step_iff_odd, Nat.odd_iff] - rw [Nat.odd_iff] at hodd - constructor <;> omega - exact ⟨a,b,c,d,hab,hcd,hsucc x a ha,hsucc x b hb, - hsucc a c (by omega),hsucc a d (by omega), - hsucc b c (by omega),hsucc b d (by omega),htop c hc,htop d hd⟩ - -end KLInvariance.Dihedral - -namespace KLInvariance.TitsSpace -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} - -/-- Every genuine ambient reflection edge of length gap greater than one -contains a full eight-edge diamond. The chosen plane comes from an actual -positive inversion contribution, avoiding the false arbitrary-plane claim. -/ -theorem ambient_edge_diamond {x y : W} (hxy : BruhatStep cs x y) - (hlen : cs.length x+1 < cs.length y) : - ∃ a b c d : W, a ≠ b ∧ c ≠ d ∧ - BruhatStep cs x a ∧ BruhatStep cs x b ∧ - BruhatStep cs a c ∧ BruhatStep cs a d ∧ - BruhatStep cs b c ∧ BruhatStep cs b d ∧ - BruhatStep cs c y ∧ BruhatStep cs d y := by - rcases hxy.2 with ⟨t,ht,het⟩ - let a := positiveRoot M cs ⟨t,ht⟩ - have ha := positiveRoot_represents M cs ⟨t,ht⟩ - have hta : rootRef a=t := congrArg (fun r : {r : W // cs.IsReflection r} => r.val) - ((positiveRootEquiv M cs).symm_apply_apply ⟨t,ht⟩) - have hx : ¬ rootInverted x a := by - intro hi - have h := (ha.inversion_iff a.property.2 x).mp hi - have hh : cs.length (t*x) < cs.length x := h.2 - rw [← het] at hh - exact (not_lt_of_gt hxy.1) hh - have hae : rootRef a*x=y := by rw [hta]; exact het.symm - obtain ⟨b,hab,hpos⟩ := exists_positive_plane x a hx (by rwa [hae]) - obtain ⟨B⟩ := nonempty_planeBasis a b hab - let P := rootPlane a b - have haP : a.val ∈ P := Submodule.subset_span (Set.mem_insert _ _) - obtain ⟨a₀,g,hg,hgx,hmin⟩ := planeCoset_exists_minimal M cs P x - let X : planeSubgroup M cs P := ⟨g,hg⟩ - let T : planeSubgroup M cs P := ⟨rootRef a, - ((rootReflection_represents M cs a).planeSubgroup_mem_iff M cs).mpr haP⟩ - let Y := T*X - have hxEq : (X:W)*a₀=x := hgx.symm - have hyEq : (Y:W)*a₀=y := by - change (rootRef a*g)*a₀=y - rw [mul_assoc, ← hgx, hae] - have hrel : BruhatStep B.system X Y := (B.coset_step_iff hmin X Y).mp - (by simpa only [hxEq,hyEq] using hxy) - have hLx := B.coset_length_eq hmin X - have hLy := B.coset_length_eq hmin Y - rw [hxEq] at hLx - rw [hyEq] at hLy - have hdegree := planeWeight_relative_degree x a b hab hx - rw [hae,hLx,hLy] at hdegree - have hlen' : B.system.length X+1 < B.system.length Y := by omega - obtain ⟨p,q,r,s,hpq,hrs,hXp,hXq,hpr,hps,hqr,hqs,hrY,hsY⟩ := - Dihedral.edge_diamond B.system hrel hlen' - have hinj : Function.Injective (fun z : planeSubgroup M cs P => (z:W)*a₀) := by - intro p q hpq - exact Subtype.ext (mul_right_cancel hpq) - refine ⟨(p:W)*a₀,(q:W)*a₀,(r:W)*a₀,(s:W)*a₀, - fun h => hpq (hinj h),fun h => hrs (hinj h),?_,?_,?_,?_,?_,?_,?_,?_⟩ - · simpa only [hxEq] using (B.coset_step_iff hmin X p).mpr hXp - · simpa only [hxEq] using (B.coset_step_iff hmin X q).mpr hXq - · exact (B.coset_step_iff hmin p r).mpr hpr - · exact (B.coset_step_iff hmin p s).mpr hps - · exact (B.coset_step_iff hmin q r).mpr hqr - · exact (B.coset_step_iff hmin q s).mpr hqs - · simpa only [hyEq] using (B.coset_step_iff hmin r Y).mpr hrY - · simpa only [hyEq] using (B.coset_step_iff hmin s Y).mpr hsY - -end KLInvariance.TitsSpace - -namespace KLInvariance -variable {I W : Type*} [Fintype I] [Group W] {M : CoxeterMatrix I} - -/-- General unlabelled Bruhat graph reconstruction completeness, for genuine -finite-rank Coxeter systems and arbitrary bottoms and interval ranks. -/ -theorem diamondEdges_of_bruhatStep (cs : CoxeterSystem M W) - {u b : W} {x y : Interval cs u b} (hxy : BruhatStep cs x.val y.val) : - DiamondEdges x y := by - suffices ∀ n : ℕ, ∀ x y : Interval cs u b, - cs.length y.val-cs.length x.val=n → BruhatStep cs x.val y.val → - DiamondEdges x y by - exact this _ x y rfl hxy - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro x y hn hxy - by_cases he : cs.length y.val=cs.length x.val+1 - · exact DiamondEdges.cover (interval_covBy_of_length_succ cs - (Relation.ReflTransGen.single hxy) he) - · have hn' : cs.length x.val+1 < cs.length y.val := by have := hxy.1; omega - obtain ⟨a,bm,c,d,hab,hcd,hxa,hxb,hac,had,hbc,hbd,hcy,hdy⟩ := - TitsSpace.ambient_edge_diamond hxy hn' - have leOf {p q : W} (h : BruhatStep cs p q) : BruhatLE cs p q := - Relation.ReflTransGen.single h - let A : Interval cs u b := ⟨a,bruhat_trans cs x.property.1 (leOf hxa), - bruhat_trans cs (leOf hac) (bruhat_trans cs (leOf hcy) y.property.2)⟩ - let B : Interval cs u b := ⟨bm,bruhat_trans cs x.property.1 (leOf hxb), - bruhat_trans cs (leOf hbc) (bruhat_trans cs (leOf hcy) y.property.2)⟩ - let C : Interval cs u b := ⟨c, - bruhat_trans cs x.property.1 (bruhat_trans cs (leOf hxa) (leOf hac)), - bruhat_trans cs (leOf hcy) y.property.2⟩ - let D : Interval cs u b := ⟨d, - bruhat_trans cs x.property.1 (bruhat_trans cs (leOf hxa) (leOf had)), - bruhat_trans cs (leOf hdy) y.property.2⟩ - have hsmall {p q : Interval cs u b} (hpq : BruhatStep cs p.val q.val) - (hp : cs.length x.val ≤ cs.length p.val) - (hq : cs.length q.val ≤ cs.length y.val) - (hs : cs.length x.val < cs.length p.val ∨ cs.length q.val < cs.length y.val) : - DiamondEdges p q := by - exact ih _ (by omega) p q rfl hpq - have h₁ := hxa.1 - have h₂ := hxb.1 - have h₃ := hac.1 - have h₄ := had.1 - have h₅ := hbc.1 - have h₆ := hbd.1 - have h₇ := hcy.1 - have h₈ := hdy.1 - refine DiamondEdges.diamond - (hsmall (p := x) (q := A) hxa ?_ ?_ ?_) - (hsmall (p := x) (q := B) hxb ?_ ?_ ?_) - (hsmall (p := A) (q := C) hac ?_ ?_ ?_) - (hsmall (p := A) (q := D) had ?_ ?_ ?_) - (hsmall (p := B) (q := C) hbc ?_ ?_ ?_) - (hsmall (p := B) (q := D) hbd ?_ ?_ ?_) - (hsmall (p := C) (q := y) hcy ?_ ?_ ?_) - (hsmall (p := D) (q := y) hdy ?_ ?_ ?_) - (fun h => hab (congrArg Subtype.val h)) - (fun h => hcd (congrArg Subtype.val h)) - all_goals first | omega | (dsimp only [A,B,C,D]; omega) - -/-- An abstract interval order isomorphism determines its actual directed -reflection edges. No root labels, generators or geometric data are supplied to -that isomorphism. This proves the finite-rank graph input of the source main. -/ -theorem intervalIso_bruhatStep_iff {I' W' : Type*} [Fintype I'] [Group W'] - {M' : CoxeterMatrix I'} (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (e : Interval cs u b ≃o Interval cs' u' b') - (x y : Interval cs u b) : - BruhatStep cs' (e x).val (e y).val ↔ BruhatStep cs x.val y.val := by - constructor - · intro h - exact diamondEdges_bruhatStep cs ((DiamondEdges.map_iff e).mp - (diamondEdges_of_bruhatStep cs' h)) - · intro h - exact diamondEdges_bruhatStep cs' ((diamondEdges_of_bruhatStep cs h).map e) - -end KLInvariance - -end - - -section - -/-! Rank-two Frobenius extension for an actual reflection on a symmetric -algebra. This supplies the elementary simple-reflection duality input; it -is not a proof of BMP or Elias--Williamson self-duality/characters. -/ -namespace KLInvariance.ReflectionFrobenius -universe uk ua uv -variable {k : Type uk} [Field k] [CharZero k] - {A : Type ua} [CommRing A] [IsDomain A] [Algebra k A] - -noncomputable section - -def fixed (τ : A ≃ₐ[k] A) : Subalgebra k A := - AlgHom.equalizer τ.toAlgHom (AlgHom.id k A) - -omit [CharZero k] [IsDomain A] in -@[simp] theorem mem_fixed (τ : A ≃ₐ[k] A) (a : A) : - a ∈ fixed τ ↔ τ a = a := Iff.rfl - -omit [CharZero k] [IsDomain A] in - theorem fixed_val (τ : A ≃ₐ[k] A) (a : fixed τ) : τ (a : A) = a := a.property - -variable (τ : A ≃ₐ[k] A) (α : A) - -def expand : (fixed τ × fixed τ) →ₗ[fixed τ] A where - toFun a := (a.1 : A) + α * (a.2 : A) - map_add' a b := by simp; ring - map_smul' c a := by simp only [Prod.smul_fst, Prod.smul_snd, smul_eq_mul, - Subalgebra.coe_mul, Subalgebra.smul_def, RingHom.id_apply]; ring - -omit [CharZero k] [IsDomain A] in -@[simp] theorem expand_apply (a : fixed τ × fixed τ) : - expand τ α a = (a.1 : A) + α * (a.2 : A) := rfl - -variable (hinv : Function.Involutive τ) (hα : α ≠ 0) (hanti : τ α = -α) - (hdiv : ∀ a : A, α ∣ a - τ a) - -omit [CharZero k] in -include hinv hα hanti in - theorem quotient_fixed {a d : A} (hd : a - τ a = α * d) : τ d = d := by - have hh := congrArg τ hd - simp only [map_sub, map_mul, hinv a, hanti] at hh - apply mul_left_cancel₀ hα - linear_combination hh + hd - -include hα hanti in - theorem expand_injective : Function.Injective (expand τ α) := by - intro a b hab - have ht := congrArg τ hab - simp only [expand_apply, map_add, map_mul, fixed_val, hanti] at ht - have he : (2 : A) * α * ((a.2 : A) - (b.2 : A)) = 0 := by - simp only [expand_apply] at hab - linear_combination hab - ht - have htwo : (2 : A) ≠ 0 := by - have hi : Function.Injective (algebraMap k A) := (algebraMap k A).injective - exact fun h => two_ne_zero (hi (by simpa only [map_ofNat, map_zero] using h : algebraMap k A (2:k) = algebraMap k A 0)) - have h2 : (a.2 : A) = (b.2 : A) := sub_eq_zero.mp - ((mul_eq_zero.mp he).resolve_left (mul_ne_zero htwo hα)) - have h1 : (a.1 : A) = (b.1 : A) := by - simpa only [expand_apply, h2, add_left_inj] using hab - exact Prod.ext (Subtype.ext h1) (Subtype.ext h2) - -include hinv hα hanti hdiv in - theorem expand_surjective : Function.Surjective (expand τ α) := by - intro a - obtain ⟨d, hd⟩ := hdiv a - have hdf : τ d = d := quotient_fixed τ α hinv hα hanti hd - let h : k := (2:k)⁻¹ - have htwo : (2:A) * algebraMap k A h = 1 := by - rw [show (2:A) = algebraMap k A (2:k) by exact (map_ofNat (algebraMap k A) 2).symm, ← map_mul] - simp [h] - let c₀ : fixed τ := ⟨algebraMap k A h * (a + τ a), by - simp only [mem_fixed, map_mul, AlgEquiv.commutes, map_add, hinv a] - ring⟩ - let c₁ : fixed τ := ⟨algebraMap k A h * d, by - simp only [mem_fixed, map_mul, AlgEquiv.commutes, hdf]⟩ - refine ⟨(c₀,c₁), ?_⟩ - change algebraMap k A h * (a + τ a) + α * (algebraMap k A h * d) = a - linear_combination a * htwo - (algebraMap k A h) * hd - -/-- The actual invariant-ring basis `1, α`, with no finiteness assumption. -/ -def coordinates : A ≃ₗ[fixed τ] (fixed τ × fixed τ) := - (LinearEquiv.ofBijective (expand τ α) - ⟨expand_injective τ α hα hanti, expand_surjective τ α hinv hα hanti hdiv⟩).symm - -@[simp] theorem expand_coordinates (a : A) : - expand τ α (coordinates τ α hinv hα hanti hdiv a) = a := - (coordinates τ α hinv hα hanti hdiv).symm_apply_apply a - -@[simp] theorem coordinates_expand (a : fixed τ × fixed τ) : - coordinates τ α hinv hα hanti hdiv (expand τ α a) = a := - (coordinates τ α hinv hα hanti hdiv).apply_symm_apply a - - -def trace : A →ₗ[fixed τ] fixed τ := - (LinearMap.snd _ _ _).comp (coordinates τ α hinv hα hanti hdiv).toLinearMap - - theorem trace_expand (a : fixed τ × fixed τ) : - trace τ α hinv hα hanti hdiv (expand τ α a) = a.2 := by - change (coordinates τ α hinv hα hanti hdiv (expand τ α a)).2 = a.2 - rw [coordinates_expand] - -omit [CharZero k] [IsDomain A] in -include hanti in - theorem square_fixed : α * α ∈ fixed τ := by - simp only [mem_fixed, map_mul, hanti, neg_mul_neg] - - theorem trace_mul (a b : A) : - trace τ α hinv hα hanti hdiv (a*b) = - (coordinates τ α hinv hα hanti hdiv a).1 * - (coordinates τ α hinv hα hanti hdiv b).2 + - (coordinates τ α hinv hα hanti hdiv a).2 * - (coordinates τ α hinv hα hanti hdiv b).1 := by - let c := coordinates τ α hinv hα hanti hdiv a - let d := coordinates τ α hinv hα hanti hdiv b - let α₂ : fixed τ := ⟨α*α, square_fixed τ α hanti⟩ - have he : a*b = expand τ α - (c.1*d.1+α₂*c.2*d.2, c.1*d.2+c.2*d.1) := by - rw [← expand_coordinates τ α hinv hα hanti hdiv a, - ← expand_coordinates τ α hinv hα hanti hdiv b] - change ((c.1:A)+α*(c.2:A))*((d.1:A)+α*(d.2:A)) = - (c.1:A)*(d.1:A)+(α*α)*(c.2:A)*(d.2:A)+ - α*((c.1:A)*(d.2:A)+(c.2:A)*(d.1:A)) - ring - rw [he,trace_expand] - -section Pair -variable (R : Type*) [CommRing R] - -def crossPair : (R × R) →ₗ[R] Module.Dual R (R × R) where - toFun a := - { toFun := fun b => a.1*b.2+a.2*b.1 - map_add' := by intro b c; simp; ring - map_smul' := by intro r b; simp; ring } - map_add' := by intro a b; apply LinearMap.ext; intro c; simp; ring - map_smul' := by intro r a; apply LinearMap.ext; intro b; simp; ring - - theorem crossPair_bijective : Function.Bijective (crossPair R) := by - constructor - · intro a b hab - have h₁ := congrArg (fun f : Module.Dual R (R×R) => f (0,1)) hab - have h₂ := congrArg (fun f : Module.Dual R (R×R) => f (1,0)) hab - exact Prod.ext (by simpa [crossPair] using h₁) (by simpa [crossPair] using h₂) - · intro f - refine ⟨(f (0,1), f (1,0)), ?_⟩ - apply LinearMap.ext - intro a - have ha : a = a.1 • (1,0) + a.2 • (0,1) := by simp - change f (0,1)*a.2 + f (1,0)*a.1 = f a - calc - _ = a.1 * f (1,0) + a.2 * f (0,1) := by ring - _ = f (a.1 • (1,0) + a.2 • (0,1)) := by rw [map_add,map_smul,map_smul]; rfl - _ = f a := congrArg f ha.symm - -def crossPairEquiv : (R × R) ≃ₗ[R] Module.Dual R (R × R) := - LinearEquiv.ofBijective (crossPair R) (crossPair_bijective R) - -end Pair - -/-- The Frobenius duality over the invariant ring is integral and perfect. -/ -def duality : A ≃ₗ[fixed τ] Module.Dual (fixed τ) A := - (coordinates τ α hinv hα hanti hdiv).trans - ((crossPairEquiv (fixed τ)).trans - (coordinates τ α hinv hα hanti hdiv).dualMap) - - theorem duality_apply (a b : A) : - duality τ α hinv hα hanti hdiv a b = trace τ α hinv hα hanti hdiv (a*b) := by - rw [trace_mul] - rfl - - theorem duality_balanced (a b c : A) : - duality τ α hinv hα hanti hdiv (c*a) b = - duality τ α hinv hα hanti hdiv a (c*b) := by - rw [duality_apply,duality_apply] - congr 1 - ring - - -section Symmetric -variable {V : Type uv} [AddCommGroup V] [Module k V] - -def symmetricMap (e : V ≃ₗ[k] V) : SymmetricAlgebra k V →ₐ[k] SymmetricAlgebra k V := - SymmetricAlgebra.lift ((SymmetricAlgebra.ι k V).comp e.toLinearMap) - -omit [CharZero k] in -@[simp] theorem symmetricMap_ι (e : V ≃ₗ[k] V) (v : V) : - symmetricMap e (SymmetricAlgebra.ι k V v) = SymmetricAlgebra.ι k V (e v) := by - simp [symmetricMap] - -omit [CharZero k] in - theorem symmetricMap_comp (e d : V ≃ₗ[k] V) : - (symmetricMap d).comp (symmetricMap e) = symmetricMap (e.trans d) := by - apply SymmetricAlgebra.algHom_ext - ext v - simp - -omit [CharZero k] in - theorem symmetricMap_refl : symmetricMap (LinearEquiv.refl k V) = - AlgHom.id k (SymmetricAlgebra k V) := by - apply SymmetricAlgebra.algHom_ext - ext v - simp - -/-- The algebra action is induced by the linear reflection, not postulated. -/ -def symmetricAction (e : V ≃ₗ[k] V) : SymmetricAlgebra k V ≃ₐ[k] SymmetricAlgebra k V := - AlgEquiv.ofAlgHom (symmetricMap e) (symmetricMap e.symm) - (by rw [symmetricMap_comp,LinearEquiv.symm_trans_self,symmetricMap_refl]) - (by rw [symmetricMap_comp,LinearEquiv.self_trans_symm,symmetricMap_refl]) - -omit [CharZero k] in -@[simp] theorem symmetricAction_ι (e : V ≃ₗ[k] V) (v : V) : - symmetricAction e (SymmetricAlgebra.ι k V v) = SymmetricAlgebra.ι k V (e v) := - symmetricMap_ι e v - -variable (root : V) (coroot : Module.Dual k V) (hroot : coroot root = 2) - -abbrev reflectionAction : SymmetricAlgebra k V ≃ₐ[k] SymmetricAlgebra k V := - symmetricAction (Module.reflection hroot) - -omit [CharZero k] in - theorem reflectionAction_involutive : Function.Involutive (reflectionAction root coroot hroot) := by - intro a - have he : (reflectionAction root coroot hroot).toAlgHom.comp - (reflectionAction root coroot hroot).toAlgHom = - AlgHom.id k (SymmetricAlgebra k V) := by - apply SymmetricAlgebra.algHom_ext - ext v - simp [Module.involutive_reflection hroot v] - exact congrArg (fun f : SymmetricAlgebra k V →ₐ[k] SymmetricAlgebra k V => f a) he - -omit [CharZero k] in - theorem reflectionAction_anti : - reflectionAction root coroot hroot (SymmetricAlgebra.ι k V root) = - -SymmetricAlgebra.ι k V root := by - simp - -include hroot in - theorem reflectionRoot_ne_zero : SymmetricAlgebra.ι k V root ≠ 0 := by - intro he - have hh := congrArg (SymmetricAlgebra.lift coroot) he - rw [SymmetricAlgebra.lift_ι_apply,map_zero,hroot] at hh - exact two_ne_zero hh - -omit [CharZero k] in - theorem reflectionAction_divisible (a : SymmetricAlgebra k V) : - SymmetricAlgebra.ι k V root ∣ a-reflectionAction root coroot hroot a := by - induction a using SymmetricAlgebra.induction with - | algebraMap c => simp - | ι v => - refine ⟨algebraMap k (SymmetricAlgebra k V) (coroot v), ?_⟩ - rw [reflectionAction,symmetricAction_ι,Module.reflection_apply,map_sub,map_smul] - simp only [sub_sub_cancel,Algebra.smul_def] - ring - | mul a b ha hb => - obtain ⟨c,hc⟩ := ha - obtain ⟨d,hd⟩ := hb - refine ⟨c*b+(reflectionAction root coroot hroot a)*d, ?_⟩ - rw [map_mul] - linear_combination b*hc+(reflectionAction root coroot hroot a)*hd - | add a b ha hb => - simpa only [map_add, add_sub_add_comm] using dvd_add ha hb - -/-- A genuine simple-reflection integral Frobenius extension in characteristic -zero, for the symmetric algebra of any representation carrying the reflection. -/ -def reflectionDuality : - SymmetricAlgebra k V ≃ₗ[fixed (reflectionAction root coroot hroot)] - Module.Dual (fixed (reflectionAction root coroot hroot)) (SymmetricAlgebra k V) := - duality (reflectionAction root coroot hroot) (SymmetricAlgebra.ι k V root) - (reflectionAction_involutive root coroot hroot) (reflectionRoot_ne_zero root coroot hroot) - (reflectionAction_anti root coroot hroot) (reflectionAction_divisible root coroot hroot) - -end Symmetric - -end -end KLInvariance.ReflectionFrobenius - -end - - -section - -/-! Frobenius extensions for the actual simple reflections of the extended -theorem realization, not abstract reflection data carried by the target. -/ - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.SheafMorphisms + +namespace OAI + +/-! +Graded decomposition characters, reflection-plane algebras and reflection Frobenius structures. +-/ + +section + +namespace KLInvariance.MomentGraph.GradedSheaf +open _root_.OAI.KLInvariance.Graded Polynomial +universe uk us um +variable {k : Type uk} [Field k] {σ : Type us} [Finite σ] + {V E : Type um} [PartialOrder V] {G : OrderedGraph V E} +noncomputable section + + def freeStalkChar (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) + (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) (x : V) : Polynomial ℤ := by + let := hf x + exact (B.vertex x).char + + theorem ModelSum.character {α : E → MvPolynomial σ k} + (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) + [Fintype V] {U : Set V} {B : GradedSheaf (𝓐 := polynomialGrading k σ) G} + (h : ModelSum O.sheaf U B) : + ∃ hmul : V → Polynomial ℤ, + (∀ y n, 0 ≤ (hmul y).coeff n) ∧ + (∀ y, y ∉ U → hmul y=0) ∧ + ∀ x, freeStalkChar B (h.free O) x = + ∑ y, hmul y*freeStalkChar (O.sheaf y) (O.free y) x := by + classical + induction h with + | zero => + refine ⟨0,by simp,by simp,?_⟩ + intro x + simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero] + exact ModuleData.char_zero _ + | @add B h c hc n d ih => + obtain ⟨m,hm,hsupp,heq⟩ := ih + let a : Polynomial ℤ := ∑ i, X^(d i) + have ha (r : ℕ) : 0 ≤ a.coeff r := by + simp only [a,Polynomial.finsetSum_coeff,Polynomial.coeff_X_pow] + exact Finset.sum_nonneg (fun i _ => by split <;> norm_num) + refine ⟨fun y => m y+if y=c then a else 0,?_,?_,?_⟩ + · intro y r + rw [Polynomial.coeff_add] + apply add_nonneg (hm y r) + split + · exact ha r + · simp + · intro y hy + have hne : y≠c := fun hh => hy (hh ▸ hc) + simp [hsupp y hy,hne] + · intro x + let _ := h.free O x + let _ := O.free c x + change ((B.vertex x).prod (ModuleData.pi (fun i => ((O.sheaf c).vertex x).shift (d i)))).char = _ + rw [ModuleData.char_prod,ModuleData.char_pi] + simp only [ModuleData.char_shift] + change freeStalkChar B (h.free O) x + _ = _ + rw [heq x] + simp only [add_mul,Finset.sum_add_distrib] + congr 1 + rw [← Finset.sum_mul] + simp only [ite_mul,zero_mul,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + rfl + + theorem exists_stalkCharacter_decomposition [Fintype V] [Fintype E] + {α : E → MvPolynomial σ k} + (O : BoundaryModels (polynomialGrading_negative k σ) (G := G) α) + (B : GradedSheaf (𝓐 := polynomialGrading k σ) G) + (hf : ∀ x, Module.Free (MvPolynomial σ k) (B.vertex x)) + (hq : B.UpperQuotient α) (hfl : B.forget.Flabby) (hg : B.forget.Generated) : + ∃ hmul : V → Polynomial ℤ, (∀ y n, 0 ≤ (hmul y).coeff n) ∧ + ∀ x, freeStalkChar B hf x = + ∑ y, hmul y*freeStalkChar (O.sheaf y) (O.free y) x := by + obtain ⟨C,hC,⟨j⟩⟩ := exists_modelSumIso (polynomialGrading_zero k σ) O B hf hq hfl hg + obtain ⟨m,hm,_,heq⟩ := hC.character O + refine ⟨m,hm,fun x => ?_⟩ + rw [← heq x] + let _ := hf x + let _ := hC.free O x + exact ModuleData.character_eq_of_gradedEquiv (j.vertex x) + (j.vertex_graded x) + +end +end KLInvariance.MomentGraph.GradedSheaf + +end + + +section + +namespace KLInvariance.BruhatGraph +open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial +universe u +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type u} [Group W] (cs : CoxeterSystem M W) (b : W) + {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) +noncomputable section +local instance (p : Prop) : Decidable p := Classical.propDecidable p + + def lowerCharacter (c x : Interval cs 1 b) : Polynomial ℤ := + if h : x≤c then stalkCharacter cs 1 c.val basis (one_bruhat cs c.val) + ⟨x.val,x.property.1,h⟩ else 0 + + theorem boundaryModels_character (c x : Interval cs 1 b) : + GradedSheaf.freeStalkChar ((boundaryModels cs b basis).sheaf c) + ((boundaryModels cs b basis).free c) x=lowerCharacter cs b basis c x := by + let _ := (boundaryModels cs b basis).free c x + by_cases hx : x≤c + · rw [lowerCharacter,dite_eq_left hx] + let B := lowerIntervalBoundary cs b basis c + let _ := B.sheaf.lowerExtend_free B.free x + let _ := (boundarySheaf cs 1 c.val basis (one_bruhat cs c.val)).free ⟨x.val,x.property.1,hx⟩ + exact ModuleData.character_eq_of_gradedEquiv (B.sheaf.lowerExtendVertex ⟨x,hx⟩) + (B.sheaf.lowerExtendVertex_graded ⟨x,hx⟩) + · rw [lowerCharacter,dite_eq_right hx] + let _ := (boundaryModels cs b basis).support c x hx + exact ModuleData.char_zero _ + + theorem lowerCharacter_zero (c x : Interval cs 1 b) (hx : ¬x≤c) : + lowerCharacter cs b basis c x=0 := dite_eq_right hx + + theorem lowerCharacter_nonneg (c x : Interval cs 1 b) (n : ℕ) : + 0≤(lowerCharacter cs b basis c x).coeff n := by + unfold lowerCharacter + split + · exact stalkCharacter_coeff_nonneg cs 1 c.val basis (one_bruhat cs c.val) _ n + · simp + +end +end KLInvariance.BruhatGraph + +end + + +section + +/-! Integral pair-projection quotients. The purpose is the actual localization +functor from a tensor bimodule to a moment-graph sheaf; no flabbiness, stalk +freeness, BMP identification or character theorem is assumed or asserted. -/ +namespace KLInvariance.PairProjection +universe u v w z +variable {R : Type u} [CommRing R] + {M : Type v} [AddCommGroup M] [Module R M] + {X : Type w} [AddCommGroup X] [Module R X] + {Y : Type z} [AddCommGroup Y] [Module R Y] + (f : M →ₗ[R] X) (g : M →ₗ[R] Y) +noncomputable section + +def relation : Submodule R (X × Y) := LinearMap.range (f.prod g) +abbrev Edge := (X × Y) ⧸ relation f g + +def lower : X →ₗ[R] Edge f g := (relation f g).mkQ.comp (LinearMap.inl R X Y) +def upper : Y →ₗ[R] Edge f g := -((relation f g).mkQ.comp (LinearMap.inr R X Y)) + +theorem diagonal_zero (m : M) : (relation f g).mkQ (f m,g m)=0 := by + exact (Submodule.Quotient.mk_eq_zero _).mpr ⟨m,rfl⟩ + +theorem compatible (m : M) : lower f g (f m)=upper f g (g m) := by + have h := diagonal_zero f g m + have hp : (f m,g m)=(f m,0)+(0,g m) := by simp + rw [hp,map_add] at h + exact eq_neg_of_add_eq_zero_left h + +theorem compatible_iff (x : X) (y : Y) : + lower f g x=upper f g y ↔ ∃ m : M, f m=x ∧ g m=y := by + change (relation f g).mkQ (x,0) = -((relation f g).mkQ (0,y)) ↔ _ + rw [eq_neg_iff_add_eq_zero,← map_add] + rw [show ((x,0)+(0,y) : X × Y)=(x,y) by simp] + change (Submodule.Quotient.mk (x,y) : Edge f g)=0 ↔ _ + rw [Submodule.Quotient.mk_eq_zero] + constructor + · rintro ⟨m,hm⟩ + exact ⟨m,congrArg Prod.fst hm,congrArg Prod.snd hm⟩ + · rintro ⟨m,hm,hn⟩ + exact ⟨m,Prod.ext hm hn⟩ + +theorem kernel_lower (x : X) : lower f g x=0 ↔ ∃ m : M, f m=x ∧ g m=0 := by + change (relation f g).mkQ (x,0)=0 ↔ _ + change Submodule.Quotient.mk (x,0) = 0 ↔ _ + rw [Submodule.Quotient.mk_eq_zero] + constructor + · rintro ⟨m,hm⟩ + exact ⟨m,congrArg Prod.fst hm,congrArg Prod.snd hm⟩ + · rintro ⟨m,hm,hn⟩ + exact ⟨m,Prod.ext hm hn⟩ + +theorem lower_surjective (hg : Function.Surjective g) : + Function.Surjective (lower f g) := by + intro v + obtain ⟨⟨x,y⟩,rfl⟩ := (relation f g).mkQ_surjective v + obtain ⟨m,rfl⟩ := hg y + refine ⟨x-f m,?_⟩ + change (relation f g).mkQ (x-f m,0) = (relation f g).mkQ (x,g m) + have hp : (x-f m,0)=(x,g m)-(f m,g m) := by simp + rw [hp,map_sub,diagonal_zero,sub_zero] + +theorem upper_surjective (hf : Function.Surjective f) : + Function.Surjective (upper f g) := by + intro v + obtain ⟨⟨x,y⟩,rfl⟩ := (relation f g).mkQ_surjective v + obtain ⟨m,rfl⟩ := hf x + refine ⟨g m-y,?_⟩ + change -((relation f g).mkQ (0,g m-y)) = (relation f g).mkQ (f m,y) + have hp : (0,g m-y)=(f m,g m)-(f m,y) := by simp + rw [hp,map_sub,diagonal_zero,zero_sub,neg_neg] + +/-- A genuine right-action eigenvalue difference annihilates the edge +quotient. This uses only the integral module, not a fraction-field equality. -/ +theorem difference_annihilates (hf : Function.Surjective f) + (hg : Function.Surjective g) (T : M →ₗ[R] M) (r s : R) + (hr : ∀ m, f (T m)=r • f m) (hs : ∀ m, g (T m)=s • g m) + (v : Edge f g) : (r-s) • v=0 := by + obtain ⟨x,rfl⟩ := lower_surjective f g hg v + rw [← map_smul] + apply (kernel_lower f g _).mpr + obtain ⟨m,rfl⟩ := hf x + refine ⟨T m-s • m,?_,?_⟩ + · rw [map_sub,map_smul,hr,sub_smul] + · rw [map_sub,map_smul,hs,sub_self] + +end +end KLInvariance.PairProjection + +end + + +section + + +namespace KLInvariance.Dihedral +noncomputable section + +variable {G : Type*} [Group G] + +/-- The matrix of a pair of distinct involutions. -/ +def pairMatrix (s t : G) (hs : s * s = 1) (hst : s ≠ t) : CoxeterMatrix Bool where + M i j := if i = j then 1 else orderOf (s * t) + isSymm := by + ext i j + change (if j = i then 1 else orderOf (s*t)) = if i = j then 1 else orderOf (s*t) + cases i <;> cases j <;> rfl + diagonal i := ite_eq_left rfl + off_diagonal i j hij := by + rw [ite_eq_right hij] + intro h + have he := orderOf_eq_one_iff.mp h + apply hst + calc + s = s * (s * t) := by rw [he, mul_one] + _ = t := by rw [← mul_assoc, hs, one_mul] + +/-- Alternating even words are powers of the product of the two generators. -/ +theorem wordProd_alt_even {N : CoxeterMatrix Bool} {H : Type*} [Group H] + (cs : CoxeterSystem N H) (i : Bool) (n : ℕ) : + cs.wordProd (alt i (2 * n)) = (cs.simple i * cs.simple (!i)) ^ n := by + induction n with + | zero => simp + | succ n ih => + rw [show 2 * (n + 1) = 2 * n + 2 by omega, alt_add_two] + rw [cs.wordProd_cons, cs.wordProd_cons, ih, pow_succ'] + exact (mul_assoc _ _ _).symm + +/-- Homomorphisms out of a rank-two Coxeter group that do not lower +its product order and do not kill either generator are injective. -/ +theorem injective_of_simple_order {N : CoxeterMatrix Bool} {H : Type*} [Group H] + (cs : CoxeterSystem N H) (f : H →* G) + (hne : ∀ i, f (cs.simple i) ≠ 1) + (horder : ∀ i, orderOf (f (cs.simple i) * f (cs.simple (!i))) = N i (!i)) : + Function.Injective f := by + apply (injective_iff_map_eq_one f).mpr + intro w hw + rcases Nat.even_or_odd (cs.length w) with he | ho + · obtain ⟨n, hn⟩ := he + have hn' : cs.length w = 2 * n := by omega + obtain ⟨i, hi⟩ := exists_alt cs w + rw [hn', wordProd_alt_even] at hi + have hpow : (f (cs.simple i) * f (cs.simple (!i))) ^ n = 1 := by + simpa only [hi, map_pow, map_mul] using hw + have hdiv := orderOf_dvd_of_pow_eq_one hpow + rw [horder i] at hdiv + obtain ⟨k, hk⟩ := hdiv + rw [hi, hk, pow_mul, cs.simple_mul_simple_pow, one_pow] + · obtain ⟨a, i, ha⟩ := (reflection_iff_odd cs w).mpr ho + have h := hw + rw [ha, map_mul, map_mul, map_inv] at h + apply False.elim + apply hne i + have h' := congrArg (fun z => (f a)⁻¹ * z * f a) h + simpa only [mul_assoc, inv_mul_cancel_left, inv_mul_cancel, mul_one, + one_mul, mul_inv_cancel_left] using h' + +variable (s t : G) (hs : s * s = 1) (ht : t * t = 1) (hst : s ≠ t) + +/-- The map from the genuine presented rank-two Coxeter group. -/ +def pairLift : (pairMatrix s t hs hst).Group →* G := + (pairMatrix s t hs hst).toCoxeterSystem.lift + ⟨(fun i => if i then t else s), by + intro i j + cases i <;> cases j + · simpa [pairMatrix] using hs + · simp only [pairMatrix, Bool.false_eq_true, ↓reduceIte] + exact pow_orderOf_eq_one (s*t) + · simp only [pairMatrix, Bool.true_eq_false, Bool.false_eq_true, ↓reduceIte] + have hinv : (s*t)⁻¹ = t*s := by + rw [mul_inv_rev, (inv_eq_of_mul_eq_one_right ht), (inv_eq_of_mul_eq_one_right hs)] + rw [← hinv, inv_pow, pow_orderOf_eq_one, inv_one] + · simpa [pairMatrix] using ht⟩ + +@[simp] theorem pairLift_simple (i : Bool) : + pairLift s t hs ht hst ((pairMatrix s t hs hst).toCoxeterSystem.simple i) = + if i then t else s := by + apply CoxeterSystem.lift_apply_simple + +/-- No relation other than the Coxeter relations is introduced by the pair. -/ +theorem pairLift_injective (hs1 : s ≠ 1) (ht1 : t ≠ 1) : + Function.Injective (pairLift s t hs ht hst) := by + apply injective_of_simple_order (pairMatrix s t hs hst).toCoxeterSystem + · intro i + rw [pairLift_simple] + cases i <;> simp_all + · intro i + simp only [pairLift_simple] + cases i + · simp [pairMatrix] + · simp only [Bool.not_true, ↓reduceIte, pairMatrix, Bool.true_eq_false, Bool.false_eq_true] + have hinv : (s*t)⁻¹ = t*s := by + rw [mul_inv_rev, (inv_eq_of_mul_eq_one_right ht), (inv_eq_of_mul_eq_one_right hs)] + rw [← hinv, orderOf_inv] + +/-- The presented pair generates exactly the subgroup generated by its images. -/ +theorem pairLift_range : + (pairLift s t hs ht hst).range = Subgroup.closure {s, t} := by + apply le_antisymm + · rintro x ⟨w, rfl⟩ + apply (pairMatrix s t hs hst).toCoxeterSystem.simple_induction w + · intro i + rw [pairLift_simple] + cases i <;> apply Subgroup.subset_closure <;> simp + · simp only [map_one, Subgroup.one_mem] + · intro a b ha hb + rw [map_mul] + exact Subgroup.mul_mem _ ha hb + · apply (Subgroup.closure_le _).mpr + intro x hx + rcases Set.mem_insert_iff.mp hx with hx | hx + · rw [hx] + exact ⟨(pairMatrix s t hs hst).toCoxeterSystem.simple false, pairLift_simple _ _ _ _ _ _⟩ + · have : x = t := Set.mem_singleton_iff.mp hx + subst x + exact ⟨(pairMatrix s t hs hst).toCoxeterSystem.simple true, pairLift_simple _ _ _ _ _ _⟩ + +/-- An actual Coxeter system on the generated subgroup, not an extra assumption. -/ +def pairSystem (hs1 : s ≠ 1) (ht1 : t ≠ 1) : + CoxeterSystem (pairMatrix s t hs hst) (Subgroup.closure {s, t}) := + (pairMatrix s t hs hst).toCoxeterSystem.map + ((MulEquiv.ofBijective (pairLift s t hs ht hst).rangeRestrict + ⟨MonoidHom.rangeRestrict_injective_iff.mpr + (pairLift_injective s t hs ht hst hs1 ht1), + (pairLift s t hs ht hst).rangeRestrict_surjective⟩).trans + (MulEquiv.subgroupCongr (pairLift_range s t hs ht hst))) + +@[simp] theorem pairSystem_simple (hs1 : s ≠ 1) (ht1 : t ≠ 1) (i : Bool) : + ((pairSystem s t hs ht hst hs1 ht1).simple i : G) = if i then t else s := by + exact pairLift_simple s t hs ht hst i + +end +end KLInvariance.Dihedral + + +namespace KLInvariance.TitsSpace +open Module +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] {cs : CoxeterSystem M W} +noncomputable section + +/-- Any two distinct positive roots in a two-dimensional root plane span it. -/ +theorem rootPlane_eq_of_mem (a b l r : PositiveRoot M cs) (hab : a ≠ b) + (hl : l.val ∈ rootPlane a b) (hr : r.val ∈ rootPlane a b) (hlr : l ≠ r) : + rootPlane l r = rootPlane a b := by + apply Submodule.eq_of_le_of_finrank_eq + · apply Submodule.span_le.mpr + intro z hz + change z ∈ rootPlane a b + rcases Set.mem_insert_iff.mp hz with hz | hz + · rw [hz]; exact hl + · rw [Set.mem_singleton_iff.mp hz]; exact hr + · rw [rootPlane_finrank _ _ hlr, rootPlane_finrank _ _ hab] + +/-- Slope betweenness detects the actual positive cone, not only one implication. -/ +theorem positive_combination_of_slope_between (a b c : PositiveRoot M cs) + (hc : c.val ∈ rootPlane a b) + (hac : geometricSlope a < geometricSlope c) + (hcb : geometricSlope c < geometricSlope b) : + ∃ r s : ℝ, 0 < r ∧ 0 < s ∧ c.val = r • a.val + s • b.val := by + let f := geometricFunctional (M := M) (cs := cs) + obtain ⟨r, s, he⟩ := Submodule.mem_span_pair.mp hc + refine ⟨r, s, ?_, ?_, he.symm⟩ + all_goals + have ha := a.height_pos + have hb := b.height_pos + have hh := c.height_pos + have hfc := congrArg f he + have hhc := congrArg (height (I := I)) he + simp only [map_add, map_smul, smul_eq_mul] at hfc hhc + change f a.val / height a.val < + f c.val / height c.val at hac + change f c.val / height c.val < + f b.val / height b.val at hcb + have hab := lt_trans hac hcb + rw [div_lt_div_iff₀ ha hb] at hab + rw [div_lt_div_iff₀ ha hh] at hac + rw [div_lt_div_iff₀ hh hb] at hcb + · have heq : r * (f b.val * height a.val - + f a.val * height b.val) = + f b.val * height c.val - + f c.val * height b.val := by rw [← hfc, ← hhc]; ring + have hp : 0 < r * (f b.val * height a.val - + f a.val * height b.val) := by rw [heq]; linarith + exact (mul_pos_iff.mp hp).resolve_right (by intro h; linarith [h.2]) |>.1 + · have heq : s * (f b.val * height a.val - + f a.val * height b.val) = + f c.val * height a.val - + f a.val * height c.val := by rw [← hfc, ← hhc]; ring + have hp : 0 < s * (f b.val * height a.val - + f a.val * height b.val) := by rw [heq]; linarith + exact (mul_pos_iff.mp hp).resolve_right (by intro h; linarith [h.2]) |>.1 + +/-- Positivity is convex in the root cone. -/ +theorem noninverted_of_positive_combination (w : W) (a b c : PositiveRoot M cs) + {r s : ℝ} (hr : 0 ≤ r) (hs : 0 ≤ s) + (hc : c.val = r • a.val + s • b.val) + (ha : ¬ rootInverted w a) (hb : ¬ rootInverted w b) : + ¬ rootInverted w c := by + rw [not_rootInverted_iff] at ha hb ⊢ + intro i + rw [hc, map_add, map_smul, map_smul] + exact add_nonneg (mul_nonneg hr (ha i)) (mul_nonneg hs (hb i)) + +@[simp] theorem not_rootInverted_one (a : PositiveRoot M cs) : + ¬ rootInverted (1 : W) a := by + rw [not_rootInverted_iff] + simp only [inv_one, map_one] + exact a.property.2 + +@[simp] theorem rootInverted_ref_self (a : PositiveRoot M cs) : + rootInverted (rootRef a) a := by + simpa only [mul_one] using (rootInverted_mul_self 1 a).mpr (not_rootInverted_one a) + +/-- A root plane has an extreme positive root. Finiteness of inversion sets +replaces the false assertion that the (real-valued) root heights are discrete. -/ +theorem exists_plane_extreme_inverted (a b : PositiveRoot M cs) (hab : a ≠ b) : + ∃ p : PositiveRoot M cs, p.val ∈ rootPlane a b ∧ rootInverted (rootRef a) p ∧ + ((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope p ≤ geometricSlope r) ∨ + (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope r ≤ geometricSlope p)) := by + classical + let S := (finite_rootInverted (M := M) (cs := cs) (rootRef a)).toFinset.filter + (fun r => r.val ∈ rootPlane a b) + have hS (r : PositiveRoot M cs) : r ∈ S ↔ + rootInverted (rootRef a) r ∧ r.val ∈ rootPlane a b := by + simp only [S, Finset.mem_filter, Set.Finite.mem_toFinset, Set.mem_ofPred_eq] + have haP : a.val ∈ rootPlane a b := Submodule.subset_span (Set.mem_insert _ _) + have haS : a ∈ S := (hS a).mpr ⟨rootInverted_ref_self a, haP⟩ + obtain ⟨p, hp, hmin⟩ := S.exists_min_image geometricSlope ⟨a, haS⟩ + obtain ⟨q, hq, hmax⟩ := S.exists_max_image geometricSlope ⟨a, haS⟩ + by_cases hleft : ∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope p ≤ geometricSlope r + · exact ⟨p, (hS p).mp hp |>.2, (hS p).mp hp |>.1, Or.inl hleft⟩ + by_cases hright : ∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope r ≤ geometricSlope q + · exact ⟨q, (hS q).mp hq |>.2, (hS q).mp hq |>.1, Or.inr hright⟩ + push Not at hleft hright + obtain ⟨l, hlP, hlp⟩ := hleft + obtain ⟨r, hrP, hqr⟩ := hright + have hla := lt_of_lt_of_le hlp (hmin a haS) + have har := lt_of_le_of_lt (hmax a haS) hqr + have hlr : l ≠ r := fun h => (lt_trans hla har).ne (congrArg geometricSlope h) + have hplane := rootPlane_eq_of_mem a b l r hab hlP hrP hlr + have hlam : ¬ rootInverted (rootRef a) l := by + intro hi + exact (not_le_of_gt hlp) (hmin l ((hS l).mpr ⟨hi, hlP⟩)) + have hram : ¬ rootInverted (rootRef a) r := by + intro hi + exact (not_le_of_gt hqr) (hmax r ((hS r).mpr ⟨hi, hrP⟩)) + obtain ⟨c, d, hc, hd, he⟩ := positive_combination_of_slope_between l r a + (hplane.symm ▸ haP) hla har + exact False.elim ((noninverted_of_positive_combination (rootRef a) l r a + hc.le hd.le he hlam hram) (rootInverted_ref_self a)) + +/-- The canonical simple-root criterion stated on the actual ambient roots. -/ +def PlaneSimple (P : Submodule ℝ (I → ℝ)) (a : PositiveRoot M cs) : Prop := + a.val ∈ P ∧ ∀ b : PositiveRoot M cs, b.val ∈ P → + (rootInverted (rootRef a) b ↔ b = a) + +theorem rootInverted_ref_iff_flipped (a b : PositiveRoot M cs) : + rootInverted (rootRef a) b ↔ flipped a b := by + unfold rootInverted flipped + rw [(rootReflection M cs a).property.inv] + +/-- An angular extreme inverts exactly its own positive root. -/ +theorem planeSimple_of_extreme {P : Submodule ℝ (I → ℝ)} + (a : PositiveRoot M cs) (ha : a.val ∈ P) + (hext : (∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope a ≤ geometricSlope r) ∨ + (∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope r ≤ geometricSlope a)) : + PlaneSimple P a := by + refine ⟨ha, fun b hb => ⟨?_, ?_⟩⟩ + · intro hinv + by_contra hba + have hn := (rootInverted_ref_iff_flipped a b).mp hinv + have hp := partner_mem a b ha hb + have hs := negative_pair_sum a b hn + have hc := negative_pair_coefficient_pos a b hn + have he : a.val = (form M a.val b.val)⁻¹ • b.val + + (form M a.val b.val)⁻¹ • (partner a b).val := by + calc + a.val = (form M a.val b.val)⁻¹ • (form M a.val b.val • a.val) := by + rw [smul_smul, inv_mul_cancel₀ hc.ne', one_smul] + _ = _ := by rw [← hs, smul_add] + have hne : geometricSlope b ≠ geometricSlope (partner a b) := by + intro h + exact hba (negative_partner_fixed a b hn (geometricSlope_injective h).symm) + rcases lt_or_gt_of_ne hne with hlt | hlt + · have hh := geometricSlope_between b (partner a b) a + (inv_pos.mpr hc) (inv_pos.mpr hc) he hlt + rcases hext with hmin | hmax + · exact (not_lt_of_ge (hmin b hb)) hh.1 + · exact (not_lt_of_ge (hmax (partner a b) hp)) hh.2 + · have he' : a.val = (form M a.val b.val)⁻¹ • (partner a b).val + + (form M a.val b.val)⁻¹ • b.val := by rw [add_comm]; exact he + have hh := geometricSlope_between (partner a b) b a + (inv_pos.mpr hc) (inv_pos.mpr hc) he' hlt + rcases hext with hmin | hmax + · exact (not_lt_of_ge (hmin (partner a b) hp)) hh.1 + · exact (not_lt_of_ge (hmax b hb)) hh.2 + · intro h + rw [h] + exact rootInverted_ref_self a + +theorem PlaneSimple.partner_val {P : Submodule ℝ (I → ℝ)} + {a : PositiveRoot M cs} (ha : PlaneSimple P a) + {b : PositiveRoot M cs} (hb : b.val ∈ P) (hba : b ≠ a) : + (partner a b).val = action M cs (rootRef a) b.val := by + have hn : ¬ rootInverted (rootRef a) b := fun h => hba ((ha.2 b hb).mp h) + have hp := (not_rootInverted_iff (rootRef a) b).mp hn + rw [(rootReflection M cs a).property.inv] at hp + exact positiveAction_eq_of_nonneg _ _ hp + +theorem PlaneSimple.exists_nonpositive_pair {P : Submodule ℝ (I → ℝ)} + {a : PositiveRoot M cs} (ha : PlaneSimple P a) + {b : PositiveRoot M cs} (hb : b.val ∈ P) (hba : b ≠ a) : + ∃ c : PositiveRoot M cs, c.val ∈ P ∧ c ≠ a ∧ form M a.val c.val ≤ 0 := by + by_cases hn : form M a.val b.val ≤ 0 + · exact ⟨b, hb, hba, hn⟩ + · refine ⟨partner a b, partner_mem a b ha.1 hb, + fun h => hba ((partner_eq_self_of_eq a b).mp h), ?_⟩ + rw [ha.partner_val hb hba, (rootReflection_represents M cs a).action_formula] + simp only [map_sub, map_smul, smul_eq_mul, a.property.1.norm] + linarith + +theorem noninverted_ref_of_pairing_nonpos (a b : PositiveRoot M cs) + (hab : form M a.val b.val ≤ 0) : ¬ rootInverted (rootRef b) a := by + rw [not_rootInverted_iff, (rootReflection M cs b).property.inv, + (rootReflection_represents M cs b).action_formula] + have hba : form M b.val a.val ≤ 0 := by rwa [(form_symm M).eq] + intro i + exact sub_nonneg.mpr ((mul_nonpos_of_nonpos_of_nonneg hba (b.property.2 i)).trans + (a.property.2 i)) + +/-- The other endpoint exists even in an infinite or degenerate plane. -/ +theorem exists_opposite_plane_extreme (a b p : PositiveRoot M cs) (hab : a ≠ b) + (hp : p.val ∈ rootPlane a b) + (hext : (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope p ≤ geometricSlope r) ∨ + (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope r ≤ geometricSlope p)) : + ∃ q : PositiveRoot M cs, q.val ∈ rootPlane a b ∧ q ≠ p ∧ + (((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope p ≤ geometricSlope r) ∧ + (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope r ≤ geometricSlope q)) ∨ + ((∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope q ≤ geometricSlope r) ∧ + (∀ r : PositiveRoot M cs, r.val ∈ rootPlane a b → + geometricSlope r ≤ geometricSlope p))) := by + have hs := planeSimple_of_extreme p hp hext + have hother : ∃ r : PositiveRoot M cs, r.val ∈ rootPlane a b ∧ r ≠ p := by + by_cases hap : a = p + · refine ⟨b, Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)), ?_⟩ + exact fun h => hab (hap.trans h.symm) + · exact ⟨a, Submodule.subset_span (Set.mem_insert _ _), hap⟩ + obtain ⟨r, hrP, hrp⟩ := hother + obtain ⟨c, hcP, hcp, hcpair⟩ := hs.exists_nonpositive_pair hrP hrp + have hn := noninverted_ref_of_pairing_nonpos p c hcpair + have hplane := rootPlane_eq_of_mem a b c p hab hcP hp hcp + obtain ⟨q, hqP, hqinv, hqext⟩ := exists_plane_extreme_inverted c p hcp + rw [hplane] at hqP hqext + have hqp : q ≠ p := fun h => hn (h ▸ hqinv) + refine ⟨q, hqP, hqp, ?_⟩ + rcases hext with hmin | hmax + · refine Or.inl ⟨hmin, ?_⟩ + rcases hqext with hqmin | hqmax + · exact False.elim (hqp (geometricSlope_injective (le_antisymm + (hqmin p hp) (hmin q hqP)))) + · exact hqmax + · refine Or.inr ⟨?_, hmax⟩ + rcases hqext with hqmin | hqmax + · exact hqmin + · exact False.elim (hqp (geometricSlope_injective (le_antisymm + (hmax q hqP) (hqmax p hp)))) + +/-- Canonical angular endpoints of a plane; no Coxeter-system assertion is +built into this data. The latter will be proved from the inversion criterion. -/ +structure PlaneBasis (P : Submodule ℝ (I → ℝ)) where + left : PositiveRoot M cs + right : PositiveRoot M cs + distinct : left ≠ right + plane_eq : rootPlane left right = P + left_min : ∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope left ≤ geometricSlope r + right_max : ∀ r : PositiveRoot M cs, r.val ∈ P → geometricSlope r ≤ geometricSlope right + +theorem nonempty_planeBasis (a b : PositiveRoot M cs) (hab : a ≠ b) : + Nonempty (PlaneBasis (M := M) (cs := cs) (rootPlane a b)) := by + obtain ⟨p, hp, _, hext⟩ := exists_plane_extreme_inverted a b hab + obtain ⟨q, hq, hqp, hpair⟩ := exists_opposite_plane_extreme a b p hab hp hext + rcases hpair with ⟨hl, hr⟩ | ⟨hl, hr⟩ + · exact ⟨⟨p, q, hqp.symm, rootPlane_eq_of_mem a b p q hab hp hq hqp.symm, hl, hr⟩⟩ + · exact ⟨⟨q, p, hqp, rootPlane_eq_of_mem a b q p hab hq hp hqp, hl, hr⟩⟩ + +namespace PlaneBasis +variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) + +theorem left_mem : B.left.val ∈ P := by + apply B.plane_eq.le + exact Submodule.subset_span (Set.mem_insert _ _) + +theorem right_mem : B.right.val ∈ P := by + apply B.plane_eq.le + exact Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)) + +theorem left_simple : PlaneSimple P B.left := + planeSimple_of_extreme B.left B.left_mem (.inl B.left_min) + +theorem right_simple : PlaneSimple P B.right := + planeSimple_of_extreme B.right B.right_mem (.inr B.right_max) + +/-- Every positive root in the plane is in its canonical nonnegative cone. -/ +theorem positive_cone (r : PositiveRoot M cs) (hr : r.val ∈ P) : + ∃ c d : ℝ, 0 ≤ c ∧ 0 ≤ d ∧ r.val = c • B.left.val + d • B.right.val := by + by_cases hl : r = B.left + · exact ⟨1, 0, zero_le_one, le_refl 0, by rw [hl]; simp⟩ + by_cases hh : r = B.right + · exact ⟨0, 1, le_refl 0, zero_le_one, by rw [hh]; simp⟩ + have hlr : geometricSlope B.left < geometricSlope r := + lt_of_le_of_ne (B.left_min r hr) (fun h => hl (geometricSlope_injective h).symm) + have hrr : geometricSlope r < geometricSlope B.right := + lt_of_le_of_ne (B.right_max r hr) (fun h => hh (geometricSlope_injective h)) + obtain ⟨c, d, hc, hd, he⟩ := positive_combination_of_slope_between B.left B.right r + (B.plane_eq.ge hr) hlr hrr + exact ⟨c, d, hc.le, hd.le, he⟩ + +end PlaneBasis + + +/-- Canonical-simple reflections have no extra root pair in their own plane. -/ +theorem PlaneSimple.planeWeight_eq_zero {P : Submodule ℝ (I → ℝ)} + {a : PositiveRoot M cs} (ha : PlaneSimple P a) (x : W) : + planeWeight x a P = 0 := by + classical + rw [planeWeight, Finsupp.mapDomain, Finsupp.sum_apply] + apply Finset.sum_eq_zero + intro b _ + change (Finsupp.single (rootPlane a b) (halfVector x a b)) P = 0 + rw [Finsupp.single_apply] + by_cases hP : rootPlane a b = P + · rw [ite_eq_left hP] + simp only [halfVector, rootIndicator_apply] + apply ite_eq_right + intro hh + have hbP : b.val ∈ P := hP.le + (Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _))) + exact hh.1.1 ((ha.2 b hbP).mp ((rootInverted_ref_iff_flipped a b).mpr hh.1.2.1)) + · exact ite_eq_right hP + +/-- The relative inversion count has the genuine simple-reflection step. -/ +theorem PlaneSimple.planeLength_step {P : Submodule ℝ (I → ℝ)} + {a b : PositiveRoot M cs} (ha : PlaneSimple P a) + (hab : a ≠ b) (hP : rootPlane a b = P) (x : W) + (hx : ¬ rootInverted x a) : + planeLength (M := M) (cs := cs) P (rootRef a * x) = + planeLength (M := M) (cs := cs) P x + 1 := by + have hh := planeWeight_relative_degree x a b hab hx + rw [hP, ha.planeWeight_eq_zero] at hh + linarith + +theorem PlaneSimple.planeLength_step_down {P : Submodule ℝ (I → ℝ)} + {a b : PositiveRoot M cs} (ha : PlaneSimple P a) + (hab : a ≠ b) (hP : rootPlane a b = P) (x : W) + (hx : rootInverted x a) : + planeLength (M := M) (cs := cs) P (rootRef a * x) = + planeLength (M := M) (cs := cs) P x - 1 := by + have hy : ¬ rootInverted (rootRef a * x) a := + fun h => (rootInverted_mul_self x a).mp h hx + have hh := ha.planeLength_step hab hP (rootRef a * x) hy + rw [← mul_assoc, (rootReflection M cs a).property.mul_self, one_mul] at hh + linarith + +/-- The usual inversion bijection, proved on the actual positive roots. -/ +theorem rootInverted_inverse_action (w : W) (a : PositiveRoot M cs) : + rootInverted w⁻¹ (positiveAction w⁻¹ a) ↔ rootInverted w a := by + have hw : action M cs w (action M cs w⁻¹ a.val) = a.val := by + rw [← LinearEquiv.mul_apply, ← map_mul, mul_inv_cancel, map_one] + rfl + by_cases hi : rootInverted w a + · apply iff_of_true ?_ hi + unfold rootInverted + rw [inv_inv, positiveAction_eq_of_nonpos _ _ hi, map_neg, hw] + exact fun i => neg_nonpos.mpr (a.property.2 i) + · apply iff_of_false ?_ hi + rw [not_rootInverted_iff, inv_inv, + positiveAction_eq_of_nonneg _ _ ((not_rootInverted_iff w a).mp hi), hw] + exact a.property.2 + +/-- Reindexing the inversion indicator by the inverse root action. -/ +theorem inversionVector_inverse (w : W) : + inversionVector (M := M) (cs := cs) w⁻¹ = + Finsupp.mapDomain (positiveActionEquiv w⁻¹) (inversionVector w) := by + classical + apply (Finsupp.ext_iff).mpr + intro b + obtain ⟨a, rfl⟩ := (positiveActionEquiv (M := M) (cs := cs) w⁻¹).surjective b + rw [Finsupp.mapDomain_equiv_apply, Equiv.symm_apply_apply] + simp only [inversionVector_apply] + change (if rootInverted w⁻¹ (positiveAction w⁻¹ a) then 1 else 0) = _ + rw [rootInverted_inverse_action] + +theorem positiveAction_mem_plane {P : Submodule ℝ (I → ℝ)} + {w : W} (hw : w ∈ planeSubgroup M cs P) (a : PositiveRoot M cs) + (ha : a.val ∈ P) : (positiveAction w a).val ∈ P := by + have hp := planeSubgroup_preserves hw ha + rcases (a.property.1.act w).sign with hs | hs + · exact (positiveAction_eq_of_nonneg w a hs).symm ▸ hp + · exact (positiveAction_eq_of_nonpos w a hs).symm ▸ P.neg_mem hp + +theorem positiveAction_mem_plane_iff {P : Submodule ℝ (I → ℝ)} + {w : W} (hw : w ∈ planeSubgroup M cs P) (a : PositiveRoot M cs) : + (positiveAction w a).val ∈ P ↔ a.val ∈ P := by + refine ⟨fun h => ?_, positiveAction_mem_plane hw a⟩ + have hh := positiveAction_mem_plane ((planeSubgroup M cs P).inv_mem hw) + (positiveAction w a) h + rwa [← positiveAction_mul, inv_mul_cancel, positiveAction_one] at hh + +/-- Relative inversion count is invariant under inverse on the actual plane subgroup. -/ +theorem planeLength_inv {P : Submodule ℝ (I → ℝ)} {w : W} + (hw : w ∈ planeSubgroup M cs P) : + planeLength (M := M) (cs := cs) P w⁻¹ = planeLength (M := M) (cs := cs) P w := by + classical + rw [planeLength, inversionVector_inverse, + Finsupp.sum_mapDomain_index (by intros; split_ifs <;> rfl) + (by intros; split_ifs <;> simp)] + apply Finsupp.sum_congr + intro a _ + change (if (positiveAction w⁻¹ a).val ∈ P then _ else _) = _ + rw [positiveAction_mem_plane_iff ((planeSubgroup M cs P).inv_mem hw)] + +theorem planeLength_nonneg (P : Submodule ℝ (I → ℝ)) (w : W) : + 0 ≤ planeLength (M := M) (cs := cs) P w := by + classical + apply Finset.sum_nonneg + intro a _ + simp only [inversionVector_apply] + split_ifs <;> norm_num + +namespace PlaneBasis +variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) + +/-- A plane reflection must invert at least one of the canonical endpoints. +This uses convex positivity, not any assumed Coxeter structure on the subgroup. -/ +theorem reflection_inverts_endpoint (r : PositiveRoot M cs) (hr : r.val ∈ P) : + rootInverted (rootRef r) B.left ∨ rootInverted (rootRef r) B.right := by + by_contra h + push Not at h + obtain ⟨c, d, hc, hd, he⟩ := B.positive_cone r hr + exact (noninverted_of_positive_combination (rootRef r) B.left B.right r + hc hd he h.1 h.2) (rootInverted_ref_self r) + +end PlaneBasis + + +/-- The second descent in a simple conjugation of a nonsimple reflection. -/ +theorem PlaneSimple.inverted_after_mul {P : Submodule ℝ (I → ℝ)} + {a r : PositiveRoot M cs} (ha : PlaneSimple P a) (hr : r.val ∈ P) + (hra : r ≠ a) (hi : rootInverted (rootRef r) a) : + rootInverted (rootRef r * rootRef a) a := by + have hn := (rootInverted_ref_iff_flipped r a).mp hi + apply (rootInverted_mul_of_nonpos (rootRef a) r a hn).mpr + intro hinv + have he : partner r a = a := (ha.2 (partner r a) (partner_mem r a hr ha.1)).mp hinv + exact hra (negative_partner_fixed r a hn he).symm + +/-- The honest relative length drops by two under the chosen simple conjugation. -/ +theorem PlaneSimple.planeLength_conj_drop {P : Submodule ℝ (I → ℝ)} + {a b r : PositiveRoot M cs} (ha : PlaneSimple P a) + (hab : a ≠ b) (hP : rootPlane a b = P) (hr : r.val ∈ P) + (hra : r ≠ a) (hi : rootInverted (rootRef r) a) : + planeLength (M := M) (cs := cs) P (rootRef (partner a r)) = + planeLength (M := M) (cs := cs) P (rootRef r) - 2 := by + have har : rootRef a ∈ planeSubgroup M cs P := + ((rootReflection_represents M cs a).planeSubgroup_mem_iff M cs).mpr ha.1 + have hrr : rootRef r ∈ planeSubgroup M cs P := + ((rootReflection_represents M cs r).planeSubgroup_mem_iff M cs).mpr hr + have hmul := (planeSubgroup M cs P).mul_mem har hrr + have hd := ha.planeLength_step_down hab hP (rootRef r) hi + have hd' := ha.planeLength_step_down hab hP (rootRef r * rootRef a) + (ha.inverted_after_mul hr hra hi) + have hli := planeLength_inv hmul + rw [mul_inv_rev, (rootReflection M cs r).property.inv, + (rootReflection M cs a).property.inv] at hli + change planeLength (M := M) (cs := cs) P + (rootReflection M cs (positiveAction (rootRef a) r)).val = _ + rw [rootReflection_positiveAction, (rootReflection M cs a).property.inv, mul_assoc] + linarith + +namespace PlaneBasis +variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) + +/-- The canonical endpoint reflections generate every ambient reflection in the plane. -/ +theorem rootRef_mem_pairClosure (r : PositiveRoot M cs) (hr : r.val ∈ P) : + rootRef r ∈ Subgroup.closure {rootRef B.left, rootRef B.right} := by + classical + generalize hn : (planeLength (M := M) (cs := cs) P (rootRef r)).toNat = n + induction n using Nat.strong_induction_on generalizing r with + | h n ih => + by_cases hl : r = B.left + · rw [hl]; exact Subgroup.subset_closure (Set.mem_insert _ _) + by_cases hh : r = B.right + · rw [hh]; exact Subgroup.subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _)) + have step (a b : PositiveRoot M cs) (ha : PlaneSimple P a) + (hab : a ≠ b) (hP : rootPlane a b = P) (hra : r ≠ a) + (hgen : rootRef a ∈ Subgroup.closure {rootRef B.left, rootRef B.right}) + (hi : rootInverted (rootRef r) a) : + rootRef r ∈ Subgroup.closure {rootRef B.left, rootRef B.right} := by + have hp : (partner a r).val ∈ P := partner_mem a r ha.1 hr + have hdrop := ha.planeLength_conj_drop hab hP hr hra hi + have hless : (planeLength (M := M) (cs := cs) P (rootRef (partner a r))).toNat < n := by + have hnonneg := planeLength_nonneg (M := M) (cs := cs) P (rootRef (partner a r)) + omega + have hind := ih _ hless (partner a r) hp rfl + have hlen := (Subgroup.closure {rootRef B.left, rootRef B.right}).mul_mem + ((Subgroup.closure {rootRef B.left, rootRef B.right}).mul_mem hgen hind) hgen + change rootRef a * (rootReflection M cs (positiveAction (rootRef a) r)).val * rootRef a ∈ _ at hlen + rw [rootReflection_positiveAction, (rootReflection M cs a).property.inv] at hlen + rw [← mul_assoc, ← mul_assoc, (rootReflection M cs a).property.mul_self, + one_mul, mul_assoc, (rootReflection M cs a).property.mul_self, mul_one] at hlen + exact hlen + rcases B.reflection_inverts_endpoint r hr with hi | hi + · exact step B.left B.right B.left_simple B.distinct B.plane_eq hl + (Subgroup.subset_closure (Set.mem_insert _ _)) hi + · exact step B.right B.left B.right_simple B.distinct.symm + (by rw [rootPlane, Set.pair_comm]; exact B.plane_eq) hh + (Subgroup.subset_closure (Set.mem_insert_of_mem _ (Set.mem_singleton _))) hi + +/-- Exact identification with the manuscript's maximal root-plane subgroup. -/ +theorem pairClosure_eq_planeSubgroup : + Subgroup.closure {rootRef B.left, rootRef B.right} = planeSubgroup M cs P := by + apply le_antisymm + · apply (Subgroup.closure_le _).mpr + intro t ht + rcases Set.mem_insert_iff.mp ht with he | he + · rw [he] + exact ((rootReflection_represents M cs B.left).planeSubgroup_mem_iff M cs).mpr B.left_mem + · rw [Set.mem_singleton_iff.mp he] + exact ((rootReflection_represents M cs B.right).planeSubgroup_mem_iff M cs).mpr B.right_mem + · apply (Subgroup.closure_le _).mpr + rintro t ⟨a, ha, haP⟩ + let r := positiveRoot M cs ⟨t, ha.isReflection⟩ + have hre : rootRef r = t := (rootReflection_represents M cs r).reflection_unique + (positiveRoot_represents M cs ⟨t, ha.isReflection⟩) + have hrP : r.val ∈ P := ((positiveRoot_represents M cs + ⟨t, ha.isReflection⟩).planeSubgroup_mem_iff M cs).mp (Subgroup.subset_closure ⟨a, ha, haP⟩) + rw [← hre] + exact B.rootRef_mem_pairClosure r hrP + +/-- Distinct positive roots give distinct actual reflections. -/ +theorem rootRef_distinct : rootRef B.left ≠ rootRef B.right := by + intro he + apply B.distinct + apply (positiveRootEquiv M cs).symm.injective + exact Subtype.ext he + +theorem rootRef_ne_one (a : PositiveRoot M cs) : rootRef a ≠ 1 := by + intro h + exact (not_rootInverted_one a) (h ▸ rootInverted_ref_self a) + +/-- The genuine dihedral matrix attached to the canonical plane endpoints. -/ +def matrix : CoxeterMatrix Bool := + Dihedral.pairMatrix (rootRef B.left) (rootRef B.right) + (rootReflection M cs B.left).property.mul_self B.rootRef_distinct + +/-- A proved Coxeter system on the *actual maximal plane subgroup*. -/ +def system : CoxeterSystem B.matrix (planeSubgroup M cs P) := + (Dihedral.pairSystem (rootRef B.left) (rootRef B.right) + (rootReflection M cs B.left).property.mul_self + (rootReflection M cs B.right).property.mul_self B.rootRef_distinct + (rootRef_ne_one B.left) + (rootRef_ne_one B.right)).map + (MulEquiv.subgroupCongr B.pairClosure_eq_planeSubgroup) + +/-- Canonical simple positive roots, indexed by Bool just like the system. -/ +def simpleRoot (i : Bool) : PositiveRoot M cs := if i then B.right else B.left + +theorem simpleRoot_mem (i : Bool) : (B.simpleRoot i).val ∈ P := by + cases i + · exact B.left_mem + · exact B.right_mem + +theorem simpleRoot_simple (i : Bool) : PlaneSimple P (B.simpleRoot i) := by + cases i + · exact B.left_simple + · exact B.right_simple + +@[simp] theorem system_simple (i : Bool) : + (B.system.simple i : W) = rootRef (B.simpleRoot i) := by + change ((Dihedral.pairSystem (rootRef B.left) (rootRef B.right) + (rootReflection M cs B.left).property.mul_self + (rootReflection M cs B.right).property.mul_self B.rootRef_distinct + (rootRef_ne_one B.left) (rootRef_ne_one B.right)).simple i : W) = _ + rw [Dihedral.pairSystem_simple] + cases i <;> rfl + +/-- The positive simple-sign criterion for the induced plane root system. -/ +theorem simple_sign {t : planeSubgroup M cs P} {a : I → ℝ} + (ha : Represents M cs t.val a) (haP : a ∈ P) (hp : ∀ k, 0 ≤ a k) (i : Bool) : + ((∀ k, action M cs (B.system.simple i : W) a k ≤ 0) ↔ t = B.system.simple i) ∧ + ((∀ k, 0 ≤ action M cs (B.system.simple i : W) a k) ↔ t ≠ B.system.simple i) := by + let r : PositiveRoot M cs := ⟨a, ha.isRoot, hp⟩ + have hneg : (∀ k, action M cs (B.system.simple i : W) a k ≤ 0) ↔ t = B.system.simple i := by + rw [B.system_simple] + change flipped (B.simpleRoot i) r ↔ _ + rw [← rootInverted_ref_iff_flipped, (B.simpleRoot_simple i).2 r haP] + constructor + · intro he + apply Subtype.ext + rw [B.system_simple] + exact ha.reflection_unique (he ▸ rootReflection_represents M cs r) + · intro he + apply Subtype.ext + have hr : Represents M cs (rootRef (B.simpleRoot i)) a := by + simpa only [he, B.system_simple] using ha + exact hr.unique_positive (rootReflection_represents M cs _) hp (B.simpleRoot i).property.2 + refine ⟨hneg, ?_⟩ + constructor + · intro h he + exact (ha.isRoot.act (B.system.simple i : W)).not_both h (hneg.mpr he) + · intro h + exact (ha.isRoot.act (B.system.simple i : W)).sign.resolve_right (fun hn => h (hneg.mp hn)) + +/-- Signed roots for the induced system. The vectors are the original ambient +roots, and membership in the actual plane is part of the relation. -/ +structure InducedSigned (p : planeSubgroup M cs P × ZMod 2) (a : I → ℝ) : Prop where + represents : Represents M cs p.1.val a + plane_mem : a ∈ P + sign : (p.2 = 0 ∧ ∀ i, 0 ≤ a i) ∨ (p.2 = 1 ∧ ∀ i, a i ≤ 0) + +theorem InducedSigned.simple {p : planeSubgroup M cs P × ZMod 2} {a : I → ℝ} + (ha : InducedSigned p a) (i : Bool) : + InducedSigned (CoxeterSupport.simpleAction B.system i p) + (action M cs (B.system.simple i : W) a) := by + rcases p with ⟨t,z⟩ + rw [CoxeterSupport.simpleAction_apply] + refine ⟨?_, planeSubgroup_preserves (B.system.simple i).property ha.plane_mem, ?_⟩ + · have h := ha.represents.act (B.system.simple i : W) + have he : (B.system.simple i : W)⁻¹ = (B.system.simple i : W) := + congrArg Subtype.val (B.system.inv_simple i) + simpa only [he, Subgroup.coe_mul] using h + · rcases ha.sign with ⟨rfl,hp⟩ | ⟨rfl,hn⟩ + · by_cases heq : t = B.system.simple i + · exact Or.inr ⟨by simp [heq], + (B.simple_sign ha.represents ha.plane_mem hp i).1.mpr heq⟩ + · exact Or.inl ⟨by simp [heq, ZModModule.add_self], + (B.simple_sign ha.represents ha.plane_mem hp i).2.mpr heq⟩ + · have hp : ∀ k, 0 ≤ (-a) k := fun k => neg_nonneg.mpr (hn k) + by_cases heq : t = B.system.simple i + · refine Or.inl ⟨by simp [heq, ZModModule.add_self], ?_⟩ + have h := (B.simple_sign ha.represents.neg (P.neg_mem ha.plane_mem) hp i).1.mpr heq + simpa only [map_neg, Pi.neg_apply, neg_nonpos] using h + · refine Or.inr ⟨by simp [heq], ?_⟩ + have h := (B.simple_sign ha.represents.neg (P.neg_mem ha.plane_mem) hp i).2.mpr heq + simpa only [map_neg, Pi.neg_apply, neg_nonneg] using h + +theorem InducedSigned.act {p : planeSubgroup M cs P × ZMod 2} {a : I → ℝ} + (ha : InducedSigned p a) (w : planeSubgroup M cs P) : + InducedSigned (CoxeterSupport.reflectionAction B.system w p) + (action M cs (w : W) a) := by + obtain ⟨ω,rfl⟩ := B.system.wordProd_surjective w + induction ω with + | nil => simpa using ha + | cons i ω ih => + simpa only [B.system.wordProd_cons, map_mul, Equiv.Perm.mul_apply, + CoxeterSupport.reflectionAction_simple, Subgroup.coe_mul, + LinearEquiv.mul_apply] using ih.simple B i + +/-- The induced positive roots have precisely the intrinsic Coxeter inversion +signs. No change of realization or extra canonical-system assumption is used. -/ +theorem inversion_iff {t : planeSubgroup M cs P} {a : I → ℝ} + (ha : Represents M cs t.val a) (haP : a ∈ P) (hp : ∀ i, 0 ≤ a i) + (w : planeSubgroup M cs P) : + (∀ i, action M cs (w : W)⁻¹ a i ≤ 0) ↔ B.system.IsLeftInversion w t := by + classical + let : BEq (planeSubgroup M cs P) := @instBEqOfDecidableEq _ (Classical.decEq _) + obtain ⟨ω,hω,heq⟩ := B.system.exists_isReduced w + rw [heq] + let c : ZMod 2 := if t ∈ B.system.leftInvSeq ω then 1 else 0 + have hrec := CoxeterSupport.wordAction_record B.system ω t c + rw [← CoxeterSupport.reflectionAction_wordProd] at hrec + have hrec' : CoxeterSupport.reflectionAction B.system (B.system.wordProd ω) + ((B.system.wordProd ω)⁻¹ * t * B.system.wordProd ω, c) = (t,0) := by + by_cases hm : t ∈ B.system.leftInvSeq ω + · have hc : c = 1 := ite_eq_left hm + simpa only [hc, List.count_eq_one_of_mem hω.nodup_leftInvSeq hm, + Nat.cast_one, ZModModule.add_self] using hrec + · have hc : c = 0 := ite_eq_right hm + simpa only [hc, List.count_eq_zero.mpr hm, Nat.cast_zero, add_zero] using hrec + have hinv : CoxeterSupport.reflectionAction B.system (B.system.wordProd ω)⁻¹ (t,0) = + ((B.system.wordProd ω)⁻¹ * t * B.system.wordProd ω,c) := by + rw [map_inv, ← hrec'] + exact Equiv.symm_apply_apply _ _ + have hs : InducedSigned (t,0) a := ⟨ha,haP,Or.inl ⟨rfl,hp⟩⟩ + have hsi := hs.act B (B.system.wordProd ω)⁻¹ + rw [hinv] at hsi + have hcount : c = if t ∈ B.system.leftInvSeq ω then 1 else 0 := rfl + have hmem : (∀ i, action M cs (B.system.wordProd ω : W)⁻¹ a i ≤ 0) ↔ + t ∈ B.system.leftInvSeq ω := by + by_cases hm : t ∈ B.system.leftInvSeq ω + · have hc1 : c=1 := by simpa [hm] using hcount + have hh := hsi.sign + simp only [hc1] at hh + rcases hh with ⟨hbad,_⟩ | ⟨_,hn⟩ + · norm_num at hbad + · exact iff_of_true hn hm + · have hc0 : c=0 := by simpa [hm] using hcount + have hh := hsi.sign + simp only [hc0] at hh + rcases hh with ⟨_,hpos⟩ | ⟨hbad,_⟩ + · exact iff_of_false (fun hn => (ha.isRoot.act _).not_both hpos hn) hm + · norm_num at hbad + rw [hmem] + exact ⟨B.system.isLeftInversion_of_mem_leftInvSeq hω, + CoxeterSupport.mem_leftInvSeq_of_inversion B.system hω⟩ + +/-- The intrinsic reflections are exactly the ambient reflections in the +actual maximal plane subgroup. -/ +theorem reflection_iff (t : planeSubgroup M cs P) : + B.system.IsReflection t ↔ cs.IsReflection (t : W) := by + constructor + · rintro ⟨w,i,he⟩ + obtain ⟨z,j,hz⟩ := (rootReflection M cs (B.simpleRoot i)).property + refine ⟨(w : W) * z,j,?_⟩ + have he' := congrArg Subtype.val he + simp only [Subgroup.coe_mul, Subgroup.coe_inv, B.system_simple] at he' + change rootRef (B.simpleRoot i) = _ at hz + rw [he', hz] + group + · intro ht + let a := positiveRoot M cs ⟨(t:W),ht⟩ + have ha := positiveRoot_represents M cs ⟨(t:W),ht⟩ + have haP : a.val ∈ P := (ha.planeSubgroup_mem_iff M cs).mp t.property + have hinv := (B.inversion_iff ha haP a.property.2 t).mp + ((ha.inversion_iff a.property.2 (t:W)).mpr + ⟨ht, by + rw [ht.mul_self, cs.length_one] + obtain ⟨k,hk⟩ := ht.odd_length + omega⟩) + exact hinv.1 + +/-- The true ambient plane inversions are in bijection with the inversions +of the canonical induced system. -/ +def inversionEquiv (w : planeSubgroup M cs P) : + {a : PositiveRoot M cs // a.val ∈ P ∧ rootInverted (w:W) a} ≃ + {t : planeSubgroup M cs P // B.system.IsLeftInversion w t} where + toFun a := ⟨⟨rootRef a.val, + ((rootReflection_represents M cs a.val).planeSubgroup_mem_iff M cs).mpr a.property.1⟩, + (B.inversion_iff (rootReflection_represents M cs a.val) a.property.1 + a.val.property.2 w).mp a.property.2⟩ + invFun t := + let a := positiveRoot M cs ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩ + let ha := positiveRoot_represents M cs + ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩ + let haP := (ha.planeSubgroup_mem_iff M cs).mp t.val.property + ⟨a,haP,(B.inversion_iff ha haP a.property.2 w).mpr t.property⟩ + left_inv a := by + apply Subtype.ext + exact (positiveRootEquiv M cs).apply_symm_apply a.val + right_inv t := by + apply Subtype.ext + apply Subtype.ext + exact congrArg (fun r : {r : W // cs.IsReflection r} => r.val) + ((positiveRootEquiv M cs).symm_apply_apply + ⟨(t.val:W),(B.reflection_iff t.val).mp t.property.1⟩) + +/-- Relative inversion count is the actual Coxeter length, completing the +length identification, not merely a rank-two presentation. -/ +theorem length_eq (w : planeSubgroup M cs P) : + planeLength (M := M) (cs := cs) P (w:W) = (B.system.length w : ℤ) := by + classical + let f := inversionVector (M := M) (cs := cs) (w:W) + let F := f.support.filter (fun a => a.val ∈ P) + have hF : (F : Set (PositiveRoot M cs)) = + {a | a.val ∈ P ∧ rootInverted (w:W) a} := by + ext a + simp only [F, Finset.mem_coe, Finset.mem_filter, Finsupp.mem_support_iff, + f, inversionVector_apply, ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not, + Set.mem_ofPred_eq, and_comm] + have hcard : F.card = B.system.length w := by + rw [← Set.ncard_coe_finset, hF, ← Nat.card_coe_set_eq] + change Nat.card {a : PositiveRoot M cs // a.val ∈ P ∧ rootInverted (w:W) a} = _ + rw [Nat.card_congr (B.inversionEquiv w)] + obtain ⟨ω,hω,he⟩ := B.system.exists_isReduced w + rw [he, Nat.card_congr (leftInversionListEquiv B.matrix B.system hω), + ← Nat.card_congr (List.Nodup.getEquiv (B.system.leftInvSeq ω) hω.nodup_leftInvSeq), + Nat.card_fin, B.system.length_leftInvSeq, hω.eq] + change f.sum (fun a n => if a.val ∈ P then n else 0) = _ + rw [Finsupp.sum, ← Finset.sum_filter] + calc + ∑ a ∈ F, f a = ∑ _a ∈ F, (1:ℤ) := by + apply Finset.sum_congr rfl + intro a ha + have hm : rootInverted (w:W) a := by + have hm := (Finset.mem_filter.mp ha).1 + simpa only [Finsupp.mem_support_iff, f, inversionVector_apply, + ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hm + simp [f,hm] + _ = _ := by simp [hcard] + +/-- Intrinsic and ambient left inversions coincide on the plane subgroup. -/ +theorem leftInversion_iff (w t : planeSubgroup M cs P) : + B.system.IsLeftInversion w t ↔ cs.IsLeftInversion (w:W) (t:W) := by + by_cases ht : cs.IsReflection (t:W) + · let a := positiveRoot M cs ⟨(t:W),ht⟩ + have ha := positiveRoot_represents M cs ⟨(t:W),ht⟩ + have haP := (ha.planeSubgroup_mem_iff M cs).mp t.property + exact (B.inversion_iff ha haP a.property.2 w).symm.trans + (ha.inversion_iff a.property.2 (w:W)) + · exact iff_of_false (fun h => ht ((B.reflection_iff t).mp h.1)) (fun h => ht h.1) + +/-- The intrinsic directed dihedral graph is the actual ambient graph +restricted to the maximal plane subgroup. -/ +theorem bruhatStep_iff (g h : planeSubgroup M cs P) : + BruhatStep cs (g:W) (h:W) ↔ BruhatStep B.system g h := by + constructor + · rintro ⟨hlen,t,ht,he⟩ + have htP : t ∈ planeSubgroup M cs P := by + have he' : t = (h:W) * (g:W)⁻¹ := by rw [he]; group + rw [he'] + exact (planeSubgroup M cs P).mul_mem h.property + ((planeSubgroup M cs P).inv_mem g.property) + let tr : planeSubgroup M cs P := ⟨t,htP⟩ + have htr : B.system.IsReflection tr := (B.reflection_iff tr).mpr ht + have het : h=tr*g := Subtype.ext he + have htg : t*(h:W)=(g:W) := by rw [he, ← mul_assoc, ht.mul_self, one_mul] + have hi := (B.leftInversion_iff h tr).mpr ⟨ht,by + change cs.length (t*(h:W)) < cs.length (h:W) + simpa only [htg] using hlen⟩ + have htg' : tr*h=g := by rw [het, ← mul_assoc, htr.mul_self, one_mul] + exact ⟨by simpa only [htg'] using hi.2,tr,htr,het⟩ + · rintro ⟨hlen,t,ht,he⟩ + have het : t*h=g := by rw [he, ← mul_assoc, ht.mul_self, one_mul] + have hi := (B.leftInversion_iff h t).mp ⟨ht,by simpa only [het] using hlen⟩ + refine ⟨?_,(t:W),(B.reflection_iff t).mp ht,congrArg Subtype.val he⟩ + simpa only [← Subgroup.coe_mul, het] using hi.2 + +/-- The exact canonical coset graph theorem needed by the reconstruction. -/ +theorem coset_step_iff {a₀ : W} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + (g h : planeSubgroup M cs P) : + BruhatStep cs ((g:W)*a₀) ((h:W)*a₀) ↔ BruhatStep B.system g h := + (bruhatStep_coset_iff hmin g.property h.property).trans (B.bruhatStep_iff g h) + +/-- Relative dihedral paths give actual ambient Bruhat paths in the coset. -/ +theorem coset_bruhat {a₀ : W} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + {g h : planeSubgroup M cs P} (hgh : BruhatLE B.system g h) : + BruhatLE cs ((g:W)*a₀) ((h:W)*a₀) := by + induction hgh with + | refl => exact Relation.ReflTransGen.refl + | @tail y z _ hyz ih => + exact ih.tail ((B.coset_step_iff hmin y z).mpr hyz) + +/-- The source inversion-count characterization holds on every minimal +representative coset, with its actual induced length. -/ +theorem coset_length_eq {a₀ : W} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + (w : planeSubgroup M cs P) : + planeLength (M := M) (cs := cs) P ((w:W)*a₀) = (B.system.length w : ℤ) := by + classical + rw [← B.length_eq w] + let f := inversionVector (M := M) (cs := cs) ((w:W)*a₀) + let g := inversionVector (M := M) (cs := cs) (w:W) + change f.sum (fun a n => if a.val ∈ P then n else 0) = + g.sum (fun a n => if a.val ∈ P then n else 0) + rw [Finsupp.sum_of_support_subset f Finset.subset_union_left _ (by intro a; simp), + Finsupp.sum_of_support_subset g Finset.subset_union_right _ (by intro a; simp)] + apply Finset.sum_congr rfl + intro a _ + by_cases haP : a.val ∈ P + · simp only [ite_eq_left haP, f, g, inversionVector_apply] + congr 1 + exact propext (root_inversion_coset_iff hmin w.property a.property.1 haP) + · simp [haP] + +end PlaneBasis + +/-- Every nonsaturated reflection edge has a genuine rank-two contribution +whose induced relative edge gap is at least three. -/ +theorem exists_positive_plane (x : W) (a : PositiveRoot M cs) + (hx : ¬ rootInverted x a) + (hlen : cs.length x + 1 < cs.length (rootRef a*x)) : + ∃ b : PositiveRoot M cs, a ≠ b ∧ 0 < planeWeight x a (rootPlane a b) := by + classical + have hsum := sum_planeWeight x a hx + have hp : 0 < (planeWeight x a).sum (fun _ n => n) := by omega + obtain ⟨P,hP,hpos⟩ := (Finset.sum_pos_iff_of_nonneg + (fun P _ => planeWeight_nonneg x a P)).mp hp + obtain ⟨b,hb,hbP⟩ := Finset.mem_image.mp (Finsupp.mapDomain_support hP) + have hb' : halfRoot x a b := by + simpa only [Finsupp.mem_support_iff, halfVector, rootIndicator_apply, + ne_eq, ite_eq_right_iff, one_ne_zero, imp_false, not_not] using hb + exact ⟨b,hb'.1.1.symm,hbP ▸ hpos⟩ + + +end +end KLInvariance.TitsSpace + +namespace KLInvariance.Dihedral +variable {G : Type*} [Group G] {N : CoxeterMatrix Bool} + +/-- Every nonsaturated dihedral edge contains a full eight-edge rectangle. -/ +theorem edge_diamond (ds : CoxeterSystem N G) {x y : G} + (hxy : BruhatStep ds x y) (hlen : ds.length x + 1 < ds.length y) : + ∃ a b c d : G, a ≠ b ∧ c ≠ d ∧ + BruhatStep ds x a ∧ BruhatStep ds x b ∧ + BruhatStep ds a c ∧ BruhatStep ds a d ∧ + BruhatStep ds b c ∧ BruhatStep ds b d ∧ + BruhatStep ds c y ∧ BruhatStep ds d y := by + have hodd := ((step_iff_odd ds x y).mp hxy).2 + have hthree : ds.length x+2 < ds.length y := by + rw [Nat.odd_iff] at hodd + omega + obtain ⟨a,b,hab,hlev₁⟩ := two_elements_length ds + (by omega : 0 < ds.length x+1) hlen + obtain ⟨c,d,hcd,hlev₂⟩ := two_elements_length ds + (by omega : 0 < ds.length x+2) hthree + have ha := (hlev₁ a).mpr (Or.inl rfl) + have hb := (hlev₁ b).mpr (Or.inr rfl) + have hc := (hlev₂ c).mpr (Or.inl rfl) + have hd := (hlev₂ d).mpr (Or.inr rfl) + have hsucc (p q : G) (h : ds.length q=ds.length p+1) : BruhatStep ds p q := by + rw [step_iff_odd, Nat.odd_iff] + constructor <;> omega + have htop (p : G) (hp : ds.length p=ds.length x+2) : BruhatStep ds p y := by + rw [step_iff_odd, Nat.odd_iff] + rw [Nat.odd_iff] at hodd + constructor <;> omega + exact ⟨a,b,c,d,hab,hcd,hsucc x a ha,hsucc x b hb, + hsucc a c (by omega),hsucc a d (by omega), + hsucc b c (by omega),hsucc b d (by omega),htop c hc,htop d hd⟩ + +end KLInvariance.Dihedral + +namespace KLInvariance.TitsSpace +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] {cs : CoxeterSystem M W} + +/-- Every genuine ambient reflection edge of length gap greater than one +contains a full eight-edge diamond. The chosen plane comes from an actual +positive inversion contribution, avoiding the false arbitrary-plane claim. -/ +theorem ambient_edge_diamond {x y : W} (hxy : BruhatStep cs x y) + (hlen : cs.length x+1 < cs.length y) : + ∃ a b c d : W, a ≠ b ∧ c ≠ d ∧ + BruhatStep cs x a ∧ BruhatStep cs x b ∧ + BruhatStep cs a c ∧ BruhatStep cs a d ∧ + BruhatStep cs b c ∧ BruhatStep cs b d ∧ + BruhatStep cs c y ∧ BruhatStep cs d y := by + rcases hxy.2 with ⟨t,ht,het⟩ + let a := positiveRoot M cs ⟨t,ht⟩ + have ha := positiveRoot_represents M cs ⟨t,ht⟩ + have hta : rootRef a=t := congrArg (fun r : {r : W // cs.IsReflection r} => r.val) + ((positiveRootEquiv M cs).symm_apply_apply ⟨t,ht⟩) + have hx : ¬ rootInverted x a := by + intro hi + have h := (ha.inversion_iff a.property.2 x).mp hi + have hh : cs.length (t*x) < cs.length x := h.2 + rw [← het] at hh + exact (not_lt_of_gt hxy.1) hh + have hae : rootRef a*x=y := by rw [hta]; exact het.symm + obtain ⟨b,hab,hpos⟩ := exists_positive_plane x a hx (by rwa [hae]) + obtain ⟨B⟩ := nonempty_planeBasis a b hab + let P := rootPlane a b + have haP : a.val ∈ P := Submodule.subset_span (Set.mem_insert _ _) + obtain ⟨a₀,g,hg,hgx,hmin⟩ := planeCoset_exists_minimal M cs P x + let X : planeSubgroup M cs P := ⟨g,hg⟩ + let T : planeSubgroup M cs P := ⟨rootRef a, + ((rootReflection_represents M cs a).planeSubgroup_mem_iff M cs).mpr haP⟩ + let Y := T*X + have hxEq : (X:W)*a₀=x := hgx.symm + have hyEq : (Y:W)*a₀=y := by + change (rootRef a*g)*a₀=y + rw [mul_assoc, ← hgx, hae] + have hrel : BruhatStep B.system X Y := (B.coset_step_iff hmin X Y).mp + (by simpa only [hxEq,hyEq] using hxy) + have hLx := B.coset_length_eq hmin X + have hLy := B.coset_length_eq hmin Y + rw [hxEq] at hLx + rw [hyEq] at hLy + have hdegree := planeWeight_relative_degree x a b hab hx + rw [hae,hLx,hLy] at hdegree + have hlen' : B.system.length X+1 < B.system.length Y := by omega + obtain ⟨p,q,r,s,hpq,hrs,hXp,hXq,hpr,hps,hqr,hqs,hrY,hsY⟩ := + Dihedral.edge_diamond B.system hrel hlen' + have hinj : Function.Injective (fun z : planeSubgroup M cs P => (z:W)*a₀) := by + intro p q hpq + exact Subtype.ext (mul_right_cancel hpq) + refine ⟨(p:W)*a₀,(q:W)*a₀,(r:W)*a₀,(s:W)*a₀, + fun h => hpq (hinj h),fun h => hrs (hinj h),?_,?_,?_,?_,?_,?_,?_,?_⟩ + · simpa only [hxEq] using (B.coset_step_iff hmin X p).mpr hXp + · simpa only [hxEq] using (B.coset_step_iff hmin X q).mpr hXq + · exact (B.coset_step_iff hmin p r).mpr hpr + · exact (B.coset_step_iff hmin p s).mpr hps + · exact (B.coset_step_iff hmin q r).mpr hqr + · exact (B.coset_step_iff hmin q s).mpr hqs + · simpa only [hyEq] using (B.coset_step_iff hmin r Y).mpr hrY + · simpa only [hyEq] using (B.coset_step_iff hmin s Y).mpr hsY + +end KLInvariance.TitsSpace + +namespace KLInvariance +variable {I W : Type*} [Fintype I] [Group W] {M : CoxeterMatrix I} + +/-- General unlabelled Bruhat graph reconstruction completeness, for genuine +finite-rank Coxeter systems and arbitrary bottoms and interval ranks. -/ +theorem diamondEdges_of_bruhatStep (cs : CoxeterSystem M W) + {u b : W} {x y : Interval cs u b} (hxy : BruhatStep cs x.val y.val) : + DiamondEdges x y := by + suffices ∀ n : ℕ, ∀ x y : Interval cs u b, + cs.length y.val-cs.length x.val=n → BruhatStep cs x.val y.val → + DiamondEdges x y by + exact this _ x y rfl hxy + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro x y hn hxy + by_cases he : cs.length y.val=cs.length x.val+1 + · exact DiamondEdges.cover (interval_covBy_of_length_succ cs + (Relation.ReflTransGen.single hxy) he) + · have hn' : cs.length x.val+1 < cs.length y.val := by have := hxy.1; omega + obtain ⟨a,bm,c,d,hab,hcd,hxa,hxb,hac,had,hbc,hbd,hcy,hdy⟩ := + TitsSpace.ambient_edge_diamond hxy hn' + have leOf {p q : W} (h : BruhatStep cs p q) : BruhatLE cs p q := + Relation.ReflTransGen.single h + let A : Interval cs u b := ⟨a,bruhat_trans cs x.property.1 (leOf hxa), + bruhat_trans cs (leOf hac) (bruhat_trans cs (leOf hcy) y.property.2)⟩ + let B : Interval cs u b := ⟨bm,bruhat_trans cs x.property.1 (leOf hxb), + bruhat_trans cs (leOf hbc) (bruhat_trans cs (leOf hcy) y.property.2)⟩ + let C : Interval cs u b := ⟨c, + bruhat_trans cs x.property.1 (bruhat_trans cs (leOf hxa) (leOf hac)), + bruhat_trans cs (leOf hcy) y.property.2⟩ + let D : Interval cs u b := ⟨d, + bruhat_trans cs x.property.1 (bruhat_trans cs (leOf hxa) (leOf had)), + bruhat_trans cs (leOf hdy) y.property.2⟩ + have hsmall {p q : Interval cs u b} (hpq : BruhatStep cs p.val q.val) + (hp : cs.length x.val ≤ cs.length p.val) + (hq : cs.length q.val ≤ cs.length y.val) + (hs : cs.length x.val < cs.length p.val ∨ cs.length q.val < cs.length y.val) : + DiamondEdges p q := by + exact ih _ (by omega) p q rfl hpq + have h₁ := hxa.1 + have h₂ := hxb.1 + have h₃ := hac.1 + have h₄ := had.1 + have h₅ := hbc.1 + have h₆ := hbd.1 + have h₇ := hcy.1 + have h₈ := hdy.1 + refine DiamondEdges.diamond + (hsmall (p := x) (q := A) hxa ?_ ?_ ?_) + (hsmall (p := x) (q := B) hxb ?_ ?_ ?_) + (hsmall (p := A) (q := C) hac ?_ ?_ ?_) + (hsmall (p := A) (q := D) had ?_ ?_ ?_) + (hsmall (p := B) (q := C) hbc ?_ ?_ ?_) + (hsmall (p := B) (q := D) hbd ?_ ?_ ?_) + (hsmall (p := C) (q := y) hcy ?_ ?_ ?_) + (hsmall (p := D) (q := y) hdy ?_ ?_ ?_) + (fun h => hab (congrArg Subtype.val h)) + (fun h => hcd (congrArg Subtype.val h)) + all_goals first | omega | (dsimp only [A,B,C,D]; omega) + +/-- An abstract interval order isomorphism determines its actual directed +reflection edges. No root labels, generators or geometric data are supplied to +that isomorphism. This proves the finite-rank graph input of the source main. -/ +theorem intervalIso_bruhatStep_iff {I' W' : Type*} [Fintype I'] [Group W'] + {M' : CoxeterMatrix I'} (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} (e : Interval cs u b ≃o Interval cs' u' b') + (x y : Interval cs u b) : + BruhatStep cs' (e x).val (e y).val ↔ BruhatStep cs x.val y.val := by + constructor + · intro h + exact diamondEdges_bruhatStep cs ((DiamondEdges.map_iff e).mp + (diamondEdges_of_bruhatStep cs' h)) + · intro h + exact diamondEdges_bruhatStep cs' ((diamondEdges_of_bruhatStep cs h).map e) + +end KLInvariance + +end + + +section + +/-! Rank-two Frobenius extension for an actual reflection on a symmetric +algebra. This supplies the elementary simple-reflection duality input; it +is not a proof of BMP or Elias--Williamson self-duality/characters. -/ +namespace KLInvariance.ReflectionFrobenius +universe uk ua uv +variable {k : Type uk} [Field k] [CharZero k] + {A : Type ua} [CommRing A] [IsDomain A] [Algebra k A] + +noncomputable section + +def fixed (τ : A ≃ₐ[k] A) : Subalgebra k A := + AlgHom.equalizer τ.toAlgHom (AlgHom.id k A) + +omit [CharZero k] [IsDomain A] in +@[simp] theorem mem_fixed (τ : A ≃ₐ[k] A) (a : A) : + a ∈ fixed τ ↔ τ a = a := Iff.rfl + +omit [CharZero k] [IsDomain A] in + theorem fixed_val (τ : A ≃ₐ[k] A) (a : fixed τ) : τ (a : A) = a := a.property + +variable (τ : A ≃ₐ[k] A) (α : A) + +def expand : (fixed τ × fixed τ) →ₗ[fixed τ] A where + toFun a := (a.1 : A) + α * (a.2 : A) + map_add' a b := by simp; ring + map_smul' c a := by simp only [Prod.smul_fst, Prod.smul_snd, smul_eq_mul, + Subalgebra.coe_mul, Subalgebra.smul_def, RingHom.id_apply]; ring + +omit [CharZero k] [IsDomain A] in +@[simp] theorem expand_apply (a : fixed τ × fixed τ) : + expand τ α a = (a.1 : A) + α * (a.2 : A) := rfl + +variable (hinv : Function.Involutive τ) (hα : α ≠ 0) (hanti : τ α = -α) + (hdiv : ∀ a : A, α ∣ a - τ a) + +omit [CharZero k] in +include hinv hα hanti in + theorem quotient_fixed {a d : A} (hd : a - τ a = α * d) : τ d = d := by + have hh := congrArg τ hd + simp only [map_sub, map_mul, hinv a, hanti] at hh + apply mul_left_cancel₀ hα + linear_combination hh + hd + +include hα hanti in + theorem expand_injective : Function.Injective (expand τ α) := by + intro a b hab + have ht := congrArg τ hab + simp only [expand_apply, map_add, map_mul, fixed_val, hanti] at ht + have he : (2 : A) * α * ((a.2 : A) - (b.2 : A)) = 0 := by + simp only [expand_apply] at hab + linear_combination hab - ht + have htwo : (2 : A) ≠ 0 := by + have hi : Function.Injective (algebraMap k A) := (algebraMap k A).injective + exact fun h => two_ne_zero (hi (by simpa only [map_ofNat, map_zero] using h : algebraMap k A (2:k) = algebraMap k A 0)) + have h2 : (a.2 : A) = (b.2 : A) := sub_eq_zero.mp + ((mul_eq_zero.mp he).resolve_left (mul_ne_zero htwo hα)) + have h1 : (a.1 : A) = (b.1 : A) := by + simpa only [expand_apply, h2, add_left_inj] using hab + exact Prod.ext (Subtype.ext h1) (Subtype.ext h2) + +include hinv hα hanti hdiv in + theorem expand_surjective : Function.Surjective (expand τ α) := by + intro a + obtain ⟨d, hd⟩ := hdiv a + have hdf : τ d = d := quotient_fixed τ α hinv hα hanti hd + let h : k := (2:k)⁻¹ + have htwo : (2:A) * algebraMap k A h = 1 := by + rw [show (2:A) = algebraMap k A (2:k) by exact (map_ofNat (algebraMap k A) 2).symm, ← map_mul] + simp [h] + let c₀ : fixed τ := ⟨algebraMap k A h * (a + τ a), by + simp only [mem_fixed, map_mul, AlgEquiv.commutes, map_add, hinv a] + ring⟩ + let c₁ : fixed τ := ⟨algebraMap k A h * d, by + simp only [mem_fixed, map_mul, AlgEquiv.commutes, hdf]⟩ + refine ⟨(c₀,c₁), ?_⟩ + change algebraMap k A h * (a + τ a) + α * (algebraMap k A h * d) = a + linear_combination a * htwo - (algebraMap k A h) * hd + +/-- The actual invariant-ring basis `1, α`, with no finiteness assumption. -/ +def coordinates : A ≃ₗ[fixed τ] (fixed τ × fixed τ) := + (LinearEquiv.ofBijective (expand τ α) + ⟨expand_injective τ α hα hanti, expand_surjective τ α hinv hα hanti hdiv⟩).symm + +@[simp] theorem expand_coordinates (a : A) : + expand τ α (coordinates τ α hinv hα hanti hdiv a) = a := + (coordinates τ α hinv hα hanti hdiv).symm_apply_apply a + +@[simp] theorem coordinates_expand (a : fixed τ × fixed τ) : + coordinates τ α hinv hα hanti hdiv (expand τ α a) = a := + (coordinates τ α hinv hα hanti hdiv).apply_symm_apply a + + +def trace : A →ₗ[fixed τ] fixed τ := + (LinearMap.snd _ _ _).comp (coordinates τ α hinv hα hanti hdiv).toLinearMap + + theorem trace_expand (a : fixed τ × fixed τ) : + trace τ α hinv hα hanti hdiv (expand τ α a) = a.2 := by + change (coordinates τ α hinv hα hanti hdiv (expand τ α a)).2 = a.2 + rw [coordinates_expand] + +omit [CharZero k] [IsDomain A] in +include hanti in + theorem square_fixed : α * α ∈ fixed τ := by + simp only [mem_fixed, map_mul, hanti, neg_mul_neg] + + theorem trace_mul (a b : A) : + trace τ α hinv hα hanti hdiv (a*b) = + (coordinates τ α hinv hα hanti hdiv a).1 * + (coordinates τ α hinv hα hanti hdiv b).2 + + (coordinates τ α hinv hα hanti hdiv a).2 * + (coordinates τ α hinv hα hanti hdiv b).1 := by + let c := coordinates τ α hinv hα hanti hdiv a + let d := coordinates τ α hinv hα hanti hdiv b + let α₂ : fixed τ := ⟨α*α, square_fixed τ α hanti⟩ + have he : a*b = expand τ α + (c.1*d.1+α₂*c.2*d.2, c.1*d.2+c.2*d.1) := by + rw [← expand_coordinates τ α hinv hα hanti hdiv a, + ← expand_coordinates τ α hinv hα hanti hdiv b] + change ((c.1:A)+α*(c.2:A))*((d.1:A)+α*(d.2:A)) = + (c.1:A)*(d.1:A)+(α*α)*(c.2:A)*(d.2:A)+ + α*((c.1:A)*(d.2:A)+(c.2:A)*(d.1:A)) + ring + rw [he,trace_expand] + +section Pair +variable (R : Type*) [CommRing R] + +def crossPair : (R × R) →ₗ[R] Module.Dual R (R × R) where + toFun a := + { toFun := fun b => a.1*b.2+a.2*b.1 + map_add' := by intro b c; simp; ring + map_smul' := by intro r b; simp; ring } + map_add' := by intro a b; apply LinearMap.ext; intro c; simp; ring + map_smul' := by intro r a; apply LinearMap.ext; intro b; simp; ring + + theorem crossPair_bijective : Function.Bijective (crossPair R) := by + constructor + · intro a b hab + have h₁ := congrArg (fun f : Module.Dual R (R×R) => f (0,1)) hab + have h₂ := congrArg (fun f : Module.Dual R (R×R) => f (1,0)) hab + exact Prod.ext (by simpa [crossPair] using h₁) (by simpa [crossPair] using h₂) + · intro f + refine ⟨(f (0,1), f (1,0)), ?_⟩ + apply LinearMap.ext + intro a + have ha : a = a.1 • (1,0) + a.2 • (0,1) := by simp + change f (0,1)*a.2 + f (1,0)*a.1 = f a + calc + _ = a.1 * f (1,0) + a.2 * f (0,1) := by ring + _ = f (a.1 • (1,0) + a.2 • (0,1)) := by rw [map_add,map_smul,map_smul]; rfl + _ = f a := congrArg f ha.symm + +def crossPairEquiv : (R × R) ≃ₗ[R] Module.Dual R (R × R) := + LinearEquiv.ofBijective (crossPair R) (crossPair_bijective R) + +end Pair + +/-- The Frobenius duality over the invariant ring is integral and perfect. -/ +def duality : A ≃ₗ[fixed τ] Module.Dual (fixed τ) A := + (coordinates τ α hinv hα hanti hdiv).trans + ((crossPairEquiv (fixed τ)).trans + (coordinates τ α hinv hα hanti hdiv).dualMap) + + theorem duality_apply (a b : A) : + duality τ α hinv hα hanti hdiv a b = trace τ α hinv hα hanti hdiv (a*b) := by + rw [trace_mul] + rfl + + theorem duality_balanced (a b c : A) : + duality τ α hinv hα hanti hdiv (c*a) b = + duality τ α hinv hα hanti hdiv a (c*b) := by + rw [duality_apply,duality_apply] + congr 1 + ring + + +section Symmetric +variable {V : Type uv} [AddCommGroup V] [Module k V] + +def symmetricMap (e : V ≃ₗ[k] V) : SymmetricAlgebra k V →ₐ[k] SymmetricAlgebra k V := + SymmetricAlgebra.lift ((SymmetricAlgebra.ι k V).comp e.toLinearMap) + +omit [CharZero k] in +@[simp] theorem symmetricMap_ι (e : V ≃ₗ[k] V) (v : V) : + symmetricMap e (SymmetricAlgebra.ι k V v) = SymmetricAlgebra.ι k V (e v) := by + simp [symmetricMap] + +omit [CharZero k] in + theorem symmetricMap_comp (e d : V ≃ₗ[k] V) : + (symmetricMap d).comp (symmetricMap e) = symmetricMap (e.trans d) := by + apply SymmetricAlgebra.algHom_ext + ext v + simp + +omit [CharZero k] in + theorem symmetricMap_refl : symmetricMap (LinearEquiv.refl k V) = + AlgHom.id k (SymmetricAlgebra k V) := by + apply SymmetricAlgebra.algHom_ext + ext v + simp + +/-- The algebra action is induced by the linear reflection, not postulated. -/ +def symmetricAction (e : V ≃ₗ[k] V) : SymmetricAlgebra k V ≃ₐ[k] SymmetricAlgebra k V := + AlgEquiv.ofAlgHom (symmetricMap e) (symmetricMap e.symm) + (by rw [symmetricMap_comp,LinearEquiv.symm_trans_self,symmetricMap_refl]) + (by rw [symmetricMap_comp,LinearEquiv.self_trans_symm,symmetricMap_refl]) + +omit [CharZero k] in +@[simp] theorem symmetricAction_ι (e : V ≃ₗ[k] V) (v : V) : + symmetricAction e (SymmetricAlgebra.ι k V v) = SymmetricAlgebra.ι k V (e v) := + symmetricMap_ι e v + +variable (root : V) (coroot : Module.Dual k V) (hroot : coroot root = 2) + +abbrev reflectionAction : SymmetricAlgebra k V ≃ₐ[k] SymmetricAlgebra k V := + symmetricAction (Module.reflection hroot) + +omit [CharZero k] in + theorem reflectionAction_involutive : Function.Involutive (reflectionAction root coroot hroot) := by + intro a + have he : (reflectionAction root coroot hroot).toAlgHom.comp + (reflectionAction root coroot hroot).toAlgHom = + AlgHom.id k (SymmetricAlgebra k V) := by + apply SymmetricAlgebra.algHom_ext + ext v + simp [Module.involutive_reflection hroot v] + exact congrArg (fun f : SymmetricAlgebra k V →ₐ[k] SymmetricAlgebra k V => f a) he + +omit [CharZero k] in + theorem reflectionAction_anti : + reflectionAction root coroot hroot (SymmetricAlgebra.ι k V root) = + -SymmetricAlgebra.ι k V root := by + simp + +include hroot in + theorem reflectionRoot_ne_zero : SymmetricAlgebra.ι k V root ≠ 0 := by + intro he + have hh := congrArg (SymmetricAlgebra.lift coroot) he + rw [SymmetricAlgebra.lift_ι_apply,map_zero,hroot] at hh + exact two_ne_zero hh + +omit [CharZero k] in + theorem reflectionAction_divisible (a : SymmetricAlgebra k V) : + SymmetricAlgebra.ι k V root ∣ a-reflectionAction root coroot hroot a := by + induction a using SymmetricAlgebra.induction with + | algebraMap c => simp + | ι v => + refine ⟨algebraMap k (SymmetricAlgebra k V) (coroot v), ?_⟩ + rw [reflectionAction,symmetricAction_ι,Module.reflection_apply,map_sub,map_smul] + simp only [sub_sub_cancel,Algebra.smul_def] + ring + | mul a b ha hb => + obtain ⟨c,hc⟩ := ha + obtain ⟨d,hd⟩ := hb + refine ⟨c*b+(reflectionAction root coroot hroot a)*d, ?_⟩ + rw [map_mul] + linear_combination b*hc+(reflectionAction root coroot hroot a)*hd + | add a b ha hb => + simpa only [map_add, add_sub_add_comm] using dvd_add ha hb + +/-- A genuine simple-reflection integral Frobenius extension in characteristic +zero, for the symmetric algebra of any representation carrying the reflection. -/ +def reflectionDuality : + SymmetricAlgebra k V ≃ₗ[fixed (reflectionAction root coroot hroot)] + Module.Dual (fixed (reflectionAction root coroot hroot)) (SymmetricAlgebra k V) := + duality (reflectionAction root coroot hroot) (SymmetricAlgebra.ι k V root) + (reflectionAction_involutive root coroot hroot) (reflectionRoot_ne_zero root coroot hroot) + (reflectionAction_anti root coroot hroot) (reflectionAction_divisible root coroot hroot) + +end Symmetric + +end +end KLInvariance.ReflectionFrobenius + +end + + +section + +/-! Frobenius extensions for the actual simple reflections of the extended +theorem realization, not abstract reflection data carried by the target. -/ + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/Dihedral.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/Dihedral.lean index 58955f15e443056ba3e02efc8726a7d12b56d85b..50f6d6250ec94d19017ad7e4ed3da29b70566ef9 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/Dihedral.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/Dihedral.lean @@ -1,803 +1,803 @@ -import OAI.RepresentationTheory.KazhdanLusztig.CanonicalKL - -namespace OAI - -/-! -Interval restrictions, dihedral Coxeter and Hecke calculations, and the genuine square-parameter R normalization. --/ - -section - -namespace KLInvariance - -universe u₁ v₁ u₂ v₂ -variable {B : Type u₁} {W : Type v₁} [Group W] {M : CoxeterMatrix B} -variable {B' : Type u₂} {W' : Type v₂} [Group W'] {M' : CoxeterMatrix B'} - -/-- Restriction of the actual interval isomorphism to any subinterval. This -is the same unlabeled map, not a new isomorphism with extra structure. -/ -def intervalIso_restrict (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (ι : Interval cs u b ≃o Interval cs' u' b') - (x y : Interval cs u b) : - Interval cs x.val y.val ≃o Interval cs' (ι x).val (ι y).val where - toFun z := - let zI : Interval cs u b := ⟨z.val, bruhat_trans cs x.property.1 z.property.1, - bruhat_trans cs z.property.2 y.property.2⟩ - ⟨(ι zI).val, ι.monotone (show x ≤ zI from z.property.1), - ι.monotone (show zI ≤ y from z.property.2)⟩ - invFun z := - let zI : Interval cs' u' b' := ⟨z.val, - bruhat_trans cs' (ι x).property.1 z.property.1, - bruhat_trans cs' z.property.2 (ι y).property.2⟩ - ⟨(ι.symm zI).val, - by - change x ≤ ι.symm zI - simpa only [OrderIso.symm_apply_apply] using - ι.symm.monotone (show ι x ≤ zI from z.property.1), - by - change ι.symm zI ≤ y - simpa only [OrderIso.symm_apply_apply] using - ι.symm.monotone (show zI ≤ ι y from z.property.2)⟩ - left_inv z := by - apply Subtype.ext - let zI : Interval cs u b := ⟨z.val, bruhat_trans cs x.property.1 z.property.1, - bruhat_trans cs z.property.2 y.property.2⟩ - change (ι.symm (ι zI)).val = zI.val - rw [ι.symm_apply_apply] - right_inv z := by - apply Subtype.ext - let zI : Interval cs' u' b' := ⟨z.val, - bruhat_trans cs' (ι x).property.1 z.property.1, - bruhat_trans cs' z.property.2 (ι y).property.2⟩ - change (ι (ι.symm zI)).val = zI.val - rw [ι.apply_symm_apply] - map_rel_iff' := by - intro z w - exact ι.map_rel_iff - -@[simp] theorem intervalIso_restrict_val (cs : CoxeterSystem M W) - (cs' : CoxeterSystem M' W') {u b : W} {u' b' : W'} - (ι : Interval cs u b ≃o Interval cs' u' b') (x y : Interval cs u b) - (z : Interval cs x.val y.val) : - (intervalIso_restrict cs cs' ι x y z).val = - (ι ⟨z.val, bruhat_trans cs x.property.1 z.property.1, - bruhat_trans cs z.property.2 y.property.2⟩).val := rfl - -end KLInvariance - -namespace KLInvariance.Dihedral - -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} - -/-- The alternating expression starting with `i`, unlike Mathlib's -`alternatingWord`, which specifies the final letter. -/ -def alt (i : Bool) : ℕ → List Bool - | 0 => [] - | n + 1 => i :: alt (!i) n - -@[simp] theorem alt_zero (i : Bool) : alt i 0 = [] := rfl -@[simp] theorem alt_succ (i : Bool) (n : ℕ) : alt i (n+1) = i :: alt (!i) n := rfl -@[simp] theorem length_alt (i : Bool) (n : ℕ) : (alt i n).length = n := by - induction n generalizing i with - | zero => rfl - | succ n ih => simp [ih] - -@[simp] theorem take_alt (i : Bool) (k n : ℕ) : (alt i n).take k = alt i (min k n) := by - induction n generalizing i k with - | zero => simp - | succ n ih => - cases k with - | zero => simp - | succ k => simp [ih] - -theorem reduced_cons_cons_ne (cs : CoxeterSystem M W) {i j : Bool} {ω : List Bool} - (h : cs.IsReduced (i :: j :: ω)) : i ≠ j := by - rintro rfl - have hlen := cs.length_wordProd_le ω - have heq := h.eq - simp only [cs.wordProd_cons, cs.simple_mul_simple_cancel_left, List.length_cons] at heq - omega - -theorem reduced_cons_eq_alt (cs : CoxeterSystem M W) (i : Bool) (ω : List Bool) - (h : cs.IsReduced (i :: ω)) : i :: ω = alt i (ω.length + 1) := by - induction ω generalizing i with - | nil => simp - | cons j ω ih => - have hj : j = !i := by - have := reduced_cons_cons_ne cs h - cases i <;> cases j <;> simp_all - have hω : cs.IsReduced (j :: ω) := by simpa using h.drop 1 - rw [show (j :: ω).length + 1 = (ω.length + 1) + 1 by rfl, alt_succ] - congr 1 - rw [ih j hω, hj] - -theorem reduced_eq_alt (cs : CoxeterSystem M W) (ω : List Bool) - (h : cs.IsReduced ω) : ∃ i, ω = alt i ω.length := by - cases ω with - | nil => exact ⟨false, rfl⟩ - | cons i ω => exact ⟨i, reduced_cons_eq_alt cs i ω h⟩ - -theorem exists_alt (cs : CoxeterSystem M W) (w : W) : - ∃ i, w = cs.wordProd (alt i (cs.length w)) := by - obtain ⟨ω, hω, hw⟩ := cs.exists_isReduced w - obtain ⟨i, hi⟩ := reduced_eq_alt cs ω hω - refine ⟨i, ?_⟩ - rw [hw, hω.eq, ← hi] - -theorem reduced_alt_take (cs : CoxeterSystem M W) {i : Bool} {k n : ℕ} - (h : cs.IsReduced (alt i n)) (hk : k ≤ n) : cs.IsReduced (alt i k) := by - simpa only [take_alt, Nat.min_eq_left hk] using h.take k - -theorem alt_sublist (i : Bool) {k n : ℕ} (h : k ≤ n) : (alt i k).Sublist (alt i n) := by - simpa only [take_alt, Nat.min_eq_left h] using List.take_sublist k (alt i n) - -end KLInvariance.Dihedral - -namespace KLInvariance.Dihedral - -noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p - -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} - -/-- In a rank-two Coxeter system, every strictly shorter element lies below -every longer element. This uses the actual Bruhat subword theorem. -/ -theorem shorter_bruhat (cs : CoxeterSystem M W) {x w : W} - (h : cs.length x < cs.length w) : BruhatLE cs x w := by - obtain ⟨i, hi⟩ := exists_alt cs w - obtain ⟨j, hj⟩ := exists_alt cs x - have hr : cs.IsReduced (alt i (cs.length w)) := by - change cs.length (cs.wordProd (alt i (cs.length w))) = (alt i (cs.length w)).length - rw [← hi, length_alt] - obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero (show cs.length w ≠ 0 by omega) - rw [hn] at hi hr h - rw [hi, hj] - apply bruhat_of_subword cs _ hr - by_cases hji : j = i - · subst j - exact alt_sublist i (by omega) - · have hj' : j = !i := by cases i <;> cases j <;> first | rfl | exact (hji rfl).elim - rw [hj', alt_succ] - exact (alt_sublist (!i) (by omega)).cons i - -theorem bruhat_iff_length_lt_or_eq (cs : CoxeterSystem M W) (x w : W) : - BruhatLE cs x w ↔ cs.length x < cs.length w ∨ x = w := by - constructor - · intro h - by_cases he : x = w - · exact Or.inr he - · exact Or.inl (length_lt_of_bruhat_ne cs h he) - · rintro (h | rfl) - · exact shorter_bruhat cs h - · exact bruhat_refl cs _ - -theorem eq_alt_of_descent (cs : CoxeterSystem M W) (i : Bool) {w : W} - (h : cs.length (cs.simple i * w) < cs.length w) : - w = cs.wordProd (alt i (cs.length w)) := by - obtain ⟨ω, hω, hw⟩ := cs.exists_isReduced (cs.simple i * w) - have hlen : cs.length w = ω.length + 1 := by - have := cs.length_simple_mul w i - rw [hw, hω.eq] at this h - omega - have hp : cs.wordProd (i :: ω) = w := by - simp only [cs.wordProd_cons, ← hw, cs.simple_mul_simple_cancel_left] - have hr : cs.IsReduced (i :: ω) := by - simpa only [CoxeterSystem.IsReduced, hp, List.length_cons] using hlen - rw [hlen, ← reduced_cons_eq_alt cs i ω hr, hp] - -end KLInvariance.Dihedral - -namespace KLInvariance.Dihedral - -noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p - -open Hecke (Space basis) -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -variable {C : Type*} [CommRing C] - -noncomputable def lowerSum (cs : CoxeterSystem M W) (w : W) : Space W C := - ∑ z ∈ lowerFinset cs w, basis z - -@[simp] theorem lowerSum_coeff (cs : CoxeterSystem M W) (w x : W) : - (lowerSum cs w : Space W C) x = if BruhatLE cs x w then 1 else 0 := by - classical - simp [lowerSum, basis, Finsupp.single_apply, eq_comm] - -@[simp] theorem lowerSum_one (cs : CoxeterSystem M W) : - (lowerSum cs 1 : Space W C) = basis 1 := by - classical - ext x - simp only [lowerSum_coeff, basis, Finsupp.single_apply] - have h : BruhatLE cs x 1 ↔ 1 = x := by - rw [bruhat_iff_length_lt_or_eq] - simp [eq_comm] - rw [h] - -/-- The two members of an s-string enter a lower ideal together precisely -on the common lower interval appearing in the source's rank-two product. -/ -theorem double_string (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) - (hr : cs.IsReduced (alt i (n+2))) (x : W) : - (BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) ∧ - BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1)))) ↔ - (0 < n ∧ BruhatLE cs x (cs.wordProd (alt i n))) := by - have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 - have hrp := reduced_alt_take cs hr (show n ≤ n+2 by omega) - have hlenw : cs.length (cs.wordProd (alt i (n+2))) = n+2 := by - simpa only [length_alt] using hr.eq - have hlenz : cs.length (cs.wordProd (alt (!i) (n+1))) = n+1 := by - simpa only [length_alt] using hr'.eq - have hlenp : cs.length (cs.wordProd (alt i n)) = n := by - simpa only [length_alt] using hrp.eq - have hsz : cs.simple i * cs.wordProd (alt (!i) (n+1)) = - cs.wordProd (alt i (n+2)) := by rw [alt_succ i (n+1), cs.wordProd_cons] - constructor - · rintro ⟨hx, hsx⟩ - have hxlen := length_le_of_bruhat cs hx - have hsxlen := length_le_of_bruhat cs hsx - have hxl : cs.length x < n+1 := by - rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hx with h | rfl - · omega - · rw [hsz, hlenw] at hsxlen - omega - have hsxl : cs.length (cs.simple i * x) < n+1 := by - rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hsx with h | h - · omega - · have heq : x = cs.wordProd (alt i (n+2)) := by - rw [← hsz, ← h, cs.simple_mul_simple_cancel_left] - rw [heq, hlenw] at hxl - omega - have hchange := cs.length_simple_mul x i - have hn : 0 < n := by omega - refine ⟨hn, ?_⟩ - by_cases hxlt : cs.length x < n - · exact shorter_bruhat cs (by omega) - · have hxi : cs.length x = n := by omega - have hdesc : cs.length (cs.simple i * x) < cs.length x := by omega - have heq := eq_alt_of_descent cs i hdesc - rw [hxi] at heq - rw [heq] - exact bruhat_refl cs _ - · rintro ⟨hn, hx⟩ - have hxlen := length_le_of_bruhat cs hx - constructor - · exact shorter_bruhat cs (by omega) - · by_cases hxlt : cs.length x < n - · have := cs.length_simple_mul x i - exact shorter_bruhat cs (by omega) - · have heq : x = cs.wordProd (alt i n) := by - rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hx with h | h - · omega - · exact h - obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (show n ≠ 0 by omega) - have hrpt : cs.IsReduced (alt (!i) k) := by simpa using hrp.drop 1 - have hpk : cs.length (cs.simple i * x) = k := by - rw [heq, alt_succ, cs.wordProd_cons, cs.simple_mul_simple_cancel_left, - hrpt.eq, length_alt] - exact shorter_bruhat cs (by omega) - -end KLInvariance.Dihedral - -namespace KLInvariance.Dihedral - -noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p - -open Hecke (Space basis) -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -variable {C : Type*} [CommRing C] - -theorem left_plus_coeff (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) - (v : Space W C) (x : W) : - (v + HeckeQ.left cs (q : C) i v) x = - if cs.length (cs.simple i * x) < cs.length x then - v (cs.simple i * x) + (q : C) * v x - else v x + (q : C) * v (cs.simple i * x) := by - have h := congrArg (fun t : Space W C => (q : C) * t x) - (HeckeQ.leftInv_apply cs q i v) - simp only [Finsupp.smul_apply, smul_eq_mul, Finsupp.sub_apply, ← mul_assoc, - q.mul_inv, one_mul] at h - rw [HeckeQ.leftInv_coeff] at h - simp only [Finsupp.add_apply] - split_ifs at h ⊢ - · linear_combination -h + v (cs.simple i * x) * q.mul_inv - · linear_combination -h + v x * q.mul_inv - -theorem union_string (cs : CoxeterSystem M W) (i : Bool) {z : W} - (hz : cs.length z < cs.length (cs.simple i * z)) (x : W) : - BruhatLE cs x (cs.simple i * z) ↔ - BruhatLE cs x z ∨ BruhatLE cs (cs.simple i * x) z := by - have hsz : cs.length (cs.simple i * (cs.simple i * z)) < - cs.length (cs.simple i * z) := by simpa using hz - constructor - · intro h - have hh := lowerSimple_mono cs i h - simp only [lowerSimple, cs.simple_mul_simple_cancel_left] at hh - split_ifs at hh with hx - · exact Or.inr hh - · exact Or.inl hh - · rintro (h | h) - · apply bruhat_trans cs h - exact Relation.ReflTransGen.single ⟨hz, cs.simple i, cs.isReflection_simple i, rfl⟩ - · simpa only [cs.simple_mul_simple_cancel_left] using - Hecke.simple_mul_le_ascent cs i h hz - -noncomputable def correction (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : Space W C := - if n = 0 then 0 else lowerSum cs (cs.wordProd (alt i n)) - -@[simp] theorem correction_coeff (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) (x : W) : - (correction cs i n : Space W C) x = - if 0 < n ∧ BruhatLE cs x (cs.wordProd (alt i n)) then 1 else 0 := by - classical - by_cases h : n = 0 - · simp [correction, h] - · have hn : 0 < n := Nat.pos_of_ne_zero h - simp [correction, h, hn] - -/-- The Hecke sum identity `loc:dihedral-product`, before normalization by -q to a half-integer power. Every interval here is genuine strong Bruhat. -/ -theorem lowerSum_product (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) (n : ℕ) - (hr : cs.IsReduced (alt i (n+2))) : - lowerSum cs (cs.wordProd (alt (!i) (n+1))) + - HeckeQ.left cs (q : C) i (lowerSum cs (cs.wordProd (alt (!i) (n+1)))) = - lowerSum cs (cs.wordProd (alt i (n+2))) + (q : C) • correction cs i n := by - classical - have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 - have hz : cs.length (cs.wordProd (alt (!i) (n+1))) < - cs.length (cs.simple i * cs.wordProd (alt (!i) (n+1))) := by - rw [← cs.wordProd_cons, ← alt_succ, hr.eq, hr'.eq, length_alt, length_alt] - omega - ext x - rw [left_plus_coeff, Finsupp.add_apply, Finsupp.smul_apply, smul_eq_mul, - correction_coeff, lowerSum_coeff, lowerSum_coeff, lowerSum_coeff] - have hu := union_string cs i hz x - rw [← cs.wordProd_cons, ← alt_succ] at hu - have hd := double_string cs i n hr x - simp only [hu, ← hd] - by_cases hdesc : cs.length (cs.simple i * x) < cs.length x - · have hclosure : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) → - BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) := by - intro h - apply bruhat_trans cs _ h - exact Relation.ReflTransGen.single - ⟨hdesc, cs.simple i, cs.isReflection_simple i, by simp⟩ - by_cases hx : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) - · simp [-alt_succ, hdesc, hx, hclosure hx] - · by_cases hs : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) <;> - simp [-alt_succ, hdesc, hx, hs] - · have hasc : cs.length x < cs.length (cs.simple i * x) := by - have := cs.length_simple_mul x i - omega - have hclosure : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) → - BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) := by - intro h - apply bruhat_trans cs _ h - exact Relation.ReflTransGen.single - ⟨hasc, cs.simple i, cs.isReflection_simple i, rfl⟩ - by_cases hs : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) - · simp [-alt_succ, hdesc, hs, hclosure hs] - · by_cases hx : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) <;> - simp [-alt_succ, hdesc, hx, hs] - -end KLInvariance.Dihedral - -namespace KLInvariance.HeckeQ - -universe uR vR -variable {B : Type uR} {W : Type vR} [Group W] {M : CoxeterMatrix B} -variable {C : Type*} [CommRing C] - -noncomputable def dualR (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : C := - (-(q : C)) ^ cs.length y * (-(↑q⁻¹ : C)) ^ cs.length x * rValue cs q⁻¹ x y - -@[simp] theorem dualR_diagonal (cs : CoxeterSystem M W) (q : Cˣ) (x : W) : - dualR cs q x x = 1 := by - rw [dualR, rValue_diagonal, mul_one, ← mul_pow] - simp - -theorem dualR_zero (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) - (h : ¬BruhatLE cs x y) : dualR cs q x y = 0 := by - simp [dualR, rValue_zero cs q⁻¹ x y h] - -theorem dualR_recursion (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) (i : B) - (hy : cs.length (cs.simple i * y) < cs.length y) : - dualR cs q x y = - if cs.length (cs.simple i * x) < cs.length x then - dualR cs q (cs.simple i * x) (cs.simple i * y) - else ((q : C) - 1) * dualR cs q x (cs.simple i * y) + - (q : C) * dualR cs q (cs.simple i * x) (cs.simple i * y) := by - have hyl : cs.length y = cs.length (cs.simple i * y) + 1 := by - have := cs.length_simple_mul y i - omega - unfold dualR - rw [rValue_recursion cs q⁻¹ x y i hy] - split_ifs with hx - · have hxl : cs.length x = cs.length (cs.simple i * x) + 1 := by - have := cs.length_simple_mul x i - omega - rw [hyl, hxl, pow_succ, pow_succ] - calc - _ = (-(q:C)) ^ cs.length (cs.simple i * y) * - (-(↑q⁻¹:C)) ^ cs.length (cs.simple i * x) * - rValue cs q⁻¹ (cs.simple i * x) (cs.simple i * y) * - ((q:C) * (↑q⁻¹:C)) := by ring - _ = _ := by rw [q.mul_inv, mul_one] - · have hxl : cs.length (cs.simple i * x) = cs.length x + 1 := by - have := cs.length_simple_mul x i - omega - rw [hyl, hxl, pow_succ, pow_succ] - have hq : (-(q:C)) * ((↑q⁻¹:C) - 1) = (q:C) - 1 := by - rw [mul_sub, neg_mul, q.mul_inv, mul_one] - ring - calc - _ = (-(q:C)) ^ cs.length (cs.simple i * y) * - (-(↑q⁻¹:C)) ^ cs.length x * - ((-(q:C)) * ((↑q⁻¹:C) - 1)) * rValue cs q⁻¹ x (cs.simple i * y) + - (q:C) * ((-(q:C)) ^ cs.length (cs.simple i * y) * - ((-(↑q⁻¹:C)) ^ cs.length x * (-(↑q⁻¹:C))) * - rValue cs q⁻¹ (cs.simple i * x) (cs.simple i * y)) := by ring - _ = _ := by rw [hq]; ring - -/-- Signed inversion symmetry of actual equal-parameter R-values, proved -from all-descent recurrence, not imposed as an additional normalization. -/ -theorem rValue_eq_dualR (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : - rValue cs q x y = dualR cs q x y := by - suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, - rValue cs q x y = dualR cs q x y by - exact this _ y rfl x - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro y hy x - by_cases hy1 : y = 1 - · subst y - by_cases hx1 : x = 1 - · subst x - simp - · have hnot : ¬BruhatLE cs x 1 := by - intro h - have hl := length_le_of_bruhat cs h - have hl0 : cs.length x = 0 := by simpa using hl - exact hx1 (cs.length_eq_zero_iff.mp hl0) - rw [rValue_zero cs q x 1 hnot, dualR_zero cs q x 1 hnot] - · obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one hy1 - have hsmall : cs.length (cs.simple i * y) < n := hy ▸ hi - rw [rValue_recursion cs q x y i hi, dualR_recursion cs q x y i hi, - ih _ hsmall _ rfl x, ih _ hsmall _ rfl (cs.simple i * x)] - -/-- R at the inverse parameter is exactly the corresponding bar coefficient -with the bottom q-power. This is the coefficient form used below. -/ -theorem rValue_inverse_eq_barBasis (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : - rValue cs q⁻¹ x y = (q:C) ^ cs.length x * barBasis cs q y x := by - rw [rValue_eq_dualR cs q⁻¹, dualR, inv_inv, rValue] - simp only [neg_pow (↑q⁻¹:C), neg_pow (q:C)] - have hsign (n : ℕ) : (-1:C)^n * (-1:C)^n = 1 := by - rw [← mul_pow]; simp - calc - _ = ((-1:C)^cs.length y * (-1:C)^cs.length y) * - ((-1:C)^cs.length x * (-1:C)^cs.length x) * - (((↑q⁻¹:C) * (q:C)) ^ cs.length y) * - (q:C)^cs.length x * barBasis cs q y x := by ring - _ = _ := by rw [hsign, hsign, q.inv_mul]; simp - -end KLInvariance.HeckeQ - -namespace KLInvariance.Dihedral - -noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p - -open Hecke (Space basis) -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -variable {C : Type*} [CommRing C] - -@[simp] theorem lowerSum_simple (cs : CoxeterSystem M W) (i : Bool) : - (lowerSum cs (cs.simple i) : Space W C) = basis 1 + basis (cs.simple i) := by - classical - ext x - rw [lowerSum_coeff, bruhat_iff_length_lt_or_eq, cs.length_simple] - simp only [Nat.lt_one_iff, cs.length_eq_zero_iff, Finsupp.add_apply, basis, - Finsupp.single_apply] - have hi : cs.simple i ≠ 1 := by - intro h - have := cs.length_simple i - simp [h] at this - by_cases hx : x = 1 - · subst x - simp [hi] - · by_cases hs : x = cs.simple i - · subst x - simp [hi, Ne.symm hi] - · simp [hx, hs, Ne.symm hx, Ne.symm hs] - -theorem plus_leftInv (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) - (v : Space W C) : - v + HeckeQ.leftInv cs q i v = - (↑q⁻¹:C) • (v + HeckeQ.left cs (q:C) i v) := by - rw [HeckeQ.leftInv_apply, smul_sub, smul_smul, mul_sub, q.inv_mul, mul_one] - module - -/-- Unnormalized form of bar invariance of the dihedral constant sums. -/ -theorem bar_lowerSum_alt (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) (n : ℕ) - (hr : cs.IsReduced (alt i n)) : - HeckeQ.barLinear cs q (lowerSum cs (cs.wordProd (alt i n))) = - (↑q⁻¹:C)^n • lowerSum cs (cs.wordProd (alt i n)) := by - induction n using Nat.strong_induction_on generalizing i with - | h n ih => - rcases n with _ | (_ | n) - · simp - · have hasc : cs.length (1:W) < cs.length (cs.simple i * 1) := by simp - have hb := HeckeQ.barBasis_simple_mul_ascent cs q i 1 hasc - simp only [mul_one, HeckeQ.barBasis_one] at hb - simp only [alt_succ, alt_zero, cs.wordProd_singleton, lowerSum_simple, - map_add, HeckeQ.barLinear_basis, HeckeQ.barBasis_one, hb] - rw [plus_leftInv, HeckeQ.left_basis] - simp - · have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 - have hrp := reduced_alt_take cs hr (show n ≤ n+2 by omega) - have hz := ih (n+1) (by omega) (!i) hr' - have hc : HeckeQ.barLinear cs q (correction cs i n) = - (↑q⁻¹:C)^n • correction cs i n := by - by_cases hn : n = 0 - · simp [correction, hn] - · simp only [correction, ite_eq_right hn] - exact ih n (by omega) i hrp - have hprod := lowerSum_product cs q i n hr - have hbar := congrArg (HeckeQ.barLinear cs q) - (lowerSum_product cs q⁻¹ i n hr) - have hinter := congrArg (fun f : Module.End C (Space W C) => - f (lowerSum cs (cs.wordProd (alt (!i) (n+1))))) - (HeckeQ.barLinear_left cs q i) - simp only [map_add, map_smul, Module.End.mul_apply] at hbar hinter - rw [hinter, hz, map_smul, ← smul_add, plus_leftInv, hprod] at hbar - simp only [smul_add, smul_smul, hc] at hbar - have hq1 : (↑q⁻¹:C)^(n+1) * (↑q⁻¹:C) = (↑q⁻¹:C)^(n+2) := by - exact (pow_succ (↑q⁻¹:C) (n+1)).symm - have hq2 : (↑q⁻¹:C)^(n+1) * ((↑q⁻¹:C) * (q:C)) = - (↑q⁻¹:C) * (↑q⁻¹:C)^n := by rw [q.inv_mul, mul_one, pow_succ']; - rw [hq1, hq2] at hbar - exact add_right_cancel hbar.symm - -theorem bar_lowerSum (cs : CoxeterSystem M W) (q : Cˣ) (w : W) : - HeckeQ.barLinear cs q (lowerSum cs w) = - (↑q⁻¹:C)^cs.length w • lowerSum cs w := by - obtain ⟨i, hi⟩ := exists_alt cs w - have hr : cs.IsReduced (alt i (cs.length w)) := by - simp only [CoxeterSystem.IsReduced, ← hi, length_alt] - simpa only [← hi] using bar_lowerSum_alt cs q i (cs.length w) hr - -end KLInvariance.Dihedral - -namespace KLInvariance.Dihedral - -noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p - -open Hecke (Space basis) -open Polynomial -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -variable {C : Type*} [CommRing C] - -theorem rValue_sum (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) - (hxy : BruhatLE cs x y) : - ∑ z ∈ lowerFinset cs y, HeckeQ.rValue cs q x z = - (q:C) ^ rankDifference cs x y := by - classical - have hb := congrArg (fun f : Space W C => f x) (bar_lowerSum cs q⁻¹ y) - simp only [Finsupp.smul_apply, smul_eq_mul, inv_inv, lowerSum_coeff, - ite_eq_left hxy, mul_one] at hb - rw [lowerSum, map_sum] at hb - simp only [Finsupp.coe_finsetSum, Finset.sum_apply, HeckeQ.barLinear_basis] at hb - have hlen : cs.length y = cs.length x + rankDifference cs x y := by - have := length_le_of_bruhat cs hxy - unfold rankDifference - omega - calc - _ = (↑q⁻¹:C)^cs.length x * - ∑ z ∈ lowerFinset cs y, HeckeQ.barBasis cs q⁻¹ z x := by - rw [Finset.mul_sum] - apply Finset.sum_congr rfl - intro z hz - simpa using HeckeQ.rValue_inverse_eq_barBasis cs q⁻¹ x z - _ = (↑q⁻¹:C)^cs.length x * (q:C)^cs.length y := by rw [hb] - _ = _ := by - rw [hlen, pow_add] - calc - _ = ((↑q⁻¹:C) * (q:C))^cs.length x * (q:C)^rankDifference cs x y := by - rw [mul_pow]; ring - _ = _ := by rw [q.inv_mul]; simp - -theorem rPolynomial_sum (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) : - ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z = - (X:ℤ[X]) ^ rankDifference cs x y := by - apply Polynomial.toLaurent_injective - simpa using rValue_sum cs OrdinaryR.variableUnit x y hxy - -noncomputable def constantP (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := - if BruhatLE cs x y then 1 else 0 - -theorem constant_normalizedKL (cs : CoxeterSystem M W) : - NormalizedKL cs (OrdinaryR.polynomial cs, constantP cs) where - R_diagonal := OrdinaryR.polynomial_diagonal cs - R_zero := OrdinaryR.polynomial_zero cs - R_recursion := OrdinaryR.polynomial_recursion cs - P_diagonal := by intro x; simp [constantP, bruhat_refl cs x] - P_zero := by intro x y h; simp [constantP, h] - P_degree := by - intro x y hxy hne - have := length_lt_of_bruhat_ne cs hxy hne - simp only [constantP, ite_eq_left hxy, natDegree_one, mul_zero] - unfold rankDifference - omega - reciprocity := by - intro x y hxy - simp only [constantP, ite_eq_left hxy, reflect_one] - classical - let := interval_finite cs x y - let : Fintype (Interval cs x y) := Fintype.ofFinite _ - rw [finsum_eq_sum_of_fintype] - have heq : (∑ z : Interval cs x y, - OrdinaryR.polynomial cs x z.val * (if BruhatLE cs z.val y then 1 else 0)) = - ∑ z : Interval cs x y, OrdinaryR.polynomial cs x z.val := by - apply Finset.sum_congr rfl - intro z hz - rw [ite_eq_left z.property.2, mul_one] - rw [heq] - have hsum := Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs x y))) - ((lowerFinset cs y).filter (fun z => BruhatLE cs x z)) - (fun z => by simp only [Finset.mem_filter, mem_lowerFinset]; exact and_comm) - (fun z => OrdinaryR.polynomial cs x z) - symm - refine hsum.symm.trans (Eq.trans ?_ (rPolynomial_sum cs x y hxy)) - apply Finset.sum_subset (Finset.filter_subset _ _) - intro z hz hnot - have hnxz : ¬BruhatLE cs x z := fun hxz => hnot (Finset.mem_filter.mpr ⟨hz, hxz⟩) - exact OrdinaryR.polynomial_zero cs x z hnxz - -/-- The manuscript's necessary dihedral calculation (`loc:dihedral-kl`), -for the actual KL family, with the exact standard normalization. This is -support for localization, not a substitute for general invariance. -/ -theorem klPolynomial_eq_one (cs : CoxeterSystem M W) (x y : W) - (hxy : BruhatLE cs x y) : klPolynomial cs x y = 1 := by - have heq := normalizedKL_unique cs (klFamilies_spec cs) (constant_normalizedKL cs) - have hp := congrArg (fun RP : PolynomialFamilies W => RP.2 x y) heq - simpa only [klPolynomial, constantP, ite_eq_left hxy] using hp - -end KLInvariance.Dihedral - -end - -section - -namespace KLInvariance -open Polynomial -universe u v -variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} - -/-- The exact square-parameter normalization, proved from the two genuine -Hecke recurrences. Integer exponents let the formula include incomparable -pairs without silently changing the R-polynomial definition. -/ -theorem rPolynomial_normalization {C : Type*} [Field C] - (cs : CoxeterSystem M W) (v : C) (hv : v ≠ 0) (x y : W) : - eval₂ (Int.castRingHom C) (v^2) (rPolynomial cs x y) = - v ^ ((cs.length y : ℤ) - cs.length x) * - eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x y) := by - rw [rPolynomial_eq_constructed] - suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, - eval₂ (Int.castRingHom C) (v^2) (OrdinaryR.polynomial cs x y) = - v ^ ((cs.length y : ℤ) - cs.length x) * - eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x y) from - this _ y rfl x - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro y hy x - by_cases h1 : y=1 - · subst y - by_cases hx : x=1 - · subst x; simp - · have hn : ¬BruhatLE cs x 1 := by - intro h - have hl := length_le_of_bruhat cs h - have hx0 : cs.length x=0 := by simpa using hl - exact hx (cs.length_eq_zero_iff.mp hx0) - rw [OrdinaryR.polynomial_zero cs _ _ hn,Hecke.rTilde_zero cs _ _ hn] - simp - · obtain ⟨i,hi⟩ := cs.exists_leftDescent_of_ne_one h1 - have hlt : cs.length (cs.simple i*y) v ^ ((cs.length x : ℤ)-cs.length b)*a) heval - have hd : (rankDifference cs x b : ℤ) = (cs.length b : ℤ)-cs.length x := by - have hlen := length_le_of_bruhat cs hxb - simp [rankDifference,Int.ofNat_sub hlen] - have hscale : v ^ ((cs.length x : ℤ)-cs.length b) * - (v^2)^(rankDifference cs x b) = - (v⁻¹) ^ ((cs.length x : ℤ)-cs.length b) := by - rw [←pow_mul,←zpow_natCast,←zpow_add₀ hv,inv_zpow,←zpow_neg] - congr 1 - push_cast - omega - rw [←mul_assoc,hscale,Finset.mul_sum] at heq - change (v⁻¹)^((cs.length x : ℤ)-cs.length b)* - eval₂ (Int.castRingHom C) ((v⁻¹)^2) (klPolynomial cs x b) = _ - rw [heq] - apply Finset.sum_congr rfl - intro z _ - rw [rPolynomial_normalization cs v hv] - unfold scaledKL - calc - _ = (v ^ ((cs.length x : ℤ)-cs.length b) * - v ^ ((cs.length z.val : ℤ)-cs.length x)) * - eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x z.val) * - eval₂ (Int.castRingHom C) (v^2) (klPolynomial cs z.val b) := by ring - _ = _ := by - rw [←zpow_add₀ hv,show (cs.length x : ℤ)-cs.length b+ - ((cs.length z.val : ℤ)-cs.length x) = - (cs.length z.val : ℤ)-cs.length b by ring] - ring - - -theorem scaledKL_reciprocity {C : Type*} [Field C] - (cs : CoxeterSystem M W) (v : C) (hv : v ≠ 0) - (x b : W) (hxb : BruhatLE cs x b) : - scaledKL cs v x b = ∑ᶠ z : Interval cs x b, - eval₂ (Int.castRingHom C) (v⁻¹-v) (Hecke.rTilde cs x z.val) * - scaledKL cs v⁻¹ z.val b := by - simpa only [inv_inv] using scaledKL_reciprocity_inverse cs v⁻¹ (inv_ne_zero hv) x b hxb - -end KLInvariance - - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.CanonicalKL + +namespace OAI + +/-! +Interval restrictions, dihedral Coxeter and Hecke calculations, and the genuine square-parameter R normalization. +-/ + +section + +namespace KLInvariance + +universe u₁ v₁ u₂ v₂ +variable {B : Type u₁} {W : Type v₁} [Group W] {M : CoxeterMatrix B} +variable {B' : Type u₂} {W' : Type v₂} [Group W'] {M' : CoxeterMatrix B'} + +/-- Restriction of the actual interval isomorphism to any subinterval. This +is the same unlabeled map, not a new isomorphism with extra structure. -/ +def intervalIso_restrict (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') + {u b : W} {u' b' : W'} (ι : Interval cs u b ≃o Interval cs' u' b') + (x y : Interval cs u b) : + Interval cs x.val y.val ≃o Interval cs' (ι x).val (ι y).val where + toFun z := + let zI : Interval cs u b := ⟨z.val, bruhat_trans cs x.property.1 z.property.1, + bruhat_trans cs z.property.2 y.property.2⟩ + ⟨(ι zI).val, ι.monotone (show x ≤ zI from z.property.1), + ι.monotone (show zI ≤ y from z.property.2)⟩ + invFun z := + let zI : Interval cs' u' b' := ⟨z.val, + bruhat_trans cs' (ι x).property.1 z.property.1, + bruhat_trans cs' z.property.2 (ι y).property.2⟩ + ⟨(ι.symm zI).val, + by + change x ≤ ι.symm zI + simpa only [OrderIso.symm_apply_apply] using + ι.symm.monotone (show ι x ≤ zI from z.property.1), + by + change ι.symm zI ≤ y + simpa only [OrderIso.symm_apply_apply] using + ι.symm.monotone (show zI ≤ ι y from z.property.2)⟩ + left_inv z := by + apply Subtype.ext + let zI : Interval cs u b := ⟨z.val, bruhat_trans cs x.property.1 z.property.1, + bruhat_trans cs z.property.2 y.property.2⟩ + change (ι.symm (ι zI)).val = zI.val + rw [ι.symm_apply_apply] + right_inv z := by + apply Subtype.ext + let zI : Interval cs' u' b' := ⟨z.val, + bruhat_trans cs' (ι x).property.1 z.property.1, + bruhat_trans cs' z.property.2 (ι y).property.2⟩ + change (ι (ι.symm zI)).val = zI.val + rw [ι.apply_symm_apply] + map_rel_iff' := by + intro z w + exact ι.map_rel_iff + +@[simp] theorem intervalIso_restrict_val (cs : CoxeterSystem M W) + (cs' : CoxeterSystem M' W') {u b : W} {u' b' : W'} + (ι : Interval cs u b ≃o Interval cs' u' b') (x y : Interval cs u b) + (z : Interval cs x.val y.val) : + (intervalIso_restrict cs cs' ι x y z).val = + (ι ⟨z.val, bruhat_trans cs x.property.1 z.property.1, + bruhat_trans cs z.property.2 y.property.2⟩).val := rfl + +end KLInvariance + +namespace KLInvariance.Dihedral + +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} + +/-- The alternating expression starting with `i`, unlike Mathlib's +`alternatingWord`, which specifies the final letter. -/ +def alt (i : Bool) : ℕ → List Bool + | 0 => [] + | n + 1 => i :: alt (!i) n + +@[simp] theorem alt_zero (i : Bool) : alt i 0 = [] := rfl +@[simp] theorem alt_succ (i : Bool) (n : ℕ) : alt i (n+1) = i :: alt (!i) n := rfl +@[simp] theorem length_alt (i : Bool) (n : ℕ) : (alt i n).length = n := by + induction n generalizing i with + | zero => rfl + | succ n ih => simp [ih] + +@[simp] theorem take_alt (i : Bool) (k n : ℕ) : (alt i n).take k = alt i (min k n) := by + induction n generalizing i k with + | zero => simp + | succ n ih => + cases k with + | zero => simp + | succ k => simp [ih] + +theorem reduced_cons_cons_ne (cs : CoxeterSystem M W) {i j : Bool} {ω : List Bool} + (h : cs.IsReduced (i :: j :: ω)) : i ≠ j := by + rintro rfl + have hlen := cs.length_wordProd_le ω + have heq := h.eq + simp only [cs.wordProd_cons, cs.simple_mul_simple_cancel_left, List.length_cons] at heq + omega + +theorem reduced_cons_eq_alt (cs : CoxeterSystem M W) (i : Bool) (ω : List Bool) + (h : cs.IsReduced (i :: ω)) : i :: ω = alt i (ω.length + 1) := by + induction ω generalizing i with + | nil => simp + | cons j ω ih => + have hj : j = !i := by + have := reduced_cons_cons_ne cs h + cases i <;> cases j <;> simp_all + have hω : cs.IsReduced (j :: ω) := by simpa using h.drop 1 + rw [show (j :: ω).length + 1 = (ω.length + 1) + 1 by rfl, alt_succ] + congr 1 + rw [ih j hω, hj] + +theorem reduced_eq_alt (cs : CoxeterSystem M W) (ω : List Bool) + (h : cs.IsReduced ω) : ∃ i, ω = alt i ω.length := by + cases ω with + | nil => exact ⟨false, rfl⟩ + | cons i ω => exact ⟨i, reduced_cons_eq_alt cs i ω h⟩ + +theorem exists_alt (cs : CoxeterSystem M W) (w : W) : + ∃ i, w = cs.wordProd (alt i (cs.length w)) := by + obtain ⟨ω, hω, hw⟩ := cs.exists_isReduced w + obtain ⟨i, hi⟩ := reduced_eq_alt cs ω hω + refine ⟨i, ?_⟩ + rw [hw, hω.eq, ← hi] + +theorem reduced_alt_take (cs : CoxeterSystem M W) {i : Bool} {k n : ℕ} + (h : cs.IsReduced (alt i n)) (hk : k ≤ n) : cs.IsReduced (alt i k) := by + simpa only [take_alt, Nat.min_eq_left hk] using h.take k + +theorem alt_sublist (i : Bool) {k n : ℕ} (h : k ≤ n) : (alt i k).Sublist (alt i n) := by + simpa only [take_alt, Nat.min_eq_left h] using List.take_sublist k (alt i n) + +end KLInvariance.Dihedral + +namespace KLInvariance.Dihedral + +noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p + +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} + +/-- In a rank-two Coxeter system, every strictly shorter element lies below +every longer element. This uses the actual Bruhat subword theorem. -/ +theorem shorter_bruhat (cs : CoxeterSystem M W) {x w : W} + (h : cs.length x < cs.length w) : BruhatLE cs x w := by + obtain ⟨i, hi⟩ := exists_alt cs w + obtain ⟨j, hj⟩ := exists_alt cs x + have hr : cs.IsReduced (alt i (cs.length w)) := by + change cs.length (cs.wordProd (alt i (cs.length w))) = (alt i (cs.length w)).length + rw [← hi, length_alt] + obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero (show cs.length w ≠ 0 by omega) + rw [hn] at hi hr h + rw [hi, hj] + apply bruhat_of_subword cs _ hr + by_cases hji : j = i + · subst j + exact alt_sublist i (by omega) + · have hj' : j = !i := by cases i <;> cases j <;> first | rfl | exact (hji rfl).elim + rw [hj', alt_succ] + exact (alt_sublist (!i) (by omega)).cons i + +theorem bruhat_iff_length_lt_or_eq (cs : CoxeterSystem M W) (x w : W) : + BruhatLE cs x w ↔ cs.length x < cs.length w ∨ x = w := by + constructor + · intro h + by_cases he : x = w + · exact Or.inr he + · exact Or.inl (length_lt_of_bruhat_ne cs h he) + · rintro (h | rfl) + · exact shorter_bruhat cs h + · exact bruhat_refl cs _ + +theorem eq_alt_of_descent (cs : CoxeterSystem M W) (i : Bool) {w : W} + (h : cs.length (cs.simple i * w) < cs.length w) : + w = cs.wordProd (alt i (cs.length w)) := by + obtain ⟨ω, hω, hw⟩ := cs.exists_isReduced (cs.simple i * w) + have hlen : cs.length w = ω.length + 1 := by + have := cs.length_simple_mul w i + rw [hw, hω.eq] at this h + omega + have hp : cs.wordProd (i :: ω) = w := by + simp only [cs.wordProd_cons, ← hw, cs.simple_mul_simple_cancel_left] + have hr : cs.IsReduced (i :: ω) := by + simpa only [CoxeterSystem.IsReduced, hp, List.length_cons] using hlen + rw [hlen, ← reduced_cons_eq_alt cs i ω hr, hp] + +end KLInvariance.Dihedral + +namespace KLInvariance.Dihedral + +noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p + +open Hecke (Space basis) +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +variable {C : Type*} [CommRing C] + +noncomputable def lowerSum (cs : CoxeterSystem M W) (w : W) : Space W C := + ∑ z ∈ lowerFinset cs w, basis z + +@[simp] theorem lowerSum_coeff (cs : CoxeterSystem M W) (w x : W) : + (lowerSum cs w : Space W C) x = if BruhatLE cs x w then 1 else 0 := by + classical + simp [lowerSum, basis, Finsupp.single_apply, eq_comm] + +@[simp] theorem lowerSum_one (cs : CoxeterSystem M W) : + (lowerSum cs 1 : Space W C) = basis 1 := by + classical + ext x + simp only [lowerSum_coeff, basis, Finsupp.single_apply] + have h : BruhatLE cs x 1 ↔ 1 = x := by + rw [bruhat_iff_length_lt_or_eq] + simp [eq_comm] + rw [h] + +/-- The two members of an s-string enter a lower ideal together precisely +on the common lower interval appearing in the source's rank-two product. -/ +theorem double_string (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) + (hr : cs.IsReduced (alt i (n+2))) (x : W) : + (BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) ∧ + BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1)))) ↔ + (0 < n ∧ BruhatLE cs x (cs.wordProd (alt i n))) := by + have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 + have hrp := reduced_alt_take cs hr (show n ≤ n+2 by omega) + have hlenw : cs.length (cs.wordProd (alt i (n+2))) = n+2 := by + simpa only [length_alt] using hr.eq + have hlenz : cs.length (cs.wordProd (alt (!i) (n+1))) = n+1 := by + simpa only [length_alt] using hr'.eq + have hlenp : cs.length (cs.wordProd (alt i n)) = n := by + simpa only [length_alt] using hrp.eq + have hsz : cs.simple i * cs.wordProd (alt (!i) (n+1)) = + cs.wordProd (alt i (n+2)) := by rw [alt_succ i (n+1), cs.wordProd_cons] + constructor + · rintro ⟨hx, hsx⟩ + have hxlen := length_le_of_bruhat cs hx + have hsxlen := length_le_of_bruhat cs hsx + have hxl : cs.length x < n+1 := by + rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hx with h | rfl + · omega + · rw [hsz, hlenw] at hsxlen + omega + have hsxl : cs.length (cs.simple i * x) < n+1 := by + rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hsx with h | h + · omega + · have heq : x = cs.wordProd (alt i (n+2)) := by + rw [← hsz, ← h, cs.simple_mul_simple_cancel_left] + rw [heq, hlenw] at hxl + omega + have hchange := cs.length_simple_mul x i + have hn : 0 < n := by omega + refine ⟨hn, ?_⟩ + by_cases hxlt : cs.length x < n + · exact shorter_bruhat cs (by omega) + · have hxi : cs.length x = n := by omega + have hdesc : cs.length (cs.simple i * x) < cs.length x := by omega + have heq := eq_alt_of_descent cs i hdesc + rw [hxi] at heq + rw [heq] + exact bruhat_refl cs _ + · rintro ⟨hn, hx⟩ + have hxlen := length_le_of_bruhat cs hx + constructor + · exact shorter_bruhat cs (by omega) + · by_cases hxlt : cs.length x < n + · have := cs.length_simple_mul x i + exact shorter_bruhat cs (by omega) + · have heq : x = cs.wordProd (alt i n) := by + rcases (bruhat_iff_length_lt_or_eq cs _ _).mp hx with h | h + · omega + · exact h + obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (show n ≠ 0 by omega) + have hrpt : cs.IsReduced (alt (!i) k) := by simpa using hrp.drop 1 + have hpk : cs.length (cs.simple i * x) = k := by + rw [heq, alt_succ, cs.wordProd_cons, cs.simple_mul_simple_cancel_left, + hrpt.eq, length_alt] + exact shorter_bruhat cs (by omega) + +end KLInvariance.Dihedral + +namespace KLInvariance.Dihedral + +noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p + +open Hecke (Space basis) +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +variable {C : Type*} [CommRing C] + +theorem left_plus_coeff (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) + (v : Space W C) (x : W) : + (v + HeckeQ.left cs (q : C) i v) x = + if cs.length (cs.simple i * x) < cs.length x then + v (cs.simple i * x) + (q : C) * v x + else v x + (q : C) * v (cs.simple i * x) := by + have h := congrArg (fun t : Space W C => (q : C) * t x) + (HeckeQ.leftInv_apply cs q i v) + simp only [Finsupp.smul_apply, smul_eq_mul, Finsupp.sub_apply, ← mul_assoc, + q.mul_inv, one_mul] at h + rw [HeckeQ.leftInv_coeff] at h + simp only [Finsupp.add_apply] + split_ifs at h ⊢ + · linear_combination -h + v (cs.simple i * x) * q.mul_inv + · linear_combination -h + v x * q.mul_inv + +theorem union_string (cs : CoxeterSystem M W) (i : Bool) {z : W} + (hz : cs.length z < cs.length (cs.simple i * z)) (x : W) : + BruhatLE cs x (cs.simple i * z) ↔ + BruhatLE cs x z ∨ BruhatLE cs (cs.simple i * x) z := by + have hsz : cs.length (cs.simple i * (cs.simple i * z)) < + cs.length (cs.simple i * z) := by simpa using hz + constructor + · intro h + have hh := lowerSimple_mono cs i h + simp only [lowerSimple, cs.simple_mul_simple_cancel_left] at hh + split_ifs at hh with hx + · exact Or.inr hh + · exact Or.inl hh + · rintro (h | h) + · apply bruhat_trans cs h + exact Relation.ReflTransGen.single ⟨hz, cs.simple i, cs.isReflection_simple i, rfl⟩ + · simpa only [cs.simple_mul_simple_cancel_left] using + Hecke.simple_mul_le_ascent cs i h hz + +noncomputable def correction (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : Space W C := + if n = 0 then 0 else lowerSum cs (cs.wordProd (alt i n)) + +@[simp] theorem correction_coeff (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) (x : W) : + (correction cs i n : Space W C) x = + if 0 < n ∧ BruhatLE cs x (cs.wordProd (alt i n)) then 1 else 0 := by + classical + by_cases h : n = 0 + · simp [correction, h] + · have hn : 0 < n := Nat.pos_of_ne_zero h + simp [correction, h, hn] + +/-- The Hecke sum identity `loc:dihedral-product`, before normalization by +q to a half-integer power. Every interval here is genuine strong Bruhat. -/ +theorem lowerSum_product (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) (n : ℕ) + (hr : cs.IsReduced (alt i (n+2))) : + lowerSum cs (cs.wordProd (alt (!i) (n+1))) + + HeckeQ.left cs (q : C) i (lowerSum cs (cs.wordProd (alt (!i) (n+1)))) = + lowerSum cs (cs.wordProd (alt i (n+2))) + (q : C) • correction cs i n := by + classical + have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 + have hz : cs.length (cs.wordProd (alt (!i) (n+1))) < + cs.length (cs.simple i * cs.wordProd (alt (!i) (n+1))) := by + rw [← cs.wordProd_cons, ← alt_succ, hr.eq, hr'.eq, length_alt, length_alt] + omega + ext x + rw [left_plus_coeff, Finsupp.add_apply, Finsupp.smul_apply, smul_eq_mul, + correction_coeff, lowerSum_coeff, lowerSum_coeff, lowerSum_coeff] + have hu := union_string cs i hz x + rw [← cs.wordProd_cons, ← alt_succ] at hu + have hd := double_string cs i n hr x + simp only [hu, ← hd] + by_cases hdesc : cs.length (cs.simple i * x) < cs.length x + · have hclosure : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) → + BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) := by + intro h + apply bruhat_trans cs _ h + exact Relation.ReflTransGen.single + ⟨hdesc, cs.simple i, cs.isReflection_simple i, by simp⟩ + by_cases hx : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) + · simp [-alt_succ, hdesc, hx, hclosure hx] + · by_cases hs : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) <;> + simp [-alt_succ, hdesc, hx, hs] + · have hasc : cs.length x < cs.length (cs.simple i * x) := by + have := cs.length_simple_mul x i + omega + have hclosure : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) → + BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) := by + intro h + apply bruhat_trans cs _ h + exact Relation.ReflTransGen.single + ⟨hasc, cs.simple i, cs.isReflection_simple i, rfl⟩ + by_cases hs : BruhatLE cs (cs.simple i * x) (cs.wordProd (alt (!i) (n+1))) + · simp [-alt_succ, hdesc, hs, hclosure hs] + · by_cases hx : BruhatLE cs x (cs.wordProd (alt (!i) (n+1))) <;> + simp [-alt_succ, hdesc, hx, hs] + +end KLInvariance.Dihedral + +namespace KLInvariance.HeckeQ + +universe uR vR +variable {B : Type uR} {W : Type vR} [Group W] {M : CoxeterMatrix B} +variable {C : Type*} [CommRing C] + +noncomputable def dualR (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : C := + (-(q : C)) ^ cs.length y * (-(↑q⁻¹ : C)) ^ cs.length x * rValue cs q⁻¹ x y + +@[simp] theorem dualR_diagonal (cs : CoxeterSystem M W) (q : Cˣ) (x : W) : + dualR cs q x x = 1 := by + rw [dualR, rValue_diagonal, mul_one, ← mul_pow] + simp + +theorem dualR_zero (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) + (h : ¬BruhatLE cs x y) : dualR cs q x y = 0 := by + simp [dualR, rValue_zero cs q⁻¹ x y h] + +theorem dualR_recursion (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) (i : B) + (hy : cs.length (cs.simple i * y) < cs.length y) : + dualR cs q x y = + if cs.length (cs.simple i * x) < cs.length x then + dualR cs q (cs.simple i * x) (cs.simple i * y) + else ((q : C) - 1) * dualR cs q x (cs.simple i * y) + + (q : C) * dualR cs q (cs.simple i * x) (cs.simple i * y) := by + have hyl : cs.length y = cs.length (cs.simple i * y) + 1 := by + have := cs.length_simple_mul y i + omega + unfold dualR + rw [rValue_recursion cs q⁻¹ x y i hy] + split_ifs with hx + · have hxl : cs.length x = cs.length (cs.simple i * x) + 1 := by + have := cs.length_simple_mul x i + omega + rw [hyl, hxl, pow_succ, pow_succ] + calc + _ = (-(q:C)) ^ cs.length (cs.simple i * y) * + (-(↑q⁻¹:C)) ^ cs.length (cs.simple i * x) * + rValue cs q⁻¹ (cs.simple i * x) (cs.simple i * y) * + ((q:C) * (↑q⁻¹:C)) := by ring + _ = _ := by rw [q.mul_inv, mul_one] + · have hxl : cs.length (cs.simple i * x) = cs.length x + 1 := by + have := cs.length_simple_mul x i + omega + rw [hyl, hxl, pow_succ, pow_succ] + have hq : (-(q:C)) * ((↑q⁻¹:C) - 1) = (q:C) - 1 := by + rw [mul_sub, neg_mul, q.mul_inv, mul_one] + ring + calc + _ = (-(q:C)) ^ cs.length (cs.simple i * y) * + (-(↑q⁻¹:C)) ^ cs.length x * + ((-(q:C)) * ((↑q⁻¹:C) - 1)) * rValue cs q⁻¹ x (cs.simple i * y) + + (q:C) * ((-(q:C)) ^ cs.length (cs.simple i * y) * + ((-(↑q⁻¹:C)) ^ cs.length x * (-(↑q⁻¹:C))) * + rValue cs q⁻¹ (cs.simple i * x) (cs.simple i * y)) := by ring + _ = _ := by rw [hq]; ring + +/-- Signed inversion symmetry of actual equal-parameter R-values, proved +from all-descent recurrence, not imposed as an additional normalization. -/ +theorem rValue_eq_dualR (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : + rValue cs q x y = dualR cs q x y := by + suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, + rValue cs q x y = dualR cs q x y by + exact this _ y rfl x + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro y hy x + by_cases hy1 : y = 1 + · subst y + by_cases hx1 : x = 1 + · subst x + simp + · have hnot : ¬BruhatLE cs x 1 := by + intro h + have hl := length_le_of_bruhat cs h + have hl0 : cs.length x = 0 := by simpa using hl + exact hx1 (cs.length_eq_zero_iff.mp hl0) + rw [rValue_zero cs q x 1 hnot, dualR_zero cs q x 1 hnot] + · obtain ⟨i, hi⟩ := cs.exists_leftDescent_of_ne_one hy1 + have hsmall : cs.length (cs.simple i * y) < n := hy ▸ hi + rw [rValue_recursion cs q x y i hi, dualR_recursion cs q x y i hi, + ih _ hsmall _ rfl x, ih _ hsmall _ rfl (cs.simple i * x)] + +/-- R at the inverse parameter is exactly the corresponding bar coefficient +with the bottom q-power. This is the coefficient form used below. -/ +theorem rValue_inverse_eq_barBasis (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) : + rValue cs q⁻¹ x y = (q:C) ^ cs.length x * barBasis cs q y x := by + rw [rValue_eq_dualR cs q⁻¹, dualR, inv_inv, rValue] + simp only [neg_pow (↑q⁻¹:C), neg_pow (q:C)] + have hsign (n : ℕ) : (-1:C)^n * (-1:C)^n = 1 := by + rw [← mul_pow]; simp + calc + _ = ((-1:C)^cs.length y * (-1:C)^cs.length y) * + ((-1:C)^cs.length x * (-1:C)^cs.length x) * + (((↑q⁻¹:C) * (q:C)) ^ cs.length y) * + (q:C)^cs.length x * barBasis cs q y x := by ring + _ = _ := by rw [hsign, hsign, q.inv_mul]; simp + +end KLInvariance.HeckeQ + +namespace KLInvariance.Dihedral + +noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p + +open Hecke (Space basis) +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +variable {C : Type*} [CommRing C] + +@[simp] theorem lowerSum_simple (cs : CoxeterSystem M W) (i : Bool) : + (lowerSum cs (cs.simple i) : Space W C) = basis 1 + basis (cs.simple i) := by + classical + ext x + rw [lowerSum_coeff, bruhat_iff_length_lt_or_eq, cs.length_simple] + simp only [Nat.lt_one_iff, cs.length_eq_zero_iff, Finsupp.add_apply, basis, + Finsupp.single_apply] + have hi : cs.simple i ≠ 1 := by + intro h + have := cs.length_simple i + simp [h] at this + by_cases hx : x = 1 + · subst x + simp [hi] + · by_cases hs : x = cs.simple i + · subst x + simp [hi, Ne.symm hi] + · simp [hx, hs, Ne.symm hx, Ne.symm hs] + +theorem plus_leftInv (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) + (v : Space W C) : + v + HeckeQ.leftInv cs q i v = + (↑q⁻¹:C) • (v + HeckeQ.left cs (q:C) i v) := by + rw [HeckeQ.leftInv_apply, smul_sub, smul_smul, mul_sub, q.inv_mul, mul_one] + module + +/-- Unnormalized form of bar invariance of the dihedral constant sums. -/ +theorem bar_lowerSum_alt (cs : CoxeterSystem M W) (q : Cˣ) (i : Bool) (n : ℕ) + (hr : cs.IsReduced (alt i n)) : + HeckeQ.barLinear cs q (lowerSum cs (cs.wordProd (alt i n))) = + (↑q⁻¹:C)^n • lowerSum cs (cs.wordProd (alt i n)) := by + induction n using Nat.strong_induction_on generalizing i with + | h n ih => + rcases n with _ | (_ | n) + · simp + · have hasc : cs.length (1:W) < cs.length (cs.simple i * 1) := by simp + have hb := HeckeQ.barBasis_simple_mul_ascent cs q i 1 hasc + simp only [mul_one, HeckeQ.barBasis_one] at hb + simp only [alt_succ, alt_zero, cs.wordProd_singleton, lowerSum_simple, + map_add, HeckeQ.barLinear_basis, HeckeQ.barBasis_one, hb] + rw [plus_leftInv, HeckeQ.left_basis] + simp + · have hr' : cs.IsReduced (alt (!i) (n+1)) := by simpa using hr.drop 1 + have hrp := reduced_alt_take cs hr (show n ≤ n+2 by omega) + have hz := ih (n+1) (by omega) (!i) hr' + have hc : HeckeQ.barLinear cs q (correction cs i n) = + (↑q⁻¹:C)^n • correction cs i n := by + by_cases hn : n = 0 + · simp [correction, hn] + · simp only [correction, ite_eq_right hn] + exact ih n (by omega) i hrp + have hprod := lowerSum_product cs q i n hr + have hbar := congrArg (HeckeQ.barLinear cs q) + (lowerSum_product cs q⁻¹ i n hr) + have hinter := congrArg (fun f : Module.End C (Space W C) => + f (lowerSum cs (cs.wordProd (alt (!i) (n+1))))) + (HeckeQ.barLinear_left cs q i) + simp only [map_add, map_smul, Module.End.mul_apply] at hbar hinter + rw [hinter, hz, map_smul, ← smul_add, plus_leftInv, hprod] at hbar + simp only [smul_add, smul_smul, hc] at hbar + have hq1 : (↑q⁻¹:C)^(n+1) * (↑q⁻¹:C) = (↑q⁻¹:C)^(n+2) := by + exact (pow_succ (↑q⁻¹:C) (n+1)).symm + have hq2 : (↑q⁻¹:C)^(n+1) * ((↑q⁻¹:C) * (q:C)) = + (↑q⁻¹:C) * (↑q⁻¹:C)^n := by rw [q.inv_mul, mul_one, pow_succ']; + rw [hq1, hq2] at hbar + exact add_right_cancel hbar.symm + +theorem bar_lowerSum (cs : CoxeterSystem M W) (q : Cˣ) (w : W) : + HeckeQ.barLinear cs q (lowerSum cs w) = + (↑q⁻¹:C)^cs.length w • lowerSum cs w := by + obtain ⟨i, hi⟩ := exists_alt cs w + have hr : cs.IsReduced (alt i (cs.length w)) := by + simp only [CoxeterSystem.IsReduced, ← hi, length_alt] + simpa only [← hi] using bar_lowerSum_alt cs q i (cs.length w) hr + +end KLInvariance.Dihedral + +namespace KLInvariance.Dihedral + +noncomputable local instance (p : Prop) : Decidable p := Classical.propDecidable p + +open Hecke (Space basis) +open Polynomial +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +variable {C : Type*} [CommRing C] + +theorem rValue_sum (cs : CoxeterSystem M W) (q : Cˣ) (x y : W) + (hxy : BruhatLE cs x y) : + ∑ z ∈ lowerFinset cs y, HeckeQ.rValue cs q x z = + (q:C) ^ rankDifference cs x y := by + classical + have hb := congrArg (fun f : Space W C => f x) (bar_lowerSum cs q⁻¹ y) + simp only [Finsupp.smul_apply, smul_eq_mul, inv_inv, lowerSum_coeff, + ite_eq_left hxy, mul_one] at hb + rw [lowerSum, map_sum] at hb + simp only [Finsupp.coe_finsetSum, Finset.sum_apply, HeckeQ.barLinear_basis] at hb + have hlen : cs.length y = cs.length x + rankDifference cs x y := by + have := length_le_of_bruhat cs hxy + unfold rankDifference + omega + calc + _ = (↑q⁻¹:C)^cs.length x * + ∑ z ∈ lowerFinset cs y, HeckeQ.barBasis cs q⁻¹ z x := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro z hz + simpa using HeckeQ.rValue_inverse_eq_barBasis cs q⁻¹ x z + _ = (↑q⁻¹:C)^cs.length x * (q:C)^cs.length y := by rw [hb] + _ = _ := by + rw [hlen, pow_add] + calc + _ = ((↑q⁻¹:C) * (q:C))^cs.length x * (q:C)^rankDifference cs x y := by + rw [mul_pow]; ring + _ = _ := by rw [q.inv_mul]; simp + +theorem rPolynomial_sum (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) : + ∑ z ∈ lowerFinset cs y, OrdinaryR.polynomial cs x z = + (X:ℤ[X]) ^ rankDifference cs x y := by + apply Polynomial.toLaurent_injective + simpa using rValue_sum cs OrdinaryR.variableUnit x y hxy + +noncomputable def constantP (cs : CoxeterSystem M W) (x y : W) : ℤ[X] := + if BruhatLE cs x y then 1 else 0 + +theorem constant_normalizedKL (cs : CoxeterSystem M W) : + NormalizedKL cs (OrdinaryR.polynomial cs, constantP cs) where + R_diagonal := OrdinaryR.polynomial_diagonal cs + R_zero := OrdinaryR.polynomial_zero cs + R_recursion := OrdinaryR.polynomial_recursion cs + P_diagonal := by intro x; simp [constantP, bruhat_refl cs x] + P_zero := by intro x y h; simp [constantP, h] + P_degree := by + intro x y hxy hne + have := length_lt_of_bruhat_ne cs hxy hne + simp only [constantP, ite_eq_left hxy, natDegree_one, mul_zero] + unfold rankDifference + omega + reciprocity := by + intro x y hxy + simp only [constantP, ite_eq_left hxy, reflect_one] + classical + let := interval_finite cs x y + let : Fintype (Interval cs x y) := Fintype.ofFinite _ + rw [finsum_eq_sum_of_fintype] + have heq : (∑ z : Interval cs x y, + OrdinaryR.polynomial cs x z.val * (if BruhatLE cs z.val y then 1 else 0)) = + ∑ z : Interval cs x y, OrdinaryR.polynomial cs x z.val := by + apply Finset.sum_congr rfl + intro z hz + rw [ite_eq_left z.property.2, mul_one] + rw [heq] + have hsum := Finset.sum_subtype (F := (inferInstance : Fintype (Interval cs x y))) + ((lowerFinset cs y).filter (fun z => BruhatLE cs x z)) + (fun z => by simp only [Finset.mem_filter, mem_lowerFinset]; exact and_comm) + (fun z => OrdinaryR.polynomial cs x z) + symm + refine hsum.symm.trans (Eq.trans ?_ (rPolynomial_sum cs x y hxy)) + apply Finset.sum_subset (Finset.filter_subset _ _) + intro z hz hnot + have hnxz : ¬BruhatLE cs x z := fun hxz => hnot (Finset.mem_filter.mpr ⟨hz, hxz⟩) + exact OrdinaryR.polynomial_zero cs x z hnxz + +/-- The manuscript's necessary dihedral calculation (`loc:dihedral-kl`), +for the actual KL family, with the exact standard normalization. This is +support for localization, not a substitute for general invariance. -/ +theorem klPolynomial_eq_one (cs : CoxeterSystem M W) (x y : W) + (hxy : BruhatLE cs x y) : klPolynomial cs x y = 1 := by + have heq := normalizedKL_unique cs (klFamilies_spec cs) (constant_normalizedKL cs) + have hp := congrArg (fun RP : PolynomialFamilies W => RP.2 x y) heq + simpa only [klPolynomial, constantP, ite_eq_left hxy] using hp + +end KLInvariance.Dihedral + +end + +section + +namespace KLInvariance +open Polynomial +universe u v +variable {B : Type u} {W : Type v} [Group W] {M : CoxeterMatrix B} + +/-- The exact square-parameter normalization, proved from the two genuine +Hecke recurrences. Integer exponents let the formula include incomparable +pairs without silently changing the R-polynomial definition. -/ +theorem rPolynomial_normalization {C : Type*} [Field C] + (cs : CoxeterSystem M W) (v : C) (hv : v ≠ 0) (x y : W) : + eval₂ (Int.castRingHom C) (v^2) (rPolynomial cs x y) = + v ^ ((cs.length y : ℤ) - cs.length x) * + eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x y) := by + rw [rPolynomial_eq_constructed] + suffices ∀ n : ℕ, ∀ y : W, cs.length y = n → ∀ x, + eval₂ (Int.castRingHom C) (v^2) (OrdinaryR.polynomial cs x y) = + v ^ ((cs.length y : ℤ) - cs.length x) * + eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x y) from + this _ y rfl x + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro y hy x + by_cases h1 : y=1 + · subst y + by_cases hx : x=1 + · subst x; simp + · have hn : ¬BruhatLE cs x 1 := by + intro h + have hl := length_le_of_bruhat cs h + have hx0 : cs.length x=0 := by simpa using hl + exact hx (cs.length_eq_zero_iff.mp hx0) + rw [OrdinaryR.polynomial_zero cs _ _ hn,Hecke.rTilde_zero cs _ _ hn] + simp + · obtain ⟨i,hi⟩ := cs.exists_leftDescent_of_ne_one h1 + have hlt : cs.length (cs.simple i*y) v ^ ((cs.length x : ℤ)-cs.length b)*a) heval + have hd : (rankDifference cs x b : ℤ) = (cs.length b : ℤ)-cs.length x := by + have hlen := length_le_of_bruhat cs hxb + simp [rankDifference,Int.ofNat_sub hlen] + have hscale : v ^ ((cs.length x : ℤ)-cs.length b) * + (v^2)^(rankDifference cs x b) = + (v⁻¹) ^ ((cs.length x : ℤ)-cs.length b) := by + rw [←pow_mul,←zpow_natCast,←zpow_add₀ hv,inv_zpow,←zpow_neg] + congr 1 + push_cast + omega + rw [←mul_assoc,hscale,Finset.mul_sum] at heq + change (v⁻¹)^((cs.length x : ℤ)-cs.length b)* + eval₂ (Int.castRingHom C) ((v⁻¹)^2) (klPolynomial cs x b) = _ + rw [heq] + apply Finset.sum_congr rfl + intro z _ + rw [rPolynomial_normalization cs v hv] + unfold scaledKL + calc + _ = (v ^ ((cs.length x : ℤ)-cs.length b) * + v ^ ((cs.length z.val : ℤ)-cs.length x)) * + eval₂ (Int.castRingHom C) (v-v⁻¹) (Hecke.rTilde cs x z.val) * + eval₂ (Int.castRingHom C) (v^2) (klPolynomial cs z.val b) := by ring + _ = _ := by + rw [←zpow_add₀ hv,show (cs.length x : ℤ)-cs.length b+ + ((cs.length z.val : ℤ)-cs.length x) = + (cs.length z.val : ℤ)-cs.length b by ring] + ring + + +theorem scaledKL_reciprocity {C : Type*} [Field C] + (cs : CoxeterSystem M W) (v : C) (hv : v ≠ 0) + (x b : W) (hxb : BruhatLE cs x b) : + scaledKL cs v x b = ∑ᶠ z : Interval cs x b, + eval₂ (Int.castRingHom C) (v⁻¹-v) (Hecke.rTilde cs x z.val) * + scaledKL cs v⁻¹ z.val b := by + simpa only [inv_inv] using scaledKL_reciprocity_inverse cs v⁻¹ (inv_ne_zero hv) x b hxb + +end KLInvariance + + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/DihedralIntervals.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/DihedralIntervals.lean index 984958965b1c839031895ea0ab61a20073538658..baf37f5c606cc7deca0c51dc63d70aff81d31748 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/DihedralIntervals.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/DihedralIntervals.lean @@ -1,2274 +1,2274 @@ -import OAI.RepresentationTheory.KazhdanLusztig.ReflectionOrders - -namespace OAI - -/-! -Signed dihedral coordinates, actual dihedral intervals, exact later-edge counts and root-plane calculations. --/ - -section - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section - - theorem wordProd_alt_odd (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : - cs.wordProd (alt i (2*n+1)) = (cs.simple i * cs.simple (!i)) ^ n * cs.simple i := by - induction n with - | zero => simp - | succ n ih => - rw [show 2*(n+1)+1 = (2*n+1)+2 by omega, alt_add_two] - simp only [cs.wordProd_cons, ih, pow_succ'] - group - - def rotation (cs : CoxeterSystem M W) : W := cs.simple false * cs.simple true - - theorem simple_rotation (cs : CoxeterSystem M W) : - cs.simple false * rotation cs = (rotation cs)⁻¹ * cs.simple false := by - simp only [rotation, mul_inv_rev, cs.inv_simple] - rw [cs.simple_mul_simple_cancel_left, mul_assoc, cs.simple_mul_simple_self, mul_one] - - theorem simple_rotation_zpow (cs : CoxeterSystem M W) (n : ℤ) : - cs.simple false * rotation cs ^ n = rotation cs ^ (-n) * cs.simple false := by - have h : SemiconjBy (cs.simple false) (rotation cs) (rotation cs)⁻¹ := - simple_rotation cs - have hh := h.zpow_right n - change cs.simple false * rotation cs ^ n = ((rotation cs)⁻¹) ^ n * cs.simple false at hh - simpa only [inv_zpow, zpow_neg] using hh - -/-- The signed coordinate evaluates both alternating rays in the same group. -The Euclidean quotient also gives the correct odd negative coordinates. -/ - def indexWord (cs : CoxeterSystem M W) (i : ℤ) : W := - if i % 2 = 0 then rotation cs ^ (i/2) - else rotation cs ^ (i/2) * cs.simple false - - theorem indexWord_even (cs : CoxeterSystem M W) (n : ℤ) : - indexWord cs (2*n) = rotation cs ^ n := by simp [indexWord] - - theorem indexWord_odd (cs : CoxeterSystem M W) (n : ℤ) : - indexWord cs (2*n+1) = rotation cs ^ n * cs.simple false := by - simp only [indexWord, show (2*n+1)%2 = 1 by omega, show (1:ℤ) ≠ 0 by omega, ite_false, - show (2*n+1)/2 = n by omega] - - theorem indexWord_nat (cs : CoxeterSystem M W) (n : ℕ) : - indexWord cs n = cs.wordProd (alt false n) := by - rcases Nat.even_or_odd n with ⟨k,rfl⟩ | ⟨k,rfl⟩ - · rw [show k+k = 2*k by omega, Nat.cast_mul, Nat.cast_ofNat, indexWord_even, - wordProd_alt_even] - simp only [rotation, Bool.not_false, zpow_natCast] - · rw [Nat.cast_add, Nat.cast_mul, - Nat.cast_ofNat, Nat.cast_one, indexWord_odd, wordProd_alt_odd] - simp only [rotation, Bool.not_false, zpow_natCast] - - theorem indexWord_neg_nat (cs : CoxeterSystem M W) (n : ℕ) : - indexWord cs (-(n:ℤ)) = cs.wordProd (alt true n) := by - have hr : cs.simple true * cs.simple false = (rotation cs)⁻¹ := by - simp only [rotation, mul_inv_rev, cs.inv_simple] - rcases Nat.even_or_odd n with ⟨k,rfl⟩ | ⟨k,rfl⟩ - · rw [show k+k = 2*k by omega, Nat.cast_mul, Nat.cast_ofNat, - show -(2*(k:ℤ)) = 2*(-k) by ring, indexWord_even, wordProd_alt_even] - simp only [Bool.not_true, hr, zpow_neg, zpow_natCast, inv_pow] - · rw [Nat.cast_add, Nat.cast_mul, - Nat.cast_ofNat, Nat.cast_one, - show -(2*(k:ℤ)+1) = 2*(-(k:ℤ)-1)+1 by ring, indexWord_odd, - wordProd_alt_odd] - rw [show -(k:ℤ)-1 = -(k:ℤ)+(-1) by ring, zpow_add] - simp only [zpow_neg, zpow_natCast, zpow_one, Bool.not_true, hr, inv_pow] - simp only [rotation, mul_inv_rev, cs.inv_simple] - simp only [mul_assoc, cs.simple_mul_simple_self, mul_one] - - theorem exists_indexWord (cs : CoxeterSystem M W) (w : W) : - ∃ i : ℤ, |i| = (cs.length w : ℤ) ∧ indexWord cs i = w := by - obtain ⟨i,hi⟩ := exists_alt cs w - cases i - · exact ⟨cs.length w, by simp, (indexWord_nat cs _).trans hi.symm⟩ - · exact ⟨-(cs.length w : ℤ), by simp, (indexWord_neg_nat cs _).trans hi.symm⟩ - -/-- A reflection acts on the signed index line by reflection in its midpoint. -Finite dihedral groups are handled by equality in the group, without choosing -residue representatives here. -/ - theorem indexWord_reflection_mul (cs : CoxeterSystem M W) {a : ℤ} (ha : Odd a) - (i : ℤ) : indexWord cs a * indexWord cs i = indexWord cs (a-i) := by - obtain ⟨k,hk⟩ := ha - have hk' : a = 2*k+1 := by omega - rw [hk',indexWord_odd] - rcases Int.even_or_odd i with ⟨l,hl⟩ | ⟨l,hl⟩ - · have hl' : i=2*l := by omega - rw [hl',indexWord_even,show 2*k+1-2*l=2*(k-l)+1 by ring,indexWord_odd] - rw [mul_assoc, simple_rotation_zpow, ← mul_assoc, ← zpow_add] - congr 2 - · have hl' : i=2*l+1 := by omega - rw [hl',indexWord_odd,show 2*k+1-(2*l+1)=2*(k-l) by ring,indexWord_even] - calc - (rotation cs ^ k * cs.simple false) * (rotation cs ^ l * cs.simple false) = - rotation cs ^ k * (cs.simple false * rotation cs ^ l) * cs.simple false := by group - _ = rotation cs ^ k * (rotation cs ^ (-l) * cs.simple false) * cs.simple false := by - rw [simple_rotation_zpow] - _ = rotation cs ^ (k-l) := by - rw [← mul_assoc, mul_assoc (rotation cs ^ k * rotation cs ^ (-l)), - cs.simple_mul_simple_self, mul_one, ← zpow_add] - congr 1 - - theorem indexWord_label (cs : CoxeterSystem M W) {i j : ℤ} (h : Odd (i+j)) : - indexWord cs j * (indexWord cs i)⁻¹ = indexWord cs (i+j) := by - have he := indexWord_reflection_mul cs h i - rw [show i+j-i=j by omega] at he - rw [← he] - group - -end -end KLInvariance.Dihedral - -end - - -section - -/-! Actual degree-one splines in the ambient extended Tits realization. -They supply the interpolation factors needed for the relative rank-two model. -/ -namespace KLInvariance.TitsSpace -open Module -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] (cs : CoxeterSystem M W) - {σ : Type us} (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def linearPolynomial : Extended M →ₗ[ℝ] MvPolynomial σ ℝ := - (SymmetricAlgebra.equivMvPolynomial basis).toLinearMap.comp - (SymmetricAlgebra.ι ℝ (Extended M)) - - def orbitSpline (y : W) (v₀ : Extended M) (v : W) : MvPolynomial σ ℝ := - linearPolynomial basis (extendedAction M cs (v*y⁻¹) v₀ - v₀) - - theorem orbitSpline_self (y : W) (v₀ : Extended M) : orbitSpline cs basis y v₀ y = 0 := by - simp [orbitSpline] - - theorem orbitSpline_reflection {t : W} {a : I → ℝ} - (ha : Represents M cs t a) (y x : W) (v₀ : Extended M) : - linearPolynomial basis (embed M a) ∣ - orbitSpline cs basis y v₀ x - orbitSpline cs basis y v₀ (t*x) := by - let c := extendedForm M (embed M a) (extendedAction M cs (x*y⁻¹) v₀) - have heq : extendedAction M cs (t*x*y⁻¹) v₀ = - extendedAction M cs (x*y⁻¹) v₀ - c • embed M a := by - rw [mul_assoc,map_mul,LinearEquiv.mul_apply,ha.formula] - unfold orbitSpline - rw [← map_sub,heq] - have hv : (extendedAction M cs (x*y⁻¹) v₀ - v₀) - - (extendedAction M cs (x*y⁻¹) v₀ - c • embed M a - v₀) = c • embed M a := by abel - rw [hv,map_smul] - exact ⟨algebraMap ℝ (MvPolynomial σ ℝ) c, by simp [Algebra.smul_def,mul_comm]⟩ - - theorem exists_pair_vector {t r : W} {a d : I → ℝ} - (ha : Represents M cs t a) (hd : Represents M cs r d) (htr : t ≠ r) : - ∃ v₀ : Extended M, extendedForm M (embed M a) v₀ = -1 ∧ - extendedForm M (embed M d) v₀ = 0 := by - have hli := (ha.extended_independent_of_ne hd htr).map' - (extendedForm M) (extendedForm_spec M).2.1.ker_eq_bot - have hli' : LinearIndependent ℝ ![extendedForm M (embed M a), - extendedForm M (embed M d)] := by - convert hli using 1 - funext i - fin_cases i <;> rfl - obtain ⟨v₀,hv₀⟩ := ReflectionPlane.formPair_surjective _ _ hli' (-1,0) - exact ⟨v₀,congrArg Prod.fst hv₀,congrArg Prod.snd hv₀⟩ - - theorem orbitSpline_pair_factor {x y z t r : W} {a d : I → ℝ} - (ha : Represents M cs t a) (hd : Represents M cs r d) - (hxy : x*y⁻¹=t) (hzy : z*y⁻¹=r) (hxz : x ≠ z) : - ∃ v₀ : Extended M, - orbitSpline cs basis y v₀ x = linearPolynomial basis (embed M a) ∧ - orbitSpline cs basis y v₀ y = 0 ∧ orbitSpline cs basis y v₀ z = 0 := by - have htr : t ≠ r := by - intro he - apply hxz - exact mul_right_cancel (hxy.trans (he.trans hzy.symm)) - obtain ⟨v₀,hv₀a,hv₀d⟩ := exists_pair_vector cs ha hd htr - refine ⟨v₀,?_,orbitSpline_self cs basis y v₀,?_⟩ - · simp only [orbitSpline,hxy,ha.formula,hv₀a] - congr 1 - module - · simp only [orbitSpline,hzy,hd.formula,hv₀d,zero_smul,sub_zero,sub_self,map_zero] - - theorem orbitSpline_single_factor {x y t : W} {a : I → ℝ} - (ha : Represents M cs t a) (hxy : x*y⁻¹=t) : - ∃ v₀ : Extended M, - orbitSpline cs basis y v₀ x = linearPolynomial basis (embed M a) ∧ - orbitSpline cs basis y v₀ y = 0 := by - let v₀ : Extended M := (-1/2 : ℝ) • embed M a - have hv₀ : extendedForm M (embed M a) v₀ = -1 := by - simp only [v₀,map_smul,smul_eq_mul,embed,(extendedForm_spec M).2.2,ha.isRoot.norm] - norm_num - refine ⟨v₀,?_,orbitSpline_self cs basis y v₀⟩ - simp only [orbitSpline,hxy,ha.formula,hv₀] - congr 1 - module - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Polynomial interpolation on an actual dihedral reflection subgroup. -The ambient realization, including all fixed directions and degenerate root -planes, is retained; no character theorem is assumed. -/ -namespace KLInvariance.Dihedral -open Module TitsSpace -universe u v w us -variable {H : Type w} [Group H] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N H) - {I : Type u} [Fintype I] {M : CoxeterMatrix I} {W : Type v} [Group W] - (cs : CoxeterSystem M W) (φ : H →* W) - (hφ : ∀ t, ds.IsReflection t → cs.IsReflection (φ t)) - {σ : Type us} (basis : Basis σ ℝ (Extended M)) -noncomputable section - - theorem reflection_of_parity {x y : H} (hp : ds.length x % 2 ≠ ds.length y % 2) : - ds.IsReflection (x*y⁻¹) := by - rw [reflection_iff_odd,Nat.odd_iff] - have h := ds.length_mul_mod_two x y⁻¹ - rw [ds.length_inv] at h - omega - - def oppositeExternal (x c : H) : Finset H := by - classical - exact (externalLower ds x c).filter (fun z => ds.length z % 2 ≠ ds.length x % 2) - - def sameExternal (x c : H) : Finset H := by - classical - exact (externalLower ds x c).filter (fun z => ds.length z % 2 = ds.length x % 2) - - theorem oppositeExternal_reflection {x c y : H} (hy : y ∈ oppositeExternal ds x c) : - ds.IsReflection (y*x⁻¹) := by - classical - exact reflection_of_parity ds (Finset.mem_filter.mp hy).2 - - def interpolationRoot (x c : H) (y : oppositeExternal ds x c) : PositiveRoot M cs := - positiveRoot M cs ⟨φ (y.val*x⁻¹), hφ _ (oppositeExternal_reflection ds y.property)⟩ - - theorem interpolation_exists (hφinj : Function.Injective φ) {x c : H} - (hxc : BruhatLE ds x c) : ∃ F : H → MvPolynomial σ ℝ, - (∀ t, ds.IsReflection t → ∀ (a : I → ℝ), Represents M cs (φ t) a → ∀ v, - linearPolynomial basis (embed M a) ∣ F v-F (t*v)) ∧ - F x = ∏ y : oppositeExternal ds x c, - linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x c y).val) ∧ - ∀ z, BruhatLE ds z c → ¬ BruhatLE ds z x → F z = 0 := by - classical - let Y := {y // y ∈ oppositeExternal ds x c} - let Z := {z // z ∈ sameExternal ds x c} - have hc : Fintype.card Z ≤ Fintype.card Y := by - change Fintype.card ↥(sameExternal ds x c) ≤ Fintype.card ↥(oppositeExternal ds x c) - rw [Fintype.card_coe,Fintype.card_coe] - exact external_parity_card_le ds hxc - obtain ⟨j⟩ := Function.Embedding.nonempty_of_card_le hc - have hfac (y : Y) : ∃ v₀ : Extended M, - orbitSpline cs basis (φ y.val) v₀ (φ x) = - linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x c y).val) ∧ - orbitSpline cs basis (φ y.val) v₀ (φ y.val) = 0 ∧ - ∀ z : Z, j z = y → orbitSpline cs basis (φ y.val) v₀ (φ z.val) = 0 := by - have ht := oppositeExternal_reflection ds y.property - have ha := positiveRoot_represents M cs - ⟨φ (y.val*x⁻¹),hφ _ ht⟩ - have hxy₀ : x*y.val⁻¹=y.val*x⁻¹ := by simpa only [mul_inv_rev,inv_inv] using ht.inv - have hxy : φ x*(φ y.val)⁻¹=φ (y.val*x⁻¹) := by - rw [← map_inv,← map_mul,hxy₀] - by_cases hex : ∃ z : Z, j z = y - · obtain ⟨z,hz⟩ := hex - have hzprop := Finset.mem_filter.mp z.property - have hyprop := Finset.mem_filter.mp y.property - have hr : ds.IsReflection (z.val*y.val⁻¹) := reflection_of_parity ds (by omega) - let d := positiveRoot M cs ⟨φ (z.val*y.val⁻¹),hφ _ hr⟩ - have hd : Represents M cs (φ (z.val*y.val⁻¹)) d.val := positiveRoot_represents M cs ⟨φ (z.val*y.val⁻¹),hφ _ hr⟩ - have hxz : φ x ≠ φ z.val := by - intro he - have he' := hφinj he - have hh := (mem_externalLower ds x c z.val).mp hzprop.1 - exact hh.2 (he' ▸ bruhat_refl ds x) - obtain ⟨v₀,ha',hy',hz0'⟩ := orbitSpline_pair_factor cs basis ha hd hxy - (by rw [map_mul,map_inv]) hxz - refine ⟨v₀,ha',hy',?_⟩ - intro z' hz' - have he := j.injective (hz'.trans hz.symm) - simpa only [he] using hz0' - · obtain ⟨v₀,ha',hy'⟩ := orbitSpline_single_factor cs basis ha hxy - exact ⟨v₀,ha',hy',fun z hz => (hex ⟨z,hz⟩).elim⟩ - choose v₀ hv₀ hy₀ hz₀ using hfac - let F : H → MvPolynomial σ ℝ := fun v => ∏ y : Y, - orbitSpline cs basis (φ y.val) (v₀ y) (φ v) - refine ⟨F,?_,?_,?_⟩ - · intro t _ht a ha v - apply Ideal.mem_span_singleton.mp - apply Ideal.Quotient.eq.mp - change Ideal.Quotient.mk _ (∏ y : Y, orbitSpline cs basis (φ y.val) (v₀ y) (φ v)) = - Ideal.Quotient.mk _ (∏ y : Y, orbitSpline cs basis (φ y.val) (v₀ y) (φ (t*v))) - simp only [map_prod] - apply Finset.prod_congr rfl - intro y _ - apply Ideal.Quotient.eq.mpr - apply Ideal.mem_span_singleton.mpr - rw [map_mul] - exact orbitSpline_reflection cs basis ha _ _ _ - · exact Finset.prod_congr rfl (fun y _ => hv₀ y) - · intro z hzc hzx - have hz : z ∈ externalLower ds x c := (mem_externalLower ds x c z).mpr ⟨hzc,hzx⟩ - by_cases hp : ds.length z % 2 = ds.length x % 2 - · let z' : Z := ⟨z,Finset.mem_filter.mpr ⟨hz,hp⟩⟩ - exact Finset.prod_eq_zero (Finset.mem_univ (j z')) (hz₀ (j z') z' rfl) - · let y : Y := ⟨z,Finset.mem_filter.mpr ⟨hz,hp⟩⟩ - exact Finset.prod_eq_zero (Finset.mem_univ y) (hy₀ y) - -end -end KLInvariance.Dihedral - -end - - -section - -/-! An elementary flabbiness criterion for the exact rank-one model. Flow-down -sections with the genuine product of outgoing labels suffice. The pairwise -relative-primality condition will be instantiated by actual root labels. -/ -namespace KLInvariance.MomentGraph.Sheaf -universe ur uv ue -variable {R : Type ur} [CommRing R] [DecompositionMonoid R] - {V : Type uv} [PartialOrder V] {E : Type ue} - (G : OrderedGraph V E) (α : E → R) (c : V) -noncomputable section -variable [Fintype E] [DecidableEq V] - -def modelOutgoing (x : V) : Finset E := by - classical - exact Finset.univ.filter (fun e => G.source e = x ∧ G.target e ≤ c) - -@[simp] theorem mem_modelOutgoing (x : V) (e : E) : - e ∈ modelOutgoing G c x ↔ G.source e = x ∧ G.target e ≤ c := by - classical - simp [modelOutgoing] - -def modelProduct (x : V) : R := ∏ e ∈ modelOutgoing G c x, α e - -def HasFlowDown : Prop := - ∀ x, x ≤ c → ∃ f : (structureSheaf G α c).Assignment, - (structureSheaf G α c).IsGlobal f ∧ - (∀ h : PLift (x ≤ c), f x h = modelProduct G α c x) ∧ - (∀ y, ¬ y ≤ x → f y = 0) - -omit [DecompositionMonoid R] [Fintype E] [DecidableEq V] in - theorem structureCompatible_iff (Ω : Set V) (f : (structureSheaf G α c).Assignment) : - (structureSheaf G α c).CompatibleOn Ω f ↔ - ∀ e, G.source e ∈ Ω → G.target e ∈ Ω → ∀ h : PLift (G.target e ≤ c), - α e ∣ f (G.source e) ⟨(G.increasing e).le.trans h.down⟩ - f (G.target e) h := by - constructor - · intro hf e hs ht h - exact Ideal.mem_span_singleton.mp - (Ideal.Quotient.eq.mp (congrFun (hf e hs ht) h)) - · intro hf e hs ht - funext h - exact Ideal.Quotient.eq.mpr (Ideal.mem_span_singleton.mpr (hf e hs ht h)) - -include G α c in - theorem flowDown_flabby [Finite V] - (hrel : ∀ x, (modelOutgoing G c x : Set E).Pairwise (Function.onFun IsRelPrime α)) - (hflow : HasFlowDown G α c) : (structureSheaf G α c).Flabby := by - classical - let B := structureSheaf G α c - let : Fintype V := Fintype.ofFinite V - suffices hh : ∀ s : Finset V, IsUpperSet (s : Set V) → - ∀ f : B.Assignment, B.CompatibleOn (s : Set V) f → - ∃ g : B.Assignment, B.IsGlobal g ∧ ∀ x ∈ s, g x = f x by - intro Ω hΩ f hf - have hset : (↑(Finset.univ.filter (· ∈ Ω)) : Set V) = Ω := by ext x; simp - obtain ⟨g,hg,hgf⟩ := hh (Finset.univ.filter (· ∈ Ω)) (by rwa [hset]) f (by rwa [hset]) - exact ⟨g,hg,fun x hx => hgf x (by simpa using hx)⟩ - intro s - refine Finset.strongInductionOn s ?_ - intro s ih hs f hf - by_cases hempty : s = ∅ - · subst s - refine ⟨0,?_,by simp⟩ - exact (B.sections Set.univ).zero_mem - obtain ⟨a,ha,hmin⟩ := s.exists_minimal (Finset.nonempty_iff_ne_empty.mpr hempty) - have hu : IsUpperSet (↑(s.erase a) : Set V) := by - intro x y hxy hx - have hx' := Finset.mem_erase.mp hx - refine Finset.mem_erase.mpr ⟨?_,hs hxy hx'.2⟩ - intro hya - subst y - exact hx'.1 (le_antisymm hxy (hmin hx'.2 hxy)) - obtain ⟨g,hg,hgf⟩ := ih (s.erase a) (Finset.erase_ssubset ha) hu f - (fun e he ht => hf e (Finset.mem_of_mem_erase he) (Finset.mem_of_mem_erase ht)) - by_cases hac : a ≤ c - · obtain ⟨t,ht,hta,htzero⟩ := hflow a hac - have hdiv : modelProduct G α c a ∣ f a ⟨hac⟩ - g a ⟨hac⟩ := by - apply Finset.prod_dvd_of_isRelPrime (hrel a) - intro e he - obtain ⟨hea,hec⟩ := (mem_modelOutgoing G c a e).mp he - have hsource : G.source e ∈ s := hea ▸ ha - have htarget : G.target e ∈ s.erase a := Finset.mem_erase.mpr - ⟨by simpa [← hea] using (G.increasing e).ne',hs (G.increasing e).le hsource⟩ - have hf' := (structureCompatible_iff G α c (s : Set V) f).mp hf e hsource - (Finset.mem_of_mem_erase htarget) ⟨hec⟩ - have hg' := (structureCompatible_iff G α c Set.univ g).mp hg e - (Set.mem_univ _) (Set.mem_univ _) ⟨hec⟩ - rw [hgf _ htarget] at hg' - have hd := dvd_sub hf' hg' - rw [sub_sub_sub_cancel_right] at hd - subst a - exact hd - obtain ⟨r,hr⟩ := hdiv - refine ⟨g+r • t,(B.sections Set.univ).add_mem hg - ((B.sections Set.univ).smul_mem r ht),?_⟩ - intro x hx - by_cases hxa : x = a - · subst x - funext h - change g a h + r * t a h = f a h - rw [hta h] - change f a h - g a h = modelProduct G α c a * r at hr - linear_combination -hr - · have hnot : ¬ x ≤ a := fun h => hxa (le_antisymm h (hmin hx h)) - have ht0 := htzero x hnot - change g x + r • t x = f x - rw [ht0,smul_zero,add_zero] - exact hgf x (Finset.mem_erase.mpr ⟨hxa,hx⟩) - · refine ⟨g,hg,?_⟩ - intro x hx - by_cases hxa : x = a - · subst x - let := structureSheaf_support G α c a hac - exact Subsingleton.elim _ _ - · exact hgf x (Finset.mem_erase.mpr ⟨hxa,hx⟩) - -end -end KLInvariance.MomentGraph.Sheaf - -end - - -section - -/-! Flabbiness of the exact rank-one model with ambient labels, proved by -interpolation rather than an assumed character theorem. -/ -namespace KLInvariance.Dihedral -open Module TitsSpace BruhatGraph MomentGraph MomentGraph.Sheaf -universe u v w us -variable {H : Type w} [Group H] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N H) - {I : Type u} [Fintype I] {M : CoxeterMatrix I} {W : Type v} [Group W] - (cs : CoxeterSystem M W) (φ : H →* W) - (hφ : ∀ t, ds.IsReflection t → cs.IsReflection (φ t)) - {σ : Type us} (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def inducedRoot (b : H) (e : Edge ds 1 b) : PositiveRoot M cs := - positiveRoot M cs ⟨φ (label ds 1 b e),hφ _ (label_isReflection ds 1 b e)⟩ - - def inducedLabel (b : H) (e : Edge ds 1 b) : MvPolynomial σ ℝ := - linearPolynomial basis (embed M (inducedRoot ds cs φ hφ b e).val) - - theorem external_step {x c y : H} (hy : y ∈ oppositeExternal ds x c) : - BruhatStep ds x y := by - classical - obtain ⟨hm,hp⟩ := Finset.mem_filter.mp hy - obtain ⟨_,hn⟩ := (mem_externalLower ds x c y).mp hm - have hl : ds.length x < ds.length y := by - have hh : ¬ ds.length y < ds.length x := fun h => hn (shorter_bruhat ds h) - omega - exact ⟨hl,y*x⁻¹,oppositeExternal_reflection ds hy,by group⟩ - - theorem step_external {x c y : H} (hy : BruhatStep ds x y) (hyc : BruhatLE ds y c) : - y ∈ oppositeExternal ds x c := by - classical - refine Finset.mem_filter.mpr ⟨(mem_externalLower ds x c y).mpr ⟨hyc,?_⟩,?_⟩ - · exact fun h => (length_le_of_bruhat ds h).not_gt hy.1 - · have hh := (step_iff_odd ds x y).mp hy - rw [Nat.odd_iff] at hh - omega - - variable (b : H) [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] - - def externalEdge (x c : Interval ds 1 b) (y : oppositeExternal ds x.val c.val) : Edge ds 1 b := - ⟨(x,⟨y.val,one_bruhat ds y.val, - bruhat_trans ds ((mem_externalLower ds x.val c.val y.val).mp - (Finset.mem_filter.mp y.property).1).1 c.property.2⟩),external_step ds y.property⟩ - - theorem externalEdge_mem (x c : Interval ds 1 b) (y : oppositeExternal ds x.val c.val) : - externalEdge ds b x c y ∈ modelOutgoing (graph ds 1 b) c x := by - classical - apply (mem_modelOutgoing _ _ _ _).mpr - exact ⟨rfl,((mem_externalLower ds x.val c.val y.val).mp - (Finset.mem_filter.mp y.property).1).1⟩ - - def outgoingEquiv (x c : Interval ds 1 b) : - ↥(oppositeExternal ds x.val c.val) ≃ ↥(modelOutgoing (graph ds 1 b) c x) where - toFun y := ⟨externalEdge ds b x c y,externalEdge_mem ds b x c y⟩ - invFun e := ⟨(target ds 1 b e.val).val,by - obtain ⟨hs,ht⟩ := (mem_modelOutgoing _ _ _ _).mp e.property - have hh := e.val.property - change BruhatStep ds (source ds 1 b e.val).val (target ds 1 b e.val).val at hh - change source ds 1 b e.val = x at hs - rw [hs] at hh - exact step_external ds hh ht⟩ - left_inv _ := rfl - right_inv e := by - apply Subtype.ext - apply Subtype.ext - apply Prod.ext - · exact ((mem_modelOutgoing _ _ _ _).mp e.property).1.symm - · rfl - - theorem interpolation_product (x c : Interval ds 1 b) : - (∏ y : oppositeExternal ds x.val c.val, - linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x.val c.val y).val)) = - modelProduct (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c x := by - classical - calc - _ = ∏ e : ↥(modelOutgoing (graph ds 1 b) c x), inducedLabel ds cs φ hφ basis b e.val := - (outgoingEquiv ds b x c).prod_comp _ - _ = _ := Finset.prod_coe_sort _ _ - - theorem hasFlowDown (hφinj : Function.Injective φ) (c : Interval ds 1 b) : - HasFlowDown (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c := by - classical - intro x hxc - obtain ⟨F,hF,hFx,hFzero⟩ := interpolation_exists ds cs φ hφ basis hφinj hxc - let f : (structureSheaf (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c).Assignment := - fun v _ => F v.val - refine ⟨f,?_,?_,?_⟩ - · apply (structureCompatible_iff _ _ _ _ _).mpr - intro e _ _ h - have hdiv := hF (label ds 1 b e) (label_isReflection ds 1 b e) - (inducedRoot ds cs φ hφ b e).val (positiveRoot_represents M cs - ⟨φ (label ds 1 b e),hφ _ (label_isReflection ds 1 b e)⟩) - (source ds 1 b e).val - rw [label_mul_source] at hdiv - exact hdiv - · intro _ - exact hFx.trans (interpolation_product ds cs φ hφ basis b x c) - · intro y hy - funext h - exact hFzero y.val h.down hy - -omit [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] in - theorem inducedLabel_prime (e : Edge ds 1 b) : Prime (inducedLabel ds cs φ hφ basis b e) := by - apply (MulEquiv.prime_iff (SymmetricAlgebra.equivMvPolynomial basis)).mpr - apply EdgeAlgebra.symmetric_ι_prime - intro h - exact (inducedRoot ds cs φ hφ b e).property.1.ne_zero (congrArg Prod.fst h) - -omit [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] in - theorem label_eq_of_induced_dvd (hφinj : Function.Injective φ) {e f : Edge ds 1 b} - (h : inducedLabel ds cs φ hφ basis b e ∣ inducedLabel ds cs φ hφ basis b f) : - label ds 1 b e = label ds 1 b f := by - apply hφinj - suffices he : inducedRoot ds cs φ hφ b e = inducedRoot ds cs φ hφ b f from - congrArg Subtype.val ((positiveRootEquiv M cs).injective he) - by_contra hn - have hd : SymmetricAlgebra.ι ℝ (Extended M) (embed M (inducedRoot ds cs φ hφ b e).val) ∣ - SymmetricAlgebra.ι ℝ (Extended M) (embed M (inducedRoot ds cs φ hφ b f).val) := by - obtain ⟨z,hz⟩ := h - exact ⟨(SymmetricAlgebra.equivMvPolynomial basis).symm z,by - apply (SymmetricAlgebra.equivMvPolynomial basis).injective - simpa only [map_mul,AlgEquiv.apply_symm_apply,inducedLabel,linearPolynomial,LinearMap.comp_apply,AlgEquiv.toLinearMap_apply] using hz⟩ - obtain ⟨r,hr⟩ := Submodule.mem_span_singleton.mp ((EdgeAlgebra.symmetric_ι_dvd_iff _ _).mp hd) - have he : r • (inducedRoot ds cs φ hφ b e).val = (1:ℝ) • (inducedRoot ds cs φ hφ b f).val := by - have hh := congrArg Prod.fst hr - exact hh.trans (one_smul ℝ _).symm - exact one_ne_zero ((positiveRoots_independent _ _ hn).eq_zero_of_pair' he).2 - - theorem model_flabby (hφinj : Function.Injective φ) (c : Interval ds 1 b) : - (structureSheaf (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c).Flabby := by - classical - let : Finite (Interval ds 1 b) := interval_finite ds 1 b - apply flowDown_flabby - · intro x e he f hf hne - apply ((inducedLabel_prime ds cs φ hφ basis b e).irreducible.isRelPrime_iff_not_dvd).mpr - intro hdiv - apply hne - apply eq_of_label_source_eq ds 1 b (label_eq_of_induced_dvd ds cs φ hφ basis b hφinj hdiv) - exact ((mem_modelOutgoing _ _ _ _).mp he).1.trans ((mem_modelOutgoing _ _ _ _).mp hf).1.symm - · exact hasFlowDown ds cs φ hφ basis b hφinj c - -end -end KLInvariance.Dihedral - -end - - -section - -/-! Instantiation on the actual maximal subgroup of the ambient root plane. -The exact canonical roots, including degenerate/infinite planes, are used. -/ -namespace KLInvariance.TitsSpace.PlaneBasis -open Module BruhatGraph MomentGraph MomentGraph.Sheaf -universe u v us -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} - {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - {σ : Type us} (basis : Basis σ ℝ (Extended M)) -noncomputable section - - def modelLabel (b : planeSubgroup M cs P) (e : Edge B.system 1 b) : MvPolynomial σ ℝ := - Dihedral.inducedLabel B.system cs (planeSubgroup M cs P).subtype - (fun t => (B.reflection_iff t).mp) basis b e - - theorem model_flabby (b : planeSubgroup M cs P) [Fintype (Edge B.system 1 b)] - [DecidableEq (Interval B.system 1 b)] (c : Interval B.system 1 b) : - (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).Flabby := - Dihedral.model_flabby B.system cs (planeSubgroup M cs P).subtype - (fun t => (B.reflection_iff t).mp) basis b Subtype.val_injective c - - theorem model_generated (b : planeSubgroup M cs P) (c : Interval B.system 1 b) : - (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).Generated := - structureSheaf_generated _ _ _ - - theorem model_quotient (b : planeSubgroup M cs P) (c : Interval B.system 1 b) : - (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).UpperQuotient - (B.modelLabel basis b) := structureSheaf_upperQuotient _ _ _ - -end -end KLInvariance.TitsSpace.PlaneBasis - -end - - -section - -/-! Each finite rank-two set fits in a principal Bruhat interval, even in -an infinite dihedral group. No finite Coxeter-system hypothesis is used. -/ -namespace KLInvariance -universe u v -variable {I : Type u} {M : CoxeterMatrix I} {W : Type v} [Group W] - - theorem bruhat_top_of_all_descents (cs : CoxeterSystem M W) (w : W) - (hw : ∀ i, cs.length (cs.simple i * w) < cs.length w) (x : W) : - BruhatLE cs x w := by - classical - have hword : ∀ ω, BruhatLE cs (cs.wordProd ω) w := by - intro ω - induction ω with - | nil => simpa only [cs.wordProd_nil] using one_bruhat cs w - | cons i ω ih => - have hu := upperSimple_mono cs i ih - have hz := le_upperSimple cs i (cs.simple i * cs.wordProd ω) - rw [upperSimple_mul] at hz - have he : upperSimple cs i w = w := by simp only [upperSimple,ite_eq_left (hw i)] - rw [he] at hu - change BruhatLE cs (cs.simple i * cs.wordProd ω) w - exact hz.trans hu - obtain ⟨ω,_,hx⟩ := cs.exists_isReduced x - rw [hx] - exact hword ω - -namespace Dihedral -variable {N : CoxeterMatrix Bool} (ds : CoxeterSystem N W) - - theorem exists_common_upper (s : Finset W) : ∃ b, ∀ x ∈ s, BruhatLE ds x b := by - classical - by_cases hb : BddAbove (Set.range ds.length) - · have hf : (Set.range ds.length).Finite := hb.finite - obtain ⟨b,hb⟩ := (Set.range_nonempty ds.length).csSup_mem hf - have hmax (x : W) : ds.length x ≤ ds.length b := by - rw [hb] - exact le_csSup (hf.bddAbove) (Set.mem_range_self x) - refine ⟨b,fun x _ => bruhat_top_of_all_descents ds b ?_ x⟩ - intro i - have hle := hmax (ds.simple i*b) - have hne := ds.length_simple_mul b i - omega - · have hn : ∀ n : ℕ, ∃ w, n < ds.length w := by - intro n - by_contra h - push Not at h - exact hb ⟨n,by rintro m ⟨x,rfl⟩; exact h x⟩ - obtain ⟨b,hb⟩ := hn (s.sup ds.length) - exact ⟨b,fun x hx => shorter_bruhat ds ((Finset.le_sup hx).trans_lt hb)⟩ - -end Dihedral -end KLInvariance - -end - - -section - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section - - theorem map_not_alt (i : Bool) (n : ℕ) : (alt i n).map Bool.not = alt (!i) n := by - induction n generalizing i with - | zero => rfl - | succ n ih => rw [alt_succ,List.map_cons,ih,alt_succ] - - theorem swap_alt (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : - swap cs (cs.wordProd (alt i n)) = cs.wordProd (alt (!i) n) := by - rw [swap_wordProd,map_not_alt] - - theorem length_alt_le_length (cs : CoxeterSystem M W) (i : Bool) {n : ℕ} {w : W} - (h : n ≤ cs.length w) : cs.length (cs.wordProd (alt i n)) = n := by - obtain ⟨j,hj⟩ := exists_alt cs w - have hr : cs.IsReduced (alt j (cs.length w)) := by - change cs.length (cs.wordProd _) = _ - rw [← hj,length_alt] - have hn := (reduced_alt_take cs hr h).eq - rw [length_alt] at hn - have hi : i=j ∨ i=(!j) := by cases i <;> cases j <;> simp - rcases hi with rfl|rfl - · exact hn - · rw [← swap_alt,length_swap,hn] - - theorem length_indexWord_nat (cs : CoxeterSystem M W) {n : ℕ} {w : W} - (h : n ≤ cs.length w) : cs.length (indexWord cs n) = n := by - rw [indexWord_nat] - exact length_alt_le_length cs false h - - theorem length_indexWord_neg_nat (cs : CoxeterSystem M W) {n : ℕ} {w : W} - (h : n ≤ cs.length w) : cs.length (indexWord cs (-(n:ℤ))) = n := by - rw [indexWord_neg_nat] - exact length_alt_le_length cs true h - - theorem length_indexWord (cs : CoxeterSystem M W) {i : ℤ} {w : W} - (h : i.natAbs ≤ cs.length w) : cs.length (indexWord cs i) = i.natAbs := by - obtain hi|hi := le_total 0 i - · have he : i=(i.natAbs:ℤ) := by rw [Int.natCast_natAbs,abs_of_nonneg hi] - nth_rw 1 [he] - exact length_indexWord_nat cs h - · have he : i= -(i.natAbs:ℤ) := by rw [Int.natCast_natAbs,abs_of_nonpos hi,neg_neg] - nth_rw 1 [he] - exact length_indexWord_neg_nat cs h - - theorem leftDescent_alt (cs : CoxeterSystem M W) (i : Bool) {n : ℕ} {w : W} - (hn : 0 geometricSlope (B.prefixRoot w n)) (Set.Iio (B.system.length w)) := by - apply strictMonoOn_of_lt_succ Set.ordConnected_Iio - intro n _ hn hn' - change n < B.system.length w at hn - change n+1 < B.system.length w at hn' - change geometricSlope (B.prefixRoot w n) < geometricSlope (B.prefixRoot w (n+1)) - rw [prefixRoot,prefixRoot,dite_eq_left hn,dite_eq_left hn'] - apply (B.edgeRoot_slopes_iff _ _).mpr - rw [indexWord_nat] - exact leftDescent_alt B.system false (by omega) hn'.le - - theorem negPrefixRoot_strictAnti (w : planeSubgroup M cs P) : - StrictAntiOn (fun n => geometricSlope (B.negPrefixRoot w n)) - (Set.Iio (B.system.length w)) := by - apply strictAntiOn_of_succ_lt Set.ordConnected_Iio - intro n _ hn hn' - change n < B.system.length w at hn - change n+1 < B.system.length w at hn' - change geometricSlope (B.negPrefixRoot w (n+1)) < geometricSlope (B.negPrefixRoot w n) - rw [negPrefixRoot,negPrefixRoot,dite_eq_left hn,dite_eq_left hn'] - have ht : B.system.IsLeftDescent (indexWord B.system (-((n+1:ℕ):ℤ))) true := by - rw [indexWord_neg_nat] - exact leftDescent_alt B.system true (by omega) hn'.le - have hlen := length_indexWord_neg_nat B.system hn'.le - have hu := unique_leftDescent B.system (w := indexWord B.system (-((n+1:ℕ):ℤ))) - (z := w) (by rw [hlen]; omega) (by rw [hlen]; omega) - have hf : ¬B.system.IsLeftDescent (indexWord B.system (-((n+1:ℕ):ℤ))) false := by - intro hf - obtain ⟨i,_,hi⟩ := hu - have h1 := hi true ht - have h2 := hi false hf - simp_all - have hnlt := (B.edgeRoot_slopes_iff (neg_indexWord_step B.system hn) - (neg_indexWord_step B.system hn')).not.mpr hf - apply lt_of_le_of_ne (le_of_not_gt hnlt) - intro he - have he' := geometricSlope_injective he - exact graphRoot_ne_of_path - ((B.bruhatStep_iff _ _).mpr (neg_indexWord_step B.system hn)) - ((B.bruhatStep_iff _ _).mpr (neg_indexWord_step B.system hn')) he'.symm - - theorem edgeRoot_eq_of_label {x y z w : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (hzw : BruhatStep B.system z w) - (he : y*x⁻¹=w*z⁻¹) : B.edgeRoot hxy = B.edgeRoot hzw := by - unfold edgeRoot graphRoot - apply congrArg (positiveRoot M cs) - apply Subtype.ext - exact congrArg (fun z : planeSubgroup M cs P => (z : W)) he - - theorem prefixRoot_eq_edgeRoot {x y w : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) {n : ℕ} (hn : n omega - · rw [abs_of_nonpos hzs, abs_lt] at hz - dsimp [Before] - split_ifs <;> omega - · rw [abs_of_nonpos hjs, abs_lt] at hi - obtain hzs | hzs := le_total 0 z - · rw [abs_of_nonneg hzs, abs_lt] at hz - dsimp [Before] - split_ifs <;> omega - · rw [abs_of_nonpos hzs, abs_lt] at hz - dsimp [Before] - split_ifs <;> omega - - theorem finite_before_next {m i j z : ℤ} (hm : 0 < m) - (hi : |i| < |j|) (hz : |j| < |z|) - (hzM : -m < z ∧ z ≤ m) : - (i+j) % (2*m) < (j+z) % (2*m) ↔ Before (i+j) (j+z) := by - have hzabs : |z| ≤ m := abs_le.mpr (by omega) - have hjabs := abs_lt.mp (hz.trans_le hzabs) - have hiabs := abs_lt.mp ((hi.trans hz).trans_le hzabs) - rw [midpoint_mod hm (by omega) (by omega), midpoint_mod hm (by omega) (by omega)] - obtain hjs | hjs := le_total 0 j - · rw [abs_of_nonneg hjs, abs_lt] at hi - obtain hzs | hzs := le_total 0 z - · rw [abs_of_nonneg hjs, abs_of_nonneg hzs] at hz - dsimp [Before] - split_ifs <;> omega - · rw [abs_of_nonneg hjs, abs_of_nonpos hzs] at hz - dsimp [Before] - split_ifs <;> omega - · rw [abs_of_nonpos hjs, abs_lt] at hi - obtain hzs | hzs := le_total 0 z - · rw [abs_of_nonpos hjs, abs_of_nonneg hzs] at hz - dsimp [Before] - split_ifs <;> omega - · rw [abs_of_nonpos hjs, abs_of_nonpos hzs] at hz - dsimp [Before] - split_ifs <;> omega - - theorem eligible_ranks_card (L k : ℕ) : - ((Finset.range (L+2*k+1)).filter (fun r => L < r ∧ Odd (L+r))).card = k := by - classical - have hc : (Finset.range k).card = - ((Finset.range (L+2*k+1)).filter (fun r => L < r ∧ Odd (L+r))).card := by - apply Finset.card_bij (fun a _ => L+1+2*a) - · intro a ha - simp only [Finset.mem_range, Finset.mem_filter, Nat.odd_iff] at ha ⊢ - omega - · intro a ha b hb he - omega - · intro b hb - simp only [Finset.mem_range, Finset.mem_filter, Nat.odd_iff] at hb - refine ⟨(b-L-1)/2, ?_, ?_⟩ - · simp only [Finset.mem_range] - omega - · omega - simpa only [Finset.card_range] using hc.symm - - noncomputable def arrowAfter (a label z : ℤ) : ℕ := - if |a| < |z| ∧ Odd (a+z) ∧ Before label (a+z) then 1 else 0 - -/-- Double internal ranks and the singleton top, with no singleton bottom -term because upward arrows never end at the bottom. -/ - noncomputable def countAfter (a label c : ℤ) : ℕ := - (∑ r ∈ Finset.range c.natAbs, (arrowAfter a label r + arrowAfter a label (-r))) + - arrowAfter a label c - - theorem arrowAfter_of_not_lt {a label z : ℤ} (h : ¬ |a| < |z|) : - arrowAfter a label z = 0 := by simp [arrowAfter,h] - - theorem arrowAfter_self (i j : ℤ) : arrowAfter i (i+j) j = 0 := by - have hb : ¬ Before (i+j) (i+j) := by - dsimp [Before] - omega - simp only [arrowAfter, hb, and_false, ite_false] - -end -end KLInvariance.SignedDihedral - -end - - -section - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} - - theorem length_indexWord_unbounded (cs : CoxeterSystem M W) - (hu : ∀ n : ℕ, ∃ w, n ≤ cs.length w) (i : ℤ) : - cs.length (indexWord cs i) = i.natAbs := by - obtain ⟨w,hw⟩ := hu i.natAbs - exact length_indexWord cs hw - -end KLInvariance.Dihedral - -namespace KLInvariance.TitsSpace.PlaneBasis -open KLInvariance.Dihedral -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} - {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) -noncomputable section - - theorem edgeRoot_inverted_iff {x y : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (w : planeSubgroup M cs P) : - rootInverted (w:W) (B.edgeRoot hxy) ↔ B.system.length ((y*x⁻¹)*w) by simp - have hl : rootInverted (w:W) B.left := by - have hh := (B.simpleRoot_inverted_coset_iff hm w false).mpr hd - simpa only [mul_one,simpleRoot,Bool.false_eq_true,↓reduceIte] using hh - exact B.slope_lt_of_inverted_left (w:W) hl _ _ (B.edgeRoot_plane hxy) - (B.edgeRoot_plane hzt) hi hn - -/-- The two angular rays of an infinite canonical dihedral subsystem, with -actual ambient labels, have precisely the source's signed-midpoint order. -/ - theorem edgeRoot_infinite_order - (hu : ∀ n : ℕ, ∃ w, n ≤ B.system.length w) - {x y z t : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (hzt : BruhatStep B.system z t) - {a b : ℤ} (ha : Odd a) (hb : Odd b) - (hx : y*x⁻¹=indexWord B.system a) (hz : t*z⁻¹=indexWord B.system b) : - geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hzt) ↔ - SignedDihedral.Before a b := by - have repr (q : ℤ) (hq : Odd q) : - ∃ k : ℕ, q=2*(k:ℤ)+1 ∨ q= -(2*(k:ℤ)+1) := by - have habs := Int.natCast_natAbs q - have ho : q.natAbs % 2=1 := by - rw [Int.odd_iff] at hq - rcases le_total 0 q with h|h - · rw [abs_of_nonneg h] at habs - omega - · rw [abs_of_nonpos h] at habs - omega - refine ⟨q.natAbs/2,?_⟩ - rcases le_total 0 q with h|h - · left - rw [abs_of_nonneg h] at habs - omega - · right - rw [abs_of_nonpos h] at habs - omega - obtain ⟨k,hk|hk⟩ := repr a ha <;> obtain ⟨l,hl|hl⟩ := repr b hb - · obtain ⟨w,hw⟩ := hu (max k l+1) - have hk' : k omega - -/-- The actual ambient angular order in a finite canonical plane subsystem -is the increasing residue order on odd doubled midpoints. -/ - theorem edgeRoot_finite_order - (w : planeSubgroup M cs P) (hmax : ∀ z, B.system.length z ≤ B.system.length w) - {x y z t : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (hzt : BruhatStep B.system z t) - {a b : ℤ} (ha : Odd a) (hb : Odd b) - (hx : y*x⁻¹=indexWord B.system a) (hz : t*z⁻¹=indexWord B.system b) : - geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hzt) ↔ - a % (2*(B.system.length w:ℤ)) < b % (2*(B.system.length w:ℤ)) := by - obtain ⟨k,hk,he⟩ := odd_residue_repr (B.max_length_pos w hmax) ha - obtain ⟨l,hl,hf⟩ := odd_residue_repr (B.max_length_pos w hmax) hb - have hp := rotation_pow_max B.system w hmax - rw [← indexWord_mod_period B.system hp a, he] at hx - rw [← indexWord_mod_period B.system hp b, hf] at hz - rw [← B.prefixRoot_eq_edgeRoot hxy hk hx,← B.prefixRoot_eq_edgeRoot hzt hl hz] - rw [(B.prefixRoot_strictMono w).lt_iff_lt hk hl,he,hf] - omega - -end -end KLInvariance.TitsSpace.PlaneBasis - -end - - -section - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section -local instance : DecidableEq W := Classical.decEq W - - theorem indexWord_pos_ne_neg (cs : CoxeterSystem M W) {n : ℕ} {w : W} - (hn : 0 cs.length z=n) = - {indexWord cs n,indexWord cs (-(n:ℤ))} := by - classical - ext z - simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_insert,Finset.mem_singleton] - constructor - · intro hz - obtain ⟨i,hi⟩ := exists_alt cs z - rw [hz.2] at hi - cases i - · exact Or.inl (hi.trans (indexWord_nat cs n).symm) - · exact Or.inr (hi.trans (indexWord_neg_nat cs n).symm) - · rintro (rfl|rfl) - · have hl := length_indexWord_nat cs hc.le - exact ⟨shorter_bruhat cs (by rw [hl]; exact hc),hl⟩ - · have hl := length_indexWord_neg_nat cs hc.le - exact ⟨shorter_bruhat cs (by rw [hl]; exact hc),hl⟩ - - theorem lower_zero_fiber (cs : CoxeterSystem M W) (c : W) : - (lowerFinset cs c).filter (fun z => cs.length z=0) = {1} := by - classical - ext z - simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_singleton] - constructor - · exact fun hz => cs.length_eq_zero_iff.mp hz.2 - · rintro rfl - exact ⟨one_bruhat cs c,cs.length_one⟩ - - theorem lower_top_fiber (cs : CoxeterSystem M W) (c : W) : - (lowerFinset cs c).filter (fun z => cs.length z=cs.length c) = {c} := by - classical - ext z - simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_singleton] - constructor - · intro hz - by_contra hne - have hl := length_lt_of_bruhat_ne cs hz.1 hne - omega - · rintro rfl - exact ⟨bruhat_refl cs _,rfl⟩ - -/-- Actual finite dihedral lower ideals have two internal alternating rays -and a singleton top. The doubled identity contributes zero. -/ - theorem sum_lower_signed (cs : CoxeterSystem M W) (c : W) - {A : Type*} [AddCommMonoid A] (f : W → A) (h1 : f 1=0) : - ∑ z ∈ lowerFinset cs c, f z = - (∑ n ∈ Finset.range (cs.length c), - (f (indexWord cs n)+f (indexWord cs (-(n:ℤ))))) + f c := by - classical - have hmap : ∀ z ∈ lowerFinset cs c, cs.length z ∈ Finset.range (cs.length c+1) := by - intro z hz - have hl := length_le_of_bruhat cs ((mem_lowerFinset cs c z).mp hz) - simp only [Finset.mem_range] - omega - rw [← Finset.sum_fiberwise_of_maps_to hmap f,Finset.sum_range_succ,lower_top_fiber, - Finset.sum_singleton] - congr 1 - apply Finset.sum_congr rfl - intro n hn - have hc := Finset.mem_range.mp hn - by_cases hz : n=0 - · subst n - rw [lower_zero_fiber] - simp only [Finset.sum_singleton,indexWord_nat,indexWord_neg_nat,alt_zero, - cs.wordProd_nil,h1,add_zero] - · rw [lower_length_fiber cs c hc, - Finset.sum_pair (indexWord_pos_ne_neg cs (by omega) hc)] - -end -end KLInvariance.Dihedral - -end - - -section - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section - - def GoodIndex (cs : CoxeterSystem M W) (i : ℤ) : Prop := - ∀ w, (∀ z, cs.length z ≤ cs.length w) → -(cs.length w:ℤ) < i ∧ i ≤ (cs.length w:ℤ) - - theorem maximal_or_unbounded (cs : CoxeterSystem M W) : - (∃ w, ∀ z, cs.length z ≤ cs.length w) ∨ (∀ n : ℕ, ∃ w, n≤cs.length w) := by - by_cases hb : BddAbove (Set.range cs.length) - · have hf : (Set.range cs.length).Finite := hb.finite - obtain ⟨b,hb⟩ := (Set.range_nonempty cs.length).csSup_mem hf - left - refine ⟨b,fun z => ?_⟩ - rw [hb] - exact le_csSup hf.bddAbove (Set.mem_range_self z) - · right - intro n - by_contra h - push Not at h - exact hb ⟨n,by rintro m ⟨z,rfl⟩; exact (h z).le⟩ - - theorem max_length_positive (cs : CoxeterSystem M W) {w : W} - (hmax : ∀ z, cs.length z ≤ cs.length w) : 0 by - have h := hmax (cs.simple i*w) - have h' := cs.length_simple_mul w i - omega) z - by_contra hne - have hl := length_lt_of_bruhat_ne cs htop hne - omega - - theorem goodIndex_nat (cs : CoxeterSystem M W) {n : ℕ} {c : W} - (hc : n≤cs.length c) : GoodIndex cs (n:ℤ) := by - intro w hw - have h := hw c - have hp := max_length_positive cs hw - omega - - theorem goodIndex_neg_nat (cs : CoxeterSystem M W) {n : ℕ} {c : W} - (hc : n rfl - · simp only [arrowAfter, hir, hl, false_and, ite_false] - - theorem arrowAfter_next {i j : ℤ} (hij : |i| < |j|) (z : ℤ) : - arrowAfter j (i+j) z = - if j.natAbs < z.natAbs ∧ Odd (j.natAbs+z.natAbs) ∧ 0 < j then 1 else 0 := by - have hlt : |j| < |z| ↔ j.natAbs < z.natAbs := by - rw [← Int.natCast_natAbs j, ← Int.natCast_natAbs z, Nat.cast_lt] - have ho : Odd (j+z) ↔ Odd (j.natAbs+z.natAbs) := by - have hj := Int.natCast_natAbs j - have hz := Int.natCast_natAbs z - rw [Int.odd_iff,Nat.odd_iff] - rcases le_total 0 j with hj'|hj' <;> rcases le_total 0 z with hz'|hz' - · rw [abs_of_nonneg hj'] at hj - rw [abs_of_nonneg hz'] at hz - omega - · rw [abs_of_nonneg hj'] at hj - rw [abs_of_nonpos hz'] at hz - omega - · rw [abs_of_nonpos hj'] at hj - rw [abs_of_nonneg hz'] at hz - omega - · rw [abs_of_nonpos hj'] at hj - rw [abs_of_nonpos hz'] at hz - omega - by_cases h : |j| < |z| - · simp only [arrowAfter, before_next_source hij h, ho, hlt] - · have h' := hlt.not.mp h - simp only [arrowAfter,h,h',false_and,ite_false] - - theorem countAfter_base {i j : ℤ} (hij : |i| < |j|) - (ho : Odd (i.natAbs+j.natAbs)) : - countAfter i (i+j) j = (j.natAbs-i.natAbs-1)/2 := by - unfold countAfter - rw [arrowAfter_self,add_zero] - have hs : ∀ r ∈ Finset.range j.natAbs, - arrowAfter i (i+j) r + arrowAfter i (i+j) (-r) = - if i.natAbs < r ∧ Odd (i.natAbs+r) then 1 else 0 := by - intro r hr - have hr' := Finset.mem_range.mp hr - rw [arrowAfter_pos hij,arrowAfter_neg hij] - have hn : ¬ j.natAbs < r := by omega - simp only [hn,and_false,ite_false,zero_add,hr',or_true,and_true] - rw [Finset.sum_congr rfl hs, ← Finset.sum_filter, Finset.sum_const, - nsmul_eq_mul, mul_one] - have hh : i.natAbs < j.natAbs := by - rw [← Nat.cast_lt (α := ℤ),Int.natCast_natAbs,Int.natCast_natAbs] - exact hij - have he : j.natAbs = i.natAbs+2*((j.natAbs-i.natAbs-1)/2)+1 := by - rw [Nat.odd_iff] at ho - omega - conv_lhs => rw [he] - exact eligible_ranks_card _ _ - -/-- A double internal level together with the singleton top contributes one -outgoing arrow per rank, independently of top parity. -/ - theorem total_outgoing_count (L C : ℕ) (h : L ≤ C) : - (∑ r ∈ Finset.range C, if L < r ∧ Odd (L+r) then 2 else 0) + - (if L < C ∧ Odd (L+C) then 1 else 0) = C-L := by - induction C, h using Nat.le_induction with - | base => - have hz : ∀ r ∈ Finset.range L, ¬ L < r := by - intro r hr - have := Finset.mem_range.mp hr - omega - have hs : (∑ r ∈ Finset.range L, if L < r ∧ Odd (L+r) then 2 else 0) = 0 := by - apply Finset.sum_eq_zero - intro r hr - simp only [hz r hr, false_and, ite_false] - simp only [hs, lt_self_iff_false, false_and, ite_false, add_zero, Nat.sub_self] - | succ C h ih => - rw [Finset.sum_range_succ] - by_cases hc : L rcases le_total 0 z with hz'|hz' - · rw [abs_of_nonneg hi'] at hi - rw [abs_of_nonneg hz'] at hz - omega - · rw [abs_of_nonneg hi'] at hi - rw [abs_of_nonpos hz'] at hz - omega - · rw [abs_of_nonpos hi'] at hi - rw [abs_of_nonneg hz'] at hz - omega - · rw [abs_of_nonpos hi'] at hi - rw [abs_of_nonpos hz'] at hz - omega - - theorem arrowAfter_far {i j z : ℤ} (hij : |i| < |j|) (hjz : |j| < |z|) : - arrowAfter i (i+j) z = if Odd (i.natAbs+z.natAbs) ∧ 0 < j then 1 else 0 := by - have hiz := hij.trans hjz - have hb : Before (i+j) (i+z) ↔ 0 < j := by - by_cases hj : 0 < j - · rw [before_same_source_pos hij hiz hj] - rw [abs_of_pos hj] at hjz - rw [lt_abs] at hjz - omega - · have hj' : j < 0 := by - have := abs_nonneg i - rw [abs_of_nonpos (by omega : j ≤ 0)] at hij - omega - rw [before_same_source_neg hij hiz hj'] - rw [abs_of_neg hj',lt_abs] at hjz - omega - simp only [arrowAfter,hiz,true_and,odd_add_abs,hb] - - def positiveCount (L M C : ℕ) : ℕ := - (∑ r ∈ Finset.range C, if L < r ∧ Odd (L+r) then (if M < r then 2 else 1) else 0) + - (if M < C ∧ Odd (L+C) then 1 else 0) - - theorem positiveCount_formula (L M C : ℕ) (hLM : L < M) (ho : Odd (L+M)) - (hMC : M ≤ C) : positiveCount L M C = (M-L-1)/2 + (C-M) := by - induction C, hMC using Nat.le_induction with - | base => - have he : M = L+2*((M-L-1)/2)+1 := by - rw [Nat.odd_iff] at ho - omega - have hs : (∑ r ∈ Finset.range M, - if L < r ∧ Odd (L+r) then (if M < r then 2 else 1) else 0) = - (∑ r ∈ Finset.range M, if L < r ∧ Odd (L+r) then 1 else 0) := by - apply Finset.sum_congr rfl - intro r hr - have hn : ¬ M < r := by have := Finset.mem_range.mp hr; omega - simp only [hn,ite_false] - rw [positiveCount,hs,← Finset.sum_filter,Finset.sum_const,nsmul_eq_mul,mul_one] - simp only [lt_self_iff_false,false_and,ite_false,add_zero,Nat.sub_self] - conv_lhs => rw [he] - exact eligible_ranks_card _ _ - | succ C hMC ih => - rw [positiveCount,Finset.sum_range_succ] - unfold positiveCount at ih - by_cases h : M rfl - · have hh : ¬(i.natAbs < r ∧ Odd (i.natAbs+r) ∧ j.natAbs < r) := by tauto - simp only [h1,hh,ite_false,add_zero] - rw [countAfter,Finset.sum_congr rfl hs,arrowAfter_far hij h] - simp only [hj,and_true] - have heq : (if Odd (i.natAbs+c.natAbs) then 1 else 0) = - (if j.natAbs < c.natAbs ∧ Odd (i.natAbs+c.natAbs) then 1 else 0) := by - simp only [hMC,true_and] - rw [heq] - exact positiveCount_formula _ _ _ hLM ho hMC.le - - theorem countAfter_neg_formula {i j c : ℤ} (hij : |i| < |j|) - (ho : Odd (i.natAbs+j.natAbs)) (hj : j < 0) - (h : c=j ∨ |j| < |c|) : - countAfter i (i+j) c = (j.natAbs-i.natAbs-1)/2 := by - rcases h with rfl|h - · exact countAfter_base hij ho - have hMC : j.natAbs < c.natAbs := by - exact_mod_cast (show (j.natAbs:ℤ) < c.natAbs by simpa only [Int.natCast_natAbs] using h) - have hn : ¬0 rfl - rw [Finset.sum_congr rfl hs] - exact total_outgoing_count _ _ hMC - · simp only [hj,and_false,ite_false,add_zero,Finset.sum_const_zero] - -/-- The signed-index cardinality identity for the source's forward angular -order. Its identification with actual Coxeter angular roots is separate. -/ - theorem countAfter_difference {i j c : ℤ} (hij : |i| < |j|) - (ho : Odd (i.natAbs+j.natAbs)) (h : c=j ∨ |j| < |c|) : - countAfter i (i+j) c = countAfter j (i+j) c + (j.natAbs-i.natAbs-1)/2 := by - rw [countAfter_next_formula hij h] - by_cases hj : 0 h (Relation.ReflTransGen.single hz) - simp only [afterIndicator,dite_eq_right hn] - -/-- Counting only the relative interval above a lower bound does not alter -an outgoing count based at a vertex above that bound. -/ - theorem interval_laterCount {a x c : planeSubgroup M cs P} - (hax : BruhatLE B.system a x) (α : PositiveRoot M cs) : - (∑ᶠ z : Interval B.system a c, B.afterIndicator x α z.val) = - B.laterCount x α c := by - classical - let := interval_finite B.system a c - let : Fintype (Interval B.system a c) := Fintype.ofFinite _ - rw [finsum_eq_sum_of_fintype,laterCount] - have hs := Finset.sum_subtype (F := (inferInstance : Fintype (Interval B.system a c))) - ((lowerFinset B.system c).filter (fun z => BruhatLE B.system a z)) - (fun z => by simp only [Finset.mem_filter,mem_lowerFinset]; exact and_comm) - (fun z => B.afterIndicator x α z) - refine hs.symm.trans (Finset.sum_subset (Finset.filter_subset _ _) ?_) - intro z hz hn - apply B.afterIndicator_eq_zero - intro hxz - exact hn (Finset.mem_filter.mpr ⟨hz,bruhat_trans B.system hax hxz⟩) - - theorem edgeRoot_coset {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {x y : planeSubgroup M cs P} (hxy : BruhatStep B.system x y) : - B.edgeRoot hxy = graphRoot ((B.coset_step_iff hmin x y).mpr hxy) := by - unfold edgeRoot graphRoot - apply congrArg (positiveRoot M cs) - apply Subtype.ext - change (y:W)*(x:W)⁻¹=((y:W)*a₀)*((x:W)*a₀)⁻¹ - group - -variable {I' : Type u'} [Fintype I'] {M' : CoxeterMatrix I'} - {W' : Type v'} [Group W'] {cs' : CoxeterSystem M' W'} - {P' : Submodule ℝ (I' → ℝ)} (B' : PlaneBasis (M := M') (cs := cs') P') - -/-- A full relative interval transport carries the actual angular later-edge -count. An arbitrary graph embedding would not suffice here. -/ - theorem interval_map_count {a c : planeSubgroup M cs P} - (hac : BruhatLE B.system a c) - (F : Interval B.system a c → planeSubgroup M' cs' P') - (hinj : Function.Injective F) - (hrange : Set.range F = {z | BruhatLE B'.system (F ⟨a,bruhat_refl B.system a,hac⟩) z ∧ - BruhatLE B'.system z (F ⟨c,hac,bruhat_refl B.system c⟩)}) - (x : Interval B.system a c) (α : PositiveRoot M' cs') : - (∑ᶠ z : Interval B.system a c, B'.afterIndicator (F x) α (F z)) = - B'.laterCount (F x) α (F ⟨c,hac,bruhat_refl B.system c⟩) := by - classical - let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ - let hi : Interval B.system a c := ⟨c,hac,bruhat_refl B.system c⟩ - have hmem (z : Interval B.system a c) : BruhatLE B'.system (F lo) (F z) ∧ - BruhatLE B'.system (F z) (F hi) := by - exact (Set.ext_iff.mp hrange (F z)).mp ⟨z,rfl⟩ - let f : Interval B.system a c → Interval B'.system (F lo) (F hi) := - fun z => ⟨F z,hmem z⟩ - have hf : Function.Bijective f := by - constructor - · intro z w h - exact hinj (congrArg Subtype.val h) - · intro z - obtain ⟨w,hw⟩ := (Set.ext_iff.mp hrange z.val).mpr z.property - exact ⟨w,Subtype.ext hw⟩ - let E := Equiv.ofBijective f hf - have hs := finsum_comp_equiv E (f := fun z : Interval B'.system (F lo) (F hi) => - B'.afterIndicator (F x) α z.val) - exact hs.trans (B'.interval_laterCount (hmem x).1 α) - -end -end KLInvariance.TitsSpace.PlaneBasis - -end - - -section - -namespace KLInvariance.TitsSpace -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section - - def ambientAfterIndicator (x : W) (α : PositiveRoot M cs) (z : W) : ℕ := by - classical - exact if h : BruhatStep cs x z then - if geometricSlope α < geometricSlope (graphRoot h) then 1 else 0 - else 0 - - theorem ambientAfterIndicator_of_le {x z : W} (α : PositiveRoot M cs) - (hz : BruhatLE cs z x) : ambientAfterIndicator x α z=0 := by - classical - have hn : ¬BruhatStep cs x z := fun h => - (not_lt_of_ge (length_le_of_bruhat cs hz)) h.1 - simp only [ambientAfterIndicator,dite_eq_right hn] - - theorem ambientAfterIndicator_edge_self {x y : W} (hxy : BruhatStep cs x y) : - ambientAfterIndicator x (graphRoot hxy) y=0 := by - classical - simp only [ambientAfterIndicator,dite_eq_left hxy,lt_self_iff_false,ite_false] - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - - theorem ambientAfterIndicator_coset {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - (x z : planeSubgroup M cs P) (α : PositiveRoot M cs) : - ambientAfterIndicator ((x:W)*a₀) α ((z:W)*a₀) = B.afterIndicator x α z := by - classical - by_cases h : BruhatStep B.system x z - · have h' := (B.coset_step_iff hmin x z).mpr h - simp only [ambientAfterIndicator,afterIndicator,dite_eq_left h,dite_eq_left h',B.edgeRoot_coset hmin h] - · have h' : ¬BruhatStep cs ((x:W)*a₀) ((z:W)*a₀) := - fun hz => h ((B.coset_step_iff hmin x z).mp hz) - simp only [ambientAfterIndicator,afterIndicator,dite_eq_right h,dite_eq_right h'] - -universe u' v' -variable {I' : Type u'} [Fintype I'] {M' : CoxeterMatrix I'} - {W' : Type v'} [Group W'] {cs' : CoxeterSystem M' W'} - - - theorem transported_count_difference {a₀ u b : W} {u' b' : W'} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {a c : planeSubgroup M cs P} (hac : BruhatLE B.system a c) - (hrank : B.system.length a+2 ≤ B.system.length c) - (hlo : BruhatLE cs u ((a:W)*a₀)) (hhi : BruhatLE cs ((c:W)*a₀) b) - (e : Interval cs u b ≃o Interval cs' u' b') - (y : Interval B.system a c) (hxy : BruhatStep B.system a y.val) : - let inc := B.cosetIntervalMap hmin hlo hhi - let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ - let α := graphRoot ((intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr - ((B.coset_step_iff hmin a y.val).mpr hxy)) - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc lo)).val α (e (inc z)).val) = - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc y)).val α (e (inc z)).val) + - (B.system.length y.val-B.system.length a-1)/2 := by - classical - dsimp only - let inc := B.cosetIntervalMap hmin hlo hhi - let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ - let hi : Interval B.system a c := ⟨c,hac,bruhat_refl B.system c⟩ - have hedge := (intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr - ((B.coset_step_iff hmin a y.val).mpr hxy) - change (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val) = - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val) + _ - obtain ⟨P',B',a',F,hmin',hinj,hcoord,horder,hstep,hlen,hrange⟩ := - B.transport_interval hmin hac hrank hlo hhi e - have hFxy : BruhatStep B'.system (F lo) (F y) := (hstep lo y).mpr hxy - have hFyc : BruhatLE B'.system (F y) (F hi) := (horder y hi).mpr y.property.2 - have hroot : B'.edgeRoot hFxy=graphRoot hedge := by - rw [B'.edgeRoot_coset hmin' hFxy] - unfold graphRoot - apply congrArg (positiveRoot M' cs') - apply Subtype.ext - change ((F y:W')*a')*((F lo:W')*a')⁻¹=(e (inc y)).val*(e (inc lo)).val⁻¹ - rw [hcoord y,hcoord lo] - have hsum (x : Interval B.system a c) : - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc x)).val (graphRoot hedge) (e (inc z)).val) = - B'.laterCount (F x) (B'.edgeRoot hFxy) (F hi) := by - rw [← B.interval_map_count B' hac F hinj hrange x (B'.edgeRoot hFxy)] - apply finsum_congr - intro z - rw [← hcoord x,← hcoord z,← hroot] - exact B'.ambientAfterIndicator_coset hmin' (F x) (F z) _ - rw [hsum lo,hsum y,B'.laterCount_difference hFxy hFyc] - congr 1 - have hy := hlen y - change B'.system.length (F y)+B.system.length a = - B'.system.length (F lo)+B.system.length y.val at hy - omega - -/-- The same scheduled count with no restriction on the relative rank. -/ - theorem transported_count_difference_all {a₀ u b : W} {u' b' : W'} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {a c : planeSubgroup M cs P} (hac : BruhatLE B.system a c) - (hlo : BruhatLE cs u ((a:W)*a₀)) (hhi : BruhatLE cs ((c:W)*a₀) b) - (e : Interval cs u b ≃o Interval cs' u' b') - (y : Interval B.system a c) (hxy : BruhatStep B.system a y.val) : - let inc := B.cosetIntervalMap hmin hlo hhi - let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ - let α := graphRoot ((intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr - ((B.coset_step_iff hmin a y.val).mpr hxy)) - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc lo)).val α (e (inc z)).val) = - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc y)).val α (e (inc z)).val) + - (B.system.length y.val-B.system.length a-1)/2 := by - classical - by_cases hrank : B.system.length a+2 ≤ B.system.length c - · exact B.transported_count_difference hmin hac hrank hlo hhi e y hxy - let inc := B.cosetIntervalMap hmin hlo hhi - let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ - have hedge := (intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr - ((B.coset_step_iff hmin a y.val).mpr hxy) - change (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val) = - (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val) + _ - have hylen := hxy.1 - have hyc := length_le_of_bruhat B.system y.property.2 - have hlen : B.system.length y.val=B.system.length a+1 := by omega - have heyc : y.val=c := by - by_contra hn - have hlt := length_lt_of_bruhat_ne B.system y.property.2 hn - omega - have hverts (z : Interval B.system a c) : z=lo ∨ z=y := by - by_cases hz : z.val=a - · exact Or.inl (Subtype.ext hz) - · right - apply Subtype.ext - rw [heyc] - by_contra hzc - have hzlo := length_lt_of_bruhat_ne B.system z.property.1 (Ne.symm hz) - have hzhi := length_lt_of_bruhat_ne B.system z.property.2 hzc - omega - have hzero₁ : (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val)=0 := by - apply finsum_eq_zero_of_forall_eq_zero - intro z - rcases hverts z with rfl | rfl - · exact ambientAfterIndicator_of_le _ (bruhat_refl cs' _) - · exact ambientAfterIndicator_edge_self hedge - have hzero₂ : (∑ᶠ z : Interval B.system a c, - ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val)=0 := by - apply finsum_eq_zero_of_forall_eq_zero - intro z - rcases hverts z with rfl | rfl - · exact ambientAfterIndicator_of_le _ (Relation.ReflTransGen.single hedge) - · exact ambientAfterIndicator_of_le _ (bruhat_refl cs' _) - rw [hzero₁,hzero₂,hlen] - omega - -end PlaneBasis -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Linear prime ideals in the exact symmetric algebra, including the actual -root-plane coefficient primes. No local-ring or survival property is assumed. -/ - -end - -end OAI +import OAI.RepresentationTheory.KazhdanLusztig.ReflectionOrders + +namespace OAI + +/-! +Signed dihedral coordinates, actual dihedral intervals, exact later-edge counts and root-plane calculations. +-/ + +section + +namespace KLInvariance.Dihedral +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +noncomputable section + + theorem wordProd_alt_odd (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : + cs.wordProd (alt i (2*n+1)) = (cs.simple i * cs.simple (!i)) ^ n * cs.simple i := by + induction n with + | zero => simp + | succ n ih => + rw [show 2*(n+1)+1 = (2*n+1)+2 by omega, alt_add_two] + simp only [cs.wordProd_cons, ih, pow_succ'] + group + + def rotation (cs : CoxeterSystem M W) : W := cs.simple false * cs.simple true + + theorem simple_rotation (cs : CoxeterSystem M W) : + cs.simple false * rotation cs = (rotation cs)⁻¹ * cs.simple false := by + simp only [rotation, mul_inv_rev, cs.inv_simple] + rw [cs.simple_mul_simple_cancel_left, mul_assoc, cs.simple_mul_simple_self, mul_one] + + theorem simple_rotation_zpow (cs : CoxeterSystem M W) (n : ℤ) : + cs.simple false * rotation cs ^ n = rotation cs ^ (-n) * cs.simple false := by + have h : SemiconjBy (cs.simple false) (rotation cs) (rotation cs)⁻¹ := + simple_rotation cs + have hh := h.zpow_right n + change cs.simple false * rotation cs ^ n = ((rotation cs)⁻¹) ^ n * cs.simple false at hh + simpa only [inv_zpow, zpow_neg] using hh + +/-- The signed coordinate evaluates both alternating rays in the same group. +The Euclidean quotient also gives the correct odd negative coordinates. -/ + def indexWord (cs : CoxeterSystem M W) (i : ℤ) : W := + if i % 2 = 0 then rotation cs ^ (i/2) + else rotation cs ^ (i/2) * cs.simple false + + theorem indexWord_even (cs : CoxeterSystem M W) (n : ℤ) : + indexWord cs (2*n) = rotation cs ^ n := by simp [indexWord] + + theorem indexWord_odd (cs : CoxeterSystem M W) (n : ℤ) : + indexWord cs (2*n+1) = rotation cs ^ n * cs.simple false := by + simp only [indexWord, show (2*n+1)%2 = 1 by omega, show (1:ℤ) ≠ 0 by omega, ite_false, + show (2*n+1)/2 = n by omega] + + theorem indexWord_nat (cs : CoxeterSystem M W) (n : ℕ) : + indexWord cs n = cs.wordProd (alt false n) := by + rcases Nat.even_or_odd n with ⟨k,rfl⟩ | ⟨k,rfl⟩ + · rw [show k+k = 2*k by omega, Nat.cast_mul, Nat.cast_ofNat, indexWord_even, + wordProd_alt_even] + simp only [rotation, Bool.not_false, zpow_natCast] + · rw [Nat.cast_add, Nat.cast_mul, + Nat.cast_ofNat, Nat.cast_one, indexWord_odd, wordProd_alt_odd] + simp only [rotation, Bool.not_false, zpow_natCast] + + theorem indexWord_neg_nat (cs : CoxeterSystem M W) (n : ℕ) : + indexWord cs (-(n:ℤ)) = cs.wordProd (alt true n) := by + have hr : cs.simple true * cs.simple false = (rotation cs)⁻¹ := by + simp only [rotation, mul_inv_rev, cs.inv_simple] + rcases Nat.even_or_odd n with ⟨k,rfl⟩ | ⟨k,rfl⟩ + · rw [show k+k = 2*k by omega, Nat.cast_mul, Nat.cast_ofNat, + show -(2*(k:ℤ)) = 2*(-k) by ring, indexWord_even, wordProd_alt_even] + simp only [Bool.not_true, hr, zpow_neg, zpow_natCast, inv_pow] + · rw [Nat.cast_add, Nat.cast_mul, + Nat.cast_ofNat, Nat.cast_one, + show -(2*(k:ℤ)+1) = 2*(-(k:ℤ)-1)+1 by ring, indexWord_odd, + wordProd_alt_odd] + rw [show -(k:ℤ)-1 = -(k:ℤ)+(-1) by ring, zpow_add] + simp only [zpow_neg, zpow_natCast, zpow_one, Bool.not_true, hr, inv_pow] + simp only [rotation, mul_inv_rev, cs.inv_simple] + simp only [mul_assoc, cs.simple_mul_simple_self, mul_one] + + theorem exists_indexWord (cs : CoxeterSystem M W) (w : W) : + ∃ i : ℤ, |i| = (cs.length w : ℤ) ∧ indexWord cs i = w := by + obtain ⟨i,hi⟩ := exists_alt cs w + cases i + · exact ⟨cs.length w, by simp, (indexWord_nat cs _).trans hi.symm⟩ + · exact ⟨-(cs.length w : ℤ), by simp, (indexWord_neg_nat cs _).trans hi.symm⟩ + +/-- A reflection acts on the signed index line by reflection in its midpoint. +Finite dihedral groups are handled by equality in the group, without choosing +residue representatives here. -/ + theorem indexWord_reflection_mul (cs : CoxeterSystem M W) {a : ℤ} (ha : Odd a) + (i : ℤ) : indexWord cs a * indexWord cs i = indexWord cs (a-i) := by + obtain ⟨k,hk⟩ := ha + have hk' : a = 2*k+1 := by omega + rw [hk',indexWord_odd] + rcases Int.even_or_odd i with ⟨l,hl⟩ | ⟨l,hl⟩ + · have hl' : i=2*l := by omega + rw [hl',indexWord_even,show 2*k+1-2*l=2*(k-l)+1 by ring,indexWord_odd] + rw [mul_assoc, simple_rotation_zpow, ← mul_assoc, ← zpow_add] + congr 2 + · have hl' : i=2*l+1 := by omega + rw [hl',indexWord_odd,show 2*k+1-(2*l+1)=2*(k-l) by ring,indexWord_even] + calc + (rotation cs ^ k * cs.simple false) * (rotation cs ^ l * cs.simple false) = + rotation cs ^ k * (cs.simple false * rotation cs ^ l) * cs.simple false := by group + _ = rotation cs ^ k * (rotation cs ^ (-l) * cs.simple false) * cs.simple false := by + rw [simple_rotation_zpow] + _ = rotation cs ^ (k-l) := by + rw [← mul_assoc, mul_assoc (rotation cs ^ k * rotation cs ^ (-l)), + cs.simple_mul_simple_self, mul_one, ← zpow_add] + congr 1 + + theorem indexWord_label (cs : CoxeterSystem M W) {i j : ℤ} (h : Odd (i+j)) : + indexWord cs j * (indexWord cs i)⁻¹ = indexWord cs (i+j) := by + have he := indexWord_reflection_mul cs h i + rw [show i+j-i=j by omega] at he + rw [← he] + group + +end +end KLInvariance.Dihedral + +end + + +section + +/-! Actual degree-one splines in the ambient extended Tits realization. +They supply the interpolation factors needed for the relative rank-two model. -/ +namespace KLInvariance.TitsSpace +open Module +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] (cs : CoxeterSystem M W) + {σ : Type us} (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def linearPolynomial : Extended M →ₗ[ℝ] MvPolynomial σ ℝ := + (SymmetricAlgebra.equivMvPolynomial basis).toLinearMap.comp + (SymmetricAlgebra.ι ℝ (Extended M)) + + def orbitSpline (y : W) (v₀ : Extended M) (v : W) : MvPolynomial σ ℝ := + linearPolynomial basis (extendedAction M cs (v*y⁻¹) v₀ - v₀) + + theorem orbitSpline_self (y : W) (v₀ : Extended M) : orbitSpline cs basis y v₀ y = 0 := by + simp [orbitSpline] + + theorem orbitSpline_reflection {t : W} {a : I → ℝ} + (ha : Represents M cs t a) (y x : W) (v₀ : Extended M) : + linearPolynomial basis (embed M a) ∣ + orbitSpline cs basis y v₀ x - orbitSpline cs basis y v₀ (t*x) := by + let c := extendedForm M (embed M a) (extendedAction M cs (x*y⁻¹) v₀) + have heq : extendedAction M cs (t*x*y⁻¹) v₀ = + extendedAction M cs (x*y⁻¹) v₀ - c • embed M a := by + rw [mul_assoc,map_mul,LinearEquiv.mul_apply,ha.formula] + unfold orbitSpline + rw [← map_sub,heq] + have hv : (extendedAction M cs (x*y⁻¹) v₀ - v₀) - + (extendedAction M cs (x*y⁻¹) v₀ - c • embed M a - v₀) = c • embed M a := by abel + rw [hv,map_smul] + exact ⟨algebraMap ℝ (MvPolynomial σ ℝ) c, by simp [Algebra.smul_def,mul_comm]⟩ + + theorem exists_pair_vector {t r : W} {a d : I → ℝ} + (ha : Represents M cs t a) (hd : Represents M cs r d) (htr : t ≠ r) : + ∃ v₀ : Extended M, extendedForm M (embed M a) v₀ = -1 ∧ + extendedForm M (embed M d) v₀ = 0 := by + have hli := (ha.extended_independent_of_ne hd htr).map' + (extendedForm M) (extendedForm_spec M).2.1.ker_eq_bot + have hli' : LinearIndependent ℝ ![extendedForm M (embed M a), + extendedForm M (embed M d)] := by + convert hli using 1 + funext i + fin_cases i <;> rfl + obtain ⟨v₀,hv₀⟩ := ReflectionPlane.formPair_surjective _ _ hli' (-1,0) + exact ⟨v₀,congrArg Prod.fst hv₀,congrArg Prod.snd hv₀⟩ + + theorem orbitSpline_pair_factor {x y z t r : W} {a d : I → ℝ} + (ha : Represents M cs t a) (hd : Represents M cs r d) + (hxy : x*y⁻¹=t) (hzy : z*y⁻¹=r) (hxz : x ≠ z) : + ∃ v₀ : Extended M, + orbitSpline cs basis y v₀ x = linearPolynomial basis (embed M a) ∧ + orbitSpline cs basis y v₀ y = 0 ∧ orbitSpline cs basis y v₀ z = 0 := by + have htr : t ≠ r := by + intro he + apply hxz + exact mul_right_cancel (hxy.trans (he.trans hzy.symm)) + obtain ⟨v₀,hv₀a,hv₀d⟩ := exists_pair_vector cs ha hd htr + refine ⟨v₀,?_,orbitSpline_self cs basis y v₀,?_⟩ + · simp only [orbitSpline,hxy,ha.formula,hv₀a] + congr 1 + module + · simp only [orbitSpline,hzy,hd.formula,hv₀d,zero_smul,sub_zero,sub_self,map_zero] + + theorem orbitSpline_single_factor {x y t : W} {a : I → ℝ} + (ha : Represents M cs t a) (hxy : x*y⁻¹=t) : + ∃ v₀ : Extended M, + orbitSpline cs basis y v₀ x = linearPolynomial basis (embed M a) ∧ + orbitSpline cs basis y v₀ y = 0 := by + let v₀ : Extended M := (-1/2 : ℝ) • embed M a + have hv₀ : extendedForm M (embed M a) v₀ = -1 := by + simp only [v₀,map_smul,smul_eq_mul,embed,(extendedForm_spec M).2.2,ha.isRoot.norm] + norm_num + refine ⟨v₀,?_,orbitSpline_self cs basis y v₀⟩ + simp only [orbitSpline,hxy,ha.formula,hv₀] + congr 1 + module + +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Polynomial interpolation on an actual dihedral reflection subgroup. +The ambient realization, including all fixed directions and degenerate root +planes, is retained; no character theorem is assumed. -/ +namespace KLInvariance.Dihedral +open Module TitsSpace +universe u v w us +variable {H : Type w} [Group H] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N H) + {I : Type u} [Fintype I] {M : CoxeterMatrix I} {W : Type v} [Group W] + (cs : CoxeterSystem M W) (φ : H →* W) + (hφ : ∀ t, ds.IsReflection t → cs.IsReflection (φ t)) + {σ : Type us} (basis : Basis σ ℝ (Extended M)) +noncomputable section + + theorem reflection_of_parity {x y : H} (hp : ds.length x % 2 ≠ ds.length y % 2) : + ds.IsReflection (x*y⁻¹) := by + rw [reflection_iff_odd,Nat.odd_iff] + have h := ds.length_mul_mod_two x y⁻¹ + rw [ds.length_inv] at h + omega + + def oppositeExternal (x c : H) : Finset H := by + classical + exact (externalLower ds x c).filter (fun z => ds.length z % 2 ≠ ds.length x % 2) + + def sameExternal (x c : H) : Finset H := by + classical + exact (externalLower ds x c).filter (fun z => ds.length z % 2 = ds.length x % 2) + + theorem oppositeExternal_reflection {x c y : H} (hy : y ∈ oppositeExternal ds x c) : + ds.IsReflection (y*x⁻¹) := by + classical + exact reflection_of_parity ds (Finset.mem_filter.mp hy).2 + + def interpolationRoot (x c : H) (y : oppositeExternal ds x c) : PositiveRoot M cs := + positiveRoot M cs ⟨φ (y.val*x⁻¹), hφ _ (oppositeExternal_reflection ds y.property)⟩ + + theorem interpolation_exists (hφinj : Function.Injective φ) {x c : H} + (hxc : BruhatLE ds x c) : ∃ F : H → MvPolynomial σ ℝ, + (∀ t, ds.IsReflection t → ∀ (a : I → ℝ), Represents M cs (φ t) a → ∀ v, + linearPolynomial basis (embed M a) ∣ F v-F (t*v)) ∧ + F x = ∏ y : oppositeExternal ds x c, + linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x c y).val) ∧ + ∀ z, BruhatLE ds z c → ¬ BruhatLE ds z x → F z = 0 := by + classical + let Y := {y // y ∈ oppositeExternal ds x c} + let Z := {z // z ∈ sameExternal ds x c} + have hc : Fintype.card Z ≤ Fintype.card Y := by + change Fintype.card ↥(sameExternal ds x c) ≤ Fintype.card ↥(oppositeExternal ds x c) + rw [Fintype.card_coe,Fintype.card_coe] + exact external_parity_card_le ds hxc + obtain ⟨j⟩ := Function.Embedding.nonempty_of_card_le hc + have hfac (y : Y) : ∃ v₀ : Extended M, + orbitSpline cs basis (φ y.val) v₀ (φ x) = + linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x c y).val) ∧ + orbitSpline cs basis (φ y.val) v₀ (φ y.val) = 0 ∧ + ∀ z : Z, j z = y → orbitSpline cs basis (φ y.val) v₀ (φ z.val) = 0 := by + have ht := oppositeExternal_reflection ds y.property + have ha := positiveRoot_represents M cs + ⟨φ (y.val*x⁻¹),hφ _ ht⟩ + have hxy₀ : x*y.val⁻¹=y.val*x⁻¹ := by simpa only [mul_inv_rev,inv_inv] using ht.inv + have hxy : φ x*(φ y.val)⁻¹=φ (y.val*x⁻¹) := by + rw [← map_inv,← map_mul,hxy₀] + by_cases hex : ∃ z : Z, j z = y + · obtain ⟨z,hz⟩ := hex + have hzprop := Finset.mem_filter.mp z.property + have hyprop := Finset.mem_filter.mp y.property + have hr : ds.IsReflection (z.val*y.val⁻¹) := reflection_of_parity ds (by omega) + let d := positiveRoot M cs ⟨φ (z.val*y.val⁻¹),hφ _ hr⟩ + have hd : Represents M cs (φ (z.val*y.val⁻¹)) d.val := positiveRoot_represents M cs ⟨φ (z.val*y.val⁻¹),hφ _ hr⟩ + have hxz : φ x ≠ φ z.val := by + intro he + have he' := hφinj he + have hh := (mem_externalLower ds x c z.val).mp hzprop.1 + exact hh.2 (he' ▸ bruhat_refl ds x) + obtain ⟨v₀,ha',hy',hz0'⟩ := orbitSpline_pair_factor cs basis ha hd hxy + (by rw [map_mul,map_inv]) hxz + refine ⟨v₀,ha',hy',?_⟩ + intro z' hz' + have he := j.injective (hz'.trans hz.symm) + simpa only [he] using hz0' + · obtain ⟨v₀,ha',hy'⟩ := orbitSpline_single_factor cs basis ha hxy + exact ⟨v₀,ha',hy',fun z hz => (hex ⟨z,hz⟩).elim⟩ + choose v₀ hv₀ hy₀ hz₀ using hfac + let F : H → MvPolynomial σ ℝ := fun v => ∏ y : Y, + orbitSpline cs basis (φ y.val) (v₀ y) (φ v) + refine ⟨F,?_,?_,?_⟩ + · intro t _ht a ha v + apply Ideal.mem_span_singleton.mp + apply Ideal.Quotient.eq.mp + change Ideal.Quotient.mk _ (∏ y : Y, orbitSpline cs basis (φ y.val) (v₀ y) (φ v)) = + Ideal.Quotient.mk _ (∏ y : Y, orbitSpline cs basis (φ y.val) (v₀ y) (φ (t*v))) + simp only [map_prod] + apply Finset.prod_congr rfl + intro y _ + apply Ideal.Quotient.eq.mpr + apply Ideal.mem_span_singleton.mpr + rw [map_mul] + exact orbitSpline_reflection cs basis ha _ _ _ + · exact Finset.prod_congr rfl (fun y _ => hv₀ y) + · intro z hzc hzx + have hz : z ∈ externalLower ds x c := (mem_externalLower ds x c z).mpr ⟨hzc,hzx⟩ + by_cases hp : ds.length z % 2 = ds.length x % 2 + · let z' : Z := ⟨z,Finset.mem_filter.mpr ⟨hz,hp⟩⟩ + exact Finset.prod_eq_zero (Finset.mem_univ (j z')) (hz₀ (j z') z' rfl) + · let y : Y := ⟨z,Finset.mem_filter.mpr ⟨hz,hp⟩⟩ + exact Finset.prod_eq_zero (Finset.mem_univ y) (hy₀ y) + +end +end KLInvariance.Dihedral + +end + + +section + +/-! An elementary flabbiness criterion for the exact rank-one model. Flow-down +sections with the genuine product of outgoing labels suffice. The pairwise +relative-primality condition will be instantiated by actual root labels. -/ +namespace KLInvariance.MomentGraph.Sheaf +universe ur uv ue +variable {R : Type ur} [CommRing R] [DecompositionMonoid R] + {V : Type uv} [PartialOrder V] {E : Type ue} + (G : OrderedGraph V E) (α : E → R) (c : V) +noncomputable section +variable [Fintype E] [DecidableEq V] + +def modelOutgoing (x : V) : Finset E := by + classical + exact Finset.univ.filter (fun e => G.source e = x ∧ G.target e ≤ c) + +@[simp] theorem mem_modelOutgoing (x : V) (e : E) : + e ∈ modelOutgoing G c x ↔ G.source e = x ∧ G.target e ≤ c := by + classical + simp [modelOutgoing] + +def modelProduct (x : V) : R := ∏ e ∈ modelOutgoing G c x, α e + +def HasFlowDown : Prop := + ∀ x, x ≤ c → ∃ f : (structureSheaf G α c).Assignment, + (structureSheaf G α c).IsGlobal f ∧ + (∀ h : PLift (x ≤ c), f x h = modelProduct G α c x) ∧ + (∀ y, ¬ y ≤ x → f y = 0) + +omit [DecompositionMonoid R] [Fintype E] [DecidableEq V] in + theorem structureCompatible_iff (Ω : Set V) (f : (structureSheaf G α c).Assignment) : + (structureSheaf G α c).CompatibleOn Ω f ↔ + ∀ e, G.source e ∈ Ω → G.target e ∈ Ω → ∀ h : PLift (G.target e ≤ c), + α e ∣ f (G.source e) ⟨(G.increasing e).le.trans h.down⟩ - f (G.target e) h := by + constructor + · intro hf e hs ht h + exact Ideal.mem_span_singleton.mp + (Ideal.Quotient.eq.mp (congrFun (hf e hs ht) h)) + · intro hf e hs ht + funext h + exact Ideal.Quotient.eq.mpr (Ideal.mem_span_singleton.mpr (hf e hs ht h)) + +include G α c in + theorem flowDown_flabby [Finite V] + (hrel : ∀ x, (modelOutgoing G c x : Set E).Pairwise (Function.onFun IsRelPrime α)) + (hflow : HasFlowDown G α c) : (structureSheaf G α c).Flabby := by + classical + let B := structureSheaf G α c + let : Fintype V := Fintype.ofFinite V + suffices hh : ∀ s : Finset V, IsUpperSet (s : Set V) → + ∀ f : B.Assignment, B.CompatibleOn (s : Set V) f → + ∃ g : B.Assignment, B.IsGlobal g ∧ ∀ x ∈ s, g x = f x by + intro Ω hΩ f hf + have hset : (↑(Finset.univ.filter (· ∈ Ω)) : Set V) = Ω := by ext x; simp + obtain ⟨g,hg,hgf⟩ := hh (Finset.univ.filter (· ∈ Ω)) (by rwa [hset]) f (by rwa [hset]) + exact ⟨g,hg,fun x hx => hgf x (by simpa using hx)⟩ + intro s + refine Finset.strongInductionOn s ?_ + intro s ih hs f hf + by_cases hempty : s = ∅ + · subst s + refine ⟨0,?_,by simp⟩ + exact (B.sections Set.univ).zero_mem + obtain ⟨a,ha,hmin⟩ := s.exists_minimal (Finset.nonempty_iff_ne_empty.mpr hempty) + have hu : IsUpperSet (↑(s.erase a) : Set V) := by + intro x y hxy hx + have hx' := Finset.mem_erase.mp hx + refine Finset.mem_erase.mpr ⟨?_,hs hxy hx'.2⟩ + intro hya + subst y + exact hx'.1 (le_antisymm hxy (hmin hx'.2 hxy)) + obtain ⟨g,hg,hgf⟩ := ih (s.erase a) (Finset.erase_ssubset ha) hu f + (fun e he ht => hf e (Finset.mem_of_mem_erase he) (Finset.mem_of_mem_erase ht)) + by_cases hac : a ≤ c + · obtain ⟨t,ht,hta,htzero⟩ := hflow a hac + have hdiv : modelProduct G α c a ∣ f a ⟨hac⟩ - g a ⟨hac⟩ := by + apply Finset.prod_dvd_of_isRelPrime (hrel a) + intro e he + obtain ⟨hea,hec⟩ := (mem_modelOutgoing G c a e).mp he + have hsource : G.source e ∈ s := hea ▸ ha + have htarget : G.target e ∈ s.erase a := Finset.mem_erase.mpr + ⟨by simpa [← hea] using (G.increasing e).ne',hs (G.increasing e).le hsource⟩ + have hf' := (structureCompatible_iff G α c (s : Set V) f).mp hf e hsource + (Finset.mem_of_mem_erase htarget) ⟨hec⟩ + have hg' := (structureCompatible_iff G α c Set.univ g).mp hg e + (Set.mem_univ _) (Set.mem_univ _) ⟨hec⟩ + rw [hgf _ htarget] at hg' + have hd := dvd_sub hf' hg' + rw [sub_sub_sub_cancel_right] at hd + subst a + exact hd + obtain ⟨r,hr⟩ := hdiv + refine ⟨g+r • t,(B.sections Set.univ).add_mem hg + ((B.sections Set.univ).smul_mem r ht),?_⟩ + intro x hx + by_cases hxa : x = a + · subst x + funext h + change g a h + r * t a h = f a h + rw [hta h] + change f a h - g a h = modelProduct G α c a * r at hr + linear_combination -hr + · have hnot : ¬ x ≤ a := fun h => hxa (le_antisymm h (hmin hx h)) + have ht0 := htzero x hnot + change g x + r • t x = f x + rw [ht0,smul_zero,add_zero] + exact hgf x (Finset.mem_erase.mpr ⟨hxa,hx⟩) + · refine ⟨g,hg,?_⟩ + intro x hx + by_cases hxa : x = a + · subst x + let := structureSheaf_support G α c a hac + exact Subsingleton.elim _ _ + · exact hgf x (Finset.mem_erase.mpr ⟨hxa,hx⟩) + +end +end KLInvariance.MomentGraph.Sheaf + +end + + +section + +/-! Flabbiness of the exact rank-one model with ambient labels, proved by +interpolation rather than an assumed character theorem. -/ +namespace KLInvariance.Dihedral +open Module TitsSpace BruhatGraph MomentGraph MomentGraph.Sheaf +universe u v w us +variable {H : Type w} [Group H] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N H) + {I : Type u} [Fintype I] {M : CoxeterMatrix I} {W : Type v} [Group W] + (cs : CoxeterSystem M W) (φ : H →* W) + (hφ : ∀ t, ds.IsReflection t → cs.IsReflection (φ t)) + {σ : Type us} (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def inducedRoot (b : H) (e : Edge ds 1 b) : PositiveRoot M cs := + positiveRoot M cs ⟨φ (label ds 1 b e),hφ _ (label_isReflection ds 1 b e)⟩ + + def inducedLabel (b : H) (e : Edge ds 1 b) : MvPolynomial σ ℝ := + linearPolynomial basis (embed M (inducedRoot ds cs φ hφ b e).val) + + theorem external_step {x c y : H} (hy : y ∈ oppositeExternal ds x c) : + BruhatStep ds x y := by + classical + obtain ⟨hm,hp⟩ := Finset.mem_filter.mp hy + obtain ⟨_,hn⟩ := (mem_externalLower ds x c y).mp hm + have hl : ds.length x < ds.length y := by + have hh : ¬ ds.length y < ds.length x := fun h => hn (shorter_bruhat ds h) + omega + exact ⟨hl,y*x⁻¹,oppositeExternal_reflection ds hy,by group⟩ + + theorem step_external {x c y : H} (hy : BruhatStep ds x y) (hyc : BruhatLE ds y c) : + y ∈ oppositeExternal ds x c := by + classical + refine Finset.mem_filter.mpr ⟨(mem_externalLower ds x c y).mpr ⟨hyc,?_⟩,?_⟩ + · exact fun h => (length_le_of_bruhat ds h).not_gt hy.1 + · have hh := (step_iff_odd ds x y).mp hy + rw [Nat.odd_iff] at hh + omega + + variable (b : H) [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] + + def externalEdge (x c : Interval ds 1 b) (y : oppositeExternal ds x.val c.val) : Edge ds 1 b := + ⟨(x,⟨y.val,one_bruhat ds y.val, + bruhat_trans ds ((mem_externalLower ds x.val c.val y.val).mp + (Finset.mem_filter.mp y.property).1).1 c.property.2⟩),external_step ds y.property⟩ + + theorem externalEdge_mem (x c : Interval ds 1 b) (y : oppositeExternal ds x.val c.val) : + externalEdge ds b x c y ∈ modelOutgoing (graph ds 1 b) c x := by + classical + apply (mem_modelOutgoing _ _ _ _).mpr + exact ⟨rfl,((mem_externalLower ds x.val c.val y.val).mp + (Finset.mem_filter.mp y.property).1).1⟩ + + def outgoingEquiv (x c : Interval ds 1 b) : + ↥(oppositeExternal ds x.val c.val) ≃ ↥(modelOutgoing (graph ds 1 b) c x) where + toFun y := ⟨externalEdge ds b x c y,externalEdge_mem ds b x c y⟩ + invFun e := ⟨(target ds 1 b e.val).val,by + obtain ⟨hs,ht⟩ := (mem_modelOutgoing _ _ _ _).mp e.property + have hh := e.val.property + change BruhatStep ds (source ds 1 b e.val).val (target ds 1 b e.val).val at hh + change source ds 1 b e.val = x at hs + rw [hs] at hh + exact step_external ds hh ht⟩ + left_inv _ := rfl + right_inv e := by + apply Subtype.ext + apply Subtype.ext + apply Prod.ext + · exact ((mem_modelOutgoing _ _ _ _).mp e.property).1.symm + · rfl + + theorem interpolation_product (x c : Interval ds 1 b) : + (∏ y : oppositeExternal ds x.val c.val, + linearPolynomial basis (embed M (interpolationRoot ds cs φ hφ x.val c.val y).val)) = + modelProduct (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c x := by + classical + calc + _ = ∏ e : ↥(modelOutgoing (graph ds 1 b) c x), inducedLabel ds cs φ hφ basis b e.val := + (outgoingEquiv ds b x c).prod_comp _ + _ = _ := Finset.prod_coe_sort _ _ + + theorem hasFlowDown (hφinj : Function.Injective φ) (c : Interval ds 1 b) : + HasFlowDown (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c := by + classical + intro x hxc + obtain ⟨F,hF,hFx,hFzero⟩ := interpolation_exists ds cs φ hφ basis hφinj hxc + let f : (structureSheaf (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c).Assignment := + fun v _ => F v.val + refine ⟨f,?_,?_,?_⟩ + · apply (structureCompatible_iff _ _ _ _ _).mpr + intro e _ _ h + have hdiv := hF (label ds 1 b e) (label_isReflection ds 1 b e) + (inducedRoot ds cs φ hφ b e).val (positiveRoot_represents M cs + ⟨φ (label ds 1 b e),hφ _ (label_isReflection ds 1 b e)⟩) + (source ds 1 b e).val + rw [label_mul_source] at hdiv + exact hdiv + · intro _ + exact hFx.trans (interpolation_product ds cs φ hφ basis b x c) + · intro y hy + funext h + exact hFzero y.val h.down hy + +omit [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] in + theorem inducedLabel_prime (e : Edge ds 1 b) : Prime (inducedLabel ds cs φ hφ basis b e) := by + apply (MulEquiv.prime_iff (SymmetricAlgebra.equivMvPolynomial basis)).mpr + apply EdgeAlgebra.symmetric_ι_prime + intro h + exact (inducedRoot ds cs φ hφ b e).property.1.ne_zero (congrArg Prod.fst h) + +omit [Fintype (Edge ds 1 b)] [DecidableEq (Interval ds 1 b)] in + theorem label_eq_of_induced_dvd (hφinj : Function.Injective φ) {e f : Edge ds 1 b} + (h : inducedLabel ds cs φ hφ basis b e ∣ inducedLabel ds cs φ hφ basis b f) : + label ds 1 b e = label ds 1 b f := by + apply hφinj + suffices he : inducedRoot ds cs φ hφ b e = inducedRoot ds cs φ hφ b f from + congrArg Subtype.val ((positiveRootEquiv M cs).injective he) + by_contra hn + have hd : SymmetricAlgebra.ι ℝ (Extended M) (embed M (inducedRoot ds cs φ hφ b e).val) ∣ + SymmetricAlgebra.ι ℝ (Extended M) (embed M (inducedRoot ds cs φ hφ b f).val) := by + obtain ⟨z,hz⟩ := h + exact ⟨(SymmetricAlgebra.equivMvPolynomial basis).symm z,by + apply (SymmetricAlgebra.equivMvPolynomial basis).injective + simpa only [map_mul,AlgEquiv.apply_symm_apply,inducedLabel,linearPolynomial,LinearMap.comp_apply,AlgEquiv.toLinearMap_apply] using hz⟩ + obtain ⟨r,hr⟩ := Submodule.mem_span_singleton.mp ((EdgeAlgebra.symmetric_ι_dvd_iff _ _).mp hd) + have he : r • (inducedRoot ds cs φ hφ b e).val = (1:ℝ) • (inducedRoot ds cs φ hφ b f).val := by + have hh := congrArg Prod.fst hr + exact hh.trans (one_smul ℝ _).symm + exact one_ne_zero ((positiveRoots_independent _ _ hn).eq_zero_of_pair' he).2 + + theorem model_flabby (hφinj : Function.Injective φ) (c : Interval ds 1 b) : + (structureSheaf (graph ds 1 b) (inducedLabel ds cs φ hφ basis b) c).Flabby := by + classical + let : Finite (Interval ds 1 b) := interval_finite ds 1 b + apply flowDown_flabby + · intro x e he f hf hne + apply ((inducedLabel_prime ds cs φ hφ basis b e).irreducible.isRelPrime_iff_not_dvd).mpr + intro hdiv + apply hne + apply eq_of_label_source_eq ds 1 b (label_eq_of_induced_dvd ds cs φ hφ basis b hφinj hdiv) + exact ((mem_modelOutgoing _ _ _ _).mp he).1.trans ((mem_modelOutgoing _ _ _ _).mp hf).1.symm + · exact hasFlowDown ds cs φ hφ basis b hφinj c + +end +end KLInvariance.Dihedral + +end + + +section + +/-! Instantiation on the actual maximal subgroup of the ambient root plane. +The exact canonical roots, including degenerate/infinite planes, are used. -/ +namespace KLInvariance.TitsSpace.PlaneBasis +open Module BruhatGraph MomentGraph MomentGraph.Sheaf +universe u v us +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] {cs : CoxeterSystem M W} + {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) + {σ : Type us} (basis : Basis σ ℝ (Extended M)) +noncomputable section + + def modelLabel (b : planeSubgroup M cs P) (e : Edge B.system 1 b) : MvPolynomial σ ℝ := + Dihedral.inducedLabel B.system cs (planeSubgroup M cs P).subtype + (fun t => (B.reflection_iff t).mp) basis b e + + theorem model_flabby (b : planeSubgroup M cs P) [Fintype (Edge B.system 1 b)] + [DecidableEq (Interval B.system 1 b)] (c : Interval B.system 1 b) : + (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).Flabby := + Dihedral.model_flabby B.system cs (planeSubgroup M cs P).subtype + (fun t => (B.reflection_iff t).mp) basis b Subtype.val_injective c + + theorem model_generated (b : planeSubgroup M cs P) (c : Interval B.system 1 b) : + (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).Generated := + structureSheaf_generated _ _ _ + + theorem model_quotient (b : planeSubgroup M cs P) (c : Interval B.system 1 b) : + (structureSheaf (graph B.system 1 b) (B.modelLabel basis b) c).UpperQuotient + (B.modelLabel basis b) := structureSheaf_upperQuotient _ _ _ + +end +end KLInvariance.TitsSpace.PlaneBasis + +end + + +section + +/-! Each finite rank-two set fits in a principal Bruhat interval, even in +an infinite dihedral group. No finite Coxeter-system hypothesis is used. -/ +namespace KLInvariance +universe u v +variable {I : Type u} {M : CoxeterMatrix I} {W : Type v} [Group W] + + theorem bruhat_top_of_all_descents (cs : CoxeterSystem M W) (w : W) + (hw : ∀ i, cs.length (cs.simple i * w) < cs.length w) (x : W) : + BruhatLE cs x w := by + classical + have hword : ∀ ω, BruhatLE cs (cs.wordProd ω) w := by + intro ω + induction ω with + | nil => simpa only [cs.wordProd_nil] using one_bruhat cs w + | cons i ω ih => + have hu := upperSimple_mono cs i ih + have hz := le_upperSimple cs i (cs.simple i * cs.wordProd ω) + rw [upperSimple_mul] at hz + have he : upperSimple cs i w = w := by simp only [upperSimple,ite_eq_left (hw i)] + rw [he] at hu + change BruhatLE cs (cs.simple i * cs.wordProd ω) w + exact hz.trans hu + obtain ⟨ω,_,hx⟩ := cs.exists_isReduced x + rw [hx] + exact hword ω + +namespace Dihedral +variable {N : CoxeterMatrix Bool} (ds : CoxeterSystem N W) + + theorem exists_common_upper (s : Finset W) : ∃ b, ∀ x ∈ s, BruhatLE ds x b := by + classical + by_cases hb : BddAbove (Set.range ds.length) + · have hf : (Set.range ds.length).Finite := hb.finite + obtain ⟨b,hb⟩ := (Set.range_nonempty ds.length).csSup_mem hf + have hmax (x : W) : ds.length x ≤ ds.length b := by + rw [hb] + exact le_csSup (hf.bddAbove) (Set.mem_range_self x) + refine ⟨b,fun x _ => bruhat_top_of_all_descents ds b ?_ x⟩ + intro i + have hle := hmax (ds.simple i*b) + have hne := ds.length_simple_mul b i + omega + · have hn : ∀ n : ℕ, ∃ w, n < ds.length w := by + intro n + by_contra h + push Not at h + exact hb ⟨n,by rintro m ⟨x,rfl⟩; exact h x⟩ + obtain ⟨b,hb⟩ := hn (s.sup ds.length) + exact ⟨b,fun x hx => shorter_bruhat ds ((Finset.le_sup hx).trans_lt hb)⟩ + +end Dihedral +end KLInvariance + +end + + +section + +namespace KLInvariance.Dihedral +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +noncomputable section + + theorem map_not_alt (i : Bool) (n : ℕ) : (alt i n).map Bool.not = alt (!i) n := by + induction n generalizing i with + | zero => rfl + | succ n ih => rw [alt_succ,List.map_cons,ih,alt_succ] + + theorem swap_alt (cs : CoxeterSystem M W) (i : Bool) (n : ℕ) : + swap cs (cs.wordProd (alt i n)) = cs.wordProd (alt (!i) n) := by + rw [swap_wordProd,map_not_alt] + + theorem length_alt_le_length (cs : CoxeterSystem M W) (i : Bool) {n : ℕ} {w : W} + (h : n ≤ cs.length w) : cs.length (cs.wordProd (alt i n)) = n := by + obtain ⟨j,hj⟩ := exists_alt cs w + have hr : cs.IsReduced (alt j (cs.length w)) := by + change cs.length (cs.wordProd _) = _ + rw [← hj,length_alt] + have hn := (reduced_alt_take cs hr h).eq + rw [length_alt] at hn + have hi : i=j ∨ i=(!j) := by cases i <;> cases j <;> simp + rcases hi with rfl|rfl + · exact hn + · rw [← swap_alt,length_swap,hn] + + theorem length_indexWord_nat (cs : CoxeterSystem M W) {n : ℕ} {w : W} + (h : n ≤ cs.length w) : cs.length (indexWord cs n) = n := by + rw [indexWord_nat] + exact length_alt_le_length cs false h + + theorem length_indexWord_neg_nat (cs : CoxeterSystem M W) {n : ℕ} {w : W} + (h : n ≤ cs.length w) : cs.length (indexWord cs (-(n:ℤ))) = n := by + rw [indexWord_neg_nat] + exact length_alt_le_length cs true h + + theorem length_indexWord (cs : CoxeterSystem M W) {i : ℤ} {w : W} + (h : i.natAbs ≤ cs.length w) : cs.length (indexWord cs i) = i.natAbs := by + obtain hi|hi := le_total 0 i + · have he : i=(i.natAbs:ℤ) := by rw [Int.natCast_natAbs,abs_of_nonneg hi] + nth_rw 1 [he] + exact length_indexWord_nat cs h + · have he : i= -(i.natAbs:ℤ) := by rw [Int.natCast_natAbs,abs_of_nonpos hi,neg_neg] + nth_rw 1 [he] + exact length_indexWord_neg_nat cs h + + theorem leftDescent_alt (cs : CoxeterSystem M W) (i : Bool) {n : ℕ} {w : W} + (hn : 0 geometricSlope (B.prefixRoot w n)) (Set.Iio (B.system.length w)) := by + apply strictMonoOn_of_lt_succ Set.ordConnected_Iio + intro n _ hn hn' + change n < B.system.length w at hn + change n+1 < B.system.length w at hn' + change geometricSlope (B.prefixRoot w n) < geometricSlope (B.prefixRoot w (n+1)) + rw [prefixRoot,prefixRoot,dite_eq_left hn,dite_eq_left hn'] + apply (B.edgeRoot_slopes_iff _ _).mpr + rw [indexWord_nat] + exact leftDescent_alt B.system false (by omega) hn'.le + + theorem negPrefixRoot_strictAnti (w : planeSubgroup M cs P) : + StrictAntiOn (fun n => geometricSlope (B.negPrefixRoot w n)) + (Set.Iio (B.system.length w)) := by + apply strictAntiOn_of_succ_lt Set.ordConnected_Iio + intro n _ hn hn' + change n < B.system.length w at hn + change n+1 < B.system.length w at hn' + change geometricSlope (B.negPrefixRoot w (n+1)) < geometricSlope (B.negPrefixRoot w n) + rw [negPrefixRoot,negPrefixRoot,dite_eq_left hn,dite_eq_left hn'] + have ht : B.system.IsLeftDescent (indexWord B.system (-((n+1:ℕ):ℤ))) true := by + rw [indexWord_neg_nat] + exact leftDescent_alt B.system true (by omega) hn'.le + have hlen := length_indexWord_neg_nat B.system hn'.le + have hu := unique_leftDescent B.system (w := indexWord B.system (-((n+1:ℕ):ℤ))) + (z := w) (by rw [hlen]; omega) (by rw [hlen]; omega) + have hf : ¬B.system.IsLeftDescent (indexWord B.system (-((n+1:ℕ):ℤ))) false := by + intro hf + obtain ⟨i,_,hi⟩ := hu + have h1 := hi true ht + have h2 := hi false hf + simp_all + have hnlt := (B.edgeRoot_slopes_iff (neg_indexWord_step B.system hn) + (neg_indexWord_step B.system hn')).not.mpr hf + apply lt_of_le_of_ne (le_of_not_gt hnlt) + intro he + have he' := geometricSlope_injective he + exact graphRoot_ne_of_path + ((B.bruhatStep_iff _ _).mpr (neg_indexWord_step B.system hn)) + ((B.bruhatStep_iff _ _).mpr (neg_indexWord_step B.system hn')) he'.symm + + theorem edgeRoot_eq_of_label {x y z w : planeSubgroup M cs P} + (hxy : BruhatStep B.system x y) (hzw : BruhatStep B.system z w) + (he : y*x⁻¹=w*z⁻¹) : B.edgeRoot hxy = B.edgeRoot hzw := by + unfold edgeRoot graphRoot + apply congrArg (positiveRoot M cs) + apply Subtype.ext + exact congrArg (fun z : planeSubgroup M cs P => (z : W)) he + + theorem prefixRoot_eq_edgeRoot {x y w : planeSubgroup M cs P} + (hxy : BruhatStep B.system x y) {n : ℕ} (hn : n omega + · rw [abs_of_nonpos hzs, abs_lt] at hz + dsimp [Before] + split_ifs <;> omega + · rw [abs_of_nonpos hjs, abs_lt] at hi + obtain hzs | hzs := le_total 0 z + · rw [abs_of_nonneg hzs, abs_lt] at hz + dsimp [Before] + split_ifs <;> omega + · rw [abs_of_nonpos hzs, abs_lt] at hz + dsimp [Before] + split_ifs <;> omega + + theorem finite_before_next {m i j z : ℤ} (hm : 0 < m) + (hi : |i| < |j|) (hz : |j| < |z|) + (hzM : -m < z ∧ z ≤ m) : + (i+j) % (2*m) < (j+z) % (2*m) ↔ Before (i+j) (j+z) := by + have hzabs : |z| ≤ m := abs_le.mpr (by omega) + have hjabs := abs_lt.mp (hz.trans_le hzabs) + have hiabs := abs_lt.mp ((hi.trans hz).trans_le hzabs) + rw [midpoint_mod hm (by omega) (by omega), midpoint_mod hm (by omega) (by omega)] + obtain hjs | hjs := le_total 0 j + · rw [abs_of_nonneg hjs, abs_lt] at hi + obtain hzs | hzs := le_total 0 z + · rw [abs_of_nonneg hjs, abs_of_nonneg hzs] at hz + dsimp [Before] + split_ifs <;> omega + · rw [abs_of_nonneg hjs, abs_of_nonpos hzs] at hz + dsimp [Before] + split_ifs <;> omega + · rw [abs_of_nonpos hjs, abs_lt] at hi + obtain hzs | hzs := le_total 0 z + · rw [abs_of_nonpos hjs, abs_of_nonneg hzs] at hz + dsimp [Before] + split_ifs <;> omega + · rw [abs_of_nonpos hjs, abs_of_nonpos hzs] at hz + dsimp [Before] + split_ifs <;> omega + + theorem eligible_ranks_card (L k : ℕ) : + ((Finset.range (L+2*k+1)).filter (fun r => L < r ∧ Odd (L+r))).card = k := by + classical + have hc : (Finset.range k).card = + ((Finset.range (L+2*k+1)).filter (fun r => L < r ∧ Odd (L+r))).card := by + apply Finset.card_bij (fun a _ => L+1+2*a) + · intro a ha + simp only [Finset.mem_range, Finset.mem_filter, Nat.odd_iff] at ha ⊢ + omega + · intro a ha b hb he + omega + · intro b hb + simp only [Finset.mem_range, Finset.mem_filter, Nat.odd_iff] at hb + refine ⟨(b-L-1)/2, ?_, ?_⟩ + · simp only [Finset.mem_range] + omega + · omega + simpa only [Finset.card_range] using hc.symm + + noncomputable def arrowAfter (a label z : ℤ) : ℕ := + if |a| < |z| ∧ Odd (a+z) ∧ Before label (a+z) then 1 else 0 + +/-- Double internal ranks and the singleton top, with no singleton bottom +term because upward arrows never end at the bottom. -/ + noncomputable def countAfter (a label c : ℤ) : ℕ := + (∑ r ∈ Finset.range c.natAbs, (arrowAfter a label r + arrowAfter a label (-r))) + + arrowAfter a label c + + theorem arrowAfter_of_not_lt {a label z : ℤ} (h : ¬ |a| < |z|) : + arrowAfter a label z = 0 := by simp [arrowAfter,h] + + theorem arrowAfter_self (i j : ℤ) : arrowAfter i (i+j) j = 0 := by + have hb : ¬ Before (i+j) (i+j) := by + dsimp [Before] + omega + simp only [arrowAfter, hb, and_false, ite_false] + +end +end KLInvariance.SignedDihedral + +end + + +section + +namespace KLInvariance.Dihedral +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} + + theorem length_indexWord_unbounded (cs : CoxeterSystem M W) + (hu : ∀ n : ℕ, ∃ w, n ≤ cs.length w) (i : ℤ) : + cs.length (indexWord cs i) = i.natAbs := by + obtain ⟨w,hw⟩ := hu i.natAbs + exact length_indexWord cs hw + +end KLInvariance.Dihedral + +namespace KLInvariance.TitsSpace.PlaneBasis +open KLInvariance.Dihedral +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] {cs : CoxeterSystem M W} + {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) +noncomputable section + + theorem edgeRoot_inverted_iff {x y : planeSubgroup M cs P} + (hxy : BruhatStep B.system x y) (w : planeSubgroup M cs P) : + rootInverted (w:W) (B.edgeRoot hxy) ↔ B.system.length ((y*x⁻¹)*w) by simp + have hl : rootInverted (w:W) B.left := by + have hh := (B.simpleRoot_inverted_coset_iff hm w false).mpr hd + simpa only [mul_one,simpleRoot,Bool.false_eq_true,↓reduceIte] using hh + exact B.slope_lt_of_inverted_left (w:W) hl _ _ (B.edgeRoot_plane hxy) + (B.edgeRoot_plane hzt) hi hn + +/-- The two angular rays of an infinite canonical dihedral subsystem, with +actual ambient labels, have precisely the source's signed-midpoint order. -/ + theorem edgeRoot_infinite_order + (hu : ∀ n : ℕ, ∃ w, n ≤ B.system.length w) + {x y z t : planeSubgroup M cs P} + (hxy : BruhatStep B.system x y) (hzt : BruhatStep B.system z t) + {a b : ℤ} (ha : Odd a) (hb : Odd b) + (hx : y*x⁻¹=indexWord B.system a) (hz : t*z⁻¹=indexWord B.system b) : + geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hzt) ↔ + SignedDihedral.Before a b := by + have repr (q : ℤ) (hq : Odd q) : + ∃ k : ℕ, q=2*(k:ℤ)+1 ∨ q= -(2*(k:ℤ)+1) := by + have habs := Int.natCast_natAbs q + have ho : q.natAbs % 2=1 := by + rw [Int.odd_iff] at hq + rcases le_total 0 q with h|h + · rw [abs_of_nonneg h] at habs + omega + · rw [abs_of_nonpos h] at habs + omega + refine ⟨q.natAbs/2,?_⟩ + rcases le_total 0 q with h|h + · left + rw [abs_of_nonneg h] at habs + omega + · right + rw [abs_of_nonpos h] at habs + omega + obtain ⟨k,hk|hk⟩ := repr a ha <;> obtain ⟨l,hl|hl⟩ := repr b hb + · obtain ⟨w,hw⟩ := hu (max k l+1) + have hk' : k omega + +/-- The actual ambient angular order in a finite canonical plane subsystem +is the increasing residue order on odd doubled midpoints. -/ + theorem edgeRoot_finite_order + (w : planeSubgroup M cs P) (hmax : ∀ z, B.system.length z ≤ B.system.length w) + {x y z t : planeSubgroup M cs P} + (hxy : BruhatStep B.system x y) (hzt : BruhatStep B.system z t) + {a b : ℤ} (ha : Odd a) (hb : Odd b) + (hx : y*x⁻¹=indexWord B.system a) (hz : t*z⁻¹=indexWord B.system b) : + geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hzt) ↔ + a % (2*(B.system.length w:ℤ)) < b % (2*(B.system.length w:ℤ)) := by + obtain ⟨k,hk,he⟩ := odd_residue_repr (B.max_length_pos w hmax) ha + obtain ⟨l,hl,hf⟩ := odd_residue_repr (B.max_length_pos w hmax) hb + have hp := rotation_pow_max B.system w hmax + rw [← indexWord_mod_period B.system hp a, he] at hx + rw [← indexWord_mod_period B.system hp b, hf] at hz + rw [← B.prefixRoot_eq_edgeRoot hxy hk hx,← B.prefixRoot_eq_edgeRoot hzt hl hz] + rw [(B.prefixRoot_strictMono w).lt_iff_lt hk hl,he,hf] + omega + +end +end KLInvariance.TitsSpace.PlaneBasis + +end + + +section + +namespace KLInvariance.Dihedral +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +noncomputable section +local instance : DecidableEq W := Classical.decEq W + + theorem indexWord_pos_ne_neg (cs : CoxeterSystem M W) {n : ℕ} {w : W} + (hn : 0 cs.length z=n) = + {indexWord cs n,indexWord cs (-(n:ℤ))} := by + classical + ext z + simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_insert,Finset.mem_singleton] + constructor + · intro hz + obtain ⟨i,hi⟩ := exists_alt cs z + rw [hz.2] at hi + cases i + · exact Or.inl (hi.trans (indexWord_nat cs n).symm) + · exact Or.inr (hi.trans (indexWord_neg_nat cs n).symm) + · rintro (rfl|rfl) + · have hl := length_indexWord_nat cs hc.le + exact ⟨shorter_bruhat cs (by rw [hl]; exact hc),hl⟩ + · have hl := length_indexWord_neg_nat cs hc.le + exact ⟨shorter_bruhat cs (by rw [hl]; exact hc),hl⟩ + + theorem lower_zero_fiber (cs : CoxeterSystem M W) (c : W) : + (lowerFinset cs c).filter (fun z => cs.length z=0) = {1} := by + classical + ext z + simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_singleton] + constructor + · exact fun hz => cs.length_eq_zero_iff.mp hz.2 + · rintro rfl + exact ⟨one_bruhat cs c,cs.length_one⟩ + + theorem lower_top_fiber (cs : CoxeterSystem M W) (c : W) : + (lowerFinset cs c).filter (fun z => cs.length z=cs.length c) = {c} := by + classical + ext z + simp only [Finset.mem_filter,mem_lowerFinset,Finset.mem_singleton] + constructor + · intro hz + by_contra hne + have hl := length_lt_of_bruhat_ne cs hz.1 hne + omega + · rintro rfl + exact ⟨bruhat_refl cs _,rfl⟩ + +/-- Actual finite dihedral lower ideals have two internal alternating rays +and a singleton top. The doubled identity contributes zero. -/ + theorem sum_lower_signed (cs : CoxeterSystem M W) (c : W) + {A : Type*} [AddCommMonoid A] (f : W → A) (h1 : f 1=0) : + ∑ z ∈ lowerFinset cs c, f z = + (∑ n ∈ Finset.range (cs.length c), + (f (indexWord cs n)+f (indexWord cs (-(n:ℤ))))) + f c := by + classical + have hmap : ∀ z ∈ lowerFinset cs c, cs.length z ∈ Finset.range (cs.length c+1) := by + intro z hz + have hl := length_le_of_bruhat cs ((mem_lowerFinset cs c z).mp hz) + simp only [Finset.mem_range] + omega + rw [← Finset.sum_fiberwise_of_maps_to hmap f,Finset.sum_range_succ,lower_top_fiber, + Finset.sum_singleton] + congr 1 + apply Finset.sum_congr rfl + intro n hn + have hc := Finset.mem_range.mp hn + by_cases hz : n=0 + · subst n + rw [lower_zero_fiber] + simp only [Finset.sum_singleton,indexWord_nat,indexWord_neg_nat,alt_zero, + cs.wordProd_nil,h1,add_zero] + · rw [lower_length_fiber cs c hc, + Finset.sum_pair (indexWord_pos_ne_neg cs (by omega) hc)] + +end +end KLInvariance.Dihedral + +end + + +section + +namespace KLInvariance.Dihedral +variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} +noncomputable section + + def GoodIndex (cs : CoxeterSystem M W) (i : ℤ) : Prop := + ∀ w, (∀ z, cs.length z ≤ cs.length w) → -(cs.length w:ℤ) < i ∧ i ≤ (cs.length w:ℤ) + + theorem maximal_or_unbounded (cs : CoxeterSystem M W) : + (∃ w, ∀ z, cs.length z ≤ cs.length w) ∨ (∀ n : ℕ, ∃ w, n≤cs.length w) := by + by_cases hb : BddAbove (Set.range cs.length) + · have hf : (Set.range cs.length).Finite := hb.finite + obtain ⟨b,hb⟩ := (Set.range_nonempty cs.length).csSup_mem hf + left + refine ⟨b,fun z => ?_⟩ + rw [hb] + exact le_csSup hf.bddAbove (Set.mem_range_self z) + · right + intro n + by_contra h + push Not at h + exact hb ⟨n,by rintro m ⟨z,rfl⟩; exact (h z).le⟩ + + theorem max_length_positive (cs : CoxeterSystem M W) {w : W} + (hmax : ∀ z, cs.length z ≤ cs.length w) : 0 by + have h := hmax (cs.simple i*w) + have h' := cs.length_simple_mul w i + omega) z + by_contra hne + have hl := length_lt_of_bruhat_ne cs htop hne + omega + + theorem goodIndex_nat (cs : CoxeterSystem M W) {n : ℕ} {c : W} + (hc : n≤cs.length c) : GoodIndex cs (n:ℤ) := by + intro w hw + have h := hw c + have hp := max_length_positive cs hw + omega + + theorem goodIndex_neg_nat (cs : CoxeterSystem M W) {n : ℕ} {c : W} + (hc : n rfl + · simp only [arrowAfter, hir, hl, false_and, ite_false] + + theorem arrowAfter_next {i j : ℤ} (hij : |i| < |j|) (z : ℤ) : + arrowAfter j (i+j) z = + if j.natAbs < z.natAbs ∧ Odd (j.natAbs+z.natAbs) ∧ 0 < j then 1 else 0 := by + have hlt : |j| < |z| ↔ j.natAbs < z.natAbs := by + rw [← Int.natCast_natAbs j, ← Int.natCast_natAbs z, Nat.cast_lt] + have ho : Odd (j+z) ↔ Odd (j.natAbs+z.natAbs) := by + have hj := Int.natCast_natAbs j + have hz := Int.natCast_natAbs z + rw [Int.odd_iff,Nat.odd_iff] + rcases le_total 0 j with hj'|hj' <;> rcases le_total 0 z with hz'|hz' + · rw [abs_of_nonneg hj'] at hj + rw [abs_of_nonneg hz'] at hz + omega + · rw [abs_of_nonneg hj'] at hj + rw [abs_of_nonpos hz'] at hz + omega + · rw [abs_of_nonpos hj'] at hj + rw [abs_of_nonneg hz'] at hz + omega + · rw [abs_of_nonpos hj'] at hj + rw [abs_of_nonpos hz'] at hz + omega + by_cases h : |j| < |z| + · simp only [arrowAfter, before_next_source hij h, ho, hlt] + · have h' := hlt.not.mp h + simp only [arrowAfter,h,h',false_and,ite_false] + + theorem countAfter_base {i j : ℤ} (hij : |i| < |j|) + (ho : Odd (i.natAbs+j.natAbs)) : + countAfter i (i+j) j = (j.natAbs-i.natAbs-1)/2 := by + unfold countAfter + rw [arrowAfter_self,add_zero] + have hs : ∀ r ∈ Finset.range j.natAbs, + arrowAfter i (i+j) r + arrowAfter i (i+j) (-r) = + if i.natAbs < r ∧ Odd (i.natAbs+r) then 1 else 0 := by + intro r hr + have hr' := Finset.mem_range.mp hr + rw [arrowAfter_pos hij,arrowAfter_neg hij] + have hn : ¬ j.natAbs < r := by omega + simp only [hn,and_false,ite_false,zero_add,hr',or_true,and_true] + rw [Finset.sum_congr rfl hs, ← Finset.sum_filter, Finset.sum_const, + nsmul_eq_mul, mul_one] + have hh : i.natAbs < j.natAbs := by + rw [← Nat.cast_lt (α := ℤ),Int.natCast_natAbs,Int.natCast_natAbs] + exact hij + have he : j.natAbs = i.natAbs+2*((j.natAbs-i.natAbs-1)/2)+1 := by + rw [Nat.odd_iff] at ho + omega + conv_lhs => rw [he] + exact eligible_ranks_card _ _ + +/-- A double internal level together with the singleton top contributes one +outgoing arrow per rank, independently of top parity. -/ + theorem total_outgoing_count (L C : ℕ) (h : L ≤ C) : + (∑ r ∈ Finset.range C, if L < r ∧ Odd (L+r) then 2 else 0) + + (if L < C ∧ Odd (L+C) then 1 else 0) = C-L := by + induction C, h using Nat.le_induction with + | base => + have hz : ∀ r ∈ Finset.range L, ¬ L < r := by + intro r hr + have := Finset.mem_range.mp hr + omega + have hs : (∑ r ∈ Finset.range L, if L < r ∧ Odd (L+r) then 2 else 0) = 0 := by + apply Finset.sum_eq_zero + intro r hr + simp only [hz r hr, false_and, ite_false] + simp only [hs, lt_self_iff_false, false_and, ite_false, add_zero, Nat.sub_self] + | succ C h ih => + rw [Finset.sum_range_succ] + by_cases hc : L rcases le_total 0 z with hz'|hz' + · rw [abs_of_nonneg hi'] at hi + rw [abs_of_nonneg hz'] at hz + omega + · rw [abs_of_nonneg hi'] at hi + rw [abs_of_nonpos hz'] at hz + omega + · rw [abs_of_nonpos hi'] at hi + rw [abs_of_nonneg hz'] at hz + omega + · rw [abs_of_nonpos hi'] at hi + rw [abs_of_nonpos hz'] at hz + omega + + theorem arrowAfter_far {i j z : ℤ} (hij : |i| < |j|) (hjz : |j| < |z|) : + arrowAfter i (i+j) z = if Odd (i.natAbs+z.natAbs) ∧ 0 < j then 1 else 0 := by + have hiz := hij.trans hjz + have hb : Before (i+j) (i+z) ↔ 0 < j := by + by_cases hj : 0 < j + · rw [before_same_source_pos hij hiz hj] + rw [abs_of_pos hj] at hjz + rw [lt_abs] at hjz + omega + · have hj' : j < 0 := by + have := abs_nonneg i + rw [abs_of_nonpos (by omega : j ≤ 0)] at hij + omega + rw [before_same_source_neg hij hiz hj'] + rw [abs_of_neg hj',lt_abs] at hjz + omega + simp only [arrowAfter,hiz,true_and,odd_add_abs,hb] + + def positiveCount (L M C : ℕ) : ℕ := + (∑ r ∈ Finset.range C, if L < r ∧ Odd (L+r) then (if M < r then 2 else 1) else 0) + + (if M < C ∧ Odd (L+C) then 1 else 0) + + theorem positiveCount_formula (L M C : ℕ) (hLM : L < M) (ho : Odd (L+M)) + (hMC : M ≤ C) : positiveCount L M C = (M-L-1)/2 + (C-M) := by + induction C, hMC using Nat.le_induction with + | base => + have he : M = L+2*((M-L-1)/2)+1 := by + rw [Nat.odd_iff] at ho + omega + have hs : (∑ r ∈ Finset.range M, + if L < r ∧ Odd (L+r) then (if M < r then 2 else 1) else 0) = + (∑ r ∈ Finset.range M, if L < r ∧ Odd (L+r) then 1 else 0) := by + apply Finset.sum_congr rfl + intro r hr + have hn : ¬ M < r := by have := Finset.mem_range.mp hr; omega + simp only [hn,ite_false] + rw [positiveCount,hs,← Finset.sum_filter,Finset.sum_const,nsmul_eq_mul,mul_one] + simp only [lt_self_iff_false,false_and,ite_false,add_zero,Nat.sub_self] + conv_lhs => rw [he] + exact eligible_ranks_card _ _ + | succ C hMC ih => + rw [positiveCount,Finset.sum_range_succ] + unfold positiveCount at ih + by_cases h : M rfl + · have hh : ¬(i.natAbs < r ∧ Odd (i.natAbs+r) ∧ j.natAbs < r) := by tauto + simp only [h1,hh,ite_false,add_zero] + rw [countAfter,Finset.sum_congr rfl hs,arrowAfter_far hij h] + simp only [hj,and_true] + have heq : (if Odd (i.natAbs+c.natAbs) then 1 else 0) = + (if j.natAbs < c.natAbs ∧ Odd (i.natAbs+c.natAbs) then 1 else 0) := by + simp only [hMC,true_and] + rw [heq] + exact positiveCount_formula _ _ _ hLM ho hMC.le + + theorem countAfter_neg_formula {i j c : ℤ} (hij : |i| < |j|) + (ho : Odd (i.natAbs+j.natAbs)) (hj : j < 0) + (h : c=j ∨ |j| < |c|) : + countAfter i (i+j) c = (j.natAbs-i.natAbs-1)/2 := by + rcases h with rfl|h + · exact countAfter_base hij ho + have hMC : j.natAbs < c.natAbs := by + exact_mod_cast (show (j.natAbs:ℤ) < c.natAbs by simpa only [Int.natCast_natAbs] using h) + have hn : ¬0 rfl + rw [Finset.sum_congr rfl hs] + exact total_outgoing_count _ _ hMC + · simp only [hj,and_false,ite_false,add_zero,Finset.sum_const_zero] + +/-- The signed-index cardinality identity for the source's forward angular +order. Its identification with actual Coxeter angular roots is separate. -/ + theorem countAfter_difference {i j c : ℤ} (hij : |i| < |j|) + (ho : Odd (i.natAbs+j.natAbs)) (h : c=j ∨ |j| < |c|) : + countAfter i (i+j) c = countAfter j (i+j) c + (j.natAbs-i.natAbs-1)/2 := by + rw [countAfter_next_formula hij h] + by_cases hj : 0 h (Relation.ReflTransGen.single hz) + simp only [afterIndicator,dite_eq_right hn] + +/-- Counting only the relative interval above a lower bound does not alter +an outgoing count based at a vertex above that bound. -/ + theorem interval_laterCount {a x c : planeSubgroup M cs P} + (hax : BruhatLE B.system a x) (α : PositiveRoot M cs) : + (∑ᶠ z : Interval B.system a c, B.afterIndicator x α z.val) = + B.laterCount x α c := by + classical + let := interval_finite B.system a c + let : Fintype (Interval B.system a c) := Fintype.ofFinite _ + rw [finsum_eq_sum_of_fintype,laterCount] + have hs := Finset.sum_subtype (F := (inferInstance : Fintype (Interval B.system a c))) + ((lowerFinset B.system c).filter (fun z => BruhatLE B.system a z)) + (fun z => by simp only [Finset.mem_filter,mem_lowerFinset]; exact and_comm) + (fun z => B.afterIndicator x α z) + refine hs.symm.trans (Finset.sum_subset (Finset.filter_subset _ _) ?_) + intro z hz hn + apply B.afterIndicator_eq_zero + intro hxz + exact hn (Finset.mem_filter.mpr ⟨hz,bruhat_trans B.system hax hxz⟩) + + theorem edgeRoot_coset {a₀ : W} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + {x y : planeSubgroup M cs P} (hxy : BruhatStep B.system x y) : + B.edgeRoot hxy = graphRoot ((B.coset_step_iff hmin x y).mpr hxy) := by + unfold edgeRoot graphRoot + apply congrArg (positiveRoot M cs) + apply Subtype.ext + change (y:W)*(x:W)⁻¹=((y:W)*a₀)*((x:W)*a₀)⁻¹ + group + +variable {I' : Type u'} [Fintype I'] {M' : CoxeterMatrix I'} + {W' : Type v'} [Group W'] {cs' : CoxeterSystem M' W'} + {P' : Submodule ℝ (I' → ℝ)} (B' : PlaneBasis (M := M') (cs := cs') P') + +/-- A full relative interval transport carries the actual angular later-edge +count. An arbitrary graph embedding would not suffice here. -/ + theorem interval_map_count {a c : planeSubgroup M cs P} + (hac : BruhatLE B.system a c) + (F : Interval B.system a c → planeSubgroup M' cs' P') + (hinj : Function.Injective F) + (hrange : Set.range F = {z | BruhatLE B'.system (F ⟨a,bruhat_refl B.system a,hac⟩) z ∧ + BruhatLE B'.system z (F ⟨c,hac,bruhat_refl B.system c⟩)}) + (x : Interval B.system a c) (α : PositiveRoot M' cs') : + (∑ᶠ z : Interval B.system a c, B'.afterIndicator (F x) α (F z)) = + B'.laterCount (F x) α (F ⟨c,hac,bruhat_refl B.system c⟩) := by + classical + let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ + let hi : Interval B.system a c := ⟨c,hac,bruhat_refl B.system c⟩ + have hmem (z : Interval B.system a c) : BruhatLE B'.system (F lo) (F z) ∧ + BruhatLE B'.system (F z) (F hi) := by + exact (Set.ext_iff.mp hrange (F z)).mp ⟨z,rfl⟩ + let f : Interval B.system a c → Interval B'.system (F lo) (F hi) := + fun z => ⟨F z,hmem z⟩ + have hf : Function.Bijective f := by + constructor + · intro z w h + exact hinj (congrArg Subtype.val h) + · intro z + obtain ⟨w,hw⟩ := (Set.ext_iff.mp hrange z.val).mpr z.property + exact ⟨w,Subtype.ext hw⟩ + let E := Equiv.ofBijective f hf + have hs := finsum_comp_equiv E (f := fun z : Interval B'.system (F lo) (F hi) => + B'.afterIndicator (F x) α z.val) + exact hs.trans (B'.interval_laterCount (hmem x).1 α) + +end +end KLInvariance.TitsSpace.PlaneBasis + +end + + +section + +namespace KLInvariance.TitsSpace +universe u v +variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} + {W : Type v} [Group W] {cs : CoxeterSystem M W} +noncomputable section + + def ambientAfterIndicator (x : W) (α : PositiveRoot M cs) (z : W) : ℕ := by + classical + exact if h : BruhatStep cs x z then + if geometricSlope α < geometricSlope (graphRoot h) then 1 else 0 + else 0 + + theorem ambientAfterIndicator_of_le {x z : W} (α : PositiveRoot M cs) + (hz : BruhatLE cs z x) : ambientAfterIndicator x α z=0 := by + classical + have hn : ¬BruhatStep cs x z := fun h => + (not_lt_of_ge (length_le_of_bruhat cs hz)) h.1 + simp only [ambientAfterIndicator,dite_eq_right hn] + + theorem ambientAfterIndicator_edge_self {x y : W} (hxy : BruhatStep cs x y) : + ambientAfterIndicator x (graphRoot hxy) y=0 := by + classical + simp only [ambientAfterIndicator,dite_eq_left hxy,lt_self_iff_false,ite_false] + +namespace PlaneBasis +variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) + + theorem ambientAfterIndicator_coset {a₀ : W} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + (x z : planeSubgroup M cs P) (α : PositiveRoot M cs) : + ambientAfterIndicator ((x:W)*a₀) α ((z:W)*a₀) = B.afterIndicator x α z := by + classical + by_cases h : BruhatStep B.system x z + · have h' := (B.coset_step_iff hmin x z).mpr h + simp only [ambientAfterIndicator,afterIndicator,dite_eq_left h,dite_eq_left h',B.edgeRoot_coset hmin h] + · have h' : ¬BruhatStep cs ((x:W)*a₀) ((z:W)*a₀) := + fun hz => h ((B.coset_step_iff hmin x z).mp hz) + simp only [ambientAfterIndicator,afterIndicator,dite_eq_right h,dite_eq_right h'] + +universe u' v' +variable {I' : Type u'} [Fintype I'] {M' : CoxeterMatrix I'} + {W' : Type v'} [Group W'] {cs' : CoxeterSystem M' W'} + + + theorem transported_count_difference {a₀ u b : W} {u' b' : W'} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + {a c : planeSubgroup M cs P} (hac : BruhatLE B.system a c) + (hrank : B.system.length a+2 ≤ B.system.length c) + (hlo : BruhatLE cs u ((a:W)*a₀)) (hhi : BruhatLE cs ((c:W)*a₀) b) + (e : Interval cs u b ≃o Interval cs' u' b') + (y : Interval B.system a c) (hxy : BruhatStep B.system a y.val) : + let inc := B.cosetIntervalMap hmin hlo hhi + let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ + let α := graphRoot ((intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr + ((B.coset_step_iff hmin a y.val).mpr hxy)) + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc lo)).val α (e (inc z)).val) = + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc y)).val α (e (inc z)).val) + + (B.system.length y.val-B.system.length a-1)/2 := by + classical + dsimp only + let inc := B.cosetIntervalMap hmin hlo hhi + let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ + let hi : Interval B.system a c := ⟨c,hac,bruhat_refl B.system c⟩ + have hedge := (intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr + ((B.coset_step_iff hmin a y.val).mpr hxy) + change (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val) = + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val) + _ + obtain ⟨P',B',a',F,hmin',hinj,hcoord,horder,hstep,hlen,hrange⟩ := + B.transport_interval hmin hac hrank hlo hhi e + have hFxy : BruhatStep B'.system (F lo) (F y) := (hstep lo y).mpr hxy + have hFyc : BruhatLE B'.system (F y) (F hi) := (horder y hi).mpr y.property.2 + have hroot : B'.edgeRoot hFxy=graphRoot hedge := by + rw [B'.edgeRoot_coset hmin' hFxy] + unfold graphRoot + apply congrArg (positiveRoot M' cs') + apply Subtype.ext + change ((F y:W')*a')*((F lo:W')*a')⁻¹=(e (inc y)).val*(e (inc lo)).val⁻¹ + rw [hcoord y,hcoord lo] + have hsum (x : Interval B.system a c) : + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc x)).val (graphRoot hedge) (e (inc z)).val) = + B'.laterCount (F x) (B'.edgeRoot hFxy) (F hi) := by + rw [← B.interval_map_count B' hac F hinj hrange x (B'.edgeRoot hFxy)] + apply finsum_congr + intro z + rw [← hcoord x,← hcoord z,← hroot] + exact B'.ambientAfterIndicator_coset hmin' (F x) (F z) _ + rw [hsum lo,hsum y,B'.laterCount_difference hFxy hFyc] + congr 1 + have hy := hlen y + change B'.system.length (F y)+B.system.length a = + B'.system.length (F lo)+B.system.length y.val at hy + omega + +/-- The same scheduled count with no restriction on the relative rank. -/ + theorem transported_count_difference_all {a₀ u b : W} {u' b' : W'} + (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) + {a c : planeSubgroup M cs P} (hac : BruhatLE B.system a c) + (hlo : BruhatLE cs u ((a:W)*a₀)) (hhi : BruhatLE cs ((c:W)*a₀) b) + (e : Interval cs u b ≃o Interval cs' u' b') + (y : Interval B.system a c) (hxy : BruhatStep B.system a y.val) : + let inc := B.cosetIntervalMap hmin hlo hhi + let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ + let α := graphRoot ((intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr + ((B.coset_step_iff hmin a y.val).mpr hxy)) + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc lo)).val α (e (inc z)).val) = + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc y)).val α (e (inc z)).val) + + (B.system.length y.val-B.system.length a-1)/2 := by + classical + by_cases hrank : B.system.length a+2 ≤ B.system.length c + · exact B.transported_count_difference hmin hac hrank hlo hhi e y hxy + let inc := B.cosetIntervalMap hmin hlo hhi + let lo : Interval B.system a c := ⟨a,bruhat_refl B.system a,hac⟩ + have hedge := (intervalIso_bruhatStep_iff_general cs cs' e (inc lo) (inc y)).mpr + ((B.coset_step_iff hmin a y.val).mpr hxy) + change (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val) = + (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val) + _ + have hylen := hxy.1 + have hyc := length_le_of_bruhat B.system y.property.2 + have hlen : B.system.length y.val=B.system.length a+1 := by omega + have heyc : y.val=c := by + by_contra hn + have hlt := length_lt_of_bruhat_ne B.system y.property.2 hn + omega + have hverts (z : Interval B.system a c) : z=lo ∨ z=y := by + by_cases hz : z.val=a + · exact Or.inl (Subtype.ext hz) + · right + apply Subtype.ext + rw [heyc] + by_contra hzc + have hzlo := length_lt_of_bruhat_ne B.system z.property.1 (Ne.symm hz) + have hzhi := length_lt_of_bruhat_ne B.system z.property.2 hzc + omega + have hzero₁ : (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc lo)).val (graphRoot hedge) (e (inc z)).val)=0 := by + apply finsum_eq_zero_of_forall_eq_zero + intro z + rcases hverts z with rfl | rfl + · exact ambientAfterIndicator_of_le _ (bruhat_refl cs' _) + · exact ambientAfterIndicator_edge_self hedge + have hzero₂ : (∑ᶠ z : Interval B.system a c, + ambientAfterIndicator (e (inc y)).val (graphRoot hedge) (e (inc z)).val)=0 := by + apply finsum_eq_zero_of_forall_eq_zero + intro z + rcases hverts z with rfl | rfl + · exact ambientAfterIndicator_of_le _ (Relation.ReflTransGen.single hedge) + · exact ambientAfterIndicator_of_le _ (bruhat_refl cs' _) + rw [hzero₁,hzero₂,hlen] + omega + +end PlaneBasis +end +end KLInvariance.TitsSpace + +end + + +section + +/-! Linear prime ideals in the exact symmetric algebra, including the actual +root-plane coefficient primes. No local-ring or survival property is assumed. -/ + +end + +end OAI diff --git a/lean/OAI/RepresentationTheory/KazhdanLusztig/DyerPaths.lean b/lean/OAI/RepresentationTheory/KazhdanLusztig/DyerPaths.lean index 8aa65f6f13e5ae89bf13a1eba853d3c198a8eed9..80af4ce3f182aba0624693113288fa11e5e149c7 100644 --- a/lean/OAI/RepresentationTheory/KazhdanLusztig/DyerPaths.lean +++ b/lean/OAI/RepresentationTheory/KazhdanLusztig/DyerPaths.lean @@ -1,2507 +1,2507 @@ -import OAI.RepresentationTheory.KazhdanLusztig.CharacterReciprocity - -namespace OAI - -/-! -Finite character cancellation, reflection-ratio orders and adapted Dyer decreasing paths. --/ - -section - -namespace KLInvariance -universe u v -variable {V : Type u} [Fintype V] {C : Type v} [CommRing C] - - theorem finite_character_cancellation (t : V) (m : V → C) (r : V → C) - (p : V → V → C) (q : V → C) (hm : m t=1) - (hword : (∑ y, m y*q y)=∑ z, r z*(∑ y, m y*p y z)) - (hlower : ∀ y, y≠t → q y=∑ z, r z*p y z) : q t=∑ z, r z*p t z := by - classical - have hexpand : (∑ z, r z*(∑ y, m y*p y z))=∑ y, m y*(∑ z, r z*p y z) := by - simp only [Finset.mul_sum] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro y _ - apply Finset.sum_congr rfl - intro z _ - ring - rw [hexpand] at hword - have hzero : (∑ y, m y*(q y-∑ z, r z*p y z))=0 := by - simp only [mul_sub,Finset.sum_sub_distrib,hword,sub_self] - have hsingle : (∑ y, m y*(q y-∑ z, r z*p y z))=q t-∑ z, r z*p t z := by - rw [Finset.sum_eq_single t] - · rw [hm,one_mul] - · intro y _ hy - rw [hlower y hy,sub_self,mul_zero] - · simp - rw [hsingle] at hzero - exact sub_eq_zero.mp hzero - -end KLInvariance - -end - - -section - -/-! R-reciprocity for the ACTUAL minimal-boundary BMP character, obtained -by simultaneous word stalk/costalk decomposition and unipotent cancellation. -This is not a character identification: strict halfdegree remains separate. -/ -namespace KLInvariance.BruhatGraph -open Module TitsSpace _root_.OAI.KLInvariance.Graded MomentGraph Polynomial -universe u -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type u} [Group W] (cs : CoxeterSystem M W) - {σ : Type u} [Fintype σ] (basis : Basis σ ℝ (Extended M)) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p -local instance bmpRecInterval (b : W) : Fintype (Interval cs 1 b) := by - let := interval_finite cs 1 b - exact Fintype.ofFinite _ - - theorem stalkCharacter_reciprocity (b : W) (x : Interval cs 1 b) : - reflect (rankDifference cs x.val b) (stalkCharacter cs 1 b basis (one_bruhat cs b) x)= - ∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val* - stalkCharacter cs 1 b basis (one_bruhat cs b) z := by - generalize hn : cs.length b=n - induction n using Nat.strong_induction_on generalizing b with - | h n ih => - obtain ⟨l,hl,rfl⟩ := cs.exists_isReduced b - let b := cs.wordProd l - let t : Interval cs 1 b := ⟨b,one_bruhat cs b,bruhat_refl cs b⟩ - obtain ⟨m,_hm,hs,hk⟩ := bottCharacter_decomposition_both cs basis l hl - have hmt : m t=1 := by - have hh := hs t - rw [bottStalkCharacter_top cs basis l hl] at hh - rw [Finset.sum_eq_single t] at hh - · simpa only [lowerCharacter_diagonal,mul_one] using hh.symm - · intro y _ hy - have hv : y.val≠b := fun h => hy (Subtype.ext h) - rw [lowerCharacter_at_top,ite_eq_right hv,mul_zero] - · simp - have ht (z : Interval cs 1 b) : lowerCharacter cs b basis t z= - stalkCharacter cs 1 b basis (one_bruhat cs b) z := dite_eq_left z.property.2 - have hw : (∑ y, m y*reflect (rankDifference cs x.val y.val) (lowerCharacter cs b basis y x))= - ∑ z : Interval cs 1 b, OrdinaryR.polynomial cs x.val z.val* - (∑ y, m y*lowerCharacter cs b basis y z) := by - rw [←hk x,bottKernelCharacter_rConvolution cs basis l hl x] - simp only [hs] - rfl - have hh := finite_character_cancellation t m - (fun z : Interval cs 1 b => OrdinaryR.polynomial cs x.val z.val) - (fun y z => lowerCharacter cs b basis y z) - (fun y => reflect (rankDifference cs x.val y.val) (lowerCharacter cs b basis y x)) - hmt hw (fun y hy => ?_) - · simpa only [ht] using hh - · apply lowerCharacter_reciprocity_lift - intro z - apply ih (cs.length y.val) _ y.val z rfl - rw [←hn] - exact length_lt_of_bruhat_ne cs y.property.2 (fun he => hy (Subtype.ext he)) - -end -end KLInvariance.BruhatGraph - -end - - -section - -/-! Removing the finite-rank restriction from the actual graph bridge, -using the already established standard-parabolic embedding. -/ -namespace KLInvariance.StandardParabolic -open CoxeterSystem -universe u v -variable {I : Type u} {W : Type v} [Group W] {M : CoxeterMatrix I} -variable (cs : CoxeterSystem M W) (J : Set I) -noncomputable section - -theorem leftInvSeq_inclusion (ω : List J) : - ((system (M := M) J).leftInvSeq ω).map (inclusion cs J) = - cs.leftInvSeq (ω.map Subtype.val) := by - induction ω with - | nil => rfl - | cons i ω ih => - simp only [CoxeterSystem.leftInvSeq, List.map_cons, List.map_map, - inclusion_simple] - rw [← ih, List.map_map] - congr 1 - apply List.map_congr_left - intro t _ - simp only [Function.comp_apply, MulAut.conj_apply, map_mul, map_inv, - inclusion_simple] - -theorem reflection_inclusion {t : (matrix (M := M) J).Group} - (ht : (system (M := M) J).IsReflection t) : - cs.IsReflection (inclusion cs J t) := by - obtain ⟨w, i, rfl⟩ := ht - exact ⟨inclusion cs J w, i.val, by simp only [map_mul, map_inv, inclusion_simple]⟩ - -theorem bruhatStep_inclusion_iff [Fintype J] (x y : (matrix (M := M) J).Group) : - BruhatStep cs (inclusion cs J x) (inclusion cs J y) ↔ - BruhatStep (system (M := M) J) x y := by - constructor - · rintro ⟨hlen, t, ht, heq⟩ - obtain ⟨ω, hω, hprod⟩ := (system (M := M) J).exists_isReduced y - have hi : cs.IsLeftInversion (inclusion cs J y) t := by - refine ⟨ht, ?_⟩ - rw [heq, ← mul_assoc, ht.mul_self, one_mul] - simpa only [heq] using hlen - have hr := (reduced_map_iff cs J ω).2 hω - have hw : cs.wordProd (ω.map Subtype.val) = inclusion cs J y := by - rw [← inclusion_word, hprod] - have hm := CoxeterSupport.mem_leftInvSeq_of_inversion cs hr (hw ▸ hi) - rw [← leftInvSeq_inclusion] at hm - obtain ⟨r, hr, hrt⟩ := List.mem_map.mp hm - refine ⟨by simpa only [length_inclusion] using hlen, - r, (system (M := M) J).isReflection_of_mem_leftInvSeq ω hr, ?_⟩ - apply inclusion_injective cs J - simpa only [map_mul, hrt] using heq - · rintro ⟨hlen, t, ht, heq⟩ - refine ⟨by simpa only [length_inclusion] using hlen, - inclusion cs J t, reflection_inclusion cs J ht, ?_⟩ - rw [heq, map_mul] - -end -end KLInvariance.StandardParabolic - -namespace KLInvariance -universe u v u' v' -variable {I : Type u} {W : Type v} [Group W] {M : CoxeterMatrix I} - -/-- The graph reconstruction input in its source scope: the Coxeter system -can have infinitely many generators. The interval determines every reflection -edge without being supplied the reflection labels. -/ -theorem diamondEdges_of_bruhatStep_general (cs : CoxeterSystem M W) - {u b : W} {x y : Interval cs u b} (hxy : BruhatStep cs x.val y.val) : - DiamondEdges x y := by - classical - obtain ⟨J, hJ, hwords⟩ := lower_ideal_finite_generator_support cs b - let : Fintype J := hJ.fintype - obtain ⟨ω, hω, hprod⟩ := hwords b (bruhat_refl cs b) - obtain ⟨ν, rfl⟩ := StandardParabolic.lift_word J hω - let bb := (StandardParabolic.system (M := M) J).wordProd ν - have hb : StandardParabolic.inclusion cs J bb = b := - (StandardParabolic.inclusion_word cs J ν).trans hprod - have hub : BruhatLE cs u b := (bruhat_trans cs x.property.1 x.property.2) - obtain ⟨ub, hu⟩ := StandardParabolic.lower_range cs J bb (hb ▸ hub) - subst u - clear hprod - subst b - let e := StandardParabolic.intervalIso cs J ub bb - let xx := e.symm x - let yy := e.symm y - have hx : StandardParabolic.inclusion cs J xx.val = x.val := - congrArg Subtype.val (e.apply_symm_apply x) - have hy : StandardParabolic.inclusion cs J yy.val = y.val := - congrArg Subtype.val (e.apply_symm_apply y) - have hh : BruhatStep (StandardParabolic.system (M := M) J) xx.val yy.val := by - apply (StandardParabolic.bruhatStep_inclusion_iff cs J _ _).mp - rwa [hx, hy] - have hg := (diamondEdges_of_bruhatStep (StandardParabolic.system (M := M) J) hh).map e - simpa only [xx, yy, e.apply_symm_apply] using hg - -theorem diamondEdges_bruhatStep_general (cs : CoxeterSystem M W) - {u b : W} {x y : Interval cs u b} (hxy : DiamondEdges x y) : - BruhatStep cs x.val y.val := by - classical - obtain ⟨J, hJ, hwords⟩ := lower_ideal_finite_generator_support cs b - let : Fintype J := hJ.fintype - obtain ⟨ω, hω, hprod⟩ := hwords b (bruhat_refl cs b) - obtain ⟨ν, rfl⟩ := StandardParabolic.lift_word J hω - let bb := (StandardParabolic.system (M := M) J).wordProd ν - have hb : StandardParabolic.inclusion cs J bb = b := - (StandardParabolic.inclusion_word cs J ν).trans hprod - have hub : BruhatLE cs u b := (bruhat_trans cs x.property.1 x.property.2) - obtain ⟨ub, hu⟩ := StandardParabolic.lower_range cs J bb (hb ▸ hub) - subst u - clear hprod - subst b - let e := StandardParabolic.intervalIso cs J ub bb - let xx := e.symm x - let yy := e.symm y - have hx : StandardParabolic.inclusion cs J xx.val = x.val := - congrArg Subtype.val (e.apply_symm_apply x) - have hy : StandardParabolic.inclusion cs J yy.val = y.val := - congrArg Subtype.val (e.apply_symm_apply y) - have hh : DiamondEdges xx yy := hxy.map e.symm - have hg := diamondEdges_bruhatStep (StandardParabolic.system (M := M) J) hh - have hs := (StandardParabolic.bruhatStep_inclusion_iff cs J xx.val yy.val).mpr hg - rwa [hx, hy] at hs - -/-- Exact unlabelled directed graph invariance, also for arbitrary infinite -Coxeter systems. This is not yet KL polynomial invariance. -/ -theorem intervalIso_bruhatStep_iff_general - {I' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix I'} - (cs : CoxeterSystem M W) (cs' : CoxeterSystem M' W') - {u b : W} {u' b' : W'} (e : Interval cs u b ≃o Interval cs' u' b') - (x y : Interval cs u b) : - BruhatStep cs' (e x).val (e y).val ↔ BruhatStep cs x.val y.val := by - constructor - · intro h - exact diamondEdges_bruhatStep_general cs ((DiamondEdges.map_iff e).mp - (diamondEdges_of_bruhatStep_general cs' h)) - · intro h - exact diamondEdges_bruhatStep_general cs' ((diamondEdges_of_bruhatStep_general cs h).map e) - -end KLInvariance - -end - - -section - - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -theorem graphRoot_mem {a₀ : W} {g h : planeSubgroup M cs P} - (he : BruhatStep cs ((g : W) * a₀) ((h : W) * a₀)) : - (graphRoot he).val ∈ P := by - exact reflection_between_coset_mem M cs (a := a₀) g.property h.property (by group) - (graphRoot_represents he) - -include B - -/-- The two labels on a composable coset path span the whole actual plane. -/ -theorem graphRoot_path_plane {a₀ : W} {g h k : planeSubgroup M cs P} - (he : BruhatStep cs ((g : W) * a₀) ((h : W) * a₀)) - (hf : BruhatStep cs ((h : W) * a₀) ((k : W) * a₀)) : - rootPlane (graphRoot he) (graphRoot hf) = P := by - exact (rootPlane_eq_of_mem B.left B.right (graphRoot he) (graphRoot hf) - B.distinct (B.plane_eq.ge (graphRoot_mem he)) (B.plane_eq.ge (graphRoot_mem hf)) - (graphRoot_ne_of_path he hf)).trans B.plane_eq - - -theorem twoStep_mem_coset {a₀ : W} {g h k : planeSubgroup M cs P} - (he : BruhatStep cs ((g : W) * a₀) ((h : W) * a₀)) - (hf : BruhatStep cs ((h : W) * a₀) ((k : W) * a₀)) - {z : W} (hez : BruhatStep cs ((g : W) * a₀) z) - (hzf : BruhatStep cs z ((k : W) * a₀)) : - z * a₀⁻¹ ∈ planeSubgroup M cs P := by - by_cases hz : (h : W) * a₀ = z - · rw [← hz, mul_inv_cancel_right] - exact h.property - have hplane := graphRoot_square_plane he hez hf hzf hz - have hroot : (graphRoot hez).val ∈ P := by - apply (hplane.symm.trans (B.graphRoot_path_plane he hf)).le - exact Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)) - have href : z * ((g : W) * a₀)⁻¹ ∈ planeSubgroup M cs P := - (Represents.planeSubgroup_mem_iff M cs (graphRoot_represents hez)).mpr hroot - convert (planeSubgroup M cs P).mul_mem href g.property using 1; group - -/-- A relative rank-two interval has exactly its two ambient two-edge paths, -with no assumption that the two ambient and relative orders coincide. -/ -theorem ambient_two_step_rank_two {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z * a₀)) - {g k : planeSubgroup M cs P} (hlen : B.system.length k = B.system.length g + 2) : - ∃ a b : W, a ≠ b ∧ ∀ z : W, - (BruhatStep cs ((g : W) * a₀) z ∧ BruhatStep cs z ((k : W) * a₀)) ↔ - z = a ∨ z = b := by - obtain ⟨a,b,hab,hpaths⟩ := Dihedral.two_step_rank_two B.system hlen - have ha := (hpaths a).mpr (Or.inl rfl) - have he := (B.coset_step_iff hmin g a).mpr ha.1 - have hf := (B.coset_step_iff hmin a k).mpr ha.2 - refine ⟨(a : W)*a₀,(b : W)*a₀,?_,fun z => ?_⟩ - · intro heq - exact hab (Subtype.ext (mul_right_cancel heq)) - constructor - · intro hz - let z' : planeSubgroup M cs P := ⟨z*a₀⁻¹,B.twoStep_mem_coset he hf hz.1 hz.2⟩ - have hz' : (z' : W)*a₀=z := by dsimp [z']; group - have hp : BruhatStep B.system g z' ∧ BruhatStep B.system z' k := by - constructor - · exact (B.coset_step_iff hmin g z').mp (hz' ▸ hz.1) - · exact (B.coset_step_iff hmin z' k).mp (hz' ▸ hz.2) - rcases (hpaths z').mp hp with hza | hzb - · exact Or.inl (hz'.symm.trans (congrArg (fun q : planeSubgroup M cs P => (q:W)*a₀) hza)) - · exact Or.inr (hz'.symm.trans (congrArg (fun q : planeSubgroup M cs P => (q:W)*a₀) hzb)) - · rintro (rfl | rfl) - · exact ⟨he,hf⟩ - · have hb := (hpaths b).mpr (Or.inr rfl) - exact ⟨(B.coset_step_iff hmin g b).mpr hb.1, - (B.coset_step_iff hmin b k).mpr hb.2⟩ - -end PlaneBasis -end -end KLInvariance.TitsSpace - -namespace KLInvariance.Dihedral -variable {G : Type*} [Group G] {N : CoxeterMatrix Bool} - -/-- Exactly two intermediate vertices characterize relative rank two as soon -as one two-edge path exists. Used to rule out skipped ranks after transport. -/ -theorem rank_two_of_two_step_bound (ds : CoxeterSystem N G) {x y a b : G} - (ha : BruhatStep ds x a) (hay : BruhatStep ds a y) - (hbound : ∀ z, BruhatStep ds x z → BruhatStep ds z y → z = a ∨ z = b) : - ds.length y = ds.length x + 2 := by - have hxa := (step_iff_odd ds x a).mp ha - have hay' := (step_iff_odd ds a y).mp hay - rw [Nat.odd_iff] at hxa hay' - have heven : (ds.length y - ds.length x) % 2 = 0 := by omega - by_contra hlen - have hlarge : ds.length x + 3 < ds.length y := by omega - obtain ⟨p,q,hpq,hlevel⟩ := two_elements_length ds - (by omega : 0 < ds.length x+1) (w := y) (by omega) - have hp := (hlevel p).mpr (Or.inl rfl) - have hq := (hlevel q).mpr (Or.inr rfl) - obtain ⟨r,s,hrs,hlevel'⟩ := two_elements_length ds - (by omega : 0 < ds.length x+3) hlarge - have hr := (hlevel' r).mpr (Or.inl rfl) - have paths : ∀ z, ds.length z = ds.length x+1 ∨ ds.length z = ds.length x+3 → - BruhatStep ds x z ∧ BruhatStep ds z y := by - intro z hz - rw [step_iff_odd,step_iff_odd,Nat.odd_iff,Nat.odd_iff] - rcases hz with hz | hz <;> omega - have pp := paths p (Or.inl hp) - have pq := paths q (Or.inl hq) - have pr := paths r (Or.inr hr) - have hpr : p ≠ r := by intro he; rw [he] at hp; omega - have hqr : q ≠ r := by intro he; rw [he] at hq; omega - rcases hbound p pp.1 pp.2 with hp' | hp' <;> - rcases hbound q pq.1 pq.2 with hq' | hq' <;> - rcases hbound r pr.1 pr.2 with hr' | hr' <;> grind - -end KLInvariance.Dihedral - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section - -theorem graphRoot_mem_of_coset {P : Submodule ℝ (I → ℝ)} {a₀ x y : W} - (h : BruhatStep cs x y) (hx : x*a₀⁻¹ ∈ planeSubgroup M cs P) - (hy : y*a₀⁻¹ ∈ planeSubgroup M cs P) : (graphRoot h).val ∈ P := by - apply (Represents.planeSubgroup_mem_iff M cs (graphRoot_represents h)).mp - convert (planeSubgroup M cs P).mul_mem hy ((planeSubgroup M cs P).inv_mem hx) using 1 - group - -theorem mem_coset_of_graphRoot {P : Submodule ℝ (I → ℝ)} {a₀ x y : W} - (h : BruhatStep cs x y) (hx : x*a₀⁻¹ ∈ planeSubgroup M cs P) - (hy : (graphRoot h).val ∈ P) : y*a₀⁻¹ ∈ planeSubgroup M cs P := by - have hm := (Represents.planeSubgroup_mem_iff M cs (graphRoot_represents h)).mpr hy - convert (planeSubgroup M cs P).mul_mem hm hx using 1 - group - -variable {D : Type*} [Group D] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N D) - {l r : D} - -/-- The image of a full relative dihedral interval lies in one maximal plane -coset. This is derived just from the directed graph and distinct vertices. -/ -theorem dihedral_image_in_plane - (f : Interval ds l r → W) (hinj : Function.Injective f) - (hgraph : ∀ a b : Interval ds l r, - BruhatStep ds a.val b.val → BruhatStep cs (f a) (f b)) - (hlr : BruhatLE ds l r) (hrank : ds.length l + 2 ≤ ds.length r) : - ∃ a b : PositiveRoot M cs, a ≠ b ∧ - ∀ z : Interval ds l r, - f z * (f ⟨l,bruhat_refl ds l,hlr⟩)⁻¹ ∈ planeSubgroup M cs (rootPlane a b) := by - let lo : Interval ds l r := ⟨l,bruhat_refl ds l,hlr⟩ - let hi : Interval ds l r := ⟨r,hlr,bruhat_refl ds r⟩ - obtain ⟨a,b,hab,ha,hb⟩ := Dihedral.two_interval_elements_length ds lo hi - (n := ds.length l+1) (by dsimp [lo]; omega) (by dsimp [hi]; omega) - have cover : ∀ p q : Interval ds l r, ds.length q.val = ds.length p.val+1 → - BruhatStep cs (f p) (f q) := by - intro p q hlen - apply hgraph - rw [Dihedral.step_iff_odd,Nat.odd_iff] - omega - have hla := cover lo a ha - have hlb := cover lo b hb - have hrootne := graphRoot_ne_of_same_source hla hlb (fun h => hab (hinj h)) - let P := rootPlane (graphRoot hla) (graphRoot hlb) - refine ⟨graphRoot hla,graphRoot hlb,hrootne,?_⟩ - change ∀ z : Interval ds l r, f z * (f lo)⁻¹ ∈ planeSubgroup M cs P - have hlo : f lo * (f lo)⁻¹ ∈ planeSubgroup M cs P := by simp - have hat : f a * (f lo)⁻¹ ∈ planeSubgroup M cs P := by - exact mem_coset_of_graphRoot hla hlo (Submodule.subset_span (Set.mem_insert _ _)) - have hbt : f b * (f lo)⁻¹ ∈ planeSubgroup M cs P := by - exact mem_coset_of_graphRoot hlb hlo - (Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _))) - intro z - suffices ∀ n, ∀ z : Interval ds l r, ds.length z.val = n → - f z * (f lo)⁻¹ ∈ planeSubgroup M cs P from this _ z rfl - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro z hz - have hzmin := length_le_of_bruhat ds z.property.1 - by_cases hzlo : z = lo - · simpa only [hzlo] using hlo - have hzgt : ds.length l < ds.length z.val := - length_lt_of_bruhat_ne ds z.property.1 (fun h => hzlo (Subtype.ext h.symm)) - by_cases hzone : ds.length z.val = ds.length l+1 - · obtain ⟨p,q,hpq,hlev⟩ := Dihedral.two_elements_length ds - (by omega : 0 < ds.length l+1) (w := r) (by omega) - have ap := (hlev a.val).mp ha - have bp := (hlev b.val).mp hb - have zp := (hlev z.val).mp hzone - have habval : a.val ≠ b.val := fun h => hab (Subtype.ext h) - have hza : z = a ∨ z = b := by - apply (show z.val = a.val ∨ z.val = b.val → z = a ∨ z = b from - fun h => h.elim (fun h => Or.inl (Subtype.ext h)) (fun h => Or.inr (Subtype.ext h))) - grind - rcases hza with rfl | rfl <;> assumption - have htwo : ds.length l+2 ≤ ds.length z.val := by omega - have hexp : ∃ p : Interval ds l r, ds.length p.val+2=ds.length z.val := by - by_cases he : ds.length z.val = ds.length l+2 - · exact ⟨lo,he.symm⟩ - · obtain ⟨p,q,_,hp,_⟩ := Dihedral.two_interval_elements_length ds lo z - (n := ds.length z.val-2) (by dsimp [lo]; omega) (by omega) - exact ⟨p,by omega⟩ - obtain ⟨p,hp⟩ := hexp - obtain ⟨q,s,hqs,hq,hs⟩ := Dihedral.two_interval_elements_length ds lo z - (n := ds.length z.val-1) (by dsimp [lo]; omega) (by omega) - have hp' := ih (ds.length p.val) (by omega) p rfl - have hq' := ih (ds.length q.val) (by omega) q rfl - have hs' := ih (ds.length s.val) (by omega) s rfl - have hpq := cover p q (by omega) - have hps := cover p s (by omega) - have hqz := cover q z (by omega) - have hsz := cover s z (by omega) - have hplane : rootPlane (graphRoot hpq) (graphRoot hps) = P := - rootPlane_eq_of_mem _ _ _ _ hrootne (graphRoot_mem_of_coset hpq hp' hq') - (graphRoot_mem_of_coset hps hp' hs') - (graphRoot_ne_of_same_source hpq hps (fun h => hqs (hinj h))) - have hsquare := graphRoot_square_plane hpq hps hqz hsz (fun h => hqs (hinj h)) - apply mem_coset_of_graphRoot hqz hq' - apply (hsquare.trans hplane).le - exact Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _)) - -end -end KLInvariance.TitsSpace - -namespace KLInvariance.Dihedral -universe u₁ u₂ -variable {D : Type u₁} [Group D] {N : CoxeterMatrix Bool} (ds : CoxeterSystem N D) - {l r : D} - -theorem exists_interval_length (hlr : BruhatLE ds l r) {n : ℕ} - (hnl : ds.length l ≤ n) (hnr : n ≤ ds.length r) : - ∃ z : Interval ds l r, ds.length z.val = n := by - by_cases hl : n = ds.length l - · exact ⟨⟨l,bruhat_refl ds l,hlr⟩,hl.symm⟩ - by_cases hr : n = ds.length r - · exact ⟨⟨r,hlr,bruhat_refl ds r⟩,hr.symm⟩ - obtain ⟨a,b,_,ha,_⟩ := two_interval_elements_length ds - (⟨l,bruhat_refl ds l,hlr⟩ : Interval ds l r) - (⟨r,hlr,bruhat_refl ds r⟩ : Interval ds l r) - (n := n) (by dsimp; omega) (by dsimp; omega) - exact ⟨a,ha⟩ - -variable {D' : Type u₂} [Group D'] {N' : CoxeterMatrix Bool} - (ds' : CoxeterSystem N' D') - -theorem map_cover_length - (f : Interval ds l r → D') - (hgraph : ∀ x y : Interval ds l r, BruhatStep ds x.val y.val → - BruhatStep ds' (f x) (f y)) - (htwo : ∀ x y : Interval ds l r, ds.length y.val = ds.length x.val+2 → - ds'.length (f y) = ds'.length (f x)+2) - (hlr : BruhatLE ds l r) (hrank : ds.length l+2 ≤ ds.length r) - {x y : Interval ds l r} (hxy : ds.length y.val = ds.length x.val+1) : - ds'.length (f y) = ds'.length (f x)+1 := by - have hstep : ∀ p q : Interval ds l r, ds.length q.val = ds.length p.val+1 → - ds'.length (f p) < ds'.length (f q) := by - intro p q hpq - apply (hgraph p q ?_).1 - rw [step_iff_odd,Nat.odd_iff] - omega - have hxy' := hstep x y hxy - have hyr := length_le_of_bruhat ds y.property.2 - by_cases hy : ds.length y.val < ds.length r - · obtain ⟨z,hz⟩ := exists_interval_length ds hlr - (n := ds.length y.val+1) - (by have := length_le_of_bruhat ds y.property.1; omega) (by omega) - have hyz := hstep y z hz - have hxz := htwo x z (by omega) - omega - · obtain ⟨z,hz⟩ := exists_interval_length ds hlr - (n := ds.length x.val-1) (by omega) (by omega) - have hzx := hstep z x (by omega) - have hzy := htwo z y (by omega) - omega - -/-- A directed dihedral-interval graph injection which does not stretch any -rank-two interval preserves all relative ranks. -/ -theorem map_length_affine - (f : Interval ds l r → D') - (hgraph : ∀ x y : Interval ds l r, BruhatStep ds x.val y.val → - BruhatStep ds' (f x) (f y)) - (htwo : ∀ x y : Interval ds l r, ds.length y.val = ds.length x.val+2 → - ds'.length (f y) = ds'.length (f x)+2) - (hlr : BruhatLE ds l r) (hrank : ds.length l+2 ≤ ds.length r) - (z : Interval ds l r) : - ds'.length (f z) + ds.length l = - ds'.length (f ⟨l,bruhat_refl ds l,hlr⟩) + ds.length z.val := by - let lo : Interval ds l r := ⟨l,bruhat_refl ds l,hlr⟩ - change ds'.length (f z)+ds.length l=ds'.length (f lo)+ds.length z.val - suffices ∀ n, ∀ z : Interval ds l r, ds.length z.val=n → - ds'.length (f z)+ds.length l=ds'.length (f lo)+ds.length z.val from this _ z rfl - intro n - induction n using Nat.strong_induction_on with - | h n ih => - intro z hz - by_cases he : z=lo - · simp [he,lo] - have hlt : ds.length l < ds.length z.val := - length_lt_of_bruhat_ne ds z.property.1 (fun h => he (Subtype.ext h.symm)) - obtain ⟨p,hp⟩ := exists_interval_length ds hlr (n := ds.length z.val-1) - (by omega) (by have := length_le_of_bruhat ds z.property.2; omega) - have ihp := ih (ds.length p.val) (by omega) p rfl - have hc := map_cover_length ds ds' f hgraph htwo hlr hrank (x := p) (y := z) - (by omega) - omega - -/-- Once relative covers are recovered, the image exhausts rather than merely -embeds in the target dihedral interval. -/ -theorem range_eq_interval_of_rank_two - (f : Interval ds l r → D') (hinj : Function.Injective f) - (hgraph : ∀ x y : Interval ds l r, BruhatStep ds x.val y.val → - BruhatStep ds' (f x) (f y)) - (htwo : ∀ x y : Interval ds l r, ds.length y.val = ds.length x.val+2 → - ds'.length (f y) = ds'.length (f x)+2) - (hlr : BruhatLE ds l r) (hrank : ds.length l+2 ≤ ds.length r) : - Set.range f = {z | BruhatLE ds' (f ⟨l,bruhat_refl ds l,hlr⟩) z ∧ - BruhatLE ds' z (f ⟨r,hlr,bruhat_refl ds r⟩)} := by - let lo : Interval ds l r := ⟨l,bruhat_refl ds l,hlr⟩ - let hi : Interval ds l r := ⟨r,hlr,bruhat_refl ds r⟩ - have hlen (z : Interval ds l r) : ds'.length (f z)+ds.length l = - ds'.length (f lo)+ds.length z.val := - map_length_affine ds ds' f hgraph htwo hlr hrank z - have hhi : ds'.length (f hi)+ds.length l=ds'.length (f lo)+ds.length r := hlen hi - have horder (x y : Interval ds l r) : - BruhatLE ds' (f x) (f y) ↔ x ≤ y := by - change BruhatLE ds' (f x) (f y) ↔ BruhatLE ds x.val y.val - rw [bruhat_iff_length_lt_or_eq,bruhat_iff_length_lt_or_eq] - have hx := hlen x - have hy := hlen y - constructor - · rintro (h | h) - · left; omega - · exact Or.inr (congrArg Subtype.val (hinj h)) - · rintro (h | h) - · left; omega - · exact Or.inr (congrArg f (Subtype.ext h)) - apply Set.ext - intro z - change (∃ x, f x=z) ↔ BruhatLE ds' (f lo) z ∧ BruhatLE ds' z (f hi) - constructor - · rintro ⟨x,rfl⟩ - exact ⟨(horder lo x).mpr x.property.1,(horder x hi).mpr x.property.2⟩ - · intro hz - by_cases hlo : z=f lo - · exact ⟨lo,hlo.symm⟩ - by_cases htop : z=f hi - · exact ⟨hi,htop.symm⟩ - have hzlo := length_lt_of_bruhat_ne ds' hz.1 (Ne.symm hlo) - have hzhi := length_lt_of_bruhat_ne ds' hz.2 htop - have hnlo : ds.length l < ds.length l+(ds'.length z-ds'.length (f lo)) := by omega - have hnhi : ds.length l+(ds'.length z-ds'.length (f lo)) < ds.length r := by omega - obtain ⟨a,b,hab,ha,hb⟩ := two_interval_elements_length ds lo hi hnlo hnhi - have hfa : ds'.length (f a)=ds'.length z := by have := hlen a; omega - have hfb : ds'.length (f b)=ds'.length z := by have := hlen b; omega - obtain ⟨p,q,hpq,helements⟩ := two_elements_length ds' (by omega : 0 hab (hinj h) - have he : z=f a ∨ z=f b := by grind - rcases he with he | he - · exact ⟨a,he.symm⟩ - · exact ⟨b,he.symm⟩ - -end KLInvariance.Dihedral - -namespace KLInvariance -universe u v u' v' -variable {I : Type u} {W : Type v} [Group W] {M : CoxeterMatrix I} - {I' : Type u'} {W' : Type v'} [Group W'] {M' : CoxeterMatrix I'} - {cs : CoxeterSystem M W} {cs' : CoxeterSystem M' W'} - {u b : W} {u' b' : W'} - -/-- An interval graph isomorphism preserves the exact two-edge intermediate -set, including ambient intermediates not specified as interval data. -/ -theorem intervalIso_twoStep_iff - (e : Interval cs u b ≃o Interval cs' u' b') (x y a c : Interval cs u b) - (hpaths : ∀ z : W, (BruhatStep cs x.val z ∧ BruhatStep cs z y.val) ↔ - z=a.val ∨ z=c.val) (z : W') : - (BruhatStep cs' (e x).val z ∧ BruhatStep cs' z (e y).val) ↔ - z=(e a).val ∨ z=(e c).val := by - constructor - · intro hz - let z' : Interval cs' u' b' := ⟨z, - bruhat_trans cs' (e x).property.1 (Relation.ReflTransGen.single hz.1), - bruhat_trans cs' (Relation.ReflTransGen.single hz.2) (e y).property.2⟩ - have hz₁ : BruhatStep cs x.val (e.symm z').val := by - apply (intervalIso_bruhatStep_iff_general cs cs' e x (e.symm z')).mp - simpa only [e.apply_symm_apply] using hz.1 - have hz₂ : BruhatStep cs (e.symm z').val y.val := by - apply (intervalIso_bruhatStep_iff_general cs cs' e (e.symm z') y).mp - simpa only [e.apply_symm_apply] using hz.2 - rcases (hpaths (e.symm z').val).mp ⟨hz₁,hz₂⟩ with ha | hc - · have he : e.symm z'=a := Subtype.ext ha - have he' : z'=e a := by rw [← he,e.apply_symm_apply] - exact Or.inl (congrArg Subtype.val he') - · have he : e.symm z'=c := Subtype.ext hc - have he' : z'=e c := by rw [← he,e.apply_symm_apply] - exact Or.inr (congrArg Subtype.val he') - · rintro (rfl | rfl) - · have h := (hpaths a.val).mpr (Or.inl rfl) - exact ⟨(intervalIso_bruhatStep_iff_general cs cs' e x a).mpr h.1, - (intervalIso_bruhatStep_iff_general cs cs' e a y).mpr h.2⟩ - · have h := (hpaths c.val).mpr (Or.inr rfl) - exact ⟨(intervalIso_bruhatStep_iff_general cs cs' e x c).mpr h.1, - (intervalIso_bruhatStep_iff_general cs cs' e c y).mpr h.2⟩ - -end KLInvariance - -namespace KLInvariance.TitsSpace.PlaneBasis -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} - {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) -noncomputable section - -def cosetIntervalMap {a₀ u b : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {g k : planeSubgroup M cs P} - (hlo : BruhatLE cs u ((g : W)*a₀)) (hhi : BruhatLE cs ((k : W)*a₀) b) : - Interval B.system g k ↪ Interval cs u b where - toFun z := ⟨(z.val : W)*a₀,bruhat_trans cs hlo (B.coset_bruhat hmin z.property.1), - bruhat_trans cs (B.coset_bruhat hmin z.property.2) hhi⟩ - inj' := by - intro x y he - exact Subtype.ext (Subtype.ext (mul_right_cancel (congrArg Subtype.val he))) - -theorem twoStep_interval_iff {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {g k : planeSubgroup M cs P} (x y : Interval B.system g k) - (hlen : B.system.length y.val=B.system.length x.val+2) : - ∃ a b : Interval B.system g k, a ≠ b ∧ ∀ z : W, - (BruhatStep cs ((x.val : W)*a₀) z ∧ BruhatStep cs z ((y.val : W)*a₀)) ↔ - z=(a.val : W)*a₀ ∨ z=(b.val : W)*a₀ := by - obtain ⟨a,b,hab,hpaths⟩ := Dihedral.two_step_rank_two B.system hlen - have ha := (hpaths a).mpr (Or.inl rfl) - have hb := (hpaths b).mpr (Or.inr rfl) - let ai : Interval B.system g k := ⟨a, - bruhat_trans B.system x.property.1 (Relation.ReflTransGen.single ha.1), - bruhat_trans B.system (Relation.ReflTransGen.single ha.2) y.property.2⟩ - let bi : Interval B.system g k := ⟨b, - bruhat_trans B.system x.property.1 (Relation.ReflTransGen.single hb.1), - bruhat_trans B.system (Relation.ReflTransGen.single hb.2) y.property.2⟩ - have he := (B.coset_step_iff hmin x.val a).mpr ha.1 - have hf := (B.coset_step_iff hmin a y.val).mpr ha.2 - refine ⟨ai,bi,fun h => hab (congrArg Subtype.val h),fun z => ?_⟩ - constructor - · intro hz - let z' : planeSubgroup M cs P := ⟨z*a₀⁻¹,B.twoStep_mem_coset he hf hz.1 hz.2⟩ - have hz' : (z' : W)*a₀=z := by dsimp [z']; group - have hp : BruhatStep B.system x.val z' ∧ BruhatStep B.system z' y.val := by - constructor - · exact (B.coset_step_iff hmin x.val z').mp (hz' ▸ hz.1) - · exact (B.coset_step_iff hmin z' y.val).mp (hz' ▸ hz.2) - rcases (hpaths z').mp hp with hza | hzb - · exact Or.inl (hz'.symm.trans (congrArg (fun q : planeSubgroup M cs P => (q:W)*a₀) hza)) - · exact Or.inr (hz'.symm.trans (congrArg (fun q : planeSubgroup M cs P => (q:W)*a₀) hzb)) - · rintro (rfl | rfl) - · exact ⟨he,hf⟩ - · exact ⟨(B.coset_step_iff hmin x.val b).mpr hb.1, - (B.coset_step_iff hmin b y.val).mpr hb.2⟩ - -end -end KLInvariance.TitsSpace.PlaneBasis - -namespace KLInvariance.TitsSpace.PlaneBasis -open Module -universe u v u' v' -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} - {I' : Type u'} [Fintype I'] {M' : CoxeterMatrix I'} - {W' : Type v'} [Group W'] {cs' : CoxeterSystem M' W'} - {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) -noncomputable section - - -theorem transport_interval {a₀ u b : W} {u' b' : W'} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - {g k : planeSubgroup M cs P} (hgk : BruhatLE B.system g k) - (hrank : B.system.length g+2 ≤ B.system.length k) - (hlo : BruhatLE cs u ((g : W)*a₀)) (hhi : BruhatLE cs ((k : W)*a₀) b) - (e : Interval cs u b ≃o Interval cs' u' b') : - ∃ (P' : Submodule ℝ (I' → ℝ)) (B' : PlaneBasis (M := M') (cs := cs') P') - (a' : W') (F : Interval B.system g k → planeSubgroup M' cs' P'), - (∀ z ∈ planeSubgroup M' cs' P', cs'.length a' ≤ cs'.length (z*a')) ∧ - Function.Injective F ∧ - (∀ z, (F z : W')*a' = (e (B.cosetIntervalMap hmin hlo hhi z)).val) ∧ - (∀ x y, BruhatLE B'.system (F x) (F y) ↔ x ≤ y) ∧ - (∀ x y, BruhatStep B'.system (F x) (F y) ↔ BruhatStep B.system x.val y.val) ∧ - (∀ z, B'.system.length (F z)+B.system.length g = - B'.system.length (F ⟨g,bruhat_refl B.system g,hgk⟩)+B.system.length z.val) ∧ - Set.range F = {z | BruhatLE B'.system (F ⟨g,bruhat_refl B.system g,hgk⟩) z ∧ - BruhatLE B'.system z (F ⟨k,hgk,bruhat_refl B.system k⟩)} := by - let inc := B.cosetIntervalMap hmin hlo hhi - let f : Interval B.system g k → W' := fun z => (e (inc z)).val - let lo : Interval B.system g k := ⟨g,bruhat_refl B.system g,hgk⟩ - have hinj : Function.Injective f := by - intro x y h - exact inc.injective (e.injective (Subtype.ext h)) - have hgraph (x y : Interval B.system g k) (h : BruhatStep B.system x.val y.val) : - BruhatStep cs' (f x) (f y) := by - exact (intervalIso_bruhatStep_iff_general cs cs' e (inc x) (inc y)).mpr - ((B.coset_step_iff hmin x.val y.val).mpr h) - obtain ⟨α,β,hαβ,hplane⟩ := dihedral_image_in_plane B.system f hinj hgraph hgk hrank - let P' := rootPlane α β - obtain ⟨B'⟩ := nonempty_planeBasis α β hαβ - obtain ⟨a',g₀,hg₀,hg₀a,hmin'⟩ := planeCoset_exists_minimal M' cs' P' (f lo) - have hmem (z : Interval B.system g k) : f z*a'⁻¹ ∈ planeSubgroup M' cs' P' := by - convert (planeSubgroup M' cs' P').mul_mem (hplane z) hg₀ using 1 - change f z*a'⁻¹=f z*(f lo)⁻¹*g₀ - rw [hg₀a] - group - let F : Interval B.system g k → planeSubgroup M' cs' P' := fun z => ⟨f z*a'⁻¹,hmem z⟩ - have hF (z : Interval B.system g k) : (F z : W')*a'=f z := by - dsimp [F]; group - have hFinj : Function.Injective F := by - intro x y h - apply hinj - rw [← hF x,← hF y,h] - have hFgraph (x y : Interval B.system g k) (h : BruhatStep B.system x.val y.val) : - BruhatStep B'.system (F x) (F y) := by - apply (B'.coset_step_iff hmin' (F x) (F y)).mp - rw [hF x,hF y] - exact hgraph x y h - have htwo (x y : Interval B.system g k) - (hlen : B.system.length y.val=B.system.length x.val+2) : - B'.system.length (F y)=B'.system.length (F x)+2 := by - obtain ⟨a,c,hac,hpaths⟩ := B.twoStep_interval_iff hmin x y hlen - have hpaths' (z : W') : (BruhatStep cs' (f x) z ∧ BruhatStep cs' z (f y)) ↔ - z=f a ∨ z=f c := intervalIso_twoStep_iff e (inc x) (inc y) (inc a) (inc c) hpaths z - have hpa := (hpaths' (f a)).mpr (Or.inl rfl) - have hxa : BruhatStep B'.system (F x) (F a) := by - apply (B'.coset_step_iff hmin' (F x) (F a)).mp - simpa only [hF] using hpa.1 - have hay : BruhatStep B'.system (F a) (F y) := by - apply (B'.coset_step_iff hmin' (F a) (F y)).mp - simpa only [hF] using hpa.2 - apply Dihedral.rank_two_of_two_step_bound B'.system hxa hay (b := F c) - intro z hxz hzy - have hp₁ := (B'.coset_step_iff hmin' (F x) z).mpr hxz - have hp₂ := (B'.coset_step_iff hmin' z (F y)).mpr hzy - rw [hF x] at hp₁ - rw [hF y] at hp₂ - rcases (hpaths' ((z : W')*a')).mp ⟨hp₁,hp₂⟩ with he | he - · exact Or.inl (Subtype.ext (mul_right_cancel (he.trans (hF a).symm))) - · exact Or.inr (Subtype.ext (mul_right_cancel (he.trans (hF c).symm))) - have hlen := Dihedral.map_length_affine B.system B'.system F hFgraph htwo hgk hrank - have horder (x y : Interval B.system g k) : BruhatLE B'.system (F x) (F y) ↔ x ≤ y := by - change BruhatLE B'.system (F x) (F y) ↔ BruhatLE B.system x.val y.val - rw [Dihedral.bruhat_iff_length_lt_or_eq,Dihedral.bruhat_iff_length_lt_or_eq] - have hx := hlen x - have hy := hlen y - constructor - · rintro (h | h) - · left; omega - · exact Or.inr (congrArg Subtype.val (hFinj h)) - · rintro (h | h) - · left; omega - · exact Or.inr (congrArg F (Subtype.ext h)) - refine ⟨P',B',a',F,hmin',hFinj,hF,horder,?_,hlen,?_⟩ - · intro x y - rw [Dihedral.step_iff_odd,Dihedral.step_iff_odd,Nat.odd_iff,Nat.odd_iff] - have hx := hlen x - have hy := hlen y - omega - · exact Dihedral.range_eq_interval_of_rank_two B.system B'.system F hFinj - hFgraph htwo hgk hrank - -end -end KLInvariance.TitsSpace.PlaneBasis - -end - - -section - - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section - -theorem inverted_of_positive_combination (w : W) (a b c : PositiveRoot M cs) - {r s : ℝ} (hr : 0 ≤ r) (hs : 0 ≤ s) - (hc : c.val = r • a.val + s • b.val) - (ha : rootInverted w a) (hb : rootInverted w b) : - rootInverted w c := by - intro i - rw [hc, map_add, map_smul, map_smul] - exact add_nonpos (mul_nonpos_of_nonneg_of_nonpos hr (ha i)) - (mul_nonpos_of_nonneg_of_nonpos hs (hb i)) - -/-- Incoming graph labels are actual inversions at their upper vertex. -/ -theorem graphRoot_inverted_target {x y : W} (h : BruhatStep cs x y) : - rootInverted y (graphRoot h) := by - apply ((graphRoot_represents h).inversion_iff (graphRoot h).property.2 y).mpr - refine ⟨h.label_reflection, ?_⟩ - have he : (y*x⁻¹)*y=x := by - calc - (y*x⁻¹)*y = (y*x⁻¹)*((y*x⁻¹)*x) := by group - _ = x := by rw [← mul_assoc,h.label_reflection.mul_self,one_mul] - simpa only [he] using h.1 - -/-- Outgoing graph labels are actual noninversions at their lower vertex. -/ -theorem graphRoot_not_inverted_source {x y : W} (h : BruhatStep cs x y) : - ¬ rootInverted x (graphRoot h) := by - intro hi - have hh := ((graphRoot_represents h).inversion_iff (graphRoot h).property.2 x).mp hi - have he : (y*x⁻¹)*x=y := by group - have hh' := hh.2 - rw [he] at hh' - exact lt_asymm h.1 hh' - -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -/-- In a plane with its first simple root inverted, every noninverted root -is later than every inverted root. This uses convexity, not a signed-index -formula for a particular realization. -/ -theorem slope_lt_of_inverted_left (w : W) (hl : rootInverted w B.left) - (a b : PositiveRoot M cs) (haP : a.val ∈ P) (hbP : b.val ∈ P) - (ha : rootInverted w a) (hb : ¬ rootInverted w b) : - geometricSlope a < geometricSlope b := by - by_contra h - have hba : geometricSlope b < geometricSlope a := - lt_of_le_of_ne (le_of_not_gt h) (fun he => hb (geometricSlope_injective he ▸ ha)) - have hlb : geometricSlope B.left < geometricSlope b := - lt_of_le_of_ne (B.left_min b hbP) (fun he => hb (geometricSlope_injective he ▸ hl)) - have heq : rootPlane B.left a = P := - rootPlane_eq_of_mem B.left B.right B.left a B.distinct - (Submodule.subset_span (Set.mem_insert _ _)) - (B.plane_eq.ge haP) (fun he => by rw [he] at hlb; exact (lt_asymm hlb hba)) |>.trans B.plane_eq - obtain ⟨r,s,hr,hs,hc⟩ := positive_combination_of_slope_between B.left a b - (heq.symm ▸ hbP) hlb hba - exact hb (inverted_of_positive_combination w B.left a b hr.le hs.le hc hl ha) - -/-- The other angular cut, when the last simple root is inverted. -/ -theorem slope_lt_of_inverted_right (w : W) (hr : rootInverted w B.right) - (a b : PositiveRoot M cs) (haP : a.val ∈ P) (hbP : b.val ∈ P) - (ha : rootInverted w a) (hb : ¬ rootInverted w b) : - geometricSlope b < geometricSlope a := by - by_contra h - have hab : geometricSlope a < geometricSlope b := - lt_of_le_of_ne (le_of_not_gt h) (fun he => hb (geometricSlope_injective he ▸ ha)) - have hbr : geometricSlope b < geometricSlope B.right := - lt_of_le_of_ne (B.right_max b hbP) (fun he => hb (geometricSlope_injective he ▸ hr)) - have har : a ≠ B.right := by - intro he - rw [he] at hab - exact lt_asymm hbr hab - have heq : rootPlane a B.right = P := - (rootPlane_eq_of_mem B.left B.right a B.right B.distinct - (B.plane_eq.ge haP) (Submodule.subset_span (Set.mem_insert_of_mem _ (Set.mem_singleton _))) - har).trans B.plane_eq - obtain ⟨r,s,hrr,hss,hc⟩ := positive_combination_of_slope_between a B.right b - (heq.symm ▸ hbP) hab hbr - exact hb (inverted_of_positive_combination w a B.right b hrr.le hss.le hc ha hr) - -/-- In the mixed-sign case the angular cut is determined by the first -canonical simple root. In particular the comparison of consecutive path -labels depends only on their middle vertex. -/ -theorem slope_lt_iff_inverted_left (w : W) - (a b : PositiveRoot M cs) (haP : a.val ∈ P) (hbP : b.val ∈ P) - (ha : rootInverted w a) (hb : ¬ rootInverted w b) : - geometricSlope a < geometricSlope b ↔ rootInverted w B.left := by - constructor - · intro hab - by_contra hl - have hr : rootInverted w B.right := by - by_contra hr - obtain ⟨r,s,hrr,hss,he⟩ := B.positive_cone a haP - exact noninverted_of_positive_combination w B.left B.right a hrr hss he hl hr ha - exact lt_asymm hab (B.slope_lt_of_inverted_right w hr a b haP hbP ha hb) - · intro hl - exact B.slope_lt_of_inverted_left w hl a b haP hbP ha hb - -/-- The exact middle-vertex test for two ascending graph arrows with both -labels in this root plane. -/ -theorem consecutive_slopes_iff {x y z : W} - (hxy : BruhatStep cs x y) (hyz : BruhatStep cs y z) - (ha : (graphRoot hxy).val ∈ P) (hb : (graphRoot hyz).val ∈ P) : - geometricSlope (graphRoot hxy) < geometricSlope (graphRoot hyz) ↔ - rootInverted y B.left := - B.slope_lt_iff_inverted_left y _ _ ha hb - (graphRoot_inverted_target hxy) (graphRoot_not_inverted_source hyz) - -end PlaneBasis -end -end KLInvariance.TitsSpace - -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section - -/-- The genuine diagram automorphism of an arbitrary rank-two Coxeter system, -including the infinite one. -/ -def swapHom (cs : CoxeterSystem M W) : W →* W := - cs.lift ⟨fun i => cs.simple (!i), by - intro i j - have he : M i j = M (!i) (!j) := by - cases i <;> cases j - · simp - · exact M.symmetric _ _ - · exact M.symmetric _ _ - · simp - rw [he] - exact cs.simple_mul_simple_pow _ _⟩ - -@[simp] theorem swapHom_simple (cs : CoxeterSystem M W) (i : Bool) : - swapHom cs (cs.simple i) = cs.simple (!i) := cs.lift_apply_simple _ i - -@[simp] theorem swapHom_involutive (cs : CoxeterSystem M W) : - Function.Involutive (swapHom cs) := by - intro w - apply cs.simple_induction w - · intro i - simp - · simp - · intro a b ha hb - simp only [map_mul,ha,hb] - -def swap (cs : CoxeterSystem M W) : W ≃* W where - toFun := swapHom cs - invFun := swapHom cs - left_inv := swapHom_involutive cs - right_inv := swapHom_involutive cs - map_mul' := map_mul (swapHom cs) - -@[simp] theorem swap_simple (cs : CoxeterSystem M W) (i : Bool) : - swap cs (cs.simple i) = cs.simple (!i) := swapHom_simple cs i - -@[simp] theorem swap_swap (cs : CoxeterSystem M W) (w : W) : - swap cs (swap cs w) = w := swapHom_involutive cs w - -theorem swap_wordProd (cs : CoxeterSystem M W) (ω : List Bool) : - swap cs (cs.wordProd ω) = cs.wordProd (ω.map Bool.not) := by - induction ω with - | nil => simp - | cons i ω ih => - simp only [cs.wordProd_cons, map_mul, swap_simple, List.map_cons, ih] - -@[simp] theorem length_swap (cs : CoxeterSystem M W) (w : W) : - cs.length (swap cs w) = cs.length w := by - have hle (z : W) : cs.length (swap cs z) ≤ cs.length z := by - obtain ⟨ω,hω,rfl⟩ := cs.exists_isReduced z - rw [swap_wordProd, hω.eq] - simpa using cs.length_wordProd_le (ω.map Bool.not) - exact le_antisymm (hle w) (by simpa using hle (swap cs w)) - -@[simp] theorem descent_swap (cs : CoxeterSystem M W) (w : W) (i : Bool) : - cs.IsLeftDescent (swap cs w) i ↔ cs.IsLeftDescent w (!i) := by - unfold CoxeterSystem.IsLeftDescent - rw [length_swap, ← Bool.not_not i, ← swap_simple, ← map_mul, length_swap] - simp - -/-- A nonzero length below an existing greater length has exactly one left -simple descent. This is not asserted for a finite dihedral longest element. -/ -theorem unique_leftDescent (cs : CoxeterSystem M W) {w z : W} - (hw : 0 < cs.length w) (hz : cs.length w < cs.length z) : - ∃! i : Bool, cs.IsLeftDescent w i := by - obtain ⟨i,hi⟩ := cs.exists_leftDescent_of_ne_one (w := w) (by - intro he - rw [he,cs.length_one] at hw - omega) - refine ⟨i,hi,?_⟩ - intro j hj - by_contra hji - have hj' : j = !i := by cases i <;> cases j <;> simp_all - have he : cs.wordProd (alt i (cs.length w)) = - cs.wordProd (alt (!i) (cs.length w)) := by - rw [← eq_alt_of_descent cs i hi, ← hj', ← eq_alt_of_descent cs j hj] - obtain ⟨a,b,hab,hab'⟩ := two_elements_length cs hw hz - have all_eq (v : W) (hv : cs.length v = cs.length w) : v=w := by - obtain ⟨k,hk⟩ := exists_alt cs v - rw [hv] at hk - have hki : k=i ∨ k=(!i) := by cases k <;> cases i <;> simp - rcases hki with hki | hki - · rw [hki] at hk - exact hk.trans (eq_alt_of_descent cs i hi).symm - · rw [hki] at hk - exact hk.trans (he.symm.trans (eq_alt_of_descent cs i hi).symm) - exact hab ((all_eq a ((hab' a).mpr (.inl rfl))).trans - (all_eq b ((hab' b).mpr (.inr rfl))).symm) - -/-- Internally, the diagram involution interchanges the two unique-descent -vertices of each rank. -/ -theorem descent_swap_false_iff_not (cs : CoxeterSystem M W) {w z : W} - (hw : 0 < cs.length w) (hz : cs.length w < cs.length z) : - cs.IsLeftDescent (swap cs w) false ↔ ¬ cs.IsLeftDescent w false := by - rw [descent_swap] - obtain ⟨i,hi,hu⟩ := unique_leftDescent cs hw hz - cases i - · constructor - · intro h - have hh := hu true h - contradiction - · exact fun h => (h hi).elim - · constructor - · intro _ h - have hh := hu false h - contradiction - · exact fun _ => hi - -end -end KLInvariance.Dihedral - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) - -/-- The ambient sign of a canonical plane root in a minimal coset is the -intrinsic simple-descent sign, with the original left labels. -/ -theorem simpleRoot_inverted_coset_iff {a₀ : W} - (hmin : ∀ z ∈ planeSubgroup M cs P, cs.length a₀ ≤ cs.length (z*a₀)) - (w : planeSubgroup M cs P) (i : Bool) : - rootInverted ((w : W)*a₀) (B.simpleRoot i) ↔ B.system.IsLeftDescent w i := by - change (∀ k, action M cs ((w : W)*a₀)⁻¹ (B.simpleRoot i).val k ≤ 0) ↔ _ - rw [root_inversion_coset_iff hmin w.property (B.simpleRoot i).property.1 - (B.simpleRoot_mem i)] - have hr : Represents M cs (B.system.simple i : W) (B.simpleRoot i).val := by - rw [B.system_simple] - exact rootReflection_represents M cs _ - rw [B.inversion_iff hr (B.simpleRoot_mem i) (B.simpleRoot i).property.2 w] - exact B.system.isLeftInversion_simple_iff_isLeftDescent w i - -/-- Geometric label of an intrinsic graph edge, taken in the actual ambient -root plane rather than an abstract alternate representation. -/ -def edgeRoot {x y : planeSubgroup M cs P} (h : BruhatStep B.system x y) : - PositiveRoot M cs := graphRoot ((B.bruhatStep_iff x y).mpr h) - -theorem edgeRoot_plane {x y : planeSubgroup M cs P} (h : BruhatStep B.system x y) : - (B.edgeRoot h).val ∈ P := by - apply (Represents.planeSubgroup_mem_iff M cs (graphRoot_represents - ((B.bruhatStep_iff x y).mpr h))).mp - exact (planeSubgroup M cs P).mul_mem y.property - ((planeSubgroup M cs P).inv_mem x.property) - -/-- In the intrinsic system, the middle-vertex test uses its actual left -simple generator; it therefore applies to any induced dihedral realization. -/ -theorem edgeRoot_slopes_iff {x y z : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (hyz : BruhatStep B.system y z) : - geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hyz) ↔ - B.system.IsLeftDescent y false := by - unfold edgeRoot - rw [B.consecutive_slopes_iff ((B.bruhatStep_iff x y).mpr hxy) - ((B.bruhatStep_iff y z).mpr hyz) (B.edgeRoot_plane hxy) (B.edgeRoot_plane hyz)] - have hmin : ∀ z ∈ planeSubgroup M cs P, cs.length (1:W) ≤ cs.length (z*1) := - fun z _ => by simp - simpa only [mul_one, simpleRoot, Bool.false_eq_true, ↓reduceIte] using - B.simpleRoot_inverted_coset_iff hmin y false - -end PlaneBasis -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Geometric orders adapted to a fixed upper vertex. These are honest -ratios of linear functionals, with a strictly positive denominator. They -will be used only as a permissible choice of the source's schedule. -/ -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - -def simplePositive (i : I) : PositiveRoot M cs := - ⟨root i, ⟨1,i,by simp⟩, root_nonneg i⟩ - -@[simp] theorem simplePositive_val (i : I) : - (simplePositive (M := M) (cs := cs) i).val = root i := rfl - -@[simp] theorem rootRef_simplePositive (i : I) : - rootRef (simplePositive (M := M) (cs := cs) i) = cs.simple i := by - exact (rootReflection_represents M cs _).reflection_unique ⟨1,i,by simp,by simp⟩ - -theorem simplePositive_injective : Function.Injective (simplePositive (M := M) (cs := cs)) := by - intro i j hij - have he := congrArg (fun a : PositiveRoot M cs => a.val i) hij - by_contra hne - simp [simplePositive, root, hne] at he - -theorem coordinate_sum (a : I → ℝ) : ∑ i, a i • root i = a := by - ext j - simp [root, Pi.single_apply, Finset.sum_apply] - -theorem dual_coordinate_sum (h : Module.Dual ℝ (I → ℝ)) (a : I → ℝ) : - h a = ∑ i, a i * h (root i) := by - conv_lhs => rw [← coordinate_sum a] - simp only [map_sum,map_smul,smul_eq_mul] - -def PositiveFunctional (h : Module.Dual ℝ (I → ℝ)) : Prop := ∀ i, 0 < h (root i) - -theorem PositiveFunctional.root_pos {h : Module.Dual ℝ (I → ℝ)} - (hh : PositiveFunctional h) (a : PositiveRoot M cs) : 0 < h a.val := by - rw [dual_coordinate_sum] - obtain ⟨i,hi⟩ : ∃ i, a.val i ≠ 0 := by - by_contra hn - push Not at hn - exact a.property.1.ne_zero (funext hn) - exact Finset.sum_pos' (fun j _ => mul_nonneg (a.property.2 j) (hh j).le) - ⟨i,Finset.mem_univ _,mul_pos (lt_of_le_of_ne' (a.property.2 i) hi) (hh i)⟩ - -theorem height_positive : PositiveFunctional (height (I := I)) := by - intro i - simp [height,root] - -/-- Both functionals are actual dual vectors; the root order is not a -label-carrying addition to the interval isomorphism. -/ -structure RatioOrder where - denominator : Module.Dual ℝ (I → ℝ) - numerator : Module.Dual ℝ (I → ℝ) - positive : PositiveFunctional denominator - generic : Function.Injective (fun a : PositiveRoot M cs => numerator a.val / denominator a.val) - -namespace RatioOrder -variable (O : RatioOrder (M := M) (cs := cs)) - -def slope (a : PositiveRoot M cs) : ℝ := O.numerator a.val / O.denominator a.val - -theorem denominator_pos (a : PositiveRoot M cs) : 0 < O.denominator a.val := - O.positive.root_pos a - -theorem slope_injective : Function.Injective O.slope := O.generic - -/-- The cut at zero is the genuine inversion set of the upper vertex. -/ -def Adapted (y : W) : Prop := ∀ a : PositiveRoot M cs, - (O.slope a < 0 ↔ rootInverted y a) ∧ O.slope a ≠ 0 - -theorem simple_lower_bound (i : I) - (hi : ∀ j, O.slope (simplePositive i) ≤ O.slope (simplePositive j)) - (a : PositiveRoot M cs) : O.slope (simplePositive i) ≤ O.slope a := by - change O.slope (simplePositive i) ≤ O.numerator a.val / O.denominator a.val - rw [le_div_iff₀ (O.denominator_pos a)] - rw [dual_coordinate_sum O.numerator a.val, dual_coordinate_sum O.denominator a.val, - Finset.mul_sum] - apply Finset.sum_le_sum - intro j _ - have hj := (le_div_iff₀ (O.positive j)).mp (hi j) - change O.slope (simplePositive i) * O.denominator (root j) ≤ O.numerator (root j) at hj - nlinarith [mul_nonneg (a.property.2 j) (sub_nonneg.mpr hj)] - -theorem exists_least_simple [Nonempty I] : ∃ i : I, - ∀ a : PositiveRoot M cs, O.slope (simplePositive i) ≤ O.slope a := by - obtain ⟨i,_,hi⟩ := Finset.exists_min_image (Finset.univ : Finset I) - (fun i => O.slope (simplePositive i)) Finset.univ_nonempty - exact ⟨i, O.simple_lower_bound i (fun j => hi j (Finset.mem_univ j))⟩ - -theorem least_simple_descent {y : W} (hy : y ≠ 1) (ha : O.Adapted y) : - ∃ i : I, cs.IsLeftDescent y i ∧ - O.slope (simplePositive i) < 0 ∧ - ∀ a : PositiveRoot M cs, O.slope (simplePositive i) ≤ O.slope a := by - obtain ⟨j,hj⟩ := cs.exists_leftDescent_of_ne_one hy - let : Nonempty I := ⟨j⟩ - obtain ⟨i,hi⟩ := O.exists_least_simple - have hjr : rootInverted y (simplePositive (M := M) (cs := cs) j) := by - apply ((rootReflection_represents M cs _).inversion_iff (simplePositive j).property.2 y).mpr - simpa only [rootRef_simplePositive] using (show cs.IsLeftInversion y (cs.simple j) from - ⟨cs.isReflection_simple j,hj⟩) - have hi0 := lt_of_le_of_lt (hi (simplePositive j)) ((ha _).1.mpr hjr) - refine ⟨i,?_,hi0,hi⟩ - have hir := ((rootReflection_represents M cs _).inversion_iff - (simplePositive i).property.2 y).mp ((ha _).1.mp hi0) - simpa only [rootRef_simplePositive, CoxeterSystem.IsLeftDescent] using hir.2 - - -/-- A functional in the chamber indexed by y has exactly Inv(y) as its -negative roots. This is stronger data used only to construct the order. -/ -def Chamber (y : W) : Prop := ∀ i, 0 < O.numerator (action M cs y (root i)) - -theorem adapted_of_chamber {y : W} (hc : O.Chamber y) : O.Adapted y := by - let f : Module.Dual ℝ (I → ℝ) := O.numerator.comp (action M cs y).toLinearMap - have hf : PositiveFunctional f := hc - intro a - have he (v : I → ℝ) : f (action M cs y⁻¹ v) = O.numerator v := by - change O.numerator (action M cs y (action M cs y⁻¹ v)) = _ - rw [← LinearEquiv.mul_apply, ← map_mul, mul_inv_cancel, map_one] - rfl - by_cases ha : rootInverted y a - · have hv := hf.root_pos (positiveAction y⁻¹ a) - rw [positiveAction_eq_of_nonpos _ _ ha, map_neg, he] at hv - have hn : O.slope a < 0 := div_neg_of_neg_of_pos (by linarith) (O.denominator_pos a) - exact ⟨iff_of_true hn ha, hn.ne⟩ - · have hp := (not_rootInverted_iff y a).mp ha - have hv := hf.root_pos (positiveAction y⁻¹ a) - rw [positiveAction_eq_of_nonneg _ _ hp, he] at hv - have hn : 0 < O.slope a := div_pos hv (O.denominator_pos a) - exact ⟨iff_of_false (not_lt.mpr hn.le) ha, hn.ne'⟩ - -end RatioOrder - -/-- The generic functional can be chosen in any prescribed Coxeter chamber, -not just outside the countably many equality hyperplanes. The explicit -polynomial perturbation makes both requirements simultaneous. -/ -theorem exists_ratioOrder_chamber_height (y : W) : - ∃ O : RatioOrder (M := M) (cs := cs), O.Chamber y ∧ O.denominator=height := by - classical - let := countable_Positiveroot M cs - let f₀ : Module.Dual ℝ (I → ℝ) := height.comp (action M cs y⁻¹).toLinearMap - let f : ℝ → Module.Dual ℝ (I → ℝ) := fun t => - f₀ + t • ReflectionSchedules.momentFunctional t - have hf (t : ℝ) (v : I → ℝ) : f t v = f₀ v + - t * (ReflectionSchedules.coordinatePolynomial v).eval t := by - simp [f,ReflectionSchedules.coordinatePolynomial_eval] - let U : Set ℝ := {t | ∀ i, 0 < f t (action M cs y (root i))} - have hu : IsOpen U := by - change IsOpen {t | ∀ i, 0 < f t (action M cs y (root i))} - rw [Set.ofPred_forall] - apply isOpen_iInter_of_finite - intro i - apply isOpen_lt continuous_const - simp only [hf] - exact continuous_const.add (continuous_id.mul (Polynomial.continuous _)) - have h0 : 0 ∈ U := by - intro i - simp only [f,zero_smul,add_zero] - change 0 < height (action M cs y⁻¹ (action M cs y (root i))) - rw [← LinearEquiv.mul_apply,← map_mul,inv_mul_cancel,map_one] - exact height_positive i - let P := {p : PositiveRoot M cs × PositiveRoot M cs // p.1 ≠ p.2} - let v : P → (I → ℝ) := fun p => normalizedRoot p.val.1 - normalizedRoot p.val.2 - let d : P → Polynomial ℝ := fun p => Polynomial.C (f₀ (v p)) + - Polynomial.X * ReflectionSchedules.coordinatePolynomial (v p) - have hd : ∀ p, d p ≠ 0 := by - intro p hp - have hz := congrArg (fun q : Polynomial ℝ => q.eval 0) hp - have hz' : f₀ (v p) = 0 := by simpa [d] using hz - have hq : ReflectionSchedules.coordinatePolynomial (v p) = 0 := by - simpa only [d,hz',Polynomial.C_0,zero_add,mul_eq_zero,Polynomial.X_ne_zero,false_or] using hp - have hv : v p = 0 := ReflectionSchedules.coordinatePolynomial_injective (by simpa [ReflectionSchedules.coordinatePolynomial] using hq) - exact p.property (normalizedRoot_injective (sub_eq_zero.mp hv)) - let bad : Set ℝ := ⋃ p : P, {t | (d p).IsRoot t} - have hbad : bad.Countable := Set.countable_iUnion - (fun p => (Polynomial.finite_setOfPred_isRoot (hd p)).countable) - obtain ⟨t,htU,ht⟩ := (hbad.dense_compl ℝ).inter_open_nonempty U hu ⟨0,h0⟩ - have hinj : Function.Injective (fun a : PositiveRoot M cs => f t a.val / height a.val) := by - intro a b heq - by_contra hab - apply ht - apply Set.mem_iUnion.mpr - refine ⟨⟨(a,b),hab⟩,?_⟩ - change (d ⟨(a,b),hab⟩).eval t = 0 - dsimp only [d] - rw [Polynomial.eval_add,Polynomial.eval_C,Polynomial.eval_mul,Polynomial.eval_X,← hf] - change f t (normalizedRoot a - normalizedRoot b) = 0 - rw [map_sub] - apply sub_eq_zero.mpr - simpa only [normalizedRoot,map_smul,smul_eq_mul,div_eq_mul_inv,mul_comm] using heq - exact ⟨⟨height,f t,height_positive,hinj⟩,htU,rfl⟩ - -theorem exists_ratioOrder_chamber (y : W) : - ∃ O : RatioOrder (M := M) (cs := cs), O.Chamber y := by - obtain ⟨O,hO,_⟩ := exists_ratioOrder_chamber_height (M := M) (cs := cs) y - exact ⟨O,hO⟩ - -@[simp] theorem positiveAction_simplePositive (i : I) : - positiveAction (cs.simple i) (simplePositive (M := M) (cs := cs) i) = simplePositive i := by - apply Subtype.ext - rw [positiveAction_eq_of_nonpos] - · simp only [simplePositive_val,action_simple_root,neg_neg] - · simpa only [simplePositive_val,action_simple_root,Pi.neg_apply,neg_nonpos] using root_nonneg i - -theorem simple_action_nonneg (i : I) (a : PositiveRoot M cs) - (ha : a ≠ simplePositive i) : ∀ k, 0 ≤ action M cs (cs.simple i) a.val k := by - apply a.property.1.act (cs.simple i) |>.sign.resolve_right - intro hn - exact ha (Subtype.ext (a.property.1.eq_simple_of_nonpos a.property.2 i hn)) - -theorem simple_positiveAction_val (i : I) (a : PositiveRoot M cs) - (ha : a ≠ simplePositive i) : - (positiveAction (cs.simple i) a).val = action M cs (cs.simple i) a.val := - positiveAction_eq_of_nonneg _ _ (simple_action_nonneg i a ha) - -theorem simple_positiveAction_ne (i : I) (a : PositiveRoot M cs) - (ha : a ≠ simplePositive i) : positiveAction (cs.simple i) a ≠ simplePositive i := by - intro he - apply ha - exact (positiveActionEquiv (cs.simple i)).injective (he.trans (positiveAction_simplePositive i).symm) - -theorem exists_uniform_pos_lt (v : I → ℝ) (hv : ∀ i, 0 < v i) : - ∃ ε : ℝ, 0 < ε ∧ ∀ i, ε < v i := by - have aux (s : Finset I) : ∃ ε : ℝ, 0 < ε ∧ ∀ i ∈ s, ε < v i := by - induction s using Finset.induction_on with - | empty => exact ⟨1,by norm_num,by simp⟩ - | @insert a s ha ih => - obtain ⟨ε,hε,hlt⟩ := ih - refine ⟨min ε (v a / 2),lt_min hε (half_pos (hv a)),?_⟩ - intro i hi - rcases Finset.mem_insert.mp hi with rfl|hi - · exact lt_of_le_of_lt (min_le_right _ _) (half_lt_self (hv i)) - · exact lt_of_le_of_lt (min_le_left _ _) (hlt i hi) - obtain ⟨ε,hε,hlt⟩ := aux Finset.univ - exact ⟨ε,hε,fun i => hlt i (Finset.mem_univ i)⟩ - -namespace RatioOrder -variable (O : RatioOrder (M := M) (cs := cs)) - -def turnNumerator (i : I) : Module.Dual ℝ (I → ℝ) := - O.numerator.comp (action M cs (cs.simple i)).toLinearMap - -def turnDenominator (i : I) (k : ℝ) : Module.Dual ℝ (I → ℝ) := - (O.numerator - k • O.denominator).comp (action M cs (cs.simple i)).toLinearMap - -theorem exists_turn_parameter (i : I) (hi0 : O.slope (simplePositive i) < 0) - (hi : ∀ a : PositiveRoot M cs, O.slope (simplePositive i) ≤ O.slope a) : - ∃ k : ℝ, k < 0 ∧ O.slope (simplePositive i) < k ∧ - PositiveFunctional (O.turnDenominator i k) := by - let c := O.slope (simplePositive i) - let v : I → ℝ := fun j => if j=i then -c else - O.slope (positiveAction (cs.simple i) (simplePositive j)) - c - have hv : ∀ j, 0 < v j := by - intro j - by_cases hj : j=i - · simp only [v,ite_eq_left hj] - exact neg_pos.mpr hi0 - · simp only [v,ite_eq_right hj] - apply sub_pos.mpr - apply lt_of_le_of_ne (hi _) - intro he - exact simple_positiveAction_ne i (simplePositive j) - (fun hh => hj (simplePositive_injective hh)) (O.slope_injective he.symm) - obtain ⟨ε,hε,hεv⟩ := exists_uniform_pos_lt v hv - have hεc : ε < -c := by simpa only [v,ite_eq_left rfl] using hεv i - refine ⟨c+ε,by linarith,by dsimp [c]; linarith,?_⟩ - intro j - change 0 < O.numerator (action M cs (cs.simple i) (root j)) - - (c+ε)*O.denominator (action M cs (cs.simple i) (root j)) - by_cases hj : j=i - · subst j - rw [action_simple_root,map_neg,map_neg] - have hc : c * O.denominator (root i) = O.numerator (root i) := by - exact div_mul_cancel₀ _ (O.positive i).ne' - nlinarith [mul_pos hε (O.positive i)] - · let a := positiveAction (cs.simple i) (simplePositive (M := M) (cs := cs) j) - have ha : a.val = action M cs (cs.simple i) (root j) := - simple_positiveAction_val i (simplePositive j) (fun hh => hj (simplePositive_injective hh)) - rw [← ha] - have hvj : ε < O.slope a - c := by simpa only [v,ite_eq_right hj] using hεv j - have hlt : c+ε < O.slope a := by linarith - exact sub_pos.mpr ((lt_div_iff₀ (O.denominator_pos a)).mp hlt) - -theorem turn_ratio_injective (i : I) (k : ℝ) (hk : k ≠ 0) - (hp : PositiveFunctional (O.turnDenominator i k)) : - Function.Injective (fun a : PositiveRoot M cs => - O.turnNumerator i a.val / O.turnDenominator i k a.val) := by - intro a b hab - have hh (a : PositiveRoot M cs) : O.denominator (action M cs (cs.simple i) a.val) ≠ 0 := by - rcases (a.property.1.act (cs.simple i)).sign with hpos|hneg - · have h := O.denominator_pos (positiveAction (cs.simple i) a) - rw [positiveAction_eq_of_nonneg _ _ hpos] at h - exact h.ne' - · have h := O.denominator_pos (positiveAction (cs.simple i) a) - rw [positiveAction_eq_of_nonpos _ _ hneg,map_neg] at h - exact (neg_pos.mp h).ne - have hc := (div_eq_div_iff (hp.root_pos a).ne' (hp.root_pos b).ne').mp hab - change O.numerator (action M cs (cs.simple i) a.val) * - (O.numerator (action M cs (cs.simple i) b.val) - - k*O.denominator (action M cs (cs.simple i) b.val)) = - O.numerator (action M cs (cs.simple i) b.val) * - (O.numerator (action M cs (cs.simple i) a.val) - - k*O.denominator (action M cs (cs.simple i) a.val)) at hc - have hcross : O.numerator (action M cs (cs.simple i) a.val) * - O.denominator (action M cs (cs.simple i) b.val) = - O.numerator (action M cs (cs.simple i) b.val) * - O.denominator (action M cs (cs.simple i) a.val) := by - apply sub_eq_zero.mp - apply (mul_eq_zero.mp (show k * (O.numerator (action M cs (cs.simple i) a.val) * - O.denominator (action M cs (cs.simple i) b.val) - - O.numerator (action M cs (cs.simple i) b.val) * - O.denominator (action M cs (cs.simple i) a.val)) = 0 by nlinarith [hc])).resolve_left hk - have he := (div_eq_div_iff (hh a) (hh b)).mpr hcross - have hval (a : PositiveRoot M cs) : - O.numerator (action M cs (cs.simple i) a.val) / - O.denominator (action M cs (cs.simple i) a.val) = - O.slope (positiveAction (cs.simple i) a) := by - unfold slope - rcases (a.property.1.act (cs.simple i)).sign with hpos|hneg - · rw [positiveAction_eq_of_nonneg _ _ hpos] - · rw [positiveAction_eq_of_nonpos _ _ hneg,map_neg,map_neg,neg_div_neg_eq] - rw [hval a,hval b] at he - exact (positiveActionEquiv (cs.simple i)).injective (O.slope_injective he) - -def turn (i : I) (k : ℝ) (hk : k ≠ 0) - (hp : PositiveFunctional (O.turnDenominator i k)) : RatioOrder (M := M) (cs := cs) := - ⟨O.turnDenominator i k,O.turnNumerator i,hp,O.turn_ratio_injective i k hk hp⟩ - - -theorem turn_chamber (i : I) (k : ℝ) (hk : k ≠ 0) - (hp : PositiveFunctional (O.turnDenominator i k)) {y : W} (hy : O.Chamber y) : - (O.turn i k hk hp).Chamber (cs.simple i * y) := by - intro j - change 0 < O.numerator (action M cs (cs.simple i) - (action M cs (cs.simple i * y) (root j))) - rw [← LinearEquiv.mul_apply,← map_mul,cs.simple_mul_simple_cancel_left] - exact hy j - -theorem turn_simple_greatest (i : I) (k : ℝ) (hk : k < 0) - (hp : PositiveFunctional (O.turnDenominator i k)) (a : PositiveRoot M cs) - (ha : a ≠ simplePositive i) : - (O.turn i k hk.ne hp).slope a < (O.turn i k hk.ne hp).slope (simplePositive i) := by - have hlt : (O.turn i k hk.ne hp).slope a < 1 := by - apply (div_lt_iff₀ (hp.root_pos a)).mpr - change O.numerator (action M cs (cs.simple i) a.val) < - 1 * (O.numerator (action M cs (cs.simple i) a.val) - - k * O.denominator (action M cs (cs.simple i) a.val)) - have hap := O.denominator_pos (positiveAction (cs.simple i) a) - rw [simple_positiveAction_val i a ha] at hap - nlinarith [mul_neg_of_neg_of_pos hk hap] - have hgt : 1 < (O.turn i k hk.ne hp).slope (simplePositive i) := by - apply (lt_div_iff₀ (hp.root_pos (simplePositive i))).mpr - change 1 * (O.numerator (action M cs (cs.simple i) (root i)) - - k * O.denominator (action M cs (cs.simple i) (root i))) < - O.numerator (action M cs (cs.simple i) (root i)) - rw [action_simple_root,map_neg,map_neg] - nlinarith [mul_neg_of_neg_of_pos hk (O.positive i)] - exact hlt.trans hgt - -theorem turn_slope_lt_iff (i : I) (k : ℝ) (hk : k < 0) - (hp : PositiveFunctional (O.turnDenominator i k)) - (a b : PositiveRoot M cs) (ha : a ≠ simplePositive i) (hb : b ≠ simplePositive i) : - (O.turn i k hk.ne hp).slope (positiveAction (cs.simple i) a) < - (O.turn i k hk.ne hp).slope (positiveAction (cs.simple i) b) ↔ O.slope a < O.slope b := by - have hact (a : PositiveRoot M cs) (ha : a ≠ simplePositive i) : - action M cs (cs.simple i) (positiveAction (cs.simple i) a).val = a.val := by - rw [simple_positiveAction_val i a ha,← LinearEquiv.mul_apply,← map_mul, - (cs.isReflection_simple i).mul_self,map_one] - rfl - have haD := hp.root_pos (positiveAction (cs.simple i) a) - have hbD := hp.root_pos (positiveAction (cs.simple i) b) - change 0 < O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) a).val) - - k * O.denominator (action M cs (cs.simple i) (positiveAction (cs.simple i) a).val) at haD - change 0 < O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) b).val) - - k * O.denominator (action M cs (cs.simple i) (positiveAction (cs.simple i) b).val) at hbD - rw [hact a ha] at haD - rw [hact b hb] at hbD - change O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) a).val) / - (O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) a).val) - - k * O.denominator (action M cs (cs.simple i) (positiveAction (cs.simple i) a).val)) < - O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) b).val) / - (O.numerator (action M cs (cs.simple i) (positiveAction (cs.simple i) b).val) - - k * O.denominator (action M cs (cs.simple i) (positiveAction (cs.simple i) b).val)) ↔ - O.numerator a.val / O.denominator a.val < O.numerator b.val / O.denominator b.val - rw [hact a ha,hact b hb,div_lt_div_iff₀ haD hbD, - div_lt_div_iff₀ (O.denominator_pos a) (O.denominator_pos b)] - constructor - · intro h - by_contra hn - have := mul_nonpos_of_nonpos_of_nonneg hk.le (sub_nonneg.mpr (le_of_not_gt hn)) - nlinarith - · intro h - have := mul_neg_of_neg_of_pos hk (sub_pos.mpr h) - nlinarith - -/-- The actual geometric rotation needed for the Hecke recursion. It moves -the least simple root to last and preserves all other root comparisons. -/ -theorem exists_rotation {y : W} (hy : y ≠ 1) (hc : O.Chamber y) : - ∃ (i : I) (O' : RatioOrder (M := M) (cs := cs)), - cs.IsLeftDescent y i ∧ O'.Chamber (cs.simple i * y) ∧ - (∀ a : PositiveRoot M cs, a ≠ simplePositive i → - O.slope (simplePositive i) < O.slope a ∧ O'.slope a < O'.slope (simplePositive i)) ∧ - (∀ a b : PositiveRoot M cs, a ≠ simplePositive i → b ≠ simplePositive i → - (O'.slope (positiveAction (cs.simple i) a) < O'.slope (positiveAction (cs.simple i) b) ↔ - O.slope a < O.slope b)) := by - obtain ⟨i,hi,hi0,hmin⟩ := O.least_simple_descent hy (O.adapted_of_chamber hc) - obtain ⟨k,hk,_,hpos⟩ := O.exists_turn_parameter i hi0 hmin - refine ⟨i,O.turn i k hk.ne hpos,hi,O.turn_chamber i k hk.ne hpos hc,?_,?_⟩ - · intro a ha - exact ⟨lt_of_le_of_ne (hmin a) (fun he => ha (O.slope_injective he).symm), - O.turn_simple_greatest i k hk hpos a ha⟩ - · exact O.turn_slope_lt_iff i k hk hpos - -end RatioOrder - -end -end KLInvariance.TitsSpace - -end - - -section - -/-! Rank-two path reversal in the actual induced root plane, for every finite -full interval. This is a required Dyer wall-crossing relation, not the Dyer -identification itself. -/ -namespace KLInvariance.Dihedral -variable {W : Type*} [Group W] {M : CoxeterMatrix Bool} -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - -/-- Switch the two vertices at every strictly internal rank, leaving all -other ranks fixed. The diagram involution supplies the intrinsic switch. -/ -def rankFlip (cs : CoxeterSystem M W) (L H : ℕ) (w : W) : W := - if L < cs.length w ∧ cs.length w < H then swap cs w else w - -@[simp] theorem length_rankFlip (cs : CoxeterSystem M W) (L H : ℕ) (w : W) : - cs.length (rankFlip cs L H w) = cs.length w := by - unfold rankFlip - split <;> simp - -@[simp] theorem rankFlip_involutive (cs : CoxeterSystem M W) (L H : ℕ) : - Function.Involutive (rankFlip cs L H) := by - intro w - unfold rankFlip - split <;> simp_all - -@[simp] theorem rankFlip_lower (cs : CoxeterSystem M W) (x y : W) : - rankFlip cs (cs.length x) (cs.length y) x = x := by simp [rankFlip] - -@[simp] theorem rankFlip_upper (cs : CoxeterSystem M W) (x y : W) : - rankFlip cs (cs.length x) (cs.length y) y = y := by simp [rankFlip] - -@[simp] theorem rankFlip_bruhat_iff (cs : CoxeterSystem M W) (L H : ℕ) (x y : W) : - BruhatLE cs (rankFlip cs L H x) (rankFlip cs L H y) ↔ BruhatLE cs x y := by - simp only [bruhat_iff_length_lt_or_eq, length_rankFlip, - (rankFlip_involutive cs L H).injective.eq_iff] - -@[simp] theorem rankFlip_step_iff (cs : CoxeterSystem M W) (L H : ℕ) (x y : W) : - BruhatStep cs (rankFlip cs L H x) (rankFlip cs L H y) ↔ BruhatStep cs x y := by - simp only [step_iff_odd, length_rankFlip] - -/-- An automorphism of the unlabelled full dihedral interval, fixing its ends. -It need not arise from a Coxeter-system automorphism at those ends. -/ -def intervalFlip (cs : CoxeterSystem M W) (lo hi : W) : - Interval cs lo hi ≃o Interval cs lo hi where - toFun x := ⟨rankFlip cs (cs.length lo) (cs.length hi) x.val, by - constructor - · simpa only [rankFlip_lower] using - (rankFlip_bruhat_iff cs (cs.length lo) (cs.length hi) lo x.val).mpr x.property.1 - · simpa only [rankFlip_upper] using - (rankFlip_bruhat_iff cs (cs.length lo) (cs.length hi) x.val hi).mpr x.property.2⟩ - invFun x := ⟨rankFlip cs (cs.length lo) (cs.length hi) x.val, by - constructor - · simpa only [rankFlip_lower] using - (rankFlip_bruhat_iff cs (cs.length lo) (cs.length hi) lo x.val).mpr x.property.1 - · simpa only [rankFlip_upper] using - (rankFlip_bruhat_iff cs (cs.length lo) (cs.length hi) x.val hi).mpr x.property.2⟩ - left_inv x := Subtype.ext (rankFlip_involutive cs _ _ x.val) - right_inv x := Subtype.ext (rankFlip_involutive cs _ _ x.val) - map_rel_iff' := rankFlip_bruhat_iff cs _ _ _ _ - -@[simp] theorem intervalFlip_val (cs : CoxeterSystem M W) (lo hi : W) - (x : Interval cs lo hi) : - (intervalFlip cs lo hi x).val = rankFlip cs (cs.length lo) (cs.length hi) x.val := rfl - -@[simp] theorem intervalFlip_involutive (cs : CoxeterSystem M W) (lo hi : W) : - Function.Involutive (intervalFlip cs lo hi) := - fun x => Subtype.ext (rankFlip_involutive cs _ _ x.val) - -def edgeFlip (cs : CoxeterSystem M W) (lo hi : W) : - BruhatGraph.Edge cs lo hi ≃ BruhatGraph.Edge cs lo hi where - toFun e := ⟨(intervalFlip cs lo hi e.val.1, intervalFlip cs lo hi e.val.2), - (rankFlip_step_iff cs _ _ _ _).mpr e.property⟩ - invFun e := ⟨(intervalFlip cs lo hi e.val.1, intervalFlip cs lo hi e.val.2), - (rankFlip_step_iff cs _ _ _ _).mpr e.property⟩ - left_inv e := Subtype.ext (Prod.ext - (intervalFlip_involutive cs lo hi e.val.1) - (intervalFlip_involutive cs lo hi e.val.2)) - right_inv e := Subtype.ext (Prod.ext - (intervalFlip_involutive cs lo hi e.val.1) - (intervalFlip_involutive cs lo hi e.val.2)) - -@[simp] theorem edgeFlip_source (cs : CoxeterSystem M W) (lo hi : W) - (e : BruhatGraph.Edge cs lo hi) : - BruhatGraph.source cs lo hi (edgeFlip cs lo hi e) = - intervalFlip cs lo hi (BruhatGraph.source cs lo hi e) := rfl - -@[simp] theorem edgeFlip_target (cs : CoxeterSystem M W) (lo hi : W) - (e : BruhatGraph.Edge cs lo hi) : - BruhatGraph.target cs lo hi (edgeFlip cs lo hi e) = - intervalFlip cs lo hi (BruhatGraph.target cs lo hi e) := rfl - -@[simp] theorem edgeFlip_involutive (cs : CoxeterSystem M W) (lo hi : W) : - Function.Involutive (edgeFlip cs lo hi) := by - intro e - apply Subtype.ext - change (intervalFlip cs lo hi (intervalFlip cs lo hi e.val.1), - intervalFlip cs lo hi (intervalFlip cs lo hi e.val.2)) = e.val - exact Prod.ext (intervalFlip_involutive cs lo hi e.val.1) - (intervalFlip_involutive cs lo hi e.val.2) - -end -end KLInvariance.Dihedral - -namespace KLInvariance.SchedulePaths -variable {V E V' E' : Type*} (source target : E → V) (source' target' : E' → V') - -/-- Relabelling graph vertices and edges preserves the actual path predicate. -/ -theorem IsPath.map {x y : V} {p : List E} - (hp : IsPath source target x y p) (f : V → V') (g : E → E') - (hs : ∀ e, source' (g e) = f (source e)) - (ht : ∀ e, target' (g e) = f (target e)) : - IsPath source' target' (f x) (f y) (p.map g) := by - induction p generalizing x with - | nil => exact congrArg f hp - | cons e p ih => - exact ⟨(hs e).trans (congrArg f hp.1), ht e ▸ ih hp.2⟩ - -/-- Every adjacent pair in a genuine path is composable. -/ -theorem IsPath.isChain {x y : V} {p : List E} (hp : IsPath source target x y p) : - p.IsChain (fun e f => target e = source f) := by - induction p generalizing x with - | nil => exact .nil - | cons e p ih => - cases p with - | nil => exact .singleton e - | cons f p => - apply List.isChain_cons_cons.mpr - exact ⟨hp.2.1.symm, ih hp.2⟩ - -/-- A path's adjacent comparisons suffice for a transitive label order. The -statement allows the comparison to change under an edge map, provided the -local relation is checked only on composable edges. -/ -theorem IsPath.pairwise_map_of_local {Λ Λ' : Type*} [LinearOrder Λ] [LinearOrder Λ'] - {x y : V} {p : List E} (hp : IsPath source target x y p) - (label : E → Λ) (label' : E' → Λ') (g : E → E') - (hlocal : ∀ e f, target e = source f → - label e < label f → label' (g e) < label' (g f)) - (horder : p.Pairwise (fun e f => label e < label f)) : - (p.map g).Pairwise (fun e f => label' e < label' f) := by - rw [← List.isChain_iff_pairwise] at horder ⊢ - rw [List.isChain_map] - induction p generalizing x with - | nil => exact .nil - | cons e p ih => - cases p with - | nil => exact .singleton e - | cons f p => - rw [List.isChain_cons_cons] at horder ⊢ - exact ⟨hlocal e f hp.2.1.symm horder.1, ih hp.2 horder.2⟩ - -end KLInvariance.SchedulePaths - -namespace KLInvariance.TitsSpace -open Module -universe u v -variable {I : Type u} [Fintype I] {M : CoxeterMatrix I} - {W : Type v} [Group W] {cs : CoxeterSystem M W} -noncomputable section -namespace PlaneBasis -variable {P : Submodule ℝ (I → ℝ)} (B : PlaneBasis (M := M) (cs := cs) P) -open Dihedral BruhatGraph -local instance (p : Prop) : Decidable p := Classical.propDecidable p - -theorem edgeRoot_ne_of_path {x y z : planeSubgroup M cs P} - (hxy : BruhatStep B.system x y) (hyz : BruhatStep B.system y z) : - B.edgeRoot hxy ≠ B.edgeRoot hyz := - graphRoot_ne_of_path ((B.bruhatStep_iff x y).mpr hxy) ((B.bruhatStep_iff y z).mpr hyz) - -/-- At every internal vertex, the cut switches side under the path involution. -This is the local relation behind rank-two path-product reversal. -/ -theorem edgeRoot_slopes_rankFlip {x y z top : planeSubgroup M cs P} {L : ℕ} - (hxy : BruhatStep B.system x y) (hyz : BruhatStep B.system y z) - (hL : L < B.system.length y) (hH : B.system.length y < B.system.length top) : - let hx := (rankFlip_step_iff B.system L (B.system.length top) x y).mpr hxy - let hz := (rankFlip_step_iff B.system L (B.system.length top) y z).mpr hyz - geometricSlope (B.edgeRoot hxy) < geometricSlope (B.edgeRoot hyz) ↔ - geometricSlope (B.edgeRoot hz) < geometricSlope (B.edgeRoot hx) := by - dsimp only - let hx := (rankFlip_step_iff B.system L (B.system.length top) x y).mpr hxy - let hz := (rankFlip_step_iff B.system L (B.system.length top) y z).mpr hyz - have hsign : B.system.IsLeftDescent - (rankFlip B.system L (B.system.length top) y) false ↔ - ¬ B.system.IsLeftDescent y false := by - rw [rankFlip,ite_eq_left ⟨hL,hH⟩] - exact descent_swap_false_iff_not B.system (by omega) hH - have hne : geometricSlope (B.edgeRoot hx) ≠ geometricSlope (B.edgeRoot hz) := - fun he => B.edgeRoot_ne_of_path hx hz (geometricSlope_injective he) - rw [B.edgeRoot_slopes_iff] - constructor - · intro hi - have hn : ¬ geometricSlope (B.edgeRoot hx) < geometricSlope (B.edgeRoot hz) := by - rw [B.edgeRoot_slopes_iff,hsign] - exact not_not.mpr hi - exact lt_of_le_of_ne (le_of_not_gt hn) hne.symm - · intro hi - by_contra hn - have hlt := (B.edgeRoot_slopes_iff hx hz).mpr (hsign.mpr hn) - exact lt_asymm hlt hi - -/-- Restriction of the actual geometric root slope to a full plane interval. -/ -def intervalEdgeSlope (lo hi : planeSubgroup M cs P) (e : Edge B.system lo hi) : ℝ := - geometricSlope (B.edgeRoot e.property) - -/-- The global edge map reverses the comparison for every composable pair. -No statement is asserted for disjoint edge labels, which can share ties. -/ -theorem intervalEdgeSlope_flip {lo hi : planeSubgroup M cs P} - (e f : Edge B.system lo hi) - (hjoin : target B.system lo hi e = source B.system lo hi f) : - B.intervalEdgeSlope lo hi e < B.intervalEdgeSlope lo hi f ↔ - B.intervalEdgeSlope lo hi (edgeFlip B.system lo hi f) < - B.intervalEdgeSlope lo hi (edgeFlip B.system lo hi e) := by - rcases e with ⟨⟨ex,ey⟩,he⟩ - rcases f with ⟨⟨fx,fy⟩,hf⟩ - change ey = fx at hjoin - subst fx - have hl : B.system.length lo < B.system.length ey.val := - lt_of_le_of_lt (length_le_of_bruhat B.system ex.property.1) he.1 - have hh : B.system.length ey.val < B.system.length hi := - lt_of_lt_of_le hf.1 (length_le_of_bruhat B.system fy.property.2) - exact B.edgeRoot_slopes_rankFlip he hf hl hh - -end PlaneBasis -end -end KLInvariance.TitsSpace - -namespace KLInvariance.SchedulePaths -open scoped BigOperators -variable {V E R : Type*} (source target : E → V) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - -/-- The finite set of genuine directed paths selected by an edge schedule. -/ -def subpaths (schedule : List E) (x y : V) : Finset (List E) := - schedule.sublists'.toFinset.filter (IsPath source target x y) - -@[simp] theorem mem_subpaths (schedule : List E) (x y : V) (p : List E) : - p ∈ subpaths source target schedule x y ↔ - p.Sublist schedule ∧ IsPath source target x y p := by - simp [subpaths, List.mem_sublists'] - -variable [Semiring R] - -theorem dispatch_eq_subpaths_sum (T : R) (schedule : List E) (hnd : schedule.Nodup) - (x y : V) : - dispatch source target T (fun z => if z=y then 1 else 0) schedule x = - ∑ p ∈ subpaths source target schedule x y, T ^ p.length := by - rw [entry_eq_weighted_paths, subpaths, Finset.sum_filter, - List.sum_toFinset _ (List.nodup_sublists'.mpr hnd)] - -/-- A length-preserving involution on the actual schedule-path sets proves -an operator-entry relation, with no Hecke polynomial used in the assumptions. -/ -theorem dispatch_eq_of_path_involution (T : R) (schedule schedule' : List E) - (hnd : schedule.Nodup) (hnd' : schedule'.Nodup) (x y : V) (g : E → E) - (hg : Function.Involutive g) - (hforward : ∀ p ∈ subpaths source target schedule x y, - p.map g ∈ subpaths source target schedule' x y) - (hbackward : ∀ p ∈ subpaths source target schedule' x y, - p.map g ∈ subpaths source target schedule x y) : - dispatch source target T (fun z => if z=y then 1 else 0) schedule x = - dispatch source target T (fun z => if z=y then 1 else 0) schedule' x := by - rw [dispatch_eq_subpaths_sum source target T schedule hnd, - dispatch_eq_subpaths_sum source target T schedule' hnd'] - exact Finset.sum_nbij' (List.map g) (List.map g) hforward hbackward - (fun p _ => List.map_involutive_iff.mpr hg p) - (fun p _ => List.map_involutive_iff.mpr hg p) (fun p _ => by simp) - -end -end KLInvariance.SchedulePaths - -namespace KLInvariance.SchedulePaths -variable {V E : Type*} (source target : E → V) -noncomputable section -local instance (p : Prop) : Decidable p := Classical.propDecidable p - -/-- Sorted full schedules select precisely their strictly monotone paths; -an actual graph map satisfying the adjacent comparison test transports them. -/ -theorem subpaths_map_of_sorted (label label' : E → ℝ) - (schedule schedule' : List E) (x y : V) - (hs : schedule.Pairwise (fun e f => label f ≤ label e)) - (hs' : schedule'.Pairwise (fun e f => label' f ≤ label' e)) - (hfull' : ∀ e, e ∈ schedule') - (hties : ∀ e f, label e = label f → target e ≠ source f) - (f : V → V) (g : E → E) - (hsource : ∀ e, source (g e) = f (source e)) - (htarget : ∀ e, target (g e) = f (target e)) - (hx : f x=x) (hy : f y=y) - (hlocal : ∀ e f, target e=source f → label f

T.val.toLeft) + +theorem visibleScheduleLaw_mass (m : ℕ) (hm : m≤Fintype.card α+Fintype.card β) (S : Finset α) : + (visibleScheduleLaw (α:=α) (β:=β) m hm).mass S= + if S.card≤ m then ((Fintype.card β).choose (m-S.card):ℝ)/ + ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0 := by + unfold visibleScheduleLaw + rw [FiniteLaw.map_mass] + by_cases hS : S.card≤ m + · rw [ite_eq_left hS] + simp only [uniformSubsetLaw,Fintype.card_sum] + rw [←Finset.sum_filter] + simp only [Finset.sum_const,nsmul_eq_mul] + have he : (Finset.univ.filter (fun T : FixedSubset (α⊕β) m => T.val.toLeft=S)).card= + (Fintype.card β).choose (m-S.card) := by + rw [←Fintype.card_subtype] + exact (Fintype.card_congr (visibleFiberEquiv (β:=β) m S hS)).trans (card_fixedSubset _) + rw [he] + ring + · rw [ite_eq_right hS] + apply Finset.sum_eq_zero + intro T _ + have hnot : T.val.toLeft≠S := by + intro he + apply hS + simpa only [he,T.property] using (Finset.card_toLeft_le (u:=T.val)) + rw [ite_eq_right hnot] + +theorem sum_finset_card (f : ℕ→ℝ) : + (∑S : Finset α,f S.card)=∑v : Fin (Fintype.card α+1), + ((Fintype.card α).choose v.val:ℝ)*f v.val := by + let g : Finset α→Fin (Fintype.card α+1) := fun S => + ⟨S.card,by have H:=Finset.card_le_univ S; omega⟩ + rw [←Fintype.sum_fiberwise g (fun S => f S.card)] + apply Finset.sum_congr rfl + intro v _ + have hc : Fintype.card {S : Finset α // g S=v}=(Fintype.card α).choose v.val := by + let e : {S : Finset α // g S=v} ≃ FixedSubset α v.val := + { toFun := fun S => ⟨S.val,by have H:=congrArg Fin.val S.property; exact H⟩ + invFun := fun S => ⟨S.val,by apply Fin.ext; exact S.property⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + exact (Fintype.card_congr e).trans (card_fixedSubset _) + calc + _=∑_S : {S : Finset α // g S=v},f v.val := by + apply Finset.sum_congr rfl + intro S _ + congr 1 + exact congrArg Fin.val S.property + _=_ := by simp [hc] + +end TraceReconstruction + +namespace TraceReconstruction +open scoped Classical +variable {α β : Type*} [Fintype α] [Fintype β] + +theorem visibleScheduleLaw_tv (m m' : ℕ) + (hm : m≤Fintype.card α+Fintype.card β) (hm' : m'≤Fintype.card α+Fintype.card β) : + (visibleScheduleLaw (α:=α) (β:=β) m hm).tv (visibleScheduleLaw m' hm')= + (hypergeomLaw (Fintype.card α) (Fintype.card β) m hm).tv + (hypergeomLaw (Fintype.card α) (Fintype.card β) m' hm') := by + unfold FiniteLaw.tv + simp_rw [visibleScheduleLaw_mass] + rw [sum_finset_card (α:=α) (fun v => + |(if v≤ m then ((Fintype.card β).choose (m-v):ℝ)/ + ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0)- + (if v≤ m' then ((Fintype.card β).choose (m'-v):ℝ)/ + ((Fintype.card α+Fintype.card β).choose m':ℝ) else 0)|)] + have he (v : ℕ) : + ((Fintype.card α).choose v:ℝ)* + |(if v≤ m then ((Fintype.card β).choose (m-v):ℝ)/ + ((Fintype.card α+Fintype.card β).choose m:ℝ) else 0)- + (if v≤ m' then ((Fintype.card β).choose (m'-v):ℝ)/ + ((Fintype.card α+Fintype.card β).choose m':ℝ) else 0)|= + |hypergeomMass (Fintype.card α) (Fintype.card β) m v- + hypergeomMass (Fintype.card α) (Fintype.card β) m' v| := by + rw [←abs_of_nonneg (Nat.cast_nonneg (α:=ℝ) ((Fintype.card α).choose v)),←abs_mul,mul_sub] + simp only [mul_ite,mul_zero,hypergeomMass,mul_div_assoc] + simp_rw [he] + simp only [hypergeomLaw] + rw [Fin.sum_univ_eq_sum_range (fun v => |hypergeomMass (Fintype.card α) (Fintype.card β) m v- + hypergeomMass (Fintype.card α) (Fintype.card β) m' v|)] + rw [Fin.sum_univ_eq_sum_range (n:=Fintype.card α+Fintype.card β+1) + (fun v => |hypergeomMass (Fintype.card α) (Fintype.card β) m v- + hypergeomMass (Fintype.card α) (Fintype.card β) m' v|)] + congr 1 + symm + apply sum_range_extend_zero (by omega) + intro k hk + rw [hypergeomMass_high _ _ _ _ (by omega),hypergeomMass_high _ _ _ _ (by omega),sub_self,abs_zero] + +theorem visibleScheduleLaw_steps (m P : ℕ) + (hN : 16≤Fintype.card α+Fintype.card β) (hM : Fintype.card β≤ m) + (hV : m+P if b=a then 1 else 0) + simpa only [expect,mul_ite,mul_one,mul_zero,Fintype.sum_ite_eq'] using H + +theorem expect_map (P : FiniteLaw α) (f : α→β) (G : β→ℝ) : + (P.map f).expect G=P.expect (G∘f) := expectation_map P f G + +theorem map_map (P : FiniteLaw α) (f : α→β) (g : β→γ) : + (P.map f).map g=P.map (g∘f) := by + apply ext_expect + intro G + rw [expect_map,expect_map,expect_map] + rfl + +theorem map_id (P : FiniteLaw α) : P.map id=P := by + apply ext_expect + intro G + rw [expect_map] + rfl + +theorem map_equiv_mass (P : FiniteLaw α) (e : α≃β) (b : β) : + (P.map e).mass b=P.mass (e.symm b) := by + rw [map_mass] + simp only [←e.eq_symm_apply,Fintype.sum_ite_eq'] + +theorem tv_map_equiv (P Q : FiniteLaw α) (e : α≃β) : + (P.map e).tv (Q.map e)=P.tv Q := by + unfold tv + simp_rw [map_equiv_mass] + rw [e.symm.sum_comp (fun a => |P.mass a-Q.mass a|)] + +end FiniteLaw + +variable {α β : Type*} [Fintype α] [Fintype β] + +def fixedSubsetEquiv (e : α≃β) (m : ℕ) : FixedSubset α m ≃ FixedSubset β m where + toFun S := ⟨S.val.map e.toEmbedding,by simpa only [Finset.card_map] using S.property⟩ + invFun T := ⟨T.val.map e.symm.toEmbedding,by simpa only [Finset.card_map] using T.property⟩ + left_inv S := by apply Subtype.ext; exact e.finsetCongr.left_inv S.val + right_inv T := by apply Subtype.ext; exact e.finsetCongr.right_inv T.val + +theorem uniformSubsetLaw_map (e : α≃β) (m : ℕ) (hm : m≤Fintype.card α) : + (uniformSubsetLaw m hm).map (fixedSubsetEquiv e m)= + uniformSubsetLaw m (by simpa only [←Fintype.card_congr e] using hm) := by + apply FiniteLaw.ext + funext T + rw [FiniteLaw.map_equiv_mass] + simp only [uniformSubsetLaw,Fintype.card_congr e] + +end TraceReconstruction + +namespace TraceReconstruction +open scoped Classical +variable {α : Type*} [Fintype α] + +abbrev HiddenIndex (H : Finset α) := {a : α // a∈H} +abbrev VisibleIndex (H : Finset α) := {a : α // a∉H} + +def splitIndexEquiv (H : Finset α) : VisibleIndex H⊕HiddenIndex H ≃ α := + (Equiv.sumComm _ _).trans (Equiv.sumCompl (fun a => a∈H)) + +theorem card_splitIndex (H : Finset α) : + Fintype.card (VisibleIndex H)+Fintype.card (HiddenIndex H)=Fintype.card α := by + simpa only [Fintype.card_sum] using Fintype.card_congr (splitIndexEquiv H) + +omit [Fintype α] in +theorem card_hiddenIndex (H : Finset α) : Fintype.card (HiddenIndex H)=H.card := by + exact Fintype.card_coe H + +def eraseScheduleLaw (H : Finset α) (m : ℕ) (hm : m≤Fintype.card α) : FiniteLaw (Finset α) := + (uniformSubsetLaw m hm).map (fun S => S.val\H) + +omit [Fintype α] in +theorem erase_splitIndex (H : Finset α) (S : Finset (VisibleIndex H⊕HiddenIndex H)) : + (S.map (splitIndexEquiv H).toEmbedding)\H= + S.toLeft.map ⟨Subtype.val,Subtype.val_injective⟩ := by + ext a + constructor + · intro ha + obtain ⟨ha,hn⟩:=Finset.mem_sdiff.mp ha + obtain ⟨b,hb,rfl⟩:=Finset.mem_map.mp ha + cases b with + | inl b => + apply Finset.mem_map.mpr + exact ⟨b,by simpa using hb,rfl⟩ + | inr b => exact False.elim (hn b.property) + · intro ha + obtain ⟨b,hb,rfl⟩:=Finset.mem_map.mp ha + apply Finset.mem_sdiff.mpr + constructor + · exact Finset.mem_map.mpr ⟨Sum.inl b,by simpa using hb,rfl⟩ + · exact b.property + +end TraceReconstruction + +namespace TraceReconstruction +open scoped Classical +variable {α : Type*} [Fintype α] + +theorem eraseScheduleLaw_eq (H : Finset α) (m : ℕ) (hm : m≤Fintype.card α) : + eraseScheduleLaw H m hm= + (visibleScheduleLaw (α:=VisibleIndex H) (β:=HiddenIndex H) m + (by simpa only [card_splitIndex] using hm)).map + (fun S => S.map ⟨Subtype.val,Subtype.val_injective⟩) := by + have h:=uniformSubsetLaw_map (splitIndexEquiv H) m + (by simpa only [Fintype.card_sum,card_splitIndex] using hm) + unfold eraseScheduleLaw visibleScheduleLaw + rw [←h,FiniteLaw.map_map,FiniteLaw.map_map] + congr 1 + funext S + exact erase_splitIndex H S.val + +theorem eraseScheduleLaw_steps (H : Finset α) (m P : ℕ) + (hN : 16≤Fintype.card α) (hM : H.card≤ m) + (hV : m+P+H.card (K i).expect (fun b => F ⟨i,b⟩)) := by + simp only [expect,sigma,Fintype.sum_sigma,Finset.mul_sum,mul_assoc] + +theorem overlap_sigma_lower (P Q : FiniteLaw ι) (K L : ∀i,FiniteLaw (β i)) : + (∑i,min (P.mass i) (Q.mass i)*overlap (K i) (L i))≤overlap (P.sigma K) (Q.sigma L) := by + simp only [overlap,sigma,Fintype.sum_sigma,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro b _ + apply le_min + · exact mul_le_mul (min_le_left _ _) (min_le_left _ _) (le_min ((K i).nonneg b) ((L i).nonneg b)) (P.nonneg i) + · exact mul_le_mul (min_le_right _ _) (min_le_right _ _) (le_min ((K i).nonneg b) ((L i).nonneg b)) (Q.nonneg i) +end FiniteLaw + +theorem sum_binomialMass_cutoff {n N : ℕ} (hn : n≤N) (p : ℝ) : + ∑l : Fin (N+1),binomialMass n p l.val=1 := by + rw [Fin.sum_univ_eq_sum_range (fun k => binomialMass n p k) (N+1)] + rw [←sum_binomialMass n p] + symm + apply Finset.sum_subset (Finset.range_mono (by omega)) + intro k _ hk + have hn' : n F (List.ofFn a.2))= + silentMarkExpectation q (List.ofFn θ) F := by + rw [countedPrimitiveLaw,FiniteLaw.expect_sigma,silentMarkExpectation_count_mixture q hq θ F] + change (∑l : Fin (N+1),binomialMass n (1-primitiveErasure q) l.val* + (boundedConditionalPrimitiveLaw hq θ l).expect (fun x => F (List.ofFn x)))=_ + let f : ℕ→ℝ := fun l => if hl:l≤n then binomialMass n (1-primitiveErasure q) l* + (conditionalPrimitiveLaw hl q hq θ).expect (fun x => F (List.ofFn x)) else 0 + have hleft : (∑l : Fin (N+1),binomialMass n (1-primitiveErasure q) l.val* + (boundedConditionalPrimitiveLaw hq θ l).expect (fun x => F (List.ofFn x)))= + ∑l : Fin (N+1),f l.val := by + apply Finset.sum_congr rfl + intro l _ + by_cases hl:l.val≤n + · simp only [boundedConditionalPrimitiveLaw,hl,dite_eq_left,f] + · simp [boundedConditionalPrimitiveLaw,hl,f,binomialMass,Nat.choose_eq_zero_of_lt (Nat.lt_of_not_ge hl)] + rw [hleft,Fin.sum_univ_eq_sum_range f (N+1)] + have he : (∑l∈Finset.range (n+1),f l)=∑l∈Finset.range (N+1),f l := by + apply Finset.sum_subset (Finset.range_mono (by omega)) + intro l _ hl + simp only [Finset.mem_range] at hl + simp [f,show ¬l≤n by omega] + rw [←he,←Fin.sum_univ_eq_sum_range f (n+1)] + apply Finset.sum_congr rfl + intro l _ + simp only [f,dite_eq_left (Nat.le_of_lt_succ l.isLt)] + +theorem countedPrimitiveLaw_simulates {n N : ℕ} (hn : n≤N) {q : ℝ} (hq : q∈Set.Ioo 0 1) + (θ : Fin n→Bool) : + SimulatesTrace q (countedPrimitiveLaw hn hq θ) decodeBoundedMarks + (((List.ofFn θ).map primitiveBlock).flatten) := by + intro F + rw [primitive_run_simulation hq] + exact countedPrimitiveLaw_expect hn hq θ (fun a => F (joinPrimitiveMarks a)) + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +variable {α : Type*} [Fintype α] + +theorem subsetLaw_expect_card (p : ℝ) (hp : p∈Set.Icc 0 1) (f : ℕ→ℝ) : + (subsetLaw (α:=α) p hp).expect (fun S => f S.card)= + ∑k∈Finset.range (Fintype.card α+1),binomialMass (Fintype.card α) p k*f k := by + change (∑S : Finset α,p^S.card*(1-p)^(Fintype.card α-S.card)*f S.card)=_ + rw [sum_finset_card (α:=α) (fun k => p^k*(1-p)^(Fintype.card α-k)*f k), + Fin.sum_univ_eq_sum_range (fun k => ((Fintype.card α).choose k:ℝ)*(p^k*(1-p)^(Fintype.card α-k)*f k))] + apply Finset.sum_congr rfl + intro k _ + unfold binomialMass + ring + +theorem subsetLaw_variance (p : ℝ) (hp : p∈Set.Icc 0 1) : + (subsetLaw (α:=α) p hp).expect (fun S => ((S.card:ℝ)-Fintype.card α*p)^2)= + (Fintype.card α:ℝ)*p*(1-p) := by + rw [subsetLaw_expect_card p hp (fun k => ((k:ℝ)-Fintype.card α*p)^2)] + exact binomialMass_variance _ p + +def hiddenScheduleLaw (p : ℝ) (hp : p∈Set.Icc 0 1) (m : ℕ) (hm : m≤Fintype.card α) : + FiniteLaw (Finset α×Finset α) := + (subsetLaw p hp).bind (fun H => (eraseScheduleLaw H m hm).map (fun S => (H,S))) + +theorem hiddenScheduleLaw_tv (p : ℝ) (hp : p∈Set.Icc 0 1) (m m' : ℕ) + (hm : m≤Fintype.card α) (hm' : m'≤Fintype.card α) : + (hiddenScheduleLaw p hp m hm).tv (hiddenScheduleLaw p hp m' hm') ≤ + (subsetLaw (α:=α) p hp).expect (fun H => + (eraseScheduleLaw H m hm).tv (eraseScheduleLaw H m' hm')) := by + unfold hiddenScheduleLaw + refine (FiniteLaw.tv_bind_kernel_le _ _ _).trans ?_ + apply FiniteLaw.expect_mono + intro H + exact FiniteLaw.tv_map_le _ _ _ + +theorem good_hiddenSchedule_bound {G P : ℕ} {p : ℝ} + (hG : 8≤G) (hP : 4*P≤G) (hp : p∈Set.Ioc 0 (1/8)) + (H : Finset (Fin (2*G))) + (hlo : p*(2*G:ℝ)/2≤H.card) (hhi : (H.card:ℝ)≤2*p*(2*G:ℝ)) : + (eraseScheduleLaw H G (by simp only [Fintype.card_fin]; omega)).tv + (eraseScheduleLaw H (G+P) (by simp only [Fintype.card_fin]; omega))≤ + (P:ℝ)*64/Real.sqrt (p*(2*G:ℝ)/2) := by + have hgr : (0:ℝ) E+4*((H.card:ℝ)-μ)^2/μ^2) (fun H => by + by_cases hg : μ/2≤(H.card:ℝ) ∧ (H.card:ℝ)≤2*μ + · exact (good_hiddenSchedule_bound hG hP hp H hg.1 (by simpa only [μ,mul_assoc] using hg.2)).trans + (le_add_of_nonneg_right (by positivity)) + · exact (FiniteLaw.tv_le_one _ _).trans + ((bad_hiddenSchedule_variance hμ hg).trans (by linarith))) + apply he.trans + have hv:=subsetLaw_variance (α:=Fin (2*G)) p ⟨hp.1.le,by linarith [hp.2]⟩ + simp only [Fintype.card_fin,Nat.cast_mul,Nat.cast_ofNat] at hv + change (∑H,(subsetLaw p _).mass H*(E+4*((H.card:ℝ)-μ)^2/μ^2))≤E+4/μ + simp_rw [mul_add, Finset.sum_add_distrib] + rw [← Finset.sum_mul,FiniteLaw.total,one_mul] + have heq : (∑H : Finset (Fin (2*G)),(subsetLaw p ⟨hp.1.le,by linarith [hp.2]⟩).mass H*(4*((H.card:ℝ)-μ)^2/μ^2))= + 4/μ^2*(2*(G:ℝ)*p*(1-p)) := by + rw [←hv,FiniteLaw.expect,Finset.mul_sum] + apply Finset.sum_congr rfl + intro H _ + dsimp [μ] + ring + rw [heq] + have heq' : 4/μ^2*(2*(G:ℝ)*p*(1-p))=4/μ*(1-p) := by + have h : 2*(G:ℝ)*p=μ := by dsimp [μ]; ring + rw [h] + field_simp + rw [heq'] + have h:=mul_le_mul_of_nonneg_left (show 1-p≤1 by linarith [hp.1]) (show 0≤4/μ by positivity) + linarith + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +theorem expect_comm (P : FiniteLaw α) (Q : FiniteLaw β) (F : α→β→ℝ) : + P.expect (fun a => Q.expect (F a))=Q.expect (fun b => P.expect (fun a => F a b)) := by + simp only [expect,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +theorem bind_map (P : FiniteLaw α) (f : α→β) (K : β→FiniteLaw γ) : + (P.map f).bind K=P.bind (K∘f) := by + apply ext_expect + intro F + rw [expect_bind,expect_map,expect_bind] + rfl + +theorem map_bind (P : FiniteLaw α) (K : α→FiniteLaw β) (f : β→γ) : + (P.bind K).map f=P.bind (fun a => (K a).map f) := by + apply ext_expect + intro F + simp only [expect_bind,expect_map] + +theorem bind_comm (P : FiniteLaw α) (Q : FiniteLaw β) (K : α→β→FiniteLaw γ) : + P.bind (fun a => Q.bind (K a))=Q.bind (fun b => P.bind (fun a => K a b)) := by + apply ext_expect + intro F + simp only [expect_bind] + exact expect_comm P Q (fun a b => (K a b).expect F) + +end FiniteLaw +variable {α : Type*} [Fintype α] + +theorem subsetWeight_mask {n : ℕ} (p : ℝ) (a : Mask n) : + subsetWeight p (maskSubset a)=maskWeight (1-p) a := by + rw [maskWeight_card] + simp only [subsetWeight,Fintype.card_fin,sub_sub_cancel] + +theorem coordinateProduct_common_flags {n : ℕ} (p : ℝ) (hp : p∈Set.Icc 0 1) + (U : FiniteLaw α) (R P : Fin n→FiniteLaw α) + (hP : ∀ i x,(P i).mass x=p*U.mass x+(1-p)*(R i).mass x) : + (subsetLaw p hp).bind (fun H : Finset (Fin n) => + FiniteLaw.coordinateProduct (fun i => if i∈H then U else R i))= + FiniteLaw.coordinateProduct P := by + apply FiniteLaw.ext + funext x + change (∑H : Finset (Fin n),subsetWeight p H*(∏i,(if i∈H then U else R i).mass (x i)))= + ∏i,(P i).mass (x i) + rw [←(maskSubsetEquiv n).sum_comp] + change (∑a : Mask n,subsetWeight p (maskSubset a)*(∏i,(if i∈maskSubset a then U else R i).mass (x i)))=_ + simp_rw [subsetWeight_mask,maskWeight,←Finset.prod_mul_distrib] + have he (a : Mask n) (i : Fin n) : + (if a i then 1-(1-p) else 1-p)*(if i∈maskSubset a then U else R i).mass (x i)= + if a i then p*U.mass (x i) else (1-p)*(R i).mass (x i) := by + cases ha : a i <;> simp [maskSubset,ha] + simp_rw [he] + rw [←Fintype.prod_sum (fun i (b : Bool) => if b then p*U.mass (x i) else (1-p)*(R i).mass (x i))] + apply Finset.prod_congr rfl + intro i _ + simp only [Fintype.sum_bool,ite_true,Bool.false_eq_true,ite_false] + rw [hP] + +end TraceReconstruction + +namespace TraceReconstruction +open scoped Classical +variable {α : Type*} [Fintype α] + +def schedulePayload {n : ℕ} (U P Q : FiniteLaw α) (z : Finset (Fin n)×Finset (Fin n)) : + FiniteLaw (Fin n→α) := + FiniteLaw.coordinateProduct (fun i => if i∈z.1 then U else if i∈z.2 then Q else P) + +def uniformSchedulePayload {n : ℕ} (P Q : FiniteLaw α) (m : ℕ) (hm : m≤n) : + FiniteLaw (Fin n→α) := + (uniformSubsetLaw (α:=Fin n) m (by simpa using hm)).bind + (fun S => FiniteLaw.coordinateProduct (fun i => if i∈S.val then Q else P)) + +theorem hiddenSchedule_payload_exact {n : ℕ} (p : ℝ) (hp : p∈Set.Icc 0 1) + (U P' Q' P Q : FiniteLaw α) + (hP : ∀ x,P.mass x=p*U.mass x+(1-p)*P'.mass x) + (hQ : ∀ x,Q.mass x=p*U.mass x+(1-p)*Q'.mass x) + (m : ℕ) (hm : m≤n) : + (hiddenScheduleLaw (α:=Fin n) p hp m (by simpa using hm)).bind (schedulePayload U P' Q')= + uniformSchedulePayload P Q m hm := by + unfold hiddenScheduleLaw eraseScheduleLaw + rw [FiniteLaw.bind_assoc] + simp_rw [FiniteLaw.bind_map] + rw [FiniteLaw.bind_comm] + unfold uniformSchedulePayload + congr 1 + funext S + trans (subsetLaw p hp).bind (fun H : Finset (Fin n) => + FiniteLaw.coordinateProduct (fun i => if i∈H then U else if i∈S.val then Q' else P')) + · congr 1 + funext H + dsimp only [Function.comp_def,schedulePayload] + congr 1 + funext i + by_cases h : i∈H <;> by_cases h' : i∈S.val <;> simp [h,h'] + apply coordinateProduct_common_flags + intro i x + by_cases h : i∈S.val + · simpa [h] using hQ x + · simpa [h] using hP x + +theorem uniformSchedulePayload_steps {G R : ℕ} {p : ℝ} + (hG : 8≤G) (hR : 4*R≤G) (hp : p∈Set.Ioc 0 (1/8)) + (P Q : FiniteLaw α) (hov : p≤FiniteLaw.overlap P Q) : + (uniformSchedulePayload (n:=2*G) P Q G (by omega)).tv + (uniformSchedulePayload P Q (G+R) (by omega))≤ + (R:ℝ)*64/Real.sqrt (p*(2*G:ℝ)/2)+4/(p*(2*G:ℝ)) := by + have hp1 : p∈Set.Ioo 0 1 := ⟨hp.1,by linarith [hp.2]⟩ + obtain ⟨U,P',Q',hP,hQ⟩:=FiniteLaw.common_part_decomposition P Q hp1 hov + rw [←hiddenSchedule_payload_exact p ⟨hp.1.le,hp1.2.le⟩ U P' Q' P Q hP hQ, + ←hiddenSchedule_payload_exact p ⟨hp.1.le,hp1.2.le⟩ U P' Q' P Q hP hQ] + exact (FiniteLaw.tv_bind_le _ _ _).trans (hiddenScheduleLaw_steps hG hR hp) + +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def coordinateWord {n : ℕ} (w : Fin n→List Bool) : List Bool := (List.ofFn w).flatten + +theorem coordinateWord_succ {n : ℕ} (w : Fin (n+1)→List Bool) : + coordinateWord w=w 0++coordinateWord (fun i => w i.succ) := by + simp only [coordinateWord,List.ofFn_succ,List.flatten_cons] + +theorem coordinateWord_cons {n : ℕ} (w : List Bool) (v : Fin n→List Bool) : + coordinateWord (Fin.cons w v)=w++coordinateWord v := by + rw [coordinateWord_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + +theorem coordinateProduct_simulates {α : Type*} [Fintype α] + {n : ℕ} {q : ℝ} (P : Fin n→FiniteLaw α) (f : α→List Bool) (w : Fin n→List Bool) + (h : ∀i,SimulatesTrace q (P i) f (w i)) : + SimulatesTrace q (FiniteLaw.coordinateProduct P) (fun a => coordinateWord (fun i => f (a i))) + (coordinateWord w) := by + induction n with + | zero => + intro F + change (FiniteLaw.coordinateProduct P).expect (fun _ => F [])=F [] + exact FiniteLaw.expect_const _ _ + | succ n ih => + intro F + rw [FiniteLaw.expect_coordinateProduct_succ,coordinateWord_succ,listDeletionExpectation_append] + have hj (a : α) (x : Fin n→α) : + coordinateWord (fun i => f ((Fin.cons a x : Fin (n+1)→α) i))=f a++coordinateWord (fun i => f (x i)) := by + rw [coordinateWord_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + simp_rw [hj] + have ht:=ih (fun i => P i.succ) (fun i => w i.succ) (fun i => h i.succ) + calc + _=(P 0).expect (fun a => listDeletionExpectation q (coordinateWord (fun i => w i.succ)) + (fun t => F (f a++t))) := by + congr 1 + funext a + exact ht (fun t => F (f a++t)) + _=_ := h 0 (fun t => listDeletionExpectation q (coordinateWord (fun i => w i.succ)) (fun u => F (t++u))) + +theorem sum_subset_choices {n : ℕ} (S : Finset (Fin n)) (k : ℕ) : + (∑i : Fin n,if i∈S then k+1 else k)=n*k+S.card := by + have he (i : Fin n) : (if i∈S then k+1 else k)=k+(if i∈S then 1 else 0) := by + split_ifs <;> omega + simp_rw [he] + simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + Finset.sum_boole,Finset.filter_mem_eq_inter,Finset.univ_inter,Nat.cast_id] + +theorem coordinateWord_pureAtomRun {n : ℕ} (w : List Bool) (k : Fin n→ℕ) : + coordinateWord (fun i => pureAtomRun w (k i))=pureAtomRun w (∑i,k i) := by + change (List.ofFn (pureAtomRun w ∘ k)).flatten=_ + rw [←List.map_ofFn,pureAtomRun_partition,List.sum_ofFn] + +theorem uniform_schedule_word {n m : ℕ} (S : FixedSubset (Fin n) m) (w : List Bool) (k : ℕ) : + coordinateWord (fun i => if i∈S.val then pureAtomRun w (k+1) else pureAtomRun w k)= + pureAtomRun w (n*k+m) := by + have he (i : Fin n) : (if i∈S.val then pureAtomRun w (k+1) else pureAtomRun w k)= + pureAtomRun w (if i∈S.val then k+1 else k) := by split_ifs <;> rfl + simp_rw [he] + rw [coordinateWord_pureAtomRun,sum_subset_choices,S.property] + +end TraceReconstruction +noncomputable section +namespace TraceReconstruction + +theorem lifting_count_scale {F k P : ℕ} {C p : ℝ} + (hk : 1≤k) (hP : 1≤P) (hp : p∈Set.Ioc 0 (1/8)) + (hC : 1073741824≤p*C) (hF : C*k*P≤F) : + (1048576:ℝ)*(P:ℝ)^2≤p*((F*P/(2*k+1):ℕ):ℝ) := by + let G := F*P/(2*k+1) + have hkr : (1:ℝ)≤k := by exact_mod_cast hk + have hPr : (1:ℝ)≤P := by exact_mod_cast hP + have hGr : (0:ℝ)≤G := Nat.cast_nonneg G + have hnat:=Nat.lt_mul_div_succ (F*P) (show 0<2*k+1 by omega) + have hupper : (F:ℝ)*P<(2*(k:ℝ)+1)*((G:ℝ)+1) := by exact_mod_cast hnat + have hF' := mul_le_mul_of_nonneg_right hF (show (0:ℝ)≤P by positivity) + have hupper' := mul_lt_mul_of_pos_left hupper hp.1 + have hlower:=mul_le_mul_of_nonneg_left hF' hp.1.le + have hC' := mul_le_mul_of_nonneg_right hC (show (0:ℝ)≤(k:ℝ)*(P:ℝ)^2 by positivity) + have hden : (2*(k:ℝ)+1)*(p*((G:ℝ)+1))≤3*(k:ℝ)*(p*((G:ℝ)+1)) := by + apply mul_le_mul_of_nonneg_right (by linarith) + positivity [hp.1.le] + have hmain : (1073741824:ℝ)*(P:ℝ)^2<3*p*((G:ℝ)+1) := by + have h : (k:ℝ)*(1073741824*(P:ℝ)^2)<(k:ℝ)*(3*p*((G:ℝ)+1)) := by + nlinarith only [hlower,hupper',hC',hden] + exact (mul_lt_mul_iff_of_pos_left (by linarith : (0:ℝ) coordinateWord (fun i => f (a i))) (pureAtomRun w (n*k+m)) := by + apply SimulatesTrace.random_partition + intro S + rw [←uniform_schedule_word S w k] + apply coordinateProduct_simulates + intro i + by_cases h : i∈S.val + · simpa only [h,ite_true] using hQ + · simpa only [h,ite_false] using hP + +/-- Explicit source common-part lifting, using finite auxiliary observations +that decode exactly to ordinary complete traces of the adjacent pure powers. -/ +theorem adjacent_power_lift {F k R : ℕ} {C p q : ℝ} + (hk : 1≤k) (hR : 1≤R) (hp : p∈Set.Ioc 0 (1/8)) (hq : q∈Set.Icc 0 1) + (hC : 1073741824≤p*C) (hF : C*k*R≤F) + (P Q : FiniteLaw α) (f : α→List Bool) (w : List Bool) + (hP : SimulatesTrace q P f (pureAtomRun w k)) + (hQ : SimulatesTrace q Q f (pureAtomRun w (k+1))) + (hov : p≤FiniteLaw.overlap P Q) : + ∃ (β : Type u) (_ : Fintype β) (P' Q' : FiniteLaw β) (g : β→List Bool), + SimulatesTrace q P' g (pureAtomRun w (F*R)) ∧ + SimulatesTrace q Q' g (pureAtomRun w (F*R+R)) ∧ + (2/3:ℝ)≤FiniteLaw.overlap P' Q' := by + let G := F*R/(2*k+1) + have hs : (1048576:ℝ)*(R:ℝ)^2≤p*(G:ℝ) := lifting_count_scale hk hR hp hC hF + obtain ⟨hG,hr⟩:=lifting_scale_valid hR hp hs + let A:=uniformSchedulePayload (n:=2*G) P Q G (by omega) + let B:=uniformSchedulePayload (n:=2*G) P Q (G+R) (by omega) + have htv : A.tv B≤1/3 := + (uniformSchedulePayload_steps hG hr hp P Q hov).trans (lifting_numeric_bound hR hp hs) + let tail:=pureAtomRun w (F*R-G*(2*k+1)) + let S:=maskLaw (n:=tail.length) q hq + let g : (Fin (2*G)→α)×Mask tail.length→List Bool := + fun a => coordinateWord (fun i => f (a.1 i))++traceOfMask tail.get a.2 + refine ⟨(Fin (2*G)→α)×Mask tail.length,inferInstance,A.prod S,B.prod S,g,?_,?_,?_⟩ + · have ha:=uniformSchedulePayload_simulates (n:=2*G) (by omega : G≤2*G) P Q f w hP hQ + have ht:=(ha.append (maskLaw_simulates hq tail)) + have hh : G*(2*k+1)≤F*R := Nat.div_mul_le_self _ _ + have he : 2*G*k+G+(F*R-G*(2*k+1))=F*R := by + have he0 : G*(2*k+1)=2*G*k+G := by ring + omega + simpa only [tail,←pureAtomRun_add,he] using ht + · have hb:=uniformSchedulePayload_simulates (n:=2*G) (by omega : G+R≤2*G) P Q f w hP hQ + have ht:=(hb.append (maskLaw_simulates hq tail)) + have hh : G*(2*k+1)≤F*R := Nat.div_mul_le_self _ _ + have he : 2*G*k+(G+R)+(F*R-G*(2*k+1))=F*R+R := by + have he0 : G*(2*k+1)=2*G*k+G := by ring + omega + simpa only [tail,←pureAtomRun_add,he] using ht + · rw [FiniteLaw.overlap_eq_one_sub_tv,FiniteLaw.tv_prod_eq_left] + linarith + +end TraceReconstruction + + + +/-! +Concrete objects for the scale inequalities, Definition 3 (the level invariant). +The observable channel remains the complete deletion trace of a literal word. +-/ +noncomputable section +namespace TraceReconstruction +open scoped Classical + +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +/-- The maximizing test for total variation on a finite sample space. -/ +theorem tv_eq_positive_test (P Q : FiniteLaw α) : + P.tv Q = P.expect (fun a => if Q.mass a ≤ P.mass a then 1 else 0) - + Q.expect (fun a => if Q.mass a ≤ P.mass a then 1 else 0) := by + have hz : (∑ a, (P.mass a - Q.mass a)) = 0 := by + rw [Finset.sum_sub_distrib, P.total, Q.total, sub_self] + have he (a : α) : + |P.mass a-Q.mass a|+(P.mass a-Q.mass a) = + 2*((P.mass a-Q.mass a)*(if Q.mass a ≤ P.mass a then 1 else 0)) := by + split_ifs with h + · rw [abs_of_nonneg (sub_nonneg.mpr h)]; ring + · rw [abs_of_neg (sub_neg.mpr (lt_of_not_ge h))]; ring + have hs := congrArg (fun f : α → ℝ => ∑ a, f a) (funext he) + simp only [Finset.sum_add_distrib, hz, add_zero, ← Finset.mul_sum] at hs + simp only [tv, expect] + rw [← Finset.sum_sub_distrib] + simp_rw [← sub_mul] + linarith only [hs] + +/-- Dual characterization, sufficient for simulators with different latent spaces. -/ +theorem tv_le_of_tests (P Q : FiniteLaw α) {E : ℝ} + (h : ∀ f : α → ℝ, (∀ a, f a ∈ Set.Icc 0 1) → + P.expect f-Q.expect f ≤ E) : P.tv Q ≤ E := by + rw [tv_eq_positive_test] + exact h _ (fun a => by split_ifs <;> norm_num) + +theorem abs_expect_sub_le_tv (P Q : FiniteLaw α) (f : α → ℝ) + (hf : ∀ a, f a ∈ Set.Icc 0 1) : |P.expect f-Q.expect f| ≤ P.tv Q := by + apply abs_le.mpr + constructor + · have h := expectation_diff_le_tv Q P f hf + rw [tv_symm Q P] at h + change Q.expect f-P.expect f ≤ P.tv Q at h + linarith + · exact expectation_diff_le_tv P Q f hf +end FiniteLaw + +/-- The genuine complete-trace law embedded in a specified finite trace space. +The extra elements have mass zero, not a cemetery mass. -/ +def listTraceLaw (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) + (M : ℕ) (hw : w.length ≤ M) : FiniteLaw (BoundedTrace M) := + (maskLaw (n:=w.length) q hq).map (fun a => + ⟨traceOfMask w.get a, mem_traceSpace_of_length_le _ + ((traceOfMask_length_le w.get a).trans hw)⟩) + +theorem listTraceLaw_expect (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) + (M : ℕ) (hw : w.length ≤ M) (F : List Bool → ℝ) : + (listTraceLaw q hq w M hw).expect (fun a => F a.val) = + listDeletionExpectation q w F := by + rw [listTraceLaw, FiniteLaw.expect_map] + have h := listDeletionExpectation_ofFn q w.get F + rw [List.ofFn_get] at h + exact h.symm + +theorem listTraceLaw_simulates (q : ℝ) (hq : q ∈ Set.Icc 0 1) (w : List Bool) + (M : ℕ) (hw : w.length ≤ M) : + SimulatesTrace q (listTraceLaw q hq w M hw) Subtype.val w := + listTraceLaw_expect q hq w M hw + +/-- Ordinary overlap of complete traces, including unequal input lengths. -/ +def listTraceOverlap (q : ℝ) (hq : q ∈ Set.Icc 0 1) (x y : List Bool) : ℝ := + let M := max x.length y.length + FiniteLaw.overlap (listTraceLaw q hq x M (le_max_left _ _)) + (listTraceLaw q hq y M (le_max_right _ _)) + +/-- Common approximate simulation transfers distinguishability to genuine +complete traces, without revealing the latent partition. -/ +theorem approximations_trace_tv {α : Type*} [Fintype α] + {q : ℝ} (hq : q ∈ Set.Icc 0 1) (P Q : FiniteLaw α) (decode : α → List Bool) + (x y : List Bool) (Ex Ey : ℝ) (M : ℕ) (hx : x.length ≤ M) (hy : y.length ≤ M) + (hP : ApproximatesTrace q P decode x Ex) + (hQ : ApproximatesTrace q Q decode y Ey) : + (listTraceLaw q hq x M hx).tv (listTraceLaw q hq y M hy) ≤ P.tv Q+Ex+Ey := by + apply FiniteLaw.tv_le_of_tests + intro f hf + let F : List Bool → ℝ := fun t => if h : t ∈ traceSpace M then f ⟨t,h⟩ else 0 + have hF : ∀ t, F t ∈ Set.Icc 0 1 := by + intro t + dsimp [F] + split_ifs with h + · exact hf ⟨t,h⟩ + · norm_num + have hFx : (listTraceLaw q hq x M hx).expect f = listDeletionExpectation q x F := by + rw [← listTraceLaw_expect q hq x M hx F] + congr 1 + funext t + simp only [F, dite_eq_left t.property] + have hFy : (listTraceLaw q hq y M hy).expect f = listDeletionExpectation q y F := by + rw [← listTraceLaw_expect q hq y M hy F] + congr 1 + funext t + simp only [F, dite_eq_left t.property] + rw [hFx,hFy] + have hp := hP F hF + have hq' := hQ F hF + have ht := FiniteLaw.abs_expect_sub_le_tv P Q (fun a => F (decode a)) (fun a => hF _) + linarith [le_abs_self (P.expect (fun a => F (decode a))-Q.expect (fun a => F (decode a))), + (abs_le.mp hp).1, (abs_le.mp hp).2, (abs_le.mp hq').1, (abs_le.mp hq').2] + +/-- A literal witness of the source level invariant. `halfOrder` is half its +positive even moment order. `countFactor` is the prescribed upper multiplier +`C^(2*B*i+O_B(1))`, to be instantiated uniformly in the actual construction. +Finite outcomes suffice for the source's finite latent experiments, and any +randomized common decoder can be included as an additional latent draw. -/ +structure ConcreteLevelPair (q : ℝ) (hq : q ∈ Set.Icc 0 1) + (N Δ d ω countFactor : ℝ) (i halfOrder : ℕ) where + left : List Bool + right : List Bool + equalLength : left.length = right.length + different : left ≠ right + length_lower : N/2 ≤ (left.length : ℝ) + length_upper : (left.length : ℝ) ≤ N + Outcome : Type + finiteOutcome : Fintype Outcome + firstLaw : @FiniteLaw Outcome finiteOutcome + secondLaw : @FiniteLaw Outcome finiteOutcome + decode : Outcome → List Bool + error : ℝ + error_nonneg : 0 ≤ error + normalized_error : error/(left.length : ℝ) ≤ ((i:ℝ)+1)*Δ + first_simulation : @ApproximatesTrace Outcome finiteOutcome q firstLaw decode left error + second_simulation : @ApproximatesTrace Outcome finiteOutcome q secondLaw decode right error + score : Outcome → ℝ + density : ∀ a, secondLaw.mass a = firstLaw.mass a*(1+score a) + score_bound : @FiniteLaw.evenMomentSq Outcome finiteOutcome firstLaw score halfOrder ≤ N ^ (-d) + overlapCount : ℕ + overlapCount_lower : left.length ≤ overlapCount + overlapCount_upper : (overlapCount:ℝ) ≤ countFactor*(left.length:ℝ) + power_overlap : ω ≤ listTraceOverlap q hq (pureAtomRun left overlapCount) + (pureAtomRun left (overlapCount+1)) + +end TraceReconstruction + + + +/-! The actual finite paired-flag experiment. We separate its unconditional +orientation-first generation (used for trace simulation) from its exact +metadata-first Bayes factorization (used for the density estimates). +Neither construction conditions on successful window layout. -/ +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace FiniteLaw +variable {α β γ : Type*} [Fintype α] [Fintype β] [Fintype γ] + +/-- A joint law retaining both the latent variable and its conditional draw. -/ +def joint (P : FiniteLaw α) (K : α → FiniteLaw β) : FiniteLaw (α × β) where + mass z := P.mass z.1 * (K z.1).mass z.2 + nonneg z := mul_nonneg (P.nonneg _) ((K _).nonneg _) + total := by + rw [Fintype.sum_prod_type] + simp_rw [← Finset.mul_sum, (K _).total, mul_one] + exact P.total + +theorem expect_joint (P : FiniteLaw α) (K : α → FiniteLaw β) (F : α × β → ℝ) : + (P.joint K).expect F = P.expect (fun a => (K a).expect (fun b => F (a,b))) := by + simp only [expect, joint, Fintype.sum_prod_type, Finset.mul_sum, mul_assoc] + +theorem expect_mixture (P : FiniteLaw α) (K : α → FiniteLaw β) (F : β → ℝ) : + (P.mixture K).expect F = P.expect (fun a => (K a).expect F) := by + simp only [expect, mixture, Finset.sum_mul, Finset.mul_sum, mul_assoc] + exact Finset.sum_comm + +theorem mixture_eq_bind (P : FiniteLaw α) (K : α → FiniteLaw β) : + P.mixture K = P.bind K := rfl + +/-- Independent maps commute with the literal finite product law. -/ +theorem coordinateProduct_map {n : ℕ} (P : Fin n → FiniteLaw α) + (f : Fin n → α → β) : + (coordinateProduct P).map (fun a i => f i (a i)) = + coordinateProduct (fun i => (P i).map (f i)) := by + apply FiniteLaw.ext + funext b + rw [map_mass] + change (∑ a : Fin n → α, if (fun i => f i (a i)) = b then ∏ i, (P i).mass (a i) else 0) = + ∏ i, ((P i).map (f i)).mass (b i) + simp_rw [map_mass] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro a _ + by_cases hab : (fun i => f i (a i)) = b + · rw [ite_eq_left hab] + apply Finset.prod_congr rfl + intro i _ + rw [ite_eq_left (congrFun hab i)] + · rw [ite_eq_right hab] + symm + have hi : ∃ i, f i (a i) ≠ b i := by + by_contra h + push Not at h + exact hab (funext h) + obtain ⟨i,hi⟩ := hi + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +/-- Forgetting the report recovers the two independent side emissions. -/ +theorem pairedFlagLaw_map (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) + (b : Bool) : + (pairedFlagLaw P Q H hω hP hQ b).map Prod.snd = orientedProd P Q b := by + apply FiniteLaw.ext + funext z + rw [map_mass, Fintype.sum_prod_type] + simp only [pairedFlagLaw] + simp_rw [Finset.sum_ite_eq'] + simp only [Finset.mem_univ, ite_true] + exact pairedFlag_simulation P Q H ω b z + +end FiniteLaw + +variable {Side Leaf : Type*} [Fintype Side] [Fintype Leaf] {m n : ℕ} + +/-- Data of the paired mechanisms, with common submass proved for each side. +All words and their actual trace laws will be substituted in these fields. -/ +structure PairedMechanisms (Side : Type*) [Fintype Side] (m : ℕ) where + first : Fin m → FiniteLaw Side + second : Fin m → FiniteLaw Side + common : Fin m → FiniteLaw Side + hiddenWeight : Fin m → ℝ + weight_nonneg : ∀ i, 0 ≤ hiddenWeight i + common_first : ∀ i a, hiddenWeight i*(common i).mass a ≤ (first i).mass a + common_second : ∀ i a, hiddenWeight i*(common i).mass a ≤ (second i).mass a + +abbrev Reports (Side : Type*) (m : ℕ) := Fin m → Option Bool × (Side × Side) + +namespace PairedMechanisms +variable (M : PairedMechanisms Side m) + +def reports : FiniteLaw (Reports Side m) := + FiniteLaw.coordinateProduct (fun i => FiniteLaw.pairedReport (M.first i) (M.second i) + (M.common i) (M.weight_nonneg i) (M.common_first i) (M.common_second i)) + +def reportsGiven (b : Fin m → Bool) : FiniteLaw (Reports Side m) := + FiniteLaw.coordinateProduct (fun i => FiniteLaw.pairedFlagLaw (M.first i) (M.second i) + (M.common i) (M.weight_nonneg i) (M.common_first i) (M.common_second i) (b i)) + +/-- Bit orientations, prior to generating any emissions. -/ +def fairOrientations (m : ℕ) : FiniteLaw (Fin m → Bool) := + (FiniteLaw.flagPosterior none).product m + +/-- Exact posterior, with zero-mass metadata treated by the same canonical +formula. In particular unseen orientations are independent fair bits. -/ +def orientationsGiven (z : Reports Side m) : FiniteLaw (Fin m → Bool) := + FiniteLaw.coordinateProduct (fun i => FiniteLaw.flagPosterior (z i).1) + +def selectedLeafLaw (P Q : FiniteLaw Leaf) (θ : Fin n → Bool) : + FiniteLaw (Fin n → Leaf) := + FiniteLaw.coordinateProduct (fun i => if θ i then Q else P) + +/-- Actual orientation-first, unconditioned augmented observation. -/ +def orientationOracle (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : + FiniteLaw (Reports Side m × (Fin n → Leaf)) := + (fairOrientations m).mixture (fun b => (M.reportsGiven b).prod (selectedLeafLaw P Q (θ b))) + +/-- Metadata-first factorization of exactly the same law, not a new oracle. -/ +def canonicalOracle (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : + FiniteLaw (Reports Side m × (Fin n → Leaf)) := + M.reports.joint (fun z => (orientationsGiven z).mixture (fun b => selectedLeafLaw P Q (θ b))) + +theorem oracle_factorization (P Q : FiniteLaw Leaf) (θ : (Fin m → Bool) → Fin n → Bool) : + M.orientationOracle P Q θ = M.canonicalOracle P Q θ := by + apply FiniteLaw.ext + funext zx + rcases zx with ⟨z,x⟩ + change (∑ b, (∏ i : Fin m, (1/2:ℝ)) * + ((∏ i, FiniteLaw.pairedFlagMass (M.first i) (M.second i) (M.common i) + (M.hiddenWeight i) (b i) (z i)) * (selectedLeafLaw P Q (θ b)).mass x)) = + (∏ i, FiniteLaw.pairedReportMass (M.first i) (M.second i) (M.common i) + (M.hiddenWeight i) (z i)) * + (∑ b, (∏ i, (FiniteLaw.flagPosterior (z i).1).mass (b i)) * (selectedLeafLaw P Q (θ b)).mass x) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro b _ + rw [← mul_assoc, ← Finset.prod_mul_distrib, + FiniteLaw.pairedFlags_product_bayes, mul_assoc] + +/-- The reference is independent old-first-law emissions, even after reporting +all side traces. This equality is exact for every metadata value. -/ +theorem canonicalOracle_density (P Q : FiniteLaw Leaf) (Z : Leaf → ℝ) + (hZ : ∀ a, Q.mass a = P.mass a*(1+Z a)) + (θ : (Fin m → Bool) → Fin n → Bool) (z : Reports Side m) (x : Fin n → Leaf) : + (M.canonicalOracle P Q θ).mass (z,x) = + (M.reports.prod (P.product n)).mass (z,x) * + averagedDensity (orientationsGiven z) θ Z x := by + change M.reports.mass z * + ((orientationsGiven z).mixture (fun b => FiniteLaw.coordinateProduct + (fun i => if θ b i then Q else P))).mass x = _ + rw [leaf_oracle_density P Q Z hZ] + exact (mul_assoc _ _ _).symm + +/-- The full side metadata has a common law for both hypotheses. -/ +theorem canonicalOracle_metadata (P Q : FiniteLaw Leaf) + (θ : (Fin m → Bool) → Fin n → Bool) (F : Reports Side m → ℝ) : + (M.canonicalOracle P Q θ).expect (fun z => F z.1) = M.reports.expect F := by + rw [canonicalOracle, FiniteLaw.expect_joint] + simp only [FiniteLaw.expect_const] + +/-- Conditional on every orientation, forgetting flags gives independent side +emissions. This is the unconditional simulation side of the construction. -/ +theorem reportsGiven_forget (b : Fin m → Bool) : + (M.reportsGiven b).map (fun z i => (z i).2) = + FiniteLaw.coordinateProduct (fun i => FiniteLaw.orientedProd (M.first i) (M.second i) (b i)) := by + rw [reportsGiven, FiniteLaw.coordinateProduct_map] + congr 1 + funext i + exact FiniteLaw.pairedFlagLaw_map _ _ _ _ _ _ _ + +end PairedMechanisms +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Parity.lean b/lean/OAI/Probability/TraceReconstruction/Parity.lean index 058a7cb9c790a67ee0eb75b44de76fee9c947e02..300b49cea1dccbbf1424da422e9a3d3cbcac64a5 100644 --- a/lean/OAI/Probability/TraceReconstruction/Parity.lean +++ b/lean/OAI/Probability/TraceReconstruction/Parity.lean @@ -1,504 +1,504 @@ -import Mathlib - -namespace OAI - -/-! -# Parity - -Parity-tree roles, forced leaves, coefficient shapes, and exact unsigned/signed motif expansions. --/ - -open scoped ENNReal -noncomputable section - -namespace TraceReconstruction - -/-- Three roles of an active odd child in the manuscript parity expansion: -constant, unsigned motif, and signed motif. -/ -def roleWeight (χ σ : ℝ) (r : Fin 3) : ℝ := - if r=0 then 1 else if r=1 then -χ else σ - -def signedRoleCount {n : ℕ} (r : Fin n → Fin 3) : ℕ := - (Finset.univ.filter fun i => r i=2).card - -def activeRoleCount {n : ℕ} (r : Fin n → Fin 3) : ℕ := - (Finset.univ.filter fun i => r i≠0).card - -theorem role_product_expansion {n : ℕ} (χ σ : Fin n → ℝ) (τ : ℝ) : - (∏ i : Fin n, (1 - χ i + σ i * τ)) = - ∑ r : Fin n → Fin 3, (∏ i, roleWeight (χ i) (σ i) (r i)) * τ^signedRoleCount r := by - have hp (r : Fin n → Fin 3) : ∏ i, (if r i=2 then τ else (1:ℝ)) = τ^signedRoleCount r := by - rw [← Finset.prod_filter] - simp only [Finset.prod_const, signedRoleCount] - simp_rw [← hp, ← Finset.prod_mul_distrib] - rw [← Fintype.prod_sum (fun (i : Fin n) (r : Fin 3) => roleWeight (χ i) (σ i) r * (if r=2 then τ else 1))] - apply Finset.prod_congr rfl - intro i _ - simp [Fin.sum_univ_three, roleWeight] - ring - -theorem odd_role_difference {n : ℕ} (χ σ : Fin n → ℝ) : - (∏ i : Fin n, (1 - χ i + σ i)) - (∏ i : Fin n, (1 - χ i - σ i)) = - 2*∑ r : Fin n → Fin 3, - if Odd (signedRoleCount r) then ∏ i, roleWeight (χ i) (σ i) (r i) else 0 := by - have hplus := role_product_expansion χ σ 1 - have hminus := role_product_expansion χ σ (-1) - simp only [mul_one, one_pow] at hplus - simp only [mul_neg_one, ← sub_eq_add_neg] at hminus - rw [hplus,hminus, ← Finset.sum_sub_distrib, Finset.mul_sum] - apply Finset.sum_congr rfl - intro r _ - by_cases hr : Odd (signedRoleCount r) - · rw [ite_eq_left hr, hr.neg_one_pow] - ring - · have he : Even (signedRoleCount r) := Nat.not_odd_iff_even.mp hr - rw [ite_eq_right hr, he.neg_one_pow] - ring - -theorem signedRoleCount_le_active {n : ℕ} (r : Fin n → Fin 3) : - signedRoleCount r ≤ activeRoleCount r := by - apply Finset.card_le_card - intro i hi - simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi ⊢ - rw [hi] - decide - -/-- A surviving odd node either has a unique active signed motif (the -local high-order cancellation case), or at least two active children. -/ -theorem odd_roles_singleton_or_branch {n : ℕ} (r : Fin n → Fin 3) - (hodd : Odd (signedRoleCount r)) : - (∃ i, r i=2 ∧ ∀ j, j≠i → r j=0) ∨ 2 ≤ activeRoleCount r := by - have hpos : 0 < signedRoleCount r := hodd.pos - have hle := signedRoleCount_le_active r - by_cases h : 2 ≤ activeRoleCount r - · exact Or.inr h - have ha : activeRoleCount r=1 := by omega - obtain ⟨i,hi⟩ := Finset.card_eq_one.mp ha - have hmem : ∀ j, r j≠0 ↔ j=i := by - intro j - have he := Finset.ext_iff.mp hi j - simpa only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] using he - have hs : ∃ j, r j=2 := by - have hs0 : (Finset.univ.filter fun j => r j=2).Nonempty := Finset.card_pos.mp hpos - obtain ⟨j,hj⟩ := hs0 - exact ⟨j, (Finset.mem_filter.mp hj).2⟩ - obtain ⟨j,hj⟩ := hs - have hij := (hmem j).mp (by rw [hj]; decide) - subst j - exact Or.inl ⟨i,hj,fun j hji => Classical.byContradiction (fun hn => hji ((hmem j).mp hn))⟩ - -/-- Finite occupied trees with at least two continuing odd children at -each positive depth. This records exactly the no-singleton branch of -the parity argument; the arity and all extra children remain arbitrary. -/ -inductive BranchingTree : ℕ → Type - | leaf : BranchingTree 0 - | node {b : ℕ} (n : ℕ) (children : Fin n → BranchingTree b) (branch : 2 ≤ n) : BranchingTree (b+1) - -def BranchingTree.leafCount : {b : ℕ} → BranchingTree b → ℕ - | _, .leaf => 1 - | _, .node _ children _ => ∑ i, (children i).leafCount - -def BranchingTree.levelCount : {b : ℕ} → BranchingTree b → ℕ → ℕ - | _, .leaf, h => if h=0 then 1 else 0 - | _, .node _ children _, h => if h=0 then 1 else ∑ i, (children i).levelCount (h-1) - -theorem BranchingTree.leafCount_lower {b : ℕ} (t : BranchingTree b) : - 2^b ≤ t.leafCount := by - induction t with - | leaf => simp [leafCount] - | @node b n children hn ih => - have h := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin n))) => ih i) - simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] at h - have hmul := Nat.mul_le_mul_right (2^b) hn - simp only [leafCount] - rw [pow_succ] - omega - - - -/-- A term in the parity expansion retains the occupied ordered shape, -all roles, and all extra children, rather than assuming it is binary. -/ -inductive OccupiedParityTree : ℕ → Type - | leaf : OccupiedParityTree 0 - | node {b : ℕ} (n : ℕ) (children : Fin n → OccupiedParityTree b) - (roles : Fin n → Fin 3) : OccupiedParityTree (b+1) - -def OccupiedParityTree.isOdd : {b : ℕ} → OccupiedParityTree b → Prop - | _, .leaf => True - | _, .node _ _ roles => Odd (signedRoleCount roles) - -def OccupiedParityTree.leafCount : {b : ℕ} → OccupiedParityTree b → ℕ - | _, .leaf => 1 - | _, .node _ children _ => ∑ i, (children i).leafCount - -/-- Only odd-role child terms may acquire an active parent multiplier. -/ -def OccupiedParityTree.valid : {b : ℕ} → OccupiedParityTree b → Prop - | _, .leaf => True - | _, .node _ children roles => - (∀ i, roles i ≠ 0 → (children i).isOdd) ∧ ∀ i, (children i).valid - -def OccupiedParityTree.noSingleton : {b : ℕ} → OccupiedParityTree b → Prop - | _, .leaf => True - | _, .node _ children roles => - (Odd (signedRoleCount roles) → activeRoleCount roles ≠ 1) ∧ - ∀ i, (children i).noSingleton - -/-- The exact forced binary number of selected leaves, with all extra -occupied vertices present. The hypotheses here are checked properties -of a parity term, not a statistical or construction theorem. -/ -theorem OccupiedParityTree.forced_leaves {b : ℕ} (t : OccupiedParityTree b) - (hv : t.valid) (hn : t.noSingleton) (ho : t.isOdd) : 2^b ≤ t.leafCount := by - induction t with - | leaf => simp [leafCount] - | @node b n children roles ih => - have hod : Odd (signedRoleCount roles) := ho - have hpos := hod.pos - have hle := signedRoleCount_le_active roles - have hne := hn.1 hod - have ha : 2 ≤ activeRoleCount roles := by omega - have hsum : (∑ i : Fin n, if roles i≠0 then 2^b else 0) ≤ - ∑ i : Fin n, (children i).leafCount := by - apply Finset.sum_le_sum - intro i _ - split_ifs with hi - · exact ih i (hv.2 i) (hn.2 i) (hv.1 i hi) - · exact Nat.zero_le _ - have hs : (∑ i : Fin n, if roles i≠0 then 2^b else 0) = activeRoleCount roles * 2^b := by - rw [← Finset.sum_filter] - simp only [Finset.sum_const, smul_eq_mul, activeRoleCount] - rw [hs] at hsum - change 2^(b+1) ≤ _ - rw [pow_succ] - exact (show 2^b*2 ≤ activeRoleCount roles*2^b by - simpa only [Nat.mul_comm] using Nat.mul_le_mul_right (2^b) ha).trans hsum - -end TraceReconstruction - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -attribute [local instance] Classical.propDecidable - -/-- The literal unsigned/signed motif values at one child index. -/ -def IsMotifValue (χ σ : ℝ) : Prop := - (χ=0 ∧ σ=0) ∨ (χ=1 ∧ (σ=1 ∨ σ= -1)) - -def IsTypeSign (τ : ℝ) : Prop := τ=1 ∨ τ= -1 - -theorem motif_child_sign {χ σ τ : ℝ} (hm : IsMotifValue χ σ) (ht : IsTypeSign τ) : - IsTypeSign (1-χ+σ*τ) := by - rcases hm with ⟨rfl,rfl⟩ | ⟨rfl,hσ⟩ - · exact Or.inl (by ring) - · rcases hσ with rfl | rfl <;> rcases ht with rfl | rfl <;> - norm_num [IsTypeSign] - -theorem sign_pow_parity {τ : ℝ} (ht : IsTypeSign τ) (n : ℕ) : - τ^n = if Odd n then τ else 1 := by - rcases ht with rfl | rfl - · simp - · split_ifs with hn - · exact hn.neg_one_pow - · exact (Nat.not_odd_iff_even.mp hn).neg_one_pow - -/-- Product expansion with an arbitrary three-role scalar per child; the -only sign variable is the current vertex type. -/ -theorem arbitrary_role_expansion {n : ℕ} (w : Fin n → Fin 3 → ℝ) (τ : ℝ) : - (∏ i, ∑ a : Fin 3, w i a * (if a=2 then τ else 1)) = - ∑ a : Fin n → Fin 3, (∏ i, w i (a i))*τ^signedRoleCount a := by - rw [Finset.prod_univ_sum] - simp only [Fintype.piFinset_univ,Finset.prod_mul_distrib] - apply Finset.sum_congr rfl - intro a _ - congr 1 - rw [← Finset.prod_filter] - simp [signedRoleCount] - -/-- At the last internal level every selected leaf has to be active. -Role zero has weight zero; unsigned and signed roles are respectively -χ/2 and -σ/2 in (χ-στ)/2. -/ -def bottomRoleWeight (χ σ : ℝ) (a : Fin 3) : ℝ := - if a=0 then 0 else if a=1 then χ/2 else -σ/2 - -def internalRoleWeight (odd : Prop) [Decidable odd] (χ σ : ℝ) (a : Fin 3) : ℝ := - if odd then roleWeight χ σ a else if a=0 then 1 else 0 - -theorem bottomRole_sum (χ σ τ : ℝ) : - (∑ a : Fin 3, bottomRoleWeight χ σ a*(if a=2 then τ else 1)) = (χ-σ*τ)/2 := by - rw [Fin.sum_univ_three] - have h01 : (0:Fin 3) ≠ 1 := by decide - have h02 : (0:Fin 3) ≠ 2 := by decide - have h12 : (1:Fin 3) ≠ 2 := by decide - simp only [bottomRoleWeight,h02,h12,Ne.symm h01,Ne.symm h02,Ne.symm h12, - ↓reduceIte,zero_add,mul_one] - ring - -theorem internalRole_sum (odd : Prop) [Decidable odd] (χ σ τ : ℝ) : - (∑ a : Fin 3, internalRoleWeight odd χ σ a*(if a=2 then τ else 1)) = - if odd then 1-χ+σ*τ else 1 := by - rw [Fin.sum_univ_three] - have h01 : (0:Fin 3) ≠ 1 := by decide - have h02 : (0:Fin 3) ≠ 2 := by decide - have h12 : (1:Fin 3) ≠ 2 := by decide - by_cases h : odd <;> simp only [internalRoleWeight,roleWeight,h,h02,h12, - Ne.symm h01,Ne.symm h02,Ne.symm h12,↓reduceIte,zero_mul,add_zero,mul_one] - ring - -/-- An arbitrary occupied ordered subtree, with motif values at its actual -child labels. Depth zero here means a bottom sibling group, so it already -has one internal level. No binary-shape assumption is made. -/ -inductive CoefficientShape : ℕ → Type - | bottom (n : ℕ) (χ σ : Fin n → ℝ) : CoefficientShape 0 - | node {b : ℕ} (n : ℕ) (χ σ : Fin n → ℝ) - (children : Fin n → CoefficientShape b) : CoefficientShape (b+1) - -namespace CoefficientShape - -def Admissible : {b : ℕ} → CoefficientShape b → Prop - | _, .bottom _ χ σ => ∀ i, IsMotifValue (χ i) (σ i) - | _, .node _ χ σ children => (∀ i, IsMotifValue (χ i) (σ i)) ∧ ∀ i, (children i).Admissible - -def eval : {b : ℕ} → CoefficientShape b → ℝ → ℝ - | _, .bottom _ χ σ, τ => ∏ i, (χ i-σ i*τ)/2 - | _, .node _ χ σ children, τ => ∏ i, (children i).eval (1-χ i+σ i*τ) - -def Choice : {b : ℕ} → CoefficientShape b → Type - | _, .bottom n _ _ => Fin n → Fin 3 - | _, .node n _ _ children => ((i : Fin n) → (children i).Choice) × (Fin n → Fin 3) - -noncomputable instance choiceFintype : {b : ℕ} → (t : CoefficientShape b) → Fintype t.Choice - | _, .bottom _ _ _ => by unfold Choice; infer_instance - | _, .node _ _ _ children => by - letI := fun i => choiceFintype (children i) - unfold Choice - infer_instance - -def termTree : {b : ℕ} → (t : CoefficientShape b) → t.Choice → OccupiedParityTree (b+1) - | _, .bottom n _ _, a => .node n (fun _ => .leaf) a - | _, .node n _ _ children, a => .node n (fun i => (children i).termTree (a.1 i)) a.2 - -noncomputable def weight : {b : ℕ} → (t : CoefficientShape b) → t.Choice → ℝ - | _, .bottom _ χ σ, a => ∏ i, bottomRoleWeight (χ i) (σ i) (a i) - | _, .node _ χ σ children, a => ∏ i, - (children i).weight (a.1 i) * - @internalRoleWeight ((children i).termTree (a.1 i)).isOdd (Classical.propDecidable _) - (χ i) (σ i) (a.2 i) - -/-- Full finite coefficient expansion, before any orientation average or -fit-event conditioning. This is the literal algebra behind source -the correlated-anchor estimate, the parity roles being retained in every term. -/ -theorem expansion {b : ℕ} (t : CoefficientShape b) (ha : t.Admissible) - {τ : ℝ} (ht : IsTypeSign τ) : - t.eval τ = ∑ a : t.Choice, t.weight a * (if (t.termTree a).isOdd then τ else 1) := by - classical - induction t generalizing τ with - | bottom n χ σ => - have H := arbitrary_role_expansion (fun i => bottomRoleWeight (χ i) (σ i)) τ - simp_rw [bottomRole_sum,sign_pow_parity ht] at H - trans ∑ a : Fin n → Fin 3, (∏ i, bottomRoleWeight (χ i) (σ i) (a i)) * - (if Odd (signedRoleCount a) then τ else 1) - · exact H - · apply Finset.sum_congr rfl - intro a _ - apply congrArg (fun z => (∏ i, bottomRoleWeight (χ i) (σ i) (a i))*z) - change _ = @ite ℝ (Odd (signedRoleCount a)) (Classical.propDecidable _) τ 1 - split_ifs <;> rfl - | @node b n χ σ children ih => - change (∏ i, (children i).eval (1-χ i+σ i*τ)) = _ - have he (i : Fin n) := ih i (ha.2 i) (motif_child_sign (ha.1 i) ht) - simp_rw [he] - rw [Finset.prod_univ_sum] - simp only [Fintype.piFinset_univ] - change (∑ a : (i : Fin n) → (children i).Choice, - ∏ i, (children i).weight (a i)* - (if ((children i).termTree (a i)).isOdd then 1-χ i+σ i*τ else 1)) = - ∑ a : ((i : Fin n) → (children i).Choice) × (Fin n → Fin 3), - (∏ i, (children i).weight (a.1 i)* - internalRoleWeight ((children i).termTree (a.1 i)).isOdd (χ i) (σ i) (a.2 i))* - (@ite ℝ (Odd (signedRoleCount a.2)) (Classical.propDecidable _) τ 1) - rw [Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro a _ - have H := arbitrary_role_expansion (fun i => - internalRoleWeight ((children i).termTree (a i)).isOdd (χ i) (σ i)) τ - simp_rw [internalRole_sum,sign_pow_parity ht] at H - rw [Finset.prod_mul_distrib,H,Finset.mul_sum] - apply Finset.sum_congr rfl - intro a' _ - rw [Finset.prod_mul_distrib,mul_assoc] - congr 2 - split_ifs <;> rfl - -/-- Nonzero terms automatically satisfy the source active-odd rule. -/ -theorem term_valid {b : ℕ} (t : CoefficientShape b) (a : t.Choice) - (h : t.weight a ≠ 0) : (t.termTree a).valid := by - classical - induction t with - | bottom n χ σ => exact ⟨fun _ _ => trivial,fun _ => trivial⟩ - | @node b n χ σ children ih => - have hp (i : Fin n) : (children i).weight (a.1 i) * - internalRoleWeight ((children i).termTree (a.1 i)).isOdd (χ i) (σ i) (a.2 i) ≠ 0 := - (Finset.prod_ne_zero_iff.mp h) i (Finset.mem_univ i) - constructor - · intro i hai - by_contra hn - have hz := (mul_ne_zero_iff.mp (hp i)).2 - simp [internalRoleWeight,hn,hai] at hz - · intro i - exact ih i (a.1 i) (mul_ne_zero_iff.mp (hp i)).1 - -/-- The difference of hypotheses consists exactly of odd root terms. -/ -theorem difference_expansion {b : ℕ} (t : CoefficientShape b) (ha : t.Admissible) : - t.eval 1-t.eval (-1) = 2*∑ a : t.Choice, - if (t.termTree a).isOdd then t.weight a else 0 := by - classical - rw [expansion t ha (Or.inl rfl),expansion t ha (Or.inr rfl), - ← Finset.sum_sub_distrib,Finset.mul_sum] - apply Finset.sum_congr rfl - intro a _ - split_ifs <;> ring - -/-- A nonzero surviving term without a singleton odd vertex has the full -forced binary number of leaves. This follows from the actual expansion, -not an assumed parity interface. -/ -theorem surviving_leaves {b : ℕ} (t : CoefficientShape b) (a : t.Choice) - (hw : t.weight a ≠ 0) (ho : (t.termTree a).isOdd) - (hn : (t.termTree a).noSingleton) : 2^(b+1) ≤ (t.termTree a).leafCount := - (t.termTree a).forced_leaves (t.term_valid a hw) hn ho - -end CoefficientShape -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -namespace OccupiedParityTree - -/-- The actual binary selection sits inside an arbitrary occupied parity -term, retaining its unselected children rather than assuming binary input. -/ -inductive Forced : {b : ℕ} → OccupiedParityTree b → Type - | leaf : Forced .leaf - | node {b n : ℕ} {children : Fin n → OccupiedParityTree b} {roles : Fin n → Fin 3} - (a c : Fin n) (hne : a≠c) (ha : roles a≠0) (hc : roles c≠0) - (left : Forced (children a)) (right : Forced (children c)) : - Forced (.node n children roles) - -/-- Every surviving nonsingleton term has an embedded binary subtree. -The selection depends only on the role-marked shape. -/ -theorem forced_nonempty {b : ℕ} (t : OccupiedParityTree b) - (hv : t.valid) (hn : t.noSingleton) (ho : t.isOdd) : Nonempty t.Forced := by - classical - induction t with - | leaf => exact ⟨.leaf⟩ - | @node b n children roles ih => - have hod : Odd (signedRoleCount roles) := ho - have ha : 2 ≤ activeRoleCount roles := by - have := signedRoleCount_le_active roles - have := hod.pos - have := hn.1 hod - omega - obtain ⟨a,ha,c,hc,hne⟩ := Finset.one_lt_card.mp ha - have ha' : roles a≠0 := (Finset.mem_filter.mp ha).2 - have hc' : roles c≠0 := (Finset.mem_filter.mp hc).2 - obtain ⟨la⟩ := ih a (hv.2 a) (hn.2 a) (hv.1 a ha') - obtain ⟨lc⟩ := ih c (hv.2 c) (hn.2 c) (hv.1 c hc') - exact ⟨.node a c hne ha' hc' la lc⟩ - -/-- Occupied shapes have at least one selected leaf below every vertex. -/ -def occupied : {b : ℕ} → OccupiedParityTree b → Prop - | _, .leaf => True - | _, .node n children _ => 0 1 - | _, .leaf, _+1 => 0 - | _, .node _ children _, k+1 => ∑ i, (children i).levelCount k - -theorem leafCount_pos {b : ℕ} (t : OccupiedParityTree b) (ht : t.occupied) : - 0 exact Nat.zero_lt_one - | @node b n children roles ih => - let i : Fin n := ⟨0,ht.1⟩ - have hp := ih i (ht.2 i) - change 0 < ∑ k, (children k).leafCount - exact hp.trans_le (Finset.single_le_sum (fun k _ => Nat.zero_le ((children k).leafCount)) (Finset.mem_univ i)) - -theorem levelCount_le_leaves {b : ℕ} (t : OccupiedParityTree b) (ht : t.occupied) - (k : ℕ) : t.levelCount k ≤ t.leafCount := by - induction t generalizing k with - | leaf => cases k <;> norm_num [levelCount,leafCount] - | @node b n children roles ih => - cases k with - | zero => exact leafCount_pos (.node n children roles) ht - | succ k => exact Finset.sum_le_sum (fun i _ => ih i (ht.2 i) k) - -/-- Two chosen coordinates supply an additive gain in a finite sum. -/ -theorem sum_two_improvements {ι : Type*} [Fintype ι] [DecidableEq ι] - (x y : ι → ℕ) {a c : ι} (hne : a≠c) (A B : ℕ) - (hrest : ∀ i, i≠a → i≠c → x i≤y i) - (ha : x a+A≤y a+B) (hc : x c+A≤y c+B) : - (∑ i, x i)+2*A ≤ (∑ i, y i)+2*B := by - have hc' : c∈Finset.univ.erase a := by simp [hne.symm] - have hx1 := Finset.sum_erase_add Finset.univ x (Finset.mem_univ a) - have hy1 := Finset.sum_erase_add Finset.univ y (Finset.mem_univ a) - have hx2 := Finset.sum_erase_add (Finset.univ.erase a) x hc' - have hy2 := Finset.sum_erase_add (Finset.univ.erase a) y hc' - have hrem : (∑ i∈(Finset.univ.erase a).erase c, x i) ≤ - ∑ i∈(Finset.univ.erase a).erase c, y i := by - apply Finset.sum_le_sum - intro i hi - exact hrest i (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 - (Finset.mem_erase.mp hi).1 - omega - -theorem Forced.leaf_lower {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - 2^b ≤ t.leafCount := by - classical - induction F with - | leaf => simp [leafCount] - | @node b n children roles a c hne ha hc left right ihl ihr => - have hh := sum_two_improvements (fun _ : Fin n => 0) - (fun i => (children i).leafCount) hne (2^b) 0 - (fun _ _ _ => Nat.zero_le _) (by simpa using ihl) (by simpa using ihr) - simpa only [Finset.sum_const_zero,zero_add,add_zero,zero_mul,pow_succ,Nat.mul_comm,leafCount] using hh - -/-- At every positive nonroot level, each unforced occupied vertex costs - an extra leaf. This is the exact combinatorial inequality used when - additional (nonbinary) labels are summed in the correlated-anchor estimate. -/ -theorem Forced.level_extra {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (ht : t.occupied) (k : ℕ) : - t.levelCount k+2^b ≤ t.leafCount+2^k := by - classical - induction F generalizing k with - | leaf => cases k <;> simp [levelCount,leafCount] - | @node b n children roles a c hne ha hc left right ihl ihr => - cases k with - | zero => - have hl := (Forced.node a c hne ha hc left right).leaf_lower - simpa only [levelCount,pow_zero,Nat.add_comm] using Nat.add_le_add_left hl 1 - | succ k => - have hh := sum_two_improvements - (fun i => (children i).levelCount k) (fun i => (children i).leafCount) - hne (2^b) (2^k) (fun i _ _ => levelCount_le_leaves _ (ht.2 i) k) - (ihl (ht.2 a) k) (ihr (ht.2 c) k) - simpa only [levelCount,leafCount,pow_succ,Nat.mul_comm] using hh - -theorem Forced.nonforced_vertices_le_extra_leaves {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (ht : t.occupied) (k : ℕ) : - t.levelCount k-2^k ≤ t.leafCount-2^b := by - have := F.level_extra ht k - have := F.leaf_lower - omega - -end OccupiedParityTree -end TraceReconstruction - -end -end -end - -end OAI +import Mathlib + +namespace OAI + +/-! +# Parity + +Parity-tree roles, forced leaves, coefficient shapes, and exact unsigned/signed motif expansions. +-/ + +open scoped ENNReal +noncomputable section + +namespace TraceReconstruction + +/-- Three roles of an active odd child in the manuscript parity expansion: +constant, unsigned motif, and signed motif. -/ +def roleWeight (χ σ : ℝ) (r : Fin 3) : ℝ := + if r=0 then 1 else if r=1 then -χ else σ + +def signedRoleCount {n : ℕ} (r : Fin n → Fin 3) : ℕ := + (Finset.univ.filter fun i => r i=2).card + +def activeRoleCount {n : ℕ} (r : Fin n → Fin 3) : ℕ := + (Finset.univ.filter fun i => r i≠0).card + +theorem role_product_expansion {n : ℕ} (χ σ : Fin n → ℝ) (τ : ℝ) : + (∏ i : Fin n, (1 - χ i + σ i * τ)) = + ∑ r : Fin n → Fin 3, (∏ i, roleWeight (χ i) (σ i) (r i)) * τ^signedRoleCount r := by + have hp (r : Fin n → Fin 3) : ∏ i, (if r i=2 then τ else (1:ℝ)) = τ^signedRoleCount r := by + rw [← Finset.prod_filter] + simp only [Finset.prod_const, signedRoleCount] + simp_rw [← hp, ← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun (i : Fin n) (r : Fin 3) => roleWeight (χ i) (σ i) r * (if r=2 then τ else 1))] + apply Finset.prod_congr rfl + intro i _ + simp [Fin.sum_univ_three, roleWeight] + ring + +theorem odd_role_difference {n : ℕ} (χ σ : Fin n → ℝ) : + (∏ i : Fin n, (1 - χ i + σ i)) - (∏ i : Fin n, (1 - χ i - σ i)) = + 2*∑ r : Fin n → Fin 3, + if Odd (signedRoleCount r) then ∏ i, roleWeight (χ i) (σ i) (r i) else 0 := by + have hplus := role_product_expansion χ σ 1 + have hminus := role_product_expansion χ σ (-1) + simp only [mul_one, one_pow] at hplus + simp only [mul_neg_one, ← sub_eq_add_neg] at hminus + rw [hplus,hminus, ← Finset.sum_sub_distrib, Finset.mul_sum] + apply Finset.sum_congr rfl + intro r _ + by_cases hr : Odd (signedRoleCount r) + · rw [ite_eq_left hr, hr.neg_one_pow] + ring + · have he : Even (signedRoleCount r) := Nat.not_odd_iff_even.mp hr + rw [ite_eq_right hr, he.neg_one_pow] + ring + +theorem signedRoleCount_le_active {n : ℕ} (r : Fin n → Fin 3) : + signedRoleCount r ≤ activeRoleCount r := by + apply Finset.card_le_card + intro i hi + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi ⊢ + rw [hi] + decide + +/-- A surviving odd node either has a unique active signed motif (the +local high-order cancellation case), or at least two active children. -/ +theorem odd_roles_singleton_or_branch {n : ℕ} (r : Fin n → Fin 3) + (hodd : Odd (signedRoleCount r)) : + (∃ i, r i=2 ∧ ∀ j, j≠i → r j=0) ∨ 2 ≤ activeRoleCount r := by + have hpos : 0 < signedRoleCount r := hodd.pos + have hle := signedRoleCount_le_active r + by_cases h : 2 ≤ activeRoleCount r + · exact Or.inr h + have ha : activeRoleCount r=1 := by omega + obtain ⟨i,hi⟩ := Finset.card_eq_one.mp ha + have hmem : ∀ j, r j≠0 ↔ j=i := by + intro j + have he := Finset.ext_iff.mp hi j + simpa only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] using he + have hs : ∃ j, r j=2 := by + have hs0 : (Finset.univ.filter fun j => r j=2).Nonempty := Finset.card_pos.mp hpos + obtain ⟨j,hj⟩ := hs0 + exact ⟨j, (Finset.mem_filter.mp hj).2⟩ + obtain ⟨j,hj⟩ := hs + have hij := (hmem j).mp (by rw [hj]; decide) + subst j + exact Or.inl ⟨i,hj,fun j hji => Classical.byContradiction (fun hn => hji ((hmem j).mp hn))⟩ + +/-- Finite occupied trees with at least two continuing odd children at +each positive depth. This records exactly the no-singleton branch of +the parity argument; the arity and all extra children remain arbitrary. -/ +inductive BranchingTree : ℕ → Type + | leaf : BranchingTree 0 + | node {b : ℕ} (n : ℕ) (children : Fin n → BranchingTree b) (branch : 2 ≤ n) : BranchingTree (b+1) + +def BranchingTree.leafCount : {b : ℕ} → BranchingTree b → ℕ + | _, .leaf => 1 + | _, .node _ children _ => ∑ i, (children i).leafCount + +def BranchingTree.levelCount : {b : ℕ} → BranchingTree b → ℕ → ℕ + | _, .leaf, h => if h=0 then 1 else 0 + | _, .node _ children _, h => if h=0 then 1 else ∑ i, (children i).levelCount (h-1) + +theorem BranchingTree.leafCount_lower {b : ℕ} (t : BranchingTree b) : + 2^b ≤ t.leafCount := by + induction t with + | leaf => simp [leafCount] + | @node b n children hn ih => + have h := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin n))) => ih i) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] at h + have hmul := Nat.mul_le_mul_right (2^b) hn + simp only [leafCount] + rw [pow_succ] + omega + + + +/-- A term in the parity expansion retains the occupied ordered shape, +all roles, and all extra children, rather than assuming it is binary. -/ +inductive OccupiedParityTree : ℕ → Type + | leaf : OccupiedParityTree 0 + | node {b : ℕ} (n : ℕ) (children : Fin n → OccupiedParityTree b) + (roles : Fin n → Fin 3) : OccupiedParityTree (b+1) + +def OccupiedParityTree.isOdd : {b : ℕ} → OccupiedParityTree b → Prop + | _, .leaf => True + | _, .node _ _ roles => Odd (signedRoleCount roles) + +def OccupiedParityTree.leafCount : {b : ℕ} → OccupiedParityTree b → ℕ + | _, .leaf => 1 + | _, .node _ children _ => ∑ i, (children i).leafCount + +/-- Only odd-role child terms may acquire an active parent multiplier. -/ +def OccupiedParityTree.valid : {b : ℕ} → OccupiedParityTree b → Prop + | _, .leaf => True + | _, .node _ children roles => + (∀ i, roles i ≠ 0 → (children i).isOdd) ∧ ∀ i, (children i).valid + +def OccupiedParityTree.noSingleton : {b : ℕ} → OccupiedParityTree b → Prop + | _, .leaf => True + | _, .node _ children roles => + (Odd (signedRoleCount roles) → activeRoleCount roles ≠ 1) ∧ + ∀ i, (children i).noSingleton + +/-- The exact forced binary number of selected leaves, with all extra +occupied vertices present. The hypotheses here are checked properties +of a parity term, not a statistical or construction theorem. -/ +theorem OccupiedParityTree.forced_leaves {b : ℕ} (t : OccupiedParityTree b) + (hv : t.valid) (hn : t.noSingleton) (ho : t.isOdd) : 2^b ≤ t.leafCount := by + induction t with + | leaf => simp [leafCount] + | @node b n children roles ih => + have hod : Odd (signedRoleCount roles) := ho + have hpos := hod.pos + have hle := signedRoleCount_le_active roles + have hne := hn.1 hod + have ha : 2 ≤ activeRoleCount roles := by omega + have hsum : (∑ i : Fin n, if roles i≠0 then 2^b else 0) ≤ + ∑ i : Fin n, (children i).leafCount := by + apply Finset.sum_le_sum + intro i _ + split_ifs with hi + · exact ih i (hv.2 i) (hn.2 i) (hv.1 i hi) + · exact Nat.zero_le _ + have hs : (∑ i : Fin n, if roles i≠0 then 2^b else 0) = activeRoleCount roles * 2^b := by + rw [← Finset.sum_filter] + simp only [Finset.sum_const, smul_eq_mul, activeRoleCount] + rw [hs] at hsum + change 2^(b+1) ≤ _ + rw [pow_succ] + exact (show 2^b*2 ≤ activeRoleCount roles*2^b by + simpa only [Nat.mul_comm] using Nat.mul_le_mul_right (2^b) ha).trans hsum + +end TraceReconstruction + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +attribute [local instance] Classical.propDecidable + +/-- The literal unsigned/signed motif values at one child index. -/ +def IsMotifValue (χ σ : ℝ) : Prop := + (χ=0 ∧ σ=0) ∨ (χ=1 ∧ (σ=1 ∨ σ= -1)) + +def IsTypeSign (τ : ℝ) : Prop := τ=1 ∨ τ= -1 + +theorem motif_child_sign {χ σ τ : ℝ} (hm : IsMotifValue χ σ) (ht : IsTypeSign τ) : + IsTypeSign (1-χ+σ*τ) := by + rcases hm with ⟨rfl,rfl⟩ | ⟨rfl,hσ⟩ + · exact Or.inl (by ring) + · rcases hσ with rfl | rfl <;> rcases ht with rfl | rfl <;> + norm_num [IsTypeSign] + +theorem sign_pow_parity {τ : ℝ} (ht : IsTypeSign τ) (n : ℕ) : + τ^n = if Odd n then τ else 1 := by + rcases ht with rfl | rfl + · simp + · split_ifs with hn + · exact hn.neg_one_pow + · exact (Nat.not_odd_iff_even.mp hn).neg_one_pow + +/-- Product expansion with an arbitrary three-role scalar per child; the +only sign variable is the current vertex type. -/ +theorem arbitrary_role_expansion {n : ℕ} (w : Fin n → Fin 3 → ℝ) (τ : ℝ) : + (∏ i, ∑ a : Fin 3, w i a * (if a=2 then τ else 1)) = + ∑ a : Fin n → Fin 3, (∏ i, w i (a i))*τ^signedRoleCount a := by + rw [Finset.prod_univ_sum] + simp only [Fintype.piFinset_univ,Finset.prod_mul_distrib] + apply Finset.sum_congr rfl + intro a _ + congr 1 + rw [← Finset.prod_filter] + simp [signedRoleCount] + +/-- At the last internal level every selected leaf has to be active. +Role zero has weight zero; unsigned and signed roles are respectively +χ/2 and -σ/2 in (χ-στ)/2. -/ +def bottomRoleWeight (χ σ : ℝ) (a : Fin 3) : ℝ := + if a=0 then 0 else if a=1 then χ/2 else -σ/2 + +def internalRoleWeight (odd : Prop) [Decidable odd] (χ σ : ℝ) (a : Fin 3) : ℝ := + if odd then roleWeight χ σ a else if a=0 then 1 else 0 + +theorem bottomRole_sum (χ σ τ : ℝ) : + (∑ a : Fin 3, bottomRoleWeight χ σ a*(if a=2 then τ else 1)) = (χ-σ*τ)/2 := by + rw [Fin.sum_univ_three] + have h01 : (0:Fin 3) ≠ 1 := by decide + have h02 : (0:Fin 3) ≠ 2 := by decide + have h12 : (1:Fin 3) ≠ 2 := by decide + simp only [bottomRoleWeight,h02,h12,Ne.symm h01,Ne.symm h02,Ne.symm h12, + ↓reduceIte,zero_add,mul_one] + ring + +theorem internalRole_sum (odd : Prop) [Decidable odd] (χ σ τ : ℝ) : + (∑ a : Fin 3, internalRoleWeight odd χ σ a*(if a=2 then τ else 1)) = + if odd then 1-χ+σ*τ else 1 := by + rw [Fin.sum_univ_three] + have h01 : (0:Fin 3) ≠ 1 := by decide + have h02 : (0:Fin 3) ≠ 2 := by decide + have h12 : (1:Fin 3) ≠ 2 := by decide + by_cases h : odd <;> simp only [internalRoleWeight,roleWeight,h,h02,h12, + Ne.symm h01,Ne.symm h02,Ne.symm h12,↓reduceIte,zero_mul,add_zero,mul_one] + ring + +/-- An arbitrary occupied ordered subtree, with motif values at its actual +child labels. Depth zero here means a bottom sibling group, so it already +has one internal level. No binary-shape assumption is made. -/ +inductive CoefficientShape : ℕ → Type + | bottom (n : ℕ) (χ σ : Fin n → ℝ) : CoefficientShape 0 + | node {b : ℕ} (n : ℕ) (χ σ : Fin n → ℝ) + (children : Fin n → CoefficientShape b) : CoefficientShape (b+1) + +namespace CoefficientShape + +def Admissible : {b : ℕ} → CoefficientShape b → Prop + | _, .bottom _ χ σ => ∀ i, IsMotifValue (χ i) (σ i) + | _, .node _ χ σ children => (∀ i, IsMotifValue (χ i) (σ i)) ∧ ∀ i, (children i).Admissible + +def eval : {b : ℕ} → CoefficientShape b → ℝ → ℝ + | _, .bottom _ χ σ, τ => ∏ i, (χ i-σ i*τ)/2 + | _, .node _ χ σ children, τ => ∏ i, (children i).eval (1-χ i+σ i*τ) + +def Choice : {b : ℕ} → CoefficientShape b → Type + | _, .bottom n _ _ => Fin n → Fin 3 + | _, .node n _ _ children => ((i : Fin n) → (children i).Choice) × (Fin n → Fin 3) + +noncomputable instance choiceFintype : {b : ℕ} → (t : CoefficientShape b) → Fintype t.Choice + | _, .bottom _ _ _ => by unfold Choice; infer_instance + | _, .node _ _ _ children => by + letI := fun i => choiceFintype (children i) + unfold Choice + infer_instance + +def termTree : {b : ℕ} → (t : CoefficientShape b) → t.Choice → OccupiedParityTree (b+1) + | _, .bottom n _ _, a => .node n (fun _ => .leaf) a + | _, .node n _ _ children, a => .node n (fun i => (children i).termTree (a.1 i)) a.2 + +noncomputable def weight : {b : ℕ} → (t : CoefficientShape b) → t.Choice → ℝ + | _, .bottom _ χ σ, a => ∏ i, bottomRoleWeight (χ i) (σ i) (a i) + | _, .node _ χ σ children, a => ∏ i, + (children i).weight (a.1 i) * + @internalRoleWeight ((children i).termTree (a.1 i)).isOdd (Classical.propDecidable _) + (χ i) (σ i) (a.2 i) + +/-- Full finite coefficient expansion, before any orientation average or +fit-event conditioning. This is the literal algebra behind source +the correlated-anchor estimate, the parity roles being retained in every term. -/ +theorem expansion {b : ℕ} (t : CoefficientShape b) (ha : t.Admissible) + {τ : ℝ} (ht : IsTypeSign τ) : + t.eval τ = ∑ a : t.Choice, t.weight a * (if (t.termTree a).isOdd then τ else 1) := by + classical + induction t generalizing τ with + | bottom n χ σ => + have H := arbitrary_role_expansion (fun i => bottomRoleWeight (χ i) (σ i)) τ + simp_rw [bottomRole_sum,sign_pow_parity ht] at H + trans ∑ a : Fin n → Fin 3, (∏ i, bottomRoleWeight (χ i) (σ i) (a i)) * + (if Odd (signedRoleCount a) then τ else 1) + · exact H + · apply Finset.sum_congr rfl + intro a _ + apply congrArg (fun z => (∏ i, bottomRoleWeight (χ i) (σ i) (a i))*z) + change _ = @ite ℝ (Odd (signedRoleCount a)) (Classical.propDecidable _) τ 1 + split_ifs <;> rfl + | @node b n χ σ children ih => + change (∏ i, (children i).eval (1-χ i+σ i*τ)) = _ + have he (i : Fin n) := ih i (ha.2 i) (motif_child_sign (ha.1 i) ht) + simp_rw [he] + rw [Finset.prod_univ_sum] + simp only [Fintype.piFinset_univ] + change (∑ a : (i : Fin n) → (children i).Choice, + ∏ i, (children i).weight (a i)* + (if ((children i).termTree (a i)).isOdd then 1-χ i+σ i*τ else 1)) = + ∑ a : ((i : Fin n) → (children i).Choice) × (Fin n → Fin 3), + (∏ i, (children i).weight (a.1 i)* + internalRoleWeight ((children i).termTree (a.1 i)).isOdd (χ i) (σ i) (a.2 i))* + (@ite ℝ (Odd (signedRoleCount a.2)) (Classical.propDecidable _) τ 1) + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + have H := arbitrary_role_expansion (fun i => + internalRoleWeight ((children i).termTree (a i)).isOdd (χ i) (σ i)) τ + simp_rw [internalRole_sum,sign_pow_parity ht] at H + rw [Finset.prod_mul_distrib,H,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a' _ + rw [Finset.prod_mul_distrib,mul_assoc] + congr 2 + split_ifs <;> rfl + +/-- Nonzero terms automatically satisfy the source active-odd rule. -/ +theorem term_valid {b : ℕ} (t : CoefficientShape b) (a : t.Choice) + (h : t.weight a ≠ 0) : (t.termTree a).valid := by + classical + induction t with + | bottom n χ σ => exact ⟨fun _ _ => trivial,fun _ => trivial⟩ + | @node b n χ σ children ih => + have hp (i : Fin n) : (children i).weight (a.1 i) * + internalRoleWeight ((children i).termTree (a.1 i)).isOdd (χ i) (σ i) (a.2 i) ≠ 0 := + (Finset.prod_ne_zero_iff.mp h) i (Finset.mem_univ i) + constructor + · intro i hai + by_contra hn + have hz := (mul_ne_zero_iff.mp (hp i)).2 + simp [internalRoleWeight,hn,hai] at hz + · intro i + exact ih i (a.1 i) (mul_ne_zero_iff.mp (hp i)).1 + +/-- The difference of hypotheses consists exactly of odd root terms. -/ +theorem difference_expansion {b : ℕ} (t : CoefficientShape b) (ha : t.Admissible) : + t.eval 1-t.eval (-1) = 2*∑ a : t.Choice, + if (t.termTree a).isOdd then t.weight a else 0 := by + classical + rw [expansion t ha (Or.inl rfl),expansion t ha (Or.inr rfl), + ← Finset.sum_sub_distrib,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> ring + +/-- A nonzero surviving term without a singleton odd vertex has the full +forced binary number of leaves. This follows from the actual expansion, +not an assumed parity interface. -/ +theorem surviving_leaves {b : ℕ} (t : CoefficientShape b) (a : t.Choice) + (hw : t.weight a ≠ 0) (ho : (t.termTree a).isOdd) + (hn : (t.termTree a).noSingleton) : 2^(b+1) ≤ (t.termTree a).leafCount := + (t.termTree a).forced_leaves (t.term_valid a hw) hn ho + +end CoefficientShape +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +namespace OccupiedParityTree + +/-- The actual binary selection sits inside an arbitrary occupied parity +term, retaining its unselected children rather than assuming binary input. -/ +inductive Forced : {b : ℕ} → OccupiedParityTree b → Type + | leaf : Forced .leaf + | node {b n : ℕ} {children : Fin n → OccupiedParityTree b} {roles : Fin n → Fin 3} + (a c : Fin n) (hne : a≠c) (ha : roles a≠0) (hc : roles c≠0) + (left : Forced (children a)) (right : Forced (children c)) : + Forced (.node n children roles) + +/-- Every surviving nonsingleton term has an embedded binary subtree. +The selection depends only on the role-marked shape. -/ +theorem forced_nonempty {b : ℕ} (t : OccupiedParityTree b) + (hv : t.valid) (hn : t.noSingleton) (ho : t.isOdd) : Nonempty t.Forced := by + classical + induction t with + | leaf => exact ⟨.leaf⟩ + | @node b n children roles ih => + have hod : Odd (signedRoleCount roles) := ho + have ha : 2 ≤ activeRoleCount roles := by + have := signedRoleCount_le_active roles + have := hod.pos + have := hn.1 hod + omega + obtain ⟨a,ha,c,hc,hne⟩ := Finset.one_lt_card.mp ha + have ha' : roles a≠0 := (Finset.mem_filter.mp ha).2 + have hc' : roles c≠0 := (Finset.mem_filter.mp hc).2 + obtain ⟨la⟩ := ih a (hv.2 a) (hn.2 a) (hv.1 a ha') + obtain ⟨lc⟩ := ih c (hv.2 c) (hn.2 c) (hv.1 c hc') + exact ⟨.node a c hne ha' hc' la lc⟩ + +/-- Occupied shapes have at least one selected leaf below every vertex. -/ +def occupied : {b : ℕ} → OccupiedParityTree b → Prop + | _, .leaf => True + | _, .node n children _ => 0 1 + | _, .leaf, _+1 => 0 + | _, .node _ children _, k+1 => ∑ i, (children i).levelCount k + +theorem leafCount_pos {b : ℕ} (t : OccupiedParityTree b) (ht : t.occupied) : + 0 exact Nat.zero_lt_one + | @node b n children roles ih => + let i : Fin n := ⟨0,ht.1⟩ + have hp := ih i (ht.2 i) + change 0 < ∑ k, (children k).leafCount + exact hp.trans_le (Finset.single_le_sum (fun k _ => Nat.zero_le ((children k).leafCount)) (Finset.mem_univ i)) + +theorem levelCount_le_leaves {b : ℕ} (t : OccupiedParityTree b) (ht : t.occupied) + (k : ℕ) : t.levelCount k ≤ t.leafCount := by + induction t generalizing k with + | leaf => cases k <;> norm_num [levelCount,leafCount] + | @node b n children roles ih => + cases k with + | zero => exact leafCount_pos (.node n children roles) ht + | succ k => exact Finset.sum_le_sum (fun i _ => ih i (ht.2 i) k) + +/-- Two chosen coordinates supply an additive gain in a finite sum. -/ +theorem sum_two_improvements {ι : Type*} [Fintype ι] [DecidableEq ι] + (x y : ι → ℕ) {a c : ι} (hne : a≠c) (A B : ℕ) + (hrest : ∀ i, i≠a → i≠c → x i≤y i) + (ha : x a+A≤y a+B) (hc : x c+A≤y c+B) : + (∑ i, x i)+2*A ≤ (∑ i, y i)+2*B := by + have hc' : c∈Finset.univ.erase a := by simp [hne.symm] + have hx1 := Finset.sum_erase_add Finset.univ x (Finset.mem_univ a) + have hy1 := Finset.sum_erase_add Finset.univ y (Finset.mem_univ a) + have hx2 := Finset.sum_erase_add (Finset.univ.erase a) x hc' + have hy2 := Finset.sum_erase_add (Finset.univ.erase a) y hc' + have hrem : (∑ i∈(Finset.univ.erase a).erase c, x i) ≤ + ∑ i∈(Finset.univ.erase a).erase c, y i := by + apply Finset.sum_le_sum + intro i hi + exact hrest i (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 + (Finset.mem_erase.mp hi).1 + omega + +theorem Forced.leaf_lower {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + 2^b ≤ t.leafCount := by + classical + induction F with + | leaf => simp [leafCount] + | @node b n children roles a c hne ha hc left right ihl ihr => + have hh := sum_two_improvements (fun _ : Fin n => 0) + (fun i => (children i).leafCount) hne (2^b) 0 + (fun _ _ _ => Nat.zero_le _) (by simpa using ihl) (by simpa using ihr) + simpa only [Finset.sum_const_zero,zero_add,add_zero,zero_mul,pow_succ,Nat.mul_comm,leafCount] using hh + +/-- At every positive nonroot level, each unforced occupied vertex costs + an extra leaf. This is the exact combinatorial inequality used when + additional (nonbinary) labels are summed in the correlated-anchor estimate. -/ +theorem Forced.level_extra {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (ht : t.occupied) (k : ℕ) : + t.levelCount k+2^b ≤ t.leafCount+2^k := by + classical + induction F generalizing k with + | leaf => cases k <;> simp [levelCount,leafCount] + | @node b n children roles a c hne ha hc left right ihl ihr => + cases k with + | zero => + have hl := (Forced.node a c hne ha hc left right).leaf_lower + simpa only [levelCount,pow_zero,Nat.add_comm] using Nat.add_le_add_left hl 1 + | succ k => + have hh := sum_two_improvements + (fun i => (children i).levelCount k) (fun i => (children i).leafCount) + hne (2^b) (2^k) (fun i _ _ => levelCount_le_leaves _ (ht.2 i) k) + (ihl (ht.2 a) k) (ihr (ht.2 c) k) + simpa only [levelCount,leafCount,pow_succ,Nat.mul_comm] using hh + +theorem Forced.nonforced_vertices_le_extra_leaves {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (ht : t.occupied) (k : ℕ) : + t.levelCount k-2^k ≤ t.leafCount-2^b := by + have := F.level_extra ht k + have := F.leaf_lower + omega + +end OccupiedParityTree +end TraceReconstruction + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Patterns.lean b/lean/OAI/Probability/TraceReconstruction/Patterns.lean index 035ecec5c5edf09cf2fd951180badae9903eecde..95cf0a4dc37cf945734e5d8af638a1703bc1a2bb 100644 --- a/lean/OAI/Probability/TraceReconstruction/Patterns.lean +++ b/lean/OAI/Probability/TraceReconstruction/Patterns.lean @@ -1,735 +1,735 @@ -import OAI.Probability.TraceReconstruction.Differences -import OAI.Probability.TraceReconstruction.InitialDensity - -namespace OAI - -/-! -# Patterns - -Pattern serialization, motif norms, flag posteriors, signed rank coefficients, translated binomials, and support geometry. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem seriesL2Sq_partial {α : Type*} [Fintype α] (f : IntSeries) - (j : α → ℤ) (hj : Function.Injective j) : - (∑ a, f.coeff (j a)^2) ≤ seriesL2Sq f := by - classical - let A := Finset.univ.image j - have he : (∑ a, f.coeff (j a)^2)=∑ z∈A, f.coeff z^2 := by - rw [Finset.sum_image] - exact fun _ _ _ _ h => hj h - rw [he] - calc - _ ≤ ∑ z∈f.coeff.support ∪ A, f.coeff z^2 := - Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_right (fun _ _ _ => sq_nonneg _) - _ = _ := by - rw [seriesL2Sq_eq_sum] - symm - apply Finset.sum_subset Finset.subset_union_left - intro z _ hz - simp [Finsupp.notMem_support_iff.mp hz] - -/-- The cancellation estimate after disjoint rank clipping, retaining the - actual fixed-period kernels and all anchor correlations. -/ -theorem period_pattern_norm {u m l r : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (hsafe : ∀ j : IncreasingTuple u r, SafeTaggedTuple (periodSlot off ∘ j.val)) - (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) - (hhalf : 1/2 ≤ θ) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (a : Fin r) (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) - (hA : ∀ j, A j^2 ≤ w (j.val a)^2) - (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) : - (∑ v, (∑ j, if PeriodRankRegion m θ j v then - A j*positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v else 0)^2) ≤ - periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - periodCentralSumConstant u r * ∑ h, w h^2 := by - have hC : 0 ≤ periodDifferencePrefactor u m r (∑ h, (k h).order) θ := by - unfold periodDifferencePrefactor lengthDifferenceConstant - positivity - calc - _ ≤ ∑ j, A j^2*∑ v, positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v^2 := - period_clipped_square_sum (by omega) hhalf _ A - _ ≤ ∑ j, A j^2*(periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) := by - apply Finset.sum_le_sum - intro j _ - exact mul_le_mul_of_nonneg_left - (period_positionalRankDifference_bound hm hr hl off hoff hdiff j (hsafe j) k hθ hmean hv) - (sq_nonneg _) - _ = periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - ∑ j, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by - rw [Finset.mul_sum]; congr 1; funext j; ring - _ ≤ _ := by - rw [mul_assoc] - exact mul_le_mul_of_nonneg_left (weighted_period_gap_sum a A w hA hw) hC - -theorem period_pattern_bounded_norm {u m l r M : ℕ} - (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) - (off : Fin u → Fin m) - (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) - (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) - (hsafe : ∀ j : IncreasingTuple u r, SafeTaggedTuple (periodSlot off ∘ j.val)) - (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) - (hhalf : 1/2 ≤ θ) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) - (a : Fin r) (c : Fin (r+1)) (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) - (hA : ∀ j, A j^2 ≤ w (j.val a)^2) - (hsupport : ∀ j, A j ≠ 0 → coarsePeriodGap j.val c ≤ M) - (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) - (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : - (∑ v, (∑ j, if PeriodRankRegion m θ j v then - A j*positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v else 0)^2) ≤ - periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - periodBoundedSumConstant u r M * ∑ h, w h^2 := by - have hC : 0 ≤ periodDifferencePrefactor u m r (∑ h, (k h).order) θ := by - unfold periodDifferencePrefactor lengthDifferenceConstant - positivity - calc - _ ≤ ∑ j, A j^2*∑ v, positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v^2 := - period_clipped_square_sum (by omega) hhalf _ A - _ ≤ ∑ j, A j^2*(periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) := by - apply Finset.sum_le_sum - intro j _ - exact mul_le_mul_of_nonneg_left - (period_positionalRankDifference_bound hm hr hl off hoff hdiff j (hsafe j) k hθ hmean hv) - (sq_nonneg _) - _ = periodDifferencePrefactor u m r (∑ h, (k h).order) θ * - ∑ j, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by - rw [Finset.mul_sum]; congr 1; funext j; ring - _ ≤ _ := by - rw [mul_assoc] - exact mul_le_mul_of_nonneg_left (weighted_period_bounded_gap_sum a c A w hA hsupport hw hM) hC - -/-- Two involved motif positions force a short *fixed* internal coarse gap. - The chosen gap is independent of the actual labels and of the offset law. -/ -theorem motif_pattern_bounded_gap {u r : ℕ} (π : IntSeries) (s : ℕ) - (j : IncreasingTuple u (r+1)) (k : Fin (r+1) → GapDifference) - (i : Fin r) (b : Fin (r+1)) (hib : i.castSucc < b) - (hi : k i.castSucc ≠ .unchanged) (hb : k b ≠ .unchanged) - (hA : motifPatternMultiplier π s (fun a => (j.val a).val) k ≠ 0) : - coarsePeriodGap j.val i.castSucc.succ ≤ 2*(2^s) := by - have hs := motif_multiplier_bounded_separation π s (fun a => (j.val a).val) k hA i.castSucc b hi hb - have hj1 := j.property (show i.castSucc < i.succ by exact Fin.castSucc_lt_succ) - have hj2 := j.property.monotone (show i.succ ≤ b by simpa only [Fin.le_iff_val_le_val,Fin.lt_def, - Fin.val_succ,Fin.val_castSucc] using (Nat.succ_le_of_lt hib)) - have h1 : (j.val i.castSucc).val < (j.val i.succ).val := hj1 - have h2 : (j.val i.succ).val ≤ (j.val b).val := hj2 - have hh := (abs_lt.mp hs).1 - rw [coarsePeriodGap_middle] - omega - -end TraceReconstruction - - -namespace TraceReconstruction - -theorem centered_window_floor_fit (P T L t : ℕ) (Y : ℤ) - (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) - (hL : 8*L ≤ T) (hY : |8*Y| ≤ (T:ℤ)) - (ht : (t:ℤ)=(((P-T)/2:ℕ):ℤ)+Y) : - t+T ≤ P ∧ t ≤ P/2 ∧ P/2+L ≤ t+T := by - obtain ⟨k,hk⟩ := heven - have hy := abs_le.mp hY - omega - -theorem centered_window_floor_anchor (P T : ℕ) (hTP : T ≤ P) (heven : Even T) : - P/2-(P-T)/2=T/2 := by - obtain ⟨k,hk⟩ := heven - omega - -theorem atomString_append (n m : ℕ) (w : Bool → List Bool) (θ : Fin (n+m) → Bool) : - atomString (n+m) w θ = - atomString n w (fun i => θ (i.castLE (Nat.le_add_right n m))) ++ - atomString m w (fun i => θ (i.natAdd n)) := by - simp only [atomString,List.ofFn_add,List.flatten_append] - -theorem atomString_three (n m k : ℕ) (w : Bool → List Bool) (θ : Fin (n+m+k) → Bool) : - atomString (n+m+k) w θ = - atomString n w (fun i => θ ⟨i.val,by omega⟩) ++ - atomString m w (fun i => θ ⟨n+i.val,by omega⟩) ++ - atomString k w (fun i => θ ⟨n+m+i.val,by omega⟩) := by - rw [atomString_append,atomString_append] - rfl - -/-- A full deterministic template equals a pure prefix, the actual translated - window, and a pure suffix. This equality is in unmarked binary strings. -/ -theorem template_word_window (t T z a L : ℕ) (sign : Fin L → Bool) (τ : Bool) - (w : Bool → List Bool) (hleft : t ≤ a) (hright : a+L ≤ t+T) : - atomString (t+T+z) w (templateType (t+T+z) a L sign τ) = - atomString t w (fun _ => false) ++ - atomString T w (templateType T (a-t) L sign τ) ++ - atomString z w (fun _ => false) := by - rw [atomString_three] - congr 2 - · congr 1 - funext i - exact templateType_outside_window sign τ hleft hright ⟨i.val,by omega⟩ (Or.inl i.isLt) - · congr 1 - funext i - exact templateType_inside_window sign τ (by omega) hleft i - · funext i - exact templateType_outside_window sign τ hleft hright ⟨t+T+i.val,by omega⟩ (Or.inr (by dsimp; omega)) - -def pureAtomRun (w : List Bool) (n : ℕ) : List Bool := - (List.replicate n w).flatten - -theorem atomString_constant (n : ℕ) (w : Bool → List Bool) (b : Bool) : - atomString n w (fun _ => b)=pureAtomRun (w b) n := by - simp [atomString,pureAtomRun] - -theorem pureAtomRun_add (w : List Bool) (n m : ℕ) : - pureAtomRun w (n+m)=pureAtomRun w n ++ pureAtomRun w m := by - simp only [pureAtomRun,List.replicate_add,List.flatten_append] - -/-- Splitting or regrouping a pure region into reported chunks changes no - unmarked string. In particular arbitrary fixed chunk IDs are harmless. -/ -theorem pureAtomRun_partition (w : List Bool) (ns : List ℕ) : - (ns.map (pureAtomRun w)).flatten=pureAtomRun w ns.sum := by - induction ns with - | nil => simp [pureAtomRun] - | cons n ns ih => simp [ih,pureAtomRun_add] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction.FiniteLaw -open scoped Classical -variable {α : Type*} [Fintype α] - -/-- Exact orientation law after a report: only invisible bits remain random. -/ -def flagPosterior (d : Option Bool) : FiniteLaw Bool where - mass b := match d with - | none => 1/2 - | some c => if b=c then 1 else 0 - nonneg := by - intro b - cases d with - | none => norm_num - | some c => dsimp; split_ifs <;> norm_num - total := by cases d with - | none => norm_num [Fintype.sum_bool] - | some c => simp - -def pairedReportMass (P Q H : FiniteLaw α) (ω : ℝ) - (z : Option Bool × (α × α)) : ℝ := - ∑ b : Bool, (1/2 : ℝ)*pairedFlagMass P Q H ω b z - -/-- Pointwise Bayes factorization, valid even at zero probability reports. -/ -theorem pairedFlag_bayes (P Q H : FiniteLaw α) (ω : ℝ) - (z : Option Bool × (α × α)) (b : Bool) : - (1/2 : ℝ)*pairedFlagMass P Q H ω b z = - pairedReportMass P Q H ω z * (flagPosterior z.1).mass b := by - rcases z with ⟨d,z⟩ - cases d with - | none => simp [pairedReportMass,pairedFlagMass,flagPosterior]; ring - | some c => cases b <;> cases c <;> - simp [pairedReportMass,pairedFlagMass,flagPosterior] - -theorem pairedReportMass_nonneg (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) - (z : Option Bool × (α × α)) : 0 ≤ pairedReportMass P Q H ω z := by - apply Finset.sum_nonneg - intro b _ - exact mul_nonneg (by norm_num) (pairedFlagMass_nonneg P Q H hω hP hQ b z) - -theorem pairedReportMass_total (P Q H : FiniteLaw α) (ω : ℝ) : - (∑ z, pairedReportMass P Q H ω z)=1 := by - unfold pairedReportMass - rw [Finset.sum_comm] - simp_rw [← Finset.mul_sum,pairedFlagMass_sum] - norm_num [Fintype.sum_bool] - -def pairedReport (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) - (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) : - FiniteLaw (Option Bool × (α × α)) := - ⟨pairedReportMass P Q H ω, pairedReportMass_nonneg P Q H hω hP hQ, - pairedReportMass_total P Q H ω⟩ - -/-- Conditioning solely on exact reports does not correlate mechanisms. - This is the actual joint-mass factorization, not an independence hypothesis. -/ -theorem pairedFlags_product_bayes {ι : Type*} [Fintype ι] - (P Q H : ι → FiniteLaw α) (ω : ι → ℝ) - (z : ι → Option Bool × (α × α)) (b : ι → Bool) : - (∏ i, (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) (b i) (z i)) = - (∏ i, pairedReportMass (P i) (Q i) (H i) (ω i) (z i)) * - ∏ i, (flagPosterior (z i).1).mass (b i) := by - simp_rw [pairedFlag_bayes] - exact Finset.prod_mul_distrib - -theorem pairedFlags_report_marginal {ι : Type*} [Fintype ι] - (P Q H : ι → FiniteLaw α) (ω : ι → ℝ) - (z : ι → Option Bool × (α × α)) : - (∑ b : ι → Bool, ∏ i, (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) (b i) (z i)) = - ∏ i, pairedReportMass (P i) (Q i) (H i) (ω i) (z i) := by - exact (Fintype.prod_sum (fun i b => (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) b (z i))).symm - -end TraceReconstruction.FiniteLaw - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def bitIndex (b : Bool) : ℕ := if b then 1 else 0 - -def posteriorBitSeries (d : Option Bool) : IntSeries := - ∑ b : Bool, AddMonoidAlgebra.single (bitIndex b : ℤ) ((FiniteLaw.flagPosterior d).mass b) - -def visibleOnes (d : Option Bool) : ℕ := if d=some true then 1 else 0 - -def hiddenTrial (d : Option Bool) : ℕ := if d=none then 1 else 0 - -theorem posteriorBitSeries_factor (d : Option Bool) : - posteriorBitSeries d = AddMonoidAlgebra.single (visibleOnes d : ℤ) 1 * fairSeries (hiddenTrial d) := by - cases d with - | none => simp [posteriorBitSeries,FiniteLaw.flagPosterior,bitIndex,visibleOnes,hiddenTrial,fairSeries, - add_comm] - | some b => cases b <;> simp [posteriorBitSeries,FiniteLaw.flagPosterior,bitIndex,visibleOnes,hiddenTrial, - fairSeries] - -/-- The count distribution of the literal posterior orientation bits is - a translated fair binomial, including reports of probability zero. -/ -theorem posterior_count_series {ι : Type*} [Fintype ι] (d : ι → Option Bool) : - (∑ b : ι → Bool, AddMonoidAlgebra.single (∑ i, (bitIndex (b i):ℤ)) - (∏ i, (FiniteLaw.flagPosterior (d i)).mass (b i))) = - AddMonoidAlgebra.single (∑ i, (visibleOnes (d i):ℤ)) 1 * - fairSeries (∑ i, hiddenTrial (d i)) := by - have he : (∑ b : ι → Bool, AddMonoidAlgebra.single (∑ i, (bitIndex (b i):ℤ)) - (∏ i, (FiniteLaw.flagPosterior (d i)).mass (b i))) = ∏ i, posteriorBitSeries (d i) := by - rw [show (∏ i, posteriorBitSeries (d i)) = - ∏ i, ∑ b : Bool, AddMonoidAlgebra.single (bitIndex b : ℤ) ((FiniteLaw.flagPosterior (d i)).mass b) from rfl] - rw [Fintype.prod_sum] - apply Finset.sum_congr rfl - intro b _ - rw [AddMonoidAlgebra.prod_single] - rw [he] - simp_rw [posteriorBitSeries_factor] - rw [Finset.prod_mul_distrib,AddMonoidAlgebra.prod_single] - simp only [Finset.prod_const_one] - congr 1 - unfold fairSeries - exact Finset.prod_pow_eq_pow_sum _ _ _ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem geomSeries_coeff (k : ℕ) (z : ℤ) : - (geomSeries k).coeff z = if 0 ≤ z ∧ z < k then 1 else 0 := by - unfold geomSeries - simp only [AddMonoidAlgebra.single_pow,one_pow,nsmul_eq_mul,mul_one, - AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply,AddMonoidAlgebra.coeff_single,Finsupp.single_apply] - by_cases hz : 0 ≤ z ∧ z < k - · obtain ⟨a,rfl⟩ := Int.eq_ofNat_of_zero_le hz.1 - rw [ite_eq_left hz,Finset.sum_eq_single a] - · simp - · intro b _ hb - exact ite_eq_right (by exact_mod_cast hb) - · intro ha - have ha' : a < k := by exact_mod_cast hz.2 - exact (ha (Finset.mem_range.mpr ha')).elim - · rw [ite_eq_right hz] - apply Finset.sum_eq_zero - intro a ha - apply ite_eq_right - intro haz - subst z - exact hz ⟨by positivity,by exact_mod_cast Finset.mem_range.mp ha⟩ - -theorem motif_unsigned_convolution (π : IntSeries) (s : ℕ) (z : ℤ) : - (∑ X ∈ π.coeff.support, π.coeff X*motifIndicator s (z-X)) = - (geomSeries (2^s)*π).coeff z := by - rw [mul_comm,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] - apply Finset.sum_congr rfl - intro X _ - rw [geomSeries_coeff] - simp only [motifIndicator,sub_eq_neg_add] - -theorem motifPatternMultiplier_sq_le {r : ℕ} (π : IntSeries) - (hπ : ∀ X, 0 ≤ π.coeff X) (s : ℕ) (j : Fin r → ℤ) - (k : Fin r → GapDifference) (h : Fin r) (hk : k h ≠ .unchanged) : - (motifPatternMultiplier π s j k)^2 ≤ ((geomSeries (2^s)*π).coeff (j h))^2 := by - have ha := motifPatternMultiplier_abs_le π hπ s j k h hk - rw [motif_unsigned_convolution] at ha - have hh := pow_le_pow_left₀ (abs_nonneg (motifPatternMultiplier π s j k)) ha 2 - simpa only [sq_abs] using hh - -theorem unsigned_motif_energy (π : IntSeries) (s : ℕ) : - seriesL2Sq (geomSeries (2^s)*π) ≤ ((2:ℝ)^s)^2 * seriesL2Sq π := by - refine (seriesL2Sq_mul_le _ _).trans ?_ - apply mul_le_mul_of_nonneg_right _ (seriesL2Sq_nonneg _) - exact pow_le_pow_left₀ (seriesL1_nonneg _) (by simpa using geomSeries_L1_le (2^s)) 2 - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction - -/-- Elementary chi-square upper bound on the Bernoulli relative entropy. - No Stirling estimate is used in the subsequent count overlap. -/ -theorem bernoulli_entropy_upper {t p : ℝ} (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : - t*Real.log (t/p)+(1-t)*Real.log ((1-t)/(1-p)) ≤ - (t-p)^2/(p*(1-p)) := by - have h1 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos (div_pos ht.1 hp.1)) ht.1.le - have h2 := mul_le_mul_of_nonneg_left - (Real.log_le_sub_one_of_pos (div_pos (sub_pos.mpr ht.2) (sub_pos.mpr hp.2))) - (sub_nonneg.mpr ht.2.le) - have hid : t*(t/p-1)+(1-t)*((1-t)/(1-p)-1)=(t-p)^2/(p*(1-p)) := by - field_simp [hp.1.ne', (sub_pos.mpr hp.2).ne'] - ring - linarith - -/-- Exact likelihood change from the mean-matched Bernoulli law. -/ -theorem binomialMass_likelihood (n l : ℕ) {t p : ℝ} - (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : - binomialMass n p l = binomialMass n t l * - Real.exp (-((l:ℝ)*Real.log (t/p)+((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p)))) := by - have h1 : Real.exp (-((l:ℝ)*Real.log (t/p)))=(p/t)^l := by - rw [show -((l:ℝ)*Real.log (t/p))=(l:ℝ)*Real.log (p/t) by - rw [Real.log_div ht.1.ne' hp.1.ne',Real.log_div hp.1.ne' ht.1.ne']; ring, - Real.exp_nat_mul,Real.exp_log (div_pos hp.1 ht.1)] - have h2 : Real.exp (-(((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p))))=((1-p)/(1-t))^(n-l) := by - rw [show -(((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p)))= - ((n-l:ℕ):ℝ)*Real.log ((1-p)/(1-t)) by - rw [Real.log_div (sub_pos.mpr ht.2).ne' (sub_pos.mpr hp.2).ne', - Real.log_div (sub_pos.mpr hp.2).ne' (sub_pos.mpr ht.2).ne']; ring, - Real.exp_nat_mul,Real.exp_log (div_pos (sub_pos.mpr hp.2) (sub_pos.mpr ht.2))] - rw [neg_add,Real.exp_add,h1,h2] - unfold binomialMass - rw [div_pow,div_pow] - field_simp [ht.1.ne', (sub_pos.mpr ht.2).ne'] - -/-- Pointwise lower mass at every interior integer, with mean-matched - variance at least one. It applies uniformly even as deletion vanishes. -/ -theorem binomialMass_near_mean_lower (n l : ℕ) {t p : ℝ} - (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) - (hl : l ≤ n) (hmean : (n:ℝ)*t=l) (hv : 1 ≤ (n:ℝ)*t*(1-t)) : - Real.exp (-((l:ℝ)-(n:ℝ)*p)^2/((n:ℝ)*p*(1-p))) / - (12*Real.sqrt ((n:ℝ)*t*(1-t))) ≤ binomialMass n p l := by - have hn : (0:ℝ) off))) - (s : ℕ) (X : ℤ) (τ : ℝ) : Fin u → Fin (u*m) := - shiftedTag (periodSlot (fun _ => off)) hsafe - (fun j => motifShift (motifIndicator s ((j.val:ℤ)-X)) ((prouhetSeries s).coeff ((j.val:ℤ)-X)) τ) - -theorem signedPeriodDefects_strictMono {u m : ℕ} (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (s : ℕ) (X : ℤ) (τ : ℝ) : StrictMono (signedPeriodDefects off hsafe s X τ) := - shiftedTag_strictMono _ _ _ - -theorem SafeTaggedTuple.comp {n u r : ℕ} {p : Fin u → Fin n} - (hp : SafeTaggedTuple p) (j : Fin r → Fin u) (hj : StrictMono j) : - SafeTaggedTuple (p ∘ j) := - ⟨fun i => hp.1 (j i),fun i k hik => hp.2 (j i) (j k) (hj hik)⟩ - -theorem shiftedTag_comp {n u r : ℕ} (p : Fin u → Fin n) (hp : SafeTaggedTuple p) - (a : Fin u → Fin 3) (j : Fin r → Fin u) (hj : StrictMono j) : - shiftedTag p hp a ∘ j = shiftedTag (p ∘ j) (hp.comp j hj) (a ∘ j) := by - funext i - apply Fin.ext - rfl - -/-- Exact degree-r coefficient difference of the actual randomized motif - in the marked central run, prior to any rank clipping. -/ -def signedRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : ℝ := - ∑ X ∈ π.coeff.support, π.coeff X * - (rankDefectCoefficient hl (signedPeriodDefects off hsafe s X 1) v - - rankDefectCoefficient hl (signedPeriodDefects off hsafe s X (-1)) v) - -theorem signedRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) - (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) - (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : - signedRankCoefficient hl off hsafe π s v = - ∑ k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then - 2*∑ j : IncreasingTuple u r, - motifPatternMultiplier π s (fun i => (j.val i).val) k * - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v else 0 := by - unfold signedRankCoefficient - simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), - ← Finset.sum_sub_distrib,Finset.mul_sum] - rw [Finset.sum_comm] - have he (j : IncreasingTuple u r) : - (∑ X ∈ π.coeff.support, π.coeff X * - (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - - subsetRankKernel hl (signedPeriodDefects off hsafe s X (-1) ∘ j.val) v.val)) = - ∑ k : Fin r → GapDifference, - (if Odd (firstDifferenceCount k) then 2*motifPatternMultiplier π s (fun i => (j.val i).val) k else 0)* - positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) - (hsafe.comp j.val j.property) k v := by - have htag (X : ℤ) (τ : ℝ) : - signedPeriodDefects off hsafe s X τ ∘ j.val = - shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) - (fun i => motifShift (motifIndicator s ((j.val i).val-X)) - ((prouhetSeries s).coeff ((j.val i).val-X)) τ) := by - funext i; apply Fin.ext; rfl - simp_rw [htag] - simpa only [positionalRankDifference] - using mixed_signed_shift_expansion π s (fun i => (j.val i).val) - (fun a => subsetRankKernel hl - (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) - simp_rw [he] - rw [Finset.sum_comm] - apply Finset.sum_congr rfl - intro k _ - split_ifs with hk - · apply Finset.sum_congr rfl - intro j _; ring - · simp only [zero_mul,Finset.sum_const_zero] - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def translateSeries (c : ℤ) (f : IntSeries) : IntSeries := - AddMonoidAlgebra.single c 1*f - -theorem translateSeries_coeff (c : ℤ) (f : IntSeries) (z : ℤ) : - (translateSeries c f).coeff z = f.coeff (z-c) := by - rw [translateSeries,AddMonoidAlgebra.coeff_single_mul_apply,one_mul] - congr 1; omega - -theorem translateSeries_L2Sq (c : ℤ) (f : IntSeries) : - seriesL2Sq (translateSeries c f)=seriesL2Sq f := by - unfold seriesL2Sq - simp_rw [translateSeries_coeff] - exact (Equiv.subRight c).tsum_eq (fun z => f.coeff z^2) - -theorem translateSeries_L1 (c : ℤ) (f : IntSeries) : - seriesL1 (translateSeries c f)=seriesL1 f := by - unfold seriesL1 - simp_rw [translateSeries_coeff] - exact (Equiv.subRight c).tsum_eq (fun z => |f.coeff z|) - -theorem mul_translateSeries (c : ℤ) (f g : IntSeries) : - f*translateSeries c g=translateSeries c (f*g) := by - unfold translateSeries - ring - -theorem fairSeries_support (g : ℕ) (z : ℤ) (hz : (fairSeries g).coeff z ≠ 0) : - 0≤z ∧ z≤g := by - have h0 : 0≤z := by - by_contra h - exact hz (fairSeries_coeff_neg g z (by omega)) - obtain ⟨k,rfl⟩ := Int.eq_ofNat_of_zero_le h0 - refine ⟨by positivity,?_⟩ - by_contra hk - rw [fairSeries_coeff_nat,fairBinomial,Nat.choose_eq_zero_of_lt (by omega)] at hz - simp at hz - -theorem fairSeries_reflect (g : ℕ) (z : ℤ) : - (fairSeries g).coeff ((g:ℤ)-z)=(fairSeries g).coeff z := by - by_cases hz : 0≤z ∧ z≤g - · obtain ⟨k,rfl⟩ := Int.eq_ofNat_of_zero_le hz.1 - have hk : k≤g := by exact_mod_cast hz.2 - rw [← Nat.cast_sub hk,fairSeries_coeff_nat,fairSeries_coeff_nat] - simp only [fairBinomial,Nat.choose_symm hk] - · have h1 : (fairSeries g).coeff z=0 := by - by_contra h; exact hz (fairSeries_support g z h) - have h2 : (fairSeries g).coeff ((g:ℤ)-z)=0 := by - by_contra h - have hh := fairSeries_support g ((g:ℤ)-z) h - exact hz ⟨by omega,by omega⟩ - rw [h1,h2] - -/-- Reflection in the posterior count is exactly an ordinary translated - fair binomial; it does not change the smoothing channel. -/ -theorem affine_reflected_binomial (g : ℕ) (c z : ℤ) : - (fairSeries g).coeff (c-z)= - (translateSeries (c-g) (fairSeries g)).coeff z := by - rw [translateSeries_coeff,← fairSeries_reflect g (c-z)] - congr 1; omega - -theorem translated_binomial_nonneg (g : ℕ) (c z : ℤ) : - 0≤(translateSeries c (fairSeries g)).coeff z := by - rw [translateSeries_coeff] - exact fairSeries_nonneg _ _ - -theorem translated_binomial_support (g : ℕ) (c z : ℤ) - (hz : (translateSeries c (fairSeries g)).coeff z ≠ 0) : - c≤z ∧ z≤c+g := by - rw [translateSeries_coeff] at hz - have h := fairSeries_support g (z-c) hz - omega - -theorem translated_binomial_smoothing (g s : ℕ) (c : ℤ) : - seriesL2Sq (prouhetSeries s*translateSeries c (fairSeries g)) ≤ - ((2:ℝ)^(s*s))^2*(((2*binomialBound (g/(s+1)))^s)^2*binomialBound (g/(s+1))) := by - rw [mul_translateSeries,translateSeries_L2Sq] - exact (signed_binomial_smoothing g s).2 - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -theorem linearPattern_order {r : ℕ} (a : Fin r) : - (∑ h, ((linearPattern a) h).order)=1 := by - classical - have he (h : Fin r) : ((linearPattern a) h).order=if h=a then 1 else 0 := by - by_cases hh : h=a <;> simp [linearPattern,hh,GapDifference.order] - simp_rw [he] - simp - -theorem first_second_counts_linear {r : ℕ} (k : Fin r → GapDifference) - (h1 : firstDifferenceCount k=1) (h2 : secondDifferenceCount k=0) : - ∃ a : Fin r, k=linearPattern a := by - classical - obtain ⟨a,ha⟩ := Finset.card_eq_one.mp h1 - refine ⟨a,funext fun b => ?_⟩ - have hfirst : k b = .first ↔ b=a := by - have hh := congrArg (fun A : Finset (Fin r) => b∈A) ha - simpa only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_singleton] using (iff_of_eq hh) - have hsecond : k b ≠ .second := by - have hh := Finset.card_eq_zero.mp h2 - intro hb - have hmem : b∈(Finset.univ.filter fun b => k b=.second) := by simp [hb] - rw [hh] at hmem - exact Finset.notMem_empty _ hmem - by_cases hb : b=a - · have hf := hfirst.mpr hb - simpa [linearPattern,hb] using hf - · have hf := mt hfirst.mp hb - cases hk : k b <;> simp_all [linearPattern] - -theorem odd_pattern_pair {r : ℕ} (k : Fin r → GapDifference) - (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : - ∃ a b : Fin r, a ?_⟩ - by_cases hb : b=a - · subst b; simp [linearPattern,ha'] - · have hba : k b=.unchanged := by - rcases lt_or_gt_of_ne hb with hba|hab - · by_contra hb' - exact (show k a≠.unchanged by simp [ha']) (hh b a hba hb') - · exact hh a b hab (by simp [ha']) - simp [linearPattern,hb,hba] - -theorem odd_nonlinear_order {r : ℕ} (k : Fin r → GapDifference) - (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : - 3≤∑ h, (k h).order := by - rcases odd_pattern_linear_or_order_three k hk with h|h - · exact (hnl (first_second_counts_linear k h.1 h.2)).elim - · exact h - -/-- An actual convolution witness, retaining the common motif offset. -/ -theorem motif_convolution_support (f π : IntSeries) (L : ℕ) - (hf : ∀z, f.coeff z≠0 → 0≤z ∧ z linarith - -theorem prouhet_convolution_central {u s : ℕ} (π : IntSeries) - (hπ : CentralMotifSupport u s π) (h : Fin u) - (hh : (prouhetSeries s*π).coeff (h.val:ℤ)≠0) : - (u:ℝ)/3≤2*h.val+1 ∧ (u:ℝ)/3≤2*u-(2*h.val+1) := by - apply motif_convolution_central π _ hπ _ h hh - intro z hz - constructor - · by_contra h; exact hz ((prouhetSeries_coeff_spec s).1 z (Or.inl (by omega))) - · by_contra h; exact hz ((prouhetSeries_coeff_spec s).1 z (Or.inr (by omega))) - -theorem unsigned_convolution_central {u s : ℕ} (π : IntSeries) - (hπ : CentralMotifSupport u s π) (h : Fin u) - (hh : (geomSeries (2^s)*π).coeff (h.val:ℤ)≠0) : - (u:ℝ)/3≤2*h.val+1 ∧ (u:ℝ)/3≤2*u-(2*h.val+1) := by - apply motif_convolution_central π _ hπ _ h hh - intro z hz - by_contra hs - rw [geomSeries_coeff,ite_eq_right hs] at hz - exact hz rfl - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Differences +import OAI.Probability.TraceReconstruction.InitialDensity + +namespace OAI + +/-! +# Patterns + +Pattern serialization, motif norms, flag posteriors, signed rank coefficients, translated binomials, and support geometry. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem seriesL2Sq_partial {α : Type*} [Fintype α] (f : IntSeries) + (j : α → ℤ) (hj : Function.Injective j) : + (∑ a, f.coeff (j a)^2) ≤ seriesL2Sq f := by + classical + let A := Finset.univ.image j + have he : (∑ a, f.coeff (j a)^2)=∑ z∈A, f.coeff z^2 := by + rw [Finset.sum_image] + exact fun _ _ _ _ h => hj h + rw [he] + calc + _ ≤ ∑ z∈f.coeff.support ∪ A, f.coeff z^2 := + Finset.sum_le_sum_of_subset_of_nonneg Finset.subset_union_right (fun _ _ _ => sq_nonneg _) + _ = _ := by + rw [seriesL2Sq_eq_sum] + symm + apply Finset.sum_subset Finset.subset_union_left + intro z _ hz + simp [Finsupp.notMem_support_iff.mp hz] + +/-- The cancellation estimate after disjoint rank clipping, retaining the + actual fixed-period kernels and all anchor correlations. -/ +theorem period_pattern_norm {u m l r : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (hsafe : ∀ j : IncreasingTuple u r, SafeTaggedTuple (periodSlot off ∘ j.val)) + (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) + (hhalf : 1/2 ≤ θ) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (a : Fin r) (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) + (hA : ∀ j, A j^2 ≤ w (j.val a)^2) + (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) : + (∑ v, (∑ j, if PeriodRankRegion m θ j v then + A j*positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v else 0)^2) ≤ + periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + periodCentralSumConstant u r * ∑ h, w h^2 := by + have hC : 0 ≤ periodDifferencePrefactor u m r (∑ h, (k h).order) θ := by + unfold periodDifferencePrefactor lengthDifferenceConstant + positivity + calc + _ ≤ ∑ j, A j^2*∑ v, positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v^2 := + period_clipped_square_sum (by omega) hhalf _ A + _ ≤ ∑ j, A j^2*(periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) := by + apply Finset.sum_le_sum + intro j _ + exact mul_le_mul_of_nonneg_left + (period_positionalRankDifference_bound hm hr hl off hoff hdiff j (hsafe j) k hθ hmean hv) + (sq_nonneg _) + _ = periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + ∑ j, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by + rw [Finset.mul_sum]; congr 1; funext j; ring + _ ≤ _ := by + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (weighted_period_gap_sum a A w hA hw) hC + +theorem period_pattern_bounded_norm {u m l r M : ℕ} + (hm : 32 ≤ m) (hr : 0 < r) (hl : l ≤ u*m) + (off : Fin u → Fin m) + (hoff : ∀ j, |((off j).val:ℝ)-(m:ℝ)/2| ≤ 3) + (hdiff : ∀ j k, |((off j).val:ℝ)-(off k).val| ≤ 2) + (hsafe : ∀ j : IncreasingTuple u r, SafeTaggedTuple (periodSlot off ∘ j.val)) + (k : Fin r → GapDifference) {θ : ℝ} (hθ : θ ∈ Set.Ioo 0 1) + (hhalf : 1/2 ≤ θ) (hmean : ((u*m:ℕ):ℝ)*θ=l) (hv : 1 ≤ ((u*m:ℕ):ℝ)*θ*(1-θ)) + (a : Fin r) (c : Fin (r+1)) (A : IncreasingTuple u r → ℝ) (w : Fin u → ℝ) + (hA : ∀ j, A j^2 ≤ w (j.val a)^2) + (hsupport : ∀ j, A j ≠ 0 → coarsePeriodGap j.val c ≤ M) + (hw : ∀ h, w h ≠ 0 → (u:ℝ)/3 ≤ 2*h.val+1 ∧ (u:ℝ)/3 ≤ 2*u-(2*h.val+1)) + (hM : (M:ℝ) < (u:ℝ)/(3*(r+1:ℝ))) : + (∑ v, (∑ j, if PeriodRankRegion m θ j v then + A j*positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v else 0)^2) ≤ + periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + periodBoundedSumConstant u r M * ∑ h, w h^2 := by + have hC : 0 ≤ periodDifferencePrefactor u m r (∑ h, (k h).order) θ := by + unfold periodDifferencePrefactor lengthDifferenceConstant + positivity + calc + _ ≤ ∑ j, A j^2*∑ v, positionalRankDifference hl (periodSlot off ∘ j.val) (hsafe j) k v^2 := + period_clipped_square_sum (by omega) hhalf _ A + _ ≤ ∑ j, A j^2*(periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + ∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹) := by + apply Finset.sum_le_sum + intro j _ + exact mul_le_mul_of_nonneg_left + (period_positionalRankDifference_bound hm hr hl off hoff hdiff j (hsafe j) k hθ hmean hv) + (sq_nonneg _) + _ = periodDifferencePrefactor u m r (∑ h, (k h).order) θ * + ∑ j, A j^2*∏ i, (Real.sqrt (coarsePeriodGap j.val i))⁻¹ := by + rw [Finset.mul_sum]; congr 1; funext j; ring + _ ≤ _ := by + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (weighted_period_bounded_gap_sum a c A w hA hsupport hw hM) hC + +/-- Two involved motif positions force a short *fixed* internal coarse gap. + The chosen gap is independent of the actual labels and of the offset law. -/ +theorem motif_pattern_bounded_gap {u r : ℕ} (π : IntSeries) (s : ℕ) + (j : IncreasingTuple u (r+1)) (k : Fin (r+1) → GapDifference) + (i : Fin r) (b : Fin (r+1)) (hib : i.castSucc < b) + (hi : k i.castSucc ≠ .unchanged) (hb : k b ≠ .unchanged) + (hA : motifPatternMultiplier π s (fun a => (j.val a).val) k ≠ 0) : + coarsePeriodGap j.val i.castSucc.succ ≤ 2*(2^s) := by + have hs := motif_multiplier_bounded_separation π s (fun a => (j.val a).val) k hA i.castSucc b hi hb + have hj1 := j.property (show i.castSucc < i.succ by exact Fin.castSucc_lt_succ) + have hj2 := j.property.monotone (show i.succ ≤ b by simpa only [Fin.le_iff_val_le_val,Fin.lt_def, + Fin.val_succ,Fin.val_castSucc] using (Nat.succ_le_of_lt hib)) + have h1 : (j.val i.castSucc).val < (j.val i.succ).val := hj1 + have h2 : (j.val i.succ).val ≤ (j.val b).val := hj2 + have hh := (abs_lt.mp hs).1 + rw [coarsePeriodGap_middle] + omega + +end TraceReconstruction + + +namespace TraceReconstruction + +theorem centered_window_floor_fit (P T L t : ℕ) (Y : ℤ) + (hP : 2*T ≤ P) (hT : 16 ≤ T) (heven : Even T) + (hL : 8*L ≤ T) (hY : |8*Y| ≤ (T:ℤ)) + (ht : (t:ℤ)=(((P-T)/2:ℕ):ℤ)+Y) : + t+T ≤ P ∧ t ≤ P/2 ∧ P/2+L ≤ t+T := by + obtain ⟨k,hk⟩ := heven + have hy := abs_le.mp hY + omega + +theorem centered_window_floor_anchor (P T : ℕ) (hTP : T ≤ P) (heven : Even T) : + P/2-(P-T)/2=T/2 := by + obtain ⟨k,hk⟩ := heven + omega + +theorem atomString_append (n m : ℕ) (w : Bool → List Bool) (θ : Fin (n+m) → Bool) : + atomString (n+m) w θ = + atomString n w (fun i => θ (i.castLE (Nat.le_add_right n m))) ++ + atomString m w (fun i => θ (i.natAdd n)) := by + simp only [atomString,List.ofFn_add,List.flatten_append] + +theorem atomString_three (n m k : ℕ) (w : Bool → List Bool) (θ : Fin (n+m+k) → Bool) : + atomString (n+m+k) w θ = + atomString n w (fun i => θ ⟨i.val,by omega⟩) ++ + atomString m w (fun i => θ ⟨n+i.val,by omega⟩) ++ + atomString k w (fun i => θ ⟨n+m+i.val,by omega⟩) := by + rw [atomString_append,atomString_append] + rfl + +/-- A full deterministic template equals a pure prefix, the actual translated + window, and a pure suffix. This equality is in unmarked binary strings. -/ +theorem template_word_window (t T z a L : ℕ) (sign : Fin L → Bool) (τ : Bool) + (w : Bool → List Bool) (hleft : t ≤ a) (hright : a+L ≤ t+T) : + atomString (t+T+z) w (templateType (t+T+z) a L sign τ) = + atomString t w (fun _ => false) ++ + atomString T w (templateType T (a-t) L sign τ) ++ + atomString z w (fun _ => false) := by + rw [atomString_three] + congr 2 + · congr 1 + funext i + exact templateType_outside_window sign τ hleft hright ⟨i.val,by omega⟩ (Or.inl i.isLt) + · congr 1 + funext i + exact templateType_inside_window sign τ (by omega) hleft i + · funext i + exact templateType_outside_window sign τ hleft hright ⟨t+T+i.val,by omega⟩ (Or.inr (by dsimp; omega)) + +def pureAtomRun (w : List Bool) (n : ℕ) : List Bool := + (List.replicate n w).flatten + +theorem atomString_constant (n : ℕ) (w : Bool → List Bool) (b : Bool) : + atomString n w (fun _ => b)=pureAtomRun (w b) n := by + simp [atomString,pureAtomRun] + +theorem pureAtomRun_add (w : List Bool) (n m : ℕ) : + pureAtomRun w (n+m)=pureAtomRun w n ++ pureAtomRun w m := by + simp only [pureAtomRun,List.replicate_add,List.flatten_append] + +/-- Splitting or regrouping a pure region into reported chunks changes no + unmarked string. In particular arbitrary fixed chunk IDs are harmless. -/ +theorem pureAtomRun_partition (w : List Bool) (ns : List ℕ) : + (ns.map (pureAtomRun w)).flatten=pureAtomRun w ns.sum := by + induction ns with + | nil => simp [pureAtomRun] + | cons n ns ih => simp [ih,pureAtomRun_add] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction.FiniteLaw +open scoped Classical +variable {α : Type*} [Fintype α] + +/-- Exact orientation law after a report: only invisible bits remain random. -/ +def flagPosterior (d : Option Bool) : FiniteLaw Bool where + mass b := match d with + | none => 1/2 + | some c => if b=c then 1 else 0 + nonneg := by + intro b + cases d with + | none => norm_num + | some c => dsimp; split_ifs <;> norm_num + total := by cases d with + | none => norm_num [Fintype.sum_bool] + | some c => simp + +def pairedReportMass (P Q H : FiniteLaw α) (ω : ℝ) + (z : Option Bool × (α × α)) : ℝ := + ∑ b : Bool, (1/2 : ℝ)*pairedFlagMass P Q H ω b z + +/-- Pointwise Bayes factorization, valid even at zero probability reports. -/ +theorem pairedFlag_bayes (P Q H : FiniteLaw α) (ω : ℝ) + (z : Option Bool × (α × α)) (b : Bool) : + (1/2 : ℝ)*pairedFlagMass P Q H ω b z = + pairedReportMass P Q H ω z * (flagPosterior z.1).mass b := by + rcases z with ⟨d,z⟩ + cases d with + | none => simp [pairedReportMass,pairedFlagMass,flagPosterior]; ring + | some c => cases b <;> cases c <;> + simp [pairedReportMass,pairedFlagMass,flagPosterior] + +theorem pairedReportMass_nonneg (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) + (z : Option Bool × (α × α)) : 0 ≤ pairedReportMass P Q H ω z := by + apply Finset.sum_nonneg + intro b _ + exact mul_nonneg (by norm_num) (pairedFlagMass_nonneg P Q H hω hP hQ b z) + +theorem pairedReportMass_total (P Q H : FiniteLaw α) (ω : ℝ) : + (∑ z, pairedReportMass P Q H ω z)=1 := by + unfold pairedReportMass + rw [Finset.sum_comm] + simp_rw [← Finset.mul_sum,pairedFlagMass_sum] + norm_num [Fintype.sum_bool] + +def pairedReport (P Q H : FiniteLaw α) {ω : ℝ} (hω : 0 ≤ ω) + (hP : ∀ a, ω*H.mass a ≤ P.mass a) (hQ : ∀ a, ω*H.mass a ≤ Q.mass a) : + FiniteLaw (Option Bool × (α × α)) := + ⟨pairedReportMass P Q H ω, pairedReportMass_nonneg P Q H hω hP hQ, + pairedReportMass_total P Q H ω⟩ + +/-- Conditioning solely on exact reports does not correlate mechanisms. + This is the actual joint-mass factorization, not an independence hypothesis. -/ +theorem pairedFlags_product_bayes {ι : Type*} [Fintype ι] + (P Q H : ι → FiniteLaw α) (ω : ι → ℝ) + (z : ι → Option Bool × (α × α)) (b : ι → Bool) : + (∏ i, (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) (b i) (z i)) = + (∏ i, pairedReportMass (P i) (Q i) (H i) (ω i) (z i)) * + ∏ i, (flagPosterior (z i).1).mass (b i) := by + simp_rw [pairedFlag_bayes] + exact Finset.prod_mul_distrib + +theorem pairedFlags_report_marginal {ι : Type*} [Fintype ι] + (P Q H : ι → FiniteLaw α) (ω : ι → ℝ) + (z : ι → Option Bool × (α × α)) : + (∑ b : ι → Bool, ∏ i, (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) (b i) (z i)) = + ∏ i, pairedReportMass (P i) (Q i) (H i) (ω i) (z i) := by + exact (Fintype.prod_sum (fun i b => (1/2 : ℝ)*pairedFlagMass (P i) (Q i) (H i) (ω i) b (z i))).symm + +end TraceReconstruction.FiniteLaw + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def bitIndex (b : Bool) : ℕ := if b then 1 else 0 + +def posteriorBitSeries (d : Option Bool) : IntSeries := + ∑ b : Bool, AddMonoidAlgebra.single (bitIndex b : ℤ) ((FiniteLaw.flagPosterior d).mass b) + +def visibleOnes (d : Option Bool) : ℕ := if d=some true then 1 else 0 + +def hiddenTrial (d : Option Bool) : ℕ := if d=none then 1 else 0 + +theorem posteriorBitSeries_factor (d : Option Bool) : + posteriorBitSeries d = AddMonoidAlgebra.single (visibleOnes d : ℤ) 1 * fairSeries (hiddenTrial d) := by + cases d with + | none => simp [posteriorBitSeries,FiniteLaw.flagPosterior,bitIndex,visibleOnes,hiddenTrial,fairSeries, + add_comm] + | some b => cases b <;> simp [posteriorBitSeries,FiniteLaw.flagPosterior,bitIndex,visibleOnes,hiddenTrial, + fairSeries] + +/-- The count distribution of the literal posterior orientation bits is + a translated fair binomial, including reports of probability zero. -/ +theorem posterior_count_series {ι : Type*} [Fintype ι] (d : ι → Option Bool) : + (∑ b : ι → Bool, AddMonoidAlgebra.single (∑ i, (bitIndex (b i):ℤ)) + (∏ i, (FiniteLaw.flagPosterior (d i)).mass (b i))) = + AddMonoidAlgebra.single (∑ i, (visibleOnes (d i):ℤ)) 1 * + fairSeries (∑ i, hiddenTrial (d i)) := by + have he : (∑ b : ι → Bool, AddMonoidAlgebra.single (∑ i, (bitIndex (b i):ℤ)) + (∏ i, (FiniteLaw.flagPosterior (d i)).mass (b i))) = ∏ i, posteriorBitSeries (d i) := by + rw [show (∏ i, posteriorBitSeries (d i)) = + ∏ i, ∑ b : Bool, AddMonoidAlgebra.single (bitIndex b : ℤ) ((FiniteLaw.flagPosterior (d i)).mass b) from rfl] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro b _ + rw [AddMonoidAlgebra.prod_single] + rw [he] + simp_rw [posteriorBitSeries_factor] + rw [Finset.prod_mul_distrib,AddMonoidAlgebra.prod_single] + simp only [Finset.prod_const_one] + congr 1 + unfold fairSeries + exact Finset.prod_pow_eq_pow_sum _ _ _ + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem geomSeries_coeff (k : ℕ) (z : ℤ) : + (geomSeries k).coeff z = if 0 ≤ z ∧ z < k then 1 else 0 := by + unfold geomSeries + simp only [AddMonoidAlgebra.single_pow,one_pow,nsmul_eq_mul,mul_one, + AddMonoidAlgebra.coeff_sum,Finsupp.finsetSum_apply,AddMonoidAlgebra.coeff_single,Finsupp.single_apply] + by_cases hz : 0 ≤ z ∧ z < k + · obtain ⟨a,rfl⟩ := Int.eq_ofNat_of_zero_le hz.1 + rw [ite_eq_left hz,Finset.sum_eq_single a] + · simp + · intro b _ hb + exact ite_eq_right (by exact_mod_cast hb) + · intro ha + have ha' : a < k := by exact_mod_cast hz.2 + exact (ha (Finset.mem_range.mpr ha')).elim + · rw [ite_eq_right hz] + apply Finset.sum_eq_zero + intro a ha + apply ite_eq_right + intro haz + subst z + exact hz ⟨by positivity,by exact_mod_cast Finset.mem_range.mp ha⟩ + +theorem motif_unsigned_convolution (π : IntSeries) (s : ℕ) (z : ℤ) : + (∑ X ∈ π.coeff.support, π.coeff X*motifIndicator s (z-X)) = + (geomSeries (2^s)*π).coeff z := by + rw [mul_comm,AddMonoidAlgebra.coeff_mul_apply_left,Finsupp.sum] + apply Finset.sum_congr rfl + intro X _ + rw [geomSeries_coeff] + simp only [motifIndicator,sub_eq_neg_add] + +theorem motifPatternMultiplier_sq_le {r : ℕ} (π : IntSeries) + (hπ : ∀ X, 0 ≤ π.coeff X) (s : ℕ) (j : Fin r → ℤ) + (k : Fin r → GapDifference) (h : Fin r) (hk : k h ≠ .unchanged) : + (motifPatternMultiplier π s j k)^2 ≤ ((geomSeries (2^s)*π).coeff (j h))^2 := by + have ha := motifPatternMultiplier_abs_le π hπ s j k h hk + rw [motif_unsigned_convolution] at ha + have hh := pow_le_pow_left₀ (abs_nonneg (motifPatternMultiplier π s j k)) ha 2 + simpa only [sq_abs] using hh + +theorem unsigned_motif_energy (π : IntSeries) (s : ℕ) : + seriesL2Sq (geomSeries (2^s)*π) ≤ ((2:ℝ)^s)^2 * seriesL2Sq π := by + refine (seriesL2Sq_mul_le _ _).trans ?_ + apply mul_le_mul_of_nonneg_right _ (seriesL2Sq_nonneg _) + exact pow_le_pow_left₀ (seriesL1_nonneg _) (by simpa using geomSeries_L1_le (2^s)) 2 + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction + +/-- Elementary chi-square upper bound on the Bernoulli relative entropy. + No Stirling estimate is used in the subsequent count overlap. -/ +theorem bernoulli_entropy_upper {t p : ℝ} (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : + t*Real.log (t/p)+(1-t)*Real.log ((1-t)/(1-p)) ≤ + (t-p)^2/(p*(1-p)) := by + have h1 := mul_le_mul_of_nonneg_left (Real.log_le_sub_one_of_pos (div_pos ht.1 hp.1)) ht.1.le + have h2 := mul_le_mul_of_nonneg_left + (Real.log_le_sub_one_of_pos (div_pos (sub_pos.mpr ht.2) (sub_pos.mpr hp.2))) + (sub_nonneg.mpr ht.2.le) + have hid : t*(t/p-1)+(1-t)*((1-t)/(1-p)-1)=(t-p)^2/(p*(1-p)) := by + field_simp [hp.1.ne', (sub_pos.mpr hp.2).ne'] + ring + linarith + +/-- Exact likelihood change from the mean-matched Bernoulli law. -/ +theorem binomialMass_likelihood (n l : ℕ) {t p : ℝ} + (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) : + binomialMass n p l = binomialMass n t l * + Real.exp (-((l:ℝ)*Real.log (t/p)+((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p)))) := by + have h1 : Real.exp (-((l:ℝ)*Real.log (t/p)))=(p/t)^l := by + rw [show -((l:ℝ)*Real.log (t/p))=(l:ℝ)*Real.log (p/t) by + rw [Real.log_div ht.1.ne' hp.1.ne',Real.log_div hp.1.ne' ht.1.ne']; ring, + Real.exp_nat_mul,Real.exp_log (div_pos hp.1 ht.1)] + have h2 : Real.exp (-(((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p))))=((1-p)/(1-t))^(n-l) := by + rw [show -(((n-l:ℕ):ℝ)*Real.log ((1-t)/(1-p)))= + ((n-l:ℕ):ℝ)*Real.log ((1-p)/(1-t)) by + rw [Real.log_div (sub_pos.mpr ht.2).ne' (sub_pos.mpr hp.2).ne', + Real.log_div (sub_pos.mpr hp.2).ne' (sub_pos.mpr ht.2).ne']; ring, + Real.exp_nat_mul,Real.exp_log (div_pos (sub_pos.mpr hp.2) (sub_pos.mpr ht.2))] + rw [neg_add,Real.exp_add,h1,h2] + unfold binomialMass + rw [div_pow,div_pow] + field_simp [ht.1.ne', (sub_pos.mpr ht.2).ne'] + +/-- Pointwise lower mass at every interior integer, with mean-matched + variance at least one. It applies uniformly even as deletion vanishes. -/ +theorem binomialMass_near_mean_lower (n l : ℕ) {t p : ℝ} + (ht : t ∈ Set.Ioo 0 1) (hp : p ∈ Set.Ioo 0 1) + (hl : l ≤ n) (hmean : (n:ℝ)*t=l) (hv : 1 ≤ (n:ℝ)*t*(1-t)) : + Real.exp (-((l:ℝ)-(n:ℝ)*p)^2/((n:ℝ)*p*(1-p))) / + (12*Real.sqrt ((n:ℝ)*t*(1-t))) ≤ binomialMass n p l := by + have hn : (0:ℝ) off))) + (s : ℕ) (X : ℤ) (τ : ℝ) : Fin u → Fin (u*m) := + shiftedTag (periodSlot (fun _ => off)) hsafe + (fun j => motifShift (motifIndicator s ((j.val:ℤ)-X)) ((prouhetSeries s).coeff ((j.val:ℤ)-X)) τ) + +theorem signedPeriodDefects_strictMono {u m : ℕ} (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (s : ℕ) (X : ℤ) (τ : ℝ) : StrictMono (signedPeriodDefects off hsafe s X τ) := + shiftedTag_strictMono _ _ _ + +theorem SafeTaggedTuple.comp {n u r : ℕ} {p : Fin u → Fin n} + (hp : SafeTaggedTuple p) (j : Fin r → Fin u) (hj : StrictMono j) : + SafeTaggedTuple (p ∘ j) := + ⟨fun i => hp.1 (j i),fun i k hik => hp.2 (j i) (j k) (hj hik)⟩ + +theorem shiftedTag_comp {n u r : ℕ} (p : Fin u → Fin n) (hp : SafeTaggedTuple p) + (a : Fin u → Fin 3) (j : Fin r → Fin u) (hj : StrictMono j) : + shiftedTag p hp a ∘ j = shiftedTag (p ∘ j) (hp.comp j hj) (a ∘ j) := by + funext i + apply Fin.ext + rfl + +/-- Exact degree-r coefficient difference of the actual randomized motif + in the marked central run, prior to any rank clipping. -/ +def signedRankCoefficient {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : ℝ := + ∑ X ∈ π.coeff.support, π.coeff X * + (rankDefectCoefficient hl (signedPeriodDefects off hsafe s X 1) v - + rankDefectCoefficient hl (signedPeriodDefects off hsafe s X (-1)) v) + +theorem signedRankCoefficient_expansion {u m l r : ℕ} (hl : l ≤ u*m) (off : Fin m) + (hsafe : SafeTaggedTuple (periodSlot (u := u) (fun _ => off))) + (π : IntSeries) (s : ℕ) (v : IncreasingTuple l r) : + signedRankCoefficient hl off hsafe π s v = + ∑ k : Fin r → GapDifference, if Odd (firstDifferenceCount k) then + 2*∑ j : IncreasingTuple u r, + motifPatternMultiplier π s (fun i => (j.val i).val) k * + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v else 0 := by + unfold signedRankCoefficient + simp_rw [rankDefectCoefficient_eq _ _ (signedPeriodDefects_strictMono _ _ _ _ _), + ← Finset.sum_sub_distrib,Finset.mul_sum] + rw [Finset.sum_comm] + have he (j : IncreasingTuple u r) : + (∑ X ∈ π.coeff.support, π.coeff X * + (subsetRankKernel hl (signedPeriodDefects off hsafe s X 1 ∘ j.val) v.val - + subsetRankKernel hl (signedPeriodDefects off hsafe s X (-1) ∘ j.val) v.val)) = + ∑ k : Fin r → GapDifference, + (if Odd (firstDifferenceCount k) then 2*motifPatternMultiplier π s (fun i => (j.val i).val) k else 0)* + positionalRankDifference hl (periodSlot (fun _ => off) ∘ j.val) + (hsafe.comp j.val j.property) k v := by + have htag (X : ℤ) (τ : ℝ) : + signedPeriodDefects off hsafe s X τ ∘ j.val = + shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) + (fun i => motifShift (motifIndicator s ((j.val i).val-X)) + ((prouhetSeries s).coeff ((j.val i).val-X)) τ) := by + funext i; apply Fin.ext; rfl + simp_rw [htag] + simpa only [positionalRankDifference] + using mixed_signed_shift_expansion π s (fun i => (j.val i).val) + (fun a => subsetRankKernel hl + (shiftedTag (periodSlot (fun _ => off) ∘ j.val) (hsafe.comp j.val j.property) a) v.val) + simp_rw [he] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + split_ifs with hk + · apply Finset.sum_congr rfl + intro j _; ring + · simp only [zero_mul,Finset.sum_const_zero] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def translateSeries (c : ℤ) (f : IntSeries) : IntSeries := + AddMonoidAlgebra.single c 1*f + +theorem translateSeries_coeff (c : ℤ) (f : IntSeries) (z : ℤ) : + (translateSeries c f).coeff z = f.coeff (z-c) := by + rw [translateSeries,AddMonoidAlgebra.coeff_single_mul_apply,one_mul] + congr 1; omega + +theorem translateSeries_L2Sq (c : ℤ) (f : IntSeries) : + seriesL2Sq (translateSeries c f)=seriesL2Sq f := by + unfold seriesL2Sq + simp_rw [translateSeries_coeff] + exact (Equiv.subRight c).tsum_eq (fun z => f.coeff z^2) + +theorem translateSeries_L1 (c : ℤ) (f : IntSeries) : + seriesL1 (translateSeries c f)=seriesL1 f := by + unfold seriesL1 + simp_rw [translateSeries_coeff] + exact (Equiv.subRight c).tsum_eq (fun z => |f.coeff z|) + +theorem mul_translateSeries (c : ℤ) (f g : IntSeries) : + f*translateSeries c g=translateSeries c (f*g) := by + unfold translateSeries + ring + +theorem fairSeries_support (g : ℕ) (z : ℤ) (hz : (fairSeries g).coeff z ≠ 0) : + 0≤z ∧ z≤g := by + have h0 : 0≤z := by + by_contra h + exact hz (fairSeries_coeff_neg g z (by omega)) + obtain ⟨k,rfl⟩ := Int.eq_ofNat_of_zero_le h0 + refine ⟨by positivity,?_⟩ + by_contra hk + rw [fairSeries_coeff_nat,fairBinomial,Nat.choose_eq_zero_of_lt (by omega)] at hz + simp at hz + +theorem fairSeries_reflect (g : ℕ) (z : ℤ) : + (fairSeries g).coeff ((g:ℤ)-z)=(fairSeries g).coeff z := by + by_cases hz : 0≤z ∧ z≤g + · obtain ⟨k,rfl⟩ := Int.eq_ofNat_of_zero_le hz.1 + have hk : k≤g := by exact_mod_cast hz.2 + rw [← Nat.cast_sub hk,fairSeries_coeff_nat,fairSeries_coeff_nat] + simp only [fairBinomial,Nat.choose_symm hk] + · have h1 : (fairSeries g).coeff z=0 := by + by_contra h; exact hz (fairSeries_support g z h) + have h2 : (fairSeries g).coeff ((g:ℤ)-z)=0 := by + by_contra h + have hh := fairSeries_support g ((g:ℤ)-z) h + exact hz ⟨by omega,by omega⟩ + rw [h1,h2] + +/-- Reflection in the posterior count is exactly an ordinary translated + fair binomial; it does not change the smoothing channel. -/ +theorem affine_reflected_binomial (g : ℕ) (c z : ℤ) : + (fairSeries g).coeff (c-z)= + (translateSeries (c-g) (fairSeries g)).coeff z := by + rw [translateSeries_coeff,← fairSeries_reflect g (c-z)] + congr 1; omega + +theorem translated_binomial_nonneg (g : ℕ) (c z : ℤ) : + 0≤(translateSeries c (fairSeries g)).coeff z := by + rw [translateSeries_coeff] + exact fairSeries_nonneg _ _ + +theorem translated_binomial_support (g : ℕ) (c z : ℤ) + (hz : (translateSeries c (fairSeries g)).coeff z ≠ 0) : + c≤z ∧ z≤c+g := by + rw [translateSeries_coeff] at hz + have h := fairSeries_support g (z-c) hz + omega + +theorem translated_binomial_smoothing (g s : ℕ) (c : ℤ) : + seriesL2Sq (prouhetSeries s*translateSeries c (fairSeries g)) ≤ + ((2:ℝ)^(s*s))^2*(((2*binomialBound (g/(s+1)))^s)^2*binomialBound (g/(s+1))) := by + rw [mul_translateSeries,translateSeries_L2Sq] + exact (signed_binomial_smoothing g s).2 + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +theorem linearPattern_order {r : ℕ} (a : Fin r) : + (∑ h, ((linearPattern a) h).order)=1 := by + classical + have he (h : Fin r) : ((linearPattern a) h).order=if h=a then 1 else 0 := by + by_cases hh : h=a <;> simp [linearPattern,hh,GapDifference.order] + simp_rw [he] + simp + +theorem first_second_counts_linear {r : ℕ} (k : Fin r → GapDifference) + (h1 : firstDifferenceCount k=1) (h2 : secondDifferenceCount k=0) : + ∃ a : Fin r, k=linearPattern a := by + classical + obtain ⟨a,ha⟩ := Finset.card_eq_one.mp h1 + refine ⟨a,funext fun b => ?_⟩ + have hfirst : k b = .first ↔ b=a := by + have hh := congrArg (fun A : Finset (Fin r) => b∈A) ha + simpa only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_singleton] using (iff_of_eq hh) + have hsecond : k b ≠ .second := by + have hh := Finset.card_eq_zero.mp h2 + intro hb + have hmem : b∈(Finset.univ.filter fun b => k b=.second) := by simp [hb] + rw [hh] at hmem + exact Finset.notMem_empty _ hmem + by_cases hb : b=a + · have hf := hfirst.mpr hb + simpa [linearPattern,hb] using hf + · have hf := mt hfirst.mp hb + cases hk : k b <;> simp_all [linearPattern] + +theorem odd_pattern_pair {r : ℕ} (k : Fin r → GapDifference) + (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : + ∃ a b : Fin r, a ?_⟩ + by_cases hb : b=a + · subst b; simp [linearPattern,ha'] + · have hba : k b=.unchanged := by + rcases lt_or_gt_of_ne hb with hba|hab + · by_contra hb' + exact (show k a≠.unchanged by simp [ha']) (hh b a hba hb') + · exact hh a b hab (by simp [ha']) + simp [linearPattern,hb,hba] + +theorem odd_nonlinear_order {r : ℕ} (k : Fin r → GapDifference) + (hk : Odd (firstDifferenceCount k)) (hnl : ¬∃a, k=linearPattern a) : + 3≤∑ h, (k h).order := by + rcases odd_pattern_linear_or_order_three k hk with h|h + · exact (hnl (first_second_counts_linear k h.1 h.2)).elim + · exact h + +/-- An actual convolution witness, retaining the common motif offset. -/ +theorem motif_convolution_support (f π : IntSeries) (L : ℕ) + (hf : ∀z, f.coeff z≠0 → 0≤z ∧ z linarith + +theorem prouhet_convolution_central {u s : ℕ} (π : IntSeries) + (hπ : CentralMotifSupport u s π) (h : Fin u) + (hh : (prouhetSeries s*π).coeff (h.val:ℤ)≠0) : + (u:ℝ)/3≤2*h.val+1 ∧ (u:ℝ)/3≤2*u-(2*h.val+1) := by + apply motif_convolution_central π _ hπ _ h hh + intro z hz + constructor + · by_contra h; exact hz ((prouhetSeries_coeff_spec s).1 z (Or.inl (by omega))) + · by_contra h; exact hz ((prouhetSeries_coeff_spec s).1 z (Or.inr (by omega))) + +theorem unsigned_convolution_central {u s : ℕ} (π : IntSeries) + (hπ : CentralMotifSupport u s π) (h : Fin u) + (hh : (geomSeries (2^s)*π).coeff (h.val:ℤ)≠0) : + (u:ℝ)/3≤2*h.val+1 ∧ (u:ℝ)/3≤2*u-(2*h.val+1) := by + apply motif_convolution_central π _ hπ _ h hh + intro z hz + by_contra hs + rw [geomSeries_coeff,ite_eq_right hs] at hz + exact hz rfl + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Propagation.lean b/lean/OAI/Probability/TraceReconstruction/Propagation.lean index e442a3b5bd7be69a53006f7336e1cf800f99cae2..76775335e646014c55d721c0b14a36c10b52238c 100644 --- a/lean/OAI/Probability/TraceReconstruction/Propagation.lean +++ b/lean/OAI/Probability/TraceReconstruction/Propagation.lean @@ -1,1268 +1,1268 @@ -import OAI.Probability.TraceReconstruction.ErrorRates - -namespace OAI - -/-! -# Propagation - -Moment restriction, scale margins, sharp budget closure, clipping and error propagation, and dense/warmup overlap. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -namespace FiniteLaw -variable {α : Type*} [Fintype α] - -theorem evenMomentSq_mono_order (P : FiniteLaw α) (F : α→ℝ) {j k : ℕ} - (hj : 1≤j) (hjk : j≤k) : P.evenMomentSq F j ≤ P.evenMomentSq F k := by - have hjp : (0:ℝ)|F a|^(2*j)) (fun a _=>P.nonneg a) P.total (fun _ _=>by positivity) hp - simp_rw [he] at H - have hr := Real.rpow_le_rpow (Real.rpow_nonneg (P.expect_nonneg _ (fun _=>by positivity)) _) H - (show 0≤1/(k:ℝ) by positivity) - change (P.expect (fun a=>|F a|^(2*j))^((k:ℝ)/j))^(1/(k:ℝ)) ≤ _ at hr - rw [←Real.rpow_mul (P.expect_nonneg _ (fun _=>by positivity))] at hr - have he' : (k:ℝ)/j*(1/(k:ℝ))=1/(j:ℝ) := by field_simp - rw [he'] at hr - exact hr - -end FiniteLaw - -def OracleTracePair.restrict {q E V : ℝ} {x y : List Bool} {j k : ℕ} - (C : OracleTracePair q x y k E V) (hj : 1≤j) (hjk : j≤k) : - OracleTracePair q x y j E V := by - let := C.finiteOutcome - exact {C with moment := (C.first.evenMomentSq_mono_order C.score hj hjk).trans C.moment} - -/-- Null-mass outcomes are assigned zero score. This proves, rather than - assumes, the pointwise positivity needed by the finite simulation API. -/ -def ConcreteLevelPair.oracle {q N Δ d ω F : ℝ} {hq : q∈Set.Icc 0 1} {i k : ℕ} - (C : ConcreteLevelPair q hq N Δ d ω F i k) : - OracleTracePair q C.left C.right k C.error (N^(-d)) := by - let := C.finiteOutcome - let Z := fun a=>if C.firstLaw.mass a=0 then 0 else C.score a - have hden (a) : C.secondLaw.mass a=C.firstLaw.mass a*(1+Z a) := by - dsimp [Z] - split_ifs with h - · simpa only [h,zero_mul] using C.density a - · exact C.density a - have hpos (a) : 0≤1+Z a := by - by_cases h : C.firstLaw.mass a=0 - · simp [Z,h] - · have hp : 0∑a,f a) (funext hden) - simp only [Finset.sum_add_distrib,mul_add,mul_one] at hsum - rw [C.firstLaw.total,C.secondLaw.total] at hsum - dsimp [FiniteLaw.expect] - linarith only [hsum] - have hm : C.firstLaw.evenMomentSq Z k=C.firstLaw.evenMomentSq C.score k := by - unfold FiniteLaw.evenMomentSq FiniteLaw.expect - congr 1 - apply Finset.sum_congr rfl - intro a _ - dsimp [Z] - split_ifs with h - · simp only [h,zero_mul] - · rfl - exact { - Outcome := C.Outcome - finiteOutcome := C.finiteOutcome - first := C.firstLaw - second := C.secondLaw - decode := C.decode - first_simulation := C.first_simulation - second_simulation := C.second_simulation - score := Z - density := hden - likelihood_nonneg := hpos - centered := hc - moment := hm.le.trans C.score_bound - } - -theorem sourceScaleProduct_step_le (B D i : ℕ) (hB : 2≤B) (hi : i hterm k) + simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at hsum + rw [Nat.cast_sub hb, Nat.cast_one] at hsum + have ha : (2:ℝ)^b * scaleA b 0 ε * d = d - ((2:ℝ)^b-1)*d*ε := by + unfold scaleA + simp only [pow_zero, mul_one] + field_simp + ring + unfold forcedDecay + rw [ha] + have hp : 0 ≤ (2:ℝ)^b*ε := by positivity + nlinarith + +theorem nat_add_one_le_two_pow (n : ℕ) : n+1 ≤ 2^n := by + induction n with + | zero => norm_num + | succ n ih => rw [pow_succ]; omega + +theorem sourceEpsilon_pos (B D : ℕ) : 0 < sourceEpsilon B D := by + unfold sourceEpsilon + positivity + +theorem sourceEpsilon_loss (B D b : ℕ) (d : ℝ) (hb : b ≤ B) + (hd0 : 0 ≤ d) (hd : d ≤ 3 + (B:ℝ)*D) : + (((2:ℝ)^b-1)*d + 3*b*((2:ℝ)^b/2))*sourceEpsilon B D < 1/100 := by + have hpow : (2:ℝ)^b ≤ (2:ℝ)^B := pow_le_pow_right₀ (by norm_num) hb + have hB : (B:ℝ)+1 ≤ (2:ℝ)^B := by exact_mod_cast nat_add_one_le_two_pow B + have hB0 : (0:ℝ) ≤ B := by positivity + have hD0 : (0:ℝ) ≤ D := by positivity + have hh : (((2:ℝ)^b-1)*d + 3*b*((2:ℝ)^b/2)) ≤ + 4*((2:ℝ)^B)^2*((D:ℝ)+1) := by + have hb' : (b:ℝ) ≤ B := by exact_mod_cast hb + have h1 := mul_le_mul_of_nonneg_right (show (2:ℝ)^b-1 ≤ (2:ℝ)^B by linarith) hd0 + have h2 := mul_le_mul_of_nonneg_left hd (show 0 ≤ (2:ℝ)^B by positivity) + have h3 := mul_le_mul hb' hpow (by positivity : (0:ℝ) ≤ (2:ℝ)^b) hB0 + have h4 := mul_le_mul_of_nonneg_left hB hD0 + have h5 := mul_le_mul_of_nonneg_left h4 (show 0 ≤ (2:ℝ)^B by positivity) + have h6 := mul_le_mul_of_nonneg_left hB (show 0 ≤ (2:ℝ)^B by positivity) + nlinarith [sq_nonneg ((2:ℝ)^B)] + apply lt_of_le_of_lt (mul_le_mul_of_nonneg_right hh (sourceEpsilon_pos B D).le) + unfold sourceEpsilon + have hpos : 0 < (2:ℝ)^(4*B+100) := by positivity + have hp2 : (2:ℝ)^(2*B) = ((2:ℝ)^B)^2 := by rw [mul_comm 2 B, pow_mul] + have hp4 : (2:ℝ)^(4*B+100) = ((2:ℝ)^B)^2 * (2:ℝ)^(2*B+100) := by + rw [show 4*B+100=2*B+(2*B+100) by omega, pow_add, hp2] + have hh2 : (400:ℝ) < (2:ℝ)^(2*B+100) := by + have h := pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 2) (by omega : 9 ≤ 2*B+100) + norm_num at h ⊢ + linarith + rw [mul_one_div] + apply (div_lt_iff₀ (by positivity)).mpr + rw [hp4] + have := mul_lt_mul_of_pos_left hh2 (show 0 < ((2:ℝ)^B)^2*((D:ℝ)+1) by positivity) + nlinarith + +theorem forcedDecay_margin (B D b : ℕ) (d : ℝ) (hb1 : 1 ≤ b) (hb : b ≤ B) + (hd0 : 0 ≤ d) (hd : d ≤ 3 + (B:ℝ)*D) : + d + ((b:ℝ)-1)/4 - 1/20 + 3/100 < forcedDecay b (sourceEpsilon B D) d := by + have h := forcedDecay_lower b (sourceEpsilon B D) d hb1 (sourceEpsilon_pos B D).le + have hg := sourceEpsilon_loss B D b d hb hd0 hd + linarith +end TraceReconstruction + +open Filter +open scoped Topology + + +open Filter +open scoped Topology +namespace TraceReconstruction + +def workingDeletion (q : ℝ) : ℝ := min q (1/2) +def blockGain (b : ℕ) : ℝ := ((b:ℝ)-1)/4-1/20 +def warmupBlocks (B : ℕ) : ℕ := 5*2^B +def sourceDepth (B : ℕ) (ζ H : ℝ) : ℕ := ⌊(1-ζ)*Real.log H/((B:ℝ)*Real.log 2)⌋₊ +def totalScoreExponent (B D : ℕ) : ℝ := + 11/5+∑ i ∈ Finset.range D, blockGain (if i congrArg blockGain (ite_eq_left (Finset.mem_range.mp hi))), blockGain_two] + simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] + ring + rw [hfirst] + have hlast : (∑ i ∈ Finset.range (D-warmupBlocks B), + blockGain (if warmupBlocks B+i by omega, ite_false, + Finset.sum_const, Finset.card_range, nsmul_eq_mul, Nat.cast_sub hD] + rw [hlast] + simp only [Nat.add_sub_of_le hD] + ring + +theorem sourceDepth_lower (B : ℕ) (ζ H : ℝ) : + (1-ζ)*Real.log H/((B:ℝ)*Real.log 2)-1 < (sourceDepth B ζ H:ℝ) := by + have := Nat.lt_floor_add_one ((1-ζ)*Real.log H/((B:ℝ)*Real.log 2)) + change _ < (sourceDepth B ζ H:ℝ)+1 at this + linarith + +theorem totalScoreExponent_slope_lower (B : ℕ) (ζ H : ℝ) (hB : 2 ≤ B) + (hD : warmupBlocks B ≤ sourceDepth B ζ H) : + finalSlope B ζ * Real.log H - + (blockGain B + (warmupBlocks B:ℝ)*blockGain B) < + totalScoreExponent B (sourceDepth B ζ H) := by + rw [totalScoreExponent_exact B _ hD] + have hh := mul_lt_mul_of_pos_right (sourceDepth_lower B ζ H) (blockGain_pos B hB) + unfold finalSlope + have he : ((1-ζ)*Real.log H/((B:ℝ)*Real.log 2))*blockGain B = + ((1-ζ)*blockGain B/((B:ℝ)*Real.log 2))*Real.log H := by ring + rw [sub_mul, he] at hh + have hw : (0:ℝ) ≤ warmupBlocks B := by positivity + linarith + +theorem sourceDepth_tendsto (B : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ < 1) + {H : ℕ → ℝ} (hH : Tendsto H atTop atTop) : + Tendsto (fun k => sourceDepth B ζ (H k)) atTop atTop := by + have hden : 0 < (B:ℝ)*Real.log 2 := by + apply mul_pos + · exact_mod_cast (show 0 < B by omega) + · exact Real.log_pos (by norm_num) + have ht := (Real.tendsto_log_atTop.comp hH).const_mul_atTop (sub_pos.mpr hζ) + have ht' := ht.atTop_div_const hden + exact tendsto_nat_floor_atTop.comp ht' + +/-- A fixed multiplicative constant is absorbed by any strict exponent +slope margin, with two independently diverging instance parameters. -/ +theorem eventually_exponent_margin {N H d : ℕ → ℝ} {α c K a : ℝ} + (hN : Tendsto N atTop atTop) (hH : Tendsto H atTop atTop) + (hα : c < α) (ha : 0 < a) + (hd : ∀ᶠ k in atTop, α*Real.log (H k)-K ≤ d k) : + ∀ᶠ k in atTop, (N k)^(c*Real.log (H k)) ≤ a*(N k)^(d k) := by + have hlog := (Real.tendsto_log_atTop.comp hH).const_mul_atTop (sub_pos.mpr hα) + filter_upwards [hd, hlog.eventually_ge_atTop (K+1), hN.eventually_ge_atTop (max 1 (1/a))] with k hd hlog hN + have hN1 : 1 ≤ N k := (le_max_left _ _).trans hN + have hNa : 1/a ≤ N k := (le_max_right _ _).trans hN + simp only [Function.comp_apply] at hlog + have hex : c*Real.log (H k)+1 ≤ d k := by nlinarith only [hd,hlog] + have hp := Real.rpow_le_rpow_of_exponent_le hN1 hex + rw [Real.rpow_add (by linarith : 0 < N k), Real.rpow_one] at hp + have hapos : 1 ≤ a*N k := (div_le_iff₀ ha).mp hNa |>.trans_eq (mul_comm _ _) + calc + (N k)^(c*Real.log (H k)) ≤ (a*N k)*(N k)^(c*Real.log (H k)) := by + exact le_mul_of_one_le_left (Real.rpow_nonneg (by linarith) _) hapos + _ ≤ a*(N k)^(d k) := by + have := mul_le_mul_of_nonneg_left hp ha.le + nlinarith only [this] + +end TraceReconstruction + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open Filter + +/-- Literal source block dimensions, with zero-based block number. -/ +def sourceDimension (B i : ℕ) : ℕ := if i < warmupBlocks B then 2 else B + +def sourceScaleProduct (B D i : ℕ) : ℝ := + ∏j∈Finset.Ico i D,scaleA (sourceDimension B j) 0 (sourceEpsilon B D) + +/-- The backwards target scales as an exact product of source exponents. -/ +def sourceTargetScale (B D : ℕ) (n : ℝ) (i : ℕ) : ℝ := n ^ sourceScaleProduct B D i + +theorem sourceTargetScale_top (B D : ℕ) (n : ℝ) : sourceTargetScale B D n D=n := by + simp [sourceTargetScale,sourceScaleProduct] + +theorem sourceTargetScale_step (B D i : ℕ) (n : ℝ) (hn : 0 ≤ n) (hi : i < D) : + sourceTargetScale B D n i = + (sourceTargetScale B D n (i+1))^(scaleA (sourceDimension B i) 0 (sourceEpsilon B D)) := by + unfold sourceTargetScale sourceScaleProduct + rw [←Real.rpow_mul hn,Finset.prod_eq_prod_Ico_succ_bot hi] + rw [mul_comm] + +theorem sourceEpsilon_small (B D : ℕ) : + ((D:ℝ)+1)*(2:ℝ)^B*sourceEpsilon B D ≤ 1/2 := by + have hp : 2*(2:ℝ)^B ≤ (2:ℝ)^(4*B+100) := by + rw [←pow_succ'] + exact pow_le_pow_right₀ (by norm_num) (by omega) + unfold sourceEpsilon + have hD : 0 < (D:ℝ)+1 := by positivity + have hpow : 0 < (2:ℝ)^(4*B+100) := by positivity + apply (le_div_iff₀ (by norm_num : (0:ℝ)<2)).mpr + have he : ((D:ℝ)+1)*2^B*(1/(2^(4*B+100)*((D:ℝ)+1)))*2 = + (2*2^B)/2^(4*B+100) := by field_simp + rw [he] + exact (div_le_one hpow).mpr hp + +theorem scaleA_zero_lower (b B : ℕ) (ε : ℝ) (hb : b ≤ B) (he : 0 ≤ ε) : + (1/((2:ℝ)^B))*(1-((2:ℝ)^B-1)*ε) ≤ scaleA b 0 ε := by + have hp : (2:ℝ)^b ≤ 2^B := pow_le_pow_right₀ (by norm_num) hb + have hpos : 0 < (2:ℝ)^b := by positivity + have hposB : 0 < (2:ℝ)^B := by positivity + have hd := div_le_div_of_nonneg_left (show 0 ≤ 1+ε by linarith) hpos hp + have heq : (1/((2:ℝ)^B))*(1-((2:ℝ)^B-1)*ε) = (1+ε)/2^B-ε := by + field_simp; ring + rw [heq] + unfold scaleA + norm_num only [pow_zero,mul_one] + linarith only [hd] + +theorem sourceScaleProduct_lower (B D i : ℕ) (hB : 2 ≤ B) : + 1/(2*((2:ℝ)^(B*D))) ≤ sourceScaleProduct B D i := by + let ε := sourceEpsilon B D + let u := ((2:ℝ)^B-1)*ε + let a := (1/(2:ℝ)^B)*(1-u) + have hε : 0 < ε := sourceEpsilon_pos _ _ + have hp : (1:ℝ) ≤ 2^B := one_le_pow₀ (by norm_num) + have hu : 0 ≤ u := mul_nonneg (sub_nonneg.mpr hp) hε.le + have hsmall := sourceEpsilon_small B D + have hu' : ((D:ℝ)+1)*u ≤ 1/2 := by + dsimp [u] + dsimp [ε] at * + nlinarith only [mul_nonneg (show 0 ≤ (D:ℝ)+1 by positivity) hε.le,hsmall] + have hu1 : u ≤ 1/2 := by nlinarith only [hu',mul_nonneg (Nat.cast_nonneg D) hu] + have ha : 0 ≤ a := mul_nonneg (by positivity) (by linarith only [hu1]) + have ha1 : a ≤ 1 := by + dsimp [a] + have h1 : 1/(2:ℝ)^B ≤ 1 := (div_le_one (by positivity)).mpr hp + exact (mul_le_mul_of_nonneg_left (by linarith only [hu] : 1-u ≤ 1) (by positivity)).trans (by simpa using h1) + have hb : 1/2 ≤ (1-u)^D := by + have H := one_add_mul_le_pow (a := -u) (by linarith only [hu1]) D + have hd : (D:ℝ)*u ≤ 1/2 := by nlinarith only [hu',hu] + simpa only [sub_eq_add_neg] using (show (1:ℝ)/2 ≤ (1+-u)^D by nlinarith only [H,hd]) + have hc : (Finset.Ico i D).card ≤ D := by simp only [Nat.card_Ico]; omega + calc + _ = (1/(2:ℝ)^B)^D*(1/2) := by rw [div_pow,one_pow,←pow_mul]; field_simp + _ ≤ (1/(2:ℝ)^B)^D*(1-u)^D := mul_le_mul_of_nonneg_left hb (by positivity) + _ = a^D := (mul_pow _ _ _).symm + _ ≤ a^(Finset.Ico i D).card := pow_le_pow_of_le_one ha ha1 hc + _ = ∏j∈Finset.Ico i D,a := by simp + _ ≤ sourceScaleProduct B D i := by + apply Finset.prod_le_prod₀ (fun _ _ => ha) + intro j _ + apply scaleA_zero_lower _ _ _ _ hε.le + unfold sourceDimension + split_ifs <;> omega + +theorem sourceDepth_upper (B : ℕ) (ζ H : ℝ) (_hB : 2 ≤ B) + (hζ : ζ ≤ 1) (hH : 1 ≤ H) : + (sourceDepth B ζ H:ℝ) ≤ (1-ζ)*Real.log H/((B:ℝ)*Real.log 2) := by + apply Nat.floor_le + exact div_nonneg (mul_nonneg (sub_nonneg.mpr hζ) (Real.log_nonneg hH)) + (mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg (by norm_num))) + +theorem sourceDepth_power (B : ℕ) (ζ H : ℝ) (hB : 2 ≤ B) + (hζ : ζ ≤ 1) (hH : 1 ≤ H) : + (2:ℝ)^(B*sourceDepth B ζ H) ≤ H^(1-ζ) := by + have hden : 0 < (B:ℝ)*Real.log 2 := + mul_pos (by exact_mod_cast (show 0 < B by omega)) (Real.log_pos (by norm_num)) + have hd := (le_div_iff₀ hden).mp (sourceDepth_upper B ζ H hB hζ hH) + apply (Real.log_le_log_iff (by positivity) (Real.rpow_pos_of_pos (by linarith) _)).mp + rw [Real.log_pow,Real.log_rpow (by linarith : 0 < H)] + push_cast + nlinarith only [hd] + +/-- Source smallest-scale lower bound, with an absolute explicit factor. -/ +theorem sourceTargetScale_log_lower (B : ℕ) (ζ H n : ℝ) (i : ℕ) (hB : 2 ≤ B) + (hζ : ζ ≤ 1) (hH : 1 ≤ H) (hn : 1 < n) : + Real.log n/(2*H^(1-ζ)) ≤ Real.log (sourceTargetScale B (sourceDepth B ζ H) n i) := by + have hp := sourceDepth_power B ζ H hB hζ hH + have hs := sourceScaleProduct_lower B (sourceDepth B ζ H) i hB + have hfrac : 1/(2*H^(1-ζ)) ≤ 1/(2*(2:ℝ)^(B*sourceDepth B ζ H)) := + div_le_div_of_nonneg_left (by norm_num) (by positivity) (by linarith only [hp]) + have hh := mul_le_mul_of_nonneg_right (hfrac.trans hs) (Real.log_pos hn).le + unfold sourceTargetScale + rw [Real.log_rpow (by linarith)] + simpa only [div_eq_mul_inv,one_mul,mul_comm] using hh + +/-- Polynomial depth losses are negligible compared with the H-zeta gain. + This statement has no bounded-deletion-rate premise. -/ +theorem sourceDepth_polynomial_absorption (B h : ℕ) (ζ : ℝ) (hB : 2 ≤ B) + (hζ : ζ∈Set.Ioo 0 1) {H : ℕ → ℝ} (hH : Tendsto H atTop atTop) : + Tendsto (fun k => ((sourceDepth B ζ (H k):ℝ)+1)^h/(H k)^ζ) atTop (nhds 0) := by + let A := (1-ζ)/((B:ℝ)*Real.log 2)+1 + have hd : 0 < (B:ℝ)*Real.log 2 := + mul_pos (by exact_mod_cast (show 0 < B by omega)) (Real.log_pos (by norm_num)) + have hA : 0 < A := by dsimp [A]; positivity [sub_pos.mpr hζ.2] + have hl := (isLittleO_log_rpow_rpow_atTop (h:ℝ) hζ.1).tendsto_div_nhds_zero.comp hH + simp only [Real.rpow_natCast] at hl + have hx := hl.const_mul (A^h) + simp only [mul_zero] at hx + apply squeeze_zero' _ _ hx + · filter_upwards [hH.eventually_gt_atTop 0] with k hk + exact div_nonneg (by positivity) (Real.rpow_pos_of_pos hk _).le + · filter_upwards [hH.eventually_ge_atTop 1, + (Real.tendsto_log_atTop.comp hH).eventually_ge_atTop 1] with k hk hklog + have hD := sourceDepth_upper B ζ (H k) hB hζ.2.le hk + have hDa : (sourceDepth B ζ (H k):ℝ)+1 ≤ A*Real.log (H k) := by + dsimp [A] + change 1 ≤ Real.log (H k) at hklog + calc + _ ≤ (1-ζ)*Real.log (H k)/((B:ℝ)*Real.log 2)+Real.log (H k) := add_le_add hD hklog + _ = _ := by ring + have hh := pow_le_pow_left₀ (by positivity : 0 ≤ (sourceDepth B ζ (H k):ℝ)+1) hDa h + rw [mul_pow] at hh + exact (div_le_div_of_nonneg_right hh (by positivity)).trans_eq (by dsimp only [Function.comp_def]; ring) + +/-- Uniform quantitative scale margin. This is the source's Lambda*H^zeta + bound, before any little-o notation or parameter choices. -/ +theorem sourceTargetScale_epsilon_log_lower (B : ℕ) (ζ H n Λ : ℝ) (i : ℕ) + (hB : 2 ≤ B) (hζ : ζ ≤ 1) (hH : 1 ≤ H) (hn : 1 < n) + (hΛ : 0 < Λ) (hrel : Real.log n=Λ*H) : + Λ*H^ζ/(2*(2:ℝ)^(4*B+100)*((sourceDepth B ζ H:ℝ)+1)) ≤ + sourceEpsilon B (sourceDepth B ζ H)* + Real.log (sourceTargetScale B (sourceDepth B ζ H) n i) := by + have h := mul_le_mul_of_nonneg_left (sourceTargetScale_log_lower B ζ H n i hB hζ hH hn) + (sourceEpsilon_pos B (sourceDepth B ζ H)).le + apply le_trans _ h + rw [hrel,Real.rpow_sub (by linarith : 0 < H), Real.rpow_one] + unfold sourceEpsilon + have hH0 : H≠0 := by linarith + have hHz : H^ζ≠0 := (Real.rpow_pos_of_pos (by linarith : 0 < H) _).ne' + have hd : (sourceDepth B ζ H:ℝ)+1≠0 := by positivity + have hp : (2:ℝ)^(4*B+100)≠0 := by positivity + apply le_of_eq + field_simp + +theorem source_absorption_ratio_bound (B h : ℕ) (ζ H n Λ : ℝ) (i : ℕ) + (hB : 2 ≤ B) (hζ : ζ ≤ 1) (hH : 1 ≤ H) (hn : 1 < n) + (hΛ : 0 < Λ) (hrel : Real.log n=Λ*H) : + ((sourceDepth B ζ H:ℝ)+1)^h*Λ / + (sourceEpsilon B (sourceDepth B ζ H)* + Real.log (sourceTargetScale B (sourceDepth B ζ H) n i)) ≤ + (2*(2:ℝ)^(4*B+100))*(((sourceDepth B ζ H:ℝ)+1)^(h+1)/H^ζ) := by + have hHz : 0 < H^ζ := Real.rpow_pos_of_pos (by linarith) _ + have hlow := sourceTargetScale_epsilon_log_lower B ζ H n Λ i hB hζ hH hn hΛ hrel + have hh := div_le_div_of_nonneg_left + (by positivity : 0 ≤ ((sourceDepth B ζ H:ℝ)+1)^h*Λ) + (by positivity : 0 < Λ*H^ζ/(2*(2:ℝ)^(4*B+100)*((sourceDepth B ζ H:ℝ)+1))) hlow + apply hh.trans_eq + rw [pow_succ] + field_simp; ring + +/-- Joint-regime uniform absorption at the genuine backwards scales, + with an arbitrary index choice and with the channel unchanged across scales. -/ +theorem source_uniform_absorption (B h : ℕ) (ζ : ℝ) (hB : 2 ≤ B) (hζ : ζ∈Set.Ioo 0 1) + {n Λ H : ℕ → ℝ} (i : ℕ → ℕ) (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) + (hΛ : ∀k,0 < Λ k) (hrel : ∀k,Real.log (n k)=Λ k*H k) : + Tendsto (fun k => ((sourceDepth B ζ (H k):ℝ)+1)^h*Λ k / + (sourceEpsilon B (sourceDepth B ζ (H k))* + Real.log (sourceTargetScale B (sourceDepth B ζ (H k)) (n k) (i k)))) atTop (nhds 0) := by + have hb := (sourceDepth_polynomial_absorption B (h+1) ζ hB hζ hH).const_mul + (2*(2:ℝ)^(4*B+100)) + simp only [mul_zero] at hb + apply squeeze_zero' _ _ hb + · filter_upwards [hH.eventually_ge_atTop 1,hn.eventually_gt_atTop 1] with k hk hnk + have hh := sourceTargetScale_epsilon_log_lower B ζ (H k) (n k) (Λ k) (i k) + hB hζ.2.le hk hnk (hΛ k) (hrel k) + have hΛk := hΛ k + have hHk : 0 < H k := by linarith + exact div_nonneg (by positivity) ((by positivity : + 0 ≤ Λ k*(H k)^ζ/(2*(2:ℝ)^(4*B+100)*((sourceDepth B ζ (H k):ℝ)+1))).trans hh) + · filter_upwards [hH.eventually_ge_atTop 1,hn.eventually_gt_atTop 1] with k hk hnk + exact source_absorption_ratio_bound B h ζ (H k) (n k) (Λ k) (i k) + hB hζ.2.le hk hnk (hΛ k) (hrel k) + +theorem source_uniform_exp_absorption (B h : ℕ) (ζ C δ : ℝ) (hB : 2 ≤ B) + (hζ : ζ∈Set.Ioo 0 1) (hC : 0 ≤ C) (hδ : 0 < δ) + {n Λ H : ℕ → ℝ} (hn : Tendsto n atTop atTop) (hH : Tendsto H atTop atTop) + (hΛ : ∀k,0 < Λ k) (hrel : ∀k,Real.log (n k)=Λ k*H k) : + ∀ᶠk in atTop,∀i, + Real.exp (C*((sourceDepth B ζ (H k):ℝ)+1)^h*Λ k) ≤ + (sourceTargetScale B (sourceDepth B ζ (H k)) (n k) i)^ + (δ*sourceEpsilon B (sourceDepth B ζ (H k))) := by + have hb := (sourceDepth_polynomial_absorption B (h+1) ζ hB hζ hH).const_mul + (C*(2*(2:ℝ)^(4*B+100))) + simp only [mul_zero] at hb + filter_upwards [hH.eventually_ge_atTop 1,hn.eventually_gt_atTop 1, + hb.eventually_lt_const hδ] with k hk hnk hbound + intro i + have hratio := source_absorption_ratio_bound B h ζ (H k) (n k) (Λ k) i + hB hζ.2.le hk hnk (hΛ k) (hrel k) + have hlower := sourceTargetScale_epsilon_log_lower B ζ (H k) (n k) (Λ k) i + hB hζ.2.le hk hnk (hΛ k) (hrel k) + have hΛk := hΛ k + have hHk : 0 < H k := by linarith + have hden : 0 < sourceEpsilon B (sourceDepth B ζ (H k))* + Real.log (sourceTargetScale B (sourceDepth B ζ (H k)) (n k) i) := + lt_of_lt_of_le (by positivity) hlower + have hMul := mul_le_mul_of_nonneg_left hratio hC + have H' : C*(((sourceDepth B ζ (H k):ℝ)+1)^h*Λ k)/ + (sourceEpsilon B (sourceDepth B ζ (H k))* + Real.log (sourceTargetScale B (sourceDepth B ζ (H k)) (n k) i)) ≤ δ := by + calc + _ = C*(((sourceDepth B ζ (H k):ℝ)+1)^h*Λ k / + (sourceEpsilon B (sourceDepth B ζ (H k))* + Real.log (sourceTargetScale B (sourceDepth B ζ (H k)) (n k) i))) := by ring + _ ≤ _ := hMul.trans (by simpa only [mul_assoc] using hbound.le) + have HH := (div_le_iff₀ hden).mp H' + have hN : 0 < sourceTargetScale B (sourceDepth B ζ (H k)) (n k) i := + Real.rpow_pos_of_pos (by linarith) _ + rw [Real.rpow_def_of_pos hN] + exact Real.exp_le_exp.mpr (by nlinarith only [HH]) + +/-- Direct instantiation with the manuscript's known deletion rate: Lambda + is q^{-3}, H=q^3 log n, never recomputed at an intermediate scale. -/ +theorem source_deletion_uniform_absorption (B h : ℕ) (ζ : ℝ) (hB : 2 ≤ B) + (hζ : ζ∈Set.Ioo 0 1) {n q : ℕ → ℝ} (i : ℕ → ℕ) + (hq : ∀k,0 < q k) (hn : Tendsto n atTop atTop) + (hH : Tendsto (fun k => (q k)^3*Real.log (n k)) atTop atTop) : + Tendsto (fun k => + ((sourceDepth B ζ ((q k)^3*Real.log (n k)):ℝ)+1)^h*(q k)^(-3:ℤ) / + (sourceEpsilon B (sourceDepth B ζ ((q k)^3*Real.log (n k)))* + Real.log (sourceTargetScale B (sourceDepth B ζ ((q k)^3*Real.log (n k))) + (n k) (i k)))) atTop (nhds 0) := by + apply source_uniform_absorption B h ζ hB hζ i hn hH + · intro k + exact zpow_pos (hq k) _ + · intro k + simp only [zpow_neg,zpow_ofNat] + field_simp [(hq k).ne'] + +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open Filter +open scoped Topology + +/-- Logarithmic order along a genuine diverging positive scale. -/ +def PowerRate (N f : ℕ → ℝ) (a : ℝ) : Prop := + (∀ᶠ t in Filter.atTop, 0 < f t) ∧ Tendsto (fun t => Real.log (f t) / Real.log (N t)) Filter.atTop (𝓝 a) + +/-- A robust upper order, with arbitrary strictly positive exponent slack. -/ +def PowerUpper (N f : ℕ → ℝ) (a : ℝ) : Prop := + ∀ b, a < b → ∀ᶠ t in Filter.atTop, |f t| ≤ (N t)^b + +variable {N f g : ℕ → ℝ} {a b : ℝ} + +theorem PowerRate.congr (h : PowerRate N f a) (he : f =ᶠ[Filter.atTop] g) : PowerRate N g a := by + constructor + · filter_upwards [h.1,he] with t ht he; simpa [←he] using ht + · exact h.2.congr' (he.mono fun t ht => by simp [ht]) + +theorem PowerRate.const (hN : Tendsto N Filter.atTop Filter.atTop) {c : ℝ} (hc : 0 c) 0 := by + exact ⟨Eventually.of_forall (fun _ => hc), (Real.tendsto_log_atTop.comp hN).const_div_atTop _⟩ + +theorem PowerRate.base (hN : Tendsto N Filter.atTop Filter.atTop) : PowerRate N N 1 := by + have hn := hN.eventually_gt_atTop 1 + refine ⟨hn.mono fun _ h => by linarith, ?_⟩ + apply tendsto_congr' _ |>.mpr tendsto_const_nhds + filter_upwards [hn] with t ht + exact div_self (ne_of_gt (Real.log_pos ht)) + +theorem PowerRate.mul (hf : PowerRate N f a) (hg : PowerRate N g b) : + PowerRate N (fun t => f t*g t) (a+b) := by + refine ⟨by filter_upwards [hf.1,hg.1] with t h ht; positivity, ?_⟩ + apply (hf.2.add hg.2).congr' + filter_upwards [hf.1,hg.1] with t h ht + rw [Real.log_mul h.ne' ht.ne',add_div] + +theorem PowerRate.div (hf : PowerRate N f a) (hg : PowerRate N g b) : + PowerRate N (fun t => f t/g t) (a-b) := by + refine ⟨by filter_upwards [hf.1,hg.1] with t h ht; positivity, ?_⟩ + apply (hf.2.sub hg.2).congr' + filter_upwards [hf.1,hg.1] with t h ht + rw [Real.log_div h.ne' ht.ne',sub_div] + +theorem PowerRate.rpow (hf : PowerRate N f a) (c : ℝ) : + PowerRate N (fun t => (f t)^c) (a*c) := by + refine ⟨by filter_upwards [hf.1] with t h; positivity, ?_⟩ + apply (hf.2.mul_const c).congr' + filter_upwards [hf.1] with t h + rw [Real.log_rpow h] + ring + +theorem PowerRate.pow (hf : PowerRate N f a) (c : ℕ) : + PowerRate N (fun t => (f t)^c) (a*c) := by + simpa only [Real.rpow_natCast] using hf.rpow (c:ℝ) + +theorem PowerRate.sqrt (hf : PowerRate N f a) : + PowerRate N (fun t => Real.sqrt (f t)) (a/2) := by + simpa only [Real.sqrt_eq_rpow,div_eq_mul_inv, one_mul] using hf.rpow (1/2:ℝ) + +theorem PowerRate.inv (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) : + PowerRate N (fun t=>(f t)⁻¹) (-a) := by + simpa only [one_div,zero_sub] using (PowerRate.const hN (by norm_num : (0:ℝ)<1)).div hf + +theorem PowerRate.const_mul (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) + {c : ℝ} (hc : 0c*f t) a := by + simpa only [zero_add] using (PowerRate.const hN hc).mul hf + +theorem PowerRate.mul_const (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) + {c : ℝ} (hc : 0f t*c) a := by + simpa only [add_zero] using hf.mul (PowerRate.const hN hc) + +theorem PowerRate.div_const (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) + {c : ℝ} (hc : 0f t/c) a := by + simpa only [sub_zero] using hf.div (PowerRate.const hN hc) + +theorem PowerRate.upper (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) : + PowerUpper N f a := by + intro b hb + filter_upwards [hN.eventually_gt_atTop 1,hf.1,hf.2.eventually_lt_const hb] with t hn hp hab + rw [abs_of_pos hp,←Real.log_le_log_iff hp (Real.rpow_pos_of_pos (by linarith) b),Real.log_rpow (by linarith : 0.le + +theorem PowerRate.lower (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) {c : ℝ} + (hc : c.le + +theorem PowerRate.tendsto_atTop (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) (ha : 0 hf c (lt_of_le_of_lt hab hc) + +theorem PowerUpper.congr (hf : PowerUpper N f a) (he : f =ᶠ[Filter.atTop] g) : PowerUpper N g a := by + intro b hb + filter_upwards [hf b hb,he] with t h he + simpa [←he] using h + +theorem PowerUpper.of_abs_le (hg : PowerUpper N g a) (h : ∀ᶠ t in Filter.atTop, |f t|≤|g t|) : + PowerUpper N f a := by + intro b hb + filter_upwards [hg b hb,h] with t ht hh + exact hh.trans ht + +theorem PowerUpper.zero (hN : Tendsto N Filter.atTop Filter.atTop) (a : ℝ) : PowerUpper N (fun _=>0) a := by + intro b hb + filter_upwards [hN.eventually_gt_atTop 0] with t ht + simpa using (Real.rpow_pos_of_pos ht b).le + +theorem PowerUpper.mul (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerUpper N f a) + (hg : PowerUpper N g b) : PowerUpper N (fun t=>f t*g t) (a+b) := by + intro c hc + let δ := (c-(a+b))/2 + have hd : 0<δ := by dsimp [δ]; linarith + filter_upwards [hN.eventually_gt_atTop 0,hf (a+δ) (by linarith),hg (b+δ) (by linarith)] with t hn ht hs + calc |f t*g t|=|f t| * |g t| := abs_mul _ _ + _ ≤ (N t)^(a+δ)*(N t)^(b+δ) := mul_le_mul ht hs (abs_nonneg _) (by positivity) + _ = (N t)^c := by rw [←Real.rpow_add hn]; congr 1; dsimp [δ]; ring + +theorem PowerUpper.pow (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerUpper N f a) + (r : ℕ) : PowerUpper N (fun t=>(f t)^r) (a*r) := by + induction r with + | zero => simpa using (PowerRate.const hN (by norm_num : (0:ℝ)<1)).upper hN + | succ r ih => + have H := ih.mul hN hf + convert H using 1 + · ext t; exact pow_succ _ _ + · push_cast; ring + +theorem PowerUpper.add (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerUpper N f a) + (hg : PowerUpper N g a) : PowerUpper N (fun t=>f t+g t) a := by + intro c hc + let d := (a+c)/2 + have had : a∑i∈S,f i t) a := by + classical + induction S using Finset.induction_on with + | empty => simpa using PowerUpper.zero hN a + | @insert i S hi ih => + have hh := (h i (Finset.mem_insert_self _ _)).add hN + (ih (fun j hj=>h j (Finset.mem_insert_of_mem hj))) + simpa only [Finset.sum_insert hi] using hh + +theorem PowerRate.add_const (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) + (ha : 0f t+c) a := by + have ht := hf.tendsto_atTop hN ha + have hratio : Tendsto (fun t=>1+c/f t) Filter.atTop (𝓝 1) := by + simpa using (tendsto_const_nhds.add (ht.const_div_atTop c)) + have hl : Tendsto (fun t=>Real.log (1+c/f t)/Real.log (N t)) Filter.atTop (𝓝 0) := + (hratio.log one_ne_zero).div_atTop (Real.tendsto_log_atTop.comp hN) + refine ⟨by filter_upwards [hf.1] with t h; positivity, ?_⟩ + have H := hf.2.add hl + simp only [add_zero] at H + apply H.congr' + filter_upwards [hf.1] with t hp + have hh : 0<1+c/f t := by positivity + rw [←add_div,←Real.log_mul hp.ne' hh.ne'] + congr 2 + field_simp + +theorem PowerRate.of_tendsto (hN : Tendsto N Filter.atTop Filter.atTop) + {c : ℝ} (hc : 0g t/f t) Filter.atTop (𝓝 c)) : PowerRate N g a := by + have hp : ∀ᶠ t in Filter.atTop, 0.1 + refine ⟨hp,?_⟩ + have hh := (hr.log hc.ne').div_atTop (Real.tendsto_log_atTop.comp hN) + have H := hf.2.add hh + simp only [add_zero] at H + apply H.congr' + filter_upwards [hf.1,hp] with t hf hg + simp only [Function.comp_apply] + rw [Real.log_div hg.ne' hf.ne'] + ring + +theorem PowerRate.nat_floor (hN : Tendsto N Filter.atTop Filter.atTop) (hf : PowerRate N f a) + (ha : 0(⌊f t⌋₊:ℝ)) a := by + exact hf.of_ratio hN (by norm_num : (0:ℝ)<1) + (tendsto_nat_floor_div_atTop.comp (hf.tendsto_atTop hN ha)) + +theorem PowerRate.exp_neg_upper (hN : Tendsto N Filter.atTop Filter.atTop) + (hf : PowerRate N f a) (ha : 0Real.exp (-f t)) c := by + intro b hb + have hh := ((isLittleO_log_rpow_atTop (show 0 N ≤ 3*u.val ∧ 3*u.val ≤ 2*N) - -/-- One actual global-pair orientation, ordered by its pre-region block and -its local identifier there. -/ -def globalTrialIndex (N t : ℕ) (v : Fin (N/4)) (a : Fin t) : Fin ((N/4)*t) := - ⟨v.val*t+a.val, by nlinarith [v.isLt,a.isLt]⟩ - -/-- Literal net global displacement immediately before a child window: -a pre block at v+1 remains active through its matched post region N-v. -The paired displacement has even t trials in each affected region. -/ -def scheduledGlobalShift (N t : ℕ) (bits : Fin ((N/4)*t) → Bool) (u : Fin N) : ℤ := - ∑v : Fin (N/4), if v.val ≤ u.val ∧ u.val+v.val globalTrialIndex N t x.1 x.2) := by - constructor - · intro x y he - have he' := congrArg Fin.val he - change x.1.val*t+x.2.val = y.1.val*t+y.2.val at he' - have hx := x.2.isLt - have hy := y.2.isLt - have hv : x.1.val=y.1.val := by - by_contra h - rcases lt_or_gt_of_ne h with h | h <;> nlinarith - have ha : x.2.val=y.2.val := by rw [hv] at he'; omega - exact Prod.ext (Fin.ext hv) (Fin.ext ha) - · intro i - have ht : 0 (bitIndex (bits i):ℤ)) - · simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - _ = _ := by congr 1; exact_mod_cast hh.symm - - -/-- The actual complete-tree global schedule has the exact plateau identity -needed by the already proved correlated anchor energy theorem. -/ -def sourceGlobalTrials (T t : ℕ → ℕ) (b : ℕ) : ℕ := (T b/4)*t b - -def sourceGlobalShift (T t : ℕ → ℕ) (b : ℕ) - (bits : Fin (sourceGlobalTrials T t b) → Bool) (u : Fin (T b)) : ℤ := - scheduledGlobalShift (T b) (t b) bits u - -theorem sourceGlobalShift_hasPlateau (T t : ℕ → ℕ) (ht : ∀b,Even (t b)) : - HasGlobalPlateau T (sourceGlobalTrials T t) (fun b => centralThird (T b)) - (fun b => (sourceGlobalTrials T t b/2:ℕ)) (sourceGlobalShift T t) := by - intro b bits u hu - exact scheduledGlobalShift_plateau (T b) (t b) (ht b) bits u hu -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -/-- One actual child-label coordinate of an arbitrary ordered occupied -shape. Unlike a complete r-ary padding, this contains no unused edges. -/ -def Edge : {b : ℕ} → OccupiedParityTree b → Type - | _, .leaf => PEmpty - | _, .node n children _ => Fin n ⊕ ((i : Fin n) × Edge (children i)) - -noncomputable instance edgeFintype : {b : ℕ} → (t : OccupiedParityTree b) → Fintype t.Edge - | _, .leaf => inferInstanceAs (Fintype PEmpty) - | _, .node n children roles => by - letI := fun i => edgeFintype (children i) - exact inferInstanceAs (Fintype (Fin n ⊕ ((i : Fin n) × Edge (children i)))) - -def Edge.height : {b : ℕ} → {t : OccupiedParityTree b} → t.Edge → ℕ - | _, .leaf, e => e.elim - | _, @OccupiedParityTree.node b _n _children _roles, e => - match e with - | Sum.inl _ => b - | Sum.inr z => Edge.height z.2 - -/-- All literal label assignments to this particular ordered shape. -/ -def Labels (T : ℕ → ℕ) {b : ℕ} (t : OccupiedParityTree b) := - (e : t.Edge) → Fin (T e.height) - -noncomputable instance labelsFintype (T : ℕ → ℕ) {b : ℕ} (t : OccupiedParityTree b) : - Fintype (t.Labels T) := inferInstanceAs (Fintype ((e : t.Edge) → Fin (T e.height))) - -def Labels.child (T : ℕ → ℕ) {b n : ℕ} {children : Fin n → OccupiedParityTree b} - {roles : Fin n → Fin 3} (x : (OccupiedParityTree.node n children roles).Labels T) - (i : Fin n) : (children i).Labels T := fun e => x (Sum.inr ⟨i,e⟩) - -/-- Projection to the actual labels of a fixed forced subtree. The shape -selection is independent of these labels and of all random orientations. -/ -def Forced.labels (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → - t.Forced → t.Labels T → BinaryWindowLabels T b - | _, _, .leaf, _ => PUnit.unit - | _, _, .node a c _ _ _ left right, x => - (x (Sum.inl a),x (Sum.inl c),left.labels T (x.child T a),right.labels T (x.child T c)) - -/-- Edge addresses in a complete binary tree, independent of all actual -numeric labels. False and true are its two children. -/ -def BinaryEdge : ℕ → Type - | 0 => PEmpty - | b+1 => Bool ⊕ (Bool × BinaryEdge b) - -noncomputable instance binaryEdgeFintype : (b : ℕ) → Fintype (BinaryEdge b) - | 0 => inferInstanceAs (Fintype PEmpty) - | b+1 => by - letI := binaryEdgeFintype b - exact inferInstanceAs (Fintype (Bool ⊕ (Bool × BinaryEdge b))) - -def BinaryEdge.height : {b : ℕ} → BinaryEdge b → ℕ - | 0, e => e.elim - | b+1, Sum.inl _ => b - | _b+1, Sum.inr e => BinaryEdge.height e.2 - -/-- The forced binary tree is embedded in the actual occupied edge set. -/ -def Forced.edge : {b : ℕ} → {t : OccupiedParityTree b} → t.Forced → BinaryEdge b → t.Edge - | _, _, .leaf, e => e.elim - | _, _, .node a _ _ _ _ _ _, Sum.inl false => Sum.inl a - | _, _, .node _ c _ _ _ _ _, Sum.inl true => Sum.inl c - | _, _, .node a _ _ _ _ left _, Sum.inr (false,e) => Sum.inr ⟨a,left.edge e⟩ - | _, _, .node _ c _ _ _ _ right, Sum.inr (true,e) => Sum.inr ⟨c,right.edge e⟩ - -theorem Forced.edge_injective {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - Function.Injective F.edge := by - induction F with - | leaf => intro i; exact i.elim - | @node b n children roles a c hne ha hc left right ihl ihr => - intro i j he - cases i with - | inl i => - cases j with - | inl j => - cases i <;> cases j - · rfl - · exact (hne (Sum.inl.inj he)).elim - · exact (hne (Sum.inl.inj he).symm).elim - · rfl - | inr j => cases i <;> rcases j with ⟨j,e⟩ <;> cases j <;> cases he - | inr i => - cases j with - | inl j => rcases i with ⟨i,e⟩; cases i <;> cases j <;> cases he - | inr j => - rcases i with ⟨i,e⟩ - rcases j with ⟨j,f⟩ - cases i <;> cases j - · have hh := Sum.inr.inj he - have hh' : left.edge e=left.edge f := by injection hh - exact congrArg (fun e => Sum.inr (false,e)) (ihl hh') - · have hh := congrArg Sigma.fst (Sum.inr.inj he) - exact (hne hh).elim - · have hh := congrArg Sigma.fst (Sum.inr.inj he) - exact (hne hh.symm).elim - · have hh := Sum.inr.inj he - have hh' : right.edge e=right.edge f := by injection hh - exact congrArg (fun e => Sum.inr (true,e)) (ihr hh') - -theorem Forced.edge_height {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (e : BinaryEdge b) : (F.edge e).height=e.height := by - induction F with - | leaf => exact e.elim - | @node b n children roles a c hne ha hc left right ihl ihr => - cases e with - | inl i => cases i <;> rfl - | inr z => rcases z with ⟨i,e⟩; cases i; exact ihl e; exact ihr e - -/-- The finite number of edge coordinates at a given child height. -/ -def edgeCount {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) : ℕ := - Fintype.card {e : t.Edge // e.height=h} - -theorem edgeCount_leaf (h : ℕ) : edgeCount OccupiedParityTree.leaf h=0 := by - unfold edgeCount - exact Fintype.card_eq_zero_iff.mpr ⟨fun e => e.val.elim⟩ - -theorem edgeCount_node {b n : ℕ} (children : Fin n → OccupiedParityTree b) - (roles : Fin n → Fin 3) (h : ℕ) : - edgeCount (.node n children roles) h = (if b=h then n else 0)+∑i,edgeCount (children i) h := by - unfold edgeCount - simp only [Fintype.card_subtype, Finset.card_filter] - change (∑e : Fin n ⊕ ((i : Fin n) × (children i).Edge),if Edge.height (t := .node n children roles) e=h then 1 else 0)=_ - rw [Fintype.sum_sum_type] - simp only [Edge.height,Fintype.sum_sigma] - - split_ifs <;> simp_all <;> simp only [Finset.card_filter] <;> rfl - -theorem Edge.height_lt {b : ℕ} {t : OccupiedParityTree b} (e : t.Edge) : e.height exact e.elim - | @node b n children roles ih => - cases e with - | inl i => exact Nat.lt_succ_self b - | inr z => exact Nat.lt_succ_of_lt (ih z.1 z.2) - -theorem edgeCount_outside {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) (hh : b≤h) : - t.edgeCount h=0 := by - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun e => ?_⟩ - have hc := e.val.height_lt - rw [e.property] at hc - omega - -theorem edgeCount_level {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) (hh : h omega - | @node b n children roles ih => - rw [edgeCount_node] - by_cases he : h=b - · subst h - have hz (i : Fin n) := edgeCount_outside (children i) b le_rfl - simp only [hz,Finset.sum_const_zero,add_zero,Nat.add_sub_cancel_left, - levelCount,Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one] - rfl - · have hh' : h ih i hh') - -def BinaryEdgeLabels (T : ℕ → ℕ) (b : ℕ) := (e : BinaryEdge b) → Fin (T e.height) - -noncomputable instance binaryEdgeLabelsFintype (T : ℕ → ℕ) (b : ℕ) : - Fintype (BinaryEdgeLabels T b) := inferInstanceAs (Fintype ((e : BinaryEdge b) → Fin (T e.height))) - -/-- Exact coordinates of the recursively defined forced label tuple. -/ -def binaryLabelsEquiv (T : ℕ → ℕ) : (b : ℕ) → BinaryEdgeLabels T b ≃ BinaryWindowLabels T b - | 0 => - { toFun := fun _ => PUnit.unit - invFun := fun _ e => e.elim - left_inv := fun _ => by funext e; exact e.elim - right_inv := fun y => by cases y; rfl } - | b+1 => - { toFun := fun x => (x (Sum.inl false),x (Sum.inl true), - binaryLabelsEquiv T b (fun e => x (Sum.inr (false,e))), - binaryLabelsEquiv T b (fun e => x (Sum.inr (true,e)))) - invFun := fun x e => match e with - | Sum.inl false => x.1 - | Sum.inl true => x.2.1 - | Sum.inr (false,e) => (binaryLabelsEquiv T b).symm x.2.2.1 e - | Sum.inr (true,e) => (binaryLabelsEquiv T b).symm x.2.2.2 e - left_inv := fun x => by - funext e - cases e with - | inl j => cases j <;> rfl - | inr z => - rcases z with ⟨j,e⟩ - cases j <;> exact congrFun ((binaryLabelsEquiv T b).symm_apply_apply _) e - right_inv := fun x => by - rcases x with ⟨a,c,l,r⟩ - simp only [Equiv.apply_symm_apply] - rfl } - -/-- Restriction to the real forced coordinates, with only equality transport -of the child-height index. -/ -def Forced.restrict (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (x : t.Labels T) : BinaryEdgeLabels T b := fun e => - Fin.cast (congrArg T (F.edge_height e)) (x (F.edge e)) - -theorem Forced.restrict_labels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (x : t.Labels T) : binaryLabelsEquiv T b (F.restrict T x)=F.labels T x := by - induction F with - | leaf => rfl - | @node b n children roles a c hne ha hc left right ihl ihr => - change (x (Sum.inl a),x (Sum.inl c),_,_) = (x (Sum.inl a),x (Sum.inl c),_,_) - refine Prod.ext rfl (Prod.ext rfl (Prod.ext ?_ ?_)) - · exact ihl (x.child T a) - · exact ihr (x.child T c) - -end OccupiedParityTree -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -def Forced.ExtraEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := - {e : t.Edge // e∉Set.range F.edge} - -noncomputable instance forcedExtraEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - Fintype F.ExtraEdge := inferInstanceAs (Fintype {e : t.Edge // e∉Set.range F.edge}) - -def Forced.ExtraLabels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := - (e : F.ExtraEdge) → Fin (T e.val.height) - -noncomputable instance forcedExtraLabelsFintype (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) : Fintype (F.ExtraLabels T) := - inferInstanceAs (Fintype ((e : F.ExtraEdge) → Fin (T e.val.height))) - -/-- Exact bijective partition of all actual edge coordinates into the -forced binary coordinates and the genuine extra coordinates. -/ -noncomputable def Forced.labelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - t.Labels T ≃ BinaryWindowLabels T b × F.ExtraLabels T := by - classical - letI : DecidablePred (Set.range F.edge) := fun _ => Classical.propDecidable _ - exact (Equiv.piEquivPiSubtypeProd (Set.range F.edge) (fun e : t.Edge => Fin (T e.height))).trans - (Equiv.prodCongr - (((Equiv.piCongrLeft (fun e : Set.range F.edge => Fin (T e.val.height)) - (Equiv.ofInjective F.edge F.edge_injective)).symm.trans - (Equiv.piCongrRight fun e => finCongr (congrArg T (F.edge_height e)))).trans - (binaryLabelsEquiv T b)) - (Equiv.refl _)) - -theorem Forced.labelsEquiv_fst (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (x : t.Labels T) : (F.labelsEquiv T x).1=F.labels T x := by - exact F.restrict_labels T x - -theorem Forced.labelsEquiv_snd (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (x : t.Labels T) : (F.labelsEquiv T x).2=(fun e : F.ExtraEdge => x e.val) := rfl - -/-- Literal finite Fubini over forced labels and all remaining labels. -/ -theorem Forced.sum_labels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (f : BinaryWindowLabels T b → F.ExtraLabels T → ℝ) : - (∑x : t.Labels T,f (F.labels T x) (fun e => x e.val)) = - ∑p : BinaryWindowLabels T b, ∑z : F.ExtraLabels T,f p z := by - have h := (F.labelsEquiv T).sum_comp (fun x => f x.1 x.2) - simpa only [Forced.labelsEquiv_fst,Forced.labelsEquiv_snd,Fintype.sum_prod_type] using h - -def Forced.ExtraLeafEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := - {e : F.ExtraEdge // e.val.height=0} - -def Forced.ExtraInteriorEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := - {e : F.ExtraEdge // e.val.height≠0} - -noncomputable instance extraLeafEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - Fintype F.ExtraLeafEdge := inferInstanceAs (Fintype {e : F.ExtraEdge // e.val.height=0}) - -noncomputable instance extraInteriorEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - Fintype F.ExtraInteriorEdge := inferInstanceAs (Fintype {e : F.ExtraEdge // e.val.height≠0}) - -def Forced.InteriorLabels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := - (e : F.ExtraInteriorEdge) → Fin (T e.val.val.height) - -noncomputable instance extraInteriorLabelsFintype (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) : Fintype (F.InteriorLabels T) := - inferInstanceAs (Fintype ((e : F.ExtraInteriorEdge) → Fin (T e.val.val.height))) - -/-- Extra bottom labels are separated from all nonleaf labels without -introducing any T₁ factor. -/ -noncomputable def Forced.extraLabelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) : F.ExtraLabels T ≃ (F.ExtraLeafEdge → Fin (T 0)) × F.InteriorLabels T := - (Equiv.piEquivPiSubtypeProd (fun e : F.ExtraEdge => e.val.height=0) - (fun e : F.ExtraEdge => Fin (T e.val.height))).trans - (Equiv.prodCongr (Equiv.piCongrRight fun e => finCongr (congrArg T e.property)) (Equiv.refl _)) - -end OccupiedParityTree -end TraceReconstruction -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -/-- The parent address of an edge in the full deterministic numerical index -tree. In particular it does not contain the edge's own child label. -/ -def Edge.parentPath (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → - t.Labels T → t.Edge → List ℕ - | _, .leaf, _, e => e.elim - | _, .node _n _children _roles, x, e => match e with - | Sum.inl _ => [] - | Sum.inr z => (x (Sum.inl z.1)).val :: Edge.parentPath T (x.child T z.1) z.2 - -/-- Every ancestor label of an extra selected leaf is an interior label. -/ -theorem Edge.parentPath_congr (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (x y : t.Labels T) (h : ∀e : t.Edge, e.height≠0 → (x e).val=(y e).val) - (e : t.Edge) : e.parentPath T x=e.parentPath T y := by - induction t with - | leaf => exact e.elim - | @node b n children roles ih => - cases e with - | inl i => rfl - | inr z => - have hb : b≠0 := by have := z.2.height_lt; omega - change (x (Sum.inl z.1)).val :: _ = (y (Sum.inl z.1)).val :: _ - congr 1 - · exact h (Sum.inl z.1) hb - · exact ih z.1 (x.child T z.1) (y.child T z.1) - (fun e he => h (Sum.inr ⟨z.1,e⟩) he) z.2 - -theorem Forced.labels_value_eq (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (x y : t.Labels T) (h : F.labels T x=F.labels T y) (j : BinaryEdge b) : - (x (F.edge j)).val=(y (F.edge j)).val := by - have hh := (binaryLabelsEquiv T b).injective - ((F.restrict_labels T x).trans (h.trans (F.restrict_labels T y).symm)) - exact congrArg (fun z : BinaryEdgeLabels T b => (z j).val) hh - -/-- The combined exact split into forced, extra-leaf and extra-interior labels. -/ -noncomputable def Forced.fullLabelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) : t.Labels T ≃ - BinaryWindowLabels T b × (F.ExtraLeafEdge → Fin (T 0)) × F.InteriorLabels T := - (F.labelsEquiv T).trans (Equiv.prodCongr (Equiv.refl _) (F.extraLabelsEquiv T)) - -theorem Forced.fullLabelsEquiv_fst (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (x : t.Labels T) : (F.fullLabelsEquiv T x).1=F.labels T x := - F.labelsEquiv_fst T x - -theorem Forced.fullLabelsEquiv_leaf_value (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (x : t.Labels T) (e : F.ExtraLeafEdge) : - ((F.fullLabelsEquiv T x).2.1 e).val=(x e.val.val).val := rfl - -theorem Forced.fullLabelsEquiv_interior_value (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (x : t.Labels T) (e : F.ExtraInteriorEdge) : - ((F.fullLabelsEquiv T x).2.2 e).val=(x e.val.val).val := rfl - -/-- Changing only extra leaf labels changes no ancestor address, even when -all the complete-tree mechanisms share their source global bits. -/ -theorem Forced.parentPath_extraLeaf_invariant (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} - (F : t.Forced) (p : BinaryWindowLabels T b) (h k : F.ExtraLeafEdge → Fin (T 0)) - (z : F.InteriorLabels T) (e : t.Edge) : - e.parentPath T ((F.fullLabelsEquiv T).symm (p,h,z)) = - e.parentPath T ((F.fullLabelsEquiv T).symm (p,k,z)) := by - let x := (F.fullLabelsEquiv T).symm (p,h,z) - let y := (F.fullLabelsEquiv T).symm (p,k,z) - have hx : F.fullLabelsEquiv T x=(p,h,z) := Equiv.apply_symm_apply _ _ - have hy : F.fullLabelsEquiv T y=(p,k,z) := Equiv.apply_symm_apply _ _ - have hp : F.labels T x=F.labels T y := by - rw [←F.fullLabelsEquiv_fst,←F.fullLabelsEquiv_fst,hx,hy] - apply Edge.parentPath_congr T x y - intro i hi - by_cases hr : i∈Set.range F.edge - · obtain ⟨j,rfl⟩ := hr - exact F.labels_value_eq T x y hp j - · let j : F.ExtraInteriorEdge := ⟨⟨i,hr⟩,hi⟩ - have hvx := congrArg (fun a => (a.2.2 j).val) hx - have hvy := congrArg (fun a => (a.2.2 j).val) hy - have hv := hvx.trans hvy.symm - simpa only [Forced.fullLabelsEquiv_interior_value] using hv - -end OccupiedParityTree -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -/-- A finite ordered-role shape code with at most r children at every -vertex. There are no numerical child labels in this type. -/ -def FiniteRoleShape (r : ℕ) : ℕ → Type - | 0 => PUnit - | b+1 => (n : Fin (r+1)) × (Fin n.val → FiniteRoleShape r b) × (Fin n.val → Fin 3) - -noncomputable instance finiteRoleShapeFintype (r : ℕ) : (b : ℕ) → Fintype (FiniteRoleShape r b) - | 0 => inferInstanceAs (Fintype PUnit) - | b+1 => by - letI := finiteRoleShapeFintype r b - exact inferInstanceAs (Fintype ((n : Fin (r+1)) × - (Fin n.val → FiniteRoleShape r b) × (Fin n.val → Fin 3))) - -def FiniteRoleShape.toTree (r : ℕ) : (b : ℕ) → FiniteRoleShape r b → OccupiedParityTree b - | 0, _ => .leaf - | b+1, x => .node x.1.val (fun i => (x.2.1 i).toTree r b) x.2.2 - -theorem occupied_arity_le_leaves {b n : ℕ} (children : Fin n → OccupiedParityTree b) - (roles : Fin n → Fin 3) (ht : (OccupiedParityTree.node n children roles).occupied) : - n≤(OccupiedParityTree.node n children roles).leafCount := by - have h (i : Fin n) : 1≤(children i).leafCount := leafCount_pos _ (ht.2 i) - simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one,leafCount] - using Finset.sum_le_sum (s:=Finset.univ) (fun i _ => h i) - -theorem child_le_leaves {b n : ℕ} (children : Fin n → OccupiedParityTree b) - (roles : Fin n → Fin 3) (i : Fin n) : - (children i).leafCount≤(OccupiedParityTree.node n children roles).leafCount := - Finset.single_le_sum (fun j _ => Nat.zero_le ((children j).leafCount)) (Finset.mem_univ i) - -/-- Every occupied shape with r selected leaves really has a finite code -whose domain depends only on r and the depth, not on any window size. -/ -theorem exists_finiteRoleShape {b : ℕ} (t : OccupiedParityTree b) (r : ℕ) - (ht : t.occupied) (hr : t.leafCount≤r) : - ∃x : FiniteRoleShape r b,x.toTree r b=t := by - induction t with - | leaf => exact ⟨PUnit.unit,rfl⟩ - | @node b n children roles ih => - have hn : n (x i).toTree r b) roles = _ - congr 1 - exact funext hx - -/-- The manuscript's finite shape/role constant, now a literal natural -number independent of the actual child-label sizes and all channel data. -/ -def shapeRoleConstant (r b : ℕ) : ℕ := Fintype.card (FiniteRoleShape r b) - -theorem finite_bounded_occupied_shapes (b r : ℕ) : - Finite {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} := by - let f : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} → FiniteRoleShape r b := - fun t => Classical.choose (exists_finiteRoleShape t.val r t.property.1 t.property.2) - apply Finite.of_injective f - intro x y he - apply Subtype.ext - have hx := Classical.choose_spec (exists_finiteRoleShape x.val r x.property.1 x.property.2) - have hy := Classical.choose_spec (exists_finiteRoleShape y.val r y.property.1 y.property.2) - dsimp only [f] at he - exact hx.symm.trans ((congrArg (FiniteRoleShape.toTree r b) he).trans hy) -end OccupiedParityTree -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open FiniteLaw - -/-- Extra-leaf index set version of the whole-bit-law sum. -/ -def indexedExtraAverage {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) - (s N : ℕ) (f : Ω → ℝ) (X : Ω → E → ℤ) (h : E → Fin N) : ℝ := - P.expect (fun ω => f ω*∏j,motifIndicator s (((h j).val:ℤ)-X ω j)) - -theorem indexedExtraAverage_nonneg {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) - (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) - (h : E → Fin N) : 0 ≤ indexedExtraAverage P s N f X h := by - apply Finset.sum_nonneg - intro ω hω - apply mul_nonneg (P.nonneg ω) - exact mul_nonneg (hf ω) (Finset.prod_nonneg (fun j _ => motifIndicator_nonneg _ _)) - -theorem indexedExtraAverage_sum {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) - (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) : - (∑h : E → Fin N,indexedExtraAverage P s N f X h) ≤ - ((2^s:ℕ):ℝ)^(Fintype.card E)*P.expect f := by - unfold indexedExtraAverage expect - rw [Finset.sum_comm] - simp_rw [←mul_assoc,←Finset.mul_sum] - calc - _ ≤ ∑ω,P.mass ω*f ω*(((2^s:ℕ):ℝ)^(Fintype.card E)) := by - apply Finset.sum_le_sum - intro ω hω - apply mul_le_mul_of_nonneg_left _ (mul_nonneg (P.nonneg _) (hf ω)) - have he := Fintype.prod_sum (fun (j : E) (h : Fin N) => motifIndicator s ((h.val:ℤ)-X ω j)) - rw [←he] - calc - _ ≤ ∏_j : E,((2^s:ℕ):ℝ) := by - apply Finset.prod_le_prod₀ - · intro j hj - exact Finset.sum_nonneg (fun h hh => motifIndicator_nonneg _ _) - · intro j hj - exact motifIndicator_finite_sum s N (X ω j) - _ = _ := by simp - _ = _ := by rw [←Finset.sum_mul]; ring - -theorem indexedExtraAverage_energy {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) - (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) : - (∑h : E → Fin N,indexedExtraAverage P s N f X h ^ 2) ≤ - ((2^s:ℕ):ℝ)^(2*Fintype.card E)*(P.expect f)^2 := by - have hn (h : E → Fin N) := indexedExtraAverage_nonneg P s N f hf X h - calc - _ ≤ (∑h : E → Fin N,indexedExtraAverage P s N f X h)^2 := - Finset.sum_sq_le_sq_sum_of_nonneg (fun h _ => hn h) - _ ≤ (((2^s:ℕ):ℝ)^(Fintype.card E)*P.expect f)^2 := by - apply pow_le_pow_left₀ (Finset.sum_nonneg (fun h _ => hn h)) - exact indexedExtraAverage_sum P s N f hf X - _ = _ := by rw [mul_pow,←pow_mul]; congr 2; omega -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -open OccupiedParityTree - -/-- Node-wise assembly of genuine edge labels. -/ -def OccupiedParityTree.Labels.node (T : ℕ → ℕ) {b k : ℕ} - {children : Fin k → OccupiedParityTree b} {roles : Fin k → Fin 3} - (h : Fin k → Fin (T b)) (z : (i : Fin k) → (children i).Labels T) : - (OccupiedParityTree.node k children roles).Labels T := - fun e => match e with - | Sum.inl i => h i - | Sum.inr q => z q.1 q.2 - -/-- The real numeric labels of the selected occupied configuration. -/ -def occupiedTermLabels (T : ℕ → ℕ) : (b : ℕ) → - (S : Finset (WindowLeaf T (b+1))) → (a : OccupiedWindowChoice T b S) → - (occupiedWindowTerm T b S a).Labels T - | 0, S, _ => Labels.node T (fun i => (S.equivFin.symm i).val.1) (fun _ e => e.elim) - | b+1, S, a => Labels.node T (fun i => ((selectedChildren S).equivFin.symm i).val) - (fun i => occupiedTermLabels T b - (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) - -theorem occupiedTermLabels_forced (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) - (F : (occupiedWindowTerm T b S a).Forced) : - F.labels T (occupiedTermLabels T b S a)=forcedWindowLabels T b S a F := by - induction b with - | zero => - cases F with - | node i j hne hi hj left right => cases left; cases right; rfl - | succ b ih => - rcases a with ⟨u,r⟩ - cases F with - | node i j hne hi hj left right => - change - (((selectedChildren S).equivFin.symm i).val, - ((selectedChildren S).equivFin.symm j).val, - left.labels T (occupiedTermLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm i).val) (u i)), - right.labels T (occupiedTermLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm j).val) (u j))) = - (((selectedChildren S).equivFin.symm i).val, - ((selectedChildren S).equivFin.symm j).val, - forcedWindowLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm i).val) (u i) left, - forcedWindowLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm j).val) (u j) right) - exact congrArg (fun z => (((selectedChildren S).equivFin.symm i).val, - ((selectedChildren S).equivFin.symm j).val,z)) (Prod.ext (ih _ _ left) (ih _ _ right)) - -namespace OccupiedParityTree -/-- Reading the set of leaf addresses from a shape and numeric edge labels. -Repeated or unordered coordinates are allowed; the true encoding is a -particular subset of this unrestricted label domain. -/ -def labelledLeaves (T : ℕ → ℕ) : {b : ℕ} → (t : OccupiedParityTree b) → - t.Labels T → Finset (WindowLeaf T b) - | 0, .leaf, _ => {(⟨0,by decide⟩ : Fin 1)} - | b+1, .node n children roles, x => Finset.univ.biUnion fun i : Fin n => - ((children i).labelledLeaves T (x.child T i)).image (fun v => (x (Sum.inl i),v)) -end OccupiedParityTree - -theorem mem_selectedChildLeaves {α β : Type*} [DecidableEq α] [DecidableEq β] - (S : Finset (α×β)) (h : α) (v : β) : v∈selectedChildLeaves S h ↔ (h,v)∈S := by - constructor - · intro hm - obtain ⟨w,hw,hv⟩ := Finset.mem_image.mp hm - have he : w=(h,v) := Prod.ext (Finset.mem_filter.mp hw).2 hv - exact he ▸ (Finset.mem_filter.mp hw).1 - · intro hm - exact Finset.mem_image.mpr ⟨(h,v),Finset.mem_filter.mpr ⟨hm,rfl⟩,rfl⟩ - -theorem occupiedTermLabels_leaves (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : - (occupiedWindowTerm T b S a).labelledLeaves T (occupiedTermLabels T b S a)=S := by - induction b with - | zero => - ext v - constructor - · intro hv - obtain ⟨i,hi,hv⟩ := Finset.mem_biUnion.mp hv - obtain ⟨w,hw,hvw⟩ := Finset.mem_image.mp hv - have he : (S.equivFin.symm i).val=v := by - apply Prod.ext - · change (occupiedTermLabels T 0 S a (Sum.inl i)) = v.1 - have hfst := congrArg (Prod.fst : Fin (T 0) × Fin 1 → Fin (T 0)) hvw - exact hfst - · exact Subsingleton.elim (α := Fin 1) _ _ - exact he ▸ (S.equivFin.symm i).property - · intro hv - let i := S.equivFin ⟨v,hv⟩ - apply Finset.mem_biUnion.mpr - refine ⟨i,Finset.mem_univ _,?_⟩ - apply Finset.mem_image.mpr - refine ⟨(⟨0,by decide⟩ : Fin 1),Finset.mem_singleton_self _,?_⟩ - change ((S.equivFin.symm i).val.1,(⟨0,by decide⟩ : Fin 1))=v - have he : (S.equivFin.symm i).val=v := congrArg Subtype.val (S.equivFin.symm_apply_apply _) - apply Prod.ext - · change (S.equivFin.symm i).val.1=v.1 - exact congrArg (Prod.fst : Fin (T 0) × Fin 1 → Fin (T 0)) he - · exact Subsingleton.elim (α := Fin 1) _ _ - | succ b ih => - rcases a with ⟨u,r⟩ - simp only [occupiedWindowTerm, labelledLeaves, occupiedTermLabels, Labels.node] - have hc (i : Fin (selectedChildren S).card) : - (Labels.node T (roles := r) (fun i => ((selectedChildren S).equivFin.symm i).val) - (fun i => occupiedTermLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm i).val) (u i))).child T i = - occupiedTermLabels T b (selectedChildLeaves S - ((selectedChildren S).equivFin.symm i).val) (u i) := by rfl - simp_rw [hc,ih] - ext v - constructor - · intro hv - obtain ⟨i,hi,hv⟩ := Finset.mem_biUnion.mp hv - obtain ⟨w,hw,rfl⟩ := Finset.mem_image.mp hv - exact (mem_selectedChildLeaves _ _ _).mp hw - · intro hv - have hc : v.1∈selectedChildren S := Finset.mem_image.mpr ⟨v,hv,rfl⟩ - let i := (selectedChildren S).equivFin ⟨v.1,hc⟩ - have he : ((selectedChildren S).equivFin.symm i).val=v.1 := - congrArg Subtype.val ((selectedChildren S).equivFin.symm_apply_apply _) - apply Finset.mem_biUnion.mpr - refine ⟨i,Finset.mem_univ _,?_⟩ - apply Finset.mem_image.mpr - refine ⟨v.2,?_,?_⟩ - · rw [he] - exact (mem_selectedChildLeaves _ _ _).mpr hv - · exact Prod.ext he rfl - -/-- The shape remembers all the role choices once the actual selected set -is fixed. -/ -theorem occupiedWindowTerm_injective (T : ℕ → ℕ) (b : ℕ) - (S : Finset (WindowLeaf T (b+1))) : Function.Injective (occupiedWindowTerm T b S) := by - induction b with - | zero => - intro a c h - exact eq_of_heq (OccupiedParityTree.node.inj h).2.2 - | succ b ih => - intro a c h - apply Prod.ext - · funext i - exact ih _ ((congrFun (eq_of_heq (OccupiedParityTree.node.inj h).2.1) i)) - · exact eq_of_heq (OccupiedParityTree.node.inj h).2.2 - -/-- Unrestricted shape/label space really covers the coefficient index -without multiplicity. -/ -def occupiedTermEncoding (T : ℕ → ℕ) (b : ℕ) - (w : (S : Finset (WindowLeaf T (b+1))) × OccupiedWindowChoice T b S) : - (t : OccupiedParityTree (b+1)) × t.Labels T := - ⟨occupiedWindowTerm T b w.1 w.2,occupiedTermLabels T b w.1 w.2⟩ - -theorem occupiedTermEncoding_injective (T : ℕ → ℕ) (b : ℕ) : - Function.Injective (occupiedTermEncoding T b) := by - intro w v he - have hS := congrArg (fun z : (t : OccupiedParityTree (b+1)) × t.Labels T => - z.1.labelledLeaves T z.2) he - change (occupiedWindowTerm T b w.1 w.2).labelledLeaves T (occupiedTermLabels T b w.1 w.2)= - (occupiedWindowTerm T b v.1 v.2).labelledLeaves T (occupiedTermLabels T b v.1 v.2) at hS - simp only [occupiedTermLabels_leaves] at hS - cases w with - | mk S a => - cases v with - | mk V c => - dsimp only at hS - subst V - have ht := congrArg Sigma.fst he - have ha := occupiedWindowTerm_injective T b S ht - change a=c at ha - subst c - rfl -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace OccupiedParityTree - -noncomputable def Forced.edgeEquiv {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - BinaryEdge b ⊕ F.ExtraEdge ≃ t.Edge := by - classical - letI : DecidablePred (Set.range F.edge) := fun _ => Classical.propDecidable _ - exact (Equiv.sumCongr (Equiv.ofInjective F.edge F.edge_injective) (Equiv.refl _)).trans - (Equiv.sumCompl (Set.range F.edge)) - -def binaryEdgeCount (b h : ℕ) : ℕ := Fintype.card {e : BinaryEdge b // e.height=h} - -theorem BinaryEdge.height_lt {b : ℕ} (e : BinaryEdge b) : e.height exact e.elim - | succ b ih => - cases e with - | inl i => exact Nat.lt_succ_self _ - | inr z => exact Nat.lt_succ_of_lt (ih z.2) - -theorem binaryEdgeCount_outside (b h : ℕ) (hh : b≤h) : binaryEdgeCount b h=0 := by - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun e => ?_⟩ - have hc := e.val.height_lt - rw [e.property] at hc - omega - -theorem binaryEdgeCount_succ (b h : ℕ) : - binaryEdgeCount (b+1) h = (if b=h then 2 else 0)+2*binaryEdgeCount b h := by - unfold binaryEdgeCount - simp only [Fintype.card_subtype,Finset.card_filter] - change (∑e : Bool ⊕ (Bool × BinaryEdge b), if BinaryEdge.height (b:=b+1) e=h then 1 else 0)=_ - rw [Fintype.sum_sum_type,Fintype.sum_prod_type] - by_cases hb : b=h <;> simp [BinaryEdge.height,hb,two_mul] <;> simp only [Finset.card_filter] <;> rfl - -theorem binaryEdgeCount_eq (b h : ℕ) (hh : h omega - | succ b ih => - rw [binaryEdgeCount_succ] - by_cases he : b=h - · subst h - rw [ite_eq_left rfl,binaryEdgeCount_outside b b le_rfl] - simp - · rw [ite_eq_right he,zero_add,ih (by omega)] - have hsub : b+1-h=(b-h)+1 := by omega - rw [hsub,pow_succ,Nat.mul_comm] - -def Forced.extraCount {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (h : ℕ) : ℕ := - Fintype.card {e : F.ExtraEdge // e.val.height=h} - -theorem Forced.count_partition {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (h : ℕ) : - F.extraCount h+binaryEdgeCount b h=t.edgeCount h := by - have he := F.edgeEquiv.sum_comp (fun e : t.Edge => if e.height=h then (1:ℕ) else 0) - rw [Fintype.sum_sum_type] at he - change (∑e : BinaryEdge b, if (F.edge e).height=h then 1 else 0)+ - (∑e : F.ExtraEdge, if e.val.height=h then 1 else 0) = - (∑e : t.Edge, if e.height=h then 1 else 0) at he - simp_rw [F.edge_height] at he - unfold Forced.extraCount binaryEdgeCount edgeCount - simp only [Fintype.card_subtype,Finset.card_filter] - omega - -theorem levelCount_bottom {b : ℕ} (t : OccupiedParityTree b) : t.levelCount b=t.leafCount := by - induction t with - | leaf => rfl - | node n children roles ih => exact Finset.sum_congr rfl (fun i _ => ih i) - -/-- The extra bottom coordinates are precisely r-2^b, including the empty -height-zero case. -/ -theorem Forced.card_extraLeafEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : - Fintype.card F.ExtraLeafEdge=t.leafCount-2^b := by - cases b with - | zero => - cases t - change F.extraCount 0 = _ - have h := F.count_partition 0 - rw [edgeCount_leaf] at h - simp only [leafCount,pow_zero,Nat.sub_self] - omega - | succ b => - change F.extraCount 0 = _ - have h := F.count_partition 0 - rw [binaryEdgeCount_eq (b+1) 0 (by omega),edgeCount_level t 0 (by omega)] at h - simp only [Nat.sub_zero,levelCount_bottom] at h - omega - -/-- Exact source nonforced vertex bound, now for genuine extra edge-label -coordinates rather than an abstract level-count surrogate. -/ -theorem Forced.extraCount_le {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) - (ht : t.occupied) (h : ℕ) : F.extraCount h≤t.leafCount-2^b := by - by_cases hh : h - ⟨e.val.val,congrArg Fin.val e.property⟩ - apply Fintype.card_le_of_injective f - intro u v he - have he' : u.val.val=v.val.val := congrArg - (fun q : {e : F.ExtraEdge // e.val.height=h.val} => q.val) he - exact Subtype.ext (Subtype.ext he') - -theorem Forced.card_interiorLabels_le (T : ℕ → ℕ) (hT : ∀j,0 T j.val) - change (∏j : Fin b, ∏_e : {e : F.ExtraInteriorEdge // F.interiorHeight e=j}, T j.val) = - ∏e : F.ExtraInteriorEdge,T e.val.val.height at hp - rw [←hp] - simp only [Finset.prod_const,Finset.card_univ] - rw [←Finset.prod_pow] - apply Finset.prod_le_prod - intro j hj - by_cases hz : j.val=0 - · have he : Fintype.card {e : F.ExtraInteriorEdge // F.interiorHeight e=j}=0 := by - apply Fintype.card_eq_zero_iff.mpr - refine ⟨fun e => ?_⟩ - exact e.val.property ((congrArg Fin.val e.property).trans hz) - rw [he,ite_eq_left hz,pow_zero,one_pow] - · rw [ite_eq_right hz] - exact Nat.pow_le_pow_right (hT j.val) (F.interiorFiber_le ht j) - -end OccupiedParityTree -end TraceReconstruction - -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Anchors + +namespace OAI + +/-! +# Shapes + +Global schedules, edge labels, forced/extra coordinate splitting, finite shape codes, and occupied-label counts. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Source central third, in the zero-based child label convention. The +shift of the source one-based indices is recorded in center parameters. -/ +def centralThird (N : ℕ) : Finset (Fin N) := + Finset.univ.filter (fun u => N ≤ 3*u.val ∧ 3*u.val ≤ 2*N) + +/-- One actual global-pair orientation, ordered by its pre-region block and +its local identifier there. -/ +def globalTrialIndex (N t : ℕ) (v : Fin (N/4)) (a : Fin t) : Fin ((N/4)*t) := + ⟨v.val*t+a.val, by nlinarith [v.isLt,a.isLt]⟩ + +/-- Literal net global displacement immediately before a child window: +a pre block at v+1 remains active through its matched post region N-v. +The paired displacement has even t trials in each affected region. -/ +def scheduledGlobalShift (N t : ℕ) (bits : Fin ((N/4)*t) → Bool) (u : Fin N) : ℤ := + ∑v : Fin (N/4), if v.val ≤ u.val ∧ u.val+v.val globalTrialIndex N t x.1 x.2) := by + constructor + · intro x y he + have he' := congrArg Fin.val he + change x.1.val*t+x.2.val = y.1.val*t+y.2.val at he' + have hx := x.2.isLt + have hy := y.2.isLt + have hv : x.1.val=y.1.val := by + by_contra h + rcases lt_or_gt_of_ne h with h | h <;> nlinarith + have ha : x.2.val=y.2.val := by rw [hv] at he'; omega + exact Prod.ext (Fin.ext hv) (Fin.ext ha) + · intro i + have ht : 0 (bitIndex (bits i):ℤ)) + · simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + _ = _ := by congr 1; exact_mod_cast hh.symm + + +/-- The actual complete-tree global schedule has the exact plateau identity +needed by the already proved correlated anchor energy theorem. -/ +def sourceGlobalTrials (T t : ℕ → ℕ) (b : ℕ) : ℕ := (T b/4)*t b + +def sourceGlobalShift (T t : ℕ → ℕ) (b : ℕ) + (bits : Fin (sourceGlobalTrials T t b) → Bool) (u : Fin (T b)) : ℤ := + scheduledGlobalShift (T b) (t b) bits u + +theorem sourceGlobalShift_hasPlateau (T t : ℕ → ℕ) (ht : ∀b,Even (t b)) : + HasGlobalPlateau T (sourceGlobalTrials T t) (fun b => centralThird (T b)) + (fun b => (sourceGlobalTrials T t b/2:ℕ)) (sourceGlobalShift T t) := by + intro b bits u hu + exact scheduledGlobalShift_plateau (T b) (t b) (ht b) bits u hu +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +/-- One actual child-label coordinate of an arbitrary ordered occupied +shape. Unlike a complete r-ary padding, this contains no unused edges. -/ +def Edge : {b : ℕ} → OccupiedParityTree b → Type + | _, .leaf => PEmpty + | _, .node n children _ => Fin n ⊕ ((i : Fin n) × Edge (children i)) + +noncomputable instance edgeFintype : {b : ℕ} → (t : OccupiedParityTree b) → Fintype t.Edge + | _, .leaf => inferInstanceAs (Fintype PEmpty) + | _, .node n children roles => by + letI := fun i => edgeFintype (children i) + exact inferInstanceAs (Fintype (Fin n ⊕ ((i : Fin n) × Edge (children i)))) + +def Edge.height : {b : ℕ} → {t : OccupiedParityTree b} → t.Edge → ℕ + | _, .leaf, e => e.elim + | _, @OccupiedParityTree.node b _n _children _roles, e => + match e with + | Sum.inl _ => b + | Sum.inr z => Edge.height z.2 + +/-- All literal label assignments to this particular ordered shape. -/ +def Labels (T : ℕ → ℕ) {b : ℕ} (t : OccupiedParityTree b) := + (e : t.Edge) → Fin (T e.height) + +noncomputable instance labelsFintype (T : ℕ → ℕ) {b : ℕ} (t : OccupiedParityTree b) : + Fintype (t.Labels T) := inferInstanceAs (Fintype ((e : t.Edge) → Fin (T e.height))) + +def Labels.child (T : ℕ → ℕ) {b n : ℕ} {children : Fin n → OccupiedParityTree b} + {roles : Fin n → Fin 3} (x : (OccupiedParityTree.node n children roles).Labels T) + (i : Fin n) : (children i).Labels T := fun e => x (Sum.inr ⟨i,e⟩) + +/-- Projection to the actual labels of a fixed forced subtree. The shape +selection is independent of these labels and of all random orientations. -/ +def Forced.labels (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → + t.Forced → t.Labels T → BinaryWindowLabels T b + | _, _, .leaf, _ => PUnit.unit + | _, _, .node a c _ _ _ left right, x => + (x (Sum.inl a),x (Sum.inl c),left.labels T (x.child T a),right.labels T (x.child T c)) + +/-- Edge addresses in a complete binary tree, independent of all actual +numeric labels. False and true are its two children. -/ +def BinaryEdge : ℕ → Type + | 0 => PEmpty + | b+1 => Bool ⊕ (Bool × BinaryEdge b) + +noncomputable instance binaryEdgeFintype : (b : ℕ) → Fintype (BinaryEdge b) + | 0 => inferInstanceAs (Fintype PEmpty) + | b+1 => by + letI := binaryEdgeFintype b + exact inferInstanceAs (Fintype (Bool ⊕ (Bool × BinaryEdge b))) + +def BinaryEdge.height : {b : ℕ} → BinaryEdge b → ℕ + | 0, e => e.elim + | b+1, Sum.inl _ => b + | _b+1, Sum.inr e => BinaryEdge.height e.2 + +/-- The forced binary tree is embedded in the actual occupied edge set. -/ +def Forced.edge : {b : ℕ} → {t : OccupiedParityTree b} → t.Forced → BinaryEdge b → t.Edge + | _, _, .leaf, e => e.elim + | _, _, .node a _ _ _ _ _ _, Sum.inl false => Sum.inl a + | _, _, .node _ c _ _ _ _ _, Sum.inl true => Sum.inl c + | _, _, .node a _ _ _ _ left _, Sum.inr (false,e) => Sum.inr ⟨a,left.edge e⟩ + | _, _, .node _ c _ _ _ _ right, Sum.inr (true,e) => Sum.inr ⟨c,right.edge e⟩ + +theorem Forced.edge_injective {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + Function.Injective F.edge := by + induction F with + | leaf => intro i; exact i.elim + | @node b n children roles a c hne ha hc left right ihl ihr => + intro i j he + cases i with + | inl i => + cases j with + | inl j => + cases i <;> cases j + · rfl + · exact (hne (Sum.inl.inj he)).elim + · exact (hne (Sum.inl.inj he).symm).elim + · rfl + | inr j => cases i <;> rcases j with ⟨j,e⟩ <;> cases j <;> cases he + | inr i => + cases j with + | inl j => rcases i with ⟨i,e⟩; cases i <;> cases j <;> cases he + | inr j => + rcases i with ⟨i,e⟩ + rcases j with ⟨j,f⟩ + cases i <;> cases j + · have hh := Sum.inr.inj he + have hh' : left.edge e=left.edge f := by injection hh + exact congrArg (fun e => Sum.inr (false,e)) (ihl hh') + · have hh := congrArg Sigma.fst (Sum.inr.inj he) + exact (hne hh).elim + · have hh := congrArg Sigma.fst (Sum.inr.inj he) + exact (hne hh.symm).elim + · have hh := Sum.inr.inj he + have hh' : right.edge e=right.edge f := by injection hh + exact congrArg (fun e => Sum.inr (true,e)) (ihr hh') + +theorem Forced.edge_height {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (e : BinaryEdge b) : (F.edge e).height=e.height := by + induction F with + | leaf => exact e.elim + | @node b n children roles a c hne ha hc left right ihl ihr => + cases e with + | inl i => cases i <;> rfl + | inr z => rcases z with ⟨i,e⟩; cases i; exact ihl e; exact ihr e + +/-- The finite number of edge coordinates at a given child height. -/ +def edgeCount {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) : ℕ := + Fintype.card {e : t.Edge // e.height=h} + +theorem edgeCount_leaf (h : ℕ) : edgeCount OccupiedParityTree.leaf h=0 := by + unfold edgeCount + exact Fintype.card_eq_zero_iff.mpr ⟨fun e => e.val.elim⟩ + +theorem edgeCount_node {b n : ℕ} (children : Fin n → OccupiedParityTree b) + (roles : Fin n → Fin 3) (h : ℕ) : + edgeCount (.node n children roles) h = (if b=h then n else 0)+∑i,edgeCount (children i) h := by + unfold edgeCount + simp only [Fintype.card_subtype, Finset.card_filter] + change (∑e : Fin n ⊕ ((i : Fin n) × (children i).Edge),if Edge.height (t := .node n children roles) e=h then 1 else 0)=_ + rw [Fintype.sum_sum_type] + simp only [Edge.height,Fintype.sum_sigma] + + split_ifs <;> simp_all <;> simp only [Finset.card_filter] <;> rfl + +theorem Edge.height_lt {b : ℕ} {t : OccupiedParityTree b} (e : t.Edge) : e.height exact e.elim + | @node b n children roles ih => + cases e with + | inl i => exact Nat.lt_succ_self b + | inr z => exact Nat.lt_succ_of_lt (ih z.1 z.2) + +theorem edgeCount_outside {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) (hh : b≤h) : + t.edgeCount h=0 := by + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun e => ?_⟩ + have hc := e.val.height_lt + rw [e.property] at hc + omega + +theorem edgeCount_level {b : ℕ} (t : OccupiedParityTree b) (h : ℕ) (hh : h omega + | @node b n children roles ih => + rw [edgeCount_node] + by_cases he : h=b + · subst h + have hz (i : Fin n) := edgeCount_outside (children i) b le_rfl + simp only [hz,Finset.sum_const_zero,add_zero,Nat.add_sub_cancel_left, + levelCount,Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one] + rfl + · have hh' : h ih i hh') + +def BinaryEdgeLabels (T : ℕ → ℕ) (b : ℕ) := (e : BinaryEdge b) → Fin (T e.height) + +noncomputable instance binaryEdgeLabelsFintype (T : ℕ → ℕ) (b : ℕ) : + Fintype (BinaryEdgeLabels T b) := inferInstanceAs (Fintype ((e : BinaryEdge b) → Fin (T e.height))) + +/-- Exact coordinates of the recursively defined forced label tuple. -/ +def binaryLabelsEquiv (T : ℕ → ℕ) : (b : ℕ) → BinaryEdgeLabels T b ≃ BinaryWindowLabels T b + | 0 => + { toFun := fun _ => PUnit.unit + invFun := fun _ e => e.elim + left_inv := fun _ => by funext e; exact e.elim + right_inv := fun y => by cases y; rfl } + | b+1 => + { toFun := fun x => (x (Sum.inl false),x (Sum.inl true), + binaryLabelsEquiv T b (fun e => x (Sum.inr (false,e))), + binaryLabelsEquiv T b (fun e => x (Sum.inr (true,e)))) + invFun := fun x e => match e with + | Sum.inl false => x.1 + | Sum.inl true => x.2.1 + | Sum.inr (false,e) => (binaryLabelsEquiv T b).symm x.2.2.1 e + | Sum.inr (true,e) => (binaryLabelsEquiv T b).symm x.2.2.2 e + left_inv := fun x => by + funext e + cases e with + | inl j => cases j <;> rfl + | inr z => + rcases z with ⟨j,e⟩ + cases j <;> exact congrFun ((binaryLabelsEquiv T b).symm_apply_apply _) e + right_inv := fun x => by + rcases x with ⟨a,c,l,r⟩ + simp only [Equiv.apply_symm_apply] + rfl } + +/-- Restriction to the real forced coordinates, with only equality transport +of the child-height index. -/ +def Forced.restrict (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (x : t.Labels T) : BinaryEdgeLabels T b := fun e => + Fin.cast (congrArg T (F.edge_height e)) (x (F.edge e)) + +theorem Forced.restrict_labels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (x : t.Labels T) : binaryLabelsEquiv T b (F.restrict T x)=F.labels T x := by + induction F with + | leaf => rfl + | @node b n children roles a c hne ha hc left right ihl ihr => + change (x (Sum.inl a),x (Sum.inl c),_,_) = (x (Sum.inl a),x (Sum.inl c),_,_) + refine Prod.ext rfl (Prod.ext rfl (Prod.ext ?_ ?_)) + · exact ihl (x.child T a) + · exact ihr (x.child T c) + +end OccupiedParityTree +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +def Forced.ExtraEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := + {e : t.Edge // e∉Set.range F.edge} + +noncomputable instance forcedExtraEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + Fintype F.ExtraEdge := inferInstanceAs (Fintype {e : t.Edge // e∉Set.range F.edge}) + +def Forced.ExtraLabels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := + (e : F.ExtraEdge) → Fin (T e.val.height) + +noncomputable instance forcedExtraLabelsFintype (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) : Fintype (F.ExtraLabels T) := + inferInstanceAs (Fintype ((e : F.ExtraEdge) → Fin (T e.val.height))) + +/-- Exact bijective partition of all actual edge coordinates into the +forced binary coordinates and the genuine extra coordinates. -/ +noncomputable def Forced.labelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + t.Labels T ≃ BinaryWindowLabels T b × F.ExtraLabels T := by + classical + letI : DecidablePred (Set.range F.edge) := fun _ => Classical.propDecidable _ + exact (Equiv.piEquivPiSubtypeProd (Set.range F.edge) (fun e : t.Edge => Fin (T e.height))).trans + (Equiv.prodCongr + (((Equiv.piCongrLeft (fun e : Set.range F.edge => Fin (T e.val.height)) + (Equiv.ofInjective F.edge F.edge_injective)).symm.trans + (Equiv.piCongrRight fun e => finCongr (congrArg T (F.edge_height e)))).trans + (binaryLabelsEquiv T b)) + (Equiv.refl _)) + +theorem Forced.labelsEquiv_fst (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (x : t.Labels T) : (F.labelsEquiv T x).1=F.labels T x := by + exact F.restrict_labels T x + +theorem Forced.labelsEquiv_snd (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (x : t.Labels T) : (F.labelsEquiv T x).2=(fun e : F.ExtraEdge => x e.val) := rfl + +/-- Literal finite Fubini over forced labels and all remaining labels. -/ +theorem Forced.sum_labels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (f : BinaryWindowLabels T b → F.ExtraLabels T → ℝ) : + (∑x : t.Labels T,f (F.labels T x) (fun e => x e.val)) = + ∑p : BinaryWindowLabels T b, ∑z : F.ExtraLabels T,f p z := by + have h := (F.labelsEquiv T).sum_comp (fun x => f x.1 x.2) + simpa only [Forced.labelsEquiv_fst,Forced.labelsEquiv_snd,Fintype.sum_prod_type] using h + +def Forced.ExtraLeafEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := + {e : F.ExtraEdge // e.val.height=0} + +def Forced.ExtraInteriorEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := + {e : F.ExtraEdge // e.val.height≠0} + +noncomputable instance extraLeafEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + Fintype F.ExtraLeafEdge := inferInstanceAs (Fintype {e : F.ExtraEdge // e.val.height=0}) + +noncomputable instance extraInteriorEdgeFintype {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + Fintype F.ExtraInteriorEdge := inferInstanceAs (Fintype {e : F.ExtraEdge // e.val.height≠0}) + +def Forced.InteriorLabels (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) := + (e : F.ExtraInteriorEdge) → Fin (T e.val.val.height) + +noncomputable instance extraInteriorLabelsFintype (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) : Fintype (F.InteriorLabels T) := + inferInstanceAs (Fintype ((e : F.ExtraInteriorEdge) → Fin (T e.val.val.height))) + +/-- Extra bottom labels are separated from all nonleaf labels without +introducing any T₁ factor. -/ +noncomputable def Forced.extraLabelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) : F.ExtraLabels T ≃ (F.ExtraLeafEdge → Fin (T 0)) × F.InteriorLabels T := + (Equiv.piEquivPiSubtypeProd (fun e : F.ExtraEdge => e.val.height=0) + (fun e : F.ExtraEdge => Fin (T e.val.height))).trans + (Equiv.prodCongr (Equiv.piCongrRight fun e => finCongr (congrArg T e.property)) (Equiv.refl _)) + +end OccupiedParityTree +end TraceReconstruction +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +/-- The parent address of an edge in the full deterministic numerical index +tree. In particular it does not contain the edge's own child label. -/ +def Edge.parentPath (T : ℕ → ℕ) : {b : ℕ} → {t : OccupiedParityTree b} → + t.Labels T → t.Edge → List ℕ + | _, .leaf, _, e => e.elim + | _, .node _n _children _roles, x, e => match e with + | Sum.inl _ => [] + | Sum.inr z => (x (Sum.inl z.1)).val :: Edge.parentPath T (x.child T z.1) z.2 + +/-- Every ancestor label of an extra selected leaf is an interior label. -/ +theorem Edge.parentPath_congr (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (x y : t.Labels T) (h : ∀e : t.Edge, e.height≠0 → (x e).val=(y e).val) + (e : t.Edge) : e.parentPath T x=e.parentPath T y := by + induction t with + | leaf => exact e.elim + | @node b n children roles ih => + cases e with + | inl i => rfl + | inr z => + have hb : b≠0 := by have := z.2.height_lt; omega + change (x (Sum.inl z.1)).val :: _ = (y (Sum.inl z.1)).val :: _ + congr 1 + · exact h (Sum.inl z.1) hb + · exact ih z.1 (x.child T z.1) (y.child T z.1) + (fun e he => h (Sum.inr ⟨z.1,e⟩) he) z.2 + +theorem Forced.labels_value_eq (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (x y : t.Labels T) (h : F.labels T x=F.labels T y) (j : BinaryEdge b) : + (x (F.edge j)).val=(y (F.edge j)).val := by + have hh := (binaryLabelsEquiv T b).injective + ((F.restrict_labels T x).trans (h.trans (F.restrict_labels T y).symm)) + exact congrArg (fun z : BinaryEdgeLabels T b => (z j).val) hh + +/-- The combined exact split into forced, extra-leaf and extra-interior labels. -/ +noncomputable def Forced.fullLabelsEquiv (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) : t.Labels T ≃ + BinaryWindowLabels T b × (F.ExtraLeafEdge → Fin (T 0)) × F.InteriorLabels T := + (F.labelsEquiv T).trans (Equiv.prodCongr (Equiv.refl _) (F.extraLabelsEquiv T)) + +theorem Forced.fullLabelsEquiv_fst (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (x : t.Labels T) : (F.fullLabelsEquiv T x).1=F.labels T x := + F.labelsEquiv_fst T x + +theorem Forced.fullLabelsEquiv_leaf_value (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (x : t.Labels T) (e : F.ExtraLeafEdge) : + ((F.fullLabelsEquiv T x).2.1 e).val=(x e.val.val).val := rfl + +theorem Forced.fullLabelsEquiv_interior_value (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (x : t.Labels T) (e : F.ExtraInteriorEdge) : + ((F.fullLabelsEquiv T x).2.2 e).val=(x e.val.val).val := rfl + +/-- Changing only extra leaf labels changes no ancestor address, even when +all the complete-tree mechanisms share their source global bits. -/ +theorem Forced.parentPath_extraLeaf_invariant (T : ℕ → ℕ) {b : ℕ} {t : OccupiedParityTree b} + (F : t.Forced) (p : BinaryWindowLabels T b) (h k : F.ExtraLeafEdge → Fin (T 0)) + (z : F.InteriorLabels T) (e : t.Edge) : + e.parentPath T ((F.fullLabelsEquiv T).symm (p,h,z)) = + e.parentPath T ((F.fullLabelsEquiv T).symm (p,k,z)) := by + let x := (F.fullLabelsEquiv T).symm (p,h,z) + let y := (F.fullLabelsEquiv T).symm (p,k,z) + have hx : F.fullLabelsEquiv T x=(p,h,z) := Equiv.apply_symm_apply _ _ + have hy : F.fullLabelsEquiv T y=(p,k,z) := Equiv.apply_symm_apply _ _ + have hp : F.labels T x=F.labels T y := by + rw [←F.fullLabelsEquiv_fst,←F.fullLabelsEquiv_fst,hx,hy] + apply Edge.parentPath_congr T x y + intro i hi + by_cases hr : i∈Set.range F.edge + · obtain ⟨j,rfl⟩ := hr + exact F.labels_value_eq T x y hp j + · let j : F.ExtraInteriorEdge := ⟨⟨i,hr⟩,hi⟩ + have hvx := congrArg (fun a => (a.2.2 j).val) hx + have hvy := congrArg (fun a => (a.2.2 j).val) hy + have hv := hvx.trans hvy.symm + simpa only [Forced.fullLabelsEquiv_interior_value] using hv + +end OccupiedParityTree +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +/-- A finite ordered-role shape code with at most r children at every +vertex. There are no numerical child labels in this type. -/ +def FiniteRoleShape (r : ℕ) : ℕ → Type + | 0 => PUnit + | b+1 => (n : Fin (r+1)) × (Fin n.val → FiniteRoleShape r b) × (Fin n.val → Fin 3) + +noncomputable instance finiteRoleShapeFintype (r : ℕ) : (b : ℕ) → Fintype (FiniteRoleShape r b) + | 0 => inferInstanceAs (Fintype PUnit) + | b+1 => by + letI := finiteRoleShapeFintype r b + exact inferInstanceAs (Fintype ((n : Fin (r+1)) × + (Fin n.val → FiniteRoleShape r b) × (Fin n.val → Fin 3))) + +def FiniteRoleShape.toTree (r : ℕ) : (b : ℕ) → FiniteRoleShape r b → OccupiedParityTree b + | 0, _ => .leaf + | b+1, x => .node x.1.val (fun i => (x.2.1 i).toTree r b) x.2.2 + +theorem occupied_arity_le_leaves {b n : ℕ} (children : Fin n → OccupiedParityTree b) + (roles : Fin n → Fin 3) (ht : (OccupiedParityTree.node n children roles).occupied) : + n≤(OccupiedParityTree.node n children roles).leafCount := by + have h (i : Fin n) : 1≤(children i).leafCount := leafCount_pos _ (ht.2 i) + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul,mul_one,leafCount] + using Finset.sum_le_sum (s:=Finset.univ) (fun i _ => h i) + +theorem child_le_leaves {b n : ℕ} (children : Fin n → OccupiedParityTree b) + (roles : Fin n → Fin 3) (i : Fin n) : + (children i).leafCount≤(OccupiedParityTree.node n children roles).leafCount := + Finset.single_le_sum (fun j _ => Nat.zero_le ((children j).leafCount)) (Finset.mem_univ i) + +/-- Every occupied shape with r selected leaves really has a finite code +whose domain depends only on r and the depth, not on any window size. -/ +theorem exists_finiteRoleShape {b : ℕ} (t : OccupiedParityTree b) (r : ℕ) + (ht : t.occupied) (hr : t.leafCount≤r) : + ∃x : FiniteRoleShape r b,x.toTree r b=t := by + induction t with + | leaf => exact ⟨PUnit.unit,rfl⟩ + | @node b n children roles ih => + have hn : n (x i).toTree r b) roles = _ + congr 1 + exact funext hx + +/-- The manuscript's finite shape/role constant, now a literal natural +number independent of the actual child-label sizes and all channel data. -/ +def shapeRoleConstant (r b : ℕ) : ℕ := Fintype.card (FiniteRoleShape r b) + +theorem finite_bounded_occupied_shapes (b r : ℕ) : + Finite {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} := by + let f : {t : OccupiedParityTree b // t.occupied ∧ t.leafCount≤r} → FiniteRoleShape r b := + fun t => Classical.choose (exists_finiteRoleShape t.val r t.property.1 t.property.2) + apply Finite.of_injective f + intro x y he + apply Subtype.ext + have hx := Classical.choose_spec (exists_finiteRoleShape x.val r x.property.1 x.property.2) + have hy := Classical.choose_spec (exists_finiteRoleShape y.val r y.property.1 y.property.2) + dsimp only [f] at he + exact hx.symm.trans ((congrArg (FiniteRoleShape.toTree r b) he).trans hy) +end OccupiedParityTree +end TraceReconstruction + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open FiniteLaw + +/-- Extra-leaf index set version of the whole-bit-law sum. -/ +def indexedExtraAverage {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) + (s N : ℕ) (f : Ω → ℝ) (X : Ω → E → ℤ) (h : E → Fin N) : ℝ := + P.expect (fun ω => f ω*∏j,motifIndicator s (((h j).val:ℤ)-X ω j)) + +theorem indexedExtraAverage_nonneg {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) + (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) + (h : E → Fin N) : 0 ≤ indexedExtraAverage P s N f X h := by + apply Finset.sum_nonneg + intro ω hω + apply mul_nonneg (P.nonneg ω) + exact mul_nonneg (hf ω) (Finset.prod_nonneg (fun j _ => motifIndicator_nonneg _ _)) + +theorem indexedExtraAverage_sum {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) + (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) : + (∑h : E → Fin N,indexedExtraAverage P s N f X h) ≤ + ((2^s:ℕ):ℝ)^(Fintype.card E)*P.expect f := by + unfold indexedExtraAverage expect + rw [Finset.sum_comm] + simp_rw [←mul_assoc,←Finset.mul_sum] + calc + _ ≤ ∑ω,P.mass ω*f ω*(((2^s:ℕ):ℝ)^(Fintype.card E)) := by + apply Finset.sum_le_sum + intro ω hω + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (P.nonneg _) (hf ω)) + have he := Fintype.prod_sum (fun (j : E) (h : Fin N) => motifIndicator s ((h.val:ℤ)-X ω j)) + rw [←he] + calc + _ ≤ ∏_j : E,((2^s:ℕ):ℝ) := by + apply Finset.prod_le_prod₀ + · intro j hj + exact Finset.sum_nonneg (fun h hh => motifIndicator_nonneg _ _) + · intro j hj + exact motifIndicator_finite_sum s N (X ω j) + _ = _ := by simp + _ = _ := by rw [←Finset.sum_mul]; ring + +theorem indexedExtraAverage_energy {Ω E : Type*} [Fintype Ω] [Fintype E] (P : FiniteLaw Ω) + (s N : ℕ) (f : Ω → ℝ) (hf : ∀ω,0≤f ω) (X : Ω → E → ℤ) : + (∑h : E → Fin N,indexedExtraAverage P s N f X h ^ 2) ≤ + ((2^s:ℕ):ℝ)^(2*Fintype.card E)*(P.expect f)^2 := by + have hn (h : E → Fin N) := indexedExtraAverage_nonneg P s N f hf X h + calc + _ ≤ (∑h : E → Fin N,indexedExtraAverage P s N f X h)^2 := + Finset.sum_sq_le_sq_sum_of_nonneg (fun h _ => hn h) + _ ≤ (((2^s:ℕ):ℝ)^(Fintype.card E)*P.expect f)^2 := by + apply pow_le_pow_left₀ (Finset.sum_nonneg (fun h _ => hn h)) + exact indexedExtraAverage_sum P s N f hf X + _ = _ := by rw [mul_pow,←pow_mul]; congr 2; omega +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +open OccupiedParityTree + +/-- Node-wise assembly of genuine edge labels. -/ +def OccupiedParityTree.Labels.node (T : ℕ → ℕ) {b k : ℕ} + {children : Fin k → OccupiedParityTree b} {roles : Fin k → Fin 3} + (h : Fin k → Fin (T b)) (z : (i : Fin k) → (children i).Labels T) : + (OccupiedParityTree.node k children roles).Labels T := + fun e => match e with + | Sum.inl i => h i + | Sum.inr q => z q.1 q.2 + +/-- The real numeric labels of the selected occupied configuration. -/ +def occupiedTermLabels (T : ℕ → ℕ) : (b : ℕ) → + (S : Finset (WindowLeaf T (b+1))) → (a : OccupiedWindowChoice T b S) → + (occupiedWindowTerm T b S a).Labels T + | 0, S, _ => Labels.node T (fun i => (S.equivFin.symm i).val.1) (fun _ e => e.elim) + | b+1, S, a => Labels.node T (fun i => ((selectedChildren S).equivFin.symm i).val) + (fun i => occupiedTermLabels T b + (selectedChildLeaves S ((selectedChildren S).equivFin.symm i).val) (a.1 i)) + +theorem occupiedTermLabels_forced (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) + (F : (occupiedWindowTerm T b S a).Forced) : + F.labels T (occupiedTermLabels T b S a)=forcedWindowLabels T b S a F := by + induction b with + | zero => + cases F with + | node i j hne hi hj left right => cases left; cases right; rfl + | succ b ih => + rcases a with ⟨u,r⟩ + cases F with + | node i j hne hi hj left right => + change + (((selectedChildren S).equivFin.symm i).val, + ((selectedChildren S).equivFin.symm j).val, + left.labels T (occupiedTermLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm i).val) (u i)), + right.labels T (occupiedTermLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm j).val) (u j))) = + (((selectedChildren S).equivFin.symm i).val, + ((selectedChildren S).equivFin.symm j).val, + forcedWindowLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm i).val) (u i) left, + forcedWindowLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm j).val) (u j) right) + exact congrArg (fun z => (((selectedChildren S).equivFin.symm i).val, + ((selectedChildren S).equivFin.symm j).val,z)) (Prod.ext (ih _ _ left) (ih _ _ right)) + +namespace OccupiedParityTree +/-- Reading the set of leaf addresses from a shape and numeric edge labels. +Repeated or unordered coordinates are allowed; the true encoding is a +particular subset of this unrestricted label domain. -/ +def labelledLeaves (T : ℕ → ℕ) : {b : ℕ} → (t : OccupiedParityTree b) → + t.Labels T → Finset (WindowLeaf T b) + | 0, .leaf, _ => {(⟨0,by decide⟩ : Fin 1)} + | b+1, .node n children roles, x => Finset.univ.biUnion fun i : Fin n => + ((children i).labelledLeaves T (x.child T i)).image (fun v => (x (Sum.inl i),v)) +end OccupiedParityTree + +theorem mem_selectedChildLeaves {α β : Type*} [DecidableEq α] [DecidableEq β] + (S : Finset (α×β)) (h : α) (v : β) : v∈selectedChildLeaves S h ↔ (h,v)∈S := by + constructor + · intro hm + obtain ⟨w,hw,hv⟩ := Finset.mem_image.mp hm + have he : w=(h,v) := Prod.ext (Finset.mem_filter.mp hw).2 hv + exact he ▸ (Finset.mem_filter.mp hw).1 + · intro hm + exact Finset.mem_image.mpr ⟨(h,v),Finset.mem_filter.mpr ⟨hm,rfl⟩,rfl⟩ + +theorem occupiedTermLabels_leaves (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) (a : OccupiedWindowChoice T b S) : + (occupiedWindowTerm T b S a).labelledLeaves T (occupiedTermLabels T b S a)=S := by + induction b with + | zero => + ext v + constructor + · intro hv + obtain ⟨i,hi,hv⟩ := Finset.mem_biUnion.mp hv + obtain ⟨w,hw,hvw⟩ := Finset.mem_image.mp hv + have he : (S.equivFin.symm i).val=v := by + apply Prod.ext + · change (occupiedTermLabels T 0 S a (Sum.inl i)) = v.1 + have hfst := congrArg (Prod.fst : Fin (T 0) × Fin 1 → Fin (T 0)) hvw + exact hfst + · exact Subsingleton.elim (α := Fin 1) _ _ + exact he ▸ (S.equivFin.symm i).property + · intro hv + let i := S.equivFin ⟨v,hv⟩ + apply Finset.mem_biUnion.mpr + refine ⟨i,Finset.mem_univ _,?_⟩ + apply Finset.mem_image.mpr + refine ⟨(⟨0,by decide⟩ : Fin 1),Finset.mem_singleton_self _,?_⟩ + change ((S.equivFin.symm i).val.1,(⟨0,by decide⟩ : Fin 1))=v + have he : (S.equivFin.symm i).val=v := congrArg Subtype.val (S.equivFin.symm_apply_apply _) + apply Prod.ext + · change (S.equivFin.symm i).val.1=v.1 + exact congrArg (Prod.fst : Fin (T 0) × Fin 1 → Fin (T 0)) he + · exact Subsingleton.elim (α := Fin 1) _ _ + | succ b ih => + rcases a with ⟨u,r⟩ + simp only [occupiedWindowTerm, labelledLeaves, occupiedTermLabels, Labels.node] + have hc (i : Fin (selectedChildren S).card) : + (Labels.node T (roles := r) (fun i => ((selectedChildren S).equivFin.symm i).val) + (fun i => occupiedTermLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm i).val) (u i))).child T i = + occupiedTermLabels T b (selectedChildLeaves S + ((selectedChildren S).equivFin.symm i).val) (u i) := by rfl + simp_rw [hc,ih] + ext v + constructor + · intro hv + obtain ⟨i,hi,hv⟩ := Finset.mem_biUnion.mp hv + obtain ⟨w,hw,rfl⟩ := Finset.mem_image.mp hv + exact (mem_selectedChildLeaves _ _ _).mp hw + · intro hv + have hc : v.1∈selectedChildren S := Finset.mem_image.mpr ⟨v,hv,rfl⟩ + let i := (selectedChildren S).equivFin ⟨v.1,hc⟩ + have he : ((selectedChildren S).equivFin.symm i).val=v.1 := + congrArg Subtype.val ((selectedChildren S).equivFin.symm_apply_apply _) + apply Finset.mem_biUnion.mpr + refine ⟨i,Finset.mem_univ _,?_⟩ + apply Finset.mem_image.mpr + refine ⟨v.2,?_,?_⟩ + · rw [he] + exact (mem_selectedChildLeaves _ _ _).mpr hv + · exact Prod.ext he rfl + +/-- The shape remembers all the role choices once the actual selected set +is fixed. -/ +theorem occupiedWindowTerm_injective (T : ℕ → ℕ) (b : ℕ) + (S : Finset (WindowLeaf T (b+1))) : Function.Injective (occupiedWindowTerm T b S) := by + induction b with + | zero => + intro a c h + exact eq_of_heq (OccupiedParityTree.node.inj h).2.2 + | succ b ih => + intro a c h + apply Prod.ext + · funext i + exact ih _ ((congrFun (eq_of_heq (OccupiedParityTree.node.inj h).2.1) i)) + · exact eq_of_heq (OccupiedParityTree.node.inj h).2.2 + +/-- Unrestricted shape/label space really covers the coefficient index +without multiplicity. -/ +def occupiedTermEncoding (T : ℕ → ℕ) (b : ℕ) + (w : (S : Finset (WindowLeaf T (b+1))) × OccupiedWindowChoice T b S) : + (t : OccupiedParityTree (b+1)) × t.Labels T := + ⟨occupiedWindowTerm T b w.1 w.2,occupiedTermLabels T b w.1 w.2⟩ + +theorem occupiedTermEncoding_injective (T : ℕ → ℕ) (b : ℕ) : + Function.Injective (occupiedTermEncoding T b) := by + intro w v he + have hS := congrArg (fun z : (t : OccupiedParityTree (b+1)) × t.Labels T => + z.1.labelledLeaves T z.2) he + change (occupiedWindowTerm T b w.1 w.2).labelledLeaves T (occupiedTermLabels T b w.1 w.2)= + (occupiedWindowTerm T b v.1 v.2).labelledLeaves T (occupiedTermLabels T b v.1 v.2) at hS + simp only [occupiedTermLabels_leaves] at hS + cases w with + | mk S a => + cases v with + | mk V c => + dsimp only at hS + subst V + have ht := congrArg Sigma.fst he + have ha := occupiedWindowTerm_injective T b S ht + change a=c at ha + subst c + rfl +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace OccupiedParityTree + +noncomputable def Forced.edgeEquiv {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + BinaryEdge b ⊕ F.ExtraEdge ≃ t.Edge := by + classical + letI : DecidablePred (Set.range F.edge) := fun _ => Classical.propDecidable _ + exact (Equiv.sumCongr (Equiv.ofInjective F.edge F.edge_injective) (Equiv.refl _)).trans + (Equiv.sumCompl (Set.range F.edge)) + +def binaryEdgeCount (b h : ℕ) : ℕ := Fintype.card {e : BinaryEdge b // e.height=h} + +theorem BinaryEdge.height_lt {b : ℕ} (e : BinaryEdge b) : e.height exact e.elim + | succ b ih => + cases e with + | inl i => exact Nat.lt_succ_self _ + | inr z => exact Nat.lt_succ_of_lt (ih z.2) + +theorem binaryEdgeCount_outside (b h : ℕ) (hh : b≤h) : binaryEdgeCount b h=0 := by + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun e => ?_⟩ + have hc := e.val.height_lt + rw [e.property] at hc + omega + +theorem binaryEdgeCount_succ (b h : ℕ) : + binaryEdgeCount (b+1) h = (if b=h then 2 else 0)+2*binaryEdgeCount b h := by + unfold binaryEdgeCount + simp only [Fintype.card_subtype,Finset.card_filter] + change (∑e : Bool ⊕ (Bool × BinaryEdge b), if BinaryEdge.height (b:=b+1) e=h then 1 else 0)=_ + rw [Fintype.sum_sum_type,Fintype.sum_prod_type] + by_cases hb : b=h <;> simp [BinaryEdge.height,hb,two_mul] <;> simp only [Finset.card_filter] <;> rfl + +theorem binaryEdgeCount_eq (b h : ℕ) (hh : h omega + | succ b ih => + rw [binaryEdgeCount_succ] + by_cases he : b=h + · subst h + rw [ite_eq_left rfl,binaryEdgeCount_outside b b le_rfl] + simp + · rw [ite_eq_right he,zero_add,ih (by omega)] + have hsub : b+1-h=(b-h)+1 := by omega + rw [hsub,pow_succ,Nat.mul_comm] + +def Forced.extraCount {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (h : ℕ) : ℕ := + Fintype.card {e : F.ExtraEdge // e.val.height=h} + +theorem Forced.count_partition {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) (h : ℕ) : + F.extraCount h+binaryEdgeCount b h=t.edgeCount h := by + have he := F.edgeEquiv.sum_comp (fun e : t.Edge => if e.height=h then (1:ℕ) else 0) + rw [Fintype.sum_sum_type] at he + change (∑e : BinaryEdge b, if (F.edge e).height=h then 1 else 0)+ + (∑e : F.ExtraEdge, if e.val.height=h then 1 else 0) = + (∑e : t.Edge, if e.height=h then 1 else 0) at he + simp_rw [F.edge_height] at he + unfold Forced.extraCount binaryEdgeCount edgeCount + simp only [Fintype.card_subtype,Finset.card_filter] + omega + +theorem levelCount_bottom {b : ℕ} (t : OccupiedParityTree b) : t.levelCount b=t.leafCount := by + induction t with + | leaf => rfl + | node n children roles ih => exact Finset.sum_congr rfl (fun i _ => ih i) + +/-- The extra bottom coordinates are precisely r-2^b, including the empty +height-zero case. -/ +theorem Forced.card_extraLeafEdge {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) : + Fintype.card F.ExtraLeafEdge=t.leafCount-2^b := by + cases b with + | zero => + cases t + change F.extraCount 0 = _ + have h := F.count_partition 0 + rw [edgeCount_leaf] at h + simp only [leafCount,pow_zero,Nat.sub_self] + omega + | succ b => + change F.extraCount 0 = _ + have h := F.count_partition 0 + rw [binaryEdgeCount_eq (b+1) 0 (by omega),edgeCount_level t 0 (by omega)] at h + simp only [Nat.sub_zero,levelCount_bottom] at h + omega + +/-- Exact source nonforced vertex bound, now for genuine extra edge-label +coordinates rather than an abstract level-count surrogate. -/ +theorem Forced.extraCount_le {b : ℕ} {t : OccupiedParityTree b} (F : t.Forced) + (ht : t.occupied) (h : ℕ) : F.extraCount h≤t.leafCount-2^b := by + by_cases hh : h + ⟨e.val.val,congrArg Fin.val e.property⟩ + apply Fintype.card_le_of_injective f + intro u v he + have he' : u.val.val=v.val.val := congrArg + (fun q : {e : F.ExtraEdge // e.val.height=h.val} => q.val) he + exact Subtype.ext (Subtype.ext he') + +theorem Forced.card_interiorLabels_le (T : ℕ → ℕ) (hT : ∀j,0 T j.val) + change (∏j : Fin b, ∏_e : {e : F.ExtraInteriorEdge // F.interiorHeight e=j}, T j.val) = + ∏e : F.ExtraInteriorEdge,T e.val.val.height at hp + rw [←hp] + simp only [Finset.prod_const,Finset.card_univ] + rw [←Finset.prod_pow] + apply Finset.prod_le_prod + intro j hj + by_cases hz : j.val=0 + · have he : Fintype.card {e : F.ExtraInteriorEdge // F.interiorHeight e=j}=0 := by + apply Fintype.card_eq_zero_iff.mpr + refine ⟨fun e => ?_⟩ + exact e.val.property ((congrArg Fin.val e.property).trans hz) + rw [he,ite_eq_left hz,pow_zero,one_pow] + · rw [ite_eq_right hz] + exact Nat.pow_le_pow_right (hT j.val) (F.interiorFiber_le ht j) + +end OccupiedParityTree +end TraceReconstruction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/Simulation.lean b/lean/OAI/Probability/TraceReconstruction/Simulation.lean index 698ff1ad5f48539859bf40946d74323083563fdc..bfd3bdeb940d7e3e2576540977f404c21919c136 100644 --- a/lean/OAI/Probability/TraceReconstruction/Simulation.lean +++ b/lean/OAI/Probability/TraceReconstruction/Simulation.lean @@ -1,1313 +1,1313 @@ -import OAI.Probability.TraceReconstruction.Energy -import OAI.Probability.TraceReconstruction.Metadata - -namespace OAI - -/-! -# Simulation - -Canonical and filled simulations, central fit, root words, chronology, slots, finite codes, and complete-trace decoding. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Heterogeneous emissions retain their actual outcome type while moving to - the one fixed public chronological order. -/ -theorem dependentProduct_approximates {ι : Type*} [Fintype ι] [DecidableEq ι] - {A : ι → Type*} [∀i,Fintype (A i)] {k : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) - (e : Fin k ≃ ι) (P : ∀i,FiniteLaw (A i)) (f : ∀i,A i → List Bool) - (w : ι → List Bool) (E : ι → ℝ) - (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : - ApproximatesTrace q (FiniteLaw.dependentProduct P) - (fun x => coordinateWord (fun j => f (e j) (x (e j)))) - (coordinateWord (fun j => w (e j))) (∑i,E i) := by - intro F hF - let G := Equiv.piCongrLeft A e - have he (x : ∀j,A (e j)) (j : Fin k) : - cast (congrArg A (e.apply_symm_apply (e j))) (x (e.symm (e j)))=x j := by - rw [←Equiv.piCongrLeft_apply_eq_cast] - exact Equiv.piCongrLeft_apply_apply A e x j - rw [FiniteLaw.dependentProduct_expect_equiv P e] - simp_rw [he] - have H := dependentCoordinate_approximates hq (fun j => P (e j)) - (fun j => f (e j)) (fun j => w (e j)) (fun j => E (e j)) (fun j => h (e j)) F hF - rwa [e.sum_comp] at H - -/-- Each paired mechanism owns two distinct side slots; fillers and old leaf - oracles have their own IDs. This type is independent of every orientation. -/ -abbrev EmissionSlot (m k n : ℕ) := (Fin m × Bool) ⊕ (Fin k ⊕ Fin n) - -def EmissionOutcome (Side Leaf : Type) {m k n : ℕ} : EmissionSlot m k n → Type - | .inl _ => Side - | .inr (.inl _) => Side - | .inr (.inr _) => Leaf - -instance emissionOutcomeFintype {Side Leaf : Type} [Fintype Side] [Fintype Leaf] - {m k n : ℕ} (i : EmissionSlot m k n) : Fintype (EmissionOutcome Side Leaf i) := by - rcases i with a | a - · exact inferInstanceAs (Fintype Side) - · rcases a with a | a - · exact inferInstanceAs (Fintype Side) - · exact inferInstanceAs (Fintype Leaf) - -/-- Actual arrays and slot observations are bijective, not a lossy interface. -/ -def emissionAssignmentEquiv (Side Leaf : Type) (m k n : ℕ) : - ((Fin m → Side × Side) × (Fin k → Side) × (Fin n → Leaf)) ≃ - (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) where - toFun x i := match i with - | .inl (j,false) => (x.1 j).1 - | .inl (j,true) => (x.1 j).2 - | .inr (.inl j) => x.2.1 j - | .inr (.inr j) => x.2.2 j - invFun x := (fun j => (x (.inl (j,false)),x (.inl (j,true))), - fun j => x (.inr (.inl j)),fun j => x (.inr (.inr j))) - left_inv x := by - rcases x with ⟨z,f,l⟩ - change (fun j => ((z j).1,(z j).2),f,l)=(z,f,l) - simp only [Prod.mk.eta] - right_inv x := by - funext i - rcases i with ⟨j,b⟩ | i - · cases b <;> rfl - · cases i <;> rfl - -namespace PairedMechanisms -variable {Side Leaf : Type} [Fintype Side] [Fintype Leaf] {m k n : ℕ} -variable (M : PairedMechanisms Side m) - -def slotLaw (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (bits : Fin m → Bool) (θ : Fin n → Bool) : - (i : EmissionSlot m k n) → FiniteLaw (EmissionOutcome Side Leaf i) - | .inl (j,false) => if bits j then M.second j else M.first j - | .inl (j,true) => if bits j then M.first j else M.second j - | .inr (.inl j) => R j - | .inr (.inr j) => if θ j then Q else P - -theorem slotLaw_mass (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (bits : Fin m → Bool) (θ : Fin n → Bool) - (x : (Fin m → Side × Side) × (Fin k → Side) × (Fin n → Leaf)) : - (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).mass - (emissionAssignmentEquiv Side Leaf m k n x)= - ((FiniteLaw.coordinateProduct (fun j => FiniteLaw.orientedProd (M.first j) (M.second j) (bits j))).prod - ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).mass x := by - change (∏i : EmissionSlot m k n,_)=_ - rw [Fintype.prod_sum_type,Fintype.prod_sum_type,Fintype.prod_prod_type] - simp only [Fintype.prod_bool,slotLaw,emissionAssignmentEquiv,Equiv.coe_fn_mk] - change (∏j : Fin m,_) * ((∏j : Fin k,_) * ∏j : Fin n,_)= - (∏j : Fin m,_) * ((∏j : Fin k,_) * ∏j : Fin n,_) - congr 1 - apply Finset.prod_congr rfl - intro j _ - cases hb : bits j <;> simp [FiniteLaw.orientedProd,hb,FiniteLaw.prod,mul_comm] - -theorem slotLaw_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (bits : Fin m → Bool) (θ : Fin n → Bool) - (F : (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) → ℝ) : - ((FiniteLaw.coordinateProduct (fun j => FiniteLaw.orientedProd (M.first j) (M.second j) (bits j))).prod - ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).expect - (fun x => F (emissionAssignmentEquiv Side Leaf m k n x))= - (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).expect F := by - unfold FiniteLaw.expect - rw [←(emissionAssignmentEquiv Side Leaf m k n).sum_comp] - simp_rw [slotLaw_mass] - -/-- Forgetting only the visible flags recovers the genuine independent side, - filler and leaf laws at every orientation, before any fit restriction. -/ -theorem reportsGiven_slot_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (bits : Fin m → Bool) (θ : Fin n → Bool) - (F : (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) → ℝ) : - ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).expect - (fun x => F (emissionAssignmentEquiv Side Leaf m k n (fun j => (x.1 j).2,x.2)))= - (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).expect F := by - rw [FiniteLaw.expect_prod] - change (M.reportsGiven bits).expect ((fun z : Fin m → Side × Side => - ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ)).expect - (fun b => F (emissionAssignmentEquiv Side Leaf m k n (z,b)))) ∘ - (fun z j => (z j).2))=_ - rw [←FiniteLaw.expect_map] - rw [reportsGiven_forget] - have H := slotLaw_expect M R P Q bits θ F - rw [FiniteLaw.expect_prod] at H - exact H - -/-- The common, bit-blind projection simply forgets flags and concatenates in - the publicly fixed ID order. -/ -def slotDecode (f : Side → List Bool) (g : Leaf → List Bool) : - (i : EmissionSlot m k n) → EmissionOutcome Side Leaf i → List Bool - | .inl _,x => f x - | .inr (.inl _),x => f x - | .inr (.inr _),x => g x - -def slotWord (U V : Fin m → List Bool) (W : Fin k → List Bool) - (atom : Bool → List Bool) (bits : Fin m → Bool) (θ : Fin n → Bool) : - EmissionSlot m k n → List Bool - | .inl (j,false) => if bits j then V j else U j - | .inl (j,true) => if bits j then U j else V j - | .inr (.inl j) => W j - | .inr (.inr j) => atom (θ j) - -def slotCost (E : ℝ) : EmissionSlot m k n → ℝ - | .inl _ => 0 - | .inr (.inl _) => 0 - | .inr (.inr _) => E - -theorem slotCost_sum (E : ℝ) : (∑i : EmissionSlot m k n,slotCost E i)=(n:ℝ)*E := by - simp only [Fintype.sum_sum_type,slotCost,Finset.sum_const_zero, - zero_add,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - -theorem slotLaw_simulation {q E : ℝ} (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) - (W : Fin k → List Bool) (atom : Bool → List Bool) - (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) - (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) - (hW : ∀j,SimulatesTrace q (R j) f (W j)) - (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) - (bits : Fin m → Bool) (θ : Fin n → Bool) (i : EmissionSlot m k n) : - ApproximatesTrace q (M.slotLaw R P Q bits θ i) (slotDecode f g i) - (slotWord U V W atom bits θ i) (slotCost E i) := by - rcases i with ⟨j,b⟩ | i - · cases b <;> cases hb : bits j <;> - simp only [slotLaw,slotWord,slotCost,hb,Bool.false_eq_true,ite_false,ite_true] - · exact (hU j).approximate - · exact (hV j).approximate - · exact (hV j).approximate - · exact (hU j).approximate - · rcases i with j | j - · exact (hW j).approximate - · cases hb : θ j <;> simp only [slotLaw,slotWord,slotCost,hb,Bool.false_eq_true] - · exact hP - · exact hQ - -/-- Exact conditional-on-orientation simulation boundary. The orientation is - not part of the common projection, and no fit conditioning enters its law. -/ -theorem reportsGiven_simulation {q E : ℝ} (hq : q∈Set.Icc 0 1) - {L : ℕ} (e : Fin L ≃ EmissionSlot m k n) - (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) - (W : Fin k → List Bool) (atom : Bool → List Bool) - (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) - (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) - (hW : ∀j,SimulatesTrace q (R j) f (W j)) - (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) - (bits : Fin m → Bool) (θ : Fin n → Bool) : - ApproximatesTrace q - ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))) - (fun x => coordinateWord (fun j => slotDecode f g (e j) - (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j)))) - (coordinateWord (fun j => slotWord U V W atom bits θ (e j))) ((n:ℝ)*E) := by - intro F hF - dsimp only - rw [M.reportsGiven_slot_expect R P Q bits θ - (fun z => F (coordinateWord (fun j => slotDecode f g (e j) (z (e j)))))] - have H := dependentProduct_approximates hq e (M.slotLaw R P Q bits θ) (slotDecode f g) - (slotWord U V W atom bits θ) (slotCost E) - (M.slotLaw_simulation R P Q f g U V W atom hU hV hW hP hQ bits θ) F hF - rwa [slotCost_sum] at H - -end PairedMechanisms -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace PairedMechanisms -variable {Side Leaf : Type} [Fintype Side] [Fintype Leaf] {m k n : ℕ} -variable (M : PairedMechanisms Side m) - -/-- The actual metadata-first oracle with independent genuine fillers has - exactly the orientation-first product experiment, in the displayed order. -/ -theorem canonical_filled_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (θ : (Fin m → Bool) → Fin n → Bool) - (F : Reports Side m × (Fin k → Side) × (Fin n → Leaf) → ℝ) : - ((M.canonicalOracle P Q θ).prod (FiniteLaw.coordinateProduct R)).expect - (fun x => F (x.1.1,x.2,x.1.2))= - (fairOrientations m).expect (fun bits => - ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod - (selectedLeafLaw P Q (θ bits)))).expect F) := by - rw [←M.oracle_factorization,orientationOracle,FiniteLaw.expect_prod,FiniteLaw.expect_mixture] - simp_rw [FiniteLaw.expect_prod] - congr 1 - funext bits - congr 1 - funext z - exact FiniteLaw.expect_comm _ _ (fun leaf fill => F (z,fill,leaf)) - -/-- Unconditional common simulation of the actual full canonical oracle. - The only layout charge is the unconditional fair-orientation failure mass. - No orientation or side metadata is conditioned on successful fitting. -/ -theorem canonical_filled_simulation {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) - {L : ℕ} (e : Fin L ≃ EmissionSlot m k n) - (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) - (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) - (W : Fin k → List Bool) (atom : Bool → List Bool) - (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) - (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) - (hW : ∀j,SimulatesTrace q (R j) f (W j)) - (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) - (θ : (Fin m → Bool) → Fin n → Bool) (w : List Bool) - (good : (Fin m → Bool) → Prop) [DecidablePred good] - (hword : ∀bits,good bits → coordinateWord - (fun j => slotWord U V W atom bits (θ bits) (e j))=w) : - ApproximatesTrace q ((M.canonicalOracle P Q θ).prod (FiniteLaw.coordinateProduct R)) - (fun x => coordinateWord (fun j => slotDecode f g (e j) - (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1.1 i).2,x.2,x.1.2) (e j)))) - w ((n:ℝ)*E+(fairOrientations m).expect (fun bits => if good bits then 0 else 1)) := by - intro F hF - dsimp only - rw [M.canonical_filled_expect R P Q θ (fun x => F (coordinateWord (fun j => slotDecode f g (e j) - (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j)))))] - rw [←FiniteLaw.expect_const (fairOrientations m) (listDeletionExpectation q w F),←FiniteLaw.expect_sub] - apply (FiniteLaw.abs_expect_le _ _).trans - calc - _ ≤ (fairOrientations m).expect (fun bits => (n:ℝ)*E+(if good bits then 0 else 1)) := by - apply FiniteLaw.expect_mono - intro bits - by_cases hb : good bits - · simp only [ite_eq_left hb,add_zero] - have H := M.reportsGiven_simulation hq e R P Q f g U V W atom hU hV hW hP hQ bits (θ bits) F hF - rwa [hword bits hb] at H - · simp only [ite_eq_right hb] - have hc := listDeletionExpectation_range hq w F hF - have hlo := FiniteLaw.expect_mono - ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q (θ bits)))) - (fun x => (hF (coordinateWord (fun j => slotDecode f g (e j) - (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j))))).1) - have hhi := FiniteLaw.expect_mono - ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q (θ bits)))) - (fun x => (hF (coordinateWord (fun j => slotDecode f g (e j) - (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j))))).2) - rw [FiniteLaw.expect_const] at hlo hhi - have hne : 0≤(n:ℝ)*E := mul_nonneg (Nat.cast_nonneg _) hE - apply abs_sub_le_iff.mpr - constructor <;> linarith [hc.1,hc.2] - _ = _ := by - unfold FiniteLaw.expect - simp only [mul_add,Finset.sum_add_distrib,←Finset.sum_mul,(fairOrientations m).total,one_mul] - -end PairedMechanisms -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The one-based source offset still puts the complete motif in the central - third under the true fit threshold. The stronger numerical margin is an - eventual consequence of L=o(T), not an additional stochastic event. -/ -theorem source_motif_central (T t s : ℕ) (bits : Fin t → Bool) (v : ℤ) - (hT : 24 ≤ T) (he : Even T) (hL : 24*2^s ≤ T) - (hfit : |8*((∑i,(bitIndex (bits i):ℤ))-(t/2:ℕ)+v)| ≤ (T:ℤ)) - (u : Fin T) - (hu : motifIndicator s ((u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+ - (∑i,(bitIndex (bits i):ℤ))+v)≠0) : u∈centralThird T := by - have hsupport : 0≤(u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+ - (∑i,(bitIndex (bits i):ℤ))+v ∧ - (u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+(∑i,(bitIndex (bits i):ℤ))+v < (2^s:ℕ) := by - by_contra h - apply hu - exact ite_eq_right h - have hh := abs_le.mp hfit - obtain ⟨k,hk⟩ := he - have hhalf : 2*(T/2)=T := by omega - apply Finset.mem_filter.mpr - refine ⟨Finset.mem_univ _,?_⟩ - omega - -/-- Fit controls every internal source motif, retaining all orientations in - the law. The incoming displacement of the root is supplied separately. -/ -theorem sourceTreeFit_central (T n : ℕ → ℕ) (s b : ℕ) - (center : ℕ → ℤ) (hc : ∀j≤b,center j=sourceLocalCenter T n j) - (hT : ∀j≤b,24≤T j) (he : ∀j≤b,Even (T j)) (hL : ∀j≤b,24*2^s≤T j) - (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (incoming : ℤ) - (hroot : |8*((∑i,(bitIndex (bits.1 i):ℤ))-(n b/2:ℕ)+incoming)|≤(T b:ℤ)) - (hfit : SourceTreeFit T n (b+1) bits) : - SourceCentral T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) - (fun j => centralThird (T j)) (b+1) bits incoming := by - induction b generalizing incoming with - | zero => - constructor - · intro u hu - rw [hc 0 (by omega)] at hu - exact source_motif_central (T 0) (n 0) s bits.1 incoming - (hT 0 (by omega)) (he 0 (by omega)) (hL 0 (by omega)) hroot u hu - · intro u; trivial - | succ b ih => - constructor - · intro u hu - rw [hc (b+1) (by omega)] at hu - exact source_motif_central (T (b+1)) (n (b+1)) s bits.1 incoming - (hT (b+1) (by omega)) (he (b+1) (by omega)) (hL (b+1) (by omega)) hroot u hu - · intro u - apply ih (fun j hj => hc j (by omega)) (fun j hj => hT j (by omega)) - (fun j hj => he j (by omega)) (fun j hj => hL j (by omega)) _ _ _ (hfit.2 u) - exact hfit.1 u - -/-- The actual root side count has no parity restriction. Its entire range - lies inside the fit displacement interval when J=o(T). -/ -theorem source_root_fit (T J : ℕ) (bits : Fin J → Bool) (h : 4*(J+1)≤T) : - |8*((∑i,(bitIndex (bits i):ℤ))-(J/2:ℕ))|≤(T:ℤ) := by - have hlo : (0:ℤ)≤∑i,(bitIndex (bits i):ℤ) := Finset.sum_nonneg (fun _ _ => Int.natCast_nonneg _) - have hhi : (∑i,(bitIndex (bits i):ℤ))≤J := by - calc - _ ≤ ∑_i : Fin J,(1:ℤ) := by - apply Finset.sum_le_sum - intro i _ - cases bits i <;> norm_num [bitIndex] - _ = J := by simp - apply abs_le.mpr - omega - -theorem sourceNoncentralMass_le_fit (T n : ℕ → ℕ) (s b : ℕ) - (center : ℕ → ℤ) (hc : ∀j≤b,center j=sourceLocalCenter T n j) - (hT : ∀j≤b,24≤T j) (he : ∀j≤b,Even (T j)) (hL : ∀j≤b,24*2^s≤T j) - (hroot : 4*(n b+1)≤T b) - (d : WindowAssignments T n (sourceScheduledTrials T n) (Option Bool) (b+1)) : - sourceNoncentralMass T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) - (fun j => centralThird (T j)) (b+1) d 0 ≤ - (windowPosteriorLaw T n (sourceScheduledTrials T n) (b+1) d).expect - (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1) := by - apply FiniteLaw.expect_mono - intro bits - by_cases hf : SourceTreeFit T n (b+1) bits - · have hh := sourceTreeFit_central T n s b center hc hT he hL bits 0 - (by simpa only [add_zero] using source_root_fit (T b) (n b) bits.1 hroot) hf - simp only [ite_eq_left hf,ite_eq_left hh,le_refl] - · simp only [ite_eq_right hf] - split_ifs <;> norm_num - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Only interior trials are paired in even bundles. The top J may be odd. -/ -theorem sourceTreeWord_eq_center_interior (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) - (atom : Bool → List Bool) (b : ℕ) (H : SourceLayoutMargins s P T n h (b-1)) - (htop : ∀j rfl - | one => rfl - | more b ih₁ ih₂ => - change (Fin (n (b+1)) → Bool) × (Fin ((T (b+1)/4)*n b) → Bool) × - (Fin (T (b+1)) → WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) at bits - let loc : Fin (T (b+1)) → Fin (n b) → Bool := fun u => (bits.2.2 u).1 - let glob := bits.2.1 - let a := P b/2-1 - let A := sourceNominalPre P T b - let B := sourceNominalPost P T b - let start := sourceWindowStart (T (b+1)) A (n b) loc glob - let θ := integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ - have hb : b htop j (by omega)) (fun j hj => hc j (by omega)) _ _ _ (hfit.2 u)] - simp only [sourceCenterWord,hx,integerTemplateType_nat,complementaryWords] - have hstartnonneg (u : Fin (T (b+1))) : 0≤(A:ℤ)+sourceDisplacement (T (b+1)) (n b) loc glob u := by - have he := sourceWindowStart_cast_of_fit (T (b+1)) (P b) (T b) (n b) loc glob - (H.ambient b hb) (H.large b hb) u (hfit.1 u) - have hn : (0:ℤ)≤(start u:ℕ) := Int.natCast_nonneg _ - change (start u:ℤ)=(A:ℤ)+_ at he - omega - have hp := htop (b+1) (by omega) - obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : T (b+1)≠0) - have hpart : (List.ofFn (fun u => complementaryWords (P b) a (2^s) (prouhetBool s) - (sourceBlockWord s P atom b) (θ u))).flatten= - coordinateWord (fun u => pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by - have hh := sourceLayout_literal_partition k A (T b) B (n b) (h b) a (2^s) - have hk' : k+1=T (b+1) := hk.symm - rw [hk'] at hh - rw [show A+T b+B=P b from htotal] at hh - exact hh (H.even_trials b hb) (H.pre_reserve b hb) (H.post_reserve b hb) loc glob - (prouhetBool s) (sourceBlockWord s P atom b) θ hstartnonneg - (fun u => (hf u).2.1) (fun u => (hf u).2.2) (fun u => (hf u).1) - change coordinateWord (fun u : Fin (T (b+1)) => - pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) - (sourceScheduledShift T n (b+1) glob u) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u))= - atomString (T (b+1)) (sourceBlockWord s P atom (b+1)) θ - calc - _ = coordinateWord (fun u : Fin (T (b+1)) => - pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ - complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by - apply congrArg coordinateWord - funext u - exact congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ w ++ - pureAtomRun (sourceBlockWord s P atom b false) - (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) (hchild u) - _ = _ := hpart.symm - - - -/-- Full literal unconditioned root partition, including both members of - every outer paired side. Its top trial count is the source's J, even or odd. -/ -def sourceFullWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) - (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (τ : Bool) : List Bool := - pureAtomRun (sourceBlockWord s P atom b false) (n b*h b+∑i,bitIndex (bits.1 i)) ++ - sourceTreeWord s P T n h (sourceLocalCenter T n) atom (b+1) bits 0 τ ++ - pureAtomRun (sourceBlockWord s P atom b false) (n b*(h b+1)-∑i,bitIndex (bits.1 i)) - -theorem bitIndex_sum_le {J : ℕ} (bits : Fin J → Bool) : (∑i,bitIndex (bits i))≤J := by - calc - _ ≤ ∑_i : Fin J,1 := by - apply Finset.sum_le_sum - intro i _ - cases bits i <;> norm_num [bitIndex] - _ = J := by simp - -/-- The source root's floor anchor and paired side counts have their literal - unmarked word interpretation, without requiring J to be even. -/ -theorem sourceFullWord_eq_block (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) - (b : ℕ) (H : SourceLayoutMargins s P T n h b) (hpos : 0 rfl) bits 0 τ hfit - have hpart := template_word_window t (T b) z a (2^s) (prouhetBool s) τ - (sourceBlockWord s P atom b) ht hz - rw [htotal] at hpart - rw [atomString_constant,atomString_constant] at hpart - unfold sourceFullWord - rw [hcenter] - change pureAtomRun (sourceBlockWord s P atom b false) t ++ - atomString (T b) (sourceBlockWord s P atom b) - (integerTemplateType (T b) s (sourceNodeAnchor T n (sourceLocalCenter T n) b bits 0) τ) ++ - pureAtomRun (sourceBlockWord s P atom b false) z = _ - rw [hanchor,integerTemplateType_nat] - exact hpart.symm - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Pure filler IDs. At bottom leaf windows the two fillers have zero length; - they are deterministic empty outputs, not extra information. -/ -def WindowFiller (T : ℕ → ℕ) : ℕ → Type - | 0 => PEmpty - | b+1 => (Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b) - -noncomputable instance windowFillerFintype (T : ℕ → ℕ) : (b : ℕ) → Fintype (WindowFiller T b) - | 0 => inferInstanceAs (Fintype PEmpty) - | b+1 => by - letI := windowFillerFintype T b - exact inferInstanceAs (Fintype ((Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b))) - -abbrev TreeEmission (T n g : ℕ → ℕ) (b : ℕ) := - (WindowTrial T n g b × Bool) ⊕ (WindowFiller T b ⊕ WindowLeaf T b) - -def TreeEmission.up (T n g : ℕ → ℕ) (b : ℕ) (u : Fin (T b)) : - TreeEmission T n g b → TreeEmission T n g (b+1) - | .inl (i,p) => .inl (.inr (.inr (u,i)),p) - | .inr (.inl f) => .inr (.inl (.inr (u,f))) - | .inr (.inr v) => .inr (.inr (u,v)) - -def treeLocalSlots (T n g : ℕ → ℕ) (b : ℕ) (p : Bool) : List (TreeEmission T n g (b+1)) := - List.ofFn (fun k : Fin (n b) => Sum.inl (Sum.inl k,p)) - -def treeGlobalSlots (T n g : ℕ → ℕ) (b : ℕ) (p : Bool) - (pos : Fin (g b) → Fin (T b)) (u : Fin (T b)) : List (TreeEmission T n g (b+1)) := - ((List.ofFn id : List (Fin (g b))).filter (fun k => pos k=u)).map - (fun k => Sum.inl (Sum.inr (Sum.inl k),p)) - -/-- Public chronological IDs. Each child carries its own local paired sides; - the group's global sides and deterministic fillers surround that child. - The order is fixed independently of all bits and both hypotheses. -/ -def treeChronology (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) : - (b : ℕ) → List (TreeEmission T n g b) - | 0 => [.inr (.inr (show WindowLeaf T 0 from (0 : Fin 1)))] - | b+1 => treeLocalSlots T n g b false ++ - (List.ofFn (fun u : Fin (T b) => - treeGlobalSlots T n g b false (pre b) u ++ - [.inr (.inl (.inl (u,false)))] ++ - (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) ++ - treeGlobalSlots T n g b true (post b) u ++ - [.inr (.inl (.inl (u,true)))])).flatten ++ - treeLocalSlots T n g b true - -theorem sum_fiber_list_length {α ι : Type*} [Fintype ι] [DecidableEq ι] (pos : α → ι) (l : List α) : - (∑i,(l.filter (fun a => pos a=i)).length)=l.length := by - induction l with - | nil => simp - | cons a l ih => - have hh (i : ι) : ((a::l).filter (fun a => pos a=i)).length= - (if pos a=i then 1 else 0)+(l.filter (fun a => pos a=i)).length := by - by_cases h : pos a=i <;> simp [h,Nat.add_comm] - simp_rw [hh] - rw [Finset.sum_add_distrib,ih] - simp [Nat.add_comm] - -theorem treeChronology_length (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : - (treeChronology T n g pre post b).length=Fintype.card (TreeEmission T n g b) := by - induction b with - | zero => - change 1=Fintype.card ((PEmpty × Bool) ⊕ (PEmpty ⊕ Fin 1)) - simp - | succ b ih => - have hp := sum_fiber_list_length (pre b) (List.ofFn id : List (Fin (g b))) - have hq := sum_fiber_list_length (post b) (List.ofFn id : List (Fin (g b))) - simp only [List.length_ofFn] at hp hq - change _=Fintype.card (((Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b))) × Bool) ⊕ - (((Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b)) ⊕ (Fin (T b) × WindowLeaf T b))) - simp only [treeChronology,treeLocalSlots,treeGlobalSlots,List.length_append, - List.length_flatten,List.map_ofFn,Function.comp_apply,List.length_ofFn,List.length_map,List.length_cons,List.length_nil, - Finset.sum_add_distrib,List.sum_ofFn,ih,Fintype.card_sum,Fintype.card_prod,Fintype.card_fin,Fintype.card_bool] - rw [hp,hq] - simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul] - ring - -theorem treeChronology_mem (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) - (x : TreeEmission T n g b) : x∈treeChronology T n g pre post b := by - induction b with - | zero => - rcases x with ⟨i,p⟩ | f | v - · exact PEmpty.elim i - · exact PEmpty.elim f - · change Fin 1 at v - have hv : v=0 := Subsingleton.elim _ _ - subst v; exact List.mem_singleton.mpr rfl - | succ b ih => - have hc (u : Fin (T b)) (x : TreeEmission T n g (b+1)) - (hx : x∈treeGlobalSlots T n g b false (pre b) u ++ [.inr (.inl (.inl (u,false)))] ++ - (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) ++ - treeGlobalSlots T n g b true (post b) u ++ [.inr (.inl (.inl (u,true)))]) : - x∈treeChronology T n g pre post (b+1) := by - apply List.mem_append_left - apply List.mem_append_right - apply List.mem_flatten.mpr - exact ⟨_,List.mem_ofFn.mpr ⟨u,rfl⟩,hx⟩ - rcases x with ⟨k,p⟩ | f | v - · rcases k with k | k | ⟨u,k⟩ - · cases p <;> - simp [treeChronology,treeLocalSlots,List.mem_ofFn] - · cases p - · apply hc (pre b k) - simp only [List.mem_append,treeGlobalSlots,List.mem_map,List.mem_filter,List.mem_ofFn] - exact Or.inl (Or.inl (Or.inl (Or.inl ⟨k,⟨⟨k,rfl⟩,by simp⟩,rfl⟩))) - · apply hc (post b k) - simp only [List.mem_append,treeGlobalSlots,List.mem_map,List.mem_filter,List.mem_ofFn] - exact Or.inl (Or.inr ⟨k,⟨⟨k,rfl⟩,by simp⟩,rfl⟩) - · apply hc u - have hm : TreeEmission.up T n g b u (.inl (k,p))∈ - (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ - exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) - · rcases f with ⟨u,p⟩ | ⟨u,f⟩ - · cases p <;> apply hc u <;> simp - · apply hc u - have hm : TreeEmission.up T n g b u (.inr (.inl f))∈ - (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ - exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) - · rcases v with ⟨u,v⟩ - apply hc u - have hm : TreeEmission.up T n g b u (.inr (.inr v))∈ - (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ - exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) - -theorem treeChronology_nodup (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : - (treeChronology T n g pre post b).Nodup := by - have hs : (treeChronology T n g pre post b).toFinset=Finset.univ := by - ext x - simp only [List.mem_toFinset,Finset.mem_univ,iff_true] - exact treeChronology_mem T n g pre post b x - have hh : (treeChronology T n g pre post b).toFinset.card=(treeChronology T n g pre post b).length := by - rw [hs,Finset.card_univ,treeChronology_length] - exact Multiset.coe_nodup.mp ((Multiset.toFinset_card_eq_card_iff_nodup - (m := (treeChronology T n g pre post b : Multiset (TreeEmission T n g b)))).mp hh) - - -/-- A genuine complete chronological bijection, not an assumed layout. -/ -def treeChronologyEquiv (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : - Fin (treeChronology T n g pre post b).length ≃ TreeEmission T n g b := - List.Nodup.getEquivOfForallMemList _ (treeChronology_nodup T n g pre post b) - (treeChronology_mem T n g pre post b) - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def pairedSideCount (h : ℕ) (bit side : Bool) : ℕ := h+bitIndex (Bool.xor bit side) - -theorem pairedSideCount_false (h : ℕ) (bit : Bool) : - pairedSideCount h bit false=h+bitIndex bit := by cases bit <;> rfl - -theorem pairedSideCount_true (h : ℕ) (bit : Bool) : - pairedSideCount h bit true=h+1-bitIndex bit := by cases bit <;> simp [pairedSideCount,bitIndex] - -theorem pairedSideCount_sum_pre {t h : ℕ} (bits : Fin t → Bool) : - (∑i,pairedSideCount h (bits i) false)=t*h+∑i,bitIndex (bits i) := by - simp only [pairedSideCount_false,Finset.sum_add_distrib,Finset.sum_const, - Finset.card_univ,Fintype.card_fin,smul_eq_mul] - -theorem pairedSideCount_sum_total {t h : ℕ} (bits : Fin t → Bool) : - (∑i,pairedSideCount h (bits i) true)+(∑i,bitIndex (bits i))=t*(h+1) := by - rw [←Finset.sum_add_distrib] - calc - _ = ∑_i : Fin t,(h+1) := by - apply Finset.sum_congr rfl - intro i _ - cases bits i <;> simp [pairedSideCount,bitIndex] - _ = _ := by simp - -theorem pairedSideCount_sum_post {t h : ℕ} (bits : Fin t → Bool) : - (∑i,pairedSideCount h (bits i) true)=t*(h+1)-∑i,bitIndex (bits i) := by - have := pairedSideCount_sum_total (h:=h) bits - omega - -/-- Global trial positions are ID functions, not positions inferred from a - realized output or orientation. -/ -def sourceGlobalPre (N t : ℕ) (k : Fin ((N/4)*t)) : Fin N := - ⟨((globalTrialEquiv N t).symm k).1.val,by - have := ((globalTrialEquiv N t).symm k).1.isLt; omega⟩ - -def sourceGlobalPost (N t : ℕ) (k : Fin ((N/4)*t)) : Fin N := - ⟨N-1-((globalTrialEquiv N t).symm k).1.val,by - have := ((globalTrialEquiv N t).symm k).1.isLt; omega⟩ - -theorem sum_globalSides (N t h : ℕ) (bits : Fin ((N/4)*t) → Bool) - (side : Bool) (pos : Fin (N/4) → Fin N) (u : Fin N) : - (∑k : Fin ((N/4)*t), if pos ((globalTrialEquiv N t).symm k).1=u then - pairedSideCount h (bits k) side else 0)= - ∑v : Fin (N/4),if pos v=u then - (∑a : Fin t,pairedSideCount h (bits (globalTrialIndex N t v a)) side) else 0 := by - rw [←(globalTrialEquiv N t).sum_comp,Fintype.sum_prod_type] - apply Finset.sum_congr rfl - intro v _ - simp only [Equiv.symm_apply_apply] - split_ifs with hv - · rfl - · simp only [Finset.sum_const_zero] - -theorem sourcePreCount_slots (N A t h : ℕ) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : - sourcePreCount N A t h loc glob u= - (∑k : Fin ((N/4)*t),if sourceGlobalPre N t k=u then pairedSideCount h (glob k) false else 0)+ - sourcePreFiller N A t h u+(∑i,pairedSideCount h (loc u i) false) := by - rw [pairedSideCount_sum_pre] - change sourcePreFiller N A t h u+(∑v : SourceBundle N, - if sourceBundleLeft N v=u then sourceBundleCount N t h loc glob v else 0)=_ - rw [Fintype.sum_sum_type] - have hl : (∑v : Fin N,if sourceBundleLeft N (.inl v)=u then - sourceBundleCount N t h loc glob (.inl v) else 0)=t*h+∑i,bitIndex (loc u i) := by - change (∑v : Fin N,if v=u then (t*h+(∑i,bitIndex (loc v i))) else 0)=_ - simp - rw [hl] - have hg := sum_globalSides N t h glob false - (fun v => ⟨v.val,by have := v.isLt; omega⟩) u - simp only [pairedSideCount_sum_pre] at hg - change (∑k,if sourceGlobalPre N t k=u then pairedSideCount h (glob k) false else 0)=_ at hg - rw [hg] - change _+(_+_) = _+_+_ - have he : (∑v : Fin (N/4),if sourceBundleLeft N (.inr v)=u then - sourceBundleCount N t h loc glob (.inr v) else 0)= - ∑v : Fin (N/4),if (⟨v.val,by have := v.isLt; omega⟩ : Fin N)=u then - (t*h+∑i,bitIndex (glob (globalTrialIndex N t v i))) else 0 := by - apply Finset.sum_congr rfl - intro v _ - rfl - rw [he] - omega - -theorem sourcePostCount_slots (N B t h : ℕ) (ht : Even t) (loc : Fin N → Fin t → Bool) - (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : - sourcePostCount N B t h loc glob u= - (∑i,pairedSideCount h (loc u i) true)+ - (∑k : Fin ((N/4)*t),if sourceGlobalPost N t k=u then pairedSideCount h (glob k) true else 0)+ - sourcePostFiller N B t h u := by - have hh : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) - have hc (bits : Fin t → Bool) : - 2*sourceLayoutReserve t h-(t*h+∑i,bitIndex (bits i))= - ∑i,pairedSideCount h (bits i) true := by - rw [pairedSideCount_sum_post] - dsimp only [sourceLayoutReserve] - have hs := bitIndex_sum_le bits - have he : 2*(t*h+t/2)=t*h+t*(h+1) := by - rw [Nat.mul_add,Nat.mul_add,Nat.mul_one,hh] - omega - rw [he] - omega - change sourcePostFiller N B t h u+(∑v : SourceBundle N, - if sourceBundleRight N v=u then 2*sourceLayoutReserve t h-sourceBundleCount N t h loc glob v else 0)=_ - rw [Fintype.sum_sum_type] - have hl : (∑v : Fin N,if sourceBundleRight N (.inl v)=u then - 2*sourceLayoutReserve t h-sourceBundleCount N t h loc glob (.inl v) else 0)= - ∑i,pairedSideCount h (loc u i) true := by - simp only [sourceBundleRight,sourceBundleCount,Finset.sum_ite_eq',Finset.mem_univ,ite_true,hc] - rw [hl] - have hg := sum_globalSides N t h glob true - (fun v => ⟨N-1-v.val,by have := v.isLt; omega⟩) u - change (∑k,if sourceGlobalPost N t k=u then pairedSideCount h (glob k) true else 0)=_ at hg - rw [hg] - simp only [sourceBundleRight,sourceBundleCount,hc] - omega - -/-- Flattening selected equal-atom chunks sums exactly their genuine lengths. -/ -theorem filter_chunks_flatten {ι : Type*} [Fintype ι] [DecidableEq ι] - (l : List ι) (p : ι → Bool) (c : ι → ℕ) (w : List Bool) : - ((l.filter p).map (fun i => pureAtomRun w (c i))).flatten= - pureAtomRun w ((l.map (fun i => if p i then c i else 0)).sum) := by - calc - _ = pureAtomRun w (((l.filter p).map c).sum) := by - simpa only [List.map_map,Function.comp_def] using pureAtomRun_partition w ((l.filter p).map c) - _ = _ := by - congr 1 - induction l with - | nil => rfl - | cons i l ih => cases hp : p i <;> simp [hp,ih] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def sourceScheduledPre (T n : ℕ → ℕ) : - (b : ℕ) → Fin (sourceScheduledTrials T n b) → Fin (T b) - | 0,k => Fin.elim0 k - | b+1,k => sourceGlobalPre (T (b+1)) (n b) k - -def sourceScheduledPost (T n : ℕ → ℕ) : - (b : ℕ) → Fin (sourceScheduledTrials T n b) → Fin (T b) - | 0,k => Fin.elim0 k - | b+1,k => sourceGlobalPost (T (b+1)) (n b) k - -/-- Two actual deterministic pure binary side words for each paired trial ID. -/ -def sourceTrialWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) : - (b : ℕ) → WindowTrial T n (sourceScheduledTrials T n) b → Bool → List Bool - | 0,i,_ => PEmpty.elim i - | b+1,.inl _,c => pureAtomRun (sourceBlockWord s P atom b false) (h b+bitIndex c) - | 1,.inr (.inl k),_ => Fin.elim0 k - | b+2,.inr (.inl _),c => pureAtomRun (sourceBlockWord s P atom b false) (h b+bitIndex c) - | b+1,.inr (.inr (_,i)),c => sourceTrialWord s P T n h atom b i c - -/-- Fixed pure fillers, including the deterministic empty bottom fillers. -/ -def sourceFillerWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) : - (b : ℕ) → WindowFiller T b → List Bool - | 0,i => PEmpty.elim i - | b+1,.inl (u,p) => match b,u with - | 0,_ => [] - | b+1,u => pureAtomRun (sourceBlockWord s P atom b false) - (if p then sourcePostFiller (T (b+1)) (sourceNominalPost P T b) (n b) (h b) u - else sourcePreFiller (T (b+1)) (sourceNominalPre P T b) (n b) (h b) u) - | b+1,.inr (_,i) => sourceFillerWord s P T n h atom b i - -def sourceSlotWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) - (incoming : ℤ) (τ : Bool) : TreeEmission T n (sourceScheduledTrials T n) b → List Bool - | .inl (i,side) => sourceTrialWord s P T n h atom b i - (Bool.xor (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool b bits i) side) - | .inr (.inl i) => sourceFillerWord s P T n h atom b i - | .inr (.inr v) => atom (sourceTreeLeafBool T n s center b bits incoming τ v) - -def sourceChronologicalWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) - (incoming : ℤ) (τ : Bool) : List Bool := - ((treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).map - (sourceSlotWord s P T n h center atom b bits incoming τ)).flatten - -theorem sourceSlotWord_up (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) - (incoming : ℤ) (τ : Bool) (u : Fin (T b)) (x : TreeEmission T n (sourceScheduledTrials T n) b) : - sourceSlotWord s P T n h center atom (b+1) bits incoming τ (TreeEmission.up T n (sourceScheduledTrials T n) b u x)= - sourceSlotWord s P T n h center atom b (bits.2.2 u) (sourceScheduledShift T n b bits.2.1 u) - (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ u) x := by - rcases x with ⟨i,p⟩ | f | v <;> rfl - -theorem treeChronology_eval (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) - (f : TreeEmission T n g (b+1) → List Bool) : - ((treeChronology T n g pre post (b+1)).map f).flatten= - ((treeLocalSlots T n g b false).map f).flatten ++ - coordinateWord (fun u => ((treeGlobalSlots T n g b false (pre b) u).map f).flatten ++ - f (.inr (.inl (.inl (u,false)))) ++ - ((treeChronology T n g pre post b).map (fun x => f (TreeEmission.up T n g b u x))).flatten ++ - ((treeGlobalSlots T n g b true (post b) u).map f).flatten ++ - f (.inr (.inl (.inl (u,true))))) ++ - ((treeLocalSlots T n g b true).map f).flatten := by - simp only [treeChronology,List.map_append,List.flatten_append,List.map_flatten, - List.map_ofFn,coordinateWord] - congr 2 - rw [List.flatten_flatten,List.map_ofFn] - apply congrArg List.flatten - apply congrArg List.ofFn - funext u - simp only [Function.comp_apply,List.map_append,List.flatten_append,List.map_cons,List.map_nil, - List.flatten_cons,List.flatten_nil,List.append_nil,List.map_map] - rfl - -theorem sourceLocalSlots_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) - (incoming : ℤ) (τ side : Bool) : - ((treeLocalSlots T n (sourceScheduledTrials T n) b side).map - (sourceSlotWord s P T n h center atom (b+1) bits incoming τ)).flatten= - pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) side) := by - rcases bits with ⟨loc,glob,kids⟩ - simp only [treeLocalSlots,List.map_ofFn] - change (List.ofFn (fun i : Fin (n b) => pureAtomRun (sourceBlockWord s P atom b false) - (pairedSideCount (h b) (loc i) side))).flatten=_ - exact coordinateWord_pureAtomRun _ _ - -theorem sourceGlobalSlots_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) - (incoming : ℤ) (τ side : Bool) (pos : Fin ((T (b+1)/4)*n b) → Fin (T (b+1))) (u : Fin (T (b+1))) : - ((treeGlobalSlots T n (sourceScheduledTrials T n) (b+1) side pos u).map - (sourceSlotWord s P T n h center atom (b+2) bits incoming τ)).flatten= - pureAtomRun (sourceBlockWord s P atom b false) - (∑k,if pos k=u then pairedSideCount (h b) (bits.2.1 k) side else 0) := by - rcases bits with ⟨loc,glob,kids⟩ - change Fin ((T (b+1)/4)*n b) → Bool at glob - simp only [treeGlobalSlots,List.map_map] - change ((List.filter (fun k => decide (pos k=u)) (List.ofFn id)).map - (fun i => pureAtomRun (sourceBlockWord s P atom b false) (pairedSideCount (h b) (glob i) side))).flatten=_ - rw [filter_chunks_flatten,List.map_ofFn,List.sum_ofFn] - simp only [Function.comp_apply,id_eq,decide_eq_true_eq] - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def sourceFramedWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : - (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool - | 0,_,_,τ => atom τ - | b+1,bits,incoming,τ => - pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) false) ++ - sourceTreeWord s P T n h center atom (b+1) bits incoming τ ++ - pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) true) - -theorem sourceChronologicalWord_eq_framed (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) - (atom : Bool → List Bool) (b : ℕ) (hev : ∀j,j+1 simp [sourceChronologicalWord,treeChronology,sourceSlotWord,sourceTreeLeafBool,sourceFramedWord] - | succ b ih => - rcases bits with ⟨loc,glob,kids⟩ - unfold sourceChronologicalWord - rw [treeChronology_eval] - erw [sourceLocalSlots_word,sourceLocalSlots_word] - change _=pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) false) ++ - sourceTreeWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ ++ - pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) true) - apply congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) - (∑i,pairedSideCount (h b) (loc i) false) ++ w ++ - pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) true)) - have child (u : Fin (T b)) : - ((treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).map - (fun x => sourceSlotWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ - (TreeEmission.up T n (sourceScheduledTrials T n) b u x))).flatten= - sourceFramedWord s P T n h center atom b (kids u) (sourceScheduledShift T n b glob u) - (integerTemplateType (T b) s (sourceNodeAnchor T n center b (loc,glob,kids) incoming) τ u) := by - have he : (fun x : TreeEmission T n (sourceScheduledTrials T n) b => - sourceSlotWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ - (TreeEmission.up T n (sourceScheduledTrials T n) b u x)) = - sourceSlotWord s P T n h center atom b (kids u) (sourceScheduledShift T n b glob u) - (integerTemplateType (T b) s (sourceNodeAnchor T n center b (loc,glob,kids) incoming) τ u) := by - funext x - exact sourceSlotWord_up s P T n h center atom b (loc,glob,kids) incoming τ u x - erw [he] - exact ih (fun j hj => hev j (by omega)) (kids u) _ _ - cases b with - | zero => - change coordinateWord _=atomString (T 0) atom _ - apply congrArg coordinateWord - funext u - rw [child] - simp only [treeGlobalSlots,sourceScheduledTrials,List.ofFn_zero,List.filter_nil,List.map_nil, - List.flatten_nil,List.nil_append,List.append_nil,sourceSlotWord,sourceFillerWord,sourceFramedWord] - | succ b => - change coordinateWord _=coordinateWord _ - apply congrArg coordinateWord - funext u - erw [sourceGlobalSlots_word,sourceGlobalSlots_word,child] - change _=pureAtomRun (sourceBlockWord s P atom b false) - (sourcePreCount (T (b+1)) (sourceNominalPre P T b) (n b) (h b) (fun v => (kids v).1) glob u) ++ - sourceTreeWord s P T n h center atom (b+1) (kids u) (sourceScheduledShift T n (b+1) glob u) - (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) (loc,glob,kids) incoming) τ u) ++ - pureAtomRun (sourceBlockWord s P atom b false) - (sourcePostCount (T (b+1)) (sourceNominalPost P T b) (n b) (h b) (fun v => (kids v).1) glob u) - erw [sourcePreCount_slots,sourcePostCount_slots _ _ _ _ (hev b (by omega))] - change pureAtomRun _ _ ++ pureAtomRun _ _ ++ - (pureAtomRun _ _ ++ sourceTreeWord s P T n h center atom (b+1) (kids u) - (sourceScheduledShift T n (b+1) glob u) - (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) (loc,glob,kids) incoming) τ u) ++ - pureAtomRun _ _) ++ pureAtomRun _ _ ++ pureAtomRun _ _ = _ - simp only [sourceScheduledPre,sourceScheduledPost,pureAtomRun_add,List.append_assoc, - Bool.false_eq_true,ite_false,ite_true] - rfl - -/-- Chronological side/filler/leaf slots produce the SAME full source word - on the joint fit event. No orientation is removed or conditioned away. -/ -theorem sourceChronologicalWord_eq_block (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) - (b : ℕ) (H : SourceLayoutMargins s P T n h b) - (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) - (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) - (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (τ : Bool) - (hfit : SourceTreeFit T n (b+1) bits) : - sourceChronologicalWord s P T n h (sourceLocalCenter T n) atom (b+1) bits 0 τ= - sourceBlockWord s P atom (b+1) τ := by - rw [sourceChronologicalWord_eq_framed s P T n h (sourceLocalCenter T n) atom (b+1) - (fun j hj => H.even_trials j (by omega))] - have hf := sourceFullWord_eq_block s P T n h atom b H (by omega) hP hT hlarge hmotif bits τ hfit - change sourceFullWord s P T n h atom b bits τ=_ at hf - simpa only [sourceFramedWord,sourceFullWord,pairedSideCount_sum_pre,pairedSideCount_sum_post] using hf - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -def finEnumeration (α : Type) [Fintype α] : Fin (Fintype.card α) ≃ α := (Fintype.equivFin α).symm - -abbrev SourceTrialCount (T n : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowTrial T n (sourceScheduledTrials T n) b) -abbrev SourceFillerCount (T : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowFiller T b) -abbrev SourceLeafCount (T : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowLeaf T b) - -def sourceEmissionEnum (T n : ℕ → ℕ) (b : ℕ) : - EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b) ≃ - TreeEmission T n (sourceScheduledTrials T n) b := - Equiv.sumCongr (Equiv.prodCongr (finEnumeration _) (Equiv.refl Bool)) - (Equiv.sumCongr (finEnumeration _) (finEnumeration _)) - -def sourceAssignmentCode (T n : ℕ → ℕ) (A : Type) (b : ℕ) : - WindowAssignments T n (sourceScheduledTrials T n) A b ≃ (Fin (SourceTrialCount T n b) → A) where - toFun bits j := windowAssignmentEquiv T n (sourceScheduledTrials T n) A b bits (finEnumeration _ j) - invFun bits := (windowAssignmentEquiv T n (sourceScheduledTrials T n) A b).symm - (fun i => bits ((finEnumeration _).symm i)) - left_inv bits := by simp only [Equiv.apply_symm_apply,Equiv.symm_apply_apply] - right_inv bits := by - funext j - simp only [Equiv.apply_symm_apply,Equiv.symm_apply_apply] - -theorem sourceAssignmentCode_eval (T n : ℕ → ℕ) (A : Type) (b : ℕ) - (bits : Fin (SourceTrialCount T n b) → A) (j : Fin (SourceTrialCount T n b)) : - windowAssignmentEquiv T n (sourceScheduledTrials T n) A b - ((sourceAssignmentCode T n A b).symm bits) (finEnumeration _ j)=bits j := by - change (sourceAssignmentCode T n A b ((sourceAssignmentCode T n A b).symm bits)) j=bits j - rw [Equiv.apply_symm_apply] - -def sourceChronologyCode (T n : ℕ → ℕ) (b : ℕ) : - Fin (treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).length ≃ - EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b) := - (treeChronologyEquiv T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).trans - (sourceEmissionEnum T n b).symm - -def sourceFlatLeafType (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) (b : ℕ) (incoming : ℤ) (τ : Bool) - (bits : Fin (SourceTrialCount T n b) → Bool) (j : Fin (SourceLeafCount T b)) : Bool := - sourceTreeLeafBool T n s center b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ (finEnumeration _ j) - -def sourceFlatTrialWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) - (c : Bool) (j : Fin (SourceTrialCount T n b)) : List Bool := - sourceTrialWord s P T n h atom b (finEnumeration _ j) c - -def sourceFlatFillerWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) - (j : Fin (SourceFillerCount T b)) : List Bool := - sourceFillerWord s P T n h atom b (finEnumeration _ j) - -theorem sourceSlotWord_code (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : Fin (SourceTrialCount T n b) → Bool) (incoming : ℤ) (τ : Bool) - (x : EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b)) : - sourceSlotWord s P T n h center atom b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ - (sourceEmissionEnum T n b x)= - PairedMechanisms.slotWord (sourceFlatTrialWord s P T n h atom b false) - (sourceFlatTrialWord s P T n h atom b true) (sourceFlatFillerWord s P T n h atom b) atom bits - (sourceFlatLeafType T n s center b incoming τ bits) x := by - rcases x with ⟨j,p⟩ | f | v - · cases p <;> - change sourceTrialWord s P T n h atom b (finEnumeration _ j) - (Bool.xor (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool b - ((sourceAssignmentCode T n Bool b).symm bits) (finEnumeration _ j)) _) = _ <;> - rw [sourceAssignmentCode_eval] <;> cases he : bits j <;> simp [PairedMechanisms.slotWord,he,sourceFlatTrialWord] - · rfl - · rfl - -theorem treeChronologyEquiv_word (T n g : ℕ → ℕ) - (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) - (f : TreeEmission T n g b → List Bool) : - coordinateWord (fun j => f (treeChronologyEquiv T n g pre post b j))= - ((treeChronology T n g pre post b).map f).flatten := by - unfold coordinateWord treeChronologyEquiv - change (List.ofFn (fun j => f ((treeChronology T n g pre post b).get j))).flatten=_ - have hh : List.map f (List.ofFn (treeChronology T n g pre post b).get) = - List.ofFn (f ∘ (treeChronology T n g pre post b).get) := List.map_ofFn - rw [List.ofFn_get] at hh - exact congrArg List.flatten hh.symm - -theorem source_slotCode_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) - (b : ℕ) (bits : Fin (SourceTrialCount T n b) → Bool) (incoming : ℤ) (τ : Bool) : - coordinateWord (fun j => PairedMechanisms.slotWord (sourceFlatTrialWord s P T n h atom b false) - (sourceFlatTrialWord s P T n h atom b true) (sourceFlatFillerWord s P T n h atom b) atom bits - (sourceFlatLeafType T n s center b incoming τ bits) (sourceChronologyCode T n b j))= - sourceChronologicalWord s P T n h center atom b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ := by - simp_rw [←sourceSlotWord_code] - simp only [sourceChronologyCode,Equiv.trans_apply,Equiv.apply_symm_apply] - exact treeChronologyEquiv_word T n (sourceScheduledTrials T n) (sourceScheduledPre T n) - (sourceScheduledPost T n) b _ - -end TraceReconstruction - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Reindex the genuine independent orientations, retaining the whole source tree. -/ -theorem source_fair_code_expect (T n : ℕ → ℕ) (b : ℕ) - (F : WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℝ) : - (PairedMechanisms.fairOrientations (SourceTrialCount T n b)).expect - (fun bits => F ((sourceAssignmentCode T n Bool b).symm bits)) = - (windowPosteriorLaw T n (sourceScheduledTrials T n) b - (noReveals T n (sourceScheduledTrials T n) b)).expect F := by - rw [windowPosterior_fair_flat,FiniteLaw.indexedProduct_expect_equiv _ (finEnumeration _)] - simp only [PairedMechanisms.fairOrientations,FiniteLaw.expect,FiniteLaw.product, - FiniteLaw.indexedProduct,sourceAssignmentCode,Equiv.coe_fn_symm_mk] - apply Finset.sum_congr (by ext; simp) - intro bits _ - rfl - -/-- The fit event uses only interior even bundles. In particular no parity - assumption is made on the top root count J. -/ -theorem sourceTreeFit_tail_interior (T n : ℕ → ℕ) (b : ℕ) - (hn : ∀j,j+1 if SourceTreeFit T n b bits then 0 else 1) ≤ sourceFitTail T n b := by - induction b using Nat.twoStepInduction with - | zero => - have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 0) : SourceTreeFit T n 0 bits := trivial - simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] - | one => - have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 1) : SourceTreeFit T n 1 bits := trivial - simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] - | more b ih0 ih => - let P := windowPosteriorLaw T n (sourceScheduledTrials T n) (b+2) - (noReveals T n (sourceScheduledTrials T n) (b+2)) - let badShift : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2) → Fin (T (b+1)) → Prop := - fun bits u => (T b:ℝ)/8≤|(sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| - have hp (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) : - (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ - (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ - (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by - let p := fun u : Fin (T (b+1)) => |8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u|≤(T b:ℤ) - have hh : (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ - (if ∀u,p u then 0 else 1)+(if ∀u,SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by - by_cases H : SourceTreeFit T n (b+2) bits - · rw [ite_eq_left H] - split_ifs <;> norm_num - · rw [ite_eq_right H] - by_cases h1 : ∀u,p u - · have h2 : ¬∀u,SourceTreeFit T n (b+1) (bits.2.2 u) := fun h2 => H ⟨h1,h2⟩ - rw [ite_eq_left h1,ite_eq_right h2] - norm_num - · rw [ite_eq_right h1] - split_ifs <;> norm_num - apply hh.trans - apply add_le_add - · apply (failure_forall_le_sum p).trans - apply Finset.sum_le_sum - intro u _ - by_cases hu : p u - · simp only [ite_eq_left hu] - split_ifs <;> norm_num - · have hr : (T b:ℝ)<8*|(sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| := by - have hi : (T b:ℤ) < |8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u| := lt_of_not_ge hu - have hi' : (T b:ℝ) < |(8*sourceDisplacement (T (b+1)) (n b) - (fun v => (bits.2.2 v).1) bits.2.1 u:ℤ)| := by exact_mod_cast hi - norm_num only [Int.cast_abs,Int.cast_mul,Int.cast_ofNat,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<8)] at hi' - exact hi' - have hb : badShift bits u := by dsimp [badShift]; linarith - simp [hu,hb] - · exact failure_forall_le_sum _ - calc - _ ≤ P.expect (fun bits => (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ - (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := - P.expect_mono hp - _ = (∑u : Fin (T (b+1)),P.expect (fun bits => if badShift bits u then 1 else 0))+ - (∑u : Fin (T (b+1)),P.expect (fun bits => if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := by - rw [FiniteLaw.expect_add,FiniteLaw.expect_fintype_sum,FiniteLaw.expect_fintype_sum] - _ ≤ (∑_u : Fin (T (b+1)),2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ))))+ - ∑_u : Fin (T (b+1)),sourceFitTail T n (b+1) := by - apply add_le_add - · apply Finset.sum_le_sum - intro u _ - exact sourceDisplacement_tail T n b (he b (by omega)) (hn b (by omega)) u (by positivity) - · apply Finset.sum_le_sum - intro u _ - dsimp only [P] - rw [windowPosterior_child T n (sourceScheduledTrials T n) (b+1) - (noReveals T n (sourceScheduledTrials T n) (b+2)) u - (fun x => if SourceTreeFit T n (b+1) x then 0 else 1)] - rw [noReveals_succ] - exact ih (fun j hj => hn j (by omega)) (fun j hj => he j (by omega)) - _ = sourceFitTail T n (b+2) := by simp [sourceFitTail,mul_add] - - -/-- Honest source joint-fit failure after the actual finite coding. -/ -theorem source_flat_fit_tail (T n : ℕ → ℕ) (b : ℕ) - (hn : ∀j,j+1 if SourceTreeFit T n b ((sourceAssignmentCode T n Bool b).symm bits) then 0 else 1) - ≤ sourceFitTail T n b := by - rw [source_fair_code_expect T n b (fun bits => if SourceTreeFit T n b bits then 0 else 1)] - exact sourceTreeFit_tail_interior T n b hn he - -/-- A fixed public decoder. It does not know the hidden orientations or the - input hypothesis, and it drops rather than reveals all pairing flags. -/ -def sourceOracleDecode {Side Leaf : Type} (T n : ℕ → ℕ) (b : ℕ) - (f : Side → List Bool) (g : Leaf → List Bool) : - ((Reports Side (SourceTrialCount T n b) × (Fin (SourceLeafCount T b) → Leaf)) × - (Fin (SourceFillerCount T b) → Side)) → List Bool := fun x => - coordinateWord (fun j => PairedMechanisms.slotDecode f g (sourceChronologyCode T n b j) - (emissionAssignmentEquiv Side Leaf (SourceTrialCount T n b) (SourceFillerCount T b) - (SourceLeafCount T b) (fun i => (x.1.1 i).2,x.2,x.1.2) (sourceChronologyCode T n b j))) - -/-- The complete canonical oracle now simulates the LITERAL source block. - All IDs, words, leaf types and chronology instantiate the actual construction. - The only failed-layout cost is its original unconditional fair-bit mass. -/ -theorem source_canonical_simulation {Side Leaf : Type} [Fintype Side] [Fintype Leaf] - {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) - (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) - (H : SourceLayoutMargins s P T n h b) - (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) - (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) - (hn : ∀j - SourceTreeFit T n (b+1) ((sourceAssignmentCode T n Bool (b+1)).symm bits) - have hw (bits : Fin (SourceTrialCount T n (b+1)) → Bool) (hg : good bits) := - sourceChronologicalWord_eq_block s P T n h atom b H hP hT hlarge hmotif - ((sourceAssignmentCode T n Bool (b+1)).symm bits) τ hg - have hs := M.canonical_filled_simulation hq hE (sourceChronologyCode T n (b+1)) R A B f g - (sourceFlatTrialWord s P T n h atom (b+1) false) - (sourceFlatTrialWord s P T n h atom (b+1) true) - (sourceFlatFillerWord s P T n h atom (b+1)) atom hU hV hW hA hB - (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) - (sourceBlockWord s P atom (b+1) τ) good (fun bits hg => by - rw [source_slotCode_word] - exact hw bits hg) - intro F hF - exact (hs F hF).trans (add_le_add le_rfl (source_flat_fit_tail T n (b+1) (fun j hj => hn j (by omega)) - (fun j hj => H.even_trials j (by omega)))) - -end TraceReconstruction - -end -end -end -end -end -end -end -end -end -end -end - -end OAI +import OAI.Probability.TraceReconstruction.Energy +import OAI.Probability.TraceReconstruction.Metadata + +namespace OAI + +/-! +# Simulation + +Canonical and filled simulations, central fit, root words, chronology, slots, finite codes, and complete-trace decoding. +-/ + +open scoped ENNReal +noncomputable section + +open Filter +open scoped Topology + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Heterogeneous emissions retain their actual outcome type while moving to + the one fixed public chronological order. -/ +theorem dependentProduct_approximates {ι : Type*} [Fintype ι] [DecidableEq ι] + {A : ι → Type*} [∀i,Fintype (A i)] {k : ℕ} {q : ℝ} (hq : q∈Set.Icc 0 1) + (e : Fin k ≃ ι) (P : ∀i,FiniteLaw (A i)) (f : ∀i,A i → List Bool) + (w : ι → List Bool) (E : ι → ℝ) + (h : ∀i,ApproximatesTrace q (P i) (f i) (w i) (E i)) : + ApproximatesTrace q (FiniteLaw.dependentProduct P) + (fun x => coordinateWord (fun j => f (e j) (x (e j)))) + (coordinateWord (fun j => w (e j))) (∑i,E i) := by + intro F hF + let G := Equiv.piCongrLeft A e + have he (x : ∀j,A (e j)) (j : Fin k) : + cast (congrArg A (e.apply_symm_apply (e j))) (x (e.symm (e j)))=x j := by + rw [←Equiv.piCongrLeft_apply_eq_cast] + exact Equiv.piCongrLeft_apply_apply A e x j + rw [FiniteLaw.dependentProduct_expect_equiv P e] + simp_rw [he] + have H := dependentCoordinate_approximates hq (fun j => P (e j)) + (fun j => f (e j)) (fun j => w (e j)) (fun j => E (e j)) (fun j => h (e j)) F hF + rwa [e.sum_comp] at H + +/-- Each paired mechanism owns two distinct side slots; fillers and old leaf + oracles have their own IDs. This type is independent of every orientation. -/ +abbrev EmissionSlot (m k n : ℕ) := (Fin m × Bool) ⊕ (Fin k ⊕ Fin n) + +def EmissionOutcome (Side Leaf : Type) {m k n : ℕ} : EmissionSlot m k n → Type + | .inl _ => Side + | .inr (.inl _) => Side + | .inr (.inr _) => Leaf + +instance emissionOutcomeFintype {Side Leaf : Type} [Fintype Side] [Fintype Leaf] + {m k n : ℕ} (i : EmissionSlot m k n) : Fintype (EmissionOutcome Side Leaf i) := by + rcases i with a | a + · exact inferInstanceAs (Fintype Side) + · rcases a with a | a + · exact inferInstanceAs (Fintype Side) + · exact inferInstanceAs (Fintype Leaf) + +/-- Actual arrays and slot observations are bijective, not a lossy interface. -/ +def emissionAssignmentEquiv (Side Leaf : Type) (m k n : ℕ) : + ((Fin m → Side × Side) × (Fin k → Side) × (Fin n → Leaf)) ≃ + (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) where + toFun x i := match i with + | .inl (j,false) => (x.1 j).1 + | .inl (j,true) => (x.1 j).2 + | .inr (.inl j) => x.2.1 j + | .inr (.inr j) => x.2.2 j + invFun x := (fun j => (x (.inl (j,false)),x (.inl (j,true))), + fun j => x (.inr (.inl j)),fun j => x (.inr (.inr j))) + left_inv x := by + rcases x with ⟨z,f,l⟩ + change (fun j => ((z j).1,(z j).2),f,l)=(z,f,l) + simp only [Prod.mk.eta] + right_inv x := by + funext i + rcases i with ⟨j,b⟩ | i + · cases b <;> rfl + · cases i <;> rfl + +namespace PairedMechanisms +variable {Side Leaf : Type} [Fintype Side] [Fintype Leaf] {m k n : ℕ} +variable (M : PairedMechanisms Side m) + +def slotLaw (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (bits : Fin m → Bool) (θ : Fin n → Bool) : + (i : EmissionSlot m k n) → FiniteLaw (EmissionOutcome Side Leaf i) + | .inl (j,false) => if bits j then M.second j else M.first j + | .inl (j,true) => if bits j then M.first j else M.second j + | .inr (.inl j) => R j + | .inr (.inr j) => if θ j then Q else P + +theorem slotLaw_mass (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (bits : Fin m → Bool) (θ : Fin n → Bool) + (x : (Fin m → Side × Side) × (Fin k → Side) × (Fin n → Leaf)) : + (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).mass + (emissionAssignmentEquiv Side Leaf m k n x)= + ((FiniteLaw.coordinateProduct (fun j => FiniteLaw.orientedProd (M.first j) (M.second j) (bits j))).prod + ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).mass x := by + change (∏i : EmissionSlot m k n,_)=_ + rw [Fintype.prod_sum_type,Fintype.prod_sum_type,Fintype.prod_prod_type] + simp only [Fintype.prod_bool,slotLaw,emissionAssignmentEquiv,Equiv.coe_fn_mk] + change (∏j : Fin m,_) * ((∏j : Fin k,_) * ∏j : Fin n,_)= + (∏j : Fin m,_) * ((∏j : Fin k,_) * ∏j : Fin n,_) + congr 1 + apply Finset.prod_congr rfl + intro j _ + cases hb : bits j <;> simp [FiniteLaw.orientedProd,hb,FiniteLaw.prod,mul_comm] + +theorem slotLaw_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (bits : Fin m → Bool) (θ : Fin n → Bool) + (F : (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) → ℝ) : + ((FiniteLaw.coordinateProduct (fun j => FiniteLaw.orientedProd (M.first j) (M.second j) (bits j))).prod + ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).expect + (fun x => F (emissionAssignmentEquiv Side Leaf m k n x))= + (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).expect F := by + unfold FiniteLaw.expect + rw [←(emissionAssignmentEquiv Side Leaf m k n).sum_comp] + simp_rw [slotLaw_mass] + +/-- Forgetting only the visible flags recovers the genuine independent side, + filler and leaf laws at every orientation, before any fit restriction. -/ +theorem reportsGiven_slot_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (bits : Fin m → Bool) (θ : Fin n → Bool) + (F : (∀i : EmissionSlot m k n,EmissionOutcome Side Leaf i) → ℝ) : + ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))).expect + (fun x => F (emissionAssignmentEquiv Side Leaf m k n (fun j => (x.1 j).2,x.2)))= + (FiniteLaw.dependentProduct (M.slotLaw R P Q bits θ)).expect F := by + rw [FiniteLaw.expect_prod] + change (M.reportsGiven bits).expect ((fun z : Fin m → Side × Side => + ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ)).expect + (fun b => F (emissionAssignmentEquiv Side Leaf m k n (z,b)))) ∘ + (fun z j => (z j).2))=_ + rw [←FiniteLaw.expect_map] + rw [reportsGiven_forget] + have H := slotLaw_expect M R P Q bits θ F + rw [FiniteLaw.expect_prod] at H + exact H + +/-- The common, bit-blind projection simply forgets flags and concatenates in + the publicly fixed ID order. -/ +def slotDecode (f : Side → List Bool) (g : Leaf → List Bool) : + (i : EmissionSlot m k n) → EmissionOutcome Side Leaf i → List Bool + | .inl _,x => f x + | .inr (.inl _),x => f x + | .inr (.inr _),x => g x + +def slotWord (U V : Fin m → List Bool) (W : Fin k → List Bool) + (atom : Bool → List Bool) (bits : Fin m → Bool) (θ : Fin n → Bool) : + EmissionSlot m k n → List Bool + | .inl (j,false) => if bits j then V j else U j + | .inl (j,true) => if bits j then U j else V j + | .inr (.inl j) => W j + | .inr (.inr j) => atom (θ j) + +def slotCost (E : ℝ) : EmissionSlot m k n → ℝ + | .inl _ => 0 + | .inr (.inl _) => 0 + | .inr (.inr _) => E + +theorem slotCost_sum (E : ℝ) : (∑i : EmissionSlot m k n,slotCost E i)=(n:ℝ)*E := by + simp only [Fintype.sum_sum_type,slotCost,Finset.sum_const_zero, + zero_add,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + +theorem slotLaw_simulation {q E : ℝ} (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) + (W : Fin k → List Bool) (atom : Bool → List Bool) + (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) + (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) + (hW : ∀j,SimulatesTrace q (R j) f (W j)) + (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) + (bits : Fin m → Bool) (θ : Fin n → Bool) (i : EmissionSlot m k n) : + ApproximatesTrace q (M.slotLaw R P Q bits θ i) (slotDecode f g i) + (slotWord U V W atom bits θ i) (slotCost E i) := by + rcases i with ⟨j,b⟩ | i + · cases b <;> cases hb : bits j <;> + simp only [slotLaw,slotWord,slotCost,hb,Bool.false_eq_true,ite_false,ite_true] + · exact (hU j).approximate + · exact (hV j).approximate + · exact (hV j).approximate + · exact (hU j).approximate + · rcases i with j | j + · exact (hW j).approximate + · cases hb : θ j <;> simp only [slotLaw,slotWord,slotCost,hb,Bool.false_eq_true] + · exact hP + · exact hQ + +/-- Exact conditional-on-orientation simulation boundary. The orientation is + not part of the common projection, and no fit conditioning enters its law. -/ +theorem reportsGiven_simulation {q E : ℝ} (hq : q∈Set.Icc 0 1) + {L : ℕ} (e : Fin L ≃ EmissionSlot m k n) + (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) + (W : Fin k → List Bool) (atom : Bool → List Bool) + (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) + (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) + (hW : ∀j,SimulatesTrace q (R j) f (W j)) + (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) + (bits : Fin m → Bool) (θ : Fin n → Bool) : + ApproximatesTrace q + ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q θ))) + (fun x => coordinateWord (fun j => slotDecode f g (e j) + (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j)))) + (coordinateWord (fun j => slotWord U V W atom bits θ (e j))) ((n:ℝ)*E) := by + intro F hF + dsimp only + rw [M.reportsGiven_slot_expect R P Q bits θ + (fun z => F (coordinateWord (fun j => slotDecode f g (e j) (z (e j)))))] + have H := dependentProduct_approximates hq e (M.slotLaw R P Q bits θ) (slotDecode f g) + (slotWord U V W atom bits θ) (slotCost E) + (M.slotLaw_simulation R P Q f g U V W atom hU hV hW hP hQ bits θ) F hF + rwa [slotCost_sum] at H + +end PairedMechanisms +end TraceReconstruction + + +noncomputable section +namespace TraceReconstruction +open scoped Classical +namespace PairedMechanisms +variable {Side Leaf : Type} [Fintype Side] [Fintype Leaf] {m k n : ℕ} +variable (M : PairedMechanisms Side m) + +/-- The actual metadata-first oracle with independent genuine fillers has + exactly the orientation-first product experiment, in the displayed order. -/ +theorem canonical_filled_expect (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (θ : (Fin m → Bool) → Fin n → Bool) + (F : Reports Side m × (Fin k → Side) × (Fin n → Leaf) → ℝ) : + ((M.canonicalOracle P Q θ).prod (FiniteLaw.coordinateProduct R)).expect + (fun x => F (x.1.1,x.2,x.1.2))= + (fairOrientations m).expect (fun bits => + ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod + (selectedLeafLaw P Q (θ bits)))).expect F) := by + rw [←M.oracle_factorization,orientationOracle,FiniteLaw.expect_prod,FiniteLaw.expect_mixture] + simp_rw [FiniteLaw.expect_prod] + congr 1 + funext bits + congr 1 + funext z + exact FiniteLaw.expect_comm _ _ (fun leaf fill => F (z,fill,leaf)) + +/-- Unconditional common simulation of the actual full canonical oracle. + The only layout charge is the unconditional fair-orientation failure mass. + No orientation or side metadata is conditioned on successful fitting. -/ +theorem canonical_filled_simulation {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) + {L : ℕ} (e : Fin L ≃ EmissionSlot m k n) + (R : Fin k → FiniteLaw Side) (P Q : FiniteLaw Leaf) + (f : Side → List Bool) (g : Leaf → List Bool) (U V : Fin m → List Bool) + (W : Fin k → List Bool) (atom : Bool → List Bool) + (hU : ∀j,SimulatesTrace q (M.first j) f (U j)) + (hV : ∀j,SimulatesTrace q (M.second j) f (V j)) + (hW : ∀j,SimulatesTrace q (R j) f (W j)) + (hP : ApproximatesTrace q P g (atom false) E) (hQ : ApproximatesTrace q Q g (atom true) E) + (θ : (Fin m → Bool) → Fin n → Bool) (w : List Bool) + (good : (Fin m → Bool) → Prop) [DecidablePred good] + (hword : ∀bits,good bits → coordinateWord + (fun j => slotWord U V W atom bits (θ bits) (e j))=w) : + ApproximatesTrace q ((M.canonicalOracle P Q θ).prod (FiniteLaw.coordinateProduct R)) + (fun x => coordinateWord (fun j => slotDecode f g (e j) + (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1.1 i).2,x.2,x.1.2) (e j)))) + w ((n:ℝ)*E+(fairOrientations m).expect (fun bits => if good bits then 0 else 1)) := by + intro F hF + dsimp only + rw [M.canonical_filled_expect R P Q θ (fun x => F (coordinateWord (fun j => slotDecode f g (e j) + (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j)))))] + rw [←FiniteLaw.expect_const (fairOrientations m) (listDeletionExpectation q w F),←FiniteLaw.expect_sub] + apply (FiniteLaw.abs_expect_le _ _).trans + calc + _ ≤ (fairOrientations m).expect (fun bits => (n:ℝ)*E+(if good bits then 0 else 1)) := by + apply FiniteLaw.expect_mono + intro bits + by_cases hb : good bits + · simp only [ite_eq_left hb,add_zero] + have H := M.reportsGiven_simulation hq e R P Q f g U V W atom hU hV hW hP hQ bits (θ bits) F hF + rwa [hword bits hb] at H + · simp only [ite_eq_right hb] + have hc := listDeletionExpectation_range hq w F hF + have hlo := FiniteLaw.expect_mono + ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q (θ bits)))) + (fun x => (hF (coordinateWord (fun j => slotDecode f g (e j) + (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j))))).1) + have hhi := FiniteLaw.expect_mono + ((M.reportsGiven bits).prod ((FiniteLaw.coordinateProduct R).prod (selectedLeafLaw P Q (θ bits)))) + (fun x => (hF (coordinateWord (fun j => slotDecode f g (e j) + (emissionAssignmentEquiv Side Leaf m k n (fun i => (x.1 i).2,x.2) (e j))))).2) + rw [FiniteLaw.expect_const] at hlo hhi + have hne : 0≤(n:ℝ)*E := mul_nonneg (Nat.cast_nonneg _) hE + apply abs_sub_le_iff.mpr + constructor <;> linarith [hc.1,hc.2] + _ = _ := by + unfold FiniteLaw.expect + simp only [mul_add,Finset.sum_add_distrib,←Finset.sum_mul,(fairOrientations m).total,one_mul] + +end PairedMechanisms +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- The one-based source offset still puts the complete motif in the central + third under the true fit threshold. The stronger numerical margin is an + eventual consequence of L=o(T), not an additional stochastic event. -/ +theorem source_motif_central (T t s : ℕ) (bits : Fin t → Bool) (v : ℤ) + (hT : 24 ≤ T) (he : Even T) (hL : 24*2^s ≤ T) + (hfit : |8*((∑i,(bitIndex (bits i):ℤ))-(t/2:ℕ)+v)| ≤ (T:ℤ)) + (u : Fin T) + (hu : motifIndicator s ((u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+ + (∑i,(bitIndex (bits i):ℤ))+v)≠0) : u∈centralThird T := by + have hsupport : 0≤(u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+ + (∑i,(bitIndex (bits i):ℤ))+v ∧ + (u.val:ℤ)-((T/2:ℕ)-1+(t/2:ℕ))+(∑i,(bitIndex (bits i):ℤ))+v < (2^s:ℕ) := by + by_contra h + apply hu + exact ite_eq_right h + have hh := abs_le.mp hfit + obtain ⟨k,hk⟩ := he + have hhalf : 2*(T/2)=T := by omega + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + omega + +/-- Fit controls every internal source motif, retaining all orientations in + the law. The incoming displacement of the root is supplied separately. -/ +theorem sourceTreeFit_central (T n : ℕ → ℕ) (s b : ℕ) + (center : ℕ → ℤ) (hc : ∀j≤b,center j=sourceLocalCenter T n j) + (hT : ∀j≤b,24≤T j) (he : ∀j≤b,Even (T j)) (hL : ∀j≤b,24*2^s≤T j) + (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (incoming : ℤ) + (hroot : |8*((∑i,(bitIndex (bits.1 i):ℤ))-(n b/2:ℕ)+incoming)|≤(T b:ℤ)) + (hfit : SourceTreeFit T n (b+1) bits) : + SourceCentral T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) + (fun j => centralThird (T j)) (b+1) bits incoming := by + induction b generalizing incoming with + | zero => + constructor + · intro u hu + rw [hc 0 (by omega)] at hu + exact source_motif_central (T 0) (n 0) s bits.1 incoming + (hT 0 (by omega)) (he 0 (by omega)) (hL 0 (by omega)) hroot u hu + · intro u; trivial + | succ b ih => + constructor + · intro u hu + rw [hc (b+1) (by omega)] at hu + exact source_motif_central (T (b+1)) (n (b+1)) s bits.1 incoming + (hT (b+1) (by omega)) (he (b+1) (by omega)) (hL (b+1) (by omega)) hroot u hu + · intro u + apply ih (fun j hj => hc j (by omega)) (fun j hj => hT j (by omega)) + (fun j hj => he j (by omega)) (fun j hj => hL j (by omega)) _ _ _ (hfit.2 u) + exact hfit.1 u + +/-- The actual root side count has no parity restriction. Its entire range + lies inside the fit displacement interval when J=o(T). -/ +theorem source_root_fit (T J : ℕ) (bits : Fin J → Bool) (h : 4*(J+1)≤T) : + |8*((∑i,(bitIndex (bits i):ℤ))-(J/2:ℕ))|≤(T:ℤ) := by + have hlo : (0:ℤ)≤∑i,(bitIndex (bits i):ℤ) := Finset.sum_nonneg (fun _ _ => Int.natCast_nonneg _) + have hhi : (∑i,(bitIndex (bits i):ℤ))≤J := by + calc + _ ≤ ∑_i : Fin J,(1:ℤ) := by + apply Finset.sum_le_sum + intro i _ + cases bits i <;> norm_num [bitIndex] + _ = J := by simp + apply abs_le.mpr + omega + +theorem sourceNoncentralMass_le_fit (T n : ℕ → ℕ) (s b : ℕ) + (center : ℕ → ℤ) (hc : ∀j≤b,center j=sourceLocalCenter T n j) + (hT : ∀j≤b,24≤T j) (he : ∀j≤b,Even (T j)) (hL : ∀j≤b,24*2^s≤T j) + (hroot : 4*(n b+1)≤T b) + (d : WindowAssignments T n (sourceScheduledTrials T n) (Option Bool) (b+1)) : + sourceNoncentralMass T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) + (fun j => centralThird (T j)) (b+1) d 0 ≤ + (windowPosteriorLaw T n (sourceScheduledTrials T n) (b+1) d).expect + (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1) := by + apply FiniteLaw.expect_mono + intro bits + by_cases hf : SourceTreeFit T n (b+1) bits + · have hh := sourceTreeFit_central T n s b center hc hT he hL bits 0 + (by simpa only [add_zero] using source_root_fit (T b) (n b) bits.1 hroot) hf + simp only [ite_eq_left hf,ite_eq_left hh,le_refl] + · simp only [ite_eq_right hf] + split_ifs <;> norm_num + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Only interior trials are paired in even bundles. The top J may be odd. -/ +theorem sourceTreeWord_eq_center_interior (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) + (atom : Bool → List Bool) (b : ℕ) (H : SourceLayoutMargins s P T n h (b-1)) + (htop : ∀j rfl + | one => rfl + | more b ih₁ ih₂ => + change (Fin (n (b+1)) → Bool) × (Fin ((T (b+1)/4)*n b) → Bool) × + (Fin (T (b+1)) → WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) at bits + let loc : Fin (T (b+1)) → Fin (n b) → Bool := fun u => (bits.2.2 u).1 + let glob := bits.2.1 + let a := P b/2-1 + let A := sourceNominalPre P T b + let B := sourceNominalPost P T b + let start := sourceWindowStart (T (b+1)) A (n b) loc glob + let θ := integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) bits incoming) τ + have hb : b htop j (by omega)) (fun j hj => hc j (by omega)) _ _ _ (hfit.2 u)] + simp only [sourceCenterWord,hx,integerTemplateType_nat,complementaryWords] + have hstartnonneg (u : Fin (T (b+1))) : 0≤(A:ℤ)+sourceDisplacement (T (b+1)) (n b) loc glob u := by + have he := sourceWindowStart_cast_of_fit (T (b+1)) (P b) (T b) (n b) loc glob + (H.ambient b hb) (H.large b hb) u (hfit.1 u) + have hn : (0:ℤ)≤(start u:ℕ) := Int.natCast_nonneg _ + change (start u:ℤ)=(A:ℤ)+_ at he + omega + have hp := htop (b+1) (by omega) + obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : T (b+1)≠0) + have hpart : (List.ofFn (fun u => complementaryWords (P b) a (2^s) (prouhetBool s) + (sourceBlockWord s P atom b) (θ u))).flatten= + coordinateWord (fun u => pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by + have hh := sourceLayout_literal_partition k A (T b) B (n b) (h b) a (2^s) + have hk' : k+1=T (b+1) := hk.symm + rw [hk'] at hh + rw [show A+T b+B=P b from htotal] at hh + exact hh (H.even_trials b hb) (H.pre_reserve b hb) (H.post_reserve b hb) loc glob + (prouhetBool s) (sourceBlockWord s P atom b) θ hstartnonneg + (fun u => (hf u).2.1) (fun u => (hf u).2.2) (fun u => (hf u).1) + change coordinateWord (fun u : Fin (T (b+1)) => + pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + sourceTreeWord s P T n h center atom (b+1) (bits.2.2 u) + (sourceScheduledShift T n (b+1) glob u) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u))= + atomString (T (b+1)) (sourceBlockWord s P atom (b+1)) θ + calc + _ = coordinateWord (fun u : Fin (T (b+1)) => + pureAtomRun (sourceBlockWord s P atom b false) (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ + complementaryWords (T b) (a-start u) (2^s) (prouhetBool s) (sourceBlockWord s P atom b) (θ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) := by + apply congrArg coordinateWord + funext u + exact congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) A (n b) (h b) loc glob u) ++ w ++ + pureAtomRun (sourceBlockWord s P atom b false) + (sourcePostCount (T (b+1)) B (n b) (h b) loc glob u)) (hchild u) + _ = _ := hpart.symm + + + +/-- Full literal unconditioned root partition, including both members of + every outer paired side. Its top trial count is the source's J, even or odd. -/ +def sourceFullWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) + (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (τ : Bool) : List Bool := + pureAtomRun (sourceBlockWord s P atom b false) (n b*h b+∑i,bitIndex (bits.1 i)) ++ + sourceTreeWord s P T n h (sourceLocalCenter T n) atom (b+1) bits 0 τ ++ + pureAtomRun (sourceBlockWord s P atom b false) (n b*(h b+1)-∑i,bitIndex (bits.1 i)) + +theorem bitIndex_sum_le {J : ℕ} (bits : Fin J → Bool) : (∑i,bitIndex (bits i))≤J := by + calc + _ ≤ ∑_i : Fin J,1 := by + apply Finset.sum_le_sum + intro i _ + cases bits i <;> norm_num [bitIndex] + _ = J := by simp + +/-- The source root's floor anchor and paired side counts have their literal + unmarked word interpretation, without requiring J to be even. -/ +theorem sourceFullWord_eq_block (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) + (b : ℕ) (H : SourceLayoutMargins s P T n h b) (hpos : 0 rfl) bits 0 τ hfit + have hpart := template_word_window t (T b) z a (2^s) (prouhetBool s) τ + (sourceBlockWord s P atom b) ht hz + rw [htotal] at hpart + rw [atomString_constant,atomString_constant] at hpart + unfold sourceFullWord + rw [hcenter] + change pureAtomRun (sourceBlockWord s P atom b false) t ++ + atomString (T b) (sourceBlockWord s P atom b) + (integerTemplateType (T b) s (sourceNodeAnchor T n (sourceLocalCenter T n) b bits 0) τ) ++ + pureAtomRun (sourceBlockWord s P atom b false) z = _ + rw [hanchor,integerTemplateType_nat] + exact hpart.symm + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Pure filler IDs. At bottom leaf windows the two fillers have zero length; + they are deterministic empty outputs, not extra information. -/ +def WindowFiller (T : ℕ → ℕ) : ℕ → Type + | 0 => PEmpty + | b+1 => (Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b) + +noncomputable instance windowFillerFintype (T : ℕ → ℕ) : (b : ℕ) → Fintype (WindowFiller T b) + | 0 => inferInstanceAs (Fintype PEmpty) + | b+1 => by + letI := windowFillerFintype T b + exact inferInstanceAs (Fintype ((Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b))) + +abbrev TreeEmission (T n g : ℕ → ℕ) (b : ℕ) := + (WindowTrial T n g b × Bool) ⊕ (WindowFiller T b ⊕ WindowLeaf T b) + +def TreeEmission.up (T n g : ℕ → ℕ) (b : ℕ) (u : Fin (T b)) : + TreeEmission T n g b → TreeEmission T n g (b+1) + | .inl (i,p) => .inl (.inr (.inr (u,i)),p) + | .inr (.inl f) => .inr (.inl (.inr (u,f))) + | .inr (.inr v) => .inr (.inr (u,v)) + +def treeLocalSlots (T n g : ℕ → ℕ) (b : ℕ) (p : Bool) : List (TreeEmission T n g (b+1)) := + List.ofFn (fun k : Fin (n b) => Sum.inl (Sum.inl k,p)) + +def treeGlobalSlots (T n g : ℕ → ℕ) (b : ℕ) (p : Bool) + (pos : Fin (g b) → Fin (T b)) (u : Fin (T b)) : List (TreeEmission T n g (b+1)) := + ((List.ofFn id : List (Fin (g b))).filter (fun k => pos k=u)).map + (fun k => Sum.inl (Sum.inr (Sum.inl k),p)) + +/-- Public chronological IDs. Each child carries its own local paired sides; + the group's global sides and deterministic fillers surround that child. + The order is fixed independently of all bits and both hypotheses. -/ +def treeChronology (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) : + (b : ℕ) → List (TreeEmission T n g b) + | 0 => [.inr (.inr (show WindowLeaf T 0 from (0 : Fin 1)))] + | b+1 => treeLocalSlots T n g b false ++ + (List.ofFn (fun u : Fin (T b) => + treeGlobalSlots T n g b false (pre b) u ++ + [.inr (.inl (.inl (u,false)))] ++ + (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) ++ + treeGlobalSlots T n g b true (post b) u ++ + [.inr (.inl (.inl (u,true)))])).flatten ++ + treeLocalSlots T n g b true + +theorem sum_fiber_list_length {α ι : Type*} [Fintype ι] [DecidableEq ι] (pos : α → ι) (l : List α) : + (∑i,(l.filter (fun a => pos a=i)).length)=l.length := by + induction l with + | nil => simp + | cons a l ih => + have hh (i : ι) : ((a::l).filter (fun a => pos a=i)).length= + (if pos a=i then 1 else 0)+(l.filter (fun a => pos a=i)).length := by + by_cases h : pos a=i <;> simp [h,Nat.add_comm] + simp_rw [hh] + rw [Finset.sum_add_distrib,ih] + simp [Nat.add_comm] + +theorem treeChronology_length (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : + (treeChronology T n g pre post b).length=Fintype.card (TreeEmission T n g b) := by + induction b with + | zero => + change 1=Fintype.card ((PEmpty × Bool) ⊕ (PEmpty ⊕ Fin 1)) + simp + | succ b ih => + have hp := sum_fiber_list_length (pre b) (List.ofFn id : List (Fin (g b))) + have hq := sum_fiber_list_length (post b) (List.ofFn id : List (Fin (g b))) + simp only [List.length_ofFn] at hp hq + change _=Fintype.card (((Fin (n b) ⊕ (Fin (g b) ⊕ (Fin (T b) × WindowTrial T n g b))) × Bool) ⊕ + (((Fin (T b) × Bool) ⊕ (Fin (T b) × WindowFiller T b)) ⊕ (Fin (T b) × WindowLeaf T b))) + simp only [treeChronology,treeLocalSlots,treeGlobalSlots,List.length_append, + List.length_flatten,List.map_ofFn,Function.comp_apply,List.length_ofFn,List.length_map,List.length_cons,List.length_nil, + Finset.sum_add_distrib,List.sum_ofFn,ih,Fintype.card_sum,Fintype.card_prod,Fintype.card_fin,Fintype.card_bool] + rw [hp,hq] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,smul_eq_mul] + ring + +theorem treeChronology_mem (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) + (x : TreeEmission T n g b) : x∈treeChronology T n g pre post b := by + induction b with + | zero => + rcases x with ⟨i,p⟩ | f | v + · exact PEmpty.elim i + · exact PEmpty.elim f + · change Fin 1 at v + have hv : v=0 := Subsingleton.elim _ _ + subst v; exact List.mem_singleton.mpr rfl + | succ b ih => + have hc (u : Fin (T b)) (x : TreeEmission T n g (b+1)) + (hx : x∈treeGlobalSlots T n g b false (pre b) u ++ [.inr (.inl (.inl (u,false)))] ++ + (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) ++ + treeGlobalSlots T n g b true (post b) u ++ [.inr (.inl (.inl (u,true)))]) : + x∈treeChronology T n g pre post (b+1) := by + apply List.mem_append_left + apply List.mem_append_right + apply List.mem_flatten.mpr + exact ⟨_,List.mem_ofFn.mpr ⟨u,rfl⟩,hx⟩ + rcases x with ⟨k,p⟩ | f | v + · rcases k with k | k | ⟨u,k⟩ + · cases p <;> + simp [treeChronology,treeLocalSlots,List.mem_ofFn] + · cases p + · apply hc (pre b k) + simp only [List.mem_append,treeGlobalSlots,List.mem_map,List.mem_filter,List.mem_ofFn] + exact Or.inl (Or.inl (Or.inl (Or.inl ⟨k,⟨⟨k,rfl⟩,by simp⟩,rfl⟩))) + · apply hc (post b k) + simp only [List.mem_append,treeGlobalSlots,List.mem_map,List.mem_filter,List.mem_ofFn] + exact Or.inl (Or.inr ⟨k,⟨⟨k,rfl⟩,by simp⟩,rfl⟩) + · apply hc u + have hm : TreeEmission.up T n g b u (.inl (k,p))∈ + (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ + exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) + · rcases f with ⟨u,p⟩ | ⟨u,f⟩ + · cases p <;> apply hc u <;> simp + · apply hc u + have hm : TreeEmission.up T n g b u (.inr (.inl f))∈ + (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ + exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) + · rcases v with ⟨u,v⟩ + apply hc u + have hm : TreeEmission.up T n g b u (.inr (.inr v))∈ + (treeChronology T n g pre post b).map (TreeEmission.up T n g b u) := List.mem_map.mpr ⟨_,ih _,rfl⟩ + exact List.mem_append_left _ (List.mem_append_left _ (List.mem_append_right _ hm)) + +theorem treeChronology_nodup (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : + (treeChronology T n g pre post b).Nodup := by + have hs : (treeChronology T n g pre post b).toFinset=Finset.univ := by + ext x + simp only [List.mem_toFinset,Finset.mem_univ,iff_true] + exact treeChronology_mem T n g pre post b x + have hh : (treeChronology T n g pre post b).toFinset.card=(treeChronology T n g pre post b).length := by + rw [hs,Finset.card_univ,treeChronology_length] + exact Multiset.coe_nodup.mp ((Multiset.toFinset_card_eq_card_iff_nodup + (m := (treeChronology T n g pre post b : Multiset (TreeEmission T n g b)))).mp hh) + + +/-- A genuine complete chronological bijection, not an assumed layout. -/ +def treeChronologyEquiv (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) : + Fin (treeChronology T n g pre post b).length ≃ TreeEmission T n g b := + List.Nodup.getEquivOfForallMemList _ (treeChronology_nodup T n g pre post b) + (treeChronology_mem T n g pre post b) + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def pairedSideCount (h : ℕ) (bit side : Bool) : ℕ := h+bitIndex (Bool.xor bit side) + +theorem pairedSideCount_false (h : ℕ) (bit : Bool) : + pairedSideCount h bit false=h+bitIndex bit := by cases bit <;> rfl + +theorem pairedSideCount_true (h : ℕ) (bit : Bool) : + pairedSideCount h bit true=h+1-bitIndex bit := by cases bit <;> simp [pairedSideCount,bitIndex] + +theorem pairedSideCount_sum_pre {t h : ℕ} (bits : Fin t → Bool) : + (∑i,pairedSideCount h (bits i) false)=t*h+∑i,bitIndex (bits i) := by + simp only [pairedSideCount_false,Finset.sum_add_distrib,Finset.sum_const, + Finset.card_univ,Fintype.card_fin,smul_eq_mul] + +theorem pairedSideCount_sum_total {t h : ℕ} (bits : Fin t → Bool) : + (∑i,pairedSideCount h (bits i) true)+(∑i,bitIndex (bits i))=t*(h+1) := by + rw [←Finset.sum_add_distrib] + calc + _ = ∑_i : Fin t,(h+1) := by + apply Finset.sum_congr rfl + intro i _ + cases bits i <;> simp [pairedSideCount,bitIndex] + _ = _ := by simp + +theorem pairedSideCount_sum_post {t h : ℕ} (bits : Fin t → Bool) : + (∑i,pairedSideCount h (bits i) true)=t*(h+1)-∑i,bitIndex (bits i) := by + have := pairedSideCount_sum_total (h:=h) bits + omega + +/-- Global trial positions are ID functions, not positions inferred from a + realized output or orientation. -/ +def sourceGlobalPre (N t : ℕ) (k : Fin ((N/4)*t)) : Fin N := + ⟨((globalTrialEquiv N t).symm k).1.val,by + have := ((globalTrialEquiv N t).symm k).1.isLt; omega⟩ + +def sourceGlobalPost (N t : ℕ) (k : Fin ((N/4)*t)) : Fin N := + ⟨N-1-((globalTrialEquiv N t).symm k).1.val,by + have := ((globalTrialEquiv N t).symm k).1.isLt; omega⟩ + +theorem sum_globalSides (N t h : ℕ) (bits : Fin ((N/4)*t) → Bool) + (side : Bool) (pos : Fin (N/4) → Fin N) (u : Fin N) : + (∑k : Fin ((N/4)*t), if pos ((globalTrialEquiv N t).symm k).1=u then + pairedSideCount h (bits k) side else 0)= + ∑v : Fin (N/4),if pos v=u then + (∑a : Fin t,pairedSideCount h (bits (globalTrialIndex N t v a)) side) else 0 := by + rw [←(globalTrialEquiv N t).sum_comp,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro v _ + simp only [Equiv.symm_apply_apply] + split_ifs with hv + · rfl + · simp only [Finset.sum_const_zero] + +theorem sourcePreCount_slots (N A t h : ℕ) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : + sourcePreCount N A t h loc glob u= + (∑k : Fin ((N/4)*t),if sourceGlobalPre N t k=u then pairedSideCount h (glob k) false else 0)+ + sourcePreFiller N A t h u+(∑i,pairedSideCount h (loc u i) false) := by + rw [pairedSideCount_sum_pre] + change sourcePreFiller N A t h u+(∑v : SourceBundle N, + if sourceBundleLeft N v=u then sourceBundleCount N t h loc glob v else 0)=_ + rw [Fintype.sum_sum_type] + have hl : (∑v : Fin N,if sourceBundleLeft N (.inl v)=u then + sourceBundleCount N t h loc glob (.inl v) else 0)=t*h+∑i,bitIndex (loc u i) := by + change (∑v : Fin N,if v=u then (t*h+(∑i,bitIndex (loc v i))) else 0)=_ + simp + rw [hl] + have hg := sum_globalSides N t h glob false + (fun v => ⟨v.val,by have := v.isLt; omega⟩) u + simp only [pairedSideCount_sum_pre] at hg + change (∑k,if sourceGlobalPre N t k=u then pairedSideCount h (glob k) false else 0)=_ at hg + rw [hg] + change _+(_+_) = _+_+_ + have he : (∑v : Fin (N/4),if sourceBundleLeft N (.inr v)=u then + sourceBundleCount N t h loc glob (.inr v) else 0)= + ∑v : Fin (N/4),if (⟨v.val,by have := v.isLt; omega⟩ : Fin N)=u then + (t*h+∑i,bitIndex (glob (globalTrialIndex N t v i))) else 0 := by + apply Finset.sum_congr rfl + intro v _ + rfl + rw [he] + omega + +theorem sourcePostCount_slots (N B t h : ℕ) (ht : Even t) (loc : Fin N → Fin t → Bool) + (glob : Fin ((N/4)*t) → Bool) (u : Fin N) : + sourcePostCount N B t h loc glob u= + (∑i,pairedSideCount h (loc u i) true)+ + (∑k : Fin ((N/4)*t),if sourceGlobalPost N t k=u then pairedSideCount h (glob k) true else 0)+ + sourcePostFiller N B t h u := by + have hh : 2*(t/2)=t := Nat.mul_div_cancel' ((even_iff_two_dvd).mp ht) + have hc (bits : Fin t → Bool) : + 2*sourceLayoutReserve t h-(t*h+∑i,bitIndex (bits i))= + ∑i,pairedSideCount h (bits i) true := by + rw [pairedSideCount_sum_post] + dsimp only [sourceLayoutReserve] + have hs := bitIndex_sum_le bits + have he : 2*(t*h+t/2)=t*h+t*(h+1) := by + rw [Nat.mul_add,Nat.mul_add,Nat.mul_one,hh] + omega + rw [he] + omega + change sourcePostFiller N B t h u+(∑v : SourceBundle N, + if sourceBundleRight N v=u then 2*sourceLayoutReserve t h-sourceBundleCount N t h loc glob v else 0)=_ + rw [Fintype.sum_sum_type] + have hl : (∑v : Fin N,if sourceBundleRight N (.inl v)=u then + 2*sourceLayoutReserve t h-sourceBundleCount N t h loc glob (.inl v) else 0)= + ∑i,pairedSideCount h (loc u i) true := by + simp only [sourceBundleRight,sourceBundleCount,Finset.sum_ite_eq',Finset.mem_univ,ite_true,hc] + rw [hl] + have hg := sum_globalSides N t h glob true + (fun v => ⟨N-1-v.val,by have := v.isLt; omega⟩) u + change (∑k,if sourceGlobalPost N t k=u then pairedSideCount h (glob k) true else 0)=_ at hg + rw [hg] + simp only [sourceBundleRight,sourceBundleCount,hc] + omega + +/-- Flattening selected equal-atom chunks sums exactly their genuine lengths. -/ +theorem filter_chunks_flatten {ι : Type*} [Fintype ι] [DecidableEq ι] + (l : List ι) (p : ι → Bool) (c : ι → ℕ) (w : List Bool) : + ((l.filter p).map (fun i => pureAtomRun w (c i))).flatten= + pureAtomRun w ((l.map (fun i => if p i then c i else 0)).sum) := by + calc + _ = pureAtomRun w (((l.filter p).map c).sum) := by + simpa only [List.map_map,Function.comp_def] using pureAtomRun_partition w ((l.filter p).map c) + _ = _ := by + congr 1 + induction l with + | nil => rfl + | cons i l ih => cases hp : p i <;> simp [hp,ih] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def sourceScheduledPre (T n : ℕ → ℕ) : + (b : ℕ) → Fin (sourceScheduledTrials T n b) → Fin (T b) + | 0,k => Fin.elim0 k + | b+1,k => sourceGlobalPre (T (b+1)) (n b) k + +def sourceScheduledPost (T n : ℕ → ℕ) : + (b : ℕ) → Fin (sourceScheduledTrials T n b) → Fin (T b) + | 0,k => Fin.elim0 k + | b+1,k => sourceGlobalPost (T (b+1)) (n b) k + +/-- Two actual deterministic pure binary side words for each paired trial ID. -/ +def sourceTrialWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) : + (b : ℕ) → WindowTrial T n (sourceScheduledTrials T n) b → Bool → List Bool + | 0,i,_ => PEmpty.elim i + | b+1,.inl _,c => pureAtomRun (sourceBlockWord s P atom b false) (h b+bitIndex c) + | 1,.inr (.inl k),_ => Fin.elim0 k + | b+2,.inr (.inl _),c => pureAtomRun (sourceBlockWord s P atom b false) (h b+bitIndex c) + | b+1,.inr (.inr (_,i)),c => sourceTrialWord s P T n h atom b i c + +/-- Fixed pure fillers, including the deterministic empty bottom fillers. -/ +def sourceFillerWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) : + (b : ℕ) → WindowFiller T b → List Bool + | 0,i => PEmpty.elim i + | b+1,.inl (u,p) => match b,u with + | 0,_ => [] + | b+1,u => pureAtomRun (sourceBlockWord s P atom b false) + (if p then sourcePostFiller (T (b+1)) (sourceNominalPost P T b) (n b) (h b) u + else sourcePreFiller (T (b+1)) (sourceNominalPre P T b) (n b) (h b) u) + | b+1,.inr (_,i) => sourceFillerWord s P T n h atom b i + +def sourceSlotWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) + (incoming : ℤ) (τ : Bool) : TreeEmission T n (sourceScheduledTrials T n) b → List Bool + | .inl (i,side) => sourceTrialWord s P T n h atom b i + (Bool.xor (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool b bits i) side) + | .inr (.inl i) => sourceFillerWord s P T n h atom b i + | .inr (.inr v) => atom (sourceTreeLeafBool T n s center b bits incoming τ v) + +def sourceChronologicalWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) + (incoming : ℤ) (τ : Bool) : List Bool := + ((treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).map + (sourceSlotWord s P T n h center atom b bits incoming τ)).flatten + +theorem sourceSlotWord_up (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) + (incoming : ℤ) (τ : Bool) (u : Fin (T b)) (x : TreeEmission T n (sourceScheduledTrials T n) b) : + sourceSlotWord s P T n h center atom (b+1) bits incoming τ (TreeEmission.up T n (sourceScheduledTrials T n) b u x)= + sourceSlotWord s P T n h center atom b (bits.2.2 u) (sourceScheduledShift T n b bits.2.1 u) + (integerTemplateType (T b) s (sourceNodeAnchor T n center b bits incoming) τ u) x := by + rcases x with ⟨i,p⟩ | f | v <;> rfl + +theorem treeChronology_eval (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) + (f : TreeEmission T n g (b+1) → List Bool) : + ((treeChronology T n g pre post (b+1)).map f).flatten= + ((treeLocalSlots T n g b false).map f).flatten ++ + coordinateWord (fun u => ((treeGlobalSlots T n g b false (pre b) u).map f).flatten ++ + f (.inr (.inl (.inl (u,false)))) ++ + ((treeChronology T n g pre post b).map (fun x => f (TreeEmission.up T n g b u x))).flatten ++ + ((treeGlobalSlots T n g b true (post b) u).map f).flatten ++ + f (.inr (.inl (.inl (u,true))))) ++ + ((treeLocalSlots T n g b true).map f).flatten := by + simp only [treeChronology,List.map_append,List.flatten_append,List.map_flatten, + List.map_ofFn,coordinateWord] + congr 2 + rw [List.flatten_flatten,List.map_ofFn] + apply congrArg List.flatten + apply congrArg List.ofFn + funext u + simp only [Function.comp_apply,List.map_append,List.flatten_append,List.map_cons,List.map_nil, + List.flatten_cons,List.flatten_nil,List.append_nil,List.map_map] + rfl + +theorem sourceLocalSlots_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) + (incoming : ℤ) (τ side : Bool) : + ((treeLocalSlots T n (sourceScheduledTrials T n) b side).map + (sourceSlotWord s P T n h center atom (b+1) bits incoming τ)).flatten= + pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) side) := by + rcases bits with ⟨loc,glob,kids⟩ + simp only [treeLocalSlots,List.map_ofFn] + change (List.ofFn (fun i : Fin (n b) => pureAtomRun (sourceBlockWord s P atom b false) + (pairedSideCount (h b) (loc i) side))).flatten=_ + exact coordinateWord_pureAtomRun _ _ + +theorem sourceGlobalSlots_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) + (incoming : ℤ) (τ side : Bool) (pos : Fin ((T (b+1)/4)*n b) → Fin (T (b+1))) (u : Fin (T (b+1))) : + ((treeGlobalSlots T n (sourceScheduledTrials T n) (b+1) side pos u).map + (sourceSlotWord s P T n h center atom (b+2) bits incoming τ)).flatten= + pureAtomRun (sourceBlockWord s P atom b false) + (∑k,if pos k=u then pairedSideCount (h b) (bits.2.1 k) side else 0) := by + rcases bits with ⟨loc,glob,kids⟩ + change Fin ((T (b+1)/4)*n b) → Bool at glob + simp only [treeGlobalSlots,List.map_map] + change ((List.filter (fun k => decide (pos k=u)) (List.ofFn id)).map + (fun i => pureAtomRun (sourceBlockWord s P atom b false) (pairedSideCount (h b) (glob i) side))).flatten=_ + rw [filter_chunks_flatten,List.map_ofFn,List.sum_ofFn] + simp only [Function.comp_apply,id_eq,decide_eq_true_eq] + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def sourceFramedWord (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) : + (b : ℕ) → WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℤ → Bool → List Bool + | 0,_,_,τ => atom τ + | b+1,bits,incoming,τ => + pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) false) ++ + sourceTreeWord s P T n h center atom (b+1) bits incoming τ ++ + pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (bits.1 i) true) + +theorem sourceChronologicalWord_eq_framed (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) + (atom : Bool → List Bool) (b : ℕ) (hev : ∀j,j+1 simp [sourceChronologicalWord,treeChronology,sourceSlotWord,sourceTreeLeafBool,sourceFramedWord] + | succ b ih => + rcases bits with ⟨loc,glob,kids⟩ + unfold sourceChronologicalWord + rw [treeChronology_eval] + erw [sourceLocalSlots_word,sourceLocalSlots_word] + change _=pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) false) ++ + sourceTreeWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ ++ + pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) true) + apply congrArg (fun w => pureAtomRun (sourceBlockWord s P atom b false) + (∑i,pairedSideCount (h b) (loc i) false) ++ w ++ + pureAtomRun (sourceBlockWord s P atom b false) (∑i,pairedSideCount (h b) (loc i) true)) + have child (u : Fin (T b)) : + ((treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).map + (fun x => sourceSlotWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ + (TreeEmission.up T n (sourceScheduledTrials T n) b u x))).flatten= + sourceFramedWord s P T n h center atom b (kids u) (sourceScheduledShift T n b glob u) + (integerTemplateType (T b) s (sourceNodeAnchor T n center b (loc,glob,kids) incoming) τ u) := by + have he : (fun x : TreeEmission T n (sourceScheduledTrials T n) b => + sourceSlotWord s P T n h center atom (b+1) (loc,glob,kids) incoming τ + (TreeEmission.up T n (sourceScheduledTrials T n) b u x)) = + sourceSlotWord s P T n h center atom b (kids u) (sourceScheduledShift T n b glob u) + (integerTemplateType (T b) s (sourceNodeAnchor T n center b (loc,glob,kids) incoming) τ u) := by + funext x + exact sourceSlotWord_up s P T n h center atom b (loc,glob,kids) incoming τ u x + erw [he] + exact ih (fun j hj => hev j (by omega)) (kids u) _ _ + cases b with + | zero => + change coordinateWord _=atomString (T 0) atom _ + apply congrArg coordinateWord + funext u + rw [child] + simp only [treeGlobalSlots,sourceScheduledTrials,List.ofFn_zero,List.filter_nil,List.map_nil, + List.flatten_nil,List.nil_append,List.append_nil,sourceSlotWord,sourceFillerWord,sourceFramedWord] + | succ b => + change coordinateWord _=coordinateWord _ + apply congrArg coordinateWord + funext u + erw [sourceGlobalSlots_word,sourceGlobalSlots_word,child] + change _=pureAtomRun (sourceBlockWord s P atom b false) + (sourcePreCount (T (b+1)) (sourceNominalPre P T b) (n b) (h b) (fun v => (kids v).1) glob u) ++ + sourceTreeWord s P T n h center atom (b+1) (kids u) (sourceScheduledShift T n (b+1) glob u) + (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) (loc,glob,kids) incoming) τ u) ++ + pureAtomRun (sourceBlockWord s P atom b false) + (sourcePostCount (T (b+1)) (sourceNominalPost P T b) (n b) (h b) (fun v => (kids v).1) glob u) + erw [sourcePreCount_slots,sourcePostCount_slots _ _ _ _ (hev b (by omega))] + change pureAtomRun _ _ ++ pureAtomRun _ _ ++ + (pureAtomRun _ _ ++ sourceTreeWord s P T n h center atom (b+1) (kids u) + (sourceScheduledShift T n (b+1) glob u) + (integerTemplateType (T (b+1)) s (sourceNodeAnchor T n center (b+1) (loc,glob,kids) incoming) τ u) ++ + pureAtomRun _ _) ++ pureAtomRun _ _ ++ pureAtomRun _ _ = _ + simp only [sourceScheduledPre,sourceScheduledPost,pureAtomRun_add,List.append_assoc, + Bool.false_eq_true,ite_false,ite_true] + rfl + +/-- Chronological side/filler/leaf slots produce the SAME full source word + on the joint fit event. No orientation is removed or conditioned away. -/ +theorem sourceChronologicalWord_eq_block (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) + (b : ℕ) (H : SourceLayoutMargins s P T n h b) + (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) + (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) + (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+1)) (τ : Bool) + (hfit : SourceTreeFit T n (b+1) bits) : + sourceChronologicalWord s P T n h (sourceLocalCenter T n) atom (b+1) bits 0 τ= + sourceBlockWord s P atom (b+1) τ := by + rw [sourceChronologicalWord_eq_framed s P T n h (sourceLocalCenter T n) atom (b+1) + (fun j hj => H.even_trials j (by omega))] + have hf := sourceFullWord_eq_block s P T n h atom b H (by omega) hP hT hlarge hmotif bits τ hfit + change sourceFullWord s P T n h atom b bits τ=_ at hf + simpa only [sourceFramedWord,sourceFullWord,pairedSideCount_sum_pre,pairedSideCount_sum_post] using hf + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +def finEnumeration (α : Type) [Fintype α] : Fin (Fintype.card α) ≃ α := (Fintype.equivFin α).symm + +abbrev SourceTrialCount (T n : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowTrial T n (sourceScheduledTrials T n) b) +abbrev SourceFillerCount (T : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowFiller T b) +abbrev SourceLeafCount (T : ℕ → ℕ) (b : ℕ) := Fintype.card (WindowLeaf T b) + +def sourceEmissionEnum (T n : ℕ → ℕ) (b : ℕ) : + EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b) ≃ + TreeEmission T n (sourceScheduledTrials T n) b := + Equiv.sumCongr (Equiv.prodCongr (finEnumeration _) (Equiv.refl Bool)) + (Equiv.sumCongr (finEnumeration _) (finEnumeration _)) + +def sourceAssignmentCode (T n : ℕ → ℕ) (A : Type) (b : ℕ) : + WindowAssignments T n (sourceScheduledTrials T n) A b ≃ (Fin (SourceTrialCount T n b) → A) where + toFun bits j := windowAssignmentEquiv T n (sourceScheduledTrials T n) A b bits (finEnumeration _ j) + invFun bits := (windowAssignmentEquiv T n (sourceScheduledTrials T n) A b).symm + (fun i => bits ((finEnumeration _).symm i)) + left_inv bits := by simp only [Equiv.apply_symm_apply,Equiv.symm_apply_apply] + right_inv bits := by + funext j + simp only [Equiv.apply_symm_apply,Equiv.symm_apply_apply] + +theorem sourceAssignmentCode_eval (T n : ℕ → ℕ) (A : Type) (b : ℕ) + (bits : Fin (SourceTrialCount T n b) → A) (j : Fin (SourceTrialCount T n b)) : + windowAssignmentEquiv T n (sourceScheduledTrials T n) A b + ((sourceAssignmentCode T n A b).symm bits) (finEnumeration _ j)=bits j := by + change (sourceAssignmentCode T n A b ((sourceAssignmentCode T n A b).symm bits)) j=bits j + rw [Equiv.apply_symm_apply] + +def sourceChronologyCode (T n : ℕ → ℕ) (b : ℕ) : + Fin (treeChronology T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).length ≃ + EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b) := + (treeChronologyEquiv T n (sourceScheduledTrials T n) (sourceScheduledPre T n) (sourceScheduledPost T n) b).trans + (sourceEmissionEnum T n b).symm + +def sourceFlatLeafType (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) (b : ℕ) (incoming : ℤ) (τ : Bool) + (bits : Fin (SourceTrialCount T n b) → Bool) (j : Fin (SourceLeafCount T b)) : Bool := + sourceTreeLeafBool T n s center b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ (finEnumeration _ j) + +def sourceFlatTrialWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) + (c : Bool) (j : Fin (SourceTrialCount T n b)) : List Bool := + sourceTrialWord s P T n h atom b (finEnumeration _ j) c + +def sourceFlatFillerWord (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) + (j : Fin (SourceFillerCount T b)) : List Bool := + sourceFillerWord s P T n h atom b (finEnumeration _ j) + +theorem sourceSlotWord_code (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : Fin (SourceTrialCount T n b) → Bool) (incoming : ℤ) (τ : Bool) + (x : EmissionSlot (SourceTrialCount T n b) (SourceFillerCount T b) (SourceLeafCount T b)) : + sourceSlotWord s P T n h center atom b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ + (sourceEmissionEnum T n b x)= + PairedMechanisms.slotWord (sourceFlatTrialWord s P T n h atom b false) + (sourceFlatTrialWord s P T n h atom b true) (sourceFlatFillerWord s P T n h atom b) atom bits + (sourceFlatLeafType T n s center b incoming τ bits) x := by + rcases x with ⟨j,p⟩ | f | v + · cases p <;> + change sourceTrialWord s P T n h atom b (finEnumeration _ j) + (Bool.xor (windowAssignmentEquiv T n (sourceScheduledTrials T n) Bool b + ((sourceAssignmentCode T n Bool b).symm bits) (finEnumeration _ j)) _) = _ <;> + rw [sourceAssignmentCode_eval] <;> cases he : bits j <;> simp [PairedMechanisms.slotWord,he,sourceFlatTrialWord] + · rfl + · rfl + +theorem treeChronologyEquiv_word (T n g : ℕ → ℕ) + (pre post : (b : ℕ) → Fin (g b) → Fin (T b)) (b : ℕ) + (f : TreeEmission T n g b → List Bool) : + coordinateWord (fun j => f (treeChronologyEquiv T n g pre post b j))= + ((treeChronology T n g pre post b).map f).flatten := by + unfold coordinateWord treeChronologyEquiv + change (List.ofFn (fun j => f ((treeChronology T n g pre post b).get j))).flatten=_ + have hh : List.map f (List.ofFn (treeChronology T n g pre post b).get) = + List.ofFn (f ∘ (treeChronology T n g pre post b).get) := List.map_ofFn + rw [List.ofFn_get] at hh + exact congrArg List.flatten hh.symm + +theorem source_slotCode_word (s : ℕ) (P T n h : ℕ → ℕ) (center : ℕ → ℤ) (atom : Bool → List Bool) + (b : ℕ) (bits : Fin (SourceTrialCount T n b) → Bool) (incoming : ℤ) (τ : Bool) : + coordinateWord (fun j => PairedMechanisms.slotWord (sourceFlatTrialWord s P T n h atom b false) + (sourceFlatTrialWord s P T n h atom b true) (sourceFlatFillerWord s P T n h atom b) atom bits + (sourceFlatLeafType T n s center b incoming τ bits) (sourceChronologyCode T n b j))= + sourceChronologicalWord s P T n h center atom b ((sourceAssignmentCode T n Bool b).symm bits) incoming τ := by + simp_rw [←sourceSlotWord_code] + simp only [sourceChronologyCode,Equiv.trans_apply,Equiv.apply_symm_apply] + exact treeChronologyEquiv_word T n (sourceScheduledTrials T n) (sourceScheduledPre T n) + (sourceScheduledPost T n) b _ + +end TraceReconstruction + + + +noncomputable section +namespace TraceReconstruction +open scoped Classical + +/-- Reindex the genuine independent orientations, retaining the whole source tree. -/ +theorem source_fair_code_expect (T n : ℕ → ℕ) (b : ℕ) + (F : WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℝ) : + (PairedMechanisms.fairOrientations (SourceTrialCount T n b)).expect + (fun bits => F ((sourceAssignmentCode T n Bool b).symm bits)) = + (windowPosteriorLaw T n (sourceScheduledTrials T n) b + (noReveals T n (sourceScheduledTrials T n) b)).expect F := by + rw [windowPosterior_fair_flat,FiniteLaw.indexedProduct_expect_equiv _ (finEnumeration _)] + simp only [PairedMechanisms.fairOrientations,FiniteLaw.expect,FiniteLaw.product, + FiniteLaw.indexedProduct,sourceAssignmentCode,Equiv.coe_fn_symm_mk] + apply Finset.sum_congr (by ext; simp) + intro bits _ + rfl + +/-- The fit event uses only interior even bundles. In particular no parity + assumption is made on the top root count J. -/ +theorem sourceTreeFit_tail_interior (T n : ℕ → ℕ) (b : ℕ) + (hn : ∀j,j+1 if SourceTreeFit T n b bits then 0 else 1) ≤ sourceFitTail T n b := by + induction b using Nat.twoStepInduction with + | zero => + have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 0) : SourceTreeFit T n 0 bits := trivial + simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] + | one => + have hh (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool 1) : SourceTreeFit T n 1 bits := trivial + simp only [ite_eq_left (hh _),FiniteLaw.expect_const,sourceFitTail,le_refl] + | more b ih0 ih => + let P := windowPosteriorLaw T n (sourceScheduledTrials T n) (b+2) + (noReveals T n (sourceScheduledTrials T n) (b+2)) + let badShift : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2) → Fin (T (b+1)) → Prop := + fun bits u => (T b:ℝ)/8≤|(sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| + have hp (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool (b+2)) : + (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ + (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ + (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by + let p := fun u : Fin (T (b+1)) => |8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u|≤(T b:ℤ) + have hh : (if SourceTreeFit T n (b+2) bits then (0:ℝ) else 1)≤ + (if ∀u,p u then 0 else 1)+(if ∀u,SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1) := by + by_cases H : SourceTreeFit T n (b+2) bits + · rw [ite_eq_left H] + split_ifs <;> norm_num + · rw [ite_eq_right H] + by_cases h1 : ∀u,p u + · have h2 : ¬∀u,SourceTreeFit T n (b+1) (bits.2.2 u) := fun h2 => H ⟨h1,h2⟩ + rw [ite_eq_left h1,ite_eq_right h2] + norm_num + · rw [ite_eq_right h1] + split_ifs <;> norm_num + apply hh.trans + apply add_le_add + · apply (failure_forall_le_sum p).trans + apply Finset.sum_le_sum + intro u _ + by_cases hu : p u + · simp only [ite_eq_left hu] + split_ifs <;> norm_num + · have hr : (T b:ℝ)<8*|(sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℝ)| := by + have hi : (T b:ℤ) < |8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u| := lt_of_not_ge hu + have hi' : (T b:ℝ) < |(8*sourceDisplacement (T (b+1)) (n b) + (fun v => (bits.2.2 v).1) bits.2.1 u:ℤ)| := by exact_mod_cast hi + norm_num only [Int.cast_abs,Int.cast_mul,Int.cast_ofNat,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<8)] at hi' + exact hi' + have hb : badShift bits u := by dsimp [badShift]; linarith + simp [hu,hb] + · exact failure_forall_le_sum _ + calc + _ ≤ P.expect (fun bits => (∑u : Fin (T (b+1)),if badShift bits u then 1 else 0)+ + (∑u : Fin (T (b+1)),if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := + P.expect_mono hp + _ = (∑u : Fin (T (b+1)),P.expect (fun bits => if badShift bits u then 1 else 0))+ + (∑u : Fin (T (b+1)),P.expect (fun bits => if SourceTreeFit T n (b+1) (bits.2.2 u) then 0 else 1)) := by + rw [FiniteLaw.expect_add,FiniteLaw.expect_fintype_sum,FiniteLaw.expect_fintype_sum] + _ ≤ (∑_u : Fin (T (b+1)),2*Real.exp (-2*((T b:ℝ)/8)^2/(((T (b+1):ℝ)+1)*(n b:ℝ))))+ + ∑_u : Fin (T (b+1)),sourceFitTail T n (b+1) := by + apply add_le_add + · apply Finset.sum_le_sum + intro u _ + exact sourceDisplacement_tail T n b (he b (by omega)) (hn b (by omega)) u (by positivity) + · apply Finset.sum_le_sum + intro u _ + dsimp only [P] + rw [windowPosterior_child T n (sourceScheduledTrials T n) (b+1) + (noReveals T n (sourceScheduledTrials T n) (b+2)) u + (fun x => if SourceTreeFit T n (b+1) x then 0 else 1)] + rw [noReveals_succ] + exact ih (fun j hj => hn j (by omega)) (fun j hj => he j (by omega)) + _ = sourceFitTail T n (b+2) := by simp [sourceFitTail,mul_add] + + +/-- Honest source joint-fit failure after the actual finite coding. -/ +theorem source_flat_fit_tail (T n : ℕ → ℕ) (b : ℕ) + (hn : ∀j,j+1 if SourceTreeFit T n b ((sourceAssignmentCode T n Bool b).symm bits) then 0 else 1) + ≤ sourceFitTail T n b := by + rw [source_fair_code_expect T n b (fun bits => if SourceTreeFit T n b bits then 0 else 1)] + exact sourceTreeFit_tail_interior T n b hn he + +/-- A fixed public decoder. It does not know the hidden orientations or the + input hypothesis, and it drops rather than reveals all pairing flags. -/ +def sourceOracleDecode {Side Leaf : Type} (T n : ℕ → ℕ) (b : ℕ) + (f : Side → List Bool) (g : Leaf → List Bool) : + ((Reports Side (SourceTrialCount T n b) × (Fin (SourceLeafCount T b) → Leaf)) × + (Fin (SourceFillerCount T b) → Side)) → List Bool := fun x => + coordinateWord (fun j => PairedMechanisms.slotDecode f g (sourceChronologyCode T n b j) + (emissionAssignmentEquiv Side Leaf (SourceTrialCount T n b) (SourceFillerCount T b) + (SourceLeafCount T b) (fun i => (x.1.1 i).2,x.2,x.1.2) (sourceChronologyCode T n b j))) + +/-- The complete canonical oracle now simulates the LITERAL source block. + All IDs, words, leaf types and chronology instantiate the actual construction. + The only failed-layout cost is its original unconditional fair-bit mass. -/ +theorem source_canonical_simulation {Side Leaf : Type} [Fintype Side] [Fintype Leaf] + {q E : ℝ} (hq : q∈Set.Icc 0 1) (hE : 0≤E) + (s : ℕ) (P T n h : ℕ → ℕ) (atom : Bool → List Bool) (b : ℕ) + (H : SourceLayoutMargins s P T n h b) + (hP : P b=n b*(2*h b+1)+T b) (hT : Even (T b)) + (hlarge : 4*(n b+1)≤T b) (hmotif : 8*2^s≤T b) + (hn : ∀j + SourceTreeFit T n (b+1) ((sourceAssignmentCode T n Bool (b+1)).symm bits) + have hw (bits : Fin (SourceTrialCount T n (b+1)) → Bool) (hg : good bits) := + sourceChronologicalWord_eq_block s P T n h atom b H hP hT hlarge hmotif + ((sourceAssignmentCode T n Bool (b+1)).symm bits) τ hg + have hs := M.canonical_filled_simulation hq hE (sourceChronologyCode T n (b+1)) R A B f g + (sourceFlatTrialWord s P T n h atom (b+1) false) + (sourceFlatTrialWord s P T n h atom (b+1) true) + (sourceFlatFillerWord s P T n h atom (b+1)) atom hU hV hW hA hB + (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) + (sourceBlockWord s P atom (b+1) τ) good (fun bits hg => by + rw [source_slotCode_word] + exact hw bits hg) + intro F hF + exact (hs F hF).trans (add_le_add le_rfl (source_flat_fit_tail T n (b+1) (fun j hj => hn j (by omega)) + (fun j hj => H.even_trials j (by omega)))) + +end TraceReconstruction + +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/TraceReconstruction/SourceOracle.lean b/lean/OAI/Probability/TraceReconstruction/SourceOracle.lean index 8a47bec4e0fcb0e5240c8047231614e626ca9367..adbd0bb7f52562fe02ff2d5a81814b12b23a2edd 100644 --- a/lean/OAI/Probability/TraceReconstruction/SourceOracle.lean +++ b/lean/OAI/Probability/TraceReconstruction/SourceOracle.lean @@ -1,1852 +1,1852 @@ -import OAI.Probability.TraceReconstruction.Simulation - -namespace OAI - -/-! -# SourceOracle - -Actual source mechanisms and posteriors, typical metadata, sparse degrees, common-event clipping, approximate oracles, and mixed Hellinger bounds. --/ - -open scoped ENNReal -noncomputable section - -open Filter -open scoped Topology - - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Ambient finite trace-space choice does not lose any of the genuine -complete-trace common mass. The embedding adds only zero-mass points. -/ -theorem listTraceOverlap_le_ambient {q : ℝ} (hq : q∈Set.Icc 0 1) - (x y : List Bool) (M : ℕ) (hx : x.length≤M) (hy : y.length≤M) : - listTraceOverlap q hq x y≤ - (listTraceLaw q hq x M hx).overlap (listTraceLaw q hq y M hy) := by - let M₀ := max x.length y.length - have H := approximations_trace_tv hq - (listTraceLaw q hq x M₀ (le_max_left _ _)) - (listTraceLaw q hq y M₀ (le_max_right _ _)) Subtype.val x y 0 0 M hx hy - (listTraceLaw_simulates q hq x M₀ _).approximate - (listTraceLaw_simulates q hq y M₀ _).approximate - simp only [add_zero] at H - unfold listTraceOverlap - rw [FiniteLaw.overlap_eq_one_sub_tv,FiniteLaw.overlap_eq_one_sub_tv] - linarith - -theorem listTraceOverlap_ambient {q : ℝ} (hq : q∈Set.Icc 0 1) - (x y : List Bool) (M : ℕ) (hx : x.length≤M) (hy : y.length≤M) : - listTraceOverlap q hq x y= - (listTraceLaw q hq x M hx).overlap (listTraceLaw q hq y M hy) := by - apply le_antisymm (listTraceOverlap_le_ambient hq x y M hx hy) - exact simulations_overlap_le hq _ _ Subtype.val x y - (listTraceLaw_simulates q hq x M hx) (listTraceLaw_simulates q hq y M hy) - -namespace FiniteLaw -variable {α : Type*} [Fintype α] -theorem commonPart_le_right (P Q : FiniteLaw α) (h : 0 exact PEmpty.elim i - | succ b ih => - rcases i with i | i | ⟨u,i⟩ - · simpa [sourceTrialWord,bitIndex] using hov b (by omega) - · cases b with - | zero => exact Fin.elim0 i - | succ b => simpa [sourceTrialWord,bitIndex] using hov b (by omega) - · exact ih (fun j hj => hov j (by omega)) i - -/-- A common finite side-trace space exists without changing any word. -/ -theorem finite_word_bound {ι : Type*} [Fintype ι] (w : ι → List Bool) : - ∃M,∀i,(w i).length≤M := by - refine ⟨∑i,(w i).length, fun i => ?_⟩ - exact Finset.single_le_sum (f:=fun i => (w i).length) (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The actual report flags, in the literal nested trial coordinates. -/ -def sourceReportFlags {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) - (z : Reports Side (SourceTrialCount T n b)) : - WindowAssignments T n (sourceScheduledTrials T n) (Option Bool) b := - (sourceAssignmentCode T n (Option Bool) b).symm (fun j => (z j).1) - -/-- Exact change of coordinates for the posterior of all hidden bits, not - just separate local marginals. -/ -theorem source_posterior_code_expect {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) - (z : Reports Side (SourceTrialCount T n b)) - (F : WindowAssignments T n (sourceScheduledTrials T n) Bool b → ℝ) : - (PairedMechanisms.orientationsGiven z).expect - (fun bits => F ((sourceAssignmentCode T n Bool b).symm bits)) = - (windowPosteriorLaw T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z)).expect F := by - rw [windowPosterior_expect_flat,FiniteLaw.indexedProduct_expect_equiv _ (finEnumeration _)] - simp only [sourceReportFlags,sourceAssignmentCode_eval] - simp only [PairedMechanisms.orientationsGiven,FiniteLaw.expect,FiniteLaw.coordinateProduct, - FiniteLaw.indexedProduct,sourceAssignmentCode,Equiv.coe_fn_symm_mk] - apply Finset.sum_congr (by ext; simp) - intro bits _ - rfl - -/-- A monomial is precisely its set of actual leaf addresses. -/ -def sourceSubsetCode (T : ℕ → ℕ) (b : ℕ) : - (Fin (SourceLeafCount T b) → Bool) ≃ Finset (WindowLeaf T b) := - (maskSubsetEquiv _).trans (Equiv.finsetCongr (finEnumeration _)) - -theorem sourceSubsetCode_card (T : ℕ → ℕ) (b : ℕ) - (σ : Fin (SourceLeafCount T b) → Bool) : - (sourceSubsetCode T b σ).card=monomialDegree σ := by - simp only [sourceSubsetCode,Equiv.trans_apply,Equiv.finsetCongr_apply,Finset.card_map] - rfl - -theorem selectionCoefficient_sign {k : ℕ} (θ σ : Fin k → Bool) : - selectionCoefficient θ σ=∏j∈maskSubset σ,(1-boolTypeSign (θ j))/2 := by - unfold selectionCoefficient maskSubset - rw [Finset.prod_filter] - apply Finset.prod_congr rfl - intro j _ - cases σ j <;> cases θ j <;> norm_num [boolTypeSign] - -theorem source_leaf_selection (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (b : ℕ) (bits : WindowAssignments T n (sourceScheduledTrials T n) Bool b) - (incoming : ℤ) (τ : Bool) (σ : Fin (SourceLeafCount T b) → Bool) : - selectionCoefficient - (fun j => sourceTreeLeafBool T n s center b bits incoming τ (finEnumeration _ j)) σ = - ∏v∈sourceSubsetCode T b σ, - (1-sourceTreeLeafSign T n (sourceScheduledTrials T n) s center - (sourceScheduledShift T n) b bits incoming (boolTypeSign τ) v)/2 := by - rw [selectionCoefficient_sign] - simp only [sourceSubsetCode,Equiv.trans_apply,Equiv.finsetCongr_apply,Finset.prod_map] - apply Finset.prod_congr rfl - intro j _ - rw [sourceTreeLeafBool_sign] - rfl - -/-- The real canonical-oracle coefficient difference is the exact source - polynomial coefficient whose forced-tree energy has been proved. -/ -theorem source_canonical_coefficient {Side : Type*} (T n : ℕ → ℕ) (s : ℕ) - (center : ℕ → ℤ) (b : ℕ) (incoming : ℤ) - (z : Reports Side (SourceTrialCount T n (b+1))) - (σ : Fin (SourceLeafCount T (b+1)) → Bool) : - averagedCoefficient (PairedMechanisms.orientationsGiven z) - (sourceFlatLeafType T n s center (b+1) incoming false) σ - - averagedCoefficient (PairedMechanisms.orientationsGiven z) - (sourceFlatLeafType T n s center (b+1) incoming true) σ = - sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) - b (sourceReportFlags T n (b+1) z) incoming (sourceSubsetCode T (b+1) σ) := by - unfold averagedCoefficient sourceFlatLeafType - rw [source_posterior_code_expect T n (b+1) z - (fun bits => selectionCoefficient - (fun j => sourceTreeLeafBool T n s center (b+1) bits incoming false (finEnumeration _ j)) σ), - source_posterior_code_expect T n (b+1) z - (fun bits => selectionCoefficient - (fun j => sourceTreeLeafBool T n s center (b+1) bits incoming true (finEnumeration _ j)) σ)] - simp_rw [source_leaf_selection] - rfl - -/-- Reindexing preserves the entire degree-r square sum, including zero - and degrees larger than the number of real leaves. -/ -theorem source_canonical_degree_sum {Side : Type*} (T n : ℕ → ℕ) (s : ℕ) - (center : ℕ → ℤ) (b r : ℕ) (incoming : ℤ) - (z : Reports Side (SourceTrialCount T n (b+1))) : - (∑σ : Fin (SourceLeafCount T (b+1)) → Bool, if monomialDegree σ=r then - (averagedCoefficient (PairedMechanisms.orientationsGiven z) - (sourceFlatLeafType T n s center (b+1) incoming false) σ - - averagedCoefficient (PairedMechanisms.orientationsGiven z) - (sourceFlatLeafType T n s center (b+1) incoming true) σ)^2 else 0) = - ∑S : DegreeLeafSubset T b r, - (sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) - b (sourceReportFlags T n (b+1) z) incoming S.val)^2 := by - simp_rw [source_canonical_coefficient,←sourceSubsetCode_card] - rw [(sourceSubsetCode T (b+1)).sum_comp - (fun S => if S.card=r then (sourceCoefficient T n (sourceScheduledTrials T n) s center - (sourceScheduledShift T n) b (sourceReportFlags T n (b+1) z) incoming S)^2 else 0)] - let f : DegreeLeafSubset T b r → ℝ := fun S => - (sourceCoefficient T n (sourceScheduledTrials T n) s center (sourceScheduledShift T n) - b (sourceReportFlags T n (b+1) z) incoming S.val)^2 - simpa only [f, dite_eq_ite] using - sum_subtype_zero_extend (fun S : Finset (WindowLeaf T (b+1)) => S.card=r) f - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical -namespace PairedMechanisms -variable {Side : Type*} [Fintype Side] {m : ℕ} (M : PairedMechanisms Side m) - -def hiddenSubset (S : Finset (Fin m)) (z : Reports Side m) : ℕ := ∑i : S,hiddenTrial (z i.val).1 - -theorem hiddenSubset_mgf (S : Finset (Fin m)) {ω t : ℝ} (hw : ∀i,M.hiddenWeight i=ω) - (hp : ω^2∈Set.Icc 0 1) (ht : |t|≤1) : - M.reports.expect (fun z => Real.exp (t*((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)))≤ - Real.exp ((S.card:ℝ)*t^2) := by - have he (z : Reports Side m) : - Real.exp (t*((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2))= - ∏i : S,Real.exp (t*((hiddenTrial (z i.val).1:ℕ)-ω^2)) := by - rw [←Real.exp_sum] - congr 1 - simp only [mul_sub,Finset.mul_sum,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_coe, - nsmul_eq_mul,hiddenSubset,Nat.cast_sum] - ring - simp_rw [he] - rw [reports,FiniteLaw.coordinateProduct_expect_subtype _ S - (fun (_ : S) (z : Option Bool × (Side × Side)) => Real.exp (t*((hiddenTrial z.1:ℕ)-ω^2)))] - calc - _ ≤ ∏i : S,Real.exp (t^2) := by - apply Finset.prod_le_prod₀ - · intro i _ - exact Finset.sum_nonneg (fun z _ => mul_nonneg - ((FiniteLaw.pairedReport (M.first i.val) (M.second i.val) (M.common i.val) (M.weight_nonneg i.val) - (M.common_first i.val) (M.common_second i.val)).nonneg z) (Real.exp_nonneg _)) - · intro i _ - have h := FiniteLaw.pairedReport_hidden_mgf (M.first i.val) (M.second i.val) (M.common i.val) - (M.weight_nonneg i.val) (M.common_first i.val) (M.common_second i.val) (by simpa [hw i.val] using hp) ht - simpa only [hw i.val] using h - _ = _ := by simp only [Finset.prod_const,Finset.card_univ,Fintype.card_coe,Real.exp_nat_mul] - -/-- A quantitative unconditional bound for failure of a source hidden-count - condition. The exponent ω⁴m is sufficient for the uniform scale margins. -/ -theorem hiddenSubset_small (S : Finset (Fin m)) {ω : ℝ} (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : - M.reports.expect (fun z => if (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 then 1 else 0)≤ - Real.exp (-(S.card:ℝ)*ω^4/16) := by - have ht : 0≤ω^2/4 := by positivity - have ht' : |-(ω^2/4)|≤1 := by rw [abs_neg,abs_of_nonneg ht]; linarith [hp.2] - have H := finite_exp_markov Finset.univ M.reports.mass - (fun z => -((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)) (fun z _ => M.reports.nonneg z) - ((S.card:ℝ)*ω^2/2) (ω^2/4) ht - have hm := M.hiddenSubset_mgf S hw hp ht' - have hsub : M.reports.expect (fun z => if (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 then 1 else 0)≤ - ∑z∈Finset.univ.filter (fun z => (S.card:ℝ)*ω^2/2≤-((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)),M.reports.mass z := by - rw [Finset.sum_filter] - apply Finset.sum_le_sum - intro z _ - dsimp only - by_cases hz : (hiddenSubset S z:ℝ)<(S.card:ℝ)*ω^2/2 - · rw [ite_eq_left hz,ite_eq_left (by linarith : (S.card:ℝ)*ω^2/2≤-((hiddenSubset S z:ℕ)-(S.card:ℝ)*ω^2)),mul_one] - · rw [ite_eq_right hz,mul_zero]; split_ifs <;> positivity [M.reports.nonneg z] - calc - _ ≤ _ := hsub.trans H - _ ≤ Real.exp (-(ω^2/4)*((S.card:ℝ)*ω^2/2))*Real.exp ((S.card:ℝ)*(-(ω^2/4))^2) := by - apply mul_le_mul_of_nonneg_left _ (Real.exp_nonneg _) - simpa only [FiniteLaw.expect,neg_mul,mul_neg,neg_neg] using hm - _ = _ := by rw [←Real.exp_add]; congr 1; ring - - -end PairedMechanisms -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- IDs for precisely one local and one global collection at every genuine - nonleaf of the complete source window tree. -/ -def WindowCollection (T : ℕ → ℕ) : ℕ → Type - | 0 => PEmpty - | b+1 => Bool ⊕ (Fin (T b) × WindowCollection T b) - -noncomputable instance windowCollectionFintype (T : ℕ → ℕ) : - (b : ℕ) → Fintype (WindowCollection T b) - | 0 => inferInstanceAs (Fintype PEmpty) - | b+1 => by - letI := windowCollectionFintype T b - exact inferInstanceAs (Fintype (Bool ⊕ (Fin (T b) × WindowCollection T b))) - -def collectionCount (T n g : ℕ → ℕ) : (b : ℕ) → WindowCollection T b → ℕ - | b+1, .inl false => n b - | b+1, .inl true => g b - | b+1, .inr (_,v) => collectionCount T n g b v - -def collectionTrial (T n g : ℕ → ℕ) : - (b : ℕ) → (v : WindowCollection T b) → Fin (collectionCount T n g b v) → WindowTrial T n g b - | _+1, .inl false, j => .inl j - | _+1, .inl true, j => .inr (.inl j) - | b+1, .inr (u,v), j => .inr (.inr (u,collectionTrial T n g b v j)) - -theorem collectionTrial_injective (T n g : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : - Function.Injective (collectionTrial T n g b v) := by - induction b with - | zero => exact PEmpty.elim v - | succ b ih => - rcases v with v | ⟨u,v⟩ - · cases v - · intro i j h - exact Sum.inl.inj h - · intro i j h - exact Sum.inl.inj (Sum.inr.inj h) - · intro i j h - apply ih v - exact congrArg Prod.snd (Sum.inr.inj (Sum.inr.inj h)) - -def collectionFlags (T n g : ℕ → ℕ) {A : Type} : - (b : ℕ) → WindowAssignments T n g A b → (v : WindowCollection T b) → - Fin (collectionCount T n g b v) → A - | _+1, d, .inl false => d.1 - | _+1, d, .inl true => d.2.1 - | b+1, d, .inr (u,v) => collectionFlags T n g b (d.2.2 u) v - -theorem collectionFlags_trial (T n g : ℕ → ℕ) {A : Type} (b : ℕ) - (d : WindowAssignments T n g A b) (v : WindowCollection T b) - (j : Fin (collectionCount T n g b v)) : - collectionFlags T n g b d v j= - windowAssignmentEquiv T n g A b d (collectionTrial T n g b v j) := by - induction b with - | zero => exact PEmpty.elim v - | succ b ih => - rcases v with v | ⟨u,v⟩ - · cases v <;> rfl - · exact ih (d.2.2 u) v j - -/-- This is the source hidden-count predicate, before any conditioning on fit. -/ -def HiddenCollectionConditions (T n g : ℕ → ℕ) (ω : ℝ) : - (b : ℕ) → WindowAssignments T n g (Option Bool) b → Prop - | 0, _ => True - | b+1, d => - (n b:ℝ)*ω^2/2≤∑i,(hiddenTrial (d.1 i):ℝ) ∧ - (g b:ℝ)*ω^2/2≤∑i,(hiddenTrial (d.2.1 i):ℝ) ∧ - ∀u,HiddenCollectionConditions T n g ω b (d.2.2 u) - -theorem hiddenCollectionConditions_iff (T n g : ℕ → ℕ) (ω : ℝ) (b : ℕ) - (d : WindowAssignments T n g (Option Bool) b) : - HiddenCollectionConditions T n g ω b d ↔ - ∀v : WindowCollection T b,(collectionCount T n g b v:ℝ)*ω^2/2≤ - ∑i,(hiddenTrial (collectionFlags T n g b d v i):ℝ) := by - induction b with - | zero => simp [HiddenCollectionConditions,WindowCollection] - | succ b ih => - constructor - · intro h v - rcases v with v | ⟨u,v⟩ - · cases v - · exact h.1 - · exact h.2.1 - · exact (ih (d.2.2 u)).mp (h.2.2 u) v - · intro h - refine ⟨h (.inl false),h (.inl true),fun u => (ih (d.2.2 u)).mpr ?_⟩ - intro v - exact h (.inr (u,v)) - -def sourceCollectionIndex (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : - Fin (collectionCount T n (sourceScheduledTrials T n) b v) → Fin (SourceTrialCount T n b) := - fun j => (finEnumeration _).symm (collectionTrial T n (sourceScheduledTrials T n) b v j) - -theorem sourceCollectionIndex_injective (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : - Function.Injective (sourceCollectionIndex T n b v) := - (finEnumeration _).symm.injective.comp (collectionTrial_injective T n _ b v) - -def sourceCollectionSet (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : - Finset (Fin (SourceTrialCount T n b)) := Finset.univ.image (sourceCollectionIndex T n b v) - -theorem sourceCollectionSet_card (T n : ℕ → ℕ) (b : ℕ) (v : WindowCollection T b) : - (sourceCollectionSet T n b v).card=collectionCount T n (sourceScheduledTrials T n) b v := by - rw [sourceCollectionSet,Finset.card_image_of_injective _ (sourceCollectionIndex_injective T n b v)] - simp only [Finset.card_univ,Fintype.card_fin] - -theorem sourceCollection_flags {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) - (z : Reports Side (SourceTrialCount T n b)) (v : WindowCollection T b) - (j : Fin (collectionCount T n (sourceScheduledTrials T n) b v)) : - collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v j= - (z (sourceCollectionIndex T n b v j)).1 := by - rw [collectionFlags_trial] - have h := sourceAssignmentCode_eval T n (Option Bool) b (fun j => (z j).1) - (sourceCollectionIndex T n b v j) - simpa only [sourceCollectionIndex,Equiv.apply_symm_apply,sourceReportFlags] using h - -theorem sourceCollection_hidden {Side : Type*} (T n : ℕ → ℕ) (b : ℕ) - (z : Reports Side (SourceTrialCount T n b)) (v : WindowCollection T b) : - PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z= - ∑i,hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i) := by - unfold PairedMechanisms.hiddenSubset - rw [←Finset.sum_subtype (sourceCollectionSet T n b v) (fun _ => Iff.rfl) - (fun j => hiddenTrial (z j).1)] - rw [sourceCollectionSet,Finset.sum_image] - · simp_rw [sourceCollection_flags] - · exact (sourceCollectionIndex_injective T n b v).injOn - -/-- Exact finite-union metadata cost; it contains no postulated typical - event and no independence assertion between different collections. -/ -def sourceHiddenTail (T n : ℕ → ℕ) (b : ℕ) (ω : ℝ) : ℝ := - ∑v : WindowCollection T b,Real.exp (-(collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^4/16) - -theorem source_hidden_conditions_tail {Side : Type*} [Fintype Side] - (T n : ℕ → ℕ) (b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n b)) - (ω : ℝ) (hw : ∀i,M.hiddenWeight i=ω) (hp : ω^2∈Set.Icc 0 1) : - M.reports.expect (fun z => if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω b - (sourceReportFlags T n b z) then 0 else 1) ≤ sourceHiddenTail T n b ω := by - calc - _ ≤ M.reports.expect (fun z => ∑v : WindowCollection T b, - if (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ - ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) - then 0 else 1) := by - apply FiniteLaw.expect_mono - intro z - simp only [hiddenCollectionConditions_iff] - exact failure_forall_le_sum _ - _ = ∑v : WindowCollection T b,M.reports.expect (fun z => - if (PairedMechanisms.hiddenSubset (sourceCollectionSet T n b v) z:ℝ)< - ((sourceCollectionSet T n b v).card:ℝ)*ω^2/2 then 1 else 0) := by - rw [FiniteLaw.expect_fintype_sum] - apply Finset.sum_congr rfl - intro v _ - apply congrArg (FiniteLaw.expect M.reports) - funext z - rw [sourceCollectionSet_card,sourceCollection_hidden,Nat.cast_sum] - by_cases h : (collectionCount T n (sourceScheduledTrials T n) b v:ℝ)*ω^2/2≤ - ∑i,(hiddenTrial (collectionFlags T n (sourceScheduledTrials T n) b (sourceReportFlags T n b z) v i):ℝ) - · simp [h,not_lt.mpr h] - · simp [h,lt_of_not_ge h] - _ ≤ _ := by - apply Finset.sum_le_sum - intro v _ - simpa only [sourceCollectionSet_card] using M.hiddenSubset_small (sourceCollectionSet T n b v) hw hp - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Numerical cap forced by at least half the mean number of hidden pairs. -/ -def hiddenBinomialCap (m : ℕ) (ω : ℝ) : ℝ := Real.sqrt (4/((m:ℝ)*ω^2+2)) - -theorem hiddenBinomialCap_nonneg (m : ℕ) (ω : ℝ) : 0≤hiddenBinomialCap m ω := - Real.sqrt_nonneg _ - -theorem hidden_binomial_bound (m G : ℕ) (ω : ℝ) - (h : (m:ℝ)*ω^2/2≤G) : binomialBound G≤hiddenBinomialCap m ω := by - apply Real.sqrt_le_sqrt - apply (div_le_div_iff₀ (by positivity : (0:ℝ) hiddenBinomialCap (n j) ω) - (fun j => hiddenBinomialCap (g j) ω) b d := by - induction b with - | zero => trivial - | succ b ih => - refine ⟨hidden_binomial_bound (n b) _ ω ?_,hidden_binomial_bound (g b) _ ω ?_,fun u => ih _ (h.2.2 u)⟩ - · simpa only [Nat.cast_sum] using h.1 - · simpa only [Nat.cast_sum] using h.2.1 - -theorem hiddenConditions_smoothingCap (T n g : ℕ → ℕ) (ω η : ℝ) (s b : ℕ) - (hη : ∀j trivial - | succ b ih => - exact ⟨(hidden_smoothing_bound d.1 s ω h.1).trans (hη b (by omega)), - fun u => ih (fun j hj => hη j (by omega)) _ (h.2.2 u)⟩ - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- The actual noncentral posterior mass has the unconditional honest - fit-error bound. Impossible reports cause no problem in Bayes averaging. -/ -theorem source_noncentral_average {Side : Type*} [Fintype Side] - (T n : ℕ → ℕ) (s b : ℕ) (M : PairedMechanisms Side (SourceTrialCount T n (b+1))) - (hn : ∀j,j sourceNoncentralMass T n (sourceScheduledTrials T n) s - (sourceLocalCenter T n) (sourceScheduledShift T n) (fun j => centralThird (T j)) - (b+1) (sourceReportFlags T n (b+1) z) 0) ≤ sourceFitTail T n (b+1) := by - calc - _ ≤ M.reports.expect (fun z => - (windowPosteriorLaw T n (sourceScheduledTrials T n) (b+1) (sourceReportFlags T n (b+1) z)).expect - (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1)) := by - apply FiniteLaw.expect_mono - intro z - exact sourceNoncentralMass_le_fit T n s b (sourceLocalCenter T n) (fun _ _ => rfl) - hT he hL hroot _ - _ = M.reports.expect (fun z => (PairedMechanisms.orientationsGiven z).expect - (fun bits => if SourceTreeFit T n (b+1) ((sourceAssignmentCode T n Bool (b+1)).symm bits) then 0 else 1)) := by - apply congrArg (FiniteLaw.expect M.reports) - funext z - exact (source_posterior_code_expect T n (b+1) z - (fun bits => if SourceTreeFit T n (b+1) bits then 0 else 1)).symm - _ = _ := M.posterior_average _ - _ ≤ _ := source_flat_fit_tail T n (b+1) (fun j hj => hn j (by omega)) (fun j hj => hne j (by omega)) - -/-- Markov for a genuine finite law, stated for the exact failure indicator. -/ -theorem FiniteLaw.positive_markov {α : Type*} [Fintype α] (P : FiniteLaw α) - (f : α → ℝ) (hf : ∀x,0≤f x) {a : ℝ} (ha : 0 if a≤f x then 1 else 0) ≤ P.expect f/a := by - apply (le_div_iff₀ ha).mpr - rw [mul_comm,←FiniteLaw.expect_const_mul] - apply FiniteLaw.expect_mono - intro x - split_ifs with hx - · simpa only [mul_one] using hx - · simpa only [mul_zero] using hf x - -/-- One metadata event, fixed before choosing a coefficient, controls - local and global smoothing and all internal central-third tests. -/ -def SourceTypical {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) (ω a : ℝ) - (z : Reports Side (SourceTrialCount T n (b+1))) : Prop := - HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) - (sourceReportFlags T n (b+1) z) ∧ - sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) - (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) - (sourceReportFlags T n (b+1) z) 0 if SourceTypical T n s b ω a z then 0 else 1) ≤ - sourceHiddenTail T n (b+1) ω+sourceFitTail T n (b+1)/a := by - let f := fun z : Reports Side (SourceTrialCount T n (b+1)) => - sourceNoncentralMass T n (sourceScheduledTrials T n) s (sourceLocalCenter T n) - (sourceScheduledShift T n) (fun j => centralThird (T j)) (b+1) - (sourceReportFlags T n (b+1) z) 0 - calc - _ ≤ M.reports.expect (fun z => - (if HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) - (sourceReportFlags T n (b+1) z) then 0 else 1)+(if a≤f z then 1 else 0)) := by - apply FiniteLaw.expect_mono - intro z - by_cases H : SourceTypical T n s b ω a z - · rw [ite_eq_left H] - split_ifs <;> norm_num - · rw [ite_eq_right H] - by_cases h : HiddenCollectionConditions T n (sourceScheduledTrials T n) ω (b+1) - (sourceReportFlags T n (b+1) z) - · have hf : ¬f z H ⟨h,hf⟩ - rw [ite_eq_left h,ite_eq_left (le_of_not_gt hf)] - norm_num - · rw [ite_eq_right h] - split_ifs <;> norm_num - _ ≤ _ := by - rw [FiniteLaw.expect_add] - apply add_le_add (source_hidden_conditions_tail T n (b+1) M ω hw hp) - apply (M.reports.positive_markov f (fun z => sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).trans - exact div_le_div_of_nonneg_right - (source_noncentral_average T n s b M hn hne hT he hL hroot) ha.le - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Exact common plateau with integer half-count centering. Unlike the - simplified g/2 formula, this identity needs no parity assumption. -/ -theorem scheduledGlobalShift_plateau_exact (N t : ℕ) - (bits : Fin ((N/4)*t) → Bool) (u : Fin N) (hu : u∈centralThird N) : - scheduledGlobalShift N t bits u = (∑i,(bitIndex (bits i):ℤ))-(N/4:ℕ)*(t/2:ℕ) := by - calc - _ = ∑v : Fin (N/4), - ((∑a : Fin t, (bitIndex (bits (globalTrialIndex N t v a)):ℤ))-(t/2:ℕ)) := by - apply Finset.sum_congr rfl - intro v _ - exact ite_eq_left (centralThird_active N u hu v) - _ = _ := by - rw [Finset.sum_sub_distrib] - congr 1 - · exact globalTrial_sum N t (fun i => (bitIndex (bits i):ℤ)) - · simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] - -def sourcePlateauCenter (T n : ℕ → ℕ) : ℕ → ℤ - | 0 => 0 - | b+1 => (T (b+1)/4:ℕ)*(n b/2:ℕ) - -theorem sourceScheduledShift_hasPlateau (T n : ℕ → ℕ) : - HasGlobalPlateau T (sourceScheduledTrials T n) (fun j => centralThird (T j)) - (sourcePlateauCenter T n) (sourceScheduledShift T n) := by - intro b bits u hu - cases b with - | zero => - change (0:ℤ)=(∑i : Fin 0,(bitIndex (bits i):ℤ))-0 - simp - | succ b => exact scheduledGlobalShift_plateau_exact (T (b+1)) (n b) bits u hu - -def sourceForcedBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω : ℝ) : ℝ := - (OccupiedParityTree.shapeRoleConstant r (b+1):ℝ)*interiorLabelBudget T b r * - ((2^s:ℕ):ℝ)^(2*(r-2^(b+1))) * - ((2*((2^s:ℕ):ℝ)^3*hiddenBinomialCap (n b) ω)* - binaryTreeBudget (fun j => 4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) b) - -theorem sourceForcedBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω : ℝ) : - 0 ≤ sourceForcedBudget T n s b r ω := by - have hB := fun j => hiddenBinomialCap_nonneg (n j) ω - have hC := fun j => hiddenBinomialCap_nonneg (sourceScheduledTrials T n j) ω - have ht := binaryTreeBudget_nonneg (fun j => 4*((2^s:ℕ):ℝ)^6* - hiddenBinomialCap (sourceScheduledTrials T n (j+1)) ω*hiddenBinomialCap (n j) ω) - (fun j => mul_nonneg (mul_nonneg (by positivity) (hC (j+1))) (hB j)) b - have hb := hB b - unfold sourceForcedBudget interiorLabelBudget - positivity - -/-- Full unabsorbed bound, now with no placeholder anchor-energy hypothesis. -/ -def sourceDegreeBudget (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : ℝ := - 4*(3^((b+1)*r):ℕ)* - (((SourceLeafCount T (b+1)).choose r:ℕ)*(3^((b+1)*r):ℕ)*(η^2+a^2)+ - sourceForcedBudget T n s b r ω) - -theorem sourceDegreeBudget_nonneg (T n : ℕ → ℕ) (s b r : ℕ) (ω η a : ℝ) : - 0 ≤ sourceDegreeBudget T n s b r ω η a := by - have h := sourceForcedBudget_nonneg T n s b r ω - unfold sourceDegreeBudget - positivity - -theorem source_canonical_degree_bound {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 centralThird (T j)) b r - (sourceReportFlags T n (b+1) z) 0 η - (hiddenConditions_smoothingCap T n _ ω η s (b+1) hη _ hz.1)).trans - apply mul_le_mul_of_nonneg_left _ (by positivity) - apply add_le_add - · apply mul_le_mul_of_nonneg_left _ (by positivity) - apply add_le_add_right - exact (sq_le_sq₀ (sourceNoncentralMass_nonneg T n _ s _ _ _ _ _ _) ha).mpr hz.2.le - · exact degreeForcedRoleEnergy_bound T n _ hT s (sourceLocalCenter T n) _ _ _ (sourceScheduledShift_hasPlateau T n) - (fun j => hiddenBinomialCap (n j) ω) (fun j => hiddenBinomialCap (sourceScheduledTrials T n j) ω) - (fun j => hiddenBinomialCap_nonneg _ _) (fun j => hiddenBinomialCap_nonneg _ _) - b r _ (hiddenConditions_binomialCaps T n _ ω (b+1) _ hz.1) 0 - -end TraceReconstruction - - -noncomputable section -namespace TraceReconstruction -open scoped Classical - -/-- Pointwise equality of the literal source types and the signed tree types. - This holds for every assignment, including overflowing windows. -/ -theorem sourceFlatLeafType_window (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (b : ℕ) (incoming : ℤ) (τ : Bool) (bits : Fin (SourceTrialCount T n b) → Bool) : - sourceFlatLeafType T n s center b incoming τ bits = - windowFinType T s (sourceTreeAnchors T n (sourceScheduledTrials T n) center - (sourceScheduledShift T n) b ((sourceAssignmentCode T n Bool b).symm bits) incoming) - b (boolTypeSign τ) := by - funext j - unfold sourceFlatLeafType windowFinType windowLeafType - rw [←sourceTreeLeafSign_eq,←sourceTreeLeafBool_sign] - change sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j)= - decide (boolTypeSign (sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j))= -1) - cases sourceTreeLeafBool T n s center b _ incoming τ (finEnumeration _ j) <;> norm_num [boolTypeSign] - -def sourceSparseCount (T : ℕ → ℕ) (s b : ℕ) : ℕ := - 2^s*∏j∈Finset.range b,T (j+1) - -theorem sourceFlatLeafType_sparse (T n : ℕ → ℕ) (s : ℕ) (center : ℕ → ℤ) - (b : ℕ) (incoming : ℤ) (τ : Bool) (bits : Fin (SourceTrialCount T n (b+1)) → Bool) : - monomialDegree (sourceFlatLeafType T n s center (b+1) incoming τ bits) ≤ sourceSparseCount T s b := by - rw [sourceFlatLeafType_window,windowFinType_degree] - exact windowMinusCount_bound T s _ b [] _ - -def sourceOracleCoefficient {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : - (Fin (SourceLeafCount T (b+1)) → Bool) → ℝ := - averagedCoefficient (PairedMechanisms.orientationsGiven z) - (sourceFlatLeafType T n s (sourceLocalCenter T n) (b+1) 0 τ) - -theorem sourceOracleCoefficient_empty {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : - sourceOracleCoefficient T n s b z τ (fun _ => false)=1 := averagedCoefficient_empty _ _ - -theorem sourceOracleCoefficient_degree {Side : Type*} (T n : ℕ → ℕ) (s b r : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) : - (∑σ, if monomialDegree σ=r then (sourceOracleCoefficient T n s b z τ σ)^2 else 0) ≤ - ((sourceSparseCount T s b).choose r:ℝ) := - averaged_sparse_degree _ _ (sourceFlatLeafType_sparse T n s _ b 0 τ) r - -def sourceSignedCoefficient {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (σ : Fin (SourceLeafCount T (b+1)) → Bool) : ℝ := - sourceOracleCoefficient T n s b z false σ-sourceOracleCoefficient T n s b z true σ - -theorem sourceSignedCoefficient_zero {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) : - (∑σ, if monomialDegree σ=0 then sourceSignedCoefficient T n s b z σ^2 else 0)=0 := by - simp [monomialDegree_eq_zero_iff,sourceSignedCoefficient,sourceOracleCoefficient_empty] - -theorem sourceSignedCoefficient_degree_geometric {Side : Type*} (T n : ℕ → ℕ) (s b r : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (w : ℝ) : - w^(2*r)*(∑σ, if monomialDegree σ=r then sourceSignedCoefficient T n s b z σ^2 else 0) ≤ - 4*(w^2*sourceSparseCount T s b)^r := by - have h0 : 0 ≤ w^(2*r) := by rw [pow_mul]; positivity - have hp := sourceOracleCoefficient_degree T n s b r z false - have hm := sourceOracleCoefficient_degree T n s b r z true - have hc : ((sourceSparseCount T s b).choose r:ℝ) ≤ (sourceSparseCount T s b:ℝ)^r := by - exact_mod_cast Nat.choose_le_pow (sourceSparseCount T s b) r - have hd := degree_square_sub_le (sourceOracleCoefficient T n s b z false) - (sourceOracleCoefficient T n s b z true) r - calc - _ ≤ w^(2*r)*(4*(sourceSparseCount T s b:ℝ)^r) := - mul_le_mul_of_nonneg_left (by dsimp only [sourceSignedCoefficient]; linarith) h0 - _ = _ := by rw [pow_mul,mul_pow]; ring - -def sourceEnergyBudget (T n : ℕ → ℕ) (s b R : ℕ) (ω η a w : ℝ) : ℝ := - (∑r∈Finset.range R, w^(2*r)*(if r=0 then 0 else sourceDegreeBudget T n s b r ω η a))+ - 4*(w^2*sourceSparseCount T s b)^R/(1-w^2*sourceSparseCount T s b) - -/-- Complete signed energy, with finite low-degree forced-tree bound and - the geometric high tail. No coefficient estimates remain as hypotheses. -/ -theorem source_canonical_energy {Side : Type*} (T n : ℕ → ℕ) (hT : ∀j,0 if r=0 then 0 else sourceDegreeBudget T n s b r ω η a) - · intro r _ - by_cases hr : r=0 - · subst r - rw [sourceSignedCoefficient_zero,ite_eq_left rfl] - · rw [ite_eq_right hr] - exact source_canonical_degree_bound T n hT s b r ω η a ha hη z hz - · intro r _ - exact sourceSignedCoefficient_degree_geometric T n s b r z w - · intro r - split_ifs - · rfl - · exact sourceDegreeBudget_nonneg T n s b r ω η a - -theorem nonconstant_eq_degreeTail {l : ℕ} (A : (Fin l → Bool) → ℝ) : - nonconstantCoefficient A=degreeTail A 1 := by - funext σ - by_cases h : σ=(fun _ => false) - · subst σ; simp [nonconstantCoefficient,degreeTail,monomialDegree] - · have hd : 1 ≤ monomialDegree σ := by - have := (monomialDegree_eq_zero_iff σ).not.mpr h - omega - simp [nonconstantCoefficient,degreeTail,h,hd] - -/-- The individual density is close to the pure reference without any - metadata typicality assumption. -/ -theorem source_canonical_centered_energy {Side : Type*} (T n : ℕ → ℕ) (s b : ℕ) - (z : Reports Side (SourceTrialCount T n (b+1))) (τ : Bool) {w : ℝ} (hw : 0 ≤ w) - (hsmall : w^2*sourceSparseCount T s b<1) : - multilinearEnergy (nonconstantCoefficient (sourceOracleCoefficient T n s b z τ)) w ≤ - (w^2*sourceSparseCount T s b)/(1-w^2*sourceSparseCount T s b) := by - rw [nonconstant_eq_degreeTail] - simpa only [pow_one,sourceOracleCoefficient] using averaged_sparse_tail_energy _ _ - (sourceFlatLeafType_sparse T n s _ b 0 τ) 1 hw hsmall - -end TraceReconstruction - -noncomputable section -namespace TraceReconstruction.FiniteLaw -open scoped Classical -variable {α : Type*} [Fintype α] - -theorem abs_expect_pow_le (P : FiniteLaw α) (F : α → ℝ) (t : ℕ) : - |P.expect F|^t ≤ P.expect (fun a => |F a|^t) := by - have habs : |P.expect F| ≤ P.expect (fun a => |F a|) := by - calc - _ ≤ ∑a, |P.mass a*F a| := Finset.abs_sum_le_sum_abs _ _ - _ = _ := by simp only [abs_mul,abs_of_nonneg (P.nonneg _)]; rfl - apply (pow_le_pow_left₀ (abs_nonneg _) habs t).trans - simpa only [smul_eq_mul,expect] using - (convexOn_pow (𝕜:=ℝ) t).map_sum_le (t:=Finset.univ) - (w:=P.mass) (p:=fun a => |F a|) (fun a _ => P.nonneg a) P.total (fun a _ => (show |F a| ∈ Set.Ici (0:ℝ) from abs_nonneg (F a))) - -theorem density_score_centered (P Q : FiniteLaw α) (Z : α → ℝ) - (hZ : ∀a,Q.mass a=P.mass a*(1+Z a)) : P.expect Z=0 := by - have h := Q.total - simp_rw [hZ,mul_add,mul_one,Finset.sum_add_distrib,P.total] at h - change _+P.expect Z=1 at h - linarith - -/-- Common-event mass difference is controlled by the restricted density - difference at every moment, by finite Jensen rather than a pointwise bound. -/ -theorem clipping_mass_difference (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) - (A : Finset α) (t : ℕ) : - |(R.withDensity f hf hfm).eventMass A-(R.withDensity g hg hgm).eventMass A|^t ≤ - R.expect (fun a => |if a∈A then g a-f a else 0|^t) := by - have he : (R.withDensity f hf hfm).eventMass A-(R.withDensity g hg hgm).eventMass A= - -(R.expect (fun a => if a∈A then g a-f a else 0)) := by - simp only [expect,mul_ite,mul_zero,←Finset.sum_filter, - Finset.filter_mem_eq_inter,Finset.univ_inter,eventMass,withDensity,mul_sub, - Finset.sum_sub_distrib] - ring - rw [he,abs_neg] - exact R.abs_expect_pow_le _ t - -theorem clipped_raw_moment_restricted (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀a,0 ≤ f a) (hfm : R.expect f=1) - (A : Finset α) (hAf : ∀a∈A,1/2 ≤ f a) - (hP : 0<(R.withDensity f hf hfm).eventMass A) (k : ℕ) : - (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g a/f a-1|^(k+1)) ≤ - 2^k/(R.withDensity f hf hfm).eventMass A * - R.expect (fun a => |if a∈A then g a-f a else 0|^(k+1)) := by - let g' : α → ℝ := fun a => if a∈A then g a else f a - have H := clipped_raw_moment R f g' hf hfm A hAf hP k - have he : (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g a/f a-1|^(k+1))= - (condition (R.withDensity f hf hfm) A hP).expect (fun a => |g' a/f a-1|^(k+1)) := by - apply Finset.sum_congr rfl - intro a _ - by_cases ha : a∈A <;> simp [condition,g',ha] - rw [he] - convert H using 1 - congr 2 - funext a - by_cases ha : a∈A <;> simp [g',ha] - -/-- Explicit normalized clipping, at half of any positive even moment. This - constructs the actual conditioned score; no bounded-score hypothesis. -/ -theorem clipped_score_moment (R : FiniteLaw α) (f g : α → ℝ) - (hf : ∀a,0 ≤ f a) (hg : ∀a,0 ≤ g a) (hfm : R.expect f=1) (hgm : R.expect g=1) - (A : Finset α) (hAf : ∀a∈A,1/2 ≤ f a) - (hp : 1/2 ≤ (R.withDensity f hf hfm).eventMass A) - (hq : 1/2 ≤ (R.withDensity g hg hgm).eventMass A) - (k : ℕ) (hk : 1 ≤ k) (V : ℝ) (hV : 0 ≤ V) - (hM : R.expect (fun a => |if a∈A then g a-f a else 0|^(2*k)) ≤ V^k) : - let p := (R.withDensity f hf hfm).eventMass A - let q := (R.withDensity g hg hgm).eventMass A - let hP : 0 < p := lt_of_lt_of_le (by norm_num) hp - (condition (R.withDensity f hf hfm) A hP).evenMomentSq (fun a => p/q*(g a/f a)-1) k ≤64*V := by - dsimp only - let p := (R.withDensity f hf hfm).eventMass A - let q := (R.withDensity g hg hgm).eventMass A - have hp0 : 0